@nzz/q-cli 1.9.2 → 1.9.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 (38) hide show
  1. package/package.json +9 -5
  2. package/skeletons/custom-code-skeleton/package.json +4 -2
  3. package/skeletons/custom-code-skeleton/rollup.config.js +59 -52
  4. package/skeletons/custom-code-skeleton/src/enums.ts +0 -0
  5. package/skeletons/custom-code-skeleton/src/main-prod.ts +2 -2
  6. package/skeletons/custom-code-skeleton/src/main.scss +1 -1
  7. package/skeletons/custom-code-skeleton/src/main.ts +6 -6
  8. package/skeletons/custom-code-skeleton/tsconfig.json +2 -1
  9. package/.history/bin/commands/qItem/itemService_20220627113036.js +0 -302
  10. package/.history/bin/commands/qItem/itemService_20221105174223.js +0 -304
  11. package/.history/bin/commands/qItem/itemService_20221105174236.js +0 -304
  12. package/.history/bin/commands/qItem/itemService_20221105174311.js +0 -304
  13. package/.history/bin/commands/qItem/itemService_20221105174605.js +0 -306
  14. package/.history/bin/commands/qItem/itemService_20221105174809.js +0 -309
  15. package/.history/bin/commands/qItem/itemService_20221107071956.js +0 -317
  16. package/.history/bin/commands/qItem/itemService_20221107072130.js +0 -310
  17. package/.history/bin/commands/qItem/itemService_20221107072222.js +0 -312
  18. package/.history/bin/commands/qItem/itemService_20221107072621.js +0 -316
  19. package/.history/bin/commands/qItem/itemService_20221107072850.js +0 -315
  20. package/.history/bin/commands/qItem/itemService_20221107073051.js +0 -315
  21. package/.history/bin/commands/qItem/itemService_20221107073244.js +0 -315
  22. package/.history/bin/commands/qItem/itemService_20221107075352.js +0 -323
  23. package/.history/bin/commands/qItem/itemService_20221107075536.js +0 -316
  24. package/.history/bin/commands/qItem/itemService_20221107075700.js +0 -312
  25. package/.history/bin/commands/qItem/itemService_20221107111951.js +0 -312
  26. package/.history/bin/commands/qItem/itemService_20221107113745.js +0 -310
  27. package/.history/bin/commands/qItem/itemService_20221107113901.js +0 -310
  28. package/.history/bin/commands/qItem/updateItem/updateItem_20220627113036.js +0 -64
  29. package/.history/bin/commands/qItem/updateItem/updateItem_20221105173137.js +0 -66
  30. package/.history/bin/commands/qItem/updateItem/updateItem_20221105173239.js +0 -68
  31. package/.history/bin/commands/qItem/updateItem/updateItem_20221105173610.js +0 -69
  32. package/.history/bin/commands/qItem/updateItem/updateItem_20221105173646.js +0 -74
  33. package/.history/bin/commands/qItem/updateItem/updateItem_20221105174010.js +0 -74
  34. package/.history/bin/commands/qItem/updateItem/updateItem_20221105174054.js +0 -75
  35. package/.history/package_20220808135115.json +0 -43
  36. package/.history/package_20221105171707.json +0 -43
  37. package/.history/package_20221105173355.json +0 -43
  38. package/.history/package_20221107112303.json +0 -43
