UNPKG

@fragment-dev/cli

Version:
114 lines (108 loc) 3.12 kB
import { AuthenticatedCommand } from "./chunk-W7HG2VEH.js"; import { require_lib } from "./chunk-UD22EIAP.js"; import { require_source } from "./chunk-M5OAS5QZ.js"; import { __toESM, init_cjs_shims } from "./chunk-7GH3YGSC.js"; // src/commands/add-ledger-entry.ts init_cjs_shims(); var import_core = __toESM(require_lib(), 1); var import_chalk = __toESM(require_source(), 1); var AddLedgerEntry = class extends AuthenticatedCommand { static { this.summary = "Add a Ledger Entry to a Ledger Account."; } static { this.description = `This mirrors the ${import_chalk.default.magentaBright( "addLedgerEntry" )} mutation in the GraphQL API. Only entries with ${import_chalk.default.cyan( "type" )} are allowed to be posted to a Ledger Account. `; } static { this.examples = ["<%= config.bin %> <%= command.id %>"]; } static { this.flags = { ik: import_core.Flags.string({ char: "i", description: "The Idempotency Key for Ledger Entry creation.", required: true }), "ledger.ik": import_core.Flags.string({ char: "l", description: "The Idempotency Key of the Ledger to post the Ledger Entry to.", required: true }), type: import_core.Flags.string({ char: "t", required: true, description: "The `type` of Ledger Entry you want to post." }), "type.version": import_core.Flags.integer({ char: "n", required: false, description: "The version of the Ledger Entry type you want to post." }), param: import_core.Flags.string({ char: "p", multiple: true, summary: "The parameters for your Ledger Entry. (ex: --param amount=100 --param currency=USD)", description: "You may specify multiple parameters by repeating the flag." }) }; } async run() { const parameters = this.flags.param?.reduce((acc, param) => { const [key, value] = param.split("="); if (!key || !value) { this.logToStderr( `Invalid value for parameters. ${import_chalk.default.cyan( "`parameters`" )} must be in the format of key=value. You can specify multiple parameters by repeating the flag. You provided: ${import_chalk.default.yellow(param)}` ); this.exit(1); } if (acc[key]) { this.logToStderr( `Invalid value for parameters. ${import_chalk.default.cyan( "`parameters`" )} must not contain duplicate keys. You provided: ${import_chalk.default.yellow(param)}` ); this.exit(1); } acc[key] = value; return acc; }, {}); const res = await this.sdk.AddLedgerEntry({ ik: this.flags.ik, entry: { ledger: { ik: this.flags["ledger.ik"] }, type: this.flags.type, typeVersion: this.flags["type.version"], parameters } }); if (res.addLedgerEntry.__typename !== "AddLedgerEntryResult") { this.exit(1); } } }; export { AddLedgerEntry };