Skip to content

Commit ab6f169

Browse files
authored
feat(google-discovery): add edit source configuration support (#146)
Implement getSource for the Google Discovery plugin with read-only config view, stored-source schema, and edit UI.
1 parent 50e8a6a commit ab6f169

7 files changed

Lines changed: 107 additions & 2 deletions

File tree

‎packages/plugins/google-discovery/src/api/group.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@ import { HttpApiEndpoint, HttpApiGroup, HttpApiSchema } from "@effect/platform";
22
import { Schema } from "effect";
33
import { ScopeId } from "@executor/sdk";
44

5+
import { GoogleDiscoveryStoredSourceSchema } from "../sdk/stored-source";
6+
57
export { HttpApiSchema };
68

79
const scopeIdParam = HttpApiSchema.param("scopeId", ScopeId);
10+
const namespaceParam = HttpApiSchema.param("namespace", Schema.String);
811

912
const AuthPayload = Schema.Union(
1013
Schema.Struct({
@@ -125,4 +128,9 @@ export class GoogleDiscoveryGroup extends HttpApiGroup.make("googleDiscovery")
125128
.addSuccess(HtmlResponse)
126129
.addError(ApiError),
127130
)
131+
.add(
132+
HttpApiEndpoint.get("getSource")`/scopes/${scopeIdParam}/google-discovery/sources/${namespaceParam}`
133+
.addSuccess(Schema.NullOr(GoogleDiscoveryStoredSourceSchema))
134+
.addError(ApiError),
135+
)
128136
{}

‎packages/plugins/google-discovery/src/api/handlers.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,12 @@ export const GoogleDiscoveryHandlers = HttpApiBuilder.group(
105105
});
106106
}).pipe(Effect.orDie),
107107
)
108+
.handle("getSource", ({ path }) =>
109+
Effect.gen(function* () {
110+
const ext = yield* GoogleDiscoveryExtensionService;
111+
return yield* ext.getSource(path.namespace);
112+
}).pipe(Effect.orDie),
113+
)
108114
.handle("oauthCallback", ({ urlParams }) =>
109115
Effect.gen(function* () {
110116
const ext = yield* GoogleDiscoveryExtensionService;

‎packages/plugins/google-discovery/src/react/EditGoogleDiscoverySource.tsx‎

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,78 @@
1+
import { useAtomValue, Result } from "@effect-atom/atom-react";
2+
import { useScope } from "@executor/react/api/scope-context";
13
import { Badge } from "@executor/react/components/badge";
24
import { Button } from "@executor/react/components/button";
35

6+
import { googleDiscoverySourceAtom } from "./atoms";
7+
48
export default function EditGoogleDiscoverySource({
59
sourceId,
610
onSave,
711
}: {
812
readonly sourceId: string;
913
readonly onSave: () => void;
1014
}) {
15+
const scopeId = useScope();
16+
const sourceResult = useAtomValue(googleDiscoverySourceAtom(scopeId, sourceId));
17+
18+
const source = Result.isSuccess(sourceResult) ? sourceResult.value : null;
19+
const config = source?.config;
20+
const authKind = config?.auth.kind ?? "none";
21+
1122
return (
1223
<div className="space-y-6">
1324
<div>
1425
<h1 className="text-xl font-semibold text-foreground">
1526
Edit Google Discovery Source
1627
</h1>
1728
<p className="mt-1 text-[13px] text-muted-foreground">
18-
This source is managed from its Discovery document and can be refreshed from the source header.
29+
View configuration for this Google API source. To change authentication,
30+
remove and re-add the source with updated OAuth credentials.
1931
</p>
2032
</div>
2133

2234
<div className="flex items-center gap-3 rounded-lg border border-border bg-card px-4 py-3">
2335
<div className="min-w-0 flex-1">
2436
<p className="truncate text-sm font-semibold text-card-foreground">
25-
{sourceId}
37+
{source?.name ?? sourceId}
2638
</p>
39+
{config?.discoveryUrl && (
40+
<p className="mt-0.5 text-xs text-muted-foreground font-mono truncate">
41+
{config.discoveryUrl}
42+
</p>
43+
)}
2744
</div>
2845
<Badge variant="secondary" className="text-[10px]">
2946
Google Discovery
3047
</Badge>
3148
</div>
3249

50+
{config && (
51+
<div className="space-y-3">
52+
<div className="grid grid-cols-2 gap-3 text-sm">
53+
<div className="rounded-lg border border-border bg-card/50 p-3">
54+
<p className="text-[10px] uppercase tracking-wider text-muted-foreground mb-1">Service</p>
55+
<p className="text-sm font-medium text-foreground">
56+
{config.service}
57+
</p>
58+
</div>
59+
<div className="rounded-lg border border-border bg-card/50 p-3">
60+
<p className="text-[10px] uppercase tracking-wider text-muted-foreground mb-1">Version</p>
61+
<p className="text-sm font-medium text-foreground">
62+
{config.version}
63+
</p>
64+
</div>
65+
</div>
66+
67+
<div className="rounded-lg border border-border bg-card/50 p-3">
68+
<p className="text-[10px] uppercase tracking-wider text-muted-foreground mb-1">Authentication</p>
69+
<p className="text-sm font-medium text-foreground capitalize">
70+
{authKind === "oauth2" ? "OAuth 2.0" : authKind}
71+
</p>
72+
</div>
73+
</div>
74+
)}
75+
3376
<div className="flex items-center justify-end border-t border-border pt-4">
3477
<Button onClick={onSave}>Done</Button>
3578
</div>

‎packages/plugins/google-discovery/src/react/atoms.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
1+
import type { ScopeId } from "@executor/sdk";
12
import { GoogleDiscoveryClient } from "./client";
23

4+
export const googleDiscoverySourceAtom = (
5+
scopeId: ScopeId,
6+
namespace: string,
7+
) =>
8+
GoogleDiscoveryClient.query("googleDiscovery", "getSource", {
9+
path: { scopeId, namespace },
10+
timeToLive: "15 seconds",
11+
});
12+
313
export const probeGoogleDiscovery = GoogleDiscoveryClient.mutation(
414
"googleDiscovery",
515
"probeDiscovery",

‎packages/plugins/google-discovery/src/sdk/binding-store.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ export interface GoogleDiscoveryBindingStore {
5555
readonly putSource: (source: GoogleDiscoveryStoredSource) => Effect.Effect<void>;
5656
readonly removeSource: (namespace: string) => Effect.Effect<void>;
5757
readonly listSources: () => Effect.Effect<readonly GoogleDiscoveryStoredSource[]>;
58+
readonly getSource: (
59+
namespace: string,
60+
) => Effect.Effect<GoogleDiscoveryStoredSource | null>;
5861
readonly getSourceConfig: (
5962
namespace: string,
6063
) => Effect.Effect<GoogleDiscoveryStoredSourceData | null>;
@@ -120,6 +123,14 @@ const makeStore = (
120123
return entries.map((e) => JSON.parse(e.value) as GoogleDiscoveryStoredSource);
121124
}),
122125

126+
getSource: (namespace) =>
127+
Effect.gen(function* () {
128+
const raw = yield* sources.get(namespace);
129+
if (!raw) return null;
130+
// @effect-diagnostics-next-line preferSchemaOverJson:off
131+
return JSON.parse(raw) as GoogleDiscoveryStoredSource;
132+
}),
133+
123134
getSourceConfig: (namespace) =>
124135
Effect.gen(function* () {
125136
const raw = yield* sources.get(namespace);

‎packages/plugins/google-discovery/src/sdk/plugin.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515

1616
import type {
1717
GoogleDiscoveryBindingStore,
18+
GoogleDiscoveryStoredSource,
1819
} from "./binding-store";
1920
import { makeInMemoryBindingStore } from "./binding-store";
2021
import { extractGoogleDiscoveryManifest } from "./document";
@@ -110,6 +111,9 @@ export interface GoogleDiscoveryPluginExtension {
110111
readonly completeOAuth: (
111112
input: GoogleDiscoveryOAuthCompleteInput,
112113
) => Effect.Effect<GoogleDiscoveryOAuthAuthResult, GoogleDiscoveryOAuthError>;
114+
readonly getSource: (
115+
namespace: string,
116+
) => Effect.Effect<GoogleDiscoveryStoredSource | null>;
113117
}
114118

115119
const DISCOVERY_SERVICE_HOST = "https://www.googleapis.com/discovery/v1/apis";
@@ -293,6 +297,7 @@ export const googleDiscoveryPlugin = (options?: {
293297
runtime: false,
294298
canRemove: true,
295299
canRefresh: true,
300+
canEdit: true,
296301
}),
297302
),
298303
),
@@ -558,6 +563,9 @@ export const googleDiscoveryPlugin = (options?: {
558563
scopes: [...session.scopes],
559564
};
560565
}),
566+
567+
getSource: (namespace: string) =>
568+
bindingStore.getSource(namespace),
561569
};
562570

563571
return {
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { Schema } from "effect";
2+
3+
import { GoogleDiscoveryStoredSourceData } from "./types";
4+
5+
// ---------------------------------------------------------------------------
6+
// Stored source — the shape persisted by the binding store and exposed
7+
// via the getSource HTTP endpoint.
8+
// ---------------------------------------------------------------------------
9+
10+
export class GoogleDiscoveryStoredSourceSchema extends Schema.Class<GoogleDiscoveryStoredSourceSchema>(
11+
"GoogleDiscoveryStoredSource",
12+
)({
13+
namespace: Schema.String,
14+
name: Schema.String,
15+
config: GoogleDiscoveryStoredSourceData,
16+
}) {}
17+
18+
export type GoogleDiscoveryStoredSourceSchemaType =
19+
typeof GoogleDiscoveryStoredSourceSchema.Type;

0 commit comments

Comments
 (0)