@medusajs/loyalty-plugin 0.0.7-preview.0 → 0.0.7-preview.2.10.1

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.
Files changed (174) hide show
  1. package/.medusa/server/medusa-config.d.ts +2 -0
  2. package/.medusa/server/src/admin/index.js +1077 -1088
  3. package/.medusa/server/src/admin/index.mjs +1079 -1090
  4. package/.medusa/server/src/api/admin/gift-cards/[id]/orders/route.d.ts +2 -0
  5. package/.medusa/server/src/api/admin/gift-cards/[id]/orders/route.js +28 -0
  6. package/.medusa/server/src/api/admin/gift-cards/[id]/route.d.ts +4 -0
  7. package/.medusa/server/src/api/admin/gift-cards/[id]/route.js +1 -1
  8. package/.medusa/server/src/api/admin/gift-cards/middlewares.d.ts +2 -0
  9. package/.medusa/server/src/api/admin/gift-cards/middlewares.js +8 -9
  10. package/.medusa/server/src/api/admin/gift-cards/query-config.d.ts +14 -0
  11. package/.medusa/server/src/api/admin/gift-cards/query-config.js +7 -2
  12. package/.medusa/server/src/api/admin/gift-cards/route.d.ts +4 -0
  13. package/.medusa/server/src/api/admin/gift-cards/route.js +1 -1
  14. package/.medusa/server/src/api/admin/gift-cards/validators.d.ts +381 -0
  15. package/.medusa/server/src/api/admin/gift-cards/validators.js +7 -8
  16. package/.medusa/server/src/api/admin/store-credit-accounts/[id]/credit/route.d.ts +3 -0
  17. package/.medusa/server/src/api/admin/store-credit-accounts/[id]/credit/route.js +30 -0
  18. package/.medusa/server/src/api/admin/store-credit-accounts/[id]/route.d.ts +3 -0
  19. package/.medusa/server/src/api/admin/store-credit-accounts/[id]/route.js +1 -6
  20. package/.medusa/server/src/api/admin/store-credit-accounts/[id]/transactions/route.d.ts +3 -0
  21. package/.medusa/server/src/api/admin/store-credit-accounts/[id]/transactions/route.js +1 -1
  22. package/.medusa/server/src/api/admin/store-credit-accounts/middlewares.d.ts +2 -0
  23. package/.medusa/server/src/api/admin/store-credit-accounts/middlewares.js +9 -1
  24. package/.medusa/server/src/api/admin/store-credit-accounts/query-config.d.ts +18 -0
  25. package/.medusa/server/src/api/admin/store-credit-accounts/query-config.js +2 -1
  26. package/.medusa/server/src/api/admin/store-credit-accounts/route.d.ts +4 -0
  27. package/.medusa/server/src/api/admin/store-credit-accounts/route.js +1 -1
  28. package/.medusa/server/src/api/admin/store-credit-accounts/validators.d.ts +412 -0
  29. package/.medusa/server/src/api/admin/store-credit-accounts/validators.js +6 -8
  30. package/.medusa/server/src/api/middlewares.d.ts +2 -0
  31. package/.medusa/server/src/api/middlewares.js +7 -9
  32. package/.medusa/server/src/api/store/carts/[id]/gift-cards/route.d.ts +5 -0
  33. package/.medusa/server/src/api/store/carts/[id]/gift-cards/route.js +1 -1
  34. package/.medusa/server/src/api/store/carts/[id]/store-credits/route.d.ts +4 -0
  35. package/.medusa/server/src/api/store/carts/[id]/store-credits/route.js +1 -1
  36. package/.medusa/server/src/api/store/carts/middlewares.d.ts +2 -0
  37. package/.medusa/server/src/api/store/carts/query-config.d.ts +4 -0
  38. package/.medusa/server/src/api/store/carts/validators.d.ts +25 -0
  39. package/.medusa/server/src/api/store/gift-cards/[idOrCode]/route.d.ts +3 -0
  40. package/.medusa/server/src/api/store/gift-cards/[idOrCode]/route.js +1 -1
  41. package/.medusa/server/src/api/store/gift-cards/middlewares.d.ts +2 -0
  42. package/.medusa/server/src/api/store/gift-cards/middlewares.js +1 -10
  43. package/.medusa/server/src/api/store/gift-cards/query-config.d.ts +9 -0
  44. package/.medusa/server/src/api/store/gift-cards/validators.d.ts +11 -0
  45. package/.medusa/server/src/api/store/store-credit-accounts/[id]/route.d.ts +3 -0
  46. package/.medusa/server/src/api/store/store-credit-accounts/[id]/route.js +1 -1
  47. package/.medusa/server/src/api/store/store-credit-accounts/claim/route.d.ts +3 -0
  48. package/.medusa/server/src/api/store/store-credit-accounts/claim/route.js +25 -0
  49. package/.medusa/server/src/api/store/store-credit-accounts/middlewares.d.ts +2 -0
  50. package/.medusa/server/src/api/store/store-credit-accounts/middlewares.js +9 -1
  51. package/.medusa/server/src/api/store/store-credit-accounts/query-config.d.ts +9 -0
  52. package/.medusa/server/src/api/store/store-credit-accounts/route.d.ts +3 -0
  53. package/.medusa/server/src/api/store/store-credit-accounts/route.js +1 -1
  54. package/.medusa/server/src/api/store/store-credit-accounts/validators.d.ts +120 -0
  55. package/.medusa/server/src/api/store/store-credit-accounts/validators.js +5 -2
  56. package/.medusa/server/src/links/cart-gift-cards-link.d.ts +2 -0
  57. package/.medusa/server/src/links/customer-store-credit-account-link.d.ts +1 -0
  58. package/.medusa/server/src/links/gift-card-store-credit.d.ts +2 -0
  59. package/.medusa/server/src/links/order-gift-cards-link.d.ts +2 -0
  60. package/.medusa/server/src/links/order-line-item-gift-card-link.d.ts +1 -0
  61. package/.medusa/server/src/modules/loyalty/index.d.ts +21 -0
  62. package/.medusa/server/src/modules/loyalty/migrations/Migration20250123130553.d.ts +5 -0
  63. package/.medusa/server/src/modules/loyalty/migrations/Migration20250127174331.d.ts +5 -0
  64. package/.medusa/server/src/modules/loyalty/migrations/Migration20250206141026.d.ts +5 -0
  65. package/.medusa/server/src/modules/loyalty/migrations/Migration20250206141429.d.ts +5 -0
  66. package/.medusa/server/src/modules/loyalty/migrations/Migration20250206144714.d.ts +5 -0
  67. package/.medusa/server/src/modules/loyalty/migrations/Migration20250326095923.d.ts +5 -0
  68. package/.medusa/server/src/modules/loyalty/migrations/Migration20250617080328.d.ts +5 -0
  69. package/.medusa/server/src/modules/loyalty/models/gift-card.d.ts +18 -0
  70. package/.medusa/server/src/modules/loyalty/service.d.ts +21 -0
  71. package/.medusa/server/src/modules/store-credit/index.d.ts +5 -0
  72. package/.medusa/server/src/modules/store-credit/migrations/Migration20250129115518.d.ts +5 -0
  73. package/.medusa/server/src/modules/store-credit/migrations/Migration20250130213237.d.ts +5 -0
  74. package/.medusa/server/src/modules/store-credit/migrations/Migration20250130220640.d.ts +5 -0
  75. package/.medusa/server/src/modules/store-credit/migrations/Migration20250131205753.d.ts +5 -0
  76. package/.medusa/server/src/modules/store-credit/migrations/Migration20250520081315.d.ts +5 -0
  77. package/.medusa/server/src/modules/store-credit/migrations/Migration20250626081315.d.ts +5 -0
  78. package/.medusa/server/src/modules/store-credit/migrations/Migration20250626081315.js +16 -0
  79. package/.medusa/server/src/modules/store-credit/migrations/Migration20250722080351.d.ts +5 -0
  80. package/.medusa/server/src/modules/store-credit/migrations/Migration20250722080351.js +27 -0
  81. package/.medusa/server/src/modules/store-credit/models/account-transaction.d.ts +28 -0
  82. package/.medusa/server/src/modules/store-credit/models/account-transaction.js +1 -7
  83. package/.medusa/server/src/modules/store-credit/models/store-credit-account.d.ts +27 -0
  84. package/.medusa/server/src/modules/store-credit/models/store-credit-account.js +3 -6
  85. package/.medusa/server/src/modules/store-credit/service.d.ts +29 -0
  86. package/.medusa/server/src/modules/store-credit/service.js +19 -178
  87. package/.medusa/server/src/subscribers/create-gift-card.d.ts +5 -0
  88. package/.medusa/server/src/subscribers/create-gift-card.js +1 -3
  89. package/.medusa/server/src/types/cart/index.d.ts +6 -0
  90. package/.medusa/server/src/types/http/gift-card.d.ts +42 -0
  91. package/.medusa/server/src/types/http/index.d.ts +3 -0
  92. package/.medusa/server/src/types/http/index.js +1 -2
  93. package/.medusa/server/src/types/http/store-credit-account.d.ts +60 -0
  94. package/.medusa/server/src/types/http/transaction.d.ts +19 -0
  95. package/.medusa/server/src/types/index.d.ts +4 -0
  96. package/.medusa/server/src/types/loyalty/index.d.ts +3 -0
  97. package/.medusa/server/src/types/loyalty/module.d.ts +42 -0
  98. package/.medusa/server/src/types/loyalty/service.d.ts +24 -0
  99. package/.medusa/server/src/types/loyalty/workflows.d.ts +3 -0
  100. package/.medusa/server/src/types/modules.d.ts +6 -0
  101. package/.medusa/server/src/types/store-credit/index.d.ts +2 -0
  102. package/.medusa/server/src/types/store-credit/module.d.ts +82 -0
  103. package/.medusa/server/src/types/store-credit/module.js +1 -1
  104. package/.medusa/server/src/types/store-credit/service.d.ts +34 -0
  105. package/.medusa/server/src/utils/code-generator.d.ts +1 -0
  106. package/.medusa/server/src/utils/code-generator.js +32 -0
  107. package/.medusa/server/src/workflows/carts/index.d.ts +5 -0
  108. package/.medusa/server/src/workflows/carts/index.js +22 -0
  109. package/.medusa/server/src/workflows/carts/steps/validate-gift-card-balances.d.ts +5 -0
  110. package/.medusa/server/src/workflows/carts/steps/validate-gift-card-balances.js +14 -0
  111. package/.medusa/server/src/workflows/carts/workflows/add-gift-card-to-cart.d.ts +18 -0
  112. package/.medusa/server/src/workflows/carts/workflows/add-gift-card-to-cart.js +14 -56
  113. package/.medusa/server/src/workflows/carts/workflows/add-store-credits-to-cart.d.ts +15 -0
  114. package/.medusa/server/src/workflows/carts/workflows/add-store-credits-to-cart.js +12 -25
  115. package/.medusa/server/src/workflows/carts/workflows/confirm-cart-credit-lines.d.ts +9 -0
  116. package/.medusa/server/src/workflows/carts/workflows/confirm-cart-credit-lines.js +16 -34
  117. package/.medusa/server/src/workflows/carts/workflows/refresh-cart-gift-cards.d.ts +3 -0
  118. package/.medusa/server/src/workflows/carts/workflows/refresh-cart-gift-cards.js +5 -24
  119. package/.medusa/server/src/workflows/carts/workflows/remove-gift-cart-from-cart.d.ts +17 -0
  120. package/.medusa/server/src/workflows/carts/workflows/remove-gift-cart-from-cart.js +4 -4
  121. package/.medusa/server/src/workflows/common/steps/validate-presence-of.d.ts +5 -0
  122. package/.medusa/server/src/workflows/gift-cards/index.d.ts +9 -0
  123. package/.medusa/server/src/workflows/gift-cards/index.js +26 -0
  124. package/.medusa/server/src/workflows/gift-cards/steps/create-gift-cards.d.ts +2 -0
  125. package/.medusa/server/src/workflows/gift-cards/steps/create-gift-cards.js +3 -3
  126. package/.medusa/server/src/workflows/gift-cards/steps/delete-gift-cards.d.ts +3 -0
  127. package/.medusa/server/src/workflows/gift-cards/steps/retrieve-gift-card-balance.d.ts +6 -0
  128. package/.medusa/server/src/workflows/gift-cards/steps/retrieve-gift-card-balance.js +2 -3
  129. package/.medusa/server/src/workflows/gift-cards/steps/update-gift-cards.d.ts +2 -0
  130. package/.medusa/server/src/workflows/gift-cards/workflows/claim-gift-card.d.ts +23 -0
  131. package/.medusa/server/src/workflows/gift-cards/workflows/claim-gift-card.js +65 -0
  132. package/.medusa/server/src/workflows/gift-cards/workflows/create-gift-cards.d.ts +2 -0
  133. package/.medusa/server/src/workflows/gift-cards/workflows/create-gift-cards.js +51 -2
  134. package/.medusa/server/src/workflows/gift-cards/workflows/delete-gift-card.d.ts +3 -0
  135. package/.medusa/server/src/workflows/gift-cards/workflows/redeem-gift-card.d.ts +13 -0
  136. package/.medusa/server/src/workflows/gift-cards/workflows/redeem-gift-card.js +33 -64
  137. package/.medusa/server/src/workflows/gift-cards/workflows/update-gift-cards.d.ts +2 -0
  138. package/.medusa/server/src/workflows/hooks/after-order-created.d.ts +1 -0
  139. package/.medusa/server/src/workflows/hooks/after-order-credit-lines-created.d.ts +1 -0
  140. package/.medusa/server/src/workflows/hooks/before-payment-collection-refresh.d.ts +1 -0
  141. package/.medusa/server/src/workflows/hooks/complete-cart-before-payment-authorization.d.ts +1 -0
  142. package/.medusa/server/src/workflows/index.d.ts +3 -0
  143. package/.medusa/server/src/workflows/index.js +20 -0
  144. package/.medusa/server/src/workflows/orders/index.d.ts +2 -0
  145. package/.medusa/server/src/workflows/orders/index.js +19 -0
  146. package/.medusa/server/src/workflows/orders/workflows/link-gift-cards-to-order.d.ts +4 -0
  147. package/.medusa/server/src/workflows/orders/workflows/refund-credit-lines.d.ts +17 -0
  148. package/.medusa/server/src/workflows/orders/workflows/refund-credit-lines.js +3 -11
  149. package/.medusa/server/src/workflows/store-credit/index.d.ts +8 -0
  150. package/.medusa/server/src/workflows/store-credit/index.js +25 -0
  151. package/.medusa/server/src/workflows/store-credit/steps/create-store-credit-accounts.d.ts +2 -0
  152. package/.medusa/server/src/workflows/store-credit/steps/create-store-credit-accounts.js +8 -1
  153. package/.medusa/server/src/workflows/store-credit/steps/credit-account.d.ts +2 -0
  154. package/.medusa/server/src/workflows/store-credit/steps/debit-account.d.ts +2 -0
  155. package/.medusa/server/src/workflows/store-credit/workflows/claim-store-credit-account.d.ts +11 -0
  156. package/.medusa/server/src/workflows/store-credit/workflows/claim-store-credit-account.js +117 -0
  157. package/.medusa/server/src/workflows/store-credit/workflows/create-store-credit-accounts.d.ts +9 -0
  158. package/.medusa/server/src/workflows/store-credit/workflows/create-store-credit-accounts.js +1 -1
  159. package/.medusa/server/src/workflows/store-credit/workflows/credit-accounts.d.ts +2 -0
  160. package/.medusa/server/src/workflows/store-credit/workflows/credit-store-credit-account.d.ts +2 -0
  161. package/.medusa/server/src/workflows/store-credit/workflows/credit-store-credit-account.js +44 -0
  162. package/.medusa/server/src/workflows/store-credit/workflows/debit-accounts.d.ts +2 -0
  163. package/package.json +21 -10
  164. package/.medusa/server/src/api/admin/gift-cards/[id]/redeem/route.js +0 -24
  165. package/.medusa/server/src/api/admin/transaction-groups/middlewares.js +0 -16
  166. package/.medusa/server/src/api/admin/transaction-groups/query-config.js +0 -13
  167. package/.medusa/server/src/api/admin/transaction-groups/route.js +0 -27
  168. package/.medusa/server/src/api/admin/transaction-groups/validators.js +0 -19
  169. package/.medusa/server/src/api/store/gift-cards/[idOrCode]/redeem/route.js +0 -24
  170. package/.medusa/server/src/modules/store-credit/models/transaction-group.js +0 -28
  171. package/.medusa/server/src/types/http/transaction-group.js +0 -3
  172. package/.medusa/server/src/utils/gift-card.js +0 -32
  173. package/.medusa/server/src/workflows/store-credit/steps/create-transaction-groups.js +0 -17
  174. package/.medusa/server/src/workflows/store-credit/workflows/create-transaction-groups.js +0 -12
@@ -206,6 +206,22 @@ const sdk = new Medusa__default.default({
206
206
  type: "session"
207
207
  }
208
208
  });
209
+ const transactionQueryKey = queryKeysFactory("transaction");
210
+ const useStoreCreditAccountTransactions = (id, query, options) => {
211
+ const fetchStoreCreditAccountTransactions = (query2, headers) => sdk.client.fetch(
212
+ `/admin/store-credit-accounts/${id}/transactions`,
213
+ {
214
+ query: query2,
215
+ headers
216
+ }
217
+ );
218
+ const { data, ...rest } = reactQuery.useQuery({
219
+ queryFn: () => fetchStoreCreditAccountTransactions(query),
220
+ queryKey: transactionQueryKey.list({ sca_id: id, query }),
221
+ ...options
222
+ });
223
+ return { ...data, ...rest };
224
+ };
209
225
  const storeCreditAccountQueryKey = queryKeysFactory(
210
226
  "store-credit-account"
211
227
  );
@@ -254,6 +270,24 @@ const useCreateStoreCreditAccount = (options) => {
254
270
  ...options
255
271
  });
256
272
  };
273
+ const useCreditStoreCreditAccount = (id, options) => {
274
+ const queryClient = reactQuery.useQueryClient();
275
+ return reactQuery.useMutation({
276
+ mutationFn: (payload) => sdk.client.fetch(
277
+ `/admin/store-credit-accounts/${id}/credit`,
278
+ { body: payload, method: "POST" }
279
+ ),
280
+ onSuccess: (data, variables, context) => {
281
+ queryClient.invalidateQueries({
282
+ queryKey: storeCreditAccountQueryKey.detail(id)
283
+ });
284
+ queryClient.invalidateQueries({
285
+ queryKey: transactionQueryKey.list({ sca_id: id })
286
+ });
287
+ },
288
+ ...options
289
+ });
290
+ };
257
291
  const CreditCardIcon = ({ className }) => {
258
292
  return /* @__PURE__ */ jsxRuntime.jsxs(
259
293
  "svg",
@@ -429,29 +463,6 @@ const useOrder = (id, query, options) => {
429
463
  });
430
464
  return { ...data, ...rest };
431
465
  };
