@payloadcms/plugin-stripe 0.0.19 → 3.0.0-beta.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
|
@@ -1,107 +1,49 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
1
|
+
export const handleDeleted = async (args)=>{
|
|
2
|
+
const { event, payload, resourceType, stripeConfig, syncConfig } = args;
|
|
3
|
+
const { logs } = stripeConfig || {};
|
|
4
|
+
const collectionSlug = syncConfig?.collection;
|
|
5
|
+
const { id: stripeID, object: eventObject } = event?.data?.object || {};
|
|
6
|
+
// if the event object and resource type don't match, this deletion was not top-level
|
|
7
|
+
const isNestedDelete = eventObject !== resourceType;
|
|
8
|
+
if (isNestedDelete) {
|
|
9
|
+
if (logs) payload.logger.info(`- This deletion occurred on a nested field of ${resourceType}. Nested fields are not yet supported.`);
|
|
36
10
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
case 0:
|
|
46
|
-
payload = args.payload, event = args.event, stripeConfig = args.stripeConfig, resourceType = args.resourceType, syncConfig = args.syncConfig;
|
|
47
|
-
logs = (stripeConfig || {}).logs;
|
|
48
|
-
collectionSlug = syncConfig === null || syncConfig === void 0 ? void 0 : syncConfig.collection;
|
|
49
|
-
_a = ((_b = event === null || event === void 0 ? void 0 : event.data) === null || _b === void 0 ? void 0 : _b.object) || {}, stripeID = _a.id, eventObject = _a.object;
|
|
50
|
-
isNestedDelete = eventObject !== resourceType;
|
|
51
|
-
if (isNestedDelete) {
|
|
52
|
-
if (logs)
|
|
53
|
-
payload.logger.info("- This deletion occurred on a nested field of ".concat(resourceType, ". Nested fields are not yet supported."));
|
|
54
|
-
}
|
|
55
|
-
if (!!isNestedDelete) return [3 /*break*/, 4];
|
|
56
|
-
if (logs)
|
|
57
|
-
payload.logger.info("- A '".concat(resourceType, "' resource was deleted in Stripe, now deleting '").concat(collectionSlug, "' document in Payload with Stripe ID: '").concat(stripeID, "'..."));
|
|
58
|
-
_c.label = 1;
|
|
59
|
-
case 1:
|
|
60
|
-
_c.trys.push([1, 3, , 4]);
|
|
61
|
-
return [4 /*yield*/, payload.find({
|
|
62
|
-
collection: collectionSlug,
|
|
63
|
-
where: {
|
|
64
|
-
stripeID: {
|
|
65
|
-
equals: stripeID,
|
|
66
|
-
},
|
|
67
|
-
},
|
|
68
|
-
})];
|
|
69
|
-
case 2:
|
|
70
|
-
payloadQuery = _c.sent();
|
|
71
|
-
foundDoc = payloadQuery.docs[0];
|
|
72
|
-
if (!foundDoc) {
|
|
73
|
-
if (logs)
|
|
74
|
-
payload.logger.info("- Nothing to delete, no existing document found with Stripe ID: '".concat(stripeID, "'."));
|
|
75
|
-
}
|
|
76
|
-
if (foundDoc) {
|
|
77
|
-
if (logs)
|
|
78
|
-
payload.logger.info("- Deleting Payload document with ID: '".concat(foundDoc.id, "'..."));
|
|
79
|
-
try {
|
|
80
|
-
payload.delete({
|
|
81
|
-
collection: collectionSlug,
|
|
82
|
-
id: foundDoc.id,
|
|
83
|
-
});
|
|
84
|
-
// NOTE: the `afterDelete` hook will trigger, which will attempt to delete the document from Stripe and safely error out
|
|
85
|
-
// There is no known way of preventing this from happening. In other hooks we use the `skipSync` field, but here the document is already deleted.
|
|
86
|
-
if (logs)
|
|
87
|
-
payload.logger.info("- \u2705 Successfully deleted Payload document with ID: '".concat(foundDoc.id, "'."));
|
|
88
|
-
}
|
|
89
|
-
catch (error) {
|
|
90
|
-
msg = error instanceof Error ? error.message : error;
|
|
91
|
-
if (logs)
|
|
92
|
-
payload.logger.error("Error deleting document: ".concat(msg));
|
|
11
|
+
if (!isNestedDelete) {
|
|
12
|
+
if (logs) payload.logger.info(`- A '${resourceType}' resource was deleted in Stripe, now deleting '${collectionSlug}' document in Payload with Stripe ID: '${stripeID}'...`);
|
|
13
|
+
try {
|
|
14
|
+
const payloadQuery = await payload.find({
|
|
15
|
+
collection: collectionSlug,
|
|
16
|
+
where: {
|
|
17
|
+
stripeID: {
|
|
18
|
+
equals: stripeID
|
|
93
19
|
}
|
|
94
20
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
21
|
+
});
|
|
22
|
+
const foundDoc = payloadQuery.docs[0];
|
|
23
|
+
if (!foundDoc) {
|
|
24
|
+
if (logs) payload.logger.info(`- Nothing to delete, no existing document found with Stripe ID: '${stripeID}'.`);
|
|
25
|
+
}
|
|
26
|
+
if (foundDoc) {
|
|
27
|
+
if (logs) payload.logger.info(`- Deleting Payload document with ID: '${foundDoc.id}'...`);
|
|
28
|
+
try {
|
|
29
|
+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
30
|
+
payload.delete({
|
|
31
|
+
id: foundDoc.id,
|
|
32
|
+
collection: collectionSlug
|
|
33
|
+
});
|
|
34
|
+
// NOTE: the `afterDelete` hook will trigger, which will attempt to delete the document from Stripe and safely error out
|
|
35
|
+
// There is no known way of preventing this from happening. In other hooks we use the `skipSync` field, but here the document is already deleted.
|
|
36
|
+
if (logs) payload.logger.info(`- ✅ Successfully deleted Payload document with ID: '${foundDoc.id}'.`);
|
|
37
|
+
} catch (error) {
|
|
38
|
+
const msg = error instanceof Error ? error.message : error;
|
|
39
|
+
if (logs) payload.logger.error(`Error deleting document: ${msg}`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
} catch (error) {
|
|
43
|
+
const msg = error instanceof Error ? error.message : error;
|
|
44
|
+
if (logs) payload.logger.error(`Error deleting document: ${msg}`);
|
|
103
45
|
}
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
|
|
107
49
|
//# sourceMappingURL=handleDeleted.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../../src/webhooks/handleDeleted.ts"],"sourcesContent":["import type { SanitizedStripeConfig, StripeWebhookHandler } from '../types.js'\n\ntype HandleDeleted = (\n args: Parameters<StripeWebhookHandler>[0] & {\n resourceType: string\n syncConfig: SanitizedStripeConfig['sync'][0]\n },\n) => void\n\nexport const handleDeleted: HandleDeleted = async (args) => {\n const { event, payload, resourceType, stripeConfig, syncConfig } = args\n\n const { logs } = stripeConfig || {}\n\n const collectionSlug = syncConfig?.collection\n\n const {\n id: stripeID,\n object: eventObject, // use this to determine if this is a nested field\n }: any = event?.data?.object || {}\n\n // if the event object and resource type don't match, this deletion was not top-level\n const isNestedDelete = eventObject !== resourceType\n\n if (isNestedDelete) {\n if (logs)\n payload.logger.info(\n `- This deletion occurred on a nested field of ${resourceType}. Nested fields are not yet supported.`,\n )\n }\n\n if (!isNestedDelete) {\n if (logs)\n payload.logger.info(\n `- A '${resourceType}' resource was deleted in Stripe, now deleting '${collectionSlug}' document in Payload with Stripe ID: '${stripeID}'...`,\n )\n\n try {\n const payloadQuery = await payload.find({\n collection: collectionSlug,\n where: {\n stripeID: {\n equals: stripeID,\n },\n },\n })\n\n const foundDoc = payloadQuery.docs[0] as any\n\n if (!foundDoc) {\n if (logs)\n payload.logger.info(\n `- Nothing to delete, no existing document found with Stripe ID: '${stripeID}'.`,\n )\n }\n\n if (foundDoc) {\n if (logs) payload.logger.info(`- Deleting Payload document with ID: '${foundDoc.id}'...`)\n\n try {\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n payload.delete({\n id: foundDoc.id,\n collection: collectionSlug,\n })\n\n // NOTE: the `afterDelete` hook will trigger, which will attempt to delete the document from Stripe and safely error out\n // There is no known way of preventing this from happening. In other hooks we use the `skipSync` field, but here the document is already deleted.\n if (logs)\n payload.logger.info(\n `- ✅ Successfully deleted Payload document with ID: '${foundDoc.id}'.`,\n )\n } catch (error: unknown) {\n const msg = error instanceof Error ? error.message : error\n if (logs) payload.logger.error(`Error deleting document: ${msg}`)\n }\n }\n } catch (error: unknown) {\n const msg = error instanceof Error ? error.message : error\n if (logs) payload.logger.error(`Error deleting document: ${msg}`)\n }\n }\n}\n"],"names":["handleDeleted","args","event","payload","resourceType","stripeConfig","syncConfig","logs","collectionSlug","collection","id","stripeID","object","eventObject","data","isNestedDelete","logger","info","payloadQuery","find","where","equals","foundDoc","docs","delete","error","msg","Error","message"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AASA,OAAO,MAAMA,gBAA+B,OAAOC;IACjD,MAAM,EAAEC,KAAK,EAAEC,OAAO,EAAEC,YAAY,EAAEC,YAAY,EAAEC,UAAU,EAAE,GAAGL;IAEnE,MAAM,EAAEM,IAAI,EAAE,GAAGF,gBAAgB,CAAC;IAElC,MAAMG,iBAAiBF,YAAYG;IAEnC,MAAM,EACJC,IAAIC,QAAQ,EACZC,QAAQC,WAAW,EACpB,GAAQX,OAAOY,MAAMF,UAAU,CAAC;IAEjC,qFAAqF;IACrF,MAAMG,iBAAiBF,gBAAgBT;IAEvC,IAAIW,gBAAgB;QAClB,IAAIR,MACFJ,QAAQa,MAAM,CAACC,IAAI,CACjB,CAAC,8CAA8C,EAAEb,aAAa,sCAAsC,CAAC;IAE3G;IAEA,IAAI,CAACW,gBAAgB;QACnB,IAAIR,MACFJ,QAAQa,MAAM,CAACC,IAAI,CACjB,CAAC,KAAK,EAAEb,aAAa,gDAAgD,EAAEI,eAAe,uCAAuC,EAAEG,SAAS,IAAI,CAAC;QAGjJ,IAAI;YACF,MAAMO,eAAe,MAAMf,QAAQgB,IAAI,CAAC;gBACtCV,YAAYD;gBACZY,OAAO;oBACLT,UAAU;wBACRU,QAAQV;oBACV;gBACF;YACF;YAEA,MAAMW,WAAWJ,aAAaK,IAAI,CAAC,EAAE;YAErC,IAAI,CAACD,UAAU;gBACb,IAAIf,MACFJ,QAAQa,MAAM,CAACC,IAAI,CACjB,CAAC,iEAAiE,EAAEN,SAAS,EAAE,CAAC;YAEtF;YAEA,IAAIW,UAAU;gBACZ,IAAIf,MAAMJ,QAAQa,MAAM,CAACC,IAAI,CAAC,CAAC,sCAAsC,EAAEK,SAASZ,EAAE,CAAC,IAAI,CAAC;gBAExF,IAAI;oBACF,mEAAmE;oBACnEP,QAAQqB,MAAM,CAAC;wBACbd,IAAIY,SAASZ,EAAE;wBACfD,YAAYD;oBACd;oBAEA,wHAAwH;oBACxH,iJAAiJ;oBACjJ,IAAID,MACFJ,QAAQa,MAAM,CAACC,IAAI,CACjB,CAAC,oDAAoD,EAAEK,SAASZ,EAAE,CAAC,EAAE,CAAC;gBAE5E,EAAE,OAAOe,OAAgB;oBACvB,MAAMC,MAAMD,iBAAiBE,QAAQF,MAAMG,OAAO,GAAGH;oBACrD,IAAIlB,MAAMJ,QAAQa,MAAM,CAACS,KAAK,CAAC,CAAC,yBAAyB,EAAEC,IAAI,CAAC;gBAClE;YACF;QACF,EAAE,OAAOD,OAAgB;YACvB,MAAMC,MAAMD,iBAAiBE,QAAQF,MAAMG,OAAO,GAAGH;YACrD,IAAIlB,MAAMJ,QAAQa,MAAM,CAACS,KAAK,CAAC,CAAC,yBAAyB,EAAEC,IAAI,CAAC;QAClE;IACF;AACF,EAAC"}
|
package/dist/webhooks/index.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/webhooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAKvD,eAAO,MAAM,cAAc,EAAE,oBAiD5B,CAAA"}
|
package/dist/webhooks/index.js
CHANGED
|
@@ -1,95 +1,51 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
|
-
exports.handleWebhooks = void 0;
|
|
51
|
-
var handleCreatedOrUpdated_1 = require("./handleCreatedOrUpdated");
|
|
52
|
-
var handleDeleted_1 = require("./handleDeleted");
|
|
53
|
-
var handleWebhooks = function (args) { return __awaiter(void 0, void 0, void 0, function () {
|
|
54
|
-
var payload, event, stripeConfig, resourceType, method, syncConfig, _a;
|
|
55
|
-
var _b;
|
|
56
|
-
return __generator(this, function (_c) {
|
|
57
|
-
switch (_c.label) {
|
|
58
|
-
case 0:
|
|
59
|
-
payload = args.payload, event = args.event, stripeConfig = args.stripeConfig;
|
|
60
|
-
if (stripeConfig === null || stripeConfig === void 0 ? void 0 : stripeConfig.logs)
|
|
61
|
-
payload.logger.info("\uD83E\uDE9D Received Stripe '".concat(event.type, "' webhook event with ID: '").concat(event.id, "'."));
|
|
62
|
-
resourceType = event.type.split('.')[0];
|
|
63
|
-
method = event.type.split('.').pop();
|
|
64
|
-
syncConfig = (_b = stripeConfig === null || stripeConfig === void 0 ? void 0 : stripeConfig.sync) === null || _b === void 0 ? void 0 : _b.find(function (sync) { return sync.stripeResourceTypeSingular === resourceType; });
|
|
65
|
-
if (!syncConfig) return [3 /*break*/, 8];
|
|
66
|
-
_a = method;
|
|
67
|
-
switch (_a) {
|
|
68
|
-
case 'created': return [3 /*break*/, 1];
|
|
69
|
-
case 'updated': return [3 /*break*/, 3];
|
|
70
|
-
case 'deleted': return [3 /*break*/, 5];
|
|
1
|
+
import { handleCreatedOrUpdated } from './handleCreatedOrUpdated.js';
|
|
2
|
+
import { handleDeleted } from './handleDeleted.js';
|
|
3
|
+
export const handleWebhooks = (args)=>{
|
|
4
|
+
const { event, payload, stripeConfig } = args;
|
|
5
|
+
if (stripeConfig?.logs) payload.logger.info(`🪝 Received Stripe '${event.type}' webhook event with ID: '${event.id}'.`);
|
|
6
|
+
// could also traverse into event.data.object.object to get the type, but that seems unreliable
|
|
7
|
+
// use cli: `stripe resources` to see all available resources
|
|
8
|
+
const resourceType = event.type.split('.')[0];
|
|
9
|
+
const method = event.type.split('.').pop();
|
|
10
|
+
const syncConfig = stripeConfig?.sync?.find((sync)=>sync.stripeResourceTypeSingular === resourceType);
|
|
11
|
+
if (syncConfig) {
|
|
12
|
+
switch(method){
|
|
13
|
+
case 'created':
|
|
14
|
+
{
|
|
15
|
+
void handleCreatedOrUpdated({
|
|
16
|
+
...args,
|
|
17
|
+
resourceType,
|
|
18
|
+
stripeConfig,
|
|
19
|
+
syncConfig
|
|
20
|
+
});
|
|
21
|
+
break;
|
|
71
22
|
}
|
|
72
|
-
|
|
73
|
-
case 1: return [4 /*yield*/, (0, handleCreatedOrUpdated_1.handleCreatedOrUpdated)(__assign(__assign({}, args), { resourceType: resourceType, stripeConfig: stripeConfig, syncConfig: syncConfig }))];
|
|
74
|
-
case 2:
|
|
75
|
-
_c.sent();
|
|
76
|
-
return [3 /*break*/, 8];
|
|
77
|
-
case 3: return [4 /*yield*/, (0, handleCreatedOrUpdated_1.handleCreatedOrUpdated)(__assign(__assign({}, args), { resourceType: resourceType, stripeConfig: stripeConfig, syncConfig: syncConfig }))];
|
|
78
|
-
case 4:
|
|
79
|
-
_c.sent();
|
|
80
|
-
return [3 /*break*/, 8];
|
|
81
|
-
case 5: return [4 /*yield*/, (0, handleDeleted_1.handleDeleted)(__assign(__assign({}, args), { resourceType: resourceType, stripeConfig: stripeConfig, syncConfig: syncConfig }))];
|
|
82
|
-
case 6:
|
|
83
|
-
_c.sent();
|
|
84
|
-
return [3 /*break*/, 8];
|
|
85
|
-
case 7:
|
|
23
|
+
case 'updated':
|
|
86
24
|
{
|
|
87
|
-
|
|
25
|
+
void handleCreatedOrUpdated({
|
|
26
|
+
...args,
|
|
27
|
+
resourceType,
|
|
28
|
+
stripeConfig,
|
|
29
|
+
syncConfig
|
|
30
|
+
});
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
case 'deleted':
|
|
34
|
+
{
|
|
35
|
+
void handleDeleted({
|
|
36
|
+
...args,
|
|
37
|
+
resourceType,
|
|
38
|
+
stripeConfig,
|
|
39
|
+
syncConfig
|
|
40
|
+
});
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
43
|
+
default:
|
|
44
|
+
{
|
|
45
|
+
break;
|
|
88
46
|
}
|
|
89
|
-
_c.label = 8;
|
|
90
|
-
case 8: return [2 /*return*/];
|
|
91
47
|
}
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
|
|
95
51
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../../src/webhooks/index.ts"],"sourcesContent":["import type { StripeWebhookHandler } from '../types.js'\n\nimport { handleCreatedOrUpdated } from './handleCreatedOrUpdated.js'\nimport { handleDeleted } from './handleDeleted.js'\n\nexport const handleWebhooks: StripeWebhookHandler = (args) => {\n const { event, payload, stripeConfig } = args\n\n if (stripeConfig?.logs)\n payload.logger.info(`🪝 Received Stripe '${event.type}' webhook event with ID: '${event.id}'.`)\n\n // could also traverse into event.data.object.object to get the type, but that seems unreliable\n // use cli: `stripe resources` to see all available resources\n const resourceType = event.type.split('.')[0]\n const method = event.type.split('.').pop()\n\n const syncConfig = stripeConfig?.sync?.find(\n (sync) => sync.stripeResourceTypeSingular === resourceType,\n )\n\n if (syncConfig) {\n switch (method) {\n case 'created': {\n void handleCreatedOrUpdated({\n ...args,\n resourceType,\n stripeConfig,\n syncConfig,\n })\n break\n }\n case 'updated': {\n void handleCreatedOrUpdated({\n ...args,\n resourceType,\n stripeConfig,\n syncConfig,\n })\n break\n }\n case 'deleted': {\n void handleDeleted({\n ...args,\n resourceType,\n stripeConfig,\n syncConfig,\n })\n break\n }\n default: {\n break\n }\n }\n }\n}\n"],"names":["handleCreatedOrUpdated","handleDeleted","handleWebhooks","args","event","payload","stripeConfig","logs","logger","info","type","id","resourceType","split","method","pop","syncConfig","sync","find","stripeResourceTypeSingular"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAEA,SAASA,sBAAsB,QAAQ,8BAA6B;AACpE,SAASC,aAAa,QAAQ,qBAAoB;AAElD,OAAO,MAAMC,iBAAuC,CAACC;IACnD,MAAM,EAAEC,KAAK,EAAEC,OAAO,EAAEC,YAAY,EAAE,GAAGH;IAEzC,IAAIG,cAAcC,MAChBF,QAAQG,MAAM,CAACC,IAAI,CAAC,CAAC,oBAAoB,EAAEL,MAAMM,IAAI,CAAC,0BAA0B,EAAEN,MAAMO,EAAE,CAAC,EAAE,CAAC;IAEhG,+FAA+F;IAC/F,6DAA6D;IAC7D,MAAMC,eAAeR,MAAMM,IAAI,CAACG,KAAK,CAAC,IAAI,CAAC,EAAE;IAC7C,MAAMC,SAASV,MAAMM,IAAI,CAACG,KAAK,CAAC,KAAKE,GAAG;IAExC,MAAMC,aAAaV,cAAcW,MAAMC,KACrC,CAACD,OAASA,KAAKE,0BAA0B,KAAKP;IAGhD,IAAII,YAAY;QACd,OAAQF;YACN,KAAK;gBAAW;oBACd,KAAKd,uBAAuB;wBAC1B,GAAGG,IAAI;wBACPS;wBACAN;wBACAU;oBACF;oBACA;gBACF;YACA,KAAK;gBAAW;oBACd,KAAKhB,uBAAuB;wBAC1B,GAAGG,IAAI;wBACPS;wBACAN;wBACAU;oBACF;oBACA;gBACF;YACA,KAAK;gBAAW;oBACd,KAAKf,cAAc;wBACjB,GAAGE,IAAI;wBACPS;wBACAN;wBACAU;oBACF;oBACA;gBACF;YACA;gBAAS;oBACP;gBACF;QACF;IACF;AACF,EAAC"}
|
package/package.json
CHANGED
|
@@ -1,19 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/plugin-stripe",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"homepage:": "https://payloadcms.com",
|
|
5
|
-
"repository": "git@github.com:payloadcms/plugin-stripe.git",
|
|
3
|
+
"version": "3.0.0-beta.23",
|
|
6
4
|
"description": "Stripe plugin for Payload",
|
|
7
|
-
"main": "dist/index.js",
|
|
8
|
-
"types": "dist/index.d.ts",
|
|
9
|
-
"scripts": {
|
|
10
|
-
"build": "tsc",
|
|
11
|
-
"test": "echo \"Error: no test specified\" && exit 1",
|
|
12
|
-
"lint": "eslint src",
|
|
13
|
-
"lint:fix": "eslint --fix --ext .ts,.tsx src",
|
|
14
|
-
"clean": "rimraf dist",
|
|
15
|
-
"prepublishOnly": "yarn clean && yarn build"
|
|
16
|
-
},
|
|
17
5
|
"keywords": [
|
|
18
6
|
"payload",
|
|
19
7
|
"stripe",
|
|
@@ -25,44 +13,61 @@
|
|
|
25
13
|
"subscriptions",
|
|
26
14
|
"licensing"
|
|
27
15
|
],
|
|
28
|
-
"
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "https://github.com/payloadcms/payload.git",
|
|
19
|
+
"directory": "packages/plugin-stripe"
|
|
20
|
+
},
|
|
29
21
|
"license": "MIT",
|
|
30
|
-
"
|
|
31
|
-
|
|
22
|
+
"author": "dev@payloadcms.com",
|
|
23
|
+
"type": "module",
|
|
24
|
+
"exports": {
|
|
25
|
+
".": {
|
|
26
|
+
"import": "./dist/index.js",
|
|
27
|
+
"require": "./dist/index.js",
|
|
28
|
+
"types": "./dist/index.d.ts"
|
|
29
|
+
}
|
|
32
30
|
},
|
|
31
|
+
"main": "./dist/index.js",
|
|
32
|
+
"types": "./dist/index.d.ts",
|
|
33
|
+
"files": [
|
|
34
|
+
"dist",
|
|
35
|
+
"types.js",
|
|
36
|
+
"types.d.ts"
|
|
37
|
+
],
|
|
33
38
|
"dependencies": {
|
|
34
|
-
"@types/uuid": "^9.0.0",
|
|
35
39
|
"lodash.get": "^4.4.2",
|
|
36
40
|
"stripe": "^10.2.0",
|
|
37
|
-
"uuid": "^9.0.0"
|
|
41
|
+
"uuid": "^9.0.0",
|
|
42
|
+
"@payloadcms/ui": "3.0.0-beta.23"
|
|
38
43
|
},
|
|
39
44
|
"devDependencies": {
|
|
40
|
-
"@types/lodash.get": "^4.4.7",
|
|
41
|
-
"@payloadcms/eslint-config": "^0.0.1",
|
|
42
45
|
"@types/express": "^4.17.9",
|
|
43
|
-
"@types/
|
|
44
|
-
"@types/react": "18.
|
|
45
|
-
"@
|
|
46
|
-
"@
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"eslint-config
|
|
51
|
-
"eslint-plugin-filenames": "^1.3.2",
|
|
52
|
-
"eslint-plugin-import": "2.25.4",
|
|
53
|
-
"eslint-plugin-prettier": "^4.0.0",
|
|
54
|
-
"eslint-plugin-react-hooks": "^4.6.0",
|
|
55
|
-
"eslint-plugin-simple-import-sort": "^10.0.0",
|
|
56
|
-
"nodemon": "^2.0.6",
|
|
57
|
-
"payload": "^1.8.2",
|
|
58
|
-
"prettier": "^2.7.1",
|
|
59
|
-
"react": "^18.0.0",
|
|
60
|
-
"ts-node": "^9.1.1",
|
|
61
|
-
"typescript": "^4.8.4"
|
|
46
|
+
"@types/lodash.get": "^4.4.7",
|
|
47
|
+
"@types/react": "18.2.74",
|
|
48
|
+
"@types/uuid": "^9.0.0",
|
|
49
|
+
"@payloadcms/translations": "3.0.0-beta.23",
|
|
50
|
+
"@payloadcms/ui": "3.0.0-beta.23",
|
|
51
|
+
"payload": "3.0.0-beta.23",
|
|
52
|
+
"@payloadcms/next": "3.0.0-beta.23",
|
|
53
|
+
"@payloadcms/eslint-config": "1.1.1"
|
|
62
54
|
},
|
|
63
|
-
"
|
|
64
|
-
"
|
|
65
|
-
"
|
|
66
|
-
"
|
|
67
|
-
|
|
68
|
-
|
|
55
|
+
"peerDependencies": {
|
|
56
|
+
"@payloadcms/translations": "3.0.0-beta.23",
|
|
57
|
+
"@payloadcms/ui": "3.0.0-beta.23",
|
|
58
|
+
"payload": "3.0.0-beta.23"
|
|
59
|
+
},
|
|
60
|
+
"publishConfig": {
|
|
61
|
+
"registry": "https://registry.npmjs.org/"
|
|
62
|
+
},
|
|
63
|
+
"homepage:": "https://payloadcms.com",
|
|
64
|
+
"scripts": {
|
|
65
|
+
"build": "pnpm copyfiles && pnpm build:swc && pnpm build:types",
|
|
66
|
+
"build:swc": "swc ./src -d ./dist --config-file .swcrc",
|
|
67
|
+
"build:types": "tsc --emitDeclarationOnly --outDir dist",
|
|
68
|
+
"clean": "rimraf {dist,*.tsbuildinfo}",
|
|
69
|
+
"copyfiles": "copyfiles -u 1 \"src/**/*.{html,css,scss,ttf,woff,woff2,eot,svg,jpg,png,json}\" dist/",
|
|
70
|
+
"lint": "eslint src",
|
|
71
|
+
"lint:fix": "eslint --fix --ext .ts,.tsx src"
|
|
72
|
+
}
|
|
73
|
+
}
|
package/types.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './dist/types'
|
|
1
|
+
export * from './dist/types'
|
package/types.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
module.exports = require('./dist/types')
|
|
1
|
+
module.exports = require('./dist/types')
|
|
@@ -1,31 +0,0 @@
|
|
|
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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.extendWebpackConfig = void 0;
|
|
18
|
-
var path_1 = __importDefault(require("path"));
|
|
19
|
-
var mockModulePath = path_1.default.resolve(__dirname, 'mocks/serverModule.js');
|
|
20
|
-
var extendWebpackConfig = function (config) {
|
|
21
|
-
return function (webpackConfig) {
|
|
22
|
-
var _a;
|
|
23
|
-
var _b, _c;
|
|
24
|
-
var existingWebpackConfig = typeof ((_b = config.admin) === null || _b === void 0 ? void 0 : _b.webpack) === 'function'
|
|
25
|
-
? config.admin.webpack(webpackConfig)
|
|
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 = { 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
|
-
};
|
|
29
|
-
};
|
|
30
|
-
exports.extendWebpackConfig = extendWebpackConfig;
|
|
31
|
-
//# sourceMappingURL=extendWebpackConfig.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"extendWebpackConfig.js","sourceRoot":"","sources":["../src/extendWebpackConfig.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,8CAAuB;AAIvB,IAAM,cAAc,GAAG,cAAI,CAAC,OAAO,CAAC,SAAS,EAAE,uBAAuB,CAAC,CAAA;AAEhE,IAAM,mBAAmB,GAC9B,UAAC,MAAc;IACf,OAAA,UAAA,aAAa;;;QACX,IAAM,qBAAqB,GACzB,OAAO,CAAA,MAAA,MAAM,CAAC,KAAK,0CAAE,OAAO,CAAA,KAAK,UAAU;YACzC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,aAAa,CAAC;YACrC,CAAC,CAAC,aAAa,CAAA;QAEnB,6BACK,qBAAqB,KACxB,OAAO,wBACF,CAAC,qBAAqB,CAAC,OAAO,IAAI,EAAE,CAAC,KACxC,KAAK,wBACA,CAAC,CAAA,MAAA,qBAAqB,CAAC,OAAO,0CAAE,KAAK,EAAC,CAAC,CAAC,qBAAqB,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,WACpF,MAAM,EAAE,cAAc,EACtB,OAAO,EAAE,cAAc,OACtB,cAAI,CAAC,OAAO,CAAC,SAAS,EAAE,eAAe,CAAC,IAAG,cAAc,KACzD,cAAI,CAAC,OAAO,CAAC,SAAS,EAAE,mBAAmB,CAAC,IAAG,cAAc,KAC7D,cAAI,CAAC,OAAO,CAAC,SAAS,EAAE,2BAA2B,CAAC,IAAG,cAAc,KACrE,cAAI,CAAC,OAAO,CAAC,SAAS,EAAE,2BAA2B,CAAC,IAAG,cAAc,KACrE,cAAI,CAAC,OAAO,CAAC,SAAS,EAAE,0BAA0B,CAAC,IAAG,cAAc,KACpE,cAAI,CAAC,OAAO,CAAC,SAAS,EAAE,gCAAgC,CAAC,IAAG,cAAc,aAGhF;IACH,CAAC;AAvBD,CAuBC,CAAA;AAzBU,QAAA,mBAAmB,uBAyB7B"}
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|