codenotch-react 1.0.34 → 1.0.36
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 +7 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +65 -29
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,12 @@ export interface ICodenotchEnv {
|
|
|
4
4
|
tenantName?: string;
|
|
5
5
|
accessToken?: string;
|
|
6
6
|
baseUrl?: string;
|
|
7
|
-
|
|
7
|
+
i18n?: {
|
|
8
|
+
[language: string]: {
|
|
9
|
+
[key: string]: string;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
currentLanguage?: string;
|
|
8
13
|
[key: string]: any;
|
|
9
14
|
}
|
|
10
15
|
export interface ICodenotchApi {
|
|
@@ -16,8 +21,8 @@ export interface ICodenotchApi {
|
|
|
16
21
|
onSignal: (signalId: string, callback: () => void) => {
|
|
17
22
|
dispose: () => void;
|
|
18
23
|
};
|
|
24
|
+
i18n: (key: string, ...args: any[]) => string;
|
|
19
25
|
}
|
|
20
|
-
export type CodenotchAppFC<T> = React.FC<(ICodenotchEnv & T)>;
|
|
21
26
|
declare const CODENOTCH_ENV: ICodenotchEnv;
|
|
22
27
|
export declare function setupCodenotchEnv(env: any): void;
|
|
23
28
|
/**
|
|
@@ -25,11 +30,5 @@ export declare function setupCodenotchEnv(env: any): void;
|
|
|
25
30
|
* @returns {ICodenotchApi} Codenotch API
|
|
26
31
|
*/
|
|
27
32
|
export declare function useCodenotch(): ICodenotchApi;
|
|
28
|
-
/**
|
|
29
|
-
* Setup Codenotch environment and return Codenotch API
|
|
30
|
-
* @param props Codenotch app properties
|
|
31
|
-
* @returns {ICodenotchApi} Codenotch API
|
|
32
|
-
*/
|
|
33
|
-
export declare function useCodenotchApp(props?: ICodenotchEnv): ICodenotchApi;
|
|
34
33
|
export { CODENOTCH_ENV };
|
|
35
34
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +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,
|
|
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,IAAI,CAAC,EAAE;QAAE,CAAC,QAAQ,EAAE,MAAM,GAAG;YAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;SAAE,CAAA;KAAE,CAAC;IACzD,eAAe,CAAC,EAAE,MAAM,CAAC;IAEzB,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;IAC9E,IAAI,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,MAAM,CAAC;CACjD;AAED,QAAA,MAAM,aAAa,EAAE,aAAkB,CAAC;AAExC,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,GAAG,GAAG,IAAI,CA4ChD;AAED;;;GAGG;AACH,wBAAgB,YAAY,IAAI,aAAa,CAmG5C;AAGD,OAAO,EAAE,aAAa,EAAE,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.CODENOTCH_ENV = void 0;
|
|
4
4
|
exports.setupCodenotchEnv = setupCodenotchEnv;
|
|
5
5
|
exports.useCodenotch = useCodenotch;
|
|
6
|
-
exports.useCodenotchApp = useCodenotchApp;
|
|
7
6
|
const CODENOTCH_ENV = {};
|
|
8
7
|
exports.CODENOTCH_ENV = CODENOTCH_ENV;
|
|
9
8
|
function setupCodenotchEnv(env) {
|
|
@@ -11,9 +10,41 @@ function setupCodenotchEnv(env) {
|
|
|
11
10
|
console.warn("Codenotch environment is not defined. Please set it in the Codenotch configuration.");
|
|
12
11
|
return;
|
|
13
12
|
}
|
|
13
|
+
// i18n.fr.somekey=some value
|
|
14
|
+
let i18nLanguages = new Set();
|
|
14
15
|
Object.keys(env).forEach((key) => {
|
|
15
|
-
|
|
16
|
+
if (key.startsWith("i18n.")) {
|
|
17
|
+
// Special case
|
|
18
|
+
let parts = key.split(".");
|
|
19
|
+
let language = parts[1];
|
|
20
|
+
let keyName = parts.slice(2).join(".");
|
|
21
|
+
i18nLanguages.add(language);
|
|
22
|
+
let keyValue = `${env[key]}`.trim();
|
|
23
|
+
if (keyValue.startsWith('"') && keyValue.endsWith('"')) {
|
|
24
|
+
// Parse like json
|
|
25
|
+
try {
|
|
26
|
+
keyValue = JSON.parse(keyValue);
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
console.warn(`Codenotch environment variable ${key} is not a valid JSON string. Using raw value.`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
CODENOTCH_ENV.i18n = CODENOTCH_ENV.i18n ?? {};
|
|
33
|
+
CODENOTCH_ENV.i18n[language] = CODENOTCH_ENV.i18n[language] ?? {};
|
|
34
|
+
CODENOTCH_ENV.i18n[language][keyName] = keyValue;
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
CODENOTCH_ENV[key] = env[key];
|
|
38
|
+
console.log(`Codenotch environment variable ${key} set to ${env[key]}`);
|
|
39
|
+
}
|
|
16
40
|
});
|
|
41
|
+
if (CODENOTCH_ENV.currentLanguage === undefined) {
|
|
42
|
+
// If current language is not defined, we set it to the first language found in i18n
|
|
43
|
+
if (i18nLanguages.size > 0) {
|
|
44
|
+
CODENOTCH_ENV.currentLanguage = Array.from(i18nLanguages)[0];
|
|
45
|
+
console.log(`Codenotch current language set to ${CODENOTCH_ENV.currentLanguage}`);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
17
48
|
}
|
|
18
49
|
/**
|
|
19
50
|
* Return Codenotch API
|
|
@@ -22,6 +53,38 @@ function setupCodenotchEnv(env) {
|
|
|
22
53
|
function useCodenotch() {
|
|
23
54
|
return {
|
|
24
55
|
ENV: CODENOTCH_ENV,
|
|
56
|
+
i18n: (key, ...args) => {
|
|
57
|
+
try {
|
|
58
|
+
if (CODENOTCH_ENV.i18n === undefined || Object.keys(CODENOTCH_ENV.i18n).length === 0) {
|
|
59
|
+
console.warn("Codenotch i18n is not defined. Please set it in the Codenotch configuration.");
|
|
60
|
+
return key;
|
|
61
|
+
}
|
|
62
|
+
let language = CODENOTCH_ENV.currentLanguage ?? "en";
|
|
63
|
+
let isLanguageExists = CODENOTCH_ENV.i18n[language] !== undefined;
|
|
64
|
+
if (isLanguageExists === false) {
|
|
65
|
+
let fallbackLanguage = Object.keys(CODENOTCH_ENV.i18n)[0];
|
|
66
|
+
console.warn(`Codenotch i18n language ${language} is not defined. Falling back to ${fallbackLanguage}. Please set the correct language in the Codenotch configuration.`);
|
|
67
|
+
language = fallbackLanguage;
|
|
68
|
+
}
|
|
69
|
+
let dico = CODENOTCH_ENV.i18n[language];
|
|
70
|
+
let value = dico[key];
|
|
71
|
+
if (typeof value !== "string") {
|
|
72
|
+
console.warn(`Codenotch i18n key ${key} is not defined for language ${language}. Please set it in the Codenotch configuration.`);
|
|
73
|
+
return key;
|
|
74
|
+
}
|
|
75
|
+
args = args ?? [];
|
|
76
|
+
let result = value.replace(/{([\d ]*)}/g, (match, p1) => {
|
|
77
|
+
let argValue = args[p1.trim()];
|
|
78
|
+
// Instead of returning 'undefined', returns an empty string
|
|
79
|
+
return argValue !== undefined ? argValue : "";
|
|
80
|
+
});
|
|
81
|
+
return result;
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
console.error("Error in i18n function:", error);
|
|
85
|
+
return key;
|
|
86
|
+
}
|
|
87
|
+
},
|
|
25
88
|
requestSioql: async (sioql, verbose) => {
|
|
26
89
|
if (CODENOTCH_ENV.clusterUrl === undefined) {
|
|
27
90
|
throw new Error("Codenotch cluster URL is not defined. Please set it in the Codenotch configuration.");
|
|
@@ -71,30 +134,3 @@ function useCodenotch() {
|
|
|
71
134
|
}
|
|
72
135
|
};
|
|
73
136
|
}
|
|
74
|
-
/**
|
|
75
|
-
* Setup Codenotch environment and return Codenotch API
|
|
76
|
-
* @param props Codenotch app properties
|
|
77
|
-
* @returns {ICodenotchApi} Codenotch API
|
|
78
|
-
*/
|
|
79
|
-
function useCodenotchApp(props) {
|
|
80
|
-
if (props) {
|
|
81
|
-
if (props.clusterUrl)
|
|
82
|
-
CODENOTCH_ENV.clusterUrl = props.clusterUrl;
|
|
83
|
-
if (props.serviceName)
|
|
84
|
-
CODENOTCH_ENV.serviceName = props.serviceName;
|
|
85
|
-
if (props.tenantName)
|
|
86
|
-
CODENOTCH_ENV.tenantName = props.tenantName;
|
|
87
|
-
if (props.accessToken)
|
|
88
|
-
CODENOTCH_ENV.accessToken = props.accessToken;
|
|
89
|
-
// Inject URL parameters as props if they are not already defined
|
|
90
|
-
if (typeof window !== 'undefined') {
|
|
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
|
-
}
|
|
98
|
-
}
|
|
99
|
-
return useCodenotch();
|
|
100
|
-
}
|