@credal/sdk 0.1.5 → 0.1.7
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/cjs/Client.d.ts +2 -2
- package/dist/cjs/Client.js +2 -2
- package/dist/cjs/api/resources/copilots/client/Client.d.ts +2 -2
- package/dist/cjs/api/resources/documentCatalog/client/Client.d.ts +2 -2
- package/dist/cjs/api/resources/documentCatalog/client/requests/UploadDocumentContentsRequest.d.ts +2 -2
- package/dist/cjs/api/resources/documentCollections/client/Client.d.ts +2 -2
- package/dist/cjs/api/resources/search/client/Client.d.ts +2 -2
- package/dist/cjs/api/resources/users/client/Client.d.ts +2 -2
- package/dist/cjs/core/auth/index.d.ts +2 -2
- package/dist/cjs/core/fetcher/EndpointMetadata.d.ts +13 -0
- package/dist/cjs/core/fetcher/EndpointMetadata.js +2 -0
- package/dist/cjs/core/fetcher/EndpointSupplier.d.ts +12 -0
- package/dist/cjs/core/fetcher/EndpointSupplier.js +22 -0
- package/dist/cjs/core/fetcher/Fetcher.d.ts +4 -2
- package/dist/cjs/core/fetcher/Fetcher.js +3 -2
- package/dist/cjs/core/fetcher/index.d.ts +2 -0
- package/dist/cjs/core/fetcher/index.js +3 -1
- package/dist/cjs/core/fetcher/requestWithRetries.js +44 -8
- package/dist/cjs/core/headers.d.ts +2 -3
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/Client.d.mts +2 -2
- package/dist/esm/Client.mjs +2 -2
- package/dist/esm/api/resources/copilots/client/Client.d.mts +2 -2
- package/dist/esm/api/resources/documentCatalog/client/Client.d.mts +2 -2
- package/dist/esm/api/resources/documentCatalog/client/requests/UploadDocumentContentsRequest.d.mts +2 -2
- package/dist/esm/api/resources/documentCollections/client/Client.d.mts +2 -2
- package/dist/esm/api/resources/search/client/Client.d.mts +2 -2
- package/dist/esm/api/resources/users/client/Client.d.mts +2 -2
- package/dist/esm/core/auth/index.d.mts +2 -2
- package/dist/esm/core/fetcher/EndpointMetadata.d.mts +13 -0
- package/dist/esm/core/fetcher/EndpointMetadata.mjs +1 -0
- package/dist/esm/core/fetcher/EndpointSupplier.d.mts +12 -0
- package/dist/esm/core/fetcher/EndpointSupplier.mjs +19 -0
- package/dist/esm/core/fetcher/Fetcher.d.mts +4 -2
- package/dist/esm/core/fetcher/Fetcher.mjs +3 -2
- package/dist/esm/core/fetcher/index.d.mts +2 -0
- package/dist/esm/core/fetcher/index.mjs +1 -0
- package/dist/esm/core/fetcher/requestWithRetries.mjs +44 -8
- package/dist/esm/core/headers.d.mts +2 -3
- package/dist/esm/version.d.mts +1 -1
- package/dist/esm/version.mjs +1 -1
- package/package.json +8 -13
package/dist/cjs/Client.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ export declare namespace CredalClient {
|
|
|
15
15
|
baseUrl?: core.Supplier<string>;
|
|
16
16
|
apiKey?: core.Supplier<core.BearerToken | undefined>;
|
|
17
17
|
/** Additional headers to include in requests. */
|
|
18
|
-
headers?: Record<string, string | core.Supplier<string | undefined> | undefined>;
|
|
18
|
+
headers?: Record<string, string | core.Supplier<string | null | undefined> | null | undefined>;
|
|
19
19
|
fetcher?: core.FetchFunction;
|
|
20
20
|
}
|
|
21
21
|
interface RequestOptions {
|
|
@@ -28,7 +28,7 @@ export declare namespace CredalClient {
|
|
|
28
28
|
/** Additional query string parameters to include in the request. */
|
|
29
29
|
queryParams?: Record<string, unknown>;
|
|
30
30
|
/** Additional headers to include in the request. */
|
|
31
|
-
headers?: Record<string, string | core.Supplier<string | undefined> | undefined>;
|
|
31
|
+
headers?: Record<string, string | core.Supplier<string | null | undefined> | null | undefined>;
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
34
|
export declare class CredalClient {
|
package/dist/cjs/Client.js
CHANGED
|
@@ -49,8 +49,8 @@ class CredalClient {
|
|
|
49
49
|
this._options = Object.assign(Object.assign({}, _options), { headers: (0, headers_js_1.mergeHeaders)({
|
|
50
50
|
"X-Fern-Language": "JavaScript",
|
|
51
51
|
"X-Fern-SDK-Name": "@credal/sdk",
|
|
52
|
-
"X-Fern-SDK-Version": "0.1.
|
|
53
|
-
"User-Agent": "@credal/sdk/0.1.
|
|
52
|
+
"X-Fern-SDK-Version": "0.1.7",
|
|
53
|
+
"User-Agent": "@credal/sdk/0.1.7",
|
|
54
54
|
"X-Fern-Runtime": core.RUNTIME.type,
|
|
55
55
|
"X-Fern-Runtime-Version": core.RUNTIME.version,
|
|
56
56
|
}, _options === null || _options === void 0 ? void 0 : _options.headers) });
|
|
@@ -11,7 +11,7 @@ export declare namespace Copilots {
|
|
|
11
11
|
baseUrl?: core.Supplier<string>;
|
|
12
12
|
apiKey?: core.Supplier<core.BearerToken | undefined>;
|
|
13
13
|
/** Additional headers to include in requests. */
|
|
14
|
-
headers?: Record<string, string | core.Supplier<string | undefined> | undefined>;
|
|
14
|
+
headers?: Record<string, string | core.Supplier<string | null | undefined> | null | undefined>;
|
|
15
15
|
fetcher?: core.FetchFunction;
|
|
16
16
|
}
|
|
17
17
|
interface RequestOptions {
|
|
@@ -24,7 +24,7 @@ export declare namespace Copilots {
|
|
|
24
24
|
/** Additional query string parameters to include in the request. */
|
|
25
25
|
queryParams?: Record<string, unknown>;
|
|
26
26
|
/** Additional headers to include in the request. */
|
|
27
|
-
headers?: Record<string, string | core.Supplier<string | undefined> | undefined>;
|
|
27
|
+
headers?: Record<string, string | core.Supplier<string | null | undefined> | null | undefined>;
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
export declare class Copilots {
|
|
@@ -11,7 +11,7 @@ export declare namespace DocumentCatalog {
|
|
|
11
11
|
baseUrl?: core.Supplier<string>;
|
|
12
12
|
apiKey?: core.Supplier<core.BearerToken | undefined>;
|
|
13
13
|
/** Additional headers to include in requests. */
|
|
14
|
-
headers?: Record<string, string | core.Supplier<string | undefined> | undefined>;
|
|
14
|
+
headers?: Record<string, string | core.Supplier<string | null | undefined> | null | undefined>;
|
|
15
15
|
fetcher?: core.FetchFunction;
|
|
16
16
|
}
|
|
17
17
|
interface RequestOptions {
|
|
@@ -24,7 +24,7 @@ export declare namespace DocumentCatalog {
|
|
|
24
24
|
/** Additional query string parameters to include in the request. */
|
|
25
25
|
queryParams?: Record<string, unknown>;
|
|
26
26
|
/** Additional headers to include in the request. */
|
|
27
|
-
headers?: Record<string, string | core.Supplier<string | undefined> | undefined>;
|
|
27
|
+
headers?: Record<string, string | core.Supplier<string | null | undefined> | null | undefined>;
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
export declare class DocumentCatalog {
|
package/dist/cjs/api/resources/documentCatalog/client/requests/UploadDocumentContentsRequest.d.ts
CHANGED
|
@@ -27,12 +27,12 @@ export interface UploadDocumentContentsRequest {
|
|
|
27
27
|
documentExternalUrl?: string;
|
|
28
28
|
/** Optional JSON representing any custom metadata for this document */
|
|
29
29
|
customMetadata?: Record<string, Credal.CustomMetadataValue>;
|
|
30
|
-
/** If specified, the document will also be added to the provided document collection.
|
|
30
|
+
/** If specified, the document will also be added to the provided document collection. This operation is eventually consistent, meaning the document does not immediately start appearing in searches of that collection due to an asynchronous embedding process. To achieve strong consistency use the `awaitVectorStoreSync` parameter. */
|
|
31
31
|
collectionId?: string;
|
|
32
32
|
/** If specified, document contents will be re-uploaded and re-embedded even if the document already exists in Credal */
|
|
33
33
|
forceUpdate?: boolean;
|
|
34
34
|
/** If specified, document will be accessible to everyone within the organization of the uploader */
|
|
35
35
|
internalPublic?: boolean;
|
|
36
|
-
/** If specified
|
|
36
|
+
/** Document uploads are eventually consistent by default. If specified `true` the API will wait for the vector store to be updated before returning. This is useful if you want to ensure that the document is immediately searchable after this call returns. */
|
|
37
37
|
awaitVectorStoreSync?: boolean;
|
|
38
38
|
}
|
|
@@ -11,7 +11,7 @@ export declare namespace DocumentCollections {
|
|
|
11
11
|
baseUrl?: core.Supplier<string>;
|
|
12
12
|
apiKey?: core.Supplier<core.BearerToken | undefined>;
|
|
13
13
|
/** Additional headers to include in requests. */
|
|
14
|
-
headers?: Record<string, string | core.Supplier<string | undefined> | undefined>;
|
|
14
|
+
headers?: Record<string, string | core.Supplier<string | null | undefined> | null | undefined>;
|
|
15
15
|
fetcher?: core.FetchFunction;
|
|
16
16
|
}
|
|
17
17
|
interface RequestOptions {
|
|
@@ -24,7 +24,7 @@ export declare namespace DocumentCollections {
|
|
|
24
24
|
/** Additional query string parameters to include in the request. */
|
|
25
25
|
queryParams?: Record<string, unknown>;
|
|
26
26
|
/** Additional headers to include in the request. */
|
|
27
|
-
headers?: Record<string, string | core.Supplier<string | undefined> | undefined>;
|
|
27
|
+
headers?: Record<string, string | core.Supplier<string | null | undefined> | null | undefined>;
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
export declare class DocumentCollections {
|
|
@@ -11,7 +11,7 @@ export declare namespace Search {
|
|
|
11
11
|
baseUrl?: core.Supplier<string>;
|
|
12
12
|
apiKey?: core.Supplier<core.BearerToken | undefined>;
|
|
13
13
|
/** Additional headers to include in requests. */
|
|
14
|
-
headers?: Record<string, string | core.Supplier<string | undefined> | undefined>;
|
|
14
|
+
headers?: Record<string, string | core.Supplier<string | null | undefined> | null | undefined>;
|
|
15
15
|
fetcher?: core.FetchFunction;
|
|
16
16
|
}
|
|
17
17
|
interface RequestOptions {
|
|
@@ -24,7 +24,7 @@ export declare namespace Search {
|
|
|
24
24
|
/** Additional query string parameters to include in the request. */
|
|
25
25
|
queryParams?: Record<string, unknown>;
|
|
26
26
|
/** Additional headers to include in the request. */
|
|
27
|
-
headers?: Record<string, string | core.Supplier<string | undefined> | undefined>;
|
|
27
|
+
headers?: Record<string, string | core.Supplier<string | null | undefined> | null | undefined>;
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
export declare class Search {
|
|
@@ -11,7 +11,7 @@ export declare namespace Users {
|
|
|
11
11
|
baseUrl?: core.Supplier<string>;
|
|
12
12
|
apiKey?: core.Supplier<core.BearerToken | undefined>;
|
|
13
13
|
/** Additional headers to include in requests. */
|
|
14
|
-
headers?: Record<string, string | core.Supplier<string | undefined> | undefined>;
|
|
14
|
+
headers?: Record<string, string | core.Supplier<string | null | undefined> | null | undefined>;
|
|
15
15
|
fetcher?: core.FetchFunction;
|
|
16
16
|
}
|
|
17
17
|
interface RequestOptions {
|
|
@@ -24,7 +24,7 @@ export declare namespace Users {
|
|
|
24
24
|
/** Additional query string parameters to include in the request. */
|
|
25
25
|
queryParams?: Record<string, unknown>;
|
|
26
26
|
/** Additional headers to include in the request. */
|
|
27
|
-
headers?: Record<string, string | core.Supplier<string | undefined> | undefined>;
|
|
27
|
+
headers?: Record<string, string | core.Supplier<string | null | undefined> | null | undefined>;
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
export declare class Users {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { AuthProvider } from "./AuthProvider.js";
|
|
2
|
-
export {
|
|
1
|
+
export type { AuthProvider } from "./AuthProvider.js";
|
|
2
|
+
export type { AuthRequest } from "./AuthRequest.js";
|
|
3
3
|
export { BasicAuth } from "./BasicAuth.js";
|
|
4
4
|
export { BearerToken } from "./BearerToken.js";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type SecuritySchemeKey = string;
|
|
2
|
+
/**
|
|
3
|
+
* A collection of security schemes, where the key is the name of the security scheme and the value is the list of scopes required for that scheme.
|
|
4
|
+
* All schemes in the collection must be satisfied for authentication to be successful.
|
|
5
|
+
*/
|
|
6
|
+
export type SecuritySchemeCollection = Record<SecuritySchemeKey, AuthScope[]>;
|
|
7
|
+
export type AuthScope = string;
|
|
8
|
+
export type EndpointMetadata = {
|
|
9
|
+
/**
|
|
10
|
+
* An array of security scheme collections. Each collection represents an alternative way to authenticate.
|
|
11
|
+
*/
|
|
12
|
+
security?: SecuritySchemeCollection[];
|
|
13
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { EndpointMetadata } from "./EndpointMetadata.js";
|
|
2
|
+
import { Supplier } from "./Supplier.js";
|
|
3
|
+
type EndpointSupplierFn<T> = (arg: {
|
|
4
|
+
endpointMetadata: EndpointMetadata;
|
|
5
|
+
}) => T | Promise<T>;
|
|
6
|
+
export type EndpointSupplier<T> = Supplier<T> | EndpointSupplierFn<T>;
|
|
7
|
+
export declare const EndpointSupplier: {
|
|
8
|
+
get: <T>(supplier: EndpointSupplier<T>, arg: {
|
|
9
|
+
endpointMetadata: EndpointMetadata;
|
|
10
|
+
}) => Promise<T>;
|
|
11
|
+
};
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.EndpointSupplier = void 0;
|
|
13
|
+
exports.EndpointSupplier = {
|
|
14
|
+
get: (supplier, arg) => __awaiter(void 0, void 0, void 0, function* () {
|
|
15
|
+
if (typeof supplier === "function") {
|
|
16
|
+
return supplier(arg);
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
return supplier;
|
|
20
|
+
}
|
|
21
|
+
}),
|
|
22
|
+
};
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { APIResponse } from "./APIResponse.js";
|
|
2
|
-
import {
|
|
2
|
+
import { EndpointMetadata } from "./EndpointMetadata.js";
|
|
3
|
+
import { EndpointSupplier } from "./EndpointSupplier.js";
|
|
3
4
|
export type FetchFunction = <R = unknown>(args: Fetcher.Args) => Promise<APIResponse<R, Fetcher.Error>>;
|
|
4
5
|
export declare namespace Fetcher {
|
|
5
6
|
interface Args {
|
|
6
7
|
url: string;
|
|
7
8
|
method: string;
|
|
8
9
|
contentType?: string;
|
|
9
|
-
headers?: Record<string, string |
|
|
10
|
+
headers?: Record<string, string | EndpointSupplier<string | null | undefined> | null | undefined>;
|
|
10
11
|
queryParameters?: Record<string, unknown>;
|
|
11
12
|
body?: unknown;
|
|
12
13
|
timeoutMs?: number;
|
|
@@ -16,6 +17,7 @@ export declare namespace Fetcher {
|
|
|
16
17
|
requestType?: "json" | "file" | "bytes";
|
|
17
18
|
responseType?: "json" | "blob" | "sse" | "streaming" | "text" | "arrayBuffer" | "binary-response";
|
|
18
19
|
duplex?: "half";
|
|
20
|
+
endpointMetadata?: EndpointMetadata;
|
|
19
21
|
}
|
|
20
22
|
type Error = FailedStatusCodeError | NonJsonError | TimeoutError | UnknownError;
|
|
21
23
|
interface FailedStatusCodeError {
|
|
@@ -13,6 +13,7 @@ exports.fetcher = void 0;
|
|
|
13
13
|
exports.fetcherImpl = fetcherImpl;
|
|
14
14
|
const json_js_1 = require("../json.js");
|
|
15
15
|
const createRequestUrl_js_1 = require("./createRequestUrl.js");
|
|
16
|
+
const EndpointSupplier_js_1 = require("./EndpointSupplier.js");
|
|
16
17
|
const getErrorResponseBody_js_1 = require("./getErrorResponseBody.js");
|
|
17
18
|
const getFetchFn_js_1 = require("./getFetchFn.js");
|
|
18
19
|
const getRequestBody_js_1 = require("./getRequestBody.js");
|
|
@@ -20,9 +21,9 @@ const getResponseBody_js_1 = require("./getResponseBody.js");
|
|
|
20
21
|
const makeRequest_js_1 = require("./makeRequest.js");
|
|
21
22
|
const RawResponse_js_1 = require("./RawResponse.js");
|
|
22
23
|
const requestWithRetries_js_1 = require("./requestWithRetries.js");
|
|
23
|
-
const Supplier_js_1 = require("./Supplier.js");
|
|
24
24
|
function getHeaders(args) {
|
|
25
25
|
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
var _a;
|
|
26
27
|
const newHeaders = {};
|
|
27
28
|
if (args.body !== undefined && args.contentType != null) {
|
|
28
29
|
newHeaders["Content-Type"] = args.contentType;
|
|
@@ -31,7 +32,7 @@ function getHeaders(args) {
|
|
|
31
32
|
return newHeaders;
|
|
32
33
|
}
|
|
33
34
|
for (const [key, value] of Object.entries(args.headers)) {
|
|
34
|
-
const result = yield
|
|
35
|
+
const result = yield EndpointSupplier_js_1.EndpointSupplier.get(value, { endpointMetadata: (_a = args.endpointMetadata) !== null && _a !== void 0 ? _a : {} });
|
|
35
36
|
if (typeof result === "string") {
|
|
36
37
|
newHeaders[key] = result;
|
|
37
38
|
continue;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export type { APIResponse } from "./APIResponse.js";
|
|
2
2
|
export type { BinaryResponse } from "./BinaryResponse.js";
|
|
3
|
+
export type { EndpointMetadata } from "./EndpointMetadata.js";
|
|
4
|
+
export { EndpointSupplier } from "./EndpointSupplier.js";
|
|
3
5
|
export type { Fetcher, FetchFunction } from "./Fetcher.js";
|
|
4
6
|
export { fetcher } from "./Fetcher.js";
|
|
5
7
|
export { getHeader } from "./getHeader.js";
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Supplier = exports.unknownRawResponse = exports.toRawResponse = exports.abortRawResponse = exports.HttpResponsePromise = exports.getHeader = exports.fetcher = void 0;
|
|
3
|
+
exports.Supplier = exports.unknownRawResponse = exports.toRawResponse = exports.abortRawResponse = exports.HttpResponsePromise = exports.getHeader = exports.fetcher = exports.EndpointSupplier = void 0;
|
|
4
|
+
var EndpointSupplier_js_1 = require("./EndpointSupplier.js");
|
|
5
|
+
Object.defineProperty(exports, "EndpointSupplier", { enumerable: true, get: function () { return EndpointSupplier_js_1.EndpointSupplier; } });
|
|
4
6
|
var Fetcher_js_1 = require("./Fetcher.js");
|
|
5
7
|
Object.defineProperty(exports, "fetcher", { enumerable: true, get: function () { return Fetcher_js_1.fetcher; } });
|
|
6
8
|
var getHeader_js_1 = require("./getHeader.js");
|
|
@@ -14,21 +14,57 @@ const INITIAL_RETRY_DELAY = 1000; // in milliseconds
|
|
|
14
14
|
const MAX_RETRY_DELAY = 60000; // in milliseconds
|
|
15
15
|
const DEFAULT_MAX_RETRIES = 2;
|
|
16
16
|
const JITTER_FACTOR = 0.2; // 20% random jitter
|
|
17
|
-
function
|
|
18
|
-
// Generate a random value between
|
|
19
|
-
const jitterMultiplier = 1 +
|
|
17
|
+
function addPositiveJitter(delay) {
|
|
18
|
+
// Generate a random value between 0 and +JITTER_FACTOR
|
|
19
|
+
const jitterMultiplier = 1 + Math.random() * JITTER_FACTOR;
|
|
20
20
|
return delay * jitterMultiplier;
|
|
21
21
|
}
|
|
22
|
+
function addSymmetricJitter(delay) {
|
|
23
|
+
// Generate a random value in a JITTER_FACTOR-sized percentage range around delay
|
|
24
|
+
const jitterMultiplier = 1 + (Math.random() - 0.5) * JITTER_FACTOR;
|
|
25
|
+
return delay * jitterMultiplier;
|
|
26
|
+
}
|
|
27
|
+
function getRetryDelayFromHeaders(response, retryAttempt) {
|
|
28
|
+
// Check for Retry-After header first (RFC 7231), with no jitter
|
|
29
|
+
const retryAfter = response.headers.get("Retry-After");
|
|
30
|
+
if (retryAfter) {
|
|
31
|
+
// Parse as number of seconds...
|
|
32
|
+
const retryAfterSeconds = parseInt(retryAfter, 10);
|
|
33
|
+
if (!isNaN(retryAfterSeconds) && retryAfterSeconds > 0) {
|
|
34
|
+
return Math.min(retryAfterSeconds * 1000, MAX_RETRY_DELAY);
|
|
35
|
+
}
|
|
36
|
+
// ...or as an HTTP date; both are valid
|
|
37
|
+
const retryAfterDate = new Date(retryAfter);
|
|
38
|
+
if (!isNaN(retryAfterDate.getTime())) {
|
|
39
|
+
const delay = retryAfterDate.getTime() - Date.now();
|
|
40
|
+
if (delay > 0) {
|
|
41
|
+
return Math.min(Math.max(delay, 0), MAX_RETRY_DELAY);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
// Then check for industry-standard X-RateLimit-Reset header, with positive jitter
|
|
46
|
+
const rateLimitReset = response.headers.get("X-RateLimit-Reset");
|
|
47
|
+
if (rateLimitReset) {
|
|
48
|
+
const resetTime = parseInt(rateLimitReset, 10);
|
|
49
|
+
if (!isNaN(resetTime)) {
|
|
50
|
+
// Assume Unix timestamp in epoch seconds
|
|
51
|
+
const delay = resetTime * 1000 - Date.now();
|
|
52
|
+
if (delay > 0) {
|
|
53
|
+
return addPositiveJitter(Math.min(delay, MAX_RETRY_DELAY));
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
// Fall back to exponential backoff, with symmetric jitter
|
|
58
|
+
return addSymmetricJitter(Math.min(INITIAL_RETRY_DELAY * Math.pow(2, retryAttempt), MAX_RETRY_DELAY));
|
|
59
|
+
}
|
|
22
60
|
function requestWithRetries(requestFn_1) {
|
|
23
61
|
return __awaiter(this, arguments, void 0, function* (requestFn, maxRetries = DEFAULT_MAX_RETRIES) {
|
|
24
62
|
let response = yield requestFn();
|
|
25
63
|
for (let i = 0; i < maxRetries; ++i) {
|
|
26
64
|
if ([408, 429].includes(response.status) || response.status >= 500) {
|
|
27
|
-
//
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
const delayWithJitter = addJitter(baseDelay);
|
|
31
|
-
yield new Promise((resolve) => setTimeout(resolve, delayWithJitter));
|
|
65
|
+
// Get delay with appropriate jitter applied
|
|
66
|
+
const delay = getRetryDelayFromHeaders(response, i);
|
|
67
|
+
yield new Promise((resolve) => setTimeout(resolve, delay));
|
|
32
68
|
response = yield requestFn();
|
|
33
69
|
}
|
|
34
70
|
else {
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
export declare function
|
|
3
|
-
export declare function mergeOnlyDefinedHeaders(...headersArray: (Record<string, string | core.Supplier<string | undefined> | undefined> | undefined)[]): Record<string, string | core.Supplier<string | undefined>>;
|
|
1
|
+
export declare function mergeHeaders<THeaderValue>(...headersArray: (Record<string, THeaderValue> | null | undefined)[]): Record<string, string | THeaderValue>;
|
|
2
|
+
export declare function mergeOnlyDefinedHeaders<THeaderValue>(...headersArray: (Record<string, THeaderValue> | null | undefined)[]): Record<string, THeaderValue>;
|
package/dist/cjs/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "0.1.
|
|
1
|
+
export declare const SDK_VERSION = "0.1.7";
|
package/dist/cjs/version.js
CHANGED
package/dist/esm/Client.d.mts
CHANGED
|
@@ -15,7 +15,7 @@ export declare namespace CredalClient {
|
|
|
15
15
|
baseUrl?: core.Supplier<string>;
|
|
16
16
|
apiKey?: core.Supplier<core.BearerToken | undefined>;
|
|
17
17
|
/** Additional headers to include in requests. */
|
|
18
|
-
headers?: Record<string, string | core.Supplier<string | undefined> | undefined>;
|
|
18
|
+
headers?: Record<string, string | core.Supplier<string | null | undefined> | null | undefined>;
|
|
19
19
|
fetcher?: core.FetchFunction;
|
|
20
20
|
}
|
|
21
21
|
interface RequestOptions {
|
|
@@ -28,7 +28,7 @@ export declare namespace CredalClient {
|
|
|
28
28
|
/** Additional query string parameters to include in the request. */
|
|
29
29
|
queryParams?: Record<string, unknown>;
|
|
30
30
|
/** Additional headers to include in the request. */
|
|
31
|
-
headers?: Record<string, string | core.Supplier<string | undefined> | undefined>;
|
|
31
|
+
headers?: Record<string, string | core.Supplier<string | null | undefined> | null | undefined>;
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
34
|
export declare class CredalClient {
|
package/dist/esm/Client.mjs
CHANGED
|
@@ -13,8 +13,8 @@ export class CredalClient {
|
|
|
13
13
|
this._options = Object.assign(Object.assign({}, _options), { headers: mergeHeaders({
|
|
14
14
|
"X-Fern-Language": "JavaScript",
|
|
15
15
|
"X-Fern-SDK-Name": "@credal/sdk",
|
|
16
|
-
"X-Fern-SDK-Version": "0.1.
|
|
17
|
-
"User-Agent": "@credal/sdk/0.1.
|
|
16
|
+
"X-Fern-SDK-Version": "0.1.7",
|
|
17
|
+
"User-Agent": "@credal/sdk/0.1.7",
|
|
18
18
|
"X-Fern-Runtime": core.RUNTIME.type,
|
|
19
19
|
"X-Fern-Runtime-Version": core.RUNTIME.version,
|
|
20
20
|
}, _options === null || _options === void 0 ? void 0 : _options.headers) });
|
|
@@ -11,7 +11,7 @@ export declare namespace Copilots {
|
|
|
11
11
|
baseUrl?: core.Supplier<string>;
|
|
12
12
|
apiKey?: core.Supplier<core.BearerToken | undefined>;
|
|
13
13
|
/** Additional headers to include in requests. */
|
|
14
|
-
headers?: Record<string, string | core.Supplier<string | undefined> | undefined>;
|
|
14
|
+
headers?: Record<string, string | core.Supplier<string | null | undefined> | null | undefined>;
|
|
15
15
|
fetcher?: core.FetchFunction;
|
|
16
16
|
}
|
|
17
17
|
interface RequestOptions {
|
|
@@ -24,7 +24,7 @@ export declare namespace Copilots {
|
|
|
24
24
|
/** Additional query string parameters to include in the request. */
|
|
25
25
|
queryParams?: Record<string, unknown>;
|
|
26
26
|
/** Additional headers to include in the request. */
|
|
27
|
-
headers?: Record<string, string | core.Supplier<string | undefined> | undefined>;
|
|
27
|
+
headers?: Record<string, string | core.Supplier<string | null | undefined> | null | undefined>;
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
export declare class Copilots {
|
|
@@ -11,7 +11,7 @@ export declare namespace DocumentCatalog {
|
|
|
11
11
|
baseUrl?: core.Supplier<string>;
|
|
12
12
|
apiKey?: core.Supplier<core.BearerToken | undefined>;
|
|
13
13
|
/** Additional headers to include in requests. */
|
|
14
|
-
headers?: Record<string, string | core.Supplier<string | undefined> | undefined>;
|
|
14
|
+
headers?: Record<string, string | core.Supplier<string | null | undefined> | null | undefined>;
|
|
15
15
|
fetcher?: core.FetchFunction;
|
|
16
16
|
}
|
|
17
17
|
interface RequestOptions {
|
|
@@ -24,7 +24,7 @@ export declare namespace DocumentCatalog {
|
|
|
24
24
|
/** Additional query string parameters to include in the request. */
|
|
25
25
|
queryParams?: Record<string, unknown>;
|
|
26
26
|
/** Additional headers to include in the request. */
|
|
27
|
-
headers?: Record<string, string | core.Supplier<string | undefined> | undefined>;
|
|
27
|
+
headers?: Record<string, string | core.Supplier<string | null | undefined> | null | undefined>;
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
export declare class DocumentCatalog {
|
package/dist/esm/api/resources/documentCatalog/client/requests/UploadDocumentContentsRequest.d.mts
CHANGED
|
@@ -27,12 +27,12 @@ export interface UploadDocumentContentsRequest {
|
|
|
27
27
|
documentExternalUrl?: string;
|
|
28
28
|
/** Optional JSON representing any custom metadata for this document */
|
|
29
29
|
customMetadata?: Record<string, Credal.CustomMetadataValue>;
|
|
30
|
-
/** If specified, the document will also be added to the provided document collection.
|
|
30
|
+
/** If specified, the document will also be added to the provided document collection. This operation is eventually consistent, meaning the document does not immediately start appearing in searches of that collection due to an asynchronous embedding process. To achieve strong consistency use the `awaitVectorStoreSync` parameter. */
|
|
31
31
|
collectionId?: string;
|
|
32
32
|
/** If specified, document contents will be re-uploaded and re-embedded even if the document already exists in Credal */
|
|
33
33
|
forceUpdate?: boolean;
|
|
34
34
|
/** If specified, document will be accessible to everyone within the organization of the uploader */
|
|
35
35
|
internalPublic?: boolean;
|
|
36
|
-
/** If specified
|
|
36
|
+
/** Document uploads are eventually consistent by default. If specified `true` the API will wait for the vector store to be updated before returning. This is useful if you want to ensure that the document is immediately searchable after this call returns. */
|
|
37
37
|
awaitVectorStoreSync?: boolean;
|
|
38
38
|
}
|
|
@@ -11,7 +11,7 @@ export declare namespace DocumentCollections {
|
|
|
11
11
|
baseUrl?: core.Supplier<string>;
|
|
12
12
|
apiKey?: core.Supplier<core.BearerToken | undefined>;
|
|
13
13
|
/** Additional headers to include in requests. */
|
|
14
|
-
headers?: Record<string, string | core.Supplier<string | undefined> | undefined>;
|
|
14
|
+
headers?: Record<string, string | core.Supplier<string | null | undefined> | null | undefined>;
|
|
15
15
|
fetcher?: core.FetchFunction;
|
|
16
16
|
}
|
|
17
17
|
interface RequestOptions {
|
|
@@ -24,7 +24,7 @@ export declare namespace DocumentCollections {
|
|
|
24
24
|
/** Additional query string parameters to include in the request. */
|
|
25
25
|
queryParams?: Record<string, unknown>;
|
|
26
26
|
/** Additional headers to include in the request. */
|
|
27
|
-
headers?: Record<string, string | core.Supplier<string | undefined> | undefined>;
|
|
27
|
+
headers?: Record<string, string | core.Supplier<string | null | undefined> | null | undefined>;
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
export declare class DocumentCollections {
|
|
@@ -11,7 +11,7 @@ export declare namespace Search {
|
|
|
11
11
|
baseUrl?: core.Supplier<string>;
|
|
12
12
|
apiKey?: core.Supplier<core.BearerToken | undefined>;
|
|
13
13
|
/** Additional headers to include in requests. */
|
|
14
|
-
headers?: Record<string, string | core.Supplier<string | undefined> | undefined>;
|
|
14
|
+
headers?: Record<string, string | core.Supplier<string | null | undefined> | null | undefined>;
|
|
15
15
|
fetcher?: core.FetchFunction;
|
|
16
16
|
}
|
|
17
17
|
interface RequestOptions {
|
|
@@ -24,7 +24,7 @@ export declare namespace Search {
|
|
|
24
24
|
/** Additional query string parameters to include in the request. */
|
|
25
25
|
queryParams?: Record<string, unknown>;
|
|
26
26
|
/** Additional headers to include in the request. */
|
|
27
|
-
headers?: Record<string, string | core.Supplier<string | undefined> | undefined>;
|
|
27
|
+
headers?: Record<string, string | core.Supplier<string | null | undefined> | null | undefined>;
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
export declare class Search {
|
|
@@ -11,7 +11,7 @@ export declare namespace Users {
|
|
|
11
11
|
baseUrl?: core.Supplier<string>;
|
|
12
12
|
apiKey?: core.Supplier<core.BearerToken | undefined>;
|
|
13
13
|
/** Additional headers to include in requests. */
|
|
14
|
-
headers?: Record<string, string | core.Supplier<string | undefined> | undefined>;
|
|
14
|
+
headers?: Record<string, string | core.Supplier<string | null | undefined> | null | undefined>;
|
|
15
15
|
fetcher?: core.FetchFunction;
|
|
16
16
|
}
|
|
17
17
|
interface RequestOptions {
|
|
@@ -24,7 +24,7 @@ export declare namespace Users {
|
|
|
24
24
|
/** Additional query string parameters to include in the request. */
|
|
25
25
|
queryParams?: Record<string, unknown>;
|
|
26
26
|
/** Additional headers to include in the request. */
|
|
27
|
-
headers?: Record<string, string | core.Supplier<string | undefined> | undefined>;
|
|
27
|
+
headers?: Record<string, string | core.Supplier<string | null | undefined> | null | undefined>;
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
export declare class Users {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { AuthProvider } from "./AuthProvider.mjs";
|
|
2
|
-
export {
|
|
1
|
+
export type { AuthProvider } from "./AuthProvider.mjs";
|
|
2
|
+
export type { AuthRequest } from "./AuthRequest.mjs";
|
|
3
3
|
export { BasicAuth } from "./BasicAuth.mjs";
|
|
4
4
|
export { BearerToken } from "./BearerToken.mjs";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type SecuritySchemeKey = string;
|
|
2
|
+
/**
|
|
3
|
+
* A collection of security schemes, where the key is the name of the security scheme and the value is the list of scopes required for that scheme.
|
|
4
|
+
* All schemes in the collection must be satisfied for authentication to be successful.
|
|
5
|
+
*/
|
|
6
|
+
export type SecuritySchemeCollection = Record<SecuritySchemeKey, AuthScope[]>;
|
|
7
|
+
export type AuthScope = string;
|
|
8
|
+
export type EndpointMetadata = {
|
|
9
|
+
/**
|
|
10
|
+
* An array of security scheme collections. Each collection represents an alternative way to authenticate.
|
|
11
|
+
*/
|
|
12
|
+
security?: SecuritySchemeCollection[];
|
|
13
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { EndpointMetadata } from "./EndpointMetadata.mjs";
|
|
2
|
+
import { Supplier } from "./Supplier.mjs";
|
|
3
|
+
type EndpointSupplierFn<T> = (arg: {
|
|
4
|
+
endpointMetadata: EndpointMetadata;
|
|
5
|
+
}) => T | Promise<T>;
|
|
6
|
+
export type EndpointSupplier<T> = Supplier<T> | EndpointSupplierFn<T>;
|
|
7
|
+
export declare const EndpointSupplier: {
|
|
8
|
+
get: <T>(supplier: EndpointSupplier<T>, arg: {
|
|
9
|
+
endpointMetadata: EndpointMetadata;
|
|
10
|
+
}) => Promise<T>;
|
|
11
|
+
};
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
export const EndpointSupplier = {
|
|
11
|
+
get: (supplier, arg) => __awaiter(void 0, void 0, void 0, function* () {
|
|
12
|
+
if (typeof supplier === "function") {
|
|
13
|
+
return supplier(arg);
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
return supplier;
|
|
17
|
+
}
|
|
18
|
+
}),
|
|
19
|
+
};
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { APIResponse } from "./APIResponse.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { EndpointMetadata } from "./EndpointMetadata.mjs";
|
|
3
|
+
import { EndpointSupplier } from "./EndpointSupplier.mjs";
|
|
3
4
|
export type FetchFunction = <R = unknown>(args: Fetcher.Args) => Promise<APIResponse<R, Fetcher.Error>>;
|
|
4
5
|
export declare namespace Fetcher {
|
|
5
6
|
interface Args {
|
|
6
7
|
url: string;
|
|
7
8
|
method: string;
|
|
8
9
|
contentType?: string;
|
|
9
|
-
headers?: Record<string, string |
|
|
10
|
+
headers?: Record<string, string | EndpointSupplier<string | null | undefined> | null | undefined>;
|
|
10
11
|
queryParameters?: Record<string, unknown>;
|
|
11
12
|
body?: unknown;
|
|
12
13
|
timeoutMs?: number;
|
|
@@ -16,6 +17,7 @@ export declare namespace Fetcher {
|
|
|
16
17
|
requestType?: "json" | "file" | "bytes";
|
|
17
18
|
responseType?: "json" | "blob" | "sse" | "streaming" | "text" | "arrayBuffer" | "binary-response";
|
|
18
19
|
duplex?: "half";
|
|
20
|
+
endpointMetadata?: EndpointMetadata;
|
|
19
21
|
}
|
|
20
22
|
type Error = FailedStatusCodeError | NonJsonError | TimeoutError | UnknownError;
|
|
21
23
|
interface FailedStatusCodeError {
|
|
@@ -9,6 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import { toJson } from "../json.mjs";
|
|
11
11
|
import { createRequestUrl } from "./createRequestUrl.mjs";
|
|
12
|
+
import { EndpointSupplier } from "./EndpointSupplier.mjs";
|
|
12
13
|
import { getErrorResponseBody } from "./getErrorResponseBody.mjs";
|
|
13
14
|
import { getFetchFn } from "./getFetchFn.mjs";
|
|
14
15
|
import { getRequestBody } from "./getRequestBody.mjs";
|
|
@@ -16,9 +17,9 @@ import { getResponseBody } from "./getResponseBody.mjs";
|
|
|
16
17
|
import { makeRequest } from "./makeRequest.mjs";
|
|
17
18
|
import { abortRawResponse, toRawResponse, unknownRawResponse } from "./RawResponse.mjs";
|
|
18
19
|
import { requestWithRetries } from "./requestWithRetries.mjs";
|
|
19
|
-
import { Supplier } from "./Supplier.mjs";
|
|
20
20
|
function getHeaders(args) {
|
|
21
21
|
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
+
var _a;
|
|
22
23
|
const newHeaders = {};
|
|
23
24
|
if (args.body !== undefined && args.contentType != null) {
|
|
24
25
|
newHeaders["Content-Type"] = args.contentType;
|
|
@@ -27,7 +28,7 @@ function getHeaders(args) {
|
|
|
27
28
|
return newHeaders;
|
|
28
29
|
}
|
|
29
30
|
for (const [key, value] of Object.entries(args.headers)) {
|
|
30
|
-
const result = yield
|
|
31
|
+
const result = yield EndpointSupplier.get(value, { endpointMetadata: (_a = args.endpointMetadata) !== null && _a !== void 0 ? _a : {} });
|
|
31
32
|
if (typeof result === "string") {
|
|
32
33
|
newHeaders[key] = result;
|
|
33
34
|
continue;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export type { APIResponse } from "./APIResponse.mjs";
|
|
2
2
|
export type { BinaryResponse } from "./BinaryResponse.mjs";
|
|
3
|
+
export type { EndpointMetadata } from "./EndpointMetadata.mjs";
|
|
4
|
+
export { EndpointSupplier } from "./EndpointSupplier.mjs";
|
|
3
5
|
export type { Fetcher, FetchFunction } from "./Fetcher.mjs";
|
|
4
6
|
export { fetcher } from "./Fetcher.mjs";
|
|
5
7
|
export { getHeader } from "./getHeader.mjs";
|
|
@@ -11,21 +11,57 @@ const INITIAL_RETRY_DELAY = 1000; // in milliseconds
|
|
|
11
11
|
const MAX_RETRY_DELAY = 60000; // in milliseconds
|
|
12
12
|
const DEFAULT_MAX_RETRIES = 2;
|
|
13
13
|
const JITTER_FACTOR = 0.2; // 20% random jitter
|
|
14
|
-
function
|
|
15
|
-
// Generate a random value between
|
|
16
|
-
const jitterMultiplier = 1 +
|
|
14
|
+
function addPositiveJitter(delay) {
|
|
15
|
+
// Generate a random value between 0 and +JITTER_FACTOR
|
|
16
|
+
const jitterMultiplier = 1 + Math.random() * JITTER_FACTOR;
|
|
17
17
|
return delay * jitterMultiplier;
|
|
18
18
|
}
|
|
19
|
+
function addSymmetricJitter(delay) {
|
|
20
|
+
// Generate a random value in a JITTER_FACTOR-sized percentage range around delay
|
|
21
|
+
const jitterMultiplier = 1 + (Math.random() - 0.5) * JITTER_FACTOR;
|
|
22
|
+
return delay * jitterMultiplier;
|
|
23
|
+
}
|
|
24
|
+
function getRetryDelayFromHeaders(response, retryAttempt) {
|
|
25
|
+
// Check for Retry-After header first (RFC 7231), with no jitter
|
|
26
|
+
const retryAfter = response.headers.get("Retry-After");
|
|
27
|
+
if (retryAfter) {
|
|
28
|
+
// Parse as number of seconds...
|
|
29
|
+
const retryAfterSeconds = parseInt(retryAfter, 10);
|
|
30
|
+
if (!isNaN(retryAfterSeconds) && retryAfterSeconds > 0) {
|
|
31
|
+
return Math.min(retryAfterSeconds * 1000, MAX_RETRY_DELAY);
|
|
32
|
+
}
|
|
33
|
+
// ...or as an HTTP date; both are valid
|
|
34
|
+
const retryAfterDate = new Date(retryAfter);
|
|
35
|
+
if (!isNaN(retryAfterDate.getTime())) {
|
|
36
|
+
const delay = retryAfterDate.getTime() - Date.now();
|
|
37
|
+
if (delay > 0) {
|
|
38
|
+
return Math.min(Math.max(delay, 0), MAX_RETRY_DELAY);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
// Then check for industry-standard X-RateLimit-Reset header, with positive jitter
|
|
43
|
+
const rateLimitReset = response.headers.get("X-RateLimit-Reset");
|
|
44
|
+
if (rateLimitReset) {
|
|
45
|
+
const resetTime = parseInt(rateLimitReset, 10);
|
|
46
|
+
if (!isNaN(resetTime)) {
|
|
47
|
+
// Assume Unix timestamp in epoch seconds
|
|
48
|
+
const delay = resetTime * 1000 - Date.now();
|
|
49
|
+
if (delay > 0) {
|
|
50
|
+
return addPositiveJitter(Math.min(delay, MAX_RETRY_DELAY));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
// Fall back to exponential backoff, with symmetric jitter
|
|
55
|
+
return addSymmetricJitter(Math.min(INITIAL_RETRY_DELAY * Math.pow(2, retryAttempt), MAX_RETRY_DELAY));
|
|
56
|
+
}
|
|
19
57
|
export function requestWithRetries(requestFn_1) {
|
|
20
58
|
return __awaiter(this, arguments, void 0, function* (requestFn, maxRetries = DEFAULT_MAX_RETRIES) {
|
|
21
59
|
let response = yield requestFn();
|
|
22
60
|
for (let i = 0; i < maxRetries; ++i) {
|
|
23
61
|
if ([408, 429].includes(response.status) || response.status >= 500) {
|
|
24
|
-
//
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
const delayWithJitter = addJitter(baseDelay);
|
|
28
|
-
yield new Promise((resolve) => setTimeout(resolve, delayWithJitter));
|
|
62
|
+
// Get delay with appropriate jitter applied
|
|
63
|
+
const delay = getRetryDelayFromHeaders(response, i);
|
|
64
|
+
yield new Promise((resolve) => setTimeout(resolve, delay));
|
|
29
65
|
response = yield requestFn();
|
|
30
66
|
}
|
|
31
67
|
else {
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
export declare function
|
|
3
|
-
export declare function mergeOnlyDefinedHeaders(...headersArray: (Record<string, string | core.Supplier<string | undefined> | undefined> | undefined)[]): Record<string, string | core.Supplier<string | undefined>>;
|
|
1
|
+
export declare function mergeHeaders<THeaderValue>(...headersArray: (Record<string, THeaderValue> | null | undefined)[]): Record<string, string | THeaderValue>;
|
|
2
|
+
export declare function mergeOnlyDefinedHeaders<THeaderValue>(...headersArray: (Record<string, THeaderValue> | null | undefined)[]): Record<string, THeaderValue>;
|
package/dist/esm/version.d.mts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "0.1.
|
|
1
|
+
export declare const SDK_VERSION = "0.1.7";
|
package/dist/esm/version.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const SDK_VERSION = "0.1.
|
|
1
|
+
export const SDK_VERSION = "0.1.7";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@credal/sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7",
|
|
4
4
|
"private": false,
|
|
5
5
|
"repository": "github:credal-ai/credal-typescript-sdk",
|
|
6
6
|
"type": "commonjs",
|
|
@@ -30,23 +30,18 @@
|
|
|
30
30
|
],
|
|
31
31
|
"scripts": {
|
|
32
32
|
"format": "prettier . --write --ignore-unknown",
|
|
33
|
-
"build": "
|
|
33
|
+
"build": "pnpm build:cjs && pnpm build:esm",
|
|
34
34
|
"build:cjs": "tsc --project ./tsconfig.cjs.json",
|
|
35
35
|
"build:esm": "tsc --project ./tsconfig.esm.json && node scripts/rename-to-esm-files.js dist/esm",
|
|
36
|
-
"test": "
|
|
37
|
-
"test:unit": "
|
|
38
|
-
"test:
|
|
39
|
-
"test:wire": "jest --selectProjects wire"
|
|
36
|
+
"test": "vitest",
|
|
37
|
+
"test:unit": "vitest --project unit",
|
|
38
|
+
"test:wire": "vitest --project wire"
|
|
40
39
|
},
|
|
41
40
|
"devDependencies": {
|
|
42
41
|
"webpack": "^5.97.1",
|
|
43
42
|
"ts-loader": "^9.5.1",
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"@types/jest": "^29.5.14",
|
|
47
|
-
"ts-jest": "^29.3.4",
|
|
48
|
-
"jest-environment-jsdom": "^29.7.0",
|
|
49
|
-
"msw": "^2.8.4",
|
|
43
|
+
"vitest": "^3.2.4",
|
|
44
|
+
"msw": "2.11.2",
|
|
50
45
|
"@types/node": "^18.19.70",
|
|
51
46
|
"prettier": "^3.4.2",
|
|
52
47
|
"typescript": "~5.7.2"
|
|
@@ -57,7 +52,7 @@
|
|
|
57
52
|
"path": false,
|
|
58
53
|
"stream": false
|
|
59
54
|
},
|
|
60
|
-
"packageManager": "
|
|
55
|
+
"packageManager": "pnpm@10.14.0",
|
|
61
56
|
"engines": {
|
|
62
57
|
"node": ">=18.0.0"
|
|
63
58
|
},
|