@magiclabs.ai/magicbook-client 0.7.8-canary → 0.7.10-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
@@ -2,7 +2,7 @@
2
2
 
3
3
  # magicbook-client
4
4
 
5
- TypeScript package to create photo books with the Magicbook API.
5
+ TypeScript package to create photo books with the MagicBook API.
6
6
 
7
7
  ## Installation
8
8
 
@@ -12,7 +12,7 @@ npm install @magiclabs.ai/magicbook-client
12
12
 
13
13
  ## Usage
14
14
 
15
- Create a Magicbook API client instance with your API key.
15
+ Create a MagicBook API client instance with your API key.
16
16
 
17
17
  ```ts
18
18
  const client = new MagicBookClient('api-key')`
@@ -44,7 +44,7 @@ const designRequest = await client.createDesignRequest()
44
44
  (designRequest.pageType = 'sp')
45
45
  ```
46
46
 
47
- As images are getting ready to be handed over to Magicbook, for example when successfully uploaded, add them to the design request object.
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
50
50
  import {Image} from '@magiclabs.ai/magicbook-client'
@@ -70,11 +70,11 @@ const selectedImageCount = 200
70
70
  const designOptions = designRequest.getOptions(selectedImageCount)
71
71
  ```
72
72
 
73
- Before submitting the design request to Magicbook, register a callback to receive update events.
73
+ Before submitting the design request to MagicBook, register a callback to receive update events.
74
74
 
75
75
  ```ts
76
76
  window.addEventListener(
77
- 'Magicbook.designRequestUpdated',
77
+ 'MagicBook.designRequestUpdated',
78
78
  async((designRequestEvent: DesignRequestEvent) => {
79
79
  console.log(designRequestEvent.detail)
80
80
  }) as EventListener
@@ -106,10 +106,10 @@ Once the design request is complete, retrieve it in JSON format.
106
106
  await designRequest.getJSON(format)
107
107
  ```
108
108
 
109
- You can get alternate layouts for a specific page.
109
+ You can get alternate layouts for a specific page. Optionally, you can pass surfaceCategoryName if your style supports it (only Snapfish).
110
110
 
111
111
  ```ts
112
- await designRequest.getAlternateLayouts(-1)
112
+ await designRequest.getAlternateLayouts(-1, 'cover' | 'inside')
113
113
  ```
114
114
 
115
115
  When a user performs a specific action, log it by calling the `logEvent` method.
@@ -120,9 +120,28 @@ await designRequest.logEvent('book.viewed', data)
120
120
 
121
121
  ---
122
122
 
123
+ ## Usage as script
124
+
125
+ ```html
126
+ <!doctype html>
127
+ <html>
128
+ <head>
129
+ <script
130
+ type="text/javascript"
131
+ src="../node_modules/@magiclabs-ai/magicbook-client
132
+ /index.iife.js"
133
+ ></script>
134
+ </head>
135
+ <script type="text/javascript">
136
+ const client = new MagicLabs.MagicBookClient('api-key')
137
+ ...
138
+ </script>
139
+ </html>
140
+ ```
141
+
123
142
  ## Example
124
143
 
125
- To see the Magicbook client in action, run the following commands (make sure you created a `.env` file before building):
144
+ To see the MagicBook client in action, run the following commands (make sure you created a `.env` file before building):
126
145
 
