@payloadcms/plugin-stripe 0.0.19 → 3.0.0-beta.23

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 (70) hide show
  1. package/README.md +3 -285
  2. package/dist/admin.d.ts +4 -0
  3. package/dist/admin.d.ts.map +1 -0
  4. package/dist/admin.js +34 -0
  5. package/dist/admin.js.map +1 -0
  6. package/dist/fields/getFields.d.ts +12 -0
  7. package/dist/fields/getFields.d.ts.map +1 -0
  8. package/dist/fields/getFields.js +46 -0
  9. package/dist/fields/getFields.js.map +1 -0
  10. package/dist/hooks/createNewInStripe.d.ts +7 -2
  11. package/dist/hooks/createNewInStripe.d.ts.map +1 -0
  12. package/dist/hooks/createNewInStripe.js +70 -124
  13. package/dist/hooks/createNewInStripe.js.map +1 -1
  14. package/dist/hooks/deleteFromStripe.d.ts +7 -2
  15. package/dist/hooks/deleteFromStripe.d.ts.map +1 -0
  16. package/dist/hooks/deleteFromStripe.js +30 -87
  17. package/dist/hooks/deleteFromStripe.js.map +1 -1
  18. package/dist/hooks/syncExistingWithStripe.d.ts +7 -2
  19. package/dist/hooks/syncExistingWithStripe.d.ts.map +1 -0
  20. package/dist/hooks/syncExistingWithStripe.js +42 -94
  21. package/dist/hooks/syncExistingWithStripe.js.map +1 -1
  22. package/dist/index.d.ts +5 -3
  23. package/dist/index.d.ts.map +1 -0
  24. package/dist/index.js +88 -166
  25. package/dist/index.js.map +1 -1
  26. package/dist/routes/rest.d.ts +4 -6
  27. package/dist/routes/rest.d.ts.map +1 -0
  28. package/dist/routes/rest.js +33 -76
  29. package/dist/routes/rest.js.map +1 -1
  30. package/dist/routes/webhooks.d.ts +4 -6
  31. package/dist/routes/webhooks.d.ts.map +1 -0
  32. package/dist/routes/webhooks.js +49 -94
  33. package/dist/routes/webhooks.js.map +1 -1
  34. package/dist/types.d.ts +138 -11
  35. package/dist/types.d.ts.map +1 -0
  36. package/dist/types.js +2 -2
  37. package/dist/types.js.map +1 -1
  38. package/dist/ui/LinkToDoc.d.ts +4 -7
  39. package/dist/ui/LinkToDoc.d.ts.map +1 -0
  40. package/dist/ui/LinkToDoc.js +29 -31
  41. package/dist/ui/LinkToDoc.js.map +1 -1
  42. package/dist/utilities/deepen.d.ts +1 -0
  43. package/dist/utilities/deepen.d.ts.map +1 -0
  44. package/dist/utilities/deepen.js +9 -16
  45. package/dist/utilities/deepen.js.map +1 -1
  46. package/dist/utilities/stripeProxy.d.ts +2 -1
  47. package/dist/utilities/stripeProxy.d.ts.map +1 -0
  48. package/dist/utilities/stripeProxy.js +37 -88
  49. package/dist/utilities/stripeProxy.js.map +1 -1
  50. package/dist/webhooks/handleCreatedOrUpdated.d.ts +3 -2
  51. package/dist/webhooks/handleCreatedOrUpdated.d.ts.map +1 -0
  52. package/dist/webhooks/handleCreatedOrUpdated.js +115 -196
  53. package/dist/webhooks/handleCreatedOrUpdated.js.map +1 -1
  54. package/dist/webhooks/handleDeleted.d.ts +2 -1
  55. package/dist/webhooks/handleDeleted.d.ts.map +1 -0
  56. package/dist/webhooks/handleDeleted.js +44 -102
  57. package/dist/webhooks/handleDeleted.js.map +1 -1
  58. package/dist/webhooks/index.d.ts +2 -1
  59. package/dist/webhooks/index.d.ts.map +1 -0
  60. package/dist/webhooks/index.js +46 -90
  61. package/dist/webhooks/index.js.map +1 -1
  62. package/package.json +50 -45
  63. package/types.d.ts +1 -1
  64. package/types.js +1 -1
  65. package/dist/extendWebpackConfig.d.ts +0 -3
  66. package/dist/extendWebpackConfig.js +0 -31
  67. package/dist/extendWebpackConfig.js.map +0 -1
  68. package/dist/mocks/serverModule.d.ts +0 -2
  69. package/dist/mocks/serverModule.js +0 -6
  70. package/dist/mocks/serverModule.js.map +0 -1
