npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@magiclabs.ai/magicbook-client

v0.7.6

Published

TypeScript package to create photo books with the Magicbook API.

Downloads

115

Readme

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