127
146
  ```bash
128
147
  npm run build
package/index.cjs CHANGED
@@ -34,7 +34,6 @@ __export(src_exports, {
34
34
  bookSizes: () => bookSizes,
35
35
  canSubmitDesignRequest: () => canSubmitDesignRequest,
36
36
  cancelledEventDetail: () => cancelledEventDetail,
37
- canvasSchema: () => canvasSchema,
38
37
  coverTypes: () => coverTypes,
39
38
  designOptionsSchema: () => designOptionsSchema,
40
39
  designOptionsServerSchema: () => designOptionsServerSchema,
@@ -59,10 +58,13 @@ __export(src_exports, {
59
58
  positionSchema: () => positionSchema,
60
59
  propertySchema: () => propertySchema,
61
60
  reportingDataSchema: () => reportingDataSchema,
61
+ sflyCanvasSchema: () => sflyCanvasSchema,
62
+ snapCanvasSchema: () => snapCanvasSchema,
62
63
  states: () => states,
63
64
  statesToCloseWS: () => statesToCloseWS,
64
65
  statesToReport: () => statesToReport,
65
66
  styles: () => styles,
67
+ surfaceCategoryNames: () => surfaceCategoryNames,
66
68
  textStickerLevels: () => textStickerLevels,
67
69
  timeoutEventDetail: () => timeoutEventDetail
68
70
  });
@@ -387,16 +389,7 @@ var styles = {
387
389
  "03f332e3b2b947ebae73b67a9a22b6f4": { slug: "winter-sparkle-snap" },
388
390
  "97f70f6cdb5244a08d45772cccfa2788": { slug: "year-of-memories-snap" }
389
391
  };
390
- var bookSizes = [
391
- "5x7",
392
- "6x6",
393
- "8x8",
394
- "10x10",
395
- "12x12",
396
- "8x11",
397
- "11x8",
398
- "11x14"
399
- ];
392
+ var bookSizes = ["5x7", "6x6", "8x8", "10x10", "12x12", "8x11", "11x8", "11x14"];
400
393
  var coverTypes = ["sc", "hc", "pl"];
401
394
  var pageTypes = ["sp", "sl", "dl"];
402
395
  var imageDensities = ["low", "medium", "high"];
@@ -416,6 +409,7 @@ var cancelledEventDetail = {
416
409
  message: "Design canceled"
417
410
  };
418
411
  var formats = ["galleon", "snapfish"];
412
+ var surfaceCategoryNames = ["inside", "cover"];
419
413
 
420
414
  // ../../core/utils/toolbox.ts
421
415
  function mergeNestedObject(obj, objToMerge) {
@@ -4672,9 +4666,9 @@ var DesignRequest = class {
4672
4666
  );
4673
4667
  return options;
4674
4668
  }
4675
- async getAlternateLayouts(pageNumber) {
4669
+ async getAlternateLayouts(pageNumber, surfaceCategoryName) {
4676
4670
  if (this.state === "ready") {
4677
- return await this.client.engineAPI.spreads.layouts(this.parentId, pageNumber);
4671
+ return await this.client.engineAPI.spreads.layouts(this.parentId, pageNumber, surfaceCategoryName);
4678
4672
  } else {
4679
4673
  throw new Error("Design request not ready");
4680
4674
  }
@@ -4789,85 +4783,6 @@ var DesignRequest = class {
4789
4783
  }
4790
4784
  };
4791
4785
 
4792
- // ../../core/models/galleon.ts
4793
- var imageAssignmentSchema = z.object({
4794
- photoRefId: z.string(),
4795
- finalCrop: z.array(z.number())
4796
- });
4797
- var positionSchema = z.object({
4798
- x: z.number(),
4799
- y: z.number(),
4800
- width: z.number().optional(),
4801
- height: z.number().optional(),
4802
- rotation: z.number()
4803
- });
4804
- var photoMetadataSchema = z.object({
4805
- id: z.string(),
4806
- llx: z.number(),
4807
- lly: z.number(),
4808
- urx: z.number(),
4809
- ury: z.number(),
4810
- data: z.string().nullable(),
4811
- title: z.string(),
4812
- width: z.number(),
4813
- effect: z.string(),
4814
- height: z.number(),
4815
- source: z.string(),
4816
- rotation: z.number(),
4817
- uploadTime: z.string()
4818
- });
4819
- var propertySchema = z.object({
4820
- key: z.string(),
4821
- value: z.any()
4822
- });
4823
- var assetSchema = z.object({
4824
- type: z.string(),
4825
- imageAssignment: imageAssignmentSchema.optional(),
4826
- position: positionSchema,
4827
- seqNum: z.number(),
4828
- z: z.number(),
4829
- id: z.string().optional(),
4830
- horizJustification: z.string().optional(),
4831
- vertJustification: z.string().optional().nullable(),
4832
- text: z.string().optional(),
4833
- fontId: z.string().optional(),
4834
- fontSize: z.number().optional(),
4835
- fontColor: z.string().optional(),
4836
- frame: z.string().optional()
4837
- });
4838
- var photoStripSchema = z.object({
4839
- url: z.string(),
4840
- encryptId: z.string(),
4841
- photoRefId: z.string(),
4842
- photoId: z.string(),
4843
- photoMetadata: photoMetadataSchema
4844
- });
4845
- var reportingDataSchema = z.object({
4846
- properties: z.array(propertySchema)
4847
- });
4848
- var canvasSchema = z.object({
4849
- backgroundId: z.string().nullable(),
4850
- assets: z.array(assetSchema).optional()
4851
- });
4852
- var pageSchema = z.object({
4853
- pageNum: z.number(),
4854
- type: z.string(),
4855
- canvas: canvasSchema
4856
- });
4857
- var magicShopBookSchema = z.object({
4858
- pages: z.array(pageSchema),
4859
- photoStrip: z.array(photoStripSchema)
4860
- });
4861
- var bookCreationRequestSchema = z.object({
4862
- title: z.string(),
4863
- binding: z.string(),
4864
- coverSpecId: z.string(),
4865
- styleId: z.number(),
4866
- userId: z.string(),
4867
- magicShopBook: magicShopBookSchema,
4868
- reportingData: reportingDataSchema
4869
- });
4870
-
4871
4786
  // ../../core/models/engine-api/endpoints/books.ts
4872
4787
  var BooksEndpoints = class {
4873
4788
  // eslint-disable-next-line no-unused-vars
@@ -4952,7 +4867,7 @@ var BooksEndpoints = class {
4952
4867
  const res = await this.engineAPI.fetcher.call({
4953
4868
  path: `/v1/books/${bookId}/format/${format}`
4954
4869
  });
4955
- return bookCreationRequestSchema.parse(res);
4870
+ return res;
4956
4871
  });
4957
4872
  }
4958
4873
  };
@@ -5145,6 +5060,90 @@ var spreadSchema = z.object({
5145
5060
  url: z.string().nullable().optional()
5146
5061
  });
5147
5062
 
5063
+ // ../../core/models/galleon.ts
5064
+ var imageAssignmentSchema = z.object({
5065
+ photoRefId: z.string(),
5066
+ finalCrop: z.array(z.number())
5067
+ });
5068
+ var positionSchema = z.object({
5069
+ x: z.number(),
5070
+ y: z.number(),
5071
+ width: z.number().optional(),
5072
+ height: z.number().optional(),
5073
+ rotation: z.number()
5074
+ });
5075
+ var photoMetadataSchema = z.object({
5076
+ id: z.string(),
5077
+ llx: z.number(),
5078
+ lly: z.number(),
5079
+ urx: z.number(),
5080
+ ury: z.number(),
5081
+ data: z.string().nullable(),
5082
+ title: z.string(),
5083
+ width: z.number(),
5084
+ effect: z.string(),
5085
+ height: z.number(),
5086
+ source: z.string(),
5087
+ rotation: z.number(),
5088
+ uploadTime: z.string()
5089
+ });
5090
+ var propertySchema = z.object({
5091
+ key: z.string(),
5092
+ value: z.any()
5093
+ });
5094
+ var assetSchema = z.object({
5095
+ type: z.string(),
5096
+ imageAssignment: imageAssignmentSchema.optional(),
5097
+ position: positionSchema,
5098
+ seqNum: z.number(),
5099
+ z: z.number(),
5100
+ id: z.string().optional(),
5101
+ horizJustification: z.string().optional(),
5102
+ vertJustification: z.string().optional().nullable(),
5103
+ text: z.string().optional(),
5104
+ fontId: z.string().optional(),
5105
+ fontSize: z.number().optional(),
5106
+ fontColor: z.string().optional(),
5107
+ frame: z.string().optional()
5108
+ });
5109
+ var photoStripSchema = z.object({
5110
+ url: z.string(),
5111
+ encryptId: z.string(),
5112
+ photoRefId: z.string(),
5113
+ photoId: z.string(),
5114
+ photoMetadata: photoMetadataSchema
5115
+ });
5116
+ var reportingDataSchema = z.object({
5117
+ properties: z.array(propertySchema)
5118
+ });
5119
+ var sflyCanvasSchema = z.object({
5120
+ backgroundId: z.string().nullable(),
5121
+ assets: z.array(assetSchema).optional()
5122
+ });
5123
+ var snapCanvasSchema = z.object({
5124
+ surfaceNumber: z.number(),
5125
+ surfaceData: z.record(z.any()),
5126
+ version: z.string()
5127
+ });
5128
+ var pageSchema = z.object({
5129
+ pageNum: z.number(),
5130
+ type: z.string(),
5131
+ canvas: sflyCanvasSchema
5132
+ });
5133
+ var magicShopBookSchema = z.object({
5134
+ pages: z.array(pageSchema),
5135
+ photoStrip: z.array(photoStripSchema)
5136
+ });
5137
+ var bookCreationRequestSchema = z.object({
5138
+ title: z.string(),
5139
+ binding: z.string(),
5140
+ coverSpecId: z.string(),
5141
+ styleId: z.number(),
5142
+ userId: z.string(),
5143
+ magicShopBook: magicShopBookSchema,
5144
+ reportingData: reportingDataSchema
5145
+ });
5146
+
5148
5147
  // ../../core/models/engine-api/endpoints/spreads.ts
5149
5148
  var SpreadsEndpoints = class {
5150
5149
  // eslint-disable-next-line no-unused-vars
@@ -5202,7 +5201,7 @@ var SpreadsEndpoints = class {
5202
5201
  });
5203
5202
  });
5204
5203
  }
5205
- layouts(bookId, page) {
5204
+ layouts(bookId, page, surfaceCategoryName) {
5206
5205
  return handleAsyncFunction(async () => {
5207
5206
  const res = await this.engineAPI.fetcher.call({
5208
5207
  path: "/v1/spreads/layouts",
@@ -5210,11 +5209,12 @@ var SpreadsEndpoints = class {
5210
5209
  method: "POST",
5211
5210
  body: cleanJSON({
5212
5211
  user_id: bookId,
5213
- page_num: page
5212
+ page_num: page,
5213
+ surfaceCategoryName
5214
5214
  })
5215
5215
  }
5216
5216
  });
5217
- return z.array(canvasSchema).parse(res);
5217
+ return z.array(surfaceCategoryName ? snapCanvasSchema : sflyCanvasSchema).parse(res);
5218
5218
  });
5219
5219
  }
5220
5220
  };
@@ -5387,7 +5387,6 @@ var MagicBookClient = class {
5387
5387
  bookSizes,
5388
5388
  canSubmitDesignRequest,
5389
5389
  cancelledEventDetail,
5390
- canvasSchema,
5391
5390
  coverTypes,
5392
5391
  designOptionsSchema,
5393
5392
  designOptionsServerSchema,
@@ -5412,10 +5411,13 @@ var MagicBookClient = class {
5412
5411
  positionSchema,
5413
5412
  propertySchema,
5414
5413
  reportingDataSchema,
5414
+ sflyCanvasSchema,
5415
+ snapCanvasSchema,
5415
5416
  states,
5416
5417
  statesToCloseWS,
5417
5418
  statesToReport,
5418
5419
  styles,
5420
+ surfaceCategoryNames,
5419
5421
  textStickerLevels,
5420
5422
  timeoutEventDetail
5421
5423
  });