@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 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
@@ -4495,21 +4495,34 @@ var Images = class {
4495
4495
  constructor(client, parentId, designRequestState) {
4496
4496
  this.client = client;
4497
4497
  this.parentId = parentId;
4498
- this.images = [];
4499
- this.length = this.images.length;
4498
+ this.list = [];
4499
+ this.length = this.list.length;
4500
4500
  this.designRequestState = designRequestState;
4501
4501
  }
4502
4502
  parentId;
4503
- images;
4503
+ list;
4504
4504
  length;
4505
4505
  designRequestState;
4506
4506
  async add(image) {
4507
4507
  if (!canSubmitDesignRequest(this.designRequestState)) {
4508
4508
  throw new Error("You need to wait for the current design request to be ready before adding new images.");
4509
4509
  } else {
4510
- this.images.push(image);
4511
- this.length = this.images.length;
4512
- await this.client.engineAPI.images.addToBook(this.parentId, new ImageServer(image));
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;
4513
4526
  return new Promise((resolve) => {
4514
4527
  resolve(this.length);
4515
4528
  });
@@ -4530,6 +4543,7 @@ var imageServerSchema = z.object({
4530
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;
@@ -4541,6 +4555,7 @@ var ImageServer = class {
4541
4555
  filename;
4542
4556
  metadata;
4543
4557
  constructor(image) {
4558
+ this.id = image.id;
4544
4559
  this.handle = image.handle;
4545
4560
  this.url = image.url;
4546
4561
  this.width = image.width;
@@ -4555,6 +4570,7 @@ var ImageServer = class {
4555
4570
  };
4556
4571
  function imageServerToImage(imageServer) {
4557
4572
  return {
4573
+ id: imageServer.id,
4558
4574
  handle: imageServer.handle,
4559
4575
  url: imageServer.url,
4560
4576
  width: imageServer.width,
@@ -4765,7 +4781,7 @@ var DesignRequest = class {
4765
4781
  toBook() {
4766
4782
  const designRequest = {
4767
4783
  ...this,
4768
- images: this.images["images"]
4784
+ images: this.images.list
4769
4785
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
4770
4786
  };
4771
4787
  delete designRequest.client;
@@ -4988,7 +5004,7 @@ var ImagesEndpoints = class {
4988
5004
  retrieve(imageId, bookId) {
4989
5005
  return handleAsyncFunction(async () => {
4990
5006
  const res = await this.engineAPI.fetcher.call({
4991
- path: `/v1/images/${imageId}/book/${bookId}/`
5007
+ path: `/v1/images/${imageId}/book/${bookId}`
4992
5008
  });
4993
5009
  return imageServerSchema.parse(res);
4994
5010
  });
@@ -4996,7 +5012,7 @@ var ImagesEndpoints = class {
4996
5012
  update(imageId, bookId, image) {
4997
5013
  return handleAsyncFunction(async () => {
4998
5014
  const res = await this.engineAPI.fetcher.call({
4999
- path: `/v1/images/${imageId}/book/${bookId}/`,
5015
+ path: `/v1/images/${imageId}/book/${bookId}`,
5000
5016
  options: {
5001
5017
  method: "PUT",
5002
5018
  body: cleanJSON(image)
@@ -5008,7 +5024,7 @@ var ImagesEndpoints = class {
5008
5024
  delete(imageId, bookId) {
5009
5025
  return handleAsyncFunction(async () => {
5010
5026
  await this.engineAPI.fetcher.call({
5011
- path: `/v1/images/${imageId}/book/${bookId}/`,
5027
+ path: `/v1/images/${imageId}/book/${bookId}`,
5012
5028
  options: {
5013
5029
  method: "DELETE"
5014
5030
  }