@payloadcms/plugin-stripe 0.0.19 → 3.0.0-alpha.68
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -285
- package/dist/admin.d.ts +4 -0
- package/dist/admin.d.ts.map +1 -0
- package/dist/admin.js +34 -0
- package/dist/admin.js.map +1 -0
- package/dist/fields/getFields.d.ts +12 -0
- package/dist/fields/getFields.d.ts.map +1 -0
- package/dist/fields/getFields.js +46 -0
- package/dist/fields/getFields.js.map +1 -0
- package/dist/hooks/createNewInStripe.d.ts +7 -2
- package/dist/hooks/createNewInStripe.d.ts.map +1 -0
- package/dist/hooks/createNewInStripe.js +70 -124
- package/dist/hooks/createNewInStripe.js.map +1 -1
- package/dist/hooks/deleteFromStripe.d.ts +7 -2
- package/dist/hooks/deleteFromStripe.d.ts.map +1 -0
- package/dist/hooks/deleteFromStripe.js +30 -87
- package/dist/hooks/deleteFromStripe.js.map +1 -1
- package/dist/hooks/syncExistingWithStripe.d.ts +7 -2
- package/dist/hooks/syncExistingWithStripe.d.ts.map +1 -0
- package/dist/hooks/syncExistingWithStripe.js +42 -94
- package/dist/hooks/syncExistingWithStripe.js.map +1 -1
- package/dist/index.d.ts +5 -3
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +88 -166
- package/dist/index.js.map +1 -1
- package/dist/routes/rest.d.ts +4 -6
- package/dist/routes/rest.d.ts.map +1 -0
- package/dist/routes/rest.js +33 -76
- package/dist/routes/rest.js.map +1 -1
- package/dist/routes/webhooks.d.ts +4 -6
- package/dist/routes/webhooks.d.ts.map +1 -0
- package/dist/routes/webhooks.js +49 -94
- package/dist/routes/webhooks.js.map +1 -1
- package/dist/types.d.ts +138 -11
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -2
- package/dist/types.js.map +1 -1
- package/dist/ui/LinkToDoc.d.ts +4 -7
- package/dist/ui/LinkToDoc.d.ts.map +1 -0
- package/dist/ui/LinkToDoc.js +29 -31
- package/dist/ui/LinkToDoc.js.map +1 -1
- package/dist/utilities/deepen.d.ts +1 -0
- package/dist/utilities/deepen.d.ts.map +1 -0
- package/dist/utilities/deepen.js +9 -16
- package/dist/utilities/deepen.js.map +1 -1
- package/dist/utilities/stripeProxy.d.ts +2 -1
- package/dist/utilities/stripeProxy.d.ts.map +1 -0
- package/dist/utilities/stripeProxy.js +37 -88
- package/dist/utilities/stripeProxy.js.map +1 -1
- package/dist/webhooks/handleCreatedOrUpdated.d.ts +3 -2
- package/dist/webhooks/handleCreatedOrUpdated.d.ts.map +1 -0
- package/dist/webhooks/handleCreatedOrUpdated.js +115 -196
- package/dist/webhooks/handleCreatedOrUpdated.js.map +1 -1
- package/dist/webhooks/handleDeleted.d.ts +2 -1
- package/dist/webhooks/handleDeleted.d.ts.map +1 -0
- package/dist/webhooks/handleDeleted.js +44 -102
- package/dist/webhooks/handleDeleted.js.map +1 -1
- package/dist/webhooks/index.d.ts +2 -1
- package/dist/webhooks/index.d.ts.map +1 -0
- package/dist/webhooks/index.js +46 -90
- package/dist/webhooks/index.js.map +1 -1
- package/package.json +50 -45
- package/types.d.ts +1 -1
- package/types.js +1 -1
- package/dist/extendWebpackConfig.d.ts +0 -3
- package/dist/extendWebpackConfig.js +0 -31
- package/dist/extendWebpackConfig.js.map +0 -1
- package/dist/mocks/serverModule.d.ts +0 -2
- package/dist/mocks/serverModule.js +0 -6
- package/dist/mocks/serverModule.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,176 +1,98 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
|
|
12
|
+
const stripeConfig = {
|
|
13
|
+
...incomingStripeConfig,
|
|
76
14
|
// TODO: in the next major version, default this to `false`
|
|
77
|
-
rest:
|
|
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
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
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
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
})
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
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,"
|
|
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"}
|
package/dist/routes/rest.d.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
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:
|
|
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"}
|
package/dist/routes/rest.js
CHANGED
|
@@ -1,79 +1,36 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
-
|
|
34
|
+
};
|
|
35
|
+
|
|
79
36
|
//# sourceMappingURL=rest.js.map
|
package/dist/routes/rest.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
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 {
|
|
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"}
|