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

Function mintOAuthConnection

packages/core/sdk/src/executor.ts:4331–4637  ·  view source on GitHub ↗
(
      input: MintOAuthConnectionInput,
    )

Source from the content-addressed store, hash-verified

4329 // existing name), this path upserts on purpose: reconnect/refresh re-mints
4330 // the SAME connection, stamping the OAuth columns.
4331 const mintOAuthConnection = (
4332 input: MintOAuthConnectionInput,
4333 ): Effect.Effect<Connection, StorageFailure> =>
4334 Effect.gen(function* () {
4335 const name = connectionIdentifier(String(input.name));
4336 yield* requireUserSubject(input.owner);
4337 const integrationRow = yield* findIntegrationRow(input.integration);
4338 if (!integrationRow) {
4339 return yield* new StorageError({
4340 message: `Integration not found: ${input.integration}`,
4341 cause: undefined,
4342 });
4343 }
4344 const keys = yield* Effect.try({
4345 try: () => ownedKeys(input.owner),
4346 catch: (cause) => storageFailureFromUnknown("invalid owner", cause),
4347 });
4348 const now = new Date();
4349 const ref: ConnectionRef = {
4350 owner: input.owner,
4351 integration: input.integration,
4352 name,
4353 };
4354 // Label precedence: an explicit (user-chosen) label always wins; a
4355 // derived label (OIDC claims) only FILLS an empty slot. Like
4356 // `description` below, a reconnect or token refresh must not erase a
4357 // label the user curated. Resolved once, used by every write below.
4358 let identityLabel: string | null = null;
4359 // The core-owned per-connection state this mint writes WHOLESALE:
4360 // whatever a previous grant recorded (a stale reauth verdict, an old
4361 // missing-scope set) describes a credential that no longer exists.
4362 const nextProviderState = {
4363 ...(input.missingOAuthScopes === undefined || input.missingOAuthScopes.length === 0
4364 ? {}
4365 : { missingOAuthScopes: input.missingOAuthScopes }),
4366 ...(input.enterpriseManaged === undefined
4367 ? {}
4368 : {
4369 [ENTERPRISE_MANAGED_PROVIDER_STATE_KEY]: input.enterpriseManaged,
4370 }),
4371 };
4372 // Null, not `{}`, when this grant records nothing: an empty object would
4373 // read back as "state exists and is empty" on a column whose absence is
4374 // what every reader tests.
4375 const providerState =
4376 Object.keys(nextProviderState).length === 0 ? null : nextProviderState;
4377 const credentialProvider = credentialProviders.get(input.provider);
4378 const credentialSet = credentialProvider?.set;
4379 if (!credentialProvider || !credentialSet) {
4380 return yield* new StorageError({
4381 message: `Credential provider ${input.provider} is not registered as writable.`,
4382 cause: undefined,
4383 });
4384 }
4385 const credentialAttemptId = crypto.randomUUID();
4386 const credentialWrite = makeCredentialWriteAttempt(
4387 credentialWriteRuntimeId,
4388 credentialAttemptId,

Callers 1

createExecutorFunction · 0.85

Calls 15

connectionIdentifierFunction · 0.90
credentialAttemptItemIdFunction · 0.90
snapshotCredentialWritesFunction · 0.90
afterCommitRequiredFunction · 0.90
requireUserSubjectFunction · 0.85
findIntegrationRowFunction · 0.85
ownedKeysFunction · 0.85
findConnectionRowFunction · 0.85
mintedRowIdOfFunction · 0.85

Tested by

no test coverage detected