@okta/spa-platform 0.6.0 → 0.9.0

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 (58) hide show
  1. package/README.md +204 -0
  2. package/claude.md +562 -0
  3. package/dist/esm/Credential/Credential.js.map +1 -1
  4. package/dist/esm/Credential/CredentialCoordinator.js +25 -22
  5. package/dist/esm/Credential/CredentialCoordinator.js.map +1 -1
  6. package/dist/esm/Credential/TokenStorage.js +19 -3
  7. package/dist/esm/Credential/TokenStorage.js.map +1 -1
  8. package/dist/esm/FetchClient/index.js.map +1 -1
  9. package/dist/esm/core.js +25 -0
  10. package/dist/esm/core.js.map +1 -0
  11. package/dist/esm/flows/AuthorizationCodeFlow.js.map +1 -1
  12. package/dist/esm/flows/SessionLogoutFlow.js.map +1 -1
  13. package/dist/esm/flows/TransactionStorage.js.map +1 -1
  14. package/dist/esm/flows.js +30 -0
  15. package/dist/esm/flows.js.map +1 -0
  16. package/dist/esm/index.js +4 -13
  17. package/dist/esm/index.js.map +1 -1
  18. package/dist/esm/orchestrators/AuthorizationCodeFlowOrchestrator.js +4 -0
  19. package/dist/esm/orchestrators/AuthorizationCodeFlowOrchestrator.js.map +1 -1
  20. package/dist/esm/orchestrators/HostOrchestrator/Host.js +9 -1
  21. package/dist/esm/orchestrators/HostOrchestrator/Host.js.map +1 -1
  22. package/dist/esm/orchestrators/HostOrchestrator/OrchestrationBridge.js.map +1 -1
  23. package/dist/esm/orchestrators/HostOrchestrator/SubApp.js +8 -2
  24. package/dist/esm/orchestrators/HostOrchestrator/SubApp.js.map +1 -1
  25. package/dist/esm/orchestrators/HostOrchestrator/index.js +11 -6
  26. package/dist/esm/orchestrators/HostOrchestrator/index.js.map +1 -1
  27. package/dist/esm/platform/OAuth2Client.js +4 -7
  28. package/dist/esm/platform/OAuth2Client.js.map +1 -1
  29. package/dist/esm/platform/defaults.js.map +1 -1
  30. package/dist/esm/platform/index.js.map +1 -1
  31. package/dist/esm/utils/IndexedDBStore.js +27 -18
  32. package/dist/esm/utils/IndexedDBStore.js.map +1 -1
  33. package/dist/esm/utils/SynchronizedResult.js +53 -60
  34. package/dist/esm/utils/SynchronizedResult.js.map +1 -1
  35. package/dist/esm/utils/isModernBrowser.js.map +1 -1
  36. package/dist/types/Credential/Credential.d.ts +8 -2
  37. package/dist/types/Credential/TokenStorage.d.ts +25 -1
  38. package/dist/types/FetchClient/index.d.ts +6 -0
  39. package/dist/types/core.d.ts +19 -0
  40. package/dist/types/flows/AuthorizationCodeFlow.d.ts +63 -13
  41. package/dist/types/flows/SessionLogoutFlow.d.ts +24 -0
  42. package/dist/types/flows/TransactionStorage.d.ts +7 -0
  43. package/dist/types/flows/index.d.ts +15 -2
  44. package/dist/types/flows.d.ts +9 -0
  45. package/dist/types/index.d.ts +1 -14
  46. package/dist/types/orchestrators/AuthorizationCodeFlowOrchestrator.d.ts +40 -6
  47. package/dist/types/orchestrators/HostOrchestrator/Host.d.ts +15 -0
  48. package/dist/types/orchestrators/HostOrchestrator/OrchestrationBridge.d.ts +4 -0
  49. package/dist/types/orchestrators/HostOrchestrator/SubApp.d.ts +13 -2
  50. package/dist/types/orchestrators/HostOrchestrator/index.d.ts +50 -16
  51. package/dist/types/orchestrators/index.d.ts +4 -1
  52. package/dist/types/platform/OAuth2Client.d.ts +9 -3
  53. package/dist/types/platform/defaults.d.ts +8 -0
  54. package/dist/types/platform/index.d.ts +6 -0
  55. package/dist/types/utils/IndexedDBStore.d.ts +1 -0
  56. package/dist/types/utils/SynchronizedResult.d.ts +1 -8
  57. package/dist/types/utils/isModernBrowser.d.ts +2 -1
  58. package/package.json +1 -1
