@01.software/sdk 0.31.0 → 0.33.0

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 (52) hide show
  1. package/README.md +128 -47
  2. package/dist/analytics/react.cjs.map +1 -1
  3. package/dist/analytics/react.js.map +1 -1
  4. package/dist/analytics.cjs.map +1 -1
  5. package/dist/analytics.js.map +1 -1
  6. package/dist/client.cjs +41 -48
  7. package/dist/client.cjs.map +1 -1
  8. package/dist/client.d.cts +6 -6
  9. package/dist/client.d.ts +6 -6
  10. package/dist/client.js +41 -48
  11. package/dist/client.js.map +1 -1
  12. package/dist/{collection-client-ByzY3hWK.d.ts → collection-client-B6SlhzIP.d.ts} +3 -3
  13. package/dist/{collection-client-DFXXz0vk.d.cts → collection-client-De6eKW1J.d.cts} +3 -3
  14. package/dist/{const-AytzliEu.d.cts → const-DwmSDeWq.d.ts} +2 -2
  15. package/dist/{const-BGCP-OJL.d.ts → const-sPR2IkCe.d.cts} +2 -2
  16. package/dist/index.cjs +310 -133
  17. package/dist/index.cjs.map +1 -1
  18. package/dist/index.d.cts +7 -7
  19. package/dist/index.d.ts +7 -7
  20. package/dist/index.js +310 -133
  21. package/dist/index.js.map +1 -1
  22. package/dist/{payload-types-Wa4-eC6x.d.cts → payload-types-dkeQyrDC.d.cts} +1572 -1440
  23. package/dist/{payload-types-Wa4-eC6x.d.ts → payload-types-dkeQyrDC.d.ts} +1572 -1440
  24. package/dist/query.cjs.map +1 -1
  25. package/dist/query.d.cts +20 -20
  26. package/dist/query.d.ts +20 -20
  27. package/dist/query.js.map +1 -1
  28. package/dist/realtime.cjs.map +1 -1
  29. package/dist/realtime.d.cts +2 -2
  30. package/dist/realtime.d.ts +2 -2
  31. package/dist/realtime.js.map +1 -1
  32. package/dist/server.cjs +70 -6
  33. package/dist/server.cjs.map +1 -1
  34. package/dist/server.d.cts +100 -8
  35. package/dist/server.d.ts +100 -8
  36. package/dist/server.js +70 -6
  37. package/dist/server.js.map +1 -1
  38. package/dist/{types-CmLG-7RL.d.cts → types-B3YT092I.d.cts} +1 -1
  39. package/dist/{types-BX2mqDf6.d.ts → types-BHh0YLmq.d.ts} +63 -13
  40. package/dist/{types-DChFjQGz.d.cts → types-BZKxss8Y.d.cts} +63 -13
  41. package/dist/{types-CVA10VC-.d.ts → types-Cel_4L9t.d.ts} +1 -1
  42. package/dist/ui/form.d.cts +1 -1
  43. package/dist/ui/form.d.ts +1 -1
  44. package/dist/ui/video.d.cts +1 -1
  45. package/dist/ui/video.d.ts +1 -1
  46. package/dist/webhook.cjs +142 -1
  47. package/dist/webhook.cjs.map +1 -1
  48. package/dist/webhook.d.cts +149 -5
  49. package/dist/webhook.d.ts +149 -5
  50. package/dist/webhook.js +142 -1
  51. package/dist/webhook.js.map +1 -1
  52. package/package.json +3 -3
@@ -1,4 +1,4 @@
1
- import { P as Product, C as CustomerProfile, a as CustomerProfileList, b as ProductCollection, c as Post, d as Comment, R as Reaction, e as Config } from './payload-types-Wa4-eC6x.cjs';
1
+ import { P as Product, C as CustomerProfile, a as CustomerProfileList, b as ProductCollection, c as Post, d as Comment, R as Reaction, e as Config } from './payload-types-dkeQyrDC.cjs';
2
2
 
3
3
  type PublicCustomerProfile = Omit<CustomerProfile, 'tenant' | 'customer' | 'isPublic' | 'anonymizedAt' | 'metadata'>;
4
4
  type PublicProfileRelation = string | PublicCustomerProfile;
@@ -1,6 +1,6 @@
1
- import { P as PublicCollection } from './const-BGCP-OJL.js';
2
- import { P as PublicProduct, C as CollectionType } from './types-CVA10VC-.js';
3
- import { O as Order, i as Cart, j as CartItem, m as OrderItem, n as Transaction, o as Fulfillment, p as Return } from './payload-types-Wa4-eC6x.js';
1
+ import { P as PublicCollection } from './const-DwmSDeWq.js';
2
+ import { P as PublicProduct, C as CollectionType } from './types-Cel_4L9t.js';
3
+ import { O as Order, i as Cart, j as CartItem, m as Transaction, n as Fulfillment, o as Return } from './payload-types-dkeQyrDC.js';
4
4
 
