@assinafy/cli 2.4.2 → 2.5.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/cli.cjs CHANGED
@@ -21605,6 +21605,12 @@ var AssignmentResource = class extends BaseResource {
21605
21605
  };
21606
21606
 
21607
21607
  // src/api/resources/authentication.ts
21608
+ function requireReauth(payload) {
21609
+ if (!payload?.password && !payload?.code) {
21610
+ throw new ValidationError("password or code is required");
21611
+ }
21612
+ return payload;
21613
+ }
21608
21614
  var AuthenticationResource = class extends BaseResource {
21609
21615
  /** `POST /login` — exchange email + password for a JWT access token. */
21610
21616
  async login(email, password2) {
@@ -21615,6 +21621,70 @@ var AuthenticationResource = class extends BaseResource {
21615
21621
  () => this.http.post("/login", { email, password: password2 }, publicRequestConfig())
21616
21622
  );
21617
21623
  }
21624
+ /**
21625
+ * `POST /authentication/mfa/verify` — exchange the login `mfa_token` and an
21626
+ * authenticator or recovery code for an access token. The challenge is
21627
+ * single-use and expires 5 minutes after login.
21628
+ */
21629
+ async verifyMfa(payload) {
21630
+ if (!payload?.mfa_token) throw new ValidationError("mfa_token is required");
21631
+ if (!payload.code?.trim()) throw new ValidationError("code is required");
21632
+ return this.call(
21633
+ "Two-factor verification failed",
21634
+ () => this.http.post(
21635
+ "/authentication/mfa/verify",
21636
+ { mfa_token: payload.mfa_token, code: payload.code.trim() },
21637
+ publicRequestConfig()
21638
+ )
21639
+ );
21640
+ }
21641
+ /** `GET /users/self/mfa` — enrolled two-factor methods and remaining recovery codes. */
21642
+ async listMfaMethods() {
21643
+ return this.call("Failed to list two-factor methods", () => this.http.get("/users/self/mfa"));
21644
+ }
21645
+ /**
21646
+ * `POST /users/self/mfa/totp` — start authenticator enrollment. The secret
21647
+ * and provisioning URI are returned only once; two-factor stays inactive
21648
+ * until {@link confirmTotpEnrollment}.
21649
+ */
21650
+ async startTotpEnrollment(label) {
21651
+ return this.call(
21652
+ "Failed to start authenticator enrollment",
21653
+ () => this.http.post("/users/self/mfa/totp", label ? { label } : {})
21654
+ );
21655
+ }
21656
+ /**
21657
+ * `PUT /users/self/mfa/totp/confirm` — activate the method with a live code
21658
+ * and receive one-time recovery codes. Replacing a confirmed method also
21659
+ * requires `password` or `reauth_code`.
21660
+ */
21661
+ async confirmTotpEnrollment(payload) {
21662
+ if (!payload?.id) throw new ValidationError("id is required");
21663
+ if (!payload.code?.trim()) throw new ValidationError("code is required");
21664
+ return this.call(
21665
+ "Failed to confirm authenticator enrollment",
21666
+ () => this.http.put("/users/self/mfa/totp/confirm", payload)
21667
+ );
21668
+ }
21669
+ /** `POST /users/self/mfa/recovery-codes` — issue ten new recovery codes, invalidating the old set. */
21670
+ async regenerateRecoveryCodes(payload) {
21671
+ return this.call(
21672
+ "Failed to regenerate recovery codes",
21673
+ () => this.http.post("/users/self/mfa/recovery-codes", requireReauth(payload))
21674
+ );
21675
+ }
21676
+ /**
21677
+ * `DELETE /users/self/mfa/{methodId}` — remove a method. Removing the last
21678
+ * one also discards the recovery codes.
21679
+ */
21680
+ async removeMfaMethod(methodId, payload) {
21681
+ const id = this.requireId(methodId, "Method ID");
21682
+ const data = requireReauth(payload);
21683
+ return this.call(
21684
+ "Failed to remove two-factor method",
21685
+ () => this.http.delete(`/users/self/mfa/${id}`, { data })
21686
+ );
21687
+ }
21618
21688
  /** `POST /authentication/social-login` — exchange a provider token for an Assinafy JWT. */
21619
21689
  async socialLogin(payload) {
21620
21690
  if (payload.provider !== "google") throw new ValidationError("provider must be google");
@@ -22996,10 +23066,8 @@ var DEFAULT_EVENTS = [
22996
23066
  "signer_rejected_document",
22997
23067
  "document_processing_failed"
22998
23068
  ];
22999
- var WebhookResource = class extends BaseResource {
23000
- /** Register (or replace) the webhook subscription for the workspace. */
23001
- async register(payload, accountId) {
23002
- if (!payload.url) throw new ValidationError("Webhook URL is required");
23069
+ function validateWebhookFields(payload) {
23070
+ if (payload.url !== void 0) {
23003
23071
  let webhookUrl;
23004
23072
  try {
23005
23073
  webhookUrl = new URL(payload.url);
@@ -23009,13 +23077,29 @@ var WebhookResource = class extends BaseResource {
23009
23077
  if (webhookUrl.protocol !== "http:" && webhookUrl.protocol !== "https:") {
23010
23078
  throw new ValidationError("Webhook URL must be a valid HTTP(S) URL");
23011
23079
  }
23012
- requireEmail(payload.email);
23013
- if (payload.events !== void 0 && (!Array.isArray(payload.events) || payload.events.some((event) => typeof event !== "string" || !event))) {
23014
- throw new ValidationError("Webhook events must contain non-empty strings");
23015
- }
23016
- if (payload.is_active !== void 0 && typeof payload.is_active !== "boolean") {
23017
- throw new ValidationError("Webhook is_active must be a boolean");
23080
+ }
23081
+ if (payload.email !== void 0) requireEmail(payload.email);
23082
+ if (payload.events !== void 0 && (!Array.isArray(payload.events) || payload.events.some((event) => typeof event !== "string" || !event))) {
23083
+ throw new ValidationError("Webhook events must contain non-empty strings");
23084
+ }
23085
+ if (payload.name !== void 0 && typeof payload.name !== "string") {
23086
+ throw new ValidationError("Webhook name must be a string");
23087
+ }
23088
+ for (const key of ["is_active", "signing_enabled"]) {
23089
+ if (payload[key] !== void 0 && typeof payload[key] !== "boolean") {
23090
+ throw new ValidationError(`Webhook ${key} must be a boolean`);
23018
23091
  }
23092
+ }
23093
+ }
23094
+ var WebhookResource = class extends BaseResource {
23095
+ /**
23096
+ * `PUT /accounts/{accountId}/webhooks/subscriptions` — create or replace the
23097
+ * account's oldest webhook endpoint. Use the endpoint methods for accounts
23098
+ * with several endpoints or for signed deliveries.
23099
+ */
23100
+ async register(payload, accountId) {
23101
+ if (!payload.url) throw new ValidationError("Webhook URL is required");
23102
+ validateWebhookFields({ ...payload, email: payload.email ?? "" });
23019
23103
  const id = this.accountId(accountId);
23020
23104
  const body = {
23021
23105
  url: payload.url,
@@ -23031,7 +23115,7 @@ var WebhookResource = class extends BaseResource {
23031
23115
  () => this.http.put(`/accounts/${id}/webhooks/subscriptions`, body)
23032
23116
  );
23033
23117
  }
23034
- /** Fetch the current webhook subscription. Returns `null` if none exists. */
23118
+ /** Fetch the account's oldest webhook endpoint. Returns `null` if none exists. */
23035
23119
  async get(accountId) {
23036
23120
  const id = this.accountId(accountId);
23037
23121
  return this.callOptional(
@@ -23039,7 +23123,7 @@ var WebhookResource = class extends BaseResource {
23039
23123
  () => this.http.get(`/accounts/${id}/webhooks/subscriptions`)
23040
23124
  );
23041
23125
  }
23042
- /** Inactivate the current webhook subscription without deleting it. */
23126
+ /** Inactivate the account's oldest webhook endpoint without deleting it. */
23043
23127
  async inactivate(accountId) {
23044
23128
  const id = this.accountId(accountId);
23045
23129
  this.logger.info("Inactivating webhook subscription");
@@ -23048,6 +23132,91 @@ var WebhookResource = class extends BaseResource {
23048
23132
  () => this.http.put(`/accounts/${id}/webhooks/inactivate`)
23049
23133
  );
23050
23134
  }
23135
+ /** `GET /accounts/{accountId}/webhooks/endpoints` — list webhook endpoints, oldest first. */
23136
+ async listEndpoints(accountId) {
23137
+ const id = this.accountId(accountId);
23138
+ return this.call(
23139
+ "Failed to list webhook endpoints",
23140
+ () => this.http.get(`/accounts/${id}/webhooks/endpoints`)
23141
+ );
23142
+ }
23143
+ /**
23144
+ * `POST /accounts/{accountId}/webhooks/endpoints` — register another
23145
+ * endpoint. Accounts allow 1 endpoint, or up to 3 on paid plans (`403` past
23146
+ * the limit); URLs must be unique per workspace. Omitted `events` uses the
23147
+ * same default set as {@link register}.
23148
+ */
23149
+ async createEndpoint(payload, accountId) {
23150
+ if (!payload.url) throw new ValidationError("Webhook URL is required");
23151
+ validateWebhookFields({ ...payload, email: payload.email ?? "" });
23152
+ const id = this.accountId(accountId);
23153
+ const body = { ...payload, events: payload.events ?? DEFAULT_EVENTS };
23154
+ this.logger.info("Creating webhook endpoint", { eventCount: body.events.length });
23155
+ return this.call(
23156
+ "Failed to create webhook endpoint",
23157
+ () => this.http.post(`/accounts/${id}/webhooks/endpoints`, body)
23158
+ );
23159
+ }
23160
+ /** `GET /accounts/{accountId}/webhooks/endpoints/{endpointId}` — fetch one endpoint. */
23161
+ async getEndpoint(endpointId, accountId) {
23162
+ const id = this.accountId(accountId);
23163
+ const eid = this.requireId(endpointId, "Endpoint ID");
23164
+ return this.call(
23165
+ "Failed to fetch webhook endpoint",
23166
+ () => this.http.get(`/accounts/${id}/webhooks/endpoints/${eid}`)
23167
+ );
23168
+ }
23169
+ /**
23170
+ * `PUT /accounts/{accountId}/webhooks/endpoints/{endpointId}` — update only
23171
+ * the fields sent. Enabling signing creates a secret when none exists;
23172
+ * disabling it discards the secret.
23173
+ */
23174
+ async updateEndpoint(endpointId, payload, accountId) {
23175
+ const id = this.accountId(accountId);
23176
+ const eid = this.requireId(endpointId, "Endpoint ID");
23177
+ if (!payload || typeof payload !== "object" || Object.keys(payload).length === 0) {
23178
+ throw new ValidationError("At least one webhook endpoint field is required");
23179
+ }
23180
+ validateWebhookFields(payload);
23181
+ return this.call(
23182
+ "Failed to update webhook endpoint",
23183
+ () => this.http.put(`/accounts/${id}/webhooks/endpoints/${eid}`, payload)
23184
+ );
23185
+ }
23186
+ /** `DELETE /accounts/{accountId}/webhooks/endpoints/{endpointId}` — delete an endpoint and free its slot. */
23187
+ async deleteEndpoint(endpointId, accountId) {
23188
+ const id = this.accountId(accountId);
23189
+ const eid = this.requireId(endpointId, "Endpoint ID");
23190
+ return this.call(
23191
+ "Failed to delete webhook endpoint",
23192
+ () => this.http.delete(`/accounts/${id}/webhooks/endpoints/${eid}`)
23193
+ );
23194
+ }
23195
+ /**
23196
+ * `GET …/endpoints/{endpointId}/secret` — the `whsec_` signing secret.
23197
+ * Returns `400` when signing is disabled. Not available to OAuth applications.
23198
+ */
23199
+ async getEndpointSecret(endpointId, accountId) {
23200
+ const id = this.accountId(accountId);
23201
+ const eid = this.requireId(endpointId, "Endpoint ID");
23202
+ return this.call(
23203
+ "Failed to fetch webhook endpoint secret",
23204
+ () => this.http.get(`/accounts/${id}/webhooks/endpoints/${eid}/secret`)
23205
+ );
23206
+ }
23207
+ /**
23208
+ * `POST …/endpoints/{endpointId}/secret/rotate` — replace the signing secret.
23209
+ * The old secret stops working immediately. Not available to OAuth applications.
23210
+ */
23211
+ async rotateEndpointSecret(endpointId, accountId) {
23212
+ const id = this.accountId(accountId);
23213
+ const eid = this.requireId(endpointId, "Endpoint ID");
23214
+ this.logger.info("Rotating webhook endpoint secret");
23215
+ return this.call(
23216
+ "Failed to rotate webhook endpoint secret",
23217
+ () => this.http.post(`/accounts/${id}/webhooks/endpoints/${eid}/secret/rotate`)
23218
+ );
23219
+ }
23051
23220
  /** List currently supported webhook event types. */
23052
23221
  async listEventTypes() {
23053
23222
  return this.call(
@@ -23055,7 +23224,7 @@ var WebhookResource = class extends BaseResource {
23055
23224
  () => this.http.get("/webhooks/event-types")
23056
23225
  );
23057
23226
  }
23058
- /** List webhook delivery history for the workspace. */
23227
+ /** List webhook delivery history for the workspace, optionally for one endpoint. */
23059
23228
  async listDispatches(params = {}, accountId) {
23060
23229
  const id = this.accountId(accountId);
23061
23230
  if ("search" in params) throw new ValidationError("webhook dispatch search is not supported");
@@ -23067,7 +23236,7 @@ var WebhookResource = class extends BaseResource {
23067
23236
  })
23068
23237
  );
23069
23238
  }
23070
- /** Retry delivery of a specific webhook dispatch. */
23239
+ /** Retry delivery of a specific webhook dispatch to that entry's endpoint. */
23071
23240
  async retryDispatch(dispatchId, accountId) {
23072
23241
  const id = this.accountId(accountId);
23073
23242
  const did = this.requireId(dispatchId, "Dispatch ID");
@@ -23176,6 +23345,17 @@ function validateNotificationSender(value) {
23176
23345
 
23177
23346
  // src/api/support/webhook-verifier.ts
23178
23347
  var import_node_crypto2 = require("crypto");
23348
+ function readHeader(headers, name) {
23349
+ if (typeof headers.get === "function") {
23350
+ return headers.get(name) ?? void 0;
23351
+ }
23352
+ for (const [key, value] of Object.entries(headers)) {
23353
+ if (key.toLowerCase() !== name) continue;
23354
+ if (Array.isArray(value)) return value.length === 1 ? value[0] : void 0;
23355
+ return value;
23356
+ }
23357
+ return void 0;
23358
+ }
23179
23359
  var WebhookVerifier = class {
23180
23360
  constructor(webhookSecret, options = {}) {
23181
23361
  this.webhookSecret = webhookSecret;
@@ -23185,15 +23365,48 @@ var WebhookVerifier = class {
23185
23365
  webhookSecret;
23186
23366
  algorithm;
23187
23367
  encoding;
23188
- /** Returns `true` if `signature` is a valid HMAC of `payload` under the configured scheme. */
23368
+ /**
23369
+ * Returns `true` when `headers` carry a Standard Webhooks signature that
23370
+ * matches the raw `payload` under this verifier's `whsec_` secret and the
23371
+ * `webhook-timestamp` is within the tolerance window. Pass the body exactly
23372
+ * as received; re-serialized JSON does not verify.
23373
+ */
23374
+ verifyDelivery(payload, headers, options = {}) {
23375
+ if (!this.webhookSecret || !headers) return false;
23376
+ const id = readHeader(headers, "webhook-id");
23377
+ const timestamp = readHeader(headers, "webhook-timestamp");
23378
+ const signatures = readHeader(headers, "webhook-signature");
23379
+ if (!id || !timestamp || !signatures || !/^\d+$/.test(timestamp)) return false;
23380
+ const tolerance = options.toleranceSeconds ?? 300;
23381
+ const now = Math.floor((options.now ?? Date.now()) / 1e3);
23382
+ if (Math.abs(now - Number(timestamp)) > tolerance) return false;
23383
+ const secret = this.webhookSecret.startsWith("whsec_") ? this.webhookSecret.slice("whsec_".length) : this.webhookSecret;
23384
+ const key = Buffer.from(secret, "base64");
23385
+ if (key.length === 0) return false;
23386
+ const expected = Buffer.from(
23387
+ (0, import_node_crypto2.createHmac)("sha256", key).update(`${id}.${timestamp}.`).update(typeof payload === "string" ? Buffer.from(payload, "utf8") : payload).digest("base64")
23388
+ );
23389
+ return signatures.split(" ").some((entry) => {
23390
+ const [version, value] = entry.split(",", 2);
23391
+ if (version !== "v1" || !value) return false;
23392
+ const provided = Buffer.from(value);
23393
+ return provided.length === expected.length && (0, import_node_crypto2.timingSafeEqual)(provided, expected);
23394
+ });
23395
+ }
23396
+ /**
23397
+ * Returns `true` if `signature` is an HMAC of `payload` keyed with the raw
23398
+ * secret string under the configured algorithm/encoding.
23399
+ *
23400
+ * @deprecated Assinafy signs deliveries with Standard Webhooks headers; use
23401
+ * {@link verifyDelivery}. Retained for existing callers.
23402
+ */
23189
23403
  verify(payload, signature) {
23190
23404
  if (!this.webhookSecret || !signature) return false;
23191
23405
  try {
23192
23406
  const buf = typeof payload === "string" ? Buffer.from(payload, "utf8") : payload;
23193
23407
  const expected = (0, import_node_crypto2.createHmac)(this.algorithm, this.webhookSecret).update(buf).digest(this.encoding);
23194
- const provided = signature.trim();
23195
23408
  const a2 = Buffer.from(expected, "utf8");
23196
- const b = Buffer.from(provided, "utf8");
23409
+ const b = Buffer.from(signature.trim(), "utf8");
23197
23410
  if (a2.length !== b.length) return false;
23198
23411
  return (0, import_node_crypto2.timingSafeEqual)(a2, b);
23199
23412
  } catch {
@@ -25131,30 +25344,157 @@ function unwrap(value) {
25131
25344
  function resetPasswordPayload(email, resetToken, newPassword) {
25132
25345
  return { email, token: resetToken, new_password: newPassword };
25133
25346
  }
25347
+ var mfaCodeOption = () => new Option(
25348
+ "--mfa-code <code>",
25349
+ "Authenticator or recovery code (prompted if required and omitted)"
25350
+ ).env("ASSINAFY_MFA_CODE");
25351
+ var printSession = (result, config) => {
25352
+ printSuccess(`Logged in as ${result.user.email}`, config);
25353
+ printData(
25354
+ result,
25355
+ config,
25356
+ (r2) => renderKeyValue({
25357
+ access_token: r2.access_token,
25358
+ user: r2.user.email,
25359
+ accounts: r2.accounts.map((a2) => a2.id)
25360
+ })
25361
+ );
25362
+ };
25134
25363
  var loginCommand = new Command("login").description(
25135
- "Exchange email + password for a JWT access token (no existing credentials required)"
25364
+ "Exchange email + password (and a two-factor code when enabled) for a JWT access token (no existing credentials required)"
25136
25365
  ).argument("<email>", "Account email").addOption(
25137
25366
  new Option("--password <password>", "Password (prompted if omitted)").env("ASSINAFY_PASSWORD")
25138
- ).action(async (email, opts, command) => {
25367
+ ).addOption(mfaCodeOption()).action(async (email, opts, command) => {
25139
25368
  await runWithPublicClient(command, async ({ client, config }) => {
25140
25369
  const password2 = opts.password ?? await promptSecret("Password");
25141
- const result = await withSpinner(
25370
+ let result = await withSpinner(
25142
25371
  "Logging in",
25143
25372
  config,
25144
25373
  () => client.auth.login(email, password2)
25145
25374
  );
25146
- printSuccess(`Logged in as ${result.user.email}`, config);
25375
+ if (!result.access_token && result.mfa_token) {
25376
+ const mfaToken = result.mfa_token;
25377
+ const code = opts.mfaCode ?? await promptSecret("Two-factor code");
25378
+ result = await withSpinner(
25379
+ "Verifying two-factor code",
25380
+ config,
25381
+ () => client.auth.verifyMfa({ mfa_token: mfaToken, code })
25382
+ );
25383
+ }
25384
+ printSession(result, config);
25385
+ });
25386
+ });
25387
+ var mfaVerifyCommand = new Command("verify").description(
25388
+ "Complete a two-factor login with the mfa_token from login (no existing credentials required)"
25389
+ ).addOption(
25390
+ new Option("--mfa-token <token>", "Challenge token returned by login").env("ASSINAFY_MFA_TOKEN").makeOptionMandatory()
25391
+ ).addOption(mfaCodeOption()).action(async (opts, command) => {
25392
+ await runWithPublicClient(command, async ({ client, config }) => {
25393
+ const code = opts.mfaCode ?? await promptSecret("Two-factor code");
25394
+ const result = await withSpinner(
25395
+ "Verifying two-factor code",
25396
+ config,
25397
+ () => client.auth.verifyMfa({ mfa_token: opts.mfaToken, code })
25398
+ );
25399
+ printSession(result, config);
25400
+ });
25401
+ });
25402
+ var mfaListCommand = new Command("list").alias("ls").description("List enrolled two-factor methods and remaining recovery codes").action(async (_opts, command) => {
25403
+ await runWithClient(command, async ({ client, config }) => {
25404
+ const result = await withSpinner(
25405
+ "Fetching two-factor methods",
25406
+ config,
25407
+ () => client.auth.listMfaMethods()
25408
+ );
25147
25409
  printData(
25148
25410
  result,
25149
25411
  config,
25150
- (r2) => renderKeyValue({
25151
- access_token: r2.access_token,
25152
- user: r2.user.email,
25153
- accounts: r2.accounts.map((a2) => a2.id)
25412
+ (r2) => [
25413
+ renderTable(r2.methods, [
25414
+ { header: "ID", value: (m) => m.id },
25415
+ { header: "TYPE", value: (m) => m.type },
25416
+ { header: "LABEL", value: (m) => m.label },
25417
+ { header: "CONFIRMED", value: (m) => m.confirmed_at },
25418
+ { header: "LAST USED", value: (m) => m.last_used_at }
25419
+ ]),
25420
+ `Recovery codes remaining: ${r2.recovery_codes_remaining}`
25421
+ ].join("\n")
25422
+ );
25423
+ });
25424
+ });
25425
+ var mfaEnrollCommand = new Command("enroll").description("Start authenticator enrollment; prints the one-time secret and provisioning URI").option("--label <label>", "Name for the authenticator").action(async (opts, command) => {
25426
+ await runWithClient(command, async ({ client, config }) => {
25427
+ const result = await withSpinner(
25428
+ "Starting enrollment",
25429
+ config,
25430
+ () => client.auth.startTotpEnrollment(opts.label)
25431
+ );
25432
+ printSuccess(
25433
+ `Enrollment started. Confirm with: assinafy auth mfa confirm ${result.id}`,
25434
+ config
25435
+ );
25436
+ printData(result, config, (r2) => renderKeyValue({ ...r2 }));
25437
+ });
25438
+ });
25439
+ var reauthPasswordOption = () => new Option("--password <password>", "Current password").env("ASSINAFY_PASSWORD");
25440
+ async function reauthPayload(opts) {
25441
+ if (opts.password) return { password: opts.password };
25442
+ return { code: opts.mfaCode ?? await promptSecret("Authenticator or recovery code") };
25443
+ }
25444
+ var mfaConfirmCommand = new Command("confirm").description("Activate an enrolled authenticator and print the one-time recovery codes").argument("<methodId>", "Method ID returned by enroll").addOption(new Option("--code <code>", "Live code from the new authenticator")).addOption(
25445
+ new Option(
25446
+ "--password <password>",
25447
+ "Current password (only when replacing a confirmed method)"
25448
+ ).env("ASSINAFY_PASSWORD")
25449
+ ).addOption(
25450
+ new Option(
25451
+ "--reauth-code <code>",
25452
+ "Code from the current authenticator or a recovery code (only when replacing)"
25453
+ ).conflicts("password")
25454
+ ).action(async (methodId, opts, command) => {
25455
+ await runWithClient(command, async ({ client, config }) => {
25456
+ const code = opts.code ?? await promptSecret("Code from the new authenticator");
25457
+ const result = await withSpinner(
25458
+ "Confirming enrollment",
25459
+ config,
25460
+ () => client.auth.confirmTotpEnrollment({
25461
+ id: methodId,
25462
+ code,
25463
+ ...opts.password ? { password: opts.password } : {},
25464
+ ...opts.reauthCode ? { reauth_code: opts.reauthCode } : {}
25154
25465
  })
25155
25466
  );
25467
+ printSuccess("Two-factor authentication enabled. Store the recovery codes now.", config);
25468
+ printData(result, config, (r2) => r2.recovery_codes.join("\n"));
25469
+ });
25470
+ });
25471
+ var mfaRecoveryCodesCommand = new Command("recovery-codes").description("Issue ten new recovery codes and invalidate the previous set").addOption(reauthPasswordOption()).addOption(mfaCodeOption().conflicts("password")).action(async (opts, command) => {
25472
+ await runWithClient(command, async ({ client, config }) => {
25473
+ const payload = await reauthPayload(opts);
25474
+ const result = await withSpinner(
25475
+ "Regenerating recovery codes",
25476
+ config,
25477
+ () => client.auth.regenerateRecoveryCodes(payload)
25478
+ );
25479
+ printSuccess("Recovery codes regenerated. Store them now.", config);
25480
+ printData(result, config, (r2) => r2.recovery_codes.join("\n"));
25156
25481
  });
25157
25482
  });
25483
+ var mfaRemoveCommand = new Command("remove").alias("rm").description("Remove a two-factor method (the last one also discards recovery codes)").argument("<methodId>", "Method ID").addOption(reauthPasswordOption()).addOption(mfaCodeOption().conflicts("password")).option("-y, --yes", "Skip the confirmation prompt").action(async (methodId, opts, command) => {
25484
+ await runWithClient(command, async ({ client, config }) => {
25485
+ if (!await confirmDestructive(`Remove two-factor method ${methodId}?`, Boolean(opts.yes)))
25486
+ return;
25487
+ const payload = await reauthPayload(opts);
25488
+ const result = await withSpinner(
25489
+ "Removing two-factor method",
25490
+ config,
25491
+ () => client.auth.removeMfaMethod(methodId, payload)
25492
+ );
25493
+ printSuccess("Two-factor method removed", config);
25494
+ printData(result, config);
25495
+ });
25496
+ });
25497
+ var mfaCommand = new Command("mfa").description("Two-factor authentication: login verification, enrollment, and recovery codes").addCommand(mfaVerifyCommand).addCommand(mfaListCommand).addCommand(mfaEnrollCommand).addCommand(mfaConfirmCommand).addCommand(mfaRecoveryCodesCommand).addCommand(mfaRemoveCommand);
25158
25498
  var socialLoginCommand = new Command("social-login").description("Exchange a provider token for an Assinafy JWT (no existing credentials required)").addOption(
25159
25499
  new Option("--provider <provider>", "OAuth provider").choices(["google"]).makeOptionMandatory()
25160
25500
  ).addOption(
@@ -25277,7 +25617,7 @@ var apiKeyDeleteCommand = new Command("delete").alias("rm").description("Revoke
25277
25617
  });
25278
25618
  });
25279
25619
  var apiKeysCommand = new Command("api-keys").description("Manage the current user personal API key").addCommand(apiKeyCreateCommand).addCommand(apiKeyGetCommand).addCommand(apiKeyDeleteCommand);
25280
- var authCommand = new Command("auth").description("Authentication, password management, and personal API keys").addCommand(loginCommand).addCommand(socialLoginCommand).addCommand(linkSocialLoginCommand).addCommand(changePasswordCommand).addCommand(requestResetCommand).addCommand(resetPasswordCommand).addCommand(apiKeysCommand);
25620
+ var authCommand = new Command("auth").description("Authentication, password management, and personal API keys").addCommand(loginCommand).addCommand(socialLoginCommand).addCommand(linkSocialLoginCommand).addCommand(changePasswordCommand).addCommand(requestResetCommand).addCommand(resetPasswordCommand).addCommand(apiKeysCommand).addCommand(mfaCommand);
25281
25621
 
25282
25622
  // src/commands/config/index.ts
25283
25623
  var import_picocolors5 = __toESM(require_picocolors(), 1);
@@ -26932,7 +27272,7 @@ var preferencesCommand = new Command("notification-preferences").alias("preferen
26932
27272
  var usersCommand = new Command("users").description("Show the authenticated user and personal preferences").addCommand(selfCommand2).addCommand(statsCommand).addCommand(preferencesCommand);
26933
27273
 
26934
27274
  // src/commands/webhooks.ts
26935
- var registerCommand = new Command("register").description("Register (or replace) the workspace webhook subscription").requiredOption("--url <url>", "Endpoint URL to receive events").requiredOption("--email <email>", "Contact email for delivery problems").option("--events <csv>", "Comma-separated event names (defaults to a sensible set)").option("--inactive", "Register the subscription as inactive").action(async (opts, command) => {
27275
+ var registerCommand = new Command("register").description("Register (or replace) the account's oldest webhook endpoint").requiredOption("--url <url>", "Endpoint URL to receive events").requiredOption("--email <email>", "Contact email for delivery problems").option("--events <csv>", "Comma-separated event names (defaults to a sensible set)").option("--inactive", "Register the subscription as inactive").action(async (opts, command) => {
26936
27276
  await runWithClient(command, async ({ client, config }) => {
26937
27277
  const accountId = requireAccountId(config);
26938
27278
  const events = splitList(opts.events);
@@ -26952,7 +27292,7 @@ var registerCommand = new Command("register").description("Register (or replace)
26952
27292
  );
26953
27293
  });
26954
27294
  });
26955
- var getCommand6 = new Command("get").description("Show the current webhook subscription").action(async (_opts, command) => {
27295
+ var getCommand6 = new Command("get").description("Show the account's oldest webhook endpoint").action(async (_opts, command) => {
26956
27296
  await runWithClient(command, async ({ client, config }) => {
26957
27297
  const accountId = requireAccountId(config);
26958
27298
  const sub = await withSpinner(
@@ -26971,7 +27311,7 @@ var getCommand6 = new Command("get").description("Show the current webhook subsc
26971
27311
  );
26972
27312
  });
26973
27313
  });
26974
- var inactivateCommand = new Command("inactivate").description("Inactivate the webhook subscription without deleting it").action(async (_opts, command) => {
27314
+ var inactivateCommand = new Command("inactivate").description("Inactivate the account's oldest webhook endpoint without deleting it").action(async (_opts, command) => {
26975
27315
  await runWithClient(command, async ({ client, config }) => {
26976
27316
  const accountId = requireAccountId(config);
26977
27317
  const sub = await withSpinner(
@@ -27001,12 +27341,13 @@ var eventTypesCommand = new Command("event-types").description("List supported w
27001
27341
  });
27002
27342
  });
27003
27343
  var dispatchesCommand = addSortableListOptions(
27004
- new Command("dispatches").description("List webhook delivery history").option("--event <event>", "Filter by event name").option("--delivered <bool>", "Filter by delivery status (true/false)").option("--from <unix>", "Start of time range (unix seconds)").option("--to <unix>", "End of time range (unix seconds)"),
27344
+ new Command("dispatches").description("List webhook delivery history").option("--endpoint <endpointId>", "Only deliveries to this webhook endpoint").option("--event <event>", "Filter by event name").option("--delivered <bool>", "Filter by delivery status (true/false)").option("--from <unix>", "Start of time range (unix seconds)").option("--to <unix>", "End of time range (unix seconds)"),
27005
27345
  "Sort by created_at (prefix with - for descending)"
27006
27346
  ).action(async (opts, command) => {
27007
27347
  await runWithClient(command, async ({ client, config }) => {
27008
27348
  const accountId = requireAccountId(config);
27009
27349
  const params = { ...listParams(opts) };
27350
+ if (opts.endpoint) params.endpoint_id = opts.endpoint;
27010
27351
  if (opts.event) params.event = opts.event;
27011
27352
  if (opts.delivered !== void 0) {
27012
27353
  const v = opts.delivered.toLowerCase();
@@ -27052,7 +27393,144 @@ var retryCommand = new Command("retry").description("Retry delivery of a specifi
27052
27393
  );
27053
27394
  });
27054
27395
  });
27055
- var webhooksCommand = new Command("webhooks").description("Manage webhook subscriptions and delivery history").addCommand(registerCommand).addCommand(getCommand6).addCommand(inactivateCommand).addCommand(eventTypesCommand).addCommand(dispatchesCommand).addCommand(retryCommand);
27396
+ var renderEndpoint = (e) => renderKeyValue({
27397
+ id: e.id,
27398
+ name: e.name,
27399
+ url: e.url,
27400
+ email: e.email,
27401
+ is_active: e.is_active,
27402
+ signing_enabled: e.signing_enabled,
27403
+ events: e.events
27404
+ });
27405
+ function endpointFieldOptions(command) {
27406
+ return command.option("--name <name>", "Label to tell endpoints apart").option("--events <csv>", "Comma-separated event names").addOption(new Option("--active", "Deliver events to this endpoint")).addOption(new Option("--inactive", "Stop delivering events").conflicts("active")).addOption(new Option("--signing", "Sign deliveries (Standard Webhooks)")).addOption(
27407
+ new Option("--no-signing", "Disable signing and discard the secret").default(void 0)
27408
+ );
27409
+ }
27410
+ function endpointPayload(opts) {
27411
+ const payload = {};
27412
+ if (opts.url !== void 0) payload.url = opts.url;
27413
+ if (opts.email !== void 0) payload.email = opts.email;
27414
+ if (opts.name !== void 0) payload.name = opts.name;
27415
+ const events = splitList(opts.events);
27416
+ if (events !== void 0) payload.events = events;
27417
+ if (opts.active || opts.inactive) payload.is_active = Boolean(opts.active);
27418
+ if (opts.signing !== void 0) payload.signing_enabled = opts.signing;
27419
+ return payload;
27420
+ }
27421
+ var endpointsListCommand = new Command("list").alias("ls").description("List webhook endpoints, oldest first").action(async (_opts, command) => {
27422
+ await runWithClient(command, async ({ client, config }) => {
27423
+ const accountId = requireAccountId(config);
27424
+ const rows = await withSpinner(
27425
+ "Fetching endpoints",
27426
+ config,
27427
+ () => client.webhooks.listEndpoints(accountId)
27428
+ );
27429
+ printData(
27430
+ rows,
27431
+ config,
27432
+ (list) => renderTable(list, [
27433
+ { header: "ID", value: (r2) => r2.id },
27434
+ { header: "NAME", value: (r2) => r2.name },
27435
+ { header: "URL", value: (r2) => r2.url },
27436
+ { header: "ACTIVE", value: (r2) => r2.is_active },
27437
+ { header: "SIGNED", value: (r2) => r2.signing_enabled }
27438
+ ])
27439
+ );
27440
+ });
27441
+ });
27442
+ var endpointsCreateCommand = endpointFieldOptions(
27443
+ new Command("create").description("Register a webhook endpoint (1 per account, up to 3 on paid plans)").requiredOption("--url <url>", "Endpoint URL to receive events").requiredOption("--email <email>", "Contact email for delivery problems")
27444
+ ).action(async (opts, command) => {
27445
+ await runWithClient(command, async ({ client, config }) => {
27446
+ const accountId = requireAccountId(config);
27447
+ const endpoint = await withSpinner(
27448
+ "Creating endpoint",
27449
+ config,
27450
+ () => client.webhooks.createEndpoint(
27451
+ { ...endpointPayload(opts), url: opts.url, email: opts.email },
27452
+ accountId
27453
+ )
27454
+ );
27455
+ printSuccess("Webhook endpoint created", config);
27456
+ printData(endpoint, config, renderEndpoint);
27457
+ });
27458
+ });
27459
+ var endpointsGetCommand = new Command("get").description("Show one webhook endpoint").argument("<endpointId>", "Endpoint ID").action(async (endpointId, _opts, command) => {
27460
+ await runWithClient(command, async ({ client, config }) => {
27461
+ const accountId = requireAccountId(config);
27462
+ const endpoint = await withSpinner(
27463
+ "Fetching endpoint",
27464
+ config,
27465
+ () => client.webhooks.getEndpoint(endpointId, accountId)
27466
+ );
27467
+ printData(endpoint, config, renderEndpoint);
27468
+ });
27469
+ });
27470
+ var endpointsUpdateCommand = endpointFieldOptions(
27471
+ new Command("update").description("Update the given fields of a webhook endpoint").argument("<endpointId>", "Endpoint ID").option("--url <url>", "Endpoint URL to receive events").option("--email <email>", "Contact email for delivery problems")
27472
+ ).action(async (endpointId, opts, command) => {
27473
+ await runWithClient(command, async ({ client, config }) => {
27474
+ const accountId = requireAccountId(config);
27475
+ const payload = endpointPayload(opts);
27476
+ if (Object.keys(payload).length === 0) {
27477
+ throw new CliError("Provide at least one field to update");
27478
+ }
27479
+ const endpoint = await withSpinner(
27480
+ "Updating endpoint",
27481
+ config,
27482
+ () => client.webhooks.updateEndpoint(endpointId, payload, accountId)
27483
+ );
27484
+ printSuccess("Webhook endpoint updated", config);
27485
+ printData(endpoint, config, renderEndpoint);
27486
+ });
27487
+ });
27488
+ var endpointsDeleteCommand = new Command("delete").alias("rm").description("Delete a webhook endpoint and free its slot").argument("<endpointId>", "Endpoint ID").option("-y, --yes", "Skip the confirmation prompt").action(async (endpointId, opts, command) => {
27489
+ await runWithClient(command, async ({ client, config }) => {
27490
+ const accountId = requireAccountId(config);
27491
+ if (!await confirmDestructive(`Delete webhook endpoint ${endpointId}?`, Boolean(opts.yes)))
27492
+ return;
27493
+ await withSpinner(
27494
+ "Deleting endpoint",
27495
+ config,
27496
+ () => client.webhooks.deleteEndpoint(endpointId, accountId)
27497
+ );
27498
+ printSuccess("Webhook endpoint deleted", config);
27499
+ printData({ id: endpointId, deleted: true }, config);
27500
+ });
27501
+ });
27502
+ var endpointsSecretCommand = new Command("secret").description(
27503
+ "Print the endpoint signing secret (signing must be enabled; not available via OAuth)"
27504
+ ).argument("<endpointId>", "Endpoint ID").action(async (endpointId, _opts, command) => {
27505
+ await runWithClient(command, async ({ client, config }) => {
27506
+ const accountId = requireAccountId(config);
27507
+ const result = await withSpinner(
27508
+ "Fetching secret",
27509
+ config,
27510
+ () => client.webhooks.getEndpointSecret(endpointId, accountId)
27511
+ );
27512
+ printData(result, config, (r2) => r2.secret);
27513
+ });
27514
+ });
27515
+ var endpointsRotateSecretCommand = new Command("rotate-secret").description("Replace the endpoint signing secret; the old one stops working immediately").argument("<endpointId>", "Endpoint ID").option("-y, --yes", "Skip the confirmation prompt").action(async (endpointId, opts, command) => {
27516
+ await runWithClient(command, async ({ client, config }) => {
27517
+ const accountId = requireAccountId(config);
27518
+ if (!await confirmDestructive(
27519
+ `Rotate the signing secret of ${endpointId}? The current secret stops working immediately.`,
27520
+ Boolean(opts.yes)
27521
+ ))
27522
+ return;
27523
+ const result = await withSpinner(
27524
+ "Rotating secret",
27525
+ config,
27526
+ () => client.webhooks.rotateEndpointSecret(endpointId, accountId)
27527
+ );
27528
+ printSuccess("Signing secret rotated", config);
27529
+ printData(result, config, (r2) => r2.secret);
27530
+ });
27531
+ });
27532
+ var endpointsCommand = new Command("endpoints").description("Manage webhook endpoints and their signing secrets").addCommand(endpointsListCommand).addCommand(endpointsCreateCommand).addCommand(endpointsGetCommand).addCommand(endpointsUpdateCommand).addCommand(endpointsDeleteCommand).addCommand(endpointsSecretCommand).addCommand(endpointsRotateSecretCommand);
27533
+ var webhooksCommand = new Command("webhooks").description("Manage webhook endpoints, the primary subscription, and delivery history").addCommand(endpointsCommand).addCommand(registerCommand).addCommand(getCommand6).addCommand(inactivateCommand).addCommand(eventTypesCommand).addCommand(dispatchesCommand).addCommand(retryCommand);
27056
27534
 
27057
27535
  // src/commands/whoami.ts
27058
27536
  var whoamiCommand = new Command("whoami").description("Verify credentials and list the workspaces they can access").action(async (_opts, command) => {
@@ -27275,7 +27753,7 @@ function handleStreamError(err, fallback, exit = process.exit) {
27275
27753
  // package.json
27276
27754
  var package_default = {
27277
27755
  name: "@assinafy/cli",
27278
- version: "2.4.2",
27756
+ version: "2.5.0",
27279
27757
  description: "The official command-line interface for the Assinafy digital-signature API",
27280
27758
  license: "MIT",
27281
27759
  type: "module",