@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
@@ -3,11 +3,11 @@ var __defNormalProp = (obj, key2, value) => key2 in obj ? __defProp(obj, key2, {
3
3
  var __publicField = (obj, key2, value) => __defNormalProp(obj, typeof key2 !== "symbol" ? key2 + "" : key2, value);
4
4
  import { jsxs, jsx, Fragment } from "react/jsx-runtime";
5
5
  import { defineWidgetConfig, defineRouteConfig } from "@medusajs/admin-sdk";
6
- import { DropdownMenu, IconButton, clx, Heading, Text, Tooltip, Button, Container as Container$1, StatusBadge, useDataTable, DataTable as DataTable$1, createDataTableFilterHelper, usePrompt, Checkbox, toast, createDataTableColumnHelper, Badge, Toaster, Label as Label$1, Hint as Hint$1, Prompt, Drawer, FocusModal, Divider, CurrencyInput as CurrencyInput$1, Textarea, Kbd, Copy, RadioGroup, DatePicker, Skeleton, Input, Alert, ProgressTabs, CommandBar, Select } from "@medusajs/ui";
6
+ import { DropdownMenu, IconButton, clx, Heading, Text, Tooltip, Button, Container as Container$1, StatusBadge, useDataTable, DataTable as DataTable$1, createDataTableFilterHelper, usePrompt, Checkbox, toast, createDataTableColumnHelper, Badge, Toaster, Label as Label$1, Hint as Hint$1, Prompt, Drawer, FocusModal, Divider, CurrencyInput as CurrencyInput$1, DatePicker, Textarea, Kbd, Copy, RadioGroup, Skeleton, Input, Alert, ProgressTabs, CommandBar, Select } from "@medusajs/ui";
7
7
  import { Link, useParams, useSearchParams, useNavigate, Outlet, useBlocker, useLocation } from "react-router-dom";
8
8
  import * as React from "react";
9
9
  import React__default, { createElement as createElement$1, useState, useCallback, useMemo, Fragment as Fragment$1, createContext, forwardRef, useId as useId$1, useContext, useEffect, isValidElement as isValidElement$1, useLayoutEffect, useRef, useReducer, useTransition, useImperativeHandle, useDeferredValue, Suspense, memo as memo$2, cloneElement } from "react";
10
- import { EllipsisHorizontal, InformationCircleSolid, ExclamationCircle, PlusMini, TriangleRightMini, Gift, Photo, PencilSquare, Trash, XMarkMini, TrianglesMini, CheckMini, EllipseMiniSolid, Tag, User, ArrowUpRightOnBox, TriangleDownMini, Check, SquareTwoStack, Calendar, ShoppingCart, AdjustmentsDone, Adjustments, TaxInclusive, TaxExclusive, XMark, ArrowDownTray, DotsSix, ThumbnailBadge, StackPerspective, XCircleSolid, TriangleLeftMini } from "@medusajs/icons";
10
+ import { EllipsisHorizontal, InformationCircleSolid, ExclamationCircle, PlusMini, TriangleRightMini, Gift, Photo, PencilSquare, Trash, XMarkMini, TrianglesMini, CheckMini, EllipseMiniSolid, Tag, CreditCard, User, Share, ArrowUpRightOnBox, TriangleDownMini, Check, SquareTwoStack, Calendar, ShoppingCart, AdjustmentsDone, Adjustments, TaxInclusive, TaxExclusive, XMark, ArrowDownTray, DotsSix, ThumbnailBadge, StackPerspective, XCircleSolid, TriangleLeftMini } from "@medusajs/icons";
11
11
  import { useQuery, useQueryClient, useMutation, useInfiniteQuery, keepPreviousData } from "@tanstack/react-query";
12
12
  import Medusa, { FetchError } from "@medusajs/js-sdk";
13
13
  import { format as format$1, subDays, subMonths, formatDistance, sub } from "date-fns";
@@ -183,6 +183,22 @@ const sdk = new Medusa({
183
183
  type: "session"
184
184
  }
185
185
  });
186
+ const transactionQueryKey = queryKeysFactory("transaction");
187
+ const useStoreCreditAccountTransactions = (id, query, options) => {
188
+ const fetchStoreCreditAccountTransactions = (query2, headers) => sdk.client.fetch(
189
+ `/admin/store-credit-accounts/${id}/transactions`,
190
+ {
191
+ query: query2,
192
+ headers
193
+ }
194
+ );
195
+ const { data, ...rest } = useQuery({
196
+ queryFn: () => fetchStoreCreditAccountTransactions(query),
197
+ queryKey: transactionQueryKey.list({ sca_id: id, query }),
198
+ ...options
199
+ });
200
+ return { ...data, ...rest };
201
+ };
186
202
  const storeCreditAccountQueryKey = queryKeysFactory(
187
203
  "store-credit-account"
188
204
  );
@@ -231,6 +247,24 @@ const useCreateStoreCreditAccount = (options) => {
231
247
  ...options
232
248
  });
233
249
  };
250
+ const useCreditStoreCreditAccount = (id, options) => {
251
+ const queryClient = useQueryClient();
252
+ return useMutation({
253
+ mutationFn: (payload) => sdk.client.fetch(
254
+ `/admin/store-credit-accounts/${id}/credit`,
255
+ { body: payload, method: "POST" }
256
+ ),
257
+ onSuccess: (data, variables, context) => {
258
+ queryClient.invalidateQueries({
259
+ queryKey: storeCreditAccountQueryKey.detail(id)
260
+ });
261
+ queryClient.invalidateQueries({
262
+ queryKey: transactionQueryKey.list({ sca_id: id })
263
+ });
264
+ },
265
+ ...options
266
+ });
267
+ };
234
268
  const CreditCardIcon = ({ className }) => {
235
269
  return /* @__PURE__ */ jsxs(
236
270
  "svg",
@@ -406,29 +440,6 @@ const useOrder = (id, query, options) => {
406
440
  });
407
441
  return { ...data, ...rest };
408
442
  };
409
- var GiftCardStatus = /* @__PURE__ */ ((GiftCardStatus2) => {
410
- GiftCardStatus2["PENDING"] = "pending";
411
- GiftCardStatus2["REDEEMED"] = "redeemed";
412
- return GiftCardStatus2;
413
- })(GiftCardStatus || {});
414
- function getGiftCardStatus(giftCard) {
415
- if (giftCard.expires_at && new Date(giftCard.expires_at) < /* @__PURE__ */ new Date()) {
416
- return "deactivated";
417
- } else if (giftCard.status === GiftCardStatus.PENDING) {
418
- return "pending";
419
- } else {
420
- return "active";
421
- }
422
- }
423
- function getGiftCardStatusColor(status) {
424
- if (status === "deactivated") {
425
- return "red";
426
- } else if (status === "pending") {
427
- return "orange";
428
- } else {
429
- return "green";
430
- }
431
- }
432
443
  const OrderGiftCardsWidget = () => {
433
444
  var _a, _b, _c;
434
445
  const params = useParams();
@@ -457,8 +468,7 @@ const OrderGiftCardsWidget = () => {
457
468
  }
458
469
  ),
