@decartai/sdk 0.0.23 → 0.0.25

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
@@ -6,6 +6,7 @@ import { QueueClient } from "./queue/client.js";
6
6
  import { DecartSDKError, ERROR_CODES } from "./utils/errors.js";
7
7
  import { RealTimeClient, RealTimeClientConnectOptions, RealTimeClientInitialState } from "./realtime/client.js";
8
8
  import { ModelState } from "./shared/types.js";
9
+ import { CreateTokenResponse, TokensClient } from "./tokens/client.js";
9
10
  import { z } from "zod";
10
11
 
11
12
  //#region src/index.d.ts
@@ -89,6 +90,23 @@ declare const createDecartClient: (options?: DecartClientOptions) => {
89
90
  * ```
90
91
  */
91
92
  queue: QueueClient;
93
+ /**
94
+ * Client for creating client tokens.
95
+ * Client tokens are short-lived API keys safe for client-side use.
96
+ *
97
+ * @example
98
+ * ```ts
99
+ * // Server-side: Create a client token
100
+ * const serverClient = createDecartClient({ apiKey: process.env.DECART_API_KEY });
101
+ * const token = await serverClient.tokens.create();
102
+ * // Returns: { apiKey: "ek_...", expiresAt: "2024-12-15T12:10:00Z" }
103
+ *
104
+ * // Client-side: Use the client token
105
+ * const client = createDecartClient({ apiKey: token.apiKey });
106
+ * const realtimeClient = await client.realtime.connect(stream, options);
107
+ * ```
108
+ */
109
+ tokens: TokensClient;
92
110
  };
93
111
  //#endregion
94
- export { DecartClientOptions, type DecartSDKError, ERROR_CODES, type FileInput, type ImageModelDefinition, type ImageModels, type JobStatus, type JobStatusResponse, type JobSubmitResponse, type Model, type ModelDefinition, type ModelState, type ProcessClient, type ProcessOptions, type QueueClient, type QueueJobResult, type QueueSubmitAndPollOptions, type QueueSubmitOptions, type RealTimeClient, type RealTimeClientConnectOptions, type RealTimeClientInitialState, type RealTimeModels, type VideoModelDefinition, type VideoModels, createDecartClient, models };
112
+ export { type CreateTokenResponse, DecartClientOptions, type DecartSDKError, ERROR_CODES, type FileInput, type ImageModelDefinition, type ImageModels, type JobStatus, type JobStatusResponse, type JobSubmitResponse, type Model, type ModelDefinition, type ModelState, type ProcessClient, type ProcessOptions, type QueueClient, type QueueJobResult, type QueueSubmitAndPollOptions, type QueueSubmitOptions, type RealTimeClient, type RealTimeClientConnectOptions, type RealTimeClientInitialState, type RealTimeModels, type TokensClient, type VideoModelDefinition, type VideoModels, createDecartClient, models };
package/dist/index.js CHANGED
@@ -3,6 +3,7 @@ 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 { createTokensClient } from "./tokens/client.js";
6
7
  import { readEnv } from "./utils/env.js";
7
8
  import { z } from "zod";
8
9
 
@@ -56,6 +57,11 @@ const createDecartClient = (options = {}) => {
56
57
  baseUrl,
57
58
  apiKey,
58
59
  integration
60
+ }),
61
+ tokens: createTokensClient({
62
+ baseUrl,
63
+ apiKey,
64
+ integration
59
65
  })
60
66
  };
61
67
  };
@@ -129,7 +129,7 @@ var WebRTCConnection = class {
129
129
  if (!this.localStream) throw new Error("No local stream found");
130
130
  if (this.pc) {
131
131
  this.pc.getSenders().forEach((sender) => {
132
- if (sender.track) this.pc.removeTrack(sender);
132
+ if (sender.track && this.pc) this.pc.removeTrack(sender);
133
133
  });
134
134
  this.pc.close();
135
135
  }
@@ -140,7 +140,9 @@ var WebRTCConnection = class {
140
140
  username: turnConfig.username
141
141
  });
142
142
  this.pc = new RTCPeerConnection({ iceServers });
143
- this.localStream.getTracks().forEach((track) => this.pc.addTrack(track, this.localStream));
143
+ this.localStream.getTracks().forEach((track) => {
144
+ if (this.pc && this.localStream) this.pc.addTrack(track, this.localStream);
145
+ });
144
146
  this.pc.ontrack = (e) => {
145
147
  if (e.streams?.[0]) this.callbacks.onRemoteStream?.(e.streams[0]);
146
148
  };
@@ -159,7 +161,9 @@ var WebRTCConnection = class {
159
161
  this.handleSignalingMessage({ type: "ready" });
160
162
  }
161
163
  cleanup() {
162
- this.pc?.getSenders().forEach((s) => s.track?.stop());
164
+ this.pc?.getSenders().forEach((s) => {
165
+ s.track?.stop();
166
+ });
163
167
  this.pc?.close();
164
168
  this.pc = null;
165
169
  this.ws?.close();
@@ -108,7 +108,7 @@ const modelInputSchemas = {
108
108
  frame: z.number().min(0),
109
109
  x: z.number().min(0),
110
110
  y: z.number().min(0)
111
- })).min(2).max(121).describe("The trajectory of the desired movement of the object in the image"),
111
+ })).min(2).max(1e3).describe("The trajectory of the desired movement of the object in the image"),
112
112
  seed: z.number().optional().describe("The seed to use for the generation"),
113
113
  resolution: motionResolutionSchema
114
114
  })
@@ -0,0 +1,21 @@
1
+ //#region src/tokens/client.d.ts
2
+
3
+ type CreateTokenResponse = {
4
+ apiKey: string;
5
+ expiresAt: string;
6
+ };
7
+ type TokensClient = {
8
+ /**
9
+ * Create a client token.
10
+ * @returns A short-lived API key safe for client-side use.
11
+ * @example
12
+ * ```ts
13
+ * const client = createDecartClient({ apiKey: process.env.DECART_API_KEY });
14
+ * const token = await client.tokens.create();
15
+ * // Returns: { apiKey: "ek_...", expiresAt: "2024-12-15T12:10:00Z" }
16
+ * ```
17
+ */
18
+ create: () => Promise<CreateTokenResponse>;
19
+ };
20
+ //#endregion
21
+ export { CreateTokenResponse, TokensClient };
@@ -0,0 +1,22 @@
1
+ import { createSDKError } from "../utils/errors.js";
2
+ import { buildAuthHeaders } from "../shared/request.js";
3
+
4
+ //#region src/tokens/client.ts
5
+ const createTokensClient = (opts) => {
6
+ const { baseUrl, apiKey, integration } = opts;
7
+ const create = async () => {
8
+ const response = await fetch(`${baseUrl}/v1/client/tokens`, {
9
+ method: "POST",
10
+ headers: buildAuthHeaders(apiKey, integration)
11
+ });
12
+ if (!response.ok) {
13
+ const errorText = await response.text().catch(() => "Unknown error");
14
+ throw createSDKError("TOKEN_CREATE_ERROR", `Failed to create token: ${response.status} - ${errorText}`, { status: response.status });
15
+ }
16
+ return response.json();
17
+ };
18
+ return { create };
19
+ };
20
+
21
+ //#endregion
22
+ export { createTokensClient };
@@ -17,6 +17,7 @@ declare const ERROR_CODES: {
17
17
  readonly QUEUE_STATUS_ERROR: "QUEUE_STATUS_ERROR";
18
18
  readonly QUEUE_RESULT_ERROR: "QUEUE_RESULT_ERROR";
19
19
  readonly JOB_NOT_COMPLETED: "JOB_NOT_COMPLETED";
20
+ readonly TOKEN_CREATE_ERROR: "TOKEN_CREATE_ERROR";
20
21
  };
21
22
  //#endregion
22
23
  export { DecartSDKError, ERROR_CODES };
@@ -10,7 +10,8 @@ const ERROR_CODES = {
10
10
  QUEUE_SUBMIT_ERROR: "QUEUE_SUBMIT_ERROR",
11
11
  QUEUE_STATUS_ERROR: "QUEUE_STATUS_ERROR",
12
12
  QUEUE_RESULT_ERROR: "QUEUE_RESULT_ERROR",
13
- JOB_NOT_COMPLETED: "JOB_NOT_COMPLETED"
13
+ JOB_NOT_COMPLETED: "JOB_NOT_COMPLETED",
14
+ TOKEN_CREATE_ERROR: "TOKEN_CREATE_ERROR"
14
15
  };
15
16
  function createSDKError(code, message, data, cause) {
16
17
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@decartai/sdk",
3
- "version": "0.0.23",
3
+ "version": "0.0.25",
4
4
  "description": "Decart's JavaScript SDK",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -29,8 +29,9 @@
29
29
  "access": "public"
30
30
  },
31
31
  "devDependencies": {
32
+ "@biomejs/biome": "2.3.8",
33
+ "@types/bun": "^1.3.3",
32
34
  "@types/node": "^22.15.17",
33
- "biome": "^0.3.3",
34
35
  "bumpp": "^10.1.0",
35
36
  "msw": "^2.11.3",
36
37
  "pkg-pr-new": "^0.0.56",