@stigg/typescript 0.1.0-alpha.1 → 0.1.0-alpha.11
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 +158 -0
- package/README.md +40 -0
- package/client.d.mts +6 -8
- package/client.d.mts.map +1 -1
- package/client.d.ts +6 -8
- package/client.d.ts.map +1 -1
- package/client.js +23 -21
- package/client.js.map +1 -1
- package/client.mjs +24 -22
- package/client.mjs.map +1 -1
- package/core/pagination.d.mts +11 -5
- package/core/pagination.d.mts.map +1 -1
- package/core/pagination.d.ts +11 -5
- package/core/pagination.d.ts.map +1 -1
- package/core/pagination.js +9 -9
- package/core/pagination.js.map +1 -1
- package/core/pagination.mjs +9 -9
- package/core/pagination.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/package.json +1 -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 +1298 -0
- package/resources/v1/addons/addons.d.mts.map +1 -0
- package/resources/v1/addons/addons.d.ts +1298 -0
- package/resources/v1/addons/addons.d.ts.map +1 -0
- package/resources/v1/addons/addons.js +78 -0
- package/resources/v1/addons/addons.js.map +1 -0
- package/resources/v1/addons/addons.mjs +73 -0
- package/resources/v1/addons/addons.mjs.map +1 -0
- package/resources/v1/addons/entitlements.d.mts +747 -0
- package/resources/v1/addons/entitlements.d.mts.map +1 -0
- package/resources/v1/addons/entitlements.d.ts +747 -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 +154 -157
- package/resources/v1/coupons.d.mts.map +1 -1
- package/resources/v1/coupons.d.ts +154 -157
- package/resources/v1/coupons.d.ts.map +1 -1
- package/resources/v1/coupons.js +21 -4
- package/resources/v1/coupons.js.map +1 -1
- package/resources/v1/coupons.mjs +21 -4
- package/resources/v1/coupons.mjs.map +1 -1
- package/resources/v1/customers/customers.d.mts +247 -118
- package/resources/v1/customers/customers.d.mts.map +1 -1
- package/resources/v1/customers/customers.d.ts +247 -118
- package/resources/v1/customers/customers.d.ts.map +1 -1
- package/resources/v1/customers/customers.js +37 -16
- package/resources/v1/customers/customers.js.map +1 -1
- package/resources/v1/customers/customers.mjs +37 -16
- 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 +7 -2
- package/resources/v1/customers/payment-method.d.mts.map +1 -1
- package/resources/v1/customers/payment-method.d.ts +7 -2
- package/resources/v1/customers/payment-method.d.ts.map +1 -1
- package/resources/v1/customers/payment-method.js +4 -2
- package/resources/v1/customers/payment-method.js.map +1 -1
- package/resources/v1/customers/payment-method.mjs +4 -2
- package/resources/v1/customers/payment-method.mjs.map +1 -1
- package/resources/v1/customers/promotional-entitlements.d.mts +498 -0
- package/resources/v1/customers/promotional-entitlements.d.mts.map +1 -0
- package/resources/v1/customers/promotional-entitlements.d.ts +498 -0
- package/resources/v1/customers/promotional-entitlements.d.ts.map +1 -0
- package/resources/v1/customers/promotional-entitlements.js +32 -0
- package/resources/v1/customers/promotional-entitlements.js.map +1 -0
- package/resources/v1/customers/promotional-entitlements.mjs +28 -0
- package/resources/v1/customers/promotional-entitlements.mjs.map +1 -0
- package/resources/v1/events.d.mts +63 -0
- package/resources/v1/events.d.mts.map +1 -0
- package/resources/v1/events.d.ts +63 -0
- package/resources/v1/events.d.ts.map +1 -0
- package/resources/v1/events.js +16 -0
- package/resources/v1/events.js.map +1 -0
- package/resources/v1/events.mjs +12 -0
- package/resources/v1/events.mjs.map +1 -0
- package/resources/v1/features.d.mts +444 -0
- package/resources/v1/features.d.mts.map +1 -0
- package/resources/v1/features.d.ts +444 -0
- package/resources/v1/features.d.ts.map +1 -0
- package/resources/v1/features.js +51 -0
- package/resources/v1/features.js.map +1 -0
- package/resources/v1/features.mjs +47 -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 +747 -0
- package/resources/v1/plans/entitlements.d.mts.map +1 -0
- package/resources/v1/plans/entitlements.d.ts +747 -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 +973 -0
- package/resources/v1/plans/plans.d.mts.map +1 -0
- package/resources/v1/plans/plans.d.ts +973 -0
- package/resources/v1/plans/plans.d.ts.map +1 -0
- package/resources/v1/plans/plans.js +76 -0
- package/resources/v1/plans/plans.js.map +1 -0
- package/resources/v1/plans/plans.mjs +71 -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 +332 -0
- package/resources/v1/products.d.mts.map +1 -0
- package/resources/v1/products.d.ts +332 -0
- package/resources/v1/products.d.ts.map +1 -0
- package/resources/v1/products.js +52 -0
- package/resources/v1/products.js.map +1 -0
- package/resources/v1/products.mjs +48 -0
- package/resources/v1/products.mjs.map +1 -0
- package/resources/v1/subscriptions/future-update.d.mts +12 -19
- package/resources/v1/subscriptions/future-update.d.mts.map +1 -1
- package/resources/v1/subscriptions/future-update.d.ts +12 -19
- package/resources/v1/subscriptions/future-update.d.ts.map +1 -1
- package/resources/v1/subscriptions/future-update.js +3 -2
- package/resources/v1/subscriptions/future-update.js.map +1 -1
- package/resources/v1/subscriptions/future-update.mjs +3 -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 +34 -0
- package/resources/v1/subscriptions/invoice.d.mts.map +1 -0
- package/resources/v1/subscriptions/invoice.d.ts +34 -0
- package/resources/v1/subscriptions/invoice.d.ts.map +1 -0
- package/resources/v1/subscriptions/invoice.js +17 -0
- package/resources/v1/subscriptions/invoice.js.map +1 -0
- package/resources/v1/subscriptions/invoice.mjs +13 -0
- package/resources/v1/subscriptions/invoice.mjs.map +1 -0
- package/resources/v1/subscriptions/subscriptions.d.mts +1565 -518
- package/resources/v1/subscriptions/subscriptions.d.mts.map +1 -1
- package/resources/v1/subscriptions/subscriptions.d.ts +1565 -518
- package/resources/v1/subscriptions/subscriptions.d.ts.map +1 -1
- package/resources/v1/subscriptions/subscriptions.js +52 -12
- package/resources/v1/subscriptions/subscriptions.js.map +1 -1
- package/resources/v1/subscriptions/subscriptions.mjs +53 -13
- package/resources/v1/subscriptions/subscriptions.mjs.map +1 -1
- package/resources/v1/subscriptions/usage.d.mts +98 -0
- package/resources/v1/subscriptions/usage.d.mts.map +1 -0
- package/resources/v1/subscriptions/usage.d.ts +98 -0
- package/resources/v1/subscriptions/usage.d.ts.map +1 -0
- package/resources/v1/subscriptions/usage.js +24 -0
- package/resources/v1/subscriptions/usage.js.map +1 -0
- package/resources/v1/subscriptions/usage.mjs +20 -0
- package/resources/v1/subscriptions/usage.mjs.map +1 -0
- package/resources/v1/usage.d.mts +230 -0
- package/resources/v1/usage.d.mts.map +1 -0
- package/resources/v1/usage.d.ts +230 -0
- package/resources/v1/usage.d.ts.map +1 -0
- package/resources/v1/usage.js +24 -0
- package/resources/v1/usage.js.map +1 -0
- package/resources/v1/usage.mjs +20 -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 +33 -40
- package/src/core/pagination.ts +24 -18
- 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/resources/index.ts +1 -7
- package/src/resources/v1/addons/addons.ts +3245 -0
- package/src/resources/v1/addons/entitlements.ts +976 -0
- package/src/resources/v1/addons/index.ts +26 -0
- package/src/resources/v1/addons.ts +3 -0
- package/src/resources/v1/coupons.ts +311 -436
- package/src/resources/v1/customers/customers.ts +334 -153
- package/src/resources/v1/customers/index.ts +17 -2
- package/src/resources/v1/customers/payment-method.ts +7 -2
- package/src/resources/v1/customers/promotional-entitlements.ts +669 -0
- package/src/resources/v1/events.ts +74 -0
- package/src/resources/v1/features.ts +571 -0
- package/src/resources/v1/index.ts +73 -15
- package/src/resources/v1/plans/entitlements.ts +968 -0
- package/src/resources/v1/plans/index.ts +24 -0
- package/src/resources/v1/plans/plans.ts +2032 -0
- package/src/resources/v1/plans.ts +3 -0
- package/src/resources/v1/products.ts +423 -0
- package/src/resources/v1/subscriptions/future-update.ts +12 -27
- package/src/resources/v1/subscriptions/index.ts +16 -11
- package/src/resources/v1/subscriptions/invoice.ts +42 -0
- package/src/resources/v1/subscriptions/subscriptions.ts +3341 -832
- package/src/resources/v1/subscriptions/usage.ts +126 -0
- package/src/resources/v1/usage.ts +284 -0
- package/src/resources/v1/v1.ts +174 -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/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 * as qs from './internal/qs';
|
|
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
|
-
* Basic re-implementation of `qs.stringify` for primitive types.
|
|
223
|
-
*/
|
|
224
216
|
protected stringifyQuery(query: Record<string, unknown>): string {
|
|
225
|
-
return
|
|
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('&');
|
|
217
|
+
return qs.stringify(query, { arrayFormat: 'comma' });
|
|
239
218
|
}
|
|
240
219
|
|
|
241
220
|
private getUserAgent(): string {
|
|
@@ -456,7 +435,7 @@ export class Stigg {
|
|
|
456
435
|
loggerFor(this).info(`${responseInfo} - ${retryMessage}`);
|
|
457
436
|
|
|
458
437
|
const errText = await response.text().catch((err: any) => castToError(err).message);
|
|
459
|
-
const errJSON = safeJSON(errText);
|
|
438
|
+
const errJSON = safeJSON(errText) as any;
|
|
460
439
|
const errMessage = errJSON ? undefined : errText;
|
|
461
440
|
|
|
462
441
|
loggerFor(this).debug(
|
|
@@ -493,9 +472,14 @@ export class Stigg {
|
|
|
493
472
|
getAPIList<Item, PageClass extends Pagination.AbstractPage<Item> = Pagination.AbstractPage<Item>>(
|
|
494
473
|
path: string,
|
|
495
474
|
Page: new (...args: any[]) => PageClass,
|
|
496
|
-
opts?: RequestOptions
|
|
475
|
+
opts?: PromiseOrValue<RequestOptions>,
|
|
497
476
|
): Pagination.PagePromise<PageClass, Item> {
|
|
498
|
-
return this.requestAPIList(
|
|
477
|
+
return this.requestAPIList(
|
|
478
|
+
Page,
|
|
479
|
+
opts && 'then' in opts ?
|
|
480
|
+
opts.then((opts) => ({ method: 'get', path, ...opts }))
|
|
481
|
+
: { method: 'get', path, ...opts },
|
|
482
|
+
);
|
|
499
483
|
}
|
|
500
484
|
|
|
501
485
|
requestAPIList<
|
|
@@ -503,7 +487,7 @@ export class Stigg {
|
|
|
503
487
|
PageClass extends Pagination.AbstractPage<Item> = Pagination.AbstractPage<Item>,
|
|
504
488
|
>(
|
|
505
489
|
Page: new (...args: ConstructorParameters<typeof Pagination.AbstractPage>) => PageClass,
|
|
506
|
-
options: FinalRequestOptions
|
|
490
|
+
options: PromiseOrValue<FinalRequestOptions>,
|
|
507
491
|
): Pagination.PagePromise<PageClass, Item> {
|
|
508
492
|
const request = this.makeRequest(options, null, undefined);
|
|
509
493
|
return new Pagination.PagePromise<PageClass, Item>(this as any as Stigg, request, Page);
|
|
@@ -516,9 +500,10 @@ export class Stigg {
|
|
|
516
500
|
controller: AbortController,
|
|
517
501
|
): Promise<Response> {
|
|
518
502
|
const { signal, method, ...options } = init || {};
|
|
519
|
-
|
|
503
|
+
const abort = this._makeAbort(controller);
|
|
504
|
+
if (signal) signal.addEventListener('abort', abort, { once: true });
|
|
520
505
|
|
|
521
|
-
const timeout = setTimeout(
|
|
506
|
+
const timeout = setTimeout(abort, ms);
|
|
522
507
|
|
|
523
508
|
const isReadableBody =
|
|
524
509
|
((globalThis as any).ReadableStream && options.body instanceof (globalThis as any).ReadableStream) ||
|
|
@@ -685,6 +670,12 @@ export class Stigg {
|
|
|
685
670
|
return headers.values;
|
|
686
671
|
}
|
|
687
672
|
|
|
673
|
+
private _makeAbort(controller: AbortController) {
|
|
674
|
+
// note: we can't just inline this method inside `fetchWithTimeout()` because then the closure
|
|
675
|
+
// would capture all request options, and cause a memory leak.
|
|
676
|
+
return () => controller.abort();
|
|
677
|
+
}
|
|
678
|
+
|
|
688
679
|
private buildBody({ options: { body, headers: rawHeaders } }: { options: FinalRequestOptions }): {
|
|
689
680
|
bodyHeaders: HeadersLike;
|
|
690
681
|
body: BodyInit | undefined;
|
|
@@ -717,6 +708,14 @@ export class Stigg {
|
|
|
717
708
|
(Symbol.iterator in body && 'next' in body && typeof body.next === 'function'))
|
|
718
709
|
) {
|
|
719
710
|
return { bodyHeaders: undefined, body: Shims.ReadableStreamFrom(body as AsyncIterable<Uint8Array>) };
|
|
711
|
+
} else if (
|
|
712
|
+
typeof body === 'object' &&
|
|
713
|
+
headers.values.get('content-type') === 'application/x-www-form-urlencoded'
|
|
714
|
+
) {
|
|
715
|
+
return {
|
|
716
|
+
bodyHeaders: { 'content-type': 'application/x-www-form-urlencoded' },
|
|
717
|
+
body: this.stringifyQuery(body as Record<string, unknown>),
|
|
718
|
+
};
|
|
720
719
|
} else {
|
|
721
720
|
return this.#encoder({ body, headers });
|
|
722
721
|
}
|
|
@@ -755,11 +754,5 @@ export declare namespace Stigg {
|
|
|
755
754
|
type MyCursorIDPageResponse as MyCursorIDPageResponse,
|
|
756
755
|
};
|
|
757
756
|
|
|
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
|
-
};
|
|
757
|
+
export { V1 as V1 };
|
|
765
758
|
}
|
package/src/core/pagination.ts
CHANGED
|
@@ -109,22 +109,31 @@ export class PagePromise<
|
|
|
109
109
|
|
|
110
110
|
export interface MyCursorIDPageResponse<Item> {
|
|
111
111
|
data: Array<Item>;
|
|
112
|
+
|
|
113
|
+
pagination: MyCursorIDPageResponse.Pagination;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export namespace MyCursorIDPageResponse {
|
|
117
|
+
export interface Pagination {
|
|
118
|
+
next?: string;
|
|
119
|
+
|
|
120
|
+
prev?: string;
|
|
121
|
+
}
|
|
112
122
|
}
|
|
113
123
|
|
|
114
124
|
export interface MyCursorIDPageParams {
|
|
115
|
-
|
|
125
|
+
after?: string;
|
|
116
126
|
|
|
117
|
-
|
|
127
|
+
before?: string;
|
|
118
128
|
|
|
119
129
|
limit?: number;
|
|
120
130
|
}
|
|
121
131
|
|
|
122
|
-
export class MyCursorIDPage<Item extends
|
|
123
|
-
extends AbstractPage<Item>
|
|
124
|
-
implements MyCursorIDPageResponse<Item>
|
|
125
|
-
{
|
|
132
|
+
export class MyCursorIDPage<Item> extends AbstractPage<Item> implements MyCursorIDPageResponse<Item> {
|
|
126
133
|
data: Array<Item>;
|
|
127
134
|
|
|
135
|
+
pagination: MyCursorIDPageResponse.Pagination;
|
|
136
|
+
|
|
128
137
|
constructor(
|
|
129
138
|
client: Stigg,
|
|
130
139
|
response: Response,
|
|
@@ -134,6 +143,7 @@ export class MyCursorIDPage<Item extends { cursor_id: string }>
|
|
|
134
143
|
super(client, response, body, options);
|
|
135
144
|
|
|
136
145
|
this.data = body.data || [];
|
|
146
|
+
this.pagination = body.pagination || {};
|
|
137
147
|
}
|
|
138
148
|
|
|
139
149
|
getPaginatedItems(): Item[] {
|
|
@@ -141,14 +151,10 @@ export class MyCursorIDPage<Item extends { cursor_id: string }>
|
|
|
141
151
|
}
|
|
142
152
|
|
|
143
153
|
nextPageRequestOptions(): PageRequestOptions | null {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
);
|
|
149
|
-
if (isForwards) {
|
|
150
|
-
const cursorID = data[data.length - 1]?.cursor_id;
|
|
151
|
-
if (!cursorID) {
|
|
154
|
+
if ((this.options.query as Record<string, unknown>)?.['before']) {
|
|
155
|
+
// in reverse
|
|
156
|
+
const prev = this.pagination?.prev;
|
|
157
|
+
if (!prev) {
|
|
152
158
|
return null;
|
|
153
159
|
}
|
|
154
160
|
|
|
@@ -156,13 +162,13 @@ export class MyCursorIDPage<Item extends { cursor_id: string }>
|
|
|
156
162
|
...this.options,
|
|
157
163
|
query: {
|
|
158
164
|
...maybeObj(this.options.query),
|
|
159
|
-
|
|
165
|
+
before: prev,
|
|
160
166
|
},
|
|
161
167
|
};
|
|
162
168
|
}
|
|
163
169
|
|
|
164
|
-
const
|
|
165
|
-
if (!
|
|
170
|
+
const cursor = this.pagination?.next;
|
|
171
|
+
if (!cursor) {
|
|
166
172
|
return null;
|
|
167
173
|
}
|
|
168
174
|
|
|
@@ -170,7 +176,7 @@ export class MyCursorIDPage<Item extends { cursor_id: string }>
|
|
|
170
176
|
...this.options,
|
|
171
177
|
query: {
|
|
172
178
|
...maybeObj(this.options.query),
|
|
173
|
-
|
|
179
|
+
after: cursor,
|
|
174
180
|
},
|
|
175
181
|
};
|
|
176
182
|
}
|
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';
|