@livechat/accounts-sdk 2.0.6 → 2.0.7
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/dist/accounts-sdk.js +193 -40
- package/dist/accounts-sdk.js.map +1 -1
- package/dist/accounts-sdk.min.js +5 -4
- package/dist/accounts-sdk.min.js.map +1 -1
- package/dist/index.cjs.js +139 -40
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +139 -40
- package/dist/index.esm.js.map +1 -1
- package/package.json +44 -44
- package/readme.md +0 -1
package/dist/accounts-sdk.js
CHANGED
|
@@ -42,6 +42,55 @@
|
|
|
42
42
|
return Constructor;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
+
function _defineProperty(obj, key, value) {
|
|
46
|
+
if (key in obj) {
|
|
47
|
+
Object.defineProperty(obj, key, {
|
|
48
|
+
value: value,
|
|
49
|
+
enumerable: true,
|
|
50
|
+
configurable: true,
|
|
51
|
+
writable: true
|
|
52
|
+
});
|
|
53
|
+
} else {
|
|
54
|
+
obj[key] = value;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return obj;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function ownKeys(object, enumerableOnly) {
|
|
61
|
+
var keys = Object.keys(object);
|
|
62
|
+
|
|
63
|
+
if (Object.getOwnPropertySymbols) {
|
|
64
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
65
|
+
if (enumerableOnly) symbols = symbols.filter(function (sym) {
|
|
66
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
67
|
+
});
|
|
68
|
+
keys.push.apply(keys, symbols);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return keys;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function _objectSpread2(target) {
|
|
75
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
76
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
77
|
+
|
|
78
|
+
if (i % 2) {
|
|
79
|
+
ownKeys(Object(source), true).forEach(function (key) {
|
|
80
|
+
_defineProperty(target, key, source[key]);
|
|
81
|
+
});
|
|
82
|
+
} else if (Object.getOwnPropertyDescriptors) {
|
|
83
|
+
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
84
|
+
} else {
|
|
85
|
+
ownKeys(Object(source)).forEach(function (key) {
|
|
86
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return target;
|
|
92
|
+
}
|
|
93
|
+
|
|
45
94
|
var errors = {
|
|
46
95
|
extend: function extend(error) {
|
|
47
96
|
if (error.oauth_exception && this.oauth_exception[error.oauth_exception]) {
|
|
@@ -1040,6 +1089,8 @@
|
|
|
1040
1089
|
|
|
1041
1090
|
}
|
|
1042
1091
|
|
|
1092
|
+
_this.sdk.redirectUriParamsPersister.retrieve(authorizeData.state);
|
|
1093
|
+
|
|
1043
1094
|
resolve(authorizeData);
|
|
1044
1095
|
});
|
|
1045
1096
|
}
|
|
@@ -1123,38 +1174,6 @@
|
|
|
1123
1174
|
|
|
1124
1175
|
/* eslint-disable require-jsdoc */
|
|
1125
1176
|
|
|
1126
|
-
/** @fileOverview
|
|
1127
|
-
* @author Auth0 https://github.com/auth0/auth0.js
|
|
1128
|
-
* @license MIT
|
|
1129
|
-
*/
|
|
1130
|
-
function string(length) {
|
|
1131
|
-
var bytes = new Uint8Array(length);
|
|
1132
|
-
var result = [];
|
|
1133
|
-
var charset = '0123456789ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvwxyz-._~';
|
|
1134
|
-
var cryptoObj = window.crypto || window.msCrypto;
|
|
1135
|
-
var random = '';
|
|
1136
|
-
|
|
1137
|
-
if (!cryptoObj) {
|
|
1138
|
-
for (var i = 0; i < length; i++) {
|
|
1139
|
-
random += charset.charAt(Math.floor(Math.random() * charset.length));
|
|
1140
|
-
}
|
|
1141
|
-
} else {
|
|
1142
|
-
random = cryptoObj.getRandomValues(bytes);
|
|
1143
|
-
}
|
|
1144
|
-
|
|
1145
|
-
for (var a = 0; a < random.length; a++) {
|
|
1146
|
-
result.push(charset[random[a] % charset.length]);
|
|
1147
|
-
}
|
|
1148
|
-
|
|
1149
|
-
return result.join('');
|
|
1150
|
-
}
|
|
1151
|
-
|
|
1152
|
-
var random = {
|
|
1153
|
-
string: string
|
|
1154
|
-
};
|
|
1155
|
-
|
|
1156
|
-
/* eslint-disable require-jsdoc */
|
|
1157
|
-
|
|
1158
1177
|
/** @fileOverview
|
|
1159
1178
|
* @author Auth0 https://github.com/auth0/auth0.js
|
|
1160
1179
|
* @license MIT
|
|
@@ -1360,8 +1379,12 @@
|
|
|
1360
1379
|
|
|
1361
1380
|
CookieStorage.prototype.setItem = function (key, value, options) {
|
|
1362
1381
|
var params = Object.assign({
|
|
1363
|
-
expires: 1
|
|
1364
|
-
|
|
1382
|
+
expires: 1,
|
|
1383
|
+
// 1 day
|
|
1384
|
+
// After august 2020 chrome changed iframe cookie policy and without
|
|
1385
|
+
// those parameters cookies wont we stored properly if document is inside iframe.
|
|
1386
|
+
SameSite: 'none',
|
|
1387
|
+
Secure: true
|
|
1365
1388
|
}, options);
|
|
1366
1389
|
js_cookie.set(key, value, params);
|
|
1367
1390
|
};
|
|
@@ -1468,11 +1491,7 @@
|
|
|
1468
1491
|
_createClass(Transaction, [{
|
|
1469
1492
|
key: "generate",
|
|
1470
1493
|
value: function generate(params) {
|
|
1471
|
-
|
|
1472
|
-
params.state = random.string(this.options.key_length);
|
|
1473
|
-
} // 30 minutes
|
|
1474
|
-
|
|
1475
|
-
|
|
1494
|
+
// 30 minutes
|
|
1476
1495
|
this.storage.setItem(this.options.namespace + params.state, {
|
|
1477
1496
|
state: params.state,
|
|
1478
1497
|
code_verifier: params.code_verifier
|
|
@@ -2172,6 +2191,134 @@
|
|
|
2172
2191
|
base64URLEncode: base64URLEncode
|
|
2173
2192
|
};
|
|
2174
2193
|
|
|
2194
|
+
var Persister = /*#__PURE__*/function () {
|
|
2195
|
+
function Persister(options, type) {
|
|
2196
|
+
_classCallCheck(this, Persister);
|
|
2197
|
+
|
|
2198
|
+
this.options = {
|
|
2199
|
+
namespace: options.transaction.namespace + type
|
|
2200
|
+
};
|
|
2201
|
+
this.storage = new Storage(this.options);
|
|
2202
|
+
}
|
|
2203
|
+
|
|
2204
|
+
_createClass(Persister, [{
|
|
2205
|
+
key: "set",
|
|
2206
|
+
value: function set(state, data) {
|
|
2207
|
+
this.storage.setItem(this.options.namespace + state, data, {
|
|
2208
|
+
expires: 1 / 48
|
|
2209
|
+
});
|
|
2210
|
+
}
|
|
2211
|
+
}, {
|
|
2212
|
+
key: "get",
|
|
2213
|
+
value: function get(state) {
|
|
2214
|
+
var data = this.storage.getItem(this.options.namespace + state);
|
|
2215
|
+
this.clear(state);
|
|
2216
|
+
return data || {};
|
|
2217
|
+
}
|
|
2218
|
+
}, {
|
|
2219
|
+
key: "clear",
|
|
2220
|
+
value: function clear(state) {
|
|
2221
|
+
this.storage.removeItem(this.options.namespace + state);
|
|
2222
|
+
}
|
|
2223
|
+
}]);
|
|
2224
|
+
|
|
2225
|
+
return Persister;
|
|
2226
|
+
}();
|
|
2227
|
+
|
|
2228
|
+
var RedirectUriParamsPersister = /*#__PURE__*/function () {
|
|
2229
|
+
function RedirectUriParamsPersister(options) {
|
|
2230
|
+
_classCallCheck(this, RedirectUriParamsPersister);
|
|
2231
|
+
|
|
2232
|
+
this.persister = new Persister(options, 'redirect_uri_params');
|
|
2233
|
+
}
|
|
2234
|
+
/**
|
|
2235
|
+
* Clears query and hash params from redirect_uri and persists them in storage
|
|
2236
|
+
* @param {Object} params
|
|
2237
|
+
*/
|
|
2238
|
+
|
|
2239
|
+
|
|
2240
|
+
_createClass(RedirectUriParamsPersister, [{
|
|
2241
|
+
key: "persist",
|
|
2242
|
+
value: function persist(params) {
|
|
2243
|
+
var redirectUrl = new URL(params.redirect_uri);
|
|
2244
|
+
var queryParams = lib.parse(redirectUrl.search.substring(1));
|
|
2245
|
+
var hashParams = lib.parse(redirectUrl.hash.substring(1));
|
|
2246
|
+
this.persister.set(params.state, {
|
|
2247
|
+
query_params: queryParams,
|
|
2248
|
+
hash_params: hashParams
|
|
2249
|
+
});
|
|
2250
|
+
params.redirect_uri = redirectUrl.origin + redirectUrl.pathname;
|
|
2251
|
+
}
|
|
2252
|
+
/**
|
|
2253
|
+
* Retrieves persisted query and hash params from storage and updates current location accordingly.
|
|
2254
|
+
* Params returned by global accounts overrides persisted params in case of duplications.
|
|
2255
|
+
* @param {Object} state
|
|
2256
|
+
*/
|
|
2257
|
+
|
|
2258
|
+
}, {
|
|
2259
|
+
key: "retrieve",
|
|
2260
|
+
value: function retrieve(state) {
|
|
2261
|
+
var _redirectUriParams$qu, _redirectUriParams$ha;
|
|
2262
|
+
|
|
2263
|
+
var redirectUriParams = this.persister.get(state, false);
|
|
2264
|
+
|
|
2265
|
+
if (!redirectUriParams) {
|
|
2266
|
+
return;
|
|
2267
|
+
}
|
|
2268
|
+
|
|
2269
|
+
var queryParams = _objectSpread2(_objectSpread2({}, (_redirectUriParams$qu = redirectUriParams.query_params) !== null && _redirectUriParams$qu !== void 0 ? _redirectUriParams$qu : {}), lib.parse(window.location.search.substring(1)));
|
|
2270
|
+
|
|
2271
|
+
var hashParams = _objectSpread2(_objectSpread2({}, (_redirectUriParams$ha = redirectUriParams.hash_params) !== null && _redirectUriParams$ha !== void 0 ? _redirectUriParams$ha : {}), lib.parse(window.location.hash.substring(1)));
|
|
2272
|
+
|
|
2273
|
+
var uri = window.location.origin + window.location.pathname;
|
|
2274
|
+
|
|
2275
|
+
if (queryParams) {
|
|
2276
|
+
uri += '?' + lib.stringify(queryParams);
|
|
2277
|
+
}
|
|
2278
|
+
|
|
2279
|
+
if (hashParams) {
|
|
2280
|
+
uri += '#' + lib.stringify(hashParams);
|
|
2281
|
+
}
|
|
2282
|
+
|
|
2283
|
+
window.history.replaceState({}, document.title, uri);
|
|
2284
|
+
}
|
|
2285
|
+
}]);
|
|
2286
|
+
|
|
2287
|
+
return RedirectUriParamsPersister;
|
|
2288
|
+
}();
|
|
2289
|
+
|
|
2290
|
+
/* eslint-disable require-jsdoc */
|
|
2291
|
+
|
|
2292
|
+
/** @fileOverview
|
|
2293
|
+
* @author Auth0 https://github.com/auth0/auth0.js
|
|
2294
|
+
* @license MIT
|
|
2295
|
+
*/
|
|
2296
|
+
function string(length) {
|
|
2297
|
+
var bytes = new Uint8Array(length);
|
|
2298
|
+
var result = [];
|
|
2299
|
+
var charset = '0123456789ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvwxyz-._~';
|
|
2300
|
+
var cryptoObj = window.crypto || window.msCrypto;
|
|
2301
|
+
var random = '';
|
|
2302
|
+
|
|
2303
|
+
if (!cryptoObj) {
|
|
2304
|
+
for (var i = 0; i < length; i++) {
|
|
2305
|
+
random += charset.charAt(Math.floor(Math.random() * charset.length));
|
|
2306
|
+
}
|
|
2307
|
+
} else {
|
|
2308
|
+
random = cryptoObj.getRandomValues(bytes);
|
|
2309
|
+
}
|
|
2310
|
+
|
|
2311
|
+
for (var a = 0; a < random.length; a++) {
|
|
2312
|
+
result.push(charset[random[a] % charset.length]);
|
|
2313
|
+
}
|
|
2314
|
+
|
|
2315
|
+
return result.join('');
|
|
2316
|
+
}
|
|
2317
|
+
|
|
2318
|
+
var random = {
|
|
2319
|
+
string: string
|
|
2320
|
+
};
|
|
2321
|
+
|
|
2175
2322
|
/**
|
|
2176
2323
|
* Accounts SDK main class
|
|
2177
2324
|
*/
|
|
@@ -2241,6 +2388,7 @@
|
|
|
2241
2388
|
};
|
|
2242
2389
|
this.options = Object.assign({}, defaultOptions, options);
|
|
2243
2390
|
this.transaction = new Transaction(this.options);
|
|
2391
|
+
this.redirectUriParamsPersister = new RedirectUriParamsPersister(this.options);
|
|
2244
2392
|
}
|
|
2245
2393
|
/**
|
|
2246
2394
|
* use iframe for authorization
|
|
@@ -2296,8 +2444,12 @@
|
|
|
2296
2444
|
var flow = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
2297
2445
|
var localOptions = Object.assign({}, this.options, options);
|
|
2298
2446
|
|
|
2447
|
+
if (!params.state) {
|
|
2448
|
+
localOptions.state = random.string(localOptions.key_length);
|
|
2449
|
+
}
|
|
2450
|
+
|
|
2299
2451
|
if (!localOptions.redirect_uri) {
|
|
2300
|
-
localOptions.redirect_uri = window.location.
|
|
2452
|
+
localOptions.redirect_uri = window.location.href;
|
|
2301
2453
|
}
|
|
2302
2454
|
|
|
2303
2455
|
var params = pick(localOptions, ['client_id', 'redirect_uri', 'state', 'response_type', 'scope', 'prompt']);
|
|
@@ -2348,6 +2500,7 @@
|
|
|
2348
2500
|
}
|
|
2349
2501
|
|
|
2350
2502
|
this.transaction.generate(params);
|
|
2503
|
+
this.redirectUriParamsPersister.persist(params);
|
|
2351
2504
|
delete params.code_verifier;
|
|
2352
2505
|
return url + '?' + lib.stringify(params);
|
|
2353
2506
|
}
|