@payloadcms/plugin-stripe 4.0.0-internal.d28e9fb → 4.0.0-internal.d3909a9
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/LICENSE.md +1 -1
- package/dist/admin.d.ts.map +1 -1
- package/dist/admin.js +4 -2
- package/dist/admin.js.map +1 -1
- package/dist/exports/client.d.ts +1 -1
- package/dist/exports/client.d.ts.map +1 -1
- package/dist/exports/client.js +1 -1
- package/dist/exports/client.js.map +1 -1
- package/dist/exports/types.d.ts +1 -1
- package/dist/exports/types.d.ts.map +1 -1
- package/dist/exports/types.js.map +1 -1
- package/dist/fields/getFields.d.ts.map +1 -1
- package/dist/fields/getFields.js +8 -0
- package/dist/fields/getFields.js.map +1 -1
- package/dist/hooks/createNewInStripe.d.ts.map +1 -1
- package/dist/hooks/createNewInStripe.js +6 -7
- package/dist/hooks/createNewInStripe.js.map +1 -1
- package/dist/hooks/syncExistingWithStripe.d.ts.map +1 -1
- package/dist/hooks/syncExistingWithStripe.js +6 -7
- package/dist/hooks/syncExistingWithStripe.js.map +1 -1
- package/dist/index.d.ts +1 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -4
- package/dist/index.js.map +1 -1
- package/dist/routes/rest.d.ts +3 -3
- package/dist/routes/rest.d.ts.map +1 -1
- package/dist/routes/rest.js +104 -27
- package/dist/routes/rest.js.map +1 -1
- package/dist/types.d.ts +10 -3
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/ui/LinkToDoc/index.css +26 -0
- package/dist/ui/LinkToDoc/index.d.ts +5 -0
- package/dist/ui/LinkToDoc/index.d.ts.map +1 -0
- package/dist/ui/LinkToDoc/index.js +45 -0
- package/dist/ui/LinkToDoc/index.js.map +1 -0
- package/dist/utilities/deepen.d.ts +6 -0
- package/dist/utilities/deepen.d.ts.map +1 -1
- package/dist/utilities/deepen.js +33 -3
- package/dist/utilities/deepen.js.map +1 -1
- package/dist/utilities/sanitizeStripeRESTConfig.d.ts +5 -0
- package/dist/utilities/sanitizeStripeRESTConfig.d.ts.map +1 -0
- package/dist/utilities/sanitizeStripeRESTConfig.js +25 -0
- package/dist/utilities/sanitizeStripeRESTConfig.js.map +1 -0
- package/dist/webhooks/handleCreatedOrUpdated.d.ts.map +1 -1
- package/dist/webhooks/handleCreatedOrUpdated.js +14 -9
- package/dist/webhooks/handleCreatedOrUpdated.js.map +1 -1
- package/dist/webhooks/handleDeleted.d.ts.map +1 -1
- package/dist/webhooks/handleDeleted.js +3 -1
- package/dist/webhooks/handleDeleted.js.map +1 -1
- package/package.json +28 -31
- package/dist/ui/LinkToDoc.d.ts +0 -3
- package/dist/ui/LinkToDoc.d.ts.map +0 -1
- package/dist/ui/LinkToDoc.js +0 -48
- package/dist/ui/LinkToDoc.js.map +0 -1
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
@layer payload-default {
|
|
2
|
+
.link-to-doc {
|
|
3
|
+
margin-bottom: var(--spacing-field);
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
.link-to-doc__header {
|
|
7
|
+
display: flex;
|
|
8
|
+
align-items: center;
|
|
9
|
+
width: fit-content;
|
|
10
|
+
gap: var(--spacer-1);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.link-to-doc__url {
|
|
14
|
+
overflow: hidden;
|
|
15
|
+
font-weight: 600;
|
|
16
|
+
text-overflow: ellipsis;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.link-to-doc__url a {
|
|
20
|
+
color: var(--color-text-secondary);
|
|
21
|
+
|
|
22
|
+
&:hover {
|
|
23
|
+
color: var(--color-text);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/ui/LinkToDoc/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAA;AAGjD,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,aAAa,CAAA;AAIpB,eAAO,MAAM,SAAS,EAAE,KAAK,CAAC,EAAE,CAAC,kBAAkB,CA6BlD,CAAA"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { CopyToClipboard, FieldLabel, useFormFields } from '@payloadcms/ui';
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import './index.css';
|
|
6
|
+
const baseClass = 'link-to-doc';
|
|
7
|
+
export const LinkToDoc = (props)=>{
|
|
8
|
+
const { field: { admin: { custom = {} } = {} } } = props;
|
|
9
|
+
const { isTestKey, nameOfIDField, stripeResourceType } = custom;
|
|
10
|
+
const field = useFormFields(([fields])=>fields && fields?.[nameOfIDField] || null);
|
|
11
|
+
const { value: stripeID } = field || {};
|
|
12
|
+
if (!stripeID) {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
const stripeEnv = isTestKey ? 'test/' : '';
|
|
16
|
+
const href = `https://dashboard.stripe.com/${stripeEnv}${stripeResourceType}/${stripeID}`;
|
|
17
|
+
return /*#__PURE__*/ _jsxs("div", {
|
|
18
|
+
className: baseClass,
|
|
19
|
+
children: [
|
|
20
|
+
/*#__PURE__*/ _jsxs("div", {
|
|
21
|
+
className: `${baseClass}__header`,
|
|
22
|
+
children: [
|
|
23
|
+
/*#__PURE__*/ _jsx(FieldLabel, {
|
|
24
|
+
htmlFor: baseClass,
|
|
25
|
+
label: "View in Stripe"
|
|
26
|
+
}),
|
|
27
|
+
/*#__PURE__*/ _jsx(CopyToClipboard, {
|
|
28
|
+
value: href
|
|
29
|
+
})
|
|
30
|
+
]
|
|
31
|
+
}),
|
|
32
|
+
/*#__PURE__*/ _jsx("div", {
|
|
33
|
+
className: `${baseClass}__url`,
|
|
34
|
+
children: /*#__PURE__*/ _jsx("a", {
|
|
35
|
+
href: href,
|
|
36
|
+
rel: "noopener noreferrer",
|
|
37
|
+
target: "_blank",
|
|
38
|
+
children: href
|
|
39
|
+
})
|
|
40
|
+
})
|
|
41
|
+
]
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/ui/LinkToDoc/index.tsx"],"sourcesContent":["'use client'\nimport type { UIFieldClientProps } from 'payload'\n\nimport { CopyToClipboard, FieldLabel, useFormFields } from '@payloadcms/ui'\nimport React from 'react'\n\nimport './index.css'\n\nconst baseClass = 'link-to-doc'\n\nexport const LinkToDoc: React.FC<UIFieldClientProps> = (props) => {\n const {\n field: { admin: { custom = {} } = {} },\n } = props\n const { isTestKey, nameOfIDField, stripeResourceType } = custom\n\n const field = useFormFields(([fields]) => (fields && fields?.[nameOfIDField]) || null)\n const { value: stripeID } = field || {}\n\n if (!stripeID) {\n return null\n }\n\n const stripeEnv = isTestKey ? 'test/' : ''\n const href = `https://dashboard.stripe.com/${stripeEnv}${stripeResourceType}/${stripeID}`\n\n return (\n <div className={baseClass}>\n <div className={`${baseClass}__header`}>\n <FieldLabel htmlFor={baseClass} label=\"View in Stripe\" />\n <CopyToClipboard value={href} />\n </div>\n <div className={`${baseClass}__url`}>\n <a href={href} rel=\"noopener noreferrer\" target=\"_blank\">\n {href}\n </a>\n </div>\n </div>\n )\n}\n"],"names":["CopyToClipboard","FieldLabel","useFormFields","React","baseClass","LinkToDoc","props","field","admin","custom","isTestKey","nameOfIDField","stripeResourceType","fields","value","stripeID","stripeEnv","href","div","className","htmlFor","label","a","rel","target"],"mappings":"AAAA;;AAGA,SAASA,eAAe,EAAEC,UAAU,EAAEC,aAAa,QAAQ,iBAAgB;AAC3E,OAAOC,WAAW,QAAO;AAEzB,OAAO,cAAa;AAEpB,MAAMC,YAAY;AAElB,OAAO,MAAMC,YAA0C,CAACC;IACtD,MAAM,EACJC,OAAO,EAAEC,OAAO,EAAEC,SAAS,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,EACvC,GAAGH;IACJ,MAAM,EAAEI,SAAS,EAAEC,aAAa,EAAEC,kBAAkB,EAAE,GAAGH;IAEzD,MAAMF,QAAQL,cAAc,CAAC,CAACW,OAAO,GAAK,AAACA,UAAUA,QAAQ,CAACF,cAAc,IAAK;IACjF,MAAM,EAAEG,OAAOC,QAAQ,EAAE,GAAGR,SAAS,CAAC;IAEtC,IAAI,CAACQ,UAAU;QACb,OAAO;IACT;IAEA,MAAMC,YAAYN,YAAY,UAAU;IACxC,MAAMO,OAAO,CAAC,6BAA6B,EAAED,YAAYJ,mBAAmB,CAAC,EAAEG,UAAU;IAEzF,qBACE,MAACG;QAAIC,WAAWf;;0BACd,MAACc;gBAAIC,WAAW,GAAGf,UAAU,QAAQ,CAAC;;kCACpC,KAACH;wBAAWmB,SAAShB;wBAAWiB,OAAM;;kCACtC,KAACrB;wBAAgBc,OAAOG;;;;0BAE1B,KAACC;gBAAIC,WAAW,GAAGf,UAAU,KAAK,CAAC;0BACjC,cAAA,KAACkB;oBAAEL,MAAMA;oBAAMM,KAAI;oBAAsBC,QAAO;8BAC7CP;;;;;AAKX,EAAC"}
|
|
@@ -1,2 +1,8 @@
|
|
|
1
|
+
import type { FieldSyncConfig } from '../types.js';
|
|
1
2
|
export declare const deepen: (obj: Record<string, any>) => Record<string, any>;
|
|
3
|
+
export declare const getSyncedFields: ({ data, fields, source, }: {
|
|
4
|
+
data: object;
|
|
5
|
+
fields: FieldSyncConfig[];
|
|
6
|
+
source: 'payload' | 'stripe';
|
|
7
|
+
}) => Record<string, unknown>;
|
|
2
8
|
//# sourceMappingURL=deepen.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deepen.d.ts","sourceRoot":"","sources":["../../src/utilities/deepen.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"deepen.d.ts","sourceRoot":"","sources":["../../src/utilities/deepen.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAElD,eAAO,MAAM,MAAM,QAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAwBnE,CAAA;AAED,eAAO,MAAM,eAAe,8BAIzB;IACD,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,eAAe,EAAE,CAAA;IACzB,MAAM,EAAE,SAAS,GAAG,QAAQ,CAAA;CAC7B,KAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAczB,CAAA"}
|
package/dist/utilities/deepen.js
CHANGED
|
@@ -1,21 +1,51 @@
|
|
|
1
1
|
// converts an object of dot notation keys to a nested object
|
|
2
2
|
// i.e. { 'price.stripePriceID': '123' } to { price: { stripePriceID: '123' } }
|
|
3
|
+
import { hasUnsupportedFieldPathSegment, setOwnProperty } from 'payload/shared';
|
|
3
4
|
export const deepen = (obj)=>{
|
|
4
5
|
const result = {};
|
|
5
|
-
for(const key
|
|
6
|
+
for (const key of Object.keys(obj)){
|
|
6
7
|
const value = obj[key];
|
|
7
8
|
const keys = key.split('.');
|
|
9
|
+
if (hasUnsupportedFieldPathSegment({
|
|
10
|
+
segments: keys
|
|
11
|
+
})) {
|
|
12
|
+
throw new Error('Invalid field path.');
|
|
13
|
+
}
|
|
8
14
|
let current = result;
|
|
9
15
|
keys.forEach((k, index)=>{
|
|
10
16
|
if (index === keys.length - 1) {
|
|
11
|
-
|
|
17
|
+
setOwnProperty({
|
|
18
|
+
key: k,
|
|
19
|
+
target: current,
|
|
20
|
+
value
|
|
21
|
+
});
|
|
12
22
|
} else {
|
|
13
|
-
current[k]
|
|
23
|
+
if (!Object.hasOwn(current, k) || current[k] === null || typeof current[k] !== 'object') {
|
|
24
|
+
setOwnProperty({
|
|
25
|
+
key: k,
|
|
26
|
+
target: current,
|
|
27
|
+
value: {}
|
|
28
|
+
});
|
|
29
|
+
}
|
|
14
30
|
current = current[k];
|
|
15
31
|
}
|
|
16
32
|
});
|
|
17
33
|
}
|
|
18
34
|
return result;
|
|
19
35
|
};
|
|
36
|
+
export const getSyncedFields = ({ data, fields, source })=>{
|
|
37
|
+
const flattened = Object.create(null);
|
|
38
|
+
for (const { fieldPath, stripeProperty } of fields){
|
|
39
|
+
const sourceProperty = source === 'payload' ? fieldPath : stripeProperty;
|
|
40
|
+
const targetProperty = source === 'payload' ? stripeProperty : fieldPath;
|
|
41
|
+
const value = Object.hasOwn(data, sourceProperty) ? data[sourceProperty] : undefined;
|
|
42
|
+
setOwnProperty({
|
|
43
|
+
key: targetProperty,
|
|
44
|
+
target: flattened,
|
|
45
|
+
value
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
return deepen(flattened);
|
|
49
|
+
};
|
|
20
50
|
|
|
21
51
|
//# sourceMappingURL=deepen.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/deepen.ts"],"sourcesContent":["// converts an object of dot notation keys to a nested object\n// i.e. { 'price.stripePriceID': '123' } to { price: { stripePriceID: '123' } }\n\nexport const deepen = (obj: Record<string, any>): Record<string, any> => {\n const result: Record<string, any> = {}\n\n for (const key
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/deepen.ts"],"sourcesContent":["// converts an object of dot notation keys to a nested object\n// i.e. { 'price.stripePriceID': '123' } to { price: { stripePriceID: '123' } }\n\nimport { hasUnsupportedFieldPathSegment, setOwnProperty } from 'payload/shared'\n\nimport type { FieldSyncConfig } from '../types.js'\n\nexport const deepen = (obj: Record<string, any>): Record<string, any> => {\n const result: Record<string, any> = {}\n\n for (const key of Object.keys(obj)) {\n const value = obj[key]\n const keys = key.split('.')\n\n if (hasUnsupportedFieldPathSegment({ segments: keys })) {\n throw new Error('Invalid field path.')\n }\n\n let current = result\n keys.forEach((k, index) => {\n if (index === keys.length - 1) {\n setOwnProperty({ key: k, target: current, value })\n } else {\n if (!Object.hasOwn(current, k) || current[k] === null || typeof current[k] !== 'object') {\n setOwnProperty({ key: k, target: current, value: {} })\n }\n current = current[k]\n }\n })\n }\n return result\n}\n\nexport const getSyncedFields = ({\n data,\n fields,\n source,\n}: {\n data: object\n fields: FieldSyncConfig[]\n source: 'payload' | 'stripe'\n}): Record<string, unknown> => {\n const flattened = Object.create(null) as Record<string, unknown>\n\n for (const { fieldPath, stripeProperty } of fields) {\n const sourceProperty = source === 'payload' ? fieldPath : stripeProperty\n const targetProperty = source === 'payload' ? stripeProperty : fieldPath\n const value = Object.hasOwn(data, sourceProperty)\n ? (data as Record<string, unknown>)[sourceProperty]\n : undefined\n\n setOwnProperty({ key: targetProperty, target: flattened, value })\n }\n\n return deepen(flattened)\n}\n"],"names":["hasUnsupportedFieldPathSegment","setOwnProperty","deepen","obj","result","key","Object","keys","value","split","segments","Error","current","forEach","k","index","length","target","hasOwn","getSyncedFields","data","fields","source","flattened","create","fieldPath","stripeProperty","sourceProperty","targetProperty","undefined"],"mappings":"AAAA,6DAA6D;AAC7D,+EAA+E;AAE/E,SAASA,8BAA8B,EAAEC,cAAc,QAAQ,iBAAgB;AAI/E,OAAO,MAAMC,SAAS,CAACC;IACrB,MAAMC,SAA8B,CAAC;IAErC,KAAK,MAAMC,OAAOC,OAAOC,IAAI,CAACJ,KAAM;QAClC,MAAMK,QAAQL,GAAG,CAACE,IAAI;QACtB,MAAME,OAAOF,IAAII,KAAK,CAAC;QAEvB,IAAIT,+BAA+B;YAAEU,UAAUH;QAAK,IAAI;YACtD,MAAM,IAAII,MAAM;QAClB;QAEA,IAAIC,UAAUR;QACdG,KAAKM,OAAO,CAAC,CAACC,GAAGC;YACf,IAAIA,UAAUR,KAAKS,MAAM,GAAG,GAAG;gBAC7Bf,eAAe;oBAAEI,KAAKS;oBAAGG,QAAQL;oBAASJ;gBAAM;YAClD,OAAO;gBACL,IAAI,CAACF,OAAOY,MAAM,CAACN,SAASE,MAAMF,OAAO,CAACE,EAAE,KAAK,QAAQ,OAAOF,OAAO,CAACE,EAAE,KAAK,UAAU;oBACvFb,eAAe;wBAAEI,KAAKS;wBAAGG,QAAQL;wBAASJ,OAAO,CAAC;oBAAE;gBACtD;gBACAI,UAAUA,OAAO,CAACE,EAAE;YACtB;QACF;IACF;IACA,OAAOV;AACT,EAAC;AAED,OAAO,MAAMe,kBAAkB,CAAC,EAC9BC,IAAI,EACJC,MAAM,EACNC,MAAM,EAKP;IACC,MAAMC,YAAYjB,OAAOkB,MAAM,CAAC;IAEhC,KAAK,MAAM,EAAEC,SAAS,EAAEC,cAAc,EAAE,IAAIL,OAAQ;QAClD,MAAMM,iBAAiBL,WAAW,YAAYG,YAAYC;QAC1D,MAAME,iBAAiBN,WAAW,YAAYI,iBAAiBD;QAC/D,MAAMjB,QAAQF,OAAOY,MAAM,CAACE,MAAMO,kBAC9B,AAACP,IAAgC,CAACO,eAAe,GACjDE;QAEJ5B,eAAe;YAAEI,KAAKuB;YAAgBX,QAAQM;YAAWf;QAAM;IACjE;IAEA,OAAON,OAAOqB;AAChB,EAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sanitizeStripeRESTConfig.d.ts","sourceRoot":"","sources":["../../src/utilities/sanitizeStripeRESTConfig.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAoB,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAKrE,eAAO,MAAM,wBAAwB,cAElC;IACD,IAAI,EAAE,OAAO,CAAA;CACd,KAAG,gBAAgB,GAAG,SA8BtB,CAAA"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const migrationError = 'The Stripe REST endpoint now requires an object with a non-empty allowedMethods array of exact method names.';
|
|
2
|
+
export const sanitizeStripeRESTConfig = ({ rest })=>{
|
|
3
|
+
if (rest === undefined || rest === false) {
|
|
4
|
+
return undefined;
|
|
5
|
+
}
|
|
6
|
+
if (typeof rest !== 'object' || rest === null || Array.isArray(rest) || !('allowedMethods' in rest) || !Array.isArray(rest.allowedMethods)) {
|
|
7
|
+
throw new Error(migrationError);
|
|
8
|
+
}
|
|
9
|
+
const access = 'access' in rest ? rest.access : undefined;
|
|
10
|
+
if (rest.allowedMethods.length === 0 || rest.allowedMethods.some((method)=>typeof method !== 'string' || method.trim().length === 0 || method.includes('*')) || access !== undefined && !isStripeRESTAccess(access)) {
|
|
11
|
+
throw new Error(migrationError);
|
|
12
|
+
}
|
|
13
|
+
const allowedMethods = Object.freeze([
|
|
14
|
+
...new Set(rest.allowedMethods)
|
|
15
|
+
]);
|
|
16
|
+
return access === undefined ? {
|
|
17
|
+
allowedMethods
|
|
18
|
+
} : {
|
|
19
|
+
access,
|
|
20
|
+
allowedMethods
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
const isStripeRESTAccess = (access)=>typeof access === 'function';
|
|
24
|
+
|
|
25
|
+
//# sourceMappingURL=sanitizeStripeRESTConfig.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/sanitizeStripeRESTConfig.ts"],"sourcesContent":["import type { StripeRESTAccess, StripeRESTConfig } from '../types.js'\n\nconst migrationError =\n 'The Stripe REST endpoint now requires an object with a non-empty allowedMethods array of exact method names.'\n\nexport const sanitizeStripeRESTConfig = ({\n rest,\n}: {\n rest: unknown\n}): StripeRESTConfig | undefined => {\n if (rest === undefined || rest === false) {\n return undefined\n }\n\n if (\n typeof rest !== 'object' ||\n rest === null ||\n Array.isArray(rest) ||\n !('allowedMethods' in rest) ||\n !Array.isArray(rest.allowedMethods)\n ) {\n throw new Error(migrationError)\n }\n\n const access = 'access' in rest ? rest.access : undefined\n\n if (\n rest.allowedMethods.length === 0 ||\n rest.allowedMethods.some(\n (method) => typeof method !== 'string' || method.trim().length === 0 || method.includes('*'),\n ) ||\n (access !== undefined && !isStripeRESTAccess(access))\n ) {\n throw new Error(migrationError)\n }\n\n const allowedMethods = Object.freeze([...new Set(rest.allowedMethods)])\n\n return access === undefined ? { allowedMethods } : { access, allowedMethods }\n}\n\nconst isStripeRESTAccess = (access: unknown): access is StripeRESTAccess =>\n typeof access === 'function'\n"],"names":["migrationError","sanitizeStripeRESTConfig","rest","undefined","Array","isArray","allowedMethods","Error","access","length","some","method","trim","includes","isStripeRESTAccess","Object","freeze","Set"],"mappings":"AAEA,MAAMA,iBACJ;AAEF,OAAO,MAAMC,2BAA2B,CAAC,EACvCC,IAAI,EAGL;IACC,IAAIA,SAASC,aAAaD,SAAS,OAAO;QACxC,OAAOC;IACT;IAEA,IACE,OAAOD,SAAS,YAChBA,SAAS,QACTE,MAAMC,OAAO,CAACH,SACd,CAAE,CAAA,oBAAoBA,IAAG,KACzB,CAACE,MAAMC,OAAO,CAACH,KAAKI,cAAc,GAClC;QACA,MAAM,IAAIC,MAAMP;IAClB;IAEA,MAAMQ,SAAS,YAAYN,OAAOA,KAAKM,MAAM,GAAGL;IAEhD,IACED,KAAKI,cAAc,CAACG,MAAM,KAAK,KAC/BP,KAAKI,cAAc,CAACI,IAAI,CACtB,CAACC,SAAW,OAAOA,WAAW,YAAYA,OAAOC,IAAI,GAAGH,MAAM,KAAK,KAAKE,OAAOE,QAAQ,CAAC,SAEzFL,WAAWL,aAAa,CAACW,mBAAmBN,SAC7C;QACA,MAAM,IAAID,MAAMP;IAClB;IAEA,MAAMM,iBAAiBS,OAAOC,MAAM,CAAC;WAAI,IAAIC,IAAIf,KAAKI,cAAc;KAAE;IAEtE,OAAOE,WAAWL,YAAY;QAAEG;IAAe,IAAI;QAAEE;QAAQF;IAAe;AAC9E,EAAC;AAED,MAAMQ,qBAAqB,CAACN,SAC1B,OAAOA,WAAW"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handleCreatedOrUpdated.d.ts","sourceRoot":"","sources":["../../src/webhooks/handleCreatedOrUpdated.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,2BAA2B,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAIpF,KAAK,sBAAsB,GAAG,CAC5B,IAAI,EAAE;IACJ,YAAY,EAAE,MAAM,CAAA;IACpB,UAAU,EAAE,2BAA2B,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAA;CACnD,GAAG,UAAU,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC,KACpC,OAAO,CAAC,IAAI,CAAC,CAAA;AAElB,eAAO,MAAM,sBAAsB,EAAE,
|
|
1
|
+
{"version":3,"file":"handleCreatedOrUpdated.d.ts","sourceRoot":"","sources":["../../src/webhooks/handleCreatedOrUpdated.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,2BAA2B,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAIpF,KAAK,sBAAsB,GAAG,CAC5B,IAAI,EAAE;IACJ,YAAY,EAAE,MAAM,CAAA;IACpB,UAAU,EAAE,2BAA2B,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAA;CACnD,GAAG,UAAU,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC,KACpC,OAAO,CAAC,IAAI,CAAC,CAAA;AAElB,eAAO,MAAM,sBAAsB,EAAE,sBA0MpC,CAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { v4 as uuid } from 'uuid';
|
|
2
|
-
import { deepen } from '../utilities/deepen.js';
|
|
2
|
+
import { deepen, getSyncedFields } from '../utilities/deepen.js';
|
|
3
3
|
export const handleCreatedOrUpdated = async (args)=>{
|
|
4
4
|
const { config: payloadConfig, event, payload, pluginConfig, resourceType, syncConfig } = args;
|
|
5
5
|
const { logs } = pluginConfig || {};
|
|
@@ -28,6 +28,7 @@ export const handleCreatedOrUpdated = async (args)=>{
|
|
|
28
28
|
const payloadQuery = await payload.find({
|
|
29
29
|
collection: collectionSlug,
|
|
30
30
|
limit: 1,
|
|
31
|
+
overrideAccess: true,
|
|
31
32
|
pagination: false,
|
|
32
33
|
where: {
|
|
33
34
|
stripeID: {
|
|
@@ -37,11 +38,11 @@ export const handleCreatedOrUpdated = async (args)=>{
|
|
|
37
38
|
});
|
|
38
39
|
const foundDoc = payloadQuery.docs[0];
|
|
39
40
|
// combine all properties of the Stripe doc and match their respective fields within the document
|
|
40
|
-
let syncedData =
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
41
|
+
let syncedData = getSyncedFields({
|
|
42
|
+
data: stripeDoc,
|
|
43
|
+
fields: syncConfig.fields,
|
|
44
|
+
source: 'stripe'
|
|
45
|
+
});
|
|
45
46
|
syncedData = deepen({
|
|
46
47
|
...syncedData,
|
|
47
48
|
skipSync: true,
|
|
@@ -59,6 +60,7 @@ export const handleCreatedOrUpdated = async (args)=>{
|
|
|
59
60
|
const authQuery = await payload.find({
|
|
60
61
|
collection: collectionSlug,
|
|
61
62
|
limit: 1,
|
|
63
|
+
overrideAccess: true,
|
|
62
64
|
pagination: false,
|
|
63
65
|
where: {
|
|
64
66
|
email: {
|
|
@@ -76,7 +78,8 @@ export const handleCreatedOrUpdated = async (args)=>{
|
|
|
76
78
|
await payload.update({
|
|
77
79
|
id: authDoc.id,
|
|
78
80
|
collection: collectionSlug,
|
|
79
|
-
data: syncedData
|
|
81
|
+
data: syncedData,
|
|
82
|
+
overrideAccess: true
|
|
80
83
|
});
|
|
81
84
|
if (logs) {
|
|
82
85
|
payload.logger.info(`✅ Successfully updated '${collectionSlug}' document in Payload with ID: '${authDoc.id}.'`);
|
|
@@ -114,7 +117,8 @@ export const handleCreatedOrUpdated = async (args)=>{
|
|
|
114
117
|
password,
|
|
115
118
|
passwordConfirm: password
|
|
116
119
|
},
|
|
117
|
-
disableVerificationEmail: isAuthCollection ? true : undefined
|
|
120
|
+
disableVerificationEmail: isAuthCollection ? true : undefined,
|
|
121
|
+
overrideAccess: true
|
|
118
122
|
});
|
|
119
123
|
if (logs) {
|
|
120
124
|
payload.logger.info(`✅ Successfully created new '${collectionSlug}' document in Payload with Stripe ID: '${stripeID}'.`);
|
|
@@ -134,7 +138,8 @@ export const handleCreatedOrUpdated = async (args)=>{
|
|
|
134
138
|
await payload.update({
|
|
135
139
|
id: foundDoc.id,
|
|
136
140
|
collection: collectionSlug,
|
|
137
|
-
data: syncedData
|
|
141
|
+
data: syncedData,
|
|
142
|
+
overrideAccess: true
|
|
138
143
|
});
|
|
139
144
|
if (logs) {
|
|
140
145
|
payload.logger.info(`✅ Successfully updated '${collectionSlug}' document in Payload from Stripe ID: '${stripeID}'.`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/webhooks/handleCreatedOrUpdated.ts"],"sourcesContent":["import { v4 as uuid } from 'uuid'\n\nimport type { SanitizedStripePluginConfig, StripeWebhookHandler } from '../types.js'\n\nimport { deepen } from '../utilities/deepen.js'\n\ntype HandleCreatedOrUpdated = (\n args: {\n resourceType: string\n syncConfig: SanitizedStripePluginConfig['sync'][0]\n } & Parameters<StripeWebhookHandler>[0],\n) => Promise<void>\n\nexport const handleCreatedOrUpdated: HandleCreatedOrUpdated = async (args) => {\n const { config: payloadConfig, event, payload, pluginConfig, resourceType, syncConfig } = args\n\n const { logs } = pluginConfig || {}\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\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\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 limit: 1,\n pagination: false,\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\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 limit: 1,\n pagination: false,\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\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 }\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 }\n } else {\n if (logs) {\n payload.logger.error(\n `No email was provided from Stripe, cannot create new '${collectionSlug}' document.`,\n )\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\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\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 }\n } catch (error: unknown) {\n const msg = error instanceof Error ? error.message : error\n if (logs) {\n payload.logger.error(`Error creating new document in Payload: ${msg}`)\n }\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\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 }\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}\n"],"names":["v4","uuid","deepen","handleCreatedOrUpdated","args","config","payloadConfig","event","payload","pluginConfig","resourceType","syncConfig","logs","stripeDoc","data","object","id","stripeID","eventObject","isNestedChange","logger","info","collectionSlug","collection","isAuthCollection","Boolean","collections","find","slug","auth","payloadQuery","limit","pagination","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"],"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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EAAE,CAAC;gBAEnG;YACF,EAAE,OAAOoC,OAAgB;gBACvB,MAAMH,MAAMG,iBAAiBF,QAAQE,MAAMD,OAAO,GAAGC;gBACrD,IAAIzC,MAAM;oBACRJ,QAAQY,MAAM,CAACiC,KAAK,CAAC,CAAC,gBAAgB,EAAE/B,eAAe,uBAAuB,EAAE4B,KAAK;gBACvF;YACF;QACF;IACF;AACF,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../src/webhooks/handleCreatedOrUpdated.ts"],"sourcesContent":["import { v4 as uuid } from 'uuid'\n\nimport type { SanitizedStripePluginConfig, StripeWebhookHandler } from '../types.js'\n\nimport { deepen, getSyncedFields } from '../utilities/deepen.js'\n\ntype HandleCreatedOrUpdated = (\n args: {\n resourceType: string\n syncConfig: SanitizedStripePluginConfig['sync'][0]\n } & Parameters<StripeWebhookHandler>[0],\n) => Promise<void>\n\nexport const handleCreatedOrUpdated: HandleCreatedOrUpdated = async (args) => {\n const { config: payloadConfig, event, payload, pluginConfig, resourceType, syncConfig } = args\n\n const { logs } = pluginConfig || {}\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\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\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 limit: 1,\n overrideAccess: true,\n pagination: false,\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 = getSyncedFields({\n data: stripeDoc,\n fields: syncConfig.fields,\n source: 'stripe',\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\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 limit: 1,\n overrideAccess: true,\n pagination: false,\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\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 overrideAccess: true,\n })\n\n if (logs) {\n payload.logger.info(\n `✅ Successfully updated '${collectionSlug}' document in Payload with ID: '${authDoc.id}.'`,\n )\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 }\n } else {\n if (logs) {\n payload.logger.error(\n `No email was provided from Stripe, cannot create new '${collectionSlug}' document.`,\n )\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\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\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 overrideAccess: true,\n })\n\n if (logs) {\n payload.logger.info(\n `✅ Successfully created new '${collectionSlug}' document in Payload with Stripe ID: '${stripeID}'.`,\n )\n }\n } catch (error: unknown) {\n const msg = error instanceof Error ? error.message : error\n if (logs) {\n payload.logger.error(`Error creating new document in Payload: ${msg}`)\n }\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\n try {\n await payload.update({\n id: foundDoc.id,\n collection: collectionSlug,\n data: syncedData,\n overrideAccess: true,\n })\n\n if (logs) {\n payload.logger.info(\n `✅ Successfully updated '${collectionSlug}' document in Payload from Stripe ID: '${stripeID}'.`,\n )\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}\n"],"names":["v4","uuid","deepen","getSyncedFields","handleCreatedOrUpdated","args","config","payloadConfig","event","payload","pluginConfig","resourceType","syncConfig","logs","stripeDoc","data","object","id","stripeID","eventObject","isNestedChange","logger","info","collectionSlug","collection","isAuthCollection","Boolean","collections","find","slug","auth","payloadQuery","limit","overrideAccess","pagination","where","equals","foundDoc","docs","syncedData","fields","source","skipSync","authDoc","email","authQuery","update","err","msg","Error","message","error","password","create","passwordConfirm","disableVerificationEmail","undefined"],"mappings":"AAAA,SAASA,MAAMC,IAAI,QAAQ,OAAM;AAIjC,SAASC,MAAM,EAAEC,eAAe,QAAQ,yBAAwB;AAShE,OAAO,MAAMC,yBAAiD,OAAOC;IACnE,MAAM,EAAEC,QAAQC,aAAa,EAAEC,KAAK,EAAEC,OAAO,EAAEC,YAAY,EAAEC,YAAY,EAAEC,UAAU,EAAE,GAAGP;IAE1F,MAAM,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AAE,OAAOiC,OAAgB;gBACvB,MAAMH,MAAMG,iBAAiBF,QAAQE,MAAMD,OAAO,GAAGC;gBACrD,IAAItC,MAAM;oBACRJ,QAAQY,MAAM,CAAC8B,KAAK,CAAC,CAAC,gBAAgB,EAAE5B,eAAe,uBAAuB,EAAEyB,KAAK;gBACvF;YACF;QACF;IACF;AACF,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handleDeleted.d.ts","sourceRoot":"","sources":["../../src/webhooks/handleDeleted.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,2BAA2B,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAEpF,KAAK,aAAa,GAAG,CACnB,IAAI,EAAE;IACJ,YAAY,EAAE,MAAM,CAAA;IACpB,UAAU,EAAE,2BAA2B,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAA;CACnD,GAAG,UAAU,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC,KACpC,OAAO,CAAC,IAAI,CAAC,CAAA;AAElB,eAAO,MAAM,aAAa,EAAE,
|
|
1
|
+
{"version":3,"file":"handleDeleted.d.ts","sourceRoot":"","sources":["../../src/webhooks/handleDeleted.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,2BAA2B,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAEpF,KAAK,aAAa,GAAG,CACnB,IAAI,EAAE;IACJ,YAAY,EAAE,MAAM,CAAA;IACpB,UAAU,EAAE,2BAA2B,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAA;CACnD,GAAG,UAAU,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC,KACpC,OAAO,CAAC,IAAI,CAAC,CAAA;AAElB,eAAO,MAAM,aAAa,EAAE,aAuF3B,CAAA"}
|
|
@@ -18,6 +18,7 @@ export const handleDeleted = async (args)=>{
|
|
|
18
18
|
const payloadQuery = await payload.find({
|
|
19
19
|
collection: collectionSlug,
|
|
20
20
|
limit: 1,
|
|
21
|
+
overrideAccess: true,
|
|
21
22
|
pagination: false,
|
|
22
23
|
where: {
|
|
23
24
|
stripeID: {
|
|
@@ -39,7 +40,8 @@ export const handleDeleted = async (args)=>{
|
|
|
39
40
|
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
40
41
|
payload.delete({
|
|
41
42
|
id: foundDoc.id,
|
|
42
|
-
collection: collectionSlug
|
|
43
|
+
collection: collectionSlug,
|
|
44
|
+
overrideAccess: true
|
|
43
45
|
});
|
|
44
46
|
// NOTE: the `afterDelete` hook will trigger, which will attempt to delete the document from Stripe and safely error out
|
|
45
47
|
// 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.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/webhooks/handleDeleted.ts"],"sourcesContent":["import type { SanitizedStripePluginConfig, StripeWebhookHandler } from '../types.js'\n\ntype HandleDeleted = (\n args: {\n resourceType: string\n syncConfig: SanitizedStripePluginConfig['sync'][0]\n } & Parameters<StripeWebhookHandler>[0],\n) => Promise<void>\n\nexport const handleDeleted: HandleDeleted = async (args) => {\n const { event, payload, pluginConfig, resourceType, syncConfig } = args\n\n const { logs } = pluginConfig || {}\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\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\n try {\n const payloadQuery = await payload.find({\n collection: collectionSlug,\n limit: 1,\n pagination: false,\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\n if (foundDoc) {\n if (logs) {\n payload.logger.info(`- Deleting Payload document with ID: '${foundDoc.id}'...`)\n }\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 }\n } catch (error: unknown) {\n const msg = error instanceof Error ? error.message : error\n if (logs) {\n payload.logger.error(`Error deleting document: ${msg}`)\n }\n }\n }\n } catch (error: unknown) {\n const msg = error instanceof Error ? error.message : error\n if (logs) {\n payload.logger.error(`Error deleting document: ${msg}`)\n }\n }\n }\n}\n"],"names":["handleDeleted","args","event","payload","pluginConfig","resourceType","syncConfig","logs","collectionSlug","collection","id","stripeID","object","eventObject","data","isNestedDelete","logger","info","payloadQuery","find","limit","pagination","where","equals","foundDoc","docs","delete","error","msg","Error","message"],"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,GAAGH,gBAAgB,CAAC;IAElC,MAAMI,iBAAiBF,YAAYG;IAEnC,MAAM,EACJC,IAAIC,QAAQ,EACZC,QAAQC,WAAW,EACpB,GAAQX,OAAOY,MAAMF,UAAU,CAAC;IAEjC,qFAAqF;IACrF,MAAMG,iBAAiBF,gBAAgBR;IAEvC,IAAIU,gBAAgB;QAClB,IAAIR,MAAM;YACRJ,QAAQa,MAAM,CAACC,IAAI,CACjB,CAAC,8CAA8C,EAAEZ,aAAa,sCAAsC,CAAC;QAEzG;IACF;IAEA,IAAI,CAACU,gBAAgB;QACnB,IAAIR,MAAM;YACRJ,QAAQa,MAAM,CAACC,IAAI,CACjB,CAAC,KAAK,EAAEZ,aAAa,gDAAgD,EAAEG,eAAe,uCAAuC,EAAEG,SAAS,IAAI,CAAC;QAEjJ;QAEA,IAAI;YACF,MAAMO,eAAe,MAAMf,QAAQgB,IAAI,CAAC;gBACtCV,YAAYD;gBACZY,OAAO;gBACPC,YAAY;gBACZC,OAAO;
|
|
1
|
+
{"version":3,"sources":["../../src/webhooks/handleDeleted.ts"],"sourcesContent":["import type { SanitizedStripePluginConfig, StripeWebhookHandler } from '../types.js'\n\ntype HandleDeleted = (\n args: {\n resourceType: string\n syncConfig: SanitizedStripePluginConfig['sync'][0]\n } & Parameters<StripeWebhookHandler>[0],\n) => Promise<void>\n\nexport const handleDeleted: HandleDeleted = async (args) => {\n const { event, payload, pluginConfig, resourceType, syncConfig } = args\n\n const { logs } = pluginConfig || {}\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\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\n try {\n const payloadQuery = await payload.find({\n collection: collectionSlug,\n limit: 1,\n overrideAccess: true,\n pagination: false,\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\n if (foundDoc) {\n if (logs) {\n payload.logger.info(`- Deleting Payload document with ID: '${foundDoc.id}'...`)\n }\n\n try {\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n payload.delete({\n id: foundDoc.id,\n collection: collectionSlug,\n overrideAccess: true,\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 }\n } catch (error: unknown) {\n const msg = error instanceof Error ? error.message : error\n if (logs) {\n payload.logger.error(`Error deleting document: ${msg}`)\n }\n }\n }\n } catch (error: unknown) {\n const msg = error instanceof Error ? error.message : error\n if (logs) {\n payload.logger.error(`Error deleting document: ${msg}`)\n }\n }\n }\n}\n"],"names":["handleDeleted","args","event","payload","pluginConfig","resourceType","syncConfig","logs","collectionSlug","collection","id","stripeID","object","eventObject","data","isNestedDelete","logger","info","payloadQuery","find","limit","overrideAccess","pagination","where","equals","foundDoc","docs","delete","error","msg","Error","message"],"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,GAAGH,gBAAgB,CAAC;IAElC,MAAMI,iBAAiBF,YAAYG;IAEnC,MAAM,EACJC,IAAIC,QAAQ,EACZC,QAAQC,WAAW,EACpB,GAAQX,OAAOY,MAAMF,UAAU,CAAC;IAEjC,qFAAqF;IACrF,MAAMG,iBAAiBF,gBAAgBR;IAEvC,IAAIU,gBAAgB;QAClB,IAAIR,MAAM;YACRJ,QAAQa,MAAM,CAACC,IAAI,CACjB,CAAC,8CAA8C,EAAEZ,aAAa,sCAAsC,CAAC;QAEzG;IACF;IAEA,IAAI,CAACU,gBAAgB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AAQa,MAAM,CAACY,KAAK,CAAC,CAAC,yBAAyB,EAAEC,KAAK;YACxD;QACF;IACF;AACF,EAAC"}
|
package/package.json
CHANGED
|
@@ -1,23 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/plugin-stripe",
|
|
3
|
-
"version": "4.0.0-internal.
|
|
3
|
+
"version": "4.0.0-internal.d3909a9",
|
|
4
4
|
"description": "Stripe plugin for Payload",
|
|
5
5
|
"keywords": [
|
|
6
|
-
"payload",
|
|
7
|
-
"stripe",
|
|
8
6
|
"cms",
|
|
9
|
-
"
|
|
10
|
-
"
|
|
7
|
+
"licensing",
|
|
8
|
+
"payload",
|
|
11
9
|
"payments",
|
|
10
|
+
"plugin",
|
|
12
11
|
"saas",
|
|
12
|
+
"stripe",
|
|
13
13
|
"subscriptions",
|
|
14
|
-
"
|
|
14
|
+
"typescript"
|
|
15
15
|
],
|
|
16
|
-
"repository": {
|
|
17
|
-
"type": "git",
|
|
18
|
-
"url": "https://github.com/payloadcms/payload.git",
|
|
19
|
-
"directory": "packages/plugin-stripe"
|
|
20
|
-
},
|
|
21
16
|
"license": "MIT",
|
|
22
17
|
"author": "Payload <dev@payloadcms.com> (https://payloadcms.com)",
|
|
23
18
|
"maintainers": [
|
|
@@ -27,8 +22,18 @@
|
|
|
27
22
|
"url": "https://payloadcms.com"
|
|
28
23
|
}
|
|
29
24
|
],
|
|
30
|
-
"
|
|
25
|
+
"repository": {
|
|
26
|
+
"type": "git",
|
|
27
|
+
"url": "https://github.com/payloadcms/payload.git",
|
|
28
|
+
"directory": "packages/plugin-stripe"
|
|
29
|
+
},
|
|
30
|
+
"files": [
|
|
31
|
+
"dist"
|
|
32
|
+
],
|
|
31
33
|
"type": "module",
|
|
34
|
+
"sideEffects": false,
|
|
35
|
+
"main": "./dist/index.js",
|
|
36
|
+
"types": "./dist/index.d.ts",
|
|
32
37
|
"exports": {
|
|
33
38
|
".": {
|
|
34
39
|
"import": "./dist/index.js",
|
|
@@ -46,31 +51,25 @@
|
|
|
46
51
|
"default": "./dist/exports/client.js"
|
|
47
52
|
}
|
|
48
53
|
},
|
|
49
|
-
"
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
"dist"
|
|
53
|
-
],
|
|
54
|
+
"publishConfig": {
|
|
55
|
+
"registry": "https://registry.npmjs.org/"
|
|
56
|
+
},
|
|
54
57
|
"dependencies": {
|
|
55
58
|
"lodash.get": "^4.4.2",
|
|
56
59
|
"stripe": "^10.2.0",
|
|
57
60
|
"uuid": "14.0.0",
|
|
58
|
-
"@payloadcms/ui": "4.0.0-internal.
|
|
59
|
-
"@payloadcms/translations": "4.0.0-internal.
|
|
61
|
+
"@payloadcms/ui": "4.0.0-internal.d3909a9",
|
|
62
|
+
"@payloadcms/translations": "4.0.0-internal.d3909a9"
|
|
60
63
|
},
|
|
61
64
|
"devDependencies": {
|
|
62
65
|
"@types/lodash.get": "^4.4.7",
|
|
63
|
-
"@types/react": "19.
|
|
64
|
-
"@types/react-dom": "19.
|
|
65
|
-
"
|
|
66
|
-
"@payloadcms/next": "4.0.0-internal.
|
|
67
|
-
"payload": "4.0.0-internal.d28e9fb"
|
|
66
|
+
"@types/react": "19.3.0",
|
|
67
|
+
"@types/react-dom": "19.3.0",
|
|
68
|
+
"payload": "4.0.0-internal.d3909a9",
|
|
69
|
+
"@payloadcms/next": "4.0.0-internal.d3909a9"
|
|
68
70
|
},
|
|
69
71
|
"peerDependencies": {
|
|
70
|
-
"payload": "4.0.0-internal.
|
|
71
|
-
},
|
|
72
|
-
"publishConfig": {
|
|
73
|
-
"registry": "https://registry.npmjs.org/"
|
|
72
|
+
"payload": "4.0.0-internal.d3909a9"
|
|
74
73
|
},
|
|
75
74
|
"homepage:": "https://payloadcms.com",
|
|
76
75
|
"scripts": {
|
|
@@ -79,8 +78,6 @@
|
|
|
79
78
|
"build:swc": "swc ./src -d ./dist --config-file .swcrc --strip-leading-paths",
|
|
80
79
|
"build:types": "tsc --emitDeclarationOnly --outDir dist",
|
|
81
80
|
"clean": "rimraf -g {dist,*.tsbuildinfo}",
|
|
82
|
-
"copyfiles": "copyfiles -u 1 \"src/**/*.{html,css,scss,ttf,woff,woff2,eot,svg,jpg,png,json}\" dist/"
|
|
83
|
-
"lint": "eslint .",
|
|
84
|
-
"lint:fix": "eslint . --fix"
|
|
81
|
+
"copyfiles": "copyfiles -u 1 -e \"**/*.spec.*\" \"src/**/*.{html,css,scss,ttf,woff,woff2,eot,svg,jpg,png,json}\" dist/"
|
|
85
82
|
}
|
|
86
83
|
}
|
package/dist/ui/LinkToDoc.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"LinkToDoc.d.ts","sourceRoot":"","sources":["../../src/ui/LinkToDoc.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAA;AAKrD,eAAO,MAAM,SAAS,EAAE,sBA0CvB,CAAA"}
|
package/dist/ui/LinkToDoc.js
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { CopyToClipboard, useFormFields } from '@payloadcms/ui';
|
|
4
|
-
import React from 'react';
|
|
5
|
-
export const LinkToDoc = (props)=>{
|
|
6
|
-
const { field: { admin: { custom = {} } = {} } } = props;
|
|
7
|
-
const { isTestKey, nameOfIDField, stripeResourceType } = custom;
|
|
8
|
-
const field = useFormFields(([fields])=>fields && fields?.[nameOfIDField] || null);
|
|
9
|
-
const { value: stripeID } = field || {};
|
|
10
|
-
const stripeEnv = isTestKey ? 'test/' : '';
|
|
11
|
-
const href = `https://dashboard.stripe.com/${stripeEnv}${stripeResourceType}/${stripeID}`;
|
|
12
|
-
if (stripeID) {
|
|
13
|
-
return /*#__PURE__*/ _jsxs("div", {
|
|
14
|
-
children: [
|
|
15
|
-
/*#__PURE__*/ _jsxs("div", {
|
|
16
|
-
children: [
|
|
17
|
-
/*#__PURE__*/ _jsx("span", {
|
|
18
|
-
className: "label",
|
|
19
|
-
style: {
|
|
20
|
-
color: '#9A9A9A'
|
|
21
|
-
},
|
|
22
|
-
children: "View in Stripe"
|
|
23
|
-
}),
|
|
24
|
-
/*#__PURE__*/ _jsx(CopyToClipboard, {
|
|
25
|
-
value: href
|
|
26
|
-
})
|
|
27
|
-
]
|
|
28
|
-
}),
|
|
29
|
-
/*#__PURE__*/ _jsx("div", {
|
|
30
|
-
style: {
|
|
31
|
-
fontWeight: '600',
|
|
32
|
-
overflow: 'hidden',
|
|
33
|
-
textOverflow: 'ellipsis'
|
|
34
|
-
},
|
|
35
|
-
children: /*#__PURE__*/ _jsx("a", {
|
|
36
|
-
href: href,
|
|
37
|
-
rel: "noreferrer noopener",
|
|
38
|
-
target: "_blank",
|
|
39
|
-
children: href
|
|
40
|
-
})
|
|
41
|
-
})
|
|
42
|
-
]
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
return null;
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
//# sourceMappingURL=LinkToDoc.js.map
|
package/dist/ui/LinkToDoc.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/ui/LinkToDoc.tsx"],"sourcesContent":["'use client'\nimport type { UIFieldClientComponent } from 'payload'\n\nimport { CopyToClipboard, useFormFields } from '@payloadcms/ui'\nimport React from 'react'\n\nexport const LinkToDoc: UIFieldClientComponent = (props) => {\n const {\n field: { admin: { custom = {} } = {} },\n } = props\n const { isTestKey, nameOfIDField, stripeResourceType } = custom\n\n const field = useFormFields(([fields]) => (fields && fields?.[nameOfIDField]) || null)\n const { value: stripeID } = field || {}\n\n const stripeEnv = isTestKey ? 'test/' : ''\n const href = `https://dashboard.stripe.com/${stripeEnv}${stripeResourceType}/${stripeID}`\n\n if (stripeID) {\n return (\n <div>\n <div>\n <span\n className=\"label\"\n style={{\n color: '#9A9A9A',\n }}\n >\n View in Stripe\n </span>\n <CopyToClipboard value={href} />\n </div>\n <div\n style={{\n fontWeight: '600',\n overflow: 'hidden',\n textOverflow: 'ellipsis',\n }}\n >\n <a href={href} rel=\"noreferrer noopener\" target=\"_blank\">\n {href}\n </a>\n </div>\n </div>\n )\n }\n\n return null\n}\n"],"names":["CopyToClipboard","useFormFields","React","LinkToDoc","props","field","admin","custom","isTestKey","nameOfIDField","stripeResourceType","fields","value","stripeID","stripeEnv","href","div","span","className","style","color","fontWeight","overflow","textOverflow","a","rel","target"],"mappings":"AAAA;;AAGA,SAASA,eAAe,EAAEC,aAAa,QAAQ,iBAAgB;AAC/D,OAAOC,WAAW,QAAO;AAEzB,OAAO,MAAMC,YAAoC,CAACC;IAChD,MAAM,EACJC,OAAO,EAAEC,OAAO,EAAEC,SAAS,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,EACvC,GAAGH;IACJ,MAAM,EAAEI,SAAS,EAAEC,aAAa,EAAEC,kBAAkB,EAAE,GAAGH;IAEzD,MAAMF,QAAQJ,cAAc,CAAC,CAACU,OAAO,GAAK,AAACA,UAAUA,QAAQ,CAACF,cAAc,IAAK;IACjF,MAAM,EAAEG,OAAOC,QAAQ,EAAE,GAAGR,SAAS,CAAC;IAEtC,MAAMS,YAAYN,YAAY,UAAU;IACxC,MAAMO,OAAO,CAAC,6BAA6B,EAAED,YAAYJ,mBAAmB,CAAC,EAAEG,UAAU;IAEzF,IAAIA,UAAU;QACZ,qBACE,MAACG;;8BACC,MAACA;;sCACC,KAACC;4BACCC,WAAU;4BACVC,OAAO;gCACLC,OAAO;4BACT;sCACD;;sCAGD,KAACpB;4BAAgBY,OAAOG;;;;8BAE1B,KAACC;oBACCG,OAAO;wBACLE,YAAY;wBACZC,UAAU;wBACVC,cAAc;oBAChB;8BAEA,cAAA,KAACC;wBAAET,MAAMA;wBAAMU,KAAI;wBAAsBC,QAAO;kCAC7CX;;;;;IAKX;IAEA,OAAO;AACT,EAAC"}
|