@magiclabs.ai/magicbook-client 0.2.0 → 0.2.1
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 +101 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
|
|
2
|
+
  [](https://www.npmjs.com/package/@magiclabs.ai/magicbook-client)
|
|
3
|
+
|
|
4
|
+
# magicbook-client
|
|
5
|
+
|
|
6
|
+
TypeScript package to create photo books with the Magicbook API.
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm install @magiclabs.ai/magicbook-client
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Usage
|
|
15
|
+
|
|
16
|
+
Create a Magicbook API client instance with your API key.
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
const client = new MagicBookClient('api-key')`
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Initiate the creation of a photo book by creating a design request. The design request can be initialized by passing parameters (design choices) to the initialization object.
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
const designRequest = await client.createDesignRequest({
|
|
26
|
+
title: 'Australia 2023',
|
|
27
|
+
occasion: 'travel',
|
|
28
|
+
style: '1234',
|
|
29
|
+
bookFormat: '8x8',
|
|
30
|
+
coverType: 'HC',
|
|
31
|
+
pageType: 'LF'
|
|
32
|
+
})
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Individual parameters can also be set directly on the design request instance:
|
|
36
|
+
|
|
37
|
+
```ts
|
|
38
|
+
const designRequest = await client.createDesignRequest()
|
|
39
|
+
designRequest.title = 'Australia 2023',
|
|
40
|
+
designRequest.occasion = 'travel',
|
|
41
|
+
designRequest.style = '1234',
|
|
42
|
+
designRequest.bookFormat = '8x8',
|
|
43
|
+
designRequest.coverType = 'HC',
|
|
44
|
+
designRequest.pageType = 'LF'
|
|
45
|
+
```
|
|
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.
|
|
48
|
+
|
|
49
|
+
```ts
|
|
50
|
+
import {Image} from '@magiclabs.ai/magicbook-client'
|
|
51
|
+
|
|
52
|
+
const image: Image = {...}
|
|
53
|
+
await designRequest.images.add(image)
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
This would typically be done in an event handler connected to the image manager.
|
|
57
|
+
|
|
58
|
+
```ts
|
|
59
|
+
window.addEventListener('ImageManager.ImageUploaded', async (item) => {
|
|
60
|
+
const image: Image = {...}
|
|
61
|
+
await designRequest.images.add(image)
|
|
62
|
+
})
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Before submitting the design request to Magicbook, register a callback to receive update events.
|
|
66
|
+
|
|
67
|
+
```ts
|
|
68
|
+
window.addEventListener('Magicbook.designRequestUpdated', async ((designRequestEvent: DesignRequestEvent) => {
|
|
69
|
+
console.log(designRequestEvent.detail)
|
|
70
|
+
}) as EventListener)
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Submit the design request. Again, the argument object can receive additional or updated design parameters.
|
|
74
|
+
|
|
75
|
+
```ts
|
|
76
|
+
designRequest.submit({
|
|
77
|
+
imageDensity: 'high',
|
|
78
|
+
embellishmentLevel: 'few',
|
|
79
|
+
textStickerLevel: 'none'
|
|
80
|
+
})
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Finally, once the design request is complete, retrieve it in JSON format.
|
|
84
|
+
|
|
85
|
+
```ts
|
|
86
|
+
await designRequest.getJSON()
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
___
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
## Example
|
|
93
|
+
|
|
94
|
+
To see the Magicbook client in action, run the following commands after navigating to the `./example` directory:
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
npm run build
|
|
98
|
+
cd example
|
|
99
|
+
npm i
|
|
100
|
+
npm run dev
|
|
101
|
+
```
|
package/package.json
CHANGED