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-react-sdk

v0.0.73

Published

A React library to embed Go1 content into your website.

Downloads

11,428

Readme

Go1 Embedding React SDK

A react hook to embed a Go1 content view in your site. Includes two-way messaging between your site and the Go1 content view.

Installation

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

Usage

Import the hook from the library and use it in your functional components.

import { useMemo, useCallback } from 'react';
import { ContentViewProps, useGo1ContentView } from '@go1/go1-embedding-react-sdk';

export function YourHostingComponent() {
  const onGo1MessageReceived = useCallback((message) => {
    console.log('Received postMessage from Go1');
    console.log(message);
  }, []);

  const options = useMemo<ContentViewProps>(() => {
    return {
      feature: 'ai-chat',
      portalURL: 'learning-incorporated-usa.mygo1.com',
      onGo1MessageReceived,
    };
  }, []);

  const { sendMessageToGo1, ContentView } = useGo1ContentView(options);

  return (
    <div style={{ width: '100vw', height: '100vh' }}>
      <ContentView />
    </div>
  );
}

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'
  | 'swap_out_open'
  | 'swap_out_close'
  | 'play_content'
  | 'go1pay_custom_data';

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

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

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 {
  searchTerm?: string;  // If the embedding search feature includes a search term, the app will initialize with the pre-filled search term.
}
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;;

export interface AdditionalUserInfo {
  jobTitle: string;
}

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

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: useGo1ContentView

A react hook that will return

  • sendMessageToGo1: A function that allows you to send a message to the Go1 content view
  • ContentView: A react component to render the Go1 content view
function useGo1ContentView(options: InitOptions): {
  sendMessageToGo1: SendMessageToGo1;
  ContentView: () => React.JSX.Element;
};

Usage

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

const options = useMemo<ContentViewProps>(() => {
  return {
    feature: 'ai-chat',
    portalURL: 'learning-incorporated-usa.mygo1.com',
    featureAttributes: {
      experience: 'manager',
    },
    onGo1MessageReceived,
    additionalUserInfo: {
      jobTitle: 'Sales development representative',
    },
    themeInformation: {
      accent: '#0437F2',
    },
    oneTimeToken: '907687a6e81a458190fe4c21f05ee689',
    integrationSystemId: 'int_nI7rPykBRm0C',
  };
}, []);

const { sendMessageToGo1, ContentView } = useGo1ContentView(options);

// now to render the <ContentView>

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