@payloadcms/plugin-stripe 0.0.19 → 3.0.0-alpha.67

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 (71) 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/payload-stripe-plugin.postman_collection.json +301 -0
  27. package/dist/routes/rest.d.ts +4 -6
  28. package/dist/routes/rest.d.ts.map +1 -0
  29. package/dist/routes/rest.js +33 -76
  30. package/dist/routes/rest.js.map +1 -1
  31. package/dist/routes/webhooks.d.ts +4 -6
  32. package/dist/routes/webhooks.d.ts.map +1 -0
  33. package/dist/routes/webhooks.js +49 -94
  34. package/dist/routes/webhooks.js.map +1 -1
  35. package/dist/types.d.ts +138 -11
  36. package/dist/types.d.ts.map +1 -0
  37. package/dist/types.js +2 -2
  38. package/dist/types.js.map +1 -1
  39. package/dist/ui/LinkToDoc.d.ts +4 -7
  40. package/dist/ui/LinkToDoc.d.ts.map +1 -0
  41. package/dist/ui/LinkToDoc.js +29 -31
  42. package/dist/ui/LinkToDoc.js.map +1 -1
  43. package/dist/utilities/deepen.d.ts +1 -0
  44. package/dist/utilities/deepen.d.ts.map +1 -0
  45. package/dist/utilities/deepen.js +9 -16
  46. package/dist/utilities/deepen.js.map +1 -1
  47. package/dist/utilities/stripeProxy.d.ts +2 -1
  48. package/dist/utilities/stripeProxy.d.ts.map +1 -0
  49. package/dist/utilities/stripeProxy.js +37 -88
  50. package/dist/utilities/stripeProxy.js.map +1 -1
  51. package/dist/webhooks/handleCreatedOrUpdated.d.ts +3 -2
  52. package/dist/webhooks/handleCreatedOrUpdated.d.ts.map +1 -0
  53. package/dist/webhooks/handleCreatedOrUpdated.js +115 -196
  54. package/dist/webhooks/handleCreatedOrUpdated.js.map +1 -1
  55. package/dist/webhooks/handleDeleted.d.ts +2 -1
  56. package/dist/webhooks/handleDeleted.d.ts.map +1 -0
  57. package/dist/webhooks/handleDeleted.js +44 -102
  58. package/dist/webhooks/handleDeleted.js.map +1 -1
  59. package/dist/webhooks/index.d.ts +2 -1
  60. package/dist/webhooks/index.d.ts.map +1 -0
  61. package/dist/webhooks/index.js +46 -90
  62. package/dist/webhooks/index.js.map +1 -1
  63. package/package.json +50 -45
  64. package/types.d.ts +1 -1
  65. package/types.js +1 -1
  66. package/dist/extendWebpackConfig.d.ts +0 -3
  67. package/dist/extendWebpackConfig.js +0 -31
  68. package/dist/extendWebpackConfig.js.map +0 -1
  69. package/dist/mocks/serverModule.d.ts +0 -2
  70. package/dist/mocks/serverModule.js +0 -6
  71. 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 @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,EAAE,CAAC;gCACrC,UAAM,IAAI;;wCACR,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"}
