@magiclabs.ai/magicbook-client 0.7.11-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 +32 -13
- package/index.cjs.map +1 -1
- package/index.d.cts +20 -8
- package/index.d.ts +20 -8
- package/index.iife.js +32 -13
- package/index.js +32 -13
- package/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -53,6 +53,12 @@ const image: Image = {...}
|
|
|
53
53
|
await designRequest.images.add(image)
|
|
54
54
|
```
|
|
55
55
|
|
|
56
|
+
To remove an image, you can invoke the delete function as follows:
|
|
57
|
+
|
|
58
|
+
```ts
|
|
59
|
+
await designRequest.images.delete(imageId)
|
|
60
|
+
```
|
|
61
|
+
|
|
56
62
|
This would typically be done in an event handler connected to the image manager.
|
|
57
63
|
|
|
58
64
|
```ts
|
package/index.cjs
CHANGED
|
@@ -4492,25 +4492,37 @@ var Book = class {
|
|
|
4492
4492
|
|
|
4493
4493
|
// ../../core/models/design-request/image.ts
|
|
4494
4494
|
var Images = class {
|
|
4495
|
-
// eslint-disable-next-line no-unused-vars
|
|
4496
4495
|
constructor(client, parentId, designRequestState) {
|
|
4497
4496
|
this.client = client;
|
|
4498
4497
|
this.parentId = parentId;
|
|
4499
|
-
this.
|
|
4500
|
-
this.length = this.
|
|
4498
|
+
this.list = [];
|
|
4499
|
+
this.length = this.list.length;
|
|
4501
4500
|
this.designRequestState = designRequestState;
|
|
4502
4501
|
}
|
|
4503
4502
|
parentId;
|
|
4504
|
-
|
|
4503
|
+
list;
|
|
4505
4504
|
length;
|
|
4506
4505
|
designRequestState;
|
|
4507
4506
|
async add(image) {
|
|
4508
4507
|
if (!canSubmitDesignRequest(this.designRequestState)) {
|
|
4509
4508
|
throw new Error("You need to wait for the current design request to be ready before adding new images.");
|
|
4510
4509
|
} else {
|
|
4511
|
-
this.images.
|
|
4512
|
-
|
|
4513
|
-
|
|
4510
|
+
const serverImage = await this.client.engineAPI.images.addToBook(this.parentId, new ImageServer(image));
|
|
4511
|
+
const img = imageServerToImage(serverImage);
|
|
4512
|
+
this.list.push(img);
|
|
4513
|
+
this.length = this.list.length;
|
|
4514
|
+
return new Promise((resolve) => {
|
|
4515
|
+
resolve(img);
|
|
4516
|
+
});
|
|
4517
|
+
}
|
|
4518
|
+
}
|
|
4519
|
+
async delete(imageId) {
|
|
4520
|
+
if (!canSubmitDesignRequest(this.designRequestState)) {
|
|
4521
|
+
throw new Error("You need to wait for the current design request to be ready before deleting images.");
|
|
4522
|
+
} else {
|
|
4523
|
+
await this.client.engineAPI.images.delete(imageId, this.parentId);
|
|
4524
|
+
this.list.splice(this.list.findIndex((image) => image.handle === imageId), 1);
|
|
4525
|
+
this.length = this.list.length;
|
|
4514
4526
|
return new Promise((resolve) => {
|
|
4515
4527
|
resolve(this.length);
|
|
4516
4528
|
});
|
|
@@ -4527,9 +4539,11 @@ var imageServerSchema = z.object({
|
|
|
4527
4539
|
taken_at: z.string(),
|
|
4528
4540
|
camera_make: z.string().optional(),
|
|
4529
4541
|
camera: z.string().optional(),
|
|
4530
|
-
filename: z.string()
|
|
4542
|
+
filename: z.string(),
|
|
4543
|
+
metadata: z.record(z.unknown()).optional()
|
|
4531
4544
|
});
|
|
4532
4545
|
var ImageServer = class {
|
|
4546
|
+
id;
|
|
4533
4547
|
handle;
|
|
4534
4548
|
url;
|
|
4535
4549
|
width;
|
|
@@ -4539,7 +4553,9 @@ var ImageServer = class {
|
|
|
4539
4553
|
camera_make;
|
|
4540
4554
|
camera;
|
|
4541
4555
|
filename;
|
|
4556
|
+
metadata;
|
|
4542
4557
|
constructor(image) {
|
|
4558
|
+
this.id = image.id;
|
|
4543
4559
|
this.handle = image.handle;
|
|
4544
4560
|
this.url = image.url;
|
|
4545
4561
|
this.width = image.width;
|
|
@@ -4549,10 +4565,12 @@ var ImageServer = class {
|
|
|
4549
4565
|
this.camera_make = image.cameraMake;
|
|
4550
4566
|
this.camera = image.cameraModel;
|
|
4551
4567
|
this.filename = image.filename;
|
|
4568
|
+
this.metadata = image.metadata;
|
|
4552
4569
|
}
|
|
4553
4570
|
};
|
|
4554
4571
|
function imageServerToImage(imageServer) {
|
|
4555
4572
|
return {
|
|
4573
|
+
id: imageServer.id,
|
|
4556
4574
|
handle: imageServer.handle,
|
|
4557
4575
|
url: imageServer.url,
|
|
4558
4576
|
width: imageServer.width,
|
|
@@ -4561,7 +4579,8 @@ function imageServerToImage(imageServer) {
|
|
|
4561
4579
|
captureTime: imageServer.taken_at,
|
|
4562
4580
|
cameraMake: imageServer.camera_make,
|
|
4563
4581
|
cameraModel: imageServer.camera,
|
|
4564
|
-
filename: imageServer.filename
|
|
4582
|
+
filename: imageServer.filename,
|
|
4583
|
+
metadata: imageServer.metadata
|
|
4565
4584
|
};
|
|
4566
4585
|
}
|
|
4567
4586
|
|
|
@@ -4762,7 +4781,7 @@ var DesignRequest = class {
|
|
|
4762
4781
|
toBook() {
|
|
4763
4782
|
const designRequest = {
|
|
4764
4783
|
...this,
|
|
4765
|
-
images: this.images
|
|
4784
|
+
images: this.images.list
|
|
4766
4785
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
4767
4786
|
};
|
|
4768
4787
|
delete designRequest.client;
|
|
@@ -4985,7 +5004,7 @@ var ImagesEndpoints = class {
|
|
|
4985
5004
|
retrieve(imageId, bookId) {
|
|
4986
5005
|
return handleAsyncFunction(async () => {
|
|
4987
5006
|
const res = await this.engineAPI.fetcher.call({
|
|
4988
|
-
path: `/v1/images/${imageId}/book/${bookId}
|
|
5007
|
+
path: `/v1/images/${imageId}/book/${bookId}`
|
|
4989
5008
|
});
|
|
4990
5009
|
return imageServerSchema.parse(res);
|
|
4991
5010
|
});
|
|
@@ -4993,7 +5012,7 @@ var ImagesEndpoints = class {
|
|
|
4993
5012
|
update(imageId, bookId, image) {
|
|
4994
5013
|
return handleAsyncFunction(async () => {
|
|
4995
5014
|
const res = await this.engineAPI.fetcher.call({
|
|
4996
|
-
path: `/v1/images/${imageId}/book/${bookId}
|
|
5015
|
+
path: `/v1/images/${imageId}/book/${bookId}`,
|
|
4997
5016
|
options: {
|
|
4998
5017
|
method: "PUT",
|
|
4999
5018
|
body: cleanJSON(image)
|
|
@@ -5005,7 +5024,7 @@ var ImagesEndpoints = class {
|
|
|
5005
5024
|
delete(imageId, bookId) {
|
|
5006
5025
|
return handleAsyncFunction(async () => {
|
|
5007
5026
|
await this.engineAPI.fetcher.call({
|
|
5008
|
-
path: `/v1/images/${imageId}/book/${bookId}
|
|
5027
|
+
path: `/v1/images/${imageId}/book/${bookId}`,
|
|
5009
5028
|
options: {
|
|
5010
5029
|
method: "DELETE"
|
|
5011
5030
|
}
|