-
Notifications
You must be signed in to change notification settings - Fork 166
Expand file tree
/
Copy pathhandlers.ts
More file actions
116 lines (112 loc) · 3.78 KB
/
Copy pathhandlers.ts
File metadata and controls
116 lines (112 loc) · 3.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import { HttpApiBuilder } from "effect/unstable/httpapi";
import { Context, Effect } from "effect";
import { addGroup, capture } from "@executor-js/api";
import type { GooglePluginExtension } from "../sdk/plugin";
import { GoogleGroup } from "./group";
export class GoogleExtensionService extends Context.Service<
GoogleExtensionService,
GooglePluginExtension
>()("GoogleExtensionService") {}
const ExecutorApiWithGoogle = addGroup(GoogleGroup);
export const GoogleHandlers = HttpApiBuilder.group(ExecutorApiWithGoogle, "google", (handlers) =>
handlers
.handle("addBundle", ({ payload }) =>
capture(
Effect.gen(function* () {
const ext = yield* GoogleExtensionService;
return yield* ext.addBundle({
urls: payload.urls,
slug: payload.slug,
name: payload.name,
description: payload.description,
baseUrl: payload.baseUrl,
});
}),
),
)
.handle("addServices", ({ payload }) =>
capture(
Effect.gen(function* () {
const ext = yield* GoogleExtensionService;
return yield* ext.addServices({
services: payload.services,
baseUrl: payload.baseUrl,
});
}),
),
)
.handle("getIntegration", ({ params }) =>
capture(
Effect.gen(function* () {
const ext = yield* GoogleExtensionService;
const integration = yield* ext.getIntegration(params.slug);
return integration
? {
slug: integration.slug,
description: integration.description,
kind: integration.kind,
canRemove: integration.canRemove,
canRefresh: integration.canRefresh,
}
: null;
}),
),
)
.handle("getConfig", ({ params }) =>
capture(
Effect.gen(function* () {
const ext = yield* GoogleExtensionService;
const config = yield* ext.getConfig(params.slug);
return config
? {
googleDiscoveryUrls: config.googleDiscoveryUrls
? [...config.googleDiscoveryUrls]
: undefined,
baseUrl: config.baseUrl,
headers: config.headers ? { ...config.headers } : undefined,
queryParams: config.queryParams ? { ...config.queryParams } : undefined,
authenticationTemplate: config.authenticationTemplate
? [...config.authenticationTemplate]
: undefined,
}
: null;
}),
),
)
.handle("configure", ({ params, payload }) =>
capture(
Effect.gen(function* () {
const ext = yield* GoogleExtensionService;
const authenticationTemplate = yield* ext.configure(params.slug, {
authenticationTemplate: payload.authenticationTemplate,
mode: payload.mode ?? "merge",
});
return { authenticationTemplate: [...authenticationTemplate] };
}),
),
)
.handle("updateBundle", ({ params, payload }) =>
capture(
Effect.gen(function* () {
const ext = yield* GoogleExtensionService;
const result = yield* ext.updateBundle(params.slug, {
...(payload.urls !== undefined ? { urls: payload.urls } : {}),
});
return {
slug: result.slug,
toolCount: result.toolCount,
addedTools: [...result.addedTools],
removedTools: [...result.removedTools],
};
}),
),
)
.handle("removeBundle", ({ params }) =>
capture(
Effect.gen(function* () {
const ext = yield* GoogleExtensionService;
yield* ext.removeBundle(params.slug);
}),
),
),
);