459
470
  (_c = order == null ? void 0 : order.gift_cards) == null ? void 0 : _c.map((giftCard) => {
460
- const giftCardStatus = getGiftCardStatus(giftCard);
461
- const giftCardStatusColor = getGiftCardStatusColor(giftCardStatus);
471
+ const hasGiftCardExpired = giftCard.expires_at && new Date(giftCard.expires_at) < /* @__PURE__ */ new Date();
462
472
  return /* @__PURE__ */ jsx(
463
473
  SidebarLink,
464
474
  {
@@ -470,7 +480,14 @@ const OrderGiftCardsWidget = () => {
470
480
  ),
471
481
  to: `/gift-cards/${giftCard.id}`,
472
482
  children: /* @__PURE__ */ jsxs(Fragment, { children: [
473
- /* @__PURE__ */ jsx(StatusBadge, { color: giftCardStatusColor, className: "capitalize", children: giftCardStatus }),
483
+ /* @__PURE__ */ jsx(
484
+ StatusBadge,
485
+ {
486
+ color: hasGiftCardExpired ? "orange" : "green",
487
+ className: "capitalize",
488
+ children: hasGiftCardExpired ? "Expired" : "Active"
489
+ }
490
+ ),
474
491
  /* @__PURE__ */ jsx(TriangleRightMini, { className: "text-ui-fg-muted" })
475
492
  ] })
476
493
  },
@@ -8269,7 +8286,8 @@ var n = function(e2, o2) {
8269
8286
  };
8270
8287
  var util;
8271
8288
  (function(util2) {
8272
- util2.assertEqual = (val) => val;
8289
+ util2.assertEqual = (_) => {
8290
+ };
8273
8291
  function assertIs(_arg) {
8274
8292
  }
8275
8293
  util2.assertIs = assertIs;
@@ -8313,7 +8331,7 @@ var util;
8313
8331
  }
8314
8332
  return void 0;
8315
8333
  };
8316
- util2.isInteger = typeof Number.isInteger === "function" ? (val) => Number.isInteger(val) : (val) => typeof val === "number" && isFinite(val) && Math.floor(val) === val;
8334
+ util2.isInteger = typeof Number.isInteger === "function" ? (val) => Number.isInteger(val) : (val) => typeof val === "number" && Number.isFinite(val) && Math.floor(val) === val;
8317
8335
  function joinValues(array, separator = " | ") {
8318
8336
  return array.map((val) => typeof val === "string" ? `'${val}'` : val).join(separator);
8319
8337
  }
@@ -8365,7 +8383,7 @@ const getParsedType = (data) => {
8365
8383
  case "string":
8366
8384
  return ZodParsedType.string;
8367
8385
  case "number":
8368
- return isNaN(data) ? ZodParsedType.nan : ZodParsedType.number;
8386
+ return Number.isNaN(data) ? ZodParsedType.nan : ZodParsedType.number;
8369
8387
  case "boolean":
8370
8388
  return ZodParsedType.boolean;
8371
8389
  case "function":
@@ -8416,11 +8434,10 @@ const ZodIssueCode = util.arrayToEnum([
8416
8434
  "not_multiple_of",
8417
8435
  "not_finite"
8418
8436
  ]);
8419
- const quotelessJson = (obj) => {
8420
- const json = JSON.stringify(obj, null, 2);
8421
- return json.replace(/"([^"]+)":/g, "$1:");
8422
- };
8423
8437
  class ZodError extends Error {
8438
+ get errors() {
8439
+ return this.issues;
8440
+ }
8424
8441
  constructor(issues) {
8425
8442
  super();
8426
8443
  this.issues = [];
@@ -8439,9 +8456,6 @@ class ZodError extends Error {
8439
8456
  this.name = "ZodError";
8440
8457
  this.issues = issues;
8441
8458
  }
8442
- get errors() {
8443
- return this.issues;
8444
- }
8445
8459
  format(_mapper) {
8446
8460
  const mapper = _mapper || function(issue) {
8447
8461
  return issue.message;
@@ -8478,6 +8492,11 @@ class ZodError extends Error {
8478
8492
  processError(this);
8479
8493
  return fieldErrors;
8480
8494
  }
8495
+ static assert(value) {
8496
+ if (!(value instanceof ZodError)) {
8497
+ throw new Error(`Not a ZodError: ${value}`);
8498
+ }
8499
+ }
8481
8500
  toString() {
8482
8501
  return this.message;
8483
8502
  }
@@ -8492,8 +8511,9 @@ class ZodError extends Error {
8492
8511
  const formErrors = [];
8493
8512
  for (const sub2 of this.issues) {
8494
8513
  if (sub2.path.length > 0) {
8495
- fieldErrors[sub2.path[0]] = fieldErrors[sub2.path[0]] || [];
8496
- fieldErrors[sub2.path[0]].push(mapper(sub2));
8514
+ const firstEl = sub2.path[0];
8515
+ fieldErrors[firstEl] = fieldErrors[firstEl] || [];
8516
+ fieldErrors[firstEl].push(mapper(sub2));
8497
8517
  } else {
8498
8518
  formErrors.push(mapper(sub2));
8499
8519
  }
@@ -8569,6 +8589,8 @@ const errorMap = (issue, _ctx) => {
8569
8589
  message = `String must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `over`} ${issue.minimum} character(s)`;
8570
8590
  else if (issue.type === "number")
8571
8591
  message = `Number must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${issue.minimum}`;
8592
+ else if (issue.type === "bigint")
8593
+ message = `Number must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${issue.minimum}`;
8572
8594
  else if (issue.type === "date")
8573
8595
  message = `Date must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${new Date(Number(issue.minimum))}`;
8574
8596
  else
@@ -8607,9 +8629,6 @@ const errorMap = (issue, _ctx) => {
8607
8629
  return { message };
8608
8630
  };
8609
8631
  let overrideErrorMap = errorMap;
8610
- function setErrorMap(map) {
8611
- overrideErrorMap = map;
8612
- }
8613
8632
  function getErrorMap() {
8614
8633
  return overrideErrorMap;
8615
8634
  }
@@ -8620,6 +8639,13 @@ const makeIssue = (params) => {
8620
8639
  ...issueData,
8621
8640
  path: fullPath
8622
8641
  };
8642
+ if (issueData.message !== void 0) {
8643
+ return {
8644
+ ...issueData,
8645
+ path: fullPath,
8646
+ message: issueData.message
8647
+ };
8648
+ }
8623
8649
  let errorMessage = "";
8624
8650
  const maps = errorMaps.filter((m) => !!m).slice().reverse();
8625
8651
  for (const map of maps) {
@@ -8628,20 +8654,23 @@ const makeIssue = (params) => {
8628
8654
  return {
8629
8655
  ...issueData,
8630
8656
  path: fullPath,
8631
- message: issueData.message || errorMessage
8657
+ message: errorMessage
8632
8658
  };
8633
8659
  };
8634
- const EMPTY_PATH = [];
8635
8660
  function addIssueToContext(ctx2, issueData) {
8661
+ const overrideMap = getErrorMap();
8636
8662
  const issue = makeIssue({
8637
8663
  issueData,
8638
8664
  data: ctx2.data,
8639
8665
  path: ctx2.path,
8640
8666
  errorMaps: [
8641
8667
  ctx2.common.contextualErrorMap,
8668
+ // contextual error map is first priority
8642
8669
  ctx2.schemaErrorMap,
8643
- getErrorMap(),
8644
- errorMap
8670
+ // then schema-bound map if available
8671
+ overrideMap,
8672
+ // then global override map
8673
+ overrideMap === errorMap ? void 0 : errorMap
8645
8674
  // then global default map
8646
8675
  ].filter((x) => !!x)
8647
8676
  });
@@ -8673,9 +8702,11 @@ class ParseStatus {
8673
8702
  static async mergeObjectAsync(status, pairs) {
8674
8703
  const syncPairs = [];
8675
8704
  for (const pair of pairs) {
8705
+ const key2 = await pair.key;
8706
+ const value = await pair.value;
8676
8707
  syncPairs.push({
8677
- key: await pair.key,
8678
- value: await pair.value
8708
+ key: key2,
8709
+ value
8679
8710
  });
8680
8711
  }
8681
8712
  return ParseStatus.mergeObjectSync(status, syncPairs);
@@ -8711,7 +8742,7 @@ const isAsync = (x) => typeof Promise !== "undefined" && x instanceof Promise;
8711
8742
  var errorUtil;
8712
8743
  (function(errorUtil2) {
8713
8744
  errorUtil2.errToObj = (message) => typeof message === "string" ? { message } : message || {};
8714
- errorUtil2.toString = (message) => typeof message === "string" ? message : message === null || message === void 0 ? void 0 : message.message;
8745
+ errorUtil2.toString = (message) => typeof message === "string" ? message : message == null ? void 0 : message.message;
8715
8746
  })(errorUtil || (errorUtil = {}));
8716
8747
  class ParseInputLazyPath {
8717
8748
  constructor(parent, value, path, key2) {
@@ -8723,7 +8754,7 @@ class ParseInputLazyPath {
8723
8754
  }
8724
8755
  get path() {
8725
8756
  if (!this._cachedPath.length) {
8726
- if (this._key instanceof Array) {
8757
+ if (Array.isArray(this._key)) {
8727
8758
  this._cachedPath.push(...this._path, ...this._key);
8728
8759
  } else {
8729
8760
  this._cachedPath.push(...this._path, this._key);
@@ -8761,44 +8792,20 @@ function processCreateParams(params) {
8761
8792
  if (errorMap2)
8762
8793
  return { errorMap: errorMap2, description };
8763
8794
  const customMap = (iss, ctx2) => {
8764
- if (iss.code !== "invalid_type")
8765
- return { message: ctx2.defaultError };
8795
+ const { message } = params;
8796
+ if (iss.code === "invalid_enum_value") {
8797
+ return { message: message ?? ctx2.defaultError };
8798
+ }
8766
8799
  if (typeof ctx2.data === "undefined") {
8767
- return { message: required_error !== null && required_error !== void 0 ? required_error : ctx2.defaultError };
8800
+ return { message: message ?? required_error ?? ctx2.defaultError };
8768
8801
  }
8769
- return { message: invalid_type_error !== null && invalid_type_error !== void 0 ? invalid_type_error : ctx2.defaultError };
8802
+ if (iss.code !== "invalid_type")
8803
+ return { message: ctx2.defaultError };
8804
+ return { message: message ?? invalid_type_error ?? ctx2.defaultError };
8770
8805
  };
8771
8806
  return { errorMap: customMap, description };
8772
8807
  }
8773
8808
  class ZodType {
8774
- constructor(def) {
8775
- this.spa = this.safeParseAsync;
8776
- this._def = def;
8777
- this.parse = this.parse.bind(this);
8778
- this.safeParse = this.safeParse.bind(this);
8779
- this.parseAsync = this.parseAsync.bind(this);
8780
- this.safeParseAsync = this.safeParseAsync.bind(this);
8781
- this.spa = this.spa.bind(this);
8782
- this.refine = this.refine.bind(this);
8783
- this.refinement = this.refinement.bind(this);
8784
- this.superRefine = this.superRefine.bind(this);
8785
- this.optional = this.optional.bind(this);
8786
- this.nullable = this.nullable.bind(this);
8787
- this.nullish = this.nullish.bind(this);
8788
- this.array = this.array.bind(this);
8789
- this.promise = this.promise.bind(this);
8790
- this.or = this.or.bind(this);
8791
- this.and = this.and.bind(this);
8792
- this.transform = this.transform.bind(this);
8793
- this.brand = this.brand.bind(this);
8794
- this.default = this.default.bind(this);
8795
- this.catch = this.catch.bind(this);
8796
- this.describe = this.describe.bind(this);
8797
- this.pipe = this.pipe.bind(this);
8798
- this.readonly = this.readonly.bind(this);
8799
- this.isNullable = this.isNullable.bind(this);
8800
- this.isOptional = this.isOptional.bind(this);
8801
- }
8802
8809
  get description() {
8803
8810
  return this._def.description;
8804
8811
  }
@@ -8846,14 +8853,13 @@ class ZodType {
8846
8853
  throw result.error;
8847
8854
  }
8848
8855
  safeParse(data, params) {
8849
- var _a;
8850
8856
  const ctx2 = {
8851
8857
  common: {
8852
8858
  issues: [],
8853
- async: (_a = params === null || params === void 0 ? void 0 : params.async) !== null && _a !== void 0 ? _a : false,
8854
- contextualErrorMap: params === null || params === void 0 ? void 0 : params.errorMap
8859
+ async: (params == null ? void 0 : params.async) ?? false,
8860
+ contextualErrorMap: params == null ? void 0 : params.errorMap
8855
8861
  },
8856
- path: (params === null || params === void 0 ? void 0 : params.path) || [],
8862
+ path: (params == null ? void 0 : params.path) || [],
8857
8863
  schemaErrorMap: this._def.errorMap,
8858
8864
  parent: null,
8859
8865
  data,
@@ -8862,6 +8868,43 @@ class ZodType {
8862
8868
  const result = this._parseSync({ data, path: ctx2.path, parent: ctx2 });
8863
8869
  return handleResult(ctx2, result);
8864
8870
  }
8871
+ "~validate"(data) {
8872
+ var _a, _b;
8873
+ const ctx2 = {
8874
+ common: {
8875
+ issues: [],
8876
+ async: !!this["~standard"].async
8877
+ },
8878
+ path: [],
8879
+ schemaErrorMap: this._def.errorMap,
8880
+ parent: null,
8881
+ data,
8882
+ parsedType: getParsedType(data)
8883
+ };
8884
+ if (!this["~standard"].async) {
8885
+ try {
8886
+ const result = this._parseSync({ data, path: [], parent: ctx2 });
8887
+ return isValid(result) ? {
8888
+ value: result.value
8889
+ } : {
8890
+ issues: ctx2.common.issues
8891
+ };
8892
+ } catch (err) {
8893
+ if ((_b = (_a = err == null ? void 0 : err.message) == null ? void 0 : _a.toLowerCase()) == null ? void 0 : _b.includes("encountered")) {
8894
+ this["~standard"].async = true;
8895
+ }
8896
+ ctx2.common = {
8897
+ issues: [],
8898
+ async: true
8899
+ };
8900
+ }
8901
+ }
8902
+ return this._parseAsync({ data, path: [], parent: ctx2 }).then((result) => isValid(result) ? {
8903
+ value: result.value
8904
+ } : {
8905
+ issues: ctx2.common.issues
8906
+ });
8907
+ }
8865
8908
  async parseAsync(data, params) {
8866
8909
  const result = await this.safeParseAsync(data, params);
8867
8910
  if (result.success)
@@ -8872,10 +8915,10 @@ class ZodType {
8872
8915
  const ctx2 = {
8873
8916
  common: {
8874
8917
  issues: [],
8875
- contextualErrorMap: params === null || params === void 0 ? void 0 : params.errorMap,
8918
+ contextualErrorMap: params == null ? void 0 : params.errorMap,
8876
8919
  async: true
8877
8920
  },
8878
- path: (params === null || params === void 0 ? void 0 : params.path) || [],
8921
+ path: (params == null ? void 0 : params.path) || [],
8879
8922
  schemaErrorMap: this._def.errorMap,
8880
8923
  parent: null,
8881
8924
  data,
@@ -8939,6 +8982,39 @@ class ZodType {
8939
8982
  superRefine(refinement) {
8940
8983
  return this._refinement(refinement);
8941
8984
  }
8985
+ constructor(def) {
8986
+ this.spa = this.safeParseAsync;
8987
+ this._def = def;
8988
+ this.parse = this.parse.bind(this);
8989
+ this.safeParse = this.safeParse.bind(this);
8990
+ this.parseAsync = this.parseAsync.bind(this);
8991
+ this.safeParseAsync = this.safeParseAsync.bind(this);
8992
+ this.spa = this.spa.bind(this);
8993
+ this.refine = this.refine.bind(this);
8994
+ this.refinement = this.refinement.bind(this);
8995
+ this.superRefine = this.superRefine.bind(this);
8996
+ this.optional = this.optional.bind(this);
8997
+ this.nullable = this.nullable.bind(this);
8998
+ this.nullish = this.nullish.bind(this);
8999
+ this.array = this.array.bind(this);
9000
+ this.promise = this.promise.bind(this);
9001
+ this.or = this.or.bind(this);
9002
+ this.and = this.and.bind(this);
9003
+ this.transform = this.transform.bind(this);
9004
+ this.brand = this.brand.bind(this);
9005
+ this.default = this.default.bind(this);
9006
+ this.catch = this.catch.bind(this);
9007
+ this.describe = this.describe.bind(this);
9008
+ this.pipe = this.pipe.bind(this);
9009
+ this.readonly = this.readonly.bind(this);
9010
+ this.isNullable = this.isNullable.bind(this);
9011
+ this.isOptional = this.isOptional.bind(this);
9012
+ this["~standard"] = {
9013
+ version: 1,
9014
+ vendor: "zod",
9015
+ validate: (data) => this["~validate"](data)
9016
+ };
9017
+ }
8942
9018
  optional() {
8943
9019
  return ZodOptional.create(this, this._def);
8944
9020
  }
@@ -8949,7 +9025,7 @@ class ZodType {
8949
9025
  return this.nullable().optional();
8950
9026
  }
8951
9027
  array() {
8952
- return ZodArray.create(this, this._def);
9028
+ return ZodArray.create(this);
8953
9029
  }
8954
9030
  promise() {
8955
9031
  return ZodPromise.create(this, this._def);
@@ -9014,35 +9090,45 @@ class ZodType {
9014
9090
  }
9015
9091
  }
9016
9092
  const cuidRegex = /^c[^\s-]{8,}$/i;
9017
- const cuid2Regex = /^[a-z][a-z0-9]*$/;
9018
- const ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/;
9093
+ const cuid2Regex = /^[0-9a-z]+$/;
9094
+ const ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/i;
9019
9095
  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;
9020
- const emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_+-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
9096
+ const nanoidRegex = /^[a-z0-9_-]{21}$/i;
9097
+ const jwtRegex = /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/;
9098
+ 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)?)??$/;
9099
+ const emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
9021
9100
  const _emojiRegex = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
9022
9101
  let emojiRegex;
9023
- 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}))$/;
9024
- 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})))$/;
9025
- const datetimeRegex = (args) => {
9102
+ 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])$/;
9103
+ 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])$/;
9104
+ 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]))$/;
9105
+ 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])$/;
9106
+ const base64Regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;
9107
+ const base64urlRegex = /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/;
9108
+ 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])))`;
9109
+ const dateRegex = new RegExp(`^${dateRegexSource}$`);
9110
+ function timeRegexSource(args) {
9111
+ let secondsRegexSource = `[0-5]\\d`;
9026
9112
  if (args.precision) {
9027
- if (args.offset) {
9028
- return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{${args.precision}}(([+-]\\d{2}(:?\\d{2})?)|Z)$`);
9029
- } else {
9030
- return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{${args.precision}}Z$`);
9031
- }
9032
- } else if (args.precision === 0) {
9033
- if (args.offset) {
9034
- return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(([+-]\\d{2}(:?\\d{2})?)|Z)$`);
9035
- } else {
9036
- return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$`);
9037
- }
9038
- } else {
9039
- if (args.offset) {
9040
- return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?(([+-]\\d{2}(:?\\d{2})?)|Z)$`);
9041
- } else {
9042
- return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?Z$`);
9043
- }
9113
+ secondsRegexSource = `${secondsRegexSource}\\.\\d{${args.precision}}`;
9114
+ } else if (args.precision == null) {
9115
+ secondsRegexSource = `${secondsRegexSource}(\\.\\d+)?`;
9044
9116
  }
9045
- };
9117
+ const secondsQuantifier = args.precision ? "+" : "?";
9118
+ return `([01]\\d|2[0-3]):[0-5]\\d(:${secondsRegexSource})${secondsQuantifier}`;
9119
+ }
9120
+ function timeRegex(args) {
9121
+ return new RegExp(`^${timeRegexSource(args)}$`);
9122
+ }
9123
+ function datetimeRegex(args) {
9124
+ let regex = `${dateRegexSource}T${timeRegexSource(args)}`;
9125
+ const opts = [];
9126
+ opts.push(args.local ? `Z?` : `Z`);
9127
+ if (args.offset)
9128
+ opts.push(`([+-]\\d{2}:?\\d{2})`);
9129
+ regex = `${regex}(${opts.join("|")})`;
9130
+ return new RegExp(`^${regex}$`);
9131
+ }
9046
9132
  function isValidIP(ip, version) {
9047
9133
  if ((version === "v4" || !version) && ipv4Regex.test(ip)) {
9048
9134
  return true;
@@ -9052,6 +9138,37 @@ function isValidIP(ip, version) {
9052
9138
  }
9053
9139
  return false;
9054
9140
  }
9141
+ function isValidJWT(jwt, alg) {
9142
+ if (!jwtRegex.test(jwt))
9143
+ return false;
9144
+ try {
9145
+ const [header] = jwt.split(".");
9146
+ if (!header)
9147
+ return false;
9148
+ const base64 = header.replace(/-/g, "+").replace(/_/g, "/").padEnd(header.length + (4 - header.length % 4) % 4, "=");
9149
+ const decoded = JSON.parse(atob(base64));
9150
+ if (typeof decoded !== "object" || decoded === null)
9151
+ return false;
9152
+ if ("typ" in decoded && (decoded == null ? void 0 : decoded.typ) !== "JWT")
9153
+ return false;
9154
+ if (!decoded.alg)
9155
+ return false;
9156
+ if (alg && decoded.alg !== alg)
9157
+ return false;
9158
+ return true;
9159
+ } catch {
9160
+ return false;
9161
+ }
9162
+ }
9163
+ function isValidCidr(ip, version) {
9164
+ if ((version === "v4" || !version) && ipv4CidrRegex.test(ip)) {
9165
+ return true;
9166
+ }
9167
+ if ((version === "v6" || !version) && ipv6CidrRegex.test(ip)) {
9168
+ return true;
9169
+ }
9170
+ return false;
9171
+ }
9055
9172
  class ZodString extends ZodType {
9056
9173
  _parse(input) {
9057
9174
  if (this._def.coerce) {
@@ -9060,15 +9177,11 @@ class ZodString extends ZodType {
9060
9177
  const parsedType = this._getType(input);
9061
9178
  if (parsedType !== ZodParsedType.string) {
9062
9179
  const ctx3 = this._getOrReturnCtx(input);
9063
- addIssueToContext(
9064
- ctx3,
9065
- {
9066
- code: ZodIssueCode.invalid_type,
9067
- expected: ZodParsedType.string,
9068
- received: ctx3.parsedType
9069
- }
9070
- //
9071
- );
9180
+ addIssueToContext(ctx3, {
9181
+ code: ZodIssueCode.invalid_type,
9182
+ expected: ZodParsedType.string,
9183
+ received: ctx3.parsedType
9184
+ });
9072
9185
  return INVALID;
9073
9186
  }
9074
9187
  const status = new ParseStatus();
@@ -9159,6 +9272,16 @@ class ZodString extends ZodType {
9159
9272
  });
9160
9273
  status.dirty();
9161
9274
  }
9275
+ } else if (check.kind === "nanoid") {
9276
+ if (!nanoidRegex.test(input.data)) {
9277
+ ctx2 = this._getOrReturnCtx(input, ctx2);
9278
+ addIssueToContext(ctx2, {
9279
+ validation: "nanoid",
9280
+ code: ZodIssueCode.invalid_string,
9281
+ message: check.message
9282
+ });
9283
+ status.dirty();
9284
+ }
9162
9285
  } else if (check.kind === "cuid") {
9163
9286
  if (!cuidRegex.test(input.data)) {
9164
9287
  ctx2 = this._getOrReturnCtx(input, ctx2);
@@ -9192,7 +9315,7 @@ class ZodString extends ZodType {
9192
9315
  } else if (check.kind === "url") {
9193
9316
  try {
9194
9317
  new URL(input.data);
9195
- } catch (_a) {
9318
+ } catch {
9196
9319
  ctx2 = this._getOrReturnCtx(input, ctx2);
9197
9320
  addIssueToContext(ctx2, {
9198
9321
  validation: "url",
@@ -9260,6 +9383,38 @@ class ZodString extends ZodType {
9260
9383
  });
9261
9384
  status.dirty();
9262
9385
  }
9386
+ } else if (check.kind === "date") {
9387
+ const regex = dateRegex;
9388
+ if (!regex.test(input.data)) {
9389
+ ctx2 = this._getOrReturnCtx(input, ctx2);
9390
+ addIssueToContext(ctx2, {
9391
+ code: ZodIssueCode.invalid_string,
9392
+ validation: "date",
9393
+ message: check.message
9394
+ });
9395
+ status.dirty();
9396
+ }
9397
+ } else if (check.kind === "time") {
9398
+ const regex = timeRegex(check);
9399
+ if (!regex.test(input.data)) {
9400
+ ctx2 = this._getOrReturnCtx(input, ctx2);
9401
+ addIssueToContext(ctx2, {
9402
+ code: ZodIssueCode.invalid_string,
9403
+ validation: "time",
9404
+ message: check.message
9405
+ });
9406
+ status.dirty();
9407
+ }
9408
+ } else if (check.kind === "duration") {
9409
+ if (!durationRegex.test(input.data)) {
9410
+ ctx2 = this._getOrReturnCtx(input, ctx2);
9411
+ addIssueToContext(ctx2, {
9412
+ validation: "duration",
9413
+ code: ZodIssueCode.invalid_string,
9414
+ message: check.message
9415
+ });
9416
+ status.dirty();
9417
+ }
9263
9418
  } else if (check.kind === "ip") {
9264
9419
  if (!isValidIP(input.data, check.version)) {
9265
9420
  ctx2 = this._getOrReturnCtx(input, ctx2);
@@ -9270,6 +9425,46 @@ class ZodString extends ZodType {
9270
9425
  });
9271
9426
  status.dirty();
9272
9427
  }
9428
+ } else if (check.kind === "jwt") {
9429
+ if (!isValidJWT(input.data, check.alg)) {
9430
+ ctx2 = this._getOrReturnCtx(input, ctx2);
9431
+ addIssueToContext(ctx2, {
9432
+ validation: "jwt",
9433
+ code: ZodIssueCode.invalid_string,
9434
+ message: check.message
9435
+ });
9436
+ status.dirty();
9437
+ }
9438
+ } else if (check.kind === "cidr") {
9439
+ if (!isValidCidr(input.data, check.version)) {
9440
+ ctx2 = this._getOrReturnCtx(input, ctx2);
9441
+ addIssueToContext(ctx2, {
9442
+ validation: "cidr",
9443
+ code: ZodIssueCode.invalid_string,
9444
+ message: check.message
9445
+ });
9446
+ status.dirty();
9447
+ }
9448
+ } else if (check.kind === "base64") {
9449
+ if (!base64Regex.test(input.data)) {
9450
+ ctx2 = this._getOrReturnCtx(input, ctx2);
9451
+ addIssueToContext(ctx2, {
9452
+ validation: "base64",
9453
+ code: ZodIssueCode.invalid_string,
9454
+ message: check.message
9455
+ });
9456
+ status.dirty();
9457
+ }
9458
+ } else if (check.kind === "base64url") {
9459
+ if (!base64urlRegex.test(input.data)) {
9460
+ ctx2 = this._getOrReturnCtx(input, ctx2);
9461
+ addIssueToContext(ctx2, {
9462
+ validation: "base64url",
9463
+ code: ZodIssueCode.invalid_string,
9464
+ message: check.message
9465
+ });
9466
+ status.dirty();
9467
+ }
9273
9468
  } else {
9274
9469
  util.assertNever(check);
9275
9470
  }
@@ -9301,6 +9496,9 @@ class ZodString extends ZodType {
9301
9496
  uuid(message) {
9302
9497
  return this._addCheck({ kind: "uuid", ...errorUtil.errToObj(message) });
9303
9498
  }
9499
+ nanoid(message) {
9500
+ return this._addCheck({ kind: "nanoid", ...errorUtil.errToObj(message) });
9501
+ }
9304
9502
  cuid(message) {
9305
9503
  return this._addCheck({ kind: "cuid", ...errorUtil.errToObj(message) });
9306
9504
  }
@@ -9310,26 +9508,62 @@ class ZodString extends ZodType {
9310
9508
  ulid(message) {
9311
9509
  return this._addCheck({ kind: "ulid", ...errorUtil.errToObj(message) });
9312
9510
  }
9511
+ base64(message) {
9512
+ return this._addCheck({ kind: "base64", ...errorUtil.errToObj(message) });
9513
+ }
9514
+ base64url(message) {
9515
+ return this._addCheck({
9516
+ kind: "base64url",
9517
+ ...errorUtil.errToObj(message)
9518
+ });
9519
+ }
9520
+ jwt(options) {
9521
+ return this._addCheck({ kind: "jwt", ...errorUtil.errToObj(options) });
9522
+ }
9313
9523
  ip(options) {
9314
9524
  return this._addCheck({ kind: "ip", ...errorUtil.errToObj(options) });
9315
9525
  }
9526
+ cidr(options) {
9527
+ return this._addCheck({ kind: "cidr", ...errorUtil.errToObj(options) });
9528
+ }
9316
9529
  datetime(options) {
9317
- var _a;
9318
9530
  if (typeof options === "string") {
9319
9531
  return this._addCheck({
9320
9532
  kind: "datetime",
9321
9533
  precision: null,
9322
9534
  offset: false,
9535
+ local: false,
9323
9536
  message: options
9324
9537
  });
9325
9538
  }
9326
9539
  return this._addCheck({
9327
9540
  kind: "datetime",
9328
- precision: typeof (options === null || options === void 0 ? void 0 : options.precision) === "undefined" ? null : options === null || options === void 0 ? void 0 : options.precision,
9329
- offset: (_a = options === null || options === void 0 ? void 0 : options.offset) !== null && _a !== void 0 ? _a : false,
9330
- ...errorUtil.errToObj(options === null || options === void 0 ? void 0 : options.message)
9541
+ precision: typeof (options == null ? void 0 : options.precision) === "undefined" ? null : options == null ? void 0 : options.precision,
9542
+ offset: (options == null ? void 0 : options.offset) ?? false,
9543
+ local: (options == null ? void 0 : options.local) ?? false,
9544
+ ...errorUtil.errToObj(options == null ? void 0 : options.message)
9545
+ });
9546
+ }
9547
+ date(message) {
9548
+ return this._addCheck({ kind: "date", message });
9549
+ }
9550
+ time(options) {
9551
+ if (typeof options === "string") {
9552
+ return this._addCheck({
9553
+ kind: "time",
9554
+ precision: null,
9555
+ message: options
9556
+ });
9557
+ }
9558
+ return this._addCheck({
9559
+ kind: "time",
9560
+ precision: typeof (options == null ? void 0 : options.precision) === "undefined" ? null : options == null ? void 0 : options.precision,
9561
+ ...errorUtil.errToObj(options == null ? void 0 : options.message)
9331
9562
  });
9332
9563
  }
9564
+ duration(message) {
9565
+ return this._addCheck({ kind: "duration", ...errorUtil.errToObj(message) });
9566
+ }
9333
9567
  regex(regex, message) {
9334
9568
  return this._addCheck({
9335
9569
  kind: "regex",
@@ -9341,8 +9575,8 @@ class ZodString extends ZodType {
9341
9575
  return this._addCheck({
9342
9576
  kind: "includes",
9343
9577
  value,
9344
- position: options === null || options === void 0 ? void 0 : options.position,
9345
- ...errorUtil.errToObj(options === null || options === void 0 ? void 0 : options.message)
9578
+ position: options == null ? void 0 : options.position,
9579
+ ...errorUtil.errToObj(options == null ? void 0 : options.message)
9346
9580
  });
9347
9581
  }
9348
9582
  startsWith(value, message) {
@@ -9381,8 +9615,7 @@ class ZodString extends ZodType {
9381
9615
  });
9382
9616
  }
9383
9617
  /**
9384
- * @deprecated Use z.string().min(1) instead.
9385
- * @see {@link ZodString.min}
9618
+ * Equivalent to `.min(1)`
9386
9619
  */
9387
9620
  nonempty(message) {
9388
9621
  return this.min(1, errorUtil.errToObj(message));
@@ -9408,6 +9641,15 @@ class ZodString extends ZodType {
9408
9641
  get isDatetime() {
9409
9642
  return !!this._def.checks.find((ch) => ch.kind === "datetime");
9410
9643
  }
9644
+ get isDate() {
9645
+ return !!this._def.checks.find((ch) => ch.kind === "date");
9646
+ }
9647
+ get isTime() {
9648
+ return !!this._def.checks.find((ch) => ch.kind === "time");
9649
+ }
9650
+ get isDuration() {
9651
+ return !!this._def.checks.find((ch) => ch.kind === "duration");
9652
+ }
9411
9653
  get isEmail() {
9412
9654
  return !!this._def.checks.find((ch) => ch.kind === "email");
9413
9655
  }
@@ -9420,6 +9662,9 @@ class ZodString extends ZodType {
9420
9662
  get isUUID() {
9421
9663
  return !!this._def.checks.find((ch) => ch.kind === "uuid");
9422
9664
  }
9665
+ get isNANOID() {
9666
+ return !!this._def.checks.find((ch) => ch.kind === "nanoid");
9667
+ }
9423
9668
  get isCUID() {
9424
9669
  return !!this._def.checks.find((ch) => ch.kind === "cuid");
9425
9670
  }
@@ -9432,6 +9677,15 @@ class ZodString extends ZodType {
9432
9677
  get isIP() {
9433
9678
  return !!this._def.checks.find((ch) => ch.kind === "ip");
9434
9679
  }
9680
+ get isCIDR() {
9681
+ return !!this._def.checks.find((ch) => ch.kind === "cidr");
9682
+ }
9683
+ get isBase64() {
9684
+ return !!this._def.checks.find((ch) => ch.kind === "base64");
9685
+ }
9686
+ get isBase64url() {
9687
+ return !!this._def.checks.find((ch) => ch.kind === "base64url");
9688
+ }
9435
9689
  get minLength() {
9436
9690
  let min2 = null;
9437
9691
  for (const ch of this._def.checks) {
@@ -9454,11 +9708,10 @@ class ZodString extends ZodType {
9454
9708
  }
9455
9709
  }
9456
9710
  ZodString.create = (params) => {
9457
- var _a;
9458
9711
  return new ZodString({
9459
9712
  checks: [],
9460
9713
  typeName: ZodFirstPartyTypeKind.ZodString,
9461
- coerce: (_a = params === null || params === void 0 ? void 0 : params.coerce) !== null && _a !== void 0 ? _a : false,
9714
+ coerce: (params == null ? void 0 : params.coerce) ?? false,
9462
9715
  ...processCreateParams(params)
9463
9716
  });
9464
9717
  };
@@ -9466,9 +9719,9 @@ function floatSafeRemainder(val, step) {
9466
9719
  const valDecCount = (val.toString().split(".")[1] || "").length;
9467
9720
  const stepDecCount = (step.toString().split(".")[1] || "").length;
9468
9721
  const decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount;
9469
- const valInt = parseInt(val.toFixed(decCount).replace(".", ""));
9470
- const stepInt = parseInt(step.toFixed(decCount).replace(".", ""));
9471
- return valInt % stepInt / Math.pow(10, decCount);
9722
+ const valInt = Number.parseInt(val.toFixed(decCount).replace(".", ""));
9723
+ const stepInt = Number.parseInt(step.toFixed(decCount).replace(".", ""));
9724
+ return valInt % stepInt / 10 ** decCount;
9472
9725
  }
9473
9726
  class ZodNumber extends ZodType {
9474
9727
  constructor() {
@@ -9678,7 +9931,8 @@ class ZodNumber extends ZodType {
9678
9931
  return !!this._def.checks.find((ch) => ch.kind === "int" || ch.kind === "multipleOf" && util.isInteger(ch.value));
9679
9932
  }
9680
9933
  get isFinite() {
9681
- let max2 = null, min2 = null;
9934
+ let max2 = null;
9935
+ let min2 = null;
9682
9936
  for (const ch of this._def.checks) {
9683
9937
  if (ch.kind === "finite" || ch.kind === "int" || ch.kind === "multipleOf") {
9684
9938
  return true;
@@ -9697,7 +9951,7 @@ ZodNumber.create = (params) => {
9697
9951
  return new ZodNumber({
9698
9952
  checks: [],
9699
9953
  typeName: ZodFirstPartyTypeKind.ZodNumber,
9700
- coerce: (params === null || params === void 0 ? void 0 : params.coerce) || false,
9954
+ coerce: (params == null ? void 0 : params.coerce) || false,
9701
9955
  ...processCreateParams(params)
9702
9956
  });
9703
9957
  };
@@ -9709,17 +9963,15 @@ class ZodBigInt extends ZodType {
9709
9963
  }
9710
9964
  _parse(input) {
9711
9965
  if (this._def.coerce) {
9712
- input.data = BigInt(input.data);
9966
+ try {
9967
+ input.data = BigInt(input.data);
9968
+ } catch {
9969
+ return this._getInvalidInput(input);
9970
+ }
9713
9971
  }
9714
9972
  const parsedType = this._getType(input);
9715
9973
  if (parsedType !== ZodParsedType.bigint) {
9716
- const ctx3 = this._getOrReturnCtx(input);
9717
- addIssueToContext(ctx3, {
9718
- code: ZodIssueCode.invalid_type,
9719
- expected: ZodParsedType.bigint,
9720
- received: ctx3.parsedType
9721
- });
9722
- return INVALID;
9974
+ return this._getInvalidInput(input);
9723
9975
  }
9724
9976
  let ctx2 = void 0;
9725
9977
  const status = new ParseStatus();
@@ -9766,6 +10018,15 @@ class ZodBigInt extends ZodType {
9766
10018
  }
9767
10019
  return { status: status.value, value: input.data };
9768
10020
  }
10021
+ _getInvalidInput(input) {
10022
+ const ctx2 = this._getOrReturnCtx(input);
10023
+ addIssueToContext(ctx2, {
10024
+ code: ZodIssueCode.invalid_type,
10025
+ expected: ZodParsedType.bigint,
10026
+ received: ctx2.parsedType
10027
+ });
10028
+ return INVALID;
10029
+ }
9769
10030
  gte(value, message) {
9770
10031
  return this.setLimit("min", value, true, errorUtil.toString(message));
9771
10032
  }
@@ -9859,11 +10120,10 @@ class ZodBigInt extends ZodType {
9859
10120
  }
9860
10121
  }
9861
10122
  ZodBigInt.create = (params) => {
9862
- var _a;
9863
10123
  return new ZodBigInt({
9864
10124
  checks: [],
9865
10125
  typeName: ZodFirstPartyTypeKind.ZodBigInt,
9866
- coerce: (_a = params === null || params === void 0 ? void 0 : params.coerce) !== null && _a !== void 0 ? _a : false,
10126
+ coerce: (params == null ? void 0 : params.coerce) ?? false,
9867
10127
  ...processCreateParams(params)
9868
10128
  });
9869
10129
  };
@@ -9888,7 +10148,7 @@ class ZodBoolean extends ZodType {
9888
10148
  ZodBoolean.create = (params) => {
9889
10149
  return new ZodBoolean({
9890
10150
  typeName: ZodFirstPartyTypeKind.ZodBoolean,
9891
- coerce: (params === null || params === void 0 ? void 0 : params.coerce) || false,
10151
+ coerce: (params == null ? void 0 : params.coerce) || false,
9892
10152
  ...processCreateParams(params)
9893
10153
  });
9894
10154
  };
@@ -9907,7 +10167,7 @@ class ZodDate extends ZodType {
9907
10167
  });
9908
10168
  return INVALID;
9909
10169
  }
9910
- if (isNaN(input.data.getTime())) {
10170
+ if (Number.isNaN(input.data.getTime())) {
9911
10171
  const ctx3 = this._getOrReturnCtx(input);
9912
10172
  addIssueToContext(ctx3, {
9913
10173
  code: ZodIssueCode.invalid_date
@@ -9996,7 +10256,7 @@ class ZodDate extends ZodType {
9996
10256
  ZodDate.create = (params) => {
9997
10257
  return new ZodDate({
9998
10258
  checks: [],
9999
- coerce: (params === null || params === void 0 ? void 0 : params.coerce) || false,
10259
+ coerce: (params == null ? void 0 : params.coerce) || false,
10000
10260
  typeName: ZodFirstPartyTypeKind.ZodDate,
10001
10261
  ...processCreateParams(params)
10002
10262
  });
@@ -10271,7 +10531,8 @@ class ZodObject extends ZodType {
10271
10531
  return this._cached;
10272
10532
  const shape = this._def.shape();
10273
10533
  const keys = util.objectKeys(shape);
10274
- return this._cached = { shape, keys };
10534
+ this._cached = { shape, keys };
10535
+ return this._cached;
10275
10536
  }
10276
10537
  _parse(input) {
10277
10538
  const parsedType = this._getType(input);
@@ -10344,9 +10605,10 @@ class ZodObject extends ZodType {
10344
10605
  const syncPairs = [];
10345
10606
  for (const pair of pairs) {
10346
10607
  const key2 = await pair.key;
10608
+ const value = await pair.value;
10347
10609
  syncPairs.push({
10348
10610
  key: key2,
10349
- value: await pair.value,
10611
+ value,
10350
10612
  alwaysSet: pair.alwaysSet
10351
10613
  });
10352
10614
  }
@@ -10368,11 +10630,11 @@ class ZodObject extends ZodType {
10368
10630
  unknownKeys: "strict",
10369
10631
  ...message !== void 0 ? {
10370
10632
  errorMap: (issue, ctx2) => {
10371
- var _a, _b, _c, _d;
10372
- 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;
10633
+ var _a, _b;
10634
+ const defaultError = ((_b = (_a = this._def).errorMap) == null ? void 0 : _b.call(_a, issue, ctx2).message) ?? ctx2.defaultError;
10373
10635
  if (issue.code === "unrecognized_keys")
10374
10636
  return {
10375
- message: (_d = errorUtil.errToObj(message).message) !== null && _d !== void 0 ? _d : defaultError
10637
+ message: errorUtil.errToObj(message).message ?? defaultError
10376
10638
  };
10377
10639
  return {
10378
10640
  message: defaultError
@@ -10503,11 +10765,11 @@ class ZodObject extends ZodType {
10503
10765
  }
10504
10766
  pick(mask) {
10505
10767
  const shape = {};
10506
- util.objectKeys(mask).forEach((key2) => {
10768
+ for (const key2 of util.objectKeys(mask)) {
10507
10769
  if (mask[key2] && this.shape[key2]) {
10508
10770
  shape[key2] = this.shape[key2];
10509
10771
  }
10510
- });
10772
+ }
10511
10773
  return new ZodObject({
10512
10774
  ...this._def,
10513
10775
  shape: () => shape
@@ -10515,11 +10777,11 @@ class ZodObject extends ZodType {
10515
10777
  }
10516
10778
  omit(mask) {
10517
10779
  const shape = {};
10518
- util.objectKeys(this.shape).forEach((key2) => {
10780
+ for (const key2 of util.objectKeys(this.shape)) {
10519
10781
  if (!mask[key2]) {
10520
10782
  shape[key2] = this.shape[key2];
10521
10783
  }
10522
- });
10784
+ }
10523
10785
  return new ZodObject({
10524
10786
  ...this._def,
10525
10787
  shape: () => shape
@@ -10533,14 +10795,14 @@ class ZodObject extends ZodType {
10533
10795
  }
10534
10796
  partial(mask) {
10535
10797
  const newShape = {};
10536
- util.objectKeys(this.shape).forEach((key2) => {
10798
+ for (const key2 of util.objectKeys(this.shape)) {
10537
10799
  const fieldSchema = this.shape[key2];
10538
10800
  if (mask && !mask[key2]) {
10539
10801
  newShape[key2] = fieldSchema;
10540
10802
  } else {
10541
10803
  newShape[key2] = fieldSchema.optional();
10542
10804
  }
10543
- });
10805
+ }
10544
10806
  return new ZodObject({
10545
10807
  ...this._def,
10546
10808
  shape: () => newShape
@@ -10548,7 +10810,7 @@ class ZodObject extends ZodType {
10548
10810
  }
10549
10811
  required(mask) {
10550
10812
  const newShape = {};
10551
- util.objectKeys(this.shape).forEach((key2) => {
10813
+ for (const key2 of util.objectKeys(this.shape)) {
10552
10814
  if (mask && !mask[key2]) {
10553
10815
  newShape[key2] = this.shape[key2];
10554
10816
  } else {
@@ -10559,7 +10821,7 @@ class ZodObject extends ZodType {
10559
10821
  }
10560
10822
  newShape[key2] = newField;
10561
10823
  }
10562
- });
10824
+ }
10563
10825
  return new ZodObject({
10564
10826
  ...this._def,
10565
10827
  shape: () => newShape
@@ -10687,103 +10949,6 @@ ZodUnion.create = (types, params) => {
10687
10949
  ...processCreateParams(params)
10688
10950
  });
10689
10951
  };
10690
- const getDiscriminator = (type) => {
10691
- if (type instanceof ZodLazy) {
10692
- return getDiscriminator(type.schema);
10693
- } else if (type instanceof ZodEffects) {
10694
- return getDiscriminator(type.innerType());
10695
- } else if (type instanceof ZodLiteral) {
10696
- return [type.value];
10697
- } else if (type instanceof ZodEnum) {
10698
- return type.options;
10699
- } else if (type instanceof ZodNativeEnum) {
10700
- return Object.keys(type.enum);
10701
- } else if (type instanceof ZodDefault) {
10702
- return getDiscriminator(type._def.innerType);
10703
- } else if (type instanceof ZodUndefined) {
10704
- return [void 0];
10705
- } else if (type instanceof ZodNull) {
10706
- return [null];
10707
- } else {
10708
- return null;
10709
- }
10710
- };
10711
- class ZodDiscriminatedUnion extends ZodType {
10712
- _parse(input) {
10713
- const { ctx: ctx2 } = this._processInputParams(input);
10714
- if (ctx2.parsedType !== ZodParsedType.object) {
10715
- addIssueToContext(ctx2, {
10716
- code: ZodIssueCode.invalid_type,
10717
- expected: ZodParsedType.object,
10718
- received: ctx2.parsedType
10719
- });
10720
- return INVALID;
10721
- }
10722
- const discriminator = this.discriminator;
10723
- const discriminatorValue = ctx2.data[discriminator];
10724
- const option = this.optionsMap.get(discriminatorValue);
10725
- if (!option) {
10726
- addIssueToContext(ctx2, {
10727
- code: ZodIssueCode.invalid_union_discriminator,
10728
- options: Array.from(this.optionsMap.keys()),
10729
- path: [discriminator]
10730
- });
10731
- return INVALID;
10732
- }
10733
- if (ctx2.common.async) {
10734
- return option._parseAsync({
10735
- data: ctx2.data,
10736
- path: ctx2.path,
10737
- parent: ctx2
10738
- });
10739
- } else {
10740
- return option._parseSync({
10741
- data: ctx2.data,
10742
- path: ctx2.path,
10743
- parent: ctx2
10744
- });
10745
- }
10746
- }
10747
- get discriminator() {
10748
- return this._def.discriminator;
10749
- }
10750
- get options() {
10751
- return this._def.options;
10752
- }
10753
- get optionsMap() {
10754
- return this._def.optionsMap;
10755
- }
10756
- /**
10757
- * The constructor of the discriminated union schema. Its behaviour is very similar to that of the normal z.union() constructor.
10758
- * However, it only allows a union of objects, all of which need to share a discriminator property. This property must
10759
- * have a different value for each object in the union.
10760
- * @param discriminator the name of the discriminator property
10761
- * @param types an array of object schemas
10762
- * @param params
10763
- */
10764
- static create(discriminator, options, params) {
10765
- const optionsMap = /* @__PURE__ */ new Map();
10766
- for (const type of options) {
10767
- const discriminatorValues = getDiscriminator(type.shape[discriminator]);
10768
- if (!discriminatorValues) {
10769
- throw new Error(`A discriminator value for key \`${discriminator}\` could not be extracted from all schema options`);
10770
- }
10771
- for (const value of discriminatorValues) {
10772
- if (optionsMap.has(value)) {
10773
- throw new Error(`Discriminator property ${String(discriminator)} has duplicate value ${String(value)}`);
10774
- }
10775
- optionsMap.set(value, type);
10776
- }
10777
- }
10778
- return new ZodDiscriminatedUnion({
10779
- typeName: ZodFirstPartyTypeKind.ZodDiscriminatedUnion,
10780
- discriminator,
10781
- options,
10782
- optionsMap,
10783
- ...processCreateParams(params)
10784
- });
10785
- }
10786
- }
10787
10952
  function mergeValues(a2, b) {
10788
10953
  const aType = getParsedType(a2);
10789
10954
  const bType = getParsedType(b);
@@ -10965,7 +11130,8 @@ class ZodRecord extends ZodType {
10965
11130
  for (const key2 in ctx2.data) {
10966
11131
  pairs.push({
10967
11132
  key: keyType._parse(new ParseInputLazyPath(ctx2, key2, ctx2.path, key2)),
10968
- value: valueType._parse(new ParseInputLazyPath(ctx2, ctx2.data[key2], ctx2.path, key2))
11133
+ value: valueType._parse(new ParseInputLazyPath(ctx2, ctx2.data[key2], ctx2.path, key2)),
11134
+ alwaysSet: key2 in ctx2.data
10969
11135
  });
10970
11136
  }
10971
11137
  if (ctx2.common.async) {
@@ -11145,121 +11311,6 @@ ZodSet.create = (valueType, params) => {
11145
11311
  ...processCreateParams(params)
11146
11312
  });
11147
11313
  };
11148
- class ZodFunction extends ZodType {
11149
- constructor() {
11150
- super(...arguments);
11151
- this.validate = this.implement;
11152
- }
11153
- _parse(input) {
11154
- const { ctx: ctx2 } = this._processInputParams(input);
11155
- if (ctx2.parsedType !== ZodParsedType.function) {
11156
- addIssueToContext(ctx2, {
11157
- code: ZodIssueCode.invalid_type,
11158
- expected: ZodParsedType.function,
11159
- received: ctx2.parsedType
11160
- });
11161
- return INVALID;
11162
- }
11163
- function makeArgsIssue(args, error) {
11164
- return makeIssue({
11165
- data: args,
11166
- path: ctx2.path,
11167
- errorMaps: [
11168
- ctx2.common.contextualErrorMap,
11169
- ctx2.schemaErrorMap,
11170
- getErrorMap(),
11171
- errorMap
11172
- ].filter((x) => !!x),
11173
- issueData: {
11174
- code: ZodIssueCode.invalid_arguments,
11175
- argumentsError: error
11176
- }
11177
- });
11178
- }
11179
- function makeReturnsIssue(returns, error) {
11180
- return makeIssue({
11181
- data: returns,
11182
- path: ctx2.path,
11183
- errorMaps: [
11184
- ctx2.common.contextualErrorMap,
11185
- ctx2.schemaErrorMap,
11186
- getErrorMap(),
11187
- errorMap
11188
- ].filter((x) => !!x),
11189
- issueData: {
11190
- code: ZodIssueCode.invalid_return_type,
11191
- returnTypeError: error
11192
- }
11193
- });
11194
- }
11195
- const params = { errorMap: ctx2.common.contextualErrorMap };
11196
- const fn = ctx2.data;
11197
- if (this._def.returns instanceof ZodPromise) {
11198
- const me = this;
11199
- return OK(async function(...args) {
11200
- const error = new ZodError([]);
11201
- const parsedArgs = await me._def.args.parseAsync(args, params).catch((e2) => {
11202
- error.addIssue(makeArgsIssue(args, e2));
11203
- throw error;
11204
- });
11205
- const result = await Reflect.apply(fn, this, parsedArgs);
11206
- const parsedReturns = await me._def.returns._def.type.parseAsync(result, params).catch((e2) => {
11207
- error.addIssue(makeReturnsIssue(result, e2));
11208
- throw error;
11209
- });
11210
- return parsedReturns;
11211
- });
11212
- } else {
11213
- const me = this;
11214
- return OK(function(...args) {
11215
- const parsedArgs = me._def.args.safeParse(args, params);
11216
- if (!parsedArgs.success) {
11217
- throw new ZodError([makeArgsIssue(args, parsedArgs.error)]);
11218
- }
11219
- const result = Reflect.apply(fn, this, parsedArgs.data);
11220
- const parsedReturns = me._def.returns.safeParse(result, params);
11221
- if (!parsedReturns.success) {
11222
- throw new ZodError([makeReturnsIssue(result, parsedReturns.error)]);
11223
- }
11224
- return parsedReturns.data;
11225
- });
11226
- }
11227
- }
11228
- parameters() {
11229
- return this._def.args;
11230
- }
11231
- returnType() {
11232
- return this._def.returns;
11233
- }
11234
- args(...items) {
11235
- return new ZodFunction({
11236
- ...this._def,
11237
- args: ZodTuple.create(items).rest(ZodUnknown.create())
11238
- });
11239
- }
11240
- returns(returnType) {
11241
- return new ZodFunction({
11242
- ...this._def,
11243
- returns: returnType
11244
- });
11245
- }
11246
- implement(func) {
11247
- const validatedFunc = this.parse(func);
11248
- return validatedFunc;
11249
- }
11250
- strictImplement(func) {
11251
- const validatedFunc = this.parse(func);
11252
- return validatedFunc;
11253
- }
11254
- static create(args, returns, params) {
11255
- return new ZodFunction({
11256
- args: args ? args : ZodTuple.create([]).rest(ZodUnknown.create()),
11257
- returns: returns || ZodUnknown.create(),
11258
- typeName: ZodFirstPartyTypeKind.ZodFunction,
11259
- ...processCreateParams(params)
11260
- });
11261
- }
11262
- }
11263
11314
  class ZodLazy extends ZodType {
11264
11315
  get schema() {
11265
11316
  return this._def.getter();
@@ -11320,7 +11371,10 @@ class ZodEnum extends ZodType {
11320
11371
  });
11321
11372
  return INVALID;
11322
11373
  }
11323
- if (this._def.values.indexOf(input.data) === -1) {
11374
+ if (!this._cache) {
11375
+ this._cache = new Set(this._def.values);
11376
+ }
11377
+ if (!this._cache.has(input.data)) {
11324
11378
  const ctx2 = this._getOrReturnCtx(input);
11325
11379
  const expectedValues = this._def.values;
11326
11380
  addIssueToContext(ctx2, {
@@ -11356,11 +11410,17 @@ class ZodEnum extends ZodType {
11356
11410
  }
11357
11411
  return enumValues;
11358
11412
  }
11359
- extract(values) {
11360
- return ZodEnum.create(values);
11413
+ extract(values, newDef = this._def) {
11414
+ return ZodEnum.create(values, {
11415
+ ...this._def,
11416
+ ...newDef
11417
+ });
11361
11418
  }
11362
- exclude(values) {
11363
- return ZodEnum.create(this.options.filter((opt) => !values.includes(opt)));
11419
+ exclude(values, newDef = this._def) {
11420
+ return ZodEnum.create(this.options.filter((opt) => !values.includes(opt)), {
11421
+ ...this._def,
11422
+ ...newDef
11423
+ });
11364
11424
  }
11365
11425
  }
11366
11426
  ZodEnum.create = createZodEnum;
@@ -11377,7 +11437,10 @@ class ZodNativeEnum extends ZodType {
11377
11437
  });
11378
11438
  return INVALID;
11379
11439
  }
11380
- if (nativeEnumValues.indexOf(input.data) === -1) {
11440
+ if (!this._cache) {
11441
+ this._cache = new Set(util.getValidEnumValues(this._def.values));
11442
+ }
11443
+ if (!this._cache.has(input.data)) {
11381
11444
  const expectedValues = util.objectValues(nativeEnumValues);
11382
11445
  addIssueToContext(ctx2, {
11383
11446
  received: ctx2.data,
@@ -11455,26 +11518,38 @@ class ZodEffects extends ZodType {
11455
11518
  checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx);
11456
11519
  if (effect.type === "preprocess") {
11457
11520
  const processed = effect.transform(ctx2.data, checkCtx);
11458
- if (ctx2.common.issues.length) {
11459
- return {
11460
- status: "dirty",
11461
- value: ctx2.data
11462
- };
11463
- }
11464
11521
  if (ctx2.common.async) {
11465
- return Promise.resolve(processed).then((processed2) => {
11466
- return this._def.schema._parseAsync({
11522
+ return Promise.resolve(processed).then(async (processed2) => {
11523
+ if (status.value === "aborted")
11524
+ return INVALID;
11525
+ const result = await this._def.schema._parseAsync({
11467
11526
  data: processed2,
11468
11527
  path: ctx2.path,
11469
11528
  parent: ctx2
11470
11529
  });
11530
+ if (result.status === "aborted")
11531
+ return INVALID;
11532
+ if (result.status === "dirty")
11533
+ return DIRTY(result.value);
11534
+ if (status.value === "dirty")
11535
+ return DIRTY(result.value);
11536
+ return result;
11471
11537
  });
11472
11538
  } else {
11473
- return this._def.schema._parseSync({
11539
+ if (status.value === "aborted")
11540
+ return INVALID;
11541
+ const result = this._def.schema._parseSync({
11474
11542
  data: processed,
11475
11543
  path: ctx2.path,
11476
11544
  parent: ctx2
11477
11545
  });
11546
+ if (result.status === "aborted")
11547
+ return INVALID;
11548
+ if (result.status === "dirty")
11549
+ return DIRTY(result.value);
11550
+ if (status.value === "dirty")
11551
+ return DIRTY(result.value);
11552
+ return result;
11478
11553
  }
11479
11554
  }
11480
11555
  if (effect.type === "refinement") {
@@ -11520,7 +11595,7 @@ class ZodEffects extends ZodType {
11520
11595
  parent: ctx2
11521
11596
  });
11522
11597
  if (!isValid(base))
11523
- return base;
11598
+ return INVALID;
11524
11599
  const result = effect.transform(base.value, checkCtx);
11525
11600
  if (result instanceof Promise) {
11526
11601
  throw new Error(`Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.`);
@@ -11529,8 +11604,11 @@ class ZodEffects extends ZodType {
11529
11604
  } else {
11530
11605
  return this._def.schema._parseAsync({ data: ctx2.data, path: ctx2.path, parent: ctx2 }).then((base) => {
11531
11606
  if (!isValid(base))
11532
- return base;
11533
- return Promise.resolve(effect.transform(base.value, checkCtx)).then((result) => ({ status: status.value, value: result }));
11607
+ return INVALID;
11608
+ return Promise.resolve(effect.transform(base.value, checkCtx)).then((result) => ({
11609
+ status: status.value,
11610
+ value: result
11611
+ }));
11534
11612
  });
11535
11613
  }
11536
11614
  }
@@ -11690,7 +11768,6 @@ ZodNaN.create = (params) => {
11690
11768
  ...processCreateParams(params)
11691
11769
  });
11692
11770
  };
11693
- const BRAND = Symbol("zod_brand");
11694
11771
  class ZodBranded extends ZodType {
11695
11772
  _parse(input) {
11696
11773
  const { ctx: ctx2 } = this._processInputParams(input);
@@ -11763,10 +11840,16 @@ class ZodPipeline extends ZodType {
11763
11840
  class ZodReadonly extends ZodType {
11764
11841
  _parse(input) {
11765
11842
  const result = this._def.innerType._parse(input);
11766
- if (isValid(result)) {
11767
- result.value = Object.freeze(result.value);
11768
- }
11769
- return result;
11843
+ const freeze = (data) => {
11844
+ if (isValid(data)) {
11845
+ data.value = Object.freeze(data.value);
11846
+ }
11847
+ return data;
11848
+ };
11849
+ return isAsync(result) ? result.then((data) => freeze(data)) : freeze(result);
11850
+ }
11851
+ unwrap() {
11852
+ return this._def.innerType;
11770
11853
  }
11771
11854
  }
11772
11855
  ZodReadonly.create = (type, params) => {
@@ -11776,22 +11859,6 @@ ZodReadonly.create = (type, params) => {
11776
11859
  ...processCreateParams(params)
11777
11860
  });
11778
11861
  };
11779
- const custom = (check, params = {}, fatal) => {
11780
- if (check)
11781
- return ZodAny.create().superRefine((data, ctx2) => {
11782
- var _a, _b;
11783
- if (!check(data)) {
11784
- const p = typeof params === "function" ? params(data) : typeof params === "string" ? { message: params } : params;
11785
- const _fatal = (_b = (_a = p.fatal) !== null && _a !== void 0 ? _a : fatal) !== null && _b !== void 0 ? _b : true;
11786
- const p2 = typeof p === "string" ? { message: p } : p;
11787
- ctx2.addIssue({ code: "custom", ...p2, fatal: _fatal });
11788
- }
11789
- });
11790
- return ZodAny.create();
11791
- };
11792
- const late = {
11793
- object: ZodObject.lazycreate
11794
- };
11795
11862
  var ZodFirstPartyTypeKind;
11796
11863
  (function(ZodFirstPartyTypeKind2) {
11797
11864
  ZodFirstPartyTypeKind2["ZodString"] = "ZodString";
@@ -11831,46 +11898,24 @@ var ZodFirstPartyTypeKind;
11831
11898
  ZodFirstPartyTypeKind2["ZodPipeline"] = "ZodPipeline";
11832
11899
  ZodFirstPartyTypeKind2["ZodReadonly"] = "ZodReadonly";
11833
11900
  })(ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {}));
11834
- const instanceOfType = (cls, params = {
11835
- message: `Input not instance of ${cls.name}`
11836
- }) => custom((data) => data instanceof cls, params);
11837
11901
  const stringType = ZodString.create;
11838
11902
  const numberType = ZodNumber.create;
11839
- const nanType = ZodNaN.create;
11840
- const bigIntType = ZodBigInt.create;
11903
+ ZodBigInt.create;
11841
11904
  const booleanType = ZodBoolean.create;
11842
11905
  const dateType = ZodDate.create;
11843
- const symbolType = ZodSymbol.create;
11844
- const undefinedType = ZodUndefined.create;
11845
- const nullType = ZodNull.create;
11846
11906
  const anyType = ZodAny.create;
11847
11907
  const unknownType = ZodUnknown.create;
11848
- const neverType = ZodNever.create;
11849
- const voidType = ZodVoid.create;
11908
+ ZodNever.create;
11850
11909
  const arrayType = ZodArray.create;
11851
11910
  const objectType = ZodObject.create;
11852
- const strictObjectType = ZodObject.strictCreate;
11853
11911
  const unionType = ZodUnion.create;
11854
- const discriminatedUnionType = ZodDiscriminatedUnion.create;
11855
- const intersectionType = ZodIntersection.create;
11856
- const tupleType = ZodTuple.create;
11912
+ ZodIntersection.create;
11913
+ ZodTuple.create;
11857
11914
  const recordType = ZodRecord.create;
11858
- const mapType = ZodMap.create;
11859
- const setType = ZodSet.create;
11860
- const functionType = ZodFunction.create;
11861
- const lazyType = ZodLazy.create;
11862
- const literalType = ZodLiteral.create;
11863
11915
  const enumType = ZodEnum.create;
11864
- const nativeEnumType = ZodNativeEnum.create;
11865
- const promiseType = ZodPromise.create;
11866
- const effectsType = ZodEffects.create;
11867
- const optionalType = ZodOptional.create;
11868
- const nullableType = ZodNullable.create;
11869
- const preprocessType = ZodEffects.createWithPreprocess;
11870
- const pipelineType = ZodPipeline.create;
11871
- const ostring = () => stringType().optional();
11872
- const onumber = () => numberType().optional();
11873
- const oboolean = () => booleanType().optional();
11916
+ ZodPromise.create;
11917
+ ZodOptional.create;
11918
+ ZodNullable.create;
11874
11919
  const coerce = {
11875
11920
  string: (arg) => ZodString.create({ ...arg, coerce: true }),
11876
11921
  number: (arg) => ZodNumber.create({ ...arg, coerce: true }),
@@ -11881,122 +11926,6 @@ const coerce = {
11881
11926
  bigint: (arg) => ZodBigInt.create({ ...arg, coerce: true }),
11882
11927
  date: (arg) => ZodDate.create({ ...arg, coerce: true })
11883
11928
  };
11884
- const NEVER = INVALID;
11885
- var z = /* @__PURE__ */ Object.freeze({
11886
- __proto__: null,
11887
- defaultErrorMap: errorMap,
11888
- setErrorMap,
11889
- getErrorMap,
11890
- makeIssue,
11891
- EMPTY_PATH,
11892
- addIssueToContext,
11893
- ParseStatus,
11894
- INVALID,
11895
- DIRTY,
11896
- OK,
11897
- isAborted,
11898
- isDirty,
11899
- isValid,
11900
- isAsync,
11901
- get util() {
11902
- return util;
11903
- },
11904
- get objectUtil() {
11905
- return objectUtil;
11906
- },
11907
- ZodParsedType,
11908
- getParsedType,
11909
- ZodType,
11910
- ZodString,
11911
- ZodNumber,
11912
- ZodBigInt,
11913
- ZodBoolean,
11914
- ZodDate,
11915
- ZodSymbol,
11916
- ZodUndefined,
11917
- ZodNull,
11918
- ZodAny,
11919
- ZodUnknown,
11920
- ZodNever,
11921
- ZodVoid,
11922
- ZodArray,
11923
- ZodObject,
11924
- ZodUnion,
11925
- ZodDiscriminatedUnion,
11926
- ZodIntersection,
11927
- ZodTuple,
11928
- ZodRecord,
11929
- ZodMap,
11930
- ZodSet,
11931
- ZodFunction,
11932
- ZodLazy,
11933
- ZodLiteral,
11934
- ZodEnum,
11935
- ZodNativeEnum,
11936
- ZodPromise,
11937
- ZodEffects,
11938
- ZodTransformer: ZodEffects,
11939
- ZodOptional,
11940
- ZodNullable,
11941
- ZodDefault,
11942
- ZodCatch,
11943
- ZodNaN,
11944
- BRAND,
11945
- ZodBranded,
11946
- ZodPipeline,
11947
- ZodReadonly,
11948
- custom,
11949
- Schema: ZodType,
11950
- ZodSchema: ZodType,
11951
- late,
11952
- get ZodFirstPartyTypeKind() {
11953
- return ZodFirstPartyTypeKind;
11954
- },
11955
- coerce,
11956
- any: anyType,
11957
- array: arrayType,
11958
- bigint: bigIntType,
11959
- boolean: booleanType,
11960
- date: dateType,
11961
- discriminatedUnion: discriminatedUnionType,
11962
- effect: effectsType,
11963
- "enum": enumType,
11964
- "function": functionType,
11965
- "instanceof": instanceOfType,
11966
- intersection: intersectionType,
11967
- lazy: lazyType,
11968
- literal: literalType,
11969
- map: mapType,
11970
- nan: nanType,
11971
- nativeEnum: nativeEnumType,
11972
- never: neverType,
11973
- "null": nullType,
11974
- nullable: nullableType,
11975
- number: numberType,
11976
- object: objectType,
11977
- oboolean,
11978
- onumber,
11979
- optional: optionalType,
11980
- ostring,
11981
- pipeline: pipelineType,
11982
- preprocess: preprocessType,
11983
- promise: promiseType,
11984
- record: recordType,
11985
- set: setType,
11986
- strictObject: strictObjectType,
11987
- string: stringType,
11988
- symbol: symbolType,
11989
- transformer: effectsType,
11990
- tuple: tupleType,
11991
- "undefined": undefinedType,
11992
- union: unionType,
11993
- unknown: unknownType,
11994
- "void": voidType,
11995
- NEVER,
11996
- ZodIssueCode,
11997
- quotelessJson,
11998
- ZodError
11999
- });
12000
11929
  var __defProp$1 = Object.defineProperty;
12001
11930
  var __defProps$1 = Object.defineProperties;
12002
11931
  var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
@@ -20065,9 +19994,9 @@ const currencies = {
20065
19994
  decimal_digits: 0
20066
19995
  }
20067
19996
  };
20068
- const formSchema = z.object({
20069
- currency_code: z.string().min(1, "Please select a currency"),
20070
- customer_id: z.string().min(1, "Please select a customer")
19997
+ const formSchema = objectType({
19998
+ currency_code: stringType().min(1, "Please select a currency"),
19999
+ customer_id: stringType().optional()
20071
20000
  });
20072
20001
  const StoreCreditAccountCreateForm = () => {
20073
20002
  const { handleSuccess } = useRouteModal();
@@ -20080,6 +20009,9 @@ const StoreCreditAccountCreateForm = () => {
20080
20009
  });
20081
20010
  const { mutateAsync: createStoreCreditAccount, isPending } = useCreateStoreCreditAccount();
20082
20011
  const handleSubmit = form.handleSubmit(async (data) => {
20012
+ if (!data.customer_id) {
20013
+ delete data.customer_id;
20014
+ }
20083
20015
  await createStoreCreditAccount(data, {
20084
20016
  onSuccess: (data2) => {
20085
20017
  toast.success(`Store credit account was successfully created.`);
@@ -20350,7 +20282,11 @@ const GiftCardProductsSection = () => {
20350
20282
  )
20351
20283
  ] });
20352
20284
  };
20353
- const giftCardQueryKey = queryKeysFactory("gift-card");
20285
+ const _giftCardQueryKey = queryKeysFactory("gift-card");
20286
+ const giftCardQueryKey = {
20287
+ ..._giftCardQueryKey,
20288
+ orders: (id) => [..._giftCardQueryKey.detail(id), "orders"]
20289
+ };
20354
20290
  const useGiftCards = (query, options) => {
20355
20291
  const fetchGiftCards = (query2, headers) => sdk.client.fetch(`/admin/gift-cards`, {
20356
20292
  query: query2,
@@ -20375,19 +20311,17 @@ const useGiftCard = (id, query, options) => {
20375
20311
  });
20376
20312
  return { ...data, ...rest };
20377
20313
  };
20378
- const useRedeemGiftCard = (id, options) => {
20379
- const queryClient = useQueryClient();
20380
- const redeemGiftCard = async (id2, body) => sdk.client.fetch(`/admin/gift-cards/${id2}/redeem`, {
20381
- body,
20382
- method: "POST"
20314
+ const useGiftCardOrders = (id, options) => {
20315
+ const fetchGiftCardOrders = (id2, query, headers) => sdk.client.fetch(`/admin/gift-cards/${id2}/orders`, {
20316
+ query,
20317
+ headers
20383
20318
  });
20384
- return useMutation({
20385
- mutationFn: (body) => redeemGiftCard(id, body),
20386
- onSuccess: (data, variables, context) => {
20387
- queryClient.invalidateQueries({ queryKey: giftCardQueryKey.lists() });
20388
- queryClient.invalidateQueries({ queryKey: giftCardQueryKey.detail(id) });
20389
- }
20319
+ const { data, ...rest } = useQuery({
20320
+ queryFn: () => fetchGiftCardOrders(id),
20321
+ queryKey: giftCardQueryKey.orders(id),
20322
+ ...options
20390
20323
  });
20324
+ return { ...data, ...rest };
20391
20325
  };
20392
20326
  const useUpdateGiftCard = (id, options) => {
20393
20327
  const queryClient = useQueryClient();
@@ -20438,6 +20372,12 @@ const columnHelper$9 = createDataTableColumnHelper();
20438
20372
  const useGiftCardTableColumns = () => {
20439
20373
  return useMemo(() => {
20440
20374
  return [
20375
+ columnHelper$9.accessor("code", {
20376
+ header: "Code",
20377
+ cell: ({ row }) => {
20378
+ return row.original.code;
20379
+ }
20380
+ }),
20441
20381
  columnHelper$9.accessor("line_item.product.title", {
20442
20382
  header: "Product",
20443
20383
  cell: ({ row }) => {
@@ -20445,34 +20385,10 @@ const useGiftCardTableColumns = () => {
20445
20385
  return ((_b = (_a = row.original.line_item) == null ? void 0 : _a.product) == null ? void 0 : _b.title) || "Custom Gift Card";
20446
20386
  }
20447
20387
  }),
20448
- columnHelper$9.accessor("customer.first_name", {
20449
- header: "Owner",
20450
- cell: ({ row }) => {
20451
- if (!row.original.customer) {
20452
- return "N/A";
20453
- }
20454
- const fullName = [
20455
- row.original.customer.first_name,
20456
- row.original.customer.last_name
20457
- ];
20458
- if (fullName.join("").length > 0) {
20459
- return fullName.join(" ");
20460
- }
20461
- return row.original.customer.email;
20462
- }
20463
- }),
20464
20388
  columnHelper$9.accessor("created_at", {
20465
20389
  header: "Date issued",
20466
20390
  cell: ({ row }) => getRelativeDate(row.original.created_at)
20467
20391
  }),
20468
- columnHelper$9.accessor("status", {
20469
- header: "Status",
20470
- cell: ({ row }) => {
20471
- const status = getGiftCardStatus(row.original);
20472
- const color = getGiftCardStatusColor(status);
20473
- return /* @__PURE__ */ jsx(StatusBadge, { color, children: status });
20474
- }
20475
- }),
20476
20392
  columnHelper$9.accessor("value", {
20477
20393
  header: "Value",
20478
20394
  cell: ({ row }) => {
@@ -20596,19 +20512,16 @@ const useStore$1 = (query, options) => {
20596
20512
  ...rest
20597
20513
  };
20598
20514
  };
20599
- const GiftCardCreateSchema = z.object({
20600
- value: z.coerce.number().positive({
20515
+ const GiftCardCreateSchema = objectType({
20516
+ value: coerce.number().positive({
20601
20517
  message: "Value must be a positive number"
20602
20518
  }),
20603
- currency_code: z.string({
20519
+ currency_code: stringType({
20604
20520
  required_error: "Currency is required"
20605
20521
  }),
20606
- customer_id: z.string({
20607
- required_error: "Customer is required"
20608
- }),
20609
- expires_at: z.date().nullable().optional(),
20610
- note: z.string().optional(),
20611
- metadata: z.record(z.string(), z.string()).optional()
20522
+ expires_at: dateType().nullable().optional(),
20523
+ note: stringType().optional(),
20524
+ metadata: recordType(stringType(), stringType()).optional()
20612
20525
  });
20613
20526
  const GiftCardCreateForm = ({
20614
20527
  store
@@ -20621,10 +20534,9 @@ const GiftCardCreateForm = ({
20621
20534
  defaultValues: {
20622
20535
  value: void 0,
20623
20536
  currency_code: (supportedCurrencies == null ? void 0 : supportedCurrencies[0]) ?? "eur",
20624
- customer_id: "",
20625
20537
  expires_at: null,
20626
- note: "",
20627
- metadata: {}
20538
+ metadata: {},
20539
+ note: ""
20628
20540
  },
20629
20541
  resolver: t(GiftCardCreateSchema)
20630
20542
  });
@@ -20653,30 +20565,6 @@ const GiftCardCreateForm = ({
20653
20565
  (option) => option.label.toLowerCase().includes(currencySearchValue.toLowerCase())
20654
20566
  );
20655
20567
  }, [currencySearchValue]);
20656
- const {
20657
- options: customerOptions,
20658
- fetchNextPage,
20659
- isFetchingNextPage,
20660
- searchValue,
20661
- onSearchValueChange,
20662
- isLoading
20663
- } = useComboboxData({
20664
- queryKey: customersQueryKeys.list(),
20665
- queryFn: async (params) => {
20666
- return sdk.admin.customer.list(params);
20667
- },
20668
- getOptions: (data) => {
20669
- var _a;
20670
- return ((_a = data.customers) == null ? void 0 : _a.map((customer) => {
20671
- const fullName = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
20672
- const label = fullName ? `${customer.email} (${fullName})` : customer.email;
20673
- return {
20674
- label,
20675
- value: customer.id
20676
- };
20677
- })) || [];
20678
- }
20679
- });
20680
20568
  const selectedCurrency = form.watch("currency_code");
20681
20569
  const currentCurrency = useMemo(() => {
20682
20570
  return currencies[selectedCurrency.toUpperCase()];
@@ -20689,7 +20577,7 @@ const GiftCardCreateForm = ({
20689
20577
  /* @__PURE__ */ jsx(RouteFocusModal.Body, { className: "size-full overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: "flex flex-col items-center p-16", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-8", children: [
20690
20578
  /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
20691
20579
  /* @__PURE__ */ jsx(Heading, { level: "h1", children: "Create Gift Card" }),
20692
- /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-subtle", size: "small", children: "Create a new gift card for a customer" })
20580
+ /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-subtle", size: "small", children: "Create a new gift card" })
20693
20581
  ] }),
20694
20582
  /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
20695
20583
  /* @__PURE__ */ jsxs(
@@ -20738,14 +20626,21 @@ const GiftCardCreateForm = ({
20738
20626
  /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
20739
20627
  CurrencyInput$1,
20740
20628
  {
20741
- ...field,
20742
- formatValueOnBlur: true,
20743
- symbol: currentCurrency.symbol_native,
20629
+ value: field.value,
20744
20630
  code: currentCurrency.code,
20631
+ symbol: currentCurrency.symbol_native,
20745
20632
  decimalScale: currentCurrency.decimal_digits,
20746
20633
  decimalsLimit: currentCurrency.decimal_digits,
20634
+ allowDecimals: true,
20635
+ formatValueOnBlur: true,
20636
+ allowNegativeValue: false,
20747
20637
  autoComplete: "off",
20748
- tabIndex: -1
20638
+ tabIndex: -1,
20639
+ onValueChange: (_value, _name, values) => {
20640
+ field.onChange(
20641
+ (values == null ? void 0 : values.value) ? values == null ? void 0 : values.value : ""
20642
+ );
20643
+ }
20749
20644
  }
20750
20645
  ) }),
20751
20646
  /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
@@ -20757,22 +20652,17 @@ const GiftCardCreateForm = ({
20757
20652
  Form$2.Field,
20758
20653
  {
20759
20654
  control: form.control,
20760
- name: "customer_id",
20655
+ name: "expires_at",
20761
20656
  render: ({ field }) => {
20762
- return /* @__PURE__ */ jsxs(Form$2.Item, { className: "w-full", children: [
20763
- /* @__PURE__ */ jsx(Form$2.Label, { className: "font-normal", children: "Customer" }),
20657
+ return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
20658
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Expires at" }),
20764
20659
  /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
20765
- Combobox,
20660
+ DatePicker,
20766
20661
  {
20767
- value: field.value,
20768
- onChange: field.onChange,
20769
- searchValue,
20770
- onSearchValueChange,
20771
- options: customerOptions,
20772
- placeholder: "Search for a customer...",
20773
- fetchNextPage,
20774
- isFetchingNextPage,
20775
- noResultsPlaceholder: isLoading ? "Loading customers..." : "No customers found"
20662
+ hourCycle: 24,
20663
+ granularity: "minute",
20664
+ shouldCloseOnSelect: false,
20665
+ ...field
20776
20666
  }
20777
20667
  ) }),
20778
20668
  /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
@@ -20992,40 +20882,60 @@ const StoreCreditAccountDetailsSection = ({
20992
20882
  if (!storeCreditAccount || typeof storeCreditAccount.balance === "undefined") {
20993
20883
  return;
20994
20884
  }
20995
- return /* @__PURE__ */ jsx(Container$1, { className: "grid grid-cols-2 gap-x-2 px-6 py-6", children: /* @__PURE__ */ jsxs(
20996
- Text,
20997
- {
20998
- weight: "plus",
20999
- size: "xlarge",
21000
- className: "text-ui-fg-base flex gap-x-4",
21001
- children: [
21002
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-2", children: [
21003
- /* @__PURE__ */ jsx(CreditCardIcon, { className: "inline" }),
21004
- " "
21005
- ] }),
21006
- /* @__PURE__ */ jsxs("div", { children: [
21007
- /* @__PURE__ */ jsxs("div", { className: "text-ui-fg-subtle", children: [
21008
- storeCreditAccount.currency_code.toUpperCase(),
21009
- " Account"
20885
+ return /* @__PURE__ */ jsxs(Container$1, { className: "flex justify-between gap-x-2 px-6 py-6", children: [
20886
+ /* @__PURE__ */ jsxs(
20887
+ Text,
20888
+ {
20889
+ weight: "plus",
20890
+ size: "xlarge",
20891
+ className: "text-ui-fg-base flex gap-x-4",
20892
+ children: [
20893
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-2", children: [
20894
+ /* @__PURE__ */ jsx(CreditCardIcon, { className: "inline" }),
20895
+ " "
21010
20896
  ] }),
21011
- /* @__PURE__ */ jsx("div", { className: "text-ui-fg-base", children: /* @__PURE__ */ jsx(
21012
- Text,
21013
- {
21014
- weight: "regular",
21015
- size: "small",
21016
- className: "text-ui-fg-base flex gap-x-4",
21017
- children: /* @__PURE__ */ jsx(DisplayId, { id: storeCreditAccount.id })
21018
- }
21019
- ) })
21020
- ] })
21021
- ]
21022
- }
21023
- ) });
20897
+ /* @__PURE__ */ jsxs("div", { children: [
20898
+ /* @__PURE__ */ jsxs("div", { className: "text-ui-fg-subtle", children: [
20899
+ storeCreditAccount.currency_code.toUpperCase(),
20900
+ " Account"
20901
+ ] }),
20902
+ /* @__PURE__ */ jsx("div", { className: "text-ui-fg-base", children: /* @__PURE__ */ jsx(
20903
+ Text,
20904
+ {
20905
+ weight: "regular",
20906
+ size: "small",
20907
+ className: "text-ui-fg-base flex gap-x-4",
20908
+ children: /* @__PURE__ */ jsx(DisplayId, { id: storeCreditAccount.id })
20909
+ }
20910
+ ) })
20911
+ ] })
20912
+ ]
20913
+ }
20914
+ ),
20915
+ /* @__PURE__ */ jsx("div", { className: "flex items-center gap-x-4", children: /* @__PURE__ */ jsx(
20916
+ ActionMenu,
20917
+ {
20918
+ groups: [
20919
+ {
20920
+ actions: [
20921
+ {
20922
+ icon: /* @__PURE__ */ jsx(CreditCard, {}),
20923
+ label: "Credit the account",
20924
+ to: "credit"
20925
+ }
20926
+ ]
20927
+ }
20928
+ ]
20929
+ }
20930
+ ) })
20931
+ ] });
21024
20932
  };
21025
20933
  function StoreCreditAccountCustomerSection({
21026
20934
  customerId
21027
20935
  }) {
21028
- const { customer, isPending } = useCustomer(customerId);
20936
+ const { customer, isPending } = useCustomer(customerId, void 0, {
20937
+ enabled: !!customerId
20938
+ });
21029
20939
  if (isPending || !customer) {
21030
20940
  return null;
21031
20941
  }
@@ -21043,22 +20953,6 @@ function StoreCreditAccountCustomerSection({
21043
20953
  )
21044
20954
  ] });
21045
20955
  }
21046
- const transactionQueryKey = queryKeysFactory("transaction");
21047
- const useStoreCreditAccountTransactions = (id, query, options) => {
21048
- const fetchStoreCreditAccountTransactions = (query2, headers) => sdk.client.fetch(
21049
- `/admin/store-credit-accounts/${id}/transactions`,
21050
- {
21051
- query: query2,
21052
- headers
21053
- }
21054
- );
21055
- const { data, ...rest } = useQuery({
21056
- queryFn: () => fetchStoreCreditAccountTransactions(query),
21057
- queryKey: transactionQueryKey.list({ sca_id: id, query }),
21058
- ...options
21059
- });
21060
- return { ...data, ...rest };
21061
- };
21062
20956
  const columnHelper$8 = createDataTableColumnHelper();
21063
20957
  const useTransactionsTableColumns = () => {
21064
20958
  return useMemo(() => {
@@ -21073,18 +20967,14 @@ const useTransactionsTableColumns = () => {
21073
20967
  header: "Created At",
21074
20968
  cell: ({ row }) => formatDate(row.original.created_at, false)
21075
20969
  }),
21076
- columnHelper$8.accessor("reference", {
21077
- header: "Reference",
21078
- cell: ({ row }) => {
21079
- var _a;
21080
- const prettyReference = (_a = row.original.reference) == null ? void 0 : _a.split("_").join(" ").split("-").join(" ");
21081
- return /* @__PURE__ */ jsx(Text, { className: "capitalize", children: prettyReference });
21082
- }
20970
+ columnHelper$8.accessor("note", {
20971
+ header: "Description",
20972
+ cell: ({ row }) => row.original.note
21083
20973
  }),
21084
- columnHelper$8.accessor("reference_id", {
21085
- header: "Reference ID",
20974
+ columnHelper$8.accessor("note", {
20975
+ header: "Note",
21086
20976
  cell: ({ row }) => {
21087
- return /* @__PURE__ */ jsx(DisplayId, { id: row.original.reference_id });
20977
+ return /* @__PURE__ */ jsx(Text, { title: row.original.note, className: "max-w-[300px] truncate", children: row.original.note || "-" });
21088
20978
  }
21089
20979
  }),
21090
20980
  columnHelper$8.accessor("amount", {
@@ -21100,55 +20990,32 @@ const useTransactionsTableColumns = () => {
21100
20990
  ];
21101
20991
  }, []);
21102
20992
  };
21103
- const useTransactionsTableFilters = ({
21104
- transactionGroup
21105
- }) => {
20993
+ const useTransactionsTableFilters = ({}) => {
21106
20994
  const dateFilterOptions = useDataTableDateFilters$1();
21107
20995
  return useMemo(() => {
21108
- if (transactionGroup) {
21109
- return [...dateFilterOptions];
21110
- }
21111
20996
  return [...dateFilterOptions];
21112
- }, [dateFilterOptions, , transactionGroup]);
20997
+ }, [dateFilterOptions]);
21113
20998
  };
21114
20999
  const useTransactionsTableQuery = ({
21115
21000
  prefix,
21116
21001
  pageSize = 20
21117
21002
  }) => {
21118
21003
  const queryObject = useQueryParams(
21119
- [
21120
- "offset",
21121
- "limit",
21122
- "transaction_group_id",
21123
- "currency_code",
21124
- "created_at",
21125
- "updated_at"
21126
- ],
21004
+ ["offset", "limit", "currency_code", "created_at", "updated_at"],
21127
21005
  prefix
21128
21006
  );
21129
- const {
21130
- offset: offset2,
21131
- limit,
21132
- created_at,
21133
- updated_at,
21134
- transaction_group_id,
21135
- ...rest
21136
- } = queryObject;
21007
+ const { offset: offset2, limit, created_at, updated_at, ...rest } = queryObject;
21137
21008
  const searchParams = {
21138
21009
  limit: limit ? Number(limit) : pageSize,
21139
21010
  offset: offset2 ? Number(offset2) : 0,
21140
21011
  created_at: created_at ? JSON.parse(created_at) : void 0,
21141
21012
  updated_at: updated_at ? JSON.parse(updated_at) : void 0,
21142
- transaction_group_id: transaction_group_id ? JSON.parse(transaction_group_id) : void 0,
21143
21013
  ...rest
21144
21014
  };
21145
21015
  return searchParams;
21146
21016
  };
21147
21017
  const PAGE_SIZE$4 = 10;
21148
- function TransactionsTable({
21149
- id,
21150
- transactionGroup
21151
- }) {
21018
+ function TransactionsTable({ id }) {
21152
21019
  const queryParams = useTransactionsTableQuery({
21153
21020
  pageSize: PAGE_SIZE$4
21154
21021
  });
@@ -21156,13 +21023,12 @@ function TransactionsTable({
21156
21023
  id,
21157
21024
  {
21158
21025
  ...queryParams,
21159
- transaction_group_id: transactionGroup == null ? void 0 : transactionGroup.id,
21160
21026
  order: queryParams.order ?? "-created_at",
21161
- fields: "*account,*transaction_group"
21027
+ fields: "*account"
21162
21028
  }
21163
21029
  );
21164
21030
  const columns = useTransactionsTableColumns();
21165
- const filters = useTransactionsTableFilters({ transactionGroup });
21031
+ const filters = useTransactionsTableFilters({});
21166
21032
  return /* @__PURE__ */ jsxs(Fragment$1, { children: [
21167
21033
  /* @__PURE__ */ jsx(Container$1, { className: "p-0", children: /* @__PURE__ */ jsx(
21168
21034
  DataTable,
@@ -21190,6 +21056,18 @@ function TransactionsTable({
21190
21056
  /* @__PURE__ */ jsx(Outlet, {})
21191
21057
  ] });
21192
21058
  }
21059
+ function StoreCreditAccountCodeSection({ code }) {
21060
+ if (!code) {
21061
+ return null;
21062
+ }
21063
+ return /* @__PURE__ */ jsxs(Container$1, { className: "p-0", children: [
21064
+ /* @__PURE__ */ jsx(Header$5, { title: "Account Code" }),
21065
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-4 px-6 mb-2", children: [
21066
+ /* @__PURE__ */ jsx(Share, { className: "inline" }),
21067
+ /* @__PURE__ */ jsx("div", { className: "text-ui-fg-subtle text-sm", children: code })
21068
+ ] })
21069
+ ] });
21070
+ }
21193
21071
  const StoreCreditAccountPage = () => {
21194
21072
  const { id } = useParams();
21195
21073
  const { store_credit_account: storeCreditAccount } = useStoreCreditAccount(
@@ -21217,6 +21095,7 @@ const StoreCreditAccountPage = () => {
21217
21095
  storeCreditAccount
21218
21096
  }
21219
21097
  ),
21098
+ /* @__PURE__ */ jsx(StoreCreditAccountCodeSection, { code: storeCreditAccount.code }),
21220
21099
  /* @__PURE__ */ jsx(
21221
21100
  StoreCreditAccountCustomerSection,
21222
21101
  {
@@ -21227,6 +21106,145 @@ const StoreCreditAccountPage = () => {
21227
21106
  }
21228
21107
  ) });
21229
21108
  };
21109
+ const KeyboundForm = React__default.forwardRef(({ onSubmit, onKeyDown, ...rest }, ref) => {
21110
+ const handleSubmit = (event) => {
21111
+ event.preventDefault();
21112
+ onSubmit == null ? void 0 : onSubmit(event);
21113
+ };
21114
+ const handleKeyDown = (event) => {
21115
+ if (event.key === "Enter") {
21116
+ if (event.target instanceof HTMLTextAreaElement && !(event.metaKey || event.ctrlKey)) {
21117
+ return;
21118
+ }
21119
+ event.preventDefault();
21120
+ if (event.metaKey || event.ctrlKey) {
21121
+ handleSubmit(event);
21122
+ }
21123
+ }
21124
+ };
21125
+ return /* @__PURE__ */ jsx(
21126
+ "form",
21127
+ {
21128
+ ...rest,
21129
+ onSubmit: handleSubmit,
21130
+ onKeyDown: onKeyDown ?? handleKeyDown,
21131
+ ref
21132
+ }
21133
+ );
21134
+ });
21135
+ KeyboundForm.displayName = "KeyboundForm";
21136
+ const Note$1 = () => {
21137
+ const { id } = useParams();
21138
+ const {
21139
+ store_credit_account: storeCreditAccount,
21140
+ isPending,
21141
+ isError,
21142
+ error
21143
+ } = useStoreCreditAccount(id, {});
21144
+ if (isError) {
21145
+ throw error;
21146
+ }
21147
+ const isReady = !isPending && !!storeCreditAccount;
21148
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
21149
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
21150
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Credit store credit account" }) }),
21151
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Credit the store credit account" }) })
21152
+ ] }),
21153
+ isReady && /* @__PURE__ */ jsx(StoreCreditAccountCreditForm, { storeCreditAccount })
21154
+ ] });
21155
+ };
21156
+ const StoreCreditAccountCreditForm = ({
21157
+ storeCreditAccount
21158
+ }) => {
21159
+ const form = useForm({
21160
+ defaultValues: {
21161
+ amount: {
21162
+ float: 0,
21163
+ value: ""
21164
+ },
21165
+ note: ""
21166
+ },
21167
+ resolver: t(schema$2)
21168
+ });
21169
+ const { mutateAsync, isPending } = useCreditStoreCreditAccount(
21170
+ storeCreditAccount.id
21171
+ );
21172
+ const { handleSuccess } = useRouteModal();
21173
+ const onSubmit = form.handleSubmit(async (data) => {
21174
+ if (data.amount.float <= 0) {
21175
+ form.setError("amount", { message: "Amount must be greater than 0" });
21176
+ return;
21177
+ }
21178
+ await mutateAsync(
21179
+ { amount: data.amount.float, note: data.note },
21180
+ {
21181
+ onSuccess: () => handleSuccess(),
21182
+ onError: (error) => toast.error(error.message)
21183
+ }
21184
+ );
21185
+ });
21186
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
21187
+ KeyboundForm,
21188
+ {
21189
+ className: "flex flex-1 flex-col overflow-hidden",
21190
+ onSubmit,
21191
+ children: [
21192
+ /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
21193
+ /* @__PURE__ */ jsx(
21194
+ Form$2.Field,
21195
+ {
21196
+ control: form.control,
21197
+ name: "amount",
21198
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
21199
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Amount" }),
21200
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
21201
+ CurrencyInput$1,
21202
+ {
21203
+ min: 0,
21204
+ placeholder: "0",
21205
+ value: field.value.value,
21206
+ onValueChange: (_value, _name, values) => {
21207
+ field.onChange({
21208
+ value: values == null ? void 0 : values.value,
21209
+ float: (values == null ? void 0 : values.float) || null
21210
+ });
21211
+ },
21212
+ symbol: currencies[storeCreditAccount.currency_code.toUpperCase()].symbol_native,
21213
+ code: storeCreditAccount.currency_code.toUpperCase()
21214
+ }
21215
+ ) }),
21216
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
21217
+ ] })
21218
+ }
21219
+ ),
21220
+ /* @__PURE__ */ jsx(
21221
+ Form$2.Field,
21222
+ {
21223
+ control: form.control,
21224
+ name: "note",
21225
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
21226
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Note" }),
21227
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Textarea, { ...field }) }),
21228
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
21229
+ ] })
21230
+ }
21231
+ )
21232
+ ] }),
21233
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
21234
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
21235
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
21236
+ ] }) })
21237
+ ]
21238
+ }
21239
+ ) });
21240
+ };
21241
+ const schema$2 = objectType({
21242
+ note: stringType(),
21243
+ amount: objectType({
21244
+ float: numberType(),
21245
+ value: stringType()
21246
+ })
21247
+ });
21230
21248
  function _extends() {
21231
21249
  return _extends = Object.assign ? Object.assign.bind() : function(n2) {
21232
21250
  for (var e2 = 1; e2 < arguments.length; e2++) {
@@ -23694,10 +23712,6 @@ const SectionRow = ({ title, value, actions }) => {
23694
23712
  const GiftCardGeneralSection = ({ giftCard }) => {
23695
23713
  var _a, _b, _c, _d, _e, _f, _g, _h, _i;
23696
23714
  const prompt = usePrompt();
23697
- useNavigate();
23698
- const { mutateAsync: redeemGiftCard, isPending } = useRedeemGiftCard(
23699
- giftCard.id
23700
- );
23701
23715
  const { mutateAsync: deleteGiftCard, isPending: isDeleting } = useDeleteGiftCard(giftCard.id);
23702
23716
  const handleDelete = async () => {
23703
23717
  const res = await prompt({
@@ -23716,8 +23730,9 @@ const GiftCardGeneralSection = ({ giftCard }) => {
23716
23730
  onError: (error) => toast.error(error.message)
23717
23731
  });
23718
23732
  };
23719
- const status = getGiftCardStatus(giftCard);
23720
- const statusColor = getGiftCardStatusColor(status);
23733
+ const hasGiftCardExpired = useMemo(() => {
23734
+ return giftCard.expires_at && new Date(giftCard.expires_at) < /* @__PURE__ */ new Date();
23735
+ }, [giftCard.expires_at]);
23721
23736
  return /* @__PURE__ */ jsxs(Container$1, { className: "divide-y p-0", children: [
23722
23737
  /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between px-6 py-4", children: [
23723
23738
  /* @__PURE__ */ jsxs("div", { children: [
@@ -23734,25 +23749,17 @@ const GiftCardGeneralSection = ({ giftCard }) => {
23734
23749
  }) })
23735
23750
  ] }),
23736
23751
  /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-4", children: [
23737
- /* @__PURE__ */ jsx(StatusBadge, { color: statusColor, children: status }),
23752
+ hasGiftCardExpired && /* @__PURE__ */ jsx(StatusBadge, { color: "orange", children: "Expired" }),
23738
23753
  /* @__PURE__ */ jsx(
23739
23754
  ActionMenu,
23740
23755
  {
23741
23756
  groups: [
23742
23757
  {
23743
23758
  actions: [
23744
- // TODO: revisit this - now GC doesn't have owner so redeeming would result in an anonymous account
23745
- // {
23746
- // icon: <Gift />,
23747
- // label: "Redeem gift card",
23748
- // onClick: () => handleRedeem(),
23749
- // disabled: isPending || giftCard.status === "redeemed",
23750
- // },
23751
23759
  {
23752
23760
  icon: /* @__PURE__ */ jsx(Calendar, {}),
23753
23761
  label: "Edit expiration date",
23754
- to: "expiration",
23755
- disabled: isPending
23762
+ to: "expiration"
23756
23763
  }
23757
23764
  ]
23758
23765
  },
@@ -23852,19 +23859,21 @@ const GiftCardNoteSection = ({ giftCard }) => {
23852
23859
  ] });
23853
23860
  };
23854
23861
  const GiftCardOrderSection = ({ giftCard }) => {
23855
- if (!giftCard || giftCard.reference !== "order") {
23856
- return;
23857
- }
23858
- const { order, isLoading, isError, error } = useOrder(giftCard.reference_id);
23862
+ const { orders, isLoading, isError, error } = useGiftCardOrders(
23863
+ giftCard == null ? void 0 : giftCard.id
23864
+ );
23859
23865
  if (isError) {
23860
23866
  throw error;
23861
23867
  }
23862
- if (isLoading) {
23868
+ if (isLoading || !orders) {
23869
+ return null;
23870
+ }
23871
+ if (orders && orders.length === 0) {
23863
23872
  return null;
23864
23873
  }
23865
23874
  return /* @__PURE__ */ jsxs(Container$1, { className: "p-0", children: [
23866
23875
  /* @__PURE__ */ jsx(Header$5, { title: "Order" }),
23867
- /* @__PURE__ */ jsx(
23876
+ orders.map((order) => /* @__PURE__ */ jsx(
23868
23877
  SidebarLink,
23869
23878
  {
23870
23879
  to: `/orders/${order.id}`,
@@ -23872,7 +23881,7 @@ const GiftCardOrderSection = ({ giftCard }) => {
23872
23881
  icon: /* @__PURE__ */ jsx(ShoppingCart, {}),
23873
23882
  descriptionKey: `Order #${order.display_id}`
23874
23883
  }
23875
- )
23884
+ ))
23876
23885
  ] });
23877
23886
  };
23878
23887
  const GiftCardTransactionsSection = ({
@@ -23922,100 +23931,6 @@ const GiftCardDetailsPage = () => {
23922
23931
  /* @__PURE__ */ jsx(Outlet, {})
23923
23932
  ] });
23924
23933
  };
23925
- const KeyboundForm = React__default.forwardRef(({ onSubmit, onKeyDown, ...rest }, ref) => {
23926
- const handleSubmit = (event) => {
23927
- event.preventDefault();
23928
- onSubmit == null ? void 0 : onSubmit(event);
23929
- };
23930
- const handleKeyDown = (event) => {
23931
- if (event.key === "Enter") {
23932
- if (event.target instanceof HTMLTextAreaElement && !(event.metaKey || event.ctrlKey)) {
23933
- return;
23934
- }
23935
- event.preventDefault();
23936
- if (event.metaKey || event.ctrlKey) {
23937
- handleSubmit(event);
23938
- }
23939
- }
23940
- };
23941
- return /* @__PURE__ */ jsx(
23942
- "form",
23943
- {
23944
- ...rest,
23945
- onSubmit: handleSubmit,
23946
- onKeyDown: onKeyDown ?? handleKeyDown,
23947
- ref
23948
- }
23949
- );
23950
- });
23951
- KeyboundForm.displayName = "KeyboundForm";
23952
- const Note = () => {
23953
- const { id } = useParams();
23954
- const {
23955
- gift_card: giftCard,
23956
- isPending,
23957
- isError,
23958
- error
23959
- } = useGiftCard(id, {});
23960
- if (isError) {
23961
- throw error;
23962
- }
23963
- const isReady = !isPending && !!giftCard;
23964
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
23965
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
23966
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit note" }) }),
23967
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the note for the gift card" }) })
23968
- ] }),
23969
- isReady && /* @__PURE__ */ jsx(GiftCardNoteForm, { giftCard })
23970
- ] });
23971
- };
23972
- const GiftCardNoteForm = ({ giftCard }) => {
23973
- const form = useForm({
23974
- defaultValues: {
23975
- note: giftCard.note ?? ""
23976
- },
23977
- resolver: t(schema$1)
23978
- });
23979
- const { mutateAsync, isPending } = useUpdateGiftCard(giftCard.id);
23980
- const { handleSuccess } = useRouteModal();
23981
- const onSubmit = form.handleSubmit(async (data) => {
23982
- await mutateAsync(
23983
- { note: data.note },
23984
- {
23985
- onSuccess: () => handleSuccess(),
23986
- onError: (error) => toast.error(error.message)
23987
- }
23988
- );
23989
- });
23990
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
23991
- KeyboundForm,
23992
- {
23993
- className: "flex flex-1 flex-col overflow-hidden",
23994
- onSubmit,
23995
- children: [
23996
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(
23997
- Form$2.Field,
23998
- {
23999
- control: form.control,
24000
- name: "note",
24001
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
24002
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Note" }),
24003
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Textarea, { ...field }) }),
24004
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
24005
- ] })
24006
- }
24007
- ) }),
24008
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
24009
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
24010
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
24011
- ] }) })
24012
- ]
24013
- }
24014
- ) });
24015
- };
24016
- const schema$1 = z.object({
24017
- note: z.string().optional()
24018
- });
24019
23934
  const GiftCardExpiration = () => {
24020
23935
  const { id } = useParams();
24021
23936
  const {
@@ -24041,7 +23956,7 @@ const GiftCardExpirationForm = ({ giftCard }) => {
24041
23956
  defaultValues: {
24042
23957
  expires_at: giftCard.expires_at ? new Date(giftCard.expires_at) : null
24043
23958
  },
24044
- resolver: t(schema)
23959
+ resolver: t(schema$1)
24045
23960
  });
24046
23961
  const { mutateAsync, isPending } = useUpdateGiftCard(giftCard.id);
24047
23962
  const { handleSuccess } = useRouteModal();
@@ -24130,8 +24045,75 @@ const GiftCardExpirationForm = ({ giftCard }) => {
24130
24045
  }
24131
24046
  ) });
24132
24047
  };
