@magiclabs.ai/magicbook-client 0.7.12-canary → 0.7.14-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 +39 -11
- package/index.cjs.map +1 -1
- package/index.d.cts +15 -12
- package/index.d.ts +15 -12
- package/index.iife.js +39 -11
- package/index.js +39 -11
- 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
|
@@ -389,7 +389,19 @@ var styles = {
|
|
|
389
389
|
"03f332e3b2b947ebae73b67a9a22b6f4": { slug: "winter-sparkle-snap" },
|
|
390
390
|
"97f70f6cdb5244a08d45772cccfa2788": { slug: "year-of-memories-snap" }
|
|
391
391
|
};
|
|
392
|
-
var bookSizes = [
|
|
392
|
+
var bookSizes = [
|
|
393
|
+
"4.5x4",
|
|
394
|
+
"5x7",
|
|
395
|
+
"6x6",
|
|
396
|
+
"6x8",
|
|
397
|
+
"7x5",
|
|
398
|
+
"8x8",
|
|
399
|
+
"8x11",
|
|
400
|
+
"10x10",
|
|
401
|
+
"11x8",
|
|
402
|
+
"11x14",
|
|
403
|
+
"12x12"
|
|
404
|
+
];
|
|
393
405
|
var coverTypes = ["sc", "hc", "pl"];
|
|
394
406
|
var pageTypes = ["sp", "sl", "dl"];
|
|
395
407
|
var imageDensities = ["low", "medium", "high"];
|
|
@@ -4495,21 +4507,34 @@ var Images = class {
|
|
|
4495
4507
|
constructor(client, parentId, designRequestState) {
|
|
4496
4508
|
this.client = client;
|
|
4497
4509
|
this.parentId = parentId;
|
|
4498
|
-
this.
|
|
4499
|
-
this.length = this.
|
|
4510
|
+
this.list = [];
|
|
4511
|
+
this.length = this.list.length;
|
|
4500
4512
|
this.designRequestState = designRequestState;
|
|
4501
4513
|
}
|
|
4502
4514
|
parentId;
|
|
4503
|
-
|
|
4515
|
+
list;
|
|
4504
4516
|
length;
|
|
4505
4517
|
designRequestState;
|
|
4506
4518
|
async add(image) {
|
|
4507
4519
|
if (!canSubmitDesignRequest(this.designRequestState)) {
|
|
4508
4520
|
throw new Error("You need to wait for the current design request to be ready before adding new images.");
|
|
4509
4521
|
} else {
|
|
4510
|
-
this.images.
|
|
4511
|
-
|
|
4512
|
-
|
|
4522
|
+
const serverImage = await this.client.engineAPI.images.addToBook(this.parentId, new ImageServer(image));
|
|
4523
|
+
const img = imageServerToImage(serverImage);
|
|
4524
|
+
this.list.push(img);
|
|
4525
|
+
this.length = this.list.length;
|
|
4526
|
+
return new Promise((resolve) => {
|
|
4527
|
+
resolve(img);
|
|
4528
|
+
});
|
|
4529
|
+
}
|
|
4530
|
+
}
|
|
4531
|
+
async delete(imageId) {
|
|
4532
|
+
if (!canSubmitDesignRequest(this.designRequestState)) {
|
|
4533
|
+
throw new Error("You need to wait for the current design request to be ready before deleting images.");
|
|
4534
|
+
} else {
|
|
4535
|
+
await this.client.engineAPI.images.delete(imageId, this.parentId);
|
|
4536
|
+
this.list.splice(this.list.findIndex((image) => image.handle === imageId), 1);
|
|
4537
|
+
this.length = this.list.length;
|
|
4513
4538
|
return new Promise((resolve) => {
|
|
4514
4539
|
resolve(this.length);
|
|
4515
4540
|
});
|
|
@@ -4530,6 +4555,7 @@ var imageServerSchema = z.object({
|
|
|
4530
4555
|
metadata: z.record(z.unknown()).optional()
|
|
4531
4556
|
});
|
|
4532
4557
|
var ImageServer = class {
|
|
4558
|
+
id;
|
|
4533
4559
|
handle;
|
|
4534
4560
|
url;
|
|
4535
4561
|
width;
|
|
@@ -4541,6 +4567,7 @@ var ImageServer = class {
|
|
|
4541
4567
|
filename;
|
|
4542
4568
|
metadata;
|
|
4543
4569
|
constructor(image) {
|
|
4570
|
+
this.id = image.id;
|
|
4544
4571
|
this.handle = image.handle;
|
|
4545
4572
|
this.url = image.url;
|
|
4546
4573
|
this.width = image.width;
|
|
@@ -4555,6 +4582,7 @@ var ImageServer = class {
|
|
|
4555
4582
|
};
|
|
4556
4583
|
function imageServerToImage(imageServer) {
|
|
4557
4584
|
return {
|
|
4585
|
+
id: imageServer.id,
|
|
4558
4586
|
handle: imageServer.handle,
|
|
4559
4587
|
url: imageServer.url,
|
|
4560
4588
|
width: imageServer.width,
|
|
@@ -4765,7 +4793,7 @@ var DesignRequest = class {
|
|
|
4765
4793
|
toBook() {
|
|
4766
4794
|
const designRequest = {
|
|
4767
4795
|
...this,
|
|
4768
|
-
images: this.images
|
|
4796
|
+
images: this.images.list
|
|
4769
4797
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
4770
4798
|
};
|
|
4771
4799
|
delete designRequest.client;
|
|
@@ -4988,7 +5016,7 @@ var ImagesEndpoints = class {
|
|
|
4988
5016
|
retrieve(imageId, bookId) {
|
|
4989
5017
|
return handleAsyncFunction(async () => {
|
|
4990
5018
|
const res = await this.engineAPI.fetcher.call({
|
|
4991
|
-
path: `/v1/images/${imageId}/book/${bookId}
|
|
5019
|
+
path: `/v1/images/${imageId}/book/${bookId}`
|
|
4992
5020
|
});
|
|
4993
5021
|
return imageServerSchema.parse(res);
|
|
4994
5022
|
});
|
|
@@ -4996,7 +5024,7 @@ var ImagesEndpoints = class {
|
|
|
4996
5024
|
update(imageId, bookId, image) {
|
|
4997
5025
|
return handleAsyncFunction(async () => {
|
|
4998
5026
|
const res = await this.engineAPI.fetcher.call({
|
|
4999
|
-
path: `/v1/images/${imageId}/book/${bookId}
|
|
5027
|
+
path: `/v1/images/${imageId}/book/${bookId}`,
|
|
5000
5028
|
options: {
|
|
5001
5029
|
method: "PUT",
|
|
5002
5030
|
body: cleanJSON(image)
|
|
@@ -5008,7 +5036,7 @@ var ImagesEndpoints = class {
|
|
|
5008
5036
|
delete(imageId, bookId) {
|
|
5009
5037
|
return handleAsyncFunction(async () => {
|
|
5010
5038
|
await this.engineAPI.fetcher.call({
|
|
5011
|
-
path: `/v1/images/${imageId}/book/${bookId}
|
|
5039
|
+
path: `/v1/images/${imageId}/book/${bookId}`,
|
|
5012
5040
|
options: {
|
|
5013
5041
|
method: "DELETE"
|
|
5014
5042
|
}
|