@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
@@ -0,0 +1,8 @@
1
+ import type { HandleDelete } from '@payloadcms/plugin-cloud-storage/types';
2
+ import type { R2Bucket } from './types.js';
3
+ interface Args {
4
+ bucket: R2Bucket;
5
+ }
6
+ export declare const getHandleDelete: ({ bucket }: Args) => HandleDelete;
7
+ export {};
8
+ //# sourceMappingURL=handleDelete.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handleDelete.d.ts","sourceRoot":"","sources":["../src/handleDelete.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wCAAwC,CAAA;AAI1E,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAE1C,UAAU,IAAI;IACZ,MAAM,EAAE,QAAQ,CAAA;CACjB;AAED,eAAO,MAAM,eAAe,eAAgB,IAAI,KAAG,YAIlD,CAAA"}
@@ -0,0 +1,8 @@
1
+ import path from 'path';
2
+ export const getHandleDelete = ({ bucket })=>{
3
+ return async ({ doc: { prefix = '' }, filename })=>{
4
+ await bucket.delete(path.posix.join(prefix, filename));
5
+ };
6
+ };
7
+
8
+ //# sourceMappingURL=handleDelete.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/handleDelete.ts"],"sourcesContent":["import type { HandleDelete } from '@payloadcms/plugin-cloud-storage/types'\n\nimport path from 'path'\n\nimport type { R2Bucket } from './types.js'\n\ninterface Args {\n bucket: R2Bucket\n}\n\nexport const getHandleDelete = ({ bucket }: Args): HandleDelete => {\n return async ({ doc: { prefix = '' }, filename }) => {\n await bucket.delete(path.posix.join(prefix, filename))\n }\n}\n"],"names":["path","getHandleDelete","bucket","doc","prefix","filename","delete","posix","join"],"mappings":"AAEA,OAAOA,UAAU,OAAM;AAQvB,OAAO,MAAMC,kBAAkB,CAAC,EAAEC,MAAM,EAAQ;IAC9C,OAAO,OAAO,EAAEC,KAAK,EAAEC,SAAS,EAAE,EAAE,EAAEC,QAAQ,EAAE;QAC9C,MAAMH,OAAOI,MAAM,CAACN,KAAKO,KAAK,CAACC,IAAI,CAACJ,QAAQC;IAC9C;AACF,EAAC"}
@@ -0,0 +1,11 @@
1
+ import type { HandleUpload } from '@payloadcms/plugin-cloud-storage/types';
2
+ import type { CollectionConfig } from 'payload';
3
+ import type { R2Bucket } from './types.js';
4
+ interface Args {
5
+ bucket: R2Bucket;
6
+ collection: CollectionConfig;
7
+ prefix?: string;
8
+ }
9
+ export declare const getHandleUpload: ({ bucket, prefix }: Args) => HandleUpload;
10
+ export {};
11
+ //# sourceMappingURL=handleUpload.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handleUpload.d.ts","sourceRoot":"","sources":["../src/handleUpload.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wCAAwC,CAAA;AAC1E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAI/C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAE1C,UAAU,IAAI;IACZ,MAAM,EAAE,QAAQ,CAAA;IAChB,UAAU,EAAE,gBAAgB,CAAA;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED,eAAO,MAAM,eAAe,uBAA6B,IAAI,KAAG,YAO/D,CAAA"}
@@ -0,0 +1,13 @@
1
+ import path from 'path';
2
+ export const getHandleUpload = ({ bucket, prefix = '' })=>{
3
+ return async ({ data, file })=>{
4
+ // Read more: https://github.com/cloudflare/workers-sdk/issues/6047#issuecomment-2691217843
5
+ const buffer = process.env.NODE_ENV === 'development' ? new Blob([
6
+ file.buffer
7
+ ]) : file.buffer;
8
+ await bucket.put(path.posix.join(prefix, file.filename), buffer);
9
+ return data;
10
+ };
11
+ };
12
+
13
+ //# sourceMappingURL=handleUpload.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/handleUpload.ts"],"sourcesContent":["import type { HandleUpload } from '@payloadcms/plugin-cloud-storage/types'\nimport type { CollectionConfig } from 'payload'\n\nimport path from 'path'\n\nimport type { R2Bucket } from './types.js'\n\ninterface Args {\n bucket: R2Bucket\n collection: CollectionConfig\n prefix?: string\n}\n\nexport const getHandleUpload = ({ bucket, prefix = '' }: Args): HandleUpload => {\n return async ({ data, file }) => {\n // Read more: https://github.com/cloudflare/workers-sdk/issues/6047#issuecomment-2691217843\n const buffer = process.env.NODE_ENV === 'development' ? new Blob([file.buffer]) : file.buffer\n await bucket.put(path.posix.join(prefix, file.filename), buffer)\n return data\n }\n}\n"],"names":["path","getHandleUpload","bucket","prefix","data","file","buffer","process","env","NODE_ENV","Blob","put","posix","join","filename"],"mappings":"AAGA,OAAOA,UAAU,OAAM;AAUvB,OAAO,MAAMC,kBAAkB,CAAC,EAAEC,MAAM,EAAEC,SAAS,EAAE,EAAQ;IAC3D,OAAO,OAAO,EAAEC,IAAI,EAAEC,IAAI,EAAE;QAC1B,2FAA2F;QAC3F,MAAMC,SAASC,QAAQC,GAAG,CAACC,QAAQ,KAAK,gBAAgB,IAAIC,KAAK;YAACL,KAAKC,MAAM;SAAC,IAAID,KAAKC,MAAM;QAC7F,MAAMJ,OAAOS,GAAG,CAACX,KAAKY,KAAK,CAACC,IAAI,CAACV,QAAQE,KAAKS,QAAQ,GAAGR;QACzD,OAAOF;IACT;AACF,EAAC"}
@@ -0,0 +1,15 @@
1
+ import type { CollectionOptions } from '@payloadcms/plugin-cloud-storage/types';
2
+ import type { Plugin, UploadCollectionSlug } from 'payload';
3
+ import type { R2Bucket } from './types.js';
4
+ export interface R2StorageOptions {
5
+ bucket: R2Bucket;
6
+ /**
7
+ * Collection options to apply the R2 adapter to.
8
+ */
9
+ collections: Partial<Record<UploadCollectionSlug, Omit<CollectionOptions, 'adapter'> | true>>;
10
+ enabled?: boolean;
11
+ }
12
+ type R2StoragePlugin = (r2StorageArgs: R2StorageOptions) => Plugin;
13
+ export declare const r2Storage: R2StoragePlugin;
14
+ export {};
15
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,iBAAiB,EAElB,MAAM,wCAAwC,CAAA;AAC/C,OAAO,KAAK,EAAU,MAAM,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAA;AAInE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAM1C,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,QAAQ,CAAA;IAChB;;OAEG;IACH,WAAW,EAAE,OAAO,CAAC,MAAM,CAAC,oBAAoB,EAAE,IAAI,CAAC,iBAAiB,EAAE,SAAS,CAAC,GAAG,IAAI,CAAC,CAAC,CAAA;IAC7F,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAED,KAAK,eAAe,GAAG,CAAC,aAAa,EAAE,gBAAgB,KAAK,MAAM,CAAA;AAElE,eAAO,MAAM,SAAS,EAAE,eA8CrB,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,59 @@
1
+ import { cloudStoragePlugin } from '@payloadcms/plugin-cloud-storage';
2
+ import { getHandleDelete } from './handleDelete.js';
3
+ import { getHandleUpload } from './handleUpload.js';
4
+ import { getHandler } from './staticHandler.js';
5
+ export const r2Storage = (r2StorageOptions)=>(incomingConfig)=>{
6
+ const adapter = r2StorageInternal(r2StorageOptions);
7
+ const isPluginDisabled = r2StorageOptions.enabled === false;
8
+ if (isPluginDisabled) {
9
+ return incomingConfig;
10
+ }
11
+ // Add adapter to each collection option object
12
+ const collectionsWithAdapter = Object.entries(r2StorageOptions.collections).reduce((acc, [slug, collOptions])=>({
13
+ ...acc,
14
+ [slug]: {
15
+ ...collOptions === true ? {} : collOptions,
16
+ adapter
17
+ }
18
+ }), {});
19
+ // Set disableLocalStorage: true for collections specified in the plugin options
20
+ const config = {
21
+ ...incomingConfig,
22
+ collections: (incomingConfig.collections || []).map((collection)=>{
23
+ if (!collectionsWithAdapter[collection.slug]) {
24
+ return collection;
25
+ }
26
+ return {
27
+ ...collection,
28
+ upload: {
29
+ ...typeof collection.upload === 'object' ? collection.upload : {},
30
+ disableLocalStorage: true
31
+ }
32
+ };
33
+ })
34
+ };
35
+ return cloudStoragePlugin({
36
+ collections: collectionsWithAdapter
37
+ })(config);
38
+ };
39
+ function r2StorageInternal({ bucket }) {
40
+ return ({ collection, prefix })=>{
41
+ return {
42
+ name: 'r2',
43
+ handleDelete: getHandleDelete({
44
+ bucket
45
+ }),
46
+ handleUpload: getHandleUpload({
47
+ bucket,
48
+ collection,
49
+ prefix
50
+ }),
51
+ staticHandler: getHandler({
52
+ bucket,
53
+ collection
54
+ })
55
+ };
56
+ };
57
+ }
58
+
59
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type {\n Adapter,\n PluginOptions as CloudStoragePluginOptions,\n CollectionOptions,\n GeneratedAdapter,\n} from '@payloadcms/plugin-cloud-storage/types'\nimport type { Config, Plugin, UploadCollectionSlug } from 'payload'\n\nimport { cloudStoragePlugin } from '@payloadcms/plugin-cloud-storage'\n\nimport type { R2Bucket } from './types.js'\n\nimport { getHandleDelete } from './handleDelete.js'\nimport { getHandleUpload } from './handleUpload.js'\nimport { getHandler } from './staticHandler.js'\n\nexport interface R2StorageOptions {\n bucket: R2Bucket\n /**\n * Collection options to apply the R2 adapter to.\n */\n collections: Partial<Record<UploadCollectionSlug, Omit<CollectionOptions, 'adapter'> | true>>\n enabled?: boolean\n}\n\ntype R2StoragePlugin = (r2StorageArgs: R2StorageOptions) => Plugin\n\nexport const r2Storage: R2StoragePlugin =\n (r2StorageOptions) =>\n (incomingConfig: Config): Config => {\n const adapter = r2StorageInternal(r2StorageOptions)\n\n const isPluginDisabled = r2StorageOptions.enabled === false\n\n if (isPluginDisabled) {\n return incomingConfig\n }\n\n // Add adapter to each collection option object\n const collectionsWithAdapter: CloudStoragePluginOptions['collections'] = Object.entries(\n r2StorageOptions.collections,\n ).reduce(\n (acc, [slug, collOptions]) => ({\n ...acc,\n [slug]: {\n ...(collOptions === true ? {} : collOptions),\n adapter,\n },\n }),\n {} as Record<string, CollectionOptions>,\n )\n\n // Set disableLocalStorage: true for collections specified in the plugin options\n const config = {\n ...incomingConfig,\n collections: (incomingConfig.collections || []).map((collection) => {\n if (!collectionsWithAdapter[collection.slug]) {\n return collection\n }\n\n return {\n ...collection,\n upload: {\n ...(typeof collection.upload === 'object' ? collection.upload : {}),\n disableLocalStorage: true,\n },\n }\n }),\n }\n\n return cloudStoragePlugin({\n collections: collectionsWithAdapter,\n })(config)\n }\n\nfunction r2StorageInternal({ bucket }: R2StorageOptions): Adapter {\n return ({ collection, prefix }): GeneratedAdapter => {\n return {\n name: 'r2',\n handleDelete: getHandleDelete({ bucket }),\n handleUpload: getHandleUpload({\n bucket,\n collection,\n prefix,\n }),\n staticHandler: getHandler({ bucket, collection }),\n }\n }\n}\n"],"names":["cloudStoragePlugin","getHandleDelete","getHandleUpload","getHandler","r2Storage","r2StorageOptions","incomingConfig","adapter","r2StorageInternal","isPluginDisabled","enabled","collectionsWithAdapter","Object","entries","collections","reduce","acc","slug","collOptions","config","map","collection","upload","disableLocalStorage","bucket","prefix","name","handleDelete","handleUpload","staticHandler"],"mappings":"AAQA,SAASA,kBAAkB,QAAQ,mCAAkC;AAIrE,SAASC,eAAe,QAAQ,oBAAmB;AACnD,SAASC,eAAe,QAAQ,oBAAmB;AACnD,SAASC,UAAU,QAAQ,qBAAoB;AAa/C,OAAO,MAAMC,YACX,CAACC,mBACD,CAACC;QACC,MAAMC,UAAUC,kBAAkBH;QAElC,MAAMI,mBAAmBJ,iBAAiBK,OAAO,KAAK;QAEtD,IAAID,kBAAkB;YACpB,OAAOH;QACT;QAEA,+CAA+C;QAC/C,MAAMK,yBAAmEC,OAAOC,OAAO,CACrFR,iBAAiBS,WAAW,EAC5BC,MAAM,CACN,CAACC,KAAK,CAACC,MAAMC,YAAY,GAAM,CAAA;gBAC7B,GAAGF,GAAG;gBACN,CAACC,KAAK,EAAE;oBACN,GAAIC,gBAAgB,OAAO,CAAC,IAAIA,WAAW;oBAC3CX;gBACF;YACF,CAAA,GACA,CAAC;QAGH,gFAAgF;QAChF,MAAMY,SAAS;YACb,GAAGb,cAAc;YACjBQ,aAAa,AAACR,CAAAA,eAAeQ,WAAW,IAAI,EAAE,AAAD,EAAGM,GAAG,CAAC,CAACC;gBACnD,IAAI,CAACV,sBAAsB,CAACU,WAAWJ,IAAI,CAAC,EAAE;oBAC5C,OAAOI;gBACT;gBAEA,OAAO;oBACL,GAAGA,UAAU;oBACbC,QAAQ;wBACN,GAAI,OAAOD,WAAWC,MAAM,KAAK,WAAWD,WAAWC,MAAM,GAAG,CAAC,CAAC;wBAClEC,qBAAqB;oBACvB;gBACF;YACF;QACF;QAEA,OAAOvB,mBAAmB;YACxBc,aAAaH;QACf,GAAGQ;IACL,EAAC;AAEH,SAASX,kBAAkB,EAAEgB,MAAM,EAAoB;IACrD,OAAO,CAAC,EAAEH,UAAU,EAAEI,MAAM,EAAE;QAC5B,OAAO;YACLC,MAAM;YACNC,cAAc1B,gBAAgB;gBAAEuB;YAAO;YACvCI,cAAc1B,gBAAgB;gBAC5BsB;gBACAH;gBACAI;YACF;YACAI,eAAe1B,WAAW;gBAAEqB;gBAAQH;YAAW;QACjD;IACF;AACF"}
@@ -0,0 +1,11 @@
1
+ import type { StaticHandler } from '@payloadcms/plugin-cloud-storage/types';
2
+ import type { CollectionConfig } from 'payload';
3
+ import type { R2Bucket } from './types.js';
4
+ interface Args {
5
+ bucket: R2Bucket;
6
+ collection: CollectionConfig;
7
+ prefix?: string;
8
+ }
9
+ export declare const getHandler: ({ bucket, prefix }: Args) => StaticHandler;
10
+ export {};
11
+ //# sourceMappingURL=staticHandler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"staticHandler.d.ts","sourceRoot":"","sources":["../src/staticHandler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wCAAwC,CAAA;AAC3E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAI/C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAE1C,UAAU,IAAI;IACZ,MAAM,EAAE,QAAQ,CAAA;IAChB,UAAU,EAAE,gBAAgB,CAAA;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAID,eAAO,MAAM,UAAU,uBAA6B,IAAI,KAAG,aAoB1D,CAAA"}
@@ -0,0 +1,29 @@
1
+ import path from 'path';
2
+ const isMiniflare = process.env.NODE_ENV === 'development';
3
+ export const getHandler = ({ bucket, prefix = '' })=>{
4
+ return async (req, { params: { filename } })=>{
5
+ // Due to https://github.com/cloudflare/workers-sdk/issues/6047
6
+ // We cannot send a Headers instance to Miniflare
7
+ const obj = await bucket?.get(path.posix.join(prefix, filename), {
8
+ range: isMiniflare ? undefined : req.headers
9
+ });
10
+ if (obj?.body == undefined) {
11
+ return new Response(null, {
12
+ status: 404
13
+ });
14
+ }
15
+ const headers = new Headers();
16
+ if (!isMiniflare) {
17
+ obj.writeHttpMetadata(headers);
18
+ }
19
+ return obj.etag === (req.headers.get('etag') || req.headers.get('if-none-match')) ? new Response(null, {
20
+ headers,
21
+ status: 304
22
+ }) : new Response(obj.body, {
23
+ headers,
24
+ status: 200
25
+ });
26
+ };
27
+ };
28
+
29
+ //# sourceMappingURL=staticHandler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/staticHandler.ts"],"sourcesContent":["import type { StaticHandler } from '@payloadcms/plugin-cloud-storage/types'\nimport type { CollectionConfig } from 'payload'\n\nimport path from 'path'\n\nimport type { R2Bucket } from './types.js'\n\ninterface Args {\n bucket: R2Bucket\n collection: CollectionConfig\n prefix?: string\n}\n\nconst isMiniflare = process.env.NODE_ENV === 'development'\n\nexport const getHandler = ({ bucket, prefix = '' }: Args): StaticHandler => {\n return async (req, { params: { filename } }) => {\n // Due to https://github.com/cloudflare/workers-sdk/issues/6047\n // We cannot send a Headers instance to Miniflare\n const obj = await bucket?.get(path.posix.join(prefix, filename), {\n range: isMiniflare ? undefined : req.headers,\n })\n if (obj?.body == undefined) {\n return new Response(null, { status: 404 })\n }\n\n const headers = new Headers()\n if (!isMiniflare) {\n obj.writeHttpMetadata(headers)\n }\n\n return obj.etag === (req.headers.get('etag') || req.headers.get('if-none-match'))\n ? new Response(null, { headers, status: 304 })\n : new Response(obj.body, { headers, status: 200 })\n }\n}\n"],"names":["path","isMiniflare","process","env","NODE_ENV","getHandler","bucket","prefix","req","params","filename","obj","get","posix","join","range","undefined","headers","body","Response","status","Headers","writeHttpMetadata","etag"],"mappings":"AAGA,OAAOA,UAAU,OAAM;AAUvB,MAAMC,cAAcC,QAAQC,GAAG,CAACC,QAAQ,KAAK;AAE7C,OAAO,MAAMC,aAAa,CAAC,EAAEC,MAAM,EAAEC,SAAS,EAAE,EAAQ;IACtD,OAAO,OAAOC,KAAK,EAAEC,QAAQ,EAAEC,QAAQ,EAAE,EAAE;QACzC,+DAA+D;QAC/D,iDAAiD;QACjD,MAAMC,MAAM,MAAML,QAAQM,IAAIZ,KAAKa,KAAK,CAACC,IAAI,CAACP,QAAQG,WAAW;YAC/DK,OAAOd,cAAce,YAAYR,IAAIS,OAAO;QAC9C;QACA,IAAIN,KAAKO,QAAQF,WAAW;YAC1B,OAAO,IAAIG,SAAS,MAAM;gBAAEC,QAAQ;YAAI;QAC1C;QAEA,MAAMH,UAAU,IAAII;QACpB,IAAI,CAACpB,aAAa;YAChBU,IAAIW,iBAAiB,CAACL;QACxB;QAEA,OAAON,IAAIY,IAAI,KAAMf,CAAAA,IAAIS,OAAO,CAACL,GAAG,CAAC,WAAWJ,IAAIS,OAAO,CAACL,GAAG,CAAC,gBAAe,IAC3E,IAAIO,SAAS,MAAM;YAAEF;YAASG,QAAQ;QAAI,KAC1C,IAAID,SAASR,IAAIO,IAAI,EAAE;YAAED;YAASG,QAAQ;QAAI;IACpD;AACF,EAAC"}
@@ -0,0 +1,16 @@
1
+ export interface R2Bucket {
2
+ createMultipartUpload(key: string, options?: any): Promise<any>;
3
+ delete(keys: string | string[]): Promise<void>;
4
+ get(key: string, options: {
5
+ onlyIf: any | Headers;
6
+ } & any): Promise<any | null>;
7
+ get(key: string, options?: any): Promise<any | null>;
8
+ head(key: string): Promise<any>;
9
+ list(options?: any): Promise<any>;
10
+ put(key: string, value: ArrayBuffer | ArrayBufferView | Blob | null | ReadableStream | string, options?: {
11
+ onlyIf: any;
12
+ } & any): Promise<any | null>;
13
+ put(key: string, value: ArrayBuffer | ArrayBufferView | Blob | null | ReadableStream | string, options?: any): Promise<any>;
14
+ resumeMultipartUpload(key: string, uploadId: string): any;
15
+ }
16
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,QAAQ;IACvB,qBAAqB,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,CAAA;IAC/D,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAC9C,GAAG,CACD,GAAG,EAAE,MAAM,EACX,OAAO,EAAE;QACP,MAAM,EAAE,GAAG,GAAG,OAAO,CAAA;KACtB,GAAG,GAAG,GACN,OAAO,CAAC,GAAG,GAAG,IAAI,CAAC,CAAA;IACtB,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,GAAG,IAAI,CAAC,CAAA;IACpD,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,CAAA;IAC/B,IAAI,CAAC,OAAO,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,CAAA;IACjC,GAAG,CACD,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,WAAW,GAAG,eAAe,GAAG,IAAI,GAAG,IAAI,GAAG,cAAc,GAAG,MAAM,EAC5E,OAAO,CAAC,EAAE;QACR,MAAM,EAAE,GAAG,CAAA;KACZ,GAAG,GAAG,GACN,OAAO,CAAC,GAAG,GAAG,IAAI,CAAC,CAAA;IACtB,GAAG,CACD,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,WAAW,GAAG,eAAe,GAAG,IAAI,GAAG,IAAI,GAAG,cAAc,GAAG,MAAM,EAC5E,OAAO,CAAC,EAAE,GAAG,GACZ,OAAO,CAAC,GAAG,CAAC,CAAA;IACf,qBAAqB,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,GAAG,CAAA;CAC1D"}
package/dist/types.js ADDED
@@ -0,0 +1,3 @@
1
+ export { };
2
+
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/types.ts"],"sourcesContent":["export interface R2Bucket {\n createMultipartUpload(key: string, options?: any): Promise<any>\n delete(keys: string | string[]): Promise<void>\n get(\n key: string,\n options: {\n onlyIf: any | Headers\n } & any,\n ): Promise<any | null>\n get(key: string, options?: any): Promise<any | null>\n head(key: string): Promise<any>\n list(options?: any): Promise<any>\n put(\n key: string,\n value: ArrayBuffer | ArrayBufferView | Blob | null | ReadableStream | string,\n options?: {\n onlyIf: any\n } & any,\n ): Promise<any | null>\n put(\n key: string,\n value: ArrayBuffer | ArrayBufferView | Blob | null | ReadableStream | string,\n options?: any,\n ): Promise<any>\n resumeMultipartUpload(key: string, uploadId: string): any\n}\n"],"names":[],"mappings":"AAAA,WAyBC"}
package/package.json CHANGED
@@ -1,4 +1,60 @@
1
1
  {
2
2
  "name": "@payloadcms/storage-r2",
3
- "version": "0.0.1-beta.0"
3
+ "version": "3.58.0-internal.8775d75",
4
+ "description": "Payload storage adapter for Cloudflare R2",
5
+ "homepage": "https://payloadcms.com",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/payloadcms/payload.git",
9
+ "directory": "packages/storage-r2"
10
+ },
11
+ "license": "MIT",
12
+ "author": "Payload <dev@payloadcms.com> (https://payloadcms.com)",
13
+ "maintainers": [
14
+ {
15
+ "name": "Payload",
16
+ "email": "info@payloadcms.com",
17
+ "url": "https://payloadcms.com"
18
+ }
19
+ ],
20
+ "sideEffects": false,
21
+ "type": "module",
22
+ "exports": {
23
+ ".": {
24
+ "import": "./dist/index.js",
25
+ "types": "./dist/index.d.ts",
26
+ "default": "./dist/index.js"
27
+ },
28
+ "./client": {
29
+ "import": "./dist/exports/client.js",
30
+ "types": "./dist/exports/client.d.ts",
31
+ "default": "./dist/exports/client.js"
32
+ }
33
+ },
34
+ "main": "./dist/index.js",
35
+ "types": "./dist/index.d.ts",
36
+ "files": [
37
+ "dist"
38
+ ],
39
+ "dependencies": {
40
+ "@payloadcms/plugin-cloud-storage": "3.58.0-internal.8775d75"
41
+ },
42
+ "devDependencies": {
43
+ "payload": "3.58.0-internal.8775d75"
44
+ },
45
+ "peerDependencies": {
46
+ "payload": "3.58.0-internal.8775d75"
47
+ },
48
+ "engines": {
49
+ "node": "^18.20.2 || >=20.9.0"
50
+ },
51
+ "scripts": {
52
+ "build": "pnpm build:types && pnpm build:swc",
53
+ "build:clean": "find . \\( -type d \\( -name build -o -name dist -o -name .cache \\) -o -type f -name tsconfig.tsbuildinfo \\) -exec rm -rf {} + && pnpm build",
54
+ "build:swc": "swc ./src -d ./dist --config-file .swcrc --strip-leading-paths",
55
+ "build:types": "tsc --emitDeclarationOnly --outDir dist",
56
+ "clean": "rimraf -g {dist,*.tsbuildinfo}",
57
+ "lint": "eslint .",
58
+ "lint:fix": "eslint . --fix"
59
+ }
4
60
  }
