@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.
Files changed (89) hide show
  1. package/dist/handleDelete.d.ts +8 -0
  2. package/dist/handleDelete.d.ts.map +1 -0
  3. package/dist/handleDelete.js +8 -0
  4. package/dist/handleDelete.js.map +1 -0
  5. package/dist/handleUpload.d.ts +11 -0
  6. package/dist/handleUpload.d.ts.map +1 -0
  7. package/dist/handleUpload.js +13 -0
  8. package/dist/handleUpload.js.map +1 -0
  9. package/dist/index.d.ts +15 -0
  10. package/dist/index.d.ts.map +1 -0
  11. package/dist/index.js +59 -0
  12. package/dist/index.js.map +1 -0
  13. package/dist/staticHandler.d.ts +11 -0
  14. package/dist/staticHandler.d.ts.map +1 -0
  15. package/dist/staticHandler.js +29 -0
  16. package/dist/staticHandler.js.map +1 -0
  17. package/dist/types.d.ts +16 -0
  18. package/dist/types.d.ts.map +1 -0
  19. package/dist/types.js +3 -0
  20. package/dist/types.js.map +1 -0
  21. package/package.json +57 -1
  22. package/.prettierignore +0 -12
  23. package/.swcrc +0 -24
  24. package/README.md +0 -3
  25. package/eslint.config.js +0 -18
  26. package/src/addresses/addressesCollection.ts +0 -76
  27. package/src/addresses/defaultAddressFields.ts +0 -83
  28. package/src/addresses/defaultCountries.ts +0 -50
  29. package/src/carts/beforeChange.ts +0 -51
  30. package/src/carts/cartsCollection.ts +0 -146
  31. package/src/currencies/index.ts +0 -29
  32. package/src/endpoints/confirmOrder.ts +0 -312
  33. package/src/endpoints/initiatePayment.ts +0 -322
  34. package/src/exports/addresses.ts +0 -2
  35. package/src/exports/currencies.ts +0 -1
  36. package/src/exports/fields.ts +0 -5
  37. package/src/exports/orders.ts +0 -1
  38. package/src/exports/payments/stripe.ts +0 -1
  39. package/src/exports/plugin.ts +0 -1
  40. package/src/exports/products.ts +0 -1
  41. package/src/exports/react.ts +0 -8
  42. package/src/exports/transactions.ts +0 -1
  43. package/src/exports/translations.ts +0 -1
  44. package/src/exports/types.ts +0 -7
  45. package/src/exports/ui.ts +0 -3
  46. package/src/exports/variants.ts +0 -5
  47. package/src/fields/amountField.ts +0 -43
  48. package/src/fields/cartItemsField.ts +0 -84
  49. package/src/fields/currencyField.ts +0 -39
  50. package/src/fields/inventoryField.ts +0 -22
  51. package/src/fields/pricesField.ts +0 -65
  52. package/src/fields/statusField.ts +0 -57
  53. package/src/fields/variantsFields.ts +0 -56
  54. package/src/index.ts +0 -275
  55. package/src/orders/ordersCollection.ts +0 -157
  56. package/src/payments/adapters/stripe/confirmOrder.ts +0 -123
  57. package/src/payments/adapters/stripe/endpoints/webhooks.ts +0 -69
  58. package/src/payments/adapters/stripe/index.ts +0 -135
  59. package/src/payments/adapters/stripe/initiatePayment.ts +0 -131
  60. package/src/products/productsCollection.ts +0 -78
  61. package/src/react/provider/index.tsx +0 -893
  62. package/src/react/provider/types.ts +0 -184
  63. package/src/react/provider/utilities.ts +0 -22
  64. package/src/transactions/transactionsCollection.ts +0 -166
  65. package/src/translations/en.ts +0 -64
  66. package/src/translations/index.ts +0 -11
  67. package/src/translations/translation-schema.json +0 -35
  68. package/src/types.ts +0 -403
  69. package/src/ui/PriceInput/FormattedInput.tsx +0 -134
  70. package/src/ui/PriceInput/index.scss +0 -28
  71. package/src/ui/PriceInput/index.tsx +0 -43
  72. package/src/ui/PriceInput/utilities.ts +0 -46
  73. package/src/ui/PriceRowLabel/index.css +0 -13
  74. package/src/ui/PriceRowLabel/index.tsx +0 -56
  75. package/src/ui/VariantOptionsSelector/ErrorBox.tsx +0 -27
  76. package/src/ui/VariantOptionsSelector/OptionsSelect.tsx +0 -78
  77. package/src/ui/VariantOptionsSelector/index.css +0 -37
  78. package/src/ui/VariantOptionsSelector/index.tsx +0 -83
  79. package/src/utilities/defaultProductsValidation.ts +0 -42
  80. package/src/utilities/errorCodes.ts +0 -14
  81. package/src/utilities/getCollectionSlugMap.ts +0 -84
  82. package/src/utilities/sanitizePluginConfig.ts +0 -80
  83. package/src/variants/variantOptionsCollection.ts +0 -59
  84. package/src/variants/variantTypesCollection.ts +0 -55
  85. package/src/variants/variantsCollection/hooks/beforeChange.ts +0 -47
  86. package/src/variants/variantsCollection/hooks/validateOptions.ts +0 -72
  87. package/src/variants/variantsCollection/index.ts +0 -119
  88. package/tsconfig.json +0 -7
  89. package/tsconfig.tsbuildinfo +0 -1
