@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.
@@ -1 +1,253 @@
1
- const o={uncountableWords:["equipment","information","rice","money","species","series","fish","sheep","moose","deer","news"],pluralRules:[[/(m)an$/gi,"$1en"],[/(pe)rson$/gi,"$1ople"],[/(child)$/gi,"$1ren"],[/^(ox)$/gi,"$1en"],[/(ax|test)is$/gi,"$1es"],[/(octop|vir)us$/gi,"$1i"],[/(alias|status)$/gi,"$1es"],[/(bu)s$/gi,"$1ses"],[/(buffal|tomat|potat)o$/gi,"$1oes"],[/([ti])um$/gi,"$1a"],[/sis$/gi,"ses"],[/(?:([^f])fe|([lr])f)$/gi,"$1$2ves"],[/(hive)$/gi,"$1s"],[/([^aeiouy]|qu)y$/gi,"$1ies"],[/(x|ch|ss|sh)$/gi,"$1es"],[/(matr|vert|ind)ix|ex$/gi,"$1ices"],[/([m|l])ouse$/gi,"$1ice"],[/(quiz)$/gi,"$1zes"],[/s$/gi,"s"],[/$/gi,"s"]],singularRules:[[/(m)en$/gi,"$1an"],[/(pe)ople$/gi,"$1rson"],[/(child)ren$/gi,"$1"],[/([ti])a$/gi,"$1um"],[/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$/gi,"$1$2sis"],[/(hive)s$/gi,"$1"],[/(tive)s$/gi,"$1"],[/(curve)s$/gi,"$1"],[/([lr])ves$/gi,"$1f"],[/([^fo])ves$/gi,"$1fe"],[/([^aeiouy]|qu)ies$/gi,"$1y"],[/(s)eries$/gi,"$1eries"],[/(m)ovies$/gi,"$1ovie"],[/(x|ch|ss|sh)es$/gi,"$1"],[/([m|l])ice$/gi,"$1ouse"],[/(bus)es$/gi,"$1"],[/(o)es$/gi,"$1"],[/(shoe)s$/gi,"$1"],[/(cris|ax|test)es$/gi,"$1is"],[/(octop|vir)i$/gi,"$1us"],[/(alias|status)es$/gi,"$1"],[/^(ox)en/gi,"$1"],[/(vert|ind)ices$/gi,"$1ex"],[/(matr)ices$/gi,"$1ix"],[/(quiz)zes$/gi,"$1"],[/s$/gi,""]],nonTitlecasedWords:["and","or","nor","a","an","the","so","but","to","of","at","by","from","into","on","onto","off","out","in","over","with","for"],idSuffix:/(_ids|_id)$/g,underbar:/_/g,spaceOrUnderbar:/[ _]/g,uppercase:/([A-Z])/g,underbarPrefix:/^_/,applyRules:function(e,i,n,r){if(r)e=r;else if(!n.includes(e.toLowerCase())){for(let a=0;a<i.length;a++)if(e.match(i[a][0])){e=e.replace(i[a][0],i[a][1]);break}}return e},pluralize:function(e,i){return o.applyRules(e,o.pluralRules,o.uncountableWords,i)},singularize:function(e,i){return o.applyRules(e,o.singularRules,o.uncountableWords,i)},camelize:function(e,i){const n=e.split("/");for(let r=0;r<n.length;r++){const s=n[r].split("_"),a=i&&r+1===n.length?1:0;for(let t=a;t<s.length;t++)s[t]=s[t].charAt(0).toUpperCase()+s[t].substring(1);n[r]=s.join("")}if(e=n.join("::"),i){const r=e.charAt(0).toLowerCase(),s=e.slice(1);e=r+s}return e},underscore:function(e){const i=e.split("::");for(let n=0;n<i.length;n++)i[n]=i[n].replace(o.uppercase,"_$1"),i[n]=i[n].replace(o.underbarPrefix,"");return e=i.join("/").toLowerCase(),e},humanize:function(e,i){return e=e.toLowerCase(),e=e.replace(o.idSuffix,""),e=e.replace(o.underbar," "),i||(e=o.capitalize(e)),e},capitalize:function(e){return e=e.toLowerCase(),e=e.substring(0,1).toUpperCase()+e.substring(1),e},dasherize:function(e){return e=e.replace(o.spaceOrUnderbar,"-"),e},camel2words:function(e,i){i?(e=o.camelize(e),e=o.underscore(e)):e=e.toLowerCase(),e=e.replace(o.underbar," ");const n=e.split(" ");for(let r=0;r<n.length;r++){const s=n[r].split("-");for(let a=0;a<s.length;a++)o.nonTitlecasedWords.includes(s[a].toLowerCase())||(s[a]=o.capitalize(s[a]));n[r]=s.join("-")}return e=n.join(" "),e=e.substring(0,1).toUpperCase()+e.substring(1),e},demodulize:function(e){const i=e.split("::");return e=i[i.length-1],e},tableize:function(e){return e=o.pluralize(o.underscore(e)),e},classify:function(e){return e=o.singularize(o.camelize(e)),e},foreignKey:function(e,i){return e=o.underscore(o.demodulize(e))+(i?"":"_")+"id",e},ordinalize:function(e){const i=e.split(" ");for(let n=0;n<i.length;n++){const r=parseInt(i[n]);if(Number.isNaN(r)){const s=i[n].substring(i[n].length-2),a=i[n].substring(i[n].length-1);let t="th";s!=="11"&&s!=="12"&&s!=="13"&&(a==="1"?t="st":a==="2"?t="nd":a==="3"&&(t="rd")),i[n]+=t}}return e=i.join(" "),e}};export default o;
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;
@@ -1 +1,42 @@
1
- const l=(t,e)=>e.find(i=>t.id===i.id&&t.type===i.type),r=(t,e)=>{const i=Object.assign({id:t.id,type:t.type},t.attributes);return t.relationships&&Object.keys(t.relationships).forEach(a=>{const n=t.relationships[a].data;n?Array.isArray(n)?i[a]=n.map(s=>r(l(s,e),e)):i[a]=r(l(n,e),e):n===null&&(i[a]=null)}),i},o=t=>{let e;t.links&&delete t.links;const i=t.data,a=t.included;return Array.isArray(i)?e=i.map(n=>r(n,a)):e=r(i,a),e};export{o as denormalize};
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
- import{inspect as f}from"util";const d=(e,r)=>f(e,{showHidden:!1,depth:null,colors:r?.color===void 0?!0:r.color,sorted:r?.sort===void 0?!1:r?.sort,maxArrayLength:1/0,breakLength:r?.width||120}),u=(e,r)=>JSON.stringify(e,null,r?.unformatted?void 0:r?.tabSize||4),i=(e,r)=>{if(!e||e.length===0)return"";const t=Object.keys(e[0]).filter(n=>["id","type"].includes(n)?r?.fields.includes(n):!0);let l=t.map(n=>n.toUpperCase().replace(/_/g," ")).join(";")+`
2
- `;return e.forEach(n=>{l+=t.map(a=>n[a]).join(";")+`
3
- `}),l},o=(e,r)=>e.padStart(e.length+Math.floor((r-e.length)/2)," ").padEnd(r," "),v=(e,r)=>e.reduce((t,l)=>{const n=Array.isArray(l[r])?l[r].join():l[r];return Math.max(t,String(n).length)},0),h=e=>e.replace("T"," ").replace("Z","").substring(0,e.lastIndexOf(".")),m=e=>e?new Date(Date.parse(e)).toLocaleString():"",c=(e,r,{color:t=!0}={})=>{if(!e)return"";if(typeof e=="string")return e;if(r){if(r.csv)return i(e,r);if(r.json)return u(e,{unformatted:r.unformatted})}return d(e,{color:t})},s=(e,r)=>c(e.errors||e,r);export{d as printObject,u as printJSON,i as printCSV,o as center,v as maxLength,h as cleanDate,m as localeDate,c as formatOutput,s as formatError};
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 i from"axios";import{readFileSync as p}from"fs";import{clColor as n}from".";const d=async(r,t,a)=>await i.request({method:r.operation,baseURL:r.baseUrl,url:`/api/${r.resource}`+(a?`/${a}`:""),headers:{"Content-Type":"application/vnd.api+json",Accept:"application/vnd.api+json",Authorization:`Bearer ${r.accessToken}`},data:t}).then(o=>o.data),c=r=>{let t,a;try{t=p(r,"utf-8")}catch{throw new Error(`Unable to find or open the data file ${n.msg.error(r)}`)}try{a=JSON.parse(t)}catch{throw new Error(`Unable to parse the data file ${n.msg.error(r)}: invalid JSON format`)}return a.data?a:{data:a}};var e;(function(r){r.Create="POST",r.Update="PATCH"})(e||(e={}));export{c as readDataFile,d as rawRequest,e as Operation};
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 t from"axios";import c from"./config";const n=async a=>{const o=`https://data.${c.api.default_app_domain}/schemas/`,s=`openapi${a?"_"+a.replace(/\./g,"-"):""}.json`,e=o+s;return(await t.get(e)).data};export{n as download};
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 t from"chalk";export const red=r=>t.red(r),green=r=>t.green(r),yellow=r=>t.yellow(r),blue=r=>t.blue(r),cyan=r=>t.cyan(r),magenta=r=>t.magenta(r),slug=r=>t.yellowBright(r),id=r=>t.magenta.bold(r),command=r=>t.cyan.italic(r),flag=r=>t.magenta.italic(r),error=r=>t.red(r),success=r=>t.green(r),warning=r=>t.yellow(r),highlight=r=>t.yellowBright(r);
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 e={check:{small:"\u2714",bkgGreen:"\u2705",squareRoot:"\u221A"},cross:{small:"\u2718",red:"\u274C"},clock:{stopwatch:"\u23F1"},arrow:{down:"\u2193"},selection:{fisheye:"\u25C9"}};e.check.heavy=e.check.small,e.check.whiteHeavy=e.check.bkgGreen,e.cross.heavyBallot=e.cross.small;export{e as symbols};
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 i from"./inflector";const o=r=>{if(!r)return r;let e=r.toLowerCase();return e=e.substring(0,1).toUpperCase()+e.substring(1),e},t=i.pluralize,s=i.singularize,l=i.camelize;export{o as capitalize,t as pluralize,s as singularize,l as camelize};export{symbols}from"./symbol";
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';