@executor-js/plugin-openapi 1.4.33 → 1.5.1

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.
Files changed (81) hide show
  1. package/dist/AddOpenApiSource-7M52SRUX.js +893 -0
  2. package/dist/AddOpenApiSource-7M52SRUX.js.map +1 -0
  3. package/dist/EditOpenApiSource-WTAMRJUK.js +68 -0
  4. package/dist/EditOpenApiSource-WTAMRJUK.js.map +1 -0
  5. package/dist/OpenApiAccountsPanel-3VJJXNQF.js +112 -0
  6. package/dist/OpenApiAccountsPanel-3VJJXNQF.js.map +1 -0
  7. package/dist/api/group.d.ts +104 -225
  8. package/dist/api/index.d.ts +127 -271
  9. package/dist/{chunk-BB5IAKRG.js → chunk-AQ7JDDRM.js} +12 -2
  10. package/dist/chunk-AQ7JDDRM.js.map +1 -0
  11. package/dist/chunk-BSLE6HCE.js +181 -0
  12. package/dist/chunk-BSLE6HCE.js.map +1 -0
  13. package/dist/chunk-MZWZQ24W.js +226 -0
  14. package/dist/chunk-MZWZQ24W.js.map +1 -0
  15. package/dist/chunk-OSIFYIQP.js +623 -0
  16. package/dist/chunk-OSIFYIQP.js.map +1 -0
  17. package/dist/chunk-QSSRVK6M.js +139 -0
  18. package/dist/chunk-QSSRVK6M.js.map +1 -0
  19. package/dist/chunk-V7VCHYOY.js +1544 -0
  20. package/dist/chunk-V7VCHYOY.js.map +1 -0
  21. package/dist/{chunk-AN4HJFNP.js → chunk-YVRI7KRC.js} +162 -186
  22. package/dist/chunk-YVRI7KRC.js.map +1 -0
  23. package/dist/client.js +9 -8
  24. package/dist/client.js.map +1 -1
  25. package/dist/core.js +28 -11
  26. package/dist/index.js +11 -4
  27. package/dist/react/AddOpenApiSource.d.ts +2 -13
  28. package/dist/react/GoogleProductPicker.d.ts +9 -0
  29. package/dist/react/OpenApiAccountsPanel.d.ts +6 -0
  30. package/dist/react/OpenApiSourceDetailsFields.d.ts +3 -2
  31. package/dist/react/atoms.d.ts +177 -192
  32. package/dist/react/auth-method-config.d.ts +15 -0
  33. package/dist/react/client.d.ts +103 -224
  34. package/dist/react/index.d.ts +2 -2
  35. package/dist/react/source-plugin.d.ts +2 -2
  36. package/dist/sdk/config.d.ts +75 -0
  37. package/dist/sdk/configure.test.d.ts +1 -0
  38. package/dist/sdk/describe-auth-methods.test.d.ts +1 -0
  39. package/dist/sdk/errors.d.ts +4 -6
  40. package/dist/sdk/extract.d.ts +7 -5
  41. package/dist/sdk/google-bundle.test.d.ts +1 -0
  42. package/dist/sdk/google-discovery.d.ts +43 -0
  43. package/dist/sdk/google-discovery.test.d.ts +1 -0
  44. package/dist/sdk/google-oauth-batches.d.ts +13 -0
  45. package/dist/sdk/google-oauth-batches.test.d.ts +1 -0
  46. package/dist/sdk/google-oauth-scopes.d.ts +3 -0
  47. package/dist/sdk/google-oauth-scopes.test.d.ts +1 -0
  48. package/dist/sdk/google-presets.d.ts +16 -0
  49. package/dist/sdk/google-presets.test.d.ts +1 -0
  50. package/dist/sdk/google-product-picker-scopes.test.d.ts +1 -0
  51. package/dist/sdk/index.d.ts +7 -5
  52. package/dist/sdk/invoke.d.ts +6 -9
  53. package/dist/sdk/openapi-utils.d.ts +1 -0
  54. package/dist/sdk/plugin.d.ts +74 -231
  55. package/dist/sdk/presets.d.ts +2 -1
  56. package/dist/sdk/preview.d.ts +20 -15
  57. package/dist/sdk/query-serialization.test.d.ts +1 -0
  58. package/dist/sdk/store.d.ts +14 -41
  59. package/dist/sdk/types.d.ts +23 -51
  60. package/dist/testing/index.d.ts +49 -38
  61. package/dist/testing.js +46 -18
  62. package/dist/testing.js.map +1 -1
  63. package/package.json +6 -4
  64. package/dist/AddOpenApiSource-NSCULGTM.js +0 -19
  65. package/dist/AddOpenApiSource-NSCULGTM.js.map +0 -1
  66. package/dist/EditOpenApiSource-MV7NYTRP.js +0 -774
  67. package/dist/EditOpenApiSource-MV7NYTRP.js.map +0 -1
  68. package/dist/OpenApiSourceSummary-7JBS7PUV.js +0 -122
  69. package/dist/OpenApiSourceSummary-7JBS7PUV.js.map +0 -1
  70. package/dist/chunk-2ZKKZYZH.js +0 -1181
  71. package/dist/chunk-2ZKKZYZH.js.map +0 -1
  72. package/dist/chunk-AN4HJFNP.js.map +0 -1
  73. package/dist/chunk-BB5IAKRG.js.map +0 -1
  74. package/dist/chunk-PRVJDE43.js +0 -2101
  75. package/dist/chunk-PRVJDE43.js.map +0 -1
  76. package/dist/chunk-X5JX3KTA.js +0 -201
  77. package/dist/chunk-X5JX3KTA.js.map +0 -1
  78. package/dist/react/OpenApiSourceSummary.d.ts +0 -5
  79. package/dist/sdk/credential-status.d.ts +0 -23
  80. package/dist/sdk/source-contracts.d.ts +0 -55
  81. /package/dist/{sdk/credential-status.test.d.ts → react/auth-method-config.test.d.ts} +0 -0
