mezon-sdk 2.7.1 → 2.7.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/README.md +143 -143
- package/api.ts +392 -0
- package/build.mjs +44 -44
- package/client.ts +409 -327
- package/dist/api.d.ts +68 -0
- package/dist/client.d.ts +173 -74
- package/dist/index.d.ts +18 -18
- package/dist/mezon-sdk.cjs.js +10346 -0
- package/dist/mezon-sdk.esm.mjs +10326 -0
- package/dist/mezon-sdk.iife.js +10348 -0
- package/dist/mezon-sdk.umd.js +11033 -0
- package/dist/session.d.ts +52 -52
- package/dist/socket.d.ts +594 -0
- package/dist/utils.d.ts +3 -3
- package/dist/web_socket_adapter.d.ts +83 -0
- package/index.ts +19 -19
- package/package.json +46 -49
- package/rollup.config.js +40 -40
- package/session.ts +107 -107
- package/socket.ts +1345 -0
- package/tsconfig.json +10 -10
- package/utils.ts +47 -47
- package/web_socket_adapter.ts +159 -0
- package/api.gen.ts +0 -783
- package/dist/api.gen.d.ts +0 -157
- package/dist/satori-js.cjs.js +0 -1456
- package/dist/satori-js.esm.mjs +0 -1436
- package/dist/satori-js.iife.js +0 -1458
- package/dist/satori-js.umd.js +0 -1956
- package/tsconfig.base.json +0 -33
package/dist/satori-js.umd.js
DELETED
|
@@ -1,1956 +0,0 @@
|
|
|
1
|
-
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
|
3
|
-
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.satorijs = {}));
|
|
5
|
-
})(this, (function (exports) { 'use strict';
|
|
6
|
-
|
|
7
|
-
/* eslint-disable no-prototype-builtins */
|
|
8
|
-
var g =
|
|
9
|
-
(typeof globalThis !== 'undefined' && globalThis) ||
|
|
10
|
-
(typeof self !== 'undefined' && self) ||
|
|
11
|
-
// eslint-disable-next-line no-undef
|
|
12
|
-
(typeof global !== 'undefined' && global) ||
|
|
13
|
-
{};
|
|
14
|
-
|
|
15
|
-
var support = {
|
|
16
|
-
searchParams: 'URLSearchParams' in g,
|
|
17
|
-
iterable: 'Symbol' in g && 'iterator' in Symbol,
|
|
18
|
-
blob:
|
|
19
|
-
'FileReader' in g &&
|
|
20
|
-
'Blob' in g &&
|
|
21
|
-
(function() {
|
|
22
|
-
try {
|
|
23
|
-
new Blob();
|
|
24
|
-
return true
|
|
25
|
-
} catch (e) {
|
|
26
|
-
return false
|
|
27
|
-
}
|
|
28
|
-
})(),
|
|
29
|
-
formData: 'FormData' in g,
|
|
30
|
-
arrayBuffer: 'ArrayBuffer' in g
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
function isDataView(obj) {
|
|
34
|
-
return obj && DataView.prototype.isPrototypeOf(obj)
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
if (support.arrayBuffer) {
|
|
38
|
-
var viewClasses = [
|
|
39
|
-
'[object Int8Array]',
|
|
40
|
-
'[object Uint8Array]',
|
|
41
|
-
'[object Uint8ClampedArray]',
|
|
42
|
-
'[object Int16Array]',
|
|
43
|
-
'[object Uint16Array]',
|
|
44
|
-
'[object Int32Array]',
|
|
45
|
-
'[object Uint32Array]',
|
|
46
|
-
'[object Float32Array]',
|
|
47
|
-
'[object Float64Array]'
|
|
48
|
-
];
|
|
49
|
-
|
|
50
|
-
var isArrayBufferView =
|
|
51
|
-
ArrayBuffer.isView ||
|
|
52
|
-
function(obj) {
|
|
53
|
-
return obj && viewClasses.indexOf(Object.prototype.toString.call(obj)) > -1
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
function normalizeName(name) {
|
|
58
|
-
if (typeof name !== 'string') {
|
|
59
|
-
name = String(name);
|
|
60
|
-
}
|
|
61
|
-
if (/[^a-z0-9\-#$%&'*+.^_`|~!]/i.test(name) || name === '') {
|
|
62
|
-
throw new TypeError('Invalid character in header field name: "' + name + '"')
|
|
63
|
-
}
|
|
64
|
-
return name.toLowerCase()
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
function normalizeValue(value) {
|
|
68
|
-
if (typeof value !== 'string') {
|
|
69
|
-
value = String(value);
|
|
70
|
-
}
|
|
71
|
-
return value
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
// Build a destructive iterator for the value list
|
|
75
|
-
function iteratorFor(items) {
|
|
76
|
-
var iterator = {
|
|
77
|
-
next: function() {
|
|
78
|
-
var value = items.shift();
|
|
79
|
-
return {done: value === undefined, value: value}
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
if (support.iterable) {
|
|
84
|
-
iterator[Symbol.iterator] = function() {
|
|
85
|
-
return iterator
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
return iterator
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
function Headers(headers) {
|
|
93
|
-
this.map = {};
|
|
94
|
-
|
|
95
|
-
if (headers instanceof Headers) {
|
|
96
|
-
headers.forEach(function(value, name) {
|
|
97
|
-
this.append(name, value);
|
|
98
|
-
}, this);
|
|
99
|
-
} else if (Array.isArray(headers)) {
|
|
100
|
-
headers.forEach(function(header) {
|
|
101
|
-
if (header.length != 2) {
|
|
102
|
-
throw new TypeError('Headers constructor: expected name/value pair to be length 2, found' + header.length)
|
|
103
|
-
}
|
|
104
|
-
this.append(header[0], header[1]);
|
|
105
|
-
}, this);
|
|
106
|
-
} else if (headers) {
|
|
107
|
-
Object.getOwnPropertyNames(headers).forEach(function(name) {
|
|
108
|
-
this.append(name, headers[name]);
|
|
109
|
-
}, this);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
Headers.prototype.append = function(name, value) {
|
|
114
|
-
name = normalizeName(name);
|
|
115
|
-
value = normalizeValue(value);
|
|
116
|
-
var oldValue = this.map[name];
|
|
117
|
-
this.map[name] = oldValue ? oldValue + ', ' + value : value;
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
Headers.prototype['delete'] = function(name) {
|
|
121
|
-
delete this.map[normalizeName(name)];
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
Headers.prototype.get = function(name) {
|
|
125
|
-
name = normalizeName(name);
|
|
126
|
-
return this.has(name) ? this.map[name] : null
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
Headers.prototype.has = function(name) {
|
|
130
|
-
return this.map.hasOwnProperty(normalizeName(name))
|
|
131
|
-
};
|
|
132
|
-
|
|
133
|
-
Headers.prototype.set = function(name, value) {
|
|
134
|
-
this.map[normalizeName(name)] = normalizeValue(value);
|
|
135
|
-
};
|
|
136
|
-
|
|
137
|
-
Headers.prototype.forEach = function(callback, thisArg) {
|
|
138
|
-
for (var name in this.map) {
|
|
139
|
-
if (this.map.hasOwnProperty(name)) {
|
|
140
|
-
callback.call(thisArg, this.map[name], name, this);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
Headers.prototype.keys = function() {
|
|
146
|
-
var items = [];
|
|
147
|
-
this.forEach(function(value, name) {
|
|
148
|
-
items.push(name);
|
|
149
|
-
});
|
|
150
|
-
return iteratorFor(items)
|
|
151
|
-
};
|
|
152
|
-
|
|
153
|
-
Headers.prototype.values = function() {
|
|
154
|
-
var items = [];
|
|
155
|
-
this.forEach(function(value) {
|
|
156
|
-
items.push(value);
|
|
157
|
-
});
|
|
158
|
-
return iteratorFor(items)
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
Headers.prototype.entries = function() {
|
|
162
|
-
var items = [];
|
|
163
|
-
this.forEach(function(value, name) {
|
|
164
|
-
items.push([name, value]);
|
|
165
|
-
});
|
|
166
|
-
return iteratorFor(items)
|
|
167
|
-
};
|
|
168
|
-
|
|
169
|
-
if (support.iterable) {
|
|
170
|
-
Headers.prototype[Symbol.iterator] = Headers.prototype.entries;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
function consumed(body) {
|
|
174
|
-
if (body._noBody) return
|
|
175
|
-
if (body.bodyUsed) {
|
|
176
|
-
return Promise.reject(new TypeError('Already read'))
|
|
177
|
-
}
|
|
178
|
-
body.bodyUsed = true;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
function fileReaderReady(reader) {
|
|
182
|
-
return new Promise(function(resolve, reject) {
|
|
183
|
-
reader.onload = function() {
|
|
184
|
-
resolve(reader.result);
|
|
185
|
-
};
|
|
186
|
-
reader.onerror = function() {
|
|
187
|
-
reject(reader.error);
|
|
188
|
-
};
|
|
189
|
-
})
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
function readBlobAsArrayBuffer(blob) {
|
|
193
|
-
var reader = new FileReader();
|
|
194
|
-
var promise = fileReaderReady(reader);
|
|
195
|
-
reader.readAsArrayBuffer(blob);
|
|
196
|
-
return promise
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
function readBlobAsText(blob) {
|
|
200
|
-
var reader = new FileReader();
|
|
201
|
-
var promise = fileReaderReady(reader);
|
|
202
|
-
var match = /charset=([A-Za-z0-9_-]+)/.exec(blob.type);
|
|
203
|
-
var encoding = match ? match[1] : 'utf-8';
|
|
204
|
-
reader.readAsText(blob, encoding);
|
|
205
|
-
return promise
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
function readArrayBufferAsText(buf) {
|
|
209
|
-
var view = new Uint8Array(buf);
|
|
210
|
-
var chars = new Array(view.length);
|
|
211
|
-
|
|
212
|
-
for (var i = 0; i < view.length; i++) {
|
|
213
|
-
chars[i] = String.fromCharCode(view[i]);
|
|
214
|
-
}
|
|
215
|
-
return chars.join('')
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
function bufferClone(buf) {
|
|
219
|
-
if (buf.slice) {
|
|
220
|
-
return buf.slice(0)
|
|
221
|
-
} else {
|
|
222
|
-
var view = new Uint8Array(buf.byteLength);
|
|
223
|
-
view.set(new Uint8Array(buf));
|
|
224
|
-
return view.buffer
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
function Body() {
|
|
229
|
-
this.bodyUsed = false;
|
|
230
|
-
|
|
231
|
-
this._initBody = function(body) {
|
|
232
|
-
/*
|
|
233
|
-
fetch-mock wraps the Response object in an ES6 Proxy to
|
|
234
|
-
provide useful test harness features such as flush. However, on
|
|
235
|
-
ES5 browsers without fetch or Proxy support pollyfills must be used;
|
|
236
|
-
the proxy-pollyfill is unable to proxy an attribute unless it exists
|
|
237
|
-
on the object before the Proxy is created. This change ensures
|
|
238
|
-
Response.bodyUsed exists on the instance, while maintaining the
|
|
239
|
-
semantic of setting Request.bodyUsed in the constructor before
|
|
240
|
-
_initBody is called.
|
|
241
|
-
*/
|
|
242
|
-
// eslint-disable-next-line no-self-assign
|
|
243
|
-
this.bodyUsed = this.bodyUsed;
|
|
244
|
-
this._bodyInit = body;
|
|
245
|
-
if (!body) {
|
|
246
|
-
this._noBody = true;
|
|
247
|
-
this._bodyText = '';
|
|
248
|
-
} else if (typeof body === 'string') {
|
|
249
|
-
this._bodyText = body;
|
|
250
|
-
} else if (support.blob && Blob.prototype.isPrototypeOf(body)) {
|
|
251
|
-
this._bodyBlob = body;
|
|
252
|
-
} else if (support.formData && FormData.prototype.isPrototypeOf(body)) {
|
|
253
|
-
this._bodyFormData = body;
|
|
254
|
-
} else if (support.searchParams && URLSearchParams.prototype.isPrototypeOf(body)) {
|
|
255
|
-
this._bodyText = body.toString();
|
|
256
|
-
} else if (support.arrayBuffer && support.blob && isDataView(body)) {
|
|
257
|
-
this._bodyArrayBuffer = bufferClone(body.buffer);
|
|
258
|
-
// IE 10-11 can't handle a DataView body.
|
|
259
|
-
this._bodyInit = new Blob([this._bodyArrayBuffer]);
|
|
260
|
-
} else if (support.arrayBuffer && (ArrayBuffer.prototype.isPrototypeOf(body) || isArrayBufferView(body))) {
|
|
261
|
-
this._bodyArrayBuffer = bufferClone(body);
|
|
262
|
-
} else {
|
|
263
|
-
this._bodyText = body = Object.prototype.toString.call(body);
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
if (!this.headers.get('content-type')) {
|
|
267
|
-
if (typeof body === 'string') {
|
|
268
|
-
this.headers.set('content-type', 'text/plain;charset=UTF-8');
|
|
269
|
-
} else if (this._bodyBlob && this._bodyBlob.type) {
|
|
270
|
-
this.headers.set('content-type', this._bodyBlob.type);
|
|
271
|
-
} else if (support.searchParams && URLSearchParams.prototype.isPrototypeOf(body)) {
|
|
272
|
-
this.headers.set('content-type', 'application/x-www-form-urlencoded;charset=UTF-8');
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
};
|
|
276
|
-
|
|
277
|
-
if (support.blob) {
|
|
278
|
-
this.blob = function() {
|
|
279
|
-
var rejected = consumed(this);
|
|
280
|
-
if (rejected) {
|
|
281
|
-
return rejected
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
if (this._bodyBlob) {
|
|
285
|
-
return Promise.resolve(this._bodyBlob)
|
|
286
|
-
} else if (this._bodyArrayBuffer) {
|
|
287
|
-
return Promise.resolve(new Blob([this._bodyArrayBuffer]))
|
|
288
|
-
} else if (this._bodyFormData) {
|
|
289
|
-
throw new Error('could not read FormData body as blob')
|
|
290
|
-
} else {
|
|
291
|
-
return Promise.resolve(new Blob([this._bodyText]))
|
|
292
|
-
}
|
|
293
|
-
};
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
this.arrayBuffer = function() {
|
|
297
|
-
if (this._bodyArrayBuffer) {
|
|
298
|
-
var isConsumed = consumed(this);
|
|
299
|
-
if (isConsumed) {
|
|
300
|
-
return isConsumed
|
|
301
|
-
} else if (ArrayBuffer.isView(this._bodyArrayBuffer)) {
|
|
302
|
-
return Promise.resolve(
|
|
303
|
-
this._bodyArrayBuffer.buffer.slice(
|
|
304
|
-
this._bodyArrayBuffer.byteOffset,
|
|
305
|
-
this._bodyArrayBuffer.byteOffset + this._bodyArrayBuffer.byteLength
|
|
306
|
-
)
|
|
307
|
-
)
|
|
308
|
-
} else {
|
|
309
|
-
return Promise.resolve(this._bodyArrayBuffer)
|
|
310
|
-
}
|
|
311
|
-
} else if (support.blob) {
|
|
312
|
-
return this.blob().then(readBlobAsArrayBuffer)
|
|
313
|
-
} else {
|
|
314
|
-
throw new Error('could not read as ArrayBuffer')
|
|
315
|
-
}
|
|
316
|
-
};
|
|
317
|
-
|
|
318
|
-
this.text = function() {
|
|
319
|
-
var rejected = consumed(this);
|
|
320
|
-
if (rejected) {
|
|
321
|
-
return rejected
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
if (this._bodyBlob) {
|
|
325
|
-
return readBlobAsText(this._bodyBlob)
|
|
326
|
-
} else if (this._bodyArrayBuffer) {
|
|
327
|
-
return Promise.resolve(readArrayBufferAsText(this._bodyArrayBuffer))
|
|
328
|
-
} else if (this._bodyFormData) {
|
|
329
|
-
throw new Error('could not read FormData body as text')
|
|
330
|
-
} else {
|
|
331
|
-
return Promise.resolve(this._bodyText)
|
|
332
|
-
}
|
|
333
|
-
};
|
|
334
|
-
|
|
335
|
-
if (support.formData) {
|
|
336
|
-
this.formData = function() {
|
|
337
|
-
return this.text().then(decode)
|
|
338
|
-
};
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
this.json = function() {
|
|
342
|
-
return this.text().then(JSON.parse)
|
|
343
|
-
};
|
|
344
|
-
|
|
345
|
-
return this
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
// HTTP methods whose capitalization should be normalized
|
|
349
|
-
var methods = ['CONNECT', 'DELETE', 'GET', 'HEAD', 'OPTIONS', 'PATCH', 'POST', 'PUT', 'TRACE'];
|
|
350
|
-
|
|
351
|
-
function normalizeMethod(method) {
|
|
352
|
-
var upcased = method.toUpperCase();
|
|
353
|
-
return methods.indexOf(upcased) > -1 ? upcased : method
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
function Request(input, options) {
|
|
357
|
-
if (!(this instanceof Request)) {
|
|
358
|
-
throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.')
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
options = options || {};
|
|
362
|
-
var body = options.body;
|
|
363
|
-
|
|
364
|
-
if (input instanceof Request) {
|
|
365
|
-
if (input.bodyUsed) {
|
|
366
|
-
throw new TypeError('Already read')
|
|
367
|
-
}
|
|
368
|
-
this.url = input.url;
|
|
369
|
-
this.credentials = input.credentials;
|
|
370
|
-
if (!options.headers) {
|
|
371
|
-
this.headers = new Headers(input.headers);
|
|
372
|
-
}
|
|
373
|
-
this.method = input.method;
|
|
374
|
-
this.mode = input.mode;
|
|
375
|
-
this.signal = input.signal;
|
|
376
|
-
if (!body && input._bodyInit != null) {
|
|
377
|
-
body = input._bodyInit;
|
|
378
|
-
input.bodyUsed = true;
|
|
379
|
-
}
|
|
380
|
-
} else {
|
|
381
|
-
this.url = String(input);
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
this.credentials = options.credentials || this.credentials || 'same-origin';
|
|
385
|
-
if (options.headers || !this.headers) {
|
|
386
|
-
this.headers = new Headers(options.headers);
|
|
387
|
-
}
|
|
388
|
-
this.method = normalizeMethod(options.method || this.method || 'GET');
|
|
389
|
-
this.mode = options.mode || this.mode || null;
|
|
390
|
-
this.signal = options.signal || this.signal || (function () {
|
|
391
|
-
if ('AbortController' in g) {
|
|
392
|
-
var ctrl = new AbortController();
|
|
393
|
-
return ctrl.signal;
|
|
394
|
-
}
|
|
395
|
-
}());
|
|
396
|
-
this.referrer = null;
|
|
397
|
-
|
|
398
|
-
if ((this.method === 'GET' || this.method === 'HEAD') && body) {
|
|
399
|
-
throw new TypeError('Body not allowed for GET or HEAD requests')
|
|
400
|
-
}
|
|
401
|
-
this._initBody(body);
|
|
402
|
-
|
|
403
|
-
if (this.method === 'GET' || this.method === 'HEAD') {
|
|
404
|
-
if (options.cache === 'no-store' || options.cache === 'no-cache') {
|
|
405
|
-
// Search for a '_' parameter in the query string
|
|
406
|
-
var reParamSearch = /([?&])_=[^&]*/;
|
|
407
|
-
if (reParamSearch.test(this.url)) {
|
|
408
|
-
// If it already exists then set the value with the current time
|
|
409
|
-
this.url = this.url.replace(reParamSearch, '$1_=' + new Date().getTime());
|
|
410
|
-
} else {
|
|
411
|
-
// Otherwise add a new '_' parameter to the end with the current time
|
|
412
|
-
var reQueryString = /\?/;
|
|
413
|
-
this.url += (reQueryString.test(this.url) ? '&' : '?') + '_=' + new Date().getTime();
|
|
414
|
-
}
|
|
415
|
-
}
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
Request.prototype.clone = function() {
|
|
420
|
-
return new Request(this, {body: this._bodyInit})
|
|
421
|
-
};
|
|
422
|
-
|
|
423
|
-
function decode(body) {
|
|
424
|
-
var form = new FormData();
|
|
425
|
-
body
|
|
426
|
-
.trim()
|
|
427
|
-
.split('&')
|
|
428
|
-
.forEach(function(bytes) {
|
|
429
|
-
if (bytes) {
|
|
430
|
-
var split = bytes.split('=');
|
|
431
|
-
var name = split.shift().replace(/\+/g, ' ');
|
|
432
|
-
var value = split.join('=').replace(/\+/g, ' ');
|
|
433
|
-
form.append(decodeURIComponent(name), decodeURIComponent(value));
|
|
434
|
-
}
|
|
435
|
-
});
|
|
436
|
-
return form
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
function parseHeaders(rawHeaders) {
|
|
440
|
-
var headers = new Headers();
|
|
441
|
-
// Replace instances of \r\n and \n followed by at least one space or horizontal tab with a space
|
|
442
|
-
// https://tools.ietf.org/html/rfc7230#section-3.2
|
|
443
|
-
var preProcessedHeaders = rawHeaders.replace(/\r?\n[\t ]+/g, ' ');
|
|
444
|
-
// Avoiding split via regex to work around a common IE11 bug with the core-js 3.6.0 regex polyfill
|
|
445
|
-
// https://github.com/github/fetch/issues/748
|
|
446
|
-
// https://github.com/zloirock/core-js/issues/751
|
|
447
|
-
preProcessedHeaders
|
|
448
|
-
.split('\r')
|
|
449
|
-
.map(function(header) {
|
|
450
|
-
return header.indexOf('\n') === 0 ? header.substr(1, header.length) : header
|
|
451
|
-
})
|
|
452
|
-
.forEach(function(line) {
|
|
453
|
-
var parts = line.split(':');
|
|
454
|
-
var key = parts.shift().trim();
|
|
455
|
-
if (key) {
|
|
456
|
-
var value = parts.join(':').trim();
|
|
457
|
-
try {
|
|
458
|
-
headers.append(key, value);
|
|
459
|
-
} catch (error) {
|
|
460
|
-
console.warn('Response ' + error.message);
|
|
461
|
-
}
|
|
462
|
-
}
|
|
463
|
-
});
|
|
464
|
-
return headers
|
|
465
|
-
}
|
|
466
|
-
|
|
467
|
-
Body.call(Request.prototype);
|
|
468
|
-
|
|
469
|
-
function Response(bodyInit, options) {
|
|
470
|
-
if (!(this instanceof Response)) {
|
|
471
|
-
throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.')
|
|
472
|
-
}
|
|
473
|
-
if (!options) {
|
|
474
|
-
options = {};
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
this.type = 'default';
|
|
478
|
-
this.status = options.status === undefined ? 200 : options.status;
|
|
479
|
-
if (this.status < 200 || this.status > 599) {
|
|
480
|
-
throw new RangeError("Failed to construct 'Response': The status provided (0) is outside the range [200, 599].")
|
|
481
|
-
}
|
|
482
|
-
this.ok = this.status >= 200 && this.status < 300;
|
|
483
|
-
this.statusText = options.statusText === undefined ? '' : '' + options.statusText;
|
|
484
|
-
this.headers = new Headers(options.headers);
|
|
485
|
-
this.url = options.url || '';
|
|
486
|
-
this._initBody(bodyInit);
|
|
487
|
-
}
|
|
488
|
-
|
|
489
|
-
Body.call(Response.prototype);
|
|
490
|
-
|
|
491
|
-
Response.prototype.clone = function() {
|
|
492
|
-
return new Response(this._bodyInit, {
|
|
493
|
-
status: this.status,
|
|
494
|
-
statusText: this.statusText,
|
|
495
|
-
headers: new Headers(this.headers),
|
|
496
|
-
url: this.url
|
|
497
|
-
})
|
|
498
|
-
};
|
|
499
|
-
|
|
500
|
-
Response.error = function() {
|
|
501
|
-
var response = new Response(null, {status: 200, statusText: ''});
|
|
502
|
-
response.ok = false;
|
|
503
|
-
response.status = 0;
|
|
504
|
-
response.type = 'error';
|
|
505
|
-
return response
|
|
506
|
-
};
|
|
507
|
-
|
|
508
|
-
var redirectStatuses = [301, 302, 303, 307, 308];
|
|
509
|
-
|
|
510
|
-
Response.redirect = function(url, status) {
|
|
511
|
-
if (redirectStatuses.indexOf(status) === -1) {
|
|
512
|
-
throw new RangeError('Invalid status code')
|
|
513
|
-
}
|
|
514
|
-
|
|
515
|
-
return new Response(null, {status: status, headers: {location: url}})
|
|
516
|
-
};
|
|
517
|
-
|
|
518
|
-
var DOMException = g.DOMException;
|
|
519
|
-
try {
|
|
520
|
-
new DOMException();
|
|
521
|
-
} catch (err) {
|
|
522
|
-
DOMException = function(message, name) {
|
|
523
|
-
this.message = message;
|
|
524
|
-
this.name = name;
|
|
525
|
-
var error = Error(message);
|
|
526
|
-
this.stack = error.stack;
|
|
527
|
-
};
|
|
528
|
-
DOMException.prototype = Object.create(Error.prototype);
|
|
529
|
-
DOMException.prototype.constructor = DOMException;
|
|
530
|
-
}
|
|
531
|
-
|
|
532
|
-
function fetch$1(input, init) {
|
|
533
|
-
return new Promise(function(resolve, reject) {
|
|
534
|
-
var request = new Request(input, init);
|
|
535
|
-
|
|
536
|
-
if (request.signal && request.signal.aborted) {
|
|
537
|
-
return reject(new DOMException('Aborted', 'AbortError'))
|
|
538
|
-
}
|
|
539
|
-
|
|
540
|
-
var xhr = new XMLHttpRequest();
|
|
541
|
-
|
|
542
|
-
function abortXhr() {
|
|
543
|
-
xhr.abort();
|
|
544
|
-
}
|
|
545
|
-
|
|
546
|
-
xhr.onload = function() {
|
|
547
|
-
var options = {
|
|
548
|
-
statusText: xhr.statusText,
|
|
549
|
-
headers: parseHeaders(xhr.getAllResponseHeaders() || '')
|
|
550
|
-
};
|
|
551
|
-
// This check if specifically for when a user fetches a file locally from the file system
|
|
552
|
-
// Only if the status is out of a normal range
|
|
553
|
-
if (request.url.indexOf('file://') === 0 && (xhr.status < 200 || xhr.status > 599)) {
|
|
554
|
-
options.status = 200;
|
|
555
|
-
} else {
|
|
556
|
-
options.status = xhr.status;
|
|
557
|
-
}
|
|
558
|
-
options.url = 'responseURL' in xhr ? xhr.responseURL : options.headers.get('X-Request-URL');
|
|
559
|
-
var body = 'response' in xhr ? xhr.response : xhr.responseText;
|
|
560
|
-
setTimeout(function() {
|
|
561
|
-
resolve(new Response(body, options));
|
|
562
|
-
}, 0);
|
|
563
|
-
};
|
|
564
|
-
|
|
565
|
-
xhr.onerror = function() {
|
|
566
|
-
setTimeout(function() {
|
|
567
|
-
reject(new TypeError('Network request failed'));
|
|
568
|
-
}, 0);
|
|
569
|
-
};
|
|
570
|
-
|
|
571
|
-
xhr.ontimeout = function() {
|
|
572
|
-
setTimeout(function() {
|
|
573
|
-
reject(new TypeError('Network request timed out'));
|
|
574
|
-
}, 0);
|
|
575
|
-
};
|
|
576
|
-
|
|
577
|
-
xhr.onabort = function() {
|
|
578
|
-
setTimeout(function() {
|
|
579
|
-
reject(new DOMException('Aborted', 'AbortError'));
|
|
580
|
-
}, 0);
|
|
581
|
-
};
|
|
582
|
-
|
|
583
|
-
function fixUrl(url) {
|
|
584
|
-
try {
|
|
585
|
-
return url === '' && g.location.href ? g.location.href : url
|
|
586
|
-
} catch (e) {
|
|
587
|
-
return url
|
|
588
|
-
}
|
|
589
|
-
}
|
|
590
|
-
|
|
591
|
-
xhr.open(request.method, fixUrl(request.url), true);
|
|
592
|
-
|
|
593
|
-
if (request.credentials === 'include') {
|
|
594
|
-
xhr.withCredentials = true;
|
|
595
|
-
} else if (request.credentials === 'omit') {
|
|
596
|
-
xhr.withCredentials = false;
|
|
597
|
-
}
|
|
598
|
-
|
|
599
|
-
if ('responseType' in xhr) {
|
|
600
|
-
if (support.blob) {
|
|
601
|
-
xhr.responseType = 'blob';
|
|
602
|
-
} else if (
|
|
603
|
-
support.arrayBuffer
|
|
604
|
-
) {
|
|
605
|
-
xhr.responseType = 'arraybuffer';
|
|
606
|
-
}
|
|
607
|
-
}
|
|
608
|
-
|
|
609
|
-
if (init && typeof init.headers === 'object' && !(init.headers instanceof Headers || (g.Headers && init.headers instanceof g.Headers))) {
|
|
610
|
-
var names = [];
|
|
611
|
-
Object.getOwnPropertyNames(init.headers).forEach(function(name) {
|
|
612
|
-
names.push(normalizeName(name));
|
|
613
|
-
xhr.setRequestHeader(name, normalizeValue(init.headers[name]));
|
|
614
|
-
});
|
|
615
|
-
request.headers.forEach(function(value, name) {
|
|
616
|
-
if (names.indexOf(name) === -1) {
|
|
617
|
-
xhr.setRequestHeader(name, value);
|
|
618
|
-
}
|
|
619
|
-
});
|
|
620
|
-
} else {
|
|
621
|
-
request.headers.forEach(function(value, name) {
|
|
622
|
-
xhr.setRequestHeader(name, value);
|
|
623
|
-
});
|
|
624
|
-
}
|
|
625
|
-
|
|
626
|
-
if (request.signal) {
|
|
627
|
-
request.signal.addEventListener('abort', abortXhr);
|
|
628
|
-
|
|
629
|
-
xhr.onreadystatechange = function() {
|
|
630
|
-
// DONE (success or failure)
|
|
631
|
-
if (xhr.readyState === 4) {
|
|
632
|
-
request.signal.removeEventListener('abort', abortXhr);
|
|
633
|
-
}
|
|
634
|
-
};
|
|
635
|
-
}
|
|
636
|
-
|
|
637
|
-
xhr.send(typeof request._bodyInit === 'undefined' ? null : request._bodyInit);
|
|
638
|
-
})
|
|
639
|
-
}
|
|
640
|
-
|
|
641
|
-
fetch$1.polyfill = true;
|
|
642
|
-
|
|
643
|
-
if (!g.fetch) {
|
|
644
|
-
g.fetch = fetch$1;
|
|
645
|
-
g.Headers = Headers;
|
|
646
|
-
g.Request = Request;
|
|
647
|
-
g.Response = Response;
|
|
648
|
-
}
|
|
649
|
-
|
|
650
|
-
/******************************************************************************
|
|
651
|
-
Copyright (c) Microsoft Corporation.
|
|
652
|
-
|
|
653
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
654
|
-
purpose with or without fee is hereby granted.
|
|
655
|
-
|
|
656
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
657
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
658
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
659
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
660
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
661
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
662
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
663
|
-
***************************************************************************** */
|
|
664
|
-
/* global Reflect, Promise */
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
var __assign = function() {
|
|
668
|
-
__assign = Object.assign || function __assign(t) {
|
|
669
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
670
|
-
s = arguments[i];
|
|
671
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
672
|
-
}
|
|
673
|
-
return t;
|
|
674
|
-
};
|
|
675
|
-
return __assign.apply(this, arguments);
|
|
676
|
-
};
|
|
677
|
-
|
|
678
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
|
679
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
680
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
681
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
682
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
683
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
684
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
685
|
-
});
|
|
686
|
-
}
|
|
687
|
-
|
|
688
|
-
function __generator(thisArg, body) {
|
|
689
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
690
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
691
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
692
|
-
function step(op) {
|
|
693
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
694
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
695
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
696
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
697
|
-
switch (op[0]) {
|
|
698
|
-
case 0: case 1: t = op; break;
|
|
699
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
700
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
701
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
702
|
-
default:
|
|
703
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
704
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
705
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
706
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
707
|
-
if (t[2]) _.ops.pop();
|
|
708
|
-
_.trys.pop(); continue;
|
|
709
|
-
}
|
|
710
|
-
op = body.call(thisArg, _);
|
|
711
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
712
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
713
|
-
}
|
|
714
|
-
}
|
|
715
|
-
|
|
716
|
-
function __values(o) {
|
|
717
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
718
|
-
if (m) return m.call(o);
|
|
719
|
-
if (o && typeof o.length === "number") return {
|
|
720
|
-
next: function () {
|
|
721
|
-
if (o && i >= o.length) o = void 0;
|
|
722
|
-
return { value: o && o[i++], done: !o };
|
|
723
|
-
}
|
|
724
|
-
};
|
|
725
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
726
|
-
}
|
|
727
|
-
|
|
728
|
-
function __read(o, n) {
|
|
729
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
730
|
-
if (!m) return o;
|
|
731
|
-
var i = m.call(o), r, ar = [], e;
|
|
732
|
-
try {
|
|
733
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
734
|
-
}
|
|
735
|
-
catch (error) { e = { error: error }; }
|
|
736
|
-
finally {
|
|
737
|
-
try {
|
|
738
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
739
|
-
}
|
|
740
|
-
finally { if (e) throw e.error; }
|
|
741
|
-
}
|
|
742
|
-
return ar;
|
|
743
|
-
}
|
|
744
|
-
|
|
745
|
-
/**
|
|
746
|
-
* base64.ts
|
|
747
|
-
*
|
|
748
|
-
* Licensed under the BSD 3-Clause License.
|
|
749
|
-
* http://opensource.org/licenses/BSD-3-Clause
|
|
750
|
-
*
|
|
751
|
-
* References:
|
|
752
|
-
* http://en.wikipedia.org/wiki/Base64
|
|
753
|
-
*
|
|
754
|
-
* @author Dan Kogai (https://github.com/dankogai)
|
|
755
|
-
*/
|
|
756
|
-
const _hasatob = typeof atob === 'function';
|
|
757
|
-
const _hasbtoa = typeof btoa === 'function';
|
|
758
|
-
const _hasBuffer = typeof Buffer === 'function';
|
|
759
|
-
typeof TextDecoder === 'function' ? new TextDecoder() : undefined;
|
|
760
|
-
const _TE = typeof TextEncoder === 'function' ? new TextEncoder() : undefined;
|
|
761
|
-
const b64ch = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
|
|
762
|
-
const b64chs = Array.prototype.slice.call(b64ch);
|
|
763
|
-
const b64tab = ((a) => {
|
|
764
|
-
let tab = {};
|
|
765
|
-
a.forEach((c, i) => tab[c] = i);
|
|
766
|
-
return tab;
|
|
767
|
-
})(b64chs);
|
|
768
|
-
const b64re = /^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/;
|
|
769
|
-
const _fromCC = String.fromCharCode.bind(String);
|
|
770
|
-
typeof Uint8Array.from === 'function'
|
|
771
|
-
? Uint8Array.from.bind(Uint8Array)
|
|
772
|
-
: (it, fn = (x) => x) => new Uint8Array(Array.prototype.slice.call(it, 0).map(fn));
|
|
773
|
-
const _mkUriSafe = (src) => src
|
|
774
|
-
.replace(/=/g, '').replace(/[+\/]/g, (m0) => m0 == '+' ? '-' : '_');
|
|
775
|
-
const _tidyB64 = (s) => s.replace(/[^A-Za-z0-9\+\/]/g, '');
|
|
776
|
-
/**
|
|
777
|
-
* polyfill version of `btoa`
|
|
778
|
-
*/
|
|
779
|
-
const btoaPolyfill = (bin) => {
|
|
780
|
-
// console.log('polyfilled');
|
|
781
|
-
let u32, c0, c1, c2, asc = '';
|
|
782
|
-
const pad = bin.length % 3;
|
|
783
|
-
for (let i = 0; i < bin.length;) {
|
|
784
|
-
if ((c0 = bin.charCodeAt(i++)) > 255 ||
|
|
785
|
-
(c1 = bin.charCodeAt(i++)) > 255 ||
|
|
786
|
-
(c2 = bin.charCodeAt(i++)) > 255)
|
|
787
|
-
throw new TypeError('invalid character found');
|
|
788
|
-
u32 = (c0 << 16) | (c1 << 8) | c2;
|
|
789
|
-
asc += b64chs[u32 >> 18 & 63]
|
|
790
|
-
+ b64chs[u32 >> 12 & 63]
|
|
791
|
-
+ b64chs[u32 >> 6 & 63]
|
|
792
|
-
+ b64chs[u32 & 63];
|
|
793
|
-
}
|
|
794
|
-
return pad ? asc.slice(0, pad - 3) + "===".substring(pad) : asc;
|
|
795
|
-
};
|
|
796
|
-
/**
|
|
797
|
-
* does what `window.btoa` of web browsers do.
|
|
798
|
-
* @param {String} bin binary string
|
|
799
|
-
* @returns {string} Base64-encoded string
|
|
800
|
-
*/
|
|
801
|
-
const _btoa = _hasbtoa ? (bin) => btoa(bin)
|
|
802
|
-
: _hasBuffer ? (bin) => Buffer.from(bin, 'binary').toString('base64')
|
|
803
|
-
: btoaPolyfill;
|
|
804
|
-
const _fromUint8Array = _hasBuffer
|
|
805
|
-
? (u8a) => Buffer.from(u8a).toString('base64')
|
|
806
|
-
: (u8a) => {
|
|
807
|
-
// cf. https://stackoverflow.com/questions/12710001/how-to-convert-uint8-array-to-base64-encoded-string/12713326#12713326
|
|
808
|
-
const maxargs = 0x1000;
|
|
809
|
-
let strs = [];
|
|
810
|
-
for (let i = 0, l = u8a.length; i < l; i += maxargs) {
|
|
811
|
-
strs.push(_fromCC.apply(null, u8a.subarray(i, i + maxargs)));
|
|
812
|
-
}
|
|
813
|
-
return _btoa(strs.join(''));
|
|
814
|
-
};
|
|
815
|
-
// This trick is found broken https://github.com/dankogai/js-base64/issues/130
|
|
816
|
-
// const utob = (src: string) => unescape(encodeURIComponent(src));
|
|
817
|
-
// reverting good old fationed regexp
|
|
818
|
-
const cb_utob = (c) => {
|
|
819
|
-
if (c.length < 2) {
|
|
820
|
-
var cc = c.charCodeAt(0);
|
|
821
|
-
return cc < 0x80 ? c
|
|
822
|
-
: cc < 0x800 ? (_fromCC(0xc0 | (cc >>> 6))
|
|
823
|
-
+ _fromCC(0x80 | (cc & 0x3f)))
|
|
824
|
-
: (_fromCC(0xe0 | ((cc >>> 12) & 0x0f))
|
|
825
|
-
+ _fromCC(0x80 | ((cc >>> 6) & 0x3f))
|
|
826
|
-
+ _fromCC(0x80 | (cc & 0x3f)));
|
|
827
|
-
}
|
|
828
|
-
else {
|
|
829
|
-
var cc = 0x10000
|
|
830
|
-
+ (c.charCodeAt(0) - 0xD800) * 0x400
|
|
831
|
-
+ (c.charCodeAt(1) - 0xDC00);
|
|
832
|
-
return (_fromCC(0xf0 | ((cc >>> 18) & 0x07))
|
|
833
|
-
+ _fromCC(0x80 | ((cc >>> 12) & 0x3f))
|
|
834
|
-
+ _fromCC(0x80 | ((cc >>> 6) & 0x3f))
|
|
835
|
-
+ _fromCC(0x80 | (cc & 0x3f)));
|
|
836
|
-
}
|
|
837
|
-
};
|
|
838
|
-
const re_utob = /[\uD800-\uDBFF][\uDC00-\uDFFFF]|[^\x00-\x7F]/g;
|
|
839
|
-
/**
|
|
840
|
-
* @deprecated should have been internal use only.
|
|
841
|
-
* @param {string} src UTF-8 string
|
|
842
|
-
* @returns {string} UTF-16 string
|
|
843
|
-
*/
|
|
844
|
-
const utob = (u) => u.replace(re_utob, cb_utob);
|
|
845
|
-
//
|
|
846
|
-
const _encode = _hasBuffer
|
|
847
|
-
? (s) => Buffer.from(s, 'utf8').toString('base64')
|
|
848
|
-
: _TE
|
|
849
|
-
? (s) => _fromUint8Array(_TE.encode(s))
|
|
850
|
-
: (s) => _btoa(utob(s));
|
|
851
|
-
/**
|
|
852
|
-
* converts a UTF-8-encoded string to a Base64 string.
|
|
853
|
-
* @param {boolean} [urlsafe] if `true` make the result URL-safe
|
|
854
|
-
* @returns {string} Base64 string
|
|
855
|
-
*/
|
|
856
|
-
const encode = (src, urlsafe = false) => urlsafe
|
|
857
|
-
? _mkUriSafe(_encode(src))
|
|
858
|
-
: _encode(src);
|
|
859
|
-
/**
|
|
860
|
-
* polyfill version of `atob`
|
|
861
|
-
*/
|
|
862
|
-
const atobPolyfill = (asc) => {
|
|
863
|
-
// console.log('polyfilled');
|
|
864
|
-
asc = asc.replace(/\s+/g, '');
|
|
865
|
-
if (!b64re.test(asc))
|
|
866
|
-
throw new TypeError('malformed base64.');
|
|
867
|
-
asc += '=='.slice(2 - (asc.length & 3));
|
|
868
|
-
let u24, bin = '', r1, r2;
|
|
869
|
-
for (let i = 0; i < asc.length;) {
|
|
870
|
-
u24 = b64tab[asc.charAt(i++)] << 18
|
|
871
|
-
| b64tab[asc.charAt(i++)] << 12
|
|
872
|
-
| (r1 = b64tab[asc.charAt(i++)]) << 6
|
|
873
|
-
| (r2 = b64tab[asc.charAt(i++)]);
|
|
874
|
-
bin += r1 === 64 ? _fromCC(u24 >> 16 & 255)
|
|
875
|
-
: r2 === 64 ? _fromCC(u24 >> 16 & 255, u24 >> 8 & 255)
|
|
876
|
-
: _fromCC(u24 >> 16 & 255, u24 >> 8 & 255, u24 & 255);
|
|
877
|
-
}
|
|
878
|
-
return bin;
|
|
879
|
-
};
|
|
880
|
-
/**
|
|
881
|
-
* does what `window.atob` of web browsers do.
|
|
882
|
-
* @param {String} asc Base64-encoded string
|
|
883
|
-
* @returns {string} binary string
|
|
884
|
-
*/
|
|
885
|
-
const _atob = _hasatob ? (asc) => atob(_tidyB64(asc))
|
|
886
|
-
: _hasBuffer ? (asc) => Buffer.from(asc, 'base64').toString('binary')
|
|
887
|
-
: atobPolyfill;
|
|
888
|
-
|
|
889
|
-
function buildFetchOptions(method, options, bodyJson) {
|
|
890
|
-
var fetchOptions = __assign({ method: method }, options);
|
|
891
|
-
fetchOptions.headers = __assign({}, options.headers);
|
|
892
|
-
var descriptor = Object.getOwnPropertyDescriptor(XMLHttpRequest.prototype, "withCredentials");
|
|
893
|
-
// in Cocos Creator, XMLHttpRequest.withCredentials is not writable, so make the fetch
|
|
894
|
-
// polyfill avoid writing to it.
|
|
895
|
-
if (!(descriptor === null || descriptor === void 0 ? void 0 : descriptor.set)) {
|
|
896
|
-
fetchOptions.credentials = 'cocos-ignore'; // string value is arbitrary, cannot be 'omit' or 'include
|
|
897
|
-
}
|
|
898
|
-
if (!Object.keys(fetchOptions.headers).includes("Accept")) {
|
|
899
|
-
fetchOptions.headers["Accept"] = "application/json";
|
|
900
|
-
}
|
|
901
|
-
if (!Object.keys(fetchOptions.headers).includes("Content-Type")) {
|
|
902
|
-
fetchOptions.headers["Content-Type"] = "application/json";
|
|
903
|
-
}
|
|
904
|
-
Object.keys(fetchOptions.headers).forEach(function (key) {
|
|
905
|
-
if (!fetchOptions.headers[key]) {
|
|
906
|
-
delete fetchOptions.headers[key];
|
|
907
|
-
}
|
|
908
|
-
});
|
|
909
|
-
if (bodyJson) {
|
|
910
|
-
fetchOptions.body = bodyJson;
|
|
911
|
-
}
|
|
912
|
-
return fetchOptions;
|
|
913
|
-
}
|
|
914
|
-
|
|
915
|
-
// tslint:disable
|
|
916
|
-
/* Code generated by openapi-gen/main.go. DO NOT EDIT. */
|
|
917
|
-
var SatoriApi = /** @class */ (function () {
|
|
918
|
-
function SatoriApi(apiKey, basePath, timeoutMs) {
|
|
919
|
-
this.apiKey = apiKey;
|
|
920
|
-
this.basePath = basePath;
|
|
921
|
-
this.timeoutMs = timeoutMs;
|
|
922
|
-
}
|
|
923
|
-
/** A healthcheck which load balancers can use to check the service. */
|
|
924
|
-
SatoriApi.prototype.satoriHealthcheck = function (bearerToken, options) {
|
|
925
|
-
var _this = this;
|
|
926
|
-
if (options === void 0) { options = {}; }
|
|
927
|
-
var urlPath = "/healthcheck";
|
|
928
|
-
var queryParams = new Map();
|
|
929
|
-
var bodyJson = "";
|
|
930
|
-
var fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
|
|
931
|
-
var fetchOptions = buildFetchOptions("GET", options, bodyJson);
|
|
932
|
-
if (bearerToken) {
|
|
933
|
-
fetchOptions.headers["Authorization"] = "Bearer " + bearerToken;
|
|
934
|
-
}
|
|
935
|
-
return Promise.race([
|
|
936
|
-
fetch(fullUrl, fetchOptions).then(function (response) {
|
|
937
|
-
if (response.status == 204) {
|
|
938
|
-
return response;
|
|
939
|
-
}
|
|
940
|
-
else if (response.status >= 200 && response.status < 300) {
|
|
941
|
-
return response.json();
|
|
942
|
-
}
|
|
943
|
-
else {
|
|
944
|
-
throw response;
|
|
945
|
-
}
|
|
946
|
-
}),
|
|
947
|
-
new Promise(function (_, reject) {
|
|
948
|
-
return setTimeout(reject, _this.timeoutMs, "Request timed out.");
|
|
949
|
-
}),
|
|
950
|
-
]);
|
|
951
|
-
};
|
|
952
|
-
/** A readycheck which load balancers can use to check the service. */
|
|
953
|
-
SatoriApi.prototype.satoriReadycheck = function (bearerToken, options) {
|
|
954
|
-
var _this = this;
|
|
955
|
-
if (options === void 0) { options = {}; }
|
|
956
|
-
var urlPath = "/readycheck";
|
|
957
|
-
var queryParams = new Map();
|
|
958
|
-
var bodyJson = "";
|
|
959
|
-
var fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
|
|
960
|
-
var fetchOptions = buildFetchOptions("GET", options, bodyJson);
|
|
961
|
-
if (bearerToken) {
|
|
962
|
-
fetchOptions.headers["Authorization"] = "Bearer " + bearerToken;
|
|
963
|
-
}
|
|
964
|
-
return Promise.race([
|
|
965
|
-
fetch(fullUrl, fetchOptions).then(function (response) {
|
|
966
|
-
if (response.status == 204) {
|
|
967
|
-
return response;
|
|
968
|
-
}
|
|
969
|
-
else if (response.status >= 200 && response.status < 300) {
|
|
970
|
-
return response.json();
|
|
971
|
-
}
|
|
972
|
-
else {
|
|
973
|
-
throw response;
|
|
974
|
-
}
|
|
975
|
-
}),
|
|
976
|
-
new Promise(function (_, reject) {
|
|
977
|
-
return setTimeout(reject, _this.timeoutMs, "Request timed out.");
|
|
978
|
-
}),
|
|
979
|
-
]);
|
|
980
|
-
};
|
|
981
|
-
/** Authenticate against the server. */
|
|
982
|
-
SatoriApi.prototype.satoriAuthenticate = function (basicAuthUsername, basicAuthPassword, body, options) {
|
|
983
|
-
var _this = this;
|
|
984
|
-
if (options === void 0) { options = {}; }
|
|
985
|
-
if (body === null || body === undefined) {
|
|
986
|
-
throw new Error("'body' is a required parameter but is null or undefined.");
|
|
987
|
-
}
|
|
988
|
-
var urlPath = "/v1/authenticate";
|
|
989
|
-
var queryParams = new Map();
|
|
990
|
-
var bodyJson = "";
|
|
991
|
-
bodyJson = JSON.stringify(body || {});
|
|
992
|
-
var fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
|
|
993
|
-
var fetchOptions = buildFetchOptions("POST", options, bodyJson);
|
|
994
|
-
if (basicAuthUsername) {
|
|
995
|
-
fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword);
|
|
996
|
-
}
|
|
997
|
-
return Promise.race([
|
|
998
|
-
fetch(fullUrl, fetchOptions).then(function (response) {
|
|
999
|
-
if (response.status == 204) {
|
|
1000
|
-
return response;
|
|
1001
|
-
}
|
|
1002
|
-
else if (response.status >= 200 && response.status < 300) {
|
|
1003
|
-
return response.json();
|
|
1004
|
-
}
|
|
1005
|
-
else {
|
|
1006
|
-
throw response;
|
|
1007
|
-
}
|
|
1008
|
-
}),
|
|
1009
|
-
new Promise(function (_, reject) {
|
|
1010
|
-
return setTimeout(reject, _this.timeoutMs, "Request timed out.");
|
|
1011
|
-
}),
|
|
1012
|
-
]);
|
|
1013
|
-
};
|
|
1014
|
-
/** Log out a session, invalidate a refresh token, or log out all sessions/refresh tokens for a user. */
|
|
1015
|
-
SatoriApi.prototype.satoriAuthenticateLogout = function (bearerToken, body, options) {
|
|
1016
|
-
var _this = this;
|
|
1017
|
-
if (options === void 0) { options = {}; }
|
|
1018
|
-
if (body === null || body === undefined) {
|
|
1019
|
-
throw new Error("'body' is a required parameter but is null or undefined.");
|
|
1020
|
-
}
|
|
1021
|
-
var urlPath = "/v1/authenticate/logout";
|
|
1022
|
-
var queryParams = new Map();
|
|
1023
|
-
var bodyJson = "";
|
|
1024
|
-
bodyJson = JSON.stringify(body || {});
|
|
1025
|
-
var fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
|
|
1026
|
-
var fetchOptions = buildFetchOptions("POST", options, bodyJson);
|
|
1027
|
-
if (bearerToken) {
|
|
1028
|
-
fetchOptions.headers["Authorization"] = "Bearer " + bearerToken;
|
|
1029
|
-
}
|
|
1030
|
-
return Promise.race([
|
|
1031
|
-
fetch(fullUrl, fetchOptions).then(function (response) {
|
|
1032
|
-
if (response.status == 204) {
|
|
1033
|
-
return response;
|
|
1034
|
-
}
|
|
1035
|
-
else if (response.status >= 200 && response.status < 300) {
|
|
1036
|
-
return response.json();
|
|
1037
|
-
}
|
|
1038
|
-
else {
|
|
1039
|
-
throw response;
|
|
1040
|
-
}
|
|
1041
|
-
}),
|
|
1042
|
-
new Promise(function (_, reject) {
|
|
1043
|
-
return setTimeout(reject, _this.timeoutMs, "Request timed out.");
|
|
1044
|
-
}),
|
|
1045
|
-
]);
|
|
1046
|
-
};
|
|
1047
|
-
/** Refresh a user's session using a refresh token retrieved from a previous authentication request. */
|
|
1048
|
-
SatoriApi.prototype.satoriAuthenticateRefresh = function (basicAuthUsername, basicAuthPassword, body, options) {
|
|
1049
|
-
var _this = this;
|
|
1050
|
-
if (options === void 0) { options = {}; }
|
|
1051
|
-
if (body === null || body === undefined) {
|
|
1052
|
-
throw new Error("'body' is a required parameter but is null or undefined.");
|
|
1053
|
-
}
|
|
1054
|
-
var urlPath = "/v1/authenticate/refresh";
|
|
1055
|
-
var queryParams = new Map();
|
|
1056
|
-
var bodyJson = "";
|
|
1057
|
-
bodyJson = JSON.stringify(body || {});
|
|
1058
|
-
var fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
|
|
1059
|
-
var fetchOptions = buildFetchOptions("POST", options, bodyJson);
|
|
1060
|
-
if (basicAuthUsername) {
|
|
1061
|
-
fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword);
|
|
1062
|
-
}
|
|
1063
|
-
return Promise.race([
|
|
1064
|
-
fetch(fullUrl, fetchOptions).then(function (response) {
|
|
1065
|
-
if (response.status == 204) {
|
|
1066
|
-
return response;
|
|
1067
|
-
}
|
|
1068
|
-
else if (response.status >= 200 && response.status < 300) {
|
|
1069
|
-
return response.json();
|
|
1070
|
-
}
|
|
1071
|
-
else {
|
|
1072
|
-
throw response;
|
|
1073
|
-
}
|
|
1074
|
-
}),
|
|
1075
|
-
new Promise(function (_, reject) {
|
|
1076
|
-
return setTimeout(reject, _this.timeoutMs, "Request timed out.");
|
|
1077
|
-
}),
|
|
1078
|
-
]);
|
|
1079
|
-
};
|
|
1080
|
-
/** Publish an event for this session. */
|
|
1081
|
-
SatoriApi.prototype.satoriEvent = function (bearerToken, body, options) {
|
|
1082
|
-
var _this = this;
|
|
1083
|
-
if (options === void 0) { options = {}; }
|
|
1084
|
-
if (body === null || body === undefined) {
|
|
1085
|
-
throw new Error("'body' is a required parameter but is null or undefined.");
|
|
1086
|
-
}
|
|
1087
|
-
var urlPath = "/v1/event";
|
|
1088
|
-
var queryParams = new Map();
|
|
1089
|
-
var bodyJson = "";
|
|
1090
|
-
bodyJson = JSON.stringify(body || {});
|
|
1091
|
-
var fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
|
|
1092
|
-
var fetchOptions = buildFetchOptions("POST", options, bodyJson);
|
|
1093
|
-
if (bearerToken) {
|
|
1094
|
-
fetchOptions.headers["Authorization"] = "Bearer " + bearerToken;
|
|
1095
|
-
}
|
|
1096
|
-
return Promise.race([
|
|
1097
|
-
fetch(fullUrl, fetchOptions).then(function (response) {
|
|
1098
|
-
if (response.status == 204) {
|
|
1099
|
-
return response;
|
|
1100
|
-
}
|
|
1101
|
-
else if (response.status >= 200 && response.status < 300) {
|
|
1102
|
-
return response.json();
|
|
1103
|
-
}
|
|
1104
|
-
else {
|
|
1105
|
-
throw response;
|
|
1106
|
-
}
|
|
1107
|
-
}),
|
|
1108
|
-
new Promise(function (_, reject) {
|
|
1109
|
-
return setTimeout(reject, _this.timeoutMs, "Request timed out.");
|
|
1110
|
-
}),
|
|
1111
|
-
]);
|
|
1112
|
-
};
|
|
1113
|
-
/** Get or list all available experiments for this identity. */
|
|
1114
|
-
SatoriApi.prototype.satoriGetExperiments = function (bearerToken, names, options) {
|
|
1115
|
-
var _this = this;
|
|
1116
|
-
if (options === void 0) { options = {}; }
|
|
1117
|
-
var urlPath = "/v1/experiment";
|
|
1118
|
-
var queryParams = new Map();
|
|
1119
|
-
queryParams.set("names", names);
|
|
1120
|
-
var bodyJson = "";
|
|
1121
|
-
var fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
|
|
1122
|
-
var fetchOptions = buildFetchOptions("GET", options, bodyJson);
|
|
1123
|
-
if (bearerToken) {
|
|
1124
|
-
fetchOptions.headers["Authorization"] = "Bearer " + bearerToken;
|
|
1125
|
-
}
|
|
1126
|
-
return Promise.race([
|
|
1127
|
-
fetch(fullUrl, fetchOptions).then(function (response) {
|
|
1128
|
-
if (response.status == 204) {
|
|
1129
|
-
return response;
|
|
1130
|
-
}
|
|
1131
|
-
else if (response.status >= 200 && response.status < 300) {
|
|
1132
|
-
return response.json();
|
|
1133
|
-
}
|
|
1134
|
-
else {
|
|
1135
|
-
throw response;
|
|
1136
|
-
}
|
|
1137
|
-
}),
|
|
1138
|
-
new Promise(function (_, reject) {
|
|
1139
|
-
return setTimeout(reject, _this.timeoutMs, "Request timed out.");
|
|
1140
|
-
}),
|
|
1141
|
-
]);
|
|
1142
|
-
};
|
|
1143
|
-
/** List all available flags for this identity. */
|
|
1144
|
-
SatoriApi.prototype.satoriGetFlags = function (bearerToken, basicAuthUsername, basicAuthPassword, names, options) {
|
|
1145
|
-
var _this = this;
|
|
1146
|
-
if (options === void 0) { options = {}; }
|
|
1147
|
-
var urlPath = "/v1/flag";
|
|
1148
|
-
var queryParams = new Map();
|
|
1149
|
-
queryParams.set("names", names);
|
|
1150
|
-
var bodyJson = "";
|
|
1151
|
-
var fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
|
|
1152
|
-
var fetchOptions = buildFetchOptions("GET", options, bodyJson);
|
|
1153
|
-
if (bearerToken) {
|
|
1154
|
-
fetchOptions.headers["Authorization"] = "Bearer " + bearerToken;
|
|
1155
|
-
}
|
|
1156
|
-
if (basicAuthUsername) {
|
|
1157
|
-
fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword);
|
|
1158
|
-
}
|
|
1159
|
-
return Promise.race([
|
|
1160
|
-
fetch(fullUrl, fetchOptions).then(function (response) {
|
|
1161
|
-
if (response.status == 204) {
|
|
1162
|
-
return response;
|
|
1163
|
-
}
|
|
1164
|
-
else if (response.status >= 200 && response.status < 300) {
|
|
1165
|
-
return response.json();
|
|
1166
|
-
}
|
|
1167
|
-
else {
|
|
1168
|
-
throw response;
|
|
1169
|
-
}
|
|
1170
|
-
}),
|
|
1171
|
-
new Promise(function (_, reject) {
|
|
1172
|
-
return setTimeout(reject, _this.timeoutMs, "Request timed out.");
|
|
1173
|
-
}),
|
|
1174
|
-
]);
|
|
1175
|
-
};
|
|
1176
|
-
/** Enrich/replace the current session with new identifier. */
|
|
1177
|
-
SatoriApi.prototype.satoriIdentify = function (bearerToken, body, options) {
|
|
1178
|
-
var _this = this;
|
|
1179
|
-
if (options === void 0) { options = {}; }
|
|
1180
|
-
if (body === null || body === undefined) {
|
|
1181
|
-
throw new Error("'body' is a required parameter but is null or undefined.");
|
|
1182
|
-
}
|
|
1183
|
-
var urlPath = "/v1/identify";
|
|
1184
|
-
var queryParams = new Map();
|
|
1185
|
-
var bodyJson = "";
|
|
1186
|
-
bodyJson = JSON.stringify(body || {});
|
|
1187
|
-
var fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
|
|
1188
|
-
var fetchOptions = buildFetchOptions("PUT", options, bodyJson);
|
|
1189
|
-
if (bearerToken) {
|
|
1190
|
-
fetchOptions.headers["Authorization"] = "Bearer " + bearerToken;
|
|
1191
|
-
}
|
|
1192
|
-
return Promise.race([
|
|
1193
|
-
fetch(fullUrl, fetchOptions).then(function (response) {
|
|
1194
|
-
if (response.status == 204) {
|
|
1195
|
-
return response;
|
|
1196
|
-
}
|
|
1197
|
-
else if (response.status >= 200 && response.status < 300) {
|
|
1198
|
-
return response.json();
|
|
1199
|
-
}
|
|
1200
|
-
else {
|
|
1201
|
-
throw response;
|
|
1202
|
-
}
|
|
1203
|
-
}),
|
|
1204
|
-
new Promise(function (_, reject) {
|
|
1205
|
-
return setTimeout(reject, _this.timeoutMs, "Request timed out.");
|
|
1206
|
-
}),
|
|
1207
|
-
]);
|
|
1208
|
-
};
|
|
1209
|
-
/** Delete the caller's identity and associated data. */
|
|
1210
|
-
SatoriApi.prototype.satoriDeleteIdentity = function (bearerToken, options) {
|
|
1211
|
-
var _this = this;
|
|
1212
|
-
if (options === void 0) { options = {}; }
|
|
1213
|
-
var urlPath = "/v1/identity";
|
|
1214
|
-
var queryParams = new Map();
|
|
1215
|
-
var bodyJson = "";
|
|
1216
|
-
var fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
|
|
1217
|
-
var fetchOptions = buildFetchOptions("DELETE", options, bodyJson);
|
|
1218
|
-
if (bearerToken) {
|
|
1219
|
-
fetchOptions.headers["Authorization"] = "Bearer " + bearerToken;
|
|
1220
|
-
}
|
|
1221
|
-
return Promise.race([
|
|
1222
|
-
fetch(fullUrl, fetchOptions).then(function (response) {
|
|
1223
|
-
if (response.status == 204) {
|
|
1224
|
-
return response;
|
|
1225
|
-
}
|
|
1226
|
-
else if (response.status >= 200 && response.status < 300) {
|
|
1227
|
-
return response.json();
|
|
1228
|
-
}
|
|
1229
|
-
else {
|
|
1230
|
-
throw response;
|
|
1231
|
-
}
|
|
1232
|
-
}),
|
|
1233
|
-
new Promise(function (_, reject) {
|
|
1234
|
-
return setTimeout(reject, _this.timeoutMs, "Request timed out.");
|
|
1235
|
-
}),
|
|
1236
|
-
]);
|
|
1237
|
-
};
|
|
1238
|
-
/** List available live events. */
|
|
1239
|
-
SatoriApi.prototype.satoriGetLiveEvents = function (bearerToken, names, options) {
|
|
1240
|
-
var _this = this;
|
|
1241
|
-
if (options === void 0) { options = {}; }
|
|
1242
|
-
var urlPath = "/v1/live-event";
|
|
1243
|
-
var queryParams = new Map();
|
|
1244
|
-
queryParams.set("names", names);
|
|
1245
|
-
var bodyJson = "";
|
|
1246
|
-
var fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
|
|
1247
|
-
var fetchOptions = buildFetchOptions("GET", options, bodyJson);
|
|
1248
|
-
if (bearerToken) {
|
|
1249
|
-
fetchOptions.headers["Authorization"] = "Bearer " + bearerToken;
|
|
1250
|
-
}
|
|
1251
|
-
return Promise.race([
|
|
1252
|
-
fetch(fullUrl, fetchOptions).then(function (response) {
|
|
1253
|
-
if (response.status == 204) {
|
|
1254
|
-
return response;
|
|
1255
|
-
}
|
|
1256
|
-
else if (response.status >= 200 && response.status < 300) {
|
|
1257
|
-
return response.json();
|
|
1258
|
-
}
|
|
1259
|
-
else {
|
|
1260
|
-
throw response;
|
|
1261
|
-
}
|
|
1262
|
-
}),
|
|
1263
|
-
new Promise(function (_, reject) {
|
|
1264
|
-
return setTimeout(reject, _this.timeoutMs, "Request timed out.");
|
|
1265
|
-
}),
|
|
1266
|
-
]);
|
|
1267
|
-
};
|
|
1268
|
-
/** Get the list of messages for the identity. */
|
|
1269
|
-
SatoriApi.prototype.satoriGetMessageList = function (bearerToken, limit, forward, cursor, options) {
|
|
1270
|
-
var _this = this;
|
|
1271
|
-
if (options === void 0) { options = {}; }
|
|
1272
|
-
var urlPath = "/v1/message";
|
|
1273
|
-
var queryParams = new Map();
|
|
1274
|
-
queryParams.set("limit", limit);
|
|
1275
|
-
queryParams.set("forward", forward);
|
|
1276
|
-
queryParams.set("cursor", cursor);
|
|
1277
|
-
var bodyJson = "";
|
|
1278
|
-
var fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
|
|
1279
|
-
var fetchOptions = buildFetchOptions("GET", options, bodyJson);
|
|
1280
|
-
if (bearerToken) {
|
|
1281
|
-
fetchOptions.headers["Authorization"] = "Bearer " + bearerToken;
|
|
1282
|
-
}
|
|
1283
|
-
return Promise.race([
|
|
1284
|
-
fetch(fullUrl, fetchOptions).then(function (response) {
|
|
1285
|
-
if (response.status == 204) {
|
|
1286
|
-
return response;
|
|
1287
|
-
}
|
|
1288
|
-
else if (response.status >= 200 && response.status < 300) {
|
|
1289
|
-
return response.json();
|
|
1290
|
-
}
|
|
1291
|
-
else {
|
|
1292
|
-
throw response;
|
|
1293
|
-
}
|
|
1294
|
-
}),
|
|
1295
|
-
new Promise(function (_, reject) {
|
|
1296
|
-
return setTimeout(reject, _this.timeoutMs, "Request timed out.");
|
|
1297
|
-
}),
|
|
1298
|
-
]);
|
|
1299
|
-
};
|
|
1300
|
-
/** Deletes a message for an identity. */
|
|
1301
|
-
SatoriApi.prototype.satoriDeleteMessage = function (bearerToken, id, options) {
|
|
1302
|
-
var _this = this;
|
|
1303
|
-
if (options === void 0) { options = {}; }
|
|
1304
|
-
if (id === null || id === undefined) {
|
|
1305
|
-
throw new Error("'id' is a required parameter but is null or undefined.");
|
|
1306
|
-
}
|
|
1307
|
-
var urlPath = "/v1/message/{id}"
|
|
1308
|
-
.replace("{id}", encodeURIComponent(String(id)));
|
|
1309
|
-
var queryParams = new Map();
|
|
1310
|
-
var bodyJson = "";
|
|
1311
|
-
var fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
|
|
1312
|
-
var fetchOptions = buildFetchOptions("DELETE", options, bodyJson);
|
|
1313
|
-
if (bearerToken) {
|
|
1314
|
-
fetchOptions.headers["Authorization"] = "Bearer " + bearerToken;
|
|
1315
|
-
}
|
|
1316
|
-
return Promise.race([
|
|
1317
|
-
fetch(fullUrl, fetchOptions).then(function (response) {
|
|
1318
|
-
if (response.status == 204) {
|
|
1319
|
-
return response;
|
|
1320
|
-
}
|
|
1321
|
-
else if (response.status >= 200 && response.status < 300) {
|
|
1322
|
-
return response.json();
|
|
1323
|
-
}
|
|
1324
|
-
else {
|
|
1325
|
-
throw response;
|
|
1326
|
-
}
|
|
1327
|
-
}),
|
|
1328
|
-
new Promise(function (_, reject) {
|
|
1329
|
-
return setTimeout(reject, _this.timeoutMs, "Request timed out.");
|
|
1330
|
-
}),
|
|
1331
|
-
]);
|
|
1332
|
-
};
|
|
1333
|
-
/** Updates a message for an identity. */
|
|
1334
|
-
SatoriApi.prototype.satoriUpdateMessage = function (bearerToken, id, body, options) {
|
|
1335
|
-
var _this = this;
|
|
1336
|
-
if (options === void 0) { options = {}; }
|
|
1337
|
-
if (id === null || id === undefined) {
|
|
1338
|
-
throw new Error("'id' is a required parameter but is null or undefined.");
|
|
1339
|
-
}
|
|
1340
|
-
if (body === null || body === undefined) {
|
|
1341
|
-
throw new Error("'body' is a required parameter but is null or undefined.");
|
|
1342
|
-
}
|
|
1343
|
-
var urlPath = "/v1/message/{id}"
|
|
1344
|
-
.replace("{id}", encodeURIComponent(String(id)));
|
|
1345
|
-
var queryParams = new Map();
|
|
1346
|
-
var bodyJson = "";
|
|
1347
|
-
bodyJson = JSON.stringify(body || {});
|
|
1348
|
-
var fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
|
|
1349
|
-
var fetchOptions = buildFetchOptions("PUT", options, bodyJson);
|
|
1350
|
-
if (bearerToken) {
|
|
1351
|
-
fetchOptions.headers["Authorization"] = "Bearer " + bearerToken;
|
|
1352
|
-
}
|
|
1353
|
-
return Promise.race([
|
|
1354
|
-
fetch(fullUrl, fetchOptions).then(function (response) {
|
|
1355
|
-
if (response.status == 204) {
|
|
1356
|
-
return response;
|
|
1357
|
-
}
|
|
1358
|
-
else if (response.status >= 200 && response.status < 300) {
|
|
1359
|
-
return response.json();
|
|
1360
|
-
}
|
|
1361
|
-
else {
|
|
1362
|
-
throw response;
|
|
1363
|
-
}
|
|
1364
|
-
}),
|
|
1365
|
-
new Promise(function (_, reject) {
|
|
1366
|
-
return setTimeout(reject, _this.timeoutMs, "Request timed out.");
|
|
1367
|
-
}),
|
|
1368
|
-
]);
|
|
1369
|
-
};
|
|
1370
|
-
/** List properties associated with this identity. */
|
|
1371
|
-
SatoriApi.prototype.satoriListProperties = function (bearerToken, options) {
|
|
1372
|
-
var _this = this;
|
|
1373
|
-
if (options === void 0) { options = {}; }
|
|
1374
|
-
var urlPath = "/v1/properties";
|
|
1375
|
-
var queryParams = new Map();
|
|
1376
|
-
var bodyJson = "";
|
|
1377
|
-
var fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
|
|
1378
|
-
var fetchOptions = buildFetchOptions("GET", options, bodyJson);
|
|
1379
|
-
if (bearerToken) {
|
|
1380
|
-
fetchOptions.headers["Authorization"] = "Bearer " + bearerToken;
|
|
1381
|
-
}
|
|
1382
|
-
return Promise.race([
|
|
1383
|
-
fetch(fullUrl, fetchOptions).then(function (response) {
|
|
1384
|
-
if (response.status == 204) {
|
|
1385
|
-
return response;
|
|
1386
|
-
}
|
|
1387
|
-
else if (response.status >= 200 && response.status < 300) {
|
|
1388
|
-
return response.json();
|
|
1389
|
-
}
|
|
1390
|
-
else {
|
|
1391
|
-
throw response;
|
|
1392
|
-
}
|
|
1393
|
-
}),
|
|
1394
|
-
new Promise(function (_, reject) {
|
|
1395
|
-
return setTimeout(reject, _this.timeoutMs, "Request timed out.");
|
|
1396
|
-
}),
|
|
1397
|
-
]);
|
|
1398
|
-
};
|
|
1399
|
-
/** Update identity properties. */
|
|
1400
|
-
SatoriApi.prototype.satoriUpdateProperties = function (bearerToken, body, options) {
|
|
1401
|
-
var _this = this;
|
|
1402
|
-
if (options === void 0) { options = {}; }
|
|
1403
|
-
if (body === null || body === undefined) {
|
|
1404
|
-
throw new Error("'body' is a required parameter but is null or undefined.");
|
|
1405
|
-
}
|
|
1406
|
-
var urlPath = "/v1/properties";
|
|
1407
|
-
var queryParams = new Map();
|
|
1408
|
-
var bodyJson = "";
|
|
1409
|
-
bodyJson = JSON.stringify(body || {});
|
|
1410
|
-
var fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
|
|
1411
|
-
var fetchOptions = buildFetchOptions("PUT", options, bodyJson);
|
|
1412
|
-
if (bearerToken) {
|
|
1413
|
-
fetchOptions.headers["Authorization"] = "Bearer " + bearerToken;
|
|
1414
|
-
}
|
|
1415
|
-
return Promise.race([
|
|
1416
|
-
fetch(fullUrl, fetchOptions).then(function (response) {
|
|
1417
|
-
if (response.status == 204) {
|
|
1418
|
-
return response;
|
|
1419
|
-
}
|
|
1420
|
-
else if (response.status >= 200 && response.status < 300) {
|
|
1421
|
-
return response.json();
|
|
1422
|
-
}
|
|
1423
|
-
else {
|
|
1424
|
-
throw response;
|
|
1425
|
-
}
|
|
1426
|
-
}),
|
|
1427
|
-
new Promise(function (_, reject) {
|
|
1428
|
-
return setTimeout(reject, _this.timeoutMs, "Request timed out.");
|
|
1429
|
-
}),
|
|
1430
|
-
]);
|
|
1431
|
-
};
|
|
1432
|
-
SatoriApi.prototype.buildFullUrl = function (basePath, fragment, queryParams) {
|
|
1433
|
-
var e_1, _a;
|
|
1434
|
-
var fullPath = basePath + fragment + "?";
|
|
1435
|
-
var _loop_1 = function (k, v) {
|
|
1436
|
-
if (v instanceof Array) {
|
|
1437
|
-
fullPath += v.reduce(function (prev, curr) {
|
|
1438
|
-
return prev + encodeURIComponent(k) + "=" + encodeURIComponent(curr) + "&";
|
|
1439
|
-
}, "");
|
|
1440
|
-
}
|
|
1441
|
-
else {
|
|
1442
|
-
if (v != null) {
|
|
1443
|
-
fullPath += encodeURIComponent(k) + "=" + encodeURIComponent(v) + "&";
|
|
1444
|
-
}
|
|
1445
|
-
}
|
|
1446
|
-
};
|
|
1447
|
-
try {
|
|
1448
|
-
for (var queryParams_1 = __values(queryParams), queryParams_1_1 = queryParams_1.next(); !queryParams_1_1.done; queryParams_1_1 = queryParams_1.next()) {
|
|
1449
|
-
var _b = __read(queryParams_1_1.value, 2), k = _b[0], v = _b[1];
|
|
1450
|
-
_loop_1(k, v);
|
|
1451
|
-
}
|
|
1452
|
-
}
|
|
1453
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1454
|
-
finally {
|
|
1455
|
-
try {
|
|
1456
|
-
if (queryParams_1_1 && !queryParams_1_1.done && (_a = queryParams_1.return)) _a.call(queryParams_1);
|
|
1457
|
-
}
|
|
1458
|
-
finally { if (e_1) throw e_1.error; }
|
|
1459
|
-
}
|
|
1460
|
-
return fullPath;
|
|
1461
|
-
};
|
|
1462
|
-
return SatoriApi;
|
|
1463
|
-
}());
|
|
1464
|
-
|
|
1465
|
-
/**
|
|
1466
|
-
* Copyright 2022 The Nakama Authors
|
|
1467
|
-
*
|
|
1468
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1469
|
-
* you may not use this file except in compliance with the License.
|
|
1470
|
-
* You may obtain a copy of the License at
|
|
1471
|
-
*
|
|
1472
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1473
|
-
*
|
|
1474
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
1475
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1476
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1477
|
-
* See the License for the specific language governing permissions and
|
|
1478
|
-
* limitations under the License.
|
|
1479
|
-
*/
|
|
1480
|
-
var Session = /** @class */ (function () {
|
|
1481
|
-
function Session(token, refresh_token) {
|
|
1482
|
-
this.token = token;
|
|
1483
|
-
this.refresh_token = refresh_token;
|
|
1484
|
-
this.created_at = Math.floor(new Date().getTime() / 1000);
|
|
1485
|
-
this.update(token, refresh_token);
|
|
1486
|
-
}
|
|
1487
|
-
Session.prototype.isexpired = function (currenttime) {
|
|
1488
|
-
return (this.expires_at - currenttime) < 0;
|
|
1489
|
-
};
|
|
1490
|
-
Session.prototype.isrefreshexpired = function (currenttime) {
|
|
1491
|
-
return (this.refresh_expires_at - currenttime) < 0;
|
|
1492
|
-
};
|
|
1493
|
-
Session.prototype.update = function (token, refreshToken) {
|
|
1494
|
-
var tokenParts = token.split('.');
|
|
1495
|
-
if (tokenParts.length != 3) {
|
|
1496
|
-
throw 'jwt is not valid.';
|
|
1497
|
-
}
|
|
1498
|
-
var tokenDecoded = JSON.parse(_atob(tokenParts[1]));
|
|
1499
|
-
var tokenExpiresAt = Math.floor(parseInt(tokenDecoded['exp']));
|
|
1500
|
-
/** clients that have just updated to the refresh tokens */
|
|
1501
|
-
/** client release will not have a cached refresh token */
|
|
1502
|
-
if (refreshToken) {
|
|
1503
|
-
var refreshTokenParts = refreshToken.split('.');
|
|
1504
|
-
if (refreshTokenParts.length != 3) {
|
|
1505
|
-
throw 'refresh jwt is not valid.';
|
|
1506
|
-
}
|
|
1507
|
-
var refreshTokenDecoded = JSON.parse(_atob(refreshTokenParts[1]));
|
|
1508
|
-
var refreshTokenExpiresAt = Math.floor(parseInt(refreshTokenDecoded['exp']));
|
|
1509
|
-
this.refresh_expires_at = refreshTokenExpiresAt;
|
|
1510
|
-
this.refresh_token = refreshToken;
|
|
1511
|
-
}
|
|
1512
|
-
this.token = token;
|
|
1513
|
-
this.expires_at = tokenExpiresAt;
|
|
1514
|
-
this.user_id = tokenDecoded['uid'];
|
|
1515
|
-
this.vars = tokenDecoded['vrs'];
|
|
1516
|
-
};
|
|
1517
|
-
Session.restore = function (token, refreshToken) {
|
|
1518
|
-
return new Session(token, refreshToken);
|
|
1519
|
-
};
|
|
1520
|
-
return Session;
|
|
1521
|
-
}());
|
|
1522
|
-
|
|
1523
|
-
/**
|
|
1524
|
-
* Copyright 2020 The Nakama Authors
|
|
1525
|
-
*
|
|
1526
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1527
|
-
* you may not use this file except in compliance with the License.
|
|
1528
|
-
* You may obtain a copy of the License at
|
|
1529
|
-
*
|
|
1530
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1531
|
-
*
|
|
1532
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
1533
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1534
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1535
|
-
* See the License for the specific language governing permissions and
|
|
1536
|
-
* limitations under the License.
|
|
1537
|
-
*/
|
|
1538
|
-
var DEFAULT_HOST = "127.0.0.1";
|
|
1539
|
-
var DEFAULT_PORT = "7450";
|
|
1540
|
-
var DEFAULT_API_KEY = "defaultkey";
|
|
1541
|
-
var DEFAULT_TIMEOUT_MS = 7000;
|
|
1542
|
-
var DEFAULT_EXPIRED_TIMESPAN_MS = 5 * 60 * 1000;
|
|
1543
|
-
/** A client for Satori server. */
|
|
1544
|
-
var Client = /** @class */ (function () {
|
|
1545
|
-
function Client(apiKey, host, port, useSSL, timeout, autoRefreshSession) {
|
|
1546
|
-
if (apiKey === void 0) { apiKey = DEFAULT_API_KEY; }
|
|
1547
|
-
if (host === void 0) { host = DEFAULT_HOST; }
|
|
1548
|
-
if (port === void 0) { port = DEFAULT_PORT; }
|
|
1549
|
-
if (useSSL === void 0) { useSSL = false; }
|
|
1550
|
-
if (timeout === void 0) { timeout = DEFAULT_TIMEOUT_MS; }
|
|
1551
|
-
if (autoRefreshSession === void 0) { autoRefreshSession = true; }
|
|
1552
|
-
this.apiKey = apiKey;
|
|
1553
|
-
this.host = host;
|
|
1554
|
-
this.port = port;
|
|
1555
|
-
this.useSSL = useSSL;
|
|
1556
|
-
this.timeout = timeout;
|
|
1557
|
-
this.autoRefreshSession = autoRefreshSession;
|
|
1558
|
-
/** The expired timespan used to check session lifetime. */
|
|
1559
|
-
this.expiredTimespanMs = DEFAULT_EXPIRED_TIMESPAN_MS;
|
|
1560
|
-
var scheme = (useSSL) ? "https://" : "http://";
|
|
1561
|
-
var basePath = "".concat(scheme).concat(host, ":").concat(port);
|
|
1562
|
-
this.apiClient = new SatoriApi(apiKey, basePath, timeout);
|
|
1563
|
-
}
|
|
1564
|
-
/** Authenticate a user with an ID against the server. */
|
|
1565
|
-
Client.prototype.authenticate = function (id, customProperties, defaultProperties) {
|
|
1566
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1567
|
-
var request;
|
|
1568
|
-
return __generator(this, function (_a) {
|
|
1569
|
-
request = {
|
|
1570
|
-
"id": id,
|
|
1571
|
-
custom: customProperties,
|
|
1572
|
-
default: defaultProperties
|
|
1573
|
-
};
|
|
1574
|
-
return [2 /*return*/, this.apiClient.satoriAuthenticate(this.apiKey, "", request).then(function (apiSession) {
|
|
1575
|
-
return Promise.resolve(new Session(apiSession.token || "", apiSession.refresh_token || ""));
|
|
1576
|
-
})];
|
|
1577
|
-
});
|
|
1578
|
-
});
|
|
1579
|
-
};
|
|
1580
|
-
/** Refresh a user's session using a refresh token retrieved from a previous authentication request. */
|
|
1581
|
-
Client.prototype.sessionRefresh = function (session) {
|
|
1582
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1583
|
-
var request;
|
|
1584
|
-
return __generator(this, function (_a) {
|
|
1585
|
-
request = {
|
|
1586
|
-
"refresh_token": session.refresh_token,
|
|
1587
|
-
};
|
|
1588
|
-
return [2 /*return*/, this.apiClient.satoriAuthenticateRefresh(this.apiKey, "", request).then(function (apiSession) {
|
|
1589
|
-
return Promise.resolve(new Session(apiSession.token || "", apiSession.refresh_token || ""));
|
|
1590
|
-
})];
|
|
1591
|
-
});
|
|
1592
|
-
});
|
|
1593
|
-
};
|
|
1594
|
-
/** Log out a session, invalidate a refresh token, or log out all sessions/refresh tokens for a user. */
|
|
1595
|
-
Client.prototype.logout = function (session) {
|
|
1596
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1597
|
-
var request;
|
|
1598
|
-
return __generator(this, function (_a) {
|
|
1599
|
-
request = {
|
|
1600
|
-
"token": session.token,
|
|
1601
|
-
"refresh_token": session.refresh_token
|
|
1602
|
-
};
|
|
1603
|
-
return [2 /*return*/, this.apiClient.satoriAuthenticateLogout(session.token, request).then(function (response) {
|
|
1604
|
-
return Promise.resolve(response !== undefined);
|
|
1605
|
-
})];
|
|
1606
|
-
});
|
|
1607
|
-
});
|
|
1608
|
-
};
|
|
1609
|
-
/** Publish an event for this session. */
|
|
1610
|
-
Client.prototype.event = function (session, event) {
|
|
1611
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1612
|
-
var request;
|
|
1613
|
-
return __generator(this, function (_a) {
|
|
1614
|
-
switch (_a.label) {
|
|
1615
|
-
case 0:
|
|
1616
|
-
if (!(this.autoRefreshSession && session.refresh_token &&
|
|
1617
|
-
session.isexpired((Date.now() + this.expiredTimespanMs) / 1000))) return [3 /*break*/, 2];
|
|
1618
|
-
return [4 /*yield*/, this.sessionRefresh(session)];
|
|
1619
|
-
case 1:
|
|
1620
|
-
_a.sent();
|
|
1621
|
-
_a.label = 2;
|
|
1622
|
-
case 2:
|
|
1623
|
-
request = {
|
|
1624
|
-
events: [event]
|
|
1625
|
-
};
|
|
1626
|
-
return [2 /*return*/, this.apiClient.satoriEvent(session.token, request).then(function (response) {
|
|
1627
|
-
return Promise.resolve(response !== undefined);
|
|
1628
|
-
})];
|
|
1629
|
-
}
|
|
1630
|
-
});
|
|
1631
|
-
});
|
|
1632
|
-
};
|
|
1633
|
-
/** Publish multiple events for this session */
|
|
1634
|
-
Client.prototype.events = function (session, events) {
|
|
1635
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1636
|
-
var request;
|
|
1637
|
-
return __generator(this, function (_a) {
|
|
1638
|
-
switch (_a.label) {
|
|
1639
|
-
case 0:
|
|
1640
|
-
if (!(this.autoRefreshSession && session.refresh_token &&
|
|
1641
|
-
session.isexpired((Date.now() + this.expiredTimespanMs) / 1000))) return [3 /*break*/, 2];
|
|
1642
|
-
return [4 /*yield*/, this.sessionRefresh(session)];
|
|
1643
|
-
case 1:
|
|
1644
|
-
_a.sent();
|
|
1645
|
-
_a.label = 2;
|
|
1646
|
-
case 2:
|
|
1647
|
-
request = {
|
|
1648
|
-
events: events
|
|
1649
|
-
};
|
|
1650
|
-
return [2 /*return*/, this.apiClient.satoriEvent(session.token, request).then(function (response) {
|
|
1651
|
-
return Promise.resolve(response !== undefined);
|
|
1652
|
-
})];
|
|
1653
|
-
}
|
|
1654
|
-
});
|
|
1655
|
-
});
|
|
1656
|
-
};
|
|
1657
|
-
/** Get or list all available experiments for this identity. */
|
|
1658
|
-
Client.prototype.getExperiments = function (session, names) {
|
|
1659
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1660
|
-
return __generator(this, function (_a) {
|
|
1661
|
-
switch (_a.label) {
|
|
1662
|
-
case 0:
|
|
1663
|
-
if (!(this.autoRefreshSession && session.refresh_token &&
|
|
1664
|
-
session.isexpired((Date.now() + this.expiredTimespanMs) / 1000))) return [3 /*break*/, 2];
|
|
1665
|
-
return [4 /*yield*/, this.sessionRefresh(session)];
|
|
1666
|
-
case 1:
|
|
1667
|
-
_a.sent();
|
|
1668
|
-
_a.label = 2;
|
|
1669
|
-
case 2: return [2 /*return*/, this.apiClient.satoriGetExperiments(session.token, names)];
|
|
1670
|
-
}
|
|
1671
|
-
});
|
|
1672
|
-
});
|
|
1673
|
-
};
|
|
1674
|
-
/** Get a single flag for this identity. Throws an error when the flag does not exist. */
|
|
1675
|
-
Client.prototype.getFlag = function (session, name) {
|
|
1676
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1677
|
-
return __generator(this, function (_a) {
|
|
1678
|
-
switch (_a.label) {
|
|
1679
|
-
case 0:
|
|
1680
|
-
if (!(this.autoRefreshSession && session.refresh_token &&
|
|
1681
|
-
session.isexpired((Date.now() + this.expiredTimespanMs) / 1000))) return [3 /*break*/, 2];
|
|
1682
|
-
return [4 /*yield*/, this.sessionRefresh(session)];
|
|
1683
|
-
case 1:
|
|
1684
|
-
_a.sent();
|
|
1685
|
-
_a.label = 2;
|
|
1686
|
-
case 2: return [2 /*return*/, this.apiClient.satoriGetFlags(session.token, "", "", [name]).then(function (flagList) {
|
|
1687
|
-
var _a;
|
|
1688
|
-
var flag = null;
|
|
1689
|
-
(_a = flagList.flags) === null || _a === void 0 ? void 0 : _a.forEach(function (f) {
|
|
1690
|
-
if (f.name === name) {
|
|
1691
|
-
flag = f;
|
|
1692
|
-
}
|
|
1693
|
-
});
|
|
1694
|
-
if (flag === null) {
|
|
1695
|
-
return Promise.reject("Flag does not exist.");
|
|
1696
|
-
}
|
|
1697
|
-
return Promise.resolve(flag);
|
|
1698
|
-
})];
|
|
1699
|
-
}
|
|
1700
|
-
});
|
|
1701
|
-
});
|
|
1702
|
-
};
|
|
1703
|
-
/** Get a single flag for this identity. */
|
|
1704
|
-
Client.prototype.getFlagWithFallback = function (session, name, fallbackValue) {
|
|
1705
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1706
|
-
return __generator(this, function (_a) {
|
|
1707
|
-
return [2 /*return*/, this.getFlag(session, name)
|
|
1708
|
-
.then(function (flag) {
|
|
1709
|
-
return flag;
|
|
1710
|
-
})
|
|
1711
|
-
.catch(function () {
|
|
1712
|
-
var flag = {
|
|
1713
|
-
name: name,
|
|
1714
|
-
value: fallbackValue
|
|
1715
|
-
};
|
|
1716
|
-
return Promise.resolve(flag);
|
|
1717
|
-
})];
|
|
1718
|
-
});
|
|
1719
|
-
});
|
|
1720
|
-
};
|
|
1721
|
-
/** Get a single flag with its configured default value. Throws an error when the flag does not exist. */
|
|
1722
|
-
Client.prototype.getFlagDefault = function (name) {
|
|
1723
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1724
|
-
return __generator(this, function (_a) {
|
|
1725
|
-
return [2 /*return*/, this.apiClient.satoriGetFlags("", this.apiKey, "", [name]).then(function (flagList) {
|
|
1726
|
-
var _a;
|
|
1727
|
-
var flag = null;
|
|
1728
|
-
(_a = flagList.flags) === null || _a === void 0 ? void 0 : _a.forEach(function (f) {
|
|
1729
|
-
if (f.name === name) {
|
|
1730
|
-
flag = f;
|
|
1731
|
-
}
|
|
1732
|
-
});
|
|
1733
|
-
if (flag === null) {
|
|
1734
|
-
return Promise.reject("Flag does not exist.");
|
|
1735
|
-
}
|
|
1736
|
-
return Promise.resolve(flag);
|
|
1737
|
-
})];
|
|
1738
|
-
});
|
|
1739
|
-
});
|
|
1740
|
-
};
|
|
1741
|
-
/** Get a single flag with its configured default value. */
|
|
1742
|
-
Client.prototype.getFlagDefaultWithFallback = function (name, fallbackValue) {
|
|
1743
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1744
|
-
return __generator(this, function (_a) {
|
|
1745
|
-
return [2 /*return*/, this.getFlagDefault(name)
|
|
1746
|
-
.then(function (flag) {
|
|
1747
|
-
return flag;
|
|
1748
|
-
})
|
|
1749
|
-
.catch(function () {
|
|
1750
|
-
var flag = {
|
|
1751
|
-
name: name,
|
|
1752
|
-
value: fallbackValue
|
|
1753
|
-
};
|
|
1754
|
-
return Promise.resolve(flag);
|
|
1755
|
-
})];
|
|
1756
|
-
});
|
|
1757
|
-
});
|
|
1758
|
-
};
|
|
1759
|
-
/** List all available flags for this identity. */
|
|
1760
|
-
Client.prototype.getFlags = function (session, names) {
|
|
1761
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1762
|
-
return __generator(this, function (_a) {
|
|
1763
|
-
switch (_a.label) {
|
|
1764
|
-
case 0:
|
|
1765
|
-
if (!(this.autoRefreshSession && session.refresh_token &&
|
|
1766
|
-
session.isexpired((Date.now() + this.expiredTimespanMs) / 1000))) return [3 /*break*/, 2];
|
|
1767
|
-
return [4 /*yield*/, this.sessionRefresh(session)];
|
|
1768
|
-
case 1:
|
|
1769
|
-
_a.sent();
|
|
1770
|
-
_a.label = 2;
|
|
1771
|
-
case 2: return [2 /*return*/, this.apiClient.satoriGetFlags(session.token, "", "", names)];
|
|
1772
|
-
}
|
|
1773
|
-
});
|
|
1774
|
-
});
|
|
1775
|
-
};
|
|
1776
|
-
/** List all available default flags. */
|
|
1777
|
-
Client.prototype.getFlagsDefault = function (names) {
|
|
1778
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1779
|
-
return __generator(this, function (_a) {
|
|
1780
|
-
return [2 /*return*/, this.apiClient.satoriGetFlags("", this.apiKey, "", names)];
|
|
1781
|
-
});
|
|
1782
|
-
});
|
|
1783
|
-
};
|
|
1784
|
-
/** Enrich/replace the current session with new identifier. */
|
|
1785
|
-
Client.prototype.identify = function (session, id, defaultProperties, customProperties) {
|
|
1786
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1787
|
-
var request;
|
|
1788
|
-
return __generator(this, function (_a) {
|
|
1789
|
-
switch (_a.label) {
|
|
1790
|
-
case 0:
|
|
1791
|
-
if (!(this.autoRefreshSession && session.refresh_token &&
|
|
1792
|
-
session.isexpired((Date.now() + this.expiredTimespanMs) / 1000))) return [3 /*break*/, 2];
|
|
1793
|
-
return [4 /*yield*/, this.sessionRefresh(session)];
|
|
1794
|
-
case 1:
|
|
1795
|
-
_a.sent();
|
|
1796
|
-
_a.label = 2;
|
|
1797
|
-
case 2:
|
|
1798
|
-
request = {
|
|
1799
|
-
id: id,
|
|
1800
|
-
default: defaultProperties,
|
|
1801
|
-
custom: customProperties
|
|
1802
|
-
};
|
|
1803
|
-
return [2 /*return*/, this.apiClient.satoriIdentify(session.token, request).then(function (apiSession) {
|
|
1804
|
-
return Promise.resolve(new Session(apiSession.token || "", apiSession.refresh_token || ""));
|
|
1805
|
-
})];
|
|
1806
|
-
}
|
|
1807
|
-
});
|
|
1808
|
-
});
|
|
1809
|
-
};
|
|
1810
|
-
/** List available live events. */
|
|
1811
|
-
Client.prototype.getLiveEvents = function (session, names) {
|
|
1812
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1813
|
-
return __generator(this, function (_a) {
|
|
1814
|
-
switch (_a.label) {
|
|
1815
|
-
case 0:
|
|
1816
|
-
if (!(this.autoRefreshSession && session.refresh_token &&
|
|
1817
|
-
session.isexpired((Date.now() + this.expiredTimespanMs) / 1000))) return [3 /*break*/, 2];
|
|
1818
|
-
return [4 /*yield*/, this.sessionRefresh(session)];
|
|
1819
|
-
case 1:
|
|
1820
|
-
_a.sent();
|
|
1821
|
-
_a.label = 2;
|
|
1822
|
-
case 2: return [2 /*return*/, this.apiClient.satoriGetLiveEvents(session.token, names)];
|
|
1823
|
-
}
|
|
1824
|
-
});
|
|
1825
|
-
});
|
|
1826
|
-
};
|
|
1827
|
-
/** List properties associated with this identity. */
|
|
1828
|
-
Client.prototype.listProperties = function (session) {
|
|
1829
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1830
|
-
return __generator(this, function (_a) {
|
|
1831
|
-
switch (_a.label) {
|
|
1832
|
-
case 0:
|
|
1833
|
-
if (!(this.autoRefreshSession && session.refresh_token &&
|
|
1834
|
-
session.isexpired((Date.now() + this.expiredTimespanMs) / 1000))) return [3 /*break*/, 2];
|
|
1835
|
-
return [4 /*yield*/, this.sessionRefresh(session)];
|
|
1836
|
-
case 1:
|
|
1837
|
-
_a.sent();
|
|
1838
|
-
_a.label = 2;
|
|
1839
|
-
case 2: return [2 /*return*/, this.apiClient.satoriListProperties(session.token)];
|
|
1840
|
-
}
|
|
1841
|
-
});
|
|
1842
|
-
});
|
|
1843
|
-
};
|
|
1844
|
-
/** Update identity properties. */
|
|
1845
|
-
Client.prototype.updateProperties = function (session, defaultProperties, customProperties, recompute) {
|
|
1846
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1847
|
-
var request;
|
|
1848
|
-
return __generator(this, function (_a) {
|
|
1849
|
-
switch (_a.label) {
|
|
1850
|
-
case 0:
|
|
1851
|
-
if (!(this.autoRefreshSession && session.refresh_token &&
|
|
1852
|
-
session.isexpired((Date.now() + this.expiredTimespanMs) / 1000))) return [3 /*break*/, 2];
|
|
1853
|
-
return [4 /*yield*/, this.sessionRefresh(session)];
|
|
1854
|
-
case 1:
|
|
1855
|
-
_a.sent();
|
|
1856
|
-
_a.label = 2;
|
|
1857
|
-
case 2:
|
|
1858
|
-
request = {
|
|
1859
|
-
default: defaultProperties,
|
|
1860
|
-
custom: customProperties,
|
|
1861
|
-
recompute: recompute,
|
|
1862
|
-
};
|
|
1863
|
-
return [2 /*return*/, this.apiClient.satoriUpdateProperties(session.token, request).then(function (response) {
|
|
1864
|
-
return Promise.resolve(response !== undefined);
|
|
1865
|
-
})];
|
|
1866
|
-
}
|
|
1867
|
-
});
|
|
1868
|
-
});
|
|
1869
|
-
};
|
|
1870
|
-
/** Delete the caller's identity and associated data. */
|
|
1871
|
-
Client.prototype.deleteIdentity = function (session) {
|
|
1872
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1873
|
-
return __generator(this, function (_a) {
|
|
1874
|
-
switch (_a.label) {
|
|
1875
|
-
case 0:
|
|
1876
|
-
if (!(this.autoRefreshSession && session.refresh_token &&
|
|
1877
|
-
session.isexpired((Date.now() + this.expiredTimespanMs) / 1000))) return [3 /*break*/, 2];
|
|
1878
|
-
return [4 /*yield*/, this.sessionRefresh(session)];
|
|
1879
|
-
case 1:
|
|
1880
|
-
_a.sent();
|
|
1881
|
-
_a.label = 2;
|
|
1882
|
-
case 2: return [2 /*return*/, this.apiClient.satoriDeleteIdentity(session.token).then(function (response) {
|
|
1883
|
-
return Promise.resolve(response !== undefined);
|
|
1884
|
-
})];
|
|
1885
|
-
}
|
|
1886
|
-
});
|
|
1887
|
-
});
|
|
1888
|
-
};
|
|
1889
|
-
Client.prototype.getMessageList = function (session) {
|
|
1890
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1891
|
-
return __generator(this, function (_a) {
|
|
1892
|
-
switch (_a.label) {
|
|
1893
|
-
case 0:
|
|
1894
|
-
if (!(this.autoRefreshSession && session.refresh_token &&
|
|
1895
|
-
session.isexpired((Date.now() + this.expiredTimespanMs) / 1000))) return [3 /*break*/, 2];
|
|
1896
|
-
return [4 /*yield*/, this.sessionRefresh(session)];
|
|
1897
|
-
case 1:
|
|
1898
|
-
_a.sent();
|
|
1899
|
-
_a.label = 2;
|
|
1900
|
-
case 2: return [2 /*return*/, this.apiClient.satoriGetMessageList(session.token).then(function (response) {
|
|
1901
|
-
return Promise.resolve(response !== undefined);
|
|
1902
|
-
})];
|
|
1903
|
-
}
|
|
1904
|
-
});
|
|
1905
|
-
});
|
|
1906
|
-
};
|
|
1907
|
-
Client.prototype.deleteMessage = function (session, id) {
|
|
1908
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1909
|
-
return __generator(this, function (_a) {
|
|
1910
|
-
switch (_a.label) {
|
|
1911
|
-
case 0:
|
|
1912
|
-
if (!(this.autoRefreshSession && session.refresh_token &&
|
|
1913
|
-
session.isexpired((Date.now() + this.expiredTimespanMs) / 1000))) return [3 /*break*/, 2];
|
|
1914
|
-
return [4 /*yield*/, this.sessionRefresh(session)];
|
|
1915
|
-
case 1:
|
|
1916
|
-
_a.sent();
|
|
1917
|
-
_a.label = 2;
|
|
1918
|
-
case 2: return [2 /*return*/, this.apiClient.satoriDeleteMessage(session.token, id).then(function (response) {
|
|
1919
|
-
return Promise.resolve(response !== undefined);
|
|
1920
|
-
})];
|
|
1921
|
-
}
|
|
1922
|
-
});
|
|
1923
|
-
});
|
|
1924
|
-
};
|
|
1925
|
-
Client.prototype.updateMessage = function (session, id, consume_time, read_time) {
|
|
1926
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1927
|
-
var request;
|
|
1928
|
-
return __generator(this, function (_a) {
|
|
1929
|
-
switch (_a.label) {
|
|
1930
|
-
case 0:
|
|
1931
|
-
if (!(this.autoRefreshSession && session.refresh_token &&
|
|
1932
|
-
session.isexpired((Date.now() + this.expiredTimespanMs) / 1000))) return [3 /*break*/, 2];
|
|
1933
|
-
return [4 /*yield*/, this.sessionRefresh(session)];
|
|
1934
|
-
case 1:
|
|
1935
|
-
_a.sent();
|
|
1936
|
-
_a.label = 2;
|
|
1937
|
-
case 2:
|
|
1938
|
-
request = {
|
|
1939
|
-
id: id,
|
|
1940
|
-
consume_time: consume_time,
|
|
1941
|
-
read_time: read_time
|
|
1942
|
-
};
|
|
1943
|
-
return [2 /*return*/, this.apiClient.satoriUpdateMessage(session.token, id, request).then(function (response) {
|
|
1944
|
-
return Promise.resolve(response !== undefined);
|
|
1945
|
-
})];
|
|
1946
|
-
}
|
|
1947
|
-
});
|
|
1948
|
-
});
|
|
1949
|
-
};
|
|
1950
|
-
return Client;
|
|
1951
|
-
}());
|
|
1952
|
-
|
|
1953
|
-
exports.Client = Client;
|
|
1954
|
-
exports.Session = Session;
|
|
1955
|
-
|
|
1956
|
-
}));
|