@inixiative/integrations 0.2.1 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (212) hide show
  1. package/README.md +21 -13
  2. package/package.json +4 -3
  3. package/src/catalog/acceptedCredentialMethods.ts +17 -0
  4. package/src/catalog/catalogOperationMeta.ts +4 -0
  5. package/src/catalog/catalogOperations.ts +10 -0
  6. package/src/catalog/integrationFamilies.ts +12 -0
  7. package/src/catalog/integrationFamilyDefinition.ts +6 -0
  8. package/src/catalog/isAccountSuppliedByHost.ts +2 -2
  9. package/src/catalog/providerAuthenticatesThroughIntegrationFamily.ts +6 -0
  10. package/src/catalog/providerModel.ts +0 -1
  11. package/src/catalog/providers.ts +0 -4
  12. package/src/catalog/providersInIntegrationFamily.ts +5 -0
  13. package/src/contracts.ts +36 -25
  14. package/src/credentials/credentialAuth.ts +38 -0
  15. package/src/credentials/credentialClient.ts +2 -2
  16. package/src/credentials/exchangeOauthCode.ts +41 -41
  17. package/src/credentials/mintProviderCredential.ts +26 -40
  18. package/src/credentials/providerExchangeTimeoutMs.ts +1 -1
  19. package/src/credentials/refreshProviderCredential.ts +102 -83
  20. package/src/credentials/renewalError.ts +11 -0
  21. package/src/credentials/renewalOwner.ts +3 -0
  22. package/src/credentials/requestOauthToken.ts +28 -0
  23. package/src/credentials/validateCredentialSecret.ts +5 -5
  24. package/src/index.ts +0 -1
  25. package/src/integrationFamilies/atlassianIntegrationFamily.ts +12 -0
  26. package/src/{providers/github/githubProvider.ts → integrationFamilies/githubIntegrationFamily.ts} +2 -3
  27. package/src/{providers/google/googleProvider.ts → integrationFamilies/googleIntegrationFamily.ts} +2 -3
  28. package/src/integrationFamilies/inixiativeIntegrationFamily.ts +8 -0
  29. package/src/operations/providerOperationInput.ts +6 -0
  30. package/src/operations/providerOperationInputSchema.ts +36 -0
  31. package/src/operations/providerOperationOrThrow.ts +23 -0
  32. package/src/operations/providerOperationSet.ts +7 -0
  33. package/src/operations/providerOperations.ts +38 -0
  34. package/src/providers/chorus/chorusProvider.ts +1 -0
  35. package/src/providers/confluence/confluenceApiBaseUrl.ts +1 -0
  36. package/src/providers/confluence/confluenceOperations.ts +4 -0
  37. package/src/providers/confluence/confluenceProvider.ts +6 -8
  38. package/src/providers/confluence/models/page/fetchConfluencePage.ts +23 -0
  39. package/src/providers/discord/discordApiBaseUrl.ts +1 -0
  40. package/src/providers/discord/discordOperations.ts +8 -0
  41. package/src/providers/discord/discordProvider.ts +5 -14
  42. package/src/providers/discord/models/channel/discordChannelKind.ts +1 -0
  43. package/src/providers/discord/models/channel/fetchDiscordChannel.ts +25 -0
  44. package/src/providers/discord/models/channel/fetchDiscordChannelMessages.ts +37 -0
  45. package/src/providers/drive/driveApiBaseUrl.ts +1 -0
  46. package/src/providers/drive/driveOperations.ts +4 -0
  47. package/src/providers/drive/driveProvider.ts +7 -10
  48. package/src/providers/drive/models/file/fetchDriveFile.ts +27 -0
  49. package/src/providers/github/auth/createGithubInstallationToken.ts +19 -0
  50. package/src/providers/github/auth/fetchGithubAppInstallUrl.ts +21 -0
  51. package/src/providers/github/auth/fetchGithubAppInstallation.ts +16 -19
  52. package/src/providers/github/auth/fetchGithubOrganizationRole.ts +22 -22
  53. package/src/providers/github/auth/fetchGithubUser.ts +10 -4
  54. package/src/providers/github/auth/githubAppAuth.ts +6 -0
  55. package/src/providers/github/auth/githubUserAuthorizeUrl.ts +2 -2
  56. package/src/providers/github/auth/listGithubUserInstallationPage.ts +18 -0
  57. package/src/providers/github/events/listGithubNotificationPage.ts +18 -0
  58. package/src/providers/github/githubApiBaseUrl.ts +1 -0
  59. package/src/providers/github/githubOrganizationProvider.ts +6 -2
  60. package/src/providers/github/githubPagination.ts +2 -2
  61. package/src/providers/github/githubRequestHeaders.ts +4 -6
  62. package/src/providers/github/githubUserProvider.ts +7 -4
  63. package/src/providers/github/models/account/githubAccount.ts +0 -1
  64. package/src/providers/github/models/repository/fetchGithubBlob.ts +59 -0
  65. package/src/providers/github/models/repository/fetchGithubCommit.ts +38 -0
  66. package/src/providers/github/models/repository/fetchGithubTree.ts +74 -0
  67. package/src/providers/github/models/repository/githubObjectRequest.ts +15 -0
  68. package/src/providers/github/models/repository/githubRepository.ts +1 -11
  69. package/src/providers/github/models/repository/githubRepositoryOperations.ts +10 -0
  70. package/src/providers/github/models/repository/listGithubInstallationRepositoryPage.ts +18 -0
  71. package/src/providers/github/models/repository/listGithubUserInstallationRepositoryPage.ts +22 -0
  72. package/src/providers/github/models/repository/readGithubObjectIdentity.ts +9 -0
  73. package/src/providers/github/services/fetchGithubUserInstallation.ts +25 -0
  74. package/src/providers/github/services/listGithubNotifications.ts +27 -0
  75. package/src/providers/github/services/listInstallationRepositories.ts +34 -0
  76. package/src/providers/github/services/listUserRepositories.ts +43 -0
  77. package/src/providers/gmail/gmailApiBaseUrl.ts +1 -0
  78. package/src/providers/gmail/gmailOperations.ts +10 -0
  79. package/src/providers/gmail/gmailProvider.ts +8 -11
  80. package/src/providers/gmail/models/label/listGmailLabelMessages.ts +45 -0
  81. package/src/providers/gmail/models/message/fetchGmailMessage.ts +19 -0
  82. package/src/providers/gmail/models/message/fetchGmailMessageBatch.ts +20 -0
  83. package/src/providers/gmail/models/message/gmailMessageKind.ts +1 -0
  84. package/src/providers/gmail/models/message/gmailMessageRequest.ts +9 -0
  85. package/src/providers/gmail/models/message/readGmailMessage.ts +26 -0
  86. package/src/providers/google/auth/buildGoogleAuthorizationUrl.ts +2 -1
  87. package/src/providers/google/auth/verifyGoogleIdToken.ts +3 -3
  88. package/src/providers/jira/jiraApiBaseUrl.ts +1 -0
  89. package/src/providers/jira/jiraOperations.ts +4 -0
  90. package/src/providers/jira/jiraProvider.ts +6 -8
  91. package/src/providers/jira/models/issue/fetchJiraIssue.ts +22 -0
  92. package/src/providers/linear/events/createLinearWebhook.ts +29 -20
  93. package/src/providers/linear/events/deleteLinearWebhook.ts +16 -9
  94. package/src/providers/linear/events/linearWebhook.ts +1 -1
  95. package/src/providers/linear/events/listLinearWebhookPage.ts +23 -0
  96. package/src/providers/linear/events/repairLinearWebhook.ts +17 -13
  97. package/src/providers/linear/linearApiBaseUrl.ts +1 -0
  98. package/src/providers/linear/linearGraphqlErrorCode.ts +8 -0
  99. package/src/providers/linear/linearOperations.ts +4 -0
  100. package/src/providers/linear/linearPagination.ts +3 -9
  101. package/src/providers/linear/linearProvider.ts +5 -2
  102. package/src/providers/linear/models/issue/fetchLinearIssue.ts +32 -0
  103. package/src/providers/linear/models/team/fetchLinearWorkspace.ts +23 -13
  104. package/src/providers/linear/models/team/linearTeam.ts +0 -1
  105. package/src/providers/linear/services/listLinearWebhooks.ts +45 -0
  106. package/src/providers/notion/models/page/fetchNotionPage.ts +32 -0
  107. package/src/providers/notion/models/page/fetchNotionPageBlocks.ts +39 -0
  108. package/src/providers/notion/models/page/notionPageKind.ts +1 -0
  109. package/src/providers/notion/notionApiBaseUrl.ts +1 -0
  110. package/src/providers/notion/notionOperations.ts +8 -0
  111. package/src/providers/notion/notionProvider.ts +5 -14
  112. package/src/providers/notion/notionVersion.ts +1 -0
  113. package/src/providers/oracle/oracleProvider.ts +1 -0
  114. package/src/providers/slack/auth/fetchSlackIdentity.ts +14 -6
  115. package/src/providers/slack/models/account/slackAccount.ts +0 -1
  116. package/src/providers/slack/models/channel/fetchSlackChannel.ts +32 -0
  117. package/src/providers/slack/models/channel/fetchSlackChannelMessages.ts +34 -0
  118. package/src/providers/slack/models/channel/listSlackUserConversations.ts +19 -0
  119. package/src/providers/slack/models/channel/slackChannel.ts +0 -14
  120. package/src/providers/slack/readSlackBody.ts +10 -0
  121. package/src/providers/slack/services/listSlackChannels.ts +23 -0
  122. package/src/providers/slack/slackApiBaseUrl.ts +1 -0
  123. package/src/providers/slack/slackOperations.ts +8 -0
  124. package/src/providers/slack/slackPagination.ts +2 -2
  125. package/src/providers/slack/slackProvider.ts +9 -1
  126. package/src/providers/slack/slackProviderError.ts +2 -2
  127. package/src/providers/teams/models/channel/fetchTeamsChannelMessages.ts +36 -0
  128. package/src/providers/teams/teamsApiBaseUrl.ts +1 -0
  129. package/src/providers/teams/teamsOperations.ts +6 -0
  130. package/src/providers/teams/teamsProvider.ts +5 -8
  131. package/src/utils/acceptJsonHeaders.ts +1 -0
  132. package/src/utils/pageQuerySchema.ts +13 -0
  133. package/src/utils/readProviderLimits.ts +1 -2
  134. package/src/catalog/familyProducts.ts +0 -5
  135. package/src/catalog/isFamilyManaged.ts +0 -7
  136. package/src/catalog/providerFamily.ts +0 -4
  137. package/src/credentials/fetchRenewalResponse.ts +0 -41
  138. package/src/credentials/renewalRequest.ts +0 -1
  139. package/src/operations/buildProviderRequest.ts +0 -54
  140. package/src/operations/executeProvider.ts +0 -26
  141. package/src/operations/findOperationHandler.ts +0 -6
  142. package/src/operations/operationHandler.ts +0 -8
  143. package/src/operations/operationHandlers.ts +0 -41
  144. package/src/operations/operationRequestInput.ts +0 -12
  145. package/src/operations/providerRequestSpec.ts +0 -1
  146. package/src/providers/confluence/confluenceOperationHandler.ts +0 -14
  147. package/src/providers/discord/discordOperationHandler.ts +0 -30
  148. package/src/providers/drive/driveOperationHandler.ts +0 -21
  149. package/src/providers/github/auth/fetchGithubUserInstallation.ts +0 -21
  150. package/src/providers/github/auth/githubAppClient.ts +0 -4
  151. package/src/providers/github/auth/githubAppInstallUrl.ts +0 -20
  152. package/src/providers/github/auth/githubClientForApp.ts +0 -11
  153. package/src/providers/github/events/listGithubNotifications.ts +0 -27
  154. package/src/providers/github/fetchAllGithubPages.ts +0 -12
  155. package/src/providers/github/iterateGithubPages.ts +0 -12
  156. package/src/providers/github/models/repository/githubOperationHandler.ts +0 -36
  157. package/src/providers/github/models/repository/listInstallationRepositories.ts +0 -31
  158. package/src/providers/github/models/repository/listUserRepositories.ts +0 -36
  159. package/src/providers/github/models/repository/readGithubObject.ts +0 -85
  160. package/src/providers/github/requestGithub.ts +0 -18
  161. package/src/providers/gmail/buildGmailMessageRequest.ts +0 -22
  162. package/src/providers/gmail/fetchGmailMessages.ts +0 -81
  163. package/src/providers/gmail/gmailOperationHandler.ts +0 -12
  164. package/src/providers/jira/jiraOperationHandler.ts +0 -14
  165. package/src/providers/linear/events/listLinearWebhooks.ts +0 -44
  166. package/src/providers/linear/fetchAllLinearPages.ts +0 -40
  167. package/src/providers/linear/linearClient.ts +0 -5
  168. package/src/providers/linear/linearRequestInput.ts +0 -1
  169. package/src/providers/linear/models/issue/linearIssue.ts +0 -11
  170. package/src/providers/linear/models/issue/linearOperationHandler.ts +0 -30
  171. package/src/providers/linear/requestLinear.ts +0 -51
  172. package/src/providers/notion/notionOperationHandler.ts +0 -32
  173. package/src/providers/slack/fetchAllSlackPages.ts +0 -12
  174. package/src/providers/slack/models/channel/listSlackChannels.ts +0 -26
  175. package/src/providers/slack/models/channel/slackOperationHandler.ts +0 -30
  176. package/src/providers/slack/requestSlack.ts +0 -22
  177. package/src/providers/teams/teamsOperationHandler.ts +0 -24
  178. package/src/utils/headerNumber.ts +0 -6
  179. package/src/utils/pagination/applyCaps.ts +0 -18
  180. package/src/utils/pagination/byCursorKeys.ts +0 -7
  181. package/src/utils/pagination/byCursorOptions.ts +0 -7
  182. package/src/utils/pagination/byPageKeys.ts +0 -7
  183. package/src/utils/pagination/byPageOptions.ts +0 -8
  184. package/src/utils/pagination/collectPages.ts +0 -27
  185. package/src/utils/pagination/compactRequest.ts +0 -4
  186. package/src/utils/pagination/fetchAllByCursor.ts +0 -6
  187. package/src/utils/pagination/fetchAllByPage.ts +0 -6
  188. package/src/utils/pagination/fetchAllRequestPages.ts +0 -16
  189. package/src/utils/pagination/incompletePageWalkError.ts +0 -8
  190. package/src/utils/pagination/isAnotherPage.ts +0 -20
  191. package/src/utils/pagination/iterateByCursor.ts +0 -49
  192. package/src/utils/pagination/iterateByPage.ts +0 -59
  193. package/src/utils/pagination/iterateProviderPages.ts +0 -27
  194. package/src/utils/pagination/iterateRequestPages.ts +0 -18
  195. package/src/utils/pagination/pageWalkError.ts +0 -6
  196. package/src/utils/pagination/paginationOptions.ts +0 -9
  197. package/src/utils/pagination/providerPagesOptions.ts +0 -8
  198. package/src/utils/pagination/providerPagination.ts +0 -6
  199. package/src/utils/pagination/readPage.ts +0 -29
  200. package/src/utils/pagination/readPath.ts +0 -12
  201. package/src/utils/pagination/repeatedCursorError.ts +0 -10
  202. package/src/utils/providerClient.ts +0 -3
  203. package/src/utils/providerError.ts +0 -10
  204. package/src/utils/providerRequest.ts +0 -22
  205. package/src/utils/providerRequestInput.ts +0 -7
  206. package/src/utils/providerResponseLimit.ts +0 -1
  207. package/src/utils/providerSend.ts +0 -1
  208. package/src/utils/readProviderJson.ts +0 -38
  209. package/src/utils/readRateLimit.ts +0 -29
  210. package/src/utils/requestProviderJson.ts +0 -13
  211. package/src/utils/responseBudget.ts +0 -1
  212. package/src/utils/sendProviderRequest.ts +0 -33
