dub 0.10.0 → 0.20.2
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/.github/workflows/sdk_generation.yaml +26 -0
- package/.github/workflows/sdk_publish.yaml +15 -0
- package/.speakeasy/gen.lock +205 -0
- package/.speakeasy/gen.yaml +37 -0
- package/.speakeasy/workflow.yaml +12 -0
- package/README.md +292 -182
- package/docs/sdks/analytics/README.md +535 -0
- package/docs/sdks/dub/README.md +9 -0
- package/docs/sdks/links/README.md +415 -0
- package/docs/sdks/qrcodes/README.md +58 -0
- package/docs/sdks/tags/README.md +113 -0
- package/docs/sdks/workspaces/README.md +168 -0
- package/hooks/hooks.d.ts +20 -0
- package/hooks/hooks.d.ts.map +1 -0
- package/hooks/hooks.js +55 -0
- package/hooks/hooks.js.map +1 -0
- package/hooks/index.d.ts +3 -0
- package/hooks/index.d.ts.map +1 -0
- package/{_shims/auto/runtime-bun.js → hooks/index.js} +6 -5
- package/hooks/index.js.map +1 -0
- package/hooks/types.d.ts +59 -0
- package/hooks/types.d.ts.map +1 -0
- package/hooks/types.js +6 -0
- package/hooks/types.js.map +1 -0
- package/index.d.ts +4 -125
- package/index.d.ts.map +1 -1
- package/index.js +10 -103
- package/index.js.map +1 -1
- package/lib/base64.d.ts +10 -0
- package/lib/base64.d.ts.map +1 -0
- package/lib/base64.js +61 -0
- package/lib/base64.js.map +1 -0
- package/lib/config.d.ts +39 -0
- package/lib/config.d.ts.map +1 -0
- package/lib/config.js +39 -0
- package/lib/config.js.map +1 -0
- package/lib/encodings.d.ts +39 -0
- package/lib/encodings.d.ts.map +1 -0
- package/lib/encodings.js +311 -0
- package/lib/encodings.js.map +1 -0
- package/lib/http.d.ts +46 -0
- package/lib/http.d.ts.map +1 -0
- package/lib/http.js +143 -0
- package/lib/http.js.map +1 -0
- package/lib/retries.d.ts +18 -0
- package/lib/retries.d.ts.map +1 -0
- package/lib/retries.js +157 -0
- package/lib/retries.js.map +1 -0
- package/lib/schemas.d.ts +7 -0
- package/lib/schemas.d.ts.map +1 -0
- package/{shims/web.js → lib/schemas.js} +24 -6
- package/lib/schemas.js.map +1 -0
- package/lib/sdks.d.ts +39 -0
- package/lib/sdks.d.ts.map +1 -0
- package/lib/sdks.js +98 -0
- package/lib/sdks.js.map +1 -0
- package/lib/security.d.ts +57 -0
- package/lib/security.d.ts.map +1 -0
- package/lib/security.js +115 -0
- package/lib/security.js.map +1 -0
- package/lib/url.d.ts +4 -0
- package/lib/url.d.ts.map +1 -0
- package/lib/url.js +26 -0
- package/lib/url.js.map +1 -0
- package/models/components/index.d.ts +5 -0
- package/models/components/index.d.ts.map +1 -0
- package/{_shims/auto/runtime-node.js → models/components/index.js} +8 -5
- package/models/components/index.js.map +1 -0
- package/models/components/linkschema.d.ts +222 -0
- package/models/components/linkschema.d.ts.map +1 -0
- package/models/components/linkschema.js +189 -0
- package/models/components/linkschema.js.map +1 -0
- package/models/components/security.d.ts +16 -0
- package/models/components/security.d.ts.map +1 -0
- package/models/components/security.js +53 -0
- package/models/components/security.js.map +1 -0
- package/models/components/tagschema.d.ts +45 -0
- package/models/components/tagschema.d.ts.map +1 -0
- package/models/components/tagschema.js +76 -0
- package/models/components/tagschema.js.map +1 -0
- package/models/components/workspaceschema.d.ts +178 -0
- package/models/components/workspaceschema.d.ts.map +1 -0
- package/models/components/workspaceschema.js +190 -0
- package/models/components/workspaceschema.js.map +1 -0
- package/models/errors/badrequest.d.ts +65 -0
- package/models/errors/badrequest.d.ts.map +1 -0
- package/models/errors/badrequest.js +111 -0
- package/models/errors/badrequest.js.map +1 -0
- package/models/errors/conflict.d.ts +65 -0
- package/models/errors/conflict.d.ts.map +1 -0
- package/models/errors/conflict.js +111 -0
- package/models/errors/conflict.js.map +1 -0
- package/models/errors/forbidden.d.ts +65 -0
- package/models/errors/forbidden.d.ts.map +1 -0
- package/models/errors/forbidden.js +111 -0
- package/models/errors/forbidden.js.map +1 -0
- package/models/errors/index.d.ts +12 -0
- package/models/errors/index.d.ts.map +1 -0
- package/{_shims/auto/types-node.js → models/errors/index.js} +15 -5
- package/models/errors/index.js.map +1 -0
- package/models/errors/internalservererror.d.ts +65 -0
- package/models/errors/internalservererror.d.ts.map +1 -0
- package/models/errors/internalservererror.js +111 -0
- package/models/errors/internalservererror.js.map +1 -0
- package/models/errors/inviteexpired.d.ts +65 -0
- package/models/errors/inviteexpired.d.ts.map +1 -0
- package/models/errors/inviteexpired.js +111 -0
- package/models/errors/inviteexpired.js.map +1 -0
- package/models/errors/notfound.d.ts +65 -0
- package/models/errors/notfound.d.ts.map +1 -0
- package/models/errors/notfound.js +111 -0
- package/models/errors/notfound.js.map +1 -0
- package/models/errors/ratelimitexceeded.d.ts +65 -0
- package/models/errors/ratelimitexceeded.d.ts.map +1 -0
- package/models/errors/ratelimitexceeded.js +111 -0
- package/models/errors/ratelimitexceeded.js.map +1 -0
- package/models/errors/sdkerror.d.ts +7 -0
- package/models/errors/sdkerror.d.ts.map +1 -0
- package/models/errors/sdkerror.js +19 -0
- package/models/errors/sdkerror.js.map +1 -0
- package/models/errors/sdkvalidationerror.d.ts +17 -0
- package/models/errors/sdkvalidationerror.d.ts.map +1 -0
- package/models/errors/sdkvalidationerror.js +107 -0
- package/models/errors/sdkvalidationerror.js.map +1 -0
- package/models/errors/unauthorized.d.ts +65 -0
- package/models/errors/unauthorized.d.ts.map +1 -0
- package/models/errors/unauthorized.js +111 -0
- package/models/errors/unauthorized.js.map +1 -0
- package/models/errors/unprocessableentity.d.ts +65 -0
- package/models/errors/unprocessableentity.d.ts.map +1 -0
- package/models/errors/unprocessableentity.js +111 -0
- package/models/errors/unprocessableentity.js.map +1 -0
- package/models/operations/bulkcreatelinks.d.ts +146 -0
- package/models/operations/bulkcreatelinks.d.ts.map +1 -0
- package/models/operations/bulkcreatelinks.js +138 -0
- package/models/operations/bulkcreatelinks.js.map +1 -0
- package/models/operations/createlink.d.ts +146 -0
- package/models/operations/createlink.d.ts.map +1 -0
- package/models/operations/createlink.js +141 -0
- package/models/operations/createlink.js.map +1 -0
- package/models/operations/createtag.d.ts +39 -0
- package/models/operations/createtag.d.ts.map +1 -0
- package/models/operations/createtag.js +72 -0
- package/models/operations/createtag.js.map +1 -0
- package/models/operations/createworkspace.d.ts +22 -0
- package/models/operations/createworkspace.d.ts.map +1 -0
- package/models/operations/createworkspace.js +61 -0
- package/models/operations/createworkspace.js.map +1 -0
- package/models/operations/deletelink.d.ts +39 -0
- package/models/operations/deletelink.d.ts.map +1 -0
- package/models/operations/deletelink.js +75 -0
- package/models/operations/deletelink.js.map +1 -0
- package/models/operations/editlink.d.ts +166 -0
- package/models/operations/editlink.d.ts.map +1 -0
- package/models/operations/editlink.js +167 -0
- package/models/operations/editlink.js.map +1 -0
- package/models/operations/getbrowseranalytics.d.ts +378 -0
- package/models/operations/getbrowseranalytics.d.ts.map +1 -0
- package/models/operations/getbrowseranalytics.js +395 -0
- package/models/operations/getbrowseranalytics.js.map +1 -0
- package/models/operations/getcityanalytics.d.ts +641 -0
- package/models/operations/getcityanalytics.d.ts.map +1 -0
- package/models/operations/getcityanalytics.js +657 -0
- package/models/operations/getcityanalytics.js.map +1 -0
- package/models/operations/getclicksanalytics.d.ts +355 -0
- package/models/operations/getclicksanalytics.d.ts.map +1 -0
- package/models/operations/getclicksanalytics.js +369 -0
- package/models/operations/getclicksanalytics.js.map +1 -0
- package/models/operations/getcountryanalytics.d.ts +635 -0
- package/models/operations/getcountryanalytics.d.ts.map +1 -0
- package/models/operations/getcountryanalytics.js +653 -0
- package/models/operations/getcountryanalytics.js.map +1 -0
- package/models/operations/getdeviceanalytics.d.ts +378 -0
- package/models/operations/getdeviceanalytics.d.ts.map +1 -0
- package/models/operations/getdeviceanalytics.js +395 -0
- package/models/operations/getdeviceanalytics.js.map +1 -0
- package/models/operations/getlinkinfo.d.ts +25 -0
- package/models/operations/getlinkinfo.d.ts.map +1 -0
- package/models/operations/getlinkinfo.js +57 -0
- package/models/operations/getlinkinfo.js.map +1 -0
- package/models/operations/getlinks.d.ts +88 -0
- package/models/operations/getlinks.d.ts.map +1 -0
- package/models/operations/getlinks.js +108 -0
- package/models/operations/getlinks.js.map +1 -0
- package/models/operations/getlinkscount.d.ts +93 -0
- package/models/operations/getlinkscount.d.ts.map +1 -0
- package/models/operations/getlinkscount.js +105 -0
- package/models/operations/getlinkscount.js.map +1 -0
- package/models/operations/getosanalytics.d.ts +378 -0
- package/models/operations/getosanalytics.d.ts.map +1 -0
- package/models/operations/getosanalytics.js +395 -0
- package/models/operations/getosanalytics.js.map +1 -0
- package/models/operations/getqrcode.d.ts +60 -0
- package/models/operations/getqrcode.d.ts.map +1 -0
- package/models/operations/getqrcode.js +85 -0
- package/models/operations/getqrcode.js.map +1 -0
- package/models/operations/getrefereranalytics.d.ts +378 -0
- package/models/operations/getrefereranalytics.d.ts.map +1 -0
- package/models/operations/getrefereranalytics.js +395 -0
- package/models/operations/getrefereranalytics.js.map +1 -0
- package/models/operations/gettags.d.ts +10 -0
- package/models/operations/gettags.d.ts.map +1 -0
- package/{shims/node.js → models/operations/gettags.js} +12 -6
- package/models/operations/gettags.js.map +1 -0
- package/models/operations/gettimeseriesanalytics.d.ts +378 -0
- package/models/operations/gettimeseriesanalytics.d.ts.map +1 -0
- package/models/operations/gettimeseriesanalytics.js +395 -0
- package/models/operations/gettimeseriesanalytics.js.map +1 -0
- package/models/operations/gettoplinks.d.ts +378 -0
- package/models/operations/gettoplinks.d.ts.map +1 -0
- package/models/operations/gettoplinks.js +395 -0
- package/models/operations/gettoplinks.js.map +1 -0
- package/models/operations/gettopurls.d.ts +378 -0
- package/models/operations/gettopurls.d.ts.map +1 -0
- package/models/operations/gettopurls.js +395 -0
- package/models/operations/gettopurls.js.map +1 -0
- package/models/operations/getworkspace.d.ts +19 -0
- package/models/operations/getworkspace.d.ts.map +1 -0
- package/models/operations/getworkspace.js +53 -0
- package/models/operations/getworkspace.js.map +1 -0
- package/models/operations/index.d.ts +23 -0
- package/models/operations/index.d.ts.map +1 -0
- package/models/operations/index.js +42 -0
- package/models/operations/index.js.map +1 -0
- package/package.json +25 -98
- package/sdk/analytics.d.ts +78 -0
- package/sdk/analytics.d.ts.map +1 -0
- package/sdk/analytics.js +2044 -0
- package/sdk/analytics.js.map +1 -0
- package/sdk/index.d.ts +2 -0
- package/sdk/index.d.ts.map +1 -0
- package/{_shims/auto/runtime.js → sdk/index.js} +5 -5
- package/sdk/index.js.map +1 -0
- package/sdk/links.d.ts +58 -0
- package/sdk/links.d.ts.map +1 -0
- package/sdk/links.js +1309 -0
- package/sdk/links.js.map +1 -0
- package/sdk/qrcodes.d.ts +21 -0
- package/sdk/qrcodes.d.ts.map +1 -0
- package/sdk/qrcodes.js +249 -0
- package/sdk/qrcodes.js.map +1 -0
- package/sdk/sdk.d.ts +22 -0
- package/sdk/sdk.d.ts.map +1 -0
- package/sdk/sdk.js +59 -0
- package/sdk/sdk.js.map +1 -0
- package/sdk/tags.d.ts +23 -0
- package/sdk/tags.d.ts.map +1 -0
- package/sdk/tags.js +401 -0
- package/sdk/tags.js.map +1 -0
- package/sdk/workspaces.d.ts +30 -0
- package/sdk/workspaces.d.ts.map +1 -0
- package/sdk/workspaces.js +556 -0
- package/sdk/workspaces.js.map +1 -0
- package/src/hooks/hooks.ts +81 -0
- package/src/hooks/index.ts +6 -0
- package/src/hooks/types.ts +74 -0
- package/src/index.ts +8 -209
- package/src/lib/base64.ts +37 -0
- package/src/lib/config.ts +70 -0
- package/src/lib/encodings.ts +384 -0
- package/src/lib/http.ts +215 -0
- package/src/lib/retries.ts +226 -0
- package/src/lib/schemas.ts +22 -0
- package/src/lib/sdks.ts +139 -0
- package/src/lib/security.ts +180 -0
- package/src/lib/url.ts +31 -0
- package/src/models/components/index.ts +8 -0
- package/src/models/components/linkschema.ts +383 -0
- package/src/models/components/security.ts +40 -0
- package/src/models/components/tagschema.ts +79 -0
- package/src/models/components/workspaceschema.ts +316 -0
- package/src/models/errors/badrequest.ts +140 -0
- package/src/models/errors/conflict.ts +140 -0
- package/src/models/errors/forbidden.ts +140 -0
- package/src/models/errors/index.ts +15 -0
- package/src/models/errors/internalservererror.ts +140 -0
- package/src/models/errors/inviteexpired.ts +140 -0
- package/src/models/errors/notfound.ts +140 -0
- package/src/models/errors/ratelimitexceeded.ts +140 -0
- package/src/models/errors/sdkerror.ts +22 -0
- package/src/models/errors/sdkvalidationerror.ts +95 -0
- package/src/models/errors/unauthorized.ts +140 -0
- package/src/models/errors/unprocessableentity.ts +140 -0
- package/src/models/operations/bulkcreatelinks.ts +254 -0
- package/src/models/operations/createlink.ts +255 -0
- package/src/models/operations/createtag.ts +69 -0
- package/src/models/operations/createworkspace.ts +54 -0
- package/src/models/operations/deletelink.ts +84 -0
- package/src/models/operations/editlink.ts +300 -0
- package/src/models/operations/getbrowseranalytics.ts +484 -0
- package/src/models/operations/getcityanalytics.ts +744 -0
- package/src/models/operations/getclicksanalytics.ts +427 -0
- package/src/models/operations/getcountryanalytics.ts +743 -0
- package/src/models/operations/getdeviceanalytics.ts +480 -0
- package/src/models/operations/getlinkinfo.ts +53 -0
- package/src/models/operations/getlinks.ts +155 -0
- package/src/models/operations/getlinkscount.ts +157 -0
- package/src/models/operations/getosanalytics.ts +475 -0
- package/src/models/operations/getqrcode.ts +106 -0
- package/src/models/operations/getrefereranalytics.ts +484 -0
- package/src/models/operations/gettags.ts +18 -0
- package/src/models/operations/gettimeseriesanalytics.ts +476 -0
- package/src/models/operations/gettoplinks.ts +475 -0
- package/src/models/operations/gettopurls.ts +475 -0
- package/src/models/operations/getworkspace.ts +43 -0
- package/src/models/operations/index.ts +26 -0
- package/src/sdk/analytics.ts +2493 -0
- package/src/sdk/index.ts +5 -0
- package/src/sdk/links.ts +1617 -0
- package/src/sdk/qrcodes.ts +276 -0
- package/src/sdk/sdk.ts +66 -0
- package/src/sdk/tags.ts +470 -0
- package/src/sdk/workspaces.ts +670 -0
- package/src/types/blobs.ts +30 -0
- package/src/types/index.ts +8 -0
- package/src/types/operations.ts +25 -0
- package/src/types/rfcdate.ts +54 -0
- package/types/blobs.d.ts +4 -0
- package/types/blobs.d.ts.map +1 -0
- package/{resources/projects/projects.js → types/blobs.js} +23 -24
- package/types/blobs.js.map +1 -0
- package/types/index.d.ts +5 -0
- package/types/index.d.ts.map +1 -0
- package/types/index.js +14 -0
- package/types/index.js.map +1 -0
- package/types/operations.d.ts +13 -0
- package/types/operations.d.ts.map +1 -0
- package/types/operations.js +19 -0
- package/types/operations.js.map +1 -0
- package/types/rfcdate.d.ts +21 -0
- package/types/rfcdate.d.ts.map +1 -0
- package/types/rfcdate.js +46 -0
- package/types/rfcdate.js.map +1 -0
- package/CHANGELOG.md +0 -116
- package/LICENSE +0 -201
- package/_shims/MultipartBody.d.ts +0 -9
- package/_shims/MultipartBody.d.ts.map +0 -1
- package/_shims/MultipartBody.js +0 -16
- package/_shims/MultipartBody.js.map +0 -1
- package/_shims/MultipartBody.mjs +0 -12
- package/_shims/MultipartBody.mjs.map +0 -1
- package/_shims/README.md +0 -46
- package/_shims/auto/runtime-bun.d.ts +0 -5
- package/_shims/auto/runtime-bun.d.ts.map +0 -1
- package/_shims/auto/runtime-bun.js.map +0 -1
- package/_shims/auto/runtime-bun.mjs +0 -2
- package/_shims/auto/runtime-bun.mjs.map +0 -1
- package/_shims/auto/runtime-node.d.ts +0 -5
- package/_shims/auto/runtime-node.d.ts.map +0 -1
- package/_shims/auto/runtime-node.js.map +0 -1
- package/_shims/auto/runtime-node.mjs +0 -2
- package/_shims/auto/runtime-node.mjs.map +0 -1
- package/_shims/auto/runtime.d.ts +0 -5
- package/_shims/auto/runtime.d.ts.map +0 -1
- package/_shims/auto/runtime.js.map +0 -1
- package/_shims/auto/runtime.mjs +0 -2
- package/_shims/auto/runtime.mjs.map +0 -1
- package/_shims/auto/types-node.d.ts +0 -5
- package/_shims/auto/types-node.d.ts.map +0 -1
- package/_shims/auto/types-node.js.map +0 -1
- package/_shims/auto/types-node.mjs +0 -2
- package/_shims/auto/types-node.mjs.map +0 -1
- package/_shims/auto/types.d.ts +0 -101
- package/_shims/auto/types.js +0 -3
- package/_shims/auto/types.mjs +0 -3
- package/_shims/bun-runtime.d.ts +0 -6
- package/_shims/bun-runtime.d.ts.map +0 -1
- package/_shims/bun-runtime.js +0 -14
- package/_shims/bun-runtime.js.map +0 -1
- package/_shims/bun-runtime.mjs +0 -10
- package/_shims/bun-runtime.mjs.map +0 -1
- package/_shims/index.d.ts +0 -81
- package/_shims/index.js +0 -13
- package/_shims/index.mjs +0 -7
- package/_shims/manual-types.d.ts +0 -12
- package/_shims/manual-types.js +0 -3
- package/_shims/manual-types.mjs +0 -3
- package/_shims/node-runtime.d.ts +0 -3
- package/_shims/node-runtime.d.ts.map +0 -1
- package/_shims/node-runtime.js +0 -90
- package/_shims/node-runtime.js.map +0 -1
- package/_shims/node-runtime.mjs +0 -56
- package/_shims/node-runtime.mjs.map +0 -1
- package/_shims/node-types.d.ts +0 -42
- package/_shims/node-types.js +0 -3
- package/_shims/node-types.mjs +0 -3
- package/_shims/registry.d.ts +0 -37
- package/_shims/registry.d.ts.map +0 -1
- package/_shims/registry.js +0 -41
- package/_shims/registry.js.map +0 -1
- package/_shims/registry.mjs +0 -37
- package/_shims/registry.mjs.map +0 -1
- package/_shims/web-runtime.d.ts +0 -5
- package/_shims/web-runtime.d.ts.map +0 -1
- package/_shims/web-runtime.js +0 -78
- package/_shims/web-runtime.js.map +0 -1
- package/_shims/web-runtime.mjs +0 -71
- package/_shims/web-runtime.mjs.map +0 -1
- package/_shims/web-types.d.ts +0 -83
- package/_shims/web-types.js +0 -3
- package/_shims/web-types.mjs +0 -3
- package/core.d.ts +0 -237
- package/core.d.ts.map +0 -1
- package/core.js +0 -868
- package/core.js.map +0 -1
- package/core.mjs +0 -837
- package/core.mjs.map +0 -1
- package/error.d.ts +0 -53
- package/error.d.ts.map +0 -1
- package/error.js +0 -143
- package/error.js.map +0 -1
- package/error.mjs +0 -127
- package/error.mjs.map +0 -1
- package/index.d.mts +0 -127
- package/index.mjs +0 -90
- package/index.mjs.map +0 -1
- package/resource.d.ts +0 -6
- package/resource.d.ts.map +0 -1
- package/resource.js +0 -11
- package/resource.js.map +0 -1
- package/resource.mjs +0 -7
- package/resource.mjs.map +0 -1
- package/resources/index.d.ts +0 -4
- package/resources/index.d.ts.map +0 -1
- package/resources/index.js +0 -11
- package/resources/index.js.map +0 -1
- package/resources/index.mjs +0 -5
- package/resources/index.mjs.map +0 -1
- package/resources/links/bulk.d.ts +0 -274
- package/resources/links/bulk.d.ts.map +0 -1
- package/resources/links/bulk.js +0 -18
- package/resources/links/bulk.js.map +0 -1
- package/resources/links/bulk.mjs +0 -14
- package/resources/links/bulk.mjs.map +0 -1
- package/resources/links/index.d.ts +0 -4
- package/resources/links/index.d.ts.map +0 -1
- package/resources/links/index.js +0 -11
- package/resources/links/index.js.map +0 -1
- package/resources/links/index.mjs +0 -5
- package/resources/links/index.mjs.map +0 -1
- package/resources/links/info.d.ts +0 -186
- package/resources/links/info.d.ts.map +0 -1
- package/resources/links/info.js +0 -18
- package/resources/links/info.js.map +0 -1
- package/resources/links/info.mjs +0 -14
- package/resources/links/info.mjs.map +0 -1
- package/resources/links/links.d.ts +0 -916
- package/resources/links/links.d.ts.map +0 -1
- package/resources/links/links.js +0 -72
- package/resources/links/links.js.map +0 -1
- package/resources/links/links.mjs +0 -45
- package/resources/links/links.mjs.map +0 -1
- package/resources/projects/index.d.ts +0 -3
- package/resources/projects/index.d.ts.map +0 -1
- package/resources/projects/index.js +0 -9
- package/resources/projects/index.js.map +0 -1
- package/resources/projects/index.mjs +0 -4
- package/resources/projects/index.mjs.map +0 -1
- package/resources/projects/projects.d.ts +0 -200
- package/resources/projects/projects.d.ts.map +0 -1
- package/resources/projects/projects.js.map +0 -1
- package/resources/projects/projects.mjs +0 -26
- package/resources/projects/projects.mjs.map +0 -1
- package/resources/projects/tags.d.ts +0 -4
- package/resources/projects/tags.d.ts.map +0 -1
- package/resources/projects/tags.js +0 -9
- package/resources/projects/tags.js.map +0 -1
- package/resources/projects/tags.mjs +0 -5
- package/resources/projects/tags.mjs.map +0 -1
- package/resources/qr.d.ts +0 -45
- package/resources/qr.d.ts.map +0 -1
- package/resources/qr.js +0 -18
- package/resources/qr.js.map +0 -1
- package/resources/qr.mjs +0 -14
- package/resources/qr.mjs.map +0 -1
- package/shims/node.d.ts +0 -29
- package/shims/node.d.ts.map +0 -1
- package/shims/node.js.map +0 -1
- package/shims/node.mjs +0 -5
- package/shims/node.mjs.map +0 -1
- package/shims/web.d.ts +0 -26
- package/shims/web.d.ts.map +0 -1
- package/shims/web.js.map +0 -1
- package/shims/web.mjs +0 -5
- package/shims/web.mjs.map +0 -1
- package/src/_shims/MultipartBody.ts +0 -9
- package/src/_shims/README.md +0 -46
- package/src/_shims/auto/runtime-bun.ts +0 -4
- package/src/_shims/auto/runtime-node.ts +0 -4
- package/src/_shims/auto/runtime.ts +0 -4
- package/src/_shims/auto/types-node.ts +0 -4
- package/src/_shims/auto/types.d.ts +0 -101
- package/src/_shims/auto/types.js +0 -3
- package/src/_shims/auto/types.mjs +0 -3
- package/src/_shims/bun-runtime.ts +0 -14
- package/src/_shims/index.d.ts +0 -81
- package/src/_shims/index.js +0 -13
- package/src/_shims/index.mjs +0 -7
- package/src/_shims/manual-types.d.ts +0 -12
- package/src/_shims/manual-types.js +0 -3
- package/src/_shims/manual-types.mjs +0 -3
- package/src/_shims/node-runtime.ts +0 -83
- package/src/_shims/node-types.d.ts +0 -42
- package/src/_shims/node-types.js +0 -3
- package/src/_shims/node-types.mjs +0 -3
- package/src/_shims/registry.ts +0 -63
- package/src/_shims/web-runtime.ts +0 -103
- package/src/_shims/web-types.d.ts +0 -83
- package/src/_shims/web-types.js +0 -3
- package/src/_shims/web-types.mjs +0 -3
- package/src/core.ts +0 -1145
- package/src/error.ts +0 -146
- package/src/lib/.keep +0 -4
- package/src/resource.ts +0 -11
- package/src/resources/index.ts +0 -20
- package/src/resources/links/bulk.ts +0 -337
- package/src/resources/links/index.ts +0 -15
- package/src/resources/links/info.ts +0 -230
- package/src/resources/links/links.ts +0 -1135
- package/src/resources/projects/index.ts +0 -4
- package/src/resources/projects/projects.ts +0 -253
- package/src/resources/projects/tags.ts +0 -5
- package/src/resources/qr.ts +0 -64
- package/src/shims/node.ts +0 -50
- package/src/shims/web.ts +0 -50
- package/src/tsconfig.json +0 -11
- package/src/uploads.ts +0 -245
- package/src/version.ts +0 -1
- package/uploads.d.ts +0 -75
- package/uploads.d.ts.map +0 -1
- package/uploads.js +0 -163
- package/uploads.js.map +0 -1
- package/uploads.mjs +0 -150
- package/uploads.mjs.map +0 -1
- package/version.d.ts +0 -2
- package/version.d.ts.map +0 -1
- package/version.js +0 -5
- package/version.js.map +0 -1
- package/version.mjs +0 -2
- package/version.mjs.map +0 -1
|
@@ -0,0 +1,384 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { bytesToBase64 } from "./base64";
|
|
6
|
+
|
|
7
|
+
export class EncodingError extends Error {
|
|
8
|
+
constructor(message: string) {
|
|
9
|
+
super(message);
|
|
10
|
+
this.name = "EncodingError";
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function encodeMatrix(
|
|
15
|
+
key: string,
|
|
16
|
+
value: unknown,
|
|
17
|
+
options?: { explode?: boolean; charEncoding?: "percent" | "none" },
|
|
18
|
+
) {
|
|
19
|
+
let out = "";
|
|
20
|
+
const pairs: [string, unknown][] = options?.explode
|
|
21
|
+
? explode(key, value)
|
|
22
|
+
: [[key, value]];
|
|
23
|
+
|
|
24
|
+
const encodeString = (v: string) => {
|
|
25
|
+
return options?.charEncoding === "percent" ? encodeURIComponent(v) : v;
|
|
26
|
+
};
|
|
27
|
+
const encodeValue = (v: unknown) => encodeString(serializeValue(v));
|
|
28
|
+
|
|
29
|
+
pairs.forEach(([pk, pv]) => {
|
|
30
|
+
let tmp = "";
|
|
31
|
+
let encValue = "";
|
|
32
|
+
|
|
33
|
+
if (pv === undefined) {
|
|
34
|
+
return;
|
|
35
|
+
} else if (Array.isArray(pv)) {
|
|
36
|
+
encValue = mapDefined(pv, (v) => `${encodeValue(v)}`).join(",");
|
|
37
|
+
} else if (isPlainObject(pv)) {
|
|
38
|
+
encValue = mapDefinedEntries(Object.entries(pv), ([k, v]) => {
|
|
39
|
+
return `,${encodeString(k)},${encodeValue(v)}`;
|
|
40
|
+
}).join("");
|
|
41
|
+
encValue = encValue.slice(1);
|
|
42
|
+
} else {
|
|
43
|
+
encValue = `${encodeValue(pv)}`;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const keyPrefix = encodeString(pk);
|
|
47
|
+
tmp = `${keyPrefix}=${encValue}`;
|
|
48
|
+
// trim trailing '=' if value was empty
|
|
49
|
+
if (tmp === `${keyPrefix}=`) {
|
|
50
|
+
tmp = tmp.slice(0, -1);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// If we end up with the nothing then skip forward
|
|
54
|
+
if (!tmp) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
out += `;${tmp}`;
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
return out;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function encodeLabel(
|
|
65
|
+
key: string,
|
|
66
|
+
value: unknown,
|
|
67
|
+
options?: { explode?: boolean; charEncoding?: "percent" | "none" },
|
|
68
|
+
) {
|
|
69
|
+
let out = "";
|
|
70
|
+
const pairs: [string, unknown][] = options?.explode
|
|
71
|
+
? explode(key, value)
|
|
72
|
+
: [[key, value]];
|
|
73
|
+
|
|
74
|
+
const encodeString = (v: string) => {
|
|
75
|
+
return options?.charEncoding === "percent" ? encodeURIComponent(v) : v;
|
|
76
|
+
};
|
|
77
|
+
const encodeValue = (v: unknown) => encodeString(serializeValue(v));
|
|
78
|
+
|
|
79
|
+
pairs.forEach(([pk, pv]) => {
|
|
80
|
+
let encValue = "";
|
|
81
|
+
|
|
82
|
+
if (pv === undefined) {
|
|
83
|
+
return;
|
|
84
|
+
} else if (Array.isArray(pv)) {
|
|
85
|
+
encValue = mapDefined(pv, (v) => `${encodeValue(v)}`).join(".");
|
|
86
|
+
} else if (isPlainObject(pv)) {
|
|
87
|
+
encValue = mapDefinedEntries(Object.entries(pv), ([k, v]) => {
|
|
88
|
+
return `.${encodeString(k)}.${encodeValue(v)}`;
|
|
89
|
+
}).join("");
|
|
90
|
+
encValue = encValue.slice(1);
|
|
91
|
+
} else {
|
|
92
|
+
const k =
|
|
93
|
+
options?.explode && isPlainObject(value) ? `${encodeString(pk)}=` : "";
|
|
94
|
+
encValue = `${k}${encodeValue(pv)}`;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
out += `.${encValue}`;
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
return out;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function formEncoder(sep: string) {
|
|
104
|
+
return (
|
|
105
|
+
key: string,
|
|
106
|
+
value: unknown,
|
|
107
|
+
options?: { explode?: boolean; charEncoding?: "percent" | "none" },
|
|
108
|
+
) => {
|
|
109
|
+
let out = "";
|
|
110
|
+
const pairs: [string, unknown][] = options?.explode
|
|
111
|
+
? explode(key, value)
|
|
112
|
+
: [[key, value]];
|
|
113
|
+
|
|
114
|
+
const encodeString = (v: string) => {
|
|
115
|
+
return options?.charEncoding === "percent" ? encodeURIComponent(v) : v;
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
const encodeValue = (v: unknown) => encodeString(serializeValue(v));
|
|
119
|
+
|
|
120
|
+
const encodedSep = encodeString(sep);
|
|
121
|
+
|
|
122
|
+
pairs.forEach(([pk, pv]) => {
|
|
123
|
+
let tmp = "";
|
|
124
|
+
let encValue = "";
|
|
125
|
+
|
|
126
|
+
if (pv === undefined) {
|
|
127
|
+
return;
|
|
128
|
+
} else if (Array.isArray(pv)) {
|
|
129
|
+
encValue = mapDefined(pv, (v) => `${encodeValue(v)}`).join(encodedSep);
|
|
130
|
+
} else if (isPlainObject(pv)) {
|
|
131
|
+
encValue = mapDefinedEntries(Object.entries(pv), ([k, v]) => {
|
|
132
|
+
return `${encodeString(k)}${encodedSep}${encodeValue(v)}`;
|
|
133
|
+
}).join(encodedSep);
|
|
134
|
+
} else {
|
|
135
|
+
encValue = `${encodeValue(pv)}`;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
tmp = `${encodeString(pk)}=${encValue}`;
|
|
139
|
+
|
|
140
|
+
// If we end up with the nothing then skip forward
|
|
141
|
+
if (!tmp || tmp === "=") {
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
out += `&${tmp}`;
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
return out.slice(1);
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export const encodeForm = formEncoder(",");
|
|
153
|
+
export const encodeSpaceDelimited = formEncoder(" ");
|
|
154
|
+
export const encodePipeDelimited = formEncoder("|");
|
|
155
|
+
|
|
156
|
+
export function encodeBodyForm(
|
|
157
|
+
key: string,
|
|
158
|
+
value: unknown,
|
|
159
|
+
options?: { explode?: boolean; charEncoding?: "percent" | "none" },
|
|
160
|
+
) {
|
|
161
|
+
let out = "";
|
|
162
|
+
const pairs: [string, unknown][] = options?.explode
|
|
163
|
+
? explode(key, value)
|
|
164
|
+
: [[key, value]];
|
|
165
|
+
|
|
166
|
+
const encodeString = (v: string) => {
|
|
167
|
+
return options?.charEncoding === "percent" ? encodeURIComponent(v) : v;
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
const encodeValue = (v: unknown) => encodeString(serializeValue(v));
|
|
171
|
+
|
|
172
|
+
pairs.forEach(([pk, pv]) => {
|
|
173
|
+
let tmp = "";
|
|
174
|
+
let encValue = "";
|
|
175
|
+
|
|
176
|
+
if (pv === undefined) {
|
|
177
|
+
return;
|
|
178
|
+
} else if (Array.isArray(pv)) {
|
|
179
|
+
encValue = JSON.stringify(pv, jsonReplacer);
|
|
180
|
+
} else if (isPlainObject(pv)) {
|
|
181
|
+
encValue = JSON.stringify(pv, jsonReplacer);
|
|
182
|
+
} else {
|
|
183
|
+
encValue = `${encodeValue(pv)}`;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
tmp = `${encodeString(pk)}=${encValue}`;
|
|
187
|
+
|
|
188
|
+
// If we end up with the nothing then skip forward
|
|
189
|
+
if (!tmp || tmp === "=") {
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
out += `&${tmp}`;
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
return out.slice(1);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export function encodeDeepObject(
|
|
200
|
+
key: string,
|
|
201
|
+
value: unknown,
|
|
202
|
+
options?: { charEncoding?: "percent" | "none" },
|
|
203
|
+
) {
|
|
204
|
+
if (value == null) {
|
|
205
|
+
return "";
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
let out = "";
|
|
209
|
+
|
|
210
|
+
const encodeString = (v: string) => {
|
|
211
|
+
return options?.charEncoding === "percent" ? encodeURIComponent(v) : v;
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
if (!isPlainObject(value)) {
|
|
215
|
+
throw new EncodingError(
|
|
216
|
+
`Value of parameter '${key}' which uses deepObject encoding must be an object`,
|
|
217
|
+
);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
Object.entries(value).forEach(([ck, cv]) => {
|
|
221
|
+
if (cv === undefined) {
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
const pk = `${key}[${ck}]`;
|
|
226
|
+
|
|
227
|
+
if (isPlainObject(cv)) {
|
|
228
|
+
throw new EncodingError(
|
|
229
|
+
`Value of parameter field '${pk}' cannot be an array or object.`,
|
|
230
|
+
);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
const pairs: unknown[] = Array.isArray(cv) ? cv : [cv];
|
|
234
|
+
let encoded = "";
|
|
235
|
+
|
|
236
|
+
encoded = mapDefined(pairs, (v) => {
|
|
237
|
+
return `${encodeString(pk)}=${encodeString(serializeValue(v))}`;
|
|
238
|
+
}).join("&");
|
|
239
|
+
|
|
240
|
+
out += `&${encoded}`;
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
return out.slice(1);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
export function encodeJSON(
|
|
247
|
+
key: string,
|
|
248
|
+
value: unknown,
|
|
249
|
+
options?: { explode?: boolean; charEncoding?: "percent" | "none" },
|
|
250
|
+
) {
|
|
251
|
+
if (typeof value === "undefined") {
|
|
252
|
+
return "";
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
const encodeString = (v: string) => {
|
|
256
|
+
return options?.charEncoding === "percent" ? encodeURIComponent(v) : v;
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
const encVal = encodeString(JSON.stringify(value, jsonReplacer));
|
|
260
|
+
|
|
261
|
+
return options?.explode ? encVal : `${encodeString(key)}=${encVal}`;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
export const encodeSimple = (
|
|
265
|
+
key: string,
|
|
266
|
+
value: unknown,
|
|
267
|
+
options?: { explode?: boolean; charEncoding?: "percent" | "none" },
|
|
268
|
+
) => {
|
|
269
|
+
let out = "";
|
|
270
|
+
const pairs: [string, unknown][] = options?.explode
|
|
271
|
+
? explode(key, value)
|
|
272
|
+
: [[key, value]];
|
|
273
|
+
|
|
274
|
+
const encodeString = (v: string) => {
|
|
275
|
+
return options?.charEncoding === "percent" ? encodeURIComponent(v) : v;
|
|
276
|
+
};
|
|
277
|
+
const encodeValue = (v: unknown) => encodeString(serializeValue(v));
|
|
278
|
+
|
|
279
|
+
pairs.forEach(([pk, pv]) => {
|
|
280
|
+
let tmp = "";
|
|
281
|
+
|
|
282
|
+
if (pv === undefined) {
|
|
283
|
+
return;
|
|
284
|
+
} else if (Array.isArray(pv)) {
|
|
285
|
+
tmp = mapDefined(pv, (v) => `${encodeValue(v)}`).join(",");
|
|
286
|
+
} else if (isPlainObject(pv)) {
|
|
287
|
+
tmp = mapDefinedEntries(Object.entries(pv), ([k, v]) => {
|
|
288
|
+
return `,${encodeString(k)},${encodeValue(v)}`;
|
|
289
|
+
}).join("");
|
|
290
|
+
tmp = tmp.slice(1);
|
|
291
|
+
} else {
|
|
292
|
+
const k = options?.explode && isPlainObject(value) ? `${pk}=` : "";
|
|
293
|
+
tmp = `${k}${encodeValue(pv)}`;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
// If we end up with the nothing then skip forward
|
|
297
|
+
if (!tmp) {
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
out += `,${tmp}`;
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
return out.slice(1);
|
|
305
|
+
};
|
|
306
|
+
|
|
307
|
+
function explode(key: string, value: unknown): [string, unknown][] {
|
|
308
|
+
if (Array.isArray(value)) {
|
|
309
|
+
return value.map((v) => [key, v]);
|
|
310
|
+
} else if (isPlainObject(value)) {
|
|
311
|
+
const o = value ?? {};
|
|
312
|
+
return Object.entries(o).map(([k, v]) => [k, v]);
|
|
313
|
+
} else {
|
|
314
|
+
return [[key, value]];
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
function isPlainObject(value: unknown): value is object {
|
|
319
|
+
if (typeof value !== "object" || value == null) return false;
|
|
320
|
+
const proto = Object.getPrototypeOf(value);
|
|
321
|
+
return proto === null || proto === Object.prototype;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
function serializeValue(value: unknown): string {
|
|
325
|
+
if (value === null) {
|
|
326
|
+
return "null";
|
|
327
|
+
} else if (typeof value === "undefined") {
|
|
328
|
+
return "";
|
|
329
|
+
} else if (value instanceof Date) {
|
|
330
|
+
return value.toISOString();
|
|
331
|
+
} else if (value instanceof Uint8Array) {
|
|
332
|
+
return bytesToBase64(value);
|
|
333
|
+
} else if (typeof value === "object") {
|
|
334
|
+
return JSON.stringify(value, jsonReplacer);
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
return `${value}`;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
function jsonReplacer(_: string, value: unknown) {
|
|
341
|
+
if (value instanceof Uint8Array) {
|
|
342
|
+
return bytesToBase64(value);
|
|
343
|
+
} else {
|
|
344
|
+
return value;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
function mapDefined<T, R>(inp: T[], mapper: (v: T) => R): R[] {
|
|
349
|
+
return inp.reduce<R[]>((acc, v) => {
|
|
350
|
+
if (v === undefined) {
|
|
351
|
+
return acc;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
const m = mapper(v);
|
|
355
|
+
if (m === undefined) {
|
|
356
|
+
return acc;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
acc.push(m);
|
|
360
|
+
|
|
361
|
+
return acc;
|
|
362
|
+
}, []);
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
function mapDefinedEntries<K, V, R>(
|
|
366
|
+
inp: Iterable<[K, V]>,
|
|
367
|
+
mapper: (v: [K, V]) => R,
|
|
368
|
+
): R[] {
|
|
369
|
+
const acc: R[] = [];
|
|
370
|
+
for (const [k, v] of inp) {
|
|
371
|
+
if (v === undefined) {
|
|
372
|
+
continue;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
const m = mapper([k, v]);
|
|
376
|
+
if (m === undefined) {
|
|
377
|
+
continue;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
acc.push(m);
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
return acc;
|
|
384
|
+
}
|
package/src/lib/http.ts
ADDED
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export type Fetcher = (
|
|
6
|
+
input: RequestInfo | URL,
|
|
7
|
+
init?: RequestInit,
|
|
8
|
+
) => Promise<Response>;
|
|
9
|
+
|
|
10
|
+
type Awaitable<T> = T | Promise<T>;
|
|
11
|
+
|
|
12
|
+
const DEFAULT_FETCHER: Fetcher = (input, init) => fetch(input, init);
|
|
13
|
+
|
|
14
|
+
export interface HTTPClientOptions {
|
|
15
|
+
fetcher?: Fetcher;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
type BeforeRequestHook = (req: Request) => Awaitable<Request | void>;
|
|
19
|
+
type RequestErrorHook = (err: unknown, req: Request) => Awaitable<void>;
|
|
20
|
+
type ResponseHook = (res: Response, req: Request) => Awaitable<void>;
|
|
21
|
+
|
|
22
|
+
export class HTTPClient {
|
|
23
|
+
private fetcher: Fetcher;
|
|
24
|
+
private requestHooks: BeforeRequestHook[] = [];
|
|
25
|
+
private requestErrorHooks: RequestErrorHook[] = [];
|
|
26
|
+
private responseHooks: ResponseHook[] = [];
|
|
27
|
+
|
|
28
|
+
constructor(private options: HTTPClientOptions = {}) {
|
|
29
|
+
this.fetcher = options.fetcher || DEFAULT_FETCHER;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async request(request: Request): Promise<Response> {
|
|
33
|
+
let req = request;
|
|
34
|
+
for (const hook of this.requestHooks) {
|
|
35
|
+
const nextRequest = await hook(req);
|
|
36
|
+
if (nextRequest) {
|
|
37
|
+
req = nextRequest;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
try {
|
|
42
|
+
const res = await this.fetcher(req);
|
|
43
|
+
|
|
44
|
+
for (const hook of this.responseHooks) {
|
|
45
|
+
await hook(res, req);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return res;
|
|
49
|
+
} catch (err) {
|
|
50
|
+
for (const hook of this.requestErrorHooks) {
|
|
51
|
+
await hook(err, req);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
throw err;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Registers a hook that is called before a request is made. The hook function
|
|
60
|
+
* can mutate the request or return a new request. This may be useful to add
|
|
61
|
+
* additional information to request such as request IDs and tracing headers.
|
|
62
|
+
*/
|
|
63
|
+
addHook(hook: "beforeRequest", fn: BeforeRequestHook): this;
|
|
64
|
+
/**
|
|
65
|
+
* Registers a hook that is called when a request cannot be made due to a
|
|
66
|
+
* network error.
|
|
67
|
+
*/
|
|
68
|
+
addHook(hook: "requestError", fn: RequestErrorHook): this;
|
|
69
|
+
/**
|
|
70
|
+
* Registers a hook that is called when a response has been received from the
|
|
71
|
+
* server.
|
|
72
|
+
*/
|
|
73
|
+
addHook(hook: "response", fn: ResponseHook): this;
|
|
74
|
+
addHook(
|
|
75
|
+
...args:
|
|
76
|
+
| [hook: "beforeRequest", fn: BeforeRequestHook]
|
|
77
|
+
| [hook: "requestError", fn: RequestErrorHook]
|
|
78
|
+
| [hook: "response", fn: ResponseHook]
|
|
79
|
+
) {
|
|
80
|
+
if (args[0] === "beforeRequest") {
|
|
81
|
+
this.requestHooks.push(args[1]);
|
|
82
|
+
} else if (args[0] === "requestError") {
|
|
83
|
+
this.requestErrorHooks.push(args[1]);
|
|
84
|
+
} else if (args[0] === "response") {
|
|
85
|
+
this.responseHooks.push(args[1]);
|
|
86
|
+
} else {
|
|
87
|
+
throw new Error(`Invalid hook type: ${args[0]}`);
|
|
88
|
+
}
|
|
89
|
+
return this;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** Removes a hook that was previously registered with `addHook`. */
|
|
93
|
+
removeHook(hook: "beforeRequest", fn: BeforeRequestHook): this;
|
|
94
|
+
/** Removes a hook that was previously registered with `addHook`. */
|
|
95
|
+
removeHook(hook: "requestError", fn: RequestErrorHook): this;
|
|
96
|
+
/** Removes a hook that was previously registered with `addHook`. */
|
|
97
|
+
removeHook(hook: "response", fn: ResponseHook): this;
|
|
98
|
+
removeHook(
|
|
99
|
+
...args:
|
|
100
|
+
| [hook: "beforeRequest", fn: BeforeRequestHook]
|
|
101
|
+
| [hook: "requestError", fn: RequestErrorHook]
|
|
102
|
+
| [hook: "response", fn: ResponseHook]
|
|
103
|
+
) {
|
|
104
|
+
let target: unknown[];
|
|
105
|
+
if (args[0] === "beforeRequest") {
|
|
106
|
+
target = this.requestHooks;
|
|
107
|
+
} else if (args[0] === "requestError") {
|
|
108
|
+
target = this.requestErrorHooks;
|
|
109
|
+
} else if (args[0] === "response") {
|
|
110
|
+
target = this.responseHooks;
|
|
111
|
+
} else {
|
|
112
|
+
throw new Error(`Invalid hook type: ${args[0]}`);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const index = target.findIndex((v) => v === args[1]);
|
|
116
|
+
if (index >= 0) {
|
|
117
|
+
target.splice(index, 1);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return this;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
clone() {
|
|
124
|
+
const child = new HTTPClient(this.options);
|
|
125
|
+
child.requestHooks = this.requestHooks.slice();
|
|
126
|
+
child.requestErrorHooks = this.requestErrorHooks.slice();
|
|
127
|
+
child.responseHooks = this.responseHooks.slice();
|
|
128
|
+
|
|
129
|
+
return child;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export function matchContentType(response: Response, pattern: string): boolean {
|
|
134
|
+
if (pattern === "*" || pattern === "*/*") {
|
|
135
|
+
return true;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const contentType =
|
|
139
|
+
response.headers.get("content-type") ?? "application/octet-stream";
|
|
140
|
+
|
|
141
|
+
const idx = contentType.split(";").findIndex((raw) => {
|
|
142
|
+
const ctype = raw.trim();
|
|
143
|
+
if (ctype === pattern) {
|
|
144
|
+
return true;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const parts = ctype.split("/");
|
|
148
|
+
if (parts.length !== 2) {
|
|
149
|
+
return false;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
return `${parts[0]}/*` === pattern || `*/${parts[1]}` === pattern;
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
return idx >= 0;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const codeRangeRE = new RegExp("^[0-9]xx$", "i");
|
|
159
|
+
|
|
160
|
+
export function matchStatusCode(
|
|
161
|
+
response: Response,
|
|
162
|
+
codes: number | string | (number | string)[],
|
|
163
|
+
) {
|
|
164
|
+
const actual = `${response.status}`;
|
|
165
|
+
const expectedCodes = Array.isArray(codes) ? codes : [codes];
|
|
166
|
+
if (!expectedCodes.length) {
|
|
167
|
+
return false;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
return expectedCodes.some((ec) => {
|
|
171
|
+
const code = `${ec}`;
|
|
172
|
+
|
|
173
|
+
if (code === "default") {
|
|
174
|
+
return true;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
if (!codeRangeRE.test(`${code}`)) {
|
|
178
|
+
return code === actual;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const expectFamily = code.charAt(0);
|
|
182
|
+
if (!expectFamily) {
|
|
183
|
+
throw new Error("Invalid status code range");
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
const actualFamily = actual.charAt(0);
|
|
187
|
+
if (!actualFamily) {
|
|
188
|
+
throw new Error(`Invalid response status code: ${actual}`);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
return actualFamily === expectFamily;
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
export function matchResponse(
|
|
196
|
+
response: Response,
|
|
197
|
+
code: number | string | (number | string)[],
|
|
198
|
+
contentTypePattern: string,
|
|
199
|
+
): boolean {
|
|
200
|
+
return (
|
|
201
|
+
matchStatusCode(response, code) &&
|
|
202
|
+
matchContentType(response, contentTypePattern)
|
|
203
|
+
);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
const headerValRE = /, */;
|
|
207
|
+
export function unpackHeaders(headers: Headers): Record<string, string[]> {
|
|
208
|
+
const out: Record<string, string[]> = {};
|
|
209
|
+
|
|
210
|
+
for (const [k, v] of headers.entries()) {
|
|
211
|
+
out[k] = v.split(headerValRE);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
return out;
|
|
215
|
+
}
|