Skip to content

Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.

fix(phone): webhook review round — no backend call without a paired phone, cached status

review53ddcd0b49d5
diff --git a/CLAUDE.md b/CLAUDE.md
index d3ddde96c..41b9a5df1 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -7364,34 +7364,57 @@ nodeterm-server (`src/routes/push-webhook.ts`, `src/lib/host-proof.ts`); the des
base64url), stored server-side only as its SHA-256 (a fast hash is right for a high-entropy
token), returned `Cache-Control: no-store`. The panel holds it in component state until "Done";
it is never written to settings.json, storage or a log (the panel test asserts local/session
- storage). There is no "show again" — Rotate mints a new one and revokes the old in one
- transaction (one live token per host).
-- **The example never puts the token on argv.** `pushWebhookCurlExample` reads
+ storage). There is no "show again" — Rotate mints a new one and revokes the old. One live token
+ per host is enforced by a partial UNIQUE index on the backend (`host_id WHERE revoked_at IS
+ NULL`), not by the mint's transaction: under READ COMMITTED two concurrent first mints each see
+ no live row and both insert.
+- **Viewing the page calls nothing without a paired phone.** The client asks `hasPairedPhone` (the
+ same local check as `pushHasPairedPhone`: a phone pin or a registry device) BEFORE reading the
+ host key or the network: the first read of `remote-host-key.json` CREATES it, and a status call
+ sends the device id + public key to the backend — neither may happen because someone opened
+ Settings → Phone. A failed local check reads as "no phone". And settings search unmounts and
+ remounts every row, so the panel reuses its last status answer for 5 minutes
+ (`STATUS_REUSE_MS`, module state) instead of spending a challenge + status round trip per remount
+ against a per-IP budget that everyone behind one NAT shares.
+- **The example never puts the token on argv.** `pushWebhookCurlExample` (labelled `sh`) reads
`$NODETERM_WEBHOOK_TOKEN` and feeds the header to `curl --config -` through `printf` (a shell
- builtin), the house rule for every credential we generate. `shared/push-webhook.test.ts` runs the
+ builtin), the house rule for every credential we generate. Windows has no `sh`, so there is a
+ `PowerShell` twin (`pushWebhookPowerShellExample`): `Invoke-RestMethod` makes the request
+ in-process, so there is no child argv at all (and PowerShell 5.1 mangles JSON quotes passed to
+ `curl.exe`). `shared/push-webhook.test.ts` runs the
example under a real `/bin/sh` with a recording curl and asserts the token reached stdin and not
argv.
- **The push is labelled and inert.** Subtitle `Webhook · <hostname>`, its own `thread-id`, the
phone's existing no-action category `AGENT_DONE`, and an `nt` block with `kind: 'webhook'` and no
`nodeId`, so a tap opens the Inbox and nothing else: no Allow/Deny buttons, no deep link, no URL
- opened. Title is one line (≤ 120 code points), body ≤ 500; C0/C1 controls and `\p{Cf}` (bidi,
- zero-width) are stripped. nodeterm mobile needs no release for it (read against its push handler:
- unknown `kind` + no `nodeId` routes to a plain Inbox open).
+ opened. Title is one line (≤ 120 code points), body ≤ 500; C0/C1 controls, lone surrogates and
+ the bidi/zero-width controls are stripped — NOT all of `\p{Cf}`, which holds ZWJ and the tag
+ characters (👨‍💻, subdivision flags) — and a payload over APNs' 4096 bytes is refused with a 413
+ rather than answered `sent: 0` (lone surrogates JSON-escape to 6 bytes each; measured 4103 bytes
+ before they were stripped).
+- **KNOWN GAP — needs an iOS release (@eneskirca).** The phone shows these pushes without a release
+ (unknown `kind` + no `nodeId` routes to a plain Inbox open), EXCEPT while its Inbox sheet is open:
+ `PushPresentation.shouldSuppressBanner` suppresses every push then (the live feed is assumed to
+ show it), so `willPresent` presents nothing — no banner, no sound, no Notification Center entry —
+ and a webhook message never appears in the Inbox feed. It is lost. The fix is phone-side: do not
+ suppress `nt.kind == "webhook"`.
- **Budgets:** 10 per minute per token, 60 per hour per HOST (keyed by hostId, so rotating does not
reset it), 20 mints per host per day, plus per-IP shields. Fan-out = exactly a host-mode
`/v1/push/notify`: this host's live relay pairings with a live APNs registration, minus phones
that muted this host.
- **Relay-paired phones only.** An SSH-granted phone (push grants) has no row the backend can tie to
this host, so it does not receive webhook pushes; minting with no live pairing answers
- `no_paired_phone` and the panel says so.
+ `no_paired_phone` and the panel says so. The desktop refuses before calling at all when it knows
+ of no paired phone, so a token left live after every phone is unpaired cannot be revoked from
+ here until a phone is paired again (it sends to nobody meanwhile).
- **No canvas-control verb.** An agent already has hook-driven pushes, and a verb would need the
desktop to hold the token, which it deliberately does not.
Surfaces: Desktop full. **Server Edition: N/A** — it has no relay host key or paired-phone
registry (same degrade as `push-notify.ts`); the bridge answers `E_UNSUPPORTED` and the row is
hidden in a browser tab. IPC is under `pairing:` so `HOST_ONLY_CHANNEL_PREFIXES` keeps it off the
-relay. **Mobile:** no change needed; an iOS follow-up could give `kind: 'webhook'` its own Inbox
-row and tap target.
+relay. **Mobile:** the Inbox-open gap above needs an iOS release; an iOS follow-up could also give
+`kind: 'webhook'` its own Inbox row and tap target.
## Hosted team relay (Server Edition as a relay host)
diff --git a/src/core/push-webhook.test.ts b/src/core/push-webhook.test.ts
index e850d408e..d0349fa61 100644
--- a/src/core/push-webhook.test.ts
+++ b/src/core/push-webhook.test.ts
@@ -55,6 +55,7 @@ function client(server: ReturnType<typeof fakeServer>, over: Partial<Parameters<
fetch: server.fetch,
apiBase: 'https://api.test',
loadHost: async () => host,
+ hasPairedPhone: async () => true,
isPackaged: () => true,
env: {},
...over
@@ -91,10 +92,12 @@ describe('push webhook client', () => {
expect(await client(fakeServer({ paired: false })).mint()).toEqual({ ok: false, error: 'no-paired-phone' })
expect(await client(fakeServer({ status: 429 })).status()).toEqual({ ok: false, error: 'rate-limited' })
expect(await client(fakeServer({ status: 502 })).status()).toEqual({ ok: false, error: 'unreachable' })
+ expect(await client(fakeServer({ status: 400 })).status()).toEqual({ ok: false, error: 'bad-request' })
const throwing = createPushWebhookClient({
fetch: (async () => { throw new Error('offline') }) as unknown as typeof fetch,
apiBase: 'https://api.test',
loadHost: async () => host,
+ hasPairedPhone: async () => true,
isPackaged: () => true
})
expect(await throwing.status()).toEqual({ ok: false, error: 'unreachable' })
@@ -104,8 +107,29 @@ describe('push webhook client', () => {
it('an unpackaged build without an API override calls nothing', async () => {
const s = fakeServer()
- const c = createPushWebhookClient({ fetch: s.fetch, loadHost: async () => host, isPackaged: () => false, env: {} })
+ const c = createPushWebhookClient({ fetch: s.fetch, loadHost: async () => host, hasPairedPhone: async () => true, isPackaged: () => false, env: {} })
expect(await c.status()).toEqual({ ok: false, error: 'dev-build' })
expect(s.calls).toHaveLength(0)
})
})
+
+it('with no paired phone it neither reads the host key nor calls the backend', async () => {
+ const s = fakeServer()
+ let keyReads = 0
+ const c = client(s, {
+ hasPairedPhone: async () => false,
+ loadHost: async () => {
+ keyReads++
+ return host
+ }
+ })
+ for (const r of [await c.status(), await c.mint(), await c.revoke()]) {
+ expect(r).toEqual({ ok: false, error: 'no-paired-phone' })
+ }
+ expect(keyReads).toBe(0)
+ expect(s.calls).toHaveLength(0)
+ // A failed local check reads as "no phone", never as permission to call.
+ const failing = client(s, { hasPairedPhone: async () => { throw new Error('unreadable') } })
+ expect(await failing.status()).toEqual({ ok: false, error: 'no-paired-phone' })
+ expect(s.calls).toHaveLength(0)
+})
diff --git a/src/core/push-webhook.ts b/src/core/push-webhook.ts
index 1908deced..2217c8d8c 100644
--- a/src/core/push-webhook.ts
+++ b/src/core/push-webhook.ts
@@ -43,6 +43,10 @@ export interface PushWebhookClientDeps {
apiBase?: string
/** Throws when the key cannot be read (keyring locked). */
loadHost: () => Promise<PushWebhookHost>
+ /** Is a phone paired with this machine at all? Asked BEFORE anything else: with no phone there
+ * is nobody to push to, and neither the host key (whose first read CREATES it) nor the backend
+ * (which would receive our device id and public key) is touched just because a page was viewed. */
+ hasPairedPhone: () => Promise<boolean>
/** false ⇒ the call is refused as 'dev-build' unless an api base override is configured. */
isPackaged: () => boolean
env?: Record<string, string | undefined>
@@ -83,6 +87,7 @@ function isTokenInfo(v: unknown): v is PushWebhookTokenInfo {
function errorFor(status: number, body: unknown): PushWebhookError {
const code = body && typeof body === 'object' ? (body as { error?: unknown }).error : undefined
if (status === 409 && code === 'no_paired_phone') return 'no-paired-phone'
+ if (status === 400) return 'bad-request'
if (status === 403) return 'refused'
if (status === 429) return 'rate-limited'
return 'unreachable'
@@ -114,6 +119,13 @@ export function createPushWebhookClient(deps: PushWebhookClientDeps): PushWebhoo
async function call(action: PushWebhookAction, path: string): Promise<PushWebhookResult<unknown>> {
if (!deps.isPackaged() && !env.NODETERM_API_BASE && !deps.apiBase) return { ok: false, error: 'dev-build' }
+ let paired = false
+ try {
+ paired = await deps.hasPairedPhone()
+ } catch {
+ paired = false
+ }
+ if (!paired) return { ok: false, error: 'no-paired-phone' }
let host: PushWebhookHost
try {
host = await deps.loadHost()
diff --git a/src/main/index.ts b/src/main/index.ts
index 19fd015f3..51adebe6c 100644
--- a/src/main/index.ts
+++ b/src/main/index.ts
@@ -1759,6 +1759,10 @@ app.whenReady().then(async () => {
// not kept by this process (core/push-webhook.ts).
const pushWebhook = createPushWebhookClient({
isPackaged: () => app.isPackaged,
+ // The same local check the host-mode push path uses (refreshPushIdentity below): no paired
+ // phone ⇒ the host key is not read (a first read creates it) and the backend is not called.
+ hasPairedPhone: async () =>
+ (await phonePins.load()).pubkeys.length > 0 || (await pairingService.listDevices()).length > 0,
loadHost: async () => {
const kp = await loadOrCreateKeyPair()
return { hostDeviceId: getDeviceId(), publicKey: kp.publicKey, secretKey: kp.secretKey, label: hostname() }
diff --git a/src/renderer/components/settings/sections/PushWebhookPanel.test.tsx b/src/renderer/components/settings/sections/PushWebhookPanel.test.tsx
index 6753059bb..27c3a05c6 100644
--- a/src/renderer/components/settings/sections/PushWebhookPanel.test.tsx
+++ b/src/renderer/components/settings/sections/PushWebhookPanel.test.tsx
@@ -2,7 +2,7 @@
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'
import { createRoot, type Root } from 'react-dom/client'
import { act } from 'react'
-import { PushWebhookPanel } from './PushWebhookPanel'
+import { PushWebhookPanel, resetPushWebhookStatusCache } from './PushWebhookPanel'
import type { PushWebhookResult, PushWebhookTokenInfo, PushWebhookMinted } from '@shared/push-webhook'
const TOKEN = 'ntwh_' + 'Z'.repeat(43)
@@ -42,6 +42,7 @@ async function click(label: string): Promise<void> {
}
beforeEach(() => {
+ resetPushWebhookStatusCache()
status = vi.fn(async () => ({ ok: true as const, value: null }))
mint = vi.fn(async () => ({ ok: true as const, value: { ...INFO, token: TOKEN } }))
revoke = vi.fn(async () => ({ ok: true as const, value: true as const }))
@@ -69,16 +70,25 @@ describe('PushWebhookPanel', () => {
await click('Create webhook token')
expect(host.textContent).toContain(TOKEN)
expect(host.textContent).toContain('won’t be shown again')
- await click('Copy')
+ const reveal = host.querySelector('[data-testid="webhook-token-reveal"]')!
+ await act(async () => {
+ Array.from(reveal.querySelectorAll('button')).find((b) => b.textContent === 'Copy')!.click()
+ })
expect(writeText).toHaveBeenCalledWith(TOKEN)
- // The example never embeds the token — it reads the env var and pipes the header on stdin.
- const pre = host.querySelector('pre')!.textContent!
- expect(pre).not.toContain(TOKEN)
- expect(pre).toContain('https://api.test/v1/push/webhook')
- expect(pre).toContain('--config -')
+ // Neither example embeds the token: sh pipes the header on stdin, PowerShell stays in-process.
+ const sh = host.querySelector('[data-testid="webhook-example-sh"] pre')!.textContent!
+ const ps = host.querySelector('[data-testid="webhook-example-powershell"] pre')!.textContent!
+ for (const ex of [sh, ps]) {
+ expect(ex).not.toContain(TOKEN)
+ expect(ex).toContain('https://api.test/v1/push/webhook')
+ }
+ expect(sh).toContain('--config -')
+ expect(ps).toContain('Invoke-RestMethod')
- await click('Done')
+ await act(async () => {
+ Array.from(reveal.querySelectorAll('button')).find((b) => b.textContent === 'Done')!.click()
+ })
expect(document.body.innerHTML).not.toContain(TOKEN)
expect(host.textContent).toContain('ntwh_ZZZZ…')
// Nothing kept it: not local storage, not session storage.
@@ -121,3 +131,28 @@ describe('PushWebhookPanel', () => {
expect(host.textContent).toContain('Pair a phone with remote access first')
})
})
+
+it('a remount reuses the last status instead of calling the backend again', async () => {
+ let calls = 0
+ status = async () => {
+ calls++
+ return { ok: true, value: INFO }
+ }
+ await render()
+ act(() => root.unmount())
+ host.remove()
+ await render()
+ expect(calls).toBe(1)
+ expect(host.textContent).toContain('ntwh_ZZZZ…')
+ // A revoke replaces the remembered answer, so the next mount does not show a dead token.
+ await click('Revoke')
+ const confirmBtn = Array.from(document.body.querySelectorAll('button')).filter((b) => b.textContent === 'Revoke').pop()!
+ await act(async () => {
+ confirmBtn.click()
+ })
+ act(() => root.unmount())
+ host.remove()
+ await render()
+ expect(calls).toBe(1)
+ expect(button('Create webhook token')).toBeTruthy()
+})
diff --git a/src/renderer/components/settings/sections/PushWebhookPanel.tsx b/src/renderer/components/settings/sections/PushWebhookPanel.tsx
index 3b794c007..5e7450ad3 100644
--- a/src/renderer/components/settings/sections/PushWebhookPanel.tsx
+++ b/src/renderer/components/settings/sections/PushWebhookPanel.tsx
@@ -7,10 +7,30 @@ import {
PUSH_WEBHOOK_TOKEN_ENV,
pushWebhookCurlExample,
pushWebhookErrorText,
+ pushWebhookPowerShellExample,
+ type PushWebhookResult,
type PushWebhookError,
type PushWebhookTokenInfo
} from '@shared/push-webhook'
+/**
+ * The last status answer, kept across REMOUNTS. Settings search unmounts and remounts every row it
+ * filters, and each mount used to cost a challenge + status round trip against a per-IP budget
+ * that everyone behind one NAT shares. An answer is reused for STATUS_REUSE_MS; a mint or revoke
+ * replaces it with what that call returned. It never holds the token — only what status reports.
+ */
+const STATUS_REUSE_MS = 5 * 60_000
+let lastStatus: { at: number; result: PushWebhookResult<PushWebhookTokenInfo | null> } | null = null
+
+/** Test seam: forget the cached status. */
+export function resetPushWebhookStatusCache(): void {
+ lastStatus = null
+}
+
+function remember(result: PushWebhookResult<PushWebhookTokenInfo | null>): void {
+ lastStatus = { at: Date.now(), result }
+}
+
function formatWhen(iso: string | null): string {
if (!iso) return 'never'
const t = Date.parse(iso)
@@ -32,18 +52,20 @@ function formatWhen(iso: string | null): string {
*/
export function PushWebhookPanel(): React.JSX.Element {
const api = window.nodeTerminal.pairing
- const [loading, setLoading] = useState(true)
- const [info, setInfo] = useState<PushWebhookTokenInfo | null>(null)
- const [error, setError] = useState<PushWebhookError | null>(null)
+ const cached = lastStatus && Date.now() - lastStatus.at < STATUS_REUSE_MS ? lastStatus.result : null
+ const [loading, setLoading] = useState(cached === null)
+ const [info, setInfo] = useState<PushWebhookTokenInfo | null>(cached?.ok ? cached.value : null)
+ const [error, setError] = useState<PushWebhookError | null>(cached && !cached.ok ? cached.error : null)
const [busy, setBusy] = useState(false)
const [revealed, setRevealed] = useState<string | null>(null)
- const [copied, setCopied] = useState<'token' | 'example' | null>(null)
+ const [copied, setCopied] = useState<'token' | 'sh' | 'powershell' | null>(null)
const [confirm, setConfirm] = useState<'rotate' | 'revoke' | null>(null)
const [endpoint, setEndpoint] = useState<string | undefined>(undefined)
const refresh = useCallback(async (): Promise<void> => {
try {
const r = await api.webhookStatus()
+ remember(r)
if (r.ok) {
setInfo(r.value)
setError(null)
@@ -56,7 +78,9 @@ export function PushWebhookPanel(): React.JSX.Element {
}, [api])
useEffect(() => {
- void refresh()
+ // A remount inside the reuse window shows the remembered answer and asks nothing. The main
+ // process also refuses to call out at all while no phone is paired (core/push-webhook.ts).
+ if (!lastStatus || Date.now() - lastStatus.at >= STATUS_REUSE_MS) void refresh()
api.webhookEndpoint().then(setEndpoint, () => undefined)
}, [api, refresh])
@@ -70,6 +94,7 @@ export function PushWebhookPanel(): React.JSX.Element {
const { token, ...rest } = r.value
setRevealed(token)
setInfo(rest)
+ remember({ ok: true, value: rest })
setError(null)
} else setError(r.error)
} catch {
@@ -87,6 +112,7 @@ export function PushWebhookPanel(): React.JSX.Element {
if (r.ok) {
setInfo(null)
setRevealed(null)
+ remember({ ok: true, value: null })
setError(null)
} else setError(r.error)
} catch {
@@ -96,12 +122,15 @@ export function PushWebhookPanel(): React.JSX.Element {
}
}
- const copy = (text: string, what: 'token' | 'example'): void => {
+ const copy = (text: string, what: 'token' | 'sh' | 'powershell'): void => {
window.nodeTerminal.clipboard.writeText(text)
setCopied(what)
}
- const example = pushWebhookCurlExample(endpoint)
+ const examples = [
+ { id: 'sh' as const, label: 'sh (macOS, Linux, CI)', text: pushWebhookCurlExample(endpoint) },
+ { id: 'powershell' as const, label: 'PowerShell (Windows)', text: pushWebhookPowerShellExample(endpoint) }
+ ]
return (
<div className="space-y-3">
@@ -176,16 +205,22 @@ export function PushWebhookPanel(): React.JSX.Element {
) : null}
{info || revealed ? (
- <div className="space-y-1">
- <div className="flex items-center justify-between gap-2">
- <span className="text-xs text-muted">Example (reads the token from ${PUSH_WEBHOOK_TOKEN_ENV})</span>
- <Button onClick={() => copy(example, 'example')}>
- {copied === 'example' ? 'Copied' : 'Copy example'}
- </Button>
- </div>
- <pre className="overflow-x-auto rounded bg-bg px-2 py-1 font-mono text-[11px] text-text">
- {example}
- </pre>
+ <div className="space-y-2">
+ <p className="text-xs text-muted">
+ Examples read the token from ${PUSH_WEBHOOK_TOKEN_ENV}, so it never appears on a
+ command line.
+ </p>
+ {examples.map((ex) => (
+ <div key={ex.id} className="space-y-1" data-testid={`webhook-example-${ex.id}`}>
+ <div className="flex items-center justify-between gap-2">
+ <span className="text-xs text-muted">{ex.label}</span>
+ <Button onClick={() => copy(ex.text, ex.id)}>{copied === ex.id ? 'Copied' : 'Copy'}</Button>
+ </div>
+ <pre className="overflow-x-auto rounded bg-bg px-2 py-1 font-mono text-[11px] text-text">
+ {ex.text}
+ </pre>
+ </div>
+ ))}
</div>
) : null}
diff --git a/src/shared/push-webhook.test.ts b/src/shared/push-webhook.test.ts
index f19a7ccf9..976389f7f 100644
--- a/src/shared/push-webhook.test.ts
+++ b/src/shared/push-webhook.test.ts
@@ -1,6 +1,12 @@
import { describe, it, expect } from 'vitest'
import { execFileSync } from 'node:child_process'
-import { PUSH_WEBHOOK_TOKEN_ENV, pushWebhookCurlExample, pushWebhookErrorText, type PushWebhookError } from './push-webhook'
+import {
+ PUSH_WEBHOOK_TOKEN_ENV,
+ pushWebhookCurlExample,
+ pushWebhookErrorText,
+ pushWebhookPowerShellExample,
+ type PushWebhookError
+} from './push-webhook'
describe('pushWebhookCurlExample', () => {
it('reads the token from the environment and hands it to curl on stdin, never argv', () => {
@@ -26,6 +32,14 @@ describe('pushWebhookCurlExample', () => {
})
it('every error has a sentence', () => {
- const all: PushWebhookError[] = ['dev-build', 'no-host-key', 'no-paired-phone', 'refused', 'rate-limited', 'unreachable']
+ const all: PushWebhookError[] = ['dev-build', 'no-host-key', 'no-paired-phone', 'refused', 'bad-request', 'rate-limited', 'unreachable']
for (const e of all) expect(pushWebhookErrorText(e).length).toBeGreaterThan(10)
})
+
+it('the PowerShell example makes the request in-process and reads the token from the environment', () => {
+ const ex = pushWebhookPowerShellExample('https://api.test')
+ expect(ex).toContain('Invoke-RestMethod')
+ expect(ex).toContain(`$env:${PUSH_WEBHOOK_TOKEN_ENV}`)
+ expect(ex).not.toMatch(/curl/i)
+ expect(ex).toContain("'https://api.test/v1/push/webhook'")
+})
diff --git a/src/shared/push-webhook.ts b/src/shared/push-webhook.ts
index 3881b8246..57de9afcc 100644
--- a/src/shared/push-webhook.ts
+++ b/src/shared/push-webhook.ts
@@ -32,6 +32,8 @@ export type PushWebhookError =
| 'no-paired-phone'
/** The backend refused the ownership proof. */
| 'refused'
+ /** The backend could not read the request (a 400) — this build and the server disagree. */
+ | 'bad-request'
| 'rate-limited'
/** Network error, timeout, 5xx or an answer we could not read. */
| 'unreachable'
@@ -59,7 +61,9 @@ export function pushWebhookErrorText(error: PushWebhookError): string {
case 'no-paired-phone':
return 'Pair a phone with remote access first — the webhook pushes to the phones paired with this machine.'
case 'refused':
- return 'The server refused this machine’s identity. Try again; if it keeps failing, re-pair your phone.'
+ return 'The server did not accept this machine’s proof of its remote-access key. Try again; if it keeps failing, report it.'
+ case 'bad-request':
+ return 'The server could not read the request — this version of nodeterm and the server disagree. Update nodeterm and try again.'
case 'rate-limited':
return 'Too many requests — wait a minute and try again.'
case 'unreachable':
@@ -73,8 +77,12 @@ export function pushWebhookErrorText(error: PushWebhookError): string {
* through `ps`, and a CI runner is exactly such a machine. `printf` is a shell builtin in sh, bash
* and zsh, so the token is not on its argv either.
*/
+function webhookUrl(apiBase: string): string {
+ return apiBase.replace(/\/+$/, '') + PUSH_WEBHOOK_PATH
+}
+
export function pushWebhookCurlExample(apiBase: string = PUSH_WEBHOOK_DEFAULT_API_BASE): string {
- const url = apiBase.replace(/\/+$/, '') + PUSH_WEBHOOK_PATH
+ const url = webhookUrl(apiBase)
return [
`printf 'header = "Authorization: Bearer %s"\\n' "$${PUSH_WEBHOOK_TOKEN_ENV}" |`,
` curl -fsS --config - -H 'Content-Type: application/json' \\`,
@@ -82,3 +90,18 @@ export function pushWebhookCurlExample(apiBase: string = PUSH_WEBHOOK_DEFAULT_AP
` ${url}`
].join('\n')
}
+
+/**
+ * The PowerShell counterpart (Windows has no `sh`). `Invoke-RestMethod` is a cmdlet, so the request
+ * — header included — is made inside the PowerShell process: no child process, no argv for `ps` to
+ * show. (`curl.exe` from PowerShell would need the header on stdin too, and Windows PowerShell 5.1
+ * mangles the double quotes of a JSON argument to native programs.)
+ */
+export function pushWebhookPowerShellExample(apiBase: string = PUSH_WEBHOOK_DEFAULT_API_BASE): string {
+ return [
+ `Invoke-RestMethod -Method Post -Uri '${webhookUrl(apiBase)}' \``,
+ ` -Headers @{ Authorization = "Bearer $env:${PUSH_WEBHOOK_TOKEN_ENV}" } \``,
+ ` -ContentType 'application/json' \``,
+ ` -Body '{"title":"Build finished","body":"main is green"}'`
+ ].join('\n')
+}