@agent-watch-ai/edge 0.2.5 → 0.4.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/CHANGELOG.md +558 -0
- package/README.md +222 -97
- package/SECURITY.md +72 -0
- package/dist/billing/session-billing.d.ts +19 -0
- package/dist/billing/session-billing.js +52 -0
- package/dist/cli/args.d.ts +10 -0
- package/dist/cli/args.js +20 -0
- package/dist/cli/constants/cli.constants.d.ts +52 -4
- package/dist/cli/constants/cli.constants.js +56 -5
- package/dist/cli/context.d.ts +33 -2
- package/dist/cli/context.js +84 -14
- package/dist/cli/doctor.js +321 -33
- package/dist/cli/hook-check.d.ts +23 -0
- package/dist/cli/hook-check.js +114 -0
- package/dist/cli/hook.js +118 -7
- package/dist/cli/index.d.ts +3 -1
- package/dist/cli/index.js +3 -1
- package/dist/cli/misc.d.ts +11 -0
- package/dist/cli/misc.js +80 -4
- package/dist/cli/npx-install.d.ts +37 -0
- package/dist/cli/npx-install.js +79 -0
- package/dist/cli/open-browser.d.ts +39 -0
- package/dist/cli/open-browser.js +62 -0
- package/dist/cli/setup.d.ts +17 -8
- package/dist/cli/setup.js +553 -103
- package/dist/cli/status.js +82 -13
- package/dist/cli/toggle.d.ts +9 -0
- package/dist/cli/toggle.js +117 -0
- package/dist/cli/types/cli.types.d.ts +43 -3
- package/dist/cli/ui.d.ts +7 -0
- package/dist/cli/ui.js +10 -1
- package/dist/cli/uninstall.js +39 -2
- package/dist/cli/update.d.ts +17 -0
- package/dist/cli/update.js +76 -0
- package/dist/cli.js +110 -12
- package/dist/config/config-store.d.ts +57 -0
- package/dist/config/config-store.js +250 -12
- package/dist/config/config.d.ts +53 -6
- package/dist/config/config.js +66 -6
- package/dist/config/constants/config.constants.d.ts +116 -6
- package/dist/config/constants/config.constants.js +131 -8
- package/dist/config/destination.d.ts +24 -0
- package/dist/config/destination.js +33 -0
- package/dist/config/index.d.ts +7 -4
- package/dist/config/index.js +5 -3
- package/dist/config/repo-config.d.ts +11 -7
- package/dist/config/repo-config.js +64 -15
- package/dist/config/root-config.d.ts +72 -0
- package/dist/config/root-config.js +170 -0
- package/dist/config/schemas/config.schema.d.ts +831 -84
- package/dist/config/schemas/config.schema.js +398 -16
- package/dist/config/types/config.types.d.ts +15 -1
- package/dist/config/types/destination.types.d.ts +8 -0
- package/dist/core/async.d.ts +36 -0
- package/dist/core/async.js +68 -0
- package/dist/core/index.d.ts +1 -1
- package/dist/core/index.js +1 -1
- package/dist/core/object.d.ts +5 -0
- package/dist/core/object.js +9 -4
- package/dist/core/pipe.d.ts +0 -13
- package/dist/core/pipe.js +1 -9
- package/dist/core/types/core.types.d.ts +9 -0
- package/dist/core/types/core.types.js +0 -3
- package/dist/core/which.d.ts +14 -0
- package/dist/core/which.js +43 -3
- package/dist/credentials/budget.d.ts +9 -0
- package/dist/credentials/budget.js +16 -0
- package/dist/credentials/command-runner.d.ts +16 -0
- package/dist/credentials/command-runner.js +37 -0
- package/dist/credentials/constants/credentials.constants.d.ts +119 -0
- package/dist/credentials/constants/credentials.constants.js +120 -0
- package/dist/credentials/credential-status.d.ts +14 -0
- package/dist/credentials/credential-status.js +38 -0
- package/dist/credentials/credentials.d.ts +86 -0
- package/dist/credentials/credentials.js +278 -0
- package/dist/credentials/device-api.d.ts +73 -0
- package/dist/credentials/device-api.js +161 -0
- package/dist/credentials/device-state.d.ts +31 -0
- package/dist/credentials/device-state.js +51 -0
- package/dist/credentials/identity.d.ts +73 -0
- package/dist/credentials/identity.js +101 -0
- package/dist/credentials/index.d.ts +7 -0
- package/dist/credentials/index.js +5 -0
- package/dist/credentials/migration.d.ts +46 -0
- package/dist/credentials/migration.js +164 -0
- package/dist/credentials/schemas/device-api.schema.d.ts +77 -0
- package/dist/credentials/schemas/device-api.schema.js +33 -0
- package/dist/credentials/schemas/device-state.schema.d.ts +51 -0
- package/dist/credentials/schemas/device-state.schema.js +20 -0
- package/dist/credentials/secret-store.d.ts +54 -0
- package/dist/credentials/secret-store.js +217 -0
- package/dist/credentials/sign-in.d.ts +31 -0
- package/dist/credentials/sign-in.js +105 -0
- package/dist/credentials/token-refresher.d.ts +39 -0
- package/dist/credentials/token-refresher.js +185 -0
- package/dist/credentials/types/credentials.types.d.ts +206 -0
- package/dist/credentials/types/credentials.types.js +1 -0
- package/dist/enforcement/constants/enforcement.constants.d.ts +47 -1
- package/dist/enforcement/constants/enforcement.constants.js +56 -0
- package/dist/enforcement/decision-cache.d.ts +20 -1
- package/dist/enforcement/decision-cache.js +65 -2
- package/dist/enforcement/decision-client.d.ts +9 -8
- package/dist/enforcement/decision-client.js +64 -17
- package/dist/enforcement/enforcement.d.ts +23 -2
- package/dist/enforcement/enforcement.js +107 -17
- package/dist/enforcement/index.d.ts +4 -3
- package/dist/enforcement/index.js +3 -2
- package/dist/enforcement/types/enforcement.types.d.ts +66 -2
- package/dist/enrollment/constants/enrollment.constants.d.ts +2 -6
- package/dist/enrollment/constants/enrollment.constants.js +2 -6
- package/dist/enrollment/enrollment.d.ts +16 -0
- package/dist/enrollment/enrollment.js +54 -0
- package/dist/enrollment/index.d.ts +3 -7
- package/dist/enrollment/index.js +1 -1
- package/dist/enrollment/types/enrollment.types.d.ts +9 -13
- package/dist/events/constants/enrich.constants.d.ts +15 -0
- package/dist/events/constants/enrich.constants.js +15 -0
- package/dist/events/constants/events.constants.d.ts +6 -2
- package/dist/events/constants/events.constants.js +5 -1
- package/dist/events/enrich.js +92 -10
- package/dist/events/event-id.d.ts +0 -8
- package/dist/events/event-id.js +0 -10
- package/dist/events/index.d.ts +2 -2
- package/dist/events/index.js +1 -1
- package/dist/events/product-event.d.ts +9 -6
- package/dist/events/types/repo-snapshot.types.d.ts +7 -0
- package/dist/events/types/session-billing.types.d.ts +16 -0
- package/dist/events/types/session-billing.types.js +1 -0
- package/dist/feature/constants/feature.constants.d.ts +7 -0
- package/dist/feature/constants/feature.constants.js +7 -0
- package/dist/feature/index.d.ts +1 -1
- package/dist/feature/index.js +1 -1
- package/dist/feature/ticket-candidates.d.ts +14 -0
- package/dist/feature/ticket-candidates.js +26 -8
- package/dist/git/blob-hash.d.ts +21 -0
- package/dist/git/blob-hash.js +69 -0
- package/dist/git/checkout-root.d.ts +27 -0
- package/dist/git/checkout-root.js +75 -0
- package/dist/git/constants/git.constants.d.ts +160 -0
- package/dist/git/constants/git.constants.js +181 -0
- package/dist/git/fingerprint.d.ts +74 -0
- package/dist/git/fingerprint.js +219 -0
- package/dist/git/gate-checkout.d.ts +44 -0
- package/dist/git/gate-checkout.js +201 -0
- package/dist/git/git-context.d.ts +45 -0
- package/dist/git/git-context.js +61 -3
- package/dist/git/index.d.ts +4 -2
- package/dist/git/index.js +2 -1
- package/dist/git/manifest-repository.d.ts +13 -0
- package/dist/git/manifest-repository.js +92 -0
- package/dist/git/repo-snapshot.d.ts +29 -3
- package/dist/git/repo-snapshot.js +110 -7
- package/dist/git/repository-root.d.ts +39 -0
- package/dist/git/repository-root.js +131 -0
- package/dist/git/types/git.types.d.ts +55 -0
- package/dist/git/types/repository-root.types.d.ts +11 -0
- package/dist/git/types/repository-root.types.js +1 -0
- package/dist/git/types/snapshot.types.d.ts +9 -0
- package/dist/pipeline/constants/pipeline.constants.d.ts +10 -0
- package/dist/pipeline/constants/pipeline.constants.js +10 -0
- package/dist/pipeline/hook-pipeline.js +410 -33
- package/dist/pipeline/types/pipeline.types.d.ts +39 -4
- package/dist/privacy/constants/privacy.constants.js +15 -1
- package/dist/privacy/index.d.ts +1 -0
- package/dist/privacy/index.js +1 -0
- package/dist/privacy/product-capture.d.ts +12 -0
- package/dist/privacy/product-capture.js +75 -0
- package/dist/privacy/sanitizer.d.ts +21 -3
- package/dist/privacy/sanitizer.js +52 -8
- package/dist/process/ancestors.d.ts +39 -0
- package/dist/process/ancestors.js +121 -0
- package/dist/process/constants/process.constants.d.ts +34 -0
- package/dist/process/constants/process.constants.js +34 -0
- package/dist/process/index.d.ts +7 -0
- package/dist/process/index.js +2 -0
- package/dist/process/types/process.types.d.ts +23 -0
- package/dist/process/types/process.types.js +1 -0
- package/dist/providers/antigravity/antigravity.adapter.d.ts +12 -1
- package/dist/providers/antigravity/antigravity.adapter.js +21 -3
- package/dist/providers/antigravity/antigravity.detect.d.ts +0 -9
- package/dist/providers/antigravity/antigravity.detect.js +1 -1
- package/dist/providers/antigravity/antigravity.provider.js +3 -2
- package/dist/providers/antigravity/constants/antigravity.constants.d.ts +2 -0
- package/dist/providers/antigravity/constants/antigravity.constants.js +2 -0
- package/dist/providers/claude/claude.adapter.d.ts +11 -1
- package/dist/providers/claude/claude.adapter.js +26 -5
- package/dist/providers/claude/claude.otel.d.ts +32 -18
- package/dist/providers/claude/claude.otel.js +81 -6
- package/dist/providers/claude/claude.provider.js +5 -2
- package/dist/providers/claude/constants/claude.constants.d.ts +2 -0
- package/dist/providers/claude/constants/claude.constants.js +2 -0
- package/dist/providers/claude/constants/claude.otel.constants.d.ts +4 -0
- package/dist/providers/claude/constants/claude.otel.constants.js +8 -0
- package/dist/providers/codex/codex.adapter.d.ts +15 -1
- package/dist/providers/codex/codex.adapter.js +29 -5
- package/dist/providers/codex/codex.otel.d.ts +36 -3
- package/dist/providers/codex/codex.otel.js +199 -32
- package/dist/providers/codex/codex.provider.js +5 -2
- package/dist/providers/codex/constants/codex.constants.d.ts +2 -0
- package/dist/providers/codex/constants/codex.constants.js +16 -0
- package/dist/providers/codex/constants/codex.otel.constants.d.ts +10 -0
- package/dist/providers/codex/constants/codex.otel.constants.js +10 -0
- package/dist/providers/constants/provider.constants.d.ts +8 -3
- package/dist/providers/constants/provider.constants.js +8 -3
- package/dist/providers/cursor/constants/cursor.constants.d.ts +9 -0
- package/dist/providers/cursor/constants/cursor.constants.js +9 -0
- package/dist/providers/cursor/cursor.adapter.d.ts +33 -1
- package/dist/providers/cursor/cursor.adapter.js +129 -4
- package/dist/providers/cursor/cursor.detect.d.ts +0 -7
- package/dist/providers/cursor/cursor.detect.js +1 -1
- package/dist/providers/cursor/cursor.provider.js +5 -2
- package/dist/providers/gemini/constants/gemini.constants.d.ts +9 -0
- package/dist/providers/gemini/constants/gemini.constants.js +9 -0
- package/dist/providers/gemini/constants/gemini.otel.constants.d.ts +9 -1
- package/dist/providers/gemini/constants/gemini.otel.constants.js +9 -0
- package/dist/providers/gemini/gemini.adapter.d.ts +14 -1
- package/dist/providers/gemini/gemini.adapter.js +25 -5
- package/dist/providers/gemini/gemini.detect.d.ts +0 -7
- package/dist/providers/gemini/gemini.detect.js +1 -1
- package/dist/providers/gemini/gemini.otel.d.ts +30 -21
- package/dist/providers/gemini/gemini.otel.js +166 -22
- package/dist/providers/gemini/gemini.provider.js +2 -1
- package/dist/providers/index.d.ts +1 -1
- package/dist/providers/index.js +1 -1
- package/dist/providers/loaders.d.ts +10 -0
- package/dist/providers/loaders.js +40 -0
- package/dist/providers/provider.d.ts +11 -0
- package/dist/providers/provider.js +1 -1
- package/dist/providers/registry.d.ts +11 -8
- package/dist/providers/registry.js +11 -15
- package/dist/providers/shared/bearer-rewrite.d.ts +19 -0
- package/dist/providers/shared/bearer-rewrite.js +46 -0
- package/dist/providers/shared/constants/hook-refusal.constants.d.ts +7 -0
- package/dist/providers/shared/constants/hook-refusal.constants.js +7 -0
- package/dist/providers/shared/constants/shell-directories.constants.d.ts +30 -0
- package/dist/providers/shared/constants/shell-directories.constants.js +39 -0
- package/dist/providers/shared/constants/tooling.constants.d.ts +24 -2
- package/dist/providers/shared/constants/tooling.constants.js +25 -3
- package/dist/providers/shared/event-builder.d.ts +12 -14
- package/dist/providers/shared/event-builder.js +20 -14
- package/dist/providers/shared/exporter-allowlist.d.ts +20 -0
- package/dist/providers/shared/exporter-allowlist.js +49 -0
- package/dist/providers/shared/hook-config.d.ts +2 -21
- package/dist/providers/shared/hook-config.js +5 -4
- package/dist/providers/shared/hook-refusal.d.ts +12 -0
- package/dist/providers/shared/hook-refusal.js +17 -1
- package/dist/providers/shared/install-record.d.ts +12 -2
- package/dist/providers/shared/install-record.js +5 -2
- package/dist/providers/shared/shell-directories.d.ts +24 -0
- package/dist/providers/shared/shell-directories.js +90 -0
- package/dist/providers/shared/tooling.d.ts +40 -1
- package/dist/providers/shared/tooling.js +70 -1
- package/dist/providers/shared/types/adapter.types.d.ts +1 -2
- package/dist/providers/types/provider.types.d.ts +81 -1
- package/dist/snapshot/constants/snapshot.constants.d.ts +32 -0
- package/dist/snapshot/constants/snapshot.constants.js +33 -0
- package/dist/snapshot/snapshot-event.js +52 -11
- package/dist/snapshot/snapshot-pipeline.js +1 -1
- package/dist/snapshot/types/snapshot.types.d.ts +2 -0
- package/dist/storage/atomic-file.d.ts +21 -0
- package/dist/storage/atomic-file.js +20 -1
- package/dist/storage/constants/storage.constants.d.ts +19 -0
- package/dist/storage/constants/storage.constants.js +19 -0
- package/dist/storage/disabled.d.ts +13 -0
- package/dist/storage/disabled.js +24 -0
- package/dist/storage/index.d.ts +2 -0
- package/dist/storage/index.js +2 -0
- package/dist/storage/paths.js +3 -2
- package/dist/storage/schemas/storage.schema.d.ts +72 -0
- package/dist/storage/schemas/storage.schema.js +6 -0
- package/dist/storage/sweep-marker.d.ts +19 -0
- package/dist/storage/sweep-marker.js +55 -0
- package/dist/storage/types/storage.types.d.ts +2 -0
- package/dist/storage/uninstalled.d.ts +58 -0
- package/dist/storage/uninstalled.js +107 -0
- package/dist/transport/auth-block.d.ts +66 -0
- package/dist/transport/auth-block.js +129 -0
- package/dist/transport/constants/transport.constants.d.ts +82 -3
- package/dist/transport/constants/transport.constants.js +83 -4
- package/dist/transport/cooldown.js +8 -1
- package/dist/transport/delivery.d.ts +14 -6
- package/dist/transport/delivery.js +80 -55
- package/dist/transport/http-transport.d.ts +1 -0
- package/dist/transport/http-transport.js +52 -10
- package/dist/transport/index.d.ts +6 -3
- package/dist/transport/index.js +3 -0
- package/dist/transport/queue-partition.d.ts +91 -0
- package/dist/transport/queue-partition.js +143 -0
- package/dist/transport/queue.d.ts +99 -20
- package/dist/transport/queue.js +210 -69
- package/dist/transport/response-body.d.ts +25 -0
- package/dist/transport/response-body.js +64 -0
- package/dist/transport/send.d.ts +11 -0
- package/dist/transport/send.js +17 -0
- package/dist/transport/types/delivery-flow.types.d.ts +19 -0
- package/dist/transport/types/delivery-flow.types.js +1 -0
- package/dist/transport/types/transport.types.d.ts +45 -0
- package/dist/turns/claude-transcript.d.ts +19 -1
- package/dist/turns/claude-transcript.js +46 -1
- package/dist/turns/codex-originator.d.ts +11 -0
- package/dist/turns/codex-originator.js +31 -0
- package/dist/turns/codex-transcript.d.ts +30 -0
- package/dist/turns/codex-transcript.js +88 -0
- package/dist/turns/constants/turns.constants.d.ts +141 -5
- package/dist/turns/constants/turns.constants.js +155 -5
- package/dist/turns/file-identity.d.ts +27 -0
- package/dist/turns/file-identity.js +48 -0
- package/dist/turns/gemini-transcript.d.ts +30 -0
- package/dist/turns/gemini-transcript.js +96 -0
- package/dist/turns/index.d.ts +3 -3
- package/dist/turns/index.js +1 -1
- package/dist/turns/inherited-checkout.d.ts +54 -0
- package/dist/turns/inherited-checkout.js +155 -0
- package/dist/turns/native-session-titles.d.ts +26 -0
- package/dist/turns/native-session-titles.js +102 -0
- package/dist/turns/transcript.d.ts +3 -2
- package/dist/turns/transcript.js +5 -1
- package/dist/turns/turn-state.d.ts +224 -3
- package/dist/turns/turn-state.js +456 -21
- package/dist/turns/turn-summary.d.ts +1 -14
- package/dist/turns/turn-summary.js +87 -51
- package/dist/turns/turn-tracker.d.ts +21 -2
- package/dist/turns/turn-tracker.js +379 -56
- package/dist/turns/types/transcript.types.d.ts +5 -0
- package/dist/turns/types/turn-state.types.d.ts +116 -5
- package/dist/turns/types/turn-summary.types.d.ts +64 -14
- package/dist/turns/types/turn-tracker.types.d.ts +27 -1
- package/dist/turns/work-checkout.d.ts +67 -0
- package/dist/turns/work-checkout.js +700 -0
- package/dist/untraced/constants/untraced.constants.d.ts +31 -0
- package/dist/untraced/constants/untraced.constants.js +63 -0
- package/dist/untraced/untraced.d.ts +35 -0
- package/dist/untraced/untraced.js +105 -0
- package/dist/update/constants/update.constants.d.ts +18 -0
- package/dist/update/constants/update.constants.js +20 -0
- package/dist/update/update-check.d.ts +52 -0
- package/dist/update/update-check.js +113 -0
- package/docs/AUDIT_PROMPT.md +129 -0
- package/docs/DATA_HANDLING.md +655 -0
- package/docs/ENTERPRISE_DEPLOYMENT.md +194 -0
- package/docs/PERFORMANCE.md +81 -0
- package/package.json +14 -4
- package/dist/enrollment/enrollment-provider.d.ts +0 -5
- package/dist/enrollment/manual-enrollment.d.ts +0 -32
- package/dist/enrollment/manual-enrollment.js +0 -72
- package/example/README.md +0 -43
- package/example/server.mjs +0 -240
- /package/dist/{enrollment/enrollment-provider.js → config/types/destination.types.js} +0 -0
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { readJsonFile } from '../storage/json-file.js';
|
|
2
|
+
import { writeFileAtomic } from '../storage/atomic-file.js';
|
|
3
|
+
import { SECRET_FILE_MODE } from '../storage/constants/storage.constants.js';
|
|
4
|
+
import { accessTokenCacheSchema, deviceStateSchema } from './schemas/device-state.schema.js';
|
|
5
|
+
/**
|
|
6
|
+
* The cached access token, when there is a readable one.
|
|
7
|
+
*
|
|
8
|
+
* @param file - The identity's access token file.
|
|
9
|
+
* @returns The cache entry, or undefined.
|
|
10
|
+
*/
|
|
11
|
+
export async function readAccessToken(file) {
|
|
12
|
+
const read = await readJsonFile(file);
|
|
13
|
+
const parsed = read.state === 'ok' ? accessTokenCacheSchema.safeParse(read.value) : undefined;
|
|
14
|
+
return parsed?.success ? parsed.data : undefined;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Keep the access token for every process on this machine. 0600: it is a
|
|
18
|
+
* bearer for up to an hour (R8 allows that on disk; the device secret never is).
|
|
19
|
+
*
|
|
20
|
+
* @param file - The identity's access token file.
|
|
21
|
+
* @param cache - The entry.
|
|
22
|
+
*/
|
|
23
|
+
export async function writeAccessToken(file, cache) {
|
|
24
|
+
await writeFileAtomic(file, JSON.stringify(cache), SECRET_FILE_MODE);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* What this identity remembers about its device credential.
|
|
28
|
+
*
|
|
29
|
+
* @param file - The identity's device state file.
|
|
30
|
+
* @returns The state; empty when there is none.
|
|
31
|
+
*/
|
|
32
|
+
export async function readDeviceState(file) {
|
|
33
|
+
const read = await readJsonFile(file);
|
|
34
|
+
const parsed = read.state === 'ok' ? deviceStateSchema.safeParse(read.value) : undefined;
|
|
35
|
+
return parsed?.success ? parsed.data : {};
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Persist the device state. Never throws: it runs on the hook path, and a
|
|
39
|
+
* diagnosis that cannot be written must not fail the agent's turn.
|
|
40
|
+
*
|
|
41
|
+
* @param file - The identity's device state file.
|
|
42
|
+
* @param state - The state.
|
|
43
|
+
*/
|
|
44
|
+
export async function writeDeviceState(file, state) {
|
|
45
|
+
try {
|
|
46
|
+
await writeFileAtomic(file, JSON.stringify(state), SECRET_FILE_MODE);
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
// See above.
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { CredentialFields, DeviceCredentialRef } from './types/credentials.types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Who a config sends as, for naming its queue partition and state files.
|
|
4
|
+
*
|
|
5
|
+
* An install key wins while there is one: a fresh `setup --token` on a migrated
|
|
6
|
+
* machine is a new identity until it too is exchanged. Never a bearer to send —
|
|
7
|
+
* see `resolveBearer` for that.
|
|
8
|
+
*
|
|
9
|
+
* @param config - The credential fields of an effective config.
|
|
10
|
+
* @returns The install key, `device:<id>`, or undefined when there is neither.
|
|
11
|
+
*/
|
|
12
|
+
export declare function identityOf(config: CredentialFields): string | undefined;
|
|
13
|
+
/**
|
|
14
|
+
* Whether a config holds any credential at all.
|
|
15
|
+
*
|
|
16
|
+
* @param config - The credential fields of an effective config.
|
|
17
|
+
* @returns True for an install key or a device credential.
|
|
18
|
+
*/
|
|
19
|
+
export declare function hasCredential(config: CredentialFields): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Whether this is an MDM install still waiting for its developer's sign-in:
|
|
22
|
+
* configured for an organization, holding no credential. It sends and queues
|
|
23
|
+
* nothing, and never adopts an identity of its own (SPEC section 5).
|
|
24
|
+
*
|
|
25
|
+
* @param config - The credential fields of an effective config, with its organization.
|
|
26
|
+
* @returns True until the developer runs `agentwatch setup`.
|
|
27
|
+
*/
|
|
28
|
+
export declare function awaitingSignIn(config: CredentialFields & {
|
|
29
|
+
readonly organizationId?: string;
|
|
30
|
+
}): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* The device id an install key's credential is filed under.
|
|
33
|
+
*
|
|
34
|
+
* The same digest that already names the key's partition, so nothing moves
|
|
35
|
+
* when the key is exchanged.
|
|
36
|
+
*
|
|
37
|
+
* @param installKey - The install key being exchanged.
|
|
38
|
+
* @returns Twelve hex characters.
|
|
39
|
+
*/
|
|
40
|
+
export declare function credentialId(installKey: string): string;
|
|
41
|
+
/**
|
|
42
|
+
* The digest naming an identity on disk; never the identity itself, which may
|
|
43
|
+
* be a bearer.
|
|
44
|
+
*
|
|
45
|
+
* @param identity - What `identityOf` returned.
|
|
46
|
+
* @returns The fingerprint.
|
|
47
|
+
*/
|
|
48
|
+
export declare function identityFingerprint(identity: string): string;
|
|
49
|
+
/**
|
|
50
|
+
* The device credential that stands for this config's identity, if any.
|
|
51
|
+
*
|
|
52
|
+
* The install key stays beside its device in the config through the migration
|
|
53
|
+
* window, to enroll again when the secret expires. A device whose
|
|
54
|
+
* id is not that key's is a leftover from an earlier key and stands for
|
|
55
|
+
* nothing.
|
|
56
|
+
*
|
|
57
|
+
* @param config - The credential fields of an effective config.
|
|
58
|
+
* @returns The device, or undefined when the config sends as an install key or has nothing.
|
|
59
|
+
*/
|
|
60
|
+
export declare function deviceFor(config: CredentialFields): DeviceCredentialRef | undefined;
|
|
61
|
+
/**
|
|
62
|
+
* Every device reference a config file holds: the machine entry's and each
|
|
63
|
+
* root's, in that order, repeats included.
|
|
64
|
+
*
|
|
65
|
+
* The one place that walks the file for devices, so "is this id still used"
|
|
66
|
+
* has one answer for the exchange, setup and uninstall.
|
|
67
|
+
*
|
|
68
|
+
* @param config - The machine's global config, roots included.
|
|
69
|
+
* @returns The references.
|
|
70
|
+
*/
|
|
71
|
+
export declare function deviceRefs(config: CredentialFields & {
|
|
72
|
+
readonly roots?: Readonly<Record<string, CredentialFields>>;
|
|
73
|
+
}): readonly DeviceCredentialRef[];
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { sha256Hex } from '../events/event-id.js';
|
|
2
|
+
import { IDENTITY_FINGERPRINT_CHARS } from '../transport/constants/transport.constants.js';
|
|
3
|
+
import { DEVICE_IDENTITY_PREFIX } from './constants/credentials.constants.js';
|
|
4
|
+
/**
|
|
5
|
+
* Who a config sends as, for naming its queue partition and state files.
|
|
6
|
+
*
|
|
7
|
+
* An install key wins while there is one: a fresh `setup --token` on a migrated
|
|
8
|
+
* machine is a new identity until it too is exchanged. Never a bearer to send —
|
|
9
|
+
* see `resolveBearer` for that.
|
|
10
|
+
*
|
|
11
|
+
* @param config - The credential fields of an effective config.
|
|
12
|
+
* @returns The install key, `device:<id>`, or undefined when there is neither.
|
|
13
|
+
*/
|
|
14
|
+
export function identityOf(config) {
|
|
15
|
+
if (config.token)
|
|
16
|
+
return config.token;
|
|
17
|
+
return config.device ? DEVICE_IDENTITY_PREFIX + config.device.id : undefined;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Whether a config holds any credential at all.
|
|
21
|
+
*
|
|
22
|
+
* @param config - The credential fields of an effective config.
|
|
23
|
+
* @returns True for an install key or a device credential.
|
|
24
|
+
*/
|
|
25
|
+
export function hasCredential(config) {
|
|
26
|
+
return identityOf(config) !== undefined;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Whether this is an MDM install still waiting for its developer's sign-in:
|
|
30
|
+
* configured for an organization, holding no credential. It sends and queues
|
|
31
|
+
* nothing, and never adopts an identity of its own (SPEC section 5).
|
|
32
|
+
*
|
|
33
|
+
* @param config - The credential fields of an effective config, with its organization.
|
|
34
|
+
* @returns True until the developer runs `agentwatch setup`.
|
|
35
|
+
*/
|
|
36
|
+
export function awaitingSignIn(config) {
|
|
37
|
+
return config.organizationId !== undefined && !hasCredential(config);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* The device id an install key's credential is filed under.
|
|
41
|
+
*
|
|
42
|
+
* The same digest that already names the key's partition, so nothing moves
|
|
43
|
+
* when the key is exchanged.
|
|
44
|
+
*
|
|
45
|
+
* @param installKey - The install key being exchanged.
|
|
46
|
+
* @returns Twelve hex characters.
|
|
47
|
+
*/
|
|
48
|
+
export function credentialId(installKey) {
|
|
49
|
+
return sha256Hex(installKey).slice(0, IDENTITY_FINGERPRINT_CHARS);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* The digest naming an identity on disk; never the identity itself, which may
|
|
53
|
+
* be a bearer.
|
|
54
|
+
*
|
|
55
|
+
* @param identity - What `identityOf` returned.
|
|
56
|
+
* @returns The fingerprint.
|
|
57
|
+
*/
|
|
58
|
+
export function identityFingerprint(identity) {
|
|
59
|
+
if (identity.startsWith(DEVICE_IDENTITY_PREFIX))
|
|
60
|
+
return identity.slice(DEVICE_IDENTITY_PREFIX.length);
|
|
61
|
+
return credentialId(identity);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* The device credential that stands for this config's identity, if any.
|
|
65
|
+
*
|
|
66
|
+
* The install key stays beside its device in the config through the migration
|
|
67
|
+
* window, to enroll again when the secret expires. A device whose
|
|
68
|
+
* id is not that key's is a leftover from an earlier key and stands for
|
|
69
|
+
* nothing.
|
|
70
|
+
*
|
|
71
|
+
* @param config - The credential fields of an effective config.
|
|
72
|
+
* @returns The device, or undefined when the config sends as an install key or has nothing.
|
|
73
|
+
*/
|
|
74
|
+
export function deviceFor(config) {
|
|
75
|
+
const device = config.device;
|
|
76
|
+
if (!device)
|
|
77
|
+
return undefined;
|
|
78
|
+
if (config.token && device.id !== credentialId(config.token))
|
|
79
|
+
return undefined;
|
|
80
|
+
return device;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Every device reference a config file holds: the machine entry's and each
|
|
84
|
+
* root's, in that order, repeats included.
|
|
85
|
+
*
|
|
86
|
+
* The one place that walks the file for devices, so "is this id still used"
|
|
87
|
+
* has one answer for the exchange, setup and uninstall.
|
|
88
|
+
*
|
|
89
|
+
* @param config - The machine's global config, roots included.
|
|
90
|
+
* @returns The references.
|
|
91
|
+
*/
|
|
92
|
+
export function deviceRefs(config) {
|
|
93
|
+
const found = [];
|
|
94
|
+
if (config.device)
|
|
95
|
+
found.push(config.device);
|
|
96
|
+
for (const root of Object.values(config.roots ?? {})) {
|
|
97
|
+
if (root.device)
|
|
98
|
+
found.push(root.device);
|
|
99
|
+
}
|
|
100
|
+
return found;
|
|
101
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** Per-device credentials: the keychain store, the token refresher and the install-key exchange (AWT-356). */
|
|
2
|
+
export type { CredentialContext, CredentialStoreKind, DeviceCredentialRef, DeviceRevocation, SecretStore } from './types/credentials.types.js';
|
|
3
|
+
export { cachedBearer, forgetDeviceCredentials, forgetDeviceIfUnused, resolveBearer } from './credentials.js';
|
|
4
|
+
export { credentialId, deviceFor, deviceRefs, hasCredential, identityOf } from './identity.js';
|
|
5
|
+
export { migrateInstallKey } from './migration.js';
|
|
6
|
+
export { preferredStore, saveSecret, secretStoreFor, storeLabel } from './secret-store.js';
|
|
7
|
+
export { cachedAccessToken, currentAccessToken, needsRefresh } from './token-refresher.js';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { cachedBearer, forgetDeviceCredentials, forgetDeviceIfUnused, resolveBearer } from './credentials.js';
|
|
2
|
+
export { credentialId, deviceFor, deviceRefs, hasCredential, identityOf } from './identity.js';
|
|
3
|
+
export { migrateInstallKey } from './migration.js';
|
|
4
|
+
export { preferredStore, saveSecret, secretStoreFor, storeLabel } from './secret-store.js';
|
|
5
|
+
export { cachedAccessToken, currentAccessToken, needsRefresh } from './token-refresher.js';
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { AgentWatchConfig } from '../config/types/config.types.js';
|
|
2
|
+
import type { CredentialContext, DeviceCredentialRef } from './types/credentials.types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Exchange the install key this config holds for a device credential, once.
|
|
5
|
+
*
|
|
6
|
+
* MIGRATION WINDOW ONLY (plan D4): the gateway route goes away when AWT-275's
|
|
7
|
+
* sign-in ships. Any install key the edge holds takes this path on its next
|
|
8
|
+
* run — written by an older setup, by `setup --token` or from
|
|
9
|
+
* `$AGENTWATCH_TOKEN`. Order matters: the secret is stored and the first token
|
|
10
|
+
* cached before the config names the device, so a crash in between costs one
|
|
11
|
+
* more exchange, never the credential. The install key stays in the config
|
|
12
|
+
* beside the device, to enroll again when the secret expires. A failure
|
|
13
|
+
* keeps the key in use, and the next try waits an hour.
|
|
14
|
+
*
|
|
15
|
+
* A device the gateway refused counts as no device: an expired secret is
|
|
16
|
+
* enrolled again by any run, a revoked or unknown one only when setup asks
|
|
17
|
+
* (`ignoreBackoff`), so a hook never undoes an admin's revocation.
|
|
18
|
+
*
|
|
19
|
+
* Never for a scope `uninstall` marked, until setup runs for it again: the key
|
|
20
|
+
* stays in the config for a reinstall, not for re-enrolling a device just
|
|
21
|
+
* revoked. Asked before the lock, under it, and once more before the device is
|
|
22
|
+
* attached; a device enrolled while uninstall marked the scope is revoked and
|
|
23
|
+
* forgotten here, since uninstall can no longer see it.
|
|
24
|
+
*
|
|
25
|
+
* Never on a Windows hook: storing the secret starts PowerShell, which does not
|
|
26
|
+
* fit a hook's budget. Setup makes the exchange there.
|
|
27
|
+
*
|
|
28
|
+
* @param ctx - Paths, clock, timeout, fetch and keychain runner.
|
|
29
|
+
* @param config - Effective config whose `token` is the install key.
|
|
30
|
+
* @param options - `ignoreBackoff` for setup, where someone asked for it now.
|
|
31
|
+
* @param options.ignoreBackoff - Try even within an hour of a failed attempt.
|
|
32
|
+
* @returns The device credential now standing for the key, or undefined.
|
|
33
|
+
*/
|
|
34
|
+
export declare function migrateInstallKey(ctx: CredentialContext, config: AgentWatchConfig, options?: {
|
|
35
|
+
readonly ignoreBackoff?: boolean;
|
|
36
|
+
}): Promise<DeviceCredentialRef | undefined>;
|
|
37
|
+
/**
|
|
38
|
+
* Undo an exchange uninstall overtook: revoke the device on the platform and
|
|
39
|
+
* forget it here, best effort. Its secret is in hand, so no keychain read.
|
|
40
|
+
*
|
|
41
|
+
* @param ctx - Paths, environment, timeout, fetch and keychain runner.
|
|
42
|
+
* @param device - The device just enrolled, with its endpoint.
|
|
43
|
+
* @param secret - Its secret.
|
|
44
|
+
* @param tokenFile - Its cached access token.
|
|
45
|
+
*/
|
|
46
|
+
export declare function abandonDevice(ctx: CredentialContext, device: DeviceCredentialRef, secret: string, tokenFile: string): Promise<void>;
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import os from 'node:os';
|
|
3
|
+
import { attachDevice, loadConfig } from '../config/config-store.js';
|
|
4
|
+
import { CONFIG_LOCK_HOOK_WAIT_MS, CONFIG_LOCK_WAIT_MS } from '../config/constants/config.constants.js';
|
|
5
|
+
import { debugLog, warnLog } from '../core/logger.js';
|
|
6
|
+
import { acquireLock } from '../storage/lock.js';
|
|
7
|
+
import { isUninstalled } from '../storage/uninstalled.js';
|
|
8
|
+
import { BackendAuthBlock } from '../transport/auth-block.js';
|
|
9
|
+
import { identityPaths } from '../transport/queue-partition.js';
|
|
10
|
+
import { ENROLL_LOCK_PREFIX, ENROLL_RETRY_MS, REFUSAL_SECRET_EXPIRED } from './constants/credentials.constants.js';
|
|
11
|
+
import { enrollDevice, revokeDevice } from './device-api.js';
|
|
12
|
+
import { readDeviceState, writeAccessToken, writeDeviceState } from './device-state.js';
|
|
13
|
+
import { withinBudget } from './budget.js';
|
|
14
|
+
import { credentialId, deviceRefs } from './identity.js';
|
|
15
|
+
import { saveSecret, secretStoreFor } from './secret-store.js';
|
|
16
|
+
/**
|
|
17
|
+
* Exchange the install key this config holds for a device credential, once.
|
|
18
|
+
*
|
|
19
|
+
* MIGRATION WINDOW ONLY (plan D4): the gateway route goes away when AWT-275's
|
|
20
|
+
* sign-in ships. Any install key the edge holds takes this path on its next
|
|
21
|
+
* run — written by an older setup, by `setup --token` or from
|
|
22
|
+
* `$AGENTWATCH_TOKEN`. Order matters: the secret is stored and the first token
|
|
23
|
+
* cached before the config names the device, so a crash in between costs one
|
|
24
|
+
* more exchange, never the credential. The install key stays in the config
|
|
25
|
+
* beside the device, to enroll again when the secret expires. A failure
|
|
26
|
+
* keeps the key in use, and the next try waits an hour.
|
|
27
|
+
*
|
|
28
|
+
* A device the gateway refused counts as no device: an expired secret is
|
|
29
|
+
* enrolled again by any run, a revoked or unknown one only when setup asks
|
|
30
|
+
* (`ignoreBackoff`), so a hook never undoes an admin's revocation.
|
|
31
|
+
*
|
|
32
|
+
* Never for a scope `uninstall` marked, until setup runs for it again: the key
|
|
33
|
+
* stays in the config for a reinstall, not for re-enrolling a device just
|
|
34
|
+
* revoked. Asked before the lock, under it, and once more before the device is
|
|
35
|
+
* attached; a device enrolled while uninstall marked the scope is revoked and
|
|
36
|
+
* forgotten here, since uninstall can no longer see it.
|
|
37
|
+
*
|
|
38
|
+
* Never on a Windows hook: storing the secret starts PowerShell, which does not
|
|
39
|
+
* fit a hook's budget. Setup makes the exchange there.
|
|
40
|
+
*
|
|
41
|
+
* @param ctx - Paths, clock, timeout, fetch and keychain runner.
|
|
42
|
+
* @param config - Effective config whose `token` is the install key.
|
|
43
|
+
* @param options - `ignoreBackoff` for setup, where someone asked for it now.
|
|
44
|
+
* @param options.ignoreBackoff - Try even within an hour of a failed attempt.
|
|
45
|
+
* @returns The device credential now standing for the key, or undefined.
|
|
46
|
+
*/
|
|
47
|
+
export async function migrateInstallKey(ctx, config, options = {}) {
|
|
48
|
+
const installKey = config.token;
|
|
49
|
+
if (!installKey || !config.endpoint)
|
|
50
|
+
return undefined;
|
|
51
|
+
if (ctx.hookPath && ctx.env.platform === 'win32')
|
|
52
|
+
return undefined;
|
|
53
|
+
// After `uninstall` the key left in the config is not an invitation to
|
|
54
|
+
// enroll: only setup, which lifts the marker first, may.
|
|
55
|
+
if (await isUninstalled(ctx.paths, ctx.scope))
|
|
56
|
+
return undefined;
|
|
57
|
+
const id = credentialId(installKey);
|
|
58
|
+
const files = identityPaths(ctx.paths, installKey);
|
|
59
|
+
// Cheap checks first, so a backed-off key costs a hook no lock; both are
|
|
60
|
+
// asked again under the lock, where the answer can no longer change.
|
|
61
|
+
const settled = await settledExchange(ctx, id, files.deviceStateFile, options);
|
|
62
|
+
if (settled.done)
|
|
63
|
+
return settled.device;
|
|
64
|
+
const release = await acquireLock(ctx.paths.locksDir, ENROLL_LOCK_PREFIX + id, ctx.env.now).catch(() => undefined);
|
|
65
|
+
if (!release)
|
|
66
|
+
return undefined;
|
|
67
|
+
try {
|
|
68
|
+
const recheck = await settledExchange(ctx, id, files.deviceStateFile, options);
|
|
69
|
+
if (recheck.done)
|
|
70
|
+
return recheck.device;
|
|
71
|
+
if (await isUninstalled(ctx.paths, ctx.scope))
|
|
72
|
+
return undefined;
|
|
73
|
+
const now = ctx.env.now();
|
|
74
|
+
const budget = withinBudget(ctx);
|
|
75
|
+
if (!budget)
|
|
76
|
+
return undefined;
|
|
77
|
+
await writeDeviceState(files.deviceStateFile, { ...recheck.state, enrollAttemptAt: now.toISOString() });
|
|
78
|
+
const result = await enrollDevice({
|
|
79
|
+
endpoint: config.endpoint,
|
|
80
|
+
installKey,
|
|
81
|
+
developerId: config.developerEmail ?? config.installationId ?? os.hostname(),
|
|
82
|
+
name: os.hostname(),
|
|
83
|
+
timeoutMs: budget.timeoutMs,
|
|
84
|
+
fetchFn: ctx.fetchFn
|
|
85
|
+
});
|
|
86
|
+
if (!result.ok) {
|
|
87
|
+
debugLog(`device enrollment failed: ${result.refusal ?? result.status ?? 'network'}`);
|
|
88
|
+
return undefined;
|
|
89
|
+
}
|
|
90
|
+
const device = { id, store: await saveSecret(ctx, id, result.value.deviceSecret), endpoint: config.endpoint };
|
|
91
|
+
await writeAccessToken(files.accessTokenFile, { accessToken: result.value.accessToken, obtainedAt: now.toISOString(), expiresAt: result.value.accessTokenExpiresAt });
|
|
92
|
+
if (await isUninstalled(ctx.paths, ctx.scope)) {
|
|
93
|
+
await abandonDevice(ctx, device, result.value.deviceSecret, files.accessTokenFile);
|
|
94
|
+
return undefined;
|
|
95
|
+
}
|
|
96
|
+
const attached = await attachDevice(ctx.paths, installKey, device, ctx.hookPath ? CONFIG_LOCK_HOOK_WAIT_MS : CONFIG_LOCK_WAIT_MS);
|
|
97
|
+
// Unnamed in the config (the lock was busy), the device is invisible to the
|
|
98
|
+
// next run: keep the backoff, or every hook would enroll yet another one.
|
|
99
|
+
await writeDeviceState(files.deviceStateFile, (await namesDevice(ctx, attached, device)) ? {} : { enrollAttemptAt: now.toISOString() });
|
|
100
|
+
await new BackendAuthBlock(files.authBlockFile, ctx.env.now).clear();
|
|
101
|
+
return device;
|
|
102
|
+
}
|
|
103
|
+
finally {
|
|
104
|
+
await release();
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Undo an exchange uninstall overtook: revoke the device on the platform and
|
|
109
|
+
* forget it here, best effort. Its secret is in hand, so no keychain read.
|
|
110
|
+
*
|
|
111
|
+
* @param ctx - Paths, environment, timeout, fetch and keychain runner.
|
|
112
|
+
* @param device - The device just enrolled, with its endpoint.
|
|
113
|
+
* @param secret - Its secret.
|
|
114
|
+
* @param tokenFile - Its cached access token.
|
|
115
|
+
*/
|
|
116
|
+
export async function abandonDevice(ctx, device, secret, tokenFile) {
|
|
117
|
+
const revoked = device.endpoint ? (await revokeDevice({ endpoint: device.endpoint, deviceSecret: secret, timeoutMs: ctx.timeoutMs, fetchFn: ctx.fetchFn })).ok : false;
|
|
118
|
+
// Its only copy of the secret goes next, so a device the platform kept can
|
|
119
|
+
// be switched off by an admin alone, who has to hear about it.
|
|
120
|
+
if (!revoked)
|
|
121
|
+
warnLog('a device that was enrolled but not kept (uninstall overtook it, or setup could not save it) could not be revoked; it may still be active on the platform. An admin can revoke this machine in Settings → Install.');
|
|
122
|
+
await secretStoreFor(device.store, ctx).remove(device.id).catch(() => undefined);
|
|
123
|
+
await fs.rm(tokenFile, { force: true }).catch(() => undefined);
|
|
124
|
+
debugLog('device enrollment overtaken by uninstall; revoked and forgotten');
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Whether there is nothing to exchange right now: the file already names a
|
|
128
|
+
* device for this key that the gateway has not refused (an earlier run or
|
|
129
|
+
* another process made the exchange), a refused one this run may not replace,
|
|
130
|
+
* or a failed attempt is too recent.
|
|
131
|
+
*
|
|
132
|
+
* @param ctx - Paths and clock.
|
|
133
|
+
* @param id - The key's device id.
|
|
134
|
+
* @param stateFile - The identity's device state file.
|
|
135
|
+
* @param options - Whether setup asked to ignore the backoff.
|
|
136
|
+
* @param options.ignoreBackoff - Try even within an hour of a failed attempt, and after any refusal.
|
|
137
|
+
* @returns `done` with the device (or none while backing off), else the state to update.
|
|
138
|
+
*/
|
|
139
|
+
async function settledExchange(ctx, id, stateFile, options) {
|
|
140
|
+
const [loaded, state] = await Promise.all([loadConfig(ctx.paths), readDeviceState(stateFile)]);
|
|
141
|
+
const device = deviceRefs(loaded.config).find((ref) => ref.id === id);
|
|
142
|
+
const reenroll = state.refusal !== undefined && (state.refusal.reason === REFUSAL_SECRET_EXPIRED || options.ignoreBackoff === true);
|
|
143
|
+
// A refused device this run may not replace stands for nothing: no bearer, and no install key either.
|
|
144
|
+
if (device && !reenroll)
|
|
145
|
+
return state.refusal ? { done: true } : { done: true, device };
|
|
146
|
+
if (!options.ignoreBackoff && state.enrollAttemptAt && ctx.env.now().getTime() - Date.parse(state.enrollAttemptAt) < ENROLL_RETRY_MS)
|
|
147
|
+
return { done: true };
|
|
148
|
+
return { done: false, state };
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Whether the config now names this device, which is what the next run reads.
|
|
152
|
+
*
|
|
153
|
+
* @param ctx - Paths.
|
|
154
|
+
* @param attached - What `attachDevice` reported.
|
|
155
|
+
* @param device - The device just stored.
|
|
156
|
+
* @returns True when it was written now or was already there.
|
|
157
|
+
*/
|
|
158
|
+
async function namesDevice(ctx, attached, device) {
|
|
159
|
+
if (attached === 'saved')
|
|
160
|
+
return true;
|
|
161
|
+
if (attached === 'busy')
|
|
162
|
+
return false;
|
|
163
|
+
return deviceRefs((await loadConfig(ctx.paths)).config).some((ref) => ref.id === device.id && ref.store === device.store);
|
|
164
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/** `POST /v1/devices/enroll` answer: returned once, neither secret readable afterwards. */
|
|
3
|
+
export declare const issuedDeviceCredentialSchema: z.ZodObject<{
|
|
4
|
+
deviceId: z.ZodString;
|
|
5
|
+
deviceSecret: z.ZodString;
|
|
6
|
+
deviceSecretExpiresAt: z.ZodString;
|
|
7
|
+
accessToken: z.ZodString;
|
|
8
|
+
accessTokenExpiresAt: z.ZodString;
|
|
9
|
+
/**
|
|
10
|
+
* A browser sign-in's approver, the device's developer (AWT-555); older
|
|
11
|
+
* gateways send none. Any shape parses: a bad value must not refuse a device
|
|
12
|
+
* the gateway already issued, so the sign-in checks it instead.
|
|
13
|
+
*/
|
|
14
|
+
developerEmail: z.ZodOptional<z.ZodUnknown>;
|
|
15
|
+
}, "strip", z.ZodTypeAny, {
|
|
16
|
+
deviceId: string;
|
|
17
|
+
deviceSecret: string;
|
|
18
|
+
deviceSecretExpiresAt: string;
|
|
19
|
+
accessToken: string;
|
|
20
|
+
accessTokenExpiresAt: string;
|
|
21
|
+
developerEmail?: unknown;
|
|
22
|
+
}, {
|
|
23
|
+
deviceId: string;
|
|
24
|
+
deviceSecret: string;
|
|
25
|
+
deviceSecretExpiresAt: string;
|
|
26
|
+
accessToken: string;
|
|
27
|
+
accessTokenExpiresAt: string;
|
|
28
|
+
developerEmail?: unknown;
|
|
29
|
+
}>;
|
|
30
|
+
/** `POST /v1/devices/token` answer. The device secret is not rotated, so it is not in it. */
|
|
31
|
+
export declare const refreshedAccessTokenSchema: z.ZodObject<{
|
|
32
|
+
deviceId: z.ZodString;
|
|
33
|
+
accessToken: z.ZodString;
|
|
34
|
+
accessTokenExpiresAt: z.ZodString;
|
|
35
|
+
deviceSecretExpiresAt: z.ZodString;
|
|
36
|
+
}, "strip", z.ZodTypeAny, {
|
|
37
|
+
deviceId: string;
|
|
38
|
+
deviceSecretExpiresAt: string;
|
|
39
|
+
accessToken: string;
|
|
40
|
+
accessTokenExpiresAt: string;
|
|
41
|
+
}, {
|
|
42
|
+
deviceId: string;
|
|
43
|
+
deviceSecretExpiresAt: string;
|
|
44
|
+
accessToken: string;
|
|
45
|
+
accessTokenExpiresAt: string;
|
|
46
|
+
}>;
|
|
47
|
+
/** `POST /v1/devices/enrollment-sessions` answer: the codes of one browser sign-in. */
|
|
48
|
+
export declare const startedEnrollmentSessionSchema: z.ZodObject<{
|
|
49
|
+
deviceCode: z.ZodString;
|
|
50
|
+
userCode: z.ZodString;
|
|
51
|
+
verificationUri: z.ZodString;
|
|
52
|
+
verificationUriComplete: z.ZodString;
|
|
53
|
+
expiresIn: z.ZodNumber;
|
|
54
|
+
interval: z.ZodNumber;
|
|
55
|
+
}, "strip", z.ZodTypeAny, {
|
|
56
|
+
deviceCode: string;
|
|
57
|
+
userCode: string;
|
|
58
|
+
verificationUri: string;
|
|
59
|
+
verificationUriComplete: string;
|
|
60
|
+
expiresIn: number;
|
|
61
|
+
interval: number;
|
|
62
|
+
}, {
|
|
63
|
+
deviceCode: string;
|
|
64
|
+
userCode: string;
|
|
65
|
+
verificationUri: string;
|
|
66
|
+
verificationUriComplete: string;
|
|
67
|
+
expiresIn: number;
|
|
68
|
+
interval: number;
|
|
69
|
+
}>;
|
|
70
|
+
/** A poll refused the RFC 6749 §5.2 way: `400 { "error": "…" }`. */
|
|
71
|
+
export declare const pollErrorSchema: z.ZodObject<{
|
|
72
|
+
error: z.ZodString;
|
|
73
|
+
}, "strip", z.ZodTypeAny, {
|
|
74
|
+
error: string;
|
|
75
|
+
}, {
|
|
76
|
+
error: string;
|
|
77
|
+
}>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/** `POST /v1/devices/enroll` answer: returned once, neither secret readable afterwards. */
|
|
3
|
+
export const issuedDeviceCredentialSchema = z.object({
|
|
4
|
+
deviceId: z.string().min(1),
|
|
5
|
+
deviceSecret: z.string().min(1),
|
|
6
|
+
deviceSecretExpiresAt: z.string().min(1),
|
|
7
|
+
accessToken: z.string().min(1),
|
|
8
|
+
accessTokenExpiresAt: z.string().min(1),
|
|
9
|
+
/**
|
|
10
|
+
* A browser sign-in's approver, the device's developer (AWT-555); older
|
|
11
|
+
* gateways send none. Any shape parses: a bad value must not refuse a device
|
|
12
|
+
* the gateway already issued, so the sign-in checks it instead.
|
|
13
|
+
*/
|
|
14
|
+
developerEmail: z.unknown().optional()
|
|
15
|
+
});
|
|
16
|
+
/** `POST /v1/devices/token` answer. The device secret is not rotated, so it is not in it. */
|
|
17
|
+
export const refreshedAccessTokenSchema = z.object({
|
|
18
|
+
deviceId: z.string().min(1),
|
|
19
|
+
accessToken: z.string().min(1),
|
|
20
|
+
accessTokenExpiresAt: z.string().min(1),
|
|
21
|
+
deviceSecretExpiresAt: z.string().min(1)
|
|
22
|
+
});
|
|
23
|
+
/** `POST /v1/devices/enrollment-sessions` answer: the codes of one browser sign-in. */
|
|
24
|
+
export const startedEnrollmentSessionSchema = z.object({
|
|
25
|
+
deviceCode: z.string().min(1),
|
|
26
|
+
userCode: z.string().min(1),
|
|
27
|
+
verificationUri: z.string().min(1),
|
|
28
|
+
verificationUriComplete: z.string().min(1),
|
|
29
|
+
expiresIn: z.number().positive(),
|
|
30
|
+
interval: z.number().positive()
|
|
31
|
+
});
|
|
32
|
+
/** A poll refused the RFC 6749 §5.2 way: `400 { "error": "…" }`. */
|
|
33
|
+
export const pollErrorSchema = z.object({ error: z.string().min(1) });
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/** The cached access token. `obtainedAt` is what the 25% rule measures the life from. */
|
|
3
|
+
export declare const accessTokenCacheSchema: z.ZodObject<{
|
|
4
|
+
accessToken: z.ZodString;
|
|
5
|
+
obtainedAt: z.ZodString;
|
|
6
|
+
expiresAt: z.ZodString;
|
|
7
|
+
}, "strip", z.ZodTypeAny, {
|
|
8
|
+
accessToken: string;
|
|
9
|
+
obtainedAt: string;
|
|
10
|
+
expiresAt: string;
|
|
11
|
+
}, {
|
|
12
|
+
accessToken: string;
|
|
13
|
+
obtainedAt: string;
|
|
14
|
+
expiresAt: string;
|
|
15
|
+
}>;
|
|
16
|
+
/** What one identity remembers about its device credential, beside the token. */
|
|
17
|
+
export declare const deviceStateSchema: z.ZodObject<{
|
|
18
|
+
/**
|
|
19
|
+
* The gateway refused the device secret; nothing but a new enrollment fixes
|
|
20
|
+
* it. An expired secret is enrolled again by any run; a revoked or unknown
|
|
21
|
+
* device only by setup, so a hook never undoes an admin's revocation.
|
|
22
|
+
*/
|
|
23
|
+
refusal: z.ZodOptional<z.ZodObject<{
|
|
24
|
+
reason: z.ZodString;
|
|
25
|
+
since: z.ZodString;
|
|
26
|
+
}, "strip", z.ZodTypeAny, {
|
|
27
|
+
reason: string;
|
|
28
|
+
since: string;
|
|
29
|
+
}, {
|
|
30
|
+
reason: string;
|
|
31
|
+
since: string;
|
|
32
|
+
}>>;
|
|
33
|
+
/** When the install key was last offered for exchange, so a failure backs off. */
|
|
34
|
+
enrollAttemptAt: z.ZodOptional<z.ZodString>;
|
|
35
|
+
/** When a Windows hook last started a background refresh, so it starts one, not one per hook. */
|
|
36
|
+
backgroundRefreshAt: z.ZodOptional<z.ZodString>;
|
|
37
|
+
}, "strip", z.ZodTypeAny, {
|
|
38
|
+
refusal?: {
|
|
39
|
+
reason: string;
|
|
40
|
+
since: string;
|
|
41
|
+
} | undefined;
|
|
42
|
+
enrollAttemptAt?: string | undefined;
|
|
43
|
+
backgroundRefreshAt?: string | undefined;
|
|
44
|
+
}, {
|
|
45
|
+
refusal?: {
|
|
46
|
+
reason: string;
|
|
47
|
+
since: string;
|
|
48
|
+
} | undefined;
|
|
49
|
+
enrollAttemptAt?: string | undefined;
|
|
50
|
+
backgroundRefreshAt?: string | undefined;
|
|
51
|
+
}>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/** The cached access token. `obtainedAt` is what the 25% rule measures the life from. */
|
|
3
|
+
export const accessTokenCacheSchema = z.object({
|
|
4
|
+
accessToken: z.string().min(1),
|
|
5
|
+
obtainedAt: z.string().min(1),
|
|
6
|
+
expiresAt: z.string().min(1)
|
|
7
|
+
});
|
|
8
|
+
/** What one identity remembers about its device credential, beside the token. */
|
|
9
|
+
export const deviceStateSchema = z.object({
|
|
10
|
+
/**
|
|
11
|
+
* The gateway refused the device secret; nothing but a new enrollment fixes
|
|
12
|
+
* it. An expired secret is enrolled again by any run; a revoked or unknown
|
|
13
|
+
* device only by setup, so a hook never undoes an admin's revocation.
|
|
14
|
+
*/
|
|
15
|
+
refusal: z.object({ reason: z.string(), since: z.string() }).optional(),
|
|
16
|
+
/** When the install key was last offered for exchange, so a failure backs off. */
|
|
17
|
+
enrollAttemptAt: z.string().optional(),
|
|
18
|
+
/** When a Windows hook last started a background refresh, so it starts one, not one per hook. */
|
|
19
|
+
backgroundRefreshAt: z.string().optional()
|
|
20
|
+
});
|