mezon-sdk 2.7.1

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.
@@ -0,0 +1,1456 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
8
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
9
+ var __spreadValues = (a, b) => {
10
+ for (var prop in b || (b = {}))
11
+ if (__hasOwnProp.call(b, prop))
12
+ __defNormalProp(a, prop, b[prop]);
13
+ if (__getOwnPropSymbols)
14
+ for (var prop of __getOwnPropSymbols(b)) {
15
+ if (__propIsEnum.call(b, prop))
16
+ __defNormalProp(a, prop, b[prop]);
17
+ }
18
+ return a;
19
+ };
20
+ var __export = (target, all) => {
21
+ for (var name in all)
22
+ __defProp(target, name, { get: all[name], enumerable: true });
23
+ };
24
+ var __copyProps = (to, from, except, desc) => {
25
+ if (from && typeof from === "object" || typeof from === "function") {
26
+ for (let key of __getOwnPropNames(from))
27
+ if (!__hasOwnProp.call(to, key) && key !== except)
28
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
29
+ }
30
+ return to;
31
+ };
32
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
33
+ var __async = (__this, __arguments, generator) => {
34
+ return new Promise((resolve, reject) => {
35
+ var fulfilled = (value) => {
36
+ try {
37
+ step(generator.next(value));
38
+ } catch (e) {
39
+ reject(e);
40
+ }
41
+ };
42
+ var rejected = (value) => {
43
+ try {
44
+ step(generator.throw(value));
45
+ } catch (e) {
46
+ reject(e);
47
+ }
48
+ };
49
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
50
+ step((generator = generator.apply(__this, __arguments)).next());
51
+ });
52
+ };
53
+
54
+ // index.ts
55
+ var mezon_sdk_exports = {};
56
+ __export(mezon_sdk_exports, {
57
+ Client: () => Client,
58
+ Session: () => Session
59
+ });
60
+ module.exports = __toCommonJS(mezon_sdk_exports);
61
+
62
+ // node_modules/whatwg-fetch/fetch.js
63
+ var g = typeof globalThis !== "undefined" && globalThis || typeof self !== "undefined" && self || // eslint-disable-next-line no-undef
64
+ typeof global !== "undefined" && global || {};
65
+ var support = {
66
+ searchParams: "URLSearchParams" in g,
67
+ iterable: "Symbol" in g && "iterator" in Symbol,
68
+ blob: "FileReader" in g && "Blob" in g && function() {
69
+ try {
70
+ new Blob();
71
+ return true;
72
+ } catch (e) {
73
+ return false;
74
+ }
75
+ }(),
76
+ formData: "FormData" in g,
77
+ arrayBuffer: "ArrayBuffer" in g
78
+ };
79
+ function isDataView(obj) {
80
+ return obj && DataView.prototype.isPrototypeOf(obj);
81
+ }
82
+ if (support.arrayBuffer) {
83
+ viewClasses = [
84
+ "[object Int8Array]",
85
+ "[object Uint8Array]",
86
+ "[object Uint8ClampedArray]",
87
+ "[object Int16Array]",
88
+ "[object Uint16Array]",
89
+ "[object Int32Array]",
90
+ "[object Uint32Array]",
91
+ "[object Float32Array]",
92
+ "[object Float64Array]"
93
+ ];
94
+ isArrayBufferView = ArrayBuffer.isView || function(obj) {
95
+ return obj && viewClasses.indexOf(Object.prototype.toString.call(obj)) > -1;
96
+ };
97
+ }
98
+ var viewClasses;
99
+ var isArrayBufferView;
100
+ function normalizeName(name) {
101
+ if (typeof name !== "string") {
102
+ name = String(name);
103
+ }
104
+ if (/[^a-z0-9\-#$%&'*+.^_`|~!]/i.test(name) || name === "") {
105
+ throw new TypeError('Invalid character in header field name: "' + name + '"');
106
+ }
107
+ return name.toLowerCase();
108
+ }
109
+ function normalizeValue(value) {
110
+ if (typeof value !== "string") {
111
+ value = String(value);
112
+ }
113
+ return value;
114
+ }
115
+ function iteratorFor(items) {
116
+ var iterator = {
117
+ next: function() {
118
+ var value = items.shift();
119
+ return { done: value === void 0, value };
120
+ }
121
+ };
122
+ if (support.iterable) {
123
+ iterator[Symbol.iterator] = function() {
124
+ return iterator;
125
+ };
126
+ }
127
+ return iterator;
128
+ }
129
+ function Headers(headers) {
130
+ this.map = {};
131
+ if (headers instanceof Headers) {
132
+ headers.forEach(function(value, name) {
133
+ this.append(name, value);
134
+ }, this);
135
+ } else if (Array.isArray(headers)) {
136
+ headers.forEach(function(header) {
137
+ if (header.length != 2) {
138
+ throw new TypeError("Headers constructor: expected name/value pair to be length 2, found" + header.length);
139
+ }
140
+ this.append(header[0], header[1]);
141
+ }, this);
142
+ } else if (headers) {
143
+ Object.getOwnPropertyNames(headers).forEach(function(name) {
144
+ this.append(name, headers[name]);
145
+ }, this);
146
+ }
147
+ }
148
+ Headers.prototype.append = function(name, value) {
149
+ name = normalizeName(name);
150
+ value = normalizeValue(value);
151
+ var oldValue = this.map[name];
152
+ this.map[name] = oldValue ? oldValue + ", " + value : value;
153
+ };
154
+ Headers.prototype["delete"] = function(name) {
155
+ delete this.map[normalizeName(name)];
156
+ };
157
+ Headers.prototype.get = function(name) {
158
+ name = normalizeName(name);
159
+ return this.has(name) ? this.map[name] : null;
160
+ };
161
+ Headers.prototype.has = function(name) {
162
+ return this.map.hasOwnProperty(normalizeName(name));
163
+ };
164
+ Headers.prototype.set = function(name, value) {
165
+ this.map[normalizeName(name)] = normalizeValue(value);
166
+ };
167
+ Headers.prototype.forEach = function(callback, thisArg) {
168
+ for (var name in this.map) {
169
+ if (this.map.hasOwnProperty(name)) {
170
+ callback.call(thisArg, this.map[name], name, this);
171
+ }
172
+ }
173
+ };
174
+ Headers.prototype.keys = function() {
175
+ var items = [];
176
+ this.forEach(function(value, name) {
177
+ items.push(name);
178
+ });
179
+ return iteratorFor(items);
180
+ };
181
+ Headers.prototype.values = function() {
182
+ var items = [];
183
+ this.forEach(function(value) {
184
+ items.push(value);
185
+ });
186
+ return iteratorFor(items);
187
+ };
188
+ Headers.prototype.entries = function() {
189
+ var items = [];
190
+ this.forEach(function(value, name) {
191
+ items.push([name, value]);
192
+ });
193
+ return iteratorFor(items);
194
+ };
195
+ if (support.iterable) {
196
+ Headers.prototype[Symbol.iterator] = Headers.prototype.entries;
197
+ }
198
+ function consumed(body) {
199
+ if (body._noBody) return;
200
+ if (body.bodyUsed) {
201
+ return Promise.reject(new TypeError("Already read"));
202
+ }
203
+ body.bodyUsed = true;
204
+ }
205
+ function fileReaderReady(reader) {
206
+ return new Promise(function(resolve, reject) {
207
+ reader.onload = function() {
208
+ resolve(reader.result);
209
+ };
210
+ reader.onerror = function() {
211
+ reject(reader.error);
212
+ };
213
+ });
214
+ }
215
+ function readBlobAsArrayBuffer(blob) {
216
+ var reader = new FileReader();
217
+ var promise = fileReaderReady(reader);
218
+ reader.readAsArrayBuffer(blob);
219
+ return promise;
220
+ }
221
+ function readBlobAsText(blob) {
222
+ var reader = new FileReader();
223
+ var promise = fileReaderReady(reader);
224
+ var match = /charset=([A-Za-z0-9_-]+)/.exec(blob.type);
225
+ var encoding = match ? match[1] : "utf-8";
226
+ reader.readAsText(blob, encoding);
227
+ return promise;
228
+ }
229
+ function readArrayBufferAsText(buf) {
230
+ var view = new Uint8Array(buf);
231
+ var chars = new Array(view.length);
232
+ for (var i = 0; i < view.length; i++) {
233
+ chars[i] = String.fromCharCode(view[i]);
234
+ }
235
+ return chars.join("");
236
+ }
237
+ function bufferClone(buf) {
238
+ if (buf.slice) {
239
+ return buf.slice(0);
240
+ } else {
241
+ var view = new Uint8Array(buf.byteLength);
242
+ view.set(new Uint8Array(buf));
243
+ return view.buffer;
244
+ }
245
+ }
246
+ function Body() {
247
+ this.bodyUsed = false;
248
+ this._initBody = function(body) {
249
+ this.bodyUsed = this.bodyUsed;
250
+ this._bodyInit = body;
251
+ if (!body) {
252
+ this._noBody = true;
253
+ this._bodyText = "";
254
+ } else if (typeof body === "string") {
255
+ this._bodyText = body;
256
+ } else if (support.blob && Blob.prototype.isPrototypeOf(body)) {
257
+ this._bodyBlob = body;
258
+ } else if (support.formData && FormData.prototype.isPrototypeOf(body)) {
259
+ this._bodyFormData = body;
260
+ } else if (support.searchParams && URLSearchParams.prototype.isPrototypeOf(body)) {
261
+ this._bodyText = body.toString();
262
+ } else if (support.arrayBuffer && support.blob && isDataView(body)) {
263
+ this._bodyArrayBuffer = bufferClone(body.buffer);
264
+ this._bodyInit = new Blob([this._bodyArrayBuffer]);
265
+ } else if (support.arrayBuffer && (ArrayBuffer.prototype.isPrototypeOf(body) || isArrayBufferView(body))) {
266
+ this._bodyArrayBuffer = bufferClone(body);
267
+ } else {
268
+ this._bodyText = body = Object.prototype.toString.call(body);
269
+ }
270
+ if (!this.headers.get("content-type")) {
271
+ if (typeof body === "string") {
272
+ this.headers.set("content-type", "text/plain;charset=UTF-8");
273
+ } else if (this._bodyBlob && this._bodyBlob.type) {
274
+ this.headers.set("content-type", this._bodyBlob.type);
275
+ } else if (support.searchParams && URLSearchParams.prototype.isPrototypeOf(body)) {
276
+ this.headers.set("content-type", "application/x-www-form-urlencoded;charset=UTF-8");
277
+ }
278
+ }
279
+ };
280
+ if (support.blob) {
281
+ this.blob = function() {
282
+ var rejected = consumed(this);
283
+ if (rejected) {
284
+ return rejected;
285
+ }
286
+ if (this._bodyBlob) {
287
+ return Promise.resolve(this._bodyBlob);
288
+ } else if (this._bodyArrayBuffer) {
289
+ return Promise.resolve(new Blob([this._bodyArrayBuffer]));
290
+ } else if (this._bodyFormData) {
291
+ throw new Error("could not read FormData body as blob");
292
+ } else {
293
+ return Promise.resolve(new Blob([this._bodyText]));
294
+ }
295
+ };
296
+ }
297
+ this.arrayBuffer = function() {
298
+ if (this._bodyArrayBuffer) {
299
+ var isConsumed = consumed(this);
300
+ if (isConsumed) {
301
+ return isConsumed;
302
+ } else if (ArrayBuffer.isView(this._bodyArrayBuffer)) {
303
+ return Promise.resolve(
304
+ this._bodyArrayBuffer.buffer.slice(
305
+ this._bodyArrayBuffer.byteOffset,
306
+ this._bodyArrayBuffer.byteOffset + this._bodyArrayBuffer.byteLength
307
+ )
308
+ );
309
+ } else {
310
+ return Promise.resolve(this._bodyArrayBuffer);
311
+ }
312
+ } else if (support.blob) {
313
+ return this.blob().then(readBlobAsArrayBuffer);
314
+ } else {
315
+ throw new Error("could not read as ArrayBuffer");
316
+ }
317
+ };
318
+ this.text = function() {
319
+ var rejected = consumed(this);
320
+ if (rejected) {
321
+ return rejected;
322
+ }
323
+ if (this._bodyBlob) {
324
+ return readBlobAsText(this._bodyBlob);
325
+ } else if (this._bodyArrayBuffer) {
326
+ return Promise.resolve(readArrayBufferAsText(this._bodyArrayBuffer));
327
+ } else if (this._bodyFormData) {
328
+ throw new Error("could not read FormData body as text");
329
+ } else {
330
+ return Promise.resolve(this._bodyText);
331
+ }
332
+ };
333
+ if (support.formData) {
334
+ this.formData = function() {
335
+ return this.text().then(decode);
336
+ };
337
+ }
338
+ this.json = function() {
339
+ return this.text().then(JSON.parse);
340
+ };
341
+ return this;
342
+ }
343
+ var methods = ["CONNECT", "DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT", "TRACE"];
344
+ function normalizeMethod(method) {
345
+ var upcased = method.toUpperCase();
346
+ return methods.indexOf(upcased) > -1 ? upcased : method;
347
+ }
348
+ function Request(input, options) {
349
+ if (!(this instanceof Request)) {
350
+ throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.');
351
+ }
352
+ options = options || {};
353
+ var body = options.body;
354
+ if (input instanceof Request) {
355
+ if (input.bodyUsed) {
356
+ throw new TypeError("Already read");
357
+ }
358
+ this.url = input.url;
359
+ this.credentials = input.credentials;
360
+ if (!options.headers) {
361
+ this.headers = new Headers(input.headers);
362
+ }
363
+ this.method = input.method;
364
+ this.mode = input.mode;
365
+ this.signal = input.signal;
366
+ if (!body && input._bodyInit != null) {
367
+ body = input._bodyInit;
368
+ input.bodyUsed = true;
369
+ }
370
+ } else {
371
+ this.url = String(input);
372
+ }
373
+ this.credentials = options.credentials || this.credentials || "same-origin";
374
+ if (options.headers || !this.headers) {
375
+ this.headers = new Headers(options.headers);
376
+ }
377
+ this.method = normalizeMethod(options.method || this.method || "GET");
378
+ this.mode = options.mode || this.mode || null;
379
+ this.signal = options.signal || this.signal || function() {
380
+ if ("AbortController" in g) {
381
+ var ctrl = new AbortController();
382
+ return ctrl.signal;
383
+ }
384
+ }();
385
+ this.referrer = null;
386
+ if ((this.method === "GET" || this.method === "HEAD") && body) {
387
+ throw new TypeError("Body not allowed for GET or HEAD requests");
388
+ }
389
+ this._initBody(body);
390
+ if (this.method === "GET" || this.method === "HEAD") {
391
+ if (options.cache === "no-store" || options.cache === "no-cache") {
392
+ var reParamSearch = /([?&])_=[^&]*/;
393
+ if (reParamSearch.test(this.url)) {
394
+ this.url = this.url.replace(reParamSearch, "$1_=" + (/* @__PURE__ */ new Date()).getTime());
395
+ } else {
396
+ var reQueryString = /\?/;
397
+ this.url += (reQueryString.test(this.url) ? "&" : "?") + "_=" + (/* @__PURE__ */ new Date()).getTime();
398
+ }
399
+ }
400
+ }
401
+ }
402
+ Request.prototype.clone = function() {
403
+ return new Request(this, { body: this._bodyInit });
404
+ };
405
+ function decode(body) {
406
+ var form = new FormData();
407
+ body.trim().split("&").forEach(function(bytes) {
408
+ if (bytes) {
409
+ var split = bytes.split("=");
410
+ var name = split.shift().replace(/\+/g, " ");
411
+ var value = split.join("=").replace(/\+/g, " ");
412
+ form.append(decodeURIComponent(name), decodeURIComponent(value));
413
+ }
414
+ });
415
+ return form;
416
+ }
417
+ function parseHeaders(rawHeaders) {
418
+ var headers = new Headers();
419
+ var preProcessedHeaders = rawHeaders.replace(/\r?\n[\t ]+/g, " ");
420
+ preProcessedHeaders.split("\r").map(function(header) {
421
+ return header.indexOf("\n") === 0 ? header.substr(1, header.length) : header;
422
+ }).forEach(function(line) {
423
+ var parts = line.split(":");
424
+ var key = parts.shift().trim();
425
+ if (key) {
426
+ var value = parts.join(":").trim();
427
+ try {
428
+ headers.append(key, value);
429
+ } catch (error) {
430
+ console.warn("Response " + error.message);
431
+ }
432
+ }
433
+ });
434
+ return headers;
435
+ }
436
+ Body.call(Request.prototype);
437
+ function Response(bodyInit, options) {
438
+ if (!(this instanceof Response)) {
439
+ throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.');
440
+ }
441
+ if (!options) {
442
+ options = {};
443
+ }
444
+ this.type = "default";
445
+ this.status = options.status === void 0 ? 200 : options.status;
446
+ if (this.status < 200 || this.status > 599) {
447
+ throw new RangeError("Failed to construct 'Response': The status provided (0) is outside the range [200, 599].");
448
+ }
449
+ this.ok = this.status >= 200 && this.status < 300;
450
+ this.statusText = options.statusText === void 0 ? "" : "" + options.statusText;
451
+ this.headers = new Headers(options.headers);
452
+ this.url = options.url || "";
453
+ this._initBody(bodyInit);
454
+ }
455
+ Body.call(Response.prototype);
456
+ Response.prototype.clone = function() {
457
+ return new Response(this._bodyInit, {
458
+ status: this.status,
459
+ statusText: this.statusText,
460
+ headers: new Headers(this.headers),
461
+ url: this.url
462
+ });
463
+ };
464
+ Response.error = function() {
465
+ var response = new Response(null, { status: 200, statusText: "" });
466
+ response.ok = false;
467
+ response.status = 0;
468
+ response.type = "error";
469
+ return response;
470
+ };
471
+ var redirectStatuses = [301, 302, 303, 307, 308];
472
+ Response.redirect = function(url, status) {
473
+ if (redirectStatuses.indexOf(status) === -1) {
474
+ throw new RangeError("Invalid status code");
475
+ }
476
+ return new Response(null, { status, headers: { location: url } });
477
+ };
478
+ var DOMException = g.DOMException;
479
+ try {
480
+ new DOMException();
481
+ } catch (err) {
482
+ DOMException = function(message, name) {
483
+ this.message = message;
484
+ this.name = name;
485
+ var error = Error(message);
486
+ this.stack = error.stack;
487
+ };
488
+ DOMException.prototype = Object.create(Error.prototype);
489
+ DOMException.prototype.constructor = DOMException;
490
+ }
491
+ function fetch2(input, init) {
492
+ return new Promise(function(resolve, reject) {
493
+ var request = new Request(input, init);
494
+ if (request.signal && request.signal.aborted) {
495
+ return reject(new DOMException("Aborted", "AbortError"));
496
+ }
497
+ var xhr = new XMLHttpRequest();
498
+ function abortXhr() {
499
+ xhr.abort();
500
+ }
501
+ xhr.onload = function() {
502
+ var options = {
503
+ statusText: xhr.statusText,
504
+ headers: parseHeaders(xhr.getAllResponseHeaders() || "")
505
+ };
506
+ if (request.url.indexOf("file://") === 0 && (xhr.status < 200 || xhr.status > 599)) {
507
+ options.status = 200;
508
+ } else {
509
+ options.status = xhr.status;
510
+ }
511
+ options.url = "responseURL" in xhr ? xhr.responseURL : options.headers.get("X-Request-URL");
512
+ var body = "response" in xhr ? xhr.response : xhr.responseText;
513
+ setTimeout(function() {
514
+ resolve(new Response(body, options));
515
+ }, 0);
516
+ };
517
+ xhr.onerror = function() {
518
+ setTimeout(function() {
519
+ reject(new TypeError("Network request failed"));
520
+ }, 0);
521
+ };
522
+ xhr.ontimeout = function() {
523
+ setTimeout(function() {
524
+ reject(new TypeError("Network request timed out"));
525
+ }, 0);
526
+ };
527
+ xhr.onabort = function() {
528
+ setTimeout(function() {
529
+ reject(new DOMException("Aborted", "AbortError"));
530
+ }, 0);
531
+ };
532
+ function fixUrl(url) {
533
+ try {
534
+ return url === "" && g.location.href ? g.location.href : url;
535
+ } catch (e) {
536
+ return url;
537
+ }
538
+ }
539
+ xhr.open(request.method, fixUrl(request.url), true);
540
+ if (request.credentials === "include") {
541
+ xhr.withCredentials = true;
542
+ } else if (request.credentials === "omit") {
543
+ xhr.withCredentials = false;
544
+ }
545
+ if ("responseType" in xhr) {
546
+ if (support.blob) {
547
+ xhr.responseType = "blob";
548
+ } else if (support.arrayBuffer) {
549
+ xhr.responseType = "arraybuffer";
550
+ }
551
+ }
552
+ if (init && typeof init.headers === "object" && !(init.headers instanceof Headers || g.Headers && init.headers instanceof g.Headers)) {
553
+ var names = [];
554
+ Object.getOwnPropertyNames(init.headers).forEach(function(name) {
555
+ names.push(normalizeName(name));
556
+ xhr.setRequestHeader(name, normalizeValue(init.headers[name]));
557
+ });
558
+ request.headers.forEach(function(value, name) {
559
+ if (names.indexOf(name) === -1) {
560
+ xhr.setRequestHeader(name, value);
561
+ }
562
+ });
563
+ } else {
564
+ request.headers.forEach(function(value, name) {
565
+ xhr.setRequestHeader(name, value);
566
+ });
567
+ }
568
+ if (request.signal) {
569
+ request.signal.addEventListener("abort", abortXhr);
570
+ xhr.onreadystatechange = function() {
571
+ if (xhr.readyState === 4) {
572
+ request.signal.removeEventListener("abort", abortXhr);
573
+ }
574
+ };
575
+ }
576
+ xhr.send(typeof request._bodyInit === "undefined" ? null : request._bodyInit);
577
+ });
578
+ }
579
+ fetch2.polyfill = true;
580
+ if (!g.fetch) {
581
+ g.fetch = fetch2;
582
+ g.Headers = Headers;
583
+ g.Request = Request;
584
+ g.Response = Response;
585
+ }
586
+
587
+ // node_modules/js-base64/base64.mjs
588
+ var _hasatob = typeof atob === "function";
589
+ var _hasbtoa = typeof btoa === "function";
590
+ var _hasBuffer = typeof Buffer === "function";
591
+ var _TD = typeof TextDecoder === "function" ? new TextDecoder() : void 0;
592
+ var _TE = typeof TextEncoder === "function" ? new TextEncoder() : void 0;
593
+ var b64ch = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
594
+ var b64chs = Array.prototype.slice.call(b64ch);
595
+ var b64tab = ((a) => {
596
+ let tab = {};
597
+ a.forEach((c, i) => tab[c] = i);
598
+ return tab;
599
+ })(b64chs);
600
+ var b64re = /^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/;
601
+ var _fromCC = String.fromCharCode.bind(String);
602
+ var _U8Afrom = typeof Uint8Array.from === "function" ? Uint8Array.from.bind(Uint8Array) : (it, fn = (x) => x) => new Uint8Array(Array.prototype.slice.call(it, 0).map(fn));
603
+ var _mkUriSafe = (src) => src.replace(/=/g, "").replace(/[+\/]/g, (m0) => m0 == "+" ? "-" : "_");
604
+ var _tidyB64 = (s) => s.replace(/[^A-Za-z0-9\+\/]/g, "");
605
+ var btoaPolyfill = (bin) => {
606
+ let u32, c0, c1, c2, asc = "";
607
+ const pad = bin.length % 3;
608
+ for (let i = 0; i < bin.length; ) {
609
+ if ((c0 = bin.charCodeAt(i++)) > 255 || (c1 = bin.charCodeAt(i++)) > 255 || (c2 = bin.charCodeAt(i++)) > 255)
610
+ throw new TypeError("invalid character found");
611
+ u32 = c0 << 16 | c1 << 8 | c2;
612
+ asc += b64chs[u32 >> 18 & 63] + b64chs[u32 >> 12 & 63] + b64chs[u32 >> 6 & 63] + b64chs[u32 & 63];
613
+ }
614
+ return pad ? asc.slice(0, pad - 3) + "===".substring(pad) : asc;
615
+ };
616
+ var _btoa = _hasbtoa ? (bin) => btoa(bin) : _hasBuffer ? (bin) => Buffer.from(bin, "binary").toString("base64") : btoaPolyfill;
617
+ var _fromUint8Array = _hasBuffer ? (u8a) => Buffer.from(u8a).toString("base64") : (u8a) => {
618
+ const maxargs = 4096;
619
+ let strs = [];
620
+ for (let i = 0, l = u8a.length; i < l; i += maxargs) {
621
+ strs.push(_fromCC.apply(null, u8a.subarray(i, i + maxargs)));
622
+ }
623
+ return _btoa(strs.join(""));
624
+ };
625
+ var cb_utob = (c) => {
626
+ if (c.length < 2) {
627
+ var cc = c.charCodeAt(0);
628
+ return cc < 128 ? c : cc < 2048 ? _fromCC(192 | cc >>> 6) + _fromCC(128 | cc & 63) : _fromCC(224 | cc >>> 12 & 15) + _fromCC(128 | cc >>> 6 & 63) + _fromCC(128 | cc & 63);
629
+ } else {
630
+ var cc = 65536 + (c.charCodeAt(0) - 55296) * 1024 + (c.charCodeAt(1) - 56320);
631
+ return _fromCC(240 | cc >>> 18 & 7) + _fromCC(128 | cc >>> 12 & 63) + _fromCC(128 | cc >>> 6 & 63) + _fromCC(128 | cc & 63);
632
+ }
633
+ };
634
+ var re_utob = /[\uD800-\uDBFF][\uDC00-\uDFFFF]|[^\x00-\x7F]/g;
635
+ var utob = (u) => u.replace(re_utob, cb_utob);
636
+ var _encode = _hasBuffer ? (s) => Buffer.from(s, "utf8").toString("base64") : _TE ? (s) => _fromUint8Array(_TE.encode(s)) : (s) => _btoa(utob(s));
637
+ var encode = (src, urlsafe = false) => urlsafe ? _mkUriSafe(_encode(src)) : _encode(src);
638
+ var atobPolyfill = (asc) => {
639
+ asc = asc.replace(/\s+/g, "");
640
+ if (!b64re.test(asc))
641
+ throw new TypeError("malformed base64.");
642
+ asc += "==".slice(2 - (asc.length & 3));
643
+ let u24, bin = "", r1, r2;
644
+ for (let i = 0; i < asc.length; ) {
645
+ u24 = b64tab[asc.charAt(i++)] << 18 | b64tab[asc.charAt(i++)] << 12 | (r1 = b64tab[asc.charAt(i++)]) << 6 | (r2 = b64tab[asc.charAt(i++)]);
646
+ bin += r1 === 64 ? _fromCC(u24 >> 16 & 255) : r2 === 64 ? _fromCC(u24 >> 16 & 255, u24 >> 8 & 255) : _fromCC(u24 >> 16 & 255, u24 >> 8 & 255, u24 & 255);
647
+ }
648
+ return bin;
649
+ };
650
+ var _atob = _hasatob ? (asc) => atob(_tidyB64(asc)) : _hasBuffer ? (asc) => Buffer.from(asc, "base64").toString("binary") : atobPolyfill;
651
+
652
+ // utils.ts
653
+ function buildFetchOptions(method, options, bodyJson) {
654
+ const fetchOptions = __spreadValues(__spreadValues({}, { method }), options);
655
+ fetchOptions.headers = __spreadValues({}, options.headers);
656
+ const descriptor = Object.getOwnPropertyDescriptor(XMLHttpRequest.prototype, "withCredentials");
657
+ if (!(descriptor == null ? void 0 : descriptor.set)) {
658
+ fetchOptions.credentials = "cocos-ignore";
659
+ }
660
+ if (!Object.keys(fetchOptions.headers).includes("Accept")) {
661
+ fetchOptions.headers["Accept"] = "application/json";
662
+ }
663
+ if (!Object.keys(fetchOptions.headers).includes("Content-Type")) {
664
+ fetchOptions.headers["Content-Type"] = "application/json";
665
+ }
666
+ Object.keys(fetchOptions.headers).forEach((key) => {
667
+ if (!fetchOptions.headers[key]) {
668
+ delete fetchOptions.headers[key];
669
+ }
670
+ });
671
+ if (bodyJson) {
672
+ fetchOptions.body = bodyJson;
673
+ }
674
+ return fetchOptions;
675
+ }
676
+
677
+ // api.gen.ts
678
+ var SatoriApi = class {
679
+ constructor(apiKey, basePath, timeoutMs) {
680
+ this.apiKey = apiKey;
681
+ this.basePath = basePath;
682
+ this.timeoutMs = timeoutMs;
683
+ }
684
+ /** A healthcheck which load balancers can use to check the service. */
685
+ satoriHealthcheck(bearerToken, options = {}) {
686
+ const urlPath = "/healthcheck";
687
+ const queryParams = /* @__PURE__ */ new Map();
688
+ let bodyJson = "";
689
+ const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
690
+ const fetchOptions = buildFetchOptions("GET", options, bodyJson);
691
+ if (bearerToken) {
692
+ fetchOptions.headers["Authorization"] = "Bearer " + bearerToken;
693
+ }
694
+ return Promise.race([
695
+ fetch(fullUrl, fetchOptions).then((response) => {
696
+ if (response.status == 204) {
697
+ return response;
698
+ } else if (response.status >= 200 && response.status < 300) {
699
+ return response.json();
700
+ } else {
701
+ throw response;
702
+ }
703
+ }),
704
+ new Promise(
705
+ (_, reject) => setTimeout(reject, this.timeoutMs, "Request timed out.")
706
+ )
707
+ ]);
708
+ }
709
+ /** A readycheck which load balancers can use to check the service. */
710
+ satoriReadycheck(bearerToken, options = {}) {
711
+ const urlPath = "/readycheck";
712
+ const queryParams = /* @__PURE__ */ new Map();
713
+ let bodyJson = "";
714
+ const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
715
+ const fetchOptions = buildFetchOptions("GET", options, bodyJson);
716
+ if (bearerToken) {
717
+ fetchOptions.headers["Authorization"] = "Bearer " + bearerToken;
718
+ }
719
+ return Promise.race([
720
+ fetch(fullUrl, fetchOptions).then((response) => {
721
+ if (response.status == 204) {
722
+ return response;
723
+ } else if (response.status >= 200 && response.status < 300) {
724
+ return response.json();
725
+ } else {
726
+ throw response;
727
+ }
728
+ }),
729
+ new Promise(
730
+ (_, reject) => setTimeout(reject, this.timeoutMs, "Request timed out.")
731
+ )
732
+ ]);
733
+ }
734
+ /** Authenticate against the server. */
735
+ satoriAuthenticate(basicAuthUsername, basicAuthPassword, body, options = {}) {
736
+ if (body === null || body === void 0) {
737
+ throw new Error("'body' is a required parameter but is null or undefined.");
738
+ }
739
+ const urlPath = "/v1/authenticate";
740
+ const queryParams = /* @__PURE__ */ new Map();
741
+ let bodyJson = "";
742
+ bodyJson = JSON.stringify(body || {});
743
+ const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
744
+ const fetchOptions = buildFetchOptions("POST", options, bodyJson);
745
+ if (basicAuthUsername) {
746
+ fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword);
747
+ }
748
+ return Promise.race([
749
+ fetch(fullUrl, fetchOptions).then((response) => {
750
+ if (response.status == 204) {
751
+ return response;
752
+ } else if (response.status >= 200 && response.status < 300) {
753
+ return response.json();
754
+ } else {
755
+ throw response;
756
+ }
757
+ }),
758
+ new Promise(
759
+ (_, reject) => setTimeout(reject, this.timeoutMs, "Request timed out.")
760
+ )
761
+ ]);
762
+ }
763
+ /** Log out a session, invalidate a refresh token, or log out all sessions/refresh tokens for a user. */
764
+ satoriAuthenticateLogout(bearerToken, body, options = {}) {
765
+ if (body === null || body === void 0) {
766
+ throw new Error("'body' is a required parameter but is null or undefined.");
767
+ }
768
+ const urlPath = "/v1/authenticate/logout";
769
+ const queryParams = /* @__PURE__ */ new Map();
770
+ let bodyJson = "";
771
+ bodyJson = JSON.stringify(body || {});
772
+ const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
773
+ const fetchOptions = buildFetchOptions("POST", options, bodyJson);
774
+ if (bearerToken) {
775
+ fetchOptions.headers["Authorization"] = "Bearer " + bearerToken;
776
+ }
777
+ return Promise.race([
778
+ fetch(fullUrl, fetchOptions).then((response) => {
779
+ if (response.status == 204) {
780
+ return response;
781
+ } else if (response.status >= 200 && response.status < 300) {
782
+ return response.json();
783
+ } else {
784
+ throw response;
785
+ }
786
+ }),
787
+ new Promise(
788
+ (_, reject) => setTimeout(reject, this.timeoutMs, "Request timed out.")
789
+ )
790
+ ]);
791
+ }
792
+ /** Refresh a user's session using a refresh token retrieved from a previous authentication request. */
793
+ satoriAuthenticateRefresh(basicAuthUsername, basicAuthPassword, body, options = {}) {
794
+ if (body === null || body === void 0) {
795
+ throw new Error("'body' is a required parameter but is null or undefined.");
796
+ }
797
+ const urlPath = "/v1/authenticate/refresh";
798
+ const queryParams = /* @__PURE__ */ new Map();
799
+ let bodyJson = "";
800
+ bodyJson = JSON.stringify(body || {});
801
+ const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
802
+ const fetchOptions = buildFetchOptions("POST", options, bodyJson);
803
+ if (basicAuthUsername) {
804
+ fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword);
805
+ }
806
+ return Promise.race([
807
+ fetch(fullUrl, fetchOptions).then((response) => {
808
+ if (response.status == 204) {
809
+ return response;
810
+ } else if (response.status >= 200 && response.status < 300) {
811
+ return response.json();
812
+ } else {
813
+ throw response;
814
+ }
815
+ }),
816
+ new Promise(
817
+ (_, reject) => setTimeout(reject, this.timeoutMs, "Request timed out.")
818
+ )
819
+ ]);
820
+ }
821
+ /** Publish an event for this session. */
822
+ satoriEvent(bearerToken, body, options = {}) {
823
+ if (body === null || body === void 0) {
824
+ throw new Error("'body' is a required parameter but is null or undefined.");
825
+ }
826
+ const urlPath = "/v1/event";
827
+ const queryParams = /* @__PURE__ */ new Map();
828
+ let bodyJson = "";
829
+ bodyJson = JSON.stringify(body || {});
830
+ const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
831
+ const fetchOptions = buildFetchOptions("POST", options, bodyJson);
832
+ if (bearerToken) {
833
+ fetchOptions.headers["Authorization"] = "Bearer " + bearerToken;
834
+ }
835
+ return Promise.race([
836
+ fetch(fullUrl, fetchOptions).then((response) => {
837
+ if (response.status == 204) {
838
+ return response;
839
+ } else if (response.status >= 200 && response.status < 300) {
840
+ return response.json();
841
+ } else {
842
+ throw response;
843
+ }
844
+ }),
845
+ new Promise(
846
+ (_, reject) => setTimeout(reject, this.timeoutMs, "Request timed out.")
847
+ )
848
+ ]);
849
+ }
850
+ /** Get or list all available experiments for this identity. */
851
+ satoriGetExperiments(bearerToken, names, options = {}) {
852
+ const urlPath = "/v1/experiment";
853
+ const queryParams = /* @__PURE__ */ new Map();
854
+ queryParams.set("names", names);
855
+ let bodyJson = "";
856
+ const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
857
+ const fetchOptions = buildFetchOptions("GET", options, bodyJson);
858
+ if (bearerToken) {
859
+ fetchOptions.headers["Authorization"] = "Bearer " + bearerToken;
860
+ }
861
+ return Promise.race([
862
+ fetch(fullUrl, fetchOptions).then((response) => {
863
+ if (response.status == 204) {
864
+ return response;
865
+ } else if (response.status >= 200 && response.status < 300) {
866
+ return response.json();
867
+ } else {
868
+ throw response;
869
+ }
870
+ }),
871
+ new Promise(
872
+ (_, reject) => setTimeout(reject, this.timeoutMs, "Request timed out.")
873
+ )
874
+ ]);
875
+ }
876
+ /** List all available flags for this identity. */
877
+ satoriGetFlags(bearerToken, basicAuthUsername, basicAuthPassword, names, options = {}) {
878
+ const urlPath = "/v1/flag";
879
+ const queryParams = /* @__PURE__ */ new Map();
880
+ queryParams.set("names", names);
881
+ let bodyJson = "";
882
+ const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
883
+ const fetchOptions = buildFetchOptions("GET", options, bodyJson);
884
+ if (bearerToken) {
885
+ fetchOptions.headers["Authorization"] = "Bearer " + bearerToken;
886
+ }
887
+ if (basicAuthUsername) {
888
+ fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword);
889
+ }
890
+ return Promise.race([
891
+ fetch(fullUrl, fetchOptions).then((response) => {
892
+ if (response.status == 204) {
893
+ return response;
894
+ } else if (response.status >= 200 && response.status < 300) {
895
+ return response.json();
896
+ } else {
897
+ throw response;
898
+ }
899
+ }),
900
+ new Promise(
901
+ (_, reject) => setTimeout(reject, this.timeoutMs, "Request timed out.")
902
+ )
903
+ ]);
904
+ }
905
+ /** Enrich/replace the current session with new identifier. */
906
+ satoriIdentify(bearerToken, body, options = {}) {
907
+ if (body === null || body === void 0) {
908
+ throw new Error("'body' is a required parameter but is null or undefined.");
909
+ }
910
+ const urlPath = "/v1/identify";
911
+ const queryParams = /* @__PURE__ */ new Map();
912
+ let bodyJson = "";
913
+ bodyJson = JSON.stringify(body || {});
914
+ const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
915
+ const fetchOptions = buildFetchOptions("PUT", options, bodyJson);
916
+ if (bearerToken) {
917
+ fetchOptions.headers["Authorization"] = "Bearer " + bearerToken;
918
+ }
919
+ return Promise.race([
920
+ fetch(fullUrl, fetchOptions).then((response) => {
921
+ if (response.status == 204) {
922
+ return response;
923
+ } else if (response.status >= 200 && response.status < 300) {
924
+ return response.json();
925
+ } else {
926
+ throw response;
927
+ }
928
+ }),
929
+ new Promise(
930
+ (_, reject) => setTimeout(reject, this.timeoutMs, "Request timed out.")
931
+ )
932
+ ]);
933
+ }
934
+ /** Delete the caller's identity and associated data. */
935
+ satoriDeleteIdentity(bearerToken, options = {}) {
936
+ const urlPath = "/v1/identity";
937
+ const queryParams = /* @__PURE__ */ new Map();
938
+ let bodyJson = "";
939
+ const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
940
+ const fetchOptions = buildFetchOptions("DELETE", options, bodyJson);
941
+ if (bearerToken) {
942
+ fetchOptions.headers["Authorization"] = "Bearer " + bearerToken;
943
+ }
944
+ return Promise.race([
945
+ fetch(fullUrl, fetchOptions).then((response) => {
946
+ if (response.status == 204) {
947
+ return response;
948
+ } else if (response.status >= 200 && response.status < 300) {
949
+ return response.json();
950
+ } else {
951
+ throw response;
952
+ }
953
+ }),
954
+ new Promise(
955
+ (_, reject) => setTimeout(reject, this.timeoutMs, "Request timed out.")
956
+ )
957
+ ]);
958
+ }
959
+ /** List available live events. */
960
+ satoriGetLiveEvents(bearerToken, names, options = {}) {
961
+ const urlPath = "/v1/live-event";
962
+ const queryParams = /* @__PURE__ */ new Map();
963
+ queryParams.set("names", names);
964
+ let bodyJson = "";
965
+ const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
966
+ const fetchOptions = buildFetchOptions("GET", options, bodyJson);
967
+ if (bearerToken) {
968
+ fetchOptions.headers["Authorization"] = "Bearer " + bearerToken;
969
+ }
970
+ return Promise.race([
971
+ fetch(fullUrl, fetchOptions).then((response) => {
972
+ if (response.status == 204) {
973
+ return response;
974
+ } else if (response.status >= 200 && response.status < 300) {
975
+ return response.json();
976
+ } else {
977
+ throw response;
978
+ }
979
+ }),
980
+ new Promise(
981
+ (_, reject) => setTimeout(reject, this.timeoutMs, "Request timed out.")
982
+ )
983
+ ]);
984
+ }
985
+ /** Get the list of messages for the identity. */
986
+ satoriGetMessageList(bearerToken, limit, forward, cursor, options = {}) {
987
+ const urlPath = "/v1/message";
988
+ const queryParams = /* @__PURE__ */ new Map();
989
+ queryParams.set("limit", limit);
990
+ queryParams.set("forward", forward);
991
+ queryParams.set("cursor", cursor);
992
+ let bodyJson = "";
993
+ const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
994
+ const fetchOptions = buildFetchOptions("GET", options, bodyJson);
995
+ if (bearerToken) {
996
+ fetchOptions.headers["Authorization"] = "Bearer " + bearerToken;
997
+ }
998
+ return Promise.race([
999
+ fetch(fullUrl, fetchOptions).then((response) => {
1000
+ if (response.status == 204) {
1001
+ return response;
1002
+ } else if (response.status >= 200 && response.status < 300) {
1003
+ return response.json();
1004
+ } else {
1005
+ throw response;
1006
+ }
1007
+ }),
1008
+ new Promise(
1009
+ (_, reject) => setTimeout(reject, this.timeoutMs, "Request timed out.")
1010
+ )
1011
+ ]);
1012
+ }
1013
+ /** Deletes a message for an identity. */
1014
+ satoriDeleteMessage(bearerToken, id, options = {}) {
1015
+ if (id === null || id === void 0) {
1016
+ throw new Error("'id' is a required parameter but is null or undefined.");
1017
+ }
1018
+ const urlPath = "/v1/message/{id}".replace("{id}", encodeURIComponent(String(id)));
1019
+ const queryParams = /* @__PURE__ */ new Map();
1020
+ let bodyJson = "";
1021
+ const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
1022
+ const fetchOptions = buildFetchOptions("DELETE", options, bodyJson);
1023
+ if (bearerToken) {
1024
+ fetchOptions.headers["Authorization"] = "Bearer " + bearerToken;
1025
+ }
1026
+ return Promise.race([
1027
+ fetch(fullUrl, fetchOptions).then((response) => {
1028
+ if (response.status == 204) {
1029
+ return response;
1030
+ } else if (response.status >= 200 && response.status < 300) {
1031
+ return response.json();
1032
+ } else {
1033
+ throw response;
1034
+ }
1035
+ }),
1036
+ new Promise(
1037
+ (_, reject) => setTimeout(reject, this.timeoutMs, "Request timed out.")
1038
+ )
1039
+ ]);
1040
+ }
1041
+ /** Updates a message for an identity. */
1042
+ satoriUpdateMessage(bearerToken, id, body, options = {}) {
1043
+ if (id === null || id === void 0) {
1044
+ throw new Error("'id' is a required parameter but is null or undefined.");
1045
+ }
1046
+ if (body === null || body === void 0) {
1047
+ throw new Error("'body' is a required parameter but is null or undefined.");
1048
+ }
1049
+ const urlPath = "/v1/message/{id}".replace("{id}", encodeURIComponent(String(id)));
1050
+ const queryParams = /* @__PURE__ */ new Map();
1051
+ let bodyJson = "";
1052
+ bodyJson = JSON.stringify(body || {});
1053
+ const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
1054
+ const fetchOptions = buildFetchOptions("PUT", options, bodyJson);
1055
+ if (bearerToken) {
1056
+ fetchOptions.headers["Authorization"] = "Bearer " + bearerToken;
1057
+ }
1058
+ return Promise.race([
1059
+ fetch(fullUrl, fetchOptions).then((response) => {
1060
+ if (response.status == 204) {
1061
+ return response;
1062
+ } else if (response.status >= 200 && response.status < 300) {
1063
+ return response.json();
1064
+ } else {
1065
+ throw response;
1066
+ }
1067
+ }),
1068
+ new Promise(
1069
+ (_, reject) => setTimeout(reject, this.timeoutMs, "Request timed out.")
1070
+ )
1071
+ ]);
1072
+ }
1073
+ /** List properties associated with this identity. */
1074
+ satoriListProperties(bearerToken, options = {}) {
1075
+ const urlPath = "/v1/properties";
1076
+ const queryParams = /* @__PURE__ */ new Map();
1077
+ let bodyJson = "";
1078
+ const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
1079
+ const fetchOptions = buildFetchOptions("GET", options, bodyJson);
1080
+ if (bearerToken) {
1081
+ fetchOptions.headers["Authorization"] = "Bearer " + bearerToken;
1082
+ }
1083
+ return Promise.race([
1084
+ fetch(fullUrl, fetchOptions).then((response) => {
1085
+ if (response.status == 204) {
1086
+ return response;
1087
+ } else if (response.status >= 200 && response.status < 300) {
1088
+ return response.json();
1089
+ } else {
1090
+ throw response;
1091
+ }
1092
+ }),
1093
+ new Promise(
1094
+ (_, reject) => setTimeout(reject, this.timeoutMs, "Request timed out.")
1095
+ )
1096
+ ]);
1097
+ }
1098
+ /** Update identity properties. */
1099
+ satoriUpdateProperties(bearerToken, body, options = {}) {
1100
+ if (body === null || body === void 0) {
1101
+ throw new Error("'body' is a required parameter but is null or undefined.");
1102
+ }
1103
+ const urlPath = "/v1/properties";
1104
+ const queryParams = /* @__PURE__ */ new Map();
1105
+ let bodyJson = "";
1106
+ bodyJson = JSON.stringify(body || {});
1107
+ const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
1108
+ const fetchOptions = buildFetchOptions("PUT", options, bodyJson);
1109
+ if (bearerToken) {
1110
+ fetchOptions.headers["Authorization"] = "Bearer " + bearerToken;
1111
+ }
1112
+ return Promise.race([
1113
+ fetch(fullUrl, fetchOptions).then((response) => {
1114
+ if (response.status == 204) {
1115
+ return response;
1116
+ } else if (response.status >= 200 && response.status < 300) {
1117
+ return response.json();
1118
+ } else {
1119
+ throw response;
1120
+ }
1121
+ }),
1122
+ new Promise(
1123
+ (_, reject) => setTimeout(reject, this.timeoutMs, "Request timed out.")
1124
+ )
1125
+ ]);
1126
+ }
1127
+ buildFullUrl(basePath, fragment, queryParams) {
1128
+ let fullPath = basePath + fragment + "?";
1129
+ for (let [k, v] of queryParams) {
1130
+ if (v instanceof Array) {
1131
+ fullPath += v.reduce((prev, curr) => {
1132
+ return prev + encodeURIComponent(k) + "=" + encodeURIComponent(curr) + "&";
1133
+ }, "");
1134
+ } else {
1135
+ if (v != null) {
1136
+ fullPath += encodeURIComponent(k) + "=" + encodeURIComponent(v) + "&";
1137
+ }
1138
+ }
1139
+ }
1140
+ return fullPath;
1141
+ }
1142
+ };
1143
+
1144
+ // session.ts
1145
+ var Session = class _Session {
1146
+ constructor(token, refresh_token) {
1147
+ this.token = token;
1148
+ this.refresh_token = refresh_token;
1149
+ this.created_at = Math.floor((/* @__PURE__ */ new Date()).getTime() / 1e3);
1150
+ this.update(token, refresh_token);
1151
+ }
1152
+ isexpired(currenttime) {
1153
+ return this.expires_at - currenttime < 0;
1154
+ }
1155
+ isrefreshexpired(currenttime) {
1156
+ return this.refresh_expires_at - currenttime < 0;
1157
+ }
1158
+ update(token, refreshToken) {
1159
+ const tokenParts = token.split(".");
1160
+ if (tokenParts.length != 3) {
1161
+ throw "jwt is not valid.";
1162
+ }
1163
+ const tokenDecoded = JSON.parse(_atob(tokenParts[1]));
1164
+ const tokenExpiresAt = Math.floor(parseInt(tokenDecoded["exp"]));
1165
+ if (refreshToken) {
1166
+ const refreshTokenParts = refreshToken.split(".");
1167
+ if (refreshTokenParts.length != 3) {
1168
+ throw "refresh jwt is not valid.";
1169
+ }
1170
+ const refreshTokenDecoded = JSON.parse(_atob(refreshTokenParts[1]));
1171
+ const refreshTokenExpiresAt = Math.floor(parseInt(refreshTokenDecoded["exp"]));
1172
+ this.refresh_expires_at = refreshTokenExpiresAt;
1173
+ this.refresh_token = refreshToken;
1174
+ }
1175
+ this.token = token;
1176
+ this.expires_at = tokenExpiresAt;
1177
+ this.user_id = tokenDecoded["uid"];
1178
+ this.vars = tokenDecoded["vrs"];
1179
+ }
1180
+ static restore(token, refreshToken) {
1181
+ return new _Session(token, refreshToken);
1182
+ }
1183
+ };
1184
+
1185
+ // client.ts
1186
+ var DEFAULT_HOST = "127.0.0.1";
1187
+ var DEFAULT_PORT = "7450";
1188
+ var DEFAULT_API_KEY = "defaultkey";
1189
+ var DEFAULT_TIMEOUT_MS = 7e3;
1190
+ var DEFAULT_EXPIRED_TIMESPAN_MS = 5 * 60 * 1e3;
1191
+ var Client = class {
1192
+ constructor(apiKey = DEFAULT_API_KEY, host = DEFAULT_HOST, port = DEFAULT_PORT, useSSL = false, timeout = DEFAULT_TIMEOUT_MS, autoRefreshSession = true) {
1193
+ this.apiKey = apiKey;
1194
+ this.host = host;
1195
+ this.port = port;
1196
+ this.useSSL = useSSL;
1197
+ this.timeout = timeout;
1198
+ this.autoRefreshSession = autoRefreshSession;
1199
+ /** The expired timespan used to check session lifetime. */
1200
+ this.expiredTimespanMs = DEFAULT_EXPIRED_TIMESPAN_MS;
1201
+ const scheme = useSSL ? "https://" : "http://";
1202
+ const basePath = `${scheme}${host}:${port}`;
1203
+ this.apiClient = new SatoriApi(apiKey, basePath, timeout);
1204
+ }
1205
+ /** Authenticate a user with an ID against the server. */
1206
+ authenticate(id, customProperties, defaultProperties) {
1207
+ return __async(this, null, function* () {
1208
+ const request = {
1209
+ "id": id,
1210
+ custom: customProperties,
1211
+ default: defaultProperties
1212
+ };
1213
+ return this.apiClient.satoriAuthenticate(this.apiKey, "", request).then((apiSession) => {
1214
+ return Promise.resolve(new Session(apiSession.token || "", apiSession.refresh_token || ""));
1215
+ });
1216
+ });
1217
+ }
1218
+ /** Refresh a user's session using a refresh token retrieved from a previous authentication request. */
1219
+ sessionRefresh(session) {
1220
+ return __async(this, null, function* () {
1221
+ const request = {
1222
+ "refresh_token": session.refresh_token
1223
+ };
1224
+ return this.apiClient.satoriAuthenticateRefresh(this.apiKey, "", request).then((apiSession) => {
1225
+ return Promise.resolve(new Session(apiSession.token || "", apiSession.refresh_token || ""));
1226
+ });
1227
+ });
1228
+ }
1229
+ /** Log out a session, invalidate a refresh token, or log out all sessions/refresh tokens for a user. */
1230
+ logout(session) {
1231
+ return __async(this, null, function* () {
1232
+ const request = {
1233
+ "token": session.token,
1234
+ "refresh_token": session.refresh_token
1235
+ };
1236
+ return this.apiClient.satoriAuthenticateLogout(session.token, request).then((response) => {
1237
+ return Promise.resolve(response !== void 0);
1238
+ });
1239
+ });
1240
+ }
1241
+ /** Publish an event for this session. */
1242
+ event(session, event) {
1243
+ return __async(this, null, function* () {
1244
+ if (this.autoRefreshSession && session.refresh_token && session.isexpired((Date.now() + this.expiredTimespanMs) / 1e3)) {
1245
+ yield this.sessionRefresh(session);
1246
+ }
1247
+ const request = {
1248
+ events: [event]
1249
+ };
1250
+ return this.apiClient.satoriEvent(session.token, request).then((response) => {
1251
+ return Promise.resolve(response !== void 0);
1252
+ });
1253
+ });
1254
+ }
1255
+ /** Publish multiple events for this session */
1256
+ events(session, events) {
1257
+ return __async(this, null, function* () {
1258
+ if (this.autoRefreshSession && session.refresh_token && session.isexpired((Date.now() + this.expiredTimespanMs) / 1e3)) {
1259
+ yield this.sessionRefresh(session);
1260
+ }
1261
+ const request = {
1262
+ events
1263
+ };
1264
+ return this.apiClient.satoriEvent(session.token, request).then((response) => {
1265
+ return Promise.resolve(response !== void 0);
1266
+ });
1267
+ });
1268
+ }
1269
+ /** Get or list all available experiments for this identity. */
1270
+ getExperiments(session, names) {
1271
+ return __async(this, null, function* () {
1272
+ if (this.autoRefreshSession && session.refresh_token && session.isexpired((Date.now() + this.expiredTimespanMs) / 1e3)) {
1273
+ yield this.sessionRefresh(session);
1274
+ }
1275
+ return this.apiClient.satoriGetExperiments(session.token, names);
1276
+ });
1277
+ }
1278
+ /** Get a single flag for this identity. Throws an error when the flag does not exist. */
1279
+ getFlag(session, name) {
1280
+ return __async(this, null, function* () {
1281
+ if (this.autoRefreshSession && session.refresh_token && session.isexpired((Date.now() + this.expiredTimespanMs) / 1e3)) {
1282
+ yield this.sessionRefresh(session);
1283
+ }
1284
+ return this.apiClient.satoriGetFlags(session.token, "", "", [name]).then((flagList) => {
1285
+ var _a;
1286
+ let flag = null;
1287
+ (_a = flagList.flags) == null ? void 0 : _a.forEach((f) => {
1288
+ if (f.name === name) {
1289
+ flag = f;
1290
+ }
1291
+ });
1292
+ if (flag === null) {
1293
+ return Promise.reject("Flag does not exist.");
1294
+ }
1295
+ return Promise.resolve(flag);
1296
+ });
1297
+ });
1298
+ }
1299
+ /** Get a single flag for this identity. */
1300
+ getFlagWithFallback(session, name, fallbackValue) {
1301
+ return __async(this, null, function* () {
1302
+ return this.getFlag(session, name).then((flag) => {
1303
+ return flag;
1304
+ }).catch(() => {
1305
+ const flag = {
1306
+ name,
1307
+ value: fallbackValue
1308
+ };
1309
+ return Promise.resolve(flag);
1310
+ });
1311
+ });
1312
+ }
1313
+ /** Get a single flag with its configured default value. Throws an error when the flag does not exist. */
1314
+ getFlagDefault(name) {
1315
+ return __async(this, null, function* () {
1316
+ return this.apiClient.satoriGetFlags("", this.apiKey, "", [name]).then((flagList) => {
1317
+ var _a;
1318
+ let flag = null;
1319
+ (_a = flagList.flags) == null ? void 0 : _a.forEach((f) => {
1320
+ if (f.name === name) {
1321
+ flag = f;
1322
+ }
1323
+ });
1324
+ if (flag === null) {
1325
+ return Promise.reject("Flag does not exist.");
1326
+ }
1327
+ return Promise.resolve(flag);
1328
+ });
1329
+ });
1330
+ }
1331
+ /** Get a single flag with its configured default value. */
1332
+ getFlagDefaultWithFallback(name, fallbackValue) {
1333
+ return __async(this, null, function* () {
1334
+ return this.getFlagDefault(name).then((flag) => {
1335
+ return flag;
1336
+ }).catch(() => {
1337
+ const flag = {
1338
+ name,
1339
+ value: fallbackValue
1340
+ };
1341
+ return Promise.resolve(flag);
1342
+ });
1343
+ });
1344
+ }
1345
+ /** List all available flags for this identity. */
1346
+ getFlags(session, names) {
1347
+ return __async(this, null, function* () {
1348
+ if (this.autoRefreshSession && session.refresh_token && session.isexpired((Date.now() + this.expiredTimespanMs) / 1e3)) {
1349
+ yield this.sessionRefresh(session);
1350
+ }
1351
+ return this.apiClient.satoriGetFlags(session.token, "", "", names);
1352
+ });
1353
+ }
1354
+ /** List all available default flags. */
1355
+ getFlagsDefault(names) {
1356
+ return __async(this, null, function* () {
1357
+ return this.apiClient.satoriGetFlags("", this.apiKey, "", names);
1358
+ });
1359
+ }
1360
+ /** Enrich/replace the current session with new identifier. */
1361
+ identify(session, id, defaultProperties, customProperties) {
1362
+ return __async(this, null, function* () {
1363
+ if (this.autoRefreshSession && session.refresh_token && session.isexpired((Date.now() + this.expiredTimespanMs) / 1e3)) {
1364
+ yield this.sessionRefresh(session);
1365
+ }
1366
+ const request = {
1367
+ id,
1368
+ default: defaultProperties,
1369
+ custom: customProperties
1370
+ };
1371
+ return this.apiClient.satoriIdentify(session.token, request).then((apiSession) => {
1372
+ return Promise.resolve(new Session(apiSession.token || "", apiSession.refresh_token || ""));
1373
+ });
1374
+ });
1375
+ }
1376
+ /** List available live events. */
1377
+ getLiveEvents(session, names) {
1378
+ return __async(this, null, function* () {
1379
+ if (this.autoRefreshSession && session.refresh_token && session.isexpired((Date.now() + this.expiredTimespanMs) / 1e3)) {
1380
+ yield this.sessionRefresh(session);
1381
+ }
1382
+ return this.apiClient.satoriGetLiveEvents(session.token, names);
1383
+ });
1384
+ }
1385
+ /** List properties associated with this identity. */
1386
+ listProperties(session) {
1387
+ return __async(this, null, function* () {
1388
+ if (this.autoRefreshSession && session.refresh_token && session.isexpired((Date.now() + this.expiredTimespanMs) / 1e3)) {
1389
+ yield this.sessionRefresh(session);
1390
+ }
1391
+ return this.apiClient.satoriListProperties(session.token);
1392
+ });
1393
+ }
1394
+ /** Update identity properties. */
1395
+ updateProperties(session, defaultProperties, customProperties, recompute) {
1396
+ return __async(this, null, function* () {
1397
+ if (this.autoRefreshSession && session.refresh_token && session.isexpired((Date.now() + this.expiredTimespanMs) / 1e3)) {
1398
+ yield this.sessionRefresh(session);
1399
+ }
1400
+ const request = {
1401
+ default: defaultProperties,
1402
+ custom: customProperties,
1403
+ recompute
1404
+ };
1405
+ return this.apiClient.satoriUpdateProperties(session.token, request).then((response) => {
1406
+ return Promise.resolve(response !== void 0);
1407
+ });
1408
+ });
1409
+ }
1410
+ /** Delete the caller's identity and associated data. */
1411
+ deleteIdentity(session) {
1412
+ return __async(this, null, function* () {
1413
+ if (this.autoRefreshSession && session.refresh_token && session.isexpired((Date.now() + this.expiredTimespanMs) / 1e3)) {
1414
+ yield this.sessionRefresh(session);
1415
+ }
1416
+ return this.apiClient.satoriDeleteIdentity(session.token).then((response) => {
1417
+ return Promise.resolve(response !== void 0);
1418
+ });
1419
+ });
1420
+ }
1421
+ getMessageList(session) {
1422
+ return __async(this, null, function* () {
1423
+ if (this.autoRefreshSession && session.refresh_token && session.isexpired((Date.now() + this.expiredTimespanMs) / 1e3)) {
1424
+ yield this.sessionRefresh(session);
1425
+ }
1426
+ return this.apiClient.satoriGetMessageList(session.token).then((response) => {
1427
+ return Promise.resolve(response !== void 0);
1428
+ });
1429
+ });
1430
+ }
1431
+ deleteMessage(session, id) {
1432
+ return __async(this, null, function* () {
1433
+ if (this.autoRefreshSession && session.refresh_token && session.isexpired((Date.now() + this.expiredTimespanMs) / 1e3)) {
1434
+ yield this.sessionRefresh(session);
1435
+ }
1436
+ return this.apiClient.satoriDeleteMessage(session.token, id).then((response) => {
1437
+ return Promise.resolve(response !== void 0);
1438
+ });
1439
+ });
1440
+ }
1441
+ updateMessage(session, id, consume_time, read_time) {
1442
+ return __async(this, null, function* () {
1443
+ if (this.autoRefreshSession && session.refresh_token && session.isexpired((Date.now() + this.expiredTimespanMs) / 1e3)) {
1444
+ yield this.sessionRefresh(session);
1445
+ }
1446
+ const request = {
1447
+ id,
1448
+ consume_time,
1449
+ read_time
1450
+ };
1451
+ return this.apiClient.satoriUpdateMessage(session.token, id, request).then((response) => {
1452
+ return Promise.resolve(response !== void 0);
1453
+ });
1454
+ });
1455
+ }
1456
+ };