@@ -0,0 +1,22 @@
1
+ import { makeApiOperation } from '@inixiative/api-client/operation';
2
+ import { z } from 'zod';
3
+ import { pageQuerySchema } from '../../../../utils/pageQuerySchema';
4
+ import { githubPagination } from '../../githubPagination';
5
+ import { githubRequestHeaders } from '../../githubRequestHeaders';
6
+
7
+ export const listGithubUserInstallationRepositoryPage = makeApiOperation({
8
+ key: 'user.installations.repositories.list',
9
+ idempotent: true,
10
+ response: 'json',
11
+ input: z.object({
12
+ installationId: z.number().int().positive(),
13
+ query: pageQuerySchema(githubPagination),
14
+ }),
15
+ toRequest: ({ installationId, query }) => ({
16
+ path: 'user/installations/:installationId/repositories',
17
+ params: { installationId: String(installationId) },
18
+ query: query,
19
+ headers: githubRequestHeaders,
20
+ }),
21
+ parse: ({ body }) => body,
22
+ });
@@ -0,0 +1,9 @@
1
+ import { ApiError } from '@inixiative/api-client';
2
+ import { gitObjectIdSchema } from '@inixiative/signet/contracts';
3
+ import { z } from 'zod';
4
+
5
+ export const readGithubObjectIdentity = (data: unknown, objectId: string) => {
6
+ const identity = z.object({ sha: gitObjectIdSchema }).parse(data);
7
+ if (identity.sha !== objectId) throw new ApiError('provider_invalid_response');
8
+ return data;
9
+ };
@@ -0,0 +1,25 @@
1
+ import type { ApiClient } from '@inixiative/api-client';
2
+ import { iterateApiPages } from '@inixiative/api-client/http/pagination';
3
+ import type { ApiOperationOptions } from '@inixiative/api-client/operation';
4
+ import { githubInstallationSchema } from '../auth/githubInstallationSchema';
5
+ import { listGithubUserInstallationPage } from '../auth/listGithubUserInstallationPage';
6
+ import { githubPagination } from '../githubPagination';
7
+
8
+ export const fetchGithubUserInstallation = async (
9
+ client: ApiClient,
10
+ { installationId }: { installationId: string },
11
+ options?: ApiOperationOptions,
12
+ ) => {
13
+ const pages = iterateApiPages(githubPagination, {
14
+ keys: { data: 'installations' },
15
+ maxPages: 10,
16
+ fetchPage: (query) => listGithubUserInstallationPage(client, { query }, options),
17
+ });
18
+ for await (const { items } of pages)
19
+ for (const candidate of items) {
20
+ const installation = githubInstallationSchema.safeParse(candidate);
21
+ if (installation.success && String(installation.data.id) === installationId)
22
+ return installation.data;
23
+ }
24
+ return null;
25
+ };
@@ -0,0 +1,27 @@
1
+ import type { ApiClient } from '@inixiative/api-client';
2
+ import { fetchAllApiPages } from '@inixiative/api-client/http/pagination';
3
+ import type { ApiOperationOptions } from '@inixiative/api-client/operation';
4
+ import { z } from 'zod';
5
+ import { githubNotificationSchema } from '../events/githubNotificationSchema';
6
+ import { listGithubNotificationPage } from '../events/listGithubNotificationPage';
7
+ import { githubPagination } from '../githubPagination';
8
+
9
+ export const listGithubNotifications = async (
10
+ client: ApiClient,
11
+ { since }: { since: Date },
12
+ options?: ApiOperationOptions,
13
+ ) => {
14
+ let truncated = false;
15
+ const notifications = z.array(githubNotificationSchema).parse(
16
+ await fetchAllApiPages(githubPagination, {
17
+ pageSize: 50,
18
+ fetchPage: (query) =>
19
+ listGithubNotificationPage(client, { since: since.toISOString(), query }, options),
20
+ maxPages: 10,
21
+ onCapped: () => {
22
+ truncated = true;
23
+ },
24
+ }),
25
+ );
26
+ return { notifications, truncated };
27
+ };
@@ -0,0 +1,34 @@
1
+ import type { ApiClient } from '@inixiative/api-client';
2
+ import { ApiError } from '@inixiative/api-client';
3
+ import { fetchAllApiPages } from '@inixiative/api-client/http/pagination';
4
+ import type { ApiOperationOptions } from '@inixiative/api-client/operation';
5
+ import { z } from 'zod';
6
+ import { providerResourceLimit } from '../../../contracts';
7
+ import { githubPagination } from '../githubPagination';
8
+ import { githubRepositoryName } from '../models/repository/githubRepositoryName';
9
+ import { listGithubInstallationRepositoryPage } from '../models/repository/listGithubInstallationRepositoryPage';
10
+
11
+ const totalSchema = z.object({ total_count: z.number().int().min(0) });
12
+ const repositoriesSchema = z.array(
13
+ z.object({ id: z.number().int().positive(), full_name: z.string() }),
14
+ );
15
+
16
+ export const listInstallationRepositories = async (
17
+ client: ApiClient,
18
+ options?: ApiOperationOptions,
19
+ ) => {
20
+ const repositories = repositoriesSchema.parse(
21
+ await fetchAllApiPages(githubPagination, {
22
+ keys: { data: 'repositories' },
23
+ fetchPage: (query) => listGithubInstallationRepositoryPage(client, { query }, options),
24
+ onResponse: (response) => {
25
+ if (totalSchema.parse(response).total_count > providerResourceLimit)
26
+ throw new ApiError('too_many_repositories', 409);
27
+ },
28
+ }),
29
+ );
30
+ const listed = new Map(
31
+ repositories.map(({ id, full_name }) => [String(id), githubRepositoryName(full_name)]),
32
+ );
33
+ return [...listed].map(([id, fullName]) => ({ id, fullName }));
34
+ };
@@ -0,0 +1,43 @@
1
+ import type { ApiClient } from '@inixiative/api-client';
2
+ import { ApiError } from '@inixiative/api-client';
3
+ import { fetchAllApiPages } from '@inixiative/api-client/http/pagination';
4
+ import type { ApiOperationOptions } from '@inixiative/api-client/operation';
5
+ import { z } from 'zod';
6
+ import { providerResourceLimit } from '../../../contracts';
7
+ import { listGithubUserInstallationPage } from '../auth/listGithubUserInstallationPage';
8
+ import { githubPagination } from '../githubPagination';
9
+ import { githubRepositoryName } from '../models/repository/githubRepositoryName';
10
+ import { listGithubUserInstallationRepositoryPage } from '../models/repository/listGithubUserInstallationRepositoryPage';
11
+
12
+ const installationsSchema = z.array(z.object({ id: z.number().int().positive() }));
13
+ const repositoriesSchema = z.array(
14
+ z.object({ id: z.number().int().positive(), full_name: z.string() }),
15
+ );
16
+
17
+ // why: a GitHub App user token reaches only repositories in the App's installations the user sees.
18
+ export const listUserRepositories = async (client: ApiClient, options?: ApiOperationOptions) => {
19
+ const installations = installationsSchema.parse(
20
+ await fetchAllApiPages(githubPagination, {
21
+ keys: { data: 'installations' },
22
+ fetchPage: (query) => listGithubUserInstallationPage(client, { query }, options),
23
+ }),
24
+ );
25
+ const listed = new Map<string, string>();
26
+ for (const installation of installations) {
27
+ const repositories = repositoriesSchema.parse(
28
+ await fetchAllApiPages(githubPagination, {
29
+ keys: { data: 'repositories' },
30
+ fetchPage: (query) =>
31
+ listGithubUserInstallationRepositoryPage(
32
+ client,
33
+ { installationId: installation.id, query },
34
+ options,
35
+ ),
36
+ }),
37
+ );
38
+ for (const repository of repositories)
39
+ listed.set(String(repository.id), githubRepositoryName(repository.full_name));
40
+ if (listed.size > providerResourceLimit) throw new ApiError('too_many_repositories', 409);
41
+ }
42
+ return [...listed].map(([id, fullName]) => ({ id, fullName }));
43
+ };
@@ -0,0 +1 @@
1
+ export const gmailApiBaseUrl = 'https://gmail.googleapis.com/';
@@ -0,0 +1,10 @@
1
+ import { defineApiOperations } from '@inixiative/api-client/operation';
2
+ import { listGmailLabelMessages } from './models/label/listGmailLabelMessages';
3
+ import { fetchGmailMessage } from './models/message/fetchGmailMessage';
4
+ import { fetchGmailMessageBatch } from './models/message/fetchGmailMessageBatch';
5
+
6
+ export const gmailOperations = defineApiOperations({
7
+ 'messages.list': listGmailLabelMessages,
8
+ 'messages.read': fetchGmailMessage,
9
+ 'messages.readBatch': fetchGmailMessageBatch,
10
+ });
@@ -1,19 +1,16 @@
1
+ import { catalogOperations } from '../../catalog/catalogOperations';
1
2
  import type { ProviderDefinition } from '../../contracts';
