claude.ai's two-step "Add custom connector" dialog probes the server URL without credentials and pre-fills the Authentication choice from the answer. Our lazy-auth endpoint (issue #1814) answers 200 on an anonymous initialize, which the dialog reads as an authless server: it suggests "None", and a connector added with that default never opens the sign-in when the challenge arrives later. Per Anthropic's connector docs a 401 is the only answer it reads as OAuth ("Claude does not honor a WWW-Authenticate header on a 200 response"). - `auth=required` on the endpoint URL (extensions/general/mcp-server/ auth-mode.ts) turns lazy auth off for that URL: every tokenless request, initialize included, answers the 401 + WWW-Authenticate challenge. Callers with a token are unaffected; the bare URL keeps lazy auth for Claude Code, the plugin, Cursor and ChatGPT, and existing connector records are untouched. - The links we control carry the flag: Settings -> API & MCP (install link and copy block), the onboarding checklist, both docs pages and claude-plugin/CONNECTORS.md (plugin 1.2.3). The docs' Path A now describes the eager flow (sign-in opens on Add) instead of telling users to override the dialog's "None". - Tests: eager-auth.test.ts (401 on initialize/tools/list/public tools, namespaced metadata pointer, token no-op, exact-flag only); checklist link shape updated. Companion: gnubok-website PR (Kom igång connector link + regenerated connect-claude / anslut-claude pages). Claude-Session: https://claude.ai/code/session_013yw62FMXGSzo6icFDiBwP3 Co-authored-by: Jakob Wennberg <311770904+jakobwennberg-oss@users.noreply.github.com> Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
97 lines
4.2 KiB
TypeScript
97 lines
4.2 KiB
TypeScript
import type { InitialSetupPath, MomsPeriod } from '@/types'
|
|
|
|
/**
|
|
* What the Skatteverket checklist step should say about VAT deadlines.
|
|
*
|
|
* - 'date': the company's next momsdeklaration due date is known; show it.
|
|
* - 'missing_period': the company is VAT-registered but moms_period is unset,
|
|
* which makes the deadline engine silently generate ZERO VAT deadlines
|
|
* (lib/tax/deadline-config.ts conditions all require a concrete period).
|
|
* An empty deadlines query in that state means misconfiguration, not
|
|
* "no VAT duty", so the UI must prompt for the period instead of showing
|
|
* nothing.
|
|
* - null: not VAT-registered (no line), or VAT-registered with a period set
|
|
* but no upcoming row surfaced (transient or horizon gap; say nothing
|
|
* rather than guessing).
|
|
*/
|
|
export type VatDeadlineLine =
|
|
| { kind: 'date'; dueDate: string }
|
|
| { kind: 'missing_period' }
|
|
| null
|
|
|
|
export function vatDeadlineLine(input: {
|
|
vatRegistered: boolean | null | undefined
|
|
momsPeriod: MomsPeriod | null | undefined
|
|
nextVatDueDate: string | null | undefined
|
|
}): VatDeadlineLine {
|
|
if (!input.vatRegistered) return null
|
|
if (!input.momsPeriod) return { kind: 'missing_period' }
|
|
if (!input.nextVatDueDate) return null
|
|
return { kind: 'date', dueDate: input.nextVatDueDate }
|
|
}
|
|
|
|
/**
|
|
* Display ordinals for the setup checklist steps. Books and bank are always
|
|
* present; Skatteverket and the receipts/inbox step render only when their
|
|
* extensions are enabled; the assistant step is always last. `count` drives
|
|
* the "{count} steg så är bokföringen igång" title.
|
|
*/
|
|
export function checklistNumbers(gates: { hasSkatteverket: boolean; hasInbox: boolean }): {
|
|
count: number
|
|
skv: number
|
|
receipts: number
|
|
assistant: number
|
|
} {
|
|
const skv = 3
|
|
const receipts = 3 + (gates.hasSkatteverket ? 1 : 0)
|
|
const assistant = receipts + (gates.hasInbox ? 1 : 0)
|
|
return { count: assistant, skv, receipts, assistant }
|
|
}
|
|
|
|
/**
|
|
* Body of the PATCH that retires the checklist once every step is done.
|
|
* The route refuses `completed: true` without a path ("Välj först hur du
|
|
* vill komma igång"). `path` is null when the journey's books question was
|
|
* skipped and the books then arrived through /import or MCP; in that state
|
|
* step 1 can only be done via an import, so `migration` is the truthful path
|
|
* to record. Without it that cohort looped on a 400 (PR #2147 skeptic).
|
|
*/
|
|
export function completionPatchBody(
|
|
path: InitialSetupPath | null,
|
|
): { completed: true; path?: InitialSetupPath } {
|
|
return path ? { completed: true } : { completed: true, path: 'migration' }
|
|
}
|
|
|
|
/**
|
|
* Done-state for the "Anslut till Claude" step. The only thing that means
|
|
* "connected" is a live API key minted by the MCP OAuth token route: it
|
|
* exists exactly when a client (claude.ai, Claude Desktop, Claude Code)
|
|
* completed the first-call sign-in. `oauthKeyCount` is the head count of
|
|
* that user's unrevoked rows named by OAUTH_MCP_KEY_NAME (lib/auth/api-keys).
|
|
* Before issue #2133 the step ticked on the in-app AI-profile flag, which
|
|
* has nothing to do with Claude; the step could show done for a user who
|
|
* never connected and stay open for one who had.
|
|
*/
|
|
export function claudeStepDone(input: { oauthKeyCount: number | null | undefined }): boolean {
|
|
return (input.oauthKeyCount ?? 0) > 0
|
|
}
|
|
|
|
/**
|
|
* The claude.ai Add-custom-connector deep link the checklist's Claude step
|
|
* opens. Same shape as the Settings → API & MCP button: `tool_namespace` is
|
|
* load-bearing (without it the server hands out legacy `gnubok_` tool
|
|
* names), `client` is a telemetry-only distribution marker, `auth=required`
|
|
* makes claude.ai's dialog detect OAuth instead of "None" (see
|
|
* extensions/general/mcp-server/auth-mode.ts), and the origin comes from the
|
|
* page so self-hosted and white-label domains link to themselves. The link
|
|
* only prefills the dialog; the user reviews there.
|
|
*/
|
|
export function claudeConnectorLink(input: { origin: string; appName: string }): string {
|
|
const serverUrl = `${input.origin}/api/extensions/ext/mcp-server/mcp?tool_namespace=accounted&client=claude-connector&auth=required`
|
|
return (
|
|
'https://claude.ai/customize/connectors?modal=add-custom-connector' +
|
|
`&connectorName=${encodeURIComponent(input.appName)}` +
|
|
`&connectorUrl=${encodeURIComponent(serverUrl)}`
|
|
)
|
|
}
|