@predictorsdk/client 0.1.0
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/LICENSE +21 -0
- package/README.md +30 -0
- package/dist/BaseClient.d.ts +39 -0
- package/dist/BaseClient.js +28 -0
- package/dist/Client.d.ts +41 -0
- package/dist/Client.js +101 -0
- package/dist/api/client/index.d.ts +1 -0
- package/dist/api/client/index.js +1 -0
- package/dist/api/client/requests/GetSportsMatchingMarketsRequest.d.ts +14 -0
- package/dist/api/client/requests/GetSportsMatchingMarketsRequest.js +2 -0
- package/dist/api/client/requests/index.d.ts +1 -0
- package/dist/api/client/requests/index.js +1 -0
- package/dist/api/errors/BadRequestError.d.ts +6 -0
- package/dist/api/errors/BadRequestError.js +17 -0
- package/dist/api/errors/ForbiddenError.d.ts +6 -0
- package/dist/api/errors/ForbiddenError.js +17 -0
- package/dist/api/errors/ServiceUnavailableError.d.ts +6 -0
- package/dist/api/errors/ServiceUnavailableError.js +17 -0
- package/dist/api/errors/TooManyRequestsError.d.ts +6 -0
- package/dist/api/errors/TooManyRequestsError.js +17 -0
- package/dist/api/errors/UnauthorizedError.d.ts +6 -0
- package/dist/api/errors/UnauthorizedError.js +17 -0
- package/dist/api/errors/index.d.ts +5 -0
- package/dist/api/errors/index.js +5 -0
- package/dist/api/index.d.ts +3 -0
- package/dist/api/index.js +3 -0
- package/dist/api/types/ErrorResponse.d.ts +4 -0
- package/dist/api/types/ErrorResponse.js +2 -0
- package/dist/api/types/PlatformMarket.d.ts +24 -0
- package/dist/api/types/PlatformMarket.js +10 -0
- package/dist/api/types/SportsMatchingResponse.d.ts +5 -0
- package/dist/api/types/SportsMatchingResponse.js +2 -0
- package/dist/api/types/index.d.ts +3 -0
- package/dist/api/types/index.js +3 -0
- package/dist/auth/BearerAuthProvider.d.ts +20 -0
- package/dist/auth/BearerAuthProvider.js +32 -0
- package/dist/auth/index.d.ts +1 -0
- package/dist/auth/index.js +1 -0
- package/dist/core/auth/AuthProvider.d.ts +7 -0
- package/dist/core/auth/AuthProvider.js +1 -0
- package/dist/core/auth/AuthRequest.d.ts +9 -0
- package/dist/core/auth/AuthRequest.js +1 -0
- package/dist/core/auth/BasicAuth.d.ts +8 -0
- package/dist/core/auth/BasicAuth.js +24 -0
- package/dist/core/auth/BearerToken.d.ts +7 -0
- package/dist/core/auth/BearerToken.js +13 -0
- package/dist/core/auth/NoOpAuthProvider.d.ts +5 -0
- package/dist/core/auth/NoOpAuthProvider.js +5 -0
- package/dist/core/auth/index.d.ts +5 -0
- package/dist/core/auth/index.js +3 -0
- package/dist/core/base64.d.ts +2 -0
- package/dist/core/base64.js +22 -0
- package/dist/core/exports.d.ts +1 -0
- package/dist/core/exports.js +1 -0
- package/dist/core/fetcher/APIResponse.d.ts +20 -0
- package/dist/core/fetcher/APIResponse.js +1 -0
- package/dist/core/fetcher/BinaryResponse.d.ts +19 -0
- package/dist/core/fetcher/BinaryResponse.js +14 -0
- package/dist/core/fetcher/EndpointMetadata.d.ts +13 -0
- package/dist/core/fetcher/EndpointMetadata.js +1 -0
- package/dist/core/fetcher/EndpointSupplier.d.ts +12 -0
- package/dist/core/fetcher/EndpointSupplier.js +10 -0
- package/dist/core/fetcher/Fetcher.d.ts +50 -0
- package/dist/core/fetcher/Fetcher.js +305 -0
- package/dist/core/fetcher/Headers.d.ts +2 -0
- package/dist/core/fetcher/Headers.js +83 -0
- package/dist/core/fetcher/HttpResponsePromise.d.ts +58 -0
- package/dist/core/fetcher/HttpResponsePromise.js +90 -0
- package/dist/core/fetcher/RawResponse.d.ts +29 -0
- package/dist/core/fetcher/RawResponse.js +40 -0
- package/dist/core/fetcher/Supplier.d.ts +4 -0
- package/dist/core/fetcher/Supplier.js +10 -0
- package/dist/core/fetcher/createRequestUrl.d.ts +1 -0
- package/dist/core/fetcher/createRequestUrl.js +5 -0
- package/dist/core/fetcher/getErrorResponseBody.d.ts +1 -0
- package/dist/core/fetcher/getErrorResponseBody.js +30 -0
- package/dist/core/fetcher/getFetchFn.d.ts +1 -0
- package/dist/core/fetcher/getFetchFn.js +3 -0
- package/dist/core/fetcher/getHeader.d.ts +1 -0
- package/dist/core/fetcher/getHeader.js +8 -0
- package/dist/core/fetcher/getRequestBody.d.ts +7 -0
- package/dist/core/fetcher/getRequestBody.js +13 -0
- package/dist/core/fetcher/getResponseBody.d.ts +1 -0
- package/dist/core/fetcher/getResponseBody.js +55 -0
- package/dist/core/fetcher/index.d.ts +13 -0
- package/dist/core/fetcher/index.js +7 -0
- package/dist/core/fetcher/makePassthroughRequest.d.ts +49 -0
- package/dist/core/fetcher/makePassthroughRequest.js +119 -0
- package/dist/core/fetcher/makeRequest.d.ts +6 -0
- package/dist/core/fetcher/makeRequest.js +53 -0
- package/dist/core/fetcher/requestWithRetries.d.ts +1 -0
- package/dist/core/fetcher/requestWithRetries.js +53 -0
- package/dist/core/fetcher/signals.d.ts +5 -0
- package/dist/core/fetcher/signals.js +20 -0
- package/dist/core/headers.d.ts +2 -0
- package/dist/core/headers.js +27 -0
- package/dist/core/index.d.ts +6 -0
- package/dist/core/index.js +6 -0
- package/dist/core/json.d.ts +15 -0
- package/dist/core/json.js +19 -0
- package/dist/core/logging/exports.d.ts +18 -0
- package/dist/core/logging/exports.js +9 -0
- package/dist/core/logging/index.d.ts +1 -0
- package/dist/core/logging/index.js +1 -0
- package/dist/core/logging/logger.d.ts +126 -0
- package/dist/core/logging/logger.js +140 -0
- package/dist/core/runtime/index.d.ts +1 -0
- package/dist/core/runtime/index.js +1 -0
- package/dist/core/runtime/runtime.d.ts +9 -0
- package/dist/core/runtime/runtime.js +100 -0
- package/dist/core/url/encodePathParam.d.ts +1 -0
- package/dist/core/url/encodePathParam.js +18 -0
- package/dist/core/url/index.d.ts +3 -0
- package/dist/core/url/index.js +3 -0
- package/dist/core/url/join.d.ts +1 -0
- package/dist/core/url/join.js +65 -0
- package/dist/core/url/qs.d.ts +6 -0
- package/dist/core/url/qs.js +64 -0
- package/dist/environments.d.ts +4 -0
- package/dist/environments.js +4 -0
- package/dist/errors/PredictorSDKError.d.ts +14 -0
- package/dist/errors/PredictorSDKError.js +35 -0
- package/dist/errors/PredictorSDKTimeoutError.d.ts +6 -0
- package/dist/errors/PredictorSDKTimeoutError.js +15 -0
- package/dist/errors/handleNonStatusCodeError.d.ts +2 -0
- package/dist/errors/handleNonStatusCodeError.js +32 -0
- package/dist/errors/index.d.ts +2 -0
- package/dist/errors/index.js +2 -0
- package/dist/exports.d.ts +1 -0
- package/dist/exports.js +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +5 -0
- package/package.json +42 -0
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
export function join(base, ...segments) {
|
|
2
|
+
if (!base) {
|
|
3
|
+
return "";
|
|
4
|
+
}
|
|
5
|
+
if (segments.length === 0) {
|
|
6
|
+
return base;
|
|
7
|
+
}
|
|
8
|
+
if (base.includes("://")) {
|
|
9
|
+
let url;
|
|
10
|
+
try {
|
|
11
|
+
url = new URL(base);
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
return joinPath(base, ...segments);
|
|
15
|
+
}
|
|
16
|
+
const lastSegment = segments[segments.length - 1];
|
|
17
|
+
const shouldPreserveTrailingSlash = lastSegment?.endsWith("/");
|
|
18
|
+
for (const segment of segments) {
|
|
19
|
+
const cleanSegment = trimSlashes(segment);
|
|
20
|
+
if (cleanSegment) {
|
|
21
|
+
url.pathname = joinPathSegments(url.pathname, cleanSegment);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
if (shouldPreserveTrailingSlash && !url.pathname.endsWith("/")) {
|
|
25
|
+
url.pathname += "/";
|
|
26
|
+
}
|
|
27
|
+
return url.toString();
|
|
28
|
+
}
|
|
29
|
+
return joinPath(base, ...segments);
|
|
30
|
+
}
|
|
31
|
+
function joinPath(base, ...segments) {
|
|
32
|
+
if (segments.length === 0) {
|
|
33
|
+
return base;
|
|
34
|
+
}
|
|
35
|
+
let result = base;
|
|
36
|
+
const lastSegment = segments[segments.length - 1];
|
|
37
|
+
const shouldPreserveTrailingSlash = lastSegment?.endsWith("/");
|
|
38
|
+
for (const segment of segments) {
|
|
39
|
+
const cleanSegment = trimSlashes(segment);
|
|
40
|
+
if (cleanSegment) {
|
|
41
|
+
result = joinPathSegments(result, cleanSegment);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (shouldPreserveTrailingSlash && !result.endsWith("/")) {
|
|
45
|
+
result += "/";
|
|
46
|
+
}
|
|
47
|
+
return result;
|
|
48
|
+
}
|
|
49
|
+
function joinPathSegments(left, right) {
|
|
50
|
+
if (left.endsWith("/")) {
|
|
51
|
+
return left + right;
|
|
52
|
+
}
|
|
53
|
+
return `${left}/${right}`;
|
|
54
|
+
}
|
|
55
|
+
function trimSlashes(str) {
|
|
56
|
+
if (!str)
|
|
57
|
+
return str;
|
|
58
|
+
let start = 0;
|
|
59
|
+
let end = str.length;
|
|
60
|
+
if (str.startsWith("/"))
|
|
61
|
+
start = 1;
|
|
62
|
+
if (str.endsWith("/"))
|
|
63
|
+
end = str.length - 1;
|
|
64
|
+
return start === 0 && end === str.length ? str : str.slice(start, end);
|
|
65
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
const defaultQsOptions = {
|
|
2
|
+
arrayFormat: "indices",
|
|
3
|
+
encode: true,
|
|
4
|
+
};
|
|
5
|
+
function encodeValue(value, shouldEncode) {
|
|
6
|
+
if (value === undefined) {
|
|
7
|
+
return "";
|
|
8
|
+
}
|
|
9
|
+
if (value === null) {
|
|
10
|
+
return "";
|
|
11
|
+
}
|
|
12
|
+
const stringValue = String(value);
|
|
13
|
+
return shouldEncode ? encodeURIComponent(stringValue) : stringValue;
|
|
14
|
+
}
|
|
15
|
+
function stringifyObject(obj, prefix = "", options) {
|
|
16
|
+
const parts = [];
|
|
17
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
18
|
+
const fullKey = prefix ? `${prefix}[${key}]` : key;
|
|
19
|
+
if (value === undefined) {
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
if (Array.isArray(value)) {
|
|
23
|
+
if (value.length === 0) {
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
for (let i = 0; i < value.length; i++) {
|
|
27
|
+
const item = value[i];
|
|
28
|
+
if (item === undefined) {
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
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)}`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
else if (typeof value === "object" && value !== null) {
|
|
43
|
+
if (Object.keys(value).length === 0) {
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
parts.push(...stringifyObject(value, fullKey, options));
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
const encodedKey = options.encode ? encodeURIComponent(fullKey) : fullKey;
|
|
50
|
+
parts.push(`${encodedKey}=${encodeValue(value, options.encode)}`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return parts;
|
|
54
|
+
}
|
|
55
|
+
export function toQueryString(obj, options) {
|
|
56
|
+
if (obj == null || typeof obj !== "object") {
|
|
57
|
+
return "";
|
|
58
|
+
}
|
|
59
|
+
const parts = stringifyObject(obj, "", {
|
|
60
|
+
...defaultQsOptions,
|
|
61
|
+
...options,
|
|
62
|
+
});
|
|
63
|
+
return parts.join("&");
|
|
64
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type * as core from "../core/index.js";
|
|
2
|
+
export declare class PredictorSDKError extends Error {
|
|
3
|
+
readonly statusCode?: number;
|
|
4
|
+
readonly body?: unknown;
|
|
5
|
+
readonly rawResponse?: core.RawResponse;
|
|
6
|
+
readonly cause?: unknown;
|
|
7
|
+
constructor({ message, statusCode, body, rawResponse, cause, }: {
|
|
8
|
+
message?: string;
|
|
9
|
+
statusCode?: number;
|
|
10
|
+
body?: unknown;
|
|
11
|
+
rawResponse?: core.RawResponse;
|
|
12
|
+
cause?: unknown;
|
|
13
|
+
});
|
|
14
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// This file was auto-generated by Fern from our API Definition.
|
|
2
|
+
import { toJson } from "../core/json.js";
|
|
3
|
+
export class PredictorSDKError extends Error {
|
|
4
|
+
statusCode;
|
|
5
|
+
body;
|
|
6
|
+
rawResponse;
|
|
7
|
+
cause;
|
|
8
|
+
constructor({ message, statusCode, body, rawResponse, cause, }) {
|
|
9
|
+
super(buildMessage({ message, statusCode, body }));
|
|
10
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
11
|
+
if (Error.captureStackTrace) {
|
|
12
|
+
Error.captureStackTrace(this, this.constructor);
|
|
13
|
+
}
|
|
14
|
+
this.name = this.constructor.name;
|
|
15
|
+
this.statusCode = statusCode;
|
|
16
|
+
this.body = body;
|
|
17
|
+
this.rawResponse = rawResponse;
|
|
18
|
+
if (cause != null) {
|
|
19
|
+
this.cause = cause;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function buildMessage({ message, statusCode, body, }) {
|
|
24
|
+
const lines = [];
|
|
25
|
+
if (message != null) {
|
|
26
|
+
lines.push(message);
|
|
27
|
+
}
|
|
28
|
+
if (statusCode != null) {
|
|
29
|
+
lines.push(`Status code: ${statusCode.toString()}`);
|
|
30
|
+
}
|
|
31
|
+
if (body != null) {
|
|
32
|
+
lines.push(`Body: ${toJson(body, undefined, 2)}`);
|
|
33
|
+
}
|
|
34
|
+
return lines.join("\n");
|
|
35
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// This file was auto-generated by Fern from our API Definition.
|
|
2
|
+
export class PredictorSDKTimeoutError extends Error {
|
|
3
|
+
cause;
|
|
4
|
+
constructor(message, opts) {
|
|
5
|
+
super(message);
|
|
6
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
7
|
+
if (Error.captureStackTrace) {
|
|
8
|
+
Error.captureStackTrace(this, this.constructor);
|
|
9
|
+
}
|
|
10
|
+
this.name = this.constructor.name;
|
|
11
|
+
if (opts?.cause != null) {
|
|
12
|
+
this.cause = opts.cause;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// This file was auto-generated by Fern from our API Definition.
|
|
2
|
+
import * as errors from "./index.js";
|
|
3
|
+
export function handleNonStatusCodeError(error, rawResponse, method, path) {
|
|
4
|
+
switch (error.reason) {
|
|
5
|
+
case "non-json":
|
|
6
|
+
throw new errors.PredictorSDKError({
|
|
7
|
+
statusCode: error.statusCode,
|
|
8
|
+
body: error.rawBody,
|
|
9
|
+
rawResponse: rawResponse,
|
|
10
|
+
});
|
|
11
|
+
case "body-is-null":
|
|
12
|
+
throw new errors.PredictorSDKError({
|
|
13
|
+
statusCode: error.statusCode,
|
|
14
|
+
rawResponse: rawResponse,
|
|
15
|
+
});
|
|
16
|
+
case "timeout":
|
|
17
|
+
throw new errors.PredictorSDKTimeoutError(`Timeout exceeded when calling ${method} ${path}.`, {
|
|
18
|
+
cause: error.cause,
|
|
19
|
+
});
|
|
20
|
+
case "unknown":
|
|
21
|
+
throw new errors.PredictorSDKError({
|
|
22
|
+
message: error.errorMessage,
|
|
23
|
+
rawResponse: rawResponse,
|
|
24
|
+
cause: error.cause,
|
|
25
|
+
});
|
|
26
|
+
default:
|
|
27
|
+
throw new errors.PredictorSDKError({
|
|
28
|
+
message: "Unknown error",
|
|
29
|
+
rawResponse: rawResponse,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./core/exports.js";
|
package/dist/exports.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./core/exports.js";
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export * as PredictorSDK from "./api/index.js";
|
|
2
|
+
export type { BaseClientOptions, BaseRequestOptions } from "./BaseClient.js";
|
|
3
|
+
export { PredictorSDKClient } from "./Client.js";
|
|
4
|
+
export { PredictorSDKEnvironment } from "./environments.js";
|
|
5
|
+
export { PredictorSDKError, PredictorSDKTimeoutError } from "./errors/index.js";
|
|
6
|
+
export * from "./exports.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export * as PredictorSDK from "./api/index.js";
|
|
2
|
+
export { PredictorSDKClient } from "./Client.js";
|
|
3
|
+
export { PredictorSDKEnvironment } from "./environments.js";
|
|
4
|
+
export { PredictorSDKError, PredictorSDKTimeoutError } from "./errors/index.js";
|
|
5
|
+
export * from "./exports.js";
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@predictorsdk/client",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "The official TypeScript/JavaScript client for the PredictorSDK matching markets API",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"scripts": {
|
|
10
|
+
"build": "tsc",
|
|
11
|
+
"prepack": "npm run build",
|
|
12
|
+
"typecheck": "tsc --noEmit"
|
|
13
|
+
},
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"import": "./dist/index.js",
|
|
18
|
+
"default": "./dist/index.js"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist"
|
|
23
|
+
],
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "https://github.com/PredictorSDK/sdk-typescript.git"
|
|
27
|
+
},
|
|
28
|
+
"homepage": "https://docs.predictorsdk.com",
|
|
29
|
+
"bugs": {
|
|
30
|
+
"url": "https://github.com/PredictorSDK/sdk-typescript/issues"
|
|
31
|
+
},
|
|
32
|
+
"publishConfig": {
|
|
33
|
+
"access": "public"
|
|
34
|
+
},
|
|
35
|
+
"engines": {
|
|
36
|
+
"node": ">=18"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@types/node": "^22.0.0",
|
|
40
|
+
"typescript": "^5.7.0"
|
|
41
|
+
}
|
|
42
|
+
}
|