@schibsted/account-sdk-browser 5.2.7 → 6.0.0-alpha.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. package/README.md +46 -301
  2. package/dist/account-sdk.d.ts +22 -0
  3. package/dist/account.d.ts +179 -0
  4. package/dist/cache.d.ts +65 -0
  5. package/dist/config.d.ts +86 -0
  6. package/dist/globals.d.ts +11 -0
  7. package/dist/has-access-response.d.ts +2 -0
  8. package/dist/identity.d.ts +302 -0
  9. package/dist/index.d.ts +11 -0
  10. package/dist/index.js +828 -0
  11. package/dist/index.js.map +1 -0
  12. package/dist/monetization.d.ts +39 -0
  13. package/{src → dist}/object.d.ts +4 -9
  14. package/dist/popup.d.ts +9 -0
  15. package/dist/resolve-browser-window.d.ts +1 -0
  16. package/dist/rest-client.d.ts +102 -0
  17. package/dist/rest-clients.d.ts +10 -0
  18. package/dist/sdk-error.d.ts +29 -0
  19. package/dist/session-response.d.ts +54 -0
  20. package/{src/spidTalk.d.ts → dist/spid-talk.d.ts} +4 -6
  21. package/dist/types/account.d.ts +48 -0
  22. package/dist/types/common.d.ts +28 -0
  23. package/dist/types/identity.d.ts +23 -0
  24. package/dist/types/login.d.ts +125 -0
  25. package/dist/types/monetization.d.ts +26 -0
  26. package/dist/types/session.d.ts +146 -0
  27. package/dist/url.d.ts +8 -0
  28. package/dist/validate.d.ts +50 -0
  29. package/dist/version.d.ts +2 -0
  30. package/package.json +34 -52
  31. package/src/account-sdk.ts +92 -0
  32. package/src/account.ts +332 -0
  33. package/src/{cache.js → cache.ts} +53 -38
  34. package/src/{config.js → config.ts} +7 -32
  35. package/src/globals.ts +8 -0
  36. package/src/has-access-response.ts +35 -0
  37. package/src/identity.ts +1023 -0
  38. package/src/index.ts +40 -0
  39. package/src/monetization.ts +128 -0
  40. package/src/{object.js → object.ts} +9 -16
  41. package/src/popup.ts +74 -0
  42. package/src/resolve-browser-window.ts +11 -0
  43. package/src/rest-client.ts +253 -0
  44. package/src/rest-clients.ts +30 -0
  45. package/src/sdk-error.ts +61 -0
  46. package/src/session-response.ts +100 -0
  47. package/src/{spidTalk.js → spid-talk.ts} +10 -12
  48. package/src/types/account.ts +55 -0
  49. package/src/types/common.ts +32 -0
  50. package/src/types/identity.ts +26 -0
  51. package/src/types/login.ts +150 -0
  52. package/src/types/monetization.ts +29 -0
  53. package/src/types/session.ts +169 -0
  54. package/src/{url.js → url.ts} +6 -10
  55. package/src/{validate.js → validate.ts} +27 -43
  56. package/src/{version.js → version.ts} +1 -2
  57. package/es5/global.js +0 -12968
  58. package/es5/global.js.map +0 -1
  59. package/es5/global.min.js +0 -2
  60. package/es5/global.min.js.map +0 -1
  61. package/es5/identity.js +0 -12212
  62. package/es5/identity.js.map +0 -1
  63. package/es5/identity.min.js +0 -2
  64. package/es5/identity.min.js.map +0 -1
  65. package/es5/index.js +0 -12940
  66. package/es5/index.js.map +0 -1
  67. package/es5/index.min.js +0 -2
  68. package/es5/index.min.js.map +0 -1
  69. package/es5/monetization.js +0 -9176
  70. package/es5/monetization.js.map +0 -1
  71. package/es5/monetization.min.js +0 -2
  72. package/es5/monetization.min.js.map +0 -1
  73. package/es5/payment.js +0 -8853
  74. package/es5/payment.js.map +0 -1
  75. package/es5/payment.min.js +0 -2
  76. package/es5/payment.min.js.map +0 -1
  77. package/identity.d.ts +0 -1
  78. package/identity.js +0 -5
  79. package/index.d.ts +0 -4
  80. package/index.js +0 -9
  81. package/monetization.d.ts +0 -1
  82. package/monetization.js +0 -5
  83. package/payment.d.ts +0 -1
  84. package/payment.js +0 -5
  85. package/src/RESTClient.d.ts +0 -89
  86. package/src/RESTClient.js +0 -193
  87. package/src/SDKError.d.ts +0 -16
  88. package/src/SDKError.js +0 -55
  89. package/src/__mocks__/.eslintrc.yml +0 -8
  90. package/src/__mocks__/RESTClient.js +0 -54
  91. package/src/cache.d.ts +0 -64
  92. package/src/config.d.ts +0 -34
  93. package/src/es5/global.js +0 -13
  94. package/src/es5/identity.js +0 -10
  95. package/src/es5/index.js +0 -13
  96. package/src/es5/monetization.js +0 -10
  97. package/src/es5/payment.js +0 -10
  98. package/src/global-registry.js +0 -20
  99. package/src/identity.d.ts +0 -679
  100. package/src/identity.js +0 -1157
  101. package/src/monetization.d.ts +0 -80
  102. package/src/monetization.js +0 -172
  103. package/src/payment.d.ts +0 -115
  104. package/src/payment.js +0 -211
  105. package/src/popup.d.ts +0 -10
  106. package/src/popup.js +0 -59
  107. package/src/url.d.ts +0 -10
  108. package/src/validate.d.ts +0 -64
  109. package/src/version.d.ts +0 -2
