@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.
- package/README.md +39 -64
- package/dist/account-sdk.d.ts +4 -0
- package/dist/account.d.ts +29 -0
- package/dist/cache.d.ts +65 -0
- package/dist/config.d.ts +86 -0
- package/dist/get-account-sdk.d.ts +3 -0
- package/dist/global-registry.d.ts +23 -0
- package/dist/globals.d.ts +15 -0
- package/dist/has-access-response.d.ts +2 -0
- package/dist/identity.d.ts +323 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +859 -0
- package/dist/index.js.map +1 -0
- package/dist/monetization.d.ts +58 -0
- package/{src → dist}/object.d.ts +4 -9
- package/dist/popup.d.ts +9 -0
- package/dist/resolve-browser-window.d.ts +1 -0
- package/dist/rest-client.d.ts +102 -0
- package/dist/rest-clients.d.ts +10 -0
- package/dist/sdk-error.d.ts +27 -0
- package/dist/session-response.d.ts +30 -0
- package/{src/spidTalk.d.ts → dist/spid-talk.d.ts} +4 -6
- package/dist/types/account.d.ts +13 -0
- package/dist/types/common.d.ts +22 -0
- package/dist/types/identity.d.ts +41 -0
- package/dist/types/login.d.ts +120 -0
- package/dist/types/monetization-guards.d.ts +2 -0
- package/dist/types/monetization.d.ts +21 -0
- package/dist/types/session-guards.d.ts +36 -0
- package/dist/types/session.d.ts +124 -0
- package/dist/url.d.ts +8 -0
- package/dist/validate.d.ts +50 -0
- package/dist/version.d.ts +2 -0
- package/package.json +30 -22
- package/src/account-sdk.ts +74 -0
- package/src/account.ts +149 -0
- package/src/{cache.js → cache.ts} +53 -38
- package/src/{config.js → config.ts} +7 -32
- package/src/get-account-sdk.ts +94 -0
- package/src/global-registry.ts +39 -0
- package/src/globals.ts +12 -0
- package/src/has-access-response.ts +35 -0
- package/src/identity.ts +1102 -0
- package/src/index.ts +32 -0
- package/src/{monetization.js → monetization.ts} +65 -73
- package/src/{object.js → object.ts} +9 -16
- package/src/popup.ts +74 -0
- package/src/resolve-browser-window.ts +11 -0
- package/src/rest-client.ts +253 -0
- package/src/rest-clients.ts +30 -0
- package/src/sdk-error.ts +59 -0
- package/src/session-response.ts +85 -0
- package/src/{spidTalk.js → spid-talk.ts} +10 -12
- package/src/types/account.ts +27 -0
- package/src/types/common.ts +26 -0
- package/src/types/identity.ts +55 -0
- package/src/types/login.ts +145 -0
- package/src/types/monetization-guards.ts +35 -0
- package/src/types/monetization.ts +24 -0
- package/src/types/session-guards.ts +89 -0
- package/src/types/session.ts +147 -0
- package/src/{url.js → url.ts} +6 -10
- package/src/{validate.js → validate.ts} +27 -43
- package/src/{version.js → version.ts} +1 -2
- package/identity.d.ts +0 -1
- package/identity.js +0 -5
- package/index.d.ts +0 -4
- package/index.js +0 -9
- package/monetization.d.ts +0 -1
- package/monetization.js +0 -5
- package/payment.d.ts +0 -1
- package/payment.js +0 -5
- package/src/RESTClient.d.ts +0 -89
- package/src/RESTClient.js +0 -193
- package/src/SDKError.d.ts +0 -16
- package/src/SDKError.js +0 -55
- package/src/cache.d.ts +0 -64
- package/src/config.d.ts +0 -34
- package/src/global-registry.js +0 -20
- package/src/identity.d.ts +0 -679
- package/src/identity.js +0 -1154
- package/src/monetization.d.ts +0 -80
- package/src/payment.d.ts +0 -115
- package/src/payment.js +0 -211
- package/src/popup.d.ts +0 -10
- package/src/popup.js +0 -59
- package/src/url.d.ts +0 -10
- package/src/validate.d.ts +0 -64
- 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 {
|
|
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
|
|
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 [
|
|
45
|
-
1. If the user is not logged-in to your site, call the [showSimplifiedLoginWidget](https://schibsted.github.io/account-sdk-browser/
|
|
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
|
|
69
|
-
|
|
70
|
-
|
|
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
|
|
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
|
-
|
|
|
81
|
-
| Monetization | `schMonetization:ready` |
|
|
82
|
-
| Payment | `schPayment:ready` |
|
|
79
|
+
| Account | `schAccount:ready` |
|
|
83
80
|
|
|
84
81
|
```js
|
|
85
|
-
window.addEventListener('
|
|
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
|
-
##
|
|
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 {
|
|
95
|
+
import { createAccountSdk } from '@schibsted/account-sdk-browser';
|
|
99
96
|
|
|
100
|
-
const
|
|
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
|
|
110
|
-
const user = await
|
|
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
|
-
|
|
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 `
|
|
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 `
|
|
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,
|
|
164
|
-
`login()`
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
|
|
211
|
+
`account.logout()`. This
|
|
207
212
|
will remove the Schibsted account brand session. User will still be logged into Schibsted account.
|
|
208
213
|
|
|
209
|
-
##
|
|
214
|
+
## Access Checks
|
|
210
215
|
|
|
211
216
|
The preferred method for checking whether a user has access to a product/subscription is
|
|
212
|
-
|
|
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 {
|
|
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
|
|
230
|
-
const
|
|
231
|
-
const
|
|
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,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;
|
package/dist/cache.d.ts
ADDED
|
@@ -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 {};
|
package/dist/config.d.ts
ADDED
|
@@ -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 = '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
|
+
}
|