@payloadcms/plugin-ecommerce 3.57.0-internal.f26caed → 3.58.0-canary.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/collections/addresses/createAddressesCollection.d.ts +1 -1
- package/dist/collections/addresses/createAddressesCollection.d.ts.map +1 -1
- package/dist/collections/addresses/createAddressesCollection.js +1 -0
- package/dist/collections/addresses/createAddressesCollection.js.map +1 -1
- package/dist/collections/addresses/defaultCountries.d.ts +1 -1
- package/dist/collections/addresses/defaultCountries.d.ts.map +1 -1
- package/dist/collections/addresses/defaultCountries.js.map +1 -1
- package/dist/collections/addresses/hooks/beforeChange.d.ts +1 -1
- package/dist/collections/addresses/hooks/beforeChange.d.ts.map +1 -1
- package/dist/collections/addresses/hooks/beforeChange.js.map +1 -1
- package/dist/collections/carts/createCartsCollection.d.ts +1 -1
- package/dist/collections/carts/createCartsCollection.d.ts.map +1 -1
- package/dist/collections/carts/createCartsCollection.js.map +1 -1
- package/dist/collections/orders/createOrdersCollection.d.ts +1 -1
- package/dist/collections/orders/createOrdersCollection.d.ts.map +1 -1
- package/dist/collections/orders/createOrdersCollection.js.map +1 -1
- package/dist/collections/products/createProductsCollection.d.ts +1 -1
- package/dist/collections/products/createProductsCollection.d.ts.map +1 -1
- package/dist/collections/products/createProductsCollection.js.map +1 -1
- package/dist/collections/transactions/createTransactionsCollection.d.ts +1 -1
- package/dist/collections/transactions/createTransactionsCollection.d.ts.map +1 -1
- package/dist/collections/transactions/createTransactionsCollection.js.map +1 -1
- package/dist/collections/variants/createVariantOptionsCollection.d.ts +1 -1
- package/dist/collections/variants/createVariantOptionsCollection.d.ts.map +1 -1
- package/dist/collections/variants/createVariantOptionsCollection.js.map +1 -1
- package/dist/collections/variants/createVariantTypesCollection.d.ts +1 -1
- package/dist/collections/variants/createVariantTypesCollection.d.ts.map +1 -1
- package/dist/collections/variants/createVariantTypesCollection.js.map +1 -1
- package/dist/collections/variants/createVariantsCollection/index.d.ts +1 -1
- package/dist/collections/variants/createVariantsCollection/index.d.ts.map +1 -1
- package/dist/collections/variants/createVariantsCollection/index.js.map +1 -1
- package/dist/currencies/index.d.ts +1 -1
- package/dist/currencies/index.d.ts.map +1 -1
- package/dist/currencies/index.js.map +1 -1
- package/dist/endpoints/confirmOrder.d.ts +1 -1
- package/dist/endpoints/confirmOrder.d.ts.map +1 -1
- package/dist/endpoints/confirmOrder.js.map +1 -1
- package/dist/endpoints/initiatePayment.d.ts +1 -1
- package/dist/endpoints/initiatePayment.d.ts.map +1 -1
- package/dist/endpoints/initiatePayment.js.map +1 -1
- package/dist/exports/types.d.ts +2 -1
- package/dist/exports/types.d.ts.map +1 -1
- package/dist/exports/types.js.map +1 -1
- package/dist/fields/amountField.d.ts +1 -1
- package/dist/fields/amountField.d.ts.map +1 -1
- package/dist/fields/amountField.js.map +1 -1
- package/dist/fields/cartItemsField.d.ts +1 -1
- package/dist/fields/cartItemsField.d.ts.map +1 -1
- package/dist/fields/cartItemsField.js.map +1 -1
- package/dist/fields/currencyField.d.ts +1 -1
- package/dist/fields/currencyField.d.ts.map +1 -1
- package/dist/fields/currencyField.js.map +1 -1
- package/dist/fields/pricesField.d.ts +1 -1
- package/dist/fields/pricesField.d.ts.map +1 -1
- package/dist/fields/pricesField.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -3
- package/dist/index.js.map +1 -1
- package/dist/payments/adapters/stripe/confirmOrder.d.ts +1 -1
- package/dist/payments/adapters/stripe/confirmOrder.d.ts.map +1 -1
- package/dist/payments/adapters/stripe/confirmOrder.js.map +1 -1
- package/dist/payments/adapters/stripe/index.d.ts +1 -1
- package/dist/payments/adapters/stripe/index.d.ts.map +1 -1
- package/dist/payments/adapters/stripe/index.js.map +1 -1
- package/dist/payments/adapters/stripe/initiatePayment.d.ts +1 -1
- package/dist/payments/adapters/stripe/initiatePayment.d.ts.map +1 -1
- package/dist/payments/adapters/stripe/initiatePayment.js.map +1 -1
- package/dist/react/provider/index.d.ts +15 -10
- package/dist/react/provider/index.d.ts.map +1 -1
- package/dist/react/provider/index.js +21 -22
- package/dist/react/provider/index.js.map +1 -1
- package/dist/react/provider/utilities.d.ts +1 -1
- package/dist/react/provider/utilities.d.ts.map +1 -1
- package/dist/react/provider/utilities.js.map +1 -1
- package/dist/translations/en.d.ts.map +1 -1
- package/dist/translations/en.js +1 -0
- package/dist/translations/en.js.map +1 -1
- package/dist/{types.d.ts → types/index.d.ts} +177 -2
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +3 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/utilities.d.ts +36 -0
- package/dist/types/utilities.d.ts.map +1 -0
- package/dist/types/utilities.js +3 -0
- package/dist/types/utilities.js.map +1 -0
- package/dist/ui/PriceCell/index.d.ts +1 -1
- package/dist/ui/PriceCell/index.d.ts.map +1 -1
- package/dist/ui/PriceCell/index.js.map +1 -1
- package/dist/ui/PriceInput/FormattedInput.d.ts +1 -1
- package/dist/ui/PriceInput/FormattedInput.d.ts.map +1 -1
- package/dist/ui/PriceInput/FormattedInput.js.map +1 -1
- package/dist/ui/PriceInput/index.d.ts +1 -1
- package/dist/ui/PriceInput/index.d.ts.map +1 -1
- package/dist/ui/PriceInput/index.js.map +1 -1
- package/dist/ui/PriceRowLabel/index.d.ts +1 -1
- package/dist/ui/PriceRowLabel/index.d.ts.map +1 -1
- package/dist/ui/PriceRowLabel/index.js.map +1 -1
- package/dist/ui/utilities.d.ts +1 -1
- package/dist/ui/utilities.d.ts.map +1 -1
- package/dist/ui/utilities.js.map +1 -1
- package/dist/utilities/defaultProductsValidation.d.ts +1 -1
- package/dist/utilities/defaultProductsValidation.d.ts.map +1 -1
- package/dist/utilities/defaultProductsValidation.js.map +1 -1
- package/dist/utilities/getCollectionSlugMap.d.ts +1 -1
- package/dist/utilities/getCollectionSlugMap.d.ts.map +1 -1
- package/dist/utilities/getCollectionSlugMap.js +5 -4
- package/dist/utilities/getCollectionSlugMap.js.map +1 -1
- package/dist/utilities/pushTypeScriptProperties.d.ts +10 -0
- package/dist/utilities/pushTypeScriptProperties.d.ts.map +1 -0
- package/dist/utilities/pushTypeScriptProperties.js +37 -0
- package/dist/utilities/pushTypeScriptProperties.js.map +1 -0
- package/dist/utilities/sanitizePluginConfig.d.ts +1 -1
- package/dist/utilities/sanitizePluginConfig.d.ts.map +1 -1
- package/dist/utilities/sanitizePluginConfig.js.map +1 -1
- package/package.json +8 -7
- package/dist/react/provider/types.d.ts +0 -172
- package/dist/react/provider/types.d.ts.map +0 -1
- package/dist/react/provider/types.js +0 -3
- package/dist/react/provider/types.js.map +0 -1
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -3
- package/dist/types.js.map +0 -1
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import type { Access, CollectionConfig, DefaultDocumentIDType, Endpoint, Field, FieldAccess, GroupField, PayloadRequest, SelectType, TypedCollection, Where } from 'payload';
|
|
1
|
+
import type { Access, CollectionConfig, DefaultDocumentIDType, Endpoint, Field, FieldAccess, GroupField, PayloadRequest, PopulateType, SelectType, TypedCollection, Where } from 'payload';
|
|
2
|
+
import type React from 'react';
|
|
3
|
+
import type { TypedEcommerce } from './utilities.js';
|
|
2
4
|
export type FieldsOverride = (args: {
|
|
3
5
|
defaultFields: Field[];
|
|
4
6
|
}) => Field[];
|
|
@@ -636,6 +638,10 @@ export type EcommercePluginConfig = {
|
|
|
636
638
|
* Defaults to true.
|
|
637
639
|
*/
|
|
638
640
|
products?: boolean | ProductsConfig;
|
|
641
|
+
/**
|
|
642
|
+
* Override the default slugs used across the plugin. This lets the plugin know which slugs to use for various internal operations and fields.
|
|
643
|
+
*/
|
|
644
|
+
slugMap?: Partial<CollectionSlugMap>;
|
|
639
645
|
/**
|
|
640
646
|
* Enable tracking of transactions. Accepts a config object to override the default collection settings.
|
|
641
647
|
*
|
|
@@ -654,5 +660,174 @@ export type SanitizedEcommercePluginConfig = {
|
|
|
654
660
|
paymentMethods: [] | PaymentAdapter[];
|
|
655
661
|
};
|
|
656
662
|
} & Omit<Required<EcommercePluginConfig>, 'access' | 'addresses' | 'currencies' | 'inventory' | 'payments'>;
|
|
663
|
+
export type EcommerceCollections = TypedEcommerce['collections'];
|
|
664
|
+
export type AddressesCollection = EcommerceCollections['addresses'];
|
|
665
|
+
export type CartsCollection = EcommerceCollections['carts'];
|
|
666
|
+
export type SyncLocalStorageConfig = {
|
|
667
|
+
/**
|
|
668
|
+
* Key to use for localStorage.
|
|
669
|
+
* Defaults to 'cart'.
|
|
670
|
+
*/
|
|
671
|
+
key?: string;
|
|
672
|
+
};
|
|
673
|
+
type APIProps = {
|
|
674
|
+
/**
|
|
675
|
+
* The route for the Payload API, defaults to `/api`.
|
|
676
|
+
*/
|
|
677
|
+
apiRoute?: string;
|
|
678
|
+
/**
|
|
679
|
+
* Customise the query used to fetch carts. Use this when you need to fetch additional data and optimise queries using depth, select and populate.
|
|
680
|
+
*
|
|
681
|
+
* Defaults to `{ depth: 0 }`.
|
|
682
|
+
*/
|
|
683
|
+
cartsFetchQuery?: {
|
|
684
|
+
depth?: number;
|
|
685
|
+
populate?: PopulateType;
|
|
686
|
+
select?: SelectType;
|
|
687
|
+
};
|
|
688
|
+
/**
|
|
689
|
+
* The route for the Payload API, defaults to ``. Eg for a Payload app running on `http://localhost:3000`, the default serverURL would be `http://localhost:3000`.
|
|
690
|
+
*/
|
|
691
|
+
serverURL?: string;
|
|
692
|
+
};
|
|
693
|
+
export type ContextProps = {
|
|
694
|
+
/**
|
|
695
|
+
* The slug for the addresses collection.
|
|
696
|
+
*
|
|
697
|
+
* Defaults to 'addresses'.
|
|
698
|
+
*/
|
|
699
|
+
addressesSlug?: string;
|
|
700
|
+
api?: APIProps;
|
|
701
|
+
/**
|
|
702
|
+
* The slug for the carts collection.
|
|
703
|
+
*
|
|
704
|
+
* Defaults to 'carts'.
|
|
705
|
+
*/
|
|
706
|
+
cartsSlug?: string;
|
|
707
|
+
children?: React.ReactNode;
|
|
708
|
+
/**
|
|
709
|
+
* The configuration for currencies used in the ecommerce context.
|
|
710
|
+
* This is used to handle currency formatting and calculations, defaults to USD.
|
|
711
|
+
*/
|
|
712
|
+
currenciesConfig?: CurrenciesConfig;
|
|
713
|
+
/**
|
|
714
|
+
* The slug for the customers collection.
|
|
715
|
+
*
|
|
716
|
+
* Defaults to 'users'.
|
|
717
|
+
*/
|
|
718
|
+
customersSlug?: string;
|
|
719
|
+
/**
|
|
720
|
+
* Enable debug mode for the ecommerce context. This will log additional information to the console.
|
|
721
|
+
* Defaults to false.
|
|
722
|
+
*/
|
|
723
|
+
debug?: boolean;
|
|
724
|
+
/**
|
|
725
|
+
* Whether to enable support for variants in the cart.
|
|
726
|
+
* This allows adding products with specific variants to the cart.
|
|
727
|
+
* Defaults to false.
|
|
728
|
+
*/
|
|
729
|
+
enableVariants?: boolean;
|
|
730
|
+
/**
|
|
731
|
+
* Supported payment methods for the ecommerce context.
|
|
732
|
+
*/
|
|
733
|
+
paymentMethods?: PaymentAdapterClient[];
|
|
734
|
+
/**
|
|
735
|
+
* Whether to enable localStorage for cart persistence.
|
|
736
|
+
* Defaults to true.
|
|
737
|
+
*/
|
|
738
|
+
syncLocalStorage?: boolean | SyncLocalStorageConfig;
|
|
739
|
+
};
|
|
740
|
+
/**
|
|
741
|
+
* Type used internally to represent the cart item to be added.
|
|
742
|
+
*/
|
|
743
|
+
type CartItemArgument = {
|
|
744
|
+
/**
|
|
745
|
+
* The ID of the product to add to the cart. Always required.
|
|
746
|
+
*/
|
|
747
|
+
product: DefaultDocumentIDType;
|
|
748
|
+
/**
|
|
749
|
+
* The ID of the variant to add to the cart. Optional, if not provided, the product will be added without a variant.
|
|
750
|
+
*/
|
|
751
|
+
variant?: DefaultDocumentIDType;
|
|
752
|
+
};
|
|
753
|
+
export type EcommerceContextType<T extends EcommerceCollections = EcommerceCollections> = {
|
|
754
|
+
/**
|
|
755
|
+
* Add an item to the cart.
|
|
756
|
+
*/
|
|
757
|
+
addItem: (item: CartItemArgument, quantity?: number) => Promise<void>;
|
|
758
|
+
/**
|
|
759
|
+
* All current addresses for the current user.
|
|
760
|
+
* This is used to manage shipping and billing addresses.
|
|
761
|
+
*/
|
|
762
|
+
addresses?: T['addresses'][];
|
|
763
|
+
/**
|
|
764
|
+
* The current data of the cart.
|
|
765
|
+
*/
|
|
766
|
+
cart?: T['addresses'];
|
|
767
|
+
/**
|
|
768
|
+
* The ID of the current cart corresponding to the cart in the database or local storage.
|
|
769
|
+
*/
|
|
770
|
+
cartID?: DefaultDocumentIDType;
|
|
771
|
+
/**
|
|
772
|
+
* Clear the cart, removing all items.
|
|
773
|
+
*/
|
|
774
|
+
clearCart: () => Promise<void>;
|
|
775
|
+
/**
|
|
776
|
+
* Initiate a payment using the selected payment method.
|
|
777
|
+
* This method should be called after the cart is ready for checkout.
|
|
778
|
+
* It requires the payment method ID and any necessary payment data.
|
|
779
|
+
*/
|
|
780
|
+
confirmOrder: (paymentMethodID: string, options?: {
|
|
781
|
+
additionalData: Record<string, unknown>;
|
|
782
|
+
}) => Promise<unknown>;
|
|
783
|
+
/**
|
|
784
|
+
* Create a new address by providing the data.
|
|
785
|
+
*/
|
|
786
|
+
createAddress: (data: Partial<T['addresses']>) => Promise<void>;
|
|
787
|
+
/**
|
|
788
|
+
* The configuration for the currencies used in the ecommerce context.
|
|
789
|
+
*/
|
|
790
|
+
currenciesConfig: CurrenciesConfig;
|
|
791
|
+
/**
|
|
792
|
+
* The currently selected currency used for the cart and price formatting automatically.
|
|
793
|
+
*/
|
|
794
|
+
currency: Currency;
|
|
795
|
+
/**
|
|
796
|
+
* Decrement an item in the cart by its index ID.
|
|
797
|
+
* If quantity reaches 0, the item will be removed from the cart.
|
|
798
|
+
*/
|
|
799
|
+
decrementItem: (item: DefaultDocumentIDType) => Promise<void>;
|
|
800
|
+
/**
|
|
801
|
+
* Increment an item in the cart by its index ID.
|
|
802
|
+
*/
|
|
803
|
+
incrementItem: (item: DefaultDocumentIDType) => Promise<void>;
|
|
804
|
+
/**
|
|
805
|
+
* Initiate a payment using the selected payment method.
|
|
806
|
+
* This method should be called after the cart is ready for checkout.
|
|
807
|
+
* It requires the payment method ID and any necessary payment data.
|
|
808
|
+
*/
|
|
809
|
+
initiatePayment: (paymentMethodID: string, options?: {
|
|
810
|
+
additionalData: Record<string, unknown>;
|
|
811
|
+
}) => Promise<unknown>;
|
|
812
|
+
paymentMethods: PaymentAdapterClient[];
|
|
813
|
+
/**
|
|
814
|
+
* Remove an item from the cart by its index ID.
|
|
815
|
+
*/
|
|
816
|
+
removeItem: (item: DefaultDocumentIDType) => Promise<void>;
|
|
817
|
+
/**
|
|
818
|
+
* The name of the currently selected payment method.
|
|
819
|
+
* This is used to determine which payment method to use when initiating a payment.
|
|
820
|
+
*/
|
|
821
|
+
selectedPaymentMethod?: null | string;
|
|
822
|
+
/**
|
|
823
|
+
* Change the currency for the cart, it defaults to the configured currency.
|
|
824
|
+
* This will update the currency used for pricing and calculations.
|
|
825
|
+
*/
|
|
826
|
+
setCurrency: (currency: string) => void;
|
|
827
|
+
/**
|
|
828
|
+
* Update an address by providing the data and the ID.
|
|
829
|
+
*/
|
|
830
|
+
updateAddress: (addressID: DefaultDocumentIDType, data: Partial<T['addresses']>) => Promise<void>;
|
|
831
|
+
};
|
|
657
832
|
export {};
|
|
658
|
-
//# sourceMappingURL=
|
|
833
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,MAAM,EACN,gBAAgB,EAChB,qBAAqB,EACrB,QAAQ,EACR,KAAK,EACL,WAAW,EACX,UAAU,EACV,cAAc,EACd,YAAY,EACZ,UAAU,EACV,eAAe,EACf,KAAK,EACN,MAAM,SAAS,CAAA;AAChB,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,OAAO,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,CAAA;IACrB,cAAc,EAAE,oBAAoB,EAAE,CAAA;IACtC;;OAEG;IACH,UAAU,EAAE,CAAC,IAAI,EAAE,qBAAqB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IAC1D;;;OAGG;IACH,qBAAqB,CAAC,EAAE,IAAI,GAAG,MAAM,CAAA;IACrC;;;OAGG;IACH,WAAW,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAA;IACvC;;OAEG;IACH,aAAa,EAAE,CAAC,SAAS,EAAE,qBAAqB,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;CAClG,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/types/index.ts"],"sourcesContent":["import type {\n Access,\n CollectionConfig,\n DefaultDocumentIDType,\n Endpoint,\n Field,\n FieldAccess,\n GroupField,\n PayloadRequest,\n PopulateType,\n SelectType,\n TypedCollection,\n Where,\n} from 'payload'\nimport type React from 'react'\n\nimport type { TypedEcommerce } from './utilities.js'\n\nexport type FieldsOverride = (args: { defaultFields: Field[] }) => Field[]\n\nexport type CollectionOverride = (args: {\n defaultCollection: CollectionConfig\n}) => CollectionConfig | Promise<CollectionConfig>\n\nexport type CartItem = {\n id: DefaultDocumentIDType\n product: DefaultDocumentIDType | TypedCollection['products']\n quantity: number\n variant?: DefaultDocumentIDType | TypedCollection['variants']\n}\n\ntype DefaultCartType = {\n currency?: string\n customer?: DefaultDocumentIDType | TypedCollection['customers']\n id: DefaultDocumentIDType\n items: CartItem[]\n subtotal?: number\n}\n\nexport type Cart = DefaultCartType\n\ntype InitiatePaymentReturnType = {\n /**\n * Allows for additional data to be returned, such as payment method specific data\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n [key: string]: any\n message: string\n}\n\ntype InitiatePayment = (args: {\n /**\n * The slug of the customers collection, defaults to 'users'.\n */\n customersSlug?: string\n data: {\n /**\n * Billing address for the payment.\n */\n billingAddress: TypedCollection['addresses']\n /**\n * Cart items.\n */\n cart: Cart\n /**\n * Currency code to use for the payment.\n */\n currency: string\n customerEmail: string\n /**\n * Shipping address for the payment.\n */\n shippingAddress?: TypedCollection['addresses']\n }\n req: PayloadRequest\n /**\n * The slug of the transactions collection, defaults to 'transactions'.\n * For example, this is used to create a record of the payment intent in the transactions collection.\n */\n transactionsSlug: string\n}) => InitiatePaymentReturnType | Promise<InitiatePaymentReturnType>\n\ntype ConfirmOrderReturnType = {\n /**\n * Allows for additional data to be returned, such as payment method specific data\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n [key: string]: any\n message: string\n orderID: DefaultDocumentIDType\n transactionID: DefaultDocumentIDType\n}\n\ntype ConfirmOrder = (args: {\n /**\n * The slug of the carts collection, defaults to 'carts'.\n * For example, this is used to retrieve the cart for the order.\n */\n cartsSlug?: string\n /**\n * The slug of the customers collection, defaults to 'users'.\n */\n customersSlug?: string\n /**\n * Data made available to the payment method when confirming an order. You should get the cart items from the transaction.\n */\n data: {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n [key: string]: any // Allows for additional data to be passed through, such as payment method specific data\n customerEmail?: string\n }\n /**\n * The slug of the orders collection, defaults to 'orders'.\n */\n ordersSlug?: string\n req: PayloadRequest\n /**\n * The slug of the transactions collection, defaults to 'transactions'.\n * For example, this is used to create a record of the payment intent in the transactions collection.\n */\n transactionsSlug?: string\n}) => ConfirmOrderReturnType | Promise<ConfirmOrderReturnType>\n\n/**\n * The full payment adapter config expected as part of the config for the Ecommerce plugin.\n *\n * You can insert this type directly or return it from a function constructing it.\n */\nexport type PaymentAdapter = {\n /**\n * The function that is called via the `/api/payments/{provider_name}/confirm-order` endpoint to confirm an order after a payment has been made.\n *\n * You should handle the order confirmation logic here.\n *\n * @example\n *\n * ```ts\n * const confirmOrder: ConfirmOrder = async ({ data: { customerEmail }, ordersSlug, req, transactionsSlug }) => {\n // Confirm the payment with Stripe or another payment provider here\n // Create an order in the orders collection here\n // Update the record of the payment intent in the transactions collection here\n return {\n message: 'Order confirmed successfully',\n orderID: 'order_123',\n transactionID: 'txn_123',\n // Include any additional data required for the payment method here\n }\n }\n * ```\n */\n confirmOrder: ConfirmOrder\n /**\n * An array of endpoints to be bootstrapped to Payload's API in order to support the payment method. All API paths are relative to `/api/payments/{provider_name}`.\n *\n * So for example, path `/webhooks` in the Stripe adapter becomes `/api/payments/stripe/webhooks`.\n *\n * @example '/webhooks'\n */\n endpoints?: Endpoint[]\n /**\n * A group configuration to be used in the admin interface to display the payment method.\n *\n * @example\n *\n * ```ts\n * const groupField: GroupField = {\n name: 'stripe',\n type: 'group',\n admin: {\n condition: (data) => data?.paymentMethod === 'stripe',\n },\n fields: [\n {\n name: 'stripeCustomerID',\n type: 'text',\n label: 'Stripe Customer ID',\n required: true,\n },\n {\n name: 'stripePaymentIntentID',\n type: 'text',\n label: 'Stripe PaymentIntent ID',\n required: true,\n },\n ],\n }\n * ```\n */\n group: GroupField\n /**\n * The function that is called via the `/api/payments/{provider_name}/initiate` endpoint to initiate a payment for an order.\n *\n * You should handle the payment initiation logic here.\n *\n * @example\n *\n * ```ts\n * const initiatePayment: InitiatePayment = async ({ data: { cart, currency, customerEmail, billingAddress, shippingAddress }, req, transactionsSlug }) => {\n // Create a payment intent with Stripe or another payment provider here\n // Create a record of the payment intent in the transactions collection here\n return {\n message: 'Payment initiated successfully',\n // Include any additional data required for the payment method here\n }\n }\n * ```\n */\n initiatePayment: InitiatePayment\n /**\n * The label of the payment method\n * @example\n * 'Bank Transfer'\n */\n label?: string\n /**\n * The name of the payment method\n * @example 'stripe'\n */\n name: string\n}\n\nexport type PaymentAdapterClient = {\n confirmOrder: boolean\n initiatePayment: boolean\n} & Pick<PaymentAdapter, 'label' | 'name'>\n\nexport type Currency = {\n /**\n * The ISO 4217 currency code\n * @example 'usd'\n */\n code: string\n /**\n * The number of decimal places the currency uses\n * @example 2\n */\n decimals: number\n /**\n * A user friendly name for the currency.\n *\n * @example 'US Dollar'\n */\n label: string\n /**\n * The symbol of the currency\n * @example '$'\n */\n symbol: string\n}\n\n/**\n * Commonly used arguments for a Payment Adapter function, it's use is entirely optional.\n */\nexport type PaymentAdapterArgs = {\n /**\n * Overrides the default fields of the collection. Affects the payment fields on collections such as transactions.\n */\n groupOverrides?: { fields?: FieldsOverride } & Partial<Omit<GroupField, 'fields'>>\n /**\n * The visually readable label for the payment method.\n * @example 'Bank Transfer'\n */\n label?: string\n}\n\n/**\n * Commonly used arguments for a Payment Adapter function, it's use is entirely optional.\n */\nexport type PaymentAdapterClientArgs = {\n /**\n * The visually readable label for the payment method.\n * @example 'Bank Transfer'\n */\n label?: string\n}\n\nexport type VariantsConfig = {\n /**\n * Override the default variants collection. If you override the collection, you should ensure it has the required fields for variants or re-use the default fields.\n *\n * @example\n *\n * ```ts\n * variants: {\n variantOptionsCollectionOverride: ({ defaultCollection }) => ({\n ...defaultCollection,\n fields: [\n ...defaultCollection.fields,\n {\n name: 'customField',\n label: 'Custom Field',\n type: 'text',\n },\n ],\n })\n }\n ```\n */\n variantOptionsCollectionOverride?: CollectionOverride\n /**\n * Override the default variants collection. If you override the collection, you should ensure it has the required fields for variants or re-use the default fields.\n *\n * @example\n *\n * ```ts\n * variants: {\n variantsCollectionOverride: ({ defaultCollection }) => ({\n ...defaultCollection,\n fields: [\n ...defaultCollection.fields,\n {\n name: 'customField',\n label: 'Custom Field',\n type: 'text',\n },\n ],\n })\n }\n ```\n */\n variantsCollectionOverride?: CollectionOverride\n /**\n * Override the default variants collection. If you override the collection, you should ensure it has the required fields for variants or re-use the default fields.\n *\n * @example\n *\n * ```ts\n * variants: {\n variantTypesCollectionOverride: ({ defaultCollection }) => ({\n ...defaultCollection,\n fields: [\n ...defaultCollection.fields,\n {\n name: 'customField',\n label: 'Custom Field',\n type: 'text',\n },\n ],\n })\n }\n ```\n */\n variantTypesCollectionOverride?: CollectionOverride\n}\n\nexport type ProductsConfig = {\n /**\n * Override the default products collection. If you override the collection, you should ensure it has the required fields for products or re-use the default fields.\n *\n * @example\n *\n * ```ts\n products: {\n productsCollectionOverride: ({ defaultCollection }) => ({\n ...defaultCollection,\n fields: [\n ...defaultCollection.fields,\n {\n name: 'notes',\n label: 'Notes',\n type: 'textarea',\n },\n ],\n })\n }\n ```\n */\n productsCollectionOverride?: CollectionOverride\n /**\n * Customise the validation used for checking products or variants before a transaction is created or a payment can be confirmed.\n */\n validation?: ProductsValidation\n /**\n * Enable variants and provide configuration for the variant collections.\n *\n * Defaults to true.\n */\n variants?: boolean | VariantsConfig\n}\n\nexport type OrdersConfig = {\n /**\n * Override the default orders collection. If you override the collection, you should ensure it has the required fields for orders or re-use the default fields.\n *\n * @example\n *\n * ```ts\n orders: {\n ordersCollectionOverride: ({ defaultCollection }) => ({\n ...defaultCollection,\n fields: [\n ...defaultCollection.fields,\n {\n name: 'notes',\n label: 'Notes',\n type: 'textarea',\n },\n ],\n })\n }\n ```\n */\n ordersCollectionOverride?: CollectionOverride\n}\n\nexport type TransactionsConfig = {\n /**\n * Override the default transactions collection. If you override the collection, you should ensure it has the required fields for transactions or re-use the default fields.\n *\n * @example\n *\n * ```ts\n transactions: {\n transactionsCollectionOverride: ({ defaultCollection }) => ({\n ...defaultCollection,\n fields: [\n ...defaultCollection.fields,\n {\n name: 'notes',\n label: 'Notes',\n type: 'textarea',\n },\n ],\n })\n }\n ```\n */\n transactionsCollectionOverride?: CollectionOverride\n}\n\nexport type CustomQuery = {\n depth?: number\n select?: SelectType\n where?: Where\n}\n\nexport type PaymentsConfig = {\n paymentMethods?: PaymentAdapter[]\n productsQuery?: CustomQuery\n variantsQuery?: CustomQuery\n}\n\nexport type CountryType = {\n /**\n * A user friendly name for the country.\n */\n label: string\n /**\n * The ISO 3166-1 alpha-2 country code.\n * @example 'US'\n */\n value: string\n}\n\n/**\n * Configuration for the addresses used by the Ecommerce plugin. Use this to override the default collection or fields used throughout\n */\ntype AddressesConfig = {\n /**\n * Override the default addresses collection. If you override the collection, you should ensure it has the required fields for addresses or re-use the default fields.\n *\n * @example\n * ```ts\n * addressesCollectionOverride: (defaultCollection) => {\n * return {\n * ...defaultCollection,\n * fields: [\n * ...defaultCollection.fields,\n * // add custom fields here\n * ],\n * }\n * }\n * ```\n */\n addressesCollectionOverride?: CollectionOverride\n /**\n * These fields will be applied to all locations where addresses are used, such as Orders and Transactions. Preferred use over the collectionOverride config.\n */\n addressFields?: FieldsOverride\n /**\n * Provide an array of countries to support for addresses. This will be used in the admin interface to provide a select field of countries.\n *\n * Defaults to a set of commonly used countries.\n *\n * @example\n * ```\n * [\n { label: 'United States', value: 'US' },\n { label: 'Canada', value: 'CA' },\n ]\n */\n supportedCountries?: CountryType[]\n}\n\nexport type CustomersConfig = {\n /**\n * Slug of the customers collection, defaults to 'users'.\n * This is used to link carts and orders to customers.\n */\n slug: string\n}\n\nexport type CartsConfig = {\n cartsCollectionOverride?: CollectionOverride\n}\n\nexport type InventoryConfig = {\n /**\n * Override the default field used to track inventory levels. Defaults to 'inventory'.\n */\n fieldName?: string\n}\n\nexport type CurrenciesConfig = {\n /**\n * Defaults to the first supported currency.\n *\n * @example 'USD'\n */\n defaultCurrency: string\n /**\n *\n */\n supportedCurrencies: Currency[]\n}\n\n/**\n * A function that validates a product or variant before a transaction is created or completed.\n * This should throw an error if validation fails as it will be caught by the function calling it.\n */\nexport type ProductsValidation = (args: {\n /**\n * The full currencies config, allowing you to check against supported currencies and their settings.\n */\n currenciesConfig?: CurrenciesConfig\n /**\n * The ISO 4217 currency code being usen in this transaction.\n */\n currency?: string\n /**\n * The full product data.\n */\n product: TypedCollection['products']\n /**\n * Quantity to check the inventory amount against.\n */\n quantity: number\n /**\n * The full variant data, if a variant was selected for the product otherwise it will be undefined.\n */\n variant?: TypedCollection['variants']\n}) => Promise<void> | void\n\n/**\n * A map of collection slugs used by the Ecommerce plugin.\n * Provides an easy way to track the slugs of collections even when they are overridden.\n */\nexport type CollectionSlugMap = {\n addresses: string\n carts: string\n customers: string\n orders: string\n products: string\n transactions: string\n variantOptions: string\n variants: string\n variantTypes: string\n}\n\n/**\n * Access control functions used throughout the Ecommerce plugin.\n * You must provide these when configuring the plugin.\n *\n * @example\n *\n * ```ts\n * access: {\n adminOnly,\n adminOnlyFieldAccess,\n adminOrCustomerOwner,\n adminOrPublishedStatus,\n customerOnlyFieldAccess,\n }\n ```\n */\nexport type AccessConfig = {\n /**\n * Limited to only admin users.\n */\n adminOnly: Access\n /**\n * Limited to only admin users, specifically for Field level access control.\n */\n adminOnlyFieldAccess: FieldAccess\n /**\n * Is the owner of the document via the `customer` field or is an admin.\n */\n adminOrCustomerOwner: Access\n /**\n * The document status is published or user is admin.\n */\n adminOrPublishedStatus: Access\n /**\n * Authenticated users only. Defaults to the example function.\n *\n * @example\n * anyUser: ({ req }) => !!req?.user\n */\n authenticatedOnly?: Access\n /**\n * Limited to customers only, specifically for Field level access control.\n */\n customerOnlyFieldAccess: FieldAccess\n /**\n * Entirely public access. Defaults to the example function.\n *\n * @example\n * publicAccess: () => true\n */\n publicAccess?: Access\n}\n\nexport type EcommercePluginConfig = {\n /**\n * Customise the access control for the plugin.\n *\n * @example\n * ```ts\n * ```\n */\n access: AccessConfig\n /**\n * Enable the addresses collection to allow customers, transactions and orders to have multiple addresses for shipping and billing. Accepts an override to customise the addresses collection.\n * Defaults to supporting a default set of countries.\n */\n addresses?: AddressesConfig | boolean\n /**\n * Configure the target collection used for carts.\n *\n * Defaults to true.\n */\n carts?: boolean | CartsConfig\n /**\n * Configure supported currencies and default settings.\n *\n * Defaults to supporting USD.\n */\n currencies?: CurrenciesConfig\n /**\n * Configure the target collection used for customers.\n *\n * @example\n * ```ts\n * customers: {\n * slug: 'users', // default\n * }\n *\n */\n customers: CustomersConfig\n /**\n * Enable tracking of inventory for products and variants. Accepts a config object to override the default collection settings.\n *\n * Defaults to true.\n */\n inventory?: boolean | InventoryConfig\n /**\n * Enables orders and accepts a config object to override the default collection settings.\n *\n * Defaults to true.\n */\n orders?: boolean | OrdersConfig\n /**\n * Enable tracking of payments. Accepts a config object to override the default collection settings.\n *\n * Defaults to true when the paymentMethods array is provided.\n */\n payments?: PaymentsConfig\n /**\n * Enables products and variants. Accepts a config object to override the product collection and each variant collection type.\n *\n * Defaults to true.\n */\n products?: boolean | ProductsConfig\n /**\n * Override the default slugs used across the plugin. This lets the plugin know which slugs to use for various internal operations and fields.\n */\n slugMap?: Partial<CollectionSlugMap>\n /**\n * Enable tracking of transactions. Accepts a config object to override the default collection settings.\n *\n * Defaults to true when the paymentMethods array is provided.\n */\n transactions?: boolean | TransactionsConfig\n}\n\nexport type SanitizedEcommercePluginConfig = {\n access: Required<AccessConfig>\n addresses: { addressFields: Field[] } & Omit<AddressesConfig, 'addressFields'>\n currencies: Required<CurrenciesConfig>\n inventory?: InventoryConfig\n payments: {\n paymentMethods: [] | PaymentAdapter[]\n }\n} & Omit<\n Required<EcommercePluginConfig>,\n 'access' | 'addresses' | 'currencies' | 'inventory' | 'payments'\n>\n\nexport type EcommerceCollections = TypedEcommerce['collections']\n\nexport type AddressesCollection = EcommerceCollections['addresses']\nexport type CartsCollection = EcommerceCollections['carts']\n\nexport type SyncLocalStorageConfig = {\n /**\n * Key to use for localStorage.\n * Defaults to 'cart'.\n */\n key?: string\n}\n\ntype APIProps = {\n /**\n * The route for the Payload API, defaults to `/api`.\n */\n apiRoute?: string\n /**\n * Customise the query used to fetch carts. Use this when you need to fetch additional data and optimise queries using depth, select and populate.\n *\n * Defaults to `{ depth: 0 }`.\n */\n cartsFetchQuery?: {\n depth?: number\n populate?: PopulateType\n select?: SelectType\n }\n /**\n * The route for the Payload API, defaults to ``. Eg for a Payload app running on `http://localhost:3000`, the default serverURL would be `http://localhost:3000`.\n */\n serverURL?: string\n}\n\nexport type ContextProps = {\n /**\n * The slug for the addresses collection.\n *\n * Defaults to 'addresses'.\n */\n addressesSlug?: string\n api?: APIProps\n /**\n * The slug for the carts collection.\n *\n * Defaults to 'carts'.\n */\n cartsSlug?: string\n children?: React.ReactNode\n /**\n * The configuration for currencies used in the ecommerce context.\n * This is used to handle currency formatting and calculations, defaults to USD.\n */\n currenciesConfig?: CurrenciesConfig\n /**\n * The slug for the customers collection.\n *\n * Defaults to 'users'.\n */\n customersSlug?: string\n /**\n * Enable debug mode for the ecommerce context. This will log additional information to the console.\n * Defaults to false.\n */\n debug?: boolean\n /**\n * Whether to enable support for variants in the cart.\n * This allows adding products with specific variants to the cart.\n * Defaults to false.\n */\n enableVariants?: boolean\n /**\n * Supported payment methods for the ecommerce context.\n */\n paymentMethods?: PaymentAdapterClient[]\n /**\n * Whether to enable localStorage for cart persistence.\n * Defaults to true.\n */\n syncLocalStorage?: boolean | SyncLocalStorageConfig\n}\n\n/**\n * Type used internally to represent the cart item to be added.\n */\ntype CartItemArgument = {\n /**\n * The ID of the product to add to the cart. Always required.\n */\n product: DefaultDocumentIDType\n /**\n * The ID of the variant to add to the cart. Optional, if not provided, the product will be added without a variant.\n */\n variant?: DefaultDocumentIDType\n}\n\nexport type EcommerceContextType<T extends EcommerceCollections = EcommerceCollections> = {\n /**\n * Add an item to the cart.\n */\n addItem: (item: CartItemArgument, quantity?: number) => Promise<void>\n /**\n * All current addresses for the current user.\n * This is used to manage shipping and billing addresses.\n */\n addresses?: T['addresses'][]\n /**\n * The current data of the cart.\n */\n cart?: T['addresses']\n /**\n * The ID of the current cart corresponding to the cart in the database or local storage.\n */\n cartID?: DefaultDocumentIDType\n /**\n * Clear the cart, removing all items.\n */\n clearCart: () => Promise<void>\n /**\n * Initiate a payment using the selected payment method.\n * This method should be called after the cart is ready for checkout.\n * It requires the payment method ID and any necessary payment data.\n */\n confirmOrder: (\n paymentMethodID: string,\n options?: { additionalData: Record<string, unknown> },\n ) => Promise<unknown>\n /**\n * Create a new address by providing the data.\n */\n createAddress: (data: Partial<T['addresses']>) => Promise<void>\n /**\n * The configuration for the currencies used in the ecommerce context.\n */\n currenciesConfig: CurrenciesConfig\n /**\n * The currently selected currency used for the cart and price formatting automatically.\n */\n currency: Currency\n /**\n * Decrement an item in the cart by its index ID.\n * If quantity reaches 0, the item will be removed from the cart.\n */\n decrementItem: (item: DefaultDocumentIDType) => Promise<void>\n /**\n * Increment an item in the cart by its index ID.\n */\n incrementItem: (item: DefaultDocumentIDType) => Promise<void>\n /**\n * Initiate a payment using the selected payment method.\n * This method should be called after the cart is ready for checkout.\n * It requires the payment method ID and any necessary payment data.\n */\n initiatePayment: (\n paymentMethodID: string,\n options?: { additionalData: Record<string, unknown> },\n ) => Promise<unknown>\n paymentMethods: PaymentAdapterClient[]\n /**\n * Remove an item from the cart by its index ID.\n */\n removeItem: (item: DefaultDocumentIDType) => Promise<void>\n /**\n * The name of the currently selected payment method.\n * This is used to determine which payment method to use when initiating a payment.\n */\n selectedPaymentMethod?: null | string\n /**\n * Change the currency for the cart, it defaults to the configured currency.\n * This will update the currency used for pricing and calculations.\n */\n setCurrency: (currency: string) => void\n /**\n * Update an address by providing the data and the ID.\n */\n updateAddress: (addressID: DefaultDocumentIDType, data: Partial<T['addresses']>) => Promise<void>\n}\n"],"names":[],"mappings":"AAoyBA,WAgFC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { DefaultDocumentIDType, GeneratedTypes } from 'payload';
|
|
2
|
+
/**
|
|
3
|
+
* THIS FILE IS EXTREMELY SENSITIVE PLEASE BE CAREFUL AS THERE IS EVIL AT PLAY
|
|
4
|
+
*
|
|
5
|
+
* This file is used to extract the types for the ecommerce plugin
|
|
6
|
+
* from the user's generated types. It must be kept as a .ts file
|
|
7
|
+
* and not a .tsx file, and it must not import any other files
|
|
8
|
+
* that are not strictly types. This is to prevent circular
|
|
9
|
+
* dependencies and to ensure that the types are always available.
|
|
10
|
+
*
|
|
11
|
+
* Do not add any runtime code to this file.
|
|
12
|
+
*/
|
|
13
|
+
type CartsUntyped = {
|
|
14
|
+
[key: string]: any;
|
|
15
|
+
id: DefaultDocumentIDType;
|
|
16
|
+
items?: any[];
|
|
17
|
+
subtotal?: number;
|
|
18
|
+
};
|
|
19
|
+
type AddressesUntyped = {
|
|
20
|
+
[key: string]: any;
|
|
21
|
+
id: DefaultDocumentIDType;
|
|
22
|
+
};
|
|
23
|
+
type ResolveEcommerceType<T> = 'ecommerce' extends keyof T ? T['ecommerce'] : T['ecommerceUntyped'];
|
|
24
|
+
export type TypedEcommerce = ResolveEcommerceType<GeneratedTypes>;
|
|
25
|
+
declare module 'payload' {
|
|
26
|
+
interface GeneratedTypes {
|
|
27
|
+
ecommerceUntyped: {
|
|
28
|
+
collections: {
|
|
29
|
+
addresses: AddressesUntyped;
|
|
30
|
+
carts: CartsUntyped;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
export {};
|
|
36
|
+
//# sourceMappingURL=utilities.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utilities.d.ts","sourceRoot":"","sources":["../../src/types/utilities.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAEpE;;;;;;;;;;GAUG;AAEH,KAAK,YAAY,GAAG;IAClB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;IAClB,EAAE,EAAE,qBAAqB,CAAA;IACzB,KAAK,CAAC,EAAE,GAAG,EAAE,CAAA;IACb,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB,CAAA;AAED,KAAK,gBAAgB,GAAG;IACtB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;IAClB,EAAE,EAAE,qBAAqB,CAAA;CAC1B,CAAA;AAED,KAAK,oBAAoB,CAAC,CAAC,IAAI,WAAW,SAAS,MAAM,CAAC,GACtD,CAAC,CAAC,WAAW,CAAC,GAEd,CAAC,CAAC,kBAAkB,CAAC,CAAA;AAEzB,MAAM,MAAM,cAAc,GAAG,oBAAoB,CAAC,cAAc,CAAC,CAAA;AAEjE,OAAO,QAAQ,SAAS,CAAC;IACvB,UAAiB,cAAc;QAC7B,gBAAgB,EAAE;YAChB,WAAW,EAAE;gBACX,SAAS,EAAE,gBAAgB,CAAA;gBAC3B,KAAK,EAAE,YAAY,CAAA;aACpB,CAAA;SACF,CAAA;KACF;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/types/utilities.ts"],"sourcesContent":["import type { DefaultDocumentIDType, GeneratedTypes } from 'payload'\n\n/**\n * THIS FILE IS EXTREMELY SENSITIVE PLEASE BE CAREFUL AS THERE IS EVIL AT PLAY\n *\n * This file is used to extract the types for the ecommerce plugin\n * from the user's generated types. It must be kept as a .ts file\n * and not a .tsx file, and it must not import any other files\n * that are not strictly types. This is to prevent circular\n * dependencies and to ensure that the types are always available.\n *\n * Do not add any runtime code to this file.\n */\n\ntype CartsUntyped = {\n [key: string]: any\n id: DefaultDocumentIDType\n items?: any[]\n subtotal?: number\n}\n\ntype AddressesUntyped = {\n [key: string]: any\n id: DefaultDocumentIDType\n}\n\ntype ResolveEcommerceType<T> = 'ecommerce' extends keyof T\n ? T['ecommerce']\n : // @ts-expect-error - typescript doesnt play nice here\n T['ecommerceUntyped']\n\nexport type TypedEcommerce = ResolveEcommerceType<GeneratedTypes>\n\ndeclare module 'payload' {\n export interface GeneratedTypes {\n ecommerceUntyped: {\n collections: {\n addresses: AddressesUntyped\n carts: CartsUntyped\n }\n }\n }\n}\n"],"names":[],"mappings":"AA+BA,WAAiE"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { DefaultCellComponentProps, TypedCollection } from 'payload';
|
|
2
|
-
import type { CurrenciesConfig, Currency } from '../../types.js';
|
|
2
|
+
import type { CurrenciesConfig, Currency } from '../../types/index.js';
|
|
3
3
|
type Props = {
|
|
4
4
|
cellData?: number;
|
|
5
5
|
currenciesConfig: CurrenciesConfig;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/ui/PriceCell/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,yBAAyB,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAIzE,OAAO,KAAK,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/ui/PriceCell/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,yBAAyB,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAIzE,OAAO,KAAK,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AAItE,KAAK,KAAK,GAAG;IACX,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,gBAAgB,EAAE,gBAAgB,CAAA;IAClC,QAAQ,CAAC,EAAE,QAAQ,CAAA;IACnB,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,OAAO,CAAC,eAAe,CAAC,UAAU,CAAC,CAAC,CAAA;CAC9C,GAAG,yBAAyB,CAAA;AAE7B,eAAO,MAAM,SAAS,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CA+BrC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/ui/PriceCell/index.tsx"],"sourcesContent":["'use client'\nimport type { DefaultCellComponentProps, TypedCollection } from 'payload'\n\nimport { useTranslation } from '@payloadcms/ui'\n\nimport type { CurrenciesConfig, Currency } from '../../types.js'\n\nimport { convertFromBaseValue } from '../utilities.js'\n\ntype Props = {\n cellData?: number\n currenciesConfig: CurrenciesConfig\n currency?: Currency\n path: string\n rowData: Partial<TypedCollection['products']>\n} & DefaultCellComponentProps\n\nexport const PriceCell: React.FC<Props> = (args) => {\n const { t } = useTranslation()\n const { cellData, currenciesConfig, currency: currencyFromProps, rowData } = args\n\n const currency = currencyFromProps || currenciesConfig.supportedCurrencies[0]\n\n if (!currency) {\n // @ts-expect-error - plugin translations are not typed yet\n return <span>{t('plugin-ecommerce:currencyNotSet')}</span>\n }\n\n if (\n (!cellData || typeof cellData !== 'number') &&\n 'enableVariants' in rowData &&\n rowData.enableVariants\n ) {\n // @ts-expect-error - plugin translations are not typed yet\n return <span>{t('plugin-ecommerce:priceSetInVariants')}</span>\n }\n\n if (!cellData) {\n // @ts-expect-error - plugin translations are not typed yet\n return <span>{t('plugin-ecommerce:priceNotSet')}</span>\n }\n\n return (\n <span>\n {currency.symbol}\n {convertFromBaseValue({ baseValue: cellData, currency })}\n </span>\n )\n}\n"],"names":["useTranslation","convertFromBaseValue","PriceCell","args","t","cellData","currenciesConfig","currency","currencyFromProps","rowData","supportedCurrencies","span","enableVariants","symbol","baseValue"],"mappings":"AAAA;;AAGA,SAASA,cAAc,QAAQ,iBAAgB;AAI/C,SAASC,oBAAoB,QAAQ,kBAAiB;AAUtD,OAAO,MAAMC,YAA6B,CAACC;IACzC,MAAM,EAAEC,CAAC,EAAE,GAAGJ;IACd,MAAM,EAAEK,QAAQ,EAAEC,gBAAgB,EAAEC,UAAUC,iBAAiB,EAAEC,OAAO,EAAE,GAAGN;IAE7E,MAAMI,WAAWC,qBAAqBF,iBAAiBI,mBAAmB,CAAC,EAAE;IAE7E,IAAI,CAACH,UAAU;QACb,2DAA2D;QAC3D,qBAAO,KAACI;sBAAMP,EAAE;;IAClB;IAEA,IACE,AAAC,CAAA,CAACC,YAAY,OAAOA,aAAa,QAAO,KACzC,oBAAoBI,WACpBA,QAAQG,cAAc,EACtB;QACA,2DAA2D;QAC3D,qBAAO,KAACD;sBAAMP,EAAE;;IAClB;IAEA,IAAI,CAACC,UAAU;QACb,2DAA2D;QAC3D,qBAAO,KAACM;sBAAMP,EAAE;;IAClB;IAEA,qBACE,MAACO;;YACEJ,SAASM,MAAM;YACfZ,qBAAqB;gBAAEa,WAAWT;gBAAUE;YAAS;;;AAG5D,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../../src/ui/PriceCell/index.tsx"],"sourcesContent":["'use client'\nimport type { DefaultCellComponentProps, TypedCollection } from 'payload'\n\nimport { useTranslation } from '@payloadcms/ui'\n\nimport type { CurrenciesConfig, Currency } from '../../types/index.js'\n\nimport { convertFromBaseValue } from '../utilities.js'\n\ntype Props = {\n cellData?: number\n currenciesConfig: CurrenciesConfig\n currency?: Currency\n path: string\n rowData: Partial<TypedCollection['products']>\n} & DefaultCellComponentProps\n\nexport const PriceCell: React.FC<Props> = (args) => {\n const { t } = useTranslation()\n const { cellData, currenciesConfig, currency: currencyFromProps, rowData } = args\n\n const currency = currencyFromProps || currenciesConfig.supportedCurrencies[0]\n\n if (!currency) {\n // @ts-expect-error - plugin translations are not typed yet\n return <span>{t('plugin-ecommerce:currencyNotSet')}</span>\n }\n\n if (\n (!cellData || typeof cellData !== 'number') &&\n 'enableVariants' in rowData &&\n rowData.enableVariants\n ) {\n // @ts-expect-error - plugin translations are not typed yet\n return <span>{t('plugin-ecommerce:priceSetInVariants')}</span>\n }\n\n if (!cellData) {\n // @ts-expect-error - plugin translations are not typed yet\n return <span>{t('plugin-ecommerce:priceNotSet')}</span>\n }\n\n return (\n <span>\n {currency.symbol}\n {convertFromBaseValue({ baseValue: cellData, currency })}\n </span>\n )\n}\n"],"names":["useTranslation","convertFromBaseValue","PriceCell","args","t","cellData","currenciesConfig","currency","currencyFromProps","rowData","supportedCurrencies","span","enableVariants","symbol","baseValue"],"mappings":"AAAA;;AAGA,SAASA,cAAc,QAAQ,iBAAgB;AAI/C,SAASC,oBAAoB,QAAQ,kBAAiB;AAUtD,OAAO,MAAMC,YAA6B,CAACC;IACzC,MAAM,EAAEC,CAAC,EAAE,GAAGJ;IACd,MAAM,EAAEK,QAAQ,EAAEC,gBAAgB,EAAEC,UAAUC,iBAAiB,EAAEC,OAAO,EAAE,GAAGN;IAE7E,MAAMI,WAAWC,qBAAqBF,iBAAiBI,mBAAmB,CAAC,EAAE;IAE7E,IAAI,CAACH,UAAU;QACb,2DAA2D;QAC3D,qBAAO,KAACI;sBAAMP,EAAE;;IAClB;IAEA,IACE,AAAC,CAAA,CAACC,YAAY,OAAOA,aAAa,QAAO,KACzC,oBAAoBI,WACpBA,QAAQG,cAAc,EACtB;QACA,2DAA2D;QAC3D,qBAAO,KAACD;sBAAMP,EAAE;;IAClB;IAEA,IAAI,CAACC,UAAU;QACb,2DAA2D;QAC3D,qBAAO,KAACM;sBAAMP,EAAE;;IAClB;IAEA,qBACE,MAACO;;YACEJ,SAASM,MAAM;YACfZ,qBAAqB;gBAAEa,WAAWT;gBAAUE;YAAS;;;AAG5D,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FormattedInput.d.ts","sourceRoot":"","sources":["../../../src/ui/PriceInput/FormattedInput.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAK7D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"FormattedInput.d.ts","sourceRoot":"","sources":["../../../src/ui/PriceInput/FormattedInput.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAK7D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AAKpD,UAAU,KAAK;IACb,QAAQ,CAAC,EAAE,QAAQ,CAAA;IACnB,WAAW,CAAC,EAAE,iBAAiB,CAAA;IAC/B,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,KAAK,CAAC,EAAE,WAAW,CAAA;IACnB,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,mBAAmB,EAAE,QAAQ,EAAE,CAAA;CAChC;AAID,eAAO,MAAM,cAAc,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CA0I1C,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/ui/PriceInput/FormattedInput.tsx"],"sourcesContent":["'use client'\n\nimport type { StaticDescription, StaticLabel } from 'payload'\n\nimport { FieldDescription, FieldLabel, useField, useFormFields } from '@payloadcms/ui'\nimport { useCallback, useEffect, useMemo, useRef, useState } from 'react'\n\nimport type { Currency } from '../../types.js'\n\nimport { USD } from '../../currencies/index.js'\nimport { convertFromBaseValue, convertToBaseValue } from '../utilities.js'\n\ninterface Props {\n currency?: Currency\n description?: StaticDescription\n disabled?: boolean\n error?: string\n id?: string\n label?: StaticLabel\n path: string\n placeholder?: string\n readOnly?: boolean\n supportedCurrencies: Currency[]\n}\n\nconst baseClass = 'formattedPrice'\n\nexport const FormattedInput: React.FC<Props> = ({\n id: idFromProps,\n currency: currencyFromProps,\n description,\n disabled = false,\n label,\n path,\n placeholder = '0.00',\n readOnly,\n supportedCurrencies,\n}) => {\n const { setValue, value } = useField<number>({ path })\n const [displayValue, setDisplayValue] = useState<string>('')\n\n const inputRef = useRef<HTMLInputElement>(null)\n const isFirstRender = useRef(true)\n const debounceTimer = useRef<NodeJS.Timeout | null>(null)\n\n const parentPath = path.split('.').slice(0, -1).join('.')\n const currencyPath = parentPath ? `${parentPath}.currency` : 'currency'\n\n const currencyFromSelectField = useFormFields(([fields, _]) => fields[currencyPath])\n\n const currencyCode = currencyFromProps?.code ?? (currencyFromSelectField?.value as string)\n const id = idFromProps || path\n\n const currency = useMemo<Currency>(() => {\n if (currencyCode && supportedCurrencies) {\n const foundCurrency = supportedCurrencies.find(\n (supportedCurrency) => supportedCurrency.code === currencyCode,\n )\n\n return foundCurrency ?? supportedCurrencies[0] ?? USD\n }\n\n return supportedCurrencies[0] ?? USD\n }, [currencyCode, supportedCurrencies])\n\n useEffect(() => {\n if (isFirstRender.current) {\n isFirstRender.current = false\n\n if (value === undefined || value === null) {\n setDisplayValue('')\n } else {\n setDisplayValue(convertFromBaseValue({ baseValue: value, currency }))\n }\n }\n }, [currency, value, currencyFromProps])\n\n const updateValue = useCallback(\n (inputValue: string) => {\n if (inputValue === '') {\n setValue(null)\n\n return\n }\n\n const baseValue = convertToBaseValue({ currency, displayValue: inputValue })\n\n setValue(baseValue)\n },\n [currency, setValue],\n )\n\n const handleInputChange = useCallback(\n (e: React.ChangeEvent<HTMLInputElement>) => {\n const inputValue = e.target.value\n\n if (!/^\\d*(?:\\.\\d*)?$/.test(inputValue) && inputValue !== '') {\n return\n }\n\n setDisplayValue(inputValue)\n\n // Clear any existing timer\n if (debounceTimer.current) {\n clearTimeout(debounceTimer.current)\n }\n\n // Only update the base value after a delay to avoid formatting while typing\n debounceTimer.current = setTimeout(() => {\n updateValue(inputValue)\n }, 500)\n },\n [updateValue, setDisplayValue],\n )\n\n const handleInputBlur = useCallback(() => {\n if (displayValue === '') {\n return\n }\n\n // Clear any pending debounce\n if (debounceTimer.current) {\n clearTimeout(debounceTimer.current)\n debounceTimer.current = null\n }\n\n const baseValue = convertToBaseValue({ currency, displayValue })\n const formattedValue = convertFromBaseValue({ baseValue, currency })\n\n if (value != baseValue) {\n setValue(baseValue)\n }\n\n setDisplayValue(formattedValue)\n }, [currency, displayValue, setValue, value])\n\n return (\n <div className={`field-type number ${baseClass}`}>\n {label && <FieldLabel as=\"label\" htmlFor={id} label={label} />}\n\n <div className={`${baseClass}Container`}>\n <div className={`${baseClass}CurrencySymbol`}>\n <span>{currency.symbol}</span>\n </div>\n\n {/* eslint-disable-next-line jsx-a11y/control-has-associated-label */}\n <input\n className={`${baseClass}Input`}\n disabled={disabled || readOnly}\n id={id}\n onBlur={handleInputBlur}\n onChange={handleInputChange}\n placeholder={placeholder}\n ref={inputRef}\n type=\"text\"\n value={displayValue}\n />\n </div>\n <FieldDescription\n className={`${baseClass}Description`}\n description={description}\n path={path}\n />\n </div>\n )\n}\n"],"names":["FieldDescription","FieldLabel","useField","useFormFields","useCallback","useEffect","useMemo","useRef","useState","USD","convertFromBaseValue","convertToBaseValue","baseClass","FormattedInput","id","idFromProps","currency","currencyFromProps","description","disabled","label","path","placeholder","readOnly","supportedCurrencies","setValue","value","displayValue","setDisplayValue","inputRef","isFirstRender","debounceTimer","parentPath","split","slice","join","currencyPath","currencyFromSelectField","fields","_","currencyCode","code","foundCurrency","find","supportedCurrency","current","undefined","baseValue","updateValue","inputValue","handleInputChange","e","target","test","clearTimeout","setTimeout","handleInputBlur","formattedValue","div","className","as","htmlFor","span","symbol","input","onBlur","onChange","ref","type"],"mappings":"AAAA;;AAIA,SAASA,gBAAgB,EAAEC,UAAU,EAAEC,QAAQ,EAAEC,aAAa,QAAQ,iBAAgB;AACtF,SAASC,WAAW,EAAEC,SAAS,EAAEC,OAAO,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,QAAO;AAIzE,SAASC,GAAG,QAAQ,4BAA2B;AAC/C,SAASC,oBAAoB,EAAEC,kBAAkB,QAAQ,kBAAiB;AAe1E,MAAMC,YAAY;AAElB,OAAO,MAAMC,iBAAkC,CAAC,EAC9CC,IAAIC,WAAW,EACfC,UAAUC,iBAAiB,EAC3BC,WAAW,EACXC,WAAW,KAAK,EAChBC,KAAK,EACLC,IAAI,EACJC,cAAc,MAAM,EACpBC,QAAQ,EACRC,mBAAmB,EACpB;IACC,MAAM,EAAEC,QAAQ,EAAEC,KAAK,EAAE,GAAGxB,SAAiB;QAAEmB;IAAK;IACpD,MAAM,CAACM,cAAcC,gBAAgB,GAAGpB,SAAiB;IAEzD,MAAMqB,WAAWtB,OAAyB;IAC1C,MAAMuB,gBAAgBvB,OAAO;IAC7B,MAAMwB,gBAAgBxB,OAA8B;IAEpD,MAAMyB,aAAaX,KAAKY,KAAK,CAAC,KAAKC,KAAK,CAAC,GAAG,CAAC,GAAGC,IAAI,CAAC;IACrD,MAAMC,eAAeJ,aAAa,GAAGA,WAAW,SAAS,CAAC,GAAG;IAE7D,MAAMK,0BAA0BlC,cAAc,CAAC,CAACmC,QAAQC,EAAE,GAAKD,MAA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,IAAIuB,iBAAiB,IAAI;YACvB;QACF;QAEA,6BAA6B;QAC7B,IAAII,cAAcc,OAAO,EAAE;YACzBS,aAAavB,cAAcc,OAAO;YAClCd,cAAcc,OAAO,GAAG;QAC1B;QAEA,MAAME,YAAYpC,mBAAmB;YAAEK;YAAUW;QAAa;QAC9D,MAAM8B,iBAAiB/C,qBAAqB;YAAEqC;YAAW/B;QAAS;QAElE,IAAIU,SAASqB,WAAW;YACtBtB,SAASsB;QACX;QAEAnB,gBAAgB6B;IAClB,GAAG;QAACzC;QAAUW;QAAcF;QAAUC;KAAM;IAE5C,qBACE,MAACgC;QAAIC,WAAW,CAAC,kBAAkB,EAAE/C,WAAW;;YAC7CQ,uBAAS,KAACnB;gBAAW2D,IAAG;gBAAQC,SAAS/C;gBAAIM,OAAOA;;0BAErD,MAACsC;gBAAIC,WAAW,GAAG/C,UAAU,SAAS,CAAC;;kCACrC,KAAC8C;wBAAIC,WAAW,GAAG/C,UAAU,cAAc,CAAC;kCAC1C,cAAA,KAACkD;sCAAM9C,SAAS+C,MAAM;;;kCAIxB,KAACC;wBACCL,WAAW,GAAG/C,UAAU,KAAK,CAAC;wBAC9BO,UAAUA,YAAYI;wBACtBT,IAAIA;wBACJmD,QAAQT;wBACRU,UAAUhB;wBACV5B,aAAaA;wBACb6C,KAAKtC;wBACLuC,MAAK;wBACL1C,OAAOC;;;;0BAGX,KAAC3B;gBACC2D,WAAW,GAAG/C,UAAU,WAAW,CAAC;gBACpCM,aAAaA;gBACbG,MAAMA;;;;AAId,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../../src/ui/PriceInput/FormattedInput.tsx"],"sourcesContent":["'use client'\n\nimport type { StaticDescription, StaticLabel } from 'payload'\n\nimport { FieldDescription, FieldLabel, useField, useFormFields } from '@payloadcms/ui'\nimport { useCallback, useEffect, useMemo, useRef, useState } from 'react'\n\nimport type { Currency } from '../../types/index.js'\n\nimport { USD } from '../../currencies/index.js'\nimport { convertFromBaseValue, convertToBaseValue } from '../utilities.js'\n\ninterface Props {\n currency?: Currency\n description?: StaticDescription\n disabled?: boolean\n error?: string\n id?: string\n label?: StaticLabel\n path: string\n placeholder?: string\n readOnly?: boolean\n supportedCurrencies: Currency[]\n}\n\nconst baseClass = 'formattedPrice'\n\nexport const FormattedInput: React.FC<Props> = ({\n id: idFromProps,\n currency: currencyFromProps,\n description,\n disabled = false,\n label,\n path,\n placeholder = '0.00',\n readOnly,\n supportedCurrencies,\n}) => {\n const { setValue, value } = useField<number>({ path })\n const [displayValue, setDisplayValue] = useState<string>('')\n\n const inputRef = useRef<HTMLInputElement>(null)\n const isFirstRender = useRef(true)\n const debounceTimer = useRef<NodeJS.Timeout | null>(null)\n\n const parentPath = path.split('.').slice(0, -1).join('.')\n const currencyPath = parentPath ? `${parentPath}.currency` : 'currency'\n\n const currencyFromSelectField = useFormFields(([fields, _]) => fields[currencyPath])\n\n const currencyCode = currencyFromProps?.code ?? (currencyFromSelectField?.value as string)\n const id = idFromProps || path\n\n const currency = useMemo<Currency>(() => {\n if (currencyCode && supportedCurrencies) {\n const foundCurrency = supportedCurrencies.find(\n (supportedCurrency) => supportedCurrency.code === currencyCode,\n )\n\n return foundCurrency ?? supportedCurrencies[0] ?? USD\n }\n\n return supportedCurrencies[0] ?? USD\n }, [currencyCode, supportedCurrencies])\n\n useEffect(() => {\n if (isFirstRender.current) {\n isFirstRender.current = false\n\n if (value === undefined || value === null) {\n setDisplayValue('')\n } else {\n setDisplayValue(convertFromBaseValue({ baseValue: value, currency }))\n }\n }\n }, [currency, value, currencyFromProps])\n\n const updateValue = useCallback(\n (inputValue: string) => {\n if (inputValue === '') {\n setValue(null)\n\n return\n }\n\n const baseValue = convertToBaseValue({ currency, displayValue: inputValue })\n\n setValue(baseValue)\n },\n [currency, setValue],\n )\n\n const handleInputChange = useCallback(\n (e: React.ChangeEvent<HTMLInputElement>) => {\n const inputValue = e.target.value\n\n if (!/^\\d*(?:\\.\\d*)?$/.test(inputValue) && inputValue !== '') {\n return\n }\n\n setDisplayValue(inputValue)\n\n // Clear any existing timer\n if (debounceTimer.current) {\n clearTimeout(debounceTimer.current)\n }\n\n // Only update the base value after a delay to avoid formatting while typing\n debounceTimer.current = setTimeout(() => {\n updateValue(inputValue)\n }, 500)\n },\n [updateValue, setDisplayValue],\n )\n\n const handleInputBlur = useCallback(() => {\n if (displayValue === '') {\n return\n }\n\n // Clear any pending debounce\n if (debounceTimer.current) {\n clearTimeout(debounceTimer.current)\n debounceTimer.current = null\n }\n\n const baseValue = convertToBaseValue({ currency, displayValue })\n const formattedValue = convertFromBaseValue({ baseValue, currency })\n\n if (value != baseValue) {\n setValue(baseValue)\n }\n\n setDisplayValue(formattedValue)\n }, [currency, displayValue, setValue, value])\n\n return (\n <div className={`field-type number ${baseClass}`}>\n {label && <FieldLabel as=\"label\" htmlFor={id} label={label} />}\n\n <div className={`${baseClass}Container`}>\n <div className={`${baseClass}CurrencySymbol`}>\n <span>{currency.symbol}</span>\n </div>\n\n {/* eslint-disable-next-line jsx-a11y/control-has-associated-label */}\n <input\n className={`${baseClass}Input`}\n disabled={disabled || readOnly}\n id={id}\n onBlur={handleInputBlur}\n onChange={handleInputChange}\n placeholder={placeholder}\n ref={inputRef}\n type=\"text\"\n value={displayValue}\n />\n </div>\n <FieldDescription\n className={`${baseClass}Description`}\n description={description}\n path={path}\n />\n </div>\n )\n}\n"],"names":["FieldDescription","FieldLabel","useField","useFormFields","useCallback","useEffect","useMemo","useRef","useState","USD","convertFromBaseValue","convertToBaseValue","baseClass","FormattedInput","id","idFromProps","currency","currencyFromProps","description","disabled","label","path","placeholder","readOnly","supportedCurrencies","setValue","value","displayValue","setDisplayValue","inputRef","isFirstRender","debounceTimer","parentPath","split","slice","join","currencyPath","currencyFromSelectField","fields","_","currencyCode","code","foundCurrency","find","supportedCurrency","current","undefined","baseValue","updateValue","inputValue","handleInputChange","e","target","test","clearTimeout","setTimeout","handleInputBlur","formattedValue","div","className","as","htmlFor","span","symbol","input","onBlur","onChange","ref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6B;IAClB,GAAG;QAACzC;QAAUW;QAAcF;QAAUC;KAAM;IAE5C,qBACE,MAACgC;QAAIC,WAAW,CAAC,kBAAkB,EAAE/C,WAAW;;YAC7CQ,uBAAS,KAACnB;gBAAW2D,IAAG;gBAAQC,SAAS/C;gBAAIM,OAAOA;;0BAErD,MAACsC;gBAAIC,WAAW,GAAG/C,UAAU,SAAS,CAAC;;kCACrC,KAAC8C;wBAAIC,WAAW,GAAG/C,UAAU,cAAc,CAAC;kCAC1C,cAAA,KAACkD;sCAAM9C,SAAS+C,MAAM;;;kCAIxB,KAACC;wBACCL,WAAW,GAAG/C,UAAU,KAAK,CAAC;wBAC9BO,UAAUA,YAAYI;wBACtBT,IAAIA;wBACJmD,QAAQT;wBACRU,UAAUhB;wBACV5B,aAAaA;wBACb6C,KAAKtC;wBACLuC,MAAK;wBACL1C,OAAOC;;;;0BAGX,KAAC3B;gBACC2D,WAAW,GAAG/C,UAAU,WAAW,CAAC;gBACpCM,aAAaA;gBACbG,MAAMA;;;;AAId,EAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { NumberFieldServerProps } from 'payload';
|
|
2
2
|
import './index.css';
|
|
3
|
-
import type { CurrenciesConfig, Currency } from '../../types.js';
|
|
3
|
+
import type { CurrenciesConfig, Currency } from '../../types/index.js';
|
|
4
4
|
type Props = {
|
|
5
5
|
currenciesConfig: CurrenciesConfig;
|
|
6
6
|
currency?: Currency;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/ui/PriceInput/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAA;AAErD,OAAO,aAAa,CAAA;AAEpB,OAAO,KAAK,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/ui/PriceInput/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAA;AAErD,OAAO,aAAa,CAAA;AAEpB,OAAO,KAAK,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AAItE,KAAK,KAAK,GAAG;IACX,gBAAgB,EAAE,gBAAgB,CAAA;IAClC,QAAQ,CAAC,EAAE,QAAQ,CAAA;IACnB,IAAI,EAAE,MAAM,CAAA;CACb,GAAG,sBAAsB,CAAA;AAE1B,eAAO,MAAM,UAAU,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CA6BtC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/ui/PriceInput/index.tsx"],"sourcesContent":["import type { NumberFieldServerProps } from 'payload'\n\nimport './index.css'\n\nimport type { CurrenciesConfig, Currency } from '../../types.js'\n\nimport { FormattedInput } from './FormattedInput.js'\n\ntype Props = {\n currenciesConfig: CurrenciesConfig\n currency?: Currency\n path: string\n} & NumberFieldServerProps\n\nexport const PriceInput: React.FC<Props> = (args) => {\n const {\n clientField: { label },\n currenciesConfig,\n currency: currencyFromProps,\n field,\n i18n: { t },\n i18n,\n path,\n readOnly,\n } = args\n\n const description = field.admin?.description\n ? typeof field.admin.description === 'function'\n ? // @ts-expect-error - weird type issue on 't' here\n field.admin.description({ i18n, t })\n : field.admin.description\n : undefined\n\n return (\n <FormattedInput\n currency={currencyFromProps}\n description={description}\n label={label}\n path={path}\n readOnly={readOnly}\n supportedCurrencies={currenciesConfig?.supportedCurrencies}\n />\n )\n}\n"],"names":["FormattedInput","PriceInput","args","clientField","label","currenciesConfig","currency","currencyFromProps","field","i18n","t","path","readOnly","description","admin","undefined","supportedCurrencies"],"mappings":";AAEA,OAAO,cAAa;AAIpB,SAASA,cAAc,QAAQ,sBAAqB;AAQpD,OAAO,MAAMC,aAA8B,CAACC;IAC1C,MAAM,EACJC,aAAa,EAAEC,KAAK,EAAE,EACtBC,gBAAgB,EAChBC,UAAUC,iBAAiB,EAC3BC,KAAK,EACLC,MAAM,EAAEC,CAAC,EAAE,EACXD,IAAI,EACJE,IAAI,EACJC,QAAQ,EACT,GAAGV;IAEJ,MAAMW,cAAcL,MAAMM,KAAK,EAAED,cAC7B,OAAOL,MAAMM,KAAK,CAACD,WAAW,KAAK,aAEjCL,MAAMM,KAAK,CAACD,WAAW,CAAC;QAAEJ;QAAMC;IAAE,KAClCF,MAAMM,KAAK,CAACD,WAAW,GACzBE;IAEJ,qBACE,KAACf;QACCM,UAAUC;QACVM,aAAaA;QACbT,OAAOA;QACPO,MAAMA;QACNC,UAAUA;QACVI,qBAAqBX,kBAAkBW;;AAG7C,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../../src/ui/PriceInput/index.tsx"],"sourcesContent":["import type { NumberFieldServerProps } from 'payload'\n\nimport './index.css'\n\nimport type { CurrenciesConfig, Currency } from '../../types/index.js'\n\nimport { FormattedInput } from './FormattedInput.js'\n\ntype Props = {\n currenciesConfig: CurrenciesConfig\n currency?: Currency\n path: string\n} & NumberFieldServerProps\n\nexport const PriceInput: React.FC<Props> = (args) => {\n const {\n clientField: { label },\n currenciesConfig,\n currency: currencyFromProps,\n field,\n i18n: { t },\n i18n,\n path,\n readOnly,\n } = args\n\n const description = field.admin?.description\n ? typeof field.admin.description === 'function'\n ? // @ts-expect-error - weird type issue on 't' here\n field.admin.description({ i18n, t })\n : field.admin.description\n : undefined\n\n return (\n <FormattedInput\n currency={currencyFromProps}\n description={description}\n label={label}\n path={path}\n readOnly={readOnly}\n supportedCurrencies={currenciesConfig?.supportedCurrencies}\n />\n )\n}\n"],"names":["FormattedInput","PriceInput","args","clientField","label","currenciesConfig","currency","currencyFromProps","field","i18n","t","path","readOnly","description","admin","undefined","supportedCurrencies"],"mappings":";AAEA,OAAO,cAAa;AAIpB,SAASA,cAAc,QAAQ,sBAAqB;AAQpD,OAAO,MAAMC,aAA8B,CAACC;IAC1C,MAAM,EACJC,aAAa,EAAEC,KAAK,EAAE,EACtBC,gBAAgB,EAChBC,UAAUC,iBAAiB,EAC3BC,KAAK,EACLC,MAAM,EAAEC,CAAC,EAAE,EACXD,IAAI,EACJE,IAAI,EACJC,QAAQ,EACT,GAAGV;IAEJ,MAAMW,cAAcL,MAAMM,KAAK,EAAED,cAC7B,OAAOL,MAAMM,KAAK,CAACD,WAAW,KAAK,aAEjCL,MAAMM,KAAK,CAACD,WAAW,CAAC;QAAEJ;QAAMC;IAAE,KAClCF,MAAMM,KAAK,CAACD,WAAW,GACzBE;IAEJ,qBACE,KAACf;QACCM,UAAUC;QACVM,aAAaA;QACbT,OAAOA;QACPO,MAAMA;QACNC,UAAUA;QACVI,qBAAqBX,kBAAkBW;;AAG7C,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/ui/PriceRowLabel/index.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/ui/PriceRowLabel/index.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AAE5D,OAAO,aAAa,CAAA;AAGpB,KAAK,KAAK,GAAG;IACX,gBAAgB,EAAE,gBAAgB,CAAA;CACnC,CAAA;AAED,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CAyCzC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/ui/PriceRowLabel/index.tsx"],"sourcesContent":["'use client'\n\nimport { useRowLabel } from '@payloadcms/ui'\nimport { useMemo } from 'react'\n\nimport type { CurrenciesConfig } from '../../types.js'\n\nimport './index.css'\nimport { convertFromBaseValue } from '../utilities.js'\n\ntype Props = {\n currenciesConfig: CurrenciesConfig\n}\n\nexport const PriceRowLabel: React.FC<Props> = (props) => {\n const { currenciesConfig } = props\n const { defaultCurrency, supportedCurrencies } = currenciesConfig\n\n const { data } = useRowLabel<{ amount: number; currency: string }>()\n\n const currency = useMemo(() => {\n if (data.currency) {\n return supportedCurrencies.find((c) => c.code === data.currency) ?? supportedCurrencies[0]\n }\n\n const fallbackCurrency = supportedCurrencies.find((c) => c.code === defaultCurrency)\n\n if (fallbackCurrency) {\n return fallbackCurrency\n }\n\n return supportedCurrencies[0]\n }, [data.currency, supportedCurrencies, defaultCurrency])\n\n const amount = useMemo(() => {\n if (data.amount) {\n return convertFromBaseValue({ baseValue: data.amount, currency: currency! })\n }\n\n return '0'\n }, [currency, data.amount])\n\n return (\n <div className=\"priceRowLabel\">\n <div className=\"priceLabel\">Price:</div>\n\n <div className=\"priceValue\">\n <span>\n {currency?.symbol}\n {amount}\n </span>\n <span>({data.currency})</span>\n </div>\n </div>\n )\n}\n"],"names":["useRowLabel","useMemo","convertFromBaseValue","PriceRowLabel","props","currenciesConfig","defaultCurrency","supportedCurrencies","data","currency","find","c","code","fallbackCurrency","amount","baseValue","div","className","span","symbol"],"mappings":"AAAA;;AAEA,SAASA,WAAW,QAAQ,iBAAgB;AAC5C,SAASC,OAAO,QAAQ,QAAO;AAI/B,OAAO,cAAa;AACpB,SAASC,oBAAoB,QAAQ,kBAAiB;AAMtD,OAAO,MAAMC,gBAAiC,CAACC;IAC7C,MAAM,EAAEC,gBAAgB,EAAE,GAAGD;IAC7B,MAAM,EAAEE,eAAe,EAAEC,mBAAmB,EAAE,GAAGF;IAEjD,MAAM,EAAEG,IAAI,EAAE,GAAGR;IAEjB,MAAMS,WAAWR,QAAQ;QACvB,IAAIO,KAAKC,QAAQ,EAAE;YACjB,OAAOF,oBAAoBG,IAAI,CAAC,CAACC,IAAMA,EAAEC,IAAI,KAAKJ,KAAKC,QAAQ,KAAKF,mBAAmB,CAAC,EAAE;QAC5F;QAEA,MAAMM,mBAAmBN,oBAAoBG,IAAI,CAAC,CAACC,IAAMA,EAAEC,IAAI,KAAKN;QAEpE,IAAIO,kBAAkB;YACpB,OAAOA;QACT;QAEA,OAAON,mBAAmB,CAAC,EAAE;IAC/B,GAAG;QAACC,KAAKC,QAAQ;QAAEF;QAAqBD;KAAgB;IAExD,MAAMQ,SAASb,QAAQ;QACrB,IAAIO,KAAKM,MAAM,EAAE;YACf,OAAOZ,qBAAqB;gBAAEa,WAAWP,KAAKM,MAAM;gBAAEL,UAAUA;YAAU;QAC5E;QAEA,OAAO;IACT,GAAG;QAACA;QAAUD,KAAKM,MAAM;KAAC;IAE1B,qBACE,MAACE;QAAIC,WAAU;;0BACb,KAACD;gBAAIC,WAAU;0BAAa;;0BAE5B,MAACD;gBAAIC,WAAU;;kCACb,MAACC;;4BACET,UAAUU;4BACVL;;;kCAEH,MAACI;;4BAAK;4BAAEV,KAAKC,QAAQ;4BAAC;;;;;;;AAI9B,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../../src/ui/PriceRowLabel/index.tsx"],"sourcesContent":["'use client'\n\nimport { useRowLabel } from '@payloadcms/ui'\nimport { useMemo } from 'react'\n\nimport type { CurrenciesConfig } from '../../types/index.js'\n\nimport './index.css'\nimport { convertFromBaseValue } from '../utilities.js'\n\ntype Props = {\n currenciesConfig: CurrenciesConfig\n}\n\nexport const PriceRowLabel: React.FC<Props> = (props) => {\n const { currenciesConfig } = props\n const { defaultCurrency, supportedCurrencies } = currenciesConfig\n\n const { data } = useRowLabel<{ amount: number; currency: string }>()\n\n const currency = useMemo(() => {\n if (data.currency) {\n return supportedCurrencies.find((c) => c.code === data.currency) ?? supportedCurrencies[0]\n }\n\n const fallbackCurrency = supportedCurrencies.find((c) => c.code === defaultCurrency)\n\n if (fallbackCurrency) {\n return fallbackCurrency\n }\n\n return supportedCurrencies[0]\n }, [data.currency, supportedCurrencies, defaultCurrency])\n\n const amount = useMemo(() => {\n if (data.amount) {\n return convertFromBaseValue({ baseValue: data.amount, currency: currency! })\n }\n\n return '0'\n }, [currency, data.amount])\n\n return (\n <div className=\"priceRowLabel\">\n <div className=\"priceLabel\">Price:</div>\n\n <div className=\"priceValue\">\n <span>\n {currency?.symbol}\n {amount}\n </span>\n <span>({data.currency})</span>\n </div>\n </div>\n )\n}\n"],"names":["useRowLabel","useMemo","convertFromBaseValue","PriceRowLabel","props","currenciesConfig","defaultCurrency","supportedCurrencies","data","currency","find","c","code","fallbackCurrency","amount","baseValue","div","className","span","symbol"],"mappings":"AAAA;;AAEA,SAASA,WAAW,QAAQ,iBAAgB;AAC5C,SAASC,OAAO,QAAQ,QAAO;AAI/B,OAAO,cAAa;AACpB,SAASC,oBAAoB,QAAQ,kBAAiB;AAMtD,OAAO,MAAMC,gBAAiC,CAACC;IAC7C,MAAM,EAAEC,gBAAgB,EAAE,GAAGD;IAC7B,MAAM,EAAEE,eAAe,EAAEC,mBAAmB,EAAE,GAAGF;IAEjD,MAAM,EAAEG,IAAI,EAAE,GAAGR;IAEjB,MAAMS,WAAWR,QAAQ;QACvB,IAAIO,KAAKC,QAAQ,EAAE;YACjB,OAAOF,oBAAoBG,IAAI,CAAC,CAACC,IAAMA,EAAEC,IAAI,KAAKJ,KAAKC,QAAQ,KAAKF,mBAAmB,CAAC,EAAE;QAC5F;QAEA,MAAMM,mBAAmBN,oBAAoBG,IAAI,CAAC,CAACC,IAAMA,EAAEC,IAAI,KAAKN;QAEpE,IAAIO,kBAAkB;YACpB,OAAOA;QACT;QAEA,OAAON,mBAAmB,CAAC,EAAE;IAC/B,GAAG;QAACC,KAAKC,QAAQ;QAAEF;QAAqBD;KAAgB;IAExD,MAAMQ,SAASb,QAAQ;QACrB,IAAIO,KAAKM,MAAM,EAAE;YACf,OAAOZ,qBAAqB;gBAAEa,WAAWP,KAAKM,MAAM;gBAAEL,UAAUA;YAAU;QAC5E;QAEA,OAAO;IACT,GAAG;QAACA;QAAUD,KAAKM,MAAM;KAAC;IAE1B,qBACE,MAACE;QAAIC,WAAU;;0BACb,KAACD;gBAAIC,WAAU;0BAAa;;0BAE5B,MAACD;gBAAIC,WAAU;;kCACb,MAACC;;4BACET,UAAUU;4BACVL;;;kCAEH,MAACI;;4BAAK;4BAAEV,KAAKC,QAAQ;4BAAC;;;;;;;AAI9B,EAAC"}
|
package/dist/ui/utilities.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utilities.d.ts","sourceRoot":"","sources":["../../src/ui/utilities.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"utilities.d.ts","sourceRoot":"","sources":["../../src/ui/utilities.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAEjD;;GAEG;AACH,eAAO,MAAM,kBAAkB,gCAG5B;IACD,QAAQ,EAAE,QAAQ,CAAA;IAClB,YAAY,EAAE,MAAM,CAAA;CACrB,KAAG,MAaH,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,oBAAoB,6BAG9B;IACD,SAAS,EAAE,MAAM,CAAA;IACjB,QAAQ,EAAE,QAAQ,CAAA;CACnB,KAAG,MAUH,CAAA"}
|
package/dist/ui/utilities.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/ui/utilities.ts"],"sourcesContent":["import type { Currency } from '../types.js'\n\n/**\n * Convert display value with decimal point to base value (e.g., $25.00 to 2500)\n */\nexport const convertToBaseValue = ({\n currency,\n displayValue,\n}: {\n currency: Currency\n displayValue: string\n}): number => {\n if (!currency) {\n return parseFloat(displayValue)\n }\n\n // Remove currency symbol and any non-numeric characters except decimal\n const cleanValue = displayValue.replace(currency.symbol, '').replace(/[^0-9.]/g, '')\n\n // Parse the clean value to a float\n const floatValue = parseFloat(cleanValue || '0')\n\n // Convert to the base value (e.g., cents for USD)\n return Math.round(floatValue * Math.pow(10, currency.decimals))\n}\n\n/**\n * Convert base value to display value with decimal point (e.g., 2500 to $25.00)\n */\nexport const convertFromBaseValue = ({\n baseValue,\n currency,\n}: {\n baseValue: number\n currency: Currency\n}): string => {\n if (!currency) {\n return baseValue.toString()\n }\n\n // Convert from base value (e.g., cents) to decimal value (e.g., dollars)\n const decimalValue = baseValue / Math.pow(10, currency.decimals)\n\n // Format with the correct number of decimal places\n return decimalValue.toFixed(currency.decimals)\n}\n"],"names":["convertToBaseValue","currency","displayValue","parseFloat","cleanValue","replace","symbol","floatValue","Math","round","pow","decimals","convertFromBaseValue","baseValue","toString","decimalValue","toFixed"],"mappings":"AAEA;;CAEC,GACD,OAAO,MAAMA,qBAAqB,CAAC,EACjCC,QAAQ,EACRC,YAAY,EAIb;IACC,IAAI,CAACD,UAAU;QACb,OAAOE,WAAWD;IACpB;IAEA,uEAAuE;IACvE,MAAME,aAAaF,aAAaG,OAAO,CAACJ,SAASK,MAAM,EAAE,IAAID,OAAO,CAAC,YAAY;IAEjF,mCAAmC;IACnC,MAAME,aAAaJ,WAAWC,cAAc;IAE5C,kDAAkD;IAClD,OAAOI,KAAKC,KAAK,CAACF,aAAaC,KAAKE,GAAG,CAAC,IAAIT,SAASU,QAAQ;AAC/D,EAAC;AAED;;CAEC,GACD,OAAO,MAAMC,uBAAuB,CAAC,EACnCC,SAAS,EACTZ,QAAQ,EAIT;IACC,IAAI,CAACA,UAAU;QACb,OAAOY,UAAUC,QAAQ;IAC3B;IAEA,yEAAyE;IACzE,MAAMC,eAAeF,YAAYL,KAAKE,GAAG,CAAC,IAAIT,SAASU,QAAQ;IAE/D,mDAAmD;IACnD,OAAOI,aAAaC,OAAO,CAACf,SAASU,QAAQ;AAC/C,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../src/ui/utilities.ts"],"sourcesContent":["import type { Currency } from '../types/index.js'\n\n/**\n * Convert display value with decimal point to base value (e.g., $25.00 to 2500)\n */\nexport const convertToBaseValue = ({\n currency,\n displayValue,\n}: {\n currency: Currency\n displayValue: string\n}): number => {\n if (!currency) {\n return parseFloat(displayValue)\n }\n\n // Remove currency symbol and any non-numeric characters except decimal\n const cleanValue = displayValue.replace(currency.symbol, '').replace(/[^0-9.]/g, '')\n\n // Parse the clean value to a float\n const floatValue = parseFloat(cleanValue || '0')\n\n // Convert to the base value (e.g., cents for USD)\n return Math.round(floatValue * Math.pow(10, currency.decimals))\n}\n\n/**\n * Convert base value to display value with decimal point (e.g., 2500 to $25.00)\n */\nexport const convertFromBaseValue = ({\n baseValue,\n currency,\n}: {\n baseValue: number\n currency: Currency\n}): string => {\n if (!currency) {\n return baseValue.toString()\n }\n\n // Convert from base value (e.g., cents) to decimal value (e.g., dollars)\n const decimalValue = baseValue / Math.pow(10, currency.decimals)\n\n // Format with the correct number of decimal places\n return decimalValue.toFixed(currency.decimals)\n}\n"],"names":["convertToBaseValue","currency","displayValue","parseFloat","cleanValue","replace","symbol","floatValue","Math","round","pow","decimals","convertFromBaseValue","baseValue","toString","decimalValue","toFixed"],"mappings":"AAEA;;CAEC,GACD,OAAO,MAAMA,qBAAqB,CAAC,EACjCC,QAAQ,EACRC,YAAY,EAIb;IACC,IAAI,CAACD,UAAU;QACb,OAAOE,WAAWD;IACpB;IAEA,uEAAuE;IACvE,MAAME,aAAaF,aAAaG,OAAO,CAACJ,SAASK,MAAM,EAAE,IAAID,OAAO,CAAC,YAAY;IAEjF,mCAAmC;IACnC,MAAME,aAAaJ,WAAWC,cAAc;IAE5C,kDAAkD;IAClD,OAAOI,KAAKC,KAAK,CAACF,aAAaC,KAAKE,GAAG,CAAC,IAAIT,SAASU,QAAQ;AAC/D,EAAC;AAED;;CAEC,GACD,OAAO,MAAMC,uBAAuB,CAAC,EACnCC,SAAS,EACTZ,QAAQ,EAIT;IACC,IAAI,CAACA,UAAU;QACb,OAAOY,UAAUC,QAAQ;IAC3B;IAEA,yEAAyE;IACzE,MAAMC,eAAeF,YAAYL,KAAKE,GAAG,CAAC,IAAIT,SAASU,QAAQ;IAE/D,mDAAmD;IACnD,OAAOI,aAAaC,OAAO,CAACf,SAASU,QAAQ;AAC/C,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defaultProductsValidation.d.ts","sourceRoot":"","sources":["../../src/utilities/defaultProductsValidation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"defaultProductsValidation.d.ts","sourceRoot":"","sources":["../../src/utilities/defaultProductsValidation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AAI3D,eAAO,MAAM,yBAAyB,EAAE,kBAqCvC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/defaultProductsValidation.ts"],"sourcesContent":["import type { ProductsValidation } from '../types.js'\n\nimport { MissingPrice, OutOfStock } from './errorCodes.js'\n\nexport const defaultProductsValidation: ProductsValidation = ({\n currenciesConfig,\n currency,\n product,\n quantity = 1,\n variant,\n}) => {\n if (!currency) {\n throw new Error('Currency must be provided for product validation.')\n }\n\n const priceField = `priceIn${currency.toUpperCase()}`\n\n if (variant) {\n if (!variant[priceField]) {\n throw new Error(`Variant with ID ${variant.id} does not have a price in ${currency}.`)\n }\n\n if (variant.inventory === 0 || (variant.inventory && variant.inventory < quantity)) {\n throw new Error(\n `Variant with ID ${variant.id} is out of stock or does not have enough inventory.`,\n )\n }\n } else if (product) {\n // Validate the product's details only if the variant is not provided as it can have its own inventory and price\n if (!product[priceField]) {\n throw new Error(`Product does not have a price in.`, {\n cause: { code: MissingPrice, codes: [product.id, currency] },\n })\n }\n\n if (product.inventory === 0 || (product.inventory && product.inventory < quantity)) {\n throw new Error(`Product is out of stock or does not have enough inventory.`, {\n cause: { code: OutOfStock, codes: [product.id] },\n })\n }\n }\n}\n"],"names":["MissingPrice","OutOfStock","defaultProductsValidation","currenciesConfig","currency","product","quantity","variant","Error","priceField","toUpperCase","id","inventory","cause","code","codes"],"mappings":"AAEA,SAASA,YAAY,EAAEC,UAAU,QAAQ,kBAAiB;AAE1D,OAAO,MAAMC,4BAAgD,CAAC,EAC5DC,gBAAgB,EAChBC,QAAQ,EACRC,OAAO,EACPC,WAAW,CAAC,EACZC,OAAO,EACR;IACC,IAAI,CAACH,UAAU;QACb,MAAM,IAAII,MAAM;IAClB;IAEA,MAAMC,aAAa,CAAC,OAAO,EAAEL,SAASM,WAAW,IAAI;IAErD,IAAIH,SAAS;QACX,IAAI,CAACA,OAAO,CAACE,WAAW,EAAE;YACxB,MAAM,IAAID,MAAM,CAAC,gBAAgB,EAAED,QAAQI,EAAE,CAAC,0BAA0B,EAAEP,SAAS,CAAC,CAAC;QACvF;QAEA,IAAIG,QAAQK,SAAS,KAAK,KAAML,QAAQK,SAAS,IAAIL,QAAQK,SAAS,GAAGN,UAAW;YAClF,MAAM,IAAIE,MACR,CAAC,gBAAgB,EAAED,QAAQI,EAAE,CAAC,mDAAmD,CAAC;QAEtF;IACF,OAAO,IAAIN,SAAS;QAClB,gHAAgH;QAChH,IAAI,CAACA,OAAO,CAACI,WAAW,EAAE;YACxB,MAAM,IAAID,MAAM,CAAC,iCAAiC,CAAC,EAAE;gBACnDK,OAAO;oBAAEC,MAAMd;oBAAce,OAAO;wBAACV,QAAQM,EAAE;wBAAEP;qBAAS;gBAAC;YAC7D;QACF;QAEA,IAAIC,QAAQO,SAAS,KAAK,KAAMP,QAAQO,SAAS,IAAIP,QAAQO,SAAS,GAAGN,UAAW;YAClF,MAAM,IAAIE,MAAM,CAAC,0DAA0D,CAAC,EAAE;gBAC5EK,OAAO;oBAAEC,MAAMb;oBAAYc,OAAO;wBAACV,QAAQM,EAAE;qBAAC;gBAAC;YACjD;QACF;IACF;AACF,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/defaultProductsValidation.ts"],"sourcesContent":["import type { ProductsValidation } from '../types/index.js'\n\nimport { MissingPrice, OutOfStock } from './errorCodes.js'\n\nexport const defaultProductsValidation: ProductsValidation = ({\n currenciesConfig,\n currency,\n product,\n quantity = 1,\n variant,\n}) => {\n if (!currency) {\n throw new Error('Currency must be provided for product validation.')\n }\n\n const priceField = `priceIn${currency.toUpperCase()}`\n\n if (variant) {\n if (!variant[priceField]) {\n throw new Error(`Variant with ID ${variant.id} does not have a price in ${currency}.`)\n }\n\n if (variant.inventory === 0 || (variant.inventory && variant.inventory < quantity)) {\n throw new Error(\n `Variant with ID ${variant.id} is out of stock or does not have enough inventory.`,\n )\n }\n } else if (product) {\n // Validate the product's details only if the variant is not provided as it can have its own inventory and price\n if (!product[priceField]) {\n throw new Error(`Product does not have a price in.`, {\n cause: { code: MissingPrice, codes: [product.id, currency] },\n })\n }\n\n if (product.inventory === 0 || (product.inventory && product.inventory < quantity)) {\n throw new Error(`Product is out of stock or does not have enough inventory.`, {\n cause: { code: OutOfStock, codes: [product.id] },\n })\n }\n }\n}\n"],"names":["MissingPrice","OutOfStock","defaultProductsValidation","currenciesConfig","currency","product","quantity","variant","Error","priceField","toUpperCase","id","inventory","cause","code","codes"],"mappings":"AAEA,SAASA,YAAY,EAAEC,UAAU,QAAQ,kBAAiB;AAE1D,OAAO,MAAMC,4BAAgD,CAAC,EAC5DC,gBAAgB,EAChBC,QAAQ,EACRC,OAAO,EACPC,WAAW,CAAC,EACZC,OAAO,EACR;IACC,IAAI,CAACH,UAAU;QACb,MAAM,IAAII,MAAM;IAClB;IAEA,MAAMC,aAAa,CAAC,OAAO,EAAEL,SAASM,WAAW,IAAI;IAErD,IAAIH,SAAS;QACX,IAAI,CAACA,OAAO,CAACE,WAAW,EAAE;YACxB,MAAM,IAAID,MAAM,CAAC,gBAAgB,EAAED,QAAQI,EAAE,CAAC,0BAA0B,EAAEP,SAAS,CAAC,CAAC;QACvF;QAEA,IAAIG,QAAQK,SAAS,KAAK,KAAML,QAAQK,SAAS,IAAIL,QAAQK,SAAS,GAAGN,UAAW;YAClF,MAAM,IAAIE,MACR,CAAC,gBAAgB,EAAED,QAAQI,EAAE,CAAC,mDAAmD,CAAC;QAEtF;IACF,OAAO,IAAIN,SAAS;QAClB,gHAAgH;QAChH,IAAI,CAACA,OAAO,CAACI,WAAW,EAAE;YACxB,MAAM,IAAID,MAAM,CAAC,iCAAiC,CAAC,EAAE;gBACnDK,OAAO;oBAAEC,MAAMd;oBAAce,OAAO;wBAACV,QAAQM,EAAE;wBAAEP;qBAAS;gBAAC;YAC7D;QACF;QAEA,IAAIC,QAAQO,SAAS,KAAK,KAAMP,QAAQO,SAAS,IAAIP,QAAQO,SAAS,GAAGN,UAAW;YAClF,MAAM,IAAIE,MAAM,CAAC,0DAA0D,CAAC,EAAE;gBAC5EK,OAAO;oBAAEC,MAAMb;oBAAYc,OAAO;wBAACV,QAAQM,EAAE;qBAAC;gBAAC;YACjD;QACF;IACF;AACF,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getCollectionSlugMap.d.ts","sourceRoot":"","sources":["../../src/utilities/getCollectionSlugMap.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,8BAA8B,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"getCollectionSlugMap.d.ts","sourceRoot":"","sources":["../../src/utilities/getCollectionSlugMap.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,8BAA8B,EAAE,MAAM,mBAAmB,CAAA;AAE1F,KAAK,KAAK,GAAG;IACX,qBAAqB,EAAE,8BAA8B,CAAA;CACtD,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,oBAAoB,8BAA+B,KAAK,KAAG,iBAoBvE,CAAA"}
|
|
@@ -13,13 +13,14 @@
|
|
|
13
13
|
variants: 'variants',
|
|
14
14
|
variantTypes: 'variantTypes'
|
|
15
15
|
};
|
|
16
|
-
const collectionSlugsMap =
|
|
17
|
-
...defaultSlugMap
|
|
18
|
-
};
|
|
16
|
+
const collectionSlugsMap = defaultSlugMap;
|
|
19
17
|
if (typeof sanitizedPluginConfig.customers === 'object' && sanitizedPluginConfig.customers.slug) {
|
|
20
18
|
collectionSlugsMap.customers = sanitizedPluginConfig.customers.slug;
|
|
21
19
|
}
|
|
22
|
-
return
|
|
20
|
+
return {
|
|
21
|
+
...collectionSlugsMap,
|
|
22
|
+
...sanitizedPluginConfig.slugMap || {}
|
|
23
|
+
};
|
|
23
24
|
};
|
|
24
25
|
|
|
25
26
|
//# sourceMappingURL=getCollectionSlugMap.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/getCollectionSlugMap.ts"],"sourcesContent":["import type { CollectionSlugMap, SanitizedEcommercePluginConfig } from '../types.js'\n\ntype Props = {\n sanitizedPluginConfig: SanitizedEcommercePluginConfig\n}\n\n/**\n * Generates a map of collection slugs based on the sanitized plugin configuration.\n * Takes into consideration any collection overrides provided in the plugin.\n */\nexport const getCollectionSlugMap = ({ sanitizedPluginConfig }: Props): CollectionSlugMap => {\n const defaultSlugMap: CollectionSlugMap = {\n addresses: 'addresses',\n carts: 'carts',\n customers: 'users',\n orders: 'orders',\n products: 'products',\n transactions: 'transactions',\n variantOptions: 'variantOptions',\n variants: 'variants',\n variantTypes: 'variantTypes',\n }\n\n const collectionSlugsMap: CollectionSlugMap =
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/getCollectionSlugMap.ts"],"sourcesContent":["import type { CollectionSlugMap, SanitizedEcommercePluginConfig } from '../types/index.js'\n\ntype Props = {\n sanitizedPluginConfig: SanitizedEcommercePluginConfig\n}\n\n/**\n * Generates a map of collection slugs based on the sanitized plugin configuration.\n * Takes into consideration any collection overrides provided in the plugin.\n */\nexport const getCollectionSlugMap = ({ sanitizedPluginConfig }: Props): CollectionSlugMap => {\n const defaultSlugMap: CollectionSlugMap = {\n addresses: 'addresses',\n carts: 'carts',\n customers: 'users',\n orders: 'orders',\n products: 'products',\n transactions: 'transactions',\n variantOptions: 'variantOptions',\n variants: 'variants',\n variantTypes: 'variantTypes',\n }\n\n const collectionSlugsMap: CollectionSlugMap = defaultSlugMap\n\n if (typeof sanitizedPluginConfig.customers === 'object' && sanitizedPluginConfig.customers.slug) {\n collectionSlugsMap.customers = sanitizedPluginConfig.customers.slug\n }\n\n return { ...collectionSlugsMap, ...(sanitizedPluginConfig.slugMap || {}) }\n}\n"],"names":["getCollectionSlugMap","sanitizedPluginConfig","defaultSlugMap","addresses","carts","customers","orders","products","transactions","variantOptions","variants","variantTypes","collectionSlugsMap","slug","slugMap"],"mappings":"AAMA;;;CAGC,GACD,OAAO,MAAMA,uBAAuB,CAAC,EAAEC,qBAAqB,EAAS;IACnE,MAAMC,iBAAoC;QACxCC,WAAW;QACXC,OAAO;QACPC,WAAW;QACXC,QAAQ;QACRC,UAAU;QACVC,cAAc;QACdC,gBAAgB;QAChBC,UAAU;QACVC,cAAc;IAChB;IAEA,MAAMC,qBAAwCV;IAE9C,IAAI,OAAOD,sBAAsBI,SAAS,KAAK,YAAYJ,sBAAsBI,SAAS,CAACQ,IAAI,EAAE;QAC/FD,mBAAmBP,SAAS,GAAGJ,sBAAsBI,SAAS,CAACQ,IAAI;IACrE;IAEA,OAAO;QAAE,GAAGD,kBAAkB;QAAE,GAAIX,sBAAsBa,OAAO,IAAI,CAAC,CAAC;IAAE;AAC3E,EAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { JSONSchema4 } from 'json-schema';
|
|
2
|
+
import type { SanitizedConfig } from 'payload';
|
|
3
|
+
import type { CollectionSlugMap, SanitizedEcommercePluginConfig } from '../types/index.js';
|
|
4
|
+
export declare const pushTypeScriptProperties: ({ collectionSlugMap, jsonSchema, }: {
|
|
5
|
+
collectionSlugMap: CollectionSlugMap;
|
|
6
|
+
config: SanitizedConfig;
|
|
7
|
+
jsonSchema: JSONSchema4;
|
|
8
|
+
sanitizedPluginConfig: SanitizedEcommercePluginConfig;
|
|
9
|
+
}) => JSONSchema4;
|
|
10
|
+
//# sourceMappingURL=pushTypeScriptProperties.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pushTypeScriptProperties.d.ts","sourceRoot":"","sources":["../../src/utilities/pushTypeScriptProperties.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAC9C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAE9C,OAAO,KAAK,EAAE,iBAAiB,EAAE,8BAA8B,EAAE,MAAM,mBAAmB,CAAA;AAE1F,eAAO,MAAM,wBAAwB,uCAGlC;IACD,iBAAiB,EAAE,iBAAiB,CAAA;IACpC,MAAM,EAAE,eAAe,CAAA;IACvB,UAAU,EAAE,WAAW,CAAA;IACvB,qBAAqB,EAAE,8BAA8B,CAAA;CACtD,KAAG,WAoCH,CAAA"}
|