@@ -1,80 +0,0 @@
1
- /**
2
- * Provides features related to monetization
3
- */
4
- export class Monetization {
5
- /**
6
- * @param {object} options
7
- * @param {string} options.clientId - Mandatory client id
8
- * @param {string} options.redirectUri - Redirect uri
9
- * @param {string} options.sessionDomain - Example: "https://id.site.com"
10
- * @param {string} [options.env=PRE] - Schibsted account environment: `PRE`, `PRO` or `PRO_NO`
11
- * @param {object} [options.window]
12
- * @throws {SDKError} - If any of options are invalid
13
- */
14
- constructor({ clientId, redirectUri, env, sessionDomain, window }: {
15
- clientId: string;
16
- redirectUri: string;
17
- sessionDomain: string;
18
- env?: string;
19
- window?: any;
20
- });
21
- cache: any;
22
- clientId: string;
23
- env: string;
24
- redirectUri: string;
25
- /**
26
- * Set SPiD server URL
27
- * @private
28
- * @param {string} url
29
- * @returns {void}
30
- */
31
- private _setSpidServerUrl;
32
- _spid: RESTClient;
33
- /**
34
- * Set session-service domain
35
- * @private
36
- * @param {string} domain - real URL — (**not** 'PRE' style env key)
37
- * @returns {void}
38
- */
39
- private _setSessionServiceUrl;
40
- _sessionService: RESTClient;
41
- /**
42
- * Checks if the user has access to a set of products or features.
43
- * @param {array} productIds - which products/features to check
44
- * @param {number} userId - id of currently logged in user
45
- * @throws {SDKError} - If the input is incorrect, or a network call fails in any way
46
- * (this will happen if, say, the user is not logged in)
47
- * @returns {Object|null} The data object returned from Schibsted account (or `null` if the user
48
- * doesn't have access to any of the given products/features)
49
- */
50
- hasAccess(productIds: any[], userId: number): any;
51
- /**
52
- * Removes the cached access result.
53
- * @param {array} productIds - which products/features to check
54
- * @param {number} userId - id of currently logged in user
55
- * @returns {void}
56
- */
57
- clearCachedAccessResult(productIds: any[], userId: number): void;
58
- /**
59
- * Compute "has access" cache key for the given product ids and user id.
60
- * @param {array} productIds - which products/features to check
61
- * @param {number} userId - id of currently logged in user
62
- * @returns {string}
63
- * @private
64
- */
65
- private _accessCacheKey;
66
- /**
67
- * Get the url for the end user to review the subscriptions
68
- * @param {string} [redirectUri=this.redirectUri]
69
- * @return {string} - The url to the subscriptions review page
70
- */
71
- subscriptionsUrl(redirectUri?: string): string;
72
- /**
73
- * Get the url for the end user to review the products
74
- * @param {string} [redirectUri=this.redirectUri]
75
- * @return {string} - The url to the products review page
76
- */
77
- productsUrl(redirectUri?: string): string;
78
- }
79
- export default Monetization;
80
- import RESTClient from "./RESTClient.js";
@@ -1,172 +0,0 @@
1
- /* Copyright 2024 Schibsted Products & Technology AS. Licensed under the terms of the MIT license.
2
- * See LICENSE.md in the project root.
3
- */
4
-
5
- 'use strict';
6
-
7
- import { assert, isStr, isNonEmptyString, isUrl } from './validate.js';
8
- import { urlMapper } from './url.js';
9
- import { ENDPOINTS, NAMESPACE } from './config.js';
10
- import EventEmitter from 'tiny-emitter';
11
- import RESTClient from './RESTClient.js';
12
- import Cache from './cache.js';
13
- import * as spidTalk from './spidTalk.js';
14
- import SDKError from './SDKError.js';
15
- import version from './version.js';
16
- import { registerGlobal } from './global-registry.js';
17
-
18
- const globalWindow = () => window;
19
-
20
- /**
21
- * Provides features related to monetization
22
- */
23
- export class Monetization extends EventEmitter {
24
- /**
25
- * @param {object} options
26
- * @param {string} options.clientId - Mandatory client id
27
- * @param {string} [options.redirectUri] - Redirect uri
28
- * @param {string} options.sessionDomain - Example: "https://id.site.com"
29
- * @param {string} [options.env=PRE] - Schibsted account environment: `PRE`, `PRO` or `PRO_NO`
30
- * @param {object} [options.window]
31
- * @throws {SDKError} - If any of options are invalid
32
- */
33
- constructor({ clientId, redirectUri, env = 'PRE', sessionDomain, window = globalWindow() }) {
34
- super();
35
- spidTalk.emulate(window);
36
- // validate options
37
- assert(isNonEmptyString(clientId), 'clientId parameter is required');
38
-
39
- this.cache = new Cache(() => window && window.sessionStorage);
40
- this.clientId = clientId;
41
- this.env = env;
42
- this.redirectUri = redirectUri;
43
- this.pendingHasAccessRequests = {};
44
- this._setSpidServerUrl(env);
45
-
46
- if (sessionDomain) {
47
- assert(isUrl(sessionDomain), 'sessionDomain parameter is not a valid URL');
48
- this._setSessionServiceUrl(sessionDomain);
49
- }
50
- registerGlobal(window, 'Monetization', this);
51
- }
52
-
53
- /**
54
- * Set SPiD server URL
55
- * @private
56
- * @param {string} url
57
- * @returns {void}
58
- */
59
- _setSpidServerUrl(url) {
60
- assert(isStr(url), `url parameter is invalid: ${url}`);
61
- this._spid = new RESTClient({
62
- serverUrl: urlMapper(url, ENDPOINTS.SPiD),
63
- defaultParams: { client_id: this.clientId, redirect_uri: this.redirectUri },
64
- });
65
- }
66
-
67
- /**
68
- * Set session-service domain
69
- * @private
70
- * @param {string} domain - real URL — (**not** 'PRE' style env key)
71
- * @returns {void}
72
- */
73
- _setSessionServiceUrl(domain) {
74
- assert(isStr(domain), `domain parameter is invalid: ${domain}`);
75
- const client_sdrn = `sdrn:${NAMESPACE[this.env]}:client:${this.clientId}`;
76
- this._sessionService = new RESTClient({
77
- serverUrl: domain,
78
- log: this.log,
79
- defaultParams: { client_sdrn, redirect_uri: this.redirectUri, sdk_version: version },
80
- });
81
- }
82
-
83
- /**
84
- * Checks if the user has access to a set of products or features.
85
- * @param {array} productIds - which products/features to check
86
- * @param {number} userId - id of currently logged in user
87
- * @throws {SDKError} - If the input is incorrect, or a network call fails in any way
88
- * (this will happen if, say, the user is not logged in)
89
- * @returns {Object|null} The data object returned from Schibsted account (or `null` if the user
90
- * doesn't have access to any of the given products/features)
91
- */
92
- async hasAccess(productIds, userId) {
93
- if (!this._sessionService) {
94
- throw new SDKError(`hasAccess can only be called if 'sessionDomain' is configured`);
95
- }
96
- if (!userId) {
97
- throw new SDKError(`'userId' must be specified`);
98
- }
99
- if (!Array.isArray(productIds)) {
100
- throw new SDKError(`'productIds' must be an array`);
101
- }
102
-
103
- const sortedIds = [...productIds].sort();
104
- const cacheKey = this._accessCacheKey(sortedIds, userId);
105
- let data = this.cache.get(cacheKey);
106
- if (!data) {
107
- if (!this.pendingHasAccessRequests[cacheKey]) {
108
- this.pendingHasAccessRequests[cacheKey] = this._sessionService.get(`/hasAccess/${sortedIds.join(',')}`);
109
- }
110
- const promise = this.pendingHasAccessRequests[cacheKey];
111
- try {
112
- data = await promise;
113
- const expiresSeconds = data.ttl;
114
- this.cache.set(cacheKey, data, expiresSeconds * 1000);
115
- } finally {
116
- // If it rejects, we still want to clear the pending request
117
- if (this.pendingHasAccessRequests[cacheKey] === promise) {
118
- delete this.pendingHasAccessRequests[cacheKey];
119
- }
120
- }
121
- }
122
-
123
- if (!data.entitled) {
124
- return null;
125
- }
126
- this.emit('hasAccess', { ids: sortedIds, data });
127
- return data;
128
- }
129
-
130
- /**
131
- * Removes the cached access result.
132
- * @param {array} productIds - which products/features to check
133
- * @param {number} userId - id of currently logged in user
134
- * @returns {void}
135
- */
136
- clearCachedAccessResult(productIds, userId) {
137
- this.cache.delete(this._accessCacheKey(productIds, userId));
138
- }
139
-
140
- /**
141
- * Compute "has access" cache key for the given product ids and user id.
142
- * @param {array} productIds - which products/features to check
143
- * @param {number} userId - id of currently logged in user
144
- * @returns {string}
145
- * @private
146
- */
147
- _accessCacheKey(productIds, userId) {
148
- return `prd_${[...productIds].sort()}_${userId}`;
149
- }
150
-
151
- /**
152
- * Get the url for the end user to review the subscriptions
153
- * @param {string} [redirectUri=this.redirectUri]
154
- * @return {string} - The url to the subscriptions review page
155
- */
156
- subscriptionsUrl(redirectUri = this.redirectUri) {
157
- assert(isUrl(redirectUri), `subscriptionsUrl(): redirectUri is invalid`);
158
- return this._spid.makeUrl('account/subscriptions', { redirect_uri: redirectUri });
159
- }
160
-
161
- /**
162
- * Get the url for the end user to review the products
163
- * @param {string} [redirectUri=this.redirectUri]
164
- * @return {string} - The url to the products review page
165
- */
166
- productsUrl(redirectUri = this.redirectUri) {
167
- assert(isUrl(redirectUri), `productsUrl(): redirectUri is invalid`);
168
- return this._spid.makeUrl('account/products', { redirect_uri: redirectUri });
169
- }
170
- }
171
-
172
- export default Monetization;
package/src/payment.d.ts DELETED
@@ -1,115 +0,0 @@
1
- /**
2
- * Provides features related to payment
3
- */
4
- export class Payment {
5
- /**
6
- * @param {object} options
7
- * @param {string} options.clientId - Mandatory client id
8
- * @param {string} [options.redirectUri] - Redirect uri
9
- * @param {string} [options.env=PRE] - Schibsted account environment: `PRE`, `PRO` or `PRO_NO`
10
- * @param {string} [options.publisher] - ZUORA publisher
11
- * @param {object} [options.window]
12
- *
13
- * @throws {SDKError} - If any of options are invalid
14
- */
15
- constructor({ clientId, redirectUri, env, publisher, window }: {
16
- clientId: string;
17
- redirectUri?: string;
18
- env?: string;
19
- publisher?: string;
20
- window?: any;
21
- });
22
- clientId: string;
23
- redirectUri: string;
24
- window: any;
25
- publisher: string;
26
- /**
27
- * Set SPiD server URL
28
- * @private
29
- * @param {string} url - real URL or 'PRE' style key
30
- * @returns {void}
31
- */
32
- private _setSpidServerUrl;
33
- _spid: RESTClient;
34
- /**
35
- * Set BFF server URL - real URL or 'PRE' style key
36
- * @private
37
- * @param {string} url
38
- * @returns {void}
39
- */
40
- private _setBffServerUrl;
41
- _bff: RESTClient;
42
- /**
43
- * Close this.popup if it exists and is open
44
- * @private
45
- * @returns {void}
46
- */
47
- private _closePopup;
48
- popup: Window;
49
- /**
50
- * Starts the flow for the paylink in a popup or current window
51
- * @param {object} options
52
- * @param {string} options.paylink - The paylink
53
- * @param {boolean} [options.preferPopup=false] - Should we try to open a popup?
54
- * @param {string} [options.redirectUri=this.redirectUri]
55
- * @returns {Window|null} - Returns a reference to the popup window, or `null` if no popup was
56
- * used
57
- */
58
- payWithPaylink({ paylink, preferPopup, redirectUri }: {
59
- paylink: string;
60
- preferPopup?: boolean;
61
- redirectUri?: string;
62
- }): Window;
63
- /**
64
- * Get the url for the end user to review the purchase history
65
- * @param {string} [redirectUri=this.redirectUri]
66
- * @return {string} - The url to the purchase history review page
67
- */
68
- purchaseHistoryUrl(redirectUri?: string): string;
69
- /**
70
- * Get the url for the end user to redeem a voucher code
71
- * @param {string} voucherCode
72
- * @param {string} [redirectUri=this.redirectUri]
73
- * @return {string} - The url
74
- */
75
- redeemUrl(voucherCode: string, redirectUri?: string): string;
76
- /**
77
- * @deprecated https://schibsted.ghe.com/user-identity/account-sdk-browser/issues/94
78
- *
79
- * Get the url for the paylink purchase
80
- * @todo Check working-ness for BFF + SPiD
81
- * @param {string} paylinkId
82
- * @param {string} [redirectUri=this.redirectUri]
83
- * @return {string} - The url to the API endpoint
84
- */
85
- purchasePaylinkUrl(paylinkId: string, redirectUri?: string): string;
86
- /**
87
- * Get the url for flow to purchase a product
88
- * @param {string} productId
89
- * @param {string} [redirectUri=this.redirectUri]
90
- * @return {string} - The url to the products review page
91
- */
92
- purchaseProductFlowUrl(productId: string, redirectUri?: string): string;
93
- /**
94
- * Get the url for flow to purchase a product through a campaign and voucher code
95
- * @todo Check working-ness for BFF + SPiD
96
- * @param {string} campaignId
97
- * @param {string} productId
98
- * @param {string} [voucherCode]
99
- * @param {string} [redirectUri=this.redirectUri]
100
- * @return {string} - The url to the products review page
101
- */
102
- purchaseCampaignFlowUrl(campaignId: string, productId: string, voucherCode?: string, redirectUri?: string): string;
103
- /**
104
- * @deprecated
105
- * Get the url for flow to purchase a promo code product with ZUORA
106
- * @param {string} code - promocode product code
107
- * @param {string} [state=''] - An opaque value used by the client to maintain state between
108
- * the request and callback. It's also recommended to prevent CSRF
109
- * @param {string} [redirectUri=this.redirectUri]
110
- * @return {string} - The url to the buy promo code product flow
111
- */
112
- purchasePromoCodeProductFlowUrl(code: string, state?: string, redirectUri?: string): string;
113
- }
114
- export default Payment;
115
- import RESTClient from "./RESTClient.js";
package/src/payment.js DELETED
@@ -1,211 +0,0 @@
1
- /* Copyright 2024 Schibsted Products & Technology AS. Licensed under the terms of the MIT license.
2
- * See LICENSE.md in the project root.
3
- */
4
-
5
- 'use strict';
6
-
7
- import { assert, isNonEmptyString, isUrl, isStr } from './validate.js';
8
- import { urlMapper } from './url.js';
9
- import { ENDPOINTS } from './config.js';
10
- import * as popup from './popup.js';
11
- import RESTClient from './RESTClient.js';
12
- import * as spidTalk from './spidTalk.js';
13
- import { registerGlobal } from './global-registry.js';
14
-
15
- const globalWindow = () => window;
16
-
17
- /**
18
- * Provides features related to payment
19
- */
20
- export class Payment {
21
- /**
22
- * @param {object} options
23
- * @param {string} options.clientId - Mandatory client id
24
- * @param {string} [options.redirectUri] - Redirect uri
25
- * @param {string} [options.env=PRE] - Schibsted account environment: `PRE`, `PRO` or `PRO_NO`
26
- * @param {string} [options.publisher] - ZUORA publisher
27
- * @param {object} [options.window]
28
- *
29
- * @throws {SDKError} - If any of options are invalid
30
- */
31
- constructor({ clientId, redirectUri, env = 'PRE', publisher, window = globalWindow() }) {
32
- spidTalk.emulate(window);
33
- assert(isNonEmptyString(clientId), 'clientId parameter is required');
34
-
35
- this.clientId = clientId;
36
- this.redirectUri = redirectUri;
37
- this.window = window;
38
- this.publisher = publisher;
39
- this._setSpidServerUrl(env);
40
- this._setBffServerUrl(env);
41
- registerGlobal(window, 'Payment', this);
42
- }
43
-
44
- /**
45
- * Set SPiD server URL
46
- * @private
47
- * @param {string} url - real URL or 'PRE' style key
48
- * @returns {void}
49
- */
50
- _setSpidServerUrl(url) {
51
- assert(isStr(url), `url parameter is invalid: ${url}`);
52
- this._spid = new RESTClient({
53
- serverUrl: urlMapper(url, ENDPOINTS.SPiD),
54
- defaultParams: { client_id: this.clientId, redirect_uri: this.redirectUri },
55
- });
56
- }
57
-
58
- /**
59
- * Set BFF server URL - real URL or 'PRE' style key
60
- * @private
61
- * @param {string} url
62
- * @returns {void}
63
- */
64
- _setBffServerUrl(url) {
65
- assert(isStr(url), `url parameter is invalid: ${url}`);
66
- this._bff = new RESTClient({
67
- serverUrl: urlMapper(url, ENDPOINTS.BFF),
68
- defaultParams: { client_id: this.clientId, redirect_uri: this.redirectUri },
69
- });
70
- }
71
-
72
- /**
73
- * Close this.popup if it exists and is open
74
- * @private
75
- * @returns {void}
76
- */
77
- _closePopup() {
78
- if (this.popup) {
79
- if (!this.popup.closed) {
80
- this.popup.close();
81
- }
82
- this.popup = null;
83
- }
84
- }
85
-
86
- /**
87
- * Starts the flow for the paylink in a popup or current window
88
- * @param {object} options
89
- * @param {string} options.paylink - The paylink
90
- * @param {boolean} [options.preferPopup=false] - Should we try to open a popup?
91
- * @param {string} [options.redirectUri=this.redirectUri]
92
- * @returns {Window|null} - Returns a reference to the popup window, or `null` if no popup was
93
- * used
94
- */
95
- payWithPaylink({ paylink, preferPopup, redirectUri = this.redirectUri }) {
96
- assert(isUrl(redirectUri), `payWithPaylink(): redirectUri is invalid`);
97
- this._closePopup();
98
- const url = this.purchasePaylinkUrl(paylink, redirectUri);
99
- if (preferPopup) {
100
- this.popup =
101
- popup.open(this.window, url, 'Schibsted account', { width: 360, height: 570 });
102
- if (this.popup) {
103
- return this.popup;
104
- }
105
- }
106
- this.window.location.href = url;
107
- return null;
108
- }
109
-
110
- /**
111
- * Get the url for the end user to review the purchase history
112
- * @param {string} [redirectUri=this.redirectUri]
113
- * @return {string} - The url to the purchase history review page
114
- */
115
- purchaseHistoryUrl(redirectUri = this.redirectUri) {
116
- assert(isUrl(redirectUri), `purchaseHistoryUrl(): redirectUri is invalid`);
117
- return this._spid.makeUrl('account/purchasehistory', { redirect_uri: redirectUri });
118
- }
119
-
120
- /**
121
- * Get the url for the end user to redeem a voucher code
122
- * @param {string} voucherCode
123
- * @param {string} [redirectUri=this.redirectUri]
124
- * @return {string} - The url
125
- */
126
- redeemUrl(voucherCode, redirectUri = this.redirectUri) {
127
- assert(isUrl(redirectUri), `redeemUrl(): redirectUri is invalid`);
128
- return this._spid.makeUrl('account/redeem', { voucher_code: voucherCode });
129
- }
130
-
131
- /**
132
- * @deprecated https://schibsted.ghe.com/user-identity/account-sdk-browser/issues/94
133
- *
134
- * Get the url for the paylink purchase
135
- * @todo Check working-ness for BFF + SPiD
136
- * @param {string} paylinkId
137
- * @param {string} [redirectUri=this.redirectUri]
138
- * @return {string} - The url to the API endpoint
139
- */
140
- purchasePaylinkUrl(paylinkId, redirectUri = this.redirectUri) {
141
- assert(isUrl(redirectUri), `purchasePaylinkUrl(): redirectUri is invalid`);
142
- assert(isNonEmptyString(paylinkId), `purchasePaylinkUrl(): paylinkId is required`);
143
- return this._bff.makeUrl('payment/purchase', {
144
- paylink: paylinkId,
145
- redirect_uri: redirectUri
146
- });
147
- }
148
-
149
- /**
150
- * Get the url for flow to purchase a product
151
- * @param {string} productId
152
- * @param {string} [redirectUri=this.redirectUri]
153
- * @return {string} - The url to the products review page
154
- */
155
- purchaseProductFlowUrl(productId, redirectUri = this.redirectUri) {
156
- assert(isUrl(redirectUri), `purchaseProductUrl(): redirectUri is invalid`);
157
- assert(isNonEmptyString(productId), `purchaseProductFlowUrl(): productId is required`);
158
- return this._bff.makeUrl('flow/checkout', {
159
- response_type: 'code',
160
- flow: 'payment',
161
- product_id: productId,
162
- redirect_uri: redirectUri
163
- });
164
- }
165
-
166
- /**
167
- * Get the url for flow to purchase a product through a campaign and voucher code
168
- * @todo Check working-ness for BFF + SPiD
169
- * @param {string} campaignId
170
- * @param {string} productId
171
- * @param {string} [voucherCode]
172
- * @param {string} [redirectUri=this.redirectUri]
173
- * @return {string} - The url to the products review page
174
- */
175
- purchaseCampaignFlowUrl(campaignId, productId, voucherCode, redirectUri = this.redirectUri) {
176
- assert(isUrl(redirectUri), `purchaseCampaignFlowUrl(): redirectUri is invalid`);
177
- assert(isNonEmptyString(campaignId), `purchaseCampaignFlowUrl(): campaignId is required`);
178
- assert(isNonEmptyString(productId), `purchaseCampaignFlowUrl(): productId is required`);
179
- return this._bff.makeUrl('flow/checkout', {
180
- response_type: 'code',
181
- flow: 'payment',
182
- campaign_id: campaignId,
183
- product_id: productId,
184
- voucher_code: voucherCode,
185
- redirect_uri: redirectUri
186
- });
187
- }
188
-
189
- /**
190
- * @deprecated
191
- * Get the url for flow to purchase a promo code product with ZUORA
192
- * @param {string} code - promocode product code
193
- * @param {string} [state=''] - An opaque value used by the client to maintain state between
194
- * the request and callback. It's also recommended to prevent CSRF
195
- * @param {string} [redirectUri=this.redirectUri]
196
- * @return {string} - The url to the buy promo code product flow
197
- */
198
- purchasePromoCodeProductFlowUrl(code, state = '', redirectUri = this.redirectUri) {
199
- assert(isUrl(redirectUri), `purchasePromoCodeProductFlowUrl(): redirectUri is invalid`);
200
- assert(isNonEmptyString(code), `purchasePromoCodeProductFlowUrl(): code is required`);
201
- assert(isNonEmptyString(this.publisher), `purchasePromoCodeProductFlowUrl(): publisher is required in the constructor`);
202
- return this._bff.makeUrl('payment/purchase/code', {
203
- code,
204
- publisher: this.publisher,
205
- state,
206
- redirect_uri: redirectUri
207
- });
208
- }
209
- }
210
-
211
- export default Payment;
package/src/popup.d.ts DELETED
@@ -1,10 +0,0 @@
1
- /**
2
- * Opens a popup
3
- * @param {Window} parentWindow - A reference to the window that will open the popup
4
- * @param {string} url - The URL that the popup will open
5
- * @param {string} [windowName] - A name for the window
6
- * @param {object} [windowFeatures] - Window features for the popup (default ones are usually ok)
7
- * @returns {Window|null} - A reference to the popup window
8
- * @private
9
- */
10
- export function open(parentWindow: Window, url: string, windowName?: string, windowFeatures?: any): Window;
package/src/popup.js DELETED
@@ -1,59 +0,0 @@
1
- /* Copyright 2024 Schibsted Products & Technology AS. Licensed under the terms of the MIT license.
2
- * See LICENSE.md in the project root.
3
- */
4
-
5
- import { assert, isObject, isUrl, isFunction } from './validate.js';
6
- import { cloneDefined } from './object.js';
7
-
8
- /**
9
- * Serializes an object to string.
10
- * @memberof core
11
- * @private
12
- * @param {object} obj - for example {a: 'b', c: 1}
13
- * @return {string} - for example 'a=b,c=1'
14
- */
15
- function serialize(obj) {
16
- assert(isObject(obj), `Object must be an object but it is '${obj}'`);
17
- return Object.keys(obj)
18
- .map(key => `${key}=${obj[key]}`)
19
- .join(',');
20
- }
21
-
22
- const defaultWindowFeatures = {
23
- scrollbars: 'yes',
24
- location: 'yes',
25
- status: 'no',
26
- menubar: 'no',
27
- toolbar: 'no',
28
- resizable: 'yes'
29
- };
30
-
31
- /**
32
- * Opens a popup
33
- * @param {Window} parentWindow - A reference to the window that will open the popup
34
- * @param {string} url - The URL that the popup will open
35
- * @param {string} [windowName] - A name for the window
36
- * @param {object} [windowFeatures] - Window features for the popup (default ones are usually ok)
37
- * @returns {Window|null} - A reference to the popup window
38
- * @private
39
- */
40
- export function open(parentWindow, url, windowName = '', windowFeatures = {}) {
41
- assert(isObject(parentWindow), `window was supposed to be an object but it is ${parentWindow}`);
42
- assert(isObject(parentWindow.screen),
43
- `window should be a valid Window object but it lacks a 'screen' property`);
44
- assert(isFunction(parentWindow.open),
45
- `window should be a valid Window object but it lacks an 'open' function`);
46
- assert(isUrl(url), 'Invalid URL for popup');
47
-
48
- const { height, width } = parentWindow.screen;
49
-
50
- let mergedFeatures = cloneDefined(defaultWindowFeatures, windowFeatures);
51
- if (Number.isFinite(mergedFeatures.width) && Number.isFinite(width)) {
52
- mergedFeatures.left = (width - mergedFeatures.width) / 2;
53
- }
54
- if (Number.isFinite(mergedFeatures.height) && Number.isFinite(height)) {
55
- mergedFeatures.top = (height - mergedFeatures.height) / 2;
56
- }
57
- const features = serialize(mergedFeatures);
58
- return parentWindow.open(url, windowName, features);
59
- }
package/src/url.d.ts DELETED
@@ -1,10 +0,0 @@
1
- /**
2
- * A simple utility function that allows looking up URLs from a dictionary
3
- * @memberof core
4
- * @param {string} url - A url like http://example.com, or a key used for lookup
5
- * @param {object<string,string>} urlMap - A map of URLs like
6
- * `{ DEV: 'http://dev.example.com' }`
7
- * @throws {SDKError} - If the url is not an string or is an empty string
8
- * @return {string} The url that points to the server
9
- */
10
- export function urlMapper(url: string, urlMap: any): string;