@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
package/src/RESTClient.d.ts
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This class can be used for creating a wrapper around a server and all its endpoints.
|
|
3
|
-
* Its functionality is extended by {@link JSONPClient}
|
|
4
|
-
* Creates a client to a REST server. While useful stand-alone, it's also used for some other
|
|
5
|
-
* types of client that change some functionalities.
|
|
6
|
-
* @throws {SDKError} if any of options are invalid
|
|
7
|
-
* @summary the simplest way to communicate to a REST endpoint without any
|
|
8
|
-
* special authentication
|
|
9
|
-
* @memberof core
|
|
10
|
-
* @private
|
|
11
|
-
*/
|
|
12
|
-
export class RESTClient {
|
|
13
|
-
/**
|
|
14
|
-
* Construct query string for WHATWG urls
|
|
15
|
-
* @private
|
|
16
|
-
* @param {object} query - Object to generate query string from
|
|
17
|
-
* @param {boolean} useDefaultParams - Use defaultParams or not
|
|
18
|
-
* @param {object} defaultParams - Default params
|
|
19
|
-
* @returns {string} Query string
|
|
20
|
-
*/
|
|
21
|
-
private static search;
|
|
22
|
-
/**
|
|
23
|
-
* @param {object} options
|
|
24
|
-
* @param {string} [options.serverUrl=PRE] - The URL to the server eg.
|
|
25
|
-
* https://login.schibsted.com or a URL key like 'DEV' in combination with {@link envDic}.
|
|
26
|
-
* @param {object} [options.envDic] - A dictionary that will be used for looking up
|
|
27
|
-
* {@link serverUrl} keys. If serverUrl is always a URL, you don't need this.
|
|
28
|
-
* @param {function} [options.fetch=window.fetch] - The fetch function to use. It can be native
|
|
29
|
-
* or a polyfill
|
|
30
|
-
* @param {function} [options.log] - A function that will be called with log messages about
|
|
31
|
-
* request and response
|
|
32
|
-
* @param {object} [options.defaultParams={}] - a set of parameters to add to every call custom.
|
|
33
|
-
* As long as it supports the standard fetch API we're good.
|
|
34
|
-
*/
|
|
35
|
-
constructor({ serverUrl, envDic, fetch, log, defaultParams }: {
|
|
36
|
-
serverUrl?: string;
|
|
37
|
-
envDic?: any;
|
|
38
|
-
fetch?: Function;
|
|
39
|
-
log?: Function;
|
|
40
|
-
defaultParams?: any;
|
|
41
|
-
});
|
|
42
|
-
url: URL;
|
|
43
|
-
defaultParams: any;
|
|
44
|
-
log: Function;
|
|
45
|
-
fetch: Function;
|
|
46
|
-
/**
|
|
47
|
-
* Makes the actual call to the server and deals with headers, data objects and the edge cases.
|
|
48
|
-
* Please note that this method expects the response to be in JSON format. However, it'll not
|
|
49
|
-
* parse the response if its code is not in the 200 range.
|
|
50
|
-
* @param {object} options - an obligatory options object
|
|
51
|
-
* @param {string} options.method - can be 'GET', 'POST', 'DELETE', etc. case sensitive. To be
|
|
52
|
-
* more specific, this can be one of the values that are passed to the `methods`
|
|
53
|
-
* property of the constructor's `options` parameter.
|
|
54
|
-
* @param {string} options.pathname - the path to the endpoint like 'api/2/endpoint-name'
|
|
55
|
-
* @param {Object} [options.data={}] - data payload (depending on GET/DELETE or POST it may be a query
|
|
56
|
-
* string or form body)
|
|
57
|
-
* @param {array} [options.headers] - fetch options headers
|
|
58
|
-
* @param {boolean} [options.useDefaultParams] - should we add the defaultParams to the query?
|
|
59
|
-
* @param {object} [options.fetchOptions] - fetch options
|
|
60
|
-
* @throws {SDKError} - if the call can't be made for whatever reason.
|
|
61
|
-
* @return {Promise<object>} - A promise that will resolve to the call's response or reject if there
|
|
62
|
-
* is an error before making the call or if the server returns a non-2xx error or
|
|
63
|
-
* something that's not parsable as JSON.
|
|
64
|
-
*/
|
|
65
|
-
go({ method, headers, pathname, data, useDefaultParams, fetchOptions }: {
|
|
66
|
-
method: string;
|
|
67
|
-
pathname: string;
|
|
68
|
-
data?: any;
|
|
69
|
-
headers?: any[];
|
|
70
|
-
useDefaultParams?: boolean;
|
|
71
|
-
fetchOptions?: any;
|
|
72
|
-
}): Promise<any>;
|
|
73
|
-
/**
|
|
74
|
-
* Creates a url that points to an endpoint in the server
|
|
75
|
-
* @param {string} [pathname=] - WHATWG pathname ie. 'api/2/endpoint-name'
|
|
76
|
-
* @param {object} [query={}] - WHATWG query. It's the data payload.
|
|
77
|
-
* @param {boolean} [useDefaultParams=true] - should we add the defaultParams to the query?
|
|
78
|
-
* @return {string} - the resulting url string ready to pass to fetch
|
|
79
|
-
*/
|
|
80
|
-
makeUrl(pathname?: string, query?: any, useDefaultParams?: boolean): string;
|
|
81
|
-
/**
|
|
82
|
-
* Make a GET request
|
|
83
|
-
* @param {string} pathname - WHATWG pathname ie. 'api/2/endpoint-name'
|
|
84
|
-
* @param {object} [data={}] - the data payload.
|
|
85
|
-
* @return {Promise}
|
|
86
|
-
*/
|
|
87
|
-
get(pathname: string, data?: any): Promise<any>;
|
|
88
|
-
}
|
|
89
|
-
export default RESTClient;
|
package/src/RESTClient.js
DELETED
|
@@ -1,193 +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 SDKError from './SDKError.js';
|
|
8
|
-
import { cloneDefined } from './object.js';
|
|
9
|
-
import { urlMapper } from './url.js';
|
|
10
|
-
import { assert, isObject, isFunction, isStr, isNonEmptyString } from './validate.js';
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Converts a series of parameters of various types to a string that's suitable for logging.
|
|
14
|
-
* @private
|
|
15
|
-
* @param {Array.<*>} msg - a number of parameters from any type (including objects)
|
|
16
|
-
* @return {string}
|
|
17
|
-
*/
|
|
18
|
-
const logString = (msg) => msg.map(m => isObject(m) ? JSON.stringify(m, null, 2) : m).join(' ');
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Calls a log function passing a string
|
|
22
|
-
* @private
|
|
23
|
-
* @param {function} fn - the log function
|
|
24
|
-
* @param {...*} msg - a series of message objects
|
|
25
|
-
* @return {*} - The result of calling fn
|
|
26
|
-
*/
|
|
27
|
-
const logFn = (fn, ...msg) => (typeof fn === 'function') && fn(logString(msg));
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Encode a string like URLSearchParams would do
|
|
31
|
-
* @private
|
|
32
|
-
* @param {string} str - The input
|
|
33
|
-
* @returns {string} The encoded string
|
|
34
|
-
*/
|
|
35
|
-
function encode(str) {
|
|
36
|
-
const replace = {
|
|
37
|
-
'!': '%21',
|
|
38
|
-
"'": '%27',
|
|
39
|
-
'(': '%28',
|
|
40
|
-
')': '%29',
|
|
41
|
-
'~': '%7E',
|
|
42
|
-
'%20': '+',
|
|
43
|
-
'%00': '\x00'
|
|
44
|
-
};
|
|
45
|
-
return encodeURIComponent(str).replace(/[!'()~]|%20|%00/g, match => replace[match]);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const globalFetch = () => window.fetch && window.fetch.bind(window);
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* This class can be used for creating a wrapper around a server and all its endpoints.
|
|
52
|
-
* Its functionality is extended by {@link JSONPClient}
|
|
53
|
-
* Creates a client to a REST server. While useful stand-alone, it's also used for some other
|
|
54
|
-
* types of client that change some functionalities.
|
|
55
|
-
* @throws {SDKError} if any of options are invalid
|
|
56
|
-
* @summary the simplest way to communicate to a REST endpoint without any
|
|
57
|
-
* special authentication
|
|
58
|
-
* @memberof core
|
|
59
|
-
* @private
|
|
60
|
-
*/
|
|
61
|
-
export class RESTClient {
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* @param {object} options
|
|
65
|
-
* @param {string} [options.serverUrl=PRE] - The URL to the server eg.
|
|
66
|
-
* https://login.schibsted.com or a URL key like 'DEV' in combination with {@link envDic}.
|
|
67
|
-
* @param {object} [options.envDic] - A dictionary that will be used for looking up
|
|
68
|
-
* {@link serverUrl} keys. If serverUrl is always a URL, you don't need this.
|
|
69
|
-
* @param {function} [options.fetch=window.fetch] - The fetch function to use. It can be native
|
|
70
|
-
* or a polyfill
|
|
71
|
-
* @param {function} [options.log] - A function that will be called with log messages about
|
|
72
|
-
* request and response
|
|
73
|
-
* @param {object} [options.defaultParams={}] - a set of parameters to add to every call custom.
|
|
74
|
-
* As long as it supports the standard fetch API we're good.
|
|
75
|
-
*/
|
|
76
|
-
constructor({ serverUrl = 'PRE', envDic, fetch = globalFetch(), log, defaultParams = {}}) {
|
|
77
|
-
assert(isObject(defaultParams), `defaultParams should be a non-null object`);
|
|
78
|
-
|
|
79
|
-
const mappedUrl = urlMapper(serverUrl, envDic);
|
|
80
|
-
const handledServerUrl = mappedUrl.endsWith('/') ? mappedUrl : `${mappedUrl}/`;
|
|
81
|
-
this.url = new URL(handledServerUrl);
|
|
82
|
-
|
|
83
|
-
this.defaultParams = defaultParams;
|
|
84
|
-
|
|
85
|
-
if (log) {
|
|
86
|
-
assert(isFunction(log), `log must be a function but it is ${log}`);
|
|
87
|
-
this.log = log;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
if (fetch) {
|
|
91
|
-
assert(isFunction(fetch), 'Fetch should be a function');
|
|
92
|
-
this.fetch = fetch;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Makes the actual call to the server and deals with headers, data objects and the edge cases.
|
|
98
|
-
* Please note that this method expects the response to be in JSON format. However, it'll not
|
|
99
|
-
* parse the response if its code is not in the 200 range.
|
|
100
|
-
* @param {object} options - an obligatory options object
|
|
101
|
-
* @param {string} options.method - can be 'GET', 'POST', 'DELETE', etc. case sensitive. To be
|
|
102
|
-
* more specific, this can be one of the values that are passed to the `methods`
|
|
103
|
-
* property of the constructor's `options` parameter.
|
|
104
|
-
* @param {string} options.pathname - the path to the endpoint like 'api/2/endpoint-name'
|
|
105
|
-
* @param {Object} [options.data={}] - data payload (depending on GET/DELETE or POST it may be a query
|
|
106
|
-
* string or form body)
|
|
107
|
-
* @param {array} [options.headers] - fetch options headers
|
|
108
|
-
* @param {boolean} [options.useDefaultParams] - should we add the defaultParams to the query?
|
|
109
|
-
* @param {object} [options.fetchOptions] - fetch options
|
|
110
|
-
* @throws {SDKError} - if the call can't be made for whatever reason.
|
|
111
|
-
* @return {Promise<object>} - A promise that will resolve to the call's response or reject if there
|
|
112
|
-
* is an error before making the call or if the server returns a non-2xx error or
|
|
113
|
-
* something that's not parsable as JSON.
|
|
114
|
-
*/
|
|
115
|
-
async go({
|
|
116
|
-
method,
|
|
117
|
-
headers,
|
|
118
|
-
pathname,
|
|
119
|
-
data = {},
|
|
120
|
-
useDefaultParams = true,
|
|
121
|
-
fetchOptions = { method, credentials: 'include' }
|
|
122
|
-
}) {
|
|
123
|
-
assert(isFunction(this.fetch),
|
|
124
|
-
`Can't make a call. The reference to fetch is missing or not a function.`);
|
|
125
|
-
assert(isNonEmptyString(method), `Method must be a non empty string but it is "${method}"`);
|
|
126
|
-
assert(isNonEmptyString(pathname), `Pathname must be string but it is "${pathname}"`);
|
|
127
|
-
assert(isObject(data), `data must be a non-null object`);
|
|
128
|
-
|
|
129
|
-
fetchOptions.headers = isObject(headers) ? cloneDefined(headers) : {};
|
|
130
|
-
const fullUrl = this.makeUrl(pathname, data, useDefaultParams);
|
|
131
|
-
|
|
132
|
-
logFn(this.log, 'Request:', fetchOptions.method.toUpperCase(), fullUrl);
|
|
133
|
-
logFn(this.log, 'Request Headers:', fetchOptions.headers);
|
|
134
|
-
logFn(this.log, 'Request Body:', fetchOptions.body);
|
|
135
|
-
try {
|
|
136
|
-
const response = await this.fetch(fullUrl, fetchOptions);
|
|
137
|
-
logFn(this.log, 'Response Code:', response.status, response.statusText);
|
|
138
|
-
if (!response.ok) {
|
|
139
|
-
// status code not in range 200-299
|
|
140
|
-
throw new SDKError(response.statusText, { code: response.status });
|
|
141
|
-
}
|
|
142
|
-
const responseObject = await response.json();
|
|
143
|
-
logFn(this.log, 'Response Parsed:', responseObject);
|
|
144
|
-
return responseObject;
|
|
145
|
-
} catch (err) {
|
|
146
|
-
let msg = isStr(err) ? err : 'Unknown RESTClient error';
|
|
147
|
-
if (isObject(err) && isStr(err.message)) {
|
|
148
|
-
msg = err.message;
|
|
149
|
-
}
|
|
150
|
-
throw new SDKError(`Failed to '${method}' '${fullUrl}': '${msg}'`, err);
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* Creates a url that points to an endpoint in the server
|
|
156
|
-
* @param {string} [pathname=] - WHATWG pathname ie. 'api/2/endpoint-name'
|
|
157
|
-
* @param {object} [query={}] - WHATWG query. It's the data payload.
|
|
158
|
-
* @param {boolean} [useDefaultParams=true] - should we add the defaultParams to the query?
|
|
159
|
-
* @return {string} - the resulting url string ready to pass to fetch
|
|
160
|
-
*/
|
|
161
|
-
makeUrl(pathname = '', query = {}, useDefaultParams = true) {
|
|
162
|
-
const handledPathname = pathname.startsWith('/') ? pathname.slice(1) : pathname;
|
|
163
|
-
|
|
164
|
-
const url = new URL(handledPathname, this.url);
|
|
165
|
-
url.search = RESTClient.search(query, useDefaultParams, this.defaultParams);
|
|
166
|
-
return url.href;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* Make a GET request
|
|
171
|
-
* @param {string} pathname - WHATWG pathname ie. 'api/2/endpoint-name'
|
|
172
|
-
* @param {object} [data={}] - the data payload.
|
|
173
|
-
* @return {Promise}
|
|
174
|
-
*/
|
|
175
|
-
get(pathname, data) {
|
|
176
|
-
return this.go({ method: 'get', pathname, data });
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
/**
|
|
180
|
-
* Construct query string for WHATWG urls
|
|
181
|
-
* @private
|
|
182
|
-
* @param {object} query - Object to generate query string from
|
|
183
|
-
* @param {boolean} useDefaultParams - Use defaultParams or not
|
|
184
|
-
* @param {object} defaultParams - Default params
|
|
185
|
-
* @returns {string} Query string
|
|
186
|
-
*/
|
|
187
|
-
static search(query, useDefaultParams, defaultParams) {
|
|
188
|
-
const params = useDefaultParams ? cloneDefined(defaultParams, query) : cloneDefined(query);
|
|
189
|
-
return Object.keys(params).filter(p => params[p]!=='').map(p => `${encode(p)}=${encode(params[p])}`).join('&');
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
export default RESTClient;
|
package/src/SDKError.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Represents a SDK error. This is returned from all rejected promises that are returned from an API
|
|
3
|
-
* call. Constructs an SDK error ready to throw
|
|
4
|
-
* @summary When the SDK throws an error, it's supposed to be an instance of this class
|
|
5
|
-
* @private
|
|
6
|
-
*/
|
|
7
|
-
export default class SDKError extends Error {
|
|
8
|
-
/**
|
|
9
|
-
* @property {number} code - The HTTP error code
|
|
10
|
-
* @extends {Error}
|
|
11
|
-
* @param {string} message - The error message
|
|
12
|
-
* @param {object} [errorObject] - The error object that was returned from the server. Any
|
|
13
|
-
* property of errorObject object will be copied into this instance SDKError
|
|
14
|
-
*/
|
|
15
|
-
constructor(message: string, errorObject?: any);
|
|
16
|
-
}
|
package/src/SDKError.js
DELETED
|
@@ -1,55 +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
|
-
/*
|
|
8
|
-
* Note: this module can't have any internal dependencies because it's used in ./validate which
|
|
9
|
-
* in turn is used as a dependency to a lot of other modules. Doing so may create a circular
|
|
10
|
-
* dependency that's hard to debug in Node.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
const STRINGIFY_TYPES = ['boolean', 'number', 'string'];
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Represents a SDK error. This is returned from all rejected promises that are returned from an API
|
|
17
|
-
* call. Constructs an SDK error ready to throw
|
|
18
|
-
* @summary When the SDK throws an error, it's supposed to be an instance of this class
|
|
19
|
-
* @private
|
|
20
|
-
*/
|
|
21
|
-
export default class SDKError extends Error {
|
|
22
|
-
/**
|
|
23
|
-
* @property {number} code - The HTTP error code
|
|
24
|
-
* @extends {Error}
|
|
25
|
-
* @param {string} message - The error message
|
|
26
|
-
* @param {object} [errorObject] - The error object that was returned from the server. Any
|
|
27
|
-
* property of errorObject object will be copied into this instance SDKError
|
|
28
|
-
*/
|
|
29
|
-
constructor(message, errorObject) {
|
|
30
|
-
super(message);
|
|
31
|
-
this.name = 'SDKError';
|
|
32
|
-
if (typeof errorObject === 'object') {
|
|
33
|
-
try {
|
|
34
|
-
// At this point it doesn't matter if errorObject === null
|
|
35
|
-
Object.assign(this, errorObject);
|
|
36
|
-
} catch(err) {
|
|
37
|
-
// silent
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Serializes the error printing any interesting additional info
|
|
44
|
-
* @private
|
|
45
|
-
* @return {String}
|
|
46
|
-
*/
|
|
47
|
-
toString() {
|
|
48
|
-
const ret = `${this.name}: ${this.message}`;
|
|
49
|
-
const additionalInfo = Object.keys(this)
|
|
50
|
-
.filter(key => key !== 'name' && STRINGIFY_TYPES.includes(typeof this[key]))
|
|
51
|
-
.map(key => ` ${key}: ${this[key]}`)
|
|
52
|
-
.join('\n');
|
|
53
|
-
return additionalInfo ? `${ret}\n${additionalInfo}` : ret;
|
|
54
|
-
}
|
|
55
|
-
}
|
package/src/cache.d.ts
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Cache class that attempts WebStorage (session/local storage), and falls back to JS object literal
|
|
3
|
-
* @private
|
|
4
|
-
*/
|
|
5
|
-
export default class Cache {
|
|
6
|
-
/**
|
|
7
|
-
* @param {Storage} [storeProvider] - A function to return a WebStorage instance (either
|
|
8
|
-
* `sessionStorage` or `localStorage` from a `Window` object)
|
|
9
|
-
* @throws {SDKError} - If sessionStorage or localStorage are not accessible
|
|
10
|
-
*/
|
|
11
|
-
constructor(storeProvider?: Storage);
|
|
12
|
-
cache: WebStorageCache | LiteralCache;
|
|
13
|
-
type: string;
|
|
14
|
-
/**
|
|
15
|
-
* Get a value from cache (checks that the object has not expired)
|
|
16
|
-
* @param {string} key
|
|
17
|
-
* @private
|
|
18
|
-
* @returns {*} - The value if it exists, otherwise null
|
|
19
|
-
*/
|
|
20
|
-
private get;
|
|
21
|
-
/**
|
|
22
|
-
* Set a cache entry
|
|
23
|
-
* @param {string} key
|
|
24
|
-
* @param {*} value
|
|
25
|
-
* @param {Number} expiresIn - Value in milliseconds until the entry expires
|
|
26
|
-
* @private
|
|
27
|
-
* @returns {void}
|
|
28
|
-
*/
|
|
29
|
-
private set;
|
|
30
|
-
/**
|
|
31
|
-
* Delete a cache entry
|
|
32
|
-
* @param {string} key
|
|
33
|
-
* @private
|
|
34
|
-
* @returns {void}
|
|
35
|
-
*/
|
|
36
|
-
private delete;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Will be used if web storage is available
|
|
40
|
-
* @private
|
|
41
|
-
*/
|
|
42
|
-
declare class WebStorageCache {
|
|
43
|
-
/**
|
|
44
|
-
* Create web storage cache object
|
|
45
|
-
* @param {Storage} store - A reference to either `sessionStorage` or `localStorage` from a
|
|
46
|
-
* `Window` object
|
|
47
|
-
*/
|
|
48
|
-
constructor(store: Storage);
|
|
49
|
-
store: Storage;
|
|
50
|
-
get: (key: any) => string;
|
|
51
|
-
set: (key: any, value: any) => void;
|
|
52
|
-
delete: (key: any) => void;
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Will be used if session storage is not available
|
|
56
|
-
* @private
|
|
57
|
-
*/
|
|
58
|
-
declare class LiteralCache {
|
|
59
|
-
store: {};
|
|
60
|
-
get: (key: any) => any;
|
|
61
|
-
set: (key: any, value: any) => any;
|
|
62
|
-
delete: (key: any) => boolean;
|
|
63
|
-
}
|
|
64
|
-
export {};
|
package/src/config.d.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
export default config;
|
|
2
|
-
export const ENDPOINTS: any;
|
|
3
|
-
export const NAMESPACE: any;
|
|
4
|
-
/**
|
|
5
|
-
* Core configuration used by the SDK
|
|
6
|
-
* @type {Object}
|
|
7
|
-
* @memberof core
|
|
8
|
-
* @prop {object} ENDPOINTS - URL to some of the services that users of this SDK may interact with
|
|
9
|
-
* @prop {object} ENDPOINTS.SPiD - SPiD endpoints
|
|
10
|
-
* @prop {string} ENDPOINTS.SPiD.LOCAL - Local endpoint (for Identity team)
|
|
11
|
-
* @prop {string} ENDPOINTS.SPiD.DEV - Dev environment (for Identity team)
|
|
12
|
-
* @prop {string} ENDPOINTS.SPiD.PRE - Staging environment
|
|
13
|
-
* @prop {string} ENDPOINTS.SPiD.PRO - Production environment Sweden
|
|
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
|
|
17
|
-
* @prop {object} ENDPOINTS.BFF - Endpoints used with new GDPR-compliant web flows
|
|
18
|
-
* @prop {string} ENDPOINTS.BFF.LOCAL - Local endpoint (for Identity team)
|
|
19
|
-
* @prop {string} ENDPOINTS.BFF.DEV - Dev environment (for Identity team)
|
|
20
|
-
* @prop {string} ENDPOINTS.BFF.PRE - Staging environment
|
|
21
|
-
* @prop {string} ENDPOINTS.BFF.PRO - Production environment Sweden
|
|
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
|
|
25
|
-
* @prop {object} ENDPOINTS.SESSION_SERVICE - Endpoints to check global user session data
|
|
26
|
-
* @prop {string} ENDPOINTS.SESSION_SERVICE.LOCAL - Local endpoint (for Identity team)
|
|
27
|
-
* @prop {string} ENDPOINTS.SESSION_SERVICE.DEV - Dev environment (for Identity team)
|
|
28
|
-
* @prop {string} ENDPOINTS.SESSION_SERVICE.PRE - Staging environment
|
|
29
|
-
* @prop {string} ENDPOINTS.SESSION_SERVICE.PRO - Production environment Sweden
|
|
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
|
|
33
|
-
*/
|
|
34
|
-
declare const config: Object;
|
package/src/global-registry.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* Registers a component as a property on the provided global object, if not already registered, and dispatches an event to notify listeners.
|
|
4
|
-
* The event is dispatched on `document` and will have the name `$sch${componentClassName}:ready` and a `detail` property with the instance.
|
|
5
|
-
*
|
|
6
|
-
* @param {any} global typically `window`
|
|
7
|
-
* @param {string} componentClassName the name of the component to register, 'identity', 'monetization' or 'payment'
|
|
8
|
-
* @param {any} instance the instance of the component to register
|
|
9
|
-
* @returns {void}
|
|
10
|
-
*/
|
|
11
|
-
export const registerGlobal = (global, componentClassName, instance) => {
|
|
12
|
-
const prefixedName = `sch${componentClassName}`;
|
|
13
|
-
if (!(global)[prefixedName]) {
|
|
14
|
-
(global)[prefixedName] = instance;
|
|
15
|
-
}
|
|
16
|
-
if (typeof global.dispatchEvent === 'function') {
|
|
17
|
-
global.dispatchEvent(new CustomEvent(`${prefixedName}:ready`, { detail: { instance } }));
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|