@go1/go1-embedding-react-sdk 0.0.9 → 0.0.10

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
@@ -88,7 +88,7 @@ export interface AdditionalUserInfo {
88
88
 
89
89
  interface InitOptions {
90
90
  /** Mandatory identifier for the embedded feature */
91
- feature: 'ai-chat' | 'content-hub' | 'preview';
91
+ feature: 'ai-chat' | 'content-hub' | 'preview' | 'library' | 'search';
92
92
  /** Optional parameters to configure the feature. See associated types for examples */
93
93
  featureAttributes?: FeatureAttributes;
94
94
  /** Optional Go1 portal URL, used for login purposes if no `oneTimeToken` is provided */
package/dist/README.md CHANGED
@@ -88,7 +88,7 @@ export interface AdditionalUserInfo {
88
88
 
89
89
  interface InitOptions {
90
90
  /** Mandatory identifier for the embedded feature */
91
- feature: 'ai-chat' | 'content-hub' | 'preview';
91
+ feature: 'ai-chat' | 'content-hub' | 'preview' | 'library' | 'search';
92
92
  /** Optional parameters to configure the feature. See associated types for examples */
93
93
  featureAttributes?: FeatureAttributes;
94
94
  /** Optional Go1 portal URL, used for login purposes if no `oneTimeToken` is provided */
@@ -1,2 +1,3 @@
1
- export declare function addPortalURL(url: URL, portalURL: string): void;
1
+ export declare function addPortalURL(url: URL, portalURL: string, env?: 'qa' | 'prod'): void;
2
2
  export declare function addOneTimeToken(url: URL, oneTimeToken: string): void;
3
+ export declare function isValidFeature(feature: string): boolean;
@@ -1,8 +1,11 @@
1
1
  "use strict";
2
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$/;
3
+ exports.isValidFeature = exports.addOneTimeToken = exports.addPortalURL = void 0;
4
+ function addPortalURL(url, portalURL, env = 'prod') {
5
+ let validPortalURL = /^(?=.{1,255}$)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,245}[a-zA-Z0-9])?\.mygo1\.com$/;
6
+ if (env === 'qa') {
7
+ validPortalURL = /^(?=.{1,255}$)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,245}[a-zA-Z0-9])?\.qa\.go1\.cloud$/;
8
+ }
6
9
  if (validPortalURL.test(portalURL)) {
7
10
  url.searchParams.append('portal_url', portalURL);
8
11
  }
@@ -21,3 +24,7 @@ function addOneTimeToken(url, oneTimeToken) {
21
24
  }
22
25
  }
23
26
  exports.addOneTimeToken = addOneTimeToken;
27
+ function isValidFeature(feature) {
28
+ return ['ai-chat', 'content-hub', 'preview', 'library', 'search'].includes(feature);
29
+ }
30
+ exports.isValidFeature = isValidFeature;
@@ -1,7 +1,11 @@
1
1
  import * as React from 'react';
2
2
  import { InitOptions, SendMessageToGo1 } from '../../common/types';
3
3
  export type ContentViewProps = Omit<InitOptions, 'iframeParentId' | 'iframeParentElement'>;
4
- export declare function useGo1ContentView(props: ContentViewProps): {
4
+ type EnvProps = {
5
+ env?: 'qa' | 'prod';
6
+ };
7
+ export declare function useGo1ContentView(props: ContentViewProps & EnvProps): {
5
8
  sendMessageToGo1: SendMessageToGo1;
6
9
  ContentView: (userProps?: React.IframeHTMLAttributes<HTMLIFrameElement>) => React.JSX.Element;
7
10
  };
11
+ export {};
@@ -6,20 +6,26 @@ const react_1 = require("react");
6
6
  const constants_1 = require("../../common/constants");
7
7
  const params_1 = require("../../common/params");
8
8
  function useGo1ContentView(props) {
9
- const { feature, featureAttributes, portalURL, oneTimeToken, onGo1MessageReceived, additionalUserInfo, themeInformation, } = props;
9
+ const { feature, featureAttributes, portalURL, oneTimeToken, onGo1MessageReceived, additionalUserInfo, themeInformation, env = 'prod', } = props;
10
10
  const iframeRef = (0, react_1.useRef)(null);
11
- const url = 'https://embedding.go1.com';
11
+ let url = 'https://embedding.go1.com';
12
+ if (env === 'qa') {
13
+ url = 'https://embedding.qa.go1.cloud';
14
+ }
15
+ if (!(0, params_1.isValidFeature)(feature)) {
16
+ throw new Error('Unsupported feature');
17
+ }
12
18
  let { iframeURL, iframeID } = (0, react_1.useMemo)(() => {
13
19
  let iframeURL = new URL(`${url}/${feature}`);
14
20
  if (portalURL) {
15
- (0, params_1.addPortalURL)(iframeURL, portalURL);
21
+ (0, params_1.addPortalURL)(iframeURL, portalURL, env);
16
22
  }
17
23
  if (oneTimeToken) {
18
24
  (0, params_1.addOneTimeToken)(iframeURL, oneTimeToken);
19
25
  }
20
26
  const iframeID = `go1-iframe-${feature}`;
21
27
  return { iframeURL, iframeID };
22
- }, [url, feature, oneTimeToken, portalURL]);
28
+ }, [url, feature, portalURL, oneTimeToken, env]);
23
29
  const sendMessageToGo1 = (0, react_1.useCallback)((message) => {
24
30
  iframeRef.current?.contentWindow?.postMessage(message, url);
25
31
  }, [url]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@go1/go1-embedding-react-sdk",
3
- "version": "0.0.9",
3
+ "version": "0.0.10",
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": [