skapi-js 0.0.51 → 0.0.53
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.js +1 -1
- package/dist/skapi.js.map +1 -1
- package/dist/skapi.module.js +1 -1
- package/dist/skapi.module.js.map +1 -1
- package/package.json +4 -1
- package/deploy.py +0 -29
- package/src/Api.ts +0 -3
- package/src/Types.ts +0 -386
- package/src/decorators.ts +0 -95
- package/src/skapi.ts +0 -3382
- package/src/skapi_error.ts +0 -43
- package/src/utils.ts +0 -794
- package/tsconfig.json +0 -116
- package/webpack.config.js +0 -25
package/package.json
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "skapi-js",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.53",
|
|
4
4
|
"description": "skapi serverless cloud javascript library",
|
|
5
5
|
"main": "./dist/skapi.module.js",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist/"
|
|
8
|
+
],
|
|
6
9
|
"scripts": {
|
|
7
10
|
"build": "npx tsc ; npx webpack --config webpack.config.js ; npx typedoc"
|
|
8
11
|
},
|
package/deploy.py
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import json
|
|
2
|
-
import os
|
|
3
|
-
|
|
4
|
-
ret = os.system('git pull')
|
|
5
|
-
|
|
6
|
-
if ret != 0:
|
|
7
|
-
print('==Failed to pull==')
|
|
8
|
-
|
|
9
|
-
ret = os.system('npm run build')
|
|
10
|
-
|
|
11
|
-
if ret != 0:
|
|
12
|
-
print('==Failed to build==')
|
|
13
|
-
|
|
14
|
-
with open('./package.json', 'r') as p:
|
|
15
|
-
package = json.loads(p.read())
|
|
16
|
-
|
|
17
|
-
ret = os.system('npm publish')
|
|
18
|
-
|
|
19
|
-
if ret != 0:
|
|
20
|
-
print('==Failed to publish==')
|
|
21
|
-
|
|
22
|
-
else:
|
|
23
|
-
ret = os.system(
|
|
24
|
-
f'aws s3 sync ./dist s3://broadwayinc.dev/jslib/skapi/{package["version"]} --acl public-read')
|
|
25
|
-
|
|
26
|
-
if ret != 0:
|
|
27
|
-
print('==Failed to upload==')
|
|
28
|
-
|
|
29
|
-
print('==END==')
|
package/src/Api.ts
DELETED
package/src/Types.ts
DELETED
|
@@ -1,386 +0,0 @@
|
|
|
1
|
-
export type Connection = {
|
|
2
|
-
/** Connection locale */
|
|
3
|
-
locale: string;
|
|
4
|
-
/** User ID of the service owner */
|
|
5
|
-
owner: string;
|
|
6
|
-
/** E-Mail address of the service owner */
|
|
7
|
-
email: string;
|
|
8
|
-
/** Service id */
|
|
9
|
-
service: string;
|
|
10
|
-
/** Service region */
|
|
11
|
-
region: string;
|
|
12
|
-
/** 13 digits timestamp of the service creation */
|
|
13
|
-
timestamp: number;
|
|
14
|
-
/** Hash string for authentication */
|
|
15
|
-
hash: string;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Additional option for form requests.
|
|
20
|
-
* You can attach callbacks on response and error.
|
|
21
|
-
* If there is a response callback, form will not trigger redirect.
|
|
22
|
-
* <b>Example:</b>
|
|
23
|
-
*
|
|
24
|
-
* ```
|
|
25
|
-
* <form onsubmit="skapi.method(this, { response:r=>r, onerror: err=>err } ); return false;">
|
|
26
|
-
* <input name='NameIsKey' value='Some value'></input>
|
|
27
|
-
* </form>
|
|
28
|
-
* ```
|
|
29
|
-
*/
|
|
30
|
-
export type FormCallbacks = {
|
|
31
|
-
/** Callback for form response */
|
|
32
|
-
response?(response: any): any;
|
|
33
|
-
/** Callback on error. When boolen true is given, alertbox will show. */
|
|
34
|
-
onerror?: (error: Error) => any;
|
|
35
|
-
/** Middleware callback for extracted FormData from HTMLFormElement. Will not execute if form is not HTMLFormElement.*/
|
|
36
|
-
formData?: (formData: FormData) => Promise<FormData> | FormData;
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* You can pass parameters with html forms if the method supports it.
|
|
41
|
-
*
|
|
42
|
-
* <b>Example:</b>
|
|
43
|
-
*
|
|
44
|
-
* ```
|
|
45
|
-
* <form onsubmit="skapi.method(this, options); return false;">
|
|
46
|
-
* <input name='NameIsKey' value='Some value'></input>
|
|
47
|
-
* </form>
|
|
48
|
-
*
|
|
49
|
-
* // Above is equivalent as skapi.method({NameIsKey: 'Some Value'}, option);
|
|
50
|
-
* // Form is useful when posting binary files.
|
|
51
|
-
* // Javascript FormData is also supported.
|
|
52
|
-
* ```
|
|
53
|
-
*/
|
|
54
|
-
export type Form = HTMLFormElement | FormData | Record<string, any>;
|
|
55
|
-
|
|
56
|
-
export type Newsletters = {
|
|
57
|
-
/** Newsletter id */
|
|
58
|
-
message_id: string;
|
|
59
|
-
/** Time sent out */
|
|
60
|
-
timestamp: number;
|
|
61
|
-
/** Number of complaints */
|
|
62
|
-
complaint: number;
|
|
63
|
-
/** Number of read */
|
|
64
|
-
read: number;
|
|
65
|
-
/** Subject */
|
|
66
|
-
subject: string;
|
|
67
|
-
/**
|
|
68
|
-
* Number of bounced.<br>
|
|
69
|
-
* When e-mail address is bounced, skapi no longer sends e-mail to the bounced address.
|
|
70
|
-
*/
|
|
71
|
-
bounced: string;
|
|
72
|
-
/**
|
|
73
|
-
* Url of the message html.
|
|
74
|
-
*/
|
|
75
|
-
url: string;
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
export type UserProfile = {
|
|
79
|
-
/** Service id of the user account. */
|
|
80
|
-
service: string;
|
|
81
|
-
/** User ID of the service owner. */
|
|
82
|
-
service_owner?: string;
|
|
83
|
-
/** Access level of the user's account. */
|
|
84
|
-
access_group?: number;
|
|
85
|
-
/** User's ID. */
|
|
86
|
-
user_id: string;
|
|
87
|
-
/** Country code of where user signed up from. */
|
|
88
|
-
locale: string;
|
|
89
|
-
/**
|
|
90
|
-
* User's E-Mail for signin.<br>
|
|
91
|
-
* 64 character max.<br>
|
|
92
|
-
* When E-Mail is changed, E-Mail verified state will be changed to false.<br>
|
|
93
|
-
* E-Mail is only visible to others when set to public.<br>
|
|
94
|
-
* E-Mail should be verified to set to public.
|
|
95
|
-
* */
|
|
96
|
-
email?: string;
|
|
97
|
-
/** Shows true when user has verified their E-Mail. */
|
|
98
|
-
email_verified?: boolean;
|
|
99
|
-
/**
|
|
100
|
-
* User's phone number. Format: "+0012341234"<br>
|
|
101
|
-
* When phone number is changed, phone number verified state will be changed to false.<br>
|
|
102
|
-
* Phone number is only visible to others when set to public.<br>
|
|
103
|
-
* Phone number should be verified to set to public.
|
|
104
|
-
*/
|
|
105
|
-
phone_number?: string;
|
|
106
|
-
/** Shows true when user has verified their phone number. */
|
|
107
|
-
phone_number_verified?: boolean;
|
|
108
|
-
|
|
109
|
-
/** User's name */
|
|
110
|
-
name?: string;
|
|
111
|
-
/** User's address */
|
|
112
|
-
address?: string;
|
|
113
|
-
/**
|
|
114
|
-
* User's gender. Can be "female" and "male".<br>
|
|
115
|
-
* Other values may be used when neither of the defined values are applicable.
|
|
116
|
-
*/
|
|
117
|
-
gender?: string;
|
|
118
|
-
/** User's birthdate. String format: "1969-07-16" */
|
|
119
|
-
birthdate?: string;
|
|
120
|
-
/** User has subscribed to service e-mail when positive number. E-mail should be verified. */
|
|
121
|
-
email_subscription?: number;
|
|
122
|
-
/** User's E-mail is public when positive number. E-Mail should be verified. */
|
|
123
|
-
email_public?: boolean;
|
|
124
|
-
/** User's phone number is public when positive number. Phone number should be verified. */
|
|
125
|
-
phone_number_public?: boolean;
|
|
126
|
-
/** User's address is public when positive number. */
|
|
127
|
-
address_public?: boolean;
|
|
128
|
-
/** User's gender is public when positive number. */
|
|
129
|
-
gender_public?: boolean;
|
|
130
|
-
/** User's birthdate is public when positive number. */
|
|
131
|
-
birthdate_public?: boolean;
|
|
132
|
-
/** Shows 'PASS' if the user's account signup was successful. */
|
|
133
|
-
signup_ticket?: string;
|
|
134
|
-
};
|
|
135
|
-
|
|
136
|
-
export interface User extends UserProfile {
|
|
137
|
-
/** Last login time */
|
|
138
|
-
log: number;
|
|
139
|
-
/** User data that has been set to private. The data is only shown to the owner of the account. */
|
|
140
|
-
private_data?: Record<string, any>;
|
|
141
|
-
/** Number of the user's subscribers. */
|
|
142
|
-
subscribers: number;
|
|
143
|
-
/** Timestamp of user signup time. */
|
|
144
|
-
timestamp: number;
|
|
145
|
-
/** User's data. */
|
|
146
|
-
user_data?: Record<string, any>;
|
|
147
|
-
/** Reference of how others would see the data. Appears only on the owner of the account. */
|
|
148
|
-
_what_public_see?: Record<string, any>;
|
|
149
|
-
/** @ignore */
|
|
150
|
-
services?: Record<string, any>[];
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
export type GetRecordParams = {
|
|
154
|
-
/** @ignore */
|
|
155
|
-
service?: string;
|
|
156
|
-
/** Table name */
|
|
157
|
-
table: string;
|
|
158
|
-
/**
|
|
159
|
-
* Query for records that are accessable in certain user groups.
|
|
160
|
-
* User cannot request access that are higher than the accounts user group.
|
|
161
|
-
* Queries private records if 'private' is given.
|
|
162
|
-
* User can only query their own private records or can have access to other private record if access is given.
|
|
163
|
-
*/
|
|
164
|
-
access_group?: number | 'private';
|
|
165
|
-
subscription?: {
|
|
166
|
-
/**
|
|
167
|
-
* You can fetch records in certain users subscription records.<br>
|
|
168
|
-
* User will not be able to access the subscription record if the user is not subscribed to the user.
|
|
169
|
-
*/
|
|
170
|
-
user_id: string;
|
|
171
|
-
/**
|
|
172
|
-
* Target subscription group number.<br>
|
|
173
|
-
* User will not be able to access subscription group if the user is not subscribed to the group.<br>
|
|
174
|
-
*/
|
|
175
|
-
group: number;
|
|
176
|
-
},
|
|
177
|
-
index: {
|
|
178
|
-
/**
|
|
179
|
-
* Index name. Queries list of nested index key if index name ends with period.<br>
|
|
180
|
-
* As example below, you can query all movies under the index name director.spielberg...<br>
|
|
181
|
-
* ex) director.spielberg.<br>
|
|
182
|
-
* Reserved index names are: '$record_id' | '$updated' | '$uploaded' | '$referenced_count'
|
|
183
|
-
* */
|
|
184
|
-
name: string | '$record_id' | '$updated' | '$uploaded' | '$referenced_count';
|
|
185
|
-
/**
|
|
186
|
-
* Index value to search based on the index name.<br>
|
|
187
|
-
* If the index name is a index key name search value type must be string.<br>
|
|
188
|
-
* For reserved index names '$record_id' is an record id string, otherwise is type number.
|
|
189
|
-
*/
|
|
190
|
-
value: string | number | boolean;
|
|
191
|
-
/** Search condition. Defaults to '='.*/
|
|
192
|
-
condition?: '>' | '>=' | '=' | '<' | '<=' | '!=' | 'gt' | 'gte' | 'eq' | 'lt' | 'lte' | 'ne';
|
|
193
|
-
/**
|
|
194
|
-
* Range of search. <br>
|
|
195
|
-
* Range does not work with conditions.
|
|
196
|
-
*/
|
|
197
|
-
range?: string | number | boolean;
|
|
198
|
-
};
|
|
199
|
-
/**
|
|
200
|
-
* Tags can be queried up to 10 tags at once.
|
|
201
|
-
*/
|
|
202
|
-
tags?: string | string[];
|
|
203
|
-
/**
|
|
204
|
-
* Queries records that are referencing other record ids.<br>
|
|
205
|
-
* If user id is given, you can get all records uploaded by certain user.
|
|
206
|
-
*/
|
|
207
|
-
reference?: string;
|
|
208
|
-
};
|
|
209
|
-
|
|
210
|
-
export type PostRecordParams = {
|
|
211
|
-
/** Record id to be updated. If omited, New record is uploaded. */
|
|
212
|
-
record_id?: string;
|
|
213
|
-
/** Table name */
|
|
214
|
-
table: string;
|
|
215
|
-
/**
|
|
216
|
-
* Access group.<br>
|
|
217
|
-
* When number is given, user of corresponding service group has access to the record.<br>
|
|
218
|
-
* User cannot set access_group number higher then the accounts service group.<br>
|
|
219
|
-
* When 'private' is given, record is private.
|
|
220
|
-
*/
|
|
221
|
-
access_group: number | 'private';
|
|
222
|
-
/**
|
|
223
|
-
* Subscription group to allow access.<br>
|
|
224
|
-
* When value is given, the record is only accessable to user who is subscribed the corresponding group.
|
|
225
|
-
*/
|
|
226
|
-
subscription_group: number;
|
|
227
|
-
/**
|
|
228
|
-
* Record id to reference.<br>
|
|
229
|
-
* If the reference record is private or subscription record, user must have access.<br>
|
|
230
|
-
* When the subscription or private record is referenced,
|
|
231
|
-
* the record does not get uploaded to the source subscription table since subscription record is only uploaded to the uploaders subscription table.<br>
|
|
232
|
-
* In other words, if you upload a record with reference, with given subscription group number,
|
|
233
|
-
* users wont be able to query all referenced record from the source since some of the referenced records will be in each individual subscription table.<br>
|
|
234
|
-
* If record is referencing a private record and uploaded as private,
|
|
235
|
-
* Any user who has access to the referenced record will also have access to all private referencing records.
|
|
236
|
-
*/
|
|
237
|
-
reference?: string;
|
|
238
|
-
index: {
|
|
239
|
-
/** Index name. When ending with period, searches for nested key names ex) director. */
|
|
240
|
-
name: string;
|
|
241
|
-
/** Index value */
|
|
242
|
-
value: string | number | boolean;
|
|
243
|
-
};
|
|
244
|
-
/** Tags */
|
|
245
|
-
tags?: string | string[];
|
|
246
|
-
config?: {
|
|
247
|
-
/** Limits possible number of references. If 0 is given, record cannot be referenced. */
|
|
248
|
-
reference_limit?: number;
|
|
249
|
-
/** When true, allows users to upload multiple record that references the current record. */
|
|
250
|
-
allow_multiple_reference?: boolean;
|
|
251
|
-
/** List of user id to allow private access. */
|
|
252
|
-
private_access?: string | string[];
|
|
253
|
-
};
|
|
254
|
-
};
|
|
255
|
-
|
|
256
|
-
export type RecordData = {
|
|
257
|
-
/** Record id */
|
|
258
|
-
record_id: string;
|
|
259
|
-
/** Table name of the record */
|
|
260
|
-
table: string;
|
|
261
|
-
/** Record access group */
|
|
262
|
-
access_group: number | 'private';
|
|
263
|
-
subscription: {
|
|
264
|
-
/** Subscription id */
|
|
265
|
-
user_id: string;
|
|
266
|
-
/** Subscription group */
|
|
267
|
-
group: number;
|
|
268
|
-
};
|
|
269
|
-
/** Uploaded timestamp */
|
|
270
|
-
uploaded: number;
|
|
271
|
-
/** User id of the record owner */
|
|
272
|
-
user_id: string;
|
|
273
|
-
/** Updated timestamp */
|
|
274
|
-
updated: number;
|
|
275
|
-
/** Number of record referencing this record. */
|
|
276
|
-
referenced_count: number;
|
|
277
|
-
config: {
|
|
278
|
-
/** Allows multiple reference if true. */
|
|
279
|
-
allow_multi_reference: boolean;
|
|
280
|
-
/** Allows referencing if true. */
|
|
281
|
-
reference_limit: number;
|
|
282
|
-
};
|
|
283
|
-
/** Record id that the record is referencing. */
|
|
284
|
-
reference?: string;
|
|
285
|
-
/** Data of the record */
|
|
286
|
-
data?: any;
|
|
287
|
-
index?: {
|
|
288
|
-
/** Name of the index */
|
|
289
|
-
name: string;
|
|
290
|
-
/** Value of the index */
|
|
291
|
-
value: string | number | boolean;
|
|
292
|
-
};
|
|
293
|
-
/** List of tags of the record. */
|
|
294
|
-
tags?: string[];
|
|
295
|
-
};
|
|
296
|
-
|
|
297
|
-
export type QueryParams = {
|
|
298
|
-
/** Index name to search. */
|
|
299
|
-
searchFor: string;
|
|
300
|
-
/** Index value to search. */
|
|
301
|
-
value: string | number | boolean;
|
|
302
|
-
/** Search condition. */
|
|
303
|
-
condition?: '>' | '>=' | '=' | '<' | '<=' | '!=' | 'gt' | 'gte' | 'eq' | 'lt' | 'lte' | 'ne';
|
|
304
|
-
/** Range of search. */
|
|
305
|
-
range?: string | number | boolean;
|
|
306
|
-
};
|
|
307
|
-
|
|
308
|
-
export type FetchOptions = {
|
|
309
|
-
/** Number of records to fetch per call */
|
|
310
|
-
limit?: number;
|
|
311
|
-
/** Refresh the startKey. Only works on paginated queries. */
|
|
312
|
-
refresh?: boolean;
|
|
313
|
-
/** Result in ascending order if true, decending when false. */
|
|
314
|
-
ascending?: boolean;
|
|
315
|
-
/** StartKey key object can be used to query from the certain page of fetch. If refresh is true, will overwrite startKey to start. Only works on paginated queries.*/
|
|
316
|
-
startKey?: Record<string, any>;
|
|
317
|
-
};
|
|
318
|
-
|
|
319
|
-
export type FetchResponse = {
|
|
320
|
-
list: any[];
|
|
321
|
-
startKey: Record<string, any> | 'end';
|
|
322
|
-
endOfList: boolean;
|
|
323
|
-
};
|
|
324
|
-
|
|
325
|
-
export type Service = {
|
|
326
|
-
/** Shows active state. 1 = active, 0 = disabled */
|
|
327
|
-
active: number;
|
|
328
|
-
/** Custom api key to use for service owners custom api. */
|
|
329
|
-
api_key: string;
|
|
330
|
-
/** Service cors for connection. */
|
|
331
|
-
cors: string[];
|
|
332
|
-
/** Service owners E-Mail. */
|
|
333
|
-
email: string;
|
|
334
|
-
/** Number of users subscribed to service E-Mail. */
|
|
335
|
-
email_subscribers: number;
|
|
336
|
-
/** Service group. 1 = free try out. 1 > paid users. */
|
|
337
|
-
group: number;
|
|
338
|
-
/** Service region */
|
|
339
|
-
region: string;
|
|
340
|
-
/** Service name. */
|
|
341
|
-
name: string;
|
|
342
|
-
/** Number of newsletter subscribers. */
|
|
343
|
-
newsletter_subscribers: number;
|
|
344
|
-
/** Service id. */
|
|
345
|
-
service: string;
|
|
346
|
-
/** E-Mail template for signup confirmation. This can be changed by trigger E-Mail. */
|
|
347
|
-
template_activation: {
|
|
348
|
-
html: string;
|
|
349
|
-
subject: string;
|
|
350
|
-
};
|
|
351
|
-
/** E-Mail template for verification code E-Mail. This can be changed by trigger E-Mail. */
|
|
352
|
-
template_verification: {
|
|
353
|
-
html: string;
|
|
354
|
-
sms: string;
|
|
355
|
-
subject: string;
|
|
356
|
-
};
|
|
357
|
-
/** E-Mail template for welcome E-Mail that user receives after signup process. This can be changed by trigger E-Mail. */
|
|
358
|
-
template_welcome: {
|
|
359
|
-
html: string;
|
|
360
|
-
subject: string;
|
|
361
|
-
};
|
|
362
|
-
/** 13 digit timestamp */
|
|
363
|
-
timestamp: number;
|
|
364
|
-
/** Service owner can send email to the triggers to send newsletters, or change automated E-Mail templates. */
|
|
365
|
-
triggers: {
|
|
366
|
-
/** Sends service E-Mail to E-Mail subscribed service users. */
|
|
367
|
-
newsletter_signed: string;
|
|
368
|
-
/** Sends newsletters. */
|
|
369
|
-
newsletter_subscribers: string;
|
|
370
|
-
/** Sets template of signup confirmation and account enable E-Mail. */
|
|
371
|
-
template_activation: string;
|
|
372
|
-
/** Sets template of verification E-Mail. */
|
|
373
|
-
template_verification: string;
|
|
374
|
-
/** Sets template of welcome E-Mail. */
|
|
375
|
-
template_welcome: string;
|
|
376
|
-
};
|
|
377
|
-
/** Number of user in the service. */
|
|
378
|
-
users: number;
|
|
379
|
-
};
|
|
380
|
-
|
|
381
|
-
export type SubscriptionGroup = {
|
|
382
|
-
/** User id. */
|
|
383
|
-
user_id: string;
|
|
384
|
-
/** Target group number (1 ~ 9). '*' is given, will apply to all groups. */
|
|
385
|
-
group: number | '*';
|
|
386
|
-
};
|
package/src/decorators.ts
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import { Form, FormCallbacks } from './Types';
|
|
2
|
-
import SkapiError from './skapi_error';
|
|
3
|
-
import { MD5 } from './utils';
|
|
4
|
-
|
|
5
|
-
function formResponse() {
|
|
6
|
-
// wraps methods that requires form handling
|
|
7
|
-
return function (target: object, propertyKey: string, descriptor: PropertyDescriptor) {
|
|
8
|
-
const fn = descriptor.value;
|
|
9
|
-
|
|
10
|
-
descriptor.value = function (...arg: any[]) {
|
|
11
|
-
let form: Form | Record<string, any> = arg[0];
|
|
12
|
-
let option: FormCallbacks = arg?.[1] || {};
|
|
13
|
-
|
|
14
|
-
const handleResponse = (response: any) => {
|
|
15
|
-
if (option?.response) {
|
|
16
|
-
if (typeof option.response === 'function') {
|
|
17
|
-
// return response callback
|
|
18
|
-
option.response(response);
|
|
19
|
-
return response;
|
|
20
|
-
} else {
|
|
21
|
-
throw new SkapiError('Callback "response" should be type: function.', { code: 'INVALID_PARAMETER' });
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
if (!(form instanceof HTMLFormElement)) {
|
|
26
|
-
// return if is not form element
|
|
27
|
-
return response;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// form element action
|
|
31
|
-
let href = new URL(form.action);
|
|
32
|
-
let response_key = MD5.hash(form.action);
|
|
33
|
-
// let response_key = form.action;
|
|
34
|
-
let timestamp = Date.now().toString();
|
|
35
|
-
|
|
36
|
-
window.sessionStorage.setItem(response_key, JSON.stringify({ [timestamp]: response }));
|
|
37
|
-
href.searchParams.set(response_key, timestamp);
|
|
38
|
-
window.location.href = href.href;
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
let response: any;
|
|
42
|
-
function handleError(err: any) {
|
|
43
|
-
let is_err = err instanceof Error ? err : new SkapiError(err);
|
|
44
|
-
if (option?.onerror) {
|
|
45
|
-
if (typeof option.onerror === 'function') {
|
|
46
|
-
// onerror callback
|
|
47
|
-
return option.onerror(is_err);
|
|
48
|
-
} else {
|
|
49
|
-
throw new SkapiError('Callback "onerror" should be type: function.', { code: 'INVALID_PARAMETER' });
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return is_err;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
try {
|
|
57
|
-
// execute
|
|
58
|
-
response = fn.bind(this)(...arg);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
catch (err) {
|
|
62
|
-
let is_err = handleError(err);
|
|
63
|
-
if (is_err instanceof Error) {
|
|
64
|
-
throw is_err;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
return is_err;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
if (response instanceof Promise) {
|
|
71
|
-
// handle promise
|
|
72
|
-
return new Promise((res, rej) => {
|
|
73
|
-
response
|
|
74
|
-
.then((r: any) => {
|
|
75
|
-
res(handleResponse(r));
|
|
76
|
-
})
|
|
77
|
-
.catch((err: any) => {
|
|
78
|
-
err = handleError(err);
|
|
79
|
-
if (err instanceof Error) {
|
|
80
|
-
rej(err);
|
|
81
|
-
} else {
|
|
82
|
-
res(err);
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
else {
|
|
89
|
-
return handleResponse(response);
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
export { formResponse };
|