@payloadcms/storage-r2 0.0.1-beta.0 → 3.58.0-internal.8775d75
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,322 +0,0 @@
|
|
|
1
|
-
import { addDataAndFileToRequest, type DefaultDocumentIDType, type Endpoint } from 'payload'
|
|
2
|
-
|
|
3
|
-
import type {
|
|
4
|
-
CurrenciesConfig,
|
|
5
|
-
PaymentAdapter,
|
|
6
|
-
ProductsValidation,
|
|
7
|
-
SanitizedEcommercePluginConfig,
|
|
8
|
-
} from '../types.js'
|
|
9
|
-
|
|
10
|
-
import { defaultProductsValidation } from '../utilities/defaultProductsValidation.js'
|
|
11
|
-
|
|
12
|
-
type Args = {
|
|
13
|
-
/**
|
|
14
|
-
* The slug of the carts collection, defaults to 'carts'.
|
|
15
|
-
*/
|
|
16
|
-
cartsSlug?: string
|
|
17
|
-
currenciesConfig: CurrenciesConfig
|
|
18
|
-
/**
|
|
19
|
-
* The slug of the customers collection, defaults to 'users'.
|
|
20
|
-
*/
|
|
21
|
-
customersSlug?: string
|
|
22
|
-
/**
|
|
23
|
-
* Track inventory stock for the products and variants.
|
|
24
|
-
* Accepts an object to override the default field name.
|
|
25
|
-
*/
|
|
26
|
-
inventory?: SanitizedEcommercePluginConfig['inventory']
|
|
27
|
-
paymentMethod: PaymentAdapter
|
|
28
|
-
/**
|
|
29
|
-
* The slug of the products collection, defaults to 'products'.
|
|
30
|
-
*/
|
|
31
|
-
productsSlug?: string
|
|
32
|
-
/**
|
|
33
|
-
* Customise the validation used for checking products or variants before a transaction is created.
|
|
34
|
-
*/
|
|
35
|
-
productsValidation?: ProductsValidation
|
|
36
|
-
/**
|
|
37
|
-
* The slug of the transactions collection, defaults to 'transactions'.
|
|
38
|
-
*/
|
|
39
|
-
transactionsSlug?: string
|
|
40
|
-
/**
|
|
41
|
-
* The slug of the variants collection, defaults to 'variants'.
|
|
42
|
-
*/
|
|
43
|
-
variantsSlug?: string
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
type InitiatePayment = (args: Args) => Endpoint['handler']
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Handles the endpoint for initiating payments. We will handle checking the amount and product and variant prices here before it is sent to the payment provider.
|
|
50
|
-
* This is the first step in the payment process.
|
|
51
|
-
*/
|
|
52
|
-
export const initiatePaymentHandler: InitiatePayment =
|
|
53
|
-
({
|
|
54
|
-
cartsSlug = 'carts',
|
|
55
|
-
currenciesConfig,
|
|
56
|
-
customersSlug = 'users',
|
|
57
|
-
paymentMethod,
|
|
58
|
-
productsSlug = 'products',
|
|
59
|
-
productsValidation,
|
|
60
|
-
transactionsSlug = 'transactions',
|
|
61
|
-
variantsSlug = 'variants',
|
|
62
|
-
}) =>
|
|
63
|
-
async (req) => {
|
|
64
|
-
await addDataAndFileToRequest(req)
|
|
65
|
-
const data = req.data
|
|
66
|
-
const payload = req.payload
|
|
67
|
-
const user = req.user
|
|
68
|
-
|
|
69
|
-
let currency: string = currenciesConfig.defaultCurrency
|
|
70
|
-
let cartID: DefaultDocumentIDType = data?.cartID
|
|
71
|
-
let cart = undefined
|
|
72
|
-
const billingAddress = data?.billingAddress
|
|
73
|
-
const shippingAddress = data?.shippingAddress
|
|
74
|
-
|
|
75
|
-
let customerEmail: string = user?.email ?? ''
|
|
76
|
-
|
|
77
|
-
if (user) {
|
|
78
|
-
if (user.cart?.docs && Array.isArray(user.cart.docs) && user.cart.docs.length > 0) {
|
|
79
|
-
if (!cartID && user.cart.docs[0]) {
|
|
80
|
-
// Use the user's cart instead
|
|
81
|
-
if (typeof user.cart.docs[0] === 'object') {
|
|
82
|
-
cartID = user.cart.docs[0].id
|
|
83
|
-
cart = user.cart.docs[0]
|
|
84
|
-
} else {
|
|
85
|
-
cartID = user.cart.docs[0]
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
} else {
|
|
90
|
-
// Get the email from the data if user is not available
|
|
91
|
-
if (data?.customerEmail && typeof data.customerEmail === 'string') {
|
|
92
|
-
customerEmail = data.customerEmail
|
|
93
|
-
} else {
|
|
94
|
-
return Response.json(
|
|
95
|
-
{
|
|
96
|
-
message: 'A customer email is required to make a purchase.',
|
|
97
|
-
},
|
|
98
|
-
{
|
|
99
|
-
status: 400,
|
|
100
|
-
},
|
|
101
|
-
)
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
if (!cart) {
|
|
106
|
-
if (cartID) {
|
|
107
|
-
cart = await payload.findByID({
|
|
108
|
-
id: cartID,
|
|
109
|
-
collection: cartsSlug,
|
|
110
|
-
depth: 2,
|
|
111
|
-
overrideAccess: false,
|
|
112
|
-
select: {
|
|
113
|
-
id: true,
|
|
114
|
-
currency: true,
|
|
115
|
-
customerEmail: true,
|
|
116
|
-
items: true,
|
|
117
|
-
subtotal: true,
|
|
118
|
-
},
|
|
119
|
-
user,
|
|
120
|
-
})
|
|
121
|
-
|
|
122
|
-
if (!cart) {
|
|
123
|
-
return Response.json(
|
|
124
|
-
{
|
|
125
|
-
message: `Cart with ID ${cartID} not found.`,
|
|
126
|
-
},
|
|
127
|
-
{
|
|
128
|
-
status: 404,
|
|
129
|
-
},
|
|
130
|
-
)
|
|
131
|
-
}
|
|
132
|
-
} else {
|
|
133
|
-
return Response.json(
|
|
134
|
-
{
|
|
135
|
-
message: 'Cart ID is required.',
|
|
136
|
-
},
|
|
137
|
-
{
|
|
138
|
-
status: 400,
|
|
139
|
-
},
|
|
140
|
-
)
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
if (cart.currency && typeof cart.currency === 'string') {
|
|
145
|
-
currency = cart.currency
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
// Ensure the currency is provided or inferred in some way
|
|
149
|
-
if (!currency) {
|
|
150
|
-
return Response.json(
|
|
151
|
-
{
|
|
152
|
-
message: 'Currency is required.',
|
|
153
|
-
},
|
|
154
|
-
{
|
|
155
|
-
status: 400,
|
|
156
|
-
},
|
|
157
|
-
)
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
// Ensure the selected currency is supported
|
|
161
|
-
if (
|
|
162
|
-
!currenciesConfig.supportedCurrencies.find(
|
|
163
|
-
(c) => c.code.toLocaleLowerCase() === currency.toLocaleLowerCase(),
|
|
164
|
-
)
|
|
165
|
-
) {
|
|
166
|
-
return Response.json(
|
|
167
|
-
{
|
|
168
|
-
message: `Currency ${currency} is not supported.`,
|
|
169
|
-
},
|
|
170
|
-
{
|
|
171
|
-
status: 400,
|
|
172
|
-
},
|
|
173
|
-
)
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
// Verify the cart is available and items are present in an array
|
|
177
|
-
if (!cart || !cart.items || !Array.isArray(cart.items) || cart.items.length === 0) {
|
|
178
|
-
return Response.json(
|
|
179
|
-
{
|
|
180
|
-
message: 'Cart is required and must contain at least one item.',
|
|
181
|
-
},
|
|
182
|
-
{
|
|
183
|
-
status: 400,
|
|
184
|
-
},
|
|
185
|
-
)
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
for (const item of cart.items) {
|
|
189
|
-
// Target field to check the price based on the currency so we can validate the total
|
|
190
|
-
const priceField = `priceIn${currency.toUpperCase()}`
|
|
191
|
-
const quantity = item.quantity || 1
|
|
192
|
-
|
|
193
|
-
// If the item has a product but no variant, we assume the product has a price in the specified currency
|
|
194
|
-
if (item.product && !item.variant) {
|
|
195
|
-
const id = typeof item.product === 'object' ? item.product.id : item.product
|
|
196
|
-
|
|
197
|
-
const product = await payload.findByID({
|
|
198
|
-
id,
|
|
199
|
-
collection: productsSlug,
|
|
200
|
-
depth: 0,
|
|
201
|
-
select: {
|
|
202
|
-
[priceField]: true,
|
|
203
|
-
},
|
|
204
|
-
})
|
|
205
|
-
|
|
206
|
-
if (!product) {
|
|
207
|
-
return Response.json(
|
|
208
|
-
{
|
|
209
|
-
message: `Product with ID ${item.product} not found.`,
|
|
210
|
-
},
|
|
211
|
-
{
|
|
212
|
-
status: 404,
|
|
213
|
-
},
|
|
214
|
-
)
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
try {
|
|
218
|
-
if (productsValidation) {
|
|
219
|
-
await productsValidation({ currenciesConfig, currency, product, quantity })
|
|
220
|
-
} else {
|
|
221
|
-
await defaultProductsValidation({
|
|
222
|
-
currenciesConfig,
|
|
223
|
-
currency,
|
|
224
|
-
product,
|
|
225
|
-
quantity,
|
|
226
|
-
})
|
|
227
|
-
}
|
|
228
|
-
} catch (error) {
|
|
229
|
-
return Response.json(
|
|
230
|
-
{
|
|
231
|
-
message: error,
|
|
232
|
-
},
|
|
233
|
-
{
|
|
234
|
-
status: 400,
|
|
235
|
-
},
|
|
236
|
-
)
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
if (item.variant) {
|
|
240
|
-
const id = typeof item.variant === 'object' ? item.variant.id : item.variant
|
|
241
|
-
|
|
242
|
-
const variant = await payload.findByID({
|
|
243
|
-
id,
|
|
244
|
-
collection: variantsSlug,
|
|
245
|
-
depth: 0,
|
|
246
|
-
select: {
|
|
247
|
-
inventory: true,
|
|
248
|
-
[priceField]: true,
|
|
249
|
-
},
|
|
250
|
-
})
|
|
251
|
-
|
|
252
|
-
if (!variant) {
|
|
253
|
-
return Response.json(
|
|
254
|
-
{
|
|
255
|
-
message: `Variant with ID ${item.variant} not found.`,
|
|
256
|
-
},
|
|
257
|
-
{
|
|
258
|
-
status: 404,
|
|
259
|
-
},
|
|
260
|
-
)
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
try {
|
|
264
|
-
if (productsValidation) {
|
|
265
|
-
await productsValidation({
|
|
266
|
-
currenciesConfig,
|
|
267
|
-
currency,
|
|
268
|
-
product: item.product,
|
|
269
|
-
quantity,
|
|
270
|
-
variant,
|
|
271
|
-
})
|
|
272
|
-
} else {
|
|
273
|
-
await defaultProductsValidation({
|
|
274
|
-
currenciesConfig,
|
|
275
|
-
currency,
|
|
276
|
-
product: item.product,
|
|
277
|
-
quantity,
|
|
278
|
-
variant,
|
|
279
|
-
})
|
|
280
|
-
}
|
|
281
|
-
} catch (error) {
|
|
282
|
-
return Response.json(
|
|
283
|
-
{
|
|
284
|
-
message: error,
|
|
285
|
-
},
|
|
286
|
-
{
|
|
287
|
-
status: 400,
|
|
288
|
-
},
|
|
289
|
-
)
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
try {
|
|
296
|
-
const paymentResponse = await paymentMethod.initiatePayment({
|
|
297
|
-
customersSlug,
|
|
298
|
-
data: {
|
|
299
|
-
billingAddress,
|
|
300
|
-
cart,
|
|
301
|
-
currency,
|
|
302
|
-
customerEmail,
|
|
303
|
-
shippingAddress,
|
|
304
|
-
},
|
|
305
|
-
req,
|
|
306
|
-
transactionsSlug,
|
|
307
|
-
})
|
|
308
|
-
|
|
309
|
-
return Response.json(paymentResponse)
|
|
310
|
-
} catch (error) {
|
|
311
|
-
payload.logger.error(error, 'Error initiating payment.')
|
|
312
|
-
|
|
313
|
-
return Response.json(
|
|
314
|
-
{
|
|
315
|
-
message: 'Error initiating payment.',
|
|
316
|
-
},
|
|
317
|
-
{
|
|
318
|
-
status: 500,
|
|
319
|
-
},
|
|
320
|
-
)
|
|
321
|
-
}
|
|
322
|
-
}
|
package/src/exports/addresses.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { EUR, GBP, JPY, USD } from '../currencies/index.js'
|
package/src/exports/fields.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
export { amountField } from '../fields/amountField.js'
|
|
2
|
-
export { currencyField } from '../fields/currencyField.js'
|
|
3
|
-
export { pricesField } from '../fields/pricesField.js'
|
|
4
|
-
export { statusField } from '../fields/statusField.js'
|
|
5
|
-
export { variantsFields } from '../fields/variantsFields.js'
|
package/src/exports/orders.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { ordersCollection } from '../orders/ordersCollection.js'
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { stripeAdapter, stripeAdapterClient } from '../../payments/adapters/stripe/index.js'
|
package/src/exports/plugin.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { ecommercePlugin } from '../index.js'
|
package/src/exports/products.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { productsCollection } from '../products/productsCollection.js'
|
package/src/exports/react.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { transactionsCollection } from '../transactions/transactionsCollection.js'
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { en } from '../translations/en.js'
|
package/src/exports/types.ts
DELETED
package/src/exports/ui.ts
DELETED
package/src/exports/variants.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import type { NumberField } from 'payload'
|
|
2
|
-
|
|
3
|
-
import type { CurrenciesConfig, Currency } from '../types.js'
|
|
4
|
-
|
|
5
|
-
type Props = {
|
|
6
|
-
currenciesConfig: CurrenciesConfig
|
|
7
|
-
/**
|
|
8
|
-
* Use this specific currency for the field.
|
|
9
|
-
*/
|
|
10
|
-
currency?: Currency
|
|
11
|
-
overrides?: Partial<NumberField>
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export const amountField: (props: Props) => NumberField = ({
|
|
15
|
-
currenciesConfig,
|
|
16
|
-
currency,
|
|
17
|
-
overrides,
|
|
18
|
-
}) => {
|
|
19
|
-
// @ts-expect-error - issue with payload types
|
|
20
|
-
const field: NumberField = {
|
|
21
|
-
name: 'amount',
|
|
22
|
-
type: 'number',
|
|
23
|
-
label: ({ t }) =>
|
|
24
|
-
// @ts-expect-error - translations are not typed in plugins yet
|
|
25
|
-
t('plugin-ecommerce:amount'),
|
|
26
|
-
...overrides,
|
|
27
|
-
admin: {
|
|
28
|
-
components: {
|
|
29
|
-
Field: {
|
|
30
|
-
clientProps: {
|
|
31
|
-
currenciesConfig,
|
|
32
|
-
currency,
|
|
33
|
-
},
|
|
34
|
-
path: '@payloadcms/plugin-ecommerce/ui#PriceInput',
|
|
35
|
-
},
|
|
36
|
-
...overrides?.admin?.components,
|
|
37
|
-
},
|
|
38
|
-
...overrides?.admin,
|
|
39
|
-
},
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return field
|
|
43
|
-
}
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import type { ArrayField, Field } from 'payload'
|
|
2
|
-
|
|
3
|
-
import type { CurrenciesConfig } from '../types.js'
|
|
4
|
-
|
|
5
|
-
import { amountField } from './amountField.js'
|
|
6
|
-
import { currencyField } from './currencyField.js'
|
|
7
|
-
|
|
8
|
-
type Props = {
|
|
9
|
-
/**
|
|
10
|
-
* Include this in order to enable support for currencies per item in the cart.
|
|
11
|
-
*/
|
|
12
|
-
currenciesConfig?: CurrenciesConfig
|
|
13
|
-
enableVariants?: boolean
|
|
14
|
-
/**
|
|
15
|
-
* Enables individual prices for each item in the cart.
|
|
16
|
-
* Defaults to false.
|
|
17
|
-
*/
|
|
18
|
-
individualPrices?: boolean
|
|
19
|
-
overrides?: Partial<ArrayField>
|
|
20
|
-
/**
|
|
21
|
-
* Slug of the products collection, defaults to 'products'.
|
|
22
|
-
*/
|
|
23
|
-
productsSlug?: string
|
|
24
|
-
/**
|
|
25
|
-
* Slug of the variants collection, defaults to 'variants'.
|
|
26
|
-
*/
|
|
27
|
-
variantsSlug?: string
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export const cartItemsField: (props?: Props) => ArrayField = (props) => {
|
|
31
|
-
const {
|
|
32
|
-
currenciesConfig,
|
|
33
|
-
enableVariants = false,
|
|
34
|
-
individualPrices,
|
|
35
|
-
overrides,
|
|
36
|
-
productsSlug = 'products',
|
|
37
|
-
variantsSlug = 'variants',
|
|
38
|
-
} = props || {}
|
|
39
|
-
|
|
40
|
-
const field: ArrayField = {
|
|
41
|
-
name: 'items',
|
|
42
|
-
type: 'array',
|
|
43
|
-
fields: [
|
|
44
|
-
{
|
|
45
|
-
name: 'product',
|
|
46
|
-
type: 'relationship',
|
|
47
|
-
label: ({ t }) =>
|
|
48
|
-
// @ts-expect-error - translations are not typed in plugins yet
|
|
49
|
-
t('plugin-ecommerce:product'),
|
|
50
|
-
relationTo: productsSlug,
|
|
51
|
-
},
|
|
52
|
-
...(enableVariants
|
|
53
|
-
? [
|
|
54
|
-
{
|
|
55
|
-
name: 'variant',
|
|
56
|
-
type: 'relationship',
|
|
57
|
-
label: ({ t }) =>
|
|
58
|
-
// @ts-expect-error - translations are not typed in plugins yet
|
|
59
|
-
t('plugin-ecommerce:variant'),
|
|
60
|
-
relationTo: variantsSlug,
|
|
61
|
-
} as Field,
|
|
62
|
-
]
|
|
63
|
-
: []),
|
|
64
|
-
{
|
|
65
|
-
name: 'quantity',
|
|
66
|
-
type: 'number',
|
|
67
|
-
defaultValue: 1,
|
|
68
|
-
label: ({ t }) =>
|
|
69
|
-
// @ts-expect-error - translations are not typed in plugins yet
|
|
70
|
-
t('plugin-ecommerce:quantity'),
|
|
71
|
-
min: 1,
|
|
72
|
-
required: true,
|
|
73
|
-
},
|
|
74
|
-
...(currenciesConfig && individualPrices ? [amountField({ currenciesConfig })] : []),
|
|
75
|
-
...(currenciesConfig ? [currencyField({ currenciesConfig })] : []),
|
|
76
|
-
],
|
|
77
|
-
label: ({ t }) =>
|
|
78
|
-
// @ts-expect-error - translations are not typed in plugins yet
|
|
79
|
-
t('plugin-ecommerce:cart'),
|
|
80
|
-
...overrides,
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
return field
|
|
84
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import type { SelectField } from 'payload'
|
|
2
|
-
|
|
3
|
-
import type { CurrenciesConfig } from '../types.js'
|
|
4
|
-
|
|
5
|
-
type Props = {
|
|
6
|
-
currenciesConfig: CurrenciesConfig
|
|
7
|
-
overrides?: Partial<SelectField>
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export const currencyField: (props: Props) => SelectField = ({ currenciesConfig, overrides }) => {
|
|
11
|
-
const options = currenciesConfig.supportedCurrencies.map((currency) => {
|
|
12
|
-
const label = currency.label ? `${currency.label} (${currency.code})` : currency.code
|
|
13
|
-
|
|
14
|
-
return {
|
|
15
|
-
label,
|
|
16
|
-
value: currency.code,
|
|
17
|
-
}
|
|
18
|
-
})
|
|
19
|
-
|
|
20
|
-
const defaultValue =
|
|
21
|
-
(currenciesConfig.defaultCurrency ?? currenciesConfig.supportedCurrencies.length === 1)
|
|
22
|
-
? currenciesConfig.supportedCurrencies[0]?.code
|
|
23
|
-
: undefined
|
|
24
|
-
|
|
25
|
-
// @ts-expect-error - issue with payload types
|
|
26
|
-
const field: SelectField = {
|
|
27
|
-
name: 'currency',
|
|
28
|
-
type: 'select',
|
|
29
|
-
label: ({ t }) =>
|
|
30
|
-
// @ts-expect-error - translations are not typed in plugins yet
|
|
31
|
-
t('plugin-ecommerce:currency'),
|
|
32
|
-
...(defaultValue && { defaultValue }),
|
|
33
|
-
options,
|
|
34
|
-
...overrides,
|
|
35
|
-
admin: { readOnly: currenciesConfig.supportedCurrencies.length === 1, ...overrides?.admin },
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return field
|
|
39
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import type { NumberField } from 'payload'
|
|
2
|
-
|
|
3
|
-
type Props = {
|
|
4
|
-
overrides?: Partial<NumberField>
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export const inventoryField: (props?: Props) => NumberField = (props) => {
|
|
8
|
-
const { overrides } = props || {}
|
|
9
|
-
|
|
10
|
-
// @ts-expect-error - issue with payload types
|
|
11
|
-
const field: NumberField = {
|
|
12
|
-
name: 'inventory',
|
|
13
|
-
type: 'number',
|
|
14
|
-
defaultValue: 0,
|
|
15
|
-
// @ts-expect-error - translations are not typed in plugins yet
|
|
16
|
-
label: ({ t }) => t('plugin-ecommerce:inventory'),
|
|
17
|
-
min: 0,
|
|
18
|
-
...(overrides || {}),
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
return field
|
|
22
|
-
}
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import type { GroupField } from 'payload'
|
|
2
|
-
|
|
3
|
-
import type { CurrenciesConfig } from '../types.js'
|
|
4
|
-
|
|
5
|
-
import { amountField } from './amountField.js'
|
|
6
|
-
|
|
7
|
-
type Props = {
|
|
8
|
-
/**
|
|
9
|
-
* Use this to specify a path for the condition.
|
|
10
|
-
*/
|
|
11
|
-
conditionalPath?: string
|
|
12
|
-
currenciesConfig: CurrenciesConfig
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export const pricesField: (props: Props) => GroupField[] = ({
|
|
16
|
-
conditionalPath,
|
|
17
|
-
currenciesConfig,
|
|
18
|
-
}) => {
|
|
19
|
-
const currencies = currenciesConfig.supportedCurrencies
|
|
20
|
-
|
|
21
|
-
const fields: GroupField[] = currencies.map((currency) => {
|
|
22
|
-
const name = `priceIn${currency.code}`
|
|
23
|
-
const label = `Price (${currency.code})`
|
|
24
|
-
|
|
25
|
-
const path = conditionalPath ? `${conditionalPath}.${name}Enabled` : `${name}Enabled`
|
|
26
|
-
|
|
27
|
-
return {
|
|
28
|
-
type: 'group',
|
|
29
|
-
fields: [
|
|
30
|
-
{
|
|
31
|
-
type: 'row',
|
|
32
|
-
fields: [
|
|
33
|
-
{
|
|
34
|
-
name: `${name}Enabled`,
|
|
35
|
-
type: 'checkbox',
|
|
36
|
-
admin: {
|
|
37
|
-
style: {
|
|
38
|
-
alignSelf: 'baseline',
|
|
39
|
-
flex: '0 0 auto',
|
|
40
|
-
},
|
|
41
|
-
},
|
|
42
|
-
label: ({ t }) =>
|
|
43
|
-
// @ts-expect-error - translations are not typed in plugins yet
|
|
44
|
-
t('plugin-ecommerce:enableCurrencyPrice', { currency: currency.code }),
|
|
45
|
-
},
|
|
46
|
-
amountField({
|
|
47
|
-
currenciesConfig,
|
|
48
|
-
currency,
|
|
49
|
-
overrides: {
|
|
50
|
-
name,
|
|
51
|
-
admin: {
|
|
52
|
-
condition: (_, siblingData) => Boolean(siblingData?.[path]),
|
|
53
|
-
},
|
|
54
|
-
// @ts-expect-error - translations are not typed in plugins yet
|
|
55
|
-
label: ({ t }) => t('plugin-ecommerce:priceIn', { currency: currency.code }),
|
|
56
|
-
},
|
|
57
|
-
}),
|
|
58
|
-
],
|
|
59
|
-
},
|
|
60
|
-
],
|
|
61
|
-
}
|
|
62
|
-
})
|
|
63
|
-
|
|
64
|
-
return fields
|
|
65
|
-
}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import type { SelectField } from 'payload'
|
|
2
|
-
|
|
3
|
-
export const statusOptions: SelectField['options'] = [
|
|
4
|
-
{
|
|
5
|
-
// @ts-expect-error - translations are not typed in plugins yet
|
|
6
|
-
label: ({ t }) => t('plugin-ecommerce:pending'),
|
|
7
|
-
value: 'pending',
|
|
8
|
-
},
|
|
9
|
-
{
|
|
10
|
-
// @ts-expect-error - translations are not typed in plugins yet
|
|
11
|
-
label: ({ t }) => t('plugin-ecommerce:succeeded'),
|
|
12
|
-
value: 'succeeded',
|
|
13
|
-
},
|
|
14
|
-
{
|
|
15
|
-
// @ts-expect-error - translations are not typed in plugins yet
|
|
16
|
-
label: ({ t }) => t('plugin-ecommerce:failed'),
|
|
17
|
-
value: 'failed',
|
|
18
|
-
},
|
|
19
|
-
{
|
|
20
|
-
// @ts-expect-error - translations are not typed in plugins yet
|
|
21
|
-
label: ({ t }) => t('plugin-ecommerce:cancelled'),
|
|
22
|
-
value: 'cancelled',
|
|
23
|
-
},
|
|
24
|
-
{
|
|
25
|
-
// @ts-expect-error - translations are not typed in plugins yet
|
|
26
|
-
label: ({ t }) => t('plugin-ecommerce:expired'),
|
|
27
|
-
value: 'expired',
|
|
28
|
-
},
|
|
29
|
-
{
|
|
30
|
-
// @ts-expect-error - translations are not typed in plugins yet
|
|
31
|
-
label: ({ t }) => t('plugin-ecommerce:refunded'),
|
|
32
|
-
value: 'refunded',
|
|
33
|
-
},
|
|
34
|
-
]
|
|
35
|
-
|
|
36
|
-
type Props = {
|
|
37
|
-
overrides?: Partial<SelectField>
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export const statusField: (props?: Props) => SelectField = (props) => {
|
|
41
|
-
const { overrides } = props || {}
|
|
42
|
-
|
|
43
|
-
// @ts-expect-error - issue with payload types
|
|
44
|
-
const field: SelectField = {
|
|
45
|
-
name: 'status',
|
|
46
|
-
type: 'select',
|
|
47
|
-
defaultValue: 'pending',
|
|
48
|
-
label: ({ t }) =>
|
|
49
|
-
// @ts-expect-error - translations are not typed in plugins yet
|
|
50
|
-
t('plugin-ecommerce:status'),
|
|
51
|
-
options: statusOptions,
|
|
52
|
-
required: true,
|
|
53
|
-
...overrides,
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
return field
|
|
57
|
-
}
|