@inixiative/integrations 0.0.0-stage → 0.2.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.
Files changed (214) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +50 -2
  3. package/package.json +56 -4
  4. package/src/catalog/declaredOperations.ts +9 -0
  5. package/src/catalog/eventLeaves.ts +5 -0
  6. package/src/catalog/familyProducts.ts +5 -0
  7. package/src/catalog/findProvider.ts +5 -0
  8. package/src/catalog/integrationEventResource.ts +20 -0
  9. package/src/catalog/integrationKeyedKinds.ts +4 -0
  10. package/src/catalog/isAccountSuppliedByHost.ts +6 -0
  11. package/src/catalog/isEventLeaf.ts +1 -0
  12. package/src/catalog/isFamilyManaged.ts +7 -0
  13. package/src/catalog/isUncalledLeaf.ts +6 -0
  14. package/src/catalog/operationLeaves.ts +6 -0
  15. package/src/catalog/providerEvent.ts +3 -0
  16. package/src/catalog/providerEventSchema.ts +3 -0
  17. package/src/catalog/providerFamily.ts +4 -0
  18. package/src/catalog/providerHasEvents.ts +8 -0
  19. package/src/catalog/providerModel.ts +12 -0
  20. package/src/catalog/providers.ts +54 -0
  21. package/src/contracts.ts +107 -0
  22. package/src/credentials/codexClientId.ts +2 -0
  23. package/src/credentials/codexTokenUrl.ts +1 -0
  24. package/src/credentials/consentReason.ts +4 -0
  25. package/src/credentials/consentReasonSchema.ts +21 -0
  26. package/src/credentials/credentialClient.ts +4 -0
  27. package/src/credentials/exchangeOauthCode.ts +61 -0
  28. package/src/credentials/fetchRenewalResponse.ts +41 -0
  29. package/src/credentials/mintProviderCredential.ts +68 -0
  30. package/src/credentials/providerExchangeTimeoutMs.ts +1 -0
  31. package/src/credentials/refreshProviderCredential.ts +172 -0
  32. package/src/credentials/renewalRequest.ts +1 -0
  33. package/src/credentials/subscriptionAccountId.ts +12 -0
  34. package/src/credentials/validateCredentialSecret.ts +18 -0
  35. package/src/index.ts +3 -0
  36. package/src/operations/buildProviderRequest.ts +54 -0
  37. package/src/operations/executeProvider.ts +26 -0
  38. package/src/operations/findOperationHandler.ts +6 -0
  39. package/src/operations/operationHandler.ts +8 -0
  40. package/src/operations/operationHandlers.ts +41 -0
  41. package/src/operations/operationRequestInput.ts +12 -0
  42. package/src/operations/providerRequestSpec.ts +1 -0
  43. package/src/providers/anthropic/anthropicProvider.ts +16 -0
  44. package/src/providers/archive/archiveCandidate.ts +1 -0
  45. package/src/providers/archive/archiveConfigurationSchema.ts +3 -0
  46. package/src/providers/archive/archiveProvider.ts +21 -0
  47. package/src/providers/archive/isLocalArchive.ts +5 -0
  48. package/src/providers/archive/localArchiveConfigurationSchema.ts +5 -0
  49. package/src/providers/archive/localArchiveSourceId.ts +8 -0
  50. package/src/providers/chorus/chorusProvider.ts +22 -0
  51. package/src/providers/claude/claudeProvider.ts +17 -0
  52. package/src/providers/codex/codexProvider.ts +17 -0
  53. package/src/providers/confluence/confluenceOperationHandler.ts +14 -0
  54. package/src/providers/confluence/confluenceProvider.ts +16 -0
  55. package/src/providers/discord/discordOperationHandler.ts +30 -0
  56. package/src/providers/discord/discordProvider.ts +22 -0
  57. package/src/providers/drive/driveOperationHandler.ts +21 -0
  58. package/src/providers/drive/driveProvider.ts +18 -0
  59. package/src/providers/foundry/foundryProvider.ts +33 -0
  60. package/src/providers/geminiApi/geminiApiProvider.ts +16 -0
  61. package/src/providers/github/auth/fetchGithubAppInstallation.ts +21 -0
  62. package/src/providers/github/auth/fetchGithubOrganizationRole.ts +27 -0
  63. package/src/providers/github/auth/fetchGithubUser.ts +11 -0
  64. package/src/providers/github/auth/fetchGithubUserInstallation.ts +21 -0
  65. package/src/providers/github/auth/githubAppClient.ts +4 -0
  66. package/src/providers/github/auth/githubAppInstallUrl.ts +20 -0
  67. package/src/providers/github/auth/githubAppJwt.ts +16 -0
  68. package/src/providers/github/auth/githubClientForApp.ts +11 -0
  69. package/src/providers/github/auth/githubInstallation.ts +4 -0
  70. package/src/providers/github/auth/githubInstallationAccountId.ts +4 -0
  71. package/src/providers/github/auth/githubInstallationFromAccountId.ts +4 -0
  72. package/src/providers/github/auth/githubInstallationSchema.ts +12 -0
  73. package/src/providers/github/auth/githubPermissionCovers.ts +14 -0
  74. package/src/providers/github/auth/githubPermissionScopes.ts +4 -0
  75. package/src/providers/github/auth/githubProviderForOwner.ts +6 -0
  76. package/src/providers/github/auth/githubUserAuthorizeUrl.ts +10 -0
  77. package/src/providers/github/events/githubEventRepositoryId.ts +10 -0
  78. package/src/providers/github/events/githubNotification.ts +4 -0
  79. package/src/providers/github/events/githubNotificationSchema.ts +9 -0
  80. package/src/providers/github/events/listGithubNotifications.ts +27 -0
  81. package/src/providers/github/events/normalizeGithubEvent.ts +200 -0
  82. package/src/providers/github/events/normalizeGithubNotification.ts +56 -0
  83. package/src/providers/github/events/verifyGithubSignature.ts +7 -0
  84. package/src/providers/github/fetchAllGithubPages.ts +12 -0
  85. package/src/providers/github/githubApiVersion.ts +1 -0
  86. package/src/providers/github/githubOrganizationProvider.ts +13 -0
  87. package/src/providers/github/githubPagination.ts +7 -0
  88. package/src/providers/github/githubProvider.ts +13 -0
  89. package/src/providers/github/githubRequestHeaders.ts +9 -0
  90. package/src/providers/github/githubUserProvider.ts +13 -0
  91. package/src/providers/github/iterateGithubPages.ts +12 -0
  92. package/src/providers/github/models/account/githubAccount.ts +17 -0
  93. package/src/providers/github/models/repository/githubOperationHandler.ts +36 -0
  94. package/src/providers/github/models/repository/githubRepository.ts +40 -0
  95. package/src/providers/github/models/repository/githubRepositoryIdSchema.ts +3 -0
  96. package/src/providers/github/models/repository/githubRepositoryMetadataSchema.ts +6 -0
  97. package/src/providers/github/models/repository/githubRepositoryName.ts +4 -0
  98. package/src/providers/github/models/repository/githubRepositoryNameSchema.ts +9 -0
  99. package/src/providers/github/models/repository/githubTreeEntryModeSchema.ts +3 -0
  100. package/src/providers/github/models/repository/githubTreeEntryTypeForMode.ts +14 -0
  101. package/src/providers/github/models/repository/githubTreeEntryTypeSchema.ts +3 -0
  102. package/src/providers/github/models/repository/listInstallationRepositories.ts +31 -0
  103. package/src/providers/github/models/repository/listUserRepositories.ts +36 -0
  104. package/src/providers/github/models/repository/readGithubObject.ts +85 -0
  105. package/src/providers/github/models/repository/readGithubRepositoryName.ts +4 -0
  106. package/src/providers/github/requestGithub.ts +18 -0
  107. package/src/providers/gmail/buildGmailMessageRequest.ts +22 -0
  108. package/src/providers/gmail/fetchGmailMessages.ts +81 -0
  109. package/src/providers/gmail/gmailOperationHandler.ts +12 -0
  110. package/src/providers/gmail/gmailProvider.ts +19 -0
  111. package/src/providers/google/auth/buildGoogleAuthorizationUrl.ts +33 -0
  112. package/src/providers/google/auth/verifyGoogleIdToken.ts +22 -0
  113. package/src/providers/google/googleProvider.ts +13 -0
  114. package/src/providers/jira/jiraOperationHandler.ts +14 -0
  115. package/src/providers/jira/jiraProvider.ts +16 -0
  116. package/src/providers/linear/auth/linearIntegrationSecret.ts +6 -0
  117. package/src/providers/linear/events/createLinearWebhook.ts +30 -0
  118. package/src/providers/linear/events/deleteLinearWebhook.ts +13 -0
  119. package/src/providers/linear/events/linearUserSchema.ts +3 -0
  120. package/src/providers/linear/events/linearWebhook.ts +3 -0
  121. package/src/providers/linear/events/linearWebhookPayload.ts +4 -0
  122. package/src/providers/linear/events/linearWebhookPayloadSchema.ts +13 -0
  123. package/src/providers/linear/events/listLinearWebhooks.ts +44 -0
  124. package/src/providers/linear/events/normalizeLinearEvent.ts +127 -0
  125. package/src/providers/linear/events/repairLinearWebhook.ts +17 -0
  126. package/src/providers/linear/events/verifyLinearSignature.ts +25 -0
  127. package/src/providers/linear/fetchAllLinearPages.ts +40 -0
  128. package/src/providers/linear/linearClient.ts +5 -0
  129. package/src/providers/linear/linearPagination.ts +13 -0
  130. package/src/providers/linear/linearProvider.ts +12 -0
  131. package/src/providers/linear/linearRequestInput.ts +1 -0
  132. package/src/providers/linear/models/issue/linearIssue.ts +11 -0
  133. package/src/providers/linear/models/issue/linearOperationHandler.ts +30 -0
  134. package/src/providers/linear/models/team/fetchLinearWorkspace.ts +30 -0
  135. package/src/providers/linear/models/team/linearTeam.ts +18 -0
  136. package/src/providers/linear/requestLinear.ts +51 -0
  137. package/src/providers/muse/museProvider.ts +17 -0
  138. package/src/providers/notion/notionOperationHandler.ts +32 -0
  139. package/src/providers/notion/notionProvider.ts +22 -0
  140. package/src/providers/openai/openaiProvider.ts +16 -0
  141. package/src/providers/oracle/oracleProvider.ts +10 -0
  142. package/src/providers/railway/railwayProvider.ts +9 -0
  143. package/src/providers/render/renderProvider.ts +9 -0
  144. package/src/providers/slack/auth/fetchSlackIdentity.ts +10 -0
  145. package/src/providers/slack/events/normalizeSlackEvent.ts +64 -0
  146. package/src/providers/slack/events/slackAccountIdOf.ts +1 -0
  147. package/src/providers/slack/events/slackEventEnvelope.ts +4 -0
  148. package/src/providers/slack/events/slackEventEnvelopeSchema.ts +16 -0
  149. package/src/providers/slack/events/slackTeamPrefix.ts +1 -0
  150. package/src/providers/slack/events/slackTokensRevokedSchema.ts +13 -0
  151. package/src/providers/slack/events/slackUserOfAccountId.ts +2 -0
  152. package/src/providers/slack/events/verifySlackSignature.ts +17 -0
  153. package/src/providers/slack/fetchAllSlackPages.ts +12 -0
  154. package/src/providers/slack/models/account/slackAccount.ts +13 -0
  155. package/src/providers/slack/models/channel/listSlackChannels.ts +26 -0
  156. package/src/providers/slack/models/channel/slackChannel.ts +31 -0
  157. package/src/providers/slack/models/channel/slackOperationHandler.ts +30 -0
  158. package/src/providers/slack/requestSlack.ts +22 -0
  159. package/src/providers/slack/slackPagination.ts +12 -0
  160. package/src/providers/slack/slackProvider.ts +12 -0
  161. package/src/providers/slack/slackProviderError.ts +12 -0
  162. package/src/providers/teams/teamsOperationHandler.ts +24 -0
  163. package/src/providers/teams/teamsProvider.ts +17 -0
  164. package/src/resources/integrationConfigurationSchemas.ts +11 -0
  165. package/src/resources/perProvider.ts +20 -0
  166. package/src/resources/resourceExternalIdSchema.ts +4 -0
  167. package/src/resources/resourceExternalIdSchemas.ts +18 -0
  168. package/src/resources/resourceMetadataSchema.ts +4 -0
  169. package/src/resources/resourceMetadataSchemas.ts +9 -0
  170. package/src/utils/capacityWindowSchema.ts +7 -0
  171. package/src/utils/headerNumber.ts +6 -0
  172. package/src/utils/jwtClaims.ts +14 -0
  173. package/src/utils/matchesHmacSha256.ts +11 -0
  174. package/src/utils/objectSchema.ts +3 -0
  175. package/src/utils/pagination/applyCaps.ts +18 -0
  176. package/src/utils/pagination/byCursorKeys.ts +7 -0
  177. package/src/utils/pagination/byCursorOptions.ts +7 -0
  178. package/src/utils/pagination/byPageKeys.ts +7 -0
  179. package/src/utils/pagination/byPageOptions.ts +8 -0
  180. package/src/utils/pagination/collectPages.ts +27 -0
  181. package/src/utils/pagination/compactRequest.ts +4 -0
  182. package/src/utils/pagination/fetchAllByCursor.ts +6 -0
  183. package/src/utils/pagination/fetchAllByPage.ts +6 -0
  184. package/src/utils/pagination/fetchAllRequestPages.ts +16 -0
  185. package/src/utils/pagination/incompletePageWalkError.ts +8 -0
  186. package/src/utils/pagination/isAnotherPage.ts +20 -0
  187. package/src/utils/pagination/iterateByCursor.ts +49 -0
  188. package/src/utils/pagination/iterateByPage.ts +59 -0
  189. package/src/utils/pagination/iterateProviderPages.ts +27 -0
  190. package/src/utils/pagination/iterateRequestPages.ts +18 -0
  191. package/src/utils/pagination/pageWalkError.ts +6 -0
  192. package/src/utils/pagination/paginationOptions.ts +9 -0
  193. package/src/utils/pagination/providerPagesOptions.ts +8 -0
  194. package/src/utils/pagination/providerPagination.ts +6 -0
  195. package/src/utils/pagination/readPage.ts +29 -0
  196. package/src/utils/pagination/readPath.ts +12 -0
  197. package/src/utils/pagination/repeatedCursorError.ts +10 -0
  198. package/src/utils/providerClient.ts +3 -0
  199. package/src/utils/providerCooldown.ts +23 -0
  200. package/src/utils/providerCooldownState.ts +4 -0
  201. package/src/utils/providerError.ts +10 -0
  202. package/src/utils/providerReading.ts +4 -0
  203. package/src/utils/providerReadingSchema.ts +8 -0
  204. package/src/utils/providerRequest.ts +22 -0
  205. package/src/utils/providerRequestInput.ts +7 -0
  206. package/src/utils/providerResponseLimit.ts +1 -0
  207. package/src/utils/providerSend.ts +1 -0
  208. package/src/utils/readProviderJson.ts +38 -0
  209. package/src/utils/readProviderLimits.ts +66 -0
  210. package/src/utils/readRateLimit.ts +29 -0
  211. package/src/utils/requestProviderJson.ts +13 -0
  212. package/src/utils/responseBudget.ts +1 -0
  213. package/src/utils/select.ts +6 -0
  214. package/src/utils/sendProviderRequest.ts +33 -0
