History

Extract Google bundle registration helper

Rhys Sullivan committed 4 months ago

Commit eb7ef351 parent 2be5cb61 file · +30 −9Browse files

Unified · Split

packages/plugins/google/src/sdk/plugin.ts+30−9
@@ -140,6 +140,7 @@ const googlePhotosBundleConsentScopes = ( · 139 unmodified lines
140140 const fetchGoogleBundleConversion = (
141141 urls: readonly string[],
142142 httpClientLayer: Layer.Layer<HttpClient.HttpClient, never, never>,
143+ consentScopesOverride?: readonly string[],
143144 ) =>
144145 Effect.forEach(
145146 urls,
@@ -151,10 +152,10 @@ const fetchGoogleBundleConversion = ( · 5 unmodified lines
151152 { concurrency: 4 },
152153 ).pipe(
153154 Effect.flatMap((documents) => {
154− const consentScopes = googlePhotosBundleConsentScopes(urls);
155+ const consentScopes = consentScopesOverride ?? googlePhotosBundleConsentScopes(urls);
155156 return convertGoogleDiscoveryBundleToOpenApi({
156157 documents,
157− ...(consentScopes ? { consentScopes } : {}),
158+ ...(consentScopes !== undefined ? { consentScopes } : {}),
158159 });
159160 }),
160161 );
@@ -215,12 +216,23 @@ const makeGooglePluginExtension = ( · 54 unmodified lines
215216 ) => {
216217 const httpClientLayer = options?.httpClientLayer ?? ctx.httpClientLayer;
217218
218− const addBundle = (config: GoogleBundleConfig) =>
219+ const addGoogleOpenApiIntegration = (input: {
220+ readonly urls: readonly string[];
221+ readonly slug: IntegrationSlug;
222+ readonly name: string;
223+ readonly description: string;
224+ readonly baseUrl?: string;
225+ readonly consentScopes?: readonly string[];
226+ }) =>
219227 Effect.gen(function* () {
220− const urls = yield* googleBundleUrlsWithIdentity(config.urls);
221− const conversion = yield* fetchGoogleBundleConversion(urls, httpClientLayer);
228+ const urls = yield* googleBundleUrlsWithIdentity(input.urls);
229+ const conversion = yield* fetchGoogleBundleConversion(
230+ urls,
231+ httpClientLayer,
232+ input.consentScopes,
233+ );
222234 const compiled = yield* compileOpenApiSpec(conversion.specText);
223− const slug = IntegrationSlug.make(config.slug?.trim() || DEFAULT_GOOGLE_SLUG);
235+ const slug = input.slug;
224236
225237 const existing = yield* ctx.core.integrations.get(slug);
226238 if (existing) {
@@ -231,7 +243,7 @@ const makeGooglePluginExtension = ( · 4 unmodified lines
231243 const integrationConfig: GoogleIntegrationConfig = {
232244 specHash,
233245 googleDiscoveryUrls: urls,
234− ...(config.baseUrl ? { baseUrl: config.baseUrl } : {}),
246+ ...(input.baseUrl ? { baseUrl: input.baseUrl } : {}),
235247 ...(conversion.authenticationTemplate
236248 ? { authenticationTemplate: conversion.authenticationTemplate }
237249 : {}),
@@ -244,8 +256,8 @@ const makeGooglePluginExtension = ( · 6 unmodified lines
244256 Effect.gen(function* () {
245257 yield* ctx.core.integrations.register({
246258 slug,
247− name: config.name?.trim() || "Google",
248− description: config.description ?? "Google APIs",
259+ name: input.name,
260+ description: input.description,
249261 config: integrationConfig satisfies GoogleIntegrationConfig as IntegrationConfig,
250262 canRemove: true,
251263 canRefresh: true,
@@ -268,6 +280,15 @@ const makeGooglePluginExtension = ( · 16 unmodified lines
268280 return { slug, toolCount: compiled.definitions.length };
269281 });
270282
283+ const addBundle = (config: GoogleBundleConfig) =>
284+ addGoogleOpenApiIntegration({
285+ urls: config.urls,
286+ slug: IntegrationSlug.make(config.slug?.trim() || DEFAULT_GOOGLE_SLUG),
287+ name: config.name?.trim() || "Google",
288+ description: config.description ?? "Google APIs",
289+ baseUrl: config.baseUrl,
290+ });
291+
271292 const updateBundle = (rawSlug: string, input?: GoogleUpdateInput) =>
272293 Effect.gen(function* () {
273294 const slug = IntegrationSlug.make(rawSlug);