@schibsted/account-sdk-browser 5.2.7 → 6.0.0-alpha.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.
Files changed (90) hide show
  1. package/README.md +12 -59
  2. package/dist/RESTClient.d.ts +91 -0
  3. package/dist/SDKError.d.ts +27 -0
  4. package/dist/cache.d.ts +65 -0
  5. package/dist/config.d.ts +86 -0
  6. package/dist/global-registry.d.ts +23 -0
  7. package/dist/globals.d.ts +13 -0
  8. package/dist/identity-s4nofYmB.js +370 -0
  9. package/dist/identity-s4nofYmB.js.map +1 -0
  10. package/dist/identity.d.ts +523 -0
  11. package/dist/identity.js +2 -0
  12. package/dist/index.d.ts +3 -0
  13. package/dist/index.js +4 -0
  14. package/dist/monetization.d.ts +94 -0
  15. package/dist/monetization.js +72 -0
  16. package/dist/monetization.js.map +1 -0
  17. package/{src → dist}/object.d.ts +4 -9
  18. package/dist/popup.d.ts +9 -0
  19. package/{src → dist}/spidTalk.d.ts +4 -6
  20. package/dist/url.d.ts +8 -0
  21. package/dist/validate.d.ts +50 -0
  22. package/dist/version-spE-k97g.js +289 -0
  23. package/dist/version-spE-k97g.js.map +1 -0
  24. package/dist/version.d.ts +2 -0
  25. package/package.json +42 -49
  26. package/src/RESTClient.ts +226 -0
  27. package/src/SDKError.ts +59 -0
  28. package/src/{cache.js → cache.ts} +52 -37
  29. package/src/{config.js → config.ts} +7 -32
  30. package/src/global-registry.ts +39 -0
  31. package/src/globals.ts +10 -0
  32. package/src/{identity.js → identity.ts} +536 -437
  33. package/{index.js → src/index.ts} +1 -3
  34. package/src/{monetization.js → monetization.ts} +77 -48
  35. package/src/{object.js → object.ts} +8 -15
  36. package/src/popup.ts +74 -0
  37. package/src/{spidTalk.js → spidTalk.ts} +10 -12
  38. package/src/{url.js → url.ts} +6 -10
  39. package/src/{validate.js → validate.ts} +26 -42
  40. package/src/{version.js → version.ts} +1 -2
  41. package/es5/global.js +0 -12968
  42. package/es5/global.js.map +0 -1
  43. package/es5/global.min.js +0 -2
  44. package/es5/global.min.js.map +0 -1
  45. package/es5/identity.js +0 -12212
  46. package/es5/identity.js.map +0 -1
  47. package/es5/identity.min.js +0 -2
  48. package/es5/identity.min.js.map +0 -1
  49. package/es5/index.js +0 -12940
  50. package/es5/index.js.map +0 -1
  51. package/es5/index.min.js +0 -2
  52. package/es5/index.min.js.map +0 -1
  53. package/es5/monetization.js +0 -9176
  54. package/es5/monetization.js.map +0 -1
  55. package/es5/monetization.min.js +0 -2
  56. package/es5/monetization.min.js.map +0 -1
  57. package/es5/payment.js +0 -8853
  58. package/es5/payment.js.map +0 -1
  59. package/es5/payment.min.js +0 -2
  60. package/es5/payment.min.js.map +0 -1
  61. package/identity.d.ts +0 -1
  62. package/identity.js +0 -5
  63. package/index.d.ts +0 -4
  64. package/monetization.d.ts +0 -1
  65. package/monetization.js +0 -5
  66. package/payment.d.ts +0 -1
  67. package/payment.js +0 -5
  68. package/src/RESTClient.d.ts +0 -89
  69. package/src/RESTClient.js +0 -193
  70. package/src/SDKError.d.ts +0 -16
  71. package/src/SDKError.js +0 -55
  72. package/src/__mocks__/.eslintrc.yml +0 -8
  73. package/src/__mocks__/RESTClient.js +0 -54
  74. package/src/cache.d.ts +0 -64
  75. package/src/config.d.ts +0 -34
  76. package/src/es5/global.js +0 -13
  77. package/src/es5/identity.js +0 -10
  78. package/src/es5/index.js +0 -13
  79. package/src/es5/monetization.js +0 -10
  80. package/src/es5/payment.js +0 -10
  81. package/src/global-registry.js +0 -20
  82. package/src/identity.d.ts +0 -679
  83. package/src/monetization.d.ts +0 -80
  84. package/src/payment.d.ts +0 -115
  85. package/src/payment.js +0 -211
  86. package/src/popup.d.ts +0 -10
  87. package/src/popup.js +0 -59
  88. package/src/url.d.ts +0 -10
  89. package/src/validate.d.ts +0 -64
  90. package/src/version.d.ts +0 -2
