@vandenberghinc/volt 1.1.26 → 1.1.28
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/backend/dist/cjs/{blacklist.d.ts → backend/src/blacklist.d.ts} +5 -3
- package/backend/dist/cjs/{blacklist.js → backend/src/blacklist.js} +8 -5
- package/backend/dist/cjs/{cli.js → backend/src/cli.js} +29 -47
- package/backend/dist/cjs/backend/src/database/collection.d.ts +1543 -0
- package/backend/dist/cjs/backend/src/database/collection.js +3042 -0
- package/backend/dist/cjs/backend/src/database/database.d.ts +66 -0
- package/backend/dist/cjs/{database → backend/src/database}/database.js +48 -43
- package/backend/dist/cjs/backend/src/database/filters/filters.d.ts +6 -0
- package/backend/dist/cjs/backend/src/database/filters/filters.js +15 -0
- package/backend/dist/cjs/backend/src/database/filters/strict_filter.d.ts +223 -0
- package/backend/dist/cjs/backend/src/database/filters/strict_filter.js +15 -0
- package/backend/dist/cjs/backend/src/database/filters/strict_filter_test.js +443 -0
- package/backend/dist/cjs/backend/src/database/filters/strict_filter_test_v0.js +15 -0
- package/backend/dist/cjs/backend/src/database/filters/strict_filter_v0.d.ts +50 -0
- package/backend/dist/cjs/backend/src/database/filters/strict_filter_v0.js +15 -0
- package/backend/dist/cjs/backend/src/database/filters/strict_filter_v1.d.ts +76 -0
- package/backend/dist/cjs/backend/src/database/filters/strict_filter_v1.js +15 -0
- package/backend/dist/cjs/backend/src/database/filters/strict_filter_v2.d.ts +75 -0
- package/backend/dist/cjs/backend/src/database/filters/strict_filter_v2.js +15 -0
- package/backend/dist/cjs/backend/src/database/filters/strict_filter_v3.d.ts +219 -0
- package/backend/dist/cjs/backend/src/database/filters/strict_filter_v3.js +15 -0
- package/backend/dist/cjs/backend/src/database/filters/strict_update_filter.d.ts +165 -0
- package/backend/dist/cjs/backend/src/database/filters/strict_update_filter.js +15 -0
- package/backend/dist/cjs/backend/src/database/filters/strict_update_filter_test.d.ts +5 -0
- package/backend/dist/cjs/backend/src/database/filters/strict_update_filter_test.js +355 -0
- package/backend/dist/cjs/backend/src/database/flatten.d.ts +75 -0
- package/backend/dist/cjs/{logger.js → backend/src/database/flatten.js} +18 -7
- package/backend/dist/cjs/backend/src/database/flatten_test.js +175 -0
- package/backend/dist/cjs/backend/src/database/quota/quota.d.ts +461 -0
- package/backend/dist/cjs/backend/src/database/quota/quota.js +1014 -0
- package/backend/dist/cjs/backend/src/database/quota/quota_v1.d.ts +534 -0
- package/backend/dist/cjs/backend/src/database/quota/quota_v1.js +1087 -0
- package/backend/dist/cjs/backend/src/database/quota/safe_int.d.ts +293 -0
- package/backend/dist/cjs/backend/src/database/quota/safe_int.js +573 -0
- package/backend/dist/{esm → cjs/backend/src}/endpoint.d.ts +69 -46
- package/backend/dist/cjs/{endpoint.js → backend/src/endpoint.js} +87 -101
- package/backend/dist/cjs/backend/src/errors/index.d.ts +7 -0
- package/backend/dist/cjs/backend/src/errors/index.js +25 -0
- package/backend/dist/{esm/utils.d.ts → cjs/backend/src/errors/internal_external.d.ts} +14 -22
- package/backend/dist/cjs/backend/src/errors/internal_external.js +85 -0
- package/backend/dist/cjs/backend/src/errors/invalid_usage_error.d.ts +38 -0
- package/backend/dist/cjs/{mutex.js → backend/src/errors/invalid_usage_error.js} +20 -37
- package/backend/dist/cjs/backend/src/errors/system_error.d.ts +230 -0
- package/backend/dist/cjs/backend/src/errors/system_error.js +393 -0
- package/backend/dist/cjs/backend/src/events.d.ts +54 -0
- package/backend/dist/cjs/backend/src/events.js +15 -0
- package/backend/dist/cjs/{frontend.js → backend/src/frontend.js} +1 -1
- package/backend/dist/cjs/{image_endpoint.d.ts → backend/src/image_endpoint.d.ts} +16 -1
- package/backend/dist/cjs/{image_endpoint.js → backend/src/image_endpoint.js} +3 -5
- package/backend/dist/cjs/backend/src/logger.d.ts +5 -0
- package/backend/dist/cjs/backend/src/logger.js +15 -0
- package/backend/dist/cjs/backend/src/meta.d.ts +64 -0
- package/backend/dist/cjs/{meta.js → backend/src/meta.js} +9 -12
- package/backend/dist/cjs/backend/src/payments/paddle.d.ts +326 -0
- package/backend/dist/cjs/{payments → backend/src/payments}/paddle.js +377 -327
- package/backend/dist/cjs/backend/src/plugins/browser.d.ts +1 -0
- package/backend/dist/cjs/backend/src/plugins/browser.js +15 -0
- package/backend/dist/cjs/backend/src/plugins/mail/mail.d.ts +248 -0
- package/backend/dist/cjs/backend/src/plugins/mail/mail.js +379 -0
- package/backend/dist/{esm → cjs/backend/src}/plugins/mail/ui.d.ts +23 -0
- package/backend/dist/cjs/backend/src/plugins/pdf.d.ts +1 -0
- package/backend/dist/cjs/backend/src/rate_limit.d.ts +145 -0
- package/backend/dist/cjs/backend/src/rate_limit.js +549 -0
- package/backend/dist/cjs/{route.d.ts → backend/src/route.d.ts} +3 -10
- package/backend/dist/cjs/{route.js → backend/src/route.js} +23 -21
- package/backend/dist/cjs/backend/src/server.d.ts +485 -0
- package/backend/dist/cjs/{server.js → backend/src/server.js} +688 -873
- package/backend/dist/cjs/backend/src/splash_screen.d.ts +80 -0
- package/backend/dist/cjs/{splash_screen.js → backend/src/splash_screen.js} +24 -3
- package/backend/dist/cjs/backend/src/status.d.ts +74 -0
- package/backend/dist/cjs/{status.js → backend/src/status.js} +64 -64
- package/backend/dist/cjs/backend/src/stream.d.ts +376 -0
- package/backend/dist/cjs/{stream.js → backend/src/stream.js} +299 -276
- package/backend/dist/cjs/backend/src/users.d.ts +807 -0
- package/backend/dist/cjs/backend/src/users.js +1971 -0
- package/backend/dist/cjs/backend/src/utils.d.ts +16 -0
- package/backend/dist/cjs/{utils.js → backend/src/utils.js} +14 -77
- package/backend/dist/{esm → cjs/backend/src}/view.d.ts +33 -11
- package/backend/dist/cjs/backend/src/view.js +508 -0
- package/backend/dist/{esm → cjs/backend/src}/volt.d.ts +10 -1
- package/backend/dist/cjs/{volt.js → backend/src/volt.js} +8 -5
- package/backend/dist/cjs/frontend/src/modules/request.d.ts +70 -0
- package/backend/dist/cjs/frontend/src/modules/request.js +99 -0
- package/backend/dist/esm/{blacklist.d.ts → backend/src/blacklist.d.ts} +5 -3
- package/backend/dist/esm/{blacklist.js → backend/src/blacklist.js} +9 -6
- package/backend/dist/esm/{cli.js → backend/src/cli.js} +43 -60
- package/backend/dist/esm/backend/src/database/collection.d.ts +1543 -0
- package/backend/dist/esm/backend/src/database/collection.js +3510 -0
- package/backend/dist/esm/backend/src/database/database.d.ts +66 -0
- package/backend/dist/esm/{database → backend/src/database}/database.js +62 -103
- package/backend/dist/esm/backend/src/database/document.d.ts +1 -0
- package/backend/dist/esm/backend/src/database/document.js +558 -0
- package/backend/dist/esm/backend/src/database/filters/filters.d.ts +6 -0
- package/backend/dist/esm/backend/src/database/filters/filters.js +1 -0
- package/backend/dist/esm/backend/src/database/filters/strict_filter.d.ts +223 -0
- package/backend/dist/esm/backend/src/database/filters/strict_filter.js +3 -0
- package/backend/dist/esm/backend/src/database/filters/strict_filter_test.d.ts +1 -0
- package/backend/dist/esm/backend/src/database/filters/strict_filter_test.js +505 -0
- package/backend/dist/esm/backend/src/database/filters/strict_filter_test_v0.d.ts +1 -0
- package/backend/dist/esm/backend/src/database/filters/strict_filter_test_v0.js +712 -0
- package/backend/dist/esm/backend/src/database/filters/strict_filter_v0.d.ts +50 -0
- package/backend/dist/esm/backend/src/database/filters/strict_filter_v0.js +5 -0
- package/backend/dist/esm/backend/src/database/filters/strict_filter_v1.d.ts +76 -0
- package/backend/dist/esm/backend/src/database/filters/strict_filter_v1.js +44 -0
- package/backend/dist/esm/backend/src/database/filters/strict_filter_v2.d.ts +75 -0
- package/backend/dist/esm/backend/src/database/filters/strict_filter_v2.js +5 -0
- package/backend/dist/esm/backend/src/database/filters/strict_filter_v3.d.ts +219 -0
- package/backend/dist/esm/backend/src/database/filters/strict_filter_v3.js +1 -0
- package/backend/dist/esm/backend/src/database/filters/strict_update_filter.d.ts +165 -0
- package/backend/dist/esm/backend/src/database/filters/strict_update_filter.js +5 -0
- package/backend/dist/esm/backend/src/database/filters/strict_update_filter_test.d.ts +5 -0
- package/backend/dist/esm/backend/src/database/filters/strict_update_filter_test.js +405 -0
- package/backend/dist/esm/backend/src/database/flatten.d.ts +75 -0
- package/backend/dist/esm/backend/src/database/flatten.js +22 -0
- package/backend/dist/esm/backend/src/database/flatten_test.d.ts +1 -0
- package/backend/dist/esm/backend/src/database/flatten_test.js +174 -0
- package/backend/dist/esm/backend/src/database/quota/quota.d.ts +461 -0
- package/backend/dist/esm/backend/src/database/quota/quota.js +1118 -0
- package/backend/dist/esm/backend/src/database/quota/quota_v1.d.ts +534 -0
- package/backend/dist/esm/backend/src/database/quota/quota_v1.js +1242 -0
- package/backend/dist/esm/backend/src/database/quota/safe_int.d.ts +293 -0
- package/backend/dist/esm/backend/src/database/quota/safe_int.js +602 -0
- package/backend/dist/{cjs → esm/backend/src}/endpoint.d.ts +69 -46
- package/backend/dist/esm/{endpoint.js → backend/src/endpoint.js} +136 -127
- package/backend/dist/esm/backend/src/errors/index.d.ts +7 -0
- package/backend/dist/esm/backend/src/errors/index.js +7 -0
- package/backend/dist/{cjs/utils.d.ts → esm/backend/src/errors/internal_external.d.ts} +14 -22
- package/backend/dist/esm/backend/src/errors/internal_external.js +70 -0
- package/backend/dist/esm/backend/src/errors/invalid_usage_error.d.ts +38 -0
- package/backend/dist/esm/backend/src/errors/invalid_usage_error.js +30 -0
- package/backend/dist/esm/backend/src/errors/system_error.d.ts +230 -0
- package/backend/dist/esm/backend/src/errors/system_error.js +402 -0
- package/backend/dist/esm/backend/src/events.d.ts +54 -0
- package/backend/dist/esm/backend/src/events.js +5 -0
- package/backend/dist/esm/{frontend.js → backend/src/frontend.js} +1 -1
- package/backend/dist/esm/{image_endpoint.d.ts → backend/src/image_endpoint.d.ts} +16 -1
- package/backend/dist/esm/{image_endpoint.js → backend/src/image_endpoint.js} +16 -20
- package/backend/dist/esm/backend/src/logger.d.ts +5 -0
- package/backend/dist/esm/backend/src/logger.js +8 -0
- package/backend/dist/esm/backend/src/meta.d.ts +64 -0
- package/backend/dist/esm/{meta.js → backend/src/meta.js} +15 -54
- package/backend/dist/esm/backend/src/payments/paddle.d.ts +326 -0
- package/backend/dist/esm/{payments → backend/src/payments}/paddle.js +417 -452
- package/backend/dist/esm/backend/src/plugins/browser.d.ts +1 -0
- package/backend/dist/esm/backend/src/plugins/browser.js +170 -0
- package/backend/dist/esm/backend/src/plugins/mail/mail.d.ts +248 -0
- package/backend/dist/esm/backend/src/plugins/mail/mail.js +389 -0
- package/backend/dist/{cjs → esm/backend/src}/plugins/mail/ui.d.ts +23 -0
- package/backend/dist/esm/{plugins → backend/src/plugins}/mail/ui.js +3 -6
- package/backend/dist/esm/backend/src/plugins/pdf.d.ts +1 -0
- package/backend/dist/esm/{plugins → backend/src/plugins}/pdf.js +3 -3
- package/backend/dist/esm/backend/src/rate_limit.d.ts +145 -0
- package/backend/dist/esm/backend/src/rate_limit.js +667 -0
- package/backend/dist/esm/{route.d.ts → backend/src/route.d.ts} +3 -10
- package/backend/dist/esm/{route.js → backend/src/route.js} +26 -21
- package/backend/dist/esm/backend/src/server.d.ts +485 -0
- package/backend/dist/esm/{server.js → backend/src/server.js} +891 -1441
- package/backend/dist/esm/backend/src/splash_screen.d.ts +80 -0
- package/backend/dist/esm/{splash_screen.js → backend/src/splash_screen.js} +42 -55
- package/backend/dist/esm/backend/src/status.d.ts +74 -0
- package/backend/dist/esm/backend/src/status.js +199 -0
- package/backend/dist/esm/backend/src/stream.d.ts +376 -0
- package/backend/dist/esm/{stream.js → backend/src/stream.js} +327 -292
- package/backend/dist/esm/backend/src/users.d.ts +809 -0
- package/backend/dist/esm/backend/src/users.js +2140 -0
- package/backend/dist/esm/backend/src/utils.d.ts +16 -0
- package/backend/dist/esm/{utils.js → backend/src/utils.js} +20 -81
- package/backend/dist/{cjs → esm/backend/src}/view.d.ts +33 -11
- package/backend/dist/esm/{view.js → backend/src/view.js} +266 -86
- package/backend/dist/{cjs → esm/backend/src}/volt.d.ts +10 -1
- package/backend/dist/esm/{volt.js → backend/src/volt.js} +7 -4
- package/backend/dist/esm/frontend/src/modules/request.d.ts +70 -0
- package/backend/dist/esm/frontend/src/modules/request.js +117 -0
- package/frontend/dist/backend/src/database/collection.d.ts +1543 -0
- package/frontend/dist/backend/src/database/collection.js +3510 -0
- package/frontend/dist/backend/src/database/database.d.ts +66 -0
- package/frontend/dist/backend/src/database/database.js +196 -0
- package/frontend/dist/backend/src/database/filters/filters.d.ts +6 -0
- package/frontend/dist/backend/src/database/filters/filters.js +1 -0
- package/frontend/dist/backend/src/database/filters/strict_filter.d.ts +223 -0
- package/frontend/dist/backend/src/database/filters/strict_filter.js +3 -0
- package/frontend/dist/backend/src/database/filters/strict_update_filter.d.ts +165 -0
- package/frontend/dist/backend/src/database/filters/strict_update_filter.js +5 -0
- package/frontend/dist/backend/src/database/flatten.d.ts +75 -0
- package/frontend/dist/backend/src/database/flatten.js +22 -0
- package/frontend/dist/backend/src/endpoint.d.ts +204 -0
- package/frontend/dist/backend/src/endpoint.js +570 -0
- package/frontend/dist/backend/src/errors/index.d.ts +7 -0
- package/frontend/dist/backend/src/errors/index.js +7 -0
- package/frontend/dist/backend/src/errors/internal_external.d.ts +38 -0
- package/frontend/dist/backend/src/errors/internal_external.js +70 -0
- package/frontend/dist/backend/src/errors/invalid_usage_error.d.ts +38 -0
- package/frontend/dist/backend/src/errors/invalid_usage_error.js +30 -0
- package/frontend/dist/backend/src/errors/system_error.d.ts +230 -0
- package/frontend/dist/backend/src/errors/system_error.js +402 -0
- package/frontend/dist/backend/src/events.d.ts +54 -0
- package/frontend/dist/backend/src/events.js +5 -0
- package/frontend/dist/backend/src/frontend.d.ts +11 -0
- package/frontend/dist/backend/src/frontend.js +12 -0
- package/frontend/dist/backend/src/image_endpoint.d.ts +39 -0
- package/frontend/dist/backend/src/image_endpoint.js +202 -0
- package/frontend/dist/backend/src/meta.d.ts +64 -0
- package/frontend/dist/backend/src/meta.js +110 -0
- package/frontend/dist/backend/src/payments/paddle.d.ts +326 -0
- package/frontend/dist/backend/src/payments/paddle.js +2256 -0
- package/frontend/dist/backend/src/plugins/mail/mail.d.ts +248 -0
- package/frontend/dist/backend/src/plugins/mail/mail.js +389 -0
- package/{backend/dist/esm/plugins/mail.d.ts → frontend/dist/backend/src/plugins/mail/ui.d.ts} +23 -0
- package/{backend/dist/esm/plugins/mail.js → frontend/dist/backend/src/plugins/mail/ui.js} +3 -6
- package/frontend/dist/backend/src/rate_limit.d.ts +145 -0
- package/frontend/dist/backend/src/rate_limit.js +673 -0
- package/frontend/dist/backend/src/route.d.ts +35 -0
- package/frontend/dist/backend/src/route.js +212 -0
- package/frontend/dist/backend/src/server.d.ts +485 -0
- package/frontend/dist/backend/src/server.js +2670 -0
- package/frontend/dist/backend/src/splash_screen.d.ts +80 -0
- package/frontend/dist/backend/src/splash_screen.js +135 -0
- package/frontend/dist/backend/src/status.d.ts +74 -0
- package/frontend/dist/backend/src/status.js +199 -0
- package/frontend/dist/backend/src/stream.d.ts +376 -0
- package/frontend/dist/backend/src/stream.js +1007 -0
- package/frontend/dist/backend/src/users.d.ts +807 -0
- package/frontend/dist/backend/src/users.js +2118 -0
- package/frontend/dist/backend/src/utils.d.ts +16 -0
- package/frontend/dist/backend/src/utils.js +241 -0
- package/frontend/dist/backend/src/view.d.ts +162 -0
- package/frontend/dist/backend/src/view.js +720 -0
- package/frontend/dist/frontend/src/elements/base.d.ts +4414 -0
- package/frontend/dist/{elements → frontend/src/elements}/base.js +3624 -260
- package/frontend/dist/frontend/src/elements/module.d.ts +95 -0
- package/frontend/dist/{elements → frontend/src/elements}/module.js +53 -52
- package/frontend/dist/frontend/src/elements/types.d.ts +52 -0
- package/frontend/dist/frontend/src/elements/types.js +5 -0
- package/frontend/dist/frontend/src/modules/attachment.d.ts +126 -0
- package/frontend/dist/frontend/src/modules/attachment.js +306 -0
- package/frontend/dist/frontend/src/modules/auth.d.ts +44 -0
- package/frontend/dist/frontend/src/modules/auth.js +80 -0
- package/frontend/dist/{modules → frontend/src/modules}/color.js +2 -2
- package/frontend/dist/frontend/src/modules/compression.d.ts +39 -0
- package/frontend/dist/frontend/src/modules/compression.js +102 -0
- package/frontend/dist/frontend/src/modules/cookies.d.ts +44 -0
- package/frontend/dist/frontend/src/modules/cookies.js +143 -0
- package/frontend/dist/frontend/src/modules/events.d.ts +31 -0
- package/frontend/dist/frontend/src/modules/events.js +74 -0
- package/frontend/dist/frontend/src/modules/google.d.ts +23 -0
- package/frontend/dist/frontend/src/modules/google.js +52 -0
- package/frontend/dist/frontend/src/modules/meta.d.ts +14 -0
- package/frontend/dist/{modules → frontend/src/modules}/meta.js +9 -7
- package/frontend/dist/{modules → frontend/src/modules}/paddle.d.ts +37 -134
- package/frontend/dist/{modules → frontend/src/modules}/paddle.js +620 -568
- package/frontend/dist/frontend/src/modules/request.d.ts +70 -0
- package/frontend/dist/frontend/src/modules/request.js +117 -0
- package/frontend/dist/frontend/src/modules/settings.d.ts +3 -0
- package/frontend/dist/frontend/src/modules/settings.js +5 -0
- package/frontend/dist/frontend/src/modules/statics.d.ts +21 -0
- package/frontend/dist/{modules → frontend/src/modules}/statics.js +15 -18
- package/frontend/dist/frontend/src/modules/support.d.ts +30 -0
- package/frontend/dist/frontend/src/modules/support.js +53 -0
- package/frontend/dist/{modules → frontend/src/modules}/theme.d.ts +67 -0
- package/frontend/dist/{modules → frontend/src/modules}/theme.js +68 -38
- package/frontend/dist/frontend/src/modules/themes.d.ts +12 -0
- package/frontend/dist/frontend/src/modules/themes.js +22 -0
- package/frontend/dist/frontend/src/modules/user.d.ts +164 -0
- package/frontend/dist/frontend/src/modules/user.js +268 -0
- package/frontend/dist/frontend/src/modules/utils.d.ts +176 -0
- package/frontend/dist/frontend/src/modules/utils.js +569 -0
- package/frontend/dist/frontend/src/types/gradient.d.ts +29 -0
- package/frontend/dist/{types → frontend/src/types}/gradient.js +14 -18
- package/frontend/dist/frontend/src/ui/border_button.d.ts +94 -0
- package/frontend/dist/{ui → frontend/src/ui}/border_button.js +7 -13
- package/frontend/dist/frontend/src/ui/button.d.ts +28 -0
- package/frontend/dist/{ui → frontend/src/ui}/button.js +21 -12
- package/frontend/dist/frontend/src/ui/canvas.d.ts +138 -0
- package/frontend/dist/{ui → frontend/src/ui}/canvas.js +88 -55
- package/frontend/dist/frontend/src/ui/checkbox.d.ts +74 -0
- package/frontend/dist/{ui → frontend/src/ui}/checkbox.js +80 -41
- package/frontend/dist/{ui → frontend/src/ui}/code.d.ts +73 -6
- package/frontend/dist/{ui → frontend/src/ui}/code.js +55 -52
- package/frontend/dist/{ui → frontend/src/ui}/context_menu.d.ts +4 -0
- package/frontend/dist/{ui → frontend/src/ui}/context_menu.js +12 -17
- package/frontend/dist/{ui → frontend/src/ui}/css.d.ts +4 -0
- package/frontend/dist/{ui → frontend/src/ui}/css.js +3 -3
- package/frontend/dist/{ui → frontend/src/ui}/divider.d.ts +4 -0
- package/frontend/dist/{ui → frontend/src/ui}/divider.js +3 -3
- package/frontend/dist/{ui → frontend/src/ui}/dropdown.d.ts +57 -2
- package/frontend/dist/{ui → frontend/src/ui}/dropdown.js +87 -94
- package/frontend/dist/{ui → frontend/src/ui}/for_each.d.ts +4 -0
- package/frontend/dist/{ui → frontend/src/ui}/for_each.js +3 -3
- package/frontend/dist/{ui → frontend/src/ui}/form.d.ts +6 -2
- package/frontend/dist/{ui → frontend/src/ui}/form.js +10 -7
- package/frontend/dist/frontend/src/ui/frame_modes.d.ts +37 -0
- package/frontend/dist/{ui → frontend/src/ui}/frame_modes.js +16 -22
- package/frontend/dist/{ui → frontend/src/ui}/google_map.d.ts +4 -0
- package/frontend/dist/{ui → frontend/src/ui}/google_map.js +4 -4
- package/frontend/dist/{ui → frontend/src/ui}/gradient.d.ts +4 -0
- package/frontend/dist/{ui → frontend/src/ui}/gradient.js +3 -3
- package/frontend/dist/{ui → frontend/src/ui}/image.d.ts +4 -0
- package/frontend/dist/{ui → frontend/src/ui}/image.js +5 -5
- package/frontend/dist/frontend/src/ui/input.d.ts +392 -0
- package/frontend/dist/{ui → frontend/src/ui}/input.js +346 -360
- package/frontend/dist/{ui → frontend/src/ui}/link.d.ts +4 -0
- package/frontend/dist/{ui → frontend/src/ui}/link.js +3 -3
- package/frontend/dist/{ui → frontend/src/ui}/list.d.ts +4 -0
- package/frontend/dist/{ui → frontend/src/ui}/list.js +12 -6
- package/frontend/dist/frontend/src/ui/loader_button.d.ts +80 -0
- package/frontend/dist/{ui → frontend/src/ui}/loader_button.js +35 -47
- package/frontend/dist/frontend/src/ui/loaders.d.ts +57 -0
- package/frontend/dist/{ui → frontend/src/ui}/loaders.js +11 -11
- package/frontend/dist/{ui → frontend/src/ui}/popup.d.ts +11 -6
- package/frontend/dist/{ui → frontend/src/ui}/popup.js +32 -18
- package/frontend/dist/frontend/src/ui/pseudo.d.ts +44 -0
- package/frontend/dist/{ui → frontend/src/ui}/pseudo.js +84 -8
- package/frontend/dist/{ui → frontend/src/ui}/scroller.d.ts +14 -2
- package/frontend/dist/{ui → frontend/src/ui}/scroller.js +37 -43
- package/frontend/dist/{ui → frontend/src/ui}/slider.d.ts +5 -1
- package/frontend/dist/{ui → frontend/src/ui}/slider.js +4 -4
- package/frontend/dist/{ui → frontend/src/ui}/spacer.d.ts +4 -0
- package/frontend/dist/{ui → frontend/src/ui}/spacer.js +3 -3
- package/frontend/dist/{ui → frontend/src/ui}/span.d.ts +4 -0
- package/frontend/dist/{ui → frontend/src/ui}/span.js +3 -3
- package/frontend/dist/{ui → frontend/src/ui}/stack.d.ts +4 -0
- package/frontend/dist/{ui → frontend/src/ui}/stack.js +3 -9
- package/frontend/dist/frontend/src/ui/steps.d.ts +131 -0
- package/frontend/dist/{ui → frontend/src/ui}/steps.js +30 -45
- package/frontend/dist/{ui → frontend/src/ui}/style.d.ts +4 -0
- package/frontend/dist/{ui → frontend/src/ui}/style.js +3 -3
- package/frontend/dist/{ui → frontend/src/ui}/switch.d.ts +5 -1
- package/frontend/dist/{ui → frontend/src/ui}/switch.js +4 -4
- package/frontend/dist/{ui → frontend/src/ui}/table.d.ts +4 -0
- package/frontend/dist/{ui → frontend/src/ui}/table.js +6 -6
- package/frontend/dist/{ui → frontend/src/ui}/tabs.d.ts +45 -3
- package/frontend/dist/{ui → frontend/src/ui}/tabs.js +65 -40
- package/frontend/dist/{ui → frontend/src/ui}/text.d.ts +4 -0
- package/frontend/dist/{ui → frontend/src/ui}/text.js +3 -3
- package/frontend/dist/frontend/src/ui/title.d.ts +91 -0
- package/frontend/dist/frontend/src/ui/title.js +272 -0
- package/frontend/dist/{ui → frontend/src/ui}/view.d.ts +4 -0
- package/frontend/dist/{ui → frontend/src/ui}/view.js +3 -3
- package/frontend/dist/{volt.d.ts → frontend/src/volt.d.ts} +3 -0
- package/frontend/dist/{volt.js → frontend/src/volt.js} +4 -0
- package/frontend/tools/bundle_d_ts.js +71 -0
- package/frontend/tools/convert_to_jsdoc_input.txt +9452 -0
- package/frontend/tools/convert_to_jsdoc_output.txt +7626 -0
- package/frontend/tools/convert_to_jsdoc_tmp.js +345 -0
- package/package.json +11 -12
- package/backend/dist/cjs/database/collection.d.ts +0 -160
- package/backend/dist/cjs/database/collection.js +0 -842
- package/backend/dist/cjs/database/database.d.ts +0 -121
- package/backend/dist/cjs/database/document.d.ts +0 -131
- package/backend/dist/cjs/database/document.js +0 -224
- package/backend/dist/cjs/database.d.ts +0 -502
- package/backend/dist/cjs/database.js +0 -2248
- package/backend/dist/cjs/logger.d.ts +0 -3
- package/backend/dist/cjs/meta.d.ts +0 -50
- package/backend/dist/cjs/mutex.d.ts +0 -24
- package/backend/dist/cjs/payments/paddle.d.ts +0 -160
- package/backend/dist/cjs/plugins/browser.d.ts +0 -36
- package/backend/dist/cjs/plugins/browser.js +0 -198
- package/backend/dist/cjs/plugins/css.d.ts +0 -11
- package/backend/dist/cjs/plugins/css.js +0 -80
- package/backend/dist/cjs/plugins/mail.d.ts +0 -277
- package/backend/dist/cjs/plugins/mail.js +0 -1370
- package/backend/dist/cjs/plugins/ts/compiler.d.ts +0 -139
- package/backend/dist/cjs/plugins/ts/compiler.js +0 -750
- package/backend/dist/cjs/plugins/ts/preprocessing.d.ts +0 -14
- package/backend/dist/cjs/plugins/ts/preprocessing.js +0 -440
- package/backend/dist/cjs/rate_limit.d.ts +0 -63
- package/backend/dist/cjs/rate_limit.js +0 -348
- package/backend/dist/cjs/request.deprc.d.ts +0 -48
- package/backend/dist/cjs/request.deprc.js +0 -572
- package/backend/dist/cjs/response.deprc.d.ts +0 -55
- package/backend/dist/cjs/response.deprc.js +0 -275
- package/backend/dist/cjs/server.d.ts +0 -342
- package/backend/dist/cjs/splash_screen.d.ts +0 -35
- package/backend/dist/cjs/status.d.ts +0 -61
- package/backend/dist/cjs/stream.d.ts +0 -79
- package/backend/dist/cjs/users.d.ts +0 -111
- package/backend/dist/cjs/users.js +0 -1817
- package/backend/dist/cjs/view.js +0 -352
- package/backend/dist/cjs/vinc.dev.d.ts +0 -3
- package/backend/dist/cjs/vinc.dev.js +0 -7
- package/backend/dist/css/adyen.css +0 -92
- package/backend/dist/css/volt.css +0 -70
- package/backend/dist/esm/database/collection.d.ts +0 -160
- package/backend/dist/esm/database/collection.js +0 -1328
- package/backend/dist/esm/database/database.d.ts +0 -121
- package/backend/dist/esm/database/document.d.ts +0 -131
- package/backend/dist/esm/database/document.js +0 -247
- package/backend/dist/esm/database.d.ts +0 -502
- package/backend/dist/esm/database.js +0 -2423
- package/backend/dist/esm/file_watcher.js +0 -329
- package/backend/dist/esm/logger.d.ts +0 -3
- package/backend/dist/esm/logger.js +0 -11
- package/backend/dist/esm/meta.d.ts +0 -50
- package/backend/dist/esm/mutex.d.ts +0 -24
- package/backend/dist/esm/mutex.js +0 -48
- package/backend/dist/esm/payments/paddle.d.ts +0 -160
- package/backend/dist/esm/plugins/browser.d.ts +0 -36
- package/backend/dist/esm/plugins/browser.js +0 -176
- package/backend/dist/esm/plugins/css.d.ts +0 -11
- package/backend/dist/esm/plugins/css.js +0 -90
- package/backend/dist/esm/plugins/ts/compiler.d.ts +0 -139
- package/backend/dist/esm/plugins/ts/compiler.js +0 -1194
- package/backend/dist/esm/plugins/ts/preprocessing.d.ts +0 -14
- package/backend/dist/esm/plugins/ts/preprocessing.js +0 -726
- package/backend/dist/esm/rate_limit.d.ts +0 -63
- package/backend/dist/esm/rate_limit.js +0 -417
- package/backend/dist/esm/request.deprc.d.ts +0 -48
- package/backend/dist/esm/request.deprc.js +0 -572
- package/backend/dist/esm/response.deprc.d.ts +0 -55
- package/backend/dist/esm/response.deprc.js +0 -275
- package/backend/dist/esm/server.d.ts +0 -342
- package/backend/dist/esm/splash_screen.d.ts +0 -35
- package/backend/dist/esm/status.d.ts +0 -61
- package/backend/dist/esm/status.js +0 -197
- package/backend/dist/esm/stream.d.ts +0 -79
- package/backend/dist/esm/users.d.ts +0 -111
- package/backend/dist/esm/users.js +0 -1935
- package/backend/dist/esm/vinc.dev.d.ts +0 -3
- package/backend/dist/esm/vinc.dev.js +0 -7
- package/frontend/dist/elements/base.d.ts +0 -9889
- package/frontend/dist/elements/module.d.ts +0 -30
- package/frontend/dist/modules/array.d.ts +0 -94
- package/frontend/dist/modules/array.js +0 -634
- package/frontend/dist/modules/auth.d.ts +0 -46
- package/frontend/dist/modules/auth.js +0 -139
- package/frontend/dist/modules/colors.d.ts +0 -1
- package/frontend/dist/modules/colors.js +0 -417
- package/frontend/dist/modules/compression.d.ts +0 -6
- package/frontend/dist/modules/compression.js +0 -999
- package/frontend/dist/modules/cookies.d.ts +0 -18
- package/frontend/dist/modules/cookies.js +0 -167
- package/frontend/dist/modules/date.d.ts +0 -142
- package/frontend/dist/modules/date.js +0 -493
- package/frontend/dist/modules/events.d.ts +0 -8
- package/frontend/dist/modules/events.js +0 -91
- package/frontend/dist/modules/google.d.ts +0 -11
- package/frontend/dist/modules/google.js +0 -54
- package/frontend/dist/modules/meta.d.ts +0 -10
- package/frontend/dist/modules/mutex.d.ts +0 -7
- package/frontend/dist/modules/mutex.js +0 -51
- package/frontend/dist/modules/number.d.ts +0 -16
- package/frontend/dist/modules/number.js +0 -23
- package/frontend/dist/modules/object.d.ts +0 -52
- package/frontend/dist/modules/object.js +0 -383
- package/frontend/dist/modules/scheme.d.ts +0 -227
- package/frontend/dist/modules/scheme.js +0 -531
- package/frontend/dist/modules/settings.d.ts +0 -3
- package/frontend/dist/modules/settings.js +0 -4
- package/frontend/dist/modules/statics.d.ts +0 -5
- package/frontend/dist/modules/string.d.ts +0 -124
- package/frontend/dist/modules/string.js +0 -745
- package/frontend/dist/modules/support.d.ts +0 -19
- package/frontend/dist/modules/support.js +0 -103
- package/frontend/dist/modules/themes.d.ts +0 -8
- package/frontend/dist/modules/themes.js +0 -18
- package/frontend/dist/modules/user.d.ts +0 -59
- package/frontend/dist/modules/user.js +0 -280
- package/frontend/dist/modules/utils.d.ts +0 -87
- package/frontend/dist/modules/utils.js +0 -923
- package/frontend/dist/types/gradient.d.ts +0 -12
- package/frontend/dist/ui/border_button.d.ts +0 -152
- package/frontend/dist/ui/button.d.ts +0 -21
- package/frontend/dist/ui/canvas.d.ts +0 -56
- package/frontend/dist/ui/checkbox.d.ts +0 -52
- package/frontend/dist/ui/frame_modes.d.ts +0 -25
- package/frontend/dist/ui/input.d.ts +0 -241
- package/frontend/dist/ui/loader_button.d.ts +0 -93
- package/frontend/dist/ui/loaders.d.ts +0 -57
- package/frontend/dist/ui/pseudo.d.ts +0 -16
- package/frontend/dist/ui/steps.d.ts +0 -59
- package/frontend/dist/ui/title.d.ts +0 -21
- package/frontend/dist/ui/title.js +0 -121
- package/frontend/examples/dashboard/dashboard.ts +0 -776
- /package/backend/dist/cjs/{cli.d.ts → backend/src/cli.d.ts} +0 -0
- /package/backend/dist/cjs/{file_watcher.d.ts → backend/src/database/document.d.ts} +0 -0
- /package/backend/dist/cjs/{file_watcher.js → backend/src/database/document.js} +0 -0
- /package/backend/dist/cjs/{plugins/pdf.d.ts → backend/src/database/filters/strict_filter_test.d.ts} +0 -0
- /package/backend/dist/{esm/file_watcher.d.ts → cjs/backend/src/database/filters/strict_filter_test_v0.d.ts} +0 -0
- /package/backend/dist/{esm/plugins/pdf.d.ts → cjs/backend/src/database/flatten_test.d.ts} +0 -0
- /package/backend/dist/cjs/{frontend.d.ts → backend/src/frontend.d.ts} +0 -0
- /package/backend/dist/cjs/{plugins → backend/src/plugins}/communication.d.ts +0 -0
- /package/backend/dist/cjs/{plugins → backend/src/plugins}/communication.js +0 -0
- /package/backend/dist/cjs/{plugins → backend/src/plugins}/mail/ui.js +0 -0
- /package/backend/dist/cjs/{plugins → backend/src/plugins}/pdf.js +0 -0
- /package/backend/dist/cjs/{plugins → backend/src/plugins}/thread_monitor.d.ts +0 -0
- /package/backend/dist/cjs/{plugins → backend/src/plugins}/thread_monitor.js +0 -0
- /package/backend/dist/cjs/{vinc.d.ts → backend/src/vinc.d.ts} +0 -0
- /package/backend/dist/cjs/{vinc.js → backend/src/vinc.js} +0 -0
- /package/backend/dist/esm/{cli.d.ts → backend/src/cli.d.ts} +0 -0
- /package/backend/dist/esm/{frontend.d.ts → backend/src/frontend.d.ts} +0 -0
- /package/backend/dist/esm/{plugins → backend/src/plugins}/communication.d.ts +0 -0
- /package/backend/dist/esm/{plugins → backend/src/plugins}/communication.js +0 -0
- /package/backend/dist/esm/{plugins → backend/src/plugins}/thread_monitor.d.ts +0 -0
- /package/backend/dist/esm/{plugins → backend/src/plugins}/thread_monitor.js +0 -0
- /package/backend/dist/esm/{vinc.d.ts → backend/src/vinc.d.ts} +0 -0
- /package/backend/dist/esm/{vinc.js → backend/src/vinc.js} +0 -0
- /package/frontend/dist/{elements → frontend/src/elements}/register_element.d.ts +0 -0
- /package/frontend/dist/{elements → frontend/src/elements}/register_element.js +0 -0
- /package/frontend/dist/{modules → frontend/src/modules}/color.d.ts +0 -0
- /package/frontend/dist/{ui → frontend/src/ui}/ui.d.ts +0 -0
- /package/frontend/dist/{ui → frontend/src/ui}/ui.js +0 -0
|
@@ -27,26 +27,50 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
27
27
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
28
|
var stdin_exports = {};
|
|
29
29
|
__export(stdin_exports, {
|
|
30
|
+
LineItem: () => LineItem,
|
|
30
31
|
Paddle: () => Paddle,
|
|
31
|
-
|
|
32
|
+
Payment: () => Payment,
|
|
33
|
+
PaymentStatusValues: () => PaymentStatusValues
|
|
32
34
|
});
|
|
33
35
|
module.exports = __toCommonJS(stdin_exports);
|
|
34
36
|
var https = __toESM(require("https"));
|
|
35
37
|
var PDFDocument = __toESM(require("pdfkit"));
|
|
36
38
|
var libcrypto = __toESM(require("crypto"));
|
|
37
|
-
var import_blob_stream = __toESM(require("blob-stream"));
|
|
38
39
|
var vlib = __toESM(require("@vandenberghinc/vlib"));
|
|
39
|
-
var
|
|
40
|
-
var import_logger = require("../logger.js");
|
|
40
|
+
var import_errors = require("../errors/index.js");
|
|
41
41
|
var import_status = require("../status.js");
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
42
|
+
var import_collection = require("../database/collection.js");
|
|
43
|
+
var import_utils = require("../utils.js");
|
|
44
|
+
var LineItem;
|
|
45
|
+
(function(LineItem2) {
|
|
46
|
+
LineItem2.Schema = {
|
|
47
|
+
product: "string",
|
|
48
|
+
item_id: "string",
|
|
49
|
+
paddle_prod_id: "string",
|
|
50
|
+
quantity: "number",
|
|
51
|
+
tax_rate: "number",
|
|
52
|
+
tax: "number",
|
|
53
|
+
discount: "number",
|
|
54
|
+
subtotal: "number",
|
|
55
|
+
total: "number",
|
|
56
|
+
status: { type: "string", enum: ["paid", "refunded", "refunding"] }
|
|
57
|
+
};
|
|
58
|
+
})(LineItem || (LineItem = {}));
|
|
59
|
+
const PaymentStatusValues = ["open", "paid", "past_due", "unknown"];
|
|
60
|
+
var Payment;
|
|
61
|
+
(function(Payment2) {
|
|
62
|
+
function anonymize(payment) {
|
|
63
|
+
if (!payment.uid || payment.uid === "unauth") {
|
|
64
|
+
const { billing_details, ...rest } = payment;
|
|
65
|
+
return {
|
|
66
|
+
...rest,
|
|
67
|
+
billing_details: void 0
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
return payment;
|
|
48
71
|
}
|
|
49
|
-
|
|
72
|
+
Payment2.anonymize = anonymize;
|
|
73
|
+
})(Payment || (Payment = {}));
|
|
50
74
|
class Paddle {
|
|
51
75
|
type;
|
|
52
76
|
client_key;
|
|
@@ -58,22 +82,28 @@ class Paddle {
|
|
|
58
82
|
_headers;
|
|
59
83
|
webhook_key;
|
|
60
84
|
_has_create_products_permission;
|
|
61
|
-
|
|
85
|
+
_last_products_db;
|
|
86
|
+
_webhook_conf_db;
|
|
62
87
|
_sub_db;
|
|
63
88
|
_active_sub_db;
|
|
64
89
|
_pay_db;
|
|
65
|
-
// private _inv_db
|
|
90
|
+
// private _inv_db: Collection;
|
|
66
91
|
performance;
|
|
67
|
-
constructor({ api_key, client_key, sandbox = false, products = [], inclusive_tax = false, _server
|
|
68
|
-
vlib.
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
92
|
+
constructor({ api_key, client_key, sandbox = false, products = [], inclusive_tax = false, _server }) {
|
|
93
|
+
vlib.schema.validate(arguments[0], {
|
|
94
|
+
unknown: false,
|
|
95
|
+
throw: true,
|
|
96
|
+
parent: "payments",
|
|
97
|
+
schema: {
|
|
98
|
+
type: { type: "string", default: "paddle" },
|
|
99
|
+
api_key: "string",
|
|
100
|
+
client_key: "string",
|
|
101
|
+
sandbox: { type: "boolean", default: false },
|
|
102
|
+
inclusive_tax: { type: "boolean", default: false },
|
|
103
|
+
products: "array",
|
|
104
|
+
_server: "object"
|
|
105
|
+
}
|
|
106
|
+
});
|
|
77
107
|
this.type = "paddle";
|
|
78
108
|
this.client_key = client_key;
|
|
79
109
|
this.sandbox = sandbox;
|
|
@@ -90,6 +120,26 @@ class Paddle {
|
|
|
90
120
|
this.server.csp["script-src"] += " https://*.paddle.com/ https://*.payments-amazon.com https://*.paypal.com https://*.google.com";
|
|
91
121
|
this.server.csp["style-src"] += " https://*.paddle.com/ https://*.media-amazon.com https://*.paypal.com https://*.google.com";
|
|
92
122
|
this.server.csp["img-src"] += " https://*.paddle.com/ https://*.media-amazon.com https://*.paypal.com https://*.google.com";
|
|
123
|
+
this._last_products_db = this.server.db.collection({
|
|
124
|
+
name: "Volt.Paddle.LastProducts",
|
|
125
|
+
indexes: ["production", "version"]
|
|
126
|
+
});
|
|
127
|
+
this._webhook_conf_db = this.server.db.collection({
|
|
128
|
+
name: "Volt.Paddle.WebhookConfig",
|
|
129
|
+
indexes: ["production", "version"]
|
|
130
|
+
});
|
|
131
|
+
this._sub_db = this.server.db.collection({
|
|
132
|
+
name: "Volt.Paddle.Subscriptions",
|
|
133
|
+
indexes: ["uid", "id"]
|
|
134
|
+
});
|
|
135
|
+
this._active_sub_db = this.server.db.collection({
|
|
136
|
+
name: "Volt.Paddle.ActiveSubscriptions",
|
|
137
|
+
indexes: ["uid", "prod_id"]
|
|
138
|
+
});
|
|
139
|
+
this._pay_db = this.server.db.collection({
|
|
140
|
+
name: "Volt.Paddle.Payments",
|
|
141
|
+
indexes: ["uid", "id", "tran_id"]
|
|
142
|
+
});
|
|
93
143
|
this.performance = new vlib.Performance("Payments performance");
|
|
94
144
|
}
|
|
95
145
|
// ---------------------------------------------------------
|
|
@@ -98,10 +148,23 @@ class Paddle {
|
|
|
98
148
|
// Utils (private).
|
|
99
149
|
async _req(method, endpoint, params = null) {
|
|
100
150
|
const promise = new Promise((resolve, reject) => {
|
|
151
|
+
const is_get_like = method === "GET" || method === "HEAD";
|
|
152
|
+
let hostname = this._host;
|
|
153
|
+
let path = endpoint;
|
|
154
|
+
try {
|
|
155
|
+
if (/^https?:\/\//i.test(endpoint)) {
|
|
156
|
+
const u = new URL(endpoint);
|
|
157
|
+
hostname = u.hostname;
|
|
158
|
+
path = u.pathname + u.search;
|
|
159
|
+
} else if (is_get_like && params != null) {
|
|
160
|
+
path = `${endpoint}?${new URLSearchParams(params).toString()}`;
|
|
161
|
+
}
|
|
162
|
+
} catch {
|
|
163
|
+
}
|
|
101
164
|
const options = {
|
|
102
165
|
method,
|
|
103
|
-
hostname
|
|
104
|
-
path
|
|
166
|
+
hostname,
|
|
167
|
+
path,
|
|
105
168
|
port: 443,
|
|
106
169
|
headers: this._headers
|
|
107
170
|
};
|
|
@@ -113,21 +176,21 @@ class Paddle {
|
|
|
113
176
|
response.on("end", () => {
|
|
114
177
|
if (response?.statusCode >= 200 && response?.statusCode < 300) {
|
|
115
178
|
try {
|
|
116
|
-
resolve(JSON.parse(data));
|
|
117
|
-
} catch (
|
|
179
|
+
resolve(data ? JSON.parse(data) : {});
|
|
180
|
+
} catch (error) {
|
|
118
181
|
reject(new Error("Failed to parse response data"));
|
|
119
182
|
}
|
|
120
183
|
} else {
|
|
121
184
|
if (data == null || data === "") {
|
|
122
|
-
return reject(new RequestError(`${method}:${endpoint}: Request failed [${response.statusCode}].`, response.statusCode));
|
|
185
|
+
return reject(new Paddle.RequestError(`${method}:${endpoint}: Request failed [${response.statusCode}].`, response.statusCode));
|
|
123
186
|
}
|
|
124
187
|
try {
|
|
125
188
|
data = JSON.parse(data);
|
|
126
189
|
} catch (e) {
|
|
127
|
-
return reject(new RequestError(`${method}:${endpoint}: Request failed [${response.statusCode}].`, response.statusCode));
|
|
190
|
+
return reject(new Paddle.RequestError(`${method}:${endpoint}: Request failed [${response.statusCode}].`, response.statusCode));
|
|
128
191
|
}
|
|
129
192
|
if (data.error == null) {
|
|
130
|
-
return reject(new RequestError(`${method}:${endpoint}: Request failed [${response.statusCode}].`, response.statusCode));
|
|
193
|
+
return reject(new Paddle.RequestError(`${method}:${endpoint}: Request failed [${response.statusCode}].`, response.statusCode));
|
|
131
194
|
}
|
|
132
195
|
data = data.error;
|
|
133
196
|
let errs = "";
|
|
@@ -138,24 +201,24 @@ class Paddle {
|
|
|
138
201
|
});
|
|
139
202
|
errs = errs.substr(0, errs.length - 2);
|
|
140
203
|
}
|
|
141
|
-
return reject(new RequestError(`${method}:${endpoint}: ${data.detail} [${response.statusCode}]${errs}.`, response.statusCode));
|
|
204
|
+
return reject(new Paddle.RequestError(`${method}:${endpoint}: ${data.detail} [${response.statusCode}]${errs}.`, response.statusCode));
|
|
142
205
|
}
|
|
143
206
|
});
|
|
144
207
|
});
|
|
145
|
-
if (params != null) {
|
|
208
|
+
if (!is_get_like && params != null) {
|
|
146
209
|
const requestBody = JSON.stringify(params);
|
|
147
210
|
request.setHeader("Content-Length", Buffer.byteLength(requestBody));
|
|
148
211
|
request.write(requestBody);
|
|
149
212
|
}
|
|
150
|
-
request.on("error", (
|
|
151
|
-
reject(
|
|
213
|
+
request.on("error", (error) => {
|
|
214
|
+
reject(error);
|
|
152
215
|
});
|
|
153
216
|
request.end();
|
|
154
217
|
});
|
|
155
218
|
try {
|
|
156
219
|
return await promise;
|
|
157
220
|
} catch (e) {
|
|
158
|
-
if (e instanceof Error || e instanceof RequestError) {
|
|
221
|
+
if (e instanceof Error || e instanceof Paddle.RequestError) {
|
|
159
222
|
throw e;
|
|
160
223
|
}
|
|
161
224
|
throw new Error(e);
|
|
@@ -165,31 +228,24 @@ class Paddle {
|
|
|
165
228
|
// Database (private).
|
|
166
229
|
// Add or remove a subscription to the user's active subscriptions.
|
|
167
230
|
async _add_subscription(uid, prod_id, sub_id) {
|
|
168
|
-
await this._active_sub_db.
|
|
231
|
+
await this._active_sub_db.set({ uid, prod_id }, { prod_id, sub_id });
|
|
169
232
|
}
|
|
170
233
|
async _delete_subscription(uid, prod_id) {
|
|
171
234
|
await this._active_sub_db.delete({ uid, prod_id });
|
|
172
235
|
}
|
|
173
236
|
async _check_subscription(uid, prod_id, load_data = false) {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
return exists;
|
|
237
|
+
try {
|
|
238
|
+
const doc = await this._active_sub_db.load({ uid, prod_id });
|
|
239
|
+
return load_data ? { exists: true, sub_id: doc.sub_id } : true;
|
|
240
|
+
} catch (err) {
|
|
241
|
+
if (err instanceof import_collection.Collection.NotFoundError) {
|
|
242
|
+
return load_data ? { exists: false, sub_id: void 0 } : false;
|
|
181
243
|
}
|
|
182
|
-
|
|
183
|
-
exists = true;
|
|
184
|
-
sub_id = doc.sub_id;
|
|
185
|
-
if (load_data) {
|
|
186
|
-
return { exists, sub_id };
|
|
187
|
-
} else {
|
|
188
|
-
return exists;
|
|
244
|
+
throw err;
|
|
189
245
|
}
|
|
190
246
|
}
|
|
191
247
|
async _get_active_subscriptions(uid, detailed = false) {
|
|
192
|
-
const list = await this._active_sub_db.
|
|
248
|
+
const list = await this._active_sub_db.list({ uid });
|
|
193
249
|
if (detailed) {
|
|
194
250
|
return list;
|
|
195
251
|
}
|
|
@@ -200,52 +256,40 @@ class Paddle {
|
|
|
200
256
|
return products;
|
|
201
257
|
}
|
|
202
258
|
async _save_subscription(subscription) {
|
|
203
|
-
await this._sub_db.
|
|
259
|
+
await this._sub_db.set({
|
|
204
260
|
uid: subscription.uid == null ? "unauth" : subscription.uid,
|
|
205
261
|
id: subscription.id
|
|
206
262
|
}, subscription);
|
|
207
263
|
}
|
|
208
264
|
async _load_subscription(id) {
|
|
209
|
-
|
|
210
|
-
if (subscription == null) {
|
|
211
|
-
throw Error(`Unable to find subscription "${id}".`);
|
|
212
|
-
}
|
|
213
|
-
return subscription;
|
|
265
|
+
return await this._sub_db.load({ id }, { retry: 3 });
|
|
214
266
|
}
|
|
215
267
|
async _get_subscriptions(uid) {
|
|
216
268
|
if (uid === "unauth" || uid == null) {
|
|
217
269
|
return [];
|
|
218
270
|
}
|
|
219
|
-
const list = await this._sub_db.
|
|
271
|
+
const list = await this._sub_db.list({ uid });
|
|
220
272
|
return list;
|
|
221
273
|
}
|
|
222
274
|
// Save and delete payments, all failed payments should be deleted from the database.
|
|
223
275
|
async _save_payment(payment) {
|
|
224
|
-
await this._pay_db.
|
|
276
|
+
await this._pay_db.set({
|
|
225
277
|
uid: payment.uid == null ? "unauth" : payment.uid,
|
|
226
278
|
id: payment.id
|
|
227
279
|
}, payment);
|
|
228
280
|
}
|
|
229
281
|
async _load_payment(id) {
|
|
230
282
|
const uid = id.split("_")[1];
|
|
231
|
-
|
|
232
|
-
if (payment == null) {
|
|
233
|
-
throw Error(`Unable to find payment "${id}".`);
|
|
234
|
-
}
|
|
235
|
-
if (uid == null || uid == "unauth") {
|
|
236
|
-
delete payment.billing_details;
|
|
237
|
-
}
|
|
238
|
-
return payment;
|
|
283
|
+
return await this._pay_db.load({ uid, id });
|
|
239
284
|
}
|
|
240
|
-
async
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
return payment;
|
|
285
|
+
async _load_payment_for_public(id) {
|
|
286
|
+
return Payment.anonymize(await this._load_payment(id));
|
|
287
|
+
}
|
|
288
|
+
async _load_payment_by_transaction(tran_id) {
|
|
289
|
+
return await this._pay_db.load({ tran_id }, { retry: 3 });
|
|
290
|
+
}
|
|
291
|
+
async _load_payment_by_transaction_for_public(tran_id) {
|
|
292
|
+
return Payment.anonymize(await this._load_payment_by_transaction(tran_id));
|
|
249
293
|
}
|
|
250
294
|
async _delete_payment(id) {
|
|
251
295
|
const uid = id.split("_")[1];
|
|
@@ -253,13 +297,13 @@ class Paddle {
|
|
|
253
297
|
}
|
|
254
298
|
// Delete all info of a user.
|
|
255
299
|
async _delete_user(uid) {
|
|
256
|
-
await this._sub_db.
|
|
257
|
-
await this._active_sub_db.
|
|
258
|
-
await this._pay_db.
|
|
300
|
+
await this._sub_db.delete_many({ uid });
|
|
301
|
+
await this._active_sub_db.delete_many({ uid });
|
|
302
|
+
await this._pay_db.delete_many({ uid });
|
|
259
303
|
}
|
|
260
304
|
// List all active subscriptions.
|
|
261
305
|
async _get_all_active_subscriptions() {
|
|
262
|
-
return await this._active_sub_db.
|
|
306
|
+
return await this._active_sub_db.list_all();
|
|
263
307
|
}
|
|
264
308
|
// ---------------------------------------------------------
|
|
265
309
|
// Overall (private).
|
|
@@ -328,8 +372,8 @@ class Paddle {
|
|
|
328
372
|
if (process.argv.includes("--no-payment-edits")) {
|
|
329
373
|
return false;
|
|
330
374
|
}
|
|
331
|
-
if (this._has_create_products_permission) {
|
|
332
|
-
return
|
|
375
|
+
if (this._has_create_products_permission != null) {
|
|
376
|
+
return this._has_create_products_permission;
|
|
333
377
|
}
|
|
334
378
|
const input = await vlib.logging.prompt("Some paddle products have to be edited, do you wish to make these changes? [y/n]: ");
|
|
335
379
|
if (["y", "yes", "ok"].includes(input.toLowerCase())) {
|
|
@@ -348,7 +392,7 @@ class Paddle {
|
|
|
348
392
|
if (!await has_create_products_permission()) {
|
|
349
393
|
return;
|
|
350
394
|
}
|
|
351
|
-
log(0, `Creating product ${product.name}.`);
|
|
395
|
+
this.server.log(0, `Creating product ${product.name}.`);
|
|
352
396
|
const created_product = await this._req("POST", "/products", {
|
|
353
397
|
name: product.name,
|
|
354
398
|
description: product.description,
|
|
@@ -357,26 +401,26 @@ class Paddle {
|
|
|
357
401
|
custom_data: { id: product.id }
|
|
358
402
|
});
|
|
359
403
|
product.paddle_prod_id = created_product.data.id;
|
|
360
|
-
log(0, `Creating a price for product ${product.name}.`);
|
|
404
|
+
this.server.log(0, `Creating a price for product ${product.name}.`);
|
|
361
405
|
const created_price = await this._req("POST", "/prices", {
|
|
362
406
|
product_id: product.paddle_prod_id,
|
|
363
407
|
name: product.name,
|
|
364
408
|
description: product.description,
|
|
365
409
|
unit_price: { amount: Math.floor(product.price * 100).toString(), currency_code: product.currency },
|
|
366
410
|
billing_cycle: product.is_subscription ? { interval: product.interval, frequency: product.frequency } : null,
|
|
367
|
-
trial_period: product.trial,
|
|
411
|
+
trial_period: product.is_subscription ? product.trial : null,
|
|
368
412
|
tax_mode: this.inclusive_tax ? "internal" : "external"
|
|
369
413
|
});
|
|
370
414
|
product.price_id = created_price.data.id;
|
|
371
415
|
} else {
|
|
372
416
|
product.paddle_prod_id = existing_product.id;
|
|
373
|
-
const has_trial = product.trial != null;
|
|
417
|
+
const has_trial = product.is_subscription && product.trial != null;
|
|
374
418
|
const update_product = existing_product.name !== product.name || existing_product.description !== product.description || existing_product.image_url !== product.icon || existing_product.tax_category !== product.tax_category || existing_product.status !== "active";
|
|
375
419
|
if (update_product) {
|
|
376
420
|
if (!await has_create_products_permission()) {
|
|
377
421
|
return;
|
|
378
422
|
}
|
|
379
|
-
log(0, `Updating product ${product.name}.`);
|
|
423
|
+
this.server.log(0, `Updating product ${product.name}.`);
|
|
380
424
|
await this._req("PATCH", `/products/${product.paddle_prod_id}`, {
|
|
381
425
|
name: product.name,
|
|
382
426
|
description: product.description,
|
|
@@ -395,14 +439,14 @@ class Paddle {
|
|
|
395
439
|
if (!await has_create_products_permission()) {
|
|
396
440
|
return;
|
|
397
441
|
}
|
|
398
|
-
log(0, `Creating a price for product ${product.name}.`);
|
|
442
|
+
this.server.log(0, `Creating a price for product ${product.name}.`);
|
|
399
443
|
const price = await this._req("POST", "/prices", {
|
|
400
444
|
product_id: product.paddle_prod_id,
|
|
401
445
|
name: product.name,
|
|
402
446
|
description: product.description,
|
|
403
447
|
unit_price: { amount: Math.floor(product.price * 100).toString(), currency_code: product.currency },
|
|
404
448
|
billing_cycle: product.is_subscription ? { interval: product.interval, frequency: product.frequency } : null,
|
|
405
|
-
trial_period: product.trial,
|
|
449
|
+
trial_period: product.is_subscription ? product.trial : null,
|
|
406
450
|
tax_mode: this.inclusive_tax ? "internal" : "external"
|
|
407
451
|
});
|
|
408
452
|
product.price_id = price.data.id;
|
|
@@ -413,14 +457,14 @@ class Paddle {
|
|
|
413
457
|
if (!await has_create_products_permission()) {
|
|
414
458
|
return;
|
|
415
459
|
}
|
|
416
|
-
log(0, `Updating the price of product ${product.name}.`);
|
|
460
|
+
this.server.log(0, `Updating the price of product ${product.name}.`);
|
|
417
461
|
await this._req("PATCH", `/prices/${product.price_id}`, {
|
|
418
462
|
// product_id: product.id, // not allowed.
|
|
419
463
|
name: product.name,
|
|
420
464
|
description: product.description,
|
|
421
465
|
unit_price: { amount: Math.floor(product.price * 100).toString(), currency_code: product.currency },
|
|
422
466
|
billing_cycle: product.is_subscription ? { interval: product.interval, frequency: product.frequency } : null,
|
|
423
|
-
trial_period: product.trial,
|
|
467
|
+
trial_period: product.is_subscription ? product.trial : null,
|
|
424
468
|
tax_mode: this.inclusive_tax ? "internal" : "external",
|
|
425
469
|
status: "active"
|
|
426
470
|
});
|
|
@@ -438,7 +482,7 @@ class Paddle {
|
|
|
438
482
|
throw Error(`Unable to find subscription "${id}".`);
|
|
439
483
|
}
|
|
440
484
|
if (subscription.status !== "active") {
|
|
441
|
-
throw new
|
|
485
|
+
throw new import_errors.ExternalError({
|
|
442
486
|
type: "NoActiveSubscriptionError",
|
|
443
487
|
message: `This subscription is already cancelled and will become inactive at the end of the billing period.`,
|
|
444
488
|
status: import_status.Status.bad_request
|
|
@@ -617,8 +661,8 @@ class Paddle {
|
|
|
617
661
|
};
|
|
618
662
|
let sub_products = 0;
|
|
619
663
|
this.products.iterate((product) => {
|
|
620
|
-
if (product.
|
|
621
|
-
if (product.plans
|
|
664
|
+
if (product.is_subscription) {
|
|
665
|
+
if (!product.plans || !Array.isArray(product.plans)) {
|
|
622
666
|
throw Error(`Product "${product_index}" has an incorrect value type for attribute "plans", the valid type is "array".`);
|
|
623
667
|
}
|
|
624
668
|
product.id = `sub_${sub_products}`;
|
|
@@ -651,18 +695,17 @@ class Paddle {
|
|
|
651
695
|
}
|
|
652
696
|
initialize_product(plan);
|
|
653
697
|
});
|
|
654
|
-
} else if (product.frequency != null || product.interval != null) {
|
|
655
|
-
throw Error(`Subscription products should be nested as plans of a subscription "{... plans: [...]}". Not as a direct product without a subscription parent.`);
|
|
656
698
|
} else {
|
|
657
699
|
product.is_subscription = false;
|
|
658
700
|
initialize_product(product);
|
|
659
701
|
}
|
|
660
702
|
});
|
|
661
703
|
now = this.performance.end("init-products", now);
|
|
662
|
-
const last_products = await this.
|
|
663
|
-
if (
|
|
664
|
-
|
|
665
|
-
|
|
704
|
+
const last_products = await this._last_products_db.load({ production: this.server.production, version: 1 }, { throw: false });
|
|
705
|
+
if (last_products instanceof Error && !(last_products instanceof import_collection.Collection.NotFoundError))
|
|
706
|
+
throw last_products;
|
|
707
|
+
if (!(last_products instanceof import_collection.Collection.NotFoundError) && vlib.Object.eq(last_products.last_products, this.products)) {
|
|
708
|
+
last_products.product_ids.iterate((item) => {
|
|
666
709
|
const product = this.get_product_sync(item.id);
|
|
667
710
|
if (product != null) {
|
|
668
711
|
product.paddle_prod_id = item.paddle_prod_id;
|
|
@@ -676,7 +719,7 @@ class Paddle {
|
|
|
676
719
|
now = this.performance.end("get-prices-and-products", now);
|
|
677
720
|
const product_ids2 = [];
|
|
678
721
|
for (const product of this.products) {
|
|
679
|
-
if (product.
|
|
722
|
+
if (product.is_subscription) {
|
|
680
723
|
for (const plan of product.plans) {
|
|
681
724
|
await this._check_product(plan, existing_products, existing_prices);
|
|
682
725
|
product_ids2.append({
|
|
@@ -697,73 +740,63 @@ class Paddle {
|
|
|
697
740
|
}
|
|
698
741
|
;
|
|
699
742
|
now = this.performance.end("check-products", now);
|
|
700
|
-
await this.
|
|
701
|
-
|
|
743
|
+
await this._last_products_db.set({ production: this.server.production, version: 1 }, {
|
|
744
|
+
last_products: vlib.Object.delete_recursively(vlib.Object.deep_copy(this.products), ["paddle_prod_id", "price_id"]),
|
|
745
|
+
product_ids: product_ids2
|
|
746
|
+
});
|
|
702
747
|
now = this.performance.end("save-products-to-db", now);
|
|
703
748
|
}
|
|
704
749
|
}
|
|
705
750
|
// Initialize the payments.
|
|
706
751
|
async _initialize() {
|
|
707
|
-
this.performance.start();
|
|
708
|
-
this._settings_db = await this.server.db.collection({
|
|
709
|
-
name: "Volt.Paddle.Settings",
|
|
710
|
-
indexes: ["_path"]
|
|
711
|
-
});
|
|
712
|
-
this._sub_db = await this.server.db.collection({
|
|
713
|
-
name: "Volt.Paddle.Subscriptions",
|
|
714
|
-
indexes: ["uid", "id"]
|
|
715
|
-
});
|
|
716
|
-
this._active_sub_db = await this.server.db.collection({
|
|
717
|
-
name: "Volt.Paddle.ActiveSubscriptions",
|
|
718
|
-
indexes: ["uid", "prod_id"]
|
|
719
|
-
});
|
|
720
|
-
this._pay_db = await this.server.db.collection({
|
|
721
|
-
name: "Volt.Paddle.Payments",
|
|
722
|
-
indexes: ["uid", "id", "tran_id"]
|
|
723
|
-
});
|
|
724
|
-
this.performance.end("init-db");
|
|
725
752
|
await this._initialize_products();
|
|
726
753
|
let now = this.performance.start();
|
|
727
754
|
this.server.endpoint({
|
|
728
755
|
method: "POST",
|
|
729
|
-
endpoint: "/volt/payments/init",
|
|
756
|
+
endpoint: "/volt/api/v1/payments/init",
|
|
730
757
|
content_type: "application/json",
|
|
731
758
|
rate_limit: "global",
|
|
732
759
|
params: {
|
|
733
|
-
items: "array"
|
|
760
|
+
items: { type: "array", required: true, value_schema: "object" }
|
|
761
|
+
// add schema for items
|
|
734
762
|
},
|
|
735
763
|
callback: async (stream, params) => {
|
|
736
764
|
if (params.items.length === 0) {
|
|
737
|
-
return stream.error({ status: import_status.Status.bad_request,
|
|
765
|
+
return stream.error({ status: import_status.Status.bad_request, message: "Shopping cart is empty." });
|
|
738
766
|
}
|
|
739
767
|
let sub_plan_count = {};
|
|
740
|
-
|
|
768
|
+
let error = void 0;
|
|
769
|
+
for (const item of params.items) {
|
|
741
770
|
if (item.product.is_subscription) {
|
|
742
771
|
if (stream.uid == null) {
|
|
743
|
-
|
|
772
|
+
error = "You must be signed-in to purchase a subscription.";
|
|
773
|
+
break;
|
|
744
774
|
}
|
|
745
775
|
if (item.quantity != null && item.quantity > 1) {
|
|
746
|
-
|
|
776
|
+
error = "Subscriptions have a max quantity of 1.";
|
|
777
|
+
break;
|
|
747
778
|
}
|
|
748
779
|
if (sub_plan_count[item.product.subscription_id] == null) {
|
|
749
780
|
sub_plan_count[item.product.subscription_id] = 1;
|
|
750
781
|
} else {
|
|
751
|
-
|
|
782
|
+
error = "You can not charge two different subscription plans from the same subscription product.";
|
|
783
|
+
break;
|
|
752
784
|
}
|
|
753
785
|
if (await this._check_subscription(stream.uid, item.product.id, false)) {
|
|
754
|
-
|
|
786
|
+
error = `You are already subscribed to product "${item.product.name}".`;
|
|
787
|
+
break;
|
|
755
788
|
}
|
|
756
789
|
}
|
|
757
|
-
}
|
|
758
|
-
if (
|
|
759
|
-
return stream.error({ status: import_status.Status.bad_request,
|
|
790
|
+
}
|
|
791
|
+
if (error) {
|
|
792
|
+
return stream.error({ status: import_status.Status.bad_request, message: error });
|
|
760
793
|
}
|
|
761
794
|
return stream.success({ data: { message: "Successfully initialized the order." } });
|
|
762
795
|
}
|
|
763
796
|
});
|
|
764
797
|
this.server.endpoint({
|
|
765
798
|
method: "GET",
|
|
766
|
-
endpoint: "/volt/payments/products",
|
|
799
|
+
endpoint: "/volt/api/v1/payments/products",
|
|
767
800
|
content_type: "application/json",
|
|
768
801
|
rate_limit: "global",
|
|
769
802
|
callback: (stream) => {
|
|
@@ -772,113 +805,125 @@ class Paddle {
|
|
|
772
805
|
});
|
|
773
806
|
this.server.endpoint({
|
|
774
807
|
method: "GET",
|
|
775
|
-
endpoint: "/volt/payments/payment",
|
|
808
|
+
endpoint: "/volt/api/v1/payments/payment",
|
|
776
809
|
content_type: "application/json",
|
|
777
810
|
rate_limit: "global",
|
|
778
811
|
params: {
|
|
779
812
|
id: "string"
|
|
780
813
|
},
|
|
781
814
|
callback: async (stream, params) => {
|
|
782
|
-
return stream.success({
|
|
815
|
+
return stream.success({
|
|
816
|
+
data: await this._load_payment_for_public(params.id)
|
|
817
|
+
});
|
|
783
818
|
}
|
|
784
819
|
});
|
|
785
820
|
this.server.endpoint({
|
|
786
821
|
method: "GET",
|
|
787
|
-
endpoint: "/volt/payments/payments",
|
|
822
|
+
endpoint: "/volt/api/v1/payments/payments",
|
|
788
823
|
content_type: "application/json",
|
|
789
824
|
authenticated: true,
|
|
790
825
|
rate_limit: "global",
|
|
791
826
|
params: {
|
|
792
827
|
days: { type: "number", default: 30 },
|
|
793
|
-
limit: { type: "number",
|
|
794
|
-
status: { type: "string",
|
|
828
|
+
limit: { type: "number", required: false },
|
|
829
|
+
status: { type: "string", required: false, enum: PaymentStatusValues }
|
|
795
830
|
},
|
|
796
831
|
callback: async (stream, params) => {
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
832
|
+
return stream.success({
|
|
833
|
+
data: await this.get_payments({
|
|
834
|
+
uid: stream.uid,
|
|
835
|
+
days: params.days,
|
|
836
|
+
limit: params.limit,
|
|
837
|
+
status: params.status
|
|
838
|
+
})
|
|
802
839
|
});
|
|
803
|
-
return stream.success({ data: result });
|
|
804
840
|
}
|
|
805
841
|
});
|
|
806
842
|
this.server.endpoint({
|
|
807
843
|
method: "GET",
|
|
808
|
-
endpoint: "/volt/payments/payments/refundable",
|
|
844
|
+
endpoint: "/volt/api/v1/payments/payments/refundable",
|
|
809
845
|
content_type: "application/json",
|
|
810
846
|
authenticated: true,
|
|
811
847
|
rate_limit: "global",
|
|
812
848
|
params: {
|
|
813
849
|
days: { type: "number", default: 30 },
|
|
814
|
-
limit: { type:
|
|
815
|
-
status: { type: ["null", "string"], default: null }
|
|
850
|
+
limit: { type: "number", required: false }
|
|
816
851
|
},
|
|
817
852
|
callback: async (stream, params) => {
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
853
|
+
return stream.success({
|
|
854
|
+
data: await this.get_refundable_payments({
|
|
855
|
+
uid: stream.uid,
|
|
856
|
+
days: params.days,
|
|
857
|
+
limit: params.limit,
|
|
858
|
+
for_public: true
|
|
859
|
+
})
|
|
822
860
|
});
|
|
823
|
-
return stream.success({ data: result });
|
|
824
861
|
}
|
|
825
862
|
});
|
|
826
863
|
this.server.endpoint({
|
|
827
864
|
method: "GET",
|
|
828
|
-
endpoint: "/volt/payments/payments/refunded",
|
|
865
|
+
endpoint: "/volt/api/v1/payments/payments/refunded",
|
|
829
866
|
content_type: "application/json",
|
|
830
867
|
authenticated: true,
|
|
831
868
|
rate_limit: "global",
|
|
832
869
|
params: {
|
|
833
870
|
days: { type: "number", default: 30 },
|
|
834
|
-
limit: { type:
|
|
871
|
+
limit: { type: "number", required: false }
|
|
835
872
|
},
|
|
836
873
|
callback: async (stream, params) => {
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
874
|
+
return stream.success({
|
|
875
|
+
data: await this.get_refunded_payments({
|
|
876
|
+
uid: stream.uid,
|
|
877
|
+
days: params.days,
|
|
878
|
+
limit: params.limit,
|
|
879
|
+
for_public: true
|
|
880
|
+
})
|
|
841
881
|
});
|
|
842
|
-
return stream.success({ data: result });
|
|
843
882
|
}
|
|
844
883
|
});
|
|
845
884
|
this.server.endpoint({
|
|
846
885
|
method: "GET",
|
|
847
|
-
endpoint: "/volt/payments/payments/refunding",
|
|
886
|
+
endpoint: "/volt/api/v1/payments/payments/refunding",
|
|
848
887
|
content_type: "application/json",
|
|
849
888
|
authenticated: true,
|
|
850
889
|
rate_limit: "global",
|
|
851
890
|
params: {
|
|
852
|
-
days: { type:
|
|
853
|
-
limit: { type:
|
|
891
|
+
days: { type: "number", default: 30 },
|
|
892
|
+
limit: { type: "number", required: false }
|
|
854
893
|
},
|
|
855
894
|
callback: async (stream, params) => {
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
895
|
+
return stream.success({
|
|
896
|
+
data: await this.get_refunding_payments({
|
|
897
|
+
uid: stream.uid,
|
|
898
|
+
days: params.days,
|
|
899
|
+
limit: params.limit,
|
|
900
|
+
for_public: true
|
|
901
|
+
})
|
|
860
902
|
});
|
|
861
|
-
return stream.success({ data: result });
|
|
862
903
|
}
|
|
863
904
|
});
|
|
864
905
|
this.server.endpoint({
|
|
865
906
|
method: "POST",
|
|
866
|
-
endpoint: "/volt/payments/refund",
|
|
907
|
+
endpoint: "/volt/api/v1/payments/refund",
|
|
867
908
|
content_type: "application/json",
|
|
909
|
+
authenticated: true,
|
|
868
910
|
rate_limit: "global",
|
|
869
911
|
params: {
|
|
870
|
-
payment: { type: ["string", "object"] },
|
|
871
|
-
line_items: { type:
|
|
912
|
+
payment: { type: ["string", "object"], schema: { id: "string" } },
|
|
913
|
+
line_items: { type: "array", required: false, value_schema: {
|
|
914
|
+
type: "object",
|
|
915
|
+
schema: LineItem.Schema
|
|
916
|
+
} },
|
|
872
917
|
reason: { type: "string", default: "refund" }
|
|
873
918
|
},
|
|
874
919
|
callback: async (stream, params) => {
|
|
875
|
-
await this.create_refund(params.payment, params.line_items, params.reason);
|
|
920
|
+
await this.create_refund(typeof params.payment === "string" ? params.payment : params.payment.id, params.line_items, params.reason);
|
|
876
921
|
return stream.success();
|
|
877
922
|
}
|
|
878
923
|
});
|
|
879
924
|
this.server.endpoint({
|
|
880
925
|
method: "DELETE",
|
|
881
|
-
endpoint: "/volt/payments/subscription",
|
|
926
|
+
endpoint: "/volt/api/v1/payments/subscription",
|
|
882
927
|
content_type: "application/json",
|
|
883
928
|
authenticated: true,
|
|
884
929
|
rate_limit: "global",
|
|
@@ -892,19 +937,21 @@ class Paddle {
|
|
|
892
937
|
});
|
|
893
938
|
this.server.endpoint({
|
|
894
939
|
method: "GET",
|
|
895
|
-
endpoint: "/volt/payments/active_subscriptions",
|
|
940
|
+
endpoint: "/volt/api/v1/payments/active_subscriptions",
|
|
896
941
|
content_type: "application/json",
|
|
897
942
|
authenticated: true,
|
|
898
943
|
rate_limit: "global",
|
|
899
|
-
callback: async (stream
|
|
944
|
+
callback: async (stream) => {
|
|
900
945
|
return stream.success({
|
|
901
|
-
data: {
|
|
946
|
+
data: {
|
|
947
|
+
subscriptions: await this.get_active_subscriptions(stream.uid)
|
|
948
|
+
}
|
|
902
949
|
});
|
|
903
950
|
}
|
|
904
951
|
});
|
|
905
952
|
this.server.endpoint({
|
|
906
953
|
method: "GET",
|
|
907
|
-
endpoint: "/volt/payments/subscribed",
|
|
954
|
+
endpoint: "/volt/api/v1/payments/subscribed",
|
|
908
955
|
content_type: "application/json",
|
|
909
956
|
authenticated: true,
|
|
910
957
|
rate_limit: "global",
|
|
@@ -913,7 +960,9 @@ class Paddle {
|
|
|
913
960
|
},
|
|
914
961
|
callback: async (stream, params) => {
|
|
915
962
|
return stream.success({
|
|
916
|
-
data: {
|
|
963
|
+
data: {
|
|
964
|
+
is_subscribed: await this.is_subscribed(stream.uid, params.product)
|
|
965
|
+
}
|
|
917
966
|
});
|
|
918
967
|
}
|
|
919
968
|
});
|
|
@@ -932,8 +981,8 @@ class Paddle {
|
|
|
932
981
|
if (res instanceof Promise) {
|
|
933
982
|
res = await res;
|
|
934
983
|
}
|
|
935
|
-
} catch (
|
|
936
|
-
console.error(
|
|
984
|
+
} catch (error) {
|
|
985
|
+
console.error(error);
|
|
937
986
|
}
|
|
938
987
|
}
|
|
939
988
|
}
|
|
@@ -948,7 +997,7 @@ class Paddle {
|
|
|
948
997
|
// }
|
|
949
998
|
// On a successfull payment webhook event.
|
|
950
999
|
async _payment_webhook(data) {
|
|
951
|
-
let obj = (await this._req("GET", `/transactions/${data.id}`, { include: ["address", "
|
|
1000
|
+
let obj = (await this._req("GET", `/transactions/${data.id}`, { include: ["address", "adjustments", "business", "customer"] })).data;
|
|
952
1001
|
const id = `pay_${obj.custom_data.uid == null ? "unauth" : obj.custom_data.uid}_${vlib.String.random(4)}${Date.now()}`;
|
|
953
1002
|
const payment = {
|
|
954
1003
|
id,
|
|
@@ -1029,7 +1078,7 @@ class Paddle {
|
|
|
1029
1078
|
payment.status = "past_due";
|
|
1030
1079
|
break;
|
|
1031
1080
|
default:
|
|
1032
|
-
error(`Payment Webhook: Unknown payment status "${obj.status}".`);
|
|
1081
|
+
this.server.log.error(`Payment Webhook: Unknown payment status "${obj.status}".`);
|
|
1033
1082
|
payment.status = "unknown";
|
|
1034
1083
|
break;
|
|
1035
1084
|
}
|
|
@@ -1043,13 +1092,13 @@ class Paddle {
|
|
|
1043
1092
|
// paddle product id.
|
|
1044
1093
|
quantity: item.quantity,
|
|
1045
1094
|
tax_rate: parseFloat(item.tax_rate),
|
|
1046
|
-
tax:
|
|
1095
|
+
tax: item.totals.tax / 100,
|
|
1047
1096
|
// should not be changed to unit totals, since mails and invoices depend on this behaviour, just divide by quantity.
|
|
1048
|
-
discount:
|
|
1097
|
+
discount: item.totals.discount / 100,
|
|
1049
1098
|
// should not be changed to unit totals, since mails and invoices depend on this behaviour, just divide by quantity.
|
|
1050
|
-
subtotal:
|
|
1099
|
+
subtotal: item.totals.subtotal / 100,
|
|
1051
1100
|
// should not be changed to unit totals, since mails and invoices depend on this behaviour, just divide by quantity.
|
|
1052
|
-
total:
|
|
1101
|
+
total: item.totals.total / 100,
|
|
1053
1102
|
// should not be changed to unit totals, since mails and invoices depend on this behaviour, just divide by quantity.
|
|
1054
1103
|
status: "paid"
|
|
1055
1104
|
// can be "paid", "refunded", "refunding".
|
|
@@ -1059,8 +1108,7 @@ class Paddle {
|
|
|
1059
1108
|
obj.adustments.iterate((adj) => {
|
|
1060
1109
|
switch (adj.action) {
|
|
1061
1110
|
case "refund":
|
|
1062
|
-
case "
|
|
1063
|
-
case "cargeback_warning":
|
|
1111
|
+
case "chargeback":
|
|
1064
1112
|
adj.items.iterate((adj_item) => {
|
|
1065
1113
|
payment.line_items.iterate((item) => {
|
|
1066
1114
|
if (adj_item.item_id === item.item_id) {
|
|
@@ -1070,24 +1118,34 @@ class Paddle {
|
|
|
1070
1118
|
});
|
|
1071
1119
|
});
|
|
1072
1120
|
break;
|
|
1121
|
+
case "chargeback_reversal":
|
|
1122
|
+
adj.items.iterate((adj_item) => {
|
|
1123
|
+
payment.line_items.iterate((item) => {
|
|
1124
|
+
if (adj_item.item_id === item.item_id) {
|
|
1125
|
+
item.status = "paid";
|
|
1126
|
+
return false;
|
|
1127
|
+
}
|
|
1128
|
+
});
|
|
1129
|
+
});
|
|
1130
|
+
break;
|
|
1073
1131
|
default:
|
|
1074
1132
|
break;
|
|
1075
1133
|
}
|
|
1076
1134
|
});
|
|
1077
1135
|
}
|
|
1078
1136
|
await this._save_payment(payment);
|
|
1079
|
-
const { uid
|
|
1080
|
-
for (const item of
|
|
1137
|
+
const { uid } = payment;
|
|
1138
|
+
for (const item of payment.line_items) {
|
|
1081
1139
|
const product = this.get_product_sync(item.product, false);
|
|
1082
1140
|
if (product == null) {
|
|
1083
1141
|
continue;
|
|
1084
1142
|
} else if (product.is_subscription) {
|
|
1085
1143
|
const subscription = await this.get_product(product.subscription_id, true);
|
|
1086
|
-
for (const plan of subscription
|
|
1144
|
+
for (const plan of subscription?.plans ?? []) {
|
|
1087
1145
|
if (plan.id != product.id) {
|
|
1088
1146
|
const { exists, sub_id } = await this._check_subscription(uid, plan.id);
|
|
1089
1147
|
if (exists) {
|
|
1090
|
-
log(0, `Cancelling subscription "${plan.id}" due too downgrade/upgrade to "${product.id}" of user "${payment.uid}".`);
|
|
1148
|
+
this.server.log(0, `Cancelling subscription "${plan.id}" due too downgrade/upgrade to "${product.id}" of user "${payment.uid}".`);
|
|
1091
1149
|
await this._cancel_subscription(sub_id);
|
|
1092
1150
|
}
|
|
1093
1151
|
}
|
|
@@ -1113,11 +1171,11 @@ class Paddle {
|
|
|
1113
1171
|
for (const item of data.items) {
|
|
1114
1172
|
const product = this._get_product_by_paddle_prod_id(item.price.product_id, false);
|
|
1115
1173
|
if (product == null) {
|
|
1116
|
-
error(`Subscription webhook [#sub1]: Unable to find product with id ${item.price.product_id}. This is a serious error which causes a non activated subscription for a paid transaction. You should manually cancel the subscription. Event: ${JSON.stringify(data, null, 4)}.`);
|
|
1174
|
+
this.server.log.error(`Subscription webhook [#sub1]: Unable to find product with id ${item.price.product_id}. This is a serious error which causes a non activated subscription for a paid transaction. You should manually cancel the subscription. Event: ${JSON.stringify(data, null, 4)}.`);
|
|
1117
1175
|
continue;
|
|
1118
1176
|
} else if (product.is_subscription) {
|
|
1119
1177
|
subscription.plans.append(product.id);
|
|
1120
|
-
log(0, `Activating subscription "${product.id}" of user "${subscription.uid}".`);
|
|
1178
|
+
this.server.log(0, `Activating subscription "${product.id}" of user "${subscription.uid}".`);
|
|
1121
1179
|
await this._add_subscription(uid, product.id, subscription.id);
|
|
1122
1180
|
await this._exec_user_callback(this.server.on_subscription, { product, subscription });
|
|
1123
1181
|
}
|
|
@@ -1129,7 +1187,7 @@ class Paddle {
|
|
|
1129
1187
|
const subscription = await this._load_subscription(data.id);
|
|
1130
1188
|
for (const plan_id of subscription.plans) {
|
|
1131
1189
|
await this._delete_subscription(subscription.uid, plan_id);
|
|
1132
|
-
log(0, `Deactivating subscription "${plan_id}" of user "${subscription.uid}".`);
|
|
1190
|
+
this.server.log(0, `Deactivating subscription "${plan_id}" of user "${subscription.uid}".`);
|
|
1133
1191
|
}
|
|
1134
1192
|
subscription.status = "cancelled";
|
|
1135
1193
|
await this._save_subscription(subscription);
|
|
@@ -1163,16 +1221,16 @@ class Paddle {
|
|
|
1163
1221
|
await this._save_payment(payment);
|
|
1164
1222
|
}
|
|
1165
1223
|
if (is_approved) {
|
|
1166
|
-
log(0, `Refunded items of payment "${payment.id}" of user "${payment.uid}".`);
|
|
1224
|
+
this.server.log(0, `Refunded items of payment "${payment.id}" of user "${payment.uid}".`);
|
|
1167
1225
|
await this._exec_user_callback(is_refund ? this.server.on_refund : this.server.on_chargeback, { payment, line_items });
|
|
1168
1226
|
} else {
|
|
1169
|
-
log(0, `Refund denied for items of payment ${payment.id} of user "${payment.uid}".`);
|
|
1227
|
+
this.server.log(0, `Refund denied for items of payment ${payment.id} of user "${payment.uid}".`);
|
|
1170
1228
|
await this._exec_user_callback(is_refund ? this.server.on_failed_refund : this.server.on_failed_chargeback, { payment, line_items });
|
|
1171
1229
|
}
|
|
1172
1230
|
} else if (data.action === "chargeback_reverse" && data.status === "reversed") {
|
|
1173
1231
|
const payment = await this._load_payment_by_transaction(data.transaction_id);
|
|
1174
1232
|
if (payment.sub_id != null) {
|
|
1175
|
-
log(0, `Chargeback reversed for payment ${payment.id} from user "${payment.uid}".`);
|
|
1233
|
+
this.server.log(0, `Chargeback reversed for payment ${payment.id} from user "${payment.uid}".`);
|
|
1176
1234
|
}
|
|
1177
1235
|
let line_items = [];
|
|
1178
1236
|
data.items.iterate((adj_item) => {
|
|
@@ -1190,7 +1248,7 @@ class Paddle {
|
|
|
1190
1248
|
}
|
|
1191
1249
|
// Create and register the webhook endpoint.
|
|
1192
1250
|
async _create_webhook() {
|
|
1193
|
-
const
|
|
1251
|
+
const now = this.performance.start();
|
|
1194
1252
|
const webhook_settings = {
|
|
1195
1253
|
description: "volt webhook",
|
|
1196
1254
|
destination: `${this.server.full_domain}/volt/payments/webhook`,
|
|
@@ -1217,58 +1275,72 @@ class Paddle {
|
|
|
1217
1275
|
"adjustment.updated"
|
|
1218
1276
|
]
|
|
1219
1277
|
};
|
|
1278
|
+
const hashed_webhook_settings = this.server.hash(webhook_settings);
|
|
1220
1279
|
const register_webhook = async () => {
|
|
1221
|
-
log(0, "Registering payments webhook.");
|
|
1280
|
+
this.server.log(0, "Registering payments webhook.");
|
|
1222
1281
|
const response = await this._req("POST", "/notification-settings", webhook_settings);
|
|
1223
1282
|
this.webhook_key = response.data.endpoint_secret_key;
|
|
1224
|
-
await this.
|
|
1283
|
+
await this._webhook_conf_db.set({ production: this.server.production, version: 1 }, {
|
|
1225
1284
|
id: response.data.id,
|
|
1226
|
-
key: this.webhook_key
|
|
1285
|
+
key: this.webhook_key,
|
|
1286
|
+
hash: this.server.hash(webhook_settings)
|
|
1227
1287
|
});
|
|
1228
1288
|
};
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
if (
|
|
1250
|
-
|
|
1289
|
+
const home_dir = vlib.Path.home().join(".volt/cache");
|
|
1290
|
+
if (!home_dir.exists()) {
|
|
1291
|
+
home_dir.mkdir({ recursive: true });
|
|
1292
|
+
}
|
|
1293
|
+
const cached_local_hash_file = home_dir.join(`paddle_webhook_${this.server.production ? "live" : "sandbox"}.hash`);
|
|
1294
|
+
const cached_local_hash = cached_local_hash_file.exists() ? await cached_local_hash_file.load() : null;
|
|
1295
|
+
if (cached_local_hash !== hashed_webhook_settings) {
|
|
1296
|
+
const webhook_doc = await this._webhook_conf_db.load({ production: this.server.production, version: 1 }, { throw: false });
|
|
1297
|
+
if (webhook_doc instanceof Error && !(webhook_doc instanceof import_collection.Collection.NotFoundError)) {
|
|
1298
|
+
throw webhook_doc;
|
|
1299
|
+
}
|
|
1300
|
+
if (!(webhook_doc instanceof import_collection.Collection.NotFoundError)) {
|
|
1301
|
+
this.webhook_key = webhook_doc.key;
|
|
1302
|
+
if (webhook_doc.hash !== hashed_webhook_settings) {
|
|
1303
|
+
this.server.log(0, `Checking payments webhook.`);
|
|
1304
|
+
const webhook_id = webhook_doc.id;
|
|
1305
|
+
let registered;
|
|
1306
|
+
try {
|
|
1307
|
+
registered = await this._req("GET", `/notification-settings/${webhook_id}`);
|
|
1308
|
+
} catch (error) {
|
|
1309
|
+
if (error.status === 404 || error.status_code === 404) {
|
|
1310
|
+
registered = void 0;
|
|
1311
|
+
await register_webhook();
|
|
1312
|
+
} else {
|
|
1313
|
+
throw error;
|
|
1251
1314
|
}
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1315
|
+
}
|
|
1316
|
+
if (registered) {
|
|
1317
|
+
const item = registered.data;
|
|
1318
|
+
const patch = (() => {
|
|
1319
|
+
if (item.active !== true || item.destination !== webhook_settings.destination || item.type !== webhook_settings.type || item.description !== webhook_settings.description || item.subscribed_events.length != webhook_settings.subscribed_events.length) {
|
|
1320
|
+
return true;
|
|
1321
|
+
}
|
|
1322
|
+
return webhook_settings.subscribed_events.iterate((x) => {
|
|
1323
|
+
const found = item.subscribed_events.iterate((y) => {
|
|
1324
|
+
if (x === y.name) {
|
|
1325
|
+
return true;
|
|
1326
|
+
}
|
|
1327
|
+
});
|
|
1328
|
+
if (found === false) {
|
|
1255
1329
|
return true;
|
|
1256
1330
|
}
|
|
1257
1331
|
});
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
log(0, "Updating payments webhook.");
|
|
1265
|
-
await this._req("PATCH", `/notification-settings/${webhook_id}`, { ...webhook_settings, active: true });
|
|
1332
|
+
})();
|
|
1333
|
+
if (patch === true) {
|
|
1334
|
+
this.server.log(0, "Updating payments webhook.");
|
|
1335
|
+
await this._req("PATCH", `/notification-settings/${webhook_id}`, { ...webhook_settings, active: true });
|
|
1336
|
+
}
|
|
1337
|
+
await this._webhook_conf_db.set({ production: this.server.production, version: 1 }, { hash: this.server.hash(webhook_settings) });
|
|
1266
1338
|
}
|
|
1267
|
-
await this._settings_db.save(`last_webhook${this.server.production ? "" : "_demo"}`, this.server.hash(webhook_settings));
|
|
1268
1339
|
}
|
|
1340
|
+
} else {
|
|
1341
|
+
await register_webhook();
|
|
1269
1342
|
}
|
|
1270
|
-
|
|
1271
|
-
await register_webhook();
|
|
1343
|
+
await cached_local_hash_file.save(hashed_webhook_settings);
|
|
1272
1344
|
}
|
|
1273
1345
|
const ip_whitelist = [
|
|
1274
1346
|
// Live.
|
|
@@ -1286,19 +1358,20 @@ class Paddle {
|
|
|
1286
1358
|
"44.241.183.62",
|
|
1287
1359
|
"100.20.172.113"
|
|
1288
1360
|
];
|
|
1361
|
+
this.server.performance.end("create-payments-webhook", now);
|
|
1289
1362
|
return {
|
|
1290
1363
|
method: "POST",
|
|
1291
|
-
endpoint: "/volt/payments/webhook",
|
|
1364
|
+
endpoint: "/volt/api/v1/payments/webhook",
|
|
1292
1365
|
content_type: "application/json",
|
|
1293
1366
|
rate_limit: void 0,
|
|
1294
1367
|
callback: async (stream) => {
|
|
1295
1368
|
if (ip_whitelist.includes(stream.ip) === false) {
|
|
1296
|
-
log(0, `POST:/volt/payments/webhook: Warning: Blocking non whitelisted ip "${stream.ip}".`);
|
|
1369
|
+
this.server.log(0, `POST:/volt/payments/webhook: Warning: Blocking non whitelisted ip "${stream.ip}".`);
|
|
1297
1370
|
return stream.error({ status: import_status.Status.unauthorized });
|
|
1298
1371
|
}
|
|
1299
1372
|
const full_signature = stream.headers["paddle-signature"];
|
|
1300
1373
|
if (full_signature == null) {
|
|
1301
|
-
log(0, "POST:/volt/payments/webhook: Error: No paddle signature found in the request headers.");
|
|
1374
|
+
this.server.log(0, "POST:/volt/payments/webhook: Error: No paddle signature found in the request headers.");
|
|
1302
1375
|
return stream.error({ status: import_status.Status.unauthorized, data: { error: "Webhook signature verification failed." } });
|
|
1303
1376
|
}
|
|
1304
1377
|
const ts_index = full_signature.indexOf(";");
|
|
@@ -1306,7 +1379,7 @@ class Paddle {
|
|
|
1306
1379
|
const signature = full_signature.substr(ts_index + 4);
|
|
1307
1380
|
const digest = libcrypto.createHmac("sha256", this.webhook_key).update(`${ts}:${stream.body}`).digest("hex");
|
|
1308
1381
|
if (libcrypto.timingSafeEqual(Buffer.from(digest, "hex"), Buffer.from(signature, "hex")) !== true) {
|
|
1309
|
-
log(0, "POST:/volt/payments/webhook: Error: Webhook signature verification failed.");
|
|
1382
|
+
this.server.log(0, "POST:/volt/payments/webhook: Error: Webhook signature verification failed.");
|
|
1310
1383
|
return stream.error({ status: import_status.Status.unauthorized, data: { error: "Webhook signature verification failed." } });
|
|
1311
1384
|
}
|
|
1312
1385
|
const event = JSON.parse(stream.body);
|
|
@@ -1365,7 +1438,6 @@ class Paddle {
|
|
|
1365
1438
|
}
|
|
1366
1439
|
return product;
|
|
1367
1440
|
}
|
|
1368
|
-
// Get a payment by id.
|
|
1369
1441
|
/* @docs:
|
|
1370
1442
|
@title: Get Payment.
|
|
1371
1443
|
@desc: Get a payment by id.
|
|
@@ -1375,10 +1447,12 @@ class Paddle {
|
|
|
1375
1447
|
@type: string
|
|
1376
1448
|
@desc: The id of the payment.
|
|
1377
1449
|
*/
|
|
1378
|
-
async get_payment(id) {
|
|
1450
|
+
async get_payment(id, opts) {
|
|
1451
|
+
if (opts?.for_public) {
|
|
1452
|
+
return await this._load_payment_for_public(id);
|
|
1453
|
+
}
|
|
1379
1454
|
return await this._load_payment(id);
|
|
1380
1455
|
}
|
|
1381
|
-
// Get payments.
|
|
1382
1456
|
/* @docs:
|
|
1383
1457
|
@title: Get Refunded Payments.
|
|
1384
1458
|
@desc:
|
|
@@ -1407,30 +1481,24 @@ class Paddle {
|
|
|
1407
1481
|
@value: "paid"
|
|
1408
1482
|
@desc: Payments that are paid.
|
|
1409
1483
|
*/
|
|
1410
|
-
async get_payments({ uid, days = 30, limit =
|
|
1411
|
-
const
|
|
1412
|
-
|
|
1484
|
+
async get_payments({ uid, days = 30, limit = 1e4, status = void 0, for_public }) {
|
|
1485
|
+
const query = {
|
|
1486
|
+
uid
|
|
1487
|
+
};
|
|
1413
1488
|
if (days != null) {
|
|
1414
|
-
since = /* @__PURE__ */ new Date();
|
|
1489
|
+
const since = /* @__PURE__ */ new Date();
|
|
1415
1490
|
since.setHours(0, 0, 0, 0);
|
|
1416
|
-
|
|
1491
|
+
query.timestamp = { $gte: Math.floor(since.getTime() - 3600 * 24 * 1e3 * days) };
|
|
1417
1492
|
}
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
}
|
|
1425
|
-
}
|
|
1426
|
-
if (limit != null && limit != -1 && payments.length >= limit) {
|
|
1427
|
-
return false;
|
|
1428
|
-
}
|
|
1429
|
-
});
|
|
1493
|
+
if (Array.isArray(status)) {
|
|
1494
|
+
query.status = { $in: status };
|
|
1495
|
+
} else if (typeof status === "string") {
|
|
1496
|
+
query.status = status;
|
|
1497
|
+
}
|
|
1498
|
+
const payments = await this._pay_db.list(query, { limit });
|
|
1430
1499
|
payments.sort((a, b) => b.timestamp - a.timestamp);
|
|
1431
|
-
return payments;
|
|
1500
|
+
return for_public ? payments.map((p) => Payment.anonymize(p)) : payments;
|
|
1432
1501
|
}
|
|
1433
|
-
// Get all refundable payments.
|
|
1434
1502
|
/* @docs:
|
|
1435
1503
|
@title: Get Refundable Payments.
|
|
1436
1504
|
@desc: Get all payments that are refundable.
|
|
@@ -1446,24 +1514,17 @@ class Paddle {
|
|
|
1446
1514
|
@type: number
|
|
1447
1515
|
@desc: Limit the amount of response payment objects.
|
|
1448
1516
|
*/
|
|
1449
|
-
async get_refundable_payments({ uid, days = 30, limit = void 0 }) {
|
|
1450
|
-
const
|
|
1451
|
-
const all_payments = await this.get_payments({ uid, days, limit, status: "paid" });
|
|
1452
|
-
all_payments.iterate((
|
|
1453
|
-
const
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
line_items.push(item);
|
|
1457
|
-
}
|
|
1458
|
-
});
|
|
1459
|
-
if (line_items.length > 0) {
|
|
1460
|
-
payment.line_items = line_items;
|
|
1461
|
-
payments.push(payment);
|
|
1517
|
+
async get_refundable_payments({ uid, days = 30, limit = void 0, for_public }) {
|
|
1518
|
+
const out = [];
|
|
1519
|
+
const all_payments = await this.get_payments({ uid, days, limit, status: "paid", for_public });
|
|
1520
|
+
all_payments.iterate((pmt) => {
|
|
1521
|
+
const refundable = pmt.line_items.filter((li) => li.status === "paid" && li.total > 0);
|
|
1522
|
+
if (refundable.length > 0) {
|
|
1523
|
+
out.push({ ...pmt, line_items: refundable });
|
|
1462
1524
|
}
|
|
1463
1525
|
});
|
|
1464
|
-
return
|
|
1526
|
+
return out;
|
|
1465
1527
|
}
|
|
1466
|
-
// Get all refunded payments.
|
|
1467
1528
|
/* @docs:
|
|
1468
1529
|
@title: Get Refunded Payments.
|
|
1469
1530
|
@desc: Get all payments that are successfully refunded.
|
|
@@ -1479,24 +1540,17 @@ class Paddle {
|
|
|
1479
1540
|
@type: number
|
|
1480
1541
|
@desc: Limit the amount of response payment objects.
|
|
1481
1542
|
*/
|
|
1482
|
-
async get_refunded_payments({ uid, days = 30, limit = void 0 }) {
|
|
1483
|
-
const
|
|
1484
|
-
const all_payments = await this.get_payments({ uid, days, limit, status: "paid" });
|
|
1485
|
-
all_payments.iterate((
|
|
1486
|
-
const
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
line_items.push(item);
|
|
1490
|
-
}
|
|
1491
|
-
});
|
|
1492
|
-
if (line_items.length > 0) {
|
|
1493
|
-
payment.line_items = line_items;
|
|
1494
|
-
payments.push(payment);
|
|
1543
|
+
async get_refunded_payments({ uid, days = 30, limit = void 0, for_public }) {
|
|
1544
|
+
const out = [];
|
|
1545
|
+
const all_payments = await this.get_payments({ uid, days, limit, status: "paid", for_public });
|
|
1546
|
+
all_payments.iterate((pmt) => {
|
|
1547
|
+
const refundable = pmt.line_items.filter((li) => li.status === "refunded" && li.total > 0);
|
|
1548
|
+
if (refundable.length > 0) {
|
|
1549
|
+
out.push({ ...pmt, line_items: refundable });
|
|
1495
1550
|
}
|
|
1496
1551
|
});
|
|
1497
|
-
return
|
|
1552
|
+
return out;
|
|
1498
1553
|
}
|
|
1499
|
-
// Get all payments that are currently in the refunding process.
|
|
1500
1554
|
/* @docs:
|
|
1501
1555
|
@title: Get Refunding Payments.
|
|
1502
1556
|
@desc: Get all payments that are currently in the refunding process.
|
|
@@ -1512,24 +1566,17 @@ class Paddle {
|
|
|
1512
1566
|
@type: number
|
|
1513
1567
|
@desc: Limit the amount of response payment objects.
|
|
1514
1568
|
*/
|
|
1515
|
-
async get_refunding_payments({ uid, days = void 0, limit = void 0 }) {
|
|
1516
|
-
const
|
|
1517
|
-
const all_payments = await this.get_payments({ uid, days, limit, status: "paid" });
|
|
1518
|
-
all_payments.iterate((
|
|
1519
|
-
const
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
line_items.push(item);
|
|
1523
|
-
}
|
|
1524
|
-
});
|
|
1525
|
-
if (line_items.length > 0) {
|
|
1526
|
-
payment.line_items = line_items;
|
|
1527
|
-
payments.push(payment);
|
|
1569
|
+
async get_refunding_payments({ uid, days = void 0, limit = void 0, for_public }) {
|
|
1570
|
+
const out = [];
|
|
1571
|
+
const all_payments = await this.get_payments({ uid, days, limit, status: "paid", for_public });
|
|
1572
|
+
all_payments.iterate((pmt) => {
|
|
1573
|
+
const refundable = pmt.line_items.filter((li) => li.status === "refunding" && li.total > 0);
|
|
1574
|
+
if (refundable.length > 0) {
|
|
1575
|
+
out.push({ ...pmt, line_items: refundable });
|
|
1528
1576
|
}
|
|
1529
1577
|
});
|
|
1530
|
-
return
|
|
1578
|
+
return out;
|
|
1531
1579
|
}
|
|
1532
|
-
// Refund a payment.
|
|
1533
1580
|
/* @docs:
|
|
1534
1581
|
@title: Refund Payment.
|
|
1535
1582
|
@desc: Refund a payment based on the payment id.
|
|
@@ -1602,7 +1649,6 @@ class Paddle {
|
|
|
1602
1649
|
}
|
|
1603
1650
|
await this._save_payment(payment);
|
|
1604
1651
|
}
|
|
1605
|
-
// Cancel a subscription.
|
|
1606
1652
|
/* @docs:
|
|
1607
1653
|
@title: Cancel Subscription.
|
|
1608
1654
|
@desc: Cancel a subscription based on the retrieved payment object or id.
|
|
@@ -1636,14 +1682,13 @@ class Paddle {
|
|
|
1636
1682
|
}
|
|
1637
1683
|
;
|
|
1638
1684
|
if (_throw_no_cancelled_err && cancelled.length === 0) {
|
|
1639
|
-
throw new
|
|
1685
|
+
throw new import_errors.ExternalError({
|
|
1640
1686
|
type: "NoCancellableSubscriptions",
|
|
1641
1687
|
message: "No cancellable subscriptions found.",
|
|
1642
1688
|
status: import_status.Status.bad_request
|
|
1643
1689
|
});
|
|
1644
1690
|
}
|
|
1645
1691
|
}
|
|
1646
|
-
// Cancel subscription by subscription id.
|
|
1647
1692
|
/* @docs:
|
|
1648
1693
|
@title: Cancel subscription by subscription id.
|
|
1649
1694
|
@desc: Cancel a subscription based on the retrieved subscription object or id.
|
|
@@ -1664,7 +1709,6 @@ class Paddle {
|
|
|
1664
1709
|
}
|
|
1665
1710
|
return await this._cancel_subscription(subscription, immediate);
|
|
1666
1711
|
}
|
|
1667
|
-
// Get subscriptioms.
|
|
1668
1712
|
/* @docs:
|
|
1669
1713
|
@title: Get active subscriptions
|
|
1670
1714
|
@desc: Get the active subscriptions of a user.
|
|
@@ -1685,7 +1729,6 @@ class Paddle {
|
|
|
1685
1729
|
async get_subscriptions(uid) {
|
|
1686
1730
|
return await this._get_subscriptions(uid);
|
|
1687
1731
|
}
|
|
1688
|
-
// Is subscribed.
|
|
1689
1732
|
/* @docs:
|
|
1690
1733
|
@title: Is Subscribed
|
|
1691
1734
|
@desc: Check if a user is subscribed to a product.
|
|
@@ -1701,7 +1744,6 @@ class Paddle {
|
|
|
1701
1744
|
async is_subscribed(uid, product) {
|
|
1702
1745
|
return await this._check_subscription(uid, product, false);
|
|
1703
1746
|
}
|
|
1704
|
-
// Generate an invoice.
|
|
1705
1747
|
/* @docs:
|
|
1706
1748
|
@title: Generate Invoice
|
|
1707
1749
|
@desc:
|
|
@@ -1882,16 +1924,12 @@ class Paddle {
|
|
|
1882
1924
|
doc.font("Helvetica-Bold");
|
|
1883
1925
|
gen_line_item({ unit_cost: "Total Due:", total_cost: `${currency} ${total_due.toFixed(2)}` });
|
|
1884
1926
|
top_offset -= spacing - 3;
|
|
1885
|
-
const
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
});
|
|
1892
|
-
stream.on("error", (error2) => {
|
|
1893
|
-
reject(error2);
|
|
1894
|
-
});
|
|
1927
|
+
const chunks = [];
|
|
1928
|
+
return await new Promise((resolve, reject) => {
|
|
1929
|
+
doc.on("data", (chunk) => chunks.push(chunk));
|
|
1930
|
+
doc.on("end", () => resolve(Buffer.concat(chunks)));
|
|
1931
|
+
doc.on("error", (err) => reject(err));
|
|
1932
|
+
doc.end();
|
|
1895
1933
|
});
|
|
1896
1934
|
}
|
|
1897
1935
|
// ---------------------------------------------------------
|
|
@@ -1912,7 +1950,7 @@ class Paddle {
|
|
|
1912
1950
|
}
|
|
1913
1951
|
for (const sub of subs) {
|
|
1914
1952
|
if (sub.status === "active") {
|
|
1915
|
-
|
|
1953
|
+
this.server.log("Cancelling subscription ", sub.id);
|
|
1916
1954
|
await this._req("POST", `/subscriptions/${sub.id}/cancel`, {
|
|
1917
1955
|
effective_from: "immediately"
|
|
1918
1956
|
});
|
|
@@ -1920,8 +1958,20 @@ class Paddle {
|
|
|
1920
1958
|
}
|
|
1921
1959
|
}
|
|
1922
1960
|
}
|
|
1923
|
-
|
|
1961
|
+
(function(Paddle2) {
|
|
1962
|
+
class RequestError extends Error {
|
|
1963
|
+
status_code;
|
|
1964
|
+
constructor(err, status_code) {
|
|
1965
|
+
super(err);
|
|
1966
|
+
this.status_code = status_code;
|
|
1967
|
+
}
|
|
1968
|
+
}
|
|
1969
|
+
Paddle2.RequestError = RequestError;
|
|
1970
|
+
})(Paddle || (Paddle = {}));
|
|
1924
1971
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1925
1972
|
0 && (module.exports = {
|
|
1926
|
-
|
|
1973
|
+
LineItem,
|
|
1974
|
+
Paddle,
|
|
1975
|
+
Payment,
|
|
1976
|
+
PaymentStatusValues
|
|
1927
1977
|
});
|