package/.prettierignore DELETED
@@ -1,12 +0,0 @@
1
- .tmp
2
- **/.git
3
- **/.hg
4
- **/.pnp.*
5
- **/.svn
6
- **/.yarn/**
7
- **/build
8
- **/dist/**
9
- **/node_modules
10
- **/temp
11
- **/docs/**
12
- tsconfig.json
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/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Payload Ecommerce
2
-
3
- A set of utilities... more to come
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
- }
@@ -1,83 +0,0 @@
1
- import type { Field } from 'payload'
2
-
3
- export const defaultAddressFields: () => Field[] = () => {
4
- return [
5
- {
6
- name: 'title',
7
- type: 'text',
8
- label: ({ t }) =>
9
- // @ts-expect-error - translations are not typed in plugins yet
10
- t('plugin-ecommerce:addressTitle'),
11
- },
12
- {
13
- name: 'firstName',
14
- type: 'text',
15
- label: ({ t }) =>
16
- // @ts-expect-error - translations are not typed in plugins yet
17
- t('plugin-ecommerce:addressFirstName'),
18
- },
19
- {
20
- name: 'lastName',
21
- type: 'text',
22
- label: ({ t }) =>
23
- // @ts-expect-error - translations are not typed in plugins yet
24
- t('plugin-ecommerce:addressLastName'),
25
- },
26
- {
27
- name: 'company',
28
- type: 'text',
29
- label: ({ t }) =>
30
- // @ts-expect-error - translations are not typed in plugins yet
31
- t('plugin-ecommerce:addressCompany'),
32
- },
33
- {
34
- name: 'addressLine1',
35
- type: 'text',
36
- label: ({ t }) =>
37
- // @ts-expect-error - translations are not typed in plugins yet
38
- t('plugin-ecommerce:addressLine1'),
39
- },
40
- {
41
- name: 'addressLine2',
42
- type: 'text',
43
- label: ({ t }) =>
44
- // @ts-expect-error - translations are not typed in plugins yet
45
- t('plugin-ecommerce:addressLine2'),
46
- },
47
- {
48
- name: 'city',
49
- type: 'text',
50
- label: ({ t }) =>
51
- // @ts-expect-error - translations are not typed in plugins yet
52
- t('plugin-ecommerce:addressCity'),
53
- },
54
- {
55
- name: 'state',
56
- type: 'text',
57
- label: ({ t }) =>
58
- // @ts-expect-error - translations are not typed in plugins yet
59
- t('plugin-ecommerce:addressState'),
60
- },
61
- {
62
- name: 'postalCode',
63
- type: 'text',
64
- label: ({ t }) =>
65
- // @ts-expect-error - translations are not typed in plugins yet
66
- t('plugin-ecommerce:addressPostalCode'),
67
- },
68
- {
69
- name: 'country',
70
- type: 'text',
71
- label: ({ t }) =>
72
- // @ts-expect-error - translations are not typed in plugins yet
73
- t('plugin-ecommerce:addressCountry'),
74
- },
75
- {
76
- name: 'phone',
77
- type: 'text',
78
- label: ({ t }) =>
79
- // @ts-expect-error - translations are not typed in plugins yet
80
- t('plugin-ecommerce:addressPhone'),
81
- },
82
- ]
83
- }
@@ -1,50 +0,0 @@
1
- import type { CountryType } from '../types.js'
2
-
3
- /**
4
- * Default list of countries supported for forms and payments.
5
- * This can be overriden or reused in other parts of the application.
6
- *
7
- * The label is the human-readable name of the country, and the value is the ISO 3166-1 alpha-2 code.
8
- */
9
- export const defaultCountries: CountryType[] = [
10
- { label: 'United States', value: 'US' },
11
- { label: 'United Kingdom', value: 'GB' },
12
- { label: 'Canada', value: 'CA' },
13
- { label: 'Australia', value: 'AU' },
14
- { label: 'Austria', value: 'AT' },
15
- { label: 'Belgium', value: 'BE' },
16
- { label: 'Brazil', value: 'BR' },
17
- { label: 'Bulgaria', value: 'BG' },
18
- { label: 'Cyprus', value: 'CY' },
19
- { label: 'Czech Republic', value: 'CZ' },
20
- { label: 'Denmark', value: 'DK' },
21
- { label: 'Estonia', value: 'EE' },
22
- { label: 'Finland', value: 'FI' },
23
- { label: 'France', value: 'FR' },
24
- { label: 'Germany', value: 'DE' },
25
- { label: 'Greece', value: 'GR' },
26
- { label: 'Hong Kong', value: 'HK' },
27
- { label: 'Hungary', value: 'HU' },
28
- { label: 'India', value: 'IN' },
29
- { label: 'Ireland', value: 'IE' },
30
- { label: 'Italy', value: 'IT' },
31
- { label: 'Japan', value: 'JP' },
32
- { label: 'Latvia', value: 'LV' },
33
- { label: 'Lithuania', value: 'LT' },
34
- { label: 'Luxembourg', value: 'LU' },
35
- { label: 'Malaysia', value: 'MY' },
36
- { label: 'Malta', value: 'MT' },
37
- { label: 'Mexico', value: 'MX' },
38
- { label: 'Netherlands', value: 'NL' },
39
- { label: 'New Zealand', value: 'NZ' },
40
- { label: 'Norway', value: 'NO' },
41
- { label: 'Poland', value: 'PL' },
42
- { label: 'Portugal', value: 'PT' },
43
- { label: 'Romania', value: 'RO' },
44
- { label: 'Singapore', value: 'SG' },
45
- { label: 'Slovakia', value: 'SK' },
46
- { label: 'Slovenia', value: 'SI' },
47
- { label: 'Spain', value: 'ES' },
48
- { label: 'Sweden', value: 'SE' },
49
- { label: 'Switzerland', value: 'CH' },
50
- ]
@@ -1,51 +0,0 @@
1
- import type { CollectionBeforeChangeHook } from 'payload'
2
-
3
- type Props = {
4
- productsSlug: string
5
- variantsSlug: string
6
- }
7
-
8
- export const beforeChangeCart: (args: Props) => CollectionBeforeChangeHook =
9
- ({ productsSlug, variantsSlug }) =>
10
- async ({ data, req }) => {
11
- // Update subtotal based on items in the cart
12
- if (data.items && Array.isArray(data.items)) {
13
- const priceField = `priceIn${data.currency}`
14
-
15
- let subtotal = 0
16
-
17
- for (const item of data.items) {
18
- if (item.variant) {
19
- const id = typeof item.variant === 'object' ? item.variant.id : item.variant
20
-
21
- const variant = await req.payload.findByID({
22
- id,
23
- collection: variantsSlug,
24
- depth: 0,
25
- select: {
26
- [priceField]: true,
27
- },
28
- })
29
-
30
- subtotal += variant[priceField] * item.quantity
31
- } else {
32
- const id = typeof item.product === 'object' ? item.product.id : item.product
33
-
34
- const product = await req.payload.findByID({
35
- id,
36
- collection: productsSlug,
37
- depth: 0,
38
- select: {
39
- [priceField]: true,
40
- },
41
- })
42
-
43
- subtotal += product[priceField] * item.quantity
44
- }
45
- }
46
-
47
- data.subtotal = subtotal
48
- } else {
49
- data.subtotal = 0
50
- }
51
- }