orc-scripts 5.0.0-dev.0 → 5.0.0-dev.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "orc-scripts",
3
- "version": "5.0.0-dev.0",
3
+ "version": "5.0.0-dev.2",
4
4
  "description": "Scripts toolbox for Orckestra",
5
5
  "type": "commonjs",
6
6
  "bin": {
@@ -108,6 +108,7 @@
108
108
  "pkg-dir": "^4.0.0",
109
109
  "polished": "^3.4.2",
110
110
  "prettier": "^3.3.2",
111
+ "prettier-plugin-sort-json": "^4.1.1",
111
112
  "react": "^17.0.2",
112
113
  "react-big-calendar": "^1.13.0",
113
114
  "react-datepicker": "^3.0.0",
@@ -6,6 +6,14 @@ const config = {
6
6
  arrowParens: "avoid",
7
7
  endOfLine: "auto",
8
8
  semi: true,
9
+ overrides: [
10
+ {
11
+ files: ["./src/translations/*.json"],
12
+ options: {
13
+ plugins: ["prettier-plugin-sort-json"],
14
+ },
15
+ },
16
+ ],
9
17
  };
10
18
 
11
19
  export default config;
@@ -5,6 +5,7 @@ const lodash = require("lodash");
5
5
  const occUrl = process.env.OccUrl;
6
6
  const occToken = process.env.OccToken;
7
7
  let outputFile = "";
8
+ let requestsFile = "";
8
9
 
9
10
  if (process.argv.includes("--outputFile")) {
10
11
  outputFile = process.argv[process.argv.indexOf("--outputFile") + 1];
@@ -14,6 +15,10 @@ if (!outputFile) {
14
15
  throw new Error("Missing --outputFile 'file' argument.");
15
16
  }
16
17
 
18
+ if (process.argv.includes("--requestsFile")) {
19
+ requestsFile = process.argv[process.argv.indexOf("--requestsFile") + 1];
20
+ }
21
+
17
22
  if (!occToken) {
18
23
  throw new Error(
19
24
  "Missing OccToken environment variable. This environment variable needs to contains the authentication token used to access the OCC platform specified in OccUrl.",
@@ -40,7 +45,7 @@ function isVerbAllowed(verb) {
40
45
  return lowerCaseVerb === "get" || lowerCaseVerb === "post" || lowerCaseVerb === "put" || lowerCaseVerb === "delete";
41
46
  }
42
47
 
43
- function generateOperationsFromPath(url, pathData) {
48
+ function generateOperationsFromPath(url, pathData, desiredRequests) {
44
49
  const operations = [];
45
50
 
46
51
  for (const verb of Object.getOwnPropertyNames(pathData)) {
@@ -50,8 +55,15 @@ function generateOperationsFromPath(url, pathData) {
50
55
 
51
56
  const operation = pathData[verb];
52
57
 
58
+ const operationName = extractRequestNameFromOperation(operation);
59
+
60
+ const shouldAddOperation = desiredRequests == null || desiredRequests.includes(operationName.toLowerCase());
61
+ if( !shouldAddOperation ){
62
+ continue;
63
+ }
64
+
53
65
  operations.push({
54
- name: extractRequestNameFromOperation(operation),
66
+ name: operationName,
55
67
  url: url,
56
68
  verb: verb.toUpperCase(),
57
69
  hasQueryString: operation.parameters.filter(p => p.in === "query").length > 0,
@@ -102,51 +114,66 @@ function generateImports() {
102
114
  return 'import { buildUrl } from "../utils/buildUrl";\n\n';
103
115
  }
104
116
 
105
- https
106
- .get(occUrl, { headers: { "X-AUTH": occToken } }, resp => {
107
- let data = "";
108
- let error = "";
109
-
110
- if (resp.statusCode !== 200) {
111
- error = new Error(`Request Failed. Status Code: ${resp.statusCode}`);
112
- }
113
- if (error) {
114
- console.error(error.message);
115
- // Consume response data to free up memory
116
- resp.resume();
117
- return;
117
+ if (requestsFile) {
118
+ fs.readFile(requestsFile, 'utf-8', (err, data) => {
119
+ if (err) {
120
+ return console.error(err);
118
121
  }
122
+ const desiredRequests = data.split("\n").map(d => d.trim().toLowerCase());
123
+ generate(desiredRequests);
124
+ })
125
+ }else {
126
+ generate(null);
127
+ }
119
128
 
120
- // A chunk of data has been received.
121
- resp.on("data", chunk => {
122
- data += chunk;
123
- });
124
129
 
125
- // The whole response has been received. Print out the result.
126
- resp.on("end", () => {
127
- const swaggerMetaData = JSON.parse(data);
128
- const paths = swaggerMetaData.paths;
129
- let operations = [];
130
+ function generate(desiredRequests) {
131
+ https
132
+ .get(occUrl, { headers: { "X-AUTH": occToken } }, resp => {
133
+ let data = "";
134
+ let error = "";
130
135
 
131
- for (const url of Object.getOwnPropertyNames(paths)) {
132
- operations = operations.concat(generateOperationsFromPath(url, paths[url]));
136
+ if (resp.statusCode !== 200) {
137
+ error = new Error(`Request Failed. Status Code: ${resp.statusCode}`);
138
+ }
139
+ if (error) {
140
+ console.error(error.message);
141
+ // Consume response data to free up memory
142
+ resp.resume();
143
+ return;
133
144
  }
134
145
 
135
- let helperData = "/* istanbul ignore file */\n\n";
136
- helperData += generateImports();
146
+ // A chunk of data has been received.
147
+ resp.on("data", chunk => {
148
+ data += chunk;
149
+ });
137
150
 
138
- for (const op of lodash.sortBy(operations, [o => o.name])) {
139
- helperData += generateOperation(op);
140
- }
151
+ // The whole response has been received. Print out the result.
152
+ resp.on("end", () => {
153
+ const swaggerMetaData = JSON.parse(data);
154
+ const paths = swaggerMetaData.paths;
155
+ let operations = [];
156
+
157
+ for (const url of Object.getOwnPropertyNames(paths)) {
158
+ operations = operations.concat(generateOperationsFromPath(url, paths[url], desiredRequests));
159
+ }
160
+
161
+ let helperData = "/* istanbul ignore file */\n\n";
162
+ helperData += generateImports();
141
163
 
142
- fs.writeFile(outputFile, helperData, function (err) {
143
- if (err) {
144
- return console.error(err);
164
+ for (const op of lodash.sortBy(operations, [o => o.name])) {
165
+ helperData += generateOperation(op);
145
166
  }
146
- console.log(`File '${outputFile}' has been created`);
167
+
168
+ fs.writeFile(outputFile, helperData, function (err) {
169
+ if (err) {
170
+ return console.error(err);
171
+ }
172
+ console.log(`File '${outputFile}' has been created`);
173
+ });
147
174
  });
175
+ })
176
+ .on("error", err => {
177
+ console.log("Error: " + err.message);
148
178
  });
149
- })
150
- .on("error", err => {
151
- console.log("Error: " + err.message);
152
- });
179
+ }
@@ -0,0 +1,101 @@
1
+ const fs = require("fs");
2
+ const https = require("https");
3
+ const jsdom = require("jsdom");
4
+
5
+ let outputFile = "";
6
+ let windowsZonesUrl = "";
7
+
8
+ if (process.argv.includes("--outputFile")) {
9
+ outputFile = process.argv[process.argv.indexOf("--outputFile") + 1];
10
+ }
11
+
12
+ if (!outputFile) {
13
+ throw new Error("Missing --outputFile 'file' argument.");
14
+ }
15
+
16
+ if (process.argv.includes("--windowsZonesUrl")) {
17
+ windowsZonesUrl = process.argv[process.argv.indexOf("--windowsZonesUrl") + 1];
18
+ } else {
19
+ windowsZonesUrl =
20
+ "https://raw.githubusercontent.com/unicode-org/cldr/refs/heads/main/common/supplemental/windowsZones.xml";
21
+ }
22
+
23
+ downloadUrl();
24
+
25
+ function extractTimeZones(timeZones) {
26
+ const result = {
27
+ ianaToWindows: {},
28
+ windowsToIana: {},
29
+ };
30
+
31
+ const dom = new jsdom.JSDOM(timeZones);
32
+ const parser = new dom.window.DOMParser();
33
+
34
+ const xmlDoc = parser.parseFromString(timeZones, "application/xml");
35
+ const mapZones = xmlDoc.getElementsByTagName("mapZone");
36
+
37
+ for (let zone of mapZones) {
38
+ const key = zone.getAttribute("other");
39
+ const type = zone.getAttribute("type");
40
+
41
+ if (!result.windowsToIana[key]) {
42
+ result.windowsToIana[key] = [];
43
+ }
44
+
45
+ const types = type.split(" ");
46
+
47
+ for (let t of types) {
48
+ if (!result.windowsToIana[key].includes(t)) {
49
+ result.windowsToIana[key].push(t);
50
+ }
51
+
52
+ if (!result.ianaToWindows[t]) {
53
+ result.ianaToWindows[t] = [];
54
+ }
55
+
56
+ if (!result.ianaToWindows[t].includes(key)) {
57
+ result.ianaToWindows[t].push(key);
58
+ }
59
+ }
60
+ }
61
+
62
+ return result;
63
+ }
64
+
65
+ function downloadUrl() {
66
+ https
67
+ .get(windowsZonesUrl, {}, resp => {
68
+ let data = "";
69
+ let error = "";
70
+
71
+ if (resp.statusCode !== 200) {
72
+ error = new Error(`Request Failed. Status Code: ${resp.statusCode}`);
73
+ }
74
+ if (error) {
75
+ console.error(error.message);
76
+ // Consume response data to free up memory
77
+ resp.resume();
78
+ return;
79
+ }
80
+
81
+ // A chunk of data has been received.
82
+ resp.on("data", chunk => {
83
+ data += chunk;
84
+ });
85
+
86
+ // The whole response has been received. Print out the result.
87
+ resp.on("end", () => {
88
+ const result = extractTimeZones(data);
89
+
90
+ fs.writeFile(outputFile, JSON.stringify(result, null, 2), function (err) {
91
+ if (err) {
92
+ return console.error(err);
93
+ }
94
+ console.log(`File '${outputFile}' has been created`);
95
+ });
96
+ });
97
+ })
98
+ .on("error", err => {
99
+ console.log("Error: " + err.message);
100
+ });
101
+ }
@@ -1,5 +1,7 @@
1
1
  const DevServer = require("webpack-dev-server");
2
2
  const webpack = require("webpack");
3
+ const path = require("path");
4
+ const fs = require("fs");
3
5
 
4
6
  const HOST = process.env.HOSTNAME || "localhost";
5
7
 
@@ -7,6 +9,42 @@ const args = process.argv.slice(2);
7
9
  const argPort = args.indexOf("--port") !== -1 ? args[args.indexOf("--port") + 1] : null;
8
10
  const PORT = argPort || process.env.PORT || 5000;
9
11
 
12
+ const findSslPasswordFromParametersFile = (certFile) => {
13
+ // reference: https://hals.app/blog/recursively-read-parent-folder-nodejs/
14
+
15
+ let parentDirectory = path.dirname(certFile);
16
+ while (fs.existsSync(parentDirectory)) {
17
+ console.log("Looking for certificate password in: " + parentDirectory)
18
+ const fileToFindPath = path.join(parentDirectory, "parameters.dev.xml");
19
+ if (fs.existsSync(fileToFindPath)) {
20
+ const fileContent = fs.readFileSync(fileToFindPath, "utf8");
21
+
22
+ // Using regex to parse the XML to avoid adding a dependency on an XML package
23
+
24
+ const matchResult = /<param\s+name="SSL_CertificatePfxPassword"\s+value="(?<Value>[^"]+)"\s*\/>/.exec(fileContent);
25
+ if (matchResult && matchResult.groups && matchResult.groups['Value']) {
26
+ console.log("Certificate password found");
27
+ return matchResult.groups['Value'];
28
+ }
29
+
30
+ console.warn("Could not find SSL_CertificatePfxPassword in file " + fileToFindPath)
31
+ return null;
32
+ }
33
+
34
+ // The trick is here:
35
+ // Using path.dirname() of a directory returns the parent directory!
36
+ const parentDirname = path.dirname(parentDirectory);
37
+ // But only to a certain point (file system root) (So to avoid infinite loops lets stop here)
38
+ if (parentDirectory === parentDirname) {
39
+ return null;
40
+ }
41
+
42
+ parentDirectory = parentDirname;
43
+ }
44
+
45
+ return null;
46
+ }
47
+
10
48
  const config = require("../config/webpack.config.js");
11
49
  const options = {
12
50
  historyApiFallback: true,
@@ -19,13 +57,20 @@ const options = {
19
57
  },
20
58
  };
21
59
 
22
- if (HOST !== "localhost") {
23
- options.public = HOST;
24
- }
25
60
  if (HOST !== "localhost" || args.indexOf("--https") !== -1 || process.env.HTTPS) {
26
61
  options.server = 'https';
27
62
  }
28
63
 
64
+ if (options.server === 'https' && process.env.SSL_CERT_PATH) {
65
+ options.server = {
66
+ type: 'https',
67
+ options: {
68
+ pfx: process.env.SSL_CERT_PATH,
69
+ passphrase: process.env.SSL_CERT_PASSWORD || findSslPasswordFromParametersFile(process.env.SSL_CERT_PATH),
70
+ },
71
+ }
72
+ }
73
+
29
74
  const compiler = webpack(config);
30
75
 
31
76
  const server = new DevServer(options, compiler);