@digicatapult/sqnc-process-management 2.2.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 (32) hide show
  1. package/LICENSE +190 -0
  2. package/README.md +213 -0
  3. package/build/package.json +64 -0
  4. package/build/src/index.d.ts +2 -0
  5. package/build/src/index.js +127 -0
  6. package/build/src/lib/process/_tests_/unit.test.d.ts +1 -0
  7. package/build/src/lib/process/_tests_/unit.test.js +112 -0
  8. package/build/src/lib/process/api.d.ts +7 -0
  9. package/build/src/lib/process/api.js +112 -0
  10. package/build/src/lib/process/constants.d.ts +3 -0
  11. package/build/src/lib/process/constants.js +3 -0
  12. package/build/src/lib/process/hex.d.ts +2 -0
  13. package/build/src/lib/process/hex.js +9 -0
  14. package/build/src/lib/process/index.d.ts +21 -0
  15. package/build/src/lib/process/index.js +205 -0
  16. package/build/src/lib/types/error.d.ts +14 -0
  17. package/build/src/lib/types/error.js +26 -0
  18. package/build/src/lib/types/validation.d.ts +5472 -0
  19. package/build/src/lib/types/validation.js +128 -0
  20. package/build/src/lib/utils/polkadot.d.ts +1 -0
  21. package/build/src/lib/utils/polkadot.js +25 -0
  22. package/build/src/version.d.ts +2 -0
  23. package/build/src/version.js +3 -0
  24. package/build/tests/fixtures/processes.d.ts +281 -0
  25. package/build/tests/fixtures/processes.js +1066 -0
  26. package/build/tests/fixtures/programs.d.ts +14 -0
  27. package/build/tests/fixtures/programs.js +211 -0
  28. package/build/tests/helpers/substrateHelper.d.ts +2 -0
  29. package/build/tests/helpers/substrateHelper.js +25 -0
  30. package/build/tests/integration/command-functions.test.d.ts +1 -0
  31. package/build/tests/integration/command-functions.test.js +327 -0
  32. package/package.json +64 -0
