@schibsted/account-sdk-browser 6.0.0-alpha.1 → 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.
- package/README.md +8 -33
- package/dist/RESTClient.d.ts +91 -0
- package/dist/SDKError.d.ts +27 -0
- package/dist/cache.d.ts +65 -0
- package/dist/config.d.ts +86 -0
- package/dist/global-registry.d.ts +23 -0
- package/dist/globals.d.ts +13 -0
- package/dist/identity-s4nofYmB.js +370 -0
- package/dist/identity-s4nofYmB.js.map +1 -0
- package/dist/identity.d.ts +523 -0
- package/dist/identity.js +2 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +4 -0
- package/dist/monetization.d.ts +94 -0
- package/dist/monetization.js +72 -0
- package/dist/monetization.js.map +1 -0
- package/{src → dist}/object.d.ts +4 -9
- package/dist/popup.d.ts +9 -0
- package/{src → dist}/spidTalk.d.ts +4 -6
- package/dist/url.d.ts +8 -0
- package/dist/validate.d.ts +50 -0
- package/dist/version-spE-k97g.js +289 -0
- package/dist/version-spE-k97g.js.map +1 -0
- package/dist/version.d.ts +2 -0
- package/package.json +38 -22
- package/src/RESTClient.ts +226 -0
- package/src/SDKError.ts +59 -0
- package/src/{cache.js → cache.ts} +52 -37
- package/src/{config.js → config.ts} +7 -32
- package/src/global-registry.ts +39 -0
- package/src/globals.ts +10 -0
- package/src/{identity.js → identity.ts} +539 -437
- package/{index.js → src/index.ts} +1 -3
- package/src/{monetization.js → monetization.ts} +77 -48
- package/src/{object.js → object.ts} +8 -15
- package/src/popup.ts +74 -0
- package/src/{spidTalk.js → spidTalk.ts} +10 -12
- package/src/{url.js → url.ts} +6 -10
- package/src/{validate.js → validate.ts} +26 -42
- 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/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/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
|
@@ -0,0 +1,523 @@
|
|
|
1
|
+
import { TinyEmitter } from 'tiny-emitter';
|
|
2
|
+
import { default as RESTClient } from './RESTClient.js';
|
|
3
|
+
import { default as SDKError } from './SDKError.js';
|
|
4
|
+
/**
|
|
5
|
+
* Options accepted by {@link Identity#login} and related login URL helpers.
|
|
6
|
+
*/
|
|
7
|
+
export type LoginOptions = {
|
|
8
|
+
/**
|
|
9
|
+
* An opaque value used by the client to maintain state between the request and callback.
|
|
10
|
+
* It's also recommended to prevent CSRF {@link https://tools.ietf.org/html/rfc6749#section-10.12}
|
|
11
|
+
*/
|
|
12
|
+
state: string;
|
|
13
|
+
/**
|
|
14
|
+
* Authentication Context Class Reference Values. If omitted, the user will be asked to
|
|
15
|
+
* authenticate using username+password. For 2FA (Two-Factor Authentication) possible values
|
|
16
|
+
* are `sms`, `otp` (one time password), `password` (will force password confirmation, even if
|
|
17
|
+
* user is already logged in), `eid`. Those values might be mixed as space-separated string.
|
|
18
|
+
* To make sure that user has authenticated with 2FA you need to verify AMR (Authentication
|
|
19
|
+
* Methods References) claim in ID token. Might also be used to ensure additional acr
|
|
20
|
+
* (sms, otp, eid) for already logged in users. Supported value is also 'otp-email' means one
|
|
21
|
+
* time password using email.
|
|
22
|
+
*/
|
|
23
|
+
acrValues?: string;
|
|
24
|
+
/**
|
|
25
|
+
* The OAuth scopes for the tokens. This is a list of scopes, separated by space. If the list
|
|
26
|
+
* of scopes contains `openid`, the generated tokens includes the id token which can be useful
|
|
27
|
+
* for getting information about the user. Omitting scope is allowed, while `invalid_scope` is
|
|
28
|
+
* returned when the client asks for a scope you aren't allowed to request.
|
|
29
|
+
* {@link https://tools.ietf.org/html/rfc6749#section-3.3}
|
|
30
|
+
* Defaults to `openid`.
|
|
31
|
+
*/
|
|
32
|
+
scope?: string;
|
|
33
|
+
/**
|
|
34
|
+
* Redirect uri that will receive the code. Must exactly match a redirectUri from your client
|
|
35
|
+
* in self-service
|
|
36
|
+
*/
|
|
37
|
+
redirectUri?: string;
|
|
38
|
+
/** Should we try to open a popup window? Defaults to `false`. */
|
|
39
|
+
preferPopup?: boolean;
|
|
40
|
+
/** user email or UUID hint */
|
|
41
|
+
loginHint?: string;
|
|
42
|
+
/** Pulse tag */
|
|
43
|
+
tag?: string;
|
|
44
|
+
/** Teaser slug. Teaser with given slug will be displayed in place of default teaser */
|
|
45
|
+
teaser?: string;
|
|
46
|
+
/**
|
|
47
|
+
* Specifies the allowable elapsed time in seconds since the last time the End-User was actively
|
|
48
|
+
* authenticated. If last authentication time is more than maxAge seconds in the past,
|
|
49
|
+
* re-authentication will be required. See the OpenID Connect spec section 3.1.2.1 for more
|
|
50
|
+
* information
|
|
51
|
+
*/
|
|
52
|
+
maxAge?: number | string;
|
|
53
|
+
/**
|
|
54
|
+
* Optional parameter to overwrite client locale setting.
|
|
55
|
+
* New flows supports nb_NO, fi_FI, sv_SE, en_US
|
|
56
|
+
*/
|
|
57
|
+
locale?: string;
|
|
58
|
+
/** display username and password on one screen. Defaults to `false`. */
|
|
59
|
+
oneStepLogin?: boolean;
|
|
60
|
+
/**
|
|
61
|
+
* String that specifies whether the Authorization Server prompts the End-User for
|
|
62
|
+
* reauthentication or confirm account screen. Supported values: `select_account` or `login`.
|
|
63
|
+
* Defaults to `select_account`.
|
|
64
|
+
*/
|
|
65
|
+
prompt?: string;
|
|
66
|
+
/** Identifier for cross-domain tracking in Pulse */
|
|
67
|
+
xDomainId?: string;
|
|
68
|
+
/** Environment for cross-domain tracking in Pulse */
|
|
69
|
+
xEnvironmentId?: string;
|
|
70
|
+
/** Campaign identifier for tracking in Pulse */
|
|
71
|
+
originCampaign?: string;
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* Identical to {@link LoginOptions} except that `state` may also be a (possibly async) function;
|
|
75
|
+
* all other fields reuse the `LoginOptions` documentation.
|
|
76
|
+
*/
|
|
77
|
+
export type SimplifiedLoginWidgetLoginOptions = Omit<LoginOptions, 'state'> & {
|
|
78
|
+
/**
|
|
79
|
+
* An opaque value used by the client to maintain state between the request and callback.
|
|
80
|
+
* It's also recommended to prevent CSRF {@link https://tools.ietf.org/html/rfc6749#section-10.12}
|
|
81
|
+
*/
|
|
82
|
+
state: string | (() => string | Promise<string>);
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* Successful response returned from {@link Identity#hasSession}.
|
|
86
|
+
*/
|
|
87
|
+
export type HasSessionSuccessResponse = {
|
|
88
|
+
/**
|
|
89
|
+
* Is the user connected to the merchant? (it means that the merchant id is in the list of
|
|
90
|
+
* merchants listed of this user in the database)? Example: false
|
|
91
|
+
*/
|
|
92
|
+
result: boolean;
|
|
93
|
+
/** Example: 'notConnected' or 'connected'. Deprecated, use `Identity.isConnected()` */
|
|
94
|
+
userStatus: string;
|
|
95
|
+
/** Example: 'localhost' */
|
|
96
|
+
baseDomain: string;
|
|
97
|
+
/** Example: '58eca10fdbb9f6df72c3368f'. Obsolete */
|
|
98
|
+
id: string;
|
|
99
|
+
/** Example: 37162 */
|
|
100
|
+
userId: number;
|
|
101
|
+
/** Example: 'b3b23aa7-34f2-5d02-a10e-5a3455c6ab2c' */
|
|
102
|
+
uuid: string;
|
|
103
|
+
/** Example: 'eyJjbGllbnRfaWQ...' */
|
|
104
|
+
sp_id: string;
|
|
105
|
+
/** Example: 30 * 60 * 1000 (for 30 minutes) */
|
|
106
|
+
expiresIn: number;
|
|
107
|
+
/** Example: 1506285759 */
|
|
108
|
+
serverTime: number;
|
|
109
|
+
/**
|
|
110
|
+
* Example: 'NCdzXaz4ZRb7...' The sig parameter is a concatenation of an HMAC SHA-256 signature
|
|
111
|
+
* string, a dot (.) and a base64url encoded JSON object (session).
|
|
112
|
+
* {@link http://techdocs.spid.no/sdks/js/response-signature-and-validation/}
|
|
113
|
+
*/
|
|
114
|
+
sig: string;
|
|
115
|
+
/** (Only for connected users) Example: 'batman' */
|
|
116
|
+
displayName: string;
|
|
117
|
+
/** (Only for connected users) Example: 'Bruce' */
|
|
118
|
+
givenName: string;
|
|
119
|
+
/** (Only for connected users) Example: 'Wayne' */
|
|
120
|
+
familyName: string;
|
|
121
|
+
/** (Only for connected users) Example: 'male', 'female', 'undisclosed' */
|
|
122
|
+
gender: string;
|
|
123
|
+
/** (Only for connected users) Example: 'http://www.srv.com/some/picture.jpg' */
|
|
124
|
+
photo: string;
|
|
125
|
+
/** (Only for connected users) */
|
|
126
|
+
tracking: boolean;
|
|
127
|
+
/** (Only for connected users) */
|
|
128
|
+
clientAgreementAccepted: boolean;
|
|
129
|
+
/** (Only for connected users) */
|
|
130
|
+
defaultAgreementAccepted: boolean;
|
|
131
|
+
pairId: string;
|
|
132
|
+
sdrn: string;
|
|
133
|
+
};
|
|
134
|
+
/**
|
|
135
|
+
* Failure response returned from {@link Identity#hasSession}.
|
|
136
|
+
*/
|
|
137
|
+
export type HasSessionFailureResponse = {
|
|
138
|
+
error: {
|
|
139
|
+
/** Typically an HTTP response code. Example: 401 */
|
|
140
|
+
code: number;
|
|
141
|
+
/** Example: "No session found!" */
|
|
142
|
+
description: string;
|
|
143
|
+
/** Example: "UserException" */
|
|
144
|
+
type: string;
|
|
145
|
+
};
|
|
146
|
+
response: {
|
|
147
|
+
/** Example: "localhost" */
|
|
148
|
+
baseDomain: string;
|
|
149
|
+
/** Time span in milliseconds. Example: 30 * 60 * 1000 (for 30 minutes) */
|
|
150
|
+
expiresIn: number;
|
|
151
|
+
result: boolean;
|
|
152
|
+
/** Server time in seconds since the Unix Epoch. Example: 1506287788 */
|
|
153
|
+
serverTime: number;
|
|
154
|
+
};
|
|
155
|
+
};
|
|
156
|
+
/**
|
|
157
|
+
* Minimal user information used by the simplified login widget flow.
|
|
158
|
+
*/
|
|
159
|
+
export type SimplifiedLoginData = {
|
|
160
|
+
/** Deprecated: User UUID, to be be used as `loginHint` for {@link Identity#login} */
|
|
161
|
+
identifier: string;
|
|
162
|
+
/** Human-readable user identifier */
|
|
163
|
+
display_text: string;
|
|
164
|
+
/** Client name */
|
|
165
|
+
client_name: string;
|
|
166
|
+
};
|
|
167
|
+
/**
|
|
168
|
+
* Configuration options for {@link Identity#showSimplifiedLoginWidget}.
|
|
169
|
+
*/
|
|
170
|
+
export type SimplifiedLoginWidgetOptions = {
|
|
171
|
+
/** expected encoding of simplified login widget. Could be utf-8 (default), iso-8859-1 or iso-8859-15 */
|
|
172
|
+
encoding: string;
|
|
173
|
+
/**
|
|
174
|
+
* expected locale of simplified login widget. Should be provided in a short format like 'nb',
|
|
175
|
+
* 'sv'. If not set, a value from the env variable is used.
|
|
176
|
+
*/
|
|
177
|
+
locale?: 'nb' | 'sv' | 'fi' | 'da' | 'en';
|
|
178
|
+
};
|
|
179
|
+
/**
|
|
180
|
+
* Provides Identity functionalty to a web page
|
|
181
|
+
*/
|
|
182
|
+
export declare class Identity extends TinyEmitter {
|
|
183
|
+
_sessionInitiatedSent: boolean;
|
|
184
|
+
window: any;
|
|
185
|
+
clientId: string;
|
|
186
|
+
sessionStorageCache: any;
|
|
187
|
+
localStorageCache: any;
|
|
188
|
+
redirectUri: string;
|
|
189
|
+
env: string;
|
|
190
|
+
log?: Function;
|
|
191
|
+
callbackBeforeRedirect: Function;
|
|
192
|
+
_sessionDomain: string;
|
|
193
|
+
_enableSessionCaching: boolean;
|
|
194
|
+
_session: any;
|
|
195
|
+
_spid: RESTClient;
|
|
196
|
+
_oauthService: RESTClient;
|
|
197
|
+
_bffService: RESTClient;
|
|
198
|
+
_sessionService: RESTClient;
|
|
199
|
+
_globalSessionService: RESTClient;
|
|
200
|
+
_usedSessionServiceGetSessionEndpoint: any;
|
|
201
|
+
_hasSessionInProgress?: boolean | Promise<any>;
|
|
202
|
+
popup?: Window | null;
|
|
203
|
+
setVarnishCookie?: boolean;
|
|
204
|
+
varnishExpiresIn?: number;
|
|
205
|
+
varnishCookieDomain?: string;
|
|
206
|
+
/**
|
|
207
|
+
* @param options
|
|
208
|
+
* @param options.clientId - Example: "1234567890abcdef12345678"
|
|
209
|
+
* @param options.sessionDomain - Example: "https://id.site.com"
|
|
210
|
+
* @param options.redirectUri - Example: "https://site.com"
|
|
211
|
+
* @param options.env - Schibsted account environment: `PRE` (default), `PRO`, `PRO_NO`, `PRO_FI` or `PRO_DK`
|
|
212
|
+
* @param options.log - A function that receives debug log information. If not set,
|
|
213
|
+
* no logging will be done
|
|
214
|
+
* @param options.window - window object
|
|
215
|
+
* @param options.callbackBeforeRedirect - callback triggered before session refresh redirect happen
|
|
216
|
+
* @throws {SDKError} - If any of options are invalid
|
|
217
|
+
*/
|
|
218
|
+
constructor({ clientId, redirectUri, sessionDomain, env, log, window, callbackBeforeRedirect, }: {
|
|
219
|
+
clientId: string;
|
|
220
|
+
sessionDomain: string;
|
|
221
|
+
redirectUri: string;
|
|
222
|
+
env?: string;
|
|
223
|
+
log?: Function;
|
|
224
|
+
window?: Window;
|
|
225
|
+
callbackBeforeRedirect?: Function;
|
|
226
|
+
});
|
|
227
|
+
/**
|
|
228
|
+
* Read tabId from session storage
|
|
229
|
+
* @private
|
|
230
|
+
*/
|
|
231
|
+
_getTabId(): number | undefined;
|
|
232
|
+
/**
|
|
233
|
+
* Checks if getting session is blocked
|
|
234
|
+
* @private
|
|
235
|
+
*
|
|
236
|
+
*/
|
|
237
|
+
_isSessionCallBlocked(): boolean | void;
|
|
238
|
+
/**
|
|
239
|
+
* Block calls to get session
|
|
240
|
+
* @private
|
|
241
|
+
*
|
|
242
|
+
*/
|
|
243
|
+
_blockSessionCall(): void;
|
|
244
|
+
/**
|
|
245
|
+
* Unblocks calls to get session
|
|
246
|
+
* @private
|
|
247
|
+
*
|
|
248
|
+
*/
|
|
249
|
+
_unblockSessionCall(): void;
|
|
250
|
+
/**
|
|
251
|
+
* Set SPiD server URL
|
|
252
|
+
* @private
|
|
253
|
+
* @param url - real URL or 'PRE' style key
|
|
254
|
+
*/
|
|
255
|
+
_setSpidServerUrl(url: string): void;
|
|
256
|
+
/**
|
|
257
|
+
* Set OAuth server URL
|
|
258
|
+
* @private
|
|
259
|
+
* @param url - real URL or 'PRE' style key
|
|
260
|
+
*/
|
|
261
|
+
_setOauthServerUrl(url: string): void;
|
|
262
|
+
/**
|
|
263
|
+
* Set BFF server URL
|
|
264
|
+
* @private
|
|
265
|
+
* @param url - real URL or 'PRE' style key
|
|
266
|
+
*/
|
|
267
|
+
_setBffServerUrl(url: string): void;
|
|
268
|
+
/**
|
|
269
|
+
* Set site-specific session-service domain
|
|
270
|
+
* @private
|
|
271
|
+
* @param domain - real URL — (**not** 'PRE' style env key)
|
|
272
|
+
*/
|
|
273
|
+
_setSessionServiceUrl(domain: string): void;
|
|
274
|
+
/**
|
|
275
|
+
* Set global session-service server URL
|
|
276
|
+
* @private
|
|
277
|
+
* @param url - real URL or 'PRE' style key
|
|
278
|
+
*/
|
|
279
|
+
_setGlobalSessionServiceUrl(url: string): void;
|
|
280
|
+
/**
|
|
281
|
+
* Emits the relevant events based on the previous and new reply from hassession
|
|
282
|
+
* @private
|
|
283
|
+
* @param previous
|
|
284
|
+
* @param current
|
|
285
|
+
*/
|
|
286
|
+
_emitSessionEvent(previous: any, current: any): void;
|
|
287
|
+
/**
|
|
288
|
+
* Close this.popup if it exists and is open
|
|
289
|
+
* @private
|
|
290
|
+
*/
|
|
291
|
+
_closePopup(): void;
|
|
292
|
+
/**
|
|
293
|
+
* Set the Varnish cookie (`SP_ID`) when hasSession() is called. Note that most browsers require
|
|
294
|
+
* that you are on a "real domain" for this to work — so, **not** `localhost`
|
|
295
|
+
* @param options
|
|
296
|
+
* @param options.expiresIn Override this to set number of seconds before the varnish
|
|
297
|
+
* cookie expires. The default is to use the same time that hasSession responses are cached for
|
|
298
|
+
* @param options.domain Override cookie domain. E.g. «vg.no» instead of «www.vg.no»
|
|
299
|
+
*/
|
|
300
|
+
enableVarnishCookie(options?: {
|
|
301
|
+
expiresIn?: number;
|
|
302
|
+
domain?: string;
|
|
303
|
+
}): void;
|
|
304
|
+
/**
|
|
305
|
+
* Set the Varnish cookie if configured
|
|
306
|
+
* @private
|
|
307
|
+
* @param sessionData
|
|
308
|
+
*/
|
|
309
|
+
_maybeSetVarnishCookie(sessionData: HasSessionSuccessResponse): void;
|
|
310
|
+
/**
|
|
311
|
+
* Clear the Varnish cookie if configured
|
|
312
|
+
* @private
|
|
313
|
+
*/
|
|
314
|
+
_maybeClearVarnishCookie(): void;
|
|
315
|
+
/**
|
|
316
|
+
* Clear the Varnish cookie
|
|
317
|
+
* @private
|
|
318
|
+
*/
|
|
319
|
+
_clearVarnishCookie(): void;
|
|
320
|
+
/**
|
|
321
|
+
* Log used settings and version
|
|
322
|
+
* @throws {SDKError} - If log method is not provided
|
|
323
|
+
*/
|
|
324
|
+
logSettings(): void;
|
|
325
|
+
/**
|
|
326
|
+
* @summary Queries the hassession endpoint and returns information about the status of the user
|
|
327
|
+
* @remarks When we send a request to this endpoint, cookies sent along with the request
|
|
328
|
+
* determines the status of the user.
|
|
329
|
+
* @throws {SDKError} - If the call to the hasSession service fails in any way (this will happen
|
|
330
|
+
* if, say, the user is not logged in)
|
|
331
|
+
* @fires Identity#login
|
|
332
|
+
* @fires Identity#logout
|
|
333
|
+
* @fires Identity#userChange
|
|
334
|
+
* @fires Identity#sessionChange
|
|
335
|
+
* @fires Identity#notLoggedin
|
|
336
|
+
* @fires Identity#sessionInit
|
|
337
|
+
* @fires Identity#statusChange
|
|
338
|
+
* @fires Identity#error
|
|
339
|
+
*/
|
|
340
|
+
hasSession(): Promise<HasSessionSuccessResponse | HasSessionFailureResponse>;
|
|
341
|
+
/**
|
|
342
|
+
* @summary Allows the client app to check if the user is logged in to Schibsted account
|
|
343
|
+
* @remarks This function calls {@link Identity#hasSession} internally and thus has the side
|
|
344
|
+
* effect that it might perform an auto-login on the user
|
|
345
|
+
*/
|
|
346
|
+
isLoggedIn(): Promise<boolean>;
|
|
347
|
+
/**
|
|
348
|
+
* Removes the cached user session.
|
|
349
|
+
*/
|
|
350
|
+
clearCachedUserSession(): void;
|
|
351
|
+
/**
|
|
352
|
+
* @summary Allows the caller to check if the current user is connected to the client_id in
|
|
353
|
+
* Schibsted account. Being connected means that the user has agreed for their account to be
|
|
354
|
+
* used by your web app and have accepted the required terms
|
|
355
|
+
* @remarks This function calls {@link Identity#hasSession} internally and thus has the side
|
|
356
|
+
* effect that it might perform an auto-login on the user
|
|
357
|
+
* @summary Check if the user is connected to the client_id
|
|
358
|
+
*/
|
|
359
|
+
isConnected(): Promise<boolean>;
|
|
360
|
+
/**
|
|
361
|
+
* @summary Returns information about the user
|
|
362
|
+
* @remarks This function calls {@link Identity#hasSession} internally and thus has the side
|
|
363
|
+
* effect that it might perform an auto-login on the user
|
|
364
|
+
* @throws {SDKError} If the user isn't connected to the merchant
|
|
365
|
+
* @throws {SDKError} If we couldn't get the user
|
|
366
|
+
*/
|
|
367
|
+
getUser(): Promise<HasSessionSuccessResponse>;
|
|
368
|
+
/**
|
|
369
|
+
* @summary
|
|
370
|
+
* In Schibsted account, there are multiple ways of identifying a user; the `userId`,
|
|
371
|
+
* `uuid` and `externalId` used for identifying a user-merchant pair (see {@link Identity#getExternalId}).
|
|
372
|
+
* There are reasons for them all to exist. The `userId` is a numeric identifier, but
|
|
373
|
+
* since Schibsted account is deployed separately in Norway and Sweden, there are a lot of
|
|
374
|
+
* duplicates. The `userId` was introduced early, so many sites still need to use them for
|
|
375
|
+
* legacy reasons. The `uuid` is universally unique, and so — if we could disregard a lot of
|
|
376
|
+
* Schibsted components depending on the numeric `userId` — it would be a good identifier to use
|
|
377
|
+
* @remarks This function calls {@link Identity#hasSession} internally and thus has the side
|
|
378
|
+
* effect that it might perform an auto-login on the user
|
|
379
|
+
* @throws {SDKError} If the user isn't connected to the merchant
|
|
380
|
+
* @return The `userId` field (not to be confused with the `uuid`)
|
|
381
|
+
*/
|
|
382
|
+
getUserId(): Promise<string>;
|
|
383
|
+
/**
|
|
384
|
+
* @function
|
|
385
|
+
* @summary
|
|
386
|
+
* Retrieves the external identifier (`externalId`) for the authenticated user.
|
|
387
|
+
*
|
|
388
|
+
* In Schibsted Account there are multiple ways of identifying users, however for integrations with
|
|
389
|
+
* third-parties it's recommended to use `externalId` as it does not disclose
|
|
390
|
+
* any critical data whilst allowing for user identification.
|
|
391
|
+
*
|
|
392
|
+
* `externalId` is merchant-scoped using a pairwise identifier (`pairId`),
|
|
393
|
+
* meaning the same user's ID will differ between merchants.
|
|
394
|
+
* Additionally, this identifier is bound to the external party provided as argument.
|
|
395
|
+
*
|
|
396
|
+
* @param externalParty
|
|
397
|
+
* @param optionalSuffix
|
|
398
|
+
* @remarks This function calls {@link Identity#hasSession} internally and thus has the side
|
|
399
|
+
* effect that it might perform an auto-login on the user
|
|
400
|
+
* @throws {SDKError} If the `pairId` is missing in user session.
|
|
401
|
+
* @throws {SDKError} If the `externalParty` is not defined
|
|
402
|
+
* @return The merchant- and 3rd-party-specific `externalId`
|
|
403
|
+
*/
|
|
404
|
+
getExternalId(externalParty: string, optionalSuffix?: string): Promise<string>;
|
|
405
|
+
/**
|
|
406
|
+
* @summary Enables brands to programmatically get the current the SDRN based on the user's session.
|
|
407
|
+
* @remarks This function calls {@link Identity#hasSession} internally and thus has the side
|
|
408
|
+
* effect that it might perform an auto-login on the user
|
|
409
|
+
* @throws {SDKError} If the SDRN is missing in user session object.
|
|
410
|
+
*/
|
|
411
|
+
getUserSDRN(): Promise<string>;
|
|
412
|
+
/**
|
|
413
|
+
* @summary In Schibsted account, there are two ways of identifying a user; the `userId` and the
|
|
414
|
+
* `uuid`. There are reasons for them both existing. The `userId` is a numeric identifier, but
|
|
415
|
+
* since Schibsted account is deployed separately in Norway and Sweden, there are a lot of
|
|
416
|
+
* duplicates. The `userId` was introduced early, so many sites still need to use them for
|
|
417
|
+
* legacy reasons. The `uuid` is universally unique, and so — if we could disregard a lot of
|
|
418
|
+
* Schibsted components depending on the numeric `userId` — it would be a good identifier to use
|
|
419
|
+
* @remarks This function calls {@link Identity#hasSession} internally and thus has the side
|
|
420
|
+
* effect that it might perform an auto-login on the user
|
|
421
|
+
* @throws {SDKError} If the user isn't connected to the merchant
|
|
422
|
+
* @return The `uuid` field (not to be confused with the `userId`)
|
|
423
|
+
*/
|
|
424
|
+
getUserUuid(): Promise<string>;
|
|
425
|
+
/**
|
|
426
|
+
* @summary Get basic information about any user currently logged-in to their Schibsted account
|
|
427
|
+
* in this browser. Can be used to provide context in a continue-as prompt.
|
|
428
|
+
* @remarks This function relies on the global Schibsted account user session cookie, which
|
|
429
|
+
* is a third-party cookie and hence might be blocked by the browser (for example due to ITP in
|
|
430
|
+
* Safari). So there's no guarantee any data is returned, even though a user is logged-in in
|
|
431
|
+
* the current browser.
|
|
432
|
+
*/
|
|
433
|
+
getUserContextData(): Promise<SimplifiedLoginData | null>;
|
|
434
|
+
/**
|
|
435
|
+
* If a popup is desired, this function needs to be called in response to a user event (like
|
|
436
|
+
* click or tap) in order to work correctly. Otherwise the popup will be blocked by the
|
|
437
|
+
* browser's popup blockers and has to be explicitly authorized to be shown.
|
|
438
|
+
* @summary Perform a login, either using a full-page redirect or a popup
|
|
439
|
+
* @see https://tools.ietf.org/html/rfc6749#section-4.1.1
|
|
440
|
+
*
|
|
441
|
+
* @param options
|
|
442
|
+
* @param options.state
|
|
443
|
+
* @param options.acrValues
|
|
444
|
+
* @param options.scope
|
|
445
|
+
* @param options.redirectUri
|
|
446
|
+
* @param options.preferPopup
|
|
447
|
+
* @param options.loginHint
|
|
448
|
+
* @param options.tag
|
|
449
|
+
* @param options.teaser
|
|
450
|
+
* @param options.maxAge
|
|
451
|
+
* @param options.locale
|
|
452
|
+
* @param options.oneStepLogin
|
|
453
|
+
* @param options.prompt
|
|
454
|
+
* @param options.xDomainId
|
|
455
|
+
* @param options.xEnvironmentId
|
|
456
|
+
* @param options.originCampaign
|
|
457
|
+
* @return - Reference to popup window if created (or `null` otherwise)
|
|
458
|
+
*/
|
|
459
|
+
login({ state, acrValues, scope, redirectUri, preferPopup, loginHint, tag, teaser, maxAge, locale, oneStepLogin, prompt, xDomainId, xEnvironmentId, originCampaign, }: LoginOptions): Window | null;
|
|
460
|
+
/**
|
|
461
|
+
* @summary Retrieve the sp_id (Varnish ID)
|
|
462
|
+
* @remarks This function calls {@link Identity#hasSession} internally and thus has the side
|
|
463
|
+
* effect that it might perform an auto-login on the user
|
|
464
|
+
* @return - The sp_id string or null (if the server didn't return it)
|
|
465
|
+
*/
|
|
466
|
+
getSpId(): Promise<string | null>;
|
|
467
|
+
/**
|
|
468
|
+
* @summary Logs the user out from the Identity platform
|
|
469
|
+
* @param redirectUri - Where to redirect the browser after logging out of Schibsted
|
|
470
|
+
* account
|
|
471
|
+
*/
|
|
472
|
+
logout(redirectUri?: string): void;
|
|
473
|
+
/**
|
|
474
|
+
* Generates the link to the new login page that'll be used in the popup or redirect flow
|
|
475
|
+
* @param options
|
|
476
|
+
* @param options.state
|
|
477
|
+
* @param options.acrValues
|
|
478
|
+
* @param options.scope
|
|
479
|
+
* @param options.redirectUri
|
|
480
|
+
* @param options.loginHint
|
|
481
|
+
* @param options.tag
|
|
482
|
+
* @param options.teaser
|
|
483
|
+
* @param options.maxAge
|
|
484
|
+
* @param options.locale
|
|
485
|
+
* @param options.oneStepLogin
|
|
486
|
+
* @param options.prompt
|
|
487
|
+
* @param options.xDomainId
|
|
488
|
+
* @param options.xEnvironmentId
|
|
489
|
+
* @param options.originCampaign
|
|
490
|
+
* @return - The url
|
|
491
|
+
*/
|
|
492
|
+
loginUrl({ state, acrValues, scope, redirectUri, loginHint, tag, teaser, maxAge, locale, oneStepLogin, prompt, xDomainId, xEnvironmentId, originCampaign, }: LoginOptions, ..._args: any[]): string;
|
|
493
|
+
/**
|
|
494
|
+
* The url for logging the user out
|
|
495
|
+
* @param redirectUri
|
|
496
|
+
* @return url
|
|
497
|
+
*/
|
|
498
|
+
logoutUrl(redirectUri?: string): string;
|
|
499
|
+
/**
|
|
500
|
+
* The account summary page url
|
|
501
|
+
* @param redirectUri
|
|
502
|
+
*/
|
|
503
|
+
accountUrl(redirectUri?: string): string;
|
|
504
|
+
/**
|
|
505
|
+
* The phone editing page url
|
|
506
|
+
* @param redirectUri
|
|
507
|
+
*/
|
|
508
|
+
phonesUrl(redirectUri?: string): string;
|
|
509
|
+
/**
|
|
510
|
+
* Function responsible for loading and displaying simplified login widget. How often
|
|
511
|
+
* widget will be display is up to you. Preferred way would be to show it once per user,
|
|
512
|
+
* and store that info in localStorage. Widget will be display only if user is logged in to SSO.
|
|
513
|
+
*
|
|
514
|
+
* @param loginParams - the same as `options` param for login function. Login will be called on user
|
|
515
|
+
* continue action. `state` might be string or async function.
|
|
516
|
+
* @param options - additional configuration of Simplified Login Widget
|
|
517
|
+
* @fires Identity#simplifiedLoginOpened
|
|
518
|
+
* @fires Identity#simplifiedLoginCancelled
|
|
519
|
+
* @return - will resolve to true if widget will be display. Otherwise, will throw SDKError
|
|
520
|
+
*/
|
|
521
|
+
showSimplifiedLoginWidget(loginParams: SimplifiedLoginWidgetLoginOptions, options?: SimplifiedLoginWidgetOptions): Promise<boolean | SDKError>;
|
|
522
|
+
}
|
|
523
|
+
export default Identity;
|
package/dist/identity.js
ADDED
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { TinyEmitter } from 'tiny-emitter';
|
|
2
|
+
import { default as Cache } from './cache.js';
|
|
3
|
+
import { default as RESTClient } from './RESTClient.js';
|
|
4
|
+
/**
|
|
5
|
+
* Result returned by the Session Service `/hasAccess` endpoint, describing whether the user
|
|
6
|
+
* is entitled to a requested set of products/features.
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
export interface HasAccessResult {
|
|
10
|
+
/** Whether the user is entitled to at least one of the requested products/features. */
|
|
11
|
+
entitled: boolean;
|
|
12
|
+
/** How long this result stays valid, in seconds, before the cache entry expires. */
|
|
13
|
+
ttl: number;
|
|
14
|
+
allowedFeatures: string[];
|
|
15
|
+
userId: number;
|
|
16
|
+
uuid: string;
|
|
17
|
+
sig: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Provides features related to monetization
|
|
21
|
+
*/
|
|
22
|
+
export declare class Monetization extends TinyEmitter {
|
|
23
|
+
cache: Cache;
|
|
24
|
+
clientId: string;
|
|
25
|
+
env: string;
|
|
26
|
+
redirectUri: string;
|
|
27
|
+
_spid: RESTClient;
|
|
28
|
+
_sessionService?: RESTClient;
|
|
29
|
+
private pendingHasAccessRequests;
|
|
30
|
+
/**
|
|
31
|
+
* @param options - Monetization configuration
|
|
32
|
+
* @throws {SDKError} - If any of options are invalid
|
|
33
|
+
*/
|
|
34
|
+
constructor({ clientId, redirectUri, env, sessionDomain, window, }: {
|
|
35
|
+
/** Mandatory client id */
|
|
36
|
+
clientId: string;
|
|
37
|
+
/** Redirect uri */
|
|
38
|
+
redirectUri: string;
|
|
39
|
+
/** Example: `"https://id.site.com"` */
|
|
40
|
+
sessionDomain: string;
|
|
41
|
+
/** Schibsted account environment: `PRE` (default), `PRO`, `PRO_NO` */
|
|
42
|
+
env?: string;
|
|
43
|
+
/** Window object to use (defaults to the global `window`). */
|
|
44
|
+
window?: Window;
|
|
45
|
+
});
|
|
46
|
+
/**
|
|
47
|
+
* Set SPiD server URL
|
|
48
|
+
* @private
|
|
49
|
+
* @param url
|
|
50
|
+
*/
|
|
51
|
+
private _setSpidServerUrl;
|
|
52
|
+
/**
|
|
53
|
+
* Set session-service domain
|
|
54
|
+
* @private
|
|
55
|
+
* @param domain - real URL — (**not** 'PRE' style env key)
|
|
56
|
+
*/
|
|
57
|
+
private _setSessionServiceUrl;
|
|
58
|
+
/**
|
|
59
|
+
* Checks if the user has access to a set of products or features.
|
|
60
|
+
* @param productIds - which products/features to check
|
|
61
|
+
* @param userId - id of currently logged in user
|
|
62
|
+
* @throws {SDKError} - If the input is incorrect, or a network call fails in any way
|
|
63
|
+
* (this will happen if, say, the user is not logged in)
|
|
64
|
+
* @returns The data object returned from Schibsted account (or `null` if the user
|
|
65
|
+
* doesn't have access to any of the given products/features)
|
|
66
|
+
*/
|
|
67
|
+
hasAccess(productIds: string[], userId: number): Promise<HasAccessResult | null>;
|
|
68
|
+
/**
|
|
69
|
+
* Removes the cached access result.
|
|
70
|
+
* @param productIds - which products/features to check
|
|
71
|
+
* @param userId - id of currently logged in user
|
|
72
|
+
*/
|
|
73
|
+
clearCachedAccessResult(productIds: string[], userId: number): void;
|
|
74
|
+
/**
|
|
75
|
+
* Compute "has access" cache key for the given product ids and user id.
|
|
76
|
+
* @private
|
|
77
|
+
* @param productIds - which products/features to check
|
|
78
|
+
* @param userId - id of currently logged in user
|
|
79
|
+
*/
|
|
80
|
+
private _accessCacheKey;
|
|
81
|
+
/**
|
|
82
|
+
* Get the url for the end user to review the subscriptions
|
|
83
|
+
* @param redirectUri
|
|
84
|
+
* @returns - The url to the subscriptions review page
|
|
85
|
+
*/
|
|
86
|
+
subscriptionsUrl(redirectUri?: string): string;
|
|
87
|
+
/**
|
|
88
|
+
* Get the url for the end user to review the products
|
|
89
|
+
* @param redirectUri
|
|
90
|
+
* @returns - The url to the products review page
|
|
91
|
+
*/
|
|
92
|
+
productsUrl(redirectUri?: string): string;
|
|
93
|
+
}
|
|
94
|
+
export default Monetization;
|