@payloadcms/storage-r2 0.0.1-beta.0 → 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/handleDelete.d.ts +8 -0
- package/dist/handleDelete.d.ts.map +1 -0
- package/dist/handleDelete.js +8 -0
- package/dist/handleDelete.js.map +1 -0
- package/dist/handleUpload.d.ts +11 -0
- package/dist/handleUpload.d.ts.map +1 -0
- package/dist/handleUpload.js +13 -0
- package/dist/handleUpload.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +59 -0
- package/dist/index.js.map +1 -0
- package/dist/staticHandler.d.ts +11 -0
- package/dist/staticHandler.d.ts.map +1 -0
- package/dist/staticHandler.js +29 -0
- package/dist/staticHandler.js.map +1 -0
- package/dist/types.d.ts +16 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/package.json +57 -1
- package/.prettierignore +0 -12
- package/.swcrc +0 -24
- package/README.md +0 -3
- 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/translations/translation-schema.json +0 -35
- package/src/types.ts +0 -403
- package/src/ui/PriceInput/FormattedInput.tsx +0 -134
- package/src/ui/PriceInput/index.scss +0 -28
- package/src/ui/PriceInput/index.tsx +0 -43
- package/src/ui/PriceInput/utilities.ts +0 -46
- package/src/ui/PriceRowLabel/index.css +0 -13
- 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.css +0 -37
- 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
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import type { Validate } from 'payload'
|
|
2
|
-
|
|
3
|
-
type Props = {
|
|
4
|
-
productsCollectionSlug?: string
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export const validateOptions: (props?: Props) => Validate =
|
|
8
|
-
(props) =>
|
|
9
|
-
async (values, { data, req }) => {
|
|
10
|
-
const { productsCollectionSlug = 'products' } = props || {}
|
|
11
|
-
const { t } = req
|
|
12
|
-
|
|
13
|
-
if (!values || values.length === 0) {
|
|
14
|
-
// @ts-expect-error - TODO: Fix types
|
|
15
|
-
return t('ecommerce:variantOptionsRequired')
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const productID = data.product
|
|
19
|
-
|
|
20
|
-
if (!productID) {
|
|
21
|
-
// @ts-expect-error - TODO: Fix types
|
|
22
|
-
return t('ecommerce:productRequired')
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const product = await req.payload.findByID({
|
|
26
|
-
id: productID,
|
|
27
|
-
collection: productsCollectionSlug,
|
|
28
|
-
depth: 1,
|
|
29
|
-
joins: {
|
|
30
|
-
variants: {
|
|
31
|
-
where: {
|
|
32
|
-
id: {
|
|
33
|
-
not_equals: data.id, // exclude the current variant from the search
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
},
|
|
37
|
-
},
|
|
38
|
-
select: {
|
|
39
|
-
variants: true,
|
|
40
|
-
variantTypes: true,
|
|
41
|
-
},
|
|
42
|
-
user: req.user,
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
// @ts-expect-error - TODO: Fix types
|
|
46
|
-
const variants = product.variants?.docs ?? []
|
|
47
|
-
|
|
48
|
-
// @ts-expect-error - TODO: Fix types
|
|
49
|
-
if (values.length < product?.variantTypes?.length) {
|
|
50
|
-
// @ts-expect-error - TODO: Fix types
|
|
51
|
-
return t('ecommerce:variantOptionsRequiredAll')
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
if (variants.length > 0) {
|
|
55
|
-
const existingOptions: (number | string)[][] = []
|
|
56
|
-
|
|
57
|
-
variants.forEach((variant: any) => {
|
|
58
|
-
existingOptions.push(variant.options)
|
|
59
|
-
})
|
|
60
|
-
|
|
61
|
-
const exists = existingOptions.some(
|
|
62
|
-
(combo) => combo.length === values.length && combo.every((val) => values.includes(val)),
|
|
63
|
-
)
|
|
64
|
-
|
|
65
|
-
if (exists) {
|
|
66
|
-
// @ts-expect-error - TODO: Fix types
|
|
67
|
-
return t('ecommerce:variantOptionsAlreadyExists')
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
return true
|
|
72
|
-
}
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
import type { CollectionConfig, Field } from 'payload'
|
|
2
|
-
|
|
3
|
-
import type { CurrenciesConfig, FieldsOverride, InventoryConfig } from '../../types.js'
|
|
4
|
-
|
|
5
|
-
import { inventoryField } from '../../fields/inventoryField.js'
|
|
6
|
-
import { pricesField } from '../../fields/pricesField.js'
|
|
7
|
-
import { variantsCollectionBeforeChange as beforeChange } from './hooks/beforeChange.js'
|
|
8
|
-
import { validateOptions } from './hooks/validateOptions.js'
|
|
9
|
-
|
|
10
|
-
type Props = {
|
|
11
|
-
currenciesConfig?: CurrenciesConfig
|
|
12
|
-
/**
|
|
13
|
-
* Enables inventory tracking for variants. Defaults to true.
|
|
14
|
-
*/
|
|
15
|
-
inventory?: InventoryConfig
|
|
16
|
-
overrides?: { fields?: FieldsOverride } & Partial<Omit<CollectionConfig, 'fields'>>
|
|
17
|
-
/**
|
|
18
|
-
* Slug of the products collection, defaults to 'products'.
|
|
19
|
-
*/
|
|
20
|
-
productsSlug?: string
|
|
21
|
-
/**
|
|
22
|
-
* Slug of the variant options collection, defaults to 'variantOptions'.
|
|
23
|
-
*/
|
|
24
|
-
variantOptionsSlug?: string
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export const variantsCollection: (props: Props) => CollectionConfig = (props) => {
|
|
28
|
-
const {
|
|
29
|
-
currenciesConfig,
|
|
30
|
-
inventory = true,
|
|
31
|
-
overrides,
|
|
32
|
-
productsSlug = 'products',
|
|
33
|
-
variantOptionsSlug = 'variantOptions',
|
|
34
|
-
} = props || {}
|
|
35
|
-
const { supportedCurrencies } = currenciesConfig || {}
|
|
36
|
-
const fieldsOverride = overrides?.fields
|
|
37
|
-
|
|
38
|
-
const defaultFields: Field[] = [
|
|
39
|
-
{
|
|
40
|
-
name: 'title',
|
|
41
|
-
type: 'text',
|
|
42
|
-
admin: {
|
|
43
|
-
description:
|
|
44
|
-
'Used for administrative purposes, not shown to customers. This is populated by default.',
|
|
45
|
-
},
|
|
46
|
-
},
|
|
47
|
-
{
|
|
48
|
-
name: 'product',
|
|
49
|
-
type: 'relationship',
|
|
50
|
-
admin: {
|
|
51
|
-
description:
|
|
52
|
-
'this should not be editable, or at least, should be able to be pre-filled via default',
|
|
53
|
-
readOnly: true,
|
|
54
|
-
},
|
|
55
|
-
relationTo: productsSlug,
|
|
56
|
-
required: true,
|
|
57
|
-
},
|
|
58
|
-
{
|
|
59
|
-
// This might need to be a custom component, to show a selector for each variant that is
|
|
60
|
-
// enabled on the parent product
|
|
61
|
-
// - separate select inputs, each showing only a specific variant (w/ options)
|
|
62
|
-
// - it will save data to the DB as IDs in this relationship field
|
|
63
|
-
// and needs a validate function as well which enforces that the options are fully specified,
|
|
64
|
-
// and accurate
|
|
65
|
-
name: 'options',
|
|
66
|
-
type: 'relationship',
|
|
67
|
-
admin: {
|
|
68
|
-
components: {
|
|
69
|
-
Field: {
|
|
70
|
-
path: '@payloadcms/plugin-ecommerce/ui#VariantOptionsSelector',
|
|
71
|
-
},
|
|
72
|
-
},
|
|
73
|
-
},
|
|
74
|
-
hasMany: true,
|
|
75
|
-
label: 'Variant options',
|
|
76
|
-
relationTo: variantOptionsSlug,
|
|
77
|
-
required: true,
|
|
78
|
-
validate: validateOptions(),
|
|
79
|
-
},
|
|
80
|
-
...(inventory ? [inventoryField()] : []),
|
|
81
|
-
]
|
|
82
|
-
|
|
83
|
-
if (supportedCurrencies?.length && supportedCurrencies.length > 0) {
|
|
84
|
-
const currencyOptions: string[] = []
|
|
85
|
-
|
|
86
|
-
supportedCurrencies.forEach((currency) => {
|
|
87
|
-
currencyOptions.push(currency.code)
|
|
88
|
-
})
|
|
89
|
-
|
|
90
|
-
if (currenciesConfig) {
|
|
91
|
-
defaultFields.push(...pricesField({ currenciesConfig }))
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
const fields =
|
|
96
|
-
fieldsOverride && typeof fieldsOverride === 'function'
|
|
97
|
-
? fieldsOverride({ defaultFields })
|
|
98
|
-
: defaultFields
|
|
99
|
-
|
|
100
|
-
const baseConfig: CollectionConfig = {
|
|
101
|
-
slug: 'variants',
|
|
102
|
-
...overrides,
|
|
103
|
-
admin: {
|
|
104
|
-
// group: false,
|
|
105
|
-
useAsTitle: 'title',
|
|
106
|
-
...overrides?.admin,
|
|
107
|
-
},
|
|
108
|
-
fields,
|
|
109
|
-
hooks: {
|
|
110
|
-
...overrides?.hooks,
|
|
111
|
-
beforeChange: [
|
|
112
|
-
beforeChange({ productsSlug, variantOptionsSlug }),
|
|
113
|
-
...(overrides?.hooks?.beforeChange || []),
|
|
114
|
-
],
|
|
115
|
-
},
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
return { ...baseConfig }
|
|
119
|
-
}
|