History

refactor(v2): remove legacy oauth token and credential id schema

Drops the remaining legacy OAuth token model and old credential ID aliases so schema consumers align on auth connection and source auth binding identifiers.

Rhys Sullivan committed 8 months ago

Commit 336a0c81 parent 6d8f04411 files · +36 −64Browse files

Unified · Split

11 files
  1. apps/convex/convex/executor.test.ts +10 −10
  2. apps/web/components/credentials/credentials-view.tsx +2 −2
  3. apps/web/components/tools/source-management-panel.tsx +1 −1
  4. apps/web/lib/control-plane/atoms/credentials.ts +1 −2
  5. packages/engine/src/credential-resolver.ts +14 −5
  6. packages/management-api/src/credentials/api.ts +2 −2
  7. packages/management-api/src/credentials/service.ts +2 −2
  8. packages/schema/src/ids.ts +0 −8
  9. packages/schema/src/index.ts +0 −1
  10. packages/schema/src/models/oauth-token.ts +0 −27
  11. packages/schema/src/models/source-credential-binding.ts +4 −4
apps/convex/convex/executor.test.ts+10−10
@@ -200,8 +200,8 @@ describe("Convex executor and control-plane", () => { · 199 unmodified lines
200200 t.action(api.controlPlane.upsertCredentialBinding, {
201201 workspaceId: "ws_1",
202202 payload: {
203− id: "credential_binding_1",
204− credentialId: "cred_1",
203+ id: "auth_binding_1",
204+ credentialId: "conn_1",
205205 scopeType: "workspace",
206206 sourceKey: "source:github",
207207 provider: "bearer",
@@ -216,7 +216,7 @@ describe("Convex executor and control-plane", () => { · 8 unmodified lines
216216 workspaceId: string | null;
217217 };
218218
219− expect(addedCredential.id).toBe("credential_binding_1");
219+ expect(addedCredential.id).toBe("auth_binding_1");
220220 expect(addedCredential.workspaceId).toBe("ws_1");
221221
222222 const listedCredentials = (yield* Effect.tryPromise(() =>
@@ -228,12 +228,12 @@ describe("Convex executor and control-plane", () => { · 5 unmodified lines
228228 }>;
229229
230230 expect(listedCredentials).toHaveLength(1);
231− expect(listedCredentials[0]?.id).toBe("credential_binding_1");
231+ expect(listedCredentials[0]?.id).toBe("auth_binding_1");
232232
233233 const removedCredential = (yield* Effect.tryPromise(() =>
234234 t.mutation(api.controlPlane.removeCredentialBinding, {
235235 workspaceId: "ws_1",
236− credentialBindingId: "credential_binding_1",
236+ credentialBindingId: "auth_binding_1",
237237 }),
238238 )) as {
239239 removed: boolean;
@@ -1127,8 +1127,8 @@ describe("Convex executor and control-plane", () => { · 887 unmodified lines
11271127 t.action(api.controlPlane.upsertCredentialBinding, {
11281128 workspaceId: "ws_cred",
11291129 payload: {
1130− id: "credential_binding_linear",
1131− credentialId: "cred_linear",
1130+ id: "auth_binding_linear",
1131+ credentialId: "conn_linear",
11321132 scopeType: "workspace",
11331133 sourceKey: "source:src_graphql_cred_1",
11341134 provider: "bearer",
@@ -1320,8 +1320,8 @@ describe("Convex executor and control-plane", () => { · 185 unmodified lines
13201320 t.action(api.controlPlane.upsertCredentialBinding, {
13211321 workspaceId: "ws_mcp_ingest",
13221322 payload: {
1323− id: "credential_binding_mcp",
1324− credentialId: "cred_mcp",
1323+ id: "auth_binding_mcp",
1324+ credentialId: "conn_mcp",
13251325 scopeType: "workspace",
13261326 sourceKey: "source:src_mcp_ingest_1",
13271327 provider: "bearer",
@@ -1612,7 +1612,7 @@ describe("Convex executor and control-plane", () => { · 284 unmodified lines
16121612 t.action(api.controlPlane.upsertCredentialBinding, {
16131613 workspaceId,
16141614 payload: {
1615− id: "credential_binding_oauth_runtime_1",
1615+ id: "auth_binding_oauth_runtime_1",
16161616 credentialId: "conn_oauth_runtime_1",
16171617 scopeType: "workspace",
16181618 sourceKey: `source:${sourceId}`,
apps/web/components/credentials/credentials-view.tsx+2−2
@@ -172,7 +172,7 @@ export function CredentialsView() { · 171 unmodified lines
172172
173173 const requestId =
174174 credentialEditingId ??
175− (createLocalId("credential_binding_") as SourceCredentialBinding["id"]);
175+ (createLocalId("auth_binding_") as SourceCredentialBinding["id"]);
176176
177177 setCredentialBusyId(requestId);
178178
@@ -319,7 +319,7 @@ export function CredentialsView() { · 140 unmodified lines
319319 id="credential-id"
320320 value={credentialIdInput}
321321 onChange={(event) => setCredentialIdInput(event.target.value)}
322− placeholder="cred_123"
322+ placeholder="conn_123"
323323 required
324324 disabled={credentialBusyId !== null}
325325 />
apps/web/components/tools/source-management-panel.tsx+1−1
@@ -497,7 +497,7 @@ export function SourceManagementPanel({ editSource, onDone }: SourceManagementPa · 496 unmodified lines
497497 workspaceId,
498498 payload: toCredentialBindingUpsertPayload({
499499 ...(existingBinding ? { id: existingBinding.id } : {}),
500− credentialId: (existingBinding?.credentialId ?? createLocalId("cred_")) as SourceCredentialBinding["credentialId"],
500+ credentialId: (existingBinding?.credentialId ?? createLocalId("conn_")) as SourceCredentialBinding["credentialId"],
501501 scopeType,
502502 sourceKey,
503503 provider: "oauth2",
apps/web/lib/control-plane/atoms/credentials.ts+1−2
@@ -4,7 +4,6 @@ import type { · 3 unmodified lines
44 UpsertCredentialBindingPayload,
55 } from "@executor-v2/management-api/credentials/api";
66 import type {
7− CredentialBindingId,
87 CredentialProvider,
98 CredentialScopeType,
109 SourceCredentialBinding,
@@ -55,7 +54,7 @@ export const removeCredentialBinding = controlPlaneClient.mutation("credentials" · 44 unmodified lines
5554 // ---------------------------------------------------------------------------
5655
5756 export const toCredentialBindingUpsertPayload = (input: {
58− id?: CredentialBindingId;
57+ id?: SourceCredentialBinding["id"];
5958 credentialId: SourceCredentialBinding["credentialId"];
6059 scopeType: CredentialScopeType;
6160 sourceKey: string;
packages/engine/src/credential-resolver.ts+14−5
@@ -1,7 +1,5 @@
11 import type {
2− OAuthToken,
32 SourceCredentialBinding,
4− WorkspaceId,
53 } from "@executor-v2/schema";
64 import type {
75 RuntimeToolCallCredentialContext,
@@ -157,11 +155,22 @@ const parseAdditionalHeaders = ( · 149 unmodified lines
157155 return decoded.right;
158156 };
159157
158+type OAuthAccessTokenRecord = {
159+ workspaceId: string;
160+ organizationId: string | null;
161+ accountId: string | null;
162+ sourceId: string;
163+ accessTokenRef: string;
164+ expiresAt: number | null;
165+ createdAt: number;
166+ updatedAt: number;
167+};
168+
160169 const tokenScopeScore = (
161− token: OAuthToken,
170+ token: OAuthAccessTokenRecord,
162171 context: RuntimeToolCallCredentialContext,
163172 ): number => {
164− if (token.workspaceId !== (context.workspaceId as WorkspaceId)) {
173+ if (token.workspaceId !== context.workspaceId) {
165174 return -1;
166175 }
167176
@@ -196,7 +205,7 @@ const tokenScopeScore = ( · 28 unmodified lines
196205 };
197206
198207 export const selectOAuthAccessToken = (
199− tokens: ReadonlyArray<OAuthToken>,
208+ tokens: ReadonlyArray<OAuthAccessTokenRecord>,
200209 context: RuntimeToolCallCredentialContext,
201210 sourceId: string,
202211 ): string | null => {
packages/management-api/src/credentials/api.ts+2−2
@@ -1,6 +1,6 @@
11 import { HttpApiEndpoint, HttpApiGroup, HttpApiSchema } from "@effect/platform";
22 import {
3− CredentialBindingIdSchema,
3+ SourceAuthBindingIdSchema,
44 SourceCredentialBindingSchema,
55 WorkspaceIdSchema,
66 } from "@executor-v2/schema";
@@ -60,7 +60,7 @@ export type RemoveCredentialBindingResult = · 53 unmodified lines
6060 const workspaceIdParam = HttpApiSchema.param("workspaceId", WorkspaceIdSchema);
6161 const credentialBindingIdParam = HttpApiSchema.param(
6262 "credentialBindingId",
63− CredentialBindingIdSchema,
63+ SourceAuthBindingIdSchema,
6464 );
6565
6666 export class CredentialsApi extends HttpApiGroup.make("credentials")
packages/management-api/src/credentials/service.ts+2−2
@@ -1,7 +1,7 @@
11 import { type SourceStoreError } from "@executor-v2/persistence-ports";
22 import {
3− type CredentialBindingId,
43 type SourceCredentialBinding,
4+ type SourceAuthBindingId,
55 type WorkspaceId,
66 } from "@executor-v2/schema";
77 import * as Effect from "effect/Effect";
@@ -18,7 +18,7 @@ export type UpsertCredentialBindingInput = { · 10 unmodified lines
1818
1919 export type RemoveCredentialBindingInput = {
2020 workspaceId: WorkspaceId;
21− credentialBindingId: CredentialBindingId;
21+ credentialBindingId: SourceAuthBindingId;
2222 };
2323
2424 export type ControlPlaneCredentialsServiceShape = {
packages/schema/src/ids.ts+0−8
@@ -6,11 +6,6 @@ export const ProfileIdSchema = Schema.String.pipe(Schema.brand("ProfileId")); · 5 unmodified lines
66 export const WorkspaceIdSchema = Schema.String.pipe(Schema.brand("WorkspaceId"));
77 export const SourceIdSchema = Schema.String.pipe(Schema.brand("SourceId"));
88 export const ToolArtifactIdSchema = Schema.String.pipe(Schema.brand("ToolArtifactId"));
9−export const CredentialBindingIdSchema = Schema.String.pipe(
10− Schema.brand("CredentialBindingId"),
11−);
12−export const CredentialIdSchema = Schema.String.pipe(Schema.brand("CredentialId"));
13−export const OAuthTokenIdSchema = Schema.String.pipe(Schema.brand("OAuthTokenId"));
149 export const AuthConnectionIdSchema = Schema.String.pipe(
1510 Schema.brand("AuthConnectionId"),
1611 );
@@ -42,9 +37,6 @@ export type ProfileId = typeof ProfileIdSchema.Type; · 25 unmodified lines
4237 export type WorkspaceId = typeof WorkspaceIdSchema.Type;
4338 export type SourceId = typeof SourceIdSchema.Type;
4439 export type ToolArtifactId = typeof ToolArtifactIdSchema.Type;
45−export type CredentialBindingId = typeof CredentialBindingIdSchema.Type;
46−export type CredentialId = typeof CredentialIdSchema.Type;
47−export type OAuthTokenId = typeof OAuthTokenIdSchema.Type;
4840 export type AuthConnectionId = typeof AuthConnectionIdSchema.Type;
4941 export type SourceAuthBindingId = typeof SourceAuthBindingIdSchema.Type;
5042 export type AuthMaterialId = typeof AuthMaterialIdSchema.Type;
packages/schema/src/index.ts+0−1
@@ -6,7 +6,6 @@ export * from "./models/profile"; · 5 unmodified lines
66 export * from "./models/workspace";
77 export * from "./models/source";
88 export * from "./models/tool-artifact";
9−export * from "./models/oauth-token";
109 export * from "./models/source-credential-binding";
1110 export * from "./models/auth-connection";
1211 export * from "./models/source-auth-binding";
packages/schema/src/models/oauth-token.ts+0−27
@@ -1,27 +0,0 @@
1−import { Schema } from "effect";
2−
3−import { TimestampMsSchema } from "../common";
4−import {
5− AccountIdSchema,
6− OAuthTokenIdSchema,
7− OrganizationIdSchema,
8− SourceIdSchema,
9− WorkspaceIdSchema,
10−} from "../ids";
11−
12−export const OAuthTokenSchema = Schema.Struct({
13− id: OAuthTokenIdSchema,
14− workspaceId: WorkspaceIdSchema,
15− organizationId: Schema.NullOr(OrganizationIdSchema),
16− accountId: Schema.NullOr(AccountIdSchema),
17− sourceId: SourceIdSchema,
18− issuer: Schema.String,
19− accessTokenRef: Schema.String,
20− refreshTokenRef: Schema.NullOr(Schema.String),
21− scope: Schema.Array(Schema.String),
22− expiresAt: Schema.NullOr(TimestampMsSchema),
23− createdAt: TimestampMsSchema,
24− updatedAt: TimestampMsSchema,
25−});
26−
27−export type OAuthToken = typeof OAuthTokenSchema.Type;
packages/schema/src/models/source-credential-binding.ts+4−4
@@ -8,15 +8,15 @@ import { · 7 unmodified lines
88 } from "../enums";
99 import {
1010 AccountIdSchema,
11− CredentialBindingIdSchema,
12− CredentialIdSchema,
11+ AuthConnectionIdSchema,
1312 OrganizationIdSchema,
13+ SourceAuthBindingIdSchema,
1414 WorkspaceIdSchema,
1515 } from "../ids";
1616
1717 export const SourceCredentialBindingSchema = Schema.Struct({
18− id: CredentialBindingIdSchema,
19− credentialId: CredentialIdSchema,
18+ id: SourceAuthBindingIdSchema,
19+ credentialId: AuthConnectionIdSchema,
2020 organizationId: OrganizationIdSchema,
2121 workspaceId: Schema.NullOr(WorkspaceIdSchema),
2222 accountId: Schema.NullOr(AccountIdSchema),