skapi-js 1.2.14-beta.3 → 1.2.14-beta.6
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/bundle-report-commonjs.html +2 -2
- package/dist/bundle-report-esm.html +2 -2
- package/dist/bundle-report-node-esm.html +2 -2
- package/dist/bundle-report.html +2 -2
- package/dist/skapi.cjs +1 -1
- package/dist/skapi.cjs.map +1 -1
- 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/dist/skapi.node.mjs +1 -1
- package/dist/skapi.node.mjs.map +1 -1
- package/js/package.json +6 -5
- package/js/src/Types.d.ts +40 -2
- package/js/src/main/skapi.d.ts +41 -29
- package/js/src/main/skapi.js +48 -60
- package/js/src/main/skapi.js.map +1 -1
- package/js/src/methods/admin.d.ts +2 -4
- package/js/src/methods/database.d.ts +8 -0
- package/js/src/methods/database.js +285 -8
- package/js/src/methods/database.js.map +1 -1
- package/js/src/methods/param_restrictions.d.ts +8 -4
- package/js/src/methods/param_restrictions.js +72 -6
- package/js/src/methods/param_restrictions.js.map +1 -1
- package/js/src/methods/request.js +1 -1
- package/js/src/methods/request.js.map +1 -1
- package/js/src/methods/subscription.d.ts +0 -6
- package/js/src/methods/subscription.js +0 -28
- package/js/src/methods/subscription.js.map +1 -1
- package/js/src/methods/vivian.d.ts +18 -3
- package/js/src/methods/vivian.js +20 -10
- package/js/src/methods/vivian.js.map +1 -1
- package/js/src/utils/network.js +16 -11
- package/js/src/utils/network.js.map +1 -1
- package/js/src/utils/utils.d.ts +3 -1
- package/js/src/utils/utils.js +15 -3
- package/js/src/utils/utils.js.map +1 -1
- package/package.json +6 -5
- package/js/Main.d.ts +0 -6
- package/js/Main.js +0 -6
- package/js/Main.js.map +0 -1
- package/js/Types.d.ts +0 -305
- package/js/Types.js +0 -2
- package/js/Types.js.map +0 -1
- package/js/main/error.d.ts +0 -9
- package/js/main/error.js +0 -46
- package/js/main/error.js.map +0 -1
- package/js/main/skapi.d.ts +0 -443
- package/js/main/skapi.js +0 -853
- package/js/main/skapi.js.map +0 -1
- package/js/methods/admin.d.ts +0 -61
- package/js/methods/admin.js +0 -325
- package/js/methods/admin.js.map +0 -1
- package/js/methods/database.d.ts +0 -65
- package/js/methods/database.js +0 -947
- package/js/methods/database.js.map +0 -1
- package/js/methods/notification.d.ts +0 -21
- package/js/methods/notification.js +0 -81
- package/js/methods/notification.js.map +0 -1
- package/js/methods/param_restrictions.d.ts +0 -21
- package/js/methods/param_restrictions.js +0 -144
- package/js/methods/param_restrictions.js.map +0 -1
- package/js/methods/realtime.d.ts +0 -35
- package/js/methods/realtime.js +0 -408
- package/js/methods/realtime.js.map +0 -1
- package/js/methods/request.d.ts +0 -43
- package/js/methods/request.js +0 -132
- package/js/methods/request.js.map +0 -1
- package/js/methods/subscription.d.ts +0 -53
- package/js/methods/subscription.js +0 -337
- package/js/methods/subscription.js.map +0 -1
- package/js/methods/user.d.ts +0 -176
- package/js/methods/user.js +0 -1120
- package/js/methods/user.js.map +0 -1
- package/js/methods/vivian.d.ts +0 -3
- package/js/methods/vivian.js +0 -36
- package/js/methods/vivian.js.map +0 -1
- package/js/methods/webrtc.d.ts +0 -26
- package/js/methods/webrtc.js +0 -608
- package/js/methods/webrtc.js.map +0 -1
- package/js/polyfills/global.d.ts +0 -3
- package/js/polyfills/global.js +0 -235
- package/js/polyfills/global.js.map +0 -1
- package/js/utils/network.d.ts +0 -24
- package/js/utils/network.js +0 -707
- package/js/utils/network.js.map +0 -1
- package/js/utils/utils.d.ts +0 -40
- package/js/utils/utils.js +0 -651
- package/js/utils/utils.js.map +0 -1
- package/js/utils/validator.d.ts +0 -24
- package/js/utils/validator.js +0 -293
- package/js/utils/validator.js.map +0 -1
package/js/utils/utils.js
DELETED
|
@@ -1,651 +0,0 @@
|
|
|
1
|
-
import SkapiError from "../main/error";
|
|
2
|
-
const BASE62_ALPHABET = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
|
|
3
|
-
const BASE62 = BigInt(BASE62_ALPHABET.length);
|
|
4
|
-
class MD5 {
|
|
5
|
-
static hash(str) {
|
|
6
|
-
if (typeof str !== 'string') {
|
|
7
|
-
console.warn('coercing non-string value to empty string');
|
|
8
|
-
str = '';
|
|
9
|
-
}
|
|
10
|
-
const x = MD5.sb(str);
|
|
11
|
-
let a = 1732584193;
|
|
12
|
-
let b = -271733879;
|
|
13
|
-
let c = -1732584194;
|
|
14
|
-
let d = 271733878;
|
|
15
|
-
let lastA;
|
|
16
|
-
let lastB;
|
|
17
|
-
let lastC;
|
|
18
|
-
let lastD;
|
|
19
|
-
for (let i = 0; i < x.length; i += 16) {
|
|
20
|
-
lastA = a;
|
|
21
|
-
lastB = b;
|
|
22
|
-
lastC = c;
|
|
23
|
-
lastD = d;
|
|
24
|
-
a = MD5.ff(a, b, c, d, x[i], 7, -680876936);
|
|
25
|
-
d = MD5.ff(d, a, b, c, x[i + 1], 12, -389564586);
|
|
26
|
-
c = MD5.ff(c, d, a, b, x[i + 2], 17, 606105819);
|
|
27
|
-
b = MD5.ff(b, c, d, a, x[i + 3], 22, -1044525330);
|
|
28
|
-
a = MD5.ff(a, b, c, d, x[i + 4], 7, -176418897);
|
|
29
|
-
d = MD5.ff(d, a, b, c, x[i + 5], 12, 1200080426);
|
|
30
|
-
c = MD5.ff(c, d, a, b, x[i + 6], 17, -1473231341);
|
|
31
|
-
b = MD5.ff(b, c, d, a, x[i + 7], 22, -45705983);
|
|
32
|
-
a = MD5.ff(a, b, c, d, x[i + 8], 7, 1770035416);
|
|
33
|
-
d = MD5.ff(d, a, b, c, x[i + 9], 12, -1958414417);
|
|
34
|
-
c = MD5.ff(c, d, a, b, x[i + 10], 17, -42063);
|
|
35
|
-
b = MD5.ff(b, c, d, a, x[i + 11], 22, -1990404162);
|
|
36
|
-
a = MD5.ff(a, b, c, d, x[i + 12], 7, 1804603682);
|
|
37
|
-
d = MD5.ff(d, a, b, c, x[i + 13], 12, -40341101);
|
|
38
|
-
c = MD5.ff(c, d, a, b, x[i + 14], 17, -1502002290);
|
|
39
|
-
b = MD5.ff(b, c, d, a, x[i + 15], 22, 1236535329);
|
|
40
|
-
a = MD5.gg(a, b, c, d, x[i + 1], 5, -165796510);
|
|
41
|
-
d = MD5.gg(d, a, b, c, x[i + 6], 9, -1069501632);
|
|
42
|
-
c = MD5.gg(c, d, a, b, x[i + 11], 14, 643717713);
|
|
43
|
-
b = MD5.gg(b, c, d, a, x[i], 20, -373897302);
|
|
44
|
-
a = MD5.gg(a, b, c, d, x[i + 5], 5, -701558691);
|
|
45
|
-
d = MD5.gg(d, a, b, c, x[i + 10], 9, 38016083);
|
|
46
|
-
c = MD5.gg(c, d, a, b, x[i + 15], 14, -660478335);
|
|
47
|
-
b = MD5.gg(b, c, d, a, x[i + 4], 20, -405537848);
|
|
48
|
-
a = MD5.gg(a, b, c, d, x[i + 9], 5, 568446438);
|
|
49
|
-
d = MD5.gg(d, a, b, c, x[i + 14], 9, -1019803690);
|
|
50
|
-
c = MD5.gg(c, d, a, b, x[i + 3], 14, -187363961);
|
|
51
|
-
b = MD5.gg(b, c, d, a, x[i + 8], 20, 1163531501);
|
|
52
|
-
a = MD5.gg(a, b, c, d, x[i + 13], 5, -1444681467);
|
|
53
|
-
d = MD5.gg(d, a, b, c, x[i + 2], 9, -51403784);
|
|
54
|
-
c = MD5.gg(c, d, a, b, x[i + 7], 14, 1735328473);
|
|
55
|
-
b = MD5.gg(b, c, d, a, x[i + 12], 20, -1926607734);
|
|
56
|
-
a = MD5.hh(a, b, c, d, x[i + 5], 4, -378558);
|
|
57
|
-
d = MD5.hh(d, a, b, c, x[i + 8], 11, -2022574463);
|
|
58
|
-
c = MD5.hh(c, d, a, b, x[i + 11], 16, 1839030562);
|
|
59
|
-
b = MD5.hh(b, c, d, a, x[i + 14], 23, -35309556);
|
|
60
|
-
a = MD5.hh(a, b, c, d, x[i + 1], 4, -1530992060);
|
|
61
|
-
d = MD5.hh(d, a, b, c, x[i + 4], 11, 1272893353);
|
|
62
|
-
c = MD5.hh(c, d, a, b, x[i + 7], 16, -155497632);
|
|
63
|
-
b = MD5.hh(b, c, d, a, x[i + 10], 23, -1094730640);
|
|
64
|
-
a = MD5.hh(a, b, c, d, x[i + 13], 4, 681279174);
|
|
65
|
-
d = MD5.hh(d, a, b, c, x[i], 11, -358537222);
|
|
66
|
-
c = MD5.hh(c, d, a, b, x[i + 3], 16, -722521979);
|
|
67
|
-
b = MD5.hh(b, c, d, a, x[i + 6], 23, 76029189);
|
|
68
|
-
a = MD5.hh(a, b, c, d, x[i + 9], 4, -640364487);
|
|
69
|
-
d = MD5.hh(d, a, b, c, x[i + 12], 11, -421815835);
|
|
70
|
-
c = MD5.hh(c, d, a, b, x[i + 15], 16, 530742520);
|
|
71
|
-
b = MD5.hh(b, c, d, a, x[i + 2], 23, -995338651);
|
|
72
|
-
a = MD5.ii(a, b, c, d, x[i], 6, -198630844);
|
|
73
|
-
d = MD5.ii(d, a, b, c, x[i + 7], 10, 1126891415);
|
|
74
|
-
c = MD5.ii(c, d, a, b, x[i + 14], 15, -1416354905);
|
|
75
|
-
b = MD5.ii(b, c, d, a, x[i + 5], 21, -57434055);
|
|
76
|
-
a = MD5.ii(a, b, c, d, x[i + 12], 6, 1700485571);
|
|
77
|
-
d = MD5.ii(d, a, b, c, x[i + 3], 10, -1894986606);
|
|
78
|
-
c = MD5.ii(c, d, a, b, x[i + 10], 15, -1051523);
|
|
79
|
-
b = MD5.ii(b, c, d, a, x[i + 1], 21, -2054922799);
|
|
80
|
-
a = MD5.ii(a, b, c, d, x[i + 8], 6, 1873313359);
|
|
81
|
-
d = MD5.ii(d, a, b, c, x[i + 15], 10, -30611744);
|
|
82
|
-
c = MD5.ii(c, d, a, b, x[i + 6], 15, -1560198380);
|
|
83
|
-
b = MD5.ii(b, c, d, a, x[i + 13], 21, 1309151649);
|
|
84
|
-
a = MD5.ii(a, b, c, d, x[i + 4], 6, -145523070);
|
|
85
|
-
d = MD5.ii(d, a, b, c, x[i + 11], 10, -1120210379);
|
|
86
|
-
c = MD5.ii(c, d, a, b, x[i + 2], 15, 718787259);
|
|
87
|
-
b = MD5.ii(b, c, d, a, x[i + 9], 21, -343485551);
|
|
88
|
-
a = MD5.ad(a, lastA);
|
|
89
|
-
b = MD5.ad(b, lastB);
|
|
90
|
-
c = MD5.ad(c, lastC);
|
|
91
|
-
d = MD5.ad(d, lastD);
|
|
92
|
-
}
|
|
93
|
-
return MD5.rh(a) + MD5.rh(b) + MD5.rh(c) + MD5.rh(d);
|
|
94
|
-
}
|
|
95
|
-
static rh(n) {
|
|
96
|
-
let s = '';
|
|
97
|
-
for (let j = 0; j <= 3; j++) {
|
|
98
|
-
s += MD5.alphabet.charAt((n >> (j * 8 + 4)) & 0x0F) + MD5.alphabet.charAt((n >> (j * 8)) & 0x0F);
|
|
99
|
-
}
|
|
100
|
-
return s;
|
|
101
|
-
}
|
|
102
|
-
static ad(x, y) {
|
|
103
|
-
const l = (x & 0xFFFF) + (y & 0xFFFF);
|
|
104
|
-
const m = (x >> 16) + (y >> 16) + (l >> 16);
|
|
105
|
-
return (m << 16) | (l & 0xFFFF);
|
|
106
|
-
}
|
|
107
|
-
static rl(n, c) {
|
|
108
|
-
return (n << c) | (n >>> (32 - c));
|
|
109
|
-
}
|
|
110
|
-
static cm(q, a, b, x, s, t) {
|
|
111
|
-
return MD5.ad(MD5.rl(MD5.ad(MD5.ad(a, q), MD5.ad(x, t)), s), b);
|
|
112
|
-
}
|
|
113
|
-
static ff(a, b, c, d, x, s, t) {
|
|
114
|
-
return MD5.cm(b & c | ~b & d, a, b, x, s, t);
|
|
115
|
-
}
|
|
116
|
-
static gg(a, b, c, d, x, s, t) {
|
|
117
|
-
return MD5.cm(b & d | c & ~d, a, b, x, s, t);
|
|
118
|
-
}
|
|
119
|
-
static hh(a, b, c, d, x, s, t) {
|
|
120
|
-
return MD5.cm(b ^ c ^ d, a, b, x, s, t);
|
|
121
|
-
}
|
|
122
|
-
static ii(a, b, c, d, x, s, t) {
|
|
123
|
-
return MD5.cm(c ^ (b | ~d), a, b, x, s, t);
|
|
124
|
-
}
|
|
125
|
-
static sb(x) {
|
|
126
|
-
let i;
|
|
127
|
-
const numBlocks = ((x.length + 8) >> 6) + 1;
|
|
128
|
-
const blocks = new Array(numBlocks * 16);
|
|
129
|
-
for (i = 0; i < numBlocks * 16; i++) {
|
|
130
|
-
blocks[i] = 0;
|
|
131
|
-
}
|
|
132
|
-
for (i = 0; i < x.length; i++) {
|
|
133
|
-
blocks[i >> 2] |= x.charCodeAt(i) << ((i % 4) * 8);
|
|
134
|
-
}
|
|
135
|
-
blocks[i >> 2] |= 0x80 << ((i % 4) * 8);
|
|
136
|
-
blocks[numBlocks * 16 - 2] = x.length * 8;
|
|
137
|
-
return blocks;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
MD5.alphabet = '0123456789abcdef';
|
|
141
|
-
function toBase62(num) {
|
|
142
|
-
if (num === 0)
|
|
143
|
-
return BASE62_ALPHABET[0];
|
|
144
|
-
let result = '';
|
|
145
|
-
while (num > 0) {
|
|
146
|
-
result = BASE62_ALPHABET[num % 62] + result;
|
|
147
|
-
num = Math.floor(num / 62);
|
|
148
|
-
}
|
|
149
|
-
return result;
|
|
150
|
-
}
|
|
151
|
-
function fromBase62(chars) {
|
|
152
|
-
return chars.split('').reverse().reduce((prev, curr, i) => prev + (BASE62_ALPHABET.indexOf(curr) * (62 ** i)), 0);
|
|
153
|
-
}
|
|
154
|
-
function generateRandom(length = 6) {
|
|
155
|
-
let result = '';
|
|
156
|
-
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
157
|
-
const charactersLength = characters.length;
|
|
158
|
-
let counter = 0;
|
|
159
|
-
while (counter < length) {
|
|
160
|
-
result += characters.charAt(Math.floor(Math.random() * charactersLength));
|
|
161
|
-
counter += 1;
|
|
162
|
-
}
|
|
163
|
-
return result;
|
|
164
|
-
}
|
|
165
|
-
const isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined';
|
|
166
|
-
const hasSubmitEvent = typeof SubmitEvent !== 'undefined';
|
|
167
|
-
const hasHTMLFormElement = typeof HTMLFormElement !== 'undefined';
|
|
168
|
-
function extractFormData(form, options, callback) {
|
|
169
|
-
let data = {};
|
|
170
|
-
let files = [];
|
|
171
|
-
function sizeof(object) {
|
|
172
|
-
let str;
|
|
173
|
-
try {
|
|
174
|
-
str = JSON.stringify(object);
|
|
175
|
-
}
|
|
176
|
-
catch (e) {
|
|
177
|
-
throw new SkapiError('Invalid data type.', { code: 'INVALID_REQUEST' });
|
|
178
|
-
}
|
|
179
|
-
return new Blob([str]).size;
|
|
180
|
-
}
|
|
181
|
-
function appendData(data, key, val) {
|
|
182
|
-
if (options?.ignoreEmpty && val === '') {
|
|
183
|
-
return;
|
|
184
|
-
}
|
|
185
|
-
if (options?.nullIfEmpty && val === '') {
|
|
186
|
-
val = null;
|
|
187
|
-
}
|
|
188
|
-
if (typeof callback === 'function') {
|
|
189
|
-
let v = callback(key, val);
|
|
190
|
-
if (v !== undefined) {
|
|
191
|
-
val = v;
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
let keys = key.split('[').map(k => {
|
|
195
|
-
let key = k.replace(']', '');
|
|
196
|
-
let numb = Number(key);
|
|
197
|
-
if (!isNaN(numb) && !key.includes('.')) {
|
|
198
|
-
key = numb;
|
|
199
|
-
}
|
|
200
|
-
else if (key[0] === '"' && key[key.length - 1] === '"' || key[0] === "'" && key[key.length - 1] === "'") {
|
|
201
|
-
key = key.replace(/"/g, '').replace(/'/g, '');
|
|
202
|
-
}
|
|
203
|
-
return key;
|
|
204
|
-
});
|
|
205
|
-
let obj = data;
|
|
206
|
-
if (typeof keys[0] === 'number') {
|
|
207
|
-
throw new SkapiError('Form key cannot start with an array index.', { code: 'INVALID_REQUEST' });
|
|
208
|
-
}
|
|
209
|
-
for (let i = 0; i < keys.length; i++) {
|
|
210
|
-
let k = keys[i];
|
|
211
|
-
if (i < keys.length - 1) {
|
|
212
|
-
if (obj[k] === undefined) {
|
|
213
|
-
let next = keys[i + 1];
|
|
214
|
-
if (typeof next === 'number') {
|
|
215
|
-
obj[k] = [];
|
|
216
|
-
}
|
|
217
|
-
else {
|
|
218
|
-
obj[k] = {};
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
obj = obj[k];
|
|
222
|
-
}
|
|
223
|
-
else {
|
|
224
|
-
if (obj[k] === undefined) {
|
|
225
|
-
obj[k] = val;
|
|
226
|
-
}
|
|
227
|
-
else if (Array.isArray(obj[k])) {
|
|
228
|
-
obj[k].push(val);
|
|
229
|
-
}
|
|
230
|
-
else {
|
|
231
|
-
obj[k] = [obj[k], val];
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
function handleFile(files, name, v) {
|
|
237
|
-
if (v instanceof File) {
|
|
238
|
-
files.push({ name, file: v });
|
|
239
|
-
}
|
|
240
|
-
else if (v instanceof FileList) {
|
|
241
|
-
if (v && v.length > 0) {
|
|
242
|
-
for (let idx = 0; idx <= v.length - 1; idx++) {
|
|
243
|
-
let file = v.item(idx);
|
|
244
|
-
if (file) {
|
|
245
|
-
files.push({ name, file });
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
let handleInput = (i) => {
|
|
252
|
-
if (i.name) {
|
|
253
|
-
if (i.type === 'number') {
|
|
254
|
-
if (i.value) {
|
|
255
|
-
appendData(data, i.name, Number(i.value));
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
else if (i.type === 'checkbox' || i.type === 'radio') {
|
|
259
|
-
if (i.checked) {
|
|
260
|
-
if (i.value === '' && i.type === 'checkbox' || i.value === 'on' || i.value === 'true') {
|
|
261
|
-
appendData(data, i.name, true);
|
|
262
|
-
}
|
|
263
|
-
else if (i.value === 'false') {
|
|
264
|
-
appendData(data, i.name, false);
|
|
265
|
-
}
|
|
266
|
-
else if (i.value) {
|
|
267
|
-
appendData(data, i.name, i.value);
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
else if (i.type === 'checkbox') {
|
|
271
|
-
if (i.value === '' || i.value === 'on' || i.value === 'true') {
|
|
272
|
-
appendData(data, i.name, false);
|
|
273
|
-
}
|
|
274
|
-
else if (i.value === 'false') {
|
|
275
|
-
appendData(data, i.name, true);
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
else if (i.type === 'file') {
|
|
280
|
-
if (i.files && i.files.length > 0) {
|
|
281
|
-
handleFile(files, i.name, i.files);
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
else {
|
|
285
|
-
appendData(data, i.name, i.value);
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
};
|
|
289
|
-
if (isBrowser && (form instanceof HTMLInputElement || form instanceof HTMLSelectElement || form instanceof HTMLTextAreaElement)) {
|
|
290
|
-
handleInput(form);
|
|
291
|
-
if (sizeof(data) > 2 * 1024 * 1024) {
|
|
292
|
-
throw new SkapiError('Data should not exceed 2MB', { code: 'INVALID_REQUEST' });
|
|
293
|
-
}
|
|
294
|
-
return { data, files };
|
|
295
|
-
}
|
|
296
|
-
else {
|
|
297
|
-
if (isBrowser && form instanceof FormData) {
|
|
298
|
-
for (let pair of form.entries()) {
|
|
299
|
-
let name = pair[0];
|
|
300
|
-
let v = pair[1];
|
|
301
|
-
if ((v instanceof File) || (v instanceof FileList)) {
|
|
302
|
-
handleFile(files, name, v);
|
|
303
|
-
}
|
|
304
|
-
else if (v instanceof Blob) {
|
|
305
|
-
let j = v;
|
|
306
|
-
if (j.type === 'application/json') {
|
|
307
|
-
try {
|
|
308
|
-
let json = JSON.parse(j.text());
|
|
309
|
-
appendData(data, name, json);
|
|
310
|
-
}
|
|
311
|
-
catch (err) {
|
|
312
|
-
appendData(data, name, j);
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
else {
|
|
317
|
-
appendData(data, name, v);
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
if (sizeof(data) > 2 * 1024 * 1024) {
|
|
321
|
-
throw new SkapiError('Data should not exceed 2MB', { code: 'INVALID_REQUEST' });
|
|
322
|
-
}
|
|
323
|
-
return { data, files };
|
|
324
|
-
}
|
|
325
|
-
if (isBrowser && hasSubmitEvent && form instanceof SubmitEvent) {
|
|
326
|
-
form = form.target;
|
|
327
|
-
}
|
|
328
|
-
if (isBrowser && hasHTMLFormElement && form instanceof HTMLFormElement) {
|
|
329
|
-
let inputs = form.querySelectorAll('input');
|
|
330
|
-
let selects = form.querySelectorAll('select');
|
|
331
|
-
let textarea = form.querySelectorAll('textarea');
|
|
332
|
-
for (let idx = 0; idx < selects.length; idx++) {
|
|
333
|
-
let i = selects[idx];
|
|
334
|
-
if (i.name) {
|
|
335
|
-
appendData(data, i.name, i.value);
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
for (let idx = 0; idx < textarea.length; idx++) {
|
|
339
|
-
let i = textarea[idx];
|
|
340
|
-
if (i.name) {
|
|
341
|
-
appendData(data, i.name, i.value);
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
for (let idx = 0; idx < inputs.length; idx++) {
|
|
345
|
-
handleInput(inputs[idx]);
|
|
346
|
-
}
|
|
347
|
-
if (sizeof(data) > 2 * 1024 * 1024) {
|
|
348
|
-
throw new SkapiError('Data should not exceed 2MB', { code: 'INVALID_REQUEST' });
|
|
349
|
-
}
|
|
350
|
-
return { data, files };
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
if (sizeof(form) > 2 * 1024 * 1024) {
|
|
354
|
-
throw new SkapiError('Data should not exceed 2MB', { code: 'INVALID_REQUEST' });
|
|
355
|
-
}
|
|
356
|
-
return { data: form, files };
|
|
357
|
-
}
|
|
358
|
-
function parseUserAttributes(attr) {
|
|
359
|
-
let user = {};
|
|
360
|
-
for (let name in attr) {
|
|
361
|
-
let value = attr[name];
|
|
362
|
-
let excludes = ['aud', 'cognito:username', 'event_id', 'exp', 'iat', 'iss', 'jti', 'origin_jti', 'secret_key', 'token_use'];
|
|
363
|
-
let converts = {
|
|
364
|
-
auth_time: 'log',
|
|
365
|
-
sub: 'user_id'
|
|
366
|
-
};
|
|
367
|
-
if (excludes.includes(name))
|
|
368
|
-
continue;
|
|
369
|
-
if (converts[name]) {
|
|
370
|
-
user[converts[name]] = value;
|
|
371
|
-
}
|
|
372
|
-
else if (name.includes('custom:')) {
|
|
373
|
-
user[name.replace('custom:', '')] = value;
|
|
374
|
-
}
|
|
375
|
-
else if (name === 'address') {
|
|
376
|
-
let addr_main = value;
|
|
377
|
-
if (addr_main && typeof addr_main === 'object' && Object.keys(addr_main).length) {
|
|
378
|
-
if (addr_main?.formatted) {
|
|
379
|
-
try {
|
|
380
|
-
user[name] = JSON.parse(addr_main.formatted);
|
|
381
|
-
}
|
|
382
|
-
catch (err) {
|
|
383
|
-
user[name] = addr_main.formatted;
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
else {
|
|
388
|
-
user[name] = addr_main;
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
else {
|
|
392
|
-
user[name] = value;
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
for (let k of [
|
|
396
|
-
'address_public',
|
|
397
|
-
'birthdate_public',
|
|
398
|
-
'email_public',
|
|
399
|
-
'gender_public',
|
|
400
|
-
'phone_number_public',
|
|
401
|
-
'access_group'
|
|
402
|
-
]) {
|
|
403
|
-
if (k.includes('_public')) {
|
|
404
|
-
if (user.hasOwnProperty(k.split('_')[0]))
|
|
405
|
-
user[k] = user.hasOwnProperty(k) ? !!Number(user[k]) : false;
|
|
406
|
-
else
|
|
407
|
-
delete user[k];
|
|
408
|
-
}
|
|
409
|
-
else
|
|
410
|
-
user[k] = user.hasOwnProperty(k) ? Number(user[k]) : 0;
|
|
411
|
-
}
|
|
412
|
-
for (let k of [
|
|
413
|
-
'email',
|
|
414
|
-
'phone_number'
|
|
415
|
-
]) {
|
|
416
|
-
if (user.hasOwnProperty(k)) {
|
|
417
|
-
user[k + '_verified'] = user[k + '_verified'] === true;
|
|
418
|
-
}
|
|
419
|
-
else {
|
|
420
|
-
delete user[k + '_verified'];
|
|
421
|
-
}
|
|
422
|
-
}
|
|
423
|
-
return user;
|
|
424
|
-
}
|
|
425
|
-
function decodeServiceId(service) {
|
|
426
|
-
service = decompressCompoundId(service);
|
|
427
|
-
if (service.split("-").length === 7) {
|
|
428
|
-
const idSplit = service.split("-");
|
|
429
|
-
let region;
|
|
430
|
-
let owner;
|
|
431
|
-
try {
|
|
432
|
-
const regionKeys = [
|
|
433
|
-
"us31", "us72", "ap51", "ap22", "ap41", "eu71", "ap21", "us32", "us71",
|
|
434
|
-
"af51", "ap31", "ap43", "ap23", "ap42", "ca01", "eu01", "eu72", "eu51",
|
|
435
|
-
"eu73", "eu11", "me51", "sa31"
|
|
436
|
-
];
|
|
437
|
-
region = regionKeys[fromBase62(idSplit[1][0])];
|
|
438
|
-
owner = idSplit.slice(2).join("-");
|
|
439
|
-
}
|
|
440
|
-
catch (err) {
|
|
441
|
-
throw new Error('INVALID_PARAMETER: Service ID is invalid.');
|
|
442
|
-
}
|
|
443
|
-
if (!region) {
|
|
444
|
-
throw new Error('INVALID_PARAMETER: Service ID is invalid.');
|
|
445
|
-
}
|
|
446
|
-
return { service: region + idSplit[0] + idSplit[1].slice(1), owner };
|
|
447
|
-
}
|
|
448
|
-
return { service, owner: "" };
|
|
449
|
-
}
|
|
450
|
-
function formatServiceId(serviceId, ownerId) {
|
|
451
|
-
const alphabet = [
|
|
452
|
-
"0",
|
|
453
|
-
"1",
|
|
454
|
-
"2",
|
|
455
|
-
"3",
|
|
456
|
-
"4",
|
|
457
|
-
"5",
|
|
458
|
-
"6",
|
|
459
|
-
"7",
|
|
460
|
-
"8",
|
|
461
|
-
"9",
|
|
462
|
-
"a",
|
|
463
|
-
"b",
|
|
464
|
-
"c",
|
|
465
|
-
"d",
|
|
466
|
-
"e",
|
|
467
|
-
"f",
|
|
468
|
-
"g",
|
|
469
|
-
"h",
|
|
470
|
-
"i",
|
|
471
|
-
"j",
|
|
472
|
-
"k",
|
|
473
|
-
"l",
|
|
474
|
-
];
|
|
475
|
-
const regionKeys = [
|
|
476
|
-
"us31",
|
|
477
|
-
"us72",
|
|
478
|
-
"ap51",
|
|
479
|
-
"ap22",
|
|
480
|
-
"ap41",
|
|
481
|
-
"eu71",
|
|
482
|
-
"ap21",
|
|
483
|
-
"us32",
|
|
484
|
-
"us71",
|
|
485
|
-
"af51",
|
|
486
|
-
"ap31",
|
|
487
|
-
"ap43",
|
|
488
|
-
"ap23",
|
|
489
|
-
"ap42",
|
|
490
|
-
"ca01",
|
|
491
|
-
"eu01",
|
|
492
|
-
"eu72",
|
|
493
|
-
"eu51",
|
|
494
|
-
"eu73",
|
|
495
|
-
"eu11",
|
|
496
|
-
"me51",
|
|
497
|
-
"sa31",
|
|
498
|
-
];
|
|
499
|
-
const regionIndex = regionKeys.indexOf(serviceId.slice(0, 4));
|
|
500
|
-
const regionChar = alphabet[regionIndex];
|
|
501
|
-
const subRegionId = serviceId.slice(4, -4);
|
|
502
|
-
let formattedServiceId = `${subRegionId}-${regionChar}${serviceId.slice(-4)}-${ownerId}`;
|
|
503
|
-
return compressCompoundId(formattedServiceId);
|
|
504
|
-
}
|
|
505
|
-
function b62ToBigInt(str) {
|
|
506
|
-
let value = 0n;
|
|
507
|
-
for (const ch of str) {
|
|
508
|
-
const idx = BASE62_ALPHABET.indexOf(ch);
|
|
509
|
-
if (idx < 0) {
|
|
510
|
-
throw new Error(`INVALID_PARAMETER: Invalid base62 character: ${ch}`);
|
|
511
|
-
}
|
|
512
|
-
value = value * BASE62 + BigInt(idx);
|
|
513
|
-
}
|
|
514
|
-
return value;
|
|
515
|
-
}
|
|
516
|
-
function bigIntToB62(value, minLength = 1) {
|
|
517
|
-
if (value < 0n) {
|
|
518
|
-
throw new Error('INVALID_PARAMETER: Negative values are not supported.');
|
|
519
|
-
}
|
|
520
|
-
if (value === 0n) {
|
|
521
|
-
return '0'.repeat(Math.max(1, minLength));
|
|
522
|
-
}
|
|
523
|
-
let output = '';
|
|
524
|
-
let current = value;
|
|
525
|
-
while (current > 0n) {
|
|
526
|
-
const remainder = Number(current % BASE62);
|
|
527
|
-
output = BASE62_ALPHABET[remainder] + output;
|
|
528
|
-
current /= BASE62;
|
|
529
|
-
}
|
|
530
|
-
if (output.length < minLength) {
|
|
531
|
-
output = '0'.repeat(minLength - output.length) + output;
|
|
532
|
-
}
|
|
533
|
-
return output;
|
|
534
|
-
}
|
|
535
|
-
function bigIntToBytes(value) {
|
|
536
|
-
if (value === 0n) {
|
|
537
|
-
return Buffer.from([0]);
|
|
538
|
-
}
|
|
539
|
-
const bytes = [];
|
|
540
|
-
let current = value;
|
|
541
|
-
while (current > 0n) {
|
|
542
|
-
bytes.push(Number(current & 0xffn));
|
|
543
|
-
current >>= 8n;
|
|
544
|
-
}
|
|
545
|
-
bytes.reverse();
|
|
546
|
-
return Buffer.from(bytes);
|
|
547
|
-
}
|
|
548
|
-
function bytesToBigInt(buf) {
|
|
549
|
-
let value = 0n;
|
|
550
|
-
for (const b of buf) {
|
|
551
|
-
value = (value << 8n) + BigInt(b);
|
|
552
|
-
}
|
|
553
|
-
return value;
|
|
554
|
-
}
|
|
555
|
-
function uuidToBytes(uuid) {
|
|
556
|
-
const hex = String(uuid).replace(/-/g, '');
|
|
557
|
-
if (!/^[0-9a-fA-F]{32}$/.test(hex)) {
|
|
558
|
-
throw new Error('INVALID_PARAMETER: Invalid UUID format.');
|
|
559
|
-
}
|
|
560
|
-
return Buffer.from(hex, 'hex');
|
|
561
|
-
}
|
|
562
|
-
function bytesToUuid(buf16) {
|
|
563
|
-
const hex = Buffer.from(buf16).toString('hex');
|
|
564
|
-
return [
|
|
565
|
-
hex.slice(0, 8),
|
|
566
|
-
hex.slice(8, 12),
|
|
567
|
-
hex.slice(12, 16),
|
|
568
|
-
hex.slice(16, 20),
|
|
569
|
-
hex.slice(20)
|
|
570
|
-
].join('-');
|
|
571
|
-
}
|
|
572
|
-
function toBase64Url(input) {
|
|
573
|
-
if (Buffer) {
|
|
574
|
-
return Buffer.from(input).toString('base64');
|
|
575
|
-
}
|
|
576
|
-
let binary = '';
|
|
577
|
-
const bytes = new Uint8Array(input);
|
|
578
|
-
const chunk = 0x8000;
|
|
579
|
-
for (let i = 0; i < bytes.length; i += chunk) {
|
|
580
|
-
const slice = bytes.subarray(i, i + chunk);
|
|
581
|
-
binary += String.fromCharCode.apply(null, Array.from(slice));
|
|
582
|
-
}
|
|
583
|
-
if (typeof btoa === 'function') {
|
|
584
|
-
return btoa(binary);
|
|
585
|
-
}
|
|
586
|
-
throw new Error('No base64 encoder available in this environment.');
|
|
587
|
-
}
|
|
588
|
-
function fromBase64Url(str, parseJson = false) {
|
|
589
|
-
const base64 = String(str).replace(/-/g, '+').replace(/_/g, '/');
|
|
590
|
-
const padding = base64.length % 4 ? '='.repeat(4 - (base64.length % 4)) : '';
|
|
591
|
-
const decoded = Buffer.from(base64 + padding, 'base64');
|
|
592
|
-
if (parseJson) {
|
|
593
|
-
return JSON.parse(decoded.toString('utf8'));
|
|
594
|
-
}
|
|
595
|
-
return decoded;
|
|
596
|
-
}
|
|
597
|
-
function compressCompoundId(input) {
|
|
598
|
-
const match = String(input).match(/^([0-9A-Za-z]+)-([0-9A-Za-z]+)-([0-9a-fA-F-]{36})$/);
|
|
599
|
-
if (!match) {
|
|
600
|
-
throw new Error('INVALID_PARAMETER: Input must match <base62>-<base62>-<uuid>.');
|
|
601
|
-
}
|
|
602
|
-
const [, firstPart, secondPart, uuid] = match;
|
|
603
|
-
const firstValue = b62ToBigInt(firstPart);
|
|
604
|
-
const secondValue = b62ToBigInt(secondPart);
|
|
605
|
-
const firstBytes = bigIntToBytes(firstValue);
|
|
606
|
-
const secondBytes = bigIntToBytes(secondValue);
|
|
607
|
-
const uuidBytes = uuidToBytes(uuid);
|
|
608
|
-
if (firstPart.length > 255 ||
|
|
609
|
-
secondPart.length > 255 ||
|
|
610
|
-
firstBytes.length > 255 ||
|
|
611
|
-
secondBytes.length > 255) {
|
|
612
|
-
throw new Error('INVALID_PARAMETER: Input parts are too long to encode.');
|
|
613
|
-
}
|
|
614
|
-
const payload = Buffer.concat([
|
|
615
|
-
Buffer.from([1, firstPart.length, secondPart.length, firstBytes.length, secondBytes.length]),
|
|
616
|
-
firstBytes,
|
|
617
|
-
secondBytes,
|
|
618
|
-
uuidBytes
|
|
619
|
-
]);
|
|
620
|
-
return `s1_${toBase64Url(payload)}`;
|
|
621
|
-
}
|
|
622
|
-
function decompressCompoundId(token) {
|
|
623
|
-
const tokenString = String(token);
|
|
624
|
-
if (!tokenString.startsWith('s1_')) {
|
|
625
|
-
return tokenString;
|
|
626
|
-
}
|
|
627
|
-
const payload = fromBase64Url(tokenString.slice(3));
|
|
628
|
-
if (payload.length < 21) {
|
|
629
|
-
throw new Error('INVALID_PARAMETER: Corrupt compressed token.');
|
|
630
|
-
}
|
|
631
|
-
const version = payload[0];
|
|
632
|
-
if (version !== 1) {
|
|
633
|
-
throw new Error(`INVALID_PARAMETER: Unsupported token version: ${version}`);
|
|
634
|
-
}
|
|
635
|
-
const firstLength = payload[1];
|
|
636
|
-
const secondLength = payload[2];
|
|
637
|
-
const firstBytesLength = payload[3];
|
|
638
|
-
const secondBytesLength = payload[4];
|
|
639
|
-
const firstStart = 5;
|
|
640
|
-
const secondStart = firstStart + firstBytesLength;
|
|
641
|
-
const uuidStart = secondStart + secondBytesLength;
|
|
642
|
-
if (payload.length !== uuidStart + 16) {
|
|
643
|
-
throw new Error('INVALID_PARAMETER: Corrupt compressed token length.');
|
|
644
|
-
}
|
|
645
|
-
const firstPart = bigIntToB62(bytesToBigInt(payload.subarray(firstStart, secondStart)), firstLength);
|
|
646
|
-
const secondPart = bigIntToB62(bytesToBigInt(payload.subarray(secondStart, uuidStart)), secondLength);
|
|
647
|
-
const uuid = bytesToUuid(payload.subarray(uuidStart, uuidStart + 16));
|
|
648
|
-
return `${firstPart}-${secondPart}-${uuid}`;
|
|
649
|
-
}
|
|
650
|
-
export { fromBase62, toBase62, extractFormData, MD5, generateRandom, parseUserAttributes, compressCompoundId, decompressCompoundId, formatServiceId, decodeServiceId, toBase64Url };
|
|
651
|
-
//# sourceMappingURL=utils.js.map
|