@monterosa/sdk-identify-kit 2.0.0-rc.4 → 2.0.0-rc.6

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/dist/api.d.ts CHANGED
@@ -24,26 +24,18 @@ export declare const identifyKits: Map<string, Identify>;
24
24
  */
25
25
  export declare function getLoginPolicy(): LoginPolicy;
26
26
  /**
27
- * Set the locally-owned login policy.
27
+ * Set the login policy.
28
28
  *
29
- * All `Identify` instances at this level honour the same policy; the
30
- * value is never propagated across the wire (each level of a multi-level
31
- * integration owns its own policy).
29
+ * - `'auto'`: the SDK automatically logs the user in whenever
30
+ * credentials are available.
31
+ * - `'disabled'`: credentials are tracked but no automatic login is
32
+ * attempted.
32
33
  *
33
- * Policy gates the Enmasse `loginTask` only credentials always mirror
34
- * from upstream regardless of policy. A `'disabled'` level still
35
- * receives credentials via the module-load pull and the cascading
36
- * `Login` / `Logout` broadcasts; it just doesn't attempt Enmasse
37
- * validation against them.
34
+ * Each level of a multi-level integration owns its own policy; the
35
+ * value is never propagated to embedded experiences. Idempotent:
36
+ * setting the same policy is a no-op.
38
37
  *
39
- * When the policy transitions to `'auto'`, enqueues a sync-state task
40
- * for every existing identify so that any in-flight session is picked
41
- * up.
42
- *
43
- * Idempotent: setting the same policy that's already in effect is a
44
- * no-op.
45
- *
46
- * @param policy - `'auto'` to enable auto-login, `'disabled'` to opt out.
38
+ * @param policy - `'auto'` or `'disabled'`.
47
39
  */
48
40
  export declare function setLoginPolicy(policy: LoginPolicy): void;
49
41
  /**
@@ -86,22 +78,24 @@ export declare function enqueueLogin(identify: IdentifyKit, credentials: Credent
86
78
  */
87
79
  export declare function enqueueLogout(identify: IdentifyKit): void;
88
80
  /**
89
- * Apply new credentials at this level: update the slot, enqueue a
90
- * `loginTask` for every existing identify on the null-to-set transition,
91
- * and broadcast `Login` downstream to every embedded experience.
81
+ * Apply new credentials at this level: update the current credentials,
82
+ * enqueue a `loginTask` for every existing identify on the null-to-set
83
+ * transition, and broadcast `Login` downstream to every embedded
84
+ * experience.
92
85
  *
93
- * Idempotent on token refresh: re-setting an already-set slot updates
94
- * the value and broadcasts, but does not re-enqueue logins (their
95
- * `loginTask` would short-circuit on `state === 'logged_in'` anyway).
86
+ * Idempotent on token refresh: re-setting when credentials are already
87
+ * present updates the value and broadcasts, but does not re-enqueue
88
+ * logins (their `loginTask` would short-circuit on
89
+ * `state === 'logged_in'` anyway).
96
90
  *
97
91
  * @internal
98
92
  */
99
93
  export declare function applyLogin(credentials: Credentials): void;
100
94
  /**
101
- * Clear credentials at this level: null out the slot, enqueue a
102
- * `logoutTask` for every existing identify on the set-to-null
103
- * transition, and broadcast `Logout` downstream to every embedded
104
- * experience.
95
+ * Clear credentials at this level: clear the current credentials,
96
+ * enqueue a `logoutTask` for every existing identify on the
97
+ * set-to-null transition, and broadcast `Logout` downstream to every
98
+ * embedded experience.
105
99
  *
106
100
  * @internal
107
101
  */
@@ -113,18 +107,20 @@ export declare function applyLogout(): void;
113
107
  * `loginPolicy` — token presence is the customer-side sign-in state and
114
108
  * must mirror upstream whether or not we choose to validate against
115
109
  * Enmasse. Best-effort: a missing or non-identify-kit parent silently
116
- * resolves with no slot change.
110
+ * resolves with no change to the current credentials.
117
111
  *
118
- * Uses {@link applyLogin} so the slot update cascades downstream to
119
- * this level's own embedded experiences and per-identify loginTasks
120
- * are enqueued under `loginPolicy === 'auto'`.
112
+ * Uses {@link applyLogin} so the update cascades downstream to this
113
+ * level's own embedded experiences and per-identify loginTasks are
114
+ * enqueued under `loginPolicy === 'auto'`.
121
115
  *
