@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,896 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @author Daan van den Bergh
|
|
3
|
-
* @copyright © 2026 - 2026 Daan van den Bergh. All rights reserved
|
|
4
|
-
*/
|
|
5
|
-
import { InternalStripeError } from "./error.js";
|
|
6
|
-
import { assert, generate_random_idempotency_key, stripe_api_call } from "./utils.js";
|
|
7
|
-
/**
|
|
8
|
-
* Nested types for the meter product definition.
|
|
9
|
-
*
|
|
10
|
-
* A meter product defines:
|
|
11
|
-
* - a Stripe Billing Meter (usage aggregation definition)
|
|
12
|
-
* - a Stripe Product + recurring metered Price attached to that meter
|
|
13
|
-
*
|
|
14
|
-
* Stripe docs:
|
|
15
|
-
* - Meters: https://docs.stripe.com/api/billing/meter
|
|
16
|
-
* - Create meter: https://docs.stripe.com/api/billing/meter/create
|
|
17
|
-
* - Prices (recurring.meter): https://docs.stripe.com/api/prices/create
|
|
18
|
-
*/
|
|
19
|
-
export var MeterProduct;
|
|
20
|
-
(function (MeterProduct) {
|
|
21
|
-
/** Multiplier from major units to pico-cent units: 100 * 10^12 = 10^14. */
|
|
22
|
-
MeterProduct.MONEY_METER_MAJOR_TO_PICO_CENTS_SHIFT = 14;
|
|
23
|
-
/** Fixed Stripe unit_amount_decimal for money meters, in cents. */
|
|
24
|
-
MeterProduct.MONEY_METER_UNIT_AMOUNT_DECIMAL_CENTS = "0.000000000001"; // 10^-12 cents
|
|
25
|
-
})(MeterProduct || (MeterProduct = {}));
|
|
26
|
-
// ----------------------------------------------------------------------------
|
|
27
|
-
// Internal constants.
|
|
28
|
-
/**
|
|
29
|
-
* The metadata key used to link an internal product id to a Stripe Product.
|
|
30
|
-
*/
|
|
31
|
-
const app_product_id_metadata_key = "__volt_app_product_id";
|
|
32
|
-
/**
|
|
33
|
-
* The metadata key used to link an internal plan id (or one-time price id) to a Stripe Price.
|
|
34
|
-
*/
|
|
35
|
-
const app_price_id_metadata_key = "__volt_app_price_id";
|
|
36
|
-
/**
|
|
37
|
-
* The metadata key storing a stable signature of price settings, used for detecting changes.
|
|
38
|
-
*/
|
|
39
|
-
const app_price_signature_metadata_key = "__volt_app_price_signature";
|
|
40
|
-
/**
|
|
41
|
-
* The Stripe list page size (maximum allowed by Stripe for list endpoints).
|
|
42
|
-
*/
|
|
43
|
-
const stripe_list_page_size = 100;
|
|
44
|
-
// ----------------------------------------------------------------------------
|
|
45
|
-
// Internal utilities.
|
|
46
|
-
/**
|
|
47
|
-
* Validate an integer amount in the smallest currency unit (e.g., cents).
|
|
48
|
-
*/
|
|
49
|
-
function validate_unit_amount(unit_amount, field_name) {
|
|
50
|
-
assert(Number.isInteger(unit_amount), "invalid_product", `Property '${field_name}' must be an integer (smallest currency unit)`, { field_name, unit_amount });
|
|
51
|
-
assert(unit_amount > 0, "invalid_product", `Property '${field_name}' must be > 0`, { field_name, unit_amount });
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Normalize a Stripe-compatible `unit_amount_decimal` string (smallest currency unit, e.g. cents).
|
|
55
|
-
*
|
|
56
|
-
* Goals:
|
|
57
|
-
* - Accept only Stripe-style non-negative decimals with up to 12 fractional digits.
|
|
58
|
-
* - Canonicalize equivalent numeric strings so signatures/metadata comparisons are stable.
|
|
59
|
-
* - Remove leading/trailing whitespace.
|
|
60
|
-
* - Normalize leading zeros in the whole part:
|
|
61
|
-
* "00012.3400" -> "12.3400"
|
|
62
|
-
* "0000.5" -> "0.5"
|
|
63
|
-
* "0.5" -> "0.5"
|
|
64
|
-
* - Normalize trailing zeros in the fractional part:
|
|
65
|
-
* "12.3400" -> "12.34"
|
|
66
|
-
* "12.000" -> "12"
|
|
67
|
-
* - Disallow zero values (matches your current pricing policy):
|
|
68
|
-
* "0", "0.0", "000.000" -> throws
|
|
69
|
-
*
|
|
70
|
-
* Notes:
|
|
71
|
-
* - This is designed for Stripe Price `unit_amount_decimal` (string) which supports up to 12 decimals.
|
|
72
|
-
* - This is intentionally strict (no "+", no "-", no scientific notation, no ".5").
|
|
73
|
-
*
|
|
74
|
-
* @throws {InternalStripeError} via `assert(...)` when invalid.
|
|
75
|
-
*/
|
|
76
|
-
function normalize_unit_amount_decimal(unit_amount_decimal, field_name) {
|
|
77
|
-
assert(typeof unit_amount_decimal === "string", "invalid_product", `Property '${field_name}' must be a string`, { field_name, unit_amount_decimal });
|
|
78
|
-
let s = unit_amount_decimal.trim();
|
|
79
|
-
assert(s.length > 0, "invalid_product", `Property '${field_name}' must be non-empty`, { field_name });
|
|
80
|
-
// Strict Stripe-style non-negative decimal with up to 12 fractional digits.
|
|
81
|
-
// - no sign
|
|
82
|
-
// - no scientific notation
|
|
83
|
-
// - requires whole digits (so ".5" is rejected)
|
|
84
|
-
// - allows optional fractional part with 1..12 digits
|
|
85
|
-
assert(/^\d+(\.\d{1,12})?$/.test(s), "invalid_product", `Property '${field_name}' must be a non-negative decimal with up to 12 decimals`, { field_name, unit_amount_decimal: s });
|
|
86
|
-
// Split whole/fractional.
|
|
87
|
-
const dot = s.indexOf(".");
|
|
88
|
-
const whole_raw = dot >= 0 ? s.slice(0, dot) : s;
|
|
89
|
-
const frac_raw = dot >= 0 ? s.slice(dot + 1) : "";
|
|
90
|
-
// Normalize whole:
|
|
91
|
-
// - strip all leading zeros
|
|
92
|
-
// - if empty -> "0"
|
|
93
|
-
let whole = whole_raw.replace(/^0+/, "");
|
|
94
|
-
if (whole === "")
|
|
95
|
-
whole = "0";
|
|
96
|
-
// Normalize fractional:
|
|
97
|
-
// - remove trailing zeros
|
|
98
|
-
// - if becomes empty -> no fractional part
|
|
99
|
-
let frac = frac_raw;
|
|
100
|
-
if (frac.length > 0) {
|
|
101
|
-
frac = frac.replace(/0+$/, "");
|
|
102
|
-
}
|
|
103
|
-
// Recompose canonical string.
|
|
104
|
-
s = frac.length > 0 ? `${whole}.${frac}` : whole;
|
|
105
|
-
// Reject zero values: "0" only (since "0.0" etc collapse to "0")
|
|
106
|
-
assert(s !== "0", "invalid_product", `Property '${field_name}' must be > 0`, { field_name, unit_amount_decimal: s });
|
|
107
|
-
// Final validation to be sure the normalization didn't produce an invalid string.
|
|
108
|
-
assert(/^\d+(\.\d{1,12})?$/.test(s), "invalid_product", "Normalization produced invalid decimal.", { s });
|
|
109
|
-
return s;
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* Resolve a unit price for meter products into Stripe Price create fields.
|
|
113
|
-
*
|
|
114
|
-
* Behavior:
|
|
115
|
-
* - Money meters: fixed `unit_amount_decimal` (in cents) at 10^-12 cents per unit.
|
|
116
|
-
* - Unit meters:
|
|
117
|
-
* - If `price` is a number: validate as a positive integer and return `{ unit_amount }`.
|
|
118
|
-
* - If `price` is `{ decimals: string }`: normalize to canonical form and return `{ unit_amount_decimal }`.
|
|
119
|
-
*
|
|
120
|
-
* Canonicalization:
|
|
121
|
-
* - Decimal prices are normalized by `normalize_unit_amount_decimal` to ensure:
|
|
122
|
-
* - stable signatures (`app_price_signature`)
|
|
123
|
-
* - stable matching of existing Stripe Prices
|
|
124
|
-
*
|
|
125
|
-
* @throws {InternalStripeError} via `assert(...)` when invalid.
|
|
126
|
-
*/
|
|
127
|
-
function resolve_unit_price_fields(product) {
|
|
128
|
-
if (product.kind === "money") {
|
|
129
|
-
// Fixed Stripe unit_amount_decimal for money meters, in cents (10^-12 cents).
|
|
130
|
-
return { unit_amount_decimal: MeterProduct.MONEY_METER_UNIT_AMOUNT_DECIMAL_CENTS };
|
|
131
|
-
}
|
|
132
|
-
if (product.kind === "units") {
|
|
133
|
-
const p = product.price;
|
|
134
|
-
if (typeof p === "number") {
|
|
135
|
-
// Positive integer in smallest currency unit (e.g., cents).
|
|
136
|
-
assert(Number.isInteger(p), "invalid_product", "Property 'price' must be an integer (smallest currency unit)", { field_name: "price", unit_amount: p });
|
|
137
|
-
assert(p > 0, "invalid_product", "Property 'price' must be > 0", { field_name: "price", unit_amount: p });
|
|
138
|
-
return { unit_amount: p };
|
|
139
|
-
}
|
|
140
|
-
// Validate object shape defensively.
|
|
141
|
-
assert(p !== null && typeof p === "object", "invalid_product", "Property 'price' must be a number or { decimals: string }", { price: p });
|
|
142
|
-
const decimals = p.decimals;
|
|
143
|
-
assert(typeof decimals === "string", "invalid_product", "Property 'price.decimals' must be a string", { price: p });
|
|
144
|
-
return { unit_amount_decimal: normalize_unit_amount_decimal(decimals, "price.decimals") };
|
|
145
|
-
}
|
|
146
|
-
// Exhaustiveness guard.
|
|
147
|
-
// @ts-expect-error exhaustive
|
|
148
|
-
product.kind.toString();
|
|
149
|
-
throw new InternalStripeError("invalid_product", `Unsupported meter product kind: ${product.kind}`, { kind: product.kind });
|
|
150
|
-
}
|
|
151
|
-
/**
|
|
152
|
-
* Validate quantity rules.
|
|
153
|
-
*/
|
|
154
|
-
function validate_quantity_rules(quantity_rules) {
|
|
155
|
-
if (!quantity_rules) {
|
|
156
|
-
return;
|
|
157
|
-
}
|
|
158
|
-
const { min, max } = quantity_rules;
|
|
159
|
-
if (min !== undefined) {
|
|
160
|
-
assert(Number.isInteger(min) && min >= 1, "invalid_product", "Quantity_rules.min must be an integer >= 1", {
|
|
161
|
-
min,
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
if (max !== undefined) {
|
|
165
|
-
assert(Number.isInteger(max) && max >= 1, "invalid_product", "Quantity_rules.max must be an integer >= 1", {
|
|
166
|
-
max,
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
if (min !== undefined && max !== undefined) {
|
|
170
|
-
assert(min <= max, "invalid_product", "Quantity_rules.min must be <= quantity_rules.max", { min, max });
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
/**
|
|
174
|
-
* Validate product images.
|
|
175
|
-
*/
|
|
176
|
-
function validate_images(images) {
|
|
177
|
-
if (!images) {
|
|
178
|
-
return;
|
|
179
|
-
}
|
|
180
|
-
assert(Array.isArray(images), "invalid_product", "Images must be an array", { images });
|
|
181
|
-
assert(images.length <= 8, "invalid_product", "Images must contain at most 8 URLs", { count: images.length });
|
|
182
|
-
for (const image of images) {
|
|
183
|
-
assert(typeof image === "string" && image.trim().length > 0, "invalid_product", "Image URL must be a non-empty string", { image });
|
|
184
|
-
// Require https URLs to avoid weird schemes ending up in Stripe/user-facing UIs.
|
|
185
|
-
assert(/^https:\/\/\S+$/i.test(image.trim()), "invalid_product", "Image URL must be an https URL", { image });
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
/**
|
|
189
|
-
* Create a stable signature for a one-time price.
|
|
190
|
-
* This signature is stored in Stripe Price metadata to detect config changes.
|
|
191
|
-
* @warning Never change this signature since it is used to link Stripe Prices to internal price definitions.
|
|
192
|
-
* Changing the signature format would cause all existing Stripe Prices to be considered stale and deactivated on the next initialization.
|
|
193
|
-
*/
|
|
194
|
-
function make_one_time_price_signature(opts) {
|
|
195
|
-
return `v1|one_time|${opts.currency}|${opts.unit_amount}|${opts.tax_behavior}`;
|
|
196
|
-
}
|
|
197
|
-
/**
|
|
198
|
-
* Create a stable signature for a recurring price.
|
|
199
|
-
* This signature is stored in Stripe Price metadata to detect config changes.
|
|
200
|
-
* @warning Never change this signature since it is used to link Stripe Prices to internal price definitions.
|
|
201
|
-
* Changing the signature format would cause all existing Stripe Prices to be considered stale and deactivated on the next initialization.
|
|
202
|
-
*/
|
|
203
|
-
function make_recurring_price_signature(opts) {
|
|
204
|
-
const meter_part = opts.usage_type === "metered" ? `|meter:${opts.meter_id ?? ""}` : "|meter:";
|
|
205
|
-
const amount_part = opts.unit_amount_decimal !== undefined ? opts.unit_amount_decimal : (opts.unit_amount ?? 0);
|
|
206
|
-
return `v1|recurring|${opts.currency}|${amount_part}|${opts.tax_behavior}|${opts.interval}|${opts.interval_count}|usage:${opts.usage_type}${meter_part}`;
|
|
207
|
-
}
|
|
208
|
-
/**
|
|
209
|
-
* Create a unique app id for the price's metadata.
|
|
210
|
-
* @warning This should not be changed, since this is used to link Stripe Prices to internal price definitions.
|
|
211
|
-
*/
|
|
212
|
-
function make_price_app_id(product_id, plan_id) {
|
|
213
|
-
return plan_id ? `${product_id}__plan__${plan_id}` : `${product_id}__one_time`;
|
|
214
|
-
}
|
|
215
|
-
/**
|
|
216
|
-
* List all Stripe products, paginated.
|
|
217
|
-
*
|
|
218
|
-
* Docs: https://docs.stripe.com/api/products/list
|
|
219
|
-
*/
|
|
220
|
-
async function list_all_stripe_products(client) {
|
|
221
|
-
const all_products = [];
|
|
222
|
-
let starting_after;
|
|
223
|
-
for (;;) {
|
|
224
|
-
const page = await stripe_api_call(() => client.products.list({
|
|
225
|
-
limit: stripe_list_page_size,
|
|
226
|
-
starting_after,
|
|
227
|
-
expand: ["data.default_price"],
|
|
228
|
-
}), { operation: "products.list_all", starting_after });
|
|
229
|
-
all_products.push(...page.data);
|
|
230
|
-
if (!page.has_more || page.data.length === 0) {
|
|
231
|
-
break;
|
|
232
|
-
}
|
|
233
|
-
const last = page.data[page.data.length - 1];
|
|
234
|
-
assert(last !== undefined, "api_error", "Stripe products pagination returned an empty last item", {
|
|
235
|
-
returned: page.data.length,
|
|
236
|
-
});
|
|
237
|
-
starting_after = last.id;
|
|
238
|
-
}
|
|
239
|
-
return all_products;
|
|
240
|
-
}
|
|
241
|
-
/**
|
|
242
|
-
* List all Stripe prices, paginated.
|
|
243
|
-
*
|
|
244
|
-
* Docs: https://docs.stripe.com/api/prices/list
|
|
245
|
-
*/
|
|
246
|
-
async function list_all_stripe_prices(client) {
|
|
247
|
-
const all_prices = [];
|
|
248
|
-
let starting_after;
|
|
249
|
-
for (;;) {
|
|
250
|
-
const page = await stripe_api_call(() => client.prices.list({
|
|
251
|
-
limit: stripe_list_page_size,
|
|
252
|
-
// We list only active prices because inactive ones are not usable for new purchases,
|
|
253
|
-
// and we only need active ones for initialization comparisons.
|
|
254
|
-
active: true,
|
|
255
|
-
starting_after,
|
|
256
|
-
}), { operation: "prices.list_all", starting_after });
|
|
257
|
-
all_prices.push(...page.data);
|
|
258
|
-
if (!page.has_more || page.data.length === 0) {
|
|
259
|
-
break;
|
|
260
|
-
}
|
|
261
|
-
const last = page.data[page.data.length - 1];
|
|
262
|
-
assert(last !== undefined, "api_error", "Stripe prices pagination returned an empty last item", {
|
|
263
|
-
returned: page.data.length,
|
|
264
|
-
});
|
|
265
|
-
starting_after = last.id;
|
|
266
|
-
}
|
|
267
|
-
return all_prices;
|
|
268
|
-
}
|
|
269
|
-
/**
|
|
270
|
-
* List all Stripe billing meters, paginated.
|
|
271
|
-
*
|
|
272
|
-
* Docs: https://docs.stripe.com/api/billing/meter/list
|
|
273
|
-
*/
|
|
274
|
-
async function list_all_stripe_meters(client) {
|
|
275
|
-
const all_meters = [];
|
|
276
|
-
let starting_after;
|
|
277
|
-
for (;;) {
|
|
278
|
-
// Stripe docs: https://docs.stripe.com/api/billing/meter/list
|
|
279
|
-
const page = await stripe_api_call(() => client.billing.meters.list({
|
|
280
|
-
limit: stripe_list_page_size,
|
|
281
|
-
starting_after,
|
|
282
|
-
}), { operation: "billing.meters.list_all", starting_after });
|
|
283
|
-
all_meters.push(...page.data);
|
|
284
|
-
if (!page.has_more || page.data.length === 0) {
|
|
285
|
-
break;
|
|
286
|
-
}
|
|
287
|
-
const last = page.data[page.data.length - 1];
|
|
288
|
-
assert(last !== undefined, "api_error", "Stripe meters pagination returned an empty last item", {
|
|
289
|
-
returned: page.data.length,
|
|
290
|
-
});
|
|
291
|
-
starting_after = last.id;
|
|
292
|
-
}
|
|
293
|
-
return all_meters;
|
|
294
|
-
}
|
|
295
|
-
/**
|
|
296
|
-
* Build a lookup table from app product id -> Stripe Product.
|
|
297
|
-
*/
|
|
298
|
-
function index_stripe_products_by_app_id(stripe_products) {
|
|
299
|
-
const map = new Map();
|
|
300
|
-
for (const product of stripe_products) {
|
|
301
|
-
const app_id = product.metadata?.[app_product_id_metadata_key];
|
|
302
|
-
if (app_id) {
|
|
303
|
-
assert(!map.has(app_id), "api_error", "Duplicate Stripe product metadata app id", {
|
|
304
|
-
app_id,
|
|
305
|
-
existing_stripe_product_id: map.get(app_id)?.id,
|
|
306
|
-
duplicate_stripe_product_id: product.id,
|
|
307
|
-
});
|
|
308
|
-
map.set(app_id, product);
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
return map;
|
|
312
|
-
}
|
|
313
|
-
/**
|
|
314
|
-
* Build a lookup table from Stripe product id -> active Stripe prices for that product.
|
|
315
|
-
*/
|
|
316
|
-
function index_active_prices_by_stripe_product_id(stripe_prices) {
|
|
317
|
-
const map = new Map();
|
|
318
|
-
for (const price of stripe_prices) {
|
|
319
|
-
// Stripe.Price.product can be string | Stripe.Product | Stripe.DeletedProduct
|
|
320
|
-
// We only index when it is a string id.
|
|
321
|
-
if (typeof price.product !== "string") {
|
|
322
|
-
continue;
|
|
323
|
-
}
|
|
324
|
-
const list = map.get(price.product) ?? [];
|
|
325
|
-
list.push(price);
|
|
326
|
-
map.set(price.product, list);
|
|
327
|
-
}
|
|
328
|
-
return map;
|
|
329
|
-
}
|
|
330
|
-
/**
|
|
331
|
-
* Build a lookup table from meter event_name -> Stripe Billing Meter.
|
|
332
|
-
*
|
|
333
|
-
* Note: Stripe Billing Meters do not currently expose metadata in the API reference,
|
|
334
|
-
* so we link by stable event_name (which must be unique in the Stripe account).
|
|
335
|
-
* Docs: https://docs.stripe.com/api/billing/meter/object
|
|
336
|
-
*/
|
|
337
|
-
function index_stripe_meters_by_event_name(stripe_meters) {
|
|
338
|
-
const map = new Map();
|
|
339
|
-
for (const meter of stripe_meters) {
|
|
340
|
-
const event_name = meter.event_name;
|
|
341
|
-
if (event_name) {
|
|
342
|
-
assert(!map.has(event_name), "api_error", "Duplicate Stripe meter event_name", {
|
|
343
|
-
event_name,
|
|
344
|
-
existing_stripe_meter_id: map.get(event_name)?.id,
|
|
345
|
-
duplicate_stripe_meter_id: meter.id,
|
|
346
|
-
});
|
|
347
|
-
map.set(event_name, meter);
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
return map;
|
|
351
|
-
}
|
|
352
|
-
/**
|
|
353
|
-
* Find an active Stripe Price by internal price id and signature.
|
|
354
|
-
*
|
|
355
|
-
* Docs: https://docs.stripe.com/api/prices
|
|
356
|
-
*/
|
|
357
|
-
function find_matching_active_price(active_prices, app_price_id, expected_signature) {
|
|
358
|
-
const match = active_prices.find((p) => {
|
|
359
|
-
const meta_price_id = p.metadata?.[app_price_id_metadata_key];
|
|
360
|
-
const meta_signature = p.metadata?.[app_price_signature_metadata_key];
|
|
361
|
-
return meta_price_id === app_price_id && meta_signature === expected_signature;
|
|
362
|
-
});
|
|
363
|
-
return match ?? null;
|
|
364
|
-
}
|
|
365
|
-
// /**
|
|
366
|
-
// * Deactivate all active Stripe Prices that match the internal price id but have different signatures.
|
|
367
|
-
// *
|
|
368
|
-
// * Docs: https://docs.stripe.com/api/prices/update
|
|
369
|
-
// */
|
|
370
|
-
// async function deactivate_stale_prices_for_app_price_id(
|
|
371
|
-
// client: Stripe,
|
|
372
|
-
// server: Server,
|
|
373
|
-
// active_prices: Stripe.Price[],
|
|
374
|
-
// app_price_id: string,
|
|
375
|
-
// expected_signature: string,
|
|
376
|
-
// ): Promise<void> {
|
|
377
|
-
// const stale_prices = active_prices.filter((p) => {
|
|
378
|
-
// const meta_price_id = p.metadata?.[app_price_id_metadata_key];
|
|
379
|
-
// const meta_signature = p.metadata?.[app_price_signature_metadata_key];
|
|
380
|
-
// return meta_price_id === app_price_id && meta_signature !== expected_signature;
|
|
381
|
-
// });
|
|
382
|
-
// await Promise.all(
|
|
383
|
-
// stale_prices.map((p) =>
|
|
384
|
-
// stripe_api_call(
|
|
385
|
-
// () =>
|
|
386
|
-
// client.prices.update(
|
|
387
|
-
// p.id,
|
|
388
|
-
// { active: false },
|
|
389
|
-
// { idempotencyKey: stable_idempotency_key(`init|prices.update|deactivate|${app_price_id}|${p.id}`) },
|
|
390
|
-
// ),
|
|
391
|
-
// { operation: "prices.update", app_price_id, stripe_price_id: p.id, action: "deactivate" },
|
|
392
|
-
// ),
|
|
393
|
-
// ),
|
|
394
|
-
// );
|
|
395
|
-
// }
|
|
396
|
-
/**
|
|
397
|
-
* Create a Stripe Product for a given internal Product.
|
|
398
|
-
*
|
|
399
|
-
* Docs: https://docs.stripe.com/api/products/create
|
|
400
|
-
* Tax code docs: https://docs.stripe.com/tax/tax-codes
|
|
401
|
-
*/
|
|
402
|
-
async function create_stripe_product(client, server, product) {
|
|
403
|
-
server.log(0, `Creating Stripe product for product '${product.id}'`);
|
|
404
|
-
return await stripe_api_call(() => client.products.create({
|
|
405
|
-
name: product.name,
|
|
406
|
-
description: product.description,
|
|
407
|
-
tax_code: product.tax_code,
|
|
408
|
-
images: product.images,
|
|
409
|
-
metadata: {
|
|
410
|
-
[app_product_id_metadata_key]: product.id,
|
|
411
|
-
},
|
|
412
|
-
expand: ["default_price"],
|
|
413
|
-
}, { idempotencyKey: generate_random_idempotency_key(`create_product_${product.id}`) }), { operation: "products.create", app_product_id: product.id });
|
|
414
|
-
}
|
|
415
|
-
/**
|
|
416
|
-
* Update a Stripe Product if user-facing fields changed.
|
|
417
|
-
*
|
|
418
|
-
* Docs: https://docs.stripe.com/api/products/update
|
|
419
|
-
*/
|
|
420
|
-
async function update_stripe_product_if_needed(client, server, stripe_product, product) {
|
|
421
|
-
const stripe_images = stripe_product.images ?? [];
|
|
422
|
-
const app_images = product.images ?? [];
|
|
423
|
-
const images_equal = stripe_images.length === app_images.length &&
|
|
424
|
-
stripe_images.every((url, index) => url === app_images[index]);
|
|
425
|
-
const needs_update = stripe_product.name !== product.name ||
|
|
426
|
-
(stripe_product.description ?? "") !== (product.description ?? "") ||
|
|
427
|
-
(stripe_product.tax_code ?? "") !== (product.tax_code ?? "") ||
|
|
428
|
-
!images_equal;
|
|
429
|
-
if (!needs_update) {
|
|
430
|
-
return stripe_product;
|
|
431
|
-
}
|
|
432
|
-
server.log(0, `Updating Stripe product '${stripe_product.id}' to match app product '${product.id}'`);
|
|
433
|
-
return await stripe_api_call(() => client.products.update(stripe_product.id, {
|
|
434
|
-
name: product.name,
|
|
435
|
-
description: product.description,
|
|
436
|
-
tax_code: product.tax_code,
|
|
437
|
-
images: product.images,
|
|
438
|
-
expand: ["default_price"],
|
|
439
|
-
}, { idempotencyKey: generate_random_idempotency_key(`update_product_${product.id}_${stripe_product.id}`) }), { operation: "products.update", app_product_id: product.id, stripe_product_id: stripe_product.id });
|
|
440
|
-
}
|
|
441
|
-
/**
|
|
442
|
-
* Update default price on a stripe product if needed.
|
|
443
|
-
*/
|
|
444
|
-
async function update_stripe_product_default_price_if_needed(client, server, stripe_product, default_price, other_plans_from_parent_subscription) {
|
|
445
|
-
// Extract default price.
|
|
446
|
-
let default_price_id = null;
|
|
447
|
-
if (typeof stripe_product.default_price === "string") {
|
|
448
|
-
default_price_id = stripe_product.default_price;
|
|
449
|
-
}
|
|
450
|
-
else if (stripe_product.default_price && typeof stripe_product.default_price === "object") {
|
|
451
|
-
default_price_id = stripe_product.default_price.id;
|
|
452
|
-
}
|
|
453
|
-
// If its still undefined, fetch the product to get the default_price expanded (this should be rare since we expand it on list/create/update).
|
|
454
|
-
if (!default_price_id) {
|
|
455
|
-
const fetched = await stripe_api_call(() => client.products.retrieve(stripe_product.id, {
|
|
456
|
-
expand: ["default_price"],
|
|
457
|
-
}), { operation: "products.retrieve_for_default_price", stripe_product_id: stripe_product.id });
|
|
458
|
-
default_price_id = typeof fetched.default_price === "string" ? fetched.default_price : fetched.default_price?.id ?? null;
|
|
459
|
-
}
|
|
460
|
-
// If the default price is already correct, do nothing.
|
|
461
|
-
if (default_price_id === default_price.id
|
|
462
|
-
// For subscription products, the default_price may be shared across multiple plans, so we also check if any other plan from the same subscription is using the price. If so, we should not update the default_price since it would affect those plans as well.
|
|
463
|
-
|| other_plans_from_parent_subscription?.some((plan) => plan.stripe_price_id === default_price_id)) {
|
|
464
|
-
return;
|
|
465
|
-
}
|
|
466
|
-
server.log(0, `Updating default price for Stripe product '${stripe_product.id}' to price '${default_price.id}'`);
|
|
467
|
-
await stripe_api_call(() => client.products.update(stripe_product.id, {
|
|
468
|
-
default_price: default_price.id,
|
|
469
|
-
}, { idempotencyKey: generate_random_idempotency_key(`update_product_default_price_${stripe_product.id}_${default_price.id}`) }), { operation: "products.update", app_product_id: stripe_product.metadata?.[app_product_id_metadata_key], stripe_product_id: stripe_product.id, action: "update_default_price" });
|
|
470
|
-
}
|
|
471
|
-
/**
|
|
472
|
-
* Create a Stripe one-time Price for a product.
|
|
473
|
-
*
|
|
474
|
-
* Docs: https://docs.stripe.com/api/prices/create
|
|
475
|
-
*/
|
|
476
|
-
async function create_one_time_price(client, server, opts) {
|
|
477
|
-
server.log(0, `Creating stripe one-time price for product: ${opts.product_id}`);
|
|
478
|
-
return await stripe_api_call(() => client.prices.create({
|
|
479
|
-
product: opts.stripe_product_id,
|
|
480
|
-
currency: opts.currency,
|
|
481
|
-
unit_amount: opts.unit_amount,
|
|
482
|
-
// Docs: https://docs.stripe.com/tax/tax-behavior
|
|
483
|
-
tax_behavior: opts.tax_behavior,
|
|
484
|
-
nickname: opts.nickname,
|
|
485
|
-
metadata: {
|
|
486
|
-
[app_price_id_metadata_key]: opts.app_price_id,
|
|
487
|
-
[app_price_signature_metadata_key]: make_one_time_price_signature({
|
|
488
|
-
currency: opts.currency,
|
|
489
|
-
unit_amount: opts.unit_amount,
|
|
490
|
-
tax_behavior: opts.tax_behavior,
|
|
491
|
-
}),
|
|
492
|
-
},
|
|
493
|
-
}, { idempotencyKey: generate_random_idempotency_key(`create_one_time_price_${opts.app_price_id}_${opts.stripe_product_id}`) }), { operation: "prices.create", app_price_id: opts.app_price_id, stripe_product_id: opts.stripe_product_id });
|
|
494
|
-
}
|
|
495
|
-
/**
|
|
496
|
-
* Create a Stripe recurring Price.
|
|
497
|
-
*
|
|
498
|
-
* Docs: https://docs.stripe.com/api/prices/create
|
|
499
|
-
*/
|
|
500
|
-
async function create_recurring_price(client, server, opts) {
|
|
501
|
-
// Build recurring fields with optional metered settings.
|
|
502
|
-
const recurring = {
|
|
503
|
-
interval: opts.interval,
|
|
504
|
-
interval_count: opts.interval_count,
|
|
505
|
-
// "metered" links the price to a billing meter; "licensed" is standard recurring.
|
|
506
|
-
// Docs: https://docs.stripe.com/api/prices/create (recurring.usage_type)
|
|
507
|
-
usage_type: opts.recurring_usage.usage_type,
|
|
508
|
-
// For metered prices, connect the Stripe price to a meter id.
|
|
509
|
-
// Docs: https://docs.stripe.com/api/prices/create (recurring.meter)
|
|
510
|
-
...(opts.recurring_usage.usage_type === "metered" ? { meter: opts.recurring_usage.meter_id } : {}),
|
|
511
|
-
};
|
|
512
|
-
const signature = make_recurring_price_signature({
|
|
513
|
-
currency: opts.currency,
|
|
514
|
-
...(("unit_amount_decimal" in opts)
|
|
515
|
-
? { unit_amount_decimal: opts.unit_amount_decimal }
|
|
516
|
-
: { unit_amount: opts.unit_amount }),
|
|
517
|
-
tax_behavior: opts.tax_behavior,
|
|
518
|
-
interval: opts.interval,
|
|
519
|
-
interval_count: opts.interval_count,
|
|
520
|
-
usage_type: opts.recurring_usage.usage_type,
|
|
521
|
-
meter_id: opts.recurring_usage.usage_type === "metered" ? opts.recurring_usage.meter_id : undefined,
|
|
522
|
-
});
|
|
523
|
-
server.log(0, `Creating stripe recurring price for product: ${opts.product_id}`);
|
|
524
|
-
return await stripe_api_call(() => client.prices.create({
|
|
525
|
-
product: opts.stripe_product_id,
|
|
526
|
-
currency: opts.currency,
|
|
527
|
-
...(("unit_amount_decimal" in opts)
|
|
528
|
-
? { unit_amount_decimal: opts.unit_amount_decimal }
|
|
529
|
-
: { unit_amount: opts.unit_amount }),
|
|
530
|
-
tax_behavior: opts.tax_behavior,
|
|
531
|
-
nickname: opts.nickname,
|
|
532
|
-
// Docs: https://docs.stripe.com/billing/prices-guide#create-prices
|
|
533
|
-
recurring,
|
|
534
|
-
metadata: {
|
|
535
|
-
[app_price_id_metadata_key]: opts.app_price_id,
|
|
536
|
-
[app_price_signature_metadata_key]: signature,
|
|
537
|
-
},
|
|
538
|
-
}, { idempotencyKey: generate_random_idempotency_key(`create_recurring_price_${opts.app_price_id}_${opts.stripe_product_id}`) }), { operation: "prices.create", app_price_id: opts.app_price_id, stripe_product_id: opts.stripe_product_id });
|
|
539
|
-
}
|
|
540
|
-
/**
|
|
541
|
-
* Create a Stripe Billing Meter.
|
|
542
|
-
*
|
|
543
|
-
* Docs: https://docs.stripe.com/api/billing/meter/create
|
|
544
|
-
*/
|
|
545
|
-
async function create_stripe_meter(client, server, product) {
|
|
546
|
-
const aggregation_formula = product.aggregation_formula ?? "sum";
|
|
547
|
-
const customer_mapping_event_payload_key = product.customer_mapping_event_payload_key ?? "stripe_customer_id";
|
|
548
|
-
const value_settings_event_payload_key = product.value_settings_event_payload_key ?? "value";
|
|
549
|
-
server.log(0, `Creating stripe billing meter for product: ${product.id}`);
|
|
550
|
-
return await stripe_api_call(() => client.billing.meters.create({
|
|
551
|
-
display_name: product.name,
|
|
552
|
-
event_name: product.meter_event_name,
|
|
553
|
-
default_aggregation: {
|
|
554
|
-
formula: aggregation_formula,
|
|
555
|
-
},
|
|
556
|
-
// Stripe currently requires by_id mapping and a payload key that contains the customer id.
|
|
557
|
-
// Docs: https://docs.stripe.com/api/billing/meter/create#billing_meter_create-customer_mapping
|
|
558
|
-
customer_mapping: {
|
|
559
|
-
type: "by_id",
|
|
560
|
-
event_payload_key: customer_mapping_event_payload_key,
|
|
561
|
-
},
|
|
562
|
-
// Value key used as the numeric value for "sum"/"last" aggregation.
|
|
563
|
-
// Docs: https://docs.stripe.com/api/billing/meter/create#billing_meter_create-value_settings
|
|
564
|
-
value_settings: {
|
|
565
|
-
event_payload_key: value_settings_event_payload_key,
|
|
566
|
-
},
|
|
567
|
-
...(product.event_time_window ? { event_time_window: product.event_time_window } : {}),
|
|
568
|
-
}, { idempotencyKey: generate_random_idempotency_key(`create_billing_meter_${product.id}_${product.meter_event_name}`) }), {
|
|
569
|
-
operation: "billing.meters.create",
|
|
570
|
-
app_meter_product_id: product.id,
|
|
571
|
-
event_name: product.meter_event_name,
|
|
572
|
-
aggregation_formula,
|
|
573
|
-
customer_mapping_event_payload_key,
|
|
574
|
-
value_settings_event_payload_key,
|
|
575
|
-
event_time_window: product.event_time_window ?? null,
|
|
576
|
-
});
|
|
577
|
-
}
|
|
578
|
-
/**
|
|
579
|
-
* Run async work with limited concurrency, preserving input order.
|
|
580
|
-
*/
|
|
581
|
-
async function map_with_concurrency(items, concurrency, mapper) {
|
|
582
|
-
assert(Number.isInteger(concurrency) && concurrency >= 1, "invalid_argument", "Concurrency must be an integer >= 1", { concurrency });
|
|
583
|
-
const results = new Array(items.length);
|
|
584
|
-
let next_index = 0;
|
|
585
|
-
let first_error = null;
|
|
586
|
-
const worker = async () => {
|
|
587
|
-
for (;;) {
|
|
588
|
-
if (first_error)
|
|
589
|
-
return;
|
|
590
|
-
const current_index = next_index;
|
|
591
|
-
next_index += 1;
|
|
592
|
-
if (current_index >= items.length) {
|
|
593
|
-
return;
|
|
594
|
-
}
|
|
595
|
-
const current_item = items[current_index];
|
|
596
|
-
assert(current_item !== undefined, "invalid_argument", "Missing item for concurrency worker index", { current_index, items_length: items.length });
|
|
597
|
-
try {
|
|
598
|
-
results[current_index] = await mapper(current_item, current_index);
|
|
599
|
-
}
|
|
600
|
-
catch (e) {
|
|
601
|
-
// Stop other workers ASAP; rethrow after all workers settle.
|
|
602
|
-
if (!first_error)
|
|
603
|
-
first_error = e;
|
|
604
|
-
return;
|
|
605
|
-
}
|
|
606
|
-
}
|
|
607
|
-
};
|
|
608
|
-
const worker_count = Math.min(concurrency, items.length);
|
|
609
|
-
await Promise.allSettled(Array.from({ length: worker_count }, () => worker()));
|
|
610
|
-
if (first_error)
|
|
611
|
-
throw first_error;
|
|
612
|
-
return results;
|
|
613
|
-
}
|
|
614
|
-
// ----------------------------------------------------------------------------
|
|
615
|
-
// Private initializer.
|
|
616
|
-
/**
|
|
617
|
-
* Initialize a product using pre-fetched Stripe products/prices indexes.
|
|
618
|
-
*/
|
|
619
|
-
async function initialize_product(client, server, product, stripe_products_by_app_id, active_prices_by_stripe_product_id, stripe_meters_by_event_name) {
|
|
620
|
-
assert(product.id.trim().length > 0, "invalid_product", "Product.id must be non-empty", { product_id: product.id });
|
|
621
|
-
assert(product.name.trim().length > 0, "invalid_product", "Product.name must be non-empty", { product_id: product.id });
|
|
622
|
-
assert(product.currency.trim().length > 0, "invalid_product", "Product.currency must be non-empty", { product_id: product.id });
|
|
623
|
-
assert(product.tax_code.trim().length > 0, "invalid_product", "Product.tax_code must be non-empty", { product_id: product.id });
|
|
624
|
-
assert(product.tax_behavior === "inclusive" ||
|
|
625
|
-
product.tax_behavior === "exclusive" ||
|
|
626
|
-
product.tax_behavior === "unspecified", "invalid_product", "Product.tax_behavior is invalid", { product_id: product.id, tax_behavior: product.tax_behavior });
|
|
627
|
-
validate_images(product.images);
|
|
628
|
-
// Normalize currency code to lowercase for consistent matching and Stripe API usage.
|
|
629
|
-
product.currency = product.currency.trim().toLowerCase();
|
|
630
|
-
assert(/^[a-z]{3}$/.test(product.currency), "invalid_product", `Invalid currency code: "${product.currency}"`, { currency: product.currency });
|
|
631
|
-
if (product.type === "one_time") {
|
|
632
|
-
validate_unit_amount(product.price, "Product.price");
|
|
633
|
-
validate_quantity_rules(product.quantity_rules);
|
|
634
|
-
}
|
|
635
|
-
else if (product.type === "subscription") {
|
|
636
|
-
assert(Array.isArray(product.plans) && product.plans.length > 0, "invalid_product", "Subscription product must have plans", { product_id: product.id });
|
|
637
|
-
if (product.trial_days !== undefined) {
|
|
638
|
-
assert(Number.isInteger(product.trial_days) && product.trial_days >= 1, "invalid_product", "Subscription.trial_days must be an integer >= 1", { product_id: product.id, trial_days: product.trial_days });
|
|
639
|
-
}
|
|
640
|
-
if (product.billing_anchor !== undefined) {
|
|
641
|
-
const anchor = product.billing_anchor;
|
|
642
|
-
assert(anchor === "immediately" || anchor === "first_of_month", "invalid_product", "Subscription.billing_anchor is invalid", { product_id: product.id, billing_anchor: anchor });
|
|
643
|
-
}
|
|
644
|
-
else {
|
|
645
|
-
// Default to "immediately" if not set.
|
|
646
|
-
product.billing_anchor = "immediately";
|
|
647
|
-
}
|
|
648
|
-
for (const plan of product.plans) {
|
|
649
|
-
assert(plan.id.trim().length > 0, "invalid_product", "Plan.id must be non-empty", { product_id: product.id });
|
|
650
|
-
assert(plan.name.trim().length > 0, "invalid_product", "Plan.name must be non-empty", { product_id: product.id, plan_id: plan.id });
|
|
651
|
-
validate_unit_amount(plan.price, "Plan.price");
|
|
652
|
-
assert(Number.isInteger(plan.interval_count) && plan.interval_count >= 1, "invalid_product", "Plan.interval_count must be >= 1", { product_id: product.id, plan_id: plan.id, interval_count: plan.interval_count });
|
|
653
|
-
assert(plan.interval === "day" || plan.interval === "week" || plan.interval === "month" || plan.interval === "year", "invalid_product", "Plan.interval is invalid", { product_id: product.id, plan_id: plan.id, interval: plan.interval });
|
|
654
|
-
}
|
|
655
|
-
}
|
|
656
|
-
else if (product.type === "meter") {
|
|
657
|
-
assert(product.interval === "day" || product.interval === "week" || product.interval === "month" || product.interval === "year", "invalid_product", "Property 'interval' is invalid", { product_id: product.id, interval: product.interval });
|
|
658
|
-
if (product.kind === "units") {
|
|
659
|
-
assert(product.price !== undefined, "invalid_product", "MeterProduct with kind='units' must define 'price'.", { product_id: product.id });
|
|
660
|
-
// validates + normalizes shape
|
|
661
|
-
resolve_unit_price_fields(product);
|
|
662
|
-
}
|
|
663
|
-
else if (product.kind === "money") {
|
|
664
|
-
// money meter: no price is allowed
|
|
665
|
-
assert(product.price === undefined, "invalid_product", "MeterProduct with kind='money' must not define 'price'.", { product_id: product.id });
|
|
666
|
-
}
|
|
667
|
-
else {
|
|
668
|
-
// @ts-expect-error
|
|
669
|
-
product.kind.toString();
|
|
670
|
-
throw new InternalStripeError("invalid_product", `Invalid 'kind': ${product.kind}`, { product_id: product.id, kind: product.kind });
|
|
671
|
-
}
|
|
672
|
-
assert(Number.isInteger(product.interval_count) && product.interval_count >= 1, "invalid_product", "Property 'interval_count' must be >= 1", { product_id: product.id, interval_count: product.interval_count });
|
|
673
|
-
assert(product.meter_event_name.trim().length > 0, "invalid_product", "Property 'meter_event_name' must be non-empty", {
|
|
674
|
-
product_id: product.id,
|
|
675
|
-
meter_event_name: product.meter_event_name,
|
|
676
|
-
});
|
|
677
|
-
// Stripe meter event_name max length is 100 chars.
|
|
678
|
-
// Docs: https://docs.stripe.com/api/billing/meter/create
|
|
679
|
-
assert(product.meter_event_name.length <= 100, "invalid_product", "Property 'meter_event_name' must be <= 100 characters", { product_id: product.id, meter_event_name_length: product.meter_event_name.length });
|
|
680
|
-
if (product.aggregation_formula !== undefined) {
|
|
681
|
-
const formula = product.aggregation_formula;
|
|
682
|
-
assert(formula === "count" || formula === "sum" || formula === "last", "invalid_product", "Property 'aggregation_formula' is invalid", { product_id: product.id, aggregation_formula: formula });
|
|
683
|
-
}
|
|
684
|
-
if (product.customer_mapping_event_payload_key !== undefined) {
|
|
685
|
-
assert(product.customer_mapping_event_payload_key.trim().length > 0, "invalid_product", "Property 'customer_mapping_event_payload_key' must be non-empty", { product_id: product.id, customer_mapping_event_payload_key: product.customer_mapping_event_payload_key });
|
|
686
|
-
}
|
|
687
|
-
if (product.value_settings_event_payload_key !== undefined) {
|
|
688
|
-
assert(product.value_settings_event_payload_key.trim().length > 0, "invalid_product", "Property 'value_settings_event_payload_key' must be non-empty", { product_id: product.id, value_settings_event_payload_key: product.value_settings_event_payload_key });
|
|
689
|
-
}
|
|
690
|
-
if (product.event_time_window !== undefined) {
|
|
691
|
-
const window = product.event_time_window;
|
|
692
|
-
assert(window === "hour" || window === "day", "invalid_product", "Property 'event_time_window' is invalid", { product_id: product.id, event_time_window: window });
|
|
693
|
-
}
|
|
694
|
-
}
|
|
695
|
-
else {
|
|
696
|
-
//@ts-expect-error product.type should be never here
|
|
697
|
-
product.type.toString();
|
|
698
|
-
throw new InternalStripeError("invalid_product", `Invalid product type: ${product.type}`, {
|
|
699
|
-
product_id: product.id, product_type: product.type
|
|
700
|
-
});
|
|
701
|
-
}
|
|
702
|
-
// 0) If this is a meter product, ensure the Stripe Billing Meter exists (or create it).
|
|
703
|
-
let stripe_meter = null;
|
|
704
|
-
if (product.type === "meter") {
|
|
705
|
-
stripe_meter = stripe_meters_by_event_name.get(product.meter_event_name) ?? null;
|
|
706
|
-
if (!stripe_meter) {
|
|
707
|
-
stripe_meter = await create_stripe_meter(client, server, product);
|
|
708
|
-
stripe_meters_by_event_name.set(product.meter_event_name, stripe_meter);
|
|
709
|
-
}
|
|
710
|
-
}
|
|
711
|
-
// 1) Ensure Stripe Product exists (or create it), linked by metadata.
|
|
712
|
-
let stripe_product = stripe_products_by_app_id.get(product.id) ?? null;
|
|
713
|
-
if (!stripe_product) {
|
|
714
|
-
stripe_product = await create_stripe_product(client, server, product);
|
|
715
|
-
stripe_products_by_app_id.set(product.id, stripe_product);
|
|
716
|
-
}
|
|
717
|
-
else {
|
|
718
|
-
stripe_product = await update_stripe_product_if_needed(client, server, stripe_product, product);
|
|
719
|
-
stripe_products_by_app_id.set(product.id, stripe_product);
|
|
720
|
-
}
|
|
721
|
-
// 2) Resolve active prices for this Stripe product (from pre-fetched index).
|
|
722
|
-
const active_prices = active_prices_by_stripe_product_id.get(stripe_product.id) ?? [];
|
|
723
|
-
if (product.type === "one_time") {
|
|
724
|
-
const app_price_id = make_price_app_id(product.id, undefined);
|
|
725
|
-
const signature = make_one_time_price_signature({
|
|
726
|
-
currency: product.currency,
|
|
727
|
-
unit_amount: product.price,
|
|
728
|
-
tax_behavior: product.tax_behavior,
|
|
729
|
-
});
|
|
730
|
-
let stripe_price = find_matching_active_price(active_prices, app_price_id, signature);
|
|
731
|
-
if (!stripe_price) {
|
|
732
|
-
stripe_price = await create_one_time_price(client, server, {
|
|
733
|
-
product_id: product.id,
|
|
734
|
-
stripe_product_id: stripe_product.id,
|
|
735
|
-
app_price_id,
|
|
736
|
-
currency: product.currency,
|
|
737
|
-
unit_amount: product.price,
|
|
738
|
-
tax_behavior: product.tax_behavior,
|
|
739
|
-
nickname: product.name,
|
|
740
|
-
});
|
|
741
|
-
const updated_prices = [...active_prices, stripe_price];
|
|
742
|
-
active_prices_by_stripe_product_id.set(stripe_product.id, updated_prices);
|
|
743
|
-
}
|
|
744
|
-
await update_stripe_product_default_price_if_needed(client, server, stripe_product, stripe_price);
|
|
745
|
-
return {
|
|
746
|
-
...product,
|
|
747
|
-
stripe_product_id: stripe_product.id,
|
|
748
|
-
stripe_price_id: stripe_price.id,
|
|
749
|
-
};
|
|
750
|
-
}
|
|
751
|
-
else if (product.type === "subscription") {
|
|
752
|
-
const initialized_plans = [];
|
|
753
|
-
for (const plan of product.plans) {
|
|
754
|
-
const app_price_id = make_price_app_id(product.id, plan.id);
|
|
755
|
-
const signature = make_recurring_price_signature({
|
|
756
|
-
currency: product.currency,
|
|
757
|
-
unit_amount: plan.price,
|
|
758
|
-
tax_behavior: product.tax_behavior,
|
|
759
|
-
interval: plan.interval,
|
|
760
|
-
interval_count: plan.interval_count,
|
|
761
|
-
usage_type: "licensed",
|
|
762
|
-
});
|
|
763
|
-
let stripe_price = find_matching_active_price(active_prices, app_price_id, signature);
|
|
764
|
-
if (!stripe_price) {
|
|
765
|
-
stripe_price = await create_recurring_price(client, server, {
|
|
766
|
-
product_id: product.id,
|
|
767
|
-
stripe_product_id: stripe_product.id,
|
|
768
|
-
app_price_id,
|
|
769
|
-
currency: product.currency,
|
|
770
|
-
unit_amount: plan.price,
|
|
771
|
-
tax_behavior: product.tax_behavior,
|
|
772
|
-
nickname: `${product.name} - ${plan.name}`,
|
|
773
|
-
interval: plan.interval,
|
|
774
|
-
interval_count: plan.interval_count,
|
|
775
|
-
recurring_usage: { usage_type: "licensed" },
|
|
776
|
-
});
|
|
777
|
-
const updated_prices = [...active_prices, stripe_price];
|
|
778
|
-
active_prices_by_stripe_product_id.set(stripe_product.id, updated_prices);
|
|
779
|
-
}
|
|
780
|
-
await update_stripe_product_default_price_if_needed(client, server, stripe_product, stripe_price, initialized_plans);
|
|
781
|
-
initialized_plans.push({
|
|
782
|
-
...plan,
|
|
783
|
-
type: "subscription_plan",
|
|
784
|
-
subscription_id: product.id,
|
|
785
|
-
stripe_price_id: stripe_price.id,
|
|
786
|
-
});
|
|
787
|
-
}
|
|
788
|
-
return {
|
|
789
|
-
...product,
|
|
790
|
-
stripe_product_id: stripe_product.id,
|
|
791
|
-
plans: initialized_plans,
|
|
792
|
-
};
|
|
793
|
-
}
|
|
794
|
-
else if (product.type === "meter") {
|
|
795
|
-
assert(stripe_meter !== null, "api_error", "Stripe meter must be resolved for meter product initialization", {
|
|
796
|
-
product_id: product.id,
|
|
797
|
-
meter_event_name: product.meter_event_name,
|
|
798
|
-
});
|
|
799
|
-
const app_price_id = `${product.id}__meter`;
|
|
800
|
-
const unit_price_fields = resolve_unit_price_fields(product);
|
|
801
|
-
const signature = make_recurring_price_signature({
|
|
802
|
-
currency: product.currency,
|
|
803
|
-
...unit_price_fields,
|
|
804
|
-
tax_behavior: product.tax_behavior,
|
|
805
|
-
interval: product.interval,
|
|
806
|
-
interval_count: product.interval_count,
|
|
807
|
-
usage_type: "metered",
|
|
808
|
-
meter_id: stripe_meter.id,
|
|
809
|
-
});
|
|
810
|
-
let stripe_price = find_matching_active_price(active_prices, app_price_id, signature);
|
|
811
|
-
if (!stripe_price) {
|
|
812
|
-
const new_price = await create_recurring_price(client, server, {
|
|
813
|
-
product_id: product.id,
|
|
814
|
-
stripe_product_id: stripe_product.id,
|
|
815
|
-
app_price_id,
|
|
816
|
-
currency: product.currency,
|
|
817
|
-
...unit_price_fields,
|
|
818
|
-
tax_behavior: product.tax_behavior,
|
|
819
|
-
nickname: product.name,
|
|
820
|
-
interval: product.interval,
|
|
821
|
-
interval_count: product.interval_count,
|
|
822
|
-
recurring_usage: { usage_type: "metered", meter_id: stripe_meter.id },
|
|
823
|
-
});
|
|
824
|
-
stripe_price = new_price;
|
|
825
|
-
active_prices_by_stripe_product_id.set(stripe_product.id, [...active_prices, new_price]);
|
|
826
|
-
}
|
|
827
|
-
await update_stripe_product_default_price_if_needed(client, server, stripe_product, stripe_price);
|
|
828
|
-
return {
|
|
829
|
-
...product,
|
|
830
|
-
stripe_meter_id: stripe_meter.id,
|
|
831
|
-
stripe_product_id: stripe_product.id,
|
|
832
|
-
stripe_price_id: stripe_price.id,
|
|
833
|
-
};
|
|
834
|
-
}
|
|
835
|
-
else {
|
|
836
|
-
//@ts-expect-error product.type should be never here
|
|
837
|
-
product.type.toString();
|
|
838
|
-
throw new InternalStripeError("invalid_product", `Invalid product type: ${product.type}`, {
|
|
839
|
-
product_id: product.id, product_type: product.type
|
|
840
|
-
});
|
|
841
|
-
}
|
|
842
|
-
}
|
|
843
|
-
// ----------------------------------------------------------------------------
|
|
844
|
-
// Public API.
|
|
845
|
-
/**
|
|
846
|
-
* Resolve the subscription product (InitializedSubscriptionProduct) that owns a given plan.
|
|
847
|
-
*/
|
|
848
|
-
export function resolve_plan_to_parent_subscription(opts) {
|
|
849
|
-
for (const product of opts.all_products) {
|
|
850
|
-
if (product.type === "subscription" && product.id === opts.plan.subscription_id) {
|
|
851
|
-
return product;
|
|
852
|
-
}
|
|
853
|
-
}
|
|
854
|
-
// If we cannot find it, this indicates a corrupted initialization state.
|
|
855
|
-
throw new InternalStripeError("invalid_product", "Subscription plan refers to a missing parent subscription product.", { plan_id: opts.plan.id, subscription_id: opts.plan.subscription_id });
|
|
856
|
-
}
|
|
857
|
-
/**
|
|
858
|
-
* Initialize a list of products through the internal initializer, using a single paginated scan
|
|
859
|
-
* of Stripe products and prices which is then reused for all initializations.
|
|
860
|
-
*/
|
|
861
|
-
export async function initialize_products(client, server, products) {
|
|
862
|
-
assert(Array.isArray(products), "invalid_argument", "Products must be an array");
|
|
863
|
-
// Verify that all `id` attributes from Products and Plans are unique.
|
|
864
|
-
const seen_ids = new Set();
|
|
865
|
-
const seen_meter_event_names = new Set();
|
|
866
|
-
for (const product of products) {
|
|
867
|
-
assert(!seen_ids.has(product.id), "invalid_product", `Duplicate product id: ${product.id}`, { product_id: product.id });
|
|
868
|
-
seen_ids.add(product.id);
|
|
869
|
-
if (product.type === "subscription") {
|
|
870
|
-
for (const plan of product.plans) {
|
|
871
|
-
assert(!seen_ids.has(plan.id), "invalid_product", `Duplicate plan id: ${plan.id} in product ${product.id}`, { product_id: product.id, plan_id: plan.id });
|
|
872
|
-
seen_ids.add(plan.id);
|
|
873
|
-
}
|
|
874
|
-
}
|
|
875
|
-
if (product.type === "meter") {
|
|
876
|
-
assert(!seen_meter_event_names.has(product.meter_event_name), "invalid_product", `Duplicate meter_event_name: ${product.meter_event_name}`, { product_id: product.id, meter_event_name: product.meter_event_name });
|
|
877
|
-
seen_meter_event_names.add(product.meter_event_name);
|
|
878
|
-
}
|
|
879
|
-
}
|
|
880
|
-
// High-performance: list all products, prices, and meters once, then reuse indexes.
|
|
881
|
-
const [all_stripe_products, all_active_stripe_prices, all_stripe_meters] = await Promise.all([
|
|
882
|
-
list_all_stripe_products(client),
|
|
883
|
-
list_all_stripe_prices(client),
|
|
884
|
-
list_all_stripe_meters(client),
|
|
885
|
-
]);
|
|
886
|
-
const stripe_products_by_app_id = index_stripe_products_by_app_id(all_stripe_products);
|
|
887
|
-
const active_prices_by_stripe_product_id = index_active_prices_by_stripe_product_id(all_active_stripe_prices);
|
|
888
|
-
const stripe_meters_by_event_name = index_stripe_meters_by_event_name(all_stripe_meters);
|
|
889
|
-
// Initialize with limited concurrency to reduce latency while avoiding Stripe rate spikes.
|
|
890
|
-
const concurrency = 5;
|
|
891
|
-
const initialized_products = await map_with_concurrency(products, concurrency, async (product) => {
|
|
892
|
-
return await initialize_product(client, server, product, stripe_products_by_app_id, active_prices_by_stripe_product_id, stripe_meters_by_event_name);
|
|
893
|
-
});
|
|
894
|
-
// Response.
|
|
895
|
-
return initialized_products;
|
|
896
|
-
}
|