codenotch-react 1.0.15 → 1.0.17
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} +36 -58
- package/package.json +15 -5
- package/index.d.ts +0 -21
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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returns {
|
|
4
|
+
* @returns {ICodenotchApi} Codenotch API
|
|
8
5
|
*/
|
|
9
|
-
function useCodenotch() {
|
|
6
|
+
export function useCodenotch() {
|
|
10
7
|
return {
|
|
11
8
|
ENV: CODENOTCH_ENV,
|
|
12
9
|
requestSioql: async (sioql, verbose) => {
|
|
@@ -16,93 +13,74 @@ function useCodenotch() {
|
|
|
16
13
|
if (CODENOTCH_ENV.serviceName === undefined) {
|
|
17
14
|
throw new Error("Codenotch service name is not defined. Please set it in the Codenotch configuration.");
|
|
18
15
|
}
|
|
19
|
-
|
|
20
16
|
let url = `${CODENOTCH_ENV.clusterUrl}/${CODENOTCH_ENV.serviceName}/sioql`;
|
|
21
|
-
|
|
22
17
|
if (verbose) {
|
|
23
18
|
url += "?v=true";
|
|
24
19
|
}
|
|
25
|
-
|
|
26
|
-
let request = {
|
|
20
|
+
const request = {
|
|
27
21
|
method: 'POST',
|
|
28
22
|
mode: 'cors',
|
|
29
|
-
credentials: 'same-origin'
|
|
23
|
+
credentials: 'same-origin',
|
|
24
|
+
headers: {
|
|
25
|
+
'Content-Type': 'application/json'
|
|
26
|
+
}
|
|
30
27
|
};
|
|
31
|
-
|
|
32
|
-
request.headers = {};
|
|
33
|
-
|
|
34
28
|
if (CODENOTCH_ENV.accessToken && CODENOTCH_ENV.accessToken !== "") {
|
|
35
29
|
if (CODENOTCH_ENV.tenantName === undefined) {
|
|
36
30
|
throw new Error("Codenotch tenant name is not defined. Please set it in the Codenotch configuration.");
|
|
37
31
|
}
|
|
38
|
-
|
|
39
|
-
|
|
32
|
+
request.headers = {
|
|
33
|
+
...request.headers,
|
|
34
|
+
[`${CODENOTCH_ENV.tenantName}AccessToken`]: CODENOTCH_ENV.accessToken
|
|
35
|
+
};
|
|
40
36
|
}
|
|
41
|
-
|
|
42
|
-
request.headers['Content-Type'] = 'application/json';
|
|
43
|
-
|
|
44
37
|
request.body = `"${sioql.replace(/\"/g, '\\\"')}"`;
|
|
45
|
-
|
|
46
|
-
let response = await fetch(url, request);
|
|
47
|
-
|
|
38
|
+
const response = await fetch(url, request);
|
|
48
39
|
if (!response.ok) {
|
|
49
|
-
|
|
40
|
+
const error = await response.text();
|
|
50
41
|
throw new Error(error);
|
|
51
42
|
}
|
|
52
|
-
|
|
53
43
|
return await response.json();
|
|
54
44
|
},
|
|
55
|
-
|
|
56
45
|
startProcess: async (processName) => {
|
|
57
|
-
|
|
58
46
|
return { success: true };
|
|
59
47
|
},
|
|
60
|
-
|
|
61
48
|
onSignal: (signalId, callback) => {
|
|
62
49
|
console.log(`Listening to signal ${signalId}`);
|
|
63
50
|
return {
|
|
64
51
|
dispose: () => {
|
|
65
52
|
console.log(`Stopped listening to signal ${signalId}`);
|
|
66
53
|
}
|
|
67
|
-
}
|
|
54
|
+
};
|
|
68
55
|
}
|
|
69
56
|
};
|
|
70
57
|
}
|
|
71
|
-
|
|
72
58
|
/**
|
|
73
59
|
* Setup Codenotch environment and return Codenotch API
|
|
74
|
-
* @param
|
|
75
|
-
* @returns {
|
|
60
|
+
* @param props Codenotch app properties
|
|
61
|
+
* @returns {ICodenotchApi} Codenotch API
|
|
76
62
|
*/
|
|
77
|
-
function useCodenotchApp(props) {
|
|
63
|
+
export function useCodenotchApp(props) {
|
|
78
64
|
if (props) {
|
|
79
|
-
if (props.clusterUrl)
|
|
80
|
-
|
|
81
|
-
if (props.
|
|
82
|
-
|
|
83
|
-
|
|
65
|
+
if (props.clusterUrl)
|
|
66
|
+
CODENOTCH_ENV.clusterUrl = props.clusterUrl;
|
|
67
|
+
if (props.serviceName)
|
|
68
|
+
CODENOTCH_ENV.serviceName = props.serviceName;
|
|
69
|
+
if (props.tenantName)
|
|
70
|
+
CODENOTCH_ENV.tenantName = props.tenantName;
|
|
71
|
+
if (props.accessToken)
|
|
72
|
+
CODENOTCH_ENV.accessToken = props.accessToken;
|
|
84
73
|
// Inject URL parameters as props if they are not already defined
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
props[key]
|
|
89
|
-
|
|
90
|
-
|
|
74
|
+
if (typeof window !== 'undefined') {
|
|
75
|
+
const params = new URL(window.location.href).searchParams;
|
|
76
|
+
params.forEach((value, key) => {
|
|
77
|
+
if (props[key] === undefined) {
|
|
78
|
+
props[key] = value;
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
}
|
|
91
82
|
}
|
|
92
|
-
|
|
93
83
|
return useCodenotch();
|
|
94
84
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
constructor(props) {
|
|
98
|
-
super(props);
|
|
99
|
-
this.codenotch = useCodenotchApp(props);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
render() {
|
|
103
|
-
return this.props.children(this.codenotch);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
module.exports = { useCodenotch, useCodenotchApp, CODENOTCH_ENV, CodenotchApp };
|
|
85
|
+
// Export de l'environnement pour compatibilité
|
|
86
|
+
export { CODENOTCH_ENV };
|
package/package.json
CHANGED
|
@@ -1,11 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "codenotch-react",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"main": "index.js",
|
|
5
|
-
"types": "index.d.ts",
|
|
3
|
+
"version": "1.0.17",
|
|
4
|
+
"main": "dist/index.js",
|
|
5
|
+
"types": "dist/index.d.ts",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"author": "Codenotch SA",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "tsc",
|
|
10
|
+
"dev": "tsc --watch",
|
|
11
|
+
"prepublishOnly": "npm run build",
|
|
12
|
+
"clean": "rm -rf dist"
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist/**/*"
|
|
16
|
+
],
|
|
8
17
|
"devDependencies": {
|
|
9
|
-
"@types/react": "^16.
|
|
18
|
+
"@types/react": "^16.14.69",
|
|
19
|
+
"typescript": "^5.9.3"
|
|
10
20
|
}
|
|
11
|
-
}
|
|
21
|
+
}
|
package/index.d.ts
DELETED
|
@@ -1,21 +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)>;
|
|
20
|
-
|
|
21
|
-
export class CodenotchApp<T, TState> extends React.Component<(ICodenotchEnv & T), TState> {}
|