@@ -1,309 +0,0 @@
1
- const resourcesService = require("./resourcesService.js");
2
- const schemaService = require("./schemaService.js");
3
- const deepmerge = require("deepmerge");
4
- const fetch = require("node-fetch");
5
- const chalk = require("chalk");
6
- const errorColor = chalk.red;
7
-
8
- async function createItem(item, environment, config) {
9
- const qServer = config.get(`${environment.name}.qServer`);
10
- const accessToken = config.get(`${environment.name}.accessToken`);
11
- const cookie = config.get(`${environment.name}.cookie`);
12
-
13
- try {
14
- const response = await fetch(`${qServer}item`, {
15
- method: "POST",
16
- body: JSON.stringify(item),
17
- headers: {
18
- "user-agent": "Q Command-line Tool",
19
- Authorization: `Bearer ${accessToken}`,
20
- "Content-Type": "application/json",
21
- Cookie: cookie ? cookie : "",
22
- },
23
- });
24
- if (response.ok) {
25
- return await response.json();
26
- } else {
27
- throw new Error(
28
- `A problem occured while creating item on ${environment.name} environment. Please check your connection and try again.`
29
- );
30
- }
31
- } catch (error) {
32
- console.error(errorColor(error.message));
33
- process.exit(1);
34
- }
35
- }
36
-
37
- async function getItem(qServer, environment, accessToken, cookie) {
38
- try {
39
- const response = await fetch(`${qServer}item/${environment.id}`, {
40
- headers: {
41
- "user-agent": "Q Command-line Tool",
42
- Authorization: `Bearer ${accessToken}`,
43
- Cookie: cookie ? cookie : "",
44
- },
45
- });
46
- if (response.ok) {
47
- return await response.json();
48
- } else {
49
- throw new Error(
50
- `A problem occured while getting item with id ${environment.id} on ${environment.name} environment. Please make sure that the id is correct, you have an internet connection and try again.`
51
- );
52
- }
53
- } catch (error) {
54
- console.error(errorColor(error.message));
55
- process.exit(1);
56
- }
57
- }
58
-
59
- function getItems(qConfig, environmentFilter) {
60
- const items = qConfig.items
61
- .filter((item) => {
62
- if (environmentFilter) {
63
- return item.environments.some(
64
- (environment) => environment.name === environmentFilter
65
- );
66
- }
67
-
68
- return true;
69
- })
70
- .map((item) => {
71
- if (environmentFilter) {
72
- item.environments = item.environments.filter(
73
- (environment) => environment.name === environmentFilter
74
- );
75
- }
76
-
77
- return item;
78
- });
79
-
80
- return items;
81
- }
82
-
83
- function getDefaultOrNull(schema) {
84
- if (schema.hasOwnProperty("default")) {
85
- if (typeof schema.default === "object") {
86
- return JSON.parse(JSON.stringify(schema.default));
87
- }
88
- return schema.default;
89
- }
90
- return null;
91
- }
92
-
93
- // Returns a default item based on the tool schema
94
- // The default item is used to derive the file properties of a certain file type
95
- // These file properties are specified by the tool and are specific to the file type
96
- // For example an image file has height/width file properties
97
- function getDefaultItem(schema) {
98
- schema = JSON.parse(JSON.stringify(schema));
99
- if (schema.type === "array") {
100
- let array = [];
101
- schema.minItems = 1;
102
- for (let i = 0; i < schema.minItems; i++) {
103
- let value = getDefaultItem(schema.items);
104
- if (value) {
105
- if (
106
- schema["Q:type"] &&
107
- schema["Q:type"] === "files" &&
108
- schema["Q:options"] &&
109
- schema["Q:options"].fileProperties
110
- ) {
111
- array.push(Object.assign(value, schema["Q:options"].fileProperties));
112
- } else {
113
- array.push(value);
114
- }
115
- }
116
- }
117
-
118
- const defaultValue = getDefaultOrNull(schema);
119
- if (array === null && defaultValue !== null) {
120
- array = defaultValue;
121
- }
122
- return array;
123
- } else if (schema.type === "object") {
124
- const defaultValue = getDefaultOrNull(schema);
125
- if (defaultValue !== null) {
126
- return defaultValue;
127
- }
128
-
129
- if (
130
- schema["Q:type"] &&
131
- schema["Q:type"] === "files" &&
132
- schema["Q:options"] &&
133
- schema["Q:options"].fileProperties
134
- ) {
135
- return schema["Q:options"].fileProperties;
136
- }
137
-
138
- if (!schema.hasOwnProperty("properties")) {
139
- return undefined;
140
- }
141
- let object = {};
142
- Object.keys(schema.properties).forEach((propertyName) => {
143
- const property = schema.properties[propertyName];
144
- let value = getDefaultItem(property);
145
- if (value !== undefined) {
146
- object[propertyName] = value;
147
- } else if (
148
- property["Q:type"] &&
149
- property["Q:type"] === "files" &&
150
- property["Q:options"] &&
151
- property["Q:options"].fileProperties
152
- ) {
153
- object[propertyName] = property["Q:options"].fileProperties;
154
- }
155
- });
156
- return object;
157
- }
158
-
159
- // if this is not an array or object, we just get the default if any
160
- const defaultValue = getDefaultOrNull(schema);
161
- if (defaultValue !== null) {
162
- return defaultValue;
163
- }
164
- return undefined;
165
- }
166
-
167
- async function updateItem(item, environment, config, qConfigPath) {
168
- const qServer = config.get(`${environment.name}.qServer`);
169
- const accessToken = config.get(`${environment.name}.accessToken`);
170
- const cookie = config.get(`${environment.name}.cookie`);
171
- const existingItem = await getItem(qServer, environment, accessToken, cookie);
172
- const updatedItem = await getUpdatedItem(
173
- qServer,
174
- accessToken,
175
- cookie,
176
- existingItem,
177
- item,
178
- environment,
179
- qConfigPath
180
- );
181
- return await saveItem(qServer, environment, accessToken, cookie, updatedItem);
182
- }
183
-
184
- async function getUpdatedItem(
185
- qServer,
186
- accessToken,
187
- cookie,
188
- existingItem,
189
- item,
190
- environment,
191
- qConfigPath
192
- ) {
193
- try {
194
- const toolSchema = await schemaService.getToolSchema(
195
- qServer,
196
- existingItem.tool
197
- );
198
- // Removes additional properties not defined in the schema on the top level object of the item
199
- toolSchema.additionalProperties = false;
200
- // If options object is available additional properties not defined in the schema are removed
201
- if (toolSchema.properties && toolSchema.properties.options) {
202
- toolSchema.properties.options.additionalProperties = false;
203
- }
204
- const defaultItem = getDefaultItem(toolSchema);
205
- console.log("-----default-----")
206
- console.log(JSON.stringify(defaultItem))
207
- item = JSON.parse(JSON.stringify(item));
208
- console.log("-----item-----")
209
- console.log(JSON.stringify(item))
210
- console.log("-----item-----")
211
- item = await resourcesService.handleResources(
212
- qServer,
213
- accessToken,
214
- cookie,
215
- item,
216
- defaultItem,
217
- qConfigPath,
218
- environment
219
- );
220
-
221
- // Merge options:
222
- // File of files property will be updated (if file exists on destination)
223
- // If it doesn't exist it is appended to the files array
224
- // All other properties are overwritten from source config
225
- const options = {
226
- arrayMerge: (destArr, srcArr) => srcArr,
227
- customMerge: (key) => {
228
- if (key === "files") {
229
- return (destArr, srcArr) => {
230
- if (destArr.length <= 0) {
231
- return srcArr;
232
- }
233
-
234
- srcArr.forEach((fileObj) => {
235
- let destIndex = destArr.findIndex(
236
- (destFileObj) =>
237
- destFileObj.file.originalName === fileObj.file.originalName
238
- );
239
-
240
- if (destIndex !== -1) {
241
- destArr[destIndex] = fileObj;
242
- } else {
243
- destArr.push(fileObj);
244
- }
245
- });
246
- return destArr;
247
- };
248
- }
249
- },
250
- };
251
-
252
- // merges existing item with the item defined in q.config.json
253
- const updatedItem = deepmerge(existingItem, item, options);
254
- // normalizes the item which removes additional properties not defined in the schema
255
- // and validates the item against the schema
256
- const normalizedItem = schemaService.getNormalizedItem(
257
- toolSchema,
258
- updatedItem,
259
- environment
260
- );
261
- // the normalized item is merged with the existing item. This is done because properties such as _id and _rev
262
- // defined in the existing item are removed during normalization, because they are not defined in the schema
263
- return deepmerge(existingItem, normalizedItem, options);
264
- } catch (error) {
265
- console.error(errorColor(error.message));
266
- process.exit(1);
267
- }
268
- }
269
-
270
- async function saveItem(
271
- qServer,
272
- environment,
273
- accessToken,
274
- cookie,
275
- updatedItem
276
- ) {
277
- try {
278
- delete updatedItem.updatedDate;
279
- console.log("updateItem")
280
- console.log(JSON.stringify(updateItem))
281
- const response = await fetch(`${qServer}item`, {
282
- method: "PUT",
283
- body: JSON.stringify(updatedItem),
284
- headers: {
285
- "user-agent": "Q Command-line Tool",
286
- Authorization: `Bearer ${accessToken}`,
287
- "Content-Type": "application/json",
288
- Cookie: cookie ? cookie : "",
289
- },
290
- });
291
- if (response.ok) {
292
- return await response.json();
293
- } else {
294
- throw new Error(
295
- `A problem occured while saving item with id ${environment.id} on ${environment.name} environment. Please check your connection and try again.`
296
- );
297
- }
298
- } catch (error) {
299
- console.error(errorColor(error.message));
300
- process.exit(1);
301
- }
302
- }
303
-
304
- module.exports = {
305
- createItem: createItem,
306
- getItem: getItem,
307
- getItems: getItems,
308
- updateItem: updateItem,
309
- };
@@ -1,317 +0,0 @@
1
- const resourcesService = require("./resourcesService.js");
2
- const schemaService = require("./schemaService.js");
3
- const deepmerge = require("deepmerge");
4
- const fetch = require("node-fetch");
5
- const chalk = require("chalk");
6
- const errorColor = chalk.red;
7
-
8
- async function createItem(item, environment, config) {
9
- const qServer = config.get(`${environment.name}.qServer`);
10
- const accessToken = config.get(`${environment.name}.accessToken`);
11
- const cookie = config.get(`${environment.name}.cookie`);
12
-
13
- try {
14
- const response = await fetch(`${qServer}item`, {
15
- method: "POST",
16
- body: JSON.stringify(item),
17
- headers: {
18
- "user-agent": "Q Command-line Tool",
19
- Authorization: `Bearer ${accessToken}`,
20
- "Content-Type": "application/json",
21
- Cookie: cookie ? cookie : "",
22
- },
23
- });
24
- if (response.ok) {
25
- return await response.json();
26
- } else {
27
- throw new Error(
28
- `A problem occured while creating item on ${environment.name} environment. Please check your connection and try again.`
29
- );
30
- }
31
- } catch (error) {
32
- console.error(errorColor(error.message));
33
- process.exit(1);
34
- }
35
- }
36
-
37
- async function getItem(qServer, environment, accessToken, cookie) {
38
- try {
39
- const response = await fetch(`${qServer}item/${environment.id}`, {
40
- headers: {
41
- "user-agent": "Q Command-line Tool",
42
- Authorization: `Bearer ${accessToken}`,
43
- Cookie: cookie ? cookie : "",
44
- },
45
- });
46
- if (response.ok) {
47
- return await response.json();
48
- } else {
49
- throw new Error(
50
- `A problem occured while getting item with id ${environment.id} on ${environment.name} environment. Please make sure that the id is correct, you have an internet connection and try again.`
51
- );
52
- }
53
- } catch (error) {
54
- console.error(errorColor(error.message));
55
- process.exit(1);
56
- }
57
- }
58
-
59
- function getItems(qConfig, environmentFilter) {
60
- const items = qConfig.items
61
- .filter((item) => {
62
- if (environmentFilter) {
63
- return item.environments.some(
64
- (environment) => environment.name === environmentFilter
65
- );
66
- }
67
-
68
- return true;
69
- })
70
- .map((item) => {
71
- if (environmentFilter) {
72
- item.environments = item.environments.filter(
73
- (environment) => environment.name === environmentFilter
74
- );
75
- }
76
-
77
- return item;
78
- });
79
-
80
- return items;
81
- }
82
-
83
- function getDefaultOrNull(schema) {
84
- if (schema.hasOwnProperty("default")) {
85
- if (typeof schema.default === "object") {
86
- return JSON.parse(JSON.stringify(schema.default));
87
- }
88
- return schema.default;
89
- }
90
- return null;
91
- }
92
-
93
- // Returns a default item based on the tool schema
94
- // The default item is used to derive the file properties of a certain file type
95
- // These file properties are specified by the tool and are specific to the file type
96
- // For example an image file has height/width file properties
97
- function getDefaultItem(schema) {
98
- schema = JSON.parse(JSON.stringify(schema));
99
- if (schema.type === "array") {
100
- let array = [];
101
- schema.minItems = 1;
102
- for (let i = 0; i < schema.minItems; i++) {
103
- let value = getDefaultItem(schema.items);
104
- if (value) {
105
- if (
106
- schema["Q:type"] &&
107
- schema["Q:type"] === "files" &&
108
- schema["Q:options"] &&
109
- schema["Q:options"].fileProperties
110
- ) {
111
- array.push(Object.assign(value, schema["Q:options"].fileProperties));
112
- } else {
113
- array.push(value);
114
- }
115
- }
116
- }
117
-
118
- const defaultValue = getDefaultOrNull(schema);
119
- if (array === null && defaultValue !== null) {
120
- array = defaultValue;
121
- }
122
- return array;
123
- } else if (schema.type === "object") {
124
- const defaultValue = getDefaultOrNull(schema);
125
- if (defaultValue !== null) {
126
- return defaultValue;
127
- }
128
-
129
- if (
130
- schema["Q:type"] &&
131
- schema["Q:type"] === "files" &&
132
- schema["Q:options"] &&
133
- schema["Q:options"].fileProperties
134
- ) {
135
- return schema["Q:options"].fileProperties;
136
- }
137
-
138
- if (!schema.hasOwnProperty("properties")) {
139
- return undefined;
140
- }
141
- let object = {};
142
- Object.keys(schema.properties).forEach((propertyName) => {
143
- const property = schema.properties[propertyName];
144
- let value = getDefaultItem(property);
145
- if (value !== undefined) {
146
- object[propertyName] = value;
147
- } else if (
148
- property["Q:type"] &&
149
- property["Q:type"] === "files" &&
150
- property["Q:options"] &&
151
- property["Q:options"].fileProperties
152
- ) {
153
- object[propertyName] = property["Q:options"].fileProperties;
154
- }
155
- });
156
- return object;
157
- }
158
-
159
- // if this is not an array or object, we just get the default if any
160
- const defaultValue = getDefaultOrNull(schema);
161
- if (defaultValue !== null) {
162
- return defaultValue;
163
- }
164
- return undefined;
165
- }
166
-
167
- async function updateItem(item, environment, config, qConfigPath) {
168
- const qServer = config.get(`${environment.name}.qServer`);
169
- const accessToken = config.get(`${environment.name}.accessToken`);
170
- const cookie = config.get(`${environment.name}.cookie`);
171
- const existingItem = await getItem(qServer, environment, accessToken, cookie);
172
- const updatedItem = await getUpdatedItem(
173
- qServer,
174
- accessToken,
175
- cookie,
176
- existingItem,
177
- item,
178
- environment,
179
- qConfigPath
180
- );
181
- return await saveItem(qServer, environment, accessToken, cookie, updatedItem);
182
- }
183
-
184
- async function getUpdatedItem(
185
- qServer,
186
- accessToken,
187
- cookie,
188
- existingItem,
189
- item,
190
- environment,
191
- qConfigPath
192
- ) {
193
- try {
194
- const toolSchema = await schemaService.getToolSchema(
195
- qServer,
196
- existingItem.tool
197
- );
198
- // Removes additional properties not defined in the schema on the top level object of the item
199
- toolSchema.additionalProperties = false;
200
- // If options object is available additional properties not defined in the schema are removed
201
- if (toolSchema.properties && toolSchema.properties.options) {
202
- toolSchema.properties.options.additionalProperties = false;
203
- }
204
- const defaultItem = getDefaultItem(toolSchema);
205
- console.log("-----default-----")
206
- console.log(JSON.stringify(defaultItem))
207
- item = JSON.parse(JSON.stringify(item));
208
- console.log("-----item-----")
209
- console.log(JSON.stringify(item))
210
- console.log("-----item-----")
211
- item = await resourcesService.handleResources(
212
- qServer,
213
- accessToken,
214
- cookie,
215
- item,
216
- defaultItem,
217
- qConfigPath,
218
- environment
219
- );
220
-
221
- console.log("-----destArr 22222-----")
222
- console.log(JSON.stringify(destArr))
223
- console.log("-----destArr-----")
224
-
225
- console.log("-----srcArr 22222-----")
226
- console.log(JSON.stringify(srcArr))
227
- console.log("-----srcArr-----")
228
-
229
- // Merge options:
230
- // File of files property will be updated (if file exists on destination)
231
- // If it doesn't exist it is appended to the files array
232
- // All other properties are overwritten from source config
233
- const options = {
234
- arrayMerge: (destArr, srcArr) => srcArr,
235
- customMerge: (key) => {
236
- if (key === "files") {
237
- return (destArr, srcArr) => {
238
- if (destArr.length <= 0) {
239
- return srcArr;
240
- }
241
-
242
- srcArr.forEach((fileObj) => {
243
- let destIndex = destArr.findIndex(
244
- (destFileObj) =>
245
- destFileObj.file.originalName === fileObj.file.originalName
246
- );
247
-
248
- if (destIndex !== -1) {
249
- destArr[destIndex] = fileObj;
250
- } else {
251
- destArr.push(fileObj);
252
- }
253
- });
254
- return destArr;
255
- };
256
- }
257
- },
258
- };
259
-
260
- // merges existing item with the item defined in q.config.json
261
- const updatedItem = deepmerge(existingItem, item, options);
262
- // normalizes the item which removes additional properties not defined in the schema
263
- // and validates the item against the schema
264
- const normalizedItem = schemaService.getNormalizedItem(
265
- toolSchema,
266
- updatedItem,
267
- environment
268
- );
269
- // the normalized item is merged with the existing item. This is done because properties such as _id and _rev
270
- // defined in the existing item are removed during normalization, because they are not defined in the schema
271
- return deepmerge(existingItem, normalizedItem, options);
272
- } catch (error) {
273
- console.error(errorColor(error.message));
274
- process.exit(1);
275
- }
276
- }
277
-
278
- async function saveItem(
279
- qServer,
280
- environment,
281
- accessToken,
282
- cookie,
283
- updatedItem
284
- ) {
285
- try {
286
- delete updatedItem.updatedDate;
287
- console.log("updateItem")
288
- console.log(JSON.stringify(updateItem))
289
- const response = await fetch(`${qServer}item`, {
290
- method: "PUT",
291
- body: JSON.stringify(updatedItem),
292
- headers: {
293
- "user-agent": "Q Command-line Tool",
294
- Authorization: `Bearer ${accessToken}`,
295
- "Content-Type": "application/json",
296
- Cookie: cookie ? cookie : "",
297
- },
298
- });
299
- if (response.ok) {
300
- return await response.json();
301
- } else {
302
- throw new Error(
303
- `A problem occured while saving item with id ${environment.id} on ${environment.name} environment. Please check your connection and try again.`
304
- );
305
- }
306
- } catch (error) {
307
- console.error(errorColor(error.message));
308
- process.exit(1);
309
- }
310
- }
311
-
312
- module.exports = {
313
- createItem: createItem,
314
- getItem: getItem,
315
- getItems: getItems,
316
- updateItem: updateItem,
317
- };