@payloadcms/plugin-stripe 0.0.13 → 0.0.14
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 +11 -7
- package/dist/extendWebpackConfig.js +1 -1
- package/dist/extendWebpackConfig.js.map +1 -1
- package/dist/hooks/createNewInStripe.d.ts +1 -1
- package/dist/hooks/createNewInStripe.js +7 -5
- package/dist/hooks/createNewInStripe.js.map +1 -1
- package/dist/hooks/deleteFromStripe.d.ts +1 -1
- package/dist/hooks/deleteFromStripe.js +5 -4
- package/dist/hooks/deleteFromStripe.js.map +1 -1
- package/dist/hooks/syncExistingWithStripe.d.ts +1 -1
- package/dist/hooks/syncExistingWithStripe.js +5 -4
- package/dist/hooks/syncExistingWithStripe.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +103 -93
- package/dist/index.js.map +1 -1
- package/dist/mocks/serverModule.js.map +1 -1
- package/dist/routes/rest.d.ts +4 -4
- package/dist/routes/rest.js +6 -6
- package/dist/routes/rest.js.map +1 -1
- package/dist/routes/webhooks.d.ts +5 -5
- package/dist/routes/webhooks.js +11 -9
- package/dist/routes/webhooks.js.map +1 -1
- package/dist/types.d.ts +12 -11
- package/dist/utilities/deepen.js +4 -4
- package/dist/utilities/deepen.js.map +1 -1
- package/dist/utilities/stripeProxy.d.ts +1 -1
- package/dist/utilities/stripeProxy.js +3 -3
- package/dist/utilities/stripeProxy.js.map +1 -1
- package/dist/webhooks/handleCreatedOrUpdated.d.ts +1 -1
- package/dist/webhooks/handleCreatedOrUpdated.js +10 -6
- package/dist/webhooks/handleCreatedOrUpdated.js.map +1 -1
- package/dist/webhooks/handleDeleted.d.ts +1 -1
- package/dist/webhooks/handleDeleted.js +5 -4
- package/dist/webhooks/handleDeleted.js.map +1 -1
- package/dist/webhooks/index.d.ts +1 -1
- package/dist/webhooks/index.js.map +1 -1
- package/package.json +26 -6
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/@payloadcms/plugin-stripe)
|
|
4
4
|
|
|
5
|
-
A plugin for [Payload
|
|
5
|
+
A plugin for [Payload](https://github.com/payloadcms/payload) to connect [Stripe](https://stripe.com) and Payload.
|
|
6
6
|
|
|
7
7
|
Core features:
|
|
8
8
|
|
|
@@ -42,23 +42,27 @@ export default config;
|
|
|
42
42
|
|
|
43
43
|
### Options
|
|
44
44
|
|
|
45
|
-
- `stripeSecretKey
|
|
45
|
+
- `stripeSecretKey`: string
|
|
46
46
|
|
|
47
47
|
Required. Your Stripe secret key.
|
|
48
48
|
|
|
49
|
-
- `sync
|
|
49
|
+
- `sync`: array
|
|
50
50
|
|
|
51
51
|
Optional. An array of sync configs. This will automatically configure a sync between Payload collections and Stripe resources on create, delete, and update. See [sync](#sync) for more details.
|
|
52
52
|
|
|
53
|
-
- `stripeWebhooksEndpointSecret
|
|
53
|
+
- `stripeWebhooksEndpointSecret`: string
|
|
54
54
|
|
|
55
55
|
Optional. Your Stripe webhook endpoint secret. This is needed only if you wish to sync data _from_ Stripe _to_ Payload.
|
|
56
56
|
|
|
57
|
-
- `
|
|
57
|
+
- `rest`: boolean
|
|
58
|
+
|
|
59
|
+
Optional. When `true`, opens the `/api/stripe/rest` endpoint. See [endpoints](#endpoints) for more details.
|
|
60
|
+
|
|
61
|
+
- `webhooks`: object | function
|
|
58
62
|
|
|
59
63
|
Optional. Either a function to handle all webhooks events, or an object of Stripe webhook handlers, keyed to the name of the event. See [webhooks](#webhooks) for more details or for a list of all available webhooks, see [here](https://stripe.com/docs/cli/trigger#trigger-event).
|
|
60
64
|
|
|
61
|
-
- `logs
|
|
65
|
+
- `logs`: boolean
|
|
62
66
|
|
|
63
67
|
Optional. When `true`, logs sync events to the console as they happen.
|
|
64
68
|
|
|
@@ -121,7 +125,7 @@ The following custom endpoints are automatically opened for you:
|
|
|
121
125
|
|
|
122
126
|
- #### `POST /api/stripe/rest`
|
|
123
127
|
|
|
124
|
-
|
|
128
|
+
If `rest` is true, proxies the [Stripe REST API](https://stripe.com/docs/api) behind [Payload access control](https://payloadcms.com/docs/access-control/overview) and returns the result. If you need to proxy the API server-side, use the [stripeProxy](#node) function.
|
|
125
129
|
|
|
126
130
|
```js
|
|
127
131
|
const res = await fetch(`/api/stripe/rest`, {
|
|
@@ -24,7 +24,7 @@ var extendWebpackConfig = function (config) {
|
|
|
24
24
|
var existingWebpackConfig = typeof ((_b = config.admin) === null || _b === void 0 ? void 0 : _b.webpack) === 'function'
|
|
25
25
|
? config.admin.webpack(webpackConfig)
|
|
26
26
|
: webpackConfig;
|
|
27
|
-
return __assign(__assign({}, existingWebpackConfig), { resolve: __assign(__assign({}, (existingWebpackConfig.resolve || {})), { alias: __assign(__assign({}, (((_c = existingWebpackConfig.resolve) === null || _c === void 0 ? void 0 : _c.alias) ? existingWebpackConfig.resolve.alias : {})), (_a = {
|
|
27
|
+
return __assign(__assign({}, existingWebpackConfig), { resolve: __assign(__assign({}, (existingWebpackConfig.resolve || {})), { alias: __assign(__assign({}, (((_c = existingWebpackConfig.resolve) === null || _c === void 0 ? void 0 : _c.alias) ? existingWebpackConfig.resolve.alias : {})), (_a = { stripe: mockModulePath, express: mockModulePath }, _a[path_1.default.resolve(__dirname, './routes/rest')] = mockModulePath, _a[path_1.default.resolve(__dirname, './routes/webhooks')] = mockModulePath, _a[path_1.default.resolve(__dirname, './webhooks/handleWebhooks')] = mockModulePath, _a[path_1.default.resolve(__dirname, './hooks/createNewInStripe')] = mockModulePath, _a[path_1.default.resolve(__dirname, './hooks/deleteFromStripe')] = mockModulePath, _a[path_1.default.resolve(__dirname, './hooks/syncExistingWithStripe')] = mockModulePath, _a)) }) });
|
|
28
28
|
};
|
|
29
29
|
};
|
|
30
30
|
exports.extendWebpackConfig = extendWebpackConfig;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extendWebpackConfig.js","sourceRoot":"","sources":["../src/extendWebpackConfig.ts"],"names":[],"mappings":";;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BAyB7B"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { CollectionBeforeValidateHook, CollectionConfig } from 'payload/types';
|
|
2
|
-
import { StripeConfig } from '../types';
|
|
2
|
+
import type { StripeConfig } from '../types';
|
|
3
3
|
export type CollectionBeforeValidateHookWithArgs = (args: Parameters<CollectionBeforeValidateHook>[0] & {
|
|
4
4
|
collection?: CollectionConfig;
|
|
5
5
|
stripeConfig?: StripeConfig;
|
|
@@ -40,13 +40,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
40
40
|
};
|
|
41
41
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
42
|
exports.createNewInStripe = void 0;
|
|
43
|
-
var stripe_1 = __importDefault(require("stripe"));
|
|
44
43
|
var errors_1 = require("payload/errors");
|
|
44
|
+
var stripe_1 = __importDefault(require("stripe"));
|
|
45
45
|
var deepen_1 = require("../utilities/deepen");
|
|
46
46
|
var stripeSecretKey = process.env.STRIPE_SECRET_KEY;
|
|
47
47
|
var stripe = new stripe_1.default(stripeSecretKey || '', { apiVersion: '2022-08-01' });
|
|
48
48
|
var createNewInStripe = function (args) { return __awaiter(void 0, void 0, void 0, function () {
|
|
49
|
-
var req, operation, data, collection, stripeConfig, _a, sync, logs, payload, dataRef, collectionSlug_1, syncConfig, syncedFields, stripeResource, error_1, stripeResource, error_2;
|
|
49
|
+
var req, operation, data, collection, stripeConfig, _a, sync, logs, payload, dataRef, collectionSlug_1, syncConfig, syncedFields, stripeResource, error_1, msg, stripeResource, error_2, msg;
|
|
50
50
|
var _b, _c;
|
|
51
51
|
return __generator(this, function (_d) {
|
|
52
52
|
switch (_d.label) {
|
|
@@ -70,7 +70,7 @@ var createNewInStripe = function (args) { return __awaiter(void 0, void 0, void
|
|
|
70
70
|
// this will prevent webhook events from triggering an unnecessary sync / infinite loop
|
|
71
71
|
dataRef.skipSync = false;
|
|
72
72
|
collectionSlug_1 = (collection || {}).slug;
|
|
73
|
-
syncConfig = sync === null || sync === void 0 ? void 0 : sync.find(function (
|
|
73
|
+
syncConfig = sync === null || sync === void 0 ? void 0 : sync.find(function (conf) { return conf.collection === collectionSlug_1; });
|
|
74
74
|
if (!syncConfig) return [3 /*break*/, 9];
|
|
75
75
|
syncedFields = syncConfig.fields.reduce(function (acc, field) {
|
|
76
76
|
var fieldPath = field.fieldPath, stripeProperty = field.stripeProperty;
|
|
@@ -96,8 +96,9 @@ var createNewInStripe = function (args) { return __awaiter(void 0, void 0, void
|
|
|
96
96
|
return [3 /*break*/, 5];
|
|
97
97
|
case 4:
|
|
98
98
|
error_1 = _d.sent();
|
|
99
|
+
msg = error_1 instanceof Error ? error_1.message : error_1;
|
|
99
100
|
if (logs)
|
|
100
|
-
payload.logger.error("- Error creating Stripe document: ".concat(
|
|
101
|
+
payload.logger.error("- Error creating Stripe document: ".concat(msg));
|
|
101
102
|
return [3 /*break*/, 5];
|
|
102
103
|
case 5:
|
|
103
104
|
if (!(operation === 'create')) return [3 /*break*/, 9];
|
|
@@ -119,7 +120,8 @@ var createNewInStripe = function (args) { return __awaiter(void 0, void 0, void
|
|
|
119
120
|
return [3 /*break*/, 9];
|
|
120
121
|
case 8:
|
|
121
122
|
error_2 = _d.sent();
|
|
122
|
-
|
|
123
|
+
msg = error_2 instanceof Error ? error_2.message : error_2;
|
|
124
|
+
throw new errors_1.APIError("Failed to create new '".concat(syncConfig.stripeResourceType, "' resource in Stripe: ").concat(msg));
|
|
123
125
|
case 9: return [2 /*return*/, dataRef];
|
|
124
126
|
}
|
|
125
127
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createNewInStripe.js","sourceRoot":"","sources":["../../src/hooks/createNewInStripe.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"createNewInStripe.js","sourceRoot":"","sources":["../../src/hooks/createNewInStripe.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;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,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,4CAAqC,GAAG,CAAE,CAAC,CAAA;;;qBAK5E,CAAA,SAAS,KAAK,QAAQ,CAAA,EAAtB,wBAAsB;gBACxB,IAAI,IAAI;oBACN,OAAO,CAAC,MAAM,CAAC,IAAI,CACjB,iBAAU,gBAAc,yDAA+C,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,EAAE,8BAA2B,CAC3G,CAAA;;;;gBAGD,IAAI,IAAI;oBACN,OAAO,CAAC,MAAM,CAAC,IAAI,CACjB,0BAAmB,UAAU,CAAC,kBAAkB,4BAAyB,CAC1E,CAAA;gBAGoB,qBAAM,CAAA,MAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAG,UAAU,CAAC,kBAAkB,CAAC,0CAAE,MAAM,CAC1E,YAAmB,CACpB,CAAA,EAAA;;gBAFK,cAAc,GAAG,SAEtB;gBAED,IAAI,IAAI;oBACN,OAAO,CAAC,MAAM,CAAC,IAAI,CACjB,2CAA+B,UAAU,CAAC,kBAAkB,4CAAkC,cAAc,CAAC,EAAE,OAAI,CACpH,CAAA;gBAEH,OAAO,CAAC,QAAQ,GAAG,cAAc,CAAC,EAAE,CAAA;gBAEpC,+DAA+D;gBAC/D,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAA;;;;gBAEjB,GAAG,GAAG,OAAK,YAAY,KAAK,CAAC,CAAC,CAAC,OAAK,CAAC,OAAO,CAAC,CAAC,CAAC,OAAK,CAAA;gBAC1D,MAAM,IAAI,iBAAQ,CAChB,gCAAyB,UAAU,CAAC,kBAAkB,mCAAyB,GAAG,CAAE,CACrF,CAAA;oBAOX,sBAAO,OAAO,EAAA;;;KACf,CAAA;AAzGY,QAAA,iBAAiB,qBAyG7B"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { CollectionAfterDeleteHook, CollectionConfig } from 'payload/types';
|
|
2
|
-
import { StripeConfig } from '../types';
|
|
2
|
+
import type { StripeConfig } from '../types';
|
|
3
3
|
export type CollectionAfterDeleteHookWithArgs = (args: Parameters<CollectionAfterDeleteHook>[0] & {
|
|
4
4
|
collection?: CollectionConfig;
|
|
5
5
|
stripeConfig?: StripeConfig;
|
|
@@ -40,12 +40,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
40
40
|
};
|
|
41
41
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
42
|
exports.deleteFromStripe = void 0;
|
|
43
|
-
var stripe_1 = __importDefault(require("stripe"));
|
|
44
43
|
var errors_1 = require("payload/errors");
|
|
44
|
+
var stripe_1 = __importDefault(require("stripe"));
|
|
45
45
|
var stripeSecretKey = process.env.STRIPE_SECRET_KEY;
|
|
46
46
|
var stripe = new stripe_1.default(stripeSecretKey || '', { apiVersion: '2022-08-01' });
|
|
47
47
|
var deleteFromStripe = function (args) { return __awaiter(void 0, void 0, void 0, function () {
|
|
48
|
-
var req, doc, stripeConfig, collection, _a, logs, sync, payload, collectionSlug, syncConfig, found, error_1;
|
|
48
|
+
var req, doc, stripeConfig, collection, _a, logs, sync, payload, collectionSlug, syncConfig, found, error_1, msg;
|
|
49
49
|
var _b, _c;
|
|
50
50
|
return __generator(this, function (_d) {
|
|
51
51
|
switch (_d.label) {
|
|
@@ -59,7 +59,7 @@ var deleteFromStripe = function (args) { return __awaiter(void 0, void 0, void 0
|
|
|
59
59
|
if (!(process.env.NODE_ENV !== 'test')) return [3 /*break*/, 7];
|
|
60
60
|
if (logs)
|
|
61
61
|
payload.logger.info("- Deleting Stripe document with ID: '".concat(doc.stripeID, "'..."));
|
|
62
|
-
syncConfig = sync === null || sync === void 0 ? void 0 : sync.find(function (
|
|
62
|
+
syncConfig = sync === null || sync === void 0 ? void 0 : sync.find(function (conf) { return conf.collection === collectionSlug; });
|
|
63
63
|
if (!syncConfig) return [3 /*break*/, 7];
|
|
64
64
|
_d.label = 1;
|
|
65
65
|
case 1:
|
|
@@ -81,7 +81,8 @@ var deleteFromStripe = function (args) { return __awaiter(void 0, void 0, void 0
|
|
|
81
81
|
case 5: return [3 /*break*/, 7];
|
|
82
82
|
case 6:
|
|
83
83
|
error_1 = _d.sent();
|
|
84
|
-
|
|
84
|
+
msg = error_1 instanceof Error ? error_1.message : error_1;
|
|
85
|
+
throw new errors_1.APIError("Failed to delete Stripe document with ID: '".concat(doc.stripeID, "': ").concat(msg));
|
|
85
86
|
case 7: return [2 /*return*/];
|
|
86
87
|
}
|
|
87
88
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deleteFromStripe.js","sourceRoot":"","sources":["../../src/hooks/deleteFromStripe.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"deleteFromStripe.js","sourceRoot":"","sources":["../../src/hooks/deleteFromStripe.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yCAAyC;AAEzC,kDAA2B;AAI3B,IAAM,eAAe,GAAG,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAA;AACrD,IAAM,MAAM,GAAG,IAAI,gBAAM,CAAC,eAAe,IAAI,EAAE,EAAE,EAAE,UAAU,EAAE,YAAY,EAAE,CAAC,CAAA;AASvE,IAAM,gBAAgB,GAAsC,UAAM,IAAI;;;;;;gBACnE,GAAG,GAAoC,IAAI,IAAxC,EAAE,GAAG,GAA+B,IAAI,IAAnC,EAAE,YAAY,GAAiB,IAAI,aAArB,EAAE,UAAU,GAAK,IAAI,WAAT,CAAS;gBAE7C,KAAiB,YAAY,IAAI,EAAE,EAAjC,IAAI,UAAA,EAAE,IAAI,UAAA,CAAuB;gBAEjC,OAAO,GAAK,GAAG,QAAR,CAAQ;gBACT,cAAc,GAAK,CAAA,UAAU,IAAI,EAAE,CAAA,KAArB,CAAqB;gBAEjD,IAAI,IAAI;oBACN,OAAO,CAAC,MAAM,CAAC,IAAI,CACjB,6BAAsB,GAAG,aAAH,GA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KAIhG,CAAA;AAxCY,QAAA,gBAAgB,oBAwC5B"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { CollectionBeforeChangeHook, CollectionConfig } from 'payload/types';
|
|
2
|
-
import { StripeConfig } from '../types';
|
|
2
|
+
import type { StripeConfig } from '../types';
|
|
3
3
|
export type CollectionBeforeChangeHookWithArgs = (args: Parameters<CollectionBeforeChangeHook>[0] & {
|
|
4
4
|
collection?: CollectionConfig;
|
|
5
5
|
stripeConfig?: StripeConfig;
|
|
@@ -40,13 +40,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
40
40
|
};
|
|
41
41
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
42
|
exports.syncExistingWithStripe = void 0;
|
|
43
|
-
var stripe_1 = __importDefault(require("stripe"));
|
|
44
43
|
var errors_1 = require("payload/errors");
|
|
44
|
+
var stripe_1 = __importDefault(require("stripe"));
|
|
45
45
|
var deepen_1 = require("../utilities/deepen");
|
|
46
46
|
var stripeSecretKey = process.env.STRIPE_SECRET_KEY;
|
|
47
47
|
var stripe = new stripe_1.default(stripeSecretKey || '', { apiVersion: '2022-08-01' });
|
|
48
48
|
var syncExistingWithStripe = function (args) { return __awaiter(void 0, void 0, void 0, function () {
|
|
49
|
-
var req, operation, data, originalDoc, collection, stripeConfig, _a, logs, sync, payload, collectionSlug, syncConfig, syncedFields, stripeResource, error_1;
|
|
49
|
+
var req, operation, data, originalDoc, collection, stripeConfig, _a, logs, sync, payload, collectionSlug, syncConfig, syncedFields, stripeResource, error_1, msg;
|
|
50
50
|
var _b;
|
|
51
51
|
return __generator(this, function (_c) {
|
|
52
52
|
switch (_c.label) {
|
|
@@ -56,7 +56,7 @@ var syncExistingWithStripe = function (args) { return __awaiter(void 0, void 0,
|
|
|
56
56
|
payload = req.payload;
|
|
57
57
|
collectionSlug = (collection || {}).slug;
|
|
58
58
|
if (!(process.env.NODE_ENV !== 'test' && !data.skipSync)) return [3 /*break*/, 5];
|
|
59
|
-
syncConfig = sync === null || sync === void 0 ? void 0 : sync.find(function (
|
|
59
|
+
syncConfig = sync === null || sync === void 0 ? void 0 : sync.find(function (conf) { return conf.collection === collectionSlug; });
|
|
60
60
|
if (!syncConfig) return [3 /*break*/, 5];
|
|
61
61
|
if (!(operation === 'update')) return [3 /*break*/, 5];
|
|
62
62
|
syncedFields = syncConfig.fields.reduce(function (acc, field) {
|
|
@@ -86,7 +86,8 @@ var syncExistingWithStripe = function (args) { return __awaiter(void 0, void 0,
|
|
|
86
86
|
return [3 /*break*/, 5];
|
|
87
87
|
case 4:
|
|
88
88
|
error_1 = _c.sent();
|
|
89
|
-
|
|
89
|
+
msg = error_1 instanceof Error ? error_1.message : error_1;
|
|
90
|
+
throw new errors_1.APIError("Failed to sync document with ID: '".concat(data.id, "' to Stripe: ").concat(msg));
|
|
90
91
|
case 5:
|
|
91
92
|
// Set back to 'false' so that all changes continue to sync to Stripe, see note in './createNewInStripe.ts'
|
|
92
93
|
data.skipSync = false;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"syncExistingWithStripe.js","sourceRoot":"","sources":["../../src/hooks/syncExistingWithStripe.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"syncExistingWithStripe.js","sourceRoot":"","sources":["../../src/hooks/syncExistingWithStripe.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yCAAyC;AAEzC,kDAA2B;AAG3B,8CAA4C;AAE5C,IAAM,eAAe,GAAG,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAA;AACrD,IAAM,MAAM,GAAG,IAAI,gBAAM,CAAC,eAAe,IAAI,EAAE,EAAE,EAAE,UAAU,EAAE,YAAY,EAAE,CAAC,CAAA;AASvE,IAAM,sBAAsB,GAAuC,UAAM,IAAI;;;;;;gBAC1E,GAAG,GAA6D,IAAI,IAAjE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AChB,iDAAiD;gBACjD,IAAI,IAAI;oBAAE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,sDAAsD,CAAC,CAAA;;;gBAEtF,IAAI,IAAI;oBACN,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,iDAA0C,IAAI,CAAC,QAAQ,SAAM,CAAC,CAAA;;;;gBAG3D,qBAAM,CAAA,MAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAG,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,kBAAkB,CAAC,0CAAE,MAAM,CAC3E,IAAI,CAAC,QAAQ,EACb,YAAY,CACb,CAAA,EAAA;;gBAHK,cAAc,GAAG,SAGtB;gBAED,IAAI,IAAI;oBACN,OAAO,CAAC,MAAM,CAAC,IAAI,CACjB,+DAAmD,cAAc,CAAC,EAAE,OAAI,CACzE,CAAA;;;;gBAEG,GAAG,GAAG,OAAK,YAAY,KAAK,CAAC,CAAC,CAAC,OAAK,CAAC,OAAO,CAAC,CAAC,CAAC,OAAK,CAAA;gBAC1D,MAAM,IAAI,iBAAQ,CAAC,4CAAqC,IAAI,CAAC,EAAE,0BAAgB,GAAG,CAAE,CAAC,CAAA;;gBAO/F,2GAA2G;gBAC3G,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAA;gBAErB,sBAAO,IAAI,EAAA;;;KACZ,CAAA;AA3DY,QAAA,sBAAsB,0BA2DlC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Config } from 'payload/config';
|
|
2
|
-
import { StripeConfig } from './types';
|
|
1
|
+
import type { Config } from 'payload/config';
|
|
2
|
+
import type { StripeConfig } from './types';
|
|
3
3
|
declare const stripePlugin: (incomingStripeConfig: StripeConfig) => (config: Config) => Config;
|
|
4
4
|
export default stripePlugin;
|
package/dist/index.js
CHANGED
|
@@ -59,108 +59,118 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
59
59
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
60
60
|
};
|
|
61
61
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
62
|
-
var rest_1 = require("./routes/rest");
|
|
63
|
-
var webhooks_1 = require("./routes/webhooks");
|
|
64
62
|
var express_1 = __importDefault(require("express"));
|
|
65
63
|
var extendWebpackConfig_1 = require("./extendWebpackConfig");
|
|
66
64
|
var createNewInStripe_1 = require("./hooks/createNewInStripe");
|
|
67
|
-
var syncExistingWithStripe_1 = require("./hooks/syncExistingWithStripe");
|
|
68
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
69
|
var LinkToDoc_1 = require("./ui/LinkToDoc");
|
|
70
|
-
var stripePlugin = function (incomingStripeConfig) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
handler: function (req, res, next) {
|
|
99
|
-
(0, rest_1.stripeREST)({
|
|
100
|
-
req: req,
|
|
101
|
-
res: res,
|
|
102
|
-
next: next,
|
|
103
|
-
stripeConfig: stripeConfig
|
|
104
|
-
});
|
|
70
|
+
var stripePlugin = function (incomingStripeConfig) {
|
|
71
|
+
return function (config) {
|
|
72
|
+
var _a;
|
|
73
|
+
var collections = config.collections;
|
|
74
|
+
// set config defaults here
|
|
75
|
+
var stripeConfig = __assign(__assign({}, incomingStripeConfig), {
|
|
76
|
+
// 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) || [] });
|
|
78
|
+
// NOTE: env variables are never passed to the client, but we need to know if `stripeSecretKey` is a test key
|
|
79
|
+
// unfortunately we must set the 'isTestKey' property on the config instead of using the following code:
|
|
80
|
+
// 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
|
+
],
|
|
105
98
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
});
|
|
118
|
-
], false), beforeChange: __spreadArray(__spreadArray([], ((existingHooks === null || existingHooks === void 0 ? void 0 : existingHooks.beforeChange) || []), true), [
|
|
119
|
-
function (args) { return __awaiter(void 0, void 0, void 0, function () {
|
|
120
|
-
return __generator(this, function (_a) {
|
|
121
|
-
return [2 /*return*/, (0, syncExistingWithStripe_1.syncExistingWithStripe)(__assign(__assign({}, args), { collection: collection, stripeConfig: stripeConfig }))];
|
|
122
|
-
});
|
|
123
|
-
}); }
|
|
124
|
-
], false), afterDelete: __spreadArray(__spreadArray([], ((existingHooks === null || existingHooks === void 0 ? void 0 : existingHooks.afterDelete) || []), true), [
|
|
125
|
-
function (args) { return __awaiter(void 0, void 0, void 0, function () {
|
|
126
|
-
return __generator(this, function (_a) {
|
|
127
|
-
return [2 /*return*/, (0, deleteFromStripe_1.deleteFromStripe)(__assign(__assign({}, args), { collection: collection, stripeConfig: stripeConfig }))];
|
|
128
|
-
});
|
|
129
|
-
}); }
|
|
130
|
-
], false) }), fields: __spreadArray(__spreadArray([], collection.fields, true), [
|
|
131
|
-
{
|
|
132
|
-
name: 'stripeID',
|
|
133
|
-
label: 'Stripe ID',
|
|
134
|
-
type: 'text',
|
|
135
|
-
saveToJWT: true,
|
|
136
|
-
admin: {
|
|
137
|
-
position: 'sidebar',
|
|
138
|
-
readOnly: true,
|
|
139
|
-
},
|
|
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
|
+
});
|
|
140
111
|
},
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
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; });
|
|
118
|
+
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
|
+
},
|
|
148
147
|
},
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
Field: function (args) { return (0, LinkToDoc_1.LinkToDoc)(__assign(__assign({}, args), { isTestKey: stripeConfig.isTestKey, stripeResourceType: syncConfig.stripeResourceType, nameOfIDField: 'stripeID' })); }
|
|
148
|
+
{
|
|
149
|
+
name: 'skipSync',
|
|
150
|
+
label: 'Skip Sync',
|
|
151
|
+
type: 'checkbox',
|
|
152
|
+
admin: {
|
|
153
|
+
position: 'sidebar',
|
|
154
|
+
readOnly: true,
|
|
157
155
|
},
|
|
158
156
|
},
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
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) });
|
|
170
|
+
}
|
|
171
|
+
return collection;
|
|
172
|
+
}) });
|
|
173
|
+
};
|
|
174
|
+
};
|
|
165
175
|
exports.default = stripePlugin;
|
|
166
176
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;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AI,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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serverModule.js","sourceRoot":"","sources":["../../src/mocks/serverModule.js"],"names":[],"mappings":";AAAA,MAAM,CAAC,OAAO,GAAG;IACf,GAAG,EAAE,
|
|
1
|
+
{"version":3,"file":"serverModule.js","sourceRoot":"","sources":["../../src/mocks/serverModule.js"],"names":[],"mappings":";AAAA,MAAM,CAAC,OAAO,GAAG;IACf,GAAG,EAAE,cAAO,CAAC;IACb,GAAG,EAAE,cAAO,CAAC;CACd,CAAA"}
|
package/dist/routes/rest.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import type { Response } from 'express';
|
|
2
|
+
import type { PayloadRequest } from 'payload/types';
|
|
3
|
+
import type { StripeConfig } from '../types';
|
|
4
4
|
export declare const stripeREST: (args: {
|
|
5
5
|
req: PayloadRequest;
|
|
6
6
|
res: Response;
|
|
7
7
|
next: any;
|
|
8
8
|
stripeConfig: StripeConfig;
|
|
9
|
-
}) => Promise<
|
|
9
|
+
}) => Promise<any>;
|
package/dist/routes/rest.js
CHANGED
|
@@ -40,24 +40,24 @@ exports.stripeREST = void 0;
|
|
|
40
40
|
var errors_1 = require("payload/errors");
|
|
41
41
|
var stripeProxy_1 = require("../utilities/stripeProxy");
|
|
42
42
|
var stripeREST = function (args) { return __awaiter(void 0, void 0, void 0, function () {
|
|
43
|
-
var req, res,
|
|
44
|
-
, stripeSecretKey, pluginRes, status_1, error_1, message;
|
|
43
|
+
var req, res, stripeConfig, payload, user, _a, stripeMethod, stripeArgs, stripeSecretKey, pluginRes, status_1, error_1, message;
|
|
45
44
|
return __generator(this, function (_b) {
|
|
46
45
|
switch (_b.label) {
|
|
47
46
|
case 0:
|
|
48
|
-
req = args.req, res = args.res,
|
|
47
|
+
req = args.req, res = args.res, stripeConfig = args.stripeConfig;
|
|
49
48
|
payload = req.payload, user = req.user, _a = req.body, stripeMethod = _a.stripeMethod, stripeArgs = _a.stripeArgs;
|
|
50
49
|
stripeSecretKey = stripeConfig.stripeSecretKey;
|
|
51
50
|
_b.label = 1;
|
|
52
51
|
case 1:
|
|
53
52
|
_b.trys.push([1, 3, , 4]);
|
|
54
|
-
if (!user) {
|
|
53
|
+
if (!user) {
|
|
54
|
+
// TODO: make this customizable from the config
|
|
55
55
|
throw new errors_1.Forbidden();
|
|
56
56
|
}
|
|
57
57
|
return [4 /*yield*/, (0, stripeProxy_1.stripeProxy)({
|
|
58
58
|
stripeSecretKey: stripeSecretKey,
|
|
59
59
|
stripeMethod: stripeMethod,
|
|
60
|
-
stripeArgs: stripeArgs
|
|
60
|
+
stripeArgs: stripeArgs,
|
|
61
61
|
})];
|
|
62
62
|
case 2:
|
|
63
63
|
pluginRes = _b.sent();
|
|
@@ -69,7 +69,7 @@ var stripeREST = function (args) { return __awaiter(void 0, void 0, void 0, func
|
|
|
69
69
|
message = "An error has occurred in the Stripe plugin REST handler: '".concat(error_1, "'");
|
|
70
70
|
payload.logger.error(message);
|
|
71
71
|
return [2 /*return*/, res.status(500).json({
|
|
72
|
-
message: message
|
|
72
|
+
message: message,
|
|
73
73
|
})];
|
|
74
74
|
case 4: return [2 /*return*/];
|
|
75
75
|
}
|
package/dist/routes/rest.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rest.js","sourceRoot":"","sources":["../../src/routes/rest.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,
|
|
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,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import type { Response } from 'express';
|
|
2
|
+
import type { Config as PayloadConfig } from 'payload/config';
|
|
3
|
+
import type { PayloadRequest } from 'payload/dist/types';
|
|
4
|
+
import type { StripeConfig } from '../types';
|
|
5
5
|
export declare const stripeWebhooks: (args: {
|
|
6
6
|
req: PayloadRequest;
|
|
7
7
|
res: Response;
|
|
8
8
|
next: any;
|
|
9
9
|
config: PayloadConfig;
|
|
10
10
|
stripeConfig: StripeConfig;
|
|
11
|
-
}) => Promise<
|
|
11
|
+
}) => Promise<any>;
|
package/dist/routes/webhooks.js
CHANGED
|
@@ -43,11 +43,11 @@ exports.stripeWebhooks = void 0;
|
|
|
43
43
|
var stripe_1 = __importDefault(require("stripe"));
|
|
44
44
|
var webhooks_1 = require("../webhooks");
|
|
45
45
|
var stripeWebhooks = function (args) { return __awaiter(void 0, void 0, void 0, function () {
|
|
46
|
-
var req, res,
|
|
46
|
+
var req, res, config, stripeConfig, stripeSecretKey, stripeWebhooksEndpointSecret, webhooks, stripe, stripeSignature, event_1, msg, webhookEventHandler;
|
|
47
47
|
return __generator(this, function (_a) {
|
|
48
48
|
switch (_a.label) {
|
|
49
49
|
case 0:
|
|
50
|
-
req = args.req, res = args.res,
|
|
50
|
+
req = args.req, res = args.res, config = args.config, stripeConfig = args.stripeConfig;
|
|
51
51
|
stripeSecretKey = stripeConfig.stripeSecretKey, stripeWebhooksEndpointSecret = stripeConfig.stripeWebhooksEndpointSecret, webhooks = stripeConfig.webhooks;
|
|
52
52
|
if (!stripeWebhooksEndpointSecret) return [3 /*break*/, 2];
|
|
53
53
|
stripe = new stripe_1.default(stripeSecretKey, {
|
|
@@ -55,7 +55,7 @@ var stripeWebhooks = function (args) { return __awaiter(void 0, void 0, void 0,
|
|
|
55
55
|
appInfo: {
|
|
56
56
|
name: 'Stripe Payload Plugin',
|
|
57
57
|
url: 'https://payloadcms.com',
|
|
58
|
-
}
|
|
58
|
+
},
|
|
59
59
|
});
|
|
60
60
|
stripeSignature = req.headers['stripe-signature'];
|
|
61
61
|
if (!stripeSignature) return [3 /*break*/, 2];
|
|
@@ -63,7 +63,8 @@ var stripeWebhooks = function (args) { return __awaiter(void 0, void 0, void 0,
|
|
|
63
63
|
event_1 = stripe.webhooks.constructEvent(req.body, stripeSignature, stripeWebhooksEndpointSecret);
|
|
64
64
|
}
|
|
65
65
|
catch (err) {
|
|
66
|
-
|
|
66
|
+
msg = err instanceof Error ? err.message : err;
|
|
67
|
+
req.payload.logger.error("Error constructing Stripe event: ".concat(msg));
|
|
67
68
|
res.status(400);
|
|
68
69
|
}
|
|
69
70
|
if (!event_1) return [3 /*break*/, 2];
|
|
@@ -72,8 +73,10 @@ var stripeWebhooks = function (args) { return __awaiter(void 0, void 0, void 0,
|
|
|
72
73
|
event: event_1,
|
|
73
74
|
stripe: stripe,
|
|
74
75
|
config: config,
|
|
75
|
-
stripeConfig: stripeConfig
|
|
76
|
-
})
|
|
76
|
+
stripeConfig: stripeConfig,
|
|
77
|
+
})
|
|
78
|
+
// Fire external webhook handlers if they exist
|
|
79
|
+
];
|
|
77
80
|
case 1:
|
|
78
81
|
_a.sent();
|
|
79
82
|
// Fire external webhook handlers if they exist
|
|
@@ -83,7 +86,7 @@ var stripeWebhooks = function (args) { return __awaiter(void 0, void 0, void 0,
|
|
|
83
86
|
event: event_1,
|
|
84
87
|
stripe: stripe,
|
|
85
88
|
config: config,
|
|
86
|
-
stripeConfig: stripeConfig
|
|
89
|
+
stripeConfig: stripeConfig,
|
|
87
90
|
});
|
|
88
91
|
}
|
|
89
92
|
if (typeof webhooks === 'object') {
|
|
@@ -94,10 +97,9 @@ var stripeWebhooks = function (args) { return __awaiter(void 0, void 0, void 0,
|
|
|
94
97
|
event: event_1,
|
|
95
98
|
stripe: stripe,
|
|
96
99
|
config: config,
|
|
97
|
-
stripeConfig: stripeConfig
|
|
100
|
+
stripeConfig: stripeConfig,
|
|
98
101
|
});
|
|
99
102
|
}
|
|
100
|
-
;
|
|
101
103
|
}
|
|
102
104
|
_a.label = 2;
|
|
103
105
|
case 2:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webhooks.js","sourceRoot":"","sources":["../../src/routes/webhooks.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"webhooks.js","sourceRoot":"","sources":["../../src/routes/webhooks.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,kDAA2B;AAG3B,wCAA4C;AAErC,IAAM,cAAc,GAAG,UAAO,IAMpC;;;;;gBACS,GAAG,GAAgC,IAAI,IAApC,EAAE,GAAG,GAA2B,IAAI,IAA/B,EAAE,MAAM,GAAmB,IAAI,OAAvB,EAAE,YAAY,GAAK,IAAI,aAAT,CAAS;gBAEvC,eAAe,GAA6C,YAAY,gBAAzD,EAAE,4BAA4B,GAAe,YAAY,6BAA3B,EAAE,QAAQ,GAAK,YAAY,SAAjB,CAAiB;qBAE5E,4BAA4B,EAA5B,wBAA4B;gBACxB,MAAM,GAAG,IAAI,gB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,EAAE;wBAC7C,mBAAmB,CAAC;4BAClB,OAAO,EAAE,GAAG,CAAC,OAAO;4BACpB,KAAK,SAAA;4BACL,MAAM,QAAA;4BACN,MAAM,QAAA;4BACN,YAAY,cAAA;yBACb,CAAC,CAAA;qBACH;iBACF;;;gBAKP,GAAG,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAA;;;;KAC7B,CAAA;AA1EY,QAAA,cAAc,kBA0E1B"}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Payload } from
|
|
2
|
-
import { Config as PayloadConfig } from
|
|
3
|
-
import Stripe from
|
|
1
|
+
import type { Payload } from 'payload';
|
|
2
|
+
import type { Config as PayloadConfig } from 'payload/config';
|
|
3
|
+
import type Stripe from 'stripe';
|
|
4
4
|
export type StripeWebhookHandler<T = any> = (args: {
|
|
5
5
|
payload: Payload;
|
|
6
6
|
event: T;
|
|
@@ -8,27 +8,28 @@ export type StripeWebhookHandler<T = any> = (args: {
|
|
|
8
8
|
config: PayloadConfig;
|
|
9
9
|
stripeConfig?: StripeConfig;
|
|
10
10
|
}) => void;
|
|
11
|
-
export
|
|
11
|
+
export interface StripeWebhookHandlers {
|
|
12
12
|
[webhookName: string]: StripeWebhookHandler;
|
|
13
|
-
}
|
|
14
|
-
export
|
|
13
|
+
}
|
|
14
|
+
export interface FieldSyncConfig {
|
|
15
15
|
fieldPath: string;
|
|
16
16
|
stripeProperty: string;
|
|
17
|
-
}
|
|
18
|
-
export
|
|
17
|
+
}
|
|
18
|
+
export interface SyncConfig {
|
|
19
19
|
collection: string;
|
|
20
20
|
stripeResourceType: 'customers' | 'products';
|
|
21
21
|
stripeResourceTypeSingular: 'customer' | 'product';
|
|
22
22
|
fields: FieldSyncConfig[];
|
|
23
|
-
}
|
|
24
|
-
export
|
|
23
|
+
}
|
|
24
|
+
export interface StripeConfig {
|
|
25
25
|
stripeSecretKey: string;
|
|
26
26
|
isTestKey?: boolean;
|
|
27
27
|
stripeWebhooksEndpointSecret?: string;
|
|
28
|
+
rest?: boolean;
|
|
28
29
|
webhooks?: StripeWebhookHandler | StripeWebhookHandlers;
|
|
29
30
|
sync?: SyncConfig[];
|
|
30
31
|
logs?: boolean;
|
|
31
|
-
}
|
|
32
|
+
}
|
|
32
33
|
export type SanitizedStripeConfig = StripeConfig & {
|
|
33
34
|
sync: SyncConfig[];
|
|
34
35
|
};
|
package/dist/utilities/deepen.js
CHANGED
|
@@ -9,13 +9,13 @@ var deepen = function (obj) {
|
|
|
9
9
|
var value = obj[key];
|
|
10
10
|
var keys = key.split('.');
|
|
11
11
|
var current = result;
|
|
12
|
-
keys.forEach(function (
|
|
12
|
+
keys.forEach(function (k, index) {
|
|
13
13
|
if (index === keys.length - 1) {
|
|
14
|
-
current[
|
|
14
|
+
current[k] = value;
|
|
15
15
|
}
|
|
16
16
|
else {
|
|
17
|
-
current[
|
|
18
|
-
current = current[
|
|
17
|
+
current[k] = current[k] || {};
|
|
18
|
+
current = current[k];
|
|
19
19
|
}
|
|
20
20
|
});
|
|
21
21
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deepen.js","sourceRoot":"","sources":["../../src/utilities/deepen.ts"],"names":[],"mappings":";AAAA,6DAA6D;AAC7D,+EAA+E;;;AAExE,IAAM,MAAM,GAAG,UAAC,GAAwB;IAC7C,IAAM,MAAM,GAAwB,EAAE,
|
|
1
|
+
{"version":3,"file":"deepen.js","sourceRoot":"","sources":["../../src/utilities/deepen.ts"],"names":[],"mappings":";AAAA,6DAA6D;AAC7D,+EAA+E;;;AAExE,IAAM,MAAM,GAAG,UAAC,GAAwB;IAC7C,IAAM,MAAM,GAAwB,EAAE,CAAA;4BAE3B,GAAG;QACZ,IAAM,KAAK,GAAG,GAAG,CAAC,GAAG,CAAC,CAAA;QACtB,IAAM,IAAI,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;QAC3B,IAAI,OAAO,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,OAAO,CAAC,UAAC,CAAC,EAAE,KAAK;YACpB,IAAI,KAAK,KAAK,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE;gBAC7B,OAAO,CAAC,CAAC,CAAC,GAAG,KAAK,CAAA;aACnB;iBAAM;gBACL,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,IAAI,EAAE,CAAA;gBAC7B,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC,CAAA;aACrB;QACH,CAAC,CAAC,CAAA;;IAXJ,KAAK,IAAM,GAAG,IAAI,GAAG;gBAAV,GAAG;KAYb;IACD,OAAO,MAAM,CAAA;AACf,CAAC,CAAA;AAjBY,QAAA,MAAM,UAiBlB"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { StripeProxy } from '../types';
|
|
1
|
+
import type { StripeProxy } from '../types';
|
|
2
2
|
export declare const stripeProxy: StripeProxy;
|
|
@@ -54,7 +54,7 @@ var stripeProxy = function (_a) {
|
|
|
54
54
|
appInfo: {
|
|
55
55
|
name: 'Stripe Payload Plugin',
|
|
56
56
|
url: 'https://payloadcms.com',
|
|
57
|
-
}
|
|
57
|
+
},
|
|
58
58
|
});
|
|
59
59
|
if (!(typeof stripeMethod === 'string')) return [3 /*break*/, 9];
|
|
60
60
|
topLevelMethod = stripeMethod.split('.')[0];
|
|
@@ -70,13 +70,13 @@ var stripeProxy = function (_a) {
|
|
|
70
70
|
stripeResponse = _b.sent();
|
|
71
71
|
return [2 /*return*/, {
|
|
72
72
|
status: 200,
|
|
73
|
-
data: stripeResponse
|
|
73
|
+
data: stripeResponse,
|
|
74
74
|
}];
|
|
75
75
|
case 3:
|
|
76
76
|
error_1 = _b.sent();
|
|
77
77
|
return [2 /*return*/, {
|
|
78
78
|
status: 404,
|
|
79
|
-
message: "A Stripe API error has occurred: ".concat(error_1)
|
|
79
|
+
message: "A Stripe API error has occurred: ".concat(error_1),
|
|
80
80
|
}];
|
|
81
81
|
case 4: return [3 /*break*/, 6];
|
|
82
82
|
case 5: throw new Error("Argument 'stripeArgs' must be an array.");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stripeProxy.js","sourceRoot":"","sources":["../../src/utilities/stripeProxy.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"stripeProxy.js","sourceRoot":"","sources":["../../src/utilities/stripeProxy.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0DAAkC;AAClC,kDAA2B;AAIpB,IAAM,WAAW,GAAgB,UAAO,EAA6C;QAA3C,eAAe,qBAAA,EAAE,YAAY,kBAAA,EAAE,UAAU,gBAAA;;;;;;oBAClF,MAAM,GAAG,IAAI,gBAAM,CAAC,eAAe,EAAE;wBACzC,UAAU,EAAE,YAAY;wBACxB,OAAO,EAAE;4BACP,IAAI,EAAE,uBAAuB;4BAC7B,GAAG,EAAE,wBAAwB;yBAC9B;qBACF,CAAC,CAAA;yBAEE,CAAA,OAAO,YAAY,KAAK,QAAQ,CAAA,EAAhC,wBAAgC;oBAC5B,cAAc,GAAG,YAAY,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAiB,CAAA;oBAC3D,aAAa,GAAG,MAAM,CAAC,cAAc,CAAC,CAAA;oBAGtC,WAAW,GAAG,IAAA,oBAAS,EAAC,MAAM,EAAE,YAAY,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAA;yBAEnE,CAAA,OAAO,WAAW,KAAK,UAAU,CAAA,EAAjC,wBAAiC;yBAC/B,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,EAAzB,wBAAyB;;;;oBAEF,qBAAM,WAAW,eAAI,UAAU,GAAC;;oBAAjD,cAAc,GAAG,SAAgC;oBACvD,sBAAO;4BACL,MAAM,EAAE,GAAG;4BACX,IAAI,EAAE,cAAc;yBACrB,EAAA;;;oBAED,sBAAO;4BACL,MAAM,EAAE,GAAG;4BACX,OAAO,EAAE,2CAAoC,OAAK,CAAE;yBACrD,EAAA;;wBAGH,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAA;;wBAG5D,MAAM,KAAK,CACT,yCAAkC,YAAY,uCAAoC,CACnF,CAAA;;wBAGH,MAAM,KAAK,CAAC,2CAA2C,CAAC,CAAA;;;;;CAE3D,CAAA;AAzCY,QAAA,WAAW,eAyCvB"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SanitizedStripeConfig, StripeWebhookHandler } from '../types';
|
|
1
|
+
import type { SanitizedStripeConfig, StripeWebhookHandler } from '../types';
|
|
2
2
|
type HandleCreatedOrUpdated = (args: Parameters<StripeWebhookHandler>[0] & {
|
|
3
3
|
syncConfig: SanitizedStripeConfig['sync'][0];
|
|
4
4
|
resourceType: string;
|
|
@@ -48,10 +48,10 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
48
48
|
};
|
|
49
49
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
50
|
exports.handleCreatedOrUpdated = void 0;
|
|
51
|
-
var deepen_1 = require("../utilities/deepen");
|
|
52
51
|
var uuid_1 = require("uuid");
|
|
52
|
+
var deepen_1 = require("../utilities/deepen");
|
|
53
53
|
var handleCreatedOrUpdated = function (args) { return __awaiter(void 0, void 0, void 0, function () {
|
|
54
|
-
var payload, event, resourceType, stripeConfig, payloadConfig, syncConfig, logs, stripeDoc, stripeID, eventObject, isNestedChange, collectionSlug_1, isAuthCollection, payloadQuery, foundDoc, syncedData, authDoc, authQuery, err_1, error_1, password, error_2, error_3;
|
|
54
|
+
var payload, event, resourceType, stripeConfig, payloadConfig, syncConfig, logs, stripeDoc, stripeID, eventObject, isNestedChange, collectionSlug_1, isAuthCollection, payloadQuery, foundDoc, syncedData, authDoc, authQuery, err_1, msg, error_1, msg, password, error_2, msg, error_3, msg;
|
|
55
55
|
var _a, _b, _c;
|
|
56
56
|
return __generator(this, function (_d) {
|
|
57
57
|
switch (_d.label) {
|
|
@@ -130,8 +130,9 @@ var handleCreatedOrUpdated = function (args) { return __awaiter(void 0, void 0,
|
|
|
130
130
|
return [3 /*break*/, 7];
|
|
131
131
|
case 6:
|
|
132
132
|
err_1 = _d.sent();
|
|
133
|
+
msg = err_1 instanceof Error ? err_1.message : err_1;
|
|
133
134
|
if (logs)
|
|
134
|
-
payload.logger.error("- Error updating existing '".concat(collectionSlug_1, "' document: ").concat(
|
|
135
|
+
payload.logger.error("- Error updating existing '".concat(collectionSlug_1, "' document: ").concat(msg));
|
|
135
136
|
return [3 /*break*/, 7];
|
|
136
137
|
case 7: return [3 /*break*/, 9];
|
|
137
138
|
case 8:
|
|
@@ -141,8 +142,9 @@ var handleCreatedOrUpdated = function (args) { return __awaiter(void 0, void 0,
|
|
|
141
142
|
case 9: return [3 /*break*/, 11];
|
|
142
143
|
case 10:
|
|
143
144
|
error_1 = _d.sent();
|
|
145
|
+
msg = error_1 instanceof Error ? error_1.message : error_1;
|
|
144
146
|
if (logs)
|
|
145
|
-
payload.logger.error("Error looking up '".concat(collectionSlug_1, "' document in Payload: ").concat(
|
|
147
|
+
payload.logger.error("Error looking up '".concat(collectionSlug_1, "' document in Payload: ").concat(msg));
|
|
146
148
|
return [3 /*break*/, 11];
|
|
147
149
|
case 11:
|
|
148
150
|
if (!(!isAuthCollection || (isAuthCollection && !authDoc))) return [3 /*break*/, 15];
|
|
@@ -164,8 +166,9 @@ var handleCreatedOrUpdated = function (args) { return __awaiter(void 0, void 0,
|
|
|
164
166
|
return [3 /*break*/, 15];
|
|
165
167
|
case 14:
|
|
166
168
|
error_2 = _d.sent();
|
|
169
|
+
msg = error_2 instanceof Error ? error_2.message : error_2;
|
|
167
170
|
if (logs)
|
|
168
|
-
payload.logger.error("Error creating new document in Payload: ".concat(
|
|
171
|
+
payload.logger.error("Error creating new document in Payload: ".concat(msg));
|
|
169
172
|
return [3 /*break*/, 15];
|
|
170
173
|
case 15: return [3 /*break*/, 20];
|
|
171
174
|
case 16:
|
|
@@ -186,8 +189,9 @@ var handleCreatedOrUpdated = function (args) { return __awaiter(void 0, void 0,
|
|
|
186
189
|
return [3 /*break*/, 20];
|
|
187
190
|
case 19:
|
|
188
191
|
error_3 = _d.sent();
|
|
192
|
+
msg = error_3 instanceof Error ? error_3.message : error_3;
|
|
189
193
|
if (logs)
|
|
190
|
-
payload.logger.error("Error updating '".concat(collectionSlug_1, "' document in Payload: ").concat(
|
|
194
|
+
payload.logger.error("Error updating '".concat(collectionSlug_1, "' document in Payload: ").concat(msg));
|
|
191
195
|
return [3 /*break*/, 20];
|
|
192
196
|
case 20: return [2 /*return*/];
|
|
193
197
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handleCreatedOrUpdated.js","sourceRoot":"","sources":["../../src/webhooks/handleCreatedOrUpdated.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"handleCreatedOrUpdated.js","sourceRoot":"","sources":["../../src/webhooks/handleCreatedOrUpdated.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6BAAiC;AAGjC,8CAA4C;AASrC,IAAM,sBAAsB,GAA2B,UAAM,IAAI;;;;;;gBAC9D,OAAO,GAA2E,IAAI,QAA/E,EAAE,KAAK,GAAoE,IAAI,MAAxE,EAAE,YAAY,GAAsD,IAAI,aAA1D,EAAE,YAAY,GAAwC,IAAI,aAA5C,EAAU,aAAa,GAAiB,IAAI,OAArB,EAAE,UAAU,GAAK,IAAI,WAAT,CAAS;gBAEtF,IAAI,GAAK,CAAA,YAAY,IAAI,EAAE,CAAA,KAAvB,CAAuB;gBAE7B,SAAS,GAAQ,CAAA,MAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,IAAI,0CAA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C,kDAA2C,GAAG,CAAE,CAAC,CAAA;;;;gBAIpF,IAAI,IAAI;oBACN,OAAO,CAAC,MAAM,CAAC,IAAI,CACjB,sBAAe,gBAAc,0DAAgD,QAAQ,uBAAoB,CAC1G,CAAA;;;;gBAGD,qBAAM,OAAO,CAAC,MAAM,CAAC;wBACnB,UAAU,EAAE,gBAAc;wBAC1B,EAAE,EAAE,QAAQ,CAAC,EAAE;wBACf,IAAI,EAAE,UAAU;qBACjB,CAAC,EAAA;;gBAJF,SAIE,CAAA;gBAEF,IAAI,IAAI;oBACN,OAAO,CAAC,MAAM,CAAC,IAAI,CACjB,uCAA2B,gBAAc,oDAA0C,QAAQ,OAAI,CAChG,CAAA;;;;gBAEG,GAAG,GAAG,OAAK,YAAY,KAAK,CAAC,CAAC,CAAC,OAAK,CAAC,OAAO,CAAC,CAAC,CAAC,OAAK,CAAA;gBAC1D,IAAI,IAAI;oBACN,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,0BAAmB,gBAAc,oCAA0B,GAAG,CAAE,CAAC,CAAA;;;;;KAI/F,CAAA;AAnLY,QAAA,sBAAsB,0BAmLlC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SanitizedStripeConfig, StripeWebhookHandler } from '../types';
|
|
1
|
+
import type { SanitizedStripeConfig, StripeWebhookHandler } from '../types';
|
|
2
2
|
type HandleDeleted = (args: Parameters<StripeWebhookHandler>[0] & {
|
|
3
3
|
resourceType: string;
|
|
4
4
|
syncConfig: SanitizedStripeConfig['sync'][0];
|
|
@@ -38,8 +38,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
exports.handleDeleted = void 0;
|
|
40
40
|
var handleDeleted = function (args) { return __awaiter(void 0, void 0, void 0, function () {
|
|
41
|
-
var payload, event, stripeConfig, resourceType, syncConfig, logs, collectionSlug, _a, stripeID, eventObject
|
|
42
|
-
, isNestedDelete, payloadQuery, foundDoc, error_1;
|
|
41
|
+
var payload, event, stripeConfig, resourceType, syncConfig, logs, collectionSlug, _a, stripeID, eventObject, isNestedDelete, payloadQuery, foundDoc, msg, error_1, msg;
|
|
43
42
|
var _b;
|
|
44
43
|
return __generator(this, function (_c) {
|
|
45
44
|
switch (_c.label) {
|
|
@@ -88,15 +87,17 @@ var handleDeleted = function (args) { return __awaiter(void 0, void 0, void 0, f
|
|
|
88
87
|
payload.logger.info("- \u2705 Successfully deleted Payload document with ID: '".concat(foundDoc.id, "'."));
|
|
89
88
|
}
|
|
90
89
|
catch (error) {
|
|
90
|
+
msg = error instanceof Error ? error.message : error;
|
|
91
91
|
if (logs)
|
|
92
|
-
payload.logger.error("Error deleting document: ".concat(
|
|
92
|
+
payload.logger.error("Error deleting document: ".concat(msg));
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
95
|
return [3 /*break*/, 4];
|
|
96
96
|
case 3:
|
|
97
97
|
error_1 = _c.sent();
|
|
98
|
+
msg = error_1 instanceof Error ? error_1.message : error_1;
|
|
98
99
|
if (logs)
|
|
99
|
-
payload.logger.error(
|
|
100
|
+
payload.logger.error("Error deleting document: ".concat(msg));
|
|
100
101
|
return [3 /*break*/, 4];
|
|
101
102
|
case 4: return [2 /*return*/];
|
|
102
103
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handleDeleted.js","sourceRoot":"","sources":["../../src/webhooks/handleDeleted.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"handleDeleted.js","sourceRoot":"","sources":["../../src/webhooks/handleDeleted.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AASO,IAAM,aAAa,GAAkB,UAAM,IAAI;;;;;;gBAC5C,OAAO,GAAoD,IAAI,QAAxD,EAAE,KAAK,GAA6C,IAAI,MAAjD,EAAE,YAAY,GAA+B,IAAI,aAAnC,EAA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AAC;4BACb,UAAU,EAAE,cAAc;4BAC1B,EAAE,EAAE,QAAQ,CAAC,EAAE;yBAChB,CAAC,CAAA;wBAEF,wHAAwH;wBACxH,iJAAiJ;wBACjJ,IAAI,IAAI;4BACN,OAAO,CAAC,MAAM,CAAC,IAAI,CACjB,mEAAuD,QAAQ,CAAC,EAAE,OAAI,CACvE,CAAA;qBACJ;oBAAC,OAAO,KAAc,EAAE;wBACjB,GAAG,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAA;wBAC1D,IAAI,IAAI;4BAAE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,mCAA4B,GAAG,CAAE,CAAC,CAAA;qBAClE;iBACF;;;;gBAEK,GAAG,GAAG,OAAK,YAAY,KAAK,CAAC,CAAC,CAAC,OAAK,CAAC,OAAO,CAAC,CAAC,CAAC,OAAK,CAAA;gBAC1D,IAAI,IAAI;oBAAE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,mCAA4B,GAAG,CAAE,CAAC,CAAA;;;;;KAGtE,CAAA;AAxEY,QAAA,aAAa,iBAwEzB"}
|
package/dist/webhooks/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { StripeWebhookHandler } from '../types';
|
|
1
|
+
import type { StripeWebhookHandler } from '../types';
|
|
2
2
|
export declare const handleWebhooks: StripeWebhookHandler;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/webhooks/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/webhooks/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,mEAAiE;AACjE,iDAA+C;AAExC,IAAM,cA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AEE;oBACP,wBAAK;iBACN;;;;;KAGN,CAAA;AAjDY,QAAA,cAAc,kBAiD1B"}
|
package/package.json
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/plugin-stripe",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.14",
|
|
4
4
|
"homepage:": "https://payloadcms.com",
|
|
5
5
|
"repository": "git@github.com:payloadcms/plugin-stripe.git",
|
|
6
|
-
"description": "Stripe plugin for Payload
|
|
6
|
+
"description": "Stripe plugin for Payload",
|
|
7
7
|
"main": "dist/index.js",
|
|
8
8
|
"types": "dist/index.d.ts",
|
|
9
9
|
"scripts": {
|
|
10
10
|
"build": "tsc",
|
|
11
|
-
"test": "echo \"Error: no test specified\" && exit 1"
|
|
11
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
12
|
+
"lint": "eslint src",
|
|
13
|
+
"lint:fix": "eslint --fix --ext .ts,.tsx src"
|
|
12
14
|
},
|
|
13
15
|
"keywords": [
|
|
14
16
|
"payload",
|
|
@@ -33,10 +35,28 @@
|
|
|
33
35
|
"uuid": "^9.0.0"
|
|
34
36
|
},
|
|
35
37
|
"devDependencies": {
|
|
36
|
-
"@types/express": "^4.17.13",
|
|
37
38
|
"@types/lodash.get": "^4.4.7",
|
|
38
|
-
"
|
|
39
|
-
"
|
|
39
|
+
"@payloadcms/eslint-config": "^0.0.1",
|
|
40
|
+
"@types/express": "^4.17.9",
|
|
41
|
+
"@types/node": "18.11.3",
|
|
42
|
+
"@types/react": "18.0.21",
|
|
43
|
+
"@typescript-eslint/eslint-plugin": "^5.51.0",
|
|
44
|
+
"@typescript-eslint/parser": "^5.51.0",
|
|
45
|
+
"copyfiles": "^2.4.1",
|
|
46
|
+
"cross-env": "^7.0.3",
|
|
47
|
+
"eslint": "^8.19.0",
|
|
48
|
+
"eslint-config-prettier": "^8.5.0",
|
|
49
|
+
"eslint-plugin-filenames": "^1.3.2",
|
|
50
|
+
"eslint-plugin-import": "2.25.4",
|
|
51
|
+
"eslint-plugin-prettier": "^4.0.0",
|
|
52
|
+
"eslint-plugin-react-hooks": "^4.6.0",
|
|
53
|
+
"eslint-plugin-simple-import-sort": "^10.0.0",
|
|
54
|
+
"nodemon": "^2.0.6",
|
|
55
|
+
"payload": "^1.8.2",
|
|
56
|
+
"prettier": "^2.7.1",
|
|
57
|
+
"react": "^18.0.0",
|
|
58
|
+
"ts-node": "^9.1.1",
|
|
59
|
+
"typescript": "^4.8.4"
|
|
40
60
|
},
|
|
41
61
|
"files": [
|
|
42
62
|
"dist",
|