432
- var GiftCardStatus = /* @__PURE__ */ ((GiftCardStatus2) => {
433
- GiftCardStatus2["PENDING"] = "pending";
434
- GiftCardStatus2["REDEEMED"] = "redeemed";
435
- return GiftCardStatus2;
436
- })(GiftCardStatus || {});
437
- function getGiftCardStatus(giftCard) {
438
- if (giftCard.expires_at && new Date(giftCard.expires_at) < /* @__PURE__ */ new Date()) {
439
- return "deactivated";
440
- } else if (giftCard.status === GiftCardStatus.PENDING) {
441
- return "pending";
442
- } else {
443
- return "active";
444
- }
445
- }
446
- function getGiftCardStatusColor(status) {
447
- if (status === "deactivated") {
448
- return "red";
449
- } else if (status === "pending") {
450
- return "orange";
451
- } else {
452
- return "green";
453
- }
454
- }
455
466
  const OrderGiftCardsWidget = () => {
456
467
  var _a, _b, _c;
457
468
  const params = reactRouterDom.useParams();
@@ -480,8 +491,7 @@ const OrderGiftCardsWidget = () => {
480
491
  }
481
492
  ),
482
493
  (_c = order == null ? void 0 : order.gift_cards) == null ? void 0 : _c.map((giftCard) => {
483
- const giftCardStatus = getGiftCardStatus(giftCard);
484
- const giftCardStatusColor = getGiftCardStatusColor(giftCardStatus);
494
+ const hasGiftCardExpired = giftCard.expires_at && new Date(giftCard.expires_at) < /* @__PURE__ */ new Date();
485
495
  return /* @__PURE__ */ jsxRuntime.jsx(
486
496
  SidebarLink,
487
497
  {
@@ -493,7 +503,14 @@ const OrderGiftCardsWidget = () => {
493
503
  ),
494
504
  to: `/gift-cards/${giftCard.id}`,
495
505
  children: /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
496
- /* @__PURE__ */ jsxRuntime.jsx(ui.StatusBadge, { color: giftCardStatusColor, className: "capitalize", children: giftCardStatus }),
506
+ /* @__PURE__ */ jsxRuntime.jsx(
507
+ ui.StatusBadge,
508
+ {
509
+ color: hasGiftCardExpired ? "orange" : "green",
510
+ className: "capitalize",
511
+ children: hasGiftCardExpired ? "Expired" : "Active"
512
+ }
513
+ ),
497
514
  /* @__PURE__ */ jsxRuntime.jsx(icons.TriangleRightMini, { className: "text-ui-fg-muted" })
498
515
  ] })
499
516
  },
@@ -8292,7 +8309,8 @@ var n = function(e2, o2) {
8292
8309
  };
8293
8310
  var util;
8294
8311
  (function(util2) {
8295
- util2.assertEqual = (val) => val;
8312
+ util2.assertEqual = (_) => {
8313
+ };
8296
8314
  function assertIs(_arg) {
8297
8315
  }
8298
8316
  util2.assertIs = assertIs;
@@ -8336,7 +8354,7 @@ var util;
8336
8354
  }
8337
8355
  return void 0;
8338
8356
  };
8339
- util2.isInteger = typeof Number.isInteger === "function" ? (val) => Number.isInteger(val) : (val) => typeof val === "number" && isFinite(val) && Math.floor(val) === val;
8357
+ util2.isInteger = typeof Number.isInteger === "function" ? (val) => Number.isInteger(val) : (val) => typeof val === "number" && Number.isFinite(val) && Math.floor(val) === val;
8340
8358
  function joinValues(array, separator = " | ") {
8341
8359
  return array.map((val) => typeof val === "string" ? `'${val}'` : val).join(separator);
8342
8360
  }
