@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
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { ApiError } from '@inixiative/api-client';
|
|
3
|
+
import { makeApiOperation } from '@inixiative/api-client/operation';
|
|
4
|
+
import {
|
|
5
|
+
githubInputSchemas,
|
|
6
|
+
githubOperationNames,
|
|
7
|
+
githubOperationSchema,
|
|
8
|
+
gitObjectIdSchema,
|
|
9
|
+
repositoryResourceKind,
|
|
10
|
+
} from '@inixiative/signet/contracts';
|
|
11
|
+
import { z } from 'zod';
|
|
12
|
+
import { providerOperationInputSchema } from '../../../../operations/providerOperationInputSchema';
|
|
13
|
+
import { githubObjectRequest } from './githubObjectRequest';
|
|
14
|
+
import { readGithubObjectIdentity } from './readGithubObjectIdentity';
|
|
15
|
+
|
|
16
|
+
const key = githubOperationSchema.enum['blobs.read'];
|
|
17
|
+
const blobSchema = z.object({
|
|
18
|
+
sha: gitObjectIdSchema,
|
|
19
|
+
encoding: z.literal('base64'),
|
|
20
|
+
size: z
|
|
21
|
+
.number()
|
|
22
|
+
.int()
|
|
23
|
+
.min(0)
|
|
24
|
+
.max(512 * 1024),
|
|
25
|
+
content: z
|
|
26
|
+
.string()
|
|
27
|
+
.max(750000)
|
|
28
|
+
.regex(/^[A-Za-z0-9+/=\r\n]*$/),
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
export const fetchGithubBlob = makeApiOperation({
|
|
32
|
+
key,
|
|
33
|
+
idempotent: true,
|
|
34
|
+
response: 'json',
|
|
35
|
+
meta: {
|
|
36
|
+
name: githubOperationNames[key],
|
|
37
|
+
resourceKind: repositoryResourceKind,
|
|
38
|
+
requiredScopes: ['contents:read'],
|
|
39
|
+
},
|
|
40
|
+
input: providerOperationInputSchema(
|
|
41
|
+
['githubOrganization', 'githubUser'],
|
|
42
|
+
repositoryResourceKind,
|
|
43
|
+
githubInputSchemas[key],
|
|
44
|
+
),
|
|
45
|
+
toRequest: ({ resource, input }) =>
|
|
46
|
+
githubObjectRequest('blobs', resource.metadata.fullName, input.objectId),
|
|
47
|
+
parse: ({ body }, { input }) => {
|
|
48
|
+
const blob = blobSchema.parse(readGithubObjectIdentity(body, input.objectId));
|
|
49
|
+
const encoded = blob.content.replace(/[\r\n]/g, '');
|
|
50
|
+
const bytes = Buffer.from(encoded, 'base64');
|
|
51
|
+
if (
|
|
52
|
+
bytes.toString('base64') !== encoded ||
|
|
53
|
+
bytes.length !== blob.size ||
|
|
54
|
+
createHash('sha1').update(`blob ${bytes.length}\0`).update(bytes).digest('hex') !== blob.sha
|
|
55
|
+
)
|
|
56
|
+
throw new ApiError('provider_invalid_response');
|
|
57
|
+
return { sha: blob.sha, encoding: blob.encoding, size: blob.size, content: encoded };
|
|
58
|
+
},
|
|
59
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { makeApiOperation } from '@inixiative/api-client/operation';
|
|
2
|
+
import {
|
|
3
|
+
githubInputSchemas,
|
|
4
|
+
githubOperationNames,
|
|
5
|
+
githubOperationSchema,
|
|
6
|
+
gitObjectIdSchema,
|
|
7
|
+
repositoryResourceKind,
|
|
8
|
+
} from '@inixiative/signet/contracts';
|
|
9
|
+
import { z } from 'zod';
|
|
10
|
+
import { providerOperationInputSchema } from '../../../../operations/providerOperationInputSchema';
|
|
11
|
+
import { githubObjectRequest } from './githubObjectRequest';
|
|
12
|
+
import { readGithubObjectIdentity } from './readGithubObjectIdentity';
|
|
13
|
+
|
|
14
|
+
const key = githubOperationSchema.enum['commits.read'];
|
|
15
|
+
const commitSchema = z.object({
|
|
16
|
+
sha: gitObjectIdSchema,
|
|
17
|
+
tree: z.object({ sha: gitObjectIdSchema }),
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
export const fetchGithubCommit = makeApiOperation({
|
|
21
|
+
key,
|
|
22
|
+
idempotent: true,
|
|
23
|
+
response: 'json',
|
|
24
|
+
meta: {
|
|
25
|
+
name: githubOperationNames[key],
|
|
26
|
+
resourceKind: repositoryResourceKind,
|
|
27
|
+
requiredScopes: ['contents:read'],
|
|
28
|
+
},
|
|
29
|
+
input: providerOperationInputSchema(
|
|
30
|
+
['githubOrganization', 'githubUser'],
|
|
31
|
+
repositoryResourceKind,
|
|
32
|
+
githubInputSchemas[key],
|
|
33
|
+
),
|
|
34
|
+
toRequest: ({ resource, input }) =>
|
|
35
|
+
githubObjectRequest('commits', resource.metadata.fullName, input.objectId),
|
|
36
|
+
parse: ({ body }, { input }) =>
|
|
37
|
+
commitSchema.parse(readGithubObjectIdentity(body, input.objectId)),
|
|
38
|
+
});
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { ApiError } from '@inixiative/api-client';
|
|
2
|
+
import { makeApiOperation } from '@inixiative/api-client/operation';
|
|
3
|
+
import {
|
|
4
|
+
githubInputSchemas,
|
|
5
|
+
githubOperationNames,
|
|
6
|
+
githubOperationSchema,
|
|
7
|
+
gitObjectIdSchema,
|
|
8
|
+
repositoryResourceKind,
|
|
9
|
+
} from '@inixiative/signet/contracts';
|
|
10
|
+
import { z } from 'zod';
|
|
11
|
+
import { providerOperationInputSchema } from '../../../../operations/providerOperationInputSchema';
|
|
12
|
+
import { githubObjectRequest } from './githubObjectRequest';
|
|
13
|
+
import { githubTreeEntryModeSchema } from './githubTreeEntryModeSchema';
|
|
14
|
+
import { githubTreeEntryTypeForMode } from './githubTreeEntryTypeForMode';
|
|
15
|
+
import { githubTreeEntryTypeSchema } from './githubTreeEntryTypeSchema';
|
|
16
|
+
import { readGithubObjectIdentity } from './readGithubObjectIdentity';
|
|
17
|
+
|
|
18
|
+
const key = githubOperationSchema.enum['trees.read'];
|
|
19
|
+
|
|
20
|
+
const isEntryName = (path: string) =>
|
|
21
|
+
path !== '.' &&
|
|
22
|
+
path !== '..' &&
|
|
23
|
+
[...path].every(
|
|
24
|
+
(character) =>
|
|
25
|
+
character.charCodeAt(0) >= 32 &&
|
|
26
|
+
character.charCodeAt(0) !== 127 &&
|
|
27
|
+
character !== '/' &&
|
|
28
|
+
character !== String.fromCharCode(92),
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
const entrySchema = z
|
|
32
|
+
.object({
|
|
33
|
+
path: z.string().min(1).max(255).refine(isEntryName),
|
|
34
|
+
mode: githubTreeEntryModeSchema,
|
|
35
|
+
type: githubTreeEntryTypeSchema,
|
|
36
|
+
sha: gitObjectIdSchema,
|
|
37
|
+
size: z
|
|
38
|
+
.number()
|
|
39
|
+
.int()
|
|
40
|
+
.min(0)
|
|
41
|
+
.max(512 * 1024)
|
|
42
|
+
.optional(),
|
|
43
|
+
})
|
|
44
|
+
.refine((entry) => githubTreeEntryTypeForMode[entry.mode] === entry.type);
|
|
45
|
+
|
|
46
|
+
export const fetchGithubTree = makeApiOperation({
|
|
47
|
+
key,
|
|
48
|
+
idempotent: true,
|
|
49
|
+
response: 'json',
|
|
50
|
+
meta: {
|
|
51
|
+
name: githubOperationNames[key],
|
|
52
|
+
resourceKind: repositoryResourceKind,
|
|
53
|
+
requiredScopes: ['contents:read'],
|
|
54
|
+
},
|
|
55
|
+
input: providerOperationInputSchema(
|
|
56
|
+
['githubOrganization', 'githubUser'],
|
|
57
|
+
repositoryResourceKind,
|
|
58
|
+
githubInputSchemas[key],
|
|
59
|
+
),
|
|
60
|
+
toRequest: ({ resource, input }) =>
|
|
61
|
+
githubObjectRequest('trees', resource.metadata.fullName, input.objectId),
|
|
62
|
+
parse: ({ body }, { input, limit }) => {
|
|
63
|
+
const tree = z
|
|
64
|
+
.object({
|
|
65
|
+
sha: gitObjectIdSchema,
|
|
66
|
+
truncated: z.literal(false),
|
|
67
|
+
tree: z.array(entrySchema).max(limit),
|
|
68
|
+
})
|
|
69
|
+
.parse(readGithubObjectIdentity(body, input.objectId));
|
|
70
|
+
if (new Set(tree.tree.map((entry) => entry.path)).size !== tree.tree.length)
|
|
71
|
+
throw new ApiError('provider_invalid_response');
|
|
72
|
+
return tree;
|
|
73
|
+
},
|
|
74
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ApiRequestInput } from '@inixiative/api-client/http';
|
|
2
|
+
import { githubRequestHeaders } from '../../githubRequestHeaders';
|
|
3
|
+
|
|
4
|
+
export const githubObjectRequest = (
|
|
5
|
+
objectKind: 'commits' | 'trees' | 'blobs',
|
|
6
|
+
fullName: string,
|
|
7
|
+
objectId: string,
|
|
8
|
+
): ApiRequestInput => {
|
|
9
|
+
const [owner = '', repository = ''] = fullName.split('/');
|
|
10
|
+
return {
|
|
11
|
+
path: `repos/:owner/:repository/git/${objectKind}/:objectId`,
|
|
12
|
+
params: { owner, repository, objectId },
|
|
13
|
+
headers: githubRequestHeaders,
|
|
14
|
+
};
|
|
15
|
+
};
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
githubOperationNames,
|
|
3
|
-
githubOperationSchema,
|
|
4
|
-
repositoryResourceKind,
|
|
5
|
-
} from '@inixiative/signet/contracts';
|
|
1
|
+
import { repositoryResourceKind } from '@inixiative/signet/contracts';
|
|
6
2
|
import { declaredOperations } from '../../../../catalog/declaredOperations';
|
|
7
3
|
import type { ProviderModel } from '../../../../catalog/providerModel';
|
|
8
4
|
import { githubEventRepositoryId } from '../../events/githubEventRepositoryId';
|
|
@@ -13,12 +9,6 @@ export const githubRepository = {
|
|
|
13
9
|
kind: repositoryResourceKind,
|
|
14
10
|
externalIdSchema: githubRepositoryIdSchema,
|
|
15
11
|
metadataSchema: githubRepositoryMetadataSchema,
|
|
16
|
-
operations: declaredOperations(
|
|
17
|
-
githubOperationNames,
|
|
18
|
-
repositoryResourceKind,
|
|
19
|
-
['contents:read'],
|
|
20
|
-
githubOperationSchema.options,
|
|
21
|
-
),
|
|
22
12
|
events: declaredOperations(
|
|
23
13
|
{
|
|
24
14
|
'events.pull_request.opened': 'Receive pull requests opened in this repository',
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { defineApiOperations } from '@inixiative/api-client/operation';
|
|
2
|
+
import { fetchGithubBlob } from './fetchGithubBlob';
|
|
3
|
+
import { fetchGithubCommit } from './fetchGithubCommit';
|
|
4
|
+
import { fetchGithubTree } from './fetchGithubTree';
|
|
5
|
+
|
|
6
|
+
export const githubRepositoryOperations = defineApiOperations({
|
|
7
|
+
'commits.read': fetchGithubCommit,
|
|
8
|
+
'trees.read': fetchGithubTree,
|
|
9
|
+
'blobs.read': fetchGithubBlob,
|
|
10
|
+
});
|
|
@@ -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 listGithubInstallationRepositoryPage = makeApiOperation({
|
|
8
|
+
key: 'installation.repositories.list',
|
|
9
|
+
idempotent: true,
|
|
10
|
+
response: 'json',
|
|
11
|
+
input: z.object({ query: pageQuerySchema(githubPagination) }),
|
|
12
|
+
toRequest: ({ query }) => ({
|
|
13
|
+
path: 'installation/repositories',
|
|
14
|
+
query: query,
|
|
15
|
+
headers: githubRequestHeaders,
|
|
16
|
+
}),
|
|
17
|
+
parse: ({ body }) => body,
|
|
18
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
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 listGithubUserInstallationRepositoryPage = makeApiOperation({
|
|
8
|
+
key: 'user.installations.repositories.list',
|
|
9
|
+
idempotent: true,
|
|
10
|
+
response: 'json',
|
|
11
|
+
input: z.object({
|
|
12
|
+
installationId: z.number().int().positive(),
|
|
13
|
+
query: pageQuerySchema(githubPagination),
|
|
14
|
+
}),
|
|
15
|
+
toRequest: ({ installationId, query }) => ({
|
|
16
|
+
path: 'user/installations/:installationId/repositories',
|
|
17
|
+
params: { installationId: String(installationId) },
|
|
18
|
+
query: query,
|
|
19
|
+
headers: githubRequestHeaders,
|
|
20
|
+
}),
|
|
21
|
+
parse: ({ body }) => body,
|
|
22
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ApiError } from '@inixiative/api-client';
|
|
2
|
+
import { gitObjectIdSchema } from '@inixiative/signet/contracts';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
|
|
5
|
+
export const readGithubObjectIdentity = (data: unknown, objectId: string) => {
|
|
6
|
+
const identity = z.object({ sha: gitObjectIdSchema }).parse(data);
|
|
7
|
+
if (identity.sha !== objectId) throw new ApiError('provider_invalid_response');
|
|
8
|
+
return data;
|
|
9
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { ApiClient } from '@inixiative/api-client';
|
|
2
|
+
import { iterateApiPages } from '@inixiative/api-client/http/pagination';
|
|
3
|
+
import type { ApiOperationOptions } from '@inixiative/api-client/operation';
|
|
4
|
+
import { githubInstallationSchema } from '../auth/githubInstallationSchema';
|
|
5
|
+
import { listGithubUserInstallationPage } from '../auth/listGithubUserInstallationPage';
|
|
6
|
+
import { githubPagination } from '../githubPagination';
|
|
7
|
+
|
|
8
|
+
export const fetchGithubUserInstallation = async (
|
|
9
|
+
client: ApiClient,
|
|
10
|
+
{ installationId }: { installationId: string },
|
|
11
|
+
options?: ApiOperationOptions,
|
|
12
|
+
) => {
|
|
13
|
+
const pages = iterateApiPages(githubPagination, {
|
|
14
|
+
keys: { data: 'installations' },
|
|
15
|
+
maxPages: 10,
|
|
16
|
+
fetchPage: (query) => listGithubUserInstallationPage(client, { query }, options),
|
|
17
|
+
});
|
|
18
|
+
for await (const { items } of pages)
|
|
19
|
+
for (const candidate of items) {
|
|
20
|
+
const installation = githubInstallationSchema.safeParse(candidate);
|
|
21
|
+
if (installation.success && String(installation.data.id) === installationId)
|
|
22
|
+
return installation.data;
|
|
23
|
+
}
|
|
24
|
+
return null;
|
|
25
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
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 { githubNotificationSchema } from '../events/githubNotificationSchema';
|
|
6
|
+
import { listGithubNotificationPage } from '../events/listGithubNotificationPage';
|
|
7
|
+
import { githubPagination } from '../githubPagination';
|
|
8
|
+
|
|
9
|
+
export const listGithubNotifications = async (
|
|
10
|
+
client: ApiClient,
|
|
11
|
+
{ since }: { since: Date },
|
|
12
|
+
options?: ApiOperationOptions,
|
|
13
|
+
) => {
|
|
14
|
+
let truncated = false;
|
|
15
|
+
const notifications = z.array(githubNotificationSchema).parse(
|
|
16
|
+
await fetchAllApiPages(githubPagination, {
|
|
17
|
+
pageSize: 50,
|
|
18
|
+
fetchPage: (query) =>
|
|
19
|
+
listGithubNotificationPage(client, { since: since.toISOString(), query }, options),
|
|
20
|
+
maxPages: 10,
|
|
21
|
+
onCapped: () => {
|
|
22
|
+
truncated = true;
|
|
23
|
+
},
|
|
24
|
+
}),
|
|
25
|
+
);
|
|
26
|
+
return { notifications, truncated };
|
|
27
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
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 { providerResourceLimit } from '../../../contracts';
|
|
7
|
+
import { githubPagination } from '../githubPagination';
|
|
8
|
+
import { githubRepositoryName } from '../models/repository/githubRepositoryName';
|
|
9
|
+
import { listGithubInstallationRepositoryPage } from '../models/repository/listGithubInstallationRepositoryPage';
|
|
10
|
+
|
|
11
|
+
const totalSchema = z.object({ total_count: z.number().int().min(0) });
|
|
12
|
+
const repositoriesSchema = z.array(
|
|
13
|
+
z.object({ id: z.number().int().positive(), full_name: z.string() }),
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
export const listInstallationRepositories = async (
|
|
17
|
+
client: ApiClient,
|
|
18
|
+
options?: ApiOperationOptions,
|
|
19
|
+
) => {
|
|
20
|
+
const repositories = repositoriesSchema.parse(
|
|
21
|
+
await fetchAllApiPages(githubPagination, {
|
|
22
|
+
keys: { data: 'repositories' },
|
|
23
|
+
fetchPage: (query) => listGithubInstallationRepositoryPage(client, { query }, options),
|
|
24
|
+
onResponse: (response) => {
|
|
25
|
+
if (totalSchema.parse(response).total_count > providerResourceLimit)
|
|
26
|
+
throw new ApiError('too_many_repositories', 409);
|
|
27
|
+
},
|
|
28
|
+
}),
|
|
29
|
+
);
|
|
30
|
+
const listed = new Map(
|
|
31
|
+
repositories.map(({ id, full_name }) => [String(id), githubRepositoryName(full_name)]),
|
|
32
|
+
);
|
|
33
|
+
return [...listed].map(([id, fullName]) => ({ id, fullName }));
|
|
34
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
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 { providerResourceLimit } from '../../../contracts';
|
|
7
|
+
import { listGithubUserInstallationPage } from '../auth/listGithubUserInstallationPage';
|
|
8
|
+
import { githubPagination } from '../githubPagination';
|
|
9
|
+
import { githubRepositoryName } from '../models/repository/githubRepositoryName';
|
|
10
|
+
import { listGithubUserInstallationRepositoryPage } from '../models/repository/listGithubUserInstallationRepositoryPage';
|
|
11
|
+
|
|
12
|
+
const installationsSchema = z.array(z.object({ id: z.number().int().positive() }));
|
|
13
|
+
const repositoriesSchema = z.array(
|
|
14
|
+
z.object({ id: z.number().int().positive(), full_name: z.string() }),
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
// why: a GitHub App user token reaches only repositories in the App's installations the user sees.
|
|
18
|
+
export const listUserRepositories = async (client: ApiClient, options?: ApiOperationOptions) => {
|
|
19
|
+
const installations = installationsSchema.parse(
|
|
20
|
+
await fetchAllApiPages(githubPagination, {
|
|
21
|
+
keys: { data: 'installations' },
|
|
22
|
+
fetchPage: (query) => listGithubUserInstallationPage(client, { query }, options),
|
|
23
|
+
}),
|
|
24
|
+
);
|
|
25
|
+
const listed = new Map<string, string>();
|
|
26
|
+
for (const installation of installations) {
|
|
27
|
+
const repositories = repositoriesSchema.parse(
|
|
28
|
+
await fetchAllApiPages(githubPagination, {
|
|
29
|
+
keys: { data: 'repositories' },
|
|
30
|
+
fetchPage: (query) =>
|
|
31
|
+
listGithubUserInstallationRepositoryPage(
|
|
32
|
+
client,
|
|
33
|
+
{ installationId: installation.id, query },
|
|
34
|
+
options,
|
|
35
|
+
),
|
|
36
|
+
}),
|
|
37
|
+
);
|
|
38
|
+
for (const repository of repositories)
|
|
39
|
+
listed.set(String(repository.id), githubRepositoryName(repository.full_name));
|
|
40
|
+
if (listed.size > providerResourceLimit) throw new ApiError('too_many_repositories', 409);
|
|
41
|
+
}
|
|
42
|
+
return [...listed].map(([id, fullName]) => ({ id, fullName }));
|
|
43
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const gmailApiBaseUrl = 'https://gmail.googleapis.com/';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { defineApiOperations } from '@inixiative/api-client/operation';
|
|
2
|
+
import { listGmailLabelMessages } from './models/label/listGmailLabelMessages';
|
|
3
|
+
import { fetchGmailMessage } from './models/message/fetchGmailMessage';
|
|
4
|
+
import { fetchGmailMessageBatch } from './models/message/fetchGmailMessageBatch';
|
|
5
|
+
|
|
6
|
+
export const gmailOperations = defineApiOperations({
|
|
7
|
+
'messages.list': listGmailLabelMessages,
|
|
8
|
+
'messages.read': fetchGmailMessage,
|
|
9
|
+
'messages.readBatch': fetchGmailMessageBatch,
|
|
10
|
+
});
|
|
@@ -1,19 +1,16 @@
|
|
|
1
|
+
import { catalogOperations } from '../../catalog/catalogOperations';
|
|
1
2
|
import type { ProviderDefinition } from '../../contracts';
|
|
3
|
+
import { gmailApiBaseUrl } from './gmailApiBaseUrl';
|
|
4
|
+
import { gmailOperations } from './gmailOperations';
|
|
2
5
|
|
|
3
6
|
export const gmailProvider: ProviderDefinition = {
|
|
4
7
|
key: 'gmail',
|
|
5
8
|
name: 'Gmail',
|
|
6
9
|
documentationUrl:
|
|
7
|
-
'https://developers.google.com/workspace/gmail/api/reference/rest/v1/users.messages
|
|
10
|
+
'https://developers.google.com/workspace/gmail/api/reference/rest/v1/users.messages',
|
|
8
11
|
authMethods: ['integrationFamily'],
|
|
9
12
|
integrationFamily: 'google',
|
|
10
13
|
oauthScopes: ['https://www.googleapis.com/auth/gmail.readonly'],
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
key: 'messages.read',
|
|
14
|
-
name: 'Read the newest messages in a label',
|
|
15
|
-
resourceKind: 'label',
|
|
16
|
-
requiredScopes: ['https://www.googleapis.com/auth/gmail.readonly'],
|
|
17
|
-
},
|
|
18
|
-
],
|
|
14
|
+
apiBaseUrl: gmailApiBaseUrl,
|
|
15
|
+
operations: catalogOperations(gmailOperations),
|
|
19
16
|
};
|
|
@@ -0,0 +1,45 @@
|
|
|
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
|
+
|
|
6
|
+
const kind = 'label';
|
|
7
|
+
const listSchema = z.object({
|
|
8
|
+
messages: z
|
|
9
|
+
.array(z.object({ id: z.string().regex(/^[A-Za-z0-9_-]{1,64}$/), threadId: z.string() }))
|
|
10
|
+
.default([]),
|
|
11
|
+
nextPageToken: z.string().optional(),
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
export const listGmailLabelMessages = makeApiOperation({
|
|
15
|
+
key: 'messages.list',
|
|
16
|
+
idempotent: true,
|
|
17
|
+
response: 'json',
|
|
18
|
+
meta: {
|
|
19
|
+
name: 'List the newest messages in a label',
|
|
20
|
+
resourceKind: kind,
|
|
21
|
+
requiredScopes: ['https://www.googleapis.com/auth/gmail.readonly'],
|
|
22
|
+
},
|
|
23
|
+
input: providerOperationInputSchema(
|
|
24
|
+
['gmail'],
|
|
25
|
+
kind,
|
|
26
|
+
z.object({ pageToken: z.string().min(1).max(512).optional() }),
|
|
27
|
+
),
|
|
28
|
+
toRequest: ({ resource, limit, input }) => ({
|
|
29
|
+
path: 'gmail/v1/users/me/messages',
|
|
30
|
+
headers: acceptJsonHeaders,
|
|
31
|
+
query: {
|
|
32
|
+
labelIds: resource.externalId,
|
|
33
|
+
maxResults: limit,
|
|
34
|
+
...(input.pageToken ? { pageToken: input.pageToken } : {}),
|
|
35
|
+
},
|
|
36
|
+
}),
|
|
37
|
+
parse: ({ body }) => {
|
|
38
|
+
const list = listSchema.parse(body);
|
|
39
|
+
return {
|
|
40
|
+
messages: list.messages.map(({ id, threadId }) => ({ id, threadId })),
|
|
41
|
+
hasMore: Boolean(list.nextPageToken),
|
|
42
|
+
nextPageToken: list.nextPageToken ?? null,
|
|
43
|
+
};
|
|
44
|
+
},
|
|
45
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { makeApiOperation } from '@inixiative/api-client/operation';
|
|
2
|
+
import { providerOperationInputSchema } from '../../../../operations/providerOperationInputSchema';
|
|
3
|
+
import { gmailMessageKind } from './gmailMessageKind';
|
|
4
|
+
import { gmailMessageRequest } from './gmailMessageRequest';
|
|
5
|
+
import { readGmailMessage } from './readGmailMessage';
|
|
6
|
+
|
|
7
|
+
export const fetchGmailMessage = makeApiOperation({
|
|
8
|
+
key: 'messages.read',
|
|
9
|
+
idempotent: true,
|
|
10
|
+
response: 'json',
|
|
11
|
+
meta: {
|
|
12
|
+
name: 'Read a message',
|
|
13
|
+
resourceKind: gmailMessageKind,
|
|
14
|
+
requiredScopes: ['https://www.googleapis.com/auth/gmail.readonly'],
|
|
15
|
+
},
|
|
16
|
+
input: providerOperationInputSchema(['gmail'], gmailMessageKind),
|
|
17
|
+
toRequest: ({ resource }) => gmailMessageRequest(resource.externalId),
|
|
18
|
+
parse: ({ body }) => readGmailMessage(body),
|
|
19
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { makeApiBatchOperation } from '@inixiative/api-client/operation';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { providerOperationInputSchema } from '../../../../operations/providerOperationInputSchema';
|
|
4
|
+
import { gmailMessageKind } from './gmailMessageKind';
|
|
5
|
+
import { gmailMessageRequest } from './gmailMessageRequest';
|
|
6
|
+
import { readGmailMessage } from './readGmailMessage';
|
|
7
|
+
|
|
8
|
+
export const fetchGmailMessageBatch = makeApiBatchOperation({
|
|
9
|
+
key: 'messages.readBatch',
|
|
10
|
+
idempotent: true,
|
|
11
|
+
meta: {
|
|
12
|
+
name: 'Read several messages in one batch',
|
|
13
|
+
resourceKind: gmailMessageKind,
|
|
14
|
+
requiredScopes: ['https://www.googleapis.com/auth/gmail.readonly'],
|
|
15
|
+
},
|
|
16
|
+
input: z.array(providerOperationInputSchema(['gmail'], gmailMessageKind)),
|
|
17
|
+
batch: { over: 'multipart', path: 'batch/gmail/v1', maxItems: 100 },
|
|
18
|
+
toItemRequest: ({ resource }) => gmailMessageRequest(resource.externalId),
|
|
19
|
+
parseItem: ({ body }) => readGmailMessage(body),
|
|
20
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const gmailMessageKind = 'message';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ApiRequestInput } from '@inixiative/api-client/http';
|
|
2
|
+
import { acceptJsonHeaders } from '../../../../utils/acceptJsonHeaders';
|
|
3
|
+
|
|
4
|
+
export const gmailMessageRequest = (messageId: string): ApiRequestInput => ({
|
|
5
|
+
path: 'gmail/v1/users/me/messages/:messageId',
|
|
6
|
+
headers: acceptJsonHeaders,
|
|
7
|
+
params: { messageId },
|
|
8
|
+
query: { format: 'metadata', metadataHeaders: ['From', 'To', 'Subject', 'Date'] },
|
|
9
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
const messageSchema = z.object({
|
|
4
|
+
id: z.string(),
|
|
5
|
+
threadId: z.string(),
|
|
6
|
+
snippet: z.string().default(''),
|
|
7
|
+
payload: z
|
|
8
|
+
.object({ headers: z.array(z.object({ name: z.string(), value: z.string() })).default([]) })
|
|
9
|
+
.default({ headers: [] }),
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
export const readGmailMessage = (value: unknown) => {
|
|
13
|
+
const message = messageSchema.parse(value);
|
|
14
|
+
const header = (name: string) =>
|
|
15
|
+
message.payload.headers.find((item) => item.name.toLowerCase() === name.toLowerCase())?.value ??
|
|
16
|
+
null;
|
|
17
|
+
return {
|
|
18
|
+
id: message.id,
|
|
19
|
+
threadId: message.threadId,
|
|
20
|
+
from: header('From'),
|
|
21
|
+
to: header('To'),
|
|
22
|
+
subject: header('Subject'),
|
|
23
|
+
date: header('Date'),
|
|
24
|
+
snippet: message.snippet,
|
|
25
|
+
};
|
|
26
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { ApiError } from '@inixiative/api-client';
|
|
1
2
|
import { decodeJwt } from 'jose';
|
|
2
3
|
import { z } from 'zod';
|
|
3
|
-
import { ProviderError } from '../../../utils/providerError';
|
|
4
4
|
|
|
5
5
|
const claimsSchema = z.object({
|
|
6
6
|
iss: z.enum(['accounts.google.com', 'https://accounts.google.com']),
|
|
@@ -15,8 +15,8 @@ export const verifyGoogleIdToken = (idToken: string, clientId: string) => {
|
|
|
15
15
|
try {
|
|
16
16
|
claims = claimsSchema.parse(decodeJwt(idToken));
|
|
17
17
|
} catch {
|
|
18
|
-
throw new
|
|
18
|
+
throw new ApiError('id_token_invalid', 502);
|
|
19
19
|
}
|
|
20
|
-
if (claims.aud !== clientId) throw new
|
|
20
|
+
if (claims.aud !== clientId) throw new ApiError('id_token_invalid', 502);
|
|
21
21
|
return { sub: claims.sub, email: claims.email };
|
|
22
22
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const jiraApiBaseUrl = 'https://api.atlassian.com/ex/jira/';
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
import { catalogOperations } from '../../catalog/catalogOperations';
|
|
1
2
|
import type { ProviderDefinition } from '../../contracts';
|
|
3
|
+
import { jiraApiBaseUrl } from './jiraApiBaseUrl';
|
|
4
|
+
import { jiraOperations } from './jiraOperations';
|
|
2
5
|
|
|
3
6
|
export const jiraProvider: ProviderDefinition = {
|
|
4
7
|
key: 'jira',
|
|
@@ -6,12 +9,6 @@ export const jiraProvider: ProviderDefinition = {
|
|
|
6
9
|
documentationUrl: 'https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issues/',
|
|
7
10
|
authMethods: ['bearer', 'oauth2'],
|
|
8
11
|
integrationFamily: 'atlassian',
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
key: 'issues.read',
|
|
12
|
-
name: 'Read an issue',
|
|
13
|
-
resourceKind: 'issue',
|
|
14
|
-
requiredScopes: ['read:jira-work'],
|
|
15
|
-
},
|
|
16
|
-
],
|
|
12
|
+
apiBaseUrl: jiraApiBaseUrl,
|
|
13
|
+
operations: catalogOperations(jiraOperations),
|
|
17
14
|
};
|
|
@@ -0,0 +1,22 @@
|
|
|
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 = 'issue';
|
|
8
|
+
|
|
9
|
+
export const fetchJiraIssue = makeApiOperation({
|
|
10
|
+
key: 'issues.read',
|
|
11
|
+
idempotent: true,
|
|
12
|
+
response: 'json',
|
|
13
|
+
meta: { name: 'Read an issue', resourceKind: kind, requiredScopes: ['read:jira-work'] },
|
|
14
|
+
input: providerOperationInputSchema(['jira'], kind),
|
|
15
|
+
toRequest: ({ resource, configuration }) => ({
|
|
16
|
+
path: ':cloudId/rest/api/3/issue/:issueId',
|
|
17
|
+
headers: acceptJsonHeaders,
|
|
18
|
+
params: { cloudId: configuration.cloudId, issueId: resource.externalId },
|
|
19
|
+
query: { fields: 'summary,description,status' },
|
|
20
|
+
}),
|
|
21
|
+
parse: ({ body }) => select(objectSchema.parse(body), ['id', 'key', 'fields']),
|
|
22
|
+
});
|