History

Add Google Photos preset with binary-safe uploads (#1137)

* feat(google): add Google Photos preset with binary uploads * test(e2e): cover Google Photos preset add flow * fix: address Google Photos upload review * fix: scope partial Google Photos bundles * fix: reject invalid nested binary uploads * fix: reject non-byte octet-stream bodies * fix: stop calling raw bytes an object * fix: base64 cosplay is not media bytes * Annotate bodyBase64 media type * test(google): update presets snapshot for Google Photos presets ---------

Zak committed 4 months ago

Commit 1a1f9aa1 parent ccfe20513 files · +899 −32Browse files

Unified · Split

13 files
  1. .changeset/google-photos-openapi-presets.md +6 −0
  2. e2e/scenarios/google-photos-preset-ui.test.ts +43 −0
  3. packages/plugins/google/src/react/AddGoogleSource.tsx +21 −7
  4. packages/plugins/google/src/react/source-plugin.ts +2 −2
  5. packages/plugins/google/src/sdk/__snapshots__/presets.test.ts.snap +8 −0
  6. packages/plugins/google/src/sdk/discovery.ts +120 −7
  7. packages/plugins/google/src/sdk/index.ts +5 −0
  8. packages/plugins/google/src/sdk/plugin.test.ts +213 −0
  9. packages/plugins/google/src/sdk/plugin.ts +34 −3
  10. packages/plugins/google/src/sdk/presets.ts +40 −0
  11. packages/plugins/openapi/src/sdk/extract.ts +38 −5
  12. packages/plugins/openapi/src/sdk/invoke.ts +120 −7
  13. packages/plugins/openapi/src/sdk/non-json-body.test.ts +249 −1
.changeset/google-photos-openapi-presets.md+6−0
@@ -0,0 +1,6 @@
1+---
2+"@executor-js/plugin-google": patch
3+"@executor-js/plugin-openapi": patch
4+---
5+
6+Add a Google Photos preset with raw upload support and binary-safe `bodyBase64` handling.
e2e/scenarios/google-photos-preset-ui.test.ts+43−0
@@ -0,0 +1,43 @@
1+import { expect } from "@effect/vitest";
2+import { Effect } from "effect";
3+
4+import { scenario } from "../src/scenario";
5+import { Browser, Target } from "../src/services";
6+
7+scenario(
8+ "Google Photos: the focused preset opens a Photos-scoped add flow",
9+ {},
10+ Effect.gen(function* () {
11+ const target = yield* Target;
12+ const browser = yield* Browser;
13+ const identity = yield* target.newIdentity();
14+
15+ yield* browser.session(identity, async ({ page, step }) => {
16+ await step("Find the Google Photos preset from the integrations picker", async () => {
17+ await page.goto("/integrations", { waitUntil: "networkidle" });
18+ await page.getByRole("button", { name: "Connect" }).click();
19+ const dialog = page.getByRole("dialog", { name: "Connect an integration" });
20+ await dialog.waitFor();
21+ await dialog.getByPlaceholder(/Search or paste a URL/).fill("google photos");
22+ await dialog.getByRole("link", { name: /^Google Photos\b/ }).waitFor();
23+ });
24+
25+ await step("Open the Google Photos scoped add flow", async () => {
26+ const dialog = page.getByRole("dialog", { name: "Connect an integration" });
27+ await dialog.getByRole("link", { name: /^Google Photos\b/ }).click();
28+ await page.waitForURL(/\/integrations\/add\/google/);
29+ await page.getByRole("heading", { name: "Add Google" }).waitFor();
30+ });
31+
32+ await step("The Photos preset defaults to the focused namespace and products", async () => {
33+ await page.locator('input[value="Google Photos"]').waitFor();
34+ await page.locator('input[value="google_photos"]').waitFor();
35+ await page.getByText("Google Photos Library").first().waitFor();
36+ await page.getByText("Google Photos Picker").first().waitFor();
37+ await page.getByText("2 Google APIs").waitFor();
38+ expect(await page.locator('input[value="Google"]').count()).toBe(0);
39+ expect(await page.locator('input[value="google"]').count()).toBe(0);
40+ });
41+ });
42+ }),
43+);
packages/plugins/google/src/react/AddGoogleSource.tsx+21−7
@@ -20,7 +20,12 @@ import { OpenApiSourceDetailsFields } from "@executor-js/plugin-openapi/react"; · 19 unmodified lines
2020
2121 import { addGoogleBundle } from "./atoms";
2222 import { GoogleProductPicker } from "./GoogleProductPicker";
23−import { googleOpenApiPresets, type GoogleOpenApiPreset } from "../sdk/presets";
23+import {
24+ GOOGLE_PHOTOS_PRESET_ID,
25+ googleOpenApiPresets,
26+ googlePhotosPresetIds,
27+ type GoogleOpenApiPreset,
28+} from "../sdk/presets";
2429
2530 const GOOGLE_BUNDLE_FAVICON = "https://fonts.gstatic.com/s/i/productlogos/googleg/v6/192px.svg";
2631
@@ -43,10 +48,12 @@ const googleBundleUrls = ( · 16 unmodified lines
4348 export default function AddGoogleSource(props: {
4449 onComplete: (slug?: string) => void;
4550 onCancel: () => void;
51+ initialPreset?: string;
4652 initialNamespace?: string;
4753 }) {
54+ const isGooglePhotosPreset = props.initialPreset === GOOGLE_PHOTOS_PRESET_ID;
4855 const [selectedPresetIds, setSelectedPresetIds] = useState<ReadonlySet<string>>(
49− googleBundleDefaultPresetIds,
56+ isGooglePhotosPreset ? new Set(googlePhotosPresetIds) : googleBundleDefaultPresetIds,
5057 );
5158 const [customDiscoveryUrls, setCustomDiscoveryUrls] = useState<readonly string[]>([]);
5259 const [baseUrl, setBaseUrl] = useState("");
@@ -55,8 +62,9 @@ export default function AddGoogleSource(props: { · 2 unmodified lines
5562 const [addError, setAddError] = useState<string | null>(null);
5663
5764 const identity = useIntegrationIdentity({
58− fallbackName: "Google",
59− fallbackNamespace: props.initialNamespace ?? "google",
65+ fallbackName: isGooglePhotosPreset ? "Google Photos" : "Google",
66+ fallbackNamespace:
67+ props.initialNamespace ?? (isGooglePhotosPreset ? "google_photos" : "google"),
6068 });
6169
6270 const bundleDiscoveryUrls = useMemo(
@@ -87,9 +95,15 @@ export default function AddGoogleSource(props: { · 24 unmodified lines
8795
8896 const doAdd = useAtomSet(addGoogleBundle, { mode: "promiseExit" });
8997
90− const resolvedSourceId = slugifyNamespace(identity.namespace) || "google";
91− const resolvedDisplayName = identity.name.trim() || "Google";
92− const resolvedDescription = descriptionDraft ?? "Google APIs";
98+ const resolvedSourceId =
99+ slugifyNamespace(identity.namespace) || (isGooglePhotosPreset ? "google_photos" : "google");
100+ const resolvedDisplayName =
101+ identity.name.trim() || (isGooglePhotosPreset ? "Google Photos" : "Google");
102+ const resolvedDescription =
103+ descriptionDraft ??
104+ (isGooglePhotosPreset
105+ ? "Google Photos albums, uploads, app-created media, and selected picker media."
106+ : "Google APIs");
93107 const slugAlreadyExists = useSlugAlreadyExists(resolvedSourceId);
94108 const canAdd = bundleDiscoveryUrls.length > 0 && !slugAlreadyExists;
95109
packages/plugins/google/src/react/source-plugin.ts+2−2
@@ -1,6 +1,6 @@
11 import { lazy } from "react";
22 import type { IntegrationPlugin } from "@executor-js/sdk/client";
3−import { googleOpenApiBundlePreset } from "../sdk/presets";
3+import { googleOpenApiBundlePreset, googlePhotosOpenApiBundlePreset } from "../sdk/presets";
44
55 const importAdd = () => import("./AddGoogleSource");
66 const importAccounts = () => import("./GoogleAccountsPanel");
@@ -10,7 +10,7 @@ export const googleIntegrationPlugin: IntegrationPlugin = { · 3 unmodified lines
1010 label: "Google",
1111 add: lazy(importAdd),
1212 accounts: lazy(importAccounts),
13− presets: [googleOpenApiBundlePreset],
13+ presets: [googleOpenApiBundlePreset, googlePhotosOpenApiBundlePreset],
1414 preload: () => {
1515 void importAdd();
1616 void importAccounts();
packages/plugins/google/src/sdk/__snapshots__/presets.test.ts.snap+8−0
@@ -38,6 +38,14 @@ exports[`classifies every Google service for bundle OAuth UX 1`] = ` · 37 unmodified lines
3838 "id": "google-people",
3939 "oauthAudience": "standard-user",
4040 },
41+ {
42+ "id": "google-photos-library",
43+ "oauthAudience": "advanced-user",
44+ },
45+ {
46+ "id": "google-photos-picker",
47+ "oauthAudience": "advanced-user",
48+ },
4149 {
4250 "id": "google-chat",
4351 "oauthAudience": "workspace-admin",
packages/plugins/google/src/sdk/discovery.ts+120−7
@@ -66,12 +66,13 @@ type OpenApiOperationObject = { · 65 unmodified lines
6666 readonly servers?: readonly { readonly url: string }[];
6767 readonly parameters: readonly OpenApiParameterObject[];
6868 readonly requestBody?: {
69− readonly required: false;
70− readonly content: {
71− readonly "application/json": {
69+ readonly required: boolean;
70+ readonly content: Record<
71+ string,
72+ {
7273 readonly schema: OpenApiSchemaObject;
73− };
74− };
74+ }
75+ >;
7576 };
7677 readonly responses: {
7778 readonly "200": {
@@ -605,6 +606,7 @@ const buildDiscoveryOperation = (input: { · 527 unmodified lines
605606 readonly method: DiscoveryMethod;
606607 readonly toolPath: string;
607608 readonly pathTemplate: string;
609+ readonly oauthScopes?: readonly string[];
608610 readonly schemaNameForRef?: (name: string) => string;
609611 readonly serverUrl?: string;
610612 readonly tags?: readonly string[];
@@ -619,7 +621,7 @@ const buildDiscoveryOperation = (input: { · 8 unmodified lines
619621 if (parameter.location) mergedParameters.set(name, parameter);
620622 }
621623
622− const methodScopes = input.method.scopes ?? [];
624+ const methodScopes = input.oauthScopes ?? input.method.scopes ?? [];
623625 const methodDescription = Option.getOrUndefined(input.method.description);
624626 const schemaNameForRef = input.schemaNameForRef ?? identitySchemaName;
625627
@@ -674,6 +676,14 @@ const buildDiscoveryOperation = (input: { · 48 unmodified lines
674676 };
675677
676678 const GOOGLE_OAUTH_SECURITY_SCHEME = "googleOAuth2";
679+const GOOGLE_PHOTOS_LIBRARY_SERVICE = "photoslibrary";
680+const GOOGLE_PHOTOS_PICKER_SERVICE = "photospicker";
681+const GOOGLE_PHOTOS_APPENDONLY_SCOPE = "https://www.googleapis.com/auth/photoslibrary.appendonly";
682+const GOOGLE_PHOTOS_UPLOAD_TOOL_PATH = "photoslibrary.mediaItems.upload";
683+const GOOGLE_PHOTOS_UPLOAD_PATH = "/uploads";
684+
685+const isGooglePhotosService = (service: string): boolean =>
686+ service === GOOGLE_PHOTOS_LIBRARY_SERVICE || service === GOOGLE_PHOTOS_PICKER_SERVICE;
677687
678688 /** The v2 oauth auth template for a Google-discovery integration. The spec
679689 * itself carries the matching `securitySchemes.googleOAuth2` entry; this is the
@@ -695,6 +705,72 @@ const googleOauthTemplate = (scopes: Record<string, string>): readonly Authentic · 15 unmodified lines
695705 },
696706 ];
697707
708+const googlePhotosUploadOperation = (input: {
709+ readonly toolPath: string;
710+ readonly oauthScopes: readonly string[];
711+ readonly serverUrl: string;
712+ readonly tags?: readonly string[];
713+}): OpenApiOperationObject => ({
714+ operationId: input.toolPath,
715+ "x-executor-toolPath": input.toolPath,
716+ "x-executor-pathTemplate": GOOGLE_PHOTOS_UPLOAD_PATH,
717+ ...(input.tags && input.tags.length > 0 ? { tags: input.tags } : {}),
718+ description:
719+ "Uploads raw photo or video bytes to Google Photos and returns a plain-text upload token. Call mediaItems.batchCreate with the returned token to create the media item.",
720+ servers: [{ url: input.serverUrl }],
721+ parameters: [
722+ {
723+ name: "X-Goog-Upload-File-Name",
724+ in: "header",
725+ required: true,
726+ description: "File name Google Photos should associate with the uploaded bytes.",
727+ schema: { type: "string" },
728+ },
729+ {
730+ name: "X-Goog-Upload-Protocol",
731+ in: "header",
732+ required: true,
733+ description: "Google Photos raw upload protocol. Set to raw.",
734+ schema: { type: "string", enum: ["raw"], default: "raw" },
735+ },
736+ {
737+ name: "X-Goog-Upload-Content-Type",
738+ in: "header",
739+ required: false,
740+ description: "MIME type of the uploaded media, for example image/jpeg or video/mp4.",
741+ schema: { type: "string" },
742+ },
743+ ],
744+ requestBody: {
745+ required: true,
746+ content: {
747+ "application/octet-stream": {
748+ schema: { type: "string", format: "binary" },
749+ },
750+ },
751+ },
752+ responses: {
753+ "200": {
754+ description: "Successful response",
755+ content: {
756+ "text/plain": {
757+ schema: { type: "string" },
758+ },
759+ },
760+ },
761+ },
762+ ...(input.oauthScopes.length > 0 ? { security: [{ googleOAuth2: input.oauthScopes }] } : {}),
763+ "x-google-scopes": input.oauthScopes,
764+});
765+
766+const hasOperation = (
767+ paths: Record<string, Record<string, OpenApiOperationObject>>,
768+ operationId: string,
769+): boolean =>
770+ Object.values(paths).some((pathItem) =>
771+ Object.values(pathItem).some((operation) => operation.operationId === operationId),
772+ );
773+
698774 export const convertGoogleDiscoveryToOpenApi = Effect.fn("OpenApi.convertGoogleDiscovery")(
699775 function* (input: { readonly discoveryUrl: string; readonly documentText: string }) {
700776 const parsed = yield* parseJson(input.documentText).pipe(
@@ -738,6 +814,18 @@ export const convertGoogleDiscoveryToOpenApi = Effect.fn("OpenApi.convertGoogleD · 37 unmodified lines
738814 });
739815 }
740816
817+ if (
818+ service === GOOGLE_PHOTOS_LIBRARY_SERVICE &&
819+ !hasOperation(paths, GOOGLE_PHOTOS_UPLOAD_TOOL_PATH)
820+ ) {
821+ paths[GOOGLE_PHOTOS_UPLOAD_PATH] ??= {};
822+ paths[GOOGLE_PHOTOS_UPLOAD_PATH]!.post = googlePhotosUploadOperation({
823+ toolPath: GOOGLE_PHOTOS_UPLOAD_TOOL_PATH,
824+ oauthScopes: [GOOGLE_PHOTOS_APPENDONLY_SCOPE],
825+ serverUrl: baseUrl,
826+ });
827+ }
828+
741829 const scopes = compactDiscoveryScopeMap(discoveryScopes(document));
742830 const authenticationTemplate = googleOauthTemplate(scopes);
743831
@@ -798,6 +886,7 @@ export const convertGoogleDiscoveryBundleToOpenApi = Effect.fn( · 54 unmodified lines
798886 "OpenApi.convertGoogleDiscoveryBundle",
799887 )(function* (input: {
800888 readonly documents: readonly { readonly discoveryUrl: string; readonly documentText: string }[];
889+ readonly consentScopes?: readonly string[];
801890 }) {
802891 if (input.documents.length === 0) {
803892 return yield* new OpenApiParseError({
@@ -829,12 +918,16 @@ export const convertGoogleDiscoveryBundleToOpenApi = Effect.fn( · 25 unmodified lines
829918 const paths: Record<string, Record<string, OpenApiOperationObject>> = {};
830919 const schemas: Record<string, OpenApiSchemaObject> = {};
831920 const rawScopes: Record<string, string> = {};
921+ const consentScopeSet = input.consentScopes ? new Set(input.consentScopes) : null;
832922
833923 for (const info of infos) {
834924 const schemaPrefix = schemaComponentPart(`${info.service}_${info.version}`);
835925 const schemaNameForRef = (name: string) => `${schemaPrefix}_${schemaComponentPart(name)}`;
926+ const scopeDescriptions = discoveryScopes(info.document);
927+ const filterPhotosScopes = consentScopeSet !== null && isGooglePhotosService(info.service);
836928
837− for (const [scope, description] of Object.entries(discoveryScopes(info.document))) {
929+ for (const [scope, description] of Object.entries(scopeDescriptions)) {
930+ if (filterPhotosScopes && !consentScopeSet.has(scope)) continue;
838931 rawScopes[scope] ??= description;
839932 }
840933
@@ -846,6 +939,11 @@ export const convertGoogleDiscoveryBundleToOpenApi = Effect.fn( · 5 unmodified lines
846939 const methodId = Option.getOrUndefined(method.id);
847940 const rawPathTemplate = Option.getOrUndefined(method.path);
848941 if (!methodId || !rawPathTemplate || !method.httpMethod) continue;
942+ const methodScopes = method.scopes ?? [];
943+ const oauthScopes = filterPhotosScopes
944+ ? methodScopes.filter((scope) => consentScopeSet.has(scope))
945+ : methodScopes;
946+ if (filterPhotosScopes && methodScopes.length > 0 && oauthScopes.length === 0) continue;
849947
850948 const toolPath = methodId;
851949 const wirePath = rawPathTemplate.startsWith("/") ? rawPathTemplate : `/${rawPathTemplate}`;
@@ -859,11 +957,26 @@ export const convertGoogleDiscoveryBundleToOpenApi = Effect.fn( · 7 unmodified lines
859957 method,
860958 toolPath,
861959 pathTemplate: wirePath,
960+ oauthScopes,
862961 schemaNameForRef,
863962 serverUrl: info.baseUrl,
864963 tags: [info.title],
865964 });
866965 }
966+
967+ if (
968+ info.service === GOOGLE_PHOTOS_LIBRARY_SERVICE &&
969+ (!consentScopeSet || consentScopeSet.has(GOOGLE_PHOTOS_APPENDONLY_SCOPE)) &&
970+ !hasOperation(paths, GOOGLE_PHOTOS_UPLOAD_TOOL_PATH)
971+ ) {
972+ paths[GOOGLE_PHOTOS_UPLOAD_PATH] ??= {};
973+ paths[GOOGLE_PHOTOS_UPLOAD_PATH]!.post = googlePhotosUploadOperation({
974+ toolPath: GOOGLE_PHOTOS_UPLOAD_TOOL_PATH,
975+ oauthScopes: [GOOGLE_PHOTOS_APPENDONLY_SCOPE],
976+ serverUrl: info.baseUrl,
977+ tags: [info.title],
978+ });
979+ }
867980 }
868981
869982 const scopes = compactDiscoveryScopeMap(rawScopes);
packages/plugins/google/src/sdk/index.ts+5−0
@@ -8,6 +8,11 @@ export { · 7 unmodified lines
88 export {
99 googleOpenApiBundlePreset,
1010 googleOpenApiPresets,
11+ googlePhotosOpenApiBundlePreset,
12+ googlePhotosOpenApiPresets,
13+ googlePhotosPresetIds,
14+ GOOGLE_PHOTOS_ICON,
15+ GOOGLE_PHOTOS_PRESET_ID,
1116 googleStandardUserOAuthPresets,
1217 googleOAuthConsentScopes,
1318 googleOAuthConsentScopesForPreset,
packages/plugins/google/src/sdk/plugin.test.ts+213−0
@@ -34,6 +34,8 @@ import { googlePlugin } from "./plugin"; · 33 unmodified lines
3434 const CALENDAR_URL = "https://www.googleapis.com/discovery/v1/apis/calendar/v3/rest";
3535 const GMAIL_URL = "https://www.googleapis.com/discovery/v1/apis/gmail/v1/rest";
3636 const DRIVE_URL = "https://www.googleapis.com/discovery/v1/apis/drive/v3/rest";
37+const PHOTOS_LIBRARY_URL = "https://www.googleapis.com/discovery/v1/apis/photoslibrary/v1/rest";
38+const PHOTOS_PICKER_URL = "https://www.googleapis.com/discovery/v1/apis/photospicker/v1/rest";
3739
3840 const calendarDoc = {
3941 name: "calendar",
@@ -141,12 +143,93 @@ const driveDoc = { · 101 unmodified lines
141143 },
142144 };
143145
146+const photosLibraryDoc = {
147+ name: "photoslibrary",
148+ version: "v1",
149+ title: "Google Photos Library API",
150+ rootUrl: "https://photoslibrary.googleapis.com/",
151+ servicePath: "v1/",
152+ auth: {
153+ oauth2: {
154+ scopes: {
155+ "https://www.googleapis.com/auth/photoslibrary": {
156+ description: "Manage the full Google Photos library",
157+ },
158+ "https://www.googleapis.com/auth/photoslibrary.appendonly": {
159+ description: "Upload to Google Photos",
160+ },
161+ "https://www.googleapis.com/auth/photoslibrary.readonly.appcreateddata": {
162+ description: "Read app-created Google Photos media",
163+ },
164+ },
165+ },
166+ },
167+ resources: {
168+ albums: {
169+ methods: {
170+ list: {
171+ id: "photoslibrary.albums.list",
172+ httpMethod: "GET",
173+ path: "albums",
174+ scopes: ["https://www.googleapis.com/auth/photoslibrary"],
175+ parameters: {},
176+ },
177+ },
178+ },
179+ mediaItems: {
180+ methods: {
181+ search: {
182+ id: "photoslibrary.mediaItems.search",
183+ httpMethod: "POST",
184+ path: "mediaItems:search",
185+ scopes: ["https://www.googleapis.com/auth/photoslibrary.readonly.appcreateddata"],
186+ parameters: {},
187+ },
188+ },
189+ },
190+ },
191+ schemas: {},
192+};
193+
194+const photosPickerDoc = {
195+ name: "photospicker",
196+ version: "v1",
197+ title: "Google Photos Picker API",
198+ rootUrl: "https://photospicker.googleapis.com/",
199+ servicePath: "v1/",
200+ auth: {
201+ oauth2: {
202+ scopes: {
203+ "https://www.googleapis.com/auth/photospicker.mediaitems.readonly": {
204+ description: "Read selected Google Photos media",
205+ },
206+ },
207+ },
208+ },
209+ resources: {
210+ mediaItems: {
211+ methods: {
212+ list: {
213+ id: "photospicker.mediaItems.list",
214+ httpMethod: "GET",
215+ path: "mediaItems",
216+ scopes: ["https://www.googleapis.com/auth/photospicker.mediaitems.readonly"],
217+ parameters: {},
218+ },
219+ },
220+ },
221+ },
222+ schemas: {},
223+};
224+
144225 const toJson = (value: unknown): string => JSON.stringify(value);
145226
146227 const DISCOVERY_BODIES: Readonly<Record<string, string>> = {
147228 [CALENDAR_URL]: toJson(calendarDoc),
148229 [GMAIL_URL]: toJson(gmailDoc),
149230 [DRIVE_URL]: toJson(driveDoc),
231+ [PHOTOS_LIBRARY_URL]: toJson(photosLibraryDoc),
232+ [PHOTOS_PICKER_URL]: toJson(photosPickerDoc),
150233 };
151234
152235 // A stub HTTP client that serves the canned Discovery document for whichever
@@ -174,6 +257,16 @@ const bundlePlugins = () => · 21 unmodified lines
174257 [googlePlugin({ httpClientLayer: discoveryHttpClientLayer }), memoryCredentialsPlugin()] as const;
175258
176259 describe("Google bundle add flow", () => {
260+ it("SDK catalog includes the Google Photos focused preset", () => {
261+ const presetIds =
262+ googlePlugin({ httpClientLayer: discoveryHttpClientLayer }).integrationPresets?.map(
263+ (preset) => preset.id,
264+ ) ?? [];
265+
266+ expect(presetIds).toContain("google");
267+ expect(presetIds).toContain("google-photos");
268+ });
269+
177270 it.effect("rejects lookalike Discovery hosts before fetching bundle documents", () =>
178271 Effect.scoped(
179272 Effect.gen(function* () {
@@ -266,4 +359,124 @@ describe("Google bundle add flow", () => { · 86 unmodified lines
266359 }),
267360 ),
268361 );
362+
363+ it.effect("addBundle constrains Google Photos to the preset scopes and upload tool", () =>
364+ Effect.scoped(
365+ Effect.gen(function* () {
366+ const executor = yield* createExecutor(makeTestConfig({ plugins: bundlePlugins() }));
367+
368+ yield* executor.google.addBundle({
369+ urls: [
370+ PHOTOS_LIBRARY_URL,
371+ "https://photospicker.googleapis.com/$discovery/rest?version=v1",
372+ ],
373+ slug: "google_photos",
374+ name: "Google Photos",
375+ });
376+
377+ const config = yield* executor.google.getConfig("google_photos");
378+ const oauth = config?.authenticationTemplate?.find((entry) => entry.kind === "oauth2");
379+ expect(oauth?.kind === "oauth2" ? [...oauth.scopes].sort() : undefined).toEqual(
380+ [
381+ "https://www.googleapis.com/auth/photoslibrary.appendonly",
382+ "https://www.googleapis.com/auth/photoslibrary.readonly.appcreateddata",
383+ "https://www.googleapis.com/auth/photospicker.mediaitems.readonly",
384+ ].sort(),
385+ );
386+
387+ yield* executor.connections.create({
388+ owner: "org",
389+ name: ConnectionName.make("main"),
390+ integration: IntegrationSlug.make("google_photos"),
391+ template: AuthTemplateSlug.make("googleOAuth2"),
392+ value: "token-xyz",
393+ });
394+
395+ const toolNames = (yield* executor.tools.list()).map((tool) => String(tool.name));
396+ expect(toolNames).toContain("photoslibrary.mediaItems.upload");
397+ expect(toolNames).toContain("photoslibrary.mediaItems.search");
398+ expect(toolNames).toContain("photospicker.mediaItems.list");
399+ expect(toolNames).not.toContain("photoslibrary.albums.list");
400+ }),
401+ ),
402+ );
403+
404+ it.effect("addBundle keeps Google Photos scoped when combined with another API", () =>
405+ Effect.scoped(
406+ Effect.gen(function* () {
407+ const executor = yield* createExecutor(makeTestConfig({ plugins: bundlePlugins() }));
408+
409+ yield* executor.google.addBundle({
410+ urls: [CALENDAR_URL, PHOTOS_LIBRARY_URL, PHOTOS_PICKER_URL],
411+ slug: "google_photos_calendar",
412+ name: "Google Photos and Calendar",
413+ });
414+
415+ const config = yield* executor.google.getConfig("google_photos_calendar");
416+ const oauth = config?.authenticationTemplate?.find((entry) => entry.kind === "oauth2");
417+ expect(oauth?.kind === "oauth2" ? [...oauth.scopes].sort() : undefined).toEqual(
418+ [
419+ "https://www.googleapis.com/auth/calendar",
420+ "https://www.googleapis.com/auth/photoslibrary.appendonly",
421+ "https://www.googleapis.com/auth/photoslibrary.readonly.appcreateddata",
422+ "https://www.googleapis.com/auth/photospicker.mediaitems.readonly",
423+ ].sort(),
424+ );
425+
426+ yield* executor.connections.create({
427+ owner: "org",
428+ name: ConnectionName.make("main"),
429+ integration: IntegrationSlug.make("google_photos_calendar"),
430+ template: AuthTemplateSlug.make("googleOAuth2"),
431+ value: "token-xyz",
432+ });
433+
434+ const toolNames = (yield* executor.tools.list()).map((tool) => String(tool.name));
435+ expect(toolNames).toContain("calendar.events.list");
436+ expect(toolNames).toContain("photoslibrary.mediaItems.upload");
437+ expect(toolNames).toContain("photoslibrary.mediaItems.search");
438+ expect(toolNames).toContain("photospicker.mediaItems.list");
439+ expect(toolNames).not.toContain("photoslibrary.albums.list");
440+ }),
441+ ),
442+ );
443+
444+ it.effect("addBundle scopes a partial Google Photos bundle when mixed with another API", () =>
445+ Effect.scoped(
446+ Effect.gen(function* () {
447+ const executor = yield* createExecutor(makeTestConfig({ plugins: bundlePlugins() }));
448+
449+ yield* executor.google.addBundle({
450+ urls: [CALENDAR_URL, PHOTOS_LIBRARY_URL],
451+ slug: "google_photos_library_calendar",
452+ name: "Google Photos Library and Calendar",
453+ });
454+
455+ const config = yield* executor.google.getConfig("google_photos_library_calendar");
456+ const oauth = config?.authenticationTemplate?.find((entry) => entry.kind === "oauth2");
457+ expect(oauth?.kind === "oauth2" ? [...oauth.scopes].sort() : undefined).toEqual(
458+ [
459+ "https://www.googleapis.com/auth/calendar",
460+ "https://www.googleapis.com/auth/photoslibrary.appendonly",
461+ "https://www.googleapis.com/auth/photoslibrary.readonly.appcreateddata",
462+ ].sort(),
463+ );
464+
465+ yield* executor.connections.create({
466+ owner: "org",
467+ name: ConnectionName.make("main"),
468+ integration: IntegrationSlug.make("google_photos_library_calendar"),
469+ template: AuthTemplateSlug.make("googleOAuth2"),
470+ value: "token-xyz",
471+ });
472+
473+ const toolNames = (yield* executor.tools.list()).map((tool) => String(tool.name));
474+ expect(toolNames).toContain("calendar.events.list");
475+ expect(toolNames).toContain("photoslibrary.mediaItems.upload");
476+ expect(toolNames).toContain("photoslibrary.mediaItems.search");
477+ expect(toolNames).not.toContain("photospicker.mediaItems.list");
478+ expect(toolNames).not.toContain("photoslibrary.albums.list");
479+ }),
480+ ),
481+ );
269482 });
packages/plugins/google/src/sdk/plugin.ts+34−3
@@ -36,7 +36,12 @@ import { · 35 unmodified lines
3636 normalizeGoogleDiscoveryUrl,
3737 } from "./discovery";
3838 import { decodeGoogleIntegrationConfig, type GoogleIntegrationConfig } from "./config";
39−import { googleOpenApiBundlePreset } from "./presets";
39+import {
40+ googleOAuthConsentScopesForPreset,
41+ googleOpenApiBundlePreset,
42+ googlePhotosOpenApiBundlePreset,
43+ googlePhotosOpenApiPresets,
44+} from "./presets";
4045
4146 export interface GoogleBundleConfig {
4247 readonly urls: readonly string[];
@@ -68,6 +73,24 @@ export interface GooglePluginOptions { · 25 unmodified lines
6873
6974 const DEFAULT_GOOGLE_SLUG = "google";
7075
76+const googlePhotosBundlePresetIdByUrl = new Map(
77+ googlePhotosOpenApiPresets.flatMap((preset) =>
78+ preset.url ? [[normalizeGoogleDiscoveryUrl(preset.url) ?? preset.url, preset.id] as const] : [],
79+ ),
80+);
81+
82+const googlePhotosBundleConsentScopes = (
83+ urls: readonly string[],
84+): readonly string[] | undefined => {
85+ const normalized = new Set(urls);
86+ const presetIds = [...googlePhotosBundlePresetIdByUrl.entries()].flatMap(([url, presetId]) =>
87+ normalized.has(url) ? [presetId] : [],
88+ );
89+ return presetIds.length > 0
90+ ? presetIds.flatMap((presetId) => googleOAuthConsentScopesForPreset(presetId))
91+ : undefined;
92+};
93+
7194 const fetchGoogleBundleConversion = (
7295 urls: readonly string[],
7396 httpClientLayer: Layer.Layer<HttpClient.HttpClient, never, never>,
@@ -80,7 +103,15 @@ const fetchGoogleBundleConversion = ( · 6 unmodified lines
80103 Effect.map((documentText) => ({ discoveryUrl: url, documentText })),
81104 ),
82105 { concurrency: 4 },
83− ).pipe(Effect.flatMap((documents) => convertGoogleDiscoveryBundleToOpenApi({ documents })));
106+ ).pipe(
107+ Effect.flatMap((documents) => {
108+ const consentScopes = googlePhotosBundleConsentScopes(urls);
109+ return convertGoogleDiscoveryBundleToOpenApi({
110+ documents,
111+ ...(consentScopes ? { consentScopes } : {}),
112+ });
113+ }),
114+ );
84115
85116 const uniqueUrls = (urls: readonly string[]): readonly string[] => [
86117 ...new Set(urls.flatMap((url) => normalizeGoogleDiscoveryUrl(url) ?? [])),
@@ -292,7 +323,7 @@ export type GooglePluginExtension = ReturnType<typeof makeGooglePluginExtension> · 205 unmodified lines
292323 export const googlePlugin = definePlugin((options?: GooglePluginOptions) => ({
293324 id: "google" as const,
294325 packageName: "@executor-js/plugin-google",
295− integrationPresets: [googleOpenApiBundlePreset],
326+ integrationPresets: [googleOpenApiBundlePreset, googlePhotosOpenApiBundlePreset],
296327 storage: (deps): OpenapiStore => makeDefaultOpenapiStore(deps),
297328
298329 extension: (ctx: PluginCtx<OpenapiStore>) => makeGooglePluginExtension(options, ctx),
packages/plugins/google/src/sdk/presets.ts+40−0
@@ -24,6 +24,9 @@ const gd = (service: string, version: string) => · 23 unmodified lines
2424
2525 const GOOGLE_G = "https://fonts.gstatic.com/s/i/productlogos/googleg/v6/192px.svg";
2626 export const GOOGLE_BUNDLE_PRESET_ID = "google";
27+export const GOOGLE_PHOTOS_PRESET_ID = "google-photos";
28+export const GOOGLE_PHOTOS_ICON =
29+ "https://www.gstatic.com/images/branding/product/2x/photos_96dp.png";
2730
2831 export const googleOpenApiBundlePreset: GooglePreset = {
2932 id: GOOGLE_BUNDLE_PRESET_ID,
@@ -33,6 +36,14 @@ export const googleOpenApiBundlePreset: GooglePreset = { · 3 unmodified lines
3336 featured: true,
3437 };
3538
39+export const googlePhotosOpenApiBundlePreset: GooglePreset = {
40+ id: GOOGLE_PHOTOS_PRESET_ID,
41+ name: "Google Photos",
42+ summary: "Albums, uploads, app-created media, and user-selected picker media.",
43+ icon: GOOGLE_PHOTOS_ICON,
44+ featured: true,
45+};
46+
3647 export const googleOpenApiPresets: readonly GoogleOpenApiPreset[] = [
3748 {
3849 id: "google-calendar",
@@ -111,6 +122,22 @@ export const googleOpenApiPresets: readonly GoogleOpenApiPreset[] = [ · 72 unmodified lines
111122 icon: "https://fonts.gstatic.com/s/i/productlogos/contacts_2022/v2/192px.svg",
112123 oauthAudience: "standard-user",
113124 },
125+ {
126+ id: "google-photos-library",
127+ name: "Google Photos Library",
128+ summary: "Albums, uploads, and app-created media through Google Photos.",
129+ url: gd("photoslibrary", "v1"),
130+ icon: GOOGLE_PHOTOS_ICON,
131+ oauthAudience: "advanced-user",
132+ },
133+ {
134+ id: "google-photos-picker",
135+ name: "Google Photos Picker",
136+ summary: "Picker sessions and user-selected Google Photos media items.",
137+ url: "https://photospicker.googleapis.com/$discovery/rest?version=v1",
138+ icon: GOOGLE_PHOTOS_ICON,
139+ oauthAudience: "advanced-user",
140+ },
114141 {
115142 id: "google-chat",
116143 name: "Google Chat",
@@ -197,6 +224,14 @@ export const googleStandardUserOAuthPresets = googleOpenApiPresets.filter( · 80 unmodified lines
197224 (preset) => preset.oauthAudience === "standard-user",
198225 );
199226
227+export const googlePhotosPresetIds: readonly string[] = [
228+ "google-photos-library",
229+ "google-photos-picker",
230+];
231+
232+export const googlePhotosOpenApiPresets: readonly GoogleOpenApiPreset[] =
233+ googleOpenApiPresets.filter((preset) => googlePhotosPresetIds.includes(preset.id));
234+
200235 // ---------------------------------------------------------------------------
201236 // Representative consent scopes per preset.
202237 //
@@ -221,6 +256,11 @@ export const googleOAuthConsentScopes: Readonly<Record<string, readonly string[] · 18 unmodified lines
221256 "google-forms": ["https://www.googleapis.com/auth/forms.body"],
222257 "google-tasks": ["https://www.googleapis.com/auth/tasks"],
223258 "google-people": ["https://www.googleapis.com/auth/contacts"],
259+ "google-photos-library": [
260+ "https://www.googleapis.com/auth/photoslibrary.appendonly",
261+ "https://www.googleapis.com/auth/photoslibrary.readonly.appcreateddata",
262+ ],
263+ "google-photos-picker": ["https://www.googleapis.com/auth/photospicker.mediaitems.readonly"],
224264 "google-chat": ["https://www.googleapis.com/auth/chat.spaces"],
225265 "google-keep": ["https://www.googleapis.com/auth/keep"],
226266 "google-youtube-data": ["https://www.googleapis.com/auth/youtube"],
packages/plugins/openapi/src/sdk/extract.ts+38−5
@@ -316,6 +316,7 @@ export const buildInputSchema = ( · 315 unmodified lines
316316 ): Record<string, unknown> | undefined => {
317317 const properties: Record<string, unknown> = {};
318318 const required: string[] = [];
319+ let requiredBodyAlternatives: readonly { readonly required: readonly string[] }[] | undefined;
319320
320321 for (const param of parameters) {
321322 properties[param.name] = Option.getOrElse(param.schema, () => ({ type: "string" }));
@@ -327,14 +328,45 @@ export const buildInputSchema = ( · 5 unmodified lines
327328 if (serverProperty && !("server" in properties)) properties.server = serverProperty;
328329
329330 if (requestBody) {
330− properties.body = Option.getOrElse(requestBody.schema, () => ({ type: "object" }));
331− if (requestBody.required) required.push("body");
332−
333331 // When the spec declares multiple media types for this requestBody,
334332 // expose `contentType` so the model can pick. Default = first declared.
335− // `body` schema tracks the default; the model is responsible for
336− // supplying a body shape that matches whichever contentType it picks.
333+ // For mixed bodies, `body` schema tracks the default; the model is
334+ // responsible for supplying a body shape that matches whichever
335+ // contentType it picks. Octet-only operations use `bodyBase64` instead.
337336 const contents = Option.getOrUndefined(requestBody.contents);
337+ const defaultIsOctetStream =
338+ requestBody.contentType.split(";")[0]?.trim().toLowerCase() === "application/octet-stream";
339+ const acceptsOctetStream =
340+ defaultIsOctetStream ||
341+ contents?.some(
342+ (content) =>
343+ content.contentType.split(";")[0]?.trim().toLowerCase() === "application/octet-stream",
344+ ) === true;
345+ const acceptsBody =
346+ !defaultIsOctetStream ||
347+ contents?.some(
348+ (content) =>
349+ content.contentType.split(";")[0]?.trim().toLowerCase() !== "application/octet-stream",
350+ ) === true;
351+ if (acceptsBody) {
352+ properties.body = Option.getOrElse(requestBody.schema, () => ({ type: "object" }));
353+ }
354+ if (acceptsOctetStream) {
355+ properties.bodyBase64 = {
356+ type: "string",
357+ contentEncoding: "base64",
358+ contentMediaType: "application/octet-stream",
359+ description:
360+ "Base64-encoded bytes for application/octet-stream request bodies. When contentType is omitted, this selects application/octet-stream.",
361+ };
362+ }
363+ if (requestBody.required) {
364+ if (acceptsOctetStream && acceptsBody) {
365+ requiredBodyAlternatives = [{ required: ["body"] }, { required: ["bodyBase64"] }];
366+ } else {
367+ required.push(acceptsOctetStream ? "bodyBase64" : "body");
368+ }
369+ }
338370 if (contents && contents.length > 1) {
339371 properties.contentType = {
340372 type: "string",
@@ -352,6 +384,7 @@ export const buildInputSchema = ( · 11 unmodified lines
352384 type: "object",
353385 properties,
354386 ...(required.length > 0 ? { required } : {}),
387+ ...(requiredBodyAlternatives ? { anyOf: requiredBodyAlternatives } : {}),
355388 additionalProperties: false,
356389 };
357390 };
packages/plugins/openapi/src/sdk/invoke.ts+120−7
@@ -272,6 +272,28 @@ const bytesFromBase64Prefix = (base64: string): Uint8Array => { · 271 unmodified lines
272272 const sniffMimeTypeFromBase64 = (base64: string): string | null =>
273273 sniffMimeType(bytesFromBase64Prefix(base64));
274274
275+type DecodedBase64Body = { readonly ok: true; readonly bytes: Uint8Array } | { readonly ok: false };
276+
277+const base64ToUint8Array = (value: string): Uint8Array | null => {
278+ let binary = "";
279+ // oxlint-disable-next-line executor/no-try-catch-or-throw -- boundary: atob throws for invalid base64; invalid shapes are treated as non-byte input
280+ try {
281+ binary = atob(normalizeBase64(value, "base64"));
282+ } catch {
283+ return null;
284+ }
285+ const bytes = new Uint8Array(binary.length);
286+ for (let index = 0; index < binary.length; index += 1) {
287+ bytes[index] = binary.charCodeAt(index);
288+ }
289+ return bytes;
290+};
291+
292+const decodeBase64Body = (value: string): DecodedBase64Body => {
293+ const bytes = base64ToUint8Array(value);
294+ return bytes ? { ok: true, bytes } : { ok: false };
295+};
296+
275297 const toUint8Array = (value: unknown): Uint8Array | null => {
276298 if (value instanceof Uint8Array) return value;
277299 if (value instanceof ArrayBuffer) return new Uint8Array(value);
@@ -285,6 +307,14 @@ const toUint8Array = (value: unknown): Uint8Array | null => { · 7 unmodified lines
285307 return null;
286308 };
287309
310+const readNestedBodyBase64 = (value: unknown): unknown =>
311+ typeof value === "object" &&
312+ value !== null &&
313+ !Array.isArray(value) &&
314+ Object.prototype.hasOwnProperty.call(value, "bodyBase64")
315+ ? (value as Record<string, unknown>).bodyBase64
316+ : undefined;
317+
288318 const readHintString = (option: OperationFileHint["dataField"], fallback: string): string =>
289319 Option.getOrElse(option, () => fallback);
290320
@@ -663,18 +693,101 @@ export const invoke = Effect.fn("OpenApi.invoke")(function* ( · 372 unmodified lines
663693
664694 if (Option.isSome(operation.requestBody)) {
665695 const rb = operation.requestBody.value;
666− const bodyValue = args.body ?? args.input;
696+ const contentsOpt = Option.getOrUndefined(rb.contents);
697+ const requestedCt = typeof args.contentType === "string" ? args.contentType : undefined;
698+ const octetStreamContent = contentsOpt?.find((c) => isOctetStream(c.contentType));
699+ const bodyAcceptsOctetStream = Boolean(octetStreamContent) || isOctetStream(rb.contentType);
700+ const hasBodyBase64 = Object.prototype.hasOwnProperty.call(args, "bodyBase64");
701+ const bodyBase64Raw = args.bodyBase64;
702+ const bodyBase64 =
703+ typeof bodyBase64Raw === "string" ? decodeBase64Body(bodyBase64Raw) : undefined;
704+
705+ if (hasBodyBase64 && typeof bodyBase64Raw !== "string") {
706+ return yield* new OpenApiInvocationError({
707+ message: "`bodyBase64` must be a base64 string",
708+ statusCode: Option.none(),
709+ });
710+ }
711+ if (bodyBase64?.ok === false) {
712+ return yield* new OpenApiInvocationError({
713+ message: "`bodyBase64` is not valid base64",
714+ statusCode: Option.none(),
715+ });
716+ }
717+ if (bodyBase64?.ok === true && !bodyAcceptsOctetStream) {
718+ return yield* new OpenApiInvocationError({
719+ message: "`bodyBase64` requires an application/octet-stream request body",
720+ statusCode: Option.none(),
721+ });
722+ }
723+ if (bodyBase64?.ok === true && requestedCt && !isOctetStream(requestedCt)) {
724+ return yield* new OpenApiInvocationError({
725+ message: "`bodyBase64` requires an application/octet-stream contentType",
726+ statusCode: Option.none(),
727+ });
728+ }
729+
730+ const rawBodyValue = args.body ?? args.input;
731+ const nestedBodyBase64Raw = readNestedBodyBase64(rawBodyValue);
732+ const hasNestedBodyBase64 = nestedBodyBase64Raw !== undefined;
733+ const nestedBodyBase64 =
734+ typeof nestedBodyBase64Raw === "string" ? decodeBase64Body(nestedBodyBase64Raw) : undefined;
735+
736+ if (hasNestedBodyBase64 && typeof nestedBodyBase64Raw !== "string") {
737+ return yield* new OpenApiInvocationError({
738+ message: "`body.bodyBase64` must be a base64 string",
739+ statusCode: Option.none(),
740+ });
741+ }
742+ if (nestedBodyBase64?.ok === false) {
743+ return yield* new OpenApiInvocationError({
744+ message: "`body.bodyBase64` is not valid base64",
745+ statusCode: Option.none(),
746+ });
747+ }
748+ if (nestedBodyBase64?.ok === true && !bodyAcceptsOctetStream) {
749+ return yield* new OpenApiInvocationError({
750+ message: "`body.bodyBase64` requires an application/octet-stream request body",
751+ statusCode: Option.none(),
752+ });
753+ }
754+ if (nestedBodyBase64?.ok === true && requestedCt && !isOctetStream(requestedCt)) {
755+ return yield* new OpenApiInvocationError({
756+ message: "`body.bodyBase64` requires an application/octet-stream contentType",
757+ statusCode: Option.none(),
758+ });
759+ }
760+
761+ const binaryBody = bodyBase64?.ok === true ? bodyBase64 : nestedBodyBase64;
762+ const bodyValue = binaryBody?.ok === true ? binaryBody.bytes : rawBodyValue;
763+ if (rb.required && bodyValue === undefined) {
764+ return yield* new OpenApiInvocationError({
765+ message: bodyAcceptsOctetStream
766+ ? "Missing required request body: provide `bodyBase64`"
767+ : "Missing required request body",
768+ statusCode: Option.none(),
769+ });
770+ }
667771 if (bodyValue !== undefined) {
668772 // Resolve which declared media type to use. When the spec declares
669773 // multiple, the caller can override via `args.contentType`; otherwise
670774 // we use the first-declared (spec author's preferred ordering).
671− const contentsOpt = Option.getOrUndefined(rb.contents);
672− const requestedCt = typeof args.contentType === "string" ? args.contentType : undefined;
673775 const selected: MediaBinding | undefined =
674− contentsOpt && requestedCt
675− ? contentsOpt.find((c) => c.contentType === requestedCt)
676− : undefined;
677− const chosenCt = selected?.contentType ?? rb.contentType;
776+ binaryBody?.ok === true && octetStreamContent
777+ ? octetStreamContent
778+ : contentsOpt && requestedCt
779+ ? contentsOpt.find((c) => c.contentType === requestedCt)
780+ : undefined;
781+ const chosenCt =
782+ binaryBody?.ok === true && !octetStreamContent && isOctetStream(rb.contentType)
783+ ? rb.contentType
784+ : (selected?.contentType ?? rb.contentType);
785+ if (isOctetStream(chosenCt) && toUint8Array(bodyValue) === null) {
786+ return yield* new OpenApiInvocationError({
787+ message: "application/octet-stream request body must be bytes; provide `bodyBase64`",
788+ statusCode: Option.none(),
789+ });
790+ }
678791 const chosenEncoding = selected
679792 ? Option.getOrUndefined(selected.encoding)
680793 : contentsOpt && contentsOpt[0]
packages/plugins/openapi/src/sdk/non-json-body.test.ts+249−1
@@ -14,7 +14,7 @@ · 13 unmodified lines
1414 // ---------------------------------------------------------------------------
1515
1616 import { describe, expect, it } from "@effect/vitest";
17−import { Effect, Schema } from "effect";
17+import { Effect, Exit, Schema } from "effect";
1818 import { FetchHttpClient, HttpServerRequest, HttpServerResponse } from "effect/unstable/http";
1919 import {
2020 HttpApi,
@@ -259,6 +259,139 @@ describe("OpenAPI non-JSON request body dispatch", () => { · 238 unmodified lines
259259 }),
260260 );
261261
262+ it.effect("application/octet-stream: bodyBase64 passes through as bytes", () =>
263+ Effect.gen(function* () {
264+ const { server, captured } = yield* startEchoServer({
265+ payload: Schema.Uint8Array.pipe(HttpApiSchema.asUint8Array()),
266+ });
267+
268+ const executor = yield* createExecutor(makeTestConfig({ plugins: testPlugins() }));
269+
270+ const conn = yield* addOpenApiTestConnection(executor, server, { slug: "bin_b64" });
271+
272+ yield* executor.execute(conn.address("body.submit"), {
273+ bodyBase64: "3q2+7w==",
274+ });
275+
276+ expect(captured.contentType).toBe("application/octet-stream");
277+ expect(Array.from(captured.body)).toEqual([0xde, 0xad, 0xbe, 0xef]);
278+ }),
279+ );
280+
281+ it.effect("application/octet-stream: invalid bodyBase64 fails before dispatch", () =>
282+ Effect.gen(function* () {
283+ const { server, captured } = yield* startEchoServer({
284+ payload: Schema.Uint8Array.pipe(HttpApiSchema.asUint8Array()),
285+ });
286+
287+ const executor = yield* createExecutor(makeTestConfig({ plugins: testPlugins() }));
288+
289+ const conn = yield* addOpenApiTestConnection(executor, server, { slug: "bin_b64_bad" });
290+
291+ const exit = yield* executor
292+ .execute(conn.address("body.submit"), {
293+ bodyBase64: "@@",
294+ })
295+ .pipe(Effect.exit);
296+
297+ expect(Exit.isFailure(exit)).toBe(true);
298+ expect(captured.contentType).toBe("");
299+ expect(captured.body.length).toBe(0);
300+ }),
301+ );
302+
303+ it.effect("application/octet-stream: invalid nested bodyBase64 fails before dispatch", () =>
304+ Effect.gen(function* () {
305+ const { server, captured } = yield* startEchoServer({
306+ payload: Schema.Uint8Array.pipe(HttpApiSchema.asUint8Array()),
307+ });
308+
309+ const executor = yield* createExecutor(makeTestConfig({ plugins: testPlugins() }));
310+
311+ const conn = yield* addOpenApiTestConnection(executor, server, {
312+ slug: "bin_nested_b64_bad",
313+ });
314+
315+ const exit = yield* executor
316+ .execute(conn.address("body.submit"), {
317+ body: { bodyBase64: "@@" },
318+ })
319+ .pipe(Effect.exit);
320+
321+ expect(Exit.isFailure(exit)).toBe(true);
322+ expect(captured.contentType).toBe("");
323+ expect(captured.body.length).toBe(0);
324+ }),
325+ );
326+
327+ it.effect("application/octet-stream: required body fails before dispatch when missing", () =>
328+ Effect.gen(function* () {
329+ const { server, captured } = yield* startEchoServer({
330+ payload: Schema.Uint8Array.pipe(HttpApiSchema.asUint8Array()),
331+ });
332+
333+ const executor = yield* createExecutor(makeTestConfig({ plugins: testPlugins() }));
334+
335+ const conn = yield* addOpenApiTestConnection(executor, server, {
336+ slug: "bin_b64_missing",
337+ });
338+
339+ const exit = yield* executor.execute(conn.address("body.submit"), {}).pipe(Effect.exit);
340+
341+ expect(Exit.isFailure(exit)).toBe(true);
342+ expect(captured.contentType).toBe("");
343+ expect(captured.body.length).toBe(0);
344+ }),
345+ );
346+
347+ it.effect("application/octet-stream: object body fails before dispatch", () =>
348+ Effect.gen(function* () {
349+ const { server, captured } = yield* startEchoServer({
350+ payload: Schema.Uint8Array.pipe(HttpApiSchema.asUint8Array()),
351+ });
352+
353+ const executor = yield* createExecutor(makeTestConfig({ plugins: testPlugins() }));
354+
355+ const conn = yield* addOpenApiTestConnection(executor, server, {
356+ slug: "bin_object_body",
357+ });
358+
359+ const exit = yield* executor
360+ .execute(conn.address("body.submit"), {
361+ body: { name: "photo.png" },
362+ })
363+ .pipe(Effect.exit);
364+
365+ expect(Exit.isFailure(exit)).toBe(true);
366+ expect(captured.contentType).toBe("");
367+ expect(captured.body.length).toBe(0);
368+ }),
369+ );
370+
371+ it.effect("application/octet-stream: string body fails before dispatch", () =>
372+ Effect.gen(function* () {
373+ const { server, captured } = yield* startEchoServer({
374+ payload: Schema.Uint8Array.pipe(HttpApiSchema.asUint8Array()),
375+ });
376+
377+ const executor = yield* createExecutor(makeTestConfig({ plugins: testPlugins() }));
378+
379+ const conn = yield* addOpenApiTestConnection(executor, server, {
380+ slug: "bin_string_body",
381+ });
382+
383+ const exit = yield* executor
384+ .execute(conn.address("body.submit"), {
385+ body: "3q2+7w==",
386+ })
387+ .pipe(Effect.exit);
388+
389+ expect(Exit.isFailure(exit)).toBe(true);
390+ expect(captured.contentType).toBe("");
391+ expect(captured.body.length).toBe(0);
392+ }),
393+ );
394+
262395 it.effect(
263396 "format: byte response: Gmail-style image attachment data is exposed as a file artifact",
264397 () =>
@@ -754,6 +887,95 @@ describe("OpenAPI non-JSON request body dispatch", () => { · 489 unmodified lines
754887 }),
755888 );
756889
890+ it.effect("multi-content: bodyBase64 selects octet-stream without explicit contentType", () =>
891+ Effect.gen(function* () {
892+ const { server, captured } = yield* startEchoServer({
893+ payload: multiContentPayload,
894+ transformSpec: replaceRequestBodyContent("/submit", "post", {
895+ "application/json": {
896+ schema: { type: "object" },
897+ },
898+ "application/octet-stream": {
899+ schema: { type: "string", format: "binary" },
900+ },
901+ }),
902+ });
903+
904+ const executor = yield* createExecutor(makeTestConfig({ plugins: testPlugins() }));
905+
906+ const conn = yield* addOpenApiTestConnection(executor, server, { slug: "mc_b64" });
907+
908+ yield* executor.execute(conn.address("body.submit"), {
909+ bodyBase64: "3q2+7w==",
910+ });
911+
912+ expect(captured.contentType).toBe("application/octet-stream");
913+ expect(Array.from(captured.body)).toEqual([0xde, 0xad, 0xbe, 0xef]);
914+ }),
915+ );
916+
917+ it.effect("multi-content: bodyBase64 rejects a non-octet contentType", () =>
918+ Effect.gen(function* () {
919+ const { server, captured } = yield* startEchoServer({
920+ payload: multiContentPayload,
921+ transformSpec: replaceRequestBodyContent("/submit", "post", {
922+ "application/json": {
923+ schema: { type: "object" },
924+ },
925+ "application/octet-stream": {
926+ schema: { type: "string", format: "binary" },
927+ },
928+ }),
929+ });
930+
931+ const executor = yield* createExecutor(makeTestConfig({ plugins: testPlugins() }));
932+
933+ const conn = yield* addOpenApiTestConnection(executor, server, { slug: "mc_b64_bad_ct" });
934+
935+ const exit = yield* executor
936+ .execute(conn.address("body.submit"), {
937+ contentType: "application/json",
938+ bodyBase64: "3q2+7w==",
939+ })
940+ .pipe(Effect.exit);
941+
942+ expect(Exit.isFailure(exit)).toBe(true);
943+ expect(captured.contentType).toBe("");
944+ expect(captured.body.length).toBe(0);
945+ }),
946+ );
947+
948+ it.effect("multi-content: required schema accepts body or bodyBase64", () =>
949+ Effect.gen(function* () {
950+ const { server } = yield* startEchoServer({
951+ payload: multiContentPayload,
952+ transformSpec: replaceRequestBodyContent("/submit", "post", {
953+ "application/json": {
954+ schema: { type: "object" },
955+ },
956+ "application/octet-stream": {
957+ schema: { type: "string", format: "binary" },
958+ },
959+ }),
960+ });
961+ const executor = yield* createExecutor(makeTestConfig({ plugins: testPlugins() }));
962+
963+ const conn = yield* addOpenApiTestConnection(executor, server, { slug: "mc_b64_schema" });
964+
965+ const view = yield* executor.tools.schema(conn.address("body.submit"));
966+ expect(view).not.toBeNull();
967+ const schema = view!.inputSchema as {
968+ anyOf?: readonly { readonly required?: readonly string[] }[];
969+ properties?: {
970+ bodyBase64?: { contentEncoding?: string; contentMediaType?: string };
971+ };
972+ };
973+ expect(schema.anyOf).toEqual([{ required: ["body"] }, { required: ["bodyBase64"] }]);
974+ expect(schema.properties?.bodyBase64?.contentEncoding).toBe("base64");
975+ expect(schema.properties?.bodyBase64?.contentMediaType).toBe("application/octet-stream");
976+ }),
977+ );
978+
757979 it.effect("multi-content: tool input schema exposes contentType enum", () =>
758980 Effect.gen(function* () {
759981 const { server } = yield* startEchoServer({
@@ -783,6 +1005,32 @@ describe("OpenAPI non-JSON request body dispatch", () => { · 23 unmodified lines
7831005 }),
7841006 );
7851007
1008+ it.effect("octet-stream: tool input schema exposes bodyBase64", () =>
1009+ Effect.gen(function* () {
1010+ const { server } = yield* startEchoServer({
1011+ payload: Schema.Uint8Array.pipe(HttpApiSchema.asUint8Array()),
1012+ });
1013+ const executor = yield* createExecutor(makeTestConfig({ plugins: testPlugins() }));
1014+
1015+ const conn = yield* addOpenApiTestConnection(executor, server, { slug: "bin_schema" });
1016+
1017+ const view = yield* executor.tools.schema(conn.address("body.submit"));
1018+ expect(view).not.toBeNull();
1019+ const schema = view!.inputSchema as {
1020+ required?: string[];
1021+ properties?: {
1022+ body?: unknown;
1023+ bodyBase64?: { contentEncoding?: string; contentMediaType?: string };
1024+ };
1025+ };
1026+ expect(schema.required).toContain("bodyBase64");
1027+ expect(schema.required).not.toContain("body");
1028+ expect(schema.properties?.body).toBeUndefined();
1029+ expect(schema.properties?.bodyBase64?.contentEncoding).toBe("base64");
1030+ expect(schema.properties?.bodyBase64?.contentMediaType).toBe("application/octet-stream");
1031+ }),
1032+ );
1033+
7861034 // -------------------------------------------------------------------------
7871035 // Per-part encoding.contentType in multipart — a metadata field declared
7881036 // as application/json must ship with its own `Content-Type: application/

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t