codenotch-react 1.0.16 → 1.0.18
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/dist/index.d.ts +33 -0
- package/dist/index.d.ts.map +1 -0
- package/{index.js → dist/index.js} +38 -44
- package/package.json +15 -6
- package/index.d.ts +0 -19
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export interface ICodenotchEnv {
|
|
2
|
+
clusterUrl?: string;
|
|
3
|
+
serviceName?: string;
|
|
4
|
+
tenantName?: string;
|
|
5
|
+
accessToken?: string;
|
|
6
|
+
baseUrl?: string;
|
|
7
|
+
[key: string]: any;
|
|
8
|
+
}
|
|
9
|
+
export interface ICodenotchApi {
|
|
10
|
+
ENV: ICodenotchEnv;
|
|
11
|
+
requestSioql: (sioql: string, verbose?: boolean) => Promise<any>;
|
|
12
|
+
startProcess: (processName: string) => Promise<{
|
|
13
|
+
success: boolean;
|
|
14
|
+
}>;
|
|
15
|
+
onSignal: (signalId: string, callback: () => void) => {
|
|
16
|
+
dispose: () => void;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
export type CodenotchAppFC<T> = React.FC<(ICodenotchEnv & T)>;
|
|
20
|
+
declare const CODENOTCH_ENV: ICodenotchEnv;
|
|
21
|
+
/**
|
|
22
|
+
* Return Codenotch API
|
|
23
|
+
* @returns {ICodenotchApi} Codenotch API
|
|
24
|
+
*/
|
|
25
|
+
export declare function useCodenotch(): ICodenotchApi;
|
|
26
|
+
/**
|
|
27
|
+
* Setup Codenotch environment and return Codenotch API
|
|
28
|
+
* @param props Codenotch app properties
|
|
29
|
+
* @returns {ICodenotchApi} Codenotch API
|
|
30
|
+
*/
|
|
31
|
+
export declare function useCodenotchApp(props?: ICodenotchEnv): ICodenotchApi;
|
|
32
|
+
export { CODENOTCH_ENV };
|
|
33
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa;IAC1B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACtB;AAED,MAAM,WAAW,aAAa;IAC1B,GAAG,EAAE,aAAa,CAAC;IACnB,YAAY,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC;IACjE,YAAY,EAAE,CAAC,WAAW,EAAE,MAAM,KAAK,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC;IACrE,QAAQ,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,IAAI,KAAK;QAAE,OAAO,EAAE,MAAM,IAAI,CAAA;KAAE,CAAC;CACjF;AAED,MAAM,MAAM,cAAc,CAAC,CAAC,IAAI,KAAK,CAAC,EAAE,CAAC,CAAC,aAAa,GAAG,CAAC,CAAC,CAAC,CAAC;AAE9D,QAAA,MAAM,aAAa,EAAE,aAAkB,CAAC;AAExC;;;GAGG;AACH,wBAAgB,YAAY,IAAI,aAAa,CA8D5C;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,KAAK,CAAC,EAAE,aAAa,GAAG,aAAa,CAmBpE;AAGD,OAAO,EAAE,aAAa,EAAE,CAAC"}
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CODENOTCH_ENV = void 0;
|
|
4
|
+
exports.useCodenotch = useCodenotch;
|
|
5
|
+
exports.useCodenotchApp = useCodenotchApp;
|
|
6
|
+
const CODENOTCH_ENV = {};
|
|
7
|
+
exports.CODENOTCH_ENV = CODENOTCH_ENV;
|
|
5
8
|
/**
|
|
6
9
|
* Return Codenotch API
|
|
7
|
-
* @returns {
|
|
10
|
+
* @returns {ICodenotchApi} Codenotch API
|
|
8
11
|
*/
|
|
9
12
|
function useCodenotch() {
|
|
10
13
|
return {
|
|
@@ -16,81 +19,72 @@ function useCodenotch() {
|
|
|
16
19
|
if (CODENOTCH_ENV.serviceName === undefined) {
|
|
17
20
|
throw new Error("Codenotch service name is not defined. Please set it in the Codenotch configuration.");
|
|
18
21
|
}
|
|
19
|
-
|
|
20
22
|
let url = `${CODENOTCH_ENV.clusterUrl}/${CODENOTCH_ENV.serviceName}/sioql`;
|
|
21
|
-
|
|
22
23
|
if (verbose) {
|
|
23
24
|
url += "?v=true";
|
|
24
25
|
}
|
|
25
|
-
|
|
26
|
-
let request = {
|
|
26
|
+
const request = {
|
|
27
27
|
method: 'POST',
|
|
28
28
|
mode: 'cors',
|
|
29
|
-
credentials: 'same-origin'
|
|
29
|
+
credentials: 'same-origin',
|
|
30
|
+
headers: {
|
|
31
|
+
'Content-Type': 'application/json'
|
|
32
|
+
}
|
|
30
33
|
};
|
|
31
|
-
|
|
32
|
-
request.headers = {};
|
|
33
|
-
|
|
34
34
|
if (CODENOTCH_ENV.accessToken && CODENOTCH_ENV.accessToken !== "") {
|
|
35
35
|
if (CODENOTCH_ENV.tenantName === undefined) {
|
|
36
36
|
throw new Error("Codenotch tenant name is not defined. Please set it in the Codenotch configuration.");
|
|
37
37
|
}
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
request.headers = {
|
|
39
|
+
...request.headers,
|
|
40
|
+
[`${CODENOTCH_ENV.tenantName}AccessToken`]: CODENOTCH_ENV.accessToken
|
|
41
|
+
};
|
|
40
42
|
}
|
|
41
|
-
|
|
42
|
-
request.headers['Content-Type'] = 'application/json';
|
|
43
|
-
|
|
44
43
|
request.body = `"${sioql.replace(/\"/g, '\\\"')}"`;
|
|
45
|
-
|
|
46
|
-
let response = await fetch(url, request);
|
|
47
|
-
|
|
44
|
+
const response = await fetch(url, request);
|
|
48
45
|
if (!response.ok) {
|
|
49
|
-
|
|
46
|
+
const error = await response.text();
|
|
50
47
|
throw new Error(error);
|
|
51
48
|
}
|
|
52
|
-
|
|
53
49
|
return await response.json();
|
|
54
50
|
},
|
|
55
|
-
|
|
56
51
|
startProcess: async (processName) => {
|
|
57
|
-
|
|
58
52
|
return { success: true };
|
|
59
53
|
},
|
|
60
|
-
|
|
61
54
|
onSignal: (signalId, callback) => {
|
|
62
55
|
console.log(`Listening to signal ${signalId}`);
|
|
63
56
|
return {
|
|
64
57
|
dispose: () => {
|
|
65
58
|
console.log(`Stopped listening to signal ${signalId}`);
|
|
66
59
|
}
|
|
67
|
-
}
|
|
60
|
+
};
|
|
68
61
|
}
|
|
69
62
|
};
|
|
70
63
|
}
|
|
71
|
-
|
|
72
64
|
/**
|
|
73
65
|
* Setup Codenotch environment and return Codenotch API
|
|
74
|
-
* @param
|
|
75
|
-
* @returns {
|
|
66
|
+
* @param props Codenotch app properties
|
|
67
|
+
* @returns {ICodenotchApi} Codenotch API
|
|
76
68
|
*/
|
|
77
69
|
function useCodenotchApp(props) {
|
|
78
70
|
if (props) {
|
|
79
|
-
if (props.clusterUrl)
|
|
80
|
-
|
|
81
|
-
if (props.
|
|
82
|
-
|
|
83
|
-
|
|
71
|
+
if (props.clusterUrl)
|
|
72
|
+
CODENOTCH_ENV.clusterUrl = props.clusterUrl;
|
|
73
|
+
if (props.serviceName)
|
|
74
|
+
CODENOTCH_ENV.serviceName = props.serviceName;
|
|
75
|
+
if (props.tenantName)
|
|
76
|
+
CODENOTCH_ENV.tenantName = props.tenantName;
|
|
77
|
+
if (props.accessToken)
|
|
78
|
+
CODENOTCH_ENV.accessToken = props.accessToken;
|
|
84
79
|
// Inject URL parameters as props if they are not already defined
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
props[key]
|
|
89
|
-
|
|
90
|
-
|
|
80
|
+
if (typeof window !== 'undefined') {
|
|
81
|
+
const params = new URL(window.location.href).searchParams;
|
|
82
|
+
params.forEach((value, key) => {
|
|
83
|
+
if (props[key] === undefined) {
|
|
84
|
+
props[key] = value;
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
}
|
|
91
88
|
}
|
|
92
|
-
|
|
93
89
|
return useCodenotch();
|
|
94
90
|
}
|
|
95
|
-
|
|
96
|
-
module.exports = { useCodenotch, useCodenotchApp, CODENOTCH_ENV };
|
package/package.json
CHANGED
|
@@ -1,11 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "codenotch-react",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"main": "index.js",
|
|
5
|
-
"types": "index.d.ts",
|
|
6
|
-
"type": "module",
|
|
3
|
+
"version": "1.0.18",
|
|
4
|
+
"main": "dist/index.js",
|
|
5
|
+
"types": "dist/index.d.ts",
|
|
7
6
|
"author": "Codenotch SA",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "tsc",
|
|
9
|
+
"dev": "tsc --watch",
|
|
10
|
+
"prepublishOnly": "npm run build",
|
|
11
|
+
"clean": "rm -rf dist"
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"dist/**/*"
|
|
15
|
+
],
|
|
8
16
|
"devDependencies": {
|
|
9
|
-
"@types/react": "^16.
|
|
17
|
+
"@types/react": "^16.14.69",
|
|
18
|
+
"typescript": "^5.9.3"
|
|
10
19
|
}
|
|
11
|
-
}
|
|
20
|
+
}
|
package/index.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
export interface ICodenotchApi {
|
|
2
|
-
ENV: ICodenotchEnv,
|
|
3
|
-
|
|
4
|
-
requestSioql: (sioql: string) => Promise<any>;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export function useCodenotch(): ICodenotchApi;
|
|
8
|
-
|
|
9
|
-
export function useCodenotchApp(props: ICodenotchEnv): ICodenotchApi;
|
|
10
|
-
|
|
11
|
-
export interface ICodenotchEnv {
|
|
12
|
-
clusterUrl?: string;
|
|
13
|
-
serviceName?: string;
|
|
14
|
-
tenantName?: string;
|
|
15
|
-
accessToken?: string;
|
|
16
|
-
baseUrl?: string;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export type CodenotchAppFC<T> = React.FC<(ICodenotchEnv & T)>;
|