@credal/sdk 0.1.14 → 0.1.16
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/BaseClient.d.ts +7 -7
- package/dist/cjs/BaseClient.js +7 -3
- package/dist/cjs/Client.d.ts +1 -2
- package/dist/cjs/api/resources/copilots/client/Client.d.ts +1 -2
- package/dist/cjs/api/resources/copilots/client/Client.js +11 -150
- package/dist/cjs/api/resources/documentCatalog/client/Client.d.ts +1 -2
- package/dist/cjs/api/resources/documentCatalog/client/Client.js +5 -60
- package/dist/cjs/api/resources/documentCollections/client/Client.d.ts +1 -2
- package/dist/cjs/api/resources/documentCollections/client/Client.js +8 -105
- package/dist/cjs/api/resources/search/client/Client.d.ts +1 -2
- package/dist/cjs/api/resources/search/client/Client.js +2 -15
- package/dist/cjs/api/resources/users/client/Client.d.ts +1 -2
- package/dist/cjs/api/resources/users/client/Client.js +2 -15
- package/dist/cjs/auth/BearerAuthProvider.d.ts +4 -2
- package/dist/cjs/core/auth/NoOpAuthProvider.d.ts +5 -0
- package/dist/cjs/core/auth/NoOpAuthProvider.js +9 -0
- package/dist/cjs/core/auth/index.d.ts +1 -0
- package/dist/cjs/core/auth/index.js +3 -1
- package/dist/cjs/core/fetcher/BinaryResponse.d.ts +6 -7
- package/dist/cjs/core/fetcher/Fetcher.d.ts +5 -1
- package/dist/cjs/core/fetcher/Fetcher.js +2 -1
- package/dist/cjs/core/fetcher/getResponseBody.js +18 -4
- package/dist/cjs/core/fetcher/signals.d.ts +1 -1
- package/dist/cjs/core/runtime/runtime.js +11 -10
- package/dist/cjs/errors/CredalError.js +5 -1
- package/dist/cjs/errors/CredalTimeoutError.js +5 -1
- package/dist/cjs/errors/handleNonStatusCodeError.d.ts +2 -0
- package/dist/cjs/errors/handleNonStatusCodeError.js +65 -0
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/BaseClient.d.mts +7 -7
- package/dist/esm/BaseClient.mjs +7 -3
- package/dist/esm/Client.d.mts +1 -2
- package/dist/esm/api/resources/copilots/client/Client.d.mts +1 -2
- package/dist/esm/api/resources/copilots/client/Client.mjs +11 -150
- package/dist/esm/api/resources/documentCatalog/client/Client.d.mts +1 -2
- package/dist/esm/api/resources/documentCatalog/client/Client.mjs +5 -60
- package/dist/esm/api/resources/documentCollections/client/Client.d.mts +1 -2
- package/dist/esm/api/resources/documentCollections/client/Client.mjs +8 -105
- package/dist/esm/api/resources/search/client/Client.d.mts +1 -2
- package/dist/esm/api/resources/search/client/Client.mjs +2 -15
- package/dist/esm/api/resources/users/client/Client.d.mts +1 -2
- package/dist/esm/api/resources/users/client/Client.mjs +2 -15
- package/dist/esm/auth/BearerAuthProvider.d.mts +4 -2
- package/dist/esm/core/auth/NoOpAuthProvider.d.mts +5 -0
- package/dist/esm/core/auth/NoOpAuthProvider.mjs +5 -0
- package/dist/esm/core/auth/index.d.mts +1 -0
- package/dist/esm/core/auth/index.mjs +1 -0
- package/dist/esm/core/fetcher/BinaryResponse.d.mts +6 -7
- package/dist/esm/core/fetcher/Fetcher.d.mts +5 -1
- package/dist/esm/core/fetcher/Fetcher.mjs +2 -1
- package/dist/esm/core/fetcher/getResponseBody.mjs +18 -4
- package/dist/esm/core/fetcher/signals.d.mts +1 -1
- package/dist/esm/core/runtime/runtime.mjs +11 -10
- package/dist/esm/errors/CredalError.mjs +5 -1
- package/dist/esm/errors/CredalTimeoutError.mjs +5 -1
- package/dist/esm/errors/handleNonStatusCodeError.d.mts +2 -0
- package/dist/esm/errors/handleNonStatusCodeError.mjs +29 -0
- package/dist/esm/version.d.mts +1 -1
- package/dist/esm/version.mjs +1 -1
- package/package.json +5 -2
- package/dist/cjs/core/fetcher/ResponseWithBody.d.ts +0 -4
- package/dist/cjs/core/fetcher/ResponseWithBody.js +0 -6
- package/dist/esm/core/fetcher/ResponseWithBody.d.mts +0 -4
- package/dist/esm/core/fetcher/ResponseWithBody.mjs +0 -3
|
@@ -1,20 +1,19 @@
|
|
|
1
|
-
import type { ResponseWithBody } from "./ResponseWithBody.mjs";
|
|
2
1
|
export type BinaryResponse = {
|
|
3
2
|
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/bodyUsed) */
|
|
4
|
-
bodyUsed:
|
|
3
|
+
bodyUsed: Response["bodyUsed"];
|
|
5
4
|
/**
|
|
6
5
|
* Returns a ReadableStream of the response body.
|
|
7
6
|
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/body)
|
|
8
7
|
*/
|
|
9
|
-
stream: () =>
|
|
8
|
+
stream: () => Response["body"];
|
|
10
9
|
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/arrayBuffer) */
|
|
11
|
-
arrayBuffer: () =>
|
|
10
|
+
arrayBuffer: () => ReturnType<Response["arrayBuffer"]>;
|
|
12
11
|
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/blob) */
|
|
13
|
-
blob: () =>
|
|
12
|
+
blob: () => ReturnType<Response["blob"]>;
|
|
14
13
|
/**
|
|
15
14
|
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/bytes)
|
|
16
15
|
* Some versions of the Fetch API may not support this method.
|
|
17
16
|
*/
|
|
18
|
-
bytes?():
|
|
17
|
+
bytes?(): ReturnType<Response["bytes"]>;
|
|
19
18
|
};
|
|
20
|
-
export declare function getBinaryResponse(response:
|
|
19
|
+
export declare function getBinaryResponse(response: Response): BinaryResponse;
|
|
@@ -22,7 +22,7 @@ export declare namespace Fetcher {
|
|
|
22
22
|
fetchFn?: typeof fetch;
|
|
23
23
|
logging?: LogConfig | Logger;
|
|
24
24
|
}
|
|
25
|
-
type Error = FailedStatusCodeError | NonJsonError | TimeoutError | UnknownError;
|
|
25
|
+
type Error = FailedStatusCodeError | NonJsonError | BodyIsNullError | TimeoutError | UnknownError;
|
|
26
26
|
interface FailedStatusCodeError {
|
|
27
27
|
reason: "status-code";
|
|
28
28
|
statusCode: number;
|
|
@@ -33,6 +33,10 @@ export declare namespace Fetcher {
|
|
|
33
33
|
statusCode: number;
|
|
34
34
|
rawBody: string;
|
|
35
35
|
}
|
|
36
|
+
interface BodyIsNullError {
|
|
37
|
+
reason: "body-is-null";
|
|
38
|
+
statusCode: number;
|
|
39
|
+
}
|
|
36
40
|
interface TimeoutError {
|
|
37
41
|
reason: "timeout";
|
|
38
42
|
}
|
|
@@ -208,9 +208,10 @@ export function fetcherImpl(args) {
|
|
|
208
208
|
};
|
|
209
209
|
logger.debug("HTTP request succeeded", metadata);
|
|
210
210
|
}
|
|
211
|
+
const body = yield getResponseBody(response, args.responseType);
|
|
211
212
|
return {
|
|
212
213
|
ok: true,
|
|
213
|
-
body:
|
|
214
|
+
body: body,
|
|
214
215
|
headers: response.headers,
|
|
215
216
|
rawResponse: toRawResponse(response),
|
|
216
217
|
};
|
|
@@ -9,12 +9,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import { fromJson } from "../json.mjs";
|
|
11
11
|
import { getBinaryResponse } from "./BinaryResponse.mjs";
|
|
12
|
-
import { isResponseWithBody } from "./ResponseWithBody.mjs";
|
|
13
12
|
export function getResponseBody(response, responseType) {
|
|
14
13
|
return __awaiter(this, void 0, void 0, function* () {
|
|
15
|
-
if (!isResponseWithBody(response)) {
|
|
16
|
-
return undefined;
|
|
17
|
-
}
|
|
18
14
|
switch (responseType) {
|
|
19
15
|
case "binary-response":
|
|
20
16
|
return getBinaryResponse(response);
|
|
@@ -23,8 +19,26 @@ export function getResponseBody(response, responseType) {
|
|
|
23
19
|
case "arrayBuffer":
|
|
24
20
|
return yield response.arrayBuffer();
|
|
25
21
|
case "sse":
|
|
22
|
+
if (response.body == null) {
|
|
23
|
+
return {
|
|
24
|
+
ok: false,
|
|
25
|
+
error: {
|
|
26
|
+
reason: "body-is-null",
|
|
27
|
+
statusCode: response.status,
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
}
|
|
26
31
|
return response.body;
|
|
27
32
|
case "streaming":
|
|
33
|
+
if (response.body == null) {
|
|
34
|
+
return {
|
|
35
|
+
ok: false,
|
|
36
|
+
error: {
|
|
37
|
+
reason: "body-is-null",
|
|
38
|
+
statusCode: response.status,
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
}
|
|
28
42
|
return response.body;
|
|
29
43
|
case "text":
|
|
30
44
|
return yield response.text();
|
|
@@ -68,6 +68,17 @@ function evaluateRuntime() {
|
|
|
68
68
|
version: Bun.version,
|
|
69
69
|
};
|
|
70
70
|
}
|
|
71
|
+
/**
|
|
72
|
+
* A constant that indicates whether the environment the code is running is in React-Native.
|
|
73
|
+
* This check should come before Node.js detection since React Native may have a process polyfill.
|
|
74
|
+
* https://github.com/facebook/react-native/blob/main/packages/react-native/Libraries/Core/setUpNavigator.js
|
|
75
|
+
*/
|
|
76
|
+
const isReactNative = typeof navigator !== "undefined" && (navigator === null || navigator === void 0 ? void 0 : navigator.product) === "ReactNative";
|
|
77
|
+
if (isReactNative) {
|
|
78
|
+
return {
|
|
79
|
+
type: "react-native",
|
|
80
|
+
};
|
|
81
|
+
}
|
|
71
82
|
/**
|
|
72
83
|
* A constant that indicates whether the environment the code is running is Node.JS.
|
|
73
84
|
*/
|
|
@@ -83,16 +94,6 @@ function evaluateRuntime() {
|
|
|
83
94
|
parsedVersion: Number(process.versions.node.split(".")[0]),
|
|
84
95
|
};
|
|
85
96
|
}
|
|
86
|
-
/**
|
|
87
|
-
* A constant that indicates whether the environment the code is running is in React-Native.
|
|
88
|
-
* https://github.com/facebook/react-native/blob/main/packages/react-native/Libraries/Core/setUpNavigator.js
|
|
89
|
-
*/
|
|
90
|
-
const isReactNative = typeof navigator !== "undefined" && (navigator === null || navigator === void 0 ? void 0 : navigator.product) === "ReactNative";
|
|
91
|
-
if (isReactNative) {
|
|
92
|
-
return {
|
|
93
|
-
type: "react-native",
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
97
|
return {
|
|
97
98
|
type: "unknown",
|
|
98
99
|
};
|
|
@@ -3,7 +3,11 @@ import { toJson } from "../core/json.mjs";
|
|
|
3
3
|
export class CredalError extends Error {
|
|
4
4
|
constructor({ message, statusCode, body, rawResponse, }) {
|
|
5
5
|
super(buildMessage({ message, statusCode, body }));
|
|
6
|
-
Object.setPrototypeOf(this,
|
|
6
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
7
|
+
if (Error.captureStackTrace) {
|
|
8
|
+
Error.captureStackTrace(this, this.constructor);
|
|
9
|
+
}
|
|
10
|
+
this.name = this.constructor.name;
|
|
7
11
|
this.statusCode = statusCode;
|
|
8
12
|
this.body = body;
|
|
9
13
|
this.rawResponse = rawResponse;
|
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
export class CredalTimeoutError extends Error {
|
|
3
3
|
constructor(message) {
|
|
4
4
|
super(message);
|
|
5
|
-
Object.setPrototypeOf(this,
|
|
5
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
6
|
+
if (Error.captureStackTrace) {
|
|
7
|
+
Error.captureStackTrace(this, this.constructor);
|
|
8
|
+
}
|
|
9
|
+
this.name = this.constructor.name;
|
|
6
10
|
}
|
|
7
11
|
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// This file was auto-generated by Fern from our API Definition.
|
|
2
|
+
import * as errors from "./index.mjs";
|
|
3
|
+
export function handleNonStatusCodeError(error, rawResponse, method, path) {
|
|
4
|
+
switch (error.reason) {
|
|
5
|
+
case "non-json":
|
|
6
|
+
throw new errors.CredalError({
|
|
7
|
+
statusCode: error.statusCode,
|
|
8
|
+
body: error.rawBody,
|
|
9
|
+
rawResponse: rawResponse,
|
|
10
|
+
});
|
|
11
|
+
case "body-is-null":
|
|
12
|
+
throw new errors.CredalError({
|
|
13
|
+
statusCode: error.statusCode,
|
|
14
|
+
rawResponse: rawResponse,
|
|
15
|
+
});
|
|
16
|
+
case "timeout":
|
|
17
|
+
throw new errors.CredalTimeoutError(`Timeout exceeded when calling ${method} ${path}.`);
|
|
18
|
+
case "unknown":
|
|
19
|
+
throw new errors.CredalError({
|
|
20
|
+
message: error.errorMessage,
|
|
21
|
+
rawResponse: rawResponse,
|
|
22
|
+
});
|
|
23
|
+
default:
|
|
24
|
+
throw new errors.CredalError({
|
|
25
|
+
message: "Unknown error",
|
|
26
|
+
rawResponse: rawResponse,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}
|
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.16";
|
package/dist/esm/version.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const SDK_VERSION = "0.1.
|
|
1
|
+
export const SDK_VERSION = "0.1.16";
|
package/package.json
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@credal/sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.16",
|
|
4
4
|
"private": false,
|
|
5
|
-
"repository":
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/Credal-ai/credal-typescript-sdk.git"
|
|
8
|
+
},
|
|
6
9
|
"type": "commonjs",
|
|
7
10
|
"main": "./dist/cjs/index.js",
|
|
8
11
|
"module": "./dist/esm/index.mjs",
|