@inixiative/integrations 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (214) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +50 -2
  3. package/package.json +56 -4
  4. package/src/catalog/declaredOperations.ts +9 -0
  5. package/src/catalog/eventLeaves.ts +5 -0
  6. package/src/catalog/familyProducts.ts +5 -0
  7. package/src/catalog/findProvider.ts +5 -0
  8. package/src/catalog/integrationEventResource.ts +20 -0
  9. package/src/catalog/integrationKeyedKinds.ts +4 -0
  10. package/src/catalog/isAccountSuppliedByHost.ts +6 -0
  11. package/src/catalog/isEventLeaf.ts +1 -0
  12. package/src/catalog/isFamilyManaged.ts +7 -0
  13. package/src/catalog/isUncalledLeaf.ts +6 -0
  14. package/src/catalog/operationLeaves.ts +6 -0
  15. package/src/catalog/providerEvent.ts +3 -0
  16. package/src/catalog/providerEventSchema.ts +3 -0
  17. package/src/catalog/providerFamily.ts +4 -0
  18. package/src/catalog/providerHasEvents.ts +8 -0
  19. package/src/catalog/providerModel.ts +12 -0
  20. package/src/catalog/providers.ts +54 -0
  21. package/src/contracts.ts +107 -0
  22. package/src/credentials/codexClientId.ts +2 -0
  23. package/src/credentials/codexTokenUrl.ts +1 -0
  24. package/src/credentials/consentReason.ts +4 -0
  25. package/src/credentials/consentReasonSchema.ts +21 -0
  26. package/src/credentials/credentialClient.ts +4 -0
  27. package/src/credentials/exchangeOauthCode.ts +61 -0
  28. package/src/credentials/fetchRenewalResponse.ts +41 -0
  29. package/src/credentials/mintProviderCredential.ts +68 -0
  30. package/src/credentials/providerExchangeTimeoutMs.ts +1 -0
  31. package/src/credentials/refreshProviderCredential.ts +172 -0
  32. package/src/credentials/renewalRequest.ts +1 -0
  33. package/src/credentials/subscriptionAccountId.ts +12 -0
  34. package/src/credentials/validateCredentialSecret.ts +18 -0
  35. package/src/index.ts +3 -0
  36. package/src/operations/buildProviderRequest.ts +54 -0
  37. package/src/operations/executeProvider.ts +26 -0
  38. package/src/operations/findOperationHandler.ts +6 -0
  39. package/src/operations/operationHandler.ts +8 -0
  40. package/src/operations/operationHandlers.ts +41 -0
  41. package/src/operations/operationRequestInput.ts +12 -0
  42. package/src/operations/providerRequestSpec.ts +1 -0
  43. package/src/providers/anthropic/anthropicProvider.ts +16 -0
  44. package/src/providers/archive/archiveCandidate.ts +1 -0
  45. package/src/providers/archive/archiveConfigurationSchema.ts +3 -0
  46. package/src/providers/archive/archiveProvider.ts +21 -0
  47. package/src/providers/archive/isLocalArchive.ts +5 -0
  48. package/src/providers/archive/localArchiveConfigurationSchema.ts +5 -0
  49. package/src/providers/archive/localArchiveSourceId.ts +8 -0
  50. package/src/providers/chorus/chorusProvider.ts +22 -0
  51. package/src/providers/claude/claudeProvider.ts +17 -0
  52. package/src/providers/codex/codexProvider.ts +17 -0
  53. package/src/providers/confluence/confluenceOperationHandler.ts +14 -0
  54. package/src/providers/confluence/confluenceProvider.ts +16 -0
  55. package/src/providers/discord/discordOperationHandler.ts +30 -0
  56. package/src/providers/discord/discordProvider.ts +22 -0
  57. package/src/providers/drive/driveOperationHandler.ts +21 -0
  58. package/src/providers/drive/driveProvider.ts +18 -0
  59. package/src/providers/foundry/foundryProvider.ts +33 -0
  60. package/src/providers/geminiApi/geminiApiProvider.ts +16 -0
  61. package/src/providers/github/auth/fetchGithubAppInstallation.ts +21 -0
  62. package/src/providers/github/auth/fetchGithubOrganizationRole.ts +27 -0
  63. package/src/providers/github/auth/fetchGithubUser.ts +11 -0
  64. package/src/providers/github/auth/fetchGithubUserInstallation.ts +21 -0
  65. package/src/providers/github/auth/githubAppClient.ts +4 -0
  66. package/src/providers/github/auth/githubAppInstallUrl.ts +20 -0
  67. package/src/providers/github/auth/githubAppJwt.ts +16 -0
  68. package/src/providers/github/auth/githubClientForApp.ts +11 -0
  69. package/src/providers/github/auth/githubInstallation.ts +4 -0
  70. package/src/providers/github/auth/githubInstallationAccountId.ts +4 -0
  71. package/src/providers/github/auth/githubInstallationFromAccountId.ts +4 -0
  72. package/src/providers/github/auth/githubInstallationSchema.ts +12 -0
  73. package/src/providers/github/auth/githubPermissionCovers.ts +14 -0
  74. package/src/providers/github/auth/githubPermissionScopes.ts +4 -0
  75. package/src/providers/github/auth/githubProviderForOwner.ts +6 -0
  76. package/src/providers/github/auth/githubUserAuthorizeUrl.ts +10 -0
  77. package/src/providers/github/events/githubEventRepositoryId.ts +10 -0
  78. package/src/providers/github/events/githubNotification.ts +4 -0
  79. package/src/providers/github/events/githubNotificationSchema.ts +9 -0
  80. package/src/providers/github/events/listGithubNotifications.ts +27 -0
  81. package/src/providers/github/events/normalizeGithubEvent.ts +200 -0
  82. package/src/providers/github/events/normalizeGithubNotification.ts +56 -0
  83. package/src/providers/github/events/verifyGithubSignature.ts +7 -0
  84. package/src/providers/github/fetchAllGithubPages.ts +12 -0
  85. package/src/providers/github/githubApiVersion.ts +1 -0
  86. package/src/providers/github/githubOrganizationProvider.ts +13 -0
  87. package/src/providers/github/githubPagination.ts +7 -0
  88. package/src/providers/github/githubProvider.ts +13 -0
  89. package/src/providers/github/githubRequestHeaders.ts +9 -0
  90. package/src/providers/github/githubUserProvider.ts +13 -0
  91. package/src/providers/github/iterateGithubPages.ts +12 -0
  92. package/src/providers/github/models/account/githubAccount.ts +17 -0
  93. package/src/providers/github/models/repository/githubOperationHandler.ts +36 -0
  94. package/src/providers/github/models/repository/githubRepository.ts +40 -0
  95. package/src/providers/github/models/repository/githubRepositoryIdSchema.ts +3 -0
  96. package/src/providers/github/models/repository/githubRepositoryMetadataSchema.ts +6 -0
  97. package/src/providers/github/models/repository/githubRepositoryName.ts +4 -0
  98. package/src/providers/github/models/repository/githubRepositoryNameSchema.ts +9 -0
  99. package/src/providers/github/models/repository/githubTreeEntryModeSchema.ts +3 -0
  100. package/src/providers/github/models/repository/githubTreeEntryTypeForMode.ts +14 -0
  101. package/src/providers/github/models/repository/githubTreeEntryTypeSchema.ts +3 -0
  102. package/src/providers/github/models/repository/listInstallationRepositories.ts +31 -0
  103. package/src/providers/github/models/repository/listUserRepositories.ts +36 -0
  104. package/src/providers/github/models/repository/readGithubObject.ts +85 -0
  105. package/src/providers/github/models/repository/readGithubRepositoryName.ts +4 -0
  106. package/src/providers/github/requestGithub.ts +18 -0
  107. package/src/providers/gmail/buildGmailMessageRequest.ts +22 -0
  108. package/src/providers/gmail/fetchGmailMessages.ts +81 -0
  109. package/src/providers/gmail/gmailOperationHandler.ts +12 -0
  110. package/src/providers/gmail/gmailProvider.ts +19 -0
  111. package/src/providers/google/auth/buildGoogleAuthorizationUrl.ts +33 -0
  112. package/src/providers/google/auth/verifyGoogleIdToken.ts +22 -0
  113. package/src/providers/google/googleProvider.ts +13 -0
  114. package/src/providers/jira/jiraOperationHandler.ts +14 -0
  115. package/src/providers/jira/jiraProvider.ts +16 -0
  116. package/src/providers/linear/auth/linearIntegrationSecret.ts +6 -0
  117. package/src/providers/linear/events/createLinearWebhook.ts +30 -0
  118. package/src/providers/linear/events/deleteLinearWebhook.ts +13 -0
  119. package/src/providers/linear/events/linearUserSchema.ts +3 -0
  120. package/src/providers/linear/events/linearWebhook.ts +3 -0
  121. package/src/providers/linear/events/linearWebhookPayload.ts +4 -0
  122. package/src/providers/linear/events/linearWebhookPayloadSchema.ts +13 -0
  123. package/src/providers/linear/events/listLinearWebhooks.ts +44 -0
  124. package/src/providers/linear/events/normalizeLinearEvent.ts +127 -0
  125. package/src/providers/linear/events/repairLinearWebhook.ts +17 -0
  126. package/src/providers/linear/events/verifyLinearSignature.ts +25 -0
  127. package/src/providers/linear/fetchAllLinearPages.ts +40 -0
  128. package/src/providers/linear/linearClient.ts +5 -0
  129. package/src/providers/linear/linearPagination.ts +13 -0
  130. package/src/providers/linear/linearProvider.ts +12 -0
  131. package/src/providers/linear/linearRequestInput.ts +1 -0
  132. package/src/providers/linear/models/issue/linearIssue.ts +11 -0
  133. package/src/providers/linear/models/issue/linearOperationHandler.ts +30 -0
  134. package/src/providers/linear/models/team/fetchLinearWorkspace.ts +30 -0
  135. package/src/providers/linear/models/team/linearTeam.ts +18 -0
  136. package/src/providers/linear/requestLinear.ts +51 -0
  137. package/src/providers/muse/museProvider.ts +17 -0
  138. package/src/providers/notion/notionOperationHandler.ts +32 -0
  139. package/src/providers/notion/notionProvider.ts +22 -0
  140. package/src/providers/openai/openaiProvider.ts +16 -0
  141. package/src/providers/oracle/oracleProvider.ts +10 -0
  142. package/src/providers/railway/railwayProvider.ts +9 -0
  143. package/src/providers/render/renderProvider.ts +9 -0
  144. package/src/providers/slack/auth/fetchSlackIdentity.ts +10 -0
  145. package/src/providers/slack/events/normalizeSlackEvent.ts +64 -0
  146. package/src/providers/slack/events/slackAccountIdOf.ts +1 -0
  147. package/src/providers/slack/events/slackEventEnvelope.ts +4 -0
  148. package/src/providers/slack/events/slackEventEnvelopeSchema.ts +16 -0
  149. package/src/providers/slack/events/slackTeamPrefix.ts +1 -0
  150. package/src/providers/slack/events/slackTokensRevokedSchema.ts +13 -0
  151. package/src/providers/slack/events/slackUserOfAccountId.ts +2 -0
  152. package/src/providers/slack/events/verifySlackSignature.ts +17 -0
  153. package/src/providers/slack/fetchAllSlackPages.ts +12 -0
  154. package/src/providers/slack/models/account/slackAccount.ts +13 -0
  155. package/src/providers/slack/models/channel/listSlackChannels.ts +26 -0
  156. package/src/providers/slack/models/channel/slackChannel.ts +31 -0
  157. package/src/providers/slack/models/channel/slackOperationHandler.ts +30 -0
  158. package/src/providers/slack/requestSlack.ts +22 -0
  159. package/src/providers/slack/slackPagination.ts +12 -0
  160. package/src/providers/slack/slackProvider.ts +12 -0
  161. package/src/providers/slack/slackProviderError.ts +12 -0
  162. package/src/providers/teams/teamsOperationHandler.ts +24 -0
  163. package/src/providers/teams/teamsProvider.ts +17 -0
  164. package/src/resources/integrationConfigurationSchemas.ts +11 -0
  165. package/src/resources/perProvider.ts +20 -0
  166. package/src/resources/resourceExternalIdSchema.ts +4 -0
  167. package/src/resources/resourceExternalIdSchemas.ts +18 -0
  168. package/src/resources/resourceMetadataSchema.ts +4 -0
  169. package/src/resources/resourceMetadataSchemas.ts +9 -0
  170. package/src/utils/capacityWindowSchema.ts +7 -0
  171. package/src/utils/headerNumber.ts +6 -0
  172. package/src/utils/jwtClaims.ts +14 -0
  173. package/src/utils/matchesHmacSha256.ts +11 -0
  174. package/src/utils/objectSchema.ts +3 -0
  175. package/src/utils/pagination/applyCaps.ts +18 -0
  176. package/src/utils/pagination/byCursorKeys.ts +7 -0
  177. package/src/utils/pagination/byCursorOptions.ts +7 -0
  178. package/src/utils/pagination/byPageKeys.ts +7 -0
  179. package/src/utils/pagination/byPageOptions.ts +8 -0
  180. package/src/utils/pagination/collectPages.ts +27 -0
  181. package/src/utils/pagination/compactRequest.ts +4 -0
  182. package/src/utils/pagination/fetchAllByCursor.ts +6 -0
  183. package/src/utils/pagination/fetchAllByPage.ts +6 -0
  184. package/src/utils/pagination/fetchAllRequestPages.ts +16 -0
  185. package/src/utils/pagination/incompletePageWalkError.ts +8 -0
  186. package/src/utils/pagination/isAnotherPage.ts +20 -0
  187. package/src/utils/pagination/iterateByCursor.ts +49 -0
  188. package/src/utils/pagination/iterateByPage.ts +59 -0
  189. package/src/utils/pagination/iterateProviderPages.ts +27 -0
  190. package/src/utils/pagination/iterateRequestPages.ts +18 -0
  191. package/src/utils/pagination/pageWalkError.ts +6 -0
  192. package/src/utils/pagination/paginationOptions.ts +9 -0
  193. package/src/utils/pagination/providerPagesOptions.ts +8 -0
  194. package/src/utils/pagination/providerPagination.ts +6 -0
  195. package/src/utils/pagination/readPage.ts +29 -0
  196. package/src/utils/pagination/readPath.ts +12 -0
  197. package/src/utils/pagination/repeatedCursorError.ts +10 -0
  198. package/src/utils/providerClient.ts +3 -0
  199. package/src/utils/providerCooldown.ts +23 -0
  200. package/src/utils/providerCooldownState.ts +4 -0
  201. package/src/utils/providerError.ts +10 -0
  202. package/src/utils/providerReading.ts +4 -0
  203. package/src/utils/providerReadingSchema.ts +8 -0
  204. package/src/utils/providerRequest.ts +22 -0
  205. package/src/utils/providerRequestInput.ts +7 -0
  206. package/src/utils/providerResponseLimit.ts +1 -0
  207. package/src/utils/providerSend.ts +1 -0
  208. package/src/utils/readProviderJson.ts +38 -0
  209. package/src/utils/readProviderLimits.ts +66 -0
  210. package/src/utils/readRateLimit.ts +29 -0
  211. package/src/utils/requestProviderJson.ts +13 -0
  212. package/src/utils/responseBudget.ts +1 -0
  213. package/src/utils/select.ts +6 -0
  214. package/src/utils/sendProviderRequest.ts +33 -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
