@go1/go1-embedding-react-sdk 0.0.3 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -60,25 +60,36 @@ interface ThemeInformation {
60
60
  }
61
61
 
62
62
  /**
63
- * Used to specify how the feature should appear, or what data it should work with.
64
- * example:
65
- * {
66
- * id: 341134,
67
- * shouldShowHeading: false
68
- * }
63
+ * Used to configure the `ai-chat` feature
69
64
  */
70
- interface FeatureAttributes {
71
- [key: string]: number | string;
65
+ export interface FeatureAttributesAIChat {
66
+ experience: 'manager' | 'learner';
67
+ intent?: 'skill_gap' | 'improve_skills' | 'next_role' | 'aspirational';
68
+ existingSkills?: string[]; // max items 7, any more are discarded
69
+ desiredSkills?: string[]; // max items 7, any more are discarded
70
+ }
71
+
72
+ export type FeatureAttributes = FeatureAttributesAIChat
73
+
74
+ export interface AdditionalUserInfo {
75
+ jobTitle: string;
72
76
  }
73
77
 
74
78
  interface InitOptions {
75
- feature: string; // 'ai-chat' | 'explore' | 'preview';
76
- featureAttributes?: FeatureAttributes; // optional
77
- portalURL?: string; //optional
78
- onGo1MessageReceived?: OnGo1MessageReceived; //optional
79
- additionalUserInfo?: any; //optional
80
- themeInformation?: ThemeInformation; //optional
81
- oneTimeToken?: string; //optional
79
+ /** Mandatory identifier for the embedded feature */
80
+ feature: 'ai-chat' | 'content-hub' | 'preview';
81
+ /** Optional parameters to configure the feature. See associated types for examples */
82
+ featureAttributes?: FeatureAttributes;
83
+ /** Optional Go1 portal URL, used for login purposes if no `oneTimeToken` is provided */
84
+ portalURL?: string;
85
+ /** Optional function that is invoked when the Go1 content view emits a message */
86
+ onGo1MessageReceived?: OnGo1MessageReceived;
87
+ /** Optional end user information that can enhance the context and provide a better experience. No PII is needed, please do not send any. */
88
+ additionalUserInfo?: AdditionalUserInfo;
89
+ /** Optional UI configuration */
90
+ themeInformation?: ThemeInformation
91
+ /** Optional token that is used to pre-authorize the user without them needing to log in */
92
+ oneTimeToken?: string;
82
93
  }
83
94
  ```
84
95
 
@@ -109,12 +120,11 @@ const options = useMemo<ContentViewProps>(() => {
109
120
  feature: 'ai-chat',
110
121
  portalURL: 'learning-incorporated-usa.mygo1.com',
111
122
  featureAttributes: {
112
- id: 32973,
123
+ experience: 'manager',
113
124
  },
114
125
  onGo1MessageReceived,
115
126
  additionalUserInfo: {
116
- department: 'sales',
117
- goals: ['leadership', 'management']
127
+ jobTitle: 'Sales development representative'
118
128
  },
119
129
  themeInformation: {
120
130
  accent: '#0437F2'
package/dist/README.md CHANGED
@@ -60,25 +60,36 @@ interface ThemeInformation {
60
60
  }
61
61
 
62
62
  /**
63
- * Used to specify how the feature should appear, or what data it should work with.
64
- * example:
65
- * {
66
- * id: 341134,
67
- * shouldShowHeading: false
68
- * }
63
+ * Used to configure the `ai-chat` feature
69
64
  */
70
- interface FeatureAttributes {
71
- [key: string]: number | string;
65
+ export interface FeatureAttributesAIChat {
66
+ experience: 'manager' | 'learner';
67
+ intent?: 'skill_gap' | 'improve_skills' | 'next_role' | 'aspirational';
68
+ existingSkills?: string[]; // max items 7, any more are discarded
69
+ desiredSkills?: string[]; // max items 7, any more are discarded
70
+ }
71
+
72
+ export type FeatureAttributes = FeatureAttributesAIChat
73
+
74
+ export interface AdditionalUserInfo {
75
+ jobTitle: string;
72
76
  }
73
77
 
74
78
  interface InitOptions {
75
- feature: string; // 'ai-chat' | 'explore' | 'preview';
76
- featureAttributes?: FeatureAttributes; // optional
77
- portalURL?: string; //optional
78
- onGo1MessageReceived?: OnGo1MessageReceived; //optional
79
- additionalUserInfo?: any; //optional
80
- themeInformation?: ThemeInformation; //optional
81
- oneTimeToken?: string; //optional
79
+ /** Mandatory identifier for the embedded feature */
80
+ feature: 'ai-chat' | 'content-hub' | 'preview';
81
+ /** Optional parameters to configure the feature. See associated types for examples */
82
+ featureAttributes?: FeatureAttributes;
83
+ /** Optional Go1 portal URL, used for login purposes if no `oneTimeToken` is provided */
84
+ portalURL?: string;
85
+ /** Optional function that is invoked when the Go1 content view emits a message */
86
+ onGo1MessageReceived?: OnGo1MessageReceived;
87
+ /** Optional end user information that can enhance the context and provide a better experience. No PII is needed, please do not send any. */
88
+ additionalUserInfo?: AdditionalUserInfo;
89
+ /** Optional UI configuration */
90
+ themeInformation?: ThemeInformation
91
+ /** Optional token that is used to pre-authorize the user without them needing to log in */
92
+ oneTimeToken?: string;
82
93
  }
83
94
  ```
84
95
 
@@ -109,12 +120,11 @@ const options = useMemo<ContentViewProps>(() => {
109
120
  feature: 'ai-chat',
110
121
  portalURL: 'learning-incorporated-usa.mygo1.com',
111
122
  featureAttributes: {
112
- id: 32973,
123
+ experience: 'manager',
113
124
  },
114
125
  onGo1MessageReceived,
115
126
  additionalUserInfo: {
116
- department: 'sales',
117
- goals: ['leadership', 'management']
127
+ jobTitle: 'Sales development representative'
118
128
  },
119
129
  themeInformation: {
120
130
  accent: '#0437F2'
@@ -0,0 +1,2 @@
1
+ export declare function addPortalURL(url: URL, portalURL: string): void;
2
+ export declare function addOneTimeToken(url: URL, oneTimeToken: string): void;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addOneTimeToken = exports.addPortalURL = void 0;
4
+ function addPortalURL(url, portalURL) {
5
+ const validPortalURL = /^(?=.{1,255}$)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,245}[a-zA-Z0-9])?\.mygo1\.com$/;
6
+ if (validPortalURL.test(portalURL)) {
7
+ url.searchParams.append('portal_url', portalURL);
8
+ }
9
+ else {
10
+ throw new Error('Invalid formatting for portalURL');
11
+ }
12
+ }
13
+ exports.addPortalURL = addPortalURL;
14
+ function addOneTimeToken(url, oneTimeToken) {
15
+ const validOTT = /^[A-Za-z0-9]+$/;
16
+ if (validOTT.test(oneTimeToken)) {
17
+ url.searchParams.append('one_time_token', oneTimeToken);
18
+ }
19
+ else {
20
+ throw new Error('Invalid formatting for oneTimeToken');
21
+ }
22
+ }
23
+ exports.addOneTimeToken = addOneTimeToken;
@@ -4,7 +4,8 @@ export type IframesMap = {
4
4
  [key: string]: HTMLIFrameElement;
5
5
  };
6
6
  export interface AdditionalInfoMessage {
7
- additionalUserInfo?: any;
7
+ additionalUserInfo?: AdditionalUserInfo;
8
+ featureAttributes?: FeatureAttributes;
8
9
  themeInformation?: ThemeInformation;
9
10
  }
10
11
  export interface ThemeInformation {
@@ -14,16 +15,24 @@ export interface Go1Message {
14
15
  type: string;
15
16
  payload?: any;
16
17
  }
17
- export interface FeatureAttributes {
18
- [key: string]: number | string;
18
+ export interface FeatureAttributesAIChat {
19
+ experience: 'manager' | 'learner';
20
+ intent?: 'skill_gap' | 'improve_skills' | 'next_role' | 'aspirational';
21
+ existingSkills?: string[];
22
+ desiredSkills?: string[];
23
+ }
24
+ export type FeatureAttributes = FeatureAttributesAIChat;
25
+ export interface AdditionalUserInfo {
26
+ jobTitle: string;
19
27
  }
20
28
  export interface InitOptions {
21
- feature: string;
22
- iframeParentId: string;
29
+ feature: 'ai-chat' | 'content-hub' | 'preview';
30
+ iframeParentId?: string;
31
+ iframeParentElement?: HTMLElement;
23
32
  featureAttributes?: FeatureAttributes;
24
33
  portalURL?: string;
25
34
  onGo1MessageReceived?: OnGo1MessageReceived;
26
- additionalUserInfo?: any;
35
+ additionalUserInfo?: AdditionalUserInfo;
27
36
  themeInformation?: ThemeInformation;
28
37
  oneTimeToken?: string;
29
38
  }
@@ -1,8 +1,6 @@
1
1
  import * as React from 'react';
2
2
  import { InitOptions, SendMessageToGo1 } from '../../common/types';
3
- export interface ContentViewProps extends Omit<InitOptions, 'iframeParentId'> {
4
- baseURL?: string;
5
- }
3
+ export type ContentViewProps = Omit<InitOptions, 'iframeParentId' | 'iframeParentElement'>;
6
4
  export declare function useGo1ContentView(props: ContentViewProps): {
7
5
  sendMessageToGo1: SendMessageToGo1;
8
6
  ContentView: (userProps?: React.IframeHTMLAttributes<HTMLIFrameElement>) => React.JSX.Element;
@@ -4,31 +4,22 @@ exports.useGo1ContentView = void 0;
4
4
  const React = require("react");
5
5
  const react_1 = require("react");
6
6
  const constants_1 = require("../../common/constants");
7
+ const params_1 = require("../../common/params");
7
8
  function useGo1ContentView(props) {
8
- const { feature, featureAttributes, portalURL, oneTimeToken, onGo1MessageReceived, additionalUserInfo, themeInformation, baseURL, } = props;
9
+ const { feature, featureAttributes, portalURL, oneTimeToken, onGo1MessageReceived, additionalUserInfo, themeInformation, } = props;
9
10
  const iframeRef = (0, react_1.useRef)(null);
10
- const url = baseURL || 'https://embedding.go1.com';
11
+ const url = 'https://embedding.go1.com';
11
12
  let { iframeURL, iframeID } = (0, react_1.useMemo)(() => {
12
13
  let iframeURL = new URL(`${url}/${feature}`);
13
- if (featureAttributes) {
14
- const { id, ...rest } = featureAttributes;
15
- if (id) {
16
- iframeURL.pathname += `/${id}`;
17
- }
18
- const entries = Object.entries(rest);
19
- for (let [key, value] of entries) {
20
- iframeURL.searchParams.append(key, `${value}`);
21
- }
22
- }
23
14
  if (portalURL) {
24
- iframeURL.searchParams.append('portal_url', portalURL);
15
+ (0, params_1.addPortalURL)(iframeURL, portalURL);
25
16
  }
26
17
  if (oneTimeToken) {
27
- iframeURL.searchParams.append('one_time_token', oneTimeToken);
18
+ (0, params_1.addOneTimeToken)(iframeURL, oneTimeToken);
28
19
  }
29
20
  const iframeID = `go1-iframe-${feature}`;
30
21
  return { iframeURL, iframeID };
31
- }, [url, feature, oneTimeToken, portalURL, featureAttributes]);
22
+ }, [url, feature, oneTimeToken, portalURL]);
32
23
  const sendMessageToGo1 = (0, react_1.useCallback)((message) => {
33
24
  iframeRef.current?.contentWindow?.postMessage(message, url);
34
25
  }, [url]);
@@ -36,12 +27,14 @@ function useGo1ContentView(props) {
36
27
  const { _type, ...rest } = event.data;
37
28
  if (_type === constants_1.GO1_MESSAGE) {
38
29
  if (rest.type === 'go1_app_initialised') {
30
+ let payload = {
31
+ additionalUserInfo,
32
+ themeInformation,
33
+ featureAttributes
34
+ };
39
35
  sendMessageToGo1({
40
36
  type: 'set_additional_embedding_data',
41
- payload: {
42
- additionalUserInfo,
43
- themeInformation,
44
- },
37
+ payload
45
38
  });
46
39
  }
47
40
  else {
@@ -55,6 +48,7 @@ function useGo1ContentView(props) {
55
48
  sendMessageToGo1,
56
49
  onGo1MessageReceived,
57
50
  themeInformation,
51
+ featureAttributes
58
52
  ]);
59
53
  (0, react_1.useEffect)(() => {
60
54
  window.addEventListener('message', eventListenerInstance);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@go1/go1-embedding-react-sdk",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "description": "A React library to embed Go1 content into your website.",
5
5
  "main": "dist/go1-embedding-react-sdk/src/index.js",
6
6
  "files": [
@@ -18,7 +18,7 @@
18
18
  "scripts": {
19
19
  "test": "jest"
20
20
  },
21
- "license": "MIT",
21
+ "license": "ISC",
22
22
  "devDependencies": {
23
23
  "@testing-library/jest-dom": "5.16.5",
24
24
  "@testing-library/react": "14.0.0",