@icedq/cli 0.1.1 → 0.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.
- package/LICENSE +201 -21
- package/NOTICE +16 -0
- package/package.json +10 -5
- package/src/bin/icedq.js +84 -75
- package/src/commands/generate-mapping.js +217 -0
- package/src/commands/import.js +174 -175
package/LICENSE
CHANGED
|
@@ -1,21 +1,201 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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 Derivative
|
|
95
|
+
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
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Torana Inc. (iceDQ)
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
iceDQ CLI (@icedq/cli)
|
|
2
|
+
Copyright 2026 Torana Inc. (iceDQ)
|
|
3
|
+
|
|
4
|
+
This product includes software developed by Torana Inc.
|
|
5
|
+
|
|
6
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
you may not use this file except in compliance with the License.
|
|
8
|
+
You may obtain a copy of the License at
|
|
9
|
+
|
|
10
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
|
|
12
|
+
Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
See the License for the specific language governing permissions and
|
|
16
|
+
limitations under the License.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@icedq/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "CLI for iceDQ rule and workflow promotion across environments",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/bin/icedq.js",
|
|
@@ -8,8 +8,9 @@
|
|
|
8
8
|
"icedq": "./src/bin/icedq.js"
|
|
9
9
|
},
|
|
10
10
|
"scripts": {
|
|
11
|
-
"test": "node --test
|
|
12
|
-
"start": "node src/bin/icedq.js"
|
|
11
|
+
"test": "node --test",
|
|
12
|
+
"start": "node src/bin/icedq.js",
|
|
13
|
+
"prepublishOnly": "npm test"
|
|
13
14
|
},
|
|
14
15
|
"engines": {
|
|
15
16
|
"node": ">=18.0.0"
|
|
@@ -22,7 +23,10 @@
|
|
|
22
23
|
"github-action"
|
|
23
24
|
],
|
|
24
25
|
"author": "iceDQ Integration Team",
|
|
25
|
-
"license": "
|
|
26
|
+
"license": "Apache-2.0",
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"access": "public"
|
|
29
|
+
},
|
|
26
30
|
"homepage": "https://github.com/icedq-tools/cli#readme",
|
|
27
31
|
"repository": {
|
|
28
32
|
"type": "git",
|
|
@@ -38,6 +42,7 @@
|
|
|
38
42
|
"files": [
|
|
39
43
|
"src/",
|
|
40
44
|
"README.md",
|
|
41
|
-
"LICENSE"
|
|
45
|
+
"LICENSE",
|
|
46
|
+
"NOTICE"
|
|
42
47
|
]
|
|
43
48
|
}
|
package/src/bin/icedq.js
CHANGED
|
@@ -1,75 +1,84 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { Command, Option } from 'commander';
|
|
3
|
-
import { runExport } from '../commands/export.js';
|
|
4
|
-
import { runImport } from '../commands/import.js';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
.
|
|
13
|
-
.
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
.option('--
|
|
19
|
-
.option('--
|
|
20
|
-
.option('--client-
|
|
21
|
-
.option('--
|
|
22
|
-
.option('--
|
|
23
|
-
.option('--
|
|
24
|
-
.option('--
|
|
25
|
-
.option('--
|
|
26
|
-
.
|
|
27
|
-
.
|
|
28
|
-
.option('-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
.
|
|
36
|
-
.
|
|
37
|
-
.requiredOption('--
|
|
38
|
-
.
|
|
39
|
-
.
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
.
|
|
46
|
-
.
|
|
47
|
-
.requiredOption('--
|
|
48
|
-
.requiredOption('--
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { Command, Option } from 'commander';
|
|
3
|
+
import { runExport } from '../commands/export.js';
|
|
4
|
+
import { runImport } from '../commands/import.js';
|
|
5
|
+
import { runGenerateMapping } from '../commands/generate-mapping.js';
|
|
6
|
+
import { CliError } from '../core/errors.js';
|
|
7
|
+
import { log } from '../core/logger.js';
|
|
8
|
+
|
|
9
|
+
const program = new Command();
|
|
10
|
+
|
|
11
|
+
program
|
|
12
|
+
.name('icedq')
|
|
13
|
+
.description('CLI for iceDQ rule and workflow promotion')
|
|
14
|
+
.version('0.1.0');
|
|
15
|
+
|
|
16
|
+
function addGlobalOptions(cmd) {
|
|
17
|
+
cmd
|
|
18
|
+
.option('--icedq-url <url>', 'iceDQ instance base URL [env: ICEDQ_URL]')
|
|
19
|
+
.option('--keycloak-url <url>', 'Keycloak token endpoint base [env: ICEDQ_KEYCLOAK_URL]')
|
|
20
|
+
.option('--client-id <id>', 'OAuth client ID [env: ICEDQ_CLIENT_ID]')
|
|
21
|
+
.option('--client-secret <secret>', 'OAuth client secret [env: ICEDQ_CLIENT_SECRET]')
|
|
22
|
+
.option('--org-id <id>', '[env: ICEDQ_ORG_ID]')
|
|
23
|
+
.option('--account-id <id>', '[env: ICEDQ_ACCOUNT_ID]')
|
|
24
|
+
.option('--workspace-id <id>', '[env: ICEDQ_WORKSPACE_ID]')
|
|
25
|
+
.option('--verify-ssl <bool>', 'verify TLS (default true)')
|
|
26
|
+
.option('--timeout <seconds>', 'polling timeout in seconds', '1800')
|
|
27
|
+
.addOption(new Option('--output <format>', 'output format').choices(['text', 'json', 'markdown']).default('text'))
|
|
28
|
+
.option('-v, --verbose', 'verbose logging')
|
|
29
|
+
.option('-q, --quiet', 'suppress non-error logging');
|
|
30
|
+
return cmd;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
addGlobalOptions(
|
|
34
|
+
program
|
|
35
|
+
.command('export')
|
|
36
|
+
.description('Export rules, workflows, or folders to a bundle')
|
|
37
|
+
.requiredOption('--resource <kind>', 'rule | workflow | folder')
|
|
38
|
+
.requiredOption('--id <uuid>', 'resource UUID')
|
|
39
|
+
.option('--include-child', 'recurse folder children (folder resource only)', false)
|
|
40
|
+
.requiredOption('--output-file <path>', 'where to write the bundle ZIP')
|
|
41
|
+
).action(async (opts, cmd) => wrap(() => runExport(merge(cmd, opts))));
|
|
42
|
+
|
|
43
|
+
addGlobalOptions(
|
|
44
|
+
program
|
|
45
|
+
.command('generate-mapping')
|
|
46
|
+
.description('Auto-generate a mapping file from an export bundle')
|
|
47
|
+
.requiredOption('--bundle <path>', 'path to the export ZIP')
|
|
48
|
+
.requiredOption('--output-file <path>', 'where to write the mapping JSON')
|
|
49
|
+
).action(async (opts, cmd) => wrap(() => runGenerateMapping(merge(cmd, opts))));
|
|
50
|
+
|
|
51
|
+
addGlobalOptions(
|
|
52
|
+
program
|
|
53
|
+
.command('import')
|
|
54
|
+
.description('Import a bundle into the target workspace')
|
|
55
|
+
.requiredOption('--bundle <path>', 'path to the export ZIP')
|
|
56
|
+
.requiredOption('--kind <kind>', 'rules | workflows')
|
|
57
|
+
.requiredOption('--mapping-file <path>', 'mapping JSON (auto-generation arrives in v0.2)')
|
|
58
|
+
.option('--use-fqn', 'use FQN (name) resolution instead of UUIDs', false)
|
|
59
|
+
.option('--strict', 'exit non-zero on any skipped rule', false)
|
|
60
|
+
.option('--terminate-on-conflict', 'cancel any active import in the target workspace and retry', false)
|
|
61
|
+
.option('--retain-log <path>', 'write the full import log to this path')
|
|
62
|
+
).action(async (opts, cmd) => wrap(() => runImport(merge(cmd, opts))));
|
|
63
|
+
|
|
64
|
+
function merge(cmd, localOpts) {
|
|
65
|
+
return { ...cmd.parent.opts(), ...cmd.opts(), ...localOpts };
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async function wrap(fn) {
|
|
69
|
+
try {
|
|
70
|
+
await fn();
|
|
71
|
+
} catch (err) {
|
|
72
|
+
if (err instanceof CliError) {
|
|
73
|
+
log.error(err.message);
|
|
74
|
+
process.exit(err.exitCode || 1);
|
|
75
|
+
}
|
|
76
|
+
log.error(`Unexpected error: ${err.message}`, { stack: err.stack });
|
|
77
|
+
process.exit(1);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
program.parseAsync(process.argv).catch((err) => {
|
|
82
|
+
log.error(`Fatal: ${err.message}`);
|
|
83
|
+
process.exit(1);
|
|
84
|
+
});
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import { readFile, writeFile, mkdir } from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { loadConfig } from '../core/config.js';
|
|
4
|
+
import { KeycloakClientCredentialsAuth } from '../core/auth.js';
|
|
5
|
+
import { IcedqApiClient } from '../core/client.js';
|
|
6
|
+
import { Reporter } from '../core/reporter.js';
|
|
7
|
+
import { ApiError, CliError } from '../core/errors.js';
|
|
8
|
+
import { log, setLevel } from '../core/logger.js';
|
|
9
|
+
|
|
10
|
+
const PAGE_SIZE = 1000;
|
|
11
|
+
|
|
12
|
+
export async function runGenerateMapping(rawOpts) {
|
|
13
|
+
if (rawOpts.verbose) setLevel('debug');
|
|
14
|
+
if (rawOpts.quiet) setLevel('error');
|
|
15
|
+
|
|
16
|
+
if (!rawOpts.bundle) throw new CliError('--bundle is required');
|
|
17
|
+
if (!rawOpts.outputFile) throw new CliError('--output-file is required');
|
|
18
|
+
|
|
19
|
+
const cfg = loadConfig(rawOpts);
|
|
20
|
+
const auth = new KeycloakClientCredentialsAuth({
|
|
21
|
+
keycloakUrl: cfg.keycloakUrl,
|
|
22
|
+
clientId: cfg.clientId,
|
|
23
|
+
clientSecret: cfg.clientSecret,
|
|
24
|
+
verifySsl: cfg.verifySsl
|
|
25
|
+
});
|
|
26
|
+
const client = new IcedqApiClient({
|
|
27
|
+
baseUrl: cfg.icedqUrl,
|
|
28
|
+
orgId: cfg.orgId,
|
|
29
|
+
accountId: cfg.accountId,
|
|
30
|
+
workspaceId: cfg.workspaceId,
|
|
31
|
+
auth,
|
|
32
|
+
verifySsl: cfg.verifySsl
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
const bundlePath = path.resolve(rawOpts.bundle);
|
|
36
|
+
let bundleBuffer;
|
|
37
|
+
try {
|
|
38
|
+
bundleBuffer = await readFile(bundlePath);
|
|
39
|
+
} catch (err) {
|
|
40
|
+
throw new CliError(`could not read bundle at ${bundlePath}: ${err.message}`);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Step 1: get expected mappings from bundle
|
|
44
|
+
log.info('Uploading bundle to get expected mappings');
|
|
45
|
+
const expected = await client.postMultipart('/api/v1/internal/imports/mapping', {
|
|
46
|
+
file: {
|
|
47
|
+
buffer: bundleBuffer,
|
|
48
|
+
filename: path.basename(bundlePath),
|
|
49
|
+
contentType: 'application/zip'
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
const srcConnections = expected.connections || [];
|
|
54
|
+
const srcParameters = expected.parameters || [];
|
|
55
|
+
const srcCustomFields = expected.customFields || [];
|
|
56
|
+
|
|
57
|
+
log.info('Expected mappings', {
|
|
58
|
+
connections: srcConnections.length,
|
|
59
|
+
parameters: srcParameters.length,
|
|
60
|
+
customFields: srcCustomFields.length
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
// Step 2: resolve connections from target environment
|
|
64
|
+
const connections = await resolveConnections(client, srcConnections);
|
|
65
|
+
|
|
66
|
+
// Step 3: resolve parameters from target environment
|
|
67
|
+
const parameters = await resolveParameters(client, srcParameters);
|
|
68
|
+
|
|
69
|
+
// Step 4: resolve custom fields from target environment
|
|
70
|
+
const customFields = await resolveCustomFields(client, srcCustomFields);
|
|
71
|
+
|
|
72
|
+
const mappingDoc = {
|
|
73
|
+
useFqn: true,
|
|
74
|
+
mapping: { connections, parameters, customFields }
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const outputFile = path.resolve(rawOpts.outputFile);
|
|
78
|
+
await mkdir(path.dirname(outputFile), { recursive: true });
|
|
79
|
+
await writeFile(outputFile, JSON.stringify(mappingDoc, null, 2), 'utf8');
|
|
80
|
+
log.info('Mapping file written', { outputFile });
|
|
81
|
+
|
|
82
|
+
const result = {
|
|
83
|
+
command: 'generate-mapping',
|
|
84
|
+
outputFile,
|
|
85
|
+
connections: connections.length,
|
|
86
|
+
parameters: parameters.length,
|
|
87
|
+
customFields: customFields.length
|
|
88
|
+
};
|
|
89
|
+
new Reporter(rawOpts.output || 'text').emit(result);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
async function resolveConnections(client, srcConnections) {
|
|
93
|
+
if (srcConnections.length === 0) return [];
|
|
94
|
+
|
|
95
|
+
// Group source connections by connectorId
|
|
96
|
+
const byConnectorId = new Map();
|
|
97
|
+
for (const conn of srcConnections) {
|
|
98
|
+
if (!byConnectorId.has(conn.connectorId)) byConnectorId.set(conn.connectorId, []);
|
|
99
|
+
byConnectorId.get(conn.connectorId).push(conn);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const mappings = [];
|
|
103
|
+
|
|
104
|
+
for (const [connectorId, srcConns] of byConnectorId) {
|
|
105
|
+
log.info('Searching connections in target', { connectorId });
|
|
106
|
+
|
|
107
|
+
// Fetch all pages for this connectorId
|
|
108
|
+
const targetItems = await fetchAllPages(client, '/api/v1/connections/search', {
|
|
109
|
+
filter: [{ attribute: 'connectorId', operator: 'In', datatype: 'string', value: connectorId }]
|
|
110
|
+
}, `connections with connectorId=${connectorId}`);
|
|
111
|
+
|
|
112
|
+
for (const src of srcConns) {
|
|
113
|
+
const match = targetItems.find(
|
|
114
|
+
(t) => t.name.toLowerCase() === src.name.toLowerCase()
|
|
115
|
+
);
|
|
116
|
+
if (!match) {
|
|
117
|
+
throw new CliError(
|
|
118
|
+
`Connection "${src.name}" (connectorId: ${connectorId}) was not found in the target environment. ` +
|
|
119
|
+
`Ensure a connection with this name exists in the target workspace before generating the mapping.`
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
mappings.push({ existingId: src.id, newId: match.id, action: 'override' });
|
|
123
|
+
log.info('Mapped connection', { name: src.name, existingId: src.id, newId: match.id });
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
return mappings;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
async function resolveParameters(client, srcParameters) {
|
|
131
|
+
if (srcParameters.length === 0) return [];
|
|
132
|
+
|
|
133
|
+
log.info('Searching parameters in target');
|
|
134
|
+
|
|
135
|
+
let targetItems = [];
|
|
136
|
+
try {
|
|
137
|
+
targetItems = await fetchAllPages(client, '/api/v1/parameters/search', {}, 'parameters');
|
|
138
|
+
} catch (err) {
|
|
139
|
+
if (err instanceof ApiError && err.code === 'ResultsNotFound') {
|
|
140
|
+
log.warn('No parameters found in target environment — mapping without newId');
|
|
141
|
+
return srcParameters.map((p) => ({ existingId: p.id, action: 'upsert' }));
|
|
142
|
+
}
|
|
143
|
+
throw err;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return srcParameters.map((src) => {
|
|
147
|
+
const match = targetItems.find(
|
|
148
|
+
(t) => t.name.toLowerCase() === src.name.toLowerCase()
|
|
149
|
+
);
|
|
150
|
+
if (!match) {
|
|
151
|
+
log.warn('Parameter not matched in target, mapping without newId', { name: src.name });
|
|
152
|
+
return { existingId: src.id, action: 'upsert' };
|
|
153
|
+
}
|
|
154
|
+
log.info('Mapped parameter', { name: src.name, existingId: src.id, newId: match.id });
|
|
155
|
+
return { existingId: src.id, newId: match.id, action: 'upsert' };
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
async function resolveCustomFields(client, srcCustomFields) {
|
|
160
|
+
if (srcCustomFields.length === 0) return [];
|
|
161
|
+
|
|
162
|
+
log.info('Fetching screens for custom field mapping');
|
|
163
|
+
const screens = await client.post('/api/v1/screens/default/search', ['rule', 'check']);
|
|
164
|
+
|
|
165
|
+
// Flatten all fields from all sections of all screens into a name→id map
|
|
166
|
+
const fieldMap = new Map();
|
|
167
|
+
for (const screen of Array.isArray(screens) ? screens : []) {
|
|
168
|
+
const sections = screen?.info?.sections || [];
|
|
169
|
+
for (const section of sections) {
|
|
170
|
+
for (const field of section.fields || []) {
|
|
171
|
+
if (field.name && field.id) {
|
|
172
|
+
fieldMap.set(field.name.toLowerCase(), field.id);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const mappings = [];
|
|
179
|
+
for (const fieldName of srcCustomFields) {
|
|
180
|
+
const targetId = fieldMap.get(fieldName.toLowerCase());
|
|
181
|
+
if (!targetId) {
|
|
182
|
+
log.warn('Custom field not found in target screens, skipping', { fieldName });
|
|
183
|
+
continue;
|
|
184
|
+
}
|
|
185
|
+
mappings.push({ existingId: fieldName, newId: targetId, action: 'override' });
|
|
186
|
+
log.info('Mapped custom field', { fieldName, newId: targetId });
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
return mappings;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// Fetches all pages from a paginated POST search endpoint.
|
|
193
|
+
// Throws ApiError with code='ResultsNotFound' when the endpoint reports nothing found.
|
|
194
|
+
async function fetchAllPages(client, endpoint, body, label) {
|
|
195
|
+
const items = [];
|
|
196
|
+
let pageNo = 1;
|
|
197
|
+
let totalPages = 1;
|
|
198
|
+
|
|
199
|
+
do {
|
|
200
|
+
const url = `${endpoint}?pageNo=${pageNo}&pageSize=${PAGE_SIZE}&sort=updatedTimestamp:desc`;
|
|
201
|
+
const resp = await client.post(url, body);
|
|
202
|
+
|
|
203
|
+
// API may return 200 with {code, message} instead of a 4xx
|
|
204
|
+
if (resp && resp.code === 'ResultsNotFound') {
|
|
205
|
+
throw new ApiError(`${label}: ${resp.message || 'ResultsNotFound'}`, {
|
|
206
|
+
status: 200,
|
|
207
|
+
code: 'ResultsNotFound'
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
items.push(...(resp?.items || []));
|
|
212
|
+
totalPages = resp?.pageable?.pages ?? 1;
|
|
213
|
+
pageNo++;
|
|
214
|
+
} while (pageNo <= totalPages);
|
|
215
|
+
|
|
216
|
+
return items;
|
|
217
|
+
}
|
package/src/commands/import.js
CHANGED
|
@@ -1,175 +1,174 @@
|
|
|
1
|
-
import { readFile, writeFile } from 'node:fs/promises';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
import { loadConfig } from '../core/config.js';
|
|
4
|
-
import { KeycloakClientCredentialsAuth } from '../core/auth.js';
|
|
5
|
-
import { IcedqApiClient } from '../core/client.js';
|
|
6
|
-
import { pollTask } from '../core/poller.js';
|
|
7
|
-
import { Reporter } from '../core/reporter.js';
|
|
8
|
-
import { parseImportLog } from '../lib/log-parser.js';
|
|
9
|
-
import { isSuccess } from '../lib/status-enum.js';
|
|
10
|
-
import { ApiError, BundleError, CliError, TaskFailedError } from '../core/errors.js';
|
|
11
|
-
import { log, setLevel } from '../core/logger.js';
|
|
12
|
-
|
|
13
|
-
const VALID_KINDS = new Set(['rules', 'workflows']);
|
|
14
|
-
|
|
15
|
-
export async function runImport(rawOpts) {
|
|
16
|
-
if (rawOpts.verbose) setLevel('debug');
|
|
17
|
-
if (rawOpts.quiet) setLevel('error');
|
|
18
|
-
|
|
19
|
-
if (!rawOpts.bundle) throw new CliError('--bundle is required');
|
|
20
|
-
if (!rawOpts.kind || !VALID_KINDS.has(rawOpts.kind)) {
|
|
21
|
-
throw new CliError(`--kind must be one of: rules, workflows`);
|
|
22
|
-
}
|
|
23
|
-
if (!rawOpts.mappingFile) {
|
|
24
|
-
throw new CliError(
|
|
25
|
-
'--mapping-file is required in v0.1. Auto-mapping (`generate-mapping`) ships in v0.2.'
|
|
26
|
-
);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const cfg = loadConfig(rawOpts);
|
|
30
|
-
const auth = new KeycloakClientCredentialsAuth({
|
|
31
|
-
keycloakUrl: cfg.keycloakUrl,
|
|
32
|
-
clientId: cfg.clientId,
|
|
33
|
-
clientSecret: cfg.clientSecret,
|
|
34
|
-
verifySsl: cfg.verifySsl
|
|
35
|
-
});
|
|
36
|
-
const client = new IcedqApiClient({
|
|
37
|
-
baseUrl: cfg.icedqUrl,
|
|
38
|
-
orgId: cfg.orgId,
|
|
39
|
-
accountId: cfg.accountId,
|
|
40
|
-
workspaceId: cfg.workspaceId,
|
|
41
|
-
auth,
|
|
42
|
-
verifySsl: cfg.verifySsl
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
const bundlePath = path.resolve(rawOpts.bundle);
|
|
46
|
-
const mappingPath = path.resolve(rawOpts.mappingFile);
|
|
47
|
-
|
|
48
|
-
let bundleBuffer;
|
|
49
|
-
try {
|
|
50
|
-
bundleBuffer = await readFile(bundlePath);
|
|
51
|
-
} catch (err) {
|
|
52
|
-
throw new BundleError(`could not read bundle at ${bundlePath}: ${err.message}`);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
let mappingDoc;
|
|
56
|
-
try {
|
|
57
|
-
const text = await readFile(mappingPath, 'utf8');
|
|
58
|
-
mappingDoc = JSON.parse(text);
|
|
59
|
-
} catch (err) {
|
|
60
|
-
throw new CliError(`could not parse --mapping-file at ${mappingPath}: ${err.message}`);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if (
|
|
64
|
-
mappingDoc.useFqn = !!rawOpts.useFqn;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
await
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
const
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
logText =
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
const
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
e
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
{ attribute: 'type', operator: 'In', value: 'import-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
)
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
}
|
|
1
|
+
import { readFile, writeFile } from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { loadConfig } from '../core/config.js';
|
|
4
|
+
import { KeycloakClientCredentialsAuth } from '../core/auth.js';
|
|
5
|
+
import { IcedqApiClient } from '../core/client.js';
|
|
6
|
+
import { pollTask } from '../core/poller.js';
|
|
7
|
+
import { Reporter } from '../core/reporter.js';
|
|
8
|
+
import { parseImportLog } from '../lib/log-parser.js';
|
|
9
|
+
import { isSuccess } from '../lib/status-enum.js';
|
|
10
|
+
import { ApiError, BundleError, CliError, TaskFailedError } from '../core/errors.js';
|
|
11
|
+
import { log, setLevel } from '../core/logger.js';
|
|
12
|
+
|
|
13
|
+
const VALID_KINDS = new Set(['rules', 'workflows']);
|
|
14
|
+
|
|
15
|
+
export async function runImport(rawOpts) {
|
|
16
|
+
if (rawOpts.verbose) setLevel('debug');
|
|
17
|
+
if (rawOpts.quiet) setLevel('error');
|
|
18
|
+
|
|
19
|
+
if (!rawOpts.bundle) throw new CliError('--bundle is required');
|
|
20
|
+
if (!rawOpts.kind || !VALID_KINDS.has(rawOpts.kind)) {
|
|
21
|
+
throw new CliError(`--kind must be one of: rules, workflows`);
|
|
22
|
+
}
|
|
23
|
+
if (!rawOpts.mappingFile) {
|
|
24
|
+
throw new CliError(
|
|
25
|
+
'--mapping-file is required in v0.1. Auto-mapping (`generate-mapping`) ships in v0.2.'
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const cfg = loadConfig(rawOpts);
|
|
30
|
+
const auth = new KeycloakClientCredentialsAuth({
|
|
31
|
+
keycloakUrl: cfg.keycloakUrl,
|
|
32
|
+
clientId: cfg.clientId,
|
|
33
|
+
clientSecret: cfg.clientSecret,
|
|
34
|
+
verifySsl: cfg.verifySsl
|
|
35
|
+
});
|
|
36
|
+
const client = new IcedqApiClient({
|
|
37
|
+
baseUrl: cfg.icedqUrl,
|
|
38
|
+
orgId: cfg.orgId,
|
|
39
|
+
accountId: cfg.accountId,
|
|
40
|
+
workspaceId: cfg.workspaceId,
|
|
41
|
+
auth,
|
|
42
|
+
verifySsl: cfg.verifySsl
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
const bundlePath = path.resolve(rawOpts.bundle);
|
|
46
|
+
const mappingPath = path.resolve(rawOpts.mappingFile);
|
|
47
|
+
|
|
48
|
+
let bundleBuffer;
|
|
49
|
+
try {
|
|
50
|
+
bundleBuffer = await readFile(bundlePath);
|
|
51
|
+
} catch (err) {
|
|
52
|
+
throw new BundleError(`could not read bundle at ${bundlePath}: ${err.message}`);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
let mappingDoc;
|
|
56
|
+
try {
|
|
57
|
+
const text = await readFile(mappingPath, 'utf8');
|
|
58
|
+
mappingDoc = JSON.parse(text);
|
|
59
|
+
} catch (err) {
|
|
60
|
+
throw new CliError(`could not parse --mapping-file at ${mappingPath}: ${err.message}`);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (mappingDoc.useFqn === undefined) {
|
|
64
|
+
mappingDoc.useFqn = !!rawOpts.useFqn;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const submitParts = {
|
|
68
|
+
file: {
|
|
69
|
+
buffer: bundleBuffer,
|
|
70
|
+
filename: path.basename(bundlePath),
|
|
71
|
+
contentType: 'application/zip'
|
|
72
|
+
},
|
|
73
|
+
mapping: { json: mappingDoc }
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const importPath = `/api/v1/imports/${rawOpts.kind}`;
|
|
77
|
+
log.info('Submitting import', { kind: rawOpts.kind, bundle: bundlePath, mapping: mappingPath });
|
|
78
|
+
|
|
79
|
+
let submitResp;
|
|
80
|
+
try {
|
|
81
|
+
submitResp = await client.postMultipart(importPath, submitParts);
|
|
82
|
+
} catch (err) {
|
|
83
|
+
if (err instanceof ApiError && err.isConstraintViolation()) {
|
|
84
|
+
const result = {
|
|
85
|
+
command: 'import',
|
|
86
|
+
status: 'ConstraintViolation',
|
|
87
|
+
hardErrors: err.messages.map(
|
|
88
|
+
(m) => `${m.fieldName ? m.fieldName + ': ' : ''}${m.violation || m.message || ''}`
|
|
89
|
+
)
|
|
90
|
+
};
|
|
91
|
+
new Reporter(rawOpts.output || 'text').emit(result);
|
|
92
|
+
throw err;
|
|
93
|
+
}
|
|
94
|
+
if (err instanceof ApiError && err.status === 409 && rawOpts.terminateOnConflict) {
|
|
95
|
+
log.warn('Active import job conflicts; locating and terminating');
|
|
96
|
+
await terminateActiveImport(client);
|
|
97
|
+
submitResp = await client.postMultipart(importPath, submitParts);
|
|
98
|
+
} else {
|
|
99
|
+
throw err;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const taskId = submitResp.taskInstanceId;
|
|
104
|
+
if (!taskId) throw new CliError(`Import submit did not return taskInstanceId: ${JSON.stringify(submitResp)}`);
|
|
105
|
+
process.stderr.write(`task-id: ${taskId}\n`);
|
|
106
|
+
|
|
107
|
+
const start = Date.now();
|
|
108
|
+
const { status, elapsedMs, attempts } = await pollTask(client, 'imports', taskId, {
|
|
109
|
+
timeoutSec: cfg.timeoutSec,
|
|
110
|
+
onTick: ({ status: s, attempt }) => log.debug('tick', { status: s, attempt })
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
let logText = '';
|
|
114
|
+
try {
|
|
115
|
+
logText = await client.get(`/api/v1/imports/${taskId}/log`);
|
|
116
|
+
if (typeof logText !== 'string') logText = JSON.stringify(logText);
|
|
117
|
+
} catch (err) {
|
|
118
|
+
log.warn('Could not retrieve import log', { error: err.message });
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (rawOpts.retainLog && logText) {
|
|
122
|
+
const logPath = path.resolve(rawOpts.retainLog);
|
|
123
|
+
try {
|
|
124
|
+
await writeFile(logPath, logText, 'utf8');
|
|
125
|
+
log.info('Import log retained', { logPath });
|
|
126
|
+
} catch (err) {
|
|
127
|
+
log.warn('Could not write retained log', { logPath, error: err.message });
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const parsed = parseImportLog(logText);
|
|
132
|
+
const result = {
|
|
133
|
+
command: 'import',
|
|
134
|
+
taskId,
|
|
135
|
+
status,
|
|
136
|
+
attempts,
|
|
137
|
+
durationMs: elapsedMs,
|
|
138
|
+
skippedCount: parsed.skippedCount,
|
|
139
|
+
skippedRules: parsed.skippedRules,
|
|
140
|
+
hardErrors: parsed.hardErrors,
|
|
141
|
+
elapsedSinceSubmitMs: Date.now() - start
|
|
142
|
+
};
|
|
143
|
+
new Reporter(rawOpts.output || 'text').emit(result);
|
|
144
|
+
|
|
145
|
+
if (!isSuccess(status)) {
|
|
146
|
+
throw new TaskFailedError(taskId, 'import', status);
|
|
147
|
+
}
|
|
148
|
+
if (rawOpts.strict && parsed.skippedCount > 0) {
|
|
149
|
+
const e = new CliError(
|
|
150
|
+
`--strict: import completed but ${parsed.skippedCount} rule(s) skipped. See log for details.`
|
|
151
|
+
);
|
|
152
|
+
e.exitCode = 1;
|
|
153
|
+
throw e;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
async function terminateActiveImport(client) {
|
|
158
|
+
const search = await client.post('/api/v1/taskruns/search', {
|
|
159
|
+
filter: [
|
|
160
|
+
{ attribute: 'type', operator: 'In', value: 'import-rules' },
|
|
161
|
+
{ attribute: 'type', operator: 'In', value: 'import-workflows' }
|
|
162
|
+
]
|
|
163
|
+
});
|
|
164
|
+
const active = (search?.items || search?.taskRuns || []).find((r) =>
|
|
165
|
+
['Submitted', 'Running'].includes(r.taskStatus || r.status)
|
|
166
|
+
);
|
|
167
|
+
if (!active) {
|
|
168
|
+
log.warn('No active import found to terminate');
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
const id = active.id || active.taskInstanceId;
|
|
172
|
+
log.info('Terminating active import', { taskId: id });
|
|
173
|
+
await client.post(`/api/v1/imports/${id}:terminate`, {});
|
|
174
|
+
}
|