@schibsted/account-sdk-browser 4.3.0 → 4.5.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/identity.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from "./src/identity.js";
package/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from "./identity.js";
2
2
  export * from "./monetization.js";
3
3
  export * from "./payment.js";
4
+ export { default as SDKError } from "./src/SDKError.js";
@@ -0,0 +1 @@
1
+ export * from "./src/monetization.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@schibsted/account-sdk-browser",
3
- "version": "4.3.0",
3
+ "version": "4.5.3",
4
4
  "description": "Schibsted account SDK for browsers",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/payment.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from "./src/payment.js";
package/src/config.d.ts CHANGED
@@ -12,17 +12,23 @@ export const NAMESPACE: any;
12
12
  * @prop {string} ENDPOINTS.SPiD.PRE - Staging environment
13
13
  * @prop {string} ENDPOINTS.SPiD.PRO - Production environment Sweden
14
14
  * @prop {string} ENDPOINTS.SPiD.PRO_NO - Production environment Norway
15
+ * @prop {string} ENDPOINTS.SPiD.PRO_FI - Production environment Finland
16
+ * @prop {string} ENDPOINTS.SPiD.PRO_DK - Production environment Denmark
15
17
  * @prop {object} ENDPOINTS.BFF - Endpoints used with new GDPR-compliant web flows
16
18
  * @prop {string} ENDPOINTS.BFF.LOCAL - Local endpoint (for Identity team)
17
19
  * @prop {string} ENDPOINTS.BFF.DEV - Dev environment (for Identity team)
18
20
  * @prop {string} ENDPOINTS.BFF.PRE - Staging environment
19
21
  * @prop {string} ENDPOINTS.BFF.PRO - Production environment Sweden
20
22
  * @prop {string} ENDPOINTS.BFF.PRO_NO - Production environment Norway
23
+ * @prop {string} ENDPOINTS.BFF.PRO_FI - Production environment Finland
24
+ * @prop {string} ENDPOINTS.BFF.PRO_DK - Production environment Denmark
21
25
  * @prop {object} ENDPOINTS.SESSION_SERVICE - Endpoints to check global user session data
22
26
  * @prop {string} ENDPOINTS.SESSION_SERVICE.LOCAL - Local endpoint (for Identity team)
23
27
  * @prop {string} ENDPOINTS.SESSION_SERVICE.DEV - Dev environment (for Identity team)
24
28
  * @prop {string} ENDPOINTS.SESSION_SERVICE.PRE - Staging environment
25
29
  * @prop {string} ENDPOINTS.SESSION_SERVICE.PRO - Production environment Sweden
26
30
  * @prop {string} ENDPOINTS.SESSION_SERVICE.PRO_NO - Production environment Norway
31
+ * @prop {string} ENDPOINTS.SESSION_SERVICE.PRO_FI - Production environment Finland
32
+ * @prop {string} ENDPOINTS.SESSION_SERVICE.PRO_DK - Production environment Denmark
27
33
  */
28
34
  declare const config: Object;
package/src/config.js CHANGED
@@ -29,6 +29,7 @@
29
29
  * @prop {string} ENDPOINTS.SPiD.PRO - Production environment Sweden
30
30
  * @prop {string} ENDPOINTS.SPiD.PRO_NO - Production environment Norway
31
31
  * @prop {string} ENDPOINTS.SPiD.PRO_FI - Production environment Finland
32
+ * @prop {string} ENDPOINTS.SPiD.PRO_DK - Production environment Denmark
32
33
  * @prop {object} ENDPOINTS.BFF - Endpoints used with new GDPR-compliant web flows
33
34
  * @prop {string} ENDPOINTS.BFF.LOCAL - Local endpoint (for Identity team)
34
35
  * @prop {string} ENDPOINTS.BFF.DEV - Dev environment (for Identity team)
@@ -36,6 +37,7 @@
36
37
  * @prop {string} ENDPOINTS.BFF.PRO - Production environment Sweden
37
38
  * @prop {string} ENDPOINTS.BFF.PRO_NO - Production environment Norway
38
39
  * @prop {string} ENDPOINTS.BFF.PRO_FI - Production environment Finland
40
+ * @prop {string} ENDPOINTS.BFF.PRO_DK - Production environment Denmark
39
41
  * @prop {object} ENDPOINTS.SESSION_SERVICE - Endpoints to check global user session data
40
42
  * @prop {string} ENDPOINTS.SESSION_SERVICE.LOCAL - Local endpoint (for Identity team)
41
43
  * @prop {string} ENDPOINTS.SESSION_SERVICE.DEV - Dev environment (for Identity team)
