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

Function resolveConnectionValues

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

Source from the content-addressed store, hash-verified

2641 // two distinct inputs yields one entry per variable. OAuth connections refresh
2642 // first (always single-input → `{ token: <access> }`).
2643 const resolveConnectionValues = (
2644 row: ConnectionRow,
2645 ): Effect.Effect<Record<string, string | null>, StorageFailure | CredentialResolutionError> =>
2646 Effect.gen(function* () {
2647 const provider = credentialProviders.get(row.provider);
2648 if (!provider) {
2649 return yield* new CredentialProviderNotRegisteredError({
2650 provider: ProviderKey.make(row.provider),
2651 });
2652 }
2653 // OAuth connections refresh their access token before resolving when
2654 // it has expired (or is within the skew window).
2655 const expiresAt = row.expires_at == null ? null : Number(row.expires_at);
2656 if (row.oauth_client != null && shouldRefreshToken({ expiresAt })) {
2657 const access = yield* refreshConnectionToken(row, provider);
2658 return { [PRIMARY_INPUT_VARIABLE]: access };
2659 }
2660 const out: Record<string, string | null> = {};
2661 for (const [variable, itemId] of Object.entries(connectionItemIds(row))) {
2662 out[variable] = yield* provider.get(ProviderItemId.make(itemId));
2663 }
2664 return out;
2665 }).pipe(
2666 // CredentialProviderNotRegisteredError is part of CredentialResolution
2667 // for ctx.connections.resolveValue's StorageFailure channel — fold it.
2668 Effect.catchTag("CredentialProviderNotRegisteredError", (err) =>
2669 Effect.fail(
2670 new StorageError({
2671 message: `Credential provider "${err.provider}" is not registered.`,
2672 cause: err,
2673 }),
2674 ),
2675 ),
2676 );
2677
2678 /** Re-mint an OAuth connection's access token unconditionally, ignoring the
2679 * 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