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

Function refreshConnectionToken

packages/core/sdk/src/executor.ts:1642–1666  ·  view source on GitHub ↗
(
      row: ConnectionRow,
      provider: CredentialProvider,
    )

Source from the content-addressed store, hash-verified

1640 });
1641
1642 const refreshConnectionToken = (
1643 row: ConnectionRow,
1644 provider: CredentialProvider,
1645 ): Effect.Effect<string | null, StorageFailure | CredentialResolutionError> =>
1646 // Share a single refresh per connection so concurrent resolves of the same
1647 // connection all await one refresh-token grant (the AS rotates the refresh
1648 // token; parallel grants would race on a consumed token — v1's refresh
1649 // deferred-map). The gate is cleared once the refresh settles so a later
1650 // expiry can refresh again.
1651 Effect.gen(function* () {
1652 const key = connectionKey(row);
1653 const existing = refreshInFlight.get(key);
1654 if (existing) return yield* existing;
1655 // `Effect.cached` memoizes the grant onto a deferred: it runs once and
1656 // replays to every awaiter sharing this entry.
1657 const memoized = yield* Effect.cached(performTokenRefresh(row, provider));
1658 const gated = memoized.pipe(
1659 Effect.ensuring(Effect.sync(() => refreshInFlight.delete(key))),
1660 );
1661 // Re-check after building (a peer fiber may have registered first while
1662 // we built ours) so everyone converges on the same shared grant.
1663 const winner = refreshInFlight.get(key) ?? gated;
1664 if (winner === gated) refreshInFlight.set(key, gated);
1665 return yield* winner;
1666 });
1667
1668 // Resolve every named input of a connection (`variable → value`). A
1669 // single-secret connection yields `{ token: <value> }`; an apiKey method with

Callers 1

resolveConnectionValuesFunction · 0.85

Calls 6

connectionKeyFunction · 0.85
performTokenRefreshFunction · 0.85
setMethod · 0.80
getMethod · 0.65
syncMethod · 0.65
deleteMethod · 0.65

Tested by

no test coverage detected