@commercelayer/cli-core 4.11.4 → 4.12.1
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/lib/cjs/api.js +107 -1
- package/lib/cjs/application.js +36 -1
- package/lib/cjs/color.js +116 -1
- package/lib/cjs/command.js +95 -1
- package/lib/cjs/config.js +182 -1
- package/lib/cjs/filter.js +81 -1
- package/lib/cjs/help.js +103 -5
- package/lib/cjs/index.js +46 -1
- package/lib/cjs/inflector.js +255 -1
- package/lib/cjs/jsonapi.js +38 -1
- package/lib/cjs/output.js +83 -3
- package/lib/cjs/raw.js +49 -1
- package/lib/cjs/schema.js +20 -1
- package/lib/cjs/style.js +39 -1
- package/lib/cjs/symbol.js +28 -1
- package/lib/cjs/text.js +23 -1
- package/lib/cjs/token.js +177 -1
- package/lib/cjs/update.js +22 -4
- package/lib/cjs/util.js +59 -2
- package/lib/esm/api.js +93 -1
- package/lib/esm/application.js +26 -1
- package/lib/esm/color.js +110 -1
- package/lib/esm/command.js +90 -1
- package/lib/esm/config.js +180 -1
- package/lib/esm/filter.js +71 -1
- package/lib/esm/help.js +100 -5
- package/lib/esm/index.js +26 -1
- package/lib/esm/inflector.js +253 -1
- package/lib/esm/jsonapi.js +42 -1
- package/lib/esm/output.js +72 -3
- package/lib/esm/raw.js +42 -1
- package/lib/esm/schema.js +14 -1
- package/lib/esm/style.js +19 -1
- package/lib/esm/symbol.js +25 -1
- package/lib/esm/text.js +13 -1
- package/lib/esm/token.js +166 -1
- package/lib/esm/update.js +16 -4
- package/lib/esm/util.js +51 -2
- package/lib/tsconfig.esm.tsbuildinfo +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +16 -17
package/lib/esm/inflector.js
CHANGED
|
@@ -1 +1,253 @@
|
|
|
1
|
-
const
|
|
1
|
+
const _Inflector = {
|
|
2
|
+
uncountableWords: [
|
|
3
|
+
'equipment', 'information', 'rice', 'money', 'species', 'series',
|
|
4
|
+
'fish', 'sheep', 'moose', 'deer', 'news'
|
|
5
|
+
],
|
|
6
|
+
pluralRules: [
|
|
7
|
+
[/(m)an$/gi, '$1en'],
|
|
8
|
+
[/(pe)rson$/gi, '$1ople'],
|
|
9
|
+
[/(child)$/gi, '$1ren'],
|
|
10
|
+
[/^(ox)$/gi, '$1en'],
|
|
11
|
+
[/(ax|test)is$/gi, '$1es'],
|
|
12
|
+
[/(octop|vir)us$/gi, '$1i'],
|
|
13
|
+
[/(alias|status)$/gi, '$1es'],
|
|
14
|
+
[/(bu)s$/gi, '$1ses'],
|
|
15
|
+
[/(buffal|tomat|potat)o$/gi, '$1oes'],
|
|
16
|
+
[/([ti])um$/gi, '$1a'],
|
|
17
|
+
[/sis$/gi, 'ses'],
|
|
18
|
+
[/(?:([^f])fe|([lr])f)$/gi, '$1$2ves'],
|
|
19
|
+
[/(hive)$/gi, '$1s'],
|
|
20
|
+
[/([^aeiouy]|qu)y$/gi, '$1ies'],
|
|
21
|
+
[/(x|ch|ss|sh)$/gi, '$1es'],
|
|
22
|
+
[/(matr|vert|ind)ix|ex$/gi, '$1ices'],
|
|
23
|
+
[/([m|l])ouse$/gi, '$1ice'],
|
|
24
|
+
[/(quiz)$/gi, '$1zes'],
|
|
25
|
+
[/s$/gi, 's'],
|
|
26
|
+
[/$/gi, 's']
|
|
27
|
+
],
|
|
28
|
+
singularRules: [
|
|
29
|
+
[/(m)en$/gi, '$1an'],
|
|
30
|
+
[/(pe)ople$/gi, '$1rson'],
|
|
31
|
+
[/(child)ren$/gi, '$1'],
|
|
32
|
+
[/([ti])a$/gi, '$1um'],
|
|
33
|
+
[/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$/gi, '$1$2sis'],
|
|
34
|
+
[/(hive)s$/gi, '$1'],
|
|
35
|
+
[/(tive)s$/gi, '$1'],
|
|
36
|
+
[/(curve)s$/gi, '$1'],
|
|
37
|
+
[/([lr])ves$/gi, '$1f'],
|
|
38
|
+
[/([^fo])ves$/gi, '$1fe'],
|
|
39
|
+
[/([^aeiouy]|qu)ies$/gi, '$1y'],
|
|
40
|
+
[/(s)eries$/gi, '$1eries'],
|
|
41
|
+
[/(m)ovies$/gi, '$1ovie'],
|
|
42
|
+
[/(x|ch|ss|sh)es$/gi, '$1'],
|
|
43
|
+
[/([m|l])ice$/gi, '$1ouse'],
|
|
44
|
+
[/(bus)es$/gi, '$1'],
|
|
45
|
+
[/(o)es$/gi, '$1'],
|
|
46
|
+
[/(shoe)s$/gi, '$1'],
|
|
47
|
+
[/(cris|ax|test)es$/gi, '$1is'],
|
|
48
|
+
[/(octop|vir)i$/gi, '$1us'],
|
|
49
|
+
[/(alias|status)es$/gi, '$1'],
|
|
50
|
+
[/^(ox)en/gi, '$1'],
|
|
51
|
+
[/(vert|ind)ices$/gi, '$1ex'],
|
|
52
|
+
[/(matr)ices$/gi, '$1ix'],
|
|
53
|
+
[/(quiz)zes$/gi, '$1'],
|
|
54
|
+
[/s$/gi, '']
|
|
55
|
+
],
|
|
56
|
+
nonTitlecasedWords: [
|
|
57
|
+
'and', 'or', 'nor', 'a', 'an', 'the', 'so', 'but', 'to', 'of', 'at',
|
|
58
|
+
'by', 'from', 'into', 'on', 'onto', 'off', 'out', 'in', 'over',
|
|
59
|
+
'with', 'for'
|
|
60
|
+
],
|
|
61
|
+
idSuffix: /(_ids|_id)$/g,
|
|
62
|
+
underbar: /_/g,
|
|
63
|
+
spaceOrUnderbar: /[ _]/g,
|
|
64
|
+
uppercase: /([A-Z])/g,
|
|
65
|
+
underbarPrefix: /^_/,
|
|
66
|
+
applyRules: function (str, rules, skip, override) {
|
|
67
|
+
if (override) {
|
|
68
|
+
str = override;
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
const ignore = (skip.includes(str.toLowerCase()));
|
|
72
|
+
if (!ignore) {
|
|
73
|
+
for (let x = 0; x < rules.length; x++) {
|
|
74
|
+
if (str.match(rules[x][0])) {
|
|
75
|
+
str = str.replace(rules[x][0], rules[x][1]);
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return str;
|
|
82
|
+
},
|
|
83
|
+
/*
|
|
84
|
+
Inflector.pluralize('person') -> 'people'
|
|
85
|
+
Inflector.pluralize('octopus') -> 'octopi'
|
|
86
|
+
Inflector.pluralize('Hat') -> 'Hats'
|
|
87
|
+
Inflector.pluralize('person', 'guys') -> 'guys'
|
|
88
|
+
*/
|
|
89
|
+
pluralize: function (str, plural) {
|
|
90
|
+
return _Inflector.applyRules(str, _Inflector.pluralRules, _Inflector.uncountableWords, plural);
|
|
91
|
+
},
|
|
92
|
+
/*
|
|
93
|
+
Inflector.singularize('person') -> 'person'
|
|
94
|
+
Inflector.singularize('octopi') -> 'octopus'
|
|
95
|
+
Inflector.singularize('hats') -> 'hat'
|
|
96
|
+
Inflector.singularize('guys', 'person') -> 'person'
|
|
97
|
+
*/
|
|
98
|
+
singularize: function (str, singular) {
|
|
99
|
+
return _Inflector.applyRules(str, _Inflector.singularRules, _Inflector.uncountableWords, singular);
|
|
100
|
+
},
|
|
101
|
+
/*
|
|
102
|
+
Inflector.camelize('message_properties') -> 'MessageProperties'
|
|
103
|
+
Inflector.camelize('message_properties', true) -> 'messageProperties'
|
|
104
|
+
*/
|
|
105
|
+
camelize: function (str, lowFirstLetter) {
|
|
106
|
+
// str = str.toLowerCase()
|
|
107
|
+
const strPath = str.split('/');
|
|
108
|
+
for (let i = 0; i < strPath.length; i++) {
|
|
109
|
+
const strArr = strPath[i].split('_');
|
|
110
|
+
const initX = ((lowFirstLetter && i + 1 === strPath.length) ? (1) : (0));
|
|
111
|
+
for (let x = initX; x < strArr.length; x++) {
|
|
112
|
+
strArr[x] = strArr[x].charAt(0).toUpperCase() + strArr[x].substring(1);
|
|
113
|
+
}
|
|
114
|
+
strPath[i] = strArr.join('');
|
|
115
|
+
}
|
|
116
|
+
str = strPath.join('::');
|
|
117
|
+
// fix
|
|
118
|
+
if (lowFirstLetter) {
|
|
119
|
+
const first = str.charAt(0).toLowerCase();
|
|
120
|
+
const last = str.slice(1);
|
|
121
|
+
str = first + last;
|
|
122
|
+
}
|
|
123
|
+
return str;
|
|
124
|
+
},
|
|
125
|
+
/*
|
|
126
|
+
Inflector.underscore('MessageProperties') -> 'message_properties'
|
|
127
|
+
Inflector.underscore('messageProperties') -> 'message_properties'
|
|
128
|
+
*/
|
|
129
|
+
underscore: function (str) {
|
|
130
|
+
const strPath = str.split('::');
|
|
131
|
+
for (let i = 0; i < strPath.length; i++) {
|
|
132
|
+
strPath[i] = strPath[i].replace(_Inflector.uppercase, '_$1');
|
|
133
|
+
strPath[i] = strPath[i].replace(_Inflector.underbarPrefix, '');
|
|
134
|
+
}
|
|
135
|
+
str = strPath.join('/').toLowerCase();
|
|
136
|
+
return str;
|
|
137
|
+
},
|
|
138
|
+
/*
|
|
139
|
+
Inflector.humanize('message_properties') -> 'Message properties'
|
|
140
|
+
Inflector.humanize('message_properties') -> 'message properties'
|
|
141
|
+
*/
|
|
142
|
+
humanize: function (str, lowFirstLetter) {
|
|
143
|
+
str = str.toLowerCase();
|
|
144
|
+
str = str.replace(_Inflector.idSuffix, '');
|
|
145
|
+
str = str.replace(_Inflector.underbar, ' ');
|
|
146
|
+
if (!lowFirstLetter) {
|
|
147
|
+
str = _Inflector.capitalize(str);
|
|
148
|
+
}
|
|
149
|
+
return str;
|
|
150
|
+
},
|
|
151
|
+
/*
|
|
152
|
+
Inflector.capitalize('message_properties') -> 'Message_properties'
|
|
153
|
+
Inflector.capitalize('message properties') -> 'Message properties'
|
|
154
|
+
*/
|
|
155
|
+
capitalize: function (str) {
|
|
156
|
+
str = str.toLowerCase();
|
|
157
|
+
str = str.substring(0, 1).toUpperCase() + str.substring(1);
|
|
158
|
+
return str;
|
|
159
|
+
},
|
|
160
|
+
/*
|
|
161
|
+
Inflector.dasherize('message_properties') -> 'message-properties'
|
|
162
|
+
Inflector.dasherize('message properties') -> 'message-properties'
|
|
163
|
+
*/
|
|
164
|
+
dasherize: function (str) {
|
|
165
|
+
str = str.replace(_Inflector.spaceOrUnderbar, '-');
|
|
166
|
+
return str;
|
|
167
|
+
},
|
|
168
|
+
/*
|
|
169
|
+
Inflector.camel2words('message_properties') -> 'Message Properties'
|
|
170
|
+
Inflector.camel2words('message properties') -> 'Message Properties'
|
|
171
|
+
Inflactor.camel2words('Message_propertyId', true) -> 'Message Properties Id'
|
|
172
|
+
*/
|
|
173
|
+
camel2words: function (str, allFirstUpper) {
|
|
174
|
+
// str = str.toLowerCase()
|
|
175
|
+
if (allFirstUpper) {
|
|
176
|
+
str = _Inflector.camelize(str);
|
|
177
|
+
str = _Inflector.underscore(str);
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
str = str.toLowerCase();
|
|
181
|
+
}
|
|
182
|
+
str = str.replace(_Inflector.underbar, ' ');
|
|
183
|
+
const strArr = str.split(' ');
|
|
184
|
+
for (let x = 0; x < strArr.length; x++) {
|
|
185
|
+
const d = strArr[x].split('-');
|
|
186
|
+
for (let i = 0; i < d.length; i++) {
|
|
187
|
+
if (!_Inflector.nonTitlecasedWords.includes(d[i].toLowerCase())) {
|
|
188
|
+
d[i] = _Inflector.capitalize(d[i]);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
strArr[x] = d.join('-');
|
|
192
|
+
}
|
|
193
|
+
str = strArr.join(' ');
|
|
194
|
+
str = str.substring(0, 1).toUpperCase() + str.substring(1);
|
|
195
|
+
return str;
|
|
196
|
+
},
|
|
197
|
+
/*
|
|
198
|
+
Inflector.demodulize('Message::Bus::Properties') -> 'Properties'
|
|
199
|
+
*/
|
|
200
|
+
demodulize: function (str) {
|
|
201
|
+
const strArr = str.split('::');
|
|
202
|
+
str = strArr[strArr.length - 1];
|
|
203
|
+
return str;
|
|
204
|
+
},
|
|
205
|
+
/*
|
|
206
|
+
Inflector.tableize('MessageBusProperty') -> 'message_bus_properties'
|
|
207
|
+
*/
|
|
208
|
+
tableize: function (str) {
|
|
209
|
+
str = _Inflector.pluralize(_Inflector.underscore(str));
|
|
210
|
+
return str;
|
|
211
|
+
},
|
|
212
|
+
/*
|
|
213
|
+
Inflector.classify('message_bus_properties') -> 'MessageBusProperty'
|
|
214
|
+
*/
|
|
215
|
+
classify: function (str) {
|
|
216
|
+
str = _Inflector.singularize(_Inflector.camelize(str));
|
|
217
|
+
return str;
|
|
218
|
+
},
|
|
219
|
+
/*
|
|
220
|
+
Inflector.foreignKey('MessageBusProperty') -> 'message_bus_property_id'
|
|
221
|
+
Inflector.foreignKey('MessageBusProperty', true) -> 'message_bus_propertyid'
|
|
222
|
+
*/
|
|
223
|
+
foreignKey: function (str, dropIdUbar) {
|
|
224
|
+
str = _Inflector.underscore(_Inflector.demodulize(str)) + (dropIdUbar ? ('') : ('_')) + 'id';
|
|
225
|
+
return str;
|
|
226
|
+
},
|
|
227
|
+
/*
|
|
228
|
+
Inflector.ordinalize('the 1 pitch') -> 'the 1st pitch'
|
|
229
|
+
*/
|
|
230
|
+
ordinalize: function (str) {
|
|
231
|
+
const strArr = str.split(' ');
|
|
232
|
+
for (let x = 0; x < strArr.length; x++) {
|
|
233
|
+
const i = parseInt(strArr[x]);
|
|
234
|
+
if (Number.isNaN(i)) {
|
|
235
|
+
const ltd = strArr[x].substring(strArr[x].length - 2);
|
|
236
|
+
const ld = strArr[x].substring(strArr[x].length - 1);
|
|
237
|
+
let suf = "th";
|
|
238
|
+
if ((ltd !== "11") && (ltd !== "12") && (ltd !== "13")) {
|
|
239
|
+
if (ld === "1")
|
|
240
|
+
suf = "st";
|
|
241
|
+
else if (ld === "2")
|
|
242
|
+
suf = "nd";
|
|
243
|
+
else if (ld === "3")
|
|
244
|
+
suf = "rd";
|
|
245
|
+
}
|
|
246
|
+
strArr[x] += suf;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
str = strArr.join(' ');
|
|
250
|
+
return str;
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
export default _Inflector;
|
package/lib/esm/jsonapi.js
CHANGED
|
@@ -1 +1,42 @@
|
|
|
1
|
-
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unsafe-argument */
|
|
2
|
+
const findIncluded = (rel, included) => {
|
|
3
|
+
return included.find(inc => {
|
|
4
|
+
return (rel.id === inc.id) && (rel.type === inc.type);
|
|
5
|
+
});
|
|
6
|
+
};
|
|
7
|
+
const denormalizeResource = (res, included) => {
|
|
8
|
+
const resource = Object.assign({ id: res.id, type: res.type }, res.attributes);
|
|
9
|
+
if (res.relationships)
|
|
10
|
+
Object.keys(res.relationships).forEach(key => {
|
|
11
|
+
const rel = res.relationships[key].data;
|
|
12
|
+
if (rel) {
|
|
13
|
+
if (Array.isArray(rel))
|
|
14
|
+
resource[key] = rel.map(r => denormalizeResource(findIncluded(r, included), included));
|
|
15
|
+
else
|
|
16
|
+
resource[key] = denormalizeResource(findIncluded(rel, included), included);
|
|
17
|
+
}
|
|
18
|
+
else if (rel === null)
|
|
19
|
+
resource[key] = null;
|
|
20
|
+
});
|
|
21
|
+
return resource;
|
|
22
|
+
};
|
|
23
|
+
const denormalize = (response) => {
|
|
24
|
+
let denormalizedResponse;
|
|
25
|
+
if (response.links)
|
|
26
|
+
delete response.links;
|
|
27
|
+
const data = response.data;
|
|
28
|
+
const included = response.included;
|
|
29
|
+
if (Array.isArray(data))
|
|
30
|
+
denormalizedResponse = data.map(res => denormalizeResource(res, included));
|
|
31
|
+
else
|
|
32
|
+
denormalizedResponse = denormalizeResource(data, included);
|
|
33
|
+
return denormalizedResponse;
|
|
34
|
+
};
|
|
35
|
+
/*
|
|
36
|
+
const includedResource = (rel: { id: any; type: any }, included: any[]) => {
|
|
37
|
+
return included.find(inc => {
|
|
38
|
+
return (rel.id === inc.id) && (rel.type === inc.type)
|
|
39
|
+
})
|
|
40
|
+
}
|
|
41
|
+
*/
|
|
42
|
+
export { denormalize };
|
package/lib/esm/output.js
CHANGED
|
@@ -1,3 +1,72 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unsafe-argument */
|
|
2
|
+
import { inspect } from 'util';
|
|
3
|
+
/** Print a formatted object */
|
|
4
|
+
const printObject = (obj, options) => {
|
|
5
|
+
return inspect(obj, {
|
|
6
|
+
showHidden: false,
|
|
7
|
+
depth: null,
|
|
8
|
+
colors: ((options === null || options === void 0 ? void 0 : options.color) === undefined) ? true : options.color,
|
|
9
|
+
sorted: ((options === null || options === void 0 ? void 0 : options.sort) === undefined) ? false : options === null || options === void 0 ? void 0 : options.sort,
|
|
10
|
+
maxArrayLength: Infinity,
|
|
11
|
+
breakLength: (options === null || options === void 0 ? void 0 : options.width) || 120,
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
/** Print object in JSON format */
|
|
15
|
+
const printJSON = (obj, options) => {
|
|
16
|
+
return JSON.stringify(obj, null, (((options === null || options === void 0 ? void 0 : options.unformatted) || false) ? undefined : ((options === null || options === void 0 ? void 0 : options.tabSize) || 4)));
|
|
17
|
+
};
|
|
18
|
+
/** Print object in CSV format */
|
|
19
|
+
const printCSV = (obj, flags) => {
|
|
20
|
+
if (!obj || (obj.length === 0))
|
|
21
|
+
return '';
|
|
22
|
+
const fields = Object.keys(obj[0]).filter(f => {
|
|
23
|
+
if (['id', 'type'].includes(f))
|
|
24
|
+
return flags === null || flags === void 0 ? void 0 : flags.fields.includes(f);
|
|
25
|
+
return true;
|
|
26
|
+
});
|
|
27
|
+
let csv = fields.map(f => f.toUpperCase().replace(/_/g, ' ')).join(';') + '\n';
|
|
28
|
+
obj.forEach((o) => {
|
|
29
|
+
csv += fields.map(f => o[f]).join(';') + '\n';
|
|
30
|
+
});
|
|
31
|
+
return csv;
|
|
32
|
+
};
|
|
33
|
+
/** Center a string in the given width space */
|
|
34
|
+
const center = (str, width) => {
|
|
35
|
+
return str.padStart(str.length + Math.floor((width - str.length) / 2), ' ').padEnd(width, ' ');
|
|
36
|
+
};
|
|
37
|
+
/** Compute longest string in a list of strings */
|
|
38
|
+
const maxLength = (values, field) => {
|
|
39
|
+
return values.reduce((ml, v) => {
|
|
40
|
+
const f = Array.isArray(v[field]) ? v[field].join() : v[field];
|
|
41
|
+
return Math.max(ml, String(f).length);
|
|
42
|
+
}, 0);
|
|
43
|
+
};
|
|
44
|
+
/** Clean ISO string date */
|
|
45
|
+
const cleanDate = (date) => {
|
|
46
|
+
return date.replace('T', ' ').replace('Z', '').substring(0, date.lastIndexOf('.'));
|
|
47
|
+
};
|
|
48
|
+
/** Localized string date */
|
|
49
|
+
const localeDate = (date) => {
|
|
50
|
+
if (!date)
|
|
51
|
+
return '';
|
|
52
|
+
return new Date(Date.parse(date)).toLocaleString();
|
|
53
|
+
};
|
|
54
|
+
/** Format aoutput */
|
|
55
|
+
const formatOutput = (output, flags, { color = true } = {}) => {
|
|
56
|
+
if (!output)
|
|
57
|
+
return '';
|
|
58
|
+
if (typeof output === 'string')
|
|
59
|
+
return output;
|
|
60
|
+
if (flags) {
|
|
61
|
+
if (flags.csv)
|
|
62
|
+
return printCSV(output, flags);
|
|
63
|
+
if (flags.json)
|
|
64
|
+
return printJSON(output, { unformatted: flags.unformatted });
|
|
65
|
+
}
|
|
66
|
+
return printObject(output, { color });
|
|
67
|
+
};
|
|
68
|
+
/** Format error message */
|
|
69
|
+
const formatError = (error, flags) => {
|
|
70
|
+
return formatOutput(error.errors || error, flags);
|
|
71
|
+
};
|
|
72
|
+
export { printObject, printJSON, printCSV, center, maxLength, cleanDate, localeDate, formatOutput, formatError };
|
package/lib/esm/raw.js
CHANGED
|
@@ -1 +1,42 @@
|
|
|
1
|
-
import
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import { readFileSync } from 'fs';
|
|
3
|
+
import { clColor } from '.';
|
|
4
|
+
const rawRequest = async (config, data, id) => {
|
|
5
|
+
return await axios.request({
|
|
6
|
+
method: config.operation,
|
|
7
|
+
baseURL: config.baseUrl,
|
|
8
|
+
url: `/api/${config.resource}` + (id ? `/${id}` : ''),
|
|
9
|
+
headers: {
|
|
10
|
+
'Content-Type': 'application/vnd.api+json',
|
|
11
|
+
Accept: 'application/vnd.api+json',
|
|
12
|
+
Authorization: `Bearer ${config.accessToken}`,
|
|
13
|
+
},
|
|
14
|
+
data,
|
|
15
|
+
}).then(res => {
|
|
16
|
+
return res.data;
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
const readDataFile = (file) => {
|
|
20
|
+
let dataFile;
|
|
21
|
+
let dataJson;
|
|
22
|
+
try {
|
|
23
|
+
dataFile = readFileSync(file, 'utf-8');
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
throw new Error(`Unable to find or open the data file ${clColor.msg.error(file)}`);
|
|
27
|
+
}
|
|
28
|
+
try {
|
|
29
|
+
dataJson = JSON.parse(dataFile);
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
throw new Error(`Unable to parse the data file ${clColor.msg.error(file)}: invalid JSON format`);
|
|
33
|
+
}
|
|
34
|
+
const data = dataJson.data ? dataJson : { data: dataJson };
|
|
35
|
+
return data;
|
|
36
|
+
};
|
|
37
|
+
var Operation;
|
|
38
|
+
(function (Operation) {
|
|
39
|
+
Operation["Create"] = "POST";
|
|
40
|
+
Operation["Update"] = "PATCH";
|
|
41
|
+
})(Operation || (Operation = {}));
|
|
42
|
+
export { readDataFile, rawRequest, Operation };
|
package/lib/esm/schema.js
CHANGED
|
@@ -1 +1,14 @@
|
|
|
1
|
-
import
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import clConfig from './config';
|
|
3
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
4
|
+
const downloadSchema = async (version) => {
|
|
5
|
+
const domain = clConfig.api.default_app_domain;
|
|
6
|
+
const baseUrl = `https://data.${domain}/schemas/`;
|
|
7
|
+
const schemaVersion = version ? ('_' + version.replace(/\./g, '-')) : '';
|
|
8
|
+
const fileName = `openapi${schemaVersion}.json`;
|
|
9
|
+
const schemaUrl = baseUrl + fileName;
|
|
10
|
+
const schemaFile = await axios.get(schemaUrl);
|
|
11
|
+
const schemaData = schemaFile.data;
|
|
12
|
+
return schemaData;
|
|
13
|
+
};
|
|
14
|
+
export { downloadSchema as download };
|
package/lib/esm/style.js
CHANGED
|
@@ -1 +1,19 @@
|
|
|
1
|
-
import
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
// Colors
|
|
3
|
+
export const red = (txt) => { return chalk.red(txt); };
|
|
4
|
+
export const green = (txt) => { return chalk.green(txt); };
|
|
5
|
+
export const yellow = (txt) => { return chalk.yellow(txt); };
|
|
6
|
+
export const blue = (txt) => { return chalk.blue(txt); };
|
|
7
|
+
export const cyan = (txt) => { return chalk.cyan(txt); };
|
|
8
|
+
export const magenta = (txt) => { return chalk.magenta(txt); };
|
|
9
|
+
// API
|
|
10
|
+
export const slug = (txt) => { return chalk.yellowBright(txt); };
|
|
11
|
+
export const id = (txt) => { return chalk.magenta.bold(txt); };
|
|
12
|
+
// CLI
|
|
13
|
+
export const command = (txt) => { return chalk.cyan.italic(txt); };
|
|
14
|
+
export const flag = (txt) => { return chalk.magenta.italic(txt); };
|
|
15
|
+
// Messages
|
|
16
|
+
export const error = (txt) => { return chalk.red(txt); };
|
|
17
|
+
export const success = (txt) => { return chalk.green(txt); };
|
|
18
|
+
export const warning = (txt) => { return chalk.yellow(txt); };
|
|
19
|
+
export const highlight = (txt) => { return chalk.yellowBright(txt); };
|
package/lib/esm/symbol.js
CHANGED
|
@@ -1 +1,25 @@
|
|
|
1
|
-
const
|
|
1
|
+
const symbols = {
|
|
2
|
+
check: {
|
|
3
|
+
small: '\u2714', // ✔ (heavy)
|
|
4
|
+
bkgGreen: '\u2705', // ✅ (whiteHeavy)
|
|
5
|
+
squareRoot: '\u221A' // √
|
|
6
|
+
},
|
|
7
|
+
cross: {
|
|
8
|
+
small: '\u2718', // ✘ (heavyBallot)
|
|
9
|
+
red: '\u274C' // ❌ (crossMark)
|
|
10
|
+
},
|
|
11
|
+
clock: {
|
|
12
|
+
stopwatch: '\u23F1' // ⏱
|
|
13
|
+
},
|
|
14
|
+
arrow: {
|
|
15
|
+
down: '\u2193' // ↓ (downArrow)
|
|
16
|
+
},
|
|
17
|
+
selection: {
|
|
18
|
+
fisheye: '\u25C9' // ◉ (fishEye)
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
// ALIASES
|
|
22
|
+
symbols.check.heavy = symbols.check.small;
|
|
23
|
+
symbols.check.whiteHeavy = symbols.check.bkgGreen;
|
|
24
|
+
symbols.cross.heavyBallot = symbols.cross.small;
|
|
25
|
+
export { symbols };
|
package/lib/esm/text.js
CHANGED
|
@@ -1 +1,13 @@
|
|
|
1
|
-
import
|
|
1
|
+
import Inflector from './inflector';
|
|
2
|
+
const capitalize = (str) => {
|
|
3
|
+
if (!str)
|
|
4
|
+
return str;
|
|
5
|
+
let s = str.toLowerCase();
|
|
6
|
+
s = s.substring(0, 1).toUpperCase() + s.substring(1);
|
|
7
|
+
return s;
|
|
8
|
+
};
|
|
9
|
+
const pluralize = Inflector.pluralize;
|
|
10
|
+
const singularize = Inflector.singularize;
|
|
11
|
+
const camelize = Inflector.camelize;
|
|
12
|
+
export { capitalize, pluralize, singularize, camelize };
|
|
13
|
+
export { symbols } from './symbol';
|