package/dist/index.js CHANGED
@@ -1,176 +1,98 @@
1
- "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
- return new (P || (P = Promise))(function (resolve, reject) {
16
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
- step((generator = generator.apply(thisArg, _arguments || [])).next());
20
- });
21
- };
22
- var __generator = (this && this.__generator) || function (thisArg, body) {
23
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
- function verb(n) { return function (v) { return step([n, v]); }; }
26
- function step(op) {
27
- if (f) throw new TypeError("Generator is already executing.");
28
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
29
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
- if (y = 0, t) op = [op[0] & 2, t.value];
31
- switch (op[0]) {
32
- case 0: case 1: t = op; break;
33
- case 4: _.label++; return { value: op[1], done: false };
34
- case 5: _.label++; y = op[1]; op = [0]; continue;
35
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
- default:
37
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
- if (t[2]) _.ops.pop();
42
- _.trys.pop(); continue;
43
- }
44
- op = body.call(thisArg, _);
45
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
- }
48
- };
49
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
50
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
51
- if (ar || !(i in from)) {
52
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
53
- ar[i] = from[i];
54
- }
55
- }
56
- return to.concat(ar || Array.prototype.slice.call(from));
57
- };
58
- var __importDefault = (this && this.__importDefault) || function (mod) {
59
- return (mod && mod.__esModule) ? mod : { "default": mod };
60
- };
61
- Object.defineProperty(exports, "__esModule", { value: true });
62
- var express_1 = __importDefault(require("express"));
63
- var extendWebpackConfig_1 = require("./extendWebpackConfig");
64
- var createNewInStripe_1 = require("./hooks/createNewInStripe");
65
- var deleteFromStripe_1 = require("./hooks/deleteFromStripe");
66
- var syncExistingWithStripe_1 = require("./hooks/syncExistingWithStripe");
67
- var rest_1 = require("./routes/rest");
68
- var webhooks_1 = require("./routes/webhooks");
69
- var LinkToDoc_1 = require("./ui/LinkToDoc");
70
- var stripePlugin = function (incomingStripeConfig) {
71
- return function (config) {
72
- var _a;
73
- var collections = config.collections;
1
+ import { getFields } from './fields/getFields.js';
2
+ import { createNewInStripe } from './hooks/createNewInStripe.js';
3
+ import { deleteFromStripe } from './hooks/deleteFromStripe.js';
4
+ import { syncExistingWithStripe } from './hooks/syncExistingWithStripe.js';
5
+ import { stripeREST } from './routes/rest.js';
6
+ import { stripeWebhooks } from './routes/webhooks.js';
7
+ export { LinkToDoc } from './ui/LinkToDoc.js';
8
+ export { stripeProxy } from './utilities/stripeProxy.js';
9
+ export const stripePlugin = (incomingStripeConfig)=>(config)=>{
10
+ const { collections } = config;
74
11
  // set config defaults here
75
- var stripeConfig = __assign(__assign({}, incomingStripeConfig), {
12
+ const stripeConfig = {
13
+ ...incomingStripeConfig,
76
14
  // TODO: in the next major version, default this to `false`
77
- rest: (_a = incomingStripeConfig === null || incomingStripeConfig === void 0 ? void 0 : incomingStripeConfig.rest) !== null && _a !== void 0 ? _a : true, sync: (incomingStripeConfig === null || incomingStripeConfig === void 0 ? void 0 : incomingStripeConfig.sync) || [] });
15
+ rest: incomingStripeConfig?.rest ?? true,
16
+ sync: incomingStripeConfig?.sync || []
17
+ };
78
18
  // NOTE: env variables are never passed to the client, but we need to know if `stripeSecretKey` is a test key
79
19
  // unfortunately we must set the 'isTestKey' property on the config instead of using the following code:
80
20
  // const isTestKey = stripeConfig.stripeSecretKey?.startsWith('sk_test_');
81
- return __assign(__assign({}, config), { admin: __assign(__assign({}, config.admin), { webpack: (0, extendWebpackConfig_1.extendWebpackConfig)(config) }), endpoints: __spreadArray(__spreadArray(__spreadArray([], ((config === null || config === void 0 ? void 0 : config.endpoints) || []), true), [
82
- {
83
- path: '/stripe/webhooks',
84
- method: 'post',
85
- root: true,
86
- handler: [
87
- express_1.default.raw({ type: 'application/json' }),
88
- function (req, res, next) {
89
- (0, webhooks_1.stripeWebhooks)({
90
- req: req,
91
- res: res,
92
- next: next,
93
- config: config,
94
- stripeConfig: stripeConfig,
95
- });
96
- },
97
- ],
98
- }
99
- ], false), ((incomingStripeConfig === null || incomingStripeConfig === void 0 ? void 0 : incomingStripeConfig.rest)
100
- ? [
101
- {
102
- path: '/stripe/rest',
103
- method: 'post',
104
- handler: function (req, res, next) {
105
- (0, rest_1.stripeREST)({
106
- req: req,
107
- res: res,
108
- next: next,
109
- stripeConfig: stripeConfig,
110
- });
111
- },
112
- },
113
- ]
114
- : []), true), collections: collections === null || collections === void 0 ? void 0 : collections.map(function (collection) {
115
- var _a;
116
- var existingHooks = collection.hooks;
117
- var syncConfig = (_a = stripeConfig.sync) === null || _a === void 0 ? void 0 : _a.find(function (sync) { return sync.collection === collection.slug; });
21
+ const endpoints = [
22
+ ...config?.endpoints || [],
23
+ {
24
+ handler: async (req)=>{
25
+ const res = await stripeWebhooks({
26
+ config,
27
+ req,
28
+ stripeConfig
29
+ });
30
+ return res;
31
+ },
32
+ method: 'post',
33
+ path: '/stripe/webhooks'
34
+ }
35
+ ];
36
+ if (incomingStripeConfig?.rest) {
37
+ endpoints.push({
38
+ handler: async (req)=>{
39
+ const res = await stripeREST({
40
+ req,
41
+ stripeConfig
42
+ });
43
+ return res;
44
+ },
45
+ method: 'post',
46
+ path: '/stripe/rest'
47
+ });
48
+ }
49
+ return {
50
+ ...config,
51
+ collections: collections?.map((collection)=>{
52
+ const { hooks: existingHooks } = collection;
53
+ const syncConfig = stripeConfig.sync?.find((sync)=>sync.collection === collection.slug);
118
54
  if (syncConfig) {
119
- return __assign(__assign({}, collection), { hooks: __assign(__assign({}, collection.hooks), { beforeValidate: __spreadArray(__spreadArray([], ((existingHooks === null || existingHooks === void 0 ? void 0 : existingHooks.beforeValidate) || []), true), [
120
- function (args) { return __awaiter(void 0, void 0, void 0, function () {
121
- return __generator(this, function (_a) {
122
- return [2 /*return*/, (0, createNewInStripe_1.createNewInStripe)(__assign(__assign({}, args), { collection: collection, stripeConfig: stripeConfig }))];
123
- });
124
- }); },
125
- ], false), beforeChange: __spreadArray(__spreadArray([], ((existingHooks === null || existingHooks === void 0 ? void 0 : existingHooks.beforeChange) || []), true), [
126
- function (args) { return __awaiter(void 0, void 0, void 0, function () {
127
- return __generator(this, function (_a) {
128
- return [2 /*return*/, (0, syncExistingWithStripe_1.syncExistingWithStripe)(__assign(__assign({}, args), { collection: collection, stripeConfig: stripeConfig }))];
129
- });
130
- }); },
131
- ], false), afterDelete: __spreadArray(__spreadArray([], ((existingHooks === null || existingHooks === void 0 ? void 0 : existingHooks.afterDelete) || []), true), [
132
- function (args) { return __awaiter(void 0, void 0, void 0, function () {
133
- return __generator(this, function (_a) {
134
- return [2 /*return*/, (0, deleteFromStripe_1.deleteFromStripe)(__assign(__assign({}, args), { collection: collection, stripeConfig: stripeConfig }))];
135
- });
136
- }); },
137
- ], false) }), fields: __spreadArray(__spreadArray([], collection.fields, true), [
138
- {
139
- name: 'stripeID',
140
- label: 'Stripe ID',
141
- type: 'text',
142
- saveToJWT: true,
143
- admin: {
144
- position: 'sidebar',
145
- readOnly: true,
146
- },
147
- },
148
- {
149
- name: 'skipSync',
150
- label: 'Skip Sync',
151
- type: 'checkbox',
152
- admin: {
153
- position: 'sidebar',
154
- readOnly: true,
155
- },
156
- },
157
- {
158
- name: 'docUrl',
159
- type: 'ui',
160
- admin: {
161
- position: 'sidebar',
162
- components: {
163
- Field: function (args) {
164
- return (0, LinkToDoc_1.LinkToDoc)(__assign(__assign({}, args), { isTestKey: stripeConfig.isTestKey, stripeResourceType: syncConfig.stripeResourceType, nameOfIDField: 'stripeID' }));
165
- },
166
- },
167
- },
168
- },
169
- ], false) });
55
+ const fields = getFields({
56
+ collection,
57
+ stripeConfig,
58
+ syncConfig
59
+ });
60
+ return {
61
+ ...collection,
62
+ fields,
63
+ hooks: {
64
+ ...collection.hooks,
65
+ afterDelete: [
66
+ ...existingHooks?.afterDelete || [],
67
+ (args)=>deleteFromStripe({
68
+ ...args,
69
+ collection,
70
+ stripeConfig
71
+ })
72
+ ],
73
+ beforeChange: [
74
+ ...existingHooks?.beforeChange || [],
75
+ (args)=>syncExistingWithStripe({
76
+ ...args,
77
+ collection,
78
+ stripeConfig
79
+ })
80
+ ],
81
+ beforeValidate: [
82
+ ...existingHooks?.beforeValidate || [],
83
+ (args)=>createNewInStripe({
84
+ ...args,
85
+ collection,
86
+ stripeConfig
87
+ })
88
+ ]
89
+ }
90
+ };
170
91
  }
171
92
  return collection;
172
- }) });
93
+ }),
94
+ endpoints
95
+ };
173
96
  };
174
- };
175
- exports.default = stripePlugin;
97
+
176
98
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../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sBAAA,IAAA,mCAAgB,wBACX,IAAI,KACP,UAAU,YAAA,EACV,YAAY,cAAA,IACZ,EAAA;;qCAAA;0CAGR,MAAM,kCACD,UAAU,CAAC,MAAM;4BACpB;gCACE,IAAI,EAAE,UAAU;gCAChB,KAAK,EAAE,WAAW;gCAClB,IAAI,EAAE,MAAM;gCACZ,SAAS,EAAE,IAAI;gCACf,KAAK,EAAE;oCACL,QAAQ,EAAE,SAAS;oCACnB,QAAQ,EAAE,IAAI;iCACf;6BACF;4BACD;gCACE,IAAI,EAAE,UAAU;gCAChB,KAAK,EAAE,WAAW;gCAClB,IAAI,EAAE,UAAU;gCAChB,KAAK,EAAE;oCACL,QAAQ,EAAE,SAAS;oCACnB,QAAQ,EAAE,IAAI;iCACf;6BACF;4BACD;gCACE,IAAI,EAAE,QAAQ;gCACd,IAAI,EAAE,IAAI;gCACV,KAAK,EAAE;oCACL,QAAQ,EAAE,SAAS;oCACnB,UAAU,EAAE;wCACV,KAAK,EAAE,UAAA,IAAI;4CACT,OAAA,IAAA,qBAAS,wBACJ,IAAI,KACP,SAAS,EAAE,YAAY,CAAC,SAAS,EACjC,kBAAkB,EAAE,UAAU,CAAC,kBAAkB,EACjD,aAAa,EAAE,UAAU,IACzB;wCALF,CAKE;qCACL;iCACF;6BACF;qCAEJ;iBACF;gBAED,OAAO,UAAU,CAAA;YACnB,CAAC,CAAC,IACH;IACH,CAAC;AA3ID,CA2IC,CAAA;AAEH,kBAAe,YAAY,CAAA"}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { Config, Endpoint } from 'payload/config'\n\nimport type { SanitizedStripeConfig, StripeConfig } from './types.js'\n\nimport { getFields } from './fields/getFields.js'\nimport { createNewInStripe } from './hooks/createNewInStripe.js'\nimport { deleteFromStripe } from './hooks/deleteFromStripe.js'\nimport { syncExistingWithStripe } from './hooks/syncExistingWithStripe.js'\nimport { stripeREST } from './routes/rest.js'\nimport { stripeWebhooks } from './routes/webhooks.js'\n\nexport { LinkToDoc } from './ui/LinkToDoc.js'\nexport { stripeProxy } from './utilities/stripeProxy.js'\n\nexport const stripePlugin =\n (incomingStripeConfig: StripeConfig) =>\n (config: Config): Config => {\n const { collections } = config\n\n // set config defaults here\n const stripeConfig: SanitizedStripeConfig = {\n ...incomingStripeConfig,\n // TODO: in the next major version, default this to `false`\n rest: incomingStripeConfig?.rest ?? true,\n sync: incomingStripeConfig?.sync || [],\n }\n\n // NOTE: env variables are never passed to the client, but we need to know if `stripeSecretKey` is a test key\n // unfortunately we must set the 'isTestKey' property on the config instead of using the following code:\n // const isTestKey = stripeConfig.stripeSecretKey?.startsWith('sk_test_');\n\n const endpoints: Endpoint[] = [\n ...(config?.endpoints || []),\n {\n handler: async (req) => {\n const res = await stripeWebhooks({\n config,\n req,\n stripeConfig,\n })\n\n return res\n },\n method: 'post',\n path: '/stripe/webhooks',\n },\n ]\n\n if (incomingStripeConfig?.rest) {\n endpoints.push({\n handler: async (req) => {\n const res = await stripeREST({\n req,\n stripeConfig,\n })\n\n return res\n },\n method: 'post' as Endpoint['method'],\n path: '/stripe/rest',\n })\n }\n\n return {\n ...config,\n collections: collections?.map((collection) => {\n const { hooks: existingHooks } = collection\n\n const syncConfig = stripeConfig.sync?.find((sync) => sync.collection === collection.slug)\n\n if (syncConfig) {\n const fields = getFields({\n collection,\n stripeConfig,\n syncConfig,\n })\n return {\n ...collection,\n fields,\n hooks: {\n ...collection.hooks,\n afterDelete: [\n ...(existingHooks?.afterDelete || []),\n (args) =>\n deleteFromStripe({\n ...args,\n collection,\n stripeConfig,\n }),\n ],\n beforeChange: [\n ...(existingHooks?.beforeChange || []),\n (args) =>\n syncExistingWithStripe({\n ...args,\n collection,\n stripeConfig,\n }),\n ],\n beforeValidate: [\n ...(existingHooks?.beforeValidate || []),\n (args) =>\n createNewInStripe({\n ...args,\n collection,\n stripeConfig,\n }),\n ],\n },\n }\n }\n\n return collection\n }),\n endpoints,\n }\n }\n"],"names":["getFields","createNewInStripe","deleteFromStripe","syncExistingWithStripe","stripeREST","stripeWebhooks","LinkToDoc","stripeProxy","stripePlugin","incomingStripeConfig","config","collections","stripeConfig","rest","sync","endpoints","handler","req","res","method","path","push","map","collection","hooks","existingHooks","syncConfig","find","slug","fields","afterDelete","args","beforeChange","beforeValidate"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAIA,SAASA,SAAS,QAAQ,wBAAuB;AACjD,SAASC,iBAAiB,QAAQ,+BAA8B;AAChE,SAASC,gBAAgB,QAAQ,8BAA6B;AAC9D,SAASC,sBAAsB,QAAQ,oCAAmC;AAC1E,SAASC,UAAU,QAAQ,mBAAkB;AAC7C,SAASC,cAAc,QAAQ,uBAAsB;AAErD,SAASC,SAAS,QAAQ,oBAAmB;AAC7C,SAASC,WAAW,QAAQ,6BAA4B;AAExD,OAAO,MAAMC,eACX,CAACC,uBACD,CAACC;QACC,MAAM,EAAEC,WAAW,EAAE,GAAGD;QAExB,2BAA2B;QAC3B,MAAME,eAAsC;YAC1C,GAAGH,oBAAoB;YACvB,2DAA2D;YAC3DI,MAAMJ,sBAAsBI,QAAQ;YACpCC,MAAML,sBAAsBK,QAAQ,EAAE;QACxC;QAEA,6GAA6G;QAC7G,wGAAwG;QACxG,0EAA0E;QAE1E,MAAMC,YAAwB;eACxBL,QAAQK,aAAa,EAAE;YAC3B;gBACEC,SAAS,OAAOC;oBACd,MAAMC,MAAM,MAAMb,eAAe;wBAC/BK;wBACAO;wBACAL;oBACF;oBAEA,OAAOM;gBACT;gBACAC,QAAQ;gBACRC,MAAM;YACR;SACD;QAED,IAAIX,sBAAsBI,MAAM;YAC9BE,UAAUM,IAAI,CAAC;gBACbL,SAAS,OAAOC;oBACd,MAAMC,MAAM,MAAMd,WAAW;wBAC3Ba;wBACAL;oBACF;oBAEA,OAAOM;gBACT;gBACAC,QAAQ;gBACRC,MAAM;YACR;QACF;QAEA,OAAO;YACL,GAAGV,MAAM;YACTC,aAAaA,aAAaW,IAAI,CAACC;gBAC7B,MAAM,EAAEC,OAAOC,aAAa,EAAE,GAAGF;gBAEjC,MAAMG,aAAad,aAAaE,IAAI,EAAEa,KAAK,CAACb,OAASA,KAAKS,UAAU,KAAKA,WAAWK,IAAI;gBAExF,IAAIF,YAAY;oBACd,MAAMG,SAAS7B,UAAU;wBACvBuB;wBACAX;wBACAc;oBACF;oBACA,OAAO;wBACL,GAAGH,UAAU;wBACbM;wBACAL,OAAO;4BACL,GAAGD,WAAWC,KAAK;4BACnBM,aAAa;mCACPL,eAAeK,eAAe,EAAE;gCACpC,CAACC,OACC7B,iBAAiB;wCACf,GAAG6B,IAAI;wCACPR;wCACAX;oCACF;6BACH;4BACDoB,cAAc;mCACRP,eAAeO,gBAAgB,EAAE;gCACrC,CAACD,OACC5B,uBAAuB;wCACrB,GAAG4B,IAAI;wCACPR;wCACAX;oCACF;6BACH;4BACDqB,gBAAgB;mCACVR,eAAeQ,kBAAkB,EAAE;gCACvC,CAACF,OACC9B,kBAAkB;wCAChB,GAAG8B,IAAI;wCACPR;wCACAX;oCACF;6BACH;wBACH;oBACF;gBACF;gBAEA,OAAOW;YACT;YACAR;QACF;IACF,EAAC"}
@@ -1,9 +1,7 @@
1
- import type { Response } from 'express';
2
- import type { PayloadRequest } from 'payload/types';
3
- import type { StripeConfig } from '../types';
1
+ import type { PayloadRequestWithData } from 'payload/types';
2
+ import type { StripeConfig } from '../types.js';
4
3
  export declare const stripeREST: (args: {
5
- req: PayloadRequest;
6
- res: Response;
7
- next: any;
4
+ req: PayloadRequestWithData;
8
5
  stripeConfig: StripeConfig;
9
6
  }) => Promise<any>;
7
+ //# sourceMappingURL=rest.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rest.d.ts","sourceRoot":"","sources":["../../src/routes/rest.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAA;AAI3D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAI/C,eAAO,MAAM,UAAU,SAAgB;IACrC,GAAG,EAAE,sBAAsB,CAAA;IAC3B,YAAY,EAAE,YAAY,CAAA;CAC3B,KAAG,QAAQ,GAAG,CA+Cd,CAAA"}
@@ -1,79 +1,36 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.stripeREST = void 0;
40
- var errors_1 = require("payload/errors");
41
- var stripeProxy_1 = require("../utilities/stripeProxy");
42
- var stripeREST = function (args) { return __awaiter(void 0, void 0, void 0, function () {
43
- var req, res, stripeConfig, payload, user, _a, stripeMethod, stripeArgs, stripeSecretKey, pluginRes, status_1, error_1, message;
44
- return __generator(this, function (_b) {
45
- switch (_b.label) {
46
- case 0:
47
- req = args.req, res = args.res, stripeConfig = args.stripeConfig;
48
- payload = req.payload, user = req.user, _a = req.body, stripeMethod = _a.stripeMethod, stripeArgs = _a.stripeArgs;
49
- stripeSecretKey = stripeConfig.stripeSecretKey;
50
- _b.label = 1;
51
- case 1:
52
- _b.trys.push([1, 3, , 4]);
53
- if (!user) {
54
- // TODO: make this customizable from the config
55
- throw new errors_1.Forbidden();
56
- }
57
- return [4 /*yield*/, (0, stripeProxy_1.stripeProxy)({
58
- stripeSecretKey: stripeSecretKey,
59
- stripeMethod: stripeMethod,
60
- stripeArgs: stripeArgs,
61
- })];
62
- case 2:
63
- pluginRes = _b.sent();
64
- status_1 = pluginRes.status;
65
- res.status(status_1).json(pluginRes);
66
- return [3 /*break*/, 4];
67
- case 3:
68
- error_1 = _b.sent();
69
- message = "An error has occurred in the Stripe plugin REST handler: '".concat(error_1, "'");
70
- payload.logger.error(message);
71
- return [2 /*return*/, res.status(500).json({
72
- message: message,
73
- })];
74
- case 4: return [2 /*return*/];
1
+ import { Forbidden } from 'payload/errors';
2
+ import { stripeProxy } from '../utilities/stripeProxy.js';
3
+ export const stripeREST = async (args)=>{
4
+ let responseStatus = 200;
5
+ let responseJSON;
6
+ const { req, stripeConfig } = args;
7
+ const { data: { stripeArgs, stripeMethod }, payload, user } = req;
8
+ const { stripeSecretKey } = stripeConfig;
9
+ try {
10
+ if (!user) {
11
+ // TODO: make this customizable from the config
12
+ throw new Forbidden(req.t);
75
13
  }
14
+ responseJSON = await stripeProxy({
15
+ // @ts-expect-error
16
+ stripeArgs,
17
+ // @ts-expect-error
18
+ stripeMethod,
19
+ stripeSecretKey
20
+ });
21
+ const { status } = responseJSON;
22
+ responseStatus = status;
23
+ } catch (error) {
24
+ const message = `An error has occurred in the Stripe plugin REST handler: '${JSON.stringify(error)}'`;
25
+ payload.logger.error(message);
26
+ responseStatus = 500;
27
+ responseJSON = {
28
+ message
29
+ };
30
+ }
31
+ return Response.json(responseJSON, {
32
+ status: responseStatus
76
33
  });
77
- }); };
78
- exports.stripeREST = stripeREST;
34
+ };
35
+
79
36
  //# sourceMappingURL=rest.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"rest.js","sourceRoot":"","sources":["../../src/routes/rest.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,yCAA0C;AAI1C,wDAAsD;AAE/C,IAAM,UAAU,GAAG,UAAO,IAKhC;;;;;gBACS,GAAG,GAAwB,IAAI,IAA5B,EAAE,GAAG,GAAmB,IAAI,IAAvB,EAAE,YAAY,GAAK,IAAI,aAAT,CAAS;gBAGrC,OAAO,GAML,GAAG,QANE,EACP,IAAI,GAKF,GAAG,KALD,EACJ,KAIE,GAAG,KADJ,EAFC,YAAY,kBAAA,EACZ,UAAU,gBAAA,CAEP;gBAEC,eAAe,GAAK,YAAY,gBAAjB,CAAiB;;;;gBAGtC,IAAI,CAAC,IAAI,EAAE;oBACT,+CAA+C;oBAC/C,MAAM,IAAI,kBAAS,EAAE,CAAA;iBACtB;gBAEiB,qBAAM,IAAA,yBAAW,EAAC;wBAClC,eAAe,iBAAA;wBACf,YAAY,cAAA;wBACZ,UAAU,YAAA;qBACX,CAAC,EAAA;;gBAJI,SAAS,GAAG,SAIhB;gBAEM,WAAW,SAAS,OAAd,CAAc;gBAE5B,GAAG,CAAC,MAAM,CAAC,QAAM,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;;;;gBAE5B,OAAO,GAAG,oEAA6D,OAAK,MAAG,CAAA;gBACrF,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;gBAC7B,sBAAO,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;wBAC1B,OAAO,SAAA;qBACR,CAAC,EAAA;;;;KAEL,CAAA;AAzCY,QAAA,UAAU,cAyCtB"}
1
+ {"version":3,"sources":["../../src/routes/rest.ts"],"sourcesContent":["import type { PayloadRequestWithData } from 'payload/types'\n\nimport { Forbidden } from 'payload/errors'\n\nimport type { StripeConfig } from '../types.js'\n\nimport { stripeProxy } from '../utilities/stripeProxy.js'\n\nexport const stripeREST = async (args: {\n req: PayloadRequestWithData\n stripeConfig: StripeConfig\n}): Promise<any> => {\n let responseStatus = 200\n let responseJSON\n\n const { req, stripeConfig } = args\n\n const {\n data: {\n stripeArgs, // example: ['cus_MGgt3Tuj3D66f2'] or [{ limit: 100 }, { stripeAccount: 'acct_1J9Z4pKZ4Z4Z4Z4Z' }]\n stripeMethod, // example: 'subscriptions.list',\n },\n payload,\n user,\n } = req\n\n const { stripeSecretKey } = stripeConfig\n\n try {\n if (!user) {\n // TODO: make this customizable from the config\n throw new Forbidden(req.t)\n }\n\n responseJSON = await stripeProxy({\n // @ts-expect-error\n stripeArgs,\n // @ts-expect-error\n stripeMethod,\n stripeSecretKey,\n })\n\n const { status } = responseJSON\n responseStatus = status\n } catch (error: unknown) {\n const message = `An error has occurred in the Stripe plugin REST handler: '${JSON.stringify(\n error,\n )}'`\n payload.logger.error(message)\n responseStatus = 500\n responseJSON = {\n message,\n }\n }\n\n return Response.json(responseJSON, {\n status: responseStatus,\n })\n}\n"],"names":["Forbidden","stripeProxy","stripeREST","args","responseStatus","responseJSON","req","stripeConfig","data","stripeArgs","stripeMethod","payload","user","stripeSecretKey","t","status","error","message","JSON","stringify","logger","Response","json"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAEA,SAASA,SAAS,QAAQ,iBAAgB;AAI1C,SAASC,WAAW,QAAQ,8BAA6B;AAEzD,OAAO,MAAMC,aAAa,OAAOC;IAI/B,IAAIC,iBAAiB;IACrB,IAAIC;IAEJ,MAAM,EAAEC,GAAG,EAAEC,YAAY,EAAE,GAAGJ;IAE9B,MAAM,EACJK,MAAM,EACJC,UAAU,EACVC,YAAY,EACb,EACDC,OAAO,EACPC,IAAI,EACL,GAAGN;IAEJ,MAAM,EAAEO,eAAe,EAAE,GAAGN;IAE5B,IAAI;QACF,IAAI,CAACK,MAAM;YACT,+CAA+C;YAC/C,MAAM,IAAIZ,UAAUM,IAAIQ,CAAC;QAC3B;QAEAT,eAAe,MAAMJ,YAAY;YAC/B,mBAAmB;YACnBQ;YACA,mBAAmB;YACnBC;YACAG;QACF;QAEA,MAAM,EAAEE,MAAM,EAAE,GAAGV;QACnBD,iBAAiBW;IACnB,EAAE,OAAOC,OAAgB;QACvB,MAAMC,UAAU,CAAC,0DAA0D,EAAEC,KAAKC,SAAS,CACzFH,OACA,CAAC,CAAC;QACJL,QAAQS,MAAM,CAACJ,KAAK,CAACC;QACrBb,iBAAiB;QACjBC,eAAe;YACbY;QACF;IACF;IAEA,OAAOI,SAASC,IAAI,CAACjB,cAAc;QACjCU,QAAQX;IACV;AACF,EAAC"}
@@ -1,11 +1,9 @@
1
- import type { Response } from 'express';
2
1
  import type { Config as PayloadConfig } from 'payload/config';
3
- import type { PayloadRequest } from 'payload/dist/types';
4
- import type { StripeConfig } from '../types';
2
+ import type { PayloadRequestWithData } from 'payload/types';
3
+ import type { StripeConfig } from '../types.js';
5
4
  export declare const stripeWebhooks: (args: {
6
- req: PayloadRequest;
7
- res: Response;
8
- next: any;
9
5
  config: PayloadConfig;
6
+ req: PayloadRequestWithData;
10
7
  stripeConfig: StripeConfig;
11
8
  }) => Promise<any>;
9
+ //# sourceMappingURL=webhooks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webhooks.d.ts","sourceRoot":"","sources":["../../src/routes/webhooks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAC7D,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAA;AAI3D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAI/C,eAAO,MAAM,cAAc,SAAgB;IACzC,MAAM,EAAE,aAAa,CAAA;IACrB,GAAG,EAAE,sBAAsB,CAAA;IAC3B,YAAY,EAAE,YAAY,CAAA;CAC3B,KAAG,QAAQ,GAAG,CAwEd,CAAA"}