@go1/go1-embedding-react-sdk 0.0.14 → 0.0.15

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.
@@ -1,3 +1,4 @@
1
1
  export declare function addPortalURL(url: URL, portalURL: string, env?: 'staging' | 'production'): void;
2
2
  export declare function addOneTimeToken(url: URL, oneTimeToken: string): void;
3
+ export declare function isValidOTT(oneTimeToken: string): boolean;
3
4
  export declare function isValidFeature(feature: string): boolean;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isValidFeature = exports.addOneTimeToken = exports.addPortalURL = void 0;
3
+ exports.isValidFeature = exports.isValidOTT = exports.addOneTimeToken = exports.addPortalURL = void 0;
4
4
  function addPortalURL(url, portalURL, env = 'production') {
5
5
  let validPortalURL = /^(?=.{1,255}$)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,245}[a-zA-Z0-9])?\.mygo1\.com$/;
6
6
  if (env === 'staging') {
@@ -11,13 +11,12 @@ function addPortalURL(url, portalURL, env = 'production') {
11
11
  url.searchParams.append('portal_url', portalURL);
12
12
  }
13
13
  else {
14
- throw new Error('Invalid formatting for portalURL');
14
+ throw new Error(`Invalid formatting for portalURL ${portalURL}, env ${env}`);
15
15
  }
16
16
  }
17
17
  exports.addPortalURL = addPortalURL;
18
18
  function addOneTimeToken(url, oneTimeToken) {
19
- const validOTT = /^[A-Za-z0-9]+$/;
20
- if (validOTT.test(oneTimeToken)) {
19
+ if (isValidOTT(oneTimeToken)) {
21
20
  url.searchParams.append('one_time_token', oneTimeToken);
22
21
  }
23
22
  else {
@@ -25,6 +24,11 @@ function addOneTimeToken(url, oneTimeToken) {
25
24
  }
26
25
  }
27
26
  exports.addOneTimeToken = addOneTimeToken;
27
+ function isValidOTT(oneTimeToken) {
28
+ const validOTT = /^[A-Za-z0-9]+$/;
29
+ return validOTT.test(oneTimeToken);
30
+ }
31
+ exports.isValidOTT = isValidOTT;
28
32
  function isValidFeature(feature) {
29
33
  return [
30
34
  'ai-chat',
@@ -11,7 +11,7 @@ export interface AdditionalInfoMessage {
11
11
  export interface ThemeInformation {
12
12
  accent: string;
13
13
  }
14
- export type Go1MessageType = 'preview_start_content' | 'preview_close' | 'preview_add_content_success' | 'preview_add_content_failure' | 'preview_remove_content_success' | 'preview_remove_content_failure' | 'set_additional_embedding_data' | 'go1_app_initialised';
14
+ export type Go1MessageType = 'preview_start_content' | 'preview_close' | 'preview_add_content_success' | 'preview_add_content_failure' | 'preview_remove_content_success' | 'preview_remove_content_failure' | 'set_additional_embedding_data' | 'go1_app_initialised' | 'ott_required' | 'pass_ott';
15
15
  export interface Go1Message {
16
16
  type: Go1MessageType;
17
17
  payload?: any;
@@ -15,6 +15,9 @@ function useGo1ContentView(props) {
15
15
  if (!(0, params_1.isValidFeature)(feature)) {
16
16
  throw new Error('Unsupported feature');
17
17
  }
18
+ const sendMessageToGo1 = (0, react_1.useCallback)((message) => {
19
+ iframeRef.current?.contentWindow?.postMessage(message, url);
20
+ }, [url]);
18
21
  let { iframeURL, iframeID } = (0, react_1.useMemo)(() => {
19
22
  let iframeURL = new URL(`${url}/${feature}`);
20
23
  if (portalURL) {
@@ -26,9 +29,6 @@ function useGo1ContentView(props) {
26
29
  const iframeID = `go1-iframe-${feature}`;
27
30
  return { iframeURL, iframeID };
28
31
  }, [url, feature, portalURL, oneTimeToken, env]);
29
- const sendMessageToGo1 = (0, react_1.useCallback)((message) => {
30
- iframeRef.current?.contentWindow?.postMessage(message, url);
31
- }, [url]);
32
32
  const eventListenerInstance = (0, react_1.useCallback)((event) => {
33
33
  const { _type, ...rest } = event.data;
34
34
  if (_type === constants_1.GO1_MESSAGE) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@go1/go1-embedding-react-sdk",
3
- "version": "0.0.14",
3
+ "version": "0.0.15",
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": [