122
116
  * @internal
123
117
  */
124
118
  export declare function pullStateFromParent(): Promise<void>;
125
119
  /**
126
- * A factory function that creates a new instance of the `IdentifyKit` class,
127
- * which is a kit of the Monterosa SDK used for user identification.
120
+ * Get the IdentifyKit instance for the given SDK / project.
121
+ *
122
+ * The IdentifyKit instance is used to authenticate users and read
123
+ * user data.
128
124
  *
129
125
  * @example
130
126
  * ```javascript
@@ -137,25 +133,19 @@ export declare function pullStateFromParent(): Promise<void>;
137
133
  * ```
138
134
  *
139
135
  * @remarks
140
- * - The `getIdentify` function returns an instance of the `IdentifyKit` class
141
- * using optional MonterosaSdk instance as a parameter.
142
- *
143
- * - The `IdentifyKit` instance returned by `getIdentify` can be used to authenticate
144
- * users and perform other user identification-related operations.
136
+ * First-call-wins: subsequent calls for the same project return the
137
+ * cached instance and ignore the `options` argument.
145
138
  *
146
- * - Subsequent calls return the cached `IdentifyKit` instance for the same
147
- * project. The `options` argument is honoured only on the first call;
148
- * later calls ignore it and return the instance configured by the first.
149
- *
150
- * @param sdk - An instance of the MonterosaSdk class.
151
- * @param options - List of `IdentifyKit` options
152
- * @returns An instance of the `IdentifyKit` class, which is used for user
153
- * identification.
139
+ * @param sdk - The Monterosa SDK instance.
140
+ * @param options - IdentifyKit options (applied only on the first call).
141
+ * @returns The IdentifyKit instance for the project.
154
142
  */
155
143
  export declare function getIdentify(sdk?: MonterosaSdk, options?: Partial<IdentifyOptions>): IdentifyKit;
156
144
  /**
157
- * A factory function that creates a new instance of the `IdentifyKit` class,
158
- * which is a kit of the Monterosa SDK used for user identification.
145
+ * Get the IdentifyKit instance for the configured SDK.
146
+ *
147
+ * The IdentifyKit instance is used to authenticate users and read
148
+ * user data.
159
149
  *
160
150
  * @example
161
151
  * ```javascript
@@ -168,23 +158,18 @@ export declare function getIdentify(sdk?: MonterosaSdk, options?: Partial<Identi
168
158
  * ```
169
159
  *
170
160
  * @remarks
171
- * - The `getIdentify` function returns an instance of the `IdentifyKit` class
172
- * using optional MonterosaSdk instance as a parameter.
161
+ * First-call-wins: subsequent calls for the same project return the
162
+ * cached instance and ignore the `options` argument.
173
163
  *
174
- * - The `IdentifyKit` instance returned by `getIdentify` can be used to authenticate
175
- * users and perform other user identification-related operations.
176
- *
177
- * - Subsequent calls return the cached `IdentifyKit` instance for the same
178
- * project. The `options` argument is honoured only on the first call;
179
- * later calls ignore it and return the instance configured by the first.
180
- *
181
- * @param options - List of `IdentifyKit` options
182
- * @returns An instance of the `IdentifyKit` class, which is used for user
183
- * identification.
164
+ * @param options - IdentifyKit options (applied only on the first call).
165
+ * @returns The IdentifyKit instance for the project.
184
166
  */
185
167
  export declare function getIdentify(options?: Partial<IdentifyOptions>): IdentifyKit;
186
168
  /**
187
- * Requests a user login.
169
+ * Request a user login.
170
+ *
171
+ * When called from an embedded experience, the request is relayed to
172
+ * the parent application — the host that owns the auth UI handles it.
188
173
  *
189
174
  * @example
190
175
  * ```javascript
@@ -195,37 +180,32 @@ export declare function getIdentify(options?: Partial<IdentifyOptions>): Identif
195
180
  *
196
181
  * try {
197
182
  * await requestLogin();
198
- *
199
183
  * console.log('Login request successful');
200
184
  * } catch (err) {
201
185
  * console.error('Error requesting login:', err.message)
202
186
  * }
203
187
  * ```
204
188
  *
205
- * @remarks
206
- * - If the app is running within a third-party application that uses
207
- * the Monterosa SDK, the function delegates to the parent app
208
- * to handle the login process.
209
- *
210
- * @returns A Promise that resolves with `void` when the login request
211
- * is completed.
189
+ * @returns A Promise that resolves once the login request has been
190
+ * delivered.
212
191
  */
