@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.
Files changed (65) hide show
  1. package/dist/cjs/BaseClient.d.ts +7 -7
  2. package/dist/cjs/BaseClient.js +7 -3
  3. package/dist/cjs/Client.d.ts +1 -2
  4. package/dist/cjs/api/resources/copilots/client/Client.d.ts +1 -2
  5. package/dist/cjs/api/resources/copilots/client/Client.js +11 -150
  6. package/dist/cjs/api/resources/documentCatalog/client/Client.d.ts +1 -2
  7. package/dist/cjs/api/resources/documentCatalog/client/Client.js +5 -60
  8. package/dist/cjs/api/resources/documentCollections/client/Client.d.ts +1 -2
  9. package/dist/cjs/api/resources/documentCollections/client/Client.js +8 -105
  10. package/dist/cjs/api/resources/search/client/Client.d.ts +1 -2
  11. package/dist/cjs/api/resources/search/client/Client.js +2 -15
  12. package/dist/cjs/api/resources/users/client/Client.d.ts +1 -2
  13. package/dist/cjs/api/resources/users/client/Client.js +2 -15
  14. package/dist/cjs/auth/BearerAuthProvider.d.ts +4 -2
  15. package/dist/cjs/core/auth/NoOpAuthProvider.d.ts +5 -0
  16. package/dist/cjs/core/auth/NoOpAuthProvider.js +9 -0
  17. package/dist/cjs/core/auth/index.d.ts +1 -0
  18. package/dist/cjs/core/auth/index.js +3 -1
  19. package/dist/cjs/core/fetcher/BinaryResponse.d.ts +6 -7
  20. package/dist/cjs/core/fetcher/Fetcher.d.ts +5 -1
  21. package/dist/cjs/core/fetcher/Fetcher.js +2 -1
  22. package/dist/cjs/core/fetcher/getResponseBody.js +18 -4
  23. package/dist/cjs/core/fetcher/signals.d.ts +1 -1
  24. package/dist/cjs/core/runtime/runtime.js +11 -10
  25. package/dist/cjs/errors/CredalError.js +5 -1
  26. package/dist/cjs/errors/CredalTimeoutError.js +5 -1
  27. package/dist/cjs/errors/handleNonStatusCodeError.d.ts +2 -0
  28. package/dist/cjs/errors/handleNonStatusCodeError.js +65 -0
  29. package/dist/cjs/version.d.ts +1 -1
  30. package/dist/cjs/version.js +1 -1
  31. package/dist/esm/BaseClient.d.mts +7 -7
  32. package/dist/esm/BaseClient.mjs +7 -3
  33. package/dist/esm/Client.d.mts +1 -2
  34. package/dist/esm/api/resources/copilots/client/Client.d.mts +1 -2
  35. package/dist/esm/api/resources/copilots/client/Client.mjs +11 -150
  36. package/dist/esm/api/resources/documentCatalog/client/Client.d.mts +1 -2
  37. package/dist/esm/api/resources/documentCatalog/client/Client.mjs +5 -60
  38. package/dist/esm/api/resources/documentCollections/client/Client.d.mts +1 -2
  39. package/dist/esm/api/resources/documentCollections/client/Client.mjs +8 -105
  40. package/dist/esm/api/resources/search/client/Client.d.mts +1 -2
  41. package/dist/esm/api/resources/search/client/Client.mjs +2 -15
  42. package/dist/esm/api/resources/users/client/Client.d.mts +1 -2
  43. package/dist/esm/api/resources/users/client/Client.mjs +2 -15
  44. package/dist/esm/auth/BearerAuthProvider.d.mts +4 -2
  45. package/dist/esm/core/auth/NoOpAuthProvider.d.mts +5 -0
  46. package/dist/esm/core/auth/NoOpAuthProvider.mjs +5 -0
  47. package/dist/esm/core/auth/index.d.mts +1 -0
  48. package/dist/esm/core/auth/index.mjs +1 -0
  49. package/dist/esm/core/fetcher/BinaryResponse.d.mts +6 -7
  50. package/dist/esm/core/fetcher/Fetcher.d.mts +5 -1
  51. package/dist/esm/core/fetcher/Fetcher.mjs +2 -1
  52. package/dist/esm/core/fetcher/getResponseBody.mjs +18 -4
  53. package/dist/esm/core/fetcher/signals.d.mts +1 -1
  54. package/dist/esm/core/runtime/runtime.mjs +11 -10
  55. package/dist/esm/errors/CredalError.mjs +5 -1
  56. package/dist/esm/errors/CredalTimeoutError.mjs +5 -1
  57. package/dist/esm/errors/handleNonStatusCodeError.d.mts +2 -0
  58. package/dist/esm/errors/handleNonStatusCodeError.mjs +29 -0
  59. package/dist/esm/version.d.mts +1 -1
  60. package/dist/esm/version.mjs +1 -1
  61. package/package.json +5 -2
  62. package/dist/cjs/core/fetcher/ResponseWithBody.d.ts +0 -4
  63. package/dist/cjs/core/fetcher/ResponseWithBody.js +0 -6
  64. package/dist/esm/core/fetcher/ResponseWithBody.d.mts +0 -4
  65. 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: boolean;
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: () => ReadableStream<Uint8Array>;
8
+ stream: () => Response["body"];
10
9
  /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/arrayBuffer) */
11
- arrayBuffer: () => Promise<ArrayBuffer>;
10
+ arrayBuffer: () => ReturnType<Response["arrayBuffer"]>;
12
11
  /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/blob) */
13
- blob: () => Promise<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?(): Promise<Uint8Array>;
17
+ bytes?(): ReturnType<Response["bytes"]>;
19
18
  };
20
- export declare function getBinaryResponse(response: ResponseWithBody): BinaryResponse;
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: (yield getResponseBody(response, args.responseType)),
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();
@@ -1,5 +1,5 @@
1
1
  export declare function getTimeoutSignal(timeoutMs: number): {
2
2
  signal: AbortSignal;
3
- abortId: NodeJS.Timeout;
3
+ abortId: ReturnType<typeof setTimeout>;
4
4
  };
5
5
  export declare function anySignal(...args: AbortSignal[] | [AbortSignal[]]): AbortSignal;
@@ -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, CredalError.prototype);
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, CredalTimeoutError.prototype);
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,2 @@
1
+ import type * as core from "../core/index.mjs";
2
+ export declare function handleNonStatusCodeError(error: core.Fetcher.Error, rawResponse: core.RawResponse, method: string, path: string): never;
@@ -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
+ }
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "0.1.14";
1
+ export declare const SDK_VERSION = "0.1.16";
@@ -1 +1 @@
1
- export const SDK_VERSION = "0.1.14";
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.14",
3
+ "version": "0.1.16",
4
4
  "private": false,
5
- "repository": "github:credal-ai/credal-typescript-sdk",
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",
@@ -1,4 +0,0 @@
1
- export type ResponseWithBody = Response & {
2
- body: ReadableStream<Uint8Array>;
3
- };
4
- export declare function isResponseWithBody(response: Response): response is ResponseWithBody;
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isResponseWithBody = isResponseWithBody;
4
- function isResponseWithBody(response) {
5
- return response.body != null;
6
- }
@@ -1,4 +0,0 @@
1
- export type ResponseWithBody = Response & {
2
- body: ReadableStream<Uint8Array>;
3
- };
4
- export declare function isResponseWithBody(response: Response): response is ResponseWithBody;
@@ -1,3 +0,0 @@
1
- export function isResponseWithBody(response) {
2
- return response.body != null;
3
- }