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

@applica-software-guru/3magic-web-plugin

v1.0.7

Published

This plugin provides a way to integrate 3Magic's configurator in third party web applications.

Downloads

22

Readme

Three Magic Web Plugin

This plugin provides a way to integrate 3Magic's configurator in third party web applications.

Installation

To install this plugin using npm, run the following command in your terminal:

npm install @applica-software-guru/3magic-web-plugin

Usage

First, import ThreeMagicWebPlugin and create a new instance with the correct initialization options, structured as follows:

  • apiKey (string): API key authentication string. Required.
  • baseUrl (url string): The base URL where the 3Magic installation is running. This URL is used as the root endpoint for all API requests and interactions with the 3Magic system. Required.
  • domElement (HTMLIFrameElement): The iFrame instance where 3Magic will be loaded. If not provided, a new one will be generated.
  • lang: Specifies the language in which the plugin will operate (e.g., "en", "fr", etc.). Required.
const instance = new ThreeMagicWebPlugin({
  apiKey: 'mySecretApiKey',
  baseUrl: 'http://3magic-instance.com',
  lang: 'en'
});

Then, init the plugin:

instance
  .init()
  .then(() => console.log('ThreeMagicWebPlugin intialized!'))
  .catch((e) => console.error(e));

Lastly, start the configurator by calling load with the correct loading options:

instance
  .load({
    mode: 'family',
    payload: '7d2f638fd40df90be7b79c65'
  })
  .then(() => console.log('ThreeMagicWebPlugin loaded!'))
  .catch((e) => console.error(e));

Full example

The following is a barebone complete usage example:

<!doctype html>
<style>
  html,
  body {
    margin: 0;
    height: 100%;
    overflow: hidden;
  }
  .wrapper {
    width: 100%;
    height: 100%;
  }
  .wrapper iframe {
    width: 100%;
    height: 100%;
    border: none;
  }
</style>
<script src="dist/bundle.umd.js"></script>
<script>
  window.onload = function () {
    const domElement = document.getElementById('iframe-instance'),
      instance = new threeMagicWebPlugin.ThreeMagicWebPlugin({
        apiKey: 'mySecretApiKey',
        baseUrl: 'myBaseUrl',
        domElement: domElement,
        lang: 'en'
      });
    instance.init().then(() =>
      instance.load({
        mode: threeMagicWebPlugin.ThreeMagicWebPluginLoadingModes.FAMILY,
        payload: '7d2f638fd40df90be7b79c65'
      })
    );
  };
</script>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>3Magic Web Plugin Example</title>
  </head>
  <body>
    <div class="wrapper">
      <iframe id="iframe-instance"></iframe>
    </div>
  </body>
</html>

Loading modes

There are three loading modes supported.

3Magic family

Requires a 3Magic family ID and initializes the configurator with an empty composition.

instance
  .load({
    mode: 'family',
    payload: '7d2f638fd40df90be7b79c65'
  })
  .then(() => console.log('ThreeMagicWebPlugin loaded!'))
  .catch((e) => console.error(e));

3Magic preset

Requires a 3Magic preset ID and initializes the configurator with the corresponding preset.

instance
  .load({
    mode: 'preset',
    payload: '8a4c739be51ef01ca8d84f76'
  })
  .then(() => console.log('ThreeMagicWebPlugin loaded!'))
  .catch((e) => console.error(e));

Custom loading options

Used for custom installations. Payload will differ depending on customer specific logics and flows.

instance
  .load({
    mode: 'custom',
    payload: {
      catalog: 'CAT01'
    }
  })
  .then(() => console.log('ThreeMagicWebPlugin loaded!'))
  .catch((e) => console.error(e));

Properties

domElement (HTMLIFrameElement)

Contains the iFrame element used to display the configurator.

error (boolean)

Indicates wether the configurator is in an error state or not.

initialized (boolean)

Indicates wether the plugin has been initialized or not. Required before the loading methods can be called.

Methods

dispose(): void

Disposes of the plugin and removes all associated listeners.

init(): Promise<void>

Initializes the plugin. Returns a promise that fulfills when the initialization is complete.

initSync(onSuccess?: () => void, onError?: () => void): void

Callback version of init. Can be passed optional onSuccess and onError callbacks, that will be called once the initialization completes or fails respectively. Note, the method will return as soon as the initialization process begins.

load(options: object): Promise<void>

Loads a family or preset. Requires an options object, structured as detailed in Loading modes.

Return a promise that fulfills when the loading is complete.

loadSync(options: object, onSuccess?: () => void, onError?: () => void): void

Callback version of load. Can be passed optional onSuccess and onError callbacks, that will be called once the initialization completes or fails respectively. Note, the method will return as soon as the loading process begins.

on(event: string, listener: Function): void

Registers a listener for the specified event. See Events for a list of available events. Upon event emission, all listeners will be passed the triggering event as first arguments, plus other optional arguments depending on the event type.

off(event: string, listener?: Function): void

Unregisters a listener for the specified event. If no listener function is passed, all listeners for the provided event will be removed. See Events for a list of available events.

Events

The plugin exposes several events that can be subscribed to using the on method. These are usually utilized to intercept events that are not a consequence of direct programmatic calls to the plugin instance (e.g. an error during configurator usage). However, regular events for programmatic actions are also provided for event based programming approaches.

error

Is invoked whenever the plugin or the instanced configurator trigger an error. Each listener is passed the error object or cause.

authorizing

Invoked when the plugin commences the authorization process.

authorized

Invoked when the authorization process is successfully completed.

loading

Invoked when the plugin commences the loading process.

loaded

Invoked when the loading process is successfully completed.

custom

Used for custom installations. Each listener is passed an object containing a type string and a payload of varying type.