@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,93 +1,42 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import lodashGet from 'lodash.get';
|
|
2
|
+
import Stripe from 'stripe';
|
|
3
|
+
export const stripeProxy = async ({ stripeArgs, stripeMethod, stripeSecretKey })=>{
|
|
4
|
+
const stripe = new Stripe(stripeSecretKey, {
|
|
5
|
+
apiVersion: '2022-08-01',
|
|
6
|
+
appInfo: {
|
|
7
|
+
name: 'Stripe Payload Plugin',
|
|
8
|
+
url: 'https://payloadcms.com'
|
|
9
|
+
}
|
|
9
10
|
});
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
if (
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
11
|
+
if (typeof stripeMethod === 'string') {
|
|
12
|
+
const topLevelMethod = stripeMethod.split('.')[0];
|
|
13
|
+
const contextToBind = stripe[topLevelMethod];
|
|
14
|
+
// NOTE: 'lodashGet' uses dot notation to get the property of an object
|
|
15
|
+
// NOTE: Stripe API methods using reference "this" within their functions, so we need to bind context
|
|
16
|
+
const foundMethod = lodashGet(stripe, stripeMethod).bind(contextToBind);
|
|
17
|
+
if (typeof foundMethod === 'function') {
|
|
18
|
+
if (Array.isArray(stripeArgs)) {
|
|
19
|
+
try {
|
|
20
|
+
const stripeResponse = await foundMethod(...stripeArgs);
|
|
21
|
+
return {
|
|
22
|
+
data: stripeResponse,
|
|
23
|
+
status: 200
|
|
24
|
+
};
|
|
25
|
+
} catch (error) {
|
|
26
|
+
return {
|
|
27
|
+
message: `A Stripe API error has occurred: ${error}`,
|
|
28
|
+
status: 404
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
} else {
|
|
32
|
+
throw new Error(`Argument 'stripeArgs' must be an array.`);
|
|
32
33
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
} else {
|
|
35
|
+
throw Error(`The provided Stripe method of '${stripeMethod}' is not a part of the Stripe API.`);
|
|
36
|
+
}
|
|
37
|
+
} else {
|
|
38
|
+
throw Error('You must provide a Stripe method to call.');
|
|
36
39
|
}
|
|
37
40
|
};
|
|
38
|
-
|
|
39
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
-
};
|
|
41
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
-
exports.stripeProxy = void 0;
|
|
43
|
-
var lodash_get_1 = __importDefault(require("lodash.get"));
|
|
44
|
-
var stripe_1 = __importDefault(require("stripe"));
|
|
45
|
-
var stripeProxy = function (_a) {
|
|
46
|
-
var stripeSecretKey = _a.stripeSecretKey, stripeMethod = _a.stripeMethod, stripeArgs = _a.stripeArgs;
|
|
47
|
-
return __awaiter(void 0, void 0, void 0, function () {
|
|
48
|
-
var stripe, topLevelMethod, contextToBind, foundMethod, stripeResponse, error_1;
|
|
49
|
-
return __generator(this, function (_b) {
|
|
50
|
-
switch (_b.label) {
|
|
51
|
-
case 0:
|
|
52
|
-
stripe = new stripe_1.default(stripeSecretKey, {
|
|
53
|
-
apiVersion: '2022-08-01',
|
|
54
|
-
appInfo: {
|
|
55
|
-
name: 'Stripe Payload Plugin',
|
|
56
|
-
url: 'https://payloadcms.com',
|
|
57
|
-
},
|
|
58
|
-
});
|
|
59
|
-
if (!(typeof stripeMethod === 'string')) return [3 /*break*/, 9];
|
|
60
|
-
topLevelMethod = stripeMethod.split('.')[0];
|
|
61
|
-
contextToBind = stripe[topLevelMethod];
|
|
62
|
-
foundMethod = (0, lodash_get_1.default)(stripe, stripeMethod).bind(contextToBind);
|
|
63
|
-
if (!(typeof foundMethod === 'function')) return [3 /*break*/, 7];
|
|
64
|
-
if (!Array.isArray(stripeArgs)) return [3 /*break*/, 5];
|
|
65
|
-
_b.label = 1;
|
|
66
|
-
case 1:
|
|
67
|
-
_b.trys.push([1, 3, , 4]);
|
|
68
|
-
return [4 /*yield*/, foundMethod.apply(void 0, stripeArgs)];
|
|
69
|
-
case 2:
|
|
70
|
-
stripeResponse = _b.sent();
|
|
71
|
-
return [2 /*return*/, {
|
|
72
|
-
status: 200,
|
|
73
|
-
data: stripeResponse,
|
|
74
|
-
}];
|
|
75
|
-
case 3:
|
|
76
|
-
error_1 = _b.sent();
|
|
77
|
-
return [2 /*return*/, {
|
|
78
|
-
status: 404,
|
|
79
|
-
message: "A Stripe API error has occurred: ".concat(error_1),
|
|
80
|
-
}];
|
|
81
|
-
case 4: return [3 /*break*/, 6];
|
|
82
|
-
case 5: throw new Error("Argument 'stripeArgs' must be an array.");
|
|
83
|
-
case 6: return [3 /*break*/, 8];
|
|
84
|
-
case 7: throw Error("The provided Stripe method of '".concat(stripeMethod, "' is not a part of the Stripe API."));
|
|
85
|
-
case 8: return [3 /*break*/, 10];
|
|
86
|
-
case 9: throw Error('You must provide a Stripe method to call.');
|
|
87
|
-
case 10: return [2 /*return*/];
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
});
|
|
91
|
-
};
|
|
92
|
-
exports.stripeProxy = stripeProxy;
|
|
41
|
+
|
|
93
42
|
//# sourceMappingURL=stripeProxy.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/stripeProxy.ts"],"sourcesContent":["import lodashGet from 'lodash.get'\nimport Stripe from 'stripe'\n\nimport type { StripeProxy } from '../types.js'\n\nexport const stripeProxy: StripeProxy = async ({ stripeArgs, stripeMethod, stripeSecretKey }) => {\n const stripe = new Stripe(stripeSecretKey, {\n apiVersion: '2022-08-01',\n appInfo: {\n name: 'Stripe Payload Plugin',\n url: 'https://payloadcms.com',\n },\n })\n\n if (typeof stripeMethod === 'string') {\n const topLevelMethod = stripeMethod.split('.')[0] as keyof Stripe\n const contextToBind = stripe[topLevelMethod]\n // NOTE: 'lodashGet' uses dot notation to get the property of an object\n // NOTE: Stripe API methods using reference \"this\" within their functions, so we need to bind context\n const foundMethod = lodashGet(stripe, stripeMethod).bind(contextToBind)\n\n if (typeof foundMethod === 'function') {\n if (Array.isArray(stripeArgs)) {\n try {\n const stripeResponse = await foundMethod(...stripeArgs)\n return {\n data: stripeResponse,\n status: 200,\n }\n } catch (error: unknown) {\n return {\n message: `A Stripe API error has occurred: ${error}`,\n status: 404,\n }\n }\n } else {\n throw new Error(`Argument 'stripeArgs' must be an array.`)\n }\n } else {\n throw Error(\n `The provided Stripe method of '${stripeMethod}' is not a part of the Stripe API.`,\n )\n }\n } else {\n throw Error('You must provide a Stripe method to call.')\n }\n}\n"],"names":["lodashGet","Stripe","stripeProxy","stripeArgs","stripeMethod","stripeSecretKey","stripe","apiVersion","appInfo","name","url","topLevelMethod","split","contextToBind","foundMethod","bind","Array","isArray","stripeResponse","data","status","error","message","Error"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,OAAOA,eAAe,aAAY;AAClC,OAAOC,YAAY,SAAQ;AAI3B,OAAO,MAAMC,cAA2B,OAAO,EAAEC,UAAU,EAAEC,YAAY,EAAEC,eAAe,EAAE;IAC1F,MAAMC,SAAS,IAAIL,OAAOI,iBAAiB;QACzCE,YAAY;QACZC,SAAS;YACPC,MAAM;YACNC,KAAK;QACP;IACF;IAEA,IAAI,OAAON,iBAAiB,UAAU;QACpC,MAAMO,iBAAiBP,aAAaQ,KAAK,CAAC,IAAI,CAAC,EAAE;QACjD,MAAMC,gBAAgBP,MAAM,CAACK,eAAe;QAC5C,uEAAuE;QACvE,qGAAqG;QACrG,MAAMG,cAAcd,UAAUM,QAAQF,cAAcW,IAAI,CAACF;QAEzD,IAAI,OAAOC,gBAAgB,YAAY;YACrC,IAAIE,MAAMC,OAAO,CAACd,aAAa;gBAC7B,IAAI;oBACF,MAAMe,iBAAiB,MAAMJ,eAAeX;oBAC5C,OAAO;wBACLgB,MAAMD;wBACNE,QAAQ;oBACV;gBACF,EAAE,OAAOC,OAAgB;oBACvB,OAAO;wBACLC,SAAS,CAAC,iCAAiC,EAAED,MAAM,CAAC;wBACpDD,QAAQ;oBACV;gBACF;YACF,OAAO;gBACL,MAAM,IAAIG,MAAM,CAAC,uCAAuC,CAAC;YAC3D;QACF,OAAO;YACL,MAAMA,MACJ,CAAC,+BAA+B,EAAEnB,aAAa,kCAAkC,CAAC;QAEtF;IACF,OAAO;QACL,MAAMmB,MAAM;IACd;AACF,EAAC"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import type { SanitizedStripeConfig, StripeWebhookHandler } from '../types';
|
|
1
|
+
import type { SanitizedStripeConfig, StripeWebhookHandler } from '../types.js';
|
|
2
2
|
type HandleCreatedOrUpdated = (args: Parameters<StripeWebhookHandler>[0] & {
|
|
3
|
-
syncConfig: SanitizedStripeConfig['sync'][0];
|
|
4
3
|
resourceType: string;
|
|
4
|
+
syncConfig: SanitizedStripeConfig['sync'][0];
|
|
5
5
|
}) => void;
|
|
6
6
|
export declare const handleCreatedOrUpdated: HandleCreatedOrUpdated;
|
|
7
7
|
export {};
|
|
8
|
+
//# sourceMappingURL=handleCreatedOrUpdated.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handleCreatedOrUpdated.d.ts","sourceRoot":"","sources":["../../src/webhooks/handleCreatedOrUpdated.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAI9E,KAAK,sBAAsB,GAAG,CAC5B,IAAI,EAAE,UAAU,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC,GAAG;IAC1C,YAAY,EAAE,MAAM,CAAA;IACpB,UAAU,EAAE,qBAAqB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAA;CAC7C,KACE,IAAI,CAAA;AAET,eAAO,MAAM,sBAAsB,EAAE,sBAsLpC,CAAA"}
|
|
@@ -1,201 +1,120 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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 };
|
|
1
|
+
import { v4 as uuid } from 'uuid';
|
|
2
|
+
import { deepen } from '../utilities/deepen.js';
|
|
3
|
+
export const handleCreatedOrUpdated = async (args)=>{
|
|
4
|
+
const { config: payloadConfig, event, payload, resourceType, stripeConfig, syncConfig } = args;
|
|
5
|
+
const { logs } = stripeConfig || {};
|
|
6
|
+
const stripeDoc = event?.data?.object || {};
|
|
7
|
+
const { id: stripeID, object: eventObject } = stripeDoc;
|
|
8
|
+
// NOTE: the Stripe API does not nest fields, everything is an object at the top level
|
|
9
|
+
// if the event object and resource type don't match, this change was not top-level
|
|
10
|
+
const isNestedChange = eventObject !== resourceType;
|
|
11
|
+
// let stripeID = docID;
|
|
12
|
+
// if (isNestedChange) {
|
|
13
|
+
// const parentResource = stripeDoc[resourceType];
|
|
14
|
+
// stripeID = parentResource;
|
|
15
|
+
// }
|
|
16
|
+
if (isNestedChange) {
|
|
17
|
+
if (logs) payload.logger.info(`- This change occurred on a nested field of ${resourceType}. Nested fields are not yet supported in auto-sync but can be manually setup.`);
|
|
47
18
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
case 0:
|
|
59
|
-
payload = args.payload, event = args.event, resourceType = args.resourceType, stripeConfig = args.stripeConfig, payloadConfig = args.config, syncConfig = args.syncConfig;
|
|
60
|
-
logs = (stripeConfig || {}).logs;
|
|
61
|
-
stripeDoc = ((_a = event === null || event === void 0 ? void 0 : event.data) === null || _a === void 0 ? void 0 : _a.object) || {};
|
|
62
|
-
stripeID = stripeDoc.id, eventObject = stripeDoc.object;
|
|
63
|
-
isNestedChange = eventObject !== resourceType;
|
|
64
|
-
// let stripeID = docID;
|
|
65
|
-
// if (isNestedChange) {
|
|
66
|
-
// const parentResource = stripeDoc[resourceType];
|
|
67
|
-
// stripeID = parentResource;
|
|
68
|
-
// }
|
|
69
|
-
if (isNestedChange) {
|
|
70
|
-
if (logs)
|
|
71
|
-
payload.logger.info("- This change occurred on a nested field of ".concat(resourceType, ". Nested fields are not yet supported in auto-sync but can be manually setup."));
|
|
19
|
+
if (!isNestedChange) {
|
|
20
|
+
if (logs) payload.logger.info(`- A new document was created or updated in Stripe, now syncing to Payload...`);
|
|
21
|
+
const collectionSlug = syncConfig?.collection;
|
|
22
|
+
const isAuthCollection = Boolean(payloadConfig?.collections?.find((collection)=>collection.slug === collectionSlug)?.auth);
|
|
23
|
+
// First, search for an existing document in Payload
|
|
24
|
+
const payloadQuery = await payload.find({
|
|
25
|
+
collection: collectionSlug,
|
|
26
|
+
where: {
|
|
27
|
+
stripeID: {
|
|
28
|
+
equals: stripeID
|
|
72
29
|
}
|
|
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
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
const foundDoc = payloadQuery.docs[0];
|
|
33
|
+
// combine all properties of the Stripe doc and match their respective fields within the document
|
|
34
|
+
let syncedData = syncConfig.fields.reduce((acc, field)=>{
|
|
35
|
+
const { fieldPath, stripeProperty } = field;
|
|
36
|
+
acc[fieldPath] = stripeDoc[stripeProperty];
|
|
37
|
+
return acc;
|
|
38
|
+
}, {});
|
|
39
|
+
syncedData = deepen({
|
|
40
|
+
...syncedData,
|
|
41
|
+
skipSync: true,
|
|
42
|
+
stripeID
|
|
43
|
+
});
|
|
44
|
+
if (!foundDoc) {
|
|
45
|
+
if (logs) payload.logger.info(`- No existing '${collectionSlug}' document found with Stripe ID: '${stripeID}', creating new...`);
|
|
46
|
+
// auth docs must use unique emails
|
|
47
|
+
let authDoc = null;
|
|
48
|
+
if (isAuthCollection) {
|
|
49
|
+
try {
|
|
50
|
+
if (stripeDoc?.email) {
|
|
51
|
+
const authQuery = await payload.find({
|
|
52
|
+
collection: collectionSlug,
|
|
53
|
+
where: {
|
|
54
|
+
email: {
|
|
55
|
+
equals: stripeDoc.email
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
authDoc = authQuery.docs[0];
|
|
60
|
+
if (authDoc) {
|
|
61
|
+
if (logs) payload.logger.info(`- Account already exists with e-mail: ${stripeDoc.email}, updating now...`);
|
|
62
|
+
// account exists by email, so update it instead
|
|
63
|
+
try {
|
|
64
|
+
await payload.update({
|
|
65
|
+
id: authDoc.id,
|
|
66
|
+
collection: collectionSlug,
|
|
67
|
+
data: syncedData
|
|
68
|
+
});
|
|
69
|
+
if (logs) payload.logger.info(`✅ Successfully updated '${collectionSlug}' document in Payload with ID: '${authDoc.id}.'`);
|
|
70
|
+
} catch (err) {
|
|
71
|
+
const msg = err instanceof Error ? err.message : err;
|
|
72
|
+
if (logs) payload.logger.error(`- Error updating existing '${collectionSlug}' document: ${msg}`);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
} else {
|
|
76
|
+
if (logs) payload.logger.error(`No email was provided from Stripe, cannot create new '${collectionSlug}' document.`);
|
|
77
|
+
}
|
|
78
|
+
} catch (error) {
|
|
79
|
+
const msg = error instanceof Error ? error.message : error;
|
|
80
|
+
if (logs) payload.logger.error(`Error looking up '${collectionSlug}' document in Payload: ${msg}`);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
if (!isAuthCollection || isAuthCollection && !authDoc) {
|
|
84
|
+
try {
|
|
85
|
+
if (logs) payload.logger.info(`- Creating new '${collectionSlug}' document in Payload with Stripe ID: '${stripeID}'.`);
|
|
86
|
+
// generate a strong, unique password for the new user
|
|
87
|
+
const password = uuid();
|
|
88
|
+
await payload.create({
|
|
89
|
+
collection: collectionSlug,
|
|
90
|
+
data: {
|
|
91
|
+
...syncedData,
|
|
92
|
+
password,
|
|
93
|
+
passwordConfirm: password
|
|
110
94
|
},
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
err_1 = _d.sent();
|
|
133
|
-
msg = err_1 instanceof Error ? err_1.message : err_1;
|
|
134
|
-
if (logs)
|
|
135
|
-
payload.logger.error("- Error updating existing '".concat(collectionSlug_1, "' document: ").concat(msg));
|
|
136
|
-
return [3 /*break*/, 7];
|
|
137
|
-
case 7: return [3 /*break*/, 9];
|
|
138
|
-
case 8:
|
|
139
|
-
if (logs)
|
|
140
|
-
payload.logger.error("No email was provided from Stripe, cannot create new '".concat(collectionSlug_1, "' document."));
|
|
141
|
-
_d.label = 9;
|
|
142
|
-
case 9: return [3 /*break*/, 11];
|
|
143
|
-
case 10:
|
|
144
|
-
error_1 = _d.sent();
|
|
145
|
-
msg = error_1 instanceof Error ? error_1.message : error_1;
|
|
146
|
-
if (logs)
|
|
147
|
-
payload.logger.error("Error looking up '".concat(collectionSlug_1, "' document in Payload: ").concat(msg));
|
|
148
|
-
return [3 /*break*/, 11];
|
|
149
|
-
case 11:
|
|
150
|
-
if (!(!isAuthCollection || (isAuthCollection && !authDoc))) return [3 /*break*/, 15];
|
|
151
|
-
_d.label = 12;
|
|
152
|
-
case 12:
|
|
153
|
-
_d.trys.push([12, 14, , 15]);
|
|
154
|
-
if (logs)
|
|
155
|
-
payload.logger.info("- Creating new '".concat(collectionSlug_1, "' document in Payload with Stripe ID: '").concat(stripeID, "'."));
|
|
156
|
-
password = (0, uuid_1.v4)();
|
|
157
|
-
return [4 /*yield*/, payload.create({
|
|
158
|
-
collection: collectionSlug_1,
|
|
159
|
-
data: __assign(__assign({}, syncedData), { password: password, passwordConfirm: password }),
|
|
160
|
-
disableVerificationEmail: isAuthCollection ? true : undefined,
|
|
161
|
-
})];
|
|
162
|
-
case 13:
|
|
163
|
-
_d.sent();
|
|
164
|
-
if (logs)
|
|
165
|
-
payload.logger.info("\u2705 Successfully created new '".concat(collectionSlug_1, "' document in Payload with Stripe ID: '").concat(stripeID, "'."));
|
|
166
|
-
return [3 /*break*/, 15];
|
|
167
|
-
case 14:
|
|
168
|
-
error_2 = _d.sent();
|
|
169
|
-
msg = error_2 instanceof Error ? error_2.message : error_2;
|
|
170
|
-
if (logs)
|
|
171
|
-
payload.logger.error("Error creating new document in Payload: ".concat(msg));
|
|
172
|
-
return [3 /*break*/, 15];
|
|
173
|
-
case 15: return [3 /*break*/, 20];
|
|
174
|
-
case 16:
|
|
175
|
-
if (logs)
|
|
176
|
-
payload.logger.info("- Existing '".concat(collectionSlug_1, "' document found in Payload with Stripe ID: '").concat(stripeID, "', updating now..."));
|
|
177
|
-
_d.label = 17;
|
|
178
|
-
case 17:
|
|
179
|
-
_d.trys.push([17, 19, , 20]);
|
|
180
|
-
return [4 /*yield*/, payload.update({
|
|
181
|
-
collection: collectionSlug_1,
|
|
182
|
-
id: foundDoc.id,
|
|
183
|
-
data: syncedData,
|
|
184
|
-
})];
|
|
185
|
-
case 18:
|
|
186
|
-
_d.sent();
|
|
187
|
-
if (logs)
|
|
188
|
-
payload.logger.info("\u2705 Successfully updated '".concat(collectionSlug_1, "' document in Payload from Stripe ID: '").concat(stripeID, "'."));
|
|
189
|
-
return [3 /*break*/, 20];
|
|
190
|
-
case 19:
|
|
191
|
-
error_3 = _d.sent();
|
|
192
|
-
msg = error_3 instanceof Error ? error_3.message : error_3;
|
|
193
|
-
if (logs)
|
|
194
|
-
payload.logger.error("Error updating '".concat(collectionSlug_1, "' document in Payload: ").concat(msg));
|
|
195
|
-
return [3 /*break*/, 20];
|
|
196
|
-
case 20: return [2 /*return*/];
|
|
95
|
+
disableVerificationEmail: isAuthCollection ? true : undefined
|
|
96
|
+
});
|
|
97
|
+
if (logs) payload.logger.info(`✅ Successfully created new '${collectionSlug}' document in Payload with Stripe ID: '${stripeID}'.`);
|
|
98
|
+
} catch (error) {
|
|
99
|
+
const msg = error instanceof Error ? error.message : error;
|
|
100
|
+
if (logs) payload.logger.error(`Error creating new document in Payload: ${msg}`);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
} else {
|
|
104
|
+
if (logs) payload.logger.info(`- Existing '${collectionSlug}' document found in Payload with Stripe ID: '${stripeID}', updating now...`);
|
|
105
|
+
try {
|
|
106
|
+
await payload.update({
|
|
107
|
+
id: foundDoc.id,
|
|
108
|
+
collection: collectionSlug,
|
|
109
|
+
data: syncedData
|
|
110
|
+
});
|
|
111
|
+
if (logs) payload.logger.info(`✅ Successfully updated '${collectionSlug}' document in Payload from Stripe ID: '${stripeID}'.`);
|
|
112
|
+
} catch (error) {
|
|
113
|
+
const msg = error instanceof Error ? error.message : error;
|
|
114
|
+
if (logs) payload.logger.error(`Error updating '${collectionSlug}' document in Payload: ${msg}`);
|
|
115
|
+
}
|
|
197
116
|
}
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
|
|
201
120
|
//# sourceMappingURL=handleCreatedOrUpdated.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handleCreatedOrUpdated.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AsB,0BAmLlC"}
|
|
1
|
+
{"version":3,"sources":["../../src/webhooks/handleCreatedOrUpdated.ts"],"sourcesContent":["import { v4 as uuid } from 'uuid'\n\nimport type { SanitizedStripeConfig, StripeWebhookHandler } from '../types.js'\n\nimport { deepen } from '../utilities/deepen.js'\n\ntype HandleCreatedOrUpdated = (\n args: Parameters<StripeWebhookHandler>[0] & {\n resourceType: string\n syncConfig: SanitizedStripeConfig['sync'][0]\n },\n) => void\n\nexport const handleCreatedOrUpdated: HandleCreatedOrUpdated = async (args) => {\n const { config: payloadConfig, event, payload, resourceType, stripeConfig, syncConfig } = args\n\n const { logs } = stripeConfig || {}\n\n const stripeDoc: any = event?.data?.object || {}\n\n const { id: stripeID, object: eventObject } = stripeDoc\n\n // NOTE: the Stripe API does not nest fields, everything is an object at the top level\n // if the event object and resource type don't match, this change was not top-level\n const isNestedChange = eventObject !== resourceType\n\n // let stripeID = docID;\n // if (isNestedChange) {\n // const parentResource = stripeDoc[resourceType];\n // stripeID = parentResource;\n // }\n\n if (isNestedChange) {\n if (logs)\n payload.logger.info(\n `- This change occurred on a nested field of ${resourceType}. Nested fields are not yet supported in auto-sync but can be manually setup.`,\n )\n }\n\n if (!isNestedChange) {\n if (logs)\n payload.logger.info(\n `- A new document was created or updated in Stripe, now syncing to Payload...`,\n )\n\n const collectionSlug = syncConfig?.collection\n\n const isAuthCollection = Boolean(\n payloadConfig?.collections?.find((collection) => collection.slug === collectionSlug)?.auth,\n )\n\n // First, search for an existing document in Payload\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 // combine all properties of the Stripe doc and match their respective fields within the document\n let syncedData = syncConfig.fields.reduce(\n (acc, field) => {\n const { fieldPath, stripeProperty } = field\n\n acc[fieldPath] = stripeDoc[stripeProperty]\n return acc\n },\n {} as Record<string, any>,\n )\n\n syncedData = deepen({\n ...syncedData,\n skipSync: true,\n stripeID,\n })\n\n if (!foundDoc) {\n if (logs)\n payload.logger.info(\n `- No existing '${collectionSlug}' document found with Stripe ID: '${stripeID}', creating new...`,\n )\n\n // auth docs must use unique emails\n let authDoc = null\n\n if (isAuthCollection) {\n try {\n if (stripeDoc?.email) {\n const authQuery = await payload.find({\n collection: collectionSlug,\n where: {\n email: {\n equals: stripeDoc.email,\n },\n },\n })\n\n authDoc = authQuery.docs[0] as any\n\n if (authDoc) {\n if (logs)\n payload.logger.info(\n `- Account already exists with e-mail: ${stripeDoc.email}, updating now...`,\n )\n\n // account exists by email, so update it instead\n try {\n await payload.update({\n id: authDoc.id,\n collection: collectionSlug,\n data: syncedData,\n })\n\n if (logs)\n payload.logger.info(\n `✅ Successfully updated '${collectionSlug}' document in Payload with ID: '${authDoc.id}.'`,\n )\n } catch (err: unknown) {\n const msg = err instanceof Error ? err.message : err\n if (logs)\n payload.logger.error(\n `- Error updating existing '${collectionSlug}' document: ${msg}`,\n )\n }\n }\n } else {\n if (logs)\n payload.logger.error(\n `No email was provided from Stripe, cannot create new '${collectionSlug}' document.`,\n )\n }\n } catch (error: unknown) {\n const msg = error instanceof Error ? error.message : error\n if (logs)\n payload.logger.error(`Error looking up '${collectionSlug}' document in Payload: ${msg}`)\n }\n }\n\n if (!isAuthCollection || (isAuthCollection && !authDoc)) {\n try {\n if (logs)\n payload.logger.info(\n `- Creating new '${collectionSlug}' document in Payload with Stripe ID: '${stripeID}'.`,\n )\n\n // generate a strong, unique password for the new user\n const password: string = uuid()\n\n await payload.create({\n collection: collectionSlug,\n data: {\n ...syncedData,\n password,\n passwordConfirm: password,\n },\n disableVerificationEmail: isAuthCollection ? true : undefined,\n })\n\n if (logs)\n payload.logger.info(\n `✅ Successfully created new '${collectionSlug}' document in Payload with Stripe ID: '${stripeID}'.`,\n )\n } catch (error: unknown) {\n const msg = error instanceof Error ? error.message : error\n if (logs) payload.logger.error(`Error creating new document in Payload: ${msg}`)\n }\n }\n } else {\n if (logs)\n payload.logger.info(\n `- Existing '${collectionSlug}' document found in Payload with Stripe ID: '${stripeID}', updating now...`,\n )\n\n try {\n await payload.update({\n id: foundDoc.id,\n collection: collectionSlug,\n data: syncedData,\n })\n\n if (logs)\n payload.logger.info(\n `✅ Successfully updated '${collectionSlug}' document in Payload from Stripe ID: '${stripeID}'.`,\n )\n } catch (error: unknown) {\n const msg = error instanceof Error ? error.message : error\n if (logs)\n payload.logger.error(`Error updating '${collectionSlug}' document in Payload: ${msg}`)\n }\n }\n }\n}\n"],"names":["v4","uuid","deepen","handleCreatedOrUpdated","args","config","payloadConfig","event","payload","resourceType","stripeConfig","syncConfig","logs","stripeDoc","data","object","id","stripeID","eventObject","isNestedChange","logger","info","collectionSlug","collection","isAuthCollection","Boolean","collections","find","slug","auth","payloadQuery","where","equals","foundDoc","docs","syncedData","fields","reduce","acc","field","fieldPath","stripeProperty","skipSync","authDoc","email","authQuery","update","err","msg","Error","message","error","password","create","passwordConfirm","disableVerificationEmail","undefined"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,SAASA,MAAMC,IAAI,QAAQ,OAAM;AAIjC,SAASC,MAAM,QAAQ,yBAAwB;AAS/C,OAAO,MAAMC,yBAAiD,OAAOC;IACnE,MAAM,EAAEC,QAAQC,aAAa,EAAEC,KAAK,EAAEC,OAAO,EAAEC,YAAY,EAAEC,YAAY,EAAEC,UAAU,EAAE,GAAGP;IAE1F,MAAM,EAAEQ,IAAI,EAAE,GAAGF,gBAAgB,CAAC;IAElC,MAAMG,YAAiBN,OAAOO,MAAMC,UAAU,CAAC;IAE/C,MAAM,EAAEC,IAAIC,QAAQ,EAAEF,QAAQG,WAAW,EAAE,GAAGL;IAE9C,sFAAsF;IACtF,mFAAmF;IACnF,MAAMM,iBAAiBD,gBAAgBT;IAEvC,wBAAwB;IAC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AAMO,QAAQ6C,MAAM,CAAC;wBACnB9B,YAAYD;wBACZR,MAAM;4BACJ,GAAGqB,UAAU;4BACbiB;4BACAE,iBAAiBF;wBACnB;wBACAG,0BAA0B/B,mBAAmB,OAAOgC;oBACtD;oBAEA,IAAI5C,MACFJ,QAAQY,MAAM,CAACC,IAAI,CACjB,CAAC,4BAA4B,EAAEC,eAAe,uCAAuC,EAAEL,SAAS,EAAE,CAAC;gBAEzG,EAAE,OAAOkC,OAAgB;oBACvB,MAAMH,MAAMG,iBAAiBF,QAAQE,MAAMD,OAAO,GAAGC;oBACrD,IAAIvC,MAAMJ,QAAQY,MAAM,CAAC+B,KAAK,CAAC,CAAC,wCAAwC,EAAEH,IAAI,CAAC;gBACjF;YACF;QACF,OAAO;YACL,IAAIpC,MACFJ,QAAQY,MAAM,CAACC,IAAI,CACjB,CAAC,YAAY,EAAEC,eAAe,6CAA6C,EAAEL,SAAS,kBAAkB,CAAC;YAG7G,IAAI;gBACF,MAAMT,QAAQsC,MAAM,CAAC;oBACnB9B,IAAIiB,SAASjB,EAAE;oBACfO,YAAYD;oBACZR,MAAMqB;gBACR;gBAEA,IAAIvB,MACFJ,QAAQY,MAAM,CAACC,IAAI,CACjB,CAAC,wBAAwB,EAAEC,eAAe,uCAAuC,EAAEL,SAAS,EAAE,CAAC;YAErG,EAAE,OAAOkC,OAAgB;gBACvB,MAAMH,MAAMG,iBAAiBF,QAAQE,MAAMD,OAAO,GAAGC;gBACrD,IAAIvC,MACFJ,QAAQY,MAAM,CAAC+B,KAAK,CAAC,CAAC,gBAAgB,EAAE7B,eAAe,uBAAuB,EAAE0B,IAAI,CAAC;YACzF;QACF;IACF;AACF,EAAC"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import type { SanitizedStripeConfig, StripeWebhookHandler } from '../types';
|
|
1
|
+
import type { SanitizedStripeConfig, StripeWebhookHandler } from '../types.js';
|
|
2
2
|
type HandleDeleted = (args: Parameters<StripeWebhookHandler>[0] & {
|
|
3
3
|
resourceType: string;
|
|
4
4
|
syncConfig: SanitizedStripeConfig['sync'][0];
|
|
5
5
|
}) => void;
|
|
6
6
|
export declare const handleDeleted: HandleDeleted;
|
|
7
7
|
export {};
|
|
8
|
+
//# sourceMappingURL=handleDeleted.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handleDeleted.d.ts","sourceRoot":"","sources":["../../src/webhooks/handleDeleted.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAE9E,KAAK,aAAa,GAAG,CACnB,IAAI,EAAE,UAAU,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC,GAAG;IAC1C,YAAY,EAAE,MAAM,CAAA;IACpB,UAAU,EAAE,qBAAqB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAA;CAC7C,KACE,IAAI,CAAA;AAET,eAAO,MAAM,aAAa,EAAE,aAyE3B,CAAA"}
|