@decartai/sdk 0.0.21 → 0.0.22

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/index.d.ts CHANGED
@@ -10,12 +10,29 @@ import { z } from "zod";
10
10
 
11
11
  //#region src/index.d.ts
12
12
  declare const decartClientOptionsSchema: z.ZodObject<{
13
- apiKey: z.ZodString;
13
+ apiKey: z.ZodOptional<z.ZodString>;
14
14
  baseUrl: z.ZodOptional<z.ZodURL>;
15
15
  integration: z.ZodOptional<z.ZodString>;
16
16
  }, z.core.$strip>;
17
17
  type DecartClientOptions = z.infer<typeof decartClientOptionsSchema>;
18
- declare const createDecartClient: (options: DecartClientOptions) => {
18
+ /**
19
+ * Create a Decart API client.
20
+ *
21
+ * @param options - Configuration options
22
+ * @param options.apiKey - API key for authentication. Defaults to the DECART_API_KEY environment variable.
23
+ * @param options.baseUrl - Override the default API base URL.
24
+ * @param options.integration - Optional integration identifier.
25
+ *
26
+ * @example
27
+ * ```ts
28
+ * // Option 1: Explicit API key
29
+ * const client = createDecartClient({ apiKey: "your-api-key" });
30
+ *
31
+ * // Option 2: Using DECART_API_KEY environment variable
32
+ * const client = createDecartClient();
33
+ * ```
34
+ */
35
+ declare const createDecartClient: (options?: DecartClientOptions) => {
19
36
  realtime: {
20
37
  connect: (stream: MediaStream, options: RealTimeClientConnectOptions) => Promise<RealTimeClient>;
21
38
  };
package/dist/index.js CHANGED
@@ -3,23 +3,44 @@ import { createProcessClient } from "./process/client.js";
3
3
  import { createQueueClient } from "./queue/client.js";
4
4
  import { models } from "./shared/model.js";
5
5
  import { createRealTimeClient } from "./realtime/client.js";
6
+ import { readEnv } from "./utils/env.js";
6
7
  import { z } from "zod";
7
8
 
8
9
  //#region src/index.ts
9
10
  const decartClientOptionsSchema = z.object({
10
- apiKey: z.string().min(1),
11
+ apiKey: z.string().min(1).optional(),
11
12
  baseUrl: z.url().optional(),
12
13
  integration: z.string().optional()
13
14
  });
14
- const createDecartClient = (options) => {
15
- const parsedOptions = decartClientOptionsSchema.safeParse(options);
15
+ /**
16
+ * Create a Decart API client.
17
+ *
18
+ * @param options - Configuration options
19
+ * @param options.apiKey - API key for authentication. Defaults to the DECART_API_KEY environment variable.
20
+ * @param options.baseUrl - Override the default API base URL.
21
+ * @param options.integration - Optional integration identifier.
22
+ *
23
+ * @example
24
+ * ```ts
25
+ * // Option 1: Explicit API key
26
+ * const client = createDecartClient({ apiKey: "your-api-key" });
27
+ *
28
+ * // Option 2: Using DECART_API_KEY environment variable
29
+ * const client = createDecartClient();
30
+ * ```
31
+ */
32
+ const createDecartClient = (options = {}) => {
33
+ const apiKey = options.apiKey ?? readEnv("DECART_API_KEY");
34
+ if (!apiKey) throw createInvalidApiKeyError();
35
+ const parsedOptions = decartClientOptionsSchema.safeParse({
36
+ ...options,
37
+ apiKey
38
+ });
16
39
  if (!parsedOptions.success) {
17
- const issue = parsedOptions.error.issues[0];
18
- if (issue.path.includes("apiKey")) throw createInvalidApiKeyError();
19
- if (issue.path.includes("baseUrl")) throw createInvalidBaseUrlError(options.baseUrl);
40
+ if (parsedOptions.error.issues[0].path.includes("baseUrl")) throw createInvalidBaseUrlError(options.baseUrl);
20
41
  throw parsedOptions.error;
21
42
  }
22
- const { baseUrl = "https://api.decart.ai", apiKey, integration } = parsedOptions.data;
43
+ const { baseUrl = "https://api.decart.ai", integration } = parsedOptions.data;
23
44
  const realtime = createRealTimeClient({
24
45
  baseUrl: "wss://api3.decart.ai",
25
46
  apiKey,
@@ -0,0 +1,9 @@
1
+ //#region src/utils/env.ts
2
+ const readEnv = (env) => {
3
+ const globalThisAny = globalThis;
4
+ if (typeof globalThisAny.process !== "undefined") return globalThisAny.process.env?.[env]?.trim();
5
+ if (typeof globalThisAny.Deno !== "undefined") return globalThisAny.Deno.env?.get?.(env)?.trim();
6
+ };
7
+
8
+ //#endregion
9
+ export { readEnv };
@@ -21,7 +21,7 @@ function createSDKError(code, message, data, cause) {
21
21
  };
22
22
  }
23
23
  function createInvalidApiKeyError() {
24
- return createSDKError(ERROR_CODES.INVALID_API_KEY, "API key is required and must be a non-empty string");
24
+ return createSDKError(ERROR_CODES.INVALID_API_KEY, "Missing API key. Pass `apiKey` to createDecartClient() or set the DECART_API_KEY environment variable.");
25
25
  }
26
26
  function createInvalidBaseUrlError(url) {
27
27
  return createSDKError(ERROR_CODES.INVALID_BASE_URL, `Invalid base URL${url ? `: ${url}` : ""}`);
package/dist/version.js CHANGED
@@ -4,7 +4,7 @@
4
4
  * Injected at build time from package.json.
5
5
  * Falls back to '0.0.0-dev' in development.
6
6
  */
7
- const VERSION = "0.0.21";
7
+ const VERSION = "0.0.22";
8
8
 
9
9
  //#endregion
10
10
  export { VERSION };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@decartai/sdk",
3
- "version": "0.0.21",
3
+ "version": "0.0.22",
4
4
  "description": "Decart's JavaScript SDK",
5
5
  "type": "module",
6
6
  "license": "MIT",