24133
- const schema = z.object({
24134
- expires_at: z.date().nullish()
24048
+ const schema$1 = objectType({
24049
+ expires_at: dateType().nullish()
24050
+ });
24051
+ const Note = () => {
24052
+ const { id } = useParams();
24053
+ const {
24054
+ gift_card: giftCard,
24055
+ isPending,
24056
+ isError,
24057
+ error
24058
+ } = useGiftCard(id, {});
24059
+ if (isError) {
24060
+ throw error;
24061
+ }
24062
+ const isReady = !isPending && !!giftCard;
24063
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
24064
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
24065
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit note" }) }),
24066
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the note for the gift card" }) })
24067
+ ] }),
24068
+ isReady && /* @__PURE__ */ jsx(GiftCardNoteForm, { giftCard })
24069
+ ] });
24070
+ };
24071
+ const GiftCardNoteForm = ({ giftCard }) => {
24072
+ const form = useForm({
24073
+ defaultValues: {
24074
+ note: giftCard.note ?? ""
24075
+ },
24076
+ resolver: t(schema)
24077
+ });
24078
+ const { mutateAsync, isPending } = useUpdateGiftCard(giftCard.id);
24079
+ const { handleSuccess } = useRouteModal();
24080
+ const onSubmit = form.handleSubmit(async (data) => {
24081
+ await mutateAsync(
24082
+ { note: data.note },
24083
+ {
24084
+ onSuccess: () => handleSuccess(),
24085
+ onError: (error) => toast.error(error.message)
24086
+ }
24087
+ );
24088
+ });
24089
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
24090
+ KeyboundForm,
24091
+ {
24092
+ className: "flex flex-1 flex-col overflow-hidden",
24093
+ onSubmit,
24094
+ children: [
24095
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(
24096
+ Form$2.Field,
24097
+ {
24098
+ control: form.control,
24099
+ name: "note",
24100
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
24101
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Note" }),
24102
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Textarea, { ...field }) }),
24103
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
24104
+ ] })
24105
+ }
24106
+ ) }),
24107
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
24108
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
24109
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
24110
+ ] }) })
24111
+ ]
24112
+ }
24113
+ ) });
24114
+ };
24115
+ const schema = objectType({
24116
+ note: stringType().optional()
24135
24117
  });
