@go1/go1-embedding-react-sdk 0.0.2 → 0.0.4

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
@@ -56,7 +56,7 @@ interface Go1Message {
56
56
 
57
57
  interface ThemeInformation {
58
58
  /** Hex string, starting with a #. Example #0437F2 */
59
- primaryColor: string;
59
+ accent: string;
60
60
  }
61
61
 
62
62
  /**
@@ -68,7 +68,7 @@ interface ThemeInformation {
68
68
  * }
69
69
  */
70
70
  interface FeatureAttributes {
71
- [key: string]: number | string
71
+ [key: string]: number | string;
72
72
  }
73
73
 
74
74
  interface InitOptions {
@@ -117,7 +117,7 @@ const options = useMemo<ContentViewProps>(() => {
117
117
  goals: ['leadership', 'management']
118
118
  },
119
119
  themeInformation: {
120
- primaryColor: '#0437F2'
120
+ accent: '#0437F2'
121
121
  },
122
122
  oneTimeToken: '907687a6e81a458190fe4c21f05ee689'
123
123
  };
package/dist/README.md CHANGED
@@ -56,7 +56,7 @@ interface Go1Message {
56
56
 
57
57
  interface ThemeInformation {
58
58
  /** Hex string, starting with a #. Example #0437F2 */
59
- primaryColor: string;
59
+ accent: string;
60
60
  }
61
61
 
62
62
  /**
@@ -68,7 +68,7 @@ interface ThemeInformation {
68
68
  * }
69
69
  */
70
70
  interface FeatureAttributes {
71
- [key: string]: number | string
71
+ [key: string]: number | string;
72
72
  }
73
73
 
74
74
  interface InitOptions {
@@ -117,7 +117,7 @@ const options = useMemo<ContentViewProps>(() => {
117
117
  goals: ['leadership', 'management']
118
118
  },
119
119
  themeInformation: {
120
- primaryColor: '#0437F2'
120
+ accent: '#0437F2'
121
121
  },
122
122
  oneTimeToken: '907687a6e81a458190fe4c21f05ee689'
123
123
  };
@@ -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,26 +4,31 @@ 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 {
11
- primaryColor: string;
12
+ accent: string;
12
13
  }
13
14
  export interface Go1Message {
14
15
  type: string;
15
16
  payload?: any;
16
17
  }
17
18
  export interface FeatureAttributes {
18
- [key: string]: number | string;
19
+ [key: string]: any;
20
+ }
21
+ export interface AdditionalUserInfo {
22
+ [key: string]: any;
19
23
  }
20
24
  export interface InitOptions {
21
25
  feature: string;
22
- iframeParentId: string;
26
+ iframeParentId?: string;
27
+ iframeParentElement?: HTMLElement;
23
28
  featureAttributes?: FeatureAttributes;
24
29
  portalURL?: string;
25
30
  onGo1MessageReceived?: OnGo1MessageReceived;
26
- additionalUserInfo?: any;
31
+ additionalUserInfo?: AdditionalUserInfo;
27
32
  themeInformation?: ThemeInformation;
28
33
  oneTimeToken?: string;
29
34
  }
@@ -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.2",
3
+ "version": "0.0.4",
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",