UNPKG

@fusionauth/cli

Version:
46 lines (45 loc) 2.38 kB
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; import { Command } from '@commander-js/extra-typings'; import { FusionAuthClient } from '@fusionauth/typescript-client'; import chalk from 'chalk'; import { existsSync } from 'fs'; import { join } from 'path'; import { mkdir, writeFile } from 'fs/promises'; import { errorAndExit, toJson } from '../utils.js'; import { apiKeyOption, hostOption } from "../options.js"; const action = function (lambdaId, { output, key: apiKey, host }) { var _a; return __awaiter(this, void 0, void 0, function* () { console.log(`Retrieving lambda ${lambdaId} from ${host}`); try { const fusionAuthClient = new FusionAuthClient(apiKey, host); const clientResponse = yield fusionAuthClient.retrieveLambda(lambdaId); if (!clientResponse.wasSuccessful()) errorAndExit(`Error retrieving lambda: `, clientResponse); if (!existsSync(output)) yield mkdir(output); const filename = join(output, ((_a = clientResponse.response.lambda) === null || _a === void 0 ? void 0 : _a.id) + ".json"); yield writeFile(filename, toJson(clientResponse.response.lambda)); console.log(chalk.green(`Lambda downloaded to ${filename}`)); } catch (e) { errorAndExit(`Error retrieving lambda:`, e); } }); }; // noinspection JSUnusedGlobalSymbols export const lambdaRetrieve = new Command('lambda:retrieve') .description('Retrieve a lambda from FusionAuth') .argument('<lambdaId>', 'The lambda id to retrieve') .option('-o, --output <output>', 'The output directory', './lambdas/') .addOption(apiKeyOption) .addOption(hostOption) .action(action);