@magiclabs.ai/magicbook-client 0.7.9-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 +27 -8
- package/index.cjs +21 -19
- package/index.cjs.map +1 -1
- package/index.d.cts +31 -7
- package/index.d.ts +31 -7
- package/index.iife.js +5333 -0
- package/index.js +18 -18
- package/index.js.map +1 -1
- package/package.json +2 -2
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
|
|
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
|
|
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
|
|
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
|
|
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
|
-
'
|
|
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
|
|
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
|
}
|
|
@@ -5122,14 +5116,19 @@ var photoStripSchema = z.object({
|
|
|
5122
5116
|
var reportingDataSchema = z.object({
|
|
5123
5117
|
properties: z.array(propertySchema)
|
|
5124
5118
|
});
|
|
5125
|
-
var
|
|
5119
|
+
var sflyCanvasSchema = z.object({
|
|
5126
5120
|
backgroundId: z.string().nullable(),
|
|
5127
5121
|
assets: z.array(assetSchema).optional()
|
|
5128
5122
|
});
|
|
5123
|
+
var snapCanvasSchema = z.object({
|
|
5124
|
+
surfaceNumber: z.number(),
|
|
5125
|
+
surfaceData: z.record(z.any()),
|
|
5126
|
+
version: z.string()
|
|
5127
|
+
});
|
|
5129
5128
|
var pageSchema = z.object({
|
|
5130
5129
|
pageNum: z.number(),
|
|
5131
5130
|
type: z.string(),
|
|
5132
|
-
canvas:
|
|
5131
|
+
canvas: sflyCanvasSchema
|
|
5133
5132
|
});
|
|
5134
5133
|
var magicShopBookSchema = z.object({
|
|
5135
5134
|
pages: z.array(pageSchema),
|
|
@@ -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(
|
|
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
|
});
|