@hotglue/cli 1.0.25 → 1.0.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/lib/cjs/index.js +34 -0
  2. package/lib/cjs/index.js.map +1 -0
  3. package/lib/mjs/index.js +34 -0
  4. package/lib/mjs/index.js.map +1 -0
  5. package/package.json +20 -21
  6. package/lib/commands/config/index.js +0 -15
  7. package/lib/commands/config/set.js +0 -82
  8. package/lib/commands/config.js +0 -71
  9. package/lib/commands/env/deploy.js +0 -162
  10. package/lib/commands/env/download.js +0 -169
  11. package/lib/commands/env/index.js +0 -17
  12. package/lib/commands/env.js +0 -34
  13. package/lib/commands/etl/delete.js +0 -171
  14. package/lib/commands/etl/deploy.js +0 -261
  15. package/lib/commands/etl/download.js +0 -205
  16. package/lib/commands/etl/index.js +0 -19
  17. package/lib/commands/etl.js +0 -34
  18. package/lib/commands/flows/index.js +0 -15
  19. package/lib/commands/flows/list.js +0 -104
  20. package/lib/commands/flows.js +0 -34
  21. package/lib/commands/index.js +0 -27
  22. package/lib/commands/jobs/download.js +0 -188
  23. package/lib/commands/jobs/index.js +0 -17
  24. package/lib/commands/jobs/list.js +0 -108
  25. package/lib/commands/jobs.js +0 -34
  26. package/lib/commands/snapshots/deploy.js +0 -202
  27. package/lib/commands/snapshots/download.js +0 -213
  28. package/lib/commands/snapshots/index.js +0 -17
  29. package/lib/commands/snapshots.js +0 -34
  30. package/lib/commands/tenants/customCatalog.js +0 -199
  31. package/lib/commands/tenants/customEtl.js +0 -183
  32. package/lib/commands/tenants/customFieldMap.js +0 -191
  33. package/lib/commands/tenants/delete.js +0 -150
  34. package/lib/commands/tenants/index.js +0 -23
  35. package/lib/commands/tenants/list.js +0 -97
  36. package/lib/commands/tenants/updateConfig.js +0 -188
  37. package/lib/commands/tenants.js +0 -34
  38. package/lib/esm/index.js +0 -2312
  39. package/lib/helpers/api.js +0 -326
  40. package/lib/helpers/baseBuilder.js +0 -30
  41. package/lib/helpers/config.js +0 -105
  42. package/lib/helpers/debug.js +0 -19
  43. package/lib/helpers/descriptions.js +0 -137
  44. package/lib/helpers/flow.js +0 -32
  45. package/lib/helpers/print.js +0 -92
  46. package/lib/helpers/utils.js +0 -245
  47. package/lib/index.js +0 -34