@@ -8388,7 +8406,7 @@ const getParsedType = (data) => {
8388
8406
  case "string":
8389
8407
  return ZodParsedType.string;
8390
8408
  case "number":
8391
- return isNaN(data) ? ZodParsedType.nan : ZodParsedType.number;
8409
+ return Number.isNaN(data) ? ZodParsedType.nan : ZodParsedType.number;
8392
8410
  case "boolean":
8393
8411
  return ZodParsedType.boolean;
8394
8412
  case "function":
@@ -8439,11 +8457,10 @@ const ZodIssueCode = util.arrayToEnum([
8439
8457
  "not_multiple_of",
8440
8458
  "not_finite"
8441
8459
  ]);
8442
- const quotelessJson = (obj) => {
8443
- const json = JSON.stringify(obj, null, 2);
8444
- return json.replace(/"([^"]+)":/g, "$1:");
8445
- };
8446
8460
  class ZodError extends Error {
8461
+ get errors() {
8462
+ return this.issues;
8463
+ }
8447
8464
  constructor(issues) {
8448
8465
  super();
8449
8466
  this.issues = [];
@@ -8462,9 +8479,6 @@ class ZodError extends Error {
8462
8479
  this.name = "ZodError";
8463
8480
  this.issues = issues;
8464
8481
  }
8465
- get errors() {
8466
- return this.issues;
8467
- }
8468
8482
  format(_mapper) {
8469
8483
  const mapper = _mapper || function(issue) {
8470
8484
  return issue.message;
@@ -8501,6 +8515,11 @@ class ZodError extends Error {
8501
8515
  processError(this);
8502
8516
  return fieldErrors;
8503
8517
  }
8518
+ static assert(value) {
8519
+ if (!(value instanceof ZodError)) {
8520
+ throw new Error(`Not a ZodError: ${value}`);
8521
+ }
8522
+ }
8504
8523
  toString() {
8505
8524
  return this.message;
8506
8525
  }
@@ -8515,8 +8534,9 @@ class ZodError extends Error {
8515
8534
  const formErrors = [];
8516
8535
  for (const sub of this.issues) {
8517
8536
  if (sub.path.length > 0) {
8518
- fieldErrors[sub.path[0]] = fieldErrors[sub.path[0]] || [];
8519
- fieldErrors[sub.path[0]].push(mapper(sub));
8537
+ const firstEl = sub.path[0];
8538
+ fieldErrors[firstEl] = fieldErrors[firstEl] || [];
8539
+ fieldErrors[firstEl].push(mapper(sub));
8520
8540
  } else {
8521
8541
  formErrors.push(mapper(sub));
8522
8542
  }
@@ -8592,6 +8612,8 @@ const errorMap = (issue, _ctx) => {
8592
8612
  message = `String must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `over`} ${issue.minimum} character(s)`;
8593
8613
  else if (issue.type === "number")
8594
8614
  message = `Number must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${issue.minimum}`;
8615
+ else if (issue.type === "bigint")
8616
+ message = `Number must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${issue.minimum}`;
8595
8617
  else if (issue.type === "date")
8596
8618
  message = `Date must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${new Date(Number(issue.minimum))}`;
8597
8619
  else
@@ -8630,9 +8652,6 @@ const errorMap = (issue, _ctx) => {
8630
8652
  return { message };
8631
8653
  };
8632
8654
  let overrideErrorMap = errorMap;
8633
- function setErrorMap(map) {
8634
- overrideErrorMap = map;
8635
- }
8636
8655
  function getErrorMap() {
8637
8656
  return overrideErrorMap;
8638
8657
  }
@@ -8643,6 +8662,13 @@ const makeIssue = (params) => {
8643
8662
  ...issueData,
8644
8663
  path: fullPath
8645
8664
  };
8665
+ if (issueData.message !== void 0) {
8666
+ return {
8667
+ ...issueData,
8668
+ path: fullPath,
8669
+ message: issueData.message
8670
+ };
8671
+ }
8646
8672
  let errorMessage = "";
8647
8673
  const maps = errorMaps.filter((m) => !!m).slice().reverse();
8648
8674
  for (const map of maps) {
@@ -8651,20 +8677,23 @@ const makeIssue = (params) => {
8651
8677
  return {
8652
8678
  ...issueData,
8653
8679
  path: fullPath,
8654
- message: issueData.message || errorMessage
8680
+ message: errorMessage
8655
8681
  };
8656
8682
  };
8657
- const EMPTY_PATH = [];
8658
8683
  function addIssueToContext(ctx2, issueData) {
8684
+ const overrideMap = getErrorMap();
8659
8685
  const issue = makeIssue({
8660
8686
  issueData,
8661
8687
  data: ctx2.data,
8662
8688
  path: ctx2.path,
8663
8689
  errorMaps: [
8664
8690
  ctx2.common.contextualErrorMap,
8691
+ // contextual error map is first priority
8665
8692
  ctx2.schemaErrorMap,
8666
- getErrorMap(),
8667
- errorMap
8693
+ // then schema-bound map if available
8694
+ overrideMap,
8695
+ // then global override map
8696
+ overrideMap === errorMap ? void 0 : errorMap
8668
8697
  // then global default map
8669
8698
  ].filter((x) => !!x)
8670
8699
  });
@@ -8696,9 +8725,11 @@ class ParseStatus {
8696
8725
  static async mergeObjectAsync(status, pairs) {
8697
8726
  const syncPairs = [];
8698
8727
  for (const pair of pairs) {
8728
+ const key2 = await pair.key;
8729
+ const value = await pair.value;
8699
8730
  syncPairs.push({
8700
- key: await pair.key,
8701
- value: await pair.value
8731
+ key: key2,
8732
+ value
8702
8733
  });
8703
8734
  }
8704
8735
  return ParseStatus.mergeObjectSync(status, syncPairs);
@@ -8734,7 +8765,7 @@ const isAsync = (x) => typeof Promise !== "undefined" && x instanceof Promise;
8734
8765
  var errorUtil;
8735
8766
  (function(errorUtil2) {
8736
8767
  errorUtil2.errToObj = (message) => typeof message === "string" ? { message } : message || {};
8737
- errorUtil2.toString = (message) => typeof message === "string" ? message : message === null || message === void 0 ? void 0 : message.message;
8768
+ errorUtil2.toString = (message) => typeof message === "string" ? message : message == null ? void 0 : message.message;
8738
8769
  })(errorUtil || (errorUtil = {}));
8739
8770
  class ParseInputLazyPath {
8740
8771
  constructor(parent, value, path, key2) {
@@ -8746,7 +8777,7 @@ class ParseInputLazyPath {
8746
8777
  }
8747
8778
  get path() {
8748
8779
  if (!this._cachedPath.length) {
8749
- if (this._key instanceof Array) {
8780
+ if (Array.isArray(this._key)) {
8750
8781
  this._cachedPath.push(...this._path, ...this._key);
8751
8782
  } else {
8752
8783
  this._cachedPath.push(...this._path, this._key);
@@ -8784,44 +8815,20 @@ function processCreateParams(params) {
8784
8815
  if (errorMap2)
8785
8816
  return { errorMap: errorMap2, description };
8786
8817
  const customMap = (iss, ctx2) => {
8787
- if (iss.code !== "invalid_type")
8788
- return { message: ctx2.defaultError };
8818
+ const { message } = params;
8819
+ if (iss.code === "invalid_enum_value") {
8820
+ return { message: message ?? ctx2.defaultError };
8821
+ }
8789
8822
  if (typeof ctx2.data === "undefined") {
8790
- return { message: required_error !== null && required_error !== void 0 ? required_error : ctx2.defaultError };
8823
+ return { message: message ?? required_error ?? ctx2.defaultError };
8791
8824
  }
8792
- return { message: invalid_type_error !== null && invalid_type_error !== void 0 ? invalid_type_error : ctx2.defaultError };
8825
+ if (iss.code !== "invalid_type")
8826
+ return { message: ctx2.defaultError };
8827
+ return { message: message ?? invalid_type_error ?? ctx2.defaultError };
8793
8828
  };
8794
8829
  return { errorMap: customMap, description };
8795
8830
  }
8796
8831
  class ZodType {
8797
- constructor(def) {
8798
- this.spa = this.safeParseAsync;
8799
- this._def = def;
8800
- this.parse = this.parse.bind(this);
8801
- this.safeParse = this.safeParse.bind(this);
8802
- this.parseAsync = this.parseAsync.bind(this);
8803
- this.safeParseAsync = this.safeParseAsync.bind(this);
8804
- this.spa = this.spa.bind(this);
8805
- this.refine = this.refine.bind(this);
8806
- this.refinement = this.refinement.bind(this);
8807
- this.superRefine = this.superRefine.bind(this);
8808
- this.optional = this.optional.bind(this);
8809
- this.nullable = this.nullable.bind(this);
8810
- this.nullish = this.nullish.bind(this);
8811
- this.array = this.array.bind(this);
8812
- this.promise = this.promise.bind(this);
8813
- this.or = this.or.bind(this);
8814
- this.and = this.and.bind(this);
8815
- this.transform = this.transform.bind(this);
8816
- this.brand = this.brand.bind(this);
8817
- this.default = this.default.bind(this);
8818
- this.catch = this.catch.bind(this);
8819
- this.describe = this.describe.bind(this);
8820
- this.pipe = this.pipe.bind(this);
8821
- this.readonly = this.readonly.bind(this);
8822
- this.isNullable = this.isNullable.bind(this);
8823
- this.isOptional = this.isOptional.bind(this);
8824
- }
8825
8832
  get description() {
8826
8833
  return this._def.description;
8827
8834
  }
@@ -8869,14 +8876,13 @@ class ZodType {
8869
8876
  throw result.error;
8870
8877
  }
8871
8878
  safeParse(data, params) {
8872
- var _a;
8873
8879
  const ctx2 = {
8874
8880
  common: {
8875
8881
  issues: [],
8876
- async: (_a = params === null || params === void 0 ? void 0 : params.async) !== null && _a !== void 0 ? _a : false,
8877
- contextualErrorMap: params === null || params === void 0 ? void 0 : params.errorMap
8882
+ async: (params == null ? void 0 : params.async) ?? false,
8883
+ contextualErrorMap: params == null ? void 0 : params.errorMap
8878
8884
  },
8879
- path: (params === null || params === void 0 ? void 0 : params.path) || [],
8885
+ path: (params == null ? void 0 : params.path) || [],
8880
8886
  schemaErrorMap: this._def.errorMap,
8881
8887
  parent: null,
8882
8888
  data,
@@ -8885,6 +8891,43 @@ class ZodType {
8885
8891
  const result = this._parseSync({ data, path: ctx2.path, parent: ctx2 });
8886
8892
  return handleResult(ctx2, result);
8887
8893
  }
8894
+ "~validate"(data) {
8895
+ var _a, _b;
8896
+ const ctx2 = {
8897
+ common: {
8898
+ issues: [],
8899
+ async: !!this["~standard"].async
8900
+ },
8901
+ path: [],
8902
+ schemaErrorMap: this._def.errorMap,
8903
+ parent: null,
8904
+ data,
8905
+ parsedType: getParsedType(data)
8906
+ };
8907
+ if (!this["~standard"].async) {
8908
+ try {
8909
+ const result = this._parseSync({ data, path: [], parent: ctx2 });
8910
+ return isValid(result) ? {
8911
+ value: result.value
8912
+ } : {
8913
+ issues: ctx2.common.issues
8914
+ };
8915
+ } catch (err) {
8916
+ if ((_b = (_a = err == null ? void 0 : err.message) == null ? void 0 : _a.toLowerCase()) == null ? void 0 : _b.includes("encountered")) {
8917
+ this["~standard"].async = true;
8918
+ }
8919
+ ctx2.common = {
8920
+ issues: [],
8921
+ async: true
8922
+ };
8923
+ }
8924
+ }
8925
+ return this._parseAsync({ data, path: [], parent: ctx2 }).then((result) => isValid(result) ? {
8926
+ value: result.value
8927
+ } : {
8928
+ issues: ctx2.common.issues
8929
+ });
8930
+ }
8888
8931
  async parseAsync(data, params) {
8889
8932
  const result = await this.safeParseAsync(data, params);
8890
8933
  if (result.success)
@@ -8895,10 +8938,10 @@ class ZodType {
8895
8938
  const ctx2 = {
8896
8939
  common: {
8897
8940
  issues: [],
8898
- contextualErrorMap: params === null || params === void 0 ? void 0 : params.errorMap,
8941
+ contextualErrorMap: params == null ? void 0 : params.errorMap,
8899
8942
  async: true
8900
8943
  },
8901
- path: (params === null || params === void 0 ? void 0 : params.path) || [],
8944
+ path: (params == null ? void 0 : params.path) || [],
8902
8945
  schemaErrorMap: this._def.errorMap,
8903
8946
  parent: null,
8904
8947
  data,
@@ -8962,6 +9005,39 @@ class ZodType {
8962
9005
  superRefine(refinement) {
8963
9006
  return this._refinement(refinement);
8964
9007
  }
9008
+ constructor(def) {
9009
+ this.spa = this.safeParseAsync;
9010
+ this._def = def;
9011
+ this.parse = this.parse.bind(this);
9012
+ this.safeParse = this.safeParse.bind(this);
9013
+ this.parseAsync = this.parseAsync.bind(this);
9014
+ this.safeParseAsync = this.safeParseAsync.bind(this);
9015
+ this.spa = this.spa.bind(this);
9016
+ this.refine = this.refine.bind(this);
9017
+ this.refinement = this.refinement.bind(this);
9018
+ this.superRefine = this.superRefine.bind(this);
9019
+ this.optional = this.optional.bind(this);
9020
+ this.nullable = this.nullable.bind(this);
9021
+ this.nullish = this.nullish.bind(this);
9022
+ this.array = this.array.bind(this);
9023
+ this.promise = this.promise.bind(this);
9024
+ this.or = this.or.bind(this);
9025
+ this.and = this.and.bind(this);
9026
+ this.transform = this.transform.bind(this);
9027
+ this.brand = this.brand.bind(this);
9028
+ this.default = this.default.bind(this);
9029
+ this.catch = this.catch.bind(this);
9030
+ this.describe = this.describe.bind(this);
9031
+ this.pipe = this.pipe.bind(this);
9032
+ this.readonly = this.readonly.bind(this);
9033
+ this.isNullable = this.isNullable.bind(this);
9034
+ this.isOptional = this.isOptional.bind(this);
9035
+ this["~standard"] = {
9036
+ version: 1,
9037
+ vendor: "zod",
9038
+ validate: (data) => this["~validate"](data)
9039
+ };
9040
+ }
8965
9041
  optional() {
8966
9042
  return ZodOptional.create(this, this._def);
8967
9043
  }
@@ -8972,7 +9048,7 @@ class ZodType {
8972
9048
  return this.nullable().optional();
8973
9049
  }
8974
9050
  array() {
8975
- return ZodArray.create(this, this._def);
9051
+ return ZodArray.create(this);
8976
9052
  }
8977
9053
  promise() {
8978
9054
  return ZodPromise.create(this, this._def);
@@ -9037,35 +9113,45 @@ class ZodType {
9037
9113
  }
9038
9114
  }
9039
9115
  const cuidRegex = /^c[^\s-]{8,}$/i;
9040
- const cuid2Regex = /^[a-z][a-z0-9]*$/;
9041
- const ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/;
9116
+ const cuid2Regex = /^[0-9a-z]+$/;
9117
+ const ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/i;
9042
9118
  const uuidRegex = /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i;
9043
- const emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_+-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
9119
+ const nanoidRegex = /^[a-z0-9_-]{21}$/i;
9120
+ const jwtRegex = /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/;
9121
+ const durationRegex = /^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/;
9122
+ const emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
9044
9123
  const _emojiRegex = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
9045
9124
  let emojiRegex;
9046
- const ipv4Regex = /^(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))$/;
9047
- const ipv6Regex = /^(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))$/;
9048
- const datetimeRegex = (args) => {
9125
+ const ipv4Regex = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/;
9126
+ const ipv4CidrRegex = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/;
9127
+ const ipv6Regex = /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/;
9128
+ const ipv6CidrRegex = /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/;
9129
+ const base64Regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;
9130
+ const base64urlRegex = /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/;
9131
+ const dateRegexSource = `((\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\\d|3[01])|(0[469]|11)-(0[1-9]|[12]\\d|30)|(02)-(0[1-9]|1\\d|2[0-8])))`;
9132
+ const dateRegex = new RegExp(`^${dateRegexSource}$`);
9133
+ function timeRegexSource(args) {
9134
+ let secondsRegexSource = `[0-5]\\d`;
9049
9135
  if (args.precision) {
9050
- if (args.offset) {
9051
- return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{${args.precision}}(([+-]\\d{2}(:?\\d{2})?)|Z)$`);
9052
- } else {
9053
- return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{${args.precision}}Z$`);
9054
- }
9055
- } else if (args.precision === 0) {
9056
- if (args.offset) {
9057
- return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(([+-]\\d{2}(:?\\d{2})?)|Z)$`);
9058
- } else {
9059
- return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$`);
9060
- }
9061
- } else {
9062
- if (args.offset) {
9063
- return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?(([+-]\\d{2}(:?\\d{2})?)|Z)$`);
9064
- } else {
9065
- return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?Z$`);
9066
- }
9136
+ secondsRegexSource = `${secondsRegexSource}\\.\\d{${args.precision}}`;
9137
+ } else if (args.precision == null) {
9138
+ secondsRegexSource = `${secondsRegexSource}(\\.\\d+)?`;
9067
9139
  }
9068
- };
9140
+ const secondsQuantifier = args.precision ? "+" : "?";
9141
+ return `([01]\\d|2[0-3]):[0-5]\\d(:${secondsRegexSource})${secondsQuantifier}`;
9142
+ }
9143
+ function timeRegex(args) {
9144
+ return new RegExp(`^${timeRegexSource(args)}$`);
9145
+ }
9146
+ function datetimeRegex(args) {
9147
+ let regex = `${dateRegexSource}T${timeRegexSource(args)}`;
9148
+ const opts = [];
9149
+ opts.push(args.local ? `Z?` : `Z`);
9150
+ if (args.offset)
9151
+ opts.push(`([+-]\\d{2}:?\\d{2})`);
9152
+ regex = `${regex}(${opts.join("|")})`;
9153
+ return new RegExp(`^${regex}$`);
9154
+ }
9069
9155
  function isValidIP(ip, version) {
9070
9156
  if ((version === "v4" || !version) && ipv4Regex.test(ip)) {
9071
9157
  return true;
@@ -9075,6 +9161,37 @@ function isValidIP(ip, version) {
9075
9161
  }
9076
9162
  return false;
9077
9163
  }
9164
+ function isValidJWT(jwt, alg) {
9165
+ if (!jwtRegex.test(jwt))
9166
+ return false;
9167
+ try {
9168
+ const [header] = jwt.split(".");
9169
+ if (!header)
9170
+ return false;
9171
+ const base64 = header.replace(/-/g, "+").replace(/_/g, "/").padEnd(header.length + (4 - header.length % 4) % 4, "=");
9172
+ const decoded = JSON.parse(atob(base64));
9173
+ if (typeof decoded !== "object" || decoded === null)
9174
+ return false;
9175
+ if ("typ" in decoded && (decoded == null ? void 0 : decoded.typ) !== "JWT")
9176
+ return false;
9177
+ if (!decoded.alg)
9178
+ return false;
9179
+ if (alg && decoded.alg !== alg)
9180
+ return false;
9181
+ return true;
9182
+ } catch {
9183
+ return false;
9184
+ }
9185
+ }
9186
+ function isValidCidr(ip, version) {
9187
+ if ((version === "v4" || !version) && ipv4CidrRegex.test(ip)) {
9188
+ return true;
9189
+ }
9190
+ if ((version === "v6" || !version) && ipv6CidrRegex.test(ip)) {
9191
+ return true;
9192
+ }
9193
+ return false;
9194
+ }
9078
9195
  class ZodString extends ZodType {
9079
9196
  _parse(input) {
9080
9197
  if (this._def.coerce) {
@@ -9083,15 +9200,11 @@ class ZodString extends ZodType {
9083
9200
  const parsedType = this._getType(input);
9084
9201
  if (parsedType !== ZodParsedType.string) {
9085
9202
  const ctx3 = this._getOrReturnCtx(input);
9086
- addIssueToContext(
9087
- ctx3,
9088
- {
9089
- code: ZodIssueCode.invalid_type,
9090
- expected: ZodParsedType.string,
9091
- received: ctx3.parsedType
9092
- }
9093
- //
9094
- );
9203
+ addIssueToContext(ctx3, {
9204
+ code: ZodIssueCode.invalid_type,
9205
+ expected: ZodParsedType.string,
9206
+ received: ctx3.parsedType
9207
+ });
9095
9208
  return INVALID;
9096
9209
  }
9097
9210
  const status = new ParseStatus();
@@ -9182,6 +9295,16 @@ class ZodString extends ZodType {
9182
9295
  });
9183
9296
  status.dirty();
9184
9297
  }
9298
+ } else if (check.kind === "nanoid") {
9299
+ if (!nanoidRegex.test(input.data)) {
9300
+ ctx2 = this._getOrReturnCtx(input, ctx2);
9301
+ addIssueToContext(ctx2, {
9302
+ validation: "nanoid",
9303
+ code: ZodIssueCode.invalid_string,
9304
+ message: check.message
9305
+ });
9306
+ status.dirty();
9307
+ }
9185
9308
  } else if (check.kind === "cuid") {
9186
9309
  if (!cuidRegex.test(input.data)) {
9187
9310
  ctx2 = this._getOrReturnCtx(input, ctx2);
@@ -9215,7 +9338,7 @@ class ZodString extends ZodType {
9215
9338
  } else if (check.kind === "url") {
9216
9339
  try {
9217
9340
  new URL(input.data);
9218
- } catch (_a) {
9341
+ } catch {
9219
9342
  ctx2 = this._getOrReturnCtx(input, ctx2);
9220
9343
  addIssueToContext(ctx2, {
9221
9344
  validation: "url",
@@ -9283,6 +9406,38 @@ class ZodString extends ZodType {
9283
9406
  });
9284
9407
  status.dirty();
9285
9408
  }
9409
+ } else if (check.kind === "date") {
9410
+ const regex = dateRegex;
9411
+ if (!regex.test(input.data)) {
9412
+ ctx2 = this._getOrReturnCtx(input, ctx2);
9413
+ addIssueToContext(ctx2, {
9414
+ code: ZodIssueCode.invalid_string,
9415
+ validation: "date",
9416
+ message: check.message
9417
+ });
9418
+ status.dirty();
9419
+ }
9420
+ } else if (check.kind === "time") {
9421
+ const regex = timeRegex(check);
9422
+ if (!regex.test(input.data)) {
9423
+ ctx2 = this._getOrReturnCtx(input, ctx2);
9424
+ addIssueToContext(ctx2, {
9425
+ code: ZodIssueCode.invalid_string,
9426
+ validation: "time",
9427
+ message: check.message
9428
+ });
9429
+ status.dirty();
9430
+ }
9431
+ } else if (check.kind === "duration") {
9432
+ if (!durationRegex.test(input.data)) {
9433
+ ctx2 = this._getOrReturnCtx(input, ctx2);
9434
+ addIssueToContext(ctx2, {
9435
+ validation: "duration",
9436
+ code: ZodIssueCode.invalid_string,
9437
+ message: check.message
9438
+ });
9439
+ status.dirty();
9440
+ }
9286
9441
  } else if (check.kind === "ip") {
9287
9442
  if (!isValidIP(input.data, check.version)) {
9288
9443
  ctx2 = this._getOrReturnCtx(input, ctx2);
@@ -9293,6 +9448,46 @@ class ZodString extends ZodType {
9293
9448
  });
9294
9449
  status.dirty();
9295
9450
  }
9451
+ } else if (check.kind === "jwt") {
9452
+ if (!isValidJWT(input.data, check.alg)) {
9453
+ ctx2 = this._getOrReturnCtx(input, ctx2);
9454
+ addIssueToContext(ctx2, {
9455
+ validation: "jwt",
9456
+ code: ZodIssueCode.invalid_string,
9457
+ message: check.message
9458
+ });
9459
+ status.dirty();
9460
+ }
9461
+ } else if (check.kind === "cidr") {
9462
+ if (!isValidCidr(input.data, check.version)) {
9463
+ ctx2 = this._getOrReturnCtx(input, ctx2);
9464
+ addIssueToContext(ctx2, {
9465
+ validation: "cidr",
9466
+ code: ZodIssueCode.invalid_string,
9467
+ message: check.message
9468
+ });
9469
+ status.dirty();
9470
+ }
9471
+ } else if (check.kind === "base64") {
9472
+ if (!base64Regex.test(input.data)) {
9473
+ ctx2 = this._getOrReturnCtx(input, ctx2);
9474
+ addIssueToContext(ctx2, {
9475
+ validation: "base64",
9476
+ code: ZodIssueCode.invalid_string,
9477
+ message: check.message
9478
+ });
9479
+ status.dirty();
9480
+ }
9481
+ } else if (check.kind === "base64url") {
9482
+ if (!base64urlRegex.test(input.data)) {
9483
+ ctx2 = this._getOrReturnCtx(input, ctx2);
9484
+ addIssueToContext(ctx2, {
9485
+ validation: "base64url",
9486
+ code: ZodIssueCode.invalid_string,
9487
+ message: check.message
9488
+ });
9489
+ status.dirty();
9490
+ }
9296
9491
  } else {
9297
9492
  util.assertNever(check);
9298
9493
  }
@@ -9324,6 +9519,9 @@ class ZodString extends ZodType {
9324
9519
  uuid(message) {
9325
9520
  return this._addCheck({ kind: "uuid", ...errorUtil.errToObj(message) });
9326
9521
  }
9522
+ nanoid(message) {
9523
+ return this._addCheck({ kind: "nanoid", ...errorUtil.errToObj(message) });
9524
+ }
9327
9525
  cuid(message) {
9328
9526
  return this._addCheck({ kind: "cuid", ...errorUtil.errToObj(message) });
9329
9527
  }
@@ -9333,26 +9531,62 @@ class ZodString extends ZodType {
9333
9531
  ulid(message) {
9334
9532
  return this._addCheck({ kind: "ulid", ...errorUtil.errToObj(message) });
9335
9533
  }
9534
+ base64(message) {
9535
+ return this._addCheck({ kind: "base64", ...errorUtil.errToObj(message) });
9536
+ }
9537
+ base64url(message) {
9538
+ return this._addCheck({
9539
+ kind: "base64url",
9540
+ ...errorUtil.errToObj(message)
9541
+ });
9542
+ }
9543
+ jwt(options) {
9544
+ return this._addCheck({ kind: "jwt", ...errorUtil.errToObj(options) });
9545
+ }
9336
9546
  ip(options) {
9337
9547
  return this._addCheck({ kind: "ip", ...errorUtil.errToObj(options) });
9338
9548
  }
9549
+ cidr(options) {
9550
+ return this._addCheck({ kind: "cidr", ...errorUtil.errToObj(options) });
9551
+ }
9339
9552
  datetime(options) {
9340
- var _a;
9341
9553
  if (typeof options === "string") {
9342
9554
  return this._addCheck({
9343
9555
  kind: "datetime",
9344
9556
  precision: null,
9345
9557
  offset: false,
9558
+ local: false,
9346
9559
  message: options
9347
9560
  });
9348
9561
  }
9349
9562
  return this._addCheck({
9350
9563
  kind: "datetime",
9351
- precision: typeof (options === null || options === void 0 ? void 0 : options.precision) === "undefined" ? null : options === null || options === void 0 ? void 0 : options.precision,
9352
- offset: (_a = options === null || options === void 0 ? void 0 : options.offset) !== null && _a !== void 0 ? _a : false,
9353
- ...errorUtil.errToObj(options === null || options === void 0 ? void 0 : options.message)
9564
+ precision: typeof (options == null ? void 0 : options.precision) === "undefined" ? null : options == null ? void 0 : options.precision,
9565
+ offset: (options == null ? void 0 : options.offset) ?? false,
9566
+ local: (options == null ? void 0 : options.local) ?? false,
9567
+ ...errorUtil.errToObj(options == null ? void 0 : options.message)
9568
+ });
9569
+ }
9570
+ date(message) {
9571
+ return this._addCheck({ kind: "date", message });
9572
+ }
9573
+ time(options) {
9574
+ if (typeof options === "string") {
9575
+ return this._addCheck({
9576
+ kind: "time",
9577
+ precision: null,
9578
+ message: options
9579
+ });
9580
+ }
9581
+ return this._addCheck({
9582
+ kind: "time",
9583
+ precision: typeof (options == null ? void 0 : options.precision) === "undefined" ? null : options == null ? void 0 : options.precision,
9584
+ ...errorUtil.errToObj(options == null ? void 0 : options.message)
9354
9585
  });
9355
9586
  }
9587
+ duration(message) {
9588
+ return this._addCheck({ kind: "duration", ...errorUtil.errToObj(message) });
9589
+ }
9356
9590
  regex(regex, message) {
9357
9591
  return this._addCheck({
9358
9592
  kind: "regex",
@@ -9364,8 +9598,8 @@ class ZodString extends ZodType {
9364
9598
  return this._addCheck({
9365
9599
  kind: "includes",
9366
9600
  value,
9367
- position: options === null || options === void 0 ? void 0 : options.position,
9368
- ...errorUtil.errToObj(options === null || options === void 0 ? void 0 : options.message)
9601
+ position: options == null ? void 0 : options.position,
9602
+ ...errorUtil.errToObj(options == null ? void 0 : options.message)
9369
9603
  });
9370
9604
  }
9371
9605
  startsWith(value, message) {
@@ -9404,8 +9638,7 @@ class ZodString extends ZodType {
9404
9638
  });
9405
9639
  }
9406
9640
  /**
9407
- * @deprecated Use z.string().min(1) instead.
9408
- * @see {@link ZodString.min}
9641
+ * Equivalent to `.min(1)`
9409
9642
  */
9410
9643
  nonempty(message) {
9411
9644
  return this.min(1, errorUtil.errToObj(message));
@@ -9431,6 +9664,15 @@ class ZodString extends ZodType {
9431
9664
  get isDatetime() {
9432
9665
  return !!this._def.checks.find((ch) => ch.kind === "datetime");
9433
9666
  }
9667
+ get isDate() {
9668
+ return !!this._def.checks.find((ch) => ch.kind === "date");
9669
+ }
9670
+ get isTime() {
9671
+ return !!this._def.checks.find((ch) => ch.kind === "time");
9672
+ }
9673
+ get isDuration() {
9674
+ return !!this._def.checks.find((ch) => ch.kind === "duration");
9675
+ }
9434
9676
  get isEmail() {
9435
9677
  return !!this._def.checks.find((ch) => ch.kind === "email");
9436
9678
  }
@@ -9443,6 +9685,9 @@ class ZodString extends ZodType {
9443
9685
  get isUUID() {
9444
9686
  return !!this._def.checks.find((ch) => ch.kind === "uuid");
9445
9687
  }
9688
+ get isNANOID() {
9689
+ return !!this._def.checks.find((ch) => ch.kind === "nanoid");
9690
+ }
9446
9691
  get isCUID() {
9447
9692
  return !!this._def.checks.find((ch) => ch.kind === "cuid");
9448
9693
  }
@@ -9455,6 +9700,15 @@ class ZodString extends ZodType {
9455
9700
  get isIP() {
9456
9701
  return !!this._def.checks.find((ch) => ch.kind === "ip");
9457
9702
  }
9703
+ get isCIDR() {
9704
+ return !!this._def.checks.find((ch) => ch.kind === "cidr");
9705
+ }
9706
+ get isBase64() {
9707
+ return !!this._def.checks.find((ch) => ch.kind === "base64");
9708
+ }
9709
+ get isBase64url() {
9710
+ return !!this._def.checks.find((ch) => ch.kind === "base64url");
9711
+ }
9458
9712
  get minLength() {
9459
9713
  let min2 = null;
9460
9714
  for (const ch of this._def.checks) {
@@ -9477,11 +9731,10 @@ class ZodString extends ZodType {
9477
9731
  }
9478
9732
  }
9479
9733
  ZodString.create = (params) => {
9480
- var _a;
9481
9734
  return new ZodString({
9482
9735
  checks: [],
9483
9736
  typeName: ZodFirstPartyTypeKind.ZodString,
9484
- coerce: (_a = params === null || params === void 0 ? void 0 : params.coerce) !== null && _a !== void 0 ? _a : false,
9737
+ coerce: (params == null ? void 0 : params.coerce) ?? false,
9485
9738
  ...processCreateParams(params)
9486
9739
  });
9487
9740
  };
@@ -9489,9 +9742,9 @@ function floatSafeRemainder(val, step) {
9489
9742
  const valDecCount = (val.toString().split(".")[1] || "").length;
9490
9743
  const stepDecCount = (step.toString().split(".")[1] || "").length;
9491
9744
  const decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount;
9492
- const valInt = parseInt(val.toFixed(decCount).replace(".", ""));
9493
- const stepInt = parseInt(step.toFixed(decCount).replace(".", ""));
9494
- return valInt % stepInt / Math.pow(10, decCount);
9745
+ const valInt = Number.parseInt(val.toFixed(decCount).replace(".", ""));
9746
+ const stepInt = Number.parseInt(step.toFixed(decCount).replace(".", ""));
9747
+ return valInt % stepInt / 10 ** decCount;
9495
9748
  }
9496
9749
  class ZodNumber extends ZodType {
9497
9750
  constructor() {
@@ -9701,7 +9954,8 @@ class ZodNumber extends ZodType {
9701
9954
  return !!this._def.checks.find((ch) => ch.kind === "int" || ch.kind === "multipleOf" && util.isInteger(ch.value));
9702
9955
  }
9703
9956
  get isFinite() {
9704
- let max2 = null, min2 = null;
9957
+ let max2 = null;
9958
+ let min2 = null;
9705
9959
  for (const ch of this._def.checks) {
9706
9960
  if (ch.kind === "finite" || ch.kind === "int" || ch.kind === "multipleOf") {
9707
9961
  return true;
@@ -9720,7 +9974,7 @@ ZodNumber.create = (params) => {
9720
9974
  return new ZodNumber({
9721
9975
  checks: [],
9722
9976
  typeName: ZodFirstPartyTypeKind.ZodNumber,
9723
- coerce: (params === null || params === void 0 ? void 0 : params.coerce) || false,
9977
+ coerce: (params == null ? void 0 : params.coerce) || false,
9724
9978
  ...processCreateParams(params)
9725
9979
  });
9726
9980
  };
@@ -9732,17 +9986,15 @@ class ZodBigInt extends ZodType {
9732
9986
  }
9733
9987
  _parse(input) {
9734
9988
  if (this._def.coerce) {
9735
- input.data = BigInt(input.data);
9989
+ try {
9990
+ input.data = BigInt(input.data);
9991
+ } catch {
9992
+ return this._getInvalidInput(input);
9993
+ }
9736
9994
  }
9737
9995
  const parsedType = this._getType(input);
9738
9996
  if (parsedType !== ZodParsedType.bigint) {
9739
- const ctx3 = this._getOrReturnCtx(input);
9740
- addIssueToContext(ctx3, {
9741
- code: ZodIssueCode.invalid_type,
9742
- expected: ZodParsedType.bigint,
9743
- received: ctx3.parsedType
9744
- });
9745
- return INVALID;
9997
+ return this._getInvalidInput(input);
9746
9998
  }
9747
9999
  let ctx2 = void 0;
9748
10000
  const status = new ParseStatus();
@@ -9789,6 +10041,15 @@ class ZodBigInt extends ZodType {
9789
10041
  }
9790
10042
  return { status: status.value, value: input.data };
9791
10043
  }
10044
+ _getInvalidInput(input) {
10045
+ const ctx2 = this._getOrReturnCtx(input);
10046
+ addIssueToContext(ctx2, {
10047
+ code: ZodIssueCode.invalid_type,
10048
+ expected: ZodParsedType.bigint,
10049
+ received: ctx2.parsedType
10050
+ });
10051
+ return INVALID;
10052
+ }
9792
10053
  gte(value, message) {
9793
10054
  return this.setLimit("min", value, true, errorUtil.toString(message));
9794
10055
  }
@@ -9882,11 +10143,10 @@ class ZodBigInt extends ZodType {
9882
10143
  }
9883
10144
  }
9884
10145
  ZodBigInt.create = (params) => {
9885
- var _a;
9886
10146
  return new ZodBigInt({
9887
10147
  checks: [],
9888
10148
  typeName: ZodFirstPartyTypeKind.ZodBigInt,
9889
- coerce: (_a = params === null || params === void 0 ? void 0 : params.coerce) !== null && _a !== void 0 ? _a : false,
10149
+ coerce: (params == null ? void 0 : params.coerce) ?? false,
9890
10150
  ...processCreateParams(params)
9891
10151
  });
9892
10152
  };
@@ -9911,7 +10171,7 @@ class ZodBoolean extends ZodType {
9911
10171
  ZodBoolean.create = (params) => {
9912
10172
  return new ZodBoolean({
9913
10173
  typeName: ZodFirstPartyTypeKind.ZodBoolean,
9914
- coerce: (params === null || params === void 0 ? void 0 : params.coerce) || false,
10174
+ coerce: (params == null ? void 0 : params.coerce) || false,
9915
10175
  ...processCreateParams(params)
9916
10176
  });
9917
10177
  };
@@ -9930,7 +10190,7 @@ class ZodDate extends ZodType {
9930
10190
  });
9931
10191
  return INVALID;
9932
10192
  }
9933
- if (isNaN(input.data.getTime())) {
10193
+ if (Number.isNaN(input.data.getTime())) {
9934
10194
  const ctx3 = this._getOrReturnCtx(input);
9935
10195
  addIssueToContext(ctx3, {
9936
10196
  code: ZodIssueCode.invalid_date
@@ -10019,7 +10279,7 @@ class ZodDate extends ZodType {
10019
10279
  ZodDate.create = (params) => {
10020
10280
  return new ZodDate({
10021
10281
  checks: [],
10022
- coerce: (params === null || params === void 0 ? void 0 : params.coerce) || false,
10282
+ coerce: (params == null ? void 0 : params.coerce) || false,
10023
10283
  typeName: ZodFirstPartyTypeKind.ZodDate,
10024
10284
  ...processCreateParams(params)
10025
10285
  });
@@ -10294,7 +10554,8 @@ class ZodObject extends ZodType {
10294
10554
  return this._cached;
10295
10555
  const shape = this._def.shape();
10296
10556
  const keys = util.objectKeys(shape);
10297
- return this._cached = { shape, keys };
10557
+ this._cached = { shape, keys };
10558
+ return this._cached;
10298
10559
  }
10299
10560
  _parse(input) {
10300
10561
  const parsedType = this._getType(input);
@@ -10367,9 +10628,10 @@ class ZodObject extends ZodType {
10367
10628
  const syncPairs = [];
10368
10629
  for (const pair of pairs) {
10369
10630
  const key2 = await pair.key;
10631
+ const value = await pair.value;
10370
10632
  syncPairs.push({
10371
10633
  key: key2,
10372
- value: await pair.value,
10634
+ value,
10373
10635
  alwaysSet: pair.alwaysSet
10374
10636
  });
10375
10637
  }
@@ -10391,11 +10653,11 @@ class ZodObject extends ZodType {
10391
10653
  unknownKeys: "strict",
10392
10654
  ...message !== void 0 ? {
10393
10655
  errorMap: (issue, ctx2) => {
10394
- var _a, _b, _c, _d;
10395
- const defaultError = (_c = (_b = (_a = this._def).errorMap) === null || _b === void 0 ? void 0 : _b.call(_a, issue, ctx2).message) !== null && _c !== void 0 ? _c : ctx2.defaultError;
10656
+ var _a, _b;
10657
+ const defaultError = ((_b = (_a = this._def).errorMap) == null ? void 0 : _b.call(_a, issue, ctx2).message) ?? ctx2.defaultError;
10396
10658
  if (issue.code === "unrecognized_keys")
10397
10659
  return {
10398
- message: (_d = errorUtil.errToObj(message).message) !== null && _d !== void 0 ? _d : defaultError
10660
+ message: errorUtil.errToObj(message).message ?? defaultError
10399
10661
  };
10400
10662
  return {
10401
10663
  message: defaultError
@@ -10526,11 +10788,11 @@ class ZodObject extends ZodType {
10526
10788
  }
10527
10789
  pick(mask) {
10528
10790
  const shape = {};
10529
- util.objectKeys(mask).forEach((key2) => {
10791
+ for (const key2 of util.objectKeys(mask)) {
10530
10792
  if (mask[key2] && this.shape[key2]) {
10531
10793
  shape[key2] = this.shape[key2];
10532
10794
  }
10533
- });
10795
+ }
10534
10796
  return new ZodObject({
10535
10797
  ...this._def,
10536
10798
  shape: () => shape
@@ -10538,11 +10800,11 @@ class ZodObject extends ZodType {
10538
10800
  }
10539
10801
  omit(mask) {
10540
10802
  const shape = {};
10541
- util.objectKeys(this.shape).forEach((key2) => {
10803
+ for (const key2 of util.objectKeys(this.shape)) {
10542
10804
  if (!mask[key2]) {
10543
10805
  shape[key2] = this.shape[key2];
10544
10806
  }
10545
- });
10807
+ }
10546
10808
  return new ZodObject({
10547
10809
  ...this._def,
10548
10810
  shape: () => shape
@@ -10556,14 +10818,14 @@ class ZodObject extends ZodType {
10556
10818
  }
10557
10819
  partial(mask) {
10558
10820
  const newShape = {};
10559
- util.objectKeys(this.shape).forEach((key2) => {
10821
+ for (const key2 of util.objectKeys(this.shape)) {
10560
10822
  const fieldSchema = this.shape[key2];
10561
10823
  if (mask && !mask[key2]) {
10562
10824
  newShape[key2] = fieldSchema;
10563
10825
  } else {
10564
10826
  newShape[key2] = fieldSchema.optional();
10565
10827
  }
10566
- });
10828
+ }
10567
10829
  return new ZodObject({
10568
10830
  ...this._def,
10569
10831
  shape: () => newShape
@@ -10571,7 +10833,7 @@ class ZodObject extends ZodType {
10571
10833
  }
10572
10834
  required(mask) {
10573
10835
  const newShape = {};
10574
- util.objectKeys(this.shape).forEach((key2) => {
10836
+ for (const key2 of util.objectKeys(this.shape)) {
10575
10837
  if (mask && !mask[key2]) {
10576
10838
  newShape[key2] = this.shape[key2];
10577
10839
  } else {
@@ -10582,7 +10844,7 @@ class ZodObject extends ZodType {
10582
10844
  }
10583
10845
  newShape[key2] = newField;
10584
10846
  }
10585
- });
10847
+ }
10586
10848
  return new ZodObject({
10587
10849
  ...this._def,
10588
10850
  shape: () => newShape
@@ -10710,103 +10972,6 @@ ZodUnion.create = (types, params) => {
10710
10972
  ...processCreateParams(params)
10711
10973
  });
10712
10974
  };
10713
- const getDiscriminator = (type) => {
10714
- if (type instanceof ZodLazy) {
10715
- return getDiscriminator(type.schema);
10716
- } else if (type instanceof ZodEffects) {
10717
- return getDiscriminator(type.innerType());
10718
- } else if (type instanceof ZodLiteral) {
10719
- return [type.value];
10720
- } else if (type instanceof ZodEnum) {
10721
- return type.options;
10722
- } else if (type instanceof ZodNativeEnum) {
10723
- return Object.keys(type.enum);
10724
- } else if (type instanceof ZodDefault) {
10725
- return getDiscriminator(type._def.innerType);
10726
- } else if (type instanceof ZodUndefined) {
10727
- return [void 0];
10728
- } else if (type instanceof ZodNull) {
10729
- return [null];
10730
- } else {
10731
- return null;
10732
- }
10733
- };
10734
- class ZodDiscriminatedUnion extends ZodType {
10735
- _parse(input) {
10736
- const { ctx: ctx2 } = this._processInputParams(input);
10737
- if (ctx2.parsedType !== ZodParsedType.object) {
10738
- addIssueToContext(ctx2, {
10739
- code: ZodIssueCode.invalid_type,
10740
- expected: ZodParsedType.object,
10741
- received: ctx2.parsedType
10742
- });
10743
- return INVALID;
10744
- }
10745
- const discriminator = this.discriminator;
10746
- const discriminatorValue = ctx2.data[discriminator];
10747
- const option = this.optionsMap.get(discriminatorValue);
10748
- if (!option) {
10749
- addIssueToContext(ctx2, {
10750
- code: ZodIssueCode.invalid_union_discriminator,
10751
- options: Array.from(this.optionsMap.keys()),
10752
- path: [discriminator]
10753
- });
10754
- return INVALID;
10755
- }
10756
- if (ctx2.common.async) {
10757
- return option._parseAsync({
10758
- data: ctx2.data,
10759
- path: ctx2.path,
10760
- parent: ctx2
10761
- });
10762
- } else {
10763
- return option._parseSync({
10764
- data: ctx2.data,
10765
- path: ctx2.path,
10766
- parent: ctx2
10767
- });
10768
- }
10769
- }
10770
- get discriminator() {
10771
- return this._def.discriminator;
10772
- }
10773
- get options() {
10774
- return this._def.options;
10775
- }
10776
- get optionsMap() {
10777
- return this._def.optionsMap;
10778
- }
10779
- /**
10780
- * The constructor of the discriminated union schema. Its behaviour is very similar to that of the normal z.union() constructor.
10781
- * However, it only allows a union of objects, all of which need to share a discriminator property. This property must
10782
- * have a different value for each object in the union.
10783
- * @param discriminator the name of the discriminator property
10784
- * @param types an array of object schemas
10785
- * @param params
10786
- */
10787
- static create(discriminator, options, params) {
10788
- const optionsMap = /* @__PURE__ */ new Map();
10789
- for (const type of options) {
10790
- const discriminatorValues = getDiscriminator(type.shape[discriminator]);
10791
- if (!discriminatorValues) {
10792
- throw new Error(`A discriminator value for key \`${discriminator}\` could not be extracted from all schema options`);
10793
- }
10794
- for (const value of discriminatorValues) {
10795
- if (optionsMap.has(value)) {
10796
- throw new Error(`Discriminator property ${String(discriminator)} has duplicate value ${String(value)}`);
10797
- }
10798
- optionsMap.set(value, type);
10799
- }
10800
- }
10801
- return new ZodDiscriminatedUnion({
10802
- typeName: ZodFirstPartyTypeKind.ZodDiscriminatedUnion,
10803
- discriminator,
10804
- options,
10805
- optionsMap,
10806
- ...processCreateParams(params)
10807
- });
10808
- }
10809
- }
10810
10975
  function mergeValues(a2, b) {
10811
10976
  const aType = getParsedType(a2);
10812
10977
  const bType = getParsedType(b);
@@ -10988,7 +11153,8 @@ class ZodRecord extends ZodType {
10988
11153
  for (const key2 in ctx2.data) {
10989
11154
  pairs.push({
10990
11155
  key: keyType._parse(new ParseInputLazyPath(ctx2, key2, ctx2.path, key2)),
10991
- value: valueType._parse(new ParseInputLazyPath(ctx2, ctx2.data[key2], ctx2.path, key2))
11156
+ value: valueType._parse(new ParseInputLazyPath(ctx2, ctx2.data[key2], ctx2.path, key2)),
11157
+ alwaysSet: key2 in ctx2.data
10992
11158
  });
10993
11159
  }
10994
11160
  if (ctx2.common.async) {
@@ -11168,121 +11334,6 @@ ZodSet.create = (valueType, params) => {
11168
11334
  ...processCreateParams(params)
11169
11335
  });
11170
11336
  };
11171
- class ZodFunction extends ZodType {
11172
- constructor() {
11173
- super(...arguments);
11174
- this.validate = this.implement;
11175
- }
11176
- _parse(input) {
11177
- const { ctx: ctx2 } = this._processInputParams(input);
11178
- if (ctx2.parsedType !== ZodParsedType.function) {
11179
- addIssueToContext(ctx2, {
11180
- code: ZodIssueCode.invalid_type,
11181
- expected: ZodParsedType.function,
11182
- received: ctx2.parsedType
11183
- });
11184
- return INVALID;
11185
- }
11186
- function makeArgsIssue(args, error) {
11187
- return makeIssue({
11188
- data: args,
11189
- path: ctx2.path,
11190
- errorMaps: [
11191
- ctx2.common.contextualErrorMap,
11192
- ctx2.schemaErrorMap,
11193
- getErrorMap(),
11194
- errorMap
11195
- ].filter((x) => !!x),
11196
- issueData: {
11197
- code: ZodIssueCode.invalid_arguments,
11198
- argumentsError: error
11199
- }
11200
- });
11201
- }
11202
- function makeReturnsIssue(returns, error) {
11203
- return makeIssue({
11204
- data: returns,
11205
- path: ctx2.path,
11206
- errorMaps: [
11207
- ctx2.common.contextualErrorMap,
11208
- ctx2.schemaErrorMap,
11209
- getErrorMap(),
11210
- errorMap
11211
- ].filter((x) => !!x),
11212
- issueData: {
11213
- code: ZodIssueCode.invalid_return_type,
11214
- returnTypeError: error
11215
- }
11216
- });
11217
- }
11218
- const params = { errorMap: ctx2.common.contextualErrorMap };
11219
- const fn = ctx2.data;
11220
- if (this._def.returns instanceof ZodPromise) {
11221
- const me = this;
11222
- return OK(async function(...args) {
11223
- const error = new ZodError([]);
11224
- const parsedArgs = await me._def.args.parseAsync(args, params).catch((e2) => {
11225
- error.addIssue(makeArgsIssue(args, e2));
11226
- throw error;
11227
- });
11228
- const result = await Reflect.apply(fn, this, parsedArgs);
11229
- const parsedReturns = await me._def.returns._def.type.parseAsync(result, params).catch((e2) => {
11230
- error.addIssue(makeReturnsIssue(result, e2));
11231
- throw error;
11232
- });
11233
- return parsedReturns;
11234
- });
11235
- } else {
11236
- const me = this;
11237
- return OK(function(...args) {
11238
- const parsedArgs = me._def.args.safeParse(args, params);
11239
- if (!parsedArgs.success) {
11240
- throw new ZodError([makeArgsIssue(args, parsedArgs.error)]);
11241
- }
11242
- const result = Reflect.apply(fn, this, parsedArgs.data);
11243
- const parsedReturns = me._def.returns.safeParse(result, params);
11244
- if (!parsedReturns.success) {
11245
- throw new ZodError([makeReturnsIssue(result, parsedReturns.error)]);
11246
- }
11247
- return parsedReturns.data;
11248
- });
11249
- }
11250
- }
11251
- parameters() {
11252
- return this._def.args;
11253
- }
11254
- returnType() {
11255
- return this._def.returns;
11256
- }
11257
- args(...items) {
11258
- return new ZodFunction({
11259
- ...this._def,
11260
- args: ZodTuple.create(items).rest(ZodUnknown.create())
11261
- });
11262
- }
11263
- returns(returnType) {
11264
- return new ZodFunction({
11265
- ...this._def,
11266
- returns: returnType
11267
- });
11268
- }
11269
- implement(func) {
11270
- const validatedFunc = this.parse(func);
11271
- return validatedFunc;
11272
- }
11273
- strictImplement(func) {
11274
- const validatedFunc = this.parse(func);
11275
- return validatedFunc;
11276
- }
11277
- static create(args, returns, params) {
11278
- return new ZodFunction({
11279
- args: args ? args : ZodTuple.create([]).rest(ZodUnknown.create()),
11280
- returns: returns || ZodUnknown.create(),
11281
- typeName: ZodFirstPartyTypeKind.ZodFunction,
11282
- ...processCreateParams(params)
11283
- });
11284
- }
11285
- }
11286
11337
  class ZodLazy extends ZodType {
11287
11338
  get schema() {
11288
11339
  return this._def.getter();
@@ -11343,7 +11394,10 @@ class ZodEnum extends ZodType {
11343
11394
  });
11344
11395
  return INVALID;
11345
11396
  }
11346
- if (this._def.values.indexOf(input.data) === -1) {
11397
+ if (!this._cache) {
11398
+ this._cache = new Set(this._def.values);
11399
+ }
11400
+ if (!this._cache.has(input.data)) {
11347
11401
  const ctx2 = this._getOrReturnCtx(input);
11348
11402
  const expectedValues = this._def.values;
11349
11403
  addIssueToContext(ctx2, {
@@ -11379,11 +11433,17 @@ class ZodEnum extends ZodType {
11379
11433
  }
11380
11434
  return enumValues;
11381
11435
  }
11382
- extract(values) {
11383
- return ZodEnum.create(values);
11436
+ extract(values, newDef = this._def) {
11437
+ return ZodEnum.create(values, {
11438
+ ...this._def,
11439
+ ...newDef
11440
+ });
11384
11441
  }
11385
- exclude(values) {
11386
- return ZodEnum.create(this.options.filter((opt) => !values.includes(opt)));
11442
+ exclude(values, newDef = this._def) {
11443
+ return ZodEnum.create(this.options.filter((opt) => !values.includes(opt)), {
11444
+ ...this._def,
11445
+ ...newDef
11446
+ });
11387
11447
  }
11388
11448
  }
11389
11449
  ZodEnum.create = createZodEnum;
@@ -11400,7 +11460,10 @@ class ZodNativeEnum extends ZodType {
11400
11460
  });
11401
11461
  return INVALID;
11402
11462
  }
11403
- if (nativeEnumValues.indexOf(input.data) === -1) {
11463
+ if (!this._cache) {
11464
+ this._cache = new Set(util.getValidEnumValues(this._def.values));
11465
+ }
11466
+ if (!this._cache.has(input.data)) {
11404
11467
  const expectedValues = util.objectValues(nativeEnumValues);
11405
11468
  addIssueToContext(ctx2, {
11406
11469
  received: ctx2.data,
@@ -11478,26 +11541,38 @@ class ZodEffects extends ZodType {
11478
11541
  checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx);
11479
11542
  if (effect.type === "preprocess") {
11480
11543
  const processed = effect.transform(ctx2.data, checkCtx);
11481
- if (ctx2.common.issues.length) {
11482
- return {
11483
- status: "dirty",
11484
- value: ctx2.data
11485
- };
11486
- }
11487
11544
  if (ctx2.common.async) {
11488
- return Promise.resolve(processed).then((processed2) => {
11489
- return this._def.schema._parseAsync({
11545
+ return Promise.resolve(processed).then(async (processed2) => {
11546
+ if (status.value === "aborted")
11547
+ return INVALID;
11548
+ const result = await this._def.schema._parseAsync({
11490
11549
  data: processed2,
11491
11550
  path: ctx2.path,
11492
11551
  parent: ctx2
11493
11552
  });
11553
+ if (result.status === "aborted")
11554
+ return INVALID;
11555
+ if (result.status === "dirty")
11556
+ return DIRTY(result.value);
11557
+ if (status.value === "dirty")
11558
+ return DIRTY(result.value);
11559
+ return result;
11494
11560
  });
11495
11561
  } else {
11496
- return this._def.schema._parseSync({
11562
+ if (status.value === "aborted")
11563
+ return INVALID;
11564
+ const result = this._def.schema._parseSync({
11497
11565
  data: processed,
11498
11566
  path: ctx2.path,
11499
11567
  parent: ctx2
11500
11568
  });
11569
+ if (result.status === "aborted")
11570
+ return INVALID;
11571
+ if (result.status === "dirty")
11572
+ return DIRTY(result.value);
11573
+ if (status.value === "dirty")
11574
+ return DIRTY(result.value);
11575
+ return result;
11501
11576
  }
11502
11577
  }
11503
11578
  if (effect.type === "refinement") {
@@ -11543,7 +11618,7 @@ class ZodEffects extends ZodType {
11543
11618
  parent: ctx2
11544
11619
  });
11545
11620
  if (!isValid(base))
11546
- return base;
11621
+ return INVALID;
11547
11622
  const result = effect.transform(base.value, checkCtx);
11548
11623
  if (result instanceof Promise) {
11549
11624
  throw new Error(`Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.`);
@@ -11552,8 +11627,11 @@ class ZodEffects extends ZodType {
11552
11627
  } else {
11553
11628
  return this._def.schema._parseAsync({ data: ctx2.data, path: ctx2.path, parent: ctx2 }).then((base) => {
11554
11629
  if (!isValid(base))
11555
- return base;
11556
- return Promise.resolve(effect.transform(base.value, checkCtx)).then((result) => ({ status: status.value, value: result }));
11630
+ return INVALID;
11631
+ return Promise.resolve(effect.transform(base.value, checkCtx)).then((result) => ({
11632
+ status: status.value,
11633
+ value: result
11634
+ }));
11557
11635
  });
11558
11636
  }
11559
11637
  }
@@ -11713,7 +11791,6 @@ ZodNaN.create = (params) => {
11713
11791
  ...processCreateParams(params)
11714
11792
  });
11715
11793
  };
11716
- const BRAND = Symbol("zod_brand");
11717
11794
  class ZodBranded extends ZodType {
11718
11795
  _parse(input) {
11719
11796
  const { ctx: ctx2 } = this._processInputParams(input);
@@ -11786,10 +11863,16 @@ class ZodPipeline extends ZodType {
11786
11863
  class ZodReadonly extends ZodType {
11787
11864
  _parse(input) {
11788
11865
  const result = this._def.innerType._parse(input);
11789
- if (isValid(result)) {
11790
- result.value = Object.freeze(result.value);
11791
- }
11792
- return result;
11866
+ const freeze = (data) => {
11867
+ if (isValid(data)) {
11868
+ data.value = Object.freeze(data.value);
11869
+ }
11870
+ return data;
11871
+ };
11872
+ return isAsync(result) ? result.then((data) => freeze(data)) : freeze(result);
11873
+ }
11874
+ unwrap() {
11875
+ return this._def.innerType;
11793
11876
  }
11794
11877
  }
11795
11878
  ZodReadonly.create = (type, params) => {
@@ -11799,22 +11882,6 @@ ZodReadonly.create = (type, params) => {
11799
11882
  ...processCreateParams(params)
11800
11883
  });
11801
11884
  };
11802
- const custom = (check, params = {}, fatal) => {
11803
- if (check)
11804
- return ZodAny.create().superRefine((data, ctx2) => {
11805
- var _a, _b;
11806
- if (!check(data)) {
11807
- const p = typeof params === "function" ? params(data) : typeof params === "string" ? { message: params } : params;
11808
- const _fatal = (_b = (_a = p.fatal) !== null && _a !== void 0 ? _a : fatal) !== null && _b !== void 0 ? _b : true;
11809
- const p2 = typeof p === "string" ? { message: p } : p;
11810
- ctx2.addIssue({ code: "custom", ...p2, fatal: _fatal });
11811
- }
11812
- });
11813
- return ZodAny.create();
11814
- };
11815
- const late = {
11816
- object: ZodObject.lazycreate
11817
- };
11818
11885
  var ZodFirstPartyTypeKind;
11819
11886
  (function(ZodFirstPartyTypeKind2) {
11820
11887
  ZodFirstPartyTypeKind2["ZodString"] = "ZodString";
@@ -11854,46 +11921,24 @@ var ZodFirstPartyTypeKind;
11854
11921
  ZodFirstPartyTypeKind2["ZodPipeline"] = "ZodPipeline";
11855
11922
  ZodFirstPartyTypeKind2["ZodReadonly"] = "ZodReadonly";
11856
11923
  })(ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {}));
11857
- const instanceOfType = (cls, params = {
11858
- message: `Input not instance of ${cls.name}`
11859
- }) => custom((data) => data instanceof cls, params);
11860
11924
  const stringType = ZodString.create;
11861
11925
  const numberType = ZodNumber.create;
11862
- const nanType = ZodNaN.create;
11863
- const bigIntType = ZodBigInt.create;
11926
+ ZodBigInt.create;
11864
11927
  const booleanType = ZodBoolean.create;
11865
11928
  const dateType = ZodDate.create;
11866
- const symbolType = ZodSymbol.create;
11867
- const undefinedType = ZodUndefined.create;
11868
- const nullType = ZodNull.create;
11869
11929
  const anyType = ZodAny.create;
11870
11930
  const unknownType = ZodUnknown.create;
11871
- const neverType = ZodNever.create;
11872
- const voidType = ZodVoid.create;
11931
+ ZodNever.create;
11873
11932
  const arrayType = ZodArray.create;
11874
11933
  const objectType = ZodObject.create;
11875
- const strictObjectType = ZodObject.strictCreate;
11876
11934
  const unionType = ZodUnion.create;
11877
- const discriminatedUnionType = ZodDiscriminatedUnion.create;
11878
- const intersectionType = ZodIntersection.create;
11879
- const tupleType = ZodTuple.create;
11935
+ ZodIntersection.create;
11936
+ ZodTuple.create;
11880
11937
  const recordType = ZodRecord.create;
11881
- const mapType = ZodMap.create;
11882
- const setType = ZodSet.create;
11883
- const functionType = ZodFunction.create;
11884
- const lazyType = ZodLazy.create;
11885
- const literalType = ZodLiteral.create;
11886
11938
  const enumType = ZodEnum.create;
11887
- const nativeEnumType = ZodNativeEnum.create;
11888
- const promiseType = ZodPromise.create;
11889
- const effectsType = ZodEffects.create;
11890
- const optionalType = ZodOptional.create;
11891
- const nullableType = ZodNullable.create;
11892
- const preprocessType = ZodEffects.createWithPreprocess;
11893
- const pipelineType = ZodPipeline.create;
11894
- const ostring = () => stringType().optional();
11895
- const onumber = () => numberType().optional();
11896
- const oboolean = () => booleanType().optional();
11939
+ ZodPromise.create;
11940
+ ZodOptional.create;
11941
+ ZodNullable.create;
11897
11942
  const coerce = {
11898
11943
  string: (arg) => ZodString.create({ ...arg, coerce: true }),
11899
11944
  number: (arg) => ZodNumber.create({ ...arg, coerce: true }),
@@ -11904,122 +11949,6 @@ const coerce = {
11904
11949
  bigint: (arg) => ZodBigInt.create({ ...arg, coerce: true }),
11905
11950
  date: (arg) => ZodDate.create({ ...arg, coerce: true })
11906
11951
  };
11907
- const NEVER = INVALID;
11908
- var z = /* @__PURE__ */ Object.freeze({
11909
- __proto__: null,
11910
- defaultErrorMap: errorMap,
11911
- setErrorMap,
11912
- getErrorMap,
11913
- makeIssue,
11914
- EMPTY_PATH,
11915
- addIssueToContext,
11916
- ParseStatus,
11917
- INVALID,
11918
- DIRTY,
11919
- OK,
11920
- isAborted,
11921
- isDirty,
11922
- isValid,
11923
- isAsync,
11924
- get util() {
11925
- return util;
11926
- },
11927
- get objectUtil() {
11928
- return objectUtil;
11929
- },
11930
- ZodParsedType,
11931
- getParsedType,
11932
- ZodType,
11933
- ZodString,
11934
- ZodNumber,
11935
- ZodBigInt,
11936
- ZodBoolean,
11937
- ZodDate,
11938
- ZodSymbol,
11939
- ZodUndefined,
11940
- ZodNull,
11941
- ZodAny,
11942
- ZodUnknown,
11943
- ZodNever,
11944
- ZodVoid,
11945
- ZodArray,
11946
- ZodObject,
11947
- ZodUnion,
11948
- ZodDiscriminatedUnion,
11949
- ZodIntersection,
11950
- ZodTuple,
11951
- ZodRecord,
11952
- ZodMap,
11953
- ZodSet,
11954
- ZodFunction,
11955
- ZodLazy,
11956
- ZodLiteral,
11957
- ZodEnum,
11958
- ZodNativeEnum,
11959
- ZodPromise,
11960
- ZodEffects,
11961
- ZodTransformer: ZodEffects,
11962
- ZodOptional,
11963
- ZodNullable,
11964
- ZodDefault,
11965
- ZodCatch,
11966
- ZodNaN,
11967
- BRAND,
11968
- ZodBranded,
11969
- ZodPipeline,
11970
- ZodReadonly,
11971
- custom,
11972
- Schema: ZodType,
11973
- ZodSchema: ZodType,
11974
- late,
11975
- get ZodFirstPartyTypeKind() {
11976
- return ZodFirstPartyTypeKind;
11977
- },
11978
- coerce,
11979
- any: anyType,
11980
- array: arrayType,
11981
- bigint: bigIntType,
11982
- boolean: booleanType,
11983
- date: dateType,
11984
- discriminatedUnion: discriminatedUnionType,
11985
- effect: effectsType,
11986
- "enum": enumType,
11987
- "function": functionType,
11988
- "instanceof": instanceOfType,
11989
- intersection: intersectionType,
11990
- lazy: lazyType,
11991
- literal: literalType,
11992
- map: mapType,
11993
- nan: nanType,
11994
- nativeEnum: nativeEnumType,
11995
- never: neverType,
11996
- "null": nullType,
11997
- nullable: nullableType,
11998
- number: numberType,
11999
- object: objectType,
12000
- oboolean,
12001
- onumber,
12002
- optional: optionalType,
12003
- ostring,
12004
- pipeline: pipelineType,
12005
- preprocess: preprocessType,
12006
- promise: promiseType,
12007
- record: recordType,
12008
- set: setType,
12009
- strictObject: strictObjectType,
12010
- string: stringType,
12011
- symbol: symbolType,
12012
- transformer: effectsType,
12013
- tuple: tupleType,
12014
- "undefined": undefinedType,
12015
- union: unionType,
12016
- unknown: unknownType,
12017
- "void": voidType,
12018
- NEVER,
12019
- ZodIssueCode,
12020
- quotelessJson,
12021
- ZodError
12022
- });
12023
11952
  var __defProp$1 = Object.defineProperty;
12024
11953
  var __defProps$1 = Object.defineProperties;
12025
11954
  var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
@@ -20088,9 +20017,9 @@ const currencies = {
20088
20017
  decimal_digits: 0
20089
20018
  }
20090
20019
  };
20091
- const formSchema = z.object({
20092
- currency_code: z.string().min(1, "Please select a currency"),
20093
- customer_id: z.string().min(1, "Please select a customer")
20020
+ const formSchema = objectType({
20021
+ currency_code: stringType().min(1, "Please select a currency"),
20022
+ customer_id: stringType().optional()
20094
20023
  });
20095
20024
  const StoreCreditAccountCreateForm = () => {
20096
20025
  const { handleSuccess } = useRouteModal();
@@ -20103,6 +20032,9 @@ const StoreCreditAccountCreateForm = () => {
20103
20032
  });
20104
20033
  const { mutateAsync: createStoreCreditAccount, isPending } = useCreateStoreCreditAccount();
20105
20034
  const handleSubmit = form.handleSubmit(async (data) => {
20035
+ if (!data.customer_id) {
20036
+ delete data.customer_id;
20037
+ }
20106
20038
  await createStoreCreditAccount(data, {
20107
20039
  onSuccess: (data2) => {
20108
20040
  ui.toast.success(`Store credit account was successfully created.`);
@@ -20373,7 +20305,11 @@ const GiftCardProductsSection = () => {
20373
20305
  )
20374
20306
  ] });
20375
20307
  };
20376
- const giftCardQueryKey = queryKeysFactory("gift-card");
20308
+ const _giftCardQueryKey = queryKeysFactory("gift-card");
20309
+ const giftCardQueryKey = {
20310
+ ..._giftCardQueryKey,
20311
+ orders: (id) => [..._giftCardQueryKey.detail(id), "orders"]
20312
+ };
20377
20313
  const useGiftCards = (query, options) => {
20378
20314
  const fetchGiftCards = (query2, headers) => sdk.client.fetch(`/admin/gift-cards`, {
20379
20315
  query: query2,
@@ -20398,19 +20334,17 @@ const useGiftCard = (id, query, options) => {
20398
20334
  });
20399
20335
  return { ...data, ...rest };
20400
20336
  };
20401
- const useRedeemGiftCard = (id, options) => {
20402
- const queryClient = reactQuery.useQueryClient();
20403
- const redeemGiftCard = async (id2, body) => sdk.client.fetch(`/admin/gift-cards/${id2}/redeem`, {
20404
- body,
20405
- method: "POST"
20337
+ const useGiftCardOrders = (id, options) => {
20338
+ const fetchGiftCardOrders = (id2, query, headers) => sdk.client.fetch(`/admin/gift-cards/${id2}/orders`, {
20339
+ query,
20340
+ headers
20406
20341
  });
20407
- return reactQuery.useMutation({
20408
- mutationFn: (body) => redeemGiftCard(id, body),
20409
- onSuccess: (data, variables, context) => {
20410
- queryClient.invalidateQueries({ queryKey: giftCardQueryKey.lists() });
20411
- queryClient.invalidateQueries({ queryKey: giftCardQueryKey.detail(id) });
20412
- }
20342
+ const { data, ...rest } = reactQuery.useQuery({
20343
+ queryFn: () => fetchGiftCardOrders(id),
20344
+ queryKey: giftCardQueryKey.orders(id),
20345
+ ...options
20413
20346
  });
20347
+ return { ...data, ...rest };
20414
20348
  };
20415
20349
  const useUpdateGiftCard = (id, options) => {
20416
20350
  const queryClient = reactQuery.useQueryClient();
@@ -20461,6 +20395,12 @@ const columnHelper$9 = ui.createDataTableColumnHelper();
20461
20395
  const useGiftCardTableColumns = () => {
20462
20396
  return React.useMemo(() => {
20463
20397
  return [
20398
+ columnHelper$9.accessor("code", {
20399
+ header: "Code",
20400
+ cell: ({ row }) => {
20401
+ return row.original.code;
20402
+ }
20403
+ }),
20464
20404
  columnHelper$9.accessor("line_item.product.title", {
20465
20405
  header: "Product",
20466
20406
  cell: ({ row }) => {
@@ -20468,34 +20408,10 @@ const useGiftCardTableColumns = () => {
20468
20408
  return ((_b = (_a = row.original.line_item) == null ? void 0 : _a.product) == null ? void 0 : _b.title) || "Custom Gift Card";
20469
20409
  }
20470
20410
  }),
20471
- columnHelper$9.accessor("customer.first_name", {
20472
- header: "Owner",
20473
- cell: ({ row }) => {
20474
- if (!row.original.customer) {
20475
- return "N/A";
20476
- }
20477
- const fullName = [
20478
- row.original.customer.first_name,
20479
- row.original.customer.last_name
20480
- ];
20481
- if (fullName.join("").length > 0) {
20482
- return fullName.join(" ");
20483
- }
20484
- return row.original.customer.email;
20485
- }
20486
- }),
20487
20411
  columnHelper$9.accessor("created_at", {
20488
20412
  header: "Date issued",
20489
20413
  cell: ({ row }) => getRelativeDate(row.original.created_at)
20490
20414
  }),
20491
- columnHelper$9.accessor("status", {
20492
- header: "Status",
20493
- cell: ({ row }) => {
20494
- const status = getGiftCardStatus(row.original);
20495
- const color = getGiftCardStatusColor(status);
20496
- return /* @__PURE__ */ jsxRuntime.jsx(ui.StatusBadge, { color, children: status });
20497
- }
20498
- }),
20499
20415
  columnHelper$9.accessor("value", {
20500
20416
  header: "Value",
20501
20417
  cell: ({ row }) => {
@@ -20619,19 +20535,16 @@ const useStore$1 = (query, options) => {
20619
20535
  ...rest
20620
20536
  };
20621
20537
  };
20622
- const GiftCardCreateSchema = z.object({
20623
- value: z.coerce.number().positive({
20538
+ const GiftCardCreateSchema = objectType({
20539
+ value: coerce.number().positive({
20624
20540
  message: "Value must be a positive number"
20625
20541
  }),
20626
- currency_code: z.string({
20542
+ currency_code: stringType({
20627
20543
  required_error: "Currency is required"
20628
20544
  }),
20629
- customer_id: z.string({
20630
- required_error: "Customer is required"
20631
- }),
20632
- expires_at: z.date().nullable().optional(),
20633
- note: z.string().optional(),
20634
- metadata: z.record(z.string(), z.string()).optional()
20545
+ expires_at: dateType().nullable().optional(),
20546
+ note: stringType().optional(),
20547
+ metadata: recordType(stringType(), stringType()).optional()
20635
20548
  });
20636
20549
  const GiftCardCreateForm = ({
20637
20550
  store
@@ -20644,10 +20557,9 @@ const GiftCardCreateForm = ({
20644
20557
  defaultValues: {
20645
20558
  value: void 0,
20646
20559
  currency_code: (supportedCurrencies == null ? void 0 : supportedCurrencies[0]) ?? "eur",
20647
- customer_id: "",
20648
20560
  expires_at: null,
20649
- note: "",
20650
- metadata: {}
20561
+ metadata: {},
20562
+ note: ""
20651
20563
  },
20652
20564
  resolver: t(GiftCardCreateSchema)
20653
20565
  });
@@ -20676,30 +20588,6 @@ const GiftCardCreateForm = ({
20676
20588
  (option) => option.label.toLowerCase().includes(currencySearchValue.toLowerCase())
20677
20589
  );
20678
20590
  }, [currencySearchValue]);
20679
- const {
20680
- options: customerOptions,
20681
- fetchNextPage,
20682
- isFetchingNextPage,
20683
- searchValue,
20684
- onSearchValueChange,
20685
- isLoading
20686
- } = useComboboxData({
20687
- queryKey: customersQueryKeys.list(),
20688
- queryFn: async (params) => {
20689
- return sdk.admin.customer.list(params);
20690
- },
20691
- getOptions: (data) => {
20692
- var _a;
20693
- return ((_a = data.customers) == null ? void 0 : _a.map((customer) => {
20694
- const fullName = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
20695
- const label = fullName ? `${customer.email} (${fullName})` : customer.email;
20696
- return {
20697
- label,
20698
- value: customer.id
20699
- };
20700
- })) || [];
20701
- }
20702
- });
20703
20591
  const selectedCurrency = form.watch("currency_code");
20704
20592
  const currentCurrency = React.useMemo(() => {
20705
20593
  return currencies[selectedCurrency.toUpperCase()];
@@ -20712,7 +20600,7 @@ const GiftCardCreateForm = ({
20712
20600
  /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Body, { className: "size-full overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col items-center p-16", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-8", children: [
20713
20601
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
20714
20602
  /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h1", children: "Create Gift Card" }),
20715
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "text-ui-fg-subtle", size: "small", children: "Create a new gift card for a customer" })
20603
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "text-ui-fg-subtle", size: "small", children: "Create a new gift card" })
20716
20604
  ] }),
20717
20605
  /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
20718
20606
  /* @__PURE__ */ jsxRuntime.jsxs(
@@ -20761,14 +20649,21 @@ const GiftCardCreateForm = ({
20761
20649
  /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
20762
20650
  ui.CurrencyInput,
20763
20651
  {
20764
- ...field,
20765
- formatValueOnBlur: true,
20766
- symbol: currentCurrency.symbol_native,
20652
+ value: field.value,
20767
20653
  code: currentCurrency.code,
20654
+ symbol: currentCurrency.symbol_native,
20768
20655
  decimalScale: currentCurrency.decimal_digits,
20769
20656
  decimalsLimit: currentCurrency.decimal_digits,
20657
+ allowDecimals: true,
20658
+ formatValueOnBlur: true,
20659
+ allowNegativeValue: false,
20770
20660
  autoComplete: "off",
20771
- tabIndex: -1
20661
+ tabIndex: -1,
20662
+ onValueChange: (_value, _name, values) => {
20663
+ field.onChange(
20664
+ (values == null ? void 0 : values.value) ? values == null ? void 0 : values.value : ""
20665
+ );
20666
+ }
20772
20667
  }
20773
20668
  ) }),
20774
20669
  /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
@@ -20780,22 +20675,17 @@ const GiftCardCreateForm = ({
20780
20675
  Form$2.Field,
20781
20676
  {
20782
20677
  control: form.control,
20783
- name: "customer_id",
20678
+ name: "expires_at",
20784
20679
  render: ({ field }) => {
20785
- return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { className: "w-full", children: [
20786
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { className: "font-normal", children: "Customer" }),
20680
+ return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
20681
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Expires at" }),
20787
20682
  /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
20788
- Combobox,
20683
+ ui.DatePicker,
20789
20684
  {
20790
- value: field.value,
20791
- onChange: field.onChange,
20792
- searchValue,
20793
- onSearchValueChange,
20794
- options: customerOptions,
20795
- placeholder: "Search for a customer...",
20796
- fetchNextPage,
20797
- isFetchingNextPage,
20798
- noResultsPlaceholder: isLoading ? "Loading customers..." : "No customers found"
20685
+ hourCycle: 24,
20686
+ granularity: "minute",
20687
+ shouldCloseOnSelect: false,
20688
+ ...field
20799
20689
  }
20800
20690
  ) }),
20801
20691
  /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
@@ -21015,40 +20905,60 @@ const StoreCreditAccountDetailsSection = ({
21015
20905
  if (!storeCreditAccount || typeof storeCreditAccount.balance === "undefined") {
21016
20906
  return;
21017
20907
  }
21018
- return /* @__PURE__ */ jsxRuntime.jsx(ui.Container, { className: "grid grid-cols-2 gap-x-2 px-6 py-6", children: /* @__PURE__ */ jsxRuntime.jsxs(
21019
- ui.Text,
21020
- {
21021
- weight: "plus",
21022
- size: "xlarge",
21023
- className: "text-ui-fg-base flex gap-x-4",
21024
- children: [
21025
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-2", children: [
21026
- /* @__PURE__ */ jsxRuntime.jsx(CreditCardIcon, { className: "inline" }),
21027
- " "
21028
- ] }),
21029
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
21030
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-subtle", children: [
21031
- storeCreditAccount.currency_code.toUpperCase(),
21032
- " Account"
20908
+ return /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { className: "flex justify-between gap-x-2 px-6 py-6", children: [
20909
+ /* @__PURE__ */ jsxRuntime.jsxs(
20910
+ ui.Text,
20911
+ {
20912
+ weight: "plus",
20913
+ size: "xlarge",
20914
+ className: "text-ui-fg-base flex gap-x-4",
20915
+ children: [
20916
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-2", children: [
20917
+ /* @__PURE__ */ jsxRuntime.jsx(CreditCardIcon, { className: "inline" }),
20918
+ " "
21033
20919
  ] }),
21034
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-ui-fg-base", children: /* @__PURE__ */ jsxRuntime.jsx(
21035
- ui.Text,
21036
- {
21037
- weight: "regular",
21038
- size: "small",
21039
- className: "text-ui-fg-base flex gap-x-4",
21040
- children: /* @__PURE__ */ jsxRuntime.jsx(DisplayId, { id: storeCreditAccount.id })
21041
- }
21042
- ) })
21043
- ] })
21044
- ]
21045
- }
21046
- ) });
20920
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
20921
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-subtle", children: [
20922
+ storeCreditAccount.currency_code.toUpperCase(),
20923
+ " Account"
20924
+ ] }),
20925
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-ui-fg-base", children: /* @__PURE__ */ jsxRuntime.jsx(
20926
+ ui.Text,
20927
+ {
20928
+ weight: "regular",
20929
+ size: "small",
20930
+ className: "text-ui-fg-base flex gap-x-4",
20931
+ children: /* @__PURE__ */ jsxRuntime.jsx(DisplayId, { id: storeCreditAccount.id })
20932
+ }
20933
+ ) })
20934
+ ] })
20935
+ ]
20936
+ }
20937
+ ),
20938
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center gap-x-4", children: /* @__PURE__ */ jsxRuntime.jsx(
20939
+ ActionMenu,
20940
+ {
20941
+ groups: [
20942
+ {
20943
+ actions: [
20944
+ {
20945
+ icon: /* @__PURE__ */ jsxRuntime.jsx(icons.CreditCard, {}),
20946
+ label: "Credit the account",
20947
+ to: "credit"
20948
+ }
20949
+ ]
20950
+ }
20951
+ ]
20952
+ }
20953
+ ) })
20954
+ ] });
21047
20955
  };
21048
20956
  function StoreCreditAccountCustomerSection({
21049
20957
  customerId
21050
20958
  }) {
21051
- const { customer, isPending } = useCustomer(customerId);
20959
+ const { customer, isPending } = useCustomer(customerId, void 0, {
20960
+ enabled: !!customerId
20961
+ });
21052
20962
  if (isPending || !customer) {
21053
20963
  return null;
21054
20964
  }
@@ -21066,22 +20976,6 @@ function StoreCreditAccountCustomerSection({
21066
20976
  )
21067
20977
  ] });
21068
20978
  }
21069
- const transactionQueryKey = queryKeysFactory("transaction");
21070
- const useStoreCreditAccountTransactions = (id, query, options) => {
21071
- const fetchStoreCreditAccountTransactions = (query2, headers) => sdk.client.fetch(
21072
- `/admin/store-credit-accounts/${id}/transactions`,
21073
- {
21074
- query: query2,
21075
- headers
21076
- }
21077
- );
21078
- const { data, ...rest } = reactQuery.useQuery({
21079
- queryFn: () => fetchStoreCreditAccountTransactions(query),
21080
- queryKey: transactionQueryKey.list({ sca_id: id, query }),
21081
- ...options
21082
- });
21083
- return { ...data, ...rest };
21084
- };
21085
20979
  const columnHelper$8 = ui.createDataTableColumnHelper();
21086
20980
  const useTransactionsTableColumns = () => {
21087
20981
  return React.useMemo(() => {
@@ -21096,18 +20990,14 @@ const useTransactionsTableColumns = () => {
21096
20990
  header: "Created At",
21097
20991
  cell: ({ row }) => formatDate(row.original.created_at, false)
21098
20992
  }),
21099
- columnHelper$8.accessor("reference", {
21100
- header: "Reference",
21101
- cell: ({ row }) => {
21102
- var _a;
21103
- const prettyReference = (_a = row.original.reference) == null ? void 0 : _a.split("_").join(" ").split("-").join(" ");
21104
- return /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "capitalize", children: prettyReference });
21105
- }
20993
+ columnHelper$8.accessor("note", {
20994
+ header: "Description",
20995
+ cell: ({ row }) => row.original.note
21106
20996
  }),
21107
- columnHelper$8.accessor("reference_id", {
21108
- header: "Reference ID",
20997
+ columnHelper$8.accessor("note", {
20998
+ header: "Note",
21109
20999
  cell: ({ row }) => {
21110
- return /* @__PURE__ */ jsxRuntime.jsx(DisplayId, { id: row.original.reference_id });
21000
+ return /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { title: row.original.note, className: "max-w-[300px] truncate", children: row.original.note || "-" });
21111
21001
  }
21112
21002
  }),
21113
21003
  columnHelper$8.accessor("amount", {
@@ -21123,55 +21013,32 @@ const useTransactionsTableColumns = () => {
21123
21013
  ];
21124
21014
  }, []);
21125
21015
  };
21126
- const useTransactionsTableFilters = ({
21127
- transactionGroup
21128
- }) => {
21016
+ const useTransactionsTableFilters = ({}) => {
21129
21017
  const dateFilterOptions = useDataTableDateFilters$1();
21130
21018
  return React.useMemo(() => {
21131
- if (transactionGroup) {
21132
- return [...dateFilterOptions];
21133
- }
21134
21019
  return [...dateFilterOptions];
21135
- }, [dateFilterOptions, , transactionGroup]);
21020
+ }, [dateFilterOptions]);
21136
21021
  };
21137
21022
  const useTransactionsTableQuery = ({
21138
21023
  prefix,
21139
21024
  pageSize = 20
21140
21025
  }) => {
21141
21026
  const queryObject = useQueryParams(
21142
- [
21143
- "offset",
21144
- "limit",
21145
- "transaction_group_id",
21146
- "currency_code",
21147
- "created_at",
21148
- "updated_at"
21149
- ],
21027
+ ["offset", "limit", "currency_code", "created_at", "updated_at"],
21150
21028
  prefix
21151
21029
  );
21152
- const {
21153
- offset: offset2,
21154
- limit,
21155
- created_at,
21156
- updated_at,
21157
- transaction_group_id,
21158
- ...rest
21159
- } = queryObject;
21030
+ const { offset: offset2, limit, created_at, updated_at, ...rest } = queryObject;
21160
21031
  const searchParams = {
21161
21032
  limit: limit ? Number(limit) : pageSize,
21162
21033
  offset: offset2 ? Number(offset2) : 0,
21163
21034
  created_at: created_at ? JSON.parse(created_at) : void 0,
21164
21035
  updated_at: updated_at ? JSON.parse(updated_at) : void 0,
21165
- transaction_group_id: transaction_group_id ? JSON.parse(transaction_group_id) : void 0,
21166
21036
  ...rest
21167
21037
  };
21168
21038
  return searchParams;
21169
21039
  };
21170
21040
  const PAGE_SIZE$4 = 10;
21171
- function TransactionsTable({
21172
- id,
21173
- transactionGroup
21174
- }) {
21041
+ function TransactionsTable({ id }) {
21175
21042
  const queryParams = useTransactionsTableQuery({
21176
21043
  pageSize: PAGE_SIZE$4
21177
21044
  });
@@ -21179,13 +21046,12 @@ function TransactionsTable({
21179
21046
  id,
21180
21047
  {
21181
21048
  ...queryParams,
21182
- transaction_group_id: transactionGroup == null ? void 0 : transactionGroup.id,
21183
21049
  order: queryParams.order ?? "-created_at",
21184
- fields: "*account,*transaction_group"
21050
+ fields: "*account"
21185
21051
  }
21186
21052
  );
21187
21053
  const columns = useTransactionsTableColumns();
21188
- const filters = useTransactionsTableFilters({ transactionGroup });
21054
+ const filters = useTransactionsTableFilters({});
21189
21055
  return /* @__PURE__ */ jsxRuntime.jsxs(React.Fragment, { children: [
21190
21056
  /* @__PURE__ */ jsxRuntime.jsx(ui.Container, { className: "p-0", children: /* @__PURE__ */ jsxRuntime.jsx(
21191
21057
  DataTable,
@@ -21213,6 +21079,18 @@ function TransactionsTable({
21213
21079
  /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Outlet, {})
21214
21080
  ] });
21215
21081
  }
21082
+ function StoreCreditAccountCodeSection({ code }) {
21083
+ if (!code) {
21084
+ return null;
21085
+ }
21086
+ return /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { className: "p-0", children: [
21087
+ /* @__PURE__ */ jsxRuntime.jsx(Header$5, { title: "Account Code" }),
21088
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-4 px-6 mb-2", children: [
21089
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Share, { className: "inline" }),
21090
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-ui-fg-subtle text-sm", children: code })
21091
+ ] })
21092
+ ] });
21093
+ }
21216
21094
  const StoreCreditAccountPage = () => {
21217
21095
  const { id } = reactRouterDom.useParams();
21218
21096
  const { store_credit_account: storeCreditAccount } = useStoreCreditAccount(
@@ -21240,6 +21118,7 @@ const StoreCreditAccountPage = () => {
21240
21118
  storeCreditAccount
21241
21119
  }
21242
21120
  ),
21121
+ /* @__PURE__ */ jsxRuntime.jsx(StoreCreditAccountCodeSection, { code: storeCreditAccount.code }),
21243
21122
  /* @__PURE__ */ jsxRuntime.jsx(
21244
21123
  StoreCreditAccountCustomerSection,
21245
21124
  {
@@ -21250,6 +21129,145 @@ const StoreCreditAccountPage = () => {
21250
21129
  }
21251
21130
  ) });
21252
21131
  };
21132
+ const KeyboundForm = React__namespace.default.forwardRef(({ onSubmit, onKeyDown, ...rest }, ref) => {
21133
+ const handleSubmit = (event) => {
21134
+ event.preventDefault();
21135
+ onSubmit == null ? void 0 : onSubmit(event);
21136
+ };
21137
+ const handleKeyDown = (event) => {
21138
+ if (event.key === "Enter") {
21139
+ if (event.target instanceof HTMLTextAreaElement && !(event.metaKey || event.ctrlKey)) {
21140
+ return;
21141
+ }
21142
+ event.preventDefault();
21143
+ if (event.metaKey || event.ctrlKey) {
21144
+ handleSubmit(event);
21145
+ }
21146
+ }
21147
+ };
21148
+ return /* @__PURE__ */ jsxRuntime.jsx(
21149
+ "form",
21150
+ {
21151
+ ...rest,
21152
+ onSubmit: handleSubmit,
21153
+ onKeyDown: onKeyDown ?? handleKeyDown,
21154
+ ref
21155
+ }
21156
+ );
21157
+ });
21158
+ KeyboundForm.displayName = "KeyboundForm";
21159
+ const Note$1 = () => {
21160
+ const { id } = reactRouterDom.useParams();
21161
+ const {
21162
+ store_credit_account: storeCreditAccount,
21163
+ isPending,
21164
+ isError,
21165
+ error
21166
+ } = useStoreCreditAccount(id, {});
21167
+ if (isError) {
21168
+ throw error;
21169
+ }
21170
+ const isReady = !isPending && !!storeCreditAccount;
21171
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
21172
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
21173
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Credit store credit account" }) }),
21174
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Credit the store credit account" }) })
21175
+ ] }),
21176
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(StoreCreditAccountCreditForm, { storeCreditAccount })
21177
+ ] });
21178
+ };
21179
+ const StoreCreditAccountCreditForm = ({
21180
+ storeCreditAccount
21181
+ }) => {
21182
+ const form = useForm({
21183
+ defaultValues: {
21184
+ amount: {
21185
+ float: 0,
21186
+ value: ""
21187
+ },
21188
+ note: ""
21189
+ },
21190
+ resolver: t(schema$2)
21191
+ });
21192
+ const { mutateAsync, isPending } = useCreditStoreCreditAccount(
21193
+ storeCreditAccount.id
21194
+ );
21195
+ const { handleSuccess } = useRouteModal();
21196
+ const onSubmit = form.handleSubmit(async (data) => {
21197
+ if (data.amount.float <= 0) {
21198
+ form.setError("amount", { message: "Amount must be greater than 0" });
21199
+ return;
21200
+ }
21201
+ await mutateAsync(
21202
+ { amount: data.amount.float, note: data.note },
21203
+ {
21204
+ onSuccess: () => handleSuccess(),
21205
+ onError: (error) => ui.toast.error(error.message)
21206
+ }
21207
+ );
21208
+ });
21209
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
21210
+ KeyboundForm,
21211
+ {
21212
+ className: "flex flex-1 flex-col overflow-hidden",
21213
+ onSubmit,
21214
+ children: [
21215
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
21216
+ /* @__PURE__ */ jsxRuntime.jsx(
21217
+ Form$2.Field,
21218
+ {
21219
+ control: form.control,
21220
+ name: "amount",
21221
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
21222
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Amount" }),
21223
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
21224
+ ui.CurrencyInput,
21225
+ {
21226
+ min: 0,
21227
+ placeholder: "0",
21228
+ value: field.value.value,
21229
+ onValueChange: (_value, _name, values) => {
21230
+ field.onChange({
21231
+ value: values == null ? void 0 : values.value,
21232
+ float: (values == null ? void 0 : values.float) || null
21233
+ });
21234
+ },
21235
+ symbol: currencies[storeCreditAccount.currency_code.toUpperCase()].symbol_native,
21236
+ code: storeCreditAccount.currency_code.toUpperCase()
21237
+ }
21238
+ ) }),
21239
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
21240
+ ] })
21241
+ }
21242
+ ),
21243
+ /* @__PURE__ */ jsxRuntime.jsx(
21244
+ Form$2.Field,
21245
+ {
21246
+ control: form.control,
21247
+ name: "note",
21248
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
21249
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Note" }),
21250
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Textarea, { ...field }) }),
21251
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
21252
+ ] })
21253
+ }
21254
+ )
21255
+ ] }),
21256
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
21257
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
21258
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
21259
+ ] }) })
21260
+ ]
21261
+ }
21262
+ ) });
21263
+ };
21264
+ const schema$2 = objectType({
21265
+ note: stringType(),
21266
+ amount: objectType({
21267
+ float: numberType(),
21268
+ value: stringType()
21269
+ })
21270
+ });
21253
21271
  function _extends() {
21254
21272
  return _extends = Object.assign ? Object.assign.bind() : function(n2) {
21255
21273
  for (var e2 = 1; e2 < arguments.length; e2++) {
@@ -23717,10 +23735,6 @@ const SectionRow = ({ title, value, actions }) => {
23717
23735
  const GiftCardGeneralSection = ({ giftCard }) => {
23718
23736
  var _a, _b, _c, _d, _e, _f, _g, _h, _i;
23719
23737
  const prompt = ui.usePrompt();
23720
- reactRouterDom.useNavigate();
23721
- const { mutateAsync: redeemGiftCard, isPending } = useRedeemGiftCard(
23722
- giftCard.id
23723
- );
23724
23738
  const { mutateAsync: deleteGiftCard, isPending: isDeleting } = useDeleteGiftCard(giftCard.id);
23725
23739
  const handleDelete = async () => {
23726
23740
  const res = await prompt({
@@ -23739,8 +23753,9 @@ const GiftCardGeneralSection = ({ giftCard }) => {
23739
23753
  onError: (error) => ui.toast.error(error.message)
23740
23754
  });
23741
23755
  };
23742
- const status = getGiftCardStatus(giftCard);
23743
- const statusColor = getGiftCardStatusColor(status);
23756
+ const hasGiftCardExpired = React.useMemo(() => {
23757
+ return giftCard.expires_at && new Date(giftCard.expires_at) < /* @__PURE__ */ new Date();
23758
+ }, [giftCard.expires_at]);
23744
23759
  return /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { className: "divide-y p-0", children: [
23745
23760
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between px-6 py-4", children: [
23746
23761
  /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
@@ -23757,25 +23772,17 @@ const GiftCardGeneralSection = ({ giftCard }) => {
23757
23772
  }) })
23758
23773
  ] }),
23759
23774
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-4", children: [
23760
- /* @__PURE__ */ jsxRuntime.jsx(ui.StatusBadge, { color: statusColor, children: status }),
23775
+ hasGiftCardExpired && /* @__PURE__ */ jsxRuntime.jsx(ui.StatusBadge, { color: "orange", children: "Expired" }),
23761
23776
  /* @__PURE__ */ jsxRuntime.jsx(
23762
23777
  ActionMenu,
23763
23778
  {
23764
23779
  groups: [
23765
23780
  {
23766
23781
  actions: [
23767
- // TODO: revisit this - now GC doesn't have owner so redeeming would result in an anonymous account
23768
- // {
23769
- // icon: <Gift />,
23770
- // label: "Redeem gift card",
23771
- // onClick: () => handleRedeem(),
23772
- // disabled: isPending || giftCard.status === "redeemed",
23773
- // },
23774
23782
  {
23775
23783
  icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Calendar, {}),
23776
23784
  label: "Edit expiration date",
23777
- to: "expiration",
23778
- disabled: isPending
23785
+ to: "expiration"
23779
23786
  }
23780
23787
  ]
23781
23788
  },
@@ -23875,19 +23882,21 @@ const GiftCardNoteSection = ({ giftCard }) => {
23875
23882
  ] });
23876
23883
  };
23877
23884
  const GiftCardOrderSection = ({ giftCard }) => {
23878
- if (!giftCard || giftCard.reference !== "order") {
23879
- return;
23880
- }
23881
- const { order, isLoading, isError, error } = useOrder(giftCard.reference_id);
23885
+ const { orders, isLoading, isError, error } = useGiftCardOrders(
23886
+ giftCard == null ? void 0 : giftCard.id
23887
+ );
23882
23888
  if (isError) {
23883
23889
  throw error;
23884
23890
  }
23885
- if (isLoading) {
23891
+ if (isLoading || !orders) {
23892
+ return null;
23893
+ }
23894
+ if (orders && orders.length === 0) {
23886
23895
  return null;
23887
23896
  }
23888
23897
  return /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { className: "p-0", children: [
23889
23898
  /* @__PURE__ */ jsxRuntime.jsx(Header$5, { title: "Order" }),
23890
- /* @__PURE__ */ jsxRuntime.jsx(
23899
+ orders.map((order) => /* @__PURE__ */ jsxRuntime.jsx(
23891
23900
  SidebarLink,
23892
23901
  {
23893
23902
  to: `/orders/${order.id}`,
@@ -23895,7 +23904,7 @@ const GiftCardOrderSection = ({ giftCard }) => {
23895
23904
  icon: /* @__PURE__ */ jsxRuntime.jsx(icons.ShoppingCart, {}),
23896
23905
  descriptionKey: `Order #${order.display_id}`
23897
23906
  }
23898
- )
23907
+ ))
23899
23908
  ] });
23900
23909
  };
23901
23910
  const GiftCardTransactionsSection = ({
@@ -23945,100 +23954,6 @@ const GiftCardDetailsPage = () => {
23945
23954
  /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Outlet, {})
23946
23955
  ] });
23947
23956
  };
23948
- const KeyboundForm = React__namespace.default.forwardRef(({ onSubmit, onKeyDown, ...rest }, ref) => {
23949
- const handleSubmit = (event) => {
23950
- event.preventDefault();
23951
- onSubmit == null ? void 0 : onSubmit(event);
23952
- };
23953
- const handleKeyDown = (event) => {
23954
- if (event.key === "Enter") {
23955
- if (event.target instanceof HTMLTextAreaElement && !(event.metaKey || event.ctrlKey)) {
23956
- return;
23957
- }
23958
- event.preventDefault();
23959
- if (event.metaKey || event.ctrlKey) {
23960
- handleSubmit(event);
23961
- }
23962
- }
23963
- };
23964
- return /* @__PURE__ */ jsxRuntime.jsx(
23965
- "form",
23966
- {
23967
- ...rest,
23968
- onSubmit: handleSubmit,
23969
- onKeyDown: onKeyDown ?? handleKeyDown,
23970
- ref
23971
- }
23972
- );
23973
- });
23974
- KeyboundForm.displayName = "KeyboundForm";
23975
- const Note = () => {
23976
- const { id } = reactRouterDom.useParams();
23977
- const {
23978
- gift_card: giftCard,
23979
- isPending,
23980
- isError,
23981
- error
23982
- } = useGiftCard(id, {});
23983
- if (isError) {
23984
- throw error;
23985
- }
23986
- const isReady = !isPending && !!giftCard;
23987
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
23988
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
23989
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit note" }) }),
23990
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the note for the gift card" }) })
23991
- ] }),
23992
- isReady && /* @__PURE__ */ jsxRuntime.jsx(GiftCardNoteForm, { giftCard })
23993
- ] });
23994
- };
23995
- const GiftCardNoteForm = ({ giftCard }) => {
23996
- const form = useForm({
23997
- defaultValues: {
23998
- note: giftCard.note ?? ""
23999
- },
24000
- resolver: t(schema$1)
24001
- });
24002
- const { mutateAsync, isPending } = useUpdateGiftCard(giftCard.id);
24003
- const { handleSuccess } = useRouteModal();
24004
- const onSubmit = form.handleSubmit(async (data) => {
24005
- await mutateAsync(
24006
- { note: data.note },
24007
- {
24008
- onSuccess: () => handleSuccess(),
24009
- onError: (error) => ui.toast.error(error.message)
24010
- }
24011
- );
24012
- });
24013
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
24014
- KeyboundForm,
24015
- {
24016
- className: "flex flex-1 flex-col overflow-hidden",
24017
- onSubmit,
24018
- children: [
24019
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(
24020
- Form$2.Field,
24021
- {
24022
- control: form.control,
24023
- name: "note",
24024
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
24025
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Note" }),
24026
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Textarea, { ...field }) }),
24027
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
24028
- ] })
24029
- }
24030
- ) }),
24031
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
24032
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
24033
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
24034
- ] }) })
24035
- ]
24036
- }
24037
- ) });
24038
- };
24039
- const schema$1 = z.object({
24040
- note: z.string().optional()
24041
- });
24042
23957
  const GiftCardExpiration = () => {
24043
23958
  const { id } = reactRouterDom.useParams();
24044
23959
  const {
@@ -24064,7 +23979,7 @@ const GiftCardExpirationForm = ({ giftCard }) => {
24064
23979
  defaultValues: {
24065
23980
  expires_at: giftCard.expires_at ? new Date(giftCard.expires_at) : null
24066
23981
  },
24067
- resolver: t(schema)
23982
+ resolver: t(schema$1)
24068
23983
  });
24069
23984
  const { mutateAsync, isPending } = useUpdateGiftCard(giftCard.id);
24070
23985
  const { handleSuccess } = useRouteModal();
@@ -24153,8 +24068,75 @@ const GiftCardExpirationForm = ({ giftCard }) => {
24153
24068
  }
24154
24069
  ) });
24155
24070
  };
24156
- const schema = z.object({
24157
- expires_at: z.date().nullish()
24071
+ const schema$1 = objectType({
24072
+ expires_at: dateType().nullish()
24073
+ });
24074
+ const Note = () => {
24075
+ const { id } = reactRouterDom.useParams();
24076
+ const {
24077
+ gift_card: giftCard,
24078
+ isPending,
24079
+ isError,
24080
+ error
24081
+ } = useGiftCard(id, {});
24082
+ if (isError) {
24083
+ throw error;
24084
+ }
24085
+ const isReady = !isPending && !!giftCard;
24086
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
24087
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
24088
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit note" }) }),
24089
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the note for the gift card" }) })
24090
+ ] }),
24091
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(GiftCardNoteForm, { giftCard })
24092
+ ] });
24093
+ };
24094
+ const GiftCardNoteForm = ({ giftCard }) => {
24095
+ const form = useForm({
24096
+ defaultValues: {
24097
+ note: giftCard.note ?? ""
24098
+ },
24099
+ resolver: t(schema)
24100
+ });
24101
+ const { mutateAsync, isPending } = useUpdateGiftCard(giftCard.id);
24102
+ const { handleSuccess } = useRouteModal();
24103
+ const onSubmit = form.handleSubmit(async (data) => {
24104
+ await mutateAsync(
24105
+ { note: data.note },
24106
+ {
24107
+ onSuccess: () => handleSuccess(),
24108
+ onError: (error) => ui.toast.error(error.message)
24109
+ }
24110
+ );
24111
+ });
24112
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
24113
+ KeyboundForm,
24114
+ {
24115
+ className: "flex flex-1 flex-col overflow-hidden",
24116
+ onSubmit,
24117
+ children: [
24118
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(
24119
+ Form$2.Field,
24120
+ {
24121
+ control: form.control,
24122
+ name: "note",
24123
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
24124
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Note" }),
24125
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Textarea, { ...field }) }),
24126
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
24127
+ ] })
24128
+ }
24129
+ ) }),
24130
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
24131
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
24132
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
24133
+ ] }) })
24134
+ ]
24135
+ }
24136
+ ) });
24137
+ };
24138
+ const schema = objectType({
24139
+ note: stringType().optional()
24158
24140
  });
