@@ -24,6 +24,7 @@ The Hyphen Node.js SDK is a JavaScript library that allows developers to easily
2424- [ ENV - Secret Management Service] ( #env---secret-management-service )
2525 - [Loading Environment Variables](#loading-environment-variables)
2626- [ Net Info - Geo Information Service] ( #net-info---geo-information-service )
27+ - [ Execution Context - API Key Validation] ( #execution-context---api-key-validation )
2728- [ Link - Short Code Service] ( #link---short-code-service )
2829 - [Creating a Short Code](#creating-a-short-code)
2930 - [Updating a Short Code](#updating-a-short-code)
@@ -673,6 +674,75 @@ console.log('IP Infos:', ipInfos);
673674
674675You can also set the API key using the ` HYPHEN_API_KEY ` environment variable. This is useful for keeping your API key secure and not hardcoding it in your code.
675676
677+ # Execution Context - API Key Validation
678+
679+ The ` getExecutionContext` function validates an API key and returns information about the authenticated user, organization, and request context. This is useful for verifying API keys and getting user/organization details.
680+
681+ ## Basic Usage
682+
683+ ` ` ` javascript
684+ import { getExecutionContext } from ' @hyphen/sdk' ;
685+
686+ const context = await getExecutionContext (' your-api-key' );
687+
688+ console .log (' User:' , context .user ? .name );
689+ console .log (' Organization:' , context .member ? .organization ? .name );
690+ console .log (' IP Address:' , context .ipAddress );
691+ console .log (' Location:' , context .location ? .city , context .location ? .country );
692+ ` ` `
693+
694+ ## Options
695+
696+ | Option | Type | Description |
697+ |--------|------|-------------|
698+ | ` organizationId` | ` string` | Optional organization ID to scope the context request |
699+ | ` baseUri` | ` string` | Custom API base URI (defaults to ` https: // api.hyphen.ai`) |
700+ | ` cache` | ` Cacheable` | Cacheable instance for caching requests |
701+
702+ ## With Organization ID
703+
704+ If you need to get context for a specific organization:
705+
706+ ` ` ` javascript
707+ import { getExecutionContext } from '@hyphen/sdk';
708+
709+ const context = await getExecutionContext('your-api-key', {
710+ organizationId: 'org_123456789',
711+ });
712+
713+ console.log('Organization:', context.organization?.name);
714+ ` ` `
715+
716+ ## With Caching
717+
718+ To enable caching of execution context requests:
719+
720+ ` ` ` javascript
721+ import { Cacheable } from 'cacheable';
722+ import { getExecutionContext } from '@hyphen/sdk';
723+
724+ const cache = new Cacheable({ ttl: 60000 }); // Cache for 60 seconds
725+
726+ const context = await getExecutionContext('your-api-key', {
727+ cache,
728+ });
729+
730+ console.log('User:', context.user?.name);
731+ ` ` `
732+
733+ ## Return Type
734+
735+ The function returns an `ExecutionContext` object with the following properties:
736+
737+ | Property | Type | Description |
738+ |----------|------|-------------|
739+ | `request` | `object` | Request metadata (` id` , ` causationId` , ` correlationId` ) |
740+ | `user` | `object` | User info (`id`, `name`, `rules`, `type`) |
741+ | `member` | `object` | Member info with nested `organization` |
742+ | `organization` | `object` | Organization info (`id`, `name`) |
743+ | `ipAddress` | `string` | The IP address of the request |
744+ | `location` | `object` | Geo location (`country`, `region`, `city`, `lat`, `lng`, `postalCode`, `timezone`) |
745+
676746# Link - Short Code Service
677747
678748The Hyphen Node.js SDK also provides a `Link` class that allows you to create and manage short codes. This can be useful for generating short links for your application.
0 commit comments