carto-cli 0.1.0-rc.1
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/.nvmrc +1 -0
- package/ARCHITECTURE.md +497 -0
- package/CHANGELOG.md +28 -0
- package/LICENSE +15 -0
- package/MAP_JSON.md +516 -0
- package/README.md +1595 -0
- package/WORKFLOW_JSON.md +623 -0
- package/dist/api.js +489 -0
- package/dist/auth-oauth.js +485 -0
- package/dist/auth-server.js +432 -0
- package/dist/browser.js +30 -0
- package/dist/colors.js +45 -0
- package/dist/commands/activity.js +427 -0
- package/dist/commands/admin.js +177 -0
- package/dist/commands/ai.js +489 -0
- package/dist/commands/auth.js +652 -0
- package/dist/commands/connections.js +412 -0
- package/dist/commands/credentials.js +606 -0
- package/dist/commands/imports.js +234 -0
- package/dist/commands/maps.js +1022 -0
- package/dist/commands/org.js +195 -0
- package/dist/commands/sql.js +326 -0
- package/dist/commands/users.js +459 -0
- package/dist/commands/workflows.js +1025 -0
- package/dist/config.js +320 -0
- package/dist/download.js +108 -0
- package/dist/help.js +285 -0
- package/dist/http.js +139 -0
- package/dist/index.js +1133 -0
- package/dist/logo.js +11 -0
- package/dist/prompt.js +67 -0
- package/dist/schedule-parser.js +287 -0
- package/jest.config.ts +43 -0
- package/package.json +53 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,1133 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
+
}) : function(o, v) {
|
|
17
|
+
o["default"] = v;
|
|
18
|
+
});
|
|
19
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
20
|
+
var ownKeys = function(o) {
|
|
21
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
22
|
+
var ar = [];
|
|
23
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
24
|
+
return ar;
|
|
25
|
+
};
|
|
26
|
+
return ownKeys(o);
|
|
27
|
+
};
|
|
28
|
+
return function (mod) {
|
|
29
|
+
if (mod && mod.__esModule) return mod;
|
|
30
|
+
var result = {};
|
|
31
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
32
|
+
__setModuleDefault(result, mod);
|
|
33
|
+
return result;
|
|
34
|
+
};
|
|
35
|
+
})();
|
|
36
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
|
+
const help_1 = require("./help");
|
|
38
|
+
const workflows_1 = require("./commands/workflows");
|
|
39
|
+
const auth_1 = require("./commands/auth");
|
|
40
|
+
const credentials_1 = require("./commands/credentials");
|
|
41
|
+
const maps_1 = require("./commands/maps");
|
|
42
|
+
const connections_1 = require("./commands/connections");
|
|
43
|
+
const imports_1 = require("./commands/imports");
|
|
44
|
+
const admin_1 = require("./commands/admin");
|
|
45
|
+
const org_1 = require("./commands/org");
|
|
46
|
+
const activity_1 = require("./commands/activity");
|
|
47
|
+
const sql_1 = require("./commands/sql");
|
|
48
|
+
const users_1 = require("./commands/users");
|
|
49
|
+
const ai_1 = require("./commands/ai");
|
|
50
|
+
const colors_1 = require("./colors");
|
|
51
|
+
const config_1 = require("./config");
|
|
52
|
+
// Import package version
|
|
53
|
+
const packageJson = require('../package.json');
|
|
54
|
+
function parseArgs() {
|
|
55
|
+
const rawArgs = process.argv.slice(2);
|
|
56
|
+
const options = {
|
|
57
|
+
json: false,
|
|
58
|
+
debug: false,
|
|
59
|
+
};
|
|
60
|
+
const args = [];
|
|
61
|
+
let command = '';
|
|
62
|
+
let subcommand;
|
|
63
|
+
for (let i = 0; i < rawArgs.length; i++) {
|
|
64
|
+
const arg = rawArgs[i];
|
|
65
|
+
if (arg === '--json') {
|
|
66
|
+
options.json = true;
|
|
67
|
+
}
|
|
68
|
+
else if (arg === '--debug') {
|
|
69
|
+
options.debug = true;
|
|
70
|
+
}
|
|
71
|
+
else if (arg === '--yes' || arg === '-y') {
|
|
72
|
+
options.yes = true;
|
|
73
|
+
}
|
|
74
|
+
else if (arg === '--token' && i + 1 < rawArgs.length) {
|
|
75
|
+
options.token = rawArgs[++i];
|
|
76
|
+
}
|
|
77
|
+
else if (arg === '--base-url' && i + 1 < rawArgs.length) {
|
|
78
|
+
options.baseUrl = rawArgs[++i];
|
|
79
|
+
}
|
|
80
|
+
else if (arg === '--profile' && i + 1 < rawArgs.length) {
|
|
81
|
+
options.profile = rawArgs[++i];
|
|
82
|
+
}
|
|
83
|
+
else if (arg === '--env' && i + 1 < rawArgs.length) {
|
|
84
|
+
options.env = rawArgs[++i];
|
|
85
|
+
}
|
|
86
|
+
else if (arg === '--organization-name' && i + 1 < rawArgs.length) {
|
|
87
|
+
options.organizationName = rawArgs[++i];
|
|
88
|
+
}
|
|
89
|
+
else if (arg === '--organization-id' && i + 1 < rawArgs.length) {
|
|
90
|
+
options.organizationId = rawArgs[++i];
|
|
91
|
+
}
|
|
92
|
+
else if (arg === '--m2m') {
|
|
93
|
+
options.m2m = true;
|
|
94
|
+
}
|
|
95
|
+
else if (arg === '--client-id' && i + 1 < rawArgs.length) {
|
|
96
|
+
options.clientId = rawArgs[++i];
|
|
97
|
+
}
|
|
98
|
+
else if (arg === '--client-secret' && i + 1 < rawArgs.length) {
|
|
99
|
+
options.clientSecret = rawArgs[++i];
|
|
100
|
+
}
|
|
101
|
+
else if (arg === '--api-base-url' && i + 1 < rawArgs.length) {
|
|
102
|
+
options.apiBaseUrl = rawArgs[++i];
|
|
103
|
+
}
|
|
104
|
+
else if (arg === '--force' || arg === '-f') {
|
|
105
|
+
options.force = true;
|
|
106
|
+
}
|
|
107
|
+
else if (arg === '--model' && i + 1 < rawArgs.length) {
|
|
108
|
+
options.model = rawArgs[++i];
|
|
109
|
+
}
|
|
110
|
+
else if (arg === '--system' && i + 1 < rawArgs.length) {
|
|
111
|
+
options.system = rawArgs[++i];
|
|
112
|
+
}
|
|
113
|
+
else if (arg === '--temperature' && i + 1 < rawArgs.length) {
|
|
114
|
+
options.temperature = rawArgs[++i];
|
|
115
|
+
}
|
|
116
|
+
else if (arg === '--max-tokens' && i + 1 < rawArgs.length) {
|
|
117
|
+
options.maxTokens = rawArgs[++i];
|
|
118
|
+
}
|
|
119
|
+
else if (arg === '--top-p' && i + 1 < rawArgs.length) {
|
|
120
|
+
options.topP = rawArgs[++i];
|
|
121
|
+
}
|
|
122
|
+
else if (arg === '--conversation-id' && i + 1 < rawArgs.length) {
|
|
123
|
+
options.conversationId = rawArgs[++i];
|
|
124
|
+
}
|
|
125
|
+
else if (arg === '--file' && i + 1 < rawArgs.length) {
|
|
126
|
+
options.file = rawArgs[++i];
|
|
127
|
+
}
|
|
128
|
+
else if (arg === '--help' || arg === '-h') {
|
|
129
|
+
(0, help_1.showHelp)();
|
|
130
|
+
process.exit(0);
|
|
131
|
+
}
|
|
132
|
+
else if (arg === '--version' || arg === '-v') {
|
|
133
|
+
console.log(`v${packageJson.version}`);
|
|
134
|
+
process.exit(0);
|
|
135
|
+
}
|
|
136
|
+
else if (!command) {
|
|
137
|
+
command = arg;
|
|
138
|
+
}
|
|
139
|
+
else if (!subcommand) {
|
|
140
|
+
subcommand = arg;
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
args.push(arg);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return { command, subcommand, args, options };
|
|
147
|
+
}
|
|
148
|
+
async function main() {
|
|
149
|
+
const { command, subcommand, args, options } = parseArgs();
|
|
150
|
+
// Show help if no command
|
|
151
|
+
if (!command) {
|
|
152
|
+
(0, help_1.showHelp)();
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
try {
|
|
156
|
+
// Auth commands
|
|
157
|
+
if (command === 'auth') {
|
|
158
|
+
if (!subcommand) {
|
|
159
|
+
console.log((0, colors_1.error)('Error: auth command requires a subcommand (login, logout, status, use, whoami)'));
|
|
160
|
+
process.exit(1);
|
|
161
|
+
}
|
|
162
|
+
switch (subcommand) {
|
|
163
|
+
case 'login':
|
|
164
|
+
const loginProfile = args.length > 0 ? args[0] : options.profile;
|
|
165
|
+
const env = options.env || process.env.CARTO_AUTH_ENV;
|
|
166
|
+
// Route to M2M login if --m2m flag is present
|
|
167
|
+
if (options.m2m) {
|
|
168
|
+
await (0, auth_1.authLoginM2M)(loginProfile, options.json, env, options.clientId, options.clientSecret, options.apiBaseUrl, options.force);
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
await (0, auth_1.authLogin)(loginProfile, options.json, env, options.organizationName, options.organizationId);
|
|
172
|
+
}
|
|
173
|
+
break;
|
|
174
|
+
case 'logout':
|
|
175
|
+
const logoutProfile = args.length > 0 ? args[0] : options.profile;
|
|
176
|
+
await (0, auth_1.authLogout)(logoutProfile, options.json);
|
|
177
|
+
break;
|
|
178
|
+
case 'status':
|
|
179
|
+
const statusProfile = args.length > 0 ? args[0] : options.profile;
|
|
180
|
+
await (0, auth_1.authStatus)(statusProfile, options.json);
|
|
181
|
+
break;
|
|
182
|
+
case 'use':
|
|
183
|
+
if (args.length === 0) {
|
|
184
|
+
console.log((0, colors_1.error)('Error: auth use requires a profile name argument'));
|
|
185
|
+
process.exit(1);
|
|
186
|
+
}
|
|
187
|
+
await (0, auth_1.authUse)(args[0], options.json);
|
|
188
|
+
break;
|
|
189
|
+
case 'whoami':
|
|
190
|
+
await (0, auth_1.authWhoami)(options.token, options.baseUrl, options.json, options.debug, options.profile);
|
|
191
|
+
break;
|
|
192
|
+
default:
|
|
193
|
+
console.log((0, colors_1.error)(`Error: unknown auth subcommand: ${subcommand}`));
|
|
194
|
+
console.log((0, colors_1.error)('For API token and OAuth client management, use: carto credentials'));
|
|
195
|
+
process.exit(1);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
// Maps commands
|
|
199
|
+
else if (command === 'maps') {
|
|
200
|
+
if (!subcommand) {
|
|
201
|
+
console.log((0, colors_1.error)('Error: maps command requires a subcommand (list, get, create, update, delete, copy)'));
|
|
202
|
+
process.exit(1);
|
|
203
|
+
}
|
|
204
|
+
switch (subcommand) {
|
|
205
|
+
case 'list':
|
|
206
|
+
const mapsOptions = {};
|
|
207
|
+
for (let i = 0; i < args.length; i++) {
|
|
208
|
+
if (args[i] === '--all') {
|
|
209
|
+
mapsOptions.all = true;
|
|
210
|
+
}
|
|
211
|
+
else if (args[i] === '--mine') {
|
|
212
|
+
mapsOptions.mine = true;
|
|
213
|
+
}
|
|
214
|
+
else if (args[i].startsWith('--')) {
|
|
215
|
+
const key = args[i].replace(/^--/, '');
|
|
216
|
+
const value = args[i + 1];
|
|
217
|
+
mapsOptions[key] = value;
|
|
218
|
+
i++; // Skip the value in next iteration
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
await (0, maps_1.mapsList)(mapsOptions, options.token, options.baseUrl, options.json, options.debug, options.profile);
|
|
222
|
+
break;
|
|
223
|
+
case 'get':
|
|
224
|
+
if (args.length === 0) {
|
|
225
|
+
console.log((0, colors_1.error)('Error: maps get requires a map ID argument'));
|
|
226
|
+
process.exit(1);
|
|
227
|
+
}
|
|
228
|
+
await (0, maps_1.mapsGet)(args[0], options.token, options.baseUrl, options.json, options.debug, options.profile);
|
|
229
|
+
break;
|
|
230
|
+
case 'delete':
|
|
231
|
+
if (args.length === 0) {
|
|
232
|
+
console.log((0, colors_1.error)('Error: maps delete requires a map ID argument'));
|
|
233
|
+
process.exit(1);
|
|
234
|
+
}
|
|
235
|
+
await (0, maps_1.mapsDelete)(args[0], options.token, options.baseUrl, options.json, options.debug, options.profile, options.yes);
|
|
236
|
+
break;
|
|
237
|
+
case 'copy':
|
|
238
|
+
if (args.length === 0) {
|
|
239
|
+
console.log((0, colors_1.error)('Error: maps copy requires a map ID argument'));
|
|
240
|
+
process.exit(1);
|
|
241
|
+
}
|
|
242
|
+
const mapId = args[0];
|
|
243
|
+
const copyOptions = {};
|
|
244
|
+
let connectionName;
|
|
245
|
+
let sourceProfile;
|
|
246
|
+
let destProfile;
|
|
247
|
+
for (let i = 1; i < args.length; i++) {
|
|
248
|
+
if (args[i] === '--connection' && i + 1 < args.length) {
|
|
249
|
+
connectionName = args[++i];
|
|
250
|
+
}
|
|
251
|
+
else if (args[i] === '--connection-mapping' && i + 1 < args.length) {
|
|
252
|
+
copyOptions.connectionMapping = args[++i];
|
|
253
|
+
}
|
|
254
|
+
else if (args[i] === '--source-profile' && i + 1 < args.length) {
|
|
255
|
+
sourceProfile = args[++i];
|
|
256
|
+
}
|
|
257
|
+
else if (args[i] === '--dest-profile' && i + 1 < args.length) {
|
|
258
|
+
destProfile = args[++i];
|
|
259
|
+
}
|
|
260
|
+
else if (args[i] === '--title' && i + 1 < args.length) {
|
|
261
|
+
copyOptions.title = args[++i];
|
|
262
|
+
}
|
|
263
|
+
else if (args[i] === '--keep-privacy') {
|
|
264
|
+
copyOptions.keepPrivacy = true;
|
|
265
|
+
}
|
|
266
|
+
else if (args[i] === '--skip-source-validation') {
|
|
267
|
+
copyOptions.skipSourceValidation = true;
|
|
268
|
+
}
|
|
269
|
+
else if (args[i] === '--skip-agent') {
|
|
270
|
+
copyOptions.skipAgent = true;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
if (!destProfile) {
|
|
274
|
+
console.log((0, colors_1.error)('Error: maps copy requires --dest-profile <name>'));
|
|
275
|
+
process.exit(1);
|
|
276
|
+
}
|
|
277
|
+
// Default source profile to current profile if not specified
|
|
278
|
+
sourceProfile = sourceProfile || options.profile || (0, config_1.getCurrentProfile)();
|
|
279
|
+
await (0, maps_1.mapsCopy)(mapId, connectionName, sourceProfile, destProfile, copyOptions, options.token, options.baseUrl, options.json, options.debug);
|
|
280
|
+
break;
|
|
281
|
+
case 'create':
|
|
282
|
+
// Parse --file flag
|
|
283
|
+
const createOptions = {};
|
|
284
|
+
for (let i = 0; i < args.length; i++) {
|
|
285
|
+
if (args[i] === '--file' && i + 1 < args.length) {
|
|
286
|
+
createOptions.file = args[++i];
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
// First non-flag arg is the JSON string (if not using --file)
|
|
290
|
+
const createJson = args.find(arg => !arg.startsWith('--') && arg !== createOptions.file);
|
|
291
|
+
await (0, maps_1.mapsCreate)(createJson, createOptions, options.token, options.baseUrl, options.json, options.debug, options.profile);
|
|
292
|
+
break;
|
|
293
|
+
case 'update':
|
|
294
|
+
if (args.length === 0) {
|
|
295
|
+
console.log((0, colors_1.error)('Error: maps update requires a map ID argument'));
|
|
296
|
+
process.exit(1);
|
|
297
|
+
}
|
|
298
|
+
const updateMapId = args[0];
|
|
299
|
+
const updateOptions = {};
|
|
300
|
+
// Parse --file flag
|
|
301
|
+
for (let i = 1; i < args.length; i++) {
|
|
302
|
+
if (args[i] === '--file' && i + 1 < args.length) {
|
|
303
|
+
updateOptions.file = args[++i];
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
// Second arg (after map ID) is the JSON string (if not using --file)
|
|
307
|
+
const updateJson = args.slice(1).find(arg => !arg.startsWith('--') && arg !== updateOptions.file);
|
|
308
|
+
await (0, maps_1.mapsUpdate)(updateMapId, updateJson, updateOptions, options.token, options.baseUrl, options.json, options.debug, options.profile);
|
|
309
|
+
break;
|
|
310
|
+
case 'clone':
|
|
311
|
+
const cloneOptions = {};
|
|
312
|
+
const otherArgs = [];
|
|
313
|
+
for (let i = 0; i < args.length; i++) {
|
|
314
|
+
if (args[i] === '--title' && i + 1 < args.length) {
|
|
315
|
+
cloneOptions.title = args[++i];
|
|
316
|
+
}
|
|
317
|
+
else {
|
|
318
|
+
otherArgs.push(args[i]);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
const cloneMapId = otherArgs.find(arg => !arg.startsWith('--'));
|
|
322
|
+
if (!cloneMapId) {
|
|
323
|
+
console.log((0, colors_1.error)('Error: maps clone requires a map ID argument'));
|
|
324
|
+
process.exit(1);
|
|
325
|
+
}
|
|
326
|
+
await (0, maps_1.mapsClone)(cloneMapId, cloneOptions, options.token, options.baseUrl, options.json, options.debug, options.profile);
|
|
327
|
+
break;
|
|
328
|
+
default:
|
|
329
|
+
console.log((0, colors_1.error)(`Error: unknown maps subcommand: ${subcommand}`));
|
|
330
|
+
process.exit(1);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
// Workflows commands
|
|
334
|
+
else if (command === 'workflows') {
|
|
335
|
+
if (!subcommand) {
|
|
336
|
+
console.log((0, colors_1.error)('Error: workflows command requires a subcommand (list, get, create, update, delete, copy, extensions, schedule)'));
|
|
337
|
+
process.exit(1);
|
|
338
|
+
}
|
|
339
|
+
switch (subcommand) {
|
|
340
|
+
case 'list':
|
|
341
|
+
const workflowsOptions = {};
|
|
342
|
+
for (let i = 0; i < args.length; i++) {
|
|
343
|
+
if (args[i] === '--all') {
|
|
344
|
+
workflowsOptions.all = true;
|
|
345
|
+
}
|
|
346
|
+
else if (args[i].startsWith('--')) {
|
|
347
|
+
const key = args[i].replace(/^--/, '');
|
|
348
|
+
const value = args[i + 1];
|
|
349
|
+
workflowsOptions[key] = value;
|
|
350
|
+
i++; // Skip the value in next iteration
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
await (0, workflows_1.workflowsList)(workflowsOptions, options.token, options.baseUrl, options.json, options.debug, options.profile);
|
|
354
|
+
break;
|
|
355
|
+
case 'get':
|
|
356
|
+
if (args.length === 0) {
|
|
357
|
+
console.log((0, colors_1.error)('Error: workflows get requires a workflow ID argument'));
|
|
358
|
+
process.exit(1);
|
|
359
|
+
}
|
|
360
|
+
const getOptions = {};
|
|
361
|
+
for (let i = 1; i < args.length; i += 2) {
|
|
362
|
+
const key = args[i].replace(/^--/, '');
|
|
363
|
+
const value = args[i + 1];
|
|
364
|
+
getOptions[key] = value;
|
|
365
|
+
}
|
|
366
|
+
await (0, workflows_1.workflowsGet)(args[0], getOptions, options.token, options.baseUrl, options.json, options.debug);
|
|
367
|
+
break;
|
|
368
|
+
case 'create':
|
|
369
|
+
// Parse --file flag
|
|
370
|
+
const createOptions = {};
|
|
371
|
+
for (let i = 0; i < args.length; i++) {
|
|
372
|
+
if (args[i] === '--file' && i + 1 < args.length) {
|
|
373
|
+
createOptions.file = args[++i];
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
// First non-flag arg is the JSON string (if not using --file)
|
|
377
|
+
const createJson = args.find(arg => !arg.startsWith('--') && arg !== createOptions.file);
|
|
378
|
+
await (0, workflows_1.workflowsCreate)(createJson, createOptions, options.token, options.baseUrl, options.json, options.debug);
|
|
379
|
+
break;
|
|
380
|
+
case 'update':
|
|
381
|
+
if (args.length === 0) {
|
|
382
|
+
console.log((0, colors_1.error)('Error: workflows update requires a workflow ID argument'));
|
|
383
|
+
process.exit(1);
|
|
384
|
+
}
|
|
385
|
+
const updateWorkflowId = args[0];
|
|
386
|
+
const updateOptions = {};
|
|
387
|
+
// Parse --file flag
|
|
388
|
+
for (let i = 1; i < args.length; i++) {
|
|
389
|
+
if (args[i] === '--file' && i + 1 < args.length) {
|
|
390
|
+
updateOptions.file = args[++i];
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
// Second arg (after workflow ID) is the JSON string (if not using --file)
|
|
394
|
+
const updateJson = args.slice(1).find(arg => !arg.startsWith('--') && arg !== updateOptions.file);
|
|
395
|
+
await (0, workflows_1.workflowsUpdate)(updateWorkflowId, updateJson, updateOptions, options.token, options.baseUrl, options.json, options.debug);
|
|
396
|
+
break;
|
|
397
|
+
case 'delete':
|
|
398
|
+
if (args.length === 0) {
|
|
399
|
+
console.log((0, colors_1.error)('Error: workflows delete requires a workflow ID argument'));
|
|
400
|
+
process.exit(1);
|
|
401
|
+
}
|
|
402
|
+
await (0, workflows_1.workflowsDelete)(args[0], options.token, options.baseUrl, options.json, options.debug, options.profile, options.yes);
|
|
403
|
+
break;
|
|
404
|
+
case 'copy':
|
|
405
|
+
if (args.length === 0) {
|
|
406
|
+
console.log((0, colors_1.error)('Error: workflows copy requires a workflow ID argument'));
|
|
407
|
+
process.exit(1);
|
|
408
|
+
}
|
|
409
|
+
const workflowId = args[0];
|
|
410
|
+
const copyOptions = {};
|
|
411
|
+
let copyConnectionName;
|
|
412
|
+
let copySourceProfile;
|
|
413
|
+
let copyDestProfile;
|
|
414
|
+
for (let i = 1; i < args.length; i++) {
|
|
415
|
+
if (args[i] === '--connection' && i + 1 < args.length) {
|
|
416
|
+
copyConnectionName = args[++i];
|
|
417
|
+
}
|
|
418
|
+
else if (args[i] === '--source-profile' && i + 1 < args.length) {
|
|
419
|
+
copySourceProfile = args[++i];
|
|
420
|
+
}
|
|
421
|
+
else if (args[i] === '--dest-profile' && i + 1 < args.length) {
|
|
422
|
+
copyDestProfile = args[++i];
|
|
423
|
+
}
|
|
424
|
+
else if (args[i] === '--title' && i + 1 < args.length) {
|
|
425
|
+
copyOptions.title = args[++i];
|
|
426
|
+
}
|
|
427
|
+
else if (args[i] === '--skip-source-validation') {
|
|
428
|
+
copyOptions.skipSourceValidation = true;
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
if (!copyDestProfile) {
|
|
432
|
+
console.log((0, colors_1.error)('Error: workflows copy requires --dest-profile <name>'));
|
|
433
|
+
process.exit(1);
|
|
434
|
+
}
|
|
435
|
+
// Default source profile to current profile if not specified
|
|
436
|
+
copySourceProfile = copySourceProfile || options.profile || (0, config_1.getCurrentProfile)();
|
|
437
|
+
await (0, workflows_1.workflowsCopy)(workflowId, copyConnectionName, copySourceProfile, copyDestProfile, copyOptions, options.token, options.baseUrl, options.json, options.debug);
|
|
438
|
+
break;
|
|
439
|
+
case 'extensions':
|
|
440
|
+
// Handle extensions subcommands
|
|
441
|
+
if (args.length === 0) {
|
|
442
|
+
console.log((0, colors_1.error)('Error: workflows extensions requires a subcommand (install)'));
|
|
443
|
+
process.exit(1);
|
|
444
|
+
}
|
|
445
|
+
const extensionSubcommand = args[0];
|
|
446
|
+
if (extensionSubcommand === 'install') {
|
|
447
|
+
let extensionFile;
|
|
448
|
+
let connectionName;
|
|
449
|
+
// Parse --file and --connection flags
|
|
450
|
+
for (let i = 1; i < args.length; i++) {
|
|
451
|
+
if (args[i] === '--file' && i + 1 < args.length) {
|
|
452
|
+
extensionFile = args[++i];
|
|
453
|
+
}
|
|
454
|
+
else if (args[i] === '--connection' && i + 1 < args.length) {
|
|
455
|
+
connectionName = args[++i];
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
if (!extensionFile) {
|
|
459
|
+
console.log((0, colors_1.error)('Error: workflows extensions install requires --file <path>'));
|
|
460
|
+
process.exit(1);
|
|
461
|
+
}
|
|
462
|
+
if (!connectionName) {
|
|
463
|
+
console.log((0, colors_1.error)('Error: workflows extensions install requires --connection <name>'));
|
|
464
|
+
process.exit(1);
|
|
465
|
+
}
|
|
466
|
+
await (0, workflows_1.workflowsExtensionsInstall)(extensionFile, connectionName, options.token, options.baseUrl, options.json, options.debug, options.profile);
|
|
467
|
+
}
|
|
468
|
+
else {
|
|
469
|
+
console.log((0, colors_1.error)(`Error: unknown workflows extensions subcommand: ${extensionSubcommand}`));
|
|
470
|
+
process.exit(1);
|
|
471
|
+
}
|
|
472
|
+
break;
|
|
473
|
+
case 'schedule':
|
|
474
|
+
// Handle schedule subcommands
|
|
475
|
+
if (args.length === 0) {
|
|
476
|
+
console.log((0, colors_1.error)('Error: workflows schedule requires a subcommand (add, update, remove)'));
|
|
477
|
+
process.exit(1);
|
|
478
|
+
}
|
|
479
|
+
const scheduleSubcommand = args[0];
|
|
480
|
+
if (scheduleSubcommand === 'add') {
|
|
481
|
+
if (args.length < 2) {
|
|
482
|
+
console.log((0, colors_1.error)('Error: workflows schedule add requires workflow ID'));
|
|
483
|
+
console.log('Usage: carto workflows schedule add <workflow-id> --expression "<expr>"');
|
|
484
|
+
process.exit(1);
|
|
485
|
+
}
|
|
486
|
+
const workflowIdAdd = args[1];
|
|
487
|
+
const addOptions = {};
|
|
488
|
+
for (let i = 2; i < args.length; i++) {
|
|
489
|
+
if (args[i] === '--expression' && i + 1 < args.length) {
|
|
490
|
+
addOptions.expression = args[++i];
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
await (0, workflows_1.workflowScheduleAdd)(workflowIdAdd, addOptions, options.token, options.baseUrl, options.json, options.debug, options.profile);
|
|
494
|
+
}
|
|
495
|
+
else if (scheduleSubcommand === 'update') {
|
|
496
|
+
if (args.length < 2) {
|
|
497
|
+
console.log((0, colors_1.error)('Error: workflows schedule update requires workflow ID'));
|
|
498
|
+
console.log('Usage: carto workflows schedule update <workflow-id> --expression "<expr>"');
|
|
499
|
+
process.exit(1);
|
|
500
|
+
}
|
|
501
|
+
const workflowIdUpdate = args[1];
|
|
502
|
+
const updateScheduleOptions = {};
|
|
503
|
+
for (let i = 2; i < args.length; i++) {
|
|
504
|
+
if (args[i] === '--expression' && i + 1 < args.length) {
|
|
505
|
+
updateScheduleOptions.expression = args[++i];
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
await (0, workflows_1.workflowScheduleUpdate)(workflowIdUpdate, updateScheduleOptions, options.token, options.baseUrl, options.json, options.debug, options.profile);
|
|
509
|
+
}
|
|
510
|
+
else if (scheduleSubcommand === 'remove') {
|
|
511
|
+
if (args.length < 2) {
|
|
512
|
+
console.log((0, colors_1.error)('Error: workflows schedule remove requires workflow ID'));
|
|
513
|
+
console.log('Usage: carto workflows schedule remove <workflow-id>');
|
|
514
|
+
process.exit(1);
|
|
515
|
+
}
|
|
516
|
+
const workflowIdRemove = args[1];
|
|
517
|
+
const removeOptions = {};
|
|
518
|
+
await (0, workflows_1.workflowScheduleRemove)(workflowIdRemove, removeOptions, options.token, options.baseUrl, options.json, options.debug, options.profile);
|
|
519
|
+
}
|
|
520
|
+
else {
|
|
521
|
+
console.log((0, colors_1.error)(`Error: unknown workflows schedule subcommand: ${scheduleSubcommand}`));
|
|
522
|
+
process.exit(1);
|
|
523
|
+
}
|
|
524
|
+
break;
|
|
525
|
+
default:
|
|
526
|
+
console.log((0, colors_1.error)(`Error: unknown workflows subcommand: ${subcommand}`));
|
|
527
|
+
process.exit(1);
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
// Connections commands
|
|
531
|
+
else if (command === 'connections') {
|
|
532
|
+
if (!subcommand) {
|
|
533
|
+
console.log((0, colors_1.error)('Error: connections command requires a subcommand (list, get, create, update, delete, browse, describe)'));
|
|
534
|
+
process.exit(1);
|
|
535
|
+
}
|
|
536
|
+
switch (subcommand) {
|
|
537
|
+
case 'list':
|
|
538
|
+
const connectionsOptions = {};
|
|
539
|
+
for (let i = 0; i < args.length; i++) {
|
|
540
|
+
if (args[i] === '--all') {
|
|
541
|
+
connectionsOptions.all = true;
|
|
542
|
+
}
|
|
543
|
+
else if (args[i].startsWith('--')) {
|
|
544
|
+
const key = args[i].replace(/^--/, '');
|
|
545
|
+
const value = args[i + 1];
|
|
546
|
+
connectionsOptions[key] = value;
|
|
547
|
+
i++; // Skip the value in next iteration
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
await (0, connections_1.connectionsList)(connectionsOptions, options.token, options.baseUrl, options.json, options.debug, options.profile);
|
|
551
|
+
break;
|
|
552
|
+
case 'get':
|
|
553
|
+
if (args.length === 0) {
|
|
554
|
+
console.log((0, colors_1.error)('Error: connections get requires a connection ID argument'));
|
|
555
|
+
process.exit(1);
|
|
556
|
+
}
|
|
557
|
+
await (0, connections_1.connectionsGet)(args[0], options.token, options.baseUrl, options.json, options.debug, options.profile);
|
|
558
|
+
break;
|
|
559
|
+
case 'browse':
|
|
560
|
+
if (args.length === 0) {
|
|
561
|
+
console.log((0, colors_1.error)('Error: connections browse requires a connection name argument'));
|
|
562
|
+
process.exit(1);
|
|
563
|
+
}
|
|
564
|
+
const connectionName = args[0];
|
|
565
|
+
const resourcePath = args.length > 1 ? args[1] : undefined;
|
|
566
|
+
const browseOptions = {};
|
|
567
|
+
// Parse pagination options
|
|
568
|
+
for (let i = 2; i < args.length; i++) {
|
|
569
|
+
if (args[i].startsWith('--')) {
|
|
570
|
+
const key = args[i].replace(/^--/, '');
|
|
571
|
+
const value = args[i + 1];
|
|
572
|
+
browseOptions[key] = value;
|
|
573
|
+
i++; // Skip the value in next iteration
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
await (0, connections_1.connectionsBrowse)(connectionName, resourcePath, browseOptions, options.token, options.baseUrl, options.json, options.debug, options.profile);
|
|
577
|
+
break;
|
|
578
|
+
case 'describe':
|
|
579
|
+
if (args.length < 2) {
|
|
580
|
+
console.log((0, colors_1.error)('Error: connections describe requires connection name and table path'));
|
|
581
|
+
console.log('Usage: carto connections describe <connection-name> <table-path>');
|
|
582
|
+
console.log('Example: carto connections describe carto_dw "carto-demo-data.demo_tables.nyc_collisions"');
|
|
583
|
+
process.exit(1);
|
|
584
|
+
}
|
|
585
|
+
await (0, connections_1.connectionsDescribe)(args[0], // connection name
|
|
586
|
+
args[1], // table path
|
|
587
|
+
options.token, options.baseUrl, options.json, options.debug, options.profile);
|
|
588
|
+
break;
|
|
589
|
+
case 'create':
|
|
590
|
+
if (args.length === 0) {
|
|
591
|
+
console.log((0, colors_1.error)('Error: connections create requires JSON body as argument'));
|
|
592
|
+
process.exit(1);
|
|
593
|
+
}
|
|
594
|
+
const createConnBody = JSON.parse(args[0]);
|
|
595
|
+
await (0, connections_1.connectionsCreate)(createConnBody, options.token, options.baseUrl, options.json, options.debug, options.profile);
|
|
596
|
+
break;
|
|
597
|
+
case 'update':
|
|
598
|
+
if (args.length < 2) {
|
|
599
|
+
console.log((0, colors_1.error)('Error: connections update requires connection ID and JSON body as arguments'));
|
|
600
|
+
process.exit(1);
|
|
601
|
+
}
|
|
602
|
+
const updateConnBody = JSON.parse(args[1]);
|
|
603
|
+
await (0, connections_1.connectionsUpdate)(args[0], updateConnBody, options.token, options.baseUrl, options.json, options.debug, options.profile);
|
|
604
|
+
break;
|
|
605
|
+
case 'delete':
|
|
606
|
+
if (args.length === 0) {
|
|
607
|
+
console.log((0, colors_1.error)('Error: connections delete requires a connection ID argument'));
|
|
608
|
+
process.exit(1);
|
|
609
|
+
}
|
|
610
|
+
await (0, connections_1.connectionsDelete)(args[0], options.token, options.baseUrl, options.json, options.debug, options.profile, options.yes);
|
|
611
|
+
break;
|
|
612
|
+
default:
|
|
613
|
+
console.log((0, colors_1.error)(`Error: unknown connections subcommand: ${subcommand}`));
|
|
614
|
+
process.exit(1);
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
// Imports commands
|
|
618
|
+
else if (command === 'imports') {
|
|
619
|
+
if (!subcommand) {
|
|
620
|
+
console.log((0, colors_1.error)('Error: imports command requires a subcommand (create)'));
|
|
621
|
+
process.exit(1);
|
|
622
|
+
}
|
|
623
|
+
switch (subcommand) {
|
|
624
|
+
case 'create':
|
|
625
|
+
const importsOptions = {};
|
|
626
|
+
for (let i = 0; i < args.length; i++) {
|
|
627
|
+
if (args[i] === '--async') {
|
|
628
|
+
importsOptions.async = true;
|
|
629
|
+
}
|
|
630
|
+
else if (args[i] === '--overwrite') {
|
|
631
|
+
importsOptions.overwrite = true;
|
|
632
|
+
}
|
|
633
|
+
else if (args[i] === '--no-autoguessing') {
|
|
634
|
+
importsOptions.noAutoguessing = true;
|
|
635
|
+
}
|
|
636
|
+
else if (args[i].startsWith('--')) {
|
|
637
|
+
const key = args[i].replace(/^--/, '');
|
|
638
|
+
if (i + 1 < args.length && !args[i + 1].startsWith('--')) {
|
|
639
|
+
const value = args[i + 1];
|
|
640
|
+
importsOptions[key] = value;
|
|
641
|
+
i++; // Skip the value in next iteration
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
await (0, imports_1.importsCreate)(importsOptions, options.token, options.baseUrl, options.json, options.debug, options.profile);
|
|
646
|
+
break;
|
|
647
|
+
default:
|
|
648
|
+
console.log((0, colors_1.error)(`Error: unknown imports subcommand: ${subcommand}`));
|
|
649
|
+
process.exit(1);
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
// Admin commands
|
|
653
|
+
else if (command === 'admin') {
|
|
654
|
+
if (!subcommand) {
|
|
655
|
+
console.log((0, colors_1.error)('Error: admin command requires a subcommand (list, batch-delete, transfer)'));
|
|
656
|
+
process.exit(1);
|
|
657
|
+
}
|
|
658
|
+
switch (subcommand) {
|
|
659
|
+
case 'list':
|
|
660
|
+
if (args.length === 0) {
|
|
661
|
+
console.log((0, colors_1.error)('Error: admin list requires a resource type argument (maps, workflows, connections)'));
|
|
662
|
+
process.exit(1);
|
|
663
|
+
}
|
|
664
|
+
const adminOptions = {};
|
|
665
|
+
for (let i = 1; i < args.length; i++) {
|
|
666
|
+
if (args[i] === '--all') {
|
|
667
|
+
adminOptions.all = true;
|
|
668
|
+
}
|
|
669
|
+
else if (args[i].startsWith('--')) {
|
|
670
|
+
const key = args[i].replace(/^--/, '');
|
|
671
|
+
const value = args[i + 1];
|
|
672
|
+
adminOptions[key] = value;
|
|
673
|
+
i++; // Skip the value in next iteration
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
await (0, admin_1.adminList)(args[0], adminOptions, options.token, options.baseUrl, options.json, options.debug, options.profile);
|
|
677
|
+
break;
|
|
678
|
+
case 'batch-delete':
|
|
679
|
+
if (args.length === 0) {
|
|
680
|
+
console.log((0, colors_1.error)('Error: admin batch-delete requires JSON body as argument'));
|
|
681
|
+
process.exit(1);
|
|
682
|
+
}
|
|
683
|
+
const batchDeleteBody = JSON.parse(args[0]);
|
|
684
|
+
await (0, admin_1.adminBatchDelete)(batchDeleteBody, options.token, options.baseUrl, options.json, options.debug, options.profile, options.yes);
|
|
685
|
+
break;
|
|
686
|
+
case 'transfer':
|
|
687
|
+
if (args.length === 0) {
|
|
688
|
+
console.log((0, colors_1.error)('Error: admin transfer requires JSON body as argument'));
|
|
689
|
+
process.exit(1);
|
|
690
|
+
}
|
|
691
|
+
const transferBody = JSON.parse(args[0]);
|
|
692
|
+
await (0, admin_1.adminTransfer)(transferBody, options.token, options.baseUrl, options.json, options.debug, options.profile);
|
|
693
|
+
break;
|
|
694
|
+
default:
|
|
695
|
+
console.log((0, colors_1.error)(`Error: unknown admin subcommand: ${subcommand}`));
|
|
696
|
+
process.exit(1);
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
// Organization commands
|
|
700
|
+
else if (command === 'org') {
|
|
701
|
+
if (!subcommand) {
|
|
702
|
+
console.log((0, colors_1.error)('Error: org command requires a subcommand (stats)'));
|
|
703
|
+
process.exit(1);
|
|
704
|
+
}
|
|
705
|
+
switch (subcommand) {
|
|
706
|
+
case 'stats':
|
|
707
|
+
await (0, org_1.orgStats)(options.token, options.baseUrl, options.json, options.debug, options.profile);
|
|
708
|
+
break;
|
|
709
|
+
default:
|
|
710
|
+
console.log((0, colors_1.error)(`Error: unknown org subcommand: ${subcommand}`));
|
|
711
|
+
process.exit(1);
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
// SQL commands
|
|
715
|
+
else if (command === 'sql') {
|
|
716
|
+
if (!subcommand) {
|
|
717
|
+
console.log((0, colors_1.error)('Error: sql command requires a subcommand (query, job)'));
|
|
718
|
+
process.exit(1);
|
|
719
|
+
}
|
|
720
|
+
switch (subcommand) {
|
|
721
|
+
case 'query':
|
|
722
|
+
if (args.length === 0) {
|
|
723
|
+
console.log((0, colors_1.error)('Error: sql query requires a connection name argument'));
|
|
724
|
+
process.exit(1);
|
|
725
|
+
}
|
|
726
|
+
const queryConnection = args[0];
|
|
727
|
+
let querySql;
|
|
728
|
+
const queryOptions = {};
|
|
729
|
+
// Parse options and SQL
|
|
730
|
+
for (let i = 1; i < args.length; i++) {
|
|
731
|
+
if (args[i] === '--cache') {
|
|
732
|
+
queryOptions.cache = true;
|
|
733
|
+
}
|
|
734
|
+
else if (args[i] === '--file' && i + 1 < args.length) {
|
|
735
|
+
queryOptions.file = args[++i];
|
|
736
|
+
}
|
|
737
|
+
else if (!querySql && !args[i].startsWith('--')) {
|
|
738
|
+
// First non-flag argument after connection is the SQL
|
|
739
|
+
querySql = args[i];
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
await (0, sql_1.sqlQuery)(queryConnection, querySql, queryOptions, options.token, options.baseUrl, options.json, options.debug, options.profile);
|
|
743
|
+
break;
|
|
744
|
+
case 'job':
|
|
745
|
+
if (args.length === 0) {
|
|
746
|
+
console.log((0, colors_1.error)('Error: sql job requires a connection name or subcommand (status, cancel)'));
|
|
747
|
+
process.exit(1);
|
|
748
|
+
}
|
|
749
|
+
// Check if first arg is a subcommand (status, cancel)
|
|
750
|
+
if (args[0] === 'status') {
|
|
751
|
+
if (args.length < 3) {
|
|
752
|
+
console.log((0, colors_1.error)('Error: sql job status requires connection name and job ID'));
|
|
753
|
+
process.exit(1);
|
|
754
|
+
}
|
|
755
|
+
const { sqlJobStatus } = await Promise.resolve().then(() => __importStar(require('./commands/sql')));
|
|
756
|
+
await sqlJobStatus(args[1], // connection
|
|
757
|
+
args[2], // job ID
|
|
758
|
+
options.token, options.baseUrl, options.json, options.debug, options.profile);
|
|
759
|
+
break;
|
|
760
|
+
}
|
|
761
|
+
if (args[0] === 'cancel') {
|
|
762
|
+
if (args.length < 3) {
|
|
763
|
+
console.log((0, colors_1.error)('Error: sql job cancel requires connection name and job ID'));
|
|
764
|
+
process.exit(1);
|
|
765
|
+
}
|
|
766
|
+
const { sqlJobCancel } = await Promise.resolve().then(() => __importStar(require('./commands/sql')));
|
|
767
|
+
await sqlJobCancel(args[1], // connection
|
|
768
|
+
args[2], // job ID
|
|
769
|
+
options.token, options.baseUrl, options.json, options.debug, options.profile);
|
|
770
|
+
break;
|
|
771
|
+
}
|
|
772
|
+
// Otherwise, it's a job creation command
|
|
773
|
+
const jobConnection = args[0];
|
|
774
|
+
let jobSql;
|
|
775
|
+
const jobOptions = {};
|
|
776
|
+
// Parse options and SQL
|
|
777
|
+
for (let i = 1; i < args.length; i++) {
|
|
778
|
+
if (args[i] === '--file' && i + 1 < args.length) {
|
|
779
|
+
jobOptions.file = args[++i];
|
|
780
|
+
}
|
|
781
|
+
else if (args[i] === '--no-wait') {
|
|
782
|
+
jobOptions.noWait = true;
|
|
783
|
+
}
|
|
784
|
+
else if (!jobSql && !args[i].startsWith('--')) {
|
|
785
|
+
// First non-flag argument after connection is the SQL
|
|
786
|
+
jobSql = args[i];
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
await (0, sql_1.sqlJob)(jobConnection, jobSql, jobOptions, options.token, options.baseUrl, options.json, options.debug, options.profile);
|
|
790
|
+
break;
|
|
791
|
+
default:
|
|
792
|
+
console.log((0, colors_1.error)(`Error: unknown sql subcommand: ${subcommand}`));
|
|
793
|
+
process.exit(1);
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
// Activity commands
|
|
797
|
+
else if (command === 'activity') {
|
|
798
|
+
if (!subcommand) {
|
|
799
|
+
console.log((0, colors_1.error)('Error: activity command requires a subcommand (export, query)'));
|
|
800
|
+
process.exit(1);
|
|
801
|
+
}
|
|
802
|
+
switch (subcommand) {
|
|
803
|
+
case 'export':
|
|
804
|
+
const activityOptions = {
|
|
805
|
+
outputDir: './activity-data'
|
|
806
|
+
};
|
|
807
|
+
for (let i = 0; i < args.length; i++) {
|
|
808
|
+
if (args[i].startsWith('--')) {
|
|
809
|
+
const key = args[i].replace(/^--/, '');
|
|
810
|
+
const value = args[i + 1];
|
|
811
|
+
if (key === 'start-date') {
|
|
812
|
+
activityOptions.startDate = value;
|
|
813
|
+
i++;
|
|
814
|
+
}
|
|
815
|
+
else if (key === 'end-date') {
|
|
816
|
+
activityOptions.endDate = value;
|
|
817
|
+
i++;
|
|
818
|
+
}
|
|
819
|
+
else if (key === 'format') {
|
|
820
|
+
activityOptions.format = value;
|
|
821
|
+
i++;
|
|
822
|
+
}
|
|
823
|
+
else if (key === 'category') {
|
|
824
|
+
activityOptions.category = value;
|
|
825
|
+
i++;
|
|
826
|
+
}
|
|
827
|
+
else if (key === 'output-dir') {
|
|
828
|
+
activityOptions.outputDir = value;
|
|
829
|
+
i++;
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
await (0, activity_1.activityExport)(activityOptions, options.token, options.baseUrl, options.json, options.debug, options.profile);
|
|
834
|
+
break;
|
|
835
|
+
case 'query':
|
|
836
|
+
const activityQueryOptions = {
|
|
837
|
+
noCache: false
|
|
838
|
+
};
|
|
839
|
+
for (let i = 0; i < args.length; i++) {
|
|
840
|
+
if (args[i] === '--no-cache') {
|
|
841
|
+
activityQueryOptions.noCache = true;
|
|
842
|
+
}
|
|
843
|
+
else if (args[i].startsWith('--')) {
|
|
844
|
+
const key = args[i].replace(/^--/, '');
|
|
845
|
+
const value = args[i + 1];
|
|
846
|
+
if (key === 'start-date') {
|
|
847
|
+
activityQueryOptions.startDate = value;
|
|
848
|
+
i++;
|
|
849
|
+
}
|
|
850
|
+
else if (key === 'end-date') {
|
|
851
|
+
activityQueryOptions.endDate = value;
|
|
852
|
+
i++;
|
|
853
|
+
}
|
|
854
|
+
else if (key === 'sql') {
|
|
855
|
+
activityQueryOptions.sql = value;
|
|
856
|
+
i++;
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
}
|
|
860
|
+
await (0, activity_1.activityQuery)(activityQueryOptions, options.token, options.baseUrl, options.json, options.debug, options.profile);
|
|
861
|
+
break;
|
|
862
|
+
default:
|
|
863
|
+
console.log((0, colors_1.error)(`Error: unknown activity subcommand: ${subcommand}`));
|
|
864
|
+
process.exit(1);
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
// Users commands
|
|
868
|
+
else if (command === 'users') {
|
|
869
|
+
if (!subcommand) {
|
|
870
|
+
console.log((0, colors_1.error)('Error: users command requires a subcommand (list, get, invite, invitations, resend-invitation, cancel-invitation, delete)'));
|
|
871
|
+
process.exit(1);
|
|
872
|
+
}
|
|
873
|
+
switch (subcommand) {
|
|
874
|
+
case 'list':
|
|
875
|
+
const usersOptions = {};
|
|
876
|
+
for (let i = 0; i < args.length; i++) {
|
|
877
|
+
if (args[i] === '--all') {
|
|
878
|
+
usersOptions.all = true;
|
|
879
|
+
}
|
|
880
|
+
else if (args[i].startsWith('--')) {
|
|
881
|
+
const key = args[i].replace(/^--/, '');
|
|
882
|
+
const value = args[i + 1];
|
|
883
|
+
usersOptions[key] = value;
|
|
884
|
+
i++; // Skip the value in next iteration
|
|
885
|
+
}
|
|
886
|
+
}
|
|
887
|
+
await (0, users_1.usersList)(usersOptions, options.token, options.baseUrl, options.json, options.debug, options.profile);
|
|
888
|
+
break;
|
|
889
|
+
case 'get':
|
|
890
|
+
if (args.length === 0) {
|
|
891
|
+
console.log((0, colors_1.error)('Error: users get requires a user ID argument'));
|
|
892
|
+
process.exit(1);
|
|
893
|
+
}
|
|
894
|
+
await (0, users_1.usersGet)(args[0], options.token, options.baseUrl, options.json, options.debug, options.profile);
|
|
895
|
+
break;
|
|
896
|
+
case 'invite':
|
|
897
|
+
if (args.length === 0) {
|
|
898
|
+
console.log((0, colors_1.error)('Error: users invite requires at least one email address'));
|
|
899
|
+
process.exit(1);
|
|
900
|
+
}
|
|
901
|
+
// Parse emails and role
|
|
902
|
+
let emails = [];
|
|
903
|
+
let role = 'Viewer'; // default role
|
|
904
|
+
for (let i = 0; i < args.length; i++) {
|
|
905
|
+
if (args[i] === '--role' && i + 1 < args.length) {
|
|
906
|
+
role = args[++i];
|
|
907
|
+
}
|
|
908
|
+
else if (!args[i].startsWith('--')) {
|
|
909
|
+
// Split by comma in case multiple emails are provided
|
|
910
|
+
emails = emails.concat(args[i].split(',').map(e => e.trim()));
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
if (emails.length === 0) {
|
|
914
|
+
console.log((0, colors_1.error)('Error: users invite requires at least one email address'));
|
|
915
|
+
process.exit(1);
|
|
916
|
+
}
|
|
917
|
+
await (0, users_1.usersInvite)(emails, role, options.token, options.baseUrl, options.json, options.debug, options.profile);
|
|
918
|
+
break;
|
|
919
|
+
case 'invitations':
|
|
920
|
+
await (0, users_1.usersInvitations)(options.token, options.baseUrl, options.json, options.debug, options.profile);
|
|
921
|
+
break;
|
|
922
|
+
case 'resend-invitation':
|
|
923
|
+
if (args.length === 0) {
|
|
924
|
+
console.log((0, colors_1.error)('Error: users resend-invitation requires an invitation token argument'));
|
|
925
|
+
process.exit(1);
|
|
926
|
+
}
|
|
927
|
+
await (0, users_1.usersResendInvitation)(args[0], options.token, options.baseUrl, options.json, options.debug, options.profile);
|
|
928
|
+
break;
|
|
929
|
+
case 'cancel-invitation':
|
|
930
|
+
if (args.length === 0) {
|
|
931
|
+
console.log((0, colors_1.error)('Error: users cancel-invitation requires an invitation token argument'));
|
|
932
|
+
process.exit(1);
|
|
933
|
+
}
|
|
934
|
+
await (0, users_1.usersCancelInvitation)(args[0], options.token, options.baseUrl, options.json, options.debug, options.profile);
|
|
935
|
+
break;
|
|
936
|
+
case 'delete':
|
|
937
|
+
if (args.length < 2) {
|
|
938
|
+
console.log((0, colors_1.error)('Error: users delete requires user identifier and receiver user identifier'));
|
|
939
|
+
console.log('Usage: carto users delete <user-id|email> <receiver-user-id|email>');
|
|
940
|
+
console.log('Both arguments accept user IDs or email addresses.');
|
|
941
|
+
console.log('The receiver user is who will receive the deleted user\'s resources.');
|
|
942
|
+
process.exit(1);
|
|
943
|
+
}
|
|
944
|
+
await (0, users_1.usersDelete)(args[0], args[1], options.token, options.baseUrl, options.json, options.debug, options.profile);
|
|
945
|
+
break;
|
|
946
|
+
default:
|
|
947
|
+
console.log((0, colors_1.error)(`Error: unknown users subcommand: ${subcommand}`));
|
|
948
|
+
process.exit(1);
|
|
949
|
+
}
|
|
950
|
+
}
|
|
951
|
+
// AI Feature commands
|
|
952
|
+
else if (command === 'aifeature') {
|
|
953
|
+
if (!subcommand) {
|
|
954
|
+
console.log((0, colors_1.error)('Error: aifeature command requires a feature name (aiagent, workflowsCreatorAgent, etc.)'));
|
|
955
|
+
console.log('Usage: carto aifeature aiagent <map-id> [message]');
|
|
956
|
+
process.exit(1);
|
|
957
|
+
}
|
|
958
|
+
// AI Feature commands: carto aifeature aiagent, carto aifeature workflowsCreatorAgent, etc.
|
|
959
|
+
await (0, ai_1.handleAiFeature)(subcommand, args, options, options.token, options.baseUrl, options.json, options.debug, options.profile);
|
|
960
|
+
}
|
|
961
|
+
// AI Proxy commands
|
|
962
|
+
else if (command === 'aiproxy') {
|
|
963
|
+
if (!subcommand) {
|
|
964
|
+
console.log((0, colors_1.error)('Error: aiproxy command requires a subcommand (chat, models, info)'));
|
|
965
|
+
console.log('Usage: carto aiproxy chat [message]');
|
|
966
|
+
console.log(' carto aiproxy models');
|
|
967
|
+
console.log(' carto aiproxy info');
|
|
968
|
+
process.exit(1);
|
|
969
|
+
}
|
|
970
|
+
// AI Proxy commands: carto aiproxy chat, carto aiproxy models
|
|
971
|
+
// Pass subcommand as first element of args array
|
|
972
|
+
await (0, ai_1.handleAiProxy)([subcommand, ...args], options, options.token, options.baseUrl, options.json, options.debug, options.profile);
|
|
973
|
+
}
|
|
974
|
+
// Credentials commands
|
|
975
|
+
else if (command === 'credentials') {
|
|
976
|
+
if (!subcommand) {
|
|
977
|
+
console.log((0, colors_1.error)('Error: credentials command requires a subcommand (list, create, get, update, delete)'));
|
|
978
|
+
process.exit(1);
|
|
979
|
+
}
|
|
980
|
+
switch (subcommand) {
|
|
981
|
+
case 'list':
|
|
982
|
+
const listType = args[0]; // undefined, 'tokens', 'spa', 'm2m', 'oauth'
|
|
983
|
+
const credListOptions = {};
|
|
984
|
+
for (let i = 1; i < args.length; i++) {
|
|
985
|
+
if (args[i] === '--all') {
|
|
986
|
+
credListOptions.all = true;
|
|
987
|
+
}
|
|
988
|
+
else if (args[i].startsWith('--')) {
|
|
989
|
+
const key = args[i].replace(/^--/, '');
|
|
990
|
+
const value = args[i + 1];
|
|
991
|
+
credListOptions[key] = value;
|
|
992
|
+
i++; // Skip the value in next iteration
|
|
993
|
+
}
|
|
994
|
+
}
|
|
995
|
+
await (0, credentials_1.credentialsList)(listType, credListOptions, options.token, options.baseUrl, options.json, options.debug, options.profile);
|
|
996
|
+
break;
|
|
997
|
+
case 'create':
|
|
998
|
+
const createType = args[0]; // 'token', 'spa', 'm2m'
|
|
999
|
+
if (!createType || !['token', 'spa', 'm2m'].includes(createType)) {
|
|
1000
|
+
console.log((0, colors_1.error)('Error: credentials create requires type (token, spa, m2m)'));
|
|
1001
|
+
process.exit(1);
|
|
1002
|
+
}
|
|
1003
|
+
// Parse flags and options
|
|
1004
|
+
const createOptions = {};
|
|
1005
|
+
for (let i = 1; i < args.length; i++) {
|
|
1006
|
+
if (args[i].startsWith('--')) {
|
|
1007
|
+
const key = args[i].replace(/^--/, '').replace(/-/g, '_');
|
|
1008
|
+
// Check for flags without values
|
|
1009
|
+
if (i + 1 >= args.length || args[i + 1].startsWith('--')) {
|
|
1010
|
+
createOptions[key] = true;
|
|
1011
|
+
}
|
|
1012
|
+
else {
|
|
1013
|
+
let value = args[i + 1];
|
|
1014
|
+
// Handle special keys that might have multiple values
|
|
1015
|
+
if (key === 'connection' || key === 'source') {
|
|
1016
|
+
if (!createOptions[key]) {
|
|
1017
|
+
createOptions[key] = [];
|
|
1018
|
+
}
|
|
1019
|
+
if (!Array.isArray(createOptions[key])) {
|
|
1020
|
+
createOptions[key] = [createOptions[key]];
|
|
1021
|
+
}
|
|
1022
|
+
createOptions[key].push(value);
|
|
1023
|
+
}
|
|
1024
|
+
else {
|
|
1025
|
+
createOptions[key] = value;
|
|
1026
|
+
}
|
|
1027
|
+
i++; // Skip the value in next iteration
|
|
1028
|
+
}
|
|
1029
|
+
}
|
|
1030
|
+
}
|
|
1031
|
+
if (createType === 'token') {
|
|
1032
|
+
await (0, credentials_1.credentialsCreateToken)(createOptions, options.token, options.baseUrl, options.json, options.debug, options.profile);
|
|
1033
|
+
}
|
|
1034
|
+
else if (createType === 'spa') {
|
|
1035
|
+
await (0, credentials_1.credentialsCreateSPA)(createOptions, options.token, options.baseUrl, options.json, options.debug, options.profile);
|
|
1036
|
+
}
|
|
1037
|
+
else if (createType === 'm2m') {
|
|
1038
|
+
await (0, credentials_1.credentialsCreateM2M)(createOptions, options.token, options.baseUrl, options.json, options.debug, options.profile);
|
|
1039
|
+
}
|
|
1040
|
+
break;
|
|
1041
|
+
case 'get':
|
|
1042
|
+
const getType = args[0]; // 'token', 'spa', 'm2m', 'oauth'
|
|
1043
|
+
const getId = args[1];
|
|
1044
|
+
if (!getType || !['token', 'spa', 'm2m', 'oauth'].includes(getType)) {
|
|
1045
|
+
console.log((0, colors_1.error)('Error: credentials get requires type (token, spa, m2m, oauth)'));
|
|
1046
|
+
process.exit(1);
|
|
1047
|
+
}
|
|
1048
|
+
if (!getId) {
|
|
1049
|
+
console.log((0, colors_1.error)(`Error: credentials get ${getType} requires an ID argument`));
|
|
1050
|
+
process.exit(1);
|
|
1051
|
+
}
|
|
1052
|
+
if (getType === 'token') {
|
|
1053
|
+
await (0, credentials_1.credentialsGetToken)(getId, options.token, options.baseUrl, options.json, options.debug, options.profile);
|
|
1054
|
+
}
|
|
1055
|
+
else {
|
|
1056
|
+
await (0, credentials_1.credentialsGetOAuth)(getId, getType, options.token, options.baseUrl, options.json, options.debug, options.profile);
|
|
1057
|
+
}
|
|
1058
|
+
break;
|
|
1059
|
+
case 'update':
|
|
1060
|
+
const updateType = args[0]; // 'token', 'spa', 'm2m', 'oauth'
|
|
1061
|
+
const updateId = args[1];
|
|
1062
|
+
if (!updateType || !['token', 'spa', 'm2m', 'oauth'].includes(updateType)) {
|
|
1063
|
+
console.log((0, colors_1.error)('Error: credentials update requires type (token, spa, m2m, oauth)'));
|
|
1064
|
+
process.exit(1);
|
|
1065
|
+
}
|
|
1066
|
+
if (!updateId) {
|
|
1067
|
+
console.log((0, colors_1.error)(`Error: credentials update ${updateType} requires an ID argument`));
|
|
1068
|
+
process.exit(1);
|
|
1069
|
+
}
|
|
1070
|
+
// Parse flags and options
|
|
1071
|
+
const updateOptions = {};
|
|
1072
|
+
for (let i = 2; i < args.length; i++) {
|
|
1073
|
+
if (args[i].startsWith('--')) {
|
|
1074
|
+
const key = args[i].replace(/^--/, '').replace(/-/g, '_');
|
|
1075
|
+
// Check for flags without values
|
|
1076
|
+
if (i + 1 >= args.length || args[i + 1].startsWith('--')) {
|
|
1077
|
+
updateOptions[key] = true;
|
|
1078
|
+
}
|
|
1079
|
+
else {
|
|
1080
|
+
updateOptions[key] = args[i + 1];
|
|
1081
|
+
i++; // Skip the value in next iteration
|
|
1082
|
+
}
|
|
1083
|
+
}
|
|
1084
|
+
}
|
|
1085
|
+
if (updateType === 'token') {
|
|
1086
|
+
await (0, credentials_1.credentialsUpdateToken)(updateId, updateOptions, options.token, options.baseUrl, options.json, options.debug, options.profile);
|
|
1087
|
+
}
|
|
1088
|
+
else {
|
|
1089
|
+
await (0, credentials_1.credentialsUpdateOAuth)(updateId, updateOptions, options.token, options.baseUrl, options.json, options.debug, options.profile);
|
|
1090
|
+
}
|
|
1091
|
+
break;
|
|
1092
|
+
case 'delete':
|
|
1093
|
+
case 'revoke':
|
|
1094
|
+
const deleteType = args[0]; // 'token', 'spa', 'm2m', 'oauth'
|
|
1095
|
+
const deleteId = args[1];
|
|
1096
|
+
if (!deleteType || !['token', 'spa', 'm2m', 'oauth'].includes(deleteType)) {
|
|
1097
|
+
console.log((0, colors_1.error)('Error: credentials delete requires type (token, spa, m2m, oauth)'));
|
|
1098
|
+
process.exit(1);
|
|
1099
|
+
}
|
|
1100
|
+
if (!deleteId) {
|
|
1101
|
+
console.log((0, colors_1.error)(`Error: credentials delete ${deleteType} requires an ID argument`));
|
|
1102
|
+
process.exit(1);
|
|
1103
|
+
}
|
|
1104
|
+
if (deleteType === 'token') {
|
|
1105
|
+
await (0, credentials_1.credentialsDeleteToken)(deleteId, options.token, options.baseUrl, options.json, options.debug, options.profile, options.yes);
|
|
1106
|
+
}
|
|
1107
|
+
else {
|
|
1108
|
+
await (0, credentials_1.credentialsDeleteOAuth)(deleteId, options.token, options.baseUrl, options.json, options.debug, options.profile, options.yes);
|
|
1109
|
+
}
|
|
1110
|
+
break;
|
|
1111
|
+
default:
|
|
1112
|
+
console.log((0, colors_1.error)(`Error: unknown credentials subcommand: ${subcommand}`));
|
|
1113
|
+
process.exit(1);
|
|
1114
|
+
}
|
|
1115
|
+
}
|
|
1116
|
+
// Unknown command
|
|
1117
|
+
else {
|
|
1118
|
+
console.log((0, colors_1.error)(`Error: unknown command: ${command}`));
|
|
1119
|
+
console.log('Run "carto --help" for usage information');
|
|
1120
|
+
process.exit(1);
|
|
1121
|
+
}
|
|
1122
|
+
}
|
|
1123
|
+
catch (err) {
|
|
1124
|
+
if (options.json) {
|
|
1125
|
+
console.log(JSON.stringify({ success: false, error: err.message }));
|
|
1126
|
+
}
|
|
1127
|
+
else {
|
|
1128
|
+
console.log((0, colors_1.error)('Error: ' + err.message));
|
|
1129
|
+
}
|
|
1130
|
+
process.exit(1);
|
|
1131
|
+
}
|
|
1132
|
+
}
|
|
1133
|
+
main();
|