@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
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Inixiative
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,51 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @inixiative/integrations
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The provider catalog behind Kingdom integrations. For each provider it declares the operations and events it offers, the resource kind each one acts on, and the scopes it needs. Beside the catalog sits the code that reaches each provider: requests, webhook signature checks, event normalizers and credential renewal.
|
|
4
|
+
|
|
5
|
+
Kingdom is the permissions hub that decides who may use an integration. This package only says what an integration can do.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
bun add @inixiative/integrations zod
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Use
|
|
14
|
+
|
|
15
|
+
Every file under `src/` holds one export and is importable by its path.
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { findProvider } from '@inixiative/integrations/findProvider';
|
|
19
|
+
import { operationLeaves } from '@inixiative/integrations/operationLeaves';
|
|
20
|
+
|
|
21
|
+
findProvider('slack')?.operations;
|
|
22
|
+
operationLeaves('githubOrganization', 'repository');
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Shape
|
|
26
|
+
|
|
27
|
+
Each provider has a folder under `src/providers/`, with `auth/`, `events/` and `models/<model>/` inside it where it has that code, and a `<provider>Provider.ts` definition that `src/catalog.ts` lists.
|
|
28
|
+
|
|
29
|
+
A call that reaches a provider takes the client first, then the request, then anything that is not part of the request:
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
import { fetchAllGithubPages } from '@inixiative/integrations/providers/github/fetchAllGithubPages';
|
|
33
|
+
|
|
34
|
+
await fetchAllGithubPages(
|
|
35
|
+
{ token, send },
|
|
36
|
+
{ path: '/notifications', query: { since, per_page: 50 } },
|
|
37
|
+
{ maxPages: 10 },
|
|
38
|
+
);
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
- **Client:** `{ token, send? }`. `send` is any `fetch`, so a recording or stubbed fetch drops in.
|
|
42
|
+
- **Input:** `{ path, method?, query?, body?, headers? }`.
|
|
43
|
+
- **Options:** pagination keys and caps.
|
|
44
|
+
|
|
45
|
+
## Pagination
|
|
46
|
+
|
|
47
|
+
`src/utils/pagination/` reads page-numbered and cursor lists. A provider declares its strategy, its parameter names and where its responses keep the list (`githubPagination`, `slackPagination`, `linearPagination`); a call may replace any key in its options.
|
|
48
|
+
|
|
49
|
+
## License
|
|
50
|
+
|
|
51
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,6 +1,58 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inixiative/integrations",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "The provider catalog behind Kingdom integrations: each provider's operations, events, resource kinds and scopes, with the request, webhook and credential code that reaches it.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "src/index.ts",
|
|
7
|
+
"types": "src/index.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": "./src/index.ts",
|
|
10
|
+
"./*": "./src/*.ts"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"src"
|
|
14
|
+
],
|
|
15
|
+
"scripts": {
|
|
16
|
+
"typecheck": "tsc --noEmit",
|
|
17
|
+
"test": "bun test",
|
|
18
|
+
"lint": "biome check .",
|
|
19
|
+
"check:all": "bun run typecheck && bun run lint && bun run test",
|
|
20
|
+
"check": "inixiative-config bounded -- bun run check:all",
|
|
21
|
+
"prepublishOnly": "bun run check",
|
|
22
|
+
"prepare": "if git rev-parse --git-dir >/dev/null 2>&1; then root=\"$(dirname \"$(git rev-parse --path-format=absolute --git-common-dir)\")\"; if [ -x \"$root/node_modules/.bin/lefthook\" ]; then (cd \"$root\" && ./node_modules/.bin/lefthook install); fi; fi"
|
|
23
|
+
},
|
|
24
|
+
"keywords": [
|
|
25
|
+
"kingdom",
|
|
26
|
+
"integrations",
|
|
27
|
+
"catalog",
|
|
28
|
+
"providers",
|
|
29
|
+
"webhooks"
|
|
30
|
+
],
|
|
31
|
+
"license": "MIT",
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@inixiative/signet": "^0.28.0",
|
|
34
|
+
"jose": "^6.2.3"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@biomejs/biome": "2.5.2",
|
|
38
|
+
"@inixiative/config": "^0.5.237",
|
|
39
|
+
"@types/bun": "1.4.4",
|
|
40
|
+
"lefthook": "2.1.9",
|
|
41
|
+
"typescript": "6.0.3",
|
|
42
|
+
"zod": "^4.3.6"
|
|
43
|
+
},
|
|
44
|
+
"peerDependencies": {
|
|
45
|
+
"zod": "^4.3.6"
|
|
46
|
+
},
|
|
47
|
+
"packageManager": "bun@1.4.4",
|
|
48
|
+
"engines": {
|
|
49
|
+
"bun": ">=1.4.4"
|
|
50
|
+
},
|
|
51
|
+
"repository": {
|
|
52
|
+
"type": "git",
|
|
53
|
+
"url": "git+https://github.com/inixiative/integrations.git"
|
|
54
|
+
},
|
|
55
|
+
"publishConfig": {
|
|
56
|
+
"access": "public"
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type ArchiveCandidate = { provider: string | null; configuration?: unknown };
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { providers } from './catalog';
|
|
3
|
+
import type { ProviderContext } from './contracts';
|
|
4
|
+
import { credentialSecretSchema } from './contracts';
|
|
5
|
+
import { findOperationHandler } from './findOperationHandler';
|
|
6
|
+
import { integrationConfigurationSchemas } from './integrationConfigurationSchemas';
|
|
7
|
+
import { isUncalledLeaf } from './isUncalledLeaf';
|
|
8
|
+
import { resourceExternalIdSchemas } from './resourceExternalIdSchemas';
|
|
9
|
+
import { resourceMetadataSchemas } from './resourceMetadataSchemas';
|
|
10
|
+
import { ProviderError } from './utils/providerError';
|
|
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
|
+
};
|
package/src/catalog.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { ProviderDefinition } from './contracts';
|
|
2
|
+
import { anthropicProvider } from './providers/anthropic/anthropicProvider';
|
|
3
|
+
import { archiveProvider } from './providers/archive/archiveProvider';
|
|
4
|
+
import { chorusProvider } from './providers/chorus/chorusProvider';
|
|
5
|
+
import { claudeProvider } from './providers/claude/claudeProvider';
|
|
6
|
+
import { codexProvider } from './providers/codex/codexProvider';
|
|
7
|
+
import { confluenceProvider } from './providers/confluence/confluenceProvider';
|
|
8
|
+
import { discordProvider } from './providers/discord/discordProvider';
|
|
9
|
+
import { driveProvider } from './providers/drive/driveProvider';
|
|
10
|
+
import { foundryProvider } from './providers/foundry/foundryProvider';
|
|
11
|
+
import { geminiApiProvider } from './providers/geminiApi/geminiApiProvider';
|
|
12
|
+
import { githubOrganizationProvider } from './providers/github/githubOrganizationProvider';
|
|
13
|
+
import { githubProvider } from './providers/github/githubProvider';
|
|
14
|
+
import { githubUserProvider } from './providers/github/githubUserProvider';
|
|
15
|
+
import { gmailProvider } from './providers/gmail/gmailProvider';
|
|
16
|
+
import { googleProvider } from './providers/google/googleProvider';
|
|
17
|
+
import { jiraProvider } from './providers/jira/jiraProvider';
|
|
18
|
+
import { linearProvider } from './providers/linear/linearProvider';
|
|
19
|
+
import { museProvider } from './providers/muse/museProvider';
|
|
20
|
+
import { notionProvider } from './providers/notion/notionProvider';
|
|
21
|
+
import { openaiProvider } from './providers/openai/openaiProvider';
|
|
22
|
+
import { oracleProvider } from './providers/oracle/oracleProvider';
|
|
23
|
+
import { railwayProvider } from './providers/railway/railwayProvider';
|
|
24
|
+
import { renderProvider } from './providers/render/renderProvider';
|
|
25
|
+
import { slackProvider } from './providers/slack/slackProvider';
|
|
26
|
+
import { teamsProvider } from './providers/teams/teamsProvider';
|
|
27
|
+
|
|
28
|
+
export const providers: ProviderDefinition[] = [
|
|
29
|
+
slackProvider,
|
|
30
|
+
discordProvider,
|
|
31
|
+
teamsProvider,
|
|
32
|
+
linearProvider,
|
|
33
|
+
notionProvider,
|
|
34
|
+
jiraProvider,
|
|
35
|
+
googleProvider,
|
|
36
|
+
gmailProvider,
|
|
37
|
+
driveProvider,
|
|
38
|
+
confluenceProvider,
|
|
39
|
+
anthropicProvider,
|
|
40
|
+
openaiProvider,
|
|
41
|
+
geminiApiProvider,
|
|
42
|
+
archiveProvider,
|
|
43
|
+
foundryProvider,
|
|
44
|
+
oracleProvider,
|
|
45
|
+
chorusProvider,
|
|
46
|
+
githubProvider,
|
|
47
|
+
githubOrganizationProvider,
|
|
48
|
+
githubUserProvider,
|
|
49
|
+
railwayProvider,
|
|
50
|
+
renderProvider,
|
|
51
|
+
claudeProvider,
|
|
52
|
+
codexProvider,
|
|
53
|
+
museProvider,
|
|
54
|
+
];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const CODEX_TOKEN_URL = 'https://auth.openai.com/oauth/token';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
export const consentReasonSchema = z.enum([
|
|
4
|
+
'state_invalid',
|
|
5
|
+
'state_actor_mismatch',
|
|
6
|
+
'owner_unavailable',
|
|
7
|
+
'google_app_unavailable',
|
|
8
|
+
'github_app_unavailable',
|
|
9
|
+
'family_unavailable',
|
|
10
|
+
'provider_unreachable',
|
|
11
|
+
'code_exchange_failed',
|
|
12
|
+
'id_token_invalid',
|
|
13
|
+
'account_mismatch',
|
|
14
|
+
'refresh_token_missing',
|
|
15
|
+
'refresh_token_conflict',
|
|
16
|
+
'installation_unverified',
|
|
17
|
+
'installation_not_organization',
|
|
18
|
+
'installation_not_admin',
|
|
19
|
+
'installation_claimed',
|
|
20
|
+
'installation_suspended',
|
|
21
|
+
]);
|
package/src/contracts.ts
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { type IntegrationEvent, operationKeySchema } from '@inixiative/signet/contracts';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
export const providerResourceLimit = 1000;
|
|
5
|
+
|
|
6
|
+
export const inferenceProtocolSchema = z.enum(['messages', 'responses', 'generateContent']);
|
|
7
|
+
export type InferenceProtocol = z.infer<typeof inferenceProtocolSchema>;
|
|
8
|
+
|
|
9
|
+
export const subscriptionRuntimeSchema = z.enum(['claude', 'codex', 'muse']);
|
|
10
|
+
export type SubscriptionRuntime = z.infer<typeof subscriptionRuntimeSchema>;
|
|
11
|
+
|
|
12
|
+
const secretValue = z
|
|
13
|
+
.string()
|
|
14
|
+
.min(1)
|
|
15
|
+
.max(16000)
|
|
16
|
+
.regex(/^[^\r\n]+$/);
|
|
17
|
+
export const credentialSecretSchema = z.strictObject({
|
|
18
|
+
token: secretValue,
|
|
19
|
+
oauth: z
|
|
20
|
+
.strictObject({
|
|
21
|
+
refreshToken: secretValue,
|
|
22
|
+
clientId: secretValue.optional(),
|
|
23
|
+
clientSecret: secretValue.optional(),
|
|
24
|
+
tenantId: z.uuid().optional(),
|
|
25
|
+
idToken: secretValue.optional(),
|
|
26
|
+
})
|
|
27
|
+
.optional(),
|
|
28
|
+
clientCredentials: z
|
|
29
|
+
.strictObject({
|
|
30
|
+
clientId: secretValue.optional(),
|
|
31
|
+
clientSecret: secretValue.optional(),
|
|
32
|
+
subjectId: secretValue.optional(),
|
|
33
|
+
})
|
|
34
|
+
.optional(),
|
|
35
|
+
});
|
|
36
|
+
export type CredentialSecret = z.infer<typeof credentialSecretSchema>;
|
|
37
|
+
export const credentialMethodSchema = z.enum(['bearer', 'apiKey', 'oauth2', 'clientCredentials']);
|
|
38
|
+
export const renewableCredentialMethods: string[] = credentialMethodSchema.extract([
|
|
39
|
+
'oauth2',
|
|
40
|
+
'clientCredentials',
|
|
41
|
+
]).options;
|
|
42
|
+
export const isRenewableMethod = (method: string) => renewableCredentialMethods.includes(method);
|
|
43
|
+
|
|
44
|
+
export const catalogOperationSchema = z.object({
|
|
45
|
+
key: operationKeySchema,
|
|
46
|
+
name: z.string(),
|
|
47
|
+
resourceKind: z.string(),
|
|
48
|
+
requiredScopes: z.array(z.string()),
|
|
49
|
+
});
|
|
50
|
+
export const providerSchema = z.enum([
|
|
51
|
+
'slack',
|
|
52
|
+
'discord',
|
|
53
|
+
'teams',
|
|
54
|
+
'linear',
|
|
55
|
+
'notion',
|
|
56
|
+
'jira',
|
|
57
|
+
'google',
|
|
58
|
+
'gmail',
|
|
59
|
+
'drive',
|
|
60
|
+
'confluence',
|
|
61
|
+
'anthropic',
|
|
62
|
+
'openai',
|
|
63
|
+
'geminiApi',
|
|
64
|
+
'archive',
|
|
65
|
+
'github',
|
|
66
|
+
'githubOrganization',
|
|
67
|
+
'githubUser',
|
|
68
|
+
'foundry',
|
|
69
|
+
'oracle',
|
|
70
|
+
'chorus',
|
|
71
|
+
'railway',
|
|
72
|
+
'render',
|
|
73
|
+
'claude',
|
|
74
|
+
'codex',
|
|
75
|
+
'muse',
|
|
76
|
+
]);
|
|
77
|
+
export const providerDefinitionSchema = z.object({
|
|
78
|
+
key: providerSchema,
|
|
79
|
+
name: z.string(),
|
|
80
|
+
documentationUrl: z.url(),
|
|
81
|
+
authMethods: z.array(credentialMethodSchema),
|
|
82
|
+
operations: z.array(catalogOperationSchema),
|
|
83
|
+
inbound: z.boolean().optional(),
|
|
84
|
+
delivery: z.literal('installationSocket').optional(),
|
|
85
|
+
subscription: z.boolean().optional(),
|
|
86
|
+
family: providerSchema.optional(),
|
|
87
|
+
oauthScopes: z.array(z.string()).optional(),
|
|
88
|
+
oauth: z.object({ authorizeUrl: z.url(), tokenUrl: z.url() }).optional(),
|
|
89
|
+
});
|
|
90
|
+
export type Provider = z.infer<typeof providerSchema>;
|
|
91
|
+
export type OAuthClient = { clientId: string; clientSecret: string };
|
|
92
|
+
export type SigningClient = OAuthClient & { appId: string; privateKey: string };
|
|
93
|
+
export type ProviderDefinition = z.infer<typeof providerDefinitionSchema> & {
|
|
94
|
+
eventResourceExternalId?: (event: Pick<IntegrationEvent, 'scope' | 'payload'>) => string | null;
|
|
95
|
+
syncedResourceKinds?: string[];
|
|
96
|
+
holderHandleKinds?: string[];
|
|
97
|
+
};
|
|
98
|
+
export type ProviderContext = {
|
|
99
|
+
provider: Provider;
|
|
100
|
+
configuration: unknown;
|
|
101
|
+
resource: { kind: string; externalId: string; metadata: unknown };
|
|
102
|
+
operation: string;
|
|
103
|
+
input: Record<string, unknown>;
|
|
104
|
+
limit: number;
|
|
105
|
+
method: z.infer<typeof credentialMethodSchema>;
|
|
106
|
+
secret: z.infer<typeof credentialSecretSchema>;
|
|
107
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ProviderDefinition } from './contracts';
|
|
2
|
+
|
|
3
|
+
export const declaredOperations = <O extends string>(
|
|
4
|
+
names: Record<O, string>,
|
|
5
|
+
resourceKind: string,
|
|
6
|
+
requiredScopes: string[] = [],
|
|
7
|
+
operations: readonly O[] = Object.keys(names) as O[],
|
|
8
|
+
): ProviderDefinition['operations'] =>
|
|
9
|
+
operations.map((key) => ({ key, name: names[key], resourceKind, requiredScopes }));
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { OAuthClient, Provider } from './contracts';
|
|
3
|
+
import { findProvider } from './findProvider';
|
|
4
|
+
import { ProviderError } from './utils/providerError';
|
|
5
|
+
import type { ProviderSend } from './utils/providerSend';
|
|
6
|
+
import { readProviderJson } from './utils/readProviderJson';
|
|
7
|
+
|
|
8
|
+
const tokenResponseSchema = z.object({
|
|
9
|
+
access_token: z.string().min(1).max(16000),
|
|
10
|
+
expires_in: z.number().int().positive().max(31536000).optional(),
|
|
11
|
+
refresh_token: z.string().min(1).max(16000).optional(),
|
|
12
|
+
scope: z.string().default(''),
|
|
13
|
+
id_token: z.string().min(1).optional(),
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
export const exchangeOauthCode = async (
|
|
17
|
+
{ app, send = fetch }: { app: OAuthClient; send?: ProviderSend },
|
|
18
|
+
input: { family: Provider; code: string; codeVerifier?: string; redirectUri?: string },
|
|
19
|
+
) => {
|
|
20
|
+
const { family } = input;
|
|
21
|
+
const tokenUrl = z.url().parse(findProvider(family)?.oauth?.tokenUrl);
|
|
22
|
+
let response: Response;
|
|
23
|
+
try {
|
|
24
|
+
response = await send(
|
|
25
|
+
new Request(tokenUrl, {
|
|
26
|
+
method: 'POST',
|
|
27
|
+
headers: {
|
|
28
|
+
Accept: 'application/json',
|
|
29
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
30
|
+
},
|
|
31
|
+
body: new URLSearchParams({
|
|
32
|
+
grant_type: 'authorization_code',
|
|
33
|
+
code: input.code,
|
|
34
|
+
client_id: app.clientId,
|
|
35
|
+
client_secret: app.clientSecret,
|
|
36
|
+
...(input.redirectUri ? { redirect_uri: input.redirectUri } : {}),
|
|
37
|
+
...(input.codeVerifier ? { code_verifier: input.codeVerifier } : {}),
|
|
38
|
+
}).toString(),
|
|
39
|
+
redirect: 'error',
|
|
40
|
+
signal: AbortSignal.timeout(15000),
|
|
41
|
+
}),
|
|
42
|
+
);
|
|
43
|
+
} catch {
|
|
44
|
+
throw new ProviderError('provider_unreachable', 502);
|
|
45
|
+
}
|
|
46
|
+
if (!response.ok) {
|
|
47
|
+
await response.body?.cancel();
|
|
48
|
+
throw new ProviderError('code_exchange_failed', 502);
|
|
49
|
+
}
|
|
50
|
+
const parsed = tokenResponseSchema.safeParse(
|
|
51
|
+
await readProviderJson(response, { remainingBytes: 128 * 1024 }).catch(() => null),
|
|
52
|
+
);
|
|
53
|
+
if (!parsed.success) throw new ProviderError('code_exchange_failed', 502);
|
|
54
|
+
return {
|
|
55
|
+
accessToken: parsed.data.access_token,
|
|
56
|
+
refreshToken: parsed.data.refresh_token ?? null,
|
|
57
|
+
expiresIn: parsed.data.expires_in ?? null,
|
|
58
|
+
scopes: parsed.data.scope.split(/[ ,]/).filter(Boolean),
|
|
59
|
+
idToken: parsed.data.id_token ?? null,
|
|
60
|
+
};
|
|
61
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { buildProviderRequest } from './buildProviderRequest';
|
|
2
|
+
import type { ProviderContext } from './contracts';
|
|
3
|
+
import { findOperationHandler } from './findOperationHandler';
|
|
4
|
+
import { fetchGmailMessages } from './providers/gmail/fetchGmailMessages';
|
|
5
|
+
import { ProviderError } from './utils/providerError';
|
|
6
|
+
import type { ProviderSend } from './utils/providerSend';
|
|
7
|
+
import { requestProviderJson } from './utils/requestProviderJson';
|
|
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
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { PROVIDER_EXCHANGE_TIMEOUT_MS } from './providerExchangeTimeoutMs';
|
|
3
|
+
import type { RenewalRequest } from './renewalRequest';
|
|
4
|
+
import { ProviderError } from './utils/providerError';
|
|
5
|
+
import { readProviderJson } from './utils/readProviderJson';
|
|
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
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
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;
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { archiveConfigurationSchema } from './archiveConfigurationSchema';
|
|
3
|
+
import { perProvider } from './perProvider';
|
|
4
|
+
|
|
5
|
+
const atlassianConfigurationSchema = z.strictObject({ cloudId: z.uuid() });
|
|
6
|
+
|
|
7
|
+
export const integrationConfigurationSchemas = perProvider(z.strictObject({}), {
|
|
8
|
+
jira: atlassianConfigurationSchema,
|
|
9
|
+
confluence: atlassianConfigurationSchema,
|
|
10
|
+
archive: archiveConfigurationSchema,
|
|
11
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { eventOperationKey, type IntegrationEvent } from '@inixiative/signet/contracts';
|
|
2
|
+
import type { Provider } from './contracts';
|
|
3
|
+
import { findProvider } from './findProvider';
|
|
4
|
+
import { isIntegrationKeyedKind } from './integrationKeyedKinds';
|
|
5
|
+
|
|
6
|
+
export const eventResourceKey = (
|
|
7
|
+
provider: Provider,
|
|
8
|
+
event: Pick<IntegrationEvent, 'type' | 'scope' | 'payload' | 'integrationId'>,
|
|
9
|
+
) => {
|
|
10
|
+
const definition = findProvider(provider);
|
|
11
|
+
const kind = definition?.operations.find(
|
|
12
|
+
(operation) => operation.key === eventOperationKey(event.type),
|
|
13
|
+
)?.resourceKind;
|
|
14
|
+
if (!kind) return null;
|
|
15
|
+
if (isIntegrationKeyedKind(kind)) return { kind, externalId: event.integrationId };
|
|
16
|
+
const externalId = definition?.eventResourceExternalId
|
|
17
|
+
? definition.eventResourceExternalId(event)
|
|
18
|
+
: event.scope;
|
|
19
|
+
return externalId ? { kind, externalId } : null;
|
|
20
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Provider } from './contracts';
|
|
2
|
+
import { isFamilyManaged } from './isFamilyManaged';
|
|
3
|
+
import { providerHasEvents } from './providerHasEvents';
|
|
4
|
+
|
|
5
|
+
export const isAccountSuppliedByHost = (provider: Provider | null | undefined) =>
|
|
6
|
+
isFamilyManaged(provider) || providerHasEvents(provider);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const isEventLeaf = (key: string) => key.startsWith('events.');
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Provider } from './contracts';
|
|
2
|
+
import { findProvider } from './findProvider';
|
|
3
|
+
|
|
4
|
+
export const isFamilyManaged = (provider: Provider | null | undefined) => {
|
|
5
|
+
const definition = findProvider(provider);
|
|
6
|
+
return Boolean(definition?.oauth || definition?.family);
|
|
7
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { conversationPermissionSchema } from '@inixiative/signet/contracts';
|
|
2
|
+
import { isEventLeaf } from './isEventLeaf';
|
|
3
|
+
|
|
4
|
+
const heldPermissions = new Set<string>(conversationPermissionSchema.options);
|
|
5
|
+
|
|
6
|
+
export const isUncalledLeaf = (key: string) => isEventLeaf(key) || heldPermissions.has(key);
|