@wix/sdk 1.12.12 → 1.12.14
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/build/auth/AppStrategy.js +3 -0
- package/build/auth/oauth2/pkce-challenge.js +11 -3
- package/build/auth/oauth2/sha256.d.ts +8 -0
- package/build/auth/oauth2/sha256.js +278 -0
- package/build/rest-modules.d.ts +1 -1
- package/build/rest-modules.js +2 -1
- package/build/wixClient.js +1 -1
- package/cjs/build/auth/AppStrategy.js +3 -0
- package/cjs/build/auth/oauth2/pkce-challenge.js +11 -6
- package/cjs/build/auth/oauth2/sha256.d.ts +8 -0
- package/cjs/build/auth/oauth2/sha256.js +282 -0
- package/cjs/build/rest-modules.d.ts +1 -1
- package/cjs/build/rest-modules.js +2 -1
- package/cjs/build/wixClient.js +1 -1
- package/package.json +7 -10
|
@@ -207,6 +207,9 @@ export function AppStrategy(opts) {
|
|
|
207
207
|
}
|
|
208
208
|
return getTokenInfo(tokenToCheck, authServerBaseUrl);
|
|
209
209
|
},
|
|
210
|
+
getActiveToken() {
|
|
211
|
+
return 'accessToken' in opts ? opts.accessToken : refreshToken;
|
|
212
|
+
},
|
|
210
213
|
};
|
|
211
214
|
}
|
|
212
215
|
async function getTokenInfo(token, authServerBaseUrl) {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import encBase64url from 'crypto-js/enc-base64url.js';
|
|
1
|
+
import { sha256 } from './sha256.js';
|
|
3
2
|
export function pkceChallenge(length) {
|
|
4
3
|
if (!length) {
|
|
5
4
|
length = 43;
|
|
@@ -18,7 +17,7 @@ function generateVerifier(length) {
|
|
|
18
17
|
return random(length);
|
|
19
18
|
}
|
|
20
19
|
export function generateChallenge(code_verifier) {
|
|
21
|
-
return
|
|
20
|
+
return base64urlencode(sha256(code_verifier));
|
|
22
21
|
}
|
|
23
22
|
function random(size) {
|
|
24
23
|
const mask = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~';
|
|
@@ -31,3 +30,12 @@ function random(size) {
|
|
|
31
30
|
}
|
|
32
31
|
return result;
|
|
33
32
|
}
|
|
33
|
+
function base64urlencode(str) {
|
|
34
|
+
const base64 = typeof Buffer === 'undefined'
|
|
35
|
+
? btoa(ab2str(str))
|
|
36
|
+
: Buffer.from(str).toString('base64');
|
|
37
|
+
return base64.replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
|
|
38
|
+
}
|
|
39
|
+
function ab2str(buf) {
|
|
40
|
+
return String.fromCharCode.apply(null, Array.from(new Uint8Array(buf)));
|
|
41
|
+
}
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* [js-sha256]{@link https://github.com/emn178/js-sha256}
|
|
3
|
+
* @version 0.11.0
|
|
4
|
+
* @author Chen, Yi-Cyuan [emn178@gmail.com]
|
|
5
|
+
* @copyright Chen, Yi-Cyuan 2014-2024
|
|
6
|
+
* @license MIT
|
|
7
|
+
*/
|
|
8
|
+
// Inline here to avoid bringing in another library, cause:
|
|
9
|
+
// 1. we have commited to a sync API (hopefully we'll change to async and
|
|
10
|
+
// can start using the builtin crypto sha256), so we need a sync sha256,
|
|
11
|
+
// but the existing sync sha256 libs are not ESM
|
|
12
|
+
// 2. avoid bringing in a library for a single function
|
|
13
|
+
const SHIFT = [24, 16, 8, 0];
|
|
14
|
+
const EXTRA = [-2147483648, 8388608, 32768, 128];
|
|
15
|
+
const K = [
|
|
16
|
+
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1,
|
|
17
|
+
0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
|
|
18
|
+
0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 0xe49b69c1, 0xefbe4786,
|
|
19
|
+
0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
|
|
20
|
+
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147,
|
|
21
|
+
0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
|
|
22
|
+
0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 0xa2bfe8a1, 0xa81a664b,
|
|
23
|
+
0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
|
|
24
|
+
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a,
|
|
25
|
+
0x5b9cca4f, 0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
|
|
26
|
+
0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,
|
|
27
|
+
];
|
|
28
|
+
class SHA256 {
|
|
29
|
+
blocks;
|
|
30
|
+
h0;
|
|
31
|
+
h1;
|
|
32
|
+
h2;
|
|
33
|
+
h3;
|
|
34
|
+
h4;
|
|
35
|
+
h5;
|
|
36
|
+
h6;
|
|
37
|
+
h7;
|
|
38
|
+
block;
|
|
39
|
+
start;
|
|
40
|
+
bytes;
|
|
41
|
+
hBytes;
|
|
42
|
+
finalized;
|
|
43
|
+
hashed;
|
|
44
|
+
first;
|
|
45
|
+
lastByteIndex;
|
|
46
|
+
chromeBugWorkAround;
|
|
47
|
+
constructor() {
|
|
48
|
+
this.blocks = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
|
|
49
|
+
// 256
|
|
50
|
+
this.h0 = 0x6a09e667;
|
|
51
|
+
this.h1 = 0xbb67ae85;
|
|
52
|
+
this.h2 = 0x3c6ef372;
|
|
53
|
+
this.h3 = 0xa54ff53a;
|
|
54
|
+
this.h4 = 0x510e527f;
|
|
55
|
+
this.h5 = 0x9b05688c;
|
|
56
|
+
this.h6 = 0x1f83d9ab;
|
|
57
|
+
this.h7 = 0x5be0cd19;
|
|
58
|
+
this.block = this.start = this.bytes = this.hBytes = 0;
|
|
59
|
+
this.finalized = this.hashed = false;
|
|
60
|
+
this.first = true;
|
|
61
|
+
}
|
|
62
|
+
update(message) {
|
|
63
|
+
const blocks = this.blocks;
|
|
64
|
+
const length = message.length;
|
|
65
|
+
let code, index = 0, i;
|
|
66
|
+
while (index < length) {
|
|
67
|
+
if (this.hashed) {
|
|
68
|
+
this.hashed = false;
|
|
69
|
+
blocks[0] = this.block;
|
|
70
|
+
this.block =
|
|
71
|
+
blocks[16] =
|
|
72
|
+
blocks[1] =
|
|
73
|
+
blocks[2] =
|
|
74
|
+
blocks[3] =
|
|
75
|
+
blocks[4] =
|
|
76
|
+
blocks[5] =
|
|
77
|
+
blocks[6] =
|
|
78
|
+
blocks[7] =
|
|
79
|
+
blocks[8] =
|
|
80
|
+
blocks[9] =
|
|
81
|
+
blocks[10] =
|
|
82
|
+
blocks[11] =
|
|
83
|
+
blocks[12] =
|
|
84
|
+
blocks[13] =
|
|
85
|
+
blocks[14] =
|
|
86
|
+
blocks[15] =
|
|
87
|
+
0;
|
|
88
|
+
}
|
|
89
|
+
for (i = this.start; index < length && i < 64; ++index) {
|
|
90
|
+
code = message.charCodeAt(index);
|
|
91
|
+
if (code < 0x80) {
|
|
92
|
+
blocks[i >>> 2] |= code << SHIFT[i++ & 3];
|
|
93
|
+
}
|
|
94
|
+
else if (code < 0x800) {
|
|
95
|
+
blocks[i >>> 2] |= (0xc0 | (code >>> 6)) << SHIFT[i++ & 3];
|
|
96
|
+
blocks[i >>> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
|
|
97
|
+
}
|
|
98
|
+
else if (code < 0xd800 || code >= 0xe000) {
|
|
99
|
+
blocks[i >>> 2] |= (0xe0 | (code >>> 12)) << SHIFT[i++ & 3];
|
|
100
|
+
blocks[i >>> 2] |= (0x80 | ((code >>> 6) & 0x3f)) << SHIFT[i++ & 3];
|
|
101
|
+
blocks[i >>> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
code =
|
|
105
|
+
0x10000 +
|
|
106
|
+
(((code & 0x3ff) << 10) | (message.charCodeAt(++index) & 0x3ff));
|
|
107
|
+
blocks[i >>> 2] |= (0xf0 | (code >>> 18)) << SHIFT[i++ & 3];
|
|
108
|
+
blocks[i >>> 2] |= (0x80 | ((code >>> 12) & 0x3f)) << SHIFT[i++ & 3];
|
|
109
|
+
blocks[i >>> 2] |= (0x80 | ((code >>> 6) & 0x3f)) << SHIFT[i++ & 3];
|
|
110
|
+
blocks[i >>> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
this.lastByteIndex = i;
|
|
114
|
+
this.bytes += i - this.start;
|
|
115
|
+
if (i >= 64) {
|
|
116
|
+
this.block = blocks[16];
|
|
117
|
+
this.start = i - 64;
|
|
118
|
+
this.hash();
|
|
119
|
+
this.hashed = true;
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
this.start = i;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
if (this.bytes > 4294967295) {
|
|
126
|
+
this.hBytes += (this.bytes / 4294967296) << 0;
|
|
127
|
+
this.bytes = this.bytes % 4294967296;
|
|
128
|
+
}
|
|
129
|
+
return this;
|
|
130
|
+
}
|
|
131
|
+
hash() {
|
|
132
|
+
const blocks = this.blocks;
|
|
133
|
+
let a = this.h0, b = this.h1, c = this.h2, d = this.h3, e = this.h4, f = this.h5, g = this.h6, h = this.h7, j, s0, s1, maj, t1, t2, ch, ab, da, cd, bc;
|
|
134
|
+
for (j = 16; j < 64; ++j) {
|
|
135
|
+
// rightrotate
|
|
136
|
+
t1 = blocks[j - 15];
|
|
137
|
+
s0 = ((t1 >>> 7) | (t1 << 25)) ^ ((t1 >>> 18) | (t1 << 14)) ^ (t1 >>> 3);
|
|
138
|
+
t1 = blocks[j - 2];
|
|
139
|
+
s1 =
|
|
140
|
+
((t1 >>> 17) | (t1 << 15)) ^ ((t1 >>> 19) | (t1 << 13)) ^ (t1 >>> 10);
|
|
141
|
+
blocks[j] = (blocks[j - 16] + s0 + blocks[j - 7] + s1) << 0;
|
|
142
|
+
}
|
|
143
|
+
bc = b & c;
|
|
144
|
+
for (j = 0; j < 64; j += 4) {
|
|
145
|
+
if (this.first) {
|
|
146
|
+
ab = 704751109;
|
|
147
|
+
t1 = blocks[0] - 210244248;
|
|
148
|
+
h = (t1 - 1521486534) << 0;
|
|
149
|
+
d = (t1 + 143694565) << 0;
|
|
150
|
+
this.first = false;
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
s0 =
|
|
154
|
+
((a >>> 2) | (a << 30)) ^
|
|
155
|
+
((a >>> 13) | (a << 19)) ^
|
|
156
|
+
((a >>> 22) | (a << 10));
|
|
157
|
+
s1 =
|
|
158
|
+
((e >>> 6) | (e << 26)) ^
|
|
159
|
+
((e >>> 11) | (e << 21)) ^
|
|
160
|
+
((e >>> 25) | (e << 7));
|
|
161
|
+
ab = a & b;
|
|
162
|
+
maj = ab ^ (a & c) ^ bc;
|
|
163
|
+
ch = (e & f) ^ (~e & g);
|
|
164
|
+
t1 = h + s1 + ch + K[j] + blocks[j];
|
|
165
|
+
t2 = s0 + maj;
|
|
166
|
+
h = (d + t1) << 0;
|
|
167
|
+
d = (t1 + t2) << 0;
|
|
168
|
+
}
|
|
169
|
+
s0 =
|
|
170
|
+
((d >>> 2) | (d << 30)) ^
|
|
171
|
+
((d >>> 13) | (d << 19)) ^
|
|
172
|
+
((d >>> 22) | (d << 10));
|
|
173
|
+
s1 =
|
|
174
|
+
((h >>> 6) | (h << 26)) ^
|
|
175
|
+
((h >>> 11) | (h << 21)) ^
|
|
176
|
+
((h >>> 25) | (h << 7));
|
|
177
|
+
da = d & a;
|
|
178
|
+
maj = da ^ (d & b) ^ ab;
|
|
179
|
+
ch = (h & e) ^ (~h & f);
|
|
180
|
+
t1 = g + s1 + ch + K[j + 1] + blocks[j + 1];
|
|
181
|
+
t2 = s0 + maj;
|
|
182
|
+
g = (c + t1) << 0;
|
|
183
|
+
c = (t1 + t2) << 0;
|
|
184
|
+
s0 =
|
|
185
|
+
((c >>> 2) | (c << 30)) ^
|
|
186
|
+
((c >>> 13) | (c << 19)) ^
|
|
187
|
+
((c >>> 22) | (c << 10));
|
|
188
|
+
s1 =
|
|
189
|
+
((g >>> 6) | (g << 26)) ^
|
|
190
|
+
((g >>> 11) | (g << 21)) ^
|
|
191
|
+
((g >>> 25) | (g << 7));
|
|
192
|
+
cd = c & d;
|
|
193
|
+
maj = cd ^ (c & a) ^ da;
|
|
194
|
+
ch = (g & h) ^ (~g & e);
|
|
195
|
+
t1 = f + s1 + ch + K[j + 2] + blocks[j + 2];
|
|
196
|
+
t2 = s0 + maj;
|
|
197
|
+
f = (b + t1) << 0;
|
|
198
|
+
b = (t1 + t2) << 0;
|
|
199
|
+
s0 =
|
|
200
|
+
((b >>> 2) | (b << 30)) ^
|
|
201
|
+
((b >>> 13) | (b << 19)) ^
|
|
202
|
+
((b >>> 22) | (b << 10));
|
|
203
|
+
s1 =
|
|
204
|
+
((f >>> 6) | (f << 26)) ^
|
|
205
|
+
((f >>> 11) | (f << 21)) ^
|
|
206
|
+
((f >>> 25) | (f << 7));
|
|
207
|
+
bc = b & c;
|
|
208
|
+
maj = bc ^ (b & d) ^ cd;
|
|
209
|
+
ch = (f & g) ^ (~f & h);
|
|
210
|
+
t1 = e + s1 + ch + K[j + 3] + blocks[j + 3];
|
|
211
|
+
t2 = s0 + maj;
|
|
212
|
+
e = (a + t1) << 0;
|
|
213
|
+
a = (t1 + t2) << 0;
|
|
214
|
+
this.chromeBugWorkAround = true;
|
|
215
|
+
}
|
|
216
|
+
this.h0 = (this.h0 + a) << 0;
|
|
217
|
+
this.h1 = (this.h1 + b) << 0;
|
|
218
|
+
this.h2 = (this.h2 + c) << 0;
|
|
219
|
+
this.h3 = (this.h3 + d) << 0;
|
|
220
|
+
this.h4 = (this.h4 + e) << 0;
|
|
221
|
+
this.h5 = (this.h5 + f) << 0;
|
|
222
|
+
this.h6 = (this.h6 + g) << 0;
|
|
223
|
+
this.h7 = (this.h7 + h) << 0;
|
|
224
|
+
}
|
|
225
|
+
finalize() {
|
|
226
|
+
if (this.finalized) {
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
this.finalized = true;
|
|
230
|
+
const blocks = this.blocks, i = this.lastByteIndex;
|
|
231
|
+
blocks[16] = this.block;
|
|
232
|
+
blocks[i >>> 2] |= EXTRA[i & 3];
|
|
233
|
+
this.block = blocks[16];
|
|
234
|
+
if (i >= 56) {
|
|
235
|
+
if (!this.hashed) {
|
|
236
|
+
this.hash();
|
|
237
|
+
}
|
|
238
|
+
blocks[0] = this.block;
|
|
239
|
+
blocks[16] =
|
|
240
|
+
blocks[1] =
|
|
241
|
+
blocks[2] =
|
|
242
|
+
blocks[3] =
|
|
243
|
+
blocks[4] =
|
|
244
|
+
blocks[5] =
|
|
245
|
+
blocks[6] =
|
|
246
|
+
blocks[7] =
|
|
247
|
+
blocks[8] =
|
|
248
|
+
blocks[9] =
|
|
249
|
+
blocks[10] =
|
|
250
|
+
blocks[11] =
|
|
251
|
+
blocks[12] =
|
|
252
|
+
blocks[13] =
|
|
253
|
+
blocks[14] =
|
|
254
|
+
blocks[15] =
|
|
255
|
+
0;
|
|
256
|
+
}
|
|
257
|
+
blocks[14] = (this.hBytes << 3) | (this.bytes >>> 29);
|
|
258
|
+
blocks[15] = this.bytes << 3;
|
|
259
|
+
this.hash();
|
|
260
|
+
}
|
|
261
|
+
arrayBuffer() {
|
|
262
|
+
this.finalize();
|
|
263
|
+
const buffer = new ArrayBuffer(32);
|
|
264
|
+
const dataView = new DataView(buffer);
|
|
265
|
+
dataView.setUint32(0, this.h0);
|
|
266
|
+
dataView.setUint32(4, this.h1);
|
|
267
|
+
dataView.setUint32(8, this.h2);
|
|
268
|
+
dataView.setUint32(12, this.h3);
|
|
269
|
+
dataView.setUint32(16, this.h4);
|
|
270
|
+
dataView.setUint32(20, this.h5);
|
|
271
|
+
dataView.setUint32(24, this.h6);
|
|
272
|
+
dataView.setUint32(28, this.h7);
|
|
273
|
+
return buffer;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
export function sha256(message) {
|
|
277
|
+
return new SHA256().update(message).arrayBuffer();
|
|
278
|
+
}
|
package/build/rest-modules.d.ts
CHANGED
|
@@ -2,4 +2,4 @@ import { BuildRESTFunction, PublicMetadata, RESTFunctionDescriptor } from '@wix/
|
|
|
2
2
|
export type RESTModuleOptions = {
|
|
3
3
|
HTTPHost?: string;
|
|
4
4
|
};
|
|
5
|
-
export declare function buildRESTDescriptor<T extends RESTFunctionDescriptor>(origFunc: T, publicMetadata: PublicMetadata, boundFetch: typeof fetch, wixAPIFetch: (relativeUrl: string, options: RequestInit) => Promise<Response>, options?: RESTModuleOptions): BuildRESTFunction<T>;
|
|
5
|
+
export declare function buildRESTDescriptor<T extends RESTFunctionDescriptor>(origFunc: T, publicMetadata: PublicMetadata, boundFetch: typeof fetch, wixAPIFetch: (relativeUrl: string, options: RequestInit) => Promise<Response>, getActiveToken?: () => string | undefined, options?: RESTModuleOptions): BuildRESTFunction<T>;
|
package/build/rest-modules.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { biHeaderGenerator } from './bi/biHeaderGenerator.js';
|
|
2
2
|
import { DEFAULT_API_URL } from './common.js';
|
|
3
3
|
import { runWithoutContext } from '@wix/sdk-runtime/context';
|
|
4
|
-
export function buildRESTDescriptor(origFunc, publicMetadata, boundFetch, wixAPIFetch, options) {
|
|
4
|
+
export function buildRESTDescriptor(origFunc, publicMetadata, boundFetch, wixAPIFetch, getActiveToken, options) {
|
|
5
5
|
return runWithoutContext(() => origFunc({
|
|
6
6
|
request: async (factory) => {
|
|
7
7
|
const requestOptions = factory({
|
|
@@ -59,6 +59,7 @@ export function buildRESTDescriptor(origFunc, publicMetadata, boundFetch, wixAPI
|
|
|
59
59
|
},
|
|
60
60
|
fetchWithAuth: boundFetch,
|
|
61
61
|
wixAPIFetch,
|
|
62
|
+
getActiveToken,
|
|
62
63
|
}));
|
|
63
64
|
}
|
|
64
65
|
const errorBuilder = (code, description, details, data) => {
|
package/build/wixClient.js
CHANGED
|
@@ -60,7 +60,7 @@ export function createClient(config) {
|
|
|
60
60
|
finalUrl.host = apiBaseUrl;
|
|
61
61
|
finalUrl.protocol = 'https';
|
|
62
62
|
return boundFetch(finalUrl.toString(), fetchOptions);
|
|
63
|
-
}, { HTTPHost: apiBaseUrl });
|
|
63
|
+
}, authStrategy.getActiveToken, { HTTPHost: apiBaseUrl });
|
|
64
64
|
}
|
|
65
65
|
else if (isObject(modules)) {
|
|
66
66
|
return Object.fromEntries(Object.entries(modules).map(([key, value]) => {
|
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.generateChallenge = exports.pkceChallenge = void 0;
|
|
7
|
-
const sha256_js_1 =
|
|
8
|
-
const enc_base64url_js_1 = __importDefault(require("crypto-js/enc-base64url.js"));
|
|
4
|
+
const sha256_js_1 = require("./sha256.js");
|
|
9
5
|
function pkceChallenge(length) {
|
|
10
6
|
if (!length) {
|
|
11
7
|
length = 43;
|
|
@@ -25,7 +21,7 @@ function generateVerifier(length) {
|
|
|
25
21
|
return random(length);
|
|
26
22
|
}
|
|
27
23
|
function generateChallenge(code_verifier) {
|
|
28
|
-
return (0, sha256_js_1.
|
|
24
|
+
return base64urlencode((0, sha256_js_1.sha256)(code_verifier));
|
|
29
25
|
}
|
|
30
26
|
exports.generateChallenge = generateChallenge;
|
|
31
27
|
function random(size) {
|
|
@@ -39,3 +35,12 @@ function random(size) {
|
|
|
39
35
|
}
|
|
40
36
|
return result;
|
|
41
37
|
}
|
|
38
|
+
function base64urlencode(str) {
|
|
39
|
+
const base64 = typeof Buffer === 'undefined'
|
|
40
|
+
? btoa(ab2str(str))
|
|
41
|
+
: Buffer.from(str).toString('base64');
|
|
42
|
+
return base64.replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
|
|
43
|
+
}
|
|
44
|
+
function ab2str(buf) {
|
|
45
|
+
return String.fromCharCode.apply(null, Array.from(new Uint8Array(buf)));
|
|
46
|
+
}
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* [js-sha256]{@link https://github.com/emn178/js-sha256}
|
|
4
|
+
* @version 0.11.0
|
|
5
|
+
* @author Chen, Yi-Cyuan [emn178@gmail.com]
|
|
6
|
+
* @copyright Chen, Yi-Cyuan 2014-2024
|
|
7
|
+
* @license MIT
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.sha256 = void 0;
|
|
11
|
+
// Inline here to avoid bringing in another library, cause:
|
|
12
|
+
// 1. we have commited to a sync API (hopefully we'll change to async and
|
|
13
|
+
// can start using the builtin crypto sha256), so we need a sync sha256,
|
|
14
|
+
// but the existing sync sha256 libs are not ESM
|
|
15
|
+
// 2. avoid bringing in a library for a single function
|
|
16
|
+
const SHIFT = [24, 16, 8, 0];
|
|
17
|
+
const EXTRA = [-2147483648, 8388608, 32768, 128];
|
|
18
|
+
const K = [
|
|
19
|
+
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1,
|
|
20
|
+
0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
|
|
21
|
+
0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 0xe49b69c1, 0xefbe4786,
|
|
22
|
+
0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
|
|
23
|
+
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147,
|
|
24
|
+
0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
|
|
25
|
+
0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 0xa2bfe8a1, 0xa81a664b,
|
|
26
|
+
0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
|
|
27
|
+
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a,
|
|
28
|
+
0x5b9cca4f, 0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
|
|
29
|
+
0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,
|
|
30
|
+
];
|
|
31
|
+
class SHA256 {
|
|
32
|
+
blocks;
|
|
33
|
+
h0;
|
|
34
|
+
h1;
|
|
35
|
+
h2;
|
|
36
|
+
h3;
|
|
37
|
+
h4;
|
|
38
|
+
h5;
|
|
39
|
+
h6;
|
|
40
|
+
h7;
|
|
41
|
+
block;
|
|
42
|
+
start;
|
|
43
|
+
bytes;
|
|
44
|
+
hBytes;
|
|
45
|
+
finalized;
|
|
46
|
+
hashed;
|
|
47
|
+
first;
|
|
48
|
+
lastByteIndex;
|
|
49
|
+
chromeBugWorkAround;
|
|
50
|
+
constructor() {
|
|
51
|
+
this.blocks = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
|
|
52
|
+
// 256
|
|
53
|
+
this.h0 = 0x6a09e667;
|
|
54
|
+
this.h1 = 0xbb67ae85;
|
|
55
|
+
this.h2 = 0x3c6ef372;
|
|
56
|
+
this.h3 = 0xa54ff53a;
|
|
57
|
+
this.h4 = 0x510e527f;
|
|
58
|
+
this.h5 = 0x9b05688c;
|
|
59
|
+
this.h6 = 0x1f83d9ab;
|
|
60
|
+
this.h7 = 0x5be0cd19;
|
|
61
|
+
this.block = this.start = this.bytes = this.hBytes = 0;
|
|
62
|
+
this.finalized = this.hashed = false;
|
|
63
|
+
this.first = true;
|
|
64
|
+
}
|
|
65
|
+
update(message) {
|
|
66
|
+
const blocks = this.blocks;
|
|
67
|
+
const length = message.length;
|
|
68
|
+
let code, index = 0, i;
|
|
69
|
+
while (index < length) {
|
|
70
|
+
if (this.hashed) {
|
|
71
|
+
this.hashed = false;
|
|
72
|
+
blocks[0] = this.block;
|
|
73
|
+
this.block =
|
|
74
|
+
blocks[16] =
|
|
75
|
+
blocks[1] =
|
|
76
|
+
blocks[2] =
|
|
77
|
+
blocks[3] =
|
|
78
|
+
blocks[4] =
|
|
79
|
+
blocks[5] =
|
|
80
|
+
blocks[6] =
|
|
81
|
+
blocks[7] =
|
|
82
|
+
blocks[8] =
|
|
83
|
+
blocks[9] =
|
|
84
|
+
blocks[10] =
|
|
85
|
+
blocks[11] =
|
|
86
|
+
blocks[12] =
|
|
87
|
+
blocks[13] =
|
|
88
|
+
blocks[14] =
|
|
89
|
+
blocks[15] =
|
|
90
|
+
0;
|
|
91
|
+
}
|
|
92
|
+
for (i = this.start; index < length && i < 64; ++index) {
|
|
93
|
+
code = message.charCodeAt(index);
|
|
94
|
+
if (code < 0x80) {
|
|
95
|
+
blocks[i >>> 2] |= code << SHIFT[i++ & 3];
|
|
96
|
+
}
|
|
97
|
+
else if (code < 0x800) {
|
|
98
|
+
blocks[i >>> 2] |= (0xc0 | (code >>> 6)) << SHIFT[i++ & 3];
|
|
99
|
+
blocks[i >>> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
|
|
100
|
+
}
|
|
101
|
+
else if (code < 0xd800 || code >= 0xe000) {
|
|
102
|
+
blocks[i >>> 2] |= (0xe0 | (code >>> 12)) << SHIFT[i++ & 3];
|
|
103
|
+
blocks[i >>> 2] |= (0x80 | ((code >>> 6) & 0x3f)) << SHIFT[i++ & 3];
|
|
104
|
+
blocks[i >>> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
code =
|
|
108
|
+
0x10000 +
|
|
109
|
+
(((code & 0x3ff) << 10) | (message.charCodeAt(++index) & 0x3ff));
|
|
110
|
+
blocks[i >>> 2] |= (0xf0 | (code >>> 18)) << SHIFT[i++ & 3];
|
|
111
|
+
blocks[i >>> 2] |= (0x80 | ((code >>> 12) & 0x3f)) << SHIFT[i++ & 3];
|
|
112
|
+
blocks[i >>> 2] |= (0x80 | ((code >>> 6) & 0x3f)) << SHIFT[i++ & 3];
|
|
113
|
+
blocks[i >>> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
this.lastByteIndex = i;
|
|
117
|
+
this.bytes += i - this.start;
|
|
118
|
+
if (i >= 64) {
|
|
119
|
+
this.block = blocks[16];
|
|
120
|
+
this.start = i - 64;
|
|
121
|
+
this.hash();
|
|
122
|
+
this.hashed = true;
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
this.start = i;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
if (this.bytes > 4294967295) {
|
|
129
|
+
this.hBytes += (this.bytes / 4294967296) << 0;
|
|
130
|
+
this.bytes = this.bytes % 4294967296;
|
|
131
|
+
}
|
|
132
|
+
return this;
|
|
133
|
+
}
|
|
134
|
+
hash() {
|
|
135
|
+
const blocks = this.blocks;
|
|
136
|
+
let a = this.h0, b = this.h1, c = this.h2, d = this.h3, e = this.h4, f = this.h5, g = this.h6, h = this.h7, j, s0, s1, maj, t1, t2, ch, ab, da, cd, bc;
|
|
137
|
+
for (j = 16; j < 64; ++j) {
|
|
138
|
+
// rightrotate
|
|
139
|
+
t1 = blocks[j - 15];
|
|
140
|
+
s0 = ((t1 >>> 7) | (t1 << 25)) ^ ((t1 >>> 18) | (t1 << 14)) ^ (t1 >>> 3);
|
|
141
|
+
t1 = blocks[j - 2];
|
|
142
|
+
s1 =
|
|
143
|
+
((t1 >>> 17) | (t1 << 15)) ^ ((t1 >>> 19) | (t1 << 13)) ^ (t1 >>> 10);
|
|
144
|
+
blocks[j] = (blocks[j - 16] + s0 + blocks[j - 7] + s1) << 0;
|
|
145
|
+
}
|
|
146
|
+
bc = b & c;
|
|
147
|
+
for (j = 0; j < 64; j += 4) {
|
|
148
|
+
if (this.first) {
|
|
149
|
+
ab = 704751109;
|
|
150
|
+
t1 = blocks[0] - 210244248;
|
|
151
|
+
h = (t1 - 1521486534) << 0;
|
|
152
|
+
d = (t1 + 143694565) << 0;
|
|
153
|
+
this.first = false;
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
s0 =
|
|
157
|
+
((a >>> 2) | (a << 30)) ^
|
|
158
|
+
((a >>> 13) | (a << 19)) ^
|
|
159
|
+
((a >>> 22) | (a << 10));
|
|
160
|
+
s1 =
|
|
161
|
+
((e >>> 6) | (e << 26)) ^
|
|
162
|
+
((e >>> 11) | (e << 21)) ^
|
|
163
|
+
((e >>> 25) | (e << 7));
|
|
164
|
+
ab = a & b;
|
|
165
|
+
maj = ab ^ (a & c) ^ bc;
|
|
166
|
+
ch = (e & f) ^ (~e & g);
|
|
167
|
+
t1 = h + s1 + ch + K[j] + blocks[j];
|
|
168
|
+
t2 = s0 + maj;
|
|
169
|
+
h = (d + t1) << 0;
|
|
170
|
+
d = (t1 + t2) << 0;
|
|
171
|
+
}
|
|
172
|
+
s0 =
|
|
173
|
+
((d >>> 2) | (d << 30)) ^
|
|
174
|
+
((d >>> 13) | (d << 19)) ^
|
|
175
|
+
((d >>> 22) | (d << 10));
|
|
176
|
+
s1 =
|
|
177
|
+
((h >>> 6) | (h << 26)) ^
|
|
178
|
+
((h >>> 11) | (h << 21)) ^
|
|
179
|
+
((h >>> 25) | (h << 7));
|
|
180
|
+
da = d & a;
|
|
181
|
+
maj = da ^ (d & b) ^ ab;
|
|
182
|
+
ch = (h & e) ^ (~h & f);
|
|
183
|
+
t1 = g + s1 + ch + K[j + 1] + blocks[j + 1];
|
|
184
|
+
t2 = s0 + maj;
|
|
185
|
+
g = (c + t1) << 0;
|
|
186
|
+
c = (t1 + t2) << 0;
|
|
187
|
+
s0 =
|
|
188
|
+
((c >>> 2) | (c << 30)) ^
|
|
189
|
+
((c >>> 13) | (c << 19)) ^
|
|
190
|
+
((c >>> 22) | (c << 10));
|
|
191
|
+
s1 =
|
|
192
|
+
((g >>> 6) | (g << 26)) ^
|
|
193
|
+
((g >>> 11) | (g << 21)) ^
|
|
194
|
+
((g >>> 25) | (g << 7));
|
|
195
|
+
cd = c & d;
|
|
196
|
+
maj = cd ^ (c & a) ^ da;
|
|
197
|
+
ch = (g & h) ^ (~g & e);
|
|
198
|
+
t1 = f + s1 + ch + K[j + 2] + blocks[j + 2];
|
|
199
|
+
t2 = s0 + maj;
|
|
200
|
+
f = (b + t1) << 0;
|
|
201
|
+
b = (t1 + t2) << 0;
|
|
202
|
+
s0 =
|
|
203
|
+
((b >>> 2) | (b << 30)) ^
|
|
204
|
+
((b >>> 13) | (b << 19)) ^
|
|
205
|
+
((b >>> 22) | (b << 10));
|
|
206
|
+
s1 =
|
|
207
|
+
((f >>> 6) | (f << 26)) ^
|
|
208
|
+
((f >>> 11) | (f << 21)) ^
|
|
209
|
+
((f >>> 25) | (f << 7));
|
|
210
|
+
bc = b & c;
|
|
211
|
+
maj = bc ^ (b & d) ^ cd;
|
|
212
|
+
ch = (f & g) ^ (~f & h);
|
|
213
|
+
t1 = e + s1 + ch + K[j + 3] + blocks[j + 3];
|
|
214
|
+
t2 = s0 + maj;
|
|
215
|
+
e = (a + t1) << 0;
|
|
216
|
+
a = (t1 + t2) << 0;
|
|
217
|
+
this.chromeBugWorkAround = true;
|
|
218
|
+
}
|
|
219
|
+
this.h0 = (this.h0 + a) << 0;
|
|
220
|
+
this.h1 = (this.h1 + b) << 0;
|
|
221
|
+
this.h2 = (this.h2 + c) << 0;
|
|
222
|
+
this.h3 = (this.h3 + d) << 0;
|
|
223
|
+
this.h4 = (this.h4 + e) << 0;
|
|
224
|
+
this.h5 = (this.h5 + f) << 0;
|
|
225
|
+
this.h6 = (this.h6 + g) << 0;
|
|
226
|
+
this.h7 = (this.h7 + h) << 0;
|
|
227
|
+
}
|
|
228
|
+
finalize() {
|
|
229
|
+
if (this.finalized) {
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
this.finalized = true;
|
|
233
|
+
const blocks = this.blocks, i = this.lastByteIndex;
|
|
234
|
+
blocks[16] = this.block;
|
|
235
|
+
blocks[i >>> 2] |= EXTRA[i & 3];
|
|
236
|
+
this.block = blocks[16];
|
|
237
|
+
if (i >= 56) {
|
|
238
|
+
if (!this.hashed) {
|
|
239
|
+
this.hash();
|
|
240
|
+
}
|
|
241
|
+
blocks[0] = this.block;
|
|
242
|
+
blocks[16] =
|
|
243
|
+
blocks[1] =
|
|
244
|
+
blocks[2] =
|
|
245
|
+
blocks[3] =
|
|
246
|
+
blocks[4] =
|
|
247
|
+
blocks[5] =
|
|
248
|
+
blocks[6] =
|
|
249
|
+
blocks[7] =
|
|
250
|
+
blocks[8] =
|
|
251
|
+
blocks[9] =
|
|
252
|
+
blocks[10] =
|
|
253
|
+
blocks[11] =
|
|
254
|
+
blocks[12] =
|
|
255
|
+
blocks[13] =
|
|
256
|
+
blocks[14] =
|
|
257
|
+
blocks[15] =
|
|
258
|
+
0;
|
|
259
|
+
}
|
|
260
|
+
blocks[14] = (this.hBytes << 3) | (this.bytes >>> 29);
|
|
261
|
+
blocks[15] = this.bytes << 3;
|
|
262
|
+
this.hash();
|
|
263
|
+
}
|
|
264
|
+
arrayBuffer() {
|
|
265
|
+
this.finalize();
|
|
266
|
+
const buffer = new ArrayBuffer(32);
|
|
267
|
+
const dataView = new DataView(buffer);
|
|
268
|
+
dataView.setUint32(0, this.h0);
|
|
269
|
+
dataView.setUint32(4, this.h1);
|
|
270
|
+
dataView.setUint32(8, this.h2);
|
|
271
|
+
dataView.setUint32(12, this.h3);
|
|
272
|
+
dataView.setUint32(16, this.h4);
|
|
273
|
+
dataView.setUint32(20, this.h5);
|
|
274
|
+
dataView.setUint32(24, this.h6);
|
|
275
|
+
dataView.setUint32(28, this.h7);
|
|
276
|
+
return buffer;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
function sha256(message) {
|
|
280
|
+
return new SHA256().update(message).arrayBuffer();
|
|
281
|
+
}
|
|
282
|
+
exports.sha256 = sha256;
|
|
@@ -2,4 +2,4 @@ import { BuildRESTFunction, PublicMetadata, RESTFunctionDescriptor } from '@wix/
|
|
|
2
2
|
export type RESTModuleOptions = {
|
|
3
3
|
HTTPHost?: string;
|
|
4
4
|
};
|
|
5
|
-
export declare function buildRESTDescriptor<T extends RESTFunctionDescriptor>(origFunc: T, publicMetadata: PublicMetadata, boundFetch: typeof fetch, wixAPIFetch: (relativeUrl: string, options: RequestInit) => Promise<Response>, options?: RESTModuleOptions): BuildRESTFunction<T>;
|
|
5
|
+
export declare function buildRESTDescriptor<T extends RESTFunctionDescriptor>(origFunc: T, publicMetadata: PublicMetadata, boundFetch: typeof fetch, wixAPIFetch: (relativeUrl: string, options: RequestInit) => Promise<Response>, getActiveToken?: () => string | undefined, options?: RESTModuleOptions): BuildRESTFunction<T>;
|
|
@@ -4,7 +4,7 @@ exports.buildRESTDescriptor = void 0;
|
|
|
4
4
|
const biHeaderGenerator_js_1 = require("./bi/biHeaderGenerator.js");
|
|
5
5
|
const common_js_1 = require("./common.js");
|
|
6
6
|
const context_1 = require("@wix/sdk-runtime/context");
|
|
7
|
-
function buildRESTDescriptor(origFunc, publicMetadata, boundFetch, wixAPIFetch, options) {
|
|
7
|
+
function buildRESTDescriptor(origFunc, publicMetadata, boundFetch, wixAPIFetch, getActiveToken, options) {
|
|
8
8
|
return (0, context_1.runWithoutContext)(() => origFunc({
|
|
9
9
|
request: async (factory) => {
|
|
10
10
|
const requestOptions = factory({
|
|
@@ -62,6 +62,7 @@ function buildRESTDescriptor(origFunc, publicMetadata, boundFetch, wixAPIFetch,
|
|
|
62
62
|
},
|
|
63
63
|
fetchWithAuth: boundFetch,
|
|
64
64
|
wixAPIFetch,
|
|
65
|
+
getActiveToken,
|
|
65
66
|
}));
|
|
66
67
|
}
|
|
67
68
|
exports.buildRESTDescriptor = buildRESTDescriptor;
|
package/cjs/build/wixClient.js
CHANGED
|
@@ -63,7 +63,7 @@ function createClient(config) {
|
|
|
63
63
|
finalUrl.host = apiBaseUrl;
|
|
64
64
|
finalUrl.protocol = 'https';
|
|
65
65
|
return boundFetch(finalUrl.toString(), fetchOptions);
|
|
66
|
-
}, { HTTPHost: apiBaseUrl });
|
|
66
|
+
}, authStrategy.getActiveToken, { HTTPHost: apiBaseUrl });
|
|
67
67
|
}
|
|
68
68
|
else if ((0, helpers_js_1.isObject)(modules)) {
|
|
69
69
|
return Object.fromEntries(Object.entries(modules).map(([key, value]) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wix/sdk",
|
|
3
|
-
"version": "1.12.
|
|
3
|
+
"version": "1.12.14",
|
|
4
4
|
"license": "UNLICENSED",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Ronny Ringel",
|
|
@@ -65,14 +65,12 @@
|
|
|
65
65
|
"dependencies": {
|
|
66
66
|
"@babel/runtime": "^7.23.2",
|
|
67
67
|
"@wix/identity": "^1.0.78",
|
|
68
|
-
"@wix/image-kit": "^1.
|
|
68
|
+
"@wix/image-kit": "^1.83.0",
|
|
69
69
|
"@wix/redirects": "^1.0.41",
|
|
70
70
|
"@wix/sdk-context": "^0.0.1",
|
|
71
|
-
"@wix/sdk-runtime": "0.3.
|
|
72
|
-
"@wix/sdk-types": "^1.
|
|
73
|
-
"crypto-js": "^4.2.0",
|
|
71
|
+
"@wix/sdk-runtime": "0.3.19",
|
|
72
|
+
"@wix/sdk-types": "^1.12.0",
|
|
74
73
|
"jose": "^5.2.1",
|
|
75
|
-
"pkce-challenge": "^3.1.0",
|
|
76
74
|
"querystring": "^0.2.1",
|
|
77
75
|
"type-fest": "^4.9.0"
|
|
78
76
|
},
|
|
@@ -80,7 +78,6 @@
|
|
|
80
78
|
"graphql": "^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0"
|
|
81
79
|
},
|
|
82
80
|
"devDependencies": {
|
|
83
|
-
"@types/crypto-js": "^4.2.1",
|
|
84
81
|
"@types/is-ci": "^3.0.4",
|
|
85
82
|
"@types/node": "^20.10.6",
|
|
86
83
|
"@vitest/ui": "^1.5.0",
|
|
@@ -88,13 +85,13 @@
|
|
|
88
85
|
"@wix/events": "^1.0.179",
|
|
89
86
|
"@wix/metro": "^1.0.73",
|
|
90
87
|
"@wix/metro-runtime": "^1.1677.0",
|
|
91
|
-
"@wix/sdk-runtime": "0.3.
|
|
88
|
+
"@wix/sdk-runtime": "0.3.19",
|
|
92
89
|
"eslint": "^8.56.0",
|
|
93
90
|
"eslint-config-sdk": "0.0.0",
|
|
94
91
|
"graphql": "^16.8.0",
|
|
95
92
|
"is-ci": "^3.0.1",
|
|
96
93
|
"jsdom": "^22.1.0",
|
|
97
|
-
"msw": "^2.
|
|
94
|
+
"msw": "^2.4.5",
|
|
98
95
|
"typescript": "^5.3.3",
|
|
99
96
|
"vitest": "^1.5.0",
|
|
100
97
|
"vitest-teamcity-reporter": "^0.3.0"
|
|
@@ -122,5 +119,5 @@
|
|
|
122
119
|
"wallaby": {
|
|
123
120
|
"autoDetect": true
|
|
124
121
|
},
|
|
125
|
-
"falconPackageHash": "
|
|
122
|
+
"falconPackageHash": "b3311f3e856f7fda5bd9d3d658ebffaf428cb466a862d8223dfd6842"
|
|
126
123
|
}
|