@01.software/sdk 0.2.9-dev.260311.926a6d4 → 0.2.9-dev.260312.8c43a16
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 +95 -62
- package/dist/auth.cjs +3 -1
- package/dist/auth.cjs.map +1 -1
- package/dist/auth.d.cts +1 -1
- package/dist/auth.d.ts +1 -1
- package/dist/auth.js +3 -1
- package/dist/auth.js.map +1 -1
- package/dist/index.cjs +172 -91
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +17 -35
- package/dist/index.d.ts +17 -35
- package/dist/index.js +177 -92
- package/dist/index.js.map +1 -1
- package/dist/{payload-types-BjvBwB8Z.d.cts → payload-types-BUwpb306.d.cts} +295 -1384
- package/dist/{payload-types-BjvBwB8Z.d.ts → payload-types-BUwpb306.d.ts} +295 -1384
- package/dist/{components → ui}/code-block.cjs +11 -8
- package/dist/ui/code-block.cjs.map +1 -0
- package/dist/{components → ui}/code-block.js +11 -8
- package/dist/ui/code-block.js.map +1 -0
- package/dist/{components → ui}/flow.cjs +117 -69
- package/dist/ui/flow.cjs.map +1 -0
- package/dist/{components → ui}/flow.js +114 -66
- package/dist/ui/flow.js.map +1 -0
- package/dist/{components → ui}/form.cjs +6 -6
- package/dist/ui/form.cjs.map +1 -0
- package/dist/{components → ui}/form.d.cts +1 -1
- package/dist/{components → ui}/form.d.ts +1 -1
- package/dist/{components → ui}/form.js +3 -3
- package/dist/ui/form.js.map +1 -0
- package/dist/{components → ui}/image.cjs +2 -2
- package/dist/ui/image.cjs.map +1 -0
- package/dist/{components → ui}/image.js +2 -2
- package/dist/ui/image.js.map +1 -0
- package/dist/{components → ui}/rich-text.cjs +6 -6
- package/dist/ui/rich-text.cjs.map +1 -0
- package/dist/{components → ui}/rich-text.js +3 -3
- package/dist/ui/rich-text.js.map +1 -0
- package/dist/{webhook-_LdLdjGa.d.ts → webhook-BUcDo2Ny.d.cts} +2 -2
- package/dist/{webhook-CszIpUKn.d.cts → webhook-D8Bp97bF.d.ts} +2 -2
- package/dist/webhook.cjs +7 -5
- package/dist/webhook.cjs.map +1 -1
- package/dist/webhook.d.cts +2 -2
- package/dist/webhook.d.ts +2 -2
- package/dist/webhook.js +7 -5
- package/dist/webhook.js.map +1 -1
- package/package.json +29 -28
- package/dist/components/code-block.cjs.map +0 -1
- package/dist/components/code-block.js.map +0 -1
- package/dist/components/flow.cjs.map +0 -1
- package/dist/components/flow.js.map +0 -1
- package/dist/components/form.cjs.map +0 -1
- package/dist/components/form.js.map +0 -1
- package/dist/components/image.cjs.map +0 -1
- package/dist/components/image.js.map +0 -1
- package/dist/components/rich-text.cjs.map +0 -1
- package/dist/components/rich-text.js.map +0 -1
- /package/dist/{components → ui}/code-block.d.cts +0 -0
- /package/dist/{components → ui}/code-block.d.ts +0 -0
- /package/dist/{components → ui}/flow.d.cts +0 -0
- /package/dist/{components → ui}/flow.d.ts +0 -0
- /package/dist/{components → ui}/image.d.cts +0 -0
- /package/dist/{components → ui}/image.d.ts +0 -0
- /package/dist/{components → ui}/rich-text.d.cts +0 -0
- /package/dist/{components → ui}/rich-text.d.ts +0 -0
package/dist/index.cjs
CHANGED
|
@@ -208,7 +208,9 @@ function parseApiKey(apiKey) {
|
|
|
208
208
|
}
|
|
209
209
|
return { clientKey, secretKey };
|
|
210
210
|
} catch (e) {
|
|
211
|
-
throw new Error(
|
|
211
|
+
throw new Error(
|
|
212
|
+
'Invalid API key. Expected Base64 encoded "clientKey:secretKey"'
|
|
213
|
+
);
|
|
212
214
|
}
|
|
213
215
|
}
|
|
214
216
|
|
|
@@ -279,7 +281,14 @@ var GoneError = class extends SDKError {
|
|
|
279
281
|
};
|
|
280
282
|
var ServiceUnavailableError = class extends SDKError {
|
|
281
283
|
constructor(message = "Service temporarily unavailable.", retryAfter, details, userMessage, suggestion) {
|
|
282
|
-
super(
|
|
284
|
+
super(
|
|
285
|
+
"SERVICE_UNAVAILABLE_ERROR",
|
|
286
|
+
message,
|
|
287
|
+
503,
|
|
288
|
+
details,
|
|
289
|
+
userMessage,
|
|
290
|
+
suggestion
|
|
291
|
+
);
|
|
283
292
|
this.name = "ServiceUnavailableError";
|
|
284
293
|
this.retryAfter = retryAfter;
|
|
285
294
|
}
|
|
@@ -331,24 +340,12 @@ var createTimeoutError = (message, details, userMessage, suggestion) => new Time
|
|
|
331
340
|
var createUsageLimitError = (message, usage, details, userMessage, suggestion) => new UsageLimitError(message, usage, details, userMessage, suggestion);
|
|
332
341
|
|
|
333
342
|
// src/core/client/types.ts
|
|
334
|
-
|
|
335
|
-
local: "http://localhost:3000",
|
|
336
|
-
development: "https://api-dev.01.software",
|
|
337
|
-
staging: "https://api-stg.01.software",
|
|
338
|
-
production: "https://api.01.software"
|
|
339
|
-
};
|
|
340
|
-
function resolveApiUrl(config) {
|
|
341
|
-
if (config == null ? void 0 : config.baseUrl) {
|
|
342
|
-
return config.baseUrl.replace(/\/$/, "");
|
|
343
|
-
}
|
|
343
|
+
function resolveApiUrl() {
|
|
344
344
|
const envUrl = process.env.SOFTWARE_API_URL || process.env.NEXT_PUBLIC_SOFTWARE_API_URL;
|
|
345
345
|
if (envUrl) {
|
|
346
346
|
return envUrl.replace(/\/$/, "");
|
|
347
347
|
}
|
|
348
|
-
|
|
349
|
-
return API_URLS[config.environment];
|
|
350
|
-
}
|
|
351
|
-
return API_URLS.production;
|
|
348
|
+
return "https://api-dev.01.software";
|
|
352
349
|
}
|
|
353
350
|
|
|
354
351
|
// src/core/internal/utils/http.ts
|
|
@@ -368,8 +365,7 @@ function debugLog(debug, type, message, data) {
|
|
|
368
365
|
function getErrorSuggestion(status) {
|
|
369
366
|
if (status === 401) return "Please check your authentication credentials.";
|
|
370
367
|
if (status === 404) return "The requested resource was not found.";
|
|
371
|
-
if (status >= 500)
|
|
372
|
-
return "A server error occurred. Please try again later.";
|
|
368
|
+
if (status >= 500) return "A server error occurred. Please try again later.";
|
|
373
369
|
return void 0;
|
|
374
370
|
}
|
|
375
371
|
function delay(ms) {
|
|
@@ -385,7 +381,7 @@ function httpFetch(url, options) {
|
|
|
385
381
|
secretKey,
|
|
386
382
|
customerToken,
|
|
387
383
|
timeout = DEFAULT_TIMEOUT,
|
|
388
|
-
baseUrl =
|
|
384
|
+
baseUrl = resolveApiUrl(),
|
|
389
385
|
debug,
|
|
390
386
|
retry,
|
|
391
387
|
onUnauthorized
|
|
@@ -448,9 +444,18 @@ function httpFetch(url, options) {
|
|
|
448
444
|
});
|
|
449
445
|
if (!response.ok) {
|
|
450
446
|
if (response.status === 429 && response.headers.get("X-Usage-Limit")) {
|
|
451
|
-
const limit = parseInt(
|
|
452
|
-
|
|
453
|
-
|
|
447
|
+
const limit = parseInt(
|
|
448
|
+
response.headers.get("X-Usage-Limit") || "0",
|
|
449
|
+
10
|
|
450
|
+
);
|
|
451
|
+
const current = parseInt(
|
|
452
|
+
response.headers.get("X-Usage-Current") || "0",
|
|
453
|
+
10
|
|
454
|
+
);
|
|
455
|
+
const remaining = parseInt(
|
|
456
|
+
response.headers.get("X-Usage-Remaining") || "0",
|
|
457
|
+
10
|
|
458
|
+
);
|
|
454
459
|
throw createUsageLimitError(
|
|
455
460
|
`Monthly API usage limit exceeded (${current.toLocaleString()}/${limit.toLocaleString()})`,
|
|
456
461
|
{ limit, current, remaining },
|
|
@@ -633,7 +638,10 @@ var OrderApi = class extends BaseApi {
|
|
|
633
638
|
return this.request("/api/orders/update-fulfillment", params);
|
|
634
639
|
}
|
|
635
640
|
returnWithRefund(params) {
|
|
636
|
-
return this.request(
|
|
641
|
+
return this.request(
|
|
642
|
+
"/api/returns/return-refund",
|
|
643
|
+
params
|
|
644
|
+
);
|
|
637
645
|
}
|
|
638
646
|
createReturn(params) {
|
|
639
647
|
return this.request("/api/returns/create", params);
|
|
@@ -642,10 +650,16 @@ var OrderApi = class extends BaseApi {
|
|
|
642
650
|
return this.request("/api/returns/update", params);
|
|
643
651
|
}
|
|
644
652
|
validateDiscount(params) {
|
|
645
|
-
return this.request(
|
|
653
|
+
return this.request(
|
|
654
|
+
"/api/discounts/validate",
|
|
655
|
+
params
|
|
656
|
+
);
|
|
646
657
|
}
|
|
647
658
|
calculateShipping(params) {
|
|
648
|
-
return this.request(
|
|
659
|
+
return this.request(
|
|
660
|
+
"/api/shipping-policies/calculate",
|
|
661
|
+
params
|
|
662
|
+
);
|
|
649
663
|
}
|
|
650
664
|
createExchange(params) {
|
|
651
665
|
return this.request("/api/exchanges/create", params);
|
|
@@ -662,7 +676,9 @@ var CartApi = class {
|
|
|
662
676
|
throw createConfigError("clientKey is required for CartApi.");
|
|
663
677
|
}
|
|
664
678
|
if (!options.secretKey && !options.customerToken) {
|
|
665
|
-
throw createConfigError(
|
|
679
|
+
throw createConfigError(
|
|
680
|
+
"Either secretKey or customerToken is required for CartApi."
|
|
681
|
+
);
|
|
666
682
|
}
|
|
667
683
|
this.clientKey = options.clientKey;
|
|
668
684
|
this.secretKey = options.secretKey;
|
|
@@ -715,7 +731,11 @@ var CartApi = class {
|
|
|
715
731
|
return this.execute("/api/carts/update-item", "POST", params);
|
|
716
732
|
}
|
|
717
733
|
removeItem(params) {
|
|
718
|
-
return this.execute(
|
|
734
|
+
return this.execute(
|
|
735
|
+
"/api/carts/remove-item",
|
|
736
|
+
"POST",
|
|
737
|
+
params
|
|
738
|
+
);
|
|
719
739
|
}
|
|
720
740
|
applyDiscount(params) {
|
|
721
741
|
return this.execute("/api/carts/apply-discount", "POST", params);
|
|
@@ -724,7 +744,11 @@ var CartApi = class {
|
|
|
724
744
|
return this.execute("/api/carts/remove-discount", "POST", params);
|
|
725
745
|
}
|
|
726
746
|
clearCart(params) {
|
|
727
|
-
return this.execute(
|
|
747
|
+
return this.execute(
|
|
748
|
+
"/api/carts/clear",
|
|
749
|
+
"POST",
|
|
750
|
+
params
|
|
751
|
+
);
|
|
728
752
|
}
|
|
729
753
|
};
|
|
730
754
|
|
|
@@ -961,7 +985,11 @@ var HttpClient = class {
|
|
|
961
985
|
}
|
|
962
986
|
get defaultOptions() {
|
|
963
987
|
var _a;
|
|
964
|
-
const opts = {
|
|
988
|
+
const opts = {
|
|
989
|
+
clientKey: this.clientKey,
|
|
990
|
+
secretKey: this.secretKey,
|
|
991
|
+
baseUrl: this.baseUrl
|
|
992
|
+
};
|
|
965
993
|
const token = (_a = this.getCustomerToken) == null ? void 0 : _a.call(this);
|
|
966
994
|
if (token) {
|
|
967
995
|
opts.customerToken = token;
|
|
@@ -979,7 +1007,9 @@ var HttpClient = class {
|
|
|
979
1007
|
assertJsonResponse(response) {
|
|
980
1008
|
const contentType = response.headers.get("content-type");
|
|
981
1009
|
if (!(contentType == null ? void 0 : contentType.includes("application/json"))) {
|
|
982
|
-
throw createApiError("Response is not in JSON format.", response.status, {
|
|
1010
|
+
throw createApiError("Response is not in JSON format.", response.status, {
|
|
1011
|
+
contentType
|
|
1012
|
+
});
|
|
983
1013
|
}
|
|
984
1014
|
}
|
|
985
1015
|
/**
|
|
@@ -994,7 +1024,9 @@ var HttpClient = class {
|
|
|
994
1024
|
this.assertJsonResponse(response);
|
|
995
1025
|
const jsonData = yield response.json();
|
|
996
1026
|
if (jsonData.docs === void 0) {
|
|
997
|
-
throw createApiError("Invalid find response.", response.status, {
|
|
1027
|
+
throw createApiError("Invalid find response.", response.status, {
|
|
1028
|
+
jsonData
|
|
1029
|
+
});
|
|
998
1030
|
}
|
|
999
1031
|
return {
|
|
1000
1032
|
docs: jsonData.docs,
|
|
@@ -1028,7 +1060,9 @@ var HttpClient = class {
|
|
|
1028
1060
|
this.assertJsonResponse(response);
|
|
1029
1061
|
const jsonData = yield response.json();
|
|
1030
1062
|
if (jsonData.doc === void 0) {
|
|
1031
|
-
throw createApiError("Invalid mutation response.", response.status, {
|
|
1063
|
+
throw createApiError("Invalid mutation response.", response.status, {
|
|
1064
|
+
jsonData
|
|
1065
|
+
});
|
|
1032
1066
|
}
|
|
1033
1067
|
return {
|
|
1034
1068
|
message: jsonData.message || "",
|
|
@@ -1092,7 +1126,9 @@ var CollectionClient = class extends HttpClient {
|
|
|
1092
1126
|
requestFind(endpoint, options) {
|
|
1093
1127
|
return __async(this, null, function* () {
|
|
1094
1128
|
const url = this.buildUrl(endpoint, options);
|
|
1095
|
-
const response = yield httpFetch(url, __spreadProps(__spreadValues({}, this.defaultOptions), {
|
|
1129
|
+
const response = yield httpFetch(url, __spreadProps(__spreadValues({}, this.defaultOptions), {
|
|
1130
|
+
method: "GET"
|
|
1131
|
+
}));
|
|
1096
1132
|
return this.parseFindResponse(response);
|
|
1097
1133
|
});
|
|
1098
1134
|
}
|
|
@@ -1103,7 +1139,9 @@ var CollectionClient = class extends HttpClient {
|
|
|
1103
1139
|
requestFindById(endpoint, options) {
|
|
1104
1140
|
return __async(this, null, function* () {
|
|
1105
1141
|
const url = this.buildUrl(endpoint, options);
|
|
1106
|
-
const response = yield httpFetch(url, __spreadProps(__spreadValues({}, this.defaultOptions), {
|
|
1142
|
+
const response = yield httpFetch(url, __spreadProps(__spreadValues({}, this.defaultOptions), {
|
|
1143
|
+
method: "GET"
|
|
1144
|
+
}));
|
|
1107
1145
|
return this.parseDocumentResponse(response);
|
|
1108
1146
|
});
|
|
1109
1147
|
}
|
|
@@ -1140,7 +1178,9 @@ var CollectionClient = class extends HttpClient {
|
|
|
1140
1178
|
requestCount(endpoint, options) {
|
|
1141
1179
|
return __async(this, null, function* () {
|
|
1142
1180
|
const url = this.buildUrl(endpoint, options);
|
|
1143
|
-
const response = yield httpFetch(url, __spreadProps(__spreadValues({}, this.defaultOptions), {
|
|
1181
|
+
const response = yield httpFetch(url, __spreadProps(__spreadValues({}, this.defaultOptions), {
|
|
1182
|
+
method: "GET"
|
|
1183
|
+
}));
|
|
1144
1184
|
return this.parseDocumentResponse(response);
|
|
1145
1185
|
});
|
|
1146
1186
|
}
|
|
@@ -1215,13 +1255,11 @@ var COLLECTIONS = [
|
|
|
1215
1255
|
"tenants",
|
|
1216
1256
|
"tenant-metadata",
|
|
1217
1257
|
"tenant-logos",
|
|
1218
|
-
"tenant-og-images",
|
|
1219
1258
|
"products",
|
|
1220
1259
|
"product-variants",
|
|
1221
1260
|
"product-options",
|
|
1222
1261
|
"product-categories",
|
|
1223
1262
|
"product-tags",
|
|
1224
|
-
"product-images",
|
|
1225
1263
|
"product-collections",
|
|
1226
1264
|
"brands",
|
|
1227
1265
|
"brand-logos",
|
|
@@ -1237,7 +1275,6 @@ var COLLECTIONS = [
|
|
|
1237
1275
|
"customers",
|
|
1238
1276
|
"customer-addresses",
|
|
1239
1277
|
"customer-groups",
|
|
1240
|
-
"customer-group-images",
|
|
1241
1278
|
"carts",
|
|
1242
1279
|
"cart-items",
|
|
1243
1280
|
"discounts",
|
|
@@ -1245,35 +1282,29 @@ var COLLECTIONS = [
|
|
|
1245
1282
|
"documents",
|
|
1246
1283
|
"document-categories",
|
|
1247
1284
|
"document-types",
|
|
1248
|
-
"document-images",
|
|
1249
1285
|
"posts",
|
|
1250
1286
|
"post-categories",
|
|
1251
1287
|
"post-tags",
|
|
1252
|
-
"post-images",
|
|
1253
1288
|
"playlists",
|
|
1254
|
-
"playlist-images",
|
|
1255
1289
|
"playlist-categories",
|
|
1256
1290
|
"playlist-tags",
|
|
1257
1291
|
"musics",
|
|
1258
1292
|
"galleries",
|
|
1259
|
-
"gallery-images",
|
|
1260
1293
|
"gallery-categories",
|
|
1261
1294
|
"gallery-tags",
|
|
1295
|
+
"gallery-items",
|
|
1262
1296
|
"flows",
|
|
1263
|
-
"flow-images",
|
|
1264
1297
|
"flow-node-types",
|
|
1265
1298
|
"flow-edge-types",
|
|
1266
1299
|
"flow-categories",
|
|
1267
1300
|
"flow-tags",
|
|
1268
1301
|
"videos",
|
|
1269
|
-
"video-images",
|
|
1270
1302
|
"video-categories",
|
|
1271
1303
|
"video-tags",
|
|
1272
1304
|
"live-streams",
|
|
1273
|
-
"
|
|
1305
|
+
"images",
|
|
1274
1306
|
"forms",
|
|
1275
|
-
"form-submissions"
|
|
1276
|
-
"media"
|
|
1307
|
+
"form-submissions"
|
|
1277
1308
|
];
|
|
1278
1309
|
|
|
1279
1310
|
// src/core/customer/customer-auth.ts
|
|
@@ -1281,19 +1312,20 @@ var DEFAULT_TIMEOUT2 = 15e3;
|
|
|
1281
1312
|
var CustomerAuth = class {
|
|
1282
1313
|
constructor(clientKey, baseUrl, options) {
|
|
1283
1314
|
this.refreshPromise = null;
|
|
1284
|
-
var _a, _b;
|
|
1315
|
+
var _a, _b, _c;
|
|
1285
1316
|
this.clientKey = clientKey;
|
|
1286
1317
|
this.baseUrl = baseUrl;
|
|
1287
|
-
|
|
1288
|
-
|
|
1318
|
+
const persist = (_a = options == null ? void 0 : options.persist) != null ? _a : true;
|
|
1319
|
+
if (persist) {
|
|
1320
|
+
const key = typeof persist === "string" ? persist : "customer-token";
|
|
1289
1321
|
const isBrowser = typeof window !== "undefined";
|
|
1290
|
-
this.token = isBrowser ? (
|
|
1322
|
+
this.token = isBrowser ? (_b = localStorage.getItem(key)) != null ? _b : null : null;
|
|
1291
1323
|
this.onTokenChange = isBrowser ? (token) => {
|
|
1292
1324
|
if (token) localStorage.setItem(key, token);
|
|
1293
1325
|
else localStorage.removeItem(key);
|
|
1294
1326
|
} : void 0;
|
|
1295
1327
|
} else {
|
|
1296
|
-
this.token = (
|
|
1328
|
+
this.token = (_c = options == null ? void 0 : options.token) != null ? _c : null;
|
|
1297
1329
|
this.onTokenChange = options == null ? void 0 : options.onTokenChange;
|
|
1298
1330
|
}
|
|
1299
1331
|
}
|
|
@@ -1313,10 +1345,13 @@ var CustomerAuth = class {
|
|
|
1313
1345
|
*/
|
|
1314
1346
|
login(data) {
|
|
1315
1347
|
return __async(this, null, function* () {
|
|
1316
|
-
const result = yield this.requestJson(
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1348
|
+
const result = yield this.requestJson(
|
|
1349
|
+
"/api/customers/login",
|
|
1350
|
+
{
|
|
1351
|
+
method: "POST",
|
|
1352
|
+
body: JSON.stringify(data)
|
|
1353
|
+
}
|
|
1354
|
+
);
|
|
1320
1355
|
this.setToken(result.token);
|
|
1321
1356
|
return result;
|
|
1322
1357
|
});
|
|
@@ -1338,10 +1373,13 @@ var CustomerAuth = class {
|
|
|
1338
1373
|
}
|
|
1339
1374
|
_doRefreshToken() {
|
|
1340
1375
|
return __async(this, null, function* () {
|
|
1341
|
-
const result = yield this.requestJson(
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1376
|
+
const result = yield this.requestJson(
|
|
1377
|
+
"/api/customers/refresh",
|
|
1378
|
+
{
|
|
1379
|
+
method: "POST",
|
|
1380
|
+
headers: { Authorization: `Bearer ${this.token}` }
|
|
1381
|
+
}
|
|
1382
|
+
);
|
|
1345
1383
|
this.setToken(result.token);
|
|
1346
1384
|
return result;
|
|
1347
1385
|
});
|
|
@@ -1360,10 +1398,13 @@ var CustomerAuth = class {
|
|
|
1360
1398
|
var _a;
|
|
1361
1399
|
if (!this.token) return null;
|
|
1362
1400
|
try {
|
|
1363
|
-
const data = yield this.requestJson(
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1401
|
+
const data = yield this.requestJson(
|
|
1402
|
+
"/api/customers/me",
|
|
1403
|
+
{
|
|
1404
|
+
method: "GET",
|
|
1405
|
+
headers: { Authorization: `Bearer ${this.token}` }
|
|
1406
|
+
}
|
|
1407
|
+
);
|
|
1367
1408
|
return (_a = data.customer) != null ? _a : null;
|
|
1368
1409
|
} catch (error) {
|
|
1369
1410
|
if (error instanceof ApiError && error.status === 401) {
|
|
@@ -1402,11 +1443,14 @@ var CustomerAuth = class {
|
|
|
1402
1443
|
updateProfile(data) {
|
|
1403
1444
|
return __async(this, null, function* () {
|
|
1404
1445
|
if (!this.token) throw new ApiError("Not authenticated", 401);
|
|
1405
|
-
const result = yield this.requestJson(
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1446
|
+
const result = yield this.requestJson(
|
|
1447
|
+
"/api/customers/me",
|
|
1448
|
+
{
|
|
1449
|
+
method: "PATCH",
|
|
1450
|
+
headers: { Authorization: `Bearer ${this.token}` },
|
|
1451
|
+
body: JSON.stringify(data)
|
|
1452
|
+
}
|
|
1453
|
+
);
|
|
1410
1454
|
return result.customer;
|
|
1411
1455
|
});
|
|
1412
1456
|
}
|
|
@@ -1493,10 +1537,10 @@ var CustomerAuth = class {
|
|
|
1493
1537
|
} catch (error) {
|
|
1494
1538
|
clearTimeout(timeoutId);
|
|
1495
1539
|
if (error instanceof Error && error.name === "AbortError") {
|
|
1496
|
-
throw new TimeoutError(
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
);
|
|
1540
|
+
throw new TimeoutError(`Request timed out after ${DEFAULT_TIMEOUT2}ms`, {
|
|
1541
|
+
url: path,
|
|
1542
|
+
timeout: DEFAULT_TIMEOUT2
|
|
1543
|
+
});
|
|
1500
1544
|
}
|
|
1501
1545
|
throw new NetworkError(
|
|
1502
1546
|
error instanceof Error ? error.message : "Network request failed",
|
|
@@ -1519,7 +1563,12 @@ var CustomerAuth = class {
|
|
|
1519
1563
|
try {
|
|
1520
1564
|
return yield res.json();
|
|
1521
1565
|
} catch (e) {
|
|
1522
|
-
throw new ApiError(
|
|
1566
|
+
throw new ApiError(
|
|
1567
|
+
"Invalid JSON response from server",
|
|
1568
|
+
res.status,
|
|
1569
|
+
void 0,
|
|
1570
|
+
"INVALID_RESPONSE"
|
|
1571
|
+
);
|
|
1523
1572
|
}
|
|
1524
1573
|
});
|
|
1525
1574
|
}
|
|
@@ -1628,7 +1677,11 @@ var CollectionHooks = class {
|
|
|
1628
1677
|
}
|
|
1629
1678
|
// ===== useInfiniteQuery =====
|
|
1630
1679
|
useInfiniteQuery(params, options) {
|
|
1631
|
-
const {
|
|
1680
|
+
const {
|
|
1681
|
+
collection,
|
|
1682
|
+
options: queryOptions,
|
|
1683
|
+
pageSize = DEFAULT_PAGE_SIZE
|
|
1684
|
+
} = params;
|
|
1632
1685
|
return (0, import_react_query2.useInfiniteQuery)(__spreadValues({
|
|
1633
1686
|
queryKey: collectionKeys(collection).infinite(queryOptions),
|
|
1634
1687
|
queryFn: (_0) => __async(this, [_0], function* ({ pageParam }) {
|
|
@@ -1643,7 +1696,11 @@ var CollectionHooks = class {
|
|
|
1643
1696
|
}
|
|
1644
1697
|
// ===== useSuspenseInfiniteQuery =====
|
|
1645
1698
|
useSuspenseInfiniteQuery(params, options) {
|
|
1646
|
-
const {
|
|
1699
|
+
const {
|
|
1700
|
+
collection,
|
|
1701
|
+
options: queryOptions,
|
|
1702
|
+
pageSize = DEFAULT_PAGE_SIZE
|
|
1703
|
+
} = params;
|
|
1647
1704
|
return (0, import_react_query2.useSuspenseInfiniteQuery)(__spreadValues({
|
|
1648
1705
|
queryKey: collectionKeys(collection).infinite(queryOptions),
|
|
1649
1706
|
queryFn: (_0) => __async(this, [_0], function* ({ pageParam }) {
|
|
@@ -1686,7 +1743,11 @@ var CollectionHooks = class {
|
|
|
1686
1743
|
prefetchInfiniteQuery(params, options) {
|
|
1687
1744
|
return __async(this, null, function* () {
|
|
1688
1745
|
var _a;
|
|
1689
|
-
const {
|
|
1746
|
+
const {
|
|
1747
|
+
collection,
|
|
1748
|
+
options: queryOptions,
|
|
1749
|
+
pageSize = DEFAULT_PAGE_SIZE
|
|
1750
|
+
} = params;
|
|
1690
1751
|
return this.queryClient.prefetchInfiniteQuery({
|
|
1691
1752
|
queryKey: collectionKeys(collection).infinite(queryOptions),
|
|
1692
1753
|
queryFn: (_0) => __async(this, [_0], function* ({ pageParam }) {
|
|
@@ -1714,7 +1775,9 @@ var CollectionHooks = class {
|
|
|
1714
1775
|
}),
|
|
1715
1776
|
onSuccess: (data) => {
|
|
1716
1777
|
var _a;
|
|
1717
|
-
this.queryClient.invalidateQueries({
|
|
1778
|
+
this.queryClient.invalidateQueries({
|
|
1779
|
+
queryKey: collectionKeys(collection).all
|
|
1780
|
+
});
|
|
1718
1781
|
(_a = options == null ? void 0 : options.onSuccess) == null ? void 0 : _a.call(options, data);
|
|
1719
1782
|
},
|
|
1720
1783
|
onError: options == null ? void 0 : options.onError,
|
|
@@ -1733,7 +1796,9 @@ var CollectionHooks = class {
|
|
|
1733
1796
|
}),
|
|
1734
1797
|
onSuccess: (data) => {
|
|
1735
1798
|
var _a;
|
|
1736
|
-
this.queryClient.invalidateQueries({
|
|
1799
|
+
this.queryClient.invalidateQueries({
|
|
1800
|
+
queryKey: collectionKeys(collection).all
|
|
1801
|
+
});
|
|
1737
1802
|
(_a = options == null ? void 0 : options.onSuccess) == null ? void 0 : _a.call(options, data);
|
|
1738
1803
|
},
|
|
1739
1804
|
onError: options == null ? void 0 : options.onError,
|
|
@@ -1748,7 +1813,9 @@ var CollectionHooks = class {
|
|
|
1748
1813
|
}),
|
|
1749
1814
|
onSuccess: (data) => {
|
|
1750
1815
|
var _a;
|
|
1751
|
-
this.queryClient.invalidateQueries({
|
|
1816
|
+
this.queryClient.invalidateQueries({
|
|
1817
|
+
queryKey: collectionKeys(collection).all
|
|
1818
|
+
});
|
|
1752
1819
|
(_a = options == null ? void 0 : options.onSuccess) == null ? void 0 : _a.call(options, data);
|
|
1753
1820
|
},
|
|
1754
1821
|
onError: options == null ? void 0 : options.onError,
|
|
@@ -1762,9 +1829,13 @@ var CollectionHooks = class {
|
|
|
1762
1829
|
}
|
|
1763
1830
|
getQueryData(collection, type, idOrOptions, options) {
|
|
1764
1831
|
if (type === "list") {
|
|
1765
|
-
return this.queryClient.getQueryData(
|
|
1832
|
+
return this.queryClient.getQueryData(
|
|
1833
|
+
collectionKeys(collection).list(idOrOptions)
|
|
1834
|
+
);
|
|
1766
1835
|
}
|
|
1767
|
-
return this.queryClient.getQueryData(
|
|
1836
|
+
return this.queryClient.getQueryData(
|
|
1837
|
+
collectionKeys(collection).detail(idOrOptions, options)
|
|
1838
|
+
);
|
|
1768
1839
|
}
|
|
1769
1840
|
setQueryData(collection, type, dataOrId, dataOrOptions, options) {
|
|
1770
1841
|
if (type === "list") {
|
|
@@ -1937,14 +2008,18 @@ var BrowserClient = class {
|
|
|
1937
2008
|
throw createConfigError("clientKey is required.");
|
|
1938
2009
|
}
|
|
1939
2010
|
this.config = __spreadValues({}, options);
|
|
1940
|
-
this.baseUrl = resolveApiUrl(
|
|
2011
|
+
this.baseUrl = resolveApiUrl();
|
|
1941
2012
|
const metadata = {
|
|
1942
2013
|
timestamp: Date.now(),
|
|
1943
2014
|
userAgent: typeof window !== "undefined" ? (_a = window.navigator) == null ? void 0 : _a.userAgent : "Node.js"
|
|
1944
2015
|
};
|
|
1945
2016
|
this.state = { metadata };
|
|
1946
2017
|
this.queryClient = getQueryClient();
|
|
1947
|
-
this.customer = new CustomerAuth(
|
|
2018
|
+
this.customer = new CustomerAuth(
|
|
2019
|
+
this.config.clientKey,
|
|
2020
|
+
this.baseUrl,
|
|
2021
|
+
options.customer
|
|
2022
|
+
);
|
|
1948
2023
|
const onUnauthorized = () => __async(this, null, function* () {
|
|
1949
2024
|
var _a2;
|
|
1950
2025
|
try {
|
|
@@ -1967,7 +2042,11 @@ var BrowserClient = class {
|
|
|
1967
2042
|
() => this.customer.getToken(),
|
|
1968
2043
|
onUnauthorized
|
|
1969
2044
|
);
|
|
1970
|
-
this.query = new QueryHooks(
|
|
2045
|
+
this.query = new QueryHooks(
|
|
2046
|
+
this.queryClient,
|
|
2047
|
+
this.collections,
|
|
2048
|
+
this.customer
|
|
2049
|
+
);
|
|
1971
2050
|
}
|
|
1972
2051
|
from(collection) {
|
|
1973
2052
|
return this.collections.from(collection);
|
|
@@ -1998,7 +2077,7 @@ var ServerClient = class {
|
|
|
1998
2077
|
throw createConfigError("secretKey is required.");
|
|
1999
2078
|
}
|
|
2000
2079
|
this.config = __spreadValues({}, options);
|
|
2001
|
-
this.baseUrl = resolveApiUrl(
|
|
2080
|
+
this.baseUrl = resolveApiUrl();
|
|
2002
2081
|
const metadata = {
|
|
2003
2082
|
timestamp: Date.now(),
|
|
2004
2083
|
userAgent: "Node.js"
|
|
@@ -2100,17 +2179,19 @@ function handleWebhook(request, handler, options) {
|
|
|
2100
2179
|
);
|
|
2101
2180
|
} catch (error) {
|
|
2102
2181
|
console.error("Webhook processing error:", error);
|
|
2103
|
-
return new Response(
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
);
|
|
2182
|
+
return new Response(JSON.stringify({ error: "Internal server error" }), {
|
|
2183
|
+
status: 500,
|
|
2184
|
+
headers: { "Content-Type": "application/json" }
|
|
2185
|
+
});
|
|
2107
2186
|
}
|
|
2108
2187
|
});
|
|
2109
2188
|
}
|
|
2110
2189
|
function createTypedWebhookHandler(collection, handler) {
|
|
2111
2190
|
return (event) => __async(null, null, function* () {
|
|
2112
2191
|
if (event.collection !== collection) {
|
|
2113
|
-
throw new Error(
|
|
2192
|
+
throw new Error(
|
|
2193
|
+
`Expected collection "${collection}", got "${event.collection}"`
|
|
2194
|
+
);
|
|
2114
2195
|
}
|
|
2115
2196
|
return handler(event);
|
|
2116
2197
|
});
|