@settlemint/dalp-cli 3.1.33-release.42636987002 → 3.1.33-release.43440124932

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 (2) hide show
  1. package/dist/dalp.js +110 -9
  2. package/package.json +6 -6
package/dist/dalp.js CHANGED
@@ -131382,7 +131382,7 @@ function normalizeDalpBaseUrl(url2) {
131382
131382
  }
131383
131383
  return `${parsed.origin}${parsed.pathname.replace(/\/+$/, "")}`;
131384
131384
  }
131385
- var SDK_PACKAGE_VERSION = "3.1.33-release.42636987002";
131385
+ var SDK_PACKAGE_VERSION = "3.1.33-release.43440124932";
131386
131386
  var SDK_VERSION = SDK_PACKAGE_VERSION;
131387
131387
  var SDK_USER_AGENT = `DALP SDK v${SDK_VERSION}`;
131388
131388
  var DEFAULT_MUTATION_PREFER = "wait=99";
@@ -132534,7 +132534,7 @@ var failedStateSet = new Set(FAILED_TRANSACTION_STATES);
132534
132534
  // package.json
132535
132535
  var package_default = {
132536
132536
  name: "@settlemint/dalp-cli",
132537
- version: "3.1.33-release.42636987002",
132537
+ version: "3.1.33-release.43440124932",
132538
132538
  private: false,
132539
132539
  description: "CLI for the Digital Asset Lifecycle Platform — manage tokens, identities, compliance, and more from the command line.",
132540
132540
  homepage: "https://settlemint.com",
@@ -195841,6 +195841,20 @@ kycCommand.command("action-request-fulfill", {
195841
195841
  // src/commands/login.ts
195842
195842
  import { execFile as execFile2 } from "node:child_process";
195843
195843
  import { hostname as hostname3 } from "node:os";
195844
+
195845
+ // src/lib/api-key-name.ts
195846
+ var SERVER_API_KEY_NAME_MAX_LENGTH = 32;
195847
+ var CLI_KEY_PREFIX = "dalp-cli";
195848
+ function cliApiKeyName(machine) {
195849
+ const name = `${CLI_KEY_PREFIX} (${machine})`;
195850
+ if (name.length <= SERVER_API_KEY_NAME_MAX_LENGTH) {
195851
+ return name;
195852
+ }
195853
+ const room = SERVER_API_KEY_NAME_MAX_LENGTH - `${CLI_KEY_PREFIX} (…)`.length;
195854
+ return `${CLI_KEY_PREFIX} (${machine.slice(0, room)}…)`;
195855
+ }
195856
+
195857
+ // src/commands/login.ts
195844
195858
  var deviceCodeSchema = object({
195845
195859
  device_code: string2(),
195846
195860
  user_code: string2(),
@@ -195986,27 +196000,28 @@ Open this URL in your browser:
195986
196000
  } catch {}
195987
196001
  }
195988
196002
  const sessionToken = await pollForToken(apiUrl, deviceCode.device_code, deviceCode.interval, deviceCode.expires_in);
195989
- const sessionCookie = `better-auth.session_token=${sessionToken.access_token}`;
196003
+ const bearerAuthorization = `Bearer ${sessionToken.access_token}`;
195990
196004
  const sessionResponse = await fetch(`${apiUrl}/api/auth/get-session`, {
195991
- headers: { Cookie: sessionCookie, "User-Agent": CLI_USER_AGENT }
196005
+ headers: { Authorization: bearerAuthorization, "User-Agent": CLI_USER_AGENT }
195992
196006
  });
195993
- if (!sessionResponse.ok) {
196007
+ const parsedSession = sessionResponse.ok ? sessionResponseSchema.safeParse(await sessionResponse.json()) : undefined;
196008
+ if (!parsedSession?.success) {
195994
196009
  return c.error({
195995
196010
  code: "SESSION_FAILED",
195996
196011
  message: "Authorized but failed to fetch session. Try 'dalp login' again.",
195997
196012
  retryable: true
195998
196013
  });
195999
196014
  }
196000
- const session = sessionResponseSchema.parse(await sessionResponse.json());
196015
+ const session = parsedSession.data;
196001
196016
  const apiKeyResponse = await fetch(`${apiUrl}/api/auth/api-key/create`, {
196002
196017
  method: "POST",
196003
196018
  headers: {
196004
196019
  "Content-Type": "application/json",
196005
196020
  "User-Agent": CLI_USER_AGENT,
196006
- Cookie: sessionCookie
196021
+ Authorization: bearerAuthorization
196007
196022
  },
196008
196023
  body: JSON.stringify({
196009
- name: `dalp-cli (${hostname3()})`,
196024
+ name: cliApiKeyName(hostname3()),
196010
196025
  metadata: {
196011
196026
  ...session.session.activeOrganizationId ? { organizationId: session.session.activeOrganizationId } : {},
196012
196027
  scope: "read-write"
@@ -201991,6 +202006,18 @@ var whoamiCommand = create("whoami", {
201991
202006
  }
201992
202007
  });
201993
202008
 
202009
+ // src/lib/confirm-prompt.ts
202010
+ import { createInterface } from "node:readline/promises";
202011
+ async function confirmYesNo(question) {
202012
+ const rl = createInterface({ input: process.stdin, output: process.stdout });
202013
+ try {
202014
+ const answer = await rl.question(`${question} `);
202015
+ return ["y", "yes"].includes(answer.trim().toLowerCase());
202016
+ } finally {
202017
+ rl.close();
202018
+ }
202019
+ }
202020
+
201994
202021
  // src/lib/errors.ts
201995
202022
  function renderSdkErrorForCli(error, context) {
201996
202023
  if (error instanceof DalpSdkError) {
@@ -202444,18 +202471,88 @@ authCommand.command("wallet-secret-codes-confirm", {
202444
202471
  return result.data;
202445
202472
  }
202446
202473
  });
202474
+ var deviceClaimSchema = object({ user_code: string2(), status: string2() });
202475
+ var deviceDetailsSchema = object({
202476
+ userCode: string2(),
202477
+ clientId: string2(),
202478
+ clientName: string2(),
202479
+ permissions: string2(),
202480
+ expiresAt: union([string2(), date3().transform((date) => date.toISOString())])
202481
+ });
202482
+ var authFetchResultSchema = object({ data: unknown().nullable(), error: unknown().nullable() }).partial();
202483
+ var DEVICE_APPROVE_WARNING = "Only approve if this code is shown on a device you have in front of you right now.";
202484
+ function formatUserCode(userCode) {
202485
+ const compact = userCode.replaceAll("-", "").toUpperCase();
202486
+ return compact.length === 8 ? `${compact.slice(0, 4)}-${compact.slice(4)}` : userCode;
202487
+ }
202488
+ function describeDeviceRequest(details) {
202489
+ return [
202490
+ `Client: ${details.clientName} (${details.clientId})`,
202491
+ `Permissions: ${details.permissions}`,
202492
+ `Code: ${formatUserCode(details.userCode)}`,
202493
+ `Expires: ${details.expiresAt}`
202494
+ ].join(`
202495
+ `);
202496
+ }
202497
+ async function getAuthEndpoint(auth, path, userCode) {
202498
+ const raw = authFetchResultSchema.parse(await auth.$fetch(path, { method: "GET", query: { user_code: userCode } }));
202499
+ return { data: raw.data ?? null, error: raw.error ?? null };
202500
+ }
202501
+ async function claimDeviceRequest(auth, userCode) {
202502
+ const claim = await getAuthEndpoint(auth, "/device", userCode);
202503
+ if (claim.error || !deviceClaimSchema.safeParse(claim.data).success) {
202504
+ return authError(claim.error, "DEVICE_CLAIM_FAILED", "Failed to claim device request");
202505
+ }
202506
+ return;
202507
+ }
202447
202508
  authCommand.command("device-approve", {
202448
202509
  description: "Approve a pending device-authorization request by its user code",
202449
202510
  args: object({
202450
202511
  userCode: string2().describe("User code displayed by the device requesting access")
202451
202512
  }),
202513
+ options: object({
202514
+ yes: boolean2().optional().describe("Skip the confirmation after the request details are shown")
202515
+ }),
202452
202516
  async run(c) {
202453
202517
  const auth = createAuthClient2(c.var.apiUrl, { apiKey: c.var.credentials.apiKey });
202518
+ const claimError = await claimDeviceRequest(auth, c.args.userCode);
202519
+ if (claimError) {
202520
+ return c.error(claimError);
202521
+ }
202522
+ const detailsResult = await getAuthEndpoint(auth, "/device/details", c.args.userCode);
202523
+ const parsedDetails = deviceDetailsSchema.safeParse(detailsResult.data);
202524
+ if (detailsResult.error || !parsedDetails.success) {
202525
+ return c.error(authError(detailsResult.error, "DEVICE_DETAILS_FAILED", "Failed to load device request details"));
202526
+ }
202527
+ const details = parsedDetails.data;
202528
+ const summary = describeDeviceRequest(details);
202529
+ console.error(`
202530
+ ${summary}
202531
+ `);
202532
+ console.error(DEVICE_APPROVE_WARNING);
202533
+ if (!c.options.yes) {
202534
+ if (c.agent || !process.stdin.isTTY) {
202535
+ return c.error({
202536
+ code: "DEVICE_APPROVE_CONFIRMATION_REQUIRED",
202537
+ message: `Approval needs confirmation.
202538
+ ${summary}
202539
+ Check these details match a device you have in front of you right now, then re-run with --yes.`,
202540
+ retryable: false
202541
+ });
202542
+ }
202543
+ if (!await confirmYesNo("Approve this request? [y/N]")) {
202544
+ return c.error({
202545
+ code: "DEVICE_APPROVE_DECLINED",
202546
+ message: "Device request was not approved.",
202547
+ retryable: false
202548
+ });
202549
+ }
202550
+ }
202454
202551
  const result = await auth.device.approve({ userCode: c.args.userCode });
202455
202552
  if (result.error) {
202456
202553
  return c.error(authError(result.error, "DEVICE_APPROVE_FAILED", "Failed to approve device"));
202457
202554
  }
202458
- return result.data;
202555
+ return { success: true, ...details, userCode: formatUserCode(details.userCode), approved: true };
202459
202556
  }
202460
202557
  });
202461
202558
  authCommand.command("device-deny", {
@@ -202465,6 +202562,10 @@ authCommand.command("device-deny", {
202465
202562
  }),
202466
202563
  async run(c) {
202467
202564
  const auth = createAuthClient2(c.var.apiUrl, { apiKey: c.var.credentials.apiKey });
202565
+ const claimError = await claimDeviceRequest(auth, c.args.userCode);
202566
+ if (claimError) {
202567
+ return c.error(claimError);
202568
+ }
202468
202569
  const result = await auth.device.deny({ userCode: c.args.userCode });
202469
202570
  if (result.error) {
202470
202571
  return c.error(authError(result.error, "DEVICE_DENY_FAILED", "Failed to deny device"));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@settlemint/dalp-cli",
3
- "version": "3.1.33-release.42636987002",
3
+ "version": "3.1.33-release.43440124932",
4
4
  "private": false,
5
5
  "description": "CLI for the Digital Asset Lifecycle Platform — manage tokens, identities, compliance, and more from the command line.",
6
6
  "homepage": "https://settlemint.com",
@@ -46,11 +46,11 @@
46
46
  },
47
47
  "devDependencies": {
48
48
  "@arethetypeswrong/cli": "0.18.3",
49
- "@core/errors": "3.1.33-release.42636987002",
50
- "@core/validation": "3.1.33-release.42636987002",
51
- "@dalp/errors": "3.1.33-release.42636987002",
52
- "@settlemint/dalp-sdk": "3.1.33-release.42636987002",
53
- "@tools/typescript-config": "3.1.33-release.42636987002",
49
+ "@core/errors": "3.1.33-release.43440124932",
50
+ "@core/validation": "3.1.33-release.43440124932",
51
+ "@dalp/errors": "3.1.33-release.43440124932",
52
+ "@settlemint/dalp-sdk": "3.1.33-release.43440124932",
53
+ "@tools/typescript-config": "3.1.33-release.43440124932",
54
54
  "@types/bun": "1.4.4",
55
55
  "publint": "0.3.21"
56
56
  },