@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.
- package/README.md +21 -13
- package/package.json +4 -3
- package/src/catalog/acceptedCredentialMethods.ts +17 -0
- package/src/catalog/catalogOperationMeta.ts +4 -0
- package/src/catalog/catalogOperations.ts +10 -0
- package/src/catalog/integrationFamilies.ts +12 -0
- package/src/catalog/integrationFamilyDefinition.ts +6 -0
- package/src/catalog/isAccountSuppliedByHost.ts +2 -2
- package/src/catalog/providerAuthenticatesThroughIntegrationFamily.ts +6 -0
- package/src/catalog/providerModel.ts +0 -1
- package/src/catalog/providers.ts +0 -4
- package/src/catalog/providersInIntegrationFamily.ts +5 -0
- package/src/contracts.ts +36 -25
- package/src/credentials/credentialAuth.ts +38 -0
- package/src/credentials/credentialClient.ts +2 -2
- package/src/credentials/exchangeOauthCode.ts +41 -41
- package/src/credentials/mintProviderCredential.ts +26 -40
- package/src/credentials/providerExchangeTimeoutMs.ts +1 -1
- package/src/credentials/refreshProviderCredential.ts +102 -83
- package/src/credentials/renewalError.ts +11 -0
- package/src/credentials/renewalOwner.ts +3 -0
- package/src/credentials/requestOauthToken.ts +28 -0
- package/src/credentials/validateCredentialSecret.ts +5 -5
- package/src/index.ts +0 -1
- package/src/integrationFamilies/atlassianIntegrationFamily.ts +12 -0
- package/src/{providers/github/githubProvider.ts → integrationFamilies/githubIntegrationFamily.ts} +2 -3
- package/src/{providers/google/googleProvider.ts → integrationFamilies/googleIntegrationFamily.ts} +2 -3
- package/src/integrationFamilies/inixiativeIntegrationFamily.ts +8 -0
- package/src/operations/providerOperationInput.ts +6 -0
- package/src/operations/providerOperationInputSchema.ts +36 -0
- package/src/operations/providerOperationOrThrow.ts +23 -0
- package/src/operations/providerOperationSet.ts +7 -0
- package/src/operations/providerOperations.ts +38 -0
- package/src/providers/chorus/chorusProvider.ts +1 -0
- package/src/providers/confluence/confluenceApiBaseUrl.ts +1 -0
- package/src/providers/confluence/confluenceOperations.ts +4 -0
- package/src/providers/confluence/confluenceProvider.ts +6 -8
- package/src/providers/confluence/models/page/fetchConfluencePage.ts +23 -0
- package/src/providers/discord/discordApiBaseUrl.ts +1 -0
- package/src/providers/discord/discordOperations.ts +8 -0
- package/src/providers/discord/discordProvider.ts +5 -14
- package/src/providers/discord/models/channel/discordChannelKind.ts +1 -0
- package/src/providers/discord/models/channel/fetchDiscordChannel.ts +25 -0
- package/src/providers/discord/models/channel/fetchDiscordChannelMessages.ts +37 -0
- package/src/providers/drive/driveApiBaseUrl.ts +1 -0
- package/src/providers/drive/driveOperations.ts +4 -0
- package/src/providers/drive/driveProvider.ts +7 -10
- package/src/providers/drive/models/file/fetchDriveFile.ts +27 -0
- package/src/providers/github/auth/createGithubInstallationToken.ts +19 -0
- package/src/providers/github/auth/fetchGithubAppInstallUrl.ts +21 -0
- package/src/providers/github/auth/fetchGithubAppInstallation.ts +16 -19
- package/src/providers/github/auth/fetchGithubOrganizationRole.ts +22 -22
- package/src/providers/github/auth/fetchGithubUser.ts +10 -4
- package/src/providers/github/auth/githubAppAuth.ts +6 -0
- package/src/providers/github/auth/githubUserAuthorizeUrl.ts +2 -2
- package/src/providers/github/auth/listGithubUserInstallationPage.ts +18 -0
- package/src/providers/github/events/listGithubNotificationPage.ts +18 -0
- package/src/providers/github/githubApiBaseUrl.ts +1 -0
- package/src/providers/github/githubOrganizationProvider.ts +6 -2
- package/src/providers/github/githubPagination.ts +2 -2
- package/src/providers/github/githubRequestHeaders.ts +4 -6
- package/src/providers/github/githubUserProvider.ts +7 -4
- package/src/providers/github/models/account/githubAccount.ts +0 -1
- package/src/providers/github/models/repository/fetchGithubBlob.ts +59 -0
- package/src/providers/github/models/repository/fetchGithubCommit.ts +38 -0
- package/src/providers/github/models/repository/fetchGithubTree.ts +74 -0
- package/src/providers/github/models/repository/githubObjectRequest.ts +15 -0
- package/src/providers/github/models/repository/githubRepository.ts +1 -11
- package/src/providers/github/models/repository/githubRepositoryOperations.ts +10 -0
- package/src/providers/github/models/repository/listGithubInstallationRepositoryPage.ts +18 -0
- package/src/providers/github/models/repository/listGithubUserInstallationRepositoryPage.ts +22 -0
- package/src/providers/github/models/repository/readGithubObjectIdentity.ts +9 -0
- package/src/providers/github/services/fetchGithubUserInstallation.ts +25 -0
- package/src/providers/github/services/listGithubNotifications.ts +27 -0
- package/src/providers/github/services/listInstallationRepositories.ts +34 -0
- package/src/providers/github/services/listUserRepositories.ts +43 -0
- package/src/providers/gmail/gmailApiBaseUrl.ts +1 -0
- package/src/providers/gmail/gmailOperations.ts +10 -0
- package/src/providers/gmail/gmailProvider.ts +8 -11
- package/src/providers/gmail/models/label/listGmailLabelMessages.ts +45 -0
- package/src/providers/gmail/models/message/fetchGmailMessage.ts +19 -0
- package/src/providers/gmail/models/message/fetchGmailMessageBatch.ts +20 -0
- package/src/providers/gmail/models/message/gmailMessageKind.ts +1 -0
- package/src/providers/gmail/models/message/gmailMessageRequest.ts +9 -0
- package/src/providers/gmail/models/message/readGmailMessage.ts +26 -0
- package/src/providers/google/auth/buildGoogleAuthorizationUrl.ts +2 -1
- package/src/providers/google/auth/verifyGoogleIdToken.ts +3 -3
- package/src/providers/jira/jiraApiBaseUrl.ts +1 -0
- package/src/providers/jira/jiraOperations.ts +4 -0
- package/src/providers/jira/jiraProvider.ts +6 -8
- package/src/providers/jira/models/issue/fetchJiraIssue.ts +22 -0
- package/src/providers/linear/events/createLinearWebhook.ts +29 -20
- package/src/providers/linear/events/deleteLinearWebhook.ts +16 -9
- package/src/providers/linear/events/linearWebhook.ts +1 -1
- package/src/providers/linear/events/listLinearWebhookPage.ts +23 -0
- package/src/providers/linear/events/repairLinearWebhook.ts +17 -13
- package/src/providers/linear/linearApiBaseUrl.ts +1 -0
- package/src/providers/linear/linearGraphqlErrorCode.ts +8 -0
- package/src/providers/linear/linearOperations.ts +4 -0
- package/src/providers/linear/linearPagination.ts +3 -9
- package/src/providers/linear/linearProvider.ts +5 -2
- package/src/providers/linear/models/issue/fetchLinearIssue.ts +32 -0
- package/src/providers/linear/models/team/fetchLinearWorkspace.ts +23 -13
- package/src/providers/linear/models/team/linearTeam.ts +0 -1
- package/src/providers/linear/services/listLinearWebhooks.ts +45 -0
- package/src/providers/notion/models/page/fetchNotionPage.ts +32 -0
- package/src/providers/notion/models/page/fetchNotionPageBlocks.ts +39 -0
- package/src/providers/notion/models/page/notionPageKind.ts +1 -0
- package/src/providers/notion/notionApiBaseUrl.ts +1 -0
- package/src/providers/notion/notionOperations.ts +8 -0
- package/src/providers/notion/notionProvider.ts +5 -14
- package/src/providers/notion/notionVersion.ts +1 -0
- package/src/providers/oracle/oracleProvider.ts +1 -0
- package/src/providers/slack/auth/fetchSlackIdentity.ts +14 -6
- package/src/providers/slack/models/account/slackAccount.ts +0 -1
- package/src/providers/slack/models/channel/fetchSlackChannel.ts +32 -0
- package/src/providers/slack/models/channel/fetchSlackChannelMessages.ts +34 -0
- package/src/providers/slack/models/channel/listSlackUserConversations.ts +19 -0
- package/src/providers/slack/models/channel/slackChannel.ts +0 -14
- package/src/providers/slack/readSlackBody.ts +10 -0
- package/src/providers/slack/services/listSlackChannels.ts +23 -0
- package/src/providers/slack/slackApiBaseUrl.ts +1 -0
- package/src/providers/slack/slackOperations.ts +8 -0
- package/src/providers/slack/slackPagination.ts +2 -2
- package/src/providers/slack/slackProvider.ts +9 -1
- package/src/providers/slack/slackProviderError.ts +2 -2
- package/src/providers/teams/models/channel/fetchTeamsChannelMessages.ts +36 -0
- package/src/providers/teams/teamsApiBaseUrl.ts +1 -0
- package/src/providers/teams/teamsOperations.ts +6 -0
- package/src/providers/teams/teamsProvider.ts +5 -8
- package/src/utils/acceptJsonHeaders.ts +1 -0
- package/src/utils/pageQuerySchema.ts +13 -0
- package/src/utils/readProviderLimits.ts +1 -2
- package/src/catalog/familyProducts.ts +0 -5
- package/src/catalog/isFamilyManaged.ts +0 -7
- package/src/catalog/providerFamily.ts +0 -4
- package/src/credentials/fetchRenewalResponse.ts +0 -41
- package/src/credentials/renewalRequest.ts +0 -1
- package/src/operations/buildProviderRequest.ts +0 -54
- package/src/operations/executeProvider.ts +0 -26
- package/src/operations/findOperationHandler.ts +0 -6
- package/src/operations/operationHandler.ts +0 -8
- package/src/operations/operationHandlers.ts +0 -41
- package/src/operations/operationRequestInput.ts +0 -12
- package/src/operations/providerRequestSpec.ts +0 -1
- package/src/providers/confluence/confluenceOperationHandler.ts +0 -14
- package/src/providers/discord/discordOperationHandler.ts +0 -30
- package/src/providers/drive/driveOperationHandler.ts +0 -21
- package/src/providers/github/auth/fetchGithubUserInstallation.ts +0 -21
- package/src/providers/github/auth/githubAppClient.ts +0 -4
- package/src/providers/github/auth/githubAppInstallUrl.ts +0 -20
- package/src/providers/github/auth/githubClientForApp.ts +0 -11
- package/src/providers/github/events/listGithubNotifications.ts +0 -27
- package/src/providers/github/fetchAllGithubPages.ts +0 -12
- package/src/providers/github/iterateGithubPages.ts +0 -12
- package/src/providers/github/models/repository/githubOperationHandler.ts +0 -36
- package/src/providers/github/models/repository/listInstallationRepositories.ts +0 -31
- package/src/providers/github/models/repository/listUserRepositories.ts +0 -36
- package/src/providers/github/models/repository/readGithubObject.ts +0 -85
- package/src/providers/github/requestGithub.ts +0 -18
- package/src/providers/gmail/buildGmailMessageRequest.ts +0 -22
- package/src/providers/gmail/fetchGmailMessages.ts +0 -81
- package/src/providers/gmail/gmailOperationHandler.ts +0 -12
- package/src/providers/jira/jiraOperationHandler.ts +0 -14
- package/src/providers/linear/events/listLinearWebhooks.ts +0 -44
- package/src/providers/linear/fetchAllLinearPages.ts +0 -40
- package/src/providers/linear/linearClient.ts +0 -5
- package/src/providers/linear/linearRequestInput.ts +0 -1
- package/src/providers/linear/models/issue/linearIssue.ts +0 -11
- package/src/providers/linear/models/issue/linearOperationHandler.ts +0 -30
- package/src/providers/linear/requestLinear.ts +0 -51
- package/src/providers/notion/notionOperationHandler.ts +0 -32
- package/src/providers/slack/fetchAllSlackPages.ts +0 -12
- package/src/providers/slack/models/channel/listSlackChannels.ts +0 -26
- package/src/providers/slack/models/channel/slackOperationHandler.ts +0 -30
- package/src/providers/slack/requestSlack.ts +0 -22
- package/src/providers/teams/teamsOperationHandler.ts +0 -24
- package/src/utils/headerNumber.ts +0 -6
- package/src/utils/pagination/applyCaps.ts +0 -18
- package/src/utils/pagination/byCursorKeys.ts +0 -7
- package/src/utils/pagination/byCursorOptions.ts +0 -7
- package/src/utils/pagination/byPageKeys.ts +0 -7
- package/src/utils/pagination/byPageOptions.ts +0 -8
- package/src/utils/pagination/collectPages.ts +0 -27
- package/src/utils/pagination/compactRequest.ts +0 -4
- package/src/utils/pagination/fetchAllByCursor.ts +0 -6
- package/src/utils/pagination/fetchAllByPage.ts +0 -6
- package/src/utils/pagination/fetchAllRequestPages.ts +0 -16
- package/src/utils/pagination/incompletePageWalkError.ts +0 -8
- package/src/utils/pagination/isAnotherPage.ts +0 -20
- package/src/utils/pagination/iterateByCursor.ts +0 -49
- package/src/utils/pagination/iterateByPage.ts +0 -59
- package/src/utils/pagination/iterateProviderPages.ts +0 -27
- package/src/utils/pagination/iterateRequestPages.ts +0 -18
- package/src/utils/pagination/pageWalkError.ts +0 -6
- package/src/utils/pagination/paginationOptions.ts +0 -9
- package/src/utils/pagination/providerPagesOptions.ts +0 -8
- package/src/utils/pagination/providerPagination.ts +0 -6
- package/src/utils/pagination/readPage.ts +0 -29
- package/src/utils/pagination/readPath.ts +0 -12
- package/src/utils/pagination/repeatedCursorError.ts +0 -10
- package/src/utils/providerClient.ts +0 -3
- package/src/utils/providerError.ts +0 -10
- package/src/utils/providerRequest.ts +0 -22
- package/src/utils/providerRequestInput.ts +0 -7
- package/src/utils/providerResponseLimit.ts +0 -1
- package/src/utils/providerSend.ts +0 -1
- package/src/utils/readProviderJson.ts +0 -38
- package/src/utils/readRateLimit.ts +0 -29
- package/src/utils/requestProviderJson.ts +0 -13
- package/src/utils/responseBudget.ts +0 -1
- package/src/utils/sendProviderRequest.ts +0 -33
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import { ProviderError } from '../utils/providerError';
|
|
3
|
-
import { readProviderJson } from '../utils/readProviderJson';
|
|
4
|
-
import { PROVIDER_EXCHANGE_TIMEOUT_MS } from './providerExchangeTimeoutMs';
|
|
5
|
-
import type { RenewalRequest } from './renewalRequest';
|
|
6
|
-
|
|
7
|
-
export const fetchRenewalResponse = async (
|
|
8
|
-
send: (request: Request) => Promise<Response>,
|
|
9
|
-
request: RenewalRequest,
|
|
10
|
-
) => {
|
|
11
|
-
let response: Response;
|
|
12
|
-
try {
|
|
13
|
-
response = await send(
|
|
14
|
-
new Request(request.url, {
|
|
15
|
-
method: 'POST',
|
|
16
|
-
headers: request.headers,
|
|
17
|
-
body: request.body,
|
|
18
|
-
redirect: 'error',
|
|
19
|
-
signal: AbortSignal.timeout(PROVIDER_EXCHANGE_TIMEOUT_MS),
|
|
20
|
-
}),
|
|
21
|
-
);
|
|
22
|
-
} catch {
|
|
23
|
-
throw new ProviderError('renewal_outcome_unknown', 409);
|
|
24
|
-
}
|
|
25
|
-
if (response.status === 429 || response.status >= 500) {
|
|
26
|
-
await response.body?.cancel();
|
|
27
|
-
throw new ProviderError('renewal_temporarily_unavailable', 503);
|
|
28
|
-
}
|
|
29
|
-
if (!response.ok) {
|
|
30
|
-
await response.body?.cancel();
|
|
31
|
-
throw new ProviderError('renewal_rejected', 409);
|
|
32
|
-
}
|
|
33
|
-
if (!response.body) throw new ProviderError('renewal_outcome_unknown', 409);
|
|
34
|
-
try {
|
|
35
|
-
return z
|
|
36
|
-
.record(z.string(), z.unknown())
|
|
37
|
-
.parse(await readProviderJson(response, { remainingBytes: 128 * 1024 }));
|
|
38
|
-
} catch {
|
|
39
|
-
throw new ProviderError('renewal_outcome_unknown', 409);
|
|
40
|
-
}
|
|
41
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export type RenewalRequest = { url: string; headers: Headers; body: string };
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import { isUncalledLeaf } from '../catalog/isUncalledLeaf';
|
|
3
|
-
import { providers } from '../catalog/providers';
|
|
4
|
-
import type { ProviderContext } from '../contracts';
|
|
5
|
-
import { credentialSecretSchema } from '../contracts';
|
|
6
|
-
import { integrationConfigurationSchemas } from '../resources/integrationConfigurationSchemas';
|
|
7
|
-
import { resourceExternalIdSchemas } from '../resources/resourceExternalIdSchemas';
|
|
8
|
-
import { resourceMetadataSchemas } from '../resources/resourceMetadataSchemas';
|
|
9
|
-
import { ProviderError } from '../utils/providerError';
|
|
10
|
-
import { findOperationHandler } from './findOperationHandler';
|
|
11
|
-
|
|
12
|
-
export const buildProviderRequest = (
|
|
13
|
-
context: ProviderContext,
|
|
14
|
-
signal: AbortSignal = AbortSignal.timeout(15000),
|
|
15
|
-
): Request => {
|
|
16
|
-
const definition = providers.find((item) => item.key === context.provider);
|
|
17
|
-
const operation = definition?.operations.find((item) => item.key === context.operation);
|
|
18
|
-
if (!definition || !operation || operation.resourceKind !== context.resource.kind)
|
|
19
|
-
throw new ProviderError('unsupported_operation', 400);
|
|
20
|
-
if (isUncalledLeaf(operation.key)) throw new ProviderError('unsupported_integration', 400);
|
|
21
|
-
if (!definition.authMethods.includes(context.method))
|
|
22
|
-
throw new ProviderError('unsupported_authentication', 400);
|
|
23
|
-
const configuration = integrationConfigurationSchemas[definition.key].parse(
|
|
24
|
-
context.configuration,
|
|
25
|
-
);
|
|
26
|
-
const metadata = resourceMetadataSchemas[definition.key].parse(context.resource.metadata);
|
|
27
|
-
const externalId = resourceExternalIdSchemas[definition.key].parse(context.resource.externalId);
|
|
28
|
-
const id = encodeURIComponent(externalId);
|
|
29
|
-
const limit = z.number().int().min(1).max(50).parse(context.limit);
|
|
30
|
-
const secret = credentialSecretSchema.parse(context.secret);
|
|
31
|
-
const headers = new Headers({
|
|
32
|
-
Accept: 'application/json',
|
|
33
|
-
Authorization: context.method === 'apiKey' ? secret.token : `Bearer ${secret.token}`,
|
|
34
|
-
});
|
|
35
|
-
const client = findOperationHandler(definition.key);
|
|
36
|
-
if (!client) throw new ProviderError('unsupported_integration', 400);
|
|
37
|
-
const { url, body } = client.request({
|
|
38
|
-
context,
|
|
39
|
-
configuration: configuration as Record<string, unknown>,
|
|
40
|
-
metadata: metadata as Record<string, unknown>,
|
|
41
|
-
externalId,
|
|
42
|
-
id,
|
|
43
|
-
limit,
|
|
44
|
-
token: secret.token,
|
|
45
|
-
headers,
|
|
46
|
-
});
|
|
47
|
-
return new Request(url.toString(), {
|
|
48
|
-
method: body ? 'POST' : 'GET',
|
|
49
|
-
headers,
|
|
50
|
-
body,
|
|
51
|
-
redirect: 'error',
|
|
52
|
-
signal,
|
|
53
|
-
});
|
|
54
|
-
};
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import type { ProviderContext } from '../contracts';
|
|
2
|
-
import { fetchGmailMessages } from '../providers/gmail/fetchGmailMessages';
|
|
3
|
-
import { ProviderError } from '../utils/providerError';
|
|
4
|
-
import type { ProviderSend } from '../utils/providerSend';
|
|
5
|
-
import { requestProviderJson } from '../utils/requestProviderJson';
|
|
6
|
-
import { buildProviderRequest } from './buildProviderRequest';
|
|
7
|
-
import { findOperationHandler } from './findOperationHandler';
|
|
8
|
-
|
|
9
|
-
export const executeProvider = async (
|
|
10
|
-
{ send = fetch }: { send?: ProviderSend },
|
|
11
|
-
context: ProviderContext,
|
|
12
|
-
{ signal = AbortSignal.timeout(15000) }: { signal?: AbortSignal } = {},
|
|
13
|
-
): Promise<unknown> => {
|
|
14
|
-
const request = buildProviderRequest(context, signal);
|
|
15
|
-
const handler = findOperationHandler(context.provider);
|
|
16
|
-
if (!handler) throw new ProviderError('unsupported_integration', 400);
|
|
17
|
-
try {
|
|
18
|
-
// why: Gmail lists a label and then fetches each message under one byte budget.
|
|
19
|
-
if (context.provider === 'gmail')
|
|
20
|
-
return await fetchGmailMessages({ send }, { listRequest: request, context });
|
|
21
|
-
return handler.parse(await requestProviderJson(send, request), context);
|
|
22
|
-
} catch (error) {
|
|
23
|
-
if (error instanceof ProviderError) throw error;
|
|
24
|
-
throw new ProviderError('provider_invalid_response');
|
|
25
|
-
}
|
|
26
|
-
};
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { Provider } from '../contracts';
|
|
2
|
-
import type { OperationHandler } from './operationHandler';
|
|
3
|
-
import { operationHandlers } from './operationHandlers';
|
|
4
|
-
|
|
5
|
-
export const findOperationHandler = (key: string): OperationHandler | null =>
|
|
6
|
-
operationHandlers[key as Provider] ?? null;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { ProviderContext } from '../contracts';
|
|
2
|
-
import type { OperationRequestInput } from './operationRequestInput';
|
|
3
|
-
import type { ProviderRequestSpec } from './providerRequestSpec';
|
|
4
|
-
|
|
5
|
-
export type OperationHandler = {
|
|
6
|
-
request(input: OperationRequestInput): ProviderRequestSpec;
|
|
7
|
-
parse(body: unknown, context: ProviderContext): unknown;
|
|
8
|
-
};
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import type { Provider } from '../contracts';
|
|
2
|
-
import { confluenceOperationHandler } from '../providers/confluence/confluenceOperationHandler';
|
|
3
|
-
import { discordOperationHandler } from '../providers/discord/discordOperationHandler';
|
|
4
|
-
import { driveOperationHandler } from '../providers/drive/driveOperationHandler';
|
|
5
|
-
import { githubOperationHandler } from '../providers/github/models/repository/githubOperationHandler';
|
|
6
|
-
import { gmailOperationHandler } from '../providers/gmail/gmailOperationHandler';
|
|
7
|
-
import { jiraOperationHandler } from '../providers/jira/jiraOperationHandler';
|
|
8
|
-
import { linearOperationHandler } from '../providers/linear/models/issue/linearOperationHandler';
|
|
9
|
-
import { notionOperationHandler } from '../providers/notion/notionOperationHandler';
|
|
10
|
-
import { slackOperationHandler } from '../providers/slack/models/channel/slackOperationHandler';
|
|
11
|
-
import { teamsOperationHandler } from '../providers/teams/teamsOperationHandler';
|
|
12
|
-
import type { OperationHandler } from './operationHandler';
|
|
13
|
-
|
|
14
|
-
// why: null marks a provider reached outside the generic HTTP path (own client, Signet, family, or admitted elsewhere).
|
|
15
|
-
export const operationHandlers: Record<Provider, OperationHandler | null> = {
|
|
16
|
-
slack: slackOperationHandler,
|
|
17
|
-
discord: discordOperationHandler,
|
|
18
|
-
teams: teamsOperationHandler,
|
|
19
|
-
linear: linearOperationHandler,
|
|
20
|
-
notion: notionOperationHandler,
|
|
21
|
-
jira: jiraOperationHandler,
|
|
22
|
-
drive: driveOperationHandler,
|
|
23
|
-
confluence: confluenceOperationHandler,
|
|
24
|
-
github: null,
|
|
25
|
-
githubOrganization: githubOperationHandler,
|
|
26
|
-
githubUser: githubOperationHandler,
|
|
27
|
-
google: null,
|
|
28
|
-
anthropic: null,
|
|
29
|
-
openai: null,
|
|
30
|
-
geminiApi: null,
|
|
31
|
-
archive: null,
|
|
32
|
-
gmail: gmailOperationHandler,
|
|
33
|
-
foundry: null,
|
|
34
|
-
oracle: null,
|
|
35
|
-
chorus: null,
|
|
36
|
-
railway: null,
|
|
37
|
-
render: null,
|
|
38
|
-
claude: null,
|
|
39
|
-
codex: null,
|
|
40
|
-
muse: null,
|
|
41
|
-
};
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { ProviderContext } from '../contracts';
|
|
2
|
-
|
|
3
|
-
export type OperationRequestInput = {
|
|
4
|
-
context: ProviderContext;
|
|
5
|
-
configuration: Record<string, unknown>;
|
|
6
|
-
metadata: Record<string, unknown>;
|
|
7
|
-
externalId: string;
|
|
8
|
-
id: string;
|
|
9
|
-
limit: number;
|
|
10
|
-
token: string;
|
|
11
|
-
headers: Headers;
|
|
12
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export type ProviderRequestSpec = { url: URL; body?: string };
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { OperationHandler } from '../../operations/operationHandler';
|
|
2
|
-
import { objectSchema } from '../../utils/objectSchema';
|
|
3
|
-
import { select } from '../../utils/select';
|
|
4
|
-
|
|
5
|
-
export const confluenceOperationHandler: OperationHandler = {
|
|
6
|
-
request: ({ configuration, id }) => {
|
|
7
|
-
const url = new URL(
|
|
8
|
-
`https://api.atlassian.com/ex/confluence/${'cloudId' in configuration ? configuration.cloudId : ''}/wiki/api/v2/pages/${id}`,
|
|
9
|
-
);
|
|
10
|
-
url.searchParams.set('body-format', 'storage');
|
|
11
|
-
return { url };
|
|
12
|
-
},
|
|
13
|
-
parse: (body) => select(objectSchema.parse(body), ['id', 'title', 'status', 'body', 'version']),
|
|
14
|
-
};
|
|
@@ -1,30 +0,0 @@
|
|
|
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 discordOperationHandler: OperationHandler = {
|
|
7
|
-
request: ({ context, id, limit, headers, token }) => {
|
|
8
|
-
headers.set('Authorization', `Bot ${token}`);
|
|
9
|
-
const url = new URL(
|
|
10
|
-
`https://discord.com/api/v10/channels/${id}${context.operation === 'messages.read' ? '/messages' : ''}`,
|
|
11
|
-
);
|
|
12
|
-
if (context.operation === 'messages.read') url.searchParams.set('limit', String(limit));
|
|
13
|
-
return { url };
|
|
14
|
-
},
|
|
15
|
-
parse: (body, context) => {
|
|
16
|
-
if (context.operation !== 'messages.read')
|
|
17
|
-
return select(objectSchema.parse(body), ['id', 'name', 'type', 'guild_id', 'topic']);
|
|
18
|
-
const messages = z.array(z.unknown()).parse(body);
|
|
19
|
-
return {
|
|
20
|
-
messages: messages.map((item) => {
|
|
21
|
-
const message = select(item, ['id', 'content', 'timestamp', 'type', 'author']);
|
|
22
|
-
return {
|
|
23
|
-
...message,
|
|
24
|
-
author: select(message.author ?? {}, ['id', 'username', 'global_name']),
|
|
25
|
-
};
|
|
26
|
-
}),
|
|
27
|
-
hasMore: messages.length >= context.limit,
|
|
28
|
-
};
|
|
29
|
-
},
|
|
30
|
-
};
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { OperationHandler } from '../../operations/operationHandler';
|
|
2
|
-
import { objectSchema } from '../../utils/objectSchema';
|
|
3
|
-
import { select } from '../../utils/select';
|
|
4
|
-
|
|
5
|
-
export const driveOperationHandler: OperationHandler = {
|
|
6
|
-
request: ({ id }) => {
|
|
7
|
-
const url = new URL(`https://www.googleapis.com/drive/v3/files/${id}`);
|
|
8
|
-
url.searchParams.set('fields', 'id,name,mimeType,description,modifiedTime,size');
|
|
9
|
-
url.searchParams.set('supportsAllDrives', 'true');
|
|
10
|
-
return { url };
|
|
11
|
-
},
|
|
12
|
-
parse: (body) =>
|
|
13
|
-
select(objectSchema.parse(body), [
|
|
14
|
-
'id',
|
|
15
|
-
'name',
|
|
16
|
-
'mimeType',
|
|
17
|
-
'description',
|
|
18
|
-
'modifiedTime',
|
|
19
|
-
'size',
|
|
20
|
-
]),
|
|
21
|
-
};
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { ProviderClient } from '../../../utils/providerClient';
|
|
2
|
-
import { iterateGithubPages } from '../iterateGithubPages';
|
|
3
|
-
import { githubInstallationSchema } from './githubInstallationSchema';
|
|
4
|
-
|
|
5
|
-
export const fetchGithubUserInstallation = async (
|
|
6
|
-
client: ProviderClient,
|
|
7
|
-
{ installationId }: { installationId: string },
|
|
8
|
-
) => {
|
|
9
|
-
const pages = iterateGithubPages(
|
|
10
|
-
client,
|
|
11
|
-
{ path: '/user/installations' },
|
|
12
|
-
{ keys: { data: 'installations' }, maxPages: 10 },
|
|
13
|
-
);
|
|
14
|
-
for await (const { items } of pages)
|
|
15
|
-
for (const candidate of items) {
|
|
16
|
-
const installation = githubInstallationSchema.safeParse(candidate);
|
|
17
|
-
if (installation.success && String(installation.data.id) === installationId)
|
|
18
|
-
return installation.data;
|
|
19
|
-
}
|
|
20
|
-
return null;
|
|
21
|
-
};
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import { requestGithub } from '../requestGithub';
|
|
3
|
-
import type { GithubAppClient } from './githubAppClient';
|
|
4
|
-
import { githubClientForApp } from './githubClientForApp';
|
|
5
|
-
|
|
6
|
-
const githubAppSchema = z.object({
|
|
7
|
-
html_url: z.url({ protocol: /^https$/, hostname: /^github\.com$/ }),
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
export const githubAppInstallUrl = async (
|
|
11
|
-
appClient: GithubAppClient,
|
|
12
|
-
{ state }: { state: string },
|
|
13
|
-
) => {
|
|
14
|
-
const { html_url } = githubAppSchema.parse(
|
|
15
|
-
await requestGithub(await githubClientForApp(appClient), { path: '/app' }),
|
|
16
|
-
);
|
|
17
|
-
const url = new URL(`${html_url.replace(/\/+$/, '')}/installations/new`);
|
|
18
|
-
url.searchParams.set('state', state);
|
|
19
|
-
return url.toString();
|
|
20
|
-
};
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { ProviderClient } from '../../../utils/providerClient';
|
|
2
|
-
import type { GithubAppClient } from './githubAppClient';
|
|
3
|
-
import { githubAppJwt } from './githubAppJwt';
|
|
4
|
-
|
|
5
|
-
export const githubClientForApp = async ({
|
|
6
|
-
app,
|
|
7
|
-
send,
|
|
8
|
-
}: GithubAppClient): Promise<ProviderClient> => ({
|
|
9
|
-
token: await githubAppJwt(app),
|
|
10
|
-
send,
|
|
11
|
-
});
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import type { ProviderClient } from '../../../utils/providerClient';
|
|
3
|
-
import { fetchAllGithubPages } from '../fetchAllGithubPages';
|
|
4
|
-
import { githubNotificationSchema } from './githubNotificationSchema';
|
|
5
|
-
|
|
6
|
-
export const listGithubNotifications = async (
|
|
7
|
-
client: ProviderClient,
|
|
8
|
-
{ since }: { since: Date },
|
|
9
|
-
) => {
|
|
10
|
-
let truncated = false;
|
|
11
|
-
const notifications = z.array(githubNotificationSchema).parse(
|
|
12
|
-
await fetchAllGithubPages(
|
|
13
|
-
client,
|
|
14
|
-
{
|
|
15
|
-
path: '/notifications',
|
|
16
|
-
query: { all: 'true', participating: 'true', since: since.toISOString(), per_page: 50 },
|
|
17
|
-
},
|
|
18
|
-
{
|
|
19
|
-
maxPages: 10,
|
|
20
|
-
onCapped: () => {
|
|
21
|
-
truncated = true;
|
|
22
|
-
},
|
|
23
|
-
},
|
|
24
|
-
),
|
|
25
|
-
);
|
|
26
|
-
return { notifications, truncated };
|
|
27
|
-
};
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { fetchAllRequestPages } from '../../utils/pagination/fetchAllRequestPages';
|
|
2
|
-
import type { ProviderPagesOptions } from '../../utils/pagination/providerPagesOptions';
|
|
3
|
-
import type { ProviderClient } from '../../utils/providerClient';
|
|
4
|
-
import type { ProviderRequestInput } from '../../utils/providerRequestInput';
|
|
5
|
-
import { githubPagination } from './githubPagination';
|
|
6
|
-
import { requestGithub } from './requestGithub';
|
|
7
|
-
|
|
8
|
-
export const fetchAllGithubPages = (
|
|
9
|
-
client: ProviderClient,
|
|
10
|
-
input: ProviderRequestInput,
|
|
11
|
-
options?: ProviderPagesOptions,
|
|
12
|
-
) => fetchAllRequestPages(githubPagination, (page) => requestGithub(client, page), input, options);
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { iterateRequestPages } from '../../utils/pagination/iterateRequestPages';
|
|
2
|
-
import type { ProviderPagesOptions } from '../../utils/pagination/providerPagesOptions';
|
|
3
|
-
import type { ProviderClient } from '../../utils/providerClient';
|
|
4
|
-
import type { ProviderRequestInput } from '../../utils/providerRequestInput';
|
|
5
|
-
import { githubPagination } from './githubPagination';
|
|
6
|
-
import { requestGithub } from './requestGithub';
|
|
7
|
-
|
|
8
|
-
export const iterateGithubPages = (
|
|
9
|
-
client: ProviderClient,
|
|
10
|
-
input: ProviderRequestInput,
|
|
11
|
-
options?: ProviderPagesOptions,
|
|
12
|
-
) => iterateRequestPages(githubPagination, (page) => requestGithub(client, page), input, options);
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { githubInputSchemas, githubOperationSchema } from '@inixiative/signet/contracts';
|
|
2
|
-
import type { OperationHandler } from '../../../../operations/operationHandler';
|
|
3
|
-
import { objectSchema } from '../../../../utils/objectSchema';
|
|
4
|
-
import { githubRequestHeaders } from '../../githubRequestHeaders';
|
|
5
|
-
import { githubRepositoryMetadataSchema } from './githubRepositoryMetadataSchema';
|
|
6
|
-
import { readGithubObject } from './readGithubObject';
|
|
7
|
-
|
|
8
|
-
const objectKinds = {
|
|
9
|
-
'commits.read': 'commits',
|
|
10
|
-
'trees.read': 'trees',
|
|
11
|
-
'blobs.read': 'blobs',
|
|
12
|
-
} as const;
|
|
13
|
-
|
|
14
|
-
const requestedObject = (operation: string, input: Record<string, unknown>) => {
|
|
15
|
-
const declared = githubOperationSchema.parse(operation);
|
|
16
|
-
return { declared, objectId: githubInputSchemas[declared].parse(input).objectId };
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export const githubOperationHandler: OperationHandler = {
|
|
20
|
-
request: ({ context, metadata, headers }) => {
|
|
21
|
-
const { declared, objectId } = requestedObject(context.operation, context.input);
|
|
22
|
-
const { fullName } = githubRepositoryMetadataSchema.parse(metadata);
|
|
23
|
-
githubRequestHeaders(headers);
|
|
24
|
-
return {
|
|
25
|
-
url: new URL(
|
|
26
|
-
`https://api.github.com/repos/${fullName}/git/${objectKinds[declared]}/${objectId}`,
|
|
27
|
-
),
|
|
28
|
-
};
|
|
29
|
-
},
|
|
30
|
-
parse: (body, context) =>
|
|
31
|
-
readGithubObject(
|
|
32
|
-
objectSchema.parse(body),
|
|
33
|
-
context,
|
|
34
|
-
requestedObject(context.operation, context.input).objectId,
|
|
35
|
-
),
|
|
36
|
-
};
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import { providerResourceLimit } from '../../../../contracts';
|
|
3
|
-
import type { ProviderClient } from '../../../../utils/providerClient';
|
|
4
|
-
import { ProviderError } from '../../../../utils/providerError';
|
|
5
|
-
import { fetchAllGithubPages } from '../../fetchAllGithubPages';
|
|
6
|
-
import { githubRepositoryName } from './githubRepositoryName';
|
|
7
|
-
|
|
8
|
-
const totalSchema = z.object({ total_count: z.number().int().min(0) });
|
|
9
|
-
const repositoriesSchema = z.array(
|
|
10
|
-
z.object({ id: z.number().int().positive(), full_name: z.string() }),
|
|
11
|
-
);
|
|
12
|
-
|
|
13
|
-
export const listInstallationRepositories = async (client: ProviderClient) => {
|
|
14
|
-
const repositories = repositoriesSchema.parse(
|
|
15
|
-
await fetchAllGithubPages(
|
|
16
|
-
client,
|
|
17
|
-
{ path: '/installation/repositories' },
|
|
18
|
-
{
|
|
19
|
-
keys: { data: 'repositories' },
|
|
20
|
-
onResponse: (response) => {
|
|
21
|
-
if (totalSchema.parse(response).total_count > providerResourceLimit)
|
|
22
|
-
throw new ProviderError('too_many_repositories', 409);
|
|
23
|
-
},
|
|
24
|
-
},
|
|
25
|
-
),
|
|
26
|
-
);
|
|
27
|
-
const listed = new Map(
|
|
28
|
-
repositories.map(({ id, full_name }) => [String(id), githubRepositoryName(full_name)]),
|
|
29
|
-
);
|
|
30
|
-
return [...listed].map(([id, fullName]) => ({ id, fullName }));
|
|
31
|
-
};
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import { providerResourceLimit } from '../../../../contracts';
|
|
3
|
-
import type { ProviderClient } from '../../../../utils/providerClient';
|
|
4
|
-
import { ProviderError } from '../../../../utils/providerError';
|
|
5
|
-
import { fetchAllGithubPages } from '../../fetchAllGithubPages';
|
|
6
|
-
import { githubRepositoryName } from './githubRepositoryName';
|
|
7
|
-
|
|
8
|
-
const installationsSchema = z.array(z.object({ id: z.number().int().positive() }));
|
|
9
|
-
const repositoriesSchema = z.array(
|
|
10
|
-
z.object({ id: z.number().int().positive(), full_name: z.string() }),
|
|
11
|
-
);
|
|
12
|
-
|
|
13
|
-
// why: a GitHub App user token reaches only repositories in the App's installations the user sees.
|
|
14
|
-
export const listUserRepositories = async (client: ProviderClient) => {
|
|
15
|
-
const installations = installationsSchema.parse(
|
|
16
|
-
await fetchAllGithubPages(
|
|
17
|
-
client,
|
|
18
|
-
{ path: '/user/installations' },
|
|
19
|
-
{ keys: { data: 'installations' } },
|
|
20
|
-
),
|
|
21
|
-
);
|
|
22
|
-
const listed = new Map<string, string>();
|
|
23
|
-
for (const installation of installations) {
|
|
24
|
-
const repositories = repositoriesSchema.parse(
|
|
25
|
-
await fetchAllGithubPages(
|
|
26
|
-
client,
|
|
27
|
-
{ path: `/user/installations/${installation.id}/repositories` },
|
|
28
|
-
{ keys: { data: 'repositories' } },
|
|
29
|
-
),
|
|
30
|
-
);
|
|
31
|
-
for (const repository of repositories)
|
|
32
|
-
listed.set(String(repository.id), githubRepositoryName(repository.full_name));
|
|
33
|
-
if (listed.size > providerResourceLimit) throw new ProviderError('too_many_repositories', 409);
|
|
34
|
-
}
|
|
35
|
-
return [...listed].map(([id, fullName]) => ({ id, fullName }));
|
|
36
|
-
};
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import { createHash } from 'node:crypto';
|
|
2
|
-
import { gitObjectIdSchema } from '@inixiative/signet/contracts';
|
|
3
|
-
import { z } from 'zod';
|
|
4
|
-
import type { ProviderContext } from '../../../../contracts';
|
|
5
|
-
import { ProviderError } from '../../../../utils/providerError';
|
|
6
|
-
import { githubTreeEntryModeSchema } from './githubTreeEntryModeSchema';
|
|
7
|
-
import { githubTreeEntryTypeForMode } from './githubTreeEntryTypeForMode';
|
|
8
|
-
import { githubTreeEntryTypeSchema } from './githubTreeEntryTypeSchema';
|
|
9
|
-
|
|
10
|
-
export const readGithubObject = (data: unknown, context: ProviderContext, objectId: string) => {
|
|
11
|
-
const identity = z.object({ sha: gitObjectIdSchema }).parse(data);
|
|
12
|
-
if (identity.sha !== objectId) throw new ProviderError('provider_invalid_response');
|
|
13
|
-
if (context.operation === 'commits.read')
|
|
14
|
-
return z
|
|
15
|
-
.object({ sha: gitObjectIdSchema, tree: z.object({ sha: gitObjectIdSchema }) })
|
|
16
|
-
.parse(data);
|
|
17
|
-
if (context.operation === 'trees.read') {
|
|
18
|
-
const tree = z
|
|
19
|
-
.object({
|
|
20
|
-
sha: gitObjectIdSchema,
|
|
21
|
-
truncated: z.literal(false),
|
|
22
|
-
tree: z
|
|
23
|
-
.array(
|
|
24
|
-
z
|
|
25
|
-
.object({
|
|
26
|
-
path: z
|
|
27
|
-
.string()
|
|
28
|
-
.min(1)
|
|
29
|
-
.max(255)
|
|
30
|
-
.refine(
|
|
31
|
-
(path) =>
|
|
32
|
-
path !== '.' &&
|
|
33
|
-
path !== '..' &&
|
|
34
|
-
[...path].every(
|
|
35
|
-
(character) =>
|
|
36
|
-
character.charCodeAt(0) >= 32 &&
|
|
37
|
-
character.charCodeAt(0) !== 127 &&
|
|
38
|
-
character !== '/' &&
|
|
39
|
-
character !== String.fromCharCode(92),
|
|
40
|
-
),
|
|
41
|
-
),
|
|
42
|
-
mode: githubTreeEntryModeSchema,
|
|
43
|
-
type: githubTreeEntryTypeSchema,
|
|
44
|
-
sha: gitObjectIdSchema,
|
|
45
|
-
size: z
|
|
46
|
-
.number()
|
|
47
|
-
.int()
|
|
48
|
-
.min(0)
|
|
49
|
-
.max(512 * 1024)
|
|
50
|
-
.optional(),
|
|
51
|
-
})
|
|
52
|
-
.refine((entry) => githubTreeEntryTypeForMode[entry.mode] === entry.type),
|
|
53
|
-
)
|
|
54
|
-
.max(context.limit),
|
|
55
|
-
})
|
|
56
|
-
.parse(data);
|
|
57
|
-
if (new Set(tree.tree.map((entry) => entry.path)).size !== tree.tree.length)
|
|
58
|
-
throw new ProviderError('provider_invalid_response');
|
|
59
|
-
return tree;
|
|
60
|
-
}
|
|
61
|
-
const blob = z
|
|
62
|
-
.object({
|
|
63
|
-
sha: gitObjectIdSchema,
|
|
64
|
-
encoding: z.literal('base64'),
|
|
65
|
-
size: z
|
|
66
|
-
.number()
|
|
67
|
-
.int()
|
|
68
|
-
.min(0)
|
|
69
|
-
.max(512 * 1024),
|
|
70
|
-
content: z
|
|
71
|
-
.string()
|
|
72
|
-
.max(750000)
|
|
73
|
-
.regex(/^[A-Za-z0-9+/=\r\n]*$/),
|
|
74
|
-
})
|
|
75
|
-
.parse(data);
|
|
76
|
-
const encoded = blob.content.replace(/[\r\n]/g, '');
|
|
77
|
-
const bytes = Buffer.from(encoded, 'base64');
|
|
78
|
-
if (
|
|
79
|
-
bytes.toString('base64') !== encoded ||
|
|
80
|
-
bytes.length !== blob.size ||
|
|
81
|
-
createHash('sha1').update(`blob ${bytes.length}\0`).update(bytes).digest('hex') !== blob.sha
|
|
82
|
-
)
|
|
83
|
-
throw new ProviderError('provider_invalid_response');
|
|
84
|
-
return { sha: blob.sha, encoding: blob.encoding, size: blob.size, content: encoded };
|
|
85
|
-
};
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { ProviderClient } from '../../utils/providerClient';
|
|
2
|
-
import { providerRequest } from '../../utils/providerRequest';
|
|
3
|
-
import type { ProviderRequestInput } from '../../utils/providerRequestInput';
|
|
4
|
-
import { requestProviderJson } from '../../utils/requestProviderJson';
|
|
5
|
-
import { githubRequestHeaders } from './githubRequestHeaders';
|
|
6
|
-
|
|
7
|
-
export const requestGithub = async (
|
|
8
|
-
{ token, send = fetch }: ProviderClient,
|
|
9
|
-
input: ProviderRequestInput,
|
|
10
|
-
) =>
|
|
11
|
-
await requestProviderJson(
|
|
12
|
-
send,
|
|
13
|
-
providerRequest(
|
|
14
|
-
'https://api.github.com',
|
|
15
|
-
input,
|
|
16
|
-
githubRequestHeaders(new Headers(input.headers), token),
|
|
17
|
-
),
|
|
18
|
-
);
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { ProviderError } from '../../utils/providerError';
|
|
2
|
-
|
|
3
|
-
const gmailMessageIdPattern = /^[A-Za-z0-9_-]{1,64}$/;
|
|
4
|
-
|
|
5
|
-
export const buildGmailMessageRequest = (
|
|
6
|
-
listRequest: Request,
|
|
7
|
-
messageId: unknown,
|
|
8
|
-
signal: AbortSignal = listRequest.signal,
|
|
9
|
-
) => {
|
|
10
|
-
if (typeof messageId !== 'string' || !gmailMessageIdPattern.test(messageId))
|
|
11
|
-
throw new ProviderError('provider_invalid_response');
|
|
12
|
-
const url = new URL(`https://gmail.googleapis.com/gmail/v1/users/me/messages/${messageId}`);
|
|
13
|
-
url.searchParams.set('format', 'metadata');
|
|
14
|
-
for (const header of ['From', 'To', 'Subject', 'Date'])
|
|
15
|
-
url.searchParams.append('metadataHeaders', header);
|
|
16
|
-
return new Request(url.toString(), {
|
|
17
|
-
method: 'GET',
|
|
18
|
-
headers: listRequest.headers,
|
|
19
|
-
redirect: 'error',
|
|
20
|
-
signal,
|
|
21
|
-
});
|
|
22
|
-
};
|