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

@go1/go1-embedding-js-sdk

v0.0.67

Published

A Javascript library to embed Go1 content into your website.

Downloads

278

Readme

Go1 Embedding JS SDK

A Javascript library to embed Go1 content into your website. Includes two-way messaging between your site and the Go1 content view.

This library is intended to be used with codebases that support CommonJS modules (e.g. esbuild, webpack, babel, and more.) If you are looking for a pure browser only implementation, please see our developer docs.

Installation

npm install @go1/go1-embedding-js-sdk

Usage

Prepare a <div> in your HTML that will be the parent to the Go1 iframe and be sure to give it an id. We'll use that id later.

<body>
  ...
  <div id="go1-chat-window" />
  ...
</body>

Run the go1Init function from this library to insert the Go1 content view as a child of the <div>.

import { go1Init } from '@go1/go1-embedding-js-sdk';

const onGo1MessageReceived = (message) => {
  console.log('Received postMessage from Go1');
  console.log(message);
};

const options = {
  feature: 'ai-chat',
  iframeParentId: 'go1-chat-window',
  onGo1MessageReceived,
};
const sendMessageToGo1 = go1Init(options); // will insert the iframe as a child of `<div id="go1-chat-window" />`, and return a function with which to send messages to the iframe.

APIs

Types

export type OnGo1MessageReceived = (message: Go1Message) => void;

export type SendMessageToGo1 = (message: Go1Message) => void;

export type IframesMap = { [key: string]: HTMLIFrameElement };

export interface AdditionalInfoMessage {
  additionalUserInfo?: AdditionalUserInfo;
  featureAttributes?: FeatureAttributes;
  themeInformation?: ThemeInformation;
}

export interface ThemeInformation {
  /** Hex string, starting with a #. Example #0437F2 */
  accent: string;
}

export type Go1MessageType =
  | 'preview_start_content'
  | 'preview_close'
  | 'preview_add_content_success'
  | 'preview_add_content_failure'
  | 'preview_remove_content_success'
  | 'preview_remove_content_failure'
  | 'parent_show_preview'
  | 'set_additional_embedding_data'
  | 'go1_app_initialised'
  | 'ott_required'
  | 'search_result_selected'
  | 'search_filter_toggle'
  | 'pass_ott'
  | 'logout',
  | 'sync_content'
  | 'inter_feature_navigation'
  | 'side_drawer_open'
  | 'side_drawer_close'
  | 'play_content'
  | 'go1pay_custom_data';

export interface Go1Message {
  type: Go1MessageType;
  payload?: any;
}

export type Experience = 'manager' | 'learner' | 'role-aware';

export interface FeatureAttributeCommon {
  shouldSuppressPreview?: boolean;
  experience?: Experience;
  contentScope?: 'subscription' | 'library';
}

/**
 * Used to configure the `ai-chat` feature
 */
export interface FeatureAttributesAIChat extends FeatureAttributeCommon {
  intent?: 'skill_gap' | 'improve_skills' | 'next_role' | 'aspirations';
  message?: string; // The desired message to start the chat, which will be shown to the user
  existingSkills?: string[]; // max items 7, any more are discarded
  desiredSkills?: string[]; // max items 7, any more are discarded
  desiredRole?: string; // e.g. "Senior Account Manager"
  showFooter?: boolean // Whether to show/hide the footer, defaults to true
}

/**
 * Used to configure the `preview` feature
 */
export interface FeatureAttributesPreview extends FeatureAttributeCommon {
  id: number;
  startWith1Player?: boolean;
  showFooter?: boolean;
  contentRatingType?: 'no rating' | 'five star rating' | 'like rating';
}

/**
 * Used to configure the `wallet` feature
 */
export interface FeatureAttributesWallet extends FeatureAttributeCommon {
  walletMode: 'setup' | 'main';
  deepLink?: string;
  oneClickBuyUrl?: string;
}

export interface FeatureAttributesLearnerSearch extends FeatureAttributeCommon {
  isGo1MobileApp?: boolean;
  experience?: 'learner';
}

export interface FeatureAttributesLibrary extends FeatureAttributeCommon, FeatureAttributesRetirement {
  libraryEmptyStateDescription?: string;
  shouldShowLibraryTabs?: boolean;
}

export interface FeatureAttributesRetirement extends FeatureAttributeCommon {
  shouldShowAlternativesSearchButton?: boolean;
  shouldShowNotificationEmailRegisterSwitch?: boolean;
}

