MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / resolveConnectionValues

Function resolveConnectionValues

packages/core/sdk/src/executor.ts:2123–2156  ·  view source on GitHub ↗
(
      row: ConnectionRow,
    )

Source from the content-addressed store, hash-verified

2121 // two distinct inputs yields one entry per variable. OAuth connections refresh
2122 // first (always single-input → `{ token: <access> }`).
2123 const resolveConnectionValues = (
2124 row: ConnectionRow,
2125 ): Effect.Effect<Record<string, string | null>, StorageFailure | CredentialResolutionError> =>
2126 Effect.gen(function* () {
2127 const provider = credentialProviders.get(row.provider);
2128 if (!provider) {
2129 return yield* new CredentialProviderNotRegisteredError({
2130 provider: ProviderKey.make(row.provider),
2131 });
2132 }
2133 // OAuth connections refresh their access token before resolving when
2134 // it has expired (or is within the skew window).
2135 const expiresAt = row.expires_at == null ? null : Number(row.expires_at);
2136 if (row.oauth_client != null && shouldRefreshToken({ expiresAt })) {
2137 const access = yield* refreshConnectionToken(row, provider);
2138 return { [PRIMARY_INPUT_VARIABLE]: access };
2139 }
2140 const out: Record<string, string | null> = {};
2141 for (const [variable, itemId] of Object.entries(connectionItemIds(row))) {
2142 out[variable] = yield* provider.get(ProviderItemId.make(itemId));
2143 }
2144 return out;
2145 }).pipe(
2146 // CredentialProviderNotRegisteredError is part of CredentialResolution
2147 // for ctx.connections.resolveValue's StorageFailure channel — fold it.
2148 Effect.catchTag("CredentialProviderNotRegisteredError", (err) =>
2149 Effect.fail(
2150 new StorageError({
2151 message: `Credential provider "${err.provider}" is not registered.`,
2152 cause: err,
2153 }),
2154 ),
2155 ),
2156 );
2157
2158 /** Re-mint an OAuth connection's access token unconditionally, ignoring the
2159 * stored expiry. Drives the reactive path: the upstream just rejected the

Callers 5

resolveConnectionValueFunction · 0.85
connectionCheckHealthFunction · 0.85
executeFunction · 0.85

Calls 4

shouldRefreshTokenFunction · 0.90
refreshConnectionTokenFunction · 0.85
connectionItemIdsFunction · 0.85
getMethod · 0.65

Tested by

no test coverage detected