@inixiative/integrations 0.2.1 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -13
- package/package.json +4 -3
- package/src/catalog/acceptedCredentialMethods.ts +17 -0
- package/src/catalog/catalogOperationMeta.ts +4 -0
- package/src/catalog/catalogOperations.ts +10 -0
- package/src/catalog/integrationFamilies.ts +12 -0
- package/src/catalog/integrationFamilyDefinition.ts +6 -0
- package/src/catalog/isAccountSuppliedByHost.ts +2 -2
- package/src/catalog/providerAuthenticatesThroughIntegrationFamily.ts +6 -0
- package/src/catalog/providerModel.ts +0 -1
- package/src/catalog/providers.ts +0 -4
- package/src/catalog/providersInIntegrationFamily.ts +5 -0
- package/src/contracts.ts +36 -25
- package/src/credentials/credentialAuth.ts +38 -0
- package/src/credentials/credentialClient.ts +2 -2
- package/src/credentials/exchangeOauthCode.ts +41 -41
- package/src/credentials/mintProviderCredential.ts +26 -40
- package/src/credentials/providerExchangeTimeoutMs.ts +1 -1
- package/src/credentials/refreshProviderCredential.ts +102 -83
- package/src/credentials/renewalError.ts +11 -0
- package/src/credentials/renewalOwner.ts +3 -0
- package/src/credentials/requestOauthToken.ts +28 -0
- package/src/credentials/validateCredentialSecret.ts +5 -5
- package/src/index.ts +0 -1
- package/src/integrationFamilies/atlassianIntegrationFamily.ts +12 -0
- package/src/{providers/github/githubProvider.ts → integrationFamilies/githubIntegrationFamily.ts} +2 -3
- package/src/{providers/google/googleProvider.ts → integrationFamilies/googleIntegrationFamily.ts} +2 -3
- package/src/integrationFamilies/inixiativeIntegrationFamily.ts +8 -0
- package/src/operations/providerOperationInput.ts +6 -0
- package/src/operations/providerOperationInputSchema.ts +36 -0
- package/src/operations/providerOperationOrThrow.ts +23 -0
- package/src/operations/providerOperationSet.ts +7 -0
- package/src/operations/providerOperations.ts +38 -0
- package/src/providers/chorus/chorusProvider.ts +1 -0
- package/src/providers/confluence/confluenceApiBaseUrl.ts +1 -0
- package/src/providers/confluence/confluenceOperations.ts +4 -0
- package/src/providers/confluence/confluenceProvider.ts +6 -8
- package/src/providers/confluence/models/page/fetchConfluencePage.ts +23 -0
- package/src/providers/discord/discordApiBaseUrl.ts +1 -0
- package/src/providers/discord/discordOperations.ts +8 -0
- package/src/providers/discord/discordProvider.ts +5 -14
- package/src/providers/discord/models/channel/discordChannelKind.ts +1 -0
- package/src/providers/discord/models/channel/fetchDiscordChannel.ts +25 -0
- package/src/providers/discord/models/channel/fetchDiscordChannelMessages.ts +37 -0
- package/src/providers/drive/driveApiBaseUrl.ts +1 -0
- package/src/providers/drive/driveOperations.ts +4 -0
- package/src/providers/drive/driveProvider.ts +7 -10
- package/src/providers/drive/models/file/fetchDriveFile.ts +27 -0
- package/src/providers/github/auth/createGithubInstallationToken.ts +19 -0
- package/src/providers/github/auth/fetchGithubAppInstallUrl.ts +21 -0
- package/src/providers/github/auth/fetchGithubAppInstallation.ts +16 -19
- package/src/providers/github/auth/fetchGithubOrganizationRole.ts +22 -22
- package/src/providers/github/auth/fetchGithubUser.ts +10 -4
- package/src/providers/github/auth/githubAppAuth.ts +6 -0
- package/src/providers/github/auth/githubUserAuthorizeUrl.ts +2 -2
- package/src/providers/github/auth/listGithubUserInstallationPage.ts +18 -0
- package/src/providers/github/events/listGithubNotificationPage.ts +18 -0
- package/src/providers/github/githubApiBaseUrl.ts +1 -0
- package/src/providers/github/githubOrganizationProvider.ts +6 -2
- package/src/providers/github/githubPagination.ts +2 -2
- package/src/providers/github/githubRequestHeaders.ts +4 -6
- package/src/providers/github/githubUserProvider.ts +7 -4
- package/src/providers/github/models/account/githubAccount.ts +0 -1
- package/src/providers/github/models/repository/fetchGithubBlob.ts +59 -0
- package/src/providers/github/models/repository/fetchGithubCommit.ts +38 -0
- package/src/providers/github/models/repository/fetchGithubTree.ts +74 -0
- package/src/providers/github/models/repository/githubObjectRequest.ts +15 -0
- package/src/providers/github/models/repository/githubRepository.ts +1 -11
- package/src/providers/github/models/repository/githubRepositoryOperations.ts +10 -0
- package/src/providers/github/models/repository/listGithubInstallationRepositoryPage.ts +18 -0
- package/src/providers/github/models/repository/listGithubUserInstallationRepositoryPage.ts +22 -0
- package/src/providers/github/models/repository/readGithubObjectIdentity.ts +9 -0
- package/src/providers/github/services/fetchGithubUserInstallation.ts +25 -0
- package/src/providers/github/services/listGithubNotifications.ts +27 -0
- package/src/providers/github/services/listInstallationRepositories.ts +34 -0
- package/src/providers/github/services/listUserRepositories.ts +43 -0
- package/src/providers/gmail/gmailApiBaseUrl.ts +1 -0
- package/src/providers/gmail/gmailOperations.ts +10 -0
- package/src/providers/gmail/gmailProvider.ts +8 -11
- package/src/providers/gmail/models/label/listGmailLabelMessages.ts +45 -0
- package/src/providers/gmail/models/message/fetchGmailMessage.ts +19 -0
- package/src/providers/gmail/models/message/fetchGmailMessageBatch.ts +20 -0
- package/src/providers/gmail/models/message/gmailMessageKind.ts +1 -0
- package/src/providers/gmail/models/message/gmailMessageRequest.ts +9 -0
- package/src/providers/gmail/models/message/readGmailMessage.ts +26 -0
- package/src/providers/google/auth/buildGoogleAuthorizationUrl.ts +2 -1
- package/src/providers/google/auth/verifyGoogleIdToken.ts +3 -3
- package/src/providers/jira/jiraApiBaseUrl.ts +1 -0
- package/src/providers/jira/jiraOperations.ts +4 -0
- package/src/providers/jira/jiraProvider.ts +6 -8
- package/src/providers/jira/models/issue/fetchJiraIssue.ts +22 -0
- package/src/providers/linear/events/createLinearWebhook.ts +29 -20
- package/src/providers/linear/events/deleteLinearWebhook.ts +16 -9
- package/src/providers/linear/events/linearWebhook.ts +1 -1
- package/src/providers/linear/events/listLinearWebhookPage.ts +23 -0
- package/src/providers/linear/events/repairLinearWebhook.ts +17 -13
- package/src/providers/linear/linearApiBaseUrl.ts +1 -0
- package/src/providers/linear/linearGraphqlErrorCode.ts +8 -0
- package/src/providers/linear/linearOperations.ts +4 -0
- package/src/providers/linear/linearPagination.ts +3 -9
- package/src/providers/linear/linearProvider.ts +5 -2
- package/src/providers/linear/models/issue/fetchLinearIssue.ts +32 -0
- package/src/providers/linear/models/team/fetchLinearWorkspace.ts +23 -13
- package/src/providers/linear/models/team/linearTeam.ts +0 -1
- package/src/providers/linear/services/listLinearWebhooks.ts +45 -0
- package/src/providers/notion/models/page/fetchNotionPage.ts +32 -0
- package/src/providers/notion/models/page/fetchNotionPageBlocks.ts +39 -0
- package/src/providers/notion/models/page/notionPageKind.ts +1 -0
- package/src/providers/notion/notionApiBaseUrl.ts +1 -0
- package/src/providers/notion/notionOperations.ts +8 -0
- package/src/providers/notion/notionProvider.ts +5 -14
- package/src/providers/notion/notionVersion.ts +1 -0
- package/src/providers/oracle/oracleProvider.ts +1 -0
- package/src/providers/slack/auth/fetchSlackIdentity.ts +14 -6
- package/src/providers/slack/models/account/slackAccount.ts +0 -1
- package/src/providers/slack/models/channel/fetchSlackChannel.ts +32 -0
- package/src/providers/slack/models/channel/fetchSlackChannelMessages.ts +34 -0
- package/src/providers/slack/models/channel/listSlackUserConversations.ts +19 -0
- package/src/providers/slack/models/channel/slackChannel.ts +0 -14
- package/src/providers/slack/readSlackBody.ts +10 -0
- package/src/providers/slack/services/listSlackChannels.ts +23 -0
- package/src/providers/slack/slackApiBaseUrl.ts +1 -0
- package/src/providers/slack/slackOperations.ts +8 -0
- package/src/providers/slack/slackPagination.ts +2 -2
- package/src/providers/slack/slackProvider.ts +9 -1
- package/src/providers/slack/slackProviderError.ts +2 -2
- package/src/providers/teams/models/channel/fetchTeamsChannelMessages.ts +36 -0
- package/src/providers/teams/teamsApiBaseUrl.ts +1 -0
- package/src/providers/teams/teamsOperations.ts +6 -0
- package/src/providers/teams/teamsProvider.ts +5 -8
- package/src/utils/acceptJsonHeaders.ts +1 -0
- package/src/utils/pageQuerySchema.ts +13 -0
- package/src/utils/readProviderLimits.ts +1 -2
- package/src/catalog/familyProducts.ts +0 -5
- package/src/catalog/isFamilyManaged.ts +0 -7
- package/src/catalog/providerFamily.ts +0 -4
- package/src/credentials/fetchRenewalResponse.ts +0 -41
- package/src/credentials/renewalRequest.ts +0 -1
- package/src/operations/buildProviderRequest.ts +0 -54
- package/src/operations/executeProvider.ts +0 -26
- package/src/operations/findOperationHandler.ts +0 -6
- package/src/operations/operationHandler.ts +0 -8
- package/src/operations/operationHandlers.ts +0 -41
- package/src/operations/operationRequestInput.ts +0 -12
- package/src/operations/providerRequestSpec.ts +0 -1
- package/src/providers/confluence/confluenceOperationHandler.ts +0 -14
- package/src/providers/discord/discordOperationHandler.ts +0 -30
- package/src/providers/drive/driveOperationHandler.ts +0 -21
- package/src/providers/github/auth/fetchGithubUserInstallation.ts +0 -21
- package/src/providers/github/auth/githubAppClient.ts +0 -4
- package/src/providers/github/auth/githubAppInstallUrl.ts +0 -20
- package/src/providers/github/auth/githubClientForApp.ts +0 -11
- package/src/providers/github/events/listGithubNotifications.ts +0 -27
- package/src/providers/github/fetchAllGithubPages.ts +0 -12
- package/src/providers/github/iterateGithubPages.ts +0 -12
- package/src/providers/github/models/repository/githubOperationHandler.ts +0 -36
- package/src/providers/github/models/repository/listInstallationRepositories.ts +0 -31
- package/src/providers/github/models/repository/listUserRepositories.ts +0 -36
- package/src/providers/github/models/repository/readGithubObject.ts +0 -85
- package/src/providers/github/requestGithub.ts +0 -18
- package/src/providers/gmail/buildGmailMessageRequest.ts +0 -22
- package/src/providers/gmail/fetchGmailMessages.ts +0 -81
- package/src/providers/gmail/gmailOperationHandler.ts +0 -12
- package/src/providers/jira/jiraOperationHandler.ts +0 -14
- package/src/providers/linear/events/listLinearWebhooks.ts +0 -44
- package/src/providers/linear/fetchAllLinearPages.ts +0 -40
- package/src/providers/linear/linearClient.ts +0 -5
- package/src/providers/linear/linearRequestInput.ts +0 -1
- package/src/providers/linear/models/issue/linearIssue.ts +0 -11
- package/src/providers/linear/models/issue/linearOperationHandler.ts +0 -30
- package/src/providers/linear/requestLinear.ts +0 -51
- package/src/providers/notion/notionOperationHandler.ts +0 -32
- package/src/providers/slack/fetchAllSlackPages.ts +0 -12
- package/src/providers/slack/models/channel/listSlackChannels.ts +0 -26
- package/src/providers/slack/models/channel/slackOperationHandler.ts +0 -30
- package/src/providers/slack/requestSlack.ts +0 -22
- package/src/providers/teams/teamsOperationHandler.ts +0 -24
- package/src/utils/headerNumber.ts +0 -6
- package/src/utils/pagination/applyCaps.ts +0 -18
- package/src/utils/pagination/byCursorKeys.ts +0 -7
- package/src/utils/pagination/byCursorOptions.ts +0 -7
- package/src/utils/pagination/byPageKeys.ts +0 -7
- package/src/utils/pagination/byPageOptions.ts +0 -8
- package/src/utils/pagination/collectPages.ts +0 -27
- package/src/utils/pagination/compactRequest.ts +0 -4
- package/src/utils/pagination/fetchAllByCursor.ts +0 -6
- package/src/utils/pagination/fetchAllByPage.ts +0 -6
- package/src/utils/pagination/fetchAllRequestPages.ts +0 -16
- package/src/utils/pagination/incompletePageWalkError.ts +0 -8
- package/src/utils/pagination/isAnotherPage.ts +0 -20
- package/src/utils/pagination/iterateByCursor.ts +0 -49
- package/src/utils/pagination/iterateByPage.ts +0 -59
- package/src/utils/pagination/iterateProviderPages.ts +0 -27
- package/src/utils/pagination/iterateRequestPages.ts +0 -18
- package/src/utils/pagination/pageWalkError.ts +0 -6
- package/src/utils/pagination/paginationOptions.ts +0 -9
- package/src/utils/pagination/providerPagesOptions.ts +0 -8
- package/src/utils/pagination/providerPagination.ts +0 -6
- package/src/utils/pagination/readPage.ts +0 -29
- package/src/utils/pagination/readPath.ts +0 -12
- package/src/utils/pagination/repeatedCursorError.ts +0 -10
- package/src/utils/providerClient.ts +0 -3
- package/src/utils/providerError.ts +0 -10
- package/src/utils/providerRequest.ts +0 -22
- package/src/utils/providerRequestInput.ts +0 -7
- package/src/utils/providerResponseLimit.ts +0 -1
- package/src/utils/providerSend.ts +0 -1
- package/src/utils/readProviderJson.ts +0 -38
- package/src/utils/readRateLimit.ts +0 -29
- package/src/utils/requestProviderJson.ts +0 -13
- package/src/utils/responseBudget.ts +0 -1
- package/src/utils/sendProviderRequest.ts +0 -33
|
@@ -1,18 +1,33 @@
|
|
|
1
1
|
import { Buffer } from 'node:buffer';
|
|
2
|
+
import { ApiError } from '@inixiative/api-client';
|
|
3
|
+
import {
|
|
4
|
+
type ApiAuth,
|
|
5
|
+
type ApiOperationOptions,
|
|
6
|
+
headerAuth,
|
|
7
|
+
} from '@inixiative/api-client/operation';
|
|
2
8
|
import { z } from 'zod';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
9
|
+
import { findProvider } from '../catalog/findProvider';
|
|
10
|
+
import { integrationFamilyDefinition } from '../catalog/integrationFamilyDefinition';
|
|
11
|
+
import {
|
|
12
|
+
type CredentialSecret,
|
|
13
|
+
credentialSecretSchema,
|
|
14
|
+
type IntegrationFamily,
|
|
15
|
+
type OAuthClient,
|
|
16
|
+
type Provider,
|
|
17
|
+
} from '../contracts';
|
|
18
|
+
import { notionVersion } from '../providers/notion/notionVersion';
|
|
5
19
|
import { jwtClaims } from '../utils/jwtClaims';
|
|
6
|
-
import { ProviderError } from '../utils/providerError';
|
|
7
20
|
import { CODEX_TOKEN_URL } from './codexTokenUrl';
|
|
8
21
|
import type { CredentialClient } from './credentialClient';
|
|
9
|
-
import { fetchRenewalResponse } from './fetchRenewalResponse';
|
|
10
22
|
import { mintProviderCredential } from './mintProviderCredential';
|
|
11
|
-
import
|
|
23
|
+
import { providerExchangeTimeoutMs } from './providerExchangeTimeoutMs';
|
|
24
|
+
import { renewalError } from './renewalError';
|
|
25
|
+
import type { RenewalOwner } from './renewalOwner';
|
|
26
|
+
import { requestOauthToken } from './requestOauthToken';
|
|
12
27
|
|
|
13
28
|
const secondsUntilJwtExpiry = (token: string) => {
|
|
14
29
|
const exp = z.number().int().positive().safeParse(jwtClaims(token)?.exp);
|
|
15
|
-
if (!exp.success) throw new
|
|
30
|
+
if (!exp.success) throw new ApiError('renewal_outcome_unknown', 409);
|
|
16
31
|
return z
|
|
17
32
|
.number()
|
|
18
33
|
.int()
|
|
@@ -21,106 +36,95 @@ const secondsUntilJwtExpiry = (token: string) => {
|
|
|
21
36
|
.parse(exp.data - Math.floor(Date.now() / 1000));
|
|
22
37
|
};
|
|
23
38
|
|
|
39
|
+
const renewalEndpointKey = (owner: RenewalOwner): Provider | IntegrationFamily => {
|
|
40
|
+
if ('integrationFamily' in owner) return owner.integrationFamily;
|
|
41
|
+
const definition = findProvider(owner.provider);
|
|
42
|
+
if (!definition?.integrationFamily || !definition.authMethods.includes('oauth2'))
|
|
43
|
+
return owner.provider;
|
|
44
|
+
return integrationFamilyDefinition(definition.integrationFamily)?.oauth
|
|
45
|
+
? definition.integrationFamily
|
|
46
|
+
: owner.provider;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const familyTokenUrl = (integrationFamily: IntegrationFamily) =>
|
|
50
|
+
z.url().parse(integrationFamilyDefinition(integrationFamily)?.oauth?.tokenUrl);
|
|
51
|
+
|
|
52
|
+
type RefreshRequest = {
|
|
53
|
+
tokenUrl: string;
|
|
54
|
+
encoding: 'form' | 'json';
|
|
55
|
+
fields: Record<string, string>;
|
|
56
|
+
headers?: Record<string, string>;
|
|
57
|
+
auth?: ApiAuth;
|
|
58
|
+
};
|
|
59
|
+
|
|
24
60
|
const refreshRequest = (
|
|
25
|
-
provider:
|
|
61
|
+
provider: Provider | IntegrationFamily,
|
|
26
62
|
secret: CredentialSecret,
|
|
27
63
|
client?: OAuthClient,
|
|
28
|
-
):
|
|
29
|
-
if (!secret.oauth) throw new
|
|
64
|
+
): RefreshRequest => {
|
|
65
|
+
if (!secret.oauth) throw new ApiError('renewal_unsupported', 409);
|
|
30
66
|
const { refreshToken, tenantId } = secret.oauth;
|
|
31
67
|
const clientId = client?.clientId ?? secret.oauth.clientId;
|
|
32
68
|
const clientSecret = client?.clientSecret ?? secret.oauth.clientSecret;
|
|
33
69
|
const publicClient = provider === 'codex';
|
|
34
|
-
if (!clientId || (!clientSecret && !publicClient))
|
|
35
|
-
throw new ProviderError('renewal_unsupported', 409);
|
|
36
|
-
const familyOAuth = providers.find((definition) => definition.key === provider)?.oauth;
|
|
70
|
+
if (!clientId || (!clientSecret && !publicClient)) throw new ApiError('renewal_unsupported', 409);
|
|
37
71
|
const fields = {
|
|
38
72
|
grant_type: 'refresh_token',
|
|
39
73
|
refresh_token: refreshToken,
|
|
40
74
|
client_id: clientId,
|
|
41
75
|
client_secret: clientSecret ?? '',
|
|
42
76
|
};
|
|
43
|
-
const headers = new Headers({
|
|
44
|
-
Accept: 'application/json',
|
|
45
|
-
'Content-Type': 'application/x-www-form-urlencoded',
|
|
46
|
-
});
|
|
47
77
|
switch (provider) {
|
|
48
78
|
case 'slack':
|
|
49
|
-
return {
|
|
50
|
-
|
|
51
|
-
headers,
|
|
52
|
-
body: new URLSearchParams(fields).toString(),
|
|
53
|
-
};
|
|
54
|
-
case 'githubUser':
|
|
55
|
-
return {
|
|
56
|
-
url: z
|
|
57
|
-
.url()
|
|
58
|
-
.parse(providers.find((definition) => definition.key === 'github')?.oauth?.tokenUrl),
|
|
59
|
-
headers,
|
|
60
|
-
body: new URLSearchParams(fields).toString(),
|
|
61
|
-
};
|
|
62
|
-
case 'linear':
|
|
63
|
-
return {
|
|
64
|
-
url: 'https://api.linear.app/oauth/token',
|
|
65
|
-
headers,
|
|
66
|
-
body: new URLSearchParams(fields).toString(),
|
|
67
|
-
};
|
|
79
|
+
return { tokenUrl: 'https://slack.com/api/oauth.v2.access', encoding: 'form', fields };
|
|
80
|
+
case 'github':
|
|
68
81
|
case 'google':
|
|
69
|
-
return {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
body: new URLSearchParams(fields).toString(),
|
|
73
|
-
};
|
|
82
|
+
return { tokenUrl: familyTokenUrl(provider), encoding: 'form', fields };
|
|
83
|
+
case 'linear':
|
|
84
|
+
return { tokenUrl: 'https://api.linear.app/oauth/token', encoding: 'form', fields };
|
|
74
85
|
case 'teams':
|
|
75
86
|
return {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
};
|
|
80
|
-
case 'jira':
|
|
81
|
-
case 'confluence':
|
|
82
|
-
headers.set('Content-Type', 'application/json');
|
|
83
|
-
return {
|
|
84
|
-
url: 'https://auth.atlassian.com/oauth/token',
|
|
85
|
-
headers,
|
|
86
|
-
body: JSON.stringify(fields),
|
|
87
|
+
tokenUrl: `https://login.microsoftonline.com/${z.uuid().parse(tenantId)}/oauth2/v2.0/token`,
|
|
88
|
+
encoding: 'form',
|
|
89
|
+
fields,
|
|
87
90
|
};
|
|
91
|
+
case 'atlassian':
|
|
92
|
+
return { tokenUrl: familyTokenUrl(provider), encoding: 'json', fields };
|
|
88
93
|
case 'notion':
|
|
89
|
-
headers.set('Content-Type', 'application/json');
|
|
90
|
-
headers.set('Notion-Version', '2026-03-11');
|
|
91
|
-
headers.set(
|
|
92
|
-
'Authorization',
|
|
93
|
-
`Basic ${Buffer.from(`${clientId}:${clientSecret}`).toString('base64')}`,
|
|
94
|
-
);
|
|
95
94
|
return {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
95
|
+
tokenUrl: 'https://api.notion.com/v1/oauth/token',
|
|
96
|
+
encoding: 'json',
|
|
97
|
+
fields: { grant_type: 'refresh_token', refresh_token: refreshToken },
|
|
98
|
+
headers: { 'Notion-Version': notionVersion },
|
|
99
|
+
auth: headerAuth(
|
|
100
|
+
'Authorization',
|
|
101
|
+
async () => Buffer.from(`${clientId}:${clientSecret}`).toString('base64'),
|
|
102
|
+
{ prefix: 'Basic ' },
|
|
103
|
+
),
|
|
99
104
|
};
|
|
100
105
|
case 'codex':
|
|
101
|
-
headers.set('Content-Type', 'application/json');
|
|
102
106
|
return {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
107
|
+
tokenUrl: CODEX_TOKEN_URL,
|
|
108
|
+
encoding: 'json',
|
|
109
|
+
fields: {
|
|
106
110
|
client_id: clientId,
|
|
107
111
|
grant_type: 'refresh_token',
|
|
108
112
|
refresh_token: refreshToken,
|
|
109
113
|
scope: 'openid profile email',
|
|
110
|
-
}
|
|
114
|
+
},
|
|
111
115
|
};
|
|
112
116
|
default:
|
|
113
|
-
throw new
|
|
117
|
+
throw new ApiError('renewal_unsupported', 409);
|
|
114
118
|
}
|
|
115
119
|
};
|
|
116
120
|
|
|
117
121
|
const refreshedSecret = (
|
|
118
|
-
provider:
|
|
122
|
+
provider: Provider | IntegrationFamily,
|
|
119
123
|
secret: CredentialSecret,
|
|
120
124
|
data: Record<string, unknown>,
|
|
121
125
|
) => {
|
|
122
126
|
if (data.error || (provider === 'slack' && data.ok !== true))
|
|
123
|
-
throw new
|
|
127
|
+
throw new ApiError(
|
|
124
128
|
data.error === 'ratelimited' ? 'renewal_temporarily_unavailable' : 'renewal_rejected',
|
|
125
129
|
data.error === 'ratelimited' ? 503 : 409,
|
|
126
130
|
);
|
|
@@ -133,40 +137,55 @@ const refreshedSecret = (
|
|
|
133
137
|
...(typeof data.id_token === 'string' ? { idToken: data.id_token } : {}),
|
|
134
138
|
},
|
|
135
139
|
});
|
|
136
|
-
if (!refreshed.success) throw new
|
|
140
|
+
if (!refreshed.success) throw new ApiError('renewal_outcome_unknown', 409);
|
|
137
141
|
if (
|
|
138
|
-
[
|
|
142
|
+
[
|
|
143
|
+
'slack',
|
|
144
|
+
'linear',
|
|
145
|
+
'atlassian',
|
|
146
|
+
'jira',
|
|
147
|
+
'confluence',
|
|
148
|
+
'notion',
|
|
149
|
+
'codex',
|
|
150
|
+
'githubUser',
|
|
151
|
+
].includes(provider) &&
|
|
139
152
|
!data.refresh_token
|
|
140
153
|
)
|
|
141
|
-
throw new
|
|
154
|
+
throw new ApiError('renewal_outcome_unknown', 409);
|
|
142
155
|
const expiresIn =
|
|
143
156
|
provider === 'notion' && data.expires_in === undefined
|
|
144
157
|
? null
|
|
145
158
|
: provider === 'codex' && data.expires_in === undefined
|
|
146
159
|
? secondsUntilJwtExpiry(refreshed.data.token)
|
|
147
160
|
: z.number().int().positive().max(31536000).safeParse(data.expires_in).data;
|
|
148
|
-
if (expiresIn === undefined) throw new
|
|
161
|
+
if (expiresIn === undefined) throw new ApiError('renewal_outcome_unknown', 409);
|
|
149
162
|
return { secret: refreshed.data, expiresIn };
|
|
150
163
|
};
|
|
151
164
|
|
|
152
165
|
export const refreshProviderCredential = async (
|
|
153
166
|
client: CredentialClient,
|
|
154
|
-
{
|
|
167
|
+
{ secret: value, ...owner }: RenewalOwner & { secret: unknown },
|
|
168
|
+
options?: ApiOperationOptions,
|
|
155
169
|
) => {
|
|
156
170
|
const secret = credentialSecretSchema.parse(value);
|
|
171
|
+
const provider = renewalEndpointKey(owner);
|
|
157
172
|
if (secret.clientCredentials)
|
|
158
|
-
return await mintProviderCredential(
|
|
159
|
-
|
|
160
|
-
clientCredentials: secret.clientCredentials,
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
173
|
+
return await mintProviderCredential(
|
|
174
|
+
client,
|
|
175
|
+
{ provider, clientCredentials: secret.clientCredentials },
|
|
176
|
+
options,
|
|
177
|
+
);
|
|
178
|
+
const { tokenUrl, auth, ...request } = refreshRequest(provider, secret, client.app);
|
|
179
|
+
const data = await requestOauthToken({ baseUrl: tokenUrl, auth, send: client.send }, request, {
|
|
180
|
+
timeoutMs: providerExchangeTimeoutMs,
|
|
181
|
+
...options,
|
|
182
|
+
}).catch((error: unknown) => {
|
|
183
|
+
throw renewalError(error);
|
|
184
|
+
});
|
|
166
185
|
try {
|
|
167
186
|
return refreshedSecret(provider, secret, data);
|
|
168
187
|
} catch (error) {
|
|
169
|
-
if (error instanceof
|
|
170
|
-
throw new
|
|
188
|
+
if (error instanceof ApiError) throw error;
|
|
189
|
+
throw new ApiError('renewal_outcome_unknown', 409);
|
|
171
190
|
}
|
|
172
191
|
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ApiError } from '@inixiative/api-client';
|
|
2
|
+
|
|
3
|
+
export const renewalError = (error: unknown) => {
|
|
4
|
+
if (!(error instanceof ApiError)) return error;
|
|
5
|
+
if (error.code === 'provider_unreachable') return new ApiError('renewal_outcome_unknown', 409);
|
|
6
|
+
const status = error.providerStatus ?? 0;
|
|
7
|
+
if (error.code === 'provider_rate_limited' || status >= 500)
|
|
8
|
+
return new ApiError('renewal_temporarily_unavailable', 503);
|
|
9
|
+
if (status >= 400) return new ApiError('renewal_rejected', 409);
|
|
10
|
+
return new ApiError('renewal_outcome_unknown', 409);
|
|
11
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { makeApiOperation } from '@inixiative/api-client/operation';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
const inputSchema = z.strictObject({
|
|
5
|
+
encoding: z.enum(['form', 'json']),
|
|
6
|
+
fields: z.record(z.string(), z.string()),
|
|
7
|
+
headers: z.record(z.string(), z.string()).optional(),
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
export const requestOauthToken = makeApiOperation({
|
|
11
|
+
key: 'oauth.token',
|
|
12
|
+
idempotent: false,
|
|
13
|
+
response: 'json',
|
|
14
|
+
responseLimitBytes: 128 * 1024,
|
|
15
|
+
input: inputSchema,
|
|
16
|
+
toRequest: ({ encoding, fields, headers }) => ({
|
|
17
|
+
path: '',
|
|
18
|
+
method: 'POST',
|
|
19
|
+
headers: {
|
|
20
|
+
Accept: 'application/json',
|
|
21
|
+
'Content-Type':
|
|
22
|
+
encoding === 'form' ? 'application/x-www-form-urlencoded' : 'application/json',
|
|
23
|
+
...headers,
|
|
24
|
+
},
|
|
25
|
+
body: encoding === 'form' ? new URLSearchParams(fields).toString() : fields,
|
|
26
|
+
}),
|
|
27
|
+
parse: ({ body }) => z.record(z.string(), z.unknown()).parse(body),
|
|
28
|
+
});
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
+
import { ApiError } from '@inixiative/api-client';
|
|
1
2
|
import { credentialSecretSchema } from '../contracts';
|
|
2
|
-
import { ProviderError } from '../utils/providerError';
|
|
3
3
|
|
|
4
4
|
export const validateCredentialSecret = (method: string, secret: unknown, provider: string) => {
|
|
5
5
|
const parsed = credentialSecretSchema.parse(secret);
|
|
6
6
|
if ((method === 'oauth2') !== Boolean(parsed.oauth))
|
|
7
|
-
throw new
|
|
7
|
+
throw new ApiError('Credential method and OAuth bundle must match', 400);
|
|
8
8
|
if ((method === 'clientCredentials') !== Boolean(parsed.clientCredentials))
|
|
9
|
-
throw new
|
|
9
|
+
throw new ApiError('Credential method and client credentials must match', 400);
|
|
10
10
|
if (
|
|
11
11
|
method === 'oauth2' &&
|
|
12
12
|
(!parsed.oauth?.clientId || (!parsed.oauth.clientSecret && provider !== 'codex'))
|
|
13
13
|
)
|
|
14
|
-
throw new
|
|
14
|
+
throw new ApiError('OAuth requires the application client ID and secret', 400);
|
|
15
15
|
if (method === 'oauth2' && provider === 'teams' && !parsed.oauth?.tenantId)
|
|
16
|
-
throw new
|
|
16
|
+
throw new ApiError('Microsoft OAuth requires a tenant UUID', 400);
|
|
17
17
|
return parsed;
|
|
18
18
|
};
|
package/src/index.ts
CHANGED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { IntegrationFamilyDefinition } from '../contracts';
|
|
2
|
+
|
|
3
|
+
export const atlassianIntegrationFamily: IntegrationFamilyDefinition = {
|
|
4
|
+
key: 'atlassian',
|
|
5
|
+
name: 'Atlassian',
|
|
6
|
+
documentationUrl: 'https://developer.atlassian.com/cloud/jira/platform/oauth-2-3lo-apps/',
|
|
7
|
+
authMethods: ['oauth2'],
|
|
8
|
+
oauth: {
|
|
9
|
+
authorizeUrl: 'https://auth.atlassian.com/authorize',
|
|
10
|
+
tokenUrl: 'https://auth.atlassian.com/oauth/token',
|
|
11
|
+
},
|
|
12
|
+
};
|
package/src/{providers/github/githubProvider.ts → integrationFamilies/githubIntegrationFamily.ts}
RENAMED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { IntegrationFamilyDefinition } from '../contracts';
|
|
2
2
|
|
|
3
|
-
export const
|
|
3
|
+
export const githubIntegrationFamily: IntegrationFamilyDefinition = {
|
|
4
4
|
key: 'github',
|
|
5
5
|
name: 'GitHub',
|
|
6
6
|
documentationUrl: 'https://docs.github.com/en/apps/overview',
|
|
7
7
|
authMethods: ['oauth2'],
|
|
8
|
-
operations: [],
|
|
9
8
|
oauth: {
|
|
10
9
|
authorizeUrl: 'https://github.com/login/oauth/authorize',
|
|
11
10
|
tokenUrl: 'https://github.com/login/oauth/access_token',
|
package/src/{providers/google/googleProvider.ts → integrationFamilies/googleIntegrationFamily.ts}
RENAMED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { IntegrationFamilyDefinition } from '../contracts';
|
|
2
2
|
|
|
3
|
-
export const
|
|
3
|
+
export const googleIntegrationFamily: IntegrationFamilyDefinition = {
|
|
4
4
|
key: 'google',
|
|
5
5
|
name: 'Google',
|
|
6
6
|
documentationUrl: 'https://developers.google.com/identity/protocols/oauth2/web-server',
|
|
7
7
|
authMethods: ['oauth2'],
|
|
8
|
-
operations: [],
|
|
9
8
|
oauth: {
|
|
10
9
|
authorizeUrl: 'https://accounts.google.com/o/oauth2/v2/auth',
|
|
11
10
|
tokenUrl: 'https://oauth2.googleapis.com/token',
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { IntegrationFamilyDefinition } from '../contracts';
|
|
2
|
+
|
|
3
|
+
export const inixiativeIntegrationFamily: IntegrationFamilyDefinition = {
|
|
4
|
+
key: 'inixiative',
|
|
5
|
+
name: 'inixiative',
|
|
6
|
+
documentationUrl: 'https://github.com/inixiative/integrations',
|
|
7
|
+
authMethods: [],
|
|
8
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { Provider } from '../contracts';
|
|
3
|
+
import { integrationConfigurationSchemas } from '../resources/integrationConfigurationSchemas';
|
|
4
|
+
import { resourceExternalIdSchemas } from '../resources/resourceExternalIdSchemas';
|
|
5
|
+
import { resourceMetadataSchemas } from '../resources/resourceMetadataSchemas';
|
|
6
|
+
|
|
7
|
+
const noInput = z.object({});
|
|
8
|
+
|
|
9
|
+
export const providerOperationInputSchema = <
|
|
10
|
+
P extends Provider,
|
|
11
|
+
Input extends z.ZodType = typeof noInput,
|
|
12
|
+
>(
|
|
13
|
+
providers: readonly [P, ...P[]],
|
|
14
|
+
kind: string,
|
|
15
|
+
input?: Input,
|
|
16
|
+
) => {
|
|
17
|
+
const [provider] = providers;
|
|
18
|
+
// why: one operation serves several providers only when they read its resource the same way.
|
|
19
|
+
const isShared = providers.every(
|
|
20
|
+
(each) =>
|
|
21
|
+
resourceExternalIdSchemas[each] === resourceExternalIdSchemas[provider] &&
|
|
22
|
+
resourceMetadataSchemas[each] === resourceMetadataSchemas[provider] &&
|
|
23
|
+
integrationConfigurationSchemas[each] === integrationConfigurationSchemas[provider],
|
|
24
|
+
);
|
|
25
|
+
if (!isShared) throw new Error(`${providers.join(', ')} read a ${kind} differently`);
|
|
26
|
+
return z.object({
|
|
27
|
+
resource: z.object({
|
|
28
|
+
kind: z.literal(kind),
|
|
29
|
+
externalId: resourceExternalIdSchemas[provider],
|
|
30
|
+
metadata: resourceMetadataSchemas[provider],
|
|
31
|
+
}),
|
|
32
|
+
configuration: integrationConfigurationSchemas[provider],
|
|
33
|
+
limit: z.number().int().min(1).max(50),
|
|
34
|
+
input: (input ?? noInput) as Input,
|
|
35
|
+
});
|
|
36
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ApiError } from '@inixiative/api-client';
|
|
2
|
+
import type { AnyApiOperation, ApiOperation } from '@inixiative/api-client/operation';
|
|
3
|
+
import type { CatalogOperationMeta } from '../catalog/catalogOperationMeta';
|
|
4
|
+
import type { Provider } from '../contracts';
|
|
5
|
+
import type { ProviderOperationInput } from './providerOperationInput';
|
|
6
|
+
import { providerOperations } from './providerOperations';
|
|
7
|
+
|
|
8
|
+
type CallableProviderOperation = ApiOperation<
|
|
9
|
+
ProviderOperationInput | ProviderOperationInput[],
|
|
10
|
+
unknown,
|
|
11
|
+
AnyApiOperation['definition'] & { meta?: CatalogOperationMeta; batch?: { maxItems: number } },
|
|
12
|
+
Record<never, never>
|
|
13
|
+
>;
|
|
14
|
+
|
|
15
|
+
export const providerOperationOrThrow = (
|
|
16
|
+
provider: Provider,
|
|
17
|
+
key: string,
|
|
18
|
+
): CallableProviderOperation => {
|
|
19
|
+
const operations = providerOperations[provider];
|
|
20
|
+
if (!Object.hasOwn(operations, key)) throw new ApiError('unsupported_operation', 400);
|
|
21
|
+
// why: an operation's call type is its parsed input, and it parses whatever it is handed.
|
|
22
|
+
return operations[key] as unknown as CallableProviderOperation;
|
|
23
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { AnyApiOperation } from '@inixiative/api-client/operation';
|
|
2
|
+
import type { CatalogOperationMeta } from '../catalog/catalogOperationMeta';
|
|
3
|
+
|
|
4
|
+
export type ProviderOperationSet = Record<
|
|
5
|
+
string,
|
|
6
|
+
AnyApiOperation & { readonly definition: { meta?: CatalogOperationMeta } }
|
|
7
|
+
>;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { Provider } from '../contracts';
|
|
2
|
+
import { confluenceOperations } from '../providers/confluence/confluenceOperations';
|
|
3
|
+
import { discordOperations } from '../providers/discord/discordOperations';
|
|
4
|
+
import { driveOperations } from '../providers/drive/driveOperations';
|
|
5
|
+
import { githubRepositoryOperations } from '../providers/github/models/repository/githubRepositoryOperations';
|
|
6
|
+
import { gmailOperations } from '../providers/gmail/gmailOperations';
|
|
7
|
+
import { jiraOperations } from '../providers/jira/jiraOperations';
|
|
8
|
+
import { linearOperations } from '../providers/linear/linearOperations';
|
|
9
|
+
import { notionOperations } from '../providers/notion/notionOperations';
|
|
10
|
+
import { slackOperations } from '../providers/slack/slackOperations';
|
|
11
|
+
import { teamsOperations } from '../providers/teams/teamsOperations';
|
|
12
|
+
import type { ProviderOperationSet } from './providerOperationSet';
|
|
13
|
+
|
|
14
|
+
export const providerOperations: Record<Provider, ProviderOperationSet> = {
|
|
15
|
+
slack: slackOperations,
|
|
16
|
+
discord: discordOperations,
|
|
17
|
+
teams: teamsOperations,
|
|
18
|
+
linear: linearOperations,
|
|
19
|
+
notion: notionOperations,
|
|
20
|
+
jira: jiraOperations,
|
|
21
|
+
gmail: gmailOperations,
|
|
22
|
+
drive: driveOperations,
|
|
23
|
+
confluence: confluenceOperations,
|
|
24
|
+
githubOrganization: githubRepositoryOperations,
|
|
25
|
+
githubUser: githubRepositoryOperations,
|
|
26
|
+
anthropic: {},
|
|
27
|
+
openai: {},
|
|
28
|
+
geminiApi: {},
|
|
29
|
+
archive: {},
|
|
30
|
+
foundry: {},
|
|
31
|
+
oracle: {},
|
|
32
|
+
chorus: {},
|
|
33
|
+
railway: {},
|
|
34
|
+
render: {},
|
|
35
|
+
claude: {},
|
|
36
|
+
codex: {},
|
|
37
|
+
muse: {},
|
|
38
|
+
};
|
|
@@ -11,6 +11,7 @@ export const chorusProvider: ProviderDefinition = {
|
|
|
11
11
|
name: 'Chorus',
|
|
12
12
|
documentationUrl: 'https://github.com/inixiative/chorus',
|
|
13
13
|
authMethods: [],
|
|
14
|
+
integrationFamily: 'inixiative',
|
|
14
15
|
inbound: true,
|
|
15
16
|
delivery: 'installationSocket',
|
|
16
17
|
holderHandleKinds: [chorusResourceKind],
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const confluenceApiBaseUrl = 'https://api.atlassian.com/ex/confluence/';
|
|
@@ -1,16 +1,14 @@
|
|
|
1
|
+
import { catalogOperations } from '../../catalog/catalogOperations';
|
|
1
2
|
import type { ProviderDefinition } from '../../contracts';
|
|
3
|
+
import { confluenceApiBaseUrl } from './confluenceApiBaseUrl';
|
|
4
|
+
import { confluenceOperations } from './confluenceOperations';
|
|
2
5
|
|
|
3
6
|
export const confluenceProvider: ProviderDefinition = {
|
|
4
7
|
key: 'confluence',
|
|
5
8
|
name: 'Confluence',
|
|
6
9
|
documentationUrl: 'https://developer.atlassian.com/cloud/confluence/rest/v2/api-group-page/',
|
|
7
10
|
authMethods: ['bearer', 'oauth2'],
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
name: 'Read a page',
|
|
12
|
-
resourceKind: 'page',
|
|
13
|
-
requiredScopes: ['read:page:confluence'],
|
|
14
|
-
},
|
|
15
|
-
],
|
|
11
|
+
integrationFamily: 'atlassian',
|
|
12
|
+
apiBaseUrl: confluenceApiBaseUrl,
|
|
13
|
+
operations: catalogOperations(confluenceOperations),
|
|
16
14
|
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { makeApiOperation } from '@inixiative/api-client/operation';
|
|
2
|
+
import { providerOperationInputSchema } from '../../../../operations/providerOperationInputSchema';
|
|
3
|
+
import { acceptJsonHeaders } from '../../../../utils/acceptJsonHeaders';
|
|
4
|
+
import { objectSchema } from '../../../../utils/objectSchema';
|
|
5
|
+
import { select } from '../../../../utils/select';
|
|
6
|
+
|
|
7
|
+
const kind = 'page';
|
|
8
|
+
|
|
9
|
+
export const fetchConfluencePage = makeApiOperation({
|
|
10
|
+
key: 'pages.read',
|
|
11
|
+
idempotent: true,
|
|
12
|
+
response: 'json',
|
|
13
|
+
meta: { name: 'Read a page', resourceKind: kind, requiredScopes: ['read:page:confluence'] },
|
|
14
|
+
input: providerOperationInputSchema(['confluence'], kind),
|
|
15
|
+
toRequest: ({ resource, configuration }) => ({
|
|
16
|
+
path: ':cloudId/wiki/api/v2/pages/:pageId',
|
|
17
|
+
headers: acceptJsonHeaders,
|
|
18
|
+
params: { cloudId: configuration.cloudId, pageId: resource.externalId },
|
|
19
|
+
query: { 'body-format': 'storage' },
|
|
20
|
+
}),
|
|
21
|
+
parse: ({ body }) =>
|
|
22
|
+
select(objectSchema.parse(body), ['id', 'title', 'status', 'body', 'version']),
|
|
23
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const discordApiBaseUrl = 'https://discord.com/api/v10/';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { defineApiOperations } from '@inixiative/api-client/operation';
|
|
2
|
+
import { fetchDiscordChannel } from './models/channel/fetchDiscordChannel';
|
|
3
|
+
import { fetchDiscordChannelMessages } from './models/channel/fetchDiscordChannelMessages';
|
|
4
|
+
|
|
5
|
+
export const discordOperations = defineApiOperations({
|
|
6
|
+
'channels.read': fetchDiscordChannel,
|
|
7
|
+
'messages.read': fetchDiscordChannelMessages,
|
|
8
|
+
});
|
|
@@ -1,22 +1,13 @@
|
|
|
1
|
+
import { catalogOperations } from '../../catalog/catalogOperations';
|
|
1
2
|
import type { ProviderDefinition } from '../../contracts';
|
|
3
|
+
import { discordApiBaseUrl } from './discordApiBaseUrl';
|
|
4
|
+
import { discordOperations } from './discordOperations';
|
|
2
5
|
|
|
3
6
|
export const discordProvider: ProviderDefinition = {
|
|
4
7
|
key: 'discord',
|
|
5
8
|
name: 'Discord',
|
|
6
9
|
documentationUrl: 'https://discord.com/developers/docs/resources/message#get-channel-messages',
|
|
7
10
|
authMethods: ['apiKey'],
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
key: 'channels.read',
|
|
11
|
-
name: 'Read channel details',
|
|
12
|
-
resourceKind: 'channel',
|
|
13
|
-
requiredScopes: ['VIEW_CHANNEL'],
|
|
14
|
-
},
|
|
15
|
-
{
|
|
16
|
-
key: 'messages.read',
|
|
17
|
-
name: 'Read channel messages',
|
|
18
|
-
resourceKind: 'channel',
|
|
19
|
-
requiredScopes: ['VIEW_CHANNEL and READ_MESSAGE_HISTORY'],
|
|
20
|
-
},
|
|
21
|
-
],
|
|
11
|
+
apiBaseUrl: discordApiBaseUrl,
|
|
12
|
+
operations: catalogOperations(discordOperations),
|
|
22
13
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const discordChannelKind = 'channel';
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { makeApiOperation } from '@inixiative/api-client/operation';
|
|
2
|
+
import { providerOperationInputSchema } from '../../../../operations/providerOperationInputSchema';
|
|
3
|
+
import { acceptJsonHeaders } from '../../../../utils/acceptJsonHeaders';
|
|
4
|
+
import { objectSchema } from '../../../../utils/objectSchema';
|
|
5
|
+
import { select } from '../../../../utils/select';
|
|
6
|
+
import { discordChannelKind } from './discordChannelKind';
|
|
7
|
+
|
|
8
|
+
export const fetchDiscordChannel = makeApiOperation({
|
|
9
|
+
key: 'channels.read',
|
|
10
|
+
idempotent: true,
|
|
11
|
+
response: 'json',
|
|
12
|
+
meta: {
|
|
13
|
+
name: 'Read channel details',
|
|
14
|
+
resourceKind: discordChannelKind,
|
|
15
|
+
requiredScopes: ['VIEW_CHANNEL'],
|
|
16
|
+
},
|
|
17
|
+
input: providerOperationInputSchema(['discord'], discordChannelKind),
|
|
18
|
+
toRequest: ({ resource }) => ({
|
|
19
|
+
path: 'channels/:channelId',
|
|
20
|
+
headers: acceptJsonHeaders,
|
|
21
|
+
params: { channelId: resource.externalId },
|
|
22
|
+
}),
|
|
23
|
+
parse: ({ body }) =>
|
|
24
|
+
select(objectSchema.parse(body), ['id', 'name', 'type', 'guild_id', 'topic']),
|
|
25
|
+
});
|