@schibsted/account-sdk-browser 6.0.0-alpha.1 → 6.0.0-alpha.3

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 (89) hide show
  1. package/README.md +39 -64
  2. package/dist/account-sdk.d.ts +4 -0
  3. package/dist/account.d.ts +29 -0
  4. package/dist/cache.d.ts +65 -0
  5. package/dist/config.d.ts +86 -0
  6. package/dist/get-account-sdk.d.ts +3 -0
  7. package/dist/global-registry.d.ts +23 -0
  8. package/dist/globals.d.ts +15 -0
  9. package/dist/has-access-response.d.ts +2 -0
  10. package/dist/identity.d.ts +323 -0
  11. package/dist/index.d.ts +8 -0
  12. package/dist/index.js +859 -0
  13. package/dist/index.js.map +1 -0
  14. package/dist/monetization.d.ts +58 -0
  15. package/{src → dist}/object.d.ts +4 -9
  16. package/dist/popup.d.ts +9 -0
  17. package/dist/resolve-browser-window.d.ts +1 -0
  18. package/dist/rest-client.d.ts +102 -0
  19. package/dist/rest-clients.d.ts +10 -0
  20. package/dist/sdk-error.d.ts +27 -0
  21. package/dist/session-response.d.ts +30 -0
  22. package/{src/spidTalk.d.ts → dist/spid-talk.d.ts} +4 -6
  23. package/dist/types/account.d.ts +13 -0
  24. package/dist/types/common.d.ts +22 -0
  25. package/dist/types/identity.d.ts +41 -0
  26. package/dist/types/login.d.ts +120 -0
  27. package/dist/types/monetization-guards.d.ts +2 -0
  28. package/dist/types/monetization.d.ts +21 -0
  29. package/dist/types/session-guards.d.ts +36 -0
  30. package/dist/types/session.d.ts +124 -0
  31. package/dist/url.d.ts +8 -0
  32. package/dist/validate.d.ts +50 -0
  33. package/dist/version.d.ts +2 -0
  34. package/package.json +30 -22
  35. package/src/account-sdk.ts +74 -0
  36. package/src/account.ts +149 -0
  37. package/src/{cache.js → cache.ts} +53 -38
  38. package/src/{config.js → config.ts} +7 -32
  39. package/src/get-account-sdk.ts +94 -0
  40. package/src/global-registry.ts +39 -0
  41. package/src/globals.ts +12 -0
  42. package/src/has-access-response.ts +35 -0
  43. package/src/identity.ts +1102 -0
  44. package/src/index.ts +32 -0
  45. package/src/{monetization.js → monetization.ts} +65 -73
  46. package/src/{object.js → object.ts} +9 -16
  47. package/src/popup.ts +74 -0
  48. package/src/resolve-browser-window.ts +11 -0
  49. package/src/rest-client.ts +253 -0
  50. package/src/rest-clients.ts +30 -0
  51. package/src/sdk-error.ts +59 -0
  52. package/src/session-response.ts +85 -0
  53. package/src/{spidTalk.js → spid-talk.ts} +10 -12
  54. package/src/types/account.ts +27 -0
  55. package/src/types/common.ts +26 -0
  56. package/src/types/identity.ts +55 -0
  57. package/src/types/login.ts +145 -0
  58. package/src/types/monetization-guards.ts +35 -0
  59. package/src/types/monetization.ts +24 -0
  60. package/src/types/session-guards.ts +89 -0
  61. package/src/types/session.ts +147 -0
  62. package/src/{url.js → url.ts} +6 -10
  63. package/src/{validate.js → validate.ts} +27 -43
  64. package/src/{version.js → version.ts} +1 -2
  65. package/identity.d.ts +0 -1
  66. package/identity.js +0 -5
  67. package/index.d.ts +0 -4
  68. package/index.js +0 -9
  69. package/monetization.d.ts +0 -1
  70. package/monetization.js +0 -5
  71. package/payment.d.ts +0 -1
  72. package/payment.js +0 -5
  73. package/src/RESTClient.d.ts +0 -89
  74. package/src/RESTClient.js +0 -193
  75. package/src/SDKError.d.ts +0 -16
  76. package/src/SDKError.js +0 -55
  77. package/src/cache.d.ts +0 -64
  78. package/src/config.d.ts +0 -34
  79. package/src/global-registry.js +0 -20
  80. package/src/identity.d.ts +0 -679
  81. package/src/identity.js +0 -1154
  82. package/src/monetization.d.ts +0 -80
  83. package/src/payment.d.ts +0 -115
  84. package/src/payment.js +0 -211
  85. package/src/popup.d.ts +0 -10
  86. package/src/popup.js +0 -59
  87. package/src/url.d.ts +0 -10
  88. package/src/validate.d.ts +0 -64
  89. package/src/version.d.ts +0 -2
