@os1-platform/console-ui-react 0.1.17 → 0.2.1

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.
@@ -87,7 +87,7 @@ var HeaderAndSideBar = function (props) {
87
87
  var _a = (0, react_1.useState)(null), consoleInstance = _a[0], setConsoleInstance = _a[1];
88
88
  (0, react_1.useEffect)(function () {
89
89
  if (!props.isLoading) {
90
- var console_1 = console_ui_js_1.ConsoleUiInit.getInstance(props.clientId, props.loginRedirectPath, props.logoutRedirectPath, props.authurl, props.devOrgName, props.appId, props.userManager);
90
+ var console_1 = console_ui_js_1.ConsoleUiInit.getInstance(props.clientId, props.loginRedirectPath, props.logoutRedirectPath, props.authurl, props.devTenantId, props.appId, props.userManager);
91
91
  setConsoleInstance(console_1);
92
92
  console_1.renderHeaderAndSidebar('headerAndSidebar', props.controls);
93
93
  }
@@ -147,45 +147,41 @@ var getTenantFromDevPortal = function (orgShortName) { return __awaiter(void 0,
147
147
  }
148
148
  });
149
149
  }); };
150
- var getTenantId = function (devOrgNameArg) {
151
- if (devOrgNameArg === void 0) { devOrgNameArg = null; }
152
- var devOrgName = devOrgNameArg;
153
- //if (!devOrgNameArg) devOrgName = getAuthConfig().devOrgName;
154
- var hostname = window.location.hostname || null;
155
- return hostname
156
- ? (hostname.split('.')[0] == 'developer' ||
157
- hostname.split('.')[0] == 'developer2' ||
158
- hostname.split('.')[0].includes('-cdev')) &&
159
- devOrgName
160
- ? devOrgName
161
- : hostname.split('.')[0]
162
- : '';
163
- };
164
- var getKeyCloakAuthority = function (domain, devOrgName) { return __awaiter(void 0, void 0, void 0, function () {
165
- var orgName, baseDomainName, _a, orgShortName, baseDomain, tenant, tenantId;
150
+ var getTenantUrlFromDevPortal = function (tenantId) { return __awaiter(void 0, void 0, void 0, function () {
151
+ var url, response;
152
+ return __generator(this, function (_a) {
153
+ switch (_a.label) {
154
+ case 0:
155
+ url = "https://api.getos1.com/app/core-api/tenant?tenantId=".concat(tenantId);
156
+ return [4 /*yield*/, axios_1.default.get(url)];
157
+ case 1:
158
+ response = _a.sent();
159
+ return [2 /*return*/, response.data.data];
160
+ }
161
+ });
162
+ }); };
163
+ var getKeyCloakAuthority = function (domain, devTenantId) { return __awaiter(void 0, void 0, void 0, function () {
164
+ var orgName, baseDomainName, tenant_1, _a, orgShortName, baseDomain, tenant;
166
165
  return __generator(this, function (_b) {
167
166
  switch (_b.label) {
168
167
  case 0:
169
168
  orgName = '';
170
169
  baseDomainName = '';
171
- if (devOrgName != undefined) {
172
- orgName = devOrgName;
173
- baseDomainName = domain.substring(domain.indexOf('.'));
174
- }
175
- else {
176
- _a = getCleanedDomain(domain), orgShortName = _a.orgShortName, baseDomain = _a.baseDomain;
177
- orgName = orgShortName;
178
- baseDomainName = baseDomain;
179
- }
180
- if (!baseDomainName.includes('os1')) return [3 /*break*/, 2];
181
- return [4 /*yield*/, getTenantFromDevPortal(orgName)];
170
+ if (!(devTenantId != undefined)) return [3 /*break*/, 2];
171
+ baseDomainName = domain.substring(domain.indexOf('.'));
172
+ return [4 /*yield*/, getTenantUrlFromDevPortal(devTenantId)];
182
173
  case 1:
174
+ tenant_1 = _b.sent();
175
+ return [2 /*return*/, "".concat(tenant_1.stackAuthUrl, "/auth/realms/").concat(devTenantId)];
176
+ case 2:
177
+ _a = getCleanedDomain(domain), orgShortName = _a.orgShortName, baseDomain = _a.baseDomain;
178
+ orgName = orgShortName;
179
+ baseDomainName = baseDomain;
180
+ _b.label = 3;
181
+ case 3: return [4 /*yield*/, getTenantFromDevPortal(orgName)];
182
+ case 4:
183
183
  tenant = _b.sent();
184
184
  return [2 /*return*/, "".concat(tenant.stackAuthUrl, "/auth/realms/").concat(tenant.tenantId)];
185
- case 2:
186
- tenantId = getTenantId(orgName);
187
- //console.log(tenantId);
188
- return [2 /*return*/, "https://keycloak".concat(baseDomainName, "/auth/realms/").concat(tenantId)];
189
185
  }
190
186
  });
191
187
  }); };
@@ -199,7 +195,7 @@ var OS1Provider = function (props) {
199
195
  return __awaiter(this, void 0, void 0, function () {
200
196
  return __generator(this, function (_a) {
201
197
  switch (_a.label) {
202
- case 0: return [4 /*yield*/, getKeyCloakAuthority(window.location.hostname, props.devOrgName)];
198
+ case 0: return [4 /*yield*/, getKeyCloakAuthority(window.location.hostname, props.devTenantId)];
203
199
  case 1:
204
200
  authUrls = _a.sent();
205
201
  setAuthUrl(authUrls);
@@ -209,12 +205,12 @@ var OS1Provider = function (props) {
209
205
  });
210
206
  })();
211
207
  }, []);
212
- return ((0, jsx_runtime_1.jsx)(OS1Provider2, { clientId: props.clientId, loginRedirectPath: props.loginRedirectPath, logoutRedirectPath: props.logoutRedirectPath, devOrgName: props.devOrgName, appId: props.appId, controls: props.controls, authUrl: authUrl, props: props }));
208
+ return ((0, jsx_runtime_1.jsx)(OS1Provider2, { clientId: props.clientId, loginRedirectPath: props.loginRedirectPath, logoutRedirectPath: props.logoutRedirectPath, devTenantId: props.devTenantId, appId: props.appId, controls: props.controls, authUrl: authUrl, props: props }));
213
209
  };
214
210
  exports.OS1Provider = OS1Provider;
215
211
  var OS1Provider2 = function (props) {
216
212
  //console.log(props);
217
- var userManager = new console_ui_js_1.AAA(props.clientId, props.loginRedirectPath, props.logoutRedirectPath, props.devOrgName, props.authUrl);
213
+ var userManager = new console_ui_js_1.AAA(props.clientId, props.loginRedirectPath, props.logoutRedirectPath, props.devTenantId, props.authUrl);
218
214
  var value = '';
219
215
  //console.log('userManager', userManager);
220
216
  var _a = (0, react_1.useState)(true), isLoading = _a[0], setIsLoading = _a[1];
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/aaa/index.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6DAAqJ;AA2SnJ,8FA3S2B,6BAAa,OA2S3B;AACb,oGA5S0D,mCAAmB,OA4S1D;AACnB,gHA7S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MA,4BAAQ","sourcesContent":["import { AAA, ConsoleUiInit, OS1HttpClient, OS1Components, functionBoundOption, functionBoundAutoCompleteOption} from '@os1-platform/console-ui-js';\nimport React, { useEffect, useRef, useState } from 'react';\nimport { ModalProps } from '../components/modal/interface';\nimport { ToastProps } from '../components/toast/interface';\n\nimport axios from 'axios';\n\nexport const AuthContext = React.createContext<any | undefined>(undefined);\nexport const ConsoleUIContext = React.createContext<any>(undefined);\n\nconst HeaderAndSideBar = (props: any) => {\n const [consoleInstance, setConsoleInstance] = useState<any>(null);\n\n useEffect(() => {\n if (!props.isLoading) {\n const console = ConsoleUiInit.getInstance(\n props.clientId,\n props.loginRedirectPath,\n props.logoutRedirectPath,\n props.authurl,\n props.devOrgName,\n props.appId,\n props.userManager\n );\n\n setConsoleInstance(console);\n console.renderHeaderAndSidebar('headerAndSidebar', props.controls);\n }\n }, [props.isLoading]);\n\n if (props.isLoading) {\n if (props.loader) {\n return props.loader;\n } else {\n const keyframes = `\n @-webkit-keyframes spin {\n 0% {\n -webkit-transform: rotate(0deg);\n }\n 100% {\n -webkit-transform: rotate(360deg);\n }\n }\n `;\n const styleSheets = Array.from(document.styleSheets).filter(\n (styleSheet) =>\n !styleSheet.href || styleSheet.href.startsWith(window.location.origin)\n );\n for (let style of styleSheets) {\n if (style instanceof CSSStyleSheet && style.cssRules) {\n style.insertRule(keyframes, style.cssRules.length);\n }\n }\n const loaderStyle = () => ({\n marginTop: '50vh',\n marginLeft: '50vw',\n border: '12px solid #F3F3F3',\n borderRadius: '50%',\n borderTop: '12px solid grey',\n width: '40px',\n height: '40px',\n animationName: 'spin',\n animationDuration: '2s',\n animationTimingFunction: 'linear',\n animationIterationCount: 'infinite',\n });\n return <div style={loaderStyle()}></div>;\n }\n }\n //console.log(consoleInstance, props);\n return (\n <ConsoleUIContext.Provider value={consoleInstance}>\n <div id=\"headerAndSidebar\">{props.children}</div>\n </ConsoleUIContext.Provider>\n );\n};\n\ninterface TenantDTO {\n tenantId: string;\n tenantStatus: string;\n tenantDns: string;\n stackId: string;\n stackName: string;\n organizationShortName: string;\n organizationBaseDomain: string;\n stackAuthUrl: string;\n}\n\nconst getCleanedDomain = (domain: string) => {\n const cleanedDomain = String(domain);\n const splitHost = cleanedDomain.split('.');\n const org = splitHost[0] || '';\n const cleanedOrg = org.replace('-cdev', '');\n const base = splitHost.join('.');\n return { orgShortName: cleanedOrg, baseDomain: base };\n};\n\nconst getTenantFromDevPortal = async (\n orgShortName: any\n): Promise<TenantDTO> => {\n const url = `https://api.getos1.com/app/core-api/tenant?orgShortName=${orgShortName}`;\n const response = await axios.get(url);\n return response.data.data;\n};\n\nconst getTenantId = (devOrgNameArg: string | null = null): string => {\n let devOrgName = devOrgNameArg;\n //if (!devOrgNameArg) devOrgName = getAuthConfig().devOrgName;\n\n const hostname = window.location.hostname || null;\n\n return hostname\n ? (hostname.split('.')[0] == 'developer' ||\n hostname.split('.')[0] == 'developer2' ||\n hostname.split('.')[0].includes('-cdev')) &&\n devOrgName\n ? devOrgName\n : hostname.split('.')[0]\n : '';\n};\n\nconst getKeyCloakAuthority = async (domain: string, devOrgName: string) => {\n let orgName: string = '';\n let baseDomainName: string = '';\n\n if (devOrgName != undefined) {\n orgName = devOrgName;\n baseDomainName = domain.substring(domain.indexOf('.'));\n } else {\n const { orgShortName, baseDomain } = getCleanedDomain(domain);\n\n orgName = orgShortName;\n baseDomainName = baseDomain;\n }\n\n if (baseDomainName.includes('os1')) {\n const tenant = await getTenantFromDevPortal(orgName);\n\n return `${tenant.stackAuthUrl}/auth/realms/${tenant.tenantId}`;\n }\n\n const tenantId = getTenantId(orgName);\n //console.log(tenantId);\n return `https://keycloak${baseDomainName}/auth/realms/${tenantId}`;\n};\n\nconst OS1Provider = (props: any) => {\n const [authUrl, setAuthUrl] = useState('');\n // const [tenantDns, setTenantDns] = useState('');\n // let isMountedRef = useRef<boolean>(false);\n\n let authUrls = '';\n useEffect(() => {\n (async function () {\n authUrls = await getKeyCloakAuthority(\n window.location.hostname,\n props.devOrgName\n );\n setAuthUrl(authUrls);\n })();\n }, []);\n\n return (\n <OS1Provider2\n clientId={props.clientId}\n loginRedirectPath={props.loginRedirectPath}\n logoutRedirectPath={props.logoutRedirectPath}\n devOrgName={props.devOrgName}\n appId={props.appId}\n controls={props.controls}\n authUrl={authUrl}\n props={...props}\n />\n );\n};\nconst OS1Provider2 = (props: any) => {\n //console.log(props);\n const userManager = new AAA(\n props.clientId,\n props.loginRedirectPath,\n props.logoutRedirectPath,\n props.devOrgName,\n props.authUrl\n );\n const value = '';\n //console.log('userManager', userManager);\n const [isLoading, setIsLoading] = useState(true);\n let isMountedRef = useRef<boolean>(false);\n\n useEffect(() => {\n // Store current isMounted since this could change while awaiting async operations below\n isMountedRef.current = true;\n (async () => {\n let user = undefined;\n try {\n user = await userManager!.getUserInfo();\n } catch (error: any) {\n window.console.log('Error: ', error);\n }\n /**\n * Check if the user is returning back from OIDC.\n */\n if (hasCodeInUrl(window.location)) {\n await userManager?.logincallback();\n cleanBrowserUrl();\n setIsLoading(false);\n return;\n }\n\n if (!(await userManager?.isAuthenticated())) {\n userManager?.login();\n } else if (isMountedRef.current) {\n setIsLoading(false);\n }\n })();\n\n return () => {\n isMountedRef.current = false;\n };\n }, [window.location, userManager]);\n\n return (\n <AuthContext.Provider value={value}>\n <HeaderAndSideBar\n userManager={userManager}\n isLoading={isLoading}\n loader={props.loader}\n devOrgName={props.devOrgName}\n controls={props.controls}\n appId={props.appId}\n authUrl={props.authUrl}\n >\n {props.props.children}\n </HeaderAndSideBar>\n </AuthContext.Provider>\n );\n};\nconst hasCodeInUrl = (location: Location): boolean => {\n const searchParams = new URLSearchParams(location.search);\n const hashParams = new URLSearchParams(location.hash.replace('#', '?'));\n return Boolean(\n searchParams.get('code') ||\n searchParams.get('id_token') ||\n searchParams.get('session_state') ||\n searchParams.get('state') ||\n hashParams.get('code') ||\n hashParams.get('id_token') ||\n hashParams.get('session_state') ||\n hashParams.get('state')\n );\n};\n\nconst cleanBrowserUrl = () => {\n const search = window.location.search;\n\n if (\n search &&\n (search.includes('session_state=') ||\n search.includes('state=') ||\n search.includes('code='))\n ) {\n /*\n * Use replaceState to redirect the user away and remove the querystring parameters\n */\n window.history.replaceState(\n {},\n document.title,\n window.location.href.split('?')[0]\n );\n }\n};\n\n// export { Toast, Modal };\n\nconst OS1Toast = (props: ToastProps) => {\n\n useEffect(() => {\n const os1Components = new OS1Components()\n os1Components.renderToast(props.elementId, props.toastConfig);\n }, []);\n\n return <div id={props.elementId}></div>;\n};\n\nconst OS1Modal = (props: ModalProps) => {\n\n useEffect(() => {\n const os1Components = new OS1Components()\n os1Components.renderModal(props.elementId, props.modalConfig);\n }, []);\n\n return <div id={props.elementId}></div>;\n};\n\n\nexport {\n OS1Provider,\n OS1Toast,\n OS1Modal,\n OS1HttpClient,\n functionBoundOption,\n functionBoundAutoCompleteOption\n};\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/aaa/index.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6DAAqJ;AA+RnJ,8FA/R2B,6BAAa,OA+R3B;AACb,oGAhS0D,mCAAmB,OAgS1D;AACnB,gHAjS+E,+CAA+B,OAiS/E;AAhSjC,6CAA2D;AAI3D,gDAA0B;AAEb,QAAA,WAAW,GAAG,eAAK,CAAC,aAAa,CAAkB,SAAS,CAAC,CAAC;AAC9D,QAAA,gBAAgB,GAAG,eAAK,CAAC,aAAa,CAAM,SAAS,CAAC,CAAC;AAEpE,IAAM,gBAAgB,GAAG,UAAC,KAAU;IAC5B,IAAA,KAAwC,IAAA,gBAAQ,EAAM,IAAI,CAAC,EAA1D,eAAe,QAAA,EAAE,kBAAkB,QAAuB,CAAC;IAElE,IAAA,iBAAS,EAAC;QACR,IAAI,CAAC,KAAK,CAAC,SAAS,EAAE;YACpB,IAAM,SAAO,GAAG,6BAAa,C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AeA,4BAAQ;AAbV,IAAM,QAAQ,GAAG,UAAC,KAAiB;IAEjC,IAAA,iBAAS,EAAC;QACR,IAAM,aAAa,GAAG,IAAI,6BAAa,EAAE,CAAA;QACzC,aAAa,CAAC,WAAW,CAAC,KAAK,CAAC,SAAS,EAAE,KAAK,CAAC,WAAW,CAAC,CAAC;IAChE,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,gCAAK,EAAE,EAAE,KAAK,CAAC,SAAS,GAAQ,CAAC;AAC1C,CAAC,CAAC;AAMA,4BAAQ","sourcesContent":["import { AAA, ConsoleUiInit, OS1HttpClient, OS1Components, functionBoundOption, functionBoundAutoCompleteOption} from '@os1-platform/console-ui-js';\nimport React, { useEffect, useRef, useState } from 'react';\nimport { ModalProps } from '../components/modal/interface';\nimport { ToastProps } from '../components/toast/interface';\n\nimport axios from 'axios';\n\nexport const AuthContext = React.createContext<any | undefined>(undefined);\nexport const ConsoleUIContext = React.createContext<any>(undefined);\n\nconst HeaderAndSideBar = (props: any) => {\n const [consoleInstance, setConsoleInstance] = useState<any>(null);\n\n useEffect(() => {\n if (!props.isLoading) {\n const console = ConsoleUiInit.getInstance(\n props.clientId,\n props.loginRedirectPath,\n props.logoutRedirectPath,\n props.authurl,\n props.devTenantId,\n props.appId,\n props.userManager\n );\n\n setConsoleInstance(console);\n console.renderHeaderAndSidebar('headerAndSidebar', props.controls);\n }\n }, [props.isLoading]);\n\n if (props.isLoading) {\n if (props.loader) {\n return props.loader;\n } else {\n const keyframes = `\n @-webkit-keyframes spin {\n 0% {\n -webkit-transform: rotate(0deg);\n }\n 100% {\n -webkit-transform: rotate(360deg);\n }\n }\n `;\n const styleSheets = Array.from(document.styleSheets).filter(\n (styleSheet) =>\n !styleSheet.href || styleSheet.href.startsWith(window.location.origin)\n );\n for (let style of styleSheets) {\n if (style instanceof CSSStyleSheet && style.cssRules) {\n style.insertRule(keyframes, style.cssRules.length);\n }\n }\n const loaderStyle = () => ({\n marginTop: '50vh',\n marginLeft: '50vw',\n border: '12px solid #F3F3F3',\n borderRadius: '50%',\n borderTop: '12px solid grey',\n width: '40px',\n height: '40px',\n animationName: 'spin',\n animationDuration: '2s',\n animationTimingFunction: 'linear',\n animationIterationCount: 'infinite',\n });\n return <div style={loaderStyle()}></div>;\n }\n }\n //console.log(consoleInstance, props);\n return (\n <ConsoleUIContext.Provider value={consoleInstance}>\n <div id=\"headerAndSidebar\">{props.children}</div>\n </ConsoleUIContext.Provider>\n );\n};\n\ninterface TenantDTO {\n tenantId: string;\n tenantStatus: string;\n tenantDns: string;\n stackId: string;\n stackName: string;\n organizationShortName: string;\n organizationBaseDomain: string;\n stackAuthUrl: string;\n}\n\nconst getCleanedDomain = (domain: string) => {\n const cleanedDomain = String(domain);\n const splitHost = cleanedDomain.split('.');\n const org = splitHost[0] || '';\n const cleanedOrg = org.replace('-cdev', '');\n const base = splitHost.join('.');\n return { orgShortName: cleanedOrg, baseDomain: base };\n};\n\nconst getTenantFromDevPortal = async (\n orgShortName: any\n): Promise<TenantDTO> => {\n const url = `https://api.getos1.com/app/core-api/tenant?orgShortName=${orgShortName}`;\n const response = await axios.get(url);\n return response.data.data;\n};\n\nconst getTenantUrlFromDevPortal = async (\n tenantId: string\n): Promise<TenantDTO> => {\n const url = `https://api.getos1.com/app/core-api/tenant?tenantId=${tenantId}`;\n const response = await axios.get(url);\n return response.data.data;\n};\n\nconst getKeyCloakAuthority = async (domain: string, devTenantId: string) => {\n let orgName: string = '';\n var baseDomainName: string = '';\n\n if (devTenantId != undefined) {\n baseDomainName = domain.substring(domain.indexOf('.'));\n\n const tenant = await getTenantUrlFromDevPortal(devTenantId);\n \n return `${tenant.stackAuthUrl}/auth/realms/${devTenantId}`;\n } else {\n const { orgShortName, baseDomain } = getCleanedDomain(domain);\n\n orgName = orgShortName;\n baseDomainName = baseDomain;\n }\n const tenant = await getTenantFromDevPortal(orgName);\n\n return `${tenant.stackAuthUrl}/auth/realms/${tenant.tenantId}`;\n};\n\nconst OS1Provider = (props: any) => {\n const [authUrl, setAuthUrl] = useState('');\n // const [tenantDns, setTenantDns] = useState('');\n // let isMountedRef = useRef<boolean>(false);\n\n let authUrls = '';\n useEffect(() => {\n (async function () {\n authUrls = await getKeyCloakAuthority(\n window.location.hostname,\n props.devTenantId\n );\n setAuthUrl(authUrls);\n })();\n }, []);\n\n return (\n <OS1Provider2\n clientId={props.clientId}\n loginRedirectPath={props.loginRedirectPath}\n logoutRedirectPath={props.logoutRedirectPath}\n devTenantId={props.devTenantId}\n appId={props.appId}\n controls={props.controls}\n authUrl={authUrl}\n props={...props}\n />\n );\n};\nconst OS1Provider2 = (props: any) => {\n //console.log(props);\n const userManager = new AAA(\n props.clientId,\n props.loginRedirectPath,\n props.logoutRedirectPath,\n props.devTenantId,\n props.authUrl\n );\n const value = '';\n //console.log('userManager', userManager);\n const [isLoading, setIsLoading] = useState(true);\n let isMountedRef = useRef<boolean>(false);\n\n useEffect(() => {\n // Store current isMounted since this could change while awaiting async operations below\n isMountedRef.current = true;\n (async () => {\n let user = undefined;\n try {\n user = await userManager!.getUserInfo();\n } catch (error: any) {\n window.console.log('Error: ', error);\n }\n /**\n * Check if the user is returning back from OIDC.\n */\n if (hasCodeInUrl(window.location)) {\n await userManager?.logincallback();\n cleanBrowserUrl();\n setIsLoading(false);\n return;\n }\n\n if (!(await userManager?.isAuthenticated())) {\n userManager?.login();\n } else if (isMountedRef.current) {\n setIsLoading(false);\n }\n })();\n\n return () => {\n isMountedRef.current = false;\n };\n }, [window.location, userManager]);\n\n return (\n <AuthContext.Provider value={value}>\n <HeaderAndSideBar\n userManager={userManager}\n isLoading={isLoading}\n loader={props.loader}\n devOrgName={props.devOrgName}\n controls={props.controls}\n appId={props.appId}\n authUrl={props.authUrl}\n >\n {props.props.children}\n </HeaderAndSideBar>\n </AuthContext.Provider>\n );\n};\nconst hasCodeInUrl = (location: Location): boolean => {\n const searchParams = new URLSearchParams(location.search);\n const hashParams = new URLSearchParams(location.hash.replace('#', '?'));\n return Boolean(\n searchParams.get('code') ||\n searchParams.get('id_token') ||\n searchParams.get('session_state') ||\n searchParams.get('state') ||\n hashParams.get('code') ||\n hashParams.get('id_token') ||\n hashParams.get('session_state') ||\n hashParams.get('state')\n );\n};\n\nconst cleanBrowserUrl = () => {\n const search = window.location.search;\n\n if (\n search &&\n (search.includes('session_state=') ||\n search.includes('state=') ||\n search.includes('code='))\n ) {\n /*\n * Use replaceState to redirect the user away and remove the querystring parameters\n */\n window.history.replaceState(\n {},\n document.title,\n window.location.href.split('?')[0]\n );\n }\n};\n\n// export { Toast, Modal };\n\nconst OS1Toast = (props: ToastProps) => {\n\n useEffect(() => {\n const os1Components = new OS1Components()\n os1Components.renderToast(props.elementId, props.toastConfig);\n }, []);\n\n return <div id={props.elementId}></div>;\n};\n\nconst OS1Modal = (props: ModalProps) => {\n\n useEffect(() => {\n const os1Components = new OS1Components()\n os1Components.renderModal(props.elementId, props.modalConfig);\n }, []);\n\n return <div id={props.elementId}></div>;\n};\n\n\nexport {\n OS1Provider,\n OS1Toast,\n OS1Modal,\n OS1HttpClient,\n functionBoundOption,\n functionBoundAutoCompleteOption\n};\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@os1-platform/console-ui-react",
3
- "version": "0.1.17",
3
+ "version": "0.2.1",
4
4
  "description": "React wrapper for console-ui library",
5
5
  "main": "dist/commonjs/aaa/index.js",
6
6
  "types": "dist/commonjs/types/aaa/index.d.ts",
@@ -27,7 +27,7 @@
27
27
  },
28
28
  "dependencies": {
29
29
  "@fullhuman/postcss-purgecss": "^5.0.0",
30
- "@os1-platform/console-ui-js": "^0.1.17",
30
+ "@os1-platform/console-ui-js": "file:../../console-ui-js/os1-platform-console-ui-js-0.2.0.tgz",
31
31
  "@react-native-community/eslint-config": "^2.0.0",
32
32
  "@types/react": "^17.0.37",
33
33
  "axios": "^0.21.4",
package/readme.md CHANGED
@@ -17,7 +17,7 @@
17
17
  clientId={`sampleClientId`} // This is the clientId that you get after creating an app.
18
18
  loginRedirectPath={'/abc'} // path that will be given when someone logins into console ui for the first time
19
19
  logoutRedirectPath={'/'} //path that needs to be redirected when someone logouts from your application.
20
- devOrgName={'orgName'} // this is an optional parameter, need only to be passed when using in development mode.
20
+ devTenantId={'tenantId'} // this is an optional parameter, need only to be passed when using in development mode.
21
21
  appId={'SolutionName-appId'} //initial appId on which you want to land when loading console ui for the first time.
22
22
  >
23
23
  <Initiate setConsole={handleConsoleInstanceChange} /> //This is your
@@ -54,7 +54,7 @@
54
54
  float: "left", // Option to align items left or right
55
55
  functionBoundOption: autoComplete(), // Function that return value as an array of object in the form of [{ value: string, text: string }]
56
56
  }]
57
- <OS1Provider clientId={`sampleClientId`} loginRedirectPath={"/abc"} logoutRedirectPath={"/"} devOrgName={"orgName"} controls ={controls} appId={'SolutionName-appId'}>
57
+ <OS1Provider clientId={`sampleClientId`} loginRedirectPath={"/abc"} logoutRedirectPath={"/"} devTenantId={"tenantId"} controls ={controls} appId={'SolutionName-appId'}>
58
58
  <Initiate setConsole={handleConsoleInstanceChange} />
59
59
  </OS1Provider>
60
60
  ```
@@ -149,7 +149,7 @@
149
149
  const handleClick = () => {
150
150
  //here consoleInstance is the state variable of ConsoleUIContext;
151
151
  if (consoleInstance) {
152
- const client = new OS1HttpClient(consoleInstane.authInitializer, `https://abc.domain.com`); //consoleInstance.authInitializer is an instance of AAA class that we get from ConsoleUi Context
152
+ const client = new OS1HttpClient(consoleInstance.authInitializer, `https://abc.domain.com`); //consoleInstance.authInitializer is an instance of AAA class that we get from ConsoleUi Context
153
153
  const reqHeaders: any = {
154
154
  withAccess: false,
155
155
  withTid: false,
@@ -191,48 +191,73 @@
191
191
 
192
192
  15. If nothing is selected then, when user clicks on app for the first time, it asks how we want to redirect the app.
193
193
 
194
- 16. Link to acceess [example app](https://github.com/OS1-logistics/vehicle-reference-app/tree/console-v2-integration)
194
+ 16. To get Access Token, use `getAuthenticationTokens` method, for userInfo, use `getUser`, and check whether user is authenticated use `isAuthenticated()`. User have to use context of consoleUi and call authInitializer method of it.
195
+ ```Javascript
196
+ if (consoleInstance) {
197
+ const accessToken = consoleInstance.authInitializer.getAuthenticationTokens();
198
+ const userInfo = consoleInstance.authInitializer.getUser();
199
+ const isUserAuthenticated = consoleInstance.authInitializer.isAuthenticated();
200
+ }
201
+ ```
202
+
203
+
204
+ 17. Link to acceess [example app](https://github.com/OS1-logistics/vehicle-reference-app/tree/console-v2-integration)
195
205
 
196
206
  ## Configuration for Injectable Controls offered by the Library
197
207
 
208
+ #### Common parameters, that will be passed in all injectable controls:-
209
+ - **type:-** This field shows the type of injectable controls that is being used. Available types are TextBox, TextBoxButton, AutoComplete, DropDown, SearchBox
210
+ - **width:-** This field shows the maximum percentage of width that can be passed.
211
+ - **placeholder:-** This field displays the placeholder text, that is passed in injectable control.
212
+ - **id:-** This is unique id that is given to injectable controls that uniquely identifies that particular component.
213
+ - **float:-** This is optional component, by default every component is left floated.
214
+
215
+
198
216
  ##### TextBox:-
199
217
 
200
218
  - To use textbox in console ui, we provide following configuration:-
201
219
 
202
220
  ```javascript
203
221
  {
204
- type: "TextBox", // type of injectable control
205
- width: 100, // maximum width in percentage that can be given
206
- placeholder: "Search Package", // placeholder text
207
- float: "left", // aligning the injectable control in left or right direction
208
- id: "TextBox1" // unique id that can be given to injectable control
209
- attributes: {
222
+ type: "TextBox",
223
+ width: 100,
224
+ placeholder: "Search Package",
225
+ float: "left",
226
+ id: "TextBox1"
227
+ attributes: {
210
228
  maxlength: “50”;
211
-
212
- } // this is optional attributes parameter that contains object which defines if any attribute needs to be set to injectable controls
213
- }
229
+ }
230
+ }
214
231
  ```
215
232
 
233
+ - **Note:-**
234
+ - Here, attributes is an optional attributes parameter that contains object which defines if any attribute needs to be set to injectable controls.
235
+ - OnChange and OnBlur event is emitted by this injectable control.
236
+
237
+
216
238
  ##### TextBoxButton:-
217
239
 
218
240
  - To use textbox with button in console ui, we provide following configuration:-
219
241
 
220
242
  ```javascript
221
243
  {
222
- type: "TextBoxButton", // type of injectable control
223
- width: 100, // maximum width in percentage that can be given
224
- placeholder: "Search Package", // placeholder text
225
- float: "left", // aligning the injectable control in left or right direction
226
- id: "TextBoxButton1" // unique id that can be given to injectable control
227
- attributes: {
228
- maxlength: “50”;
229
- } // this is optional attributes parameter that contains object which defines if any attribute needs to be set to injectable controls
230
- button: true, // this by default set to false,
231
- buttonText: “Search”, // this field needs to be present when button is true.
232
- buttonColor: “red”, // this field needs to be present when button is true.
244
+ type: "TextBoxButton",
245
+ width: 100,
246
+ placeholder: "Search Package",
247
+ float: "left",
248
+ id: "TextBoxButton1"
249
+ attributes: {
250
+ maxlength: “50”;
251
+ }
252
+ button: true,
253
+ buttonText: “Search”,
254
+ buttonColor: “red
233
255
  }
234
-
235
256
  ```
257
+ - **Note:-**
258
+ - Here button by default set to false, but if we set it to true, then we have to pass buttonText and buttonColor, which specifies the outlook of a button
259
+ - Here, attributes is an optional attributes parameter that contains object which defines if any attribute needs to be set to injectable controls.
260
+ - OnChange is emitted when we change text in input box and OnClick is emitted when user clicks on button.
236
261
 
237
262
  ##### Search Box:-
238
263
 
@@ -240,32 +265,40 @@
240
265
 
241
266
  ```javascript
242
267
  {
243
- type: "SearchBox", // type of injectable control
244
- width: 100, // maximum width in percentage that can be given
245
- placeholder: "Search Package", // placeholder text
246
- float: "right", // aligning the injectable control in left or right direction
247
- id: "SearchBox1" // unique id that can be given to injectable control
248
- attributes: { maxlength: “50”; } // this is optional attributes parameter that contains object which defines if any attribute needs to be set to injectable controls
249
- lensIcon: true // this field is optional, if set to true then lensIcon will be shown.
268
+ type: "SearchBox",
269
+ width: 100,
270
+ placeholder: "Search Package",
271
+ float: "right",
272
+ id: "SearchBox1"
273
+ attributes: { maxlength: “50”; }
274
+ lensIcon: true
250
275
  }
251
-
252
276
  ```
253
277
 
278
+ - **Note:-**
279
+ - Here lensIcon is optional, if it is set to true then lensIcon will be shown in injectable control.
280
+ - Here, attributes is an optional attributes parameter that contains object which defines if any attribute needs to be set to injectable controls.
281
+ - OnChange, onBlur, onFocus is emitted on input box.
282
+
254
283
  ##### AutoComplete:-
255
284
 
256
285
  - To use AutoComplete in console ui, we provide following configuration:-
257
286
 
258
287
  ```javascript
259
288
  {
260
- type: "AutoComplete", // type of injectable control
261
- width: 100, // maximum width in percentage that can be given
262
- placeholder: "Search Package", // placeholder text
263
- float: "right", // aligning the injectable control in left or right direction
264
- id: "AutcoComplete1" // unique id that can be given to injectable control
289
+ type: "AutoComplete",
290
+ width: 100,
291
+ placeholder: "Search Package",
292
+ float: "right",
293
+ id: "AutcoComplete1"
265
294
  functionBoundOption: autoComplete(), // This field can be a function which return array of Objects or normal array of objects in the form of [{ value: string, text: string }],
266
295
  }
267
-
268
296
  ```
297
+ - **Note:-**
298
+ - In this `functionBoundOption` is passed when options are static and they can be passed in the form of [{ value: string, text: string }], User can declare this as value of this field or can pass the function that returns the value in above mentioned format.
299
+ - For setting options dynamically, user can set `hasAsyncFunctionBoundOption`, then they can call `functionBoundAutoCompleteOption` and pass array of objects and id of autocomplete as parameters to that function.
300
+ - OnChange, onBlur, OnClick is emitted on this injectable controls
301
+
269
302
 
270
303
  ##### DropDown:-
271
304
 
@@ -281,3 +314,7 @@
281
314
  functionBoundOption: [{ value: "1", text: "Mobiles" },{ value:"2", text: "Laptops" }], // This field can be a function which return array of Objects or normal array of objects in the form of [{ value: string, text: string }],
282
315
  }
283
316
  ```
317
+ - **Note:-**
318
+ - In this `functionBoundOption` is passed when options are static and they can be passed in the form of [{ value: string, text: string }], User can declare this as value of this field or can pass the function that returns the value in above mentioned format.
319
+ - For setting options dynamically, user can set `hasAsyncFunctionBoundOption`, then they can call `functionBoundOption` and pass array of objects and id of autocomplete as parameters to that function.
320
+ - OnChange, onScroll, OnClick is emitted on this injectable controls