213
192
  export declare function requestLogin(): Promise<void>;
214
193
  /**
215
- * Read the current credentials, pulling from the parent application when
216
- * called from an embedded experience.
194
+ * Read the current credentials.
217
195
  *
218
- * At the root this returns the canonical slot value. At a non-root
219
- * experience this dispatches a `GetCredentials` request upstream and
220
- * resolves with the response, ensuring the caller always sees the
221
- * authoritative value rather than a possibly-stale local mirror.
196
+ * When called from an embedded experience, fetches the credentials
197
+ * from the parent application so the caller always sees the
198
+ * authoritative value.
222
199
  *
223
- * @returns A Promise that resolves to the current credentials, or `null`
224
- * if none are set.
200
+ * @returns A Promise that resolves to the current credentials, or
201
+ * `null` if none are set.
225
202
  */
226
203
  export declare function getCredentials(): Promise<Credentials | null>;
227
204
  /**
228
- * Requests a user logout.
205
+ * Request a user logout.
206
+ *
207
+ * When called from an embedded experience, the request is relayed to
208
+ * the parent application — the host that owns the auth UI handles it.
229
209
  *
230
210
  * @example
231
211
  * ```javascript
@@ -236,20 +216,14 @@ export declare function getCredentials(): Promise<Credentials | null>;
236
216
  *
237
217
  * try {
238
218
  * await requestLogout();
239
- *
240
219
  * console.log('Logout request successful');
241
220
  * } catch (err) {
242
221
  * console.error('Error requesting logout:', err.message)
243
222
  * }
244
223
  * ```
245
224
  *
246
- * @remarks
247
- * - If the app is running within a third-party application that uses
248
- * the Monterosa SDK, the function delegates to the parent app
249
- * to handle the logout process.
250
- *
251
- * @returns A Promise that resolves with `void` when the logout request
252
- * is completed.
225
+ * @returns A Promise that resolves once the logout request has been
226
+ * delivered.
253
227
  */
254
228
  export declare function requestLogout(): Promise<void>;
255
229
  /**
@@ -270,18 +244,18 @@ export declare function requestLogout(): Promise<void>;
270
244
  */
271
245
  export declare function getSessionSignature(identify: IdentifyKit, credentials: Credentials): Promise<Signature>;
272
246
  /**
247
+ * @internal
248
+ *
273
249
  * A memoized version of the `getSessionSignature` function. Memo key is
274
250
  * the credentials token, so both leaf-side and bridge-side callers share
275
251
  * the same cache for the same token.
276
252
  */
277
253
  export declare const getSessionSignatureMemoized: (...args: any[]) => Promise<Signature>;
278
254
  /**
279
- * Fetches user data for the given credentials.
255
+ * Fetch user data for the given credentials.
280
256
  *
281
- * Credentials are required explicitly so the precondition is visible at
282
- * the call site — without them the function cannot be called. Obtain a
283
- * `Credentials` value via {@link getCredentials} or the
284
- * {@link onCredentialsUpdated} callback.
257
+ * Credentials are required explicitly. Obtain a value via
258
+ * {@link getCredentials} or the {@link onCredentialsUpdated} callback.
285
259
  *
286
260
  * @example
287
261
  * ```javascript
@@ -304,20 +278,22 @@ export declare const getSessionSignatureMemoized: (...args: any[]) => Promise<Si
304
278
  * ```
305
279
  *
306
280
  * @remarks
307
- * Cached on the identify instance after the first successful fetch.
308
- * Cleared on {@link clearCredentials} via the logout path.
309
- *
310
- * @param identify - An instance of `IdentifyKit` that provides the user
311
- * identification functionality.
312
- * @param credentials - The user's authentication credentials. The
313
- * request authorises against the value's token.
314
- * @returns A Promise that resolves to a key-value object representing
315
- * user data. The structure and content of the user data object depend
316
- * on the identify service provider and may vary.
281
+ * Cached after the first successful fetch and reset when credentials
282
+ * are cleared.
283
+ *
284
+ * @param identify - The IdentifyKit instance.
285
+ * @param credentials - The user's authentication credentials.
286
+ * @returns A Promise that resolves to a key-value object of user data.
287
+ * The structure depends on the identify service provider.
317
288
  */
