@magiclabs.ai/magicbook-client 0.7.5 → 0.7.6

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
@@ -1,4 +1,3 @@
1
-
2
1
  ![GitHub CI](https://github.com/magiclabs-ai/mb-client/actions/workflows/ci.yml/badge.svg) [![npm version](https://img.shields.io/npm/v/@magiclabs.ai/magicbook-client.svg)](https://www.npmjs.com/package/@magiclabs.ai/magicbook-client)
3
2
 
4
3
  # magicbook-client
@@ -13,7 +12,7 @@ npm install @magiclabs.ai/magicbook-client
13
12
 
14
13
  ## Usage
15
14
 
16
- Create a Magicbook API client instance with your API key.
15
+ Create a Magicbook API client instance with your API key.
17
16
 
18
17
  ```ts
19
18
  const client = new MagicBookClient('api-key')`
@@ -37,13 +36,14 @@ Individual parameters can also be set directly on the design request instance (e
37
36
 
38
37
  ```ts
39
38
  const designRequest = await client.createDesignRequest()
40
- designRequest.title = 'Australia 2023',
41
- designRequest.occasion = 'travel',
42
- designRequest.style = '1234',
43
- designRequest.bookSize = '8x8',
44
- designRequest.coverType = 'hc',
45
- designRequest.pageType = 'sp'
39
+ ;(designRequest.title = 'Australia 2023'),
40
+ (designRequest.occasion = 'travel'),
41
+ (designRequest.style = '1234'),
42
+ (designRequest.bookSize = '8x8'),
43
+ (designRequest.coverType = 'hc'),
44
+ (designRequest.pageType = 'sp')
46
45
  ```
46
+
47
47
  As images are getting ready to be handed over to Magicbook, for example when successfully uploaded, add them to the design request object.
48
48
 
49
49
  ```ts
@@ -73,9 +73,12 @@ const designOptions = designRequest.getOptions(selectedImageCount)
73
73
  Before submitting the design request to Magicbook, register a callback to receive update events.
74
74
 
75
75
  ```ts
76
- window.addEventListener('Magicbook.designRequestUpdated', async ((designRequestEvent: DesignRequestEvent) => {
77
- console.log(designRequestEvent.detail)
78
- }) as EventListener)
76
+ window.addEventListener(
77
+ 'Magicbook.designRequestUpdated',
78
+ async((designRequestEvent: DesignRequestEvent) => {
79
+ console.log(designRequestEvent.detail)
80
+ }) as EventListener
81
+ )
79
82
  ```
80
83
 
81
84
  Submit the design request. Again, the argument object can receive additional or updated design parameters.
@@ -102,13 +105,19 @@ Once the design request is complete, retrieve it in JSON format.
102
105
  await designRequest.getJSON()
103
106
  ```
104
107
 
108
+ You can get alternate layouts for a specific page.
109
+
110
+ ```ts
111
+ await designRequest.getAlternateLayouts(-1)
112
+ ```
113
+
105
114
  When a user performs a specific action, log it by calling the `logEvent` method.
106
115
 
107
116
  ```ts
108
117
  await designRequest.logEvent('book.viewed', data)
109
118
  ```
110
119
 
111
- ___
120
+ ---
112
121
 
113
122
  ## Example
114
123
 
package/index.cjs CHANGED
@@ -4349,15 +4349,24 @@ var DesignRequest = class {
4349
4349
  }
4350
4350
  }
4351
4351
  async getOptions(imageCount) {
4352
- const options = designOptionsSchema.parse(snakeCaseObjectKeysToCamelCase(
4353
- await this.client.engineAPI.designOptions.retrieve(
4354
- this.bookSize,
4355
- imageCount || this.images.length,
4356
- this.imageFilteringLevel
4352
+ const options = designOptionsSchema.parse(
4353
+ snakeCaseObjectKeysToCamelCase(
4354
+ await this.client.engineAPI.designOptions.retrieve(
4355
+ this.bookSize,
4356
+ imageCount || this.images.length,
4357
+ this.imageFilteringLevel
4358
+ )
4357
4359
  )
4358
- ));
4360
+ );
4359
4361
  return options;
4360
4362
  }
4363
+ async getAlternateLayouts(pageNumber) {
4364
+ if (this.state === "ready") {
4365
+ return await this.client.engineAPI.spreads.layouts(this.parentId, pageNumber);
4366
+ } else {
4367
+ throw new Error("Design request not ready");
4368
+ }
4369
+ }
4361
4370
  async submit(submitDesignRequestProps) {
4362
4371
  if (!canSubmitDesignRequest(this.state)) {
4363
4372
  throw new Error("You need to wait for the current design request to be ready before submitting a new one");
@@ -4365,9 +4374,7 @@ var DesignRequest = class {
4365
4374
  submitDesignRequestProps && this.updateDesignRequest(submitDesignRequestProps);
4366
4375
  this.webSocket = new WebSocket(`${this.client.webSocketHost}/?book_id=${this.parentId}`);
4367
4376
  await this.client.engineAPI.books.update(this.parentId, this.toBook());
4368
- this.updateDesignRequest(
4369
- (await this.client.engineAPI.books.design(this.parentId)).toDesignRequestProps()
4370
- );
4377
+ this.updateDesignRequest((await this.client.engineAPI.books.design(this.parentId)).toDesignRequestProps());
4371
4378
  this.getProgress();
4372
4379
  return this;
4373
4380
  }
@@ -4882,6 +4889,21 @@ var SpreadsEndpoints = class {
4882
4889
  });
4883
4890
  });
4884
4891
  }
4892
+ layouts(bookId, page) {
4893
+ return handleAsyncFunction(async () => {
4894
+ const res = await this.engineAPI.fetcher.call({
4895
+ path: "/v1/spreads/layouts",
4896
+ options: {
4897
+ method: "POST",
4898
+ body: cleanJSON({
4899
+ user_id: bookId,
4900
+ page_num: page
4901
+ })
4902
+ }
4903
+ });
4904
+ return z.array(canvasSchema).parse(res);
4905
+ });
4906
+ }
4885
4907
  };
4886
4908
 
4887
4909
  // ../../core/models/storyboard-item.ts