@commercelayer/cli-plugin-triggers 4.2.0 → 4.3.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.
package/README.md CHANGED
@@ -102,6 +102,7 @@ $ commercelayer plugins:install triggers
102
102
  * [`commercelayer order:commit_invoice ID`](#commercelayer-ordercommit_invoice-id)
103
103
  * [`commercelayer order:create_subscriptions ID`](#commercelayer-ordercreate_subscriptions-id)
104
104
  * [`commercelayer order:customer_payment_source_id ID`](#commercelayer-ordercustomer_payment_source_id-id)
105
+ * [`commercelayer order:fulfill ID`](#commercelayer-orderfulfill-id)
105
106
  * [`commercelayer order:nullify_payment_source ID`](#commercelayer-ordernullify_payment_source-id)
106
107
  * [`commercelayer order:pending ID`](#commercelayer-orderpending-id)
107
108
  * [`commercelayer order:place ID`](#commercelayer-orderplace-id)
@@ -149,6 +150,7 @@ $ commercelayer plugins:install triggers
149
150
  * [`commercelayer satispay_payment:refresh ID`](#commercelayer-satispay_paymentrefresh-id)
150
151
  * [`commercelayer shipment ID`](#commercelayer-shipment-id)
151
152
  * [`commercelayer shipment:decrement_stock ID`](#commercelayer-shipmentdecrement_stock-id)
153
+ * [`commercelayer shipment:deliver ID`](#commercelayer-shipmentdeliver-id)
152
154
  * [`commercelayer shipment:get_rates ID`](#commercelayer-shipmentget_rates-id)
153
155
  * [`commercelayer shipment:on_hold ID`](#commercelayer-shipmenton_hold-id)
154
156
  * [`commercelayer shipment:packing ID`](#commercelayer-shipmentpacking-id)
@@ -1785,6 +1787,28 @@ DESCRIPTION
1785
1787
 
1786
1788
  _See code: [src/commands/order/customer_payment_source_id.ts](https://github.com/commercelayer/commercelayer-cli-plugin-triggers/blob/main/src/commands/order/customer_payment_source_id.ts)_
1787
1789
 
1790
+ ### `commercelayer order:fulfill ID`
1791
+
1792
+ Send this attribute if you want to mark as fulfilled a shipped/delivered order.
1793
+
1794
+ ```sh-session
1795
+ USAGE
1796
+ $ commercelayer order:fulfill ID [-u [-j -p]]
1797
+
1798
+ ARGUMENTS
1799
+ ID the unique id of the resource
1800
+
1801
+ FLAGS
1802
+ -j, --json print result in JSON format
1803
+ -p, --print print out the modified resource
1804
+ -u, --unformatted print JSON output without indentation
1805
+
1806
+ DESCRIPTION
1807
+ Send this attribute if you want to mark as fulfilled a shipped/delivered order.
1808
+ ```
1809
+
1810
+ _See code: [src/commands/order/fulfill.ts](https://github.com/commercelayer/commercelayer-cli-plugin-triggers/blob/main/src/commands/order/fulfill.ts)_
1811
+
1788
1812
  ### `commercelayer order:nullify_payment_source ID`
1789
1813
 
1790
1814
  Send this attribute if you want to nullify the payment source for this order.
@@ -2829,6 +2853,28 @@ DESCRIPTION
2829
2853
 
2830
2854
  _See code: [src/commands/shipment/decrement_stock.ts](https://github.com/commercelayer/commercelayer-cli-plugin-triggers/blob/main/src/commands/shipment/decrement_stock.ts)_
2831
2855
 
2856
+ ### `commercelayer shipment:deliver ID`
2857
+
2858
+ Send this attribute if you want to mark this shipment as delivered.
2859
+
2860
+ ```sh-session
2861
+ USAGE
2862
+ $ commercelayer shipment:deliver ID [-u [-j -p]]
2863
+
2864
+ ARGUMENTS
2865
+ ID the unique id of the resource
2866
+
2867
+ FLAGS
2868
+ -j, --json print result in JSON format
2869
+ -p, --print print out the modified resource
2870
+ -u, --unformatted print JSON output without indentation
2871
+
2872
+ DESCRIPTION
2873
+ Send this attribute if you want to mark this shipment as delivered.
2874
+ ```
2875
+
2876
+ _See code: [src/commands/shipment/deliver.ts](https://github.com/commercelayer/commercelayer-cli-plugin-triggers/blob/main/src/commands/shipment/deliver.ts)_
2877
+
2832
2878
  ### `commercelayer shipment:get_rates ID`
2833
2879
 
2834
2880
  Send this attribute if you want get the shipping rates from the associated carrier accounts.
package/lib/base.js CHANGED
@@ -88,7 +88,7 @@ class default_1 extends core_1.Command {
88
88
  this.log(cli_core_1.clOutput.formatOutput(res, flags));
89
89
  }
90
90
  successMessage(resource, action, id) {
91
- this.log(`\nAction ${cli_core_1.clColor.api.trigger(action)} executed without errors on ${resource.replace(/_/g, ' ')} ${cli_core_1.clColor.api.id(id)}\n`);
91
+ this.log(`\nAction ${cli_core_1.clColor.api.trigger(action)} executed without errors on ${cli_core_1.clApi.humanizeResource(resource)} ${cli_core_1.clColor.api.id(id)}\n`);
92
92
  }
93
93
  async executeAction(resourceType, id, action, flags, fields) {
94
94
  return await (0, exec_1.default)(resourceType, id, action, flags, fields, this.config);
@@ -0,0 +1,9 @@
1
+ import Command from '../../base';
2
+ export default class OrderFulfill extends Command {
3
+ static description: string;
4
+ static flags: {};
5
+ static args: {
6
+ id: import("@oclif/core/lib/interfaces").Arg<string, Record<string, unknown>>;
7
+ };
8
+ run(): Promise<any>;
9
+ }
@@ -0,0 +1,22 @@
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 orders_1 = require("../../triggers/orders");
6
+ const TRIGGER = 'fulfill';
7
+ class OrderFulfill extends base_1.default {
8
+ static description = orders_1.triggers[TRIGGER].description;
9
+ static flags = {};
10
+ static args = {
11
+ ...base_1.default.args,
12
+ };
13
+ async run() {
14
+ const { args, flags } = await this.parse(OrderFulfill);
15
+ const res = await this.executeAction('orders', args.id, TRIGGER, flags);
16
+ if (flags.print)
17
+ this.printOutput(res, flags);
18
+ this.successMessage('order', TRIGGER, res.id);
19
+ return res;
20
+ }
21
+ }
22
+ exports.default = OrderFulfill;
@@ -0,0 +1,9 @@
1
+ import Command from '../../base';
2
+ export default class ShipmentDeliver extends Command {
3
+ static description: string;
4
+ static flags: {};
5
+ static args: {
6
+ id: import("@oclif/core/lib/interfaces").Arg<string, Record<string, unknown>>;
7
+ };
8
+ run(): Promise<any>;
9
+ }
@@ -0,0 +1,22 @@
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 shipments_1 = require("../../triggers/shipments");
6
+ const TRIGGER = 'deliver';
7
+ class ShipmentDeliver extends base_1.default {
8
+ static description = shipments_1.triggers[TRIGGER].description;
9
+ static flags = {};
10
+ static args = {
11
+ ...base_1.default.args,
12
+ };
13
+ async run() {
14
+ const { args, flags } = await this.parse(ShipmentDeliver);
15
+ const res = await this.executeAction('shipments', args.id, TRIGGER, flags);
16
+ if (flags.print)
17
+ this.printOutput(res, flags);
18
+ this.successMessage('shipment', TRIGGER, res.id);
19
+ return res;
20
+ }
21
+ }
22
+ exports.default = ShipmentDeliver;
package/lib/exec.js CHANGED
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  const cli_core_1 = require("@commercelayer/cli-core");
5
5
  const sdk_1 = tslib_1.__importStar(require("@commercelayer/sdk"));
6
+ const errors_1 = require("@oclif/core/lib/errors");
6
7
  const commercelayerInit = (flags, config) => {
7
8
  const organization = flags.organization;
8
9
  const domain = flags.domain;
@@ -17,15 +18,18 @@ const commercelayerInit = (flags, config) => {
17
18
  };
18
19
  const exec = async (resourceType, id, action, flags, fields, config) => {
19
20
  const cl = commercelayerInit(flags, config);
20
- const res = { id };
21
- const trigger = `_${action}`;
22
- res[trigger] = flags.value || true;
21
+ const resSdk = cl[resourceType];
22
+ await cl.orders.retrieve(id).catch(err => {
23
+ const resource = cli_core_1.clApi.humanizeResource(cli_core_1.clText.singularize(resourceType));
24
+ if (cl.isApiError(err) && (err.status === 404))
25
+ throw new errors_1.CLIError(`Invalid ${resource} or ${resource} not found: ${cli_core_1.clColor.msg.error(id)}`);
26
+ });
27
+ const res = { id, [`_${action}`]: flags.value || true };
23
28
  const params = {};
24
29
  if (fields && (fields.length > 0)) {
25
30
  params.fields = {};
26
31
  params.fields[resourceType] = fields;
27
32
  }
28
- const resSdk = cl[resourceType];
29
33
  const result = resSdk.update(res, params).catch((error) => {
30
34
  if (sdk_1.CommerceLayerStatic.isApiError(error))
31
35
  error.code = `RES_${resourceType}_${id}`;
@@ -1,3 +1,3 @@
1
1
  import type { Trigger } from '../common';
2
2
  export declare const triggers: Record<string, Trigger>;
3
- export type ActionType = 'archive' | 'unarchive' | 'pending' | 'place' | 'cancel' | 'approve' | 'approve_and_capture' | 'authorize' | 'authorization_amount_cents' | 'capture' | 'refund' | 'update_taxes' | 'nullify_payment_source' | 'billing_address_clone_id' | 'shipping_address_clone_id' | 'customer_payment_source_id' | 'shipping_address_same_as_billing' | 'billing_address_same_as_shipping' | 'commit_invoice' | 'refund_invoice' | 'save_payment_source_to_customer_wallet' | 'save_shipping_address_to_customer_address_book' | 'save_billing_address_to_customer_address_book' | 'refresh' | 'validate' | 'create_subscriptions' | 'start_editing' | 'stop_editing' | 'reset_circuit';
3
+ export type ActionType = 'archive' | 'unarchive' | 'pending' | 'place' | 'cancel' | 'approve' | 'approve_and_capture' | 'authorize' | 'authorization_amount_cents' | 'capture' | 'refund' | 'fulfill' | 'update_taxes' | 'nullify_payment_source' | 'billing_address_clone_id' | 'shipping_address_clone_id' | 'customer_payment_source_id' | 'shipping_address_same_as_billing' | 'billing_address_same_as_shipping' | 'commit_invoice' | 'refund_invoice' | 'save_payment_source_to_customer_wallet' | 'save_shipping_address_to_customer_address_book' | 'save_billing_address_to_customer_address_book' | 'refresh' | 'validate' | 'create_subscriptions' | 'start_editing' | 'stop_editing' | 'reset_circuit';
@@ -57,6 +57,11 @@ exports.triggers = {
57
57
  trigger: '_refund',
58
58
  description: 'Send this attribute if you want to refund a captured order.',
59
59
  },
60
+ fulfill: {
61
+ action: 'fulfill',
62
+ trigger: '_fulfill',
63
+ description: 'Send this attribute if you want to mark as fulfilled a shipped/delivered order.',
64
+ },
60
65
  update_taxes: {
61
66
  action: 'update_taxes',
62
67
  trigger: '_update_taxes',
@@ -1,3 +1,3 @@
1
1
  import type { Trigger } from '../common';
2
2
  export declare const triggers: Record<string, Trigger>;
3
- export type ActionType = 'upcoming' | 'on_hold' | 'picking' | 'packing' | 'ready_to_ship' | 'ship' | 'reserve_stock' | 'release_stock' | 'decrement_stock' | 'get_rates' | 'purchase';
3
+ export type ActionType = 'upcoming' | 'on_hold' | 'picking' | 'packing' | 'ready_to_ship' | 'ship' | 'deliver' | 'reserve_stock' | 'release_stock' | 'decrement_stock' | 'get_rates' | 'purchase';
@@ -32,6 +32,11 @@ exports.triggers = {
32
32
  trigger: '_ship',
33
33
  description: 'Send this attribute if you want to mark this shipment as shipped.',
34
34
  },
35
+ deliver: {
36
+ action: 'deliver',
37
+ trigger: '_deliver',
38
+ description: 'Send this attribute if you want to mark this shipment as delivered.',
39
+ },
35
40
  reserve_stock: {
36
41
  action: 'reserve_stock',
37
42
  trigger: '_reserve_stock',
@@ -6286,6 +6286,94 @@
6286
6286
  "customer_payment_source_id.js"
6287
6287
  ]
6288
6288
  },
6289
+ "order:fulfill": {
6290
+ "aliases": [],
6291
+ "args": {
6292
+ "id": {
6293
+ "description": "the unique id of the resource",
6294
+ "name": "id",
6295
+ "required": true
6296
+ }
6297
+ },
6298
+ "description": "Send this attribute if you want to mark as fulfilled a shipped/delivered order.",
6299
+ "flags": {
6300
+ "organization": {
6301
+ "char": "o",
6302
+ "description": "the slug of your organization",
6303
+ "env": "CL_CLI_ORGANIZATION",
6304
+ "hidden": true,
6305
+ "name": "organization",
6306
+ "required": true,
6307
+ "hasDynamicHelp": false,
6308
+ "multiple": false,
6309
+ "type": "option"
6310
+ },
6311
+ "domain": {
6312
+ "char": "d",
6313
+ "dependsOn": [
6314
+ "organization"
6315
+ ],
6316
+ "env": "CL_CLI_DOMAIN",
6317
+ "hidden": true,
6318
+ "name": "domain",
6319
+ "required": false,
6320
+ "hasDynamicHelp": false,
6321
+ "multiple": false,
6322
+ "type": "option"
6323
+ },
6324
+ "accessToken": {
6325
+ "env": "CL_CLI_ACCESS_TOKEN",
6326
+ "hidden": true,
6327
+ "name": "accessToken",
6328
+ "required": true,
6329
+ "hasDynamicHelp": false,
6330
+ "multiple": false,
6331
+ "type": "option"
6332
+ },
6333
+ "print": {
6334
+ "char": "p",
6335
+ "description": "print out the modified resource",
6336
+ "name": "print",
6337
+ "allowNo": false,
6338
+ "type": "boolean"
6339
+ },
6340
+ "json": {
6341
+ "char": "j",
6342
+ "dependsOn": [
6343
+ "print"
6344
+ ],
6345
+ "description": "print result in JSON format",
6346
+ "name": "json",
6347
+ "allowNo": false,
6348
+ "type": "boolean"
6349
+ },
6350
+ "unformatted": {
6351
+ "char": "u",
6352
+ "dependsOn": [
6353
+ "json"
6354
+ ],
6355
+ "description": "print JSON output without indentation",
6356
+ "name": "unformatted",
6357
+ "allowNo": false,
6358
+ "type": "boolean"
6359
+ }
6360
+ },
6361
+ "hasDynamicHelp": false,
6362
+ "hiddenAliases": [],
6363
+ "id": "order:fulfill",
6364
+ "pluginAlias": "@commercelayer/cli-plugin-triggers",
6365
+ "pluginName": "@commercelayer/cli-plugin-triggers",
6366
+ "pluginType": "core",
6367
+ "strict": true,
6368
+ "enableJsonFlag": false,
6369
+ "isESM": false,
6370
+ "relativePath": [
6371
+ "lib",
6372
+ "commands",
6373
+ "order",
6374
+ "fulfill.js"
6375
+ ]
6376
+ },
6289
6377
  "order": {
6290
6378
  "aliases": [],
6291
6379
  "args": {
@@ -10431,6 +10519,94 @@
10431
10519
  "decrement_stock.js"
10432
10520
  ]
10433
10521
  },
10522
+ "shipment:deliver": {
10523
+ "aliases": [],
10524
+ "args": {
10525
+ "id": {
10526
+ "description": "the unique id of the resource",
10527
+ "name": "id",
10528
+ "required": true
10529
+ }
10530
+ },
10531
+ "description": "Send this attribute if you want to mark this shipment as delivered.",
10532
+ "flags": {
10533
+ "organization": {
10534
+ "char": "o",
10535
+ "description": "the slug of your organization",
10536
+ "env": "CL_CLI_ORGANIZATION",
10537
+ "hidden": true,
10538
+ "name": "organization",
10539
+ "required": true,
10540
+ "hasDynamicHelp": false,
10541
+ "multiple": false,
10542
+ "type": "option"
10543
+ },
10544
+ "domain": {
10545
+ "char": "d",
10546
+ "dependsOn": [
10547
+ "organization"
10548
+ ],
10549
+ "env": "CL_CLI_DOMAIN",
10550
+ "hidden": true,
10551
+ "name": "domain",
10552
+ "required": false,
10553
+ "hasDynamicHelp": false,
10554
+ "multiple": false,
10555
+ "type": "option"
10556
+ },
10557
+ "accessToken": {
10558
+ "env": "CL_CLI_ACCESS_TOKEN",
10559
+ "hidden": true,
10560
+ "name": "accessToken",
10561
+ "required": true,
10562
+ "hasDynamicHelp": false,
10563
+ "multiple": false,
10564
+ "type": "option"
10565
+ },
10566
+ "print": {
10567
+ "char": "p",
10568
+ "description": "print out the modified resource",
10569
+ "name": "print",
10570
+ "allowNo": false,
10571
+ "type": "boolean"
10572
+ },
10573
+ "json": {
10574
+ "char": "j",
10575
+ "dependsOn": [
10576
+ "print"
10577
+ ],
10578
+ "description": "print result in JSON format",
10579
+ "name": "json",
10580
+ "allowNo": false,
10581
+ "type": "boolean"
10582
+ },
10583
+ "unformatted": {
10584
+ "char": "u",
10585
+ "dependsOn": [
10586
+ "json"
10587
+ ],
10588
+ "description": "print JSON output without indentation",
10589
+ "name": "unformatted",
10590
+ "allowNo": false,
10591
+ "type": "boolean"
10592
+ }
10593
+ },
10594
+ "hasDynamicHelp": false,
10595
+ "hiddenAliases": [],
10596
+ "id": "shipment:deliver",
10597
+ "pluginAlias": "@commercelayer/cli-plugin-triggers",
10598
+ "pluginName": "@commercelayer/cli-plugin-triggers",
10599
+ "pluginType": "core",
10600
+ "strict": true,
10601
+ "enableJsonFlag": false,
10602
+ "isESM": false,
10603
+ "relativePath": [
10604
+ "lib",
10605
+ "commands",
10606
+ "shipment",
10607
+ "deliver.js"
10608
+ ]
10609
+ },
10434
10610
  "shipment:get_rates": {
10435
10611
  "aliases": [],
10436
10612
  "args": {
@@ -13688,5 +13864,5 @@
13688
13864
  ]
13689
13865
  }
13690
13866
  },
13691
- "version": "4.2.0"
13867
+ "version": "4.3.0"
13692
13868
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@commercelayer/cli-plugin-triggers",
3
3
  "description": "Commerce Layer CLI Triggers plugin",
4
- "version": "4.2.0",
4
+ "version": "4.3.0",
5
5
  "author": "Pierluigi Viti <pierluigi@commercelayer.io>",
6
6
  "homepage": "https://github.com/commercelayer/commercelayer-cli-plugin-triggers",
7
7
  "repository": "commercelayer/commercelayer-cli-plugin-triggers",
@@ -64,21 +64,21 @@
64
64
  "@types/inquirer": "^8.2.10",
65
65
  "@types/lodash.snakecase": "^4.1.9",
66
66
  "@types/mocha": "^10.0.6",
67
- "@types/node": "^20.12.12",
67
+ "@types/node": "^20.12.13",
68
68
  "chai": "^4.4.1",
69
69
  "eslint": "^8.57.0",
70
70
  "inflector-js": "^1.0.1",
71
71
  "lodash.snakecase": "^4.1.1",
72
72
  "mocha": "^10.4.0",
73
73
  "nyc": "^15.1.0",
74
- "oclif": "^4.10.15",
74
+ "oclif": "^4.11.3",
75
75
  "semantic-release": "^22.0.12",
76
- "tsx": "^4.10.5",
76
+ "tsx": "^4.11.0",
77
77
  "typescript": "5.3.2"
78
78
  },
79
79
  "dependencies": {
80
- "@commercelayer/cli-core": "^5.0.2",
81
- "@commercelayer/sdk": "^6.2.0",
80
+ "@commercelayer/cli-core": "^5.0.4",
81
+ "@commercelayer/sdk": "^6.4.0",
82
82
  "@oclif/core": "^3.26.6",
83
83
  "inquirer": "^8.2.6",
84
84
  "tslib": "^2.6.2"