@vandenberghinc/volt 1.2.5 → 1.2.6
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/frontend/assets/admin/admin.png +0 -0
- package/frontend/assets/admin/password.webp +0 -0
- package/frontend/assets/icons/arrow.v1.webp +0 -0
- package/frontend/assets/icons/copy.webp +0 -0
- package/frontend/assets/payments/arrow.long.webp +0 -0
- package/frontend/assets/payments/arrow.long2.webp +0 -0
- package/frontend/assets/payments/cancelled.webp +0 -0
- package/frontend/assets/payments/check.sign.webp +0 -0
- package/frontend/assets/payments/check.webp +0 -0
- package/frontend/assets/payments/close.webp +0 -0
- package/frontend/assets/payments/error.webp +0 -0
- package/frontend/assets/payments/exclamation.webp +0 -0
- package/frontend/assets/payments/minus.webp +0 -0
- package/frontend/assets/payments/party.webp +0 -0
- package/frontend/assets/payments/plus.webp +0 -0
- package/frontend/assets/payments/shopping_cart.webp +0 -0
- package/frontend/assets/payments/trash.webp +0 -0
- package/package.json +5 -1
- package/.libris/config.json +0 -82
- package/backend/dist/cjs/backend/src/blacklist.d.ts +0 -12
- package/backend/dist/cjs/backend/src/blacklist.js +0 -78
- package/backend/dist/cjs/backend/src/cli.d.ts +0 -2
- package/backend/dist/cjs/backend/src/cli.js +0 -198
- package/backend/dist/cjs/backend/src/database/collection.d.ts +0 -1765
- package/backend/dist/cjs/backend/src/database/collection.js +0 -3301
- package/backend/dist/cjs/backend/src/database/database.d.ts +0 -92
- package/backend/dist/cjs/backend/src/database/database.js +0 -170
- package/backend/dist/cjs/backend/src/database/document.d.ts +0 -1
- package/backend/dist/cjs/backend/src/database/document.js +0 -15
- package/backend/dist/cjs/backend/src/database/filters/filters.d.ts +0 -6
- package/backend/dist/cjs/backend/src/database/filters/filters.js +0 -15
- package/backend/dist/cjs/backend/src/database/filters/strict_filter.d.ts +0 -223
- package/backend/dist/cjs/backend/src/database/filters/strict_filter.js +0 -15
- package/backend/dist/cjs/backend/src/database/filters/strict_filter_test.d.ts +0 -1
- package/backend/dist/cjs/backend/src/database/filters/strict_filter_test.js +0 -443
- package/backend/dist/cjs/backend/src/database/filters/strict_filter_test_v0.d.ts +0 -1
- package/backend/dist/cjs/backend/src/database/filters/strict_filter_test_v0.js +0 -15
- package/backend/dist/cjs/backend/src/database/filters/strict_filter_v0.d.ts +0 -50
- package/backend/dist/cjs/backend/src/database/filters/strict_filter_v0.js +0 -15
- package/backend/dist/cjs/backend/src/database/filters/strict_filter_v1.d.ts +0 -76
- package/backend/dist/cjs/backend/src/database/filters/strict_filter_v1.js +0 -15
- package/backend/dist/cjs/backend/src/database/filters/strict_filter_v2.d.ts +0 -75
- package/backend/dist/cjs/backend/src/database/filters/strict_filter_v2.js +0 -15
- package/backend/dist/cjs/backend/src/database/filters/strict_filter_v3.d.ts +0 -219
- package/backend/dist/cjs/backend/src/database/filters/strict_filter_v3.js +0 -15
- package/backend/dist/cjs/backend/src/database/filters/strict_update_filter.d.ts +0 -165
- package/backend/dist/cjs/backend/src/database/filters/strict_update_filter.js +0 -15
- package/backend/dist/cjs/backend/src/database/filters/strict_update_filter_test.d.ts +0 -5
- package/backend/dist/cjs/backend/src/database/filters/strict_update_filter_test.js +0 -355
- package/backend/dist/cjs/backend/src/database/flatten.d.ts +0 -78
- package/backend/dist/cjs/backend/src/database/flatten.js +0 -53
- package/backend/dist/cjs/backend/src/database/flatten_test.d.ts +0 -1
- package/backend/dist/cjs/backend/src/database/flatten_test.js +0 -175
- package/backend/dist/cjs/backend/src/database/quota/quoata_v2.d.ts +0 -533
- package/backend/dist/cjs/backend/src/database/quota/quoata_v2.js +0 -1046
- package/backend/dist/cjs/backend/src/database/quota/quota.d.ts +0 -551
- package/backend/dist/cjs/backend/src/database/quota/quota.js +0 -1108
- package/backend/dist/cjs/backend/src/database/quota/quota_v1.d.ts +0 -534
- package/backend/dist/cjs/backend/src/database/quota/quota_v1.js +0 -1087
- package/backend/dist/cjs/backend/src/database/quota/safe_int.d.ts +0 -412
- package/backend/dist/cjs/backend/src/database/quota/safe_int.js +0 -745
- package/backend/dist/cjs/backend/src/endpoint.d.ts +0 -346
- package/backend/dist/cjs/backend/src/endpoint.js +0 -468
- package/backend/dist/cjs/backend/src/errors/index.d.ts +0 -7
- package/backend/dist/cjs/backend/src/errors/index.js +0 -25
- package/backend/dist/cjs/backend/src/errors/internal_external.d.ts +0 -52
- package/backend/dist/cjs/backend/src/errors/internal_external.js +0 -95
- package/backend/dist/cjs/backend/src/errors/invalid_usage_error.d.ts +0 -41
- package/backend/dist/cjs/backend/src/errors/invalid_usage_error.js +0 -47
- package/backend/dist/cjs/backend/src/errors/system_error.d.ts +0 -261
- package/backend/dist/cjs/backend/src/errors/system_error.js +0 -436
- package/backend/dist/cjs/backend/src/events.d.ts +0 -97
- package/backend/dist/cjs/backend/src/events.js +0 -15
- package/backend/dist/cjs/backend/src/frontend.d.ts +0 -11
- package/backend/dist/cjs/backend/src/frontend.js +0 -37
- package/backend/dist/cjs/backend/src/image_endpoint.d.ts +0 -44
- package/backend/dist/cjs/backend/src/image_endpoint.js +0 -185
- package/backend/dist/cjs/backend/src/index.d.ts +0 -23
- package/backend/dist/cjs/backend/src/index.js +0 -70
- package/backend/dist/cjs/backend/src/logger.d.ts +0 -5
- package/backend/dist/cjs/backend/src/logger.js +0 -15
- package/backend/dist/cjs/backend/src/meta.d.ts +0 -112
- package/backend/dist/cjs/backend/src/meta.js +0 -181
- package/backend/dist/cjs/backend/src/payments/paddle.d.ts +0 -329
- package/backend/dist/cjs/backend/src/payments/paddle.js +0 -1996
- package/backend/dist/cjs/backend/src/payments/stripe/checkout.d.ts +0 -113
- package/backend/dist/cjs/backend/src/payments/stripe/checkout.js +0 -295
- package/backend/dist/cjs/backend/src/payments/stripe/customers.d.ts +0 -17
- package/backend/dist/cjs/backend/src/payments/stripe/customers.js +0 -164
- package/backend/dist/cjs/backend/src/payments/stripe/error.d.ts +0 -74
- package/backend/dist/cjs/backend/src/payments/stripe/error.js +0 -64
- package/backend/dist/cjs/backend/src/payments/stripe/events.d.ts +0 -155
- package/backend/dist/cjs/backend/src/payments/stripe/events.js +0 -15
- package/backend/dist/cjs/backend/src/payments/stripe/meters.d.ts +0 -105
- package/backend/dist/cjs/backend/src/payments/stripe/meters.js +0 -230
- package/backend/dist/cjs/backend/src/payments/stripe/payment_methods.d.ts +0 -58
- package/backend/dist/cjs/backend/src/payments/stripe/payment_methods.js +0 -109
- package/backend/dist/cjs/backend/src/payments/stripe/products.d.ts +0 -519
- package/backend/dist/cjs/backend/src/payments/stripe/products.js +0 -650
- package/backend/dist/cjs/backend/src/payments/stripe/stripe.d.ts +0 -215
- package/backend/dist/cjs/backend/src/payments/stripe/stripe.js +0 -468
- package/backend/dist/cjs/backend/src/payments/stripe/subscriptions.d.ts +0 -172
- package/backend/dist/cjs/backend/src/payments/stripe/subscriptions.js +0 -557
- package/backend/dist/cjs/backend/src/payments/stripe/utils.d.ts +0 -63
- package/backend/dist/cjs/backend/src/payments/stripe/utils.js +0 -118
- package/backend/dist/cjs/backend/src/payments/stripe/webhooks.d.ts +0 -105
- package/backend/dist/cjs/backend/src/payments/stripe/webhooks.js +0 -627
- package/backend/dist/cjs/backend/src/plugins/browser.d.ts +0 -1
- package/backend/dist/cjs/backend/src/plugins/browser.js +0 -15
- package/backend/dist/cjs/backend/src/plugins/communication.d.ts +0 -70
- package/backend/dist/cjs/backend/src/plugins/communication.js +0 -196
- package/backend/dist/cjs/backend/src/plugins/mail/mail.d.ts +0 -255
- package/backend/dist/cjs/backend/src/plugins/mail/mail.js +0 -381
- package/backend/dist/cjs/backend/src/plugins/mail/ui.d.ts +0 -297
- package/backend/dist/cjs/backend/src/plugins/mail/ui.js +0 -1370
- package/backend/dist/cjs/backend/src/plugins/pdf.d.ts +0 -1
- package/backend/dist/cjs/backend/src/plugins/pdf.js +0 -1456
- package/backend/dist/cjs/backend/src/plugins/thread_monitor.d.ts +0 -18
- package/backend/dist/cjs/backend/src/plugins/thread_monitor.js +0 -116
- package/backend/dist/cjs/backend/src/rate_limit.d.ts +0 -148
- package/backend/dist/cjs/backend/src/rate_limit.js +0 -543
- package/backend/dist/cjs/backend/src/route.d.ts +0 -39
- package/backend/dist/cjs/backend/src/route.js +0 -172
- package/backend/dist/cjs/backend/src/server.d.ts +0 -502
- package/backend/dist/cjs/backend/src/server.js +0 -1713
- package/backend/dist/cjs/backend/src/server.old.d.ts +0 -594
- package/backend/dist/cjs/backend/src/server.old.js +0 -2058
- package/backend/dist/cjs/backend/src/splash_screen.d.ts +0 -93
- package/backend/dist/cjs/backend/src/splash_screen.js +0 -119
- package/backend/dist/cjs/backend/src/status.d.ts +0 -89
- package/backend/dist/cjs/backend/src/status.js +0 -211
- package/backend/dist/cjs/backend/src/stream.d.ts +0 -494
- package/backend/dist/cjs/backend/src/stream.js +0 -1370
- package/backend/dist/cjs/backend/src/users.d.ts +0 -926
- package/backend/dist/cjs/backend/src/users.js +0 -2223
- package/backend/dist/cjs/backend/src/utils.d.ts +0 -22
- package/backend/dist/cjs/backend/src/utils.js +0 -626
- package/backend/dist/cjs/backend/src/view.d.ts +0 -115
- package/backend/dist/cjs/backend/src/view.js +0 -519
- package/backend/dist/cjs/backend/src/vinc.d.ts +0 -6
- package/backend/dist/cjs/backend/src/vinc.js +0 -40
- package/backend/dist/cjs/backend/src/volt.d.ts +0 -24
- package/backend/dist/cjs/backend/src/volt.js +0 -72
- package/backend/dist/cjs/frontend/src/modules/request.d.ts +0 -70
- package/backend/dist/cjs/frontend/src/modules/request.js +0 -99
- package/backend/dist/cjs/package.json +0 -1
- package/backend/dist/esm/backend/src/blacklist.d.ts +0 -12
- package/backend/dist/esm/backend/src/blacklist.js +0 -52
- package/backend/dist/esm/backend/src/cli.d.ts +0 -2
- package/backend/dist/esm/backend/src/cli.js +0 -211
- package/backend/dist/esm/backend/src/database/collection.d.ts +0 -1765
- package/backend/dist/esm/backend/src/database/collection.js +0 -3779
- package/backend/dist/esm/backend/src/database/database.d.ts +0 -92
- package/backend/dist/esm/backend/src/database/database.js +0 -214
- package/backend/dist/esm/backend/src/database/document.d.ts +0 -1
- package/backend/dist/esm/backend/src/database/document.js +0 -558
- package/backend/dist/esm/backend/src/database/filters/filters.d.ts +0 -6
- package/backend/dist/esm/backend/src/database/filters/filters.js +0 -1
- package/backend/dist/esm/backend/src/database/filters/strict_filter.d.ts +0 -223
- package/backend/dist/esm/backend/src/database/filters/strict_filter.js +0 -3
- package/backend/dist/esm/backend/src/database/filters/strict_filter_test.d.ts +0 -1
- package/backend/dist/esm/backend/src/database/filters/strict_filter_test.js +0 -505
- package/backend/dist/esm/backend/src/database/filters/strict_filter_test_v0.d.ts +0 -1
- package/backend/dist/esm/backend/src/database/filters/strict_filter_test_v0.js +0 -712
- package/backend/dist/esm/backend/src/database/filters/strict_filter_v0.d.ts +0 -50
- package/backend/dist/esm/backend/src/database/filters/strict_filter_v0.js +0 -5
- package/backend/dist/esm/backend/src/database/filters/strict_filter_v1.d.ts +0 -76
- package/backend/dist/esm/backend/src/database/filters/strict_filter_v1.js +0 -44
- package/backend/dist/esm/backend/src/database/filters/strict_filter_v2.d.ts +0 -75
- package/backend/dist/esm/backend/src/database/filters/strict_filter_v2.js +0 -5
- package/backend/dist/esm/backend/src/database/filters/strict_filter_v3.d.ts +0 -219
- package/backend/dist/esm/backend/src/database/filters/strict_filter_v3.js +0 -1
- package/backend/dist/esm/backend/src/database/filters/strict_update_filter.d.ts +0 -165
- package/backend/dist/esm/backend/src/database/filters/strict_update_filter.js +0 -5
- package/backend/dist/esm/backend/src/database/filters/strict_update_filter_test.d.ts +0 -5
- package/backend/dist/esm/backend/src/database/filters/strict_update_filter_test.js +0 -415
- package/backend/dist/esm/backend/src/database/flatten.d.ts +0 -78
- package/backend/dist/esm/backend/src/database/flatten.js +0 -22
- package/backend/dist/esm/backend/src/database/flatten_test.d.ts +0 -1
- package/backend/dist/esm/backend/src/database/flatten_test.js +0 -174
- package/backend/dist/esm/backend/src/database/quota/quoata_v2.d.ts +0 -533
- package/backend/dist/esm/backend/src/database/quota/quoata_v2.js +0 -1155
- package/backend/dist/esm/backend/src/database/quota/quota.d.ts +0 -551
- package/backend/dist/esm/backend/src/database/quota/quota.js +0 -1219
- package/backend/dist/esm/backend/src/database/quota/quota_v1.d.ts +0 -534
- package/backend/dist/esm/backend/src/database/quota/quota_v1.js +0 -1242
- package/backend/dist/esm/backend/src/database/quota/safe_int.d.ts +0 -412
- package/backend/dist/esm/backend/src/database/quota/safe_int.js +0 -810
- package/backend/dist/esm/backend/src/endpoint.d.ts +0 -346
- package/backend/dist/esm/backend/src/endpoint.js +0 -479
- package/backend/dist/esm/backend/src/errors/index.d.ts +0 -7
- package/backend/dist/esm/backend/src/errors/index.js +0 -7
- package/backend/dist/esm/backend/src/errors/internal_external.d.ts +0 -52
- package/backend/dist/esm/backend/src/errors/internal_external.js +0 -86
- package/backend/dist/esm/backend/src/errors/invalid_usage_error.d.ts +0 -41
- package/backend/dist/esm/backend/src/errors/invalid_usage_error.js +0 -33
- package/backend/dist/esm/backend/src/errors/system_error.d.ts +0 -261
- package/backend/dist/esm/backend/src/errors/system_error.js +0 -444
- package/backend/dist/esm/backend/src/events.d.ts +0 -97
- package/backend/dist/esm/backend/src/events.js +0 -5
- package/backend/dist/esm/backend/src/frontend.d.ts +0 -11
- package/backend/dist/esm/backend/src/frontend.js +0 -12
- package/backend/dist/esm/backend/src/image_endpoint.d.ts +0 -44
- package/backend/dist/esm/backend/src/image_endpoint.js +0 -196
- package/backend/dist/esm/backend/src/index.d.ts +0 -23
- package/backend/dist/esm/backend/src/index.js +0 -26
- package/backend/dist/esm/backend/src/logger.d.ts +0 -5
- package/backend/dist/esm/backend/src/logger.js +0 -8
- package/backend/dist/esm/backend/src/meta.d.ts +0 -112
- package/backend/dist/esm/backend/src/meta.js +0 -152
- package/backend/dist/esm/backend/src/payments/paddle.d.ts +0 -329
- package/backend/dist/esm/backend/src/payments/paddle.js +0 -2276
- package/backend/dist/esm/backend/src/payments/stripe/checkout.d.ts +0 -113
- package/backend/dist/esm/backend/src/payments/stripe/checkout.js +0 -356
- package/backend/dist/esm/backend/src/payments/stripe/customers.d.ts +0 -17
- package/backend/dist/esm/backend/src/payments/stripe/customers.js +0 -193
- package/backend/dist/esm/backend/src/payments/stripe/error.d.ts +0 -74
- package/backend/dist/esm/backend/src/payments/stripe/error.js +0 -51
- package/backend/dist/esm/backend/src/payments/stripe/events.d.ts +0 -155
- package/backend/dist/esm/backend/src/payments/stripe/events.js +0 -5
- package/backend/dist/esm/backend/src/payments/stripe/meters.d.ts +0 -105
- package/backend/dist/esm/backend/src/payments/stripe/meters.js +0 -318
- package/backend/dist/esm/backend/src/payments/stripe/payment_methods.d.ts +0 -58
- package/backend/dist/esm/backend/src/payments/stripe/payment_methods.js +0 -135
- package/backend/dist/esm/backend/src/payments/stripe/products.d.ts +0 -519
- package/backend/dist/esm/backend/src/payments/stripe/products.js +0 -896
- package/backend/dist/esm/backend/src/payments/stripe/stripe.d.ts +0 -215
- package/backend/dist/esm/backend/src/payments/stripe/stripe.js +0 -464
- package/backend/dist/esm/backend/src/payments/stripe/subscriptions.d.ts +0 -172
- package/backend/dist/esm/backend/src/payments/stripe/subscriptions.js +0 -754
- package/backend/dist/esm/backend/src/payments/stripe/utils.d.ts +0 -63
- package/backend/dist/esm/backend/src/payments/stripe/utils.js +0 -131
- package/backend/dist/esm/backend/src/payments/stripe/webhooks.d.ts +0 -105
- package/backend/dist/esm/backend/src/payments/stripe/webhooks.js +0 -752
- package/backend/dist/esm/backend/src/plugins/browser.d.ts +0 -1
- package/backend/dist/esm/backend/src/plugins/browser.js +0 -170
- package/backend/dist/esm/backend/src/plugins/communication.d.ts +0 -70
- package/backend/dist/esm/backend/src/plugins/communication.js +0 -169
- package/backend/dist/esm/backend/src/plugins/mail/mail.d.ts +0 -255
- package/backend/dist/esm/backend/src/plugins/mail/mail.js +0 -396
- package/backend/dist/esm/backend/src/plugins/mail/ui.d.ts +0 -297
- package/backend/dist/esm/backend/src/plugins/mail/ui.js +0 -1400
- package/backend/dist/esm/backend/src/plugins/pdf.d.ts +0 -1
- package/backend/dist/esm/backend/src/plugins/pdf.js +0 -1694
- package/backend/dist/esm/backend/src/plugins/thread_monitor.d.ts +0 -18
- package/backend/dist/esm/backend/src/plugins/thread_monitor.js +0 -120
- package/backend/dist/esm/backend/src/rate_limit.d.ts +0 -148
- package/backend/dist/esm/backend/src/rate_limit.js +0 -667
- package/backend/dist/esm/backend/src/route.d.ts +0 -39
- package/backend/dist/esm/backend/src/route.js +0 -222
- package/backend/dist/esm/backend/src/server.d.ts +0 -502
- package/backend/dist/esm/backend/src/server.js +0 -2034
- package/backend/dist/esm/backend/src/server.old.d.ts +0 -594
- package/backend/dist/esm/backend/src/server.old.js +0 -2630
- package/backend/dist/esm/backend/src/splash_screen.d.ts +0 -93
- package/backend/dist/esm/backend/src/splash_screen.js +0 -156
- package/backend/dist/esm/backend/src/status.d.ts +0 -89
- package/backend/dist/esm/backend/src/status.js +0 -213
- package/backend/dist/esm/backend/src/stream.d.ts +0 -494
- package/backend/dist/esm/backend/src/stream.js +0 -1611
- package/backend/dist/esm/backend/src/users.d.ts +0 -926
- package/backend/dist/esm/backend/src/users.js +0 -2423
- package/backend/dist/esm/backend/src/utils.d.ts +0 -22
- package/backend/dist/esm/backend/src/utils.js +0 -463
- package/backend/dist/esm/backend/src/view.d.ts +0 -115
- package/backend/dist/esm/backend/src/view.js +0 -584
- package/backend/dist/esm/backend/src/vinc.d.ts +0 -6
- package/backend/dist/esm/backend/src/vinc.js +0 -6
- package/backend/dist/esm/backend/src/volt.d.ts +0 -24
- package/backend/dist/esm/backend/src/volt.js +0 -27
- package/backend/dist/esm/frontend/src/modules/request.d.ts +0 -70
- package/backend/dist/esm/frontend/src/modules/request.js +0 -117
- package/backend/old/file_watcher.ts +0 -359
- package/backend/old/request.deprc.js +0 -626
- package/backend/old/response.deprc.js +0 -354
- package/frontend/dist/backend/src/database/collection.d.ts +0 -1765
- package/frontend/dist/backend/src/database/collection.js +0 -3779
- package/frontend/dist/backend/src/database/database.d.ts +0 -92
- package/frontend/dist/backend/src/database/database.js +0 -214
- package/frontend/dist/backend/src/database/filters/filters.d.ts +0 -6
- package/frontend/dist/backend/src/database/filters/filters.js +0 -1
- package/frontend/dist/backend/src/database/filters/strict_filter.d.ts +0 -223
- package/frontend/dist/backend/src/database/filters/strict_filter.js +0 -3
- package/frontend/dist/backend/src/database/filters/strict_update_filter.d.ts +0 -165
- package/frontend/dist/backend/src/database/filters/strict_update_filter.js +0 -5
- package/frontend/dist/backend/src/database/flatten.d.ts +0 -78
- package/frontend/dist/backend/src/database/flatten.js +0 -22
- package/frontend/dist/backend/src/endpoint.d.ts +0 -346
- package/frontend/dist/backend/src/endpoint.js +0 -479
- package/frontend/dist/backend/src/errors/index.d.ts +0 -7
- package/frontend/dist/backend/src/errors/index.js +0 -7
- package/frontend/dist/backend/src/errors/internal_external.d.ts +0 -52
- package/frontend/dist/backend/src/errors/internal_external.js +0 -86
- package/frontend/dist/backend/src/errors/invalid_usage_error.d.ts +0 -41
- package/frontend/dist/backend/src/errors/invalid_usage_error.js +0 -33
- package/frontend/dist/backend/src/errors/system_error.d.ts +0 -261
- package/frontend/dist/backend/src/errors/system_error.js +0 -444
- package/frontend/dist/backend/src/events.d.ts +0 -97
- package/frontend/dist/backend/src/events.js +0 -5
- package/frontend/dist/backend/src/frontend.d.ts +0 -11
- package/frontend/dist/backend/src/frontend.js +0 -12
- package/frontend/dist/backend/src/image_endpoint.d.ts +0 -44
- package/frontend/dist/backend/src/image_endpoint.js +0 -196
- package/frontend/dist/backend/src/meta.d.ts +0 -112
- package/frontend/dist/backend/src/meta.js +0 -152
- package/frontend/dist/backend/src/payments/paddle.d.ts +0 -329
- package/frontend/dist/backend/src/payments/paddle.js +0 -2276
- package/frontend/dist/backend/src/payments/stripe/checkout.d.ts +0 -113
- package/frontend/dist/backend/src/payments/stripe/checkout.js +0 -356
- package/frontend/dist/backend/src/payments/stripe/customers.d.ts +0 -17
- package/frontend/dist/backend/src/payments/stripe/customers.js +0 -193
- package/frontend/dist/backend/src/payments/stripe/error.d.ts +0 -74
- package/frontend/dist/backend/src/payments/stripe/error.js +0 -51
- package/frontend/dist/backend/src/payments/stripe/events.d.ts +0 -155
- package/frontend/dist/backend/src/payments/stripe/events.js +0 -5
- package/frontend/dist/backend/src/payments/stripe/meters.d.ts +0 -105
- package/frontend/dist/backend/src/payments/stripe/meters.js +0 -318
- package/frontend/dist/backend/src/payments/stripe/payment_methods.d.ts +0 -58
- package/frontend/dist/backend/src/payments/stripe/payment_methods.js +0 -135
- package/frontend/dist/backend/src/payments/stripe/products.d.ts +0 -519
- package/frontend/dist/backend/src/payments/stripe/products.js +0 -896
- package/frontend/dist/backend/src/payments/stripe/stripe.d.ts +0 -215
- package/frontend/dist/backend/src/payments/stripe/stripe.js +0 -464
- package/frontend/dist/backend/src/payments/stripe/subscriptions.d.ts +0 -172
- package/frontend/dist/backend/src/payments/stripe/subscriptions.js +0 -754
- package/frontend/dist/backend/src/payments/stripe/utils.d.ts +0 -63
- package/frontend/dist/backend/src/payments/stripe/utils.js +0 -131
- package/frontend/dist/backend/src/payments/stripe/webhooks.d.ts +0 -105
- package/frontend/dist/backend/src/payments/stripe/webhooks.js +0 -752
- package/frontend/dist/backend/src/plugins/mail/mail.d.ts +0 -255
- package/frontend/dist/backend/src/plugins/mail/mail.js +0 -396
- package/frontend/dist/backend/src/plugins/mail/ui.d.ts +0 -297
- package/frontend/dist/backend/src/plugins/mail/ui.js +0 -1400
- package/frontend/dist/backend/src/rate_limit.d.ts +0 -148
- package/frontend/dist/backend/src/rate_limit.js +0 -667
- package/frontend/dist/backend/src/route.d.ts +0 -39
- package/frontend/dist/backend/src/route.js +0 -222
- package/frontend/dist/backend/src/server.d.ts +0 -502
- package/frontend/dist/backend/src/server.js +0 -2034
- package/frontend/dist/backend/src/splash_screen.d.ts +0 -93
- package/frontend/dist/backend/src/splash_screen.js +0 -156
- package/frontend/dist/backend/src/status.d.ts +0 -89
- package/frontend/dist/backend/src/status.js +0 -213
- package/frontend/dist/backend/src/stream.d.ts +0 -494
- package/frontend/dist/backend/src/stream.js +0 -1611
- package/frontend/dist/backend/src/users.d.ts +0 -926
- package/frontend/dist/backend/src/users.js +0 -2423
- package/frontend/dist/backend/src/utils.d.ts +0 -22
- package/frontend/dist/backend/src/utils.js +0 -463
- package/frontend/dist/backend/src/view.d.ts +0 -115
- package/frontend/dist/backend/src/view.js +0 -584
- package/frontend/dist/frontend/src/elements/base.d.ts +0 -3743
- package/frontend/dist/frontend/src/elements/base.js +0 -12151
- package/frontend/dist/frontend/src/elements/module.d.ts +0 -95
- package/frontend/dist/frontend/src/elements/module.js +0 -216
- package/frontend/dist/frontend/src/elements/register_element.d.ts +0 -3
- package/frontend/dist/frontend/src/elements/register_element.js +0 -22
- package/frontend/dist/frontend/src/elements/resize_query_manager.d.ts +0 -0
- package/frontend/dist/frontend/src/elements/resize_query_manager.js +0 -150
- package/frontend/dist/frontend/src/elements/types.d.ts +0 -52
- package/frontend/dist/frontend/src/elements/types.js +0 -5
- package/frontend/dist/frontend/src/index.d.ts +0 -21
- package/frontend/dist/frontend/src/index.js +0 -29
- package/frontend/dist/frontend/src/modules/attachment.d.ts +0 -126
- package/frontend/dist/frontend/src/modules/attachment.js +0 -306
- package/frontend/dist/frontend/src/modules/auth.d.ts +0 -44
- package/frontend/dist/frontend/src/modules/auth.js +0 -80
- package/frontend/dist/frontend/src/modules/color.d.ts +0 -160
- package/frontend/dist/frontend/src/modules/color.js +0 -316
- package/frontend/dist/frontend/src/modules/compression.d.ts +0 -39
- package/frontend/dist/frontend/src/modules/compression.js +0 -102
- package/frontend/dist/frontend/src/modules/cookies.d.ts +0 -44
- package/frontend/dist/frontend/src/modules/cookies.js +0 -143
- package/frontend/dist/frontend/src/modules/events.d.ts +0 -31
- package/frontend/dist/frontend/src/modules/events.js +0 -79
- package/frontend/dist/frontend/src/modules/google.d.ts +0 -23
- package/frontend/dist/frontend/src/modules/google.js +0 -52
- package/frontend/dist/frontend/src/modules/meta.d.ts +0 -14
- package/frontend/dist/frontend/src/modules/meta.js +0 -48
- package/frontend/dist/frontend/src/modules/paddle.d.ts +0 -1207
- package/frontend/dist/frontend/src/modules/paddle.js +0 -2594
- package/frontend/dist/frontend/src/modules/request.d.ts +0 -70
- package/frontend/dist/frontend/src/modules/request.js +0 -117
- package/frontend/dist/frontend/src/modules/settings.d.ts +0 -3
- package/frontend/dist/frontend/src/modules/settings.js +0 -5
- package/frontend/dist/frontend/src/modules/statics.d.ts +0 -21
- package/frontend/dist/frontend/src/modules/statics.js +0 -43
- package/frontend/dist/frontend/src/modules/stripe/cart.d.ts +0 -112
- package/frontend/dist/frontend/src/modules/stripe/cart.js +0 -321
- package/frontend/dist/frontend/src/modules/stripe/checkout.d.ts +0 -7
- package/frontend/dist/frontend/src/modules/stripe/checkout.js +0 -37
- package/frontend/dist/frontend/src/modules/stripe/index.m.d.ts +0 -6
- package/frontend/dist/frontend/src/modules/stripe/index.m.js +0 -6
- package/frontend/dist/frontend/src/modules/stripe/payments.d.ts +0 -58
- package/frontend/dist/frontend/src/modules/stripe/payments.js +0 -92
- package/frontend/dist/frontend/src/modules/support.d.ts +0 -30
- package/frontend/dist/frontend/src/modules/support.js +0 -53
- package/frontend/dist/frontend/src/modules/theme.d.ts +0 -133
- package/frontend/dist/frontend/src/modules/theme.js +0 -406
- package/frontend/dist/frontend/src/modules/themes.d.ts +0 -12
- package/frontend/dist/frontend/src/modules/themes.js +0 -22
- package/frontend/dist/frontend/src/modules/user.d.ts +0 -164
- package/frontend/dist/frontend/src/modules/user.js +0 -270
- package/frontend/dist/frontend/src/modules/utils.d.ts +0 -176
- package/frontend/dist/frontend/src/modules/utils.js +0 -569
- package/frontend/dist/frontend/src/types/gradient.d.ts +0 -29
- package/frontend/dist/frontend/src/types/gradient.js +0 -79
- package/frontend/dist/frontend/src/ui/border_button.d.ts +0 -94
- package/frontend/dist/frontend/src/ui/border_button.js +0 -228
- package/frontend/dist/frontend/src/ui/button.d.ts +0 -241
- package/frontend/dist/frontend/src/ui/button.js +0 -682
- package/frontend/dist/frontend/src/ui/canvas.d.ts +0 -138
- package/frontend/dist/frontend/src/ui/canvas.js +0 -444
- package/frontend/dist/frontend/src/ui/checkbox.d.ts +0 -74
- package/frontend/dist/frontend/src/ui/checkbox.js +0 -321
- package/frontend/dist/frontend/src/ui/code.d.ts +0 -235
- package/frontend/dist/frontend/src/ui/code.js +0 -1007
- package/frontend/dist/frontend/src/ui/context_menu.d.ts +0 -36
- package/frontend/dist/frontend/src/ui/context_menu.js +0 -205
- package/frontend/dist/frontend/src/ui/css.d.ts +0 -16
- package/frontend/dist/frontend/src/ui/css.js +0 -48
- package/frontend/dist/frontend/src/ui/divider.d.ts +0 -15
- package/frontend/dist/frontend/src/ui/divider.js +0 -78
- package/frontend/dist/frontend/src/ui/dropdown.d.ts +0 -176
- package/frontend/dist/frontend/src/ui/dropdown.js +0 -481
- package/frontend/dist/frontend/src/ui/for_each.d.ts +0 -37
- package/frontend/dist/frontend/src/ui/for_each.js +0 -92
- package/frontend/dist/frontend/src/ui/form.d.ts +0 -34
- package/frontend/dist/frontend/src/ui/form.js +0 -233
- package/frontend/dist/frontend/src/ui/frame_modes.d.ts +0 -37
- package/frontend/dist/frontend/src/ui/frame_modes.js +0 -108
- package/frontend/dist/frontend/src/ui/google_map.d.ts +0 -24
- package/frontend/dist/frontend/src/ui/google_map.js +0 -106
- package/frontend/dist/frontend/src/ui/gradient.d.ts +0 -25
- package/frontend/dist/frontend/src/ui/gradient.js +0 -131
- package/frontend/dist/frontend/src/ui/image.d.ts +0 -111
- package/frontend/dist/frontend/src/ui/image.js +0 -576
- package/frontend/dist/frontend/src/ui/input.d.ts +0 -392
- package/frontend/dist/frontend/src/ui/input.js +0 -1201
- package/frontend/dist/frontend/src/ui/link.d.ts +0 -25
- package/frontend/dist/frontend/src/ui/link.js +0 -140
- package/frontend/dist/frontend/src/ui/list.d.ts +0 -37
- package/frontend/dist/frontend/src/ui/list.js +0 -170
- package/frontend/dist/frontend/src/ui/loader_button.d.ts +0 -80
- package/frontend/dist/frontend/src/ui/loader_button.js +0 -193
- package/frontend/dist/frontend/src/ui/loaders.d.ts +0 -57
- package/frontend/dist/frontend/src/ui/loaders.js +0 -157
- package/frontend/dist/frontend/src/ui/popup.d.ts +0 -94
- package/frontend/dist/frontend/src/ui/popup.js +0 -510
- package/frontend/dist/frontend/src/ui/pseudo.d.ts +0 -44
- package/frontend/dist/frontend/src/ui/pseudo.js +0 -154
- package/frontend/dist/frontend/src/ui/scroller.d.ts +0 -105
- package/frontend/dist/frontend/src/ui/scroller.js +0 -1253
- package/frontend/dist/frontend/src/ui/slider.d.ts +0 -45
- package/frontend/dist/frontend/src/ui/slider.js +0 -217
- package/frontend/dist/frontend/src/ui/spacer.d.ts +0 -15
- package/frontend/dist/frontend/src/ui/spacer.js +0 -78
- package/frontend/dist/frontend/src/ui/span.d.ts +0 -15
- package/frontend/dist/frontend/src/ui/span.js +0 -73
- package/frontend/dist/frontend/src/ui/stack.d.ts +0 -66
- package/frontend/dist/frontend/src/ui/stack.js +0 -335
- package/frontend/dist/frontend/src/ui/steps.d.ts +0 -131
- package/frontend/dist/frontend/src/ui/steps.js +0 -308
- package/frontend/dist/frontend/src/ui/style.d.ts +0 -17
- package/frontend/dist/frontend/src/ui/style.js +0 -73
- package/frontend/dist/frontend/src/ui/switch.d.ts +0 -69
- package/frontend/dist/frontend/src/ui/switch.js +0 -357
- package/frontend/dist/frontend/src/ui/table.d.ts +0 -100
- package/frontend/dist/frontend/src/ui/table.js +0 -405
- package/frontend/dist/frontend/src/ui/tabs.d.ts +0 -111
- package/frontend/dist/frontend/src/ui/tabs.js +0 -424
- package/frontend/dist/frontend/src/ui/text.d.ts +0 -15
- package/frontend/dist/frontend/src/ui/text.js +0 -83
- package/frontend/dist/frontend/src/ui/title.d.ts +0 -91
- package/frontend/dist/frontend/src/ui/title.js +0 -272
- package/frontend/dist/frontend/src/ui/ui.d.ts +0 -35
- package/frontend/dist/frontend/src/ui/ui.js +0 -38
- package/frontend/dist/frontend/src/ui/view.d.ts +0 -15
- package/frontend/dist/frontend/src/ui/view.js +0 -88
- package/frontend/dist/frontend/src/volt.d.ts +0 -20
- package/frontend/dist/frontend/src/volt.js +0 -27
- package/frontend/examples/theme/theme.ts +0 -58
- package/frontend/tools/bundle_d_ts.js +0 -71
- package/frontend/tools/convert_to_jsdoc_input.txt +0 -9452
- package/frontend/tools/convert_to_jsdoc_output.txt +0 -7626
- package/frontend/tools/convert_to_jsdoc_tmp.js +0 -345
- package/frontend/tools/scan_mixed_imports.js +0 -69
- /package/frontend/{dist/frontend/src/css → css}/adyen.css +0 -0
- /package/frontend/{dist/frontend/src/css → css}/volt.css +0 -0
|
@@ -1,752 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @author Daan van den Bergh
|
|
3
|
-
* @copyright © 2026 - 2026 Daan van den Bergh. All rights reserved
|
|
4
|
-
*
|
|
5
|
-
* Stripe webhook entrypoint:
|
|
6
|
-
* - Verifies webhook signatures (security-critical).
|
|
7
|
-
* - Handles lifecycle events emitted by our billing flows (Checkout, Subscriptions, Invoices, SetupIntents, PaymentIntents).
|
|
8
|
-
* - Invalidates local entitlement caches after Stripe-side mutations.
|
|
9
|
-
* - Triggers server events for application-level reactions.
|
|
10
|
-
*
|
|
11
|
-
* Stripe docs:
|
|
12
|
-
* - Webhooks: https://docs.stripe.com/webhooks
|
|
13
|
-
* - Verify signatures: https://docs.stripe.com/webhooks/signatures
|
|
14
|
-
*/
|
|
15
|
-
import * as vlib from "@vandenberghinc/vlib";
|
|
16
|
-
import { Collection } from "../../database/collection.js";
|
|
17
|
-
import { InternalStripeError } from "./error.js";
|
|
18
|
-
import { assert, is_non_empty_string, stable_idempotency_key, stripe_api_call, } from "./utils.js";
|
|
19
|
-
import { resolve_plan_to_parent_subscription, } from "./products.js";
|
|
20
|
-
import { delete_subscription_caches, enforce_single_subscription_plan, update_subscription_record, } from "./subscriptions.js";
|
|
21
|
-
import { finalize_payment_method_setup } from "./payment_methods.js";
|
|
22
|
-
// -------------------------------------------------------------------------------------------------
|
|
23
|
-
// Internal constants.
|
|
24
|
-
/** The uid metadata key we use across Stripe objects. */
|
|
25
|
-
const stripe_uid_metadata_key = "__volt_uid";
|
|
26
|
-
/**
|
|
27
|
-
* Dedup cache for webhook event ids (webhooks are delivered at-least-once).
|
|
28
|
-
* We keep a short TTL to avoid double-processing on transient retries.
|
|
29
|
-
*/
|
|
30
|
-
const processed_event_id_cache = new vlib.Cache({
|
|
31
|
-
max_size: 250_000,
|
|
32
|
-
ttl: {
|
|
33
|
-
sliding: true,
|
|
34
|
-
duration: 10 * 60 * 1000, // 10 minutes
|
|
35
|
-
},
|
|
36
|
-
});
|
|
37
|
-
/**
|
|
38
|
-
* Short-lived "inflight" lock to avoid concurrent double-processing inside this instance,
|
|
39
|
-
* while still allowing retries if handling fails.
|
|
40
|
-
*/
|
|
41
|
-
const inflight_event_id_cache = new vlib.Cache({
|
|
42
|
-
max_size: 250_000,
|
|
43
|
-
ttl: {
|
|
44
|
-
sliding: true,
|
|
45
|
-
duration: 60 * 1000 * 5, // 5 minutes
|
|
46
|
-
},
|
|
47
|
-
});
|
|
48
|
-
// -------------------------------------------------------------------------------------------------
|
|
49
|
-
// Handling webhook event helpers.
|
|
50
|
-
/**
|
|
51
|
-
* Build a mapping from Stripe price id -> (plan | meter_product) for fast resolution.
|
|
52
|
-
*/
|
|
53
|
-
function index_products_by_stripe_price_id(all_products) {
|
|
54
|
-
const plan_by_price_id = new Map();
|
|
55
|
-
const meter_by_price_id = new Map();
|
|
56
|
-
// const subscription_by_id = new Map<string, InitializedSubscriptionProduct>();
|
|
57
|
-
for (const product of all_products) {
|
|
58
|
-
if (product.type === "subscription") {
|
|
59
|
-
// subscription_by_id.set(product.id, product);
|
|
60
|
-
for (const plan of product.plans) {
|
|
61
|
-
plan_by_price_id.set(plan.stripe_price_id, plan);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
else if (product.type === "meter") {
|
|
65
|
-
meter_by_price_id.set(product.stripe_price_id, product);
|
|
66
|
-
}
|
|
67
|
-
else if (product.type === "one_time") {
|
|
68
|
-
// Note: one-time products can show up in checkout sessions, but not in subscriptions.
|
|
69
|
-
// We do not index them here for subscription item mapping.
|
|
70
|
-
// void product;
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
// @ts-expect-error
|
|
74
|
-
product.type.toString();
|
|
75
|
-
throw new InternalStripeError("invalid_product", "Unknown product type.", { product_type: product.type });
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
return { plan_by_price_id, meter_by_price_id };
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* Resolve subscription item mappings from a Stripe subscription object.
|
|
82
|
-
*
|
|
83
|
-
* We expect `subscription.items.data[].price` to be expanded or at least present with `id`.
|
|
84
|
-
*/
|
|
85
|
-
function resolve_subscription_items(opts) {
|
|
86
|
-
const { plan_by_price_id, meter_by_price_id } = index_products_by_stripe_price_id(opts.all_products);
|
|
87
|
-
const resolved = [];
|
|
88
|
-
for (const item of opts.subscription.items.data) {
|
|
89
|
-
const price = item.price;
|
|
90
|
-
if (!price) {
|
|
91
|
-
continue;
|
|
92
|
-
}
|
|
93
|
-
const stripe_price_id = price.id;
|
|
94
|
-
const plan = plan_by_price_id.get(stripe_price_id) ?? undefined;
|
|
95
|
-
const meter_product = meter_by_price_id.get(stripe_price_id) ?? undefined;
|
|
96
|
-
if (plan) {
|
|
97
|
-
const product = resolve_plan_to_parent_subscription({
|
|
98
|
-
plan,
|
|
99
|
-
all_products: opts.all_products,
|
|
100
|
-
});
|
|
101
|
-
resolved.push({
|
|
102
|
-
stripe_price_id,
|
|
103
|
-
product,
|
|
104
|
-
plan,
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
else if (meter_product) {
|
|
108
|
-
resolved.push({
|
|
109
|
-
stripe_price_id,
|
|
110
|
-
product: meter_product,
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
else {
|
|
114
|
-
// Unknown price id (maybe created outside our initializer). We still surface the price id.
|
|
115
|
-
resolved.push({ stripe_price_id });
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
return resolved;
|
|
119
|
-
}
|
|
120
|
-
/**
|
|
121
|
-
* Verify and construct a Stripe event from raw request payload.
|
|
122
|
-
*/
|
|
123
|
-
function construct_stripe_event(client, opts) {
|
|
124
|
-
// Security: This is the only safe way to validate the signature and parse the event.
|
|
125
|
-
// Docs: https://docs.stripe.com/webhooks/signatures#verify-signatures
|
|
126
|
-
try {
|
|
127
|
-
return client.webhooks.constructEvent(opts.raw_body, opts.stripe_signature_header, opts.webhook_signing_secret);
|
|
128
|
-
}
|
|
129
|
-
catch (error) {
|
|
130
|
-
// Signature issues are user-facing *only* if exposed through an API; usually treat as internal and log.
|
|
131
|
-
throw new InternalStripeError("invalid_argument", "Invalid Stripe webhook signature.", { has_signature: is_non_empty_string(opts.stripe_signature_header) }, error);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* Await the events trigger() response concurrently.
|
|
136
|
-
*/
|
|
137
|
-
async function await_event_trigger(response) {
|
|
138
|
-
const promises = response.filter((r) => Boolean(r));
|
|
139
|
-
await Promise.all(promises);
|
|
140
|
-
}
|
|
141
|
-
// -------------------------------------------------------------------------------------------------
|
|
142
|
-
// Registering webhook helpers.
|
|
143
|
-
/**
|
|
144
|
-
* The full set of event types used by `handle_stripe_webhook()`.
|
|
145
|
-
* Keep this list in lockstep with the switch cases in the webhook handler.
|
|
146
|
-
*/
|
|
147
|
-
const required_stripe_webhook_events = [
|
|
148
|
-
"checkout.session.completed",
|
|
149
|
-
"customer.subscription.created",
|
|
150
|
-
"customer.subscription.updated",
|
|
151
|
-
"customer.subscription.deleted",
|
|
152
|
-
"invoice.paid",
|
|
153
|
-
"invoice.payment_failed",
|
|
154
|
-
"payment_intent.succeeded",
|
|
155
|
-
"payment_intent.payment_failed",
|
|
156
|
-
"setup_intent.succeeded",
|
|
157
|
-
];
|
|
158
|
-
/** The metadata app id key name. */
|
|
159
|
-
const webhook_metadata_app_id = "__volt_webhook_app_id";
|
|
160
|
-
/**
|
|
161
|
-
* Create (or fetch cached) database collection used to pin a Stripe webhook endpoint per app id.
|
|
162
|
-
*/
|
|
163
|
-
function create_stripe_webhook_endpoints_db(server) {
|
|
164
|
-
return server.db.collection({
|
|
165
|
-
name: "Volt.Stripe.WebhookEndpoints",
|
|
166
|
-
indexes: [
|
|
167
|
-
{
|
|
168
|
-
keys: { webhook_app_id: 1 },
|
|
169
|
-
unique: true,
|
|
170
|
-
},
|
|
171
|
-
],
|
|
172
|
-
// No TTL: webhook endpoints are long-lived configuration.
|
|
173
|
-
unique: false,
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
/**
|
|
177
|
-
* Assert a provided URL is an absolute https URL.
|
|
178
|
-
*/
|
|
179
|
-
function assert_https_webhook_url(webhook_url) {
|
|
180
|
-
assert(is_non_empty_string(webhook_url), "invalid_argument", "Property 'webhook_url' must be a non-empty string.");
|
|
181
|
-
let parsed;
|
|
182
|
-
try {
|
|
183
|
-
parsed = new URL(webhook_url);
|
|
184
|
-
}
|
|
185
|
-
catch (error) {
|
|
186
|
-
throw new InternalStripeError("invalid_argument", "Property 'webhook_url' must be a valid absolute URL.", { webhook_url }, error);
|
|
187
|
-
}
|
|
188
|
-
assert(parsed.protocol === "https:", "invalid_argument", "Property 'webhook_url' must use https.", { webhook_url });
|
|
189
|
-
}
|
|
190
|
-
/**
|
|
191
|
-
* Compare two event lists as sets (order-independent).
|
|
192
|
-
*/
|
|
193
|
-
function same_event_set(a, b) {
|
|
194
|
-
if (a.length !== b.length)
|
|
195
|
-
return false;
|
|
196
|
-
const set_a = new Set(a);
|
|
197
|
-
if (set_a.size !== b.length)
|
|
198
|
-
return false;
|
|
199
|
-
for (const ev of b) {
|
|
200
|
-
if (!set_a.has(ev))
|
|
201
|
-
return false;
|
|
202
|
-
}
|
|
203
|
-
return true;
|
|
204
|
-
}
|
|
205
|
-
/**
|
|
206
|
-
* Safely extract a webhook signing secret from a Stripe WebhookEndpoint object.
|
|
207
|
-
* Stripe returns the `secret` only at creation time (and not reliably on retrieve/update),
|
|
208
|
-
* so we must persist it at creation.
|
|
209
|
-
*/
|
|
210
|
-
function extract_webhook_secret(endpoint) {
|
|
211
|
-
const secret = endpoint.secret;
|
|
212
|
-
return is_non_empty_string(secret) ? secret : undefined;
|
|
213
|
-
}
|
|
214
|
-
/**
|
|
215
|
-
* Find an existing Stripe webhook endpoint matching our URL by listing endpoints and filtering.
|
|
216
|
-
* Stripe does not provide a direct "retrieve by url" API.
|
|
217
|
-
*/
|
|
218
|
-
async function find_stripe_webhook_by_app_id(client, webhook_app_id) {
|
|
219
|
-
// Docs: https://docs.stripe.com/api/webhook_endpoints/list
|
|
220
|
-
let starting_after;
|
|
221
|
-
for (;;) {
|
|
222
|
-
const page = await stripe_api_call(() => client.webhookEndpoints.list({ limit: 100, ...(starting_after ? { starting_after } : {}) }), { operation: "webhookEndpoints.list", webhook_app_id });
|
|
223
|
-
for (const endpoint of page.data) {
|
|
224
|
-
if (endpoint.metadata?.[webhook_metadata_app_id] === webhook_app_id) {
|
|
225
|
-
return endpoint;
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
if (!page.has_more)
|
|
229
|
-
return undefined;
|
|
230
|
-
const last = page.data[page.data.length - 1];
|
|
231
|
-
if (!last)
|
|
232
|
-
return undefined;
|
|
233
|
-
starting_after = last.id;
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
// -------------------------------------------------------------------------------------------------
|
|
237
|
-
// Public API.
|
|
238
|
-
/**
|
|
239
|
-
* Register or update the Stripe Webhook Endpoint for our billing system.
|
|
240
|
-
*
|
|
241
|
-
* - Creates a webhook endpoint if it does not exist.
|
|
242
|
-
* - Ensures all required billing events are enabled.
|
|
243
|
-
* - Persists endpoint id + signing secret in our DB for later signature verification config.
|
|
244
|
-
*
|
|
245
|
-
* Stripe docs:
|
|
246
|
-
* - Create: https://docs.stripe.com/api/webhook_endpoints/create
|
|
247
|
-
* - Update: https://docs.stripe.com/api/webhook_endpoints/update
|
|
248
|
-
*/
|
|
249
|
-
export async function register_or_update_stripe_webhook_endpoint(client, server, opts) {
|
|
250
|
-
// Validate inputs early.
|
|
251
|
-
assert_https_webhook_url(opts.webhook_url);
|
|
252
|
-
assert(is_non_empty_string(opts.webhook_app_id), "invalid_argument", "Property 'webhook_app_id' must be a non-empty string.");
|
|
253
|
-
const ensure_enabled = opts.ensure_enabled !== false;
|
|
254
|
-
const enabled_events = Array.from(required_stripe_webhook_events);
|
|
255
|
-
// Init db collection (cached by server db layer).
|
|
256
|
-
const webhook_endpoints_db = create_stripe_webhook_endpoints_db(server);
|
|
257
|
-
// First: check our DB pin (fast path).
|
|
258
|
-
const loaded = await webhook_endpoints_db.load({ webhook_app_id: opts.webhook_app_id }, { throw: false, retry: 3 });
|
|
259
|
-
// If the DB already knows the endpoint, still ensure Stripe config is correct.
|
|
260
|
-
if (!(loaded instanceof Error)) {
|
|
261
|
-
// Load endpoint.
|
|
262
|
-
let endpoint;
|
|
263
|
-
try {
|
|
264
|
-
endpoint = await stripe_api_call(() => client.webhookEndpoints.retrieve(loaded.stripe_webhook_endpoint_id), {
|
|
265
|
-
operation: "webhookEndpoints.retrieve",
|
|
266
|
-
stripe_webhook_endpoint_id: loaded.stripe_webhook_endpoint_id,
|
|
267
|
-
webhook_url: opts.webhook_url,
|
|
268
|
-
});
|
|
269
|
-
}
|
|
270
|
-
catch (error) {
|
|
271
|
-
// If the pinned endpoint id is stale (deleted/rotated), try resolving by app id.
|
|
272
|
-
const by_app_id = await find_stripe_webhook_by_app_id(client, opts.webhook_app_id);
|
|
273
|
-
if (!by_app_id)
|
|
274
|
-
throw error;
|
|
275
|
-
endpoint = by_app_id;
|
|
276
|
-
}
|
|
277
|
-
// Check metadata app id match.
|
|
278
|
-
if (endpoint.metadata?.[webhook_metadata_app_id] !== opts.webhook_app_id) {
|
|
279
|
-
// The URL-keyed DB record may be stale if the webhook URL changed.
|
|
280
|
-
// Fall back to resolving the "default" endpoint by app id.
|
|
281
|
-
const by_app_id = await find_stripe_webhook_by_app_id(client, opts.webhook_app_id);
|
|
282
|
-
if (!by_app_id) {
|
|
283
|
-
throw new InternalStripeError("webhook_endpoint_app_id_mismatch", "Webhook endpoint app id does not match and no endpoint was found for webhook_app_id.", { webhook_url: opts.webhook_url, webhook_app_id: opts.webhook_app_id });
|
|
284
|
-
}
|
|
285
|
-
// Continue by treating this as the "existing" branch: enforce config (including URL).
|
|
286
|
-
// We cannot rely on Stripe to return the secret here; must be stored at creation time.
|
|
287
|
-
throw new InternalStripeError("webhook_endpoint_secret_missing", "Stripe webhook endpoint for webhook_app_id exists but signing secret is not available via DB lookup. Store the whsec_ value at creation time.", { webhook_url: opts.webhook_url, stripe_webhook_endpoint_id: by_app_id.id, webhook_app_id: opts.webhook_app_id });
|
|
288
|
-
}
|
|
289
|
-
const needs_event_update = !same_event_set(endpoint.enabled_events ?? [], enabled_events);
|
|
290
|
-
// Stripe's WebhookEndpoint has `status` (enabled/disabled).
|
|
291
|
-
const needs_enable = ensure_enabled && endpoint.status !== "enabled";
|
|
292
|
-
if (needs_event_update || needs_enable) {
|
|
293
|
-
const update_params = {
|
|
294
|
-
enabled_events,
|
|
295
|
-
...(needs_enable ? { disabled: false } : {}),
|
|
296
|
-
...(is_non_empty_string(opts.description) ? { description: opts.description.trim() } : {}),
|
|
297
|
-
metadata: {
|
|
298
|
-
...(endpoint.metadata ?? {}),
|
|
299
|
-
[webhook_metadata_app_id]: opts.webhook_app_id,
|
|
300
|
-
},
|
|
301
|
-
};
|
|
302
|
-
await stripe_api_call(() => client.webhookEndpoints.update(endpoint.id, update_params, {
|
|
303
|
-
// Stable idempotency ensures safe retries without duplicating config writes.
|
|
304
|
-
idempotencyKey: stable_idempotency_key(`webhook_endpoints.update:${endpoint.id}:${opts.webhook_url}`, 255),
|
|
305
|
-
}), {
|
|
306
|
-
operation: "webhookEndpoints.update",
|
|
307
|
-
stripe_webhook_endpoint_id: endpoint.id,
|
|
308
|
-
webhook_url: opts.webhook_url,
|
|
309
|
-
});
|
|
310
|
-
}
|
|
311
|
-
// Persist the events we *intend* to be enabled (source of truth for our integration).
|
|
312
|
-
const updated_record = {
|
|
313
|
-
webhook_url: opts.webhook_url,
|
|
314
|
-
stripe_webhook_endpoint_id: loaded.stripe_webhook_endpoint_id,
|
|
315
|
-
webhook_signing_secret: loaded.webhook_signing_secret,
|
|
316
|
-
enabled_events: enabled_events.slice(),
|
|
317
|
-
updated_at_ms: Date.now(),
|
|
318
|
-
webhook_app_id: opts.webhook_app_id,
|
|
319
|
-
};
|
|
320
|
-
await webhook_endpoints_db.set({ webhook_app_id: opts.webhook_app_id }, updated_record, { throw: true, retry: 3 });
|
|
321
|
-
return {
|
|
322
|
-
stripe_webhook_endpoint_id: updated_record.stripe_webhook_endpoint_id,
|
|
323
|
-
webhook_signing_secret: updated_record.webhook_signing_secret,
|
|
324
|
-
enabled_events: updated_record.enabled_events,
|
|
325
|
-
};
|
|
326
|
-
}
|
|
327
|
-
if (loaded instanceof Error && !(loaded instanceof Collection.NotFoundError)) {
|
|
328
|
-
throw new InternalStripeError("webhook_endpoint_load_error", "Failed to access webhook endpoints record.", { webhook_url: opts.webhook_url }, loaded);
|
|
329
|
-
}
|
|
330
|
-
// Second: DB has no record. Try to find an existing endpoint in Stripe by URL.
|
|
331
|
-
const existing = await find_stripe_webhook_by_app_id(client, opts.webhook_app_id);
|
|
332
|
-
if (existing) {
|
|
333
|
-
// Ensure it has the right configuration.
|
|
334
|
-
const needs_event_update = !same_event_set(existing.enabled_events ?? [], enabled_events);
|
|
335
|
-
const needs_enable = ensure_enabled && existing.status !== "enabled";
|
|
336
|
-
const needs_url_update = existing.url !== opts.webhook_url;
|
|
337
|
-
if (needs_event_update || needs_enable || needs_url_update) {
|
|
338
|
-
const update_params = {
|
|
339
|
-
enabled_events,
|
|
340
|
-
...(needs_enable ? { disabled: false } : {}),
|
|
341
|
-
...(is_non_empty_string(opts.description) ? { description: opts.description.trim() } : {}),
|
|
342
|
-
...(needs_url_update ? { url: opts.webhook_url } : {}),
|
|
343
|
-
metadata: {
|
|
344
|
-
...(existing.metadata ?? {}),
|
|
345
|
-
[webhook_metadata_app_id]: opts.webhook_app_id,
|
|
346
|
-
},
|
|
347
|
-
};
|
|
348
|
-
await stripe_api_call(() => client.webhookEndpoints.update(existing.id, update_params, {
|
|
349
|
-
idempotencyKey: stable_idempotency_key(`webhook_endpoints.update:${existing.id}:${opts.webhook_url}`, 255),
|
|
350
|
-
}), {
|
|
351
|
-
operation: "webhookEndpoints.update",
|
|
352
|
-
stripe_webhook_endpoint_id: existing.id,
|
|
353
|
-
webhook_url: opts.webhook_url,
|
|
354
|
-
});
|
|
355
|
-
}
|
|
356
|
-
// We cannot rely on Stripe to return the secret here; we must have it stored.
|
|
357
|
-
// If you reached this branch without a DB record, you must provide the secret out-of-band.
|
|
358
|
-
throw new InternalStripeError("webhook_endpoint_secret_missing", "Stripe webhook endpoint exists but signing secret is not available. Store the whsec_ value at creation time.", { webhook_url: opts.webhook_url, stripe_webhook_endpoint_id: existing.id });
|
|
359
|
-
}
|
|
360
|
-
// Third: create a new endpoint in Stripe.
|
|
361
|
-
const create_params = {
|
|
362
|
-
// Docs: https://docs.stripe.com/api/webhook_endpoints/create
|
|
363
|
-
url: opts.webhook_url,
|
|
364
|
-
enabled_events,
|
|
365
|
-
...(is_non_empty_string(opts.description) ? { description: opts.description.trim() } : {}),
|
|
366
|
-
metadata: {
|
|
367
|
-
[webhook_metadata_app_id]: opts.webhook_app_id,
|
|
368
|
-
},
|
|
369
|
-
};
|
|
370
|
-
const created = await stripe_api_call(() => client.webhookEndpoints.create(create_params, {
|
|
371
|
-
// Stable idempotency ensures safe retries without creating multiple endpoints.
|
|
372
|
-
idempotencyKey: stable_idempotency_key(`webhook_endpoints.create:${opts.webhook_app_id}:${opts.webhook_url}`, 255),
|
|
373
|
-
}), { operation: "webhookEndpoints.create", webhook_app_id: opts.webhook_app_id });
|
|
374
|
-
const webhook_signing_secret = extract_webhook_secret(created);
|
|
375
|
-
if (!webhook_signing_secret) {
|
|
376
|
-
// Without a signing secret, we cannot securely verify webhook signatures.
|
|
377
|
-
throw new InternalStripeError("webhook_endpoint_secret_missing", "Stripe did not return a webhook signing secret on endpoint creation.", { webhook_url: opts.webhook_url, stripe_webhook_endpoint_id: created.id });
|
|
378
|
-
}
|
|
379
|
-
// Optionally enforce enabled state (Stripe defaults to enabled, but we harden this anyway).
|
|
380
|
-
if (ensure_enabled && created.status !== "enabled") {
|
|
381
|
-
await stripe_api_call(() => client.webhookEndpoints.update(created.id, { disabled: false }, {
|
|
382
|
-
idempotencyKey: stable_idempotency_key(`webhook_endpoints.enable:${created.id}:${opts.webhook_url}`, 255),
|
|
383
|
-
}), {
|
|
384
|
-
operation: "webhookEndpoints.update",
|
|
385
|
-
stripe_webhook_endpoint_id: created.id,
|
|
386
|
-
webhook_url: opts.webhook_url,
|
|
387
|
-
});
|
|
388
|
-
}
|
|
389
|
-
// Persist endpoint id + secret so the webhook handler can verify signatures.
|
|
390
|
-
const record = {
|
|
391
|
-
webhook_url: opts.webhook_url,
|
|
392
|
-
stripe_webhook_endpoint_id: created.id,
|
|
393
|
-
webhook_signing_secret,
|
|
394
|
-
enabled_events: enabled_events.slice(),
|
|
395
|
-
updated_at_ms: Date.now(),
|
|
396
|
-
webhook_app_id: opts.webhook_app_id,
|
|
397
|
-
};
|
|
398
|
-
await webhook_endpoints_db.set({ webhook_app_id: opts.webhook_app_id }, record, { throw: true, retry: 3 });
|
|
399
|
-
return {
|
|
400
|
-
stripe_webhook_endpoint_id: record.stripe_webhook_endpoint_id,
|
|
401
|
-
webhook_signing_secret: record.webhook_signing_secret,
|
|
402
|
-
enabled_events: record.enabled_events,
|
|
403
|
-
};
|
|
404
|
-
}
|
|
405
|
-
/**
|
|
406
|
-
* Handle a Stripe webhook call:
|
|
407
|
-
* - verifies signature
|
|
408
|
-
* - deduplicates event ids briefly
|
|
409
|
-
* - routes event types to handlers
|
|
410
|
-
* - emits application events via `server.events.trigger`
|
|
411
|
-
*
|
|
412
|
-
* Sending a response through the stream automatically.
|
|
413
|
-
*
|
|
414
|
-
* @note This function expects the caller to provide the raw body and Stripe-Signature header.
|
|
415
|
-
*/
|
|
416
|
-
export async function handle_stripe_webhook(client, opts) {
|
|
417
|
-
try {
|
|
418
|
-
// Validate critical inputs early.
|
|
419
|
-
assert(is_non_empty_string(opts.webhook_signing_secret), "invalid_argument", "webhook_signing_secret must be provided.");
|
|
420
|
-
assert(is_non_empty_string(opts.stripe_signature_header), "invalid_argument", "stripe_signature_header must be provided.");
|
|
421
|
-
assert(Array.isArray(opts.all_products), "invalid_argument", "all_products must be an array.");
|
|
422
|
-
assert(Buffer.isBuffer(opts.raw_body), "invalid_argument", "raw_body must be a Buffer.");
|
|
423
|
-
// 1) Verify signature + parse event.
|
|
424
|
-
const event = construct_stripe_event(client, {
|
|
425
|
-
webhook_signing_secret: opts.webhook_signing_secret,
|
|
426
|
-
raw_body: opts.raw_body,
|
|
427
|
-
stripe_signature_header: opts.stripe_signature_header,
|
|
428
|
-
});
|
|
429
|
-
// 2) Deduplicate best-effort (webhooks are at-least-once).
|
|
430
|
-
// Only mark as processed AFTER successful handling.
|
|
431
|
-
if (processed_event_id_cache.get(event.id) === true) {
|
|
432
|
-
opts.server.log(1, "Stripe webhook deduplicated event: ", { event_id: event.id, type: event.type });
|
|
433
|
-
opts.stream.success({ status: 200, data: { received: true, deduplicated: true } });
|
|
434
|
-
return;
|
|
435
|
-
}
|
|
436
|
-
if (inflight_event_id_cache.get(event.id) === true) {
|
|
437
|
-
opts.server.log(1, "Stripe webhook already inflight: ", { event_id: event.id, type: event.type });
|
|
438
|
-
// Respond 200 to avoid retry storms; the in-flight handler will complete.
|
|
439
|
-
opts.stream.success({ status: 200, data: { received: true, inflight: true } });
|
|
440
|
-
return;
|
|
441
|
-
}
|
|
442
|
-
inflight_event_id_cache.set(event.id, true);
|
|
443
|
-
try {
|
|
444
|
-
// 3) Route by event type.
|
|
445
|
-
//
|
|
446
|
-
// Stripe event type list: https://docs.stripe.com/api/events/types
|
|
447
|
-
switch (event.type) {
|
|
448
|
-
case "checkout.session.completed": {
|
|
449
|
-
opts.server.log(1, "Stripe webhook received checkout.session.completed: ", { event_id: event.id });
|
|
450
|
-
const session = event.data.object;
|
|
451
|
-
const stripe_session_id = session.id;
|
|
452
|
-
assert(is_non_empty_string(stripe_session_id), "api_error", "checkout.session.completed missing session.id");
|
|
453
|
-
const uid = session.metadata?.[stripe_uid_metadata_key];
|
|
454
|
-
if (!is_non_empty_string(uid)) {
|
|
455
|
-
throw new InternalStripeError("invalid_argument", "Checkout session missing uid metadata.", { stripe_session_id });
|
|
456
|
-
}
|
|
457
|
-
const mode = session.mode === "subscription"
|
|
458
|
-
? "subscription"
|
|
459
|
-
: session.mode === "setup"
|
|
460
|
-
? "setup"
|
|
461
|
-
: "payment";
|
|
462
|
-
const stripe_customer_id = typeof session.customer === "string"
|
|
463
|
-
? session.customer
|
|
464
|
-
: session.customer && typeof session.customer === "object"
|
|
465
|
-
? session.customer.id
|
|
466
|
-
: undefined;
|
|
467
|
-
assert(is_non_empty_string(stripe_customer_id), "api_error", "Checkout session missing customer id.", {
|
|
468
|
-
uid,
|
|
469
|
-
stripe_session_id,
|
|
470
|
-
});
|
|
471
|
-
const stripe_subscription_id = typeof session.subscription === "string" ? session.subscription : undefined;
|
|
472
|
-
const currency = is_non_empty_string(session.currency) ? session.currency : undefined;
|
|
473
|
-
const metadata = session.metadata ?? {};
|
|
474
|
-
delete_subscription_caches(uid);
|
|
475
|
-
await await_event_trigger(opts.server.events.trigger("stripe.checkout_session_completed", {
|
|
476
|
-
uid,
|
|
477
|
-
stripe_session_id,
|
|
478
|
-
mode,
|
|
479
|
-
stripe_customer_id,
|
|
480
|
-
stripe_subscription_id,
|
|
481
|
-
currency,
|
|
482
|
-
metadata,
|
|
483
|
-
}));
|
|
484
|
-
processed_event_id_cache.set(event.id, true);
|
|
485
|
-
opts.stream.success({ status: 200, data: { received: true } });
|
|
486
|
-
return;
|
|
487
|
-
}
|
|
488
|
-
case "customer.subscription.created":
|
|
489
|
-
case "customer.subscription.updated":
|
|
490
|
-
case "customer.subscription.deleted": {
|
|
491
|
-
opts.server.log(1, "Stripe webhook received subscription event: ", { event_id: event.id, type: event.type });
|
|
492
|
-
const subscription = event.data.object;
|
|
493
|
-
const stripe_subscription_id = subscription.id;
|
|
494
|
-
assert(is_non_empty_string(stripe_subscription_id), "api_error", "Subscription event missing subscription.id");
|
|
495
|
-
const stripe_customer_id_value = subscription.customer;
|
|
496
|
-
const stripe_customer_id = typeof stripe_customer_id_value === "string" ? stripe_customer_id_value : stripe_customer_id_value.id;
|
|
497
|
-
assert(is_non_empty_string(stripe_customer_id), "api_error", "Subscription event missing customer id", {
|
|
498
|
-
stripe_subscription_id,
|
|
499
|
-
});
|
|
500
|
-
let uid = subscription.metadata?.[stripe_uid_metadata_key];
|
|
501
|
-
if (!is_non_empty_string(uid)) {
|
|
502
|
-
const customer = await stripe_api_call(() => client.customers.retrieve(stripe_customer_id), { operation: "customers.retrieve", stripe_customer_id, reason: "resolve_uid_fallback" });
|
|
503
|
-
if ("deleted" in customer && customer.deleted === true) {
|
|
504
|
-
throw new InternalStripeError("customer_not_found", "Subscription references a deleted customer.", { stripe_subscription_id, stripe_customer_id });
|
|
505
|
-
}
|
|
506
|
-
uid = customer.metadata?.[stripe_uid_metadata_key];
|
|
507
|
-
}
|
|
508
|
-
if (!is_non_empty_string(uid)) {
|
|
509
|
-
throw new InternalStripeError("invalid_argument", "Subscription missing uid metadata (subscription + customer).", { stripe_subscription_id, stripe_customer_id });
|
|
510
|
-
}
|
|
511
|
-
const typed_subscription = await stripe_api_call(() => client.subscriptions.retrieve(stripe_subscription_id, {
|
|
512
|
-
expand: ["items.data.price"],
|
|
513
|
-
}), {
|
|
514
|
-
operation: "subscriptions.retrieve",
|
|
515
|
-
stripe_subscription_id,
|
|
516
|
-
stripe_customer_id,
|
|
517
|
-
uid,
|
|
518
|
-
});
|
|
519
|
-
delete_subscription_caches(uid);
|
|
520
|
-
if (event.type === "customer.subscription.created"
|
|
521
|
-
|| event.type === "customer.subscription.updated") {
|
|
522
|
-
await enforce_single_subscription_plan(client, opts.server, {
|
|
523
|
-
uid,
|
|
524
|
-
stripe_customer_id: stripe_customer_id,
|
|
525
|
-
new_subscription: typed_subscription,
|
|
526
|
-
all_products: opts.all_products,
|
|
527
|
-
idempotency_key: stable_idempotency_key(`enforce_single_subscription_plan:${event.id}`),
|
|
528
|
-
});
|
|
529
|
-
}
|
|
530
|
-
// Update the subscription record.
|
|
531
|
-
await update_subscription_record(client, opts.server, {
|
|
532
|
-
uid,
|
|
533
|
-
all_products: opts.all_products,
|
|
534
|
-
});
|
|
535
|
-
// Trigger event.
|
|
536
|
-
const items = resolve_subscription_items({
|
|
537
|
-
subscription: typed_subscription,
|
|
538
|
-
all_products: opts.all_products,
|
|
539
|
-
});
|
|
540
|
-
const cancel_at_period_end = typed_subscription.cancel_at_period_end ?? undefined;
|
|
541
|
-
if (event.type === "customer.subscription.created") {
|
|
542
|
-
await await_event_trigger(opts.server.events.trigger("stripe.subscription_created", {
|
|
543
|
-
uid,
|
|
544
|
-
stripe_subscription_id: typed_subscription.id,
|
|
545
|
-
stripe_customer_id,
|
|
546
|
-
status: typed_subscription.status,
|
|
547
|
-
items,
|
|
548
|
-
}));
|
|
549
|
-
}
|
|
550
|
-
else if (event.type === "customer.subscription.updated") {
|
|
551
|
-
await await_event_trigger(opts.server.events.trigger("stripe.subscription_updated", {
|
|
552
|
-
uid,
|
|
553
|
-
stripe_subscription_id: typed_subscription.id,
|
|
554
|
-
stripe_customer_id,
|
|
555
|
-
status: typed_subscription.status,
|
|
556
|
-
items,
|
|
557
|
-
cancel_at_period_end,
|
|
558
|
-
}));
|
|
559
|
-
}
|
|
560
|
-
else {
|
|
561
|
-
await await_event_trigger(opts.server.events.trigger("stripe.subscription_deleted", {
|
|
562
|
-
uid,
|
|
563
|
-
stripe_subscription_id: typed_subscription.id,
|
|
564
|
-
stripe_customer_id,
|
|
565
|
-
status: typed_subscription.status,
|
|
566
|
-
items,
|
|
567
|
-
}));
|
|
568
|
-
}
|
|
569
|
-
processed_event_id_cache.set(event.id, true);
|
|
570
|
-
opts.stream.success({ status: 200, data: { received: true } });
|
|
571
|
-
return;
|
|
572
|
-
}
|
|
573
|
-
case "invoice.paid":
|
|
574
|
-
case "invoice.payment_failed": {
|
|
575
|
-
opts.server.log(1, "Stripe webhook received invoice event: ", { event_id: event.id, type: event.type });
|
|
576
|
-
const invoice = event.data.object;
|
|
577
|
-
const stripe_invoice_id = invoice.id;
|
|
578
|
-
assert(is_non_empty_string(stripe_invoice_id), "api_error", "Invoice event missing invoice.id");
|
|
579
|
-
const stripe_customer_id_value = invoice.customer;
|
|
580
|
-
const stripe_customer_id = typeof stripe_customer_id_value === "string"
|
|
581
|
-
? stripe_customer_id_value
|
|
582
|
-
: stripe_customer_id_value?.id;
|
|
583
|
-
assert(is_non_empty_string(stripe_customer_id), "api_error", "Invoice event missing customer id", {
|
|
584
|
-
stripe_invoice_id,
|
|
585
|
-
});
|
|
586
|
-
let uid = invoice.metadata?.[stripe_uid_metadata_key];
|
|
587
|
-
if (!is_non_empty_string(uid)) {
|
|
588
|
-
const customer = await stripe_api_call(() => client.customers.retrieve(stripe_customer_id), { operation: "customers.retrieve", stripe_customer_id, reason: "resolve_uid_fallback" });
|
|
589
|
-
if ("deleted" in customer && customer.deleted === true) {
|
|
590
|
-
throw new InternalStripeError("customer_not_found", "Invoice references a deleted customer.", { stripe_invoice_id, stripe_customer_id });
|
|
591
|
-
}
|
|
592
|
-
uid = customer.metadata?.[stripe_uid_metadata_key];
|
|
593
|
-
}
|
|
594
|
-
if (!is_non_empty_string(uid)) {
|
|
595
|
-
throw new InternalStripeError("invalid_argument", "Invoice missing uid metadata (invoice + customer).", { stripe_invoice_id, stripe_customer_id });
|
|
596
|
-
}
|
|
597
|
-
delete_subscription_caches(uid);
|
|
598
|
-
const currency = invoice.currency;
|
|
599
|
-
assert(is_non_empty_string(currency), "api_error", "Invoice missing currency", { stripe_invoice_id });
|
|
600
|
-
const hosted_invoice_url = is_non_empty_string(invoice.hosted_invoice_url) ? invoice.hosted_invoice_url : undefined;
|
|
601
|
-
if (event.type === "invoice.paid") {
|
|
602
|
-
const amount_paid = typeof invoice.amount_paid === "number" && Number.isFinite(invoice.amount_paid) ? invoice.amount_paid : 0;
|
|
603
|
-
await await_event_trigger(opts.server.events.trigger("stripe.invoice_paid", {
|
|
604
|
-
uid,
|
|
605
|
-
stripe_invoice_id,
|
|
606
|
-
stripe_customer_id,
|
|
607
|
-
amount_paid,
|
|
608
|
-
currency,
|
|
609
|
-
hosted_invoice_url,
|
|
610
|
-
}));
|
|
611
|
-
}
|
|
612
|
-
else {
|
|
613
|
-
const amount_due = typeof invoice.amount_due === "number" && Number.isFinite(invoice.amount_due) ? invoice.amount_due : 0;
|
|
614
|
-
await await_event_trigger(opts.server.events.trigger("stripe.invoice_payment_failed", {
|
|
615
|
-
uid,
|
|
616
|
-
stripe_invoice_id,
|
|
617
|
-
stripe_customer_id,
|
|
618
|
-
amount_due,
|
|
619
|
-
currency,
|
|
620
|
-
hosted_invoice_url,
|
|
621
|
-
}));
|
|
622
|
-
}
|
|
623
|
-
processed_event_id_cache.set(event.id, true);
|
|
624
|
-
opts.stream.success({ status: 200, data: { received: true } });
|
|
625
|
-
return;
|
|
626
|
-
}
|
|
627
|
-
case "payment_intent.succeeded":
|
|
628
|
-
case "payment_intent.payment_failed": {
|
|
629
|
-
opts.server.log(1, "Stripe webhook received payment_intent event: ", { event_id: event.id, type: event.type });
|
|
630
|
-
const pi = event.data.object;
|
|
631
|
-
const stripe_payment_intent_id = pi.id;
|
|
632
|
-
assert(is_non_empty_string(stripe_payment_intent_id), "api_error", "PaymentIntent event missing id");
|
|
633
|
-
let uid = pi.metadata?.[stripe_uid_metadata_key];
|
|
634
|
-
const stripe_customer_id_value = pi.customer;
|
|
635
|
-
const stripe_customer_id = typeof stripe_customer_id_value === "string"
|
|
636
|
-
? stripe_customer_id_value
|
|
637
|
-
: stripe_customer_id_value?.id;
|
|
638
|
-
if (!is_non_empty_string(uid) && is_non_empty_string(stripe_customer_id)) {
|
|
639
|
-
const customer = await stripe_api_call(() => client.customers.retrieve(stripe_customer_id), { operation: "customers.retrieve", stripe_customer_id, reason: "resolve_uid_fallback" });
|
|
640
|
-
if ("deleted" in customer && customer.deleted === true) {
|
|
641
|
-
throw new InternalStripeError("customer_not_found", "PaymentIntent references a deleted customer.", { stripe_payment_intent_id, stripe_customer_id });
|
|
642
|
-
}
|
|
643
|
-
uid = customer.metadata?.[stripe_uid_metadata_key];
|
|
644
|
-
}
|
|
645
|
-
if (!is_non_empty_string(uid)) {
|
|
646
|
-
processed_event_id_cache.set(event.id, true);
|
|
647
|
-
opts.stream.success({ status: 200, data: { received: true } });
|
|
648
|
-
return;
|
|
649
|
-
}
|
|
650
|
-
const currency = pi.currency;
|
|
651
|
-
if (!is_non_empty_string(currency)) {
|
|
652
|
-
throw new InternalStripeError("api_error", "PaymentIntent missing currency.", { uid, stripe_payment_intent_id });
|
|
653
|
-
}
|
|
654
|
-
const metadata = pi.metadata ?? {};
|
|
655
|
-
if (event.type === "payment_intent.succeeded") {
|
|
656
|
-
const amount_received = typeof pi.amount_received === "number" && Number.isFinite(pi.amount_received) ? pi.amount_received : 0;
|
|
657
|
-
await await_event_trigger(opts.server.events.trigger("stripe.payment_succeeded", {
|
|
658
|
-
uid,
|
|
659
|
-
stripe_payment_intent_id,
|
|
660
|
-
stripe_customer_id,
|
|
661
|
-
amount_received,
|
|
662
|
-
currency,
|
|
663
|
-
metadata,
|
|
664
|
-
}));
|
|
665
|
-
}
|
|
666
|
-
else {
|
|
667
|
-
const amount = typeof pi.amount === "number" && Number.isFinite(pi.amount) ? pi.amount : 0;
|
|
668
|
-
const last_payment_error_message = is_non_empty_string(pi.last_payment_error?.message) ? pi.last_payment_error?.message : undefined;
|
|
669
|
-
await await_event_trigger(opts.server.events.trigger("stripe.payment_failed", {
|
|
670
|
-
uid,
|
|
671
|
-
stripe_payment_intent_id,
|
|
672
|
-
stripe_customer_id,
|
|
673
|
-
amount,
|
|
674
|
-
currency,
|
|
675
|
-
last_payment_error_message,
|
|
676
|
-
metadata,
|
|
677
|
-
}));
|
|
678
|
-
}
|
|
679
|
-
processed_event_id_cache.set(event.id, true);
|
|
680
|
-
opts.stream.success({ status: 200, data: { received: true } });
|
|
681
|
-
return;
|
|
682
|
-
}
|
|
683
|
-
case "setup_intent.succeeded": {
|
|
684
|
-
opts.server.log(1, "Stripe webhook received setup_intent.succeeded: ", { event_id: event.id });
|
|
685
|
-
const setup_intent = event.data.object;
|
|
686
|
-
const stripe_setup_intent_id = setup_intent.id;
|
|
687
|
-
assert(is_non_empty_string(stripe_setup_intent_id), "api_error", "SetupIntent event missing id");
|
|
688
|
-
const stripe_customer_id_value = setup_intent.customer;
|
|
689
|
-
const stripe_customer_id = typeof stripe_customer_id_value === "string"
|
|
690
|
-
? stripe_customer_id_value
|
|
691
|
-
: stripe_customer_id_value?.id;
|
|
692
|
-
if (!is_non_empty_string(stripe_customer_id)) {
|
|
693
|
-
throw new InternalStripeError("invalid_argument", "SetupIntent missing customer id.", { stripe_setup_intent_id });
|
|
694
|
-
}
|
|
695
|
-
let uid = setup_intent.metadata?.[stripe_uid_metadata_key];
|
|
696
|
-
if (!is_non_empty_string(uid)) {
|
|
697
|
-
const customer = await stripe_api_call(() => client.customers.retrieve(stripe_customer_id), { operation: "customers.retrieve", stripe_customer_id, reason: "resolve_uid_fallback" });
|
|
698
|
-
if ("deleted" in customer && customer.deleted === true) {
|
|
699
|
-
throw new InternalStripeError("customer_not_found", "SetupIntent references a deleted customer.", { stripe_setup_intent_id, stripe_customer_id });
|
|
700
|
-
}
|
|
701
|
-
uid = customer.metadata?.[stripe_uid_metadata_key];
|
|
702
|
-
}
|
|
703
|
-
if (!is_non_empty_string(uid)) {
|
|
704
|
-
throw new InternalStripeError("invalid_argument", "SetupIntent missing uid metadata (intent + customer).", { stripe_setup_intent_id, stripe_customer_id });
|
|
705
|
-
}
|
|
706
|
-
const finalized = await finalize_payment_method_setup(client, opts.server, {
|
|
707
|
-
uid,
|
|
708
|
-
setup_intent_id: stripe_setup_intent_id,
|
|
709
|
-
idempotency_key: stable_idempotency_key(`finalize_payment_method_setup:${event.id}`),
|
|
710
|
-
});
|
|
711
|
-
await await_event_trigger(opts.server.events.trigger("stripe.payment_method_ready", {
|
|
712
|
-
uid,
|
|
713
|
-
stripe_customer_id: finalized.stripe_customer_id,
|
|
714
|
-
stripe_setup_intent_id: finalized.setup_intent_id,
|
|
715
|
-
stripe_payment_method_id: finalized.payment_method_id,
|
|
716
|
-
}));
|
|
717
|
-
processed_event_id_cache.set(event.id, true);
|
|
718
|
-
opts.stream.success({ status: 200, data: { received: true } });
|
|
719
|
-
return;
|
|
720
|
-
}
|
|
721
|
-
default: {
|
|
722
|
-
opts.server.log(1, "Stripe webhook received unhandled event type: ", { event_id: event.id, type: event.type });
|
|
723
|
-
processed_event_id_cache.set(event.id, true);
|
|
724
|
-
opts.stream.success({ status: 200, data: { received: true } });
|
|
725
|
-
return;
|
|
726
|
-
}
|
|
727
|
-
}
|
|
728
|
-
}
|
|
729
|
-
finally {
|
|
730
|
-
inflight_event_id_cache.delete(event.id);
|
|
731
|
-
}
|
|
732
|
-
}
|
|
733
|
-
catch (error) {
|
|
734
|
-
// Always respond so Stripe can decide whether to retry.
|
|
735
|
-
// 2xx => success, non-2xx => retry.
|
|
736
|
-
let status = 500;
|
|
737
|
-
let type = "api_error";
|
|
738
|
-
let message = "Stripe webhook handling failed.";
|
|
739
|
-
if (error instanceof InternalStripeError) {
|
|
740
|
-
type = error.error_code ?? type;
|
|
741
|
-
// Treat argument/signature issues as 4xx to prevent pointless retries.
|
|
742
|
-
if (type === "invalid_argument") {
|
|
743
|
-
status = 400;
|
|
744
|
-
}
|
|
745
|
-
}
|
|
746
|
-
// Avoid double-send if caller already responded for some reason.
|
|
747
|
-
if (!opts.stream.finished) {
|
|
748
|
-
opts.stream.error({ status, type, message });
|
|
749
|
-
}
|
|
750
|
-
return;
|
|
751
|
-
}
|
|
752
|
-
}
|