openmeld 0.3.205 → 0.3.207
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/dist/{add-me-membership-jhCNTfdl.js → add-me-membership-1JHMjZoR.js} +2 -2
- package/dist/{add-me-membership-jhCNTfdl.js.map → add-me-membership-1JHMjZoR.js.map} +1 -1
- package/dist/{agents-9krfNX_L.js → agents-CIDsThyG.js} +1041 -597
- package/dist/agents-CIDsThyG.js.map +1 -0
- package/dist/{api-client-foundation-BguumKMv.js → api-client-foundation-D6_NXHPV.js} +1 -1
- package/dist/{api-client-foundation-BMPOo4bG.js → api-client-foundation-DSurenul.js} +17 -7
- package/dist/api-client-foundation-DSurenul.js.map +1 -0
- package/dist/auth-session-B7QMhHwh.js +4 -0
- package/dist/{auth-session-wmefguut.js → auth-session-CO5XtFaq.js} +450 -128
- package/dist/auth-session-CO5XtFaq.js.map +1 -0
- package/dist/{base-url-C89TOpPV.js → base-url-BE3pFiOZ.js} +1 -1
- package/dist/{base-url-jWXPssF_.js → base-url-C6sHRNGu.js} +3 -3
- package/dist/{base-url-jWXPssF_.js.map → base-url-C6sHRNGu.js.map} +1 -1
- package/dist/cli-binary-manifest-DiUulkp0.js +117 -0
- package/dist/cli-binary-manifest-DiUulkp0.js.map +1 -0
- package/dist/{command-DKM3wO3V.js → command-Bzt9zgnI.js} +14 -12
- package/dist/{command-DKM3wO3V.js.map → command-Bzt9zgnI.js.map} +1 -1
- package/dist/computer-connection-BOl79Ftf.js +54 -0
- package/dist/computer-connection-BOl79Ftf.js.map +1 -0
- package/dist/computer-connection-review-BTOvbJYL.js +39 -0
- package/dist/computer-connection-review-BTOvbJYL.js.map +1 -0
- package/dist/{computer-setup-continuation-Dad0lLP9.js → computer-setup-continuation-DmKdhR5u.js} +4 -4
- package/dist/{computer-setup-continuation-Dad0lLP9.js.map → computer-setup-continuation-DmKdhR5u.js.map} +1 -1
- package/dist/control-plane-D9jDcbMZ.js +1211 -0
- package/dist/control-plane-D9jDcbMZ.js.map +1 -0
- package/dist/daemon-local-state-file-jOXuXrky.js +45 -0
- package/dist/daemon-local-state-file-jOXuXrky.js.map +1 -0
- package/dist/daemon-runtime-lease-Dd4hdHNo.js +50 -0
- package/dist/daemon-runtime-lease-Dd4hdHNo.js.map +1 -0
- package/dist/{daemon-runtime-lease-BG9g0a6Z.js → daemon-runtime-lease-y3n1K0-C.js} +1 -1
- package/dist/{daemon-service-manager-DqVtRLBY.js → daemon-service-manager-Bh0LoLed.js} +1 -1
- package/dist/{daemon-service-manager-BVipiZwK.js → daemon-service-manager-GiMCiTmu.js} +99 -85
- package/dist/daemon-service-manager-GiMCiTmu.js.map +1 -0
- package/dist/daemon-service-runtime-DQW9gSLT.js +3642 -0
- package/dist/daemon-service-runtime-DQW9gSLT.js.map +1 -0
- package/dist/{daemon-state-BwIoDq7_.js → daemon-state-C37ZtIZK.js} +11 -5
- package/dist/daemon-state-C37ZtIZK.js.map +1 -0
- package/dist/{dist-CkixulB-.js → dist-D-kJdWZE.js} +4272 -3990
- package/dist/dist-D-kJdWZE.js.map +1 -0
- package/dist/dist-DTG_Vqc7.js +4 -0
- package/dist/distribution-DY2fBeSW.js +72 -0
- package/dist/distribution-DY2fBeSW.js.map +1 -0
- package/dist/{elapsed-time-CjAPqg-B.js → elapsed-time-CcoM2R3N.js} +7 -4
- package/dist/{elapsed-time-CjAPqg-B.js.map → elapsed-time-CcoM2R3N.js.map} +1 -1
- package/dist/{installer-CZyyvNZr.js → installation-inventory-DJlwXa1q.js} +362 -361
- package/dist/installation-inventory-DJlwXa1q.js.map +1 -0
- package/dist/{lock-CvBnBcFK.js → lock-Dxp6o_t_.js} +56 -7
- package/dist/lock-Dxp6o_t_.js.map +1 -0
- package/dist/{openmeld-DVThrV4O.js → openmeld-CiL4AiB0.js} +232 -23
- package/dist/openmeld-CiL4AiB0.js.map +1 -0
- package/dist/openmeld-dev.js +1 -1
- package/dist/openmeld-environment-target-NtJYJe1D.js +256 -0
- package/dist/openmeld-environment-target-NtJYJe1D.js.map +1 -0
- package/dist/{openmeld-maintenance-worker-Cxp6fwB5.js → openmeld-maintenance-worker-DjdmRASI.js} +9 -8
- package/dist/{openmeld-maintenance-worker-Cxp6fwB5.js.map → openmeld-maintenance-worker-DjdmRASI.js.map} +1 -1
- package/dist/{openmeld-tools-update-coordinator-DJ65uI3O.js → openmeld-tools-update-coordinator-D9Skj8IE.js} +52 -4013
- package/dist/openmeld-tools-update-coordinator-D9Skj8IE.js.map +1 -0
- package/dist/openmeld.js +3 -3
- package/dist/{prepare-session-executor-aE1YARgn.js → prepare-session-executor-B0NtjHEL.js} +15 -13
- package/dist/{prepare-session-executor-aE1YARgn.js.map → prepare-session-executor-B0NtjHEL.js.map} +1 -1
- package/dist/{profiles-Dx3gaXgQ.js → runtime-transport-QIZmAo4-.js} +634 -1825
- package/dist/runtime-transport-QIZmAo4-.js.map +1 -0
- package/dist/service-account-authorization-Dt8kGvq8.js +56 -0
- package/dist/service-account-authorization-Dt8kGvq8.js.map +1 -0
- package/dist/service-control-capabilities-BU5F75zi.js +54 -0
- package/dist/service-control-capabilities-BU5F75zi.js.map +1 -0
- package/dist/service-control-capabilities-CzUB1ovW.js +4 -0
- package/dist/upgrade-DLECkjMt.js +4 -0
- package/dist/{upgrade-Bk8t5oav.js → upgrade-NxpTydHp.js} +6 -4
- package/dist/upgrade-NxpTydHp.js.map +1 -0
- package/dist/{urls-4D7CaXe3.js → urls-CY2uzH2-.js} +2 -1
- package/dist/urls-CY2uzH2-.js.map +1 -0
- package/package.json +2 -2
- package/dist/agents-9krfNX_L.js.map +0 -1
- package/dist/api-client-foundation-BMPOo4bG.js.map +0 -1
- package/dist/auth-session-CpPqG8Xz.js +0 -4
- package/dist/auth-session-wmefguut.js.map +0 -1
- package/dist/daemon-runtime-lease-CXlGR-iA.js +0 -87
- package/dist/daemon-runtime-lease-CXlGR-iA.js.map +0 -1
- package/dist/daemon-service-manager-BVipiZwK.js.map +0 -1
- package/dist/daemon-state-BwIoDq7_.js.map +0 -1
- package/dist/dist-BFbC-9BX.js +0 -4
- package/dist/dist-CkixulB-.js.map +0 -1
- package/dist/installer-CZyyvNZr.js.map +0 -1
- package/dist/lock-CvBnBcFK.js.map +0 -1
- package/dist/openmeld-DVThrV4O.js.map +0 -1
- package/dist/openmeld-tools-update-coordinator-DJ65uI3O.js.map +0 -1
- package/dist/profiles-Dx3gaXgQ.js.map +0 -1
- package/dist/upgrade-BFGKy5He.js +0 -4
- package/dist/upgrade-Bk8t5oav.js.map +0 -1
- package/dist/urls-4D7CaXe3.js.map +0 -1
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
import { t as isLoopbackHostname } from "./loopback-hostname-DHQPKq8N.js";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { C as isProcessIdentityAlive, S as CURRENT_PROCESS_START_IDENTITY, d as runWithHeldLock, i as isOpenMeldLockError, rt as openMeldRootDir, t as acquireLock, w as readProcessStartIdentity } from "./lock-Dxp6o_t_.js";
|
|
5
|
+
import { Dr as START_BOUNDED_ID_SCHEMA, Gr as openMeldProfileIdSchema, Lr as authProfileKindSchema, Nr as localAgentCatalogSchema, Or as START_BOUNDED_VERSION_SCHEMA, Rr as authProfileManagedRoleSchema, jr as startReplyReadinessSummarySchema, kr as START_ISO_DATE_TIME_SCHEMA, t as CURRENT_DAEMON_EXECUTION_CONTRACT_EPOCH } from "./runtime-transport-QIZmAo4-.js";
|
|
6
|
+
import { $ as literal, G as boolean, W as array, X as int, Y as enumFactory, Z as iso, at as record, dt as unknown, ot as strictObject, q as discriminatedUnion, rt as object, st as string, tt as nullFactory, ut as union } from "./control-plane-D9jDcbMZ.js";
|
|
6
7
|
import { r as daemonServiceLaneSchema } from "./service-contract-CRyDcIIf.js";
|
|
8
|
+
import { i as serviceAccountAdmissionSchema, t as isBinaryDistribution } from "./distribution-DY2fBeSW.js";
|
|
9
|
+
import { n as writeDaemonLocalStateFile } from "./daemon-local-state-file-jOXuXrky.js";
|
|
7
10
|
import { createRequire } from "node:module";
|
|
8
11
|
import { createHash, randomUUID } from "node:crypto";
|
|
9
12
|
import { join, resolve } from "node:path";
|
|
10
13
|
import { chmod, link, mkdir, open, readFile, rename, rm, writeFile } from "node:fs/promises";
|
|
11
14
|
import * as z$1 from "zod/v4";
|
|
12
15
|
import { spawn } from "node:child_process";
|
|
16
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
13
17
|
import { setTimeout as setTimeout$1 } from "node:timers/promises";
|
|
14
18
|
import { fileURLToPath } from "node:url";
|
|
15
19
|
//#region ../../packages/schemas/dist/schemas/start/device-projection.js
|
|
@@ -81,63 +85,6 @@ z$1.strictObject({
|
|
|
81
85
|
deviceReplyReadiness: startReplyReadinessSummarySchema
|
|
82
86
|
});
|
|
83
87
|
//#endregion
|
|
84
|
-
//#region ../../packages/schemas/dist/schemas/local-machine/macos-keychain-helper.js
|
|
85
|
-
const MAC_OS_KEYCHAIN_AUTHENTICATION_INTERACTION = "disallow";
|
|
86
|
-
const macOsKeychainServiceSchema = z$1.string().trim().min(1).max(512);
|
|
87
|
-
const macOsKeychainAccountSchema = z$1.string().trim().min(1).max(512);
|
|
88
|
-
const macOsKeychainAccessTokenSchema = z$1.string().min(1).max(65536);
|
|
89
|
-
const macOsKeychainHelperOperationSchema = z$1.enum([
|
|
90
|
-
"store",
|
|
91
|
-
"read",
|
|
92
|
-
"delete"
|
|
93
|
-
]);
|
|
94
|
-
const macOsKeychainHelperRequestSchema = z$1.discriminatedUnion("operation", [
|
|
95
|
-
z$1.strictObject({
|
|
96
|
-
schemaVersion: z$1.literal(2),
|
|
97
|
-
operation: z$1.literal("store"),
|
|
98
|
-
service: macOsKeychainServiceSchema,
|
|
99
|
-
account: macOsKeychainAccountSchema,
|
|
100
|
-
accessToken: macOsKeychainAccessTokenSchema,
|
|
101
|
-
authenticationInteraction: z$1.literal(MAC_OS_KEYCHAIN_AUTHENTICATION_INTERACTION)
|
|
102
|
-
}),
|
|
103
|
-
z$1.strictObject({
|
|
104
|
-
schemaVersion: z$1.literal(2),
|
|
105
|
-
operation: z$1.literal("read"),
|
|
106
|
-
service: macOsKeychainServiceSchema,
|
|
107
|
-
account: macOsKeychainAccountSchema,
|
|
108
|
-
authenticationInteraction: z$1.literal(MAC_OS_KEYCHAIN_AUTHENTICATION_INTERACTION)
|
|
109
|
-
}),
|
|
110
|
-
z$1.strictObject({
|
|
111
|
-
schemaVersion: z$1.literal(2),
|
|
112
|
-
operation: z$1.literal("delete"),
|
|
113
|
-
service: macOsKeychainServiceSchema,
|
|
114
|
-
account: macOsKeychainAccountSchema,
|
|
115
|
-
authenticationInteraction: z$1.literal(MAC_OS_KEYCHAIN_AUTHENTICATION_INTERACTION)
|
|
116
|
-
})
|
|
117
|
-
]);
|
|
118
|
-
const macOsKeychainHelperMutationSuccessSchema = z$1.strictObject({
|
|
119
|
-
schemaVersion: z$1.literal(2),
|
|
120
|
-
ok: z$1.literal(true),
|
|
121
|
-
operation: z$1.enum(["store", "delete"])
|
|
122
|
-
});
|
|
123
|
-
const macOsKeychainHelperReadSuccessSchema = z$1.strictObject({
|
|
124
|
-
schemaVersion: z$1.literal(2),
|
|
125
|
-
ok: z$1.literal(true),
|
|
126
|
-
operation: z$1.literal("read"),
|
|
127
|
-
accessToken: z$1.union([macOsKeychainAccessTokenSchema, z$1.null()])
|
|
128
|
-
});
|
|
129
|
-
const macOsKeychainHelperErrorSchema = z$1.strictObject({
|
|
130
|
-
schemaVersion: z$1.literal(2),
|
|
131
|
-
ok: z$1.literal(false),
|
|
132
|
-
operation: macOsKeychainHelperOperationSchema,
|
|
133
|
-
errorMessage: z$1.string().trim().min(1).max(2048)
|
|
134
|
-
});
|
|
135
|
-
const macOsKeychainHelperResponseSchema = z$1.union([
|
|
136
|
-
macOsKeychainHelperMutationSuccessSchema,
|
|
137
|
-
macOsKeychainHelperReadSuccessSchema,
|
|
138
|
-
macOsKeychainHelperErrorSchema
|
|
139
|
-
]);
|
|
140
|
-
//#endregion
|
|
141
88
|
//#region ../../packages/schemas/dist/schemas/prepare/session.js
|
|
142
89
|
const PREPARE_BOUNDED_ID_SCHEMA = string().trim().min(1).max(256);
|
|
143
90
|
const prepareSessionContinuationSchema = strictObject({
|
|
@@ -590,7 +537,7 @@ const prepareSessionEventSchema = strictObject({
|
|
|
590
537
|
localAgentIds: prepareLocalAgentIdsSchema,
|
|
591
538
|
createdAt: PREPARE_ISO_DATE_TIME_SCHEMA
|
|
592
539
|
});
|
|
593
|
-
strictObject({
|
|
540
|
+
const createPrepareSessionRequestSchema = strictObject({
|
|
594
541
|
connectedComputerId: union([PREPARE_BOUNDED_ID_SCHEMA, nullFactory()]).optional(),
|
|
595
542
|
humanProfileId: union([openMeldProfileIdSchema, nullFactory()]).optional(),
|
|
596
543
|
deviceId: union([PREPARE_BOUNDED_ID_SCHEMA, nullFactory()]).optional(),
|
|
@@ -706,6 +653,63 @@ const prepareSessionStreamServerFrameSchema = discriminatedUnion("type", [
|
|
|
706
653
|
})
|
|
707
654
|
]);
|
|
708
655
|
//#endregion
|
|
656
|
+
//#region ../../packages/schemas/dist/schemas/local-machine/macos-keychain-helper.js
|
|
657
|
+
const MAC_OS_KEYCHAIN_AUTHENTICATION_INTERACTION = "disallow";
|
|
658
|
+
const macOsKeychainServiceSchema = z$1.string().trim().min(1).max(512);
|
|
659
|
+
const macOsKeychainAccountSchema = z$1.string().trim().min(1).max(512);
|
|
660
|
+
const macOsKeychainAccessTokenSchema = z$1.string().min(1).max(65536);
|
|
661
|
+
const macOsKeychainHelperOperationSchema = z$1.enum([
|
|
662
|
+
"store",
|
|
663
|
+
"read",
|
|
664
|
+
"delete"
|
|
665
|
+
]);
|
|
666
|
+
const macOsKeychainHelperRequestSchema = z$1.discriminatedUnion("operation", [
|
|
667
|
+
z$1.strictObject({
|
|
668
|
+
schemaVersion: z$1.literal(2),
|
|
669
|
+
operation: z$1.literal("store"),
|
|
670
|
+
service: macOsKeychainServiceSchema,
|
|
671
|
+
account: macOsKeychainAccountSchema,
|
|
672
|
+
accessToken: macOsKeychainAccessTokenSchema,
|
|
673
|
+
authenticationInteraction: z$1.literal(MAC_OS_KEYCHAIN_AUTHENTICATION_INTERACTION)
|
|
674
|
+
}),
|
|
675
|
+
z$1.strictObject({
|
|
676
|
+
schemaVersion: z$1.literal(2),
|
|
677
|
+
operation: z$1.literal("read"),
|
|
678
|
+
service: macOsKeychainServiceSchema,
|
|
679
|
+
account: macOsKeychainAccountSchema,
|
|
680
|
+
authenticationInteraction: z$1.literal(MAC_OS_KEYCHAIN_AUTHENTICATION_INTERACTION)
|
|
681
|
+
}),
|
|
682
|
+
z$1.strictObject({
|
|
683
|
+
schemaVersion: z$1.literal(2),
|
|
684
|
+
operation: z$1.literal("delete"),
|
|
685
|
+
service: macOsKeychainServiceSchema,
|
|
686
|
+
account: macOsKeychainAccountSchema,
|
|
687
|
+
authenticationInteraction: z$1.literal(MAC_OS_KEYCHAIN_AUTHENTICATION_INTERACTION)
|
|
688
|
+
})
|
|
689
|
+
]);
|
|
690
|
+
const macOsKeychainHelperMutationSuccessSchema = z$1.strictObject({
|
|
691
|
+
schemaVersion: z$1.literal(2),
|
|
692
|
+
ok: z$1.literal(true),
|
|
693
|
+
operation: z$1.enum(["store", "delete"])
|
|
694
|
+
});
|
|
695
|
+
const macOsKeychainHelperReadSuccessSchema = z$1.strictObject({
|
|
696
|
+
schemaVersion: z$1.literal(2),
|
|
697
|
+
ok: z$1.literal(true),
|
|
698
|
+
operation: z$1.literal("read"),
|
|
699
|
+
accessToken: z$1.union([macOsKeychainAccessTokenSchema, z$1.null()])
|
|
700
|
+
});
|
|
701
|
+
const macOsKeychainHelperErrorSchema = z$1.strictObject({
|
|
702
|
+
schemaVersion: z$1.literal(2),
|
|
703
|
+
ok: z$1.literal(false),
|
|
704
|
+
operation: macOsKeychainHelperOperationSchema,
|
|
705
|
+
errorMessage: z$1.string().trim().min(1).max(2048)
|
|
706
|
+
});
|
|
707
|
+
const macOsKeychainHelperResponseSchema = z$1.union([
|
|
708
|
+
macOsKeychainHelperMutationSuccessSchema,
|
|
709
|
+
macOsKeychainHelperReadSuccessSchema,
|
|
710
|
+
macOsKeychainHelperErrorSchema
|
|
711
|
+
]);
|
|
712
|
+
//#endregion
|
|
709
713
|
//#region src/strategy-constants.ts
|
|
710
714
|
const DEFAULT_GATEWAY_CHAIN_TIMEOUT_MS = 3e4;
|
|
711
715
|
const DEFAULT_REMOTE_SESSION_TIMEOUT_MS = 8e3;
|
|
@@ -791,19 +795,111 @@ async function acquireAuthSessionLock(input) {
|
|
|
791
795
|
}
|
|
792
796
|
}
|
|
793
797
|
//#endregion
|
|
794
|
-
//#region src/
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
798
|
+
//#region src/config/service-account-admission.ts
|
|
799
|
+
var ServiceAccountAdmissionError = class extends Error {
|
|
800
|
+
code;
|
|
801
|
+
constructor(reason, message) {
|
|
802
|
+
super(message);
|
|
803
|
+
this.name = "ServiceAccountAdmissionError";
|
|
804
|
+
this.code = `service.account_admission.${reason}`;
|
|
805
|
+
}
|
|
806
|
+
};
|
|
807
|
+
function admissionPath() {
|
|
808
|
+
return join(openMeldRootDir(), "auth", "service-account-admission.json");
|
|
809
|
+
}
|
|
810
|
+
async function readServiceAccountAdmission() {
|
|
811
|
+
let raw;
|
|
812
|
+
try {
|
|
813
|
+
raw = await readFile(admissionPath(), "utf8");
|
|
814
|
+
} catch (error) {
|
|
815
|
+
if (error.code === "ENOENT") return null;
|
|
816
|
+
throw error;
|
|
817
|
+
}
|
|
818
|
+
let value;
|
|
819
|
+
try {
|
|
820
|
+
value = JSON.parse(raw);
|
|
821
|
+
} catch {
|
|
822
|
+
value = null;
|
|
823
|
+
}
|
|
824
|
+
const parsed = serviceAccountAdmissionSchema.safeParse(value);
|
|
825
|
+
if (!parsed.success) throw new ServiceAccountAdmissionError("unknown", "OpenMeld could not verify the pending Service action. Run `openmeld service status --json` for diagnostics.");
|
|
826
|
+
return parsed.data;
|
|
827
|
+
}
|
|
828
|
+
async function writeAdmission(value) {
|
|
829
|
+
await writeDaemonLocalStateFile({
|
|
830
|
+
path: admissionPath(),
|
|
831
|
+
schema: serviceAccountAdmissionSchema,
|
|
832
|
+
value,
|
|
833
|
+
mode: 384
|
|
834
|
+
});
|
|
835
|
+
}
|
|
836
|
+
async function assertServiceAccountAdmissionMutationAvailable() {
|
|
837
|
+
const current = await readServiceAccountAdmission();
|
|
838
|
+
if (current?.state !== "pending") return;
|
|
839
|
+
if (isProcessIdentityAlive(current.requester)) throw new ServiceAccountAdmissionError("busy", "OpenMeld is starting or stopping this Service. Try the account change again when that action is accepted.");
|
|
840
|
+
await writeAdmission({
|
|
841
|
+
...current,
|
|
842
|
+
state: "cancelled"
|
|
843
|
+
});
|
|
844
|
+
}
|
|
845
|
+
async function reserveServiceAccountAdmission(input) {
|
|
846
|
+
await assertServiceAccountAdmissionMutationAvailable();
|
|
847
|
+
const previous = await readServiceAccountAdmission();
|
|
848
|
+
if (!CURRENT_PROCESS_START_IDENTITY.startsWith("ps:")) throw new ServiceAccountAdmissionError("unknown", "OpenMeld could not verify this command's process identity. Try again from a supported local CLI.");
|
|
849
|
+
const reservation = {
|
|
850
|
+
version: 1,
|
|
851
|
+
id: randomUUID(),
|
|
852
|
+
operation: input.operation,
|
|
853
|
+
state: "pending",
|
|
854
|
+
identity: input.identity,
|
|
855
|
+
...input.target ? { target: input.target } : {},
|
|
856
|
+
requester: {
|
|
857
|
+
ownerPid: process.pid,
|
|
858
|
+
ownerProcessStartedAt: CURRENT_PROCESS_START_IDENTITY
|
|
859
|
+
},
|
|
860
|
+
...previous?.startupReceipt ? { startupReceipt: previous.startupReceipt } : {}
|
|
861
|
+
};
|
|
862
|
+
await writeAdmission(reservation);
|
|
863
|
+
return reservation;
|
|
864
|
+
}
|
|
865
|
+
async function cancelServiceAccountAdmission(id) {
|
|
866
|
+
await withAuthSessionTransitionMutationLock(async () => {
|
|
867
|
+
const current = await readServiceAccountAdmission();
|
|
868
|
+
if (current?.id === id && current.state === "pending") await writeAdmission({
|
|
869
|
+
...current,
|
|
870
|
+
state: "cancelled"
|
|
871
|
+
});
|
|
872
|
+
});
|
|
873
|
+
}
|
|
874
|
+
async function admitServiceAccountOperation(input) {
|
|
875
|
+
const current = await readServiceAccountAdmission();
|
|
876
|
+
const contractBinding = bindServiceAccountIdentity(input.identity);
|
|
877
|
+
if (input.operation === "start" && current?.startupReceipt?.id === input.id && current.startupReceipt.contractBinding === contractBinding) return;
|
|
878
|
+
if (!current || current.id !== input.id || current.operation !== input.operation || current.state !== "pending" || readProcessStartIdentity(current.requester.ownerPid) !== current.requester.ownerProcessStartedAt || current.target !== void 0 && (current.target.ownerPid !== process.pid || current.target.ownerProcessStartedAt !== CURRENT_PROCESS_START_IDENTITY) || JSON.stringify(current.identity) !== JSON.stringify(input.identity)) throw new ServiceAccountAdmissionError("cancelled", "This Service action is no longer authorized. Check the signed-in account and try again.");
|
|
879
|
+
input.commit?.();
|
|
880
|
+
await writeAdmission({
|
|
881
|
+
...current,
|
|
882
|
+
state: "admitted",
|
|
883
|
+
carrier: {
|
|
884
|
+
ownerPid: process.pid,
|
|
885
|
+
ownerProcessStartedAt: CURRENT_PROCESS_START_IDENTITY
|
|
886
|
+
},
|
|
887
|
+
...input.operation === "start" ? { startupReceipt: {
|
|
888
|
+
id: input.id,
|
|
889
|
+
contractBinding
|
|
890
|
+
} } : {}
|
|
891
|
+
});
|
|
892
|
+
}
|
|
893
|
+
function bindServiceAccountIdentity(identity) {
|
|
894
|
+
return createHash("sha256").update(JSON.stringify([
|
|
895
|
+
identity.accountId,
|
|
896
|
+
identity.authBaseUrl,
|
|
897
|
+
identity.clientId,
|
|
898
|
+
identity.gatewayUrl,
|
|
899
|
+
identity.lane,
|
|
900
|
+
identity.deviceId,
|
|
901
|
+
identity.contractGeneration
|
|
902
|
+
])).digest("hex");
|
|
807
903
|
}
|
|
808
904
|
//#endregion
|
|
809
905
|
//#region src/config/macos-native-keychain.ts
|
|
@@ -816,6 +912,9 @@ let unresponsiveKeychainError = null;
|
|
|
816
912
|
let keychainRetryAt = 0;
|
|
817
913
|
let lastKeychainFailureCode = null;
|
|
818
914
|
const MAC_OS_KEYCHAIN_RETRY_DELAY_MS = 3e4;
|
|
915
|
+
function getMacOsKeychainRetryAfterMs() {
|
|
916
|
+
return Math.max(0, keychainRetryAt - Date.now());
|
|
917
|
+
}
|
|
819
918
|
async function storeMacOsNativeKeychainToken(input) {
|
|
820
919
|
if (isBinaryDistribution()) {
|
|
821
920
|
await runBoundedMacOsNativeKeychainRequest({
|
|
@@ -1172,6 +1271,7 @@ async function readAccessToken(ref) {
|
|
|
1172
1271
|
} catch (error) {
|
|
1173
1272
|
return {
|
|
1174
1273
|
errorMessage: toErrorMessage$1(error),
|
|
1274
|
+
...ref.provider === "macos-keychain" ? { retryAfterMs: getMacOsKeychainRetryAfterMs() } : {},
|
|
1175
1275
|
status: "unavailable"
|
|
1176
1276
|
};
|
|
1177
1277
|
}
|
|
@@ -1447,13 +1547,128 @@ var AuthSessionTransitionConflictError = class extends Error {
|
|
|
1447
1547
|
};
|
|
1448
1548
|
const TRAILING_SLASHES_RE = /\/+$/u;
|
|
1449
1549
|
let cachedAuthSession = null;
|
|
1550
|
+
const pendingCredentialReads = /* @__PURE__ */ new Map();
|
|
1551
|
+
const credentialAvailabilityListeners = /* @__PURE__ */ new Set();
|
|
1552
|
+
function onAuthSessionCredentialAvailable(notify) {
|
|
1553
|
+
const listener = {
|
|
1554
|
+
path: authSessionPath(),
|
|
1555
|
+
notify
|
|
1556
|
+
};
|
|
1557
|
+
credentialAvailabilityListeners.add(listener);
|
|
1558
|
+
return () => {
|
|
1559
|
+
credentialAvailabilityListeners.delete(listener);
|
|
1560
|
+
};
|
|
1561
|
+
}
|
|
1450
1562
|
const activeAuthSessionTransitionIds = /* @__PURE__ */ new Set();
|
|
1563
|
+
const admittedServiceSession = new AsyncLocalStorage();
|
|
1564
|
+
const boundSessionPayloadKeys = /* @__PURE__ */ new WeakMap();
|
|
1565
|
+
function withAdmittedServiceSession(session, run) {
|
|
1566
|
+
return admittedServiceSession.run(structuredClone(session), run);
|
|
1567
|
+
}
|
|
1568
|
+
async function readServiceAdmissionSessionWithOwnership() {
|
|
1569
|
+
if (await readAuthSessionTransitionJournal()) throw new AuthSessionRecoveryInProgressError();
|
|
1570
|
+
const state = await getLocalAuthSessionState({ recover: false });
|
|
1571
|
+
if (state.state !== "valid" || !state.session?.user?.id) throw new Error("Service control requires a valid CLI sign-in. Sign in with the matching account and try again.");
|
|
1572
|
+
return state.session;
|
|
1573
|
+
}
|
|
1574
|
+
const credentialObservationListeners = /* @__PURE__ */ new Set();
|
|
1575
|
+
function onAuthSessionCredentialObservation(notify) {
|
|
1576
|
+
const listener = {
|
|
1577
|
+
path: authSessionPath(),
|
|
1578
|
+
notify
|
|
1579
|
+
};
|
|
1580
|
+
credentialObservationListeners.add(listener);
|
|
1581
|
+
return () => {
|
|
1582
|
+
credentialObservationListeners.delete(listener);
|
|
1583
|
+
};
|
|
1584
|
+
}
|
|
1585
|
+
function observeCredential(reason) {
|
|
1586
|
+
const path = authSessionPath();
|
|
1587
|
+
for (const listener of credentialObservationListeners) if (listener.path === path) try {
|
|
1588
|
+
listener.notify(reason);
|
|
1589
|
+
} catch {}
|
|
1590
|
+
}
|
|
1451
1591
|
async function getAuthSessionState(options = {}) {
|
|
1452
|
-
|
|
1592
|
+
const bound = admittedServiceSession.getStore();
|
|
1593
|
+
if (bound) return await getBoundServiceSessionState(bound, options);
|
|
1594
|
+
const result = await getAuthSessionStateWithCandidateRefreshFence(options, false);
|
|
1595
|
+
if (result.reasonCode === "session_metadata_invalid") observeCredential("metadata_unavailable");
|
|
1596
|
+
return {
|
|
1597
|
+
state: result.state,
|
|
1598
|
+
session: result.session,
|
|
1599
|
+
...result.reasonCode ? { reasonCode: result.reasonCode } : {},
|
|
1600
|
+
...result.errorMessage ? { errorMessage: result.errorMessage } : {},
|
|
1601
|
+
...result.retryAfterMs !== void 0 ? { retryAfterMs: result.retryAfterMs } : {}
|
|
1602
|
+
};
|
|
1603
|
+
}
|
|
1604
|
+
async function syncBoundServiceCredentials(bound) {
|
|
1605
|
+
const local = await getLocalAuthSessionState({ recover: false });
|
|
1606
|
+
const samePrincipal = isSameAuthPrincipal(local.session, bound);
|
|
1607
|
+
const localPayloadKey = samePrincipal && "payloadKey" in local ? local.payloadKey : null;
|
|
1608
|
+
if (samePrincipal && local.session && boundSessionPayloadKeys.get(bound) !== localPayloadKey) {
|
|
1609
|
+
Object.assign(bound, local.session, { activeOrganization: local.session.activeOrganization });
|
|
1610
|
+
boundSessionPayloadKeys.set(bound, localPayloadKey);
|
|
1611
|
+
}
|
|
1612
|
+
if (samePrincipal && local.session && bound.expiresAt && (bound.accessToken !== local.session.accessToken || bound.expiresAt !== local.session.expiresAt)) await persistBoundServiceRefresh(bound, {
|
|
1613
|
+
state: "valid",
|
|
1614
|
+
accessToken: bound.accessToken,
|
|
1615
|
+
expiresAt: bound.expiresAt
|
|
1616
|
+
}, localPayloadKey, local.session.accessToken);
|
|
1617
|
+
return samePrincipal ? boundSessionPayloadKeys.get(bound) ?? null : null;
|
|
1618
|
+
}
|
|
1619
|
+
async function getBoundServiceSessionState(bound, options) {
|
|
1620
|
+
const localPayloadKey = await syncBoundServiceCredentials(bound);
|
|
1621
|
+
if (options.validateRemote || options.refreshExpired && isExpired(bound.expiresAt)) {
|
|
1622
|
+
const remote = await getRemoteAuthSessionState(bound);
|
|
1623
|
+
if (remote.state === "revoked" || remote.state === "invalid") return {
|
|
1624
|
+
state: remote.state,
|
|
1625
|
+
session: null,
|
|
1626
|
+
reasonCode: resolveRemoteAuthSessionReasonCode(remote.state)
|
|
1627
|
+
};
|
|
1628
|
+
if (remote.state === "valid") {
|
|
1629
|
+
await persistBoundServiceRefresh(bound, remote, localPayloadKey);
|
|
1630
|
+
if (remote.accessToken) bound.accessToken = remote.accessToken;
|
|
1631
|
+
if (remote.expiresAt) bound.expiresAt = remote.expiresAt;
|
|
1632
|
+
}
|
|
1633
|
+
}
|
|
1634
|
+
const expiry = resolveAuthSessionExpiryEligibility(bound.expiresAt);
|
|
1635
|
+
if (expiry.status === "expired") return {
|
|
1636
|
+
session: bound,
|
|
1637
|
+
state: "expired",
|
|
1638
|
+
reasonCode: "session_expired"
|
|
1639
|
+
};
|
|
1640
|
+
if (expiry.status === "invalid") return {
|
|
1641
|
+
session: null,
|
|
1642
|
+
state: "invalid",
|
|
1643
|
+
reasonCode: "session_expiry_invalid"
|
|
1644
|
+
};
|
|
1645
|
+
return {
|
|
1646
|
+
session: bound,
|
|
1647
|
+
state: "valid"
|
|
1648
|
+
};
|
|
1649
|
+
}
|
|
1650
|
+
async function persistBoundServiceRefresh(bound, remote, localPayloadKey, previousAccessToken = bound.accessToken) {
|
|
1651
|
+
if (!(localPayloadKey && remote.expiresAt) || isExpired(remote.expiresAt)) return;
|
|
1652
|
+
try {
|
|
1653
|
+
if (await persistRemoteSessionRefresh({
|
|
1654
|
+
accessToken: remote.accessToken ?? bound.accessToken,
|
|
1655
|
+
previousAccessToken,
|
|
1656
|
+
expectedPayloadKey: localPayloadKey,
|
|
1657
|
+
expiresAt: remote.expiresAt
|
|
1658
|
+
})) {
|
|
1659
|
+
const current = await getLocalAuthSessionState({ recover: false });
|
|
1660
|
+
boundSessionPayloadKeys.set(bound, isSameAuthPrincipal(current.session, bound) && "payloadKey" in current ? current.payloadKey : null);
|
|
1661
|
+
}
|
|
1662
|
+
} catch (error) {
|
|
1663
|
+
if (!(error instanceof ServiceAccountAdmissionError && error.code === "service.account_admission.busy")) throw error;
|
|
1664
|
+
}
|
|
1665
|
+
}
|
|
1666
|
+
function isSameAuthPrincipal(current, expected) {
|
|
1667
|
+
return Boolean(expected.user?.id && current?.user?.id === expected.user.id && current.authBaseUrl === expected.authBaseUrl && current.clientId === expected.clientId);
|
|
1453
1668
|
}
|
|
1454
1669
|
async function getAuthSessionStateWithCandidateRefreshFence(options, candidateRefreshFenceHeld) {
|
|
1455
1670
|
const localState = await getLocalAuthSessionState();
|
|
1456
|
-
const localPayloadKey =
|
|
1671
|
+
const localPayloadKey = "payloadKey" in localState ? localState.payloadKey : null;
|
|
1457
1672
|
const shouldValidateRemote = options.validateRemote === true || options.refreshExpired === true && localState.state === "expired";
|
|
1458
1673
|
switch (localState.state) {
|
|
1459
1674
|
case "missing":
|
|
@@ -1970,6 +2185,11 @@ async function completeInterruptedComputerAuthSessionRecovery(id) {
|
|
|
1970
2185
|
});
|
|
1971
2186
|
}
|
|
1972
2187
|
async function getAuthSessionMetadata() {
|
|
2188
|
+
const bound = admittedServiceSession.getStore();
|
|
2189
|
+
if (bound) {
|
|
2190
|
+
await getBoundServiceSessionState(bound, {});
|
|
2191
|
+
return buildAuthSessionMetadata(bound);
|
|
2192
|
+
}
|
|
1973
2193
|
return buildAuthSessionMetadata(await readSessionPayload());
|
|
1974
2194
|
}
|
|
1975
2195
|
function buildAuthSessionMetadata(payload) {
|
|
@@ -2049,6 +2269,12 @@ async function assertAuthSessionMutationAvailable() {
|
|
|
2049
2269
|
await withAuthSessionTransitionMutationLock(assertAuthSessionMutationAvailableWithOwnership);
|
|
2050
2270
|
}
|
|
2051
2271
|
async function assertAuthSessionMutationAvailableWithOwnership() {
|
|
2272
|
+
await assertServiceAccountAdmissionMutationAvailable();
|
|
2273
|
+
const bound = admittedServiceSession.getStore();
|
|
2274
|
+
if (bound) {
|
|
2275
|
+
const current = await readSessionPayloadFile();
|
|
2276
|
+
if (current?.user?.id !== bound.user?.id || current?.authBaseUrl !== bound.authBaseUrl || current?.clientId !== bound.clientId) throw new AuthSessionChangedBeforeTransitionError();
|
|
2277
|
+
}
|
|
2052
2278
|
await recoverInterruptedAuthSessionTransitionWithOwnership();
|
|
2053
2279
|
if (await readAuthSessionTransitionJournal()) throw new AuthSessionRecoveryInProgressError();
|
|
2054
2280
|
}
|
|
@@ -2124,65 +2350,59 @@ async function getLocalAuthSessionState(options = {}) {
|
|
|
2124
2350
|
try {
|
|
2125
2351
|
payload = options.recover === false ? await readSessionPayloadFile() : await readSessionPayload();
|
|
2126
2352
|
} catch (error) {
|
|
2127
|
-
if (error instanceof AuthSessionStorageError)
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2353
|
+
if (error instanceof AuthSessionStorageError) {
|
|
2354
|
+
cachedAuthSession = null;
|
|
2355
|
+
return {
|
|
2356
|
+
errorMessage: error.message,
|
|
2357
|
+
reasonCode: "session_metadata_invalid",
|
|
2358
|
+
state: "invalid",
|
|
2359
|
+
session: null
|
|
2360
|
+
};
|
|
2361
|
+
}
|
|
2362
|
+
throw error;
|
|
2363
|
+
}
|
|
2364
|
+
if (payload?.v !== 1) {
|
|
2365
|
+
cachedAuthSession = null;
|
|
2366
|
+
return {
|
|
2367
|
+
reasonCode: "session_missing",
|
|
2368
|
+
state: "missing",
|
|
2131
2369
|
session: null
|
|
2132
2370
|
};
|
|
2133
|
-
throw error;
|
|
2134
2371
|
}
|
|
2135
|
-
if (payload?.v !== 1) return {
|
|
2136
|
-
reasonCode: "session_missing",
|
|
2137
|
-
state: "missing",
|
|
2138
|
-
session: null
|
|
2139
|
-
};
|
|
2140
2372
|
const tokenRef = normalizeTokenRef(payload.tokenRef);
|
|
2141
|
-
if (!tokenRef)
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2373
|
+
if (!tokenRef) {
|
|
2374
|
+
cachedAuthSession = null;
|
|
2375
|
+
return {
|
|
2376
|
+
reasonCode: "session_token_ref_invalid",
|
|
2377
|
+
state: "invalid",
|
|
2378
|
+
session: null
|
|
2379
|
+
};
|
|
2380
|
+
}
|
|
2146
2381
|
const tokenType = normalizeOptionalString(payload.tokenType);
|
|
2147
2382
|
const authBaseUrl = normalizeOptionalString(payload.authBaseUrl);
|
|
2148
2383
|
const clientId = normalizeOptionalString(payload.clientId);
|
|
2149
2384
|
const createdAt = normalizeOptionalString(payload.createdAt);
|
|
2150
|
-
if (!(tokenType && authBaseUrl && clientId && createdAt))
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
};
|
|
2155
|
-
let session = readCachedAuthSession(payload);
|
|
2156
|
-
if (!session) {
|
|
2157
|
-
const accessToken = await readAccessToken(tokenRef);
|
|
2158
|
-
if (accessToken.status === "missing") return {
|
|
2159
|
-
reasonCode: "session_token_missing",
|
|
2160
|
-
state: "invalid",
|
|
2161
|
-
session: null
|
|
2162
|
-
};
|
|
2163
|
-
if (accessToken.status === "unavailable") return {
|
|
2164
|
-
errorMessage: accessToken.errorMessage,
|
|
2165
|
-
reasonCode: "session_token_unavailable",
|
|
2385
|
+
if (!(tokenType && authBaseUrl && clientId && createdAt)) {
|
|
2386
|
+
cachedAuthSession = null;
|
|
2387
|
+
return {
|
|
2388
|
+
reasonCode: "session_metadata_invalid",
|
|
2166
2389
|
state: "invalid",
|
|
2167
2390
|
session: null
|
|
2168
2391
|
};
|
|
2169
|
-
session = buildStoredAuthSession({
|
|
2170
|
-
accessToken: accessToken.accessToken,
|
|
2171
|
-
payload: {
|
|
2172
|
-
...payload,
|
|
2173
|
-
v: 1,
|
|
2174
|
-
tokenRef,
|
|
2175
|
-
tokenType,
|
|
2176
|
-
authBaseUrl,
|
|
2177
|
-
clientId,
|
|
2178
|
-
createdAt
|
|
2179
|
-
}
|
|
2180
|
-
});
|
|
2181
|
-
cacheAuthSession({
|
|
2182
|
-
payload,
|
|
2183
|
-
session
|
|
2184
|
-
});
|
|
2185
2392
|
}
|
|
2393
|
+
const session = readCachedAuthSession(payload);
|
|
2394
|
+
if (!session) return await loadCurrentSessionCredential({
|
|
2395
|
+
...payload,
|
|
2396
|
+
v: 1,
|
|
2397
|
+
tokenRef,
|
|
2398
|
+
tokenType,
|
|
2399
|
+
authBaseUrl,
|
|
2400
|
+
clientId,
|
|
2401
|
+
createdAt
|
|
2402
|
+
}, options);
|
|
2403
|
+
return resolveLocalStoredSessionState(session, buildAuthSessionPayloadKey(payload));
|
|
2404
|
+
}
|
|
2405
|
+
function resolveLocalStoredSessionState(session, payloadKey) {
|
|
2186
2406
|
const expiryEligibility = resolveAuthSessionExpiryEligibility(session.expiresAt);
|
|
2187
2407
|
if (expiryEligibility.status === "invalid") return {
|
|
2188
2408
|
reasonCode: "session_expiry_invalid",
|
|
@@ -2192,13 +2412,68 @@ async function getLocalAuthSessionState(options = {}) {
|
|
|
2192
2412
|
if (expiryEligibility.status === "expired") return {
|
|
2193
2413
|
reasonCode: "session_expired",
|
|
2194
2414
|
state: "expired",
|
|
2415
|
+
payloadKey,
|
|
2195
2416
|
session
|
|
2196
2417
|
};
|
|
2197
2418
|
return {
|
|
2198
2419
|
state: "valid",
|
|
2420
|
+
payloadKey,
|
|
2199
2421
|
session
|
|
2200
2422
|
};
|
|
2201
2423
|
}
|
|
2424
|
+
async function loadCurrentSessionCredential(payload, options) {
|
|
2425
|
+
const credentialKey = buildAuthSessionCredentialCacheKey(payload);
|
|
2426
|
+
const accessToken = await readSessionCredential(credentialKey, payload.tokenRef);
|
|
2427
|
+
let currentPayload;
|
|
2428
|
+
try {
|
|
2429
|
+
currentPayload = options.recover === false ? await readSessionPayloadFile() : await readSessionPayload();
|
|
2430
|
+
} catch (error) {
|
|
2431
|
+
if (!(error instanceof AuthSessionStorageError)) throw error;
|
|
2432
|
+
cachedAuthSession = null;
|
|
2433
|
+
return {
|
|
2434
|
+
state: "invalid",
|
|
2435
|
+
session: null,
|
|
2436
|
+
reasonCode: "session_metadata_invalid",
|
|
2437
|
+
errorMessage: error.message
|
|
2438
|
+
};
|
|
2439
|
+
}
|
|
2440
|
+
if (!currentPayload || buildAuthSessionCredentialCacheKey(currentPayload) !== credentialKey) {
|
|
2441
|
+
if ((options.reloadCount ?? 0) >= 2) {
|
|
2442
|
+
cachedAuthSession = null;
|
|
2443
|
+
return {
|
|
2444
|
+
state: "invalid",
|
|
2445
|
+
session: null,
|
|
2446
|
+
reasonCode: "session_metadata_invalid",
|
|
2447
|
+
errorMessage: "The local login changed while reading its credentials. Try again."
|
|
2448
|
+
};
|
|
2449
|
+
}
|
|
2450
|
+
return await getLocalAuthSessionState({
|
|
2451
|
+
...options,
|
|
2452
|
+
reloadCount: (options.reloadCount ?? 0) + 1
|
|
2453
|
+
});
|
|
2454
|
+
}
|
|
2455
|
+
if (accessToken.status === "missing") return {
|
|
2456
|
+
reasonCode: "session_token_missing",
|
|
2457
|
+
state: "invalid",
|
|
2458
|
+
session: null
|
|
2459
|
+
};
|
|
2460
|
+
if (accessToken.status === "unavailable") return {
|
|
2461
|
+
errorMessage: accessToken.errorMessage,
|
|
2462
|
+
retryAfterMs: accessToken.retryAfterMs,
|
|
2463
|
+
reasonCode: "session_token_unavailable",
|
|
2464
|
+
state: "invalid",
|
|
2465
|
+
session: null
|
|
2466
|
+
};
|
|
2467
|
+
const session = buildStoredAuthSession({
|
|
2468
|
+
accessToken: accessToken.accessToken,
|
|
2469
|
+
payload: currentPayload
|
|
2470
|
+
});
|
|
2471
|
+
cacheAuthSession({
|
|
2472
|
+
payload: currentPayload,
|
|
2473
|
+
session
|
|
2474
|
+
});
|
|
2475
|
+
return resolveLocalStoredSessionState(session, buildAuthSessionPayloadKey(currentPayload));
|
|
2476
|
+
}
|
|
2202
2477
|
async function assertStoredAccessTokenReloads(input) {
|
|
2203
2478
|
const reloaded = await readAccessToken(input.tokenRef);
|
|
2204
2479
|
if (reloaded.status === "found" && reloaded.accessToken === input.accessToken) return;
|
|
@@ -2243,14 +2518,55 @@ async function cleanupTransitionTokensNotReferencedByCurrentSession(input) {
|
|
|
2243
2518
|
}
|
|
2244
2519
|
}
|
|
2245
2520
|
function cacheAuthSession(input) {
|
|
2521
|
+
const credentialKey = buildAuthSessionCredentialCacheKey(input.payload);
|
|
2522
|
+
const becameAvailable = cachedAuthSession?.credentialKey !== credentialKey;
|
|
2523
|
+
const previous = cachedAuthSession;
|
|
2246
2524
|
cachedAuthSession = {
|
|
2247
|
-
|
|
2525
|
+
credentialKey,
|
|
2248
2526
|
session: input.session
|
|
2249
2527
|
};
|
|
2528
|
+
if (!previous) observeCredential("credential_available");
|
|
2529
|
+
else if (previous.session.user?.id !== input.session.user?.id) observeCredential("account_changed");
|
|
2530
|
+
else if (becameAvailable) observeCredential("credential_changed");
|
|
2531
|
+
else if (JSON.stringify([previous.session.activeOrganization, previous.session.user]) !== JSON.stringify([input.session.activeOrganization, input.session.user])) observeCredential("context_changed");
|
|
2532
|
+
if (becameAvailable) {
|
|
2533
|
+
const path = authSessionPath();
|
|
2534
|
+
for (const listener of credentialAvailabilityListeners) if (listener.path === path) listener.notify();
|
|
2535
|
+
}
|
|
2250
2536
|
}
|
|
2251
2537
|
function readCachedAuthSession(payload) {
|
|
2252
|
-
|
|
2253
|
-
|
|
2538
|
+
if (cachedAuthSession?.credentialKey !== buildAuthSessionCredentialCacheKey(payload)) return null;
|
|
2539
|
+
const session = buildStoredAuthSession({
|
|
2540
|
+
accessToken: cachedAuthSession.session.accessToken,
|
|
2541
|
+
payload
|
|
2542
|
+
});
|
|
2543
|
+
cacheAuthSession({
|
|
2544
|
+
payload,
|
|
2545
|
+
session
|
|
2546
|
+
});
|
|
2547
|
+
return session;
|
|
2548
|
+
}
|
|
2549
|
+
function buildAuthSessionCredentialCacheKey(payload) {
|
|
2550
|
+
return `${authSessionPath()}\n${JSON.stringify({
|
|
2551
|
+
v: payload.v,
|
|
2552
|
+
tokenRef: payload.tokenRef,
|
|
2553
|
+
tokenType: payload.tokenType,
|
|
2554
|
+
authBaseUrl: payload.authBaseUrl,
|
|
2555
|
+
clientId: payload.clientId,
|
|
2556
|
+
createdAt: payload.createdAt,
|
|
2557
|
+
expiresAt: payload.expiresAt,
|
|
2558
|
+
scope: payload.scope,
|
|
2559
|
+
ownerUserId: payload.user?.id
|
|
2560
|
+
})}`;
|
|
2561
|
+
}
|
|
2562
|
+
async function readSessionCredential(key, ref) {
|
|
2563
|
+
const pending = pendingCredentialReads.get(key);
|
|
2564
|
+
if (pending) return await pending;
|
|
2565
|
+
const read = readAccessToken(ref).finally(() => {
|
|
2566
|
+
if (pendingCredentialReads.get(key) === read) pendingCredentialReads.delete(key);
|
|
2567
|
+
});
|
|
2568
|
+
pendingCredentialReads.set(key, read);
|
|
2569
|
+
return await read;
|
|
2254
2570
|
}
|
|
2255
2571
|
function buildAuthSessionPayloadKey(payload) {
|
|
2256
2572
|
return `${authSessionPath()}\n${JSON.stringify(payload)}`;
|
|
@@ -2274,6 +2590,11 @@ async function cleanupCandidateTokenRefs(journal, keepTokenRef) {
|
|
|
2274
2590
|
}
|
|
2275
2591
|
async function persistRemoteSessionRefresh(input) {
|
|
2276
2592
|
return await withAuthSessionTransitionMutationLock(async () => {
|
|
2593
|
+
const bound = admittedServiceSession.getStore();
|
|
2594
|
+
if (bound) {
|
|
2595
|
+
if (!isSameAuthPrincipal((await getLocalAuthSessionState({ recover: false })).session, bound)) return null;
|
|
2596
|
+
}
|
|
2597
|
+
await assertServiceAccountAdmissionMutationAvailable();
|
|
2277
2598
|
await recoverInterruptedAuthSessionTransitionWithOwnership();
|
|
2278
2599
|
const transitionJournal = await readAuthSessionTransitionJournal();
|
|
2279
2600
|
if (transitionJournal) {
|
|
@@ -2292,7 +2613,7 @@ async function persistCommittedRemoteSessionRefresh(input) {
|
|
|
2292
2613
|
const refresh = await prepareRemoteSessionRefresh({
|
|
2293
2614
|
...input,
|
|
2294
2615
|
payload,
|
|
2295
|
-
uniqueTokenRef:
|
|
2616
|
+
uniqueTokenRef: true
|
|
2296
2617
|
});
|
|
2297
2618
|
if (!refresh) return null;
|
|
2298
2619
|
try {
|
|
@@ -2501,6 +2822,7 @@ async function recoverInterruptedAuthSessionTransition() {
|
|
|
2501
2822
|
async function recoverInterruptedAuthSessionTransitionWithOwnership() {
|
|
2502
2823
|
let journal = await readAuthSessionTransitionJournal();
|
|
2503
2824
|
if (!journal) return;
|
|
2825
|
+
await assertServiceAccountAdmissionMutationAvailable();
|
|
2504
2826
|
if (activeAuthSessionTransitionIds.has(journal.id)) return;
|
|
2505
2827
|
if (journal.state === "pending" && isProcessIdentityAlive({
|
|
2506
2828
|
ownerPid: journal.ownerPid,
|
|
@@ -2873,6 +3195,6 @@ async function removeSessionFile() {
|
|
|
2873
3195
|
await rm(authSessionPath(), { force: true });
|
|
2874
3196
|
}
|
|
2875
3197
|
//#endregion
|
|
2876
|
-
export {
|
|
3198
|
+
export { RUNTIME_STATE_PERSIST_MIN_INTERVAL_MS as $, withAuthSessionTransitionMutationLock as A, DEFAULT_SPACE_REQUEST_TIMEOUT_MS as B, withAdmittedServiceSession as C, cancelServiceAccountAdmission as D, admitServiceAccountOperation as E, DAEMON_STREAM_CONNECT_TIMEOUT_MS as F, MIN_SPACE_REQUEST_TIMEOUT_MS as G, MAX_HEARTBEAT_INTERVAL_MS as H, DAEMON_STREAM_KEEPALIVE_INTERVAL_MS as I, PROVIDER_CONVERSATION_PROOF_SYNC_RETRY_INTERVAL_MS as J, OPENCLAW_CLI_TIMEOUT_MS as K, DAEMON_STREAM_KEEPALIVE_PONG_TIMEOUT_MS as L, CATALOG_SYNC_RETRY_INTERVAL_MS as M, CATALOG_SYNC_SIGNAL_POLL_INTERVAL_MS as N, readServiceAccountAdmission as O, DAEMON_RUNTIME_CONTRACT_EPOCH as P, RUNTIME_AGENT_CONTROLLER_REPORT_SYNC_RETRY_INTERVAL_MS as Q, DEFAULT_GATEWAY_CHAIN_TIMEOUT_MS as R, updateAuthSessionActiveOrganization as S, ServiceAccountAdmissionError as T, MAX_SPACE_REQUEST_TIMEOUT_MS as U, HEARTBEAT_RESPONSE_TIMEOUT_MS as V, MIN_HEARTBEAT_INTERVAL_MS as W, ROUTE_CATALOG_LOAD_TIMEOUT_MS as X, REGISTER_RESPONSE_TIMEOUT_MS as Y, RUNTIME_AGENT_CONTROLLER_REPORT_SYNC_INTERVAL_MS as Z, onAuthSessionCredentialObservation as _, beginAuthSessionTransition as a, prepareSessionWithTokenResponseSchema as at, resumeInterruptedComputerSetup as b, completeInterruptedComputerAuthSessionRecovery as c, redactPrepareStepDiagnosticsBundle as ct, getCurrentAuthOwnerUserId as d, PREPARE_STEP_DIAGNOSTICS_MAX_CHARS as et, getInterruptedComputerAuthSessionRecovery as f, onAuthSessionCredentialAvailable as g, normalizeStoredActiveOrganization as h, assertAuthSessionMutationAvailable as i, prepareSessionStreamServerFrameSchema as it, resolveAuthSessionExpiryEligibility as j, reserveServiceAccountAdmission as k, getAuthSessionMetadata as l, redactPrepareStepDiagnosticsText as lt, markInterruptedComputerAuthSessionRecovery as m, AuthSessionRecoveryInProgressError as n, prepareSessionResponseSchema as nt, buildStoredAuthSessionIdentity as o, prepareSetupBootstrapWriteSchema as ot, hasPendingComputerSetupContinuation as p, PROVIDER_CONVERSATION_PROOF_SYNC_INTERVAL_MS as q, AuthSessionTransitionConflictError as r, prepareSessionSnapshotSchema as rt, clearAuthSession as s, prepareStepDiagnosticsBundleSchema as st, AuthSessionChangedBeforeTransitionError as t, createPrepareSessionRequestSchema as tt, getAuthSessionState as u, redactPrepareStepDiagnosticsValue as ut, readServiceAdmissionSessionWithOwnership as v, runMacOsNativeKeychainHelperIfRequested as w, setAuthSession as x, recordInterruptedComputerAuthSessionRecoveryFailure as y, DEFAULT_HEARTBEAT_INTERVAL_MS as z };
|
|
2877
3199
|
|
|
2878
|
-
//# sourceMappingURL=auth-session-
|
|
3200
|
+
//# sourceMappingURL=auth-session-CO5XtFaq.js.map
|