24159
24141
  const columnHelper$7 = createColumnHelper();
24160
24142
  const useGiftCardProductsTableColumns = () => {
@@ -26582,7 +26564,7 @@ instance.loadLanguages;
26582
26564
  const castNumber = (number) => {
26583
26565
  return typeof number === "string" ? Number(number.replace(",", ".")) : number;
26584
26566
  };
26585
- const optionalInt = z.union([z.string(), z.number()]).optional().refine(
26567
+ const optionalInt = unionType([stringType(), numberType()]).optional().refine(
26586
26568
  (value) => {
26587
26569
  if (value === "" || value === void 0) {
26588
26570
  return true;
@@ -26603,7 +26585,7 @@ const optionalInt = z.union([z.string(), z.number()]).optional().refine(
26603
26585
  message: instance.t("validation.mustBePositive")
26604
26586
  }
26605
26587
  );
26606
- const optionalFloat = z.union([z.string(), z.number()]).optional().refine(
26588
+ const optionalFloat = unionType([stringType(), numberType()]).optional().refine(
26607
26589
  (value) => {
26608
26590
  if (value === "" || value === void 0) {
26609
26591
  return true;
@@ -26614,13 +26596,13 @@ const optionalFloat = z.union([z.string(), z.number()]).optional().refine(
26614
26596
  message: instance.t("validation.mustBePositive")
26615
26597
  }
26616
26598
  );
26617
- z.array(
26618
- z.object({
26619
- key: z.string(),
26620
- value: z.unknown(),
26621
- isInitial: z.boolean().optional(),
26622
- isDeleted: z.boolean().optional(),
26623
- isIgnored: z.boolean().optional()
26599
+ arrayType(
26600
+ objectType({
26601
+ key: stringType(),
26602
+ value: unknownType(),
26603
+ isInitial: booleanType().optional(),
26604
+ isDeleted: booleanType().optional(),
26605
+ isIgnored: booleanType().optional()
26624
26606
  })
26625
26607
  );
26626
26608
  const normalizeProductFormValues = (values) => {
@@ -36410,81 +36392,81 @@ const useSalesChannelTableQuery = ({
36410
36392
  return searchParams;
36411
36393
  };
36412
36394
  const SC_STACKED_MODAL_ID = "sc";
36413
- const MediaSchema = z.object({
36414
- id: z.string().optional(),
36415
- url: z.string(),
36416
- isThumbnail: z.boolean(),
36417
- file: z.any().nullable()
36395
+ const MediaSchema = objectType({
36396
+ id: stringType().optional(),
36397
+ url: stringType(),
36398
+ isThumbnail: booleanType(),
36399
+ file: anyType().nullable()
36418
36400
  // File
36419
36401
  });
36420
- z.object({
36421
- should_create: z.boolean(),
36422
- is_default: z.boolean().optional(),
36423
- title: z.string(),
36424
- upc: z.string().optional(),
36425
- ean: z.string().optional(),
36426
- barcode: z.string().optional(),
36427
- mid_code: z.string().optional(),
36428
- hs_code: z.string().optional(),
36402
+ objectType({
36403
+ should_create: booleanType(),
36404
+ is_default: booleanType().optional(),
36405
+ title: stringType(),
36406
+ upc: stringType().optional(),
36407
+ ean: stringType().optional(),
36408
+ barcode: stringType().optional(),
36409
+ mid_code: stringType().optional(),
36410
+ hs_code: stringType().optional(),
36429
36411
  width: optionalInt,
36430
36412
  height: optionalInt,
36431
36413
  length: optionalInt,
36432
36414
  weight: optionalInt,
36433
- material: z.string().optional(),
36434
- origin_country: z.string().optional(),
36435
- manage_inventory: z.boolean().optional(),
36436
- allow_backorder: z.boolean().optional(),
36437
- inventory_kit: z.boolean().optional(),
36438
- options: z.record(z.string(), z.string()),
36439
- variant_rank: z.number(),
36440
- prices: z.record(z.string(), optionalFloat).optional(),
36441
- inventory: z.array(
36442
- z.object({
36443
- inventory_item_id: z.string(),
36415
+ material: stringType().optional(),
36416
+ origin_country: stringType().optional(),
36417
+ manage_inventory: booleanType().optional(),
36418
+ allow_backorder: booleanType().optional(),
36419
+ inventory_kit: booleanType().optional(),
36420
+ options: recordType(stringType(), stringType()),
36421
+ variant_rank: numberType(),
36422
+ prices: recordType(stringType(), optionalFloat).optional(),
36423
+ inventory: arrayType(
36424
+ objectType({
36425
+ inventory_item_id: stringType(),
36444
36426
  required_quantity: optionalInt
36445
36427
  })
36446
36428
  ).optional()
36447
36429
  });
36448
- z.object({
36449
- title: z.string(),
36450
- values: z.array(z.string()).min(1)
36430
+ objectType({
36431
+ title: stringType(),
36432
+ values: arrayType(stringType()).min(1)
36451
36433
  });
36452
- const ProductCreateSchema = z.object({
36453
- title: z.string().min(1),
36454
- subtitle: z.string().optional(),
36455
- handle: z.string().optional(),
36456
- description: z.string().optional(),
36457
- discountable: z.boolean(),
36458
- type_id: z.string().optional(),
36459
- collection_id: z.string().optional(),
36460
- shipping_profile_id: z.string().optional(),
36461
- categories: z.array(z.string()),
36462
- tags: z.array(z.string()).optional(),
36463
- sales_channels: z.array(
36464
- z.object({
36465
- id: z.string(),
36466
- name: z.string()
36434
+ const ProductCreateSchema = objectType({
36435
+ title: stringType().min(1),
36436
+ subtitle: stringType().optional(),
36437
+ handle: stringType().optional(),
36438
+ description: stringType().optional(),
36439
+ discountable: booleanType(),
36440
+ type_id: stringType().optional(),
36441
+ collection_id: stringType().optional(),
36442
+ shipping_profile_id: stringType().optional(),
36443
+ categories: arrayType(stringType()),
36444
+ tags: arrayType(stringType()).optional(),
36445
+ sales_channels: arrayType(
36446
+ objectType({
36447
+ id: stringType(),
36448
+ name: stringType()
36467
36449
  })
36468
36450
  ).optional(),
36469
- origin_country: z.string().optional(),
36470
- material: z.string().optional(),
36471
- width: z.string().optional(),
36472
- length: z.string().optional(),
36473
- height: z.string().optional(),
36474
- weight: z.string().optional(),
36475
- mid_code: z.string().optional(),
36476
- hs_code: z.string().optional(),
36477
- denominations: z.array(
36478
- z.object({
36479
- value: z.string().min(1),
36480
- prices: z.record(z.string(), optionalFloat).optional()
36451
+ origin_country: stringType().optional(),
36452
+ material: stringType().optional(),
36453
+ width: stringType().optional(),
36454
+ length: stringType().optional(),
36455
+ height: stringType().optional(),
36456
+ weight: stringType().optional(),
36457
+ mid_code: stringType().optional(),
36458
+ hs_code: stringType().optional(),
36459
+ denominations: arrayType(
36460
+ objectType({
36461
+ value: stringType().min(1),
36462
+ prices: recordType(stringType(), optionalFloat).optional()
36481
36463
  })
36482
36464
  ).min(1),
36483
- enable_variants: z.boolean(),
36484
- media: z.array(MediaSchema).optional()
36465
+ enable_variants: booleanType(),
36466
+ media: arrayType(MediaSchema).optional()
36485
36467
  });
36486
- const EditProductMediaSchema = z.object({
36487
- media: z.array(MediaSchema)
36468
+ const EditProductMediaSchema = objectType({
36469
+ media: arrayType(MediaSchema)
36488
36470
  });
36489
36471
  const PRODUCT_CREATE_FORM_DEFAULTS = {
36490
36472
  discountable: true,
@@ -37437,12 +37419,159 @@ const ProductDetail = () => {
37437
37419
  /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Outlet, {})
37438
37420
  ] });
37439
37421
  };
37440
- const EditProductSchema$1 = z.object({
37441
- status: z.enum(["draft", "published", "proposed", "rejected"]),
37442
- title: z.string().min(1),
37443
- subtitle: z.string().optional(),
37444
- handle: z.string().min(1),
37445
- description: z.string().optional()
37422
+ const EditProductSchema$1 = objectType({
37423
+ denominations: arrayType(
37424
+ objectType({
37425
+ id: stringType().optional(),
37426
+ value: stringType().min(1),
37427
+ prices: recordType(stringType(), optionalFloat).optional()
37428
+ })
37429
+ ).min(1)
37430
+ });
37431
+ const GiftCardProductEditDenominationsForm = ({
37432
+ product
37433
+ }) => {
37434
+ var _a;
37435
+ const { handleSuccess } = useRouteModal();
37436
+ const form = useForm({
37437
+ defaultValues: {
37438
+ denominations: (_a = product.variants) == null ? void 0 : _a.map((variant) => ({
37439
+ id: variant.id,
37440
+ value: variant.title
37441
+ }))
37442
+ },
37443
+ resolver: t(EditProductSchema$1)
37444
+ });
37445
+ const { mutateAsync, isPending } = useUpdateProduct(product.id);
37446
+ const handleSubmit = form.handleSubmit(async (data) => {
37447
+ const optionValues = data.denominations.map(
37448
+ (denomination) => denomination.value
37449
+ );
37450
+ const options = [
37451
+ {
37452
+ title: "denomination",
37453
+ values: optionValues
37454
+ }
37455
+ ];
37456
+ await mutateAsync(
37457
+ {
37458
+ options,
37459
+ variants: data.denominations.map((denomination) => ({
37460
+ id: denomination.id,
37461
+ title: denomination.value,
37462
+ manage_inventory: false,
37463
+ options: {
37464
+ denomination: denomination.value
37465
+ }
37466
+ }))
37467
+ },
37468
+ {
37469
+ onSuccess: () => {
37470
+ ui.toast.success(`Denominations updated successfully`);
37471
+ handleSuccess();
37472
+ },
37473
+ onError: (e2) => {
37474
+ ui.toast.error(e2.message);
37475
+ }
37476
+ }
37477
+ );
37478
+ });
37479
+ const {
37480
+ fields: denominationsFields,
37481
+ append: addDenomination,
37482
+ remove: removeDenomination
37483
+ } = useFieldArray({
37484
+ name: "denominations",
37485
+ control: form.control
37486
+ });
37487
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
37488
+ KeyboundForm,
37489
+ {
37490
+ onSubmit: handleSubmit,
37491
+ className: "flex flex-1 flex-col overflow-hidden",
37492
+ children: [
37493
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-y-6", children: /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-2", children: [
37494
+ denominationsFields.map((denominationField, index) => {
37495
+ return /* @__PURE__ */ jsxRuntime.jsxs(
37496
+ "div",
37497
+ {
37498
+ className: "flex items-center justify-between shadow-elevation-card-rest bg-ui-bg-component transition-fg rounded-md px-4 py-2",
37499
+ children: [
37500
+ /* @__PURE__ */ jsxRuntime.jsx(
37501
+ Form$2.Field,
37502
+ {
37503
+ control: form.control,
37504
+ name: `denominations.${index}.value`,
37505
+ render: ({ field }) => {
37506
+ return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { className: "w-full", children: [
37507
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field, placeholder: "100" }) }),
37508
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
37509
+ ] });
37510
+ }
37511
+ },
37512
+ denominationField.id
37513
+ ),
37514
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center rounded-xl", children: /* @__PURE__ */ jsxRuntime.jsx(
37515
+ ui.Button,
37516
+ {
37517
+ size: "small",
37518
+ variant: "secondary",
37519
+ type: "button",
37520
+ className: "rounded-full p-0 ml-4",
37521
+ onClick: () => {
37522
+ removeDenomination(index);
37523
+ },
37524
+ children: /* @__PURE__ */ jsxRuntime.jsx(icons.XCircleSolid, { className: "rounded-full" })
37525
+ }
37526
+ ) })
37527
+ ]
37528
+ },
37529
+ denominationField.id
37530
+ );
37531
+ }),
37532
+ /* @__PURE__ */ jsxRuntime.jsx(
37533
+ ui.Button,
37534
+ {
37535
+ size: "small",
37536
+ variant: "secondary",
37537
+ type: "button",
37538
+ className: "w-full",
37539
+ onClick: () => {
37540
+ addDenomination({ value: "", prices: {} });
37541
+ },
37542
+ children: "Add denomination"
37543
+ }
37544
+ ),
37545
+ form.formState.errors.denominations && /* @__PURE__ */ jsxRuntime.jsx(ui.Alert, { variant: "error", children: "Please add at least one denomination." })
37546
+ ] }) }) }) }),
37547
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
37548
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
37549
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
37550
+ ] }) })
37551
+ ]
37552
+ }
37553
+ ) });
37554
+ };
37555
+ const GiftCardProductEdit$1 = () => {
37556
+ const { id } = reactRouterDom.useParams();
37557
+ const { product, isLoading, isError, error } = useProduct(id, {});
37558
+ if (isError) {
37559
+ throw error;
37560
+ }
37561
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
37562
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
37563
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit gift cards denominations" }) }),
37564
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { className: "sr-only", children: "Edit the gift card denominations" })
37565
+ ] }),
37566
+ !isLoading && product && /* @__PURE__ */ jsxRuntime.jsx(GiftCardProductEditDenominationsForm, { product })
37567
+ ] });
37568
+ };
37569
+ const EditProductSchema = objectType({
37570
+ status: enumType(["draft", "published", "proposed", "rejected"]),
37571
+ title: stringType().min(1),
37572
+ subtitle: stringType().optional(),
37573
+ handle: stringType().min(1),
37574
+ description: stringType().optional()
37446
37575
  });
