@centreon/js-config 24.10.1 → 24.10.3

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 (33) hide show
  1. package/cypress/component/commands.tsx +22 -82
  2. package/cypress/component/configuration.js +16 -39
  3. package/cypress/component/enableVisualTesting.ts +1 -1
  4. package/cypress/e2e/commands/configuration.ts +1 -330
  5. package/cypress/e2e/commands.ts +175 -623
  6. package/cypress/e2e/configuration.ts +40 -46
  7. package/cypress/e2e/plugins.ts +114 -52
  8. package/eslint/base.typescript.eslintrc.js +3 -15
  9. package/jest/index.js +2 -5
  10. package/package.json +45 -57
  11. package/tsconfig/index.json +4 -5
  12. package/webpack/base/index.js +130 -0
  13. package/webpack/patch/dev.js +24 -0
  14. package/{rspack → webpack}/patch/devServer.js +8 -4
  15. package/webpack/patch/module.js +46 -0
  16. package/biome/base.json +0 -224
  17. package/cypress/component/disableCssTransitions.ts +0 -19
  18. package/cypress/component/excludeNodeModulesFromCoverage.js +0 -36
  19. package/cypress/e2e/commands/monitoring.ts +0 -225
  20. package/cypress/e2e/esbuild-preprocessor.ts +0 -26
  21. package/cypress/e2e/reporter-config.js +0 -13
  22. package/cypress/e2e/tasks.ts +0 -259
  23. package/eslint/lambda/typescript.eslintrc.js +0 -48
  24. package/jest/lambda/typescript.js +0 -49
  25. package/rspack/base/globalConfig.js +0 -71
  26. package/rspack/base/index.js +0 -89
  27. package/rspack/patch/dev.js +0 -12
  28. package/rspack/patch/module.js +0 -13
  29. package/rspack/plugins/TransformPreloadScript.js +0 -37
  30. package/rspack/plugins/WriteRemoteEntryNameToModuleFederation.js +0 -30
  31. package/tsconfig/lambda/node20.tsconfig.json +0 -12
  32. package/tsconfig/lambda/tsconfig.json +0 -14
  33. package/tsconfig.json +0 -21
@@ -1,6 +1,6 @@
1
1
  const os = require('os');
2
2
 
3
- const ReactRefreshPlugin = require('@rspack/plugin-react-refresh');
3
+ const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin');
4
4
 
5
5
  const devServerPort = 9090;
6
6
 
@@ -13,13 +13,16 @@ const externalInterface = Object.keys(interfaces).find(
13
13
  !process.env.IS_STATIC_PORT_FORWARDED
14
14
  );
15
15
 
16
- const devServerAddress = 'localhost';
16
+ const devServerAddress = externalInterface
17
+ ? interfaces[externalInterface][0].address
18
+ : 'localhost';
17
19
 
18
20
  const publicPath = `http://${devServerAddress}:${devServerPort}/static/`;
19
21
 
20
- const isDevelopmentMode = process.env.NODE_ENV !== 'production';
22
+ const isServeMode = process.env.WEBPACK_ENV === 'serve';
23
+ const isDevelopmentMode = process.env.WEBPACK_ENV === 'development';
21
24
 
22
- const devServerPlugins = isDevelopmentMode ? [new ReactRefreshPlugin()] : [];
25
+ const devServerPlugins = isServeMode ? [new ReactRefreshWebpackPlugin()] : [];
23
26
 
