@inixiative/integrations 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (193) hide show
  1. package/README.md +21 -13
  2. package/package.json +3 -2
  3. package/src/catalog/catalogOperationMeta.ts +4 -0
  4. package/src/catalog/catalogOperations.ts +10 -0
  5. package/src/catalog/providerModel.ts +0 -1
  6. package/src/contracts.ts +1 -10
  7. package/src/credentials/credentialAuth.ts +38 -0
  8. package/src/credentials/credentialClient.ts +2 -2
  9. package/src/credentials/exchangeOauthCode.ts +30 -36
  10. package/src/credentials/mintProviderCredential.ts +26 -40
  11. package/src/credentials/providerExchangeTimeoutMs.ts +1 -1
  12. package/src/credentials/refreshProviderCredential.ts +62 -65
  13. package/src/credentials/renewalError.ts +11 -0
  14. package/src/credentials/requestOauthToken.ts +28 -0
  15. package/src/credentials/validateCredentialSecret.ts +5 -5
  16. package/src/index.ts +0 -1
  17. package/src/operations/providerOperationInput.ts +6 -0
  18. package/src/operations/providerOperationInputSchema.ts +36 -0
  19. package/src/operations/providerOperationOrThrow.ts +23 -0
  20. package/src/operations/providerOperationSet.ts +7 -0
  21. package/src/operations/providerOperations.ts +38 -0
  22. package/src/providers/confluence/confluenceApiBaseUrl.ts +1 -0
  23. package/src/providers/confluence/confluenceOperations.ts +4 -0
  24. package/src/providers/confluence/confluenceProvider.ts +5 -8
  25. package/src/providers/confluence/models/page/fetchConfluencePage.ts +23 -0
  26. package/src/providers/discord/discordApiBaseUrl.ts +1 -0
  27. package/src/providers/discord/discordOperations.ts +8 -0
  28. package/src/providers/discord/discordProvider.ts +5 -14
  29. package/src/providers/discord/models/channel/discordChannelKind.ts +1 -0
  30. package/src/providers/discord/models/channel/fetchDiscordChannel.ts +25 -0
  31. package/src/providers/discord/models/channel/fetchDiscordChannelMessages.ts +37 -0
  32. package/src/providers/drive/driveApiBaseUrl.ts +1 -0
  33. package/src/providers/drive/driveOperations.ts +4 -0
  34. package/src/providers/drive/driveProvider.ts +5 -8
  35. package/src/providers/drive/models/file/fetchDriveFile.ts +27 -0
  36. package/src/providers/github/auth/createGithubInstallationToken.ts +19 -0
  37. package/src/providers/github/auth/fetchGithubAppInstallUrl.ts +21 -0
  38. package/src/providers/github/auth/fetchGithubAppInstallation.ts +16 -19
  39. package/src/providers/github/auth/fetchGithubOrganizationRole.ts +22 -22
  40. package/src/providers/github/auth/fetchGithubUser.ts +10 -4
  41. package/src/providers/github/auth/githubAppAuth.ts +6 -0
  42. package/src/providers/github/auth/listGithubUserInstallationPage.ts +18 -0
  43. package/src/providers/github/events/listGithubNotificationPage.ts +18 -0
  44. package/src/providers/github/githubApiBaseUrl.ts +1 -0
  45. package/src/providers/github/githubOrganizationProvider.ts +5 -1
  46. package/src/providers/github/githubPagination.ts +2 -2
  47. package/src/providers/github/githubRequestHeaders.ts +4 -6
  48. package/src/providers/github/githubUserProvider.ts +5 -2
  49. package/src/providers/github/models/account/githubAccount.ts +0 -1
  50. package/src/providers/github/models/repository/fetchGithubBlob.ts +59 -0
  51. package/src/providers/github/models/repository/fetchGithubCommit.ts +38 -0
  52. package/src/providers/github/models/repository/fetchGithubTree.ts +74 -0
  53. package/src/providers/github/models/repository/githubObjectRequest.ts +15 -0
  54. package/src/providers/github/models/repository/githubRepository.ts +1 -11
  55. package/src/providers/github/models/repository/githubRepositoryOperations.ts +10 -0
  56. package/src/providers/github/models/repository/listGithubInstallationRepositoryPage.ts +18 -0
  57. package/src/providers/github/models/repository/listGithubUserInstallationRepositoryPage.ts +22 -0
  58. package/src/providers/github/models/repository/readGithubObjectIdentity.ts +9 -0
  59. package/src/providers/github/services/fetchGithubUserInstallation.ts +25 -0
  60. package/src/providers/github/services/listGithubNotifications.ts +27 -0
  61. package/src/providers/github/services/listInstallationRepositories.ts +34 -0
  62. package/src/providers/github/services/listUserRepositories.ts +43 -0
  63. package/src/providers/gmail/gmailApiBaseUrl.ts +1 -0
  64. package/src/providers/gmail/gmailOperations.ts +10 -0
  65. package/src/providers/gmail/gmailProvider.ts +6 -9
  66. package/src/providers/gmail/models/label/listGmailLabelMessages.ts +45 -0
  67. package/src/providers/gmail/models/message/fetchGmailMessage.ts +19 -0
  68. package/src/providers/gmail/models/message/fetchGmailMessageBatch.ts +20 -0
  69. package/src/providers/gmail/models/message/gmailMessageKind.ts +1 -0
  70. package/src/providers/gmail/models/message/gmailMessageRequest.ts +9 -0
  71. package/src/providers/gmail/models/message/readGmailMessage.ts +26 -0
  72. package/src/providers/google/auth/verifyGoogleIdToken.ts +3 -3
  73. package/src/providers/jira/jiraApiBaseUrl.ts +1 -0
  74. package/src/providers/jira/jiraOperations.ts +4 -0
  75. package/src/providers/jira/jiraProvider.ts +5 -8
  76. package/src/providers/jira/models/issue/fetchJiraIssue.ts +22 -0
  77. package/src/providers/linear/events/createLinearWebhook.ts +29 -20
  78. package/src/providers/linear/events/deleteLinearWebhook.ts +16 -9
  79. package/src/providers/linear/events/linearWebhook.ts +1 -1
  80. package/src/providers/linear/events/listLinearWebhookPage.ts +23 -0
  81. package/src/providers/linear/events/repairLinearWebhook.ts +17 -13
  82. package/src/providers/linear/linearApiBaseUrl.ts +1 -0
  83. package/src/providers/linear/linearGraphqlErrorCode.ts +8 -0
  84. package/src/providers/linear/linearOperations.ts +4 -0
  85. package/src/providers/linear/linearPagination.ts +3 -9
  86. package/src/providers/linear/linearProvider.ts +5 -2
  87. package/src/providers/linear/models/issue/fetchLinearIssue.ts +32 -0
  88. package/src/providers/linear/models/team/fetchLinearWorkspace.ts +23 -13
  89. package/src/providers/linear/models/team/linearTeam.ts +0 -1
  90. package/src/providers/linear/services/listLinearWebhooks.ts +45 -0
  91. package/src/providers/notion/models/page/fetchNotionPage.ts +32 -0
  92. package/src/providers/notion/models/page/fetchNotionPageBlocks.ts +39 -0
  93. package/src/providers/notion/models/page/notionPageKind.ts +1 -0
  94. package/src/providers/notion/notionApiBaseUrl.ts +1 -0
  95. package/src/providers/notion/notionOperations.ts +8 -0
  96. package/src/providers/notion/notionProvider.ts +5 -14
  97. package/src/providers/notion/notionVersion.ts +1 -0
  98. package/src/providers/slack/auth/fetchSlackIdentity.ts +14 -6
  99. package/src/providers/slack/models/account/slackAccount.ts +0 -1
  100. package/src/providers/slack/models/channel/fetchSlackChannel.ts +32 -0
  101. package/src/providers/slack/models/channel/fetchSlackChannelMessages.ts +34 -0
  102. package/src/providers/slack/models/channel/listSlackUserConversations.ts +19 -0
  103. package/src/providers/slack/models/channel/slackChannel.ts +0 -14
  104. package/src/providers/slack/readSlackBody.ts +10 -0
  105. package/src/providers/slack/services/listSlackChannels.ts +23 -0
  106. package/src/providers/slack/slackApiBaseUrl.ts +1 -0
  107. package/src/providers/slack/slackOperations.ts +8 -0
  108. package/src/providers/slack/slackPagination.ts +2 -2
  109. package/src/providers/slack/slackProvider.ts +9 -1
  110. package/src/providers/slack/slackProviderError.ts +2 -2
  111. package/src/providers/teams/models/channel/fetchTeamsChannelMessages.ts +36 -0
  112. package/src/providers/teams/teamsApiBaseUrl.ts +1 -0
  113. package/src/providers/teams/teamsOperations.ts +6 -0
  114. package/src/providers/teams/teamsProvider.ts +5 -8
  115. package/src/utils/acceptJsonHeaders.ts +1 -0
  116. package/src/utils/pageQuerySchema.ts +13 -0
  117. package/src/utils/readProviderLimits.ts +1 -2
  118. package/src/credentials/fetchRenewalResponse.ts +0 -41
  119. package/src/credentials/renewalRequest.ts +0 -1
  120. package/src/operations/buildProviderRequest.ts +0 -55
  121. package/src/operations/executeProvider.ts +0 -26
  122. package/src/operations/findOperationHandler.ts +0 -6
  123. package/src/operations/operationHandler.ts +0 -8
  124. package/src/operations/operationHandlers.ts +0 -39
  125. package/src/operations/operationRequestInput.ts +0 -12
  126. package/src/operations/providerRequestSpec.ts +0 -1
  127. package/src/providers/confluence/confluenceOperationHandler.ts +0 -14
  128. package/src/providers/discord/discordOperationHandler.ts +0 -30
  129. package/src/providers/drive/driveOperationHandler.ts +0 -21
  130. package/src/providers/github/auth/fetchGithubUserInstallation.ts +0 -21
  131. package/src/providers/github/auth/githubAppClient.ts +0 -4
  132. package/src/providers/github/auth/githubAppInstallUrl.ts +0 -20
  133. package/src/providers/github/auth/githubClientForApp.ts +0 -11
  134. package/src/providers/github/events/listGithubNotifications.ts +0 -27
  135. package/src/providers/github/fetchAllGithubPages.ts +0 -12
  136. package/src/providers/github/iterateGithubPages.ts +0 -12
  137. package/src/providers/github/models/repository/githubOperationHandler.ts +0 -36
  138. package/src/providers/github/models/repository/listInstallationRepositories.ts +0 -31
  139. package/src/providers/github/models/repository/listUserRepositories.ts +0 -36
  140. package/src/providers/github/models/repository/readGithubObject.ts +0 -85
  141. package/src/providers/github/requestGithub.ts +0 -18
  142. package/src/providers/gmail/buildGmailMessageRequest.ts +0 -22
  143. package/src/providers/gmail/fetchGmailMessages.ts +0 -81
  144. package/src/providers/gmail/gmailOperationHandler.ts +0 -12
  145. package/src/providers/jira/jiraOperationHandler.ts +0 -14
  146. package/src/providers/linear/events/listLinearWebhooks.ts +0 -44
  147. package/src/providers/linear/fetchAllLinearPages.ts +0 -40
  148. package/src/providers/linear/linearClient.ts +0 -5
  149. package/src/providers/linear/linearRequestInput.ts +0 -1
  150. package/src/providers/linear/models/issue/linearIssue.ts +0 -11
  151. package/src/providers/linear/models/issue/linearOperationHandler.ts +0 -30
  152. package/src/providers/linear/requestLinear.ts +0 -51
  153. package/src/providers/notion/notionOperationHandler.ts +0 -32
  154. package/src/providers/slack/fetchAllSlackPages.ts +0 -12
  155. package/src/providers/slack/models/channel/listSlackChannels.ts +0 -26
  156. package/src/providers/slack/models/channel/slackOperationHandler.ts +0 -30
  157. package/src/providers/slack/requestSlack.ts +0 -22
  158. package/src/providers/teams/teamsOperationHandler.ts +0 -24
  159. package/src/utils/headerNumber.ts +0 -6
  160. package/src/utils/pagination/applyCaps.ts +0 -18
  161. package/src/utils/pagination/byCursorKeys.ts +0 -7
  162. package/src/utils/pagination/byCursorOptions.ts +0 -7
  163. package/src/utils/pagination/byPageKeys.ts +0 -7
  164. package/src/utils/pagination/byPageOptions.ts +0 -8
  165. package/src/utils/pagination/collectPages.ts +0 -27
  166. package/src/utils/pagination/compactRequest.ts +0 -4
  167. package/src/utils/pagination/fetchAllByCursor.ts +0 -6
  168. package/src/utils/pagination/fetchAllByPage.ts +0 -6
  169. package/src/utils/pagination/fetchAllRequestPages.ts +0 -16
  170. package/src/utils/pagination/incompletePageWalkError.ts +0 -8
  171. package/src/utils/pagination/isAnotherPage.ts +0 -20
  172. package/src/utils/pagination/iterateByCursor.ts +0 -49
  173. package/src/utils/pagination/iterateByPage.ts +0 -59
  174. package/src/utils/pagination/iterateProviderPages.ts +0 -27
  175. package/src/utils/pagination/iterateRequestPages.ts +0 -18
  176. package/src/utils/pagination/pageWalkError.ts +0 -6
  177. package/src/utils/pagination/paginationOptions.ts +0 -9
  178. package/src/utils/pagination/providerPagesOptions.ts +0 -8
  179. package/src/utils/pagination/providerPagination.ts +0 -6
  180. package/src/utils/pagination/readPage.ts +0 -29
  181. package/src/utils/pagination/readPath.ts +0 -12
  182. package/src/utils/pagination/repeatedCursorError.ts +0 -10
  183. package/src/utils/providerClient.ts +0 -3
  184. package/src/utils/providerError.ts +0 -10
  185. package/src/utils/providerRequest.ts +0 -22
  186. package/src/utils/providerRequestInput.ts +0 -7
  187. package/src/utils/providerResponseLimit.ts +0 -1
  188. package/src/utils/providerSend.ts +0 -1
  189. package/src/utils/readProviderJson.ts +0 -38
  190. package/src/utils/readRateLimit.ts +0 -29
  191. package/src/utils/requestProviderJson.ts +0 -13
  192. package/src/utils/responseBudget.ts +0 -1
  193. package/src/utils/sendProviderRequest.ts +0 -33
