@payloadcms/plugin-ecommerce 0.0.1-beta.0 → 3.57.0-internal.36ffe2b
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 +21 -0
- package/dist/collections/addresses/createAddressesCollection.d.ts.map +1 -0
- package/dist/collections/addresses/createAddressesCollection.js +71 -0
- package/dist/collections/addresses/createAddressesCollection.js.map +1 -0
- package/dist/collections/addresses/defaultAddressFields.d.ts +3 -0
- package/dist/collections/addresses/defaultAddressFields.d.ts.map +1 -0
- package/dist/collections/addresses/defaultAddressFields.js +72 -0
- package/dist/collections/addresses/defaultAddressFields.js.map +1 -0
- package/dist/collections/addresses/defaultCountries.d.ts +9 -0
- package/dist/collections/addresses/defaultCountries.d.ts.map +1 -0
- package/dist/collections/addresses/defaultCountries.js +169 -0
- package/dist/collections/addresses/defaultCountries.js.map +1 -0
- package/dist/collections/addresses/hooks/beforeChange.d.ts +8 -0
- package/dist/collections/addresses/hooks/beforeChange.d.ts.map +1 -0
- package/dist/collections/addresses/hooks/beforeChange.js +12 -0
- package/dist/collections/addresses/hooks/beforeChange.js.map +1 -0
- package/dist/collections/carts/beforeChange.d.ts +8 -0
- package/dist/collections/carts/beforeChange.d.ts.map +1 -0
- package/dist/collections/carts/beforeChange.js +37 -0
- package/dist/collections/carts/beforeChange.js.map +1 -0
- package/dist/collections/carts/createCartsCollection.d.ts +29 -0
- package/dist/collections/carts/createCartsCollection.d.ts.map +1 -0
- package/dist/collections/carts/createCartsCollection.js +138 -0
- package/dist/collections/carts/createCartsCollection.js.map +1 -0
- package/dist/collections/carts/statusBeforeRead.d.ts +3 -0
- package/dist/collections/carts/statusBeforeRead.d.ts.map +1 -0
- package/dist/collections/carts/statusBeforeRead.js +18 -0
- package/dist/collections/carts/statusBeforeRead.js.map +1 -0
- package/dist/collections/orders/createOrdersCollection.d.ts +34 -0
- package/dist/collections/orders/createOrdersCollection.d.ts.map +1 -0
- package/dist/collections/orders/createOrdersCollection.js +162 -0
- package/dist/collections/orders/createOrdersCollection.js.map +1 -0
- package/dist/collections/products/createProductsCollection.d.ts +26 -0
- package/dist/collections/products/createProductsCollection.d.ts.map +1 -0
- package/dist/collections/products/createProductsCollection.js +62 -0
- package/dist/collections/products/createProductsCollection.js.map +1 -0
- package/dist/collections/transactions/createTransactionsCollection.d.ts +40 -0
- package/dist/collections/transactions/createTransactionsCollection.d.ts.map +1 -0
- package/dist/collections/transactions/createTransactionsCollection.js +157 -0
- package/dist/collections/transactions/createTransactionsCollection.js.map +1 -0
- package/dist/collections/variants/createVariantOptionsCollection.d.ts +15 -0
- package/dist/collections/variants/createVariantOptionsCollection.d.ts.map +1 -0
- package/dist/collections/variants/createVariantOptionsCollection.js +53 -0
- package/dist/collections/variants/createVariantOptionsCollection.js.map +1 -0
- package/dist/collections/variants/createVariantTypesCollection.d.ts +15 -0
- package/dist/collections/variants/createVariantTypesCollection.d.ts.map +1 -0
- package/dist/collections/variants/createVariantTypesCollection.js +49 -0
- package/dist/collections/variants/createVariantTypesCollection.js.map +1 -0
- package/dist/collections/variants/createVariantsCollection/hooks/beforeChange.d.ts +8 -0
- package/dist/collections/variants/createVariantsCollection/hooks/beforeChange.d.ts.map +1 -0
- package/dist/collections/variants/createVariantsCollection/hooks/beforeChange.js +38 -0
- package/dist/collections/variants/createVariantsCollection/hooks/beforeChange.js.map +1 -0
- package/dist/collections/variants/createVariantsCollection/hooks/validateOptions.d.ts +7 -0
- package/dist/collections/variants/createVariantsCollection/hooks/validateOptions.d.ts.map +1 -0
- package/dist/collections/variants/createVariantsCollection/hooks/validateOptions.js +53 -0
- package/dist/collections/variants/createVariantsCollection/hooks/validateOptions.js.map +1 -0
- package/dist/collections/variants/createVariantsCollection/index.d.ts +24 -0
- package/dist/collections/variants/createVariantsCollection/index.d.ts.map +1 -0
- package/dist/collections/variants/createVariantsCollection/index.js +101 -0
- package/dist/collections/variants/createVariantsCollection/index.js.map +1 -0
- package/dist/currencies/index.d.ts +5 -0
- package/dist/currencies/index.d.ts.map +1 -0
- package/dist/currencies/index.js +20 -0
- package/dist/currencies/index.js.map +1 -0
- package/dist/endpoints/confirmOrder.d.ts +42 -0
- package/dist/endpoints/confirmOrder.d.ts.map +1 -0
- package/dist/endpoints/confirmOrder.js +143 -0
- package/dist/endpoints/confirmOrder.js.map +1 -0
- package/dist/endpoints/initiatePayment.d.ts +43 -0
- package/dist/endpoints/initiatePayment.d.ts.map +1 -0
- package/dist/endpoints/initiatePayment.js +220 -0
- package/dist/endpoints/initiatePayment.js.map +1 -0
- package/dist/exports/client/index.d.ts +3 -0
- package/dist/exports/client/index.d.ts.map +1 -0
- package/dist/exports/client/index.js +4 -0
- package/dist/exports/client/index.js.map +1 -0
- package/dist/exports/client/react.d.ts +4 -0
- package/dist/exports/client/react.d.ts.map +1 -0
- package/dist/exports/client/react.js +5 -0
- package/dist/exports/client/react.js.map +1 -0
- package/dist/exports/payments/stripe.d.ts +2 -0
- package/dist/exports/payments/stripe.d.ts.map +1 -0
- package/dist/exports/payments/stripe.js +3 -0
- package/dist/exports/payments/stripe.js.map +1 -0
- package/dist/exports/rsc.d.ts +3 -0
- package/dist/exports/rsc.d.ts.map +1 -0
- package/dist/exports/rsc.js +4 -0
- package/dist/exports/rsc.js.map +1 -0
- package/dist/exports/translations.d.ts +2 -0
- package/dist/exports/translations.d.ts.map +1 -0
- package/dist/exports/translations.js +3 -0
- package/dist/exports/translations.js.map +1 -0
- package/dist/exports/types.d.ts +2 -0
- package/dist/exports/types.d.ts.map +1 -0
- package/dist/exports/types.js +3 -0
- package/dist/exports/types.js.map +1 -0
- package/dist/fields/amountField.d.ts +13 -0
- package/dist/fields/amountField.d.ts.map +1 -0
- package/dist/fields/amountField.js +33 -0
- package/dist/fields/amountField.js.map +1 -0
- package/dist/fields/cartItemsField.d.ts +26 -0
- package/dist/fields/cartItemsField.d.ts.map +1 -0
- package/dist/fields/cartItemsField.js +55 -0
- package/dist/fields/cartItemsField.js.map +1 -0
- package/dist/fields/currencyField.d.ts +9 -0
- package/dist/fields/currencyField.d.ts.map +1 -0
- package/dist/fields/currencyField.js +29 -0
- package/dist/fields/currencyField.js.map +1 -0
- package/dist/fields/inventoryField.d.ts +7 -0
- package/dist/fields/inventoryField.d.ts.map +1 -0
- package/dist/fields/inventoryField.js +16 -0
- package/dist/fields/inventoryField.js.map +1 -0
- package/dist/fields/pricesField.d.ts +12 -0
- package/dist/fields/pricesField.d.ts.map +1 -0
- package/dist/fields/pricesField.js +54 -0
- package/dist/fields/pricesField.js.map +1 -0
- package/dist/fields/statusField.d.ts +8 -0
- package/dist/fields/statusField.d.ts.map +1 -0
- package/dist/fields/statusField.js +49 -0
- package/dist/fields/statusField.js.map +1 -0
- package/dist/fields/variantsFields.d.ts +14 -0
- package/dist/fields/variantsFields.d.ts.map +1 -0
- package/dist/fields/variantsFields.js +48 -0
- package/dist/fields/variantsFields.js.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +238 -0
- package/dist/index.js.map +1 -0
- package/dist/payments/adapters/stripe/confirmOrder.d.ts +11 -0
- package/dist/payments/adapters/stripe/confirmOrder.d.ts.map +1 -0
- package/dist/payments/adapters/stripe/confirmOrder.js +101 -0
- package/dist/payments/adapters/stripe/confirmOrder.js.map +1 -0
- package/dist/payments/adapters/stripe/endpoints/webhooks.d.ts +13 -0
- package/dist/payments/adapters/stripe/endpoints/webhooks.d.ts.map +1 -0
- package/dist/payments/adapters/stripe/endpoints/webhooks.js +53 -0
- package/dist/payments/adapters/stripe/endpoints/webhooks.js.map +1 -0
- package/dist/payments/adapters/stripe/index.d.ts +60 -0
- package/dist/payments/adapters/stripe/index.d.ts.map +1 -0
- package/dist/payments/adapters/stripe/index.js +68 -0
- package/dist/payments/adapters/stripe/index.js.map +1 -0
- package/dist/payments/adapters/stripe/initiatePayment.d.ts +11 -0
- package/dist/payments/adapters/stripe/initiatePayment.d.ts.map +1 -0
- package/dist/payments/adapters/stripe/initiatePayment.js +102 -0
- package/dist/payments/adapters/stripe/initiatePayment.js.map +1 -0
- package/dist/react/provider/index.d.ts +41 -0
- package/dist/react/provider/index.d.ts.map +1 -0
- package/dist/react/provider/index.js +790 -0
- package/dist/react/provider/index.js.map +1 -0
- package/dist/react/provider/types.d.ts +171 -0
- package/dist/react/provider/types.d.ts.map +1 -0
- package/dist/react/provider/types.js +3 -0
- package/dist/react/provider/types.js.map +1 -0
- package/dist/react/provider/utilities.d.ts +9 -0
- package/dist/react/provider/utilities.d.ts.map +1 -0
- package/dist/react/provider/utilities.js +13 -0
- package/dist/react/provider/utilities.js.map +1 -0
- package/dist/translations/en.d.ts +3 -0
- package/dist/translations/en.d.ts.map +1 -0
- package/dist/translations/en.js +86 -0
- package/dist/translations/en.js.map +1 -0
- package/dist/translations/index.d.ts +7 -0
- package/dist/translations/index.d.ts.map +1 -0
- package/dist/translations/index.js +6 -0
- package/dist/translations/index.js.map +1 -0
- package/dist/types.d.ts +658 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/ui/PriceCell/index.d.ts +12 -0
- package/dist/ui/PriceCell/index.d.ts.map +1 -0
- package/dist/ui/PriceCell/index.js +38 -0
- package/dist/ui/PriceCell/index.js.map +1 -0
- package/dist/ui/PriceInput/FormattedInput.d.ts +17 -0
- package/dist/ui/PriceInput/FormattedInput.d.ts.map +1 -0
- package/dist/ui/PriceInput/FormattedInput.js +146 -0
- package/dist/ui/PriceInput/FormattedInput.js.map +1 -0
- package/{src/ui/PriceInput/index.scss → dist/ui/PriceInput/index.css} +7 -0
- package/dist/ui/PriceInput/index.d.ts +11 -0
- package/dist/ui/PriceInput/index.d.ts.map +1 -0
- package/dist/ui/PriceInput/index.js +20 -0
- package/dist/ui/PriceInput/index.js.map +1 -0
- package/dist/ui/PriceRowLabel/index.d.ts +8 -0
- package/dist/ui/PriceRowLabel/index.d.ts.map +1 -0
- package/dist/ui/PriceRowLabel/index.js +66 -0
- package/dist/ui/PriceRowLabel/index.js.map +1 -0
- package/dist/ui/VariantOptionsSelector/ErrorBox.d.ts +8 -0
- package/dist/ui/VariantOptionsSelector/ErrorBox.d.ts.map +1 -0
- package/dist/ui/VariantOptionsSelector/ErrorBox.js +28 -0
- package/dist/ui/VariantOptionsSelector/ErrorBox.js.map +1 -0
- package/dist/ui/VariantOptionsSelector/OptionsSelect.d.ts +13 -0
- package/dist/ui/VariantOptionsSelector/OptionsSelect.d.ts.map +1 -0
- package/dist/ui/VariantOptionsSelector/OptionsSelect.js +71 -0
- package/dist/ui/VariantOptionsSelector/OptionsSelect.js.map +1 -0
- package/dist/ui/VariantOptionsSelector/index.d.ts +6 -0
- package/dist/ui/VariantOptionsSelector/index.d.ts.map +1 -0
- package/dist/ui/VariantOptionsSelector/index.js +78 -0
- package/dist/ui/VariantOptionsSelector/index.js.map +1 -0
- package/dist/ui/utilities.d.ts +16 -0
- package/dist/ui/utilities.d.ts.map +1 -0
- package/dist/ui/utilities.js +26 -0
- package/dist/ui/utilities.js.map +1 -0
- package/dist/utilities/defaultProductsValidation.d.ts +3 -0
- package/dist/utilities/defaultProductsValidation.d.ts.map +1 -0
- package/dist/utilities/defaultProductsValidation.js +40 -0
- package/dist/utilities/defaultProductsValidation.js.map +1 -0
- package/dist/utilities/errorCodes.d.ts +3 -0
- package/dist/utilities/errorCodes.d.ts.map +1 -0
- package/dist/utilities/errorCodes.js +4 -0
- package/dist/utilities/errorCodes.js.map +1 -0
- package/dist/utilities/getCollectionSlugMap.d.ts +11 -0
- package/dist/utilities/getCollectionSlugMap.d.ts.map +1 -0
- package/dist/utilities/getCollectionSlugMap.js +25 -0
- package/dist/utilities/getCollectionSlugMap.js.map +1 -0
- package/dist/utilities/sanitizePluginConfig.d.ts +7 -0
- package/dist/utilities/sanitizePluginConfig.d.ts.map +1 -0
- package/dist/utilities/sanitizePluginConfig.js +67 -0
- package/dist/utilities/sanitizePluginConfig.js.map +1 -0
- package/package.json +98 -1
- package/.prettierignore +0 -12
- package/.swcrc +0 -24
- package/eslint.config.js +0 -18
- package/src/addresses/addressesCollection.ts +0 -76
- package/src/addresses/defaultAddressFields.ts +0 -83
- package/src/addresses/defaultCountries.ts +0 -50
- package/src/carts/beforeChange.ts +0 -51
- package/src/carts/cartsCollection.ts +0 -146
- package/src/currencies/index.ts +0 -29
- package/src/endpoints/confirmOrder.ts +0 -312
- package/src/endpoints/initiatePayment.ts +0 -322
- package/src/exports/addresses.ts +0 -2
- package/src/exports/currencies.ts +0 -1
- package/src/exports/fields.ts +0 -5
- package/src/exports/orders.ts +0 -1
- package/src/exports/payments/stripe.ts +0 -1
- package/src/exports/plugin.ts +0 -1
- package/src/exports/products.ts +0 -1
- package/src/exports/react.ts +0 -8
- package/src/exports/transactions.ts +0 -1
- package/src/exports/translations.ts +0 -1
- package/src/exports/types.ts +0 -7
- package/src/exports/ui.ts +0 -3
- package/src/exports/variants.ts +0 -5
- package/src/fields/amountField.ts +0 -43
- package/src/fields/cartItemsField.ts +0 -84
- package/src/fields/currencyField.ts +0 -39
- package/src/fields/inventoryField.ts +0 -22
- package/src/fields/pricesField.ts +0 -65
- package/src/fields/statusField.ts +0 -57
- package/src/fields/variantsFields.ts +0 -56
- package/src/index.ts +0 -275
- package/src/orders/ordersCollection.ts +0 -157
- package/src/payments/adapters/stripe/confirmOrder.ts +0 -123
- package/src/payments/adapters/stripe/endpoints/webhooks.ts +0 -69
- package/src/payments/adapters/stripe/index.ts +0 -135
- package/src/payments/adapters/stripe/initiatePayment.ts +0 -131
- package/src/products/productsCollection.ts +0 -78
- package/src/react/provider/index.tsx +0 -893
- package/src/react/provider/types.ts +0 -184
- package/src/react/provider/utilities.ts +0 -22
- package/src/transactions/transactionsCollection.ts +0 -166
- package/src/translations/en.ts +0 -64
- package/src/translations/index.ts +0 -11
- package/src/types.ts +0 -403
- package/src/ui/PriceInput/FormattedInput.tsx +0 -134
- package/src/ui/PriceInput/index.tsx +0 -43
- package/src/ui/PriceInput/utilities.ts +0 -46
- package/src/ui/PriceRowLabel/index.tsx +0 -56
- package/src/ui/VariantOptionsSelector/ErrorBox.tsx +0 -27
- package/src/ui/VariantOptionsSelector/OptionsSelect.tsx +0 -78
- package/src/ui/VariantOptionsSelector/index.tsx +0 -83
- package/src/utilities/defaultProductsValidation.ts +0 -42
- package/src/utilities/errorCodes.ts +0 -14
- package/src/utilities/getCollectionSlugMap.ts +0 -84
- package/src/utilities/sanitizePluginConfig.ts +0 -80
- package/src/variants/variantOptionsCollection.ts +0 -59
- package/src/variants/variantTypesCollection.ts +0 -55
- package/src/variants/variantsCollection/hooks/beforeChange.ts +0 -47
- package/src/variants/variantsCollection/hooks/validateOptions.ts +0 -72
- package/src/variants/variantsCollection/index.ts +0 -119
- package/tsconfig.json +0 -7
- package/tsconfig.tsbuildinfo +0 -1
- /package/{src → dist}/translations/translation-schema.json +0 -0
- /package/{src → dist}/ui/PriceRowLabel/index.css +0 -0
- /package/{src → dist}/ui/VariantOptionsSelector/index.css +0 -0
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { FieldLabel } from '@payloadcms/ui';
|
|
3
|
+
import { ErrorBox } from './ErrorBox.js';
|
|
4
|
+
import './index.css';
|
|
5
|
+
import { OptionsSelect } from './OptionsSelect.js';
|
|
6
|
+
export const VariantOptionsSelector = async (props)=>{
|
|
7
|
+
const { clientField, data, path, req, user } = props;
|
|
8
|
+
const { label } = clientField;
|
|
9
|
+
const product = await req.payload.findByID({
|
|
10
|
+
id: data.product,
|
|
11
|
+
collection: 'products',
|
|
12
|
+
depth: 0,
|
|
13
|
+
draft: true,
|
|
14
|
+
select: {
|
|
15
|
+
variants: true,
|
|
16
|
+
variantTypes: true
|
|
17
|
+
},
|
|
18
|
+
user
|
|
19
|
+
});
|
|
20
|
+
// @ts-expect-error - TODO: Fix types
|
|
21
|
+
const existingVariantOptions = product.variants?.docs?.map((variant)=>variant.options) ?? [];
|
|
22
|
+
const variantTypeIDs = product.variantTypes;
|
|
23
|
+
const variantTypes = [];
|
|
24
|
+
// Need to get the variant types separately so that the options are populated
|
|
25
|
+
// @ts-expect-error - TODO: Fix types
|
|
26
|
+
if (variantTypeIDs?.length && variantTypeIDs.length > 0) {
|
|
27
|
+
// @ts-expect-error - TODO: Fix types
|
|
28
|
+
for (const variantTypeID of variantTypeIDs){
|
|
29
|
+
const variantType = await req.payload.findByID({
|
|
30
|
+
id: variantTypeID,
|
|
31
|
+
collection: 'variantTypes',
|
|
32
|
+
depth: 1,
|
|
33
|
+
joins: {
|
|
34
|
+
options: {
|
|
35
|
+
sort: 'value'
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
if (variantType) {
|
|
40
|
+
variantTypes.push(variantType);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return /*#__PURE__*/ _jsxs("div", {
|
|
45
|
+
className: "variantOptionsSelector",
|
|
46
|
+
children: [
|
|
47
|
+
/*#__PURE__*/ _jsx("div", {
|
|
48
|
+
className: "variantOptionsSelectorHeading",
|
|
49
|
+
children: /*#__PURE__*/ _jsx(FieldLabel, {
|
|
50
|
+
as: "span",
|
|
51
|
+
label: label
|
|
52
|
+
})
|
|
53
|
+
}),
|
|
54
|
+
/*#__PURE__*/ _jsx(ErrorBox, {
|
|
55
|
+
existingOptions: existingVariantOptions,
|
|
56
|
+
path: path,
|
|
57
|
+
children: /*#__PURE__*/ _jsx("div", {
|
|
58
|
+
className: "variantOptionsSelectorList",
|
|
59
|
+
children: variantTypes.map((type)=>{
|
|
60
|
+
// @ts-expect-error - TODO: Fix types
|
|
61
|
+
const options = type.options.docs.map((option)=>({
|
|
62
|
+
label: option.label,
|
|
63
|
+
value: option.id
|
|
64
|
+
}));
|
|
65
|
+
return /*#__PURE__*/ _jsx(OptionsSelect, {
|
|
66
|
+
field: clientField,
|
|
67
|
+
label: type.label || type.name,
|
|
68
|
+
options: options,
|
|
69
|
+
path: path
|
|
70
|
+
}, type.name);
|
|
71
|
+
})
|
|
72
|
+
})
|
|
73
|
+
})
|
|
74
|
+
]
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/ui/VariantOptionsSelector/index.tsx"],"sourcesContent":["import type { SelectFieldServerProps } from 'payload'\n\nimport { FieldLabel } from '@payloadcms/ui'\n\nimport { ErrorBox } from './ErrorBox.js'\nimport './index.css'\nimport { OptionsSelect } from './OptionsSelect.js'\ntype Props = {} & SelectFieldServerProps\n\nexport const VariantOptionsSelector: React.FC<Props> = async (props) => {\n const { clientField, data, path, req, user } = props\n const { label } = clientField\n\n const product = await req.payload.findByID({\n id: data.product,\n collection: 'products',\n depth: 0,\n draft: true,\n select: {\n variants: true,\n variantTypes: true,\n },\n user,\n })\n\n // @ts-expect-error - TODO: Fix types\n const existingVariantOptions = product.variants?.docs?.map((variant) => variant.options) ?? []\n\n const variantTypeIDs = product.variantTypes\n\n const variantTypes = []\n\n // Need to get the variant types separately so that the options are populated\n // @ts-expect-error - TODO: Fix types\n if (variantTypeIDs?.length && variantTypeIDs.length > 0) {\n // @ts-expect-error - TODO: Fix types\n for (const variantTypeID of variantTypeIDs) {\n const variantType = await req.payload.findByID({\n id: variantTypeID,\n collection: 'variantTypes',\n depth: 1,\n joins: {\n options: {\n sort: 'value',\n },\n },\n })\n\n if (variantType) {\n variantTypes.push(variantType)\n }\n }\n }\n\n return (\n <div className=\"variantOptionsSelector\">\n <div className=\"variantOptionsSelectorHeading\">\n <FieldLabel as=\"span\" label={label} />\n </div>\n\n <ErrorBox existingOptions={existingVariantOptions} path={path}>\n <div className=\"variantOptionsSelectorList\">\n {variantTypes.map((type) => {\n // @ts-expect-error - TODO: Fix types\n const options = type.options.docs.map((option) => ({\n label: option.label,\n value: option.id,\n }))\n\n return (\n <OptionsSelect\n field={clientField}\n key={type.name}\n label={type.label || type.name}\n options={options}\n path={path}\n />\n )\n })}\n </div>\n </ErrorBox>\n </div>\n )\n}\n"],"names":["FieldLabel","ErrorBox","OptionsSelect","VariantOptionsSelector","props","clientField","data","path","req","user","label","product","payload","findByID","id","collection","depth","draft","select","variants","variantTypes","existingVariantOptions","docs","map","variant","options","variantTypeIDs","length","variantTypeID","variantType","joins","sort","push","div","className","as","existingOptions","type","option","value","field","name"],"mappings":";AAEA,SAASA,UAAU,QAAQ,iBAAgB;AAE3C,SAASC,QAAQ,QAAQ,gBAAe;AACxC,OAAO,cAAa;AACpB,SAASC,aAAa,QAAQ,qBAAoB;AAGlD,OAAO,MAAMC,yBAA0C,OAAOC;IAC5D,MAAM,EAAEC,WAAW,EAAEC,IAAI,EAAEC,IAAI,EAAEC,GAAG,EAAEC,IAAI,EAAE,GAAGL;IAC/C,MAAM,EAAEM,KAAK,EAAE,GAAGL;IAElB,MAAMM,UAAU,MAAMH,IAAII,OAAO,CAACC,QAAQ,CAAC;QACzCC,IAAIR,KAAKK,OAAO;QAChBI,YAAY;QACZC,OAAO;QACPC,OAAO;QACPC,QAAQ;YACNC,UAAU;YACVC,cAAc;QAChB;QACAX;IACF;IAEA,qCAAqC;IACrC,MAAMY,yBAAyBV,QAAQQ,QAAQ,EAAEG,MAAMC,IAAI,CAACC,UAAYA,QAAQC,OAAO,KAAK,EAAE;IAE9F,MAAMC,iBAAiBf,QAAQS,YAAY;IAE3C,MAAMA,eAAe,EAAE;IAEvB,6EAA6E;IAC7E,qCAAqC;IACrC,IAAIM,gBAAgBC,UAAUD,eAAeC,MAAM,GAAG,GAAG;QACvD,qCAAqC;QACrC,KAAK,MAAMC,iBAAiBF,eAAgB;YAC1C,MAAMG,cAAc,MAAMrB,IAAII,OAAO,CAACC,QAAQ,CAAC;gBAC7CC,IAAIc;gBACJb,YAAY;gBACZC,OAAO;gBACPc,OAAO;oBACLL,SAAS;wBACPM,MAAM;oBACR;gBACF;YACF;YAEA,IAAIF,aAAa;gBACfT,aAAaY,IAAI,CAACH;YACpB;QACF;IACF;IAEA,qBACE,MAACI;QAAIC,WAAU;;0BACb,KAACD;gBAAIC,WAAU;0BACb,cAAA,KAAClC;oBAAWmC,IAAG;oBAAOzB,OAAOA;;;0BAG/B,KAACT;gBAASmC,iBAAiBf;gBAAwBd,MAAMA;0BACvD,cAAA,KAAC0B;oBAAIC,WAAU;8BACZd,aAAaG,GAAG,CAAC,CAACc;wBACjB,qCAAqC;wBACrC,MAAMZ,UAAUY,KAAKZ,OAAO,CAACH,IAAI,CAACC,GAAG,CAAC,CAACe,SAAY,CAAA;gCACjD5B,OAAO4B,OAAO5B,KAAK;gCACnB6B,OAAOD,OAAOxB,EAAE;4BAClB,CAAA;wBAEA,qBACE,KAACZ;4BACCsC,OAAOnC;4BAEPK,OAAO2B,KAAK3B,KAAK,IAAI2B,KAAKI,IAAI;4BAC9BhB,SAASA;4BACTlB,MAAMA;2BAHD8B,KAAKI,IAAI;oBAMpB;;;;;AAKV,EAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Currency } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Convert display value with decimal point to base value (e.g., $25.00 to 2500)
|
|
4
|
+
*/
|
|
5
|
+
export declare const convertToBaseValue: ({ currency, displayValue, }: {
|
|
6
|
+
currency: Currency;
|
|
7
|
+
displayValue: string;
|
|
8
|
+
}) => number;
|
|
9
|
+
/**
|
|
10
|
+
* Convert base value to display value with decimal point (e.g., 2500 to $25.00)
|
|
11
|
+
*/
|
|
12
|
+
export declare const convertFromBaseValue: ({ baseValue, currency, }: {
|
|
13
|
+
baseValue: number;
|
|
14
|
+
currency: Currency;
|
|
15
|
+
}) => string;
|
|
16
|
+
//# sourceMappingURL=utilities.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utilities.d.ts","sourceRoot":"","sources":["../../src/ui/utilities.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAE3C;;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"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convert display value with decimal point to base value (e.g., $25.00 to 2500)
|
|
3
|
+
*/ export const convertToBaseValue = ({ currency, displayValue })=>{
|
|
4
|
+
if (!currency) {
|
|
5
|
+
return parseFloat(displayValue);
|
|
6
|
+
}
|
|
7
|
+
// Remove currency symbol and any non-numeric characters except decimal
|
|
8
|
+
const cleanValue = displayValue.replace(currency.symbol, '').replace(/[^0-9.]/g, '');
|
|
9
|
+
// Parse the clean value to a float
|
|
10
|
+
const floatValue = parseFloat(cleanValue || '0');
|
|
11
|
+
// Convert to the base value (e.g., cents for USD)
|
|
12
|
+
return Math.round(floatValue * Math.pow(10, currency.decimals));
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Convert base value to display value with decimal point (e.g., 2500 to $25.00)
|
|
16
|
+
*/ export const convertFromBaseValue = ({ baseValue, currency })=>{
|
|
17
|
+
if (!currency) {
|
|
18
|
+
return baseValue.toString();
|
|
19
|
+
}
|
|
20
|
+
// Convert from base value (e.g., cents) to decimal value (e.g., dollars)
|
|
21
|
+
const decimalValue = baseValue / Math.pow(10, currency.decimals);
|
|
22
|
+
// Format with the correct number of decimal places
|
|
23
|
+
return decimalValue.toFixed(currency.decimals);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
//# sourceMappingURL=utilities.js.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaultProductsValidation.d.ts","sourceRoot":"","sources":["../../src/utilities/defaultProductsValidation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAIrD,eAAO,MAAM,yBAAyB,EAAE,kBAqCvC,CAAA"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { MissingPrice, OutOfStock } from './errorCodes.js';
|
|
2
|
+
export const defaultProductsValidation = ({ currenciesConfig, currency, product, quantity = 1, variant })=>{
|
|
3
|
+
if (!currency) {
|
|
4
|
+
throw new Error('Currency must be provided for product validation.');
|
|
5
|
+
}
|
|
6
|
+
const priceField = `priceIn${currency.toUpperCase()}`;
|
|
7
|
+
if (variant) {
|
|
8
|
+
if (!variant[priceField]) {
|
|
9
|
+
throw new Error(`Variant with ID ${variant.id} does not have a price in ${currency}.`);
|
|
10
|
+
}
|
|
11
|
+
if (variant.inventory === 0 || variant.inventory && variant.inventory < quantity) {
|
|
12
|
+
throw new Error(`Variant with ID ${variant.id} is out of stock or does not have enough inventory.`);
|
|
13
|
+
}
|
|
14
|
+
} else if (product) {
|
|
15
|
+
// Validate the product's details only if the variant is not provided as it can have its own inventory and price
|
|
16
|
+
if (!product[priceField]) {
|
|
17
|
+
throw new Error(`Product does not have a price in.`, {
|
|
18
|
+
cause: {
|
|
19
|
+
code: MissingPrice,
|
|
20
|
+
codes: [
|
|
21
|
+
product.id,
|
|
22
|
+
currency
|
|
23
|
+
]
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
if (product.inventory === 0 || product.inventory && product.inventory < quantity) {
|
|
28
|
+
throw new Error(`Product is out of stock or does not have enough inventory.`, {
|
|
29
|
+
cause: {
|
|
30
|
+
code: OutOfStock,
|
|
31
|
+
codes: [
|
|
32
|
+
product.id
|
|
33
|
+
]
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
//# sourceMappingURL=defaultProductsValidation.js.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errorCodes.d.ts","sourceRoot":"","sources":["../../src/utilities/errorCodes.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,YAAY,iBAAiB,CAAA;AAC1C,eAAO,MAAM,UAAU,eAAe,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/errorCodes.ts"],"sourcesContent":["export const MissingPrice = 'MissingPrice'\nexport const OutOfStock = 'OutOfStock'\n"],"names":["MissingPrice","OutOfStock"],"mappings":"AAAA,OAAO,MAAMA,eAAe,eAAc;AAC1C,OAAO,MAAMC,aAAa,aAAY"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { CollectionSlugMap, SanitizedEcommercePluginConfig } from '../types.js';
|
|
2
|
+
type Props = {
|
|
3
|
+
sanitizedPluginConfig: SanitizedEcommercePluginConfig;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* Generates a map of collection slugs based on the sanitized plugin configuration.
|
|
7
|
+
* Takes into consideration any collection overrides provided in the plugin.
|
|
8
|
+
*/
|
|
9
|
+
export declare const getCollectionSlugMap: ({ sanitizedPluginConfig }: Props) => CollectionSlugMap;
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=getCollectionSlugMap.d.ts.map
|
|
@@ -0,0 +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,aAAa,CAAA;AAEpF,KAAK,KAAK,GAAG;IACX,qBAAqB,EAAE,8BAA8B,CAAA;CACtD,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,oBAAoB,8BAA+B,KAAK,KAAG,iBAsBvE,CAAA"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates a map of collection slugs based on the sanitized plugin configuration.
|
|
3
|
+
* Takes into consideration any collection overrides provided in the plugin.
|
|
4
|
+
*/ export const getCollectionSlugMap = ({ sanitizedPluginConfig })=>{
|
|
5
|
+
const defaultSlugMap = {
|
|
6
|
+
addresses: 'addresses',
|
|
7
|
+
carts: 'carts',
|
|
8
|
+
customers: 'users',
|
|
9
|
+
orders: 'orders',
|
|
10
|
+
products: 'products',
|
|
11
|
+
transactions: 'transactions',
|
|
12
|
+
variantOptions: 'variantOptions',
|
|
13
|
+
variants: 'variants',
|
|
14
|
+
variantTypes: 'variantTypes'
|
|
15
|
+
};
|
|
16
|
+
const collectionSlugsMap = {
|
|
17
|
+
...defaultSlugMap
|
|
18
|
+
};
|
|
19
|
+
if (typeof sanitizedPluginConfig.customers === 'object' && sanitizedPluginConfig.customers.slug) {
|
|
20
|
+
collectionSlugsMap.customers = sanitizedPluginConfig.customers.slug;
|
|
21
|
+
}
|
|
22
|
+
return collectionSlugsMap;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
//# sourceMappingURL=getCollectionSlugMap.js.map
|
|
@@ -0,0 +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 = {\n ...defaultSlugMap,\n }\n\n if (typeof sanitizedPluginConfig.customers === 'object' && sanitizedPluginConfig.customers.slug) {\n collectionSlugsMap.customers = sanitizedPluginConfig.customers.slug\n }\n\n return collectionSlugsMap\n}\n"],"names":["getCollectionSlugMap","sanitizedPluginConfig","defaultSlugMap","addresses","carts","customers","orders","products","transactions","variantOptions","variants","variantTypes","collectionSlugsMap","slug"],"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,qBAAwC;QAC5C,GAAGV,cAAc;IACnB;IAEA,IAAI,OAAOD,sBAAsBI,SAAS,KAAK,YAAYJ,sBAAsBI,SAAS,CAACQ,IAAI,EAAE;QAC/FD,mBAAmBP,SAAS,GAAGJ,sBAAsBI,SAAS,CAACQ,IAAI;IACrE;IAEA,OAAOD;AACT,EAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { EcommercePluginConfig, SanitizedEcommercePluginConfig } from '../types.js';
|
|
2
|
+
type Props = {
|
|
3
|
+
pluginConfig: EcommercePluginConfig;
|
|
4
|
+
};
|
|
5
|
+
export declare const sanitizePluginConfig: ({ pluginConfig }: Props) => SanitizedEcommercePluginConfig;
|
|
6
|
+
export {};
|
|
7
|
+
//# sourceMappingURL=sanitizePluginConfig.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sanitizePluginConfig.d.ts","sourceRoot":"","sources":["../../src/utilities/sanitizePluginConfig.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,8BAA8B,EAAE,MAAM,aAAa,CAAA;AAKxF,KAAK,KAAK,GAAG;IACX,YAAY,EAAE,qBAAqB,CAAA;CACpC,CAAA;AAED,eAAO,MAAM,oBAAoB,qBAAsB,KAAK,KAAG,8BAkF9D,CAAA"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { defaultAddressFields } from '../collections/addresses/defaultAddressFields.js';
|
|
2
|
+
import { USD } from '../currencies/index.js';
|
|
3
|
+
export const sanitizePluginConfig = ({ pluginConfig })=>{
|
|
4
|
+
const config = {
|
|
5
|
+
...pluginConfig
|
|
6
|
+
};
|
|
7
|
+
if (typeof config.customers === 'undefined') {
|
|
8
|
+
config.customers = {
|
|
9
|
+
slug: 'users'
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
if (typeof config.addresses === 'undefined' || typeof config.addresses === 'boolean' && config.addresses === true) {
|
|
13
|
+
config.addresses = {
|
|
14
|
+
addressFields: defaultAddressFields()
|
|
15
|
+
};
|
|
16
|
+
} else {
|
|
17
|
+
const addressFields = typeof pluginConfig.addresses === 'object' && typeof pluginConfig.addresses.addressFields === 'function' && pluginConfig.addresses.addressFields({
|
|
18
|
+
defaultFields: defaultAddressFields()
|
|
19
|
+
}) || defaultAddressFields();
|
|
20
|
+
config.addresses = {
|
|
21
|
+
...config.addresses,
|
|
22
|
+
addressFields
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
if (!config.currencies) {
|
|
26
|
+
config.currencies = {
|
|
27
|
+
defaultCurrency: 'USD',
|
|
28
|
+
supportedCurrencies: [
|
|
29
|
+
USD
|
|
30
|
+
]
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
if (typeof config.inventory === 'undefined' || typeof config.inventory === 'boolean' && config.inventory === true) {
|
|
34
|
+
config.inventory = {
|
|
35
|
+
fieldName: 'inventory'
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
if (typeof config.carts === 'undefined') {
|
|
39
|
+
config.carts = true;
|
|
40
|
+
}
|
|
41
|
+
if (typeof config.orders === 'undefined') {
|
|
42
|
+
config.orders = true;
|
|
43
|
+
}
|
|
44
|
+
if (typeof config.transactions === 'undefined') {
|
|
45
|
+
config.transactions = true;
|
|
46
|
+
}
|
|
47
|
+
if (typeof config.payments === 'undefined') {
|
|
48
|
+
config.payments = {
|
|
49
|
+
paymentMethods: []
|
|
50
|
+
};
|
|
51
|
+
} else if (!config.payments.paymentMethods) {
|
|
52
|
+
config.payments.paymentMethods = [];
|
|
53
|
+
}
|
|
54
|
+
if (config.products) {
|
|
55
|
+
if (typeof config.products === 'object' && typeof config.products.variants === 'undefined') {
|
|
56
|
+
config.products.variants = true;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
config.access = {
|
|
60
|
+
authenticatedOnly: ({ req: { user } })=>Boolean(user),
|
|
61
|
+
publicAccess: ()=>true,
|
|
62
|
+
...pluginConfig.access
|
|
63
|
+
};
|
|
64
|
+
return config;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
//# sourceMappingURL=sanitizePluginConfig.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/sanitizePluginConfig.ts"],"sourcesContent":["import type { EcommercePluginConfig, SanitizedEcommercePluginConfig } from '../types.js'\n\nimport { defaultAddressFields } from '../collections/addresses/defaultAddressFields.js'\nimport { USD } from '../currencies/index.js'\n\ntype Props = {\n pluginConfig: EcommercePluginConfig\n}\n\nexport const sanitizePluginConfig = ({ pluginConfig }: Props): SanitizedEcommercePluginConfig => {\n const config = {\n ...pluginConfig,\n } as Partial<SanitizedEcommercePluginConfig>\n\n if (typeof config.customers === 'undefined') {\n config.customers = {\n slug: 'users',\n }\n }\n\n if (\n typeof config.addresses === 'undefined' ||\n (typeof config.addresses === 'boolean' && config.addresses === true)\n ) {\n config.addresses = {\n addressFields: defaultAddressFields(),\n }\n } else {\n const addressFields =\n (typeof pluginConfig.addresses === 'object' &&\n typeof pluginConfig.addresses.addressFields === 'function' &&\n pluginConfig.addresses.addressFields({\n defaultFields: defaultAddressFields(),\n })) ||\n defaultAddressFields()\n\n config.addresses = {\n ...config.addresses,\n addressFields,\n }\n }\n\n if (!config.currencies) {\n config.currencies = {\n defaultCurrency: 'USD',\n supportedCurrencies: [USD],\n }\n }\n\n if (\n typeof config.inventory === 'undefined' ||\n (typeof config.inventory === 'boolean' && config.inventory === true)\n ) {\n config.inventory = {\n fieldName: 'inventory',\n }\n }\n\n if (typeof config.carts === 'undefined') {\n config.carts = true\n }\n\n if (typeof config.orders === 'undefined') {\n config.orders = true\n }\n\n if (typeof config.transactions === 'undefined') {\n config.transactions = true\n }\n\n if (typeof config.payments === 'undefined') {\n config.payments = {\n paymentMethods: [],\n }\n } else if (!config.payments.paymentMethods) {\n config.payments.paymentMethods = []\n }\n\n if (config.products) {\n if (typeof config.products === 'object' && typeof config.products.variants === 'undefined') {\n config.products.variants = true\n }\n }\n\n config.access = {\n authenticatedOnly: ({ req: { user } }) => Boolean(user),\n publicAccess: () => true,\n ...pluginConfig.access,\n }\n\n return config as SanitizedEcommercePluginConfig\n}\n"],"names":["defaultAddressFields","USD","sanitizePluginConfig","pluginConfig","config","customers","slug","addresses","addressFields","defaultFields","currencies","defaultCurrency","supportedCurrencies","inventory","fieldName","carts","orders","transactions","payments","paymentMethods","products","variants","access","authenticatedOnly","req","user","Boolean","publicAccess"],"mappings":"AAEA,SAASA,oBAAoB,QAAQ,mDAAkD;AACvF,SAASC,GAAG,QAAQ,yBAAwB;AAM5C,OAAO,MAAMC,uBAAuB,CAAC,EAAEC,YAAY,EAAS;IAC1D,MAAMC,SAAS;QACb,GAAGD,YAAY;IACjB;IAEA,IAAI,OAAOC,OAAOC,SAAS,KAAK,aAAa;QAC3CD,OAAOC,SAAS,GAAG;YACjBC,MAAM;QACR;IACF;IAEA,IACE,OAAOF,OAAOG,SAAS,KAAK,eAC3B,OAAOH,OAAOG,SAAS,KAAK,aAAaH,OAAOG,SAAS,KAAK,MAC/D;QACAH,OAAOG,SAAS,GAAG;YACjBC,eAAeR;QACjB;IACF,OAAO;QACL,MAAMQ,gBACJ,AAAC,OAAOL,aAAaI,SAAS,KAAK,YACjC,OAAOJ,aAAaI,SAAS,CAACC,aAAa,KAAK,cAChDL,aAAaI,SAAS,CAACC,aAAa,CAAC;YACnCC,eAAeT;QACjB,MACFA;QAEFI,OAAOG,SAAS,GAAG;YACjB,GAAGH,OAAOG,SAAS;YACnBC;QACF;IACF;IAEA,IAAI,CAACJ,OAAOM,UAAU,EAAE;QACtBN,OAAOM,UAAU,GAAG;YAClBC,iBAAiB;YACjBC,qBAAqB;gBAACX;aAAI;QAC5B;IACF;IAEA,IACE,OAAOG,OAAOS,SAAS,KAAK,eAC3B,OAAOT,OAAOS,SAAS,KAAK,aAAaT,OAAOS,SAAS,KAAK,MAC/D;QACAT,OAAOS,SAAS,GAAG;YACjBC,WAAW;QACb;IACF;IAEA,IAAI,OAAOV,OAAOW,KAAK,KAAK,aAAa;QACvCX,OAAOW,KAAK,GAAG;IACjB;IAEA,IAAI,OAAOX,OAAOY,MAAM,KAAK,aAAa;QACxCZ,OAAOY,MAAM,GAAG;IAClB;IAEA,IAAI,OAAOZ,OAAOa,YAAY,KAAK,aAAa;QAC9Cb,OAAOa,YAAY,GAAG;IACxB;IAEA,IAAI,OAAOb,OAAOc,QAAQ,KAAK,aAAa;QAC1Cd,OAAOc,QAAQ,GAAG;YAChBC,gBAAgB,EAAE;QACpB;IACF,OAAO,IAAI,CAACf,OAAOc,QAAQ,CAACC,cAAc,EAAE;QAC1Cf,OAAOc,QAAQ,CAACC,cAAc,GAAG,EAAE;IACrC;IAEA,IAAIf,OAAOgB,QAAQ,EAAE;QACnB,IAAI,OAAOhB,OAAOgB,QAAQ,KAAK,YAAY,OAAOhB,OAAOgB,QAAQ,CAACC,QAAQ,KAAK,aAAa;YAC1FjB,OAAOgB,QAAQ,CAACC,QAAQ,GAAG;QAC7B;IACF;IAEAjB,OAAOkB,MAAM,GAAG;QACdC,mBAAmB,CAAC,EAAEC,KAAK,EAAEC,IAAI,EAAE,EAAE,GAAKC,QAAQD;QAClDE,cAAc,IAAM;QACpB,GAAGxB,aAAamB,MAAM;IACxB;IAEA,OAAOlB;AACT,EAAC"}
|
package/package.json
CHANGED
|
@@ -1,4 +1,101 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/plugin-ecommerce",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.57.0-internal.36ffe2b",
|
|
4
|
+
"description": "Ecommerce plugin for Payload",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"payload",
|
|
7
|
+
"cms",
|
|
8
|
+
"plugin",
|
|
9
|
+
"typescript",
|
|
10
|
+
"react",
|
|
11
|
+
"ecommerce"
|
|
12
|
+
],
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "https://github.com/payloadcms/payload.git",
|
|
16
|
+
"directory": "packages/plugin-ecommerce"
|
|
17
|
+
},
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"author": "Payload <dev@payloadcms.com> (https://payloadcms.com)",
|
|
20
|
+
"maintainers": [
|
|
21
|
+
{
|
|
22
|
+
"name": "Payload",
|
|
23
|
+
"email": "info@payloadcms.com",
|
|
24
|
+
"url": "https://payloadcms.com"
|
|
25
|
+
}
|
|
26
|
+
],
|
|
27
|
+
"type": "module",
|
|
28
|
+
"exports": {
|
|
29
|
+
".": {
|
|
30
|
+
"import": "./dist/index.js",
|
|
31
|
+
"types": "./dist/index.d.ts",
|
|
32
|
+
"default": "./dist/index.js"
|
|
33
|
+
},
|
|
34
|
+
"./types": {
|
|
35
|
+
"import": "./dist/exports/types.js",
|
|
36
|
+
"types": "./dist/exports/types.d.ts",
|
|
37
|
+
"default": "./dist/exports/types.js"
|
|
38
|
+
},
|
|
39
|
+
"./payments/stripe": {
|
|
40
|
+
"import": "./dist/exports/payments/stripe.js",
|
|
41
|
+
"types": "./dist/exports/payments/stripe.d.ts",
|
|
42
|
+
"default": "./dist/exports/payments/stripe.js"
|
|
43
|
+
},
|
|
44
|
+
"./rsc": {
|
|
45
|
+
"import": "./dist/exports/rsc.js",
|
|
46
|
+
"types": "./dist/exports/rsc.d.ts",
|
|
47
|
+
"default": "./dist/exports/rsc.js"
|
|
48
|
+
},
|
|
49
|
+
"./client": {
|
|
50
|
+
"import": "./dist/exports/client/index.js",
|
|
51
|
+
"types": "./dist/exports/client/index.d.ts",
|
|
52
|
+
"default": "./dist/exports/client/index.js"
|
|
53
|
+
},
|
|
54
|
+
"./client/react": {
|
|
55
|
+
"import": "./dist/exports/client/react.js",
|
|
56
|
+
"types": "./dist/exports/client/react.d.ts",
|
|
57
|
+
"default": "./dist/exports/client/react.js"
|
|
58
|
+
},
|
|
59
|
+
"./translations": {
|
|
60
|
+
"import": "./dist/exports/translations.js",
|
|
61
|
+
"types": "./dist/exports/translations.d.ts",
|
|
62
|
+
"default": "./dist/exports/translations.js"
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
"main": "./dist/index.js",
|
|
66
|
+
"types": "./dist/index.d.ts",
|
|
67
|
+
"files": [
|
|
68
|
+
"dist"
|
|
69
|
+
],
|
|
70
|
+
"dependencies": {
|
|
71
|
+
"qs-esm": "7.0.2",
|
|
72
|
+
"@payloadcms/translations": "3.57.0-internal.36ffe2b",
|
|
73
|
+
"@payloadcms/ui": "3.57.0-internal.36ffe2b"
|
|
74
|
+
},
|
|
75
|
+
"devDependencies": {
|
|
76
|
+
"@types/react": "19.1.0",
|
|
77
|
+
"@types/react-dom": "19.1.2",
|
|
78
|
+
"stripe": "18.3.0",
|
|
79
|
+
"@payloadcms/next": "3.57.0-internal.36ffe2b",
|
|
80
|
+
"@payloadcms/eslint-config": "3.28.0",
|
|
81
|
+
"payload": "3.57.0-internal.36ffe2b"
|
|
82
|
+
},
|
|
83
|
+
"peerDependencies": {
|
|
84
|
+
"react": "^19.0.0 || ^19.0.0-rc-65a56d0e-20241020",
|
|
85
|
+
"react-dom": "^19.0.0 || ^19.0.0-rc-65a56d0e-20241020",
|
|
86
|
+
"payload": "3.57.0-internal.36ffe2b"
|
|
87
|
+
},
|
|
88
|
+
"publishConfig": {
|
|
89
|
+
"registry": "https://registry.npmjs.org/"
|
|
90
|
+
},
|
|
91
|
+
"homepage:": "https://payloadcms.com",
|
|
92
|
+
"scripts": {
|
|
93
|
+
"build": "pnpm copyfiles && pnpm build:types && pnpm build:swc",
|
|
94
|
+
"build:swc": "swc ./src -d ./dist --config-file .swcrc --strip-leading-paths",
|
|
95
|
+
"build:types": "tsc --emitDeclarationOnly --outDir dist",
|
|
96
|
+
"clean": "rimraf -g {dist,*.tsbuildinfo}",
|
|
97
|
+
"copyfiles": "copyfiles -u 1 \"src/**/*.{html,css,scss,ttf,woff,woff2,eot,svg,jpg,png,json}\" dist/",
|
|
98
|
+
"lint": "eslint .",
|
|
99
|
+
"lint:fix": "eslint . --fix"
|
|
100
|
+
}
|
|
4
101
|
}
|
package/.prettierignore
DELETED
package/.swcrc
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "https://json.schemastore.org/swcrc",
|
|
3
|
-
"sourceMaps": true,
|
|
4
|
-
"jsc": {
|
|
5
|
-
"target": "esnext",
|
|
6
|
-
"parser": {
|
|
7
|
-
"syntax": "typescript",
|
|
8
|
-
"tsx": true,
|
|
9
|
-
"dts": true
|
|
10
|
-
},
|
|
11
|
-
"transform": {
|
|
12
|
-
"react": {
|
|
13
|
-
"runtime": "automatic",
|
|
14
|
-
"pragmaFrag": "React.Fragment",
|
|
15
|
-
"throwIfNamespace": true,
|
|
16
|
-
"development": false,
|
|
17
|
-
"useBuiltins": true
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
},
|
|
21
|
-
"module": {
|
|
22
|
-
"type": "es6"
|
|
23
|
-
}
|
|
24
|
-
}
|
package/eslint.config.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { rootEslintConfig, rootParserOptions } from '../../eslint.config.js'
|
|
2
|
-
|
|
3
|
-
/** @typedef {import('eslint').Linter.Config} Config */
|
|
4
|
-
|
|
5
|
-
/** @type {Config[]} */
|
|
6
|
-
export const index = [
|
|
7
|
-
...rootEslintConfig,
|
|
8
|
-
{
|
|
9
|
-
languageOptions: {
|
|
10
|
-
parserOptions: {
|
|
11
|
-
...rootParserOptions,
|
|
12
|
-
tsconfigRootDir: import.meta.dirname,
|
|
13
|
-
},
|
|
14
|
-
},
|
|
15
|
-
},
|
|
16
|
-
]
|
|
17
|
-
|
|
18
|
-
export default index
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import type { CollectionConfig, Field } from 'payload'
|
|
2
|
-
|
|
3
|
-
import type { CountryType, FieldsOverride } from '../types.js'
|
|
4
|
-
|
|
5
|
-
import { defaultCountries } from './defaultCountries.js'
|
|
6
|
-
|
|
7
|
-
type Props = {
|
|
8
|
-
/**
|
|
9
|
-
* Array of fields used for capturing the address data. Use this over overrides to customise the fields here as it's reused across the plugin.
|
|
10
|
-
*/
|
|
11
|
-
addressFields: Field[]
|
|
12
|
-
/**
|
|
13
|
-
* Slug of the customers collection, defaults to 'users'.
|
|
14
|
-
*/
|
|
15
|
-
customersSlug?: string
|
|
16
|
-
overrides?: { fields?: FieldsOverride } & Partial<Omit<CollectionConfig, 'fields'>>
|
|
17
|
-
supportedCountries?: CountryType[]
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export const addressesCollection: (props: Props) => CollectionConfig = (props) => {
|
|
21
|
-
const { addressFields, customersSlug = 'users', overrides } = props || {}
|
|
22
|
-
const fieldsOverride = overrides?.fields
|
|
23
|
-
|
|
24
|
-
const { supportedCountries: supportedCountriesFromProps } = props || {}
|
|
25
|
-
const supportedCountries = supportedCountriesFromProps || defaultCountries
|
|
26
|
-
const hasOnlyOneCountry = supportedCountries && supportedCountries.length === 1
|
|
27
|
-
|
|
28
|
-
const defaultFields: Field[] = [
|
|
29
|
-
{
|
|
30
|
-
name: 'customer',
|
|
31
|
-
type: 'relationship',
|
|
32
|
-
label: ({ t }) =>
|
|
33
|
-
// @ts-expect-error - translations are not typed in plugins yet
|
|
34
|
-
t('plugin-ecommerce:customer'),
|
|
35
|
-
relationTo: customersSlug,
|
|
36
|
-
},
|
|
37
|
-
...addressFields.map((field) => {
|
|
38
|
-
if ('name' in field && field.name === 'country') {
|
|
39
|
-
return {
|
|
40
|
-
name: 'country',
|
|
41
|
-
type: 'select',
|
|
42
|
-
label: ({ t }) =>
|
|
43
|
-
// @ts-expect-error - translations are not typed in plugins yet
|
|
44
|
-
t('plugin-ecommerce:addressCountry'),
|
|
45
|
-
options: supportedCountries || defaultCountries,
|
|
46
|
-
required: true,
|
|
47
|
-
...(supportedCountries && supportedCountries?.[0] && hasOnlyOneCountry
|
|
48
|
-
? {
|
|
49
|
-
defaultValue: supportedCountries?.[0].value,
|
|
50
|
-
}
|
|
51
|
-
: {}),
|
|
52
|
-
} as Field
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return field
|
|
56
|
-
}),
|
|
57
|
-
]
|
|
58
|
-
|
|
59
|
-
const fields =
|
|
60
|
-
fieldsOverride && typeof fieldsOverride === 'function'
|
|
61
|
-
? fieldsOverride({ defaultFields })
|
|
62
|
-
: defaultFields
|
|
63
|
-
|
|
64
|
-
const baseConfig: CollectionConfig = {
|
|
65
|
-
slug: 'addresses',
|
|
66
|
-
timestamps: true,
|
|
67
|
-
...overrides,
|
|
68
|
-
admin: {
|
|
69
|
-
useAsTitle: 'createdAt',
|
|
70
|
-
...overrides?.admin,
|
|
71
|
-
},
|
|
72
|
-
fields,
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
return { ...baseConfig }
|
|
76
|
-
}
|