5
5
  interface CommunityClientOptions {
6
6
  publishableKey?: string;
@@ -504,10 +504,12 @@ type ProductListingSwatch = {
504
504
  href: string;
505
505
  availableForSale: boolean;
506
506
  };
507
+ type ProductListingCardRepresentativeVariant = ProductListingGroupsItem['groups'][number]['variants'][number];
507
508
  type ProductListingCard = {
508
509
  id: EntityID;
509
510
  href: string;
510
511
  title: string;
512
+ representativeVariant?: ProductListingCardRepresentativeVariant | null;
511
513
  primaryImage: ProductDetailMedia | null;
512
514
  priceRange: ProductListingCardPriceRange;
513
515
  availableForSale: boolean;
@@ -666,8 +668,10 @@ type StockCheckParams = {
666
668
  };
667
669
  type StockCheckResult = {
668
670
  variantId: string;
671
+ status: 'available' | 'not_published' | 'archived' | 'not_found';
669
672
  available: boolean;
670
673
  availableStock: number;
674
+ isUnlimited: boolean;
671
675
  requestedQuantity: number;
672
676
  error?: string;
673
677
  };
@@ -678,19 +682,33 @@ type StockCheckResponse = {
678
682
  type ListingGroupsParams = {
679
683
  productIds: string[];
680
684
  };
681
- type ProductListingGroupSummary = Omit<ProductListingGroup, 'variants'>;
682
- type ProductListingGroupsProduct = PublicProduct & {
685
+ type ListingGroupingState = 'grouped' | 'no_primary_option' | 'empty';
686
+ type ProductListingGroupVariant = Pick<ProductVariantShape, 'id' | 'optionValues' | 'price' | 'compareAtPrice' | 'stock' | 'isUnlimited' | 'isActive' | 'thumbnail' | 'images' | '_order'>;
687
+ type ProductListingGroupSummary = ProductListingGroup<ProductListingGroupVariant>;
688
+ type ProductListingGroupsProductVariants = NonNullable<PublicProduct['variants']>;
689
+ type ProductListingGroupsProduct = Omit<PublicProduct, 'variants'> & {
683
690
  id: string;
684
691
  slug: string;
685
692
  title: string;
693
+ variants?: (Omit<ProductListingGroupsProductVariants, 'docs'> & {
694
+ docs: ProductListingGroupVariant[];
695
+ }) | null;
686
696
  };
687
697
  type ProductListingGroupsItem = {
688
698
  product: ProductListingGroupsProduct;
689
699
  primaryOptionId: string | null;
700
+ listingGroupingState: ListingGroupingState;
690
701
  groups: ProductListingGroupSummary[];
691
702
  };
692
703
  type ProductListingGroupsResponse = {
704
+ /**
705
+ * Matching products in the same order as the requested productIds, excluding
706
+ * ids that were not found, not published, or not accessible for the current
707
+ * tenant/key.
708
+ */
693
709
  docs: ProductListingGroupsItem[];
710
+ /** Requested productIds that could not be returned. */
711
+ missing: string[];
694
712
  };
695
713
  type ProductDetailParams = {
696
714
  slug: string;
@@ -794,8 +812,9 @@ interface ProductDetail {
794
812
  content?: unknown;
795
813
  publishedAt?: string | null;
796
814
  status: string;
797
- totalInventory: number;
815
+ totalInventory: number | null;
798
816
  totalVariants: number;
817
+ hasUnlimitedVariant: boolean;
799
818
  hasOnlyDefaultVariant: boolean;
800
819
  };
801
820
  variants: ProductDetailVariant[];
@@ -807,6 +826,14 @@ interface ProductDetail {
807
826
  videos: ProductDetailVideo[];
808
827
  listing: ProductDetailListing;
809
828
  }
829
+ type ProductDetailUnavailableReason = 'not_found' | 'not_published' | 'feature_disabled';
830
+ type ProductDetailResult = {
831
+ found: true;
832
+ product: ProductDetail;
833
+ } | {
834
+ found: false;
835
+ reason: ProductDetailUnavailableReason;
836
+ };
810
837
  type ProductUpsertOptionValueInput = {
811
838
  id?: string;
812
839
  value: string;
@@ -873,11 +900,15 @@ declare class ProductApi extends BaseApi {
873
900
  listingGroups(params: ListingGroupsParams): Promise<ProductListingGroupsResponse>;
874
901
  /**
875
902
  * Fetch full product detail by slug or id.
876
- * Returns `null` on 404 regardless of reason (`not_found` / `not_published` /
877
- * `tenant_mismatch` / `feature_disabled`). For the reason behind a null,
878
- * inspect `client.lastRequestId` against backend logs.
903
+ * Returns a discriminated result so storefronts can distinguish missing,
904
+ * unpublished, and feature-disabled products.
905
+ *
906
+ * Only product-detail 404 responses carrying one of those allowlisted reasons
907
+ * are mapped to `{ found: false, reason }`. Unknown or uncoded 404s, plus
908
+ * permission/auth errors such as tenant mismatch, continue to throw typed SDK
909
+ * errors instead of being collapsed into a storefront absence result.
879
910
  */
880
- detail(params: ProductDetailParams): Promise<ProductDetail | null>;
911
+ detail(params: ProductDetailParams): Promise<ProductDetailResult>;
881
912
  /**
882
913
  * Atomically create or update a product together with its options,
883
914
  * option-values, and variants in a single transaction. Mirrors Shopify's
@@ -936,12 +967,29 @@ type ReturnItem = {
936
967
  orderItem: string;
937
968
  quantity: number;
938
969
  };
970
+ type OrderCreateEntityID = string | number;
971
+ type CreateOrderItem = {
972
+ product: OrderCreateEntityID;
973
+ variant: OrderCreateEntityID;
974
+ option: OrderCreateEntityID;
975
+ quantity: number;
976
+ /**
977
+ * Compatibility input: the create-order endpoint accepts this, but the server
978
+ * derives authoritative line pricing from the product variant.
979
+ */
980
+ unitPrice?: number;
981
+ /**
982
+ * Compatibility input: the create-order endpoint accepts this, but the server
983
+ * derives authoritative line totals from the product variant.
984
+ */
985
+ totalPrice?: number;
986
+ };
939
987
  type CreateOrderParams = {
940
988
  orderNumber: string;
941
989
  customer?: string;
942
990
  customerSnapshot: CustomerSnapshot;
943
991
  shippingAddress: Order['shippingAddress'];
944
- orderItems: Pick<OrderItem, 'product' | 'variant' | 'quantity' | 'unitPrice' | 'totalPrice'>[];
992
+ orderItems: CreateOrderItem[];
945
993
  totalAmount: number;
946
994
  shippingAmount?: number;
947
995
  pgPaymentId?: string;
@@ -986,6 +1034,7 @@ type ReturnWithRefundItem = {
986
1034
  orderItem: string | number;
987
1035
  quantity: number;
988
1036
  restockAction?: RestockAction;
1037
+ restockingFee?: number;
989
1038
  };
990
1039
  type ReturnWithRefundParams = {
991
1040
  orderNumber: string;
@@ -993,6 +1042,7 @@ type ReturnWithRefundParams = {
993
1042
  reasonDetail?: string;
994
1043
  returnItems: ReturnWithRefundItem[];
995
1044
  refundAmount: number;
1045
+ returnShippingFee?: number;
996
1046
  pgPaymentId: string;
997
1047
  paymentKey?: string;
998
1048
  refundReceiptUrl?: string;
@@ -1077,7 +1127,7 @@ declare class CommerceClient {
1077
1127
  readonly product: {
1078
1128
  stockCheck: (params: StockCheckParams) => Promise<StockCheckResponse>;
1079
1129
  listingGroups: (params: ListingGroupsParams) => Promise<ProductListingGroupsResponse>;
1080
- detail: (params: ProductDetailParams) => Promise<ProductDetail | null>;
1130
+ detail: (params: ProductDetailParams) => Promise<ProductDetailResult>;
1081
1131
  };
1082
1132
  readonly cart: {
1083
1133
  get: (cartId: string) => Promise<Cart>;
@@ -1286,4 +1336,4 @@ type DeepPartial<T> = {
1286
1336
  };
1287
1337
  type ExtractArrayType<T> = T extends (infer U)[] ? U : never;
1288
1338
 
1289
- export { type OrderApiOptions as $, type ApiQueryOptions as A, BaseApi as B, CommerceClient as C, type DebugConfig as D, type ExtractArrayType as E, type CreateFulfillmentParams as F, type CreateOrderParams as G, type CreateReturnParams as H, CustomerAuth as I, type CustomerAuthOptions as J, type CustomerAuthResponse as K, type CustomerLoginData as L, type CustomerProfile as M, type CustomerRefreshResponse as N, type CustomerRegisterData as O, type PayloadFindResponse as P, type CustomerRegisterResponse as Q, type RetryConfig as R, type Sort as S, type CustomerSnapshot as T, DiscountApi as U, type DiscountApiOptions as V, type Where as W, type LegacyProductSelectionParamEvent as X, type ListingGroupsParams as Y, type NormalizedProductSelection as Z, OrderApi as _, CommunityClient as a, buildProductHref as a$, ProductApi as a0, type ProductApiOptions as a1, type ProductDetail as a2, type ProductDetailBrand as a3, type ProductDetailCategory as a4, type ProductDetailImage as a5, type ProductDetailImageMedia as a6, type ProductDetailListing as a7, type ProductDetailMedia as a8, type ProductDetailOption as a9, type ProductSelectionByOptionValue as aA, ProductSelectionCodecError as aB, type ProductSelectionCodecOptions as aC, type ProductSelectionInput as aD, type ProductSelectionResolution as aE, type ProductSelectionResolutionContext as aF, type ProductVariantShape as aG, type RemoveDiscountParams as aH, type RemoveItemParams as aI, type RequestOptions as aJ, type ReturnItem as aK, type ReturnReason as aL, type ReturnWithRefundParams as aM, type ServerApiOptions as aN, ShippingApi as aO, type ShippingApiOptions as aP, type StockCheckParams as aQ, type StockCheckResponse as aR, type StockCheckResult as aS, type UpdateFulfillmentParams as aT, type UpdateItemParams as aU, type UpdateOrderParams as aV, type UpdateProfileData as aW, type UpdateReturnParams as aX, type UpdateTransactionParams as aY, type ValidateDiscountParams as aZ, type ValidateDiscountResult as a_, type ProductDetailOptionValue as aa, type ProductDetailParams as ab, type ProductDetailTag as ac, type ProductDetailVariant as ad, type ProductDetailVariantOptionValue as ae, type ProductDetailVideo as af, type ProductHrefGroup as ag, type ProductHrefOptions as ah, type ProductHrefProduct as ai, type ProductListingCard as aj, type ProductListingCardPriceRange as ak, type ProductListingGroup as al, type ProductListingGroupSummary as am, type ProductListingGroupsItem as an, type ProductListingGroupsProduct as ao, type ProductListingGroupsResponse as ap, type ProductListingProductShape as aq, type ProductListingProjection as ar, type ProductListingSwatch as as, type ProductOptionMatrix as at, type ProductOptionMatrixOption as au, type ProductOptionMatrixValue as av, type ProductOptionMatrixVariant as aw, type ProductOptionShape as ax, type ProductOptionValueShape as ay, type ProductSelectionAvailableValue as az, CustomerNamespace as b, buildProductListingCard as b0, buildProductListingGroupsByOption as b1, buildProductListingProjection as b2, buildProductOptionMatrix as b3, buildProductOptionMatrixFromDetail as b4, createProductSelectionCodec as b5, getAvailableOptionValues as b6, getProductSelectionImages as b7, getSelectedValueByOptionId as b8, normalizeProductSelection as b9, normalizeProductSelectionFromMatrix as ba, normalizeSelectedValueIds as bb, parseProductSelection as bc, resolveProductSelection as bd, resolveProductSelectionFromMatrix as be, resolveVariantForSelection as bf, stringifyProductSelection as bg, type ProductDetailPreviewParams as bh, type ProductDetailPreviewOptions as bi, type ProductUpsertParams as bj, type ProductUpsertResponse as bk, type ClientServerConfig as bl, type ClientState as c, type ClientConfig as d, type ClientMetadata as e, type DeepPartial as f, type PayloadMutationResponse as g, type RootClient as h, type RootCollectionClient as i, type RootReadOnlyQueryBuilder as j, type AddItemParams as k, type ApplyDiscountParams as l, type BulkImportFulfillmentsParams as m, type BulkImportFulfillmentsResponse as n, type CalculateShippingParams as o, type CalculateShippingResult as p, CartApi as q, type CartApiOptions as r, type CheckoutParams as s, type ClearCartParams as t, type CommerceClientOptions as u, type CommunityClientOptions as v, type CommunityPost as w, type CompatibilityProductSelectionParamEvent as x, type ConfirmPaymentParams as y, type ConfirmPaymentResponse as z };
1339
+ export { type NormalizedProductSelection as $, type ApiQueryOptions as A, BaseApi as B, CommerceClient as C, type DebugConfig as D, type ExtractArrayType as E, type CreateFulfillmentParams as F, type CreateOrderItem as G, type CreateOrderParams as H, type CreateReturnParams as I, CustomerAuth as J, type CustomerAuthOptions as K, type CustomerAuthResponse as L, type CustomerLoginData as M, type CustomerProfile as N, type CustomerRefreshResponse as O, type PayloadFindResponse as P, type CustomerRegisterData as Q, type RetryConfig as R, type Sort as S, type CustomerRegisterResponse as T, type CustomerSnapshot as U, DiscountApi as V, type Where as W, type DiscountApiOptions as X, type LegacyProductSelectionParamEvent as Y, type ListingGroupingState as Z, type ListingGroupsParams as _, CommunityClient as a, type UpdateItemParams as a$, OrderApi as a0, type OrderApiOptions as a1, ProductApi as a2, type ProductApiOptions as a3, type ProductDetail as a4, type ProductDetailBrand as a5, type ProductDetailCategory as a6, type ProductDetailImage as a7, type ProductDetailImageMedia as a8, type ProductDetailListing as a9, type ProductOptionMatrixOption as aA, type ProductOptionMatrixValue as aB, type ProductOptionMatrixVariant as aC, type ProductOptionShape as aD, type ProductOptionValueShape as aE, type ProductSelectionAvailableValue as aF, type ProductSelectionByOptionValue as aG, ProductSelectionCodecError as aH, type ProductSelectionCodecOptions as aI, type ProductSelectionInput as aJ, type ProductSelectionResolution as aK, type ProductSelectionResolutionContext as aL, type ProductVariantShape as aM, type RemoveDiscountParams as aN, type RemoveItemParams as aO, type RequestOptions as aP, type ReturnItem as aQ, type ReturnReason as aR, type ReturnWithRefundItem as aS, type ReturnWithRefundParams as aT, type ServerApiOptions as aU, ShippingApi as aV, type ShippingApiOptions as aW, type StockCheckParams as aX, type StockCheckResponse as aY, type StockCheckResult as aZ, type UpdateFulfillmentParams as a_, type ProductDetailMedia as aa, type ProductDetailOption as ab, type ProductDetailOptionValue as ac, type ProductDetailParams as ad, type ProductDetailResult as ae, type ProductDetailTag as af, type ProductDetailUnavailableReason as ag, type ProductDetailVariant as ah, type ProductDetailVariantOptionValue as ai, type ProductDetailVideo as aj, type ProductHrefGroup as ak, type ProductHrefOptions as al, type ProductHrefProduct as am, type ProductListingCard as an, type ProductListingCardPriceRange as ao, type ProductListingCardRepresentativeVariant as ap, type ProductListingGroup as aq, type ProductListingGroupSummary as ar, type ProductListingGroupVariant as as, type ProductListingGroupsItem as at, type ProductListingGroupsProduct as au, type ProductListingGroupsResponse as av, type ProductListingProductShape as aw, type ProductListingProjection as ax, type ProductListingSwatch as ay, type ProductOptionMatrix as az, CustomerNamespace as b, type UpdateOrderParams as b0, type UpdateProfileData as b1, type UpdateReturnParams as b2, type UpdateTransactionParams as b3, type ValidateDiscountParams as b4, type ValidateDiscountResult as b5, buildProductHref as b6, buildProductListingCard as b7, buildProductListingGroupsByOption as b8, buildProductListingProjection as b9, buildProductOptionMatrix as ba, buildProductOptionMatrixFromDetail as bb, createProductSelectionCodec as bc, getAvailableOptionValues as bd, getProductSelectionImages as be, getSelectedValueByOptionId as bf, normalizeProductSelection as bg, normalizeProductSelectionFromMatrix as bh, normalizeSelectedValueIds as bi, parseProductSelection as bj, resolveProductSelection as bk, resolveProductSelectionFromMatrix as bl, resolveVariantForSelection as bm, stringifyProductSelection as bn, type ProductDetailPreviewParams as bo, type ProductDetailPreviewOptions as bp, type ProductUpsertParams as bq, type ProductUpsertResponse as br, type ClientServerConfig as bs, type ClientState as c, type ClientConfig as d, type ClientMetadata as e, type DeepPartial as f, type PayloadMutationResponse as g, type RootClient as h, type RootCollectionClient as i, type RootReadOnlyQueryBuilder as j, type AddItemParams as k, type ApplyDiscountParams as l, type BulkImportFulfillmentsParams as m, type BulkImportFulfillmentsResponse as n, type CalculateShippingParams as o, type CalculateShippingResult as p, CartApi as q, type CartApiOptions as r, type CheckoutParams as s, type ClearCartParams as t, type CommerceClientOptions as u, type CommunityClientOptions as v, type CommunityPost as w, type CompatibilityProductSelectionParamEvent as x, type ConfirmPaymentParams as y, type ConfirmPaymentResponse as z };
@@ -1,6 +1,6 @@
1
- import { P as PublicCollection } from './const-AytzliEu.cjs';
2
- import { P as PublicProduct, C as CollectionType } from './types-CmLG-7RL.cjs';
3
- import { O as Order, i as Cart, j as CartItem, m as OrderItem, n as Transaction, o as Fulfillment, p as Return } from './payload-types-Wa4-eC6x.cjs';
1
+ import { P as PublicCollection } from './const-sPR2IkCe.cjs';
2
+ import { P as PublicProduct, C as CollectionType } from './types-B3YT092I.cjs';
3
+ import { O as Order, i as Cart, j as CartItem, m as Transaction, n as Fulfillment, o as Return } from './payload-types-dkeQyrDC.cjs';
4
4
 
5
5
  interface CommunityClientOptions {
6
6
  publishableKey?: string;
@@ -504,10 +504,12 @@ type ProductListingSwatch = {
504
504
  href: string;
505
505
  availableForSale: boolean;
506
506
  };
507
+ type ProductListingCardRepresentativeVariant = ProductListingGroupsItem['groups'][number]['variants'][number];
507
508
  type ProductListingCard = {
508
509
  id: EntityID;
509
510
  href: string;
510
511
  title: string;
512
+ representativeVariant?: ProductListingCardRepresentativeVariant | null;
511
513
  primaryImage: ProductDetailMedia | null;
512
514
  priceRange: ProductListingCardPriceRange;
513
515
  availableForSale: boolean;
@@ -666,8 +668,10 @@ type StockCheckParams = {
666
668
  };
667
669
  type StockCheckResult = {
668
670
  variantId: string;
671
+ status: 'available' | 'not_published' | 'archived' | 'not_found';
669
672
  available: boolean;
670
673
  availableStock: number;
674
+ isUnlimited: boolean;
671
675
  requestedQuantity: number;
672
676
  error?: string;
673
677
  };
@@ -678,19 +682,33 @@ type StockCheckResponse = {
678
682
  type ListingGroupsParams = {
679
683
  productIds: string[];
680
684
  };
681
- type ProductListingGroupSummary = Omit<ProductListingGroup, 'variants'>;
682
- type ProductListingGroupsProduct = PublicProduct & {
685
+ type ListingGroupingState = 'grouped' | 'no_primary_option' | 'empty';
686
+ type ProductListingGroupVariant = Pick<ProductVariantShape, 'id' | 'optionValues' | 'price' | 'compareAtPrice' | 'stock' | 'isUnlimited' | 'isActive' | 'thumbnail' | 'images' | '_order'>;
687
+ type ProductListingGroupSummary = ProductListingGroup<ProductListingGroupVariant>;
688
+ type ProductListingGroupsProductVariants = NonNullable<PublicProduct['variants']>;
689
+ type ProductListingGroupsProduct = Omit<PublicProduct, 'variants'> & {
683
690
  id: string;
684
691
  slug: string;
685
692
  title: string;
693
+ variants?: (Omit<ProductListingGroupsProductVariants, 'docs'> & {
694
+ docs: ProductListingGroupVariant[];
695
+ }) | null;
686
696
  };
687
697
  type ProductListingGroupsItem = {
688
698
  product: ProductListingGroupsProduct;
689
699
  primaryOptionId: string | null;
700
+ listingGroupingState: ListingGroupingState;
690
701
  groups: ProductListingGroupSummary[];
691
702
  };
692
703
  type ProductListingGroupsResponse = {
704
+ /**
705
+ * Matching products in the same order as the requested productIds, excluding
706
+ * ids that were not found, not published, or not accessible for the current
707
+ * tenant/key.
708
+ */
693
709
  docs: ProductListingGroupsItem[];
710
+ /** Requested productIds that could not be returned. */
711
+ missing: string[];
694
712
  };
695
713
  type ProductDetailParams = {
696
714
  slug: string;
@@ -794,8 +812,9 @@ interface ProductDetail {
794
812
  content?: unknown;
795
813
  publishedAt?: string | null;
796
814
  status: string;
797
- totalInventory: number;
815
+ totalInventory: number | null;
798
816
  totalVariants: number;
817
+ hasUnlimitedVariant: boolean;
799
818
  hasOnlyDefaultVariant: boolean;
800
819
  };
801
820
  variants: ProductDetailVariant[];
@@ -807,6 +826,14 @@ interface ProductDetail {
807
826
  videos: ProductDetailVideo[];
808
827
  listing: ProductDetailListing;
809
828
  }
829
+ type ProductDetailUnavailableReason = 'not_found' | 'not_published' | 'feature_disabled';
830
+ type ProductDetailResult = {
831
+ found: true;
832
+ product: ProductDetail;
833
+ } | {
834
+ found: false;
835
+ reason: ProductDetailUnavailableReason;
836
+ };
810
837
  type ProductUpsertOptionValueInput = {
811
838
  id?: string;
812
839
  value: string;
@@ -873,11 +900,15 @@ declare class ProductApi extends BaseApi {
873
900
  listingGroups(params: ListingGroupsParams): Promise<ProductListingGroupsResponse>;
874
901
  /**
875
902
  * Fetch full product detail by slug or id.
876
- * Returns `null` on 404 regardless of reason (`not_found` / `not_published` /
877
- * `tenant_mismatch` / `feature_disabled`). For the reason behind a null,
878
- * inspect `client.lastRequestId` against backend logs.
903
+ * Returns a discriminated result so storefronts can distinguish missing,
904
+ * unpublished, and feature-disabled products.
905
+ *
906
+ * Only product-detail 404 responses carrying one of those allowlisted reasons
907
+ * are mapped to `{ found: false, reason }`. Unknown or uncoded 404s, plus
908
+ * permission/auth errors such as tenant mismatch, continue to throw typed SDK
909
+ * errors instead of being collapsed into a storefront absence result.
879
910
  */
880
- detail(params: ProductDetailParams): Promise<ProductDetail | null>;
911
+ detail(params: ProductDetailParams): Promise<ProductDetailResult>;
881
912
  /**
882
913
  * Atomically create or update a product together with its options,
883
914
  * option-values, and variants in a single transaction. Mirrors Shopify's
@@ -936,12 +967,29 @@ type ReturnItem = {
936
967
  orderItem: string;
937
968
  quantity: number;
938
969
  };
970
+ type OrderCreateEntityID = string | number;
971
+ type CreateOrderItem = {
972
+ product: OrderCreateEntityID;
973
+ variant: OrderCreateEntityID;
974
+ option: OrderCreateEntityID;
975
+ quantity: number;
976
+ /**
977
+ * Compatibility input: the create-order endpoint accepts this, but the server
978
+ * derives authoritative line pricing from the product variant.
979
+ */
980
+ unitPrice?: number;
981
+ /**
982
+ * Compatibility input: the create-order endpoint accepts this, but the server
983
+ * derives authoritative line totals from the product variant.
984
+ */
985
+ totalPrice?: number;
986
+ };
939
987
  type CreateOrderParams = {
940
988
  orderNumber: string;
941
989
  customer?: string;
942
990
  customerSnapshot: CustomerSnapshot;
943
991
  shippingAddress: Order['shippingAddress'];
944
- orderItems: Pick<OrderItem, 'product' | 'variant' | 'quantity' | 'unitPrice' | 'totalPrice'>[];
992
+ orderItems: CreateOrderItem[];
945
993
  totalAmount: number;
946
994
  shippingAmount?: number;
947
995
  pgPaymentId?: string;
@@ -986,6 +1034,7 @@ type ReturnWithRefundItem = {
986
1034
  orderItem: string | number;
987
1035
  quantity: number;
988
1036
  restockAction?: RestockAction;
1037
+ restockingFee?: number;
989
1038
  };
990
1039
  type ReturnWithRefundParams = {
991
1040
  orderNumber: string;
@@ -993,6 +1042,7 @@ type ReturnWithRefundParams = {
993
1042
  reasonDetail?: string;
994
1043
  returnItems: ReturnWithRefundItem[];
995
1044
  refundAmount: number;
1045
+ returnShippingFee?: number;
996
1046
  pgPaymentId: string;
997
1047
  paymentKey?: string;
998
1048
  refundReceiptUrl?: string;
@@ -1077,7 +1127,7 @@ declare class CommerceClient {
1077
1127
  readonly product: {
1078
1128
  stockCheck: (params: StockCheckParams) => Promise<StockCheckResponse>;
1079
1129
  listingGroups: (params: ListingGroupsParams) => Promise<ProductListingGroupsResponse>;
1080
- detail: (params: ProductDetailParams) => Promise<ProductDetail | null>;
1130
+ detail: (params: ProductDetailParams) => Promise<ProductDetailResult>;
1081
1131
  };
1082
1132
  readonly cart: {
1083
1133
  get: (cartId: string) => Promise<Cart>;
@@ -1286,4 +1336,4 @@ type DeepPartial<T> = {
1286
1336
  };
1287
1337
  type ExtractArrayType<T> = T extends (infer U)[] ? U : never;
1288
1338
 
1289
- export { type OrderApiOptions as $, type ApiQueryOptions as A, BaseApi as B, CommerceClient as C, type DebugConfig as D, type ExtractArrayType as E, type CreateFulfillmentParams as F, type CreateOrderParams as G, type CreateReturnParams as H, CustomerAuth as I, type CustomerAuthOptions as J, type CustomerAuthResponse as K, type CustomerLoginData as L, type CustomerProfile as M, type CustomerRefreshResponse as N, type CustomerRegisterData as O, type PayloadFindResponse as P, type CustomerRegisterResponse as Q, type RetryConfig as R, type Sort as S, type CustomerSnapshot as T, DiscountApi as U, type DiscountApiOptions as V, type Where as W, type LegacyProductSelectionParamEvent as X, type ListingGroupsParams as Y, type NormalizedProductSelection as Z, OrderApi as _, CommunityClient as a, buildProductHref as a$, ProductApi as a0, type ProductApiOptions as a1, type ProductDetail as a2, type ProductDetailBrand as a3, type ProductDetailCategory as a4, type ProductDetailImage as a5, type ProductDetailImageMedia as a6, type ProductDetailListing as a7, type ProductDetailMedia as a8, type ProductDetailOption as a9, type ProductSelectionByOptionValue as aA, ProductSelectionCodecError as aB, type ProductSelectionCodecOptions as aC, type ProductSelectionInput as aD, type ProductSelectionResolution as aE, type ProductSelectionResolutionContext as aF, type ProductVariantShape as aG, type RemoveDiscountParams as aH, type RemoveItemParams as aI, type RequestOptions as aJ, type ReturnItem as aK, type ReturnReason as aL, type ReturnWithRefundParams as aM, type ServerApiOptions as aN, ShippingApi as aO, type ShippingApiOptions as aP, type StockCheckParams as aQ, type StockCheckResponse as aR, type StockCheckResult as aS, type UpdateFulfillmentParams as aT, type UpdateItemParams as aU, type UpdateOrderParams as aV, type UpdateProfileData as aW, type UpdateReturnParams as aX, type UpdateTransactionParams as aY, type ValidateDiscountParams as aZ, type ValidateDiscountResult as a_, type ProductDetailOptionValue as aa, type ProductDetailParams as ab, type ProductDetailTag as ac, type ProductDetailVariant as ad, type ProductDetailVariantOptionValue as ae, type ProductDetailVideo as af, type ProductHrefGroup as ag, type ProductHrefOptions as ah, type ProductHrefProduct as ai, type ProductListingCard as aj, type ProductListingCardPriceRange as ak, type ProductListingGroup as al, type ProductListingGroupSummary as am, type ProductListingGroupsItem as an, type ProductListingGroupsProduct as ao, type ProductListingGroupsResponse as ap, type ProductListingProductShape as aq, type ProductListingProjection as ar, type ProductListingSwatch as as, type ProductOptionMatrix as at, type ProductOptionMatrixOption as au, type ProductOptionMatrixValue as av, type ProductOptionMatrixVariant as aw, type ProductOptionShape as ax, type ProductOptionValueShape as ay, type ProductSelectionAvailableValue as az, CustomerNamespace as b, buildProductListingCard as b0, buildProductListingGroupsByOption as b1, buildProductListingProjection as b2, buildProductOptionMatrix as b3, buildProductOptionMatrixFromDetail as b4, createProductSelectionCodec as b5, getAvailableOptionValues as b6, getProductSelectionImages as b7, getSelectedValueByOptionId as b8, normalizeProductSelection as b9, normalizeProductSelectionFromMatrix as ba, normalizeSelectedValueIds as bb, parseProductSelection as bc, resolveProductSelection as bd, resolveProductSelectionFromMatrix as be, resolveVariantForSelection as bf, stringifyProductSelection as bg, type ProductDetailPreviewParams as bh, type ProductDetailPreviewOptions as bi, type ProductUpsertParams as bj, type ProductUpsertResponse as bk, type ClientServerConfig as bl, type ClientState as c, type ClientConfig as d, type ClientMetadata as e, type DeepPartial as f, type PayloadMutationResponse as g, type RootClient as h, type RootCollectionClient as i, type RootReadOnlyQueryBuilder as j, type AddItemParams as k, type ApplyDiscountParams as l, type BulkImportFulfillmentsParams as m, type BulkImportFulfillmentsResponse as n, type CalculateShippingParams as o, type CalculateShippingResult as p, CartApi as q, type CartApiOptions as r, type CheckoutParams as s, type ClearCartParams as t, type CommerceClientOptions as u, type CommunityClientOptions as v, type CommunityPost as w, type CompatibilityProductSelectionParamEvent as x, type ConfirmPaymentParams as y, type ConfirmPaymentResponse as z };
1339
+ export { type NormalizedProductSelection as $, type ApiQueryOptions as A, BaseApi as B, CommerceClient as C, type DebugConfig as D, type ExtractArrayType as E, type CreateFulfillmentParams as F, type CreateOrderItem as G, type CreateOrderParams as H, type CreateReturnParams as I, CustomerAuth as J, type CustomerAuthOptions as K, type CustomerAuthResponse as L, type CustomerLoginData as M, type CustomerProfile as N, type CustomerRefreshResponse as O, type PayloadFindResponse as P, type CustomerRegisterData as Q, type RetryConfig as R, type Sort as S, type CustomerRegisterResponse as T, type CustomerSnapshot as U, DiscountApi as V, type Where as W, type DiscountApiOptions as X, type LegacyProductSelectionParamEvent as Y, type ListingGroupingState as Z, type ListingGroupsParams as _, CommunityClient as a, type UpdateItemParams as a$, OrderApi as a0, type OrderApiOptions as a1, ProductApi as a2, type ProductApiOptions as a3, type ProductDetail as a4, type ProductDetailBrand as a5, type ProductDetailCategory as a6, type ProductDetailImage as a7, type ProductDetailImageMedia as a8, type ProductDetailListing as a9, type ProductOptionMatrixOption as aA, type ProductOptionMatrixValue as aB, type ProductOptionMatrixVariant as aC, type ProductOptionShape as aD, type ProductOptionValueShape as aE, type ProductSelectionAvailableValue as aF, type ProductSelectionByOptionValue as aG, ProductSelectionCodecError as aH, type ProductSelectionCodecOptions as aI, type ProductSelectionInput as aJ, type ProductSelectionResolution as aK, type ProductSelectionResolutionContext as aL, type ProductVariantShape as aM, type RemoveDiscountParams as aN, type RemoveItemParams as aO, type RequestOptions as aP, type ReturnItem as aQ, type ReturnReason as aR, type ReturnWithRefundItem as aS, type ReturnWithRefundParams as aT, type ServerApiOptions as aU, ShippingApi as aV, type ShippingApiOptions as aW, type StockCheckParams as aX, type StockCheckResponse as aY, type StockCheckResult as aZ, type UpdateFulfillmentParams as a_, type ProductDetailMedia as aa, type ProductDetailOption as ab, type ProductDetailOptionValue as ac, type ProductDetailParams as ad, type ProductDetailResult as ae, type ProductDetailTag as af, type ProductDetailUnavailableReason as ag, type ProductDetailVariant as ah, type ProductDetailVariantOptionValue as ai, type ProductDetailVideo as aj, type ProductHrefGroup as ak, type ProductHrefOptions as al, type ProductHrefProduct as am, type ProductListingCard as an, type ProductListingCardPriceRange as ao, type ProductListingCardRepresentativeVariant as ap, type ProductListingGroup as aq, type ProductListingGroupSummary as ar, type ProductListingGroupVariant as as, type ProductListingGroupsItem as at, type ProductListingGroupsProduct as au, type ProductListingGroupsResponse as av, type ProductListingProductShape as aw, type ProductListingProjection as ax, type ProductListingSwatch as ay, type ProductOptionMatrix as az, CustomerNamespace as b, type UpdateOrderParams as b0, type UpdateProfileData as b1, type UpdateReturnParams as b2, type UpdateTransactionParams as b3, type ValidateDiscountParams as b4, type ValidateDiscountResult as b5, buildProductHref as b6, buildProductListingCard as b7, buildProductListingGroupsByOption as b8, buildProductListingProjection as b9, buildProductOptionMatrix as ba, buildProductOptionMatrixFromDetail as bb, createProductSelectionCodec as bc, getAvailableOptionValues as bd, getProductSelectionImages as be, getSelectedValueByOptionId as bf, normalizeProductSelection as bg, normalizeProductSelectionFromMatrix as bh, normalizeSelectedValueIds as bi, parseProductSelection as bj, resolveProductSelection as bk, resolveProductSelectionFromMatrix as bl, resolveVariantForSelection as bm, stringifyProductSelection as bn, type ProductDetailPreviewParams as bo, type ProductDetailPreviewOptions as bp, type ProductUpsertParams as bq, type ProductUpsertResponse as br, type ClientServerConfig as bs, type ClientState as c, type ClientConfig as d, type ClientMetadata as e, type DeepPartial as f, type PayloadMutationResponse as g, type RootClient as h, type RootCollectionClient as i, type RootReadOnlyQueryBuilder as j, type AddItemParams as k, type ApplyDiscountParams as l, type BulkImportFulfillmentsParams as m, type BulkImportFulfillmentsResponse as n, type CalculateShippingParams as o, type CalculateShippingResult as p, CartApi as q, type CartApiOptions as r, type CheckoutParams as s, type ClearCartParams as t, type CommerceClientOptions as u, type CommunityClientOptions as v, type CommunityPost as w, type CompatibilityProductSelectionParamEvent as x, type ConfirmPaymentParams as y, type ConfirmPaymentResponse as z };
@@ -1,4 +1,4 @@
1
- import { P as Product, C as CustomerProfile, a as CustomerProfileList, b as ProductCollection, c as Post, d as Comment, R as Reaction, e as Config } from './payload-types-Wa4-eC6x.js';
1
+ import { P as Product, C as CustomerProfile, a as CustomerProfileList, b as ProductCollection, c as Post, d as Comment, R as Reaction, e as Config } from './payload-types-dkeQyrDC.js';
2
2
 
3
3
  type PublicCustomerProfile = Omit<CustomerProfile, 'tenant' | 'customer' | 'isPublic' | 'anonymizedAt' | 'metadata'>;
4
4
  type PublicProfileRelation = string | PublicCustomerProfile;
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { F as Form } from '../payload-types-Wa4-eC6x.cjs';
2
+ import { F as Form } from '../payload-types-dkeQyrDC.cjs';
3
3
  import { RichTextData } from './rich-text.cjs';
4
4
  import '@payloadcms/richtext-lexical';
5
5
  import '@payloadcms/richtext-lexical/lexical';
package/dist/ui/form.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { F as Form } from '../payload-types-Wa4-eC6x.js';
2
+ import { F as Form } from '../payload-types-dkeQyrDC.js';
3
3
  import { RichTextData } from './rich-text.js';
4
4
  import '@payloadcms/richtext-lexical';
5
5
  import '@payloadcms/richtext-lexical/lexical';
@@ -1,7 +1,7 @@
1
1
  import React, { CSSProperties } from 'react';
2
2
  import { MuxPlayerProps, MuxPlayerRefAttributes } from '@mux/mux-player-react';
3
3
  export { MuxPlayerRefAttributes as VideoPlayerRef } from '@mux/mux-player-react';
4
- import { V as Video } from '../payload-types-Wa4-eC6x.cjs';
4
+ import { V as Video } from '../payload-types-dkeQyrDC.cjs';
5
5
  export { V as VideoGifOptions, a as VideoThumbnailOptions, g as getVideoGif, b as getVideoMp4Url, c as getVideoStoryboard, d as getVideoStreamUrl, e as getVideoThumbnail } from '../video-WR_TFO9a.cjs';
6
6
 
7
7
  interface VideoPlayerCSSProperties extends CSSProperties {
@@ -1,7 +1,7 @@
1
1
  import React, { CSSProperties } from 'react';
2
2
  import { MuxPlayerProps, MuxPlayerRefAttributes } from '@mux/mux-player-react';
3
3
  export { MuxPlayerRefAttributes as VideoPlayerRef } from '@mux/mux-player-react';
4
- import { V as Video } from '../payload-types-Wa4-eC6x.js';
4
+ import { V as Video } from '../payload-types-dkeQyrDC.js';
5
5
  export { V as VideoGifOptions, a as VideoThumbnailOptions, g as getVideoGif, b as getVideoMp4Url, c as getVideoStoryboard, d as getVideoStreamUrl, e as getVideoThumbnail } from '../video-WR_TFO9a.js';
6
6
 
7
7
  interface VideoPlayerCSSProperties extends CSSProperties {
package/dist/webhook.cjs CHANGED
@@ -20,21 +20,162 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/webhook.ts
21
21
  var webhook_exports = {};
22
22
  __export(webhook_exports, {
23
+ COMMERCE_NOTIFICATION_EVENTS: () => COMMERCE_NOTIFICATION_EVENTS,
24
+ COMMERCE_NOTIFICATION_EVENT_TYPE: () => COMMERCE_NOTIFICATION_EVENT_TYPE,
25
+ COMMERCE_NOTIFICATION_OPERATION: () => COMMERCE_NOTIFICATION_OPERATION,
23
26
  CUSTOMER_PASSWORD_RESET_OPERATION: () => CUSTOMER_PASSWORD_RESET_OPERATION,
27
+ ORDER_CHANGED_EVENT_TYPE: () => ORDER_CHANGED_EVENT_TYPE,
28
+ createCommerceEmailWebhookHandler: () => createCommerceEmailWebhookHandler,
24
29
  createCustomerAuthWebhookHandler: () => createCustomerAuthWebhookHandler,
25
30
  createTypedWebhookHandler: () => createTypedWebhookHandler,
31
+ defineCommerceEmailConfig: () => defineCommerceEmailConfig,
32
+ getCommerceNotificationIdempotencyKey: () => getCommerceNotificationIdempotencyKey,
26
33
  handleWebhook: () => handleWebhook,
34
+ isCommerceNotificationWebhookEvent: () => isCommerceNotificationWebhookEvent,
27
35
  isCustomerPasswordResetWebhookEvent: () => isCustomerPasswordResetWebhookEvent,
28
- isValidWebhookEvent: () => isValidWebhookEvent
36
+ isOrderChangedWebhookEvent: () => isOrderChangedWebhookEvent,
37
+ isValidWebhookEvent: () => isValidWebhookEvent,
38
+ isWebhookCollection: () => isWebhookCollection,
39
+ isWebhookOperation: () => isWebhookOperation
29
40
  });
30
41
  module.exports = __toCommonJS(webhook_exports);
31
42
 
32
43
  // src/core/webhook/index.ts
44
+ var ORDER_CHANGED_EVENT_TYPE = "collection.orderChanged";
45
+ var COMMERCE_NOTIFICATION_EVENT_TYPE = "commerce.notification";
33
46
  function isValidWebhookEvent(data) {
34
47
  if (typeof data !== "object" || data === null) return false;
35
48
  const obj = data;
36
49
  return typeof obj.collection === "string" && typeof obj.operation === "string" && obj.operation.length > 0 && typeof obj.data === "object" && obj.data !== null;
37
50
  }
51
+ var COMMERCE_NOTIFICATION_OPERATION = "notification";
52
+ var COMMERCE_NOTIFICATION_EVENTS = [
53
+ "orderPaid",
54
+ "fulfillmentShipped",
55
+ "orderDelivered",
56
+ "returnRequested",
57
+ "returnCompleted"
58
+ ];
59
+ function isStringOrNumber(value) {
60
+ return typeof value === "string" || typeof value === "number";
61
+ }
62
+ function isWebhookOrderScope(value) {
63
+ if (!isRecord(value)) return false;
64
+ if (value.kind === "collection") {
65
+ return typeof value.collection === "string";
66
+ }
67
+ if (value.kind === "join") {
68
+ return typeof value.collection === "string" && typeof value.field === "string" && isStringOrNumber(value.id);
69
+ }
70
+ return false;
71
+ }
72
+ function isWebhookOrderMoved(value) {
73
+ if (!isRecord(value)) return false;
74
+ return typeof value.collection === "string" && isStringOrNumber(value.id) && (value.relatedCollection === void 0 || typeof value.relatedCollection === "string") && (value.relatedId === void 0 || isStringOrNumber(value.relatedId));
75
+ }
76
+ function hasOptionalOrderValue(value, key) {
77
+ return value[key] === void 0 || value[key] === null || typeof value[key] === "string";
78
+ }
79
+ function isWebhookOrderChange(value) {
80
+ if (!isRecord(value)) return false;
81
+ return value.type === "order" && value.source === "payload-orderable" && (value.orderableFieldName === void 0 || typeof value.orderableFieldName === "string") && hasOptionalOrderValue(value, "previousOrder") && hasOptionalOrderValue(value, "nextOrder") && isWebhookOrderScope(value.scope) && isWebhookOrderMoved(value.moved);
82
+ }
83
+ function isCommerceNotificationEventName(value) {
84
+ return typeof value === "string" && COMMERCE_NOTIFICATION_EVENTS.includes(value);
85
+ }
86
+ function isCommerceNotificationSourceCollection(value) {
87
+ return value === "orders" || value === "fulfillments" || value === "returns";
88
+ }
89
+ function isCommerceNotificationData(value) {
90
+ if (!isRecord(value)) return false;
91
+ if (value.source !== void 0 && (!isRecord(value.source) || !isCommerceNotificationSourceCollection(value.source.collection) || !isStringOrNumber(value.source.id))) {
92
+ return false;
93
+ }
94
+ return (value.orderId === void 0 || isStringOrNumber(value.orderId)) && (value.orderNumber === void 0 || typeof value.orderNumber === "string") && (value.status === void 0 || typeof value.status === "string") && (value.totalAmount === void 0 || typeof value.totalAmount === "number") && (value.currency === void 0 || typeof value.currency === "string") && (value.fulfillmentId === void 0 || isStringOrNumber(value.fulfillmentId)) && (value.fulfillmentStatus === void 0 || typeof value.fulfillmentStatus === "string") && (value.shippedAt === void 0 || typeof value.shippedAt === "string") && (value.returnId === void 0 || isStringOrNumber(value.returnId)) && (value.returnStatus === void 0 || typeof value.returnStatus === "string") && (value.refundAmount === void 0 || typeof value.refundAmount === "number") && (value.completedAt === void 0 || typeof value.completedAt === "string");
95
+ }
96
+ function isCommerceNotification(value) {
97
+ if (!isRecord(value)) return false;
98
+ return isCommerceNotificationEventName(value.event) && typeof value.intentId === "string" && value.intentId.length > 0 && typeof value.dedupeKey === "string" && value.dedupeKey.length > 0 && (value.orderId === void 0 || typeof value.orderId === "string") && (value.fulfillmentId === void 0 || typeof value.fulfillmentId === "string") && (value.returnId === void 0 || typeof value.returnId === "string");
99
+ }
100
+ function isWebhookCommerceNotificationChange(value) {
101
+ if (!isRecord(value)) return false;
102
+ return value.type === "notification" && value.source === "commerce-notifications" && isCommerceNotificationEventName(value.event) && isCommerceNotificationSourceCollection(value.sourceCollection) && isStringOrNumber(value.sourceId);
103
+ }
104
+ function matchesOptionalId(actual, expected) {
105
+ return actual === void 0 || expected === void 0 || actual === expected;
106
+ }
107
+ function isOrderChangedWebhookEvent(event) {
108
+ if (!isValidWebhookEvent(event) || event.operation !== "update" || event.eventType !== ORDER_CHANGED_EVENT_TYPE || !isWebhookOrderChange(event.change)) {
109
+ return false;
110
+ }
111
+ if (event.collection !== event.change.scope.collection) {
112
+ return false;
113
+ }
114
+ if (event.change.scope.kind === "collection" && event.change.moved.collection !== event.change.scope.collection) {
115
+ return false;
116
+ }
117
+ return true;
118
+ }
119
+ function isCommerceNotificationWebhookEvent(event) {
120
+ if (!isValidWebhookEvent(event) || event.operation !== COMMERCE_NOTIFICATION_OPERATION || event.eventType !== COMMERCE_NOTIFICATION_EVENT_TYPE || !isCommerceNotificationData(event.data) || !isCommerceNotification(event.notification)) {
121
+ return false;
122
+ }
123
+ const notification = event.notification;
124
+ const data = event.data;
125
+ const change = event.change;
126
+ const sourceCollection = data.source?.collection ?? event.collection;
127
+ const sourceId = data.source?.id;
128
+ if (!isCommerceNotificationSourceCollection(sourceCollection)) return false;
129
+ if (data.source !== void 0 && event.collection !== data.source.collection) {
130
+ return false;
131
+ }
132
+ if (change !== void 0) {
133
+ if (!isWebhookCommerceNotificationChange(change)) return false;
134
+ if (change.sourceCollection !== sourceCollection) return false;
135
+ if (change.event !== notification.event) return false;
136
+ if (!matchesOptionalId(change.sourceId, sourceId)) return false;
137
+ }
138
+ const changeSourceId = isWebhookCommerceNotificationChange(change) ? change.sourceId : void 0;
139
+ if (notification.event === "orderPaid" || notification.event === "orderDelivered") {
140
+ return sourceCollection === "orders" && typeof notification.orderId === "string" && notification.orderId.length > 0 && matchesOptionalId(data.orderId, sourceId) && matchesOptionalId(notification.orderId, sourceId) && matchesOptionalId(data.orderId, notification.orderId) && matchesOptionalId(changeSourceId, data.orderId ?? notification.orderId);
141
+ }
142
+ if (notification.event === "fulfillmentShipped") {
143
+ return sourceCollection === "fulfillments" && matchesOptionalId(data.fulfillmentId, sourceId) && typeof notification.fulfillmentId === "string" && notification.fulfillmentId.length > 0 && matchesOptionalId(notification.fulfillmentId, sourceId) && matchesOptionalId(data.fulfillmentId, notification.fulfillmentId) && matchesOptionalId(changeSourceId, notification.fulfillmentId);
144
+ }
145
+ if (notification.event === "returnRequested" || notification.event === "returnCompleted") {
146
+ return sourceCollection === "returns" && matchesOptionalId(data.returnId, sourceId) && typeof notification.returnId === "string" && notification.returnId.length > 0 && matchesOptionalId(notification.returnId, sourceId) && matchesOptionalId(data.returnId, notification.returnId) && matchesOptionalId(changeSourceId, notification.returnId);
147
+ }
148
+ return false;
149
+ }
150
+ function getCommerceNotificationIdempotencyKey(event) {
151
+ return `${event.notification.intentId}:${event.notification.dedupeKey}`;
152
+ }
153
+ function defineCommerceEmailConfig(config) {
154
+ return config;
155
+ }
156
+ function createCommerceEmailWebhookHandler(handlers) {
157
+ return async (event) => {
158
+ if (!isCommerceNotificationWebhookEvent(event)) {
159
+ await handlers.unhandled?.(event);
160
+ return;
161
+ }
162
+ const handler = handlers[event.notification.event];
163
+ if (!handler) {
164
+ await handlers.unhandled?.(event);
165
+ return;
166
+ }
167
+ await handler({
168
+ event,
169
+ idempotencyKey: getCommerceNotificationIdempotencyKey(event)
170
+ });
171
+ };
172
+ }
173
+ function isWebhookCollection(event, collection) {
174
+ return isValidWebhookEvent(event) && event.collection === collection;
175
+ }
176
+ function isWebhookOperation(event, operation) {
177
+ return isValidWebhookEvent(event) && event.operation === operation;
178
+ }
38
179
  var CUSTOMER_PASSWORD_RESET_OPERATION = "password-reset";
39
180
  function isRecord(value) {
40
181
  return typeof value === "object" && value !== null;