@primitive.ai/prim 0.1.0-alpha.124 → 0.1.0-alpha.126
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/README.md +27 -0
- package/dist/{chunk-5KPDY5GF.js → chunk-5D2C6RCH.js} +4 -4
- package/dist/{chunk-3OKVMKK2.js → chunk-6KXQQ7CQ.js} +3 -3
- package/dist/{chunk-EER7VG3P.js → chunk-74DQDWLW.js} +2 -2
- package/dist/{chunk-KMWXI7KO.js → chunk-BFYJLI7V.js} +1 -1
- package/dist/{chunk-TS2NX6YT.js → chunk-C5VBPHOS.js} +9 -8
- package/dist/{chunk-ZMH6GJUG.js → chunk-DT7E3SD5.js} +4 -4
- package/dist/{chunk-6W72SEXC.js → chunk-EZXIKEMA.js} +3 -3
- package/dist/{chunk-6WKJWW6D.js → chunk-FYYHBOOM.js} +2 -2
- package/dist/{chunk-DGZX3MID.js → chunk-JFWJN2ME.js} +3 -3
- package/dist/{chunk-A6YTFBQ4.js → chunk-KKUDAQQZ.js} +7 -8
- package/dist/{chunk-WLVEXOHC.js → chunk-L32WYFJT.js} +1 -1
- package/dist/{chunk-6VJ7C2B5.js → chunk-NBNQI3YJ.js} +2 -2
- package/dist/{chunk-KTXJJE5K.js → chunk-ND6TYHNI.js} +2 -2
- package/dist/{chunk-Q2PVD5W2.js → chunk-NJBN3WXF.js} +37 -5
- package/dist/{chunk-5MH2C5QG.js → chunk-O73J3KQQ.js} +7121 -5513
- package/dist/{chunk-EWV7VIZ3.js → chunk-PPZ56EVJ.js} +1 -1
- package/dist/{chunk-WQFJ5TEG.js → chunk-R6NDP7OF.js} +2 -2
- package/dist/{chunk-5BZWFN62.js → chunk-TI37ME2D.js} +12 -8
- package/dist/{chunk-6PSCGY2A.js → chunk-YP4OXKNX.js} +4 -2
- package/dist/{chunk-QZWLZH6D.js → chunk-ZKXNJB6U.js} +3 -3
- package/dist/daemon/server.js +7128 -5507
- package/dist/hook-runtime/daemon/server.js +7128 -5507
- package/dist/hook-runtime/hooks/post-commit.js +7106 -5496
- package/dist/hook-runtime/hooks/post-rewrite.js +7106 -5496
- package/dist/hook-runtime/hooks/post-tool-use.js +3595 -1977
- package/dist/hook-runtime/hooks/pre-commit.js +17 -7
- package/dist/hook-runtime/hooks/pre-tool-use-worker.js +3796 -2184
- package/dist/hook-runtime/hooks/prim-hook.js +7117 -5502
- package/dist/hook-runtime/hooks/session-end.js +11 -4
- package/dist/hook-runtime/hooks/session-start.js +3584 -1970
- package/dist/hook-runtime/index.js +6376 -4464
- package/dist/hook-runtime/statusline-main.js +11 -4
- package/dist/hooks/post-commit.js +7 -7
- package/dist/hooks/post-rewrite.js +6 -6
- package/dist/hooks/post-tool-use.js +15 -15
- package/dist/hooks/pre-commit.js +4 -4
- package/dist/hooks/pre-tool-use-worker.js +9 -9
- package/dist/hooks/prim-hook.js +16 -16
- package/dist/hooks/session-end.js +4 -4
- package/dist/hooks/session-start.js +11 -11
- package/dist/index.js +9117 -8836
- package/dist/statusline-main.js +11 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -723,3 +723,30 @@ imports an explicitly unpublished backend contract. Canonical provenance remains
|
|
|
723
723
|
blocked until the backend is published and imported with
|
|
724
724
|
`pnpm contracts:update --revision <full-commit>`. Production releases must pass
|
|
725
725
|
`pnpm contracts:provenance`.
|
|
726
|
+
|
|
727
|
+
### Developer installation enrollment
|
|
728
|
+
|
|
729
|
+
When automatic enrollment is enabled by your organization, run `prim setup`.
|
|
730
|
+
Sign in once and select your organization; Prim registers this installation and
|
|
731
|
+
stores its machine credentials in the OS credential store (or the existing private
|
|
732
|
+
file fallback). Repeated setup reuses the installation. No WorkOS dashboard access
|
|
733
|
+
or copying of client secrets is required. `prim auth enroll` also enrolls an already
|
|
734
|
+
signed-in installation.
|
|
735
|
+
|
|
736
|
+
The installation authenticates the request while your account owns the Decisions.
|
|
737
|
+
Your private drafts, existing Decisions, and normal lifecycle permissions remain
|
|
738
|
+
available. Human/agent attribution and adoption rules stay the same. The installation
|
|
739
|
+
is recorded as provenance. Administrators can manage enrollment policy and revoke
|
|
740
|
+
installations in the web application's Settings → Developer installations.
|
|
741
|
+
|
|
742
|
+
Setup attempts to deliver pending legacy captures before changing credentials.
|
|
743
|
+
Any remaining activity stays under its original authorization; inspect it with
|
|
744
|
+
`prim moves status`. It is never uploaded under newly assigned authorship.
|
|
745
|
+
`prim auth status` reports the installation, authorized user, storage backend, and
|
|
746
|
+
expiry without revealing credentials. If older-secret retirement is pending, rerun
|
|
747
|
+
`prim auth enroll` to retry it.
|
|
748
|
+
|
|
749
|
+
On a server without enrollment, setup retains legacy authentication. Existing
|
|
750
|
+
manually configured machines and CI credentials remain service identities; routine
|
|
751
|
+
setup does not convert them into developer installations. GitHub installation and
|
|
752
|
+
API-key administration remain available in the web application.
|
|
@@ -4,20 +4,20 @@ import {
|
|
|
4
4
|
import {
|
|
5
5
|
analyzeShellTargets,
|
|
6
6
|
extractFileTargets
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-KKUDAQQZ.js";
|
|
8
8
|
import {
|
|
9
9
|
scrubEnvironmentPaths
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-74DQDWLW.js";
|
|
11
11
|
import {
|
|
12
12
|
cachedCollectScopeAdmits
|
|
13
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-O73J3KQQ.js";
|
|
14
14
|
import {
|
|
15
15
|
canonicalRepositoryPath,
|
|
16
16
|
currentBranch,
|
|
17
17
|
isRepoActiveForCapture,
|
|
18
18
|
relatedWorktreeTarget,
|
|
19
19
|
repoSyncId
|
|
20
|
-
} from "./chunk-
|
|
20
|
+
} from "./chunk-NJBN3WXF.js";
|
|
21
21
|
|
|
22
22
|
// src/hooks/file-refs.ts
|
|
23
23
|
var MAX_PREFLIGHT_FILE_TARGETS = 25;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
boundedHealthError
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-O73J3KQQ.js";
|
|
4
4
|
import {
|
|
5
5
|
stripControlChars
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-ZKXNJB6U.js";
|
|
7
7
|
import {
|
|
8
8
|
hasMachineConfiguration
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-NJBN3WXF.js";
|
|
10
10
|
|
|
11
11
|
// src/lib/delivery-backlog.ts
|
|
12
12
|
var MS_PER_SECOND = 1e3;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
boundedHealthError
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-O73J3KQQ.js";
|
|
4
4
|
import {
|
|
5
5
|
terminalSafeLine
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-ZKXNJB6U.js";
|
|
7
7
|
|
|
8
8
|
// src/hooks/redact.ts
|
|
9
9
|
import { existsSync, readFileSync, statSync } from "fs";
|
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
import {
|
|
2
2
|
analyzeShellTargets,
|
|
3
3
|
extractFileTargets
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-KKUDAQQZ.js";
|
|
5
5
|
import {
|
|
6
6
|
DEFAULT_RULES,
|
|
7
7
|
scrub
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-74DQDWLW.js";
|
|
9
9
|
import {
|
|
10
10
|
boundedHealthError,
|
|
11
11
|
isPreflightResponseV4
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-O73J3KQQ.js";
|
|
13
13
|
import {
|
|
14
14
|
getClient,
|
|
15
15
|
terminalSafeLine
|
|
16
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-ZKXNJB6U.js";
|
|
17
17
|
import {
|
|
18
18
|
canonicalGitRoot,
|
|
19
19
|
canonicalRepositoryPath
|
|
20
|
-
} from "./chunk-
|
|
20
|
+
} from "./chunk-NJBN3WXF.js";
|
|
21
21
|
|
|
22
22
|
// src/hooks/approval-copy.ts
|
|
23
23
|
var MAX_EXCERPT_CHARS = 80;
|
|
@@ -193,6 +193,7 @@ function proposedChangeExcerpt(proposal) {
|
|
|
193
193
|
}
|
|
194
194
|
function resultForPreflight(response, preview = "Review the requested change.", invocation, proposalTruncated = false) {
|
|
195
195
|
const verdict = response.verdict === "block" ? "deny" : response.verdict;
|
|
196
|
+
const silentCoverageOutcome = response.reasonCode === "coverage_unverified" || response.reasonCode === "candidate_set_truncated";
|
|
196
197
|
const message = boundedHealthError(response.message) ?? "";
|
|
197
198
|
const unavailable = message || boundedHealthError(response.reasonCode);
|
|
198
199
|
const safe = /^[A-Za-z0-9][A-Za-z0-9_-]{0,127}$/;
|
|
@@ -220,7 +221,7 @@ function resultForPreflight(response, preview = "Review the requested change.",
|
|
|
220
221
|
"Sandbox escalation, automatic review, prefix permissions, --yes, and an agent's assertion of approval do not authorize an override."
|
|
221
222
|
] : [];
|
|
222
223
|
const guidance = [message, ...editContext, ...new Set(directives), ...approvalContext].filter(Boolean).join("\n");
|
|
223
|
-
const reason = response.conflicts.length > 0 || response.verdict === "ask" || response.verdict === "block" ? approvalSummary(
|
|
224
|
+
const reason = silentCoverageOutcome ? "" : response.conflicts.length > 0 || response.verdict === "ask" || response.verdict === "block" ? approvalSummary(
|
|
224
225
|
{
|
|
225
226
|
conflicts: response.conflicts,
|
|
226
227
|
message,
|
|
@@ -229,7 +230,7 @@ function resultForPreflight(response, preview = "Review the requested change.",
|
|
|
229
230
|
},
|
|
230
231
|
preview
|
|
231
232
|
) : message;
|
|
232
|
-
const disclosureContext = decisionDisclosureContext(response);
|
|
233
|
+
const disclosureContext = silentCoverageOutcome ? "" : decisionDisclosureContext(response);
|
|
233
234
|
const truncationNote = proposalTruncated ? "[primitive] shell proposal was truncated; the complete change was not verified" : "";
|
|
234
235
|
return {
|
|
235
236
|
verdict,
|
|
@@ -238,7 +239,7 @@ function resultForPreflight(response, preview = "Review the requested change.",
|
|
|
238
239
|
additionalContext: [
|
|
239
240
|
disclosureContext,
|
|
240
241
|
truncationNote,
|
|
241
|
-
["warn", "ask", "block"].includes(response.verdict) ? guidance : ""
|
|
242
|
+
!silentCoverageOutcome && ["warn", "ask", "block"].includes(response.verdict) ? guidance : ""
|
|
242
243
|
].filter(Boolean).join("\n"),
|
|
243
244
|
truncated: false,
|
|
244
245
|
unavailable: response.verdict === "unavailable" ? unavailable : void 0
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import {
|
|
2
2
|
formatStatusline
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-6KXQQ7CQ.js";
|
|
4
4
|
import {
|
|
5
5
|
daemonPrincipalsMatch,
|
|
6
6
|
daemonRequest,
|
|
7
7
|
resolveDaemonPrincipal
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-YP4OXKNX.js";
|
|
9
9
|
import {
|
|
10
10
|
getSiteUrl,
|
|
11
11
|
isSessionEnded,
|
|
12
12
|
terminalSafeText
|
|
13
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-ZKXNJB6U.js";
|
|
14
14
|
import {
|
|
15
15
|
decisionIngestionStatus,
|
|
16
16
|
gitToplevel,
|
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
primConfigDirectory,
|
|
19
19
|
repositoryBindingState,
|
|
20
20
|
withFileLock
|
|
21
|
-
} from "./chunk-
|
|
21
|
+
} from "./chunk-NJBN3WXF.js";
|
|
22
22
|
|
|
23
23
|
// src/hooks/codex-context.ts
|
|
24
24
|
import { createHash, randomBytes as randomBytes2 } from "crypto";
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import {
|
|
2
2
|
daemonRequest
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-YP4OXKNX.js";
|
|
4
4
|
import {
|
|
5
5
|
getClient,
|
|
6
6
|
getSiteUrl,
|
|
7
7
|
terminalSafeLine
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-ZKXNJB6U.js";
|
|
9
9
|
import {
|
|
10
10
|
canonicalGitRoot,
|
|
11
11
|
canonicalRepositoryPath,
|
|
12
12
|
currentBranch,
|
|
13
13
|
repoSyncId
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-NJBN3WXF.js";
|
|
15
15
|
|
|
16
16
|
// src/daemon/proxy.ts
|
|
17
17
|
var DAEMON_HTTP_TIMEOUT_MS = 1e4;
|
|
@@ -3,10 +3,10 @@ import {
|
|
|
3
3
|
} from "./chunk-EZXEWFDG.js";
|
|
4
4
|
import {
|
|
5
5
|
scrubEnvironmentPaths
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-74DQDWLW.js";
|
|
7
7
|
import {
|
|
8
8
|
isValidRepoSyncId
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-NJBN3WXF.js";
|
|
10
10
|
|
|
11
11
|
// src/hooks/prim-hook-core.ts
|
|
12
12
|
import { createHash, randomUUID } from "crypto";
|
|
@@ -9,11 +9,11 @@ import {
|
|
|
9
9
|
hookBlockContractVersion,
|
|
10
10
|
inspectGitHookEntrypoint,
|
|
11
11
|
managedHookBlock
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-L32WYFJT.js";
|
|
13
13
|
import {
|
|
14
14
|
HttpError,
|
|
15
15
|
getClient
|
|
16
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-ZKXNJB6U.js";
|
|
17
17
|
import {
|
|
18
18
|
atomicWriteFile,
|
|
19
19
|
binFile,
|
|
@@ -27,7 +27,7 @@ import {
|
|
|
27
27
|
setRepoSyncId,
|
|
28
28
|
setRepositoryBindingState,
|
|
29
29
|
withFileLock
|
|
30
|
-
} from "./chunk-
|
|
30
|
+
} from "./chunk-NJBN3WXF.js";
|
|
31
31
|
|
|
32
32
|
// src/commands/skill.ts
|
|
33
33
|
import { createHash as createHash3 } from "crypto";
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import {
|
|
2
2
|
inspectHookRuntime
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-L32WYFJT.js";
|
|
4
4
|
import {
|
|
5
5
|
isDemoStatusResponse
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-O73J3KQQ.js";
|
|
7
7
|
import {
|
|
8
8
|
atomicWriteFile,
|
|
9
9
|
primConfigDirectory,
|
|
10
10
|
withFileLock,
|
|
11
11
|
withFileLockSync
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-NJBN3WXF.js";
|
|
13
13
|
|
|
14
14
|
// src/hooks/pre-tool-use-scoring.ts
|
|
15
15
|
import { isAbsolute, relative, sep } from "path";
|
|
@@ -18,16 +18,15 @@ function anyUnverified(results) {
|
|
|
18
18
|
}
|
|
19
19
|
function unverifiedNote(results) {
|
|
20
20
|
const causes = [];
|
|
21
|
-
const unavailable = results.find(
|
|
21
|
+
const unavailable = results.find(
|
|
22
|
+
(result) => result.verdict === "unavailable" && !result.unavailable?.startsWith("Mutation targets could not be resolved")
|
|
23
|
+
);
|
|
22
24
|
if (unavailable) {
|
|
23
25
|
causes.push(
|
|
24
26
|
unavailable.unavailable ? `decision check skipped \u2014 ${unavailable.unavailable}` : "decision check skipped \u2014 not verified"
|
|
25
27
|
);
|
|
26
28
|
}
|
|
27
|
-
|
|
28
|
-
causes.push("decision check partial \u2014 conflict set truncated (per-file cap hit)");
|
|
29
|
-
}
|
|
30
|
-
return causes.map((c) => `[primitive] ${c}`).join("\n");
|
|
29
|
+
return causes.map((cause) => `[primitive] ${cause}`).join("\n");
|
|
31
30
|
}
|
|
32
31
|
function blockingReason(results) {
|
|
33
32
|
const parts = results.filter((result) => result.verdict === "ask" || result.verdict === "deny").flatMap((result) => [result.reason, result.additionalContext]).filter((value) => value.length > 0);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getSiteUrl
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-ZKXNJB6U.js";
|
|
4
4
|
import {
|
|
5
5
|
atomicWriteFile,
|
|
6
6
|
ensureDurableDirectory,
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
machineJournalBucket,
|
|
12
12
|
primConfigDirectory,
|
|
13
13
|
resolveAuthCredential
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-NJBN3WXF.js";
|
|
15
15
|
|
|
16
16
|
// src/journal.ts
|
|
17
17
|
import {
|
|
@@ -2,10 +2,10 @@ import {
|
|
|
2
2
|
cursorHooksPath,
|
|
3
3
|
hasExactCursorHandler,
|
|
4
4
|
readCursorHooks
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-L32WYFJT.js";
|
|
6
6
|
import {
|
|
7
7
|
resolveRepositoryContext
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-NJBN3WXF.js";
|
|
9
9
|
|
|
10
10
|
// src/hooks/cursor-coexistence.ts
|
|
11
11
|
var CURSOR_EVENTS = /* @__PURE__ */ new Set([
|
|
@@ -1236,7 +1236,11 @@ function parseMachineConfiguration(value) {
|
|
|
1236
1236
|
"The WorkOS issuer must be an HTTPS origin."
|
|
1237
1237
|
);
|
|
1238
1238
|
}
|
|
1239
|
-
return {
|
|
1239
|
+
return {
|
|
1240
|
+
issuer: record.issuer,
|
|
1241
|
+
audience: record.audience,
|
|
1242
|
+
...record.developer_enrollment === true ? { developerEnrollment: true } : {}
|
|
1243
|
+
};
|
|
1240
1244
|
}
|
|
1241
1245
|
function machineSignal(signal) {
|
|
1242
1246
|
return signal ? AbortSignal.any([signal, AbortSignal.timeout(1e4)]) : AbortSignal.timeout(1e4);
|
|
@@ -1336,7 +1340,7 @@ async function exchangeMachineCredentials(configuration, clientId, clientSecret,
|
|
|
1336
1340
|
function parseMachineIdentity(value, clientId) {
|
|
1337
1341
|
const data = machineRecord(value);
|
|
1338
1342
|
const principal = machineRecord(data.principal);
|
|
1339
|
-
if (data.authenticated !== true || data.captureAuthorityKind !== "workos_m2m" || data.organizationBindingVersion !==
|
|
1343
|
+
if (data.authenticated !== true || data.captureAuthorityKind !== "workos_m2m" || ![2, 3].includes(data.organizationBindingVersion) || (data.organizationBindingVersion === 3 ? !machineString(principal.authorizedUserId, 256) : principal.authorizedUserId !== void 0) || principal.kind !== "machine" || principal.clientId !== clientId || !machineString(principal.machineId, 256) || !machineString(principal.displayName, 256) || !machineString(data.organizationId, 256) || !machineString(data.workosOrganizationId, 256) || !Array.isArray(principal.scopes) || !principal.scopes.every((scope) => machineString(scope, 128))) {
|
|
1340
1344
|
throw new MachineAuthError(
|
|
1341
1345
|
"machine_identity_rejected",
|
|
1342
1346
|
"The API did not verify a machine identity.",
|
|
@@ -1345,6 +1349,7 @@ function parseMachineIdentity(value, clientId) {
|
|
|
1345
1349
|
}
|
|
1346
1350
|
return {
|
|
1347
1351
|
machineId: principal.machineId,
|
|
1352
|
+
...data.organizationBindingVersion === 3 ? { authorizedUserId: principal.authorizedUserId } : {},
|
|
1348
1353
|
clientId,
|
|
1349
1354
|
displayName: principal.displayName,
|
|
1350
1355
|
organizationId: data.organizationId,
|
|
@@ -1671,6 +1676,7 @@ function writeEnvironmentContext(credential, deps) {
|
|
|
1671
1676
|
organizationId,
|
|
1672
1677
|
workosOrganizationId,
|
|
1673
1678
|
displayName,
|
|
1679
|
+
authorizedUserId,
|
|
1674
1680
|
scopes,
|
|
1675
1681
|
expiresAt
|
|
1676
1682
|
} = credential;
|
|
@@ -1686,6 +1692,7 @@ function writeEnvironmentContext(credential, deps) {
|
|
|
1686
1692
|
organizationId,
|
|
1687
1693
|
workosOrganizationId,
|
|
1688
1694
|
displayName,
|
|
1695
|
+
authorizedUserId,
|
|
1689
1696
|
scopes,
|
|
1690
1697
|
expiresAt
|
|
1691
1698
|
});
|
|
@@ -1783,7 +1790,7 @@ function parseStoredIdentity(data) {
|
|
|
1783
1790
|
return parseMachineIdentity(
|
|
1784
1791
|
{
|
|
1785
1792
|
authenticated: true,
|
|
1786
|
-
organizationBindingVersion: 2,
|
|
1793
|
+
organizationBindingVersion: data.authorizedUserId ? 3 : 2,
|
|
1787
1794
|
captureAuthorityKind: "workos_m2m",
|
|
1788
1795
|
organizationId: data.organizationId,
|
|
1789
1796
|
workosOrganizationId: data.workosOrganizationId,
|
|
@@ -1891,6 +1898,7 @@ async function loadRecord(profile, deps, signal) {
|
|
|
1891
1898
|
"generation",
|
|
1892
1899
|
"storage",
|
|
1893
1900
|
"machineId",
|
|
1901
|
+
"authorizedUserId",
|
|
1894
1902
|
"clientId",
|
|
1895
1903
|
"organizationId",
|
|
1896
1904
|
"workosOrganizationId"
|
|
@@ -1961,6 +1969,18 @@ async function configureMachine(clientId, clientSecret, deps = {}, signal) {
|
|
|
1961
1969
|
signal,
|
|
1962
1970
|
deps.fetch
|
|
1963
1971
|
);
|
|
1972
|
+
if (deps.expectedAuthorizedUserId && identity2.authorizedUserId !== deps.expectedAuthorizedUserId)
|
|
1973
|
+
throw new MachineAuthError(
|
|
1974
|
+
"delegation_mismatch",
|
|
1975
|
+
"The enrolled installation does not have the expected user delegation.",
|
|
1976
|
+
true
|
|
1977
|
+
);
|
|
1978
|
+
if (deps.expectedOrganizationId && identity2.organizationId !== deps.expectedOrganizationId)
|
|
1979
|
+
throw new MachineAuthError(
|
|
1980
|
+
"delegation_mismatch",
|
|
1981
|
+
"The installation belongs to a different organization.",
|
|
1982
|
+
true
|
|
1983
|
+
);
|
|
1964
1984
|
return { configuration: configuration2, tokens: tokens2, identity: identity2 };
|
|
1965
1985
|
}
|
|
1966
1986
|
);
|
|
@@ -2128,7 +2148,7 @@ async function acquireMachineCredential(options = {}, deps = {}) {
|
|
|
2128
2148
|
return { tokens: tokens2, identity: identity2 };
|
|
2129
2149
|
}
|
|
2130
2150
|
);
|
|
2131
|
-
if (identity.machineId !== profile.machineId || identity.organizationId !== profile.organizationId || identity.workosOrganizationId !== profile.workosOrganizationId)
|
|
2151
|
+
if (identity.machineId !== profile.machineId || identity.authorizedUserId !== profile.authorizedUserId || identity.organizationId !== profile.organizationId || identity.workosOrganizationId !== profile.workosOrganizationId)
|
|
2132
2152
|
throw new MachineAuthError(
|
|
2133
2153
|
"identity_changed",
|
|
2134
2154
|
"Machine identity changed; configure the new identity explicitly.",
|
|
@@ -2189,13 +2209,14 @@ function machineCaptureActor(deps = {}) {
|
|
|
2189
2209
|
clientId: context.clientId,
|
|
2190
2210
|
issuer: context.issuer,
|
|
2191
2211
|
machineId: context.machineId,
|
|
2212
|
+
authorizedUserId: context.authorizedUserId,
|
|
2192
2213
|
organizationId: context.organizationId
|
|
2193
2214
|
};
|
|
2194
2215
|
const injected = environmentCredentials(deps);
|
|
2195
2216
|
return injected ? { kind: "machine", apiUrl: apiUrlFor(deps), clientId: injected.clientId } : void 0;
|
|
2196
2217
|
}
|
|
2197
2218
|
function machineJournalBucket(identity) {
|
|
2198
|
-
return `_machine_${hash(`${identity.apiUrl}\0${identity.clientId}`)}`;
|
|
2219
|
+
return `_machine_${hash(`${identity.apiUrl}\0${identity.clientId}${identity.authorizedUserId ? `\0${identity.authorizedUserId}` : ""}`)}`;
|
|
2199
2220
|
}
|
|
2200
2221
|
function readRetiredProfiles(directory) {
|
|
2201
2222
|
const value = readPrivate(join7(directory, "machine_retired.json"));
|
|
@@ -2224,6 +2245,12 @@ async function cleanupRetired(deps, signal) {
|
|
|
2224
2245
|
if (pending.length) writePrivate(path, pending);
|
|
2225
2246
|
else rmSync5(path, { force: true });
|
|
2226
2247
|
}
|
|
2248
|
+
function prepareMachineMetadataDirectory(directory) {
|
|
2249
|
+
ensureDirectory(directory);
|
|
2250
|
+
}
|
|
2251
|
+
function writeMachineMetadata(path, value) {
|
|
2252
|
+
writePrivate(path, value);
|
|
2253
|
+
}
|
|
2227
2254
|
|
|
2228
2255
|
// src/lib/credentials.ts
|
|
2229
2256
|
import { createHash as createHash5 } from "crypto";
|
|
@@ -2407,7 +2434,10 @@ export {
|
|
|
2407
2434
|
parseWorkosConnectTokens,
|
|
2408
2435
|
pollWorkosDeviceAuthorization,
|
|
2409
2436
|
MachineAuthError,
|
|
2437
|
+
machineString,
|
|
2438
|
+
machineRecord,
|
|
2410
2439
|
machineApiUrl,
|
|
2440
|
+
discoverMachineConfiguration,
|
|
2411
2441
|
parseMachineIdentity,
|
|
2412
2442
|
verifyMachineIdentity,
|
|
2413
2443
|
primConfigDirectory,
|
|
@@ -2422,6 +2452,8 @@ export {
|
|
|
2422
2452
|
clearMachineCredentials,
|
|
2423
2453
|
machineCaptureActor,
|
|
2424
2454
|
machineJournalBucket,
|
|
2455
|
+
prepareMachineMetadataDirectory,
|
|
2456
|
+
writeMachineMetadata,
|
|
2425
2457
|
TOKEN_FILE_PATH,
|
|
2426
2458
|
REFRESH_TOKEN_PATH,
|
|
2427
2459
|
TOKEN_EXPIRES_PATH,
|