@localauth/cli 0.4.1 → 0.4.2

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/cli/ask.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { spawn } from 'node:child_process'
2
2
  import * as fs from 'node:fs/promises'
3
3
  import * as path from 'node:path'
4
- import { answerFields, isAskRequest, isFieldName, isReservedName, MAX_APPROVAL_DESCRIPTION } from '../shared/ask.ts'
4
+ import { answerFields, isApproval, isAskRequest, isFieldName, isReservedName, MAX_APPROVAL_DESCRIPTION } from '../shared/ask.ts'
5
5
  import { setTimeout as sleep } from 'node:timers/promises'
6
6
  import type { AnswerData, AskRequest, RunData } from '../shared/protocol.ts'
7
7
  import { isAnswer } from '../shared/validation.ts'
@@ -201,7 +201,7 @@ export async function approve(connection: Connection, options: ApproveOptions, s
201
201
  if (message.kind === 'decline') { decided = false; break }
202
202
  if (message.kind !== 'answer' || typeof message.data !== 'string' || !message.data.startsWith('a1.')) continue
203
203
  let value = await run.openMessage<AnswerData>('answer', message.data)
204
- if (isAnswer(value) && !value.declined && answerFields(value, request)?.APPROVE === 'yes') { decided = true; break }
204
+ if (isApproval(value)) { decided = true; break }
205
205
  }
206
206
  if (decided === null) await sleep(Math.min(1500, Math.max(1, expiresAt - Date.now())), undefined, { signal })
207
207
  } catch (error) { if (!signal.aborted) throw error }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@localauth/cli",
3
- "version": "0.4.1",
3
+ "version": "0.4.2",
4
4
  "description": "Finish CLI logins on a headless server from your phone, with optional passkey-based end-to-end encryption",
5
5
  "license": "MIT",
6
6
  "type": "module",
package/shared/ask.ts CHANGED
@@ -46,6 +46,11 @@ export function answerFields(answer: unknown, request: AskRequest, legacy = fals
46
46
  return Object.fromEntries(request.fields.filter(field => Object.hasOwn(fields, field.name)).map(field => [field.name, fields[field.name]]))
47
47
  }
48
48
 
49
+ /** Whether an answer approves. Only the answer matters here: an approval's description can be longer than an ask's. */
50
+ export function isApproval(answer: unknown): boolean {
51
+ return answerFields(answer, { fields: [{ name: 'APPROVE', label: 'Approve', secret: false, required: true }] })?.APPROVE === 'yes'
52
+ }
53
+
49
54
  /** Plain text segments and HTTP(S) URLs only. JSX renders both labels and segments as escaped text. */
50
55
  export function descriptionParts(text: string): { text: string; href?: string }[] {
51
56
  return text.split(/(https?:\/\/[^\s<>"']+)/g).filter(Boolean).map(text => {