@inixiative/integrations 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +50 -2
- package/package.json +56 -4
- package/src/archiveCandidate.ts +1 -0
- package/src/archiveConfigurationSchema.ts +3 -0
- package/src/buildProviderRequest.ts +54 -0
- package/src/catalog.ts +54 -0
- package/src/codexClientId.ts +2 -0
- package/src/codexTokenUrl.ts +1 -0
- package/src/consentReason.ts +4 -0
- package/src/consentReasonSchema.ts +21 -0
- package/src/contracts.ts +107 -0
- package/src/credentialClient.ts +4 -0
- package/src/declaredOperations.ts +9 -0
- package/src/eventLeaves.ts +5 -0
- package/src/exchangeOauthCode.ts +61 -0
- package/src/executeProvider.ts +26 -0
- package/src/familyProducts.ts +5 -0
- package/src/fetchRenewalResponse.ts +41 -0
- package/src/findOperationHandler.ts +6 -0
- package/src/findProvider.ts +5 -0
- package/src/index.ts +3 -0
- package/src/integrationConfigurationSchemas.ts +11 -0
- package/src/integrationEventResource.ts +20 -0
- package/src/integrationKeyedKinds.ts +4 -0
- package/src/isAccountSuppliedByHost.ts +6 -0
- package/src/isEventLeaf.ts +1 -0
- package/src/isFamilyManaged.ts +7 -0
- package/src/isLocalArchive.ts +5 -0
- package/src/isUncalledLeaf.ts +6 -0
- package/src/localArchiveConfigurationSchema.ts +5 -0
- package/src/localArchiveSourceId.ts +8 -0
- package/src/mintProviderCredential.ts +68 -0
- package/src/operationHandler.ts +8 -0
- package/src/operationHandlers.ts +41 -0
- package/src/operationLeaves.ts +6 -0
- package/src/operationRequestInput.ts +12 -0
- package/src/perProvider.ts +20 -0
- package/src/providerEvent.ts +3 -0
- package/src/providerEventSchema.ts +3 -0
- package/src/providerExchangeTimeoutMs.ts +1 -0
- package/src/providerFamily.ts +4 -0
- package/src/providerHasEvents.ts +8 -0
- package/src/providerModel.ts +12 -0
- package/src/providerRequestSpec.ts +1 -0
- package/src/providers/anthropic/anthropicProvider.ts +16 -0
- package/src/providers/archive/archiveProvider.ts +21 -0
- package/src/providers/chorus/chorusProvider.ts +22 -0
- package/src/providers/claude/claudeProvider.ts +17 -0
- package/src/providers/codex/codexProvider.ts +17 -0
- package/src/providers/confluence/confluenceOperationHandler.ts +14 -0
- package/src/providers/confluence/confluenceProvider.ts +16 -0
- package/src/providers/discord/discordOperationHandler.ts +30 -0
- package/src/providers/discord/discordProvider.ts +22 -0
- package/src/providers/drive/driveOperationHandler.ts +21 -0
- package/src/providers/drive/driveProvider.ts +18 -0
- package/src/providers/foundry/foundryProvider.ts +33 -0
- package/src/providers/geminiApi/geminiApiProvider.ts +16 -0
- package/src/providers/github/auth/fetchGithubAppInstallation.ts +21 -0
- package/src/providers/github/auth/fetchGithubOrganizationRole.ts +27 -0
- package/src/providers/github/auth/fetchGithubUser.ts +11 -0
- package/src/providers/github/auth/fetchGithubUserInstallation.ts +21 -0
- package/src/providers/github/auth/githubAppClient.ts +4 -0
- package/src/providers/github/auth/githubAppInstallUrl.ts +20 -0
- package/src/providers/github/auth/githubAppJwt.ts +16 -0
- package/src/providers/github/auth/githubClientForApp.ts +11 -0
- package/src/providers/github/auth/githubInstallation.ts +4 -0
- package/src/providers/github/auth/githubInstallationAccountId.ts +4 -0
- package/src/providers/github/auth/githubInstallationFromAccountId.ts +4 -0
- package/src/providers/github/auth/githubInstallationSchema.ts +12 -0
- package/src/providers/github/auth/githubPermissionCovers.ts +14 -0
- package/src/providers/github/auth/githubPermissionScopes.ts +4 -0
- package/src/providers/github/auth/githubProviderForOwner.ts +6 -0
- package/src/providers/github/auth/githubUserAuthorizeUrl.ts +10 -0
- package/src/providers/github/events/githubEventRepositoryId.ts +10 -0
- package/src/providers/github/events/githubNotification.ts +4 -0
- package/src/providers/github/events/githubNotificationSchema.ts +9 -0
- package/src/providers/github/events/listGithubNotifications.ts +27 -0
- package/src/providers/github/events/normalizeGithubEvent.ts +200 -0
- package/src/providers/github/events/normalizeGithubNotification.ts +56 -0
- package/src/providers/github/events/verifyGithubSignature.ts +7 -0
- package/src/providers/github/fetchAllGithubPages.ts +12 -0
- package/src/providers/github/githubApiVersion.ts +1 -0
- package/src/providers/github/githubOrganizationProvider.ts +13 -0
- package/src/providers/github/githubPagination.ts +7 -0
- package/src/providers/github/githubProvider.ts +13 -0
- package/src/providers/github/githubRequestHeaders.ts +9 -0
- package/src/providers/github/githubUserProvider.ts +13 -0
- package/src/providers/github/iterateGithubPages.ts +12 -0
- package/src/providers/github/models/account/githubAccount.ts +17 -0
- package/src/providers/github/models/repository/githubOperationHandler.ts +36 -0
- package/src/providers/github/models/repository/githubRepository.ts +40 -0
- package/src/providers/github/models/repository/githubRepositoryIdSchema.ts +3 -0
- package/src/providers/github/models/repository/githubRepositoryMetadataSchema.ts +6 -0
- package/src/providers/github/models/repository/githubRepositoryName.ts +4 -0
- package/src/providers/github/models/repository/githubRepositoryNameSchema.ts +9 -0
- package/src/providers/github/models/repository/githubTreeEntryModeSchema.ts +3 -0
- package/src/providers/github/models/repository/githubTreeEntryTypeForMode.ts +14 -0
- package/src/providers/github/models/repository/githubTreeEntryTypeSchema.ts +3 -0
- package/src/providers/github/models/repository/listInstallationRepositories.ts +31 -0
- package/src/providers/github/models/repository/listUserRepositories.ts +36 -0
- package/src/providers/github/models/repository/readGithubObject.ts +85 -0
- package/src/providers/github/models/repository/readGithubRepositoryName.ts +4 -0
- package/src/providers/github/requestGithub.ts +18 -0
- package/src/providers/gmail/buildGmailMessageRequest.ts +22 -0
- package/src/providers/gmail/fetchGmailMessages.ts +81 -0
- package/src/providers/gmail/gmailOperationHandler.ts +12 -0
- package/src/providers/gmail/gmailProvider.ts +19 -0
- package/src/providers/google/auth/buildGoogleAuthorizationUrl.ts +33 -0
- package/src/providers/google/auth/verifyGoogleIdToken.ts +22 -0
- package/src/providers/google/googleProvider.ts +13 -0
- package/src/providers/jira/jiraOperationHandler.ts +14 -0
- package/src/providers/jira/jiraProvider.ts +16 -0
- package/src/providers/linear/auth/linearIntegrationSecret.ts +6 -0
- package/src/providers/linear/events/createLinearWebhook.ts +30 -0
- package/src/providers/linear/events/deleteLinearWebhook.ts +13 -0
- package/src/providers/linear/events/linearUserSchema.ts +3 -0
- package/src/providers/linear/events/linearWebhook.ts +3 -0
- package/src/providers/linear/events/linearWebhookPayload.ts +4 -0
- package/src/providers/linear/events/linearWebhookPayloadSchema.ts +13 -0
- package/src/providers/linear/events/listLinearWebhooks.ts +44 -0
- package/src/providers/linear/events/normalizeLinearEvent.ts +127 -0
- package/src/providers/linear/events/repairLinearWebhook.ts +17 -0
- package/src/providers/linear/events/verifyLinearSignature.ts +25 -0
- package/src/providers/linear/fetchAllLinearPages.ts +40 -0
- package/src/providers/linear/linearClient.ts +5 -0
- package/src/providers/linear/linearPagination.ts +13 -0
- package/src/providers/linear/linearProvider.ts +25 -0
- package/src/providers/linear/linearRequestInput.ts +1 -0
- package/src/providers/linear/models/issue/linearOperationHandler.ts +30 -0
- package/src/providers/linear/models/team/fetchLinearWorkspace.ts +30 -0
- package/src/providers/linear/requestLinear.ts +51 -0
- package/src/providers/muse/museProvider.ts +17 -0
- package/src/providers/notion/notionOperationHandler.ts +32 -0
- package/src/providers/notion/notionProvider.ts +22 -0
- package/src/providers/openai/openaiProvider.ts +16 -0
- package/src/providers/oracle/oracleProvider.ts +10 -0
- package/src/providers/railway/railwayProvider.ts +9 -0
- package/src/providers/render/renderProvider.ts +9 -0
- package/src/providers/slack/auth/fetchSlackIdentity.ts +10 -0
- package/src/providers/slack/events/normalizeSlackEvent.ts +64 -0
- package/src/providers/slack/events/slackAccountIdOf.ts +1 -0
- package/src/providers/slack/events/slackEventEnvelope.ts +4 -0
- package/src/providers/slack/events/slackEventEnvelopeSchema.ts +16 -0
- package/src/providers/slack/events/slackTeamPrefix.ts +1 -0
- package/src/providers/slack/events/slackTokensRevokedSchema.ts +13 -0
- package/src/providers/slack/events/slackUserOfAccountId.ts +2 -0
- package/src/providers/slack/events/verifySlackSignature.ts +17 -0
- package/src/providers/slack/fetchAllSlackPages.ts +12 -0
- package/src/providers/slack/models/channel/listSlackChannels.ts +26 -0
- package/src/providers/slack/models/channel/slackOperationHandler.ts +30 -0
- package/src/providers/slack/requestSlack.ts +22 -0
- package/src/providers/slack/slackPagination.ts +12 -0
- package/src/providers/slack/slackProvider.ts +47 -0
- package/src/providers/slack/slackProviderError.ts +12 -0
- package/src/providers/teams/teamsOperationHandler.ts +24 -0
- package/src/providers/teams/teamsProvider.ts +17 -0
- package/src/refreshProviderCredential.ts +172 -0
- package/src/renewalRequest.ts +1 -0
- package/src/resourceExternalIdSchema.ts +4 -0
- package/src/resourceExternalIdSchemas.ts +18 -0
- package/src/resourceMetadataSchema.ts +4 -0
- package/src/resourceMetadataSchemas.ts +9 -0
- package/src/subscriptionAccountId.ts +12 -0
- package/src/utils/capacityWindowSchema.ts +7 -0
- package/src/utils/headerNumber.ts +6 -0
- package/src/utils/jwtClaims.ts +14 -0
- package/src/utils/matchesHmacSha256.ts +11 -0
- package/src/utils/objectSchema.ts +3 -0
- package/src/utils/pagination/applyCaps.ts +18 -0
- package/src/utils/pagination/byCursorKeys.ts +7 -0
- package/src/utils/pagination/byCursorOptions.ts +7 -0
- package/src/utils/pagination/byPageKeys.ts +7 -0
- package/src/utils/pagination/byPageOptions.ts +8 -0
- package/src/utils/pagination/collectPages.ts +27 -0
- package/src/utils/pagination/compactRequest.ts +4 -0
- package/src/utils/pagination/fetchAllByCursor.ts +6 -0
- package/src/utils/pagination/fetchAllByPage.ts +6 -0
- package/src/utils/pagination/fetchAllRequestPages.ts +16 -0
- package/src/utils/pagination/incompletePageWalkError.ts +8 -0
- package/src/utils/pagination/isAnotherPage.ts +20 -0
- package/src/utils/pagination/iterateByCursor.ts +49 -0
- package/src/utils/pagination/iterateByPage.ts +59 -0
- package/src/utils/pagination/iterateProviderPages.ts +27 -0
- package/src/utils/pagination/iterateRequestPages.ts +18 -0
- package/src/utils/pagination/pageWalkError.ts +6 -0
- package/src/utils/pagination/paginationOptions.ts +9 -0
- package/src/utils/pagination/providerPagesOptions.ts +8 -0
- package/src/utils/pagination/providerPagination.ts +6 -0
- package/src/utils/pagination/readPage.ts +29 -0
- package/src/utils/pagination/readPath.ts +12 -0
- package/src/utils/pagination/repeatedCursorError.ts +10 -0
- package/src/utils/providerClient.ts +3 -0
- package/src/utils/providerCooldown.ts +23 -0
- package/src/utils/providerCooldownState.ts +4 -0
- package/src/utils/providerError.ts +10 -0
- package/src/utils/providerReading.ts +4 -0
- package/src/utils/providerReadingSchema.ts +8 -0
- package/src/utils/providerRequest.ts +22 -0
- package/src/utils/providerRequestInput.ts +7 -0
- package/src/utils/providerResponseLimit.ts +1 -0
- package/src/utils/providerSend.ts +1 -0
- package/src/utils/readProviderJson.ts +38 -0
- package/src/utils/readProviderLimits.ts +66 -0
- package/src/utils/readRateLimit.ts +29 -0
- package/src/utils/requestProviderJson.ts +13 -0
- package/src/utils/responseBudget.ts +1 -0
- package/src/utils/select.ts +6 -0
- package/src/utils/sendProviderRequest.ts +33 -0
- package/src/validateCredentialSecret.ts +18 -0
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ArchiveCandidate } from './archiveCandidate';
|
|
2
|
+
import { localArchiveConfigurationSchema } from './localArchiveConfigurationSchema';
|
|
3
|
+
|
|
4
|
+
export const localArchiveSourceId = (integration: ArchiveCandidate) =>
|
|
5
|
+
integration.provider === 'archive'
|
|
6
|
+
? (localArchiveConfigurationSchema.safeParse(integration.configuration).data?.local.sourceId ??
|
|
7
|
+
null)
|
|
8
|
+
: null;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import {
|
|
3
|
+
type CredentialSecret,
|
|
4
|
+
credentialSecretSchema,
|
|
5
|
+
type OAuthClient,
|
|
6
|
+
type SigningClient,
|
|
7
|
+
} from './contracts';
|
|
8
|
+
import type { CredentialClient } from './credentialClient';
|
|
9
|
+
import { fetchRenewalResponse } from './fetchRenewalResponse';
|
|
10
|
+
import { githubAppJwt } from './providers/github/auth/githubAppJwt';
|
|
11
|
+
import { githubPermissionScopes } from './providers/github/auth/githubPermissionScopes';
|
|
12
|
+
import { githubRequestHeaders } from './providers/github/githubRequestHeaders';
|
|
13
|
+
import type { RenewalRequest } from './renewalRequest';
|
|
14
|
+
import { ProviderError } from './utils/providerError';
|
|
15
|
+
|
|
16
|
+
type ClientCredentials = NonNullable<CredentialSecret['clientCredentials']>;
|
|
17
|
+
|
|
18
|
+
const mintRequest = async (
|
|
19
|
+
provider: string,
|
|
20
|
+
clientCredentials: ClientCredentials,
|
|
21
|
+
client?: OAuthClient | SigningClient,
|
|
22
|
+
): Promise<RenewalRequest> => {
|
|
23
|
+
const subjectId = clientCredentials.subjectId;
|
|
24
|
+
if (provider !== 'githubOrganization' || !subjectId || !client || !('privateKey' in client))
|
|
25
|
+
throw new ProviderError('renewal_unsupported', 409);
|
|
26
|
+
const headers = githubRequestHeaders(new Headers(), await githubAppJwt(client));
|
|
27
|
+
headers.set('Content-Type', 'application/json');
|
|
28
|
+
return {
|
|
29
|
+
url: `https://api.github.com/app/installations/${encodeURIComponent(subjectId)}/access_tokens`,
|
|
30
|
+
headers,
|
|
31
|
+
body: JSON.stringify({ permissions: { contents: 'read' } }),
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const mintedSecret = (clientCredentials: ClientCredentials, data: Record<string, unknown>) => {
|
|
36
|
+
const minted = z
|
|
37
|
+
.object({
|
|
38
|
+
token: z.string().min(1),
|
|
39
|
+
expires_at: z.iso.datetime({ offset: true }),
|
|
40
|
+
permissions: z.record(z.string(), z.string()).default({}),
|
|
41
|
+
})
|
|
42
|
+
.safeParse(data);
|
|
43
|
+
if (!minted.success) throw new ProviderError('renewal_outcome_unknown', 409);
|
|
44
|
+
const expiresIn = z
|
|
45
|
+
.number()
|
|
46
|
+
.int()
|
|
47
|
+
.positive()
|
|
48
|
+
.max(31536000)
|
|
49
|
+
.safeParse(Math.floor((Date.parse(minted.data.expires_at) - Date.now()) / 1000));
|
|
50
|
+
if (!expiresIn.success) throw new ProviderError('renewal_outcome_unknown', 409);
|
|
51
|
+
return {
|
|
52
|
+
secret: credentialSecretSchema.parse({
|
|
53
|
+
token: minted.data.token,
|
|
54
|
+
clientCredentials,
|
|
55
|
+
}),
|
|
56
|
+
expiresIn: expiresIn.data,
|
|
57
|
+
scopes: githubPermissionScopes(minted.data.permissions),
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export const mintProviderCredential = async (
|
|
62
|
+
{ app, send = fetch }: CredentialClient,
|
|
63
|
+
{ provider, clientCredentials }: { provider: string; clientCredentials: ClientCredentials },
|
|
64
|
+
) =>
|
|
65
|
+
mintedSecret(
|
|
66
|
+
clientCredentials,
|
|
67
|
+
await fetchRenewalResponse(send, await mintRequest(provider, clientCredentials, app)),
|
|
68
|
+
);
|
|
@@ -0,0 +1,8 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { Provider } from './contracts';
|
|
2
|
+
import type { OperationHandler } from './operationHandler';
|
|
3
|
+
import { confluenceOperationHandler } from './providers/confluence/confluenceOperationHandler';
|
|
4
|
+
import { discordOperationHandler } from './providers/discord/discordOperationHandler';
|
|
5
|
+
import { driveOperationHandler } from './providers/drive/driveOperationHandler';
|
|
6
|
+
import { githubOperationHandler } from './providers/github/models/repository/githubOperationHandler';
|
|
7
|
+
import { gmailOperationHandler } from './providers/gmail/gmailOperationHandler';
|
|
8
|
+
import { jiraOperationHandler } from './providers/jira/jiraOperationHandler';
|
|
9
|
+
import { linearOperationHandler } from './providers/linear/models/issue/linearOperationHandler';
|
|
10
|
+
import { notionOperationHandler } from './providers/notion/notionOperationHandler';
|
|
11
|
+
import { slackOperationHandler } from './providers/slack/models/channel/slackOperationHandler';
|
|
12
|
+
import { teamsOperationHandler } from './providers/teams/teamsOperationHandler';
|
|
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
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { providers } from './catalog';
|
|
2
|
+
|
|
3
|
+
export const operationLeaves = (provider: string | null | undefined, kind: string) =>
|
|
4
|
+
(providers.find((item) => item.key === provider)?.operations ?? [])
|
|
5
|
+
.filter((operation) => operation.resourceKind === kind)
|
|
6
|
+
.map((operation) => operation.key);
|
|
@@ -0,0 +1,12 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { z } from 'zod';
|
|
2
|
+
import { type Provider, providerSchema } from './contracts';
|
|
3
|
+
|
|
4
|
+
type PerProvider<TFallback, TOverrides> = {
|
|
5
|
+
[P in Provider]: P extends keyof TOverrides ? TOverrides[P] : TFallback;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export const perProvider = <
|
|
9
|
+
TFallback extends z.ZodType,
|
|
10
|
+
TOverrides extends Partial<Record<Provider, z.ZodType>>,
|
|
11
|
+
>(
|
|
12
|
+
fallback: TFallback,
|
|
13
|
+
overrides: TOverrides,
|
|
14
|
+
): PerProvider<TFallback, TOverrides> =>
|
|
15
|
+
Object.fromEntries(
|
|
16
|
+
providerSchema.options.map((provider) => [
|
|
17
|
+
provider,
|
|
18
|
+
overrides[provider as keyof TOverrides] ?? fallback,
|
|
19
|
+
]),
|
|
20
|
+
) as PerProvider<TFallback, TOverrides>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const PROVIDER_EXCHANGE_TIMEOUT_MS = 15_000;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Provider } from './contracts';
|
|
2
|
+
import { findProvider } from './findProvider';
|
|
3
|
+
import { isEventLeaf } from './isEventLeaf';
|
|
4
|
+
|
|
5
|
+
export const providerHasEvents = (provider: string | null | undefined) =>
|
|
6
|
+
(findProvider(provider as Provider)?.operations ?? []).some((operation) =>
|
|
7
|
+
isEventLeaf(operation.key),
|
|
8
|
+
);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { IntegrationEvent } from '@inixiative/signet/contracts';
|
|
2
|
+
import type { z } from 'zod';
|
|
3
|
+
import type { ProviderDefinition } from './contracts';
|
|
4
|
+
|
|
5
|
+
export type ProviderModel = {
|
|
6
|
+
kind: string;
|
|
7
|
+
externalIdSchema?: z.ZodType<string>;
|
|
8
|
+
metadataSchema?: z.ZodType;
|
|
9
|
+
operations: ProviderDefinition['operations'];
|
|
10
|
+
events: ProviderDefinition['operations'];
|
|
11
|
+
externalIdOfEvent?: (event: Pick<IntegrationEvent, 'scope' | 'payload'>) => string | null;
|
|
12
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type ProviderRequestSpec = { url: URL; body?: string };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ProviderDefinition } from '../../contracts';
|
|
2
|
+
|
|
3
|
+
export const anthropicProvider: ProviderDefinition = {
|
|
4
|
+
key: 'anthropic',
|
|
5
|
+
name: 'Anthropic',
|
|
6
|
+
documentationUrl: 'https://platform.claude.com/docs/en/api/messages',
|
|
7
|
+
authMethods: ['apiKey', 'bearer'],
|
|
8
|
+
operations: [
|
|
9
|
+
{
|
|
10
|
+
key: 'inference.create',
|
|
11
|
+
name: 'Run inference',
|
|
12
|
+
resourceKind: 'model',
|
|
13
|
+
requiredScopes: ['inference'],
|
|
14
|
+
},
|
|
15
|
+
],
|
|
16
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import {
|
|
2
|
+
archiveLibraryResourceKind,
|
|
3
|
+
archiveOperationNames,
|
|
4
|
+
archiveOperationSchema,
|
|
5
|
+
} from '@inixiative/signet/contracts';
|
|
6
|
+
import type { ProviderDefinition } from '../../contracts';
|
|
7
|
+
import { declaredOperations } from '../../declaredOperations';
|
|
8
|
+
|
|
9
|
+
export const archiveProvider: ProviderDefinition = {
|
|
10
|
+
key: 'archive',
|
|
11
|
+
name: 'Archive',
|
|
12
|
+
documentationUrl: 'https://github.com/inixiative/archive',
|
|
13
|
+
authMethods: ['bearer'],
|
|
14
|
+
inbound: true,
|
|
15
|
+
operations: declaredOperations(
|
|
16
|
+
archiveOperationNames,
|
|
17
|
+
archiveLibraryResourceKind,
|
|
18
|
+
[],
|
|
19
|
+
archiveOperationSchema.options,
|
|
20
|
+
),
|
|
21
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import {
|
|
2
|
+
chorusOperationNames,
|
|
3
|
+
chorusOperationSchema,
|
|
4
|
+
chorusResourceKind,
|
|
5
|
+
} from '@inixiative/signet/contracts';
|
|
6
|
+
import type { ProviderDefinition } from '../../contracts';
|
|
7
|
+
import { declaredOperations } from '../../declaredOperations';
|
|
8
|
+
|
|
9
|
+
export const chorusProvider: ProviderDefinition = {
|
|
10
|
+
key: 'chorus',
|
|
11
|
+
name: 'Chorus',
|
|
12
|
+
documentationUrl: 'https://github.com/inixiative/chorus',
|
|
13
|
+
authMethods: [],
|
|
14
|
+
inbound: true,
|
|
15
|
+
delivery: 'installationSocket',
|
|
16
|
+
operations: declaredOperations(
|
|
17
|
+
chorusOperationNames,
|
|
18
|
+
chorusResourceKind,
|
|
19
|
+
[],
|
|
20
|
+
chorusOperationSchema.options,
|
|
21
|
+
),
|
|
22
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ProviderDefinition } from '../../contracts';
|
|
2
|
+
|
|
3
|
+
export const claudeProvider: ProviderDefinition = {
|
|
4
|
+
key: 'claude',
|
|
5
|
+
name: 'Claude subscription',
|
|
6
|
+
documentationUrl: 'https://code.claude.com/docs/en/authentication',
|
|
7
|
+
authMethods: ['bearer'],
|
|
8
|
+
subscription: true,
|
|
9
|
+
operations: [
|
|
10
|
+
{
|
|
11
|
+
key: 'subscription.use',
|
|
12
|
+
name: 'Run Claude Code on this login',
|
|
13
|
+
resourceKind: 'subscription',
|
|
14
|
+
requiredScopes: ['user:inference'],
|
|
15
|
+
},
|
|
16
|
+
],
|
|
17
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ProviderDefinition } from '../../contracts';
|
|
2
|
+
|
|
3
|
+
export const codexProvider: ProviderDefinition = {
|
|
4
|
+
key: 'codex',
|
|
5
|
+
name: 'ChatGPT subscription',
|
|
6
|
+
documentationUrl: 'https://developers.openai.com/codex/auth',
|
|
7
|
+
authMethods: ['oauth2'],
|
|
8
|
+
subscription: true,
|
|
9
|
+
operations: [
|
|
10
|
+
{
|
|
11
|
+
key: 'subscription.use',
|
|
12
|
+
name: 'Run Codex on this login',
|
|
13
|
+
resourceKind: 'subscription',
|
|
14
|
+
requiredScopes: ['openid', 'offline_access'],
|
|
15
|
+
},
|
|
16
|
+
],
|
|
17
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { OperationHandler } from '../../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
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ProviderDefinition } from '../../contracts';
|
|
2
|
+
|
|
3
|
+
export const confluenceProvider: ProviderDefinition = {
|
|
4
|
+
key: 'confluence',
|
|
5
|
+
name: 'Confluence',
|
|
6
|
+
documentationUrl: 'https://developer.atlassian.com/cloud/confluence/rest/v2/api-group-page/',
|
|
7
|
+
authMethods: ['bearer', 'oauth2'],
|
|
8
|
+
operations: [
|
|
9
|
+
{
|
|
10
|
+
key: 'pages.read',
|
|
11
|
+
name: 'Read a page',
|
|
12
|
+
resourceKind: 'page',
|
|
13
|
+
requiredScopes: ['read:page:confluence'],
|
|
14
|
+
},
|
|
15
|
+
],
|
|
16
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { OperationHandler } from '../../operationHandler';
|
|
3
|
+
import { objectSchema } from '../../utils/objectSchema';
|
|
4
|
+
import { select } from '../../utils/select';
|
|
5
|
+
|
|
6
|
+
export const 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
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ProviderDefinition } from '../../contracts';
|
|
2
|
+
|
|
3
|
+
export const discordProvider: ProviderDefinition = {
|
|
4
|
+
key: 'discord',
|
|
5
|
+
name: 'Discord',
|
|
6
|
+
documentationUrl: 'https://discord.com/developers/docs/resources/message#get-channel-messages',
|
|
7
|
+
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
|
+
],
|
|
22
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { OperationHandler } from '../../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
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ProviderDefinition } from '../../contracts';
|
|
2
|
+
|
|
3
|
+
export const driveProvider: ProviderDefinition = {
|
|
4
|
+
key: 'drive',
|
|
5
|
+
name: 'Google Drive',
|
|
6
|
+
documentationUrl: 'https://developers.google.com/workspace/drive/api/reference/rest/v3/files/get',
|
|
7
|
+
authMethods: ['oauth2'],
|
|
8
|
+
family: 'google',
|
|
9
|
+
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
|
+
],
|
|
18
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import {
|
|
2
|
+
conversationPermissionNames,
|
|
3
|
+
conversationPermissionSchema,
|
|
4
|
+
conversationResourceKind,
|
|
5
|
+
threadOperationNames,
|
|
6
|
+
threadOperationSchema,
|
|
7
|
+
} from '@inixiative/signet/contracts';
|
|
8
|
+
import type { ProviderDefinition } from '../../contracts';
|
|
9
|
+
import { declaredOperations } from '../../declaredOperations';
|
|
10
|
+
|
|
11
|
+
export const foundryProvider: ProviderDefinition = {
|
|
12
|
+
key: 'foundry',
|
|
13
|
+
name: 'Foundry',
|
|
14
|
+
documentationUrl: 'https://github.com/inixiative/foundry',
|
|
15
|
+
authMethods: [],
|
|
16
|
+
inbound: true,
|
|
17
|
+
delivery: 'installationSocket',
|
|
18
|
+
holderHandleKinds: [conversationResourceKind],
|
|
19
|
+
operations: [
|
|
20
|
+
...declaredOperations(
|
|
21
|
+
threadOperationNames,
|
|
22
|
+
conversationResourceKind,
|
|
23
|
+
[],
|
|
24
|
+
threadOperationSchema.options,
|
|
25
|
+
),
|
|
26
|
+
...declaredOperations(
|
|
27
|
+
conversationPermissionNames,
|
|
28
|
+
conversationResourceKind,
|
|
29
|
+
[],
|
|
30
|
+
conversationPermissionSchema.options,
|
|
31
|
+
),
|
|
32
|
+
],
|
|
33
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ProviderDefinition } from '../../contracts';
|
|
2
|
+
|
|
3
|
+
export const geminiApiProvider: ProviderDefinition = {
|
|
4
|
+
key: 'geminiApi',
|
|
5
|
+
name: 'Gemini API',
|
|
6
|
+
documentationUrl: 'https://ai.google.dev/api/generate-content',
|
|
7
|
+
authMethods: ['apiKey'],
|
|
8
|
+
operations: [
|
|
9
|
+
{
|
|
10
|
+
key: 'inference.create',
|
|
11
|
+
name: 'Run inference',
|
|
12
|
+
resourceKind: 'model',
|
|
13
|
+
requiredScopes: ['inference'],
|
|
14
|
+
},
|
|
15
|
+
],
|
|
16
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ProviderError } from '../../../utils/providerError';
|
|
2
|
+
import { requestGithub } from '../requestGithub';
|
|
3
|
+
import type { GithubAppClient } from './githubAppClient';
|
|
4
|
+
import { githubClientForApp } from './githubClientForApp';
|
|
5
|
+
import { githubInstallationSchema } from './githubInstallationSchema';
|
|
6
|
+
|
|
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
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { ProviderClient } from '../../../utils/providerClient';
|
|
3
|
+
import { ProviderError } from '../../../utils/providerError';
|
|
4
|
+
import { requestGithub } from '../requestGithub';
|
|
5
|
+
|
|
6
|
+
const membershipSchema = z.object({ state: z.string(), role: z.string() });
|
|
7
|
+
|
|
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
|
+
);
|
|
18
|
+
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
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { ProviderClient } from '../../../utils/providerClient';
|
|
3
|
+
import { requestGithub } from '../requestGithub';
|
|
4
|
+
|
|
5
|
+
const githubUserSchema = z.object({
|
|
6
|
+
id: z.number().int().positive(),
|
|
7
|
+
login: z.string().min(1).max(39),
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
export const fetchGithubUser = async (client: ProviderClient) =>
|
|
11
|
+
githubUserSchema.parse(await requestGithub(client, { path: '/user' }));
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { createPrivateKey } from 'node:crypto';
|
|
2
|
+
import { SignJWT } from 'jose';
|
|
3
|
+
import type { SigningClient } from '../../../contracts';
|
|
4
|
+
|
|
5
|
+
export const githubAppJwt = async (
|
|
6
|
+
app: Pick<SigningClient, 'appId' | 'privateKey'>,
|
|
7
|
+
now = new Date(),
|
|
8
|
+
) => {
|
|
9
|
+
const issuedAt = Math.floor(now.getTime() / 1000) - 60;
|
|
10
|
+
return await new SignJWT({})
|
|
11
|
+
.setProtectedHeader({ alg: 'RS256', typ: 'JWT' })
|
|
12
|
+
.setIssuer(app.appId)
|
|
13
|
+
.setIssuedAt(issuedAt)
|
|
14
|
+
.setExpirationTime(issuedAt + 540)
|
|
15
|
+
.sign(createPrivateKey(app.privateKey.replace(/\\n/g, '\n')));
|
|
16
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
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
|
+
});
|