@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,127 @@
|
|
|
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 { linearUserSchema } from './linearUserSchema';
|
|
6
|
+
import type { LinearWebhookPayload } from './linearWebhookPayload';
|
|
7
|
+
|
|
8
|
+
const excerptLength = 500;
|
|
9
|
+
|
|
10
|
+
const textSchema = z.string().nullish();
|
|
11
|
+
|
|
12
|
+
const issueSchema = z.object({
|
|
13
|
+
id: z.string().min(1),
|
|
14
|
+
identifier: z.string().min(1),
|
|
15
|
+
number: z.number(),
|
|
16
|
+
title: z.string(),
|
|
17
|
+
url: z.url(),
|
|
18
|
+
teamId: z.string().min(1),
|
|
19
|
+
description: textSchema,
|
|
20
|
+
assigneeId: z.string().nullish(),
|
|
21
|
+
assignee: linearUserSchema.nullish(),
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
const commentSchema = z.object({
|
|
25
|
+
id: z.string().min(1),
|
|
26
|
+
body: textSchema,
|
|
27
|
+
parentId: z.string().nullish(),
|
|
28
|
+
user: linearUserSchema.nullish(),
|
|
29
|
+
issue: z.object({
|
|
30
|
+
id: z.string().min(1),
|
|
31
|
+
identifier: z.string().min(1),
|
|
32
|
+
title: z.string(),
|
|
33
|
+
url: z.url(),
|
|
34
|
+
teamId: z.string().min(1),
|
|
35
|
+
}),
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
const profilePattern = /https:\/\/linear\.app\/[\w-]+\/profiles\/([\w.-]+)/g;
|
|
39
|
+
|
|
40
|
+
const login = (value: string) => value.toLowerCase();
|
|
41
|
+
|
|
42
|
+
const linearMentions = (text: string | null | undefined) => [
|
|
43
|
+
...new Set([...(text ?? '').matchAll(profilePattern)].map((match) => login(match[1]!))),
|
|
44
|
+
];
|
|
45
|
+
|
|
46
|
+
const loginOf = (user: z.infer<typeof linearUserSchema>) => {
|
|
47
|
+
const handle = /\/profiles\/([\w.-]+)/.exec(user.url ?? '')?.[1];
|
|
48
|
+
return { login: handle ? login(handle) : user.id, id: user.id };
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const excerpt = (text: string | null | undefined) =>
|
|
52
|
+
text ? { excerpt: text.slice(0, excerptLength) } : {};
|
|
53
|
+
|
|
54
|
+
type Fields = Pick<IntegrationEvent, 'mentions' | 'assignees' | 'scope' | 'subject' | 'excerpt'>;
|
|
55
|
+
|
|
56
|
+
const issueSubject = (issue: { title: string; url: string; identifier: string }) => ({
|
|
57
|
+
title: `${issue.identifier} ${issue.title}`,
|
|
58
|
+
url: issue.url,
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
const addedMentions = (current: string | null | undefined, previous: unknown) => {
|
|
62
|
+
const before = new Set(linearMentions(typeof previous === 'string' ? previous : ''));
|
|
63
|
+
return linearMentions(current).filter((mention) => !before.has(mention));
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const fieldsOf: Record<string, (payload: LinearWebhookPayload) => Fields | null> = {
|
|
67
|
+
'Issue.create': ({ data }) => {
|
|
68
|
+
const issue = issueSchema.safeParse(data).data;
|
|
69
|
+
if (!issue) return null;
|
|
70
|
+
return {
|
|
71
|
+
mentions: linearMentions(issue.description),
|
|
72
|
+
assignees: issue.assignee ? [loginOf(issue.assignee).login] : [],
|
|
73
|
+
scope: issue.teamId,
|
|
74
|
+
subject: { ...issueSubject(issue), number: issue.number },
|
|
75
|
+
...excerpt(issue.description),
|
|
76
|
+
};
|
|
77
|
+
},
|
|
78
|
+
'Issue.update': ({ data, updatedFrom }) => {
|
|
79
|
+
const issue = issueSchema.safeParse(data).data;
|
|
80
|
+
if (!issue) return null;
|
|
81
|
+
const previous = updatedFrom ?? {};
|
|
82
|
+
const reassigned = Object.hasOwn(previous, 'assigneeId') && issue.assignee;
|
|
83
|
+
return {
|
|
84
|
+
mentions: Object.hasOwn(previous, 'description')
|
|
85
|
+
? addedMentions(issue.description, previous.description)
|
|
86
|
+
: [],
|
|
87
|
+
assignees: reassigned && issue.assignee ? [loginOf(issue.assignee).login] : [],
|
|
88
|
+
scope: issue.teamId,
|
|
89
|
+
subject: { ...issueSubject(issue), number: issue.number },
|
|
90
|
+
};
|
|
91
|
+
},
|
|
92
|
+
'Comment.create': ({ data, url }) => {
|
|
93
|
+
const comment = commentSchema.safeParse(data).data;
|
|
94
|
+
if (!comment) return null;
|
|
95
|
+
return {
|
|
96
|
+
mentions: linearMentions(comment.body),
|
|
97
|
+
assignees: [],
|
|
98
|
+
scope: comment.issue.teamId,
|
|
99
|
+
subject: { ...issueSubject(comment.issue), ...(url ? { url } : {}) },
|
|
100
|
+
...excerpt(comment.body),
|
|
101
|
+
};
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
export const normalizeLinearEvent = (input: {
|
|
106
|
+
integrationId: string;
|
|
107
|
+
provider: string;
|
|
108
|
+
deliveryId: string;
|
|
109
|
+
payload: LinearWebhookPayload;
|
|
110
|
+
body: unknown;
|
|
111
|
+
}): ProviderEvent | null => {
|
|
112
|
+
const type = `${input.payload.type}.${input.payload.action}`;
|
|
113
|
+
const fields = Object.hasOwn(fieldsOf, type) ? fieldsOf[type]!(input.payload) : null;
|
|
114
|
+
if (!fields) return null;
|
|
115
|
+
const event = providerEventSchema.safeParse({
|
|
116
|
+
eventId: input.deliveryId,
|
|
117
|
+
integrationId: input.integrationId,
|
|
118
|
+
provider: input.provider,
|
|
119
|
+
type,
|
|
120
|
+
at: new Date(input.payload.createdAt).toISOString(),
|
|
121
|
+
actor: input.payload.actor ? loginOf(input.payload.actor) : null,
|
|
122
|
+
requestedReviewers: [],
|
|
123
|
+
...fields,
|
|
124
|
+
payload: input.body,
|
|
125
|
+
});
|
|
126
|
+
return event.success ? event.data : null;
|
|
127
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { LinearClient } from '../linearClient';
|
|
3
|
+
import { requestLinear } from '../requestLinear';
|
|
4
|
+
|
|
5
|
+
const updatedSchema = z.object({ webhookUpdate: z.object({ success: z.boolean() }) });
|
|
6
|
+
|
|
7
|
+
export const repairLinearWebhook = async (
|
|
8
|
+
client: LinearClient,
|
|
9
|
+
{ id, secret }: { id: string; secret: string },
|
|
10
|
+
) =>
|
|
11
|
+
updatedSchema.parse(
|
|
12
|
+
await requestLinear(client, {
|
|
13
|
+
query:
|
|
14
|
+
'mutation WebhookRepair($id: String!, $input: WebhookUpdateInput!) { webhookUpdate(id: $id, input: $input) { success } }',
|
|
15
|
+
variables: { id, input: { enabled: true, secret } },
|
|
16
|
+
}),
|
|
17
|
+
).webhookUpdate.success;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { matchesHmacSha256 } from '../../../utils/matchesHmacSha256';
|
|
3
|
+
|
|
4
|
+
const replayWindowMs = 60 * 1000;
|
|
5
|
+
|
|
6
|
+
const signedFieldsSchema = z.object({ webhookTimestamp: z.number() });
|
|
7
|
+
|
|
8
|
+
const signedFields = (rawBody: Uint8Array) => {
|
|
9
|
+
try {
|
|
10
|
+
return signedFieldsSchema.safeParse(JSON.parse(new TextDecoder().decode(rawBody))).data ?? null;
|
|
11
|
+
} catch {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export const verifyLinearSignature = (
|
|
17
|
+
rawBody: Uint8Array,
|
|
18
|
+
headers: Headers,
|
|
19
|
+
integrationSecret: string,
|
|
20
|
+
now = Date.now(),
|
|
21
|
+
) => {
|
|
22
|
+
if (!matchesHmacSha256(rawBody, headers.get('linear-signature'), integrationSecret)) return false;
|
|
23
|
+
const fields = signedFields(rawBody);
|
|
24
|
+
return fields !== null && Math.abs(now - fields.webhookTimestamp) <= replayWindowMs;
|
|
25
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { collectPages } from '../../utils/pagination/collectPages';
|
|
2
|
+
import { iterateProviderPages } from '../../utils/pagination/iterateProviderPages';
|
|
3
|
+
import type { ProviderPagesOptions } from '../../utils/pagination/providerPagesOptions';
|
|
4
|
+
import { readPath } from '../../utils/pagination/readPath';
|
|
5
|
+
import { ProviderError } from '../../utils/providerError';
|
|
6
|
+
import type { LinearClient } from './linearClient';
|
|
7
|
+
import { linearPagination } from './linearPagination';
|
|
8
|
+
import type { LinearRequestInput } from './linearRequestInput';
|
|
9
|
+
import { requestLinear } from './requestLinear';
|
|
10
|
+
|
|
11
|
+
export const fetchAllLinearPages = (
|
|
12
|
+
client: LinearClient,
|
|
13
|
+
{ query, variables }: LinearRequestInput,
|
|
14
|
+
{ connection, ...options }: Omit<ProviderPagesOptions, 'keys'> & { connection: string },
|
|
15
|
+
) => {
|
|
16
|
+
const { keys } = linearPagination;
|
|
17
|
+
const pageSize = variables?.[keys.pageSize];
|
|
18
|
+
return collectPages(
|
|
19
|
+
(walk: Omit<ProviderPagesOptions, 'keys'>) =>
|
|
20
|
+
iterateProviderPages(linearPagination, {
|
|
21
|
+
...walk,
|
|
22
|
+
pageSize: typeof pageSize === 'number' ? pageSize : undefined,
|
|
23
|
+
keys: {
|
|
24
|
+
data: `${connection}.${keys.data}`,
|
|
25
|
+
nextCursor: `${connection}.${keys.nextCursor}`,
|
|
26
|
+
hasMore: `${connection}.${keys.hasMore}`,
|
|
27
|
+
},
|
|
28
|
+
fetchPage: (page) => requestLinear(client, { query, variables: { ...variables, ...page } }),
|
|
29
|
+
onResponse: (response, page) => {
|
|
30
|
+
if (
|
|
31
|
+
readPath(response, `${connection}.${keys.hasMore}`) === true &&
|
|
32
|
+
!readPath(response, `${connection}.${keys.nextCursor}`)
|
|
33
|
+
)
|
|
34
|
+
throw new ProviderError('provider_invalid_response');
|
|
35
|
+
walk.onResponse?.(response, page);
|
|
36
|
+
},
|
|
37
|
+
}),
|
|
38
|
+
options,
|
|
39
|
+
);
|
|
40
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ProviderPagination } from '../../utils/pagination/providerPagination';
|
|
2
|
+
|
|
3
|
+
export const linearPagination = {
|
|
4
|
+
strategy: 'cursor',
|
|
5
|
+
keys: {
|
|
6
|
+
cursor: 'after',
|
|
7
|
+
pageSize: 'first',
|
|
8
|
+
data: 'nodes',
|
|
9
|
+
nextCursor: 'pageInfo.endCursor',
|
|
10
|
+
hasMore: 'pageInfo.hasNextPage',
|
|
11
|
+
},
|
|
12
|
+
pageSize: 250,
|
|
13
|
+
} satisfies ProviderPagination;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { ProviderDefinition } from '../../contracts';
|
|
2
|
+
import { declaredOperations } from '../../declaredOperations';
|
|
3
|
+
|
|
4
|
+
const linearTeamEvents = {
|
|
5
|
+
'events.Issue.create': 'Receive issues created in this team',
|
|
6
|
+
'events.Issue.update': 'Receive issue changes in this team',
|
|
7
|
+
'events.Comment.create': "Receive comments on this team's issues",
|
|
8
|
+
} as const;
|
|
9
|
+
|
|
10
|
+
export const linearProvider: ProviderDefinition = {
|
|
11
|
+
key: 'linear',
|
|
12
|
+
name: 'Linear',
|
|
13
|
+
documentationUrl: 'https://linear.app/developers/graphql',
|
|
14
|
+
authMethods: ['apiKey', 'bearer', 'oauth2'],
|
|
15
|
+
operations: [
|
|
16
|
+
{
|
|
17
|
+
key: 'issues.read',
|
|
18
|
+
name: 'Read an issue',
|
|
19
|
+
resourceKind: 'issue',
|
|
20
|
+
requiredScopes: ['read'],
|
|
21
|
+
},
|
|
22
|
+
...declaredOperations(linearTeamEvents, 'team', ['read']),
|
|
23
|
+
],
|
|
24
|
+
syncedResourceKinds: ['team'],
|
|
25
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type LinearRequestInput = { query: string; variables?: Record<string, unknown> };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { OperationHandler } from '../../../../operationHandler';
|
|
2
|
+
import { objectSchema } from '../../../../utils/objectSchema';
|
|
3
|
+
import { ProviderError } from '../../../../utils/providerError';
|
|
4
|
+
import { select } from '../../../../utils/select';
|
|
5
|
+
|
|
6
|
+
export const linearOperationHandler: OperationHandler = {
|
|
7
|
+
request: ({ externalId, headers }) => {
|
|
8
|
+
headers.set('Content-Type', 'application/json');
|
|
9
|
+
return {
|
|
10
|
+
url: new URL('https://api.linear.app/graphql'),
|
|
11
|
+
body: JSON.stringify({
|
|
12
|
+
query:
|
|
13
|
+
'query OwnerIssue($id: String!) { issue(id: $id) { id identifier title description url state { name } } }',
|
|
14
|
+
variables: { id: externalId },
|
|
15
|
+
}),
|
|
16
|
+
};
|
|
17
|
+
},
|
|
18
|
+
parse: (body) => {
|
|
19
|
+
const data = objectSchema.parse(body);
|
|
20
|
+
if (data.errors) throw new ProviderError('provider_failed');
|
|
21
|
+
return select(objectSchema.parse(data.data).issue, [
|
|
22
|
+
'id',
|
|
23
|
+
'identifier',
|
|
24
|
+
'title',
|
|
25
|
+
'description',
|
|
26
|
+
'url',
|
|
27
|
+
'state',
|
|
28
|
+
]);
|
|
29
|
+
},
|
|
30
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { LinearClient } from '../../linearClient';
|
|
3
|
+
import { requestLinear } from '../../requestLinear';
|
|
4
|
+
|
|
5
|
+
const workspaceSchema = z.object({
|
|
6
|
+
organization: z.object({ id: z.string().min(1), urlKey: z.string() }),
|
|
7
|
+
teams: z.object({
|
|
8
|
+
pageInfo: z.object({ hasNextPage: z.boolean() }),
|
|
9
|
+
nodes: z.array(
|
|
10
|
+
z.object({
|
|
11
|
+
id: z.string().min(1),
|
|
12
|
+
key: z.string(),
|
|
13
|
+
name: z.string(),
|
|
14
|
+
private: z.boolean(),
|
|
15
|
+
}),
|
|
16
|
+
),
|
|
17
|
+
}),
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
const workspaceQuery =
|
|
21
|
+
'query Workspace { organization { id urlKey } teams(first: 250) { pageInfo { hasNextPage } nodes { id key name private } } }';
|
|
22
|
+
|
|
23
|
+
export const fetchLinearWorkspace = async (client: LinearClient) => {
|
|
24
|
+
const workspace = workspaceSchema.parse(await requestLinear(client, { query: workspaceQuery }));
|
|
25
|
+
return {
|
|
26
|
+
organizationId: workspace.organization.id,
|
|
27
|
+
teams: workspace.teams.nodes,
|
|
28
|
+
truncated: workspace.teams.pageInfo.hasNextPage,
|
|
29
|
+
};
|
|
30
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { ProviderError } from '../../utils/providerError';
|
|
3
|
+
import { providerRequest } from '../../utils/providerRequest';
|
|
4
|
+
import { requestProviderJson } from '../../utils/requestProviderJson';
|
|
5
|
+
import type { LinearClient } from './linearClient';
|
|
6
|
+
import type { LinearRequestInput } from './linearRequestInput';
|
|
7
|
+
|
|
8
|
+
const resultSchema = z.object({
|
|
9
|
+
data: z.unknown().optional(),
|
|
10
|
+
errors: z
|
|
11
|
+
.array(
|
|
12
|
+
z.object({
|
|
13
|
+
message: z.string().optional(),
|
|
14
|
+
extensions: z
|
|
15
|
+
.looseObject({ type: z.string().optional(), code: z.string().optional() })
|
|
16
|
+
.optional(),
|
|
17
|
+
}),
|
|
18
|
+
)
|
|
19
|
+
.optional(),
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
const errorCode = (extensions: { type?: string; code?: string } | undefined) => {
|
|
23
|
+
const kind = `${extensions?.type ?? ''} ${extensions?.code ?? ''}`.toLowerCase();
|
|
24
|
+
if (kind.includes('authentication')) return 'provider_authentication_expired';
|
|
25
|
+
if (kind.includes('forbidden')) return 'provider_access_denied';
|
|
26
|
+
return 'provider_failed';
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export const requestLinear = async (
|
|
30
|
+
{ method, token, send = fetch }: LinearClient,
|
|
31
|
+
{ query, variables = {} }: LinearRequestInput,
|
|
32
|
+
) => {
|
|
33
|
+
const headers = new Headers({
|
|
34
|
+
Accept: 'application/json',
|
|
35
|
+
Authorization: method === 'apiKey' ? token : `Bearer ${token}`,
|
|
36
|
+
});
|
|
37
|
+
const result = resultSchema.parse(
|
|
38
|
+
await requestProviderJson(
|
|
39
|
+
send,
|
|
40
|
+
providerRequest(
|
|
41
|
+
'https://api.linear.app',
|
|
42
|
+
{ path: '/graphql', body: { query, variables } },
|
|
43
|
+
headers,
|
|
44
|
+
),
|
|
45
|
+
{ readableStatuses: [400] },
|
|
46
|
+
),
|
|
47
|
+
);
|
|
48
|
+
const [error] = result.errors ?? [];
|
|
49
|
+
if (error) throw new ProviderError(errorCode(error.extensions));
|
|
50
|
+
return result.data;
|
|
51
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ProviderDefinition } from '../../contracts';
|
|
2
|
+
|
|
3
|
+
export const museProvider: ProviderDefinition = {
|
|
4
|
+
key: 'muse',
|
|
5
|
+
name: 'Muse subscription',
|
|
6
|
+
documentationUrl: 'https://dev.meta.ai/docs/muse-code/auth',
|
|
7
|
+
authMethods: ['bearer'],
|
|
8
|
+
subscription: true,
|
|
9
|
+
operations: [
|
|
10
|
+
{
|
|
11
|
+
key: 'subscription.use',
|
|
12
|
+
name: 'Run Muse Code on this login',
|
|
13
|
+
resourceKind: 'subscription',
|
|
14
|
+
requiredScopes: [],
|
|
15
|
+
},
|
|
16
|
+
],
|
|
17
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { OperationHandler } from '../../operationHandler';
|
|
3
|
+
import { objectSchema } from '../../utils/objectSchema';
|
|
4
|
+
import { select } from '../../utils/select';
|
|
5
|
+
|
|
6
|
+
export const notionOperationHandler: OperationHandler = {
|
|
7
|
+
request: ({ context, id, limit, headers }) => {
|
|
8
|
+
headers.set('Notion-Version', '2026-03-11');
|
|
9
|
+
const url = new URL(
|
|
10
|
+
context.operation === 'pages.read'
|
|
11
|
+
? `https://api.notion.com/v1/pages/${id}`
|
|
12
|
+
: `https://api.notion.com/v1/blocks/${id}/children`,
|
|
13
|
+
);
|
|
14
|
+
if (context.operation === 'blocks.read') url.searchParams.set('page_size', String(limit));
|
|
15
|
+
return { url };
|
|
16
|
+
},
|
|
17
|
+
parse: (body, context) => {
|
|
18
|
+
const data = objectSchema.parse(body);
|
|
19
|
+
return context.operation === 'pages.read'
|
|
20
|
+
? select(data, ['id', 'properties', 'created_time', 'last_edited_time', 'archived'])
|
|
21
|
+
: {
|
|
22
|
+
blocks: z
|
|
23
|
+
.array(z.unknown())
|
|
24
|
+
.parse(data.results)
|
|
25
|
+
.map((item) => {
|
|
26
|
+
const block = objectSchema.parse(item);
|
|
27
|
+
return select(block, ['id', 'type', 'has_children', String(block.type)]);
|
|
28
|
+
}),
|
|
29
|
+
hasMore: data.has_more === true,
|
|
30
|
+
};
|
|
31
|
+
},
|
|
32
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ProviderDefinition } from '../../contracts';
|
|
2
|
+
|
|
3
|
+
export const notionProvider: ProviderDefinition = {
|
|
4
|
+
key: 'notion',
|
|
5
|
+
name: 'Notion',
|
|
6
|
+
documentationUrl: 'https://developers.notion.com/reference/get-block-children',
|
|
7
|
+
authMethods: ['bearer', 'oauth2'],
|
|
8
|
+
operations: [
|
|
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
|
+
],
|
|
22
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ProviderDefinition } from '../../contracts';
|
|
2
|
+
|
|
3
|
+
export const openaiProvider: ProviderDefinition = {
|
|
4
|
+
key: 'openai',
|
|
5
|
+
name: 'OpenAI',
|
|
6
|
+
documentationUrl: 'https://developers.openai.com/api/reference/resources/responses',
|
|
7
|
+
authMethods: ['apiKey', 'bearer'],
|
|
8
|
+
operations: [
|
|
9
|
+
{
|
|
10
|
+
key: 'inference.create',
|
|
11
|
+
name: 'Run inference',
|
|
12
|
+
resourceKind: 'model',
|
|
13
|
+
requiredScopes: ['inference'],
|
|
14
|
+
},
|
|
15
|
+
],
|
|
16
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ProviderDefinition } from '../../contracts';
|
|
2
|
+
|
|
3
|
+
export const oracleProvider: ProviderDefinition = {
|
|
4
|
+
key: 'oracle',
|
|
5
|
+
name: 'Oracle',
|
|
6
|
+
documentationUrl: 'https://github.com/inixiative/oracle',
|
|
7
|
+
authMethods: [],
|
|
8
|
+
inbound: true,
|
|
9
|
+
operations: [],
|
|
10
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ProviderDefinition } from '../../contracts';
|
|
2
|
+
|
|
3
|
+
export const railwayProvider: ProviderDefinition = {
|
|
4
|
+
key: 'railway',
|
|
5
|
+
name: 'Railway',
|
|
6
|
+
documentationUrl: 'https://docs.railway.com/integrations/api',
|
|
7
|
+
authMethods: ['bearer'],
|
|
8
|
+
operations: [],
|
|
9
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ProviderDefinition } from '../../contracts';
|
|
2
|
+
|
|
3
|
+
export const renderProvider: ProviderDefinition = {
|
|
4
|
+
key: 'render',
|
|
5
|
+
name: 'Render',
|
|
6
|
+
documentationUrl: 'https://api-docs.render.com/reference/introduction',
|
|
7
|
+
authMethods: ['bearer'],
|
|
8
|
+
operations: [],
|
|
9
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { ProviderClient } from '../../../utils/providerClient';
|
|
3
|
+
import { requestSlack } from '../requestSlack';
|
|
4
|
+
|
|
5
|
+
const identitySchema = z.object({ team_id: z.string().min(1), user_id: z.string().min(1) });
|
|
6
|
+
|
|
7
|
+
export const fetchSlackIdentity = async (client: ProviderClient) => {
|
|
8
|
+
const identity = identitySchema.parse(await requestSlack(client, { path: 'auth.test' }));
|
|
9
|
+
return { teamId: identity.team_id, userId: identity.user_id };
|
|
10
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
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 type { SlackEventEnvelope } from './slackEventEnvelope';
|
|
6
|
+
|
|
7
|
+
const excerptLength = 500;
|
|
8
|
+
|
|
9
|
+
const postedSubtypes = ['thread_broadcast', 'file_share'];
|
|
10
|
+
|
|
11
|
+
const messageSchema = z.object({
|
|
12
|
+
type: z.enum(['message', 'app_mention']),
|
|
13
|
+
subtype: z.string().optional(),
|
|
14
|
+
channel: z.string().min(1),
|
|
15
|
+
channel_type: z.string().optional(),
|
|
16
|
+
user: z.string().min(1),
|
|
17
|
+
text: z.string().default(''),
|
|
18
|
+
ts: z.string().min(1),
|
|
19
|
+
thread_ts: z.string().optional(),
|
|
20
|
+
});
|
|
21
|
+
type SlackMessage = z.infer<typeof messageSchema>;
|
|
22
|
+
|
|
23
|
+
const mentionPattern = /<@([UW][A-Z0-9]+)(?:\|[^>]*)?>/g;
|
|
24
|
+
|
|
25
|
+
const slackMentions = (text: string) => [
|
|
26
|
+
...new Set([...text.matchAll(mentionPattern)].map((match) => match[1]!)),
|
|
27
|
+
];
|
|
28
|
+
|
|
29
|
+
const typeOf = (message: SlackMessage) => {
|
|
30
|
+
if (message.type === 'app_mention') return 'app_mention';
|
|
31
|
+
if (message.channel_type === 'im') return 'message.im';
|
|
32
|
+
if (message.channel_type === 'channel') return 'message.channels';
|
|
33
|
+
return null;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export const normalizeSlackEvent = (input: {
|
|
37
|
+
integrationId: string;
|
|
38
|
+
provider: string;
|
|
39
|
+
envelope: SlackEventEnvelope;
|
|
40
|
+
body: unknown;
|
|
41
|
+
}): ProviderEvent | null => {
|
|
42
|
+
const parsed = messageSchema.safeParse(input.envelope.event);
|
|
43
|
+
if (!parsed.success) return null;
|
|
44
|
+
const message = parsed.data;
|
|
45
|
+
if (message.subtype && !postedSubtypes.includes(message.subtype)) return null;
|
|
46
|
+
const type = typeOf(message);
|
|
47
|
+
if (!type) return null;
|
|
48
|
+
const event = providerEventSchema.safeParse({
|
|
49
|
+
eventId: input.envelope.event_id,
|
|
50
|
+
integrationId: input.integrationId,
|
|
51
|
+
provider: input.provider,
|
|
52
|
+
type,
|
|
53
|
+
at: new Date(input.envelope.event_time * 1000).toISOString(),
|
|
54
|
+
actor: { login: message.user, id: message.user },
|
|
55
|
+
scope: message.channel,
|
|
56
|
+
mentions: slackMentions(message.text),
|
|
57
|
+
assignees: [],
|
|
58
|
+
requestedReviewers: [],
|
|
59
|
+
subject: {},
|
|
60
|
+
...(message.text ? { excerpt: message.text.slice(0, excerptLength) } : {}),
|
|
61
|
+
payload: input.body,
|
|
62
|
+
});
|
|
63
|
+
return event.success ? event.data : null;
|
|
64
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const slackAccountIdOf = (teamId: string, userId: string) => `${teamId}:${userId}`;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
const slackAuthorizationSchema = z.object({
|
|
4
|
+
team_id: z.string().nullish(),
|
|
5
|
+
user_id: z.string().nullish(),
|
|
6
|
+
is_bot: z.boolean().optional(),
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
export const slackEventEnvelopeSchema = z.object({
|
|
10
|
+
type: z.literal('event_callback'),
|
|
11
|
+
team_id: z.string().min(1),
|
|
12
|
+
event_id: z.string().min(1),
|
|
13
|
+
event_time: z.number().int(),
|
|
14
|
+
authorizations: z.array(slackAuthorizationSchema).default([]),
|
|
15
|
+
event: z.looseObject({ type: z.string().min(1) }),
|
|
16
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const slackTeamPrefix = (teamId: string) => `${teamId}:`;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
export const slackTokensRevokedSchema = z.object({
|
|
4
|
+
type: z.literal('event_callback'),
|
|
5
|
+
team_id: z.string().min(1),
|
|
6
|
+
event: z.object({
|
|
7
|
+
type: z.literal('tokens_revoked'),
|
|
8
|
+
tokens: z.object({
|
|
9
|
+
oauth: z.array(z.string()).default([]),
|
|
10
|
+
bot: z.array(z.string()).default([]),
|
|
11
|
+
}),
|
|
12
|
+
}),
|
|
13
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { matchesHmacSha256 } from '../../../utils/matchesHmacSha256';
|
|
2
|
+
|
|
3
|
+
const replayWindowSeconds = 5 * 60;
|
|
4
|
+
|
|
5
|
+
export const verifySlackSignature = (
|
|
6
|
+
rawBody: Uint8Array,
|
|
7
|
+
headers: Headers,
|
|
8
|
+
secret: string,
|
|
9
|
+
now = Date.now(),
|
|
10
|
+
) => {
|
|
11
|
+
const timestamp = headers.get('x-slack-request-timestamp') ?? '';
|
|
12
|
+
if (!/^\d{1,12}$/.test(timestamp)) return false;
|
|
13
|
+
if (Math.abs(now / 1000 - Number(timestamp)) > replayWindowSeconds) return false;
|
|
14
|
+
const signature = /^v0=([a-f0-9]{64})$/.exec(headers.get('x-slack-signature') ?? '')?.[1];
|
|
15
|
+
const basestring = Buffer.concat([Buffer.from(`v0:${timestamp}:`), rawBody]);
|
|
16
|
+
return matchesHmacSha256(basestring, signature, secret);
|
|
17
|
+
};
|
|
@@ -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 { requestSlack } from './requestSlack';
|
|
6
|
+
import { slackPagination } from './slackPagination';
|
|
7
|
+
|
|
8
|
+
export const fetchAllSlackPages = (
|
|
9
|
+
client: ProviderClient,
|
|
10
|
+
input: ProviderRequestInput,
|
|
11
|
+
options?: ProviderPagesOptions,
|
|
12
|
+
) => fetchAllRequestPages(slackPagination, (page) => requestSlack(client, page), input, options);
|