@livechat/accounts-sdk 2.0.5 → 2.0.6-beta.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/dist/accounts-sdk.js +179 -38
- 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 +130 -40
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +130 -40
- package/dist/index.esm.js.map +1 -1
- package/package.json +44 -44
- package/readme.md +1 -2
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
|
|
@@ -1468,11 +1487,7 @@
|
|
|
1468
1487
|
_createClass(Transaction, [{
|
|
1469
1488
|
key: "generate",
|
|
1470
1489
|
value: function generate(params) {
|
|
1471
|
-
|
|
1472
|
-
params.state = random.string(this.options.key_length);
|
|
1473
|
-
} // 30 minutes
|
|
1474
|
-
|
|
1475
|
-
|
|
1490
|
+
// 30 minutes
|
|
1476
1491
|
this.storage.setItem(this.options.namespace + params.state, {
|
|
1477
1492
|
state: params.state,
|
|
1478
1493
|
code_verifier: params.code_verifier
|
|
@@ -2172,6 +2187,126 @@
|
|
|
2172
2187
|
base64URLEncode: base64URLEncode
|
|
2173
2188
|
};
|
|
2174
2189
|
|
|
2190
|
+
var Persister = /*#__PURE__*/function () {
|
|
2191
|
+
function Persister(options, type) {
|
|
2192
|
+
_classCallCheck(this, Persister);
|
|
2193
|
+
|
|
2194
|
+
this.options = {
|
|
2195
|
+
namespace: options.transaction.namespace + type
|
|
2196
|
+
};
|
|
2197
|
+
this.storage = new Storage(this.options);
|
|
2198
|
+
}
|
|
2199
|
+
|
|
2200
|
+
_createClass(Persister, [{
|
|
2201
|
+
key: "set",
|
|
2202
|
+
value: function set(state, data) {
|
|
2203
|
+
this.storage.setItem(this.options.namespace + state, data, {
|
|
2204
|
+
expires: 1 / 48
|
|
2205
|
+
});
|
|
2206
|
+
}
|
|
2207
|
+
}, {
|
|
2208
|
+
key: "get",
|
|
2209
|
+
value: function get(state) {
|
|
2210
|
+
var data = this.storage.getItem(this.options.namespace + state);
|
|
2211
|
+
this.clear(state);
|
|
2212
|
+
return data || {};
|
|
2213
|
+
}
|
|
2214
|
+
}, {
|
|
2215
|
+
key: "clear",
|
|
2216
|
+
value: function clear(state) {
|
|
2217
|
+
this.storage.removeItem(this.options.namespace + state);
|
|
2218
|
+
}
|
|
2219
|
+
}]);
|
|
2220
|
+
|
|
2221
|
+
return Persister;
|
|
2222
|
+
}();
|
|
2223
|
+
|
|
2224
|
+
var RedirectUriParamsPersister = /*#__PURE__*/function () {
|
|
2225
|
+
function RedirectUriParamsPersister(options) {
|
|
2226
|
+
_classCallCheck(this, RedirectUriParamsPersister);
|
|
2227
|
+
|
|
2228
|
+
this.persister = new Persister(options, 'redirect_uri_params');
|
|
2229
|
+
}
|
|
2230
|
+
|
|
2231
|
+
_createClass(RedirectUriParamsPersister, [{
|
|
2232
|
+
key: "persist",
|
|
2233
|
+
value: function persist(params) {
|
|
2234
|
+
var redirectUrl = new URL(params.redirect_uri);
|
|
2235
|
+
var queryParams = lib.parse(redirectUrl.search.substring(1));
|
|
2236
|
+
var hashParams = lib.parse(redirectUrl.hash.substring(1));
|
|
2237
|
+
this.persister.set(params.state, {
|
|
2238
|
+
query_params: queryParams,
|
|
2239
|
+
hash_params: hashParams
|
|
2240
|
+
});
|
|
2241
|
+
params.redirect_uri = redirectUrl.origin + redirectUrl.pathname;
|
|
2242
|
+
}
|
|
2243
|
+
}, {
|
|
2244
|
+
key: "retrieve",
|
|
2245
|
+
value: function retrieve(state) {
|
|
2246
|
+
var _customParamsData$que, _customParamsData$has;
|
|
2247
|
+
|
|
2248
|
+
var redirectUriParams = this.persister.get(state, false);
|
|
2249
|
+
|
|
2250
|
+
if (!redirectUriParams) {
|
|
2251
|
+
return;
|
|
2252
|
+
}
|
|
2253
|
+
|
|
2254
|
+
var queryParams = _objectSpread2(_objectSpread2({}, (_customParamsData$que = customParamsData.query_params) !== null && _customParamsData$que !== void 0 ? _customParamsData$que : {}), lib.parse(window.location.search.substring(1)));
|
|
2255
|
+
|
|
2256
|
+
var hashParams = _objectSpread2(_objectSpread2({}, (_customParamsData$has = customParamsData.hash_params) !== null && _customParamsData$has !== void 0 ? _customParamsData$has : {}), lib.parse(window.location.hash.substring(1)));
|
|
2257
|
+
|
|
2258
|
+
console.log('queryParams: ', queryParams);
|
|
2259
|
+
console.log('hashParams: ', hashParams);
|
|
2260
|
+
var uri = window.location.origin + window.location.pathname;
|
|
2261
|
+
|
|
2262
|
+
if (queryParams) {
|
|
2263
|
+
uri += '?' + lib.stringify(queryParams);
|
|
2264
|
+
}
|
|
2265
|
+
|
|
2266
|
+
if (hashParams) {
|
|
2267
|
+
uri += '?' + lib.stringify(hashParams);
|
|
2268
|
+
}
|
|
2269
|
+
|
|
2270
|
+
console.log(uri);
|
|
2271
|
+
window.history.replaceState({}, document.title, uri);
|
|
2272
|
+
}
|
|
2273
|
+
}]);
|
|
2274
|
+
|
|
2275
|
+
return RedirectUriParamsPersister;
|
|
2276
|
+
}();
|
|
2277
|
+
|
|
2278
|
+
/* eslint-disable require-jsdoc */
|
|
2279
|
+
|
|
2280
|
+
/** @fileOverview
|
|
2281
|
+
* @author Auth0 https://github.com/auth0/auth0.js
|
|
2282
|
+
* @license MIT
|
|
2283
|
+
*/
|
|
2284
|
+
function string(length) {
|
|
2285
|
+
var bytes = new Uint8Array(length);
|
|
2286
|
+
var result = [];
|
|
2287
|
+
var charset = '0123456789ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvwxyz-._~';
|
|
2288
|
+
var cryptoObj = window.crypto || window.msCrypto;
|
|
2289
|
+
var random = '';
|
|
2290
|
+
|
|
2291
|
+
if (!cryptoObj) {
|
|
2292
|
+
for (var i = 0; i < length; i++) {
|
|
2293
|
+
random += charset.charAt(Math.floor(Math.random() * charset.length));
|
|
2294
|
+
}
|
|
2295
|
+
} else {
|
|
2296
|
+
random = cryptoObj.getRandomValues(bytes);
|
|
2297
|
+
}
|
|
2298
|
+
|
|
2299
|
+
for (var a = 0; a < random.length; a++) {
|
|
2300
|
+
result.push(charset[random[a] % charset.length]);
|
|
2301
|
+
}
|
|
2302
|
+
|
|
2303
|
+
return result.join('');
|
|
2304
|
+
}
|
|
2305
|
+
|
|
2306
|
+
var random = {
|
|
2307
|
+
string: string
|
|
2308
|
+
};
|
|
2309
|
+
|
|
2175
2310
|
/**
|
|
2176
2311
|
* Accounts SDK main class
|
|
2177
2312
|
*/
|
|
@@ -2241,6 +2376,7 @@
|
|
|
2241
2376
|
};
|
|
2242
2377
|
this.options = Object.assign({}, defaultOptions, options);
|
|
2243
2378
|
this.transaction = new Transaction(this.options);
|
|
2379
|
+
this.redirectUriParamsPersister = new RedirectUriParamsPersister(this.options);
|
|
2244
2380
|
}
|
|
2245
2381
|
/**
|
|
2246
2382
|
* use iframe for authorization
|
|
@@ -2296,8 +2432,12 @@
|
|
|
2296
2432
|
var flow = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
2297
2433
|
var localOptions = Object.assign({}, this.options, options);
|
|
2298
2434
|
|
|
2435
|
+
if (!params.state) {
|
|
2436
|
+
localOptions.state = random.string(localOptions.key_length);
|
|
2437
|
+
}
|
|
2438
|
+
|
|
2299
2439
|
if (!localOptions.redirect_uri) {
|
|
2300
|
-
localOptions.redirect_uri = window.location.
|
|
2440
|
+
localOptions.redirect_uri = window.location.href;
|
|
2301
2441
|
}
|
|
2302
2442
|
|
|
2303
2443
|
var params = pick(localOptions, ['client_id', 'redirect_uri', 'state', 'response_type', 'scope', 'prompt']);
|
|
@@ -2348,6 +2488,7 @@
|
|
|
2348
2488
|
}
|
|
2349
2489
|
|
|
2350
2490
|
this.transaction.generate(params);
|
|
2491
|
+
this.redirectUriParamsPersister.persist(params);
|
|
2351
2492
|
delete params.code_verifier;
|
|
2352
2493
|
return url + '?' + lib.stringify(params);
|
|
2353
2494
|
}
|