@@ -1,5 +1,13 @@
1
+ /**
2
+ * @module
3
+ * @mergeModuleWith Orchestrators
4
+ */
1
5
  import type { HostOrchestrator as HO } from './index.ts';
2
6
  import { Token, EventEmitter, type Emitter, TokenOrchestrator } from '@okta/auth-foundation/core';
7
+ /**
8
+ * Receives and fulfills delegated {@link AuthFoundation!Token | Token} requests from `HostOrchestrator.SubApp` instances
9
+ * @noNamespaceMerge
10
+ */
3
11
  export declare abstract class HostOrchestrator<E extends HO.HostEvents = HO.HostEvents> implements Emitter<E> {
4
12
  #private;
5
13
  protected readonly name: string;
@@ -12,10 +20,17 @@ export declare abstract class HostOrchestrator<E extends HO.HostEvents = HO.Host
12
20
  protected shouldActive(): boolean;
13
21
  activate(): void;
14
22
  close(): void;
23
+ /** @internal */
15
24
  protected parseRequest<K extends keyof HO.RequestEvent>(request: HO.RequestEvent[K], replyFn: any): Promise<any>;
25
+ /** @internal */
16
26
  protected handleHostActivated({ hostId }: HO.ActivatedEvent): void;
27
+ /** @internal */
17
28
  protected handleTokenRequest(event: HO.TokenRequest): Promise<HO.TokenResponse>;
29
+ /** @internal */
18
30
  protected handleAuthorizeRequest(event: HO.AuthorizeRequest): Promise<HO.AuthorizeResponse>;
31
+ /** @internal */
19
32
  protected handleProfileRequest(event: HO.TokenRequest): Promise<HO.ProfileResponse>;
33
+ protected handleInvalidateRequest(event: HO.InvalidateRequest): Promise<HO.InvalidateResponse>;
20
34
  abstract findToken(params: TokenOrchestrator.AuthorizeParams): Promise<Token | null | HO.ErrorResponse>;
35
+ abstract invalidateToken(tokenId: string): Promise<HO.InvalidateResponse>;
21
36
  }
@@ -1,3 +1,7 @@
1
+ /**
2
+ * @packageDocumentation
3
+ * @internal
4
+ */
1
5
  import type { HostOrchestrator } from './index.ts';
2
6
  import { TaskBridge } from '@okta/auth-foundation/core';
3
7
  export declare class OrchestrationBridge extends TaskBridge<HostOrchestrator.RequestEvent, HostOrchestrator.ResponseEvent> {
@@ -1,8 +1,18 @@
1
+ /**
2
+ * @module
3
+ * @mergeModuleWith Orchestrators
4
+ */
1
5
  import type { HostOrchestrator as HO } from './index.ts';
2
6
  import { Token, TokenOrchestrator, EventEmitter } from '@okta/auth-foundation/core';
3
7
  export type SubAppBroadcastOptions = {
4
8
  timeout: number;
5
9
  };
10
+ /**
11
+ * An implementation of {@link TokenOrchestrator} which delegates all token retrieval to a centralized broker,
12
+ * rather than acquiring tokens itself
13
+ *
14
+ * @overridePath orchestrators/HostOrchestrator/classes/SubApp.md
15
+ */
6
16
  export declare class SubAppOrchestrator<E extends HO.SubAppEvents = HO.SubAppEvents> extends TokenOrchestrator<E> {
7
17
  #private;
8
18
  readonly name: string;
@@ -20,10 +30,11 @@ export declare class SubAppOrchestrator<E extends HO.SubAppEvents = HO.SubAppEve
20
30
  }): Promise<boolean>;
