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

Function resolveConnectionValues

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

Source from the content-addressed store, hash-verified

1686 // two distinct inputs yields one entry per variable. OAuth connections refresh
1687 // first (always single-input → `{ token: <access> }`).
1688 const resolveConnectionValues = (
1689 row: ConnectionRow,
1690 ): Effect.Effect<Record<string, string | null>, StorageFailure | CredentialResolutionError> =>
1691 Effect.gen(function* () {
1692 const provider = credentialProviders.get(row.provider);
1693 if (!provider) {
1694 return yield* new CredentialProviderNotRegisteredError({
1695 provider: ProviderKey.make(row.provider),
1696 });
1697 }
1698 // OAuth connections refresh their access token before resolving when
1699 // it has expired (or is within the skew window).
1700 const expiresAt = row.expires_at == null ? null : Number(row.expires_at);
1701 if (row.oauth_client != null && shouldRefreshToken({ expiresAt })) {
1702 const access = yield* refreshConnectionToken(row, provider);
1703 return { [PRIMARY_INPUT_VARIABLE]: access };
1704 }
1705 const out: Record<string, string | null> = {};
1706 for (const [variable, itemId] of Object.entries(connectionItemIds(row))) {
1707 out[variable] = yield* provider.get(ProviderItemId.make(itemId));
1708 }
1709 return out;
1710 }).pipe(
1711 // CredentialProviderNotRegisteredError is part of CredentialResolution
1712 // for ctx.connections.resolveValue's StorageFailure channel — fold it.
1713 Effect.catchTag("CredentialProviderNotRegisteredError", (err) =>
1714 Effect.fail(
1715 new StorageError({
1716 message: `Credential provider "${err.provider}" is not registered.`,
1717 cause: err,
1718 }),
1719 ),
1720 ),
1721 );
1722
1723 /** The primary (`token`) value — the public seam for OAuth + single-input
1724 * callers that only ever need one value. */

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