@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.js
CHANGED
|
@@ -128,7 +128,9 @@ function parseApiKey(apiKey) {
|
|
|
128
128
|
}
|
|
129
129
|
return { clientKey, secretKey };
|
|
130
130
|
} catch (e) {
|
|
131
|
-
throw new Error(
|
|
131
|
+
throw new Error(
|
|
132
|
+
'Invalid API key. Expected Base64 encoded "clientKey:secretKey"'
|
|
133
|
+
);
|
|
132
134
|
}
|
|
133
135
|
}
|
|
134
136
|
|
|
@@ -199,7 +201,14 @@ var GoneError = class extends SDKError {
|
|
|
199
201
|
};
|
|
200
202
|
var ServiceUnavailableError = class extends SDKError {
|
|
201
203
|
constructor(message = "Service temporarily unavailable.", retryAfter, details, userMessage, suggestion) {
|
|
202
|
-
super(
|
|
204
|
+
super(
|
|
205
|
+
"SERVICE_UNAVAILABLE_ERROR",
|
|
206
|
+
message,
|
|
207
|
+
503,
|
|
208
|
+
details,
|
|
209
|
+
userMessage,
|
|
210
|
+
suggestion
|
|
211
|
+
);
|
|
203
212
|
this.name = "ServiceUnavailableError";
|
|
204
213
|
this.retryAfter = retryAfter;
|
|
205
214
|
}
|
|
@@ -251,24 +260,12 @@ var createTimeoutError = (message, details, userMessage, suggestion) => new Time
|
|
|
251
260
|
var createUsageLimitError = (message, usage, details, userMessage, suggestion) => new UsageLimitError(message, usage, details, userMessage, suggestion);
|
|
252
261
|
|
|
253
262
|
// src/core/client/types.ts
|
|
254
|
-
|
|
255
|
-
local: "http://localhost:3000",
|
|
256
|
-
development: "https://api-dev.01.software",
|
|
257
|
-
staging: "https://api-stg.01.software",
|
|
258
|
-
production: "https://api.01.software"
|
|
259
|
-
};
|
|
260
|
-
function resolveApiUrl(config) {
|
|
261
|
-
if (config == null ? void 0 : config.baseUrl) {
|
|
262
|
-
return config.baseUrl.replace(/\/$/, "");
|
|
263
|
-
}
|
|
263
|
+
function resolveApiUrl() {
|
|
264
264
|
const envUrl = process.env.SOFTWARE_API_URL || process.env.NEXT_PUBLIC_SOFTWARE_API_URL;
|
|
265
265
|
if (envUrl) {
|
|
266
266
|
return envUrl.replace(/\/$/, "");
|
|
267
267
|
}
|
|
268
|
-
|
|
269
|
-
return API_URLS[config.environment];
|
|
270
|
-
}
|
|
271
|
-
return API_URLS.production;
|
|
268
|
+
return "https://api-dev.01.software";
|
|
272
269
|
}
|
|
273
270
|
|
|
274
271
|
// src/core/internal/utils/http.ts
|
|
@@ -288,8 +285,7 @@ function debugLog(debug, type, message, data) {
|
|
|
288
285
|
function getErrorSuggestion(status) {
|
|
289
286
|
if (status === 401) return "Please check your authentication credentials.";
|
|
290
287
|
if (status === 404) return "The requested resource was not found.";
|
|
291
|
-
if (status >= 500)
|
|
292
|
-
return "A server error occurred. Please try again later.";
|
|
288
|
+
if (status >= 500) return "A server error occurred. Please try again later.";
|
|
293
289
|
return void 0;
|
|
294
290
|
}
|
|
295
291
|
function delay(ms) {
|
|
@@ -305,7 +301,7 @@ function httpFetch(url, options) {
|
|
|
305
301
|
secretKey,
|
|
306
302
|
customerToken,
|
|
307
303
|
timeout = DEFAULT_TIMEOUT,
|
|
308
|
-
baseUrl =
|
|
304
|
+
baseUrl = resolveApiUrl(),
|
|
309
305
|
debug,
|
|
310
306
|
retry,
|
|
311
307
|
onUnauthorized
|
|
@@ -368,9 +364,18 @@ function httpFetch(url, options) {
|
|
|
368
364
|
});
|
|
369
365
|
if (!response.ok) {
|
|
370
366
|
if (response.status === 429 && response.headers.get("X-Usage-Limit")) {
|
|
371
|
-
const limit = parseInt(
|
|
372
|
-
|
|
373
|
-
|
|
367
|
+
const limit = parseInt(
|
|
368
|
+
response.headers.get("X-Usage-Limit") || "0",
|
|
369
|
+
10
|
|
370
|
+
);
|
|
371
|
+
const current = parseInt(
|
|
372
|
+
response.headers.get("X-Usage-Current") || "0",
|
|
373
|
+
10
|
|
374
|
+
);
|
|
375
|
+
const remaining = parseInt(
|
|
376
|
+
response.headers.get("X-Usage-Remaining") || "0",
|
|
377
|
+
10
|
|
378
|
+
);
|
|
374
379
|
throw createUsageLimitError(
|
|
375
380
|
`Monthly API usage limit exceeded (${current.toLocaleString()}/${limit.toLocaleString()})`,
|
|
376
381
|
{ limit, current, remaining },
|
|
@@ -553,7 +558,10 @@ var OrderApi = class extends BaseApi {
|
|
|
553
558
|
return this.request("/api/orders/update-fulfillment", params);
|
|
554
559
|
}
|
|
555
560
|
returnWithRefund(params) {
|
|
556
|
-
return this.request(
|
|
561
|
+
return this.request(
|
|
562
|
+
"/api/returns/return-refund",
|
|
563
|
+
params
|
|
564
|
+
);
|
|
557
565
|
}
|
|
558
566
|
createReturn(params) {
|
|
559
567
|
return this.request("/api/returns/create", params);
|
|
@@ -562,10 +570,16 @@ var OrderApi = class extends BaseApi {
|
|
|
562
570
|
return this.request("/api/returns/update", params);
|
|
563
571
|
}
|
|
564
572
|
validateDiscount(params) {
|
|
565
|
-
return this.request(
|
|
573
|
+
return this.request(
|
|
574
|
+
"/api/discounts/validate",
|
|
575
|
+
params
|
|
576
|
+
);
|
|
566
577
|
}
|
|
567
578
|
calculateShipping(params) {
|
|
568
|
-
return this.request(
|
|
579
|
+
return this.request(
|
|
580
|
+
"/api/shipping-policies/calculate",
|
|
581
|
+
params
|
|
582
|
+
);
|
|
569
583
|
}
|
|
570
584
|
createExchange(params) {
|
|
571
585
|
return this.request("/api/exchanges/create", params);
|
|
@@ -582,7 +596,9 @@ var CartApi = class {
|
|
|
582
596
|
throw createConfigError("clientKey is required for CartApi.");
|
|
583
597
|
}
|
|
584
598
|
if (!options.secretKey && !options.customerToken) {
|
|
585
|
-
throw createConfigError(
|
|
599
|
+
throw createConfigError(
|
|
600
|
+
"Either secretKey or customerToken is required for CartApi."
|
|
601
|
+
);
|
|
586
602
|
}
|
|
587
603
|
this.clientKey = options.clientKey;
|
|
588
604
|
this.secretKey = options.secretKey;
|
|
@@ -635,7 +651,11 @@ var CartApi = class {
|
|
|
635
651
|
return this.execute("/api/carts/update-item", "POST", params);
|
|
636
652
|
}
|
|
637
653
|
removeItem(params) {
|
|
638
|
-
return this.execute(
|
|
654
|
+
return this.execute(
|
|
655
|
+
"/api/carts/remove-item",
|
|
656
|
+
"POST",
|
|
657
|
+
params
|
|
658
|
+
);
|
|
639
659
|
}
|
|
640
660
|
applyDiscount(params) {
|
|
641
661
|
return this.execute("/api/carts/apply-discount", "POST", params);
|
|
@@ -644,7 +664,11 @@ var CartApi = class {
|
|
|
644
664
|
return this.execute("/api/carts/remove-discount", "POST", params);
|
|
645
665
|
}
|
|
646
666
|
clearCart(params) {
|
|
647
|
-
return this.execute(
|
|
667
|
+
return this.execute(
|
|
668
|
+
"/api/carts/clear",
|
|
669
|
+
"POST",
|
|
670
|
+
params
|
|
671
|
+
);
|
|
648
672
|
}
|
|
649
673
|
};
|
|
650
674
|
|
|
@@ -881,7 +905,11 @@ var HttpClient = class {
|
|
|
881
905
|
}
|
|
882
906
|
get defaultOptions() {
|
|
883
907
|
var _a;
|
|
884
|
-
const opts = {
|
|
908
|
+
const opts = {
|
|
909
|
+
clientKey: this.clientKey,
|
|
910
|
+
secretKey: this.secretKey,
|
|
911
|
+
baseUrl: this.baseUrl
|
|
912
|
+
};
|
|
885
913
|
const token = (_a = this.getCustomerToken) == null ? void 0 : _a.call(this);
|
|
886
914
|
if (token) {
|
|
887
915
|
opts.customerToken = token;
|
|
@@ -899,7 +927,9 @@ var HttpClient = class {
|
|
|
899
927
|
assertJsonResponse(response) {
|
|
900
928
|
const contentType = response.headers.get("content-type");
|
|
901
929
|
if (!(contentType == null ? void 0 : contentType.includes("application/json"))) {
|
|
902
|
-
throw createApiError("Response is not in JSON format.", response.status, {
|
|
930
|
+
throw createApiError("Response is not in JSON format.", response.status, {
|
|
931
|
+
contentType
|
|
932
|
+
});
|
|
903
933
|
}
|
|
904
934
|
}
|
|
905
935
|
/**
|
|
@@ -914,7 +944,9 @@ var HttpClient = class {
|
|
|
914
944
|
this.assertJsonResponse(response);
|
|
915
945
|
const jsonData = yield response.json();
|
|
916
946
|
if (jsonData.docs === void 0) {
|
|
917
|
-
throw createApiError("Invalid find response.", response.status, {
|
|
947
|
+
throw createApiError("Invalid find response.", response.status, {
|
|
948
|
+
jsonData
|
|
949
|
+
});
|
|
918
950
|
}
|
|
919
951
|
return {
|
|
920
952
|
docs: jsonData.docs,
|
|
@@ -948,7 +980,9 @@ var HttpClient = class {
|
|
|
948
980
|
this.assertJsonResponse(response);
|
|
949
981
|
const jsonData = yield response.json();
|
|
950
982
|
if (jsonData.doc === void 0) {
|
|
951
|
-
throw createApiError("Invalid mutation response.", response.status, {
|
|
983
|
+
throw createApiError("Invalid mutation response.", response.status, {
|
|
984
|
+
jsonData
|
|
985
|
+
});
|
|
952
986
|
}
|
|
953
987
|
return {
|
|
954
988
|
message: jsonData.message || "",
|
|
@@ -1012,7 +1046,9 @@ var CollectionClient = class extends HttpClient {
|
|
|
1012
1046
|
requestFind(endpoint, options) {
|
|
1013
1047
|
return __async(this, null, function* () {
|
|
1014
1048
|
const url = this.buildUrl(endpoint, options);
|
|
1015
|
-
const response = yield httpFetch(url, __spreadProps(__spreadValues({}, this.defaultOptions), {
|
|
1049
|
+
const response = yield httpFetch(url, __spreadProps(__spreadValues({}, this.defaultOptions), {
|
|
1050
|
+
method: "GET"
|
|
1051
|
+
}));
|
|
1016
1052
|
return this.parseFindResponse(response);
|
|
1017
1053
|
});
|
|
1018
1054
|
}
|
|
@@ -1023,7 +1059,9 @@ var CollectionClient = class extends HttpClient {
|
|
|
1023
1059
|
requestFindById(endpoint, options) {
|
|
1024
1060
|
return __async(this, null, function* () {
|
|
1025
1061
|
const url = this.buildUrl(endpoint, options);
|
|
1026
|
-
const response = yield httpFetch(url, __spreadProps(__spreadValues({}, this.defaultOptions), {
|
|
1062
|
+
const response = yield httpFetch(url, __spreadProps(__spreadValues({}, this.defaultOptions), {
|
|
1063
|
+
method: "GET"
|
|
1064
|
+
}));
|
|
1027
1065
|
return this.parseDocumentResponse(response);
|
|
1028
1066
|
});
|
|
1029
1067
|
}
|
|
@@ -1060,7 +1098,9 @@ var CollectionClient = class extends HttpClient {
|
|
|
1060
1098
|
requestCount(endpoint, options) {
|
|
1061
1099
|
return __async(this, null, function* () {
|
|
1062
1100
|
const url = this.buildUrl(endpoint, options);
|
|
1063
|
-
const response = yield httpFetch(url, __spreadProps(__spreadValues({}, this.defaultOptions), {
|
|
1101
|
+
const response = yield httpFetch(url, __spreadProps(__spreadValues({}, this.defaultOptions), {
|
|
1102
|
+
method: "GET"
|
|
1103
|
+
}));
|
|
1064
1104
|
return this.parseDocumentResponse(response);
|
|
1065
1105
|
});
|
|
1066
1106
|
}
|
|
@@ -1135,13 +1175,11 @@ var COLLECTIONS = [
|
|
|
1135
1175
|
"tenants",
|
|
1136
1176
|
"tenant-metadata",
|
|
1137
1177
|
"tenant-logos",
|
|
1138
|
-
"tenant-og-images",
|
|
1139
1178
|
"products",
|
|
1140
1179
|
"product-variants",
|
|
1141
1180
|
"product-options",
|
|
1142
1181
|
"product-categories",
|
|
1143
1182
|
"product-tags",
|
|
1144
|
-
"product-images",
|
|
1145
1183
|
"product-collections",
|
|
1146
1184
|
"brands",
|
|
1147
1185
|
"brand-logos",
|
|
@@ -1157,7 +1195,6 @@ var COLLECTIONS = [
|
|
|
1157
1195
|
"customers",
|
|
1158
1196
|
"customer-addresses",
|
|
1159
1197
|
"customer-groups",
|
|
1160
|
-
"customer-group-images",
|
|
1161
1198
|
"carts",
|
|
1162
1199
|
"cart-items",
|
|
1163
1200
|
"discounts",
|
|
@@ -1165,35 +1202,29 @@ var COLLECTIONS = [
|
|
|
1165
1202
|
"documents",
|
|
1166
1203
|
"document-categories",
|
|
1167
1204
|
"document-types",
|
|
1168
|
-
"document-images",
|
|
1169
1205
|
"posts",
|
|
1170
1206
|
"post-categories",
|
|
1171
1207
|
"post-tags",
|
|
1172
|
-
"post-images",
|
|
1173
1208
|
"playlists",
|
|
1174
|
-
"playlist-images",
|
|
1175
1209
|
"playlist-categories",
|
|
1176
1210
|
"playlist-tags",
|
|
1177
1211
|
"musics",
|
|
1178
1212
|
"galleries",
|
|
1179
|
-
"gallery-images",
|
|
1180
1213
|
"gallery-categories",
|
|
1181
1214
|
"gallery-tags",
|
|
1215
|
+
"gallery-items",
|
|
1182
1216
|
"flows",
|
|
1183
|
-
"flow-images",
|
|
1184
1217
|
"flow-node-types",
|
|
1185
1218
|
"flow-edge-types",
|
|
1186
1219
|
"flow-categories",
|
|
1187
1220
|
"flow-tags",
|
|
1188
1221
|
"videos",
|
|
1189
|
-
"video-images",
|
|
1190
1222
|
"video-categories",
|
|
1191
1223
|
"video-tags",
|
|
1192
1224
|
"live-streams",
|
|
1193
|
-
"
|
|
1225
|
+
"images",
|
|
1194
1226
|
"forms",
|
|
1195
|
-
"form-submissions"
|
|
1196
|
-
"media"
|
|
1227
|
+
"form-submissions"
|
|
1197
1228
|
];
|
|
1198
1229
|
|
|
1199
1230
|
// src/core/customer/customer-auth.ts
|
|
@@ -1201,19 +1232,20 @@ var DEFAULT_TIMEOUT2 = 15e3;
|
|
|
1201
1232
|
var CustomerAuth = class {
|
|
1202
1233
|
constructor(clientKey, baseUrl, options) {
|
|
1203
1234
|
this.refreshPromise = null;
|
|
1204
|
-
var _a, _b;
|
|
1235
|
+
var _a, _b, _c;
|
|
1205
1236
|
this.clientKey = clientKey;
|
|
1206
1237
|
this.baseUrl = baseUrl;
|
|
1207
|
-
|
|
1208
|
-
|
|
1238
|
+
const persist = (_a = options == null ? void 0 : options.persist) != null ? _a : true;
|
|
1239
|
+
if (persist) {
|
|
1240
|
+
const key = typeof persist === "string" ? persist : "customer-token";
|
|
1209
1241
|
const isBrowser = typeof window !== "undefined";
|
|
1210
|
-
this.token = isBrowser ? (
|
|
1242
|
+
this.token = isBrowser ? (_b = localStorage.getItem(key)) != null ? _b : null : null;
|
|
1211
1243
|
this.onTokenChange = isBrowser ? (token) => {
|
|
1212
1244
|
if (token) localStorage.setItem(key, token);
|
|
1213
1245
|
else localStorage.removeItem(key);
|
|
1214
1246
|
} : void 0;
|
|
1215
1247
|
} else {
|
|
1216
|
-
this.token = (
|
|
1248
|
+
this.token = (_c = options == null ? void 0 : options.token) != null ? _c : null;
|
|
1217
1249
|
this.onTokenChange = options == null ? void 0 : options.onTokenChange;
|
|
1218
1250
|
}
|
|
1219
1251
|
}
|
|
@@ -1233,10 +1265,13 @@ var CustomerAuth = class {
|
|
|
1233
1265
|
*/
|
|
1234
1266
|
login(data) {
|
|
1235
1267
|
return __async(this, null, function* () {
|
|
1236
|
-
const result = yield this.requestJson(
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1268
|
+
const result = yield this.requestJson(
|
|
1269
|
+
"/api/customers/login",
|
|
1270
|
+
{
|
|
1271
|
+
method: "POST",
|
|
1272
|
+
body: JSON.stringify(data)
|
|
1273
|
+
}
|
|
1274
|
+
);
|
|
1240
1275
|
this.setToken(result.token);
|
|
1241
1276
|
return result;
|
|
1242
1277
|
});
|
|
@@ -1258,10 +1293,13 @@ var CustomerAuth = class {
|
|
|
1258
1293
|
}
|
|
1259
1294
|
_doRefreshToken() {
|
|
1260
1295
|
return __async(this, null, function* () {
|
|
1261
|
-
const result = yield this.requestJson(
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1296
|
+
const result = yield this.requestJson(
|
|
1297
|
+
"/api/customers/refresh",
|
|
1298
|
+
{
|
|
1299
|
+
method: "POST",
|
|
1300
|
+
headers: { Authorization: `Bearer ${this.token}` }
|
|
1301
|
+
}
|
|
1302
|
+
);
|
|
1265
1303
|
this.setToken(result.token);
|
|
1266
1304
|
return result;
|
|
1267
1305
|
});
|
|
@@ -1280,10 +1318,13 @@ var CustomerAuth = class {
|
|
|
1280
1318
|
var _a;
|
|
1281
1319
|
if (!this.token) return null;
|
|
1282
1320
|
try {
|
|
1283
|
-
const data = yield this.requestJson(
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1321
|
+
const data = yield this.requestJson(
|
|
1322
|
+
"/api/customers/me",
|
|
1323
|
+
{
|
|
1324
|
+
method: "GET",
|
|
1325
|
+
headers: { Authorization: `Bearer ${this.token}` }
|
|
1326
|
+
}
|
|
1327
|
+
);
|
|
1287
1328
|
return (_a = data.customer) != null ? _a : null;
|
|
1288
1329
|
} catch (error) {
|
|
1289
1330
|
if (error instanceof ApiError && error.status === 401) {
|
|
@@ -1322,11 +1363,14 @@ var CustomerAuth = class {
|
|
|
1322
1363
|
updateProfile(data) {
|
|
1323
1364
|
return __async(this, null, function* () {
|
|
1324
1365
|
if (!this.token) throw new ApiError("Not authenticated", 401);
|
|
1325
|
-
const result = yield this.requestJson(
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1366
|
+
const result = yield this.requestJson(
|
|
1367
|
+
"/api/customers/me",
|
|
1368
|
+
{
|
|
1369
|
+
method: "PATCH",
|
|
1370
|
+
headers: { Authorization: `Bearer ${this.token}` },
|
|
1371
|
+
body: JSON.stringify(data)
|
|
1372
|
+
}
|
|
1373
|
+
);
|
|
1330
1374
|
return result.customer;
|
|
1331
1375
|
});
|
|
1332
1376
|
}
|
|
@@ -1413,10 +1457,10 @@ var CustomerAuth = class {
|
|
|
1413
1457
|
} catch (error) {
|
|
1414
1458
|
clearTimeout(timeoutId);
|
|
1415
1459
|
if (error instanceof Error && error.name === "AbortError") {
|
|
1416
|
-
throw new TimeoutError(
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
);
|
|
1460
|
+
throw new TimeoutError(`Request timed out after ${DEFAULT_TIMEOUT2}ms`, {
|
|
1461
|
+
url: path,
|
|
1462
|
+
timeout: DEFAULT_TIMEOUT2
|
|
1463
|
+
});
|
|
1420
1464
|
}
|
|
1421
1465
|
throw new NetworkError(
|
|
1422
1466
|
error instanceof Error ? error.message : "Network request failed",
|
|
@@ -1439,14 +1483,23 @@ var CustomerAuth = class {
|
|
|
1439
1483
|
try {
|
|
1440
1484
|
return yield res.json();
|
|
1441
1485
|
} catch (e) {
|
|
1442
|
-
throw new ApiError(
|
|
1486
|
+
throw new ApiError(
|
|
1487
|
+
"Invalid JSON response from server",
|
|
1488
|
+
res.status,
|
|
1489
|
+
void 0,
|
|
1490
|
+
"INVALID_RESPONSE"
|
|
1491
|
+
);
|
|
1443
1492
|
}
|
|
1444
1493
|
});
|
|
1445
1494
|
}
|
|
1446
1495
|
};
|
|
1447
1496
|
|
|
1448
1497
|
// src/core/query/get-query-client.ts
|
|
1449
|
-
import {
|
|
1498
|
+
import {
|
|
1499
|
+
isServer,
|
|
1500
|
+
QueryClient,
|
|
1501
|
+
defaultShouldDehydrateQuery
|
|
1502
|
+
} from "@tanstack/react-query";
|
|
1450
1503
|
function makeQueryClient() {
|
|
1451
1504
|
return new QueryClient({
|
|
1452
1505
|
defaultOptions: {
|
|
@@ -1554,7 +1607,11 @@ var CollectionHooks = class {
|
|
|
1554
1607
|
}
|
|
1555
1608
|
// ===== useInfiniteQuery =====
|
|
1556
1609
|
useInfiniteQuery(params, options) {
|
|
1557
|
-
const {
|
|
1610
|
+
const {
|
|
1611
|
+
collection,
|
|
1612
|
+
options: queryOptions,
|
|
1613
|
+
pageSize = DEFAULT_PAGE_SIZE
|
|
1614
|
+
} = params;
|
|
1558
1615
|
return useInfiniteQueryOriginal(__spreadValues({
|
|
1559
1616
|
queryKey: collectionKeys(collection).infinite(queryOptions),
|
|
1560
1617
|
queryFn: (_0) => __async(this, [_0], function* ({ pageParam }) {
|
|
@@ -1569,7 +1626,11 @@ var CollectionHooks = class {
|
|
|
1569
1626
|
}
|
|
1570
1627
|
// ===== useSuspenseInfiniteQuery =====
|
|
1571
1628
|
useSuspenseInfiniteQuery(params, options) {
|
|
1572
|
-
const {
|
|
1629
|
+
const {
|
|
1630
|
+
collection,
|
|
1631
|
+
options: queryOptions,
|
|
1632
|
+
pageSize = DEFAULT_PAGE_SIZE
|
|
1633
|
+
} = params;
|
|
1573
1634
|
return useSuspenseInfiniteQueryOriginal(__spreadValues({
|
|
1574
1635
|
queryKey: collectionKeys(collection).infinite(queryOptions),
|
|
1575
1636
|
queryFn: (_0) => __async(this, [_0], function* ({ pageParam }) {
|
|
@@ -1612,7 +1673,11 @@ var CollectionHooks = class {
|
|
|
1612
1673
|
prefetchInfiniteQuery(params, options) {
|
|
1613
1674
|
return __async(this, null, function* () {
|
|
1614
1675
|
var _a;
|
|
1615
|
-
const {
|
|
1676
|
+
const {
|
|
1677
|
+
collection,
|
|
1678
|
+
options: queryOptions,
|
|
1679
|
+
pageSize = DEFAULT_PAGE_SIZE
|
|
1680
|
+
} = params;
|
|
1616
1681
|
return this.queryClient.prefetchInfiniteQuery({
|
|
1617
1682
|
queryKey: collectionKeys(collection).infinite(queryOptions),
|
|
1618
1683
|
queryFn: (_0) => __async(this, [_0], function* ({ pageParam }) {
|
|
@@ -1640,7 +1705,9 @@ var CollectionHooks = class {
|
|
|
1640
1705
|
}),
|
|
1641
1706
|
onSuccess: (data) => {
|
|
1642
1707
|
var _a;
|
|
1643
|
-
this.queryClient.invalidateQueries({
|
|
1708
|
+
this.queryClient.invalidateQueries({
|
|
1709
|
+
queryKey: collectionKeys(collection).all
|
|
1710
|
+
});
|
|
1644
1711
|
(_a = options == null ? void 0 : options.onSuccess) == null ? void 0 : _a.call(options, data);
|
|
1645
1712
|
},
|
|
1646
1713
|
onError: options == null ? void 0 : options.onError,
|
|
@@ -1659,7 +1726,9 @@ var CollectionHooks = class {
|
|
|
1659
1726
|
}),
|
|
1660
1727
|
onSuccess: (data) => {
|
|
1661
1728
|
var _a;
|
|
1662
|
-
this.queryClient.invalidateQueries({
|
|
1729
|
+
this.queryClient.invalidateQueries({
|
|
1730
|
+
queryKey: collectionKeys(collection).all
|
|
1731
|
+
});
|
|
1663
1732
|
(_a = options == null ? void 0 : options.onSuccess) == null ? void 0 : _a.call(options, data);
|
|
1664
1733
|
},
|
|
1665
1734
|
onError: options == null ? void 0 : options.onError,
|
|
@@ -1674,7 +1743,9 @@ var CollectionHooks = class {
|
|
|
1674
1743
|
}),
|
|
1675
1744
|
onSuccess: (data) => {
|
|
1676
1745
|
var _a;
|
|
1677
|
-
this.queryClient.invalidateQueries({
|
|
1746
|
+
this.queryClient.invalidateQueries({
|
|
1747
|
+
queryKey: collectionKeys(collection).all
|
|
1748
|
+
});
|
|
1678
1749
|
(_a = options == null ? void 0 : options.onSuccess) == null ? void 0 : _a.call(options, data);
|
|
1679
1750
|
},
|
|
1680
1751
|
onError: options == null ? void 0 : options.onError,
|
|
@@ -1688,9 +1759,13 @@ var CollectionHooks = class {
|
|
|
1688
1759
|
}
|
|
1689
1760
|
getQueryData(collection, type, idOrOptions, options) {
|
|
1690
1761
|
if (type === "list") {
|
|
1691
|
-
return this.queryClient.getQueryData(
|
|
1762
|
+
return this.queryClient.getQueryData(
|
|
1763
|
+
collectionKeys(collection).list(idOrOptions)
|
|
1764
|
+
);
|
|
1692
1765
|
}
|
|
1693
|
-
return this.queryClient.getQueryData(
|
|
1766
|
+
return this.queryClient.getQueryData(
|
|
1767
|
+
collectionKeys(collection).detail(idOrOptions, options)
|
|
1768
|
+
);
|
|
1694
1769
|
}
|
|
1695
1770
|
setQueryData(collection, type, dataOrId, dataOrOptions, options) {
|
|
1696
1771
|
if (type === "list") {
|
|
@@ -1866,14 +1941,18 @@ var BrowserClient = class {
|
|
|
1866
1941
|
throw createConfigError("clientKey is required.");
|
|
1867
1942
|
}
|
|
1868
1943
|
this.config = __spreadValues({}, options);
|
|
1869
|
-
this.baseUrl = resolveApiUrl(
|
|
1944
|
+
this.baseUrl = resolveApiUrl();
|
|
1870
1945
|
const metadata = {
|
|
1871
1946
|
timestamp: Date.now(),
|
|
1872
1947
|
userAgent: typeof window !== "undefined" ? (_a = window.navigator) == null ? void 0 : _a.userAgent : "Node.js"
|
|
1873
1948
|
};
|
|
1874
1949
|
this.state = { metadata };
|
|
1875
1950
|
this.queryClient = getQueryClient();
|
|
1876
|
-
this.customer = new CustomerAuth(
|
|
1951
|
+
this.customer = new CustomerAuth(
|
|
1952
|
+
this.config.clientKey,
|
|
1953
|
+
this.baseUrl,
|
|
1954
|
+
options.customer
|
|
1955
|
+
);
|
|
1877
1956
|
const onUnauthorized = () => __async(this, null, function* () {
|
|
1878
1957
|
var _a2;
|
|
1879
1958
|
try {
|
|
@@ -1896,7 +1975,11 @@ var BrowserClient = class {
|
|
|
1896
1975
|
() => this.customer.getToken(),
|
|
1897
1976
|
onUnauthorized
|
|
1898
1977
|
);
|
|
1899
|
-
this.query = new QueryHooks(
|
|
1978
|
+
this.query = new QueryHooks(
|
|
1979
|
+
this.queryClient,
|
|
1980
|
+
this.collections,
|
|
1981
|
+
this.customer
|
|
1982
|
+
);
|
|
1900
1983
|
}
|
|
1901
1984
|
from(collection) {
|
|
1902
1985
|
return this.collections.from(collection);
|
|
@@ -1927,7 +2010,7 @@ var ServerClient = class {
|
|
|
1927
2010
|
throw createConfigError("secretKey is required.");
|
|
1928
2011
|
}
|
|
1929
2012
|
this.config = __spreadValues({}, options);
|
|
1930
|
-
this.baseUrl = resolveApiUrl(
|
|
2013
|
+
this.baseUrl = resolveApiUrl();
|
|
1931
2014
|
const metadata = {
|
|
1932
2015
|
timestamp: Date.now(),
|
|
1933
2016
|
userAgent: "Node.js"
|
|
@@ -2029,17 +2112,19 @@ function handleWebhook(request, handler, options) {
|
|
|
2029
2112
|
);
|
|
2030
2113
|
} catch (error) {
|
|
2031
2114
|
console.error("Webhook processing error:", error);
|
|
2032
|
-
return new Response(
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
);
|
|
2115
|
+
return new Response(JSON.stringify({ error: "Internal server error" }), {
|
|
2116
|
+
status: 500,
|
|
2117
|
+
headers: { "Content-Type": "application/json" }
|
|
2118
|
+
});
|
|
2036
2119
|
}
|
|
2037
2120
|
});
|
|
2038
2121
|
}
|
|
2039
2122
|
function createTypedWebhookHandler(collection, handler) {
|
|
2040
2123
|
return (event) => __async(null, null, function* () {
|
|
2041
2124
|
if (event.collection !== collection) {
|
|
2042
|
-
throw new Error(
|
|
2125
|
+
throw new Error(
|
|
2126
|
+
`Expected collection "${collection}", got "${event.collection}"`
|
|
2127
|
+
);
|
|
2043
2128
|
}
|
|
2044
2129
|
return handler(event);
|
|
2045
2130
|
});
|