@@ -43,6 +45,7 @@
43
45
  * @prop {string} ENDPOINTS.SESSION_SERVICE.PRO - Production environment Sweden
44
46
  * @prop {string} ENDPOINTS.SESSION_SERVICE.PRO_NO - Production environment Norway
45
47
  * @prop {string} ENDPOINTS.SESSION_SERVICE.PRO_FI - Production environment Finland
48
+ * @prop {string} ENDPOINTS.SESSION_SERVICE.PRO_DK - Production environment Denmark
46
49
  */
47
50
  const config = {
48
51
  ENDPOINTS: {
@@ -53,6 +56,7 @@ const config = {
53
56
  PRO: 'https://login.schibsted.com',
54
57
  PRO_NO: 'https://payment.schibsted.no',
55
58
  PRO_FI: 'https://login.schibsted.fi',
59
+ PRO_DK: 'https://login.schibsted.dk',
56
60
  },
57
61
  BFF: {
58
62
  LOCAL: 'http://id.localhost/authn/',
@@ -61,6 +65,7 @@ const config = {
61
65
  PRO: 'https://login.schibsted.com/authn/',
62
66
  PRO_NO: 'https://payment.schibsted.no/authn/',
63
67
  PRO_FI: 'https://login.schibsted.fi/authn/',
68
+ PRO_DK: 'https://login.schibsted.dk/authn/',
64
69
  },
65
70
  SESSION_SERVICE: {
66
71
  LOCAL: 'http://session-service.id.localhost',
@@ -69,6 +74,7 @@ const config = {
69
74
  PRO: 'https://session-service.login.schibsted.com',
70
75
  PRO_NO: 'https://session-service.payment.schibsted.no',
71
76
  PRO_FI: 'https://session-service.login.schibsted.fi',
77
+ PRO_DK: 'https://session-service.login.schibsted.dk',
72
78
  },
73
79
  },
74
80
  NAMESPACE: {
@@ -78,6 +84,7 @@ const config = {
78
84
  PRO: 'schibsted.com',
79
85
  PRO_NO: 'spid.no',
80
86
  PRO_FI: 'schibsted.fi',
87
+ PRO_DK: 'schibsted.dk',
81
88
  }
82
89
  };
83
90
 
package/src/identity.d.ts CHANGED
@@ -7,7 +7,7 @@ export class Identity {
7
7
  * @param {string} options.clientId - Example: "1234567890abcdef12345678"
8
8
  * @param {string} options.sessionDomain - Example: "https://id.site.com"
9
9
  * @param {string} options.redirectUri - Example: "https://site.com"
10
- * @param {string} [options.env=PRE] - Schibsted account environment: `PRE`, `PRO` or `PRO_NO`
10
+ * @param {string} [options.env=PRE] - Schibsted account environment: `PRE`, `PRO`, `PRO_NO`, `PRO_FI` or `PRO_DK`
11
11
  * @param {function} [options.log] - A function that receives debug log information. If not set,
12
12
  * no logging will be done
13
13
  * @param {object} [options.window] - window object
@@ -92,16 +92,16 @@ export class Identity {
92
92
  * @param {object} [options]
93
93
  * @param {number} [options.expiresIn] Override this to set number of seconds before the varnish
94
94
  * cookie expires. The default is to use the same time that hasSession responses are cached for
95
- * @param {boolean} [options.domain] Override cookie domain. E.g. «vg.no» instead of «www.vg.no»
95
+ * @param {string} [options.domain] Override cookie domain. E.g. «vg.no» instead of «www.vg.no»
96
96
  * @returns {void}
97
97
  */
98
98
  enableVarnishCookie(options?: {
99
99
  expiresIn?: number;
100
- domain?: boolean;
100
+ domain?: string;
101
101
  }): void;
102
102
  setVarnishCookie: boolean;
103
103
  varnishExpiresIn: number;
104
- varnishCookieDomain: boolean;
104
+ varnishCookieDomain: string;
105
105
  /**
106
106
  * Set the Varnish cookie if configured
107
107
  * @private
@@ -237,10 +237,10 @@ export class Identity {
237
237
  * @param {number|string} [options.maxAge]
238
238
  * @param {string} [options.locale]
239
239
  * @param {boolean} [options.oneStepLogin=false]
240
- * @param {string} [options.prompt]
240
+ * @param {string} [options.prompt=select_account]
241
241
  * @return {Window|null} - Reference to popup window if created (or `null` otherwise)
242
242
  */
243
- login({ state, acrValues, scope, redirectUri, preferPopup, loginHint, tag, teaser, maxAge, locale, oneStepLogin, prompt }: LoginOptions): Window;
243
+ login({ state, acrValues, scope, redirectUri, preferPopup, loginHint, tag, teaser, maxAge, locale, oneStepLogin, prompt }: LoginOptions): Window | null;
244
244
  /**
245
245
  * @async
246
246
  * @summary Retrieve the sp_id (Varnish ID)
@@ -269,7 +269,7 @@ export class Identity {
269
269
  * @param {number|string} [options.maxAge]
270
270
  * @param {string} [options.locale]
271
271
  * @param {boolean} [options.oneStepLogin=false]
272
- * @param {string} [options.prompt]
272
+ * @param {string} [options.prompt=select_account]
273
273
  * @return {string} - The url
274
274
  */
275
275
  loginUrl({ state, acrValues, scope, redirectUri, loginHint, tag, teaser, maxAge, locale, oneStepLogin, prompt, }: LoginOptions, ...args: any[]): string;
@@ -297,11 +297,12 @@ export class Identity {
297
297
  * and store that info in localStorage. Widget will be display only if user is logged in to SSO.
298
298
  *
299
299
  * @async
300
- * @param {LoginOptions} loginParams - the same as `options` param for login function. Login will be called on user
300
+ * @param {SimplifiedLoginWidgetLoginOptions} loginParams - the same as `options` param for login function. Login will be called on user
301
301
  * continue action. `state` might be string or async function.
302
+ * @param {SimplifiedLoginWidgetOptions} [options] - additional configuration of Simplified Login Widget
302
303
  * @return {Promise<boolean|SDKError>} - will resolve to true if widget will be display. Otherwise will throw SDKError
303
304
  */
304
- showSimplifiedLoginWidget(loginParams: LoginOptions): Promise<boolean | SDKError>;
305
+ showSimplifiedLoginWidget(loginParams: SimplifiedLoginWidgetLoginOptions, options?: SimplifiedLoginWidgetOptions): Promise<boolean | SDKError>;
305
306
  }
306
307
  export default Identity;
307
308
  export type LoginOptions = {
@@ -352,6 +353,76 @@ export type LoginOptions = {
352
353
  * in place of default teaser
353
354
  */
354
355
  teaser?: string;
356
+ /**
357
+ * - Specifies the allowable elapsed time in seconds since
358
+ * the last time the End-User was actively authenticated. If last authentication time is more
359
+ * than maxAge seconds in the past, re-authentication will be required. See the OpenID Connect
360
+ * spec section 3.1.2.1 for more information
361
+ */
362
+ maxAge?: number | string;
363
+ /**
364
+ * - Optional parameter to overwrite client locale setting.
365
+ * New flows supports nb_NO, fi_FI, sv_SE, en_US
366
+ */
367
+ locale?: string;
368
+ /**
369
+ * - display username and password on one screen
370
+ */
371
+ oneStepLogin?: boolean;
372
+ /**
373
+ * - String that specifies whether the Authorization Server prompts the
374
+ * End-User for reauthentication or confirm account screen. Supported values: `select_account` or `login`
375
+ */
376
+ prompt?: string;
377
+ };
378
+ export type SimplifiedLoginWidgetLoginOptions = {
379
+ /**
380
+ * - An opaque value used by the client to maintain state between
381
+ * the request and callback. It's also recommended to prevent CSRF {@link https://tools.ietf.org/html/rfc6749#section-10.12}
382
+ */
383
+ state: string | (() => (string | Promise<string>));
384
+ /**
385
+ * - Authentication Context Class Reference Values. If
386
+ * omitted, the user will be asked to authenticate using username+password.
387
+ * For 2FA (Two-Factor Authentication) possible values are `sms`, `otp` (one time password) and
388
+ * `password` (will force password confirmation, even if user is already logged in). Those values might
389
+ * be mixed as space-separated string. To make sure that user has authenticated with 2FA you need
390
+ * to verify AMR (Authentication Methods References) claim in ID token.
391
+ * Might also be used to ensure additional acr (sms, otp) for already logged in users.
392
+ * Supported values are also 'otp-email' means one time password using email, and 'otp-sms' means
393
+ * one time password using sms.
394
+ */
395
+ acrValues?: string;
396
+ /**
397
+ * - The OAuth scopes for the tokens. This is a list of
398
+ * scopes, separated by space. If the list of scopes contains `openid`, the generated tokens
399
+ * includes the id token which can be useful for getting information about the user. Omitting
400
+ * scope is allowed, while `invalid_scope` is returned when the client asks for a scope you
401
+ * aren’t allowed to request. {@link https ://tools.ietf.org/html/rfc6749#section-3.3}
402
+ */
403
+ scope?: string;
404
+ /**
405
+ * - Redirect uri that will receive the
406
+ * code. Must exactly match a redirectUri from your client in self-service
407
+ */
408
+ redirectUri?: string;
409
+ /**
410
+ * - Should we try to open a popup window?
411
+ */
412
+ preferPopup?: boolean;
413
+ /**
414
+ * - user email or UUID hint
415
+ */
416
+ loginHint?: string;
417
+ /**
418
+ * - Pulse tag
419
+ */
420
+ tag?: string;
421
+ /**
422
+ * - Teaser slug. Teaser with given slug will be displayed
423
+ * in place of default teaser
424
+ */
425
+ teaser?: string;
355
426
  /**
356
427
  * - Specifies the allowable elapsed time in seconds since
357
428
  * the last time the End-User was actively authenticated. If last authentication time is more
@@ -498,5 +569,11 @@ export type SimplifiedLoginData = {
498
569
  */
499
570
  client_name: string;
500
571
  };
572
+ export type SimplifiedLoginWidgetOptions = {
573
+ /**
574
+ * - expected encoding of simplified login widget. Could be utf-8 (default), iso-8859-1 or iso-8859-15
575
+ */
576
+ encoding: string;
577
+ };
501
578
  import RESTClient from "./RESTClient";
502
579
  import SDKError from "./SDKError";
package/src/identity.js CHANGED
@@ -48,7 +48,42 @@ const { version } = require('../package.json');
48
48
  * @property {string} [locale] - Optional parameter to overwrite client locale setting.
49
49
  * New flows supports nb_NO, fi_FI, sv_SE, en_US
50
50
  * @property {boolean} [oneStepLogin] - display username and password on one screen
51
- * @property {string} [prompt] - String that specifies whether the Authorization Server prompts the
51
+ * @property {string} [prompt] - String that specifies whether the Authorization Server prompts the
52
+ * End-User for reauthentication or confirm account screen. Supported values: `select_account` or `login`
53
+ */
54
+ /**
55
+ * @typedef {object} SimplifiedLoginWidgetLoginOptions
56
+ * @property {string|function(): (string|Promise<string>)} state - An opaque value used by the client to maintain state between
57
+ * the request and callback. It's also recommended to prevent CSRF {@link https://tools.ietf.org/html/rfc6749#section-10.12}
58
+ * @property {string} [acrValues] - Authentication Context Class Reference Values. If
59
+ * omitted, the user will be asked to authenticate using username+password.
60
+ * For 2FA (Two-Factor Authentication) possible values are `sms`, `otp` (one time password) and
61
+ * `password` (will force password confirmation, even if user is already logged in). Those values might
62
+ * be mixed as space-separated string. To make sure that user has authenticated with 2FA you need
63
+ * to verify AMR (Authentication Methods References) claim in ID token.
64
+ * Might also be used to ensure additional acr (sms, otp) for already logged in users.
65
+ * Supported values are also 'otp-email' means one time password using email, and 'otp-sms' means
66
+ * one time password using sms.
67
+ * @property {string} [scope] - The OAuth scopes for the tokens. This is a list of
68
+ * scopes, separated by space. If the list of scopes contains `openid`, the generated tokens
69
+ * includes the id token which can be useful for getting information about the user. Omitting
70
+ * scope is allowed, while `invalid_scope` is returned when the client asks for a scope you
71
+ * aren’t allowed to request. {@link https://tools.ietf.org/html/rfc6749#section-3.3}
72
+ * @property {string} [redirectUri] - Redirect uri that will receive the
73
+ * code. Must exactly match a redirectUri from your client in self-service
74
+ * @property {boolean} [preferPopup] - Should we try to open a popup window?
75
+ * @property {string} [loginHint] - user email or UUID hint
76
+ * @property {string} [tag] - Pulse tag
77
+ * @property {string} [teaser] - Teaser slug. Teaser with given slug will be displayed
78
+ * in place of default teaser
79
+ * @property {number|string} [maxAge] - Specifies the allowable elapsed time in seconds since
80
+ * the last time the End-User was actively authenticated. If last authentication time is more
81
+ * than maxAge seconds in the past, re-authentication will be required. See the OpenID Connect
82
+ * spec section 3.1.2.1 for more information
83
+ * @property {string} [locale] - Optional parameter to overwrite client locale setting.
84
+ * New flows supports nb_NO, fi_FI, sv_SE, en_US
85
+ * @property {boolean} [oneStepLogin] - display username and password on one screen
86
+ * @property {string} [prompt] - String that specifies whether the Authorization Server prompts the
52
87
  * End-User for reauthentication or confirm account screen. Supported values: `select_account` or `login`
53
88
  */
54
89
 
@@ -104,6 +139,11 @@ const { version } = require('../package.json');
104
139
  * @property {string} client_name - Client name
105
140
  */
106
141
 
142
+ /**
143
+ * @typedef {object} SimplifiedLoginWidgetOptions
144
+ * @property {string} encoding - expected encoding of simplified login widget. Could be utf-8 (default), iso-8859-1 or iso-8859-15
145
+ */
146
+
107
147
  const HAS_SESSION_CACHE_KEY = 'hasSession-cache';
108
148
  const globalWindow = () => window;
109
149
 
@@ -116,7 +156,7 @@ export class Identity extends EventEmitter {
116
156
  * @param {string} options.clientId - Example: "1234567890abcdef12345678"
117
157
  * @param {string} options.sessionDomain - Example: "https://id.site.com"
118
158
  * @param {string} options.redirectUri - Example: "https://site.com"
119
- * @param {string} [options.env=PRE] - Schibsted account environment: `PRE`, `PRO` or `PRO_NO`
159
+ * @param {string} [options.env=PRE] - Schibsted account environment: `PRE`, `PRO`, `PRO_NO`, `PRO_FI` or `PRO_DK`
120
160
  * @param {function} [options.log] - A function that receives debug log information. If not set,
121
161
  * no logging will be done
122
162
  * @param {object} [options.window] - window object
@@ -315,7 +355,7 @@ export class Identity extends EventEmitter {
315
355
  * @param {object} [options]
316
356
  * @param {number} [options.expiresIn] Override this to set number of seconds before the varnish
317
357
  * cookie expires. The default is to use the same time that hasSession responses are cached for
318
- * @param {boolean} [options.domain] Override cookie domain. E.g. «vg.no» instead of «www.vg.no»
358
+ * @param {string} [options.domain] Override cookie domain. E.g. «vg.no» instead of «www.vg.no»
319
359
  * @returns {void}
320
360
  */
321
361
  enableVarnishCookie(options) {
@@ -808,14 +848,20 @@ export class Identity extends EventEmitter {
808
848
  * and store that info in localStorage. Widget will be display only if user is logged in to SSO.
809
849
  *
810
850
  * @async
811
- * @param {LoginOptions} loginParams - the same as `options` param for login function. Login will be called on user
851
+ * @param {SimplifiedLoginWidgetLoginOptions} loginParams - the same as `options` param for login function. Login will be called on user
812
852
  * continue action. `state` might be string or async function.
853
+ * @param {SimplifiedLoginWidgetOptions} [options] - additional configuration of Simplified Login Widget
813
854
  * @return {Promise<boolean|SDKError>} - will resolve to true if widget will be display. Otherwise will throw SDKError
814
855
  */
815
- async showSimplifiedLoginWidget(loginParams) {
856
+ async showSimplifiedLoginWidget(loginParams, options) {
816
857
  // getUserContextData doens't throw exception
817
858
  const userData = await this.getUserContextData();
818
- const widgetUrl = this._bffService.makeUrl('simplified-login-widget', { client_id: this.clientId }, false);
859
+
860
+ const queryParams = { client_id: this.clientId };
861
+ if (options && options.encoding) {
862
+ queryParams.encoding = options.encoding;
863
+ }
864
+ const widgetUrl = this._bffService.makeUrl('simplified-login-widget', queryParams, false);
819
865
 
820
866
  const prepareLoginParams = async (loginPrams) => {
821
867
  if (typeof loginPrams.state === 'function') {
package/src/payment.d.ts CHANGED
@@ -101,6 +101,7 @@ export class Payment {
101
101
  */
102
102
  purchaseCampaignFlowUrl(campaignId: string, productId: string, voucherCode?: string, redirectUri?: string): string;
103
103
  /**
104
+ * @deprecated
104
105
  * Get the url for flow to purchase a promo code product with ZUORA
105
106
  * @param {string} code - promocode product code
106
107
  * @param {string} [state=''] - An opaque value used by the client to maintain state between
package/src/payment.js CHANGED
@@ -185,6 +185,7 @@ export class Payment {
185
185
  }
186
186
 
187
187
  /**
188
+ * @deprecated
188
189
  * Get the url for flow to purchase a promo code product with ZUORA
189
190
  * @param {string} code - promocode product code
190
191
  * @param {string} [state=''] - An opaque value used by the client to maintain state between