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

Function mintOAuthConnection

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

Source from the content-addressed store, hash-verified

4395 // existing name), this path upserts on purpose: reconnect/refresh re-mints
4396 // the SAME connection, stamping the OAuth columns.
4397 const mintOAuthConnection = (
4398 input: MintOAuthConnectionInput,
4399 ): Effect.Effect<Connection, StorageFailure> =>
4400 Effect.gen(function* () {
4401 const name = connectionIdentifier(String(input.name));
4402 yield* requireUserSubject(input.owner);
4403 const integrationRow = yield* findIntegrationRow(input.integration);
4404 if (!integrationRow) {
4405 return yield* new StorageError({
4406 message: `Integration not found: ${input.integration}`,
4407 cause: undefined,
4408 });
4409 }
4410 const keys = yield* Effect.try({
4411 try: () => ownedKeys(input.owner),
4412 catch: (cause) => storageFailureFromUnknown("invalid owner", cause),
4413 });
4414 const now = new Date();
4415 const ref: ConnectionRef = {
4416 owner: input.owner,
4417 integration: input.integration,
4418 name,
4419 };
4420 // Label precedence: an explicit (user-chosen) label always wins; a
4421 // derived label (OIDC claims) only FILLS an empty slot. Like
4422 // `description` below, a reconnect or token refresh must not erase a
4423 // label the user curated. Resolved once, used by every write below.
4424 let identityLabel: string | null = null;
4425 // The core-owned per-connection state this mint writes WHOLESALE:
4426 // whatever a previous grant recorded (a stale reauth verdict, an old
4427 // missing-scope set) describes a credential that no longer exists.
4428 const nextProviderState = {
4429 ...(input.missingOAuthScopes === undefined || input.missingOAuthScopes.length === 0
4430 ? {}
4431 : { missingOAuthScopes: input.missingOAuthScopes }),
4432 ...(input.enterpriseManaged === undefined
4433 ? {}
4434 : {
4435 [ENTERPRISE_MANAGED_PROVIDER_STATE_KEY]: input.enterpriseManaged,
4436 }),
4437 };
4438 // Null, not `{}`, when this grant records nothing: an empty object would
4439 // read back as "state exists and is empty" on a column whose absence is
4440 // what every reader tests.
4441 const providerState =
4442 Object.keys(nextProviderState).length === 0 ? null : nextProviderState;
4443 const credentialProvider = credentialProviders.get(input.provider);
4444 const credentialSet = credentialProvider?.set;
4445 if (!credentialProvider || !credentialSet) {
4446 return yield* new StorageError({
4447 message: `Credential provider ${input.provider} is not registered as writable.`,
4448 cause: undefined,
4449 });
4450 }
4451 const credentialAttemptId = crypto.randomUUID();
4452 const credentialWrite = makeCredentialWriteAttempt(
4453 credentialWriteRuntimeId,
4454 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