24136
24118
  const columnHelper$7 = createColumnHelper();
24137
24119
  const useGiftCardProductsTableColumns = () => {
@@ -26559,7 +26541,7 @@ instance.loadLanguages;
26559
26541
  const castNumber = (number) => {
26560
26542
  return typeof number === "string" ? Number(number.replace(",", ".")) : number;
26561
26543
  };
26562
- const optionalInt = z.union([z.string(), z.number()]).optional().refine(
26544
+ const optionalInt = unionType([stringType(), numberType()]).optional().refine(
26563
26545
  (value) => {
26564
26546
  if (value === "" || value === void 0) {
26565
26547
  return true;
@@ -26580,7 +26562,7 @@ const optionalInt = z.union([z.string(), z.number()]).optional().refine(
26580
26562
  message: instance.t("validation.mustBePositive")
26581
26563
  }
26582
26564
  );
26583
- const optionalFloat = z.union([z.string(), z.number()]).optional().refine(
26565
+ const optionalFloat = unionType([stringType(), numberType()]).optional().refine(
26584
26566
  (value) => {
26585
26567
  if (value === "" || value === void 0) {
26586
26568
  return true;
@@ -26591,13 +26573,13 @@ const optionalFloat = z.union([z.string(), z.number()]).optional().refine(
26591
26573
  message: instance.t("validation.mustBePositive")
26592
26574
  }
26593
26575
  );
26594
- z.array(
26595
- z.object({
26596
- key: z.string(),
26597
- value: z.unknown(),
26598
- isInitial: z.boolean().optional(),
26599
- isDeleted: z.boolean().optional(),
26600
- isIgnored: z.boolean().optional()
26576
+ arrayType(
26577
+ objectType({
26578
+ key: stringType(),
26579
+ value: unknownType(),
26580
+ isInitial: booleanType().optional(),
26581
+ isDeleted: booleanType().optional(),
26582
+ isIgnored: booleanType().optional()
26601
26583
  })
26602
26584
  );
26603
26585
  const normalizeProductFormValues = (values) => {
@@ -36387,81 +36369,81 @@ const useSalesChannelTableQuery = ({
36387
36369
  return searchParams;
36388
36370
  };
36389
36371
  const SC_STACKED_MODAL_ID = "sc";
36390
- const MediaSchema = z.object({
36391
- id: z.string().optional(),
36392
- url: z.string(),
36393
- isThumbnail: z.boolean(),
36394
- file: z.any().nullable()
36372
+ const MediaSchema = objectType({
36373
+ id: stringType().optional(),
36374
+ url: stringType(),
36375
+ isThumbnail: booleanType(),
36376
+ file: anyType().nullable()
36395
36377
  // File
36396
36378
  });
36397
- z.object({
36398
- should_create: z.boolean(),
36399
- is_default: z.boolean().optional(),
36400
- title: z.string(),
36401
- upc: z.string().optional(),
36402
- ean: z.string().optional(),
36403
- barcode: z.string().optional(),
36404
- mid_code: z.string().optional(),
36405
- hs_code: z.string().optional(),
36379
+ objectType({
36380
+ should_create: booleanType(),
36381
+ is_default: booleanType().optional(),
36382
+ title: stringType(),
36383
+ upc: stringType().optional(),
36384
+ ean: stringType().optional(),
36385
+ barcode: stringType().optional(),
36386
+ mid_code: stringType().optional(),
36387
+ hs_code: stringType().optional(),
36406
36388
  width: optionalInt,
36407
36389
  height: optionalInt,
36408
36390
  length: optionalInt,
36409
36391
  weight: optionalInt,
36410
- material: z.string().optional(),
36411
- origin_country: z.string().optional(),
36412
- manage_inventory: z.boolean().optional(),
36413
- allow_backorder: z.boolean().optional(),
36414
- inventory_kit: z.boolean().optional(),
36415
- options: z.record(z.string(), z.string()),
36416
- variant_rank: z.number(),
36417
- prices: z.record(z.string(), optionalFloat).optional(),
36418
- inventory: z.array(
36419
- z.object({
36420
- inventory_item_id: z.string(),
36392
+ material: stringType().optional(),
36393
+ origin_country: stringType().optional(),
36394
+ manage_inventory: booleanType().optional(),
36395
+ allow_backorder: booleanType().optional(),
36396
+ inventory_kit: booleanType().optional(),
36397
+ options: recordType(stringType(), stringType()),
36398
+ variant_rank: numberType(),
36399
+ prices: recordType(stringType(), optionalFloat).optional(),
36400
+ inventory: arrayType(
36401
+ objectType({
36402
+ inventory_item_id: stringType(),
36421
36403
  required_quantity: optionalInt
36422
36404
  })
36423
36405
  ).optional()
36424
36406
  });
36425
- z.object({
36426
- title: z.string(),
36427
- values: z.array(z.string()).min(1)
36407
+ objectType({
36408
+ title: stringType(),
36409
+ values: arrayType(stringType()).min(1)
36428
36410
  });
36429
- const ProductCreateSchema = z.object({
36430
- title: z.string().min(1),
36431
- subtitle: z.string().optional(),
36432
- handle: z.string().optional(),
36433
- description: z.string().optional(),
36434
- discountable: z.boolean(),
36435
- type_id: z.string().optional(),
36436
- collection_id: z.string().optional(),
36437
- shipping_profile_id: z.string().optional(),
36438
- categories: z.array(z.string()),
36439
- tags: z.array(z.string()).optional(),
36440
- sales_channels: z.array(
36441
- z.object({
36442
- id: z.string(),
36443
- name: z.string()
36411
+ const ProductCreateSchema = objectType({
36412
+ title: stringType().min(1),
36413
+ subtitle: stringType().optional(),
36414
+ handle: stringType().optional(),
36415
+ description: stringType().optional(),
36416
+ discountable: booleanType(),
36417
+ type_id: stringType().optional(),
36418
+ collection_id: stringType().optional(),
36419
+ shipping_profile_id: stringType().optional(),
36420
+ categories: arrayType(stringType()),
36421
+ tags: arrayType(stringType()).optional(),
36422
+ sales_channels: arrayType(
36423
+ objectType({
36424
+ id: stringType(),
36425
+ name: stringType()
36444
36426
  })
36445
36427
  ).optional(),
36446
- origin_country: z.string().optional(),
36447
- material: z.string().optional(),
36448
- width: z.string().optional(),
36449
- length: z.string().optional(),
36450
- height: z.string().optional(),
36451
- weight: z.string().optional(),
36452
- mid_code: z.string().optional(),
36453
- hs_code: z.string().optional(),
36454
- denominations: z.array(
36455
- z.object({
36456
- value: z.string().min(1),
36457
- prices: z.record(z.string(), optionalFloat).optional()
36428
+ origin_country: stringType().optional(),
36429
+ material: stringType().optional(),
36430
+ width: stringType().optional(),
36431
+ length: stringType().optional(),
36432
+ height: stringType().optional(),
36433
+ weight: stringType().optional(),
36434
+ mid_code: stringType().optional(),
36435
+ hs_code: stringType().optional(),
36436
+ denominations: arrayType(
36437
+ objectType({
36438
+ value: stringType().min(1),
36439
+ prices: recordType(stringType(), optionalFloat).optional()
36458
36440
  })
36459
36441
  ).min(1),
36460
- enable_variants: z.boolean(),
36461
- media: z.array(MediaSchema).optional()
36442
+ enable_variants: booleanType(),
36443
+ media: arrayType(MediaSchema).optional()
36462
36444
  });
36463
- const EditProductMediaSchema = z.object({
36464
- media: z.array(MediaSchema)
36445
+ const EditProductMediaSchema = objectType({
36446
+ media: arrayType(MediaSchema)
36465
36447
  });
36466
36448
  const PRODUCT_CREATE_FORM_DEFAULTS = {
36467
36449
  discountable: true,
@@ -37414,12 +37396,159 @@ const ProductDetail = () => {
37414
37396
  /* @__PURE__ */ jsx(Outlet, {})
37415
37397
  ] });
37416
37398
  };
37417
- const EditProductSchema$1 = z.object({
37418
- status: z.enum(["draft", "published", "proposed", "rejected"]),
37419
- title: z.string().min(1),
37420
- subtitle: z.string().optional(),
37421
- handle: z.string().min(1),
37422
- description: z.string().optional()
37399
+ const EditProductSchema$1 = objectType({
37400
+ denominations: arrayType(
37401
+ objectType({
37402
+ id: stringType().optional(),
37403
+ value: stringType().min(1),
37404
+ prices: recordType(stringType(), optionalFloat).optional()
37405
+ })
37406
+ ).min(1)
37407
+ });
37408
+ const GiftCardProductEditDenominationsForm = ({
37409
+ product
37410
+ }) => {
37411
+ var _a;
37412
+ const { handleSuccess } = useRouteModal();
37413
+ const form = useForm({
37414
+ defaultValues: {
37415
+ denominations: (_a = product.variants) == null ? void 0 : _a.map((variant) => ({
37416
+ id: variant.id,
37417
+ value: variant.title
37418
+ }))
37419
+ },
37420
+ resolver: t(EditProductSchema$1)
37421
+ });
37422
+ const { mutateAsync, isPending } = useUpdateProduct(product.id);
37423
+ const handleSubmit = form.handleSubmit(async (data) => {
37424
+ const optionValues = data.denominations.map(
37425
+ (denomination) => denomination.value
37426
+ );
37427
+ const options = [
37428
+ {
37429
+ title: "denomination",
37430
+ values: optionValues
37431
+ }
37432
+ ];
37433
+ await mutateAsync(
37434
+ {
37435
+ options,
37436
+ variants: data.denominations.map((denomination) => ({
37437
+ id: denomination.id,
37438
+ title: denomination.value,
37439
+ manage_inventory: false,
37440
+ options: {
37441
+ denomination: denomination.value
37442
+ }
37443
+ }))
37444
+ },
37445
+ {
37446
+ onSuccess: () => {
37447
+ toast.success(`Denominations updated successfully`);
37448
+ handleSuccess();
37449
+ },
37450
+ onError: (e2) => {
37451
+ toast.error(e2.message);
37452
+ }
37453
+ }
37454
+ );
37455
+ });
37456
+ const {
37457
+ fields: denominationsFields,
37458
+ append: addDenomination,
37459
+ remove: removeDenomination
37460
+ } = useFieldArray({
37461
+ name: "denominations",
37462
+ control: form.control
37463
+ });
37464
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
37465
+ KeyboundForm,
37466
+ {
37467
+ onSubmit: handleSubmit,
37468
+ className: "flex flex-1 flex-col overflow-hidden",
37469
+ children: [
37470
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-y-6", children: /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-2", children: [
37471
+ denominationsFields.map((denominationField, index) => {
37472
+ return /* @__PURE__ */ jsxs(
37473
+ "div",
37474
+ {
37475
+ className: "flex items-center justify-between shadow-elevation-card-rest bg-ui-bg-component transition-fg rounded-md px-4 py-2",
37476
+ children: [
37477
+ /* @__PURE__ */ jsx(
37478
+ Form$2.Field,
37479
+ {
37480
+ control: form.control,
37481
+ name: `denominations.${index}.value`,
37482
+ render: ({ field }) => {
37483
+ return /* @__PURE__ */ jsxs(Form$2.Item, { className: "w-full", children: [
37484
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field, placeholder: "100" }) }),
37485
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
37486
+ ] });
37487
+ }
37488
+ },
37489
+ denominationField.id
37490
+ ),
37491
+ /* @__PURE__ */ jsx("div", { className: "flex items-center rounded-xl", children: /* @__PURE__ */ jsx(
37492
+ Button,
37493
+ {
37494
+ size: "small",
37495
+ variant: "secondary",
37496
+ type: "button",
37497
+ className: "rounded-full p-0 ml-4",
37498
+ onClick: () => {
37499
+ removeDenomination(index);
37500
+ },
37501
+ children: /* @__PURE__ */ jsx(XCircleSolid, { className: "rounded-full" })
37502
+ }
37503
+ ) })
37504
+ ]
37505
+ },
37506
+ denominationField.id
37507
+ );
37508
+ }),
37509
+ /* @__PURE__ */ jsx(
37510
+ Button,
37511
+ {
37512
+ size: "small",
37513
+ variant: "secondary",
37514
+ type: "button",
37515
+ className: "w-full",
37516
+ onClick: () => {
37517
+ addDenomination({ value: "", prices: {} });
37518
+ },
37519
+ children: "Add denomination"
37520
+ }
37521
+ ),
37522
+ form.formState.errors.denominations && /* @__PURE__ */ jsx(Alert, { variant: "error", children: "Please add at least one denomination." })
37523
+ ] }) }) }) }),
37524
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
37525
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
37526
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
37527
+ ] }) })
37528
+ ]
37529
+ }
37530
+ ) });
37531
+ };
37532
+ const GiftCardProductEdit$1 = () => {
37533
+ const { id } = useParams();
37534
+ const { product, isLoading, isError, error } = useProduct(id, {});
37535
+ if (isError) {
37536
+ throw error;
37537
+ }
37538
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
37539
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
37540
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit gift cards denominations" }) }),
37541
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { className: "sr-only", children: "Edit the gift card denominations" })
37542
+ ] }),
37543
+ !isLoading && product && /* @__PURE__ */ jsx(GiftCardProductEditDenominationsForm, { product })
37544
+ ] });
37545
+ };
37546
+ const EditProductSchema = objectType({
37547
+ status: enumType(["draft", "published", "proposed", "rejected"]),
37548
+ title: stringType().min(1),
37549
+ subtitle: stringType().optional(),
37550
+ handle: stringType().min(1),
37551
+ description: stringType().optional()
37423
37552
  });
37424
37553
  const GiftCardProductEditForm = ({
37425
37554
  product
@@ -37433,7 +37562,7 @@ const GiftCardProductEditForm = ({
37433
37562
  handle: product.handle || "",
37434
37563
  description: product.description || ""
37435
37564
  },
37436
- resolver: t(EditProductSchema$1)
37565
+ resolver: t(EditProductSchema)
37437
37566
  });
37438
37567
  const { mutateAsync, isPending } = useUpdateProduct(product.id);
37439
37568
  const handleSubmit = form.handleSubmit(async (data) => {
@@ -37574,7 +37703,7 @@ const GiftCardProductEditForm = ({
37574
37703
  }
37575
37704
  ) });
37576
37705
  };
37577
- const GiftCardProductEdit$1 = () => {
37706
+ const GiftCardProductEdit = () => {
37578
37707
  const { id } = useParams();
37579
37708
  const { product, isLoading, isError, error } = useProduct(id, {});
37580
37709
  if (isError) {
@@ -37588,152 +37717,6 @@ const GiftCardProductEdit$1 = () => {
37588
37717
  !isLoading && product && /* @__PURE__ */ jsx(GiftCardProductEditForm, { product })
37589
37718
  ] });
37590
37719
  };
37591
- const EditProductSchema = z.object({
37592
- denominations: z.array(
37593
- z.object({
37594
- id: z.string().optional(),
37595
- value: z.string().min(1),
37596
- prices: z.record(z.string(), optionalFloat).optional()
37597
- })
37598
- ).min(1)
37599
- });
37600
- const GiftCardProductEditDenominationsForm = ({
37601
- product
37602
- }) => {
37603
- var _a;
37604
- const { handleSuccess } = useRouteModal();
37605
- const form = useForm({
37606
- defaultValues: {
37607
- denominations: (_a = product.variants) == null ? void 0 : _a.map((variant) => ({
37608
- id: variant.id,
37609
- value: variant.title
37610
- }))
37611
- },
37612
- resolver: t(EditProductSchema)
37613
- });
37614
- const { mutateAsync, isPending } = useUpdateProduct(product.id);
37615
- const handleSubmit = form.handleSubmit(async (data) => {
37616
- const optionValues = data.denominations.map(
37617
- (denomination) => denomination.value
37618
- );
37619
- const options = [
37620
- {
37621
- title: "denomination",
37622
- values: optionValues
37623
- }
37624
- ];
37625
- await mutateAsync(
37626
- {
37627
- options,
37628
- variants: data.denominations.map((denomination) => ({
37629
- id: denomination.id,
37630
- title: denomination.value,
37631
- options: {
37632
- denomination: denomination.value
37633
- }
37634
- }))
37635
- },
37636
- {
37637
- onSuccess: () => {
37638
- toast.success(`Denominations updated successfully`);
37639
- handleSuccess();
37640
- },
37641
- onError: (e2) => {
37642
- toast.error(e2.message);
37643
- }
37644
- }
37645
- );
37646
- });
37647
- const {
37648
- fields: denominationsFields,
37649
- append: addDenomination,
37650
- remove: removeDenomination
37651
- } = useFieldArray({
37652
- name: "denominations",
37653
- control: form.control
37654
- });
37655
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
37656
- KeyboundForm,
37657
- {
37658
- onSubmit: handleSubmit,
37659
- className: "flex flex-1 flex-col overflow-hidden",
37660
- children: [
37661
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-y-6", children: /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-2", children: [
37662
- denominationsFields.map((denominationField, index) => {
37663
- return /* @__PURE__ */ jsxs(
37664
- "div",
37665
- {
37666
- className: "flex items-center justify-between shadow-elevation-card-rest bg-ui-bg-component transition-fg rounded-md px-4 py-2",
37667
- children: [
37668
- /* @__PURE__ */ jsx(
37669
- Form$2.Field,
37670
- {
37671
- control: form.control,
37672
- name: `denominations.${index}.value`,
37673
- render: ({ field }) => {
37674
- return /* @__PURE__ */ jsxs(Form$2.Item, { className: "w-full", children: [
37675
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field, placeholder: "100" }) }),
37676
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
37677
- ] });
37678
- }
37679
- },
37680
- denominationField.id
37681
- ),
37682
- /* @__PURE__ */ jsx("div", { className: "flex items-center rounded-xl", children: /* @__PURE__ */ jsx(
37683
- Button,
37684
- {
37685
- size: "small",
37686
- variant: "secondary",
37687
- type: "button",
37688
- className: "rounded-full p-0 ml-4",
37689
- onClick: () => {
37690
- removeDenomination(index);
37691
- },
37692
- children: /* @__PURE__ */ jsx(XCircleSolid, { className: "rounded-full" })
37693
- }
37694
- ) })
37695
- ]
37696
- },
37697
- denominationField.id
37698
- );
37699
- }),
37700
- /* @__PURE__ */ jsx(
37701
- Button,
37702
- {
37703
- size: "small",
37704
- variant: "secondary",
37705
- type: "button",
37706
- className: "w-full",
37707
- onClick: () => {
37708
- addDenomination({ value: "", prices: {} });
37709
- },
37710
- children: "Add denomination"
37711
- }
37712
- ),
37713
- form.formState.errors.denominations && /* @__PURE__ */ jsx(Alert, { variant: "error", children: "Please add at least one denomination." })
37714
- ] }) }) }) }),
37715
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
37716
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
37717
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
37718
- ] }) })
37719
- ]
37720
- }
37721
- ) });
37722
- };
37723
- const GiftCardProductEdit = () => {
37724
- const { id } = useParams();
37725
- const { product, isLoading, isError, error } = useProduct(id, {});
37726
- if (isError) {
37727
- throw error;
37728
- }
37729
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
37730
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
37731
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit gift cards denominations" }) }),
37732
- /* @__PURE__ */ jsx(RouteDrawer.Description, { className: "sr-only", children: "Edit the gift card denominations" })
37733
- ] }),
37734
- !isLoading && product && /* @__PURE__ */ jsx(GiftCardProductEditDenominationsForm, { product })
37735
- ] });
37736
- };
37737
37720
  const EditProductMediaForm = ({ product }) => {
37738
37721
  const [selection, setSelection] = useState({});
37739
37722
  const { handleSuccess } = useRouteModal();
@@ -38649,19 +38632,25 @@ const routeModule = {
38649
38632
  },
38650
38633
  {
38651
38634
  Component: StoreCreditAccountPage,
38652
- path: "/store-credit-accounts/:id"
38635
+ path: "/store-credit-accounts/:id",
38636
+ children: [
38637
+ {
38638
+ Component: Note$1,
38639
+ path: "/store-credit-accounts/:id/credit"
38640
+ }
38641
+ ]
38653
38642
  },
38654
38643
  {
38655
38644
  Component: GiftCardDetailsPage,
38656
38645
  path: "/gift-cards/:id",
38657
38646
  children: [
38658
- {
38659
- Component: Note,
38660
- path: "/gift-cards/:id/note"
38661
- },
38662
38647
  {
38663
38648
  Component: GiftCardExpiration,
38664
38649
  path: "/gift-cards/:id/expiration"
38650
+ },
38651
+ {
38652
+ Component: Note,
38653
+ path: "/gift-cards/:id/note"
38665
38654
  }
38666
38655
  ]
38667
38656
  },
@@ -38681,11 +38670,11 @@ const routeModule = {
38681
38670
  children: [
38682
38671
  {
38683
38672
  Component: GiftCardProductEdit$1,
38684
- path: "/gift-cards/gift-card-products/:id/edit"
38673
+ path: "/gift-cards/gift-card-products/:id/denominations"
38685
38674
  },
38686
38675
  {
38687
38676
  Component: GiftCardProductEdit,
38688
- path: "/gift-cards/gift-card-products/:id/denominations"
38677
+ path: "/gift-cards/gift-card-products/:id/edit"
38689
38678
  }
38690
38679
  ]
38691
38680
  },