@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,5 +1,7 @@
|
|
|
1
|
+
import { catalogOperations } from '../../catalog/catalogOperations';
|
|
1
2
|
import type { ProviderDefinition } from '../../contracts';
|
|
2
|
-
import {
|
|
3
|
+
import { linearApiBaseUrl } from './linearApiBaseUrl';
|
|
4
|
+
import { linearOperations } from './linearOperations';
|
|
3
5
|
import { linearTeam } from './models/team/linearTeam';
|
|
4
6
|
|
|
5
7
|
export const linearProvider: ProviderDefinition = {
|
|
@@ -7,6 +9,7 @@ export const linearProvider: ProviderDefinition = {
|
|
|
7
9
|
name: 'Linear',
|
|
8
10
|
documentationUrl: 'https://linear.app/developers/graphql',
|
|
9
11
|
authMethods: ['apiKey', 'bearer', 'oauth2'],
|
|
10
|
-
|
|
12
|
+
apiBaseUrl: linearApiBaseUrl,
|
|
13
|
+
operations: [...catalogOperations(linearOperations), ...linearTeam.events],
|
|
11
14
|
syncedResourceKinds: [linearTeam.kind],
|
|
12
15
|
};
|
|
@@ -0,0 +1,32 @@
|
|
|
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 { linearGraphqlErrorCode } from '../../linearGraphqlErrorCode';
|
|
7
|
+
|
|
8
|
+
const kind = 'issue';
|
|
9
|
+
|
|
10
|
+
export const fetchLinearIssue = makeApiOperation({
|
|
11
|
+
key: 'issues.read',
|
|
12
|
+
idempotent: true,
|
|
13
|
+
response: 'graphql',
|
|
14
|
+
errorCode: linearGraphqlErrorCode,
|
|
15
|
+
meta: { name: 'Read an issue', resourceKind: kind, requiredScopes: ['read'] },
|
|
16
|
+
input: providerOperationInputSchema(['linear'], kind),
|
|
17
|
+
toRequest: ({ resource }) => ({
|
|
18
|
+
headers: acceptJsonHeaders,
|
|
19
|
+
query:
|
|
20
|
+
'query OwnerIssue($id: String!) { issue(id: $id) { id identifier title description url state { name } } }',
|
|
21
|
+
variables: { id: resource.externalId },
|
|
22
|
+
}),
|
|
23
|
+
parse: ({ body }) =>
|
|
24
|
+
select(objectSchema.parse(body).issue, [
|
|
25
|
+
'id',
|
|
26
|
+
'identifier',
|
|
27
|
+
'title',
|
|
28
|
+
'description',
|
|
29
|
+
'url',
|
|
30
|
+
'state',
|
|
31
|
+
]),
|
|
32
|
+
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { makeApiOperation } from '@inixiative/api-client/operation';
|
|
1
2
|
import { z } from 'zod';
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
3
|
+
import { acceptJsonHeaders } from '../../../../utils/acceptJsonHeaders';
|
|
4
|
+
import { linearGraphqlErrorCode } from '../../linearGraphqlErrorCode';
|
|
4
5
|
|
|
5
6
|
const workspaceSchema = z.object({
|
|
6
7
|
organization: z.object({ id: z.string().min(1), urlKey: z.string() }),
|
|
@@ -17,14 +18,23 @@ const workspaceSchema = z.object({
|
|
|
17
18
|
}),
|
|
18
19
|
});
|
|
19
20
|
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
21
|
+
export const fetchLinearWorkspace = makeApiOperation({
|
|
22
|
+
key: 'workspace.read',
|
|
23
|
+
idempotent: true,
|
|
24
|
+
response: 'graphql',
|
|
25
|
+
errorCode: linearGraphqlErrorCode,
|
|
26
|
+
input: z.strictObject({}),
|
|
27
|
+
toRequest: () => ({
|
|
28
|
+
headers: acceptJsonHeaders,
|
|
29
|
+
query:
|
|
30
|
+
'query Workspace { organization { id urlKey } teams(first: 250) { pageInfo { hasNextPage } nodes { id key name private } } }',
|
|
31
|
+
}),
|
|
32
|
+
parse: ({ body }) => {
|
|
33
|
+
const workspace = workspaceSchema.parse(body);
|
|
34
|
+
return {
|
|
35
|
+
organizationId: workspace.organization.id,
|
|
36
|
+
teams: workspace.teams.nodes,
|
|
37
|
+
truncated: workspace.teams.pageInfo.hasNextPage,
|
|
38
|
+
};
|
|
39
|
+
},
|
|
40
|
+
});
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { ApiClient } from '@inixiative/api-client';
|
|
2
|
+
import { ApiError } from '@inixiative/api-client';
|
|
3
|
+
import { fetchAllApiPages } from '@inixiative/api-client/http/pagination';
|
|
4
|
+
import type { ApiOperationOptions } from '@inixiative/api-client/operation';
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
import { listLinearWebhookPage } from '../events/listLinearWebhookPage';
|
|
7
|
+
import { linearPagination } from '../linearPagination';
|
|
8
|
+
|
|
9
|
+
const webhooksSchema = z.array(
|
|
10
|
+
z.object({
|
|
11
|
+
id: z.string(),
|
|
12
|
+
url: z.string().nullish(),
|
|
13
|
+
allPublicTeams: z.boolean(),
|
|
14
|
+
enabled: z.boolean(),
|
|
15
|
+
secret: z.string().nullish(),
|
|
16
|
+
resourceTypes: z.array(z.string()),
|
|
17
|
+
team: z.object({ id: z.string() }).nullish(),
|
|
18
|
+
}),
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
export const listLinearWebhooks = async (client: ApiClient, options?: ApiOperationOptions) => {
|
|
22
|
+
const webhooks = webhooksSchema.parse(
|
|
23
|
+
await fetchAllApiPages(linearPagination, {
|
|
24
|
+
keys: {
|
|
25
|
+
data: 'webhooks.nodes',
|
|
26
|
+
nextCursor: 'webhooks.pageInfo.endCursor',
|
|
27
|
+
hasMore: 'webhooks.pageInfo.hasNextPage',
|
|
28
|
+
},
|
|
29
|
+
fetchPage: (variables) => listLinearWebhookPage(client, { variables }, options),
|
|
30
|
+
maxPages: 40,
|
|
31
|
+
onCapped: () => {
|
|
32
|
+
throw new ApiError('provider_invalid_response');
|
|
33
|
+
},
|
|
34
|
+
}),
|
|
35
|
+
);
|
|
36
|
+
return webhooks.map((webhook) => ({
|
|
37
|
+
id: webhook.id,
|
|
38
|
+
url: webhook.url ?? null,
|
|
39
|
+
allPublicTeams: webhook.allPublicTeams,
|
|
40
|
+
enabled: webhook.enabled,
|
|
41
|
+
secret: webhook.secret ?? null,
|
|
42
|
+
resourceTypes: webhook.resourceTypes,
|
|
43
|
+
teamId: webhook.team?.id ?? null,
|
|
44
|
+
}));
|
|
45
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
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 { notionVersion } from '../../notionVersion';
|
|
7
|
+
import { notionPageKind } from './notionPageKind';
|
|
8
|
+
|
|
9
|
+
export const fetchNotionPage = makeApiOperation({
|
|
10
|
+
key: 'pages.read',
|
|
11
|
+
idempotent: true,
|
|
12
|
+
response: 'json',
|
|
13
|
+
meta: {
|
|
14
|
+
name: 'Read page properties',
|
|
15
|
+
resourceKind: notionPageKind,
|
|
16
|
+
requiredScopes: ['Read content'],
|
|
17
|
+
},
|
|
18
|
+
input: providerOperationInputSchema(['notion'], notionPageKind),
|
|
19
|
+
toRequest: ({ resource }) => ({
|
|
20
|
+
path: 'pages/:pageId',
|
|
21
|
+
params: { pageId: resource.externalId },
|
|
22
|
+
headers: { ...acceptJsonHeaders, 'Notion-Version': notionVersion },
|
|
23
|
+
}),
|
|
24
|
+
parse: ({ body }) =>
|
|
25
|
+
select(objectSchema.parse(body), [
|
|
26
|
+
'id',
|
|
27
|
+
'properties',
|
|
28
|
+
'created_time',
|
|
29
|
+
'last_edited_time',
|
|
30
|
+
'archived',
|
|
31
|
+
]),
|
|
32
|
+
});
|
|
@@ -0,0 +1,39 @@
|
|
|
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 { objectSchema } from '../../../../utils/objectSchema';
|
|
6
|
+
import { select } from '../../../../utils/select';
|
|
7
|
+
import { notionVersion } from '../../notionVersion';
|
|
8
|
+
import { notionPageKind } from './notionPageKind';
|
|
9
|
+
|
|
10
|
+
export const fetchNotionPageBlocks = makeApiOperation({
|
|
11
|
+
key: 'blocks.read',
|
|
12
|
+
idempotent: true,
|
|
13
|
+
response: 'json',
|
|
14
|
+
meta: {
|
|
15
|
+
name: 'Read page blocks',
|
|
16
|
+
resourceKind: notionPageKind,
|
|
17
|
+
requiredScopes: ['Read content'],
|
|
18
|
+
},
|
|
19
|
+
input: providerOperationInputSchema(['notion'], notionPageKind),
|
|
20
|
+
toRequest: ({ resource, limit }) => ({
|
|
21
|
+
path: 'blocks/:pageId/children',
|
|
22
|
+
params: { pageId: resource.externalId },
|
|
23
|
+
query: { page_size: limit },
|
|
24
|
+
headers: { ...acceptJsonHeaders, 'Notion-Version': notionVersion },
|
|
25
|
+
}),
|
|
26
|
+
parse: ({ body }) => {
|
|
27
|
+
const data = objectSchema.parse(body);
|
|
28
|
+
return {
|
|
29
|
+
blocks: z
|
|
30
|
+
.array(z.unknown())
|
|
31
|
+
.parse(data.results)
|
|
32
|
+
.map((item) => {
|
|
33
|
+
const block = objectSchema.parse(item);
|
|
34
|
+
return select(block, ['id', 'type', 'has_children', String(block.type)]);
|
|
35
|
+
}),
|
|
36
|
+
hasMore: data.has_more === true,
|
|
37
|
+
};
|
|
38
|
+
},
|
|
39
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const notionPageKind = 'page';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const notionApiBaseUrl = 'https://api.notion.com/v1/';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { defineApiOperations } from '@inixiative/api-client/operation';
|
|
2
|
+
import { fetchNotionPage } from './models/page/fetchNotionPage';
|
|
3
|
+
import { fetchNotionPageBlocks } from './models/page/fetchNotionPageBlocks';
|
|
4
|
+
|
|
5
|
+
export const notionOperations = defineApiOperations({
|
|
6
|
+
'pages.read': fetchNotionPage,
|
|
7
|
+
'blocks.read': fetchNotionPageBlocks,
|
|
8
|
+
});
|
|
@@ -1,22 +1,13 @@
|
|
|
1
|
+
import { catalogOperations } from '../../catalog/catalogOperations';
|
|
1
2
|
import type { ProviderDefinition } from '../../contracts';
|
|
3
|
+
import { notionApiBaseUrl } from './notionApiBaseUrl';
|
|
4
|
+
import { notionOperations } from './notionOperations';
|
|
2
5
|
|
|
3
6
|
export const notionProvider: ProviderDefinition = {
|
|
4
7
|
key: 'notion',
|
|
5
8
|
name: 'Notion',
|
|
6
9
|
documentationUrl: 'https://developers.notion.com/reference/get-block-children',
|
|
7
10
|
authMethods: ['bearer', 'oauth2'],
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
key: 'pages.read',
|
|
11
|
-
name: 'Read page properties',
|
|
12
|
-
resourceKind: 'page',
|
|
13
|
-
requiredScopes: ['Read content'],
|
|
14
|
-
},
|
|
15
|
-
{
|
|
16
|
-
key: 'blocks.read',
|
|
17
|
-
name: 'Read page blocks',
|
|
18
|
-
resourceKind: 'page',
|
|
19
|
-
requiredScopes: ['Read content'],
|
|
20
|
-
},
|
|
21
|
-
],
|
|
11
|
+
apiBaseUrl: notionApiBaseUrl,
|
|
12
|
+
operations: catalogOperations(notionOperations),
|
|
22
13
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const notionVersion = '2026-03-11';
|
|
@@ -1,10 +1,18 @@
|
|
|
1
|
+
import { makeApiOperation } from '@inixiative/api-client/operation';
|
|
1
2
|
import { z } from 'zod';
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
3
|
+
import { acceptJsonHeaders } from '../../../utils/acceptJsonHeaders';
|
|
4
|
+
import { readSlackBody } from '../readSlackBody';
|
|
4
5
|
|
|
5
6
|
const identitySchema = z.object({ team_id: z.string().min(1), user_id: z.string().min(1) });
|
|
6
7
|
|
|
7
|
-
export const fetchSlackIdentity =
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
export const fetchSlackIdentity = makeApiOperation({
|
|
9
|
+
key: 'auth.test',
|
|
10
|
+
idempotent: true,
|
|
11
|
+
response: 'json',
|
|
12
|
+
input: z.strictObject({}),
|
|
13
|
+
toRequest: () => ({ path: 'auth.test', headers: acceptJsonHeaders }),
|
|
14
|
+
parse: ({ body }) => {
|
|
15
|
+
const identity = identitySchema.parse(readSlackBody(body));
|
|
16
|
+
return { teamId: identity.team_id, userId: identity.user_id };
|
|
17
|
+
},
|
|
18
|
+
});
|
|
@@ -4,7 +4,6 @@ import type { ProviderModel } from '../../../../catalog/providerModel';
|
|
|
4
4
|
|
|
5
5
|
export const slackAccount = {
|
|
6
6
|
kind: accountResourceKind,
|
|
7
|
-
operations: [],
|
|
8
7
|
events: declaredOperations(
|
|
9
8
|
{ 'events.message.im': 'Receive the direct messages of this Slack account' },
|
|
10
9
|
accountResourceKind,
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { makeApiOperation } from '@inixiative/api-client/operation';
|
|
2
|
+
import { providerOperationInputSchema } from '../../../../operations/providerOperationInputSchema';
|
|
3
|
+
import { acceptJsonHeaders } from '../../../../utils/acceptJsonHeaders';
|
|
4
|
+
import { select } from '../../../../utils/select';
|
|
5
|
+
import { readSlackBody } from '../../readSlackBody';
|
|
6
|
+
import { slackChannel } from './slackChannel';
|
|
7
|
+
|
|
8
|
+
export const fetchSlackChannel = makeApiOperation({
|
|
9
|
+
key: 'conversations.read',
|
|
10
|
+
idempotent: true,
|
|
11
|
+
response: 'json',
|
|
12
|
+
meta: {
|
|
13
|
+
name: 'Read channel details',
|
|
14
|
+
resourceKind: slackChannel.kind,
|
|
15
|
+
requiredScopes: ['channels:read or groups:read'],
|
|
16
|
+
},
|
|
17
|
+
input: providerOperationInputSchema(['slack'], slackChannel.kind),
|
|
18
|
+
toRequest: ({ resource }) => ({
|
|
19
|
+
path: 'conversations.info',
|
|
20
|
+
headers: acceptJsonHeaders,
|
|
21
|
+
query: { channel: resource.externalId },
|
|
22
|
+
}),
|
|
23
|
+
parse: ({ body }) =>
|
|
24
|
+
select(readSlackBody(body).channel, [
|
|
25
|
+
'id',
|
|
26
|
+
'name',
|
|
27
|
+
'is_private',
|
|
28
|
+
'num_members',
|
|
29
|
+
'topic',
|
|
30
|
+
'purpose',
|
|
31
|
+
]),
|
|
32
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
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 { readSlackBody } from '../../readSlackBody';
|
|
7
|
+
import { slackChannel } from './slackChannel';
|
|
8
|
+
|
|
9
|
+
export const fetchSlackChannelMessages = makeApiOperation({
|
|
10
|
+
key: 'messages.read',
|
|
11
|
+
idempotent: true,
|
|
12
|
+
response: 'json',
|
|
13
|
+
meta: {
|
|
14
|
+
name: 'Read channel messages',
|
|
15
|
+
resourceKind: slackChannel.kind,
|
|
16
|
+
requiredScopes: ['channels:history or groups:history'],
|
|
17
|
+
},
|
|
18
|
+
input: providerOperationInputSchema(['slack'], slackChannel.kind),
|
|
19
|
+
toRequest: ({ resource, limit }) => ({
|
|
20
|
+
path: 'conversations.history',
|
|
21
|
+
headers: acceptJsonHeaders,
|
|
22
|
+
query: { channel: resource.externalId, limit: Math.min(limit, 15) },
|
|
23
|
+
}),
|
|
24
|
+
parse: ({ body }) => {
|
|
25
|
+
const data = readSlackBody(body);
|
|
26
|
+
return {
|
|
27
|
+
messages: z
|
|
28
|
+
.array(z.unknown())
|
|
29
|
+
.parse(data.messages)
|
|
30
|
+
.map((item) => select(item, ['ts', 'text', 'user', 'type'])),
|
|
31
|
+
hasMore: data.has_more === true,
|
|
32
|
+
};
|
|
33
|
+
},
|
|
34
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { makeApiOperation } from '@inixiative/api-client/operation';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { acceptJsonHeaders } from '../../../../utils/acceptJsonHeaders';
|
|
4
|
+
import { pageQuerySchema } from '../../../../utils/pageQuerySchema';
|
|
5
|
+
import { readSlackBody } from '../../readSlackBody';
|
|
6
|
+
import { slackPagination } from '../../slackPagination';
|
|
7
|
+
|
|
8
|
+
export const listSlackUserConversations = makeApiOperation({
|
|
9
|
+
key: 'users.conversations',
|
|
10
|
+
idempotent: true,
|
|
11
|
+
response: 'json',
|
|
12
|
+
input: z.object({ query: pageQuerySchema(slackPagination) }),
|
|
13
|
+
toRequest: ({ query }) => ({
|
|
14
|
+
path: 'users.conversations',
|
|
15
|
+
headers: acceptJsonHeaders,
|
|
16
|
+
query: { types: 'public_channel,private_channel', exclude_archived: 'true', ...query },
|
|
17
|
+
}),
|
|
18
|
+
parse: ({ body }) => readSlackBody(body),
|
|
19
|
+
});
|
|
@@ -10,20 +10,6 @@ const events = {
|
|
|
10
10
|
|
|
11
11
|
export const slackChannel = {
|
|
12
12
|
kind,
|
|
13
|
-
operations: [
|
|
14
|
-
{
|
|
15
|
-
key: 'conversations.read',
|
|
16
|
-
name: 'Read channel details',
|
|
17
|
-
resourceKind: kind,
|
|
18
|
-
requiredScopes: ['channels:read or groups:read'],
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
key: 'messages.read',
|
|
22
|
-
name: 'Read channel messages',
|
|
23
|
-
resourceKind: kind,
|
|
24
|
-
requiredScopes: ['channels:history or groups:history'],
|
|
25
|
-
},
|
|
26
|
-
],
|
|
27
13
|
events: [
|
|
28
14
|
...declaredOperations(events, kind, ['channels:history'], ['events.message.channels']),
|
|
29
15
|
...declaredOperations(events, kind, ['app_mentions:read'], ['events.app_mention']),
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { slackProviderError } from './slackProviderError';
|
|
3
|
+
|
|
4
|
+
const slackResultSchema = z.looseObject({ ok: z.boolean(), error: z.string().optional() });
|
|
5
|
+
|
|
6
|
+
export const readSlackBody = (body: unknown) => {
|
|
7
|
+
const result = slackResultSchema.parse(body);
|
|
8
|
+
if (!result.ok) throw slackProviderError(result.error);
|
|
9
|
+
return result;
|
|
10
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { ApiClient } from '@inixiative/api-client';
|
|
2
|
+
import { fetchAllApiPages } from '@inixiative/api-client/http/pagination';
|
|
3
|
+
import type { ApiOperationOptions } from '@inixiative/api-client/operation';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
import { listSlackUserConversations } from '../models/channel/listSlackUserConversations';
|
|
6
|
+
import { slackPagination } from '../slackPagination';
|
|
7
|
+
|
|
8
|
+
const channelsSchema = z.array(z.object({ id: z.string().min(1), name: z.string().min(1) }));
|
|
9
|
+
|
|
10
|
+
export const listSlackChannels = async (client: ApiClient, options?: ApiOperationOptions) => {
|
|
11
|
+
let truncated = false;
|
|
12
|
+
const channels = channelsSchema.parse(
|
|
13
|
+
await fetchAllApiPages(slackPagination, {
|
|
14
|
+
keys: { data: 'channels' },
|
|
15
|
+
fetchPage: (query) => listSlackUserConversations(client, { query }, options),
|
|
16
|
+
maxPages: 20,
|
|
17
|
+
onCapped: () => {
|
|
18
|
+
truncated = true;
|
|
19
|
+
},
|
|
20
|
+
}),
|
|
21
|
+
);
|
|
22
|
+
return { channels, truncated };
|
|
23
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const slackApiBaseUrl = 'https://slack.com/api/';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { defineApiOperations } from '@inixiative/api-client/operation';
|
|
2
|
+
import { fetchSlackChannel } from './models/channel/fetchSlackChannel';
|
|
3
|
+
import { fetchSlackChannelMessages } from './models/channel/fetchSlackChannelMessages';
|
|
4
|
+
|
|
5
|
+
export const slackOperations = defineApiOperations({
|
|
6
|
+
'conversations.read': fetchSlackChannel,
|
|
7
|
+
'messages.read': fetchSlackChannelMessages,
|
|
8
|
+
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ApiPagination } from '@inixiative/api-client/http/pagination';
|
|
2
2
|
|
|
3
3
|
export const slackPagination = {
|
|
4
4
|
strategy: 'cursor',
|
|
@@ -9,4 +9,4 @@ export const slackPagination = {
|
|
|
9
9
|
nextCursor: 'response_metadata.next_cursor',
|
|
10
10
|
},
|
|
11
11
|
pageSize: 200,
|
|
12
|
-
} satisfies
|
|
12
|
+
} satisfies ApiPagination;
|
|
@@ -1,12 +1,20 @@
|
|
|
1
|
+
import { catalogOperations } from '../../catalog/catalogOperations';
|
|
1
2
|
import type { ProviderDefinition } from '../../contracts';
|
|
2
3
|
import { slackAccount } from './models/account/slackAccount';
|
|
3
4
|
import { slackChannel } from './models/channel/slackChannel';
|
|
5
|
+
import { slackApiBaseUrl } from './slackApiBaseUrl';
|
|
6
|
+
import { slackOperations } from './slackOperations';
|
|
4
7
|
|
|
5
8
|
export const slackProvider: ProviderDefinition = {
|
|
6
9
|
key: 'slack',
|
|
7
10
|
name: 'Slack',
|
|
8
11
|
documentationUrl: 'https://docs.slack.dev/reference/methods/conversations.history/',
|
|
9
12
|
authMethods: ['bearer', 'oauth2'],
|
|
10
|
-
|
|
13
|
+
apiBaseUrl: slackApiBaseUrl,
|
|
14
|
+
operations: [
|
|
15
|
+
...catalogOperations(slackOperations),
|
|
16
|
+
...slackChannel.events,
|
|
17
|
+
...slackAccount.events,
|
|
18
|
+
],
|
|
11
19
|
syncedResourceKinds: [slackChannel.kind],
|
|
12
20
|
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ApiError } from '@inixiative/api-client';
|
|
2
2
|
|
|
3
3
|
const authenticationErrors = ['invalid_auth', 'token_expired', 'token_revoked', 'not_authed'];
|
|
4
4
|
|
|
5
5
|
export const slackProviderError = (error: unknown) =>
|
|
6
|
-
new
|
|
6
|
+
new ApiError(
|
|
7
7
|
authenticationErrors.includes(String(error))
|
|
8
8
|
? 'provider_authentication_expired'
|
|
9
9
|
: error === 'ratelimited'
|
|
@@ -0,0 +1,36 @@
|
|
|
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 { objectSchema } from '../../../../utils/objectSchema';
|
|
6
|
+
import { select } from '../../../../utils/select';
|
|
7
|
+
|
|
8
|
+
const kind = 'channel';
|
|
9
|
+
|
|
10
|
+
export const fetchTeamsChannelMessages = makeApiOperation({
|
|
11
|
+
key: 'messages.read',
|
|
12
|
+
idempotent: true,
|
|
13
|
+
response: 'json',
|
|
14
|
+
meta: {
|
|
15
|
+
name: 'Read channel messages',
|
|
16
|
+
resourceKind: kind,
|
|
17
|
+
requiredScopes: ['ChannelMessage.Read.All or ChannelMessage.Read.Group'],
|
|
18
|
+
},
|
|
19
|
+
input: providerOperationInputSchema(['teams'], kind),
|
|
20
|
+
toRequest: ({ resource, limit }) => ({
|
|
21
|
+
path: 'teams/:teamId/channels/:channelId/messages',
|
|
22
|
+
headers: acceptJsonHeaders,
|
|
23
|
+
params: { teamId: resource.metadata.teamId, channelId: resource.externalId },
|
|
24
|
+
query: { $top: limit },
|
|
25
|
+
}),
|
|
26
|
+
parse: ({ body }) => {
|
|
27
|
+
const data = objectSchema.parse(body);
|
|
28
|
+
return {
|
|
29
|
+
messages: z
|
|
30
|
+
.array(z.unknown())
|
|
31
|
+
.parse(data.value)
|
|
32
|
+
.map((item) => select(item, ['id', 'subject', 'body', 'createdDateTime'])),
|
|
33
|
+
hasMore: typeof data['@odata.nextLink'] === 'string',
|
|
34
|
+
};
|
|
35
|
+
},
|
|
36
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const teamsApiBaseUrl = 'https://graph.microsoft.com/v1.0/';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { defineApiOperations } from '@inixiative/api-client/operation';
|
|
2
|
+
import { fetchTeamsChannelMessages } from './models/channel/fetchTeamsChannelMessages';
|
|
3
|
+
|
|
4
|
+
export const teamsOperations = defineApiOperations({
|
|
5
|
+
'messages.read': fetchTeamsChannelMessages,
|
|
6
|
+
});
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
import { catalogOperations } from '../../catalog/catalogOperations';
|
|
1
2
|
import type { ProviderDefinition } from '../../contracts';
|
|
3
|
+
import { teamsApiBaseUrl } from './teamsApiBaseUrl';
|
|
4
|
+
import { teamsOperations } from './teamsOperations';
|
|
2
5
|
|
|
3
6
|
export const teamsProvider: ProviderDefinition = {
|
|
4
7
|
key: 'teams',
|
|
@@ -6,12 +9,6 @@ export const teamsProvider: ProviderDefinition = {
|
|
|
6
9
|
documentationUrl:
|
|
7
10
|
'https://learn.microsoft.com/en-us/graph/api/channel-list-messages?view=graph-rest-1.0',
|
|
8
11
|
authMethods: ['bearer', 'oauth2'],
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
key: 'messages.read',
|
|
12
|
-
name: 'Read channel messages',
|
|
13
|
-
resourceKind: 'channel',
|
|
14
|
-
requiredScopes: ['ChannelMessage.Read.All or ChannelMessage.Read.Group'],
|
|
15
|
-
},
|
|
16
|
-
],
|
|
12
|
+
apiBaseUrl: teamsApiBaseUrl,
|
|
13
|
+
operations: catalogOperations(teamsOperations),
|
|
17
14
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const acceptJsonHeaders = { Accept: 'application/json' };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ApiPagination } from '@inixiative/api-client/http/pagination';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
export const pageQuerySchema = (pagination: ApiPagination) => {
|
|
5
|
+
const keys: string[] =
|
|
6
|
+
pagination.strategy === 'page'
|
|
7
|
+
? [pagination.keys.page, pagination.keys.pageSize]
|
|
8
|
+
: [pagination.keys.cursor, pagination.keys.pageSize];
|
|
9
|
+
return z
|
|
10
|
+
.record(z.string(), z.union([z.string(), z.number()]))
|
|
11
|
+
.refine((query) => Object.keys(query).every((key) => keys.includes(key)))
|
|
12
|
+
.optional();
|
|
13
|
+
};
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
+
import { headerNumber, readRateLimit } from '@inixiative/api-client/http';
|
|
1
2
|
import type { InferenceProtocol } from '../contracts';
|
|
2
|
-
import { headerNumber } from './headerNumber';
|
|
3
3
|
import type { ProviderReading } from './providerReading';
|
|
4
4
|
import { providerReadingSchema } from './providerReadingSchema';
|
|
5
|
-
import { readRateLimit } from './readRateLimit';
|
|
6
5
|
|
|
7
6
|
const ANTHROPIC_WINDOWS = ['requests', 'tokens', 'input-tokens', 'output-tokens'] as const;
|
|
8
7
|
const OPENAI_WINDOWS = ['requests', 'tokens'] as const;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { Provider } from '../contracts';
|
|
2
|
-
import { findProvider } from './findProvider';
|
|
3
|
-
|
|
4
|
-
export const isFamilyManaged = (provider: Provider | null | undefined) => {
|
|
5
|
-
const definition = findProvider(provider);
|
|
6
|
-
return Boolean(definition?.oauth || definition?.family);
|
|
7
|
-
};
|