@@ -0,0 +1,623 @@
1
+ import {
2
+ OpenApiParseError
3
+ } from "./chunk-YVRI7KRC.js";
4
+
5
+ // src/sdk/google-discovery.ts
6
+ import { Effect, Option, Predicate, Schema, SchemaGetter } from "effect";
7
+ import { HttpClient, HttpClientRequest } from "effect/unstable/http";
8
+
9
+ // src/sdk/google-oauth-scopes.ts
10
+ var googleUserConsentBlockedScopes = /* @__PURE__ */ new Set([
11
+ "https://www.googleapis.com/auth/chat.bot",
12
+ "https://www.googleapis.com/auth/chat.import",
13
+ "https://www.googleapis.com/auth/keep",
14
+ "https://www.googleapis.com/auth/keep.readonly"
15
+ ]);
16
+ var googleUserConsentBlockedScopePrefixes = ["https://www.googleapis.com/auth/chat.app."];
17
+ var googleBroadScopeGroups = [
18
+ {
19
+ broad: "https://mail.google.com/",
20
+ prefixes: ["https://www.googleapis.com/auth/gmail."]
21
+ },
22
+ {
23
+ broad: "https://www.googleapis.com/auth/calendar",
24
+ prefixes: ["https://www.googleapis.com/auth/calendar."]
25
+ },
26
+ {
27
+ broad: "https://www.googleapis.com/auth/drive",
28
+ prefixes: ["https://www.googleapis.com/auth/drive."]
29
+ }
30
+ ];
31
+ var normalizeGoogleIdentityScope = (scope) => scope === "https://www.googleapis.com/auth/userinfo.email" ? "email" : scope === "https://www.googleapis.com/auth/userinfo.profile" ? "profile" : scope;
32
+ var orderedUniqueScopes = (scopes) => {
33
+ const ordered = [];
34
+ const seen = /* @__PURE__ */ new Set();
35
+ for (const scope of scopes) {
36
+ const trimmed = scope.trim();
37
+ if (!trimmed || seen.has(trimmed)) continue;
38
+ seen.add(trimmed);
39
+ ordered.push(trimmed);
40
+ }
41
+ return ordered;
42
+ };
43
+ var isGoogleUserConsentOAuthScope = (scope) => !googleUserConsentBlockedScopes.has(scope) && !googleUserConsentBlockedScopePrefixes.some((prefix) => scope.startsWith(prefix));
44
+ var filterGoogleUserConsentOAuthScopes = (scopes) => orderedUniqueScopes(scopes).filter(isGoogleUserConsentOAuthScope);
45
+ var compactGoogleOAuthScopes = (scopes) => {
46
+ const ordered = filterGoogleUserConsentOAuthScopes([...scopes].map(normalizeGoogleIdentityScope));
47
+ const present = new Set(ordered);
48
+ return ordered.filter(
49
+ (scope) => !googleBroadScopeGroups.some(
50
+ (group) => scope !== group.broad && present.has(group.broad) && group.prefixes.some((prefix) => scope.startsWith(prefix))
51
+ )
52
+ );
53
+ };
54
+
55
+ // src/sdk/google-discovery.ts
56
+ import { AuthTemplateSlug } from "@executor-js/sdk/shared";
57
+ var DISCOVERY_SERVICE_HOST = "https://www.googleapis.com/discovery/v1/apis";
58
+ var GOOGLE_BUNDLE_BASE_URL = "https://www.googleapis.com/";
59
+ var GOOGLE_OAUTH_AUTHORIZATION_URL = "https://accounts.google.com/o/oauth2/v2/auth";
60
+ var GOOGLE_OAUTH_TOKEN_URL = "https://oauth2.googleapis.com/token";
61
+ var OPENAPI_SCHEMA_TYPES = /* @__PURE__ */ new Set([
62
+ "array",
63
+ "boolean",
64
+ "integer",
65
+ "null",
66
+ "number",
67
+ "object",
68
+ "string"
69
+ ]);
70
+ var TextOption = Schema.OptionFromOptional(Schema.Trim).pipe(
71
+ Schema.decode({
72
+ decode: SchemaGetter.transform((value) => Option.filter(value, (text) => text.length > 0)),
73
+ encode: SchemaGetter.transform((value) => value)
74
+ }),
75
+ Schema.withDecodingDefaultType(Effect.succeed(Option.none()))
76
+ );
77
+ var TextArray = Schema.optional(Schema.Array(Schema.String)).pipe(
78
+ Schema.withDecodingDefaultType(Effect.succeed([]))
79
+ );
80
+ var UnknownRecord = Schema.Record(Schema.String, Schema.Unknown);
81
+ var UnknownRecordWithDefault = Schema.optional(UnknownRecord).pipe(
82
+ Schema.withDecodingDefaultType(Effect.succeed({}))
83
+ );
84
+ var DiscoveryParameter = Schema.Struct({
85
+ type: Schema.optional(Schema.String),
86
+ description: TextOption,
87
+ properties: UnknownRecordWithDefault,
88
+ items: Schema.optional(Schema.Unknown),
89
+ additionalProperties: Schema.optional(Schema.Union([Schema.Boolean, Schema.Unknown])),
90
+ enum: TextArray,
91
+ format: Schema.optional(Schema.String),
92
+ readOnly: Schema.optional(Schema.Boolean),
93
+ default: Schema.optional(Schema.Union([Schema.String, Schema.Number, Schema.Boolean])),
94
+ $ref: Schema.optional(Schema.String),
95
+ location: Schema.optional(Schema.Literals(["path", "query", "header"])),
96
+ required: Schema.optional(Schema.Boolean),
97
+ repeated: Schema.optional(Schema.Boolean)
98
+ });
99
+ var DiscoveryRef = Schema.Struct({
100
+ $ref: Schema.optional(Schema.String)
101
+ });
102
+ var DiscoveryMethod = Schema.Struct({
103
+ id: TextOption,
104
+ description: TextOption,
105
+ httpMethod: Schema.optional(Schema.String),
106
+ path: TextOption,
107
+ parameters: UnknownRecordWithDefault,
108
+ request: Schema.optional(DiscoveryRef),
109
+ response: Schema.optional(DiscoveryRef),
110
+ scopes: TextArray
111
+ });
112
+ var DiscoveryResource = Schema.Struct({
113
+ methods: UnknownRecordWithDefault,
114
+ resources: UnknownRecordWithDefault
115
+ });
116
+ var DiscoveryDocument = Schema.Struct({
117
+ name: TextOption,
118
+ version: TextOption,
119
+ title: TextOption,
120
+ rootUrl: TextOption,
121
+ servicePath: Schema.optional(Schema.Trim).pipe(
122
+ Schema.withDecodingDefaultType(Effect.succeed(""))
123
+ ),
124
+ parameters: UnknownRecordWithDefault,
125
+ methods: UnknownRecordWithDefault,
126
+ resources: UnknownRecordWithDefault,
127
+ schemas: UnknownRecordWithDefault,
128
+ auth: Schema.optional(
129
+ Schema.Struct({
130
+ oauth2: Schema.optional(
131
+ Schema.Struct({
132
+ scopes: Schema.optional(
133
+ Schema.Record(
134
+ Schema.String,
135
+ Schema.Struct({
136
+ description: TextOption
137
+ })
138
+ )
139
+ ).pipe(Schema.withDecodingDefaultType(Effect.succeed({})))
140
+ })
141
+ )
142
+ })
143
+ )
144
+ });
145
+ var decodeDiscoveryDocument = Schema.decodeUnknownSync(DiscoveryDocument);
146
+ var decodeDiscoveryParameter = Schema.decodeUnknownSync(DiscoveryParameter);
147
+ var decodeDiscoveryMethod = Schema.decodeUnknownSync(DiscoveryMethod);
148
+ var decodeDiscoveryResource = Schema.decodeUnknownSync(DiscoveryResource);
149
+ var parseJson = Schema.decodeUnknownEffect(Schema.fromJsonString(Schema.Unknown));
150
+ var normalizeDiscoveryUrl = (discoveryUrl) => {
151
+ const trimmed = discoveryUrl.trim();
152
+ if (!URL.canParse(trimmed)) return trimmed;
153
+ const parsed = new URL(trimmed);
154
+ if (parsed.pathname !== "/$discovery/rest") return trimmed;
155
+ const version = parsed.searchParams.get("version")?.trim();
156
+ if (!version) return trimmed;
157
+ const host = parsed.hostname.toLowerCase();
158
+ if (!host.endsWith(".googleapis.com")) return trimmed;
159
+ const rawService = host.slice(0, -".googleapis.com".length);
160
+ const service = rawService === "calendar-json" ? "calendar" : rawService.endsWith("-json") ? rawService.slice(0, -5) : rawService;
161
+ return service ? `${DISCOVERY_SERVICE_HOST}/${service}/${version}/rest` : trimmed;
162
+ };
163
+ var isGoogleDiscoveryUrl = (url) => {
164
+ const trimmed = url.trim();
165
+ if (!URL.canParse(trimmed)) return false;
166
+ const parsed = new URL(trimmed);
167
+ const host = parsed.hostname.toLowerCase();
168
+ if (!host.endsWith("googleapis.com")) return false;
169
+ return parsed.pathname.includes("/discovery/") || parsed.pathname.includes("$discovery");
170
+ };
171
+ var fetchGoogleDiscoveryDocument = Effect.fn("OpenApi.fetchGoogleDiscoveryDocument")(
172
+ function* (discoveryUrl, credentials) {
173
+ const client = yield* HttpClient.HttpClient;
174
+ const requestUrl = new URL(discoveryUrl);
175
+ for (const [name, value] of Object.entries(credentials?.queryParams ?? {})) {
176
+ requestUrl.searchParams.set(name, value);
177
+ }
178
+ let request = HttpClientRequest.get(requestUrl.toString()).pipe(
179
+ HttpClientRequest.setHeader("Accept", "application/json, */*")
180
+ );
181
+ for (const [name, value] of Object.entries(credentials?.headers ?? {})) {
182
+ request = HttpClientRequest.setHeader(request, name, value);
183
+ }
184
+ const response = yield* client.execute(request).pipe(
185
+ Effect.mapError(
186
+ () => new OpenApiParseError({
187
+ message: "Failed to fetch Google Discovery document"
188
+ })
189
+ )
190
+ );
191
+ if (response.status < 200 || response.status >= 300) {
192
+ return yield* new OpenApiParseError({
193
+ message: `Failed to fetch Google Discovery document: HTTP ${response.status}`
194
+ });
195
+ }
196
+ return yield* response.text.pipe(
197
+ Effect.mapError(
198
+ () => new OpenApiParseError({
199
+ message: "Failed to read Google Discovery document body"
200
+ })
201
+ )
202
+ );
203
+ }
204
+ );
205
+ var schemaRef = (name) => `#/components/schemas/${name}`;
206
+ var identitySchemaName = (name) => name;
207
+ var schemaComponentPart = (value) => value.trim().replace(/[^A-Za-z0-9._-]+/g, "_").replace(/^_+|_+$/g, "") || "schema";
208
+ var normalizeDiscoveryPathTemplate = (pathTemplate) => pathTemplate.replaceAll(/\{\+([^{}]+)\}/g, "{$1}");
209
+ var pathUsesReservedExpansion = (pathTemplate, parameterName) => pathTemplate.includes(`{+${parameterName}}`);
210
+ var uniquePathKey = (paths, preferredPath, method, toolPath) => {
211
+ if (!paths[preferredPath]?.[method]) return preferredPath;
212
+ const disambiguated = `/${toolPath.replace(/[^A-Za-z0-9._~-]+/g, "/")}`;
213
+ if (!paths[disambiguated]?.[method]) return disambiguated;
214
+ let index = 2;
215
+ while (paths[`${disambiguated}/${index}`]?.[method]) index += 1;
216
+ return `${disambiguated}/${index}`;
217
+ };
218
+ var discoveryDescription = (value) => typeof value === "string" ? value : Option.isOption(value) && Option.isSome(value) ? typeof value.value === "string" ? value.value : void 0 : void 0;
219
+ var isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
220
+ var jsonValue = (value) => {
221
+ if (value === null || typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
222
+ return value;
223
+ }
224
+ if (Array.isArray(value)) {
225
+ const values = value.map(jsonValue);
226
+ return values.every(Predicate.isNotUndefined) ? values : void 0;
227
+ }
228
+ if (!isRecord(value)) return void 0;
229
+ const entries = Object.entries(value).flatMap(([key, item]) => {
230
+ const converted = jsonValue(item);
231
+ return converted === void 0 ? [] : [[key, converted]];
232
+ });
233
+ return Object.fromEntries(entries);
234
+ };
235
+ var stringArray = (value) => {
236
+ if (!Array.isArray(value)) return void 0;
237
+ const strings = value.filter((item) => typeof item === "string");
238
+ return strings.length === value.length ? strings : void 0;
239
+ };
240
+ var schemaType = (value) => typeof value === "string" && OPENAPI_SCHEMA_TYPES.has(value) ? value : void 0;
241
+ var discoverySchemaToOpenApiSchema = (raw, schemaNameForRef = identitySchemaName) => {
242
+ if (!isRecord(raw)) return {};
243
+ const schema = raw;
244
+ if (typeof schema.$ref === "string") return { $ref: schemaRef(schemaNameForRef(schema.$ref)) };
245
+ const description = discoveryDescription(schema.description);
246
+ const title = discoveryDescription(schema.title);
247
+ const defaultValue = jsonValue(schema.default);
248
+ const enumValues = Array.isArray(schema.enum) ? schema.enum.map(jsonValue).filter(Predicate.isNotUndefined) : [];
249
+ const format = typeof schema.format === "string" ? schema.format : void 0;
250
+ const readOnly = typeof schema.readOnly === "boolean" ? schema.readOnly : void 0;
251
+ const type = schemaType(schema.type);
252
+ const base = {
253
+ ...description !== void 0 ? { description } : {},
254
+ ...title !== void 0 ? { title } : {},
255
+ ...format !== void 0 ? { format } : {},
256
+ ...readOnly !== void 0 ? { readOnly } : {},
257
+ ...defaultValue !== void 0 ? { default: defaultValue } : {},
258
+ ...enumValues.length > 0 ? { enum: enumValues } : {}
259
+ };
260
+ if (type === "array") {
261
+ return {
262
+ ...base,
263
+ type: "array",
264
+ items: discoverySchemaToOpenApiSchema(schema.items, schemaNameForRef)
265
+ };
266
+ }
267
+ const properties = schema.properties;
268
+ if (type === "object" || isRecord(properties) && Object.keys(properties).length > 0 || schema.additionalProperties !== void 0) {
269
+ const convertedProperties = isRecord(properties) ? Object.fromEntries(
270
+ Object.entries(properties).map(([name, value]) => [
271
+ name,
272
+ discoverySchemaToOpenApiSchema(value, schemaNameForRef)
273
+ ])
274
+ ) : void 0;
275
+ const required = stringArray(schema.required);
276
+ const additionalProperties = schema.additionalProperties === void 0 ? void 0 : typeof schema.additionalProperties === "boolean" ? schema.additionalProperties : discoverySchemaToOpenApiSchema(schema.additionalProperties, schemaNameForRef);
277
+ return {
278
+ ...base,
279
+ type: "object",
280
+ ...convertedProperties && Object.keys(convertedProperties).length > 0 ? { properties: convertedProperties } : {},
281
+ ...required && required.length > 0 ? { required } : {},
282
+ ...additionalProperties !== void 0 ? { additionalProperties } : {}
283
+ };
284
+ }
285
+ return type !== void 0 ? { ...base, type } : base;
286
+ };
287
+ var parameterSchema = (parameter, schemaNameForRef = identitySchemaName) => {
288
+ const base = discoverySchemaToOpenApiSchema(parameter, schemaNameForRef);
289
+ return parameter.repeated ? {
290
+ type: "array",
291
+ items: base
292
+ } : base;
293
+ };
294
+ var methodToolPath = (service, methodId) => methodId.startsWith(`${service}.`) ? methodId.slice(service.length + 1) : methodId;
295
+ var collectMethods = (resource) => {
296
+ const decoded = decodeDiscoveryResource(resource);
297
+ const direct = Object.values(decoded.methods ?? {}).map((raw) => decodeDiscoveryMethod(raw));
298
+ const nested = Object.values(decoded.resources ?? {}).flatMap(collectMethods);
299
+ return [...direct, ...nested];
300
+ };
301
+ var discoveryScopes = (document) => Object.fromEntries(
302
+ Object.entries(document.auth?.oauth2?.scopes ?? {}).map(([scope, value]) => [
303
+ scope,
304
+ Option.getOrElse(value.description, () => "")
305
+ ])
306
+ );
307
+ var compactDiscoveryScopeMap = (raw) => {
308
+ const descriptionFor = (scope) => {
309
+ if (raw[scope] !== void 0) return raw[scope];
310
+ if (scope === "email") return raw["https://www.googleapis.com/auth/userinfo.email"] ?? "";
311
+ if (scope === "profile") return raw["https://www.googleapis.com/auth/userinfo.profile"] ?? "";
312
+ return "";
313
+ };
314
+ return Object.fromEntries(
315
+ compactGoogleOAuthScopes(Object.keys(raw)).map((scope) => [scope, descriptionFor(scope)])
316
+ );
317
+ };
318
+ var allDiscoveryMethods = (document) => [
319
+ ...Object.values(document.methods ?? {}).map((raw) => decodeDiscoveryMethod(raw)),
320
+ ...Object.values(document.resources ?? {}).flatMap(collectMethods)
321
+ ];
322
+ var discoveryDocumentInfo = (document, discoveryUrl) => Effect.gen(function* () {
323
+ const service = Option.getOrUndefined(document.name);
324
+ const version = Option.getOrUndefined(document.version);
325
+ const rootUrl = Option.getOrUndefined(document.rootUrl);
326
+ if (!service || !version || !rootUrl) {
327
+ return yield* new OpenApiParseError({
328
+ message: "Google Discovery document is missing one of: name, version, rootUrl"
329
+ });
330
+ }
331
+ return {
332
+ discoveryUrl,
333
+ document,
334
+ service,
335
+ version,
336
+ rootUrl,
337
+ baseUrl: new URL(document.servicePath || "", rootUrl).toString(),
338
+ title: Option.getOrElse(document.title, () => `${service} ${version}`)
339
+ };
340
+ });
341
+ var buildDiscoveryOperation = (input) => {
342
+ const mergedParameters = /* @__PURE__ */ new Map();
343
+ for (const [name, raw] of Object.entries(input.document.parameters ?? {})) {
344
+ const parameter = decodeDiscoveryParameter(raw);
345
+ if (parameter.location) mergedParameters.set(name, parameter);
346
+ }
347
+ for (const [name, raw] of Object.entries(input.method.parameters ?? {})) {
348
+ const parameter = decodeDiscoveryParameter(raw);
349
+ if (parameter.location) mergedParameters.set(name, parameter);
350
+ }
351
+ const methodScopes = input.method.scopes ?? [];
352
+ const methodDescription = Option.getOrUndefined(input.method.description);
353
+ const schemaNameForRef = input.schemaNameForRef ?? identitySchemaName;
354
+ return {
355
+ operationId: input.toolPath,
356
+ "x-executor-toolPath": input.toolPath,
357
+ "x-executor-pathTemplate": input.pathTemplate,
358
+ ...input.tags && input.tags.length > 0 ? { tags: input.tags } : {},
359
+ ...methodDescription !== void 0 ? { description: methodDescription } : {},
360
+ ...input.serverUrl ? { servers: [{ url: input.serverUrl }] } : {},
361
+ parameters: [...mergedParameters.entries()].flatMap(([name, parameter]) => {
362
+ const location = parameter.location;
363
+ if (!location) return [];
364
+ const description = Option.getOrUndefined(parameter.description);
365
+ const allowReserved = location === "path" && pathUsesReservedExpansion(input.pathTemplate, name);
366
+ return [
367
+ {
368
+ name,
369
+ in: location,
370
+ required: location === "path" ? true : parameter.required === true,
371
+ ...description !== void 0 ? { description } : {},
372
+ schema: parameterSchema(parameter, schemaNameForRef),
373
+ ...location === "query" ? { style: "form", explode: parameter.repeated === true } : {},
374
+ ...allowReserved ? { allowReserved: true } : {}
375
+ }
376
+ ];
377
+ }),
378
+ ...input.method.request?.$ref ? {
379
+ requestBody: {
380
+ required: false,
381
+ content: {
382
+ "application/json": {
383
+ schema: { $ref: schemaRef(schemaNameForRef(input.method.request.$ref)) }
384
+ }
385
+ }
386
+ }
387
+ } : {},
388
+ responses: {
389
+ "200": {
390
+ description: "Successful response",
391
+ content: {
392
+ "application/json": {
393
+ schema: input.method.response?.$ref ? { $ref: schemaRef(schemaNameForRef(input.method.response.$ref)) } : {}
394
+ }
395
+ }
396
+ }
397
+ },
398
+ ...methodScopes.length > 0 ? { security: [{ googleOAuth2: methodScopes }] } : {},
399
+ "x-google-scopes": methodScopes
400
+ };
401
+ };
402
+ var GOOGLE_OAUTH_SECURITY_SCHEME = "googleOAuth2";
403
+ var googleOauthTemplate = (scopes) => (
404
+ // A Google-discovery integration is ALWAYS OAuth, so it ALWAYS declares its
405
+ // oauth method — even when the compacted scope set is empty (e.g. a bundle of
406
+ // only limited-consent APIs like Google Keep, whose scopes Google won't grant
407
+ // through standard consent). Without this the integration declares no auth
408
+ // method and the "Add account" / "Add a connection" actions are disabled, so
409
+ // you can't even start the flow. Empty `scopes` just requests no scope.
410
+ [
411
+ {
412
+ slug: AuthTemplateSlug.make(GOOGLE_OAUTH_SECURITY_SCHEME),
413
+ type: "oauth",
414
+ authorizationUrl: GOOGLE_OAUTH_AUTHORIZATION_URL,
415
+ tokenUrl: GOOGLE_OAUTH_TOKEN_URL,
416
+ scopes: Object.keys(scopes)
417
+ }
418
+ ]
419
+ );
420
+ var convertGoogleDiscoveryToOpenApi = Effect.fn("OpenApi.convertGoogleDiscovery")(
421
+ function* (input) {
422
+ const parsed = yield* parseJson(input.documentText).pipe(
423
+ Effect.mapError(
424
+ () => new OpenApiParseError({
425
+ message: "Failed to parse Google Discovery document"
426
+ })
427
+ )
428
+ );
429
+ const document = yield* Effect.try({
430
+ try: () => decodeDiscoveryDocument(parsed),
431
+ catch: () => new OpenApiParseError({
432
+ message: "Failed to decode Google Discovery document"
433
+ })
434
+ });
435
+ const info = yield* discoveryDocumentInfo(document, input.discoveryUrl);
436
+ const { service, version, baseUrl, title } = info;
437
+ const paths = {};
438
+ for (const method of allDiscoveryMethods(document)) {
439
+ const methodId = Option.getOrUndefined(method.id);
440
+ const pathTemplate = Option.getOrUndefined(method.path);
441
+ if (!methodId || !pathTemplate || !method.httpMethod) continue;
442
+ const toolPath = methodToolPath(service, methodId);
443
+ const path = normalizeDiscoveryPathTemplate(
444
+ pathTemplate.startsWith("/") ? pathTemplate : `/${pathTemplate}`
445
+ );
446
+ const methodKey = method.httpMethod.toLowerCase();
447
+ const pathKey = uniquePathKey(paths, path, methodKey, toolPath);
448
+ paths[pathKey] ??= {};
449
+ paths[pathKey][methodKey] = buildDiscoveryOperation({
450
+ document,
451
+ method,
452
+ toolPath,
453
+ pathTemplate: pathTemplate.startsWith("/") ? pathTemplate : `/${pathTemplate}`
454
+ });
455
+ }
456
+ const scopes = compactDiscoveryScopeMap(discoveryScopes(document));
457
+ const authenticationTemplate = googleOauthTemplate(scopes);
458
+ const spec = {
459
+ openapi: "3.1.0",
460
+ info: {
461
+ title,
462
+ version
463
+ },
464
+ servers: [{ url: baseUrl }],
465
+ paths,
466
+ components: {
467
+ schemas: Object.fromEntries(
468
+ Object.entries(document.schemas ?? {}).map(([name, schema]) => [
469
+ name,
470
+ discoverySchemaToOpenApiSchema(schema)
471
+ ])
472
+ ),
473
+ ...authenticationTemplate ? {
474
+ securitySchemes: {
475
+ googleOAuth2: {
476
+ type: "oauth2",
477
+ flows: {
478
+ authorizationCode: {
479
+ authorizationUrl: GOOGLE_OAUTH_AUTHORIZATION_URL,
480
+ tokenUrl: GOOGLE_OAUTH_TOKEN_URL,
481
+ scopes
482
+ }
483
+ }
484
+ }
485
+ }
486
+ } : {}
487
+ },
488
+ ...authenticationTemplate ? { security: [{ googleOAuth2: Object.keys(scopes) }] } : {},
489
+ "x-executor-origin": {
490
+ kind: "googleDiscovery",
491
+ discoveryUrl: normalizeDiscoveryUrl(input.discoveryUrl),
492
+ service,
493
+ version
494
+ }
495
+ };
496
+ return {
497
+ // @effect-diagnostics-next-line preferSchemaOverJson:off
498
+ specText: JSON.stringify(spec),
499
+ baseUrl,
500
+ title,
501
+ service,
502
+ version,
503
+ ...authenticationTemplate ? { authenticationTemplate } : {}
504
+ };
505
+ }
506
+ );
507
+ var convertGoogleDiscoveryBundleToOpenApi = Effect.fn(
508
+ "OpenApi.convertGoogleDiscoveryBundle"
509
+ )(function* (input) {
510
+ if (input.documents.length === 0) {
511
+ return yield* new OpenApiParseError({
512
+ message: "Google Discovery bundle requires at least one document"
513
+ });
514
+ }
515
+ const infos = yield* Effect.forEach(
516
+ input.documents,
517
+ ({ discoveryUrl, documentText }) => Effect.gen(function* () {
518
+ const parsed = yield* parseJson(documentText).pipe(
519
+ Effect.mapError(
520
+ () => new OpenApiParseError({
521
+ message: "Failed to parse Google Discovery document"
522
+ })
523
+ )
524
+ );
525
+ const document = yield* Effect.try({
526
+ try: () => decodeDiscoveryDocument(parsed),
527
+ catch: () => new OpenApiParseError({
528
+ message: "Failed to decode Google Discovery document"
529
+ })
530
+ });
531
+ return yield* discoveryDocumentInfo(document, discoveryUrl);
532
+ })
533
+ );
534
+ const paths = {};
535
+ const schemas = {};
536
+ const rawScopes = {};
537
+ for (const info of infos) {
538
+ const schemaPrefix = schemaComponentPart(`${info.service}_${info.version}`);
539
+ const schemaNameForRef = (name) => `${schemaPrefix}_${schemaComponentPart(name)}`;
540
+ for (const [scope, description] of Object.entries(discoveryScopes(info.document))) {
541
+ rawScopes[scope] ??= description;
542
+ }
543
+ for (const [name, schema] of Object.entries(info.document.schemas ?? {})) {
544
+ schemas[schemaNameForRef(name)] = discoverySchemaToOpenApiSchema(schema, schemaNameForRef);
545
+ }
546
+ for (const method of allDiscoveryMethods(info.document)) {
547
+ const methodId = Option.getOrUndefined(method.id);
548
+ const rawPathTemplate = Option.getOrUndefined(method.path);
549
+ if (!methodId || !rawPathTemplate || !method.httpMethod) continue;
550
+ const toolPath = methodId;
551
+ const wirePath = rawPathTemplate.startsWith("/") ? rawPathTemplate : `/${rawPathTemplate}`;
552
+ const openApiPath = normalizeDiscoveryPathTemplate(wirePath);
553
+ const methodKey = method.httpMethod.toLowerCase();
554
+ const pathKey = uniquePathKey(paths, openApiPath, methodKey, toolPath);
555
+ paths[pathKey] ??= {};
556
+ paths[pathKey][methodKey] = buildDiscoveryOperation({
557
+ document: info.document,
558
+ method,
559
+ toolPath,
560
+ pathTemplate: wirePath,
561
+ schemaNameForRef,
562
+ serverUrl: info.baseUrl,
563
+ tags: [info.title]
564
+ });
565
+ }
566
+ }
567
+ const scopes = compactDiscoveryScopeMap(rawScopes);
568
+ const authenticationTemplate = googleOauthTemplate(scopes);
569
+ const spec = {
570
+ openapi: "3.1.0",
571
+ info: {
572
+ title: "Google",
573
+ version: "google-discovery-bundle"
574
+ },
575
+ servers: [{ url: GOOGLE_BUNDLE_BASE_URL }],
576
+ paths,
577
+ components: {
578
+ schemas,
579
+ ...authenticationTemplate ? {
580
+ securitySchemes: {
581
+ googleOAuth2: {
582
+ type: "oauth2",
583
+ flows: {
584
+ authorizationCode: {
585
+ authorizationUrl: GOOGLE_OAUTH_AUTHORIZATION_URL,
586
+ tokenUrl: GOOGLE_OAUTH_TOKEN_URL,
587
+ scopes
588
+ }
589
+ }
590
+ }
591
+ }
592
+ } : {}
593
+ },
594
+ ...authenticationTemplate ? { security: [{ googleOAuth2: Object.keys(scopes) }] } : {},
595
+ "x-executor-origin": {
596
+ kind: "googleDiscoveryBundle",
597
+ services: infos.map((info) => ({
598
+ discoveryUrl: normalizeDiscoveryUrl(info.discoveryUrl),
599
+ service: info.service,
600
+ version: info.version
601
+ }))
602
+ }
603
+ };
604
+ return {
605
+ // @effect-diagnostics-next-line preferSchemaOverJson:off
606
+ specText: JSON.stringify(spec),
607
+ baseUrl: GOOGLE_BUNDLE_BASE_URL,
608
+ title: "Google",
609
+ service: "google",
610
+ version: "google-discovery-bundle",
611
+ discoveryUrls: infos.map((info) => normalizeDiscoveryUrl(info.discoveryUrl)),
612
+ ...authenticationTemplate ? { authenticationTemplate } : {}
613
+ };
614
+ });
615
+
616
+ export {
617
+ compactGoogleOAuthScopes,
618
+ isGoogleDiscoveryUrl,
619
+ fetchGoogleDiscoveryDocument,
620
+ convertGoogleDiscoveryToOpenApi,
621
+ convertGoogleDiscoveryBundleToOpenApi
622
+ };
623
+ //# sourceMappingURL=chunk-OSIFYIQP.js.map