@predictorsdk/client 0.3.0 → 0.3.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/dist/BaseClient.d.ts +3 -0
- package/dist/BaseClient.js +15 -0
- package/dist/Client.d.ts +3 -1
- package/dist/Client.js +40 -10
- package/dist/api/errors/BadGatewayError.d.ts +1 -0
- package/dist/api/errors/BadRequestError.d.ts +1 -0
- package/dist/api/errors/ForbiddenError.d.ts +1 -0
- package/dist/api/errors/PaymentRequiredError.d.ts +7 -0
- package/dist/api/errors/{InternalServerError.js → PaymentRequiredError.js} +3 -3
- package/dist/api/errors/ServiceUnavailableError.d.ts +1 -0
- package/dist/api/errors/TooManyRequestsError.d.ts +1 -0
- package/dist/api/errors/UnauthorizedError.d.ts +1 -0
- package/dist/api/errors/index.d.ts +1 -1
- package/dist/api/errors/index.js +1 -1
- package/dist/api/types/PaymentRequiredErrorAction.d.ts +6 -0
- package/dist/api/types/PaymentRequiredErrorAction.js +6 -0
- package/dist/api/types/PaymentRequiredErrorBody.d.ts +20 -0
- package/dist/api/types/PaymentRequiredErrorBody.js +2 -0
- package/dist/api/types/index.d.ts +2 -0
- package/dist/api/types/index.js +2 -0
- package/dist/core/auth/AuthProvider.d.ts +1 -0
- package/dist/core/auth/AuthProvider.js +6 -1
- package/dist/core/auth/index.d.ts +1 -1
- package/dist/core/auth/index.js +1 -0
- package/dist/core/fetcher/Fetcher.d.ts +6 -0
- package/dist/core/fetcher/Fetcher.js +9 -8
- package/dist/core/fetcher/requestWithRetries.js +4 -1
- package/dist/core/schemas/builders/enum/enum.d.ts +1 -0
- package/dist/core/schemas/builders/enum/enum.js +6 -0
- package/dist/core/schemas/builders/enum/index.d.ts +1 -1
- package/dist/core/schemas/builders/enum/index.js +1 -1
- package/dist/core/schemas/builders/schema-utils/JsonError.js +2 -1
- package/dist/core/schemas/builders/schema-utils/ParseError.js +2 -1
- package/dist/core/url/QueryStringBuilder.d.ts +47 -0
- package/dist/core/url/QueryStringBuilder.js +78 -0
- package/dist/core/url/index.d.ts +1 -0
- package/dist/core/url/index.js +1 -0
- package/dist/core/url/qs.d.ts +2 -1
- package/dist/core/url/qs.js +24 -12
- package/dist/serialization/types/PaymentRequiredErrorAction.d.ts +7 -0
- package/dist/serialization/types/PaymentRequiredErrorAction.js +3 -0
- package/dist/serialization/types/PaymentRequiredErrorBody.d.ts +17 -0
- package/dist/serialization/types/PaymentRequiredErrorBody.js +13 -0
- package/dist/serialization/types/index.d.ts +2 -0
- package/dist/serialization/types/index.js +2 -0
- package/package.json +1 -1
- package/dist/api/errors/InternalServerError.d.ts +0 -6
package/dist/BaseClient.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { BearerAuthProvider } from "./auth/BearerAuthProvider.js";
|
|
2
2
|
import * as core from "./core/index.js";
|
|
3
3
|
import type * as environments from "./environments.js";
|
|
4
|
+
export type AuthOption = false | core.AuthProvider["getAuthRequest"] | core.AuthProvider | BearerAuthProvider.AuthOptions;
|
|
4
5
|
export type BaseClientOptions = {
|
|
5
6
|
environment?: core.Supplier<environments.PredictorSDKEnvironment | string>;
|
|
6
7
|
/** Specify a custom URL to connect the client to. */
|
|
@@ -15,6 +16,8 @@ export type BaseClientOptions = {
|
|
|
15
16
|
fetch?: typeof fetch;
|
|
16
17
|
/** Configure logging for the client. */
|
|
17
18
|
logging?: core.logging.LogConfig | core.logging.Logger;
|
|
19
|
+
/** Override auth. Pass false to disable, a function returning auth headers, an AuthProvider, or auth options. */
|
|
20
|
+
auth?: AuthOption;
|
|
18
21
|
} & BearerAuthProvider.AuthOptions;
|
|
19
22
|
export interface BaseRequestOptions {
|
|
20
23
|
/** The maximum time to wait for a response in seconds. */
|
package/dist/BaseClient.js
CHANGED
|
@@ -16,6 +16,21 @@ export function normalizeClientOptions(options) {
|
|
|
16
16
|
}
|
|
17
17
|
export function normalizeClientOptionsWithAuth(options) {
|
|
18
18
|
const normalized = normalizeClientOptions(options);
|
|
19
|
+
if (options.auth === false) {
|
|
20
|
+
normalized.authProvider = new core.NoOpAuthProvider();
|
|
21
|
+
return normalized;
|
|
22
|
+
}
|
|
23
|
+
if (options.auth != null) {
|
|
24
|
+
if (typeof options.auth === "function") {
|
|
25
|
+
normalized.authProvider = { getAuthRequest: options.auth };
|
|
26
|
+
return normalized;
|
|
27
|
+
}
|
|
28
|
+
if (core.isAuthProvider(options.auth)) {
|
|
29
|
+
normalized.authProvider = options.auth;
|
|
30
|
+
return normalized;
|
|
31
|
+
}
|
|
32
|
+
Object.assign(normalized, options.auth);
|
|
33
|
+
}
|
|
19
34
|
const normalizedWithNoOpAuthProvider = withNoOpAuthProvider(normalized);
|
|
20
35
|
normalized.authProvider ??= new BearerAuthProvider(normalizedWithNoOpAuthProvider);
|
|
21
36
|
return normalized;
|
package/dist/Client.d.ts
CHANGED
|
@@ -18,6 +18,7 @@ export declare class PredictorSDKClient {
|
|
|
18
18
|
*
|
|
19
19
|
* @throws {@link PredictorSDK.BadRequestError}
|
|
20
20
|
* @throws {@link PredictorSDK.UnauthorizedError}
|
|
21
|
+
* @throws {@link PredictorSDK.PaymentRequiredError}
|
|
21
22
|
* @throws {@link PredictorSDK.ForbiddenError}
|
|
22
23
|
* @throws {@link PredictorSDK.TooManyRequestsError}
|
|
23
24
|
* @throws {@link PredictorSDK.ServiceUnavailableError}
|
|
@@ -35,9 +36,9 @@ export declare class PredictorSDKClient {
|
|
|
35
36
|
*
|
|
36
37
|
* @throws {@link PredictorSDK.BadRequestError}
|
|
37
38
|
* @throws {@link PredictorSDK.UnauthorizedError}
|
|
39
|
+
* @throws {@link PredictorSDK.PaymentRequiredError}
|
|
38
40
|
* @throws {@link PredictorSDK.ForbiddenError}
|
|
39
41
|
* @throws {@link PredictorSDK.TooManyRequestsError}
|
|
40
|
-
* @throws {@link PredictorSDK.InternalServerError}
|
|
41
42
|
* @throws {@link PredictorSDK.ServiceUnavailableError}
|
|
42
43
|
*
|
|
43
44
|
* @example
|
|
@@ -53,6 +54,7 @@ export declare class PredictorSDKClient {
|
|
|
53
54
|
*
|
|
54
55
|
* @throws {@link PredictorSDK.BadRequestError}
|
|
55
56
|
* @throws {@link PredictorSDK.UnauthorizedError}
|
|
57
|
+
* @throws {@link PredictorSDK.PaymentRequiredError}
|
|
56
58
|
* @throws {@link PredictorSDK.ForbiddenError}
|
|
57
59
|
* @throws {@link PredictorSDK.TooManyRequestsError}
|
|
58
60
|
* @throws {@link PredictorSDK.BadGatewayError}
|
package/dist/Client.js
CHANGED
|
@@ -20,6 +20,7 @@ export class PredictorSDKClient {
|
|
|
20
20
|
*
|
|
21
21
|
* @throws {@link PredictorSDK.BadRequestError}
|
|
22
22
|
* @throws {@link PredictorSDK.UnauthorizedError}
|
|
23
|
+
* @throws {@link PredictorSDK.PaymentRequiredError}
|
|
23
24
|
* @throws {@link PredictorSDK.ForbiddenError}
|
|
24
25
|
* @throws {@link PredictorSDK.TooManyRequestsError}
|
|
25
26
|
* @throws {@link PredictorSDK.ServiceUnavailableError}
|
|
@@ -49,7 +50,11 @@ export class PredictorSDKClient {
|
|
|
49
50
|
environments.PredictorSDKEnvironment.Production, "v1/matching-markets/sports"),
|
|
50
51
|
method: "GET",
|
|
51
52
|
headers: _headers,
|
|
52
|
-
|
|
53
|
+
queryString: core.url
|
|
54
|
+
.queryBuilder()
|
|
55
|
+
.addMany(_queryParams)
|
|
56
|
+
.mergeAdditional(requestOptions?.queryParams)
|
|
57
|
+
.build(),
|
|
53
58
|
timeoutMs: (requestOptions?.timeoutInSeconds ?? this._options?.timeoutInSeconds ?? 60) * 1000,
|
|
54
59
|
maxRetries: requestOptions?.maxRetries ?? this._options?.maxRetries,
|
|
55
60
|
abortSignal: requestOptions?.abortSignal,
|
|
@@ -86,6 +91,14 @@ export class PredictorSDKClient {
|
|
|
86
91
|
skipValidation: true,
|
|
87
92
|
breadcrumbsPrefix: ["response"],
|
|
88
93
|
}), _response.rawResponse);
|
|
94
|
+
case 402:
|
|
95
|
+
throw new PredictorSDK.PaymentRequiredError(serializers.PaymentRequiredErrorBody.parseOrThrow(_response.error.body, {
|
|
96
|
+
unrecognizedObjectKeys: "passthrough",
|
|
97
|
+
allowUnrecognizedUnionMembers: true,
|
|
98
|
+
allowUnrecognizedEnumValues: true,
|
|
99
|
+
skipValidation: true,
|
|
100
|
+
breadcrumbsPrefix: ["response"],
|
|
101
|
+
}), _response.rawResponse);
|
|
89
102
|
case 403:
|
|
90
103
|
throw new PredictorSDK.ForbiddenError(serializers.ErrorResponse.parseOrThrow(_response.error.body, {
|
|
91
104
|
unrecognizedObjectKeys: "passthrough",
|
|
@@ -128,9 +141,9 @@ export class PredictorSDKClient {
|
|
|
128
141
|
*
|
|
129
142
|
* @throws {@link PredictorSDK.BadRequestError}
|
|
130
143
|
* @throws {@link PredictorSDK.UnauthorizedError}
|
|
144
|
+
* @throws {@link PredictorSDK.PaymentRequiredError}
|
|
131
145
|
* @throws {@link PredictorSDK.ForbiddenError}
|
|
132
146
|
* @throws {@link PredictorSDK.TooManyRequestsError}
|
|
133
|
-
* @throws {@link PredictorSDK.InternalServerError}
|
|
134
147
|
* @throws {@link PredictorSDK.ServiceUnavailableError}
|
|
135
148
|
*
|
|
136
149
|
* @example
|
|
@@ -153,7 +166,11 @@ export class PredictorSDKClient {
|
|
|
153
166
|
environments.PredictorSDKEnvironment.Production, "v1/markets"),
|
|
154
167
|
method: "GET",
|
|
155
168
|
headers: _headers,
|
|
156
|
-
|
|
169
|
+
queryString: core.url
|
|
170
|
+
.queryBuilder()
|
|
171
|
+
.addMany(_queryParams)
|
|
172
|
+
.mergeAdditional(requestOptions?.queryParams)
|
|
173
|
+
.build(),
|
|
157
174
|
timeoutMs: (requestOptions?.timeoutInSeconds ?? this._options?.timeoutInSeconds ?? 60) * 1000,
|
|
158
175
|
maxRetries: requestOptions?.maxRetries ?? this._options?.maxRetries,
|
|
159
176
|
abortSignal: requestOptions?.abortSignal,
|
|
@@ -190,24 +207,24 @@ export class PredictorSDKClient {
|
|
|
190
207
|
skipValidation: true,
|
|
191
208
|
breadcrumbsPrefix: ["response"],
|
|
192
209
|
}), _response.rawResponse);
|
|
193
|
-
case
|
|
194
|
-
throw new PredictorSDK.
|
|
210
|
+
case 402:
|
|
211
|
+
throw new PredictorSDK.PaymentRequiredError(serializers.PaymentRequiredErrorBody.parseOrThrow(_response.error.body, {
|
|
195
212
|
unrecognizedObjectKeys: "passthrough",
|
|
196
213
|
allowUnrecognizedUnionMembers: true,
|
|
197
214
|
allowUnrecognizedEnumValues: true,
|
|
198
215
|
skipValidation: true,
|
|
199
216
|
breadcrumbsPrefix: ["response"],
|
|
200
217
|
}), _response.rawResponse);
|
|
201
|
-
case
|
|
202
|
-
throw new PredictorSDK.
|
|
218
|
+
case 403:
|
|
219
|
+
throw new PredictorSDK.ForbiddenError(serializers.ErrorResponse.parseOrThrow(_response.error.body, {
|
|
203
220
|
unrecognizedObjectKeys: "passthrough",
|
|
204
221
|
allowUnrecognizedUnionMembers: true,
|
|
205
222
|
allowUnrecognizedEnumValues: true,
|
|
206
223
|
skipValidation: true,
|
|
207
224
|
breadcrumbsPrefix: ["response"],
|
|
208
225
|
}), _response.rawResponse);
|
|
209
|
-
case
|
|
210
|
-
throw new PredictorSDK.
|
|
226
|
+
case 429:
|
|
227
|
+
throw new PredictorSDK.TooManyRequestsError(serializers.ErrorResponse.parseOrThrow(_response.error.body, {
|
|
211
228
|
unrecognizedObjectKeys: "passthrough",
|
|
212
229
|
allowUnrecognizedUnionMembers: true,
|
|
213
230
|
allowUnrecognizedEnumValues: true,
|
|
@@ -240,6 +257,7 @@ export class PredictorSDKClient {
|
|
|
240
257
|
*
|
|
241
258
|
* @throws {@link PredictorSDK.BadRequestError}
|
|
242
259
|
* @throws {@link PredictorSDK.UnauthorizedError}
|
|
260
|
+
* @throws {@link PredictorSDK.PaymentRequiredError}
|
|
243
261
|
* @throws {@link PredictorSDK.ForbiddenError}
|
|
244
262
|
* @throws {@link PredictorSDK.TooManyRequestsError}
|
|
245
263
|
* @throws {@link PredictorSDK.BadGatewayError}
|
|
@@ -270,7 +288,11 @@ export class PredictorSDKClient {
|
|
|
270
288
|
environments.PredictorSDKEnvironment.Production, "v1/crypto-prices/binance"),
|
|
271
289
|
method: "GET",
|
|
272
290
|
headers: _headers,
|
|
273
|
-
|
|
291
|
+
queryString: core.url
|
|
292
|
+
.queryBuilder()
|
|
293
|
+
.addMany(_queryParams)
|
|
294
|
+
.mergeAdditional(requestOptions?.queryParams)
|
|
295
|
+
.build(),
|
|
274
296
|
timeoutMs: (requestOptions?.timeoutInSeconds ?? this._options?.timeoutInSeconds ?? 60) * 1000,
|
|
275
297
|
maxRetries: requestOptions?.maxRetries ?? this._options?.maxRetries,
|
|
276
298
|
abortSignal: requestOptions?.abortSignal,
|
|
@@ -307,6 +329,14 @@ export class PredictorSDKClient {
|
|
|
307
329
|
skipValidation: true,
|
|
308
330
|
breadcrumbsPrefix: ["response"],
|
|
309
331
|
}), _response.rawResponse);
|
|
332
|
+
case 402:
|
|
333
|
+
throw new PredictorSDK.PaymentRequiredError(serializers.PaymentRequiredErrorBody.parseOrThrow(_response.error.body, {
|
|
334
|
+
unrecognizedObjectKeys: "passthrough",
|
|
335
|
+
allowUnrecognizedUnionMembers: true,
|
|
336
|
+
allowUnrecognizedEnumValues: true,
|
|
337
|
+
skipValidation: true,
|
|
338
|
+
breadcrumbsPrefix: ["response"],
|
|
339
|
+
}), _response.rawResponse);
|
|
310
340
|
case 403:
|
|
311
341
|
throw new PredictorSDK.ForbiddenError(serializers.ErrorResponse.parseOrThrow(_response.error.body, {
|
|
312
342
|
unrecognizedObjectKeys: "passthrough",
|
|
@@ -2,5 +2,6 @@ import type * as core from "../../core/index.js";
|
|
|
2
2
|
import * as errors from "../../errors/index.js";
|
|
3
3
|
import type * as PredictorSDK from "../index.js";
|
|
4
4
|
export declare class BadGatewayError extends errors.PredictorSDKError {
|
|
5
|
+
readonly body: PredictorSDK.ErrorResponse;
|
|
5
6
|
constructor(body: PredictorSDK.ErrorResponse, rawResponse?: core.RawResponse);
|
|
6
7
|
}
|
|
@@ -2,5 +2,6 @@ import type * as core from "../../core/index.js";
|
|
|
2
2
|
import * as errors from "../../errors/index.js";
|
|
3
3
|
import type * as PredictorSDK from "../index.js";
|
|
4
4
|
export declare class BadRequestError extends errors.PredictorSDKError {
|
|
5
|
+
readonly body: PredictorSDK.ErrorResponse;
|
|
5
6
|
constructor(body: PredictorSDK.ErrorResponse, rawResponse?: core.RawResponse);
|
|
6
7
|
}
|
|
@@ -2,5 +2,6 @@ import type * as core from "../../core/index.js";
|
|
|
2
2
|
import * as errors from "../../errors/index.js";
|
|
3
3
|
import type * as PredictorSDK from "../index.js";
|
|
4
4
|
export declare class ForbiddenError extends errors.PredictorSDKError {
|
|
5
|
+
readonly body: PredictorSDK.ErrorResponse;
|
|
5
6
|
constructor(body: PredictorSDK.ErrorResponse, rawResponse?: core.RawResponse);
|
|
6
7
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type * as core from "../../core/index.js";
|
|
2
|
+
import * as errors from "../../errors/index.js";
|
|
3
|
+
import type * as PredictorSDK from "../index.js";
|
|
4
|
+
export declare class PaymentRequiredError extends errors.PredictorSDKError {
|
|
5
|
+
readonly body: PredictorSDK.PaymentRequiredErrorBody;
|
|
6
|
+
constructor(body: PredictorSDK.PaymentRequiredErrorBody, rawResponse?: core.RawResponse);
|
|
7
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// This file was auto-generated by Fern from our API Definition.
|
|
2
2
|
import * as errors from "../../errors/index.js";
|
|
3
|
-
export class
|
|
3
|
+
export class PaymentRequiredError extends errors.PredictorSDKError {
|
|
4
4
|
constructor(body, rawResponse) {
|
|
5
5
|
super({
|
|
6
|
-
message: "
|
|
7
|
-
statusCode:
|
|
6
|
+
message: "PaymentRequiredError",
|
|
7
|
+
statusCode: 402,
|
|
8
8
|
body: body,
|
|
9
9
|
rawResponse: rawResponse,
|
|
10
10
|
});
|
|
@@ -2,5 +2,6 @@ import type * as core from "../../core/index.js";
|
|
|
2
2
|
import * as errors from "../../errors/index.js";
|
|
3
3
|
import type * as PredictorSDK from "../index.js";
|
|
4
4
|
export declare class ServiceUnavailableError extends errors.PredictorSDKError {
|
|
5
|
+
readonly body: PredictorSDK.ErrorResponse;
|
|
5
6
|
constructor(body: PredictorSDK.ErrorResponse, rawResponse?: core.RawResponse);
|
|
6
7
|
}
|
|
@@ -2,5 +2,6 @@ import type * as core from "../../core/index.js";
|
|
|
2
2
|
import * as errors from "../../errors/index.js";
|
|
3
3
|
import type * as PredictorSDK from "../index.js";
|
|
4
4
|
export declare class TooManyRequestsError extends errors.PredictorSDKError {
|
|
5
|
+
readonly body: PredictorSDK.ErrorResponse;
|
|
5
6
|
constructor(body: PredictorSDK.ErrorResponse, rawResponse?: core.RawResponse);
|
|
6
7
|
}
|
|
@@ -2,5 +2,6 @@ import type * as core from "../../core/index.js";
|
|
|
2
2
|
import * as errors from "../../errors/index.js";
|
|
3
3
|
import type * as PredictorSDK from "../index.js";
|
|
4
4
|
export declare class UnauthorizedError extends errors.PredictorSDKError {
|
|
5
|
+
readonly body: PredictorSDK.ErrorResponse;
|
|
5
6
|
constructor(body: PredictorSDK.ErrorResponse, rawResponse?: core.RawResponse);
|
|
6
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export * from "./BadGatewayError.js";
|
|
2
2
|
export * from "./BadRequestError.js";
|
|
3
3
|
export * from "./ForbiddenError.js";
|
|
4
|
-
export * from "./
|
|
4
|
+
export * from "./PaymentRequiredError.js";
|
|
5
5
|
export * from "./ServiceUnavailableError.js";
|
|
6
6
|
export * from "./TooManyRequestsError.js";
|
|
7
7
|
export * from "./UnauthorizedError.js";
|
package/dist/api/errors/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export * from "./BadGatewayError.js";
|
|
2
2
|
export * from "./BadRequestError.js";
|
|
3
3
|
export * from "./ForbiddenError.js";
|
|
4
|
-
export * from "./
|
|
4
|
+
export * from "./PaymentRequiredError.js";
|
|
5
5
|
export * from "./ServiceUnavailableError.js";
|
|
6
6
|
export * from "./TooManyRequestsError.js";
|
|
7
7
|
export * from "./UnauthorizedError.js";
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** Recommended client action for this 402. */
|
|
2
|
+
export declare const PaymentRequiredErrorAction: {
|
|
3
|
+
readonly UpgradePlan: "upgrade_plan";
|
|
4
|
+
readonly ResolvePayment: "resolve_payment";
|
|
5
|
+
};
|
|
6
|
+
export type PaymentRequiredErrorAction = (typeof PaymentRequiredErrorAction)[keyof typeof PaymentRequiredErrorAction];
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type * as PredictorSDK from "../index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Error body returned with HTTP 402. The `action` discriminator lets clients route to the correct recovery flow: `upgrade_plan` means the caller is on a lower tier than the endpoint requires, or the Free monthly allowance is exhausted; `resolve_payment` means the caller had a paid subscription that entered a payment-recovery state (past_due/unpaid/paused/incomplete) and the backend has already downgraded them to Free — the fix is in the billing portal, not a new purchase. `required_tier` / `current_tier` are always populated; `included_requests_per_month` and `current_period_requests` are only set when a Free caller hits the monthly allowance.
|
|
4
|
+
*/
|
|
5
|
+
export interface PaymentRequiredErrorBody {
|
|
6
|
+
error: string;
|
|
7
|
+
/** Additional detail about the error. */
|
|
8
|
+
message?: string;
|
|
9
|
+
statusCode: number;
|
|
10
|
+
/** Recommended client action for this 402. */
|
|
11
|
+
action: PredictorSDK.PaymentRequiredErrorAction;
|
|
12
|
+
/** Billing tier that would satisfy the gate (e.g. `starter`, `pro`, `business`, `enterprise`). */
|
|
13
|
+
requiredTier: string;
|
|
14
|
+
/** Billing tier currently associated with the caller. */
|
|
15
|
+
currentTier: string;
|
|
16
|
+
/** Monthly Free-tier allowance. Present only when the 402 is caused by the Free cap. */
|
|
17
|
+
includedRequestsPerMonth?: number;
|
|
18
|
+
/** Requests the Free caller has made in the current calendar month. Present only when the 402 is caused by the Free cap. */
|
|
19
|
+
currentPeriodRequests?: number;
|
|
20
|
+
}
|
|
@@ -3,6 +3,8 @@ export * from "./CryptoPricesResponse.js";
|
|
|
3
3
|
export * from "./ErrorResponse.js";
|
|
4
4
|
export * from "./MarketsListResponse.js";
|
|
5
5
|
export * from "./PaginationBlock.js";
|
|
6
|
+
export * from "./PaymentRequiredErrorAction.js";
|
|
7
|
+
export * from "./PaymentRequiredErrorBody.js";
|
|
6
8
|
export * from "./PlatformMarket.js";
|
|
7
9
|
export * from "./PlatformMarketPlatform.js";
|
|
8
10
|
export * from "./SportsMatchingResponse.js";
|
package/dist/api/types/index.js
CHANGED
|
@@ -3,6 +3,8 @@ export * from "./CryptoPricesResponse.js";
|
|
|
3
3
|
export * from "./ErrorResponse.js";
|
|
4
4
|
export * from "./MarketsListResponse.js";
|
|
5
5
|
export * from "./PaginationBlock.js";
|
|
6
|
+
export * from "./PaymentRequiredErrorAction.js";
|
|
7
|
+
export * from "./PaymentRequiredErrorBody.js";
|
|
6
8
|
export * from "./PlatformMarket.js";
|
|
7
9
|
export * from "./PlatformMarketPlatform.js";
|
|
8
10
|
export * from "./SportsMatchingResponse.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type
|
|
1
|
+
export { type AuthProvider, isAuthProvider } from "./AuthProvider.js";
|
|
2
2
|
export type { AuthRequest } from "./AuthRequest.js";
|
|
3
3
|
export { BasicAuth } from "./BasicAuth.js";
|
|
4
4
|
export { BearerToken } from "./BearerToken.js";
|
package/dist/core/auth/index.js
CHANGED
|
@@ -8,7 +8,13 @@ export declare namespace Fetcher {
|
|
|
8
8
|
method: string;
|
|
9
9
|
contentType?: string;
|
|
10
10
|
headers?: Record<string, unknown>;
|
|
11
|
+
/**
|
|
12
|
+
* @deprecated Prefer `queryString` (produced by `core.url.queryBuilder()`).
|
|
13
|
+
* Retained for backwards compatibility with custom fetchers and callers that
|
|
14
|
+
* still construct request args with a query-parameter object.
|
|
15
|
+
*/
|
|
11
16
|
queryParameters?: Record<string, unknown>;
|
|
17
|
+
queryString?: string;
|
|
12
18
|
body?: unknown;
|
|
13
19
|
timeoutMs?: number;
|
|
14
20
|
maxRetries?: number;
|
|
@@ -62,16 +62,11 @@ const SENSITIVE_QUERY_PARAMS = new Set([
|
|
|
62
62
|
]);
|
|
63
63
|
function redactQueryParameters(queryParameters) {
|
|
64
64
|
if (queryParameters == null) {
|
|
65
|
-
return
|
|
65
|
+
return undefined;
|
|
66
66
|
}
|
|
67
67
|
const redacted = {};
|
|
68
68
|
for (const [key, value] of Object.entries(queryParameters)) {
|
|
69
|
-
|
|
70
|
-
redacted[key] = "[REDACTED]";
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
redacted[key] = value;
|
|
74
|
-
}
|
|
69
|
+
redacted[key] = SENSITIVE_QUERY_PARAMS.has(key.toLowerCase()) ? "[REDACTED]" : value;
|
|
75
70
|
}
|
|
76
71
|
return redacted;
|
|
77
72
|
}
|
|
@@ -168,7 +163,13 @@ async function getHeaders(args) {
|
|
|
168
163
|
return newHeaders;
|
|
169
164
|
}
|
|
170
165
|
export async function fetcherImpl(args) {
|
|
171
|
-
|
|
166
|
+
let url = args.url;
|
|
167
|
+
if (args.queryString != null && args.queryString.length > 0) {
|
|
168
|
+
url = `${url}?${args.queryString}`;
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
url = createRequestUrl(args.url, args.queryParameters);
|
|
172
|
+
}
|
|
172
173
|
const requestBody = await getRequestBody({
|
|
173
174
|
body: args.body,
|
|
174
175
|
type: args.requestType ?? "other",
|
|
@@ -2,6 +2,9 @@ const INITIAL_RETRY_DELAY = 1000; // in milliseconds
|
|
|
2
2
|
const MAX_RETRY_DELAY = 60000; // in milliseconds
|
|
3
3
|
const DEFAULT_MAX_RETRIES = 2;
|
|
4
4
|
const JITTER_FACTOR = 0.2; // 20% random jitter
|
|
5
|
+
function isRetryableStatusCode(statusCode) {
|
|
6
|
+
return [408, 429].includes(statusCode) || statusCode >= 500;
|
|
7
|
+
}
|
|
5
8
|
function addPositiveJitter(delay) {
|
|
6
9
|
const jitterMultiplier = 1 + Math.random() * JITTER_FACTOR;
|
|
7
10
|
return delay * jitterMultiplier;
|
|
@@ -40,7 +43,7 @@ function getRetryDelayFromHeaders(response, retryAttempt) {
|
|
|
40
43
|
export async function requestWithRetries(requestFn, maxRetries = DEFAULT_MAX_RETRIES) {
|
|
41
44
|
let response = await requestFn();
|
|
42
45
|
for (let i = 0; i < maxRetries; ++i) {
|
|
43
|
-
if (
|
|
46
|
+
if (isRetryableStatusCode(response.status)) {
|
|
44
47
|
const delay = getRetryDelayFromHeaders(response, i);
|
|
45
48
|
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
46
49
|
response = await requestFn();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { enum_ } from "./enum.js";
|
|
1
|
+
export { enum_, forwardCompatibleEnum_ } from "./enum.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { enum_ } from "./enum.js";
|
|
1
|
+
export { enum_, forwardCompatibleEnum_ } from "./enum.js";
|
|
@@ -4,6 +4,7 @@ export class JsonError extends Error {
|
|
|
4
4
|
constructor(errors) {
|
|
5
5
|
super(errors.map(stringifyValidationError).join("; "));
|
|
6
6
|
this.errors = errors;
|
|
7
|
-
Object.setPrototypeOf(this,
|
|
7
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
8
|
+
this.name = this.constructor.name;
|
|
8
9
|
}
|
|
9
10
|
}
|
|
@@ -4,6 +4,7 @@ export class ParseError extends Error {
|
|
|
4
4
|
constructor(errors) {
|
|
5
5
|
super(errors.map(stringifyValidationError).join("; "));
|
|
6
6
|
this.errors = errors;
|
|
7
|
-
Object.setPrototypeOf(this,
|
|
7
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
8
|
+
this.name = this.constructor.name;
|
|
8
9
|
}
|
|
9
10
|
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a fluent builder for constructing URL query strings.
|
|
3
|
+
*
|
|
4
|
+
* Each `.add()` call serializes its value immediately (like C#'s builder),
|
|
5
|
+
* so no format tracking is needed — the style is applied at add-time.
|
|
6
|
+
*
|
|
7
|
+
* Usage (generated code):
|
|
8
|
+
*
|
|
9
|
+
* const qs = core.url.queryBuilder()
|
|
10
|
+
* .add("limit", limit)
|
|
11
|
+
* .add("tags", tags, { style: "comma" }) // explode: false
|
|
12
|
+
* .mergeAdditional(requestOptions?.queryParams)
|
|
13
|
+
* .build();
|
|
14
|
+
*/
|
|
15
|
+
export declare function queryBuilder(): QueryStringBuilder;
|
|
16
|
+
declare class QueryStringBuilder {
|
|
17
|
+
private parts;
|
|
18
|
+
/**
|
|
19
|
+
* Adds a query parameter, serializing it immediately.
|
|
20
|
+
*
|
|
21
|
+
* By default arrays use "repeat" format (`key=a&key=b`).
|
|
22
|
+
* Pass `{ style: "comma" }` for OpenAPI `explode: false` parameters
|
|
23
|
+
* to get comma-separated values (`key=a,b,c`).
|
|
24
|
+
*
|
|
25
|
+
* Null / undefined values are silently skipped.
|
|
26
|
+
*/
|
|
27
|
+
add(key: string, value: unknown, options?: {
|
|
28
|
+
style?: "comma";
|
|
29
|
+
}): this;
|
|
30
|
+
/**
|
|
31
|
+
* Adds multiple query parameters at once from a record.
|
|
32
|
+
* All parameters use the default "repeat" array format.
|
|
33
|
+
* Null / undefined values are silently skipped.
|
|
34
|
+
*/
|
|
35
|
+
addMany(params: Record<string, unknown>): this;
|
|
36
|
+
/**
|
|
37
|
+
* Merges additional query parameters supplied at call-time via
|
|
38
|
+
* `requestOptions.queryParams`. Overrides existing keys (last-write-wins).
|
|
39
|
+
*/
|
|
40
|
+
mergeAdditional(additionalParams?: Record<string, unknown>): this;
|
|
41
|
+
/**
|
|
42
|
+
* Returns the assembled query string (without the leading `?`).
|
|
43
|
+
* Returns an empty string when no parameters were added.
|
|
44
|
+
*/
|
|
45
|
+
build(): string;
|
|
46
|
+
}
|
|
47
|
+
export {};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { toQueryString } from "./qs.js";
|
|
2
|
+
/**
|
|
3
|
+
* Creates a fluent builder for constructing URL query strings.
|
|
4
|
+
*
|
|
5
|
+
* Each `.add()` call serializes its value immediately (like C#'s builder),
|
|
6
|
+
* so no format tracking is needed — the style is applied at add-time.
|
|
7
|
+
*
|
|
8
|
+
* Usage (generated code):
|
|
9
|
+
*
|
|
10
|
+
* const qs = core.url.queryBuilder()
|
|
11
|
+
* .add("limit", limit)
|
|
12
|
+
* .add("tags", tags, { style: "comma" }) // explode: false
|
|
13
|
+
* .mergeAdditional(requestOptions?.queryParams)
|
|
14
|
+
* .build();
|
|
15
|
+
*/
|
|
16
|
+
export function queryBuilder() {
|
|
17
|
+
return new QueryStringBuilder();
|
|
18
|
+
}
|
|
19
|
+
class QueryStringBuilder {
|
|
20
|
+
parts = new Map();
|
|
21
|
+
/**
|
|
22
|
+
* Adds a query parameter, serializing it immediately.
|
|
23
|
+
*
|
|
24
|
+
* By default arrays use "repeat" format (`key=a&key=b`).
|
|
25
|
+
* Pass `{ style: "comma" }` for OpenAPI `explode: false` parameters
|
|
26
|
+
* to get comma-separated values (`key=a,b,c`).
|
|
27
|
+
*
|
|
28
|
+
* Null / undefined values are silently skipped.
|
|
29
|
+
*/
|
|
30
|
+
add(key, value, options) {
|
|
31
|
+
if (value === undefined || value === null) {
|
|
32
|
+
return this;
|
|
33
|
+
}
|
|
34
|
+
const serialized = toQueryString({ [key]: value }, { arrayFormat: options?.style === "comma" ? "comma" : "repeat" });
|
|
35
|
+
if (serialized.length > 0) {
|
|
36
|
+
this.parts.set(key, serialized);
|
|
37
|
+
}
|
|
38
|
+
return this;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Adds multiple query parameters at once from a record.
|
|
42
|
+
* All parameters use the default "repeat" array format.
|
|
43
|
+
* Null / undefined values are silently skipped.
|
|
44
|
+
*/
|
|
45
|
+
addMany(params) {
|
|
46
|
+
if (params != null) {
|
|
47
|
+
for (const [key, value] of Object.entries(params)) {
|
|
48
|
+
this.add(key, value);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return this;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Merges additional query parameters supplied at call-time via
|
|
55
|
+
* `requestOptions.queryParams`. Overrides existing keys (last-write-wins).
|
|
56
|
+
*/
|
|
57
|
+
mergeAdditional(additionalParams) {
|
|
58
|
+
if (additionalParams != null) {
|
|
59
|
+
for (const [key, value] of Object.entries(additionalParams)) {
|
|
60
|
+
if (value === undefined || value === null) {
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
const serialized = toQueryString({ [key]: value }, { arrayFormat: "repeat" });
|
|
64
|
+
if (serialized.length > 0) {
|
|
65
|
+
this.parts.set(key, serialized);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return this;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Returns the assembled query string (without the leading `?`).
|
|
73
|
+
* Returns an empty string when no parameters were added.
|
|
74
|
+
*/
|
|
75
|
+
build() {
|
|
76
|
+
return [...this.parts.values()].join("&");
|
|
77
|
+
}
|
|
78
|
+
}
|
package/dist/core/url/index.d.ts
CHANGED
package/dist/core/url/index.js
CHANGED
package/dist/core/url/qs.d.ts
CHANGED
package/dist/core/url/qs.js
CHANGED
|
@@ -23,19 +23,31 @@ function stringifyObject(obj, prefix = "", options) {
|
|
|
23
23
|
if (value.length === 0) {
|
|
24
24
|
continue;
|
|
25
25
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
const effectiveFormat = options.arrayFormat;
|
|
27
|
+
if (effectiveFormat === "comma") {
|
|
28
|
+
const encodedKey = options.encode ? encodeURIComponent(fullKey) : fullKey;
|
|
29
|
+
const encodedValues = value
|
|
30
|
+
.filter((item) => item !== undefined && item !== null)
|
|
31
|
+
.map((item) => encodeValue(item, options.encode));
|
|
32
|
+
if (encodedValues.length > 0) {
|
|
33
|
+
parts.push(`${encodedKey}=${encodedValues.join(",")}`);
|
|
30
34
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
for (let i = 0; i < value.length; i++) {
|
|
38
|
+
const item = value[i];
|
|
39
|
+
if (item === undefined) {
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
if (typeof item === "object" && !Array.isArray(item) && item !== null) {
|
|
43
|
+
const arrayKey = effectiveFormat === "indices" ? `${fullKey}[${i}]` : fullKey;
|
|
44
|
+
parts.push(...stringifyObject(item, arrayKey, options));
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
const arrayKey = effectiveFormat === "indices" ? `${fullKey}[${i}]` : fullKey;
|
|
48
|
+
const encodedKey = options.encode ? encodeURIComponent(arrayKey) : arrayKey;
|
|
49
|
+
parts.push(`${encodedKey}=${encodeValue(item, options.encode)}`);
|
|
50
|
+
}
|
|
39
51
|
}
|
|
40
52
|
}
|
|
41
53
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type * as PredictorSDK from "../../api/index.js";
|
|
2
|
+
import * as core from "../../core/index.js";
|
|
3
|
+
import type * as serializers from "../index.js";
|
|
4
|
+
export declare const PaymentRequiredErrorAction: core.serialization.Schema<serializers.PaymentRequiredErrorAction.Raw, PredictorSDK.PaymentRequiredErrorAction>;
|
|
5
|
+
export declare namespace PaymentRequiredErrorAction {
|
|
6
|
+
type Raw = "upgrade_plan" | "resolve_payment";
|
|
7
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type * as PredictorSDK from "../../api/index.js";
|
|
2
|
+
import * as core from "../../core/index.js";
|
|
3
|
+
import type * as serializers from "../index.js";
|
|
4
|
+
import { PaymentRequiredErrorAction } from "./PaymentRequiredErrorAction.js";
|
|
5
|
+
export declare const PaymentRequiredErrorBody: core.serialization.ObjectSchema<serializers.PaymentRequiredErrorBody.Raw, PredictorSDK.PaymentRequiredErrorBody>;
|
|
6
|
+
export declare namespace PaymentRequiredErrorBody {
|
|
7
|
+
interface Raw {
|
|
8
|
+
error: string;
|
|
9
|
+
message?: string | null;
|
|
10
|
+
status_code: number;
|
|
11
|
+
action: PaymentRequiredErrorAction.Raw;
|
|
12
|
+
required_tier: string;
|
|
13
|
+
current_tier: string;
|
|
14
|
+
included_requests_per_month?: number | null;
|
|
15
|
+
current_period_requests?: number | null;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// This file was auto-generated by Fern from our API Definition.
|
|
2
|
+
import * as core from "../../core/index.js";
|
|
3
|
+
import { PaymentRequiredErrorAction } from "./PaymentRequiredErrorAction.js";
|
|
4
|
+
export const PaymentRequiredErrorBody = core.serialization.object({
|
|
5
|
+
error: core.serialization.string(),
|
|
6
|
+
message: core.serialization.string().optional(),
|
|
7
|
+
statusCode: core.serialization.property("status_code", core.serialization.number()),
|
|
8
|
+
action: PaymentRequiredErrorAction,
|
|
9
|
+
requiredTier: core.serialization.property("required_tier", core.serialization.string()),
|
|
10
|
+
currentTier: core.serialization.property("current_tier", core.serialization.string()),
|
|
11
|
+
includedRequestsPerMonth: core.serialization.property("included_requests_per_month", core.serialization.number().optional()),
|
|
12
|
+
currentPeriodRequests: core.serialization.property("current_period_requests", core.serialization.number().optional()),
|
|
13
|
+
});
|
|
@@ -3,6 +3,8 @@ export * from "./CryptoPricesResponse.js";
|
|
|
3
3
|
export * from "./ErrorResponse.js";
|
|
4
4
|
export * from "./MarketsListResponse.js";
|
|
5
5
|
export * from "./PaginationBlock.js";
|
|
6
|
+
export * from "./PaymentRequiredErrorAction.js";
|
|
7
|
+
export * from "./PaymentRequiredErrorBody.js";
|
|
6
8
|
export * from "./PlatformMarket.js";
|
|
7
9
|
export * from "./PlatformMarketPlatform.js";
|
|
8
10
|
export * from "./SportsMatchingResponse.js";
|
|
@@ -3,6 +3,8 @@ export * from "./CryptoPricesResponse.js";
|
|
|
3
3
|
export * from "./ErrorResponse.js";
|
|
4
4
|
export * from "./MarketsListResponse.js";
|
|
5
5
|
export * from "./PaginationBlock.js";
|
|
6
|
+
export * from "./PaymentRequiredErrorAction.js";
|
|
7
|
+
export * from "./PaymentRequiredErrorBody.js";
|
|
6
8
|
export * from "./PlatformMarket.js";
|
|
7
9
|
export * from "./PlatformMarketPlatform.js";
|
|
8
10
|
export * from "./SportsMatchingResponse.js";
|
package/package.json
CHANGED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type * as core from "../../core/index.js";
|
|
2
|
-
import * as errors from "../../errors/index.js";
|
|
3
|
-
import type * as PredictorSDK from "../index.js";
|
|
4
|
-
export declare class InternalServerError extends errors.PredictorSDKError {
|
|
5
|
-
constructor(body: PredictorSDK.ErrorResponse, rawResponse?: core.RawResponse);
|
|
6
|
-
}
|