@commercelayer/cli-plugin-provisioning 1.0.1 → 2.0.0-oclif3.10
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/README.md +68 -16
- package/bin/run.js +7 -0
- package/lib/base.d.ts +16 -6
- package/lib/base.js +115 -92
- package/lib/commands/provisioning/create.d.ts +14 -7
- package/lib/commands/provisioning/create.js +48 -44
- package/lib/commands/provisioning/delete.d.ts +8 -4
- package/lib/commands/provisioning/delete.js +21 -20
- package/lib/commands/provisioning/exec.d.ts +4 -4
- package/lib/commands/provisioning/exec.js +18 -18
- package/lib/commands/provisioning/fetch.d.ts +14 -9
- package/lib/commands/provisioning/fetch.js +19 -18
- package/lib/commands/provisioning/get.d.ts +13 -9
- package/lib/commands/provisioning/get.js +16 -15
- package/lib/commands/provisioning/list.d.ts +14 -7
- package/lib/commands/provisioning/list.js +65 -61
- package/lib/commands/provisioning/noc.js +2 -2
- package/lib/commands/provisioning/relationship.d.ts +14 -10
- package/lib/commands/provisioning/relationship.js +26 -23
- package/lib/commands/provisioning/resources.js +9 -9
- package/lib/commands/provisioning/retrieve.d.ts +9 -5
- package/lib/commands/provisioning/retrieve.js +43 -42
- package/lib/commands/provisioning/update.d.ts +14 -10
- package/lib/commands/provisioning/update.js +57 -55
- package/lib/lang/curl.d.ts +4 -0
- package/lib/lang/curl.js +17 -0
- package/lib/lang/index.d.ts +19 -0
- package/lib/lang/index.js +51 -0
- package/lib/lang/node.d.ts +4 -0
- package/lib/lang/node.js +26 -0
- package/lib/lang/request.d.ts +32 -0
- package/lib/lang/request.js +108 -0
- package/lib/lang/ruby.d.ts +4 -0
- package/lib/lang/ruby.js +7 -0
- package/oclif.manifest.json +508 -12
- package/package.json +21 -19
- package/bin/dev +0 -18
- package/bin/dev.cmd +0 -3
- package/bin/run +0 -5
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getOperation = exports.getHeaders = exports.getRelationship = exports.getResource = exports.getFullUrl = exports.getMethod = exports.isRequestInterrupted = exports.addRequestReader = void 0;
|
|
4
|
+
const provisioning_sdk_1 = require("@commercelayer/provisioning-sdk");
|
|
5
|
+
const cli_core_1 = require("@commercelayer/cli-core");
|
|
6
|
+
class RequestInterrupted extends Error {
|
|
7
|
+
requestInterrupted = true;
|
|
8
|
+
constructor() {
|
|
9
|
+
super('REQUEST_INTERRUPT');
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
const addRequestReader = (cl, interrupt = true) => {
|
|
13
|
+
const reader = {
|
|
14
|
+
id: -1,
|
|
15
|
+
request: { baseUrl: '', path: '/', method: 'get', headers: {} },
|
|
16
|
+
};
|
|
17
|
+
function requestInterceptor(request) {
|
|
18
|
+
const c = request;
|
|
19
|
+
const x = reader.request;
|
|
20
|
+
x.path = c.url || '';
|
|
21
|
+
x.method = c.method || 'get';
|
|
22
|
+
x.headers = c.headers;
|
|
23
|
+
x.params = c.params;
|
|
24
|
+
x.baseUrl = c.baseURL || '';
|
|
25
|
+
x.data = c.data;
|
|
26
|
+
if (interrupt)
|
|
27
|
+
throw new RequestInterrupted();
|
|
28
|
+
return request;
|
|
29
|
+
}
|
|
30
|
+
const interceptor = cl.addRequestInterceptor(requestInterceptor);
|
|
31
|
+
reader.id = interceptor;
|
|
32
|
+
return reader;
|
|
33
|
+
};
|
|
34
|
+
exports.addRequestReader = addRequestReader;
|
|
35
|
+
const isRequestInterrupted = (error) => {
|
|
36
|
+
return (provisioning_sdk_1.CommerceLayerProvisioningStatic.isSdkError(error) && (error.source instanceof RequestInterrupted) && error.source.requestInterrupted);
|
|
37
|
+
};
|
|
38
|
+
exports.isRequestInterrupted = isRequestInterrupted;
|
|
39
|
+
const getMethod = (request) => {
|
|
40
|
+
return request.method?.toUpperCase();
|
|
41
|
+
};
|
|
42
|
+
exports.getMethod = getMethod;
|
|
43
|
+
const getFullUrl = (request) => {
|
|
44
|
+
let fullUrl = `${request.baseUrl}/${request.path}`;
|
|
45
|
+
if (request.params && (Object.keys(request.params).length > 0)) {
|
|
46
|
+
const qs = Object.entries(request.params).map(([k, v]) => `${k}=${v}`).join('&');
|
|
47
|
+
fullUrl += `?${qs}`;
|
|
48
|
+
}
|
|
49
|
+
return fullUrl;
|
|
50
|
+
};
|
|
51
|
+
exports.getFullUrl = getFullUrl;
|
|
52
|
+
const getResource = (request) => {
|
|
53
|
+
const slashIdx = request.path.indexOf('/');
|
|
54
|
+
if (slashIdx < 0)
|
|
55
|
+
return request.path;
|
|
56
|
+
return request.path.substring(0, slashIdx);
|
|
57
|
+
};
|
|
58
|
+
exports.getResource = getResource;
|
|
59
|
+
const getRelationship = (request) => {
|
|
60
|
+
const i1 = request.path.indexOf('/');
|
|
61
|
+
const il = request.path.lastIndexOf('/');
|
|
62
|
+
return (i1 === il) ? undefined : request.path.substring(il + 1);
|
|
63
|
+
};
|
|
64
|
+
exports.getRelationship = getRelationship;
|
|
65
|
+
const getHeaders = (request) => {
|
|
66
|
+
/*
|
|
67
|
+
const headers = { ...request.headers }
|
|
68
|
+
for (const h of Object.keys(headers))
|
|
69
|
+
if (['User-Agent', 'Content-Length'].includes(h)) delete headers[h]
|
|
70
|
+
return headers
|
|
71
|
+
*/
|
|
72
|
+
return {
|
|
73
|
+
Accept: request.headers.Accept,
|
|
74
|
+
'Content-Type': request.headers['Content-Type'],
|
|
75
|
+
Authorization: request.headers.Authorization,
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
exports.getHeaders = getHeaders;
|
|
79
|
+
const getOperation = (request) => {
|
|
80
|
+
const res = (0, exports.getResource)(request);
|
|
81
|
+
const rel = (0, exports.getRelationship)(request);
|
|
82
|
+
const id = request.path.replace(res, '').replace(rel || '', '').replace(/\//g, '');
|
|
83
|
+
const method = request.method.toLowerCase();
|
|
84
|
+
const singleton = ['application', 'organization'].includes(res);
|
|
85
|
+
const op = {
|
|
86
|
+
method,
|
|
87
|
+
name: 'retrieve',
|
|
88
|
+
resource: res,
|
|
89
|
+
relationship: rel,
|
|
90
|
+
id,
|
|
91
|
+
};
|
|
92
|
+
if (op.relationship)
|
|
93
|
+
op.oneToMany = (cli_core_1.clText.pluralize(op.relationship) === op.relationship);
|
|
94
|
+
if (op.method === 'get') {
|
|
95
|
+
if (singleton || (op.id && !op.relationship))
|
|
96
|
+
op.name = 'retrieve';
|
|
97
|
+
else
|
|
98
|
+
op.name = rel || 'list';
|
|
99
|
+
}
|
|
100
|
+
else if (method === 'patch')
|
|
101
|
+
op.name = 'update';
|
|
102
|
+
else if (method === 'post')
|
|
103
|
+
op.name = 'create';
|
|
104
|
+
else if (method === 'delete')
|
|
105
|
+
op.name = 'delete';
|
|
106
|
+
return op;
|
|
107
|
+
};
|
|
108
|
+
exports.getOperation = getOperation;
|