@workos/authkit-session 0.0.1-alpha.3 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +80 -5
- package/dist/core/client/types.d.ts +75 -0
- package/dist/core/client/types.d.ts.map +1 -0
- package/dist/core/client/types.js +2 -0
- package/dist/core/client/types.js.map +1 -0
- package/dist/core/client/workos.d.ts +11 -0
- package/dist/core/client/workos.d.ts.map +1 -0
- package/dist/core/client/workos.js +33 -0
- package/dist/core/client/workos.js.map +1 -0
- package/dist/core/config/ConfigurationProvider.d.ts +43 -0
- package/dist/core/config/ConfigurationProvider.d.ts.map +1 -0
- package/dist/core/config/ConfigurationProvider.js +171 -0
- package/dist/core/config/ConfigurationProvider.js.map +1 -0
- package/dist/core/config/types.d.ts +62 -0
- package/dist/core/config/types.d.ts.map +1 -0
- package/dist/core/config/types.js +2 -0
- package/dist/core/config/types.js.map +1 -0
- package/dist/core/config.d.ts +69 -0
- package/dist/core/config.d.ts.map +1 -0
- package/dist/core/config.js +49 -0
- package/dist/core/config.js.map +1 -0
- package/dist/core/createAuthKitFactory.d.ts +64 -0
- package/dist/core/createAuthKitFactory.d.ts.map +1 -0
- package/dist/core/createAuthKitFactory.js +95 -0
- package/dist/core/createAuthKitFactory.js.map +1 -0
- package/dist/core/encryption/ironSessionEncryption.d.ts +16 -0
- package/dist/core/encryption/ironSessionEncryption.d.ts.map +1 -0
- package/dist/core/encryption/ironSessionEncryption.js +6 -0
- package/dist/core/encryption/ironSessionEncryption.js.map +1 -0
- package/dist/core/encryption/ironWebcryptoEncryption.d.ts +19 -0
- package/dist/core/encryption/ironWebcryptoEncryption.d.ts.map +1 -0
- package/dist/core/encryption/ironWebcryptoEncryption.js +84 -0
- package/dist/core/encryption/ironWebcryptoEncryption.js.map +1 -0
- package/dist/core/encryption/pureWebcryptoEncryption.d.ts +29 -0
- package/dist/core/encryption/pureWebcryptoEncryption.d.ts.map +1 -0
- package/dist/core/encryption/pureWebcryptoEncryption.js +182 -0
- package/dist/core/encryption/pureWebcryptoEncryption.js.map +1 -0
- package/dist/core/errors.d.ts +14 -0
- package/dist/core/errors.d.ts.map +1 -0
- package/dist/core/errors.js +28 -0
- package/dist/core/errors.js.map +1 -0
- package/dist/core/session/CookieSessionStorage.d.ts +33 -0
- package/dist/core/session/CookieSessionStorage.d.ts.map +1 -0
- package/dist/core/session/CookieSessionStorage.js +52 -0
- package/dist/core/session/CookieSessionStorage.js.map +1 -0
- package/dist/core/session/SessionManager.d.ts +51 -0
- package/dist/core/session/SessionManager.d.ts.map +1 -0
- package/dist/core/session/SessionManager.js +238 -0
- package/dist/core/session/SessionManager.js.map +1 -0
- package/dist/core/session/TokenManager.d.ts +14 -0
- package/dist/core/session/TokenManager.d.ts.map +1 -0
- package/dist/core/session/TokenManager.js +43 -0
- package/dist/core/session/TokenManager.js.map +1 -0
- package/dist/core/session/types.d.ts +101 -0
- package/dist/core/session/types.d.ts.map +1 -0
- package/dist/core/session/types.js +2 -0
- package/dist/core/session/types.js.map +1 -0
- package/dist/index.d.ts +10 -406
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -923
- package/dist/index.js.map +1 -1
- package/dist/utils.d.ts +9 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +19 -0
- package/dist/utils.js.map +1 -0
- package/package.json +19 -11
- package/src/core/client/types.ts +2 -7
- package/src/core/client/workos.ts +5 -5
- package/src/core/config/ConfigurationProvider.spec.ts +201 -0
- package/src/core/config/ConfigurationProvider.ts +75 -7
- package/src/core/config.spec.ts +160 -0
- package/src/core/config.ts +29 -3
- package/src/core/createAuthKitFactory.spec.ts +161 -0
- package/src/core/createAuthKitFactory.ts +28 -23
- package/src/core/encryption/ironWebcryptoEncryption.spec.ts +129 -0
- package/src/core/encryption/ironWebcryptoEncryption.ts +28 -23
- package/src/core/encryption/pureWebcryptoEncryption.spec.ts +177 -0
- package/src/core/encryption/pureWebcryptoEncryption.ts +339 -0
- package/src/core/errors.spec.ts +130 -0
- package/src/core/session/CookieSessionStorage.spec.ts +136 -0
- package/src/core/session/CookieSessionStorage.ts +40 -7
- package/src/core/session/SessionManager.spec.ts +357 -0
- package/src/core/session/SessionManager.ts +71 -72
- package/src/core/session/TokenManager.spec.ts +132 -0
- package/src/core/session/TokenManager.ts +8 -6
- package/src/core/session/types.ts +39 -3
- package/src/index.ts +20 -8
- package/src/utils.spec.ts +12 -0
- package/dist/index.cjs +0 -924
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -406
- package/src/HttpClient.ts +0 -160
- package/src/adapters/chrome/ChromeExtensionStorage.ts +0 -34
- package/src/core/UserManagement.ts +0 -8
- package/src/core/client/WorkOSLite.ts +0 -284
- package/src/core/iron.ts +0 -103
package/README.md
CHANGED
|
@@ -144,13 +144,19 @@ const authUrl = await authKit.getAuthorizationUrl({
|
|
|
144
144
|
returnPathname: '/dashboard',
|
|
145
145
|
redirectUri: 'https://yourdomain.com/auth/callback',
|
|
146
146
|
screenHint: 'sign-in', // or 'sign-up'
|
|
147
|
+
organizationId: 'org_123', // Optional: pre-select organization
|
|
148
|
+
loginHint: 'user@example.com', // Optional: pre-fill email
|
|
149
|
+
prompt: 'login', // Optional: force re-authentication
|
|
147
150
|
});
|
|
148
151
|
|
|
149
|
-
// Generate sign-in/sign-up URLs
|
|
152
|
+
// Generate sign-in/sign-up URLs (convenience methods)
|
|
150
153
|
const signInUrl = await authKit.getSignInUrl({
|
|
154
|
+
returnPathname: '/dashboard',
|
|
151
155
|
redirectUri: 'https://yourdomain.com/auth/callback',
|
|
156
|
+
organizationId: 'org_123', // Optional
|
|
152
157
|
});
|
|
153
158
|
const signUpUrl = await authKit.getSignUpUrl({
|
|
159
|
+
returnPathname: '/welcome',
|
|
154
160
|
redirectUri: 'https://yourdomain.com/auth/callback',
|
|
155
161
|
});
|
|
156
162
|
|
|
@@ -252,6 +258,39 @@ export async function handleCallback(event: RequestEvent) {
|
|
|
252
258
|
- **TypeScript Support**: Export proper types for your framework's patterns
|
|
253
259
|
- **Error Handling**: Wrap AuthKit errors in framework-appropriate error types
|
|
254
260
|
|
|
261
|
+
### Configuration Validation
|
|
262
|
+
|
|
263
|
+
Framework adapters should validate configuration on startup to provide clear error messages:
|
|
264
|
+
|
|
265
|
+
```typescript
|
|
266
|
+
import { validateConfig } from '@workos/authkit-session';
|
|
267
|
+
|
|
268
|
+
// In your framework's initialization or middleware
|
|
269
|
+
try {
|
|
270
|
+
validateConfig();
|
|
271
|
+
} catch (error) {
|
|
272
|
+
// Framework will display helpful error message with all missing/invalid config
|
|
273
|
+
throw error;
|
|
274
|
+
}
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
The `validateConfig()` function performs batch validation, collecting all configuration errors before throwing. This provides developers with a complete picture of what needs to be fixed, rather than discovering issues one at a time.
|
|
278
|
+
|
|
279
|
+
### Accessing Configuration
|
|
280
|
+
|
|
281
|
+
Framework adapters can access configuration values directly:
|
|
282
|
+
|
|
283
|
+
```typescript
|
|
284
|
+
import { getConfig, getConfigurationProvider } from '@workos/authkit-session';
|
|
285
|
+
|
|
286
|
+
// Get a single config value
|
|
287
|
+
const clientId = getConfig('clientId');
|
|
288
|
+
|
|
289
|
+
// Get the ConfigurationProvider for more advanced use
|
|
290
|
+
const provider = getConfigurationProvider();
|
|
291
|
+
const config = provider.getConfig(); // Returns full AuthKitConfig object
|
|
292
|
+
```
|
|
293
|
+
|
|
255
294
|
## Core Concepts
|
|
256
295
|
|
|
257
296
|
### Session Management
|
|
@@ -388,7 +427,7 @@ AuthKit can be configured in multiple ways:
|
|
|
388
427
|
|
|
389
428
|
### Environment Variables
|
|
390
429
|
|
|
391
|
-
```
|
|
430
|
+
```bash
|
|
392
431
|
WORKOS_CLIENT_ID=your-client-id
|
|
393
432
|
WORKOS_API_KEY=your-api-key
|
|
394
433
|
WORKOS_REDIRECT_URI=https://yourdomain.com/auth/callback
|
|
@@ -400,6 +439,18 @@ WORKOS_API_HTTPS=true
|
|
|
400
439
|
WORKOS_API_PORT=443
|
|
401
440
|
```
|
|
402
441
|
|
|
442
|
+
**Environment Variable Naming Convention:**
|
|
443
|
+
Environment variables follow the pattern: `WORKOS_{PROPERTY_NAME}` where the property name is converted from camelCase to UPPER_SNAKE_CASE.
|
|
444
|
+
|
|
445
|
+
Examples:
|
|
446
|
+
|
|
447
|
+
- `clientId` → `WORKOS_CLIENT_ID`
|
|
448
|
+
- `redirectUri` → `WORKOS_REDIRECT_URI`
|
|
449
|
+
- `cookiePassword` → `WORKOS_COOKIE_PASSWORD`
|
|
450
|
+
- `cookieMaxAge` → `WORKOS_COOKIE_MAX_AGE`
|
|
451
|
+
|
|
452
|
+
Environment variables always take precedence over programmatic configuration.
|
|
453
|
+
|
|
403
454
|
### Programmatic Configuration
|
|
404
455
|
|
|
405
456
|
```typescript
|
|
@@ -425,7 +476,9 @@ configure({
|
|
|
425
476
|
### Core API
|
|
426
477
|
|
|
427
478
|
- `configure(config)`: Set up AuthKit with your WorkOS configuration
|
|
479
|
+
- `validateConfig()`: Validate all required configuration values are present and valid (throws descriptive error if not)
|
|
428
480
|
- `getConfig(key)`: Get a specific configuration value
|
|
481
|
+
- `getConfigurationProvider()`: Get the ConfigurationProvider instance for advanced configuration access
|
|
429
482
|
- `createAuthKitFactory(options)`: Create an instance of AuthKit for your framework
|
|
430
483
|
|
|
431
484
|
### AuthKit Instance API
|
|
@@ -442,9 +495,12 @@ configure({
|
|
|
442
495
|
|
|
443
496
|
#### URL Generation
|
|
444
497
|
|
|
445
|
-
- `getAuthorizationUrl(options)`: Generate a WorkOS authorization URL
|
|
446
|
-
- `
|
|
447
|
-
- `
|
|
498
|
+
- `getAuthorizationUrl(options)`: Generate a WorkOS authorization URL
|
|
499
|
+
- Options: `returnPathname`, `redirectUri`, `screenHint` ('sign-in' | 'sign-up'), `organizationId`, `loginHint`, `prompt` ('login' | 'none' | 'consent' | 'select_account')
|
|
500
|
+
- `getSignInUrl(options)`: Generate a sign-in URL (convenience method with screenHint='sign-in')
|
|
501
|
+
- Options: `returnPathname`, `redirectUri`, `organizationId`, `loginHint`, `prompt`
|
|
502
|
+
- `getSignUpUrl(options)`: Generate a sign-up URL (convenience method with screenHint='sign-up')
|
|
503
|
+
- Options: `returnPathname`, `redirectUri`, `organizationId`, `loginHint`, `prompt`
|
|
448
504
|
|
|
449
505
|
#### Token & Organization Management
|
|
450
506
|
|
|
@@ -541,9 +597,28 @@ The library also exports these components for advanced use cases:
|
|
|
541
597
|
|
|
542
598
|
```typescript
|
|
543
599
|
import {
|
|
600
|
+
// Core configuration
|
|
601
|
+
configure, // Set up configuration
|
|
602
|
+
validateConfig, // Validate all required config values
|
|
603
|
+
getConfig, // Get specific config value
|
|
604
|
+
getConfigurationProvider, // Get ConfigurationProvider instance
|
|
605
|
+
ConfigurationProvider, // ConfigurationProvider class
|
|
606
|
+
|
|
607
|
+
// Session management
|
|
544
608
|
SessionManager, // Core session management class
|
|
545
609
|
CookieSessionStorage, // Abstract cookie storage base class
|
|
610
|
+
|
|
611
|
+
// WorkOS client
|
|
546
612
|
getWorkOS, // WorkOS client factory
|
|
613
|
+
|
|
614
|
+
// Types
|
|
615
|
+
type SessionStorage,
|
|
616
|
+
type AuthKitConfig,
|
|
617
|
+
type AuthResult,
|
|
618
|
+
type Session,
|
|
619
|
+
type User,
|
|
620
|
+
type Impersonator,
|
|
621
|
+
// ... and more
|
|
547
622
|
} from '@workos/authkit-session';
|
|
548
623
|
```
|
|
549
624
|
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type { User, Impersonator, WorkOS } from '@workos-inc/node';
|
|
2
|
+
export interface UserManagementInterface {
|
|
3
|
+
getAuthorizationUrl: (options: AuthorizationURLOptions) => string;
|
|
4
|
+
authenticateWithCode: (options: AuthenticateWithCodeOptions) => Promise<AuthenticationResponse>;
|
|
5
|
+
authenticateWithRefreshToken: (options: AuthenticateWithRefreshTokenOptions) => Promise<AuthenticationResponse>;
|
|
6
|
+
getLogoutUrl: (options: {
|
|
7
|
+
sessionId: string;
|
|
8
|
+
returnTo?: string;
|
|
9
|
+
}) => string;
|
|
10
|
+
revokeSession: (options: {
|
|
11
|
+
sessionId: string;
|
|
12
|
+
}) => Promise<void>;
|
|
13
|
+
}
|
|
14
|
+
export interface WorkOSClientConstructor {
|
|
15
|
+
new (apiKey: string, options?: WorkOSOptions): WorkOS;
|
|
16
|
+
}
|
|
17
|
+
export interface AppInfo {
|
|
18
|
+
name: string;
|
|
19
|
+
version: string;
|
|
20
|
+
}
|
|
21
|
+
export interface WorkOSOptions {
|
|
22
|
+
apiHostname?: string;
|
|
23
|
+
https?: boolean;
|
|
24
|
+
port?: number;
|
|
25
|
+
config?: RequestInit;
|
|
26
|
+
appInfo?: AppInfo;
|
|
27
|
+
fetchFn?: typeof fetch;
|
|
28
|
+
clientId?: string;
|
|
29
|
+
}
|
|
30
|
+
export interface AuthenticationResponse {
|
|
31
|
+
user: User;
|
|
32
|
+
organizationId?: string;
|
|
33
|
+
accessToken: string;
|
|
34
|
+
refreshToken: string;
|
|
35
|
+
impersonator?: Impersonator;
|
|
36
|
+
authenticationMethod?: string;
|
|
37
|
+
sealedSession?: string;
|
|
38
|
+
}
|
|
39
|
+
export interface AuthenticateWithOptionsBase {
|
|
40
|
+
clientId: string;
|
|
41
|
+
ipAddress?: string;
|
|
42
|
+
userAgent?: string;
|
|
43
|
+
session?: {
|
|
44
|
+
cookiePassword?: string;
|
|
45
|
+
sealSession: boolean;
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
export interface AuthenticateWithRefreshTokenOptions extends AuthenticateWithOptionsBase {
|
|
49
|
+
refreshToken: string;
|
|
50
|
+
organizationId?: string;
|
|
51
|
+
}
|
|
52
|
+
export interface AuthenticateWithCodeOptions extends AuthenticateWithOptionsBase {
|
|
53
|
+
codeVerifier?: string;
|
|
54
|
+
code: string;
|
|
55
|
+
invitationToken?: string;
|
|
56
|
+
}
|
|
57
|
+
export interface AuthenticateWithEmailVerificationOptions extends AuthenticateWithOptionsBase {
|
|
58
|
+
code: string;
|
|
59
|
+
pendingAuthenticationToken: string;
|
|
60
|
+
}
|
|
61
|
+
export interface AuthorizationURLOptions {
|
|
62
|
+
clientId: string;
|
|
63
|
+
codeChallenge?: string;
|
|
64
|
+
codeChallengeMethod?: 'S256';
|
|
65
|
+
connectionId?: string;
|
|
66
|
+
context?: string;
|
|
67
|
+
organizationId?: string;
|
|
68
|
+
domainHint?: string;
|
|
69
|
+
loginHint?: string;
|
|
70
|
+
provider?: string;
|
|
71
|
+
redirectUri: string;
|
|
72
|
+
state?: string;
|
|
73
|
+
screenHint?: 'sign-up' | 'sign-in';
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/core/client/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AACnE,MAAM,WAAW,uBAAuB;IACtC,mBAAmB,EAAE,CAAC,OAAO,EAAE,uBAAuB,KAAK,MAAM,CAAC;IAClE,oBAAoB,EAAE,CACpB,OAAO,EAAE,2BAA2B,KACjC,OAAO,CAAC,sBAAsB,CAAC,CAAC;IACrC,4BAA4B,EAAE,CAC5B,OAAO,EAAE,mCAAmC,KACzC,OAAO,CAAC,sBAAsB,CAAC,CAAC;IACrC,YAAY,EAAE,CAAC,OAAO,EAAE;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE,KAAK,MAAM,CAAC;IAC5E,aAAa,EAAE,CAAC,OAAO,EAAE;QAAE,SAAS,EAAE,MAAM,CAAA;KAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CAClE;AAED,MAAM,WAAW,uBAAuB;IACtC,KAAK,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,MAA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0B,EAAE,MAAM,CAAC;CACpC;AAED,MAAM,WAAW,uBAAuB;IACtC,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,SAAS,GAAG,SAAS,CAAC;CACpC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/core/client/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { WorkOS } from '@workos-inc/node';
|
|
2
|
+
/**
|
|
3
|
+
* Create a WorkOS instance with the provided API key and optional settings.
|
|
4
|
+
*/
|
|
5
|
+
export declare function createWorkOSInstance(): WorkOS;
|
|
6
|
+
/**
|
|
7
|
+
* Create a WorkOS instance with the provided API key and optional settings.
|
|
8
|
+
* This function is lazy loaded to avoid loading the WorkOS SDK when it's not needed.
|
|
9
|
+
*/
|
|
10
|
+
export declare const getWorkOS: () => WorkOS;
|
|
11
|
+
//# sourceMappingURL=workos.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workos.d.ts","sourceRoot":"","sources":["../../../src/core/client/workos.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAK1C;;GAEG;AACH,wBAAgB,oBAAoB,WAuBnC;AAED;;;GAGG;AACH,eAAO,MAAM,SAAS,cAA6B,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { WorkOS } from '@workos-inc/node';
|
|
2
|
+
import { getConfig } from '../config.js';
|
|
3
|
+
import { once } from '../../utils.js';
|
|
4
|
+
import pkg from '../../../package.json' with { type: 'json' };
|
|
5
|
+
/**
|
|
6
|
+
* Create a WorkOS instance with the provided API key and optional settings.
|
|
7
|
+
*/
|
|
8
|
+
export function createWorkOSInstance() {
|
|
9
|
+
// Get required API key from config
|
|
10
|
+
const apiKey = getConfig('apiKey');
|
|
11
|
+
// Get optional settings
|
|
12
|
+
const apiHostname = getConfig('apiHostname');
|
|
13
|
+
const apiHttps = getConfig('apiHttps');
|
|
14
|
+
const apiPort = getConfig('apiPort');
|
|
15
|
+
const options = {
|
|
16
|
+
apiHostname,
|
|
17
|
+
https: apiHttps,
|
|
18
|
+
port: apiPort,
|
|
19
|
+
appInfo: {
|
|
20
|
+
name: 'authkit-session',
|
|
21
|
+
version: pkg.version,
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
// Initialize the WorkOS client with config values
|
|
25
|
+
const workos = new WorkOS(apiKey, options);
|
|
26
|
+
return workos;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Create a WorkOS instance with the provided API key and optional settings.
|
|
30
|
+
* This function is lazy loaded to avoid loading the WorkOS SDK when it's not needed.
|
|
31
|
+
*/
|
|
32
|
+
export const getWorkOS = once(createWorkOSInstance);
|
|
33
|
+
//# sourceMappingURL=workos.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workos.js","sourceRoot":"","sources":["../../../src/core/client/workos.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AACtC,OAAO,GAAG,MAAM,uBAAuB,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAC;AAE9D;;GAEG;AACH,MAAM,UAAU,oBAAoB;IAClC,mCAAmC;IACnC,MAAM,MAAM,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC;IAEnC,wBAAwB;IACxB,MAAM,WAAW,GAAG,SAAS,CAAC,aAAa,CAAC,CAAC;IAC7C,MAAM,QAAQ,GAAG,SAAS,CAAC,UAAU,CAAC,CAAC;IACvC,MAAM,OAAO,GAAG,SAAS,CAAC,SAAS,CAAC,CAAC;IAErC,MAAM,OAAO,GAAG;QACd,WAAW;QACX,KAAK,EAAE,QAAQ;QACf,IAAI,EAAE,OAAO;QACb,OAAO,EAAE;YACP,IAAI,EAAE,iBAAiB;YACvB,OAAO,EAAE,GAAG,CAAC,OAAO;SACrB;KACF,CAAC;IAEF,kDAAkD;IAClD,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAE3C,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,IAAI,CAAC,oBAAoB,CAAC,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { AuthKitConfig, ValueSource } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Configuration class for AuthKit.
|
|
4
|
+
* This class is used to manage configuration values and provide defaults.
|
|
5
|
+
* It also provides a way to get configuration values from environment variables.
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
export declare class ConfigurationProvider {
|
|
9
|
+
private config;
|
|
10
|
+
private valueSource;
|
|
11
|
+
private readonly requiredKeys;
|
|
12
|
+
/**
|
|
13
|
+
* Convert a camelCase string to an uppercase, underscore-separated environment variable name.
|
|
14
|
+
* @param str The string to convert
|
|
15
|
+
* @returns The environment variable name
|
|
16
|
+
*/
|
|
17
|
+
protected getEnvironmentVariableName(str: string): string;
|
|
18
|
+
private updateConfig;
|
|
19
|
+
setValueSource(source: ValueSource): void;
|
|
20
|
+
configure(configOrSource: Partial<AuthKitConfig> | ValueSource, source?: ValueSource): void;
|
|
21
|
+
getValue<K extends keyof AuthKitConfig>(key: K): AuthKitConfig[K];
|
|
22
|
+
private getEnvironmentValue;
|
|
23
|
+
private convertValueType;
|
|
24
|
+
/**
|
|
25
|
+
* Validates that all required configuration values are present and meet requirements.
|
|
26
|
+
* Collects all validation errors before throwing to provide comprehensive feedback.
|
|
27
|
+
*
|
|
28
|
+
* @throws {Error} If any required configuration is missing or invalid
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* const provider = new ConfigurationProvider();
|
|
33
|
+
* try {
|
|
34
|
+
* provider.validate();
|
|
35
|
+
* } catch (error) {
|
|
36
|
+
* console.error(error.message); // Shows all missing/invalid config at once
|
|
37
|
+
* }
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
validate(): void;
|
|
41
|
+
getConfig(): AuthKitConfig;
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=ConfigurationProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConfigurationProvider.d.ts","sourceRoot":"","sources":["../../../src/core/config/ConfigurationProvider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAgB7D;;;;;GAKG;AACH,qBAAa,qBAAqB;IAChC,OAAO,CAAC,MAAM,CAQZ;IAEF,OAAO,CAAC,WAAW,CAA8B;IAEjD,OAAO,CAAC,QAAQ,CAAC,YAAY,CAK3B;IAEF;;;;OAIG;IACH,SAAS,CAAC,0BAA0B,CAAC,GAAG,EAAE,MAAM;IAIhD,OAAO,CAAC,YAAY;IAIpB,cAAc,CAAC,MAAM,EAAE,WAAW,GAAG,IAAI;IAIzC,SAAS,CACP,cAAc,EAAE,OAAO,CAAC,aAAa,CAAC,GAAG,WAAW,EACpD,MAAM,CAAC,EAAE,WAAW,GACnB,IAAI;IAWP,QAAQ,CAAC,CAAC,SAAS,MAAM,aAAa,EAAE,GAAG,EAAE,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC;IAoBjE,OAAO,CAAC,mBAAmB;IAc3B,OAAO,CAAC,gBAAgB;IAsBxB;;;;;;;;;;;;;;;OAeG;IACH,QAAQ,IAAI,IAAI;IAiChB,SAAS,IAAI,aAAa;CA4B3B"}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default environment variable source that uses process.env
|
|
3
|
+
*/
|
|
4
|
+
const defaultSource = (key) => {
|
|
5
|
+
try {
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
7
|
+
const processEnv = globalThis
|
|
8
|
+
?.process?.env;
|
|
9
|
+
return processEnv?.[key];
|
|
10
|
+
}
|
|
11
|
+
catch {
|
|
12
|
+
return undefined;
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Configuration class for AuthKit.
|
|
17
|
+
* This class is used to manage configuration values and provide defaults.
|
|
18
|
+
* It also provides a way to get configuration values from environment variables.
|
|
19
|
+
* @internal
|
|
20
|
+
*/
|
|
21
|
+
export class ConfigurationProvider {
|
|
22
|
+
config = {
|
|
23
|
+
cookieName: 'wos-session',
|
|
24
|
+
apiHttps: true,
|
|
25
|
+
// Defaults to 400 days, the maximum allowed by Chrome
|
|
26
|
+
// It's fine to have a long cookie expiry date as the access/refresh tokens
|
|
27
|
+
// act as the actual time-limited aspects of the session.
|
|
28
|
+
cookieMaxAge: 60 * 60 * 24 * 400,
|
|
29
|
+
apiHostname: 'api.workos.com',
|
|
30
|
+
};
|
|
31
|
+
valueSource = defaultSource;
|
|
32
|
+
requiredKeys = [
|
|
33
|
+
'clientId',
|
|
34
|
+
'apiKey',
|
|
35
|
+
'redirectUri',
|
|
36
|
+
'cookiePassword',
|
|
37
|
+
];
|
|
38
|
+
/**
|
|
39
|
+
* Convert a camelCase string to an uppercase, underscore-separated environment variable name.
|
|
40
|
+
* @param str The string to convert
|
|
41
|
+
* @returns The environment variable name
|
|
42
|
+
*/
|
|
43
|
+
getEnvironmentVariableName(str) {
|
|
44
|
+
return `WORKOS_${str.replace(/([a-z])([A-Z])/g, '$1_$2').toUpperCase()}`;
|
|
45
|
+
}
|
|
46
|
+
updateConfig(config) {
|
|
47
|
+
this.config = { ...this.config, ...config };
|
|
48
|
+
}
|
|
49
|
+
setValueSource(source) {
|
|
50
|
+
this.valueSource = source;
|
|
51
|
+
}
|
|
52
|
+
configure(configOrSource, source) {
|
|
53
|
+
if (typeof configOrSource === 'function') {
|
|
54
|
+
this.setValueSource(configOrSource);
|
|
55
|
+
}
|
|
56
|
+
else if (typeof configOrSource === 'object' && !source) {
|
|
57
|
+
this.updateConfig(configOrSource);
|
|
58
|
+
}
|
|
59
|
+
else if (typeof configOrSource === 'object' && source) {
|
|
60
|
+
this.updateConfig(configOrSource);
|
|
61
|
+
this.setValueSource(source);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
getValue(key) {
|
|
65
|
+
const envKey = this.getEnvironmentVariableName(key);
|
|
66
|
+
const envValue = this.getEnvironmentValue(envKey);
|
|
67
|
+
// Use environment value if available, otherwise fall back to config
|
|
68
|
+
const rawValue = envValue ?? this.config[key];
|
|
69
|
+
if (rawValue != null) {
|
|
70
|
+
return this.convertValueType(key, rawValue);
|
|
71
|
+
}
|
|
72
|
+
if (this.requiredKeys.includes(key)) {
|
|
73
|
+
throw new Error(`Missing required configuration value for ${key} (${envKey}).`);
|
|
74
|
+
}
|
|
75
|
+
return undefined;
|
|
76
|
+
}
|
|
77
|
+
getEnvironmentValue(envKey) {
|
|
78
|
+
const { valueSource } = this;
|
|
79
|
+
if (typeof valueSource === 'function') {
|
|
80
|
+
return valueSource(envKey);
|
|
81
|
+
}
|
|
82
|
+
if (valueSource && envKey in valueSource) {
|
|
83
|
+
return valueSource[envKey];
|
|
84
|
+
}
|
|
85
|
+
return undefined;
|
|
86
|
+
}
|
|
87
|
+
convertValueType(key, value) {
|
|
88
|
+
if (typeof value !== 'string') {
|
|
89
|
+
return value;
|
|
90
|
+
}
|
|
91
|
+
// Handle boolean conversion
|
|
92
|
+
if (key === 'apiHttps') {
|
|
93
|
+
return (value === 'true');
|
|
94
|
+
}
|
|
95
|
+
// Handle number conversion
|
|
96
|
+
if (key === 'apiPort' || key === 'cookieMaxAge') {
|
|
97
|
+
const num = parseInt(value, 10);
|
|
98
|
+
return (isNaN(num) ? undefined : num);
|
|
99
|
+
}
|
|
100
|
+
return value;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Validates that all required configuration values are present and meet requirements.
|
|
104
|
+
* Collects all validation errors before throwing to provide comprehensive feedback.
|
|
105
|
+
*
|
|
106
|
+
* @throws {Error} If any required configuration is missing or invalid
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* ```typescript
|
|
110
|
+
* const provider = new ConfigurationProvider();
|
|
111
|
+
* try {
|
|
112
|
+
* provider.validate();
|
|
113
|
+
* } catch (error) {
|
|
114
|
+
* console.error(error.message); // Shows all missing/invalid config at once
|
|
115
|
+
* }
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
118
|
+
validate() {
|
|
119
|
+
const errors = [];
|
|
120
|
+
// Validate each required key
|
|
121
|
+
for (const key of this.requiredKeys) {
|
|
122
|
+
const envKey = this.getEnvironmentVariableName(key);
|
|
123
|
+
const envValue = this.getEnvironmentValue(envKey);
|
|
124
|
+
const configValue = this.config[key];
|
|
125
|
+
const value = envValue ?? configValue;
|
|
126
|
+
if (!value) {
|
|
127
|
+
errors.push(`${envKey} is required`);
|
|
128
|
+
}
|
|
129
|
+
else if (key === 'cookiePassword') {
|
|
130
|
+
// Special validation for cookiePassword length
|
|
131
|
+
const password = String(value);
|
|
132
|
+
if (password.length < 32) {
|
|
133
|
+
errors.push(`${envKey} must be at least 32 characters (currently ${password.length})`);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
if (errors.length > 0) {
|
|
138
|
+
throw new Error('AuthKit configuration error. Missing or invalid environment variables:\n\n' +
|
|
139
|
+
errors.map(e => ` • ${e}`).join('\n') +
|
|
140
|
+
'\n\nSet these environment variables or call configure() with the required values.' +
|
|
141
|
+
'\nGet your values from the WorkOS Dashboard: https://dashboard.workos.com');
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
getConfig() {
|
|
145
|
+
// Build a complete config by merging stored config with environment variables
|
|
146
|
+
const fullConfig = {};
|
|
147
|
+
// Get all keys from the stored config and required keys
|
|
148
|
+
const allKeys = new Set([
|
|
149
|
+
...Object.keys(this.config),
|
|
150
|
+
...this.requiredKeys,
|
|
151
|
+
]);
|
|
152
|
+
// Merge each key, with environment variables taking precedence
|
|
153
|
+
for (const key of allKeys) {
|
|
154
|
+
try {
|
|
155
|
+
const value = this.getValue(key);
|
|
156
|
+
if (value !== undefined) {
|
|
157
|
+
fullConfig[key] = value;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
catch (error) {
|
|
161
|
+
// If a required key is missing, let the error bubble up
|
|
162
|
+
if (this.requiredKeys.includes(key)) {
|
|
163
|
+
throw error;
|
|
164
|
+
}
|
|
165
|
+
// For optional keys, continue without the value
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return fullConfig;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
//# sourceMappingURL=ConfigurationProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConfigurationProvider.js","sourceRoot":"","sources":["../../../src/core/config/ConfigurationProvider.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,aAAa,GAAgB,CAAC,GAAW,EAAsB,EAAE;IACrE,IAAI,CAAC;QACH,8DAA8D;QAC9D,MAAM,UAAU,GAAwC,UAAkB;YACxE,EAAE,OAAO,EAAE,GAAG,CAAC;QACjB,OAAO,UAAU,EAAE,CAAC,GAAG,CAAC,CAAC;IAC3B,CAAC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AAI,CAAC,IAAI,CAAC;gBACtC,mFAAmF;gBACnF,2EAA2E,CAC9E,CAAC;QACJ,CAAC;IACH,CAAC;IAED,SAAS;QACP,8EAA8E;QAC9E,MAAM,UAAU,GAAG,EAAmB,CAAC;QAEvC,wDAAwD;QACxD,MAAM,OAAO,GAAG,IAAI,GAAG,CAAsB;YAC3C,GAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAA6B;YACxD,GAAG,IAAI,CAAC,YAAY;SACrB,CAAC,CAAC;QAEH,+DAA+D;QAC/D,KAAK,MAAM,GAAG,IAAI,OAAO,EAAE,CAAC;YAC1B,IAAI,CAAC;gBACH,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;gBACjC,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;oBACvB,UAAkB,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;gBACnC,CAAC;YACH,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,wDAAwD;gBACxD,IAAI,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;oBACpC,MAAM,KAAK,CAAC;gBACd,CAAC;gBACD,gDAAgD;YAClD,CAAC;QACH,CAAC;QAED,OAAO,UAAU,CAAC;IACpB,CAAC;CACF"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AuthKit Configuration Options
|
|
3
|
+
*/
|
|
4
|
+
export interface AuthKitConfig {
|
|
5
|
+
/**
|
|
6
|
+
* The WorkOS Client ID
|
|
7
|
+
* Equivalent to the WORKOS_CLIENT_ID environment variable
|
|
8
|
+
*/
|
|
9
|
+
clientId: string;
|
|
10
|
+
/**
|
|
11
|
+
* The WorkOS API Key
|
|
12
|
+
* Equivalent to the WORKOS_API_KEY environment variable
|
|
13
|
+
*/
|
|
14
|
+
apiKey: string;
|
|
15
|
+
/**
|
|
16
|
+
* The redirect URI for the authentication callback
|
|
17
|
+
* Equivalent to the WORKOS_REDIRECT_URI environment variable
|
|
18
|
+
*/
|
|
19
|
+
redirectUri: string;
|
|
20
|
+
/**
|
|
21
|
+
* The password used to encrypt the session cookie
|
|
22
|
+
* Equivalent to the WORKOS_COOKIE_PASSWORD environment variable
|
|
23
|
+
* Must be at least 32 characters long
|
|
24
|
+
*/
|
|
25
|
+
cookiePassword: string;
|
|
26
|
+
/**
|
|
27
|
+
* The hostname of the API to use
|
|
28
|
+
* Equivalent to the WORKOS_API_HOSTNAME environment variable
|
|
29
|
+
*/
|
|
30
|
+
apiHostname?: string;
|
|
31
|
+
/**
|
|
32
|
+
* Whether to use HTTPS for API requests
|
|
33
|
+
* Equivalent to the WORKOS_API_HTTPS environment variable
|
|
34
|
+
*/
|
|
35
|
+
apiHttps: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* The port to use for the API
|
|
38
|
+
* Equivalent to the WORKOS_API_PORT environment variable
|
|
39
|
+
*/
|
|
40
|
+
apiPort?: number;
|
|
41
|
+
/**
|
|
42
|
+
* The maximum age of the session cookie in seconds
|
|
43
|
+
* Equivalent to the WORKOS_COOKIE_MAX_AGE environment variable
|
|
44
|
+
*/
|
|
45
|
+
cookieMaxAge: number;
|
|
46
|
+
/**
|
|
47
|
+
* The sameSite attribute for the session cookie
|
|
48
|
+
*/
|
|
49
|
+
cookieSameSite?: 'strict' | 'lax' | 'none';
|
|
50
|
+
/**
|
|
51
|
+
* The name of the session cookie
|
|
52
|
+
* Equivalent to the WORKOS_COOKIE_NAME environment variable
|
|
53
|
+
* Defaults to "wos-session"
|
|
54
|
+
*/
|
|
55
|
+
cookieName: string;
|
|
56
|
+
/**
|
|
57
|
+
* The domain for the session cookie
|
|
58
|
+
*/
|
|
59
|
+
cookieDomain?: string;
|
|
60
|
+
}
|
|
61
|
+
export type ValueSource = Record<string, any> | ((key: string) => any);
|
|
62
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/core/config/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B;;;OAGG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;;OAGG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf;;;OAGG;IACH,WAAW,EAAE,MAAM,CAAC;IAEpB;;;;OAIG;IACH,cAAc,EAAE,MAAM,CAAC;IAEvB;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;;OAGG;IACH,QAAQ,EAAE,OAAO,CAAC;IAElB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;;OAGG;IACH,YAAY,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,cAAc,CAAC,EAAE,QAAQ,GAAG,KAAK,GAAG,MAAM,CAAC;IAE3C;;;;OAIG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAGD,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,MAAM,KAAK,GAAG,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/core/config/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { ConfigurationProvider } from './config/ConfigurationProvider.js';
|
|
2
|
+
import type { AuthKitConfig, ValueSource } from './config/types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Configure AuthKit with a custom value source.
|
|
5
|
+
* @param source The source of configuration values
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* configure(key => Deno.env.get(key));
|
|
9
|
+
*/
|
|
10
|
+
export declare function configure(source: ValueSource): void;
|
|
11
|
+
/**
|
|
12
|
+
* Configure AuthKit with custom values.
|
|
13
|
+
* @param config The configuration values
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* configure({
|
|
17
|
+
* clientId: 'your-client-id',
|
|
18
|
+
* redirectUri: 'https://your-app.com/auth/callback',
|
|
19
|
+
* apiKey: 'your-api-key',
|
|
20
|
+
* cookiePassword: 'your-cookie-password',
|
|
21
|
+
* });
|
|
22
|
+
*/
|
|
23
|
+
export declare function configure(config: Partial<AuthKitConfig>): void;
|
|
24
|
+
/**
|
|
25
|
+
* Configure AuthKit with custom values and a custom value source.
|
|
26
|
+
* @param config The configuration values
|
|
27
|
+
* @param source The source of configuration values
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* configure({
|
|
31
|
+
* clientId: 'your-client-id',
|
|
32
|
+
* }, env);
|
|
33
|
+
*/
|
|
34
|
+
export declare function configure(config: Partial<AuthKitConfig>, source: ValueSource): void;
|
|
35
|
+
/**
|
|
36
|
+
* Get a configuration value by key.
|
|
37
|
+
* This function will first check environment variables, then programmatically provided config,
|
|
38
|
+
* and finally fall back to defaults for optional settings.
|
|
39
|
+
* If a required setting is missing, an error will be thrown.
|
|
40
|
+
* @param key The configuration key
|
|
41
|
+
* @returns The configuration value
|
|
42
|
+
*/
|
|
43
|
+
export declare function getConfig<K extends keyof AuthKitConfig>(key: K): AuthKitConfig[K];
|
|
44
|
+
export declare function getConfigurationProvider(): ConfigurationProvider;
|
|
45
|
+
export declare function getFullConfig(): AuthKitConfig;
|
|
46
|
+
/**
|
|
47
|
+
* Validates that all required configuration values are present and meet requirements.
|
|
48
|
+
* Collects all validation errors before throwing to provide comprehensive feedback.
|
|
49
|
+
*
|
|
50
|
+
* This is useful to call early in your application lifecycle to fail fast with
|
|
51
|
+
* helpful error messages showing all missing/invalid configuration at once.
|
|
52
|
+
*
|
|
53
|
+
* @throws {Error} If any required configuration is missing or invalid
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```typescript
|
|
57
|
+
* import { validateConfig } from '@workos/authkit-session';
|
|
58
|
+
*
|
|
59
|
+
* // Validate configuration on startup
|
|
60
|
+
* try {
|
|
61
|
+
* validateConfig();
|
|
62
|
+
* } catch (error) {
|
|
63
|
+
* console.error(error.message); // Shows all missing config at once
|
|
64
|
+
* process.exit(1);
|
|
65
|
+
* }
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
export declare function validateConfig(): void;
|
|
69
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/core/config.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAC1E,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAIpE;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,WAAW,GAAG,IAAI,CAAC;AACrD;;;;;;;;;;;GAWG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,OAAO,CAAC,aAAa,CAAC,GAAG,IAAI,CAAC;AAChE;;;;;;;;;GASG;AACH,wBAAgB,SAAS,CACvB,MAAM,EAAE,OAAO,CAAC,aAAa,CAAC,EAC9B,MAAM,EAAE,WAAW,GAClB,IAAI,CAAC;AAQR;;;;;;;GAOG;AACH,wBAAgB,SAAS,CAAC,CAAC,SAAS,MAAM,aAAa,EACrD,GAAG,EAAE,CAAC,GACL,aAAa,CAAC,CAAC,CAAC,CAElB;AAED,wBAAgB,wBAAwB,IAAI,qBAAqB,CAEhE;AAED,wBAAgB,aAAa,IAAI,aAAa,CAE7C;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,cAAc,IAAI,IAAI,CAErC"}
|