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

Function resolveConnectionValues

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

Source from the content-addressed store, hash-verified

2988 // two distinct inputs yields one entry per variable. OAuth connections refresh
2989 // first (always single-input → `{ token: <access> }`).
2990 const resolveConnectionValues = (
2991 row: ConnectionRow,
2992 ): Effect.Effect<Record<string, string | null>, StorageFailure | CredentialResolutionError> =>
2993 Effect.gen(function* () {
2994 const provider = credentialProviders.get(row.provider);
2995 if (!provider) {
2996 return yield* new CredentialProviderNotRegisteredError({
2997 provider: ProviderKey.make(row.provider),
2998 });
2999 }
3000 // OAuth connections refresh their access token before resolving when
3001 // it has expired (or is within the skew window).
3002 const expiresAt = row.expires_at == null ? null : Number(row.expires_at);
3003 if (row.oauth_client != null && shouldRefreshToken({ expiresAt })) {
3004 const access = yield* refreshConnectionToken(row, provider);
3005 return { [PRIMARY_INPUT_VARIABLE]: access };
3006 }
3007 const out: Record<string, string | null> = {};
3008 for (const [variable, itemId] of Object.entries(connectionItemIds(row))) {
3009 const value = yield* provider.get(ProviderItemId.make(itemId));
3010 if (value === null && parseCredentialWriteAttempt(row.credential_write) !== null) {
3011 return yield* new CredentialWriteIncompleteError({
3012 message: `Credential write for ${row.owner}/${row.integration}/${row.name} is incomplete; retry the connection operation.`,
3013 cause: undefined,
3014 });
3015 }
3016 out[variable] = value;
3017 }
3018 return out;
3019 }).pipe(
3020 // CredentialProviderNotRegisteredError is part of CredentialResolution
3021 // for ctx.connections.resolveValue's StorageFailure channel — fold it.
3022 Effect.catchTag("CredentialProviderNotRegisteredError", (err) =>
3023 Effect.fail(
3024 new StorageError({
3025 message: `Credential provider "${err.provider}" is not registered.`,
3026 cause: err,
3027 }),
3028 ),
3029 ),
3030 );
3031
3032 /** Re-mint an OAuth connection's access token unconditionally, ignoring the
3033 * stored expiry. Drives the reactive path: the upstream just rejected the

Callers 5

resolveConnectionValueFunction · 0.85
connectionCheckHealthFunction · 0.85
executeFunction · 0.85

Calls 5

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

Tested by

no test coverage detected