21
31
  protected requestToken(params: TokenOrchestrator.AuthorizeParams): Promise<Token | null>;
22
32
  /**
23
- * Retrieves a valid {@link Platform.Token | Token} to be used within an application
33
+ * Retrieves a valid {@link AuthFoundation!Token | Token} to be used within an application
24
34
  */
25
35
  getToken(params?: TokenOrchestrator.AuthorizeParams): Promise<Token | null>;
26
36
  authorize(input: string | URL | Request, init?: RequestInit & {
27
37
  dpopNonce?: string;
28
- } & TokenOrchestrator.AuthorizeParams): Promise<Request>;
38
+ } & TokenOrchestrator.AuthorizeParams): ReturnType<TokenOrchestrator['authorize']>;
39
+ invalidateToken(id: string): Promise<void>;
29
40
  }
@@ -1,42 +1,44 @@
1
1
  /**
2
2
  * @module
3
- * @mergeModuleWith TokenOrchestrators
3
+ * @mergeModuleWith Orchestrators
4
4
  */
5
5
  import { type TokenOrchestrator, type AcrValues, type JsonRecord, type TokenPrimitiveInit, Token } from '@okta/auth-foundation/core';
6
6
  import { HostOrchestrator as HostApp } from './Host.ts';
7
7
  import { SubAppOrchestrator } from './SubApp.ts';
