codenotch-react 1.0.11 → 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 -20
  2. package/index.js +33 -31
  3. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -1,33 +1,21 @@
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;
28
- userId?: string;
29
15
  accessToken?: string;
30
16
  baseUrl?: string;
31
17
  }
32
18
 
33
- 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,8 +2,11 @@ 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
- console.log("useCodenotch has been called");
7
10
  return {
8
11
  ENV: CODENOTCH_ENV,
9
12
  requestSioql: async (sioql, verbose) => {
@@ -66,41 +69,40 @@ function useCodenotch() {
66
69
  };
67
70
  }
68
71
 
69
-
72
+ /**
73
+ * Setup Codenotch environment and return Codenotch API
74
+ * @param {*} props Codenotch app properties
75
+ * @returns {Object} Codenotch API
76
+ */
70
77
  function useCodenotchApp(props) {
71
78
  if (props) {
72
- if (props.clusterUrl) {
73
- CODENOTCH_ENV.clusterUrl = props.clusterUrl;
74
- }
75
-
76
- if (props.serviceName) {
77
- CODENOTCH_ENV.serviceName = props.serviceName;
78
- }
79
-
80
- if (props.tenantName) {
81
- CODENOTCH_ENV.tenantName = props.tenantName;
82
- }
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
+ }
83
92
 
84
- if (props.userId) {
85
- CODENOTCH_ENV.userId = props.userId;
86
- }
93
+ return useCodenotch();
94
+ }
87
95
 
88
- if (props.accessToken) {
89
- CODENOTCH_ENV.accessToken = props.accessToken;
90
- }
91
- }
92
- else {
93
- console.warn("useCodenotchApp: No Codenotch configuration provided.");
96
+ class CodenotchApp extends React.Component {
97
+ constructor(props) {
98
+ super(props);
99
+ this.codenotch = useCodenotchApp(props);
94
100
  }
95
101
 
96
- const params = new URL(window.location.href).searchParams;
97
- params.forEach((value, key) => {
98
- if(props[key] === undefined){
99
- props[key] = value;
100
- }
101
- });
102
-
103
- return useCodenotch();
102
+ render() {
103
+ return this.props.children(this.codenotch);
104
+ }
104
105
  }
105
106
 
106
- 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.11",
3
+ "version": "1.0.13",
4
4
  "main": "index.js",
5
5
  "types": "index.d.ts",
6
6
  "type": "module",