3
+ import { gmailApiBaseUrl } from './gmailApiBaseUrl';
4
+ import { gmailOperations } from './gmailOperations';
2
5
 
3
6
  export const gmailProvider: ProviderDefinition = {
4
7
  key: 'gmail',
5
8
  name: 'Gmail',
6
9
  documentationUrl:
7
- 'https://developers.google.com/workspace/gmail/api/reference/rest/v1/users.messages/list',
8
- authMethods: ['oauth2'],
9
- family: 'google',
10
+ 'https://developers.google.com/workspace/gmail/api/reference/rest/v1/users.messages',
11
+ authMethods: ['integrationFamily'],
12
+ integrationFamily: 'google',
10
13
  oauthScopes: ['https://www.googleapis.com/auth/gmail.readonly'],
11
- operations: [
12
- {
13
- key: 'messages.read',
14
- name: 'Read the newest messages in a label',
15
- resourceKind: 'label',
16
- requiredScopes: ['https://www.googleapis.com/auth/gmail.readonly'],
17
- },
18
- ],
14
+ apiBaseUrl: gmailApiBaseUrl,
15
+ operations: catalogOperations(gmailOperations),
19
16
  };
@@ -0,0 +1,45 @@
1
+ import { makeApiOperation } from '@inixiative/api-client/operation';
2
+ import { z } from 'zod';
3
+ import { providerOperationInputSchema } from '../../../../operations/providerOperationInputSchema';
4
+ import { acceptJsonHeaders } from '../../../../utils/acceptJsonHeaders';
5
+
6
+ const kind = 'label';
7
+ const listSchema = z.object({
8
+ messages: z
9
+ .array(z.object({ id: z.string().regex(/^[A-Za-z0-9_-]{1,64}$/), threadId: z.string() }))
10
+ .default([]),
11
+ nextPageToken: z.string().optional(),
12
+ });
13
+
14
+ export const listGmailLabelMessages = makeApiOperation({
15
+ key: 'messages.list',
16
+ idempotent: true,
17
+ response: 'json',
18
+ meta: {
19
+ name: 'List the newest messages in a label',
20
+ resourceKind: kind,
21
+ requiredScopes: ['https://www.googleapis.com/auth/gmail.readonly'],
22
+ },
23
+ input: providerOperationInputSchema(
24
+ ['gmail'],
25
+ kind,
26
+ z.object({ pageToken: z.string().min(1).max(512).optional() }),
27
+ ),
28
+ toRequest: ({ resource, limit, input }) => ({
29
+ path: 'gmail/v1/users/me/messages',
30
+ headers: acceptJsonHeaders,
31
+ query: {
32
+ labelIds: resource.externalId,
33
+ maxResults: limit,
34
+ ...(input.pageToken ? { pageToken: input.pageToken } : {}),
35
+ },
36
+ }),
37
+ parse: ({ body }) => {
38
+ const list = listSchema.parse(body);
39
+ return {
40
+ messages: list.messages.map(({ id, threadId }) => ({ id, threadId })),
41
+ hasMore: Boolean(list.nextPageToken),
42
+ nextPageToken: list.nextPageToken ?? null,
43
+ };
44
+ },
45
+ });
@@ -0,0 +1,19 @@
1
+ import { makeApiOperation } from '@inixiative/api-client/operation';
2
+ import { providerOperationInputSchema } from '../../../../operations/providerOperationInputSchema';
3
+ import { gmailMessageKind } from './gmailMessageKind';
4
+ import { gmailMessageRequest } from './gmailMessageRequest';
5
+ import { readGmailMessage } from './readGmailMessage';
6
+
7
+ export const fetchGmailMessage = makeApiOperation({
8
+ key: 'messages.read',
9
+ idempotent: true,
10
+ response: 'json',
11
+ meta: {
12
+ name: 'Read a message',
13
+ resourceKind: gmailMessageKind,
14
+ requiredScopes: ['https://www.googleapis.com/auth/gmail.readonly'],
15
+ },
16
+ input: providerOperationInputSchema(['gmail'], gmailMessageKind),
17
+ toRequest: ({ resource }) => gmailMessageRequest(resource.externalId),
18
+ parse: ({ body }) => readGmailMessage(body),
19
+ });
@@ -0,0 +1,20 @@
1
+ import { makeApiBatchOperation } from '@inixiative/api-client/operation';
2
+ import { z } from 'zod';
3
+ import { providerOperationInputSchema } from '../../../../operations/providerOperationInputSchema';
4
+ import { gmailMessageKind } from './gmailMessageKind';
5
+ import { gmailMessageRequest } from './gmailMessageRequest';
6
+ import { readGmailMessage } from './readGmailMessage';
7
+
8
+ export const fetchGmailMessageBatch = makeApiBatchOperation({
9
+ key: 'messages.readBatch',
10
+ idempotent: true,
11
+ meta: {
12
+ name: 'Read several messages in one batch',
13
+ resourceKind: gmailMessageKind,
14
+ requiredScopes: ['https://www.googleapis.com/auth/gmail.readonly'],
15
+ },
16
+ input: z.array(providerOperationInputSchema(['gmail'], gmailMessageKind)),
17
+ batch: { over: 'multipart', path: 'batch/gmail/v1', maxItems: 100 },
18
+ toItemRequest: ({ resource }) => gmailMessageRequest(resource.externalId),
19
+ parseItem: ({ body }) => readGmailMessage(body),
20
+ });
@@ -0,0 +1 @@
1
+ export const gmailMessageKind = 'message';
@@ -0,0 +1,9 @@
1
+ import type { ApiRequestInput } from '@inixiative/api-client/http';
2
+ import { acceptJsonHeaders } from '../../../../utils/acceptJsonHeaders';
3
+
4
+ export const gmailMessageRequest = (messageId: string): ApiRequestInput => ({
5
+ path: 'gmail/v1/users/me/messages/:messageId',
6
+ headers: acceptJsonHeaders,
7
+ params: { messageId },
8
+ query: { format: 'metadata', metadataHeaders: ['From', 'To', 'Subject', 'Date'] },
9
+ });
@@ -0,0 +1,26 @@
1
+ import { z } from 'zod';
2
+
3
+ const messageSchema = z.object({
4
+ id: z.string(),
5
+ threadId: z.string(),
6
+ snippet: z.string().default(''),
7
+ payload: z
8
+ .object({ headers: z.array(z.object({ name: z.string(), value: z.string() })).default([]) })
9
+ .default({ headers: [] }),
10
+ });
11
+
12
+ export const readGmailMessage = (value: unknown) => {
13
+ const message = messageSchema.parse(value);
14
+ const header = (name: string) =>
15
+ message.payload.headers.find((item) => item.name.toLowerCase() === name.toLowerCase())?.value ??
16
+ null;
17
+ return {
18
+ id: message.id,
19
+ threadId: message.threadId,
20
+ from: header('From'),
21
+ to: header('To'),
22
+ subject: header('Subject'),
23
+ date: header('Date'),
24
+ snippet: message.snippet,
25
+ };
26
+ };
@@ -1,5 +1,6 @@
1
1
  import { z } from 'zod';
