@wix/sdk 1.12.11 → 1.12.13
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/ambassador-modules.d.ts +0 -2
- package/build/ambassador-modules.js +0 -3
- package/build/auth/oauth2/OAuthStrategy.js +2 -2
- 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/common.d.ts +1 -2
- package/build/common.js +1 -2
- package/build/index.d.ts +1 -2
- package/build/index.js +1 -2
- package/build/rest-modules.d.ts +0 -1
- package/build/rest-modules.js +5 -4
- package/build/wixClient.js +14 -15
- package/cjs/build/ambassador-modules.d.ts +0 -2
- package/cjs/build/ambassador-modules.js +1 -5
- package/cjs/build/auth/oauth2/OAuthStrategy.js +1 -1
- 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/common.d.ts +1 -2
- package/cjs/build/common.js +2 -3
- package/cjs/build/index.d.ts +1 -2
- package/cjs/build/index.js +2 -4
- package/cjs/build/rest-modules.d.ts +0 -1
- package/cjs/build/rest-modules.js +5 -5
- package/cjs/build/wixClient.js +12 -13
- package/package.json +7 -10
|
@@ -1,5 +1,3 @@
|
|
|
1
1
|
import type { HttpClient as SDKHttpClient, AmbassadorFactory } from '@wix/sdk-types';
|
|
2
|
-
import { RESTModuleOptions } from './rest-modules.js';
|
|
3
2
|
export declare const toHTTPModule: <Request_1, Response_1>(factory: AmbassadorFactory<Request_1, Response_1>) => (httpClient: SDKHttpClient) => (payload: Request_1) => Promise<Response_1>;
|
|
4
|
-
export declare const ambassadorModuleOptions: () => RESTModuleOptions;
|
|
5
3
|
export declare const isAmbassadorModule: (module: any) => boolean;
|
|
@@ -73,9 +73,6 @@ export const toHTTPModule = (factory) => (httpClient) => async (payload) => {
|
|
|
73
73
|
throw e;
|
|
74
74
|
}
|
|
75
75
|
};
|
|
76
|
-
export const ambassadorModuleOptions = () => ({
|
|
77
|
-
HTTPHost: self.location.host,
|
|
78
|
-
});
|
|
79
76
|
/*
|
|
80
77
|
* Because of issues with tree-shaking, we cant really put static parameter on module.
|
|
81
78
|
* We still have check for __isAmbassador for backward compatibility
|
|
@@ -2,7 +2,7 @@ import { createClient } from '../../wixClient.js';
|
|
|
2
2
|
import { redirects } from '@wix/redirects';
|
|
3
3
|
import { createAccessToken, isTokenExpired } from '../../tokenHelpers.js';
|
|
4
4
|
import { authentication, recovery, verification } from '@wix/identity';
|
|
5
|
-
import {
|
|
5
|
+
import { DEFAULT_API_URL } from '../../common.js';
|
|
6
6
|
import { LoginState, TokenRole, } from './types.js';
|
|
7
7
|
import { addPostMessageListener, loadFrame } from '../../iframeUtils.js';
|
|
8
8
|
import { EMAIL_EXISTS, INVALID_CAPTCHA, INVALID_PASSWORD, MISSING_CAPTCHA, RESET_PASSWORD, } from './constants.js';
|
|
@@ -358,7 +358,7 @@ export function OAuthStrategy(config) {
|
|
|
358
358
|
};
|
|
359
359
|
}
|
|
360
360
|
const fetchTokens = async (payload, headers = {}) => {
|
|
361
|
-
const res = await fetch(`https://${
|
|
361
|
+
const res = await fetch(`https://${DEFAULT_API_URL}/oauth2/token`, {
|
|
362
362
|
method: 'POST',
|
|
363
363
|
body: JSON.stringify(payload),
|
|
364
364
|
headers: {
|
|
@@ -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/common.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
export declare const PUBLIC_METADATA_KEY = "__metadata";
|
|
2
|
-
export declare const
|
|
3
|
-
export declare const READ_ONLY_API_URL = "readonly.wixapis.com";
|
|
2
|
+
export declare const DEFAULT_API_URL = "www.wixapis.com";
|
|
4
3
|
export declare const FORCE_WRITE_API_URLS: string[];
|
package/build/common.js
CHANGED
package/build/index.d.ts
CHANGED
|
@@ -5,5 +5,4 @@ export * from './auth/oauth2/types.js';
|
|
|
5
5
|
export * from './auth/ApiKeyAuthStrategy.js';
|
|
6
6
|
export * from './auth/AppStrategy.js';
|
|
7
7
|
export * from '@wix/sdk-types';
|
|
8
|
-
export {
|
|
9
|
-
export { API_URL } from './common.js';
|
|
8
|
+
export { DEFAULT_API_URL } from './common.js';
|
package/build/index.js
CHANGED
|
@@ -5,5 +5,4 @@ export * from './auth/oauth2/types.js';
|
|
|
5
5
|
export * from './auth/ApiKeyAuthStrategy.js';
|
|
6
6
|
export * from './auth/AppStrategy.js';
|
|
7
7
|
export * from '@wix/sdk-types';
|
|
8
|
-
export {
|
|
9
|
-
export { API_URL } from './common.js';
|
|
8
|
+
export { DEFAULT_API_URL } from './common.js';
|
package/build/rest-modules.d.ts
CHANGED
|
@@ -2,5 +2,4 @@ import { BuildRESTFunction, PublicMetadata, RESTFunctionDescriptor } from '@wix/
|
|
|
2
2
|
export type RESTModuleOptions = {
|
|
3
3
|
HTTPHost?: string;
|
|
4
4
|
};
|
|
5
|
-
export declare const getDefaultDomain: (_method: string, _url: string) => string;
|
|
6
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>;
|
package/build/rest-modules.js
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
import { biHeaderGenerator } from './bi/biHeaderGenerator.js';
|
|
2
|
-
import {
|
|
2
|
+
import { DEFAULT_API_URL } from './common.js';
|
|
3
3
|
import { runWithoutContext } from '@wix/sdk-runtime/context';
|
|
4
|
-
export const getDefaultDomain = (_method, _url) => API_URL;
|
|
5
4
|
export function buildRESTDescriptor(origFunc, publicMetadata, boundFetch, wixAPIFetch, options) {
|
|
6
5
|
return runWithoutContext(() => origFunc({
|
|
7
6
|
request: async (factory) => {
|
|
8
|
-
const requestOptions = factory({
|
|
7
|
+
const requestOptions = factory({
|
|
8
|
+
host: options?.HTTPHost || DEFAULT_API_URL,
|
|
9
|
+
});
|
|
9
10
|
let request = requestOptions;
|
|
10
11
|
if (request.method === 'GET' &&
|
|
11
12
|
request.fallback?.length &&
|
|
12
13
|
request.params.toString().length > 4000) {
|
|
13
14
|
request = requestOptions.fallback[0];
|
|
14
15
|
}
|
|
15
|
-
const domain = options?.HTTPHost ??
|
|
16
|
+
const domain = options?.HTTPHost ?? DEFAULT_API_URL;
|
|
16
17
|
let url = `https://${domain}${request.url}`;
|
|
17
18
|
if (request.params && request.params.toString()) {
|
|
18
19
|
url += `?${request.params.toString()}`;
|
package/build/wixClient.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { wixContext } from '@wix/sdk-context';
|
|
2
2
|
import { SERVICE_PLUGIN_ERROR_TYPE, } from '@wix/sdk-types';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { isAmbassadorModule, toHTTPModule } from './ambassador-modules.js';
|
|
4
|
+
import { DEFAULT_API_URL, PUBLIC_METADATA_KEY } from './common.js';
|
|
5
5
|
import { FetchErrorResponse } from './fetch-error.js';
|
|
6
6
|
import { getDefaultContentHeader, isObject } from './helpers.js';
|
|
7
7
|
import { buildHostModule, isHostModule } from './host-modules.js';
|
|
@@ -52,18 +52,15 @@ export function createClient(config) {
|
|
|
52
52
|
if ('__type' in modules && modules.__type === SERVICE_PLUGIN_ERROR_TYPE) {
|
|
53
53
|
return modules;
|
|
54
54
|
}
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return buildRESTDescriptor(module, metadata ?? {}, boundFetch, (relativeUrl, fetchOptions) => {
|
|
62
|
-
const finalUrl = new URL(relativeUrl, `https://${API_URL}`);
|
|
63
|
-
finalUrl.host = API_URL;
|
|
55
|
+
const apiBaseUrl = config.host?.apiBaseUrl ?? DEFAULT_API_URL;
|
|
56
|
+
return buildRESTDescriptor(runWithoutContext(() => isAmbassadorModule(modules))
|
|
57
|
+
? toHTTPModule(modules)
|
|
58
|
+
: modules, metadata ?? {}, boundFetch, (relativeUrl, fetchOptions) => {
|
|
59
|
+
const finalUrl = new URL(relativeUrl, `https://${apiBaseUrl}`);
|
|
60
|
+
finalUrl.host = apiBaseUrl;
|
|
64
61
|
finalUrl.protocol = 'https';
|
|
65
62
|
return boundFetch(finalUrl.toString(), fetchOptions);
|
|
66
|
-
},
|
|
63
|
+
}, { HTTPHost: apiBaseUrl });
|
|
67
64
|
}
|
|
68
65
|
else if (isObject(modules)) {
|
|
69
66
|
return Object.fromEntries(Object.entries(modules).map(([key, value]) => {
|
|
@@ -116,8 +113,9 @@ export function createClient(config) {
|
|
|
116
113
|
}
|
|
117
114
|
},
|
|
118
115
|
fetch: (relativeUrl, options) => {
|
|
119
|
-
const
|
|
120
|
-
finalUrl
|
|
116
|
+
const apiBaseUrl = config.host?.apiBaseUrl ?? DEFAULT_API_URL;
|
|
117
|
+
const finalUrl = new URL(relativeUrl, `https://${apiBaseUrl}`);
|
|
118
|
+
finalUrl.host = apiBaseUrl;
|
|
121
119
|
finalUrl.protocol = 'https';
|
|
122
120
|
return boundFetch(finalUrl.toString(), options);
|
|
123
121
|
},
|
|
@@ -141,7 +139,8 @@ export function createClient(config) {
|
|
|
141
139
|
async graphql(query, variables, opts = {
|
|
142
140
|
apiVersion: 'alpha',
|
|
143
141
|
}) {
|
|
144
|
-
const
|
|
142
|
+
const apiBaseUrl = config?.host?.apiBaseUrl ?? DEFAULT_API_URL;
|
|
143
|
+
const res = await boundFetch(`https://${apiBaseUrl}/graphql/${opts.apiVersion}`, {
|
|
145
144
|
method: 'POST',
|
|
146
145
|
headers: {
|
|
147
146
|
'Content-Type': 'application/json',
|
|
@@ -1,5 +1,3 @@
|
|
|
1
1
|
import type { HttpClient as SDKHttpClient, AmbassadorFactory } from '@wix/sdk-types';
|
|
2
|
-
import { RESTModuleOptions } from './rest-modules.js';
|
|
3
2
|
export declare const toHTTPModule: <Request_1, Response_1>(factory: AmbassadorFactory<Request_1, Response_1>) => (httpClient: SDKHttpClient) => (payload: Request_1) => Promise<Response_1>;
|
|
4
|
-
export declare const ambassadorModuleOptions: () => RESTModuleOptions;
|
|
5
3
|
export declare const isAmbassadorModule: (module: any) => boolean;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isAmbassadorModule = exports.
|
|
3
|
+
exports.isAmbassadorModule = exports.toHTTPModule = void 0;
|
|
4
4
|
const parseMethod = (method) => {
|
|
5
5
|
switch (method) {
|
|
6
6
|
case 'get':
|
|
@@ -77,10 +77,6 @@ const toHTTPModule = (factory) => (httpClient) => async (payload) => {
|
|
|
77
77
|
}
|
|
78
78
|
};
|
|
79
79
|
exports.toHTTPModule = toHTTPModule;
|
|
80
|
-
const ambassadorModuleOptions = () => ({
|
|
81
|
-
HTTPHost: self.location.host,
|
|
82
|
-
});
|
|
83
|
-
exports.ambassadorModuleOptions = ambassadorModuleOptions;
|
|
84
80
|
/*
|
|
85
81
|
* Because of issues with tree-shaking, we cant really put static parameter on module.
|
|
86
82
|
* We still have check for __isAmbassador for backward compatibility
|
|
@@ -362,7 +362,7 @@ function OAuthStrategy(config) {
|
|
|
362
362
|
}
|
|
363
363
|
exports.OAuthStrategy = OAuthStrategy;
|
|
364
364
|
const fetchTokens = async (payload, headers = {}) => {
|
|
365
|
-
const res = await fetch(`https://${common_js_1.
|
|
365
|
+
const res = await fetch(`https://${common_js_1.DEFAULT_API_URL}/oauth2/token`, {
|
|
366
366
|
method: 'POST',
|
|
367
367
|
body: JSON.stringify(payload),
|
|
368
368
|
headers: {
|
|
@@ -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;
|
package/cjs/build/common.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
export declare const PUBLIC_METADATA_KEY = "__metadata";
|
|
2
|
-
export declare const
|
|
3
|
-
export declare const READ_ONLY_API_URL = "readonly.wixapis.com";
|
|
2
|
+
export declare const DEFAULT_API_URL = "www.wixapis.com";
|
|
4
3
|
export declare const FORCE_WRITE_API_URLS: string[];
|
package/cjs/build/common.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FORCE_WRITE_API_URLS = exports.
|
|
3
|
+
exports.FORCE_WRITE_API_URLS = exports.DEFAULT_API_URL = exports.PUBLIC_METADATA_KEY = void 0;
|
|
4
4
|
exports.PUBLIC_METADATA_KEY = '__metadata';
|
|
5
|
-
exports.
|
|
6
|
-
exports.READ_ONLY_API_URL = 'readonly.wixapis.com';
|
|
5
|
+
exports.DEFAULT_API_URL = 'www.wixapis.com';
|
|
7
6
|
exports.FORCE_WRITE_API_URLS = ['/ecom/v1/carts/current'];
|
package/cjs/build/index.d.ts
CHANGED
|
@@ -5,5 +5,4 @@ export * from './auth/oauth2/types.js';
|
|
|
5
5
|
export * from './auth/ApiKeyAuthStrategy.js';
|
|
6
6
|
export * from './auth/AppStrategy.js';
|
|
7
7
|
export * from '@wix/sdk-types';
|
|
8
|
-
export {
|
|
9
|
-
export { API_URL } from './common.js';
|
|
8
|
+
export { DEFAULT_API_URL } from './common.js';
|
package/cjs/build/index.js
CHANGED
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.
|
|
17
|
+
exports.DEFAULT_API_URL = void 0;
|
|
18
18
|
__exportStar(require("./wixClient.js"), exports);
|
|
19
19
|
__exportStar(require("./wixMedia.js"), exports);
|
|
20
20
|
__exportStar(require("./auth/oauth2/OAuthStrategy.js"), exports);
|
|
@@ -22,7 +22,5 @@ __exportStar(require("./auth/oauth2/types.js"), exports);
|
|
|
22
22
|
__exportStar(require("./auth/ApiKeyAuthStrategy.js"), exports);
|
|
23
23
|
__exportStar(require("./auth/AppStrategy.js"), exports);
|
|
24
24
|
__exportStar(require("@wix/sdk-types"), exports);
|
|
25
|
-
var rest_modules_js_1 = require("./rest-modules.js");
|
|
26
|
-
Object.defineProperty(exports, "getDefaultDomain", { enumerable: true, get: function () { return rest_modules_js_1.getDefaultDomain; } });
|
|
27
25
|
var common_js_1 = require("./common.js");
|
|
28
|
-
Object.defineProperty(exports, "
|
|
26
|
+
Object.defineProperty(exports, "DEFAULT_API_URL", { enumerable: true, get: function () { return common_js_1.DEFAULT_API_URL; } });
|
|
@@ -2,5 +2,4 @@ import { BuildRESTFunction, PublicMetadata, RESTFunctionDescriptor } from '@wix/
|
|
|
2
2
|
export type RESTModuleOptions = {
|
|
3
3
|
HTTPHost?: string;
|
|
4
4
|
};
|
|
5
|
-
export declare const getDefaultDomain: (_method: string, _url: string) => string;
|
|
6
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>;
|
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.buildRESTDescriptor =
|
|
3
|
+
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
|
-
const getDefaultDomain = (_method, _url) => common_js_1.API_URL;
|
|
8
|
-
exports.getDefaultDomain = getDefaultDomain;
|
|
9
7
|
function buildRESTDescriptor(origFunc, publicMetadata, boundFetch, wixAPIFetch, options) {
|
|
10
8
|
return (0, context_1.runWithoutContext)(() => origFunc({
|
|
11
9
|
request: async (factory) => {
|
|
12
|
-
const requestOptions = factory({
|
|
10
|
+
const requestOptions = factory({
|
|
11
|
+
host: options?.HTTPHost || common_js_1.DEFAULT_API_URL,
|
|
12
|
+
});
|
|
13
13
|
let request = requestOptions;
|
|
14
14
|
if (request.method === 'GET' &&
|
|
15
15
|
request.fallback?.length &&
|
|
16
16
|
request.params.toString().length > 4000) {
|
|
17
17
|
request = requestOptions.fallback[0];
|
|
18
18
|
}
|
|
19
|
-
const domain = options?.HTTPHost ??
|
|
19
|
+
const domain = options?.HTTPHost ?? common_js_1.DEFAULT_API_URL;
|
|
20
20
|
let url = `https://${domain}${request.url}`;
|
|
21
21
|
if (request.params && request.params.toString()) {
|
|
22
22
|
url += `?${request.params.toString()}`;
|
package/cjs/build/wixClient.js
CHANGED
|
@@ -55,18 +55,15 @@ function createClient(config) {
|
|
|
55
55
|
if ('__type' in modules && modules.__type === sdk_types_1.SERVICE_PLUGIN_ERROR_TYPE) {
|
|
56
56
|
return modules;
|
|
57
57
|
}
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
return (0, rest_modules_js_1.buildRESTDescriptor)(module, metadata ?? {}, boundFetch, (relativeUrl, fetchOptions) => {
|
|
65
|
-
const finalUrl = new URL(relativeUrl, `https://${common_js_1.API_URL}`);
|
|
66
|
-
finalUrl.host = common_js_1.API_URL;
|
|
58
|
+
const apiBaseUrl = config.host?.apiBaseUrl ?? common_js_1.DEFAULT_API_URL;
|
|
59
|
+
return (0, rest_modules_js_1.buildRESTDescriptor)((0, context_1.runWithoutContext)(() => (0, ambassador_modules_js_1.isAmbassadorModule)(modules))
|
|
60
|
+
? (0, ambassador_modules_js_1.toHTTPModule)(modules)
|
|
61
|
+
: modules, metadata ?? {}, boundFetch, (relativeUrl, fetchOptions) => {
|
|
62
|
+
const finalUrl = new URL(relativeUrl, `https://${apiBaseUrl}`);
|
|
63
|
+
finalUrl.host = apiBaseUrl;
|
|
67
64
|
finalUrl.protocol = 'https';
|
|
68
65
|
return boundFetch(finalUrl.toString(), fetchOptions);
|
|
69
|
-
},
|
|
66
|
+
}, { HTTPHost: apiBaseUrl });
|
|
70
67
|
}
|
|
71
68
|
else if ((0, helpers_js_1.isObject)(modules)) {
|
|
72
69
|
return Object.fromEntries(Object.entries(modules).map(([key, value]) => {
|
|
@@ -119,8 +116,9 @@ function createClient(config) {
|
|
|
119
116
|
}
|
|
120
117
|
},
|
|
121
118
|
fetch: (relativeUrl, options) => {
|
|
122
|
-
const
|
|
123
|
-
finalUrl
|
|
119
|
+
const apiBaseUrl = config.host?.apiBaseUrl ?? common_js_1.DEFAULT_API_URL;
|
|
120
|
+
const finalUrl = new URL(relativeUrl, `https://${apiBaseUrl}`);
|
|
121
|
+
finalUrl.host = apiBaseUrl;
|
|
124
122
|
finalUrl.protocol = 'https';
|
|
125
123
|
return boundFetch(finalUrl.toString(), options);
|
|
126
124
|
},
|
|
@@ -144,7 +142,8 @@ function createClient(config) {
|
|
|
144
142
|
async graphql(query, variables, opts = {
|
|
145
143
|
apiVersion: 'alpha',
|
|
146
144
|
}) {
|
|
147
|
-
const
|
|
145
|
+
const apiBaseUrl = config?.host?.apiBaseUrl ?? common_js_1.DEFAULT_API_URL;
|
|
146
|
+
const res = await boundFetch(`https://${apiBaseUrl}/graphql/${opts.apiVersion}`, {
|
|
148
147
|
method: 'POST',
|
|
149
148
|
headers: {
|
|
150
149
|
'Content-Type': 'application/json',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wix/sdk",
|
|
3
|
-
"version": "1.12.
|
|
3
|
+
"version": "1.12.13",
|
|
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.18",
|
|
72
|
+
"@wix/sdk-types": "^1.10.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.18",
|
|
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": "b1f56afb5f401e2aa11769c9e887f152fbce4bee17f7d7c651c43a30"
|
|
126
123
|
}
|