@01.software/sdk 0.7.1 → 0.9.0
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/README.md +54 -18
- package/dist/const-DZ04SC2y.d.cts +19 -0
- package/dist/const-hXu9oG66.d.ts +19 -0
- package/dist/index.cjs +57 -180
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +47 -64
- package/dist/index.d.ts +47 -64
- package/dist/index.js +57 -180
- package/dist/index.js.map +1 -1
- package/dist/{payload-types-Cp10MoF6.d.cts → payload-types-DICC2-Zr.d.cts} +916 -475
- package/dist/{payload-types-Cp10MoF6.d.ts → payload-types-DICC2-Zr.d.ts} +916 -475
- package/dist/{realtime-DupPIYx-.d.cts → realtime-D7HtUpqt.d.cts} +2 -2
- package/dist/{realtime-DupPIYx-.d.ts → realtime-D7HtUpqt.d.ts} +2 -2
- package/dist/realtime.cjs +8 -7
- package/dist/realtime.cjs.map +1 -1
- package/dist/realtime.d.cts +6 -6
- package/dist/realtime.d.ts +6 -6
- package/dist/realtime.js +8 -7
- package/dist/realtime.js.map +1 -1
- package/dist/{server-DxhuG-_s.d.cts → server-JR9TvKZ5.d.cts} +0 -2
- package/dist/{server-DxhuG-_s.d.ts → server-JR9TvKZ5.d.ts} +0 -2
- package/dist/ui/canvas/server.cjs +1 -2
- package/dist/ui/canvas/server.cjs.map +1 -1
- package/dist/ui/canvas/server.d.cts +1 -1
- package/dist/ui/canvas/server.d.ts +1 -1
- package/dist/ui/canvas/server.js +1 -2
- package/dist/ui/canvas/server.js.map +1 -1
- package/dist/ui/canvas.cjs +1 -2
- package/dist/ui/canvas.cjs.map +1 -1
- package/dist/ui/canvas.d.cts +2 -2
- package/dist/ui/canvas.d.ts +2 -2
- package/dist/ui/canvas.js +1 -2
- package/dist/ui/canvas.js.map +1 -1
- package/dist/ui/form.d.cts +1 -1
- package/dist/ui/form.d.ts +1 -1
- package/dist/ui/video.cjs +1 -1
- package/dist/ui/video.cjs.map +1 -1
- package/dist/ui/video.d.cts +1 -1
- package/dist/ui/video.d.ts +1 -1
- package/dist/ui/video.js +1 -1
- package/dist/ui/video.js.map +1 -1
- package/dist/{webhook-BKhMTlFN.d.ts → webhook-BD9ivfyR.d.ts} +2 -2
- package/dist/{webhook-CiWsseVz.d.cts → webhook-D8ogsafv.d.cts} +2 -2
- package/dist/webhook.d.cts +3 -3
- package/dist/webhook.d.ts +3 -3
- package/package.json +1 -11
- package/dist/auth.cjs +0 -109
- package/dist/auth.cjs.map +0 -1
- package/dist/auth.d.cts +0 -36
- package/dist/auth.d.ts +0 -36
- package/dist/auth.js +0 -86
- package/dist/auth.js.map +0 -1
- package/dist/const-B8iE-mDN.d.cts +0 -19
- package/dist/const-Chw71pKS.d.ts +0 -19
package/dist/index.js
CHANGED
|
@@ -1,82 +1,3 @@
|
|
|
1
|
-
// src/core/internal/utils/jwt.ts
|
|
2
|
-
import { SignJWT, jwtVerify, decodeJwt } from "jose";
|
|
3
|
-
async function createServerToken(clientKey, secretKey, expiresIn = "1h") {
|
|
4
|
-
if (!clientKey || !secretKey) {
|
|
5
|
-
throw new Error("clientKey and secretKey are required.");
|
|
6
|
-
}
|
|
7
|
-
const secret = new TextEncoder().encode(secretKey);
|
|
8
|
-
return new SignJWT({ clientKey }).setProtectedHeader({ alg: "HS256" }).setIssuedAt().setExpirationTime(expiresIn).sign(secret);
|
|
9
|
-
}
|
|
10
|
-
async function verifyServerToken(token, secretKey) {
|
|
11
|
-
if (!token || !secretKey) {
|
|
12
|
-
throw new Error("token and secretKey are required.");
|
|
13
|
-
}
|
|
14
|
-
const secret = new TextEncoder().encode(secretKey);
|
|
15
|
-
const { payload } = await jwtVerify(token, secret, {
|
|
16
|
-
algorithms: ["HS256"]
|
|
17
|
-
});
|
|
18
|
-
if (!payload.clientKey || typeof payload.clientKey !== "string") {
|
|
19
|
-
throw new Error("Invalid token payload: clientKey is missing");
|
|
20
|
-
}
|
|
21
|
-
return {
|
|
22
|
-
clientKey: payload.clientKey,
|
|
23
|
-
iat: payload.iat,
|
|
24
|
-
exp: payload.exp
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
function decodeServerToken(token) {
|
|
28
|
-
if (!token) {
|
|
29
|
-
throw new Error("token is required.");
|
|
30
|
-
}
|
|
31
|
-
const payload = decodeJwt(token);
|
|
32
|
-
if (!payload.clientKey || typeof payload.clientKey !== "string") {
|
|
33
|
-
throw new Error("Invalid token payload: clientKey is missing");
|
|
34
|
-
}
|
|
35
|
-
return {
|
|
36
|
-
clientKey: payload.clientKey,
|
|
37
|
-
iat: payload.iat,
|
|
38
|
-
exp: payload.exp
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// src/core/internal/utils/encoding.ts
|
|
43
|
-
function createApiKey(clientKey, secretKey) {
|
|
44
|
-
if (!clientKey || !secretKey) {
|
|
45
|
-
throw new Error("clientKey and secretKey are required.");
|
|
46
|
-
}
|
|
47
|
-
if (typeof Buffer !== "undefined") {
|
|
48
|
-
return Buffer.from(`${clientKey}:${secretKey}`).toString("base64");
|
|
49
|
-
}
|
|
50
|
-
return btoa(`${clientKey}:${secretKey}`);
|
|
51
|
-
}
|
|
52
|
-
function parseApiKey(apiKey) {
|
|
53
|
-
if (!apiKey) {
|
|
54
|
-
throw new Error("apiKey is required.");
|
|
55
|
-
}
|
|
56
|
-
try {
|
|
57
|
-
let decoded;
|
|
58
|
-
if (typeof Buffer !== "undefined") {
|
|
59
|
-
decoded = Buffer.from(apiKey, "base64").toString("utf-8");
|
|
60
|
-
} else {
|
|
61
|
-
decoded = atob(apiKey);
|
|
62
|
-
}
|
|
63
|
-
const colonIndex = decoded.indexOf(":");
|
|
64
|
-
if (colonIndex === -1) {
|
|
65
|
-
throw new Error("Invalid format: missing colon separator");
|
|
66
|
-
}
|
|
67
|
-
const clientKey = decoded.substring(0, colonIndex);
|
|
68
|
-
const secretKey = decoded.substring(colonIndex + 1);
|
|
69
|
-
if (!clientKey || !secretKey) {
|
|
70
|
-
throw new Error("Invalid format: empty clientKey or secretKey");
|
|
71
|
-
}
|
|
72
|
-
return { clientKey, secretKey };
|
|
73
|
-
} catch {
|
|
74
|
-
throw new Error(
|
|
75
|
-
'Invalid API key. Expected Base64 encoded "clientKey:secretKey"'
|
|
76
|
-
);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
1
|
// src/core/internal/errors/index.ts
|
|
81
2
|
var SDKError = class extends Error {
|
|
82
3
|
constructor(code, message, status, details, userMessage, suggestion) {
|
|
@@ -197,7 +118,6 @@ function isUsageLimitError(error) {
|
|
|
197
118
|
return error instanceof UsageLimitError;
|
|
198
119
|
}
|
|
199
120
|
var createNetworkError = (message, status, details, userMessage, suggestion) => new NetworkError(message, status, details, userMessage, suggestion);
|
|
200
|
-
var createValidationError = (message, details, userMessage, suggestion) => new ValidationError(message, details, userMessage, suggestion);
|
|
201
121
|
var createApiError = (message, status, details, userMessage, suggestion) => new ApiError(message, status, details, userMessage, suggestion);
|
|
202
122
|
var createConfigError = (message, details, userMessage, suggestion) => new ConfigError(message, details, userMessage, suggestion);
|
|
203
123
|
var createTimeoutError = (message, details, userMessage, suggestion) => new TimeoutError(message, details, userMessage, suggestion);
|
|
@@ -291,24 +211,24 @@ async function delay(ms) {
|
|
|
291
211
|
}
|
|
292
212
|
async function httpFetch(url, options) {
|
|
293
213
|
const {
|
|
294
|
-
|
|
214
|
+
publishableKey,
|
|
295
215
|
secretKey,
|
|
296
216
|
customerToken,
|
|
297
217
|
timeout = DEFAULT_TIMEOUT,
|
|
298
|
-
baseUrl = resolveApiUrl(),
|
|
299
218
|
debug,
|
|
300
219
|
retry,
|
|
301
220
|
onUnauthorized,
|
|
302
221
|
...requestInit
|
|
303
222
|
} = options || {};
|
|
223
|
+
const baseUrl = resolveApiUrl();
|
|
304
224
|
const retryConfig = {
|
|
305
225
|
maxRetries: retry?.maxRetries ?? 3,
|
|
306
226
|
retryableStatuses: retry?.retryableStatuses ?? DEFAULT_RETRYABLE_STATUSES,
|
|
307
227
|
retryDelay: retry?.retryDelay ?? ((attempt) => Math.min(1e3 * 2 ** attempt, 1e4))
|
|
308
228
|
};
|
|
309
229
|
let authToken;
|
|
310
|
-
if (secretKey
|
|
311
|
-
authToken =
|
|
230
|
+
if (secretKey) {
|
|
231
|
+
authToken = secretKey;
|
|
312
232
|
} else if (customerToken) {
|
|
313
233
|
authToken = customerToken;
|
|
314
234
|
}
|
|
@@ -317,8 +237,8 @@ async function httpFetch(url, options) {
|
|
|
317
237
|
for (let attempt = 0; attempt <= retryConfig.maxRetries; attempt++) {
|
|
318
238
|
try {
|
|
319
239
|
const headers = new Headers(requestInit.headers);
|
|
320
|
-
if (
|
|
321
|
-
headers.set("X-
|
|
240
|
+
if (publishableKey) {
|
|
241
|
+
headers.set("X-Publishable-Key", publishableKey);
|
|
322
242
|
}
|
|
323
243
|
if (authToken) {
|
|
324
244
|
headers.set("Authorization", `Bearer ${authToken}`);
|
|
@@ -509,23 +429,18 @@ async function parseApiResponse(response, endpoint) {
|
|
|
509
429
|
// src/core/api/base-api.ts
|
|
510
430
|
var BaseApi = class {
|
|
511
431
|
constructor(apiName, options) {
|
|
512
|
-
if (!options.clientKey) {
|
|
513
|
-
throw createConfigError(`clientKey is required for ${apiName}.`);
|
|
514
|
-
}
|
|
515
432
|
if (!options.secretKey) {
|
|
516
433
|
throw createConfigError(`secretKey is required for ${apiName}.`);
|
|
517
434
|
}
|
|
518
|
-
this.
|
|
435
|
+
this.publishableKey = options.publishableKey ?? "";
|
|
519
436
|
this.secretKey = options.secretKey;
|
|
520
|
-
this.baseUrl = options.baseUrl;
|
|
521
437
|
}
|
|
522
438
|
async request(endpoint, body, options) {
|
|
523
439
|
const method = options?.method ?? "POST";
|
|
524
440
|
const response = await httpFetch(endpoint, {
|
|
525
441
|
method,
|
|
526
|
-
|
|
442
|
+
publishableKey: this.publishableKey,
|
|
527
443
|
secretKey: this.secretKey,
|
|
528
|
-
baseUrl: this.baseUrl,
|
|
529
444
|
...body !== void 0 && { body: JSON.stringify(body) },
|
|
530
445
|
...options?.headers && { headers: options.headers }
|
|
531
446
|
});
|
|
@@ -583,39 +498,28 @@ var OrderApi = class extends BaseApi {
|
|
|
583
498
|
params
|
|
584
499
|
);
|
|
585
500
|
}
|
|
586
|
-
createExchange(params) {
|
|
587
|
-
return this.request("/api/exchanges/create", params);
|
|
588
|
-
}
|
|
589
|
-
updateExchange(params) {
|
|
590
|
-
return this.request("/api/exchanges/update", params);
|
|
591
|
-
}
|
|
592
501
|
};
|
|
593
502
|
|
|
594
503
|
// src/core/api/cart-api.ts
|
|
595
504
|
var CartApi = class {
|
|
596
505
|
constructor(options) {
|
|
597
|
-
if (!options.clientKey) {
|
|
598
|
-
throw createConfigError("clientKey is required for CartApi.");
|
|
599
|
-
}
|
|
600
506
|
if (!options.secretKey && !options.customerToken) {
|
|
601
507
|
throw createConfigError(
|
|
602
508
|
"Either secretKey or customerToken is required for CartApi."
|
|
603
509
|
);
|
|
604
510
|
}
|
|
605
|
-
this.
|
|
511
|
+
this.publishableKey = options.publishableKey ?? "";
|
|
606
512
|
this.secretKey = options.secretKey;
|
|
607
513
|
this.customerToken = options.customerToken;
|
|
608
|
-
this.baseUrl = options.baseUrl;
|
|
609
514
|
this.onUnauthorized = options.onUnauthorized;
|
|
610
515
|
}
|
|
611
516
|
async execute(endpoint, method, body) {
|
|
612
517
|
const token = typeof this.customerToken === "function" ? this.customerToken() : this.customerToken;
|
|
613
518
|
const response = await httpFetch(endpoint, {
|
|
614
519
|
method,
|
|
615
|
-
|
|
520
|
+
publishableKey: this.publishableKey,
|
|
616
521
|
secretKey: this.secretKey,
|
|
617
522
|
customerToken: token ?? void 0,
|
|
618
|
-
baseUrl: this.baseUrl,
|
|
619
523
|
...token && this.onUnauthorized && { onUnauthorized: this.onUnauthorized },
|
|
620
524
|
...body !== void 0 && { body: JSON.stringify(body) }
|
|
621
525
|
});
|
|
@@ -862,21 +766,16 @@ var CollectionQueryBuilder = class {
|
|
|
862
766
|
// src/core/collection/http-client.ts
|
|
863
767
|
import { stringify } from "qs-esm";
|
|
864
768
|
var HttpClient = class {
|
|
865
|
-
constructor(
|
|
866
|
-
|
|
867
|
-
throw createValidationError("clientKey is required.");
|
|
868
|
-
}
|
|
869
|
-
this.clientKey = clientKey;
|
|
769
|
+
constructor(publishableKey, secretKey, getCustomerToken, onUnauthorized) {
|
|
770
|
+
this.publishableKey = publishableKey;
|
|
870
771
|
this.secretKey = secretKey;
|
|
871
|
-
this.baseUrl = baseUrl;
|
|
872
772
|
this.getCustomerToken = getCustomerToken;
|
|
873
773
|
this.onUnauthorized = onUnauthorized;
|
|
874
774
|
}
|
|
875
775
|
get defaultOptions() {
|
|
876
776
|
const opts = {
|
|
877
|
-
|
|
878
|
-
secretKey: this.secretKey
|
|
879
|
-
baseUrl: this.baseUrl
|
|
777
|
+
publishableKey: this.publishableKey,
|
|
778
|
+
secretKey: this.secretKey
|
|
880
779
|
};
|
|
881
780
|
const token = this.getCustomerToken?.();
|
|
882
781
|
if (token) {
|
|
@@ -991,9 +890,6 @@ function buildPayloadFormData(data, file, filename) {
|
|
|
991
890
|
return formData;
|
|
992
891
|
}
|
|
993
892
|
var CollectionClient = class extends HttpClient {
|
|
994
|
-
constructor(clientKey, secretKey, baseUrl, getCustomerToken, onUnauthorized) {
|
|
995
|
-
super(clientKey, secretKey, baseUrl, getCustomerToken, onUnauthorized);
|
|
996
|
-
}
|
|
997
893
|
from(collection) {
|
|
998
894
|
return new CollectionQueryBuilder(this, collection);
|
|
999
895
|
}
|
|
@@ -1129,17 +1025,16 @@ var COLLECTIONS = [
|
|
|
1129
1025
|
"products",
|
|
1130
1026
|
"product-variants",
|
|
1131
1027
|
"product-options",
|
|
1028
|
+
"product-option-values",
|
|
1132
1029
|
"product-categories",
|
|
1133
1030
|
"product-tags",
|
|
1134
1031
|
"product-collections",
|
|
1135
1032
|
"brands",
|
|
1136
1033
|
"brand-logos",
|
|
1137
1034
|
"orders",
|
|
1138
|
-
"order-
|
|
1035
|
+
"order-items",
|
|
1139
1036
|
"returns",
|
|
1140
|
-
"return-
|
|
1141
|
-
"exchanges",
|
|
1142
|
-
"exchange-products",
|
|
1037
|
+
"return-items",
|
|
1143
1038
|
"fulfillments",
|
|
1144
1039
|
"fulfillment-items",
|
|
1145
1040
|
"transactions",
|
|
@@ -1196,23 +1091,18 @@ var COLLECTIONS = [
|
|
|
1196
1091
|
// src/core/community/community-client.ts
|
|
1197
1092
|
var CommunityClient = class {
|
|
1198
1093
|
constructor(options) {
|
|
1199
|
-
|
|
1200
|
-
throw createConfigError("clientKey is required for CommunityClient.");
|
|
1201
|
-
}
|
|
1202
|
-
this.clientKey = options.clientKey;
|
|
1094
|
+
this.publishableKey = options.publishableKey ?? "";
|
|
1203
1095
|
this.secretKey = options.secretKey;
|
|
1204
1096
|
this.customerToken = options.customerToken;
|
|
1205
|
-
this.baseUrl = options.baseUrl;
|
|
1206
1097
|
this.onUnauthorized = options.onUnauthorized;
|
|
1207
1098
|
}
|
|
1208
1099
|
async execute(endpoint, method, body) {
|
|
1209
1100
|
const token = typeof this.customerToken === "function" ? this.customerToken() : this.customerToken;
|
|
1210
1101
|
const response = await httpFetch(endpoint, {
|
|
1211
1102
|
method,
|
|
1212
|
-
|
|
1103
|
+
publishableKey: this.publishableKey,
|
|
1213
1104
|
secretKey: this.secretKey,
|
|
1214
1105
|
customerToken: token ?? void 0,
|
|
1215
|
-
baseUrl: this.baseUrl,
|
|
1216
1106
|
...token && this.onUnauthorized && { onUnauthorized: this.onUnauthorized },
|
|
1217
1107
|
...body !== void 0 && { body: JSON.stringify(body) }
|
|
1218
1108
|
});
|
|
@@ -1260,32 +1150,32 @@ var CommunityClient = class {
|
|
|
1260
1150
|
}
|
|
1261
1151
|
// Comments
|
|
1262
1152
|
createComment(params) {
|
|
1263
|
-
const { threadId, parentId,
|
|
1264
|
-
const body = { thread: threadId,
|
|
1153
|
+
const { threadId, parentId, body: commentBody } = params;
|
|
1154
|
+
const body = { thread: threadId, body: commentBody };
|
|
1265
1155
|
if (parentId !== void 0) {
|
|
1266
1156
|
body.parent = parentId;
|
|
1267
1157
|
}
|
|
1268
1158
|
return this.execute("/api/comments", "POST", body);
|
|
1269
1159
|
}
|
|
1270
1160
|
listComments(params) {
|
|
1271
|
-
const { threadId, page, limit,
|
|
1161
|
+
const { threadId, page, limit, rootComment } = params;
|
|
1272
1162
|
const urlParams = new URLSearchParams();
|
|
1273
1163
|
urlParams.set("where[thread][equals]", threadId);
|
|
1274
1164
|
urlParams.set("sort", "-createdAt");
|
|
1275
1165
|
if (limit !== void 0) urlParams.set("limit", String(limit));
|
|
1276
1166
|
if (page !== void 0) urlParams.set("page", String(page));
|
|
1277
|
-
if (
|
|
1167
|
+
if (rootComment !== void 0) urlParams.set("where[rootComment][equals]", rootComment);
|
|
1278
1168
|
return this.execute(
|
|
1279
1169
|
`/api/comments?${urlParams.toString()}`,
|
|
1280
1170
|
"GET"
|
|
1281
1171
|
);
|
|
1282
1172
|
}
|
|
1283
1173
|
updateComment(params) {
|
|
1284
|
-
const { commentId,
|
|
1174
|
+
const { commentId, body } = params;
|
|
1285
1175
|
return this.execute(
|
|
1286
1176
|
`/api/comments/${commentId}`,
|
|
1287
1177
|
"PATCH",
|
|
1288
|
-
{
|
|
1178
|
+
{ body }
|
|
1289
1179
|
);
|
|
1290
1180
|
}
|
|
1291
1181
|
deleteComment(params) {
|
|
@@ -1389,10 +1279,10 @@ function safeGetItem(key) {
|
|
|
1389
1279
|
}
|
|
1390
1280
|
}
|
|
1391
1281
|
var CustomerAuth = class {
|
|
1392
|
-
constructor(
|
|
1282
|
+
constructor(publishableKey, options) {
|
|
1393
1283
|
this.refreshPromise = null;
|
|
1394
|
-
this.
|
|
1395
|
-
this.baseUrl =
|
|
1284
|
+
this.publishableKey = publishableKey;
|
|
1285
|
+
this.baseUrl = resolveApiUrl();
|
|
1396
1286
|
const persist = options?.persist ?? true;
|
|
1397
1287
|
if (persist) {
|
|
1398
1288
|
const key = typeof persist === "string" ? persist : "customer-token";
|
|
@@ -1578,7 +1468,7 @@ var CustomerAuth = class {
|
|
|
1578
1468
|
*/
|
|
1579
1469
|
async requestJson(path, init) {
|
|
1580
1470
|
const headers = new Headers(init.headers);
|
|
1581
|
-
headers.set("X-
|
|
1471
|
+
headers.set("X-Publishable-Key", this.publishableKey);
|
|
1582
1472
|
if (!headers.has("Content-Type") && init.body) {
|
|
1583
1473
|
headers.set("Content-Type", "application/json");
|
|
1584
1474
|
}
|
|
@@ -2071,11 +1961,11 @@ var QueryHooks = class extends CollectionHooks {
|
|
|
2071
1961
|
// src/core/client/client.ts
|
|
2072
1962
|
var Client = class {
|
|
2073
1963
|
constructor(options) {
|
|
2074
|
-
|
|
2075
|
-
|
|
1964
|
+
const publishableKey = options.publishableKey;
|
|
1965
|
+
if (!publishableKey) {
|
|
1966
|
+
throw createConfigError("publishableKey is required.");
|
|
2076
1967
|
}
|
|
2077
|
-
this.config = { ...options };
|
|
2078
|
-
this.baseUrl = resolveApiUrl();
|
|
1968
|
+
this.config = { ...options, publishableKey };
|
|
2079
1969
|
const metadata = {
|
|
2080
1970
|
timestamp: Date.now(),
|
|
2081
1971
|
userAgent: typeof window !== "undefined" ? window.navigator?.userAgent : "Node.js"
|
|
@@ -2083,8 +1973,7 @@ var Client = class {
|
|
|
2083
1973
|
this.state = { metadata };
|
|
2084
1974
|
this.queryClient = getQueryClient();
|
|
2085
1975
|
this.customer = new CustomerAuth(
|
|
2086
|
-
this.config.
|
|
2087
|
-
this.baseUrl,
|
|
1976
|
+
this.config.publishableKey,
|
|
2088
1977
|
options.customer
|
|
2089
1978
|
);
|
|
2090
1979
|
const onUnauthorized = async () => {
|
|
@@ -2096,21 +1985,18 @@ var Client = class {
|
|
|
2096
1985
|
}
|
|
2097
1986
|
};
|
|
2098
1987
|
this.cart = new CartApi({
|
|
2099
|
-
|
|
1988
|
+
publishableKey: this.config.publishableKey,
|
|
2100
1989
|
customerToken: () => this.customer.getToken(),
|
|
2101
|
-
baseUrl: this.baseUrl,
|
|
2102
1990
|
onUnauthorized
|
|
2103
1991
|
});
|
|
2104
1992
|
this.community = new CommunityClient({
|
|
2105
|
-
|
|
1993
|
+
publishableKey: this.config.publishableKey,
|
|
2106
1994
|
customerToken: () => this.customer.getToken(),
|
|
2107
|
-
baseUrl: this.baseUrl,
|
|
2108
1995
|
onUnauthorized
|
|
2109
1996
|
});
|
|
2110
1997
|
this.collections = new CollectionClient(
|
|
2111
|
-
this.config.
|
|
1998
|
+
this.config.publishableKey,
|
|
2112
1999
|
void 0,
|
|
2113
|
-
this.baseUrl,
|
|
2114
2000
|
() => this.customer.getToken(),
|
|
2115
2001
|
onUnauthorized
|
|
2116
2002
|
);
|
|
@@ -2142,43 +2028,39 @@ var ServerClient = class {
|
|
|
2142
2028
|
"ServerClient must not be used in a browser environment. This risks exposing your secretKey in client bundles. Use createClient() for browser code instead."
|
|
2143
2029
|
);
|
|
2144
2030
|
}
|
|
2145
|
-
if (!options.clientKey) {
|
|
2146
|
-
throw createConfigError("clientKey is required.");
|
|
2147
|
-
}
|
|
2148
2031
|
if (!options.secretKey) {
|
|
2149
2032
|
throw createConfigError("secretKey is required.");
|
|
2150
2033
|
}
|
|
2151
|
-
|
|
2152
|
-
|
|
2034
|
+
if (!options.publishableKey) {
|
|
2035
|
+
throw createConfigError(
|
|
2036
|
+
"publishableKey is required. It is used for rate limiting and monthly quota enforcement via the X-Publishable-Key header. Get it from Console > Settings > API Keys."
|
|
2037
|
+
);
|
|
2038
|
+
}
|
|
2039
|
+
this.config = { ...options, publishableKey: options.publishableKey };
|
|
2153
2040
|
const metadata = {
|
|
2154
2041
|
timestamp: Date.now(),
|
|
2155
2042
|
userAgent: "Node.js"
|
|
2156
2043
|
};
|
|
2157
2044
|
this.state = { metadata };
|
|
2158
2045
|
this.api = new OrderApi({
|
|
2159
|
-
|
|
2160
|
-
secretKey: this.config.secretKey
|
|
2161
|
-
baseUrl: this.baseUrl
|
|
2046
|
+
publishableKey: this.config.publishableKey,
|
|
2047
|
+
secretKey: this.config.secretKey
|
|
2162
2048
|
});
|
|
2163
2049
|
this.cart = new CartApi({
|
|
2164
|
-
|
|
2165
|
-
secretKey: this.config.secretKey
|
|
2166
|
-
baseUrl: this.baseUrl
|
|
2050
|
+
publishableKey: this.config.publishableKey,
|
|
2051
|
+
secretKey: this.config.secretKey
|
|
2167
2052
|
});
|
|
2168
2053
|
this.community = new CommunityClient({
|
|
2169
|
-
|
|
2170
|
-
secretKey: this.config.secretKey
|
|
2171
|
-
baseUrl: this.baseUrl
|
|
2054
|
+
publishableKey: this.config.publishableKey,
|
|
2055
|
+
secretKey: this.config.secretKey
|
|
2172
2056
|
});
|
|
2173
2057
|
this.product = new ProductApi({
|
|
2174
|
-
|
|
2175
|
-
secretKey: this.config.secretKey
|
|
2176
|
-
baseUrl: this.baseUrl
|
|
2058
|
+
publishableKey: this.config.publishableKey,
|
|
2059
|
+
secretKey: this.config.secretKey
|
|
2177
2060
|
});
|
|
2178
2061
|
this.collections = new CollectionClient(
|
|
2179
|
-
this.config.
|
|
2180
|
-
this.config.secretKey
|
|
2181
|
-
this.baseUrl
|
|
2062
|
+
this.config.publishableKey,
|
|
2063
|
+
this.config.secretKey
|
|
2182
2064
|
);
|
|
2183
2065
|
this.queryClient = getQueryClient();
|
|
2184
2066
|
this.query = new QueryHooks(this.queryClient, this.collections);
|
|
@@ -2204,9 +2086,9 @@ var MAX_RECONNECT_DELAY = 3e4;
|
|
|
2204
2086
|
var RECONNECT_BACKOFF_FACTOR = 2;
|
|
2205
2087
|
var MAX_NO_TOKEN_RETRIES = 5;
|
|
2206
2088
|
var RealtimeConnection = class {
|
|
2207
|
-
constructor(baseUrl,
|
|
2089
|
+
constructor(baseUrl, publishableKey, getToken, collections) {
|
|
2208
2090
|
this.baseUrl = baseUrl;
|
|
2209
|
-
this.
|
|
2091
|
+
this.publishableKey = publishableKey;
|
|
2210
2092
|
this.getToken = getToken;
|
|
2211
2093
|
this.collections = collections;
|
|
2212
2094
|
this.abortController = null;
|
|
@@ -2259,7 +2141,7 @@ var RealtimeConnection = class {
|
|
|
2259
2141
|
try {
|
|
2260
2142
|
const response = await fetch(url, {
|
|
2261
2143
|
headers: {
|
|
2262
|
-
"X-
|
|
2144
|
+
"X-Publishable-Key": this.publishableKey,
|
|
2263
2145
|
Authorization: `Bearer ${token}`
|
|
2264
2146
|
},
|
|
2265
2147
|
signal
|
|
@@ -2553,13 +2435,10 @@ export {
|
|
|
2553
2435
|
UsageLimitError,
|
|
2554
2436
|
ValidationError,
|
|
2555
2437
|
collectionKeys,
|
|
2556
|
-
createApiKey,
|
|
2557
2438
|
createClient,
|
|
2558
2439
|
createServerClient,
|
|
2559
|
-
createServerToken,
|
|
2560
2440
|
createTypedWebhookHandler,
|
|
2561
2441
|
customerKeys,
|
|
2562
|
-
decodeServerToken,
|
|
2563
2442
|
formatOrderName,
|
|
2564
2443
|
generateOrderNumber,
|
|
2565
2444
|
getImageLqip,
|
|
@@ -2584,8 +2463,6 @@ export {
|
|
|
2584
2463
|
isUsageLimitError,
|
|
2585
2464
|
isValidWebhookEvent,
|
|
2586
2465
|
isValidationError,
|
|
2587
|
-
|
|
2588
|
-
resolveRelation,
|
|
2589
|
-
verifyServerToken
|
|
2466
|
+
resolveRelation
|
|
2590
2467
|
};
|
|
2591
2468
|
//# sourceMappingURL=index.js.map
|