@commercelayer/cli-plugin-metrics 1.0.0 → 1.0.2

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 CHANGED
@@ -1 +1,210 @@
1
- # commercelayer-cli-plugin-links
1
+ # @commercelayer/cli-plugin-metrics
2
+
3
+ Commerce Layer CLI Metrics plugin
4
+
5
+ [![oclif](https://img.shields.io/badge/cli-oclif-brightgreen.svg)](https://oclif.io)
6
+ [![Version](https://img.shields.io/npm/v/@commercelayer/cli-plugin-metrics.svg)](https://npmjs.org/package/@commercelayer/cli-plugin-metrics)
7
+ [![Downloads/week](https://img.shields.io/npm/dw/@commercelayer/cli-plugin-metrics.svg)](https://npmjs.org/package/@commercelayer/cli-plugin-metrics)
8
+ [![License](https://img.shields.io/npm/l/@commercelayer/cli-plugin-metrics.svg)](https://github.com/@commercelayer/cli-plugin-metrics/blob/master/package.json)
9
+
10
+ <!-- toc -->
11
+
12
+ * [Usage](#usage)
13
+ * [Commands](#commands)
14
+ <!-- tocstop -->
15
+ ## Usage
16
+ <!-- usage -->
17
+
18
+ ```sh-session
19
+ commercelayer COMMAND
20
+
21
+ commercelayer [COMMAND] (--help | -h) for detailed information about plugin commands.
22
+ ```
23
+ <!-- usagestop -->
24
+ ## Commands
25
+ <!-- commands -->
26
+
27
+ * [`commercelayer metrics:breakdown RESOURCE`](#commercelayer-metricsbreakdown-resource)
28
+ * [`commercelayer metrics:date_breakdown RESOURCE`](#commercelayer-metricsdate_breakdown-resource)
29
+ * [`commercelayer metrics:fbt`](#commercelayer-metricsfbt)
30
+ * [`commercelayer metrics:search RESOURCE`](#commercelayer-metricssearch-resource)
31
+ * [`commercelayer metrics:stats RESOURCE`](#commercelayer-metricsstats-resource)
32
+
33
+ ### `commercelayer metrics:breakdown RESOURCE`
34
+
35
+ Perform a breakdown query on the Metrics API endpoint.
36
+
37
+ ```sh-session
38
+ USAGE
39
+ $ commercelayer metrics:breakdown RESOURCE -b <value> -f <value> -O
40
+ avg|cardinality|max|min|percentiles|stats|sum|value_count [-F <value>] [-B <value>] [-c <value>] [-s asc|desc] [-l
41
+ <value>]
42
+
43
+ FLAGS
44
+ -B, --breakdown=<value> the optional nested breakdown
45
+ -F, --filter=<value> the filter to apply to the query in JSON format (enclosed in single quotes)
46
+ -O, --operator=<option> (required) the computing operator
47
+ <options: avg|cardinality|max|min|percentiles|stats|sum|value_count>
48
+ -b, --by=<value> (required) the field you want the results of the query aggragated by
49
+ -c, --condition=<value> an additional constraint to fine-tune the set of records
50
+ -f, --field=<value> (required) the field you want the metrics or statistics computed on
51
+ -l, --limit=<value> the maximum number of records shown in the response
52
+ -s, --sort=<option> the way you want the results of the query to be sorted
53
+ <options: asc|desc>
54
+
55
+ DESCRIPTION
56
+ perform a breakdown query on the Metrics API endpoint
57
+
58
+ ALIASES
59
+ $ commercelayer metrics:break
60
+ $ commercelayer breakdown
61
+
62
+ EXAMPLES
63
+ $ commercelayer metrics:breakdown orders -b order.country_code -f order.id -O value_count -s desc -l 20
64
+
65
+ cl breakdown orders -b order.country_code -f order.id -O value_count -s desc -l 20 -B '{"by": "line_items.name","field": "line_items.id","operator": "value_count","sort": "desc","limit": 20}'
66
+
67
+ FLAG DESCRIPTIONS
68
+ -B, --breakdown=<value> the optional nested breakdown
69
+
70
+ a JSON object (enclosed in single quotes) containing the nested breakdown
71
+
72
+ -O, --operator=avg|cardinality|max|min|percentiles|stats|sum|value_count the computing operator
73
+
74
+ the list of valid operators depends on the value of the field key
75
+
76
+ -c, --condition=<value> an additional constraint to fine-tune the set of records
77
+
78
+ the condition is applied to the computed results of the query and it is available for operators that return single
79
+ numeric (float or integer) values.
80
+ ```
81
+
82
+ _See code: [src/commands/metrics/breakdown.ts](https://github.com/commercelayer/commercelayer-cli-plugin-metrics/blob/main/src/commands/metrics/breakdown.ts)_
83
+
84
+ ### `commercelayer metrics:date_breakdown RESOURCE`
85
+
86
+ Perform a date breakdown query on the Metrics API endpoint.
87
+
88
+ ```sh-session
89
+ USAGE
90
+ $ commercelayer metrics:date_breakdown RESOURCE -b <value> -f <value> -O
91
+ avg|cardinality|max|min|percentiles|stats|sum|value_count [-F <value>] [-B <value>] [-i hour|day|week|month|year]
92
+
93
+ FLAGS
94
+ -B, --breakdown=<value> the optional nested breakdown
95
+ -F, --filter=<value> the filter to apply to the query in JSON format (enclosed in single quotes)
96
+ -O, --operator=<option> (required) the computing operator
97
+ <options: avg|cardinality|max|min|percentiles|stats|sum|value_count>
98
+ -b, --by=<value> (required) the field you want the results of the query aggragated by
99
+ -f, --field=<value> (required) the field you want the metrics or statistics computed on
100
+ -i, --interval=<option> the time interval over which the metrics are computed
101
+ <options: hour|day|week|month|year>
102
+
103
+ DESCRIPTION
104
+ perform a date breakdown query on the Metrics API endpoint
105
+
106
+ ALIASES
107
+ $ commercelayer metrics:breakdate
108
+ $ commercelayer metrics:date
109
+ $ commercelayer breakdate
110
+ $ commercelayer date_breakdown
111
+
112
+ EXAMPLES
113
+ $ commercelayer metrics:date_breakdown orders -b order.placed_at -f order.total_amount_with_taxes -O stats -i month
114
+
115
+ FLAG DESCRIPTIONS
116
+ -B, --breakdown=<value> the optional nested breakdown
117
+
118
+ a JSON object (enclosed in single quotes) containing the nested breakdown
119
+
120
+ -O, --operator=avg|cardinality|max|min|percentiles|stats|sum|value_count the computing operator
121
+
122
+ the list of valid operators depends on the value of the field key
123
+ ```
124
+
125
+ _See code: [src/commands/metrics/date_breakdown.ts](https://github.com/commercelayer/commercelayer-cli-plugin-metrics/blob/main/src/commands/metrics/date_breakdown.ts)_
126
+
127
+ ### `commercelayer metrics:fbt`
128
+
129
+ Perform a Frequently Bought Together query on the Metrics API analysis endpoint.
130
+
131
+ ```sh-session
132
+ USAGE
133
+ $ commercelayer metrics:fbt [-F <value>] [-i <value>...]
134
+
135
+ FLAGS
136
+ -F, --filter=<value> the filter to apply to the query in JSON format (enclosed in single quotes)
137
+ -i, --in=<value>... a list of SKU or bundle IDs associated as line items to one or more orders
138
+
139
+ DESCRIPTION
140
+ perform a Frequently Bought Together query on the Metrics API analysis endpoint
141
+
142
+ ALIASES
143
+ $ commercelayer fbt
144
+
145
+ EXAMPLES
146
+ $ commercelayer metrics:fbt --in xYZkjABcde,yzXKjYzaCx
147
+ ```
148
+
149
+ _See code: [src/commands/metrics/fbt.ts](https://github.com/commercelayer/commercelayer-cli-plugin-metrics/blob/main/src/commands/metrics/fbt.ts)_
150
+
151
+ ### `commercelayer metrics:search RESOURCE`
152
+
153
+ Perform a search query on the Metrics API endpoint.
154
+
155
+ ```sh-session
156
+ USAGE
157
+ $ commercelayer metrics:search RESOURCE -f <value>... [-F <value>] [-l <value>] [-s asc|desc -b <value>] [-c
158
+ <value>]
159
+
160
+ FLAGS
161
+ -F, --filter=<value> the filter to apply to the query in JSON format (enclosed in single quotes)
162
+ -b, --sort_by=<value> the date field you want the results of the query sorted by
163
+ -c, --cursor=<value> the cursor pointing to a specific page in the paginated search results
164
+ -f, --fields=<value>... (required) comma-separated list of fields you want to be returned for each record in the
165
+ response
166
+ -l, --limit=<value> the maximum number of records shown in the response
167
+ -s, --sort=<option> the way you want the results of the query to be sorted
168
+ <options: asc|desc>
169
+
170
+ DESCRIPTION
171
+ perform a search query on the Metrics API endpoint
172
+
173
+ ALIASES
174
+ $ commercelayer search
175
+
176
+ EXAMPLES
177
+ commercelayewr metrics:search orders -l 5 -s asc -b order.placed_at -f order.id,order.number,order.placed_at,customer.email
178
+ ```
179
+
180
+ _See code: [src/commands/metrics/search.ts](https://github.com/commercelayer/commercelayer-cli-plugin-metrics/blob/main/src/commands/metrics/search.ts)_
181
+
182
+ ### `commercelayer metrics:stats RESOURCE`
183
+
184
+ Perform a stats query on the Metrics API endpoint.
185
+
186
+ ```sh-session
187
+ USAGE
188
+ $ commercelayer metrics:stats RESOURCE -f <value> -O avg|cardinality|max|min|percentiles|stats|sum|value_count
189
+ [-F <value>]
190
+
191
+ FLAGS
192
+ -F, --filter=<value> the filter to apply to the query in JSON format (enclosed in single quotes)
193
+ -O, --operator=<option> (required) the computing operator
194
+ <options: avg|cardinality|max|min|percentiles|stats|sum|value_count>
195
+ -f, --field=<value> (required) the field you want the metrics or statistics computed on
196
+
197
+ DESCRIPTION
198
+ perform a stats query on the Metrics API endpoint
199
+
200
+ ALIASES
201
+ $ commercelayer stats
202
+
203
+ EXAMPLES
204
+ $ commercelayer metrics:stats orders -f order.total_amount_with_taxes --op avg
205
+
206
+ cl stats orders -f order.total_amount_with_taxes -O stats
207
+ ```
208
+
209
+ _See code: [src/commands/metrics/stats.ts](https://github.com/commercelayer/commercelayer-cli-plugin-metrics/blob/main/src/commands/metrics/stats.ts)_
210
+ <!-- commandsstop -->
package/lib/base.d.ts CHANGED
@@ -15,7 +15,16 @@ export declare abstract class BaseCommand extends Command {
15
15
  protected multivalFlag(flag?: string[]): string[];
16
16
  protected printResponse(response: Response): Promise<void>;
17
17
  }
18
- export declare abstract class BaseResourceCommand extends BaseCommand {
18
+ export declare abstract class BaseFilterCommand extends BaseCommand {
19
+ static baseFlags: {
20
+ filter: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
21
+ organization: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
22
+ domain: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
23
+ accessToken: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
24
+ };
25
+ protected filterFlag(flag?: string): MetricsFilter | undefined;
26
+ }
27
+ export declare abstract class BaseResourceCommand extends BaseFilterCommand {
19
28
  static baseFlags: {
20
29
  filter: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
21
30
  organization: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
@@ -25,7 +34,6 @@ export declare abstract class BaseResourceCommand extends BaseCommand {
25
34
  static args: {
26
35
  resource: import("@oclif/core/lib/interfaces").Arg<string, Record<string, unknown>>;
27
36
  };
28
- protected filterFlag(flag?: string): MetricsFilter | undefined;
29
37
  }
30
38
  export declare abstract class BaseBreakdownCommand extends BaseResourceCommand {
31
39
  static baseFlags: {
package/lib/base.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Flags = exports.Args = exports.BaseBreakdownCommand = exports.BaseResourceCommand = exports.BaseCommand = void 0;
3
+ exports.Flags = exports.Args = exports.BaseBreakdownCommand = exports.BaseResourceCommand = exports.BaseFilterCommand = exports.BaseCommand = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const sdk_1 = tslib_1.__importStar(require("@commercelayer/sdk"));
6
6
  const core_1 = require("@oclif/core");
@@ -99,7 +99,7 @@ class BaseCommand extends core_1.Command {
99
99
  }
100
100
  }
101
101
  exports.BaseCommand = BaseCommand;
102
- class BaseResourceCommand extends BaseCommand {
102
+ class BaseFilterCommand extends BaseCommand {
103
103
  static baseFlags = {
104
104
  ...BaseCommand.baseFlags,
105
105
  filter: core_1.Flags.string({
@@ -107,9 +107,6 @@ class BaseResourceCommand extends BaseCommand {
107
107
  description: 'the filter to apply to the query in JSON format (enclosed in single quotes)'
108
108
  })
109
109
  };
110
- static args = {
111
- resource: core_1.Args.string({ resource: 'the resource name', options: common_1.resources, required: true })
112
- };
113
110
  filterFlag(flag) {
114
111
  let filter;
115
112
  if (flag) {
@@ -123,6 +120,15 @@ class BaseResourceCommand extends BaseCommand {
123
120
  return filter;
124
121
  }
125
122
  }
123
+ exports.BaseFilterCommand = BaseFilterCommand;
124
+ class BaseResourceCommand extends BaseFilterCommand {
125
+ static baseFlags = {
126
+ ...BaseFilterCommand.baseFlags
127
+ };
128
+ static args = {
129
+ resource: core_1.Args.string({ resource: 'the resource name', options: common_1.resources, required: true })
130
+ };
131
+ }
126
132
  exports.BaseResourceCommand = BaseResourceCommand;
127
133
  class BaseBreakdownCommand extends BaseResourceCommand {
128
134
  static baseFlags = {
@@ -1,11 +1,11 @@
1
- import { BaseCommand } from '../../base';
2
- export default class MetricsFbt extends BaseCommand {
1
+ import { BaseFilterCommand } from '../../base';
2
+ export default class MetricsFbt extends BaseFilterCommand {
3
3
  static operation: string;
4
4
  static aliases: string[];
5
5
  static description: string;
6
6
  static examples: string[];
7
7
  static flags: {
8
- in: import("@oclif/core/lib/interfaces").OptionFlag<string[], import("@oclif/core/lib/interfaces").CustomOptions>;
8
+ in: import("@oclif/core/lib/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
9
9
  };
10
10
  run(): Promise<void>;
11
11
  }
@@ -6,7 +6,7 @@ const base_1 = require("../../base");
6
6
  const request_1 = require("../../request");
7
7
  const cli_core_1 = require("@commercelayer/cli-core");
8
8
  const cliux = tslib_1.__importStar(require("@commercelayer/cli-ux"));
9
- class MetricsFbt extends base_1.BaseCommand {
9
+ class MetricsFbt extends base_1.BaseFilterCommand {
10
10
  static operation = 'fbt';
11
11
  static aliases = [MetricsFbt.operation];
12
12
  static description = 'perform a Frequently Bought Together query on the Metrics API analysis endpoint';
@@ -17,23 +17,28 @@ class MetricsFbt extends base_1.BaseCommand {
17
17
  in: core_1.Flags.string({
18
18
  char: 'i',
19
19
  description: 'a list of SKU or bundle IDs associated as line items to one or more orders',
20
- required: true,
21
- multiple: true
20
+ required: false,
21
+ multiple: true,
22
+ relationships: [
23
+ { type: 'some', flags: ['in', 'filter'] }
24
+ ],
22
25
  })
23
26
  };
24
27
  async run() {
25
28
  const { flags } = await this.parse(MetricsFbt);
26
29
  this.checkAcessTokenData(flags.accessToken, flags);
27
30
  const ids = this.multivalFlag(flags.in);
28
- const query = {
31
+ const filterObject = this.filterFlag(flags.filter);
32
+ const query = (ids.length > 0) ? {
29
33
  filter: {
34
+ ...filterObject,
30
35
  line_items: {
31
36
  item_ids: {
32
37
  in: ids
33
38
  }
34
39
  }
35
40
  }
36
- };
41
+ } : {};
37
42
  const response = await (0, request_1.metricsRequest)(MetricsFbt.operation, query, undefined, flags);
38
43
  if (response.ok) {
39
44
  cliux.action.stop(cli_core_1.clColor.msg.success('Done'));
package/lib/common.d.ts CHANGED
@@ -101,7 +101,7 @@ export type MetricsFilterFbt = {
101
101
  };
102
102
  };
103
103
  export type MetricsQueryFbt = {
104
- filter: MetricsFilterFbt;
104
+ filter?: MetricsFilterFbt;
105
105
  };
106
106
  export type MetricsQuery = (({
107
107
  search: MetricsQuerySearch;
@@ -365,11 +365,28 @@
365
365
  "multiple": false,
366
366
  "type": "option"
367
367
  },
368
+ "filter": {
369
+ "char": "F",
370
+ "description": "the filter to apply to the query in JSON format (enclosed in single quotes)",
371
+ "name": "filter",
372
+ "hasDynamicHelp": false,
373
+ "multiple": false,
374
+ "type": "option"
375
+ },
368
376
  "in": {
369
377
  "char": "i",
370
378
  "description": "a list of SKU or bundle IDs associated as line items to one or more orders",
371
379
  "name": "in",
372
- "required": true,
380
+ "relationships": [
381
+ {
382
+ "type": "some",
383
+ "flags": [
384
+ "in",
385
+ "filter"
386
+ ]
387
+ }
388
+ ],
389
+ "required": false,
373
390
  "hasDynamicHelp": false,
374
391
  "multiple": true,
375
392
  "type": "option"
@@ -670,5 +687,5 @@
670
687
  ]
671
688
  }
672
689
  },
673
- "version": "1.0.0"
690
+ "version": "1.0.2"
674
691
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@commercelayer/cli-plugin-metrics",
3
3
  "description": "Commerce Layer CLI metrics plugin",
4
- "version": "1.0.0",
4
+ "version": "1.0.2",
5
5
  "author": "Pierluigi Viti <pierluigi@commercelayer.io>",
6
6
  "bugs": "https://github.com/commercelayer/commercelayer-cli-plugin-metrics/issues",
7
7
  "engines": {
@@ -62,22 +62,21 @@
62
62
  "@semantic-release/changelog": "^6.0.3",
63
63
  "@semantic-release/git": "^10.0.1",
64
64
  "@types/chai": "^4.3.20",
65
- "@types/lodash.isempty": "^4.4.9",
66
65
  "@types/mocha": "^10.0.10",
67
- "@types/node": "^22.15.18",
66
+ "@types/node": "^22.15.24",
68
67
  "chai": "^4.5.0",
69
68
  "eslint": "^8.57.1",
70
69
  "mocha": "^10.8.2",
71
70
  "nyc": "^15.1.0",
72
71
  "oclif": "^4.17.46",
73
- "semantic-release": "^24.2.3",
72
+ "semantic-release": "^24.2.5",
74
73
  "tsx": "^4.19.4",
75
74
  "typescript": "5.5.2"
76
75
  },
77
76
  "dependencies": {
78
77
  "@commercelayer/cli-core": "^5.9.0",
79
78
  "@commercelayer/cli-ux": "^1.0.7",
80
- "@commercelayer/sdk": "^6.41.0",
79
+ "@commercelayer/sdk": "^6.42.0",
81
80
  "@oclif/core": "^3.27.0",
82
81
  "tslib": "^2.8.1"
83
82
  },