@stigg/typescript 0.1.0-alpha.2 → 0.1.0-alpha.21
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/CHANGELOG.md +270 -0
- package/README.md +9 -0
- package/client.d.mts +7 -9
- package/client.d.mts.map +1 -1
- package/client.d.ts +7 -9
- package/client.d.ts.map +1 -1
- package/client.js +29 -26
- package/client.js.map +1 -1
- package/client.mjs +30 -27
- package/client.mjs.map +1 -1
- package/internal/parse.d.mts.map +1 -1
- package/internal/parse.d.ts.map +1 -1
- package/internal/parse.js +5 -0
- package/internal/parse.js.map +1 -1
- package/internal/parse.mjs +5 -0
- package/internal/parse.mjs.map +1 -1
- package/internal/qs/formats.d.mts +7 -0
- package/internal/qs/formats.d.mts.map +1 -0
- package/internal/qs/formats.d.ts +7 -0
- package/internal/qs/formats.d.ts.map +1 -0
- package/internal/qs/formats.js +13 -0
- package/internal/qs/formats.js.map +1 -0
- package/internal/qs/formats.mjs +9 -0
- package/internal/qs/formats.mjs.map +1 -0
- package/internal/qs/index.d.mts +10 -0
- package/internal/qs/index.d.mts.map +1 -0
- package/internal/qs/index.d.ts +10 -0
- package/internal/qs/index.d.ts.map +1 -0
- package/internal/qs/index.js +14 -0
- package/internal/qs/index.js.map +1 -0
- package/internal/qs/index.mjs +10 -0
- package/internal/qs/index.mjs.map +1 -0
- package/internal/qs/stringify.d.mts +3 -0
- package/internal/qs/stringify.d.mts.map +1 -0
- package/internal/qs/stringify.d.ts +3 -0
- package/internal/qs/stringify.d.ts.map +1 -0
- package/internal/qs/stringify.js +277 -0
- package/internal/qs/stringify.js.map +1 -0
- package/internal/qs/stringify.mjs +274 -0
- package/internal/qs/stringify.mjs.map +1 -0
- package/internal/qs/types.d.mts +57 -0
- package/internal/qs/types.d.mts.map +1 -0
- package/internal/qs/types.d.ts +57 -0
- package/internal/qs/types.d.ts.map +1 -0
- package/internal/qs/types.js +3 -0
- package/internal/qs/types.js.map +1 -0
- package/internal/qs/types.mjs +2 -0
- package/internal/qs/types.mjs.map +1 -0
- package/internal/qs/utils.d.mts +15 -0
- package/internal/qs/utils.d.mts.map +1 -0
- package/internal/qs/utils.d.ts +15 -0
- package/internal/qs/utils.d.ts.map +1 -0
- package/internal/qs/utils.js +230 -0
- package/internal/qs/utils.js.map +1 -0
- package/internal/qs/utils.mjs +217 -0
- package/internal/qs/utils.mjs.map +1 -0
- package/internal/tslib.js +17 -17
- package/internal/utils/query.d.mts +2 -0
- package/internal/utils/query.d.mts.map +1 -0
- package/internal/utils/query.d.ts +2 -0
- package/internal/utils/query.d.ts.map +1 -0
- package/internal/utils/query.js +10 -0
- package/internal/utils/query.js.map +1 -0
- package/internal/utils/query.mjs +6 -0
- package/internal/utils/query.mjs.map +1 -0
- package/internal/utils.d.mts +1 -0
- package/internal/utils.d.ts +1 -0
- package/internal/utils.js +1 -0
- package/internal/utils.js.map +1 -1
- package/internal/utils.mjs +1 -0
- package/package.json +12 -1
- package/resources/index.d.mts +1 -1
- package/resources/index.d.mts.map +1 -1
- package/resources/index.d.ts +1 -1
- package/resources/index.d.ts.map +1 -1
- package/resources/index.js.map +1 -1
- package/resources/index.mjs +1 -1
- package/resources/index.mjs.map +1 -1
- package/resources/v1/addons/addons.d.mts +1305 -0
- package/resources/v1/addons/addons.d.mts.map +1 -0
- package/resources/v1/addons/addons.d.ts +1305 -0
- package/resources/v1/addons/addons.d.ts.map +1 -0
- package/resources/v1/addons/addons.js +81 -0
- package/resources/v1/addons/addons.js.map +1 -0
- package/resources/v1/addons/addons.mjs +76 -0
- package/resources/v1/addons/addons.mjs.map +1 -0
- package/resources/v1/addons/entitlements.d.mts +860 -0
- package/resources/v1/addons/entitlements.d.mts.map +1 -0
- package/resources/v1/addons/entitlements.d.ts +860 -0
- package/resources/v1/addons/entitlements.d.ts.map +1 -0
- package/resources/v1/addons/entitlements.js +36 -0
- package/resources/v1/addons/entitlements.js.map +1 -0
- package/resources/v1/addons/entitlements.mjs +32 -0
- package/resources/v1/addons/entitlements.mjs.map +1 -0
- package/resources/v1/addons/index.d.mts +3 -0
- package/resources/v1/addons/index.d.mts.map +1 -0
- package/resources/v1/addons/index.d.ts +3 -0
- package/resources/v1/addons/index.d.ts.map +1 -0
- package/resources/v1/addons/index.js +9 -0
- package/resources/v1/addons/index.js.map +1 -0
- package/resources/v1/addons/index.mjs +4 -0
- package/resources/v1/addons/index.mjs.map +1 -0
- package/resources/v1/addons.d.mts +2 -0
- package/resources/v1/addons.d.mts.map +1 -0
- package/resources/v1/addons.d.ts +2 -0
- package/resources/v1/addons.d.ts.map +1 -0
- package/resources/v1/addons.js +6 -0
- package/resources/v1/addons.js.map +1 -0
- package/resources/v1/addons.mjs +3 -0
- package/resources/v1/addons.mjs.map +1 -0
- package/resources/v1/coupons.d.mts +113 -82
- package/resources/v1/coupons.d.mts.map +1 -1
- package/resources/v1/coupons.d.ts +113 -82
- package/resources/v1/coupons.d.ts.map +1 -1
- package/resources/v1/coupons.js +19 -3
- package/resources/v1/coupons.js.map +1 -1
- package/resources/v1/coupons.mjs +19 -3
- package/resources/v1/coupons.mjs.map +1 -1
- package/resources/v1/customers/customers.d.mts +221 -45
- package/resources/v1/customers/customers.d.mts.map +1 -1
- package/resources/v1/customers/customers.d.ts +221 -45
- package/resources/v1/customers/customers.d.ts.map +1 -1
- package/resources/v1/customers/customers.js +32 -15
- package/resources/v1/customers/customers.js.map +1 -1
- package/resources/v1/customers/customers.mjs +32 -15
- package/resources/v1/customers/customers.mjs.map +1 -1
- package/resources/v1/customers/index.d.mts +2 -2
- package/resources/v1/customers/index.d.mts.map +1 -1
- package/resources/v1/customers/index.d.ts +2 -2
- package/resources/v1/customers/index.d.ts.map +1 -1
- package/resources/v1/customers/index.js +3 -3
- package/resources/v1/customers/index.js.map +1 -1
- package/resources/v1/customers/index.mjs +1 -1
- package/resources/v1/customers/index.mjs.map +1 -1
- package/resources/v1/customers/payment-method.d.mts +10 -2
- package/resources/v1/customers/payment-method.d.mts.map +1 -1
- package/resources/v1/customers/payment-method.d.ts +10 -2
- package/resources/v1/customers/payment-method.d.ts.map +1 -1
- package/resources/v1/customers/payment-method.js +7 -2
- package/resources/v1/customers/payment-method.js.map +1 -1
- package/resources/v1/customers/payment-method.mjs +7 -2
- package/resources/v1/customers/payment-method.mjs.map +1 -1
- package/resources/v1/customers/promotional-entitlements.d.mts +501 -0
- package/resources/v1/customers/promotional-entitlements.d.mts.map +1 -0
- package/resources/v1/customers/promotional-entitlements.d.ts +501 -0
- package/resources/v1/customers/promotional-entitlements.d.ts.map +1 -0
- package/resources/v1/customers/promotional-entitlements.js +35 -0
- package/resources/v1/customers/promotional-entitlements.js.map +1 -0
- package/resources/v1/customers/promotional-entitlements.mjs +31 -0
- package/resources/v1/customers/promotional-entitlements.mjs.map +1 -0
- package/resources/v1/events/credits/credits.d.mts +260 -0
- package/resources/v1/events/credits/credits.d.mts.map +1 -0
- package/resources/v1/events/credits/credits.d.ts +260 -0
- package/resources/v1/events/credits/credits.d.ts.map +1 -0
- package/resources/v1/events/credits/credits.js +41 -0
- package/resources/v1/events/credits/credits.js.map +1 -0
- package/resources/v1/events/credits/credits.mjs +36 -0
- package/resources/v1/events/credits/credits.mjs.map +1 -0
- package/resources/v1/events/credits/grants.d.mts +549 -0
- package/resources/v1/events/credits/grants.d.mts.map +1 -0
- package/resources/v1/events/credits/grants.d.ts +549 -0
- package/resources/v1/events/credits/grants.d.ts.map +1 -0
- package/resources/v1/events/credits/grants.js +37 -0
- package/resources/v1/events/credits/grants.js.map +1 -0
- package/resources/v1/events/credits/grants.mjs +33 -0
- package/resources/v1/events/credits/grants.mjs.map +1 -0
- package/resources/v1/events/credits/index.d.mts +3 -0
- package/resources/v1/events/credits/index.d.mts.map +1 -0
- package/resources/v1/events/credits/index.d.ts +3 -0
- package/resources/v1/events/credits/index.d.ts.map +1 -0
- package/resources/v1/events/credits/index.js +9 -0
- package/resources/v1/events/credits/index.js.map +1 -0
- package/resources/v1/events/credits/index.mjs +4 -0
- package/resources/v1/events/credits/index.mjs.map +1 -0
- package/resources/v1/events/credits.d.mts +2 -0
- package/resources/v1/events/credits.d.mts.map +1 -0
- package/resources/v1/events/credits.d.ts +2 -0
- package/resources/v1/events/credits.d.ts.map +1 -0
- package/resources/v1/events/credits.js +6 -0
- package/resources/v1/events/credits.js.map +1 -0
- package/resources/v1/events/credits.mjs +3 -0
- package/resources/v1/events/credits.mjs.map +1 -0
- package/resources/v1/events/events.d.mts +70 -0
- package/resources/v1/events/events.d.mts.map +1 -0
- package/resources/v1/events/events.d.ts +70 -0
- package/resources/v1/events/events.d.ts.map +1 -0
- package/resources/v1/events/events.js +27 -0
- package/resources/v1/events/events.js.map +1 -0
- package/resources/v1/events/events.mjs +22 -0
- package/resources/v1/events/events.mjs.map +1 -0
- package/resources/v1/events/index.d.mts +3 -0
- package/resources/v1/events/index.d.mts.map +1 -0
- package/resources/v1/events/index.d.ts +3 -0
- package/resources/v1/events/index.d.ts.map +1 -0
- package/resources/v1/events/index.js +9 -0
- package/resources/v1/events/index.js.map +1 -0
- package/resources/v1/events/index.mjs +4 -0
- package/resources/v1/events/index.mjs.map +1 -0
- package/resources/v1/events.d.mts +2 -0
- package/resources/v1/events.d.mts.map +1 -0
- package/resources/v1/events.d.ts +2 -0
- package/resources/v1/events.d.ts.map +1 -0
- package/resources/v1/events.js +6 -0
- package/resources/v1/events.js.map +1 -0
- package/resources/v1/events.mjs +3 -0
- package/resources/v1/events.mjs.map +1 -0
- package/resources/v1/features.d.mts +447 -0
- package/resources/v1/features.d.mts.map +1 -0
- package/resources/v1/features.d.ts +447 -0
- package/resources/v1/features.d.ts.map +1 -0
- package/resources/v1/features.js +54 -0
- package/resources/v1/features.js.map +1 -0
- package/resources/v1/features.mjs +50 -0
- package/resources/v1/features.mjs.map +1 -0
- package/resources/v1/index.d.mts +10 -4
- package/resources/v1/index.d.mts.map +1 -1
- package/resources/v1/index.d.ts +10 -4
- package/resources/v1/index.d.ts.map +1 -1
- package/resources/v1/index.js +17 -5
- package/resources/v1/index.js.map +1 -1
- package/resources/v1/index.mjs +7 -1
- package/resources/v1/index.mjs.map +1 -1
- package/resources/v1/plans/entitlements.d.mts +860 -0
- package/resources/v1/plans/entitlements.d.mts.map +1 -0
- package/resources/v1/plans/entitlements.d.ts +860 -0
- package/resources/v1/plans/entitlements.d.ts.map +1 -0
- package/resources/v1/plans/entitlements.js +36 -0
- package/resources/v1/plans/entitlements.js.map +1 -0
- package/resources/v1/plans/entitlements.mjs +32 -0
- package/resources/v1/plans/entitlements.mjs.map +1 -0
- package/resources/v1/plans/index.d.mts +3 -0
- package/resources/v1/plans/index.d.mts.map +1 -0
- package/resources/v1/plans/index.d.ts +3 -0
- package/resources/v1/plans/index.d.ts.map +1 -0
- package/resources/v1/plans/index.js +9 -0
- package/resources/v1/plans/index.js.map +1 -0
- package/resources/v1/plans/index.mjs +4 -0
- package/resources/v1/plans/index.mjs.map +1 -0
- package/resources/v1/plans/plans.d.mts +976 -0
- package/resources/v1/plans/plans.d.mts.map +1 -0
- package/resources/v1/plans/plans.d.ts +976 -0
- package/resources/v1/plans/plans.d.ts.map +1 -0
- package/resources/v1/plans/plans.js +79 -0
- package/resources/v1/plans/plans.js.map +1 -0
- package/resources/v1/plans/plans.mjs +74 -0
- package/resources/v1/plans/plans.mjs.map +1 -0
- package/resources/v1/plans.d.mts +2 -0
- package/resources/v1/plans.d.mts.map +1 -0
- package/resources/v1/plans.d.ts +2 -0
- package/resources/v1/plans.d.ts.map +1 -0
- package/resources/v1/plans.js +6 -0
- package/resources/v1/plans.js.map +1 -0
- package/resources/v1/plans.mjs +3 -0
- package/resources/v1/plans.mjs.map +1 -0
- package/resources/v1/products.d.mts +335 -0
- package/resources/v1/products.d.mts.map +1 -0
- package/resources/v1/products.d.ts +335 -0
- package/resources/v1/products.d.ts.map +1 -0
- package/resources/v1/products.js +55 -0
- package/resources/v1/products.js.map +1 -0
- package/resources/v1/products.mjs +51 -0
- package/resources/v1/products.mjs.map +1 -0
- package/resources/v1/subscriptions/future-update.d.mts +15 -19
- package/resources/v1/subscriptions/future-update.d.mts.map +1 -1
- package/resources/v1/subscriptions/future-update.d.ts +15 -19
- package/resources/v1/subscriptions/future-update.d.ts.map +1 -1
- package/resources/v1/subscriptions/future-update.js +6 -2
- package/resources/v1/subscriptions/future-update.js.map +1 -1
- package/resources/v1/subscriptions/future-update.mjs +6 -2
- package/resources/v1/subscriptions/future-update.mjs.map +1 -1
- package/resources/v1/subscriptions/index.d.mts +4 -2
- package/resources/v1/subscriptions/index.d.mts.map +1 -1
- package/resources/v1/subscriptions/index.d.ts +4 -2
- package/resources/v1/subscriptions/index.d.ts.map +1 -1
- package/resources/v1/subscriptions/index.js +5 -1
- package/resources/v1/subscriptions/index.js.map +1 -1
- package/resources/v1/subscriptions/index.mjs +3 -1
- package/resources/v1/subscriptions/index.mjs.map +1 -1
- package/resources/v1/subscriptions/invoice.d.mts +37 -0
- package/resources/v1/subscriptions/invoice.d.mts.map +1 -0
- package/resources/v1/subscriptions/invoice.d.ts +37 -0
- package/resources/v1/subscriptions/invoice.d.ts.map +1 -0
- package/resources/v1/subscriptions/invoice.js +20 -0
- package/resources/v1/subscriptions/invoice.js.map +1 -0
- package/resources/v1/subscriptions/invoice.mjs +16 -0
- package/resources/v1/subscriptions/invoice.mjs.map +1 -0
- package/resources/v1/subscriptions/subscriptions.d.mts +2547 -561
- package/resources/v1/subscriptions/subscriptions.d.mts.map +1 -1
- package/resources/v1/subscriptions/subscriptions.d.ts +2547 -561
- package/resources/v1/subscriptions/subscriptions.d.ts.map +1 -1
- package/resources/v1/subscriptions/subscriptions.js +47 -11
- package/resources/v1/subscriptions/subscriptions.js.map +1 -1
- package/resources/v1/subscriptions/subscriptions.mjs +49 -13
- package/resources/v1/subscriptions/subscriptions.mjs.map +1 -1
- package/resources/v1/subscriptions/usage.d.mts +101 -0
- package/resources/v1/subscriptions/usage.d.mts.map +1 -0
- package/resources/v1/subscriptions/usage.d.ts +101 -0
- package/resources/v1/subscriptions/usage.d.ts.map +1 -0
- package/resources/v1/subscriptions/usage.js +27 -0
- package/resources/v1/subscriptions/usage.js.map +1 -0
- package/resources/v1/subscriptions/usage.mjs +23 -0
- package/resources/v1/subscriptions/usage.mjs.map +1 -0
- package/resources/v1/usage.d.mts +238 -0
- package/resources/v1/usage.d.mts.map +1 -0
- package/resources/v1/usage.d.ts +238 -0
- package/resources/v1/usage.d.ts.map +1 -0
- package/resources/v1/usage.js +27 -0
- package/resources/v1/usage.js.map +1 -0
- package/resources/v1/usage.mjs +23 -0
- package/resources/v1/usage.mjs.map +1 -0
- package/resources/v1/v1.d.mts +30 -149
- package/resources/v1/v1.d.mts.map +1 -1
- package/resources/v1/v1.d.ts +30 -149
- package/resources/v1/v1.d.ts.map +1 -1
- package/resources/v1/v1.js +24 -12
- package/resources/v1/v1.js.map +1 -1
- package/resources/v1/v1.mjs +24 -12
- package/resources/v1/v1.mjs.map +1 -1
- package/src/client.ts +41 -47
- package/src/internal/parse.ts +6 -0
- package/src/internal/qs/LICENSE.md +13 -0
- package/src/internal/qs/README.md +3 -0
- package/src/internal/qs/formats.ts +10 -0
- package/src/internal/qs/index.ts +13 -0
- package/src/internal/qs/stringify.ts +385 -0
- package/src/internal/qs/types.ts +71 -0
- package/src/internal/qs/utils.ts +265 -0
- package/src/internal/utils/query.ts +7 -0
- package/src/internal/utils.ts +1 -0
- package/src/resources/index.ts +1 -7
- package/src/resources/v1/addons/addons.ts +3253 -0
- package/src/resources/v1/addons/entitlements.ts +1120 -0
- package/src/resources/v1/addons/index.ts +26 -0
- package/src/resources/v1/addons.ts +3 -0
- package/src/resources/v1/coupons.ts +126 -216
- package/src/resources/v1/customers/customers.ts +296 -61
- package/src/resources/v1/customers/index.ts +16 -2
- package/src/resources/v1/customers/payment-method.ts +10 -2
- package/src/resources/v1/customers/promotional-entitlements.ts +672 -0
- package/src/resources/v1/events/credits/credits.ts +356 -0
- package/src/resources/v1/events/credits/grants.ts +795 -0
- package/src/resources/v1/events/credits/index.ts +20 -0
- package/src/resources/v1/events/credits.ts +3 -0
- package/src/resources/v1/events/events.ts +103 -0
- package/src/resources/v1/events/index.ts +13 -0
- package/src/resources/v1/events.ts +3 -0
- package/src/resources/v1/features.ts +574 -0
- package/src/resources/v1/index.ts +70 -15
- package/src/resources/v1/plans/entitlements.ts +1112 -0
- package/src/resources/v1/plans/index.ts +24 -0
- package/src/resources/v1/plans/plans.ts +2035 -0
- package/src/resources/v1/plans.ts +3 -0
- package/src/resources/v1/products.ts +426 -0
- package/src/resources/v1/subscriptions/future-update.ts +15 -27
- package/src/resources/v1/subscriptions/index.ts +15 -11
- package/src/resources/v1/subscriptions/invoice.ts +45 -0
- package/src/resources/v1/subscriptions/subscriptions.ts +5836 -777
- package/src/resources/v1/subscriptions/usage.ts +129 -0
- package/src/resources/v1/usage.ts +293 -0
- package/src/resources/v1/v1.ts +168 -197
- package/src/version.ts +1 -1
- package/version.d.mts +1 -1
- package/version.d.mts.map +1 -1
- package/version.d.ts +1 -1
- package/version.d.ts.map +1 -1
- package/version.js +1 -1
- package/version.js.map +1 -1
- package/version.mjs +1 -1
- package/version.mjs.map +1 -1
- package/resources/v1/customers/usage.d.mts +0 -98
- package/resources/v1/customers/usage.d.mts.map +0 -1
- package/resources/v1/customers/usage.d.ts +0 -98
- package/resources/v1/customers/usage.d.ts.map +0 -1
- package/resources/v1/customers/usage.js +0 -20
- package/resources/v1/customers/usage.js.map +0 -1
- package/resources/v1/customers/usage.mjs +0 -16
- package/resources/v1/customers/usage.mjs.map +0 -1
- package/src/resources/v1/customers/usage.ts +0 -132
package/resources/v1/v1.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"v1.mjs","sourceRoot":"","sources":["../../src/resources/v1/v1.ts"],"names":[],"mappings":"AAAA,sFAAsF;OAE/E,EAAE,WAAW,EAAE;OACf,KAAK,UAAU;OACf,EAOL,OAAO,GACR;OACM,KAAK,YAAY;OACjB,
|
|
1
|
+
{"version":3,"file":"v1.mjs","sourceRoot":"","sources":["../../src/resources/v1/v1.ts"],"names":[],"mappings":"AAAA,sFAAsF;OAE/E,EAAE,WAAW,EAAE;OACf,KAAK,UAAU;OACf,EAOL,OAAO,GACR;OACM,KAAK,WAAW;OAChB,EAOL,QAAQ,GACT;OACM,KAAK,WAAW;OAChB,EAQL,QAAQ,GACT;OACM,KAAK,QAAQ;OACb,EACL,KAAK,GAKN;OACM,KAAK,SAAS;OACd,EAWL,MAAM,GAGP;OACM,KAAK,YAAY;OACjB,EAYL,SAAS,GACV;OACM,KAAK,SAAS;OACd,EAA0C,MAAM,EAAE;OAClD,KAAK,QAAQ;OACb,EAWL,KAAK,GACN;OACM,KAAK,gBAAgB;OACrB,EAgBL,aAAa,GACd;AAED,MAAM,OAAO,EAAG,SAAQ,WAAW;IAAnC;;QACE,cAAS,GAA2B,IAAI,YAAY,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC7E,kBAAa,GAAmC,IAAI,gBAAgB,CAAC,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACjG,YAAO,GAAuB,IAAI,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACnE,WAAM,GAAqB,IAAI,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC9D,aAAQ,GAAyB,IAAI,WAAW,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACxE,WAAM,GAAqB,IAAI,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC9D,UAAK,GAAmB,IAAI,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACzD,UAAK,GAAmB,IAAI,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACzD,aAAQ,GAAyB,IAAI,WAAW,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC1E,CAAC;CAAA;AAED,EAAE,CAAC,SAAS,GAAG,SAAS,CAAC;AACzB,EAAE,CAAC,aAAa,GAAG,aAAa,CAAC;AACjC,EAAE,CAAC,OAAO,GAAG,OAAO,CAAC;AACrB,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC;AACnB,EAAE,CAAC,QAAQ,GAAG,QAAQ,CAAC;AACvB,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC;AACnB,EAAE,CAAC,KAAK,GAAG,KAAK,CAAC;AACjB,EAAE,CAAC,KAAK,GAAG,KAAK,CAAC;AACjB,EAAE,CAAC,QAAQ,GAAG,QAAQ,CAAC"}
|
package/src/client.ts
CHANGED
|
@@ -11,6 +11,7 @@ import type { APIResponseProps } from './internal/parse';
|
|
|
11
11
|
import { getPlatformHeaders } from './internal/detect-platform';
|
|
12
12
|
import * as Shims from './internal/shims';
|
|
13
13
|
import * as Opts from './internal/request-options';
|
|
14
|
+
import { stringifyQuery } from './internal/utils/query';
|
|
14
15
|
import { VERSION } from './version';
|
|
15
16
|
import * as Errors from './core/error';
|
|
16
17
|
import * as Pagination from './core/pagination';
|
|
@@ -18,13 +19,7 @@ import { AbstractPage, type MyCursorIDPageParams, MyCursorIDPageResponse } from
|
|
|
18
19
|
import * as Uploads from './core/uploads';
|
|
19
20
|
import * as API from './resources/index';
|
|
20
21
|
import { APIPromise } from './core/api-promise';
|
|
21
|
-
import {
|
|
22
|
-
V1,
|
|
23
|
-
V1CreateEventParams,
|
|
24
|
-
V1CreateEventResponse,
|
|
25
|
-
V1CreateUsageParams,
|
|
26
|
-
V1CreateUsageResponse,
|
|
27
|
-
} from './resources/v1/v1';
|
|
22
|
+
import { V1 } from './resources/v1/v1';
|
|
28
23
|
import { type Fetch } from './internal/builtin-types';
|
|
29
24
|
import { HeadersLike, NullableHeaders, buildHeaders } from './internal/headers';
|
|
30
25
|
import { FinalRequestOptions, RequestOptions } from './internal/request-options';
|
|
@@ -135,7 +130,7 @@ export class Stigg {
|
|
|
135
130
|
* API Client for interfacing with the Stigg API.
|
|
136
131
|
*
|
|
137
132
|
* @param {string | undefined} [opts.apiKey=process.env['STIGG_API_KEY'] ?? undefined]
|
|
138
|
-
* @param {string} [opts.baseURL=process.env['STIGG_BASE_URL'] ?? https://api.
|
|
133
|
+
* @param {string} [opts.baseURL=process.env['STIGG_BASE_URL'] ?? https://api.stigg.io] - Override the default base URL for the API.
|
|
139
134
|
* @param {number} [opts.timeout=1 minute] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
|
|
140
135
|
* @param {MergedRequestInit} [opts.fetchOptions] - Additional `RequestInit` options to be passed to `fetch` calls.
|
|
141
136
|
* @param {Fetch} [opts.fetch] - Specify a custom `fetch` function implementation.
|
|
@@ -157,7 +152,7 @@ export class Stigg {
|
|
|
157
152
|
const options: ClientOptions = {
|
|
158
153
|
apiKey,
|
|
159
154
|
...opts,
|
|
160
|
-
baseURL: baseURL || `https://api.
|
|
155
|
+
baseURL: baseURL || `https://api.stigg.io`,
|
|
161
156
|
};
|
|
162
157
|
|
|
163
158
|
this.baseURL = options.baseURL!;
|
|
@@ -203,7 +198,7 @@ export class Stigg {
|
|
|
203
198
|
* Check whether the base URL is set to its default.
|
|
204
199
|
*/
|
|
205
200
|
#baseURLOverridden(): boolean {
|
|
206
|
-
return this.baseURL !== 'https://api.
|
|
201
|
+
return this.baseURL !== 'https://api.stigg.io';
|
|
207
202
|
}
|
|
208
203
|
|
|
209
204
|
protected defaultQuery(): Record<string, string | undefined> | undefined {
|
|
@@ -218,24 +213,8 @@ export class Stigg {
|
|
|
218
213
|
return buildHeaders([{ 'X-API-KEY': this.apiKey }]);
|
|
219
214
|
}
|
|
220
215
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
*/
|
|
224
|
-
protected stringifyQuery(query: Record<string, unknown>): string {
|
|
225
|
-
return Object.entries(query)
|
|
226
|
-
.filter(([_, value]) => typeof value !== 'undefined')
|
|
227
|
-
.map(([key, value]) => {
|
|
228
|
-
if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
|
|
229
|
-
return `${encodeURIComponent(key)}=${encodeURIComponent(value)}`;
|
|
230
|
-
}
|
|
231
|
-
if (value === null) {
|
|
232
|
-
return `${encodeURIComponent(key)}=`;
|
|
233
|
-
}
|
|
234
|
-
throw new Errors.StiggError(
|
|
235
|
-
`Cannot stringify type ${typeof value}; Expected string, number, boolean, or null. If you need to pass nested query parameters, you can manually encode them, e.g. { query: { 'foo[key1]': value1, 'foo[key2]': value2 } }, and please open a GitHub issue requesting better support for your use case.`,
|
|
236
|
-
);
|
|
237
|
-
})
|
|
238
|
-
.join('&');
|
|
216
|
+
protected stringifyQuery(query: object | Record<string, unknown>): string {
|
|
217
|
+
return stringifyQuery(query);
|
|
239
218
|
}
|
|
240
219
|
|
|
241
220
|
private getUserAgent(): string {
|
|
@@ -267,12 +246,13 @@ export class Stigg {
|
|
|
267
246
|
: new URL(baseURL + (baseURL.endsWith('/') && path.startsWith('/') ? path.slice(1) : path));
|
|
268
247
|
|
|
269
248
|
const defaultQuery = this.defaultQuery();
|
|
270
|
-
|
|
271
|
-
|
|
249
|
+
const pathQuery = Object.fromEntries(url.searchParams);
|
|
250
|
+
if (!isEmptyObj(defaultQuery) || !isEmptyObj(pathQuery)) {
|
|
251
|
+
query = { ...pathQuery, ...defaultQuery, ...query };
|
|
272
252
|
}
|
|
273
253
|
|
|
274
254
|
if (typeof query === 'object' && query && !Array.isArray(query)) {
|
|
275
|
-
url.search = this.stringifyQuery(query
|
|
255
|
+
url.search = this.stringifyQuery(query);
|
|
276
256
|
}
|
|
277
257
|
|
|
278
258
|
return url.toString();
|
|
@@ -456,7 +436,7 @@ export class Stigg {
|
|
|
456
436
|
loggerFor(this).info(`${responseInfo} - ${retryMessage}`);
|
|
457
437
|
|
|
458
438
|
const errText = await response.text().catch((err: any) => castToError(err).message);
|
|
459
|
-
const errJSON = safeJSON(errText);
|
|
439
|
+
const errJSON = safeJSON(errText) as any;
|
|
460
440
|
const errMessage = errJSON ? undefined : errText;
|
|
461
441
|
|
|
462
442
|
loggerFor(this).debug(
|
|
@@ -493,9 +473,14 @@ export class Stigg {
|
|
|
493
473
|
getAPIList<Item, PageClass extends Pagination.AbstractPage<Item> = Pagination.AbstractPage<Item>>(
|
|
494
474
|
path: string,
|
|
495
475
|
Page: new (...args: any[]) => PageClass,
|
|
496
|
-
opts?: RequestOptions
|
|
476
|
+
opts?: PromiseOrValue<RequestOptions>,
|
|
497
477
|
): Pagination.PagePromise<PageClass, Item> {
|
|
498
|
-
return this.requestAPIList(
|
|
478
|
+
return this.requestAPIList(
|
|
479
|
+
Page,
|
|
480
|
+
opts && 'then' in opts ?
|
|
481
|
+
opts.then((opts) => ({ method: 'get', path, ...opts }))
|
|
482
|
+
: { method: 'get', path, ...opts },
|
|
483
|
+
);
|
|
499
484
|
}
|
|
500
485
|
|
|
501
486
|
requestAPIList<
|
|
@@ -503,7 +488,7 @@ export class Stigg {
|
|
|
503
488
|
PageClass extends Pagination.AbstractPage<Item> = Pagination.AbstractPage<Item>,
|
|
504
489
|
>(
|
|
505
490
|
Page: new (...args: ConstructorParameters<typeof Pagination.AbstractPage>) => PageClass,
|
|
506
|
-
options: FinalRequestOptions
|
|
491
|
+
options: PromiseOrValue<FinalRequestOptions>,
|
|
507
492
|
): Pagination.PagePromise<PageClass, Item> {
|
|
508
493
|
const request = this.makeRequest(options, null, undefined);
|
|
509
494
|
return new Pagination.PagePromise<PageClass, Item>(this as any as Stigg, request, Page);
|
|
@@ -516,9 +501,10 @@ export class Stigg {
|
|
|
516
501
|
controller: AbortController,
|
|
517
502
|
): Promise<Response> {
|
|
518
503
|
const { signal, method, ...options } = init || {};
|
|
519
|
-
|
|
504
|
+
const abort = this._makeAbort(controller);
|
|
505
|
+
if (signal) signal.addEventListener('abort', abort, { once: true });
|
|
520
506
|
|
|
521
|
-
const timeout = setTimeout(
|
|
507
|
+
const timeout = setTimeout(abort, ms);
|
|
522
508
|
|
|
523
509
|
const isReadableBody =
|
|
524
510
|
((globalThis as any).ReadableStream && options.body instanceof (globalThis as any).ReadableStream) ||
|
|
@@ -595,9 +581,9 @@ export class Stigg {
|
|
|
595
581
|
}
|
|
596
582
|
}
|
|
597
583
|
|
|
598
|
-
// If the API asks us to wait a certain amount of time
|
|
599
|
-
//
|
|
600
|
-
if (
|
|
584
|
+
// If the API asks us to wait a certain amount of time, just do what it
|
|
585
|
+
// says, but otherwise calculate a default
|
|
586
|
+
if (timeoutMillis === undefined) {
|
|
601
587
|
const maxRetries = options.maxRetries ?? this.maxRetries;
|
|
602
588
|
timeoutMillis = this.calculateDefaultRetryTimeoutMillis(retriesRemaining, maxRetries);
|
|
603
589
|
}
|
|
@@ -685,6 +671,12 @@ export class Stigg {
|
|
|
685
671
|
return headers.values;
|
|
686
672
|
}
|
|
687
673
|
|
|
674
|
+
private _makeAbort(controller: AbortController) {
|
|
675
|
+
// note: we can't just inline this method inside `fetchWithTimeout()` because then the closure
|
|
676
|
+
// would capture all request options, and cause a memory leak.
|
|
677
|
+
return () => controller.abort();
|
|
678
|
+
}
|
|
679
|
+
|
|
688
680
|
private buildBody({ options: { body, headers: rawHeaders } }: { options: FinalRequestOptions }): {
|
|
689
681
|
bodyHeaders: HeadersLike;
|
|
690
682
|
body: BodyInit | undefined;
|
|
@@ -717,6 +709,14 @@ export class Stigg {
|
|
|
717
709
|
(Symbol.iterator in body && 'next' in body && typeof body.next === 'function'))
|
|
718
710
|
) {
|
|
719
711
|
return { bodyHeaders: undefined, body: Shims.ReadableStreamFrom(body as AsyncIterable<Uint8Array>) };
|
|
712
|
+
} else if (
|
|
713
|
+
typeof body === 'object' &&
|
|
714
|
+
headers.values.get('content-type') === 'application/x-www-form-urlencoded'
|
|
715
|
+
) {
|
|
716
|
+
return {
|
|
717
|
+
bodyHeaders: { 'content-type': 'application/x-www-form-urlencoded' },
|
|
718
|
+
body: this.stringifyQuery(body),
|
|
719
|
+
};
|
|
720
720
|
} else {
|
|
721
721
|
return this.#encoder({ body, headers });
|
|
722
722
|
}
|
|
@@ -755,11 +755,5 @@ export declare namespace Stigg {
|
|
|
755
755
|
type MyCursorIDPageResponse as MyCursorIDPageResponse,
|
|
756
756
|
};
|
|
757
757
|
|
|
758
|
-
export {
|
|
759
|
-
V1 as V1,
|
|
760
|
-
type V1CreateEventResponse as V1CreateEventResponse,
|
|
761
|
-
type V1CreateUsageResponse as V1CreateUsageResponse,
|
|
762
|
-
type V1CreateEventParams as V1CreateEventParams,
|
|
763
|
-
type V1CreateUsageParams as V1CreateUsageParams,
|
|
764
|
-
};
|
|
758
|
+
export { V1 as V1 };
|
|
765
759
|
}
|
package/src/internal/parse.ts
CHANGED
|
@@ -29,6 +29,12 @@ export async function defaultParseResponse<T>(client: Stigg, props: APIResponseP
|
|
|
29
29
|
const mediaType = contentType?.split(';')[0]?.trim();
|
|
30
30
|
const isJSON = mediaType?.includes('application/json') || mediaType?.endsWith('+json');
|
|
31
31
|
if (isJSON) {
|
|
32
|
+
const contentLength = response.headers.get('content-length');
|
|
33
|
+
if (contentLength === '0') {
|
|
34
|
+
// if there is no content we can't do anything
|
|
35
|
+
return undefined as T;
|
|
36
|
+
}
|
|
37
|
+
|
|
32
38
|
const json = await response.json();
|
|
33
39
|
return json as T;
|
|
34
40
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
BSD 3-Clause License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2014, Nathan LaFreniere and other [contributors](https://github.com/puruvj/neoqs/graphs/contributors) All rights reserved.
|
|
4
|
+
|
|
5
|
+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
6
|
+
|
|
7
|
+
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
|
8
|
+
|
|
9
|
+
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
|
10
|
+
|
|
11
|
+
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
|
12
|
+
|
|
13
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Format } from './types';
|
|
2
|
+
|
|
3
|
+
export const default_format: Format = 'RFC3986';
|
|
4
|
+
export const default_formatter = (v: PropertyKey) => String(v);
|
|
5
|
+
export const formatters: Record<Format, (str: PropertyKey) => string> = {
|
|
6
|
+
RFC1738: (v: PropertyKey) => String(v).replace(/%20/g, '+'),
|
|
7
|
+
RFC3986: default_formatter,
|
|
8
|
+
};
|
|
9
|
+
export const RFC1738 = 'RFC1738';
|
|
10
|
+
export const RFC3986 = 'RFC3986';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { default_format, formatters, RFC1738, RFC3986 } from './formats';
|
|
2
|
+
|
|
3
|
+
const formats = {
|
|
4
|
+
formatters,
|
|
5
|
+
RFC1738,
|
|
6
|
+
RFC3986,
|
|
7
|
+
default: default_format,
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export { stringify } from './stringify';
|
|
11
|
+
export { formats };
|
|
12
|
+
|
|
13
|
+
export type { DefaultDecoder, DefaultEncoder, Format, ParseOptions, StringifyOptions } from './types';
|
|
@@ -0,0 +1,385 @@
|
|
|
1
|
+
import { encode, is_buffer, maybe_map, has } from './utils';
|
|
2
|
+
import { default_format, default_formatter, formatters } from './formats';
|
|
3
|
+
import type { NonNullableProperties, StringifyOptions } from './types';
|
|
4
|
+
import { isArray } from '../utils/values';
|
|
5
|
+
|
|
6
|
+
const array_prefix_generators = {
|
|
7
|
+
brackets(prefix: PropertyKey) {
|
|
8
|
+
return String(prefix) + '[]';
|
|
9
|
+
},
|
|
10
|
+
comma: 'comma',
|
|
11
|
+
indices(prefix: PropertyKey, key: string) {
|
|
12
|
+
return String(prefix) + '[' + key + ']';
|
|
13
|
+
},
|
|
14
|
+
repeat(prefix: PropertyKey) {
|
|
15
|
+
return String(prefix);
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const push_to_array = function (arr: any[], value_or_array: any) {
|
|
20
|
+
Array.prototype.push.apply(arr, isArray(value_or_array) ? value_or_array : [value_or_array]);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
let toISOString;
|
|
24
|
+
|
|
25
|
+
const defaults = {
|
|
26
|
+
addQueryPrefix: false,
|
|
27
|
+
allowDots: false,
|
|
28
|
+
allowEmptyArrays: false,
|
|
29
|
+
arrayFormat: 'indices',
|
|
30
|
+
charset: 'utf-8',
|
|
31
|
+
charsetSentinel: false,
|
|
32
|
+
delimiter: '&',
|
|
33
|
+
encode: true,
|
|
34
|
+
encodeDotInKeys: false,
|
|
35
|
+
encoder: encode,
|
|
36
|
+
encodeValuesOnly: false,
|
|
37
|
+
format: default_format,
|
|
38
|
+
formatter: default_formatter,
|
|
39
|
+
/** @deprecated */
|
|
40
|
+
indices: false,
|
|
41
|
+
serializeDate(date) {
|
|
42
|
+
return (toISOString ??= Function.prototype.call.bind(Date.prototype.toISOString))(date);
|
|
43
|
+
},
|
|
44
|
+
skipNulls: false,
|
|
45
|
+
strictNullHandling: false,
|
|
46
|
+
} as NonNullableProperties<StringifyOptions & { formatter: (typeof formatters)['RFC1738'] }>;
|
|
47
|
+
|
|
48
|
+
function is_non_nullish_primitive(v: unknown): v is string | number | boolean | symbol | bigint {
|
|
49
|
+
return (
|
|
50
|
+
typeof v === 'string' ||
|
|
51
|
+
typeof v === 'number' ||
|
|
52
|
+
typeof v === 'boolean' ||
|
|
53
|
+
typeof v === 'symbol' ||
|
|
54
|
+
typeof v === 'bigint'
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const sentinel = {};
|
|
59
|
+
|
|
60
|
+
function inner_stringify(
|
|
61
|
+
object: any,
|
|
62
|
+
prefix: PropertyKey,
|
|
63
|
+
generateArrayPrefix: StringifyOptions['arrayFormat'] | ((prefix: string, key: string) => string),
|
|
64
|
+
commaRoundTrip: boolean,
|
|
65
|
+
allowEmptyArrays: boolean,
|
|
66
|
+
strictNullHandling: boolean,
|
|
67
|
+
skipNulls: boolean,
|
|
68
|
+
encodeDotInKeys: boolean,
|
|
69
|
+
encoder: StringifyOptions['encoder'],
|
|
70
|
+
filter: StringifyOptions['filter'],
|
|
71
|
+
sort: StringifyOptions['sort'],
|
|
72
|
+
allowDots: StringifyOptions['allowDots'],
|
|
73
|
+
serializeDate: StringifyOptions['serializeDate'],
|
|
74
|
+
format: StringifyOptions['format'],
|
|
75
|
+
formatter: StringifyOptions['formatter'],
|
|
76
|
+
encodeValuesOnly: boolean,
|
|
77
|
+
charset: StringifyOptions['charset'],
|
|
78
|
+
sideChannel: WeakMap<any, any>,
|
|
79
|
+
) {
|
|
80
|
+
let obj = object;
|
|
81
|
+
|
|
82
|
+
let tmp_sc = sideChannel;
|
|
83
|
+
let step = 0;
|
|
84
|
+
let find_flag = false;
|
|
85
|
+
while ((tmp_sc = tmp_sc.get(sentinel)) !== void undefined && !find_flag) {
|
|
86
|
+
// Where object last appeared in the ref tree
|
|
87
|
+
const pos = tmp_sc.get(object);
|
|
88
|
+
step += 1;
|
|
89
|
+
if (typeof pos !== 'undefined') {
|
|
90
|
+
if (pos === step) {
|
|
91
|
+
throw new RangeError('Cyclic object value');
|
|
92
|
+
} else {
|
|
93
|
+
find_flag = true; // Break while
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
if (typeof tmp_sc.get(sentinel) === 'undefined') {
|
|
97
|
+
step = 0;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (typeof filter === 'function') {
|
|
102
|
+
obj = filter(prefix, obj);
|
|
103
|
+
} else if (obj instanceof Date) {
|
|
104
|
+
obj = serializeDate?.(obj);
|
|
105
|
+
} else if (generateArrayPrefix === 'comma' && isArray(obj)) {
|
|
106
|
+
obj = maybe_map(obj, function (value) {
|
|
107
|
+
if (value instanceof Date) {
|
|
108
|
+
return serializeDate?.(value);
|
|
109
|
+
}
|
|
110
|
+
return value;
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if (obj === null) {
|
|
115
|
+
if (strictNullHandling) {
|
|
116
|
+
return encoder && !encodeValuesOnly ?
|
|
117
|
+
// @ts-expect-error
|
|
118
|
+
encoder(prefix, defaults.encoder, charset, 'key', format)
|
|
119
|
+
: prefix;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
obj = '';
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (is_non_nullish_primitive(obj) || is_buffer(obj)) {
|
|
126
|
+
if (encoder) {
|
|
127
|
+
const key_value =
|
|
128
|
+
encodeValuesOnly ? prefix
|
|
129
|
+
// @ts-expect-error
|
|
130
|
+
: encoder(prefix, defaults.encoder, charset, 'key', format);
|
|
131
|
+
return [
|
|
132
|
+
formatter?.(key_value) +
|
|
133
|
+
'=' +
|
|
134
|
+
// @ts-expect-error
|
|
135
|
+
formatter?.(encoder(obj, defaults.encoder, charset, 'value', format)),
|
|
136
|
+
];
|
|
137
|
+
}
|
|
138
|
+
return [formatter?.(prefix) + '=' + formatter?.(String(obj))];
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const values: string[] = [];
|
|
142
|
+
|
|
143
|
+
if (typeof obj === 'undefined') {
|
|
144
|
+
return values;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
let obj_keys;
|
|
148
|
+
if (generateArrayPrefix === 'comma' && isArray(obj)) {
|
|
149
|
+
// we need to join elements in
|
|
150
|
+
if (encodeValuesOnly && encoder) {
|
|
151
|
+
// @ts-expect-error values only
|
|
152
|
+
obj = maybe_map(obj, encoder);
|
|
153
|
+
}
|
|
154
|
+
obj_keys = [{ value: obj.length > 0 ? obj.join(',') || null : void undefined }];
|
|
155
|
+
} else if (isArray(filter)) {
|
|
156
|
+
obj_keys = filter;
|
|
157
|
+
} else {
|
|
158
|
+
const keys = Object.keys(obj);
|
|
159
|
+
obj_keys = sort ? keys.sort(sort) : keys;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const encoded_prefix = encodeDotInKeys ? String(prefix).replace(/\./g, '%2E') : String(prefix);
|
|
163
|
+
|
|
164
|
+
const adjusted_prefix =
|
|
165
|
+
commaRoundTrip && isArray(obj) && obj.length === 1 ? encoded_prefix + '[]' : encoded_prefix;
|
|
166
|
+
|
|
167
|
+
if (allowEmptyArrays && isArray(obj) && obj.length === 0) {
|
|
168
|
+
return adjusted_prefix + '[]';
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
for (let j = 0; j < obj_keys.length; ++j) {
|
|
172
|
+
const key = obj_keys[j];
|
|
173
|
+
const value =
|
|
174
|
+
// @ts-ignore
|
|
175
|
+
typeof key === 'object' && typeof key.value !== 'undefined' ? key.value : obj[key as any];
|
|
176
|
+
|
|
177
|
+
if (skipNulls && value === null) {
|
|
178
|
+
continue;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// @ts-ignore
|
|
182
|
+
const encoded_key = allowDots && encodeDotInKeys ? (key as any).replace(/\./g, '%2E') : key;
|
|
183
|
+
const key_prefix =
|
|
184
|
+
isArray(obj) ?
|
|
185
|
+
typeof generateArrayPrefix === 'function' ?
|
|
186
|
+
generateArrayPrefix(adjusted_prefix, encoded_key)
|
|
187
|
+
: adjusted_prefix
|
|
188
|
+
: adjusted_prefix + (allowDots ? '.' + encoded_key : '[' + encoded_key + ']');
|
|
189
|
+
|
|
190
|
+
sideChannel.set(object, step);
|
|
191
|
+
const valueSideChannel = new WeakMap();
|
|
192
|
+
valueSideChannel.set(sentinel, sideChannel);
|
|
193
|
+
push_to_array(
|
|
194
|
+
values,
|
|
195
|
+
inner_stringify(
|
|
196
|
+
value,
|
|
197
|
+
key_prefix,
|
|
198
|
+
generateArrayPrefix,
|
|
199
|
+
commaRoundTrip,
|
|
200
|
+
allowEmptyArrays,
|
|
201
|
+
strictNullHandling,
|
|
202
|
+
skipNulls,
|
|
203
|
+
encodeDotInKeys,
|
|
204
|
+
// @ts-ignore
|
|
205
|
+
generateArrayPrefix === 'comma' && encodeValuesOnly && isArray(obj) ? null : encoder,
|
|
206
|
+
filter,
|
|
207
|
+
sort,
|
|
208
|
+
allowDots,
|
|
209
|
+
serializeDate,
|
|
210
|
+
format,
|
|
211
|
+
formatter,
|
|
212
|
+
encodeValuesOnly,
|
|
213
|
+
charset,
|
|
214
|
+
valueSideChannel,
|
|
215
|
+
),
|
|
216
|
+
);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
return values;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
function normalize_stringify_options(
|
|
223
|
+
opts: StringifyOptions = defaults,
|
|
224
|
+
): NonNullableProperties<Omit<StringifyOptions, 'indices'>> & { indices?: boolean } {
|
|
225
|
+
if (typeof opts.allowEmptyArrays !== 'undefined' && typeof opts.allowEmptyArrays !== 'boolean') {
|
|
226
|
+
throw new TypeError('`allowEmptyArrays` option can only be `true` or `false`, when provided');
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
if (typeof opts.encodeDotInKeys !== 'undefined' && typeof opts.encodeDotInKeys !== 'boolean') {
|
|
230
|
+
throw new TypeError('`encodeDotInKeys` option can only be `true` or `false`, when provided');
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
if (opts.encoder !== null && typeof opts.encoder !== 'undefined' && typeof opts.encoder !== 'function') {
|
|
234
|
+
throw new TypeError('Encoder has to be a function.');
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
const charset = opts.charset || defaults.charset;
|
|
238
|
+
if (typeof opts.charset !== 'undefined' && opts.charset !== 'utf-8' && opts.charset !== 'iso-8859-1') {
|
|
239
|
+
throw new TypeError('The charset option must be either utf-8, iso-8859-1, or undefined');
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
let format = default_format;
|
|
243
|
+
if (typeof opts.format !== 'undefined') {
|
|
244
|
+
if (!has(formatters, opts.format)) {
|
|
245
|
+
throw new TypeError('Unknown format option provided.');
|
|
246
|
+
}
|
|
247
|
+
format = opts.format;
|
|
248
|
+
}
|
|
249
|
+
const formatter = formatters[format];
|
|
250
|
+
|
|
251
|
+
let filter = defaults.filter;
|
|
252
|
+
if (typeof opts.filter === 'function' || isArray(opts.filter)) {
|
|
253
|
+
filter = opts.filter;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
let arrayFormat: StringifyOptions['arrayFormat'];
|
|
257
|
+
if (opts.arrayFormat && opts.arrayFormat in array_prefix_generators) {
|
|
258
|
+
arrayFormat = opts.arrayFormat;
|
|
259
|
+
} else if ('indices' in opts) {
|
|
260
|
+
arrayFormat = opts.indices ? 'indices' : 'repeat';
|
|
261
|
+
} else {
|
|
262
|
+
arrayFormat = defaults.arrayFormat;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
if ('commaRoundTrip' in opts && typeof opts.commaRoundTrip !== 'boolean') {
|
|
266
|
+
throw new TypeError('`commaRoundTrip` must be a boolean, or absent');
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
const allowDots =
|
|
270
|
+
typeof opts.allowDots === 'undefined' ?
|
|
271
|
+
!!opts.encodeDotInKeys === true ?
|
|
272
|
+
true
|
|
273
|
+
: defaults.allowDots
|
|
274
|
+
: !!opts.allowDots;
|
|
275
|
+
|
|
276
|
+
return {
|
|
277
|
+
addQueryPrefix: typeof opts.addQueryPrefix === 'boolean' ? opts.addQueryPrefix : defaults.addQueryPrefix,
|
|
278
|
+
// @ts-ignore
|
|
279
|
+
allowDots: allowDots,
|
|
280
|
+
allowEmptyArrays:
|
|
281
|
+
typeof opts.allowEmptyArrays === 'boolean' ? !!opts.allowEmptyArrays : defaults.allowEmptyArrays,
|
|
282
|
+
arrayFormat: arrayFormat,
|
|
283
|
+
charset: charset,
|
|
284
|
+
charsetSentinel:
|
|
285
|
+
typeof opts.charsetSentinel === 'boolean' ? opts.charsetSentinel : defaults.charsetSentinel,
|
|
286
|
+
commaRoundTrip: !!opts.commaRoundTrip,
|
|
287
|
+
delimiter: typeof opts.delimiter === 'undefined' ? defaults.delimiter : opts.delimiter,
|
|
288
|
+
encode: typeof opts.encode === 'boolean' ? opts.encode : defaults.encode,
|
|
289
|
+
encodeDotInKeys:
|
|
290
|
+
typeof opts.encodeDotInKeys === 'boolean' ? opts.encodeDotInKeys : defaults.encodeDotInKeys,
|
|
291
|
+
encoder: typeof opts.encoder === 'function' ? opts.encoder : defaults.encoder,
|
|
292
|
+
encodeValuesOnly:
|
|
293
|
+
typeof opts.encodeValuesOnly === 'boolean' ? opts.encodeValuesOnly : defaults.encodeValuesOnly,
|
|
294
|
+
filter: filter,
|
|
295
|
+
format: format,
|
|
296
|
+
formatter: formatter,
|
|
297
|
+
serializeDate: typeof opts.serializeDate === 'function' ? opts.serializeDate : defaults.serializeDate,
|
|
298
|
+
skipNulls: typeof opts.skipNulls === 'boolean' ? opts.skipNulls : defaults.skipNulls,
|
|
299
|
+
// @ts-ignore
|
|
300
|
+
sort: typeof opts.sort === 'function' ? opts.sort : null,
|
|
301
|
+
strictNullHandling:
|
|
302
|
+
typeof opts.strictNullHandling === 'boolean' ? opts.strictNullHandling : defaults.strictNullHandling,
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
export function stringify(object: any, opts: StringifyOptions = {}) {
|
|
307
|
+
let obj = object;
|
|
308
|
+
const options = normalize_stringify_options(opts);
|
|
309
|
+
|
|
310
|
+
let obj_keys: PropertyKey[] | undefined;
|
|
311
|
+
let filter;
|
|
312
|
+
|
|
313
|
+
if (typeof options.filter === 'function') {
|
|
314
|
+
filter = options.filter;
|
|
315
|
+
obj = filter('', obj);
|
|
316
|
+
} else if (isArray(options.filter)) {
|
|
317
|
+
filter = options.filter;
|
|
318
|
+
obj_keys = filter;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
const keys: string[] = [];
|
|
322
|
+
|
|
323
|
+
if (typeof obj !== 'object' || obj === null) {
|
|
324
|
+
return '';
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
const generateArrayPrefix = array_prefix_generators[options.arrayFormat];
|
|
328
|
+
const commaRoundTrip = generateArrayPrefix === 'comma' && options.commaRoundTrip;
|
|
329
|
+
|
|
330
|
+
if (!obj_keys) {
|
|
331
|
+
obj_keys = Object.keys(obj);
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
if (options.sort) {
|
|
335
|
+
obj_keys.sort(options.sort);
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
const sideChannel = new WeakMap();
|
|
339
|
+
for (let i = 0; i < obj_keys.length; ++i) {
|
|
340
|
+
const key = obj_keys[i]!;
|
|
341
|
+
|
|
342
|
+
if (options.skipNulls && obj[key] === null) {
|
|
343
|
+
continue;
|
|
344
|
+
}
|
|
345
|
+
push_to_array(
|
|
346
|
+
keys,
|
|
347
|
+
inner_stringify(
|
|
348
|
+
obj[key],
|
|
349
|
+
key,
|
|
350
|
+
// @ts-expect-error
|
|
351
|
+
generateArrayPrefix,
|
|
352
|
+
commaRoundTrip,
|
|
353
|
+
options.allowEmptyArrays,
|
|
354
|
+
options.strictNullHandling,
|
|
355
|
+
options.skipNulls,
|
|
356
|
+
options.encodeDotInKeys,
|
|
357
|
+
options.encode ? options.encoder : null,
|
|
358
|
+
options.filter,
|
|
359
|
+
options.sort,
|
|
360
|
+
options.allowDots,
|
|
361
|
+
options.serializeDate,
|
|
362
|
+
options.format,
|
|
363
|
+
options.formatter,
|
|
364
|
+
options.encodeValuesOnly,
|
|
365
|
+
options.charset,
|
|
366
|
+
sideChannel,
|
|
367
|
+
),
|
|
368
|
+
);
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
const joined = keys.join(options.delimiter);
|
|
372
|
+
let prefix = options.addQueryPrefix === true ? '?' : '';
|
|
373
|
+
|
|
374
|
+
if (options.charsetSentinel) {
|
|
375
|
+
if (options.charset === 'iso-8859-1') {
|
|
376
|
+
// encodeURIComponent('✓'), the "numeric entity" representation of a checkmark
|
|
377
|
+
prefix += 'utf8=%26%2310003%3B&';
|
|
378
|
+
} else {
|
|
379
|
+
// encodeURIComponent('✓')
|
|
380
|
+
prefix += 'utf8=%E2%9C%93&';
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
return joined.length > 0 ? prefix + joined : '';
|
|
385
|
+
}
|