318
289
  export declare function getUserData(identify: IdentifyKit, credentials: Credentials): Promise<UserData>;
319
290
  /**
320
- * Sets the user's authentication credentials.
291
+ * Set the user's authentication credentials.
292
+ *
293
+ * The credentials become the active credentials for the entire
294
+ * integration. When called from an embedded experience, the call is
295
+ * relayed to the parent application so that every level of the
296
+ * integration sees the new value.
321
297
  *
322
298
  * @example
323
299
  * ```javascript
@@ -329,22 +305,17 @@ export declare function getUserData(identify: IdentifyKit, credentials: Credenti
329
305
  * await setCredentials({ token: 'abc123' });
330
306
  * ```
331
307
  *
332
- * @remarks
333
- * - At the root of an integration, the credentials are stored locally
334
- * and a `Login` broadcast is sent to every embedded experience.
335
- * - When called from an embedded experience, the call is relayed
336
- * upstream via the `SetCredentials` wire action. The credentials are
337
- * ultimately applied at the root and propagate back down via the
338
- * cascading `Login` broadcast.
339
- *
340
- * @param credentials - An object representing the user's authentication
341
- * credentials.
342
- * @returns A Promise that resolves to `void` once the credentials have
343
- * been written (root) or the upstream relay has completed (non-root).
308
+ * @param credentials - The user's authentication credentials.
309
+ * @returns A Promise that resolves once the credentials have been
310
+ * applied.
344
311
  */
345
312
  export declare function setCredentials(credentials: Credentials): Promise<void>;
346
313
  /**
347
- * Clears the user's authentication credentials.
314
+ * Clear the user's authentication credentials.
315
+ *
316
+ * When called from an embedded experience, the call is relayed to the
317
+ * parent application so that every level of the integration is
318
+ * cleared.
348
319
  *
349
320
  * @example
350
321
  * ```javascript
@@ -356,21 +327,12 @@ export declare function setCredentials(credentials: Credentials): Promise<void>;
356
327
  * await clearCredentials();
357
328
  * ```
358
329
  *
359
- * @remarks
360
- * - At the root of an integration, the credentials slot is cleared and
361
- * a `Logout` broadcast is sent to every embedded experience.
362
- * - When called from an embedded experience, the call is relayed
363
- * upstream via the `ClearCredentials` wire action. The slot is
364
- * cleared at the root and the cascading `Logout` broadcast propagates
365
- * back down.
366
- *
367
- * @returns A Promise that resolves to `void` once the slot has been
368
- * cleared (root) or the upstream relay has completed (non-root).
330
+ * @returns A Promise that resolves once the credentials have been
331
+ * cleared.
369
332
  */
370
333
  export declare function clearCredentials(): Promise<void>;
371
334
  /**
372
- * Registers a callback function that will be called whenever the `LoginState`
373
- * object associated with the `IdentifyKit` instance is updated.
335
+ * Register a callback for `LoginState` updates on the given identify.
374
336
  *
375
337
  * @example
376
338
  * ```javascript
@@ -384,22 +346,15 @@ export declare function clearCredentials(): Promise<void>;
384
346
  * const unsubscribe = onStateUpdated(identify, (state) => {
385
347
  * console.log("State updated:", state);
386
348
  * });
387
- *
388
- * // Call unsubscribe() to unregister the callback function
389
- * // unsubscribe();
390
349
  * ```
391
350
  *
392
- * @param identify - An instance of `IdentifyKit` that provides the user
393
- * identification functionality.
394
- * @param callback - The callback function to register. This function will be
395
- * called with the updated `LoginState` object as its only argument.
396
- * @returns An `Unsubscribe` function that can be called to unregister
397
- * the callback function.
351
+ * @param identify - The IdentifyKit instance.
352
+ * @param callback - Called with the updated `LoginState`.
353
+ * @returns An `Unsubscribe` function.
398
354
  */
399
355
  export declare function onStateUpdated(identify: IdentifyKit, callback: (state: LoginState) => void): Unsubscribe;
