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

@iadvize-oss/boxed-tag

v1.4.4

Published

Boxed iAdvize tag

Downloads

46

Readme

Boxed tag

The “iAdvize Boxed Tag” is a way to include the iAdvize Tag in the most secure way, without it having access to the client’s website.

With this solution, the iAdvize tag can be loaded in an isolated box (a sandboxed iframe). This way, the main page context cannot be accessed by the iAdvize tag: the main page only sends controlled, relevant data to the boxed tag.

Simple installation

This is the simplest way too add the iAdvize Boxed Tag to a website with the default configuration.

1 - Serve this HTML file

Serve a HTML file. We will use the name iadvize-boxed-iframe.html, but any name can be chosen. This file needs to be served on the same top domain as the page it will be included in. Replace <your-sid> with your own sid.

Ex :

  • Web page : https://hostpage.brand-domain.com
  • Iframe : https://static.brand-domain.com/iadvize-boxed-iframe.html
<!DOCTYPE html>
<html>
  <body>
   <script src="https://static.iadvize.com/boxed-tag/1.4.4/index.js" integrity="sha512-NS7M2FyNHaefJ42ilas6W+t/qJleeGTWIyhM2pj2Pn+t7PgWRH/HarBqV8HT+RFDi6JVS1ReAeF2Afz5dwpBjQ==" crossorigin="anonymous"></script>
    <script>
      window.iAdvizeBoxedTag.initIAdvizeIframe(<your-sid>, "halc");
    </script>
  </body>
</html>

2 - Add the following script

Add the following script (in your frontend code, or in your tag manager), replacing https://static.brand-domain.com/iadvize-boxed-iframe.html with the actual URL of the iframe :

// Change this URL with the actual URL of the iframe
const iAdvizeIframeUrl = "https://static.brand-domain.com/iadvize-boxed-iframe.html";

const style = document.createElement("style");
style.innerHTML = `
  #iAdvizeSandboxedIframe {
    border: none;
    position: fixed;
    bottom: 0;
    right: 0;
    width: 100vw;
    height: 100vh;
    pointer-events: none;
    z-index: 2147483647;
  }
`;
document.body.append(style);

const boxedTagScript = document.createElement("script");
boxedTagScript.src =
  "https://static.iadvize.com/boxed-tag/1.4.4/index.js";
boxedTagScript.integrity =
"sha512-NS7M2FyNHaefJ42ilas6W+t/qJleeGTWIyhM2pj2Pn+t7PgWRH/HarBqV8HT+RFDi6JVS1ReAeF2Afz5dwpBjQ==";
boxedTagScript.crossOrigin = "anonymous";

const iAdvizeSandboxedIframe = document.createElement("iframe");
iAdvizeSandboxedIframe.sandbox = "allow-scripts allow-same-origin allow-popups allow-forms";
iAdvizeSandboxedIframe.allow = "camera;microphone;autoplay";
iAdvizeSandboxedIframe.src = iAdvizeIframeUrl;
iAdvizeSandboxedIframe.id = "iAdvizeSandboxedIframe";
document.body.append(iAdvizeSandboxedIframe);

boxedTagScript.onload = function () {
  window.iAdvizeBoxedTag.initIAdvizeHost("iAdvizeSandboxedIframe");
};

document.body.append(boxedTagScript);

Advanced installation

