@01.software/sdk 0.2.9-dev.260306.4e16dd4 → 0.2.9-dev.260309.c56872d

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
@@ -78,12 +78,14 @@ __export(src_exports, {
78
78
  CollectionQueryBuilder: () => CollectionQueryBuilder,
79
79
  ConfigError: () => ConfigError,
80
80
  CustomerAuth: () => CustomerAuth,
81
+ GoneError: () => GoneError,
81
82
  IMAGE_SIZES: () => IMAGE_SIZES,
82
83
  NetworkError: () => NetworkError,
83
84
  OrderApi: () => OrderApi,
84
85
  ProductApi: () => ProductApi,
85
86
  QueryHooks: () => QueryHooks,
86
87
  ServerClient: () => ServerClient,
88
+ ServiceUnavailableError: () => ServiceUnavailableError,
87
89
  TimeoutError: () => TimeoutError,
88
90
  UsageLimitError: () => UsageLimitError,
89
91
  ValidationError: () => ValidationError,
@@ -103,11 +105,18 @@ __export(src_exports, {
103
105
  getImageSrcSet: () => getImageSrcSet,
104
106
  getImageUrl: () => getImageUrl,
105
107
  getQueryClient: () => getQueryClient,
108
+ getVideoGif: () => getVideoGif,
109
+ getVideoMp4Url: () => getVideoMp4Url,
110
+ getVideoStoryboard: () => getVideoStoryboard,
111
+ getVideoStreamUrl: () => getVideoStreamUrl,
112
+ getVideoThumbnail: () => getVideoThumbnail,
106
113
  handleWebhook: () => handleWebhook,
107
114
  isApiError: () => isApiError,
108
115
  isConfigError: () => isConfigError,
116
+ isGoneError: () => isGoneError,
109
117
  isNetworkError: () => isNetworkError,
110
118
  isSDKError: () => isSDKError,
119
+ isServiceUnavailableError: () => isServiceUnavailableError,
111
120
  isTimeoutError: () => isTimeoutError,
112
121
  isUsageLimitError: () => isUsageLimitError,
113
122
  isValidWebhookEvent: () => isValidWebhookEvent,
@@ -181,6 +190,19 @@ var TimeoutError = class extends SDKError {
181
190
  this.name = "TimeoutError";
182
191
  }
183
192
  };
193
+ var GoneError = class extends SDKError {
194
+ constructor(message = "The requested resource is no longer available.", details, userMessage, suggestion) {
195
+ super("GONE_ERROR", message, 410, details, userMessage, suggestion);
196
+ this.name = "GoneError";
197
+ }
198
+ };
199
+ var ServiceUnavailableError = class extends SDKError {
200
+ constructor(message = "Service temporarily unavailable.", retryAfter, details, userMessage, suggestion) {
201
+ super("SERVICE_UNAVAILABLE_ERROR", message, 503, details, userMessage, suggestion);
202
+ this.name = "ServiceUnavailableError";
203
+ this.retryAfter = retryAfter;
204
+ }
205
+ };
184
206
  var UsageLimitError = class extends SDKError {
185
207
  constructor(message, usage, details, userMessage, suggestion) {
186
208
  super("USAGE_LIMIT_ERROR", message, 429, details, userMessage, suggestion);
@@ -211,6 +233,12 @@ function isConfigError(error) {
211
233
  function isTimeoutError(error) {
212
234
  return error instanceof TimeoutError;
213
235
  }
236
+ function isGoneError(error) {
237
+ return error instanceof GoneError;
238
+ }
239
+ function isServiceUnavailableError(error) {
240
+ return error instanceof ServiceUnavailableError;
241
+ }
214
242
  function isUsageLimitError(error) {
215
243
  return error instanceof UsageLimitError;
216
244
  }
@@ -224,8 +252,8 @@ var createUsageLimitError = (message, usage, details, userMessage, suggestion) =
224
252
  // src/core/client/types.ts
225
253
  var API_URLS = {
226
254
  local: "http://localhost:3000",
227
- development: "https://dev.01.software",
228
- staging: "https://stg.01.software",
255
+ development: "https://api-dev.01.software",
256
+ staging: "https://api-stg.01.software",
229
257
  production: "https://api.01.software"
230
258
  };
231
259
  function resolveApiUrl(config) {
@@ -354,7 +382,8 @@ function _fetch(url, options) {
354
382
  timeout = DEFAULT_TIMEOUT,
355
383
  baseUrl = API_URLS.production,
356
384
  debug,
357
- retry
385
+ retry,
386
+ onUnauthorized
358
387
  } = _a, requestInit = __objRest(_a, [
359
388
  "clientKey",
360
389
  "secretKey",
@@ -362,7 +391,8 @@ function _fetch(url, options) {
362
391
  "timeout",
363
392
  "baseUrl",
364
393
  "debug",
365
- "retry"
394
+ "retry",
395
+ "onUnauthorized"
366
396
  ]);
367
397
  const retryConfig = {
368
398
  maxRetries: (_b = retry == null ? void 0 : retry.maxRetries) != null ? _b : 3,
@@ -376,6 +406,7 @@ function _fetch(url, options) {
376
406
  authToken = customerToken;
377
407
  }
378
408
  let lastError;
409
+ let hasRetried401 = false;
379
410
  for (let attempt = 0; attempt <= retryConfig.maxRetries; attempt++) {
380
411
  try {
381
412
  const headers = new Headers(requestInit.headers);
@@ -423,6 +454,17 @@ function _fetch(url, options) {
423
454
  "Upgrade your tenant plan to increase the monthly API call limit."
424
455
  );
425
456
  }
457
+ if (response.status === 401 && onUnauthorized && customerToken && !hasRetried401) {
458
+ hasRetried401 = true;
459
+ try {
460
+ const newToken = yield onUnauthorized();
461
+ if (newToken) {
462
+ authToken = newToken;
463
+ continue;
464
+ }
465
+ } catch (e) {
466
+ }
467
+ }
426
468
  if (NON_RETRYABLE_STATUSES.includes(response.status)) {
427
469
  throw createNetworkError(
428
470
  `HTTP ${response.status}: ${response.statusText}`,
@@ -575,6 +617,9 @@ var OrderApi = class {
575
617
  createFulfillment(params) {
576
618
  return this.request("/api/orders/create-fulfillment", params);
577
619
  }
620
+ updateFulfillment(params) {
621
+ return this.request("/api/orders/update-fulfillment", params);
622
+ }
578
623
  returnWithRefund(params) {
579
624
  return this.request("/api/returns/return-refund", params);
580
625
  }
@@ -584,6 +629,18 @@ var OrderApi = class {
584
629
  updateReturn(params) {
585
630
  return this.request("/api/returns/update", params);
586
631
  }
632
+ validateDiscount(params) {
633
+ return this.request("/api/discounts/validate", params);
634
+ }
635
+ calculateShipping(params) {
636
+ return this.request("/api/shipping-policies/calculate", params);
637
+ }
638
+ createExchange(params) {
639
+ return this.request("/api/exchanges/create", params);
640
+ }
641
+ updateExchange(params) {
642
+ return this.request("/api/exchanges/update", params);
643
+ }
587
644
  };
588
645
 
589
646
  // src/core/api/cart-api.ts
@@ -599,18 +656,18 @@ var CartApi = class {
599
656
  this.secretKey = options.secretKey;
600
657
  this.customerToken = options.customerToken;
601
658
  this.baseUrl = options.baseUrl;
659
+ this.onUnauthorized = options.onUnauthorized;
602
660
  }
603
- request(endpoint, body) {
661
+ execute(endpoint, method, body) {
604
662
  return __async(this, null, function* () {
605
663
  const token = typeof this.customerToken === "function" ? this.customerToken() : this.customerToken;
606
- const response = yield _fetch(endpoint, {
607
- method: "POST",
664
+ const response = yield _fetch(endpoint, __spreadValues(__spreadValues({
665
+ method,
608
666
  clientKey: this.clientKey,
609
667
  secretKey: this.secretKey,
610
668
  customerToken: token != null ? token : void 0,
611
- baseUrl: this.baseUrl,
612
- body: JSON.stringify(body)
613
- });
669
+ baseUrl: this.baseUrl
670
+ }, token && this.onUnauthorized && { onUnauthorized: this.onUnauthorized }), body !== void 0 && { body: JSON.stringify(body) }));
614
671
  let data;
615
672
  try {
616
673
  data = yield response.json();
@@ -636,14 +693,26 @@ var CartApi = class {
636
693
  return data;
637
694
  });
638
695
  }
696
+ getCart(cartId) {
697
+ return this.execute(`/api/carts/${cartId}`, "GET");
698
+ }
639
699
  addItem(params) {
640
- return this.request("/api/carts/add-item", params);
700
+ return this.execute("/api/carts/add-item", "POST", params);
641
701
  }
642
702
  updateItem(params) {
643
- return this.request("/api/carts/update-item", params);
703
+ return this.execute("/api/carts/update-item", "POST", params);
644
704
  }
645
705
  removeItem(params) {
646
- return this.request("/api/carts/remove-item", params);
706
+ return this.execute("/api/carts/remove-item", "POST", params);
707
+ }
708
+ applyDiscount(params) {
709
+ return this.execute("/api/carts/apply-discount", "POST", params);
710
+ }
711
+ removeDiscount(params) {
712
+ return this.execute("/api/carts/remove-discount", "POST", params);
713
+ }
714
+ clearCart(params) {
715
+ return this.execute("/api/carts/clear", "POST", params);
647
716
  }
648
717
  };
649
718
 
@@ -908,7 +977,7 @@ var CollectionQueryBuilder = class {
908
977
  // src/core/collection/http-client.ts
909
978
  var import_qs_esm = require("qs-esm");
910
979
  var HttpClient = class {
911
- constructor(clientKey, secretKey, baseUrl, getCustomerToken) {
980
+ constructor(clientKey, secretKey, baseUrl, getCustomerToken, onUnauthorized) {
912
981
  if (!clientKey) {
913
982
  throw createValidationError("clientKey is required.");
914
983
  }
@@ -916,6 +985,7 @@ var HttpClient = class {
916
985
  this.secretKey = secretKey;
917
986
  this.baseUrl = baseUrl;
918
987
  this.getCustomerToken = getCustomerToken;
988
+ this.onUnauthorized = onUnauthorized;
919
989
  }
920
990
  get defaultOptions() {
921
991
  var _a;
@@ -923,6 +993,9 @@ var HttpClient = class {
923
993
  const token = (_a = this.getCustomerToken) == null ? void 0 : _a.call(this);
924
994
  if (token) {
925
995
  opts.customerToken = token;
996
+ if (this.onUnauthorized) {
997
+ opts.onUnauthorized = this.onUnauthorized;
998
+ }
926
999
  }
927
1000
  return opts;
928
1001
  }
@@ -1028,8 +1101,8 @@ function buildPayloadFormData(data, file, filename) {
1028
1101
  return formData;
1029
1102
  }
1030
1103
  var CollectionClient = class extends HttpClient {
1031
- constructor(clientKey, secretKey, baseUrl, getCustomerToken) {
1032
- super(clientKey, secretKey, baseUrl, getCustomerToken);
1104
+ constructor(clientKey, secretKey, baseUrl, getCustomerToken, onUnauthorized) {
1105
+ super(clientKey, secretKey, baseUrl, getCustomerToken, onUnauthorized);
1033
1106
  }
1034
1107
  from(collection) {
1035
1108
  return new CollectionQueryBuilder(this, collection);
@@ -1205,8 +1278,16 @@ var COLLECTIONS = [
1205
1278
  "playlists",
1206
1279
  "playlist-images",
1207
1280
  "musics",
1281
+ "galleries",
1282
+ "gallery-images",
1283
+ "gallery-categories",
1208
1284
  "flows",
1209
1285
  "flow-images",
1286
+ "flow-node-types",
1287
+ "flow-edge-types",
1288
+ "videos",
1289
+ "live-streams",
1290
+ "live-stream-images",
1210
1291
  "forms",
1211
1292
  "form-submissions",
1212
1293
  "media"
@@ -1216,6 +1297,7 @@ var COLLECTIONS = [
1216
1297
  var DEFAULT_TIMEOUT2 = 15e3;
1217
1298
  var CustomerAuth = class {
1218
1299
  constructor(clientKey, baseUrl, options) {
1300
+ this.refreshPromise = null;
1219
1301
  var _a, _b;
1220
1302
  this.clientKey = clientKey;
1221
1303
  this.baseUrl = baseUrl;
@@ -1262,6 +1344,17 @@ var CustomerAuth = class {
1262
1344
  refreshToken() {
1263
1345
  return __async(this, null, function* () {
1264
1346
  if (!this.token) throw new ApiError("Not authenticated", 401);
1347
+ if (this.refreshPromise) return this.refreshPromise;
1348
+ this.refreshPromise = this._doRefreshToken();
1349
+ try {
1350
+ return yield this.refreshPromise;
1351
+ } finally {
1352
+ this.refreshPromise = null;
1353
+ }
1354
+ });
1355
+ }
1356
+ _doRefreshToken() {
1357
+ return __async(this, null, function* () {
1265
1358
  const result = yield this.requestJson("/api/customers/refresh", {
1266
1359
  method: "POST",
1267
1360
  headers: { Authorization: `Bearer ${this.token}` }
@@ -1320,6 +1413,20 @@ var CustomerAuth = class {
1320
1413
  });
1321
1414
  });
1322
1415
  }
1416
+ /**
1417
+ * Update the authenticated customer's profile (name, phone, marketingConsent)
1418
+ */
1419
+ updateProfile(data) {
1420
+ return __async(this, null, function* () {
1421
+ if (!this.token) throw new ApiError("Not authenticated", 401);
1422
+ const result = yield this.requestJson("/api/customers/me", {
1423
+ method: "PATCH",
1424
+ headers: { Authorization: `Bearer ${this.token}` },
1425
+ body: JSON.stringify(data)
1426
+ });
1427
+ return result.customer;
1428
+ });
1429
+ }
1323
1430
  /**
1324
1431
  * Change the password of the currently authenticated customer
1325
1432
  */
@@ -1344,6 +1451,23 @@ var CustomerAuth = class {
1344
1451
  });
1345
1452
  });
1346
1453
  }
1454
+ /**
1455
+ * Get the authenticated customer's orders with pagination and optional status filter
1456
+ */
1457
+ getMyOrders(options) {
1458
+ return __async(this, null, function* () {
1459
+ if (!this.token) throw new ApiError("Not authenticated", 401);
1460
+ const params = new URLSearchParams();
1461
+ if (options == null ? void 0 : options.page) params.set("page", String(options.page));
1462
+ if (options == null ? void 0 : options.limit) params.set("limit", String(options.limit));
1463
+ if (options == null ? void 0 : options.status) params.set("status", options.status);
1464
+ const qs = params.toString();
1465
+ return this.requestJson(`/api/customers/me/orders${qs ? `?${qs}` : ""}`, {
1466
+ method: "GET",
1467
+ headers: { Authorization: `Bearer ${this.token}` }
1468
+ });
1469
+ });
1470
+ }
1347
1471
  /**
1348
1472
  * Get the current token (or null if not authenticated)
1349
1473
  */
@@ -1612,7 +1736,7 @@ var QueryHooks = class {
1612
1736
  }),
1613
1737
  onSuccess: (data) => {
1614
1738
  var _a;
1615
- this.queryClient.invalidateQueries({ queryKey: collectionKeys(collection).lists() });
1739
+ this.queryClient.invalidateQueries({ queryKey: collectionKeys(collection).all });
1616
1740
  (_a = options == null ? void 0 : options.onSuccess) == null ? void 0 : _a.call(options, data);
1617
1741
  },
1618
1742
  onError: options == null ? void 0 : options.onError,
@@ -1775,6 +1899,20 @@ var QueryHooks = class {
1775
1899
  onSettled: options == null ? void 0 : options.onSettled
1776
1900
  });
1777
1901
  }
1902
+ useCustomerUpdateProfile(options) {
1903
+ return (0, import_react_query2.useMutation)({
1904
+ mutationFn: (data) => __async(this, null, function* () {
1905
+ return yield this.ensureCustomerAuth().updateProfile(data);
1906
+ }),
1907
+ onSuccess: (data) => {
1908
+ var _a;
1909
+ this.queryClient.invalidateQueries({ queryKey: customerKeys.me() });
1910
+ (_a = options == null ? void 0 : options.onSuccess) == null ? void 0 : _a.call(options, data);
1911
+ },
1912
+ onError: options == null ? void 0 : options.onError,
1913
+ onSettled: options == null ? void 0 : options.onSettled
1914
+ });
1915
+ }
1778
1916
  useCustomerChangePassword(options) {
1779
1917
  return (0, import_react_query2.useMutation)({
1780
1918
  mutationFn: (data) => __async(this, null, function* () {
@@ -1813,16 +1951,27 @@ var BrowserClient = class {
1813
1951
  this.state = { metadata };
1814
1952
  this.queryClient = getQueryClient();
1815
1953
  this.customer = new CustomerAuth(this.config.clientKey, this.baseUrl, options.customer);
1954
+ const onUnauthorized = () => __async(this, null, function* () {
1955
+ var _a2;
1956
+ try {
1957
+ const result = yield this.customer.refreshToken();
1958
+ return (_a2 = result.token) != null ? _a2 : null;
1959
+ } catch (e) {
1960
+ return null;
1961
+ }
1962
+ });
1816
1963
  this.cart = new CartApi({
1817
1964
  clientKey: this.config.clientKey,
1818
1965
  customerToken: () => this.customer.getToken(),
1819
- baseUrl: this.baseUrl
1966
+ baseUrl: this.baseUrl,
1967
+ onUnauthorized
1820
1968
  });
1821
1969
  this.collections = new CollectionClient(
1822
1970
  this.config.clientKey,
1823
1971
  void 0,
1824
1972
  this.baseUrl,
1825
- () => this.customer.getToken()
1973
+ () => this.customer.getToken(),
1974
+ onUnauthorized
1826
1975
  );
1827
1976
  this.query = new QueryHooks(this.queryClient, this.collections, this.customer);
1828
1977
  }
@@ -1832,6 +1981,9 @@ var BrowserClient = class {
1832
1981
  getState() {
1833
1982
  return __spreadValues({}, this.state);
1834
1983
  }
1984
+ getConfig() {
1985
+ return __spreadValues({}, this.config);
1986
+ }
1835
1987
  };
1836
1988
  function createBrowserClient(options) {
1837
1989
  return new BrowserClient(options);
@@ -1896,7 +2048,7 @@ function createServerClient(options) {
1896
2048
  return new ServerClient(options);
1897
2049
  }
1898
2050
 
1899
- // src/core/webhook/index.tsx
2051
+ // src/core/webhook/index.ts
1900
2052
  function isValidWebhookEvent(data) {
1901
2053
  if (typeof data !== "object" || data === null) return false;
1902
2054
  const obj = data;
@@ -2049,10 +2201,44 @@ var generateOrderNumber = () => {
2049
2201
  };
2050
2202
 
2051
2203
  // src/utils/order/formatOrderName.ts
2052
- var formatOrderName = (options) => {
2204
+ var formatOrderName = (items) => {
2053
2205
  var _a, _b;
2054
- if (options.length === 0) return "";
2055
- const firstTitle = ((_b = resolveRelation((_a = options[0]) == null ? void 0 : _a.product)) == null ? void 0 : _b.title) || "";
2056
- return options.length === 1 ? firstTitle : `${firstTitle} \uC678 ${options.length - 1}\uAC74`;
2206
+ if (items.length === 0) return "";
2207
+ const firstTitle = ((_b = resolveRelation((_a = items[0]) == null ? void 0 : _a.product)) == null ? void 0 : _b.title) || "";
2208
+ return items.length === 1 ? firstTitle : `${firstTitle} \uC678 ${items.length - 1}\uAC74`;
2057
2209
  };
2210
+
2211
+ // src/utils/video.ts
2212
+ var MUX_IMAGE_BASE = "https://image.mux.com";
2213
+ var MUX_STREAM_BASE = "https://stream.mux.com";
2214
+ function getVideoThumbnail(playbackId, options) {
2215
+ var _a;
2216
+ const params = new URLSearchParams();
2217
+ params.set("width", String((_a = options == null ? void 0 : options.width) != null ? _a : 640));
2218
+ if (options == null ? void 0 : options.height) params.set("height", String(options.height));
2219
+ if ((options == null ? void 0 : options.time) != null) params.set("time", String(options.time));
2220
+ if (options == null ? void 0 : options.fitMode) params.set("fit_mode", options.fitMode);
2221
+ if (options == null ? void 0 : options.flipH) params.set("flip_h", "true");
2222
+ if (options == null ? void 0 : options.flipV) params.set("flip_v", "true");
2223
+ if (options == null ? void 0 : options.rotate) params.set("rotate", String(options.rotate));
2224
+ return `${MUX_IMAGE_BASE}/${playbackId}/thumbnail.jpg?${params}`;
2225
+ }
2226
+ function getVideoGif(playbackId, options) {
2227
+ var _a;
2228
+ const params = new URLSearchParams();
2229
+ params.set("width", String((_a = options == null ? void 0 : options.width) != null ? _a : 320));
2230
+ if ((options == null ? void 0 : options.start) != null) params.set("start", String(options.start));
2231
+ if ((options == null ? void 0 : options.end) != null) params.set("end", String(options.end));
2232
+ if (options == null ? void 0 : options.fps) params.set("fps", String(options.fps));
2233
+ return `${MUX_IMAGE_BASE}/${playbackId}/animated.gif?${params}`;
2234
+ }
2235
+ function getVideoStoryboard(playbackId) {
2236
+ return `${MUX_IMAGE_BASE}/${playbackId}/storyboard.vtt`;
2237
+ }
2238
+ function getVideoStreamUrl(playbackId) {
2239
+ return `${MUX_STREAM_BASE}/${playbackId}.m3u8`;
2240
+ }
2241
+ function getVideoMp4Url(playbackId, resolution = "high") {
2242
+ return `${MUX_STREAM_BASE}/${playbackId}/${resolution}.mp4`;
2243
+ }
2058
2244
  //# sourceMappingURL=index.cjs.map