24
27
  module.exports = {
25
28
  devServer: {
@@ -29,5 +32,6 @@ module.exports = {
29
32
  },
30
33
  devServerPlugins,
31
34
  isDevelopmentMode,
35
+ isServeMode,
32
36
  publicPath
33
37
  };
@@ -0,0 +1,46 @@
1
+ const fs = require('fs');
2
+ const { CleanWebpackPlugin } = require('clean-webpack-plugin');
3
+
4
+ class CentreonModulePlugin {
5
+ constructor(federatedComponentConfiguration) {
6
+ this.federatedComponentConfiguration = federatedComponentConfiguration;
7
+ }
8
+
9
+ apply(compiler) {
10
+ compiler.hooks.done.tap('CentreonModulePlugin', (stats) => {
11
+ const newFederatedComponentConfiguration = {
12
+ ...this.federatedComponentConfiguration,
13
+ remoteEntry: Object.keys(stats.compilation.assets).find((assetName) =>
14
+ assetName.match(/(^remoteEntry)\S+.js$/),
15
+ ),
16
+ };
17
+
18
+ if (!fs.existsSync(compiler.options.output.path)) {
19
+ fs.mkdirSync(compiler.options.output.path, { recursive: true });
20
+ }
21
+
22
+ fs.writeFileSync(
23
+ `${compiler.options.output.path}/moduleFederation.json`,
24
+ JSON.stringify(newFederatedComponentConfiguration, null, 2),
25
+ );
26
+ });
27
+ }
28
+ }
29
+
30
+ module.exports = ({
31
+ outputPath,
32
+ federatedComponentConfiguration,
33
+ }) => ({
34
+ output: {
35
+ library: '[chunkhash:8]',
36
+ path: outputPath,
37
+ },
38
+ plugins: [
39
+ new CleanWebpackPlugin({
40
+ cleanOnceBeforeBuildPatterns: [`${outputPath}/**/*.js`],
41
+ dangerouslyAllowCleanPatternsOutsideProject: true,
42
+ dry: false,
43
+ }),
44
+ new CentreonModulePlugin(federatedComponentConfiguration),
45
+ ],
46
+ });
package/biome/base.json DELETED
@@ -1,224 +0,0 @@
1
- {
2
- "formatter": {
3
- "enabled": true,
4
- "indentStyle": "space",
5
- "formatWithErrors": false
6
- },
7
- "organizeImports": {
8
- "enabled": true
9
- },
10
- "linter": {
11
- "enabled": true,
12
- "rules": {
13
- "recommended": true,
14
- "a11y": {
15
- "noSvgWithoutTitle": "off"
16
- },
17
- "complexity": {
18
- "noBannedTypes": "off",
19
- "noForEach": "off"
20
- },
21
- "correctness": {
22
- "noUnusedImports": "error",
23
- "noUnusedVariables": "error",
24
- "useExhaustiveDependencies": "off"
25
- },
26
- "nursery": {
27
- "noConsole": "error",
28
- "noRestrictedImports": {
29
- "level": "error",
30
- "options": {
31
- "paths": {
32
- "lodash": "Using lodash is not encouraged.",
33
- "moment": "Using moment is not encouraged."
34
- }
35
- }
36
- },
37
- "noUnknownFunction": "error",
38
- "noUnknownProperty": "error",
39
- "noUnknownUnit": "error"
40
- },
41
- "suspicious": {
42
- "useAwait": "error"
43
- },
44
- "performance": {
45
- "noAccumulatingSpread": "off"
46
- },
47
- "style": {
48
- "useLiteralEnumMembers": "off",
49
- "useImportType": "off",
50
- "noNamespace": "error",
51
- "noNamespaceImport": "error",
52
- "useFragmentSyntax": "error",
53
- "useFilenamingConvention": {
54
- "level": "error",
55
- "options": {
56
- "strictCase": false,
57
- "filenameCases": [
58
- "camelCase",
59
- "PascalCase",
60
- "kebab-case"
61
- ]
62
- }
63
- },
64
- "useNamingConvention": {
65
- "level": "error",
66
- "options": {
67
- "strictCase": false,
68
- "conventions": [
69
- {
70
- "formats": [
71
- "camelCase",
72
- "PascalCase"
73
- ],
74
- "selector": {
75
- "kind": "variable"
76
- }
77
- },
78
- {
79
- "selector": {
80
- "kind": "interface"
81
- },
82
- "formats": [
83
- "PascalCase"
84
- ]
85
- },
86
- {
87
- "selector": {
88
- "kind": "enum"
89
- },
90
- "formats": [
91
- "PascalCase"
92
- ]
93
- },
94
- {
95
- "selector": {
96
- "kind": "objectLiteralProperty"
97
- },
98
- "match": ".*"
99
- },
100
- {
101
- "match": "_(.*)|([a-zA-Z].*)",
102
- "selector": {
103
- "kind": "functionParameter"
104
- },
105
- "formats": [
106
- "snake_case",
107
- "PascalCase",
108
- "camelCase"
109
- ]
110
- },
111
- {
112
- "match": ".*",
113
- "formats": [
114
- "snake_case",
115
- "camelCase",
116
- "PascalCase",
117
- "CONSTANT_CASE"
118
- ]
119
- }
120
- ]
121
- }
122
- },
123
- "noRestrictedGlobals": {
124
- "level": "error",
125
- "options": {
126
- "deniedGlobals": [
127
- "isFinite",
128
- "isNaN",
129
- "addEventListener",
130
- "blur",
131
- "close",
132
- "closed",
133
- "confirm",
134
- "defaultStatus",
135
- "defaultstatus",
136
- "event",
137
- "external",
138
- "find",
139
- "focus",
140
- "frameElement",
141
- "frames",
142
- "history",
143
- "innerHeight",
144
- "innerWidth",
145
- "length",
146
- "location",
147
- "locationbar",
148
- "menubar",
149
- "moveBy",
150
- "moveTo",
151
- "name",
152
- "onblur",
153
- "onerror",
154
- "onfocus",
155
- "onload",
156
- "onresize",
157
- "onunload",
158
- "open",
159
- "opener",
160
- "opera",
161
- "outerHeight",
162
- "outerWidth",
163
- "pageXOffset",
164
- "pageYOffset",
165
- "parent",
166
- "print",
167
- "removeEventListener",
168
- "resizeBy",
169
- "resizeTo",
170
- "screen",
171
- "screenLeft",
172
- "screenTop",
173
- "screenX",
174
- "screenY",
175
- "scroll",
176
- "scrollbars",
177
- "scrollBy",
178
- "scrollTo",
179
- "scrollX",
180
- "scrollY",
181
- "self",
182
- "status",
183
- "statusbar",
184
- "stop",
185
- "toolbar",
186
- "top"
187
- ]
188
- }
189
- }
190
- }
191
- }
192
- },
193
- "javascript": {
194
- "formatter": {
195
- "enabled": true,
196
- "quoteStyle": "single",
197
- "semicolons": "always",
198
- "indentStyle": "space",
199
- "trailingCommas": "none"
200
- },
201
- "linter": {
202
- "enabled": true
203
- }
204
- },
205
- "json": {
206
- "parser": {
207
- "allowComments": true,
208
- "allowTrailingCommas": false
209
- },
210
- "formatter": {
211
- "enabled": true,
212
- "indentStyle": "space"
213
- }
214
- },
215
- "css": {
216
- "formatter": {
217
- "enabled": true,
218
- "indentStyle": "space"
219
- },
220
- "linter": {
221
- "enabled": true
222
- }
223
- }
224
- }
@@ -1,19 +0,0 @@
1
- const disableMotion = (win): void => {
2
- const injectedStyleEl = win.document.getElementById('__cy_disable_motion__');
3
- if (injectedStyleEl) {
4
- return;
5
- }
6
- win.document.head.insertAdjacentHTML(
7
- 'beforeend',
8
- `
9
- <style id="__cy_disable_motion__">
10
- /* Disable CSS transitions. */
11
- *, *::before, *::after { -webkit-transition: none !important; -moz-transition: none !important; -o-transition: none !important; -ms-transition: none !important; transition: none !important; }
12
- /* Disable CSS animations. */
13
- *, *::before, *::after { -webkit-animation: none !important; -moz-animation: none !important; -o-animation: none !important; -ms-animation: none !important; animation: none !important; }
14
- </style>
15
- `.trim()
16
- );
17
- };
18
-
19
- export default disableMotion;
@@ -1,36 +0,0 @@
1
- const fs = require('fs');
2
- const path = require('path');
3
-
4
- const filePath = process.argv[2];
5
-
6
- const { error: logError } = console;
7
-
8
- try {
9
- const outFile = fs.readFileSync(path.resolve(filePath)).toString();
10
- const outFileJson = JSON.parse(outFile);
11
-
12
- const coveragesWithoutNodeModules = Object.entries(outFileJson)
13
- .map(([key, value]) => {
14
- if (key.includes('node_modules')) {
15
- return undefined;
16
- }
17
-
18
- return [key, value];
19
- })
20
- .filter((v) => v);
21
-
22
- const finalOutJson = coveragesWithoutNodeModules.reduce(
23
- (acc, [key, value]) => ({
24
- ...acc,
25
- [key]: value
26
- }),
27
- {}
28
- );
29
-
30
- fs.writeFileSync(
31
- path.resolve(filePath),
32
- JSON.stringify(finalOutJson, null, 2)
33
- );
34
- } catch (error) {
35
- logError(error.message);
36
- }
@@ -1,225 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-namespace */
2
-
3
- const apiBase = '/centreon/api';
4
- const apiActionV1 = `${apiBase}/index.php`;
5
-
6
- const getStatusNumberFromString = (status: string): number => {
7
- const statuses = {
8
- critical: '2',
9
- down: '1',
10
- ok: '0',
11
- unknown: '3',
12
- unreachable: '2',
13
- up: '0',
14
- warning: '1'
15
- };
16
-
17
- if (status in statuses) {
18
- return statuses[status];
19
- }
20
-
21
- throw new Error(`Status ${status} does not exist`);
22
- };
23
-
24
- interface HostCheck {
25
- host: string;
26
- isForced?: boolean;
27
- }
28
-
29
- Cypress.Commands.add(
30
- 'scheduleHostCheck',
31
- ({
32
- host,
33
- isForced = true
34
- }: ServiceCheck): Cypress.Chainable => {
35
- let query = `SELECT id FROM resources WHERE name = '${host}' AND type = 1`;
36
-
37
- return cy
38
- .requestOnDatabase({
39
- database: 'centreon_storage',
40
- query
41
- })
42
- .then(([rows]) => {
43
- if (rows.length === 0) {
44
- throw new Error(`Cannot find host ${host}`);
45
- }
46
-
47
- const hostId = rows[0].id;
48
-
49
- return cy.request({
50
- body: {
51
- check: {
52
- is_forced: isForced
53
- },
54
- resources: [
55
- {
56
- id: hostId,
57
- parent: null,
58
- type: 'host'
59
- }
60
- ]
61
- },
62
- method: 'POST',
63
- timeout: 30000,
64
- url: '/centreon/api/latest/monitoring/resources/check'
65
- }).then((response) => {
66
- expect(response.status).to.eq(204);
67
-
68
- return cy.wrap(null);
69
- });
70
- });
71
- }
72
- );
73
-
74
- interface ServiceCheck {
75
- host: string;
76
- isForced?: boolean;
77
- service: string;
78
- }
79
-
80
- Cypress.Commands.add(
81
- 'scheduleServiceCheck',
82
- ({
83
- host,
84
- isForced = true,
85
- service
86
- }: ServiceCheck): Cypress.Chainable => {
87
- let query = `SELECT parent_id, id FROM resources WHERE parent_name = '${host}' AND name = '${service}'`;
88
-
89
- return cy
90
- .requestOnDatabase({
91
- database: 'centreon_storage',
92
- query
93
- })
94
- .then(([rows]) => {
95
- if (rows.length === 0) {
96
- throw new Error(`Cannot find service ${host} / ${service}`);
97
- }
98
-
99
- const hostId = rows[0].parent_id;
100
- const serviceId = rows[0].id;
101
-
102
- return cy.request({
103
- body: {
104
- check: {
105
- is_forced: isForced
106
- },
107
- resources: [
108
- {
109
- id: serviceId,
110
- parent: {
111
- id: hostId
112
- },
113
- type: 'service'
114
- }
115
- ]
116
- },
117
- method: 'POST',
118
- timeout: 30000,
119
- url: '/centreon/api/latest/monitoring/resources/check'
120
- }).then((response) => {
121
- expect(response.status).to.eq(204);
122
-
123
- return cy.wrap(null);
124
- });
125
- });
126
- }
127
- );
128
-
129
-
130
- interface SubmitResult {
131
- host: string;
132
- output: string;
133
- perfdata?: string | null;
134
- service?: string | null;
135
- status: string;
136
- }
137
-
138
- Cypress.Commands.add(
139
- 'submitResults',
140
- (results: Array<SubmitResult>): Cypress.Chainable => {
141
- results.forEach(
142
- ({ host, output, perfdata = '', service = null, status }) => {
143
- const timestampNow = Math.floor(Date.now() / 1000) - 15;
144
- const updatetime = timestampNow.toString();
145
-
146
- const result = {
147
- host,
148
- output,
149
- perfdata,
150
- service,
151
- status: getStatusNumberFromString(status),
152
- updatetime
153
- };
154
-
155
- cy.request({
156
- body: {
157
- results: [result]
158
- },
159
- headers: {
160
- 'Content-Type': 'application/json',
161
- 'centreon-auth-token': window.localStorage.getItem('userTokenApiV1')
162
- },
163
- method: 'POST',
164
- url: `${apiActionV1}?action=submit&object=centreon_submit_results`
165
- });
166
- }
167
- );
168
-
169
- return cy.wrap(null);
170
- }
171
- );
172
-
173
- interface Downtime {
174
- host: string;
175
- service?: string | null;
176
- }
177
-
178
- Cypress.Commands.add(
179
- 'waitForDowntime',
180
- (downtime: Downtime): Cypress.Chainable => {
181
- cy.log('Checking hosts in database');
182
-
183
- let query = `SELECT COUNT(d.downtime_id) AS count_downtimes FROM downtimes as d
184
- INNER JOIN hosts as h ON h.host_id = d.host_id AND h.name = '${downtime.host}'`;
185
- if (downtime.service) {
186
- query += ` INNER JOIN services as s ON s.service_id = d.service_id AND s.description = '${downtime.service}'`;
187
- }
188
- query += ` WHERE d.started=1`;
189
- if (!downtime.service) {
190
- query += ` AND d.service_id = 0`;
191
- }
192
-
193
- cy.log(query);
194
-
195
- cy.waitUntil(() => {
196
- return cy
197
- .requestOnDatabase({
198
- database: 'centreon_storage',
199
- query
200
- })
201
- .then(([rows]) => {
202
- const foundDowntimesCount = rows.length ? rows[0].count_downtimes : 0;
203
-
204
- cy.log('Downtime count in database', foundDowntimesCount);
205
-
206
- return cy.wrap(foundDowntimesCount > 0);
207
- });
208
- });
209
-
210
- return cy.wrap(null);
211
- }
212
- );
213
-
214
- declare global {
215
- namespace Cypress {
216
- interface Chainable {
217
- scheduleHostCheck: (hostCheck) => Cypress.Chainable;
218
- scheduleServiceCheck: (serviceCheck) => Cypress.Chainable;
219
- submitResults: (props: Array<SubmitResult>) => Cypress.Chainable;
220
- waitForDowntime: (downtime: Downtime) => Cypress.Chainable;
221
- }
222
- }
223
- }
224
-
225
- export {};
@@ -1,26 +0,0 @@
1
- import { NodeGlobalsPolyfillPlugin } from '@esbuild-plugins/node-globals-polyfill';
2
- import { NodeModulesPolyfillPlugin } from '@esbuild-plugins/node-modules-polyfill';
3
- import { addCucumberPreprocessorPlugin } from '@badeball/cypress-cucumber-preprocessor';
4
- import createBundler from '@bahmutov/cypress-esbuild-preprocessor';
5
- import createEsbuildPlugin from '@badeball/cypress-cucumber-preprocessor/esbuild';
6
-
7
- export default async (
8
- on: Cypress.PluginEvents,
9
- config: Cypress.PluginConfigOptions
10
- ): Promise<void> => {
11
- await addCucumberPreprocessorPlugin(on, config);
12
-
13
- on(
14
- 'file:preprocessor',
15
- createBundler({
16
- plugins: [
17
- createEsbuildPlugin(config),
18
- NodeModulesPolyfillPlugin(),
19
- NodeGlobalsPolyfillPlugin({
20
- buffer: true,
21
- process: true
22
- })
23
- ]
24
- })
25
- );
26
- };
@@ -1,13 +0,0 @@
1
- module.exports = {
2
- mochawesomeReporterOptions: {
3
- consoleReporter: 'none',
4
- html: false,
5
- json: true,
6
- overwrite: true,
7
- reportDir: 'results/reports',
8
- reportFilename: '[name]-report.json'
9
- },
10
- reporterEnabled: `mochawesome,${require.resolve(
11
- '@badeball/cypress-cucumber-preprocessor/pretty-reporter'
12
- )}`
13
- };