@schibsted/account-sdk-browser 6.0.0-alpha.7 → 6.0.0-alpha.9
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 +11 -273
- package/dist/account.d.ts +19 -7
- package/dist/identity.d.ts +25 -3
- package/dist/index.d.ts +2 -0
- package/dist/index.js +41 -26
- package/dist/index.js.map +1 -1
- package/dist/session-response.d.ts +24 -0
- package/dist/types/account.d.ts +6 -4
- package/dist/types/session.d.ts +2 -5
- package/dist/version.d.ts +1 -1
- package/package.json +1 -1
- package/src/account.ts +39 -8
- package/src/has-access-response.ts +1 -1
- package/src/identity.ts +66 -7
- package/src/index.ts +8 -0
- package/src/session-response.ts +25 -4
- package/src/types/account.ts +6 -4
- package/src/types/session.ts +2 -5
- package/src/version.ts +1 -1
package/README.md
CHANGED
|
@@ -8,23 +8,7 @@ Welcome! This is the home of the Schibsted Account JavaScript SDK for browsers.
|
|
|
8
8
|
sign up and log in with Schibsted Account, read the current session, and check access to products
|
|
9
9
|
and features.
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
Create one SDK instance with `createAccountSdk()`. Use `getAccountSdk()` when another module needs
|
|
14
|
-
to wait for that initialized `Account` instance.
|
|
15
|
-
|
|
16
|
-
The package publishes ES modules and modern JavaScript, including async/await and WHATWG browser
|
|
17
|
-
APIs. It does not include polyfills.
|
|
18
|
-
|
|
19
|
-
## Installation
|
|
20
|
-
|
|
21
|
-
```sh
|
|
22
|
-
npm install --save @schibsted/account-sdk-browser
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
```js
|
|
26
|
-
import { createAccountSdk, getAccountSdk } from '@schibsted/account-sdk-browser';
|
|
27
|
-
```
|
|
11
|
+
For detailed Account SDK API documentation, check [TYPEDOC](./TYPEDOC.md).
|
|
28
12
|
|
|
29
13
|
## Before You Start
|
|
30
14
|
|
|
@@ -44,261 +28,16 @@ For example, if your pre-production site is `pre.sdk-example.com` and uses
|
|
|
44
28
|
If this is a new site and you do not have a `sessionDomain` yet, contact
|
|
45
29
|
[support](mailto:schibstedaccount@schibsted.com).
|
|
46
30
|
|
|
47
|
-
##
|
|
48
|
-
|
|
49
|
-
Create the SDK once during application startup:
|
|
50
|
-
|
|
51
|
-
```js
|
|
52
|
-
import { createAccountSdk } from '@schibsted/account-sdk-browser';
|
|
53
|
-
|
|
54
|
-
const account = createAccountSdk({
|
|
55
|
-
clientId: '56e9a5d1eee0000000000000',
|
|
56
|
-
redirectUri: 'https://awesomenews.site/callback',
|
|
57
|
-
sessionDomain: 'https://id.awesomenews.site',
|
|
58
|
-
env: 'PRE',
|
|
59
|
-
});
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
Required configuration:
|
|
63
|
-
|
|
64
|
-
- `clientId`: your Schibsted Account client id
|
|
65
|
-
- `redirectUri`: the callback URL registered for your client
|
|
66
|
-
- `sessionDomain`: your client-configured Session Service domain
|
|
67
|
-
|
|
68
|
-
Optional configuration:
|
|
69
|
-
|
|
70
|
-
- `env`: defaults to `PRE`; supported keys include `LOCAL`, `DEV`, `PRE`, `PRO`, `PRO_NO`,
|
|
71
|
-
`PRO_FI`, and `PRO_DK`
|
|
72
|
-
- `callbackBeforeRedirect`: called before a full-page session refresh redirect
|
|
73
|
-
- `log`: receives SDK debug log lines
|
|
74
|
-
- `varnish`: enables Varnish cookie handling
|
|
75
|
-
- `window`: overrides the browser window object, mostly useful in tests
|
|
76
|
-
|
|
77
|
-
`createAccountSdk()` registers the instance on `window.schAccount` and emits
|
|
78
|
-
`schAccount:ready` event.
|
|
79
|
-
|
|
80
|
-
```js
|
|
81
|
-
window.addEventListener('schAccount:ready', (event) => {
|
|
82
|
-
const account = event.detail.instance;
|
|
83
|
-
});
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
If another module needs the initialized instance, use `getAccountSdk()`:
|
|
87
|
-
|
|
88
|
-
```js
|
|
89
|
-
import { getAccountSdk } from '@schibsted/account-sdk-browser';
|
|
90
|
-
|
|
91
|
-
const account = await getAccountSdk();
|
|
92
|
-
```
|
|
31
|
+
## Development
|
|
93
32
|
|
|
94
|
-
|
|
95
|
-
for `schAccount:ready` and rejects if initialization does not happen within 4000 ms.
|
|
33
|
+
Install dependencies and run the standard checks:
|
|
96
34
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
const container = document.getElementById('login-container');
|
|
104
|
-
|
|
105
|
-
if (await account.isConnected()) {
|
|
106
|
-
const user = await account.getUser();
|
|
107
|
-
container.textContent = `Hello ${user.givenName || user.displayName || user.userId}`;
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
container.innerHTML = '<button type="button">Log in</button>';
|
|
112
|
-
container.querySelector('button').addEventListener('click', () => {
|
|
113
|
-
account.login({ state: createLoginState() });
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
```
|
|
117
|
-
|
|
118
|
-
## Login Flow
|
|
119
|
-
|
|
120
|
-
Use `account.login()` to start the OAuth authorization flow:
|
|
121
|
-
|
|
122
|
-
```js
|
|
123
|
-
account.login({
|
|
124
|
-
state: createLoginState(),
|
|
125
|
-
scope: 'openid',
|
|
126
|
-
preferPopup: false,
|
|
127
|
-
});
|
|
128
|
-
```
|
|
129
|
-
|
|
130
|
-
By default the SDK redirects the current window. Set `preferPopup: true` when login is triggered by
|
|
131
|
-
a user gesture and you want to try a popup first. If the popup cannot be opened, the SDK falls back
|
|
132
|
-
to the redirect flow.
|
|
133
|
-
|
|
134
|
-
If you only need the URL, use `account.loginUrl()`:
|
|
135
|
-
|
|
136
|
-
```js
|
|
137
|
-
const url = account.loginUrl({ state: createLoginState() });
|
|
138
|
-
```
|
|
139
|
-
|
|
140
|
-
### Handling `state`
|
|
141
|
-
|
|
142
|
-
`state` is an opaque OpenID Connect value that is returned to your `redirectUri` with the
|
|
143
|
-
authorization `code`. Use it to protect against CSRF and to restore application state.
|
|
144
|
-
|
|
145
|
-
A common pattern is:
|
|
146
|
-
|
|
147
|
-
1. Your backend creates a random token and stores it temporarily.
|
|
148
|
-
2. Your frontend calls `account.login({ state })` with that token, or with an encoded payload that
|
|
149
|
-
contains it.
|
|
150
|
-
3. Schibsted Account redirects back to your `redirectUri` with `code` and `state`.
|
|
151
|
-
4. Your backend validates the returned `state` before exchanging `code` for tokens.
|
|
152
|
-
|
|
153
|
-
Keep Access Tokens and Refresh Tokens on your backend. Do not send them to the browser.
|
|
154
|
-
|
|
155
|
-
### Authentication Methods
|
|
156
|
-
|
|
157
|
-
Use `acrValues` when you need to request a specific authentication method:
|
|
158
|
-
|
|
159
|
-
```js
|
|
160
|
-
account.login({
|
|
161
|
-
state: createLoginState(),
|
|
162
|
-
acrValues: 'otp-email',
|
|
163
|
-
});
|
|
164
|
-
```
|
|
165
|
-
|
|
166
|
-
Supported values include `password`, `otp`, `sms`, `otp-email`, `eid`, `eid-no`, `eid-se`,
|
|
167
|
-
`eid-fi`, and `eid-dk`. Values other than `otp-email` can be combined as a space-separated string
|
|
168
|
-
where supported by the account flow. Verify the resulting AMR claim in the ID token on your backend
|
|
169
|
-
if you need to enforce a completed authentication method.
|
|
170
|
-
|
|
171
|
-
## Session and User Data
|
|
172
|
-
|
|
173
|
-
Use these methods to inspect the current Session Service state:
|
|
174
|
-
|
|
175
|
-
- `account.hasSession()` returns the raw SDK-known session response
|
|
176
|
-
- `account.isLoggedIn()` returns whether the browser has a Schibsted Account session
|
|
177
|
-
- `account.isConnected()` returns whether the user is connected to your client
|
|
178
|
-
- `account.getUser()` returns the connected user session data
|
|
179
|
-
- `account.getUserId()` returns the realm-specific user id as a string
|
|
180
|
-
- `account.getUserUuid()` returns the globally unique user id
|
|
181
|
-
- `account.getUserSDRN()` returns the user SDRN
|
|
182
|
-
- `account.getSpId()` returns the Varnish `sp_id` value when present
|
|
183
|
-
|
|
184
|
-
Some session methods can trigger a full-page Session Service refresh redirect, especially for
|
|
185
|
-
Safari-based browsers. Use `callbackBeforeRedirect` if you need to persist client state before that
|
|
186
|
-
happens.
|
|
187
|
-
|
|
188
|
-
```js
|
|
189
|
-
const account = createAccountSdk({
|
|
190
|
-
clientId,
|
|
191
|
-
redirectUri,
|
|
192
|
-
sessionDomain,
|
|
193
|
-
callbackBeforeRedirect: () => {
|
|
194
|
-
saveCurrentUiState();
|
|
195
|
-
},
|
|
196
|
-
});
|
|
197
|
-
```
|
|
198
|
-
|
|
199
|
-
## Logout and Account Page
|
|
200
|
-
|
|
201
|
-
Use `account.logout()` to remove the brand Session Service session and redirect the browser:
|
|
202
|
-
|
|
203
|
-
```js
|
|
204
|
-
account.logout('https://awesomenews.site/logged-out');
|
|
205
|
-
```
|
|
206
|
-
|
|
207
|
-
Use `account.logoutUrl()` when you need the logout URL without navigating immediately:
|
|
208
|
-
|
|
209
|
-
```js
|
|
210
|
-
const logoutUrl = account.logoutUrl('https://awesomenews.site/logged-out');
|
|
211
|
-
```
|
|
212
|
-
|
|
213
|
-
Use `account.accountUrl()` to send the user to their Schibsted Account profile page:
|
|
214
|
-
|
|
215
|
-
```js
|
|
216
|
-
window.location.href = account.accountUrl('https://awesomenews.site/account-return');
|
|
217
|
-
```
|
|
218
|
-
|
|
219
|
-
## Access Checks
|
|
220
|
-
|
|
221
|
-
Use `account.hasAccess()` to check access to Schibsted Account product ids or Zuora feature ids:
|
|
222
|
-
|
|
223
|
-
```js
|
|
224
|
-
const userId = await account.getUserId();
|
|
225
|
-
const access = await account.hasAccess(['product-id'], userId);
|
|
226
|
-
|
|
227
|
-
if (access?.entitled) {
|
|
228
|
-
showPremiumContent();
|
|
229
|
-
} else {
|
|
230
|
-
showPaywall();
|
|
231
|
-
}
|
|
232
|
-
```
|
|
233
|
-
|
|
234
|
-
`hasAccess()` requires `sessionDomain`. Results are cached according to the Session Service TTL.
|
|
235
|
-
Use `account.clearCachedAccessResult(productIds, userId)` when you need to invalidate that cache.
|
|
236
|
-
|
|
237
|
-
## Simplified Login Widget
|
|
238
|
-
|
|
239
|
-
Before using the simplified login widget, make sure your site has no site-specific terms and
|
|
240
|
-
conditions in the Schibsted Account login flow.
|
|
241
|
-
|
|
242
|
-
The widget is shown only when the SDK can read enough user context from the global account session.
|
|
243
|
-
Your application decides when and how often to show it.
|
|
244
|
-
|
|
245
|
-
```js
|
|
246
|
-
if (!(await account.isConnected()) && shouldShowSimplifiedLogin()) {
|
|
247
|
-
const opened = await account.showSimplifiedLoginWidget(
|
|
248
|
-
{ state: createLoginState },
|
|
249
|
-
{ locale: 'nb' },
|
|
250
|
-
);
|
|
251
|
-
|
|
252
|
-
if (opened) {
|
|
253
|
-
rememberSimplifiedLoginWasShown();
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
```
|
|
257
|
-
|
|
258
|
-
`state` may be a string or a function that returns a string or `Promise<string>`. The function is
|
|
259
|
-
called only if the user continues from the widget.
|
|
260
|
-
|
|
261
|
-
## Events
|
|
262
|
-
|
|
263
|
-
The SDK exposes fluent `on()` and `off()` aliases for browser-native event listeners.
|
|
264
|
-
Payload-bearing events are `CustomEvent` instances and expose their payload through `detail`:
|
|
265
|
-
|
|
266
|
-
```ts
|
|
267
|
-
import type { AccountEventListener } from '@schibsted/account-sdk-browser';
|
|
268
|
-
|
|
269
|
-
const handleLogin: AccountEventListener<'login'> = (event) => {
|
|
270
|
-
console.log('Login started', event.detail.url, event.detail.method);
|
|
271
|
-
};
|
|
272
|
-
|
|
273
|
-
account.on('login', handleLogin);
|
|
274
|
-
account.off('login', handleLogin);
|
|
275
|
-
```
|
|
276
|
-
|
|
277
|
-
Available Account events:
|
|
278
|
-
|
|
279
|
-
- `login` — a `CustomEvent` whose `detail` contains `url` and the `method` (`popup` or `default`)
|
|
280
|
-
- `logout` — a `CustomEvent` whose `detail` contains the logout `url`
|
|
281
|
-
- `simplifiedLoginOpened` — an `Event` emitted when the widget is displayed
|
|
282
|
-
- `simplifiedLoginCancelled` — an `Event` emitted when the widget is closed
|
|
283
|
-
|
|
284
|
-
The SDK also emits `schAccount:ready` on `window` when an Account instance is created.
|
|
285
|
-
|
|
286
|
-
## Errors
|
|
287
|
-
|
|
288
|
-
Validation, network, and service failures from API calls reject or throw `SDKError`. Convenience
|
|
289
|
-
methods such as `isLoggedIn()`, `isConnected()`, and `getSpId()` return fallback values instead of
|
|
290
|
-
throwing when the session lookup fails.
|
|
291
|
-
|
|
292
|
-
```js
|
|
293
|
-
import { SDKError } from '@schibsted/account-sdk-browser';
|
|
294
|
-
|
|
295
|
-
try {
|
|
296
|
-
await account.getUser();
|
|
297
|
-
} catch (error) {
|
|
298
|
-
if (error instanceof SDKError) {
|
|
299
|
-
console.error(error.toString());
|
|
300
|
-
}
|
|
301
|
-
}
|
|
35
|
+
```sh
|
|
36
|
+
npm ci
|
|
37
|
+
npm run build
|
|
38
|
+
npm test
|
|
39
|
+
npm run lint
|
|
40
|
+
npm run typecheck
|
|
302
41
|
```
|
|
303
42
|
|
|
304
43
|
## API Documentation
|
|
@@ -320,9 +59,8 @@ Generated docs are written to `docs/` and are not committed.
|
|
|
320
59
|
|
|
321
60
|
## Example Project
|
|
322
61
|
|
|
323
|
-
|
|
324
|
-
[sdk-example repository](https://schibsted.ghe.com/user-identity/sdk-example)
|
|
325
|
-
at [pro.sdk-example.com](https://pro.sdk-example.com).
|
|
62
|
+
The internal example integration is available in the
|
|
63
|
+
[sdk-example repository](https://schibsted.ghe.com/user-identity/sdk-example).
|
|
326
64
|
|
|
327
65
|
## Publishing
|
|
328
66
|
|
package/dist/account.d.ts
CHANGED
|
@@ -43,13 +43,24 @@ export declare class Account {
|
|
|
43
43
|
*/
|
|
44
44
|
getUser(): Promise<ConnectedSessionResponse>;
|
|
45
45
|
/**
|
|
46
|
-
* Returns the realm-specific Schibsted Account user id as a
|
|
46
|
+
* Returns the realm-specific Schibsted Account user id as a number.
|
|
47
47
|
*
|
|
48
48
|
* Use `getUserUuid()` when you need the globally unique user id.
|
|
49
49
|
*
|
|
50
50
|
* @throws {SDKError} If the user is not connected to the configured client.
|
|
51
51
|
*/
|
|
52
|
-
getUserId(): Promise<
|
|
52
|
+
getUserId(): Promise<number>;
|
|
53
|
+
/**
|
|
54
|
+
* Returns an external identifier for the authenticated user, scoped to the configured client
|
|
55
|
+
* and external party.
|
|
56
|
+
*
|
|
57
|
+
* @param externalParty - External party for which the identifier is generated.
|
|
58
|
+
* @param optionalSuffix - Optional suffix included when generating the identifier.
|
|
59
|
+
* @throws {SDKError} If the session lookup fails, the session does not contain a `pairId`, or
|
|
60
|
+
* `externalParty` is empty.
|
|
61
|
+
* @deprecated Retained for compatibility with existing integrations. Avoid new usage.
|
|
62
|
+
*/
|
|
63
|
+
getExternalId(externalParty: string, optionalSuffix?: string): Promise<string>;
|
|
53
64
|
/**
|
|
54
65
|
* Returns the globally unique user id from the current session.
|
|
55
66
|
*
|
|
@@ -128,16 +139,17 @@ export declare class Account {
|
|
|
128
139
|
*/
|
|
129
140
|
clearCachedUserSession(): void;
|
|
130
141
|
/**
|
|
131
|
-
* Checks whether
|
|
142
|
+
* Checks whether the current user has access to any of the requested products or features.
|
|
132
143
|
*
|
|
144
|
+
* When `productIds` is omitted, the ids configured as `defaultProductIds` are used.
|
|
133
145
|
* Results are cached according to the TTL returned by Session Service.
|
|
134
146
|
*
|
|
135
|
-
* @param productIds - Product or feature ids to check.
|
|
136
|
-
* @param userId - Current user id, usually from `getUserId()`.
|
|
147
|
+
* @param productIds - Product or feature ids to check instead of the configured defaults.
|
|
137
148
|
* @returns Access data, or `null` when the user is not entitled.
|
|
138
|
-
* @throws {SDKError} If
|
|
149
|
+
* @throws {SDKError} If product ids are not provided or configured, `sessionDomain` is missing,
|
|
150
|
+
* the current user cannot be resolved, input is invalid, or the request fails.
|
|
139
151
|
*/
|
|
140
|
-
hasAccess(productIds
|
|
152
|
+
hasAccess(productIds?: string[] | undefined): Promise<HasAccessResult | null>;
|
|
141
153
|
/**
|
|
142
154
|
* Removes a cached access-check result.
|
|
143
155
|
*
|
package/dist/identity.d.ts
CHANGED
|
@@ -160,7 +160,29 @@ export declare class Identity {
|
|
|
160
160
|
* @throws {SDKError} If the user isn't connected to the merchant
|
|
161
161
|
* @return The `userId` field (not to be confused with the `uuid`)
|
|
162
162
|
*/
|
|
163
|
-
getUserId(): Promise<
|
|
163
|
+
getUserId(): Promise<number>;
|
|
164
|
+
/**
|
|
165
|
+
* @function
|
|
166
|
+
* @summary
|
|
167
|
+
* Retrieves the external identifier (`externalId`) for the authenticated user.
|
|
168
|
+
*
|
|
169
|
+
* In Schibsted Account there are multiple ways of identifying users, however for integrations with
|
|
170
|
+
* third-parties it's recommended to use `externalId` as it does not disclose
|
|
171
|
+
* any critical data whilst allowing for user identification.
|
|
172
|
+
*
|
|
173
|
+
* `externalId` is merchant-scoped using a pairwise identifier (`pairId`),
|
|
174
|
+
* meaning the same user's ID will differ between merchants.
|
|
175
|
+
* Additionally, this identifier is bound to the external party provided as argument.
|
|
176
|
+
*
|
|
177
|
+
* @param externalParty
|
|
178
|
+
* @param optionalSuffix
|
|
179
|
+
* @remarks This function calls {@link Identity#hasSession} internally and thus has the side
|
|
180
|
+
* effect that it might perform an auto-login on the user
|
|
181
|
+
* @throws {SDKError} If the `pairId` is missing in user session.
|
|
182
|
+
* @throws {SDKError} If the `externalParty` is not defined
|
|
183
|
+
* @return The merchant- and 3rd-party-specific `externalId`
|
|
184
|
+
*/
|
|
185
|
+
getExternalId(externalParty: string, optionalSuffix?: string): Promise<string>;
|
|
164
186
|
/**
|
|
165
187
|
* @summary Enables brands to programmatically get the current the SDRN based on the user's session.
|
|
166
188
|
* @remarks This function calls {@link Identity#hasSession} internally and thus has the side
|
|
@@ -213,7 +235,7 @@ export declare class Identity {
|
|
|
213
235
|
* @param options.xDomainId
|
|
214
236
|
* @param options.xEnvironmentId
|
|
215
237
|
* @param options.originCampaign
|
|
216
|
-
* @fires Identity#
|
|
238
|
+
* @fires Identity#loginRequested
|
|
217
239
|
* @return - Reference to popup window if created (or `null` otherwise)
|
|
218
240
|
*/
|
|
219
241
|
login({ state, acrValues, scope, redirectUri, preferPopup, loginHint, tag, teaser, maxAge, locale, oneStepLogin, prompt, xDomainId, xEnvironmentId, originCampaign, }: LoginOptions): Window | null;
|
|
@@ -227,7 +249,7 @@ export declare class Identity {
|
|
|
227
249
|
/**
|
|
228
250
|
* @summary Logs the user out from the Identity platform
|
|
229
251
|
* @param redirectUri - Where to redirect the browser after logging out of Schibsted account
|
|
230
|
-
* @fires Identity#
|
|
252
|
+
* @fires Identity#logoutRequested
|
|
231
253
|
*/
|
|
232
254
|
logout(redirectUri?: string): void;
|
|
233
255
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,8 @@ export { Account } from './account.js';
|
|
|
2
2
|
export { createAccountSdk, getAccountSdk } from './account-sdk.js';
|
|
3
3
|
export * from './globals.js';
|
|
4
4
|
export { default as SDKError } from './sdk-error.js';
|
|
5
|
+
/** session response type guards */
|
|
6
|
+
export { isConnectedSessionResponse, isConnectedSessionWithUserIdResponse, isSessionFailureResponse, isSessionSuccessResponse, } from './session-response.js';
|
|
5
7
|
export type { AccountConfig, AccountEventListener, AccountEventName, } from './types/account.js';
|
|
6
8
|
export type { AccountEnvironment, LogFunction } from './types/common.js';
|
|
7
9
|
export type { LoginOptions, SimplifiedLoginData, SimplifiedLoginWidgetLoginOptions, SimplifiedLoginWidgetOptions, } from './types/login.js';
|
package/dist/index.js
CHANGED
|
@@ -178,10 +178,10 @@ function y(e) {
|
|
|
178
178
|
}
|
|
179
179
|
//#endregion
|
|
180
180
|
//#region src/popup.ts
|
|
181
|
-
function
|
|
181
|
+
function b(e) {
|
|
182
182
|
return u(p(e), `Object must be an object but it is '${e}'`), Object.keys(e).map((t) => `${t}=${e[t]}`).join(",");
|
|
183
183
|
}
|
|
184
|
-
var
|
|
184
|
+
var ee = {
|
|
185
185
|
scrollbars: "yes",
|
|
186
186
|
location: "yes",
|
|
187
187
|
status: "no",
|
|
@@ -189,11 +189,11 @@ var te = {
|
|
|
189
189
|
toolbar: "no",
|
|
190
190
|
resizable: "yes"
|
|
191
191
|
};
|
|
192
|
-
function
|
|
192
|
+
function te(e, t, n = "", r = {}) {
|
|
193
193
|
u(p(e), `window was supposed to be an object but it is ${e}`), u(p(e.screen), "window should be a valid Window object but it lacks a 'screen' property"), u(g(e.open), "window should be a valid Window object but it lacks an 'open' function"), u(h(t), "Invalid URL for popup");
|
|
194
|
-
let { height: i, width: a } = e.screen, o = v(
|
|
194
|
+
let { height: i, width: a } = e.screen, o = v(ee, r), { width: s, height: c } = o;
|
|
195
195
|
typeof s == "number" && Number.isFinite(s) && Number.isFinite(a) && (o.left = (a - s) / 2), typeof c == "number" && Number.isFinite(c) && Number.isFinite(i) && (o.top = (i - c) / 2);
|
|
196
|
-
let l =
|
|
196
|
+
let l = b(o);
|
|
197
197
|
return e.open(t, n, l);
|
|
198
198
|
}
|
|
199
199
|
//#endregion
|
|
@@ -218,14 +218,14 @@ function C(e) {
|
|
|
218
218
|
};
|
|
219
219
|
return encodeURIComponent(e).replace(/[!'()~]|%20|%00/g, (e) => t[e]);
|
|
220
220
|
}
|
|
221
|
-
var
|
|
221
|
+
var re = () => window.fetch && window.fetch.bind(window), w = () => {
|
|
222
222
|
throw new t("fetch is not available in this environment");
|
|
223
|
-
},
|
|
223
|
+
}, T = class e {
|
|
224
224
|
url;
|
|
225
225
|
defaultParams;
|
|
226
226
|
log;
|
|
227
227
|
fetch;
|
|
228
|
-
constructor({ serverUrl: e = "PRE", envDic: t, fetch: n =
|
|
228
|
+
constructor({ serverUrl: e = "PRE", envDic: t, fetch: n = re() ?? w, log: r, defaultParams: i = {} }) {
|
|
229
229
|
u(p(i), "defaultParams should be a non-null object");
|
|
230
230
|
let a = x(e, t ?? {}), o = a.endsWith("/") ? a : `${a}/`;
|
|
231
231
|
this.url = new URL(o), this.defaultParams = i, r && (u(g(r), `log must be a function but it is ${r}`), this.log = r), this.fetch = n;
|
|
@@ -270,7 +270,7 @@ var w = () => window.fetch && window.fetch.bind(window), T = () => {
|
|
|
270
270
|
let r = t ? v(n, e) : v(e);
|
|
271
271
|
return Object.keys(r).filter((e) => r[e] !== "").map((e) => `${C(e)}=${C(String(r[e]))}`).join("&");
|
|
272
272
|
}
|
|
273
|
-
},
|
|
273
|
+
}, E = (e) => Object.hasOwn(l, e), D = (e, t) => (u(f(t), "clientId parameter is required"), u(E(e), `env parameter is invalid: ${e}`), `sdrn:${l[e]}:client:${t}`), O = ({ serverUrl: e, log: t, defaultParams: n }) => new T({
|
|
274
274
|
serverUrl: e,
|
|
275
275
|
log: t,
|
|
276
276
|
defaultParams: n
|
|
@@ -290,7 +290,7 @@ function M(e) {
|
|
|
290
290
|
return p(e) && Object.keys(e).length === 1 && d(e.redirectURL);
|
|
291
291
|
}
|
|
292
292
|
function N(e) {
|
|
293
|
-
return A(e) &&
|
|
293
|
+
return A(e) && typeof e.userId == "number";
|
|
294
294
|
}
|
|
295
295
|
function P(e) {
|
|
296
296
|
return M(e) || j(e) || k(e) || p(e) ? e : {};
|
|
@@ -302,7 +302,7 @@ function F(e) {
|
|
|
302
302
|
}
|
|
303
303
|
//#endregion
|
|
304
304
|
//#region src/types/login.ts
|
|
305
|
-
var I = (e) => typeof e.openSimplifiedLoginWidget == "function", L = "6.0.0-alpha.
|
|
305
|
+
var I = (e) => typeof e.openSimplifiedLoginWidget == "function", L = "6.0.0-alpha.9", R = "hasSession-cache", z = "sessionCallBlocked-cache", B = 1e3 * 60 * 5, V = "tab-id-cache", H = Math.floor(Math.random() * 1e5), U = 1e3 * 60 * 60 * 24 * 30, W = () => window, G = class {
|
|
306
306
|
eventTarget = new EventTarget();
|
|
307
307
|
window;
|
|
308
308
|
clientId;
|
|
@@ -479,9 +479,16 @@ var I = (e) => typeof e.openSimplifiedLoginWidget == "function", L = "6.0.0-alph
|
|
|
479
479
|
}
|
|
480
480
|
async getUserId() {
|
|
481
481
|
let e = await this.hasSession();
|
|
482
|
-
if (N(e)) return
|
|
482
|
+
if (N(e)) return e.userId;
|
|
483
483
|
throw new t("The user is not connected to this merchant");
|
|
484
484
|
}
|
|
485
|
+
async getExternalId(e, n = "") {
|
|
486
|
+
let r = await this.hasSession(), i = k(r) ? r.pairId : void 0;
|
|
487
|
+
if (!i) throw new t("pairId missing in user session!");
|
|
488
|
+
if (!e || e.length === 0) throw new t("externalParty cannot be empty");
|
|
489
|
+
let a = (e) => Array.from(new Uint8Array(e)).map((e) => e.toString(16).padStart(2, "0")).join(""), o = (e) => crypto.subtle.digest("SHA-256", e);
|
|
490
|
+
return (async (e) => o(new TextEncoder().encode(e)).then((e) => a(e)))(((e, t, n) => n ? `${e}:${t}:${n}` : `${e}:${t}`)(i, e, n));
|
|
491
|
+
}
|
|
485
492
|
async getUserSDRN() {
|
|
486
493
|
let e = await this.hasSession();
|
|
487
494
|
if (k(e) && e.sdrn) return e.sdrn;
|
|
@@ -522,13 +529,13 @@ var I = (e) => typeof e.openSimplifiedLoginWidget == "function", L = "6.0.0-alph
|
|
|
522
529
|
xEnvironmentId: p,
|
|
523
530
|
originCampaign: m
|
|
524
531
|
});
|
|
525
|
-
return i && (this.popup =
|
|
532
|
+
return i && (this.popup = te(this.window, h, "Schibsted account", {
|
|
526
533
|
width: 360,
|
|
527
534
|
height: 570
|
|
528
|
-
}), this.popup) ? (this.eventTarget.dispatchEvent(new CustomEvent("
|
|
535
|
+
}), this.popup) ? (this.eventTarget.dispatchEvent(new CustomEvent("loginRequested", { detail: {
|
|
529
536
|
url: h,
|
|
530
537
|
method: "popup"
|
|
531
|
-
} })), this.popup) : (this.eventTarget.dispatchEvent(new CustomEvent("
|
|
538
|
+
} })), this.popup) : (this.eventTarget.dispatchEvent(new CustomEvent("loginRequested", { detail: {
|
|
532
539
|
url: h,
|
|
533
540
|
method: "default"
|
|
534
541
|
} })), this.window.location.href = h, null);
|
|
@@ -546,7 +553,7 @@ var I = (e) => typeof e.openSimplifiedLoginWidget == "function", L = "6.0.0-alph
|
|
|
546
553
|
logout(e = this.redirectUri) {
|
|
547
554
|
this.sessionStorageCache.delete(R), this._maybeClearVarnishCookie();
|
|
548
555
|
let t = this.logoutUrl(e);
|
|
549
|
-
this.eventTarget.dispatchEvent(new CustomEvent("
|
|
556
|
+
this.eventTarget.dispatchEvent(new CustomEvent("logoutRequested", { detail: { url: t } })), this.window.location.href = t;
|
|
550
557
|
}
|
|
551
558
|
loginUrl({ state: e, acrValues: t = "", scope: n = "openid", redirectUri: r = this.redirectUri, loginHint: i = "", tag: a = "", teaser: o = "", maxAge: s = "", locale: c, oneStepLogin: l = !1, prompt: d = "select_account", xDomainId: p = "", xEnvironmentId: m = "", originCampaign: g = "" }) {
|
|
552
559
|
return u(!t || _(t, ["", "otp-email"], !0) || t.split(" ").every((e) => _(e, [
|
|
@@ -645,7 +652,7 @@ var I = (e) => typeof e.openSimplifiedLoginWidget == "function", L = "6.0.0-alph
|
|
|
645
652
|
function K(e) {
|
|
646
653
|
if (!p(e)) throw new t("Invalid hasAccess response");
|
|
647
654
|
let { entitled: n, ttl: r, allowedFeatures: i, userId: a, uuid: o, sig: s } = e;
|
|
648
|
-
if (typeof n != "boolean" || typeof r != "number" || !Array.isArray(i) || typeof a != "number"
|
|
655
|
+
if (typeof n != "boolean" || typeof r != "number" || !Array.isArray(i) || typeof a != "number" || !d(o) || !d(s)) throw new t("Invalid hasAccess response");
|
|
649
656
|
return {
|
|
650
657
|
entitled: n,
|
|
651
658
|
ttl: r,
|
|
@@ -700,11 +707,12 @@ var q = () => window, J = class {
|
|
|
700
707
|
}, Y = (e) => e || (typeof window > "u" ? void 0 : window), X = class {
|
|
701
708
|
#e;
|
|
702
709
|
#t;
|
|
710
|
+
#n;
|
|
703
711
|
constructor(e) {
|
|
704
712
|
let n = Y(e.window);
|
|
705
713
|
if (!n) throw new t("Schibsted Account SDK is not available in this browser context");
|
|
706
714
|
if (n.schAccount) throw new t("Schibsted Account SDK has already been initialized");
|
|
707
|
-
let { log: r, callbackBeforeRedirect: i,
|
|
715
|
+
let { log: r, callbackBeforeRedirect: i, defaultProductIds: a, varnish: o } = e, s = {
|
|
708
716
|
clientId: e.clientId,
|
|
709
717
|
redirectUri: e.redirectUri,
|
|
710
718
|
sessionDomain: e.sessionDomain,
|
|
@@ -712,14 +720,15 @@ var q = () => window, J = class {
|
|
|
712
720
|
window: n
|
|
713
721
|
};
|
|
714
722
|
if (this.#e = new G({
|
|
715
|
-
...
|
|
723
|
+
...s,
|
|
716
724
|
log: r,
|
|
717
725
|
callbackBeforeRedirect: i
|
|
718
|
-
}), a)
|
|
719
|
-
|
|
720
|
-
|
|
726
|
+
}), a !== void 0 && !Array.isArray(a)) throw new t("Account defaultProductIds config must be an array");
|
|
727
|
+
if (this.#n = a, o) {
|
|
728
|
+
if (typeof o != "object" || Array.isArray(o)) throw new t("Account varnish config must be an object");
|
|
729
|
+
this.#e.enableVarnishCookie(o);
|
|
721
730
|
}
|
|
722
|
-
this.#t = new J(
|
|
731
|
+
this.#t = new J(s), n.schAccount = this, n.dispatchEvent(new CustomEvent("schAccount:ready", { detail: { instance: this } }));
|
|
723
732
|
}
|
|
724
733
|
hasSession() {
|
|
725
734
|
return this.#e.hasSession();
|
|
@@ -736,6 +745,9 @@ var q = () => window, J = class {
|
|
|
736
745
|
getUserId() {
|
|
737
746
|
return this.#e.getUserId();
|
|
738
747
|
}
|
|
748
|
+
getExternalId(e, t = "") {
|
|
749
|
+
return this.#e.getExternalId(e, t);
|
|
750
|
+
}
|
|
739
751
|
getUserUuid() {
|
|
740
752
|
return this.#e.getUserUuid();
|
|
741
753
|
}
|
|
@@ -772,8 +784,11 @@ var q = () => window, J = class {
|
|
|
772
784
|
clearCachedUserSession() {
|
|
773
785
|
this.#e.clearCachedUserSession();
|
|
774
786
|
}
|
|
775
|
-
hasAccess(e
|
|
776
|
-
|
|
787
|
+
async hasAccess(e = this.#n) {
|
|
788
|
+
if (!e) throw new t("hasAccess requires productIds or defaultProductIds in the Account config");
|
|
789
|
+
if (e.length === 0) return null;
|
|
790
|
+
let n = await this.#e.getUserId();
|
|
791
|
+
return this.#t.hasAccess(e, n);
|
|
777
792
|
}
|
|
778
793
|
clearCachedAccessResult(e, t) {
|
|
779
794
|
this.#t.clearCachedAccessResult(e, t);
|
|
@@ -808,6 +823,6 @@ function se() {
|
|
|
808
823
|
}), $);
|
|
809
824
|
}
|
|
810
825
|
//#endregion
|
|
811
|
-
export { X as Account, t as SDKError, oe as createAccountSdk, se as getAccountSdk };
|
|
826
|
+
export { X as Account, t as SDKError, oe as createAccountSdk, se as getAccountSdk, A as isConnectedSessionResponse, N as isConnectedSessionWithUserIdResponse, j as isSessionFailureResponse, k as isSessionSuccessResponse };
|
|
812
827
|
|
|
813
828
|
//# sourceMappingURL=index.js.map
|