37447
37576
  const GiftCardProductEditForm = ({
37448
37577
  product
@@ -37456,7 +37585,7 @@ const GiftCardProductEditForm = ({
37456
37585
  handle: product.handle || "",
37457
37586
  description: product.description || ""
37458
37587
  },
37459
- resolver: t(EditProductSchema$1)
37588
+ resolver: t(EditProductSchema)
37460
37589
  });
37461
37590
  const { mutateAsync, isPending } = useUpdateProduct(product.id);
37462
37591
  const handleSubmit = form.handleSubmit(async (data) => {
@@ -37597,7 +37726,7 @@ const GiftCardProductEditForm = ({
37597
37726
  }
37598
37727
  ) });
37599
37728
  };
37600
- const GiftCardProductEdit$1 = () => {
37729
+ const GiftCardProductEdit = () => {
37601
37730
  const { id } = reactRouterDom.useParams();
37602
37731
  const { product, isLoading, isError, error } = useProduct(id, {});
37603
37732
  if (isError) {
@@ -37611,152 +37740,6 @@ const GiftCardProductEdit$1 = () => {
37611
37740
  !isLoading && product && /* @__PURE__ */ jsxRuntime.jsx(GiftCardProductEditForm, { product })
37612
37741
  ] });
37613
37742
  };