@@ -1,135 +0,0 @@
1
- import type { Field, GroupField, PayloadRequest } from 'payload'
2
- import type { Stripe } from 'stripe'
3
-
4
- import type {
5
- BasePaymentAdapterArgs,
6
- BasePaymentAdapterClientArgs,
7
- PaymentAdapter,
8
- PaymentAdapterClient,
9
- } from '../../../types.js'
10
-
11
- import { confirmOrder } from './confirmOrder.js'
12
- import { webhooksEndpoint } from './endpoints/webhooks.js'
13
- import { initiatePayment } from './initiatePayment.js'
14
-
15
- type StripeWebhookHandler = (args: {
16
- event: Stripe.Event
17
- req: PayloadRequest
18
- stripe: Stripe
19
- }) => Promise<void> | void
20
-
21
- type StripeWebhookHandlers = {
22
- /**
23
- * Description of the event (e.g., invoice.created or charge.refunded).
24
- */
25
- [webhookName: string]: StripeWebhookHandler
26
- }
27
-
28
- export type StripeAdapterArgs = {
29
- /**
30
- * This library's types only reflect the latest API version.
31
- *
32
- * We recommend upgrading your account's API Version to the latest version
33
- * if you wish to use TypeScript with this library.
34
- *
35
- * If you wish to remain on your account's default API version,
36
- * you may pass `null` or another version instead of the latest version,
37
- * and add a `@ts-ignore` comment here and anywhere the types differ between API versions.
38
- *
39
- * @docs https://stripe.com/docs/api/versioning
40
- */
41
- apiVersion?: Stripe.StripeConfig['apiVersion']
42
- appInfo?: Stripe.StripeConfig['appInfo']
43
- publishableKey: string
44
- secretKey: string
45
- webhooks?: StripeWebhookHandlers
46
- webhookSecret: string
47
- } & BasePaymentAdapterArgs
48
-
49
- export const stripeAdapter: (props: StripeAdapterArgs) => PaymentAdapter = (props) => {
50
- const { apiVersion, appInfo, groupOverrides, secretKey, webhooks, webhookSecret } = props
51
- const label = props?.label || 'Stripe'
52
-
53
- const baseFields: Field[] = [
54
- {
55
- name: 'customerID',
56
- type: 'text',
57
- label: 'Stripe Customer ID',
58
- },
59
- {
60
- name: 'paymentIntentID',
61
- type: 'text',
62
- label: 'Stripe PaymentIntent ID',
63
- },
64
- ]
65
-
66
- const groupField: GroupField = {
67
- name: 'stripe',
68
- type: 'group',
69
- ...groupOverrides,
70
- admin: {
71
- condition: (data) => {
72
- const path = 'paymentMethod'
73
-
74
- return data?.[path] === 'stripe'
75
- },
76
- ...groupOverrides?.admin,
77
- },
78
- fields:
79
- groupOverrides?.fields && typeof groupOverrides?.fields === 'function'
80
- ? groupOverrides.fields({ defaultFields: baseFields })
81
- : baseFields,
82
- }
83
-
84
- return {
85
- name: 'stripe',
86
- confirmOrder: confirmOrder({
87
- apiVersion,
88
- appInfo,
89
- secretKey,
90
- }),
91
- endpoints: [webhooksEndpoint({ apiVersion, appInfo, secretKey, webhooks, webhookSecret })],
92
- group: groupField,
93
- initiatePayment: initiatePayment({
94
- apiVersion,
95
- appInfo,
96
- secretKey,
97
- }),
98
- label,
99
- }
100
- }
101
-
102
- export type StripeAdapterClientArgs = {
103
- /**
104
- * This library's types only reflect the latest API version.
105
- *
106
- * We recommend upgrading your account's API Version to the latest version
107
- * if you wish to use TypeScript with this library.
108
- *
109
- * If you wish to remain on your account's default API version,
110
- * you may pass `null` or another version instead of the latest version,
111
- * and add a `@ts-ignore` comment here and anywhere the types differ between API versions.
112
- *
113
- * @docs https://stripe.com/docs/api/versioning
114
- */
115
- apiVersion?: Stripe.StripeConfig['apiVersion']
116
- appInfo?: Stripe.StripeConfig['appInfo']
117
- publishableKey: string
118
- } & BasePaymentAdapterClientArgs
119
-
120
- export const stripeAdapterClient: (props: StripeAdapterClientArgs) => PaymentAdapterClient = (
121
- props,
122
- ) => {
123
- return {
124
- name: 'stripe',
125
- confirmOrder: true,
126
- initiatePayment: true,
127
- label: 'Card',
128
- }
129
- }
130
-
131
- export type InitiatePaymentReturnType = {
132
- clientSecret: string
133
- message: string
134
- paymentIntentID: string
135
- }
@@ -1,131 +0,0 @@
1
- import Stripe from 'stripe'
2
-
3
- import type { PaymentAdapter } from '../../../types.js'
4
- import type { InitiatePaymentReturnType, StripeAdapterArgs } from './index.js'
5
-
6
- type Props = {
7
- apiVersion?: Stripe.StripeConfig['apiVersion']
8
- appInfo?: Stripe.StripeConfig['appInfo']
9
- secretKey: StripeAdapterArgs['secretKey']
10
- }
11
-
12
- export const initiatePayment: (props: Props) => NonNullable<PaymentAdapter>['initiatePayment'] =
13
- (props) =>
14
- async ({ data, req, transactionsSlug }) => {
15
- const payload = req.payload
16
- const { apiVersion, appInfo, secretKey } = props || {}
17
-
18
- const customerEmail = data.customerEmail
19
- const currency = data.currency
20
- const cart = data.cart
21
- const amount = cart.subtotal
22
- const billingAddressFromData = data.billingAddress
23
- const shippingAddressFromData = data.shippingAddress
24
-
25
- if (!secretKey) {
26
- throw new Error('Stripe secret key is required.')
27
- }
28
-
29
- if (!currency) {
30
- throw new Error('Currency is required.')
31
- }
32
-
33
- if (!cart || !cart.items || cart.items.length === 0) {
34
- throw new Error('Cart is empty or not provided.')
35
- }
36
-
37
- if (!customerEmail || typeof customerEmail !== 'string') {
38
- throw new Error('A valid customer email is required to make a purchase.')
39
- }
40
-
41
- if (!amount || typeof amount !== 'number' || amount <= 0) {
42
- throw new Error('A valid amount is required to initiate a payment.')
43
- }
44
-
45
- const stripe = new Stripe(secretKey, {
46
- // API version can only be the latest, stripe recommends ts ignoring it
47
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
48
- // @ts-ignore - ignoring since possible versions are not type safe, only the latest version is recognised
49
- apiVersion: apiVersion || '2025-06-30.preview',
50
- appInfo: appInfo || {
51
- name: 'Stripe Payload Plugin',
52
- url: 'https://payloadcms.com',
53
- },
54
- })
55
-
56
- try {
57
- let customer = (
58
- await stripe.customers.list({
59
- email: customerEmail,
60
- })
61
- ).data[0]
62
-
63
- if (!customer?.id) {
64
- customer = await stripe.customers.create({
65
- email: customerEmail,
66
- })
67
- }
68
-
69
- const flattenedCart = cart.items.map((item) => {
70
- const productID = typeof item.product === 'object' ? item.product.id : item.product
71
- const variantID = item.variant
72
- ? typeof item.variant === 'object'
73
- ? item.variant.id
74
- : item.variant
75
- : undefined
76
-
77
- return {
78
- product: productID,
79
- quantity: item.quantity,
80
- variant: variantID,
81
- }
82
- })
83
-
84
- const shippingAddressAsString = JSON.stringify(shippingAddressFromData)
85
-
86
- const paymentIntent = await stripe.paymentIntents.create({
87
- amount,
88
- automatic_payment_methods: {
89
- enabled: true,
90
- },
91
- currency,
92
- customer: customer.id,
93
- metadata: {
94
- cartID: cart.id,
95
- cartItemsSnapshot: JSON.stringify(flattenedCart),
96
- shippingAddress: shippingAddressAsString,
97
- },
98
- })
99
-
100
- // Create a transaction for the payment intent in the database
101
- const transaction = await payload.create({
102
- collection: transactionsSlug,
103
- data: {
104
- ...(req.user ? { customer: req.user.id } : { customerEmail }),
105
- amount: paymentIntent.amount,
106
- billingAddress: billingAddressFromData,
107
- cart: cart.id,
108
- currency: paymentIntent.currency.toUpperCase(),
109
- items: flattenedCart,
110
- paymentMethod: 'stripe',
111
- status: 'pending',
112
- stripe: {
113
- customerID: customer.id,
114
- paymentIntentID: paymentIntent.id,
115
- },
116
- },
117
- })
118
-
119
- const returnData: InitiatePaymentReturnType = {
120
- clientSecret: paymentIntent.client_secret || '',
121
- message: 'Payment initiated successfully',
122
- paymentIntentID: paymentIntent.id,
123
- }
124
-
125
- return returnData
126
- } catch (error) {
127
- payload.logger.error(error, 'Error initiating payment with Stripe')
128
-
129
- throw new Error(error instanceof Error ? error.message : 'Unknown error initiating payment')
130
- }
131
- }
@@ -1,78 +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 { variantsFields } from '../fields/variantsFields.js'
8
-
9
- type Props = {
10
- currenciesConfig: CurrenciesConfig
11
- enableVariants?: boolean
12
- /**
13
- * Adds in an inventory field to the product and its variants. This is useful for tracking inventory levels.
14
- * Defaults to true.
15
- */
16
- inventory?: boolean | InventoryConfig
17
- overrides?: { fields?: FieldsOverride } & Partial<Omit<CollectionConfig, 'fields'>>
18
- /**
19
- * Slug of the variants collection, defaults to 'variants'.
20
- */
21
- variantsSlug?: string
22
- /**
23
- * Slug of the variant types collection, defaults to 'variantTypes'.
24
- */
25
- variantTypesSlug?: string
26
- }
27
-
28
- export const productsCollection: (props: Props) => CollectionConfig = (props) => {
29
- const {
30
- currenciesConfig,
31
- enableVariants = false,
32
- inventory = true,
33
- overrides,
34
- variantsSlug = 'variants',
35
- variantTypesSlug = 'variantTypes',
36
- } = props || {}
37
- const fieldsOverride = overrides?.fields
38
-
39
- const defaultFields: Field[] = [
40
- ...(inventory
41
- ? [
42
- inventoryField({
43
- overrides: {
44
- admin: {
45
- condition: ({ enableVariants }) => !enableVariants,
46
- },
47
- },
48
- }),
49
- ]
50
- : []),
51
- ]
52
-
53
- const baseFields = [
54
- ...defaultFields,
55
- ...(enableVariants ? variantsFields({ variantsSlug, variantTypesSlug }) : []),
56
- ...(currenciesConfig ? [...pricesField({ currenciesConfig })] : []),
57
- ]
58
-
59
- const fields =
60
- fieldsOverride && typeof fieldsOverride === 'function'
61
- ? fieldsOverride({ defaultFields: baseFields })
62
- : baseFields
63
-
64
- const baseConfig: CollectionConfig = {
65
- slug: 'products',
66
- ...overrides,
67
- admin: {
68
- defaultColumns: [
69
- ...(currenciesConfig ? ['prices'] : []),
70
- ...(enableVariants ? ['variants'] : []),
71
- ],
72
- ...overrides?.admin,
73
- },
74
- fields,
75
- }
76
-
77
- return { ...baseConfig }
78
- }