package/lib/esm/index.js DELETED
@@ -1,2312 +0,0 @@
1
- #!/usr/bin/env node
2
- var __defProp = Object.defineProperty;
3
- var __export = (target, all) => {
4
- for (var name in all)
5
- __defProp(target, name, { get: all[name], enumerable: true });
6
- };
7
-
8
- // src/index.js
9
- import "../../node_modules/dotenv/config.js";
10
- import _yargs from "../../node_modules/yargs/index.mjs";
11
- import { hideBin } from "../../node_modules/yargs/helpers/helpers.mjs";
12
-
13
- // src/helpers/config.js
14
- import { homedir } from "os";
15
- import { mkdir, writeFile } from "fs/promises";
16
- import path from "path";
17
- import { cosmiconfig } from "../../node_modules/cosmiconfig/dist/index.js";
18
- var staticOptions = {
19
- hg: {
20
- appName: "hotglue",
21
- clientApiBaseUri: process.env.HOTGLUE_CLIENT_API_BASE_URI || "https://client-api.hotglue.xyz",
22
- defaultConfigFileName: "config.yaml"
23
- }
24
- };
25
- var defaultOptions = {};
26
- var getProfileConfigFilePath = () => path.resolve(homedir(), `.${staticOptions.hg.appName}`, staticOptions.hg.defaultConfigFileName);
27
- var writeConfigFile = async (file, data) => {
28
- await mkdir(path.dirname(file), { recursive: true });
29
- await writeFile(file, data);
30
- };
31
- var getProfileConfig = async () => {
32
- const { appName } = staticOptions.hg;
33
- try {
34
- const result = await cosmiconfig(appName).load(getProfileConfigFilePath());
35
- return result || {};
36
- } catch (err) {
37
- return {};
38
- }
39
- };
40
- var getProjectConfig = async () => {
41
- const { appName } = staticOptions.hg;
42
- const cosmic = cosmiconfig(appName, {
43
- searchPlaces: [
44
- `${appName}.yaml`,
45
- `.${appName}.yaml`,
46
- `.${appName}rc.yaml`,
47
- `.${appName}rc.yml`,
48
- `.${appName}rc`,
49
- `.${appName}rc.json`,
50
- `.${appName}rc.js`
51
- ]
52
- });
53
- try {
54
- const result = await cosmic.search();
55
- return result || {};
56
- } catch (err) {
57
- console.log(err);
58
- throw new Error(`Malformed configuration file: ${err.message}`);
59
- }
60
- };
61
- var getCombinedConfig = async () => {
62
- const profileConfig = await getProfileConfig();
63
- const projectConfig = await getProjectConfig();
64
- const result = { ...defaultOptions, ...profileConfig.config, ...projectConfig.config };
65
- return result;
66
- };
67
-
68
- // src/helpers/print.js
69
- import { inspect } from "util";
70
- import chalk from "../../node_modules/chalk/source/index.js";
71
- var defaultTheme = {
72
- primary: (str) => chalk.whiteBright(str),
73
- secondary: (str) => chalk.white(str),
74
- info: (str) => chalk.green(str),
75
- warn: (str) => chalk.yellow(str),
76
- error: (str) => chalk.redBright(str),
77
- success: (str) => chalk.greenBright(str)
78
- };
79
- var _currentTheme = defaultTheme;
80
- var _defaultColor = "primary";
81
- function setTheme(theme) {
82
- _currentTheme = { ...defaultTheme, ...theme };
83
- return funcs;
84
- }
85
- function print(str) {
86
- process.stdout.write(str);
87
- }
88
- var themed = (content, color = _defaultColor) => {
89
- if (!content)
90
- return "";
91
- if (typeof content === "string")
92
- return _currentTheme[color] ? _currentTheme[color](content) : _currentTheme[_defaultColor](content);
93
- const objString = inspect(content, { colors: true });
94
- return _currentTheme[color] ? _currentTheme[color](objString) : objString;
95
- };
96
- function cl(...contentArgs) {
97
- console.log(...contentArgs);
98
- return funcs;
99
- }
100
- function pr(content, color) {
101
- print(themed(content, color));
102
- print("\n");
103
- return funcs;
104
- }
105
- function pp(content, color) {
106
- print(themed(content, color));
107
- return funcs;
108
- }
109
- function setDefault(color = "primary") {
110
- if (_currentTheme[color])
111
- _defaultColor = color;
112
- return funcs;
113
- }
114
- var funcs = {
115
- cl,
116
- pr,
117
- pp,
118
- setTheme,
119
- setDefault
120
- };
121
- var printJSON = (data) => {
122
- console.log(JSON.stringify(data));
123
- };
124
-
125
- // src/index.js
126
- import "../../node_modules/aws-sdk/lib/aws.js";
127
-
128
- // src/commands/config.js
129
- var config_exports = {};
130
- __export(config_exports, {
131
- builder: () => builder2,
132
- command: () => command2,
133
- desc: () => desc2,
134
- handler: () => handler2
135
- });
136
- import path2 from "path";
137
-
138
- // src/helpers/debug.js
139
- import Debug from "../../node_modules/debug/src/index.js";
140
- var debug = Debug("hotglue-cli");
141
- function extendDebug(namespace) {
142
- return debug.extend(namespace);
143
- }
144
- var debug_default = extendDebug;
145
-
146
- // src/commands/config.js
147
- import YAML2 from "../../node_modules/yaml/index.js";
148
- import Table2 from "../../node_modules/cli-table/lib/index.js";
149
-
150
- // src/commands/config/set.js
151
- var set_exports = {};
152
- __export(set_exports, {
153
- builder: () => builder,
154
- command: () => command,
155
- desc: () => desc,
156
- handler: () => handler
157
- });
158
- import YAML from "../../node_modules/yaml/index.js";
159
- import Table from "../../node_modules/cli-table/lib/index.js";
160
- var debug2 = debug_default("commands:config:set");
161
- var command = "set <setting> <value>";
162
- var desc = "Set configuration key-value pairs";
163
- var builder = async (yargs2) => {
164
- debug2("builder", command, yargs2);
165
- yargs2.option("setting", {
166
- describe: "The configuration parameter you wish to set",
167
- type: "string"
168
- }).option("value", {
169
- describe: "The configuration parameter's value",
170
- type: "string"
171
- });
172
- return yargs2;
173
- };
174
- var handler = async (argv) => {
175
- debug2("handler", command, argv);
176
- const { json, setting, value } = argv;
177
- const allowedSettings = ["apikey"];
178
- if (!allowedSettings.includes(setting)) {
179
- json ? printJSON({ status: "error", error: "Invalid settings parameter" }) : console.error("Invalid settings parameter");
180
- return;
181
- }
182
- try {
183
- const profileConfig = await getProfileConfig();
184
- if (profileConfig && profileConfig.config)
185
- !json && pp("Updating profile config file...");
186
- else
187
- !json && pp("Creating profile config file...");
188
- const data = profileConfig && profileConfig.config ? { ...profileConfig.config, [setting]: value } : { [setting]: value };
189
- const yamlData = YAML.stringify(data);
190
- const filePath = profileConfig && profileConfig.filepath ? profileConfig.filepath : getProfileConfigFilePath();
191
- await writeConfigFile(filePath, yamlData);
192
- json ? printJSON({ status: "success" }) : pp("Done").pr();
193
- } catch (err) {
194
- json ? printJSON({ status: "error", error: err }) : console.log(err);
195
- }
196
- };
197
-
198
- // src/commands/config/index.js
199
- var config = [set_exports];
200
-
201
- // src/commands/config.js
202
- var debug3 = debug_default("commands:config");
203
- var command2 = "config [action]";
204
- var desc2 = "Configure your hotglue CLI";
205
- var builder2 = async function(yargs2) {
206
- debug3("builder", command2);
207
- return yargs2.command(config);
208
- };
209
- var handler2 = async function(argv) {
210
- debug3("handler", command2, argv);
211
- const { action } = argv;
212
- if (!action) {
213
- try {
214
- const profileConfig = await getProfileConfig();
215
- if (!profileConfig.config || Object.keys(profileConfig.config).length === 0) {
216
- pr("No profile configuration found. Run config set to configure the hotglue CLI.");
217
- }
218
- const table = new Table2({ head: ["Setting", "Value", "Config File", "Type"] });
219
- if (profileConfig.config)
220
- Object.entries(profileConfig.config).forEach(([k, v]) => table.push([k, v, profileConfig.filepath, `Profile`]));
221
- const projectConfig = await getProjectConfig();
222
- if (projectConfig.config)
223
- Object.entries(projectConfig.config).forEach(([k, v]) => table.push([k, v, path2.relative(process.cwd(), projectConfig.filepath), "Project"]));
224
- if (table.length > 0) {
225
- console.log(table.toString());
226
- }
227
- } catch (err) {
228
- console.log(err);
229
- throw err;
230
- }
231
- }
232
- };
233
-
234
- // src/commands/env.js
235
- var env_exports = {};
236
- __export(env_exports, {
237
- builder: () => builder5,
238
- command: () => command5,
239
- desc: () => desc5,
240
- handler: () => handler5
241
- });
242
-
243
- // src/helpers/descriptions.js
244
- var descriptions_default = {
245
- commands: {},
246
- options: {
247
- env: {
248
- config: {
249
- describe: "Environment Id",
250
- type: "string",
251
- alias: ["e"]
252
- },
253
- demandText: 'The "env" parameter (Environment Id) is required. Either pass here using `-e [env_id]` or add an env property in your rc file.'
254
- },
255
- apikey: {
256
- config: {
257
- describe: "API key",
258
- type: "string",
259
- alias: ["k"]
260
- },
261
- demandText: "API key is required. Either pass here using -k [key] or configure your profile using config set."
262
- },
263
- json: {
264
- config: {
265
- describe: "Makes the output format to be JSON",
266
- type: "boolean",
267
- default: false
268
- },
269
- demandText: ""
270
- },
271
- tenant: {
272
- config: {
273
- describe: "Tenant (user) ID",
274
- type: "string",
275
- alias: ["u"]
276
- },
277
- demandText: "TenantId is required. You can pass it using -u [tenantId]."
278
- },
279
- flow: {
280
- config: {
281
- describe: "Flow ID",
282
- type: "string",
283
- alias: ["f"]
284
- },
285
- demandText: "FlowId is required. You can pass it using -f [flow_id]."
286
- },
287
- tap: {
288
- config: {
289
- describe: "Tap name",
290
- type: "string",
291
- alias: ["t"]
292
- },
293
- demandText: "Tap name is required. You can pass it using -t <tap_name>."
294
- },
295
- connector: {
296
- config: {
297
- describe: "Connector ID",
298
- type: "string",
299
- alias: ["c"]
300
- },
301
- demandText: "Connector ID is required. You can pass it using -c <connector>."
302
- },
303
- all: {
304
- config: {
305
- describe: "Run command for all taps/connectors",
306
- type: "boolean",
307
- default: false,
308
- alias: ["a"]
309
- },
310
- demandText: 'This "all" flag is required. You can pass it using -a or --all.'
311
- },
312
- jobroot: {
313
- config: {
314
- describe: "Job Root (S3 prefix)",
315
- type: "string",
316
- alias: ["j"]
317
- },
318
- demandText: "JobRoot key is required. You can pass it using -j [job_root]."
319
- },
320
- count: {
321
- config: {
322
- describe: "Max returned records",
323
- type: "number"
324
- }
325
- },
326
- downloadTo: {
327
- config: {
328
- describe: "Download folder",
329
- default: ".",
330
- type: "string",
331
- alias: ["d"]
332
- },
333
- demandText: "A destination folder is required. You can pass it using -d [folder] and can be either relative from cwd or absolute."
334
- },
335
- sourceFolder: {
336
- config: {
337
- describe: "Source folder",
338
- type: "string",
339
- default: ".",
340
- alias: ["s"]
341
- },
342
- demandText: ""
343
- },
344
- configFilePath: {
345
- config: {
346
- describe: "Config file path",
347
- type: "string",
348
- default: "./config.json",
349
- alias: ["p"]
350
- },
351
- demandText: 'Local path of the config (with .json extension). Example: "/home/hotglue/config.json"'
352
- },
353
- overwrite: {
354
- config: {
355
- describe: "Overwrite existing",
356
- type: "boolean",
357
- default: false,
358
- alias: ["o"]
359
- },
360
- demandText: ""
361
- },
362
- cleanup: {
363
- config: {
364
- describe: "Clean up target prior to action",
365
- type: "boolean",
366
- default: false,
367
- alias: ["c"]
368
- },
369
- demandText: ""
370
- }
371
- }
372
- };
373
-
374
- // src/helpers/baseBuilder.js
375
- var debug4 = debug_default("base");
376
- var baseBuilder = (yargs2) => {
377
- return yargs2;
378
- };
379
- var baseApiBuilder = async (yargs2) => {
380
- debug4("builder");
381
- const config2 = await getCombinedConfig();
382
- return baseBuilder(yargs2).option("apikey", descriptions_default.options["apikey"].config).option("env", descriptions_default.options["env"].config).option("json", descriptions_default.options["json"].config).config(config2).demandOption(["env"], descriptions_default.options["env"].demandText).demandOption(["apikey"], descriptions_default.options["apikey"].demandText);
383
- };
384
-
385
- // src/commands/env/deploy.js
386
- var deploy_exports = {};
387
- __export(deploy_exports, {
388
- builder: () => builder3,
389
- command: () => command3,
390
- desc: () => desc3,
391
- handler: () => handler3
392
- });
393
- import path4 from "path";
394
- import { readdir as readdir2, readFile } from "fs/promises";
395
- import ora from "../../node_modules/ora/index.js";
396
- import axios2 from "../../node_modules/axios/index.js";
397
- import AWS from "../../node_modules/aws-sdk/lib/aws.js";
398
- import Table3 from "../../node_modules/cli-table/lib/index.js";
399
-
400
- // src/helpers/utils.js
401
- import path3 from "path";
402
- import { readdir } from "fs/promises";
403
- import micromatch from "../../node_modules/micromatch/index.js";
404
- var debug5 = debug_default("utils.js");
405
- var _getFolderFiles = async (dir, options, result = []) => {
406
- const { includeSymLinks, recursive, filter } = options;
407
- const { matcher } = filter;
408
- const fullPath = path3.resolve(dir);
409
- const files = await readdir(fullPath, { withFileTypes: true });
410
- for (const file of files) {
411
- const filePath = path3.resolve(fullPath, file.name);
412
- if (file.isSymbolicLink() && !includeSymLinks) {
413
- continue;
414
- }
415
- if (matcher && !matcher(filePath)) {
416
- debug5("skip", filePath);
417
- continue;
418
- }
419
- if (file.isFile()) {
420
- result.push(path3.resolve(fullPath, file.name));
421
- } else if (file.isDirectory() && recursive) {
422
- await _getFolderFiles(path3.resolve(fullPath, file.name), options, result);
423
- }
424
- }
425
- return result;
426
- };
427
- var getFolderFiles = async (dir, options) => {
428
- const _options = { includeSymLinks: false, recursive: false, filter: {}, ...options };
429
- const { pattern } = _options.filter;
430
- if (pattern) {
431
- _options.filter.matcher = micromatch.matcher(pattern);
432
- }
433
- return _getFolderFiles(dir, _options);
434
- };
435
- var filterFiles = (files, filter) => {
436
- debug5("filter-in", files);
437
- const { pattern } = { ...filter };
438
- let result = files;
439
- if (pattern)
440
- result = micromatch(result, pattern);
441
- debug5("filter-out", result);
442
- return result;
443
- };
444
- function userSetOption(option) {
445
- function wasArgPassed(option2) {
446
- return process.argv.indexOf(option2) > -1;
447
- }
448
- if (wasArgPassed(`--${option}`)) {
449
- return true;
450
- }
451
- const aliases = descriptions_default.options[option]?.config?.alias || [];
452
- for (let i in aliases) {
453
- if (wasArgPassed(`-${aliases[i]}`))
454
- return true;
455
- }
456
- return false;
457
- }
458
- var streamToString = (stream) => {
459
- const chunks = [];
460
- return new Promise((resolve, reject) => {
461
- stream.on("error", reject);
462
- stream.on("data", (c) => chunks.push(Buffer.from(c)));
463
- stream.on("end", () => resolve(Buffer.concat(chunks).toString("utf8")));
464
- });
465
- };
466
- var buildChunks = (array, chunkSize = 10) => {
467
- const resultArray = [];
468
- for (let i = 0; i < array.length; i += chunkSize) {
469
- const chunk = array.slice(i, i + chunkSize);
470
- resultArray.push(chunk);
471
- }
472
- return resultArray;
473
- };
474
-
475
- // src/helpers/api.js
476
- import axios from "../../node_modules/axios/index.js";
477
- var resetAvailableEntities = async ({ debug: debug27, baseUri, env: env2, apiKey }) => {
478
- const urlObj = new URL(`${baseUri}/${env2}/resetAvailableEntities`);
479
- const { data } = await axios.delete(urlObj, { headers: { "x-api-key": apiKey, "Content-type": "application/json" } });
480
- debug27({ data });
481
- };
482
- var genCredentialsOnClientApi = async ({ debug: debug27, baseUri, task, env: env2, apikey, ...params }) => {
483
- const urlObj = new URL(`${baseUri}/credentials/${task}/${env2}`);
484
- if (params) {
485
- Object.entries(params).forEach(([key, value]) => {
486
- urlObj.searchParams.set(key, value);
487
- });
488
- }
489
- const uri = urlObj.toString();
490
- debug27 && debug27("uri:", uri);
491
- const { data } = await axios.get(uri, { headers: { "x-api-key": apikey } });
492
- const { accessKeyId, secretAccessKey, sessionToken } = data;
493
- return { accessKeyId, secretAccessKey, sessionToken };
494
- };
495
- var getTenants = async ({ debug: debug27, baseUri, env: env2, apikey }) => {
496
- const uri = `${baseUri}/tenants/${env2}`;
497
- debug27("requesting:", uri);
498
- const { data } = await axios.get(uri, { headers: { "x-api-key": apikey } });
499
- debug27("response-data", data);
500
- return data;
501
- };
502
- var getSupportedSources = async ({ debug: debug27, baseUri, env: env2, flow, apikey }) => {
503
- const urlObj = new URL(`${baseUri}/${env2}/${flow}/supportedSources`);
504
- const headers = { "x-api-key": apikey };
505
- const uri = urlObj.toString();
506
- debug27 && debug27("uri:", uri);
507
- const { data } = await axios.get(uri, { headers });
508
- return data;
509
- };
510
- var getSupportedConnectors = async ({ debug: debug27, baseUri, env: env2, flow, apikey }) => {
511
- const urlObj = new URL(`${baseUri}/v2/${env2}/${flow}/supportedConnectors`);
512
- const headers = { "x-api-key": apikey };
513
- const uri = urlObj.toString();
514
- debug27 && debug27("uri:", uri);
515
- const { data } = await axios.get(uri, { headers });
516
- return data;
517
- };
518
- var getLinkedSources = async ({ debug: debug27, baseUri, env: env2, flow, tenant, apikey, config: config2 }) => {
519
- const urlObj = new URL(`${baseUri}/${env2}/${flow}/${tenant}/linkedSources`);
520
- if (config2) {
521
- urlObj.searchParams.set("config", "true");
522
- }
523
- const headers = { "x-api-key": apikey };
524
- const uri = urlObj.toString();
525
- debug27 && debug27("uri:", uri);
526
- const { data } = await axios.get(uri, { headers });
527
- return data;
528
- };
529
- var getLinkedConnectors = async ({ debug: debug27, baseUri, env: env2, flow, tenant, apikey, config: config2 }) => {
530
- const urlObj = new URL(`${baseUri}/v2/${env2}/${flow}/${tenant}/linkedConnectors`);
531
- if (config2) {
532
- urlObj.searchParams.set("config", "true");
533
- }
534
- const headers = { "x-api-key": apikey };
535
- const uri = urlObj.toString();
536
- debug27 && debug27("uri:", uri);
537
- const { data } = await axios.get(uri, { headers });
538
- return data;
539
- };
540
- var patchLinkedSourceConfig = async ({ debug: debug27, baseUri, env: env2, flow, tenant, apikey, connectorId, config: config2 }) => {
541
- const urlObj = new URL(`${baseUri}/${env2}/${flow}/${tenant}/linkedSources`);
542
- const headers = { "x-api-key": apikey };
543
- const uri = urlObj.toString();
544
- const body = { tap: connectorId, config: config2 };
545
- debug27 && debug27("uri:", uri);
546
- const { data } = await axios.patch(uri, body, { headers });
547
- return data;
548
- };
549
- var patchLinkedConnectorConfig = async ({ debug: debug27, baseUri, env: env2, flow, tenant, apikey, connectorId, config: config2 }) => {
550
- const urlObj = new URL(`${baseUri}/v2/${env2}/${flow}/${tenant}/linkedConnectors`);
551
- const headers = { "x-api-key": apikey };
552
- const uri = urlObj.toString();
553
- const body = { connector_id: connectorId, config: config2 };
554
- debug27 && debug27("uri:", uri);
555
- const { data } = await axios.patch(uri, body, { headers });
556
- return data;
557
- };
558
- var getSupportedFlows = async ({ debug: debug27, baseUri, env: env2, apikey }) => {
559
- const urlObj = new URL(`${baseUri}/${env2}/flows/supported`);
560
- const headers = { "x-api-key": apikey };
561
- const uri = urlObj.toString();
562
- debug27 && debug27("uri:", uri);
563
- const { data } = await axios.get(uri, { headers });
564
- return data;
565
- };
566
- var getSupportedFlow = async ({ debug: debug27, baseUri, env: env2, flow, apikey }) => {
567
- const urlObj = new URL(`${baseUri}/${env2}/flows/${flow}/supported`);
568
- const headers = { "x-api-key": apikey };
569
- const uri = urlObj.toString();
570
- debug27 && debug27("uri:", uri);
571
- const { data } = await axios.get(uri, { headers });
572
- return data;
573
- };
574
- var deleteTenantSchedules = async ({ debug: debug27, baseUri, env: env2, apikey, tenant }) => {
575
- const urlObj = new URL(`${baseUri}/tenant/${env2}/${tenant}?schedules_only=true`);
576
- const headers = { "x-api-key": apikey };
577
- const uri = urlObj.toString();
578
- debug27 && debug27("uri:", uri);
579
- const { data } = await axios.delete(uri, { headers });
580
- return data;
581
- };
582
-
583
- // src/commands/env/deploy.js
584
- var debug6 = debug_default("commands:env:deploy");
585
- var command3 = "deploy";
586
- var desc3 = "Deploy Environment settings";
587
- var builder3 = async (yargs2) => {
588
- debug6("builder", command3);
589
- return yargs2.option("sourceFolder", descriptions_default.options["sourceFolder"].config).demandOption("sourceFolder", descriptions_default.options["sourceFolder"].demandText);
590
- };
591
- var handler3 = async (argv) => {
592
- debug6("handler", command3, argv);
593
- const { hg, json, apikey, env: env2, sourceFolder } = argv;
594
- const { clientApiBaseUri } = hg;
595
- const folderPrefix = path4.resolve(process.cwd(), sourceFolder);
596
- let message;
597
- let spinner = ora();
598
- try {
599
- message = themed(`Scanning ${themed(folderPrefix, "info")} for deployable files`);
600
- !json && spinner.start(themed(`In progress: ${message}...`, "secondary"));
601
- const deployableFiles = await getFolderFiles(folderPrefix, {
602
- filter: {
603
- pattern: "((**/requirements.txt)|(**/availableSources.json)|(**/availableTargets.json)|(**/availableConnectors.json))"
604
- }
605
- });
606
- if (deployableFiles.length === 0) {
607
- if (json) {
608
- printJSON({ status: "error", error: "There are no files to deploy at the specified location!" });
609
- } else {
610
- spinner.fail(themed(`Error: ${message}.`, "secondary"));
611
- pr(themed(`Message: ${themed("There are no files to deploy at the specified location!")}`, "secondary"));
612
- }
613
- return;
614
- }
615
- !json && spinner.succeed(themed(`Finished: ${message}.`, "secondary"));
616
- message = themed(`Verifying user and authorizing`);
617
- !json && spinner.start(themed(`In progress: ${message}...`, "secondary"));
618
- const { accessKeyId, secretAccessKey, sessionToken } = await genCredentialsOnClientApi({
619
- debug: debug6,
620
- baseUri: clientApiBaseUri,
621
- task: "env-deploy",
622
- env: env2,
623
- apikey
624
- });
625
- !json && spinner.succeed(themed(`Finished: ${message}.`, "secondary"));
626
- const s3 = new AWS.S3({
627
- accessKeyId,
628
- secretAccessKey,
629
- sessionToken
630
- });
631
- message = themed(`Deploying environment files`);
632
- !json && spinner.info(themed(`Info: ${message}.`, "secondary"));
633
- const rootKey = `config/`;
634
- const table = new Table3({ head: ["File", "Status"] });
635
- for await (const file of deployableFiles) {
636
- const filename = path4.basename(file);
637
- message = themed(`Pushing file: ${themed(filename, "info")}`);
638
- !json && spinner.start(themed(`In progress: ${message}...`, "secondary"));
639
- const readBuffer = await readFile(file);
640
- const params = {
641
- Bucket: env2,
642
- Key: `${rootKey}${filename}`,
643
- Body: readBuffer
644
- };
645
- const res = await s3.putObject(params).promise();
646
- !json && spinner.succeed(themed(`Finished: ${message}.`, "secondary"));
647
- debug6("s3-put-res", res);
648
- table.push([filename, "Deployed"]);
649
- await resetAvailableEntities({
650
- debug: debug6,
651
- baseUri: clientApiBaseUri,
652
- env: env2,
653
- apiKey: apikey
654
- });
655
- }
656
- if (json) {
657
- printJSON({ status: "success", deployedFiles: deployableFiles });
658
- } else {
659
- cl(table.toString());
660
- }
661
- } catch (err) {
662
- !json && spinner.fail(themed(`Error: ${message}.`, "secondary"));
663
- pr(themed(`Message: ${themed(err.message)}`, "secondary"));
664
- debug6(err);
665
- if (err && err.response && err.response.data) {
666
- debug6("response", err.response.data);
667
- }
668
- }
669
- };
670
-
671
- // src/commands/env/download.js
672
- var download_exports = {};
673
- __export(download_exports, {
674
- builder: () => builder4,
675
- command: () => command4,
676
- desc: () => desc4,
677
- handler: () => handler4
678
- });
679
- import path5 from "path";
680
- import { mkdir as mkdir2, writeFile as writeFile2, stat } from "fs/promises";
681
- import ora2 from "../../node_modules/ora/index.js";
682
- import axios3 from "../../node_modules/axios/index.js";
683
- import Table4 from "../../node_modules/cli-table/lib/index.js";
684
- import AWS2 from "../../node_modules/aws-sdk/lib/aws.js";
685
- var debug7 = debug_default("commands:env:download");
686
- var command4 = "download";
687
- var desc4 = "Download Environment settings";
688
- var builder4 = async (yargs2) => {
689
- debug7("builder", command4);
690
- return yargs2.option("downloadTo", descriptions_default.options["downloadTo"].config);
691
- };
692
- var handler4 = async (argv) => {
693
- debug7("handler", command4, argv);
694
- const { hg, json, apikey, env: env2, downloadTo } = argv;
695
- const { clientApiBaseUri } = hg;
696
- const folderPrefix = path5.resolve(process.cwd(), downloadTo);
697
- let message;
698
- let spinner = ora2();
699
- try {
700
- message = themed(`Verifying user and authorizing`);
701
- !json && spinner.start(themed(`In progress: ${message}...`, "secondary"));
702
- const { accessKeyId, secretAccessKey, sessionToken } = await genCredentialsOnClientApi({
703
- debug: debug7,
704
- baseUri: clientApiBaseUri,
705
- task: "env-download",
706
- env: env2,
707
- apikey
708
- });
709
- !json && spinner.succeed(themed(`Finished: ${message}.`, "secondary"));
710
- const s3 = new AWS2.S3({
711
- accessKeyId,
712
- secretAccessKey,
713
- sessionToken
714
- });
715
- message = themed(`Scanning environment ${themed(env2, "info")}`);
716
- !json && spinner.start(themed(`In progress: ${message}...`, "secondary"));
717
- const params = {
718
- Bucket: env2,
719
- Prefix: `config/`
720
- };
721
- const { Contents: s3Files } = await s3.listObjectsV2(params).promise();
722
- !json && spinner.succeed(themed(`Finished: ${message}.`, "secondary"));
723
- debug7("s3-files", s3Files);
724
- const filesToDownload = s3Files ? filterFiles(s3Files.map((item) => item.Key), {
725
- pattern: "((*/requirements.txt)|(*/availableSources.json)|(*/availableTargets.json)|(*/availableConnectors.json))"
726
- }) : [];
727
- if (!filesToDownload || filesToDownload.length === 0) {
728
- json ? printJSON({ status: "success", downloadedFiles: [] }) : spinner.warn(themed(`Warning: ${themed("Nothing to download!")}`, "secondary"));
729
- return;
730
- }
731
- message = themed(`Downloading to ${themed(folderPrefix, "info")}`);
732
- !json && spinner.info(themed(`Info: ${message}.`, "secondary"));
733
- const table = new Table4({ head: ["File", "Status"] });
734
- for await (const item of filesToDownload) {
735
- const filename = path5.basename(item);
736
- const fullPath = path5.resolve(folderPrefix, filename);
737
- debug7("local-file", fullPath);
738
- await mkdir2(path5.dirname(fullPath), { recursive: true });
739
- message = themed(`Downloading file: ${themed(filename, "info")}`);
740
- !json && spinner.start(themed(`In progress: ${message}...`, "secondary"));
741
- const fileStream = s3.getObject({ Bucket: env2, Key: item }).createReadStream();
742
- await writeFile2(fullPath, await streamToString(fileStream));
743
- !json && spinner.succeed(themed(`Finished: ${message}.`, "secondary"));
744
- table.push([filename, "Downloaded"]);
745
- }
746
- if (json) {
747
- printJSON({ status: "success", downloadedFiles: filesToDownload });
748
- } else {
749
- cl(table.toString());
750
- }
751
- } catch (err) {
752
- if (json) {
753
- printJSON({ status: "error", error: err });
754
- } else {
755
- spinner.fail(themed(`Error: ${message}.`, "secondary"));
756
- pr(themed(`Message: ${themed(err.message)}`, "secondary"));
757
- debug7(err);
758
- if (err && err.response && err.response.data) {
759
- debug7("response", err.response.data);
760
- }
761
- }
762
- }
763
- };
764
-
765
- // src/commands/env/index.js
766
- var env = [deploy_exports, download_exports];
767
-
768
- // src/commands/env.js
769
- var debug8 = debug_default("commands:env");
770
- var command5 = "env <action>";
771
- var desc5 = "Manage environment settings";
772
- var builder5 = async function(yargs2) {
773
- debug8("builder", command5);
774
- const base = await baseApiBuilder(yargs2);
775
- return base.command(env);
776
- };
777
- var handler5 = async function(argv) {
778
- debug8("handler", command5, argv);
779
- };
780
-
781
- // src/commands/etl.js
782
- var etl_exports = {};
783
- __export(etl_exports, {
784
- builder: () => builder9,
785
- command: () => command9,
786
- desc: () => desc9,
787
- handler: () => handler9
788
- });
789
-
790
- // src/commands/etl/delete.js
791
- var delete_exports = {};
792
- __export(delete_exports, {
793
- builder: () => builder6,
794
- command: () => command6,
795
- desc: () => desc6,
796
- handler: () => handler6
797
- });
798
- import ora3 from "../../node_modules/ora/index.js";
799
- import AWS3 from "../../node_modules/aws-sdk/lib/aws.js";
800
- import Table5 from "../../node_modules/cli-table/lib/index.js";
801
-
802
- // src/helpers/flow.js
803
- var isV2Flow = async (s3, envId, tenantId, flowId) => {
804
- try {
805
- const fileStream = s3.getObject({
806
- Bucket: envId,
807
- Key: `${tenantId}/flows/${flowId}/flow.json`
808
- }).createReadStream();
809
- const fileString = await streamToString(fileStream);
810
- const fileJson = JSON.parse(fileString);
811
- return fileJson.version === 2;
812
- } catch (error) {
813
- return false;
814
- }
815
- };
816
- var getEntityLabel = async (s3, envId, tenantId, flowId, isV2 = void 0) => {
817
- const _isV2Flow = isV2 ?? await isV2Flow(s3, envId, tenantId, flowId);
818
- return _isV2Flow ? "connectors" : "taps";
819
- };
820
-
821
- // src/commands/etl/delete.js
822
- var debug9 = debug_default("commands:etl:delete");
823
- var command6 = "delete";
824
- var desc6 = "Delete ETL scripts";
825
- var builder6 = async (yargs2) => {
826
- debug9("builder", command6);
827
- return yargs2.option("flow", descriptions_default.options["flow"].config).demandOption("flow", descriptions_default.options["flow"].demandText).option("tap", descriptions_default.options["tap"].config).demandOption("tap", descriptions_default.options["tap"].demandText).option("tenant", { ...descriptions_default.options["tenant"].config }).demandOption("tenant", descriptions_default.options["tenant"].demandText);
828
- };
829
- var handler6 = async (argv) => {
830
- debug9("handler", command6, argv);
831
- const { hg, json, apikey, env: env2, flow, tap, tenant } = argv;
832
- const { clientApiBaseUri } = hg;
833
- let message;
834
- let spinner = ora3();
835
- try {
836
- message = themed(`Deleting ETL scripts for Tenant ${themed(tenant, "info")} Flow ${themed(flow, "info")} and Tap ${themed(tap, "info")} to ${themed(env2, "info")}`);
837
- !json && spinner.info(themed(`Info: ${message}.`, "secondary"));
838
- message = themed(`Verifying user and authorizing`);
839
- !json && spinner.start(themed(`In progress: ${message}...`, "secondary"));
840
- const { accessKeyId, secretAccessKey, sessionToken } = await genCredentialsOnClientApi({
841
- debug: debug9,
842
- baseUri: clientApiBaseUri,
843
- task: "etl-deploy",
844
- env: env2,
845
- tenant,
846
- flow,
847
- tap,
848
- apikey
849
- });
850
- const s3 = new AWS3.S3({
851
- accessKeyId,
852
- secretAccessKey,
853
- sessionToken
854
- });
855
- !json && spinner.succeed(themed(`Finished: ${message}.`, "secondary"));
856
- message = themed(`Deleting ETL scripts`);
857
- !json && spinner.start(themed(`In progress: ${message}...`, "secondary"));
858
- const keyPrefix = `${tenant}/flows/${flow}/${await getEntityLabel(s3, env2, tenant, flow)}/${tap}/etl/`;
859
- const listObjectsRes = await s3.listObjectsV2({ Bucket: env2, Prefix: keyPrefix }).promise();
860
- debug9("s3-list-objects-res", listObjectsRes);
861
- if (listObjectsRes.Contents?.length > 0) {
862
- const deleteObjectsRes = await s3.deleteObjects({
863
- Bucket: env2,
864
- Delete: {
865
- Objects: listObjectsRes.Contents.map((object) => {
866
- return { Key: object.Key };
867
- })
868
- }
869
- }).promise();
870
- debug9("s3-list-objects-res", deleteObjectsRes);
871
- }
872
- const response = await s3.deleteObject({ Bucket: env2, Key: keyPrefix }).promise();
873
- debug9("s3-delete-object-res", response);
874
- !json && spinner.succeed(themed(`Finished: ${message}.`, "secondary"));
875
- if (listObjectsRes.Contents?.length > 0) {
876
- const table = new Table5({ head: ["File", "Status"] });
877
- listObjectsRes.Contents.filter(({ Key }) => {
878
- return Key !== keyPrefix;
879
- }).forEach(({ Key }) => {
880
- const splittedKey = Key.split("/");
881
- const filename = splittedKey[splittedKey.length - 1];
882
- table.push([filename, themed("Deleted", "info")]);
883
- });
884
- if (json) {
885
- printJSON({
886
- status: "success",
887
- deletedObjects: (listObjectsRes.Contents ?? []).map(({ Key }) => Key)
888
- });
889
- } else {
890
- cl(table.toString());
891
- }
892
- } else {
893
- message = themed(`There was no file or folder to be deleted`);
894
- json ? printJSON({ status: "success", deletedObjects: [] }) : spinner.info(themed(`Info: ${message}.`, "secondary"));
895
- }
896
- } catch (err) {
897
- if (json) {
898
- printJSON({ status: "error", error: err });
899
- } else {
900
- spinner.fail(themed(`Error: ${message}.`, "secondary"));
901
- pr(themed(`Message: ${themed(err.message)}`, "secondary"));
902
- debug9(err);
903
- if (err && err.response && err.response.data) {
904
- debug9("response", err.response.data);
905
- }
906
- }
907
- }
908
- };
909
-
910
- // src/commands/etl/deploy.js
911
- var deploy_exports2 = {};
912
- __export(deploy_exports2, {
913
- builder: () => builder7,
914
- command: () => command7,
915
- desc: () => desc7,
916
- handler: () => handler7
917
- });
918
- import path6 from "path";
919
- import { readFile as readFile2 } from "fs/promises";
920
- import ora4 from "../../node_modules/ora/index.js";
921
- import AWS4 from "../../node_modules/aws-sdk/lib/aws.js";
922
- import Table6 from "../../node_modules/cli-table/lib/index.js";
923
- var debug10 = debug_default("commands:etl:deploy");
924
- var command7 = "deploy";
925
- var desc7 = "Deploy ETL scripts";
926
- var builder7 = async (yargs2) => {
927
- debug10("builder", command7);
928
- return yargs2.option("flow", descriptions_default.options["flow"].config).demandOption("flow", descriptions_default.options["flow"].demandText).option("tap", descriptions_default.options["tap"].config).option("all", descriptions_default.options["all"].config).option("tenant", { ...descriptions_default.options["tenant"].config, default: "default" }).option("sourceFolder", descriptions_default.options["sourceFolder"].config).demandOption("sourceFolder", descriptions_default.options["sourceFolder"].demandText);
929
- };
930
- var handler7 = async (argv) => {
931
- debug10("handler", command7, argv);
932
- const { hg, json, apikey, env: env2, flow, tap, all, tenant, sourceFolder } = argv;
933
- const { clientApiBaseUri } = hg;
934
- if (!all && !tap) {
935
- throw new Error(`${descriptions_default.options["tap"].demandText} Or you can pass the --all flag to run this command for all taps/connectors.`);
936
- }
937
- let message;
938
- let spinner = ora4();
939
- const folderPrefix = path6.resolve(process.cwd(), sourceFolder);
940
- try {
941
- message = themed(`Deploying script for Tenant ${themed(tenant, "info")} Flow ${themed(flow, "info")}${tap ? ` and Tap ${themed(tap, "info")}` : ""} to ${themed(env2, "info")}`);
942
- !json && spinner.info(themed(`Info: ${message}.`, "secondary"));
943
- const deployableFiles = await getFolderFiles(folderPrefix, {
944
- recursive: true,
945
- filter: { pattern: "!((**/sync-output)|(**/etl-output)|(**/snapshots))" }
946
- });
947
- if (deployableFiles.length === 0) {
948
- json ? printJSON({ status: "error", error: "There are no files to deploy at the specified location!" }) : spinner.fail(themed(`Error: ${themed("There are no files to deploy at the specified location!")}.`, "secondary"));
949
- return;
950
- }
951
- message = themed(`Verifying user and authorizing`);
952
- !json && spinner.start(themed(`In progress: ${message}...`, "secondary"));
953
- const params = {
954
- debug: debug10,
955
- baseUri: clientApiBaseUri,
956
- task: "etl-deploy",
957
- env: env2,
958
- tenant,
959
- flow,
960
- apikey
961
- };
962
- if (tap)
963
- params.tap = tap;
964
- const { accessKeyId, secretAccessKey, sessionToken } = await genCredentialsOnClientApi(params);
965
- !json && spinner.succeed(themed(`Finished: ${message}.`, "secondary"));
966
- const s3 = new AWS4.S3({
967
- accessKeyId,
968
- secretAccessKey,
969
- sessionToken
970
- });
971
- const isV2 = await isV2Flow(s3, env2, tenant, flow);
972
- message = themed(`Validating flow and tap location`);
973
- !json && spinner.start(themed(`In progress: ${message}...`, "secondary"));
974
- const supportedFlows = await getSupportedFlows({
975
- debug: debug10,
976
- baseUri: clientApiBaseUri,
977
- apikey,
978
- env: env2
979
- });
980
- const supportedFlow = supportedFlows.find(({ id }) => id === flow);
981
- let connectors = [];
982
- try {
983
- if (tenant === "default" || supportedFlow?.type) {
984
- const supportedSources = isV2 ? await getSupportedConnectors({
985
- debug: debug10,
986
- baseUri: clientApiBaseUri,
987
- env: env2,
988
- flow,
989
- apikey
990
- }) : await getSupportedSources({
991
- debug: debug10,
992
- baseUri: clientApiBaseUri,
993
- env: env2,
994
- flow,
995
- apikey
996
- });
997
- connectors = (supportedSources ?? []).filter((ss) => tap ? ss[isV2 ? "id" : "tap"] === tap : true);
998
- if (tap && connectors.length === 0)
999
- throw new Error("Tap is not supported");
1000
- } else {
1001
- const linkedSources = isV2 ? await getLinkedConnectors({
1002
- debug: debug10,
1003
- baseUri: clientApiBaseUri,
1004
- env: env2,
1005
- flow,
1006
- tenant,
1007
- apikey
1008
- }) : await getLinkedSources({
1009
- debug: debug10,
1010
- baseUri: clientApiBaseUri,
1011
- env: env2,
1012
- flow,
1013
- tenant,
1014
- apikey
1015
- });
1016
- connectors = (linkedSources ?? []).filter((ls) => tap ? ls[isV2 ? "id" : "tap"] === tap : true);
1017
- if (tap && connectors.length === 0)
1018
- throw new Error("Tap is not linked");
1019
- }
1020
- } catch (err) {
1021
- debug10("err", err);
1022
- throw new Error(`Target location doesn't exist. Check your tenant, flow and tap arguments.`);
1023
- }
1024
- !json && spinner.succeed(themed(`Finished: ${message}.`, "secondary"));
1025
- const table = new Table6({ head: ["File", "Status"] });
1026
- for (const connector of connectors) {
1027
- const connectorId = connector[isV2 ? "id" : "tap"];
1028
- message = themed(`Preparing ${connectorId} deployment target`);
1029
- !json && spinner.start(themed(`In progress: ${message}...`, "secondary"));
1030
- const rootKey = `${tenant}/flows/${flow}/${await getEntityLabel(null, null, null, null, isV2)}/${connectorId}/etl/`;
1031
- const { Contents } = await s3.listObjectsV2({ Bucket: env2, Prefix: `${rootKey}` }).promise();
1032
- !json && spinner.succeed(themed(`Finished: ${message}.`, "secondary"));
1033
- debug10("contents", Contents);
1034
- const filesToDelete = Contents.map((item) => ({ Key: item.Key }));
1035
- if (filesToDelete.length > 0) {
1036
- message = themed(`Removing old ${connectorId} ETL files`);
1037
- !json && spinner.start(themed(`In progress: ${message}...`, "secondary"));
1038
- const delParams = {
1039
- Bucket: env2,
1040
- Delete: { Objects: filesToDelete, Quiet: true }
1041
- };
1042
- await s3.deleteObjects(delParams).promise();
1043
- filesToDelete.forEach(({ Key }) => table.push([`${connectorId}/${Key.substring(rootKey.length)}`, themed("Deleted", "warn")]));
1044
- !json && spinner.succeed(themed(`Finished: ${message}.`, "secondary"));
1045
- }
1046
- for await (const file of deployableFiles) {
1047
- const relativePath = process.platform === "win32" ? path6.relative(sourceFolder, file).replace(/\\/g, "/") : path6.relative(sourceFolder, file);
1048
- const key = `${rootKey}${relativePath}`;
1049
- message = themed(`Deploying file: ${themed(`${connectorId}/${relativePath}`, "info")}`);
1050
- !json && spinner.start(themed(`In progress: ${message}...`, "secondary"));
1051
- const readBuffer = await readFile2(file);
1052
- const params2 = {
1053
- Bucket: env2,
1054
- Key: key,
1055
- Body: readBuffer
1056
- };
1057
- const res = await s3.putObject(params2).promise();
1058
- !json && spinner.succeed(themed(`Finished: ${message}.`, "secondary"));
1059
- debug10("s3-put-res", res);
1060
- table.push([`${connectorId}/${relativePath}`, themed("Deployed", "info")]);
1061
- }
1062
- }
1063
- if (json) {
1064
- printJSON({ status: "success", deployedFiles: deployableFiles });
1065
- } else {
1066
- cl(table.toString());
1067
- }
1068
- } catch (err) {
1069
- if (json) {
1070
- printJSON({ status: "error", error: err });
1071
- } else {
1072
- spinner.fail(themed(`Error: ${message}.`, "secondary"));
1073
- pr(themed(`Message: ${themed(err.message)}`, "secondary"));
1074
- debug10(err);
1075
- if (err && err.response && err.response.data) {
1076
- debug10("response", err.response.data);
1077
- }
1078
- }
1079
- }
1080
- };
1081
-
1082
- // src/commands/etl/download.js
1083
- var download_exports2 = {};
1084
- __export(download_exports2, {
1085
- builder: () => builder8,
1086
- command: () => command8,
1087
- desc: () => desc8,
1088
- handler: () => handler8
1089
- });
1090
- import path7 from "path";
1091
- import { mkdir as mkdir3, writeFile as writeFile3, stat as stat2 } from "fs/promises";
1092
- import { existsSync } from "fs";
1093
- import ora5 from "../../node_modules/ora/index.js";
1094
- import axios4 from "../../node_modules/axios/index.js";
1095
- import Table7 from "../../node_modules/cli-table/lib/index.js";
1096
- import AWS5 from "../../node_modules/aws-sdk/lib/aws.js";
1097
- import ProgressBar from "../../node_modules/progress/index.js";
1098
- var debug11 = debug_default("commands:etl:download");
1099
- var command8 = "download";
1100
- var desc8 = "Download ETL scripts";
1101
- var builder8 = async (yargs2) => {
1102
- debug11("builder", command8);
1103
- return yargs2.option("flow", descriptions_default.options["flow"].config).demandOption("flow", descriptions_default.options["flow"].demandText).option("tap", descriptions_default.options["tap"].config).demandOption("tap", descriptions_default.options["tap"].demandText).option("downloadTo", descriptions_default.options["downloadTo"].config).demandOption("downloadTo", descriptions_default.options["downloadTo"].demandText).option("tenant", { ...descriptions_default.options["tenant"].config, default: "default" }).option("overwrite", descriptions_default.options["overwrite"].config).demandOption("overwrite", descriptions_default.options["overwrite"].demandText);
1104
- };
1105
- var handler8 = async (argv) => {
1106
- debug11("handler", command8, argv);
1107
- const { hg, json, apikey, env: env2, flow, tap, tenant, downloadTo, overwrite } = argv;
1108
- const { clientApiBaseUri } = hg;
1109
- let message;
1110
- let spinner = ora5();
1111
- const folderPrefix = path7.resolve(process.cwd(), downloadTo);
1112
- try {
1113
- message = themed(`Verifying user and authorizing`);
1114
- !json && spinner.start(themed(`In progress: ${message}...`, "secondary"));
1115
- const { accessKeyId, secretAccessKey, sessionToken } = await genCredentialsOnClientApi({
1116
- debug: debug11,
1117
- baseUri: clientApiBaseUri,
1118
- task: "etl-download",
1119
- env: env2,
1120
- tenant,
1121
- flow,
1122
- tap,
1123
- apikey
1124
- });
1125
- const s3 = new AWS5.S3({
1126
- accessKeyId,
1127
- secretAccessKey,
1128
- sessionToken
1129
- });
1130
- !json && spinner.succeed(themed(`Finished: ${message}.`, "secondary"));
1131
- message = themed(`Scanning for downloadable files`);
1132
- !json && spinner.start(themed(`In progress: ${message}...`, "secondary"));
1133
- const keyPrefix = `${tenant}/flows/${flow}/${await getEntityLabel(s3, env2, tenant, flow)}/${tap}/etl/`;
1134
- const params = {
1135
- Bucket: env2,
1136
- Prefix: keyPrefix
1137
- };
1138
- const { Contents: s3Files } = await s3.listObjectsV2(params).promise();
1139
- !json && spinner.succeed(themed(`Finished: ${message}.`, "secondary"));
1140
- debug11("s3-list-res", s3Files);
1141
- const filesToDownload = s3Files ? filterFiles(s3Files.map((item) => item.Key), { pattern: "!(.ipynb_checkpoints/*)" }) : [];
1142
- if (!filesToDownload || filesToDownload.length === 0) {
1143
- json ? printJSON({ status: "success", downloadedFiles: [] }) : spinner.warn(themed(`Warning: ${themed("Nothing to download!")}`, "secondary"));
1144
- return;
1145
- }
1146
- message = themed(`Downloading script files to ${themed(folderPrefix, "info")}`);
1147
- !json && spinner.info(themed(`Info: ${message}.`, "secondary"));
1148
- const table = new Table7({ head: ["File", "Status"] });
1149
- for await (const file of filesToDownload) {
1150
- const subPath = file.substring(keyPrefix.length);
1151
- const fullPath = path7.resolve(folderPrefix, subPath);
1152
- debug11("file", fullPath);
1153
- if (file.endsWith("/")) {
1154
- !existsSync(fullPath) && await mkdir3(fullPath, { recursive: true });
1155
- continue;
1156
- }
1157
- if (!overwrite) {
1158
- try {
1159
- await stat2(fullPath);
1160
- debug11("exists, skipping");
1161
- table.push([subPath, "Skipped"]);
1162
- continue;
1163
- } catch (err) {
1164
- if (err.code !== "ENOENT")
1165
- cl(err);
1166
- }
1167
- }
1168
- message = themed(`Downloading file: ${themed(subPath, "info")}`);
1169
- !json && spinner.start(themed(`In progress: ${message}...`, "secondary"));
1170
- await mkdir3(path7.dirname(fullPath), { recursive: true });
1171
- const fileStream = s3.getObject({ Bucket: env2, Key: file }).createReadStream();
1172
- await writeFile3(fullPath, await streamToString(fileStream));
1173
- !json && spinner.succeed(themed(`Finished: ${message}.`, "secondary"));
1174
- table.push([subPath, "Downloaded"]);
1175
- }
1176
- if (json) {
1177
- printJSON({ status: "success", downloadedFiles: filesToDownload });
1178
- } else {
1179
- cl(table.toString());
1180
- }
1181
- } catch (err) {
1182
- if (json) {
1183
- printJSON({ status: "error", error: err });
1184
- } else {
1185
- spinner.fail(themed(`Error: ${message}.`, "secondary"));
1186
- pr(themed(`Message: ${themed(err.message)}`, "secondary"));
1187
- debug11(err);
1188
- if (err && err.response && err.response.data) {
1189
- debug11("response", err.response.data);
1190
- }
1191
- }
1192
- }
1193
- };
1194
-
1195
- // src/commands/etl/index.js
1196
- var etl = [delete_exports, deploy_exports2, download_exports2];
1197
-
1198
- // src/commands/etl.js
1199
- var debug12 = debug_default("commands:etl");
1200
- var command9 = "etl <action>";
1201
- var desc9 = "Manage ETL scripts";
1202
- var builder9 = async function(yargs2) {
1203
- debug12("builder", command9);
1204
- const base = await baseApiBuilder(yargs2);
1205
- return base.command(etl);
1206
- };
1207
- var handler9 = async function(argv) {
1208
- debug12("handler", command9, argv);
1209
- };
1210
-
1211
- // src/commands/flows.js
1212
- var flows_exports = {};
1213
- __export(flows_exports, {
1214
- builder: () => builder11,
1215
- command: () => command11,
1216
- desc: () => desc11,
1217
- handler: () => handler11
1218
- });
1219
-
1220
- // src/commands/flows/list.js
1221
- var list_exports = {};
1222
- __export(list_exports, {
1223
- builder: () => builder10,
1224
- command: () => command10,
1225
- desc: () => desc10,
1226
- handler: () => handler10
1227
- });
1228
- import { inspect as inspect2 } from "util";
1229
- import ora6 from "../../node_modules/ora/index.js";
1230
- import axios5 from "../../node_modules/axios/index.js";
1231
- import Table8 from "../../node_modules/cli-table/lib/index.js";
1232
- var debug13 = debug_default("commands:flows:list");
1233
- var command10 = "list";
1234
- var desc10 = "List flows";
1235
- var builder10 = async (yargs2) => {
1236
- debug13("builder", command10);
1237
- return yargs2.option("tenant", { ...descriptions_default.options["tenant"].config });
1238
- };
1239
- var handler10 = async (argv) => {
1240
- debug13("handler", command10, argv);
1241
- const { hg, json, apikey, env: env2, tenant } = argv;
1242
- const { clientApiBaseUri } = hg;
1243
- let message;
1244
- let spinner = ora6();
1245
- try {
1246
- message = themed(`Retrieving ${!tenant ? `the` : `${themed(tenant, "info")} tenant's`} flows for environment: ${themed(env2, "info")}`);
1247
- const uri = `${clientApiBaseUri}/${env2}/flows/${tenant ? `linked?user_id=${tenant}` : `supported`}`;
1248
- debug13("requesting:", uri);
1249
- !json && spinner.start(themed(`In progress: ${message}...`, "secondary"));
1250
- const { data } = await axios5.get(uri, { headers: { "x-api-key": apikey } });
1251
- !json && spinner.succeed(themed(`Finished: ${message}.`, "secondary"));
1252
- debug13("response-data", data);
1253
- if (!data || data.length === 0) {
1254
- json ? printJSON([]) : spinner.warn(themed(`Warning: ${themed("No flows for specified environment and tenant")}.`, "secondary"));
1255
- return;
1256
- }
1257
- if (json) {
1258
- printJSON(data);
1259
- } else {
1260
- const table = new Table8({ head: ["ID", "Name", "isPush", "Taps", "Targets"] });
1261
- data.forEach((item) => table.push([
1262
- item.id,
1263
- item.name || "",
1264
- item.type || false,
1265
- item.taps ? inspect2(item.taps) : "",
1266
- item.targets ? inspect2(item.targets) : "none"
1267
- ]));
1268
- console.log(table.toString());
1269
- }
1270
- } catch (err) {
1271
- if (json) {
1272
- printJSON({ status: "error", error: err });
1273
- } else {
1274
- spinner.fail(themed(`Error: ${message}.`, "secondary"));
1275
- pr(themed(`Message: ${themed(err.message)}`, "secondary"));
1276
- debug13(err);
1277
- if (err && err.response && err.response.data) {
1278
- debug13("response", err.response.data);
1279
- }
1280
- }
1281
- }
1282
- };
1283
-
1284
- // src/commands/flows/index.js
1285
- var flows = [list_exports];
1286
-
1287
- // src/commands/flows.js
1288
- var debug14 = debug_default("commands:flows");
1289
- var command11 = "flows <action>";
1290
- var desc11 = "Manage flows";
1291
- var builder11 = async function(yargs2) {
1292
- debug14("builder", command11);
1293
- const base = await baseApiBuilder(yargs2);
1294
- return base.command(flows);
1295
- };
1296
- var handler11 = async function(argv) {
1297
- debug14("handler", command11, argv);
1298
- };
1299
-
1300
- // src/commands/jobs.js
1301
- var jobs_exports = {};
1302
- __export(jobs_exports, {
1303
- builder: () => builder14,
1304
- command: () => command14,
1305
- desc: () => desc14,
1306
- handler: () => handler14
1307
- });
1308
-
1309
- // src/commands/jobs/download.js
1310
- var download_exports3 = {};
1311
- __export(download_exports3, {
1312
- builder: () => builder12,
1313
- command: () => command12,
1314
- desc: () => desc12,
1315
- handler: () => handler12
1316
- });
1317
- import path8 from "path";
1318
- import { mkdir as mkdir4 } from "node:fs/promises";
1319
- import { createWriteStream } from "fs";
1320
- import ora7 from "../../node_modules/ora/index.js";
1321
- import Table9 from "../../node_modules/cli-table/lib/index.js";
1322
- import AWS6 from "../../node_modules/aws-sdk/lib/aws.js";
1323
- import eachSeries from "../../node_modules/async/eachSeries.js";
1324
- var debug15 = debug_default("commands:jobs:download");
1325
- var command12 = "download <jobroot>";
1326
- var desc12 = "Download Job files";
1327
- var builder12 = async (yargs2) => {
1328
- debug15("builder", command12);
1329
- return yargs2.option("downloadTo", descriptions_default.options["downloadTo"].config);
1330
- };
1331
- var handler12 = async (argv) => {
1332
- debug15("handler", command12, argv);
1333
- const { hg, json, apikey, env: env2, jobroot, downloadTo } = argv;
1334
- const { clientApiBaseUri } = hg;
1335
- let message;
1336
- let spinner = ora7();
1337
- try {
1338
- message = themed(`Verifying user and authorizing`);
1339
- !json && spinner.start(themed(`In progress: ${message}...`, "secondary"));
1340
- const { accessKeyId, secretAccessKey, sessionToken } = await genCredentialsOnClientApi({
1341
- debug: debug15,
1342
- baseUri: clientApiBaseUri,
1343
- task: "job-download",
1344
- env: env2,
1345
- apikey,
1346
- jobroot
1347
- });
1348
- const s3 = new AWS6.S3({
1349
- accessKeyId,
1350
- secretAccessKey,
1351
- sessionToken
1352
- });
1353
- !json && spinner.succeed(themed(`Finished: ${message}.`, "secondary"));
1354
- message = themed(`Scanning for downloadable files`);
1355
- !json && spinner.start(themed(`In progress: ${message}...`, "secondary"));
1356
- const params = {
1357
- Bucket: env2,
1358
- Prefix: jobroot
1359
- };
1360
- const { Contents: filesList } = await s3.listObjectsV2(params).promise();
1361
- debug15("res", filesList);
1362
- if (!filesList || filesList.length === 0) {
1363
- if (json) {
1364
- printJSON({ status: "error", error: "Nothing to download!" });
1365
- } else {
1366
- spinner.fail(themed(`Error: ${message}.`, "secondary"));
1367
- pr(themed(`Message: ${themed("Nothing to download!")}`, "secondary"));
1368
- }
1369
- return;
1370
- }
1371
- !json && spinner.succeed(themed(`Finished: ${message}.`, "secondary"));
1372
- if (!json) {
1373
- const table = new Table9({ head: ["File", "Size", "LastModified"] });
1374
- filesList.forEach((item) => {
1375
- const subPath = item.Key.substring(jobroot.length + 1);
1376
- table.push([subPath, item.Size, item.LastModified.toLocaleString("en-US")]);
1377
- });
1378
- console.log(table.toString());
1379
- }
1380
- const localRoot = path8.resolve(process.cwd(), downloadTo, path8.basename(jobroot));
1381
- await eachSeries(filesList.filter(({ Key }) => {
1382
- const regex = new RegExp(`${jobroot}/([^/]+)-config.json`);
1383
- return !regex.test(Key);
1384
- }), async (item) => {
1385
- message = themed(`Downloading file: ${themed(item.Key, "info")}`);
1386
- !json && spinner.start(themed(`In progress: ${message}...`, "secondary"));
1387
- const file = path8.resolve(localRoot, item.Key.substring(jobroot.length + 1));
1388
- debug15("file", file);
1389
- await mkdir4(path8.dirname(file), { recursive: true });
1390
- const fileStream = s3.getObject({ Bucket: env2, Key: item.Key }).createReadStream();
1391
- const writableStream = createWriteStream(file, { flags: "w" });
1392
- fileStream.pipe(writableStream);
1393
- !json && spinner.succeed(themed(`Finished: ${message}.`, "secondary"));
1394
- });
1395
- if (json) {
1396
- printJSON({ status: "success", downloadedFiles: filesList.map(({ Key }) => Key) });
1397
- } else {
1398
- message = themed(`Downloading job files.`);
1399
- spinner.succeed(themed(`Finished: ${message}`, "secondary"));
1400
- }
1401
- } catch (err) {
1402
- if (json) {
1403
- printJSON({ status: "error", error: err });
1404
- } else {
1405
- spinner.fail(themed(`Error: ${message}.`, "secondary"));
1406
- pr(themed(`Message: ${themed(err.message)}`, "secondary"));
1407
- debug15(err);
1408
- if (err && err.response && err.response.data) {
1409
- debug15("response", err.response.data);
1410
- }
1411
- }
1412
- }
1413
- };
1414
-
1415
- // src/commands/jobs/list.js
1416
- var list_exports2 = {};
1417
- __export(list_exports2, {
1418
- builder: () => builder13,
1419
- command: () => command13,
1420
- desc: () => desc13,
1421
- handler: () => handler13
1422
- });
1423
- import ora8 from "../../node_modules/ora/index.js";
1424
- import axios6 from "../../node_modules/axios/index.js";
1425
- import Table10 from "../../node_modules/cli-table/lib/index.js";
1426
- var debug16 = (...args) => {
1427
- const debug27 = debug_default("commands:jobs:list");
1428
- debug27(...args);
1429
- };
1430
- var command13 = "list";
1431
- var desc13 = "List jobs";
1432
- var builder13 = async (yargs2) => {
1433
- debug16("builder", command13);
1434
- return yargs2.option("flow", descriptions_default.options["flow"].config).demandOption("flow", descriptions_default.options["flow"].demandText).option("tenant", { ...descriptions_default.options["tenant"].config, default: "default" }).option("count", descriptions_default.options["count"].config);
1435
- };
1436
- var handler13 = async (argv) => {
1437
- debug16("handler", command13, argv);
1438
- const { hg, json, apikey, env: env2, flow, tenant, count } = argv;
1439
- const { clientApiBaseUri } = hg;
1440
- let message;
1441
- let spinner = ora8();
1442
- try {
1443
- message = themed(`Retrieving jobs for environment: ${themed(env2, "info")} flow: ${themed(flow, "info")} tenant: ${themed(tenant, "info")}...`);
1444
- const uri = `${clientApiBaseUri}/${env2}/${flow}/${tenant}/jobs${count ? `?count=${count}` : ""}`;
1445
- debug16("requesting:", uri);
1446
- !json && spinner.start(themed(`In progress: ${message}...`, "secondary"));
1447
- const { data } = await axios6.get(uri, { headers: { "x-api-key": apikey } });
1448
- !json && spinner.succeed(themed(`Finished: ${message}.`, "secondary"));
1449
- debug16("response-data", data);
1450
- if (!data || data.length === 0) {
1451
- json ? printJSON([]) : spinner.warn(themed(`Warning: ${themed("No jobs for the specified environment, flow and tenant")}.`, "secondary"));
1452
- return;
1453
- }
1454
- if (json) {
1455
- printJSON(data);
1456
- } else {
1457
- const table = new Table10({ head: ["name", "details"] });
1458
- data.forEach((item) => table.push([item.job_name, JSON.stringify(item, void 0, 2)]));
1459
- console.log(table.toString());
1460
- }
1461
- } catch (err) {
1462
- if (json) {
1463
- printJSON({ status: "error", error: err });
1464
- } else {
1465
- spinner.fail(themed(`Error: ${message}.`, "secondary"));
1466
- pr(themed(`Message: ${themed(err.message)}`, "secondary"));
1467
- debug16(err);
1468
- if (err && err.response && err.response.data) {
1469
- debug16("response", err.response.data);
1470
- }
1471
- }
1472
- }
1473
- };
1474
-
1475
- // src/commands/jobs/index.js
1476
- var jobs = [download_exports3, list_exports2];
1477
-
1478
- // src/commands/jobs.js
1479
- var debug17 = debug_default("commands:jobs");
1480
- var command14 = "jobs <action>";
1481
- var desc14 = "Manage ETL jobs";
1482
- var builder14 = async function(yargs2) {
1483
- debug17("builder", command14);
1484
- const base = await baseApiBuilder(yargs2);
1485
- return base.command(jobs);
1486
- };
1487
- var handler14 = async function(argv) {
1488
- debug17("handler", command14, argv);
1489
- };
1490
-
1491
- // src/commands/snapshots.js
1492
- var snapshots_exports = {};
1493
- __export(snapshots_exports, {
1494
- builder: () => builder17,
1495
- command: () => command17,
1496
- desc: () => desc17,
1497
- handler: () => handler17
1498
- });
1499
-
1500
- // src/commands/snapshots/deploy.js
1501
- var deploy_exports3 = {};
1502
- __export(deploy_exports3, {
1503
- builder: () => builder15,
1504
- command: () => command15,
1505
- desc: () => desc15,
1506
- handler: () => handler15
1507
- });
1508
- import path9 from "path";
1509
- import { readdir as readdir3, readFile as readFile3 } from "fs/promises";
1510
- import ora9 from "../../node_modules/ora/index.js";
1511
- import axios7 from "../../node_modules/axios/index.js";
1512
- import AWS7 from "../../node_modules/aws-sdk/lib/aws.js";
1513
- import Table11 from "../../node_modules/cli-table/lib/index.js";
1514
- var debug18 = debug_default("commands:snapshots:deploy");
1515
- var command15 = "deploy";
1516
- var desc15 = "Deploy Snapshots";
1517
- var builder15 = async (yargs2) => {
1518
- debug18("builder", command15);
1519
- return yargs2.option("tenant", { ...descriptions_default.options["tenant"].config, default: "default" }).option("sourceFolder", descriptions_default.options["sourceFolder"].config).demandOption("sourceFolder", descriptions_default.options["sourceFolder"].demandText);
1520
- };
1521
- var handler15 = async (argv) => {
1522
- debug18("handler", command15, argv);
1523
- const { hg, json, apikey, env: env2, tenant, sourceFolder } = argv;
1524
- const { clientApiBaseUri } = hg;
1525
- let message;
1526
- let spinner = ora9();
1527
- const folderPrefix = path9.resolve(process.cwd(), sourceFolder);
1528
- try {
1529
- message = themed(`Deploying Snapshots for Tenant ${themed(tenant, "info")} to ${themed(env2, "info")}`);
1530
- !json && spinner.info(themed(`Info: ${message}.`, "secondary"));
1531
- const deployableFiles = await getFolderFiles(folderPrefix, {
1532
- recursive: true
1533
- });
1534
- if (deployableFiles.length === 0) {
1535
- json ? printJSON({ status: "error", error: "There are no files to deploy at the specified location!" }) : spinner.fail(themed(`Error: ${themed("There are no files to deploy at the specified location!")}.`, "secondary"));
1536
- return;
1537
- }
1538
- message = themed(`Verifying user and authorizing`);
1539
- const { accessKeyId, secretAccessKey, sessionToken } = await genCredentialsOnClientApi({
1540
- debug: debug18,
1541
- baseUri: clientApiBaseUri,
1542
- task: "snapshot-deploy",
1543
- env: env2,
1544
- tenant,
1545
- apikey
1546
- });
1547
- !json && spinner.succeed(themed(`Finished: ${message}.`, "secondary"));
1548
- const s3 = new AWS7.S3({
1549
- accessKeyId,
1550
- secretAccessKey,
1551
- sessionToken
1552
- });
1553
- message = themed(`Validating tenant exists`);
1554
- !json && spinner.start(themed(`In progress: ${message}...`, "secondary"));
1555
- try {
1556
- const { CommonPrefixes: tenantFolders } = await s3.listObjectsV2({ Bucket: env2, Prefix: `${tenant}/`, Delimiter: "/" }).promise();
1557
- if (tenantFolders.length === 0)
1558
- throw new Error("Invalid tenant");
1559
- } catch (err) {
1560
- debug18("err", err);
1561
- throw new Error(`Tenant doesn't exist. Please check your tenant (-u) argument.`);
1562
- }
1563
- !json && spinner.succeed(themed(`Finished: ${message}.`, "secondary"));
1564
- const rootKey = `${tenant}/snapshots/`;
1565
- const table = new Table11({ head: ["File", "Status"] });
1566
- message = themed(`Preparing deployment target`);
1567
- !json && spinner.start(themed(`In progress: ${message}...`, "secondary"));
1568
- const { Contents } = await s3.listObjectsV2({ Bucket: env2, Prefix: `${rootKey}` }).promise();
1569
- !json && spinner.stop();
1570
- debug18("contents", Contents);
1571
- !json && spinner.start(themed(`In progress: ${message}...`, "secondary"));
1572
- const filesToDelete = Contents.map((item) => ({ Key: item.Key }));
1573
- if (filesToDelete.length > 0) {
1574
- const delParams = {
1575
- Bucket: env2,
1576
- Delete: { Objects: filesToDelete, Quiet: true }
1577
- };
1578
- await s3.deleteObjects(delParams).promise();
1579
- filesToDelete.forEach(({ Key }) => table.push([Key.substring(rootKey.length), themed("Deleted", "warn")]));
1580
- }
1581
- !json && spinner.succeed(themed(`Finished: ${message}.`, "secondary"));
1582
- for await (const file of deployableFiles) {
1583
- const relativePath = path9.relative(sourceFolder, file);
1584
- const key = `${rootKey}${relativePath}`;
1585
- message = themed(`Deploying file: ${themed(relativePath, "info")}`);
1586
- !json && spinner.start(themed(`In progress: ${message}...`, "secondary"));
1587
- const readBuffer = await readFile3(file);
1588
- const params = {
1589
- Bucket: env2,
1590
- Key: key,
1591
- Body: readBuffer
1592
- };
1593
- const res = await s3.putObject(params).promise();
1594
- !json && spinner.succeed(themed(`Finished: ${message}.`, "secondary"));
1595
- debug18("s3-put-res", res);
1596
- table.push([relativePath, themed("Deployed", "info")]);
1597
- }
1598
- if (json) {
1599
- printJSON({ status: "success", deployedFiles: deployableFiles });
1600
- } else {
1601
- cl(table.toString());
1602
- }
1603
- } catch (err) {
1604
- if (json) {
1605
- printJSON({ status: "error", error: err });
1606
- } else {
1607
- spinner.fail(themed(`Error: ${message}.`, "secondary"));
1608
- pr(themed(`Message: ${themed(err.message)}`, "secondary"));
1609
- debug18(err);
1610
- if (err && err.response && err.response.data) {
1611
- debug18("response", err.response.data);
1612
- }
1613
- }
1614
- }
1615
- };
1616
-
1617
- // src/commands/snapshots/download.js
1618
- var download_exports4 = {};
1619
- __export(download_exports4, {
1620
- builder: () => builder16,
1621
- command: () => command16,
1622
- desc: () => desc16,
1623
- handler: () => handler16
1624
- });
1625
- import path10 from "path";
1626
- import { mkdir as mkdir5, writeFile as writeFile4, stat as stat3 } from "fs/promises";
1627
- import { existsSync as existsSync2 } from "fs";
1628
- import ora10 from "../../node_modules/ora/index.js";
1629
- import Table12 from "../../node_modules/cli-table/lib/index.js";
1630
- import AWS8 from "../../node_modules/aws-sdk/lib/aws.js";
1631
- var debug19 = debug_default("commands:snapshots:download");
1632
- var command16 = "download";
1633
- var desc16 = "Download Snapshots";
1634
- var builder16 = async (yargs2) => {
1635
- debug19("builder", command16);
1636
- return yargs2.option("downloadTo", descriptions_default.options["downloadTo"].config).demandOption("downloadTo", descriptions_default.options["downloadTo"].demandText).option("tenant", { ...descriptions_default.options["tenant"].config, default: "default" }).option("overwrite", descriptions_default.options["overwrite"].config).demandOption("overwrite", descriptions_default.options["overwrite"].demandText);
1637
- };
1638
- var handler16 = async (argv) => {
1639
- debug19("handler", command16, argv);
1640
- const { hg, json, apikey, env: env2, tenant, downloadTo, overwrite } = argv;
1641
- const { clientApiBaseUri } = hg;
1642
- let message;
1643
- let spinner = ora10();
1644
- const folderPrefix = path10.resolve(process.cwd(), userSetOption("downloadTo") ? downloadTo : "snapshots");
1645
- try {
1646
- message = themed(`Verifying user and authorizing`);
1647
- !json && spinner.start(themed(`In progress: ${message}...`, "secondary"));
1648
- const { accessKeyId, secretAccessKey, sessionToken } = await genCredentialsOnClientApi({
1649
- debug: debug19,
1650
- baseUri: clientApiBaseUri,
1651
- task: "snapshot-download",
1652
- env: env2,
1653
- tenant,
1654
- apikey
1655
- });
1656
- const s3 = new AWS8.S3({
1657
- accessKeyId,
1658
- secretAccessKey,
1659
- sessionToken
1660
- });
1661
- !json && spinner.succeed(themed(`Finished: ${message}.`, "secondary"));
1662
- message = themed(`Validating tenant exists`);
1663
- !json && spinner.start(themed(`In progress: ${message}...`, "secondary"));
1664
- try {
1665
- const { CommonPrefixes: tenantFolders } = await s3.listObjectsV2({ Bucket: env2, Prefix: `${tenant}/`, Delimiter: "/" }).promise();
1666
- if (tenantFolders.length === 0)
1667
- throw new Error("Invalid tenant");
1668
- } catch (err) {
1669
- debug19("err", err);
1670
- throw new Error(`Tenant doesn't exist. Please check your tenant (-u) argument.`);
1671
- }
1672
- !json && spinner.succeed(themed(`Finished: ${message}.`, "secondary"));
1673
- message = themed(`Scanning for downloadable files`);
1674
- !json && spinner.start(themed(`In progress: ${message}...`, "secondary"));
1675
- const keyPrefix = `${tenant}/snapshots/`;
1676
- const params = {
1677
- Bucket: env2,
1678
- Prefix: keyPrefix
1679
- };
1680
- const { Contents: s3Files } = await s3.listObjectsV2(params).promise();
1681
- !json && spinner.succeed(themed(`Finished: ${message}.`, "secondary"));
1682
- debug19("s3-list-res", s3Files);
1683
- const filesToDownload = s3Files ? s3Files.map((item) => item.Key).filter((item) => item !== keyPrefix) : [];
1684
- if (!filesToDownload || filesToDownload.length === 0) {
1685
- json ? printJSON({ status: "success", downloadedFiles: [] }) : spinner.warn(themed(`Warning: ${themed("Nothing to download!")}`, "secondary"));
1686
- return;
1687
- }
1688
- message = themed(`Downloading snapshot files to ${themed(folderPrefix, "info")}`);
1689
- !json && spinner.info(themed(`Info: ${message}.`, "secondary"));
1690
- const table = new Table12({ head: ["File", "Status"] });
1691
- for await (const file of filesToDownload) {
1692
- const subPath = file.substring(keyPrefix.length);
1693
- const fullPath = path10.resolve(folderPrefix, subPath);
1694
- debug19("file", fullPath);
1695
- if (file.endsWith("/")) {
1696
- !existsSync2(fullPath) && await mkdir5(fullPath, { recursive: true });
1697
- continue;
1698
- }
1699
- if (!overwrite) {
1700
- try {
1701
- await stat3(fullPath);
1702
- debug19("exists, skipping");
1703
- table.push([subPath, "Skipped"]);
1704
- continue;
1705
- } catch (err) {
1706
- if (err.code !== "ENOENT")
1707
- cl(err);
1708
- }
1709
- }
1710
- message = themed(`Downloading file: ${themed(subPath, "info")}`);
1711
- !json && spinner.start(themed(`In progress: ${message}...`, "secondary"));
1712
- await mkdir5(path10.dirname(fullPath), { recursive: true });
1713
- const fileStream = s3.getObject({ Bucket: env2, Key: file }).createReadStream();
1714
- await writeFile4(fullPath, await streamToString(fileStream));
1715
- !json && spinner.succeed(themed(`Finished: ${message}.`, "secondary"));
1716
- table.push([subPath, "Downloaded"]);
1717
- }
1718
- if (json) {
1719
- printJSON({ status: "success", downloadedFiles: filesToDownload });
1720
- } else {
1721
- cl(table.toString());
1722
- }
1723
- } catch (err) {
1724
- if (json) {
1725
- printJSON({ status: "error", error: err });
1726
- } else {
1727
- spinner.fail(themed(`Error: ${message}.`, "secondary"));
1728
- pr(themed(`Message: ${themed(err.message)}`, "secondary"));
1729
- debug19(err);
1730
- if (err && err.response && err.response.data) {
1731
- debug19("response", err.response.data);
1732
- }
1733
- }
1734
- }
1735
- };
1736
-
1737
- // src/commands/snapshots/index.js
1738
- var snapshots = [deploy_exports3, download_exports4];
1739
-
1740
- // src/commands/snapshots.js
1741
- var debug20 = debug_default("commands:snapshots");
1742
- var command17 = "snapshots <action>";
1743
- var desc17 = "Manage tenant snapshots";
1744
- var builder17 = async function(yargs2) {
1745
- debug20("builder", command17, yargs2);
1746
- const base = await baseApiBuilder(yargs2);
1747
- return base.command(snapshots);
1748
- };
1749
- var handler17 = async function(argv) {
1750
- debug20("handler", command17, argv);
1751
- };
1752
-
1753
- // src/commands/tenants.js
1754
- var tenants_exports = {};
1755
- __export(tenants_exports, {
1756
- builder: () => builder23,
1757
- command: () => command23,
1758
- desc: () => desc23,
1759
- handler: () => handler23
1760
- });
1761
-
1762
- // src/commands/tenants/customEtl.js
1763
- var customEtl_exports = {};
1764
- __export(customEtl_exports, {
1765
- builder: () => builder18,
1766
- command: () => command18,
1767
- desc: () => desc18,
1768
- handler: () => handler18
1769
- });
1770
- import ora11 from "../../node_modules/ora/index.js";
1771
- import AWS9 from "../../node_modules/aws-sdk/lib/aws.js";
1772
- import Table13 from "../../node_modules/cli-table/lib/index.js";
1773
- var debug21 = debug_default("commands:tenants:custom-etl");
1774
- var command18 = "custom-etl";
1775
- var desc18 = "List tenants with custom ETL in a specific flow";
1776
- var builder18 = async (yargs2) => {
1777
- debug21("builder", command18);
1778
- return yargs2.option("tenant", descriptions_default.options["tenant"].config).option("flow", descriptions_default.options["flow"].config).demandOption("flow", descriptions_default.options["flow"].demandText);
1779
- };
1780
- var processTenant = async ({ debug: debug27, baseUri, apikey, env: env2, flow, tenant, supportedSources }) => {
1781
- const linkedSources = await getLinkedSources({
1782
- debug: debug27,
1783
- baseUri,
1784
- env: env2,
1785
- flow,
1786
- tenant,
1787
- apikey
1788
- });
1789
- let result = null;
1790
- for (const { tap } of [...linkedSources, ...supportedSources]) {
1791
- const { accessKeyId, secretAccessKey, sessionToken } = await genCredentialsOnClientApi({
1792
- debug: debug27,
1793
- baseUri,
1794
- task: "etl-download",
1795
- env: env2,
1796
- tenant,
1797
- flow,
1798
- tap,
1799
- apikey
1800
- });
1801
- const s3 = new AWS9.S3({
1802
- accessKeyId,
1803
- secretAccessKey,
1804
- sessionToken
1805
- });
1806
- const keyPrefix = `${tenant}/flows/${flow}/taps/${tap}/etl/`;
1807
- const params = {
1808
- Bucket: env2,
1809
- Prefix: keyPrefix
1810
- };
1811
- const { Contents: s3Files } = await s3.listObjectsV2(params).promise();
1812
- const hasCustomEtl = s3Files.some(({ Key }) => Key.endsWith("etl.py") || Key.endsWith("etl.ipynb"));
1813
- if (hasCustomEtl)
1814
- result = tenant;
1815
- if (result !== null)
1816
- break;
1817
- }
1818
- return result;
1819
- };
1820
- var handler18 = async (argv) => {
1821
- debug21("handler", command18, argv);
1822
- const { hg, json, apikey, env: env2, flow } = argv;
1823
- let message;
1824
- let spinner = ora11();
1825
- try {
1826
- message = themed(`Retrieving tenants for environment ${themed(env2, "info")}`);
1827
- !json && spinner.start(themed(`In progress: ${message}...`, "secondary"));
1828
- const [allTenants, supportedSources] = await Promise.all([
1829
- getTenants({
1830
- debug: debug21,
1831
- baseUri: hg.clientApiBaseUri,
1832
- apikey,
1833
- env: env2
1834
- }),
1835
- getSupportedSources({
1836
- debug: debug21,
1837
- baseUri: hg.clientApiBaseUri,
1838
- apikey,
1839
- env: env2,
1840
- flow
1841
- })
1842
- ]);
1843
- !json && spinner.succeed(themed(`Finished: ${message}.`, "secondary"));
1844
- let tenantsWithCustomEtl = [];
1845
- message = themed(`Querying for custom ETL scripts for flow ${themed(flow, "info")}`);
1846
- !json && spinner.start(themed(`In progress: ${message}...`, "secondary"));
1847
- for (const tenants2 of buildChunks(allTenants)) {
1848
- const maybeTenantsWithCustomEtl = await Promise.all(tenants2.map((tenant) => processTenant({
1849
- debug: debug21,
1850
- baseUri: hg.clientApiBaseUri,
1851
- apikey,
1852
- env: env2,
1853
- flow,
1854
- tenant,
1855
- supportedSources
1856
- })));
1857
- tenantsWithCustomEtl = tenantsWithCustomEtl.concat(maybeTenantsWithCustomEtl.filter(Boolean));
1858
- }
1859
- !json && spinner.succeed(themed(`Finished: ${message}.`, "secondary"));
1860
- if (json) {
1861
- printJSON(tenantsWithCustomEtl);
1862
- } else {
1863
- const table = new Table13({ head: ["Tenant ID"] });
1864
- table.push(...tenantsWithCustomEtl.map((item) => [item]));
1865
- console.log(table.toString());
1866
- }
1867
- } catch (err) {
1868
- if (json) {
1869
- printJSON({ status: "error", error: err });
1870
- } else {
1871
- spinner.fail(themed(`Error: ${message}.`, "secondary"));
1872
- pr(themed(`Message: ${themed(err.message)}`, "secondary"));
1873
- debug21(err);
1874
- if (err && err.response && err.response.data) {
1875
- debug21("response", err.response.data);
1876
- }
1877
- }
1878
- }
1879
- };
1880
-
1881
- // src/commands/tenants/customFieldMap.js
1882
- var customFieldMap_exports = {};
1883
- __export(customFieldMap_exports, {
1884
- builder: () => builder19,
1885
- command: () => command19,
1886
- desc: () => desc19,
1887
- handler: () => handler19
1888
- });
1889
- import ora12 from "../../node_modules/ora/index.js";
1890
- import AWS10 from "../../node_modules/aws-sdk/lib/aws.js";
1891
- import Table14 from "../../node_modules/cli-table/lib/index.js";
1892
- var debug22 = debug_default("commands:tenants:custom-field-map");
1893
- var command19 = "custom-field-map";
1894
- var desc19 = "List tenants with custom field map in a specific flow";
1895
- var builder19 = async (yargs2) => {
1896
- debug22("builder", command19);
1897
- return yargs2.option("tenant", descriptions_default.options["tenant"].config).option("flow", descriptions_default.options["flow"].config).demandOption("flow", descriptions_default.options["flow"].demandText);
1898
- };
1899
- var processTenant2 = async ({ debug: debug27, baseUri, apikey, env: env2, flow, tenant, isV2Flow: isV2Flow2 }) => {
1900
- const linkedConnectors = isV2Flow2 ? await getLinkedConnectors({
1901
- debug: debug27,
1902
- baseUri,
1903
- env: env2,
1904
- flow,
1905
- tenant,
1906
- apikey
1907
- }) : await getLinkedSources({
1908
- debug: debug27,
1909
- baseUri,
1910
- env: env2,
1911
- flow,
1912
- tenant,
1913
- apikey
1914
- });
1915
- const connectors = [];
1916
- const { accessKeyId, secretAccessKey, sessionToken } = await genCredentialsOnClientApi({
1917
- debug: debug27,
1918
- baseUri,
1919
- task: "field-map-download",
1920
- env: env2,
1921
- tenant,
1922
- flow,
1923
- apikey
1924
- });
1925
- const s3 = new AWS10.S3({
1926
- accessKeyId,
1927
- secretAccessKey,
1928
- sessionToken
1929
- });
1930
- for (const { id, tap } of linkedConnectors) {
1931
- const entityLabel = isV2Flow2 ? "connectors" : "taps";
1932
- const params = {
1933
- Bucket: env2,
1934
- Key: `${tenant}/flows/${flow}/${entityLabel}/${isV2Flow2 ? id : tap}/fieldMap.json`
1935
- };
1936
- try {
1937
- await s3.headObject(params).promise();
1938
- connectors.push(isV2Flow2 ? id : tap);
1939
- } catch (error) {
1940
- }
1941
- }
1942
- return { tenant, connectors };
1943
- };
1944
- var handler19 = async (argv) => {
1945
- debug22("handler", command19, argv);
1946
- const { hg, json, apikey, env: env2, flow } = argv;
1947
- let message;
1948
- let spinner = ora12();
1949
- try {
1950
- message = themed(`Retrieving tenants for environment ${themed(env2, "info")}`);
1951
- !json && spinner.start(themed(`In progress: ${message}...`, "secondary"));
1952
- const [allTenants, supportedFlow] = await Promise.all([
1953
- getTenants({
1954
- debug: debug22,
1955
- baseUri: hg.clientApiBaseUri,
1956
- apikey,
1957
- env: env2
1958
- }),
1959
- getSupportedFlow({
1960
- debug: debug22,
1961
- baseUri: hg.clientApiBaseUri,
1962
- apikey,
1963
- env: env2,
1964
- flow
1965
- })
1966
- ]);
1967
- const isV2Flow2 = supportedFlow?.version === 2;
1968
- !json && spinner.succeed(themed(`Finished: ${message}.`, "secondary"));
1969
- const tenantsWithCustomFieldMap = [];
1970
- message = themed(`Querying for custom field maps for flow ${themed(flow, "info")}`);
1971
- !json && spinner.start(themed(`In progress: ${message}...`, "secondary"));
1972
- for (const tenants2 of buildChunks(allTenants)) {
1973
- const maybeTenantsWithCustomFieldMap = await Promise.all(tenants2.map((tenant) => processTenant2({
1974
- debug: debug22,
1975
- baseUri: hg.clientApiBaseUri,
1976
- apikey,
1977
- env: env2,
1978
- flow,
1979
- tenant,
1980
- isV2Flow: isV2Flow2
1981
- })));
1982
- tenantsWithCustomFieldMap.push(...maybeTenantsWithCustomFieldMap.filter(({ connectors }) => connectors.length > 0));
1983
- }
1984
- !json && spinner.succeed(themed(`Finished: ${message}.`, "secondary"));
1985
- if (json) {
1986
- printJSON(tenantsWithCustomFieldMap);
1987
- } else {
1988
- const table = new Table14({ head: ["Tenant ID", "Connector IDs"] });
1989
- table.push(...tenantsWithCustomFieldMap.map(({ tenant, connectors }) => [tenant, connectors.join(", ")]));
1990
- console.log(table.toString());
1991
- }
1992
- } catch (err) {
1993
- if (json) {
1994
- printJSON({ status: "error", error: err });
1995
- } else {
1996
- spinner.fail(themed(`Error: ${message}.`, "secondary"));
1997
- pr(themed(`Message: ${themed(err.message)}`, "secondary"));
1998
- debug22(err);
1999
- if (err && err.response && err.response.data) {
2000
- debug22("response", err.response.data);
2001
- }
2002
- }
2003
- }
2004
- };
2005
-
2006
- // src/commands/tenants/delete.js
2007
- var delete_exports2 = {};
2008
- __export(delete_exports2, {
2009
- builder: () => builder20,
2010
- command: () => command20,
2011
- desc: () => desc20,
2012
- handler: () => handler20
2013
- });
2014
- import AWS11 from "../../node_modules/aws-sdk/lib/aws.js";
2015
- import ora13 from "../../node_modules/ora/index.js";
2016
- import Table15 from "../../node_modules/cli-table/lib/index.js";
2017
- var debug23 = debug_default("commands:tenants:delete");
2018
- var command20 = "delete";
2019
- var desc20 = "Delete tenant";
2020
- var builder20 = async (yargs2) => {
2021
- debug23("builder", command20);
2022
- return yargs2.option("tenant", descriptions_default.options["tenant"].config);
2023
- };
2024
- var handler20 = async (argv) => {
2025
- debug23("handler", command20, argv);
2026
- const { hg, json, apikey, env: env2, tenant } = argv;
2027
- const { clientApiBaseUri } = hg;
2028
- let message;
2029
- let spinner = ora13();
2030
- try {
2031
- if (tenant === "default") {
2032
- throw new Error(`It's not possible to delete "default" tenant!`);
2033
- }
2034
- message = themed(`Deleting tenant ${tenant} schedules`);
2035
- !json && spinner.start(themed(`In progress: ${message}...`, "secondary"));
2036
- await deleteTenantSchedules({
2037
- debug: debug23,
2038
- baseUri: clientApiBaseUri,
2039
- env: env2,
2040
- apikey,
2041
- tenant
2042
- });
2043
- !json && spinner.succeed(themed(`Finished: ${message}.`, "secondary"));
2044
- message = themed(`Verifying user and authorizing`);
2045
- !json && spinner.start(themed(`In progress: ${message}...`, "secondary"));
2046
- const { accessKeyId, secretAccessKey, sessionToken } = await genCredentialsOnClientApi({
2047
- debug: debug23,
2048
- baseUri: clientApiBaseUri,
2049
- task: "tenant-delete",
2050
- env: env2,
2051
- tenant,
2052
- apikey
2053
- });
2054
- !json && spinner.succeed(themed(`Finished: ${message}.`, "secondary"));
2055
- const s3 = new AWS11.S3({
2056
- accessKeyId,
2057
- secretAccessKey,
2058
- sessionToken
2059
- });
2060
- message = themed(`Deleting tenant ${tenant} for environment ${themed(env2, "info")}`);
2061
- !json && spinner.start(themed(`In progress: ${message}...`, "secondary"));
2062
- while (true) {
2063
- const s3Objects = await s3.listObjectsV2({
2064
- Bucket: env2,
2065
- Prefix: `${tenant}/`
2066
- }).promise();
2067
- const Objects = (s3Objects.Contents || []).map(({ Key }) => ({ Key }));
2068
- if (Objects.length === 0) {
2069
- break;
2070
- }
2071
- const response = await s3.deleteObjects({
2072
- Bucket: env2,
2073
- Delete: {
2074
- Objects
2075
- }
2076
- }).promise();
2077
- }
2078
- !json && spinner.succeed(themed(`Finished: ${message}.`, "secondary"));
2079
- if (json) {
2080
- printJSON({ statu: "success", tenantDeleted: tenant });
2081
- } else {
2082
- const table = new Table15({ head: ["Tenant ID"] });
2083
- table.push([tenant]);
2084
- console.log(table.toString());
2085
- }
2086
- } catch (err) {
2087
- if (json) {
2088
- printJSON({ status: "error", error: err });
2089
- } else {
2090
- spinner.fail(themed(`Error: ${message}.`, "secondary"));
2091
- pr(themed(`Message: ${themed(err.message)}`, "secondary"));
2092
- debug23(err);
2093
- if (err && err.response && err.response.data) {
2094
- debug23("response", err.response.data);
2095
- }
2096
- }
2097
- }
2098
- };
2099
-
2100
- // src/commands/tenants/list.js
2101
- var list_exports3 = {};
2102
- __export(list_exports3, {
2103
- builder: () => builder21,
2104
- command: () => command21,
2105
- desc: () => desc21,
2106
- handler: () => handler21
2107
- });
2108
- import ora14 from "../../node_modules/ora/index.js";
2109
- import axios8 from "../../node_modules/axios/index.js";
2110
- import Table16 from "../../node_modules/cli-table/lib/index.js";
2111
- var debug24 = debug_default("commands:tenants:list");
2112
- var command21 = "list";
2113
- var desc21 = "List tenants";
2114
- var builder21 = async (yargs2) => {
2115
- debug24("builder", command21);
2116
- return yargs2.option("tenant", descriptions_default.options["tenant"].config);
2117
- };
2118
- var handler21 = async (argv) => {
2119
- debug24("handler", command21, argv);
2120
- const { hg, json, apikey, env: env2, tenant } = argv;
2121
- let message;
2122
- let spinner = ora14();
2123
- try {
2124
- message = themed(`Retrieving tenants for environment ${themed(env2, "info")}`);
2125
- const uri = `${hg.clientApiBaseUri}/tenants/${env2}${tenant ? `?tenant=${tenant}` : ""}`;
2126
- debug24("requesting:", uri);
2127
- !json && spinner.start(themed(`In progress: ${message}...`, "secondary"));
2128
- const { data } = await axios8.get(uri, { headers: { "x-api-key": apikey } });
2129
- !json && spinner.succeed(themed(`Finished: ${message}.`, "secondary"));
2130
- debug24("response-data", data);
2131
- if (!data || data.length === 0) {
2132
- json ? printJSON([]) : spinner.info(themed(`Info: ${themed("No tenants found in the specified environment")}.`, "secondary"));
2133
- return;
2134
- }
2135
- if (json) {
2136
- printJSON(data);
2137
- } else {
2138
- const table = new Table16({ head: ["tenant ID"] });
2139
- table.push(...data.map((item) => [item]));
2140
- console.log(table.toString());
2141
- }
2142
- } catch (err) {
2143
- if (json) {
2144
- printJSON({ status: "error", error: err });
2145
- } else {
2146
- spinner.fail(themed(`Error: ${message}.`, "secondary"));
2147
- pr(themed(`Message: ${themed(err.message)}`, "secondary"));
2148
- debug24(err);
2149
- if (err && err.response && err.response.data) {
2150
- debug24("response", err.response.data);
2151
- }
2152
- }
2153
- }
2154
- };
2155
-
2156
- // src/commands/tenants/updateConfig.js
2157
- var updateConfig_exports = {};
2158
- __export(updateConfig_exports, {
2159
- builder: () => builder22,
2160
- command: () => command22,
2161
- desc: () => desc22,
2162
- handler: () => handler22
2163
- });
2164
- import ora15 from "../../node_modules/ora/index.js";
2165
- import Table17 from "../../node_modules/cli-table/lib/index.js";
2166
- import { existsSync as existsSync3, readFileSync } from "fs";
2167
- var debug25 = debug_default("commands:tenants:update-config");
2168
- var command22 = "update-config";
2169
- var desc22 = "Update the config of a specific connector and flow for all tenants";
2170
- var builder22 = async (yargs2) => {
2171
- debug25("builder", command22);
2172
- return yargs2.option("flow", descriptions_default.options["flow"].config).demandOption("flow", descriptions_default.options["flow"].demandText).option("connector", descriptions_default.options["connector"].config).demandOption("connector", descriptions_default.options["connector"].demandText).option("configFilePath", descriptions_default.options["configFilePath"].config).demandOption("configFilePath", descriptions_default.options["configFilePath"].demandText);
2173
- };
2174
- var processTenant3 = async ({ debug: debug27, baseUri, apikey, env: env2, flow, tenant, connectorId, config: config2, isV2Flow: isV2Flow2 }) => {
2175
- const lookupKey = isV2Flow2 ? "id" : "tap";
2176
- const linkedConnectors = isV2Flow2 ? await getLinkedConnectors({
2177
- debug: debug27,
2178
- baseUri,
2179
- env: env2,
2180
- flow,
2181
- tenant,
2182
- apikey,
2183
- config: true
2184
- }) : await getLinkedSources({
2185
- debug: debug27,
2186
- baseUri,
2187
- env: env2,
2188
- flow,
2189
- tenant,
2190
- apikey,
2191
- config: true
2192
- });
2193
- const connector = linkedConnectors.find((c) => c[lookupKey] === connectorId);
2194
- if (!connector)
2195
- return null;
2196
- const patchFunction = isV2Flow2 ? patchLinkedConnectorConfig : patchLinkedSourceConfig;
2197
- try {
2198
- await patchFunction({
2199
- debug: debug27,
2200
- baseUri,
2201
- env: env2,
2202
- flow,
2203
- tenant,
2204
- apikey,
2205
- connectorId,
2206
- config: config2
2207
- });
2208
- } catch (e) {
2209
- console.log(themed(`Error patching: ${tenant}. ${e}`, "secondary"));
2210
- }
2211
- return tenant;
2212
- };
2213
- var handler22 = async (argv) => {
2214
- debug25("handler", command22, argv);
2215
- const { hg, json, apikey, env: env2, flow, connector, configFilePath } = argv;
2216
- let message;
2217
- let spinner = ora15();
2218
- try {
2219
- if (!configFilePath) {
2220
- throw new Error("Config file path not provided");
2221
- }
2222
- if (!configFilePath.endsWith(".json")) {
2223
- throw new Error("Config file must have .json extension");
2224
- }
2225
- if (!existsSync3(configFilePath)) {
2226
- throw new Error("Config file not found");
2227
- }
2228
- const config2 = JSON.parse(readFileSync(configFilePath, { encoding: "utf-8" }));
2229
- message = themed(`Retrieving tenants for environment ${themed(env2, "info")}`);
2230
- !json && spinner.start(themed(`In progress: ${message}...`, "secondary"));
2231
- const [allTenants, supportedFlow] = await Promise.all([
2232
- getTenants({
2233
- debug: debug25,
2234
- baseUri: hg.clientApiBaseUri,
2235
- apikey,
2236
- env: env2
2237
- }),
2238
- getSupportedFlow({
2239
- debug: debug25,
2240
- baseUri: hg.clientApiBaseUri,
2241
- apikey,
2242
- env: env2,
2243
- flow
2244
- })
2245
- ]);
2246
- const isV2Flow2 = supportedFlow?.version === 2;
2247
- !json && spinner.succeed(themed(`Finished: ${message}.`, "secondary"));
2248
- const tenantsUpdated = [];
2249
- message = themed(`Updating config for connector ${themed(connector, "info")} and flow ${themed(flow, "info")}`);
2250
- !json && spinner.start(themed(`In progress: ${message}...`, "secondary"));
2251
- for (const tenants2 of buildChunks(allTenants)) {
2252
- const maybeTenantsUpdated = await Promise.all(tenants2.map((tenant) => processTenant3({
2253
- debug: debug25,
2254
- baseUri: hg.clientApiBaseUri,
2255
- apikey,
2256
- env: env2,
2257
- flow,
2258
- tenant,
2259
- connectorId: connector,
2260
- config: config2,
2261
- isV2Flow: isV2Flow2
2262
- })));
2263
- tenantsUpdated.push(...maybeTenantsUpdated.filter(Boolean));
2264
- }
2265
- !json && spinner.succeed(themed(`Finished: ${message}.`, "secondary"));
2266
- if (json) {
2267
- printJSON(tenantsUpdated);
2268
- } else {
2269
- const table = new Table17({ head: ["Tenant ID"] });
2270
- tenantsUpdated.forEach((t) => table.push([t]));
2271
- console.log(table.toString());
2272
- }
2273
- } catch (err) {
2274
- if (json) {
2275
- printJSON({ status: "error", error: err });
2276
- } else {
2277
- spinner.fail(themed(`Error: ${message}.`, "secondary"));
2278
- pr(themed(`Message: ${themed(err.message)}`, "secondary"));
2279
- debug25(err);
2280
- if (err && err.response && err.response.data) {
2281
- debug25("response", err.response.data);
2282
- }
2283
- }
2284
- }
2285
- };
2286
-
2287
- // src/commands/tenants/index.js
2288
- var tenants = [customEtl_exports, customFieldMap_exports, delete_exports2, list_exports3, updateConfig_exports];
2289
-
2290
- // src/commands/tenants.js
2291
- var debug26 = debug_default("commands:tenants");
2292
- var command23 = "tenants <action>";
2293
- var desc23 = "Manage tenants";
2294
- var builder23 = async function(yargs2) {
2295
- debug26("builder", command23);
2296
- const base = await baseApiBuilder(yargs2);
2297
- return base.command(tenants);
2298
- };
2299
- var handler23 = async function(argv) {
2300
- debug26("handler", command23, argv);
2301
- };
2302
-
2303
- // src/commands/index.js
2304
- var commands = [config_exports, env_exports, etl_exports, flows_exports, jobs_exports, snapshots_exports, tenants_exports];
2305
-
2306
- // src/index.js
2307
- import mmm from "../../node_modules/aws-sdk/lib/maintenance_mode_message.js";
2308
- mmm.suppress = true;
2309
- var myTheme = {};
2310
- setTheme(myTheme);
2311
- var yargs = _yargs(process.argv.slice(2));
2312
- yargs.usage(themed("Usage: $0 <command>")).command(commands).demandCommand().alias("v", "version").alias("h", "help").string("_").strictCommands().epilogue(themed("For more information, visit https://docs.hotglue.xyz/docs/cli-overview")).wrap(Math.min(yargs.terminalWidth(), 90)).parse(hideBin(process.argv), staticOptions);