skapi-js 1.6.1 → 1.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/skapi.browser.mjs +1 -1
- package/dist/skapi.browser.mjs.map +1 -1
- package/dist/skapi.cjs +1 -1
- package/dist/skapi.cjs.map +1 -1
- package/dist/skapi.d.mts +68 -52
- package/dist/skapi.d.ts +68 -52
- package/dist/skapi.js +1 -1
- package/dist/skapi.js.map +1 -1
- package/dist/skapi.mjs +1 -1
- package/dist/skapi.mjs.map +1 -1
- package/package.json +1 -1
package/dist/skapi.d.ts
CHANGED
|
@@ -43,14 +43,14 @@ type WebSocketMessage = {
|
|
|
43
43
|
};
|
|
44
44
|
type RealtimeCallback = (rt: WebSocketMessage) => void;
|
|
45
45
|
type DelRecordQuery = GetRecordQuery & {
|
|
46
|
-
unique_id?: string
|
|
47
|
-
record_id?: string
|
|
46
|
+
unique_id?: string;
|
|
47
|
+
record_id?: string;
|
|
48
48
|
};
|
|
49
49
|
type GetRecordQuery = {
|
|
50
50
|
unique_id?: string;
|
|
51
51
|
record_id?: string;
|
|
52
|
-
/** Table name not required when "record_id" is given
|
|
53
|
-
table?: {
|
|
52
|
+
/** Table name not required when "record_id" is given. A bare string is shorthand for { name: <string> }. */
|
|
53
|
+
table?: string | {
|
|
54
54
|
/** Max 128 chars. Blocks: / ! * #, control chars, and sentinel . */
|
|
55
55
|
name: string;
|
|
56
56
|
/** Number range: 0 ~ 99. Default: 'public' */
|
|
@@ -58,7 +58,11 @@ type GetRecordQuery = {
|
|
|
58
58
|
/** User ID of subscription */
|
|
59
59
|
subscription?: string;
|
|
60
60
|
};
|
|
61
|
-
reference?: string
|
|
61
|
+
reference?: string | {
|
|
62
|
+
record_id?: string;
|
|
63
|
+
unique_id?: string;
|
|
64
|
+
user_id?: string;
|
|
65
|
+
};
|
|
62
66
|
/** Index condition and range cannot be used simultaneously.*/
|
|
63
67
|
index?: {
|
|
64
68
|
/** Custom names: max 128 chars, cannot start with "$", blocks / ! * #, control chars, and sentinel . Reserved names: $uploaded, $updated, $referenced_count, $user_id. */
|
|
@@ -726,11 +730,11 @@ declare class Skapi {
|
|
|
726
730
|
constructor(service: string, owner?: string | Options, options?: Options | any, __etc?: any);
|
|
727
731
|
/**
|
|
728
732
|
* Returns current connection metadata such as service name, client IP, user agent, locale, and SDK version.
|
|
729
|
-
* @param params Request parameters.
|
|
733
|
+
* @param params Request parameters. When `refresh` is true, the cached connection metadata is re-fetched before returning; otherwise the cached connection is returned.
|
|
730
734
|
* @returns A promise that resolves to Promise<ConnectionInfo>.
|
|
731
735
|
*/
|
|
732
736
|
getConnectionInfo(params?: {
|
|
733
|
-
refresh
|
|
737
|
+
refresh?: boolean;
|
|
734
738
|
}): Promise<ConnectionInfo>;
|
|
735
739
|
private _updateConnection;
|
|
736
740
|
private registerTicket;
|
|
@@ -768,12 +772,13 @@ declare class Skapi {
|
|
|
768
772
|
connectRTC(params: RTCConnectorParams, callback: (e: RTCEvent) => void): Promise<RTCConnector>;
|
|
769
773
|
/**
|
|
770
774
|
* Opens a realtime WebSocket connection and registers a callback for incoming realtime messages.
|
|
775
|
+
* The WebSocket is delivered through the callback (and stored on the instance); on the initial connection the returned promise resolves to undefined rather than the socket.
|
|
771
776
|
* @param callback Callback invoked for events or updates.
|
|
772
|
-
* @returns A promise that resolves to Promise<WebSocket>.
|
|
777
|
+
* @returns A promise that resolves to Promise<WebSocket | void>.
|
|
773
778
|
*/
|
|
774
|
-
connectRealtime(callback: RealtimeCallback): Promise<WebSocket>;
|
|
779
|
+
connectRealtime(callback: RealtimeCallback): Promise<WebSocket | void>;
|
|
775
780
|
/**
|
|
776
|
-
*
|
|
781
|
+
* Casts a spell (uploads the given spell/name). The server response is not surfaced; resolves to a fixed confirmation string.
|
|
777
782
|
* @param params Request parameters.
|
|
778
783
|
* @returns A promise that resolves to Promise<string>.
|
|
779
784
|
*/
|
|
@@ -796,25 +801,25 @@ declare class Skapi {
|
|
|
796
801
|
magic?: any;
|
|
797
802
|
}>>;
|
|
798
803
|
/**
|
|
799
|
-
*
|
|
804
|
+
* Uploads a dopamine message. In non-browser runtimes, resolves to a formatted string (including the video URL, and the previous message if one exists); in the browser it alerts and redirects, resolving to undefined.
|
|
800
805
|
* @param params Request parameters.
|
|
801
|
-
* @returns A promise that resolves to Promise<string>.
|
|
806
|
+
* @returns A promise that resolves to Promise<string | void>.
|
|
802
807
|
*/
|
|
803
808
|
dopamine(params: {
|
|
804
809
|
message: string;
|
|
805
810
|
name: string;
|
|
806
|
-
}): Promise<string>;
|
|
811
|
+
}): Promise<string | void>;
|
|
807
812
|
/**
|
|
808
813
|
* Queries unique ID records by unique_id or condition filters.
|
|
809
814
|
* @param params Request parameters.
|
|
810
815
|
* @param fetchOptions Pagination and fetch behavior options.
|
|
811
816
|
* @returns A promise that resolves to Promise<DatabaseResponse<UniqueId>>.
|
|
812
817
|
*/
|
|
813
|
-
getUniqueId(params
|
|
818
|
+
getUniqueId(params?: Form<{
|
|
814
819
|
/** Unique ID */
|
|
815
820
|
unique_id?: string;
|
|
816
|
-
/** String query condition for
|
|
817
|
-
condition?: Condition;
|
|
821
|
+
/** String query condition for the unique_id value. */
|
|
822
|
+
condition?: Condition | 'ne' | '!=';
|
|
818
823
|
}>, fetchOptions?: FetchOptions): Promise<DatabaseResponse<UniqueId>>;
|
|
819
824
|
/**
|
|
820
825
|
* Resends an existing user invitation email to the target address.
|
|
@@ -823,7 +828,6 @@ declare class Skapi {
|
|
|
823
828
|
*/
|
|
824
829
|
resendInvitation(params: Form<{
|
|
825
830
|
email: string;
|
|
826
|
-
confirmation_url?: string;
|
|
827
831
|
}>): Promise<'SUCCESS: Invitation has been re-sent. (User ID: xxx...)'>;
|
|
828
832
|
/**
|
|
829
833
|
* Cancels a pending invitation for the target email address.
|
|
@@ -839,9 +843,9 @@ declare class Skapi {
|
|
|
839
843
|
* @param fetchOptions Pagination and fetch behavior options.
|
|
840
844
|
* @returns A promise that resolves to Promise<DatabaseResponse<UserProfile>>.
|
|
841
845
|
*/
|
|
842
|
-
getInvitations(params
|
|
846
|
+
getInvitations(params?: Form<{
|
|
843
847
|
email?: string;
|
|
844
|
-
}>, fetchOptions
|
|
848
|
+
}>, fetchOptions?: FetchOptions): Promise<DatabaseResponse<UserProfile>>;
|
|
845
849
|
/**
|
|
846
850
|
* Completes OpenID login and optionally merges the OpenID identity with an existing account.
|
|
847
851
|
* @param params Request parameters.
|
|
@@ -901,7 +905,7 @@ declare class Skapi {
|
|
|
901
905
|
in_queue: number;
|
|
902
906
|
poll?: (arg?: {
|
|
903
907
|
latency?: number;
|
|
904
|
-
}) =>
|
|
908
|
+
}) => Promise<any>;
|
|
905
909
|
}>;
|
|
906
910
|
/**
|
|
907
911
|
* Retrieves the history of client secret requests for a given URL and method.
|
|
@@ -959,20 +963,20 @@ declare class Skapi {
|
|
|
959
963
|
* Lists consumed tickets with optional filters and pagination.
|
|
960
964
|
* @param params Request parameters.
|
|
961
965
|
* @param fetchOptions Pagination and fetch behavior options.
|
|
962
|
-
* @returns A promise that resolves to Promise<DatabaseResponse<any
|
|
966
|
+
* @returns A promise that resolves to Promise<DatabaseResponse<any>>.
|
|
963
967
|
*/
|
|
964
968
|
getConsumedTickets(params: {
|
|
965
969
|
ticket_id?: string;
|
|
966
|
-
}, fetchOptions?: FetchOptions): Promise<DatabaseResponse<any
|
|
970
|
+
}, fetchOptions?: FetchOptions): Promise<DatabaseResponse<any>>;
|
|
967
971
|
/**
|
|
968
972
|
* Lists issued tickets with optional filters and pagination.
|
|
969
973
|
* @param params Request parameters.
|
|
970
974
|
* @param fetchOptions Pagination and fetch behavior options.
|
|
971
|
-
* @returns A promise that resolves to Promise<DatabaseResponse<any
|
|
975
|
+
* @returns A promise that resolves to Promise<DatabaseResponse<any>>.
|
|
972
976
|
*/
|
|
973
977
|
getTickets(params: {
|
|
974
978
|
ticket_id?: string;
|
|
975
|
-
}, fetchOptions?: FetchOptions): Promise<DatabaseResponse<any
|
|
979
|
+
}, fetchOptions?: FetchOptions): Promise<DatabaseResponse<any>>;
|
|
976
980
|
/**
|
|
977
981
|
* Closes the active realtime WebSocket connection.
|
|
978
982
|
* @returns A promise that resolves to Promise<void>.
|
|
@@ -980,12 +984,12 @@ declare class Skapi {
|
|
|
980
984
|
closeRealtime(): Promise<void>;
|
|
981
985
|
/**
|
|
982
986
|
* Fetches currently connected users in a realtime group.
|
|
983
|
-
* @param params Request parameters.
|
|
987
|
+
* @param params Request parameters. When `group` is omitted, it defaults to the realtime group the user is currently joined to.
|
|
984
988
|
* @param fetchOptions Pagination and fetch behavior options.
|
|
985
989
|
* @returns A promise that resolves to Promise<DatabaseResponse<{ user_id: string; cid: string }[]>>.
|
|
986
990
|
*/
|
|
987
|
-
getRealtimeUsers(params
|
|
988
|
-
group
|
|
991
|
+
getRealtimeUsers(params?: {
|
|
992
|
+
group?: string;
|
|
989
993
|
user_id?: string;
|
|
990
994
|
}, fetchOptions?: FetchOptions): Promise<DatabaseResponse<{
|
|
991
995
|
user_id: string;
|
|
@@ -1030,11 +1034,11 @@ declare class Skapi {
|
|
|
1030
1034
|
* Invites a user by email with optional attributes and invitation email options.
|
|
1031
1035
|
* @param params Payload for the request.
|
|
1032
1036
|
* @param options Optional behavior configuration.
|
|
1033
|
-
* @returns A promise that resolves to Promise<'SUCCESS: Invitation has been sent.'>.
|
|
1037
|
+
* @returns A promise that resolves to Promise<'SUCCESS: Invitation has been sent. (User ID: xxx...)'>.
|
|
1034
1038
|
*/
|
|
1035
1039
|
inviteUser(params: UserAttributes & {
|
|
1036
|
-
openid_id
|
|
1037
|
-
access_group
|
|
1040
|
+
openid_id?: string;
|
|
1041
|
+
access_group?: number;
|
|
1038
1042
|
}, options?: {
|
|
1039
1043
|
confirmation_url?: string;
|
|
1040
1044
|
email_subscription?: boolean;
|
|
@@ -1042,15 +1046,16 @@ declare class Skapi {
|
|
|
1042
1046
|
url: string;
|
|
1043
1047
|
subject: string;
|
|
1044
1048
|
};
|
|
1045
|
-
}): Promise<'SUCCESS: Invitation has been sent.'>;
|
|
1049
|
+
}): Promise<'SUCCESS: Invitation has been sent. (User ID: xxx...)'>;
|
|
1046
1050
|
/**
|
|
1047
1051
|
* Creates a user account directly from admin context.
|
|
1048
1052
|
* @param params Payload for the request.
|
|
1049
1053
|
* @returns A promise that resolves to Promise<UserProfile & { email_admin: string; username: string; }>.
|
|
1050
1054
|
*/
|
|
1051
1055
|
createAccount(params: UserAttributes & {
|
|
1056
|
+
email: string;
|
|
1052
1057
|
password: string;
|
|
1053
|
-
access_group
|
|
1058
|
+
access_group?: number;
|
|
1054
1059
|
}): Promise<UserProfile & {
|
|
1055
1060
|
email_admin: string;
|
|
1056
1061
|
username: string;
|
|
@@ -1072,9 +1077,9 @@ declare class Skapi {
|
|
|
1072
1077
|
*/
|
|
1073
1078
|
getRealtimeGroups(params?: {
|
|
1074
1079
|
/** Index name to search. */
|
|
1075
|
-
searchFor
|
|
1080
|
+
searchFor?: 'group' | 'number_of_users';
|
|
1076
1081
|
/** Index value to search. */
|
|
1077
|
-
value
|
|
1082
|
+
value?: string | number;
|
|
1078
1083
|
/** Search condition. */
|
|
1079
1084
|
condition?: '>' | '>=' | '=' | '<' | '<=' | '!=' | 'gt' | 'gte' | 'eq' | 'lt' | 'lte' | 'ne';
|
|
1080
1085
|
/** Range of search. */
|
|
@@ -1117,7 +1122,7 @@ declare class Skapi {
|
|
|
1117
1122
|
* @returns A promise that resolves to Promise<UserProfile | null>.
|
|
1118
1123
|
*/
|
|
1119
1124
|
getProfile(options?: {
|
|
1120
|
-
refreshToken
|
|
1125
|
+
refreshToken?: boolean;
|
|
1121
1126
|
}): Promise<UserProfile | null>;
|
|
1122
1127
|
/**
|
|
1123
1128
|
* Retrieves a file by URL with optional conversion mode, expiration, and progress handling.
|
|
@@ -1170,9 +1175,9 @@ declare class Skapi {
|
|
|
1170
1175
|
* @returns A promise that resolves to Promise<DatabaseResponse<Table>>.
|
|
1171
1176
|
*/
|
|
1172
1177
|
getTables(
|
|
1173
|
-
/** If
|
|
1174
|
-
query
|
|
1175
|
-
table
|
|
1178
|
+
/** If omitted, fetches the full list of tables. */
|
|
1179
|
+
query?: {
|
|
1180
|
+
table?: string;
|
|
1176
1181
|
/** Condition operator of table name. */
|
|
1177
1182
|
condition?: Condition;
|
|
1178
1183
|
}, fetchOptions?: FetchOptions): Promise<DatabaseResponse<Table>>;
|
|
@@ -1190,7 +1195,7 @@ declare class Skapi {
|
|
|
1190
1195
|
/** Queries order by */
|
|
1191
1196
|
order?: {
|
|
1192
1197
|
/** Key name to order by. */
|
|
1193
|
-
by: 'average_number' | 'total_number' | 'number_count' | 'average_bool' | 'total_bool' | 'bool_count' | 'string_count' | 'index_name';
|
|
1198
|
+
by: 'average_number' | 'total_number' | 'number_count' | 'average_bool' | 'total_bool' | 'bool_count' | 'string_count' | 'index_name' | 'number_of_records';
|
|
1194
1199
|
/** Value to query. */
|
|
1195
1200
|
value?: number | boolean | string;
|
|
1196
1201
|
condition?: Condition;
|
|
@@ -1202,9 +1207,9 @@ declare class Skapi {
|
|
|
1202
1207
|
* @param fetchOptions Pagination and fetch behavior options.
|
|
1203
1208
|
* @returns A promise that resolves to Promise<DatabaseResponse<Tag>>.
|
|
1204
1209
|
*/
|
|
1205
|
-
getTags(query
|
|
1210
|
+
getTags(query?: {
|
|
1206
1211
|
/** Table name */
|
|
1207
|
-
table
|
|
1212
|
+
table?: string;
|
|
1208
1213
|
/** Tag name */
|
|
1209
1214
|
tag?: string;
|
|
1210
1215
|
/** String query condition for tag name. */
|
|
@@ -1240,13 +1245,13 @@ declare class Skapi {
|
|
|
1240
1245
|
*/
|
|
1241
1246
|
getUsers(params?: {
|
|
1242
1247
|
/** Index name to search. */
|
|
1243
|
-
searchFor: 'user_id' | 'email' | 'phone_number' | 'locale' | 'name' | 'address' | 'gender' | 'birthdate' | 'subscribers' | 'timestamp' | 'approved';
|
|
1248
|
+
searchFor: 'user_id' | 'email' | 'phone_number' | 'locale' | 'name' | 'address' | 'gender' | 'birthdate' | 'subscribers' | 'timestamp' | 'access_group' | 'approved';
|
|
1244
1249
|
/** Index value to search. */
|
|
1245
|
-
value: string | number |
|
|
1250
|
+
value: string | number | string[];
|
|
1246
1251
|
/** Search condition. */
|
|
1247
1252
|
condition?: '>' | '>=' | '=' | '<' | '<=' | 'gt' | 'gte' | 'eq' | 'lt' | 'lte';
|
|
1248
1253
|
/** Range of search. */
|
|
1249
|
-
range?: string | number
|
|
1254
|
+
range?: string | number;
|
|
1250
1255
|
}, fetchOptions?: FetchOptions): Promise<DatabaseResponse<UserPublic>>;
|
|
1251
1256
|
/**
|
|
1252
1257
|
* Disables the currently logged-in user account.
|
|
@@ -1267,7 +1272,7 @@ declare class Skapi {
|
|
|
1267
1272
|
* @returns A promise that resolves to Promise<string>.
|
|
1268
1273
|
*/
|
|
1269
1274
|
unsubscribeNewsletter(params: {
|
|
1270
|
-
group: number | 'public' | 'authorized' |
|
|
1275
|
+
group: number | 'public' | 'authorized' | 'admin';
|
|
1271
1276
|
}): Promise<string>;
|
|
1272
1277
|
/**
|
|
1273
1278
|
* Registers a web push subscription endpoint for notifications.
|
|
@@ -1318,9 +1323,9 @@ declare class Skapi {
|
|
|
1318
1323
|
* 'message_id' and 'subject' value should be string.<br>
|
|
1319
1324
|
* Others numbers.
|
|
1320
1325
|
*/
|
|
1321
|
-
searchFor: 'message_id' | 'timestamp' | 'read' | 'complaint' | 'subject';
|
|
1326
|
+
searchFor: 'message_id' | 'timestamp' | 'read' | 'complaint' | 'bounced' | 'subject';
|
|
1322
1327
|
value: string | number;
|
|
1323
|
-
range
|
|
1328
|
+
range?: string | number;
|
|
1324
1329
|
/**
|
|
1325
1330
|
* Defaults to '=',
|
|
1326
1331
|
* Condition does not work with range.
|
|
@@ -1336,12 +1341,18 @@ declare class Skapi {
|
|
|
1336
1341
|
*/
|
|
1337
1342
|
getNewsletterSubscription(params: {
|
|
1338
1343
|
group?: number | 'public' | 'authorized';
|
|
1344
|
+
user_id?: string;
|
|
1339
1345
|
}, fetchOptions?: FetchOptions): Promise<{
|
|
1340
1346
|
active: boolean;
|
|
1341
1347
|
timestamp: number;
|
|
1342
1348
|
group: number;
|
|
1343
1349
|
subscribed_email: string;
|
|
1344
|
-
}[]
|
|
1350
|
+
}[] | DatabaseResponse<{
|
|
1351
|
+
active: boolean;
|
|
1352
|
+
timestamp: number;
|
|
1353
|
+
group: number;
|
|
1354
|
+
subscribed_email: string;
|
|
1355
|
+
}>>;
|
|
1345
1356
|
/**
|
|
1346
1357
|
* Requests a username change confirmation flow for the current user.
|
|
1347
1358
|
* @param params Request parameters.
|
|
@@ -1559,7 +1570,7 @@ declare class Skapi {
|
|
|
1559
1570
|
/**
|
|
1560
1571
|
* Creates or updates a database record with optional file uploads.
|
|
1561
1572
|
* @param params Payload for the request.
|
|
1562
|
-
* @param config
|
|
1573
|
+
* @param config Required record configuration (table, record_id, index, tags, source, reference, etc.).
|
|
1563
1574
|
* @param files File list to process.
|
|
1564
1575
|
* @returns A promise that resolves to Promise<RecordData>.
|
|
1565
1576
|
*/
|
|
@@ -1568,7 +1579,7 @@ declare class Skapi {
|
|
|
1568
1579
|
file: File;
|
|
1569
1580
|
}[]): Promise<RecordData>;
|
|
1570
1581
|
/**
|
|
1571
|
-
* Fetches subscriber/subscription relationships with filters and pagination.
|
|
1582
|
+
* Fetches subscriber/subscription relationships with filters and pagination. At least one of `subscriber` or `subscription` must be provided.
|
|
1572
1583
|
* @param params Request parameters.
|
|
1573
1584
|
* @param fetchOptions Pagination and fetch behavior options.
|
|
1574
1585
|
* @returns A promise that resolves to Promise<DatabaseResponse<Subscription>>.
|
|
@@ -1622,10 +1633,15 @@ declare class Skapi {
|
|
|
1622
1633
|
* @returns A promise that resolves to Promise<string>.
|
|
1623
1634
|
*/
|
|
1624
1635
|
subscribeNewsletter(params: Form<{
|
|
1625
|
-
email?: string;
|
|
1626
|
-
group: number | 'public' | 'authorized' | 'admin';
|
|
1636
|
+
email?: string | string[];
|
|
1637
|
+
group: number | 'public' | 'authorized' | 'admin' | (string & {});
|
|
1627
1638
|
redirect?: string;
|
|
1628
1639
|
}>): Promise<string>;
|
|
1640
|
+
/**
|
|
1641
|
+
* Creates or updates multiple database records in a single bulk request. Requires a non-empty array, and all entries must share the same table/service.
|
|
1642
|
+
* @param config Non-empty array of record configurations to post.
|
|
1643
|
+
* @returns A promise that resolves to Promise<RecordData[]>.
|
|
1644
|
+
*/
|
|
1629
1645
|
bulkPostRecords(config: PostRecordConfig[]): Promise<RecordData[]>;
|
|
1630
1646
|
}
|
|
1631
1647
|
|
package/dist/skapi.js
CHANGED
|
@@ -215,7 +215,7 @@ var Ls=Object.create;var Ne=Object.defineProperty;var qr=Object.getOwnPropertyDe
|
|
|
215
215
|
runInterval(); // Start interval
|
|
216
216
|
`,o=new Blob([s],{type:"application/javascript"});Ee=new Worker(URL.createObjectURL(o)),Ee.onmessage=a=>{i.readyState===1&&i.send(JSON.stringify({action:"keepAlive"}));},n(i);},i.onmessage=async s=>{let o="";try{o=JSON.parse(decodeURI(s.data)),this.log("socket onmessage",o);}catch{return}let a;switch(true){case !!o?.["#message"]:a="message";break;case !!o?.["#private"]:a="private";break;case !!o?.["#notice"]:a="notice";break;case !!o?.["#rtc"]:a="rtc";break;case !!o?.["#error"]:a="error";break}if(!a)return;let u={type:a,message:o?.["#rtc"]||o?.["#message"]||o?.["#private"]||o?.["#notice"]||o?.["#error"]||null,sender:o?.["#user_id"]||null,sender_cid:o?.["#scid"]?"cid:"+o["#scid"]:null,sender_rid:o?.["#srid"]||null,code:o?.["#code"]||null};if(a==="notice")r(u);else if(a==="rtc"){if(u.sender!==this.user.user_id){let c=u.message;if(c.hungup){se[u.sender_cid]&&(se[u.sender_cid](false),delete se[u.sender_cid]),fe[u.sender_cid]&&delete fe[u.sender_cid],x?.[u.sender_cid]&&oe.bind(this)({cid:u.sender_cid}),u.type="rtc:closed",r(u);return}if(c.candidate&&Nr.bind(this)(c.candidate,u.sender_cid),c.sdpoffer&&(kr.bind(this)(c.sdpoffer,u.sender_cid),fe[u.sender_cid]||(fe[u.sender_cid]=u.sender_cid,delete u.message,u.connectRTC=Gi.bind(this)(u),u.type="rtc:incoming",u.hangup=(()=>{x[u.sender_cid]?oe.bind(this)({cid:u.sender_cid}):fe[u.sender_cid]&&(delete fe[u.sender_cid],i.send(JSON.stringify({action:"rtc",uid:u.sender_cid,content:{hungup:this.user.user_id},token:this.session.accessToken.jwtToken})));}).bind(this),r(u))),c.pickup&&se[u.sender_cid]&&(se[u.sender_cid](true),delete se[u.sender_cid]),c.sdpanswer&&x[u.sender_cid])if(x[u.sender_cid].signalingState==="have-local-offer")await x[u.sender_cid].setRemoteDescription(new RTCSessionDescription(c.sdpanswer));else throw new f("Invalid signaling state.",{code:"INVALID_REQUEST"})}}else r(u);},i.onclose=()=>{it?(this.log("realtime onclose","WebSocket connection closed."),r({type:"close",message:"WebSocket connection closed."})):(this.log("realtime onclose","WebSocket unexpected close."),r({type:"error",message:"Skapi: WebSocket unexpected close."}),Ge++,Ge<3?(this.log("realtime onclose","Reconnecting to WebSocket server..."+Ge),r({type:"reconnect",message:"Reconnecting to WebSocket server..."+Ge}),Bt.bind(this)(r,3e3,"reconnect")):(this.log("realtime onclose","Max reconnection attempts reached."),r({type:"error",message:"Skapi: Max reconnection attempts reached."})));},i.onerror=()=>{this.log("realtime onerror","WebSocket connection error."),r({type:"error",message:"Skapi: WebSocket connection error."});};},e);});}async function Xi(r,e,t){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 He.bind(this)(),r=L(r).data;let i="";if(t&&(t=m.Params(t,{config:{always:"boolean"},title:"string",body:"string"},["title","body"]),i=JSON.stringify({title:t.title,body:t.body}),new Blob([i]).size>3072))throw new f("Notification size exceeds 3kb.",{code:"INVALID_PARAMETER"});if(n.readyState===1){try{m.UserId(e),n.send(JSON.stringify({action:"sendMessage",uid:e,content:r,notification:i,notificationConfig:t?.config||{},token:`IdT:${this.service}:${this.owner}:`+(this.bearerToken||this.session?.idToken?.jwtToken||"null")}));}catch(s){if(this.log("postRealtime:err",{err:s}),Se!==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:r,notification:i,notificationConfig:t?.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 Lr(r){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 He.bind(this)(),r=L(r,{nullIfEmpty:true}).data;let{group:t=null}=r;if(!t&&!Se)return {type:"success",message:"Left realtime message group."};if(t!==null&&typeof t!="string")throw new f('"group" must be a string | null.',{code:"INVALID_PARAMETER"});return e.send(JSON.stringify({action:"joinRoom",rid:t,token:this.session.accessToken.jwtToken})),Se=t,{type:"success",message:t?`Joined realtime message group: "${t}".`:"Left realtime message group."}}async function Zi(r,e){r=m.Params(r,{user_id:n=>m.UserId(n,'User ID in "user_id"'),group:["string",()=>{if(!Se)throw new f('No group has been joined. Otherwise "group" is required.',{code:"INVALID_REQUEST"});return Se}]});let t=await S.bind(this)("get-ws-group",r,{fetchOptions:e,auth:true,method:"post"});return t.list=t.list.map(n=>({user_id:n.uid.split("#")[1],cid:"cid:"+n.cid})),t}async function es(r,e){if(await this.__connection,r||(r={searchFor:"group",value:" ",condition:">"}),r=m.Params(r,{searchFor:["group","number_of_users",()=>"group"],value:["string","number",()=>r?.searchFor&&r?.searchFor==="number_of_users"?0:" "],condition:[">",">=","=","<","<=","!=","gt","gte","eq","lt","lte","ne"],range:["string","number"]}),r.condition||(r.value===" "||!r.value?r.condition=">":r.condition="="),r.range&&r.condition&&delete r.condition,r.searchFor==="number_of_users"&&typeof r.value!="number")throw new f('"value" must be a number.',{code:"INVALID_PARAMETER"});if(r.searchFor==="group"&&typeof r.value!="string")throw new f('"value" must be a string.',{code:"INVALID_PARAMETER"});if(r.hasOwnProperty("range")&&typeof r.range!=typeof r.value)throw new f(`"range" must be a ${typeof r.value}.`,{code:"INVALID_PARAMETER"});let t=await S.bind(this)("get-ws-group",r,{fetchOptions:e,auth:true,method:"post"});return t.list=t.list.map(n=>({group:n.rid.split("#")[1],number_of_users:n.cnt})),t}var Zu=typeof FormData<"u",ec=typeof HTMLFormElement<"u",tc=typeof SubmitEvent<"u",ve={},Or={};function ts({id:r,auth:e,service:t,owner:n,latency:i=1e3,queue:s,onResponse:o,onError:a}){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&&!ve?.[s]&&(ve[s]=new et({breakWhenError:false,batchSize:1}));let u=()=>new Promise((c,d)=>{let l=false,h=setInterval(async()=>{try{let p=await S.bind(this)("csr-poll",{id:r,service:t,owner:n},{auth:e});if(p.status==="running"||p.status==="pending"||l)return;l=!0,o&&o(p),clearInterval(h),c(p);}catch(p){if(l)return;l=true,a&&a(p),clearInterval(h),d(p);}},i);});return s?new Promise((c,d)=>{let l=ve[s].add([async()=>{try{let h=await u();return c(h),h}catch(h){throw d(h),h}}])[0];Or[r]=l;}):u()}function rs(r,e){if(!r.queue)throw new f('"queue" is required.',{code:"INVALID_PARAMETER"});let t={service:r.service||this.service,owner:r.owner||this.owner,queue:r.queue+":"};return S.bind(this)("csr-poll",t,{auth:true})}async function ns(r){let e=false;if(typeof r.poll=="number"&&r.poll<0)throw new f('"poll" should be a non-negative number.',{code:"INVALID_PARAMETER"});let t=r?.onResponse,n=r?.onError,i=typeof r.poll=="number"?r.poll:r.poll?1e3:0;delete r.poll,i&&!r.queue&&(r.queue=(this.__user?.user_id||"anonymous")+"-"+De());let s=u=>{for(let c in u)if(typeof u[c]=="string"&&u[c].includes("$CLIENT_SECRET")){e=true;break}};if(r=m.Params(r,{url:u=>{if(!u||typeof u!="string")throw new f('"url" should be type: <string>.',{code:"INVALID_PARAMETER"});return m.Url(u),u.includes("$CLIENT_SECRET")&&(e=true),u},clientSecretName:"string",method:u=>{if(u&&typeof u!="string")throw new f('"method" should be either "GET" or "POST" or "DELETE" or "PUT".',{code:"INVALID_PARAMETER"});let c=u.toLowerCase();if(c!=="get"&&c!=="post"&&c!=="delete"&&c!=="put")throw new f('"method" should be either "GET" or "POST" or "DELETE" or "PUT".',{code:"INVALID_PARAMETER"});return c},headers:u=>{if(u&&typeof u!="object")throw new f('"headers" should be type: <object>.',{code:"INVALID_PARAMETER"});return s(u),u},data:u=>{if(u&&typeof u!="object")throw new f('"data" should be type: <object>.',{code:"INVALID_PARAMETER"});return s(u),u},params:u=>{if(u&&typeof u!="object")throw new f('"params" should be type: <object>.',{code:"INVALID_PARAMETER"});return s(u),u},expires:"number",queue:"string"},["clientSecretName","method","url"]),!e)throw new f(`At least one parameter value should include "$CLIENT_SECRET" in ${r.method.toLowerCase()==="post"?'"data"':'"params"'} or "headers".`,{code:"INVALID_PARAMETER"});await this.__connection;let o=!!this.__user,a=()=>S.bind(this)("csr",r,{auth:o,tokenHeaders:{accessToken:!!o}}).then(u=>{if(u.status==="running"||u.status==="pending"){let c=`[${r.method.toUpperCase()}]${r.url.toLowerCase()}`,d=r.service||this.service,l=r.owner||this.owner,h=`${c}#${d}:${u.id}`;Object.assign(u,{poll:async p=>ts.call(this,{id:h,auth:o,service:d,owner:l,latency:p?.latency||1e3,queue:r?.queue,onResponse:t,onError:n})});}return t?t(u):u}).catch(u=>{if(n)return n(u);throw u});if(r?.queue){let u="base:"+r.queue;return ve?.[u]||(ve[u]=new et({breakWhenError:false,batchSize:1})),new Promise((c,d)=>{ve[u].add([async()=>{try{let l=await a();if(i>0){let h=l.poll({latency:i});return c(h),h}return c(l),l}catch(l){throw d(l),l}}]);})}else return a()}async function is(r,e){await this.__connection;let t=r.service||this.service,n=r.owner||this.owner;r=m.Params(r,{url:"string",method:["GET","POST","DELETE","PUT"],queue:"string",status:["pending","running","resolved","failed"]},["url","method"]);let i=!!this.__user,s=`[${r.method.toUpperCase()}]${r.url.toLowerCase()}#${t}:`,o={id:s,queue:r?.queue,status:r?.status,service:t,owner:n};Object.keys(o).forEach(u=>{o[u]||delete o[u];}),o.queue&&delete o.id;let a=await S.bind(this)("csr-poll",o,{auth:i,fetchOptions:e});return a.list=a.list.map(u=>{let c={id:u.id,status_code:u.rslv?.status_code||null,response_body:u.rslv?.body||u.rslv?.truncated||null,error:u?.err,updated:u?.utmp,request_body:u?.reqbdy,expires:u?.expt,status:u.stts,queue_name:u?.qid};for(let d in c)c[d]===void 0&&delete c[d];return (c.status==="running"||c.status==="pending")&&(c.poll=d=>ts.call(this,{id:s+c.id,auth:i,service:t,owner:n,latency:d?.latency||1e3,queue:u?.qid,onResponse:d?.onResponse,onError:d?.onError})),c}),a}async function ss(r){await this.__connection,r=m.Params(r,{url:"string",method:["GET","POST","DELETE","PUT"],id:"string",queue:"string"},["url","method","id"]);let e=r?.service||this.service,t=r?.owner||this.owner,n=!!this.__user,i=`[${r.method.toUpperCase()}]${r.url.toLowerCase()}#${e}`,s=r.id,o=`${i}:${s}`,a=r?.queue;return a&&ve?.[a]&&(ve[a].remove(Or[o]),delete Or[o]),S.bind(this)("csr-cancel",{id:o,service:e,owner:t},{auth:n})}async function os(r){await this.__connection;let e={name:"string",email:t=>(m.Email(t),t),subject:"string",message:"string"};return r=m.Params(r,e,["name","email","subject","message"]),await S.bind(this)("send-inquiry",r),"SUCCESS: Inquiry has been sent."}async function as(r,e){if(await this.__connection,Zu&&r instanceof FormData||ec&&r instanceof HTMLFormElement||tc&&r instanceof SubmitEvent){if(!e)throw new f("Url string as a second argument is required when form is passed.",{code:"INVALID_PARAMETER"});let n=L(r);r={url:e,data:n.data,sync:true};}let t={url:n=>m.Url(n),data:n=>n,sync:["boolean",()=>true]};if(Array.isArray(r))for(let n of r)n=m.Params(n,t);else r=m.Params(r,t);return S.bind(this)("post-secure",r,{auth:true})}async function us(r,e){await this.__connection;let{auth:t=false,method:n="POST",bypassAwaitConnection:i=false,responseType:s,contentType:o,tokenHeaders:a,progress:u}=e||{};if(e=Object.assign({auth:t,method:n,bypassAwaitConnection:i,responseType:s,contentType:o,tokenHeaders:a},{fetchOptions:{progress:u}}),typeof r!="object"&&(o==="application/json"||o===void 0))throw new f('"data" should be type: <object>.',{code:"INVALID_PARAMETER"});return S.bind(this)("mock",r,e)}async function cs(r,e){await this.__connection,r=m.Params(r||{},{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 t=await S.bind(this)("get-feed",r,{auth:true,fetchOptions:e});for(let n in t.list)t.list[n]=await Je.bind(this)(t.list[n]);return t}function st(r){if(r===this.__user.user_id)throw new f(`"user_id" cannot be the user's own ID.`,{code:"INVALID_PARAMETER"});return m.UserId(r,'"user_id"')}async function ls(r,e){if(r=L(r,{ignoreEmpty:true}).data,r=m.Params(r,{subscriber:n=>m.UserId(n,'User ID in "subscriber"'),subscription:st.bind(this),blocked:"boolean"}),!r.subscriber&&!r.subscription)throw new f('At least either "subscriber" or "subscription" should have a value.',{code:"INVALID_PARAMETER"});let t=await S.bind(this)("get-subscription",r,Object.assign({auth:true},{fetchOptions:e}));return t.list=t.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})),t}async function ds(r){await this.__connection,r=m.Params(r,{user_id:st.bind(this),get_feed:["boolean",()=>false],get_notified:["boolean",()=>false],get_email:n=>{if(n&&!this.__user.email||!this.__user.email_verified)throw new f("User has no verified email address.",{code:"INVALID_REQUEST"});return !!n}},["user_id"]);let e=await S.bind(this)("subscription",{subscribe:r.user_id,option:{get_feed:r.get_feed,get_notified:r.get_notified,get_email:r.get_email||false}},{auth:true}),t={};if(e.sub){let n=e.sub.split("#");t.subscriber=n[2],t.subscription=n[0];}else t.subscriber=e.subscriber,t.subscription=e.subscription;return t.timestamp=e?.timestamp||e.stmp,t.blocked=e?.blocked||e.grp.substring(0,1)==="N",Object.assign(t,e.opt),t}async function fs(r){await this.__connection;let{user_id:e}=m.Params(r,{user_id:st.bind(this)},["user_id"]);return await S.bind(this)("subscription",{unsubscribe:e},{auth:true})}async function hs(r){await this.__connection;let{user_id:e}=m.Params(r,{user_id:st.bind(this)},["user_id"]);return await S.bind(this)("subscription",{block:e},{auth:true})}async function gs(r){await this.__connection;let{user_id:e}=m.Params(r,{user_id:st.bind(this)},["user_id"]);return await S.bind(this)("subscription",{unblock:e},{auth:true})}async function ps(r,e){await this.__connection;let t=await J.bind(this)();r=m.Params(r,{user_id:o=>{if(o!==this.__user.user_id&&!t)throw new f("No access.",{code:"INVALID_REQUEST"});return o},group:o=>{if(o==="public"&&(o=0),o==="authorized"&&(o=1),typeof o!="number")throw new f('"group" should be type number | "public" | "authorized".',{code:"INVALID_PARAMETER"});return o}});let n=await S.bind(this)("get-newsletter-subscription",r,{auth:true,fetchOptions:e||null}),i=n?.list||n,s=[];Array.isArray(i)||(i=[]);for(let o of i){let a=o.subt.split("#"),u=true;a[0].charAt(0)==="@"&&(u=false,a[0]=a[0].substring(1));let c=parseInt(a[0]);s.push({timestamp:o.stmp,group:c,subscribed_email:a[1],active:u});}return n?.list?(n.list=s,n):s}async function ms(r){await this.__connection;let e=m.Params(r||{},{email:t=>Array.isArray(t)&&t.length>0?t.length===1?m.Email(t[0]):t.map(n=>m.Email(n)):m.Email(t),group:["number","public","authorized","admin",t=>{if(typeof t!="string"||t.length>20||!/^[a-zA-Z0-9]+$/.test(t))throw new f('"group" should be an alphanumeric string without spaces and less than 20 characters.',{code:"INVALID_PARAMETER"});return t}],redirect:t=>m.Url(t)},this.__user?["group"]:["email","group"]);return S.bind(this)(`subscribe-${this.__user?"":"public-"}newsletter`,e,{auth:!!this.__user})}async function _s(r){await this.__connection,r=m.Params(r,{group:["number","public","authorized","admin"]},["group"]);let e=Object.assign({action:"unsubscribe"},r);return S.bind(this)("subscribe-newsletter",e,{auth:true})}async function bs(r,e){let t=await J.bind(this)(),n={message_id:"string",timestamp:"number",read:"number",complaint:"number",subject:"string",bounced:"number"};r||(e=Object.assign({ascending:false},e||{})),r=L(r).data,r=r||{searchFor:"timestamp",value:Date.now(),condition:"<",group:"public"},r=m.Params(r,{searchFor:["message_id","timestamp","subject","complaint","read","bounced"],value:u=>{if(typeof u!==n[r.searchFor])throw new f(`"value" type does not match the type of "${r.searchFor}" index.`,{code:"INVALID_PARAMETER"});if(typeof u=="string"&&!u)throw new f('"value" should not be empty string.',{code:"INVALID_PARAMETER"});return u},range:u=>{if(!r.hasOwnProperty("value")||typeof u!=typeof r.value)throw new f('"range" should match type of "value".',{code:"INVALID_PARAMETER"});return u},condition:[">",">=","=","<","<=","gt","gte","eq","lt","lte",()=>"="],group:u=>{if(u==="public")return 0;if(!this.session)throw new f("User should be logged in.",{code:"INVALID_REQUEST"});if(u==="authorized")return 1;if(typeof u=="number"){if(!t&&u>parseInt(this.user?.access_group||this.session?.idToken?.payload?.access_group))throw new f("User has no access.",{code:"INVALID_REQUEST"});return u}throw new f('"group" should be type: number | "public" | "authorized".',{code:"INVALID_PARAMETER"})}},["searchFor","value","group"]);let i=r.group===0?"get-public-newsletters":"get-newsletters",s=await S.bind(this)(i,r,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"},a={message_id:"",timestamp:0,complaint:0,read:0,subject:"",bounced:"",url:"",delivered:0};return s.list=s.list.map(u=>{let c={};for(let d in o)c[d]=u[o[d]]||a[d];return c.bounced=String(c.bounced),c}),s}async function ys(r){let e=m.Params(r,{user_id:n=>m.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 J.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 S.bind(this)("block-account",e,{auth:true})}async function ws(r){let e=m.Params(r,{user_id:n=>m.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 J.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 S.bind(this)("block-account",e,{auth:true})}async function As(r){let e=m.Params(r,{user_id:n=>m.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 J.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 S.bind(this)("remove-account",e,{auth:true})}async function Es(r,e){let t={email:s=>m.Email(s),password:s=>m.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=>m.Birthdate(s),phone_number:s=>m.PhoneNumber(s),picture:s=>{if(s)return m.Url(s)},profile:s=>{if(s)return m.Url(s)},website:s=>{if(s)return m.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=m.Params(r,t,["email"]);if(e=m.Params(e,{confirmation_url:s=>{let o=s;if(typeof s=="string")o=m.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:m.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 J.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 S.bind(this)("admin-signup",n,{auth:true})}async function Ss(r){let e={email:s=>m.Email(s),password:s=>m.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=>m.Birthdate(s),phone_number:s=>m.PhoneNumber(s),picture:s=>s?m.Url(s):"",profile:s=>s?m.Url(s):"",website:s=>s?m.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}},t=["email","password"],n=m.Params(r,e,t);if(!await J.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 S.bind(this)("admin-signup",n,{auth:true})}async function vs(r){if(r=m.Params(r,{user_id:t=>m.UserId(t,'"user_id"'),access_group:t=>{try{typeof t=="string"&&(t=parseInt(t));}catch{throw new f('"access_group" is invalid. Should be type <number>.',{code:"INVALID_PARAMETER"})}if(typeof t=="number"&&t>0&&t<100)return t;throw new f('"access_group" is invalid. Should be type <number> of range 1~99',{code:"INVALID_PARAMETER"})}},["user_id","access_group"]),!await J.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 S.bind(this)("grant-access",r,{auth:true})}async function Ts(r,e){if(r=m.Params(r,{email:"string"}),!await J.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 S.bind(this)("invitation-list",Object.assign({mode:"search"},r),{fetchOptions:e,auth:true});return n.list=n.list.map(i=>Ye(i.user)),n}async function Rs(r){if(r=m.Params(r,{email:t=>m.Email(t)},["email"]),!await J.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 S.bind(this)("invitation-list",Object.assign({mode:"cancel"},r),{auth:true})}async function Is(r){if(r=m.Params(r,{email:t=>m.Email(t)},["email"]),!await J.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 S.bind(this)("invitation-list",Object.assign({mode:"resend"},r),{auth:true})}async function Ps(r){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,!r.endpoint)throw new f("Missing parameter: endpoint",{code:"INVALID_PARAMETER"});if(!r.keys||!r.keys.p256dh||!r.keys.auth)throw new f("Missing parameter: keys.p256dh or keys.auth",{code:"INVALID_PARAMETER"});return await S.bind(this)("store-subscription",{endpoint:r.endpoint,keys:r.keys},{auth:true}),"SUCCESS: Subscribed to receive notifications."}async function xs(r){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,!r.endpoint)throw new f("Missing parameter: endpoint",{code:"INVALID_PARAMETER"});if(!r.keys||!r.keys.p256dh||!r.keys.auth)throw new f("Missing parameter: keys.p256dh or keys.auth",{code:"INVALID_PARAMETER"});return await S.bind(this)("delete-subscription",{endpoint:r.endpoint,keys:r.keys},{auth:true}),"SUCCESS: Unsubscribed from notifications."}async function Us(){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 S.bind(this)("get-vapid-public-key",null,{auth:true})}}async function Cs(r,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:t,body:n}=L(r||{},{nullIfEmpty:true}).data;if(!t)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:t,body:n};return e?(typeof e=="string"&&(e=[e]),i.user_ids=e):i.user_ids="all_users",await S.bind(this)("push-notification",i,{auth:true}),"SUCCESS: Notification sent."}async function Ds(r){await this.__connection,r=m.Params(r,{spell:"string",name:"string",magic:t=>t},["spell","name"]);await S.bind(this)("castspell",r);return `The spell "${r.spell}" has been cast.`}async function ks(r){return await this.__connection,r=m.Params(r||{},{search:["spell","name",()=>"spell"],value:"string"}),await S.bind(this)("getspell",r)}async function Ns(r){await this.__connection,r=m.Params(r,{message:"string",name:"string"},["message","name"]);let e=await S.bind(this)("dopamine",r,{auth:true}),t=e?.previous_message?.message,n=e?.previous_message?.name;if(z())t&&n&&window.alert(`${n} said: ${t}`),window.location.href=e.video;else return t&&n?`${n} said: ${t}
|
|
217
217
|
Watch the video here: ${e.video}`:`Your message has been uploaded for future generations to receive.
|
|
218
|
-
Watch the video here: ${e.video}`}var E=class{constructor(e,t,n,i){this.__version="1.6.
|
|
218
|
+
Watch the video here: ${e.video}`}var E=class{constructor(e,t,n,i){this.__version="1.6.2";this.session=null;this.connection=null;this.__my_unique_ids={};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=30;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 m.UserId(e),!0}catch{return false}},url(e){try{return m.Url(e),!0}catch{return false}},phoneNumber(e){try{return m.PhoneNumber(e),!0}catch{return false}},birthdate(e){try{return m.Birthdate(e),!0}catch{return false}},email(e){try{return m.Email(e),!0}catch{return false}},params(e,t,n){return m.Params(e,t,n)}};this.util={MD5:Q,generateRandom:De,toBase62:Qn,fromBase62:ne,decodeServiceId:vr,formatServiceId:zn,extractFormData:L,terminatePendingRequests:Si,request:(e,t,n)=>S.bind(this)(e,t,n,{ignoreService:true})};this.__network_logs=false;this.__endpoint_version="v1";this.__public_identifier="";this.bearerToken="";this.registerTicket=ti.bind(this);this.unregisterTicket=ri.bind(this);if(!e||typeof e!="string")throw this._alert("Service ID is required."),new f("Service ID is required.",{code:"INVALID_PARAMETER"});let s=e.split("-").length;if(s===2||s===7)try{let g=vr(e);n&&typeof n=="object"&&(i=n),t&&typeof t=="object"&&(n=t),t=g.owner,e=g.service;}catch{throw this._alert("Service ID is invalid."),new f("Service ID is invalid.",{code:"INVALID_PARAMETER"})}if(!t||typeof t!="string")throw this._alert("Owner ID is invalid."),new f("Owner ID is invalid.",{code:"INVALID_PARAMETER"});if(e.toLowerCase()==="service_id")throw this._alert('Replace "service_id" with your actual Service ID.'),new f("Service ID is required.",{code:"INVALID_PARAMETER"});if(t!==this.host)try{m.UserId(t,'"owner"');}catch{throw this._alert("Owner ID is invalid."),new f("Owner ID is invalid.",{code:"INVALID_PARAMETER"})}this.service=e,this.owner=t;let u=true;if(n&&(typeof n.autoLogin=="boolean"&&(u=n.autoLogin),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`,d=e.substring(0,4);this.admin_endpoint=fetch(`${c}/${d}/admin-${this.__endpoint_version}.json`).then(g=>g.blob()).then(g=>new Promise((b,w)=>{let _=new FileReader;_.onloadend=()=>b(_.result),_.onerror=w,_.readAsDataURL(g);})).then(g=>{try{return typeof g=="string"?JSON.parse(atob(g.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}/${d}/record-${this.__endpoint_version}.json`).then(g=>g.blob()).then(g=>new Promise((b,w)=>{let _=new FileReader;_.onloadend=()=>b(_.result),_.onerror=w,_.readAsDataURL(g);})).then(g=>{try{return typeof g=="string"?JSON.parse(atob(g.split(",")[1])):null}catch{throw new f("Service does not exist. Create your service from skapi.com",{code:"NOT_EXISTS"})}});let l=z();if(l&&!window.sessionStorage)throw this._alert("This browser is not supported."),new Error("This browser is not supported.");let h=l?JSON.parse(window.sessionStorage.getItem(`${e}#${t}`)||"null"):null;if(this.log("constructor:restore",h),h?.connection){for(let g in h)this[g]=h[g];h.__public_identifier||(this.__public_identifier=`${this.service}:${this.owner}:${De(16)}`);}this.__authConnection=(async()=>{let g=await this.admin_endpoint,b={UserPoolId:g.userpool_id,ClientId:g.userpool_client};Sr()&&(b.Storage=window.localStorage),this.userPool=new wr(b);try{this.user||await W.bind(this)().getSession({skipUserUpdateEventTrigger:!0}),this.user&&(!h?.connection&&!u?be.bind(this)():(this._runOnLoginListeners(this.user),this._runOnUserUpdateListeners(this.user)));}catch{}})();let p=l?window.sessionStorage.getItem(`${this.service}:uniqueids`):null;if(p)try{this.__my_unique_ids=JSON.parse(p);}catch{this.__my_unique_ids={};}this.__connection=(async()=>{let g=null;await this.record_endpoint,h?.connection||(g=this._updateConnection());let b=()=>{if(this.__class_properties_has_been_cached)return;let w=()=>{let _={},R=["__startKeyHistory","__disabledAccount","__cached_requests","__request_signup_confirmation","__public_identifier","connection"];if(this.connection){for(let C of R)_[C]=this[C];l&&window.sessionStorage.setItem(`${e}#${t}`,JSON.stringify(_)),this.__class_properties_has_been_cached=true;}};return g instanceof Promise?g.then(()=>w()):w()};return l&&(window.addEventListener("beforeunload",()=>{this.closeRealtime(),b();}),window.addEventListener("visibilitychange",()=>{b();})),await g,await this.__authConnection,this.connection})(),this.__connection.then(g=>{((g?.group||0)<3||this.__network_logs)&&this.version();});}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 t of this._userProfileListeners)typeof t=="function"&&t(e);}_runOnLoginListeners(e){for(let t of this._onLoginListeners)typeof t=="function"&&t(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);}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 {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 t=e?.refresh||false;try{this.connection=await S.bind(this)("service",{service:this.service,owner:this.owner,refresh:t},{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 t=`Built with:
|
|
219
219
|
%c\r
|
|
220
220
|
$$\\ $$\\ \r
|
|
221
221
|
$$ | \\__|\r
|