(
row: ConnectionRow,
)
| 2947 | // two distinct inputs yields one entry per variable. OAuth connections refresh |
| 2948 | // first (always single-input → `{ token: <access> }`). |
| 2949 | const resolveConnectionValues = ( |
| 2950 | row: ConnectionRow, |
| 2951 | ): Effect.Effect<Record<string, string | null>, StorageFailure | CredentialResolutionError> => |
| 2952 | Effect.gen(function* () { |
| 2953 | const provider = credentialProviders.get(row.provider); |
| 2954 | if (!provider) { |
| 2955 | return yield* new CredentialProviderNotRegisteredError({ |
| 2956 | provider: ProviderKey.make(row.provider), |
| 2957 | }); |
| 2958 | } |
| 2959 | // OAuth connections refresh their access token before resolving when |
| 2960 | // it has expired (or is within the skew window). |
| 2961 | const expiresAt = row.expires_at == null ? null : Number(row.expires_at); |
| 2962 | if (row.oauth_client != null && shouldRefreshToken({ expiresAt })) { |
| 2963 | const access = yield* refreshConnectionToken(row, provider); |
| 2964 | return { [PRIMARY_INPUT_VARIABLE]: access }; |
| 2965 | } |
| 2966 | const out: Record<string, string | null> = {}; |
| 2967 | for (const [variable, itemId] of Object.entries(connectionItemIds(row))) { |
| 2968 | const value = yield* provider.get(ProviderItemId.make(itemId)); |
| 2969 | if (value === null && parseCredentialWriteAttempt(row.credential_write) !== null) { |
| 2970 | return yield* new CredentialWriteIncompleteError({ |
| 2971 | message: `Credential write for ${row.owner}/${row.integration}/${row.name} is incomplete; retry the connection operation.`, |
| 2972 | cause: undefined, |
| 2973 | }); |
| 2974 | } |
| 2975 | out[variable] = value; |
| 2976 | } |
| 2977 | return out; |
| 2978 | }).pipe( |
| 2979 | // CredentialProviderNotRegisteredError is part of CredentialResolution |
| 2980 | // for ctx.connections.resolveValue's StorageFailure channel — fold it. |
| 2981 | Effect.catchTag("CredentialProviderNotRegisteredError", (err) => |
| 2982 | Effect.fail( |
| 2983 | new StorageError({ |
| 2984 | message: `Credential provider "${err.provider}" is not registered.`, |
| 2985 | cause: err, |
| 2986 | }), |
| 2987 | ), |
| 2988 | ), |
| 2989 | ); |
| 2990 | |
| 2991 | /** Re-mint an OAuth connection's access token unconditionally, ignoring the |
| 2992 | * stored expiry. Drives the reactive path: the upstream just rejected the |
no test coverage detected