@@ -0,0 +1,301 @@
1
+ {
2
+ "info": {
3
+ "name": "Payload Stripe Plugin",
4
+ "_exporter_id": "4309346",
5
+ "_postman_id": "130686e1-ddd9-40f1-b031-68ec1a6413ee",
6
+ "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
7
+ },
8
+ "item": [
9
+ {
10
+ "name": "Get All Subscriptions",
11
+ "request": {
12
+ "body": {
13
+ "mode": "raw",
14
+ "raw": "{\n \"stripeMethod\": \"subscriptions.list\",\n \"stripeArgs\": {\n \"customer\": \"cus_MGgt3Tuj3D66f2\"\n }\n}"
15
+ },
16
+ "header": [
17
+ {
18
+ "key": "Content-Type",
19
+ "type": "text",
20
+ "value": "application/json"
21
+ },
22
+ {
23
+ "key": "Authorization",
24
+ "type": "text",
25
+ "value": "JWT {{PAYLOAD_API_TOKEN}}"
26
+ }
27
+ ],
28
+ "method": "POST",
29
+ "url": {
30
+ "host": ["localhost"],
31
+ "path": ["api", "stripe", "rest"],
32
+ "port": "3000",
33
+ "raw": "localhost:3000/api/stripe/rest"
34
+ }
35
+ },
36
+ "response": []
37
+ },
38
+ {
39
+ "name": "Get All Products",
40
+ "request": {
41
+ "body": {
42
+ "mode": "raw",
43
+ "raw": "{\n \"stripeMethod\": \"products.list\",\n \"stripeArgs\": [{\n \"limit\": 100\n }]\n}"
44
+ },
45
+ "header": [
46
+ {
47
+ "key": "Content-Type",
48
+ "type": "text",
49
+ "value": "application/json"
50
+ },
51
+ {
52
+ "key": "Authorization",
53
+ "type": "text",
54
+ "value": "JWT {{PAYLOAD_API_TOKEN}}"
55
+ }
56
+ ],
57
+ "method": "POST",
58
+ "url": {
59
+ "host": ["localhost"],
60
+ "path": ["api", "stripe", "rest"],
61
+ "port": "3000",
62
+ "raw": "localhost:3000/api/stripe/rest"
63
+ }
64
+ },
65
+ "response": []
66
+ },
67
+ {
68
+ "name": "Get Product",
69
+ "protocolProfileBehavior": {
70
+ "disableBodyPruning": true
71
+ },
72
+ "request": {
73
+ "body": {
74
+ "mode": "raw",
75
+ "raw": "{\n \"stripeMethod\": \"subscriptions.list\",\n \"stripeArgs\": {\n \"customer\": \"cus_MGgt3Tuj3D66f2\"\n }\n}"
76
+ },
77
+ "header": [
78
+ {
79
+ "key": "Content-Type",
80
+ "type": "text",
81
+ "value": "application/json"
82
+ },
83
+ {
84
+ "key": "Authorization",
85
+ "type": "text",
86
+ "value": "JWT {{PAYLOAD_API_TOKEN}}"
87
+ }
88
+ ],
89
+ "method": "GET",
90
+ "url": {
91
+ "host": ["localhost"],
92
+ "path": ["api", "products", "6344664c003348299a226249"],
93
+ "port": "3000",
94
+ "raw": "localhost:3000/api/products/6344664c003348299a226249"
95
+ }
96
+ },
97
+ "response": []
98
+ },
99
+ {
100
+ "name": "Update Product",
101
+ "request": {
102
+ "body": {
103
+ "mode": "raw",
104
+ "raw": "{\n \"name\": \"Reactions\",\n \"price\": {\n \"stripePriceID\": \"price_1LXXU9H77M76aDnomGU5iIZu\"\n },\n \"stripeID\": \"prod_MG3bPl2yQGQK4x\",\n \"skipSync\": true\n}"
105
+ },
106
+ "header": [
107
+ {
108
+ "key": "Content-Type",
109
+ "type": "text",
110
+ "value": "application/json"
111
+ },
112
+ {
113
+ "key": "Authorization",
114
+ "type": "text",
115
+ "value": "JWT {{PAYLOAD_API_TOKEN}}"
116
+ }
117
+ ],
118
+ "method": "PATCH",
119
+ "url": {
120
+ "host": ["localhost"],
121
+ "path": ["api", "products", "6344664c003348299a226249"],
122
+ "port": "3000",
123
+ "raw": "localhost:3000/api/products/6344664c003348299a226249"
124
+ }
125
+ },
126
+ "response": []
127
+ },
128
+ {
129
+ "name": "Create Product",
130
+ "request": {
131
+ "body": {
132
+ "mode": "raw",
133
+ "raw": "{\n \"name\": \"Test\",\n \"price\": {\n \"stripePriceID\": \"price_1LXXU9H77M76aDnomGU5iIZu\"\n },\n \"stripeID\": \"prod_MG3bPl2yQGQK4x\",\n \"skipSync\": true\n}"
134
+ },
135
+ "header": [
136
+ {
137
+ "key": "Content-Type",
138
+ "type": "text",
139
+ "value": "application/json"
140
+ },
141
+ {
142
+ "key": "Authorization",
143
+ "type": "text",
144
+ "value": "JWT {{PAYLOAD_API_TOKEN}}"
145
+ }
146
+ ],
147
+ "method": "POST",
148
+ "url": {
149
+ "host": ["localhost"],
150
+ "path": ["api", "products"],
151
+ "port": "3000",
152
+ "raw": "localhost:3000/api/products"
153
+ }
154
+ },
155
+ "response": []
156
+ },
157
+ {
158
+ "name": "Create Stripe Customer",
159
+ "request": {
160
+ "body": {
161
+ "mode": "raw",
162
+ "raw": "{\n \"stripeMethod\": \"customers.create\",\n \"stripeArgs\": {\n \"email\": \"cta@hulu.com\",\n \"name\": \"Hulu\"\n }\n}"
163
+ },
164
+ "header": [
165
+ {
166
+ "key": "Content-Type",
167
+ "type": "text",
168
+ "value": "application/json"
169
+ },
170
+ {
171
+ "key": "Authorization",
172
+ "type": "text",
173
+ "value": "JWT {{PAYLOAD_API_TOKEN}}"
174
+ }
175
+ ],
176
+ "method": "POST",
177
+ "url": {
178
+ "host": ["localhost"],
179
+ "path": ["api", "stripe", "rest"],
180
+ "port": "3000",
181
+ "raw": "localhost:3000/api/stripe/rest"
182
+ }
183
+ },
184
+ "response": []
185
+ },
186
+ {
187
+ "name": "Login",
188
+ "event": [
189
+ {
190
+ "listen": "test",
191
+ "script": {
192
+ "exec": [
193
+ "let jsonData = pm.response.json();",
194
+ "pm.environment.set(\"PAYLOAD_API_TOKEN\", jsonData.token);"
195
+ ],
196
+ "type": "text/javascript"
197
+ }
198
+ }
199
+ ],
200
+ "request": {
201
+ "body": {
202
+ "mode": "raw",
203
+ "options": {
204
+ "raw": {
205
+ "language": "json"
206
+ }
207
+ },
208
+ "raw": "{\n\t\"email\": \"jacob@trbl.design\",\n\t\"password\": \"test\"\n}"
209
+ },
210
+ "description": "\t",
211
+ "header": [
212
+ {
213
+ "disabled": true,
214
+ "key": "Authorization",
215
+ "value": ""
216
+ }
217
+ ],
218
+ "method": "POST",
219
+ "url": {
220
+ "host": ["localhost"],
221
+ "path": ["api", "users", "login"],
222
+ "port": "3000",
223
+ "raw": "localhost:3000/api/users/login"
224
+ }
225
+ },
226
+ "response": []
227
+ },
228
+ {
229
+ "name": "Refresh Token",
230
+ "protocolProfileBehavior": {
231
+ "disabledSystemHeaders": {}
232
+ },
233
+ "request": {
234
+ "body": {
235
+ "mode": "raw",
236
+ "options": {
237
+ "raw": {
238
+ "language": "json"
239
+ }
240
+ },
241
+ "raw": "{\n \"token\": \"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6ImphY29ic2ZsZXRjaEBnbWFpbC5jb20iLCJpZCI6IjYwODJlZjUxMzg5ZmM2MmYzNWI2MmM2ZiIsImNvbGxlY3Rpb24iOiJ1c2VycyIsImZpcnN0TmFtZSI6IkphY29iIiwibGFzdE5hbWUiOiJGbGV0Y2hlciIsIm9yZ2FuaXphdGlvbiI6IjYwN2RiNGNmYjYzMGIyNWI5YzkzNmMzNSIsImlhdCI6MTYzMTExMDk3NSwiZXhwIjoxNjMyOTI1Mzc1fQ.OL9l8jFNaCZCU-ZDQpH-EJauaRM-5JT4_Y3J_-aC-aY\"\n}"
242
+ },
243
+ "header": [],
244
+ "method": "POST",
245
+ "url": {
246
+ "host": ["localhost"],
247
+ "path": ["api", "users", "refresh-token"],
248
+ "port": "3000",
249
+ "raw": "localhost:3000/api/users/refresh-token"
250
+ }
251
+ },
252
+ "response": []
253
+ },
254
+ {
255
+ "name": "Me",
256
+ "event": [
257
+ {
258
+ "listen": "test",
259
+ "script": {
260
+ "exec": [
261
+ "let jsonData = pm.response.json();",
262
+ "pm.environment.set(\"PAYLOAD_API_TOKEN\", jsonData.token);"
263
+ ],
264
+ "type": "text/javascript"
265
+ }
266
+ }
267
+ ],
268
+ "protocolProfileBehavior": {
269
+ "disableBodyPruning": true
270
+ },
271
+ "request": {
272
+ "body": {
273
+ "mode": "raw",
274
+ "raw": ""
275
+ },
276
+ "description": "\t",
277
+ "header": [
278
+ {
279
+ "disabled": true,
280
+ "key": "Authorization",
281
+ "value": ""
282
+ }
283
+ ],
284
+ "method": "GET",
285
+ "url": {
286
+ "host": ["localhost"],
287
+ "path": ["api", "users", "me"],
288
+ "port": "3000",
289
+ "query": [
290
+ {
291
+ "key": "depth",
292
+ "value": "1"
293
+ }
294
+ ],
295
+ "raw": "localhost:3000/api/users/me?depth=1"
296
+ }
297
+ },
298
+ "response": []
299
+ }
300
+ ]
301
+ }
@@ -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"}