@inixiative/integrations 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +50 -2
- package/package.json +56 -4
- package/src/archiveCandidate.ts +1 -0
- package/src/archiveConfigurationSchema.ts +3 -0
- package/src/buildProviderRequest.ts +54 -0
- package/src/catalog.ts +54 -0
- package/src/codexClientId.ts +2 -0
- package/src/codexTokenUrl.ts +1 -0
- package/src/consentReason.ts +4 -0
- package/src/consentReasonSchema.ts +21 -0
- package/src/contracts.ts +107 -0
- package/src/credentialClient.ts +4 -0
- package/src/declaredOperations.ts +9 -0
- package/src/eventLeaves.ts +5 -0
- package/src/exchangeOauthCode.ts +61 -0
- package/src/executeProvider.ts +26 -0
- package/src/familyProducts.ts +5 -0
- package/src/fetchRenewalResponse.ts +41 -0
- package/src/findOperationHandler.ts +6 -0
- package/src/findProvider.ts +5 -0
- package/src/index.ts +3 -0
- package/src/integrationConfigurationSchemas.ts +11 -0
- package/src/integrationEventResource.ts +20 -0
- package/src/integrationKeyedKinds.ts +4 -0
- package/src/isAccountSuppliedByHost.ts +6 -0
- package/src/isEventLeaf.ts +1 -0
- package/src/isFamilyManaged.ts +7 -0
- package/src/isLocalArchive.ts +5 -0
- package/src/isUncalledLeaf.ts +6 -0
- package/src/localArchiveConfigurationSchema.ts +5 -0
- package/src/localArchiveSourceId.ts +8 -0
- package/src/mintProviderCredential.ts +68 -0
- package/src/operationHandler.ts +8 -0
- package/src/operationHandlers.ts +41 -0
- package/src/operationLeaves.ts +6 -0
- package/src/operationRequestInput.ts +12 -0
- package/src/perProvider.ts +20 -0
- package/src/providerEvent.ts +3 -0
- package/src/providerEventSchema.ts +3 -0
- package/src/providerExchangeTimeoutMs.ts +1 -0
- package/src/providerFamily.ts +4 -0
- package/src/providerHasEvents.ts +8 -0
- package/src/providerModel.ts +12 -0
- package/src/providerRequestSpec.ts +1 -0
- package/src/providers/anthropic/anthropicProvider.ts +16 -0
- package/src/providers/archive/archiveProvider.ts +21 -0
- package/src/providers/chorus/chorusProvider.ts +22 -0
- package/src/providers/claude/claudeProvider.ts +17 -0
- package/src/providers/codex/codexProvider.ts +17 -0
- package/src/providers/confluence/confluenceOperationHandler.ts +14 -0
- package/src/providers/confluence/confluenceProvider.ts +16 -0
- package/src/providers/discord/discordOperationHandler.ts +30 -0
- package/src/providers/discord/discordProvider.ts +22 -0
- package/src/providers/drive/driveOperationHandler.ts +21 -0
- package/src/providers/drive/driveProvider.ts +18 -0
- package/src/providers/foundry/foundryProvider.ts +33 -0
- package/src/providers/geminiApi/geminiApiProvider.ts +16 -0
- package/src/providers/github/auth/fetchGithubAppInstallation.ts +21 -0
- package/src/providers/github/auth/fetchGithubOrganizationRole.ts +27 -0
- package/src/providers/github/auth/fetchGithubUser.ts +11 -0
- package/src/providers/github/auth/fetchGithubUserInstallation.ts +21 -0
- package/src/providers/github/auth/githubAppClient.ts +4 -0
- package/src/providers/github/auth/githubAppInstallUrl.ts +20 -0
- package/src/providers/github/auth/githubAppJwt.ts +16 -0
- package/src/providers/github/auth/githubClientForApp.ts +11 -0
- package/src/providers/github/auth/githubInstallation.ts +4 -0
- package/src/providers/github/auth/githubInstallationAccountId.ts +4 -0
- package/src/providers/github/auth/githubInstallationFromAccountId.ts +4 -0
- package/src/providers/github/auth/githubInstallationSchema.ts +12 -0
- package/src/providers/github/auth/githubPermissionCovers.ts +14 -0
- package/src/providers/github/auth/githubPermissionScopes.ts +4 -0
- package/src/providers/github/auth/githubProviderForOwner.ts +6 -0
- package/src/providers/github/auth/githubUserAuthorizeUrl.ts +10 -0
- package/src/providers/github/events/githubEventRepositoryId.ts +10 -0
- package/src/providers/github/events/githubNotification.ts +4 -0
- package/src/providers/github/events/githubNotificationSchema.ts +9 -0
- package/src/providers/github/events/listGithubNotifications.ts +27 -0
- package/src/providers/github/events/normalizeGithubEvent.ts +200 -0
- package/src/providers/github/events/normalizeGithubNotification.ts +56 -0
- package/src/providers/github/events/verifyGithubSignature.ts +7 -0
- package/src/providers/github/fetchAllGithubPages.ts +12 -0
- package/src/providers/github/githubApiVersion.ts +1 -0
- package/src/providers/github/githubOrganizationProvider.ts +13 -0
- package/src/providers/github/githubPagination.ts +7 -0
- package/src/providers/github/githubProvider.ts +13 -0
- package/src/providers/github/githubRequestHeaders.ts +9 -0
- package/src/providers/github/githubUserProvider.ts +13 -0
- package/src/providers/github/iterateGithubPages.ts +12 -0
- package/src/providers/github/models/account/githubAccount.ts +17 -0
- package/src/providers/github/models/repository/githubOperationHandler.ts +36 -0
- package/src/providers/github/models/repository/githubRepository.ts +40 -0
- package/src/providers/github/models/repository/githubRepositoryIdSchema.ts +3 -0
- package/src/providers/github/models/repository/githubRepositoryMetadataSchema.ts +6 -0
- package/src/providers/github/models/repository/githubRepositoryName.ts +4 -0
- package/src/providers/github/models/repository/githubRepositoryNameSchema.ts +9 -0
- package/src/providers/github/models/repository/githubTreeEntryModeSchema.ts +3 -0
- package/src/providers/github/models/repository/githubTreeEntryTypeForMode.ts +14 -0
- package/src/providers/github/models/repository/githubTreeEntryTypeSchema.ts +3 -0
- package/src/providers/github/models/repository/listInstallationRepositories.ts +31 -0
- package/src/providers/github/models/repository/listUserRepositories.ts +36 -0
- package/src/providers/github/models/repository/readGithubObject.ts +85 -0
- package/src/providers/github/models/repository/readGithubRepositoryName.ts +4 -0
- package/src/providers/github/requestGithub.ts +18 -0
- package/src/providers/gmail/buildGmailMessageRequest.ts +22 -0
- package/src/providers/gmail/fetchGmailMessages.ts +81 -0
- package/src/providers/gmail/gmailOperationHandler.ts +12 -0
- package/src/providers/gmail/gmailProvider.ts +19 -0
- package/src/providers/google/auth/buildGoogleAuthorizationUrl.ts +33 -0
- package/src/providers/google/auth/verifyGoogleIdToken.ts +22 -0
- package/src/providers/google/googleProvider.ts +13 -0
- package/src/providers/jira/jiraOperationHandler.ts +14 -0
- package/src/providers/jira/jiraProvider.ts +16 -0
- package/src/providers/linear/auth/linearIntegrationSecret.ts +6 -0
- package/src/providers/linear/events/createLinearWebhook.ts +30 -0
- package/src/providers/linear/events/deleteLinearWebhook.ts +13 -0
- package/src/providers/linear/events/linearUserSchema.ts +3 -0
- package/src/providers/linear/events/linearWebhook.ts +3 -0
- package/src/providers/linear/events/linearWebhookPayload.ts +4 -0
- package/src/providers/linear/events/linearWebhookPayloadSchema.ts +13 -0
- package/src/providers/linear/events/listLinearWebhooks.ts +44 -0
- package/src/providers/linear/events/normalizeLinearEvent.ts +127 -0
- package/src/providers/linear/events/repairLinearWebhook.ts +17 -0
- package/src/providers/linear/events/verifyLinearSignature.ts +25 -0
- package/src/providers/linear/fetchAllLinearPages.ts +40 -0
- package/src/providers/linear/linearClient.ts +5 -0
- package/src/providers/linear/linearPagination.ts +13 -0
- package/src/providers/linear/linearProvider.ts +25 -0
- package/src/providers/linear/linearRequestInput.ts +1 -0
- package/src/providers/linear/models/issue/linearOperationHandler.ts +30 -0
- package/src/providers/linear/models/team/fetchLinearWorkspace.ts +30 -0
- package/src/providers/linear/requestLinear.ts +51 -0
- package/src/providers/muse/museProvider.ts +17 -0
- package/src/providers/notion/notionOperationHandler.ts +32 -0
- package/src/providers/notion/notionProvider.ts +22 -0
- package/src/providers/openai/openaiProvider.ts +16 -0
- package/src/providers/oracle/oracleProvider.ts +10 -0
- package/src/providers/railway/railwayProvider.ts +9 -0
- package/src/providers/render/renderProvider.ts +9 -0
- package/src/providers/slack/auth/fetchSlackIdentity.ts +10 -0
- package/src/providers/slack/events/normalizeSlackEvent.ts +64 -0
- package/src/providers/slack/events/slackAccountIdOf.ts +1 -0
- package/src/providers/slack/events/slackEventEnvelope.ts +4 -0
- package/src/providers/slack/events/slackEventEnvelopeSchema.ts +16 -0
- package/src/providers/slack/events/slackTeamPrefix.ts +1 -0
- package/src/providers/slack/events/slackTokensRevokedSchema.ts +13 -0
- package/src/providers/slack/events/slackUserOfAccountId.ts +2 -0
- package/src/providers/slack/events/verifySlackSignature.ts +17 -0
- package/src/providers/slack/fetchAllSlackPages.ts +12 -0
- package/src/providers/slack/models/channel/listSlackChannels.ts +26 -0
- package/src/providers/slack/models/channel/slackOperationHandler.ts +30 -0
- package/src/providers/slack/requestSlack.ts +22 -0
- package/src/providers/slack/slackPagination.ts +12 -0
- package/src/providers/slack/slackProvider.ts +47 -0
- package/src/providers/slack/slackProviderError.ts +12 -0
- package/src/providers/teams/teamsOperationHandler.ts +24 -0
- package/src/providers/teams/teamsProvider.ts +17 -0
- package/src/refreshProviderCredential.ts +172 -0
- package/src/renewalRequest.ts +1 -0
- package/src/resourceExternalIdSchema.ts +4 -0
- package/src/resourceExternalIdSchemas.ts +18 -0
- package/src/resourceMetadataSchema.ts +4 -0
- package/src/resourceMetadataSchemas.ts +9 -0
- package/src/subscriptionAccountId.ts +12 -0
- package/src/utils/capacityWindowSchema.ts +7 -0
- package/src/utils/headerNumber.ts +6 -0
- package/src/utils/jwtClaims.ts +14 -0
- package/src/utils/matchesHmacSha256.ts +11 -0
- package/src/utils/objectSchema.ts +3 -0
- package/src/utils/pagination/applyCaps.ts +18 -0
- package/src/utils/pagination/byCursorKeys.ts +7 -0
- package/src/utils/pagination/byCursorOptions.ts +7 -0
- package/src/utils/pagination/byPageKeys.ts +7 -0
- package/src/utils/pagination/byPageOptions.ts +8 -0
- package/src/utils/pagination/collectPages.ts +27 -0
- package/src/utils/pagination/compactRequest.ts +4 -0
- package/src/utils/pagination/fetchAllByCursor.ts +6 -0
- package/src/utils/pagination/fetchAllByPage.ts +6 -0
- package/src/utils/pagination/fetchAllRequestPages.ts +16 -0
- package/src/utils/pagination/incompletePageWalkError.ts +8 -0
- package/src/utils/pagination/isAnotherPage.ts +20 -0
- package/src/utils/pagination/iterateByCursor.ts +49 -0
- package/src/utils/pagination/iterateByPage.ts +59 -0
- package/src/utils/pagination/iterateProviderPages.ts +27 -0
- package/src/utils/pagination/iterateRequestPages.ts +18 -0
- package/src/utils/pagination/pageWalkError.ts +6 -0
- package/src/utils/pagination/paginationOptions.ts +9 -0
- package/src/utils/pagination/providerPagesOptions.ts +8 -0
- package/src/utils/pagination/providerPagination.ts +6 -0
- package/src/utils/pagination/readPage.ts +29 -0
- package/src/utils/pagination/readPath.ts +12 -0
- package/src/utils/pagination/repeatedCursorError.ts +10 -0
- package/src/utils/providerClient.ts +3 -0
- package/src/utils/providerCooldown.ts +23 -0
- package/src/utils/providerCooldownState.ts +4 -0
- package/src/utils/providerError.ts +10 -0
- package/src/utils/providerReading.ts +4 -0
- package/src/utils/providerReadingSchema.ts +8 -0
- package/src/utils/providerRequest.ts +22 -0
- package/src/utils/providerRequestInput.ts +7 -0
- package/src/utils/providerResponseLimit.ts +1 -0
- package/src/utils/providerSend.ts +1 -0
- package/src/utils/readProviderJson.ts +38 -0
- package/src/utils/readProviderLimits.ts +66 -0
- package/src/utils/readRateLimit.ts +29 -0
- package/src/utils/requestProviderJson.ts +13 -0
- package/src/utils/responseBudget.ts +1 -0
- package/src/utils/select.ts +6 -0
- package/src/utils/sendProviderRequest.ts +33 -0
- package/src/validateCredentialSecret.ts +18 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
export const githubInstallationSchema = z.object({
|
|
4
|
+
id: z.number().int().positive(),
|
|
5
|
+
app_id: z.number().int().positive(),
|
|
6
|
+
account: z.object({
|
|
7
|
+
id: z.number().int().positive(),
|
|
8
|
+
login: z.string().min(1).max(39),
|
|
9
|
+
type: z.string(),
|
|
10
|
+
}),
|
|
11
|
+
suspended_at: z.string().nullable().default(null),
|
|
12
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const levelRanks: Record<string, number> = { read: 1, write: 2, admin: 3 };
|
|
2
|
+
|
|
3
|
+
const parsePermission = (scope: string) => {
|
|
4
|
+
const [permission, level] = scope.split(':');
|
|
5
|
+
const rank = level === undefined ? undefined : levelRanks[level];
|
|
6
|
+
return rank === undefined ? null : { permission, rank };
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export const githubPermissionCovers = (granted: string, required: string) => {
|
|
10
|
+
const held = parsePermission(granted);
|
|
11
|
+
const needed = parsePermission(required);
|
|
12
|
+
if (!held || !needed) return granted === required;
|
|
13
|
+
return held.permission === needed.permission && held.rank >= needed.rank;
|
|
14
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { OwnerRef } from '@inixiative/signet/contracts';
|
|
2
|
+
|
|
3
|
+
export const githubProviderForOwner = (
|
|
4
|
+
ownerModel: OwnerRef['ownerModel'],
|
|
5
|
+
): 'githubOrganization' | 'githubUser' =>
|
|
6
|
+
ownerModel === 'Organization' || ownerModel === 'Space' ? 'githubOrganization' : 'githubUser';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { OAuthClient } from '../../../contracts';
|
|
3
|
+
import { findProvider } from '../../../findProvider';
|
|
4
|
+
|
|
5
|
+
export const githubUserAuthorizeUrl = (app: Pick<OAuthClient, 'clientId'>, state: string) => {
|
|
6
|
+
const url = new URL(z.url().parse(findProvider('github')?.oauth?.authorizeUrl));
|
|
7
|
+
url.searchParams.set('client_id', app.clientId);
|
|
8
|
+
url.searchParams.set('state', state);
|
|
9
|
+
return url.toString();
|
|
10
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { IntegrationEvent } from '@inixiative/signet/contracts';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { githubRepositoryIdSchema } from '../models/repository/githubRepositoryIdSchema';
|
|
4
|
+
|
|
5
|
+
const repositoryIdSchema = z.object({ repository: z.object({ id: z.number().int() }) });
|
|
6
|
+
|
|
7
|
+
export const githubEventRepositoryId = (event: Pick<IntegrationEvent, 'payload'>) => {
|
|
8
|
+
const id = repositoryIdSchema.safeParse(event.payload).data?.repository.id;
|
|
9
|
+
return id === undefined ? null : (githubRepositoryIdSchema.safeParse(String(id)).data ?? null);
|
|
10
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
export const githubNotificationSchema = z.looseObject({
|
|
4
|
+
id: z.string().min(1),
|
|
5
|
+
reason: z.string(),
|
|
6
|
+
updated_at: z.string(),
|
|
7
|
+
subject: z.object({ title: z.string(), url: z.url().nullable(), type: z.string() }),
|
|
8
|
+
repository: z.object({ id: z.number().int(), full_name: z.string() }),
|
|
9
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { ProviderClient } from '../../../utils/providerClient';
|
|
3
|
+
import { fetchAllGithubPages } from '../fetchAllGithubPages';
|
|
4
|
+
import { githubNotificationSchema } from './githubNotificationSchema';
|
|
5
|
+
|
|
6
|
+
export const listGithubNotifications = async (
|
|
7
|
+
client: ProviderClient,
|
|
8
|
+
{ since }: { since: Date },
|
|
9
|
+
) => {
|
|
10
|
+
let truncated = false;
|
|
11
|
+
const notifications = z.array(githubNotificationSchema).parse(
|
|
12
|
+
await fetchAllGithubPages(
|
|
13
|
+
client,
|
|
14
|
+
{
|
|
15
|
+
path: '/notifications',
|
|
16
|
+
query: { all: 'true', participating: 'true', since: since.toISOString(), per_page: 50 },
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
maxPages: 10,
|
|
20
|
+
onCapped: () => {
|
|
21
|
+
truncated = true;
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
),
|
|
25
|
+
);
|
|
26
|
+
return { notifications, truncated };
|
|
27
|
+
};
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import type { IntegrationEvent } from '@inixiative/signet/contracts';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import type { ProviderEvent } from '../../../providerEvent';
|
|
4
|
+
import { providerEventSchema } from '../../../providerEventSchema';
|
|
5
|
+
import { readGithubRepositoryName } from '../models/repository/readGithubRepositoryName';
|
|
6
|
+
|
|
7
|
+
const excerptLength = 500;
|
|
8
|
+
|
|
9
|
+
const userSchema = z.object({ login: z.string().min(1), id: z.number().int() });
|
|
10
|
+
const loginsSchema = z.array(z.object({ login: z.string().min(1) })).default([]);
|
|
11
|
+
const textSchema = z.string().nullish();
|
|
12
|
+
|
|
13
|
+
const repositorySchema = z.object({ id: z.number().int(), full_name: z.string() });
|
|
14
|
+
|
|
15
|
+
const threadSchema = z.object({
|
|
16
|
+
id: z.number().int(),
|
|
17
|
+
number: z.number().int(),
|
|
18
|
+
title: z.string(),
|
|
19
|
+
html_url: z.url(),
|
|
20
|
+
body: textSchema,
|
|
21
|
+
updated_at: z.string(),
|
|
22
|
+
assignees: loginsSchema,
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const pullRequestSchema = threadSchema.extend({ requested_reviewers: loginsSchema });
|
|
26
|
+
|
|
27
|
+
const commentSchema = z.object({
|
|
28
|
+
id: z.number().int(),
|
|
29
|
+
body: textSchema,
|
|
30
|
+
html_url: z.url(),
|
|
31
|
+
created_at: z.string(),
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const base = { repository: repositorySchema, sender: userSchema.nullish() };
|
|
35
|
+
|
|
36
|
+
const payloadSchemas = {
|
|
37
|
+
'issue_comment.created': z.object({ ...base, issue: threadSchema, comment: commentSchema }),
|
|
38
|
+
'issues.opened': z.object({ ...base, issue: threadSchema }),
|
|
39
|
+
'issues.assigned': z.object({ ...base, issue: threadSchema, assignee: userSchema }),
|
|
40
|
+
'pull_request.opened': z.object({ ...base, pull_request: pullRequestSchema }),
|
|
41
|
+
'pull_request.closed': z.object({ ...base, pull_request: pullRequestSchema }),
|
|
42
|
+
'pull_request.review_requested': z.object({
|
|
43
|
+
...base,
|
|
44
|
+
pull_request: pullRequestSchema,
|
|
45
|
+
requested_reviewer: userSchema,
|
|
46
|
+
}),
|
|
47
|
+
'pull_request.assigned': z.object({
|
|
48
|
+
...base,
|
|
49
|
+
pull_request: pullRequestSchema,
|
|
50
|
+
assignee: userSchema,
|
|
51
|
+
}),
|
|
52
|
+
'pull_request_review.submitted': z.object({
|
|
53
|
+
...base,
|
|
54
|
+
pull_request: pullRequestSchema,
|
|
55
|
+
review: commentSchema.omit({ created_at: true }).extend({
|
|
56
|
+
submitted_at: z.string(),
|
|
57
|
+
state: z.string(),
|
|
58
|
+
}),
|
|
59
|
+
}),
|
|
60
|
+
'pull_request_review_comment.created': z.object({
|
|
61
|
+
...base,
|
|
62
|
+
pull_request: pullRequestSchema,
|
|
63
|
+
comment: commentSchema,
|
|
64
|
+
}),
|
|
65
|
+
} as const;
|
|
66
|
+
|
|
67
|
+
type GithubEventType = keyof typeof payloadSchemas;
|
|
68
|
+
|
|
69
|
+
const isGithubEventType = (type: string): type is GithubEventType =>
|
|
70
|
+
Object.hasOwn(payloadSchemas, type);
|
|
71
|
+
|
|
72
|
+
const mentionPattern = /(?<![\w`/@.-])@([a-z0-9](?:[a-z0-9]|-(?=[a-z0-9])){0,38})(?![\w/-])/gi;
|
|
73
|
+
|
|
74
|
+
const login = (value: string) => value.toLowerCase();
|
|
75
|
+
|
|
76
|
+
const githubMentions = (text: string | null | undefined) => [
|
|
77
|
+
...new Set([...(text ?? '').matchAll(mentionPattern)].map((match) => login(match[1]!))),
|
|
78
|
+
];
|
|
79
|
+
|
|
80
|
+
const logins = (users: { login: string }[]) => [...new Set(users.map((user) => login(user.login)))];
|
|
81
|
+
|
|
82
|
+
const isoAt = (value: string) => new Date(value).toISOString();
|
|
83
|
+
|
|
84
|
+
type Parsed<T extends GithubEventType> = z.infer<(typeof payloadSchemas)[T]>;
|
|
85
|
+
|
|
86
|
+
type Fields = Pick<
|
|
87
|
+
IntegrationEvent,
|
|
88
|
+
'mentions' | 'assignees' | 'requestedReviewers' | 'subject' | 'excerpt' | 'at'
|
|
89
|
+
>;
|
|
90
|
+
|
|
91
|
+
const thread = (item: z.infer<typeof threadSchema>) => ({
|
|
92
|
+
title: item.title,
|
|
93
|
+
url: item.html_url,
|
|
94
|
+
number: item.number,
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
const excerpt = (text: string | null | undefined) =>
|
|
98
|
+
text ? { excerpt: text.slice(0, excerptLength) } : {};
|
|
99
|
+
|
|
100
|
+
const none = { mentions: [], assignees: [], requestedReviewers: [] };
|
|
101
|
+
|
|
102
|
+
const fieldsOf: { [T in GithubEventType]: (payload: Parsed<T>) => Fields } = {
|
|
103
|
+
'issue_comment.created': ({ issue, comment }) => ({
|
|
104
|
+
...none,
|
|
105
|
+
mentions: githubMentions(comment.body),
|
|
106
|
+
subject: { ...thread(issue), url: comment.html_url },
|
|
107
|
+
...excerpt(comment.body),
|
|
108
|
+
at: isoAt(comment.created_at),
|
|
109
|
+
}),
|
|
110
|
+
'issues.opened': ({ issue }) => ({
|
|
111
|
+
...none,
|
|
112
|
+
mentions: githubMentions(issue.body),
|
|
113
|
+
assignees: logins(issue.assignees),
|
|
114
|
+
subject: thread(issue),
|
|
115
|
+
...excerpt(issue.body),
|
|
116
|
+
at: isoAt(issue.updated_at),
|
|
117
|
+
}),
|
|
118
|
+
'issues.assigned': ({ issue, assignee }) => ({
|
|
119
|
+
...none,
|
|
120
|
+
assignees: logins([assignee]),
|
|
121
|
+
subject: thread(issue),
|
|
122
|
+
at: isoAt(issue.updated_at),
|
|
123
|
+
}),
|
|
124
|
+
'pull_request.opened': ({ pull_request }) => ({
|
|
125
|
+
mentions: githubMentions(pull_request.body),
|
|
126
|
+
assignees: logins(pull_request.assignees),
|
|
127
|
+
requestedReviewers: logins(pull_request.requested_reviewers),
|
|
128
|
+
subject: thread(pull_request),
|
|
129
|
+
...excerpt(pull_request.body),
|
|
130
|
+
at: isoAt(pull_request.updated_at),
|
|
131
|
+
}),
|
|
132
|
+
'pull_request.closed': ({ pull_request }) => ({
|
|
133
|
+
...none,
|
|
134
|
+
subject: thread(pull_request),
|
|
135
|
+
at: isoAt(pull_request.updated_at),
|
|
136
|
+
}),
|
|
137
|
+
'pull_request.review_requested': ({ pull_request, requested_reviewer }) => ({
|
|
138
|
+
...none,
|
|
139
|
+
requestedReviewers: logins([requested_reviewer]),
|
|
140
|
+
subject: thread(pull_request),
|
|
141
|
+
at: isoAt(pull_request.updated_at),
|
|
142
|
+
}),
|
|
143
|
+
'pull_request.assigned': ({ pull_request, assignee }) => ({
|
|
144
|
+
...none,
|
|
145
|
+
assignees: logins([assignee]),
|
|
146
|
+
subject: thread(pull_request),
|
|
147
|
+
at: isoAt(pull_request.updated_at),
|
|
148
|
+
}),
|
|
149
|
+
'pull_request_review.submitted': ({ pull_request, review }) => ({
|
|
150
|
+
...none,
|
|
151
|
+
mentions: githubMentions(review.body),
|
|
152
|
+
subject: { ...thread(pull_request), url: review.html_url },
|
|
153
|
+
...excerpt(review.body),
|
|
154
|
+
at: isoAt(review.submitted_at),
|
|
155
|
+
}),
|
|
156
|
+
'pull_request_review_comment.created': ({ pull_request, comment }) => ({
|
|
157
|
+
...none,
|
|
158
|
+
mentions: githubMentions(comment.body),
|
|
159
|
+
subject: { ...thread(pull_request), url: comment.html_url },
|
|
160
|
+
...excerpt(comment.body),
|
|
161
|
+
at: isoAt(comment.created_at),
|
|
162
|
+
}),
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
const normalize = <T extends GithubEventType>(type: T, payload: unknown) => {
|
|
166
|
+
const parsed = payloadSchemas[type].safeParse(payload);
|
|
167
|
+
if (!parsed.success) return null;
|
|
168
|
+
const data = parsed.data as Parsed<T>;
|
|
169
|
+
const scope = readGithubRepositoryName(data.repository.full_name);
|
|
170
|
+
if (!scope) return null;
|
|
171
|
+
const fields = fieldsOf[type](data);
|
|
172
|
+
return {
|
|
173
|
+
...fields,
|
|
174
|
+
actor: data.sender ? { login: login(data.sender.login), id: String(data.sender.id) } : null,
|
|
175
|
+
scope,
|
|
176
|
+
};
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
export const normalizeGithubEvent = (input: {
|
|
180
|
+
integrationId: string;
|
|
181
|
+
provider: string;
|
|
182
|
+
event: string;
|
|
183
|
+
deliveryId: string;
|
|
184
|
+
payload: unknown;
|
|
185
|
+
}): ProviderEvent | null => {
|
|
186
|
+
const action = z.object({ action: z.string() }).safeParse(input.payload).data?.action;
|
|
187
|
+
const type = action ? `${input.event}.${action}` : input.event;
|
|
188
|
+
if (!isGithubEventType(type)) return null;
|
|
189
|
+
const fields = normalize(type, input.payload);
|
|
190
|
+
if (!fields) return null;
|
|
191
|
+
const event = providerEventSchema.safeParse({
|
|
192
|
+
eventId: input.deliveryId,
|
|
193
|
+
integrationId: input.integrationId,
|
|
194
|
+
provider: input.provider,
|
|
195
|
+
type,
|
|
196
|
+
...fields,
|
|
197
|
+
payload: input.payload,
|
|
198
|
+
});
|
|
199
|
+
return event.success ? event.data : null;
|
|
200
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { IntegrationEvent } from '@inixiative/signet/contracts';
|
|
2
|
+
import type { ProviderEvent } from '../../../providerEvent';
|
|
3
|
+
import { providerEventSchema } from '../../../providerEventSchema';
|
|
4
|
+
import { readGithubRepositoryName } from '../models/repository/readGithubRepositoryName';
|
|
5
|
+
import type { GithubNotification } from './githubNotification';
|
|
6
|
+
|
|
7
|
+
const namedBy = {
|
|
8
|
+
mention: 'mentions',
|
|
9
|
+
review_requested: 'requestedReviewers',
|
|
10
|
+
assign: 'assignees',
|
|
11
|
+
} as const;
|
|
12
|
+
|
|
13
|
+
const isNamingReason = (reason: string): reason is keyof typeof namedBy =>
|
|
14
|
+
Object.hasOwn(namedBy, reason);
|
|
15
|
+
|
|
16
|
+
const apiSubjectPattern =
|
|
17
|
+
/^https:\/\/api\.github\.com\/repos\/([^/]+\/[^/]+)\/(issues|pulls)\/(\d+)$/;
|
|
18
|
+
|
|
19
|
+
const subjectLink = (url: string | null) => {
|
|
20
|
+
const match = url ? apiSubjectPattern.exec(url) : null;
|
|
21
|
+
if (!match) return {};
|
|
22
|
+
const [, repository, kind, number] = match;
|
|
23
|
+
return {
|
|
24
|
+
url: `https://github.com/${repository}/${kind === 'pulls' ? 'pull' : 'issues'}/${number}`,
|
|
25
|
+
number: Number(number),
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export const normalizeGithubNotification = (input: {
|
|
30
|
+
integrationId: string;
|
|
31
|
+
provider: string;
|
|
32
|
+
login: string;
|
|
33
|
+
notification: GithubNotification;
|
|
34
|
+
}): ProviderEvent | null => {
|
|
35
|
+
const { notification } = input;
|
|
36
|
+
if (!isNamingReason(notification.reason)) return null;
|
|
37
|
+
const scope = readGithubRepositoryName(notification.repository.full_name);
|
|
38
|
+
if (!scope) return null;
|
|
39
|
+
const login = input.login.toLowerCase();
|
|
40
|
+
const event = providerEventSchema.safeParse({
|
|
41
|
+
eventId: `${notification.id}:${notification.updated_at}`,
|
|
42
|
+
integrationId: input.integrationId,
|
|
43
|
+
provider: input.provider,
|
|
44
|
+
type: `notifications.${notification.reason}`,
|
|
45
|
+
at: new Date(notification.updated_at).toISOString(),
|
|
46
|
+
actor: null,
|
|
47
|
+
scope,
|
|
48
|
+
mentions: [],
|
|
49
|
+
assignees: [],
|
|
50
|
+
requestedReviewers: [],
|
|
51
|
+
[namedBy[notification.reason]]: [login],
|
|
52
|
+
subject: { title: notification.subject.title, ...subjectLink(notification.subject.url) },
|
|
53
|
+
payload: notification,
|
|
54
|
+
});
|
|
55
|
+
return event.success ? event.data : null;
|
|
56
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { matchesHmacSha256 } from '../../../utils/matchesHmacSha256';
|
|
2
|
+
|
|
3
|
+
export const verifyGithubSignature = (
|
|
4
|
+
rawBody: Uint8Array,
|
|
5
|
+
signature: string | null | undefined,
|
|
6
|
+
secret: string,
|
|
7
|
+
) => matchesHmacSha256(rawBody, /^sha256=([a-f0-9]{64})$/.exec(signature ?? '')?.[1], secret);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { fetchAllRequestPages } from '../../utils/pagination/fetchAllRequestPages';
|
|
2
|
+
import type { ProviderPagesOptions } from '../../utils/pagination/providerPagesOptions';
|
|
3
|
+
import type { ProviderClient } from '../../utils/providerClient';
|
|
4
|
+
import type { ProviderRequestInput } from '../../utils/providerRequestInput';
|
|
5
|
+
import { githubPagination } from './githubPagination';
|
|
6
|
+
import { requestGithub } from './requestGithub';
|
|
7
|
+
|
|
8
|
+
export const fetchAllGithubPages = (
|
|
9
|
+
client: ProviderClient,
|
|
10
|
+
input: ProviderRequestInput,
|
|
11
|
+
options?: ProviderPagesOptions,
|
|
12
|
+
) => fetchAllRequestPages(githubPagination, (page) => requestGithub(client, page), input, options);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const githubApiVersion = '2026-03-10';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ProviderDefinition } from '../../contracts';
|
|
2
|
+
import { githubRepository } from './models/repository/githubRepository';
|
|
3
|
+
|
|
4
|
+
export const githubOrganizationProvider: ProviderDefinition = {
|
|
5
|
+
key: 'githubOrganization',
|
|
6
|
+
name: 'GitHub organization',
|
|
7
|
+
documentationUrl:
|
|
8
|
+
'https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/authenticating-as-a-github-app-installation',
|
|
9
|
+
authMethods: ['clientCredentials'],
|
|
10
|
+
family: 'github',
|
|
11
|
+
operations: [...githubRepository.operations, ...githubRepository.events],
|
|
12
|
+
eventResourceExternalId: githubRepository.externalIdOfEvent,
|
|
13
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ProviderPagination } from '../../utils/pagination/providerPagination';
|
|
2
|
+
|
|
3
|
+
export const githubPagination = {
|
|
4
|
+
strategy: 'page',
|
|
5
|
+
keys: { page: 'page', pageSize: 'per_page', data: '', total: 'total_count' },
|
|
6
|
+
pageSize: 100,
|
|
7
|
+
} satisfies ProviderPagination;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ProviderDefinition } from '../../contracts';
|
|
2
|
+
|
|
3
|
+
export const githubProvider: ProviderDefinition = {
|
|
4
|
+
key: 'github',
|
|
5
|
+
name: 'GitHub',
|
|
6
|
+
documentationUrl: 'https://docs.github.com/en/apps/overview',
|
|
7
|
+
authMethods: ['oauth2'],
|
|
8
|
+
operations: [],
|
|
9
|
+
oauth: {
|
|
10
|
+
authorizeUrl: 'https://github.com/login/oauth/authorize',
|
|
11
|
+
tokenUrl: 'https://github.com/login/oauth/access_token',
|
|
12
|
+
},
|
|
13
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { githubApiVersion } from './githubApiVersion';
|
|
2
|
+
|
|
3
|
+
export const githubRequestHeaders = (headers: Headers, token?: string) => {
|
|
4
|
+
headers.set('Accept', 'application/vnd.github+json');
|
|
5
|
+
headers.set('X-GitHub-Api-Version', githubApiVersion);
|
|
6
|
+
headers.set('User-Agent', 'inixiative-integrations');
|
|
7
|
+
if (token) headers.set('Authorization', `Bearer ${token}`);
|
|
8
|
+
return headers;
|
|
9
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ProviderDefinition } from '../../contracts';
|
|
2
|
+
import { githubAccount } from './models/account/githubAccount';
|
|
3
|
+
import { githubRepository } from './models/repository/githubRepository';
|
|
4
|
+
|
|
5
|
+
export const githubUserProvider: ProviderDefinition = {
|
|
6
|
+
key: 'githubUser',
|
|
7
|
+
name: 'GitHub user',
|
|
8
|
+
documentationUrl:
|
|
9
|
+
'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
|
+
authMethods: ['oauth2', 'bearer'],
|
|
11
|
+
family: 'github',
|
|
12
|
+
operations: [...githubRepository.operations, ...githubAccount.events],
|
|
13
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { iterateRequestPages } from '../../utils/pagination/iterateRequestPages';
|
|
2
|
+
import type { ProviderPagesOptions } from '../../utils/pagination/providerPagesOptions';
|
|
3
|
+
import type { ProviderClient } from '../../utils/providerClient';
|
|
4
|
+
import type { ProviderRequestInput } from '../../utils/providerRequestInput';
|
|
5
|
+
import { githubPagination } from './githubPagination';
|
|
6
|
+
import { requestGithub } from './requestGithub';
|
|
7
|
+
|
|
8
|
+
export const iterateGithubPages = (
|
|
9
|
+
client: ProviderClient,
|
|
10
|
+
input: ProviderRequestInput,
|
|
11
|
+
options?: ProviderPagesOptions,
|
|
12
|
+
) => iterateRequestPages(githubPagination, (page) => requestGithub(client, page), input, options);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { accountResourceKind } from '@inixiative/signet/contracts';
|
|
2
|
+
import { declaredOperations } from '../../../../declaredOperations';
|
|
3
|
+
import type { ProviderModel } from '../../../../providerModel';
|
|
4
|
+
|
|
5
|
+
export const githubAccount = {
|
|
6
|
+
kind: accountResourceKind,
|
|
7
|
+
operations: [],
|
|
8
|
+
events: declaredOperations(
|
|
9
|
+
{
|
|
10
|
+
'events.notifications.mention': 'Receive the mentions of this GitHub user',
|
|
11
|
+
'events.notifications.review_requested': 'Receive the review requests of this GitHub user',
|
|
12
|
+
'events.notifications.assign': 'Receive the assignments of this GitHub user',
|
|
13
|
+
},
|
|
14
|
+
accountResourceKind,
|
|
15
|
+
['notifications'],
|
|
16
|
+
),
|
|
17
|
+
} satisfies ProviderModel;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { githubInputSchemas, githubOperationSchema } from '@inixiative/signet/contracts';
|
|
2
|
+
import type { OperationHandler } from '../../../../operationHandler';
|
|
3
|
+
import { objectSchema } from '../../../../utils/objectSchema';
|
|
4
|
+
import { githubRequestHeaders } from '../../githubRequestHeaders';
|
|
5
|
+
import { githubRepositoryMetadataSchema } from './githubRepositoryMetadataSchema';
|
|
6
|
+
import { readGithubObject } from './readGithubObject';
|
|
7
|
+
|
|
8
|
+
const objectKinds = {
|
|
9
|
+
'commits.read': 'commits',
|
|
10
|
+
'trees.read': 'trees',
|
|
11
|
+
'blobs.read': 'blobs',
|
|
12
|
+
} as const;
|
|
13
|
+
|
|
14
|
+
const requestedObject = (operation: string, input: Record<string, unknown>) => {
|
|
15
|
+
const declared = githubOperationSchema.parse(operation);
|
|
16
|
+
return { declared, objectId: githubInputSchemas[declared].parse(input).objectId };
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export const githubOperationHandler: OperationHandler = {
|
|
20
|
+
request: ({ context, metadata, headers }) => {
|
|
21
|
+
const { declared, objectId } = requestedObject(context.operation, context.input);
|
|
22
|
+
const { fullName } = githubRepositoryMetadataSchema.parse(metadata);
|
|
23
|
+
githubRequestHeaders(headers);
|
|
24
|
+
return {
|
|
25
|
+
url: new URL(
|
|
26
|
+
`https://api.github.com/repos/${fullName}/git/${objectKinds[declared]}/${objectId}`,
|
|
27
|
+
),
|
|
28
|
+
};
|
|
29
|
+
},
|
|
30
|
+
parse: (body, context) =>
|
|
31
|
+
readGithubObject(
|
|
32
|
+
objectSchema.parse(body),
|
|
33
|
+
context,
|
|
34
|
+
requestedObject(context.operation, context.input).objectId,
|
|
35
|
+
),
|
|
36
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import {
|
|
2
|
+
githubOperationNames,
|
|
3
|
+
githubOperationSchema,
|
|
4
|
+
repositoryResourceKind,
|
|
5
|
+
} from '@inixiative/signet/contracts';
|
|
6
|
+
import { declaredOperations } from '../../../../declaredOperations';
|
|
7
|
+
import type { ProviderModel } from '../../../../providerModel';
|
|
8
|
+
import { githubEventRepositoryId } from '../../events/githubEventRepositoryId';
|
|
9
|
+
import { githubRepositoryIdSchema } from './githubRepositoryIdSchema';
|
|
10
|
+
import { githubRepositoryMetadataSchema } from './githubRepositoryMetadataSchema';
|
|
11
|
+
|
|
12
|
+
export const githubRepository = {
|
|
13
|
+
kind: repositoryResourceKind,
|
|
14
|
+
externalIdSchema: githubRepositoryIdSchema,
|
|
15
|
+
metadataSchema: githubRepositoryMetadataSchema,
|
|
16
|
+
operations: declaredOperations(
|
|
17
|
+
githubOperationNames,
|
|
18
|
+
repositoryResourceKind,
|
|
19
|
+
['contents:read'],
|
|
20
|
+
githubOperationSchema.options,
|
|
21
|
+
),
|
|
22
|
+
events: declaredOperations(
|
|
23
|
+
{
|
|
24
|
+
'events.pull_request.opened': 'Receive pull requests opened in this repository',
|
|
25
|
+
'events.pull_request.review_requested': 'Receive review requests in this repository',
|
|
26
|
+
'events.pull_request.assigned': 'Receive pull request assignments in this repository',
|
|
27
|
+
'events.pull_request.closed': 'Receive pull requests closed or merged in this repository',
|
|
28
|
+
'events.issue_comment.created':
|
|
29
|
+
'Receive comments on issues and pull requests in this repository',
|
|
30
|
+
'events.issues.opened': 'Receive issues opened in this repository',
|
|
31
|
+
'events.issues.assigned': 'Receive issue assignments in this repository',
|
|
32
|
+
'events.pull_request_review.submitted': 'Receive pull request reviews in this repository',
|
|
33
|
+
'events.pull_request_review_comment.created':
|
|
34
|
+
'Receive pull request review comments in this repository',
|
|
35
|
+
},
|
|
36
|
+
repositoryResourceKind,
|
|
37
|
+
['issues:read', 'pull_requests:read'],
|
|
38
|
+
),
|
|
39
|
+
externalIdOfEvent: githubEventRepositoryId,
|
|
40
|
+
} satisfies ProviderModel;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
export const githubRepositoryNameSchema = z
|
|
4
|
+
.string()
|
|
5
|
+
.regex(/^[a-z0-9]+(?:-[a-z0-9]+)*\/[a-z0-9_.-]+$/)
|
|
6
|
+
.refine((name) => {
|
|
7
|
+
const [owner = '', repository = ''] = name.split('/');
|
|
8
|
+
return owner.length <= 39 && repository.length <= 100 && !['.', '..'].includes(repository);
|
|
9
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { z } from 'zod';
|
|
2
|
+
import type { githubTreeEntryModeSchema } from './githubTreeEntryModeSchema';
|
|
3
|
+
import type { githubTreeEntryTypeSchema } from './githubTreeEntryTypeSchema';
|
|
4
|
+
|
|
5
|
+
export const githubTreeEntryTypeForMode: Record<
|
|
6
|
+
z.infer<typeof githubTreeEntryModeSchema>,
|
|
7
|
+
z.infer<typeof githubTreeEntryTypeSchema>
|
|
8
|
+
> = {
|
|
9
|
+
'040000': 'tree',
|
|
10
|
+
'100644': 'blob',
|
|
11
|
+
'100755': 'blob',
|
|
12
|
+
'120000': 'blob',
|
|
13
|
+
'160000': 'commit',
|
|
14
|
+
};
|