8
+ /**
9
+ * @overrideContent orchestrators/HostOrchestrator/doc.md
10
+ * @overridePath orchestrators/HostOrchestrator
11
+ */
8
12
  export declare namespace HostOrchestrator {
9
13
  /**
10
- * Receives and fulfills delegated {@link Platform.Token | Token} requests from {@link HostOrchestrator.SubApp} instances
11
- *
12
- * @group Host
14
+ * @reexport
13
15
  */
14
- abstract class Host<E extends HostEvents = HostEvents> extends HostApp<E> {
15
- }
16
+ const Host: typeof HostApp;
17
+ type Host<E extends HostEvents = HostEvents> = InstanceType<typeof HostApp<E>>;
16
18
  /**
17
- * A {@link AuthFoundation!TokenOrchestrator | TokenOrchestrator} instance which delegates all {@link Platform.Token | Token}
18
- * requests to a {@link HostOrchestrator.Host}
19
- *
20
- * @group SubApp
19
+ * @reexport
21
20
  */
22
- class SubApp<E extends SubAppEvents = SubAppEvents> extends SubAppOrchestrator<E> {
23
- }
21
+ const SubApp: typeof SubAppOrchestrator;
22
+ type SubApp<E extends SubAppEvents = SubAppEvents> = InstanceType<typeof SubAppOrchestrator<E>>;
24
23
  /**
25
- * A utility class to adapt any {@link AuthFoundation!TokenOrchestrator | TokenOrchestrator} instance into a {@link HostOrchestrator.Host}
24
+ * A utility class to adapt any {@link AuthFoundation!TokenOrchestrator | TokenOrchestrator} instance into a {@link HostOrchestrator}
26
25
  * @group ProxyHost
27
26
  */
28
27
  class ProxyHost<E extends HostEvents = HostEvents> extends HostOrchestrator.Host<E> {
29
28
  protected readonly orchestrator: Exclude<TokenOrchestrator, HostOrchestrator.SubApp>;
30
29
  constructor(name: string, orchestrator: Exclude<TokenOrchestrator, HostOrchestrator.SubApp>);
31
30
  findToken(params?: TokenOrchestrator.AuthorizeParams): Promise<Token | ErrorResponse>;
31
+ invalidateToken(tokenId: string): Promise<Partial<ErrorResponse>>;
32
32
  }
33
33
  /**
34
+ *
34
35
  * @group Host
35
36
  */
36
37
  type HostOptions = {
37
38
  allowedOrigins?: string[];
38
39
  };
39
40
  /**
41
+ * Map of events which can be emitted from {@link HostOrchestrator.emitter}
40
42
  * @group Host
41
43
  */
42
44
  type HostEvents = {
@@ -67,6 +69,7 @@ export declare namespace HostOrchestrator {
67
69
  } & TokenOrchestrator.Events;
68
70
  /**
69
71
  * @group Types
72
+ * @internal
70
73
  */
71
74
  type TokenRequestEventPayloads = {
72
75
  'TOKEN': TokenRequest;
@@ -74,9 +77,11 @@ export declare namespace HostOrchestrator {
74
77
  'PROFILE': TokenRequest;
75
78
  };
76
79
  /**
77
- * @group Types
78
80
  * Payload for "host_activated" events.
79
81
  * Sent once a {@link HostOrchestrator.Host} instantiates. Used to detect multiple hosts
82
+ *
83
+ * @group Types
84
+ * @internal
80
85
  */
81
86
  type ActivatedEvent = {
82
87
  eventName: 'ACTIVATED';
@@ -85,6 +90,7 @@ export declare namespace HostOrchestrator {
85
90
  };
86
91
  /**
87
92
  * @group Types
93
+ * @internal
88
94
  */
89
95
  type PingEvent = {
90
96
  eventName: 'PING';
@@ -92,8 +98,19 @@ export declare namespace HostOrchestrator {
92
98
  };
93
99
  /**
94
100
  * @group Types
95
- * Lose typing of the request event object structure. Provides slightly more type-safety than
101
+ */
102
+ type InvalidateEvent = {
103
+ eventName: 'INVALIDATE';
104
+ data: {
105
+ tokenId: string;
106
+ };
107
+ };
108
+ /**
109
+ * Loose typing of the request event object structure. Provides slightly more type-safety than
96
110
  * using `any` or `unknown` like most generic messaging APIs
111
+ *
112
+ * @group Types
113
+ * @internal
97
114
  */
98
115
  type RequestEvent = ({
99
116
  [K in keyof TokenRequestEventPayloads]: {
@@ -105,9 +122,11 @@ export declare namespace HostOrchestrator {
105
122
  } & {
106
123
  ACTIVATED: ActivatedEvent;
107
124
  PING: PingEvent;
125
+ INVALIDATE: InvalidateEvent;
108
126
  });
109
127
  /**
110
128
  * @group Types
129
+ * @internal
111
130
  */
112
131
  type TokenRequest = {
113
132
  issuer?: string;
@@ -118,15 +137,19 @@ export declare namespace HostOrchestrator {
118
137
  };
119
138
  /**
120
139
  * @group Types
140
+ * @internal
121
141
  */
122
142
  type AuthorizeRequest = TokenRequest & {
123
143
  url?: string;
124
144
  method?: string;
125
145
  nonce?: string;
126
146
  };
147
+ /** @group Types */
148
+ type InvalidateRequest = InvalidateEvent['data'];
127
149
  /**
128
- * @group Types
129
150
  * Map of responses from a HostOrchestrator request event
151
+ * @group Types
152
+ * @internal
130
153
  */
131
154
  type ResponseEvent = {
132
155
  'TOKEN': TokenResponse;
@@ -134,37 +157,48 @@ export declare namespace HostOrchestrator {
134
157
  'PROFILE': ProfileResponse;
135
158
  'PING': PingResponse;
136
159
  'ACTIVATED': object;
160
+ 'INVALIDATE': InvalidateResponse;
137
161
  };
138
162
  /**
139
163
  * @group Types
164
+ * @internal
140
165
  */
141
166
  type ErrorResponse = {
142
167
  error: string;
143
168
  };
144
169
  /**
145
170
  * @group Types
171
+ * @internal
146
172
  */
147
173
  type PingResponse = {
148
174
  message: 'PONG';
149
175
  };
150
176
  /**
151
177
  * @group Types
178
+ * @internal
152
179
  */
153
180
  type TokenResponse = {
154
181
  token: TokenPrimitiveInit;
155
182
  } | ErrorResponse;
156
183
  /**
157
184
  * @group Types
185
+ * @internal
158
186
  */
159
187
  type AuthorizeResponse = {
188
+ tokenId: string;
160
189
  tokenType: string;
161
190
  dpop?: string;
162
191
  authorization: string;
163
192
  } | ErrorResponse;
164
193
  /**
165
194
  * @group Types
195
+ * @internal
166
196
  */
167
197
  type ProfileResponse = {
168
198
  profile: JsonRecord;
169
199
  } | ErrorResponse;
200
+ /**
201
+ * @group Types
202
+ */
203
+ type InvalidateResponse = Partial<ErrorResponse>;
170
204
  }
@@ -1,5 +1,8 @@
1
1
  /**
2
- * @module TokenOrchestrators
2
+ * Browser-specific implementations of {@link AuthFoundation!TokenOrchestrator | TokenOrchestrator}.
3
+ *
4
+ * @module Orchestrators
5
+ * @overrideContent orchestrators/doc.md
3
6
  */
4
7
  export * from './AuthorizationCodeFlowOrchestrator.ts';
5
8
  export * from './HostOrchestrator/index.ts';
@@ -1,13 +1,19 @@
1
1
  /**
2
- * @module
3
- * @mergeModuleWith Platform
2
+ * @packageDocumentation
3
+ * @internal
4
+ *
5
+ * Does not differ enough from base class to require further documentation
4
6
  */
5
7
  import { Token, OAuth2Client as OAuth2ClientBase, OAuth2ErrorResponse } from '@okta/auth-foundation/core';
6
8
  /**
7
9
  * Browser-specific implementation of {@link OAuth2Client}
8
10
  *
11
+ * @remarks
12
+ * Utilizies {@link SynchronizedResult} to prevent race conditions when using refresh tokens.
13
+ *
9
14
  * @group OAuth2Client
15
+ * @internal
10
16
  */
11
17
  export declare class OAuth2Client extends OAuth2ClientBase {
12
- protected prepareRefreshRequest(token: Token, scopes?: string[]): Promise<Token | OAuth2ErrorResponse>;
18
+ protected sendRefreshRequest(request: Token.RefreshRequest, context: OAuth2ClientBase.TokenRequestContext): Promise<OAuth2ErrorResponse | Token>;
13
19
  }
@@ -1,2 +1,10 @@
1
+ /**
2
+ * @module
3
+ * @mergeModuleWith Platform
4
+ */
1
5
  import { type PlatformDependencies } from '@okta/auth-foundation/core';
6
+ /**
7
+ * {@link AuthFoundation!PlatformDependencies | PlatformDependencies} implementations designed for browsers
8
+ *
9
+ */
2
10
  export declare const PlatformDefaults: PlatformDependencies;
@@ -1,5 +1,11 @@
1
1
  /**
2
+ * > [!Tip]
3
+ * > See {@link AuthFoundation!Platform | Platform} explanation first.
4
+ *
5
+ * Provides browser-specific default implementations of
6
+ * {@link AuthFoundation!PlatformDependencies | PlatformDependencies}
2
7
  * @module Platform
8
+ * @see [SPA Platform: Platform](/api/spa-platform/#platform)
3
9
  */
4
10
  export * from './OAuth2Client.ts';
5
11
  /**
@@ -9,6 +9,7 @@
9
9
  */
10
10
  export declare class IndexedDBStore<T> {
11
11
  private readonly storeName;
12
+ static upgradeBlockedTimeoutMs: number;
12
13
  private readonly dbName;
13
14
  constructor(storeName: string);
14
15
  private keyStore;
@@ -4,8 +4,6 @@
4
4
  */
5
5
  export type SynchronizedResultOptions<T = any, R = any> = {
6
6
  timeout: number;
7
- lockFreedDelay: number;
8
- retries: number;
9
7
  seralizer?: (obj: T) => R;
10
8
  deseralizer?: (input: R) => T;
11
9
  };
@@ -24,12 +22,7 @@ export declare class SynchronizedResult<T, R = T> {
24
22
  private channel;
25
23
  private options;
26
24
  constructor(name: string, task: () => Promise<T>, options?: Partial<SynchronizedResultOptions<T, R>>);
27
- private onResultFromOtherTab;
28
- private onLockFreedPlusDelay;
29
- private onTimeout;
30
- private whenLockIsTaken;
31
- private whenLockIsGranted;
32
- exec(overrides?: Partial<SynchronizedResultOptions<T, R>>): Promise<T>;
25
+ exec(): Promise<T>;
33
26
  /**
34
27
  * Closes the underlying BroadcastChannel, useful for testing environments to avoid open handles
35
28
  *
@@ -1,5 +1,6 @@
1
1
  /**
2
- * @module Utils
2
+ * @module
3
+ * @mergeModuleWith Platform
3
4
  */
4
5
  /**
5
6
  * Verifies the browser supports all features this library depends on
package/package.json CHANGED
@@ -1 +1 @@
1
- {"name":"@okta/spa-platform","version":"0.6.0","type":"module","main":"dist/esm/index.js","module":"dist/esm/index.js","types":"dist/types/index.d.ts","license":"Apache-2.0","files":["./LICENSE","./dist","*.md","package.json"],"exports":{".":{"types":"./dist/types/index.d.ts","import":"./dist/esm/index.js"},"./package.json":"./package.json"},"scripts":{"lint":"eslint --ext .js,.ts,.jsx .","build":"yarn build:esm && yarn build:types","build:watch":"yarn build:esm --watch & yarn build:types --watch","build:esm":"rollup -c","build:types":"tsc","test":"yarn test:unit","test:watch":"jest --watchAll","test:unit":"jest"},"dependencies":{},"peerDependencies":{"@okta/auth-foundation":"*","@okta/oauth2-flows":"*"},"peerDependenciesMeta":{"@okta/oauth2-flows":{"optional":true}},"devDependencies":{"@repo/eslint-config":"*","@repo/jest-helpers":"*","@repo/typescript-config":"*","@repo/rollup-config":"*","@okta/auth-foundation":"*","@okta/oauth2-flows":"*","eslint":"^8.56.0","jest":"^29.7.0","rollup":"^4.52.4","typescript":"^5.9.2"},"devEngines":{"runtime":{"name":"node","version":">=22.13.1","onFail":"warn"},"packageManager":{"name":"yarn","version":">=1.19.0","onFail":"warn"}},"okta":{"commitSha":"533d076fb5f59d4214751d8414be8f0f3adac2f5","fullVersion":"0.6.0-g533d076-g533d076"}}
1
+ {"name":"@okta/spa-platform","version":"0.9.0","type":"module","main":"dist/esm/index.js","module":"dist/esm/index.js","types":"dist/types/index.d.ts","license":"Apache-2.0","files":["./LICENSE","./dist","*.md","package.json"],"exports":{".":{"types":"./dist/types/index.d.ts","import":"./dist/esm/index.js"},"./flows":{"types":"./dist/types/flows.d.ts","import":"./dist/esm/flows.js"},"./package.json":"./package.json"},"scripts":{"lint":"eslint --ext .js,.ts,.jsx .","build":"yarn build:esm && yarn build:types","build:watch":"yarn build:esm --watch & yarn build:types --watch","build:esm":"rollup -c","build:types":"tsc","test":"yarn test:unit","test:watch":"jest --watchAll","test:unit":"jest"},"dependencies":{},"peerDependencies":{"@okta/auth-foundation":"~0.9.*","@okta/oauth2-flows":"~0.9.*"},"peerDependenciesMeta":{"@okta/oauth2-flows":{"optional":true}},"devDependencies":{"@repo/eslint-config":"*","@repo/jest-helpers":"*","@repo/typescript-config":"*","@repo/rollup-config":"*","@okta/auth-foundation":"*","@okta/oauth2-flows":"*","eslint":"^8.56.0","fake-indexeddb":"^6.0.0","jest":"^29.7.0","rollup":"^4.52.4","typescript":"^5.9.2"},"devEngines":{"runtime":{"name":"node","version":">=22.13.1","onFail":"warn"},"packageManager":{"name":"yarn","version":">=1.19.0","onFail":"warn"}},"okta":{"commitSha":"a777274f98680847ae55a4d34a7101e07104c359","fullVersion":"0.9.0-ga777274-ga777274"}}