package/LICENSE ADDED
@@ -0,0 +1,190 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ Copyright © 2017 Digital Catapult
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,213 @@
1
+ # sqnc-process-management
2
+
3
+ A Library for managing restricted process flows in the `Sequence` (SQNC) ledger-based system.
4
+
5
+ ## Getting started
6
+
7
+ For the basic application to work and for locally run tests to work `docker-compose up` must be run.
8
+
9
+ The build command should be run first to create the converted ts files.
10
+
11
+ ```shell
12
+ npm run build
13
+ ```
14
+
15
+ To start the basic application
16
+
17
+ ```shell
18
+ npm run local
19
+ ```
20
+
21
+ To install npm CLI tool. It will be linked to local binaries so can be executed as `process-management`
22
+
23
+ ```shell
24
+ npm i -g
25
+ ```
26
+
27
+ ## using CLI
28
+
29
+ ```sh
30
+ process-management help
31
+ ```
32
+
33
+ ### Options
34
+
35
+ `sqnc-process-management` takes the following arguments to configure the `Polkadot.js` API connection:
36
+
37
+ | variable | required | default | description |
38
+ | :------- | :------: | :---------: | :-------------------------------------------------------------------------------------------------------------------- |
39
+ | `host` | N | `localhost` | The hostname of the `sqnc-node` the API should connect to |
40
+ | `port` | N | `9944` | The port of the `sqnc-node` the API should connect to |
41
+ | `user` | Y | - | The Substrate `URI` representing the private key to use when making `sqnc-node` transactions. `//Alice` for dev chain |
42
+
43
+ For the full list of available restrictions see [`sqnc-node`](https://github.com/digicatapult/sqnc-node/blob/main/pallets/process-validation/src/restrictions.rs)
44
+
45
+ ### Help
46
+
47
+ Returns all available commands
48
+
49
+ ```sh
50
+ $ process-management
51
+ Usage: process management [options] [command]
52
+
53
+ a command line interface for managing chain processes
54
+
55
+ Options:
56
+ -v, --version output current version
57
+ --help display help for command
58
+
59
+ Commands:
60
+ list [options] A command for listing all active process flows
61
+ create [options] <json> A command for persisting process flows onto the chain
62
+ disable [options] <id> <version> A command for disabling an existing process flows. Required process ID and version
63
+ help [command] display help for command
64
+ ```
65
+
66
+ ### Create Process Command
67
+
68
+ ```sh
69
+ $ process-management help create
70
+ Usage: process management create [options] <json>
71
+
72
+ A command for persisting process flows onto the chain
73
+
74
+ Options:
75
+ --dryRun to validate process and response locally before persisting on the chain, default - false
76
+ --verbose Returns all information about the transation, default - false
77
+ -h, --host <host> substrate blockchain host address or FQDM, default - "localhost" (default: "localhost")
78
+ -p, --port <port> specify host port number if it is not a default, default - 9944 (default: "9944")
79
+ -f, --file <file> path to file containing process flows to loads
80
+ -u, --user <user> specify substrate blockchain user URI
81
+ --help display help for command
82
+
83
+ #
84
+ # example
85
+ #
86
+
87
+ $ process-management create -h localhost -p 9944 -u //Alice '[{"name":"A test","version":1,"program":[{"restriction":{"FixedNumberOfOutputs":{"numOutputs":1}}},{"restriction":{"None":{}}},{"op":"Or"}]}]'
88
+
89
+ {
90
+ 'A test': {
91
+ message: 'Transaction for new process A test has been successfully submitted',
92
+ process: {
93
+ id: 'A test',
94
+ version: 1,
95
+ status: 'Enabled',
96
+ program: [
97
+ { restriction: { FixedNumberOfOutputs: { numOutputs: 1 } } },
98
+ { restriction: { None: {} } },
99
+ { op: 'Or' }
100
+ ]
101
+ }
102
+ }
103
+ }
104
+ ```
105
+
106
+ Or use a `.json` file
107
+
108
+ ```
109
+ process-management create -h localhost -p 9944 -u //Alice "$(cat exampleProcess.json)"
110
+ ```
111
+
112
+ ### Disable Process Command
113
+
114
+ ```sh
115
+ $ process-management help disable
116
+ Usage: process management disable [options] <id> <version>
117
+
118
+ A command for disabling an existing process flows. Required process ID and version
119
+
120
+ Arguments:
121
+ id a valid process id that you would like to disable
122
+ version a version number of a process
123
+
124
+ Options:
125
+ --dryRun to validate process and response locally before persisting on the chain, default - false
126
+ -h, --host <host> substrate blockchain host address or FQDM, default - "localhost" (default: "localhost")
127
+ -p, --port <port> specify host port number if it is not a default, default - 9944 (default: "9944")
128
+ --print print debugging info
129
+ -u, --user <user> specify substrate blockchain user URI
130
+ --help display help for command
131
+
132
+ #
133
+ # example
134
+ #
135
+
136
+ # let's create so we have something to disable
137
+ $ process-management create -u //Alice -f ./exampleProcess.json
138
+
139
+ {
140
+ 'B test': {
141
+ message: 'Transaction for new process B test has been successfully submitted',
142
+ process: {
143
+ id: 'B test',
144
+ version: 1,
145
+ status: 'Enabled',
146
+ program: [
147
+ { restriction: { FixedNumberOfOutputs: { numOutputs: 1 } } },
148
+ { restriction: { None: {} } },
149
+ { op: 'Or' }
150
+ ]
151
+ }
152
+ }
153
+ }
154
+
155
+ $ process-management disable -u //Alice 'B test' '1'
156
+
157
+ {
158
+ message: 'Process has been disabled',
159
+ process: { id: 'B test', version: 1, status: 'Disabled' }
160
+ }
161
+ ```
162
+
163
+ ### List Processes Command
164
+
165
+ ```sh
166
+ $ process-management list --help
167
+ Usage: process management list [options]
168
+
169
+ A command for listing all active process flows
170
+
171
+ Options:
172
+ -h, --host <host> substrate blockchain host address or FQDM, default - "localhost" (default: "localhost")
173
+ -p, --port <port> specify host port number if it is not a default, default - 9944 (default: "9944")
174
+ --raw print processes with hex values and extra keys such as "createdAtHash"
175
+ --active returns only active process flows
176
+ --disabled returns only disabled process flows
177
+ --print print debugging info
178
+ --help display help for command
179
+
180
+ #
181
+ # example
182
+ #
183
+
184
+ $ process-management list --active
185
+ [
186
+ {
187
+ id: 'default',
188
+ version: 1,
189
+ status: 'Enabled',
190
+ program: [ { restriction: { none: null } } ]
191
+ }
192
+ ]
193
+ ```
194
+
195
+ ## Running tests
196
+
197
+ Unit tests can be run without docker using:
198
+
199
+ ```shell
200
+ npm run test:unit
201
+ ```
202
+
203
+ To run the integration test suite first bring up the test dependency services using docker
204
+
205
+ ```shell
206
+ docker compose -f ./docker-compose-test.yaml up -d
207
+ ```
208
+
209
+ And then to run the tests
210
+
211
+ ```shell
212
+ npm run test
213
+ ```
@@ -0,0 +1,64 @@
1
+ {
2
+ "name": "@digicatapult/sqnc-process-management",
3
+ "version": "2.2.0",
4
+ "description": "SQNC Process Management Flow",
5
+ "main": "./lib/index.js",
6
+ "bin": {
7
+ "process-management": "./build/src/index.js"
8
+ },
9
+ "type": "module",
10
+ "scripts": {
11
+ "start": "node --loader ts-node/esm src/index.ts",
12
+ "local": "npm i -g && process-management",
13
+ "dev": "nodemon --watch 'src/**/*.ts' --exec node --loader ts-node/esm src/index.ts",
14
+ "lint": "eslint . --ext .ts",
15
+ "build": "tsc --build",
16
+ "depcheck": "depcheck",
17
+ "test": "ts-mocha --config ./tests/mocharc.json -n loader=ts-node/esm -p tsconfig.json tests/**/*.test.ts --exit",
18
+ "test:unit": "ts-mocha --config ./tests/mocharc.json -n loader=ts-node/esm -p tsconfig.json src/**/*.test.ts --exit",
19
+ "prettier": "npx prettier --write ."
20
+ },
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "git+https://github.com/digicatapult/sqnc-process-management.git"
24
+ },
25
+ "files": [
26
+ "/build"
27
+ ],
28
+ "engines": {
29
+ "node": ">=20.x.x",
30
+ "npm": ">=10.x.x"
31
+ },
32
+ "author": "Digital Catapult",
33
+ "license": "Apache-2.0",
34
+ "bugs": {
35
+ "url": "https://github.com/digicatapult/sqnc-process-management/issues"
36
+ },
37
+ "homepage": "https://github.com/digicatapult/sqnc-process-management#readme",
38
+ "devDependencies": {
39
+ "@types/chai": "^4.3.11",
40
+ "@types/chai-as-promised": "^7.1.8",
41
+ "@types/mocha": "^10.0.6",
42
+ "@types/node": "^18.19.4",
43
+ "@typescript-eslint/eslint-plugin": "^6.17.0",
44
+ "@typescript-eslint/parser": "^6.17.0",
45
+ "chai": "^4.3.10",
46
+ "chai-as-promised": "^7.1.1",
47
+ "depcheck": "^1.4.7",
48
+ "eslint": "^8.56.0",
49
+ "eslint-config-prettier": "^9.1.0",
50
+ "eslint-plugin-prettier": "^5.1.2",
51
+ "mocha": "^10.2.0",
52
+ "nodemon": "^3.0.2",
53
+ "prettier": "^3.1.1",
54
+ "ts-mocha": "^10.0.0",
55
+ "ts-node": "^10.9.2"
56
+ },
57
+ "dependencies": {
58
+ "@polkadot/api": "^10.11.2",
59
+ "chalk": "^5.3.0",
60
+ "commander": "^11.1.0",
61
+ "typescript": "^5.3.3",
62
+ "zod": "^3.22.4"
63
+ }
64
+ }
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env -S node --no-warnings
2
+ export {};
@@ -0,0 +1,127 @@
1
+ #!/usr/bin/env -S node --no-warnings
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ import fs from 'fs/promises';
12
+ import chalk from 'chalk';
13
+ import { Command } from 'commander';
14
+ import { loadProcesses, disableProcess, listTransforming } from './lib/process/index.js';
15
+ import { getAll } from './lib/process/api.js';
16
+ import cliVersion from './version.js';
17
+ const unwrap = (res) => {
18
+ if (res.type === 'ok')
19
+ return res.result;
20
+ else
21
+ throw res.error;
22
+ };
23
+ const { log, dir } = console;
24
+ const program = new Command();
25
+ const { red: r, blue: b } = {
26
+ red: (txt) => chalk.redBright(txt),
27
+ blue: (txt) => chalk.blueBright(txt),
28
+ };
29
+ const mapOptions = (options) => ({
30
+ API_HOST: options.host,
31
+ API_PORT: parseInt(options.port),
32
+ USER_URI: options.user,
33
+ });
34
+ // TODO nice to have, a local config file for substrate host details e.g. name, port, address
35
+ // so no need to parse every time calling a command, or ability to set
36
+ program
37
+ .name('process management')
38
+ .description('a command line interface for managing chain processes')
39
+ .version(cliVersion, '-v, --version', 'output current version')
40
+ .helpOption('--help', 'display help for command'); //override -h
41
+ program
42
+ .command('list')
43
+ .description('A command for listing all active process flows')
44
+ .option('-v, --verbose', 'Returns all information about the transation, default - false')
45
+ .option('-h, --host <host>', 'substrate blockchain host address or FQDM, default - "localhost"', 'localhost')
46
+ .option('-p, --port <port>', 'specify host port number if it is not a default, default - 9944', '9944')
47
+ .option('--raw', 'print processes with hex values and extra keys such as "createdAtHash"')
48
+ .option('--active', 'returns only active process flows')
49
+ .option('--disabled', 'returns only disabled process flows')
50
+ .action((options) => __awaiter(void 0, void 0, void 0, function* () {
51
+ if (options.print)
52
+ log(`
53
+ retrieving all process flows from a chain...
54
+ options: ${b(JSON.stringify(options))}
55
+ `);
56
+ try {
57
+ const res = yield getAll(mapOptions(options));
58
+ const transformed = listTransforming(res, options);
59
+ dir(transformed, { depth: null });
60
+ process.exit(0);
61
+ }
62
+ catch (err) {
63
+ log(err);
64
+ process.exit(1);
65
+ }
66
+ }));
67
+ program
68
+ .command('create')
69
+ .description('A command for persisting process flows onto the chain')
70
+ .option('--dryRun', 'to validate process and response locally before persisting on the chain, default - false')
71
+ .option('--verbose', 'Returns all information about the transation, default - false')
72
+ .option('-h, --host <host>', 'substrate blockchain host address or FQDM, default - "localhost"', 'localhost')
73
+ .option('-p, --port <port>', 'specify host port number if it is not a default, default - 9944', '9944')
74
+ .requiredOption('-f, --file <file>', 'path to file containing process flows to loads')
75
+ .requiredOption('-u, --user <user>', 'specify substrate blockchain user URI')
76
+ .action((options) => __awaiter(void 0, void 0, void 0, function* () {
77
+ if (options.print)
78
+ log(`
79
+ attempting to create a process...
80
+ options: ${b(JSON.stringify(options))}
81
+ `);
82
+ const { dryRun, verbose } = options;
83
+ try {
84
+ const data = (yield fs.readFile(options.file)).toString('utf8');
85
+ const loadResult = yield loadProcesses({ data, dryRun, options: mapOptions(options), verbose });
86
+ dir(loadResult.message, { depth: null });
87
+ dir(unwrap(loadResult), { depth: null });
88
+ process.exit(0);
89
+ }
90
+ catch (err) {
91
+ log(err);
92
+ process.exit(1);
93
+ }
94
+ }));
95
+ program
96
+ .command('disable')
97
+ .description('A command for disabling an existing process flows. Required process ID and version')
98
+ .option('--dryRun', 'to validate process and response locally before persisting on the chain, default - false')
99
+ .option('-h, --host <host>', 'substrate blockchain host address or FQDM, default - "localhost"', 'localhost')
100
+ .option('-p, --port <port>', 'specify host port number if it is not a default, default - 9944', '9944')
101
+ .requiredOption('-u, --user <user>', 'specify substrate blockchain user URI')
102
+ .argument('<id>', 'a valid process id that you would like to disable')
103
+ .argument('<version>', 'a version number of a process')
104
+ .action((id, version, options) => __awaiter(void 0, void 0, void 0, function* () {
105
+ if (options.print)
106
+ log(`attempting to disable:\nID:${b(id)}\nVersion:${b(version)}`);
107
+ try {
108
+ const { dryRun } = options;
109
+ const res = unwrap(yield disableProcess(id, parseInt(version), dryRun, mapOptions(options)));
110
+ dir(res, { depth: null });
111
+ process.exit(0);
112
+ }
113
+ catch (err) {
114
+ log(err);
115
+ process.exit(1);
116
+ }
117
+ }));
118
+ program.parse();
119
+ if (!program.option) {
120
+ program.help();
121
+ }
122
+ program.on('command:*', function () {
123
+ log(`
124
+ ${r('Invalid command: %s\nSee --help for a list of available commands.')}
125
+ ${program.args.join(' ')}`);
126
+ process.exit(127);
127
+ });
@@ -0,0 +1 @@
1
+ export {};