@commercelayer/cli-plugin-provisioning 1.0.0

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 (42) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +413 -0
  3. package/bin/dev +18 -0
  4. package/bin/dev.cmd +3 -0
  5. package/bin/run +5 -0
  6. package/bin/run.cmd +3 -0
  7. package/lib/base.d.ts +59 -0
  8. package/lib/base.js +496 -0
  9. package/lib/commands/provisioning/create.d.ts +21 -0
  10. package/lib/commands/provisioning/create.js +137 -0
  11. package/lib/commands/provisioning/delete.d.ts +20 -0
  12. package/lib/commands/provisioning/delete.js +52 -0
  13. package/lib/commands/provisioning/exec.d.ts +15 -0
  14. package/lib/commands/provisioning/exec.js +55 -0
  15. package/lib/commands/provisioning/fetch.d.ts +28 -0
  16. package/lib/commands/provisioning/fetch.js +57 -0
  17. package/lib/commands/provisioning/get.d.ts +27 -0
  18. package/lib/commands/provisioning/get.js +31 -0
  19. package/lib/commands/provisioning/list.d.ts +22 -0
  20. package/lib/commands/provisioning/list.js +137 -0
  21. package/lib/commands/provisioning/noc.d.ts +6 -0
  22. package/lib/commands/provisioning/noc.js +13 -0
  23. package/lib/commands/provisioning/relationship.d.ts +30 -0
  24. package/lib/commands/provisioning/relationship.js +114 -0
  25. package/lib/commands/provisioning/resources.d.ts +11 -0
  26. package/lib/commands/provisioning/resources.js +36 -0
  27. package/lib/commands/provisioning/retrieve.d.ts +21 -0
  28. package/lib/commands/provisioning/retrieve.js +95 -0
  29. package/lib/commands/provisioning/update.d.ts +26 -0
  30. package/lib/commands/provisioning/update.js +157 -0
  31. package/lib/csv.d.ts +3 -0
  32. package/lib/csv.js +98 -0
  33. package/lib/output.d.ts +5 -0
  34. package/lib/output.js +15 -0
  35. package/lib/util/resources/available.d.ts +35 -0
  36. package/lib/util/resources/available.js +13 -0
  37. package/lib/util/resources/build.d.ts +1 -0
  38. package/lib/util/resources/build.js +47 -0
  39. package/lib/util/resources/index.d.ts +12 -0
  40. package/lib/util/resources/index.js +19 -0
  41. package/oclif.manifest.json +1502 -0
  42. package/package.json +86 -0
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const base_1 = tslib_1.__importStar(require("../../base"));
5
+ // import { addRequestReader, isRequestInterrupted } from '../../lang'
6
+ const cli_core_1 = require("@commercelayer/cli-core");
7
+ const OPERATION = 'delete';
8
+ class ProvisioningDelete extends base_1.default {
9
+ async run() {
10
+ const { args, flags } = await this.parse(ProvisioningDelete);
11
+ const invalidFlags = ['fields', 'include'];
12
+ invalidFlags.forEach(x => {
13
+ if (flags[x])
14
+ this.error(`Flag not supported in ${cli_core_1.clColor.cli.command(OPERATION)} operation: ${cli_core_1.clColor.style.error(x)}`);
15
+ });
16
+ const { res, id } = this.checkResourceId(args.resource, args.id);
17
+ const resource = this.checkResource(res, { singular: true });
18
+ const showHeaders = flags.headers || flags['headers-only'];
19
+ const cl = this.initCommerceLayer(flags);
20
+ const rawReader = (flags.raw && showHeaders) ? cl.addRawResponseReader({ headers: showHeaders }) : undefined;
21
+ // const reqReader = flags.doc ? addRequestReader(cl) : undefined
22
+ try {
23
+ const resSdk = cl[resource.api];
24
+ this.checkOperation(resSdk, OPERATION);
25
+ await resSdk.delete(id);
26
+ if (showHeaders)
27
+ this.printHeaders(rawReader?.headers, flags);
28
+ this.log(`\n${cli_core_1.clColor.style.success('Successfully')} deleted resource of type ${cli_core_1.clColor.style.resource(resource.api)} with id ${cli_core_1.clColor.style.id(id)}\n`);
29
+ }
30
+ catch (error) {
31
+ /*
32
+ if (isRequestInterrupted(error) && reqReader) {
33
+ await this.showLiveDocumentation(reqReader.request, undefined, flags)
34
+ cl.removeInterceptor('request', reqReader.id)
35
+ } else */ this.printError(error, flags, args);
36
+ }
37
+ }
38
+ }
39
+ ProvisioningDelete.description = 'delete an existing resource';
40
+ ProvisioningDelete.aliases = ['prov:delete', 'pd', 'pdelete', 'pdel'];
41
+ ProvisioningDelete.examples = [
42
+ '$ commercelayer provisioning:delete api_credentials/<id>',
43
+ '$ cl prov:delete api_credentials <id>',
44
+ ];
45
+ ProvisioningDelete.flags = {
46
+ ...(cli_core_1.clCommand.commandFlags(base_1.default.flags, ['save-params', 'load-params']))
47
+ };
48
+ ProvisioningDelete.args = {
49
+ ...base_1.default.args,
50
+ id: base_1.Args.string({ name: 'id', description: 'id of the resource to delete', required: false })
51
+ };
52
+ exports.default = ProvisioningDelete;
@@ -0,0 +1,15 @@
1
+ import { BaseCommand } from '../../base';
2
+ export default class ProvisioningExec extends BaseCommand {
3
+ static description: string;
4
+ static aliases: string[];
5
+ static examples: string[];
6
+ static flags: {
7
+ attribute: import("@oclif/core/lib/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
8
+ };
9
+ static args: {
10
+ id: import("@oclif/core/lib/interfaces/parser").Arg<string | undefined, Record<string, unknown>>;
11
+ action: import("@oclif/core/lib/interfaces/parser").Arg<string | undefined, Record<string, unknown>>;
12
+ resource: import("@oclif/core/lib/interfaces/parser").Arg<string, Record<string, unknown>>;
13
+ };
14
+ run(): Promise<void>;
15
+ }
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const base_1 = tslib_1.__importStar(require("../../base"));
5
+ const cli_core_1 = require("@commercelayer/cli-core");
6
+ class ProvisioningExec extends base_1.BaseCommand {
7
+ async run() {
8
+ const { args, flags } = await this.parse(ProvisioningExec);
9
+ const action = args.action;
10
+ if (!action)
11
+ this.error('Missing action name');
12
+ const { res, id } = this.checkResourceId(args.resource, args.id);
13
+ const resource = this.checkResource(res, { singular: true });
14
+ const clp = this.initCommerceLayer(flags);
15
+ try {
16
+ const resSdk = clp[resource.api];
17
+ this.checkOperation(resSdk, action);
18
+ if (resSdk[action].length > 2) { // Base action command has two arguments: resource id and request options
19
+ const attributes = this.attributeFlag(flags.attribute);
20
+ await resSdk[action](id, attributes);
21
+ }
22
+ else {
23
+ if (flags.attribute && (flags.attribute.length > 0))
24
+ this.warn(`Action ${cli_core_1.clColor.cli.arg(action)} does not require argumemts, all the attributes will be ignored.`);
25
+ await resSdk[action](id);
26
+ }
27
+ }
28
+ catch (error) {
29
+ /*
30
+ if (isRequestInterrupted(error) && reqReader) {
31
+ await this.showLiveDocumentation(reqReader.request, undefined, flags)
32
+ cl.removeInterceptor('request', reqReader.id)
33
+ } else */ this.printError(error, flags, args);
34
+ }
35
+ }
36
+ }
37
+ ProvisioningExec.description = 'execute an action on a resource';
38
+ ProvisioningExec.aliases = ['prov:exec', 'pe', 'pexec'];
39
+ ProvisioningExec.examples = [
40
+ '$ commercelayer provisioning:exec organizations <organizationId> transfer_ownership',
41
+ '$ cl prov:exec memberships <membershipId> resend'
42
+ ];
43
+ ProvisioningExec.flags = {
44
+ attribute: base_1.Flags.string({
45
+ char: 'a',
46
+ description: 'define a resource attribute',
47
+ multiple: true,
48
+ })
49
+ };
50
+ ProvisioningExec.args = {
51
+ ...base_1.default.args,
52
+ id: base_1.Args.string({ name: 'id', description: 'id of the resource on which to execute the action', required: false }),
53
+ action: base_1.Args.string({ name: 'action', description: 'action to execute on resource', required: false })
54
+ };
55
+ exports.default = ProvisioningExec;
@@ -0,0 +1,28 @@
1
+ import { BaseFilterCommand } from '../../base';
2
+ export default class ResourcesFetch extends BaseFilterCommand {
3
+ static description: string;
4
+ static aliases: string[];
5
+ static examples: string[];
6
+ static strict: boolean;
7
+ static flags: {
8
+ where: import("@oclif/core/lib/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
9
+ page: import("@oclif/core/lib/interfaces").OptionFlag<number | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
10
+ pageSize: import("@oclif/core/lib/interfaces").OptionFlag<number | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
11
+ sort: import("@oclif/core/lib/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
12
+ extract: import("@oclif/core/lib/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
13
+ 'force-include': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
14
+ include: import("@oclif/core/lib/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
15
+ fields: import("@oclif/core/lib/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
16
+ json: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
17
+ unformatted: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
18
+ raw: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
19
+ headers: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
20
+ 'headers-only': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
21
+ };
22
+ static args: {
23
+ path: import("@oclif/core/lib/interfaces/parser").Arg<string, Record<string, unknown>>;
24
+ id: import("@oclif/core/lib/interfaces/parser").Arg<string | undefined, Record<string, unknown>>;
25
+ };
26
+ run(): Promise<any>;
27
+ private fixPath;
28
+ }
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const base_1 = require("../../base");
5
+ const retrieve_1 = tslib_1.__importDefault(require("./retrieve"));
6
+ const list_1 = tslib_1.__importDefault(require("./list"));
7
+ const relationship_1 = tslib_1.__importDefault(require("./relationship"));
8
+ const get_1 = tslib_1.__importDefault(require("./get"));
9
+ class ResourcesFetch extends base_1.BaseFilterCommand {
10
+ async run() {
11
+ const { args } = await this.parse(ResourcesFetch);
12
+ const path = this.fixPath(args.path, args);
13
+ const id = args.id;
14
+ // If no relationship is defined then run retrieve/list command
15
+ const pathNodes = path.split('/');
16
+ if (pathNodes.length < 3)
17
+ return await get_1.default.run(this.argv, this.config);
18
+ // Build argv array to pass to Relationship command
19
+ const relArgs = [...this.argv];
20
+ relArgs.splice(0, id ? 2 : 1, ...pathNodes);
21
+ return await relationship_1.default.run(relArgs, this.config);
22
+ }
23
+ fixPath(path, args, _flags) {
24
+ // Remove base URL
25
+ if (path.startsWith('http'))
26
+ path = path.substring(path.indexOf('/api/') + 4);
27
+ // Remove 'relationships' sub-path (usually part of 'self' link)
28
+ if (path.includes('/relationships/'))
29
+ path = path.replace('/relationships', '');
30
+ // Remove leading slash
31
+ if (path.startsWith('/'))
32
+ path = path.substring(1);
33
+ // Replace {resourceId} placeholder with actual resource id
34
+ if (args.id)
35
+ path = path.replace(/\{.*\}/g, args.id);
36
+ return path;
37
+ }
38
+ }
39
+ ResourcesFetch.description = 'retrieve a resource or list a set of resources';
40
+ ResourcesFetch.aliases = ['prov:fetch', 'pf'];
41
+ ResourcesFetch.examples = [
42
+ '$ commercelayer provisioning:fetch roles',
43
+ '$ commercelayer prov:fetch roles',
44
+ '$ clayer prov:fetch roles/<roleId>',
45
+ '$ cl prov:fetch roles/<roleId>/<roleRelationship>',
46
+ '$ cl pf roles/{roleId}/permissions aBcdEkYWx',
47
+ ];
48
+ ResourcesFetch.strict = false;
49
+ ResourcesFetch.flags = {
50
+ ...retrieve_1.default.flags,
51
+ ...list_1.default.flags,
52
+ };
53
+ ResourcesFetch.args = {
54
+ path: base_1.Args.string({ name: 'path', description: 'path (or URL) of the resource(s) to fetch', required: true }),
55
+ id: base_1.Args.string({ name: 'id', description: 'resource id', required: false }),
56
+ };
57
+ exports.default = ResourcesFetch;
@@ -0,0 +1,27 @@
1
+ import Command from '../../base';
2
+ export default class ProvisioningGet extends Command {
3
+ static description: string;
4
+ static aliases: string[];
5
+ static examples: string[];
6
+ static strict: boolean;
7
+ static flags: {
8
+ where: import("@oclif/core/lib/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
9
+ page: import("@oclif/core/lib/interfaces").OptionFlag<number | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
10
+ pageSize: import("@oclif/core/lib/interfaces").OptionFlag<number | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
11
+ sort: import("@oclif/core/lib/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
12
+ extract: import("@oclif/core/lib/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
13
+ 'force-include': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
14
+ include: import("@oclif/core/lib/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
15
+ fields: import("@oclif/core/lib/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
16
+ json: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
17
+ unformatted: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
18
+ raw: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
19
+ headers: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
20
+ 'headers-only': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
21
+ };
22
+ static args: {
23
+ id: import("@oclif/core/lib/interfaces/parser").Arg<string | undefined, Record<string, unknown>>;
24
+ resource: import("@oclif/core/lib/interfaces/parser").Arg<string, Record<string, unknown>>;
25
+ };
26
+ run(): Promise<any>;
27
+ }
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const base_1 = tslib_1.__importDefault(require("../../base"));
5
+ const retrieve_1 = tslib_1.__importDefault(require("./retrieve"));
6
+ const list_1 = tslib_1.__importDefault(require("./list"));
7
+ class ProvisioningGet extends base_1.default {
8
+ async run() {
9
+ const { args } = await this.parse(ProvisioningGet);
10
+ const { id, singleton } = this.checkResourceId(args.resource, args.id, false);
11
+ const command = (id || singleton) ? retrieve_1.default : list_1.default;
12
+ const result = await command.run(this.argv, this.config);
13
+ return result;
14
+ }
15
+ }
16
+ ProvisioningGet.description = 'retrieve a resource or list a set of resources';
17
+ ProvisioningGet.aliases = ['prov:get', 'pg', 'pget'];
18
+ ProvisioningGet.examples = [
19
+ '$ commercelayer provisioning:get roles',
20
+ '$ commercelayer prov:get roles',
21
+ '$ clayer prov:get roles/<roleId>',
22
+ '$ cl prov:get roles <roleId>',
23
+ ];
24
+ ProvisioningGet.strict = false;
25
+ ProvisioningGet.flags = {
26
+ ...list_1.default.flags,
27
+ };
28
+ ProvisioningGet.args = {
29
+ ...retrieve_1.default.args,
30
+ };
31
+ exports.default = ProvisioningGet;
@@ -0,0 +1,22 @@
1
+ import Command from '../../base';
2
+ export default class ProvisioningList extends Command {
3
+ static description: string;
4
+ static aliases: string[];
5
+ static examples: string[];
6
+ static flags: {
7
+ where: import("@oclif/core/lib/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
8
+ page: import("@oclif/core/lib/interfaces").OptionFlag<number | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
9
+ pageSize: import("@oclif/core/lib/interfaces").OptionFlag<number | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
10
+ sort: import("@oclif/core/lib/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
11
+ extract: import("@oclif/core/lib/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
12
+ 'force-include': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
13
+ include: import("@oclif/core/lib/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
14
+ fields: import("@oclif/core/lib/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
15
+ json: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
16
+ unformatted: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
17
+ raw: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
18
+ headers: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
19
+ 'headers-only': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
20
+ };
21
+ run(): Promise<any>;
22
+ }
@@ -0,0 +1,137 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const base_1 = tslib_1.__importStar(require("../../base"));
5
+ // import { addRequestReader, isRequestInterrupted } from '../../lang'
6
+ // import { mergeCommandParams } from '../../commands'
7
+ const cli_core_1 = require("@commercelayer/cli-core");
8
+ const OPERATION = 'list';
9
+ class ProvisioningList extends base_1.default {
10
+ async run() {
11
+ const { args, flags } = await this.parse(ProvisioningList);
12
+ const resource = this.checkResource(args.resource);
13
+ // const loadParams = flags[FLAG_LOAD_PARAMS]
14
+ // const saveCmd = flags[FLAG_SAVE_PARAMS]
15
+ // if (saveCmd) this.checkAlias(saveCmd, resource.api, OPERATION, this.config)
16
+ const showHeaders = flags.headers || flags['headers-only'];
17
+ // Include flags
18
+ const include = this.includeFlag(flags.include, undefined, flags['force-include']);
19
+ // Fields flags
20
+ const fields = this.fieldsFlag(flags.fields, resource.api);
21
+ // Where flags
22
+ const wheres = this.whereFlag(flags.where);
23
+ // Sort flags
24
+ const sort = this.sortFlag(flags.sort);
25
+ const page = flags.page;
26
+ const perPage = flags.pageSize;
27
+ const cl = this.initCommerceLayer(flags);
28
+ const rawReader = flags.raw ? cl.addRawResponseReader({ headers: showHeaders }) : undefined;
29
+ // const reqReader = flags.doc ? addRequestReader(cl) : undefined
30
+ const params = {};
31
+ try {
32
+ const resSdk = cl[resource.api];
33
+ this.checkOperation(resSdk, OPERATION);
34
+ if (include && (include.length > 0))
35
+ params.include = include;
36
+ if (fields && (Object.keys(fields).length > 0))
37
+ params.fields = fields;
38
+ if (wheres && (Object.keys(wheres).length > 0))
39
+ params.filters = wheres;
40
+ if (sort && (Object.keys(sort).length > 0))
41
+ params.sort = sort;
42
+ if (perPage && (perPage > 0))
43
+ params.pageSize = perPage;
44
+ if (page && (page > 0))
45
+ params.pageNumber = page;
46
+ // Load saved command arguments
47
+ // if (loadParams) {
48
+ // const savedParams = this.loadParams(loadParams, resource.api, OPERATION)
49
+ // if (savedParams) mergeCommandParams(params, savedParams)
50
+ // }
51
+ // if (!flags.doc) cliux.action.start(`Fetching ${resource.api.replace(/_/g, ' ')}`)
52
+ const res = await resSdk.list(params);
53
+ base_1.cliux.action.stop();
54
+ const out = (flags.raw && rawReader) ? rawReader.rawResponse : [...res];
55
+ const meta = res.meta;
56
+ if (res && (res.length > 0)) {
57
+ if (flags.extract && Array.isArray(out)) {
58
+ const ext = this.extractFlag(flags.extract);
59
+ out.forEach(o => { this.extractObjectFields(ext, o); });
60
+ }
61
+ this.printHeaders(rawReader?.headers, flags);
62
+ this.printOutput(out, flags);
63
+ if (!flags['headers-only'])
64
+ this.log(`\nRecords: ${cli_core_1.clColor.blueBright(res.length)} of ${meta.recordCount} | Page: ${cli_core_1.clColor.blueBright(String(flags.page || 1))} of ${meta.pageCount}\n`);
65
+ // Save command output
66
+ // if (flags.save || flags['save-path']) this.saveOutput(out, flags)
67
+ }
68
+ else
69
+ this.log(cli_core_1.clColor.italic('\nNo records found\n'));
70
+ // Save command arguments
71
+ // if (saveCmd) this.saveParams(saveCmd, { type: resource.api }, OPERATION, params)
72
+ return out;
73
+ }
74
+ catch (error) {
75
+ /*
76
+ if (isRequestInterrupted(error) && reqReader) {
77
+ await this.showLiveDocumentation(reqReader.request, params, flags)
78
+ cl.removeInterceptor('request', reqReader.id)
79
+ } else */ this.printError(error, flags, args);
80
+ }
81
+ }
82
+ }
83
+ ProvisioningList.description = 'fetch a collection of resources';
84
+ ProvisioningList.aliases = ['pl', 'prov:list', 'plist', 'pls'];
85
+ ProvisioningList.examples = [
86
+ '$ commercelayer provisioning:list roles -f id,name -i organization -s updated_at',
87
+ '$ cl prov:list roles -i organization -f name -f organizations/name -w organization_name_eq="ORG NAME"',
88
+ '$ cl prov:list roles -p 5 -n 10 -s -created_at --raw',
89
+ ];
90
+ ProvisioningList.flags = {
91
+ ...base_1.default.flags,
92
+ where: base_1.Flags.string({
93
+ char: 'w',
94
+ multiple: true,
95
+ description: 'comma separated list of query filters',
96
+ }),
97
+ page: base_1.Flags.integer({
98
+ char: 'p',
99
+ description: 'page number',
100
+ }),
101
+ pageSize: base_1.Flags.integer({
102
+ char: 'n',
103
+ description: 'number of elements per page',
104
+ }),
105
+ sort: base_1.Flags.string({
106
+ char: 's',
107
+ description: 'defines results ordering',
108
+ multiple: true,
109
+ }),
110
+ /*
111
+ save: Flags.string({
112
+ char: 'x',
113
+ description: 'save command output to file',
114
+ multiple: false,
115
+ exclusive: ['save-path'],
116
+ }),
117
+ 'save-path': Flags.string({
118
+ char: 'X',
119
+ description: 'save command output to file and create missing path directories',
120
+ multiple: false,
121
+ exclusive: ['save'],
122
+ }),
123
+ */
124
+ extract: base_1.Flags.string({
125
+ char: 'e',
126
+ description: 'extract subfields from object attributes',
127
+ multiple: true,
128
+ exclusive: ['raw'],
129
+ }),
130
+ 'force-include': base_1.Flags.boolean({
131
+ char: 'I',
132
+ description: 'force resources inclusion beyound the 3rd level',
133
+ dependsOn: ['include'],
134
+ hidden: true,
135
+ }),
136
+ };
137
+ exports.default = ProvisioningList;
@@ -0,0 +1,6 @@
1
+ import { Command } from '@oclif/core';
2
+ export default class Noc extends Command {
3
+ static hidden: boolean;
4
+ static flags: {};
5
+ run(): Promise<any>;
6
+ }
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const core_1 = require("@oclif/core");
4
+ class Noc extends core_1.Command {
5
+ async run() {
6
+ const output = '-= NoC =-';
7
+ this.log(output);
8
+ return output;
9
+ }
10
+ }
11
+ Noc.hidden = true;
12
+ Noc.flags = {};
13
+ exports.default = Noc;
@@ -0,0 +1,30 @@
1
+ import Command from '../../base';
2
+ export default class ResourcesRelationship extends Command {
3
+ static description: string;
4
+ static aliases: string[];
5
+ static hidden: boolean;
6
+ static examples: string[];
7
+ static flags: {
8
+ where: import("@oclif/core/lib/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
9
+ page: import("@oclif/core/lib/interfaces").OptionFlag<number | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
10
+ pageSize: import("@oclif/core/lib/interfaces").OptionFlag<number | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
11
+ sort: import("@oclif/core/lib/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
12
+ extract: import("@oclif/core/lib/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
13
+ 'force-include': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
14
+ include: import("@oclif/core/lib/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
15
+ fields: import("@oclif/core/lib/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
16
+ json: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
17
+ unformatted: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
18
+ raw: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
19
+ headers: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
20
+ 'headers-only': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
21
+ };
22
+ static args: {
23
+ id: import("@oclif/core/lib/interfaces/parser").Arg<string, Record<string, unknown>>;
24
+ relationship: import("@oclif/core/lib/interfaces/parser").Arg<string, Record<string, unknown>>;
25
+ resource: import("@oclif/core/lib/interfaces/parser").Arg<string, Record<string, unknown>>;
26
+ };
27
+ run(): Promise<any>;
28
+ private checkRelationship;
29
+ private isRelationship1N;
30
+ }
@@ -0,0 +1,114 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const base_1 = tslib_1.__importStar(require("../../base"));
5
+ // import { addRequestReader, isRequestInterrupted } from '../../lang'
6
+ // import { mergeCommandParams } from '../../commands'
7
+ const list_1 = tslib_1.__importDefault(require("./list"));
8
+ const cli_core_1 = require("@commercelayer/cli-core");
9
+ // const OPERATION = 'relationship'
10
+ class ResourcesRelationship extends base_1.default {
11
+ async run() {
12
+ const { args, flags } = await this.parse(ResourcesRelationship);
13
+ const { res: resName, id } = this.checkResourceId(args.resource, args.id);
14
+ const resource = this.checkResource(resName, { singular: true });
15
+ const relationship = args.relationship;
16
+ const multiRel = this.isRelationship1N(relationship);
17
+ const showHeaders = flags.headers || flags['headers-only'];
18
+ const cl = this.initCommerceLayer(flags);
19
+ const resSdk = cl[resource.api];
20
+ this.checkRelationship(resSdk, relationship);
21
+ // Load saved args
22
+ // const loadParams = flags[FLAG_LOAD_PARAMS]
23
+ // const saveCmd = flags[FLAG_SAVE_PARAMS]
24
+ // if (saveCmd) this.checkAlias(saveCmd, resource.api, OPERATION, this.config)
25
+ // Include flags
26
+ const include = this.includeFlag(flags.include);
27
+ // Fields flags
28
+ const fields = this.fieldsFlag(flags.fields, resource.api);
29
+ // Where flags
30
+ const wheres = this.whereFlag(flags.where);
31
+ // Sort flags
32
+ const sort = this.sortFlag(flags.sort);
33
+ const page = flags.page;
34
+ const perPage = flags.pageSize;
35
+ const rawReader = flags.raw ? cl.addRawResponseReader({ headers: showHeaders }) : undefined;
36
+ // const reqReader = flags.doc ? addRequestReader(cl) : undefined
37
+ const params = {};
38
+ try {
39
+ if (include && (include.length > 0))
40
+ params.include = include;
41
+ if (fields && (Object.keys(fields).length > 0))
42
+ params.fields = fields;
43
+ if (wheres && (Object.keys(wheres).length > 0))
44
+ params.filters = wheres;
45
+ if (sort && (Object.keys(sort).length > 0))
46
+ params.sort = sort;
47
+ if (perPage && (perPage > 0))
48
+ params.pageSize = perPage;
49
+ if (page && (page > 0))
50
+ params.pageNumber = page;
51
+ // Load saved command arguments
52
+ // if (loadParams) {
53
+ // const savedParams = this.loadParams(loadParams, resource.api, OPERATION)
54
+ // if (savedParams) mergeCommandParams(params, savedParams)
55
+ // }
56
+ // if (!flags.doc && multiRel) cliux.action.start(`Fetching ${resource.api.replace(/_/g, ' ')}.${relationship} for id ${id}`)
57
+ const res = await resSdk[relationship](id, params);
58
+ if (multiRel)
59
+ base_1.cliux.action.stop();
60
+ const out = (flags.raw && rawReader) ? rawReader.rawResponse : (multiRel ? [...res] : res);
61
+ if (out && flags.extract) {
62
+ const ext = this.extractFlag(flags.extract);
63
+ if (Array.isArray(out))
64
+ out.forEach(o => { this.extractObjectFields(ext, o); });
65
+ else
66
+ this.extractObjectFields(ext, out);
67
+ }
68
+ if (!out || (out.length === 0))
69
+ this.log(cli_core_1.clColor.italic(`\nRelationship ${cli_core_1.clColor.api.resource(`${resName}.${relationship}`)} is empty\n`));
70
+ else {
71
+ this.printHeaders(rawReader?.headers, flags);
72
+ this.printOutput(out, flags);
73
+ if (multiRel && !flags['headers-only'])
74
+ this.log(`\nRecords: ${cli_core_1.clColor.blueBright(out.length)} of ${res.meta.recordCount} | Page: ${cli_core_1.clColor.blueBright(String(flags.page || 1))} of ${res.meta.pageCount}\n`);
75
+ // Save command output
76
+ // if (flags.save || flags['save-path']) this.saveOutput(out, flags)
77
+ }
78
+ // Save command arguments
79
+ // if (saveCmd) this.saveParams(saveCmd, { type: resource.api, id }, OPERATION, params)
80
+ return out;
81
+ }
82
+ catch (error) {
83
+ /* if (isRequestInterrupted(error) && reqReader) {
84
+ await this.showLiveDocumentation(reqReader.request, params, flags)
85
+ cl.removeInterceptor('request', reqReader.id)
86
+ } else */ this.printError(error, flags, args);
87
+ }
88
+ }
89
+ checkRelationship(sdk, name) {
90
+ if (!sdk[name])
91
+ this.error(`Relationship not available for resource ${cli_core_1.clColor.api.resource(sdk.type())}: ${cli_core_1.clColor.msg.error(name)}`);
92
+ return true;
93
+ }
94
+ isRelationship1N(name) {
95
+ return (name === cli_core_1.clText.pluralize(name));
96
+ }
97
+ }
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
+ exports.default = ResourcesRelationship;
@@ -0,0 +1,11 @@
1
+ import { Command } from '@oclif/core';
2
+ export default class ProvisioningResources extends Command {
3
+ static description: string;
4
+ static aliases: string[];
5
+ static examples: string[];
6
+ static flags: {
7
+ help: import("@oclif/core/lib/interfaces").BooleanFlag<void>;
8
+ };
9
+ run(): Promise<any>;
10
+ catch(error: any): Promise<any>;
11
+ }
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const core_1 = require("@oclif/core");
4
+ const resources_1 = require("../../util/resources");
5
+ const cli_core_1 = require("@commercelayer/cli-core");
6
+ class ProvisioningResources extends core_1.Command {
7
+ async run() {
8
+ await this.parse(ProvisioningResources);
9
+ this.log(cli_core_1.clColor.style.title('\n-= Provisioning API available resources =-\n'));
10
+ const resourceArray = (0, resources_1.resourceList)('api').map(r => {
11
+ return { name: r, url: `${cli_core_1.clConfig.doc.provisioning_api_reference}/${r}` };
12
+ });
13
+ core_1.ux.Table.table(resourceArray, {
14
+ key: { header: 'NAME', minWidth: 35, get: row => cli_core_1.clColor.blueBright(row.name) },
15
+ description: { header: 'ONLINE DOCUMENTATION URL', get: row => row.url },
16
+ }, {
17
+ printLine: cli_core_1.clUtil.log,
18
+ });
19
+ this.log();
20
+ }
21
+ async catch(error) {
22
+ if ((error.code === 'EEXIT') && (error.message === 'EEXIT: 0'))
23
+ return;
24
+ return await super.catch(error);
25
+ }
26
+ }
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
+ exports.default = ProvisioningResources;