codenotch-react 1.0.12 → 1.0.13

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.
Files changed (3) hide show
  1. package/index.d.ts +8 -19
  2. package/index.js +33 -26
  3. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -1,27 +1,14 @@
1
- export interface ICodenotch {
2
- ENV: ICodenotchAppProps,
1
+ export interface ICodenotchApi {
2
+ ENV: ICodenotchEnv,
3
3
 
4
4
  requestSioql: (sioql: string) => Promise<any>;
5
-
6
- startProcess: (processName: string) => Promise<IProcessResult>;
7
-
8
- onSignal: (signalId: string, callback: (data: any) => void) => IDisposable;
9
-
10
- }
11
-
12
- interface IDisposable {
13
- dispose(): void;
14
- }
15
-
16
- interface IProcessResult {
17
- success: boolean;
18
5
  }
19
6
 
20
- export function useCodenotch(): ICodenotch;
7
+ export function useCodenotch(): ICodenotchApi;
21
8
 
22
- export function useCodenotchApp(props: ICodenotchAppProps): ICodenotch;
9
+ export function useCodenotchApp(props: ICodenotchEnv): ICodenotchApi;
23
10
 
24
- export interface ICodenotchAppProps {
11
+ export interface ICodenotchEnv {
25
12
  clusterUrl?: string;
26
13
  serviceName?: string;
27
14
  tenantName?: string;
@@ -29,4 +16,6 @@ export interface ICodenotchAppProps {
29
16
  baseUrl?: string;
30
17
  }
31
18
 
32
- export type CodenotchApp<T> = React.FC<(ICodenotchAppProps & T)>;
19
+ export type CodenotchFC<T> = React.FC<(ICodenotchEnv & T)>;
20
+
21
+ export type CodenotchComponent<T> = React.ComponentType<(ICodenotchEnv & T)>;
package/index.js CHANGED
@@ -2,6 +2,10 @@ const CODENOTCH_ENV = {
2
2
 
3
3
  };
4
4
 
5
+ /**
6
+ * Return Codenotch API
7
+ * @returns {Object} Codenotch API
8
+ */
5
9
  function useCodenotch() {
6
10
  return {
7
11
  ENV: CODENOTCH_ENV,
@@ -65,37 +69,40 @@ function useCodenotch() {
65
69
  };
66
70
  }
67
71
 
68
-
72
+ /**
73
+ * Setup Codenotch environment and return Codenotch API
74
+ * @param {*} props Codenotch app properties
75
+ * @returns {Object} Codenotch API
76
+ */
69
77
  function useCodenotchApp(props) {
70
78
  if (props) {
71
- if (props.clusterUrl) {
72
- CODENOTCH_ENV.clusterUrl = props.clusterUrl;
73
- }
74
-
75
- if (props.serviceName) {
76
- CODENOTCH_ENV.serviceName = props.serviceName;
77
- }
79
+ if (props.clusterUrl) CODENOTCH_ENV.clusterUrl = props.clusterUrl;
80
+ if (props.serviceName) CODENOTCH_ENV.serviceName = props.serviceName;
81
+ if (props.tenantName) CODENOTCH_ENV.tenantName = props.tenantName;
82
+ if (props.accessToken) CODENOTCH_ENV.accessToken = props.accessToken;
83
+
84
+ // Inject URL parameters as props if they are not already defined
85
+ const params = new URL(window.location.href).searchParams;
86
+ params.forEach((value, key) => {
87
+ if(props[key] === undefined){
88
+ props[key] = value;
89
+ }
90
+ });
91
+ }
78
92
 
79
- if (props.tenantName) {
80
- CODENOTCH_ENV.tenantName = props.tenantName;
81
- }
93
+ return useCodenotch();
94
+ }
82
95
 
83
- if (props.accessToken) {
84
- CODENOTCH_ENV.accessToken = props.accessToken;
85
- }
96
+ class CodenotchApp extends React.Component {
97
+ constructor(props) {
98
+ super(props);
99
+ this.codenotch = useCodenotchApp(props);
86
100
  }
87
- else {
88
- console.warn("useCodenotchApp: No Codenotch configuration provided.");
89
- }
90
-
91
- const params = new URL(window.location.href).searchParams;
92
- params.forEach((value, key) => {
93
- if(props[key] === undefined){
94
- props[key] = value;
95
- }
96
- });
97
101
 
98
- return useCodenotch();
102
+ render() {
103
+ return this.props.children(this.codenotch);
104
+ }
99
105
  }
100
106
 
101
- module.exports = { useCodenotch, useCodenotchApp };
107
+
108
+ module.exports = { useCodenotch, useCodenotchApp, CODENOTCH_ENV, CodenotchApp };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codenotch-react",
3
- "version": "1.0.12",
3
+ "version": "1.0.13",
4
4
  "main": "index.js",
5
5
  "types": "index.d.ts",
6
6
  "type": "module",