@schibsted/account-sdk-browser 6.0.0-alpha.4 → 6.0.0-alpha.5

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.
@@ -1,12 +1,11 @@
1
- import { TinyEmitter } from 'tiny-emitter';
2
1
  import { default as Cache } from './cache.js';
3
- import { SessionUserId } from './identity.js';
4
2
  import { default as RESTClient } from './rest-client.js';
5
3
  import { HasAccessResult, MonetizationOptions } from './types/monetization.js';
4
+ import { SessionUserId } from './types/session.js';
6
5
  /**
7
6
  * Provides features related to monetization
8
7
  */
9
- export declare class Monetization extends TinyEmitter {
8
+ export declare class Monetization {
10
9
  cache: Cache;
11
10
  clientId: string;
12
11
  env: string;
@@ -42,17 +41,5 @@ export declare class Monetization extends TinyEmitter {
42
41
  * @param userId - id of currently logged in user
43
42
  */
44
43
  private _accessCacheKey;
45
- /**
46
- * Get the url for the end user to review the subscriptions
47
- * @param redirectUri
48
- * @returns - The url to the subscriptions review page
49
- */
50
- subscriptionsUrl(redirectUri?: string): string;
51
- /**
52
- * Get the url for the end user to review the products
53
- * @param redirectUri
54
- * @returns - The url to the products review page
55
- */
56
- productsUrl(redirectUri?: string): string;
57
44
  }
58
45
  export default Monetization;
@@ -8,6 +8,14 @@ export type AccountConfig = AccountBaseConfig & {
8
8
  /** Optional Varnish cookie setup applied during Account initialization. */
9
9
  varnish?: VarnishCookieOptions;
10
10
  };
11
- export type AccountSessionEventName = 'login' | 'logout' | 'userChange' | 'sessionChange' | 'notLoggedin' | 'sessionInit' | 'statusChange' | 'error' | 'simplifiedLoginOpened' | 'simplifiedLoginCancelled';
12
- export type AccountEventName = AccountSessionEventName | 'hasAccess';
11
+ /**
12
+ * Identity events emitted by the SDK.
13
+ *
14
+ * - `login`: emitted when `hasSession()` resolves with a logged-in user payload.
15
+ * - `logout`: emitted when a previously logged-in user is no longer logged in, or when
16
+ * `logout()` is called.
17
+ * - `simplifiedLoginOpened`: emitted when the simplified login widget is displayed.
18
+ * - `simplifiedLoginCancelled`: emitted when the simplified login widget is closed.
19
+ */
20
+ export type AccountEventName = 'login' | 'logout' | 'simplifiedLoginOpened' | 'simplifiedLoginCancelled';
13
21
  export type AccountEventHandler = (...args: unknown[]) => void;
@@ -12,24 +12,6 @@ export type IdentityOptions = AccountBaseConfig & {
12
12
  /** Callback triggered before a session refresh redirect happens. */
13
13
  callbackBeforeRedirect?: IdentityBeforeRedirectCallback;
14
14
  };
15
- /**
16
- * Identity events emitted by the SDK.
17
- *
18
- * - `login`: emitted when `hasSession()` resolves with a logged-in user payload.
19
- * - `logout`: emitted when a previously logged-in user is no longer logged in, or when
20
- * `logout()` is called.
21
- * - `userChange`: emitted when the current session user id changes.
22
- * - `sessionChange`: emitted when either the previous or current `hasSession()` payload contains
23
- * a logged-in user.
24
- * - `notLoggedin`: emitted when neither the previous nor current `hasSession()` payload contains
25
- * a logged-in user.
26
- * - `sessionInit`: emitted once for the first logged-in session payload.
27
- * - `statusChange`: emitted when the session `userStatus` changes.
28
- * - `error`: emitted when `hasSession()` fails.
29
- * - `simplifiedLoginOpened`: emitted when the simplified login widget is displayed.
30
- * - `simplifiedLoginCancelled`: emitted when the simplified login widget is closed.
31
- */
32
- export type IdentityEventName = 'login' | 'logout' | 'userChange' | 'sessionChange' | 'notLoggedin' | 'sessionInit' | 'statusChange' | 'error' | 'simplifiedLoginOpened' | 'simplifiedLoginCancelled';
33
15
  /**
34
16
  * Options for {@link Identity#enableVarnishCookie}.
35
17
  */
package/dist/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- declare const version = "6.0.0-alpha.4";
1
+ declare const version = "6.0.0-alpha.5";
2
2
  export default version;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@schibsted/account-sdk-browser",
3
- "version": "6.0.0-alpha.4",
3
+ "version": "6.0.0-alpha.5",
4
4
  "description": "Schibsted account SDK for browsers",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",
package/src/account.ts CHANGED
@@ -2,7 +2,6 @@
2
2
  * See LICENSE.md in the project root.
3
3
  */
4
4
 
5
- import { registerAndDispatchInGlobal } from './global-registry.js';
6
5
  import Identity from './identity.js';
7
6
  import Monetization from './monetization.js';
8
7
  import { resolveBrowserWindow } from './resolve-browser-window.js';
@@ -59,7 +58,10 @@ export class Account {
59
58
 
60
59
  this.#monetization = new Monetization(sharedConfig);
61
60
 
62
- registerAndDispatchInGlobal(browserWindow, 'schAccount', this);
61
+ browserWindow.schAccount = this;
62
+ browserWindow.dispatchEvent(
63
+ new CustomEvent('schAccount:ready', { detail: { instance: this } }),
64
+ );
63
65
  }
64
66
 
65
67
  hasSession(): Promise<SessionResponse> {
@@ -82,6 +84,10 @@ export class Account {
82
84
  return this.#identity.getUserId();
83
85
  }
84
86
 
87
+ getUserUuid(): Promise<string> {
88
+ return this.#identity.getUserUuid();
89
+ }
90
+
85
91
  getUserSDRN(): Promise<string> {
86
92
  return this.#identity.getUserSDRN();
87
93
  }
@@ -130,21 +136,13 @@ export class Account {
130
136
  }
131
137
 
132
138
  on(event: AccountEventName, callback: AccountEventHandler, ctx?: unknown): this {
133
- if (event === 'hasAccess') {
134
- this.#monetization.on(event, callback, ctx);
135
- } else {
136
- this.#identity.on(event, callback, ctx);
137
- }
139
+ this.#identity.on(event, callback, ctx);
138
140
 
139
141
  return this;
140
142
  }
141
143
 
142
144
  off(event: AccountEventName, callback?: AccountEventHandler): this {
143
- if (event === 'hasAccess') {
144
- this.#monetization.off(event, callback);
145
- } else {
146
- this.#identity.off(event, callback);
147
- }
145
+ this.#identity.off(event, callback);
148
146
 
149
147
  return this;
150
148
  }
package/src/globals.ts CHANGED
@@ -1,12 +1,8 @@
1
1
  import type { Account } from './account.js';
2
- import type { Identity } from './identity.js';
3
- import type { Monetization } from './monetization.js';
4
2
 
5
3
  declare global {
6
4
  interface Window {
7
5
  schAccount?: Account;
8
- schIdentity?: Identity;
9
- schMonetization?: Monetization;
10
6
  SPiD?: { Talk?: { response?: (callbackName: string, data: unknown) => unknown } };
11
7
  }
12
8
  }
package/src/identity.ts CHANGED
@@ -5,7 +5,6 @@
5
5
  import { TinyEmitter } from 'tiny-emitter';
6
6
  import Cache from './cache.js';
7
7
  import { ENDPOINTS } from './config.js';
8
- import { registerAndDispatchInGlobal } from './global-registry.js';
9
8
  import { cloneDeep } from './object.js';
10
9
  import * as popup from './popup.js';
11
10
  import type RESTClient from './rest-client.js';
@@ -45,16 +44,6 @@ import { urlMapper } from './url.js';
45
44
  import { assert, isNonEmptyString, isObject, isStr, isStrIn, isUrl } from './validate.js';
46
45
  import version from './version.js';
47
46
 
48
- export { isConnectedSessionResponse, isSessionSuccessResponse } from './session-response.js';
49
- export type {
50
- ConnectedSessionResponse,
51
- SessionFailureResponse,
52
- SessionObjectResponse,
53
- SessionResponse,
54
- SessionSuccessResponse,
55
- SessionUserId,
56
- } from './types/session.js';
57
-
58
47
  declare global {
59
48
  interface Window {
60
49
  openSimplifiedLoginWidget?: OpenSimplifiedLoginWidget;
@@ -75,7 +64,6 @@ const globalWindow = () => window;
75
64
  * Provides Identity functionalty to a web page
76
65
  */
77
66
  export class Identity extends TinyEmitter {
78
- _sessionInitiatedSent: boolean;
79
67
  window: Window;
80
68
  clientId: string;
81
69
  sessionStorageCache: Cache;
@@ -135,7 +123,6 @@ export class Identity extends TinyEmitter {
135
123
  assert(isStr(env), `env parameter is invalid: ${env}`);
136
124
 
137
125
  spidTalk.emulate(window);
138
- this._sessionInitiatedSent = false;
139
126
  this.window = window;
140
127
  this.clientId = clientId;
141
128
  this.sessionStorageCache = new Cache(() => this.window && this.window.sessionStorage);
@@ -191,8 +178,6 @@ export class Identity extends TinyEmitter {
191
178
  });
192
179
 
193
180
  this._unblockSessionCall();
194
-
195
- registerAndDispatchInGlobal(window, 'schIdentity', this);
196
181
  }
197
182
 
198
183
  /**
@@ -253,12 +238,6 @@ export class Identity extends TinyEmitter {
253
238
  _emitSessionEvent(previous: object, current: object): void {
254
239
  const previousUserId = isSessionSuccessResponse(previous) ? previous.userId : undefined;
255
240
  const currentUserId = isSessionSuccessResponse(current) ? current.userId : undefined;
256
- const previousUserStatus = isSessionSuccessResponse(previous)
257
- ? previous.userStatus
258
- : undefined;
259
- const currentUserStatus = isSessionSuccessResponse(current)
260
- ? current.userStatus
261
- : undefined;
262
241
 
263
242
  /**
264
243
  * Emitted when the user is logged in (This happens as a result of calling
@@ -275,47 +254,6 @@ export class Identity extends TinyEmitter {
275
254
  if (previousUserId && !currentUserId) {
276
255
  this.emit('logout', current);
277
256
  }
278
- /**
279
- * Emitted when the user is changed. This happens as a result of calling
280
- * {@link Identity#hasSession}, and is emitted if there was a user both before and after
281
- * this invocation, and the userId has now changed
282
- * @event Identity#userChange
283
- */
284
- if (previousUserId && currentUserId && previousUserId !== currentUserId) {
285
- this.emit('userChange', current);
286
- }
287
- if (previousUserId || currentUserId) {
288
- /**
289
- * Emitted when the session is changed. More accurately, this event is emitted if there
290
- * was a logged-in user either before or after {@link Identity#hasSession} was called.
291
- * In practice, this means the event is emitted a lot
292
- * @event Identity#sessionChange
293
- */
294
- this.emit('sessionChange', current);
295
- } else {
296
- /**
297
- * Emitted when there is no logged-in user. More specifically, it means that there was
298
- * no logged-in user neither before nor after {@link Identity#hasSession} was called
299
- * @event Identity#notLoggedin
300
- */
301
- this.emit('notLoggedin', current);
302
- }
303
- /**
304
- * Emitted when the session is first created
305
- * @event Identity#sessionInit
306
- */
307
- if (currentUserId && !this._sessionInitiatedSent) {
308
- this._sessionInitiatedSent = true;
309
- this.emit('sessionInit', current);
310
- }
311
- /**
312
- * Emitted when the user status changes. This happens as a result of calling
313
- * {@link Identity#hasSession}
314
- * @event Identity#statusChange
315
- */
316
- if (previousUserStatus !== currentUserStatus) {
317
- this.emit('statusChange', current);
318
- }
319
257
  }
320
258
 
321
259
  /**
@@ -417,28 +355,6 @@ export class Identity extends TinyEmitter {
417
355
  document.cookie = `SP_ID=nothing; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/; domain=.${domain}`;
418
356
  }
419
357
 
420
- /**
421
- * Log used settings and version
422
- * @throws {SDKError} - If log method is not provided
423
- */
424
- logSettings(): void {
425
- if (!this.log && !window.console) {
426
- throw new SDKError('You have to provide log method in constructor');
427
- }
428
-
429
- const log = this.log || console.log;
430
-
431
- const settings = {
432
- clientId: this.clientId,
433
- redirectUri: this.redirectUri,
434
- env: this.env,
435
- sessionDomain: this._sessionDomain,
436
- sdkVersion: version,
437
- };
438
-
439
- log(`Schibsted account SDK for browsers settings: \n${JSON.stringify(settings, null, 2)}`);
440
- }
441
-
442
358
  /**
443
359
  * @summary Queries the hassession endpoint and returns information about the status of the user
444
360
  * @remarks When we send a request to this endpoint, cookies sent along with the request
@@ -447,12 +363,6 @@ export class Identity extends TinyEmitter {
447
363
  * if, say, the user is not logged in)
448
364
  * @fires Identity#login
449
365
  * @fires Identity#logout
450
- * @fires Identity#userChange
451
- * @fires Identity#sessionChange
452
- * @fires Identity#notLoggedin
453
- * @fires Identity#sessionInit
454
- * @fires Identity#statusChange
455
- * @fires Identity#error
456
366
  */
457
367
  hasSession(): Promise<SessionResponse> {
458
368
  const isSessionCallBlocked = this._isSessionCallBlocked();
@@ -558,7 +468,6 @@ export class Identity extends TinyEmitter {
558
468
  return sessionData;
559
469
  },
560
470
  (err) => {
561
- this.emit('error', err);
562
471
  this._hasSessionInProgress = false;
563
472
  throw new SDKError('HasSession failed', err);
564
473
  },
@@ -618,11 +527,9 @@ export class Identity extends TinyEmitter {
618
527
  }
619
528
  return cloneDeep(user);
620
529
  }
621
-
622
530
  /**
623
531
  * @summary
624
- * In Schibsted account, there are multiple ways of identifying a user; the `userId`,
625
- * `uuid` and `externalId` used for identifying a user-merchant pair (see {@link Identity#getExternalId}).
532
+ * In Schibsted account, there are multiple ways of identifying a user; the `userId` or `uuid`.
626
533
  * There are reasons for them all to exist. The `userId` is a numeric identifier, but
627
534
  * since Schibsted account is deployed separately in Norway and Sweden, there are a lot of
628
535
  * duplicates. The `userId` was introduced early, so many sites still need to use them for
@@ -641,65 +548,6 @@ export class Identity extends TinyEmitter {
641
548
  throw new SDKError('The user is not connected to this merchant');
642
549
  }
643
550
 
644
- /**
645
- * @function
646
- * @summary
647
- * Retrieves the external identifier (`externalId`) for the authenticated user.
648
- *
649
- * In Schibsted Account there are multiple ways of identifying users, however for integrations with
650
- * third-parties it's recommended to use `externalId` as it does not disclose
651
- * any critical data whilst allowing for user identification.
652
- *
653
- * `externalId` is merchant-scoped using a pairwise identifier (`pairId`),
654
- * meaning the same user's ID will differ between merchants.
655
- * Additionally, this identifier is bound to the external party provided as argument.
656
- *
657
- * @param externalParty
658
- * @param optionalSuffix
659
- * @remarks This function calls {@link Identity#hasSession} internally and thus has the side
660
- * effect that it might perform an auto-login on the user
661
- * @throws {SDKError} If the `pairId` is missing in user session.
662
- * @throws {SDKError} If the `externalParty` is not defined
663
- * @return The merchant- and 3rd-party-specific `externalId`
664
- */
665
- async getExternalId(externalParty: string, optionalSuffix: string = ''): Promise<string> {
666
- const user = await this.hasSession();
667
- const pairId = isSessionSuccessResponse(user) ? user.pairId : undefined;
668
-
669
- if (!pairId) throw new SDKError('pairId missing in user session!');
670
-
671
- if (!externalParty || externalParty.length === 0) {
672
- throw new SDKError('externalParty cannot be empty');
673
- }
674
- const _toHexDigest = (hashBuffer: ArrayBuffer) => {
675
- // convert buffer to byte array
676
- const hashArray = Array.from(new Uint8Array(hashBuffer));
677
- // convert bytes to hex string
678
- return hashArray.map((b) => b.toString(16).padStart(2, '0')).join('');
679
- };
680
-
681
- const _getSha256Digest = (data: BufferSource) => {
682
- return crypto.subtle.digest('SHA-256', data);
683
- };
684
-
685
- const _hashMessage = async (message: string) => {
686
- const msgUint8 = new TextEncoder().encode(message);
687
- return _getSha256Digest(msgUint8).then((it) => _toHexDigest(it));
688
- };
689
-
690
- const _constructMessage = (
691
- pairId: string,
692
- externalParty: string,
693
- optionalSuffix: string,
694
- ) => {
695
- return optionalSuffix
696
- ? `${pairId}:${externalParty}:${optionalSuffix}`
697
- : `${pairId}:${externalParty}`;
698
- };
699
-
700
- return _hashMessage(_constructMessage(pairId, externalParty, optionalSuffix));
701
- }
702
-
703
551
  /**
704
552
  * @summary Enables brands to programmatically get the current the SDRN based on the user's session.
705
553
  * @remarks This function calls {@link Identity#hasSession} internally and thus has the side
@@ -961,17 +809,6 @@ export class Identity extends TinyEmitter {
961
809
  });
962
810
  }
963
811
 
964
- /**
965
- * The phone editing page url
966
- * @param redirectUri
967
- */
968
- phonesUrl(redirectUri: string = this.redirectUri): string {
969
- return this._spid.makeUrl('profile-pages/about-you/phone', {
970
- response_type: 'code',
971
- redirect_uri: redirectUri,
972
- });
973
- }
974
-
975
812
  /**
976
813
  * Function responsible for loading and displaying simplified login widget. How often
977
814
  * widget will be display is up to you. Preferred way would be to show it once per user,
package/src/index.ts CHANGED
@@ -4,6 +4,7 @@
4
4
 
5
5
  export { Account } from './account.js';
6
6
  export { createAccountSdk, getAccountSdk } from './account-sdk.js';
7
+ export * from './globals.js';
7
8
  export { default as SDKError } from './sdk-error.js';
8
9
 
9
10
  /* public available types */
@@ -11,7 +12,6 @@ export type {
11
12
  AccountConfig,
12
13
  AccountEventHandler,
13
14
  AccountEventName,
14
- AccountSessionEventName,
15
15
  } from './types/account.js';
16
16
  export type { AccountEnvironment, LogFunction } from './types/common.js';
17
17
  export type {
@@ -2,17 +2,15 @@
2
2
  * See LICENSE.md in the project root.
3
3
  */
4
4
 
5
- import { TinyEmitter } from 'tiny-emitter';
6
5
  import Cache from './cache.js';
7
6
  import { ENDPOINTS } from './config.js';
8
- import { registerAndDispatchInGlobal } from './global-registry.js';
9
7
  import { parseHasAccessResult } from './has-access-response.js';
10
- import type { SessionUserId } from './identity.js';
11
8
  import type RESTClient from './rest-client.js';
12
9
  import { buildClientSdrn, createAccountRestClient } from './rest-clients.js';
13
10
  import SDKError from './sdk-error.js';
14
11
  import * as spidTalk from './spid-talk.js';
15
12
  import type { HasAccessResult, MonetizationOptions } from './types/monetization.js';
13
+ import type { SessionUserId } from './types/session.js';
16
14
  import { urlMapper } from './url.js';
17
15
  import { assert, isNonEmptyString, isStr, isUrl } from './validate.js';
18
16
  import version from './version.js';
@@ -22,7 +20,7 @@ const globalWindow = () => window;
22
20
  /**
23
21
  * Provides features related to monetization
24
22
  */
25
- export class Monetization extends TinyEmitter {
23
+ export class Monetization {
26
24
  cache: Cache;
27
25
  clientId: string;
28
26
  env: string;
@@ -42,7 +40,6 @@ export class Monetization extends TinyEmitter {
42
40
  sessionDomain,
43
41
  window = globalWindow(),
44
42
  }: MonetizationOptions) {
45
- super();
46
43
  spidTalk.emulate(window);
47
44
  assert(isNonEmptyString(clientId), 'clientId parameter is required');
48
45
  assert(isStr(env), `env parameter is invalid: ${env}`);
@@ -68,7 +65,6 @@ export class Monetization extends TinyEmitter {
68
65
  },
69
66
  });
70
67
  }
71
- registerAndDispatchInGlobal(window, 'schMonetization', this);
72
68
  }
73
69
 
74
70
  /**
@@ -117,7 +113,7 @@ export class Monetization extends TinyEmitter {
117
113
  if (!data.entitled) {
118
114
  return null;
119
115
  }
120
- this.emit('hasAccess', { ids: sortedIds, data });
116
+
121
117
  return data;
122
118
  }
123
119
 
@@ -139,26 +135,6 @@ export class Monetization extends TinyEmitter {
139
135
  private _accessCacheKey(productIds: string[], userId: SessionUserId): string {
140
136
  return `prd_${[...productIds].sort()}_${userId}`;
141
137
  }
142
-
143
- /**
144
- * Get the url for the end user to review the subscriptions
145
- * @param redirectUri
146
- * @returns - The url to the subscriptions review page
147
- */
148
- subscriptionsUrl(redirectUri: string = this.redirectUri ?? ''): string {
149
- assert(isUrl(redirectUri), `subscriptionsUrl(): redirectUri is invalid`);
150
- return this._spid.makeUrl('account/subscriptions', { redirect_uri: redirectUri });
151
- }
152
-
153
- /**
154
- * Get the url for the end user to review the products
155
- * @param redirectUri
156
- * @returns - The url to the products review page
157
- */
158
- productsUrl(redirectUri: string = this.redirectUri ?? ''): string {
159
- assert(isUrl(redirectUri), `productsUrl(): redirectUri is invalid`);
160
- return this._spid.makeUrl('account/products', { redirect_uri: redirectUri });
161
- }
162
138
  }
163
139
 
164
140
  export default Monetization;
@@ -10,18 +10,19 @@ export type AccountConfig = AccountBaseConfig & {
10
10
  varnish?: VarnishCookieOptions;
11
11
  };
12
12
 
13
- export type AccountSessionEventName =
13
+ /**
14
+ * Identity events emitted by the SDK.
15
+ *
16
+ * - `login`: emitted when `hasSession()` resolves with a logged-in user payload.
17
+ * - `logout`: emitted when a previously logged-in user is no longer logged in, or when
18
+ * `logout()` is called.
19
+ * - `simplifiedLoginOpened`: emitted when the simplified login widget is displayed.
20
+ * - `simplifiedLoginCancelled`: emitted when the simplified login widget is closed.
21
+ */
22
+ export type AccountEventName =
14
23
  | 'login'
15
24
  | 'logout'
16
- | 'userChange'
17
- | 'sessionChange'
18
- | 'notLoggedin'
19
- | 'sessionInit'
20
- | 'statusChange'
21
- | 'error'
22
25
  | 'simplifiedLoginOpened'
23
26
  | 'simplifiedLoginCancelled';
24
27
 
25
- export type AccountEventName = AccountSessionEventName | 'hasAccess';
26
-
27
28
  export type AccountEventHandler = (...args: unknown[]) => void;
@@ -15,35 +15,6 @@ export type IdentityOptions = AccountBaseConfig & {
15
15
  callbackBeforeRedirect?: IdentityBeforeRedirectCallback;
16
16
  };
17
17
 
18
- /**
19
- * Identity events emitted by the SDK.
20
- *
21
- * - `login`: emitted when `hasSession()` resolves with a logged-in user payload.
22
- * - `logout`: emitted when a previously logged-in user is no longer logged in, or when
23
- * `logout()` is called.
24
- * - `userChange`: emitted when the current session user id changes.
25
- * - `sessionChange`: emitted when either the previous or current `hasSession()` payload contains
26
- * a logged-in user.
27
- * - `notLoggedin`: emitted when neither the previous nor current `hasSession()` payload contains
28
- * a logged-in user.
29
- * - `sessionInit`: emitted once for the first logged-in session payload.
30
- * - `statusChange`: emitted when the session `userStatus` changes.
31
- * - `error`: emitted when `hasSession()` fails.
32
- * - `simplifiedLoginOpened`: emitted when the simplified login widget is displayed.
33
- * - `simplifiedLoginCancelled`: emitted when the simplified login widget is closed.
34
- */
35
- export type IdentityEventName =
36
- | 'login'
37
- | 'logout'
38
- | 'userChange'
39
- | 'sessionChange'
40
- | 'notLoggedin'
41
- | 'sessionInit'
42
- | 'statusChange'
43
- | 'error'
44
- | 'simplifiedLoginOpened'
45
- | 'simplifiedLoginCancelled';
46
-
47
18
  /**
48
19
  * Options for {@link Identity#enableVarnishCookie}.
49
20
  */
package/src/version.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  // Version is bumped automatically by release-please. See release-please-config.json.
2
2
 
3
- const version = '6.0.0-alpha.4'; // x-release-please-version
3
+ const version = '6.0.0-alpha.5'; // x-release-please-version
4
4
  export default version;
@@ -1,23 +0,0 @@
1
- /**
2
- * Names of the SDK instance properties that can be registered on the global {@link Window} object.
3
- */
4
- type Property = 'schAccount' | 'schIdentity' | 'schMonetization';
5
- /**
6
- * Registers an SDK instance on the global {@link Window} object's given property and dispatches a ready event.
7
- *
8
- * The dispatched event is a {@link CustomEvent} fired on `global` (i.e. `window`) with:
9
- * - name: `${property}:ready` (e.g. `"schIdentity:ready"` or `"schMonetization:ready"`)
10
- * - `detail.instance`: the registered SDK instance
11
- *
12
- * @typeParam T - Constrained to {@link Property}; inferred from the `property` argument.
13
- * @param global - The `Window` object to register on.
14
- * @param property - The window property name to assign the instance to, 'schIdentity' or 'schMonetization'.
15
- * @param instance - The SDK instance to register. Must be non-nullable.
16
- *
17
- * @example
18
- * registerAndDispatchInGlobal(window, 'schIdentity', identityInstance);
19
- * / window.schIdentity === identityInstance
20
- * / CustomEvent 'schIdentity:ready' has been dispatched on window
21
- */
22
- export declare const registerAndDispatchInGlobal: <T extends Property>(global: Window, property: T, instance: NonNullable<Window[T]>) => void;
23
- export {};
@@ -1,2 +0,0 @@
1
- import { HasAccessResult } from './monetization.js';
2
- export declare function parseHasAccessResult(value: unknown): HasAccessResult;
@@ -1,36 +0,0 @@
1
- import { ConnectedSessionResponse, ConnectedSessionWithUserIdResponse, SessionFailureResponse, SessionResponse, SessionSuccessResponse, UnrecognizedSessionResponse } from './session.js';
2
- type SessionObjectResponse = SessionSuccessResponse | SessionFailureResponse | UnrecognizedSessionResponse;
3
- type RedirectSessionPayload = {
4
- redirectURL: string;
5
- };
6
- export type NormalizedSessionPayload = SessionObjectResponse | RedirectSessionPayload;
7
- export declare function isSessionSuccessResponse(value: unknown): value is SessionSuccessResponse;
8
- export declare function isConnectedSessionResponse(value: unknown): value is ConnectedSessionResponse;
9
- export declare function isSessionFailureResponse(value: unknown): value is SessionFailureResponse;
10
- export declare function isRedirectSessionPayload(value: unknown): value is RedirectSessionPayload;
11
- export declare function isConnectedSessionWithUserIdResponse(value: SessionResponse): value is ConnectedSessionWithUserIdResponse;
12
- /**
13
- * Converts an unknown Session Service `hasSession` payload into one of the shapes the SDK knows how
14
- * to handle.
15
- *
16
- * This function is intentionally tolerant because `hasSession()` historically resolved unknown
17
- * object payloads instead of rejecting them. The SDK relies on that behavior for backwards
18
- * compatibility with clients that check the raw response themselves.
19
- *
20
- * The normal cases are:
21
- * - regular success payloads with a boolean `result`;
22
- * - failure payloads wrapped as `{ error, response? }`;
23
- * - Safari/session-refresh redirect payloads shaped as `{ redirectURL }`.
24
- *
25
- * Any other object is preserved as an unrecognized response so callers can still receive it.
26
- * Non-object values are normalized to `{}`, matching the old "empty response" fallback used by
27
- * `hasSession()` and cached-session reads.
28
- *
29
- * This is used both for network responses parsed by `RESTClient` and for values restored from the
30
- * session cache, so the rest of the Identity flow can switch on typed guards instead of repeatedly
31
- * re-validating unknown data.
32
- *
33
- * @internal
34
- */
35
- export declare function normalizeSessionResponse(value: unknown): NormalizedSessionPayload;
36
- export {};