@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.
Files changed (47) hide show
  1. package/dist/BaseClient.d.ts +3 -0
  2. package/dist/BaseClient.js +15 -0
  3. package/dist/Client.d.ts +3 -1
  4. package/dist/Client.js +40 -10
  5. package/dist/api/errors/BadGatewayError.d.ts +1 -0
  6. package/dist/api/errors/BadRequestError.d.ts +1 -0
  7. package/dist/api/errors/ForbiddenError.d.ts +1 -0
  8. package/dist/api/errors/PaymentRequiredError.d.ts +7 -0
  9. package/dist/api/errors/{InternalServerError.js → PaymentRequiredError.js} +3 -3
  10. package/dist/api/errors/ServiceUnavailableError.d.ts +1 -0
  11. package/dist/api/errors/TooManyRequestsError.d.ts +1 -0
  12. package/dist/api/errors/UnauthorizedError.d.ts +1 -0
  13. package/dist/api/errors/index.d.ts +1 -1
  14. package/dist/api/errors/index.js +1 -1
  15. package/dist/api/types/PaymentRequiredErrorAction.d.ts +6 -0
  16. package/dist/api/types/PaymentRequiredErrorAction.js +6 -0
  17. package/dist/api/types/PaymentRequiredErrorBody.d.ts +20 -0
  18. package/dist/api/types/PaymentRequiredErrorBody.js +2 -0
  19. package/dist/api/types/index.d.ts +2 -0
  20. package/dist/api/types/index.js +2 -0
  21. package/dist/core/auth/AuthProvider.d.ts +1 -0
  22. package/dist/core/auth/AuthProvider.js +6 -1
  23. package/dist/core/auth/index.d.ts +1 -1
  24. package/dist/core/auth/index.js +1 -0
  25. package/dist/core/fetcher/Fetcher.d.ts +6 -0
  26. package/dist/core/fetcher/Fetcher.js +9 -8
  27. package/dist/core/fetcher/requestWithRetries.js +4 -1
  28. package/dist/core/schemas/builders/enum/enum.d.ts +1 -0
  29. package/dist/core/schemas/builders/enum/enum.js +6 -0
  30. package/dist/core/schemas/builders/enum/index.d.ts +1 -1
  31. package/dist/core/schemas/builders/enum/index.js +1 -1
  32. package/dist/core/schemas/builders/schema-utils/JsonError.js +2 -1
  33. package/dist/core/schemas/builders/schema-utils/ParseError.js +2 -1
  34. package/dist/core/url/QueryStringBuilder.d.ts +47 -0
  35. package/dist/core/url/QueryStringBuilder.js +78 -0
  36. package/dist/core/url/index.d.ts +1 -0
  37. package/dist/core/url/index.js +1 -0
  38. package/dist/core/url/qs.d.ts +2 -1
  39. package/dist/core/url/qs.js +24 -12
  40. package/dist/serialization/types/PaymentRequiredErrorAction.d.ts +7 -0
  41. package/dist/serialization/types/PaymentRequiredErrorAction.js +3 -0
  42. package/dist/serialization/types/PaymentRequiredErrorBody.d.ts +17 -0
  43. package/dist/serialization/types/PaymentRequiredErrorBody.js +13 -0
  44. package/dist/serialization/types/index.d.ts +2 -0
  45. package/dist/serialization/types/index.js +2 -0
  46. package/package.json +1 -1
  47. package/dist/api/errors/InternalServerError.d.ts +0 -6