package/README.md CHANGED
@@ -24,14 +24,11 @@ For example if your `pre` domain is pre.sdk-example.com, and it uses id.pre.sdk-
24
24
  domain, your local domain should be local.sdk-example.com.
25
25
 
26
26
  1. Do `npm install --save @schibsted/account-sdk-browser`
27
- 1. Use this library as you would any other npm module: `import { Identity, Monetization, Payment } from '@schibsted/account-sdk-browser'`
28
- With CommonJS it is possible to `require` the modules Identity, Monetization and Payment
29
- by appending `/identity`, `/monetization'` or `/payment'`.
30
- 1. Build your site as you prefer. This library uses modern JavaScript syntax (including async/await
31
- and other ES2017 and WHATWG features) by default. We recommend that you do any transpilation
32
- yourself for the browser versions you need to cater to. See [this paragraph](#polyfills) for
33
- info about our Babel-ified version and info about polyfills.
34
- 1. Initiate the SDK and provide at least `clientId`, `env` and `sessionDomain`.
27
+ 2. Use this library as you would any other npm module: `import { Identity, Monetization } from '@schibsted/account-sdk-browser'`.
28
+ 3. Build your site as you prefer. This library is published as ES modules and uses modern JavaScript
29
+ syntax (including async/await and other ES2017 and WHATWG features). We recommend that you do
30
+ any transpilation yourself for the browser versions you need to cater to. We do not add polyfills.
31
+ 4. Initiate the SDK and provide at least `clientId`, `env` and `sessionDomain`.
35
32
 
36
33
  If this is for a new site and there is no sessionDomain yet, contact
37
34
  [support](mailto:schibstedaccount@schibsted.com) to initiate the process.
@@ -44,8 +41,8 @@ Follow the [migration guide](./MIGRATION.md).
44
41
 
45
42
  1. Ensure that your site has no site specific terms and conditions in the Schibsted account login flow.
46
43
  1. Define rules for when and how often the simplified login prompt should be shown to unique users on your site. How you do this is up to you, but we recommend starting with showing the prompt once per user before potentially increasing this frequency over time.
47
- 1. Set up a function to check if users landing on your domain [is logged in](https://schibsted.github.io/account-sdk-browser/Identity.html#isLoggedIn) to your site.
48
- 1. If the user is not logged-in to your site, call the [showSimplifiedLoginWidget](https://schibsted.github.io/account-sdk-browser/Identity.html#showSimplifiedLoginWidget) function. The `showSimplifiedLoginWidget` accepts the same params as login function (`state` is required, it might be string or async function). If the simplified login prompt is to be loaded, `showSimplifiedLoginWidget` will return `true`.
44
+ 1. Set up a function to check if users landing on your domain [is logged in](https://schibsted.github.io/account-sdk-browser/classes/Identity.html#isloggedin) to your site.
45
+ 1. If the user is not logged-in to your site, call the [showSimplifiedLoginWidget](https://schibsted.github.io/account-sdk-browser/classes/Identity.html#showsimplifiedloginwidget) function. The `showSimplifiedLoginWidget` accepts the same params as login function (`state` is required, it might be string or async function). If the simplified login prompt is to be loaded, `showSimplifiedLoginWidget` will return `true`.
49
46
  1. Set up a way to store information about which users have been shown the simplified login prompt. How you do this is up to you, but one way is to use localStorage. Use this information to execute on the rules defined in #2.
50
47
 
51
48
  ## Example project
@@ -69,7 +66,7 @@ This allows you to call Schibsted Account APIs on behalf of that user.
69
66
  ## Events
70
67
 
71
68
  The SDK fires events on the instances when something we deem interesting is happening. For example the
72
- [Identity](https://schibsted.github.io/account-sdk-browser/Identity.html) class
69
+ [Identity](https://schibsted.github.io/account-sdk-browser/classes/Identity.html) class
73
70
  emits some events when the user is logged in or logged out. This SDK uses a familar interface that's
74
71
  very similar to Node's [EventEmitter](https://nodejs.org/api/events.html). The most important
75
72
  methods are `.on(eventName, listener)` (to subscribe to an event) and `.off(eventName, listener)`
@@ -82,7 +79,6 @@ Events are emitted for:
82
79
  | ------------ | ----------------------- |
83
80
  | Identity | `schIdentity:ready` |
84
81
  | Monetization | `schMonetization:ready` |
85
- | Payment | `schPayment:ready` |
86
82
 
87
83
  ```js
88
84
  window.addEventListener('schIdentity:ready', e => {
@@ -191,10 +187,10 @@ Schibsted account relies on browser cookies to determine whether a user is recog
191
187
  The SDK provides functions that can be used to check if the user that's visiting your site is
192
188
  already a Schibsted user or not.
193
189
 
194
- * [Identity#isLoggedIn](https://schibsted.github.io/account-sdk-browser/Identity.html#isLoggedIn)
190
+ * [Identity#isLoggedIn](https://schibsted.github.io/account-sdk-browser/classes/Identity.html#isloggedin)
195
191
  tells you if the user that is visiting your site is already logged in to Schibsted account or not.
196
192
 
197
- * [Identity#isConnected](https://schibsted.github.io/account-sdk-browser/Identity.html#isConnected)
193
+ * [Identity#isConnected](https://schibsted.github.io/account-sdk-browser/classes/Identity.html#isconnected)
198
194
  tells you if the user is connected to your client. A user might have `isLoggedIn=true` and at the
199
195
  same time `isConnected=false` if they have logged in to Schibsted account, but not accepted terms
200
196
  and privacy policy for your site.
@@ -206,13 +202,13 @@ will just ask them to accept those terms and redirect them right back to your si
206
202
  #### Logging out
207
203
 
208
204
  If you want to log the user out of Schibsted account, you can call
209
- [Identity#logout](https://schibsted.github.io/account-sdk-browser/Identity.html#logout). This
205
+ [Identity#logout](https://schibsted.github.io/account-sdk-browser/classes/Identity.html#logout). This
210
206
  will remove the Schibsted account brand session. User will still be logged into Schibsted account.
211
207
 
212
208
  ## Monetization
213
209
 
214
210
  The preferred method for checking whether a user has access to a product/subscription is
215
- [Monetization#hasAccess](https://schibsted.github.io/account-sdk-browser/Monetization.html#hasAccess).
211
+ [Monetization#hasAccess](https://schibsted.github.io/account-sdk-browser/classes/Monetization.html#hasaccess).
216
212
  It requires using Session Service, and supports both Schibsted account productId's and Zuora
217
213
  feature id's.
218
214
 
@@ -238,49 +234,6 @@ try {
238
234
  }
239
235
  ```
240
236
 
241
- ## Payment
242
-
243
- This class provides methods for paying with a so-called paylink, buying a product, getting links to
244
- pages for redeeming voucher codes, reviewing payment history, and more.
245
-
246
- #### Example
247
-
248
- ```javascript
249
- import { Payment } from '@schibsted/account-sdk-browser';
250
-
251
- const paymentSDK = new Payment({
252
- clientId: '56e9a5d1eee0000000000000',
253
- redirectUri: 'https://awesomenews.site', // ensure it's listed in selfservice
254
- env: 'PRE', // Schibsted account env. A url or a special key: 'PRE', 'PRO' or 'PRO_NO'
255
- });
256
-
257
- // Get the url to paymentSDK with paylink
258
- const paylink = '...';
259
- const paylinkUrl = paymentSDK.purchasePaylinkUrl(paylink);
260
-
261
- // Or another example --- pay with paylink in a popup
262
- paymentSDK.payWithPaylink(paylink);
263
- ```
264
-
265
- ## Appendix
266
-
267
- #### Polyfills
268
-
269
- This SDK uses modern JavaScript features. If you support older browsers, you should use a tool like
270
- babel to transform the JavaScript as needed. However, since certain teams have deployment pipelines
271
- where it's difficult to do their own transpilation, we do provide some opt-in es5 files as well:
272
-
273
- 1. `@schibsted/account-sdk-browser/es5`: Include both `Identity`, `Monetization` and `Payment`.
274
- 1. `@schibsted/account-sdk-browser/es5/global`: Include both `Identity`, `Monetization` and
275
- `Payment`. In addition, add them as variables to the global `window` object.
276
- 1. `@schibsted/account-sdk-browser/es5/identity`, `@schibsted/account-sdk-browser/es5/monetization`
277
- or `@schibsted/account-sdk-browser/es5/payment` can be used to only include each class by itself.
278
-
279
- But then regardless of whether you use the es5 versions or not, you might need to polyfill certain
280
- things that might be missing in the browsers you wish to support. A quick test using IE11 showed
281
- that we needed polyfills for `Promise`, `URL`, `Object.entries`, `fetch`, `Number.isFinite` and
282
- `Number.isInteger`.
283
-
284
237
  #### Cookies
285
238
 
286
239
  There are some cookies used by Schibsted account. They should all be considered opaque on the
@@ -0,0 +1,91 @@
1
+ type FetchFunction = (input: RequestInfo, init?: RequestInit) => Promise<Response>;
2
+ /**
3
+ * The value of a single query parameter; `undefined` entries are skipped.
4
+ */
5
+ type QueryValue = string | number | boolean | undefined;
6
+ /**
7
+ * Query parameters appended to a request URL.
8
+ */
9
+ type QueryParams = Record<string, QueryValue>;
10
+ /**
11
+ * HTTP method used for a request.
12
+ */
13
+ type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
14
+ /**
15
+ * This class can be used for creating a wrapper around a server and all its endpoints.
16
+ * Its functionality is extended by {@link JSONPClient}
17
+ * Creates a client to a REST server. While useful stand-alone, it's also used for some other
18
+ * types of client that change some functionalities.
19
+ * @throws {SDKError} - If any of options are invalid
20
+ * @summary The simplest way to communicate to a REST endpoint without any
21
+ * special authentication
22
+ * @private
23
+ */
24
+ export declare class RESTClient {
25
+ url: URL;
26
+ defaultParams: QueryParams;
27
+ log?: Function;
28
+ fetch: FetchFunction;
29
+ /**
30
+ * @param options
31
+ * @param options.serverUrl - The URL to the server eg.
32
+ * https://login.schibsted.com or a URL key like 'DEV' in combination with {@link envDic}.
33
+ * @param options.envDic - A dictionary that will be used for looking up
34
+ * {@link serverUrl} keys. If serverUrl is always a URL, you don't need this.
35
+ * @param options.fetch - The fetch function to use. It can be native
36
+ * or a polyfill
37
+ * @param options.log - A function that will be called with log messages about
38
+ * request and response
39
+ * @param options.defaultParams - Query parameters added to every request
40
+ */
41
+ constructor({ serverUrl, envDic, fetch, log, defaultParams, }: {
42
+ serverUrl?: string;
43
+ envDic?: Record<string, string>;
44
+ fetch?: FetchFunction;
45
+ log?: Function;
46
+ defaultParams?: QueryParams;
47
+ });
48
+ /**
49
+ * Makes the actual call to the server and deals with headers, data objects and the edge cases.
50
+ * Please note that this method expects the response to be in JSON format. However, it'll not
51
+ * parse the response if its code is not in the 200 range.
52
+ * @param options - An obligatory options object
53
+ * @param options.method - The HTTP request method, e.g. 'GET' or 'POST'
54
+ * @param options.pathname - The path to the endpoint like 'api/2/endpoint-name'
55
+ * @param options.data - Query parameters added to the request URL
56
+ * @param options.headers - Request headers as a plain key/value map
57
+ * @param options.useDefaultParams - Should we add the defaultParams to the query?
58
+ * @param options.fetchOptions - Additional fetch options
59
+ * @throws {SDKError} - If the call can't be made for whatever reason.
60
+ */
61
+ go({ method, headers, pathname, data, useDefaultParams, fetchOptions, }: {
62
+ method: HttpMethod;
63
+ pathname: string;
64
+ data?: QueryParams;
65
+ headers?: Record<string, string>;
66
+ useDefaultParams?: boolean;
67
+ fetchOptions?: RequestInit;
68
+ }): Promise<any>;
69
+ /**
70
+ * Creates a url that points to an endpoint in the server
71
+ * @param pathname - WHATWG pathname ie. 'api/2/endpoint-name'
72
+ * @param query - Query parameters to serialize into the query string
73
+ * @param useDefaultParams - Should we add the defaultParams to the query?
74
+ */
75
+ makeUrl(pathname?: string, query?: QueryParams, useDefaultParams?: boolean): string;
76
+ /**
77
+ * Make a GET request
78
+ * @param pathname - WHATWG pathname ie. 'api/2/endpoint-name'
79
+ * @param data - Query parameters
80
+ */
81
+ get(pathname: string, data?: QueryParams): Promise<any>;
82
+ /**
83
+ * Construct query string for WHATWG urls
84
+ * @private
85
+ * @param query - Query parameters to generate the query string from
86
+ * @param useDefaultParams - Use defaultParams or not
87
+ * @param defaultParams - Default params
88
+ */
89
+ private static search;
90
+ }
91
+ export default RESTClient;
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Custom error class thrown by all SDK methods on failure.
3
+ *
4
+ * All rejected promises from API calls reject with an instance of this class.
5
+ */
6
+ export default class SDKError extends Error {
7
+ /** HTTP status code from the server error payload;
8
+ * declared explicitly to allow numeric comparisons without type-casting.
9
+ */
10
+ code?: number;
11
+ /**
12
+ * Properties copied from the server error object.
13
+ * @internal
14
+ */
15
+ [key: string]: unknown;
16
+ /**
17
+ * @param message - Human-readable error message
18
+ * @param errorObject - Optional server error payload. All enumerable properties are
19
+ * shallow-copied onto this instance.
20
+ */
21
+ constructor(message: string, errorObject?: Record<string, unknown>);
22
+ /**
23
+ * Returns a multi-line string with the error name, message, and any other properties copied
24
+ * from the server error payload.
25
+ */
26
+ toString(): string;
27
+ }
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Cache implementation used when web storage is available. Wraps a `Storage` instance.
3
+ * @private
4
+ */
5
+ declare class WebStorageCache {
6
+ store: Storage;
7
+ get: (key: string) => string | null;
8
+ set: (key: string, value: string) => void;
9
+ delete: (key: string) => void;
10
+ /**
11
+ * Create web storage cache object
12
+ * @param store - A reference to either `sessionStorage` or `localStorage` from a
13
+ * `Window` object
14
+ */
15
+ constructor(store: Storage);
16
+ }
17
+ /**
18
+ * Cache implementation used when web storage is not available. Stores entries in an in-memory object.
19
+ * @private
20
+ */
21
+ declare class LiteralCache {
22
+ store: Record<string, string>;
23
+ get: (key: string) => string | undefined;
24
+ set: (key: string, value: string) => void;
25
+ delete: (key: string) => void;
26
+ /**
27
+ * Create JS object literal cache object
28
+ */
29
+ constructor();
30
+ }
31
+ /**
32
+ * Cache class that attempts WebStorage (session/local storage), and falls back to JS object literal
33
+ * @private
34
+ */
35
+ export default class Cache {
36
+ cache: WebStorageCache | LiteralCache;
37
+ type: string;
38
+ /**
39
+ * @param storeProvider - A function to return a WebStorage instance (either
40
+ * `sessionStorage` or `localStorage` from a `Window` object)
41
+ * @throws {SDKError} - If sessionStorage or localStorage are not accessible
42
+ */
43
+ constructor(storeProvider?: () => Storage);
44
+ /**
45
+ * Get a value from cache (checks that the object has not expired)
46
+ * @param key
47
+ * @private
48
+ */
49
+ get(key: string): unknown;
50
+ /**
51
+ * Set a cache entry
52
+ * @param key
53
+ * @param value
54
+ * @param expiresIn - Value in milliseconds until the entry expires
55
+ * @private
56
+ */
57
+ set(key: string, value: unknown, expiresIn?: number): void;
58
+ /**
59
+ * Delete a cache entry
60
+ * @param key
61
+ * @private
62
+ */
63
+ delete(key: string): void;
64
+ }
65
+ export {};
@@ -0,0 +1,86 @@
1
+ /**
2
+ * Core configuration used by the SDK.
3
+ * - `ENDPOINTS.SPiD` — SPiD endpoints per environment
4
+ * - `ENDPOINTS.BFF` — Endpoints used with new GDPR-compliant web flows
5
+ * - `ENDPOINTS.SESSION_SERVICE` — Endpoints to check global user session data
6
+ *
7
+ */
8
+ declare const config: {
9
+ readonly ENDPOINTS: {
10
+ readonly SPiD: {
11
+ readonly LOCAL: "http://id.localhost";
12
+ readonly DEV: "https://identity-dev.schibsted.com";
13
+ readonly PRE: "https://identity-pre.schibsted.com";
14
+ readonly PRO: "https://login.schibsted.com";
15
+ readonly PRO_NO: "https://payment.schibsted.no";
16
+ readonly PRO_FI: "https://login.schibsted.fi";
17
+ readonly PRO_DK: "https://login.schibsted.dk";
18
+ };
19
+ readonly BFF: {
20
+ readonly LOCAL: "http://id.localhost/authn/";
21
+ readonly DEV: "https://identity-dev.schibsted.com/authn/";
22
+ readonly PRE: "https://identity-pre.schibsted.com/authn/";
23
+ readonly PRO: "https://login.schibsted.com/authn/";
24
+ readonly PRO_NO: "https://payment.schibsted.no/authn/";
25
+ readonly PRO_FI: "https://login.schibsted.fi/authn/";
26
+ readonly PRO_DK: "https://login.schibsted.dk/authn/";
27
+ };
28
+ readonly SESSION_SERVICE: {
29
+ readonly LOCAL: "http://session-service.id.localhost";
30
+ readonly DEV: "https://session-service.identity-dev.schibsted.com";
31
+ readonly PRE: "https://session-service.identity-pre.schibsted.com";
32
+ readonly PRO: "https://session-service.login.schibsted.com";
33
+ readonly PRO_NO: "https://session-service.payment.schibsted.no";
34
+ readonly PRO_FI: "https://session-service.login.schibsted.fi";
35
+ readonly PRO_DK: "https://session-service.login.schibsted.dk";
36
+ };
37
+ };
38
+ readonly NAMESPACE: {
39
+ readonly LOCAL: "id.localhost";
40
+ readonly DEV: "schibsted.com";
41
+ readonly PRE: "schibsted.com";
42
+ readonly PRO: "schibsted.com";
43
+ readonly PRO_NO: "spid.no";
44
+ readonly PRO_FI: "schibsted.fi";
45
+ readonly PRO_DK: "schibsted.dk";
46
+ };
47
+ };
48
+ export default config;
49
+ export declare const ENDPOINTS: {
50
+ readonly SPiD: {
51
+ readonly LOCAL: "http://id.localhost";
52
+ readonly DEV: "https://identity-dev.schibsted.com";
53
+ readonly PRE: "https://identity-pre.schibsted.com";
54
+ readonly PRO: "https://login.schibsted.com";
55
+ readonly PRO_NO: "https://payment.schibsted.no";
56
+ readonly PRO_FI: "https://login.schibsted.fi";
57
+ readonly PRO_DK: "https://login.schibsted.dk";
58
+ };
59
+ readonly BFF: {
60
+ readonly LOCAL: "http://id.localhost/authn/";
61
+ readonly DEV: "https://identity-dev.schibsted.com/authn/";
62
+ readonly PRE: "https://identity-pre.schibsted.com/authn/";
63
+ readonly PRO: "https://login.schibsted.com/authn/";
64
+ readonly PRO_NO: "https://payment.schibsted.no/authn/";
65
+ readonly PRO_FI: "https://login.schibsted.fi/authn/";
66
+ readonly PRO_DK: "https://login.schibsted.dk/authn/";
67
+ };
68
+ readonly SESSION_SERVICE: {
69
+ readonly LOCAL: "http://session-service.id.localhost";
70
+ readonly DEV: "https://session-service.identity-dev.schibsted.com";
71
+ readonly PRE: "https://session-service.identity-pre.schibsted.com";
72
+ readonly PRO: "https://session-service.login.schibsted.com";
73
+ readonly PRO_NO: "https://session-service.payment.schibsted.no";
74
+ readonly PRO_FI: "https://session-service.login.schibsted.fi";
75
+ readonly PRO_DK: "https://session-service.login.schibsted.dk";
76
+ };
77
+ };
78
+ export declare const NAMESPACE: {
79
+ readonly LOCAL: "id.localhost";
80
+ readonly DEV: "schibsted.com";
81
+ readonly PRE: "schibsted.com";
82
+ readonly PRO: "schibsted.com";
83
+ readonly PRO_NO: "spid.no";
84
+ readonly PRO_FI: "schibsted.fi";
85
+ readonly PRO_DK: "schibsted.dk";
86
+ };
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Names of the SDK instance properties that can be registered on the global {@link Window} object.
3
+ */
4
+ type Property = '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 {};
@@ -0,0 +1,13 @@
1
+ import { Identity } from './identity.js';
2
+ import { Monetization } from './monetization.js';
3
+ declare global {
4
+ interface Window {
5
+ schIdentity?: Identity;
6
+ schMonetization?: Monetization;
7
+ SPiD?: {
8
+ Talk?: {
9
+ response?: (callbackName: string, data: unknown) => unknown;
10
+ };
11
+ };
12
+ }
13
+ }