@agenzo/token-cli 0.2.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -270,6 +270,10 @@ var ApiClient = class {
270
270
  const headers = {
271
271
  "User-Agent": `agenzo-admin-cli/${getCurrentVersion()}`
272
272
  };
273
+ const traceparent = process.env.TRACEPARENT;
274
+ if (traceparent) {
275
+ headers["traceparent"] = traceparent;
276
+ }
273
277
  if (auth.type === "bearer") {
274
278
  headers["Authorization"] = `Bearer ${auth.token}`;
275
279
  } else if (auth.type === "api-key") {
@@ -692,11 +696,17 @@ async function renderWithContext(result, opts, configManager) {
692
696
  render({ ...result, data: payload }, opts);
693
697
  }
694
698
  var PromptEngine = class {
695
- /** Return flagValue directly if provided, otherwise prompt interactively */
699
+ /** Return flagValue if provided, else env fallback, else prompt interactively */
696
700
  static async resolveInput(flagValue, config) {
697
701
  if (flagValue !== void 0) {
698
702
  return flagValue;
699
703
  }
704
+ if (config.envVar) {
705
+ const envValue = process.env[config.envVar];
706
+ if (envValue !== void 0 && envValue !== "") {
707
+ return envValue;
708
+ }
709
+ }
700
710
  if (config.type === "password") {
701
711
  return password({ message: config.message, mask: "*" });
702
712
  }
@@ -743,6 +753,230 @@ async function collectPaymentMethodParams(type, flags) {
743
753
  return params;
744
754
  }
745
755
 
756
+ // src/verb-schema.ts
757
+ var CLI_NAME = "agenzo-token-cli";
758
+ function wantsJsonSchema(argv = process.argv) {
759
+ for (let i = 0; i < argv.length; i++) {
760
+ const a = argv[i];
761
+ if (a === "--format=json") return true;
762
+ if (a === "--format" && argv[i + 1] === "json") return true;
763
+ }
764
+ return false;
765
+ }
766
+ function emitSchema(schema) {
767
+ console.log(JSON.stringify(schema, null, 2));
768
+ }
769
+ function attachSchemaHelp(cmd, schema) {
770
+ const baseHelp = cmd.helpInformation.bind(cmd);
771
+ cmd.helpInformation = (context) => {
772
+ if (!wantsJsonSchema()) return baseHelp(context);
773
+ emitSchema(schema);
774
+ return "";
775
+ };
776
+ return cmd;
777
+ }
778
+ var pmAddSchema = {
779
+ cli: CLI_NAME,
780
+ noun: "payment-methods",
781
+ verb: "add",
782
+ description: "Add a payment method (card binding + 3DS verification)",
783
+ flags: {
784
+ "card-number": { type: "string", required: true, description: "Card number (PAN)" },
785
+ "exp-month": { type: "string", required: true, description: "Expiration month (MM)" },
786
+ "exp-year": { type: "string", required: true, description: "Expiration year (YY or YYYY)" },
787
+ "cardholder-name": { type: "string", required: true, description: "Name on the card" },
788
+ "member-id": { type: "string", required: false, description: "Member ID to associate the card with" },
789
+ "api-key": { type: "string", required: true, description: "API Key for authentication", source: "config" }
790
+ },
791
+ response: {
792
+ id: { type: "string", description: "Payment method ID" },
793
+ status: { type: "string", description: "PENDING / ACTIVE / FAILED" },
794
+ card_brand: { type: "string", description: "visa / mastercard / ..." },
795
+ last_four: { type: "string", description: "Last 4 digits of card" },
796
+ verification_url: { type: "string|null", description: "3DS verification URL (when PENDING)" }
797
+ },
798
+ example: {
799
+ command: 'agenzo-token-cli payment-methods add --card-number 4111111111111111 --exp-month 12 --exp-year 2027 --cardholder-name "Alice Test"',
800
+ output_summary: "Returns payment method ID and 3DS verification URL. Complete 3DS to activate."
801
+ },
802
+ error_recovery: {
803
+ INVALID_CARD: "Card number failed Luhn check or is not supported. Verify and retry.",
804
+ EVO_ERROR: "Upstream payment processor error. Retry after a short delay."
805
+ }
806
+ };
807
+ var pmListSchema = {
808
+ cli: CLI_NAME,
809
+ noun: "payment-methods",
810
+ verb: "list",
811
+ description: "List payment methods for the authenticated developer",
812
+ flags: {
813
+ "member": { type: "string", required: false, description: "Filter by member ID" },
814
+ "api-key": { type: "string", required: true, description: "API Key for authentication", source: "config" }
815
+ },
816
+ response: {
817
+ payment_methods: {
818
+ type: "array",
819
+ description: "List of payment methods",
820
+ items: {
821
+ id: { type: "string", description: "Payment method ID" },
822
+ status: { type: "string", description: "PENDING / ACTIVE / DISABLED" },
823
+ card_brand: { type: "string", description: "Card brand" },
824
+ last_four: { type: "string", description: "Last 4 digits" },
825
+ created_at: { type: "string", description: "Creation time (ISO 8601)" }
826
+ }
827
+ }
828
+ },
829
+ example: {
830
+ command: "agenzo-token-cli payment-methods list",
831
+ output_summary: "Returns array of payment methods with status and card info."
832
+ }
833
+ };
834
+ var pmGetSchema = {
835
+ cli: CLI_NAME,
836
+ noun: "payment-methods",
837
+ verb: "get",
838
+ description: "Get a payment method by ID",
839
+ flags: {
840
+ "pm-id": { type: "string", required: true, description: "Payment method ID" },
841
+ "api-key": { type: "string", required: true, description: "API Key for authentication", source: "config" }
842
+ },
843
+ response: {
844
+ id: { type: "string", description: "Payment method ID" },
845
+ status: { type: "string", description: "PENDING / ACTIVE / DISABLED / FAILED / EXPIRED" },
846
+ card_brand: { type: "string", description: "Card brand" },
847
+ last_four: { type: "string", description: "Last 4 digits" },
848
+ member_id: { type: "string|null", description: "Associated member ID" },
849
+ created_at: { type: "string", description: "Creation time" }
850
+ },
851
+ example: {
852
+ command: "agenzo-token-cli payment-methods get pm_01HZXD...",
853
+ output_summary: "Returns full payment method details including 3DS verification status."
854
+ }
855
+ };
856
+ var pmDisableSchema = {
857
+ cli: CLI_NAME,
858
+ noun: "payment-methods",
859
+ verb: "disable",
860
+ description: "Disable a payment method (cascades revoke on active payment tokens)",
861
+ flags: {
862
+ "pm-id": { type: "string", required: true, description: "Payment method ID to disable" },
863
+ "api-key": { type: "string", required: true, description: "API Key for authentication", source: "config" }
864
+ },
865
+ response: {
866
+ id: { type: "string", description: "Disabled payment method ID" },
867
+ status: { type: "string", description: "DISABLED" },
868
+ revoked_tokens_count: { type: "int", description: "Number of payment tokens revoked by cascade" }
869
+ },
870
+ example: {
871
+ command: "agenzo-token-cli payment-methods disable pm_01HZXD...",
872
+ output_summary: "Disables the payment method and revokes any active tokens bound to it."
873
+ }
874
+ };
875
+ var ptCreateSchema = {
876
+ cli: CLI_NAME,
877
+ noun: "payment-tokens",
878
+ verb: "create",
879
+ description: "Create a payment token (VCN, Network Token cryptogram, or x402 USDC signature)",
880
+ flags: {
881
+ "type": { type: "string", required: true, description: "Token type: vcn / network_token / x402", constraints: "vcn | network_token | x402" },
882
+ "payment-method-id": { type: "string", required: true, description: "Source payment method ID (must be ACTIVE)" },
883
+ "amount": { type: "string", required: "conditional", description: "Amount in minor units (required for vcn and x402)" },
884
+ "currency": { type: "string", required: false, default: "USD", description: "ISO 4217 currency code" },
885
+ "member-id": { type: "string", required: false, description: "Member ID" },
886
+ "external-transaction-id": { type: "string", required: false, description: "External reference for reconciliation" },
887
+ "pay-to": { type: "string", required: "conditional", description: "Recipient address (required for x402)" },
888
+ "nonce": { type: "string", required: "conditional", description: "Nonce bytes32 hex (required for x402)" },
889
+ "network": { type: "string", required: "conditional", description: "Chain network (required for x402, e.g. base-sepolia)" },
890
+ "deadline": { type: "int", required: "conditional", description: "Epoch seconds deadline (required for x402)" },
891
+ "api-key": { type: "string", required: true, description: "API Key for authentication", source: "config" }
892
+ },
893
+ response: {
894
+ id: { type: "string", description: "Payment token ID" },
895
+ type: { type: "string", description: "vcn / network_token / x402" },
896
+ status: { type: "string", description: "ACTIVE / REVOKED / EXPIRED" },
897
+ token_data: { type: "object", description: "Type-specific token payload (cryptogram / VCN number / x402 signature)" },
898
+ expires_at: { type: "string|null", description: "Expiration time (ISO 8601)" }
899
+ },
900
+ example: {
901
+ command: "agenzo-token-cli payment-tokens create --type network_token --payment-method-id pm_01HZXD...",
902
+ output_summary: "Returns token ID and cryptogram/VCN/signature data for payment execution."
903
+ },
904
+ error_recovery: {
905
+ INVALID_PAYMENT_METHOD: "Payment method is not ACTIVE or not found. Verify status with payment-methods get.",
906
+ UNSUPPORTED_TOKEN_TYPE: "Use vcn, network_token, or x402."
907
+ }
908
+ };
909
+ var ptListSchema = {
910
+ cli: CLI_NAME,
911
+ noun: "payment-tokens",
912
+ verb: "list",
913
+ description: "List payment tokens for the authenticated developer",
914
+ flags: {
915
+ "type": { type: "string", required: false, description: "Filter by token type (vcn / network_token / x402)" },
916
+ "member-id": { type: "string", required: false, description: "Filter by member ID" },
917
+ "payment-method-id": { type: "string", required: false, description: "Filter by source payment method" },
918
+ "api-key": { type: "string", required: true, description: "API Key for authentication", source: "config" }
919
+ },
920
+ response: {
921
+ payment_tokens: {
922
+ type: "array",
923
+ description: "List of payment tokens",
924
+ items: {
925
+ id: { type: "string", description: "Token ID" },
926
+ type: { type: "string", description: "Token type" },
927
+ status: { type: "string", description: "ACTIVE / REVOKED / EXPIRED" },
928
+ payment_method_id: { type: "string", description: "Source payment method" },
929
+ created_at: { type: "string", description: "Creation time" }
930
+ }
931
+ }
932
+ },
933
+ example: {
934
+ command: "agenzo-token-cli payment-tokens list --type network_token",
935
+ output_summary: "Returns array of payment tokens filtered by type."
936
+ }
937
+ };
938
+ var ptGetSchema = {
939
+ cli: CLI_NAME,
940
+ noun: "payment-tokens",
941
+ verb: "get",
942
+ description: "Get a payment token by ID",
943
+ flags: {
944
+ "payment-token-id": { type: "string", required: true, description: "Payment token ID" },
945
+ "api-key": { type: "string", required: true, description: "API Key for authentication", source: "config" }
946
+ },
947
+ response: {
948
+ id: { type: "string", description: "Token ID" },
949
+ type: { type: "string", description: "Token type" },
950
+ status: { type: "string", description: "ACTIVE / REVOKED / EXPIRED" },
951
+ token_data: { type: "object", description: "Type-specific payload" },
952
+ payment_method_id: { type: "string", description: "Source payment method" },
953
+ created_at: { type: "string", description: "Creation time" },
954
+ expires_at: { type: "string|null", description: "Expiration time" }
955
+ },
956
+ example: {
957
+ command: "agenzo-token-cli payment-tokens get pt_01HZXD...",
958
+ output_summary: "Returns full token details including token_data payload."
959
+ }
960
+ };
961
+ var ptRevokeSchema = {
962
+ cli: CLI_NAME,
963
+ noun: "payment-tokens",
964
+ verb: "revoke",
965
+ description: "Revoke an active payment token",
966
+ flags: {
967
+ "payment-token-id": { type: "string", required: true, description: "Payment token ID to revoke" },
968
+ "api-key": { type: "string", required: true, description: "API Key for authentication", source: "config" }
969
+ },
970
+ response: {
971
+ id: { type: "string", description: "Revoked token ID" },
972
+ status: { type: "string", description: "REVOKED" }
973
+ },
974
+ example: {
975
+ command: "agenzo-token-cli payment-tokens revoke pt_01HZXD...",
976
+ output_summary: "Marks the token as REVOKED. Cannot be undone."
977
+ }
978
+ };
979
+
746
980
  // src/payment-methods/add.ts
747
981
  var POLL_INTERVAL_MS = 3e3;
748
982
  var POLL_TIMEOUT_MS = 15 * 60 * 1e3;
@@ -751,13 +985,15 @@ function registerAddCommand(parent, deps) {
751
985
  "--idempotency-key <key>",
752
986
  "Idempotency key forwarded verbatim as the Idempotency-Key header"
753
987
  );
988
+ attachSchemaHelp(cmd, pmAddSchema);
754
989
  cmd.action(async () => {
755
990
  const opts = cmd.optsWithGlobals();
756
991
  const format = resolveFormat(opts.format);
757
992
  const isYes = Boolean(opts.yes);
758
993
  const apiKey = await PromptEngine.resolveInput(opts.apiKey, {
759
994
  message: "API Key:",
760
- type: "password"
995
+ type: "password",
996
+ envVar: "AGENZO_API_KEY"
761
997
  });
762
998
  const type = opts.type || "card";
763
999
  const flags = {
@@ -898,12 +1134,14 @@ function sleep(ms) {
898
1134
  // src/payment-methods/list.ts
899
1135
  function registerListCommand(parent, deps) {
900
1136
  const cmd = parent.command("list").description("List payment methods").option("--api-key <key>", "API Key for authentication").option("--member <member_id>", "Filter by member ID");
1137
+ attachSchemaHelp(cmd, pmListSchema);
901
1138
  cmd.action(async () => {
902
1139
  const opts = cmd.optsWithGlobals();
903
1140
  const format = resolveFormat(opts.format);
904
1141
  const apiKey = await PromptEngine.resolveInput(opts.apiKey, {
905
1142
  message: "API Key:",
906
- type: "password"
1143
+ type: "password",
1144
+ envVar: "AGENZO_API_KEY"
907
1145
  });
908
1146
  const params = {};
909
1147
  if (opts.member) {
@@ -944,12 +1182,14 @@ function registerListCommand(parent, deps) {
944
1182
  // src/payment-methods/get.ts
945
1183
  function registerGetCommand(parent, deps) {
946
1184
  const cmd = parent.command("get <pm_id>").description("Get a payment method by ID").option("--api-key <key>", "API key for authentication");
1185
+ attachSchemaHelp(cmd, pmGetSchema);
947
1186
  cmd.action(async (pmId) => {
948
1187
  const opts = cmd.optsWithGlobals();
949
1188
  const format = resolveFormat(opts.format);
950
1189
  const apiKey = await PromptEngine.resolveInput(opts.apiKey, {
951
1190
  message: "API Key:",
952
- type: "password"
1191
+ type: "password",
1192
+ envVar: "AGENZO_API_KEY"
953
1193
  });
954
1194
  const result = await deps.apiClient.get(
955
1195
  `/payment-methods/${pmId}`,
@@ -989,12 +1229,14 @@ function registerDisableCommand(parent, deps) {
989
1229
  "--idempotency-key <key>",
990
1230
  "Idempotency key forwarded verbatim as the Idempotency-Key header"
991
1231
  );
1232
+ attachSchemaHelp(cmd, pmDisableSchema);
992
1233
  cmd.action(async (pmId) => {
993
1234
  const opts = cmd.optsWithGlobals();
994
1235
  const format = resolveFormat(opts.format);
995
1236
  const apiKey = await PromptEngine.resolveInput(opts.apiKey, {
996
1237
  message: "API Key:",
997
- type: "password"
1238
+ type: "password",
1239
+ envVar: "AGENZO_API_KEY"
998
1240
  });
999
1241
  let idempotencyKey = opts.idempotencyKey;
1000
1242
  if (!idempotencyKey) {
@@ -1145,13 +1387,15 @@ function registerCreateCommand(parent, deps) {
1145
1387
  "--idempotency-key <key>",
1146
1388
  "Idempotency key forwarded verbatim as the Idempotency-Key header"
1147
1389
  );
1390
+ attachSchemaHelp(cmd, ptCreateSchema);
1148
1391
  cmd.action(async () => {
1149
1392
  const opts = cmd.optsWithGlobals();
1150
1393
  const format = resolveFormat(opts.format);
1151
1394
  const isYes = Boolean(opts.yes);
1152
1395
  const apiKey = await PromptEngine.resolveInput(opts.apiKey, {
1153
1396
  message: "API Key:",
1154
- type: "password"
1397
+ type: "password",
1398
+ envVar: "AGENZO_API_KEY"
1155
1399
  });
1156
1400
  const cliType = await PromptEngine.resolveInput(opts.type, {
1157
1401
  message: "Token type:",
@@ -1290,7 +1534,7 @@ function registerCreateCommand(parent, deps) {
1290
1534
  body.member_id = member;
1291
1535
  }
1292
1536
  if (opts.externalTxId) {
1293
- body.external_tx_id = opts.externalTxId;
1537
+ body.external_transaction_id = opts.externalTxId;
1294
1538
  }
1295
1539
  const extraHeaders = {
1296
1540
  "Idempotency-Key": idempotencyKey
@@ -1376,12 +1620,14 @@ function getSummary(token) {
1376
1620
  }
1377
1621
  function registerListCommand2(parent, deps) {
1378
1622
  const cmd = parent.command("list").description("List payment tokens").option("--api-key <key>", "API Key for authentication").option("--type <type>", "Filter by token type").option("--member <member_id>", "Filter by member ID");
1623
+ attachSchemaHelp(cmd, ptListSchema);
1379
1624
  cmd.action(async () => {
1380
1625
  const opts = cmd.optsWithGlobals();
1381
1626
  const format = resolveFormat(opts.format);
1382
1627
  const apiKey = await PromptEngine.resolveInput(opts.apiKey, {
1383
1628
  message: "API Key:",
1384
- type: "password"
1629
+ type: "password",
1630
+ envVar: "AGENZO_API_KEY"
1385
1631
  });
1386
1632
  const params = {};
1387
1633
  if (opts.type) {
@@ -1512,12 +1758,14 @@ function formatCentsPlain(cents) {
1512
1758
  }
1513
1759
  function registerGetCommand2(parent, deps) {
1514
1760
  const cmd = parent.command("get <payment_token_id>").description("Get a payment token by ID").option("--api-key <key>", "API key for authentication").option("--reveal", "Reveal full VCN card number and CVC in the output");
1761
+ attachSchemaHelp(cmd, ptGetSchema);
1515
1762
  cmd.action(async (paymentTokenId) => {
1516
1763
  const opts = cmd.optsWithGlobals();
1517
1764
  const format = resolveFormat(opts.format);
1518
1765
  const apiKey = await PromptEngine.resolveInput(opts.apiKey, {
1519
1766
  message: "API Key:",
1520
- type: "password"
1767
+ type: "password",
1768
+ envVar: "AGENZO_API_KEY"
1521
1769
  });
1522
1770
  const result = await deps.apiClient.get(
1523
1771
  `/payment-tokens/${paymentTokenId}`,
@@ -1543,12 +1791,14 @@ function registerRevokeCommand(parent, deps) {
1543
1791
  "--idempotency-key <key>",
1544
1792
  "Idempotency key forwarded verbatim as the Idempotency-Key header"
1545
1793
  );
1794
+ attachSchemaHelp(cmd, ptRevokeSchema);
1546
1795
  cmd.action(async (paymentTokenId) => {
1547
1796
  const opts = cmd.optsWithGlobals();
1548
1797
  const format = resolveFormat(opts.format);
1549
1798
  const apiKey = await PromptEngine.resolveInput(opts.apiKey, {
1550
1799
  message: "API Key:",
1551
- type: "password"
1800
+ type: "password",
1801
+ envVar: "AGENZO_API_KEY"
1552
1802
  });
1553
1803
  let idempotencyKey = opts.idempotencyKey;
1554
1804
  if (!idempotencyKey) {
@@ -1636,6 +1886,54 @@ async function main() {
1636
1886
  registerListCommand2(ptCmd, deps);
1637
1887
  registerGetCommand2(ptCmd, deps);
1638
1888
  registerRevokeCommand(ptCmd, deps);
1889
+ const svcCmd = program.command("services").description("Token service discovery");
1890
+ svcCmd.command("list").description("List available token services from platform catalog").option("--api-key <key>", "API Key for authentication").action(async () => {
1891
+ const opts = svcCmd.parent.optsWithGlobals();
1892
+ const format = resolveFormat(opts.format);
1893
+ const apiKey = await PromptEngine.resolveInput(opts.apiKey, {
1894
+ message: "API Key:",
1895
+ type: "password",
1896
+ envVar: "AGENZO_API_KEY"
1897
+ });
1898
+ const host = (await configManager.load()).api_host || "http://localhost:8001";
1899
+ const discoveryClient = new ApiClient({ baseUrl: `${host}/api/discovery/v1` });
1900
+ const result = await discoveryClient.get(
1901
+ "/catalog",
1902
+ { type: "api-key", key: apiKey },
1903
+ { category: "payment" }
1904
+ );
1905
+ if (!result.success) {
1906
+ throw CliError.fromApi(result, { auth: "api-key" });
1907
+ }
1908
+ const cmdResult = {
1909
+ text: () => JSON.stringify(result.data, null, 2),
1910
+ data: result.data
1911
+ };
1912
+ await renderWithContext(cmdResult, { format }, configManager);
1913
+ });
1914
+ svcCmd.command("get <service_id>").description("Get a token service capability by ID").option("--api-key <key>", "API Key for authentication").action(async (serviceId) => {
1915
+ const opts = svcCmd.parent.optsWithGlobals();
1916
+ const format = resolveFormat(opts.format);
1917
+ const apiKey = await PromptEngine.resolveInput(opts.apiKey, {
1918
+ message: "API Key:",
1919
+ type: "password",
1920
+ envVar: "AGENZO_API_KEY"
1921
+ });
1922
+ const host2 = (await configManager.load()).api_host || "http://localhost:8001";
1923
+ const discoveryClient2 = new ApiClient({ baseUrl: `${host2}/api/discovery/v1` });
1924
+ const result = await discoveryClient2.get(
1925
+ `/catalog/${serviceId}`,
1926
+ { type: "api-key", key: apiKey }
1927
+ );
1928
+ if (!result.success) {
1929
+ throw CliError.fromApi(result, { auth: "api-key" });
1930
+ }
1931
+ const cmdResult = {
1932
+ text: () => JSON.stringify(result.data, null, 2),
1933
+ data: result.data
1934
+ };
1935
+ await renderWithContext(cmdResult, { format }, configManager);
1936
+ });
1639
1937
  await program.parseAsync(process.argv);
1640
1938
  }
1641
1939
  function resolveActiveFormat() {