@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
|
@@ -2,12 +2,28 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
const base_1 = tslib_1.__importStar(require("../../base"));
|
|
5
|
-
|
|
5
|
+
const lang_1 = require("../../lang");
|
|
6
6
|
// import { mergeCommandParams } from '../../commands'
|
|
7
7
|
const list_1 = tslib_1.__importDefault(require("./list"));
|
|
8
8
|
const cli_core_1 = require("@commercelayer/cli-core");
|
|
9
9
|
// const OPERATION = 'relationship'
|
|
10
10
|
class ResourcesRelationship extends base_1.default {
|
|
11
|
+
static description = 'fetch a resource relationship';
|
|
12
|
+
static aliases = ['provisioning:rel', 'prov:rel', 'prov:relationship'];
|
|
13
|
+
static hidden = true;
|
|
14
|
+
static examples = [
|
|
15
|
+
'$ commercelayer provisioning:relationship roles <roleId> organization',
|
|
16
|
+
'$ clayer prov:relationship roles <roleId> permissions',
|
|
17
|
+
'$ cl prov:rel roles <roleId> permisions -w subject_eq=testsub'
|
|
18
|
+
];
|
|
19
|
+
static flags = {
|
|
20
|
+
...list_1.default.flags,
|
|
21
|
+
};
|
|
22
|
+
static args = {
|
|
23
|
+
...list_1.default.args,
|
|
24
|
+
id: base_1.Args.string({ name: 'id', description: 'id of the resource to retrieve', required: true }),
|
|
25
|
+
relationship: base_1.Args.string({ name: 'relationship', description: 'name of the relationship field', required: true }),
|
|
26
|
+
};
|
|
11
27
|
async run() {
|
|
12
28
|
const { args, flags } = await this.parse(ResourcesRelationship);
|
|
13
29
|
const { res: resName, id } = this.checkResourceId(args.resource, args.id);
|
|
@@ -33,7 +49,7 @@ class ResourcesRelationship extends base_1.default {
|
|
|
33
49
|
const page = flags.page;
|
|
34
50
|
const perPage = flags.pageSize;
|
|
35
51
|
const rawReader = flags.raw ? cl.addRawResponseReader({ headers: showHeaders }) : undefined;
|
|
36
|
-
|
|
52
|
+
const reqReader = flags.doc ? (0, lang_1.addRequestReader)(cl) : undefined;
|
|
37
53
|
const params = {};
|
|
38
54
|
try {
|
|
39
55
|
if (include && (include.length > 0))
|
|
@@ -53,7 +69,8 @@ class ResourcesRelationship extends base_1.default {
|
|
|
53
69
|
// const savedParams = this.loadParams(loadParams, resource.api, OPERATION)
|
|
54
70
|
// if (savedParams) mergeCommandParams(params, savedParams)
|
|
55
71
|
// }
|
|
56
|
-
|
|
72
|
+
if (!flags.doc && multiRel)
|
|
73
|
+
base_1.cliux.action.start(`Fetching ${resource.api.replace(/_/g, ' ')}.${relationship} for id ${id}`);
|
|
57
74
|
const res = await resSdk[relationship](id, params);
|
|
58
75
|
if (multiRel)
|
|
59
76
|
base_1.cliux.action.stop();
|
|
@@ -80,10 +97,12 @@ class ResourcesRelationship extends base_1.default {
|
|
|
80
97
|
return out;
|
|
81
98
|
}
|
|
82
99
|
catch (error) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
100
|
+
if ((0, lang_1.isRequestInterrupted)(error) && reqReader) {
|
|
101
|
+
await this.showLiveDocumentation(reqReader.request, params, flags);
|
|
102
|
+
cl.removeInterceptor('request', reqReader.id);
|
|
103
|
+
}
|
|
104
|
+
else
|
|
105
|
+
this.printError(error, flags, args);
|
|
87
106
|
}
|
|
88
107
|
}
|
|
89
108
|
checkRelationship(sdk, name) {
|
|
@@ -95,20 +114,4 @@ class ResourcesRelationship extends base_1.default {
|
|
|
95
114
|
return (name === cli_core_1.clText.pluralize(name));
|
|
96
115
|
}
|
|
97
116
|
}
|
|
98
|
-
ResourcesRelationship.description = 'fetch a resource relationship';
|
|
99
|
-
ResourcesRelationship.aliases = ['provisioning:rel', 'prov:rel', 'prov:relationship'];
|
|
100
|
-
ResourcesRelationship.hidden = true;
|
|
101
|
-
ResourcesRelationship.examples = [
|
|
102
|
-
'$ commercelayer provisioning:relationship roles <roleId> organization',
|
|
103
|
-
'$ clayer prov:relationship roles <roleId> permissions',
|
|
104
|
-
'$ cl prov:rel roles <roleId> permisions -w subject_eq=testsub'
|
|
105
|
-
];
|
|
106
|
-
ResourcesRelationship.flags = {
|
|
107
|
-
...list_1.default.flags,
|
|
108
|
-
};
|
|
109
|
-
ResourcesRelationship.args = {
|
|
110
|
-
...base_1.default.args,
|
|
111
|
-
id: base_1.Args.string({ name: 'id', description: 'id of the resource to retrieve', required: true }),
|
|
112
|
-
relationship: base_1.Args.string({ name: 'relationship', description: 'name of the relationship field', required: true }),
|
|
113
|
-
};
|
|
114
117
|
exports.default = ResourcesRelationship;
|
|
@@ -4,6 +4,15 @@ const core_1 = require("@oclif/core");
|
|
|
4
4
|
const resources_1 = require("../../util/resources");
|
|
5
5
|
const cli_core_1 = require("@commercelayer/cli-core");
|
|
6
6
|
class ProvisioningResources extends core_1.Command {
|
|
7
|
+
static description = 'list all the available Provisioning API resources';
|
|
8
|
+
static aliases = ['prov:resources', 'pres'];
|
|
9
|
+
static examples = [
|
|
10
|
+
'$ commercelayer provisioning:resources',
|
|
11
|
+
'$ cl prov:resources',
|
|
12
|
+
];
|
|
13
|
+
static flags = {
|
|
14
|
+
help: core_1.Flags.help({ char: 'h' }),
|
|
15
|
+
};
|
|
7
16
|
async run() {
|
|
8
17
|
await this.parse(ProvisioningResources);
|
|
9
18
|
this.log(cli_core_1.clColor.style.title('\n-= Provisioning API available resources =-\n'));
|
|
@@ -24,13 +33,4 @@ class ProvisioningResources extends core_1.Command {
|
|
|
24
33
|
return await super.catch(error);
|
|
25
34
|
}
|
|
26
35
|
}
|
|
27
|
-
ProvisioningResources.description = 'list all the available Provisioning API resources';
|
|
28
|
-
ProvisioningResources.aliases = ['prov:resources', 'pres'];
|
|
29
|
-
ProvisioningResources.examples = [
|
|
30
|
-
'$ commercelayer provisioning:resources',
|
|
31
|
-
'$ cl prov:resources',
|
|
32
|
-
];
|
|
33
|
-
ProvisioningResources.flags = {
|
|
34
|
-
help: core_1.Flags.help({ char: 'h' }),
|
|
35
|
-
};
|
|
36
36
|
exports.default = ProvisioningResources;
|
|
@@ -4,18 +4,22 @@ export default class ProvisioningRetrieve extends Command {
|
|
|
4
4
|
static aliases: string[];
|
|
5
5
|
static examples: string[];
|
|
6
6
|
static flags: {
|
|
7
|
-
extract: import("@oclif/core/lib/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/lib/interfaces
|
|
8
|
-
include: import("@oclif/core/lib/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/lib/interfaces
|
|
9
|
-
fields: import("@oclif/core/lib/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/lib/interfaces
|
|
7
|
+
extract: import("@oclif/core/lib/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
8
|
+
include: import("@oclif/core/lib/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
9
|
+
fields: import("@oclif/core/lib/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
10
10
|
json: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
11
11
|
unformatted: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
12
12
|
raw: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
13
|
+
doc: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
14
|
+
lang: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
15
|
+
curl: import("@oclif/core/lib/interfaces").BooleanFlag<string>;
|
|
16
|
+
node: import("@oclif/core/lib/interfaces").BooleanFlag<string>;
|
|
13
17
|
headers: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
14
18
|
'headers-only': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
15
19
|
};
|
|
16
20
|
static args: {
|
|
17
|
-
id: import("@oclif/core/lib/interfaces
|
|
18
|
-
resource: import("@oclif/core/lib/interfaces
|
|
21
|
+
id: import("@oclif/core/lib/interfaces").Arg<string | undefined, Record<string, unknown>>;
|
|
22
|
+
resource: import("@oclif/core/lib/interfaces").Arg<string, Record<string, unknown>>;
|
|
19
23
|
};
|
|
20
24
|
run(): Promise<any>;
|
|
21
25
|
}
|
|
@@ -2,10 +2,45 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
const base_1 = tslib_1.__importStar(require("../../base"));
|
|
5
|
-
|
|
5
|
+
const lang_1 = require("../../lang");
|
|
6
6
|
// import { mergeCommandParams } from '../../commands'
|
|
7
7
|
const OPERATION = 'retrieve';
|
|
8
8
|
class ProvisioningRetrieve extends base_1.default {
|
|
9
|
+
static description = 'fetch a single resource';
|
|
10
|
+
static aliases = ['prov:retrieve', 'pr', 'pretrieve'];
|
|
11
|
+
static examples = [
|
|
12
|
+
'$ commercelayer provisioning:retrieve roles/<roleId>',
|
|
13
|
+
'$ commercelayer prov:retrieve roles <roleId>',
|
|
14
|
+
'$ cl prov:retrieve roles <roleId>',
|
|
15
|
+
'$ clayer pr roles/<roleId>',
|
|
16
|
+
];
|
|
17
|
+
static flags = {
|
|
18
|
+
...base_1.default.flags,
|
|
19
|
+
/*
|
|
20
|
+
save: Flags.string({
|
|
21
|
+
char: 'x',
|
|
22
|
+
description: 'save command output to file',
|
|
23
|
+
multiple: false,
|
|
24
|
+
exclusive: ['save-path'],
|
|
25
|
+
}),
|
|
26
|
+
'save-path': Flags.string({
|
|
27
|
+
char: 'X',
|
|
28
|
+
description: 'save command output to file and create missing path directories',
|
|
29
|
+
multiple: false,
|
|
30
|
+
exclusive: ['save'],
|
|
31
|
+
}),
|
|
32
|
+
*/
|
|
33
|
+
extract: base_1.Flags.string({
|
|
34
|
+
char: 'e',
|
|
35
|
+
description: 'extract subfields from object attributes',
|
|
36
|
+
multiple: true,
|
|
37
|
+
exclusive: ['raw'],
|
|
38
|
+
}),
|
|
39
|
+
};
|
|
40
|
+
static args = {
|
|
41
|
+
...base_1.default.args,
|
|
42
|
+
id: base_1.Args.string({ name: 'id', description: 'id of the resource to retrieve', required: false }),
|
|
43
|
+
};
|
|
9
44
|
async run() {
|
|
10
45
|
const { args, flags } = await this.parse(ProvisioningRetrieve);
|
|
11
46
|
const { res, id } = this.checkResourceId(args.resource, args.id);
|
|
@@ -20,7 +55,7 @@ class ProvisioningRetrieve extends base_1.default {
|
|
|
20
55
|
const fields = this.fieldsFlag(flags.fields, resource.api);
|
|
21
56
|
const cl = this.initCommerceLayer(flags);
|
|
22
57
|
const rawReader = flags.raw ? cl.addRawResponseReader({ headers: showHeaders }) : undefined;
|
|
23
|
-
|
|
58
|
+
const reqReader = flags.doc ? (0, lang_1.addRequestReader)(cl) : undefined;
|
|
24
59
|
const params = {};
|
|
25
60
|
try {
|
|
26
61
|
const resSdk = cl[resource.api];
|
|
@@ -49,47 +84,13 @@ class ProvisioningRetrieve extends base_1.default {
|
|
|
49
84
|
return out;
|
|
50
85
|
}
|
|
51
86
|
catch (error) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
87
|
+
if ((0, lang_1.isRequestInterrupted)(error) && reqReader) {
|
|
88
|
+
await this.showLiveDocumentation(reqReader.request, params, flags);
|
|
89
|
+
cl.removeInterceptor('request', reqReader.id);
|
|
90
|
+
}
|
|
91
|
+
else
|
|
92
|
+
this.printError(error, flags, args);
|
|
57
93
|
}
|
|
58
94
|
}
|
|
59
95
|
}
|
|
60
|
-
ProvisioningRetrieve.description = 'fetch a single resource';
|
|
61
|
-
ProvisioningRetrieve.aliases = ['prov:retrieve', 'pr', 'pretrieve'];
|
|
62
|
-
ProvisioningRetrieve.examples = [
|
|
63
|
-
'$ commercelayer provisioning:retrieve roles/<roleId>',
|
|
64
|
-
'$ commercelayer prov:retrieve roles <roleId>',
|
|
65
|
-
'$ cl prov:retrieve roles <roleId>',
|
|
66
|
-
'$ clayer pr roles/<roleId>',
|
|
67
|
-
];
|
|
68
|
-
ProvisioningRetrieve.flags = {
|
|
69
|
-
...base_1.default.flags,
|
|
70
|
-
/*
|
|
71
|
-
save: Flags.string({
|
|
72
|
-
char: 'x',
|
|
73
|
-
description: 'save command output to file',
|
|
74
|
-
multiple: false,
|
|
75
|
-
exclusive: ['save-path'],
|
|
76
|
-
}),
|
|
77
|
-
'save-path': Flags.string({
|
|
78
|
-
char: 'X',
|
|
79
|
-
description: 'save command output to file and create missing path directories',
|
|
80
|
-
multiple: false,
|
|
81
|
-
exclusive: ['save'],
|
|
82
|
-
}),
|
|
83
|
-
*/
|
|
84
|
-
extract: base_1.Flags.string({
|
|
85
|
-
char: 'e',
|
|
86
|
-
description: 'extract subfields from object attributes',
|
|
87
|
-
multiple: true,
|
|
88
|
-
exclusive: ['raw'],
|
|
89
|
-
}),
|
|
90
|
-
};
|
|
91
|
-
ProvisioningRetrieve.args = {
|
|
92
|
-
...base_1.default.args,
|
|
93
|
-
id: base_1.Args.string({ name: 'id', description: 'id of the resource to retrieve', required: false }),
|
|
94
|
-
};
|
|
95
96
|
exports.default = ProvisioningRetrieve;
|
|
@@ -4,23 +4,27 @@ export default class ProvisioningUpdate extends Command {
|
|
|
4
4
|
static aliases: string[];
|
|
5
5
|
static examples: string[];
|
|
6
6
|
static flags: {
|
|
7
|
-
attribute: import("@oclif/core/lib/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/lib/interfaces
|
|
8
|
-
object: import("@oclif/core/lib/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/lib/interfaces
|
|
9
|
-
relationship: import("@oclif/core/lib/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/lib/interfaces
|
|
10
|
-
metadata: import("@oclif/core/lib/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/lib/interfaces
|
|
11
|
-
'metadata-replace': import("@oclif/core/lib/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/lib/interfaces
|
|
12
|
-
data: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces
|
|
13
|
-
include: import("@oclif/core/lib/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/lib/interfaces
|
|
14
|
-
fields: import("@oclif/core/lib/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/lib/interfaces
|
|
7
|
+
attribute: import("@oclif/core/lib/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
8
|
+
object: import("@oclif/core/lib/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
9
|
+
relationship: import("@oclif/core/lib/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
10
|
+
metadata: import("@oclif/core/lib/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
11
|
+
'metadata-replace': import("@oclif/core/lib/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
12
|
+
data: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
13
|
+
include: import("@oclif/core/lib/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
14
|
+
fields: import("@oclif/core/lib/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
15
15
|
json: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
16
16
|
unformatted: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
17
17
|
raw: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
18
|
+
doc: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
19
|
+
lang: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
20
|
+
curl: import("@oclif/core/lib/interfaces").BooleanFlag<string>;
|
|
21
|
+
node: import("@oclif/core/lib/interfaces").BooleanFlag<string>;
|
|
18
22
|
headers: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
19
23
|
'headers-only': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
20
24
|
};
|
|
21
25
|
static args: {
|
|
22
|
-
id: import("@oclif/core/lib/interfaces
|
|
23
|
-
resource: import("@oclif/core/lib/interfaces
|
|
26
|
+
id: import("@oclif/core/lib/interfaces").Arg<string | undefined, Record<string, unknown>>;
|
|
27
|
+
resource: import("@oclif/core/lib/interfaces").Arg<string, Record<string, unknown>>;
|
|
24
28
|
};
|
|
25
29
|
run(): Promise<any>;
|
|
26
30
|
}
|
|
@@ -3,8 +3,58 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
const base_1 = tslib_1.__importStar(require("../../base"));
|
|
5
5
|
const cli_core_1 = require("@commercelayer/cli-core");
|
|
6
|
+
const lang_1 = require("../../lang");
|
|
6
7
|
const OPERATION = 'update';
|
|
7
8
|
class ProvisioningUpdate extends base_1.default {
|
|
9
|
+
static description = 'update an existing resource';
|
|
10
|
+
static aliases = ['prov:update', 'pu', 'pupdate', 'pupd'];
|
|
11
|
+
static examples = [
|
|
12
|
+
'$ commercelayer provisioning:update roles/<roleId> -a reference=referenceId',
|
|
13
|
+
'$ commercelayer prov:update roles <roleId> -a reference_origin="Ref Origin"',
|
|
14
|
+
'$ cl prov:update roles/<roleId> -m meta_key="meta value"',
|
|
15
|
+
'$ cl pu roles <roleId> -M meta_key="metadata overwrite',
|
|
16
|
+
'$ clayer prov:update roles <roleId> -D /path/to/data/file/data.json',
|
|
17
|
+
];
|
|
18
|
+
static flags = {
|
|
19
|
+
...base_1.default.flags,
|
|
20
|
+
attribute: base_1.Flags.string({
|
|
21
|
+
char: 'a',
|
|
22
|
+
description: 'define a resource attribute',
|
|
23
|
+
multiple: true,
|
|
24
|
+
}),
|
|
25
|
+
object: base_1.Flags.string({
|
|
26
|
+
char: 'O',
|
|
27
|
+
description: 'define a resource object attribute',
|
|
28
|
+
multiple: true,
|
|
29
|
+
}),
|
|
30
|
+
relationship: base_1.Flags.string({
|
|
31
|
+
char: 'r',
|
|
32
|
+
description: 'define a relationship with another resource',
|
|
33
|
+
multiple: true,
|
|
34
|
+
}),
|
|
35
|
+
metadata: base_1.Flags.string({
|
|
36
|
+
char: 'm',
|
|
37
|
+
description: 'define a metadata attribute and merge it with the metadata already present in the remote resource',
|
|
38
|
+
multiple: true,
|
|
39
|
+
exclusive: ['metadata-replace'],
|
|
40
|
+
}),
|
|
41
|
+
'metadata-replace': base_1.Flags.string({
|
|
42
|
+
char: 'M',
|
|
43
|
+
description: 'define a metadata attribute and replace every item already present in the remote resource',
|
|
44
|
+
multiple: true,
|
|
45
|
+
exclusive: ['metadata'],
|
|
46
|
+
}),
|
|
47
|
+
data: base_1.Flags.string({
|
|
48
|
+
char: 'D',
|
|
49
|
+
description: 'the data file to use as request body',
|
|
50
|
+
multiple: false,
|
|
51
|
+
exclusive: ['attribute', 'relationship', 'metadata', 'metadata-replace', 'doc' /*, FLAG_LOAD_PARAMS, FLAG_SAVE_PARAMS */],
|
|
52
|
+
})
|
|
53
|
+
};
|
|
54
|
+
static args = {
|
|
55
|
+
...base_1.default.args,
|
|
56
|
+
id: base_1.Args.string({ name: 'id', description: 'id of the resource to update', required: false }),
|
|
57
|
+
};
|
|
8
58
|
async run() {
|
|
9
59
|
const { args, flags } = await this.parse(ProvisioningUpdate);
|
|
10
60
|
const { res, id } = this.checkResourceId(args.resource, args.id);
|
|
@@ -64,7 +114,7 @@ class ProvisioningUpdate extends base_1.default {
|
|
|
64
114
|
// Fields flags
|
|
65
115
|
const fields = this.fieldsFlag(flags.fields, resource.api);
|
|
66
116
|
const rawReader = flags.raw ? cl.addRawResponseReader({ headers: showHeaders }) : undefined;
|
|
67
|
-
|
|
117
|
+
const reqReader = flags.doc ? (0, lang_1.addRequestReader)(cl) : undefined;
|
|
68
118
|
const params = {};
|
|
69
119
|
try {
|
|
70
120
|
const resSdk = cl[resource.api];
|
|
@@ -97,61 +147,13 @@ class ProvisioningUpdate extends base_1.default {
|
|
|
97
147
|
return out;
|
|
98
148
|
}
|
|
99
149
|
catch (error) {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
150
|
+
if ((0, lang_1.isRequestInterrupted)(error) && reqReader) {
|
|
151
|
+
await this.showLiveDocumentation(reqReader.request, undefined, flags);
|
|
152
|
+
cl.removeInterceptor('request', reqReader.id);
|
|
153
|
+
}
|
|
154
|
+
else
|
|
155
|
+
this.printError(error, flags, args);
|
|
105
156
|
}
|
|
106
157
|
}
|
|
107
158
|
}
|
|
108
|
-
ProvisioningUpdate.description = 'update an existing resource';
|
|
109
|
-
ProvisioningUpdate.aliases = ['prov:update', 'pu', 'pupdate', 'pupd'];
|
|
110
|
-
ProvisioningUpdate.examples = [
|
|
111
|
-
'$ commercelayer provisioning:update roles/<roleId> -a reference=referenceId',
|
|
112
|
-
'$ commercelayer prov:update roles <roleId> -a reference_origin="Ref Origin"',
|
|
113
|
-
'$ cl prov:update roles/<roleId> -m meta_key="meta value"',
|
|
114
|
-
'$ cl pu roles <roleId> -M meta_key="metadata overwrite',
|
|
115
|
-
'$ clayer prov:update roles <roleId> -D /path/to/data/file/data.json',
|
|
116
|
-
];
|
|
117
|
-
ProvisioningUpdate.flags = {
|
|
118
|
-
...base_1.default.flags,
|
|
119
|
-
attribute: base_1.Flags.string({
|
|
120
|
-
char: 'a',
|
|
121
|
-
description: 'define a resource attribute',
|
|
122
|
-
multiple: true,
|
|
123
|
-
}),
|
|
124
|
-
object: base_1.Flags.string({
|
|
125
|
-
char: 'O',
|
|
126
|
-
description: 'define a resource object attribute',
|
|
127
|
-
multiple: true,
|
|
128
|
-
}),
|
|
129
|
-
relationship: base_1.Flags.string({
|
|
130
|
-
char: 'r',
|
|
131
|
-
description: 'define a relationship with another resource',
|
|
132
|
-
multiple: true,
|
|
133
|
-
}),
|
|
134
|
-
metadata: base_1.Flags.string({
|
|
135
|
-
char: 'm',
|
|
136
|
-
description: 'define a metadata attribute and merge it with the metadata already present in the remote resource',
|
|
137
|
-
multiple: true,
|
|
138
|
-
exclusive: ['metadata-replace'],
|
|
139
|
-
}),
|
|
140
|
-
'metadata-replace': base_1.Flags.string({
|
|
141
|
-
char: 'M',
|
|
142
|
-
description: 'define a metadata attribute and replace every item already present in the remote resource',
|
|
143
|
-
multiple: true,
|
|
144
|
-
exclusive: ['metadata'],
|
|
145
|
-
}),
|
|
146
|
-
data: base_1.Flags.string({
|
|
147
|
-
char: 'D',
|
|
148
|
-
description: 'the data file to use as request body',
|
|
149
|
-
multiple: false,
|
|
150
|
-
exclusive: ['attribute', 'relationship', 'metadata', 'metadata-replace', 'doc' /*, FLAG_LOAD_PARAMS, FLAG_SAVE_PARAMS */],
|
|
151
|
-
})
|
|
152
|
-
};
|
|
153
|
-
ProvisioningUpdate.args = {
|
|
154
|
-
...base_1.default.args,
|
|
155
|
-
id: base_1.Args.string({ name: 'id', description: 'id of the resource to update', required: false }),
|
|
156
|
-
};
|
|
157
159
|
exports.default = ProvisioningUpdate;
|
package/lib/lang/curl.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildCurl = void 0;
|
|
4
|
+
const _1 = require(".");
|
|
5
|
+
const request_1 = require("./request");
|
|
6
|
+
const headers = (request) => {
|
|
7
|
+
return Object.entries((0, request_1.getHeaders)(request)).map(([h, v]) => {
|
|
8
|
+
return `-H '${h}: ${v}'`;
|
|
9
|
+
}).join(' \\\n ');
|
|
10
|
+
};
|
|
11
|
+
const buildCurl = (request, _params) => {
|
|
12
|
+
let cmd = `curl -g -X ${(0, request_1.getMethod)(request)} \\\n '${(0, _1.getFullUrl)(request)}' \\\n ${headers(request)}`;
|
|
13
|
+
if (request.data)
|
|
14
|
+
cmd += ` \\\n-d '${JSON.stringify(request.data)}'`;
|
|
15
|
+
return cmd;
|
|
16
|
+
};
|
|
17
|
+
exports.buildCurl = buildCurl;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { QueryParams } from '@commercelayer/provisioning-sdk';
|
|
2
|
+
import type { RequestData } from './request';
|
|
3
|
+
export { isRequestInterrupted } from './request';
|
|
4
|
+
export * from './request';
|
|
5
|
+
export declare const availableLanguages: string[];
|
|
6
|
+
export declare const languageInfo: {
|
|
7
|
+
curl: {
|
|
8
|
+
name: string;
|
|
9
|
+
label: string;
|
|
10
|
+
};
|
|
11
|
+
node: {
|
|
12
|
+
name: string;
|
|
13
|
+
label: string;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
declare const buildCommand: (lang: string, request: RequestData, params?: QueryParams, flags?: any) => string;
|
|
17
|
+
declare const getLanguageArg: (flags: any) => string;
|
|
18
|
+
declare const promptLanguage: () => Promise<string>;
|
|
19
|
+
export { getLanguageArg, buildCommand, promptLanguage };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.promptLanguage = exports.buildCommand = exports.getLanguageArg = exports.languageInfo = exports.availableLanguages = exports.isRequestInterrupted = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const curl_1 = require("./curl");
|
|
6
|
+
const ruby_1 = require("./ruby");
|
|
7
|
+
const node_1 = require("./node");
|
|
8
|
+
const inquirer_1 = tslib_1.__importDefault(require("inquirer"));
|
|
9
|
+
var request_1 = require("./request");
|
|
10
|
+
Object.defineProperty(exports, "isRequestInterrupted", { enumerable: true, get: function () { return request_1.isRequestInterrupted; } });
|
|
11
|
+
tslib_1.__exportStar(require("./request"), exports);
|
|
12
|
+
exports.availableLanguages = ['curl', 'node'];
|
|
13
|
+
exports.languageInfo = {
|
|
14
|
+
curl: { name: 'cURL', label: 'cURL command' },
|
|
15
|
+
node: { name: 'Node', label: 'Node SDK source code' },
|
|
16
|
+
};
|
|
17
|
+
const buildCommand = (lang, request, params, flags) => {
|
|
18
|
+
if (lang)
|
|
19
|
+
switch (lang.toLowerCase()) {
|
|
20
|
+
case 'curl': return (0, curl_1.buildCurl)(request, params);
|
|
21
|
+
case 'node': return (0, node_1.buildTypescript)(request, params, flags);
|
|
22
|
+
case 'ruby': return (0, ruby_1.buildRuby)(request, params);
|
|
23
|
+
default: return '';
|
|
24
|
+
}
|
|
25
|
+
else
|
|
26
|
+
return '';
|
|
27
|
+
};
|
|
28
|
+
exports.buildCommand = buildCommand;
|
|
29
|
+
const getLanguageArg = (flags) => {
|
|
30
|
+
let lang = flags.lang;
|
|
31
|
+
for (const l of exports.availableLanguages) {
|
|
32
|
+
if (flags[l]) {
|
|
33
|
+
lang = l;
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return lang;
|
|
38
|
+
};
|
|
39
|
+
exports.getLanguageArg = getLanguageArg;
|
|
40
|
+
const promptLanguage = async () => {
|
|
41
|
+
return await inquirer_1.default.prompt([{
|
|
42
|
+
type: 'list',
|
|
43
|
+
name: 'language',
|
|
44
|
+
message: 'Select a format to show the command live documentation:',
|
|
45
|
+
choices: exports.availableLanguages.map(l => {
|
|
46
|
+
const info = exports.languageInfo[l];
|
|
47
|
+
return { name: info.label, value: l, short: info.name };
|
|
48
|
+
}),
|
|
49
|
+
}]).then(answers => answers.language);
|
|
50
|
+
};
|
|
51
|
+
exports.promptLanguage = promptLanguage;
|
package/lib/lang/node.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildTypescript = void 0;
|
|
4
|
+
const _1 = require(".");
|
|
5
|
+
const cli_core_1 = require("@commercelayer/cli-core");
|
|
6
|
+
const buildTypescript = (request, params, flags) => {
|
|
7
|
+
const hasParams = params && (Object.keys(params).length > 0);
|
|
8
|
+
const operation = (0, _1.getOperation)(request);
|
|
9
|
+
const qpSuffix = (operation.name === 'list') ? 'List' : 'Retrieve';
|
|
10
|
+
const paramsImport = hasParams ? `, { QueryParams${qpSuffix} }` : '';
|
|
11
|
+
let ts = `import commercelayer${paramsImport} from '@commercelayer/provisioning-sdk'`;
|
|
12
|
+
ts += `\nconst accessToken = '${flags.accessToken}'`;
|
|
13
|
+
if (flags.domain)
|
|
14
|
+
ts += `\nconst domain = '${flags.domain}'`;
|
|
15
|
+
ts += `\n\nconst cl = commercelayer({ accessToken${flags.domain ? ', domain' : ''} })`;
|
|
16
|
+
if (hasParams)
|
|
17
|
+
ts += `\n\nconst params: QueryParams${qpSuffix} = ${cli_core_1.clOutput.printObject(params, { color: false })}`;
|
|
18
|
+
const args = [];
|
|
19
|
+
if (operation.id)
|
|
20
|
+
args.push(`'${operation.id}'`);
|
|
21
|
+
if (hasParams)
|
|
22
|
+
args.push('params');
|
|
23
|
+
ts += `\n\ncl.${operation.resource}.${operation.name}(${args.join(', ')}).then(console.log)`;
|
|
24
|
+
return ts;
|
|
25
|
+
};
|
|
26
|
+
exports.buildTypescript = buildTypescript;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type CommerceLayerProvisioningClient } from '@commercelayer/provisioning-sdk';
|
|
2
|
+
import { type KeyValString } from '@commercelayer/cli-core';
|
|
3
|
+
type RequestData = {
|
|
4
|
+
baseUrl: string;
|
|
5
|
+
path: string;
|
|
6
|
+
method: string;
|
|
7
|
+
headers: any;
|
|
8
|
+
params?: any;
|
|
9
|
+
data?: any;
|
|
10
|
+
};
|
|
11
|
+
type OperationData = {
|
|
12
|
+
name: string;
|
|
13
|
+
id?: string;
|
|
14
|
+
resource: string;
|
|
15
|
+
relationship?: string;
|
|
16
|
+
oneToMany?: boolean;
|
|
17
|
+
method: string;
|
|
18
|
+
};
|
|
19
|
+
type RequestReader = {
|
|
20
|
+
id: number;
|
|
21
|
+
request: RequestData;
|
|
22
|
+
};
|
|
23
|
+
declare const addRequestReader: (cl: CommerceLayerProvisioningClient, interrupt?: boolean) => RequestReader;
|
|
24
|
+
declare const isRequestInterrupted: (error: unknown) => boolean;
|
|
25
|
+
export { addRequestReader, isRequestInterrupted };
|
|
26
|
+
export type { RequestReader, RequestData, OperationData };
|
|
27
|
+
export declare const getMethod: (request: RequestData) => string;
|
|
28
|
+
export declare const getFullUrl: (request: RequestData) => string;
|
|
29
|
+
export declare const getResource: (request: RequestData) => string;
|
|
30
|
+
export declare const getRelationship: (request: RequestData) => string | undefined;
|
|
31
|
+
export declare const getHeaders: (request: RequestData) => KeyValString;
|
|
32
|
+
export declare const getOperation: (request: RequestData) => OperationData;
|