@@ -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. */
@@ -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
- queryParameters: { ..._queryParams, ...requestOptions?.queryParams },
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
- queryParameters: { ..._queryParams, ...requestOptions?.queryParams },
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 403:
194
- throw new PredictorSDK.ForbiddenError(serializers.ErrorResponse.parseOrThrow(_response.error.body, {
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 429:
202
- throw new PredictorSDK.TooManyRequestsError(serializers.ErrorResponse.parseOrThrow(_response.error.body, {
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 500:
210
- throw new PredictorSDK.InternalServerError(serializers.ErrorResponse.parseOrThrow(_response.error.body, {
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
- queryParameters: { ..._queryParams, ...requestOptions?.queryParams },
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 InternalServerError extends errors.PredictorSDKError {
3
+ export class PaymentRequiredError extends errors.PredictorSDKError {
4
4
  constructor(body, rawResponse) {
5
5
  super({
6
- message: "InternalServerError",
7
- statusCode: 500,
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 "./InternalServerError.js";
4
+ export * from "./PaymentRequiredError.js";
5
5
  export * from "./ServiceUnavailableError.js";
6
6
  export * from "./TooManyRequestsError.js";
7
7
  export * from "./UnauthorizedError.js";
@@ -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 "./InternalServerError.js";
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,6 @@
1
+ // This file was auto-generated by Fern from our API Definition.
2
+ /** Recommended client action for this 402. */
3
+ export const PaymentRequiredErrorAction = {
4
+ UpgradePlan: "upgrade_plan",
5
+ ResolvePayment: "resolve_payment",
6
+ };
@@ -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
+ }
@@ -0,0 +1,2 @@
1
+ // This file was auto-generated by Fern from our API Definition.
2
+ export {};
@@ -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";
@@ -5,3 +5,4 @@ export interface AuthProvider {
5
5
  endpointMetadata?: EndpointMetadata;
6
6
  }): Promise<AuthRequest>;
7
7
  }
8
+ export declare function isAuthProvider(value: unknown): value is AuthProvider;
@@ -1 +1,6 @@
1
- export {};
1
+ export function isAuthProvider(value) {
2
+ return (typeof value === "object" &&
3
+ value !== null &&
4
+ "getAuthRequest" in value &&
5
+ typeof value.getAuthRequest === "function");
6
+ }
@@ -1,4 +1,4 @@
1
- export type { AuthProvider } from "./AuthProvider.js";
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";
@@ -1,3 +1,4 @@
1
+ export { isAuthProvider } from "./AuthProvider.js";
1
2
  export { BasicAuth } from "./BasicAuth.js";
2
3
  export { BearerToken } from "./BearerToken.js";
3
4
  export { NoOpAuthProvider } from "./NoOpAuthProvider.js";
@@ -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 queryParameters;
65
+ return undefined;
66
66
  }
67
67
  const redacted = {};
68
68
  for (const [key, value] of Object.entries(queryParameters)) {
69
- if (SENSITIVE_QUERY_PARAMS.has(key.toLowerCase())) {
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
- const url = createRequestUrl(args.url, args.queryParameters);
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 ([408, 429].includes(response.status) || response.status >= 500) {
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,2 +1,3 @@
1
1
  import { type Schema } from "../../Schema.js";
2
2
  export declare function enum_<U extends string, E extends U[]>(values: E): Schema<E[number], E[number]>;
3
+ export declare function forwardCompatibleEnum_<U extends string, E extends U[]>(values: E): Schema<E[number], string>;
@@ -33,3 +33,9 @@ export function enum_(values) {
33
33
  });
34
34
  return schemaCreator();
35
35
  }
36
+ export function forwardCompatibleEnum_(values) {
37
+ return enum_(values).transform({
38
+ transform: (val) => val,
39
+ untransform: (val) => val,
40
+ });
41
+ }
@@ -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, JsonError.prototype);
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, ParseError.prototype);
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
+ }
@@ -1,3 +1,4 @@
1
1
  export { encodePathParam } from "./encodePathParam.js";
2
2
  export { join } from "./join.js";
3
+ export { queryBuilder } from "./QueryStringBuilder.js";
3
4
  export { toQueryString } from "./qs.js";
@@ -1,3 +1,4 @@
1
1
  export { encodePathParam } from "./encodePathParam.js";
2
2
  export { join } from "./join.js";
3
+ export { queryBuilder } from "./QueryStringBuilder.js";
3
4
  export { toQueryString } from "./qs.js";
@@ -1,5 +1,6 @@
1
+ type ArrayFormat = "indices" | "repeat" | "comma";
1
2
  interface QueryStringOptions {
2
- arrayFormat?: "indices" | "repeat";
3
+ arrayFormat?: ArrayFormat;
3
4
  encode?: boolean;
4
5
  }
5
6
  export declare function toQueryString(obj: unknown, options?: QueryStringOptions): string;
@@ -23,19 +23,31 @@ function stringifyObject(obj, prefix = "", options) {
23
23
  if (value.length === 0) {
24
24
  continue;
25
25
  }
26
- for (let i = 0; i < value.length; i++) {
27
- const item = value[i];
28
- if (item === undefined) {
29
- continue;
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
- if (typeof item === "object" && !Array.isArray(item) && item !== null) {
32
- const arrayKey = options.arrayFormat === "indices" ? `${fullKey}[${i}]` : fullKey;
33
- parts.push(...stringifyObject(item, arrayKey, options));
34
- }
35
- else {
36
- const arrayKey = options.arrayFormat === "indices" ? `${fullKey}[${i}]` : fullKey;
37
- const encodedKey = options.encode ? encodeURIComponent(arrayKey) : arrayKey;
38
- parts.push(`${encodedKey}=${encodeValue(item, options.encode)}`);
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,3 @@
1
+ // This file was auto-generated by Fern from our API Definition.
2
+ import * as core from "../../core/index.js";
3
+ export const PaymentRequiredErrorAction = core.serialization.enum_(["upgrade_plan", "resolve_payment"]);
@@ -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 +1,6 @@
1
1
  {
2
2
  "name": "@predictorsdk/client",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
4
4
  "description": "The official TypeScript/JavaScript client for the PredictorSDK matching markets API",
5
5
  "license": "MIT",
6
6
  "keywords": [
@@ -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
- }