0.7.6 • Published 2 months ago

@magiclabs.ai/magicbook-client v0.7.6

Weekly downloads
-
License
-
Repository
github
Last release
2 months ago

GitHub CI npm version

magicbook-client

TypeScript package to create photo books with the Magicbook API.

Installation

npm install @magiclabs.ai/magicbook-client

Usage

Create a Magicbook API client instance with your API key.

const client = new MagicBookClient('api-key')`

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.

const designRequest = await client.createDesignRequest({
  userId: 'd72f1bbc-80c1-4338-987d-ca3eff058305' // Required value
  title: 'Australia 2023',
  occasion: 'travel',
  style: '1234',
  bookSize: '8x8',
  coverType: 'hc',
  pageType: 'sp'
})

Individual parameters can also be set directly on the design request instance (except for userId):

const designRequest = await client.createDesignRequest()
;(designRequest.title = 'Australia 2023'),
  (designRequest.occasion = 'travel'),
  (designRequest.style = '1234'),
  (designRequest.bookSize = '8x8'),
  (designRequest.coverType = 'hc'),
  (designRequest.pageType = 'sp')

As images are getting ready to be handed over to Magicbook, for example when successfully uploaded, add them to the design request object.

import {Image} from '@magiclabs.ai/magicbook-client'

const image: Image = {...}
await designRequest.images.add(image)

This would typically be done in an event handler connected to the image manager.

window.addEventListener('ImageManager.ImageUploaded', async (item) => {
  const image: DesignRequestImage = {...}
  await designRequest.images.add(image)
})

Optionally, you can retrieve design options for the design request by calling the getOptions method, providing the total number of images selected by the user. The returned object contains the image densities (i.e. page count and image per page estimations)

const selectedImageCount = 200
...
const designOptions = designRequest.getOptions(selectedImageCount)

Before submitting the design request to Magicbook, register a callback to receive update events.

window.addEventListener(
  'Magicbook.designRequestUpdated',
  async((designRequestEvent: DesignRequestEvent) => {
    console.log(designRequestEvent.detail)
  }) as EventListener
)

Submit the design request. Again, the argument object can receive additional or updated design parameters. You can submit multiple design requests by calling this function after receiving the "ready" event from the previous one.

await designRequest.submit({
  imageDensity: 'high',
  imageFilteringLevel: 'best',
  embellishmentLevel: 'few',
  textStickerLevel: 'none'
})

After submitting you can set a GUID to the design request.

await designRequest.setGuid('a9ccb406-015a-47df-bb59-ea171b8617ca')

Once the design request is complete, retrieve it in JSON format.

await designRequest.getJSON()

You can get alternate layouts for a specific page.

await designRequest.getAlternateLayouts(-1)

When a user performs a specific action, log it by calling the logEvent method.

await designRequest.logEvent('book.viewed', data)

Example

To see the Magicbook client in action, run the following commands (make sure you created a .env file before building):

npm run build
cd example
npm i
npm run dev
0.7.6

2 months ago

0.7.6-canary

2 months ago

0.7.5

2 months ago

0.7.5-canary.1

5 months ago

0.7.5-canary.0

5 months ago

0.6.7

8 months ago

0.6.6

8 months ago

0.6.13-canary

8 months ago

0.6.9

8 months ago

0.6.8

8 months ago

0.6.6-canary

8 months ago

0.6.8-canary

8 months ago

0.6.10

8 months ago

0.6.12

8 months ago

0.6.11

8 months ago

0.6.8-canary.1

8 months ago

0.6.14

7 months ago

0.6.13

8 months ago

0.7.2

6 months ago

0.7.1

7 months ago

0.7.4

6 months ago

0.7.3

6 months ago

0.7.0

7 months ago

0.6.12-canary

8 months ago

0.6.14-canary

7 months ago

0.6.5-canary

9 months ago

0.6.7-canary

8 months ago

0.7.2-canary

6 months ago

0.7.1-canary

7 months ago

0.0.0

8 months ago

0.7.4-canary

6 months ago

0.6.3

9 months ago

0.6.2

9 months ago

0.6.1

10 months ago

0.6.0

11 months ago

0.5.6

11 months ago

0.5.5

11 months ago

0.5.2

11 months ago

0.5.1

12 months ago

0.5.0

12 months ago

0.5.0-dev

12 months ago

0.4.9-dev

12 months ago

0.4.8

12 months ago

0.4.8-dev

12 months ago

0.4.2

12 months ago

0.4.7-dev

12 months ago

0.4.2-dev

1 year ago

0.4.1-dev

1 year ago

0.4.1

1 year ago

0.4.0

1 year ago

0.3.3

1 year ago

0.3.2

1 year ago

0.3.1

1 year ago

0.3.0

1 year ago

0.2.1

1 year ago

0.2.0

1 year ago

0.1.9

1 year ago

0.1.8

1 year ago

0.1.7

1 year ago