@01.software/sdk 0.2.9-dev.260311.bb95a4e → 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/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('Invalid API key. Expected Base64 encoded "clientKey:secretKey"');
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("SERVICE_UNAVAILABLE_ERROR", message, 503, details, userMessage, suggestion);
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
  }
@@ -336,7 +345,7 @@ function resolveApiUrl() {
336
345
  if (envUrl) {
337
346
  return envUrl.replace(/\/$/, "");
338
347
  }
339
- return "http://localhost:3000";
348
+ return "https://api-dev.01.software";
340
349
  }
341
350
 
342
351
  // src/core/internal/utils/http.ts
@@ -356,8 +365,7 @@ function debugLog(debug, type, message, data) {
356
365
  function getErrorSuggestion(status) {
357
366
  if (status === 401) return "Please check your authentication credentials.";
358
367
  if (status === 404) return "The requested resource was not found.";
359
- if (status >= 500)
360
- return "A server error occurred. Please try again later.";
368
+ if (status >= 500) return "A server error occurred. Please try again later.";
361
369
  return void 0;
362
370
  }
363
371
  function delay(ms) {
@@ -436,9 +444,18 @@ function httpFetch(url, options) {
436
444
  });
437
445
  if (!response.ok) {
438
446
  if (response.status === 429 && response.headers.get("X-Usage-Limit")) {
439
- const limit = parseInt(response.headers.get("X-Usage-Limit") || "0", 10);
440
- const current = parseInt(response.headers.get("X-Usage-Current") || "0", 10);
441
- const remaining = parseInt(response.headers.get("X-Usage-Remaining") || "0", 10);
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
+ );
442
459
  throw createUsageLimitError(
443
460
  `Monthly API usage limit exceeded (${current.toLocaleString()}/${limit.toLocaleString()})`,
444
461
  { limit, current, remaining },
@@ -621,7 +638,10 @@ var OrderApi = class extends BaseApi {
621
638
  return this.request("/api/orders/update-fulfillment", params);
622
639
  }
623
640
  returnWithRefund(params) {
624
- return this.request("/api/returns/return-refund", params);
641
+ return this.request(
642
+ "/api/returns/return-refund",
643
+ params
644
+ );
625
645
  }
626
646
  createReturn(params) {
627
647
  return this.request("/api/returns/create", params);
@@ -630,10 +650,16 @@ var OrderApi = class extends BaseApi {
630
650
  return this.request("/api/returns/update", params);
631
651
  }
632
652
  validateDiscount(params) {
633
- return this.request("/api/discounts/validate", params);
653
+ return this.request(
654
+ "/api/discounts/validate",
655
+ params
656
+ );
634
657
  }
635
658
  calculateShipping(params) {
636
- return this.request("/api/shipping-policies/calculate", params);
659
+ return this.request(
660
+ "/api/shipping-policies/calculate",
661
+ params
662
+ );
637
663
  }
638
664
  createExchange(params) {
639
665
  return this.request("/api/exchanges/create", params);
@@ -650,7 +676,9 @@ var CartApi = class {
650
676
  throw createConfigError("clientKey is required for CartApi.");
651
677
  }
652
678
  if (!options.secretKey && !options.customerToken) {
653
- throw createConfigError("Either secretKey or customerToken is required for CartApi.");
679
+ throw createConfigError(
680
+ "Either secretKey or customerToken is required for CartApi."
681
+ );
654
682
  }
655
683
  this.clientKey = options.clientKey;
656
684
  this.secretKey = options.secretKey;
@@ -703,7 +731,11 @@ var CartApi = class {
703
731
  return this.execute("/api/carts/update-item", "POST", params);
704
732
  }
705
733
  removeItem(params) {
706
- return this.execute("/api/carts/remove-item", "POST", params);
734
+ return this.execute(
735
+ "/api/carts/remove-item",
736
+ "POST",
737
+ params
738
+ );
707
739
  }
708
740
  applyDiscount(params) {
709
741
  return this.execute("/api/carts/apply-discount", "POST", params);
@@ -712,7 +744,11 @@ var CartApi = class {
712
744
  return this.execute("/api/carts/remove-discount", "POST", params);
713
745
  }
714
746
  clearCart(params) {
715
- return this.execute("/api/carts/clear", "POST", params);
747
+ return this.execute(
748
+ "/api/carts/clear",
749
+ "POST",
750
+ params
751
+ );
716
752
  }
717
753
  };
718
754
 
@@ -949,7 +985,11 @@ var HttpClient = class {
949
985
  }
950
986
  get defaultOptions() {
951
987
  var _a;
952
- const opts = { clientKey: this.clientKey, secretKey: this.secretKey, baseUrl: this.baseUrl };
988
+ const opts = {
989
+ clientKey: this.clientKey,
990
+ secretKey: this.secretKey,
991
+ baseUrl: this.baseUrl
992
+ };
953
993
  const token = (_a = this.getCustomerToken) == null ? void 0 : _a.call(this);
954
994
  if (token) {
955
995
  opts.customerToken = token;
@@ -967,7 +1007,9 @@ var HttpClient = class {
967
1007
  assertJsonResponse(response) {
968
1008
  const contentType = response.headers.get("content-type");
969
1009
  if (!(contentType == null ? void 0 : contentType.includes("application/json"))) {
970
- throw createApiError("Response is not in JSON format.", response.status, { contentType });
1010
+ throw createApiError("Response is not in JSON format.", response.status, {
1011
+ contentType
1012
+ });
971
1013
  }
972
1014
  }
973
1015
  /**
@@ -982,7 +1024,9 @@ var HttpClient = class {
982
1024
  this.assertJsonResponse(response);
983
1025
  const jsonData = yield response.json();
984
1026
  if (jsonData.docs === void 0) {
985
- throw createApiError("Invalid find response.", response.status, { jsonData });
1027
+ throw createApiError("Invalid find response.", response.status, {
1028
+ jsonData
1029
+ });
986
1030
  }
987
1031
  return {
988
1032
  docs: jsonData.docs,
@@ -1016,7 +1060,9 @@ var HttpClient = class {
1016
1060
  this.assertJsonResponse(response);
1017
1061
  const jsonData = yield response.json();
1018
1062
  if (jsonData.doc === void 0) {
1019
- throw createApiError("Invalid mutation response.", response.status, { jsonData });
1063
+ throw createApiError("Invalid mutation response.", response.status, {
1064
+ jsonData
1065
+ });
1020
1066
  }
1021
1067
  return {
1022
1068
  message: jsonData.message || "",
@@ -1080,7 +1126,9 @@ var CollectionClient = class extends HttpClient {
1080
1126
  requestFind(endpoint, options) {
1081
1127
  return __async(this, null, function* () {
1082
1128
  const url = this.buildUrl(endpoint, options);
1083
- const response = yield httpFetch(url, __spreadProps(__spreadValues({}, this.defaultOptions), { method: "GET" }));
1129
+ const response = yield httpFetch(url, __spreadProps(__spreadValues({}, this.defaultOptions), {
1130
+ method: "GET"
1131
+ }));
1084
1132
  return this.parseFindResponse(response);
1085
1133
  });
1086
1134
  }
@@ -1091,7 +1139,9 @@ var CollectionClient = class extends HttpClient {
1091
1139
  requestFindById(endpoint, options) {
1092
1140
  return __async(this, null, function* () {
1093
1141
  const url = this.buildUrl(endpoint, options);
1094
- const response = yield httpFetch(url, __spreadProps(__spreadValues({}, this.defaultOptions), { method: "GET" }));
1142
+ const response = yield httpFetch(url, __spreadProps(__spreadValues({}, this.defaultOptions), {
1143
+ method: "GET"
1144
+ }));
1095
1145
  return this.parseDocumentResponse(response);
1096
1146
  });
1097
1147
  }
@@ -1128,7 +1178,9 @@ var CollectionClient = class extends HttpClient {
1128
1178
  requestCount(endpoint, options) {
1129
1179
  return __async(this, null, function* () {
1130
1180
  const url = this.buildUrl(endpoint, options);
1131
- const response = yield httpFetch(url, __spreadProps(__spreadValues({}, this.defaultOptions), { method: "GET" }));
1181
+ const response = yield httpFetch(url, __spreadProps(__spreadValues({}, this.defaultOptions), {
1182
+ method: "GET"
1183
+ }));
1132
1184
  return this.parseDocumentResponse(response);
1133
1185
  });
1134
1186
  }
@@ -1203,13 +1255,11 @@ var COLLECTIONS = [
1203
1255
  "tenants",
1204
1256
  "tenant-metadata",
1205
1257
  "tenant-logos",
1206
- "tenant-og-images",
1207
1258
  "products",
1208
1259
  "product-variants",
1209
1260
  "product-options",
1210
1261
  "product-categories",
1211
1262
  "product-tags",
1212
- "product-images",
1213
1263
  "product-collections",
1214
1264
  "brands",
1215
1265
  "brand-logos",
@@ -1225,7 +1275,6 @@ var COLLECTIONS = [
1225
1275
  "customers",
1226
1276
  "customer-addresses",
1227
1277
  "customer-groups",
1228
- "customer-group-images",
1229
1278
  "carts",
1230
1279
  "cart-items",
1231
1280
  "discounts",
@@ -1233,35 +1282,29 @@ var COLLECTIONS = [
1233
1282
  "documents",
1234
1283
  "document-categories",
1235
1284
  "document-types",
1236
- "document-images",
1237
1285
  "posts",
1238
1286
  "post-categories",
1239
1287
  "post-tags",
1240
- "post-images",
1241
1288
  "playlists",
1242
- "playlist-images",
1243
1289
  "playlist-categories",
1244
1290
  "playlist-tags",
1245
1291
  "musics",
1246
1292
  "galleries",
1247
- "gallery-images",
1248
1293
  "gallery-categories",
1249
1294
  "gallery-tags",
1295
+ "gallery-items",
1250
1296
  "flows",
1251
- "flow-images",
1252
1297
  "flow-node-types",
1253
1298
  "flow-edge-types",
1254
1299
  "flow-categories",
1255
1300
  "flow-tags",
1256
1301
  "videos",
1257
- "video-images",
1258
1302
  "video-categories",
1259
1303
  "video-tags",
1260
1304
  "live-streams",
1261
- "live-stream-images",
1305
+ "images",
1262
1306
  "forms",
1263
- "form-submissions",
1264
- "media"
1307
+ "form-submissions"
1265
1308
  ];
1266
1309
 
1267
1310
  // src/core/customer/customer-auth.ts
@@ -1269,19 +1312,20 @@ var DEFAULT_TIMEOUT2 = 15e3;
1269
1312
  var CustomerAuth = class {
1270
1313
  constructor(clientKey, baseUrl, options) {
1271
1314
  this.refreshPromise = null;
1272
- var _a, _b;
1315
+ var _a, _b, _c;
1273
1316
  this.clientKey = clientKey;
1274
1317
  this.baseUrl = baseUrl;
1275
- if (options == null ? void 0 : options.persist) {
1276
- const key = typeof options.persist === "string" ? options.persist : "customer-token";
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";
1277
1321
  const isBrowser = typeof window !== "undefined";
1278
- this.token = isBrowser ? (_a = localStorage.getItem(key)) != null ? _a : null : null;
1322
+ this.token = isBrowser ? (_b = localStorage.getItem(key)) != null ? _b : null : null;
1279
1323
  this.onTokenChange = isBrowser ? (token) => {
1280
1324
  if (token) localStorage.setItem(key, token);
1281
1325
  else localStorage.removeItem(key);
1282
1326
  } : void 0;
1283
1327
  } else {
1284
- this.token = (_b = options == null ? void 0 : options.token) != null ? _b : null;
1328
+ this.token = (_c = options == null ? void 0 : options.token) != null ? _c : null;
1285
1329
  this.onTokenChange = options == null ? void 0 : options.onTokenChange;
1286
1330
  }
1287
1331
  }
@@ -1301,10 +1345,13 @@ var CustomerAuth = class {
1301
1345
  */
1302
1346
  login(data) {
1303
1347
  return __async(this, null, function* () {
1304
- const result = yield this.requestJson("/api/customers/login", {
1305
- method: "POST",
1306
- body: JSON.stringify(data)
1307
- });
1348
+ const result = yield this.requestJson(
1349
+ "/api/customers/login",
1350
+ {
1351
+ method: "POST",
1352
+ body: JSON.stringify(data)
1353
+ }
1354
+ );
1308
1355
  this.setToken(result.token);
1309
1356
  return result;
1310
1357
  });
@@ -1326,10 +1373,13 @@ var CustomerAuth = class {
1326
1373
  }
1327
1374
  _doRefreshToken() {
1328
1375
  return __async(this, null, function* () {
1329
- const result = yield this.requestJson("/api/customers/refresh", {
1330
- method: "POST",
1331
- headers: { Authorization: `Bearer ${this.token}` }
1332
- });
1376
+ const result = yield this.requestJson(
1377
+ "/api/customers/refresh",
1378
+ {
1379
+ method: "POST",
1380
+ headers: { Authorization: `Bearer ${this.token}` }
1381
+ }
1382
+ );
1333
1383
  this.setToken(result.token);
1334
1384
  return result;
1335
1385
  });
@@ -1348,10 +1398,13 @@ var CustomerAuth = class {
1348
1398
  var _a;
1349
1399
  if (!this.token) return null;
1350
1400
  try {
1351
- const data = yield this.requestJson("/api/customers/me", {
1352
- method: "GET",
1353
- headers: { Authorization: `Bearer ${this.token}` }
1354
- });
1401
+ const data = yield this.requestJson(
1402
+ "/api/customers/me",
1403
+ {
1404
+ method: "GET",
1405
+ headers: { Authorization: `Bearer ${this.token}` }
1406
+ }
1407
+ );
1355
1408
  return (_a = data.customer) != null ? _a : null;
1356
1409
  } catch (error) {
1357
1410
  if (error instanceof ApiError && error.status === 401) {
@@ -1390,11 +1443,14 @@ var CustomerAuth = class {
1390
1443
  updateProfile(data) {
1391
1444
  return __async(this, null, function* () {
1392
1445
  if (!this.token) throw new ApiError("Not authenticated", 401);
1393
- const result = yield this.requestJson("/api/customers/me", {
1394
- method: "PATCH",
1395
- headers: { Authorization: `Bearer ${this.token}` },
1396
- body: JSON.stringify(data)
1397
- });
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
+ );
1398
1454
  return result.customer;
1399
1455
  });
1400
1456
  }
@@ -1481,10 +1537,10 @@ var CustomerAuth = class {
1481
1537
  } catch (error) {
1482
1538
  clearTimeout(timeoutId);
1483
1539
  if (error instanceof Error && error.name === "AbortError") {
1484
- throw new TimeoutError(
1485
- `Request timed out after ${DEFAULT_TIMEOUT2}ms`,
1486
- { url: path, timeout: DEFAULT_TIMEOUT2 }
1487
- );
1540
+ throw new TimeoutError(`Request timed out after ${DEFAULT_TIMEOUT2}ms`, {
1541
+ url: path,
1542
+ timeout: DEFAULT_TIMEOUT2
1543
+ });
1488
1544
  }
1489
1545
  throw new NetworkError(
1490
1546
  error instanceof Error ? error.message : "Network request failed",
@@ -1507,7 +1563,12 @@ var CustomerAuth = class {
1507
1563
  try {
1508
1564
  return yield res.json();
1509
1565
  } catch (e) {
1510
- throw new ApiError("Invalid JSON response from server", res.status, void 0, "INVALID_RESPONSE");
1566
+ throw new ApiError(
1567
+ "Invalid JSON response from server",
1568
+ res.status,
1569
+ void 0,
1570
+ "INVALID_RESPONSE"
1571
+ );
1511
1572
  }
1512
1573
  });
1513
1574
  }
@@ -1616,7 +1677,11 @@ var CollectionHooks = class {
1616
1677
  }
1617
1678
  // ===== useInfiniteQuery =====
1618
1679
  useInfiniteQuery(params, options) {
1619
- const { collection, options: queryOptions, pageSize = DEFAULT_PAGE_SIZE } = params;
1680
+ const {
1681
+ collection,
1682
+ options: queryOptions,
1683
+ pageSize = DEFAULT_PAGE_SIZE
1684
+ } = params;
1620
1685
  return (0, import_react_query2.useInfiniteQuery)(__spreadValues({
1621
1686
  queryKey: collectionKeys(collection).infinite(queryOptions),
1622
1687
  queryFn: (_0) => __async(this, [_0], function* ({ pageParam }) {
@@ -1631,7 +1696,11 @@ var CollectionHooks = class {
1631
1696
  }
1632
1697
  // ===== useSuspenseInfiniteQuery =====
1633
1698
  useSuspenseInfiniteQuery(params, options) {
1634
- const { collection, options: queryOptions, pageSize = DEFAULT_PAGE_SIZE } = params;
1699
+ const {
1700
+ collection,
1701
+ options: queryOptions,
1702
+ pageSize = DEFAULT_PAGE_SIZE
1703
+ } = params;
1635
1704
  return (0, import_react_query2.useSuspenseInfiniteQuery)(__spreadValues({
1636
1705
  queryKey: collectionKeys(collection).infinite(queryOptions),
1637
1706
  queryFn: (_0) => __async(this, [_0], function* ({ pageParam }) {
@@ -1674,7 +1743,11 @@ var CollectionHooks = class {
1674
1743
  prefetchInfiniteQuery(params, options) {
1675
1744
  return __async(this, null, function* () {
1676
1745
  var _a;
1677
- const { collection, options: queryOptions, pageSize = DEFAULT_PAGE_SIZE } = params;
1746
+ const {
1747
+ collection,
1748
+ options: queryOptions,
1749
+ pageSize = DEFAULT_PAGE_SIZE
1750
+ } = params;
1678
1751
  return this.queryClient.prefetchInfiniteQuery({
1679
1752
  queryKey: collectionKeys(collection).infinite(queryOptions),
1680
1753
  queryFn: (_0) => __async(this, [_0], function* ({ pageParam }) {
@@ -1702,7 +1775,9 @@ var CollectionHooks = class {
1702
1775
  }),
1703
1776
  onSuccess: (data) => {
1704
1777
  var _a;
1705
- this.queryClient.invalidateQueries({ queryKey: collectionKeys(collection).all });
1778
+ this.queryClient.invalidateQueries({
1779
+ queryKey: collectionKeys(collection).all
1780
+ });
1706
1781
  (_a = options == null ? void 0 : options.onSuccess) == null ? void 0 : _a.call(options, data);
1707
1782
  },
1708
1783
  onError: options == null ? void 0 : options.onError,
@@ -1721,7 +1796,9 @@ var CollectionHooks = class {
1721
1796
  }),
1722
1797
  onSuccess: (data) => {
1723
1798
  var _a;
1724
- this.queryClient.invalidateQueries({ queryKey: collectionKeys(collection).all });
1799
+ this.queryClient.invalidateQueries({
1800
+ queryKey: collectionKeys(collection).all
1801
+ });
1725
1802
  (_a = options == null ? void 0 : options.onSuccess) == null ? void 0 : _a.call(options, data);
1726
1803
  },
1727
1804
  onError: options == null ? void 0 : options.onError,
@@ -1736,7 +1813,9 @@ var CollectionHooks = class {
1736
1813
  }),
1737
1814
  onSuccess: (data) => {
1738
1815
  var _a;
1739
- this.queryClient.invalidateQueries({ queryKey: collectionKeys(collection).all });
1816
+ this.queryClient.invalidateQueries({
1817
+ queryKey: collectionKeys(collection).all
1818
+ });
1740
1819
  (_a = options == null ? void 0 : options.onSuccess) == null ? void 0 : _a.call(options, data);
1741
1820
  },
1742
1821
  onError: options == null ? void 0 : options.onError,
@@ -1750,9 +1829,13 @@ var CollectionHooks = class {
1750
1829
  }
1751
1830
  getQueryData(collection, type, idOrOptions, options) {
1752
1831
  if (type === "list") {
1753
- return this.queryClient.getQueryData(collectionKeys(collection).list(idOrOptions));
1832
+ return this.queryClient.getQueryData(
1833
+ collectionKeys(collection).list(idOrOptions)
1834
+ );
1754
1835
  }
1755
- return this.queryClient.getQueryData(collectionKeys(collection).detail(idOrOptions, options));
1836
+ return this.queryClient.getQueryData(
1837
+ collectionKeys(collection).detail(idOrOptions, options)
1838
+ );
1756
1839
  }
1757
1840
  setQueryData(collection, type, dataOrId, dataOrOptions, options) {
1758
1841
  if (type === "list") {
@@ -1932,7 +2015,11 @@ var BrowserClient = class {
1932
2015
  };
1933
2016
  this.state = { metadata };
1934
2017
  this.queryClient = getQueryClient();
1935
- this.customer = new CustomerAuth(this.config.clientKey, this.baseUrl, options.customer);
2018
+ this.customer = new CustomerAuth(
2019
+ this.config.clientKey,
2020
+ this.baseUrl,
2021
+ options.customer
2022
+ );
1936
2023
  const onUnauthorized = () => __async(this, null, function* () {
1937
2024
  var _a2;
1938
2025
  try {
@@ -1955,7 +2042,11 @@ var BrowserClient = class {
1955
2042
  () => this.customer.getToken(),
1956
2043
  onUnauthorized
1957
2044
  );
1958
- this.query = new QueryHooks(this.queryClient, this.collections, this.customer);
2045
+ this.query = new QueryHooks(
2046
+ this.queryClient,
2047
+ this.collections,
2048
+ this.customer
2049
+ );
1959
2050
  }
1960
2051
  from(collection) {
1961
2052
  return this.collections.from(collection);
@@ -2088,17 +2179,19 @@ function handleWebhook(request, handler, options) {
2088
2179
  );
2089
2180
  } catch (error) {
2090
2181
  console.error("Webhook processing error:", error);
2091
- return new Response(
2092
- JSON.stringify({ error: "Internal server error" }),
2093
- { status: 500, headers: { "Content-Type": "application/json" } }
2094
- );
2182
+ return new Response(JSON.stringify({ error: "Internal server error" }), {
2183
+ status: 500,
2184
+ headers: { "Content-Type": "application/json" }
2185
+ });
2095
2186
  }
2096
2187
  });
2097
2188
  }
2098
2189
  function createTypedWebhookHandler(collection, handler) {
2099
2190
  return (event) => __async(null, null, function* () {
2100
2191
  if (event.collection !== collection) {
2101
- throw new Error(`Expected collection "${collection}", got "${event.collection}"`);
2192
+ throw new Error(
2193
+ `Expected collection "${collection}", got "${event.collection}"`
2194
+ );
2102
2195
  }
2103
2196
  return handler(event);
2104
2197
  });