@payloadcms/plugin-stripe 3.0.0-alpha.70 → 3.0.0-beta.100
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/dist/admin.d.ts +1 -1
- package/dist/admin.d.ts.map +1 -1
- package/dist/admin.js.map +1 -1
- package/dist/exports/client.d.ts +2 -0
- package/dist/exports/client.d.ts.map +1 -0
- package/dist/exports/client.js +4 -0
- package/dist/exports/client.js.map +1 -0
- package/dist/exports/types.js.map +1 -1
- package/dist/fields/getFields.d.ts +1 -1
- package/dist/fields/getFields.d.ts.map +1 -1
- package/dist/fields/getFields.js +1 -2
- package/dist/fields/getFields.js.map +1 -1
- package/dist/hooks/createNewInStripe.d.ts +5 -5
- package/dist/hooks/createNewInStripe.d.ts.map +1 -1
- package/dist/hooks/createNewInStripe.js +22 -8
- package/dist/hooks/createNewInStripe.js.map +1 -1
- package/dist/hooks/deleteFromStripe.d.ts +5 -5
- package/dist/hooks/deleteFromStripe.d.ts.map +1 -1
- package/dist/hooks/deleteFromStripe.js +13 -5
- package/dist/hooks/deleteFromStripe.js.map +1 -1
- package/dist/hooks/syncExistingWithStripe.d.ts +5 -5
- package/dist/hooks/syncExistingWithStripe.d.ts.map +1 -1
- package/dist/hooks/syncExistingWithStripe.js +13 -5
- 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 +0 -1
- package/dist/index.js.map +1 -1
- package/dist/routes/rest.d.ts +2 -2
- package/dist/routes/rest.d.ts.map +1 -1
- package/dist/routes/rest.js +5 -4
- package/dist/routes/rest.js.map +1 -1
- package/dist/routes/webhooks.d.ts +2 -3
- package/dist/routes/webhooks.d.ts.map +1 -1
- package/dist/routes/webhooks.js +3 -0
- package/dist/routes/webhooks.js.map +1 -1
- package/dist/types.d.ts +5 -131
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/ui/LinkToDoc.d.ts +2 -3
- package/dist/ui/LinkToDoc.d.ts.map +1 -1
- package/dist/ui/LinkToDoc.js +34 -20
- package/dist/ui/LinkToDoc.js.map +1 -1
- package/dist/utilities/deepen.d.ts.map +1 -1
- package/dist/utilities/deepen.js.map +1 -1
- package/dist/utilities/stripeProxy.js.map +1 -1
- package/dist/webhooks/handleCreatedOrUpdated.d.ts +2 -2
- package/dist/webhooks/handleCreatedOrUpdated.d.ts.map +1 -1
- package/dist/webhooks/handleCreatedOrUpdated.js +42 -14
- package/dist/webhooks/handleCreatedOrUpdated.js.map +1 -1
- package/dist/webhooks/handleDeleted.d.ts +2 -2
- package/dist/webhooks/handleDeleted.d.ts.map +1 -1
- package/dist/webhooks/handleDeleted.js +21 -7
- package/dist/webhooks/handleDeleted.js.map +1 -1
- package/dist/webhooks/index.d.ts.map +1 -1
- package/dist/webhooks/index.js +3 -1
- package/dist/webhooks/index.js.map +1 -1
- package/package.json +30 -23
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/routes/webhooks.ts"],"sourcesContent":["import type { Config as PayloadConfig
|
|
1
|
+
{"version":3,"sources":["../../src/routes/webhooks.ts"],"sourcesContent":["import type { Config as PayloadConfig, PayloadRequest } from 'payload'\n\nimport Stripe from 'stripe'\n\nimport type { StripePluginConfig } from '../types.js'\n\nimport { handleWebhooks } from '../webhooks/index.js'\n\nexport const stripeWebhooks = async (args: {\n config: PayloadConfig\n pluginConfig: StripePluginConfig\n req: PayloadRequest\n}): Promise<any> => {\n const { config, pluginConfig, req } = args\n let returnStatus = 200\n\n const { stripeSecretKey, stripeWebhooksEndpointSecret, webhooks } = pluginConfig\n\n if (stripeWebhooksEndpointSecret) {\n const stripe = new Stripe(stripeSecretKey, {\n // api version can only be the latest, stripe recommends ts ignoring it\n apiVersion: '2022-08-01',\n appInfo: {\n name: 'Stripe Payload Plugin',\n url: 'https://payloadcms.com',\n },\n })\n\n const body = await req.text()\n const stripeSignature = req.headers.get('stripe-signature')\n\n if (stripeSignature) {\n let event: Stripe.Event | undefined\n\n try {\n event = stripe.webhooks.constructEvent(body, stripeSignature, stripeWebhooksEndpointSecret)\n } catch (err: unknown) {\n const msg: string = err instanceof Error ? err.message : JSON.stringify(err)\n req.payload.logger.error(`Error constructing Stripe event: ${msg}`)\n returnStatus = 400\n }\n\n if (event) {\n handleWebhooks({\n config,\n event,\n payload: req.payload,\n pluginConfig,\n req,\n stripe,\n })\n\n // Fire external webhook handlers if they exist\n if (typeof webhooks === 'function') {\n webhooks({\n config,\n event,\n payload: req.payload,\n pluginConfig,\n req,\n stripe,\n })\n }\n\n if (typeof webhooks === 'object') {\n const webhookEventHandler = webhooks[event.type]\n if (typeof webhookEventHandler === 'function') {\n webhookEventHandler({\n config,\n event,\n payload: req.payload,\n pluginConfig,\n req,\n stripe,\n })\n }\n }\n }\n }\n }\n\n return Response.json(\n { received: true },\n {\n status: returnStatus,\n },\n )\n}\n"],"names":["Stripe","handleWebhooks","stripeWebhooks","args","config","pluginConfig","req","returnStatus","stripeSecretKey","stripeWebhooksEndpointSecret","webhooks","stripe","apiVersion","appInfo","name","url","body","text","stripeSignature","headers","get","event","constructEvent","err","msg","Error","message","JSON","stringify","payload","logger","error","webhookEventHandler","type","Response","json","received","status"],"mappings":"AAEA,OAAOA,YAAY,SAAQ;AAI3B,SAASC,cAAc,QAAQ,uBAAsB;AAErD,OAAO,MAAMC,iBAAiB,OAAOC;IAKnC,MAAM,EAAEC,MAAM,EAAEC,YAAY,EAAEC,GAAG,EAAE,GAAGH;IACtC,IAAII,eAAe;IAEnB,MAAM,EAAEC,eAAe,EAAEC,4BAA4B,EAAEC,QAAQ,EAAE,GAAGL;IAEpE,IAAII,8BAA8B;QAChC,MAAME,SAAS,IAAIX,OAAOQ,iBAAiB;YACzC,uEAAuE;YACvEI,YAAY;YACZC,SAAS;gBACPC,MAAM;gBACNC,KAAK;YACP;QACF;QAEA,MAAMC,OAAO,MAAMV,IAAIW,IAAI;QAC3B,MAAMC,kBAAkBZ,IAAIa,OAAO,CAACC,GAAG,CAAC;QAExC,IAAIF,iBAAiB;YACnB,IAAIG;YAEJ,IAAI;gBACFA,QAAQV,OAAOD,QAAQ,CAACY,cAAc,CAACN,MAAME,iBAAiBT;YAChE,EAAE,OAAOc,KAAc;gBACrB,MAAMC,MAAcD,eAAeE,QAAQF,IAAIG,OAAO,GAAGC,KAAKC,SAAS,CAACL;gBACxEjB,IAAIuB,OAAO,CAACC,MAAM,CAACC,KAAK,CAAC,CAAC,iCAAiC,EAAEP,IAAI,CAAC;gBAClEjB,eAAe;YACjB;YAEA,IAAIc,OAAO;gBACTpB,eAAe;oBACbG;oBACAiB;oBACAQ,SAASvB,IAAIuB,OAAO;oBACpBxB;oBACAC;oBACAK;gBACF;gBAEA,+CAA+C;gBAC/C,IAAI,OAAOD,aAAa,YAAY;oBAClCA,SAAS;wBACPN;wBACAiB;wBACAQ,SAASvB,IAAIuB,OAAO;wBACpBxB;wBACAC;wBACAK;oBACF;gBACF;gBAEA,IAAI,OAAOD,aAAa,UAAU;oBAChC,MAAMsB,sBAAsBtB,QAAQ,CAACW,MAAMY,IAAI,CAAC;oBAChD,IAAI,OAAOD,wBAAwB,YAAY;wBAC7CA,oBAAoB;4BAClB5B;4BACAiB;4BACAQ,SAASvB,IAAIuB,OAAO;4BACpBxB;4BACAC;4BACAK;wBACF;oBACF;gBACF;YACF;QACF;IACF;IAEA,OAAOuB,SAASC,IAAI,CAClB;QAAEC,UAAU;IAAK,GACjB;QACEC,QAAQ9B;IACV;AAEJ,EAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,139 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
/// <reference types="stripe/types/shared.js" />
|
|
3
|
-
/// <reference types="stripe/types/Errors.js" />
|
|
4
|
-
/// <reference types="stripe/types/OAuth.js" />
|
|
5
|
-
/// <reference types="stripe/types/Webhooks.js" />
|
|
6
|
-
/// <reference types="stripe/types/2022-08-01/AccountLinks.js" />
|
|
7
|
-
/// <reference types="stripe/types/2022-08-01/Accounts.js" />
|
|
8
|
-
/// <reference types="stripe/types/2022-08-01/ApplePayDomains.js" />
|
|
9
|
-
/// <reference types="stripe/types/2022-08-01/ApplicationFees.js" />
|
|
10
|
-
/// <reference types="stripe/types/2022-08-01/Applications.js" />
|
|
11
|
-
/// <reference types="stripe/types/2022-08-01/Apps/Secrets.js" />
|
|
12
|
-
/// <reference types="stripe/types/2022-08-01/Balance.js" />
|
|
13
|
-
/// <reference types="stripe/types/2022-08-01/BalanceTransactions.js" />
|
|
14
|
-
/// <reference types="stripe/types/2022-08-01/BankAccounts.js" />
|
|
15
|
-
/// <reference types="stripe/types/2022-08-01/BillingPortal/Configurations.js" />
|
|
16
|
-
/// <reference types="stripe/types/2022-08-01/BillingPortal/Sessions.js" />
|
|
17
|
-
/// <reference types="stripe/types/2022-08-01/Capabilities.js" />
|
|
18
|
-
/// <reference types="stripe/types/2022-08-01/Cards.js" />
|
|
19
|
-
/// <reference types="stripe/types/2022-08-01/CashBalances.js" />
|
|
20
|
-
/// <reference types="stripe/types/2022-08-01/Charges.js" />
|
|
21
|
-
/// <reference types="stripe/types/2022-08-01/Checkout/Sessions.js" />
|
|
22
|
-
/// <reference types="stripe/types/2022-08-01/ConnectCollectionTransfers.js" />
|
|
23
|
-
/// <reference types="stripe/types/2022-08-01/CountrySpecs.js" />
|
|
24
|
-
/// <reference types="stripe/types/2022-08-01/Coupons.js" />
|
|
25
|
-
/// <reference types="stripe/types/2022-08-01/CreditNoteLineItems.js" />
|
|
26
|
-
/// <reference types="stripe/types/2022-08-01/CreditNotes.js" />
|
|
27
|
-
/// <reference types="stripe/types/2022-08-01/CustomerBalanceTransactions.js" />
|
|
28
|
-
/// <reference types="stripe/types/2022-08-01/CustomerCashBalanceTransactions.js" />
|
|
29
|
-
/// <reference types="stripe/types/2022-08-01/CustomerSources.js" />
|
|
30
|
-
/// <reference types="stripe/types/2022-08-01/Customers.js" />
|
|
31
|
-
/// <reference types="stripe/types/2022-08-01/Discounts.js" />
|
|
32
|
-
/// <reference types="stripe/types/2022-08-01/Disputes.js" />
|
|
33
|
-
/// <reference types="stripe/types/2022-08-01/EphemeralKeys.js" />
|
|
34
|
-
/// <reference types="stripe/types/2022-08-01/Events.js" />
|
|
35
|
-
/// <reference types="stripe/types/2022-08-01/ExchangeRates.js" />
|
|
36
|
-
/// <reference types="stripe/types/2022-08-01/ExternalAccounts.js" />
|
|
37
|
-
/// <reference types="stripe/types/2022-08-01/FeeRefunds.js" />
|
|
38
|
-
/// <reference types="stripe/types/2022-08-01/FileLinks.js" />
|
|
39
|
-
/// <reference types="stripe/types/2022-08-01/Files.js" />
|
|
40
|
-
/// <reference types="stripe/types/2022-08-01/FinancialConnections/AccountOwners.js" />
|
|
41
|
-
/// <reference types="stripe/types/2022-08-01/FinancialConnections/AccountOwnerships.js" />
|
|
42
|
-
/// <reference types="stripe/types/2022-08-01/FinancialConnections/Accounts.js" />
|
|
43
|
-
/// <reference types="stripe/types/2022-08-01/FinancialConnections/Sessions.js" />
|
|
44
|
-
/// <reference types="stripe/types/2022-08-01/FundingInstructions.js" />
|
|
45
|
-
/// <reference types="stripe/types/2022-08-01/Identity/VerificationReports.js" />
|
|
46
|
-
/// <reference types="stripe/types/2022-08-01/Identity/VerificationSessions.js" />
|
|
47
|
-
/// <reference types="stripe/types/2022-08-01/InvoiceItems.js" />
|
|
48
|
-
/// <reference types="stripe/types/2022-08-01/InvoiceLineItems.js" />
|
|
49
|
-
/// <reference types="stripe/types/2022-08-01/Invoices.js" />
|
|
50
|
-
/// <reference types="stripe/types/2022-08-01/Issuing/Authorizations.js" />
|
|
51
|
-
/// <reference types="stripe/types/2022-08-01/Issuing/Cardholders.js" />
|
|
52
|
-
/// <reference types="stripe/types/2022-08-01/Issuing/Cards.js" />
|
|
53
|
-
/// <reference types="stripe/types/2022-08-01/Issuing/Disputes.js" />
|
|
54
|
-
/// <reference types="stripe/types/2022-08-01/Issuing/Transactions.js" />
|
|
55
|
-
/// <reference types="stripe/types/2022-08-01/LineItems.js" />
|
|
56
|
-
/// <reference types="stripe/types/2022-08-01/LoginLinks.js" />
|
|
57
|
-
/// <reference types="stripe/types/2022-08-01/Mandates.js" />
|
|
58
|
-
/// <reference types="stripe/types/2022-08-01/Orders.js" />
|
|
59
|
-
/// <reference types="stripe/types/2022-08-01/PaymentIntents.js" />
|
|
60
|
-
/// <reference types="stripe/types/2022-08-01/PaymentLinks.js" />
|
|
61
|
-
/// <reference types="stripe/types/2022-08-01/PaymentMethods.js" />
|
|
62
|
-
/// <reference types="stripe/types/2022-08-01/Payouts.js" />
|
|
63
|
-
/// <reference types="stripe/types/2022-08-01/Persons.js" />
|
|
64
|
-
/// <reference types="stripe/types/2022-08-01/Plans.js" />
|
|
65
|
-
/// <reference types="stripe/types/2022-08-01/PlatformTaxFees.js" />
|
|
66
|
-
/// <reference types="stripe/types/2022-08-01/Prices.js" />
|
|
67
|
-
/// <reference types="stripe/types/2022-08-01/Products.js" />
|
|
68
|
-
/// <reference types="stripe/types/2022-08-01/PromotionCodes.js" />
|
|
69
|
-
/// <reference types="stripe/types/2022-08-01/Quotes.js" />
|
|
70
|
-
/// <reference types="stripe/types/2022-08-01/Radar/EarlyFraudWarnings.js" />
|
|
71
|
-
/// <reference types="stripe/types/2022-08-01/Radar/ValueListItems.js" />
|
|
72
|
-
/// <reference types="stripe/types/2022-08-01/Radar/ValueLists.js" />
|
|
73
|
-
/// <reference types="stripe/types/2022-08-01/Refunds.js" />
|
|
74
|
-
/// <reference types="stripe/types/2022-08-01/Reporting/ReportRuns.js" />
|
|
75
|
-
/// <reference types="stripe/types/2022-08-01/Reporting/ReportTypes.js" />
|
|
76
|
-
/// <reference types="stripe/types/2022-08-01/ReserveTransactions.js" />
|
|
77
|
-
/// <reference types="stripe/types/2022-08-01/Reviews.js" />
|
|
78
|
-
/// <reference types="stripe/types/2022-08-01/SKUs.js" />
|
|
79
|
-
/// <reference types="stripe/types/2022-08-01/SetupAttempts.js" />
|
|
80
|
-
/// <reference types="stripe/types/2022-08-01/SetupIntents.js" />
|
|
81
|
-
/// <reference types="stripe/types/2022-08-01/ShippingRates.js" />
|
|
82
|
-
/// <reference types="stripe/types/2022-08-01/Sigma/ScheduledQueryRuns.js" />
|
|
83
|
-
/// <reference types="stripe/types/2022-08-01/SourceMandateNotifications.js" />
|
|
84
|
-
/// <reference types="stripe/types/2022-08-01/SourceTransactions.js" />
|
|
85
|
-
/// <reference types="stripe/types/2022-08-01/Sources.js" />
|
|
86
|
-
/// <reference types="stripe/types/2022-08-01/SubscriptionItems.js" />
|
|
87
|
-
/// <reference types="stripe/types/2022-08-01/SubscriptionSchedules.js" />
|
|
88
|
-
/// <reference types="stripe/types/2022-08-01/Subscriptions.js" />
|
|
89
|
-
/// <reference types="stripe/types/2022-08-01/TaxCodes.js" />
|
|
90
|
-
/// <reference types="stripe/types/2022-08-01/TaxDeductedAtSources.js" />
|
|
91
|
-
/// <reference types="stripe/types/2022-08-01/TaxIds.js" />
|
|
92
|
-
/// <reference types="stripe/types/2022-08-01/TaxRates.js" />
|
|
93
|
-
/// <reference types="stripe/types/2022-08-01/Terminal/Configurations.js" />
|
|
94
|
-
/// <reference types="stripe/types/2022-08-01/Terminal/ConnectionTokens.js" />
|
|
95
|
-
/// <reference types="stripe/types/2022-08-01/Terminal/Locations.js" />
|
|
96
|
-
/// <reference types="stripe/types/2022-08-01/Terminal/Readers.js" />
|
|
97
|
-
/// <reference types="stripe/types/2022-08-01/TestHelpers/Customers.js" />
|
|
98
|
-
/// <reference types="stripe/types/2022-08-01/TestHelpers/Issuing/Cards.js" />
|
|
99
|
-
/// <reference types="stripe/types/2022-08-01/TestHelpers/Refunds.js" />
|
|
100
|
-
/// <reference types="stripe/types/2022-08-01/TestHelpers/Terminal/Readers.js" />
|
|
101
|
-
/// <reference types="stripe/types/2022-08-01/TestHelpers/TestClocks.js" />
|
|
102
|
-
/// <reference types="stripe/types/2022-08-01/TestHelpers/Treasury/InboundTransfers.js" />
|
|
103
|
-
/// <reference types="stripe/types/2022-08-01/TestHelpers/Treasury/OutboundPayments.js" />
|
|
104
|
-
/// <reference types="stripe/types/2022-08-01/TestHelpers/Treasury/OutboundTransfers.js" />
|
|
105
|
-
/// <reference types="stripe/types/2022-08-01/TestHelpers/Treasury/ReceivedCredits.js" />
|
|
106
|
-
/// <reference types="stripe/types/2022-08-01/TestHelpers/Treasury/ReceivedDebits.js" />
|
|
107
|
-
/// <reference types="stripe/types/2022-08-01/Tokens.js" />
|
|
108
|
-
/// <reference types="stripe/types/2022-08-01/Topups.js" />
|
|
109
|
-
/// <reference types="stripe/types/2022-08-01/TransferReversals.js" />
|
|
110
|
-
/// <reference types="stripe/types/2022-08-01/Transfers.js" />
|
|
111
|
-
/// <reference types="stripe/types/2022-08-01/Treasury/CreditReversals.js" />
|
|
112
|
-
/// <reference types="stripe/types/2022-08-01/Treasury/DebitReversals.js" />
|
|
113
|
-
/// <reference types="stripe/types/2022-08-01/Treasury/FinancialAccountFeatures.js" />
|
|
114
|
-
/// <reference types="stripe/types/2022-08-01/Treasury/FinancialAccounts.js" />
|
|
115
|
-
/// <reference types="stripe/types/2022-08-01/Treasury/InboundTransfers.js" />
|
|
116
|
-
/// <reference types="stripe/types/2022-08-01/Treasury/OutboundPayments.js" />
|
|
117
|
-
/// <reference types="stripe/types/2022-08-01/Treasury/OutboundTransfers.js" />
|
|
118
|
-
/// <reference types="stripe/types/2022-08-01/Treasury/ReceivedCredits.js" />
|
|
119
|
-
/// <reference types="stripe/types/2022-08-01/Treasury/ReceivedDebits.js" />
|
|
120
|
-
/// <reference types="stripe/types/2022-08-01/Treasury/TransactionEntries.js" />
|
|
121
|
-
/// <reference types="stripe/types/2022-08-01/Treasury/Transactions.js" />
|
|
122
|
-
/// <reference types="stripe/types/2022-08-01/UsageRecordSummaries.js" />
|
|
123
|
-
/// <reference types="stripe/types/2022-08-01/UsageRecords.js" />
|
|
124
|
-
/// <reference types="stripe/types/2022-08-01/WebhookEndpoints.js" />
|
|
125
|
-
/// <reference types="stripe/types/lib.js" />
|
|
126
|
-
/// <reference types="stripe/types/net/net.js" />
|
|
127
|
-
import type { Payload } from 'payload';
|
|
128
|
-
import type { Config as PayloadConfig } from 'payload/config';
|
|
1
|
+
import type { Payload, Config as PayloadConfig, PayloadRequest } from 'payload';
|
|
129
2
|
import type Stripe from 'stripe';
|
|
130
3
|
export type StripeWebhookHandler<T = any> = (args: {
|
|
131
4
|
config: PayloadConfig;
|
|
132
5
|
event: T;
|
|
133
6
|
payload: Payload;
|
|
134
7
|
pluginConfig?: StripePluginConfig;
|
|
8
|
+
req: PayloadRequest;
|
|
135
9
|
stripe: Stripe;
|
|
136
|
-
}) => void;
|
|
10
|
+
}) => Promise<void> | void;
|
|
137
11
|
export type StripeWebhookHandlers = {
|
|
138
12
|
[webhookName: string]: StripeWebhookHandler;
|
|
139
13
|
};
|
|
@@ -157,9 +31,9 @@ export type StripePluginConfig = {
|
|
|
157
31
|
sync?: SyncConfig[];
|
|
158
32
|
webhooks?: StripeWebhookHandler | StripeWebhookHandlers;
|
|
159
33
|
};
|
|
160
|
-
export type SanitizedStripePluginConfig =
|
|
34
|
+
export type SanitizedStripePluginConfig = {
|
|
161
35
|
sync: SyncConfig[];
|
|
162
|
-
};
|
|
36
|
+
} & StripePluginConfig;
|
|
163
37
|
export type StripeProxy = (args: {
|
|
164
38
|
stripeArgs: any[];
|
|
165
39
|
stripeMethod: string;
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,IAAI,aAAa,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAC/E,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAA;AAEhC,MAAM,MAAM,oBAAoB,CA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Ae,EAAE,MAAM,CAAA;CACxB,KAAK,OAAO,CAAC;IACZ,IAAI,CAAC,EAAE,GAAG,CAAA;IACV,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,MAAM,EAAE,MAAM,CAAA;CACf,CAAC,CAAA"}
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type { Payload
|
|
1
|
+
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type { Payload, Config as PayloadConfig, PayloadRequest } from 'payload'\nimport type Stripe from 'stripe'\n\nexport type StripeWebhookHandler<T = any> = (args: {\n config: PayloadConfig\n event: T\n payload: Payload\n pluginConfig?: StripePluginConfig\n req: PayloadRequest\n stripe: Stripe\n}) => Promise<void> | void\n\nexport type StripeWebhookHandlers = {\n [webhookName: string]: StripeWebhookHandler\n}\n\nexport type FieldSyncConfig = {\n fieldPath: string\n stripeProperty: string\n}\n\nexport type SyncConfig = {\n collection: string\n fields: FieldSyncConfig[]\n stripeResourceType: 'customers' | 'products' // TODO: get this from Stripe types\n stripeResourceTypeSingular: 'customer' | 'product' // TODO: there must be a better way to do this\n}\n\nexport type StripePluginConfig = {\n isTestKey?: boolean\n logs?: boolean\n /** @default false */\n rest?: boolean\n stripeSecretKey: string\n stripeWebhooksEndpointSecret?: string\n sync?: SyncConfig[]\n webhooks?: StripeWebhookHandler | StripeWebhookHandlers\n}\n\nexport type SanitizedStripePluginConfig = {\n sync: SyncConfig[] // convert to required\n} & StripePluginConfig\n\nexport type StripeProxy = (args: {\n stripeArgs: any[]\n stripeMethod: string\n stripeSecretKey: string\n}) => Promise<{\n data?: any\n message?: string\n status: number\n}>\n"],"names":[],"mappings":"AA2CA,WAQE"}
|
package/dist/ui/LinkToDoc.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { CustomComponent } from 'payload
|
|
2
|
-
|
|
3
|
-
export declare const LinkToDoc: CustomComponent<UIField>;
|
|
1
|
+
import type { CustomComponent, PayloadClientReactComponent } from 'payload';
|
|
2
|
+
export declare const LinkToDoc: PayloadClientReactComponent<CustomComponent>;
|
|
4
3
|
//# sourceMappingURL=LinkToDoc.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LinkToDoc.d.ts","sourceRoot":"","sources":["../../src/ui/LinkToDoc.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,
|
|
1
|
+
{"version":3,"file":"LinkToDoc.d.ts","sourceRoot":"","sources":["../../src/ui/LinkToDoc.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,2BAA2B,EAAE,MAAM,SAAS,CAAA;AAK3E,eAAO,MAAM,SAAS,EAAE,2BAA2B,CAAC,eAAe,CAwClE,CAAA"}
|
package/dist/ui/LinkToDoc.js
CHANGED
|
@@ -1,32 +1,46 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
import { useFormFields } from '@payloadcms/ui/forms/Form';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { CopyToClipboard, useFieldProps, useFormFields } from '@payloadcms/ui';
|
|
5
4
|
import React from 'react';
|
|
6
5
|
export const LinkToDoc = ()=>{
|
|
7
6
|
const { custom } = useFieldProps();
|
|
8
7
|
const { isTestKey, nameOfIDField, stripeResourceType } = custom;
|
|
9
|
-
const field = useFormFields(([fields])=>fields[nameOfIDField]);
|
|
8
|
+
const field = useFormFields(([fields])=>fields && fields?.[nameOfIDField] || null);
|
|
10
9
|
const { value: stripeID } = field || {};
|
|
11
10
|
const stripeEnv = isTestKey ? 'test/' : '';
|
|
12
11
|
const href = `https://dashboard.stripe.com/${stripeEnv}${stripeResourceType}/${stripeID}`;
|
|
13
12
|
if (stripeID) {
|
|
14
|
-
return /*#__PURE__*/
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
+
});
|
|
30
44
|
}
|
|
31
45
|
return null;
|
|
32
46
|
};
|
package/dist/ui/LinkToDoc.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/ui/LinkToDoc.tsx"],"sourcesContent":["'use client'\nimport type { CustomComponent
|
|
1
|
+
{"version":3,"sources":["../../src/ui/LinkToDoc.tsx"],"sourcesContent":["'use client'\nimport type { CustomComponent, PayloadClientReactComponent } from 'payload'\n\nimport { CopyToClipboard, useFieldProps, useFormFields } from '@payloadcms/ui'\nimport React from 'react'\n\nexport const LinkToDoc: PayloadClientReactComponent<CustomComponent> = () => {\n const { custom } = useFieldProps()\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","useFieldProps","useFormFields","React","LinkToDoc","custom","isTestKey","nameOfIDField","stripeResourceType","field","fields","value","stripeID","stripeEnv","href","div","span","className","style","color","fontWeight","overflow","textOverflow","a","rel","target"],"mappings":"AAAA;;AAGA,SAASA,eAAe,EAAEC,aAAa,EAAEC,aAAa,QAAQ,iBAAgB;AAC9E,OAAOC,WAAW,QAAO;AAEzB,OAAO,MAAMC,YAA0D;IACrE,MAAM,EAAEC,MAAM,EAAE,GAAGJ;IACnB,MAAM,EAAEK,SAAS,EAAEC,aAAa,EAAEC,kBAAkB,EAAE,GAAGH;IAEzD,MAAMI,QAAQP,cAAc,CAAC,CAACQ,OAAO,GAAK,AAACA,UAAUA,QAAQ,CAACH,cAAc,IAAK;IACjF,MAAM,EAAEI,OAAOC,QAAQ,EAAE,GAAGH,SAAS,CAAC;IAEtC,MAAMI,YAAYP,YAAY,UAAU;IACxC,MAAMQ,OAAO,CAAC,6BAA6B,EAAED,UAAU,EAAEL,mBAAmB,CAAC,EAAEI,SAAS,CAAC;IAEzF,IAAIA,UAAU;QACZ,qBACE,MAACG;;8BACC,MAACA;;sCACC,KAACC;4BACCC,WAAU;4BACVC,OAAO;gCACLC,OAAO;4BACT;sCACD;;sCAGD,KAACnB;4BAAgBW,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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deepen.d.ts","sourceRoot":"","sources":["../../src/utilities/deepen.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,MAAM,QAAS,
|
|
1
|
+
{"version":3,"file":"deepen.d.ts","sourceRoot":"","sources":["../../src/utilities/deepen.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,MAAM,QAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAiBnE,CAAA"}
|
|
@@ -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 in obj) {\n const value = obj[key]\n const keys = key.split('.')\n let current = result\n keys.forEach((k, index) => {\n if (index === keys.length - 1) {\n current[k] = value\n } else {\n current[k] = current[k] || {}\n current = current[k]\n }\n })\n }\n return result\n}\n"],"names":["deepen","obj","result","key","value","keys","split","current","forEach","k","index","length"],"
|
|
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 in obj) {\n const value = obj[key]\n const keys = key.split('.')\n let current = result\n keys.forEach((k, index) => {\n if (index === keys.length - 1) {\n current[k] = value\n } else {\n current[k] = current[k] || {}\n current = current[k]\n }\n })\n }\n return result\n}\n"],"names":["deepen","obj","result","key","value","keys","split","current","forEach","k","index","length"],"mappings":"AAAA,6DAA6D;AAC7D,+EAA+E;AAE/E,OAAO,MAAMA,SAAS,CAACC;IACrB,MAAMC,SAA8B,CAAC;IAErC,IAAK,MAAMC,OAAOF,IAAK;QACrB,MAAMG,QAAQH,GAAG,CAACE,IAAI;QACtB,MAAME,OAAOF,IAAIG,KAAK,CAAC;QACvB,IAAIC,UAAUL;QACdG,KAAKG,OAAO,CAAC,CAACC,GAAGC;YACf,IAAIA,UAAUL,KAAKM,MAAM,GAAG,GAAG;gBAC7BJ,OAAO,CAACE,EAAE,GAAGL;YACf,OAAO;gBACLG,OAAO,CAACE,EAAE,GAAGF,OAAO,CAACE,EAAE,IAAI,CAAC;gBAC5BF,UAAUA,OAAO,CAACE,EAAE;YACtB;QACF;IACF;IACA,OAAOP;AACT,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
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"],"
|
|
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"],"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,8 +1,8 @@
|
|
|
1
1
|
import type { SanitizedStripePluginConfig, StripeWebhookHandler } from '../types.js';
|
|
2
|
-
type HandleCreatedOrUpdated = (args:
|
|
2
|
+
type HandleCreatedOrUpdated = (args: {
|
|
3
3
|
resourceType: string;
|
|
4
4
|
syncConfig: SanitizedStripePluginConfig['sync'][0];
|
|
5
|
-
}) => void;
|
|
5
|
+
} & Parameters<StripeWebhookHandler>[0]) => void;
|
|
6
6
|
export declare const handleCreatedOrUpdated: HandleCreatedOrUpdated;
|
|
7
7
|
export {};
|
|
8
8
|
//# sourceMappingURL=handleCreatedOrUpdated.d.ts.map
|
|
@@ -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
|
|
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,IAAI,CAAA;AAET,eAAO,MAAM,sBAAsB,EAAE,sBAqMpC,CAAA"}
|
|
@@ -14,10 +14,14 @@ export const handleCreatedOrUpdated = async (args)=>{
|
|
|
14
14
|
// stripeID = parentResource;
|
|
15
15
|
// }
|
|
16
16
|
if (isNestedChange) {
|
|
17
|
-
if (logs)
|
|
17
|
+
if (logs) {
|
|
18
|
+
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.`);
|
|
19
|
+
}
|
|
18
20
|
}
|
|
19
21
|
if (!isNestedChange) {
|
|
20
|
-
if (logs)
|
|
22
|
+
if (logs) {
|
|
23
|
+
payload.logger.info(`- A new document was created or updated in Stripe, now syncing to Payload...`);
|
|
24
|
+
}
|
|
21
25
|
const collectionSlug = syncConfig?.collection;
|
|
22
26
|
const isAuthCollection = Boolean(payloadConfig?.collections?.find((collection)=>collection.slug === collectionSlug)?.auth);
|
|
23
27
|
// First, search for an existing document in Payload
|
|
@@ -42,7 +46,9 @@ export const handleCreatedOrUpdated = async (args)=>{
|
|
|
42
46
|
stripeID
|
|
43
47
|
});
|
|
44
48
|
if (!foundDoc) {
|
|
45
|
-
if (logs)
|
|
49
|
+
if (logs) {
|
|
50
|
+
payload.logger.info(`- No existing '${collectionSlug}' document found with Stripe ID: '${stripeID}', creating new...`);
|
|
51
|
+
}
|
|
46
52
|
// auth docs must use unique emails
|
|
47
53
|
let authDoc = null;
|
|
48
54
|
if (isAuthCollection) {
|
|
@@ -58,7 +64,9 @@ export const handleCreatedOrUpdated = async (args)=>{
|
|
|
58
64
|
});
|
|
59
65
|
authDoc = authQuery.docs[0];
|
|
60
66
|
if (authDoc) {
|
|
61
|
-
if (logs)
|
|
67
|
+
if (logs) {
|
|
68
|
+
payload.logger.info(`- Account already exists with e-mail: ${stripeDoc.email}, updating now...`);
|
|
69
|
+
}
|
|
62
70
|
// account exists by email, so update it instead
|
|
63
71
|
try {
|
|
64
72
|
await payload.update({
|
|
@@ -66,23 +74,33 @@ export const handleCreatedOrUpdated = async (args)=>{
|
|
|
66
74
|
collection: collectionSlug,
|
|
67
75
|
data: syncedData
|
|
68
76
|
});
|
|
69
|
-
if (logs)
|
|
77
|
+
if (logs) {
|
|
78
|
+
payload.logger.info(`✅ Successfully updated '${collectionSlug}' document in Payload with ID: '${authDoc.id}.'`);
|
|
79
|
+
}
|
|
70
80
|
} catch (err) {
|
|
71
81
|
const msg = err instanceof Error ? err.message : err;
|
|
72
|
-
if (logs)
|
|
82
|
+
if (logs) {
|
|
83
|
+
payload.logger.error(`- Error updating existing '${collectionSlug}' document: ${msg}`);
|
|
84
|
+
}
|
|
73
85
|
}
|
|
74
86
|
}
|
|
75
87
|
} else {
|
|
76
|
-
if (logs)
|
|
88
|
+
if (logs) {
|
|
89
|
+
payload.logger.error(`No email was provided from Stripe, cannot create new '${collectionSlug}' document.`);
|
|
90
|
+
}
|
|
77
91
|
}
|
|
78
92
|
} catch (error) {
|
|
79
93
|
const msg = error instanceof Error ? error.message : error;
|
|
80
|
-
if (logs)
|
|
94
|
+
if (logs) {
|
|
95
|
+
payload.logger.error(`Error looking up '${collectionSlug}' document in Payload: ${msg}`);
|
|
96
|
+
}
|
|
81
97
|
}
|
|
82
98
|
}
|
|
83
99
|
if (!isAuthCollection || isAuthCollection && !authDoc) {
|
|
84
100
|
try {
|
|
85
|
-
if (logs)
|
|
101
|
+
if (logs) {
|
|
102
|
+
payload.logger.info(`- Creating new '${collectionSlug}' document in Payload with Stripe ID: '${stripeID}'.`);
|
|
103
|
+
}
|
|
86
104
|
// generate a strong, unique password for the new user
|
|
87
105
|
const password = uuid();
|
|
88
106
|
await payload.create({
|
|
@@ -94,24 +112,34 @@ export const handleCreatedOrUpdated = async (args)=>{
|
|
|
94
112
|
},
|
|
95
113
|
disableVerificationEmail: isAuthCollection ? true : undefined
|
|
96
114
|
});
|
|
97
|
-
if (logs)
|
|
115
|
+
if (logs) {
|
|
116
|
+
payload.logger.info(`✅ Successfully created new '${collectionSlug}' document in Payload with Stripe ID: '${stripeID}'.`);
|
|
117
|
+
}
|
|
98
118
|
} catch (error) {
|
|
99
119
|
const msg = error instanceof Error ? error.message : error;
|
|
100
|
-
if (logs)
|
|
120
|
+
if (logs) {
|
|
121
|
+
payload.logger.error(`Error creating new document in Payload: ${msg}`);
|
|
122
|
+
}
|
|
101
123
|
}
|
|
102
124
|
}
|
|
103
125
|
} else {
|
|
104
|
-
if (logs)
|
|
126
|
+
if (logs) {
|
|
127
|
+
payload.logger.info(`- Existing '${collectionSlug}' document found in Payload with Stripe ID: '${stripeID}', updating now...`);
|
|
128
|
+
}
|
|
105
129
|
try {
|
|
106
130
|
await payload.update({
|
|
107
131
|
id: foundDoc.id,
|
|
108
132
|
collection: collectionSlug,
|
|
109
133
|
data: syncedData
|
|
110
134
|
});
|
|
111
|
-
if (logs)
|
|
135
|
+
if (logs) {
|
|
136
|
+
payload.logger.info(`✅ Successfully updated '${collectionSlug}' document in Payload from Stripe ID: '${stripeID}'.`);
|
|
137
|
+
}
|
|
112
138
|
} catch (error) {
|
|
113
139
|
const msg = error instanceof Error ? error.message : error;
|
|
114
|
-
if (logs)
|
|
140
|
+
if (logs) {
|
|
141
|
+
payload.logger.error(`Error updating '${collectionSlug}' document in Payload: ${msg}`);
|
|
142
|
+
}
|
|
115
143
|
}
|
|
116
144
|
}
|
|
117
145
|
}
|
|
@@ -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: Parameters<StripeWebhookHandler>[0] & {\n resourceType: string\n syncConfig: SanitizedStripePluginConfig['sync'][0]\n },\n) => 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 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","pluginConfig","resourceType","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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,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
|
+
{"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) => 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 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 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","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,EAAEQ,IAAI,EAAE,GAAGH,gBAAgB,CAAC;IAElC,MAAMI,YAAiBN,OAAOO,MAAMC,UAAU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AIvC,MAAM;oBACRJ,QAAQY,MAAM,CAAC+B,KAAK,CAAC,CAAC,gBAAgB,EAAE7B,eAAe,uBAAuB,EAAE0B,IAAI,CAAC;gBACvF;YACF;QACF;IACF;AACF,EAAC"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { SanitizedStripePluginConfig, StripeWebhookHandler } from '../types.js';
|
|
2
|
-
type HandleDeleted = (args:
|
|
2
|
+
type HandleDeleted = (args: {
|
|
3
3
|
resourceType: string;
|
|
4
4
|
syncConfig: SanitizedStripePluginConfig['sync'][0];
|
|
5
|
-
}) => void;
|
|
5
|
+
} & Parameters<StripeWebhookHandler>[0]) => void;
|
|
6
6
|
export declare const handleDeleted: HandleDeleted;
|
|
7
7
|
export {};
|
|
8
8
|
//# sourceMappingURL=handleDeleted.d.ts.map
|
|
@@ -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
|
|
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,IAAI,CAAA;AAET,eAAO,MAAM,aAAa,EAAE,aAmF3B,CAAA"}
|