( owner: Owner, modelSlug: string )
| 441 | */ |
| 442 | export async function readSlackBotToken( |
| 443 | integration: PlatformIntegration |
| 444 | ): Promise<SlackBotTokenRead> { |
| 445 | const owner = getOwnerFromInstallation(integration); |
| 446 | if (!owner) { |
| 447 | // Terminal for this read path: re-reading the same row cannot produce an owner. |
| 448 | captureException(new Error('Slack integration has no exclusive owner'), { |
| 449 | level: 'error', |
| 450 | tags: { component: 'slack-service', op: 'read-slack-credential' }, |
| 451 | extra: { integrationId: integration.id }, |
| 452 | }); |
| 453 | return { status: 'unavailable', reason: 'owner_missing' }; |
| 454 | } |
| 455 | |
| 456 | let credential: SlackOAuthCredential | null; |
| 457 | try { |
| 458 | credential = await getSlackCredentialByIntegrationId(integration.id); |
| 459 | } catch (error) { |
| 460 | captureException(error, { |
| 461 | level: 'error', |
| 462 | tags: { component: 'slack-service', op: 'read-slack-credential' }, |
| 463 | extra: { integrationId: integration.id }, |
| 464 | }); |
| 465 | return { status: 'unavailable', reason: 'read_failed' }; |
| 466 | } |
| 467 | if (!credential) return { status: 'absent' }; |
| 468 | |
| 469 | try { |
| 470 | // A revoked row decrypts to null: Slack already dropped that token, so nothing |
| 471 | // is live and the row is safe to remove. |
| 472 | const token = decryptSlackBotToken(credential, owner); |
| 473 | if (!token) return { status: 'absent' }; |
| 474 | return { status: 'available', token }; |
| 475 | } catch (error) { |
| 476 | captureException(error, { |
| 477 | level: 'error', |
| 478 | tags: { component: 'slack-service', op: 'read-slack-credential' }, |
| 479 | extra: { |
| 480 | integrationId: integration.id, |
| 481 | kind: error instanceof SlackCredentialDecryptionError ? error.kind : 'unknown', |
| 482 | }, |
| 483 | }); |
| 484 | return { status: 'unavailable', reason: 'decrypt_failed' }; |
nothing calls this directly
no test coverage detected