400
356
  /**
401
- * Registers a callback function that will be called whenever the
402
- * credentials slot is updated.
357
+ * Register a callback for updates to the current credentials.
403
358
  *
404
359
  * @example
405
360
  * ```javascript
@@ -415,22 +370,18 @@ export declare function onStateUpdated(identify: IdentifyKit, callback: (state:
415
370
  * console.log("Credentials cleared.");
416
371
  * }
417
372
  * });
418
- *
419
- * // Call unsubscribe() to unregister the callback function
420
- * // unsubscribe();
421
373
  * ```
422
374
  *
423
- * @param callback - The callback function to register. This function will be
424
- * called with the updated `Credentials` object as its only argument.
425
- * If the value `null` is received, it indicates that the credentials have
426
- * been cleared.
427
- * @returns An `Unsubscribe` function that can be called to unregister
428
- * the callback function.
375
+ * @param callback - Called with the updated `Credentials`, or `null`
376
+ * when credentials are cleared.
377
+ * @returns An `Unsubscribe` function.
429
378
  */
430
379
  export declare function onCredentialsUpdated(callback: (credentials: Credentials | null) => void): Unsubscribe;
431
380
  /**
432
- * Registers a callback function that will be called when a login is requested
433
- * by an Experience.
381
+ * Register a callback for login requests.
382
+ *
383
+ * Fires when {@link requestLogin} is called at this level — whether by
384
+ * local code or relayed up from an embedded experience.
434
385
  *
435
386
  * @example
436
387
  * ```javascript
@@ -442,20 +393,17 @@ export declare function onCredentialsUpdated(callback: (credentials: Credentials
442
393
  * const unsubscribe = onLoginRequestedByExperience(() => {
443
394
  * showLoginForm();
444
395
  * });
445
- *
446
- * // Call unsubscribe() to unregister the callback function
447
- * // unsubscribe();
448
396
  * ```
449
397
  *
450
- * @param callback - The callback function to register. This function will
451
- * be called when a login is requested by an Experience.
452
- * @returns An `Unsubscribe` function that can be called to unregister
453
- * the callback function.
398
+ * @param callback - Called when a login is requested.
399
+ * @returns An `Unsubscribe` function.
454
400
  */
455
401
  export declare function onLoginRequestedByExperience(callback: () => void): Unsubscribe;
456
402
  /**
457
- * Registers a callback function that will be called when a logout is requested
458
- * by an Experience.
403
+ * Register a callback for logout requests.
404
+ *
405
+ * Fires when {@link requestLogout} is called at this level — whether
406
+ * by local code or relayed up from an embedded experience.
459
407
  *
460
408
  * @example
461
409
  * ```javascript
@@ -465,22 +413,15 @@ export declare function onLoginRequestedByExperience(callback: () => void): Unsu
465
413
  * configure({ host: '...', projectId: '...' });
466
414
  *
467
415
  * const unsubscribe = onLogoutRequestedByExperience(() => {
468
- * // logout requested by experience
469
- * // perform logout from Auth service
416
+ * // perform logout from auth service
470
417
  * });
471
- *
472
- * // Call unsubscribe() to unregister the callback function
473
- * // unsubscribe();
474
418
  * ```
475
419
  *
476
- * @param callback - The callback function to register. This function will
477
- * be called when a logout is requested by an Experience.
478
- * @returns An `Unsubscribe` function that can be called to unregister
479
- * the callback function.
420
+ * @param callback - Called when a logout is requested.
421
+ * @returns An `Unsubscribe` function.
480
422
  */
481
423
  export declare function onLogoutRequestedByExperience(callback: () => void): Unsubscribe;
482
424
  /**
483
- *
484
425
  * @internal
485
426
  */
486
427
  export declare function watchConnectionStatus(identify: IdentifyKit): Promise<void>;
package/dist/bridge.d.ts CHANGED
@@ -9,7 +9,7 @@
9
9
  import { Experience, ExperienceState, Message } from '@monterosa/sdk-launcher-kit';
10
10
  /**
11
11
  * Process an incoming `Login` / `Logout` broadcast from the parent
12
- * application. Updates the local credentials slot, enqueues login/logout
12
+ * application. Updates the local current credentials, enqueues login/logout
13
13
  * for every existing identify, and forwards the broadcast downstream to
14
14
  * this level's own embedded experiences — the mechanism that cascades a
15
15
  * root-level `setCredentials` through every nested experience.
@@ -9,7 +9,7 @@
9
9
  import { Emitter, Unsubscribe } from '@monterosa/sdk-util';
10
10
  import { Credentials } from './types';
11
11
  /**
12
- * Root-owned credentials slot.
12
+ * Root-owned credentials store.
13
13
  *
14
14
  * Single source of truth at the root of an integration; an internal
15
15
  * mirror at every other level, kept in sync via `Login` / `Logout`