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

Function resolveConnectionValues

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

Source from the content-addressed store, hash-verified

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