37614
- const EditProductSchema = z.object({
37615
- denominations: z.array(
37616
- z.object({
37617
- id: z.string().optional(),
37618
- value: z.string().min(1),
37619
- prices: z.record(z.string(), optionalFloat).optional()
37620
- })
37621
- ).min(1)
37622
- });
37623
- const GiftCardProductEditDenominationsForm = ({
37624
- product
37625
- }) => {
37626
- var _a;
37627
- const { handleSuccess } = useRouteModal();
37628
- const form = useForm({
37629
- defaultValues: {
37630
- denominations: (_a = product.variants) == null ? void 0 : _a.map((variant) => ({
37631
- id: variant.id,
37632
- value: variant.title
37633
- }))
37634
- },
37635
- resolver: t(EditProductSchema)
37636
- });
37637
- const { mutateAsync, isPending } = useUpdateProduct(product.id);
37638
- const handleSubmit = form.handleSubmit(async (data) => {
37639
- const optionValues = data.denominations.map(
37640
- (denomination) => denomination.value
37641
- );
37642
- const options = [
37643
- {
37644
- title: "denomination",
37645
- values: optionValues
37646
- }
37647
- ];
37648
- await mutateAsync(
37649
- {
37650
- options,
37651
- variants: data.denominations.map((denomination) => ({
37652
- id: denomination.id,
37653
- title: denomination.value,
37654
- options: {
37655
- denomination: denomination.value
37656
- }
37657
- }))
37658
- },
37659
- {
37660
- onSuccess: () => {
37661
- ui.toast.success(`Denominations updated successfully`);
37662
- handleSuccess();
37663
- },
37664
- onError: (e2) => {
37665
- ui.toast.error(e2.message);
37666
- }
37667
- }
37668
- );
37669
- });
37670
- const {
37671
- fields: denominationsFields,
37672
- append: addDenomination,
37673
- remove: removeDenomination
37674
- } = useFieldArray({
37675
- name: "denominations",
37676
- control: form.control
37677
- });
37678
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
37679
- KeyboundForm,
37680
- {
37681
- onSubmit: handleSubmit,
37682
- className: "flex flex-1 flex-col overflow-hidden",
37683
- children: [
37684
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-y-6", children: /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-2", children: [
37685
- denominationsFields.map((denominationField, index) => {
37686
- return /* @__PURE__ */ jsxRuntime.jsxs(
37687
- "div",
37688
- {
37689
- className: "flex items-center justify-between shadow-elevation-card-rest bg-ui-bg-component transition-fg rounded-md px-4 py-2",
37690
- children: [
37691
- /* @__PURE__ */ jsxRuntime.jsx(
37692
- Form$2.Field,
37693
- {
37694
- control: form.control,
37695
- name: `denominations.${index}.value`,
37696
- render: ({ field }) => {
37697
- return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { className: "w-full", children: [
37698
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field, placeholder: "100" }) }),
37699
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
37700
- ] });
37701
- }
37702
- },
37703
- denominationField.id
37704
- ),
37705
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center rounded-xl", children: /* @__PURE__ */ jsxRuntime.jsx(
37706
- ui.Button,
37707
- {
37708
- size: "small",
37709
- variant: "secondary",
37710
- type: "button",
37711
- className: "rounded-full p-0 ml-4",
37712
- onClick: () => {
37713
- removeDenomination(index);
37714
- },
37715
- children: /* @__PURE__ */ jsxRuntime.jsx(icons.XCircleSolid, { className: "rounded-full" })
37716
- }
37717
- ) })
37718
- ]
37719
- },
37720
- denominationField.id
37721
- );
37722
- }),
37723
- /* @__PURE__ */ jsxRuntime.jsx(
37724
- ui.Button,
37725
- {
37726
- size: "small",
37727
- variant: "secondary",
37728
- type: "button",
37729
- className: "w-full",
37730
- onClick: () => {
37731
- addDenomination({ value: "", prices: {} });
37732
- },
37733
- children: "Add denomination"
37734
- }
37735
- ),
37736
- form.formState.errors.denominations && /* @__PURE__ */ jsxRuntime.jsx(ui.Alert, { variant: "error", children: "Please add at least one denomination." })
37737
- ] }) }) }) }),
37738
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
37739
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
37740
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
37741
- ] }) })
37742
- ]
37743
- }
37744
- ) });
37745
- };
37746
- const GiftCardProductEdit = () => {
37747
- const { id } = reactRouterDom.useParams();
37748
- const { product, isLoading, isError, error } = useProduct(id, {});
37749
- if (isError) {
37750
- throw error;
37751
- }
37752
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
37753
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
37754
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit gift cards denominations" }) }),
37755
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { className: "sr-only", children: "Edit the gift card denominations" })
37756
- ] }),
37757
- !isLoading && product && /* @__PURE__ */ jsxRuntime.jsx(GiftCardProductEditDenominationsForm, { product })
37758
- ] });
37759
- };
37760
37743
  const EditProductMediaForm = ({ product }) => {
37761
37744
  const [selection, setSelection] = React.useState({});
37762
37745
  const { handleSuccess } = useRouteModal();
@@ -38672,19 +38655,25 @@ const routeModule = {
38672
38655
  },
38673
38656
  {
38674
38657
  Component: StoreCreditAccountPage,
38675
- path: "/store-credit-accounts/:id"
38658
+ path: "/store-credit-accounts/:id",
38659
+ children: [
38660
+ {
38661
+ Component: Note$1,
38662
+ path: "/store-credit-accounts/:id/credit"
38663
+ }
38664
+ ]
38676
38665
  },
38677
38666
  {
38678
38667
  Component: GiftCardDetailsPage,
38679
38668
  path: "/gift-cards/:id",
38680
38669
  children: [
38681
- {
38682
- Component: Note,
38683
- path: "/gift-cards/:id/note"
38684
- },
38685
38670
  {
38686
38671
  Component: GiftCardExpiration,
38687
38672
  path: "/gift-cards/:id/expiration"
38673
+ },
38674
+ {
38675
+ Component: Note,
38676
+ path: "/gift-cards/:id/note"
38688
38677
  }
38689
38678
  ]
38690
38679
  },
@@ -38704,11 +38693,11 @@ const routeModule = {
38704
38693
  children: [
38705
38694
  {
38706
38695
  Component: GiftCardProductEdit$1,
38707
- path: "/gift-cards/gift-card-products/:id/edit"
38696
+ path: "/gift-cards/gift-card-products/:id/denominations"
38708
38697
  },
38709
38698
  {
38710
38699
  Component: GiftCardProductEdit,
38711
- path: "/gift-cards/gift-card-products/:id/denominations"
38700
+ path: "/gift-cards/gift-card-products/:id/edit"
38712
38701
  }
38713
38702
  ]
38714
38703
  },