@easypayment/medusa-payment-paypal 1.2.2 → 1.2.4
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/.medusa/server/src/admin/index.js +390 -136
- package/.medusa/server/src/admin/index.mjs +390 -136
- package/.medusa/server/src/api/admin/payment-collections/[id]/payment-sessions/route.d.ts +1 -0
- package/.medusa/server/src/api/admin/payment-collections/[id]/payment-sessions/route.d.ts.map +1 -1
- package/.medusa/server/src/api/admin/payment-collections/[id]/payment-sessions/route.js +5 -1
- package/.medusa/server/src/api/admin/payment-collections/[id]/payment-sessions/route.js.map +1 -1
- package/.medusa/server/src/api/admin/paypal/disconnect/route.d.ts +1 -0
- package/.medusa/server/src/api/admin/paypal/disconnect/route.d.ts.map +1 -1
- package/.medusa/server/src/api/admin/paypal/disconnect/route.js +1 -0
- package/.medusa/server/src/api/admin/paypal/disconnect/route.js.map +1 -1
- package/.medusa/server/src/api/admin/paypal/environment/route.d.ts +2 -0
- package/.medusa/server/src/api/admin/paypal/environment/route.d.ts.map +1 -1
- package/.medusa/server/src/api/admin/paypal/environment/route.js +2 -0
- package/.medusa/server/src/api/admin/paypal/environment/route.js.map +1 -1
- package/.medusa/server/src/api/admin/paypal/onboard-complete/route.d.ts +9 -0
- package/.medusa/server/src/api/admin/paypal/onboard-complete/route.d.ts.map +1 -1
- package/.medusa/server/src/api/admin/paypal/onboard-complete/route.js +9 -4
- package/.medusa/server/src/api/admin/paypal/onboard-complete/route.js.map +1 -1
- package/.medusa/server/src/api/admin/paypal/onboarding-link/route.d.ts +7 -1
- package/.medusa/server/src/api/admin/paypal/onboarding-link/route.d.ts.map +1 -1
- package/.medusa/server/src/api/admin/paypal/onboarding-link/route.js +9 -2
- package/.medusa/server/src/api/admin/paypal/onboarding-link/route.js.map +1 -1
- package/.medusa/server/src/api/admin/paypal/onboarding-status/route.d.ts +1 -0
- package/.medusa/server/src/api/admin/paypal/onboarding-status/route.d.ts.map +1 -1
- package/.medusa/server/src/api/admin/paypal/onboarding-status/route.js +1 -0
- package/.medusa/server/src/api/admin/paypal/onboarding-status/route.js.map +1 -1
- package/.medusa/server/src/api/admin/paypal/save-credentials/route.d.ts +1 -0
- package/.medusa/server/src/api/admin/paypal/save-credentials/route.d.ts.map +1 -1
- package/.medusa/server/src/api/admin/paypal/save-credentials/route.js +10 -3
- package/.medusa/server/src/api/admin/paypal/save-credentials/route.js.map +1 -1
- package/.medusa/server/src/api/admin/paypal/settings/route.d.ts +2 -0
- package/.medusa/server/src/api/admin/paypal/settings/route.d.ts.map +1 -1
- package/.medusa/server/src/api/admin/paypal/settings/route.js +9 -2
- package/.medusa/server/src/api/admin/paypal/settings/route.js.map +1 -1
- package/.medusa/server/src/api/admin/paypal/status/route.d.ts +4 -0
- package/.medusa/server/src/api/admin/paypal/status/route.d.ts.map +1 -1
- package/.medusa/server/src/api/admin/paypal/status/route.js +9 -1
- package/.medusa/server/src/api/admin/paypal/status/route.js.map +1 -1
- package/.medusa/server/src/api/store/payment-collections/[id]/payment-sessions/route.d.ts +4 -0
- package/.medusa/server/src/api/store/payment-collections/[id]/payment-sessions/route.d.ts.map +1 -1
- package/.medusa/server/src/api/store/payment-collections/[id]/payment-sessions/route.js +5 -0
- package/.medusa/server/src/api/store/payment-collections/[id]/payment-sessions/route.js.map +1 -1
- package/.medusa/server/src/api/store/paypal/capture-order/route.d.ts +8 -0
- package/.medusa/server/src/api/store/paypal/capture-order/route.d.ts.map +1 -1
- package/.medusa/server/src/api/store/paypal/capture-order/route.js +23 -3
- package/.medusa/server/src/api/store/paypal/capture-order/route.js.map +1 -1
- package/.medusa/server/src/api/store/paypal/config/route.d.ts +5 -0
- package/.medusa/server/src/api/store/paypal/config/route.d.ts.map +1 -1
- package/.medusa/server/src/api/store/paypal/config/route.js +12 -5
- package/.medusa/server/src/api/store/paypal/config/route.js.map +1 -1
- package/.medusa/server/src/api/store/paypal/create-order/route.d.ts +8 -0
- package/.medusa/server/src/api/store/paypal/create-order/route.d.ts.map +1 -1
- package/.medusa/server/src/api/store/paypal/create-order/route.js +54 -20
- package/.medusa/server/src/api/store/paypal/create-order/route.js.map +1 -1
- package/.medusa/server/src/api/store/paypal/onboard-return/route.d.ts.map +1 -1
- package/.medusa/server/src/api/store/paypal/onboard-return/route.js +19 -19
- package/.medusa/server/src/api/store/paypal/onboard-return/route.js.map +1 -1
- package/.medusa/server/src/api/store/paypal/settings/route.d.ts +1 -0
- package/.medusa/server/src/api/store/paypal/settings/route.d.ts.map +1 -1
- package/.medusa/server/src/api/store/paypal/settings/route.js +4 -1
- package/.medusa/server/src/api/store/paypal/settings/route.js.map +1 -1
- package/.medusa/server/src/api/store/paypal/webhook/route.d.ts +7 -0
- package/.medusa/server/src/api/store/paypal/webhook/route.d.ts.map +1 -1
- package/.medusa/server/src/api/store/paypal/webhook/route.js +34 -3
- package/.medusa/server/src/api/store/paypal/webhook/route.js.map +1 -1
- package/.medusa/server/src/api/store/paypal-complete/route.d.ts +8 -0
- package/.medusa/server/src/api/store/paypal-complete/route.d.ts.map +1 -1
- package/.medusa/server/src/api/store/paypal-complete/route.js +33 -6
- package/.medusa/server/src/api/store/paypal-complete/route.js.map +1 -1
- package/.medusa/server/src/api/utils/rate-limit.d.ts +4 -0
- package/.medusa/server/src/api/utils/rate-limit.d.ts.map +1 -1
- package/.medusa/server/src/api/utils/rate-limit.js +9 -4
- package/.medusa/server/src/api/utils/rate-limit.js.map +1 -1
- package/.medusa/server/src/jobs/paypal-webhook-retry.d.ts +5 -0
- package/.medusa/server/src/jobs/paypal-webhook-retry.d.ts.map +1 -1
- package/.medusa/server/src/jobs/paypal-webhook-retry.js +13 -2
- package/.medusa/server/src/jobs/paypal-webhook-retry.js.map +1 -1
- package/.medusa/server/src/modules/paypal/index.d.ts +1 -0
- package/.medusa/server/src/modules/paypal/index.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/index.js +1 -0
- package/.medusa/server/src/modules/paypal/index.js.map +1 -1
- package/.medusa/server/src/modules/paypal/migrations/20260115120000_create_paypal_connection.js +22 -22
- package/.medusa/server/src/modules/paypal/migrations/20260123090000_create_paypal_settings.js +11 -11
- package/.medusa/server/src/modules/paypal/migrations/20260201090000_create_paypal_webhook_event.js +18 -18
- package/.medusa/server/src/modules/paypal/migrations/20260401090000_create_paypal_metric.js +16 -16
- package/.medusa/server/src/modules/paypal/migrations/20260701090000_add_paypal_webhook_event_processing.js +20 -20
- package/.medusa/server/src/modules/paypal/migrations/20261101090000_remove_paypal_reconciliation_status.js +14 -14
- package/.medusa/server/src/modules/paypal/migrations/20261201090000_remove_paypal_audit_log.js +15 -15
- package/.medusa/server/src/modules/paypal/migrations/20270101090000_set_paypal_environment_default_live.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/migrations/20270101090000_set_paypal_environment_default_live.js.map +1 -1
- package/.medusa/server/src/modules/paypal/migrations/20270102090000_add_paypal_seller_email.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/migrations/20270102090000_add_paypal_seller_email.js.map +1 -1
- package/.medusa/server/src/modules/paypal/migrations/20270103090000_add_paypal_seller_merchant_id.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/migrations/20270103090000_add_paypal_seller_merchant_id.js.map +1 -1
- package/.medusa/server/src/modules/paypal/migrations/20270201000000_add_webhook_dead_letter.js +6 -6
- package/.medusa/server/src/modules/paypal/models/paypal_connection.d.ts +5 -0
- package/.medusa/server/src/modules/paypal/models/paypal_connection.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/models/paypal_connection.js +5 -0
- package/.medusa/server/src/modules/paypal/models/paypal_connection.js.map +1 -1
- package/.medusa/server/src/modules/paypal/models/paypal_metric.d.ts +4 -0
- package/.medusa/server/src/modules/paypal/models/paypal_metric.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/models/paypal_metric.js +4 -0
- package/.medusa/server/src/modules/paypal/models/paypal_metric.js.map +1 -1
- package/.medusa/server/src/modules/paypal/models/paypal_settings.d.ts +5 -0
- package/.medusa/server/src/modules/paypal/models/paypal_settings.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/models/paypal_settings.js +5 -0
- package/.medusa/server/src/modules/paypal/models/paypal_settings.js.map +1 -1
- package/.medusa/server/src/modules/paypal/models/paypal_webhook_event.d.ts +7 -0
- package/.medusa/server/src/modules/paypal/models/paypal_webhook_event.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/models/paypal_webhook_event.js +7 -0
- package/.medusa/server/src/modules/paypal/models/paypal_webhook_event.js.map +1 -1
- package/.medusa/server/src/modules/paypal/payment-provider/base-provider.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/payment-provider/base-provider.js.map +1 -1
- package/.medusa/server/src/modules/paypal/payment-provider/card-service.d.ts +14 -6
- package/.medusa/server/src/modules/paypal/payment-provider/card-service.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/payment-provider/card-service.js +55 -32
- package/.medusa/server/src/modules/paypal/payment-provider/card-service.js.map +1 -1
- package/.medusa/server/src/modules/paypal/payment-provider/index.d.ts +6 -1
- package/.medusa/server/src/modules/paypal/payment-provider/index.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/payment-provider/index.js +6 -4
- package/.medusa/server/src/modules/paypal/payment-provider/index.js.map +1 -1
- package/.medusa/server/src/modules/paypal/payment-provider/service.d.ts +8 -0
- package/.medusa/server/src/modules/paypal/payment-provider/service.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/payment-provider/service.js +39 -12
- package/.medusa/server/src/modules/paypal/payment-provider/service.js.map +1 -1
- package/.medusa/server/src/modules/paypal/service.d.ts +72 -2
- package/.medusa/server/src/modules/paypal/service.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/service.js +159 -33
- package/.medusa/server/src/modules/paypal/service.js.map +1 -1
- package/.medusa/server/src/modules/paypal/types/config.d.ts +2 -0
- package/.medusa/server/src/modules/paypal/types/config.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/types/config.js +5 -2
- package/.medusa/server/src/modules/paypal/types/config.js.map +1 -1
- package/.medusa/server/src/modules/paypal/utils/amounts.d.ts +1 -0
- package/.medusa/server/src/modules/paypal/utils/amounts.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/utils/amounts.js +15 -5
- package/.medusa/server/src/modules/paypal/utils/amounts.js.map +1 -1
- package/.medusa/server/src/modules/paypal/utils/credential-resolver.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/utils/credential-resolver.js +3 -1
- package/.medusa/server/src/modules/paypal/utils/credential-resolver.js.map +1 -1
- package/.medusa/server/src/modules/paypal/utils/currencies.d.ts +9 -0
- package/.medusa/server/src/modules/paypal/utils/currencies.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/utils/currencies.js +13 -0
- package/.medusa/server/src/modules/paypal/utils/currencies.js.map +1 -1
- package/.medusa/server/src/modules/paypal/utils/payment-session.d.ts +12 -0
- package/.medusa/server/src/modules/paypal/utils/payment-session.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/utils/payment-session.js +4 -3
- package/.medusa/server/src/modules/paypal/utils/payment-session.js.map +1 -1
- package/.medusa/server/src/modules/paypal/utils/paypal-auth.d.ts +1 -0
- package/.medusa/server/src/modules/paypal/utils/paypal-auth.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/utils/paypal-auth.js +1 -0
- package/.medusa/server/src/modules/paypal/utils/paypal-auth.js.map +1 -1
- package/.medusa/server/src/modules/paypal/utils/paypal-fetch.d.ts +11 -0
- package/.medusa/server/src/modules/paypal/utils/paypal-fetch.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/utils/paypal-fetch.js +17 -1
- package/.medusa/server/src/modules/paypal/utils/paypal-fetch.js.map +1 -1
- package/.medusa/server/src/modules/paypal/utils/provider-ids.d.ts +6 -0
- package/.medusa/server/src/modules/paypal/utils/provider-ids.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/utils/provider-ids.js +6 -0
- package/.medusa/server/src/modules/paypal/utils/provider-ids.js.map +1 -1
- package/.medusa/server/src/modules/paypal/utils/secret-crypto.d.ts +2 -0
- package/.medusa/server/src/modules/paypal/utils/secret-crypto.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/utils/secret-crypto.js +6 -1
- package/.medusa/server/src/modules/paypal/utils/secret-crypto.js.map +1 -1
- package/.medusa/server/src/modules/paypal/webhook-processor.d.ts +43 -0
- package/.medusa/server/src/modules/paypal/webhook-processor.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/webhook-processor.js +57 -5
- package/.medusa/server/src/modules/paypal/webhook-processor.js.map +1 -1
- package/.medusa/server/src/providers/paypal/index.d.ts +1 -0
- package/.medusa/server/src/providers/paypal/index.d.ts.map +1 -1
- package/.medusa/server/src/providers/paypal/index.js +1 -0
- package/.medusa/server/src/providers/paypal/index.js.map +1 -1
- package/.medusa/server/src/providers/paypal_card/index.d.ts +1 -0
- package/.medusa/server/src/providers/paypal_card/index.d.ts.map +1 -1
- package/.medusa/server/src/providers/paypal_card/index.js +1 -0
- package/.medusa/server/src/providers/paypal_card/index.js.map +1 -1
- package/.medusa/server/src/subscribers/paypal-order-invoice.d.ts +6 -0
- package/.medusa/server/src/subscribers/paypal-order-invoice.d.ts.map +1 -1
- package/.medusa/server/src/subscribers/paypal-order-invoice.js +9 -1
- package/.medusa/server/src/subscribers/paypal-order-invoice.js.map +1 -1
- package/.medusa/server/src/subscribers/paypal-webhook-process.d.ts +1 -0
- package/.medusa/server/src/subscribers/paypal-webhook-process.d.ts.map +1 -1
- package/.medusa/server/src/subscribers/paypal-webhook-process.js +17 -4
- package/.medusa/server/src/subscribers/paypal-webhook-process.js.map +1 -1
- package/CHANGELOG.md +19 -0
- package/README.md +184 -175
- package/package.json +24 -5
- package/src/admin/index.ts +1 -1
- package/src/admin/routes/settings/paypal/_components/FieldRow.tsx +38 -29
- package/src/admin/routes/settings/paypal/_components/SectionCard.tsx +29 -26
- package/src/admin/routes/settings/paypal/_components/Tabs.tsx +49 -48
- package/src/admin/routes/settings/paypal/_components/Toast.tsx +63 -52
- package/src/admin/routes/settings/paypal/_utils/adminFetch.ts +52 -32
- package/src/admin/routes/settings/paypal/additional-settings/page.tsx +246 -139
- package/src/admin/routes/settings/paypal/advanced-card-payments/page.tsx +208 -123
- package/src/admin/routes/settings/paypal/apple-pay/page.tsx +9 -5
- package/src/admin/routes/settings/paypal/connection/page.tsx +974 -908
- package/src/admin/routes/settings/paypal/google-pay/page.tsx +9 -5
- package/src/admin/routes/settings/paypal/page.tsx +14 -13
- package/src/admin/routes/settings/paypal/pay-later-messaging/page.tsx +9 -5
- package/src/admin/routes/settings/paypal/paypal-settings/page.tsx +304 -273
- package/src/api/admin/payment-collections/[id]/payment-sessions/route.ts +48 -39
- package/src/api/admin/paypal/disconnect/route.ts +15 -14
- package/src/api/admin/paypal/environment/route.ts +34 -32
- package/src/api/admin/paypal/onboard-complete/route.ts +61 -50
- package/src/api/admin/paypal/onboarding-link/route.ts +91 -76
- package/src/api/admin/paypal/onboarding-status/route.ts +21 -20
- package/src/api/admin/paypal/save-credentials/route.ts +48 -37
- package/src/api/admin/paypal/settings/route.ts +63 -45
- package/src/api/admin/paypal/status/route.ts +29 -17
- package/src/api/hooks/paypal/onboard-return/route.ts +15 -15
- package/src/api/hooks/paypal/webhook/route.ts +17 -17
- package/src/api/middlewares.ts +61 -61
- package/src/api/store/payment-collections/[id]/payment-sessions/route.ts +63 -54
- package/src/api/store/paypal/capture-order/route.ts +416 -370
- package/src/api/store/paypal/config/route.ts +121 -115
- package/src/api/store/paypal/create-order/route.ts +586 -539
- package/src/api/store/paypal/onboard-return/route.ts +116 -113
- package/src/api/store/paypal/settings/route.ts +29 -19
- package/src/api/store/paypal/webhook/route.ts +380 -314
- package/src/api/store/paypal-complete/route.ts +157 -128
- package/src/api/utils/rate-limit.ts +143 -129
- package/src/index.ts +1 -1
- package/src/jobs/paypal-webhook-retry.ts +257 -241
- package/src/modules/paypal/index.ts +9 -8
- package/src/modules/paypal/migrations/20260115120000_create_paypal_connection.ts +33 -33
- package/src/modules/paypal/migrations/20260123090000_create_paypal_settings.ts +22 -22
- package/src/modules/paypal/migrations/20260201090000_create_paypal_webhook_event.ts +29 -29
- package/src/modules/paypal/migrations/20260401090000_create_paypal_metric.ts +27 -27
- package/src/modules/paypal/migrations/20260701090000_add_paypal_webhook_event_processing.ts +31 -31
- package/src/modules/paypal/migrations/20261101090000_remove_paypal_reconciliation_status.ts +25 -25
- package/src/modules/paypal/migrations/20261201090000_remove_paypal_audit_log.ts +26 -26
- package/src/modules/paypal/migrations/20270101090000_set_paypal_environment_default_live.ts +15 -11
- package/src/modules/paypal/migrations/20270102090000_add_paypal_seller_email.ts +15 -11
- package/src/modules/paypal/migrations/20270103090000_add_paypal_seller_merchant_id.ts +15 -11
- package/src/modules/paypal/migrations/20270201000000_add_webhook_dead_letter.ts +17 -17
- package/src/modules/paypal/migrations/20270202000000_align_nullable_defaults.ts +44 -44
- package/src/modules/paypal/migrations/20270301000000_add_webhook_transmission_id_index.ts +15 -15
- package/src/modules/paypal/models/paypal_connection.ts +28 -23
- package/src/modules/paypal/models/paypal_metric.ts +13 -9
- package/src/modules/paypal/models/paypal_settings.ts +13 -8
- package/src/modules/paypal/models/paypal_webhook_event.ts +26 -19
- package/src/modules/paypal/payment-provider/base-provider.ts +287 -275
- package/src/modules/paypal/payment-provider/card-service.ts +927 -855
- package/src/modules/paypal/payment-provider/index.ts +14 -15
- package/src/modules/paypal/payment-provider/service.ts +906 -836
- package/src/modules/paypal/payment-provider/status-utils.ts +59 -59
- package/src/modules/paypal/payment-provider/webhook-utils.ts +109 -109
- package/src/modules/paypal/service.ts +362 -115
- package/src/modules/paypal/types/config.ts +70 -65
- package/src/modules/paypal/utils/amounts.ts +123 -107
- package/src/modules/paypal/utils/core-workflow.ts +46 -46
- package/src/modules/paypal/utils/credential-resolver.ts +275 -271
- package/src/modules/paypal/utils/currencies.ts +97 -84
- package/src/modules/paypal/utils/partner.ts +8 -8
- package/src/modules/paypal/utils/payment-session.ts +144 -138
- package/src/modules/paypal/utils/paypal-auth.ts +6 -5
- package/src/modules/paypal/utils/paypal-fetch.ts +197 -181
- package/src/modules/paypal/utils/provider-ids.ts +21 -15
- package/src/modules/paypal/utils/secret-crypto.ts +226 -197
- package/src/modules/paypal/utils/webhook-verify.ts +61 -61
- package/src/modules/paypal/webhook-processor.ts +641 -573
- package/src/providers/paypal/index.ts +9 -8
- package/src/providers/paypal_card/index.ts +9 -8
- package/src/subscribers/paypal-order-invoice.ts +180 -173
- package/src/subscribers/paypal-webhook-process.ts +147 -131
- package/tsconfig.json +21 -31
|
@@ -1,197 +1,226 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* Format (
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
const
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
)
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
if (
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
1
|
+
import {
|
|
2
|
+
createCipheriv,
|
|
3
|
+
createDecipheriv,
|
|
4
|
+
createHash,
|
|
5
|
+
randomBytes,
|
|
6
|
+
scryptSync,
|
|
7
|
+
} from "crypto"
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Opt-in encryption-at-rest for PayPal secrets (client secret, app access
|
|
11
|
+
* token).
|
|
12
|
+
*
|
|
13
|
+
* Activated only when `PAYPAL_ENCRYPTION_KEY` is set. When it is unset (the
|
|
14
|
+
* default), both functions are the identity — behavior is byte-for-byte
|
|
15
|
+
* unchanged, so existing deployments are unaffected.
|
|
16
|
+
*
|
|
17
|
+
* Format (current): `enc:v2:<salt_b64>:<iv_b64>:<tag_b64>:<ciphertext_b64>`
|
|
18
|
+
* using AES-256-GCM with a key derived via **scrypt** over the env key and a
|
|
19
|
+
* random per-secret salt. scrypt is a memory-hard KDF, so even a low-entropy
|
|
20
|
+
* passphrase resists brute-force/rainbow-table attacks (the previous unsalted,
|
|
21
|
+
* single-pass SHA-256 did not).
|
|
22
|
+
*
|
|
23
|
+
* Format (legacy): `enc:v1:<iv_b64>:<tag_b64>:<ciphertext_b64>` with an
|
|
24
|
+
* unsalted SHA-256 key. Still decryptable so secrets written before the KDF
|
|
25
|
+
* upgrade keep working; they are transparently upgraded to v2 on the next save.
|
|
26
|
+
*
|
|
27
|
+
* Legacy plaintext values (no prefix) are returned as-is on decrypt.
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
const PREFIX_V2 = "enc:v2:"
|
|
31
|
+
const PREFIX_V1 = "enc:v1:"
|
|
32
|
+
|
|
33
|
+
// scrypt cost parameters. N=2^14 with r=8 needs ~16MB (128*N*r), which stays
|
|
34
|
+
// under Node's default 32MB scrypt memory limit while imposing a meaningful
|
|
35
|
+
// per-derivation cost. Derived keys are cached, so this runs at most once per
|
|
36
|
+
// (env key, salt) pair rather than on every encrypt/decrypt.
|
|
37
|
+
const SCRYPT_N = 16384
|
|
38
|
+
const SCRYPT_R = 8
|
|
39
|
+
const SCRYPT_P = 1
|
|
40
|
+
const KEY_LEN = 32
|
|
41
|
+
const SALT_LEN = 16
|
|
42
|
+
|
|
43
|
+
let cachedRaw: string | undefined
|
|
44
|
+
let cachedRawKey: string | null = null
|
|
45
|
+
let legacyV1Key: Buffer | null = null
|
|
46
|
+
const V2_KEY_CACHE_MAX = 100
|
|
47
|
+
const v2KeyCache = new Map<string, Buffer>()
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* `@types/node` 22.0-22.6 typed `Buffer` as `Buffer<ArrayBufferLike>`, which is
|
|
51
|
+
* rejected where the `crypto` APIs and `Buffer.concat` expect a plain
|
|
52
|
+
* `Uint8Array` (the regression was fixed in 22.8). Narrowing each byte view to
|
|
53
|
+
* `Uint8Array` at the call boundary sidesteps it without changing runtime
|
|
54
|
+
* behavior, and stays valid on every other `@types/node` / TypeScript version.
|
|
55
|
+
*/
|
|
56
|
+
const bytes = (view: Buffer): Uint8Array => view as unknown as Uint8Array
|
|
57
|
+
|
|
58
|
+
/** The raw env key (trimmed), or null when encryption is disabled. */
|
|
59
|
+
function getRawKey(): string | null {
|
|
60
|
+
const raw = (process.env.PAYPAL_ENCRYPTION_KEY || "").trim()
|
|
61
|
+
if (raw !== cachedRaw) {
|
|
62
|
+
cachedRaw = raw
|
|
63
|
+
cachedRawKey = raw || null
|
|
64
|
+
// The unsalted SHA-256 key is only needed to decrypt legacy v1 values.
|
|
65
|
+
legacyV1Key = raw ? createHash("sha256").update(raw).digest() : null
|
|
66
|
+
v2KeyCache.clear()
|
|
67
|
+
}
|
|
68
|
+
return cachedRawKey
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** Derive (and cache) the AES key for a v2 secret from the env key + salt. */
|
|
72
|
+
function deriveV2Key(raw: string, salt: Buffer): Buffer {
|
|
73
|
+
const cacheKey = `${raw}::${salt.toString("base64")}`
|
|
74
|
+
let key = v2KeyCache.get(cacheKey)
|
|
75
|
+
if (!key) {
|
|
76
|
+
key = scryptSync(raw, bytes(salt), KEY_LEN, {
|
|
77
|
+
N: SCRYPT_N,
|
|
78
|
+
r: SCRYPT_R,
|
|
79
|
+
p: SCRYPT_P,
|
|
80
|
+
})
|
|
81
|
+
if (v2KeyCache.size >= V2_KEY_CACHE_MAX) {
|
|
82
|
+
const oldest = v2KeyCache.keys().next().value
|
|
83
|
+
if (oldest !== undefined) v2KeyCache.delete(oldest)
|
|
84
|
+
}
|
|
85
|
+
v2KeyCache.set(cacheKey, key)
|
|
86
|
+
}
|
|
87
|
+
return key
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function gcmDecrypt(
|
|
91
|
+
key: Buffer,
|
|
92
|
+
ivB64: string,
|
|
93
|
+
tagB64: string,
|
|
94
|
+
ctB64: string
|
|
95
|
+
): string {
|
|
96
|
+
const decipher = createDecipheriv(
|
|
97
|
+
"aes-256-gcm",
|
|
98
|
+
bytes(key),
|
|
99
|
+
bytes(Buffer.from(ivB64, "base64"))
|
|
100
|
+
)
|
|
101
|
+
decipher.setAuthTag(bytes(Buffer.from(tagB64, "base64")))
|
|
102
|
+
const plaintext = Buffer.concat([
|
|
103
|
+
bytes(decipher.update(bytes(Buffer.from(ctB64, "base64")))),
|
|
104
|
+
bytes(decipher.final()),
|
|
105
|
+
])
|
|
106
|
+
return plaintext.toString("utf8")
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** True when `PAYPAL_ENCRYPTION_KEY` is configured. */
|
|
110
|
+
export function isSecretEncryptionEnabled(): boolean {
|
|
111
|
+
return getRawKey() !== null
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** True when `value` carries one of the `enc:v*:` ciphertext prefixes. */
|
|
115
|
+
export function isEncrypted(value: unknown): boolean {
|
|
116
|
+
return (
|
|
117
|
+
typeof value === "string" &&
|
|
118
|
+
(value.startsWith(PREFIX_V2) || value.startsWith(PREFIX_V1))
|
|
119
|
+
)
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
let warnedNoKey = false
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Surface (once) that secrets are being stored without encryption-at-rest. In a
|
|
126
|
+
* production environment this is a real exposure — client_secret / access_token
|
|
127
|
+
* land in the database as plaintext — so it is worth a loud warning. Set
|
|
128
|
+
* PAYPAL_ENCRYPTION_STRICT=true to make it a hard error instead (recommended for
|
|
129
|
+
* production once a key is provisioned), which fails the write rather than
|
|
130
|
+
* persisting a plaintext secret.
|
|
131
|
+
*/
|
|
132
|
+
function assertOrWarnNoEncryptionKey(): void {
|
|
133
|
+
const strict = String(
|
|
134
|
+
process.env.PAYPAL_ENCRYPTION_STRICT || ""
|
|
135
|
+
).toLowerCase()
|
|
136
|
+
if (strict === "true" || strict === "1") {
|
|
137
|
+
throw new Error(
|
|
138
|
+
"PAYPAL_ENCRYPTION_STRICT is enabled but PAYPAL_ENCRYPTION_KEY is not set. " +
|
|
139
|
+
"Set PAYPAL_ENCRYPTION_KEY to encrypt PayPal secrets at rest, or disable strict mode."
|
|
140
|
+
)
|
|
141
|
+
}
|
|
142
|
+
if (!warnedNoKey) {
|
|
143
|
+
warnedNoKey = true
|
|
144
|
+
const inProd = process.env.NODE_ENV === "production"
|
|
145
|
+
console.warn(
|
|
146
|
+
`[PayPal]${inProd ? " WARNING (production):" : ""} PAYPAL_ENCRYPTION_KEY is not set — ` +
|
|
147
|
+
"PayPal secrets (client_secret, access_token) are stored UNENCRYPTED. " +
|
|
148
|
+
"Set PAYPAL_ENCRYPTION_KEY to enable AES-256-GCM encryption at rest."
|
|
149
|
+
)
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Encrypt a secret for storage. Returns the input unchanged when no key is
|
|
155
|
+
* configured or when the value is empty/already encrypted. Always writes the
|
|
156
|
+
* current (v2) format.
|
|
157
|
+
*/
|
|
158
|
+
export function encryptSecret<T extends string | null | undefined>(
|
|
159
|
+
value: T
|
|
160
|
+
): T | string {
|
|
161
|
+
if (!value) {
|
|
162
|
+
return value
|
|
163
|
+
}
|
|
164
|
+
const raw = getRawKey()
|
|
165
|
+
if (!raw) {
|
|
166
|
+
if (!isEncrypted(value)) {
|
|
167
|
+
assertOrWarnNoEncryptionKey()
|
|
168
|
+
}
|
|
169
|
+
return value
|
|
170
|
+
}
|
|
171
|
+
if (isEncrypted(value)) {
|
|
172
|
+
return value
|
|
173
|
+
}
|
|
174
|
+
const salt = randomBytes(SALT_LEN)
|
|
175
|
+
const key = deriveV2Key(raw, salt)
|
|
176
|
+
const iv = randomBytes(12)
|
|
177
|
+
const cipher = createCipheriv("aes-256-gcm", bytes(key), bytes(iv))
|
|
178
|
+
const ciphertext = Buffer.concat([
|
|
179
|
+
bytes(cipher.update(String(value), "utf8")),
|
|
180
|
+
bytes(cipher.final()),
|
|
181
|
+
])
|
|
182
|
+
const tag = cipher.getAuthTag()
|
|
183
|
+
return `${PREFIX_V2}${salt.toString("base64")}:${iv.toString("base64")}:${tag.toString("base64")}:${ciphertext.toString("base64")}`
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Decrypt a stored secret. Returns non-encrypted (legacy plaintext) values
|
|
188
|
+
* unchanged. Throws if the value is encrypted but no key is configured, or if
|
|
189
|
+
* authentication fails (wrong key / tampering).
|
|
190
|
+
*/
|
|
191
|
+
export function decryptSecret<T extends string | null | undefined>(
|
|
192
|
+
value: T
|
|
193
|
+
): T | string {
|
|
194
|
+
if (!value || !isEncrypted(value)) {
|
|
195
|
+
return value
|
|
196
|
+
}
|
|
197
|
+
const raw = getRawKey()
|
|
198
|
+
if (!raw) {
|
|
199
|
+
throw new Error(
|
|
200
|
+
"PayPal secret is encrypted but PAYPAL_ENCRYPTION_KEY is not set. Restore the key to decrypt stored credentials."
|
|
201
|
+
)
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
if (String(value).startsWith(PREFIX_V2)) {
|
|
205
|
+
const body = String(value).slice(PREFIX_V2.length)
|
|
206
|
+
const [saltB64, ivB64, tagB64, ctB64] = body.split(":")
|
|
207
|
+
if (!saltB64 || !ivB64 || !tagB64 || !ctB64) {
|
|
208
|
+
throw new Error("PayPal secret ciphertext is malformed.")
|
|
209
|
+
}
|
|
210
|
+
const key = deriveV2Key(raw, Buffer.from(saltB64, "base64"))
|
|
211
|
+
return gcmDecrypt(key, ivB64, tagB64, ctB64)
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// Legacy v1 (unsalted SHA-256 key).
|
|
215
|
+
const body = String(value).slice(PREFIX_V1.length)
|
|
216
|
+
const [ivB64, tagB64, ctB64] = body.split(":")
|
|
217
|
+
if (!ivB64 || !tagB64 || !ctB64) {
|
|
218
|
+
throw new Error("PayPal secret ciphertext is malformed.")
|
|
219
|
+
}
|
|
220
|
+
if (!legacyV1Key) {
|
|
221
|
+
throw new Error(
|
|
222
|
+
"PayPal secret is encrypted but PAYPAL_ENCRYPTION_KEY is not set."
|
|
223
|
+
)
|
|
224
|
+
}
|
|
225
|
+
return gcmDecrypt(legacyV1Key, ivB64, tagB64, ctB64)
|
|
226
|
+
}
|
|
@@ -1,61 +1,61 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Helpers for calling PayPal's `verify-webhook-signature` API correctly.
|
|
3
|
-
*
|
|
4
|
-
* PayPal computes the expected signature over the EXACT bytes it transmitted.
|
|
5
|
-
* Re-serializing the parsed body (`JSON.stringify(req.body)`) can change those
|
|
6
|
-
* bytes — key ordering, non-ASCII escaping (`José` vs `José`), number and
|
|
7
|
-
* whitespace formatting — which makes verification intermittently return
|
|
8
|
-
* FAILURE for legitimate webhooks. When the original raw body is available we
|
|
9
|
-
* inject it verbatim as `webhook_event`; otherwise we fall back to serializing
|
|
10
|
-
* the parsed body so behavior never regresses.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
/** Normalize Medusa's `req.rawBody` (a Buffer when `preserveRawBody` is set) to a string. */
|
|
14
|
-
export function rawBodyToString(rawBody: unknown): string | null {
|
|
15
|
-
if (rawBody == null) {
|
|
16
|
-
return null
|
|
17
|
-
}
|
|
18
|
-
if (typeof rawBody === "string") {
|
|
19
|
-
return rawBody.length > 0 ? rawBody : null
|
|
20
|
-
}
|
|
21
|
-
if (Buffer.isBuffer(rawBody)) {
|
|
22
|
-
return rawBody.length > 0 ? rawBody.toString("utf8") : null
|
|
23
|
-
}
|
|
24
|
-
if (rawBody instanceof Uint8Array) {
|
|
25
|
-
return rawBody.length > 0 ? Buffer.from(rawBody).toString("utf8") : null
|
|
26
|
-
}
|
|
27
|
-
return null
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Compose the JSON request body for `verify-webhook-signature`.
|
|
32
|
-
*
|
|
33
|
-
* `fields` are the transmission headers + webhook_id; `webhookEventJson` is the
|
|
34
|
-
* raw webhook body verbatim (preferred) or a serialized fallback. Undefined /
|
|
35
|
-
* null header values are omitted. The webhook event is concatenated as raw JSON
|
|
36
|
-
* (not re-encoded) so the bytes PayPal hashes match what it signed.
|
|
37
|
-
*/
|
|
38
|
-
export function composeVerifyRequestBody(
|
|
39
|
-
fields: Record<string, string | undefined | null>,
|
|
40
|
-
webhookEventJson: string
|
|
41
|
-
): string {
|
|
42
|
-
const head = Object.entries(fields)
|
|
43
|
-
.filter(([, v]) => v !== undefined && v !== null)
|
|
44
|
-
.map(([k, v]) => `${JSON.stringify(k)}:${JSON.stringify(v)}`)
|
|
45
|
-
.join(",")
|
|
46
|
-
return `{${head}${head ? "," : ""}"webhook_event":${webhookEventJson}}`
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Pick the bytes to use for `webhook_event`: the raw body when present and
|
|
51
|
-
* non-blank, otherwise a JSON serialization of the parsed body.
|
|
52
|
-
*/
|
|
53
|
-
export function resolveWebhookEventJson(
|
|
54
|
-
rawBody: string | null | undefined,
|
|
55
|
-
parsedBody: unknown
|
|
56
|
-
): string {
|
|
57
|
-
if (typeof rawBody === "string" && rawBody.trim().length > 0) {
|
|
58
|
-
return rawBody
|
|
59
|
-
}
|
|
60
|
-
return JSON.stringify(parsedBody ?? {})
|
|
61
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Helpers for calling PayPal's `verify-webhook-signature` API correctly.
|
|
3
|
+
*
|
|
4
|
+
* PayPal computes the expected signature over the EXACT bytes it transmitted.
|
|
5
|
+
* Re-serializing the parsed body (`JSON.stringify(req.body)`) can change those
|
|
6
|
+
* bytes — key ordering, non-ASCII escaping (`José` vs `José`), number and
|
|
7
|
+
* whitespace formatting — which makes verification intermittently return
|
|
8
|
+
* FAILURE for legitimate webhooks. When the original raw body is available we
|
|
9
|
+
* inject it verbatim as `webhook_event`; otherwise we fall back to serializing
|
|
10
|
+
* the parsed body so behavior never regresses.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/** Normalize Medusa's `req.rawBody` (a Buffer when `preserveRawBody` is set) to a string. */
|
|
14
|
+
export function rawBodyToString(rawBody: unknown): string | null {
|
|
15
|
+
if (rawBody == null) {
|
|
16
|
+
return null
|
|
17
|
+
}
|
|
18
|
+
if (typeof rawBody === "string") {
|
|
19
|
+
return rawBody.length > 0 ? rawBody : null
|
|
20
|
+
}
|
|
21
|
+
if (Buffer.isBuffer(rawBody)) {
|
|
22
|
+
return rawBody.length > 0 ? rawBody.toString("utf8") : null
|
|
23
|
+
}
|
|
24
|
+
if (rawBody instanceof Uint8Array) {
|
|
25
|
+
return rawBody.length > 0 ? Buffer.from(rawBody).toString("utf8") : null
|
|
26
|
+
}
|
|
27
|
+
return null
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Compose the JSON request body for `verify-webhook-signature`.
|
|
32
|
+
*
|
|
33
|
+
* `fields` are the transmission headers + webhook_id; `webhookEventJson` is the
|
|
34
|
+
* raw webhook body verbatim (preferred) or a serialized fallback. Undefined /
|
|
35
|
+
* null header values are omitted. The webhook event is concatenated as raw JSON
|
|
36
|
+
* (not re-encoded) so the bytes PayPal hashes match what it signed.
|
|
37
|
+
*/
|
|
38
|
+
export function composeVerifyRequestBody(
|
|
39
|
+
fields: Record<string, string | undefined | null>,
|
|
40
|
+
webhookEventJson: string
|
|
41
|
+
): string {
|
|
42
|
+
const head = Object.entries(fields)
|
|
43
|
+
.filter(([, v]) => v !== undefined && v !== null)
|
|
44
|
+
.map(([k, v]) => `${JSON.stringify(k)}:${JSON.stringify(v)}`)
|
|
45
|
+
.join(",")
|
|
46
|
+
return `{${head}${head ? "," : ""}"webhook_event":${webhookEventJson}}`
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Pick the bytes to use for `webhook_event`: the raw body when present and
|
|
51
|
+
* non-blank, otherwise a JSON serialization of the parsed body.
|
|
52
|
+
*/
|
|
53
|
+
export function resolveWebhookEventJson(
|
|
54
|
+
rawBody: string | null | undefined,
|
|
55
|
+
parsedBody: unknown
|
|
56
|
+
): string {
|
|
57
|
+
if (typeof rawBody === "string" && rawBody.trim().length > 0) {
|
|
58
|
+
return rawBody
|
|
59
|
+
}
|
|
60
|
+
return JSON.stringify(parsedBody ?? {})
|
|
61
|
+
}
|