@ekanos/harness 0.25.0 → 0.26.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/README.md +3 -4
- package/dist/api-types.d.ts +98 -0
- package/dist/internal/components/approvals-tray.js +1 -1
- package/dist/internal/components/ask-assistant-bridge.js +2 -8
- package/dist/internal/components/connect-panel.js +414 -20
- package/dist/internal/components/dev-toolbar.js +3 -3
- package/dist/internal/components/docs-link.js +1 -1
- package/dist/internal/components/integration-badge.js +2 -2
- package/dist/internal/components/local-oauth-panel.js +28 -2
- package/dist/internal/components/provenance-banner.js +2 -2
- package/dist/internal/components/surface-nav.js +16 -16
- package/dist/internal/components/widget-boundary.js +1 -7
- package/dist/internal/lib/console-client.d.ts +22 -5
- package/dist/internal/lib/console-client.js +32 -6
- package/dist/internal/lib/console-context.js +14 -2
- package/dist/internal/lib/console-types.d.ts +11 -1
- package/dist/internal/lib/experience-runtime.d.ts +20 -0
- package/dist/internal/lib/experience-runtime.js +16 -1
- package/dist/internal/lib/oauth-connect-href.d.ts +9 -0
- package/dist/internal/lib/oauth-connect-href.js +14 -0
- package/dist/internal/lib/run-log-view.js +1 -0
- package/dist/internal/lib/trigger-contract.d.ts +19 -0
- package/dist/internal/lib/trigger-runner.js +4 -1
- package/dist/internal/routes/experience-page-host.d.ts +5 -1
- package/dist/internal/routes/experience-page-host.js +8 -7
- package/dist/internal/routes/repo-home-page.js +1 -1
- package/dist/internal/routes/repo-layout.js +2 -4
- package/dist/internal/routes/root-layout.d.ts +0 -1
- package/dist/internal/routes/root-layout.js +2 -4
- package/dist/internal/routes/tile-page.js +1 -1
- package/dist/internal/routes/triggers-page.js +30 -2
- package/dist/internal/server/activation-credentials.d.ts +26 -0
- package/dist/internal/server/activation-credentials.js +56 -0
- package/dist/internal/server/api-router.js +63 -5
- package/dist/internal/server/console-state.d.ts +25 -0
- package/dist/internal/server/console-state.js +44 -0
- package/dist/internal/server/ekanos-api-router.js +168 -4
- package/dist/internal/server/live-context.js +2 -1
- package/dist/internal/server/live-invoker.js +10 -2
- package/dist/internal/server/local-secrets.d.ts +47 -0
- package/dist/internal/server/local-secrets.js +111 -2
- package/dist/internal/server/local-state.d.ts +8 -2
- package/dist/internal/server/local-state.js +26 -9
- package/dist/internal/server/nonce-store.d.ts +2 -0
- package/dist/internal/server/oauth-connections.d.ts +45 -0
- package/dist/internal/server/oauth-connections.js +69 -0
- package/dist/internal/server/oauth-loop.d.ts +1 -1
- package/dist/internal/server/oauth-loop.js +4 -1
- package/dist/internal/server/oauth-persistence.d.ts +13 -0
- package/dist/internal/server/oauth-persistence.js +28 -0
- package/dist/internal/server/operation-runner.js +21 -1
- package/dist/internal/server/person-context.d.ts +35 -0
- package/dist/internal/server/person-context.js +115 -0
- package/dist/internal/server/semantics.d.ts +1 -1
- package/dist/internal/surfaces.d.ts +1 -1
- package/dist/internal/surfaces.js +4 -4
- package/dist/registry.d.ts +7 -0
- package/dist/registry.js +4 -0
- package/dist/styles.css +3 -8
- package/package.json +11 -11
|
@@ -2,8 +2,14 @@ import { validateAgainstSchema } from "@ekanos/integration-schema";
|
|
|
2
2
|
import fs from "node:fs";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { z } from "zod";
|
|
5
|
+
import { HARNESS_USER_ID } from "../../registry.js";
|
|
5
6
|
import { deriveConnectionFacts } from "../lib/connection-facts.js";
|
|
7
|
+
import {
|
|
8
|
+
declaredActivationFieldNames,
|
|
9
|
+
describeActivationCredentials
|
|
10
|
+
} from "./activation-credentials.js";
|
|
6
11
|
import { createApprovalsTray } from "./approvals.js";
|
|
12
|
+
import { readConsoleSwitches, writeConsoleSwitches } from "./console-state.js";
|
|
7
13
|
import {
|
|
8
14
|
loadExperience,
|
|
9
15
|
usedByIndex
|
|
@@ -20,12 +26,17 @@ import {
|
|
|
20
26
|
clearActivationBlock,
|
|
21
27
|
declaredSecretNames,
|
|
22
28
|
readLocalSecrets,
|
|
29
|
+
readOauthConnections,
|
|
30
|
+
readPersonTier,
|
|
31
|
+
updatePersonTier,
|
|
32
|
+
removeOauthConnection,
|
|
23
33
|
selectConnectionTarget,
|
|
24
34
|
writeActivationSecrets,
|
|
25
35
|
writeLocalSecrets
|
|
26
36
|
} from "./local-secrets.js";
|
|
27
37
|
import { isPinnedToFixtures, setPinnedToFixtures } from "./local-state.js";
|
|
28
38
|
import { loopbackRefusal, isLoopbackHost } from "./loopback-guard.js";
|
|
39
|
+
import { describeOAuthConnections } from "./oauth-connections.js";
|
|
29
40
|
import { hasStoredOauthConnection } from "./oauth-persistence.js";
|
|
30
41
|
import {
|
|
31
42
|
createFileFixtureSource,
|
|
@@ -87,10 +98,23 @@ const CredentialsBodySchema = z.object({
|
|
|
87
98
|
values: z.record(z.string(), z.string())
|
|
88
99
|
});
|
|
89
100
|
const ActivationBodySchema = z.object({
|
|
90
|
-
activationData: z.record(z.string(), z.unknown())
|
|
101
|
+
activationData: z.record(z.string(), z.unknown()),
|
|
102
|
+
merge: z.boolean().optional(),
|
|
103
|
+
as: z.enum(["me", "team"]).optional()
|
|
104
|
+
});
|
|
105
|
+
const SwitchesBodySchema = z.object({
|
|
106
|
+
runAs: z.enum(["me", "machine"]).optional(),
|
|
107
|
+
connectAs: z.object({
|
|
108
|
+
credential: z.string().regex(/^(oauth|activation):[a-z][a-z0-9-]{0,31}$/),
|
|
109
|
+
as: z.enum(["me", "team"])
|
|
110
|
+
}).optional()
|
|
91
111
|
});
|
|
92
112
|
const RuntimeModeBodySchema = z.object({ mode: z.enum(["auto", "fixtures"]) });
|
|
93
|
-
const DisconnectBodySchema = z.object({
|
|
113
|
+
const DisconnectBodySchema = z.object({
|
|
114
|
+
clearKeys: z.boolean().optional(),
|
|
115
|
+
connection: z.string().regex(/^[a-z][a-z0-9-]{1,31}$/).optional(),
|
|
116
|
+
as: z.enum(["me", "team"]).optional()
|
|
117
|
+
});
|
|
94
118
|
const RESOLUTION_INPUTS = [
|
|
95
119
|
"ekanos.json",
|
|
96
120
|
"ekanos.lock.json",
|
|
@@ -681,15 +705,85 @@ function createEkanosApiRouter(partial = {}) {
|
|
|
681
705
|
);
|
|
682
706
|
}
|
|
683
707
|
const definition = await integration.loadDefinition();
|
|
708
|
+
if (parsed.data.merge) {
|
|
709
|
+
const known = new Set(declaredActivationFieldNames(definition));
|
|
710
|
+
const unknown = Object.keys(parsed.data.activationData).filter(
|
|
711
|
+
(name) => !known.has(name)
|
|
712
|
+
);
|
|
713
|
+
if (unknown.length > 0) {
|
|
714
|
+
return apiError(
|
|
715
|
+
400,
|
|
716
|
+
"rejected",
|
|
717
|
+
`"${rest[0]}" declares no activation field ${unknown.map((name) => `"${name}"`).join(", ")}.`
|
|
718
|
+
);
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
if (parsed.data.as === "me") {
|
|
722
|
+
const given = Object.fromEntries(
|
|
723
|
+
Object.entries(parsed.data.activationData).filter(
|
|
724
|
+
(entry) => typeof entry[1] === "string" && (!parsed.data.merge || entry[1] !== "")
|
|
725
|
+
)
|
|
726
|
+
);
|
|
727
|
+
const mine = updatePersonTier({
|
|
728
|
+
projectRoot: integration.credentialRoot,
|
|
729
|
+
slug: definition.slug,
|
|
730
|
+
userId: HARNESS_USER_ID,
|
|
731
|
+
update: (tier) => ({
|
|
732
|
+
...tier,
|
|
733
|
+
activation: parsed.data.merge ? { ...tier.activation, ...given } : given
|
|
734
|
+
})
|
|
735
|
+
});
|
|
736
|
+
if (!mine.ok) return apiError(400, "rejected", mine.message);
|
|
737
|
+
return json(await credentialsFor(integration));
|
|
738
|
+
}
|
|
684
739
|
const written = writeActivationSecrets({
|
|
685
740
|
projectRoot: integration.credentialRoot,
|
|
686
741
|
slug: definition.slug,
|
|
687
|
-
activationData: parsed.data.activationData
|
|
742
|
+
activationData: parsed.data.activationData,
|
|
743
|
+
...parsed.data.merge ? { merge: true } : {}
|
|
688
744
|
});
|
|
689
745
|
if (!written.ok) return apiError(400, "rejected", written.message);
|
|
690
746
|
getLiveStore().delete(definition.slug);
|
|
691
747
|
return json(await credentialsFor(integration));
|
|
692
748
|
}
|
|
749
|
+
if (head === "credentials" && rest.length === 2 && rest[1] === "switches") {
|
|
750
|
+
if (method !== "PUT") {
|
|
751
|
+
return apiError(405, "method_not_allowed", "PUT only.");
|
|
752
|
+
}
|
|
753
|
+
const state = await getResolution();
|
|
754
|
+
const integration = state.integrations.find(
|
|
755
|
+
(s) => s.integration === rest[0]
|
|
756
|
+
);
|
|
757
|
+
if (!integration?.loadDefinition) {
|
|
758
|
+
return apiError(
|
|
759
|
+
404,
|
|
760
|
+
"unknown_integration",
|
|
761
|
+
`No resolved integration with local credentials is named "${rest[0]}".`
|
|
762
|
+
);
|
|
763
|
+
}
|
|
764
|
+
const parsed = SwitchesBodySchema.safeParse(
|
|
765
|
+
await request.json().catch(() => null)
|
|
766
|
+
);
|
|
767
|
+
if (!parsed.success) {
|
|
768
|
+
return apiError(
|
|
769
|
+
400,
|
|
770
|
+
"invalid_request",
|
|
771
|
+
'Body must be { runAs?: "me" | "machine", connectAs?: { credential, as } }.'
|
|
772
|
+
);
|
|
773
|
+
}
|
|
774
|
+
const definition = await integration.loadDefinition();
|
|
775
|
+
writeConsoleSwitches({
|
|
776
|
+
projectRoot: integration.credentialRoot,
|
|
777
|
+
...parsed.data.runAs ? { runAs: parsed.data.runAs } : {},
|
|
778
|
+
...parsed.data.connectAs ? {
|
|
779
|
+
connectAs: {
|
|
780
|
+
slug: definition.slug,
|
|
781
|
+
...parsed.data.connectAs
|
|
782
|
+
}
|
|
783
|
+
} : {}
|
|
784
|
+
});
|
|
785
|
+
return json(await credentialsFor(integration));
|
|
786
|
+
}
|
|
693
787
|
if (head === "credentials" && rest.length === 2 && rest[1] === "disconnect") {
|
|
694
788
|
if (method !== "POST") {
|
|
695
789
|
return apiError(405, "method_not_allowed", "POST only.");
|
|
@@ -712,11 +806,47 @@ function createEkanosApiRouter(partial = {}) {
|
|
|
712
806
|
return apiError(
|
|
713
807
|
400,
|
|
714
808
|
"invalid_request",
|
|
715
|
-
"Body must be { clearKeys?: boolean }."
|
|
809
|
+
"Body must be { clearKeys?: boolean, connection?: string }."
|
|
716
810
|
);
|
|
717
811
|
}
|
|
718
812
|
const definition = await integration.loadDefinition();
|
|
719
813
|
const names = declaredSecretNames(definition);
|
|
814
|
+
if (parsed.data.connection !== void 0) {
|
|
815
|
+
const connectionId = parsed.data.connection;
|
|
816
|
+
const declared = connectionId === "default" ? definition.oauth !== void 0 : Object.hasOwn(definition.oauthConnections ?? {}, connectionId);
|
|
817
|
+
if (!declared) {
|
|
818
|
+
return apiError(
|
|
819
|
+
404,
|
|
820
|
+
"unknown_connection",
|
|
821
|
+
`"${rest[0]}" declares no OAuth connection "${connectionId}".`
|
|
822
|
+
);
|
|
823
|
+
}
|
|
824
|
+
if (parsed.data.as === "me") {
|
|
825
|
+
const mine = updatePersonTier({
|
|
826
|
+
projectRoot: integration.credentialRoot,
|
|
827
|
+
slug: definition.slug,
|
|
828
|
+
userId: HARNESS_USER_ID,
|
|
829
|
+
update: (tier) => {
|
|
830
|
+
const { [connectionId]: _gone, ...oauth } = tier.oauth;
|
|
831
|
+
return {
|
|
832
|
+
...tier,
|
|
833
|
+
oauth,
|
|
834
|
+
secrets: Object.keys(oauth).length > 0 ? tier.secrets : {}
|
|
835
|
+
};
|
|
836
|
+
}
|
|
837
|
+
});
|
|
838
|
+
if (!mine.ok) return apiError(400, "rejected", mine.message);
|
|
839
|
+
return json(await credentialsFor(integration));
|
|
840
|
+
}
|
|
841
|
+
const removed = removeOauthConnection({
|
|
842
|
+
projectRoot: integration.credentialRoot,
|
|
843
|
+
slug: definition.slug,
|
|
844
|
+
connectionId
|
|
845
|
+
});
|
|
846
|
+
if (!removed.ok) return apiError(400, "rejected", removed.message);
|
|
847
|
+
getLiveStore().delete(definition.slug);
|
|
848
|
+
return json(await credentialsFor(integration));
|
|
849
|
+
}
|
|
720
850
|
const cleared = clearActivationBlock({
|
|
721
851
|
projectRoot: integration.credentialRoot,
|
|
722
852
|
slug: definition.slug
|
|
@@ -818,6 +948,21 @@ function createEkanosApiRouter(partial = {}) {
|
|
|
818
948
|
names
|
|
819
949
|
});
|
|
820
950
|
if (!secrets.ok) throw new Error(secrets.message);
|
|
951
|
+
const switches = readConsoleSwitches(integration.credentialRoot);
|
|
952
|
+
const person = readPersonTier({
|
|
953
|
+
projectRoot: integration.credentialRoot,
|
|
954
|
+
slug: definition.slug,
|
|
955
|
+
userId: HARNESS_USER_ID
|
|
956
|
+
});
|
|
957
|
+
const activationCredentials = describeActivationCredentials(
|
|
958
|
+
definition,
|
|
959
|
+
Object.keys(secrets.activation),
|
|
960
|
+
{
|
|
961
|
+
slug: definition.slug,
|
|
962
|
+
switches,
|
|
963
|
+
set: Object.keys(person.activation)
|
|
964
|
+
}
|
|
965
|
+
);
|
|
821
966
|
return {
|
|
822
967
|
integration: integration.integration,
|
|
823
968
|
root: integration.credentialRoot,
|
|
@@ -828,6 +973,25 @@ function createEkanosApiRouter(partial = {}) {
|
|
|
828
973
|
activationFieldsSet: Object.keys(secrets.activation),
|
|
829
974
|
target: selectConnectionTarget(secrets.activation, names),
|
|
830
975
|
oauth: facts.kind === "oauth",
|
|
976
|
+
...activationCredentials.length > 0 ? { activationCredentials } : {},
|
|
977
|
+
...definition.oauth || Object.keys(definition.oauthConnections ?? {}).length > 0 ? {
|
|
978
|
+
oauthConnections: describeOAuthConnections({
|
|
979
|
+
definition,
|
|
980
|
+
filled: Object.keys(secrets.values),
|
|
981
|
+
values: secrets.values,
|
|
982
|
+
held: getLiveStore().get(definition.slug),
|
|
983
|
+
stored: readOauthConnections({
|
|
984
|
+
projectRoot: integration.credentialRoot,
|
|
985
|
+
slug: definition.slug
|
|
986
|
+
}),
|
|
987
|
+
personal: {
|
|
988
|
+
slug: definition.slug,
|
|
989
|
+
switches,
|
|
990
|
+
stored: person.oauth
|
|
991
|
+
}
|
|
992
|
+
})
|
|
993
|
+
} : {},
|
|
994
|
+
runAs: switches.runAs,
|
|
831
995
|
...displayRootOf(integration.credentialRoot) ? { displayRoot: displayRootOf(integration.credentialRoot) } : {},
|
|
832
996
|
facts
|
|
833
997
|
};
|
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
import { HARNESS_ACCOUNT_ID } from "../../registry.js";
|
|
6
6
|
import { resolveOriginalFetch } from "../lib/original-fetch.js";
|
|
7
7
|
import { createNonceStore } from "./nonce-store.js";
|
|
8
|
+
import { machineContext } from "./person-context.js";
|
|
8
9
|
const STORE = /* @__PURE__ */ Symbol.for("ekanos.harness.live-state");
|
|
9
10
|
function getLiveStore() {
|
|
10
11
|
const carrier = globalThis;
|
|
@@ -73,7 +74,7 @@ function startWarmup(state, definition, now = Date.now) {
|
|
|
73
74
|
for (const schedule of schedules) {
|
|
74
75
|
try {
|
|
75
76
|
await invokeSchedule(definition, schedule.id, {
|
|
76
|
-
context: state.ctx,
|
|
77
|
+
context: machineContext(state.ctx),
|
|
77
78
|
trigger: "schedule"
|
|
78
79
|
});
|
|
79
80
|
} catch (error) {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { invokeWebhook } from "@ekanos/sdk/testing";
|
|
2
|
+
import { readConsoleSwitches } from "./console-state.js";
|
|
2
3
|
import { getLiveState } from "./live-context.js";
|
|
3
4
|
import {
|
|
4
5
|
declaredSecretNames,
|
|
@@ -6,6 +7,7 @@ import {
|
|
|
6
7
|
readLocalSecrets
|
|
7
8
|
} from "./local-secrets.js";
|
|
8
9
|
import { restoreOauthConnections } from "./oauth-persistence.js";
|
|
10
|
+
import { contextAs } from "./person-context.js";
|
|
9
11
|
function liveIntegration(definition) {
|
|
10
12
|
return {
|
|
11
13
|
slug: definition.slug,
|
|
@@ -52,13 +54,19 @@ function createLiveInvoker(options = {}) {
|
|
|
52
54
|
integration,
|
|
53
55
|
options.networkFetch
|
|
54
56
|
);
|
|
57
|
+
const callCtx = contextAs({
|
|
58
|
+
base: state.ctx,
|
|
59
|
+
runAs: readConsoleSwitches(integration.credentialRoot).runAs,
|
|
60
|
+
projectRoot: integration.credentialRoot,
|
|
61
|
+
slug: definition.slug
|
|
62
|
+
});
|
|
55
63
|
if (kind === "tool") {
|
|
56
64
|
const tool = definition.tools?.find(
|
|
57
65
|
(candidate) => candidate.name === name
|
|
58
66
|
);
|
|
59
67
|
if (!tool)
|
|
60
68
|
throw new Error(`"${definition.slug}" declares no tool "${name}"`);
|
|
61
|
-
return tool.run(
|
|
69
|
+
return tool.run(callCtx, input);
|
|
62
70
|
}
|
|
63
71
|
const action = definition.actions?.[name];
|
|
64
72
|
if (!action)
|
|
@@ -69,7 +77,7 @@ function createLiveInvoker(options = {}) {
|
|
|
69
77
|
`action "${name}" input failed its own schema: ${JSON.stringify(parsed.error.issues).slice(0, 400)}`
|
|
70
78
|
);
|
|
71
79
|
}
|
|
72
|
-
return action.handler(
|
|
80
|
+
return action.handler(callCtx, parsed.data);
|
|
73
81
|
},
|
|
74
82
|
async deliverWebhook({ integration, webhookId, payload }) {
|
|
75
83
|
const { state, definition } = await liveStateFor(
|
|
@@ -116,6 +116,11 @@ export declare function writeActivationSecrets(args: {
|
|
|
116
116
|
projectRoot: string;
|
|
117
117
|
slug: string;
|
|
118
118
|
activationData: unknown;
|
|
119
|
+
/**
|
|
120
|
+
* Keep the stored fields and set only the non-empty ones given: one
|
|
121
|
+
* credential saved from the Connect tab, beside the rest of the block.
|
|
122
|
+
*/
|
|
123
|
+
merge?: boolean;
|
|
119
124
|
}): LocalSecretsWrite;
|
|
120
125
|
/**
|
|
121
126
|
* Whether an activation-form field holds a credential, judged by its name.
|
|
@@ -198,3 +203,45 @@ export declare function writeOauthConnection(args: {
|
|
|
198
203
|
connectionId: string;
|
|
199
204
|
connection: StoredOauthConnection;
|
|
200
205
|
}): LocalSecretsWrite;
|
|
206
|
+
/**
|
|
207
|
+
* Forget one connection's stored tokens — a per-connection Disconnect. The
|
|
208
|
+
* other connections, the app keys and the activation fields stay. Never
|
|
209
|
+
* creates the file or the slug's block; keeps the file at 0600.
|
|
210
|
+
*/
|
|
211
|
+
export declare function removeOauthConnection(args: {
|
|
212
|
+
projectRoot: string;
|
|
213
|
+
slug: string;
|
|
214
|
+
connectionId: string;
|
|
215
|
+
}): LocalSecretsClear;
|
|
216
|
+
/**
|
|
217
|
+
* The block key holding the per-person tier (plan 261 R6): what one local
|
|
218
|
+
* person connected as themselves, beside — never among — the team's values.
|
|
219
|
+
* One entry per local user id, each `{ activationData, secrets, oauthTokens }`:
|
|
220
|
+
* the string fields they submitted, the names their own `onTokens` wrote, and
|
|
221
|
+
* the OAuth connections they made.
|
|
222
|
+
*/
|
|
223
|
+
export declare const PERSONAL_BLOCK_KEY = "personal";
|
|
224
|
+
export interface PersonTier {
|
|
225
|
+
/** Activation-form string fields the person saved for themselves. */
|
|
226
|
+
activation: Record<string, string>;
|
|
227
|
+
/** Names the integration wrote to the person's tier (`ctx.identity.secrets.set`). */
|
|
228
|
+
secrets: Record<string, string>;
|
|
229
|
+
/** The person's own OAuth connections, by connection id. */
|
|
230
|
+
oauth: Record<string, StoredOauthConnection>;
|
|
231
|
+
}
|
|
232
|
+
/** One person's tier for `slug`. Never creates the file; an unreadable one reads empty. */
|
|
233
|
+
export declare function readPersonTier(args: {
|
|
234
|
+
projectRoot: string;
|
|
235
|
+
slug: string;
|
|
236
|
+
userId: string;
|
|
237
|
+
}): PersonTier;
|
|
238
|
+
/**
|
|
239
|
+
* Change one person's tier in place, keeping everything else in the file (the
|
|
240
|
+
* team's values, other people, the help line) and its 0600 mode.
|
|
241
|
+
*/
|
|
242
|
+
export declare function updatePersonTier(args: {
|
|
243
|
+
projectRoot: string;
|
|
244
|
+
slug: string;
|
|
245
|
+
userId: string;
|
|
246
|
+
update: (tier: PersonTier) => PersonTier;
|
|
247
|
+
}): LocalSecretsWrite;
|
|
@@ -180,7 +180,13 @@ function writeActivationSecrets(args) {
|
|
|
180
180
|
const doc = existing.kind === "ok" ? { ...existing.doc } : { "//": HELP };
|
|
181
181
|
const currentBlock = doc[args.slug];
|
|
182
182
|
const block = isRecord(currentBlock) ? { ...currentBlock } : {};
|
|
183
|
-
const
|
|
183
|
+
const given = stringFields(args.activationData);
|
|
184
|
+
const fields = args.merge ? {
|
|
185
|
+
...stringFields(block[ACTIVATION_BLOCK_KEY]),
|
|
186
|
+
...Object.fromEntries(
|
|
187
|
+
Object.entries(given).filter(([, value]) => value !== "")
|
|
188
|
+
)
|
|
189
|
+
} : given;
|
|
184
190
|
if (Object.keys(fields).length > 0) {
|
|
185
191
|
block[ACTIVATION_BLOCK_KEY] = fields;
|
|
186
192
|
} else {
|
|
@@ -206,7 +212,7 @@ function peekSecretValues(args) {
|
|
|
206
212
|
if (existing.kind !== "ok") return [];
|
|
207
213
|
const block = existing.doc[args.slug];
|
|
208
214
|
if (!isRecord(block)) return [];
|
|
209
|
-
const values =
|
|
215
|
+
const values = personValues(block);
|
|
210
216
|
for (const [key, value] of Object.entries(block)) {
|
|
211
217
|
if (typeof value === "string" && value.trim().length > 0) {
|
|
212
218
|
values.push(value);
|
|
@@ -292,10 +298,110 @@ function writeOauthConnection(args) {
|
|
|
292
298
|
writeDocument(file, doc);
|
|
293
299
|
return { ok: true };
|
|
294
300
|
}
|
|
301
|
+
function removeOauthConnection(args) {
|
|
302
|
+
const file = path.join(args.projectRoot, LOCAL_SECRETS_RELATIVE_PATH);
|
|
303
|
+
const existing = readDocument(file);
|
|
304
|
+
if (existing.kind === "missing") return { ok: true, removed: false };
|
|
305
|
+
if (existing.kind === "corrupt") {
|
|
306
|
+
return {
|
|
307
|
+
ok: false,
|
|
308
|
+
message: `${file} is not a JSON object; fix or delete it by hand first.`
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
const block = existing.doc[args.slug];
|
|
312
|
+
if (!isRecord(block) || !isRecord(block[OAUTH_BLOCK_KEY])) {
|
|
313
|
+
return { ok: true, removed: false };
|
|
314
|
+
}
|
|
315
|
+
const held = { ...block[OAUTH_BLOCK_KEY] };
|
|
316
|
+
if (!Object.hasOwn(held, args.connectionId)) {
|
|
317
|
+
return { ok: true, removed: false };
|
|
318
|
+
}
|
|
319
|
+
delete held[args.connectionId];
|
|
320
|
+
const rest = { ...block };
|
|
321
|
+
if (Object.keys(held).length > 0) rest[OAUTH_BLOCK_KEY] = held;
|
|
322
|
+
else delete rest[OAUTH_BLOCK_KEY];
|
|
323
|
+
writeDocument(file, { ...existing.doc, [args.slug]: rest });
|
|
324
|
+
return { ok: true, removed: true };
|
|
325
|
+
}
|
|
326
|
+
const PERSONAL_BLOCK_KEY = "personal";
|
|
327
|
+
function personEntry(block, userId) {
|
|
328
|
+
if (!isRecord(block) || !isRecord(block[PERSONAL_BLOCK_KEY])) return {};
|
|
329
|
+
const entry = block[PERSONAL_BLOCK_KEY][userId];
|
|
330
|
+
return isRecord(entry) ? entry : {};
|
|
331
|
+
}
|
|
332
|
+
function toPersonTier(entry) {
|
|
333
|
+
return {
|
|
334
|
+
activation: stringFields(entry[ACTIVATION_BLOCK_KEY]),
|
|
335
|
+
secrets: stringFields(entry.secrets),
|
|
336
|
+
oauth: isRecord(entry[OAUTH_BLOCK_KEY]) ? Object.fromEntries(
|
|
337
|
+
Object.entries(entry[OAUTH_BLOCK_KEY]).filter(
|
|
338
|
+
(pair) => isStoredOauth(pair[1])
|
|
339
|
+
)
|
|
340
|
+
) : {}
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
function readPersonTier(args) {
|
|
344
|
+
const file = path.join(args.projectRoot, LOCAL_SECRETS_RELATIVE_PATH);
|
|
345
|
+
let existing;
|
|
346
|
+
try {
|
|
347
|
+
existing = readDocument(file);
|
|
348
|
+
} catch {
|
|
349
|
+
return { activation: {}, secrets: {}, oauth: {} };
|
|
350
|
+
}
|
|
351
|
+
if (existing.kind !== "ok") return { activation: {}, secrets: {}, oauth: {} };
|
|
352
|
+
return toPersonTier(personEntry(existing.doc[args.slug], args.userId));
|
|
353
|
+
}
|
|
354
|
+
function updatePersonTier(args) {
|
|
355
|
+
const file = path.join(args.projectRoot, LOCAL_SECRETS_RELATIVE_PATH);
|
|
356
|
+
const existing = readDocument(file);
|
|
357
|
+
if (existing.kind === "corrupt") {
|
|
358
|
+
return {
|
|
359
|
+
ok: false,
|
|
360
|
+
message: `${file} is not a JSON object; fix or delete it by hand first.`
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
const doc = existing.kind === "ok" ? { ...existing.doc } : { "//": HELP };
|
|
364
|
+
const held = doc[args.slug];
|
|
365
|
+
const block = isRecord(held) ? { ...held } : {};
|
|
366
|
+
const people = isRecord(block[PERSONAL_BLOCK_KEY]) ? { ...block[PERSONAL_BLOCK_KEY] } : {};
|
|
367
|
+
const next = args.update(toPersonTier(personEntry(block, args.userId)));
|
|
368
|
+
const entry = {};
|
|
369
|
+
if (Object.keys(next.activation).length > 0) {
|
|
370
|
+
entry[ACTIVATION_BLOCK_KEY] = next.activation;
|
|
371
|
+
}
|
|
372
|
+
if (Object.keys(next.secrets).length > 0) entry.secrets = next.secrets;
|
|
373
|
+
if (Object.keys(next.oauth).length > 0) entry[OAUTH_BLOCK_KEY] = next.oauth;
|
|
374
|
+
if (Object.keys(entry).length > 0) people[args.userId] = entry;
|
|
375
|
+
else delete people[args.userId];
|
|
376
|
+
if (Object.keys(people).length > 0) block[PERSONAL_BLOCK_KEY] = people;
|
|
377
|
+
else delete block[PERSONAL_BLOCK_KEY];
|
|
378
|
+
doc[args.slug] = block;
|
|
379
|
+
writeDocument(file, doc);
|
|
380
|
+
return { ok: true };
|
|
381
|
+
}
|
|
382
|
+
function personValues(block) {
|
|
383
|
+
const people = block[PERSONAL_BLOCK_KEY];
|
|
384
|
+
if (!isRecord(people)) return [];
|
|
385
|
+
const values = [];
|
|
386
|
+
for (const entry of Object.values(people)) {
|
|
387
|
+
if (!isRecord(entry)) continue;
|
|
388
|
+
const tier = toPersonTier(entry);
|
|
389
|
+
values.push(...Object.values(tier.secrets));
|
|
390
|
+
for (const [field, value] of Object.entries(tier.activation)) {
|
|
391
|
+
if (isSensitiveFieldName(field)) values.push(value);
|
|
392
|
+
}
|
|
393
|
+
for (const stored of Object.values(tier.oauth)) {
|
|
394
|
+
values.push(stored.tokens.accessToken);
|
|
395
|
+
if (stored.tokens.refreshToken) values.push(stored.tokens.refreshToken);
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
return values.filter((value) => value.trim().length > 0);
|
|
399
|
+
}
|
|
295
400
|
export {
|
|
296
401
|
ACTIVATION_BLOCK_KEY,
|
|
297
402
|
LOCAL_SECRETS_RELATIVE_PATH,
|
|
298
403
|
OAUTH_BLOCK_KEY,
|
|
404
|
+
PERSONAL_BLOCK_KEY,
|
|
299
405
|
clearActivationBlock,
|
|
300
406
|
declaredSecretNames,
|
|
301
407
|
isSensitiveFieldName,
|
|
@@ -303,7 +409,10 @@ export {
|
|
|
303
409
|
peekSecretValues,
|
|
304
410
|
readLocalSecrets,
|
|
305
411
|
readOauthConnections,
|
|
412
|
+
readPersonTier,
|
|
413
|
+
removeOauthConnection,
|
|
306
414
|
selectConnectionTarget,
|
|
415
|
+
updatePersonTier,
|
|
307
416
|
writeActivationSecrets,
|
|
308
417
|
writeLocalSecrets,
|
|
309
418
|
writeOauthConnection
|
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* `.ekanos/local-state.json` — non-secret local choices, kept apart from
|
|
3
|
-
* credentials.
|
|
3
|
+
* credentials. Which integrations the dev pinned to fixtures, keyed by
|
|
4
4
|
* integration slug (`{ "pinnedFixtures": { "<slug>": true } }`), so integrations
|
|
5
|
-
* that share one file (registry integrations of an experience) pin one by one
|
|
5
|
+
* that share one file (registry integrations of an experience) pin one by one;
|
|
6
|
+
* and the Connect-as / Run-as switches (`switches`, see `console-state.ts`).
|
|
7
|
+
* Each writer keeps the keys it does not own.
|
|
6
8
|
* `.ekanos/` is gitignored; `.ekanos/harness` is the only part `ekanos dev`
|
|
7
9
|
* regenerates, so this file survives that.
|
|
8
10
|
*/
|
|
9
11
|
export declare const LOCAL_STATE_RELATIVE_PATH: string;
|
|
12
|
+
/** The whole document, `{}` when absent or unreadable. */
|
|
13
|
+
export declare function readLocalState(file: string): Record<string, unknown>;
|
|
14
|
+
/** Write the document, or remove the file once it is empty. */
|
|
15
|
+
export declare function writeLocalState(file: string, doc: Record<string, unknown>): void;
|
|
10
16
|
export declare function isPinnedToFixtures(root: string, slug: string): boolean;
|
|
11
17
|
/** Pin sets this slug's key; unpin removes it, and the file once empty. */
|
|
12
18
|
export declare function setPinnedToFixtures(root: string, slug: string, pinned: boolean): void;
|
|
@@ -4,6 +4,26 @@ const LOCAL_STATE_RELATIVE_PATH = path.join(
|
|
|
4
4
|
".ekanos",
|
|
5
5
|
"local-state.json"
|
|
6
6
|
);
|
|
7
|
+
function readLocalState(file) {
|
|
8
|
+
try {
|
|
9
|
+
const parsed = JSON.parse(fs.readFileSync(file, "utf8"));
|
|
10
|
+
return typeof parsed === "object" && parsed !== null && !Array.isArray(parsed) ? { ...parsed } : {};
|
|
11
|
+
} catch (error) {
|
|
12
|
+
if (error.code !== "ENOENT") {
|
|
13
|
+
console.error("[harness] local-state.json could not be read", error);
|
|
14
|
+
}
|
|
15
|
+
return {};
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
function writeLocalState(file, doc) {
|
|
19
|
+
if (Object.keys(doc).length === 0) {
|
|
20
|
+
fs.rmSync(file, { force: true });
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
24
|
+
fs.writeFileSync(file, `${JSON.stringify(doc, null, 2)}
|
|
25
|
+
`);
|
|
26
|
+
}
|
|
7
27
|
function readPins(file) {
|
|
8
28
|
try {
|
|
9
29
|
const parsed = JSON.parse(fs.readFileSync(file, "utf8"));
|
|
@@ -27,19 +47,16 @@ function setPinnedToFixtures(root, slug, pinned) {
|
|
|
27
47
|
const pins = readPins(file);
|
|
28
48
|
if (pinned) pins[slug] = true;
|
|
29
49
|
else delete pins[slug];
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
35
|
-
fs.writeFileSync(
|
|
50
|
+
const { pinnedFixtures: _previous, ...rest } = readLocalState(file);
|
|
51
|
+
writeLocalState(
|
|
36
52
|
file,
|
|
37
|
-
|
|
38
|
-
`
|
|
53
|
+
Object.keys(pins).length > 0 ? { ...rest, pinnedFixtures: pins } : rest
|
|
39
54
|
);
|
|
40
55
|
}
|
|
41
56
|
export {
|
|
42
57
|
LOCAL_STATE_RELATIVE_PATH,
|
|
43
58
|
isPinnedToFixtures,
|
|
44
|
-
|
|
59
|
+
readLocalState,
|
|
60
|
+
setPinnedToFixtures,
|
|
61
|
+
writeLocalState
|
|
45
62
|
};
|
|
@@ -16,6 +16,8 @@ export interface PendingAuthorization {
|
|
|
16
16
|
codeVerifier?: string;
|
|
17
17
|
/** Which OAuth connection (`default`, or an `oauthConnections` key). */
|
|
18
18
|
connectionId?: string;
|
|
19
|
+
/** Whose tier the tokens are stored in; the team's when absent. */
|
|
20
|
+
connectAs?: 'me' | 'team';
|
|
19
21
|
}
|
|
20
22
|
export type ConsumeResult = {
|
|
21
23
|
status: 'ok';
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { type IntegrationDefinition, type PartnerOAuthDeclaration } from '@ekanos/sdk/integration';
|
|
2
|
+
import type { OAuthConnectionStatus } from '../../api-types.js';
|
|
3
|
+
import { type ConsoleSwitches } from './console-state.js';
|
|
4
|
+
import type { LiveConnection } from './live-context.js';
|
|
5
|
+
import { type StoredOauthConnection } from './local-secrets.js';
|
|
6
|
+
/**
|
|
7
|
+
* Every OAuth connection a definition declares — the main `oauth` (id
|
|
8
|
+
* `default`) and each `oauthConnections` entry — as the Connect surfaces show
|
|
9
|
+
* them: one Connect button each, the secret names that connection needs, and
|
|
10
|
+
* whether it is connected. Linear's agent is the case this exists for: a
|
|
11
|
+
* second app-actor grant whose `onTokens` could not be exercised while the
|
|
12
|
+
* harness drew a single Connect button.
|
|
13
|
+
*/
|
|
14
|
+
export declare const MAIN_CONNECTION_LABEL = "Main connection";
|
|
15
|
+
type Declaration = PartnerOAuthDeclaration & {
|
|
16
|
+
label?: string;
|
|
17
|
+
description?: string;
|
|
18
|
+
};
|
|
19
|
+
/** `[id, declaration]` for every declared connection, the main one first. */
|
|
20
|
+
export declare function declaredOAuthConnections(definition: Pick<IntegrationDefinition, 'oauth' | 'oauthConnections'>): Array<[string, Declaration]>;
|
|
21
|
+
export declare function describeOAuthConnections(input: {
|
|
22
|
+
definition: Pick<IntegrationDefinition, 'oauth' | 'oauthConnections'>;
|
|
23
|
+
/** Declared secret names that hold a value. */
|
|
24
|
+
filled: readonly string[];
|
|
25
|
+
/** Declared secret names → values, to tie stored tokens to their app. */
|
|
26
|
+
values: Readonly<Record<string, string>>;
|
|
27
|
+
/** What the live context holds, by connection id, when one exists. */
|
|
28
|
+
held?: {
|
|
29
|
+
connection: LiveConnection | null;
|
|
30
|
+
connections: Record<string, LiveConnection>;
|
|
31
|
+
} | undefined;
|
|
32
|
+
/** Tokens persisted in `.ekanos/local-secrets.json`, by connection id. */
|
|
33
|
+
stored: Readonly<Record<string, StoredOauthConnection>>;
|
|
34
|
+
/**
|
|
35
|
+
* The per-person tier and the Connect-as switches (plan 261 R6). Given,
|
|
36
|
+
* each connection reports which tier it connects into and whether THAT
|
|
37
|
+
* tier holds it; absent, every connection is the team's.
|
|
38
|
+
*/
|
|
39
|
+
personal?: {
|
|
40
|
+
slug: string;
|
|
41
|
+
switches: ConsoleSwitches;
|
|
42
|
+
stored: Readonly<Record<string, StoredOauthConnection>>;
|
|
43
|
+
};
|
|
44
|
+
}): OAuthConnectionStatus[];
|
|
45
|
+
export {};
|