(config: OpenApiSpecConfig)
| 780 | }); |
| 781 | |
| 782 | const addSpec = (config: OpenApiSpecConfig) => |
| 783 | Effect.gen(function* () { |
| 784 | // Resolve URL → text and parse BEFORE opening a transaction. Holding |
| 785 | // `BEGIN` across a network fetch is the Hyperdrive deadlock path. |
| 786 | const resolved = yield* resolveSpecForInput(config, httpClientLayer); |
| 787 | const compiled = resolved.keepPathItem |
| 788 | ? undefined |
| 789 | : yield* compileOpenApiSpec(resolved.specText); |
| 790 | const adapter = yield* resolveSpecFormatAdapter( |
| 791 | options?.specFormats ?? [], |
| 792 | config.specFormat, |
| 793 | config.spec.kind === "url" ? config.spec.url : undefined, |
| 794 | ); |
| 795 | const derivedIdentity = |
| 796 | adapter?.deriveIdentity && resolved.document |
| 797 | ? adapter.deriveIdentity(resolved.document) |
| 798 | : null; |
| 799 | const resolvedSlug = config.slug?.trim() || derivedIdentity?.slug; |
| 800 | if (!resolvedSlug) { |
| 801 | return yield* new OpenApiParseError({ |
| 802 | message: "OpenAPI integration slug is required", |
| 803 | }); |
| 804 | } |
| 805 | |
| 806 | // Defaults the add page derives from its preview, applied here so |
| 807 | // headless callers (MCP, API) get the same integration the UI's |
| 808 | // add flow would produce - see e2e/scenarios/connect-handoff.test.ts: |
| 809 | // - effectiveBaseUrl: the spec's first server, used to anchor the |
| 810 | // derived auth template's absolute URLs. It is NOT stored as the |
| 811 | // connection baseUrl - the request host is resolved per call from |
| 812 | // the operation's extracted `servers`. |
| 813 | // - authenticationTemplate: the spec's declared security schemes |
| 814 | // (else the Add-connection modal is a dead "No authentication" |
| 815 | // end with nowhere to paste a credential) |
| 816 | // An explicit input always wins; for auth, an explicit EMPTY array |
| 817 | // means "no auth methods" and suppresses the derivation. |
| 818 | const explicitBaseUrl = config.baseUrl ?? resolved.baseUrl; |
| 819 | const needsDerivedBaseUrl = explicitBaseUrl == null; |
| 820 | const needsDerivedAuth = config.authenticationTemplate == null; |
| 821 | // Spec-format selections (resolved.keepPathItem) preview via the |
| 822 | // streaming path: the whole-document parse of a Graph-sized source is |
| 823 | // the measured isolate OOM. The OAuth-discovery enrich re-parses the |
| 824 | // full text for the same reason, and an adapter spec declares its |
| 825 | // auth (or the adapter supplies the template), so it is skipped. |
| 826 | const preview = |
| 827 | needsDerivedBaseUrl || needsDerivedAuth |
| 828 | ? resolved.keepPathItem |
| 829 | ? yield* previewSpecTextStreaming(resolved.specText, resolved.keepPathItem) |
| 830 | : yield* previewSpecText(resolved.specText).pipe( |
| 831 | Effect.flatMap((rawPreview) => |
| 832 | enrichPreviewWithDiscoveredOAuth({ |
| 833 | specText: resolved.specText, |
| 834 | preview: rawPreview, |
| 835 | specUrl: resolved.specUrl ?? specInputToSpecUrl(config.spec), |
| 836 | baseUrl: explicitBaseUrl, |
| 837 | }), |
| 838 | ), |
| 839 | ) |
nothing calls this directly
no test coverage detected