This is a more advanced installation, allowing :

  • a custom configuration,
  • the use of WebSDK methods (see https://developers.iadvize.com/documentation/javascript-web-sdk#javascript-web-sdk).

Install the lib on your project

npm install @iadvize-oss/boxed-tag

Create the iframe script

Create a js file that will import the iframe script. Then call initIAdvizeIframe to listen the host messages. The initIAdvizeIframe comes with 2 arguments :

  • sid : your iAdvize sid.
  • iAdvizePlatform : the iadvize platform (default: ha).
import { initIAdvizeIframe } from '@iadvize-oss/boxed-tag';

initIAdvizeIframe(<sid>, <iAdvizePlatform>);

Add a boxed iframe

Add a boxed iframe on your site's main page.

<iframe
  title="iAdvize chat notification frame"
  sandbox="allow-scripts allow-same-origin allow-popups allow-forms"
  allow="camera;microphone;autoplay"
  src="https://my-iframe-script-url"
  id="myIframeId"
></iframe>

The iframe is set with the following sandbox parameters: | sandbox param | description | |-------------------|----------------------------------------------------------------| | allow-scripts | Allows the page to run iAdvize tag script. | | allow-same-origin | Allows the iAdvize tag to access the host cookies and storages | | allow-popups | Allows the iAdvize tag to open links sent by the agent | | allow-forms | Allows the iAdvize tag to submit the visitor email if needed |

And the following allow parameters: | allow param | description | |-------------------|-------------------------------------------------------------------------| | camera | Allows the boxed tag to ask the camera permission (for video calls) | | microphone | Allows the boxed tag to ask the microphone permission (for video calls) | | autoplay | Allows the boxed tag to launch the video stream automatically |

Add the host script on your site's main page

Create a js file with the host lib import, then call initIAdvizeHost to listen to the iframe messages.

import { initIAdvizeHost } from '@iadvize-oss/boxed-tag';

initIAdvizeHost('myIframeId');

Communication

The only way to start a communication between the host and the sandboxed iframe is the window.postMessage method provided by the navigators (see https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage).

warning The postMessage data is serialized, so functions cannot be sent (see https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage#parameters).

Then, the target of the postMessage calls can listen to the events using window.addEventListener('message').

warning The source of the event should be checked to avoid conflicts and security concerns (see https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage#security_concerns).

Call iAdvize WebSDK methods from host

WebSDK methods cannot be called from the host context because the iAdvize tag is isolated in the iframe : we need to communicate to the iframe what we want to call.

After having called initIAdvizeHost, a iAdvizeBoxedInterface object is available in the host window context.
This object sends the method name and args to the iframe, that will call the webSDK. The activate, get and on methods can return a value to the host :
to retrieve it, add a window.addEventListener("message") and check the e.data.method property to recognize the method called.

Navigate

// WebSDK navigate
window.iAdvizeBoxedInterface.push({
  method: 'navigate',
  args: [window.location.href],
});

Activate

The host can listen to the result of the activate call.

For an anonymous authentication:

// WebSDK activate anonymous
window.iAdvizeBoxedInterface.push({
  method: 'activate',
  args: {
    authenticationOption: { type: 'ANONYMOUS' },
  },
});

// Listen to activate result
window.addEventListener('message', ({ data: { method, activation } }) => {
  if (method === 'activate') {
    console.log(activation); // activation return object : success or failure
  }
});

For a secured authentication, the JWE token should be generated on the host side and sent to the iframe :

  • the host should listen a get-activate-auth-token message initiated by the iframe.
  • the backend api then gets the JWE token,
  • the token is then sent to the iframe inside a set-activate-auth-token message.

The get-activate-auth-token listener allows the iframe to ask for a token refresh if needed.

Example of secured authentication implementation:

// WebSDK activate secured auth
const getJweToken = Promise.resolve('myJWEToken');// your backend logic to generate a JWE

window.iAdvizeBoxedInterface.push({
  method: 'activate',
  args: {
    authenticationOption: {
      type: 'SECURED_AUTHENTICATION',
    },
  },
});

// Listen to activate result
window.addEventListener('message', ({ data: { method, activation } }) => {
  // Handle authentication token
  if (method === 'get-activate-auth-token') {
    getJweToken().then((token) =>
      window.iAdvizeBoxedInterface.push({
        method: 'set-activate-auth-token',
        args: `${token}`,
      }),
    );
  }
  if (method === 'activate') {
    console.log(activation); // activation return object : success or failure
  }
});

Logout

The host can listen to the result of the logout call.

Example of implementation:

// WebSDK logout
window.iAdvizeBoxedInterface.push({
  method: 'logout',
});

// Listen to logout
window.addEventListener('message', ({ data: { method } }) => {
  if (method === 'logout') {
    // Do something after logout
  }
});

On

The host can listen to the result of the on call.

Example of implementation:

// WebSDK on
window.iAdvizeBoxedInterface.push({
  method: 'on',
  args: ['visitor:cookiesConsentChanged'],
});

// Listen to cookiesConsentChanged result
window.addEventListener('message', ({ data: { method, args, value } }) => {
  if (method === 'on' && args.includes('visitor:cookiesConsentChanged')) {
    console.log(value); // cookiesConsentChanged value
  }
});

Off

// WebSDK off
window.iAdvizeBoxedInterface.push({
  method: 'off',
  args: ['visitor:cookiesConsentChanged'],
});

Set

// WebSDK set
window.iAdvizeBoxedInterface.push({
  method: 'set',
  args: ['visitor:GDPRConsent', true],
});

Get

The host can listen to the result of the get call.

Example of implementation:

// WebSDK get
window.iAdvizeBoxedInterface.push({
  method: 'get',
  args: ['visitor:cookiesConsent'],
});

// Listen to cookiesConsent get
window.addEventListener('message', ({ data: { method, args, value } }) => {
  if (method === 'get' && args.includes('visitor:cookiesConsent')) {
    console.log(value); // cookiesConsent value
  }
});