package/src/index.ts CHANGED
@@ -1,3 +1,2 @@
1
1
  export * from './catalog/providers';
2
2
  export * from './contracts';
3
- export * from './utils/providerError';
@@ -0,0 +1,6 @@
1
+ export type ProviderOperationInput = {
2
+ resource: { kind: string; externalId: string; metadata: unknown };
3
+ configuration: unknown;
4
+ limit: number;
5
+ input: Record<string, unknown>;
6
+ };
@@ -0,0 +1,36 @@
1
+ import { z } from 'zod';
2
+ import type { Provider } from '../contracts';
3
+ import { integrationConfigurationSchemas } from '../resources/integrationConfigurationSchemas';
4
+ import { resourceExternalIdSchemas } from '../resources/resourceExternalIdSchemas';
5
+ import { resourceMetadataSchemas } from '../resources/resourceMetadataSchemas';
6
+
7
+ const noInput = z.object({});
8
+
9
+ export const providerOperationInputSchema = <
10
+ P extends Provider,
11
+ Input extends z.ZodType = typeof noInput,
12
+ >(
13
+ providers: readonly [P, ...P[]],
14
+ kind: string,
15
+ input?: Input,
16
+ ) => {
17
+ const [provider] = providers;
18
+ // why: one operation serves several providers only when they read its resource the same way.
19
+ const isShared = providers.every(
20
+ (each) =>
21
+ resourceExternalIdSchemas[each] === resourceExternalIdSchemas[provider] &&
22
+ resourceMetadataSchemas[each] === resourceMetadataSchemas[provider] &&
23
+ integrationConfigurationSchemas[each] === integrationConfigurationSchemas[provider],
24
+ );
25
+ if (!isShared) throw new Error(`${providers.join(', ')} read a ${kind} differently`);
26
+ return z.object({
27
+ resource: z.object({
28
+ kind: z.literal(kind),
29
+ externalId: resourceExternalIdSchemas[provider],
30
+ metadata: resourceMetadataSchemas[provider],
31
+ }),
32
+ configuration: integrationConfigurationSchemas[provider],
33
+ limit: z.number().int().min(1).max(50),
34
+ input: (input ?? noInput) as Input,
35
+ });
36
+ };
@@ -0,0 +1,23 @@
1
+ import { ApiError } from '@inixiative/api-client';
2
+ import type { AnyApiOperation, ApiOperation } from '@inixiative/api-client/operation';
3
+ import type { CatalogOperationMeta } from '../catalog/catalogOperationMeta';
4
+ import type { Provider } from '../contracts';
5
+ import type { ProviderOperationInput } from './providerOperationInput';
6
+ import { providerOperations } from './providerOperations';
7
+
8
+ type CallableProviderOperation = ApiOperation<
9
+ ProviderOperationInput | ProviderOperationInput[],
10
+ unknown,
11
+ AnyApiOperation['definition'] & { meta?: CatalogOperationMeta; batch?: { maxItems: number } },
12
+ Record<never, never>
13
+ >;
14
+
15
+ export const providerOperationOrThrow = (
16
+ provider: Provider,
17
+ key: string,
18
+ ): CallableProviderOperation => {
19
+ const operations = providerOperations[provider];
20
+ if (!Object.hasOwn(operations, key)) throw new ApiError('unsupported_operation', 400);
21
+ // why: an operation's call type is its parsed input, and it parses whatever it is handed.
22
+ return operations[key] as unknown as CallableProviderOperation;
23
+ };
@@ -0,0 +1,7 @@
1
+ import type { AnyApiOperation } from '@inixiative/api-client/operation';
2
+ import type { CatalogOperationMeta } from '../catalog/catalogOperationMeta';
3
+
4
+ export type ProviderOperationSet = Record<
5
+ string,
6
+ AnyApiOperation & { readonly definition: { meta?: CatalogOperationMeta } }
7
+ >;
@@ -0,0 +1,38 @@
1
+ import type { Provider } from '../contracts';
2
+ import { confluenceOperations } from '../providers/confluence/confluenceOperations';
3
+ import { discordOperations } from '../providers/discord/discordOperations';
4
+ import { driveOperations } from '../providers/drive/driveOperations';
5
+ import { githubRepositoryOperations } from '../providers/github/models/repository/githubRepositoryOperations';
6
+ import { gmailOperations } from '../providers/gmail/gmailOperations';
7
+ import { jiraOperations } from '../providers/jira/jiraOperations';
8
+ import { linearOperations } from '../providers/linear/linearOperations';
9
+ import { notionOperations } from '../providers/notion/notionOperations';
10
+ import { slackOperations } from '../providers/slack/slackOperations';
11
+ import { teamsOperations } from '../providers/teams/teamsOperations';
12
+ import type { ProviderOperationSet } from './providerOperationSet';
13
+
14
+ export const providerOperations: Record<Provider, ProviderOperationSet> = {
15
+ slack: slackOperations,
16
+ discord: discordOperations,
17
+ teams: teamsOperations,
18
+ linear: linearOperations,
19
+ notion: notionOperations,
20
+ jira: jiraOperations,
21
+ gmail: gmailOperations,
22
+ drive: driveOperations,
23
+ confluence: confluenceOperations,
24
+ githubOrganization: githubRepositoryOperations,
25
+ githubUser: githubRepositoryOperations,
26
+ anthropic: {},
27
+ openai: {},
28
+ geminiApi: {},
29
+ archive: {},
30
+ foundry: {},
31
+ oracle: {},
32
+ chorus: {},
33
+ railway: {},
34
+ render: {},
35
+ claude: {},
36
+ codex: {},
37
+ muse: {},
38
+ };
@@ -0,0 +1 @@
1
+ export const confluenceApiBaseUrl = 'https://api.atlassian.com/ex/confluence/';
@@ -0,0 +1,4 @@
1
+ import { defineApiOperations } from '@inixiative/api-client/operation';
2
+ import { fetchConfluencePage } from './models/page/fetchConfluencePage';
3
+
4
+ export const confluenceOperations = defineApiOperations({ 'pages.read': fetchConfluencePage });
@@ -1,4 +1,7 @@
1
+ import { catalogOperations } from '../../catalog/catalogOperations';
1
2
  import type { ProviderDefinition } from '../../contracts';