@@ -0,0 +1,13 @@
1
+ import { z } from 'zod';
2
+ import type { LinearClient } from '../linearClient';
3
+ import { requestLinear } from '../requestLinear';
4
+
5
+ const deletedSchema = z.object({ webhookDelete: z.object({ success: z.boolean() }) });
6
+
7
+ export const deleteLinearWebhook = async (client: LinearClient, { id }: { id: string }) =>
8
+ deletedSchema.parse(
9
+ await requestLinear(client, {
10
+ query: 'mutation WebhookDelete($id: String!) { webhookDelete(id: $id) { success } }',
11
+ variables: { id },
12
+ }),
13
+ ).webhookDelete.success;
@@ -0,0 +1,3 @@
1
+ import { z } from 'zod';
2
+
3
+ export const linearUserSchema = z.object({ id: z.string().min(1), url: z.string().optional() });
@@ -0,0 +1,3 @@
1
+ import type { listLinearWebhooks } from './listLinearWebhooks';
2
+
3
+ export type LinearWebhook = Awaited<ReturnType<typeof listLinearWebhooks>>[number];
@@ -0,0 +1,4 @@
1
+ import type { z } from 'zod';
2
+ import type { linearWebhookPayloadSchema } from './linearWebhookPayloadSchema';
3
+
4
+ export type LinearWebhookPayload = z.infer<typeof linearWebhookPayloadSchema>;
@@ -0,0 +1,13 @@
1
+ import { z } from 'zod';
2
+ import { linearUserSchema } from './linearUserSchema';
3
+
4
+ export const linearWebhookPayloadSchema = z.object({
5
+ action: z.string().min(1),
6
+ type: z.string().min(1),
7
+ organizationId: z.string().min(1),
8
+ createdAt: z.string().min(1),
9
+ url: z.string().nullish(),
10
+ actor: linearUserSchema.nullish(),
11
+ updatedFrom: z.record(z.string(), z.unknown()).nullish(),
12
+ data: z.looseObject({}),
13
+ });
@@ -0,0 +1,44 @@
1
+ import { z } from 'zod';
2
+ import { ProviderError } from '../../../utils/providerError';
3
+ import { fetchAllLinearPages } from '../fetchAllLinearPages';
4
+ import type { LinearClient } from '../linearClient';
5
+
6
+ const webhooksSchema = z.array(
7
+ z.object({
8
+ id: z.string(),
9
+ url: z.string().nullish(),
10
+ allPublicTeams: z.boolean(),
11
+ enabled: z.boolean(),
12
+ secret: z.string().nullish(),
13
+ resourceTypes: z.array(z.string()),
14
+ team: z.object({ id: z.string() }).nullish(),
15
+ }),
16
+ );
17
+
18
+ const webhooksQuery =
19
+ 'query Webhooks($first: Int, $after: String) { webhooks(first: $first, after: $after) { pageInfo { hasNextPage endCursor } nodes { id url allPublicTeams enabled secret resourceTypes team { id } } } }';
20
+
21
+ export const listLinearWebhooks = async (client: LinearClient) => {
22
+ const webhooks = webhooksSchema.parse(
23
+ await fetchAllLinearPages(
24
+ client,
25
+ { query: webhooksQuery },
26
+ {
27
+ connection: 'webhooks',
28
+ maxPages: 40,
29
+ onCapped: () => {
30
+ throw new ProviderError('provider_invalid_response');
31
+ },
32
+ },
33
+ ),
34
+ );
35
+ return webhooks.map((webhook) => ({
36
+ id: webhook.id,
37
+ url: webhook.url ?? null,
38
+ allPublicTeams: webhook.allPublicTeams,
39
+ enabled: webhook.enabled,
40
+ secret: webhook.secret ?? null,
41
+ resourceTypes: webhook.resourceTypes,
42
+ teamId: webhook.team?.id ?? null,
43
+ }));
44
+ };
@@ -0,0 +1,127 @@
1
+ import type { IntegrationEvent } from '@inixiative/signet/contracts';
2
+ import { z } from 'zod';
3
+ import type { ProviderEvent } from '../../../catalog/providerEvent';
4
+ import { providerEventSchema } from '../../../catalog/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,5 @@
1
+ import type { z } from 'zod';
2
+ import type { credentialMethodSchema } from '../../contracts';
3
+ import type { ProviderClient } from '../../utils/providerClient';
4
+
5
+ export type LinearClient = ProviderClient & { method: z.infer<typeof credentialMethodSchema> };
@@ -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,12 @@
1
+ import type { ProviderDefinition } from '../../contracts';
2
+ import { linearIssue } from './models/issue/linearIssue';
3
+ import { linearTeam } from './models/team/linearTeam';
4
+
5
+ export const linearProvider: ProviderDefinition = {
6
+ key: 'linear',
7
+ name: 'Linear',
8
+ documentationUrl: 'https://linear.app/developers/graphql',
9
+ authMethods: ['apiKey', 'bearer', 'oauth2'],
10
+ operations: [...linearIssue.operations, ...linearTeam.events],
11
+ syncedResourceKinds: [linearTeam.kind],
12
+ };
@@ -0,0 +1 @@
1
+ export type LinearRequestInput = { query: string; variables?: Record<string, unknown> };
@@ -0,0 +1,11 @@
1
+ import type { ProviderModel } from '../../../../catalog/providerModel';
2
+
3
+ const kind = 'issue';
4
+
5
+ export const linearIssue = {
6
+ kind,
7
+ operations: [
8
+ { key: 'issues.read', name: 'Read an issue', resourceKind: kind, requiredScopes: ['read'] },
9
+ ],
10
+ events: [],
11
+ } satisfies ProviderModel;
@@ -0,0 +1,30 @@
1
+ import type { OperationHandler } from '../../../../operations/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,18 @@
1
+ import { declaredOperations } from '../../../../catalog/declaredOperations';
2
+ import type { ProviderModel } from '../../../../catalog/providerModel';
3
+
4
+ const kind = 'team';
5
+
6
+ export const linearTeam = {
7
+ kind,
8
+ operations: [],
9
+ events: declaredOperations(
10
+ {
11
+ 'events.Issue.create': 'Receive issues created in this team',
12
+ 'events.Issue.update': 'Receive issue changes in this team',
13
+ 'events.Comment.create': "Receive comments on this team's issues",
14
+ },
15
+ kind,
16
+ ['read'],
17
+ ),
18
+ } satisfies ProviderModel;
@@ -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 '../../operations/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
+ };