- # Temporary Holding Version
1
+ # @inixiative/integrations
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
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/catalog/findProvider';
19
+ import { operationLeaves } from '@inixiative/integrations/catalog/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/providers.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.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.2.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,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,5 @@
1
+ import { isEventLeaf } from './isEventLeaf';
2
+ import { operationLeaves } from './operationLeaves';
3
+
4
+ export const eventLeaves = (provider: string | null | undefined, kind: string) =>
5
+ operationLeaves(provider, kind).filter(isEventLeaf);
@@ -0,0 +1,5 @@
1
+ import type { Provider } from '../contracts';
2
+ import { providers } from './providers';
3
+
4
+ export const familyProducts = (family: Provider) =>
5
+ providers.filter((definition) => definition.family === family);
@@ -0,0 +1,5 @@
1
+ import type { Provider } from '../contracts';
2
+ import { providers } from './providers';
3
+
4
+ export const findProvider = (value: Provider | null | undefined) =>
5
+ providers.find((provider) => provider.key === value);
@@ -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,4 @@
1
+ import { accountResourceKind, archiveLibraryResourceKind } from '@inixiative/signet/contracts';
2
+
3
+ export const isIntegrationKeyedKind = (kind: string) =>
4
+ kind === archiveLibraryResourceKind || kind === accountResourceKind;
@@ -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);
@@ -0,0 +1,6 @@
1
+ import { providers } from './providers';
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,3 @@
1
+ import type { IntegrationEvent } from '@inixiative/signet/contracts';
2
+
3
+ export type ProviderEvent = Omit<IntegrationEvent, 'id'>;
@@ -0,0 +1,3 @@
1
+ import { integrationEventSchema } from '@inixiative/signet/contracts';
2
+
3
+ export const providerEventSchema = integrationEventSchema.omit({ id: true });
@@ -0,0 +1,4 @@
1
+ import { providers } from './providers';
2
+
3
+ export const providerFamily = <T extends string | null | undefined>(provider: T) =>
4
+ providers.find((definition) => definition.key === provider)?.family ?? provider;
@@ -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,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,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,2 @@
1
+ // why: the Codex CLI's public OAuth client, so a renewal is the one Codex itself would make.
2
+ export const CODEX_CLIENT_ID = 'app_EMoamEEZ73f0CkXaXp7hrann';
@@ -0,0 +1 @@
1
+ export const CODEX_TOKEN_URL = 'https://auth.openai.com/oauth/token';
@@ -0,0 +1,4 @@
1
+ import type { z } from 'zod';
2
+ import type { consentReasonSchema } from './consentReasonSchema';
3
+
4
+ export type ConsentReason = z.infer<typeof consentReasonSchema>;
@@ -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
+ ]);
@@ -0,0 +1,4 @@
1
+ import type { OAuthClient, SigningClient } from '../contracts';
2
+ import type { ProviderSend } from '../utils/providerSend';
3
+
4
+ export type CredentialClient = { app?: OAuthClient | SigningClient; send?: ProviderSend };
@@ -0,0 +1,61 @@
1
+ import { z } from 'zod';
2
+ import { findProvider } from '../catalog/findProvider';
3
+ import type { OAuthClient, Provider } from '../contracts';
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,41 @@
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
+ };
@@ -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 { githubAppJwt } from '../providers/github/auth/githubAppJwt';
9
+ import { githubPermissionScopes } from '../providers/github/auth/githubPermissionScopes';
10
+ import { githubRequestHeaders } from '../providers/github/githubRequestHeaders';
11
+ import { ProviderError } from '../utils/providerError';
12
+ import type { CredentialClient } from './credentialClient';
13
+ import { fetchRenewalResponse } from './fetchRenewalResponse';
14
+ import type { RenewalRequest } from './renewalRequest';
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 @@
1
+ export const PROVIDER_EXCHANGE_TIMEOUT_MS = 15_000;