3
+ import { confluenceApiBaseUrl } from './confluenceApiBaseUrl';
4
+ import { confluenceOperations } from './confluenceOperations';
2
5
 
3
6
  export const confluenceProvider: ProviderDefinition = {
4
7
  key: 'confluence',
@@ -6,12 +9,6 @@ export const confluenceProvider: ProviderDefinition = {
6
9
  documentationUrl: 'https://developer.atlassian.com/cloud/confluence/rest/v2/api-group-page/',
7
10
  authMethods: ['bearer', 'oauth2'],
8
11
  integrationFamily: 'atlassian',
9
- operations: [
10
- {
11
- key: 'pages.read',
12
- name: 'Read a page',
13
- resourceKind: 'page',
14
- requiredScopes: ['read:page:confluence'],
15
- },
16
- ],
12
+ apiBaseUrl: confluenceApiBaseUrl,
13
+ operations: catalogOperations(confluenceOperations),
17
14
  };
@@ -0,0 +1,23 @@
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 = 'page';
8
+
9
+ export const fetchConfluencePage = makeApiOperation({
10
+ key: 'pages.read',
11
+ idempotent: true,
12
+ response: 'json',
13
+ meta: { name: 'Read a page', resourceKind: kind, requiredScopes: ['read:page:confluence'] },
14
+ input: providerOperationInputSchema(['confluence'], kind),
15
+ toRequest: ({ resource, configuration }) => ({
16
+ path: ':cloudId/wiki/api/v2/pages/:pageId',
17
+ headers: acceptJsonHeaders,
18
+ params: { cloudId: configuration.cloudId, pageId: resource.externalId },
19
+ query: { 'body-format': 'storage' },
20
+ }),
21
+ parse: ({ body }) =>
22
+ select(objectSchema.parse(body), ['id', 'title', 'status', 'body', 'version']),
23
+ });
@@ -0,0 +1 @@
1
+ export const discordApiBaseUrl = 'https://discord.com/api/v10/';
@@ -0,0 +1,8 @@
1
+ import { defineApiOperations } from '@inixiative/api-client/operation';
2
+ import { fetchDiscordChannel } from './models/channel/fetchDiscordChannel';
3
+ import { fetchDiscordChannelMessages } from './models/channel/fetchDiscordChannelMessages';
4
+
5
+ export const discordOperations = defineApiOperations({
6
+ 'channels.read': fetchDiscordChannel,
7
+ 'messages.read': fetchDiscordChannelMessages,
8
+ });
@@ -1,22 +1,13 @@
1
+ import { catalogOperations } from '../../catalog/catalogOperations';
1
2
  import type { ProviderDefinition } from '../../contracts';
3
+ import { discordApiBaseUrl } from './discordApiBaseUrl';
4
+ import { discordOperations } from './discordOperations';
2
5
 
3
6
  export const discordProvider: ProviderDefinition = {
4
7
  key: 'discord',
5
8
  name: 'Discord',
6
9
  documentationUrl: 'https://discord.com/developers/docs/resources/message#get-channel-messages',
7
10
  authMethods: ['apiKey'],
8
- operations: [
9
- {
10
- key: 'channels.read',
11
- name: 'Read channel details',
12
- resourceKind: 'channel',
13
- requiredScopes: ['VIEW_CHANNEL'],
14
- },
15
- {
16
- key: 'messages.read',
17
- name: 'Read channel messages',
18
- resourceKind: 'channel',
19
- requiredScopes: ['VIEW_CHANNEL and READ_MESSAGE_HISTORY'],
20
- },
21
- ],
11
+ apiBaseUrl: discordApiBaseUrl,
12
+ operations: catalogOperations(discordOperations),
22
13
  };
@@ -0,0 +1 @@
1
+ export const discordChannelKind = 'channel';
@@ -0,0 +1,25 @@
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
+ import { discordChannelKind } from './discordChannelKind';
7
+
8
+ export const fetchDiscordChannel = makeApiOperation({
9
+ key: 'channels.read',
10
+ idempotent: true,
11
+ response: 'json',
12
+ meta: {
13
+ name: 'Read channel details',
14
+ resourceKind: discordChannelKind,
15
+ requiredScopes: ['VIEW_CHANNEL'],
16
+ },
17
+ input: providerOperationInputSchema(['discord'], discordChannelKind),
18
+ toRequest: ({ resource }) => ({
19
+ path: 'channels/:channelId',
20
+ headers: acceptJsonHeaders,
21
+ params: { channelId: resource.externalId },
22
+ }),
23
+ parse: ({ body }) =>
24
+ select(objectSchema.parse(body), ['id', 'name', 'type', 'guild_id', 'topic']),
25
+ });
@@ -0,0 +1,37 @@
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
+ import { select } from '../../../../utils/select';
6
+ import { discordChannelKind } from './discordChannelKind';
7
+
8
+ export const fetchDiscordChannelMessages = makeApiOperation({
9
+ key: 'messages.read',
10
+ idempotent: true,
11
+ response: 'json',
12
+ meta: {
13
+ name: 'Read channel messages',
14
+ resourceKind: discordChannelKind,
15
+ requiredScopes: ['VIEW_CHANNEL and READ_MESSAGE_HISTORY'],
16
+ },
17
+ input: providerOperationInputSchema(['discord'], discordChannelKind),
18
+ toRequest: ({ resource, limit }) => ({
19
+ path: 'channels/:channelId/messages',
20
+ headers: acceptJsonHeaders,
21
+ params: { channelId: resource.externalId },
22
+ query: { limit },
23
+ }),
24
+ parse: ({ body }, { limit }) => {
25
+ const messages = z.array(z.unknown()).parse(body);
26
+ return {
27
+ messages: messages.map((item) => {
28
+ const message = select(item, ['id', 'content', 'timestamp', 'type', 'author']);
29
+ return {
30
+ ...message,
31
+ author: select(message.author ?? {}, ['id', 'username', 'global_name']),
32
+ };
33
+ }),
34
+ hasMore: messages.length >= limit,
35
+ };
36
+ },
37
+ });
@@ -0,0 +1 @@
1
+ export const driveApiBaseUrl = 'https://www.googleapis.com/drive/v3/';
@@ -0,0 +1,4 @@
1
+ import { defineApiOperations } from '@inixiative/api-client/operation';
2
+ import { fetchDriveFile } from './models/file/fetchDriveFile';
3
+
4
+ export const driveOperations = defineApiOperations({ 'files.read': fetchDriveFile });
@@ -1,4 +1,7 @@
1
+ import { catalogOperations } from '../../catalog/catalogOperations';
1
2
  import type { ProviderDefinition } from '../../contracts';
3
+ import { driveApiBaseUrl } from './driveApiBaseUrl';
4
+ import { driveOperations } from './driveOperations';
2
5
 
3
6
  export const driveProvider: ProviderDefinition = {
4
7
  key: 'drive',
@@ -7,12 +10,6 @@ export const driveProvider: ProviderDefinition = {
7
10
  authMethods: ['integrationFamily'],
8
11
  integrationFamily: 'google',
9
12
  oauthScopes: ['https://www.googleapis.com/auth/drive.metadata.readonly'],
10
- operations: [
11
- {
12
- key: 'files.read',
13
- name: 'Read file metadata',
14
- resourceKind: 'file',
15
- requiredScopes: ['https://www.googleapis.com/auth/drive.metadata.readonly'],
16
- },
17
- ],
13
+ apiBaseUrl: driveApiBaseUrl,
14
+ operations: catalogOperations(driveOperations),
18
15
  };
@@ -0,0 +1,27 @@
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 = 'file';
8
+ const fields = ['id', 'name', 'mimeType', 'description', 'modifiedTime', 'size'];
9
+
10
+ export const fetchDriveFile = makeApiOperation({
11
+ key: 'files.read',
12
+ idempotent: true,
13
+ response: 'json',
14
+ meta: {
15
+ name: 'Read file metadata',
16
+ resourceKind: kind,
17
+ requiredScopes: ['https://www.googleapis.com/auth/drive.metadata.readonly'],
18
+ },
19
+ input: providerOperationInputSchema(['drive'], kind),
20
+ toRequest: ({ resource }) => ({
21
+ path: 'files/:fileId',
22
+ headers: acceptJsonHeaders,
23
+ params: { fileId: resource.externalId },
24
+ query: { fields: fields.join(','), supportsAllDrives: 'true' },
25
+ }),
26
+ parse: ({ body }) => select(objectSchema.parse(body), fields),
27
+ });
@@ -0,0 +1,19 @@
1
+ import { makeApiOperation } from '@inixiative/api-client/operation';
2
+ import { z } from 'zod';
3
+ import { githubRequestHeaders } from '../githubRequestHeaders';
4
+
5
+ export const createGithubInstallationToken = makeApiOperation({
6
+ key: 'app.installations.accessTokens.create',
7
+ idempotent: false,
8
+ response: 'json',
9
+ responseLimitBytes: 128 * 1024,
10
+ input: z.strictObject({ installationId: z.string().min(1) }),
11
+ toRequest: ({ installationId }) => ({
12
+ path: 'app/installations/:installationId/access_tokens',
13
+ method: 'POST',
14
+ params: { installationId },
15
+ headers: githubRequestHeaders,
16
+ body: { permissions: { contents: 'read' } },
17
+ }),
18
+ parse: ({ body }) => z.record(z.string(), z.unknown()).parse(body),
19
+ });
@@ -0,0 +1,21 @@
1
+ import { makeApiOperation } from '@inixiative/api-client/operation';
2
+ import { z } from 'zod';
3
+ import { githubRequestHeaders } from '../githubRequestHeaders';
4
+
5
+ const githubAppSchema = z.object({
6
+ html_url: z.url({ protocol: /^https$/, hostname: /^github\.com$/ }),
7
+ });
8
+
9
+ export const fetchGithubAppInstallUrl = makeApiOperation({
10
+ key: 'app.read',
11
+ idempotent: true,
12
+ response: 'json',
13
+ input: z.strictObject({ state: z.string().min(1) }),
14
+ toRequest: () => ({ path: 'app', headers: githubRequestHeaders }),
15
+ parse: ({ body }, { state }) => {
16
+ const { html_url } = githubAppSchema.parse(body);
17
+ const url = new URL(`${html_url.replace(/\/+$/, '')}/installations/new`);
18
+ url.searchParams.set('state', state);
19
+ return url.toString();
20
+ },
21
+ });
@@ -1,21 +1,18 @@
1
- import { ProviderError } from '../../../utils/providerError';
2
- import { requestGithub } from '../requestGithub';
3
- import type { GithubAppClient } from './githubAppClient';
4
- import { githubClientForApp } from './githubClientForApp';
1
+ import { makeApiOperation } from '@inixiative/api-client/operation';
2
+ import { z } from 'zod';
3
+ import { githubRequestHeaders } from '../githubRequestHeaders';
5
4
  import { githubInstallationSchema } from './githubInstallationSchema';
6
5
 
7
- export const fetchGithubAppInstallation = async (
8
- appClient: GithubAppClient,
9
- { installationId }: { installationId: string },
10
- ) => {
11
- try {
12
- return githubInstallationSchema.parse(
13
- await requestGithub(await githubClientForApp(appClient), {
14
- path: `/app/installations/${encodeURIComponent(installationId)}`,
15
- }),
16
- );
17
- } catch (error) {
18
- if (error instanceof ProviderError && error.code === 'provider_not_found') return null;
19
- throw error;
20
- }
21
- };
6
+ export const fetchGithubAppInstallation = makeApiOperation({
7
+ key: 'app.installations.read',
8
+ idempotent: true,
9
+ response: 'json',
10
+ readableStatuses: [404],
11
+ input: z.strictObject({ installationId: z.string().min(1) }),
12
+ toRequest: ({ installationId }) => ({
13
+ path: 'app/installations/:installationId',
14
+ params: { installationId },
15
+ headers: githubRequestHeaders,
16
+ }),
17
+ parse: ({ status, body }) => (status === 404 ? null : githubInstallationSchema.parse(body)),
18
+ });
@@ -1,27 +1,27 @@
1
+ import { ApiError } from '@inixiative/api-client';
2
+ import { readRateLimit } from '@inixiative/api-client/http';
3
+ import { makeApiOperation } from '@inixiative/api-client/operation';
1
4
  import { z } from 'zod';
2
- import type { ProviderClient } from '../../../utils/providerClient';
3
- import { ProviderError } from '../../../utils/providerError';
4
- import { requestGithub } from '../requestGithub';
5
+ import { githubRequestHeaders } from '../githubRequestHeaders';
5
6
 
6
7
  const membershipSchema = z.object({ state: z.string(), role: z.string() });
7
8
 
8
- export const fetchGithubOrganizationRole = async (
9
- client: ProviderClient,
10
- { organizationLogin }: { organizationLogin: string },
11
- ) => {
12
- try {
13
- const membership = membershipSchema.parse(
14
- await requestGithub(client, {
15
- path: `/user/memberships/orgs/${encodeURIComponent(organizationLogin)}`,
16
- }),
17
- );
9
+ export const fetchGithubOrganizationRole = makeApiOperation({
10
+ key: 'user.memberships.orgs.read',
11
+ idempotent: true,
12
+ response: 'json',
13
+ readableStatuses: [403, 404],
14
+ input: z.strictObject({ organizationLogin: z.string().min(1) }),
15
+ toRequest: ({ organizationLogin }) => ({
16
+ path: 'user/memberships/orgs/:organizationLogin',
17
+ params: { organizationLogin },
18
+ headers: githubRequestHeaders,
19
+ }),
20
+ parse: ({ status, headers, body }) => {
21
+ const { rateLimited, retryAfterMs } = readRateLimit(headers, status);
22
+ if (rateLimited) throw new ApiError('provider_rate_limited', 502, retryAfterMs);
23
+ if (status !== 200) return null;
24
+ const membership = membershipSchema.parse(body);
18
25
  return membership.state === 'active' ? membership.role : null;
19
- } catch (error) {
20
- if (
21
- error instanceof ProviderError &&
22
- ['provider_not_found', 'provider_access_denied'].includes(error.code)
23
- )
24
- return null;
25
- throw error;
26
- }
27
- };
26
+ },
27
+ });
@@ -1,11 +1,17 @@
1
+ import { makeApiOperation } from '@inixiative/api-client/operation';
1
2
  import { z } from 'zod';
2
- import type { ProviderClient } from '../../../utils/providerClient';
3
- import { requestGithub } from '../requestGithub';
3
+ import { githubRequestHeaders } from '../githubRequestHeaders';
4
4
 
5
5
  const githubUserSchema = z.object({
6
6
  id: z.number().int().positive(),
7
7
  login: z.string().min(1).max(39),
8
8
  });
9
9
 
10
- export const fetchGithubUser = async (client: ProviderClient) =>
11
- githubUserSchema.parse(await requestGithub(client, { path: '/user' }));
10
+ export const fetchGithubUser = makeApiOperation({
11
+ key: 'user.read',
12
+ idempotent: true,
13
+ response: 'json',
14
+ input: z.strictObject({}),
15
+ toRequest: () => ({ path: 'user', headers: githubRequestHeaders }),
16
+ parse: ({ body }) => githubUserSchema.parse(body),
17
+ });
@@ -0,0 +1,6 @@
1
+ import { bearerAuth } from '@inixiative/api-client/operation';
2
+ import type { SigningClient } from '../../../contracts';
3
+ import { githubAppJwt } from './githubAppJwt';
4
+
5
+ export const githubAppAuth = (app: Pick<SigningClient, 'appId' | 'privateKey'>) =>
6
+ bearerAuth(() => githubAppJwt(app));
@@ -0,0 +1,18 @@
1
+ import { makeApiOperation } from '@inixiative/api-client/operation';
2
+ import { z } from 'zod';
3
+ import { pageQuerySchema } from '../../../utils/pageQuerySchema';
4
+ import { githubPagination } from '../githubPagination';
5
+ import { githubRequestHeaders } from '../githubRequestHeaders';
6
+
7
+ export const listGithubUserInstallationPage = makeApiOperation({
8
+ key: 'user.installations.list',
9
+ idempotent: true,
10
+ response: 'json',
11
+ input: z.object({ query: pageQuerySchema(githubPagination) }),
12
+ toRequest: ({ query }) => ({
13
+ path: 'user/installations',
14
+ query: query,
15
+ headers: githubRequestHeaders,
16
+ }),
17
+ parse: ({ body }) => body,
18
+ });
@@ -0,0 +1,18 @@
1
+ import { makeApiOperation } from '@inixiative/api-client/operation';
2
+ import { z } from 'zod';
3
+ import { pageQuerySchema } from '../../../utils/pageQuerySchema';
4
+ import { githubPagination } from '../githubPagination';
5
+ import { githubRequestHeaders } from '../githubRequestHeaders';
6
+
7
+ export const listGithubNotificationPage = makeApiOperation({
8
+ key: 'notifications.list',
9
+ idempotent: true,
10
+ response: 'json',
11
+ input: z.object({ since: z.iso.datetime(), query: pageQuerySchema(githubPagination) }),
12
+ toRequest: ({ since, query }) => ({
13
+ path: 'notifications',
14
+ query: { all: 'true', participating: 'true', since, ...query },
15
+ headers: githubRequestHeaders,
16
+ }),
17
+ parse: ({ body }) => body,
18
+ });
@@ -0,0 +1 @@
1
+ export const githubApiBaseUrl = 'https://api.github.com/';
@@ -1,5 +1,8 @@
1
+ import { catalogOperations } from '../../catalog/catalogOperations';
1
2
  import type { ProviderDefinition } from '../../contracts';
3
+ import { githubApiBaseUrl } from './githubApiBaseUrl';
2
4
  import { githubRepository } from './models/repository/githubRepository';
5
+ import { githubRepositoryOperations } from './models/repository/githubRepositoryOperations';
3
6
 
4
7
  export const githubOrganizationProvider: ProviderDefinition = {
5
8
  key: 'githubOrganization',
@@ -8,6 +11,7 @@ export const githubOrganizationProvider: ProviderDefinition = {
8
11
  'https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/authenticating-as-a-github-app-installation',
9
12
  authMethods: ['clientCredentials'],
10
13
  integrationFamily: 'github',
11
- operations: [...githubRepository.operations, ...githubRepository.events],
14
+ apiBaseUrl: githubApiBaseUrl,
15
+ operations: [...catalogOperations(githubRepositoryOperations), ...githubRepository.events],
12
16
  eventResourceExternalId: githubRepository.externalIdOfEvent,
13
17
  };
@@ -1,7 +1,7 @@
1
- import type { ProviderPagination } from '../../utils/pagination/providerPagination';
1
+ import type { ApiPagination } from '@inixiative/api-client/http/pagination';
2
2
 
3
3
  export const githubPagination = {
4
4
  strategy: 'page',
5
5
  keys: { page: 'page', pageSize: 'per_page', data: '', total: 'total_count' },
6
6
  pageSize: 100,
7
- } satisfies ProviderPagination;
7
+ } satisfies ApiPagination;
@@ -1,9 +1,7 @@
1
1
  import { githubApiVersion } from './githubApiVersion';
2
2
 
3
- export const githubRequestHeaders = (headers: Headers, token?: string) => {
4
- headers.set('Accept', 'application/vnd.github+json');
5
- headers.set('X-GitHub-Api-Version', githubApiVersion);
6
- headers.set('User-Agent', 'inixiative-integrations');
7
- if (token) headers.set('Authorization', `Bearer ${token}`);
8
- return headers;
3
+ export const githubRequestHeaders = {
4
+ Accept: 'application/vnd.github+json',
5
+ 'X-GitHub-Api-Version': githubApiVersion,
6
+ 'User-Agent': 'inixiative-integrations',
9
7
  };
@@ -1,6 +1,8 @@
1
+ import { catalogOperations } from '../../catalog/catalogOperations';
1
2
  import type { ProviderDefinition } from '../../contracts';
3
+ import { githubApiBaseUrl } from './githubApiBaseUrl';
2
4
  import { githubAccount } from './models/account/githubAccount';
3
- import { githubRepository } from './models/repository/githubRepository';
5
+ import { githubRepositoryOperations } from './models/repository/githubRepositoryOperations';
4
6
 
5
7
  export const githubUserProvider: ProviderDefinition = {
6
8
  key: 'githubUser',
@@ -9,5 +11,6 @@ export const githubUserProvider: ProviderDefinition = {
9
11
  'https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/authenticating-with-a-github-app-on-behalf-of-a-user',
10
12
  authMethods: ['integrationFamily', 'bearer'],
11
13
  integrationFamily: 'github',
12
- operations: [...githubRepository.operations, ...githubAccount.events],
14
+ apiBaseUrl: githubApiBaseUrl,
15
+ operations: [...catalogOperations(githubRepositoryOperations), ...githubAccount.events],
13
16
  };
@@ -4,7 +4,6 @@ import type { ProviderModel } from '../../../../catalog/providerModel';
4
4
 
5
5
  export const githubAccount = {
6
6
  kind: accountResourceKind,
7
- operations: [],
8
7
  events: declaredOperations(
9
8
  {
10
9
  'events.notifications.mention': 'Receive the mentions of this GitHub user',