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

Function resolveConnectionValues

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

Source from the content-addressed store, hash-verified

2061 // two distinct inputs yields one entry per variable. OAuth connections refresh
2062 // first (always single-input → `{ token: <access> }`).
2063 const resolveConnectionValues = (
2064 row: ConnectionRow,
2065 ): Effect.Effect<Record<string, string | null>, StorageFailure | CredentialResolutionError> =>
2066 Effect.gen(function* () {
2067 const provider = credentialProviders.get(row.provider);
2068 if (!provider) {
2069 return yield* new CredentialProviderNotRegisteredError({
2070 provider: ProviderKey.make(row.provider),
2071 });
2072 }
2073 // OAuth connections refresh their access token before resolving when
2074 // it has expired (or is within the skew window).
2075 const expiresAt = row.expires_at == null ? null : Number(row.expires_at);
2076 if (row.oauth_client != null && shouldRefreshToken({ expiresAt })) {
2077 const access = yield* refreshConnectionToken(row, provider);
2078 return { [PRIMARY_INPUT_VARIABLE]: access };
2079 }
2080 const out: Record<string, string | null> = {};
2081 for (const [variable, itemId] of Object.entries(connectionItemIds(row))) {
2082 out[variable] = yield* provider.get(ProviderItemId.make(itemId));
2083 }
2084 return out;
2085 }).pipe(
2086 // CredentialProviderNotRegisteredError is part of CredentialResolution
2087 // for ctx.connections.resolveValue's StorageFailure channel — fold it.
2088 Effect.catchTag("CredentialProviderNotRegisteredError", (err) =>
2089 Effect.fail(
2090 new StorageError({
2091 message: `Credential provider "${err.provider}" is not registered.`,
2092 cause: err,
2093 }),
2094 ),
2095 ),
2096 );
2097
2098 /** Re-mint an OAuth connection's access token unconditionally, ignoring the
2099 * 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