skapi-js 2.2.2 → 2.2.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/dist/skapi.browser.mjs +2 -2
- package/dist/skapi.browser.mjs.map +1 -1
- package/dist/skapi.cjs +2 -2
- package/dist/skapi.cjs.map +1 -1
- package/dist/skapi.d.mts +38 -7
- package/dist/skapi.d.ts +38 -7
- package/dist/skapi.js +2 -2
- package/dist/skapi.js.map +1 -1
- package/dist/skapi.mjs +2 -2
- package/dist/skapi.mjs.map +1 -1
- package/package.json +1 -1
package/dist/skapi.d.mts
CHANGED
|
@@ -573,6 +573,7 @@ type RequestHistory = {
|
|
|
573
573
|
created: number;
|
|
574
574
|
updated: number;
|
|
575
575
|
executed?: number;
|
|
576
|
+
responded?: number;
|
|
576
577
|
request_body: any;
|
|
577
578
|
expires?: number;
|
|
578
579
|
status: 'pending' | 'running' | 'resolved' | 'failed';
|
|
@@ -1360,6 +1361,12 @@ declare class Skapi {
|
|
|
1360
1361
|
/**
|
|
1361
1362
|
* Queries unique ID records by unique_id or condition filters.
|
|
1362
1363
|
*
|
|
1364
|
+
* With `condition` omitted the unique ID is matched exactly. `gte` / `>=`
|
|
1365
|
+
* is a prefix search ("unique IDs starting with x") and `lte` / `<=` is a
|
|
1366
|
+
* suffix search ("unique IDs ending with x"); `gt` / `>` and `lt` / `<`
|
|
1367
|
+
* are lexicographic. An 'ends with' search returns its matches in the
|
|
1368
|
+
* order of the unique ID read from its last character backwards.
|
|
1369
|
+
*
|
|
1363
1370
|
* Refused to a signed out caller when the project's `require_login`
|
|
1364
1371
|
* setting is on: REQUIRE_LOGIN from the SDK, INVALID_REQUEST from the
|
|
1365
1372
|
* backend for a caller that skips it. A project that has never set the
|
|
@@ -1378,7 +1385,7 @@ declare class Skapi {
|
|
|
1378
1385
|
getUniqueId(params?: Form<{
|
|
1379
1386
|
/** Unique ID */
|
|
1380
1387
|
unique_id?: string;
|
|
1381
|
-
/** String query condition for the unique_id value. */
|
|
1388
|
+
/** String query condition for the unique_id value. Omitted: exact match. `gte` / `>=`: starts with. `lte` / `<=`: ends with. */
|
|
1382
1389
|
condition?: Condition | 'ne' | '!=';
|
|
1383
1390
|
}>, fetchOptions?: FetchOptions): Promise<DatabaseResponse<UniqueId>>;
|
|
1384
1391
|
/**
|
|
@@ -2201,13 +2208,17 @@ declare class Skapi {
|
|
|
2201
2208
|
* exactly. With `table` omitted entirely, every table is returned.
|
|
2202
2209
|
* `gte` / `>=` is a prefix search ("table names starting with x"), while
|
|
2203
2210
|
* `gt` / `>` is a lexicographic greater-than that spills past the prefix
|
|
2204
|
-
* into every later table name.
|
|
2211
|
+
* into every later table name. `lte` / `<=` is a suffix search ("table
|
|
2212
|
+
* names ending with x"); its matches come back in the order of the name
|
|
2213
|
+
* read from its last character backwards.
|
|
2205
2214
|
*
|
|
2206
2215
|
* Every combination:
|
|
2207
2216
|
* - `getTables({})`: every table in the project.
|
|
2208
2217
|
* - `getTables({ table: 'x' })`: exact match on 'x'.
|
|
2209
2218
|
* - `getTables({ table: 'x', condition: 'gte' })`: prefix, every table
|
|
2210
2219
|
* name starting with 'x'.
|
|
2220
|
+
* - `getTables({ table: 'x', condition: 'lte' })`: suffix, every table
|
|
2221
|
+
* name ending with 'x'.
|
|
2211
2222
|
* - `getTables({ table: '' })`: errors with '"table" should not be empty.'
|
|
2212
2223
|
* - `getTables({ condition: 'gte' })` with no `table`: errors with
|
|
2213
2224
|
* '"table" is required for condition.'
|
|
@@ -2250,7 +2261,7 @@ declare class Skapi {
|
|
|
2250
2261
|
/** If omitted, fetches the full list of tables. */
|
|
2251
2262
|
query?: {
|
|
2252
2263
|
table?: string;
|
|
2253
|
-
/** Condition operator of table name. Omitted: exact match on the given table name. `gte` / `>=`:
|
|
2264
|
+
/** Condition operator of table name. Omitted: exact match on the given table name. `gte` / `>=`: starts with. `lte` / `<=`: ends with. */
|
|
2254
2265
|
condition?: Condition;
|
|
2255
2266
|
}, fetchOptions?: FetchOptions): Promise<DatabaseResponse<Table>>;
|
|
2256
2267
|
/**
|
|
@@ -2265,6 +2276,14 @@ declare class Skapi {
|
|
|
2265
2276
|
* The only condition is `order.condition`, which requires `order.value`.
|
|
2266
2277
|
* Omitting it matches `order.value` exactly.
|
|
2267
2278
|
*
|
|
2279
|
+
* With `order.by: 'index_name'`, `order.value` is a piece of the name and
|
|
2280
|
+
* the condition searches the names: `>=` 'starts with', `<=` 'ends with',
|
|
2281
|
+
* `>` and `<` the names after and before it in order. 'Ends with' matches
|
|
2282
|
+
* the name segment right under `index` (or the first segment when `index`
|
|
2283
|
+
* is omitted), and returns what is nested under a match as well, the way
|
|
2284
|
+
* 'starts with' does: `index: 'Band.'` with `value: 'ers'` and `<=` finds
|
|
2285
|
+
* Band.Members, Band.Members.name and Band.Singers.
|
|
2286
|
+
*
|
|
2268
2287
|
* Every combination (`table` is required, so there is no no-argument
|
|
2269
2288
|
* form):
|
|
2270
2289
|
* - `getIndexes({ table: 't' })`: every index of table 't'.
|
|
@@ -2274,6 +2293,12 @@ declare class Skapi {
|
|
|
2274
2293
|
* the compound index, so Band.name, Band.year.
|
|
2275
2294
|
* - `getIndexes({ table: 't', order: { by: 'index_name', value: 'B' } })`:
|
|
2276
2295
|
* exact match against the value.
|
|
2296
|
+
* - `getIndexes({ table: 't', order: { by: 'index_name' } })`: every index
|
|
2297
|
+
* of the table, ordered by name.
|
|
2298
|
+
* - `getIndexes({ table: 't', order: { by: 'index_name', value: 'B', condition: '>=' } })`:
|
|
2299
|
+
* the index names that start with 'B'.
|
|
2300
|
+
* - `getIndexes({ table: 't', order: { by: 'index_name', value: 'e', condition: '<=' } })`:
|
|
2301
|
+
* the index names that end with 'e'.
|
|
2277
2302
|
* - `getIndexes({ table: 't', order: { by: 'total_number' } })`: the whole
|
|
2278
2303
|
* partition, ordered by that attribute.
|
|
2279
2304
|
* - `order.condition` without `order.value`: errors.
|
|
@@ -2315,9 +2340,9 @@ declare class Skapi {
|
|
|
2315
2340
|
order?: {
|
|
2316
2341
|
/** Key name to order by. */
|
|
2317
2342
|
by: 'average_number' | 'total_number' | 'number_count' | 'average_bool' | 'total_bool' | 'bool_count' | 'string_count' | 'index_name' | 'number_of_records';
|
|
2318
|
-
/** Value to query. */
|
|
2343
|
+
/** Value to query. A string when "by" is 'index_name': a piece of the index name. */
|
|
2319
2344
|
value?: number | boolean | string;
|
|
2320
|
-
/** Requires "value". Omitted: exact match against "value". */
|
|
2345
|
+
/** Requires "value". Omitted: exact match against "value". With "by" 'index_name': `>=` starts with, `<=` ends with. */
|
|
2321
2346
|
condition?: Condition;
|
|
2322
2347
|
};
|
|
2323
2348
|
}, fetchOptions?: FetchOptions): Promise<DatabaseResponse<Index>>;
|
|
@@ -2328,7 +2353,9 @@ declare class Skapi {
|
|
|
2328
2353
|
* `table` and `tag` together match the tag exactly, `table` alone is a
|
|
2329
2354
|
* prefix ('>=') that lists every tag in that table, and neither one
|
|
2330
2355
|
* returns every tag in the project, ordered by record count, descending.
|
|
2331
|
-
* `gte` / `>=` is a prefix search
|
|
2356
|
+
* `gte` / `>=` is a prefix search and `lte` / `<=` is a suffix search:
|
|
2357
|
+
* with `table` it finds the tags of that table that end with `tag`, and
|
|
2358
|
+
* with `tag` alone the tags that end with it in every table.
|
|
2332
2359
|
*
|
|
2333
2360
|
* Every combination:
|
|
2334
2361
|
* - `getTags({})`: every tag in the project, ordered by record count,
|
|
@@ -2340,6 +2367,10 @@ declare class Skapi {
|
|
|
2340
2367
|
* tables.
|
|
2341
2368
|
* - `getTags({ table: 't', tag: 'g', condition: 'gte' })`: prefix, every
|
|
2342
2369
|
* tag in 't' starting with 'g'.
|
|
2370
|
+
* - `getTags({ table: 't', tag: 'g', condition: 'lte' })`: suffix, every
|
|
2371
|
+
* tag in 't' ending with 'g'.
|
|
2372
|
+
* - `getTags({ tag: 'g', condition: 'lte' })` with no `table`: every tag
|
|
2373
|
+
* ending with 'g', in every table.
|
|
2343
2374
|
* - `getTags({ condition: 'gte' })` with neither `table` nor `tag`: errors
|
|
2344
2375
|
* with '"table" or "tag" is required for condition.'
|
|
2345
2376
|
*
|
|
@@ -2376,7 +2407,7 @@ declare class Skapi {
|
|
|
2376
2407
|
table?: string;
|
|
2377
2408
|
/** Tag name */
|
|
2378
2409
|
tag?: string;
|
|
2379
|
-
/** String query condition for tag name. Omitted: exact match when `table` and `tag` are both given, prefix when only `table` is given. */
|
|
2410
|
+
/** String query condition for tag name. Omitted: exact match when `table` and `tag` are both given, prefix when only `table` is given. `gte` / `>=`: starts with. `lte` / `<=`: ends with. */
|
|
2380
2411
|
condition?: Condition;
|
|
2381
2412
|
}, fetchOptions?: FetchOptions): Promise<DatabaseResponse<Tag>>;
|
|
2382
2413
|
/**
|
package/dist/skapi.d.ts
CHANGED
|
@@ -573,6 +573,7 @@ type RequestHistory = {
|
|
|
573
573
|
created: number;
|
|
574
574
|
updated: number;
|
|
575
575
|
executed?: number;
|
|
576
|
+
responded?: number;
|
|
576
577
|
request_body: any;
|
|
577
578
|
expires?: number;
|
|
578
579
|
status: 'pending' | 'running' | 'resolved' | 'failed';
|
|
@@ -1360,6 +1361,12 @@ declare class Skapi {
|
|
|
1360
1361
|
/**
|
|
1361
1362
|
* Queries unique ID records by unique_id or condition filters.
|
|
1362
1363
|
*
|
|
1364
|
+
* With `condition` omitted the unique ID is matched exactly. `gte` / `>=`
|
|
1365
|
+
* is a prefix search ("unique IDs starting with x") and `lte` / `<=` is a
|
|
1366
|
+
* suffix search ("unique IDs ending with x"); `gt` / `>` and `lt` / `<`
|
|
1367
|
+
* are lexicographic. An 'ends with' search returns its matches in the
|
|
1368
|
+
* order of the unique ID read from its last character backwards.
|
|
1369
|
+
*
|
|
1363
1370
|
* Refused to a signed out caller when the project's `require_login`
|
|
1364
1371
|
* setting is on: REQUIRE_LOGIN from the SDK, INVALID_REQUEST from the
|
|
1365
1372
|
* backend for a caller that skips it. A project that has never set the
|
|
@@ -1378,7 +1385,7 @@ declare class Skapi {
|
|
|
1378
1385
|
getUniqueId(params?: Form<{
|
|
1379
1386
|
/** Unique ID */
|
|
1380
1387
|
unique_id?: string;
|
|
1381
|
-
/** String query condition for the unique_id value. */
|
|
1388
|
+
/** String query condition for the unique_id value. Omitted: exact match. `gte` / `>=`: starts with. `lte` / `<=`: ends with. */
|
|
1382
1389
|
condition?: Condition | 'ne' | '!=';
|
|
1383
1390
|
}>, fetchOptions?: FetchOptions): Promise<DatabaseResponse<UniqueId>>;
|
|
1384
1391
|
/**
|
|
@@ -2201,13 +2208,17 @@ declare class Skapi {
|
|
|
2201
2208
|
* exactly. With `table` omitted entirely, every table is returned.
|
|
2202
2209
|
* `gte` / `>=` is a prefix search ("table names starting with x"), while
|
|
2203
2210
|
* `gt` / `>` is a lexicographic greater-than that spills past the prefix
|
|
2204
|
-
* into every later table name.
|
|
2211
|
+
* into every later table name. `lte` / `<=` is a suffix search ("table
|
|
2212
|
+
* names ending with x"); its matches come back in the order of the name
|
|
2213
|
+
* read from its last character backwards.
|
|
2205
2214
|
*
|
|
2206
2215
|
* Every combination:
|
|
2207
2216
|
* - `getTables({})`: every table in the project.
|
|
2208
2217
|
* - `getTables({ table: 'x' })`: exact match on 'x'.
|
|
2209
2218
|
* - `getTables({ table: 'x', condition: 'gte' })`: prefix, every table
|
|
2210
2219
|
* name starting with 'x'.
|
|
2220
|
+
* - `getTables({ table: 'x', condition: 'lte' })`: suffix, every table
|
|
2221
|
+
* name ending with 'x'.
|
|
2211
2222
|
* - `getTables({ table: '' })`: errors with '"table" should not be empty.'
|
|
2212
2223
|
* - `getTables({ condition: 'gte' })` with no `table`: errors with
|
|
2213
2224
|
* '"table" is required for condition.'
|
|
@@ -2250,7 +2261,7 @@ declare class Skapi {
|
|
|
2250
2261
|
/** If omitted, fetches the full list of tables. */
|
|
2251
2262
|
query?: {
|
|
2252
2263
|
table?: string;
|
|
2253
|
-
/** Condition operator of table name. Omitted: exact match on the given table name. `gte` / `>=`:
|
|
2264
|
+
/** Condition operator of table name. Omitted: exact match on the given table name. `gte` / `>=`: starts with. `lte` / `<=`: ends with. */
|
|
2254
2265
|
condition?: Condition;
|
|
2255
2266
|
}, fetchOptions?: FetchOptions): Promise<DatabaseResponse<Table>>;
|
|
2256
2267
|
/**
|
|
@@ -2265,6 +2276,14 @@ declare class Skapi {
|
|
|
2265
2276
|
* The only condition is `order.condition`, which requires `order.value`.
|
|
2266
2277
|
* Omitting it matches `order.value` exactly.
|
|
2267
2278
|
*
|
|
2279
|
+
* With `order.by: 'index_name'`, `order.value` is a piece of the name and
|
|
2280
|
+
* the condition searches the names: `>=` 'starts with', `<=` 'ends with',
|
|
2281
|
+
* `>` and `<` the names after and before it in order. 'Ends with' matches
|
|
2282
|
+
* the name segment right under `index` (or the first segment when `index`
|
|
2283
|
+
* is omitted), and returns what is nested under a match as well, the way
|
|
2284
|
+
* 'starts with' does: `index: 'Band.'` with `value: 'ers'` and `<=` finds
|
|
2285
|
+
* Band.Members, Band.Members.name and Band.Singers.
|
|
2286
|
+
*
|
|
2268
2287
|
* Every combination (`table` is required, so there is no no-argument
|
|
2269
2288
|
* form):
|
|
2270
2289
|
* - `getIndexes({ table: 't' })`: every index of table 't'.
|
|
@@ -2274,6 +2293,12 @@ declare class Skapi {
|
|
|
2274
2293
|
* the compound index, so Band.name, Band.year.
|
|
2275
2294
|
* - `getIndexes({ table: 't', order: { by: 'index_name', value: 'B' } })`:
|
|
2276
2295
|
* exact match against the value.
|
|
2296
|
+
* - `getIndexes({ table: 't', order: { by: 'index_name' } })`: every index
|
|
2297
|
+
* of the table, ordered by name.
|
|
2298
|
+
* - `getIndexes({ table: 't', order: { by: 'index_name', value: 'B', condition: '>=' } })`:
|
|
2299
|
+
* the index names that start with 'B'.
|
|
2300
|
+
* - `getIndexes({ table: 't', order: { by: 'index_name', value: 'e', condition: '<=' } })`:
|
|
2301
|
+
* the index names that end with 'e'.
|
|
2277
2302
|
* - `getIndexes({ table: 't', order: { by: 'total_number' } })`: the whole
|
|
2278
2303
|
* partition, ordered by that attribute.
|
|
2279
2304
|
* - `order.condition` without `order.value`: errors.
|
|
@@ -2315,9 +2340,9 @@ declare class Skapi {
|
|
|
2315
2340
|
order?: {
|
|
2316
2341
|
/** Key name to order by. */
|
|
2317
2342
|
by: 'average_number' | 'total_number' | 'number_count' | 'average_bool' | 'total_bool' | 'bool_count' | 'string_count' | 'index_name' | 'number_of_records';
|
|
2318
|
-
/** Value to query. */
|
|
2343
|
+
/** Value to query. A string when "by" is 'index_name': a piece of the index name. */
|
|
2319
2344
|
value?: number | boolean | string;
|
|
2320
|
-
/** Requires "value". Omitted: exact match against "value". */
|
|
2345
|
+
/** Requires "value". Omitted: exact match against "value". With "by" 'index_name': `>=` starts with, `<=` ends with. */
|
|
2321
2346
|
condition?: Condition;
|
|
2322
2347
|
};
|
|
2323
2348
|
}, fetchOptions?: FetchOptions): Promise<DatabaseResponse<Index>>;
|
|
@@ -2328,7 +2353,9 @@ declare class Skapi {
|
|
|
2328
2353
|
* `table` and `tag` together match the tag exactly, `table` alone is a
|
|
2329
2354
|
* prefix ('>=') that lists every tag in that table, and neither one
|
|
2330
2355
|
* returns every tag in the project, ordered by record count, descending.
|
|
2331
|
-
* `gte` / `>=` is a prefix search
|
|
2356
|
+
* `gte` / `>=` is a prefix search and `lte` / `<=` is a suffix search:
|
|
2357
|
+
* with `table` it finds the tags of that table that end with `tag`, and
|
|
2358
|
+
* with `tag` alone the tags that end with it in every table.
|
|
2332
2359
|
*
|
|
2333
2360
|
* Every combination:
|
|
2334
2361
|
* - `getTags({})`: every tag in the project, ordered by record count,
|
|
@@ -2340,6 +2367,10 @@ declare class Skapi {
|
|
|
2340
2367
|
* tables.
|
|
2341
2368
|
* - `getTags({ table: 't', tag: 'g', condition: 'gte' })`: prefix, every
|
|
2342
2369
|
* tag in 't' starting with 'g'.
|
|
2370
|
+
* - `getTags({ table: 't', tag: 'g', condition: 'lte' })`: suffix, every
|
|
2371
|
+
* tag in 't' ending with 'g'.
|
|
2372
|
+
* - `getTags({ tag: 'g', condition: 'lte' })` with no `table`: every tag
|
|
2373
|
+
* ending with 'g', in every table.
|
|
2343
2374
|
* - `getTags({ condition: 'gte' })` with neither `table` nor `tag`: errors
|
|
2344
2375
|
* with '"table" or "tag" is required for condition.'
|
|
2345
2376
|
*
|
|
@@ -2376,7 +2407,7 @@ declare class Skapi {
|
|
|
2376
2407
|
table?: string;
|
|
2377
2408
|
/** Tag name */
|
|
2378
2409
|
tag?: string;
|
|
2379
|
-
/** String query condition for tag name. Omitted: exact match when `table` and `tag` are both given, prefix when only `table` is given. */
|
|
2410
|
+
/** String query condition for tag name. Omitted: exact match when `table` and `tag` are both given, prefix when only `table` is given. `gte` / `>=`: starts with. `lte` / `<=`: ends with. */
|
|
2380
2411
|
condition?: Condition;
|
|
2381
2412
|
}, fetchOptions?: FetchOptions): Promise<DatabaseResponse<Tag>>;
|
|
2382
2413
|
/**
|
package/dist/skapi.js
CHANGED
|
@@ -213,7 +213,7 @@ var ol=Object.create;var et=Object.defineProperty;var Oi=Object.getOwnPropertyDe
|
|
|
213
213
|
}
|
|
214
214
|
|
|
215
215
|
runInterval(); // Start interval
|
|
216
|
-
`,l=new Blob([c],{type:"application/javascript"});Ge=new Worker(URL.createObjectURL(l)),Ge.onmessage=d=>{a.readyState===1&&a.send(JSON.stringify({action:"keepAlive"}));},i(a);},a.onmessage=async c=>{let l="";try{l=JSON.parse(decodeURI(c.data)),this.log("socket onmessage",l);}catch{return}let d;switch(!0){case !!l?.["#message"]:d="message";break;case !!l?.["#private"]:d="private";break;case !!l?.["#notice"]:d="notice";break;case !!l?.["#rtc"]:d="rtc";break;case !!l?.["#error"]:d="error";break}if(!d)return;let h={type:d,message:l?.["#rtc"]||l?.["#message"]||l?.["#private"]||l?.["#notice"]||l?.["#error"]||null,sender:l?.["#user_id"]||null,sender_cid:l?.["#scid"]?"cid:"+l["#scid"]:null,sender_rid:l?.["#srid"]||null,code:l?.["#code"]||null};if(d==="notice")t(h);else if(d==="rtc"){if(h.sender!==this.user.user_id){let u=h.message;if(u.hungup){Se[h.sender_cid]&&(Se[h.sender_cid](!1),delete Se[h.sender_cid]),ke[h.sender_cid]&&delete ke[h.sender_cid],D?.[h.sender_cid]&&Re.bind(this)({cid:h.sender_cid}),h.type="rtc:closed",t(h);return}if(u.candidate&&Ri.bind(this)(u.candidate,h.sender_cid),u.sdpoffer&&(Si.bind(this)(u.sdpoffer,h.sender_cid),ke[h.sender_cid]||(ke[h.sender_cid]=h.sender_cid,delete h.message,h.connectRTC=Ha.bind(this)(h),h.type="rtc:incoming",h.hangup=(()=>{D[h.sender_cid]?Re.bind(this)({cid:h.sender_cid}):ke[h.sender_cid]&&(delete ke[h.sender_cid],a.send(JSON.stringify({action:"rtc",uid:h.sender_cid,content:{hungup:this.user.user_id},token:this.session.accessToken.jwtToken})));}).bind(this),t(h))),u.pickup&&Se[h.sender_cid]&&(Se[h.sender_cid](!0),delete Se[h.sender_cid]),u.sdpanswer&&D[h.sender_cid])if(D[h.sender_cid].signalingState==="have-local-offer")await D[h.sender_cid].setRemoteDescription(new RTCSessionDescription(u.sdpanswer));else throw new f("Invalid signaling state.",{code:"INVALID_REQUEST"})}}else t(h);},a.onclose=()=>{Jt?(this.log("realtime onclose","WebSocket connection closed."),t({type:"close",message:"WebSocket connection closed."})):(this.log("realtime onclose","WebSocket unexpected close."),t({type:"error",message:"Skapi: WebSocket unexpected close."}),At++,At<3?(this.log("realtime onclose","Reconnecting to WebSocket server..."+At),t({type:"reconnect",message:"Reconnecting to WebSocket server..."+At}),St.bind(this)(t,3e3,"reconnect")):(this.log("realtime onclose","Max reconnection attempts reached."),t({type:"error",message:"Skapi: Max reconnection attempts reached."})));},a.onerror=()=>{this.log("realtime onerror","WebSocket connection error."),t({type:"error",message:"Skapi: WebSocket connection error."});};}catch(a){o(a);}},e);}),n.value=this.__socket,this.__socket}async function za(t,e,r){if(typeof window>"u"||window._runningInNodeJS)throw new f("WebSocket is not supported in Node.js environment.",{code:"NOT_SUPPORTED"});let n=this.__socket?await this.__socket:this.__socket;if(!n)throw new f("No realtime connection. Execute connectRealtime() before this method.",{code:"INVALID_REQUEST"});if(!e)throw new f("No recipient.",{code:"INVALID_REQUEST"});await _t.bind(this)(),t=$(t).data;let i="";if(r&&(r=b.Params(r,{config:{always:"boolean"},title:"string",body:"string"},["title","body"]),i=JSON.stringify({title:r.title,body:r.body}),new Blob([i]).size>3072))throw new f("Notification size exceeds 3kb.",{code:"INVALID_PARAMETER"});if(n.readyState===1){try{b.UserId(e),n.send(JSON.stringify({action:"sendMessage",uid:e,content:t,notification:i,notificationConfig:r?.config||{},token:`IdT:${this.service}:${this.owner}:`+(this.bearerToken||this.session?.idToken?.jwtToken||"null")}));}catch(s){if(this.log("postRealtime:err",{err:s}),Ve!==e)throw new f(`User has not joined to the recipient group. Run joinRealtime({ group: "${e}" })`,{code:"INVALID_REQUEST"});n.send(JSON.stringify({action:"broadcast",rid:e,content:t,notification:i,notificationConfig:r?.config||{},token:`IdT:${this.service}:${this.owner}:`+(this.bearerToken||this.session?.idToken?.jwtToken||"null")}));}return {type:"success",message:"Message sent."}}throw new f("Realtime connection is not open. Try reconnecting with connectRealtime().",{code:"INVALID_REQUEST"})}async function Rt(t){if(typeof window>"u"||window._runningInNodeJS)throw new f("WebSocket is not supported in Node.js environment.",{code:"NOT_SUPPORTED"});let e=this.__socket?await this.__socket:this.__socket;if(!e)throw new f("No realtime connection. Execute connectRealtime() before this method.",{code:"INVALID_REQUEST"});await _t.bind(this)(),t=$(t,{nullIfEmpty:true}).data;let{group:r=null}=t;if(!r&&!Ve)return {type:"success",message:"Left realtime message group."};if(r!==null&&typeof r!="string")throw new f('"group" must be a string | null.',{code:"INVALID_PARAMETER"});return e.readyState===1&&e.send(JSON.stringify({action:"joinRoom",rid:r,token:this.session.accessToken.jwtToken})),Ve=r,{type:"success",message:r?`Joined realtime message group: "${r}".`:"Left realtime message group."}}async function Ya(t,e){t=b.Params(t,{user_id:n=>b.UserId(n,'User ID in "user_id"'),group:["string",()=>{if(!Ve)throw new f('No group has been joined. Otherwise "group" is required.',{code:"INVALID_REQUEST"});return Ve}]});let r=await C.bind(this)("get-ws-group",t,{fetchOptions:e,auth:true,method:"post"});return r.list=r.list.map(n=>({user_id:n.uid.split("#")[1],cid:"cid:"+n.cid})),r}async function Qa(t,e){if(await this.__connection,t||(t={searchFor:"group",value:" ",condition:">"}),t=b.Params(t,{searchFor:["group","number_of_users",()=>"group"],value:["string","number",()=>t?.searchFor&&t?.searchFor==="number_of_users"?0:" "],condition:[">",">=","=","<","<=","!=","gt","gte","eq","lt","lte","ne"],range:["string","number"]}),t.condition||(t.value===" "||!t.value?t.condition=">":t.condition="="),t.range&&t.condition&&delete t.condition,t.searchFor==="number_of_users"&&typeof t.value!="number")throw new f('"value" must be a number.',{code:"INVALID_PARAMETER"});if(t.searchFor==="group"&&typeof t.value!="string")throw new f('"value" must be a string.',{code:"INVALID_PARAMETER"});if(t.hasOwnProperty("range")&&typeof t.range!=typeof t.value)throw new f(`"range" must be a ${typeof t.value}.`,{code:"INVALID_PARAMETER"});let r=await C.bind(this)("get-ws-group",t,{fetchOptions:e,auth:true,method:"post"});return r.list=r.list.map(n=>({group:n.rid.split("#")[1],number_of_users:n.cnt})),r}var ch=typeof FormData<"u",Za=typeof HTMLFormElement<"u",ec=typeof SubmitEvent<"u",Ue={},zt={},de={};function Yt(t){return Object.freeze({id:t,status:"stopped"})}function Ii(t){return !!t&&typeof t=="object"&&t.status==="stopped"}var tc=3;function rc(t,e,r){let n=false,i=Array.isArray(t?.chunks)?t.chunks.slice():[];i.sort((s,o)=>(s?.seq||0)-(o?.seq||0));for(let s of i)if(!(!s||typeof s.seq!="number"||s.seq<=e.seq)&&(e.seq=s.seq,n=true,r&&typeof s.txt=="string"&&s.txt!==""))try{r(s.txt,s.seq,"poll");}catch(o){console.error(o);}return typeof t?.last_seq=="number"&&t.last_seq>e.seq&&(e.seq=t.last_seq,n=true),n}var lh=2e3,nc=5e3,uh=2e3,dh=5,fh=1500,Wr=null;function ic(t,e,r){let n=new Map,i=false,s=false,o=0,a={socket:0,poll:0},c=(u,g,p)=>{if(t.seq=u,!(!e||typeof g!="string"||g===""))try{e(g,u,p);}catch(m){console.error(m);}},l=()=>{for(let u of Array.from(n.keys()))u<=t.seq&&n.delete(u);for(;;){let u=t.seq+1;if(!n.has(u))break;let g=n.get(u);n.delete(u),c(u,g.txt,g.via);}};return {cursor:t,open:()=>{i||s||(i=true,l());},fromPoll:u=>{if(s)return false;let g=t.seq,p=t.seq,m=Array.isArray(u?.chunks)?u.chunks:[];for(let y of m){if(!y||typeof y.seq!="number"||y.seq<=t.seq)continue;let A=!n.has(y.seq);A&&(a.poll++,r&&a.poll===1&&r("poll",y.seq)),n.set(y.seq,{txt:typeof y.txt=="string"?y.txt:"",via:A?"poll":n.get(y.seq).via}),y.seq>p&&(p=y.seq);}typeof u?.last_seq=="number"&&u.last_seq>p&&(p=u.last_seq);let _=Array.from(n.keys()).sort((y,A)=>y-A);for(let y of _){if(y<=t.seq){n.delete(y);continue}if(y>p)break;let A=n.get(y);n.delete(y),c(y,A.txt,A.via);}return p>t.seq&&(t.seq=p),l(),t.seq>g},fromSocket:(u,g)=>{s||typeof u!="number"||!Number.isFinite(u)||(o=Date.now(),!(u<=t.seq)&&(!n.has(u)&&n.size>=uh||(n.has(u)||(a.socket++,r&&a.socket===1&&r("socket",u)),n.set(u,{txt:typeof g=="string"?g:"",via:n.has(u)?n.get(u).via:"socket"}),i&&l())));},warm:()=>o!==0&&Date.now()-o<lh,stats:()=>({socket:a.socket,poll:a.poll}),close:()=>{s=true,n.clear();}}}function sc(t){if(!this||!this.__network_logs)return {onTransport:void 0,done:()=>{}};let e=Date.now(),r=false;return {onTransport:(n,i)=>{console.log(`%cSKAPI: stream chunk arrived over ${n==="socket"?"WEBSOCKET":"POLL"}`,`color: ${n==="socket"?"green":"orange"};`,{id:t,first_seq:i,after_ms:Date.now()-e});},done:n=>{if(r||!n)return;r=true;let i=n.stats();console.log("%cSKAPI: stream transport","color: blue;",{id:t,over_websocket:i.socket,over_poll:i.poll,took_ms:Date.now()-e});}}}function oc(t,e){let r={stop:()=>{}};if(typeof window>"u"||window._runningInNodeJS||Wr)return r;let n={stopped:false,socket:null,opened:null,joined:false,attempts:0,unavailable:false};Wr=n;let i=l=>{if(n.stopped)return;let d=l?.data;if(typeof d!="string")return;let h=null;try{h=JSON.parse(d);}catch{try{h=JSON.parse(decodeURI(d));}catch{return}}let u=h?.["#message"];if(u==null)return;if(typeof u=="string")try{u=JSON.parse(u);}catch{return}if(typeof u!="object")return;let g=h?.["#srid"];if(typeof g=="string"&&g!==t)return;let p=u.seq;typeof p=="string"&&p!==""&&(p=Number(p)),e.fromSocket(p,u.txt);},s=()=>{if(n.socket){try{n.socket.removeEventListener("message",i);}catch{}try{n.socket.removeEventListener("close",a);}catch{}n.socket=null;}},o=async()=>{let l=n.opened,d=n.joined;if(n.opened=null,n.joined=false,s(),!(!d&&!l))try{let h=this.__socket?await this.__socket:null;if(l&&h===l){await Gr.bind(this)();return}d&&h&&Ja()===room&&await Rt.bind(this)({group:null});}catch{}},a=()=>{n.stopped||(s(),!n.unavailable&&(n.attempts>=dh||(n.attempts+=1,setTimeout(()=>{n.stopped||c();},fh))));},c=async()=>{try{let l=this.__socket?await this.__socket:null;if(n.stopped){o();return}if(!l){if(!this.session){n.unavailable=!0,o();return}if(await St.bind(this)(()=>{},0),l=this.__socket?await this.__socket:null,n.stopped){o();return}l&&!n.opened&&(n.opened=l);}if(!l||l.readyState!==1)return;if(l.addEventListener("message",i),l.addEventListener("close",a),n.socket=l,!n.joined&&(await Rt.bind(this)({group:t}),n.joined=!0,n.stopped)){o();return}}catch{}};return c(),{stop:()=>{n.stopped||(n.stopped=true,Wr===n&&(Wr=null),o());}}}function ac(t){return t?.status==="running"||t?.status==="pending"}function cc(t){return !!t&&typeof t=="object"&&!Array.isArray(t)&&typeof t.status=="string"&&typeof t.id=="string"&&"in_queue"in t}function lc(t,e,r,n){if(!t||typeof t!="string")throw new f('"requestId" should be type: <string>.',{code:"INVALID_PARAMETER"});if(t.includes("#"))return t;if(!e||typeof e!="string"||!r||typeof r!="string")throw new f('"url" and "method" are required to address a request by its short id.',{code:"INVALID_PARAMETER"});return b.Url(e),`[${r.toUpperCase()}]${e.toLowerCase()}#${n}:${t}`}function uc({id:t,auth:e,service:r,owner:n,latency:i=1e3,queue:s,seedExecuted:o,onResponse:a,onError:c,onStream:l,realtimeGroup:d}){if(typeof i!="number")throw new f('"latency" should be a number.',{code:"INVALID_PARAMETER"});if(i<0)throw new f('"latency" should be a non-negative number.',{code:"INVALID_PARAMETER"});s&&!Ue?.[s]&&(Ue[s]=new jt({breakWhenError:false,batchSize:1}));let h={stop:null,aborted:false,queue:s};de[t]=h;let u=null,g=()=>{de[t]===h&&delete de[t];},p=()=>new Promise((_,y)=>{let A=false;if(h.aborted){g(),_(Yt(t));return}let w={seq:0},T=sc.call(this,t),S=l&&d?ic(w,l,T.onTransport):null,k=S?oc.call(this,d,S):null,L=()=>{T.done(S),k&&k.stop(),S&&S.close();};u=L;let N=0,x=false,U=0,F=typeof o=="number"&&o>0?o:void 0,B=async()=>{if(!(A||x)&&!(S&&S.warm()&&Date.now()-N<nc)){x=true;try{for(;;){let ie={id:t,service:r,owner:n};l&&(ie.since=w.seq),N=Date.now();let M=await C.bind(this)("csr-poll",ie,{auth:e});if(A)return;let X=S?S.fromPoll(M):l?rc(M,w,l):!1;S&&S.open();let Zt=ac(M);if(typeof M?.executed=="number"&&M.executed>0&&(F=M.executed),M?.more&&X){U=0;continue}if(Zt){U=0;return}if(U=M?.more?U+1:0,M?.more&&U<tc)return;A=!0,a&&a(M,F!==void 0?{executed:F}:void 0),clearInterval(te),L(),g(),_(M);return}}catch(ie){if(A)return;A=true,c&&c(ie),clearInterval(te),L(),g(),y(ie);}finally{x=false;}}},te=setInterval(B,i);S&&B(),h.stop=()=>{A||(A=true,clearInterval(te),L(),g(),_(Yt(t)));};}),m=()=>{let _=de[t];_&&(_.stop?_.stop():(_.aborted=true,delete de[t]));};if(s){let _=new Promise((y,A)=>{let w=false,T=Ue[s].add([async()=>{try{let S=await p();return w||(w=!0,y(S)),S}catch(S){throw w||(w=true,A(S)),S}}])[0];zt[t]=T,h.stop=()=>{if(!w){h.aborted=true,u&&u();try{Ue[s]&&Ue[s].remove(zt[t]);}catch{}delete zt[t],g(),w=true,y(Yt(t));}};});return Object.assign(_,{stop:m})}else return Object.assign(p(),{stop:m})}function zr(t){let e=0,r=[];if(t?.id){if(t.url&&t.method){let n=t.service||this.service;r.push(`[${t.method.toUpperCase()}]${t.url.toLowerCase()}#${n}:${t.id}`);}r.push(t.id);}else if(t?.queue)for(let n in de)de[n]?.queue===t.queue&&r.push(n);else for(let n in de)r.push(n);for(let n of r){let i=de[n];i&&(i.stop?i.stop():(i.aborted=true,delete de[n]),e+=1);}return e}function Pi(t,e){if(!t.queue)throw new f('"queue" is required.',{code:"INVALID_PARAMETER"});let r=()=>C.bind(this)("csr-poll",{service:t.service||this.service,owner:t.owner||this.owner,queue:t.queue+":"},{auth:true});return this.__projectIdInput?this.__projectIdInput.then(r):r()}function hh(t){if(typeof Buffer<"u"&&typeof Buffer.from=="function")return Buffer.from(t).toString("base64");if(typeof btoa=="function"){let e="";for(let n=0;n<t.length;n+=32768)e+=String.fromCharCode.apply(null,Array.from(t.subarray(n,n+32768)));return btoa(e)}throw new f("No base64 encoder available in this environment.",{code:"NOT_SUPPORTED"})}var Xa=2*1024*1024-64*1024;function Jr(t){return typeof File<"u"&&t instanceof File||typeof Blob<"u"&&t instanceof Blob}function Ti(t){if(Array.isArray(t)){let e=[];for(let r of t)Jr(r)||e.push(Ti(r));return e}if(t&&typeof t=="object"&&!Jr(t)){let e=Object.getPrototypeOf(t);if(e!==Object.prototype&&e!==null)return t;let r={};for(let n in t)Jr(t[n])||(r[n]=Ti(t[n]));return r}return t}function ph(t){if(t==null)return null;let e=$(t)?.data;return !e||typeof e!="object"||Array.isArray(e)?null:Ti(e)}function dc(t,e,r){if(r!==void 0){if(Array.isArray(r)){for(let n of r)dc(t,e,n);return}if(Jr(r)){t.append(e,r);return}if(r===null){t.append(e,"");return}if(typeof r=="object"){t.append(e,JSON.stringify(r));return}t.append(e,String(r));}}async function gh(t){if(t==null)throw new f('"multipart": true needs a form body in the first argument.',{code:"INVALID_PARAMETER"});if(typeof FormData>"u"||typeof Response>"u")throw new f('"multipart": true is not available in this environment.',{code:"NOT_SUPPORTED"});let e;if(ec&&t instanceof SubmitEvent)e=new FormData(t.target);else if(Za&&t instanceof HTMLFormElement)e=new FormData(t);else if(t instanceof FormData)e=t;else if(typeof t=="object"&&!Array.isArray(t)){e=new FormData;for(let s in t)dc(e,s,t[s]);}else throw new f('"form" should be a submit event, a form element, FormData, or an object.',{code:"INVALID_PARAMETER"});let r=new Response(e),n=r.headers.get("content-type"),i=hh(new Uint8Array(await r.arrayBuffer()));if(i.length>Xa)throw new f(`Multipart body is too large: ${i.length} bytes once base64 encoded, and the limit is ${Xa}. Upload the file first and send its url instead.`,{code:"INVALID_PARAMETER"});return {body_b64:i,body_content_type:n}}function mh(t){if(t!=null){if(typeof t=="boolean")return t;if(typeof t=="object"&&!Array.isArray(t))return {user:!!t.user,service:!!t.service};throw new f('"skapiHeaders" should be type: <boolean> or { user?: boolean; service?: boolean }.',{code:"INVALID_PARAMETER"})}}function yh(t){if(!(!t||typeof t!="object")){for(let e in t)if(typeof e=="string"&&e.toLowerCase().indexOf("x-skapi-")===0)throw new f(`"headers" cannot set "${e}": the "x-skapi-" prefix is reserved. Use "skapiHeaders" to tell the destination who the caller is.`,{code:"INVALID_PARAMETER"})}}async function fc(t,e){let r=false,n=!!(t?.secretName||t?.clientSecretName),i=e?.signal;if(i?.aborted)throw new f('"signal" was already aborted.',{code:"INVALID_REQUEST"});if(typeof t.poll=="number"&&t.poll<0)throw new f('"poll" should be a non-negative number.',{code:"INVALID_PARAMETER"});let s=t?.onResponse,o=t?.onError,a=t?.onStream,c=typeof t.poll=="number"?t.poll:t.poll?1e3:0;delete t.poll,(c||t.stream)&&!t.queue&&(t.queue=(this.__user?.user_id||"anonymous")+"-"+Ye());let l=u=>{for(let g in u)if(typeof u[g]=="string"&&u[g].includes("$CLIENT_SECRET")){r=true;break}};if(t=b.Params(t,{url:u=>{if(!u||typeof u!="string")throw new f('"url" should be type: <string>.',{code:"INVALID_PARAMETER"});return b.Url(u),u.includes("$CLIENT_SECRET")&&(r=true),u},secretName:"string",clientSecretName:"string",method:u=>{if(u&&typeof u!="string")throw new f('"method" should be one of "GET", "POST", "PUT", "PATCH", "DELETE" or "HEAD".',{code:"INVALID_PARAMETER"});let g=u.toLowerCase();if(g!=="get"&&g!=="post"&&g!=="delete"&&g!=="put"&&g!=="patch"&&g!=="head")throw new f('"method" should be one of "GET", "POST", "PUT", "PATCH", "DELETE" or "HEAD".',{code:"INVALID_PARAMETER"});return g},stream:u=>{if(u!=null&&typeof u!="boolean")throw new f('"stream" should be type: <boolean>.',{code:"INVALID_PARAMETER"});return !!u},realtime:u=>{if(u!=null&&typeof u!="boolean")throw new f('"realtime" should be type: <boolean>.',{code:"INVALID_PARAMETER"});return !!u},headers:u=>{if(u&&typeof u!="object")throw new f('"headers" should be type: <object>.',{code:"INVALID_PARAMETER"});return yh(u),l(u),u},skapiHeaders:u=>mh(u),data:u=>{if(u&&typeof u!="object")throw new f('"data" should be type: <object>.',{code:"INVALID_PARAMETER"});return l(u),u},params:u=>{if(u&&typeof u!="object")throw new f('"params" should be type: <object>.',{code:"INVALID_PARAMETER"});return l(u),u},body_b64:"string",body_content_type:"string",expires:"number",queue:"string"},e?.requireSecretName?["clientSecretName","method","url"]:["method","url"]),t.realtime&&!t.stream)throw new f('"realtime" requires "stream": true.',{code:"INVALID_PARAMETER"});if(t.body_b64&&t.data)throw new f('"data" cannot be sent with "multipart": true.',{code:"INVALID_PARAMETER"});if(n&&!r){let u=t.method==="get"||t.method==="delete"||t.method==="head"?'"params"':'"data"';throw new f(`At least one parameter value should include "$CLIENT_SECRET" in ${u} or "headers".`,{code:"INVALID_PARAMETER"})}await this.__connection;let d=!!this.__user,h=()=>C.bind(this)("csr",t,{auth:d,tokenHeaders:{accessToken:!!d}}).then(u=>{if(u.status==="running"||u.status==="pending"){let g=`[${t.method.toUpperCase()}]${t.url.toLowerCase()}`,p=t.service||this.service,m=t.owner||this.owner,_=`${g}#${p}:${u.id}`;if(i){let y=()=>{zr.call(this,{id:_});};i.aborted?y():i.addEventListener("abort",y,{once:true});}Object.assign(u,{poll:y=>uc.call(this,{id:_,auth:d,service:p,owner:m,latency:y?.latency||1e3,queue:t?.queue,onResponse:s,onError:o,onStream:y?.onStream||a,realtimeGroup:u?.realtime_group})});}return s?s(u):u}).catch(u=>{if(o)return o(u);throw u});if(t?.queue){let u="base:"+t.queue;return Ue?.[u]||(Ue[u]=new jt({breakWhenError:false,batchSize:1})),new Promise((g,p)=>{Ue[u].add([async()=>{try{let m=await h();if(c>0){let _=m.poll({latency:c});return i&&(i.aborted?_.stop():i.addEventListener("abort",()=>_.stop(),{once:!0})),g(_),_}return g(m),m}catch(m){throw p(m),m}}]);})}else return h()}async function hc(t,e){if(!e||typeof e!="object")throw new f('"options" is required in the second argument.',{code:"INVALID_PARAMETER"});if(e.apiKeyHeader!==void 0||e.apiKeyScheme!==void 0)throw new f('"apiKeyHeader" and "apiKeyScheme" are no longer supported. Store the key as a client secret, name it with "secretName", and put "$CLIENT_SECRET" where the key goes.',{code:"INVALID_PARAMETER"});if(e.multipart!==void 0&&e.multipart!==null&&typeof e.multipart!="boolean")throw new f('"multipart" should be type: <boolean>.',{code:"INVALID_PARAMETER"});let r=e.responseType;if(r!=null){if(r==="response")throw new f(`"responseType": "response" is not available here. The request is relayed from the server and what comes back is the stored answer, not a live Response; the destination's status code is the "status_code" of the row forwardRequestHistory lists.`,{code:"INVALID_PARAMETER"});if(r!=="json"&&r!=="text")throw new f('"responseType" should be either "json" or "text".',{code:"INVALID_PARAMETER"})}let n=e.method||"POST",i=typeof n=="string"?n.toLowerCase():"",s=i==="get"||i==="delete"||i==="head"?"params":"data",o={url:e.url,method:n};if(e.secretName!==void 0&&(o.secretName=e.secretName),e.headers!==void 0&&(o.headers=e.headers),e.data!==void 0&&(o.data=e.data),e.params!==void 0&&(o.params=e.params),e.skapiHeaders!==void 0&&(o.skapiHeaders=e.skapiHeaders),e.service!==void 0&&(o.service=e.service),e.owner!==void 0&&(o.owner=e.owner),e.queue!==void 0&&(o.queue=e.queue),e.expires!==void 0&&(o.expires=e.expires),e.stream!==void 0&&(o.stream=e.stream),e.realtime!==void 0&&(o.realtime=e.realtime),e.poll!==void 0&&(o.poll=e.poll),e.onStream!==void 0&&(o.onStream=e.onStream),e.onResponse!==void 0&&(o.onResponse=e.onResponse),e.onError!==void 0&&(o.onError=e.onError),e.multipart){if(e.data!==void 0&&e.data!==null)throw new f('"data" cannot be sent with "multipart": true. The form itself is the body.',{code:"INVALID_PARAMETER"});let c=await gh(t);o.body_b64=c.body_b64,o.body_content_type=c.body_content_type;}else {let c=ph(t);c&&Object.keys(c).length&&(o[s]=Object.assign({},c,o[s]||{}));}let a=fc.call(this,o,{signal:e.signal});return r?a.then(c=>{if(cc(c)||Ii(c))return c;if(r==="text")return typeof c=="string"?c:JSON.stringify(c);if(typeof c=="string")try{return JSON.parse(c)}catch{return c}return c}):a}async function pc(t){return fc.call(this,t,{requireSecretName:true})}async function Ci(t,e){await this.__connection;let r=t.service||this.service,n=t.owner||this.owner;t=b.Params(t,{url:"string",method:["GET","POST","PUT","PATCH","DELETE","HEAD"],queue:"string",status:["pending","running","resolved","failed"],compact:"boolean",queue_exact:"boolean",queue_exclude:"string"},["url","method"]);let i=!!this.__user,s=`[${t.method.toUpperCase()}]${t.url.toLowerCase()}#${r}:`,o={id:s,queue:t?.queue,status:t?.status,service:r,owner:n};t?.compact&&(o.compact=true),t?.queue_exact&&(o.queue_exact=true),t?.queue_exclude&&(o.queue_exclude=t.queue_exclude),Object.keys(o).forEach(c=>{o[c]||delete o[c];}),o.queue&&(o.id_prefix=o.id,delete o.id);let a=await C.bind(this)("csr-poll",o,{auth:i,fetchOptions:e});return a.list=a.list.map(c=>{let l={id:c.id,status_code:c.rslv?.status_code||null,response_body:c.rslv?.body||c.rslv?.truncated||null,error:c?.err,created:c?.stmp,updated:c?.utmp,executed:typeof c?.att=="number"?c.att*1e3:void 0,request_body:c?.reqbdy,expires:c?.expt,status:c.stts,queue_name:c?.qid,request_text:c?.reqtxt,response_text:c?.rslvtxt,response_complete_marker:c?.rslvmk!=null?!!c.rslvmk:void 0,compact:c?.cmpct?true:void 0};for(let d in l)l[d]===void 0&&delete l[d];return (l.status==="running"||l.status==="pending")&&(l.poll=d=>uc.call(this,{id:s+l.id,auth:i,service:r,owner:n,latency:d?.latency||1e3,queue:c?.qid,seedExecuted:l.executed,onResponse:d?.onResponse,onError:d?.onError,onStream:d?.onStream})),l}),a}async function xi(t){await this.__connection,t=b.Params(t,{url:"string",method:["GET","POST","PUT","PATCH","DELETE","HEAD"],id:"string",queue:"string"},["url","method","id"]);let e=t?.service||this.service,r=t?.owner||this.owner,n=!!this.__user,i=`[${t.method.toUpperCase()}]${t.url.toLowerCase()}#${e}`,s=t.id,o=`${i}:${s}`,a=t?.queue;return a&&Ue?.[a]&&(Ue[a].remove(zt[o]),delete zt[o]),C.bind(this)("csr-cancel",{id:o,service:e,owner:r},{auth:n})}function ki(t,e){let r=typeof e?.poll=="number"?e.poll:1e3;if(!Number.isFinite(r)||r<0)throw new f('"poll" should be a non-negative number.',{code:"INVALID_PARAMETER"});if(!t||typeof t!="string")throw new f('"requestId" should be type: <string>.',{code:"INVALID_PARAMETER"});if(e?.since!==void 0&&typeof e.since!="number")throw new f('"since" should be a number.',{code:"INVALID_PARAMETER"});if(e?.realtimeGroup!==void 0&&e.realtimeGroup!==null&&typeof e.realtimeGroup!="string")throw new f('"realtimeGroup" should be type: <string>.',{code:"INVALID_PARAMETER"});let n=typeof e?.since=="number"&&e.since>0?e.since:0,i=e?.onStream,s=e?.onResponse,o=e?.onError,a={stopped:false,fullId:t,resolve:null},c=null,l={stop:null,aborted:false},d=()=>{de[a.fullId]===l&&delete de[a.fullId];},h=()=>{a.stopped||(a.stopped=true,c&&c(),d(),a.resolve&&a.resolve(Yt(a.fullId)));};l.stop=h;let u=new Promise(async(g,p)=>{a.resolve=g;try{await this.__connection;let m=!!this.__user,_=e?.service||this.service,y=e?.owner||this.owner;if(a.fullId=lc(t,e?.url,e?.method,_),a.stopped){g(Yt(a.fullId));return}de[a.fullId]=l;let A={seq:n},w=0,T=sc.call(this,a.fullId),S=i&&e?.realtimeGroup?ic(A,i,T.onTransport):null,k=S?oc.call(this,e.realtimeGroup,S):null,L=()=>{T.done(S),k&&k.stop(),S&&S.close();};for(c=L;;){let N=await C.bind(this)("csr-poll",{id:a.fullId,service:_,owner:y,since:A.seq},{auth:m});if(a.stopped)return;if(!cc(N)){L(),d(),s&&s(N),g(N);return}let x=S?S.fromPoll(N):rc(N,A,i);S&&S.open();let U=ac(N);if(N.more&&x){w=0;continue}if(w=N.more?w+1:0,!U&&(!N.more||w>=tc)){L(),d(),s&&s(N),g(N);return}if(await new Promise(F=>setTimeout(F,S&&S.warm()?Math.max(r,nc):r)),a.stopped)return}}catch(m){if(a.stopped)return;c&&c(),d(),o&&o(m),p(m);}});return Object.assign(u,{stop:h})}async function Ui(t,e,r){await this.__connection;let n=r?.service||this.service,i=r?.owner||this.owner,s=!!this.__user,o=lc(t,r?.url,r?.method,n);return C.bind(this)("csr-finalize",{id:o,data:e,service:n,owner:i},{auth:s})}var gc=ki,mc=Ui,yc=Ci,_c=xi,bc=zr,wc=Pi;async function Ec(t){await this.__connection;let e={name:"string",email:r=>(b.Email(r),r),subject:"string",message:"string"};return t=b.Params(t,e,["name","email","subject","message"]),await C.bind(this)("send-inquiry",t),"SUCCESS: Inquiry has been sent."}async function Ac(t,e){if(await this.__connection,ch&&t instanceof FormData||Za&&t instanceof HTMLFormElement||ec&&t instanceof SubmitEvent){if(!e)throw new f("Url string as a second argument is required when form is passed.",{code:"INVALID_PARAMETER"});let n=$(t);t={url:e,data:n.data,sync:true};}let r={url:n=>b.Url(n),data:n=>n,sync:["boolean",()=>true]};if(Array.isArray(t))for(let n of t)n=b.Params(n,r);else t=b.Params(t,r);return C.bind(this)("post-secure",t,{auth:true})}async function Sc(t,e){await this.__connection;let{auth:r=false,method:n="POST",bypassAwaitConnection:i=false,responseType:s,contentType:o,tokenHeaders:a,progress:c}=e||{};if(e=Object.assign({auth:r,method:n,bypassAwaitConnection:i,responseType:s,contentType:o,tokenHeaders:a},{fetchOptions:{progress:c}}),typeof t!="object"&&(o==="application/json"||o===void 0))throw new f('"data" should be type: <object>.',{code:"INVALID_PARAMETER"});return C.bind(this)("mock",t,e)}async function Rc(t,e){await this.__connection,t=b.Params(t||{},{access_group:n=>{if(n==="authorized"&&(n=1),n==="public"&&(n=0),typeof n!="number")throw new f('"access_group" should be type number.',{code:"INVALID_PARAMETER"});if(n<0)throw new f('"access_group" should be zero or a positive number.',{code:"INVALID_PARAMETER"});if(n>this.__user.access_group)throw new f("User has no access.",{code:"INVALID_REQUEST"});return n}});let r=await C.bind(this)("get-feed",t,{auth:true,fetchOptions:e});return Array.isArray(r?.list)&&(r.list=await Promise.all(r.list.map(n=>Ze.bind(this)(n)))),r}function Qt(t){if(t===this.__user.user_id)throw new f(`"user_id" cannot be the user's own ID.`,{code:"INVALID_PARAMETER"});return b.UserId(t,'"user_id"')}async function vc(t,e){if(t=$(t,{ignoreEmpty:true}).data,t=b.Params(t,{subscriber:n=>b.UserId(n,'User ID in "subscriber"'),subscription:Qt.bind(this),blocked:"boolean"}),!t.subscriber&&!t.subscription)throw new f('At least either "subscriber" or "subscription" should have a value.',{code:"INVALID_PARAMETER"});let r=await C.bind(this)("get-subscription",t,Object.assign({auth:true},{fetchOptions:e}));return r.list=r.list.map((n=>{let i={};if(n.sub){let s=n.sub.split("#");i.subscriber=s[2],i.subscription=s[0];}else i.subscriber=n.subscriber,i.subscription=n.subscription;return i.timestamp=n?.timestamp||n.stmp,i.blocked=n?.blocked||n.grp.substring(0,1)==="N",Object.assign(i,n.opt),i})),r}async function Tc(t){await this.__connection,t=b.Params(t,{user_id:Qt.bind(this),get_feed:"boolean",get_notified:"boolean",get_email:i=>{if(i&&(!this.__user.email||!this.__user.email_verified))throw new f("User has no verified email address.",{code:"INVALID_REQUEST"});return !!i}},["user_id"]);let e={};for(let i of ["get_feed","get_notified","get_email"])typeof t[i]=="boolean"&&(e[i]=t[i]);let r=await C.bind(this)("subscription",{subscribe:t.user_id,option:e},{auth:true}),n={};if(r.sub){let i=r.sub.split("#");n.subscriber=i[2],n.subscription=i[0];}else n.subscriber=r.subscriber,n.subscription=r.subscription;return n.timestamp=r?.timestamp||r.stmp,n.blocked=r?.blocked||r.grp.substring(0,1)==="N",Object.assign(n,r.opt),n}async function Ic(t){await this.__connection;let{user_id:e}=b.Params(t,{user_id:Qt.bind(this)},["user_id"]);return await C.bind(this)("subscription",{unsubscribe:e},{auth:true})}async function Pc(t){await this.__connection;let{user_id:e}=b.Params(t,{user_id:Qt.bind(this)},["user_id"]);return await C.bind(this)("subscription",{block:e},{auth:true})}async function Cc(t){await this.__connection;let{user_id:e}=b.Params(t,{user_id:Qt.bind(this)},["user_id"]);return await C.bind(this)("subscription",{unblock:e},{auth:true})}async function xc(t,e){await this.__connection;let r=await ee.bind(this)();if(t=b.Params(t||{},{user_id:o=>{if(o!==this.__user.user_id&&!r)throw new f("No access.",{code:"INVALID_REQUEST"});return o},group:o=>b.newsletterGroup(o,{allowNull:true}),email:o=>{if(typeof o!="string"||!o.trim())throw new f('"email" should be a non-empty string.',{code:"INVALID_PARAMETER"});if(o.trim().length>255)throw new f('"email" should be at most 255 characters.',{code:"INVALID_PARAMETER"});return o.trim().toLowerCase()}}),t.email!==void 0){if(t.user_id!==void 0&&t.user_id!==null)throw new f('"email" cannot be used with "user_id".',{code:"INVALID_PARAMETER"});if(t.group===void 0||t.group===null)throw new f('"group" is required to search by "email".',{code:"INVALID_PARAMETER"})}let n=await C.bind(this)("get-newsletter-subscription",t,{auth:true,fetchOptions:e||null}),i=n?.list||n,s=[];Array.isArray(i)||(i=[]);for(let o of i){let a=o.subt.split("#"),c=true;a[0].charAt(0)==="@"&&(c=false,a[0]=a[0].substring(1));let l=/^\d+$/.test(a[0])?parseInt(a[0]):a[0],d={timestamp:o.stmp,group:l,subscribed_email:a[1],active:c};typeof o.email_token=="string"&&o.email_token&&(d.subscriber_token=o.email_token),s.push(d);}return n?.list?(n.list=s,n):s}async function kc(t){await this.__connection;let e=b.Params(t||{},{email:r=>Array.isArray(r)&&r.length>0?r.length===1?b.Email(r[0]):r.map(n=>b.Email(n)):b.Email(r),group:r=>b.newsletterGroup(r),redirect:r=>b.Url(r)},this.__user?["group"]:["email","group"]);return C.bind(this)(`subscribe-${this.__user?"":"public-"}newsletter`,e,{auth:!!this.__user})}async function Uc(t){await this.__connection;let e=b.Params(t||{},{group:r=>b.newsletterGroup(r,{nameOnly:true}),restriction:r=>{if(typeof r!="number"||!Number.isInteger(r)||r<0||r>99)throw new f('"restriction" should be a number between 0 and 99.',{code:"INVALID_PARAMETER"});return r},name:r=>{if(typeof r!="string"||r.length>60)throw new f('"name" should be a string of 60 characters or less.',{code:"INVALID_PARAMETER"});return r}},["group"]);return C.bind(this)("register-newsletter-group",e,{auth:true})}async function Dc(t){await this.__connection;let e=b.Params(t||{},{group:r=>b.newsletterGroup(r,{nameOnly:true})},["group"]);return C.bind(this)("delete-newsletter-group",e,{auth:true})}async function Nc(){return await this.__connection,C.bind(this)("newsletter-group-endpoint",null,{auth:true})}async function Oc(t){await this.__connection,t=b.Params(t,{group:r=>b.newsletterGroup(r,{allowNull:true})},["group"]);let e=Object.assign({action:"unsubscribe"},t);return C.bind(this)("subscribe-newsletter",e,{auth:true})}async function Fc(t,e){let r=await ee.bind(this)(),n={message_id:"string",timestamp:"number",read:"number",complaint:"number",subject:"string",bounced:"number"};t||(e=Object.assign({ascending:false},e||{})),t=$(t).data,t=t||{searchFor:"timestamp",value:Date.now(),condition:"<",group:"public"},t=b.Params(t,{searchFor:["message_id","timestamp","subject","complaint","read","bounced"],value:c=>{if(typeof c!==n[t.searchFor])throw new f(`"value" type does not match the type of "${t.searchFor}" index.`,{code:"INVALID_PARAMETER"});if(typeof c=="string"&&!c)throw new f('"value" should not be empty string.',{code:"INVALID_PARAMETER"});return c},range:c=>{if(!t.hasOwnProperty("value")||typeof c!=typeof t.value)throw new f('"range" should match type of "value".',{code:"INVALID_PARAMETER"});return c},condition:[">",">=","=","<","<=","gt","gte","eq","lt","lte",()=>"="],group:c=>{let l=b.newsletterGroup(c);if(l===0)return 0;if(typeof l=="string")return l;if(!this.session)throw new f("User should be logged in.",{code:"INVALID_REQUEST"});if(c==="authorized")return 1;if(!r&&l>parseInt(this.user?.access_group||this.session?.idToken?.payload?.access_group))throw new f("User has no access.",{code:"INVALID_REQUEST"});return l}},["searchFor","value","group"]);let i=t.group===0||typeof t.group=="string"&&!this.__user?"get-public-newsletters":"get-newsletters",s=await C.bind(this)(i,t,Object.assign({method:"get",auth:i==="get-public-newsletters"?!!this.__user:true},{fetchOptions:e})),o={message_id:"mid",timestamp:"stmp",complaint:"cmpl",read:"read",subject:"subj",bounced:"bnce",url:"url",delivered:"delv",group:"grp"},a={message_id:"",timestamp:0,complaint:0,read:0,subject:"",bounced:"",url:"",delivered:0,group:t.group};return s.list=s.list.map(c=>{let l={};for(let d in o)l[d]=c[o[d]]||a[d];return l.bounced=String(l.bounced),l}),s}var vt="skapi:project_id";function Lc(t){let e=t.trim().toLowerCase().replace(/^<|>$/g,"").replace(/[\s_\-.]+/g,"");return e==="serviceid"||e==="projectid"}function Mc(){try{return window.sessionStorage.getItem(vt)||null}catch{return null}}function qc(t){try{window.sessionStorage.setItem(vt,t);}catch{}}function Yr(t){try{window.sessionStorage.getItem(vt)===t&&window.sessionStorage.removeItem(vt);}catch{}}function Vc(){if(z())return typeof window.prompt=="function";let t=it("tty");return !!(t&&it("readline")&&t.isatty(0)&&t.isatty(2))}function Bc(){return new f("Project ID is required.",{code:"INVALID_PARAMETER"})}var Xt=null;function jc(t,e){if(!Xt){Xt=z()?_h(t,e):bh(t,e);let r=()=>{Xt=null;};Xt.then(r,r);}return Xt}async function _h(t,e){await new Promise(o=>setTimeout(o,0));let r=`new Skapi() was given the placeholder "${t}" instead of your Project ID.`,n=`Enter your Project ID to continue. This browser tab remembers it until the tab is closed. To stop being asked, replace "${t}" in your code with the ID.`,i=`${r}
|
|
216
|
+
`,l=new Blob([c],{type:"application/javascript"});Ge=new Worker(URL.createObjectURL(l)),Ge.onmessage=d=>{a.readyState===1&&a.send(JSON.stringify({action:"keepAlive"}));},i(a);},a.onmessage=async c=>{let l="";try{l=JSON.parse(decodeURI(c.data)),this.log("socket onmessage",l);}catch{return}let d;switch(!0){case !!l?.["#message"]:d="message";break;case !!l?.["#private"]:d="private";break;case !!l?.["#notice"]:d="notice";break;case !!l?.["#rtc"]:d="rtc";break;case !!l?.["#error"]:d="error";break}if(!d)return;let h={type:d,message:l?.["#rtc"]||l?.["#message"]||l?.["#private"]||l?.["#notice"]||l?.["#error"]||null,sender:l?.["#user_id"]||null,sender_cid:l?.["#scid"]?"cid:"+l["#scid"]:null,sender_rid:l?.["#srid"]||null,code:l?.["#code"]||null};if(d==="notice")t(h);else if(d==="rtc"){if(h.sender!==this.user.user_id){let u=h.message;if(u.hungup){Se[h.sender_cid]&&(Se[h.sender_cid](!1),delete Se[h.sender_cid]),ke[h.sender_cid]&&delete ke[h.sender_cid],D?.[h.sender_cid]&&Re.bind(this)({cid:h.sender_cid}),h.type="rtc:closed",t(h);return}if(u.candidate&&Ri.bind(this)(u.candidate,h.sender_cid),u.sdpoffer&&(Si.bind(this)(u.sdpoffer,h.sender_cid),ke[h.sender_cid]||(ke[h.sender_cid]=h.sender_cid,delete h.message,h.connectRTC=Ha.bind(this)(h),h.type="rtc:incoming",h.hangup=(()=>{D[h.sender_cid]?Re.bind(this)({cid:h.sender_cid}):ke[h.sender_cid]&&(delete ke[h.sender_cid],a.send(JSON.stringify({action:"rtc",uid:h.sender_cid,content:{hungup:this.user.user_id},token:this.session.accessToken.jwtToken})));}).bind(this),t(h))),u.pickup&&Se[h.sender_cid]&&(Se[h.sender_cid](!0),delete Se[h.sender_cid]),u.sdpanswer&&D[h.sender_cid])if(D[h.sender_cid].signalingState==="have-local-offer")await D[h.sender_cid].setRemoteDescription(new RTCSessionDescription(u.sdpanswer));else throw new f("Invalid signaling state.",{code:"INVALID_REQUEST"})}}else t(h);},a.onclose=()=>{Jt?(this.log("realtime onclose","WebSocket connection closed."),t({type:"close",message:"WebSocket connection closed."})):(this.log("realtime onclose","WebSocket unexpected close."),t({type:"error",message:"Skapi: WebSocket unexpected close."}),At++,At<3?(this.log("realtime onclose","Reconnecting to WebSocket server..."+At),t({type:"reconnect",message:"Reconnecting to WebSocket server..."+At}),St.bind(this)(t,3e3,"reconnect")):(this.log("realtime onclose","Max reconnection attempts reached."),t({type:"error",message:"Skapi: Max reconnection attempts reached."})));},a.onerror=()=>{this.log("realtime onerror","WebSocket connection error."),t({type:"error",message:"Skapi: WebSocket connection error."});};}catch(a){o(a);}},e);}),n.value=this.__socket,this.__socket}async function za(t,e,r){if(typeof window>"u"||window._runningInNodeJS)throw new f("WebSocket is not supported in Node.js environment.",{code:"NOT_SUPPORTED"});let n=this.__socket?await this.__socket:this.__socket;if(!n)throw new f("No realtime connection. Execute connectRealtime() before this method.",{code:"INVALID_REQUEST"});if(!e)throw new f("No recipient.",{code:"INVALID_REQUEST"});await _t.bind(this)(),t=$(t).data;let i="";if(r&&(r=b.Params(r,{config:{always:"boolean"},title:"string",body:"string"},["title","body"]),i=JSON.stringify({title:r.title,body:r.body}),new Blob([i]).size>3072))throw new f("Notification size exceeds 3kb.",{code:"INVALID_PARAMETER"});if(n.readyState===1){try{b.UserId(e),n.send(JSON.stringify({action:"sendMessage",uid:e,content:t,notification:i,notificationConfig:r?.config||{},token:`IdT:${this.service}:${this.owner}:`+(this.bearerToken||this.session?.idToken?.jwtToken||"null")}));}catch(s){if(this.log("postRealtime:err",{err:s}),Ve!==e)throw new f(`User has not joined to the recipient group. Run joinRealtime({ group: "${e}" })`,{code:"INVALID_REQUEST"});n.send(JSON.stringify({action:"broadcast",rid:e,content:t,notification:i,notificationConfig:r?.config||{},token:`IdT:${this.service}:${this.owner}:`+(this.bearerToken||this.session?.idToken?.jwtToken||"null")}));}return {type:"success",message:"Message sent."}}throw new f("Realtime connection is not open. Try reconnecting with connectRealtime().",{code:"INVALID_REQUEST"})}async function Rt(t){if(typeof window>"u"||window._runningInNodeJS)throw new f("WebSocket is not supported in Node.js environment.",{code:"NOT_SUPPORTED"});let e=this.__socket?await this.__socket:this.__socket;if(!e)throw new f("No realtime connection. Execute connectRealtime() before this method.",{code:"INVALID_REQUEST"});await _t.bind(this)(),t=$(t,{nullIfEmpty:true}).data;let{group:r=null}=t;if(!r&&!Ve)return {type:"success",message:"Left realtime message group."};if(r!==null&&typeof r!="string")throw new f('"group" must be a string | null.',{code:"INVALID_PARAMETER"});return e.readyState===1&&e.send(JSON.stringify({action:"joinRoom",rid:r,token:this.session.accessToken.jwtToken})),Ve=r,{type:"success",message:r?`Joined realtime message group: "${r}".`:"Left realtime message group."}}async function Ya(t,e){t=b.Params(t,{user_id:n=>b.UserId(n,'User ID in "user_id"'),group:["string",()=>{if(!Ve)throw new f('No group has been joined. Otherwise "group" is required.',{code:"INVALID_REQUEST"});return Ve}]});let r=await C.bind(this)("get-ws-group",t,{fetchOptions:e,auth:true,method:"post"});return r.list=r.list.map(n=>({user_id:n.uid.split("#")[1],cid:"cid:"+n.cid})),r}async function Qa(t,e){if(await this.__connection,t||(t={searchFor:"group",value:" ",condition:">"}),t=b.Params(t,{searchFor:["group","number_of_users",()=>"group"],value:["string","number",()=>t?.searchFor&&t?.searchFor==="number_of_users"?0:" "],condition:[">",">=","=","<","<=","!=","gt","gte","eq","lt","lte","ne"],range:["string","number"]}),t.condition||(t.value===" "||!t.value?t.condition=">":t.condition="="),t.range&&t.condition&&delete t.condition,t.searchFor==="number_of_users"&&typeof t.value!="number")throw new f('"value" must be a number.',{code:"INVALID_PARAMETER"});if(t.searchFor==="group"&&typeof t.value!="string")throw new f('"value" must be a string.',{code:"INVALID_PARAMETER"});if(t.hasOwnProperty("range")&&typeof t.range!=typeof t.value)throw new f(`"range" must be a ${typeof t.value}.`,{code:"INVALID_PARAMETER"});let r=await C.bind(this)("get-ws-group",t,{fetchOptions:e,auth:true,method:"post"});return r.list=r.list.map(n=>({group:n.rid.split("#")[1],number_of_users:n.cnt})),r}var ch=typeof FormData<"u",Za=typeof HTMLFormElement<"u",ec=typeof SubmitEvent<"u",Ue={},zt={},de={};function Yt(t){return Object.freeze({id:t,status:"stopped"})}function Ii(t){return !!t&&typeof t=="object"&&t.status==="stopped"}var tc=3;function rc(t,e,r){let n=false,i=Array.isArray(t?.chunks)?t.chunks.slice():[];i.sort((s,o)=>(s?.seq||0)-(o?.seq||0));for(let s of i)if(!(!s||typeof s.seq!="number"||s.seq<=e.seq)&&(e.seq=s.seq,n=true,r&&typeof s.txt=="string"&&s.txt!==""))try{r(s.txt,s.seq,"poll");}catch(o){console.error(o);}return typeof t?.last_seq=="number"&&t.last_seq>e.seq&&(e.seq=t.last_seq,n=true),n}var lh=2e3,nc=5e3,uh=2e3,dh=5,fh=1500,Wr=null;function ic(t,e,r){let n=new Map,i=false,s=false,o=0,a={socket:0,poll:0},c=(u,g,p)=>{if(t.seq=u,!(!e||typeof g!="string"||g===""))try{e(g,u,p);}catch(m){console.error(m);}},l=()=>{for(let u of Array.from(n.keys()))u<=t.seq&&n.delete(u);for(;;){let u=t.seq+1;if(!n.has(u))break;let g=n.get(u);n.delete(u),c(u,g.txt,g.via);}};return {cursor:t,open:()=>{i||s||(i=true,l());},fromPoll:u=>{if(s)return false;let g=t.seq,p=t.seq,m=Array.isArray(u?.chunks)?u.chunks:[];for(let y of m){if(!y||typeof y.seq!="number"||y.seq<=t.seq)continue;let A=!n.has(y.seq);A&&(a.poll++,r&&a.poll===1&&r("poll",y.seq)),n.set(y.seq,{txt:typeof y.txt=="string"?y.txt:"",via:A?"poll":n.get(y.seq).via}),y.seq>p&&(p=y.seq);}typeof u?.last_seq=="number"&&u.last_seq>p&&(p=u.last_seq);let _=Array.from(n.keys()).sort((y,A)=>y-A);for(let y of _){if(y<=t.seq){n.delete(y);continue}if(y>p)break;let A=n.get(y);n.delete(y),c(y,A.txt,A.via);}return p>t.seq&&(t.seq=p),l(),t.seq>g},fromSocket:(u,g)=>{s||typeof u!="number"||!Number.isFinite(u)||(o=Date.now(),!(u<=t.seq)&&(!n.has(u)&&n.size>=uh||(n.has(u)||(a.socket++,r&&a.socket===1&&r("socket",u)),n.set(u,{txt:typeof g=="string"?g:"",via:n.has(u)?n.get(u).via:"socket"}),i&&l())));},warm:()=>o!==0&&Date.now()-o<lh,stats:()=>({socket:a.socket,poll:a.poll}),close:()=>{s=true,n.clear();}}}function sc(t){if(!this||!this.__network_logs)return {onTransport:void 0,done:()=>{}};let e=Date.now(),r=false;return {onTransport:(n,i)=>{console.log(`%cSKAPI: stream chunk arrived over ${n==="socket"?"WEBSOCKET":"POLL"}`,`color: ${n==="socket"?"green":"orange"};`,{id:t,first_seq:i,after_ms:Date.now()-e});},done:n=>{if(r||!n)return;r=true;let i=n.stats();console.log("%cSKAPI: stream transport","color: blue;",{id:t,over_websocket:i.socket,over_poll:i.poll,took_ms:Date.now()-e});}}}function oc(t,e){let r={stop:()=>{}};if(typeof window>"u"||window._runningInNodeJS||Wr)return r;let n={stopped:false,socket:null,opened:null,joined:false,attempts:0,unavailable:false};Wr=n;let i=l=>{if(n.stopped)return;let d=l?.data;if(typeof d!="string")return;let h=null;try{h=JSON.parse(d);}catch{try{h=JSON.parse(decodeURI(d));}catch{return}}let u=h?.["#message"];if(u==null)return;if(typeof u=="string")try{u=JSON.parse(u);}catch{return}if(typeof u!="object")return;let g=h?.["#srid"];if(typeof g=="string"&&g!==t)return;let p=u.seq;typeof p=="string"&&p!==""&&(p=Number(p)),e.fromSocket(p,u.txt);},s=()=>{if(n.socket){try{n.socket.removeEventListener("message",i);}catch{}try{n.socket.removeEventListener("close",a);}catch{}n.socket=null;}},o=async()=>{let l=n.opened,d=n.joined;if(n.opened=null,n.joined=false,s(),!(!d&&!l))try{let h=this.__socket?await this.__socket:null;if(l&&h===l){await Gr.bind(this)();return}d&&h&&Ja()===room&&await Rt.bind(this)({group:null});}catch{}},a=()=>{n.stopped||(s(),!n.unavailable&&(n.attempts>=dh||(n.attempts+=1,setTimeout(()=>{n.stopped||c();},fh))));},c=async()=>{try{let l=this.__socket?await this.__socket:null;if(n.stopped){o();return}if(!l){if(!this.session){n.unavailable=!0,o();return}if(await St.bind(this)(()=>{},0),l=this.__socket?await this.__socket:null,n.stopped){o();return}l&&!n.opened&&(n.opened=l);}if(!l||l.readyState!==1)return;if(l.addEventListener("message",i),l.addEventListener("close",a),n.socket=l,!n.joined&&(await Rt.bind(this)({group:t}),n.joined=!0,n.stopped)){o();return}}catch{}};return c(),{stop:()=>{n.stopped||(n.stopped=true,Wr===n&&(Wr=null),o());}}}function ac(t){return t?.status==="running"||t?.status==="pending"}function cc(t){return !!t&&typeof t=="object"&&!Array.isArray(t)&&typeof t.status=="string"&&typeof t.id=="string"&&"in_queue"in t}function lc(t,e,r,n){if(!t||typeof t!="string")throw new f('"requestId" should be type: <string>.',{code:"INVALID_PARAMETER"});if(t.includes("#"))return t;if(!e||typeof e!="string"||!r||typeof r!="string")throw new f('"url" and "method" are required to address a request by its short id.',{code:"INVALID_PARAMETER"});return b.Url(e),`[${r.toUpperCase()}]${e.toLowerCase()}#${n}:${t}`}function uc({id:t,auth:e,service:r,owner:n,latency:i=1e3,queue:s,seedExecuted:o,onResponse:a,onError:c,onStream:l,realtimeGroup:d}){if(typeof i!="number")throw new f('"latency" should be a number.',{code:"INVALID_PARAMETER"});if(i<0)throw new f('"latency" should be a non-negative number.',{code:"INVALID_PARAMETER"});s&&!Ue?.[s]&&(Ue[s]=new jt({breakWhenError:false,batchSize:1}));let h={stop:null,aborted:false,queue:s};de[t]=h;let u=null,g=()=>{de[t]===h&&delete de[t];},p=()=>new Promise((_,y)=>{let A=false;if(h.aborted){g(),_(Yt(t));return}let w={seq:0},T=sc.call(this,t),S=l&&d?ic(w,l,T.onTransport):null,k=S?oc.call(this,d,S):null,L=()=>{T.done(S),k&&k.stop(),S&&S.close();};u=L;let N=0,x=false,U=0,F=typeof o=="number"&&o>0?o:void 0,B=async()=>{if(!(A||x)&&!(S&&S.warm()&&Date.now()-N<nc)){x=true;try{for(;;){let ie={id:t,service:r,owner:n};l&&(ie.since=w.seq),N=Date.now();let M=await C.bind(this)("csr-poll",ie,{auth:e});if(A)return;let X=S?S.fromPoll(M):l?rc(M,w,l):!1;S&&S.open();let Zt=ac(M);if(typeof M?.executed=="number"&&M.executed>0&&(F=M.executed),M?.more&&X){U=0;continue}if(Zt){U=0;return}if(U=M?.more?U+1:0,M?.more&&U<tc)return;A=!0,a&&a(M,F!==void 0?{executed:F}:void 0),clearInterval(te),L(),g(),_(M);return}}catch(ie){if(A)return;A=true,c&&c(ie),clearInterval(te),L(),g(),y(ie);}finally{x=false;}}},te=setInterval(B,i);S&&B(),h.stop=()=>{A||(A=true,clearInterval(te),L(),g(),_(Yt(t)));};}),m=()=>{let _=de[t];_&&(_.stop?_.stop():(_.aborted=true,delete de[t]));};if(s){let _=new Promise((y,A)=>{let w=false,T=Ue[s].add([async()=>{try{let S=await p();return w||(w=!0,y(S)),S}catch(S){throw w||(w=true,A(S)),S}}])[0];zt[t]=T,h.stop=()=>{if(!w){h.aborted=true,u&&u();try{Ue[s]&&Ue[s].remove(zt[t]);}catch{}delete zt[t],g(),w=true,y(Yt(t));}};});return Object.assign(_,{stop:m})}else return Object.assign(p(),{stop:m})}function zr(t){let e=0,r=[];if(t?.id){if(t.url&&t.method){let n=t.service||this.service;r.push(`[${t.method.toUpperCase()}]${t.url.toLowerCase()}#${n}:${t.id}`);}r.push(t.id);}else if(t?.queue)for(let n in de)de[n]?.queue===t.queue&&r.push(n);else for(let n in de)r.push(n);for(let n of r){let i=de[n];i&&(i.stop?i.stop():(i.aborted=true,delete de[n]),e+=1);}return e}function Pi(t,e){if(!t.queue)throw new f('"queue" is required.',{code:"INVALID_PARAMETER"});let r=()=>C.bind(this)("csr-poll",{service:t.service||this.service,owner:t.owner||this.owner,queue:t.queue+":"},{auth:true});return this.__projectIdInput?this.__projectIdInput.then(r):r()}function hh(t){if(typeof Buffer<"u"&&typeof Buffer.from=="function")return Buffer.from(t).toString("base64");if(typeof btoa=="function"){let e="";for(let n=0;n<t.length;n+=32768)e+=String.fromCharCode.apply(null,Array.from(t.subarray(n,n+32768)));return btoa(e)}throw new f("No base64 encoder available in this environment.",{code:"NOT_SUPPORTED"})}var Xa=2*1024*1024-64*1024;function Jr(t){return typeof File<"u"&&t instanceof File||typeof Blob<"u"&&t instanceof Blob}function Ti(t){if(Array.isArray(t)){let e=[];for(let r of t)Jr(r)||e.push(Ti(r));return e}if(t&&typeof t=="object"&&!Jr(t)){let e=Object.getPrototypeOf(t);if(e!==Object.prototype&&e!==null)return t;let r={};for(let n in t)Jr(t[n])||(r[n]=Ti(t[n]));return r}return t}function ph(t){if(t==null)return null;let e=$(t)?.data;return !e||typeof e!="object"||Array.isArray(e)?null:Ti(e)}function dc(t,e,r){if(r!==void 0){if(Array.isArray(r)){for(let n of r)dc(t,e,n);return}if(Jr(r)){t.append(e,r);return}if(r===null){t.append(e,"");return}if(typeof r=="object"){t.append(e,JSON.stringify(r));return}t.append(e,String(r));}}async function gh(t){if(t==null)throw new f('"multipart": true needs a form body in the first argument.',{code:"INVALID_PARAMETER"});if(typeof FormData>"u"||typeof Response>"u")throw new f('"multipart": true is not available in this environment.',{code:"NOT_SUPPORTED"});let e;if(ec&&t instanceof SubmitEvent)e=new FormData(t.target);else if(Za&&t instanceof HTMLFormElement)e=new FormData(t);else if(t instanceof FormData)e=t;else if(typeof t=="object"&&!Array.isArray(t)){e=new FormData;for(let s in t)dc(e,s,t[s]);}else throw new f('"form" should be a submit event, a form element, FormData, or an object.',{code:"INVALID_PARAMETER"});let r=new Response(e),n=r.headers.get("content-type"),i=hh(new Uint8Array(await r.arrayBuffer()));if(i.length>Xa)throw new f(`Multipart body is too large: ${i.length} bytes once base64 encoded, and the limit is ${Xa}. Upload the file first and send its url instead.`,{code:"INVALID_PARAMETER"});return {body_b64:i,body_content_type:n}}function mh(t){if(t!=null){if(typeof t=="boolean")return t;if(typeof t=="object"&&!Array.isArray(t))return {user:!!t.user,service:!!t.service};throw new f('"skapiHeaders" should be type: <boolean> or { user?: boolean; service?: boolean }.',{code:"INVALID_PARAMETER"})}}function yh(t){if(!(!t||typeof t!="object")){for(let e in t)if(typeof e=="string"&&e.toLowerCase().indexOf("x-skapi-")===0)throw new f(`"headers" cannot set "${e}": the "x-skapi-" prefix is reserved. Use "skapiHeaders" to tell the destination who the caller is.`,{code:"INVALID_PARAMETER"})}}async function fc(t,e){let r=false,n=!!(t?.secretName||t?.clientSecretName),i=e?.signal;if(i?.aborted)throw new f('"signal" was already aborted.',{code:"INVALID_REQUEST"});if(typeof t.poll=="number"&&t.poll<0)throw new f('"poll" should be a non-negative number.',{code:"INVALID_PARAMETER"});let s=t?.onResponse,o=t?.onError,a=t?.onStream,c=typeof t.poll=="number"?t.poll:t.poll?1e3:0;delete t.poll,(c||t.stream)&&!t.queue&&(t.queue=(this.__user?.user_id||"anonymous")+"-"+Ye());let l=u=>{for(let g in u)if(typeof u[g]=="string"&&u[g].includes("$CLIENT_SECRET")){r=true;break}};if(t=b.Params(t,{url:u=>{if(!u||typeof u!="string")throw new f('"url" should be type: <string>.',{code:"INVALID_PARAMETER"});return b.Url(u),u.includes("$CLIENT_SECRET")&&(r=true),u},secretName:"string",clientSecretName:"string",method:u=>{if(u&&typeof u!="string")throw new f('"method" should be one of "GET", "POST", "PUT", "PATCH", "DELETE" or "HEAD".',{code:"INVALID_PARAMETER"});let g=u.toLowerCase();if(g!=="get"&&g!=="post"&&g!=="delete"&&g!=="put"&&g!=="patch"&&g!=="head")throw new f('"method" should be one of "GET", "POST", "PUT", "PATCH", "DELETE" or "HEAD".',{code:"INVALID_PARAMETER"});return g},stream:u=>{if(u!=null&&typeof u!="boolean")throw new f('"stream" should be type: <boolean>.',{code:"INVALID_PARAMETER"});return !!u},realtime:u=>{if(u!=null&&typeof u!="boolean")throw new f('"realtime" should be type: <boolean>.',{code:"INVALID_PARAMETER"});return !!u},headers:u=>{if(u&&typeof u!="object")throw new f('"headers" should be type: <object>.',{code:"INVALID_PARAMETER"});return yh(u),l(u),u},skapiHeaders:u=>mh(u),data:u=>{if(u&&typeof u!="object")throw new f('"data" should be type: <object>.',{code:"INVALID_PARAMETER"});return l(u),u},params:u=>{if(u&&typeof u!="object")throw new f('"params" should be type: <object>.',{code:"INVALID_PARAMETER"});return l(u),u},body_b64:"string",body_content_type:"string",expires:"number",queue:"string"},e?.requireSecretName?["clientSecretName","method","url"]:["method","url"]),t.realtime&&!t.stream)throw new f('"realtime" requires "stream": true.',{code:"INVALID_PARAMETER"});if(t.body_b64&&t.data)throw new f('"data" cannot be sent with "multipart": true.',{code:"INVALID_PARAMETER"});if(n&&!r){let u=t.method==="get"||t.method==="delete"||t.method==="head"?'"params"':'"data"';throw new f(`At least one parameter value should include "$CLIENT_SECRET" in ${u} or "headers".`,{code:"INVALID_PARAMETER"})}await this.__connection;let d=!!this.__user,h=()=>C.bind(this)("csr",t,{auth:d,tokenHeaders:{accessToken:!!d}}).then(u=>{if(u.status==="running"||u.status==="pending"){let g=`[${t.method.toUpperCase()}]${t.url.toLowerCase()}`,p=t.service||this.service,m=t.owner||this.owner,_=`${g}#${p}:${u.id}`;if(i){let y=()=>{zr.call(this,{id:_});};i.aborted?y():i.addEventListener("abort",y,{once:true});}Object.assign(u,{poll:y=>uc.call(this,{id:_,auth:d,service:p,owner:m,latency:y?.latency||1e3,queue:t?.queue,onResponse:s,onError:o,onStream:y?.onStream||a,realtimeGroup:u?.realtime_group})});}return s?s(u):u}).catch(u=>{if(o)return o(u);throw u});if(t?.queue){let u="base:"+t.queue;return Ue?.[u]||(Ue[u]=new jt({breakWhenError:false,batchSize:1})),new Promise((g,p)=>{Ue[u].add([async()=>{try{let m=await h();if(c>0){let _=m.poll({latency:c});return i&&(i.aborted?_.stop():i.addEventListener("abort",()=>_.stop(),{once:!0})),g(_),_}return g(m),m}catch(m){throw p(m),m}}]);})}else return h()}async function hc(t,e){if(!e||typeof e!="object")throw new f('"options" is required in the second argument.',{code:"INVALID_PARAMETER"});if(e.apiKeyHeader!==void 0||e.apiKeyScheme!==void 0)throw new f('"apiKeyHeader" and "apiKeyScheme" are no longer supported. Store the key as a client secret, name it with "secretName", and put "$CLIENT_SECRET" where the key goes.',{code:"INVALID_PARAMETER"});if(e.multipart!==void 0&&e.multipart!==null&&typeof e.multipart!="boolean")throw new f('"multipart" should be type: <boolean>.',{code:"INVALID_PARAMETER"});let r=e.responseType;if(r!=null){if(r==="response")throw new f(`"responseType": "response" is not available here. The request is relayed from the server and what comes back is the stored answer, not a live Response; the destination's status code is the "status_code" of the row forwardRequestHistory lists.`,{code:"INVALID_PARAMETER"});if(r!=="json"&&r!=="text")throw new f('"responseType" should be either "json" or "text".',{code:"INVALID_PARAMETER"})}let n=e.method||"POST",i=typeof n=="string"?n.toLowerCase():"",s=i==="get"||i==="delete"||i==="head"?"params":"data",o={url:e.url,method:n};if(e.secretName!==void 0&&(o.secretName=e.secretName),e.headers!==void 0&&(o.headers=e.headers),e.data!==void 0&&(o.data=e.data),e.params!==void 0&&(o.params=e.params),e.skapiHeaders!==void 0&&(o.skapiHeaders=e.skapiHeaders),e.service!==void 0&&(o.service=e.service),e.owner!==void 0&&(o.owner=e.owner),e.queue!==void 0&&(o.queue=e.queue),e.expires!==void 0&&(o.expires=e.expires),e.stream!==void 0&&(o.stream=e.stream),e.realtime!==void 0&&(o.realtime=e.realtime),e.poll!==void 0&&(o.poll=e.poll),e.onStream!==void 0&&(o.onStream=e.onStream),e.onResponse!==void 0&&(o.onResponse=e.onResponse),e.onError!==void 0&&(o.onError=e.onError),e.multipart){if(e.data!==void 0&&e.data!==null)throw new f('"data" cannot be sent with "multipart": true. The form itself is the body.',{code:"INVALID_PARAMETER"});let c=await gh(t);o.body_b64=c.body_b64,o.body_content_type=c.body_content_type;}else {let c=ph(t);c&&Object.keys(c).length&&(o[s]=Object.assign({},c,o[s]||{}));}let a=fc.call(this,o,{signal:e.signal});return r?a.then(c=>{if(cc(c)||Ii(c))return c;if(r==="text")return typeof c=="string"?c:JSON.stringify(c);if(typeof c=="string")try{return JSON.parse(c)}catch{return c}return c}):a}async function pc(t){return fc.call(this,t,{requireSecretName:true})}async function Ci(t,e){await this.__connection;let r=t.service||this.service,n=t.owner||this.owner;t=b.Params(t,{url:"string",method:["GET","POST","PUT","PATCH","DELETE","HEAD"],queue:"string",status:["pending","running","resolved","failed"],compact:"boolean",queue_exact:"boolean",queue_exclude:"string"},["url","method"]);let i=!!this.__user,s=`[${t.method.toUpperCase()}]${t.url.toLowerCase()}#${r}:`,o={id:s,queue:t?.queue,status:t?.status,service:r,owner:n};t?.compact&&(o.compact=true),t?.queue_exact&&(o.queue_exact=true),t?.queue_exclude&&(o.queue_exclude=t.queue_exclude),Object.keys(o).forEach(c=>{o[c]||delete o[c];}),o.queue&&(o.id_prefix=o.id,delete o.id);let a=await C.bind(this)("csr-poll",o,{auth:i,fetchOptions:e});return a.list=a.list.map(c=>{let l={id:c.id,status_code:c.rslv?.status_code||null,response_body:c.rslv?.body||c.rslv?.truncated||null,error:c?.err,created:c?.stmp,updated:c?.utmp,executed:typeof c?.att=="number"?c.att*1e3:void 0,responded:typeof c?.rtmp=="number"?c.rtmp:void 0,request_body:c?.reqbdy,expires:c?.expt,status:c.stts,queue_name:c?.qid,request_text:c?.reqtxt,response_text:c?.rslvtxt,response_complete_marker:c?.rslvmk!=null?!!c.rslvmk:void 0,compact:c?.cmpct?true:void 0};for(let d in l)l[d]===void 0&&delete l[d];return (l.status==="running"||l.status==="pending")&&(l.poll=d=>uc.call(this,{id:s+l.id,auth:i,service:r,owner:n,latency:d?.latency||1e3,queue:c?.qid,seedExecuted:l.executed,onResponse:d?.onResponse,onError:d?.onError,onStream:d?.onStream})),l}),a}async function xi(t){await this.__connection,t=b.Params(t,{url:"string",method:["GET","POST","PUT","PATCH","DELETE","HEAD"],id:"string",queue:"string"},["url","method","id"]);let e=t?.service||this.service,r=t?.owner||this.owner,n=!!this.__user,i=`[${t.method.toUpperCase()}]${t.url.toLowerCase()}#${e}`,s=t.id,o=`${i}:${s}`,a=t?.queue;return a&&Ue?.[a]&&(Ue[a].remove(zt[o]),delete zt[o]),C.bind(this)("csr-cancel",{id:o,service:e,owner:r},{auth:n})}function ki(t,e){let r=typeof e?.poll=="number"?e.poll:1e3;if(!Number.isFinite(r)||r<0)throw new f('"poll" should be a non-negative number.',{code:"INVALID_PARAMETER"});if(!t||typeof t!="string")throw new f('"requestId" should be type: <string>.',{code:"INVALID_PARAMETER"});if(e?.since!==void 0&&typeof e.since!="number")throw new f('"since" should be a number.',{code:"INVALID_PARAMETER"});if(e?.realtimeGroup!==void 0&&e.realtimeGroup!==null&&typeof e.realtimeGroup!="string")throw new f('"realtimeGroup" should be type: <string>.',{code:"INVALID_PARAMETER"});let n=typeof e?.since=="number"&&e.since>0?e.since:0,i=e?.onStream,s=e?.onResponse,o=e?.onError,a={stopped:false,fullId:t,resolve:null},c=null,l={stop:null,aborted:false},d=()=>{de[a.fullId]===l&&delete de[a.fullId];},h=()=>{a.stopped||(a.stopped=true,c&&c(),d(),a.resolve&&a.resolve(Yt(a.fullId)));};l.stop=h;let u=new Promise(async(g,p)=>{a.resolve=g;try{await this.__connection;let m=!!this.__user,_=e?.service||this.service,y=e?.owner||this.owner;if(a.fullId=lc(t,e?.url,e?.method,_),a.stopped){g(Yt(a.fullId));return}de[a.fullId]=l;let A={seq:n},w=0,T=sc.call(this,a.fullId),S=i&&e?.realtimeGroup?ic(A,i,T.onTransport):null,k=S?oc.call(this,e.realtimeGroup,S):null,L=()=>{T.done(S),k&&k.stop(),S&&S.close();};for(c=L;;){let N=await C.bind(this)("csr-poll",{id:a.fullId,service:_,owner:y,since:A.seq},{auth:m});if(a.stopped)return;if(!cc(N)){L(),d(),s&&s(N),g(N);return}let x=S?S.fromPoll(N):rc(N,A,i);S&&S.open();let U=ac(N);if(N.more&&x){w=0;continue}if(w=N.more?w+1:0,!U&&(!N.more||w>=tc)){L(),d(),s&&s(N),g(N);return}if(await new Promise(F=>setTimeout(F,S&&S.warm()?Math.max(r,nc):r)),a.stopped)return}}catch(m){if(a.stopped)return;c&&c(),d(),o&&o(m),p(m);}});return Object.assign(u,{stop:h})}async function Ui(t,e,r){await this.__connection;let n=r?.service||this.service,i=r?.owner||this.owner,s=!!this.__user,o=lc(t,r?.url,r?.method,n);return C.bind(this)("csr-finalize",{id:o,data:e,service:n,owner:i},{auth:s})}var gc=ki,mc=Ui,yc=Ci,_c=xi,bc=zr,wc=Pi;async function Ec(t){await this.__connection;let e={name:"string",email:r=>(b.Email(r),r),subject:"string",message:"string"};return t=b.Params(t,e,["name","email","subject","message"]),await C.bind(this)("send-inquiry",t),"SUCCESS: Inquiry has been sent."}async function Ac(t,e){if(await this.__connection,ch&&t instanceof FormData||Za&&t instanceof HTMLFormElement||ec&&t instanceof SubmitEvent){if(!e)throw new f("Url string as a second argument is required when form is passed.",{code:"INVALID_PARAMETER"});let n=$(t);t={url:e,data:n.data,sync:true};}let r={url:n=>b.Url(n),data:n=>n,sync:["boolean",()=>true]};if(Array.isArray(t))for(let n of t)n=b.Params(n,r);else t=b.Params(t,r);return C.bind(this)("post-secure",t,{auth:true})}async function Sc(t,e){await this.__connection;let{auth:r=false,method:n="POST",bypassAwaitConnection:i=false,responseType:s,contentType:o,tokenHeaders:a,progress:c}=e||{};if(e=Object.assign({auth:r,method:n,bypassAwaitConnection:i,responseType:s,contentType:o,tokenHeaders:a},{fetchOptions:{progress:c}}),typeof t!="object"&&(o==="application/json"||o===void 0))throw new f('"data" should be type: <object>.',{code:"INVALID_PARAMETER"});return C.bind(this)("mock",t,e)}async function Rc(t,e){await this.__connection,t=b.Params(t||{},{access_group:n=>{if(n==="authorized"&&(n=1),n==="public"&&(n=0),typeof n!="number")throw new f('"access_group" should be type number.',{code:"INVALID_PARAMETER"});if(n<0)throw new f('"access_group" should be zero or a positive number.',{code:"INVALID_PARAMETER"});if(n>this.__user.access_group)throw new f("User has no access.",{code:"INVALID_REQUEST"});return n}});let r=await C.bind(this)("get-feed",t,{auth:true,fetchOptions:e});return Array.isArray(r?.list)&&(r.list=await Promise.all(r.list.map(n=>Ze.bind(this)(n)))),r}function Qt(t){if(t===this.__user.user_id)throw new f(`"user_id" cannot be the user's own ID.`,{code:"INVALID_PARAMETER"});return b.UserId(t,'"user_id"')}async function vc(t,e){if(t=$(t,{ignoreEmpty:true}).data,t=b.Params(t,{subscriber:n=>b.UserId(n,'User ID in "subscriber"'),subscription:Qt.bind(this),blocked:"boolean"}),!t.subscriber&&!t.subscription)throw new f('At least either "subscriber" or "subscription" should have a value.',{code:"INVALID_PARAMETER"});let r=await C.bind(this)("get-subscription",t,Object.assign({auth:true},{fetchOptions:e}));return r.list=r.list.map((n=>{let i={};if(n.sub){let s=n.sub.split("#");i.subscriber=s[2],i.subscription=s[0];}else i.subscriber=n.subscriber,i.subscription=n.subscription;return i.timestamp=n?.timestamp||n.stmp,i.blocked=n?.blocked||n.grp.substring(0,1)==="N",Object.assign(i,n.opt),i})),r}async function Tc(t){await this.__connection,t=b.Params(t,{user_id:Qt.bind(this),get_feed:"boolean",get_notified:"boolean",get_email:i=>{if(i&&(!this.__user.email||!this.__user.email_verified))throw new f("User has no verified email address.",{code:"INVALID_REQUEST"});return !!i}},["user_id"]);let e={};for(let i of ["get_feed","get_notified","get_email"])typeof t[i]=="boolean"&&(e[i]=t[i]);let r=await C.bind(this)("subscription",{subscribe:t.user_id,option:e},{auth:true}),n={};if(r.sub){let i=r.sub.split("#");n.subscriber=i[2],n.subscription=i[0];}else n.subscriber=r.subscriber,n.subscription=r.subscription;return n.timestamp=r?.timestamp||r.stmp,n.blocked=r?.blocked||r.grp.substring(0,1)==="N",Object.assign(n,r.opt),n}async function Ic(t){await this.__connection;let{user_id:e}=b.Params(t,{user_id:Qt.bind(this)},["user_id"]);return await C.bind(this)("subscription",{unsubscribe:e},{auth:true})}async function Pc(t){await this.__connection;let{user_id:e}=b.Params(t,{user_id:Qt.bind(this)},["user_id"]);return await C.bind(this)("subscription",{block:e},{auth:true})}async function Cc(t){await this.__connection;let{user_id:e}=b.Params(t,{user_id:Qt.bind(this)},["user_id"]);return await C.bind(this)("subscription",{unblock:e},{auth:true})}async function xc(t,e){await this.__connection;let r=await ee.bind(this)();if(t=b.Params(t||{},{user_id:o=>{if(o!==this.__user.user_id&&!r)throw new f("No access.",{code:"INVALID_REQUEST"});return o},group:o=>b.newsletterGroup(o,{allowNull:true}),email:o=>{if(typeof o!="string"||!o.trim())throw new f('"email" should be a non-empty string.',{code:"INVALID_PARAMETER"});if(o.trim().length>255)throw new f('"email" should be at most 255 characters.',{code:"INVALID_PARAMETER"});return o.trim().toLowerCase()}}),t.email!==void 0){if(t.user_id!==void 0&&t.user_id!==null)throw new f('"email" cannot be used with "user_id".',{code:"INVALID_PARAMETER"});if(t.group===void 0||t.group===null)throw new f('"group" is required to search by "email".',{code:"INVALID_PARAMETER"})}let n=await C.bind(this)("get-newsletter-subscription",t,{auth:true,fetchOptions:e||null}),i=n?.list||n,s=[];Array.isArray(i)||(i=[]);for(let o of i){let a=o.subt.split("#"),c=true;a[0].charAt(0)==="@"&&(c=false,a[0]=a[0].substring(1));let l=/^\d+$/.test(a[0])?parseInt(a[0]):a[0],d={timestamp:o.stmp,group:l,subscribed_email:a[1],active:c};typeof o.email_token=="string"&&o.email_token&&(d.subscriber_token=o.email_token),s.push(d);}return n?.list?(n.list=s,n):s}async function kc(t){await this.__connection;let e=b.Params(t||{},{email:r=>Array.isArray(r)&&r.length>0?r.length===1?b.Email(r[0]):r.map(n=>b.Email(n)):b.Email(r),group:r=>b.newsletterGroup(r),redirect:r=>b.Url(r)},this.__user?["group"]:["email","group"]);return C.bind(this)(`subscribe-${this.__user?"":"public-"}newsletter`,e,{auth:!!this.__user})}async function Uc(t){await this.__connection;let e=b.Params(t||{},{group:r=>b.newsletterGroup(r,{nameOnly:true}),restriction:r=>{if(typeof r!="number"||!Number.isInteger(r)||r<0||r>99)throw new f('"restriction" should be a number between 0 and 99.',{code:"INVALID_PARAMETER"});return r},name:r=>{if(typeof r!="string"||r.length>60)throw new f('"name" should be a string of 60 characters or less.',{code:"INVALID_PARAMETER"});return r}},["group"]);return C.bind(this)("register-newsletter-group",e,{auth:true})}async function Dc(t){await this.__connection;let e=b.Params(t||{},{group:r=>b.newsletterGroup(r,{nameOnly:true})},["group"]);return C.bind(this)("delete-newsletter-group",e,{auth:true})}async function Nc(){return await this.__connection,C.bind(this)("newsletter-group-endpoint",null,{auth:true})}async function Oc(t){await this.__connection,t=b.Params(t,{group:r=>b.newsletterGroup(r,{allowNull:true})},["group"]);let e=Object.assign({action:"unsubscribe"},t);return C.bind(this)("subscribe-newsletter",e,{auth:true})}async function Fc(t,e){let r=await ee.bind(this)(),n={message_id:"string",timestamp:"number",read:"number",complaint:"number",subject:"string",bounced:"number"};t||(e=Object.assign({ascending:false},e||{})),t=$(t).data,t=t||{searchFor:"timestamp",value:Date.now(),condition:"<",group:"public"},t=b.Params(t,{searchFor:["message_id","timestamp","subject","complaint","read","bounced"],value:c=>{if(typeof c!==n[t.searchFor])throw new f(`"value" type does not match the type of "${t.searchFor}" index.`,{code:"INVALID_PARAMETER"});if(typeof c=="string"&&!c)throw new f('"value" should not be empty string.',{code:"INVALID_PARAMETER"});return c},range:c=>{if(!t.hasOwnProperty("value")||typeof c!=typeof t.value)throw new f('"range" should match type of "value".',{code:"INVALID_PARAMETER"});return c},condition:[">",">=","=","<","<=","gt","gte","eq","lt","lte",()=>"="],group:c=>{let l=b.newsletterGroup(c);if(l===0)return 0;if(typeof l=="string")return l;if(!this.session)throw new f("User should be logged in.",{code:"INVALID_REQUEST"});if(c==="authorized")return 1;if(!r&&l>parseInt(this.user?.access_group||this.session?.idToken?.payload?.access_group))throw new f("User has no access.",{code:"INVALID_REQUEST"});return l}},["searchFor","value","group"]);let i=t.group===0||typeof t.group=="string"&&!this.__user?"get-public-newsletters":"get-newsletters",s=await C.bind(this)(i,t,Object.assign({method:"get",auth:i==="get-public-newsletters"?!!this.__user:true},{fetchOptions:e})),o={message_id:"mid",timestamp:"stmp",complaint:"cmpl",read:"read",subject:"subj",bounced:"bnce",url:"url",delivered:"delv",group:"grp"},a={message_id:"",timestamp:0,complaint:0,read:0,subject:"",bounced:"",url:"",delivered:0,group:t.group};return s.list=s.list.map(c=>{let l={};for(let d in o)l[d]=c[o[d]]||a[d];return l.bounced=String(l.bounced),l}),s}var vt="skapi:project_id";function Lc(t){let e=t.trim().toLowerCase().replace(/^<|>$/g,"").replace(/[\s_\-.]+/g,"");return e==="serviceid"||e==="projectid"}function Mc(){try{return window.sessionStorage.getItem(vt)||null}catch{return null}}function qc(t){try{window.sessionStorage.setItem(vt,t);}catch{}}function Yr(t){try{window.sessionStorage.getItem(vt)===t&&window.sessionStorage.removeItem(vt);}catch{}}function Vc(){if(z())return typeof window.prompt=="function";let t=it("tty");return !!(t&&it("readline")&&t.isatty(0)&&t.isatty(2))}function Bc(){return new f("Project ID is required.",{code:"INVALID_PARAMETER"})}var Xt=null;function jc(t,e){if(!Xt){Xt=z()?_h(t,e):bh(t,e);let r=()=>{Xt=null;};Xt.then(r,r);}return Xt}async function _h(t,e){await new Promise(o=>setTimeout(o,0));let r=`new Skapi() was given the placeholder "${t}" instead of your Project ID.`,n=`Enter your Project ID to continue. This browser tab remembers it until the tab is closed. To stop being asked, replace "${t}" in your code with the ID.`,i=`${r}
|
|
217
217
|
|
|
218
218
|
${n}`,s="";for(;;){let o=window.prompt(i,s);if(o===null)throw Bc();if(s=o.trim(),!s){i=`${r}
|
|
219
219
|
|
|
@@ -225,7 +225,7 @@ ${n}`;}}}function bh(t,e){let r=globalThis.process,n=it("readline");return new P
|
|
|
225
225
|
This process remembers the ID until it exits. To stop being asked, replace "${t}" in your code with the ID.
|
|
226
226
|
`),c();})}async function Kc(t){let e=b.Params(t,{user_id:n=>b.UserId(n,'"user_id"')},["user_id"]);if(e?.service&&e?.owner?e={service:e?.service,owner:e?.owner,block:e.user_id}:e={block:e.user_id},!await ee.bind(this)()){if(!this.__user)throw new f("User needs to login.",{code:"INVALID_REQUEST"});if(this.__user.access_group<90)throw new f("Invalid access.",{code:"INVALID_REQUEST"})}return await C.bind(this)("block-account",e,{auth:true})}async function $c(t){let e=b.Params(t,{user_id:n=>b.UserId(n,'"user_id"')},["user_id"]);if(e?.service&&e?.owner?e={service:e?.service,owner:e?.owner,unblock:e.user_id}:e={unblock:e.user_id},!await ee.bind(this)()){if(!this.__user)throw new f("User needs to login.",{code:"INVALID_REQUEST"});if(this.__user.access_group<90)throw new f("Invalid access.",{code:"INVALID_REQUEST"})}return await C.bind(this)("block-account",e,{auth:true})}async function Hc(t){let e=b.Params(t,{user_id:n=>b.UserId(n,'"user_id"')},["user_id"]);if(e?.service&&e?.owner?e={service:e?.service,owner:e?.owner,delete:e.user_id}:e={delete:e.user_id},!await ee.bind(this)()){if(!this.__user)throw new f("User needs to login.",{code:"INVALID_REQUEST"});if(this.__user.access_group<90)throw new f("Invalid access.",{code:"INVALID_REQUEST"})}return await C.bind(this)("remove-account",e,{auth:true})}async function Gc(t,e){let r={email:s=>b.Email(s),password:s=>b.Password(s),name:"string",username:"string",gender:"string",address:s=>{if(!s)return "";if(typeof s=="string")return s;if(typeof s=="object")return JSON.stringify(s)},birthdate:s=>b.Birthdate(s),phone_number:s=>b.PhoneNumber(s),picture:s=>{if(s)return b.Url(s)},profile:s=>{if(s)return b.Url(s)},website:s=>{if(s)return b.Url(s)},nickname:"string",misc:"string",email_public:["boolean",()=>false],gender_public:["boolean",()=>false],address_public:["boolean",()=>false],birthdate_public:["boolean",()=>false],phone_number_public:["boolean",()=>false],openid_id:"string",access_group:s=>{try{typeof s=="string"&&(s=s==="admin"?99:parseInt(s));}catch{throw new f('"access_group" is invalid. Should be type <number>.',{code:"INVALID_PARAMETER"})}if(typeof s!="number"||s<1||s>100)throw new f('"access_group" is invalid. Should be type <number> of range 1~99',{code:"INVALID_PARAMETER"});return s}},n=b.Params(t,r,["email"]);if(e=b.Params(e,{confirmation_url:s=>{let o=s;if(typeof s=="string")o=b.Url(s);else throw new f('"options.confirmation_url" should be type: <string>.',{code:"INVALID_PARAMETER"});if(o&&!n.email)throw new f('"email" is required for signup confirmation.',{code:"INVALID_PARAMETER"});return o},email_subscription:s=>{if(typeof s!="boolean")throw new f('"options.email_subscription" should be type: <boolean>.',{code:"INVALID_PARAMETER"});if(!e?.confirmation_url)throw new f('"options.confirmation_url" is required for email subscription.',{code:"INVALID_PARAMETER"});return s},template:s=>{if(typeof s!="object"||!s.url||!s.subject)throw new f('"options.template" should be type: <object> with "url" and "subject".',{code:"INVALID_PARAMETER"});return {url:b.Url(s.url),subject:s.subject}}}),n.signup_confirmation=e?.confirmation_url||true,n.email_subscription=e?.email_subscription||false,n.template=e?.template||{},!await ee.bind(this)()){if(!this.__user)throw new f("User needs to login.",{code:"INVALID_REQUEST"});if(this.__user.access_group<90)throw new f("Invalid access.",{code:"INVALID_REQUEST"})}return await C.bind(this)("admin-signup",n,{auth:true})}async function Wc(t){let e={email:s=>b.Email(s),password:s=>b.Password(s),openid_id:"string",name:"string",username:"string",gender:"string",address:s=>{if(!s)return "";if(typeof s=="string")return s;if(typeof s=="object")return JSON.stringify(s)},birthdate:s=>b.Birthdate(s),phone_number:s=>b.PhoneNumber(s),picture:s=>s?b.Url(s):"",profile:s=>s?b.Url(s):"",website:s=>s?b.Url(s):"",nickname:"string",misc:"string",email_public:["boolean",()=>false],gender_public:["boolean",()=>false],address_public:["boolean",()=>false],birthdate_public:["boolean",()=>false],phone_number_public:["boolean",()=>false],access_group:s=>{try{typeof s=="string"&&(s=parseInt(s));}catch{throw new f('"access_group" is invalid. Should be type <number>.',{code:"INVALID_PARAMETER"})}if(typeof s!="number"||s<1||s>100)throw new f('"access_group" is invalid. Should be type <number> of range 1~99',{code:"INVALID_PARAMETER"});return s}},r=["email","password"],n=b.Params(t,e,r);if(!await ee.bind(this)()){if(!this.__user)throw new f("User needs to login.",{code:"INVALID_REQUEST"});if(this.__user.access_group<90)throw new f("Invalid access.",{code:"INVALID_REQUEST"})}return await C.bind(this)("admin-signup",n,{auth:true})}async function Jc(t){if(t=b.Params(t,{user_id:r=>b.UserId(r,'"user_id"'),access_group:r=>{try{typeof r=="string"&&(r=parseInt(r));}catch{throw new f('"access_group" is invalid. Should be type <number>.',{code:"INVALID_PARAMETER"})}if(typeof r=="number"&&r>0&&r<100)return r;throw new f('"access_group" is invalid. Should be type <number> of range 1~99',{code:"INVALID_PARAMETER"})}},["user_id","access_group"]),!await ee.bind(this)()){if(!this.__user)throw new f("User needs to login.",{code:"INVALID_REQUEST"});if(this.__user.access_group<90)throw new f("Invalid access.",{code:"INVALID_REQUEST"})}return await C.bind(this)("grant-access",t,{auth:true})}async function zc(t,e){if(t=b.Params(t,{email:"string"}),!await ee.bind(this)()){if(!this.__user)throw new f("User needs to login.",{code:"INVALID_REQUEST"});if(this.__user.access_group<90)throw new f("Invalid access.",{code:"INVALID_REQUEST"})}let n=await C.bind(this)("invitation-list",Object.assign({mode:"search"},t),{fetchOptions:e,auth:true});return n.list=n.list.map(i=>Ct(i.user)),n}async function Yc(t){if(t=b.Params(t,{email:r=>b.Email(r)},["email"]),!await ee.bind(this)()){if(!this.__user)throw new f("User needs to login.",{code:"INVALID_REQUEST"});if(this.__user.access_group<90)throw new f("Invalid access.",{code:"INVALID_REQUEST"})}return await C.bind(this)("invitation-list",Object.assign({mode:"cancel"},t),{auth:true})}async function Qc(t){if(t=b.Params(t,{email:r=>b.Email(r)},["email"]),!await ee.bind(this)()){if(!this.__user)throw new f("User needs to login.",{code:"INVALID_REQUEST"});if(this.__user.access_group<90)throw new f("Invalid access.",{code:"INVALID_REQUEST"})}return await C.bind(this)("invitation-list",Object.assign({mode:"resend"},t),{auth:true})}async function Xc(t){let e=b.Params(t,{user_id:o=>b.UserId(o,'"user_id"'),email:o=>b.Email(o),address:o=>{if(!o)return "";if(typeof o=="string")return o;if(typeof o=="object")return JSON.stringify(o)},name:"string",gender:"string",birthdate:o=>o?b.Birthdate(o):"",phone_number:o=>o?b.PhoneNumber(o):"",email_public:"boolean",phone_number_public:"boolean",address_public:"boolean",gender_public:"boolean",birthdate_public:"boolean",misc:"string",picture:o=>o?b.Url(o):"",profile:o=>o?b.Url(o):"",nickname:"string",website:o=>o?b.Url(o):""},["user_id"]),r=e.service,n=e.owner;if(delete e.service,delete e.owner,await this.__connection,this.__user?.user_id&&e.user_id===this.__user.user_id)throw new f("Cannot modify attributes of the current user.",{code:"INVALID_REQUEST"});if(Object.keys(e).filter(o=>o!=="user_id"&&e[o]!==void 0).length===0)throw new f("At least one attribute to update is required.",{code:"INVALID_PARAMETER"});if(!await ee.bind(this)()){if(!this.__user)throw new f("User needs to login.",{code:"INVALID_REQUEST"});if(this.__user.access_group<90)throw new f("Invalid access.",{code:"INVALID_REQUEST"})}let s={attributes:e};return r&&n&&(s.service=r,s.owner=n),await C.bind(this)("admin-edit-profile",s,{auth:true})}async function Zc(t){if(typeof window>"u"||window._runningInNodeJS)throw new f("Push Notifications are not supported in Node.js environment.",{code:"NOT_SUPPORTED"});if(await this.__connection,!t.endpoint)throw new f("Missing parameter: endpoint",{code:"INVALID_PARAMETER"});if(!t.keys||!t.keys.p256dh||!t.keys.auth)throw new f("Missing parameter: keys.p256dh or keys.auth",{code:"INVALID_PARAMETER"});return await C.bind(this)("store-subscription",{endpoint:t.endpoint,keys:t.keys},{auth:true}),"SUCCESS: Subscribed to receive notifications."}async function el(t){if(typeof window>"u"||window._runningInNodeJS)throw new f("Push Notifications are not supported in Node.js environment.",{code:"NOT_SUPPORTED"});if(await this.__connection,!t.endpoint)throw new f("Missing parameter: endpoint",{code:"INVALID_PARAMETER"});if(!t.keys||!t.keys.p256dh||!t.keys.auth)throw new f("Missing parameter: keys.p256dh or keys.auth",{code:"INVALID_PARAMETER"});return await C.bind(this)("delete-subscription",{endpoint:t.endpoint,keys:t.keys},{auth:true}),"SUCCESS: Unsubscribed from notifications."}async function tl(){if(typeof window>"u"||window._runningInNodeJS)throw new f("Push Notifications are not supported in Node.js environment.",{code:"NOT_SUPPORTED"});return await this.__connection,{VAPIDPublicKey:await C.bind(this)("get-vapid-public-key",null,{auth:true})}}async function rl(t,e){if(typeof window>"u"||window._runningInNodeJS)throw new f("Push Notifications are not supported in Node.js environment.",{code:"NOT_SUPPORTED"});await this.__connection;let{title:r,body:n}=$(t||{},{nullIfEmpty:true}).data;if(!r)throw new f("Missing parameter: message title",{code:"INVALID_PARAMETER"});if(!n)throw new f("Missing parameter: message body",{code:"INVALID_PARAMETER"});let i={title:r,body:n};return e?(typeof e=="string"&&(e=[e]),i.user_ids=e):i.user_ids="all_users",await C.bind(this)("push-notification",i,{auth:true}),"SUCCESS: Notification sent."}async function nl(t){await this.__connection,t=b.Params(t,{spell:"string",name:"string",magic:r=>r},["spell","name"]);await C.bind(this)("castspell",t);return `The spell "${t.spell}" has been cast.`}async function il(t){return await this.__connection,t=b.Params(t||{},{search:["spell","name",()=>"spell"],value:"string"}),await C.bind(this)("getspell",t)}async function sl(t){await this.__connection,t=b.Params(t,{message:"string",name:"string"},["message","name"]);let e=await C.bind(this)("dopamine",t,{auth:true}),r=e?.previous_message?.message,n=e?.previous_message?.name;if(z())r&&n&&window.alert(`${n} said: ${r}`),window.location.href=e.video;else return r&&n?`${n} said: ${r}
|
|
227
227
|
Watch the video here: ${e.video}`:`Your message has been uploaded for future generations to receive.
|
|
228
|
-
Watch the video here: ${e.video}`}var R=class{constructor(e,r,n,i){this.__version="2.2.
|
|
228
|
+
Watch the video here: ${e.video}`}var R=class{constructor(e,r,n,i){this.__version="2.2.3";this.project_id="";this.session=null;this.connection=null;this.__my_unique_ids={};this.__uniqueIdsPersistTimer=null;this.userPool=null;this.__socket=null;this.__mediaStream=null;this.host="skapi";this.hostDomain="skapi.com";this.target_cdn="d3e9syvbtso631";this.customApiDomain="skapi.dev";this.requestBatchSize=50;this.__disabledAccount=null;this.__cached_requests={};this.__startKeyHistory={};this.__request_signup_confirmation=null;this.__private_access_key={};this.__class_properties_has_been_cached=false;this.__user=null;this._userProfileListeners=[];this._onLoginListeners=[];this._onBatchProcessListeners=[];this.validate={userId(e){try{return b.UserId(e),!0}catch{return false}},url(e){try{return b.Url(e),!0}catch{return false}},phoneNumber(e){try{return b.PhoneNumber(e),!0}catch{return false}},birthdate(e){try{return b.Birthdate(e),!0}catch{return false}},email(e){try{return b.Email(e),!0}catch{return false}},params(e,r,n){return b.Params(e,r,n)}};this.util={MD5:le,generateRandom:Ye,toBase62:Bs,fromBase62:be,decodeProjectId:qn,formatServiceId:Vn,extractFormData:$,terminatePendingRequests:pa,request:(e,r,n)=>C.bind(this)(e,r,n,{ignoreService:true})};this.__projectIdInput=null;this.__network_logs=false;this.__endpoint_version="v2";this.__public_identifier="";this.bearerToken="";this.registerTicket=Wo.bind(this);this.unregisterTicket=Jo.bind(this);if(!e||typeof e!="string")throw this._alert("Service ID is required."),new f("Service ID is required.",{code:"INVALID_PARAMETER"});if(Lc(e)){let o=Mc(),a=null;if(o)try{a=this._resolveProject(o,r,n,i);}catch{Yr(o);}if(a)z()&&console.info(`Skapi: "${e}" was replaced with the Project ID entered earlier in this tab (${o}). It is kept in sessionStorage under "${vt}"; delete that entry to enter a different one.`),this._start(a),this.__connection.catch(()=>Yr(o));else if(Vc())this._startAfterProjectIdInput(e,r,n,i);else throw this._alert(`Replace "${e}" with your actual Project ID.`),new f("Project ID is required.",{code:"INVALID_PARAMETER"});return}let s;try{s=this._resolveProject(e,r,n,i);}catch(o){throw this._alert(o.message),o}this._start(s);}get user(){return this.__user&&Object.keys(this.__user).length?JSON.parse(JSON.stringify(this.__user)):null}set user(e){}get onLogin(){return this._onLoginListeners}set onLogin(e){typeof e=="function"&&this._onLoginListeners.push(e);}get onUserUpdate(){return this._userProfileListeners}set onUserUpdate(e){typeof e=="function"&&this._userProfileListeners.push(e);}_runOnUserUpdateListeners(e){for(let r of this._userProfileListeners)typeof r=="function"&&r(e);}_runOnLoginListeners(e){for(let r of this._onLoginListeners)typeof r=="function"&&r(e);}get onBatchProcess(){return this._onBatchProcessListeners}set onBatchProcess(e){typeof e=="function"&&this._onBatchProcessListeners.push(e);}_alert(e){z()&&typeof window.alert=="function"&&window.alert(e);}_resolveProject(e,r,n,i){let s=e.split("-").length;if(s===2||s===7)try{let c=qn(e);n&&typeof n=="object"&&(i=n),r&&typeof r=="object"&&(n=r),r=c.owner,e=c.service;}catch{throw new f("Service ID is invalid.",{code:"INVALID_PARAMETER"})}if(!r||typeof r!="string")throw new f("Owner ID is invalid.",{code:"INVALID_PARAMETER"});if(r!==this.host)try{b.UserId(r,'"owner"');}catch{throw new f("Owner ID is invalid.",{code:"INVALID_PARAMETER"})}return {service:e,owner:r,options:n,__etc:i}}_startAfterProjectIdInput(e,r,n,i){let s=jc(e,o=>{this._resolveProject(o,r,n,i);}).then(o=>{qc(o),this._start(this._resolveProject(o,r,n,i)),this.__connection.catch(()=>Yr(o));});this.__projectIdInput=s,this.admin_endpoint=s.then(()=>this.admin_endpoint),this.record_endpoint=s.then(()=>this.record_endpoint),this.__authConnection=s.then(()=>this.__authConnection),this.__connection=s.then(()=>this.__connection);for(let o of [s,this.admin_endpoint,this.record_endpoint,this.__authConnection,this.__connection])o.catch(()=>{});}_start({service:e,owner:r,options:n,__etc:i}){this.service=e,this.owner=r;try{this.project_id=Vn(e,r);}catch{this.project_id="";}let s=true,o=false,a=null;if(n&&(typeof n.refetchServiceInfo=="boolean"&&(o=n.refetchServiceInfo),typeof n.autoLogin=="boolean"&&(s=n.autoLogin),n.encryption&&(a=uo(n.encryption)),typeof n.requestBatchSize=="number")){if(n.requestBatchSize<1)throw new f('"requestBatchSize" must be greater than 0.',{code:"INVALID_PARAMETER"});this.requestBatchSize=n.requestBatchSize;}n?.eventListener&&typeof n.eventListener=="object"&&(n.eventListener?.onLogin&&typeof n.eventListener.onLogin=="function"&&(this.onLogin=n.eventListener.onLogin),n.eventListener?.onUserUpdate&&typeof n.eventListener.onUserUpdate=="function"&&(this.onUserUpdate=n.eventListener.onUserUpdate),n.eventListener?.onBatchProcess&&typeof n.eventListener.onBatchProcess=="function"&&(this.onBatchProcess=n.eventListener.onBatchProcess)),this.target_cdn=i?.target_cdn||this.target_cdn,this.hostDomain=i?.hostDomain||this.hostDomain,this.customApiDomain=i?.customApiDomain||this.customApiDomain,this.__network_logs=!!i?.network_logs;let c=`https://${this.target_cdn}.cloudfront.net`,l=e.substring(0,4);this.admin_endpoint=fetch(`${c}/${l}/admin-${this.__endpoint_version}.json`).then(p=>p.blob()).then(p=>new Promise((m,_)=>{let y=new FileReader;y.onloadend=()=>m(y.result),y.onerror=_,y.readAsDataURL(p);})).then(p=>{try{return typeof p=="string"?JSON.parse(atob(p.split(",")[1])):null}catch{throw new f("Service does not exist. Create your service from skapi.com",{code:"NOT_EXISTS"})}}),this.record_endpoint=fetch(`${c}/${l}/record-${this.__endpoint_version}.json`).then(p=>p.blob()).then(p=>new Promise((m,_)=>{let y=new FileReader;y.onloadend=()=>m(y.result),y.onerror=_,y.readAsDataURL(p);})).then(p=>{try{return typeof p=="string"?JSON.parse(atob(p.split(",")[1])):null}catch{throw new f("Service does not exist. Create your service from skapi.com",{code:"NOT_EXISTS"})}});let d=z();if(d&&!window.sessionStorage)throw this._alert("This browser is not supported."),new Error("This browser is not supported.");let h=d?JSON.parse(window.sessionStorage.getItem(`${e}#${r}`)||"null"):null;if(this.log("constructor:restore",h),h?.connection){for(let p in h)this[p]=h[p];h.__public_identifier||(this.__public_identifier=`${this.service}:${this.owner}:${Ye(16)}`);}fo.bind(this)(a),this.__authConnection=(async()=>{let p=await this.admin_endpoint,m={UserPoolId:p.userpool_id,ClientId:p.userpool_client};Mn()&&(m.Storage=window.localStorage),this.userPool=new Nn(m);try{this.user||await Z.bind(this)().getSession({skipUserUpdateEventTrigger:!0}),this.user&&(!h?.connection&&!s?Me.bind(this)():(a&&ko.bind(this)(),this._runOnLoginListeners(this.user),this._runOnUserUpdateListeners(this.user)));}catch{}})();let u=`${this.service}/${this.owner}`,g=d?window.sessionStorage.getItem(`${u}:uniqueids`):null;if(g)try{let p=JSON.parse(g);this.__my_unique_ids=p&&typeof p=="object"&&!Array.isArray(p)?{[u]:p}:{};}catch{this.__my_unique_ids={};}this.__connection=(async()=>{let p=null;await this.record_endpoint,h?.connection||(p=this._updateConnection({refresh:o}));let m=()=>{if(this.__class_properties_has_been_cached)return;let _=()=>{let y={},A=["__startKeyHistory","__disabledAccount","__cached_requests","__request_signup_confirmation","__public_identifier","connection"];if(this.connection){for(let w of A)y[w]=this[w];if(a&&(y.__cached_requests={},y.__startKeyHistory={}),d){let w=`${e}#${r}`;try{window.sessionStorage.setItem(w,JSON.stringify(y));}catch{try{let S=Object.assign({},y,{__cached_requests:{},__startKeyHistory:{}});window.sessionStorage.setItem(w,JSON.stringify(S));}catch{try{window.sessionStorage.removeItem(w);}catch{}}}}this.__class_properties_has_been_cached=true;}};return p instanceof Promise?p.then(()=>_()):_()};return d&&(window.addEventListener("beforeunload",()=>{this.closeRealtime(),m();}),window.addEventListener("visibilitychange",()=>{m();})),await p,await this.__authConnection,this.connection})(),this.__connection.then(p=>{((p?.group||0)<3||this.__network_logs)&&this.version();}).catch(()=>{});}async getConnectionInfo(e){e?.refresh&&(this.__connection instanceof Promise&&await this.__connection,this.__connection=this._updateConnection({refresh:true}));let n=await this.__connection,i=n?.user_agent||(z()&&typeof window.navigator?.userAgent=="string"?window.navigator.userAgent:`skapi-node/${globalThis?.process?.versions?.node||"unknown"}`);return {project_id:this.project_id,user_ip:n.ip,user_agent:i,user_location:n.locale,service_name:n.service_name,version:this.__version,service_description:n?.service_description||"",ai_agent:n?.ai_agent||"",conf:n?.opt}}async _updateConnection(e){let r=e?.refresh||false;try{this.connection=await C.bind(this)("service",{service:this.service,owner:this.owner,refresh:r},{bypassAwaitConnection:!0,method:"get"});}catch(n){throw this.log("connection fail",n),this._alert("Service is not available: "+(n.message||n.toString())),this.connection=null,n}return this.connection}async version(){if(await this.__connection,z()){let r=`Built with:
|
|
229
229
|
%c\r
|
|
230
230
|
##\\ ##\\ \r
|
|
231
231
|
## | \\__|\r
|