@magiclabs.ai/magicbook-client 0.7.12-canary → 0.7.13-canary
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/README.md +6 -0
- package/index.cjs +26 -10
- package/index.cjs.map +1 -1
- package/index.d.cts +5 -2
- package/index.d.ts +5 -2
- package/index.iife.js +26 -10
- package/index.js +26 -10
- package/index.js.map +1 -1
- package/package.json +1 -1
package/index.d.cts
CHANGED
|
@@ -1183,6 +1183,7 @@ declare class MagicBookClient {
|
|
|
1183
1183
|
}
|
|
1184
1184
|
|
|
1185
1185
|
type Image = {
|
|
1186
|
+
id?: string;
|
|
1186
1187
|
handle: string;
|
|
1187
1188
|
url: string;
|
|
1188
1189
|
width: number;
|
|
@@ -1197,11 +1198,12 @@ type Image = {
|
|
|
1197
1198
|
declare class Images {
|
|
1198
1199
|
private readonly client;
|
|
1199
1200
|
private parentId;
|
|
1200
|
-
|
|
1201
|
+
list: Array<Image>;
|
|
1201
1202
|
length: number;
|
|
1202
1203
|
designRequestState: State;
|
|
1203
1204
|
constructor(client: MagicBookClient, parentId: string, designRequestState: State);
|
|
1204
|
-
add(image: Image): Promise<
|
|
1205
|
+
add(image: Image): Promise<Image>;
|
|
1206
|
+
delete(imageId: string): Promise<number>;
|
|
1205
1207
|
}
|
|
1206
1208
|
declare const imageServerSchema: z.ZodObject<{
|
|
1207
1209
|
id: z.ZodOptional<z.ZodString>;
|
|
@@ -1241,6 +1243,7 @@ declare const imageServerSchema: z.ZodObject<{
|
|
|
1241
1243
|
metadata?: Record<string, unknown> | undefined;
|
|
1242
1244
|
}>;
|
|
1243
1245
|
declare class ImageServer {
|
|
1246
|
+
id?: string;
|
|
1244
1247
|
handle: string;
|
|
1245
1248
|
url: string;
|
|
1246
1249
|
width: number;
|
package/index.d.ts
CHANGED
|
@@ -1183,6 +1183,7 @@ declare class MagicBookClient {
|
|
|
1183
1183
|
}
|
|
1184
1184
|
|
|
1185
1185
|
type Image = {
|
|
1186
|
+
id?: string;
|
|
1186
1187
|
handle: string;
|
|
1187
1188
|
url: string;
|
|
1188
1189
|
width: number;
|
|
@@ -1197,11 +1198,12 @@ type Image = {
|
|
|
1197
1198
|
declare class Images {
|
|
1198
1199
|
private readonly client;
|
|
1199
1200
|
private parentId;
|
|
1200
|
-
|
|
1201
|
+
list: Array<Image>;
|
|
1201
1202
|
length: number;
|
|
1202
1203
|
designRequestState: State;
|
|
1203
1204
|
constructor(client: MagicBookClient, parentId: string, designRequestState: State);
|
|
1204
|
-
add(image: Image): Promise<
|
|
1205
|
+
add(image: Image): Promise<Image>;
|
|
1206
|
+
delete(imageId: string): Promise<number>;
|
|
1205
1207
|
}
|
|
1206
1208
|
declare const imageServerSchema: z.ZodObject<{
|
|
1207
1209
|
id: z.ZodOptional<z.ZodString>;
|
|
@@ -1241,6 +1243,7 @@ declare const imageServerSchema: z.ZodObject<{
|
|
|
1241
1243
|
metadata?: Record<string, unknown> | undefined;
|
|
1242
1244
|
}>;
|
|
1243
1245
|
declare class ImageServer {
|
|
1246
|
+
id?: string;
|
|
1244
1247
|
handle: string;
|
|
1245
1248
|
url: string;
|
|
1246
1249
|
width: number;
|
package/index.iife.js
CHANGED
|
@@ -4485,21 +4485,34 @@ var MagicLabs = (() => {
|
|
|
4485
4485
|
constructor(client, parentId, designRequestState) {
|
|
4486
4486
|
this.client = client;
|
|
4487
4487
|
this.parentId = parentId;
|
|
4488
|
-
this.
|
|
4489
|
-
this.length = this.
|
|
4488
|
+
this.list = [];
|
|
4489
|
+
this.length = this.list.length;
|
|
4490
4490
|
this.designRequestState = designRequestState;
|
|
4491
4491
|
}
|
|
4492
4492
|
parentId;
|
|
4493
|
-
|
|
4493
|
+
list;
|
|
4494
4494
|
length;
|
|
4495
4495
|
designRequestState;
|
|
4496
4496
|
async add(image) {
|
|
4497
4497
|
if (!canSubmitDesignRequest(this.designRequestState)) {
|
|
4498
4498
|
throw new Error("You need to wait for the current design request to be ready before adding new images.");
|
|
4499
4499
|
} else {
|
|
4500
|
-
this.images.
|
|
4501
|
-
|
|
4502
|
-
|
|
4500
|
+
const serverImage = await this.client.engineAPI.images.addToBook(this.parentId, new ImageServer(image));
|
|
4501
|
+
const img = imageServerToImage(serverImage);
|
|
4502
|
+
this.list.push(img);
|
|
4503
|
+
this.length = this.list.length;
|
|
4504
|
+
return new Promise((resolve) => {
|
|
4505
|
+
resolve(img);
|
|
4506
|
+
});
|
|
4507
|
+
}
|
|
4508
|
+
}
|
|
4509
|
+
async delete(imageId) {
|
|
4510
|
+
if (!canSubmitDesignRequest(this.designRequestState)) {
|
|
4511
|
+
throw new Error("You need to wait for the current design request to be ready before deleting images.");
|
|
4512
|
+
} else {
|
|
4513
|
+
await this.client.engineAPI.images.delete(imageId, this.parentId);
|
|
4514
|
+
this.list.splice(this.list.findIndex((image) => image.handle === imageId), 1);
|
|
4515
|
+
this.length = this.list.length;
|
|
4503
4516
|
return new Promise((resolve) => {
|
|
4504
4517
|
resolve(this.length);
|
|
4505
4518
|
});
|
|
@@ -4520,6 +4533,7 @@ var MagicLabs = (() => {
|
|
|
4520
4533
|
metadata: z.record(z.unknown()).optional()
|
|
4521
4534
|
});
|
|
4522
4535
|
var ImageServer = class {
|
|
4536
|
+
id;
|
|
4523
4537
|
handle;
|
|
4524
4538
|
url;
|
|
4525
4539
|
width;
|
|
@@ -4531,6 +4545,7 @@ var MagicLabs = (() => {
|
|
|
4531
4545
|
filename;
|
|
4532
4546
|
metadata;
|
|
4533
4547
|
constructor(image) {
|
|
4548
|
+
this.id = image.id;
|
|
4534
4549
|
this.handle = image.handle;
|
|
4535
4550
|
this.url = image.url;
|
|
4536
4551
|
this.width = image.width;
|
|
@@ -4545,6 +4560,7 @@ var MagicLabs = (() => {
|
|
|
4545
4560
|
};
|
|
4546
4561
|
function imageServerToImage(imageServer) {
|
|
4547
4562
|
return {
|
|
4563
|
+
id: imageServer.id,
|
|
4548
4564
|
handle: imageServer.handle,
|
|
4549
4565
|
url: imageServer.url,
|
|
4550
4566
|
width: imageServer.width,
|
|
@@ -4751,7 +4767,7 @@ var MagicLabs = (() => {
|
|
|
4751
4767
|
toBook() {
|
|
4752
4768
|
const designRequest = {
|
|
4753
4769
|
...this,
|
|
4754
|
-
images: this.images
|
|
4770
|
+
images: this.images.list
|
|
4755
4771
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
4756
4772
|
};
|
|
4757
4773
|
delete designRequest.client;
|
|
@@ -4962,7 +4978,7 @@ var MagicLabs = (() => {
|
|
|
4962
4978
|
retrieve(imageId, bookId) {
|
|
4963
4979
|
return handleAsyncFunction(async () => {
|
|
4964
4980
|
const res = await this.engineAPI.fetcher.call({
|
|
4965
|
-
path: `/v1/images/${imageId}/book/${bookId}
|
|
4981
|
+
path: `/v1/images/${imageId}/book/${bookId}`
|
|
4966
4982
|
});
|
|
4967
4983
|
return imageServerSchema.parse(res);
|
|
4968
4984
|
});
|
|
@@ -4970,7 +4986,7 @@ var MagicLabs = (() => {
|
|
|
4970
4986
|
update(imageId, bookId, image) {
|
|
4971
4987
|
return handleAsyncFunction(async () => {
|
|
4972
4988
|
const res = await this.engineAPI.fetcher.call({
|
|
4973
|
-
path: `/v1/images/${imageId}/book/${bookId}
|
|
4989
|
+
path: `/v1/images/${imageId}/book/${bookId}`,
|
|
4974
4990
|
options: {
|
|
4975
4991
|
method: "PUT",
|
|
4976
4992
|
body: cleanJSON(image)
|
|
@@ -4982,7 +4998,7 @@ var MagicLabs = (() => {
|
|
|
4982
4998
|
delete(imageId, bookId) {
|
|
4983
4999
|
return handleAsyncFunction(async () => {
|
|
4984
5000
|
await this.engineAPI.fetcher.call({
|
|
4985
|
-
path: `/v1/images/${imageId}/book/${bookId}
|
|
5001
|
+
path: `/v1/images/${imageId}/book/${bookId}`,
|
|
4986
5002
|
options: {
|
|
4987
5003
|
method: "DELETE"
|
|
4988
5004
|
}
|
package/index.js
CHANGED
|
@@ -4423,21 +4423,34 @@ var Images = class {
|
|
|
4423
4423
|
constructor(client, parentId, designRequestState) {
|
|
4424
4424
|
this.client = client;
|
|
4425
4425
|
this.parentId = parentId;
|
|
4426
|
-
this.
|
|
4427
|
-
this.length = this.
|
|
4426
|
+
this.list = [];
|
|
4427
|
+
this.length = this.list.length;
|
|
4428
4428
|
this.designRequestState = designRequestState;
|
|
4429
4429
|
}
|
|
4430
4430
|
parentId;
|
|
4431
|
-
|
|
4431
|
+
list;
|
|
4432
4432
|
length;
|
|
4433
4433
|
designRequestState;
|
|
4434
4434
|
async add(image) {
|
|
4435
4435
|
if (!canSubmitDesignRequest(this.designRequestState)) {
|
|
4436
4436
|
throw new Error("You need to wait for the current design request to be ready before adding new images.");
|
|
4437
4437
|
} else {
|
|
4438
|
-
this.images.
|
|
4439
|
-
|
|
4440
|
-
|
|
4438
|
+
const serverImage = await this.client.engineAPI.images.addToBook(this.parentId, new ImageServer(image));
|
|
4439
|
+
const img = imageServerToImage(serverImage);
|
|
4440
|
+
this.list.push(img);
|
|
4441
|
+
this.length = this.list.length;
|
|
4442
|
+
return new Promise((resolve) => {
|
|
4443
|
+
resolve(img);
|
|
4444
|
+
});
|
|
4445
|
+
}
|
|
4446
|
+
}
|
|
4447
|
+
async delete(imageId) {
|
|
4448
|
+
if (!canSubmitDesignRequest(this.designRequestState)) {
|
|
4449
|
+
throw new Error("You need to wait for the current design request to be ready before deleting images.");
|
|
4450
|
+
} else {
|
|
4451
|
+
await this.client.engineAPI.images.delete(imageId, this.parentId);
|
|
4452
|
+
this.list.splice(this.list.findIndex((image) => image.handle === imageId), 1);
|
|
4453
|
+
this.length = this.list.length;
|
|
4441
4454
|
return new Promise((resolve) => {
|
|
4442
4455
|
resolve(this.length);
|
|
4443
4456
|
});
|
|
@@ -4458,6 +4471,7 @@ var imageServerSchema = z.object({
|
|
|
4458
4471
|
metadata: z.record(z.unknown()).optional()
|
|
4459
4472
|
});
|
|
4460
4473
|
var ImageServer = class {
|
|
4474
|
+
id;
|
|
4461
4475
|
handle;
|
|
4462
4476
|
url;
|
|
4463
4477
|
width;
|
|
@@ -4469,6 +4483,7 @@ var ImageServer = class {
|
|
|
4469
4483
|
filename;
|
|
4470
4484
|
metadata;
|
|
4471
4485
|
constructor(image) {
|
|
4486
|
+
this.id = image.id;
|
|
4472
4487
|
this.handle = image.handle;
|
|
4473
4488
|
this.url = image.url;
|
|
4474
4489
|
this.width = image.width;
|
|
@@ -4483,6 +4498,7 @@ var ImageServer = class {
|
|
|
4483
4498
|
};
|
|
4484
4499
|
function imageServerToImage(imageServer) {
|
|
4485
4500
|
return {
|
|
4501
|
+
id: imageServer.id,
|
|
4486
4502
|
handle: imageServer.handle,
|
|
4487
4503
|
url: imageServer.url,
|
|
4488
4504
|
width: imageServer.width,
|
|
@@ -4693,7 +4709,7 @@ var DesignRequest = class {
|
|
|
4693
4709
|
toBook() {
|
|
4694
4710
|
const designRequest = {
|
|
4695
4711
|
...this,
|
|
4696
|
-
images: this.images
|
|
4712
|
+
images: this.images.list
|
|
4697
4713
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
4698
4714
|
};
|
|
4699
4715
|
delete designRequest.client;
|
|
@@ -4916,7 +4932,7 @@ var ImagesEndpoints = class {
|
|
|
4916
4932
|
retrieve(imageId, bookId) {
|
|
4917
4933
|
return handleAsyncFunction(async () => {
|
|
4918
4934
|
const res = await this.engineAPI.fetcher.call({
|
|
4919
|
-
path: `/v1/images/${imageId}/book/${bookId}
|
|
4935
|
+
path: `/v1/images/${imageId}/book/${bookId}`
|
|
4920
4936
|
});
|
|
4921
4937
|
return imageServerSchema.parse(res);
|
|
4922
4938
|
});
|
|
@@ -4924,7 +4940,7 @@ var ImagesEndpoints = class {
|
|
|
4924
4940
|
update(imageId, bookId, image) {
|
|
4925
4941
|
return handleAsyncFunction(async () => {
|
|
4926
4942
|
const res = await this.engineAPI.fetcher.call({
|
|
4927
|
-
path: `/v1/images/${imageId}/book/${bookId}
|
|
4943
|
+
path: `/v1/images/${imageId}/book/${bookId}`,
|
|
4928
4944
|
options: {
|
|
4929
4945
|
method: "PUT",
|
|
4930
4946
|
body: cleanJSON(image)
|
|
@@ -4936,7 +4952,7 @@ var ImagesEndpoints = class {
|
|
|
4936
4952
|
delete(imageId, bookId) {
|
|
4937
4953
|
return handleAsyncFunction(async () => {
|
|
4938
4954
|
await this.engineAPI.fetcher.call({
|
|
4939
|
-
path: `/v1/images/${imageId}/book/${bookId}
|
|
4955
|
+
path: `/v1/images/${imageId}/book/${bookId}`,
|
|
4940
4956
|
options: {
|
|
4941
4957
|
method: "DELETE"
|
|
4942
4958
|
}
|