@workos/authkit-session 0.0.1-alpha.3 → 0.1.1

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.
Files changed (35) hide show
  1. package/README.md +80 -5
  2. package/dist/index.cjs +229 -356
  3. package/dist/index.cjs.map +1 -1
  4. package/dist/index.js +225 -352
  5. package/dist/index.js.map +1 -1
  6. package/package.json +18 -11
  7. package/src/core/client/types.ts +2 -7
  8. package/src/core/client/workos.ts +5 -5
  9. package/src/core/config/ConfigurationProvider.spec.ts +201 -0
  10. package/src/core/config/ConfigurationProvider.ts +75 -7
  11. package/src/core/config.spec.ts +160 -0
  12. package/src/core/config.ts +29 -3
  13. package/src/core/createAuthKitFactory.spec.ts +161 -0
  14. package/src/core/createAuthKitFactory.ts +28 -23
  15. package/src/core/encryption/ironWebcryptoEncryption.spec.ts +129 -0
  16. package/src/core/encryption/ironWebcryptoEncryption.ts +28 -23
  17. package/src/core/encryption/pureWebcryptoEncryption.spec.ts +177 -0
  18. package/src/core/encryption/pureWebcryptoEncryption.ts +339 -0
  19. package/src/core/errors.spec.ts +130 -0
  20. package/src/core/session/CookieSessionStorage.spec.ts +136 -0
  21. package/src/core/session/CookieSessionStorage.ts +40 -7
  22. package/src/core/session/SessionManager.spec.ts +357 -0
  23. package/src/core/session/SessionManager.ts +71 -72
  24. package/src/core/session/TokenManager.spec.ts +132 -0
  25. package/src/core/session/TokenManager.ts +8 -6
  26. package/src/core/session/types.ts +39 -3
  27. package/src/index.ts +20 -8
  28. package/src/utils.spec.ts +12 -0
  29. package/dist/index.d.cts +0 -406
  30. package/dist/index.d.ts +0 -406
  31. package/src/HttpClient.ts +0 -160
  32. package/src/adapters/chrome/ChromeExtensionStorage.ts +0 -34
  33. package/src/core/UserManagement.ts +0 -8
  34. package/src/core/client/WorkOSLite.ts +0 -284
  35. 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 with `returnPathname`, `redirectUri`, and `screenHint`
446
- - `getSignInUrl(options)`: Generate a sign-in URL with `organizationId`, `loginHint`, and `redirectUri`
447
- - `getSignUpUrl(options)`: Generate a sign-up URL with `organizationId`, `loginHint`, and `redirectUri`
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