@inixiative/integrations 0.3.0 → 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 +3 -2
- package/src/catalog/catalogOperationMeta.ts +4 -0
- package/src/catalog/catalogOperations.ts +10 -0
- package/src/catalog/providerModel.ts +0 -1
- package/src/contracts.ts +1 -10
- package/src/credentials/credentialAuth.ts +38 -0
- package/src/credentials/credentialClient.ts +2 -2
- package/src/credentials/exchangeOauthCode.ts +30 -36
- package/src/credentials/mintProviderCredential.ts +26 -40
- package/src/credentials/providerExchangeTimeoutMs.ts +1 -1
- package/src/credentials/refreshProviderCredential.ts +62 -65
- package/src/credentials/renewalError.ts +11 -0
- package/src/credentials/requestOauthToken.ts +28 -0
- package/src/credentials/validateCredentialSecret.ts +5 -5
- package/src/index.ts +0 -1
- 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/confluence/confluenceApiBaseUrl.ts +1 -0
- package/src/providers/confluence/confluenceOperations.ts +4 -0
- package/src/providers/confluence/confluenceProvider.ts +5 -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 +5 -8
- 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/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 +5 -1
- package/src/providers/github/githubPagination.ts +2 -2
- package/src/providers/github/githubRequestHeaders.ts +4 -6
- package/src/providers/github/githubUserProvider.ts +5 -2
- 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 +6 -9
- 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/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 +5 -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/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/credentials/fetchRenewalResponse.ts +0 -41
- package/src/credentials/renewalRequest.ts +0 -1
- package/src/operations/buildProviderRequest.ts +0 -55
- 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 -39
- 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
package/src/index.ts
CHANGED
|
@@ -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
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const confluenceApiBaseUrl = 'https://api.atlassian.com/ex/confluence/';
|
|
@@ -1,4 +1,7 @@
|
|
|
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',
|
|
@@ -6,12 +9,6 @@ export const confluenceProvider: ProviderDefinition = {
|
|
|
6
9
|
documentationUrl: 'https://developer.atlassian.com/cloud/confluence/rest/v2/api-group-page/',
|
|
7
10
|
authMethods: ['bearer', 'oauth2'],
|
|
8
11
|
integrationFamily: 'atlassian',
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
key: 'pages.read',
|
|
12
|
-
name: 'Read a page',
|
|
13
|
-
resourceKind: 'page',
|
|
14
|
-
requiredScopes: ['read:page:confluence'],
|
|
15
|
-
},
|
|
16
|
-
],
|
|
12
|
+
apiBaseUrl: confluenceApiBaseUrl,
|
|
13
|
+
operations: catalogOperations(confluenceOperations),
|
|
17
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
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { makeApiOperation } from '@inixiative/api-client/operation';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { providerOperationInputSchema } from '../../../../operations/providerOperationInputSchema';
|
|
4
|
+
import { acceptJsonHeaders } from '../../../../utils/acceptJsonHeaders';
|
|
5
|
+
import { select } from '../../../../utils/select';
|
|
6
|
+
import { discordChannelKind } from './discordChannelKind';
|
|
7
|
+
|
|
8
|
+
export const fetchDiscordChannelMessages = makeApiOperation({
|
|
9
|
+
key: 'messages.read',
|
|
10
|
+
idempotent: true,
|
|
11
|
+
response: 'json',
|
|
12
|
+
meta: {
|
|
13
|
+
name: 'Read channel messages',
|
|
14
|
+
resourceKind: discordChannelKind,
|
|
15
|
+
requiredScopes: ['VIEW_CHANNEL and READ_MESSAGE_HISTORY'],
|
|
16
|
+
},
|
|
17
|
+
input: providerOperationInputSchema(['discord'], discordChannelKind),
|
|
18
|
+
toRequest: ({ resource, limit }) => ({
|
|
19
|
+
path: 'channels/:channelId/messages',
|
|
20
|
+
headers: acceptJsonHeaders,
|
|
21
|
+
params: { channelId: resource.externalId },
|
|
22
|
+
query: { limit },
|
|
23
|
+
}),
|
|
24
|
+
parse: ({ body }, { limit }) => {
|
|
25
|
+
const messages = z.array(z.unknown()).parse(body);
|
|
26
|
+
return {
|
|
27
|
+
messages: messages.map((item) => {
|
|
28
|
+
const message = select(item, ['id', 'content', 'timestamp', 'type', 'author']);
|
|
29
|
+
return {
|
|
30
|
+
...message,
|
|
31
|
+
author: select(message.author ?? {}, ['id', 'username', 'global_name']),
|
|
32
|
+
};
|
|
33
|
+
}),
|
|
34
|
+
hasMore: messages.length >= limit,
|
|
35
|
+
};
|
|
36
|
+
},
|
|
37
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const driveApiBaseUrl = 'https://www.googleapis.com/drive/v3/';
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
import { catalogOperations } from '../../catalog/catalogOperations';
|
|
1
2
|
import type { ProviderDefinition } from '../../contracts';
|
|
3
|
+
import { driveApiBaseUrl } from './driveApiBaseUrl';
|
|
4
|
+
import { driveOperations } from './driveOperations';
|
|
2
5
|
|
|
3
6
|
export const driveProvider: ProviderDefinition = {
|
|
4
7
|
key: 'drive',
|
|
@@ -7,12 +10,6 @@ export const driveProvider: ProviderDefinition = {
|
|
|
7
10
|
authMethods: ['integrationFamily'],
|
|
8
11
|
integrationFamily: 'google',
|
|
9
12
|
oauthScopes: ['https://www.googleapis.com/auth/drive.metadata.readonly'],
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
key: 'files.read',
|
|
13
|
-
name: 'Read file metadata',
|
|
14
|
-
resourceKind: 'file',
|
|
15
|
-
requiredScopes: ['https://www.googleapis.com/auth/drive.metadata.readonly'],
|
|
16
|
-
},
|
|
17
|
-
],
|
|
13
|
+
apiBaseUrl: driveApiBaseUrl,
|
|
14
|
+
operations: catalogOperations(driveOperations),
|
|
18
15
|
};
|
|
@@ -0,0 +1,27 @@
|
|
|
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 = 'file';
|
|
8
|
+
const fields = ['id', 'name', 'mimeType', 'description', 'modifiedTime', 'size'];
|
|
9
|
+
|
|
10
|
+
export const fetchDriveFile = makeApiOperation({
|
|
11
|
+
key: 'files.read',
|
|
12
|
+
idempotent: true,
|
|
13
|
+
response: 'json',
|
|
14
|
+
meta: {
|
|
15
|
+
name: 'Read file metadata',
|
|
16
|
+
resourceKind: kind,
|
|
17
|
+
requiredScopes: ['https://www.googleapis.com/auth/drive.metadata.readonly'],
|
|
18
|
+
},
|
|
19
|
+
input: providerOperationInputSchema(['drive'], kind),
|
|
20
|
+
toRequest: ({ resource }) => ({
|
|
21
|
+
path: 'files/:fileId',
|
|
22
|
+
headers: acceptJsonHeaders,
|
|
23
|
+
params: { fileId: resource.externalId },
|
|
24
|
+
query: { fields: fields.join(','), supportsAllDrives: 'true' },
|
|
25
|
+
}),
|
|
26
|
+
parse: ({ body }) => select(objectSchema.parse(body), fields),
|
|
27
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { makeApiOperation } from '@inixiative/api-client/operation';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { githubRequestHeaders } from '../githubRequestHeaders';
|
|
4
|
+
|
|
5
|
+
export const createGithubInstallationToken = makeApiOperation({
|
|
6
|
+
key: 'app.installations.accessTokens.create',
|
|
7
|
+
idempotent: false,
|
|
8
|
+
response: 'json',
|
|
9
|
+
responseLimitBytes: 128 * 1024,
|
|
10
|
+
input: z.strictObject({ installationId: z.string().min(1) }),
|
|
11
|
+
toRequest: ({ installationId }) => ({
|
|
12
|
+
path: 'app/installations/:installationId/access_tokens',
|
|
13
|
+
method: 'POST',
|
|
14
|
+
params: { installationId },
|
|
15
|
+
headers: githubRequestHeaders,
|
|
16
|
+
body: { permissions: { contents: 'read' } },
|
|
17
|
+
}),
|
|
18
|
+
parse: ({ body }) => z.record(z.string(), z.unknown()).parse(body),
|
|
19
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { makeApiOperation } from '@inixiative/api-client/operation';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { githubRequestHeaders } from '../githubRequestHeaders';
|
|
4
|
+
|
|
5
|
+
const githubAppSchema = z.object({
|
|
6
|
+
html_url: z.url({ protocol: /^https$/, hostname: /^github\.com$/ }),
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
export const fetchGithubAppInstallUrl = makeApiOperation({
|
|
10
|
+
key: 'app.read',
|
|
11
|
+
idempotent: true,
|
|
12
|
+
response: 'json',
|
|
13
|
+
input: z.strictObject({ state: z.string().min(1) }),
|
|
14
|
+
toRequest: () => ({ path: 'app', headers: githubRequestHeaders }),
|
|
15
|
+
parse: ({ body }, { state }) => {
|
|
16
|
+
const { html_url } = githubAppSchema.parse(body);
|
|
17
|
+
const url = new URL(`${html_url.replace(/\/+$/, '')}/installations/new`);
|
|
18
|
+
url.searchParams.set('state', state);
|
|
19
|
+
return url.toString();
|
|
20
|
+
},
|
|
21
|
+
});
|
|
@@ -1,21 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import { githubClientForApp } from './githubClientForApp';
|
|
1
|
+
import { makeApiOperation } from '@inixiative/api-client/operation';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { githubRequestHeaders } from '../githubRequestHeaders';
|
|
5
4
|
import { githubInstallationSchema } from './githubInstallationSchema';
|
|
6
5
|
|
|
7
|
-
export const fetchGithubAppInstallation =
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
};
|
|
6
|
+
export const fetchGithubAppInstallation = makeApiOperation({
|
|
7
|
+
key: 'app.installations.read',
|
|
8
|
+
idempotent: true,
|
|
9
|
+
response: 'json',
|
|
10
|
+
readableStatuses: [404],
|
|
11
|
+
input: z.strictObject({ installationId: z.string().min(1) }),
|
|
12
|
+
toRequest: ({ installationId }) => ({
|
|
13
|
+
path: 'app/installations/:installationId',
|
|
14
|
+
params: { installationId },
|
|
15
|
+
headers: githubRequestHeaders,
|
|
16
|
+
}),
|
|
17
|
+
parse: ({ status, body }) => (status === 404 ? null : githubInstallationSchema.parse(body)),
|
|
18
|
+
});
|
|
@@ -1,27 +1,27 @@
|
|
|
1
|
+
import { ApiError } from '@inixiative/api-client';
|
|
2
|
+
import { readRateLimit } from '@inixiative/api-client/http';
|
|
3
|
+
import { makeApiOperation } from '@inixiative/api-client/operation';
|
|
1
4
|
import { z } from 'zod';
|
|
2
|
-
import
|
|
3
|
-
import { ProviderError } from '../../../utils/providerError';
|
|
4
|
-
import { requestGithub } from '../requestGithub';
|
|
5
|
+
import { githubRequestHeaders } from '../githubRequestHeaders';
|
|
5
6
|
|
|
6
7
|
const membershipSchema = z.object({ state: z.string(), role: z.string() });
|
|
7
8
|
|
|
8
|
-
export const fetchGithubOrganizationRole =
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
9
|
+
export const fetchGithubOrganizationRole = makeApiOperation({
|
|
10
|
+
key: 'user.memberships.orgs.read',
|
|
11
|
+
idempotent: true,
|
|
12
|
+
response: 'json',
|
|
13
|
+
readableStatuses: [403, 404],
|
|
14
|
+
input: z.strictObject({ organizationLogin: z.string().min(1) }),
|
|
15
|
+
toRequest: ({ organizationLogin }) => ({
|
|
16
|
+
path: 'user/memberships/orgs/:organizationLogin',
|
|
17
|
+
params: { organizationLogin },
|
|
18
|
+
headers: githubRequestHeaders,
|
|
19
|
+
}),
|
|
20
|
+
parse: ({ status, headers, body }) => {
|
|
21
|
+
const { rateLimited, retryAfterMs } = readRateLimit(headers, status);
|
|
22
|
+
if (rateLimited) throw new ApiError('provider_rate_limited', 502, retryAfterMs);
|
|
23
|
+
if (status !== 200) return null;
|
|
24
|
+
const membership = membershipSchema.parse(body);
|
|
18
25
|
return membership.state === 'active' ? membership.role : null;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
error instanceof ProviderError &&
|
|
22
|
-
['provider_not_found', 'provider_access_denied'].includes(error.code)
|
|
23
|
-
)
|
|
24
|
-
return null;
|
|
25
|
-
throw error;
|
|
26
|
-
}
|
|
27
|
-
};
|
|
26
|
+
},
|
|
27
|
+
});
|
|
@@ -1,11 +1,17 @@
|
|
|
1
|
+
import { makeApiOperation } from '@inixiative/api-client/operation';
|
|
1
2
|
import { z } from 'zod';
|
|
2
|
-
import
|
|
3
|
-
import { requestGithub } from '../requestGithub';
|
|
3
|
+
import { githubRequestHeaders } from '../githubRequestHeaders';
|
|
4
4
|
|
|
5
5
|
const githubUserSchema = z.object({
|
|
6
6
|
id: z.number().int().positive(),
|
|
7
7
|
login: z.string().min(1).max(39),
|
|
8
8
|
});
|
|
9
9
|
|
|
10
|
-
export const fetchGithubUser =
|
|
11
|
-
|
|
10
|
+
export const fetchGithubUser = makeApiOperation({
|
|
11
|
+
key: 'user.read',
|
|
12
|
+
idempotent: true,
|
|
13
|
+
response: 'json',
|
|
14
|
+
input: z.strictObject({}),
|
|
15
|
+
toRequest: () => ({ path: 'user', headers: githubRequestHeaders }),
|
|
16
|
+
parse: ({ body }) => githubUserSchema.parse(body),
|
|
17
|
+
});
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { bearerAuth } from '@inixiative/api-client/operation';
|
|
2
|
+
import type { SigningClient } from '../../../contracts';
|
|
3
|
+
import { githubAppJwt } from './githubAppJwt';
|
|
4
|
+
|
|
5
|
+
export const githubAppAuth = (app: Pick<SigningClient, 'appId' | 'privateKey'>) =>
|
|
6
|
+
bearerAuth(() => githubAppJwt(app));
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { makeApiOperation } from '@inixiative/api-client/operation';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { pageQuerySchema } from '../../../utils/pageQuerySchema';
|
|
4
|
+
import { githubPagination } from '../githubPagination';
|
|
5
|
+
import { githubRequestHeaders } from '../githubRequestHeaders';
|
|
6
|
+
|
|
7
|
+
export const listGithubUserInstallationPage = makeApiOperation({
|
|
8
|
+
key: 'user.installations.list',
|
|
9
|
+
idempotent: true,
|
|
10
|
+
response: 'json',
|
|
11
|
+
input: z.object({ query: pageQuerySchema(githubPagination) }),
|
|
12
|
+
toRequest: ({ query }) => ({
|
|
13
|
+
path: 'user/installations',
|
|
14
|
+
query: query,
|
|
15
|
+
headers: githubRequestHeaders,
|
|
16
|
+
}),
|
|
17
|
+
parse: ({ body }) => body,
|
|
18
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { makeApiOperation } from '@inixiative/api-client/operation';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { pageQuerySchema } from '../../../utils/pageQuerySchema';
|
|
4
|
+
import { githubPagination } from '../githubPagination';
|
|
5
|
+
import { githubRequestHeaders } from '../githubRequestHeaders';
|
|
6
|
+
|
|
7
|
+
export const listGithubNotificationPage = makeApiOperation({
|
|
8
|
+
key: 'notifications.list',
|
|
9
|
+
idempotent: true,
|
|
10
|
+
response: 'json',
|
|
11
|
+
input: z.object({ since: z.iso.datetime(), query: pageQuerySchema(githubPagination) }),
|
|
12
|
+
toRequest: ({ since, query }) => ({
|
|
13
|
+
path: 'notifications',
|
|
14
|
+
query: { all: 'true', participating: 'true', since, ...query },
|
|
15
|
+
headers: githubRequestHeaders,
|
|
16
|
+
}),
|
|
17
|
+
parse: ({ body }) => body,
|
|
18
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const githubApiBaseUrl = 'https://api.github.com/';
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
import { catalogOperations } from '../../catalog/catalogOperations';
|
|
1
2
|
import type { ProviderDefinition } from '../../contracts';
|
|
3
|
+
import { githubApiBaseUrl } from './githubApiBaseUrl';
|
|
2
4
|
import { githubRepository } from './models/repository/githubRepository';
|
|
5
|
+
import { githubRepositoryOperations } from './models/repository/githubRepositoryOperations';
|
|
3
6
|
|
|
4
7
|
export const githubOrganizationProvider: ProviderDefinition = {
|
|
5
8
|
key: 'githubOrganization',
|
|
@@ -8,6 +11,7 @@ export const githubOrganizationProvider: ProviderDefinition = {
|
|
|
8
11
|
'https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/authenticating-as-a-github-app-installation',
|
|
9
12
|
authMethods: ['clientCredentials'],
|
|
10
13
|
integrationFamily: 'github',
|
|
11
|
-
|
|
14
|
+
apiBaseUrl: githubApiBaseUrl,
|
|
15
|
+
operations: [...catalogOperations(githubRepositoryOperations), ...githubRepository.events],
|
|
12
16
|
eventResourceExternalId: githubRepository.externalIdOfEvent,
|
|
13
17
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ApiPagination } from '@inixiative/api-client/http/pagination';
|
|
2
2
|
|
|
3
3
|
export const githubPagination = {
|
|
4
4
|
strategy: 'page',
|
|
5
5
|
keys: { page: 'page', pageSize: 'per_page', data: '', total: 'total_count' },
|
|
6
6
|
pageSize: 100,
|
|
7
|
-
} satisfies
|
|
7
|
+
} satisfies ApiPagination;
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { githubApiVersion } from './githubApiVersion';
|
|
2
2
|
|
|
3
|
-
export const githubRequestHeaders =
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
if (token) headers.set('Authorization', `Bearer ${token}`);
|
|
8
|
-
return headers;
|
|
3
|
+
export const githubRequestHeaders = {
|
|
4
|
+
Accept: 'application/vnd.github+json',
|
|
5
|
+
'X-GitHub-Api-Version': githubApiVersion,
|
|
6
|
+
'User-Agent': 'inixiative-integrations',
|
|
9
7
|
};
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import { catalogOperations } from '../../catalog/catalogOperations';
|
|
1
2
|
import type { ProviderDefinition } from '../../contracts';
|
|
3
|
+
import { githubApiBaseUrl } from './githubApiBaseUrl';
|
|
2
4
|
import { githubAccount } from './models/account/githubAccount';
|
|
3
|
-
import {
|
|
5
|
+
import { githubRepositoryOperations } from './models/repository/githubRepositoryOperations';
|
|
4
6
|
|
|
5
7
|
export const githubUserProvider: ProviderDefinition = {
|
|
6
8
|
key: 'githubUser',
|
|
@@ -9,5 +11,6 @@ export const githubUserProvider: ProviderDefinition = {
|
|
|
9
11
|
'https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/authenticating-with-a-github-app-on-behalf-of-a-user',
|
|
10
12
|
authMethods: ['integrationFamily', 'bearer'],
|
|
11
13
|
integrationFamily: 'github',
|
|
12
|
-
|
|
14
|
+
apiBaseUrl: githubApiBaseUrl,
|
|
15
|
+
operations: [...catalogOperations(githubRepositoryOperations), ...githubAccount.events],
|
|
13
16
|
};
|