package/README.md CHANGED
@@ -24,11 +24,12 @@ 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
- 2. Use this library as you would any other npm module: `import { Identity, Monetization, Payment } from '@schibsted/account-sdk-browser'`.
27
+ 2. Use this library as you would any other npm module: `import { createAccountSdk, getAccountSdk } from '@schibsted/account-sdk-browser'`.
28
28
  3. Build your site as you prefer. This library is published as ES modules and uses modern JavaScript
29
29
  syntax (including async/await and other ES2017 and WHATWG features). We recommend that you do
30
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`.
31
+ 4. Initiate the SDK with `createAccountSdk` and provide `clientId`, `redirectUri` and `sessionDomain`.
32
+ Set `env` if you do not want to use the default `PRE` environment.
32
33
 
33
34
  If this is for a new site and there is no sessionDomain yet, contact
34
35
  [support](mailto:schibstedaccount@schibsted.com) to initiate the process.
@@ -41,8 +42,8 @@ Follow the [migration guide](./MIGRATION.md).
41
42
 
42
43
  1. Ensure that your site has no site specific terms and conditions in the Schibsted account login flow.
43
44
  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.
44
- 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.
45
- 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`.
45
+ 1. Set up a function to check if users landing on your domain [are logged in](https://schibsted.github.io/account-sdk-browser/classes/Account.html#isloggedin) to your site.
46
+ 1. If the user is not logged-in to your site, call the [showSimplifiedLoginWidget](https://schibsted.github.io/account-sdk-browser/classes/Account.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`.
46
47
  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.
47
48
 
48
49
  ## Example project
@@ -65,39 +66,35 @@ This allows you to call Schibsted Account APIs on behalf of that user.
65
66
 
66
67
  ## Events
67
68
 
68
- The SDK fires events on the instances when something we deem interesting is happening. For example the
69
- [Identity](https://schibsted.github.io/account-sdk-browser/Identity.html) class
70
- emits some events when the user is logged in or logged out. This SDK uses a familar interface that's
71
- very similar to Node's [EventEmitter](https://nodejs.org/api/events.html). The most important
69
+ The SDK fires events on the Account instance when something we deem interesting is happening. For
70
+ example, the Account instance emits events when the user is logged in or logged out. This SDK uses a
71
+ familiar interface that's very similar to Node's [EventEmitter](https://nodejs.org/api/events.html). The most important
72
72
  methods are `.on(eventName, listener)` (to subscribe to an event) and `.off(eventName, listener)`
73
73
  (to unsubscribe to an event).
74
74
 
75
- The SDK also emits global events on the `window` when a new instance is created.
76
- Events are emitted for:
75
+ The SDK also emits a global event on the `window` when a new Account instance is created.
77
76
 
78
77
  | Class | event name |
79
78
  | ------------ | ----------------------- |
80
- | Identity | `schIdentity:ready` |
81
- | Monetization | `schMonetization:ready` |
82
- | Payment | `schPayment:ready` |
79
+ | Account | `schAccount:ready` |
83
80
 
84
81
  ```js
85
- window.addEventListener('schIdentity:ready', e => {
82
+ window.addEventListener('schAccount:ready', e => {
86
83
  // The event contains the initialized instance (e.detail.instance);
87
84
  }
88
85
 
89
86
  ```
90
87
 
91
- ## Identity
88
+ ## Account
92
89
 
93
90
  Let's start with a bit of example code:
94
91
 
95
92
  #### Example
96
93
 
97
94
  ```javascript
98
- import { Identity } from '@schibsted/account-sdk-browser';
95
+ import { createAccountSdk } from '@schibsted/account-sdk-browser';
99
96
 
100
- const identity = new Identity({
97
+ const account = createAccountSdk({
101
98
  clientId: '56e9a5d1eee0000000000000',
102
99
  redirectUri: 'https://awesomenews.site', // ensure it's listed in selfservice
103
100
  env: 'PRE', // Schibsted account env. A url or a special key: 'PRE', 'PRO', 'PRO_NO', 'PRO_FI' or 'PRO_DK'
@@ -106,8 +103,8 @@ const identity = new Identity({
106
103
 
107
104
  async function whenSiteLoaded() {
108
105
  const loginContainer = document.getElementById('login-container');
109
- if (await identity.isLoggedIn()) {
110
- const user = await identity.getUser();
106
+ if (await account.isLoggedIn()) {
107
+ const user = await account.getUser();
111
108
  const span = document.createElement('span');
112
109
  span.textContent = `Hello ${user.givenName}`;
113
110
  loginContainer.appendChild(span);
@@ -117,10 +114,18 @@ async function whenSiteLoaded() {
117
114
  }
118
115
 
119
116
  function userClicksLogIn() {
120
- identity.login({ state: 'some-random-string-1234-foobar-wonky-pig' });
117
+ account.login({ state: 'some-random-string-1234-foobar-wonky-pig' });
121
118
  }
122
119
  ```
123
120
 
121
+ If your code needs the initialized singleton from another module, use `getAccountSdk()`:
122
+
123
+ ```javascript
124
+ import { getAccountSdk } from '@schibsted/account-sdk-browser';
125
+
126
+ const account = await getAccountSdk();
127
+ ```
128
+
124
129
  #### Regarding `state`
125
130
 
126
131
  This parameter is an OpenID Connect parameter (described in [this paragraph in the
@@ -129,7 +134,7 @@ an opaque string. This means you can send anything that can be serialized to a s
129
134
  we have good experience sending something like a JSON value like a base64-url-encoded value — it's
130
135
  just an easy way to avoid browsers or backends messing with special characters.
131
136
 
132
- But as a trivial example, if you call `Identity.login(..)` with params
137
+ But as a trivial example, if you call `account.login(..)` with params
133
138
  `redirectUri=https://site.com&state=article%3D1234` — then at the end of the authentication flow,
134
139
  the user will be sent back to your redirectUri, and the `state` parameter will be forwarded along
135
140
  with the auth `code` parameter.
@@ -139,7 +144,7 @@ attacks. For example this can be accomplished by:
139
144
 
140
145
  1. Your backend generates random token: `1234abcd`, saves it in some tokenCache, and forwards to
141
146
  your browser frontend
142
- 1. Your frontend calls `Identity.login` with `state = base64Urlencode({ token: '1234abcd', article:
147
+ 1. Your frontend calls `account.login` with `state = base64Urlencode({ token: '1234abcd', article:
143
148
  '1234', ... })`
144
149
  1. When auth flow completes, the user is redirected back to your site. Then, your backend sees the
145
150
  query parameters `code` (which it can exchange for OAuth tokens for the user) and `state`
@@ -160,8 +165,8 @@ mentioning that your end users have a few ways to log in:
160
165
  * Multifactor authentication: first client indicates which methods should be preferred, later these
161
166
  will be included (if fulfilled) in `AMR` claim of IDToken
162
167
 
163
- The default is username & password. If you wish to use one of the passwordless login methods, the
164
- `login()` function takes an optional parameter called `acrValues` (Authentication Context Class Reference).
168
+ The default is username & password. If you wish to use one of the passwordless login methods,
169
+ `account.login()` takes an optional parameter called `acrValues` (Authentication Context Class Reference).
165
170
  The `acrValues` parameter with multifactor authentication can take following values:
166
171
 
167
172
  * `eid` - authentication using BankID (for DEV and PRE environments you can choose between country specific solution by specifying `eid-no` or `eid-se` instead)
@@ -188,10 +193,10 @@ Schibsted account relies on browser cookies to determine whether a user is recog
188
193
  The SDK provides functions that can be used to check if the user that's visiting your site is
189
194
  already a Schibsted user or not.
190
195
 
191
- * [Identity#isLoggedIn](https://schibsted.github.io/account-sdk-browser/Identity.html#isLoggedIn)
196
+ * `account.isLoggedIn()`
192
197
  tells you if the user that is visiting your site is already logged in to Schibsted account or not.
193
198
 
194
- * [Identity#isConnected](https://schibsted.github.io/account-sdk-browser/Identity.html#isConnected)
199
+ * `account.isConnected()`
195
200
  tells you if the user is connected to your client. A user might have `isLoggedIn=true` and at the
196
201
  same time `isConnected=false` if they have logged in to Schibsted account, but not accepted terms
197
202
  and privacy policy for your site.
@@ -203,62 +208,32 @@ will just ask them to accept those terms and redirect them right back to your si
203
208
  #### Logging out
204
209
 
205
210
  If you want to log the user out of Schibsted account, you can call
206
- [Identity#logout](https://schibsted.github.io/account-sdk-browser/Identity.html#logout). This
211
+ `account.logout()`. This
207
212
  will remove the Schibsted account brand session. User will still be logged into Schibsted account.
208
213
 
209
- ## Monetization
214
+ ## Access Checks
210
215
 
211
216
  The preferred method for checking whether a user has access to a product/subscription is
212
- [Monetization#hasAccess](https://schibsted.github.io/account-sdk-browser/Monetization.html#hasAccess).
217
+ `account.hasAccess()`.
213
218
  It requires using Session Service, and supports both Schibsted account productId's and Zuora
214
219
  feature id's.
215
220
 
216
221
  #### Example
217
222
 
218
223
  ```javascript
219
- import { Monetization } from '@schibsted/account-sdk-browser';
220
-
221
- const monetization = new Monetization({
222
- clientId: '56e9a5d1eee0000000000000',
223
- redirectUri: 'https://awesomenews.site', // ensure it's listed in selfservice
224
- sessionDomain: 'https://id.aweseome.site', // client-configured session-service domain
225
- env: 'PRE', // Schibsted account env. A url or a special key: 'PRE', 'PRO' or 'PRO_NO'
226
- });
224
+ import { getAccountSdk } from '@schibsted/account-sdk-browser';
227
225
 
228
226
  try {
229
- // Check if the user has access to a a particular product
230
- const userId = await identity.getUserId();
231
- const data = await monetization.hasAccess([productId], userId);
227
+ // Check if the user has access to a particular product
228
+ const account = await getAccountSdk();
229
+ const userId = await account.getUserId();
230
+ const data = await account.hasAccess([productId], userId);
232
231
  alert(`User has access to ${productId}? ${data.entitled}`);
233
232
  } catch (err) {
234
233
  alert(`Could not query if the user has access to ${productId} because ${err}`);
235
234
  }
236
235
  ```
237
236
 
238
- ## Payment
239
-
240
- This class provides methods for paying with a so-called paylink, buying a product, getting links to
241
- pages for redeeming voucher codes, reviewing payment history, and more.
242
-
243
- #### Example
244
-
245
- ```javascript
246
- import { Payment } from '@schibsted/account-sdk-browser';
247
-
248
- const paymentSDK = new Payment({
249
- clientId: '56e9a5d1eee0000000000000',
250
- redirectUri: 'https://awesomenews.site', // ensure it's listed in selfservice
251
- env: 'PRE', // Schibsted account env. A url or a special key: 'PRE', 'PRO' or 'PRO_NO'
252
- });
253
-
254
- // Get the url to paymentSDK with paylink
255
- const paylink = '...';
256
- const paylinkUrl = paymentSDK.purchasePaylinkUrl(paylink);
257
-
258
- // Or another example --- pay with paylink in a popup
259
- paymentSDK.payWithPaylink(paylink);
260
- ```
261
-
262
237
  #### Cookies
263
238
 
264
239
  There are some cookies used by Schibsted account. They should all be considered opaque on the
@@ -0,0 +1,4 @@
1
+ import { Account } from './account.js';
2
+ import { AccountConfig } from './types/account.js';
3
+ export declare function createAccountSdk(config: AccountConfig): Account;
4
+ export declare function getAccountSdk(): Promise<Account>;
@@ -0,0 +1,29 @@
1
+ import { AccountConfig, AccountEventHandler, AccountEventName } from './types/account.js';
2
+ import { LoginOptions, SimplifiedLoginData, SimplifiedLoginWidgetLoginOptions, SimplifiedLoginWidgetOptions } from './types/login.js';
3
+ import { HasAccessResult } from './types/monetization.js';
4
+ import { ConnectedSessionResponse, SessionResponse, SessionUserId } from './types/session.js';
5
+ /**
6
+ * Unified client-side interface for a configured Schibsted Account integration.
7
+ */
8
+ export declare class Account {
9
+ #private;
10
+ constructor(config: AccountConfig);
11
+ hasSession(): Promise<SessionResponse>;
12
+ isLoggedIn(): Promise<boolean>;
13
+ isConnected(): Promise<boolean>;
14
+ getUser(): Promise<ConnectedSessionResponse>;
15
+ getUserId(): Promise<string>;
16
+ getUserSDRN(): Promise<string>;
17
+ getUserContextData(): Promise<SimplifiedLoginData | null>;
18
+ getSpId(): Promise<string | null>;
19
+ login(options: LoginOptions): Window | null;
20
+ logout(redirectUri?: string): void;
21
+ loginUrl(options: LoginOptions): string;
22
+ showSimplifiedLoginWidget(loginParams: SimplifiedLoginWidgetLoginOptions, options?: SimplifiedLoginWidgetOptions): Promise<boolean>;
23
+ clearCachedUserSession(): void;
24
+ hasAccess(productIds: string[], userId: SessionUserId): Promise<HasAccessResult | null>;
25
+ clearCachedAccessResult(productIds: string[], userId: SessionUserId): void;
26
+ on(event: AccountEventName, callback: AccountEventHandler, ctx?: unknown): this;
27
+ off(event: AccountEventName, callback?: AccountEventHandler): this;
28
+ }
29
+ export default Account;
@@ -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,3 @@
1
+ import { Account } from './account.js';
2
+ import { AccountConfig } from './types/account.js';
3
+ export declare function getAccountSdk(config?: AccountConfig): Promise<Account>;
@@ -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 = '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 {};
@@ -0,0 +1,15 @@
1
+ import { Account } from './account.js';
2
+ import { Identity } from './identity.js';
3
+ import { Monetization } from './monetization.js';
4
+ declare global {
5
+ interface Window {
6
+ schAccount?: Account;
7
+ schIdentity?: Identity;
8
+ schMonetization?: Monetization;
9
+ SPiD?: {
10
+ Talk?: {
11
+ response?: (callbackName: string, data: unknown) => unknown;
12
+ };
13
+ };
14
+ }
15
+ }
@@ -0,0 +1,2 @@
1
+ import { HasAccessResult } from './types/monetization.js';
2
+ export declare function parseHasAccessResult(value: unknown): HasAccessResult;