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

Function resolveConnectionValues

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

Source from the content-addressed store, hash-verified

1980 // two distinct inputs yields one entry per variable. OAuth connections refresh
1981 // first (always single-input → `{ token: <access> }`).
1982 const resolveConnectionValues = (
1983 row: ConnectionRow,
1984 ): Effect.Effect<Record<string, string | null>, StorageFailure | CredentialResolutionError> =>
1985 Effect.gen(function* () {
1986 const provider = credentialProviders.get(row.provider);
1987 if (!provider) {
1988 return yield* new CredentialProviderNotRegisteredError({
1989 provider: ProviderKey.make(row.provider),
1990 });
1991 }
1992 // OAuth connections refresh their access token before resolving when
1993 // it has expired (or is within the skew window).
1994 const expiresAt = row.expires_at == null ? null : Number(row.expires_at);
1995 if (row.oauth_client != null && shouldRefreshToken({ expiresAt })) {
1996 const access = yield* refreshConnectionToken(row, provider);
1997 return { [PRIMARY_INPUT_VARIABLE]: access };
1998 }
1999 const out: Record<string, string | null> = {};
2000 for (const [variable, itemId] of Object.entries(connectionItemIds(row))) {
2001 out[variable] = yield* provider.get(ProviderItemId.make(itemId));
2002 }
2003 return out;
2004 }).pipe(
2005 // CredentialProviderNotRegisteredError is part of CredentialResolution
2006 // for ctx.connections.resolveValue's StorageFailure channel — fold it.
2007 Effect.catchTag("CredentialProviderNotRegisteredError", (err) =>
2008 Effect.fail(
2009 new StorageError({
2010 message: `Credential provider "${err.provider}" is not registered.`,
2011 cause: err,
2012 }),
2013 ),
2014 ),
2015 );
2016
2017 /** Re-mint an OAuth connection's access token unconditionally, ignoring the
2018 * 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