2
2
  import { findProvider } from '../../../catalog/findProvider';
3
+ import { integrationFamilyDefinition } from '../../../catalog/integrationFamilyDefinition';
3
4
  import type { Provider } from '../../../contracts';
4
5
 
5
6
  export const buildGoogleAuthorizationUrl = (input: {
@@ -10,7 +11,7 @@ export const buildGoogleAuthorizationUrl = (input: {
10
11
  codeChallenge: string;
11
12
  loginHint?: string;
12
13
  }) => {
13
- const url = new URL(z.url().parse(findProvider('google')?.oauth?.authorizeUrl));
14
+ const url = new URL(z.url().parse(integrationFamilyDefinition('google')?.oauth?.authorizeUrl));
14
15
  const scopes = [
15
16
  ...new Set([
16
17
  ...input.products.flatMap((product) => findProvider(product)?.oauthScopes ?? []),
@@ -1,6 +1,6 @@
1
+ import { ApiError } from '@inixiative/api-client';
1
2
  import { decodeJwt } from 'jose';
2
3
  import { z } from 'zod';
3
- import { ProviderError } from '../../../utils/providerError';
4
4
 
5
5
  const claimsSchema = z.object({
6
6
  iss: z.enum(['accounts.google.com', 'https://accounts.google.com']),
@@ -15,8 +15,8 @@ export const verifyGoogleIdToken = (idToken: string, clientId: string) => {
15
15
  try {
16
16
  claims = claimsSchema.parse(decodeJwt(idToken));
17
17
  } catch {
18
- throw new ProviderError('id_token_invalid', 502);
18
+ throw new ApiError('id_token_invalid', 502);
19
19
  }
20
- if (claims.aud !== clientId) throw new ProviderError('id_token_invalid', 502);
20
+ if (claims.aud !== clientId) throw new ApiError('id_token_invalid', 502);
21
21
  return { sub: claims.sub, email: claims.email };
22
22
  };
@@ -0,0 +1 @@
1
+ export const jiraApiBaseUrl = 'https://api.atlassian.com/ex/jira/';
@@ -0,0 +1,4 @@
1
+ import { defineApiOperations } from '@inixiative/api-client/operation';
2
+ import { fetchJiraIssue } from './models/issue/fetchJiraIssue';
3
+
4
+ export const jiraOperations = defineApiOperations({ 'issues.read': fetchJiraIssue });
@@ -1,16 +1,14 @@
1
+ import { catalogOperations } from '../../catalog/catalogOperations';
1
2
  import type { ProviderDefinition } from '../../contracts';
3
+ import { jiraApiBaseUrl } from './jiraApiBaseUrl';
4
+ import { jiraOperations } from './jiraOperations';
2
5
 
3
6
  export const jiraProvider: ProviderDefinition = {
4
7
  key: 'jira',
5
8
  name: 'Jira',
6
9
  documentationUrl: 'https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issues/',
7
10
  authMethods: ['bearer', 'oauth2'],
8
- operations: [
9
- {
10
- key: 'issues.read',
11
- name: 'Read an issue',
12
- resourceKind: 'issue',
13
- requiredScopes: ['read:jira-work'],
14
- },
15
- ],
11
+ integrationFamily: 'atlassian',
12
+ apiBaseUrl: jiraApiBaseUrl,
13
+ operations: catalogOperations(jiraOperations),
16
14
  };
@@ -0,0 +1,22 @@
1
+ import { makeApiOperation } from '@inixiative/api-client/operation';
2
+ import { providerOperationInputSchema } from '../../../../operations/providerOperationInputSchema';
3
+ import { acceptJsonHeaders } from '../../../../utils/acceptJsonHeaders';
4
+ import { objectSchema } from '../../../../utils/objectSchema';
5
+ import { select } from '../../../../utils/select';
6
+
7
+ const kind = 'issue';
8
+
9
+ export const fetchJiraIssue = makeApiOperation({
10
+ key: 'issues.read',
11
+ idempotent: true,
12
+ response: 'json',
13
+ meta: { name: 'Read an issue', resourceKind: kind, requiredScopes: ['read:jira-work'] },
14
+ input: providerOperationInputSchema(['jira'], kind),
15
+ toRequest: ({ resource, configuration }) => ({
16
+ path: ':cloudId/rest/api/3/issue/:issueId',
17
+ headers: acceptJsonHeaders,
18
+ params: { cloudId: configuration.cloudId, issueId: resource.externalId },
19
+ query: { fields: 'summary,description,status' },
20
+ }),
21
+ parse: ({ body }) => select(objectSchema.parse(body), ['id', 'key', 'fields']),
22
+ });
@@ -1,6 +1,7 @@
1
+ import { makeApiOperation } from '@inixiative/api-client/operation';
1
2
  import { z } from 'zod';
2
- import type { LinearClient } from '../linearClient';
3
- import { requestLinear } from '../requestLinear';
3
+ import { acceptJsonHeaders } from '../../../utils/acceptJsonHeaders';
4
+ import { linearGraphqlErrorCode } from '../linearGraphqlErrorCode';
4
5
 
5
6
  const createdSchema = z.object({
6
7
  webhookCreate: z.object({
@@ -9,22 +10,30 @@ const createdSchema = z.object({
9
10
  }),
10
11
  });
11
12
 
12
- export const createLinearWebhook = async (
13
- client: LinearClient,
14
- { url, secret, label, teamId }: { url: string; secret: string; label: string; teamId?: string },
15
- ) =>
16
- createdSchema.parse(
17
- await requestLinear(client, {
18
- query:
19
- 'mutation WebhookCreate($input: WebhookCreateInput!) { webhookCreate(input: $input) { success webhook { id } } }',
20
- variables: {
21
- input: {
22
- url,
23
- secret,
24
- label,
25
- resourceTypes: ['Issue', 'Comment'],
26
- ...(teamId ? { teamId } : { allPublicTeams: true }),
27
- },
13
+ export const createLinearWebhook = makeApiOperation({
14
+ key: 'webhooks.create',
15
+ idempotent: false,
16
+ response: 'graphql',
17
+ errorCode: linearGraphqlErrorCode,
18
+ input: z.strictObject({
19
+ url: z.string(),
20
+ secret: z.string(),
21
+ label: z.string(),
22
+ teamId: z.string().optional(),
23
+ }),
24
+ toRequest: ({ url, secret, label, teamId }) => ({
25
+ headers: acceptJsonHeaders,
26
+ query:
27
+ 'mutation WebhookCreate($input: WebhookCreateInput!) { webhookCreate(input: $input) { success webhook { id } } }',
28
+ variables: {
29
+ input: {
30
+ url,
31
+ secret,
32
+ label,
33
+ resourceTypes: ['Issue', 'Comment'],
34
+ ...(teamId ? { teamId } : { allPublicTeams: true }),
28
35
  },
29
- }),
30
- ).webhookCreate.success;
36
+ },
37
+ }),
38
+ parse: ({ body }) => createdSchema.parse(body).webhookCreate.success,
39
+ });
@@ -1,13 +1,20 @@
1
+ import { makeApiOperation } from '@inixiative/api-client/operation';
1
2
  import { z } from 'zod';
2
- import type { LinearClient } from '../linearClient';
3
- import { requestLinear } from '../requestLinear';
3
+ import { acceptJsonHeaders } from '../../../utils/acceptJsonHeaders';
4
+ import { linearGraphqlErrorCode } from '../linearGraphqlErrorCode';
4
5
 
5
6
  const deletedSchema = z.object({ webhookDelete: z.object({ success: z.boolean() }) });
6
7
 
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;
8
+ export const deleteLinearWebhook = makeApiOperation({
9
+ key: 'webhooks.delete',
10
+ idempotent: true,
11
+ response: 'graphql',
12
+ errorCode: linearGraphqlErrorCode,
13
+ input: z.strictObject({ id: z.string() }),
14
+ toRequest: ({ id }) => ({
15
+ headers: acceptJsonHeaders,
16
+ query: 'mutation WebhookDelete($id: String!) { webhookDelete(id: $id) { success } }',
17
+ variables: { id },
18
+ }),
19
+ parse: ({ body }) => deletedSchema.parse(body).webhookDelete.success,
20
+ });
@@ -1,3 +1,3 @@
1
- import type { listLinearWebhooks } from './listLinearWebhooks';
1
+ import type { listLinearWebhooks } from '../services/listLinearWebhooks';
2
2
 
3
3
  export type LinearWebhook = Awaited<ReturnType<typeof listLinearWebhooks>>[number];
@@ -0,0 +1,23 @@
1
+ import { makeApiOperation } from '@inixiative/api-client/operation';
2
+ import { z } from 'zod';
3
+ import { acceptJsonHeaders } from '../../../utils/acceptJsonHeaders';
4
+ import { linearGraphqlErrorCode } from '../linearGraphqlErrorCode';
5
+
6
+ export const listLinearWebhookPage = makeApiOperation({
7
+ key: 'webhooks.list',
8
+ idempotent: true,
9
+ response: 'graphql',
10
+ errorCode: linearGraphqlErrorCode,
11
+ input: z.object({
12
+ variables: z
13
+ .object({ first: z.number().int().optional(), after: z.string().optional() })
14
+ .optional(),
15
+ }),
16
+ toRequest: ({ variables = {} }) => ({
17
+ headers: acceptJsonHeaders,
18
+ query:
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
+ variables,
21
+ }),
22
+ parse: ({ body }) => body,
23
+ });
@@ -1,17 +1,21 @@
1
+ import { makeApiOperation } from '@inixiative/api-client/operation';
1
2
  import { z } from 'zod';
2
- import type { LinearClient } from '../linearClient';
3
- import { requestLinear } from '../requestLinear';
3
+ import { acceptJsonHeaders } from '../../../utils/acceptJsonHeaders';
4
+ import { linearGraphqlErrorCode } from '../linearGraphqlErrorCode';
4
5
 
5
6
  const updatedSchema = z.object({ webhookUpdate: z.object({ success: z.boolean() }) });
6
7
 
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;
8
+ export const repairLinearWebhook = makeApiOperation({
9
+ key: 'webhooks.update',
10
+ idempotent: true,
11
+ response: 'graphql',
12
+ errorCode: linearGraphqlErrorCode,
13
+ input: z.strictObject({ id: z.string(), secret: z.string() }),
14
+ toRequest: ({ id, secret }) => ({
15
+ headers: acceptJsonHeaders,
16
+ query:
17
+ 'mutation WebhookRepair($id: String!, $input: WebhookUpdateInput!) { webhookUpdate(id: $id, input: $input) { success } }',
18
+ variables: { id, input: { enabled: true, secret } },
19
+ }),
20
+ parse: ({ body }) => updatedSchema.parse(body).webhookUpdate.success,
21
+ });
@@ -0,0 +1 @@
1
+ export const linearApiBaseUrl = 'https://api.linear.app/graphql';
@@ -0,0 +1,8 @@
1
+ import type { GraphqlError } from '@inixiative/api-client/graphql';
2
+
3
+ export const linearGraphqlErrorCode = ({ extensions }: GraphqlError) => {
4
+ const kind = `${extensions?.type ?? ''} ${extensions?.code ?? ''}`.toLowerCase();
5
+ if (kind.includes('authentication')) return 'provider_authentication_expired';
6
+ if (kind.includes('forbidden')) return 'provider_access_denied';
7
+ return 'provider_failed';
8
+ };
@@ -0,0 +1,4 @@
1
+ import { defineApiOperations } from '@inixiative/api-client/operation';
2
+ import { fetchLinearIssue } from './models/issue/fetchLinearIssue';
3
+
4
+ export const linearOperations = defineApiOperations({ 'issues.read': fetchLinearIssue });
@@ -1,13 +1,7 @@
1
- import type { ProviderPagination } from '../../utils/pagination/providerPagination';
1
+ import { type GraphqlPagination, graphqlConnectionKeys } from '@inixiative/api-client/graphql';
2
2
 
3
3
  export const linearPagination = {
4
4
  strategy: 'cursor',
5
- keys: {
6
- cursor: 'after',
7
- pageSize: 'first',
8
- data: 'nodes',
9
- nextCursor: 'pageInfo.endCursor',
10
- hasMore: 'pageInfo.hasNextPage',
11
- },
5
+ keys: graphqlConnectionKeys,
12
6
  pageSize: 250,
13
- } satisfies ProviderPagination;
7
+ } satisfies GraphqlPagination;