export interface FeatureAttributesSearch extends FeatureAttributeCommon {}
export interface FeatureAttributesMyPlaylists extends FeatureAttributesPreviewCommon {
  playlistId?: number; // If embedding my-playlists feature with playlistId, the app will initialise with the specified playlistId page.
}

export interface FeatureAttributesMyLearning extends FeatureAttributeCommon {}

export type FeatureAttributes =
  | FeatureAttributesAIChat
  | FeatureAttributesPreview
  | FeatureAttributesWallet
  | FeatureAttributesLibrary
  | FeatureAttributesSearch
  | FeatureAttributesMyPlaylists
  | FeatureAttributesMyLearning
  | FeatureAttributesContentStatus;

export interface AdditionalUserInfo {
  jobTitle: string;
}

export type FeatureType =
  | 'ai-chat'
  | 'content-hub'
  | 'preview'
  | 'library'
  | 'search'
  | 'wallet'
  | 'content-retirement'
  | 'my-playlists'
  | 'activity-feed'
  | 'my-learning'
  | 'content-status';

export interface InitOptions {
  /** Mandatory identifier for the embedded feature */
  feature: FeatureType;
  /** Optional element id to search for, and use as the parent for the Go1 content view (use either this or `iframeParentElement`, not both) */
  iframeParentId?: string;
  /** Optional element to use as the parent for the Go1 content view (use either this or `iframeParentId`, not both) */
  iframeParentElement?: HTMLElement;
  /** Optional parameters to configure the feature. See associated types for examples */
  featureAttributes?: FeatureAttributes;
  /** Optional Go1 portal URL, used for login purposes if no `oneTimeToken` is provided */
  portalURL?: string;
  /** Optional function that is invoked when the Go1 content view emits a message */
  onGo1MessageReceived?: OnGo1MessageReceived;
  /** Optional end user information that can enhance the context and provide a better experience. No PII is needed, please do not send any. */
  additionalUserInfo?: AdditionalUserInfo;
  /** Optional UI configuration */
  themeInformation?: ThemeInformation;
  /** Optional token that is used to pre-authorize the user without them needing to log in */
  oneTimeToken?: string;
  /** Optional Id that let us know which integration system users are coming from (will be required in the future)*/
  integrationSystemId?: string;
  /** Optional Id that let us know which integration system users are coming from, if using an intermediary system to embed */
  presentingIntegrationSystemId?: string;
}

Function: go1Init

Initialize the Go1 content view and insert it into your web page. Establish messaging functions and configure the theme (UI).

function go1Init(options: InitOptions): SendMessageToGo1;

Usage

const onGo1MessageReceived = (message) => {
  console.log('Received postMessage from Go1');
  console.log(message);
};

const options = {
  feature: 'ai-chat',
  iframeParentId: 'go1-chat-window', // alternatively, you could provide `iframeParentElement` directly, instead of this prop
  featureAttributes: {
    experience: 'manager',
  },
  portalURL: 'learning-incorporated-usa.mygo1.com',
  onGo1MessageReceived,
  additionalUserInfo: {
    jobTitle: 'Sales development representative',
  },
  themeInformation: {
    accent: '#0437F2',
  },
  oneTimeToken: '907687a6e81a458190fe4c21f05ee689',
  integrationSystemId: 'int_nI7rPykBRm0C',
};
const sendMessageToGo1 = go1Init(options);

Function: sendMessageToGo1

Send a message to the Go1 content view. Useful to control the user experience when an event starts on your website and the Go1 content view needs to be aware of it (and potentially perform other actions - this is feature dependent.)

A currently supported message is update_experience, this will update the experience Feature Attribute. An example of its usage is below.

function sendMessageToGo1(message: Go1Message): void;

Usage

const message = {
  type: 'update_experience',
  payload: { experience: 'learner' },
};
sendMessageToGo1(message);

Function: onGo1MessageReceived

Respond to events that have occurred in the Go1 content view. Useful to control the user experience when an event starts in the Go1 content view and your website needs to be aware of it.

Usage

const onGo1MessageReceived = (message) => {
  switch (message.type) {
    case 'enrolment_created': {
      const { userId, courseId } = message.payload;
      // perform appropriate actions for when a new enrolment is created
      break;
    }
    case 'category_favourite_added': {
      const { userId, category } = message.payload;
      // perform appropriate actions for when a new category is favourited
      break;
    }
    default:
      break;
  }
};

Support

https://www.go1.com/developers