@indreamai/client 0.2.1 → 0.3.0
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.cjs +222 -9
- package/dist/index.d.cts +330 -4
- package/dist/index.d.ts +330 -4
- package/dist/index.js +217 -9
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -35,9 +35,14 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
35
35
|
var index_exports = {};
|
|
36
36
|
__export(index_exports, {
|
|
37
37
|
APIError: () => APIError,
|
|
38
|
+
AssetsResource: () => AssetsResource,
|
|
38
39
|
AuthError: () => AuthError,
|
|
40
|
+
EditorResource: () => EditorResource,
|
|
41
|
+
ExportsResource: () => ExportsResource,
|
|
39
42
|
IndreamClient: () => IndreamClient,
|
|
43
|
+
ProjectsResource: () => ProjectsResource,
|
|
40
44
|
RateLimitError: () => RateLimitError,
|
|
45
|
+
UploadsResource: () => UploadsResource,
|
|
41
46
|
ValidationError: () => ValidationError,
|
|
42
47
|
createApiError: () => createApiError,
|
|
43
48
|
isExportTaskSnapshot: () => isExportTaskSnapshot,
|
|
@@ -115,6 +120,25 @@ var createApiError = (status, payload) => {
|
|
|
115
120
|
return new APIError(problem);
|
|
116
121
|
};
|
|
117
122
|
|
|
123
|
+
// src/resources/assets.ts
|
|
124
|
+
var AssetsResource = class {
|
|
125
|
+
constructor(client) {
|
|
126
|
+
this.client = client;
|
|
127
|
+
}
|
|
128
|
+
async get(assetId, options = {}) {
|
|
129
|
+
return await this.client.request(`/v1/assets/${assetId}`, {
|
|
130
|
+
method: "GET",
|
|
131
|
+
signal: options.signal
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
async delete(assetId, options = {}) {
|
|
135
|
+
return await this.client.request(`/v1/assets/${assetId}`, {
|
|
136
|
+
method: "DELETE",
|
|
137
|
+
signal: options.signal
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
|
|
118
142
|
// src/resources/exports.ts
|
|
119
143
|
var TERMINAL_STATUSES = /* @__PURE__ */ new Set(["COMPLETED", "FAILED", "CANCELED"]);
|
|
120
144
|
var sleep = async (ms) => {
|
|
@@ -220,6 +244,164 @@ var EditorResource = class {
|
|
|
220
244
|
}
|
|
221
245
|
};
|
|
222
246
|
|
|
247
|
+
// src/resources/projects.ts
|
|
248
|
+
var ProjectsResource = class {
|
|
249
|
+
constructor(client) {
|
|
250
|
+
this.client = client;
|
|
251
|
+
}
|
|
252
|
+
async create(payload, options = {}) {
|
|
253
|
+
var _a;
|
|
254
|
+
return await this.client.request("/v1/projects", {
|
|
255
|
+
method: "POST",
|
|
256
|
+
body: payload,
|
|
257
|
+
idempotencyKey: ((_a = options.idempotencyKey) == null ? void 0 : _a.trim()) || void 0,
|
|
258
|
+
signal: options.signal
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
async list(params) {
|
|
262
|
+
var _a;
|
|
263
|
+
const search = new URLSearchParams();
|
|
264
|
+
if (params == null ? void 0 : params.pageSize) {
|
|
265
|
+
search.set("pageSize", String(params.pageSize));
|
|
266
|
+
}
|
|
267
|
+
if (params == null ? void 0 : params.pageCursor) {
|
|
268
|
+
search.set("pageCursor", params.pageCursor);
|
|
269
|
+
}
|
|
270
|
+
const query = search.toString();
|
|
271
|
+
const envelope = await this.client.requestEnvelope(
|
|
272
|
+
`/v1/projects${query ? `?${query}` : ""}`,
|
|
273
|
+
{
|
|
274
|
+
method: "GET",
|
|
275
|
+
signal: params == null ? void 0 : params.signal
|
|
276
|
+
}
|
|
277
|
+
);
|
|
278
|
+
return {
|
|
279
|
+
items: envelope.data || [],
|
|
280
|
+
nextPageCursor: typeof ((_a = envelope.meta) == null ? void 0 : _a.nextPageCursor) === "string" ? envelope.meta.nextPageCursor : null
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
async get(projectId, options = {}) {
|
|
284
|
+
return await this.client.request(`/v1/projects/${projectId}`, {
|
|
285
|
+
method: "GET",
|
|
286
|
+
signal: options.signal
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
async update(projectId, payload, options = {}) {
|
|
290
|
+
return await this.client.request(`/v1/projects/${projectId}`, {
|
|
291
|
+
method: "PATCH",
|
|
292
|
+
body: payload,
|
|
293
|
+
signal: options.signal
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
async sync(projectId, payload, options = {}) {
|
|
297
|
+
return await this.client.request(`/v1/projects/${projectId}/sync`, {
|
|
298
|
+
method: "POST",
|
|
299
|
+
body: payload,
|
|
300
|
+
signal: options.signal
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
async delete(projectId, options = {}) {
|
|
304
|
+
return await this.client.request(`/v1/projects/${projectId}`, {
|
|
305
|
+
method: "DELETE",
|
|
306
|
+
signal: options.signal
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
async listAssets(params) {
|
|
310
|
+
var _a;
|
|
311
|
+
const search = new URLSearchParams();
|
|
312
|
+
if (params.pageSize) {
|
|
313
|
+
search.set("pageSize", String(params.pageSize));
|
|
314
|
+
}
|
|
315
|
+
if (params.pageCursor) {
|
|
316
|
+
search.set("pageCursor", params.pageCursor);
|
|
317
|
+
}
|
|
318
|
+
const query = search.toString();
|
|
319
|
+
const envelope = await this.client.requestEnvelope(
|
|
320
|
+
`/v1/projects/${params.projectId}/assets${query ? `?${query}` : ""}`,
|
|
321
|
+
{
|
|
322
|
+
method: "GET",
|
|
323
|
+
signal: params.signal
|
|
324
|
+
}
|
|
325
|
+
);
|
|
326
|
+
return {
|
|
327
|
+
items: envelope.data || [],
|
|
328
|
+
nextPageCursor: typeof ((_a = envelope.meta) == null ? void 0 : _a.nextPageCursor) === "string" ? envelope.meta.nextPageCursor : null
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
async addAsset(projectId, assetId, options = {}) {
|
|
332
|
+
return await this.client.request(
|
|
333
|
+
`/v1/projects/${projectId}/assets`,
|
|
334
|
+
{
|
|
335
|
+
method: "POST",
|
|
336
|
+
body: { assetId },
|
|
337
|
+
signal: options.signal
|
|
338
|
+
}
|
|
339
|
+
);
|
|
340
|
+
}
|
|
341
|
+
async removeAsset(projectId, assetId, options = {}) {
|
|
342
|
+
return await this.client.request(
|
|
343
|
+
`/v1/projects/${projectId}/assets/${assetId}`,
|
|
344
|
+
{
|
|
345
|
+
method: "DELETE",
|
|
346
|
+
signal: options.signal
|
|
347
|
+
}
|
|
348
|
+
);
|
|
349
|
+
}
|
|
350
|
+
async createExport(projectId, payload, options = {}) {
|
|
351
|
+
var _a;
|
|
352
|
+
return await this.client.request(`/v1/projects/${projectId}/exports`, {
|
|
353
|
+
method: "POST",
|
|
354
|
+
body: payload,
|
|
355
|
+
idempotencyKey: ((_a = options.idempotencyKey) == null ? void 0 : _a.trim()) || void 0,
|
|
356
|
+
signal: options.signal
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
};
|
|
360
|
+
|
|
361
|
+
// src/resources/uploads.ts
|
|
362
|
+
var resolveFilename = (body, options) => {
|
|
363
|
+
var _a;
|
|
364
|
+
if ((_a = options.filename) == null ? void 0 : _a.trim()) {
|
|
365
|
+
return options.filename.trim();
|
|
366
|
+
}
|
|
367
|
+
if (typeof File !== "undefined" && body instanceof File && typeof body.name === "string" && body.name.trim()) {
|
|
368
|
+
return body.name.trim();
|
|
369
|
+
}
|
|
370
|
+
throw new Error("filename is required for uploads.upload(...)");
|
|
371
|
+
};
|
|
372
|
+
var resolveContentType = (body, options) => {
|
|
373
|
+
var _a;
|
|
374
|
+
if ((_a = options.contentType) == null ? void 0 : _a.trim()) {
|
|
375
|
+
return options.contentType.trim();
|
|
376
|
+
}
|
|
377
|
+
if (typeof Blob !== "undefined" && body instanceof Blob && body.type.trim()) {
|
|
378
|
+
return body.type.trim();
|
|
379
|
+
}
|
|
380
|
+
throw new Error("contentType is required for uploads.upload(...)");
|
|
381
|
+
};
|
|
382
|
+
var UploadsResource = class {
|
|
383
|
+
constructor(client) {
|
|
384
|
+
this.client = client;
|
|
385
|
+
}
|
|
386
|
+
async upload(body, options = {}) {
|
|
387
|
+
var _a;
|
|
388
|
+
const headers = {
|
|
389
|
+
"x-file-name": resolveFilename(body, options),
|
|
390
|
+
"Content-Type": resolveContentType(body, options)
|
|
391
|
+
};
|
|
392
|
+
if ((_a = options.projectId) == null ? void 0 : _a.trim()) {
|
|
393
|
+
headers["x-project-id"] = options.projectId.trim();
|
|
394
|
+
}
|
|
395
|
+
return await this.client.request("/v1/uploads", {
|
|
396
|
+
method: "POST",
|
|
397
|
+
body,
|
|
398
|
+
headers,
|
|
399
|
+
signal: options.signal,
|
|
400
|
+
skipRetry: true
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
};
|
|
404
|
+
|
|
223
405
|
// src/retry.ts
|
|
224
406
|
var sleep2 = async (ms) => {
|
|
225
407
|
await new Promise((resolve) => setTimeout(resolve, ms));
|
|
@@ -252,6 +434,16 @@ var withRetry = async (execute, options) => {
|
|
|
252
434
|
};
|
|
253
435
|
|
|
254
436
|
// src/client.ts
|
|
437
|
+
var isBodyInit = (value) => {
|
|
438
|
+
if (typeof value === "string") return true;
|
|
439
|
+
if (value instanceof URLSearchParams) return true;
|
|
440
|
+
if (value instanceof ArrayBuffer) return true;
|
|
441
|
+
if (ArrayBuffer.isView(value)) return true;
|
|
442
|
+
if (typeof Blob !== "undefined" && value instanceof Blob) return true;
|
|
443
|
+
if (typeof FormData !== "undefined" && value instanceof FormData) return true;
|
|
444
|
+
if (typeof ReadableStream !== "undefined" && value instanceof ReadableStream) return true;
|
|
445
|
+
return false;
|
|
446
|
+
};
|
|
255
447
|
var IndreamClient = class {
|
|
256
448
|
constructor(options) {
|
|
257
449
|
if (!options.apiKey) {
|
|
@@ -265,6 +457,9 @@ var IndreamClient = class {
|
|
|
265
457
|
this.fetchImpl = options.fetch || fetch;
|
|
266
458
|
this.exports = new ExportsResource(this);
|
|
267
459
|
this.editor = new EditorResource(this);
|
|
460
|
+
this.projects = new ProjectsResource(this);
|
|
461
|
+
this.uploads = new UploadsResource(this);
|
|
462
|
+
this.assets = new AssetsResource(this);
|
|
268
463
|
}
|
|
269
464
|
async request(path, init) {
|
|
270
465
|
const envelope = await this.requestEnvelope(path, init);
|
|
@@ -272,7 +467,15 @@ var IndreamClient = class {
|
|
|
272
467
|
}
|
|
273
468
|
async requestEnvelope(path, init) {
|
|
274
469
|
const url = `${this.baseURL}${path.startsWith("/") ? path : `/${path}`}`;
|
|
275
|
-
const
|
|
470
|
+
const isJsonPayload = init.body !== void 0 && !isBodyInit(init.body);
|
|
471
|
+
let payload;
|
|
472
|
+
if (init.body !== void 0) {
|
|
473
|
+
if (isJsonPayload) {
|
|
474
|
+
payload = JSON.stringify(init.body);
|
|
475
|
+
} else if (isBodyInit(init.body)) {
|
|
476
|
+
payload = init.body;
|
|
477
|
+
}
|
|
478
|
+
}
|
|
276
479
|
const execute = async () => {
|
|
277
480
|
const controller = new AbortController();
|
|
278
481
|
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
@@ -291,19 +494,23 @@ var IndreamClient = class {
|
|
|
291
494
|
"x-api-key": this.apiKey,
|
|
292
495
|
Accept: "application/json"
|
|
293
496
|
}, init.headers);
|
|
294
|
-
if (payload !== void 0) {
|
|
497
|
+
if (isJsonPayload && payload !== void 0) {
|
|
295
498
|
headers["Content-Type"] = "application/json";
|
|
296
499
|
}
|
|
297
500
|
if (init.idempotencyKey) {
|
|
298
501
|
headers["Idempotency-Key"] = init.idempotencyKey;
|
|
299
502
|
}
|
|
503
|
+
const requestInit = {
|
|
504
|
+
method: init.method,
|
|
505
|
+
body: payload,
|
|
506
|
+
headers,
|
|
507
|
+
signal: controller.signal
|
|
508
|
+
};
|
|
509
|
+
if (typeof ReadableStream !== "undefined" && payload instanceof ReadableStream) {
|
|
510
|
+
requestInit.duplex = "half";
|
|
511
|
+
}
|
|
300
512
|
try {
|
|
301
|
-
const response = await this.fetchImpl(url,
|
|
302
|
-
method: init.method,
|
|
303
|
-
body: payload,
|
|
304
|
-
headers,
|
|
305
|
-
signal: controller.signal
|
|
306
|
-
});
|
|
513
|
+
const response = await this.fetchImpl(url, requestInit);
|
|
307
514
|
const text = await response.text();
|
|
308
515
|
const parsed = text ? JSON.parse(text) : null;
|
|
309
516
|
if (!response.ok) {
|
|
@@ -378,6 +585,7 @@ var TASK_STATUSES = /* @__PURE__ */ new Set([
|
|
|
378
585
|
]);
|
|
379
586
|
var isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
380
587
|
var isNullableString = (value) => typeof value === "string" || value === null;
|
|
588
|
+
var isOptionalNullableString = (value) => value === void 0 || isNullableString(value);
|
|
381
589
|
var toArrayBuffer = (bytes) => {
|
|
382
590
|
const copy = new Uint8Array(bytes.byteLength);
|
|
383
591
|
copy.set(bytes);
|
|
@@ -435,7 +643,7 @@ var isExportTaskSnapshot = (value) => {
|
|
|
435
643
|
if (!isObject(value)) {
|
|
436
644
|
return false;
|
|
437
645
|
}
|
|
438
|
-
return typeof value.taskId === "string" && isNullableString(value.createdByApiKeyId) && isNullableString(value.clientTaskId) && isTaskStatus(value.status) && typeof value.progress === "number" && isNullableString(value.error) && isNullableString(value.outputUrl) && typeof value.durationSeconds === "number" && typeof value.billedStandardSeconds === "number" && typeof value.chargedCredits === "string" && isNullableString(value.callbackUrl) && typeof value.createdAt === "string" && isNullableString(value.completedAt);
|
|
646
|
+
return typeof value.taskId === "string" && isOptionalNullableString(value.projectId) && isNullableString(value.createdByApiKeyId) && isNullableString(value.clientTaskId) && isTaskStatus(value.status) && typeof value.progress === "number" && isNullableString(value.error) && isNullableString(value.outputUrl) && typeof value.durationSeconds === "number" && typeof value.billedStandardSeconds === "number" && typeof value.chargedCredits === "string" && isNullableString(value.callbackUrl) && typeof value.createdAt === "string" && isNullableString(value.completedAt);
|
|
439
647
|
};
|
|
440
648
|
var isExportWebhookEvent = (value) => {
|
|
441
649
|
if (!isObject(value)) {
|
|
@@ -510,9 +718,14 @@ var verifyExportWebhookRequest = async ({
|
|
|
510
718
|
// Annotate the CommonJS export names for ESM import in node:
|
|
511
719
|
0 && (module.exports = {
|
|
512
720
|
APIError,
|
|
721
|
+
AssetsResource,
|
|
513
722
|
AuthError,
|
|
723
|
+
EditorResource,
|
|
724
|
+
ExportsResource,
|
|
514
725
|
IndreamClient,
|
|
726
|
+
ProjectsResource,
|
|
515
727
|
RateLimitError,
|
|
728
|
+
UploadsResource,
|
|
516
729
|
ValidationError,
|
|
517
730
|
createApiError,
|
|
518
731
|
isExportTaskSnapshot,
|