@shipfox/api-integration-github 8.0.0 → 9.0.2
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/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +53 -0
- package/dist/api/client.js +1 -1
- package/dist/api/client.js.map +1 -1
- package/dist/api/installation-token-envelope.d.ts +1 -1
- package/dist/api/installation-token-envelope.d.ts.map +1 -1
- package/dist/api/installation-token-envelope.js +1 -1
- package/dist/api/installation-token-envelope.js.map +1 -1
- package/dist/api/installation-token-provider.d.ts +1 -1
- package/dist/api/installation-token-provider.d.ts.map +1 -1
- package/dist/api/installation-token-provider.js.map +1 -1
- package/dist/core/actions-logs.d.ts +1 -1
- package/dist/core/actions-logs.d.ts.map +1 -1
- package/dist/core/actions-logs.js +2 -2
- package/dist/core/actions-logs.js.map +1 -1
- package/dist/core/agent-tool-selection.d.ts +1 -1
- package/dist/core/agent-tool-selection.d.ts.map +1 -1
- package/dist/core/agent-tool-selection.js +1 -1
- package/dist/core/agent-tool-selection.js.map +1 -1
- package/dist/core/agent-tools.d.ts +4 -4
- package/dist/core/agent-tools.d.ts.map +1 -1
- package/dist/core/agent-tools.js +2 -2
- package/dist/core/agent-tools.js.map +1 -1
- package/dist/core/errors.d.ts +1 -1
- package/dist/core/errors.d.ts.map +1 -1
- package/dist/core/errors.js +1 -1
- package/dist/core/errors.js.map +1 -1
- package/dist/core/github-agent-tool-catalog.d.ts +49 -0
- package/dist/core/github-agent-tool-catalog.d.ts.map +1 -0
- package/dist/core/github-agent-tool-catalog.js +867 -0
- package/dist/core/github-agent-tool-catalog.js.map +1 -0
- package/dist/core/install.d.ts +1 -1
- package/dist/core/install.d.ts.map +1 -1
- package/dist/core/install.js.map +1 -1
- package/dist/core/source-control.d.ts +1 -1
- package/dist/core/source-control.d.ts.map +1 -1
- package/dist/core/source-control.js +1 -1
- package/dist/core/source-control.js.map +1 -1
- package/dist/core/webhook-processor.d.ts +1 -1
- package/dist/core/webhook-processor.d.ts.map +1 -1
- package/dist/core/webhook-processor.js +1 -1
- package/dist/core/webhook-processor.js.map +1 -1
- package/dist/core/webhook.d.ts +1 -1
- package/dist/core/webhook.d.ts.map +1 -1
- package/dist/core/webhook.js +1 -1
- package/dist/core/webhook.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/metrics/instance.d.ts +1 -1
- package/dist/metrics/instance.d.ts.map +1 -1
- package/dist/metrics/instance.js.map +1 -1
- package/dist/presentation/dto/integrations.d.ts +8 -7
- package/dist/presentation/dto/integrations.d.ts.map +1 -1
- package/dist/presentation/dto/integrations.js +18 -7
- package/dist/presentation/dto/integrations.js.map +1 -1
- package/dist/presentation/e2eRoutes/create-connection.d.ts +1 -1
- package/dist/presentation/e2eRoutes/create-connection.d.ts.map +1 -1
- package/dist/presentation/e2eRoutes/create-connection.js +1 -1
- package/dist/presentation/e2eRoutes/create-connection.js.map +1 -1
- package/dist/presentation/routes/errors.js +1 -1
- package/dist/presentation/routes/errors.js.map +1 -1
- package/dist/presentation/routes/install.d.ts +1 -1
- package/dist/presentation/routes/install.d.ts.map +1 -1
- package/dist/presentation/routes/install.js.map +1 -1
- package/dist/presentation/routes/webhooks.d.ts +1 -1
- package/dist/presentation/routes/webhooks.d.ts.map +1 -1
- package/dist/presentation/routes/webhooks.js +1 -1
- package/dist/presentation/routes/webhooks.js.map +1 -1
- package/dist/tsconfig.test.tsbuildinfo +1 -1
- package/package.json +25 -14
- package/src/api/client.ts +1 -1
- package/src/api/installation-token-envelope.ts +1 -1
- package/src/api/installation-token-provider.test.ts +1 -1
- package/src/api/installation-token-provider.ts +1 -1
- package/src/core/actions-logs.ts +2 -2
- package/src/core/agent-tool-selection.ts +1 -1
- package/src/core/agent-tools.ts +10 -10
- package/src/core/errors.ts +1 -1
- package/src/core/github-agent-tool-catalog.ts +963 -0
- package/src/core/install.test.ts +1 -1
- package/src/core/install.ts +1 -1
- package/src/core/source-control.ts +1 -1
- package/src/core/webhook-processor.test.ts +1 -1
- package/src/core/webhook-processor.ts +1 -1
- package/src/core/webhook.test.ts +1 -1
- package/src/core/webhook.ts +7 -7
- package/src/index.ts +2 -1
- package/src/metrics/instance.ts +1 -1
- package/src/presentation/dto/integrations.ts +24 -6
- package/src/presentation/e2eRoutes/create-connection.ts +2 -2
- package/src/presentation/e2eRoutes/index.test.ts +1 -1
- package/src/presentation/routes/errors.ts +1 -1
- package/src/presentation/routes/install.test.ts +1 -1
- package/src/presentation/routes/install.ts +1 -1
- package/src/presentation/routes/webhooks.test.ts +1 -1
- package/src/presentation/routes/webhooks.ts +2 -5
- package/tsconfig.build.tsbuildinfo +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/core/github-agent-tool-catalog.ts"],"sourcesContent":["type AgentToolSensitivity = 'read' | 'write';\ntype AgentToolJsonSchema = Record<string, unknown>;\n\ninterface AgentToolCatalogMethod<RequiredScope = unknown> {\n id: string;\n description: string;\n sensitivity: AgentToolSensitivity;\n sensitive: boolean;\n requiredScope: RequiredScope;\n}\n\ninterface AgentToolCatalogEntry<RequiredScope = unknown> {\n id: string;\n description: string;\n sensitivity: AgentToolSensitivity;\n sensitive: boolean;\n requiredScope: RequiredScope;\n inputSchema: AgentToolJsonSchema;\n outputSchema?: AgentToolJsonSchema | undefined;\n methods?: readonly AgentToolCatalogMethod<RequiredScope>[] | undefined;\n}\n\ninterface AgentToolSelector {\n readonly token: string;\n readonly kind: 'family' | 'family_wildcard' | 'method' | 'standalone';\n readonly sensitivity: AgentToolSensitivity;\n readonly sensitive: boolean;\n}\n\ninterface AgentToolSelectionCatalog {\n readonly selectors: readonly AgentToolSelector[];\n}\n\nexport const DEFAULT_JOB_LOG_TAIL_LINES = 500;\n\nexport type GithubAgentToolCategory = 'issues' | 'pull_requests' | 'actions';\nexport type GithubAgentToolPermission = 'actions' | 'contents' | 'issues' | 'pull_requests';\nexport type GithubAgentToolPermissionAccess = 'read' | 'write';\nexport type GithubAgentToolSensitivity = 'read' | 'write';\n\nexport interface GithubAgentToolRequiredPermission {\n permission: GithubAgentToolPermission;\n access: GithubAgentToolPermissionAccess;\n}\n\nexport type GithubAgentToolRequiredScope = readonly GithubAgentToolRequiredPermission[];\n\nexport type GithubAgentToolCatalogMethod = AgentToolCatalogMethod<GithubAgentToolRequiredScope>;\n\nexport interface GithubAgentToolCatalogEntry\n extends AgentToolCatalogEntry<GithubAgentToolRequiredScope> {\n category: GithubAgentToolCategory;\n methods?: readonly GithubAgentToolCatalogMethod[] | undefined;\n}\n\ninterface GithubAgentToolCatalogInput {\n id: string;\n category: GithubAgentToolCategory;\n description: string;\n inputSchema: AgentToolJsonSchema;\n outputSchema: AgentToolJsonSchema;\n sensitivity?: GithubAgentToolSensitivity | undefined;\n sensitive?: boolean | undefined;\n requiredScope?: GithubAgentToolRequiredScope | undefined;\n methods?: readonly GithubAgentToolCatalogMethod[] | undefined;\n}\n\nconst scopes = {\n issuesRead: [{permission: 'issues', access: 'read'}],\n issuesWrite: [{permission: 'issues', access: 'write'}],\n pullRequestsRead: [{permission: 'pull_requests', access: 'read'}],\n pullRequestsWrite: [{permission: 'pull_requests', access: 'write'}],\n actionsRead: [{permission: 'actions', access: 'read'}],\n actionsWrite: [{permission: 'actions', access: 'write'}],\n mergePullRequest: [\n {permission: 'pull_requests', access: 'write'},\n {permission: 'contents', access: 'write'},\n ],\n} as const satisfies Record<string, GithubAgentToolRequiredScope>;\n\nconst repositoryProperties = {\n owner: stringSchema('Repository owner'),\n repo: stringSchema('Repository name'),\n};\n\nconst pageProperties = {\n page: integerSchema('Page number for pagination', {minimum: 1}),\n per_page: integerSchema('Results per page for pagination', {minimum: 1, maximum: 100}),\n};\n\nconst issueReadMethods = [\n method('get', 'Get information about a specific issue.', 'read', false, scopes.issuesRead),\n method('get_comments', 'Get comments on a specific issue.', 'read', false, scopes.issuesRead),\n method(\n 'get_sub_issues',\n 'Get sub-issues for a specific issue.',\n 'read',\n false,\n scopes.issuesRead,\n ),\n method(\n 'get_parent',\n 'Get the parent issue for a specific issue.',\n 'read',\n false,\n scopes.issuesRead,\n ),\n method(\n 'get_labels',\n 'Get labels assigned to a specific issue.',\n 'read',\n false,\n scopes.issuesRead,\n ),\n] as const satisfies readonly GithubAgentToolCatalogMethod[];\n\nconst issueWriteMethods = [\n method('create', 'Create a new issue.', 'write', false, scopes.issuesWrite),\n method('update', 'Update an existing issue.', 'write', false, scopes.issuesWrite),\n] as const satisfies readonly GithubAgentToolCatalogMethod[];\n\nconst subIssueWriteMethods = [\n method('add', 'Add a sub-issue to a parent issue.', 'write', false, scopes.issuesWrite),\n method('remove', 'Remove a sub-issue from a parent issue.', 'write', false, scopes.issuesWrite),\n method(\n 'reprioritize',\n 'Reprioritize a sub-issue under its parent issue.',\n 'write',\n false,\n scopes.issuesWrite,\n ),\n] as const satisfies readonly GithubAgentToolCatalogMethod[];\n\nconst pullRequestReadMethods = [\n method(\n 'get',\n 'Get information about a specific pull request.',\n 'read',\n false,\n scopes.pullRequestsRead,\n ),\n method(\n 'get_diff',\n 'Get the diff for a specific pull request.',\n 'read',\n false,\n scopes.pullRequestsRead,\n ),\n method(\n 'get_status',\n 'Get status information for a specific pull request.',\n 'read',\n false,\n scopes.pullRequestsRead,\n ),\n method(\n 'get_files',\n 'Get files changed in a specific pull request.',\n 'read',\n false,\n scopes.pullRequestsRead,\n ),\n method(\n 'get_commits',\n 'Get commits in a specific pull request.',\n 'read',\n false,\n scopes.pullRequestsRead,\n ),\n method(\n 'get_review_comments',\n 'Get review comments for a specific pull request.',\n 'read',\n false,\n scopes.pullRequestsRead,\n ),\n method(\n 'get_reviews',\n 'Get reviews for a specific pull request.',\n 'read',\n false,\n scopes.pullRequestsRead,\n ),\n method(\n 'get_comments',\n 'Get conversation comments for a specific pull request.',\n 'read',\n false,\n scopes.issuesRead,\n ),\n method(\n 'get_check_runs',\n 'Get check runs for the head commit of a pull request.',\n 'read',\n false,\n scopes.pullRequestsRead,\n ),\n] as const satisfies readonly GithubAgentToolCatalogMethod[];\n\nconst pullRequestReviewWriteMethods = [\n method(\n 'create',\n 'Create a pending pull request review.',\n 'write',\n false,\n scopes.pullRequestsWrite,\n ),\n method(\n 'submit_pending',\n 'Submit the latest pending pull request review.',\n 'write',\n false,\n scopes.pullRequestsWrite,\n ),\n method(\n 'delete_pending',\n 'Delete the latest pending pull request review.',\n 'write',\n false,\n scopes.pullRequestsWrite,\n ),\n] as const satisfies readonly GithubAgentToolCatalogMethod[];\n\nconst actionsListMethods = [\n method('list_workflows', 'List workflows in a repository.', 'read', false, scopes.actionsRead),\n method(\n 'list_workflow_runs',\n 'List workflow runs in a repository or for a workflow.',\n 'read',\n false,\n scopes.actionsRead,\n ),\n method('list_workflow_jobs', 'List jobs for a workflow run.', 'read', false, scopes.actionsRead),\n method(\n 'list_workflow_run_artifacts',\n 'List artifacts for a workflow run.',\n 'read',\n false,\n scopes.actionsRead,\n ),\n] as const satisfies readonly GithubAgentToolCatalogMethod[];\n\nconst actionsGetMethods = [\n method('get_workflow', 'Get details for a workflow.', 'read', false, scopes.actionsRead),\n method('get_workflow_run', 'Get details for a workflow run.', 'read', false, scopes.actionsRead),\n method('get_workflow_job', 'Get details for a workflow job.', 'read', false, scopes.actionsRead),\n method(\n 'download_workflow_run_artifact',\n 'Download a workflow run artifact.',\n 'read',\n false,\n scopes.actionsRead,\n ),\n method('get_workflow_run_usage', 'Get workflow run usage.', 'read', false, scopes.actionsRead),\n method(\n 'get_workflow_run_logs_url',\n 'Get a workflow run logs download URL.',\n 'read',\n false,\n scopes.actionsRead,\n ),\n] as const satisfies readonly GithubAgentToolCatalogMethod[];\n\nconst actionsRunTriggerMethods = [\n method('run_workflow', 'Trigger a workflow_dispatch run.', 'write', true, scopes.actionsWrite),\n method('rerun_workflow_run', 'Rerun a workflow run.', 'write', false, scopes.actionsWrite),\n method(\n 'rerun_failed_jobs',\n 'Rerun failed jobs in a workflow run.',\n 'write',\n false,\n scopes.actionsWrite,\n ),\n method('cancel_workflow_run', 'Cancel a workflow run.', 'write', false, scopes.actionsWrite),\n method(\n 'delete_workflow_run_logs',\n 'Delete logs for a workflow run.',\n 'write',\n true,\n scopes.actionsWrite,\n ),\n] as const satisfies readonly GithubAgentToolCatalogMethod[];\n\nexport const githubAgentToolCatalog = [\n tool({\n id: 'issue_read',\n category: 'issues',\n description: 'Get information about a specific issue in a GitHub repository.',\n methods: issueReadMethods,\n inputSchema: repositoryInputSchema(\n {\n method: methodSchema(issueReadMethods, 'The read operation to perform on a single issue'),\n issue_number: integerSchema('The number of the issue'),\n ...pageProperties,\n },\n ['method', 'issue_number'],\n ),\n outputSchema: openObjectSchema('Issue read result'),\n }),\n tool({\n id: 'list_issue_types',\n category: 'issues',\n description:\n 'List supported issue types for a repository or its owner organization. When repo is omitted, returns org-level issue types directly.',\n sensitivity: 'read',\n sensitive: false,\n requiredScope: scopes.issuesRead,\n inputSchema: objectSchema(\n {\n owner: stringSchema('The account owner of the repository or organization'),\n repo: stringSchema('The name of the repository'),\n },\n ['owner'],\n ),\n outputSchema: objectSchema({issue_types: arraySchema(openObjectSchema('Issue type'))}, [\n 'issue_types',\n ]),\n }),\n tool({\n id: 'list_issues',\n category: 'issues',\n description:\n \"List issues in a GitHub repository. For pagination, use the 'endCursor' from the previous response's 'pageInfo' in the 'after' parameter.\",\n sensitivity: 'read',\n sensitive: false,\n requiredScope: scopes.issuesRead,\n inputSchema: repositoryInputSchema({\n state: enumSchema(['OPEN', 'CLOSED'], 'Filter by state'),\n labels: arraySchema(stringSchema('Label name')),\n orderBy: enumSchema(['CREATED_AT', 'UPDATED_AT', 'COMMENTS'], 'Order issues by field'),\n direction: enumSchema(['ASC', 'DESC'], 'Order direction'),\n since: stringSchema('Filter by date (ISO 8601 timestamp)'),\n after: stringSchema('Pagination cursor'),\n first: integerSchema('Number of issues to return', {minimum: 1, maximum: 100}),\n }),\n outputSchema: objectSchema({issues: arraySchema(openObjectSchema('GitHub issue'))}, ['issues']),\n }),\n tool({\n id: 'search_issues',\n category: 'issues',\n description:\n 'Search for issues in GitHub repositories using issues search syntax already scoped to is:issue',\n sensitivity: 'read',\n sensitive: false,\n requiredScope: scopes.issuesRead,\n inputSchema: objectSchema(\n {\n query: stringSchema('Search query using GitHub issues search syntax'),\n owner: stringSchema('Optional repository owner'),\n repo: stringSchema('Optional repository name'),\n sort: enumSchema(\n [\n 'comments',\n 'reactions',\n 'reactions-+1',\n 'reactions--1',\n 'reactions-smile',\n 'reactions-thinking_face',\n 'reactions-heart',\n 'reactions-tada',\n 'interactions',\n 'created',\n 'updated',\n ],\n 'Sort field',\n ),\n order: enumSchema(['asc', 'desc'], 'Sort order'),\n ...pageProperties,\n },\n ['query'],\n ),\n outputSchema: objectSchema({issues: arraySchema(openObjectSchema('GitHub issue'))}, ['issues']),\n }),\n tool({\n id: 'add_issue_comment',\n category: 'issues',\n description:\n 'Add a comment and/or reaction to a specific issue or issue comment in a GitHub repository. Use this tool with pull requests as well, but only if the user is not asking specifically to add or react to review comments. At least one of body or reaction is required.',\n sensitivity: 'write',\n sensitive: false,\n requiredScope: scopes.issuesWrite,\n inputSchema: repositoryInputSchema(\n {\n issue_number: integerSchema('Issue or pull request number to comment on or react to'),\n comment_id: integerSchema(\n 'The numeric ID of the issue or pull request comment to react to',\n ),\n body: stringSchema('Comment content. Required unless reaction is provided'),\n reaction: enumSchema(\n ['+1', '-1', 'laugh', 'confused', 'heart', 'hooray', 'rocket', 'eyes'],\n 'Emoji reaction to add. Required unless body is provided',\n ),\n },\n [],\n {\n anyOf: [\n {required: ['issue_number', 'body']},\n {required: ['issue_number', 'reaction']},\n {required: ['comment_id', 'reaction']},\n ],\n },\n ),\n outputSchema: openObjectSchema('Created issue comment or reaction'),\n }),\n tool({\n id: 'issue_write',\n category: 'issues',\n description: 'Create a new or update an existing issue in a GitHub repository.',\n methods: issueWriteMethods,\n inputSchema: repositoryInputSchema(\n {\n method: methodSchema(issueWriteMethods, 'Write operation to perform on a single issue'),\n issue_number: integerSchema('Issue number to update'),\n title: stringSchema('Issue title'),\n body: stringSchema('Issue body content'),\n assignees: arraySchema(stringSchema('GitHub username')),\n labels: arraySchema(stringSchema('Label name')),\n milestone: integerSchema('Milestone number'),\n issue_type: stringSchema('Type of this issue'),\n state: enumSchema(['open', 'closed'], 'New state'),\n state_reason: enumSchema(\n ['completed', 'not_planned', 'duplicate'],\n 'Reason for the state change',\n ),\n duplicate_of: integerSchema('Issue number that this issue is a duplicate of'),\n },\n ['method'],\n ),\n outputSchema: openObjectSchema('Issue write result'),\n }),\n tool({\n id: 'sub_issue_write',\n category: 'issues',\n description:\n 'Add, remove, or reprioritize a sub-issue under a parent issue in a GitHub repository.',\n methods: subIssueWriteMethods,\n inputSchema: repositoryInputSchema(\n {\n method: methodSchema(subIssueWriteMethods, 'The action to perform on a single sub-issue'),\n issue_number: integerSchema('The number of the parent issue'),\n sub_issue_id: integerSchema('The ID of the sub-issue'),\n replace_parent: booleanSchema(\"Replace the sub-issue's current parent issue\"),\n after_id: integerSchema('The ID of the sub-issue to be prioritized after'),\n before_id: integerSchema('The ID of the sub-issue to be prioritized before'),\n },\n ['method', 'issue_number', 'sub_issue_id'],\n ),\n outputSchema: openObjectSchema('Sub-issue write result'),\n }),\n tool({\n id: 'pull_request_read',\n category: 'pull_requests',\n description: 'Get information on a specific pull request in a GitHub repository.',\n methods: pullRequestReadMethods,\n inputSchema: repositoryInputSchema(\n {\n method: methodSchema(\n pullRequestReadMethods,\n 'Action to specify what pull request data needs to be retrieved from GitHub',\n ),\n pull_number: integerSchema('Pull request number'),\n ref: stringSchema('Git reference to inspect. Required for get_status and get_check_runs'),\n cursor: stringSchema('Cursor for review comment pagination'),\n ...pageProperties,\n },\n ['method', 'pull_number'],\n {\n oneOf: [\n methodRequiredSchema('get', []),\n methodRequiredSchema('get_diff', []),\n methodRequiredSchema('get_status', ['ref']),\n methodRequiredSchema('get_files', []),\n methodRequiredSchema('get_commits', []),\n methodRequiredSchema('get_review_comments', []),\n methodRequiredSchema('get_reviews', []),\n methodRequiredSchema('get_comments', []),\n methodRequiredSchema('get_check_runs', ['ref']),\n ],\n },\n ),\n outputSchema: openObjectSchema('Pull request read result'),\n }),\n tool({\n id: 'list_pull_requests',\n category: 'pull_requests',\n description:\n 'List pull requests in a GitHub repository. If the user specifies an author, then do not use this tool and use the search_pull_requests tool instead.',\n sensitivity: 'read',\n sensitive: false,\n requiredScope: scopes.pullRequestsRead,\n inputSchema: repositoryInputSchema({\n state: enumSchema(['open', 'closed', 'all'], 'Filter by state'),\n head: stringSchema('Filter by head user/org and branch'),\n base: stringSchema('Filter by base branch'),\n sort: enumSchema(['created', 'updated', 'popularity', 'long-running'], 'Sort by'),\n direction: enumSchema(['asc', 'desc'], 'Sort direction'),\n ...pageProperties,\n }),\n outputSchema: objectSchema(\n {pull_requests: arraySchema(openObjectSchema('GitHub pull request'))},\n ['pull_requests'],\n ),\n }),\n tool({\n id: 'search_pull_requests',\n category: 'pull_requests',\n description:\n 'Search for pull requests in GitHub repositories using issues search syntax already scoped to is:pr',\n sensitivity: 'read',\n sensitive: false,\n requiredScope: scopes.pullRequestsRead,\n inputSchema: objectSchema(\n {\n query: stringSchema('Search query using GitHub pull request search syntax'),\n owner: stringSchema('Optional repository owner'),\n repo: stringSchema('Optional repository name'),\n sort: enumSchema(\n [\n 'comments',\n 'reactions',\n 'reactions-+1',\n 'reactions--1',\n 'reactions-smile',\n 'reactions-thinking_face',\n 'reactions-heart',\n 'reactions-tada',\n 'interactions',\n 'created',\n 'updated',\n ],\n 'Sort field',\n ),\n order: enumSchema(['asc', 'desc'], 'Sort order'),\n ...pageProperties,\n },\n ['query'],\n ),\n outputSchema: objectSchema(\n {pull_requests: arraySchema(openObjectSchema('GitHub pull request'))},\n ['pull_requests'],\n ),\n }),\n tool({\n id: 'create_pull_request',\n category: 'pull_requests',\n description: 'Create a new pull request in a GitHub repository.',\n sensitivity: 'write',\n sensitive: false,\n requiredScope: scopes.pullRequestsWrite,\n inputSchema: repositoryInputSchema(\n {\n title: stringSchema('PR title'),\n body: stringSchema('PR description'),\n head: stringSchema('Branch containing changes'),\n base: stringSchema('Branch to merge into'),\n draft: booleanSchema('Create as draft PR'),\n maintainer_can_modify: booleanSchema('Allow maintainer edits'),\n reviewers: arraySchema(stringSchema('GitHub username or ORG/team-slug reviewer')),\n },\n ['title', 'head', 'base'],\n ),\n outputSchema: objectSchema({pull_request: openObjectSchema('Created GitHub pull request')}, [\n 'pull_request',\n ]),\n }),\n tool({\n id: 'update_pull_request',\n category: 'pull_requests',\n description: 'Update an existing pull request in a GitHub repository.',\n sensitivity: 'write',\n sensitive: false,\n requiredScope: scopes.pullRequestsWrite,\n inputSchema: repositoryInputSchema(\n {\n pull_number: integerSchema('Pull request number to update'),\n title: stringSchema('New title'),\n body: stringSchema('New description'),\n state: enumSchema(['open', 'closed'], 'New state'),\n base: stringSchema('New base branch name'),\n maintainer_can_modify: booleanSchema('Allow maintainer edits'),\n reviewers: arraySchema(stringSchema('GitHub username or ORG/team-slug reviewer')),\n },\n ['pull_number'],\n ),\n outputSchema: objectSchema({pull_request: openObjectSchema('Updated GitHub pull request')}, [\n 'pull_request',\n ]),\n }),\n tool({\n id: 'add_reply_to_pull_request_comment',\n category: 'pull_requests',\n description:\n 'Add a reply and/or reaction to an existing pull request comment. This can create a new comment linked as a reply to the specified comment, add an emoji reaction to the specified comment, or do both. At least one of body or reaction is required.',\n sensitivity: 'write',\n sensitive: false,\n requiredScope: scopes.pullRequestsWrite,\n inputSchema: repositoryInputSchema(\n {\n pull_number: integerSchema('Pull request number. Required when body is provided'),\n comment_id: integerSchema(\n 'The numeric ID of the pull request review comment to reply or react to',\n ),\n body: stringSchema('The text of the reply'),\n reaction: enumSchema(\n ['+1', '-1', 'laugh', 'confused', 'heart', 'hooray', 'rocket', 'eyes'],\n 'Emoji reaction to add',\n ),\n },\n ['comment_id'],\n {anyOf: [{required: ['pull_number', 'body']}, {required: ['reaction']}]},\n ),\n outputSchema: openObjectSchema('Pull request comment reply or reaction result'),\n }),\n tool({\n id: 'merge_pull_request',\n category: 'pull_requests',\n description: 'Merge a pull request in a GitHub repository.',\n sensitivity: 'write',\n sensitive: true,\n requiredScope: scopes.mergePullRequest,\n inputSchema: repositoryInputSchema(\n {\n pull_number: integerSchema('Pull request number'),\n commit_title: stringSchema('Title for merge commit'),\n commit_message: stringSchema('Extra detail for merge commit'),\n merge_method: enumSchema(['merge', 'squash', 'rebase'], 'Merge method'),\n },\n ['pull_number'],\n ),\n outputSchema: objectSchema({merge: openObjectSchema('Merge result')}, ['merge']),\n }),\n tool({\n id: 'update_pull_request_branch',\n category: 'pull_requests',\n description:\n 'Update the branch of a pull request with the latest changes from the base branch.',\n sensitivity: 'write',\n sensitive: false,\n requiredScope: scopes.pullRequestsWrite,\n inputSchema: repositoryInputSchema(\n {\n pull_number: integerSchema('Pull request number'),\n expected_head_sha: stringSchema(\"The expected SHA of the pull request's HEAD ref\"),\n },\n ['pull_number'],\n ),\n outputSchema: openObjectSchema('Pull request branch update result'),\n }),\n tool({\n id: 'pull_request_review_write',\n category: 'pull_requests',\n description: 'Create and/or submit, delete review of a pull request.',\n methods: pullRequestReviewWriteMethods,\n inputSchema: repositoryInputSchema(\n {\n method: methodSchema(\n pullRequestReviewWriteMethods,\n 'The write operation to perform on pull request review',\n ),\n pull_number: integerSchema('Pull request number'),\n body: stringSchema('Review comment text'),\n event: enumSchema(['APPROVE', 'REQUEST_CHANGES', 'COMMENT'], 'Review action to perform'),\n commit_id: stringSchema('SHA of commit to review'),\n },\n ['method', 'pull_number'],\n ),\n outputSchema: openObjectSchema('Pull request review write result'),\n }),\n tool({\n id: 'add_comment_to_pending_review',\n category: 'pull_requests',\n description:\n \"Add review comment to the requester's latest pending pull request review. A pending review needs to already exist to call this.\",\n sensitivity: 'write',\n sensitive: false,\n requiredScope: scopes.pullRequestsWrite,\n inputSchema: repositoryInputSchema(\n {\n pull_number: integerSchema('Pull request number'),\n path: stringSchema('The relative path to the file that necessitates a comment'),\n body: stringSchema('The text of the review comment'),\n subject_type: enumSchema(['LINE', 'FILE'], 'The level at which the comment is targeted'),\n line: integerSchema('The line of the blob in the pull request diff'),\n side: enumSchema(['LEFT', 'RIGHT'], 'The side of the diff to comment on'),\n start_line: integerSchema('The first line of a multi-line comment range'),\n start_side: enumSchema(\n ['LEFT', 'RIGHT'],\n 'The starting side of a multi-line comment range',\n ),\n },\n ['pull_number', 'path', 'body'],\n ),\n outputSchema: openObjectSchema('Pending review comment result'),\n }),\n tool({\n id: 'actions_list',\n category: 'actions',\n description:\n 'Tools for listing GitHub Actions resources. Use this tool to list workflows in a repository, or list workflow runs, jobs, and artifacts for a specific workflow or workflow run.',\n methods: actionsListMethods,\n inputSchema: repositoryInputSchema(\n {\n method: methodSchema(actionsListMethods, 'The action to perform'),\n resource_id: stringSchema('The unique identifier of the resource'),\n workflow_runs_filter: openObjectSchema('Filters for workflow runs'),\n workflow_jobs_filter: openObjectSchema('Filters for workflow jobs'),\n ...pageProperties,\n },\n ['method'],\n ),\n outputSchema: openObjectSchema('Actions list result'),\n }),\n tool({\n id: 'actions_get',\n category: 'actions',\n description:\n 'Get details about specific GitHub Actions resources. Use this tool to get details about individual workflows, workflow runs, jobs, and artifacts by their unique IDs.',\n methods: actionsGetMethods,\n inputSchema: repositoryInputSchema(\n {\n method: methodSchema(actionsGetMethods, 'The method to execute'),\n resource_id: stringSchema('The unique identifier of the resource'),\n },\n ['method', 'resource_id'],\n ),\n outputSchema: openObjectSchema('Actions get result'),\n }),\n tool({\n id: 'actions_run_trigger',\n category: 'actions',\n description:\n 'Trigger GitHub Actions workflow operations, including running, re-running, cancelling workflow runs, and deleting workflow run logs.',\n methods: actionsRunTriggerMethods,\n inputSchema: repositoryInputSchema(\n {\n method: methodSchema(actionsRunTriggerMethods, 'The method to execute'),\n workflow_id: stringSchema(\n 'The workflow ID or workflow file name. Required for run_workflow',\n ),\n ref: stringSchema('The git reference for the workflow. Required for run_workflow'),\n inputs: openObjectSchema('Inputs the workflow accepts. Only used for run_workflow'),\n run_id: integerSchema(\n 'The ID of the workflow run. Required for all methods except run_workflow',\n ),\n },\n ['method'],\n {\n oneOf: [\n methodRequiredSchema('run_workflow', ['workflow_id', 'ref']),\n methodRequiredSchema('rerun_workflow_run', ['run_id']),\n methodRequiredSchema('rerun_failed_jobs', ['run_id']),\n methodRequiredSchema('cancel_workflow_run', ['run_id']),\n methodRequiredSchema('delete_workflow_run_logs', ['run_id']),\n ],\n },\n ),\n outputSchema: openObjectSchema('Actions run trigger result'),\n }),\n tool({\n id: 'get_job_logs',\n category: 'actions',\n description:\n 'Get logs for GitHub Actions workflow jobs. Use this tool to retrieve logs for a specific job or all failed jobs in a workflow run. For single job logs, provide job_id. For all failed jobs in a run, provide run_id with failed_only=true.',\n sensitivity: 'read',\n sensitive: false,\n requiredScope: scopes.actionsRead,\n inputSchema: repositoryInputSchema({\n job_id: numberSchema(\n 'The unique identifier of the workflow job. Required when getting logs for a single job.',\n ),\n run_id: numberSchema(\n 'The unique identifier of the workflow run. Required when failed_only is true to get logs for all failed jobs in the run.',\n ),\n failed_only: booleanSchema(\n 'When true, gets logs for all failed jobs in the workflow run specified by run_id. Requires run_id to be provided.',\n ),\n return_content: booleanSchema('Returns actual log content instead of URLs'),\n tail_lines: {\n ...numberSchema('Number of lines to return from the end of the log'),\n default: DEFAULT_JOB_LOG_TAIL_LINES,\n },\n }),\n outputSchema: openObjectSchema('GitHub Actions workflow job logs'),\n }),\n] as const satisfies readonly GithubAgentToolCatalogEntry[];\n\nexport type GithubAgentToolId = (typeof githubAgentToolCatalog)[number]['id'];\n\nexport function buildGithubAgentToolSelectionCatalog(\n catalog: readonly GithubAgentToolCatalogEntry[],\n): AgentToolSelectionCatalog {\n return {\n selectors: catalog.flatMap((entry): AgentToolSelector[] => {\n if (!entry.methods) {\n return [\n {\n token: entry.id,\n kind: 'standalone',\n sensitivity: entry.sensitivity,\n sensitive: entry.sensitive,\n },\n ];\n }\n\n return [\n {\n token: entry.id,\n kind: 'family',\n sensitivity: entry.sensitivity,\n sensitive: entry.sensitive,\n },\n {\n token: `${entry.id}.*`,\n kind: 'family_wildcard',\n sensitivity: entry.sensitivity,\n sensitive: entry.sensitive,\n },\n ...entry.methods.map((method) => ({\n token: `${entry.id}.${method.id}`,\n kind: 'method' as const,\n sensitivity: method.sensitivity,\n sensitive: method.sensitive,\n })),\n ];\n }),\n };\n}\n\nexport const githubAgentToolSelectionCatalog =\n buildGithubAgentToolSelectionCatalog(githubAgentToolCatalog);\n\nfunction tool(input: GithubAgentToolCatalogInput): GithubAgentToolCatalogEntry {\n if (!input.methods) {\n if (!input.sensitivity || input.sensitive === undefined || !input.requiredScope) {\n throw new Error(`GitHub agent tool ${input.id} is missing sensitivity or required scope`);\n }\n return {\n id: input.id,\n category: input.category,\n description: input.description,\n sensitivity: input.sensitivity,\n sensitive: input.sensitive,\n requiredScope: input.requiredScope,\n inputSchema: input.inputSchema,\n outputSchema: input.outputSchema,\n };\n }\n\n return {\n id: input.id,\n category: input.category,\n description: input.description,\n sensitivity: input.methods.some((candidate) => candidate.sensitivity === 'write')\n ? 'write'\n : 'read',\n sensitive: input.methods.some((candidate) => candidate.sensitive),\n requiredScope: unionRequiredScopes(input.methods),\n inputSchema: input.inputSchema,\n outputSchema: input.outputSchema,\n methods: input.methods,\n };\n}\n\nfunction method(\n id: string,\n description: string,\n sensitivity: GithubAgentToolSensitivity,\n sensitive: boolean,\n requiredScope: GithubAgentToolRequiredScope,\n): GithubAgentToolCatalogMethod {\n return {id, description, sensitivity, sensitive, requiredScope};\n}\n\nfunction unionRequiredScopes(\n methods: readonly GithubAgentToolCatalogMethod[],\n): GithubAgentToolRequiredScope {\n const byPermission = new Map<GithubAgentToolPermission, GithubAgentToolPermissionAccess>();\n\n for (const {requiredScope} of methods) {\n for (const {permission, access} of requiredScope) {\n if (byPermission.get(permission) === 'write') continue;\n byPermission.set(permission, access);\n }\n }\n\n return [...byPermission.entries()].map(([permission, access]) => ({permission, access}));\n}\n\nfunction repositoryInputSchema(\n properties: Record<string, AgentToolJsonSchema> = {},\n required: string[] = [],\n extraSchema: Partial<AgentToolJsonSchema> = {},\n): AgentToolJsonSchema {\n return objectSchema(\n {...repositoryProperties, ...properties},\n ['owner', 'repo', ...required],\n extraSchema,\n );\n}\n\nfunction objectSchema(\n properties: Record<string, AgentToolJsonSchema>,\n required: string[] = [],\n extraSchema: Partial<AgentToolJsonSchema> = {},\n): AgentToolJsonSchema {\n return {\n type: 'object',\n additionalProperties: false,\n properties,\n ...(required.length > 0 ? {required} : {}),\n ...extraSchema,\n };\n}\n\nfunction methodRequiredSchema(methodId: string, required: string[]): AgentToolJsonSchema {\n return {\n properties: {\n method: {const: methodId},\n },\n required,\n };\n}\n\nfunction openObjectSchema(description: string): AgentToolJsonSchema {\n return {type: 'object', description, additionalProperties: true};\n}\n\nfunction stringSchema(description?: string): AgentToolJsonSchema {\n return {type: 'string', ...(description ? {description} : {})};\n}\n\nfunction integerSchema(\n description?: string,\n options: {minimum?: number | undefined; maximum?: number | undefined} = {},\n): AgentToolJsonSchema {\n return {type: 'integer', ...(description ? {description} : {}), ...options};\n}\n\nfunction numberSchema(description?: string): AgentToolJsonSchema {\n return {type: 'number', ...(description ? {description} : {})};\n}\n\nfunction booleanSchema(description: string): AgentToolJsonSchema {\n return {type: 'boolean', description};\n}\n\nfunction enumSchema(values: string[], description: string): AgentToolJsonSchema {\n return {type: 'string', description, enum: values};\n}\n\nfunction methodSchema(\n methods: readonly GithubAgentToolCatalogMethod[],\n description: string,\n): AgentToolJsonSchema {\n return enumSchema(\n methods.map((candidate) => candidate.id),\n description,\n );\n}\n\nfunction arraySchema(items: AgentToolJsonSchema): AgentToolJsonSchema {\n return {type: 'array', items};\n}\n"],"names":["DEFAULT_JOB_LOG_TAIL_LINES","scopes","issuesRead","permission","access","issuesWrite","pullRequestsRead","pullRequestsWrite","actionsRead","actionsWrite","mergePullRequest","repositoryProperties","owner","stringSchema","repo","pageProperties","page","integerSchema","minimum","per_page","maximum","issueReadMethods","method","issueWriteMethods","subIssueWriteMethods","pullRequestReadMethods","pullRequestReviewWriteMethods","actionsListMethods","actionsGetMethods","actionsRunTriggerMethods","githubAgentToolCatalog","tool","id","category","description","methods","inputSchema","repositoryInputSchema","methodSchema","issue_number","outputSchema","openObjectSchema","sensitivity","sensitive","requiredScope","objectSchema","issue_types","arraySchema","state","enumSchema","labels","orderBy","direction","since","after","first","issues","query","sort","order","comment_id","body","reaction","anyOf","required","title","assignees","milestone","issue_type","state_reason","duplicate_of","sub_issue_id","replace_parent","booleanSchema","after_id","before_id","pull_number","ref","cursor","oneOf","methodRequiredSchema","head","base","pull_requests","draft","maintainer_can_modify","reviewers","pull_request","commit_title","commit_message","merge_method","merge","expected_head_sha","event","commit_id","path","subject_type","line","side","start_line","start_side","resource_id","workflow_runs_filter","workflow_jobs_filter","workflow_id","inputs","run_id","job_id","numberSchema","failed_only","return_content","tail_lines","default","buildGithubAgentToolSelectionCatalog","catalog","selectors","flatMap","entry","token","kind","map","githubAgentToolSelectionCatalog","input","undefined","Error","some","candidate","unionRequiredScopes","byPermission","Map","get","set","entries","properties","extraSchema","type","additionalProperties","length","methodId","const","options","values","enum","items"],"mappings":"AAiCA,OAAO,MAAMA,6BAA6B,IAAI;AAkC9C,MAAMC,SAAS;IACbC,YAAY;QAAC;YAACC,YAAY;YAAUC,QAAQ;QAAM;KAAE;IACpDC,aAAa;QAAC;YAACF,YAAY;YAAUC,QAAQ;QAAO;KAAE;IACtDE,kBAAkB;QAAC;YAACH,YAAY;YAAiBC,QAAQ;QAAM;KAAE;IACjEG,mBAAmB;QAAC;YAACJ,YAAY;YAAiBC,QAAQ;QAAO;KAAE;IACnEI,aAAa;QAAC;YAACL,YAAY;YAAWC,QAAQ;QAAM;KAAE;IACtDK,cAAc;QAAC;YAACN,YAAY;YAAWC,QAAQ;QAAO;KAAE;IACxDM,kBAAkB;QAChB;YAACP,YAAY;YAAiBC,QAAQ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AI;AACjE;AAEA,SAAS3H,aAAaqB,WAAoB;IACxC,OAAO;QAACqG,MAAM;QAAU,GAAIrG,cAAc;YAACA;QAAW,IAAI,CAAC,CAAC;IAAC;AAC/D;AAEA,SAASjB,cACPiB,WAAoB,EACpB0G,UAAwE,CAAC,CAAC;IAE1E,OAAO;QAACL,MAAM;QAAW,GAAIrG,cAAc;YAACA;QAAW,IAAI,CAAC,CAAC;QAAG,GAAG0G,OAAO;IAAA;AAC5E;AAEA,SAAShC,aAAa1E,WAAoB;IACxC,OAAO;QAACqG,MAAM;QAAU,GAAIrG,cAAc;YAACA;QAAW,IAAI,CAAC,CAAC;IAAC;AAC/D;AAEA,SAASuC,cAAcvC,WAAmB;IACxC,OAAO;QAACqG,MAAM;QAAWrG;IAAW;AACtC;AAEA,SAASe,WAAW4F,MAAgB,EAAE3G,WAAmB;IACvD,OAAO;QAACqG,MAAM;QAAUrG;QAAa4G,MAAMD;IAAM;AACnD;AAEA,SAASvG,aACPH,OAAgD,EAChDD,WAAmB;IAEnB,OAAOe,WACLd,QAAQqF,GAAG,CAAC,CAACM,YAAcA,UAAU9F,EAAE,GACvCE;AAEJ;AAEA,SAASa,YAAYgG,KAA0B;IAC7C,OAAO;QAACR,MAAM;QAASQ;IAAK;AAC9B"}
|
package/dist/core/install.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { UserContextMembership } from '@shipfox/api-auth-context';
|
|
2
|
-
import type { IntegrationConnection } from '@shipfox/api-integration-
|
|
2
|
+
import type { IntegrationConnection } from '@shipfox/api-integration-spi';
|
|
3
3
|
import type { GithubApiClient } from '#api/client.js';
|
|
4
4
|
export interface ConnectGithubInstallationInput {
|
|
5
5
|
workspaceId: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"install.d.ts","sourceRoot":"","sources":["../../src/core/install.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,qBAAqB,EAAC,MAAM,2BAA2B,CAAC;AACrE,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nC,cAAc,EAAE,MAAM,CAAC;KACxB,KAAK,OAAO,CAAC,qBAAqB,CAAC,QAAQ,CAAC,GAAG,SAAS,CAAC,CAAC;IAC3D,yBAAyB,EAAE,CACzB,KAAK,EAAE,8BAA8B,KAClC,OAAO,CAAC,qBAAqB,CAAC,QAAQ,CAAC,CAAC,CAAC;CAC/C;AAED,wBAAsB,oBAAoB,CACxC,MAAM,EAAE,0BAA0B,GACjC,OAAO,CAAC,qBAAqB,CAAC,QAAQ,CAAC,CAAC,CAoC1C"}
|
package/dist/core/install.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/core/install.ts"],"sourcesContent":["import type {UserContextMembership} from '@shipfox/api-auth-context';\nimport type {IntegrationConnection} from '@shipfox/api-integration-
|
|
1
|
+
{"version":3,"sources":["../../src/core/install.ts"],"sourcesContent":["import type {UserContextMembership} from '@shipfox/api-auth-context';\nimport type {IntegrationConnection} from '@shipfox/api-integration-spi';\nimport type {GithubApiClient, GithubInstallationDetails} from '#api/client.js';\nimport {\n GithubInstallationAlreadyLinkedError,\n GithubInstallationNotAuthorizedError,\n GithubInstallStateActorMismatchError,\n} from './errors.js';\nimport {verifyGithubInstallState} from './state.js';\n\nexport interface ConnectGithubInstallationInput {\n workspaceId: string;\n installationId: string;\n displayName: string;\n installerUserId: string;\n installation: {\n installationId: string;\n accountLogin: string;\n accountType: string;\n repositorySelection: string;\n suspendedAt: Date | null;\n deletedAt: Date | null;\n latestEvent: Record<string, unknown>;\n installerUserId: string;\n };\n}\n\nexport interface HandleGithubCallbackParams {\n github: GithubApiClient;\n code: string;\n installationId: number;\n state: string;\n sessionUserId: string;\n sessionMemberships: ReadonlyArray<UserContextMembership>;\n requireWorkspaceMembership: (params: {\n workspaceId: string;\n userId: string;\n memberships: ReadonlyArray<UserContextMembership>;\n }) => Promise<unknown>;\n getExistingGithubConnection: (input: {\n installationId: string;\n }) => Promise<IntegrationConnection<'github'> | undefined>;\n connectGithubInstallation: (\n input: ConnectGithubInstallationInput,\n ) => Promise<IntegrationConnection<'github'>>;\n}\n\nexport async function handleGithubCallback(\n params: HandleGithubCallbackParams,\n): Promise<IntegrationConnection<'github'>> {\n const claims = verifyGithubInstallState(params.state);\n if (claims.userId !== params.sessionUserId) {\n throw new GithubInstallStateActorMismatchError();\n }\n await params.requireWorkspaceMembership({\n workspaceId: claims.workspaceId,\n userId: claims.userId,\n memberships: params.sessionMemberships,\n });\n\n const installationIdStr = String(params.installationId);\n const existing = await params.getExistingGithubConnection({installationId: installationIdStr});\n if (existing && existing.workspaceId !== claims.workspaceId) {\n throw new GithubInstallationAlreadyLinkedError(params.installationId);\n }\n if (existing && existing.lifecycleStatus === 'active') {\n return existing;\n }\n\n const userAccessToken = await params.github.exchangeOAuthCode(params.code);\n const accessible = await userCanAccessInstallation({\n github: params.github,\n userAccessToken,\n installationId: params.installationId,\n });\n if (!accessible) throw new GithubInstallationNotAuthorizedError(params.installationId);\n\n const installation = await params.github.getInstallation(params.installationId);\n return await params.connectGithubInstallation({\n workspaceId: claims.workspaceId,\n installationId: installationIdStr,\n displayName: `GitHub ${installation.account.login}`,\n installerUserId: claims.userId,\n installation: toConnectionInstallationInput(installation, claims.userId),\n });\n}\n\nasync function userCanAccessInstallation(params: {\n github: GithubApiClient;\n userAccessToken: string;\n installationId: number;\n}): Promise<boolean> {\n let cursor: string | undefined;\n do {\n const page = await params.github.listUserInstallations({\n userAccessToken: params.userAccessToken,\n cursor,\n });\n if (page.installationIds.includes(params.installationId)) return true;\n cursor = page.nextCursor ?? undefined;\n } while (cursor);\n return false;\n}\n\nfunction toConnectionInstallationInput(\n installation: GithubInstallationDetails,\n installerUserId: string,\n) {\n return {\n installationId: String(installation.id),\n accountLogin: installation.account.login,\n accountType: installation.account.type,\n repositorySelection: installation.repositorySelection,\n suspendedAt: installation.suspendedAt,\n deletedAt: null,\n latestEvent: installation.raw,\n installerUserId,\n };\n}\n"],"names":["GithubInstallationAlreadyLinkedError","GithubInstallationNotAuthorizedError","GithubInstallStateActorMismatchError","verifyGithubInstallState","handleGithubCallback","params","claims","state","userId","sessionUserId","requireWorkspaceMembership","workspaceId","memberships","sessionMemberships","installationIdStr","String","installationId","existing","getExistingGithubConnection","lifecycleStatus","userAccessToken","github","exchangeOAuthCode","code","accessible","userCanAccessInstallation","installation","getInstallation","connectGithubInstallation","displayName","account","login","installerUserId","toConnectionInstallationInput","cursor","page","listUserInstallations","installationIds","includes","nextCursor","undefined","id","accountLogin","accountType","type","repositorySelection","suspendedAt","deletedAt","latestEvent","raw"],"mappings":"AAGA,SACEA,oCAAoC,EACpCC,oCAAoC,EACpCC,oCAAoC,QAC/B,cAAc;AACrB,SAAQC,wBAAwB,QAAO,aAAa;AAuCpD,OAAO,eAAeC,qBACpBC,MAAkC;IAElC,MAAMC,SAASH,yBAAyBE,OAAOE,KAAK;IACpD,IAAID,OAAOE,MAAM,KAAKH,OAAOI,aAAa,EAAE;QAC1C,MAAM,IAAIP;IACZ;IACA,MAAMG,OAAOK,0BAA0B,CAAC;QACtCC,aAAaL,OAAOK,WAAW;QAC/BH,QAAQF,OAAOE,MAAM;QACrBI,aAAaP,OAAOQ,kBAAkB;IACxC;IAEA,MAAMC,oBAAoBC,OAAOV,OAAOW,cAAc;IACtD,MAAMC,WAAW,MAAMZ,OAAOa,2BAA2B,CAAC;QAACF,gBAAgBF;IAAiB;IAC5F,IAAIG,YAAYA,SAASN,WAAW,KAAKL,OAAOK,WAAW,EAAE;QAC3D,MAAM,IAAIX,qCAAqCK,OAAOW,cAAc;IACtE;IACA,IAAIC,YAAYA,SAASE,eAAe,KAAK,UAAU;QACrD,OAAOF;IACT;IAEA,MAAMG,kBAAkB,MAAMf,OAAOgB,MAAM,CAACC,iBAAiB,CAACjB,OAAOkB,IAAI;IACzE,MAAMC,aAAa,MAAMC,0BAA0B;QACjDJ,QAAQhB,OAAOgB,MAAM;QACrBD;QACAJ,gBAAgBX,OAAOW,cAAc;IACvC;IACA,IAAI,CAACQ,YAAY,MAAM,IAAIvB,qCAAqCI,OAAOW,cAAc;IAErF,MAAMU,eAAe,MAAMrB,OAAOgB,MAAM,CAACM,eAAe,CAACtB,OAAOW,cAAc;IAC9E,OAAO,MAAMX,OAAOuB,yBAAyB,CAAC;QAC5CjB,aAAaL,OAAOK,WAAW;QAC/BK,gBAAgBF;QAChBe,aAAa,CAAC,OAAO,EAAEH,aAAaI,OAAO,CAACC,KAAK,EAAE;QACnDC,iBAAiB1B,OAAOE,MAAM;QAC9BkB,cAAcO,8BAA8BP,cAAcpB,OAAOE,MAAM;IACzE;AACF;AAEA,eAAeiB,0BAA0BpB,MAIxC;IACC,IAAI6B;IACJ,GAAG;QACD,MAAMC,OAAO,MAAM9B,OAAOgB,MAAM,CAACe,qBAAqB,CAAC;YACrDhB,iBAAiBf,OAAOe,eAAe;YACvCc;QACF;QACA,IAAIC,KAAKE,eAAe,CAACC,QAAQ,CAACjC,OAAOW,cAAc,GAAG,OAAO;QACjEkB,SAASC,KAAKI,UAAU,IAAIC;IAC9B,QAASN,OAAQ;IACjB,OAAO;AACT;AAEA,SAASD,8BACPP,YAAuC,EACvCM,eAAuB;IAEvB,OAAO;QACLhB,gBAAgBD,OAAOW,aAAae,EAAE;QACtCC,cAAchB,aAAaI,OAAO,CAACC,KAAK;QACxCY,aAAajB,aAAaI,OAAO,CAACc,IAAI;QACtCC,qBAAqBnB,aAAamB,mBAAmB;QACrDC,aAAapB,aAAaoB,WAAW;QACrCC,WAAW;QACXC,aAAatB,aAAauB,GAAG;QAC7BjB;IACF;AACF"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type CheckoutSpec, type CreateCheckoutSpecInput, type FetchFileInput, type FilePage, type FileSnapshot, type IntegrationConnection, type ListFilesInput, type ListRepositoriesInput, type RepositoryPage, type RepositorySnapshot, type ResolveRepositoryInput, type SourceControlProvider } from '@shipfox/api-integration-
|
|
1
|
+
import { type CheckoutSpec, type CreateCheckoutSpecInput, type FetchFileInput, type FilePage, type FileSnapshot, type IntegrationConnection, type ListFilesInput, type ListRepositoriesInput, type RepositoryPage, type RepositorySnapshot, type ResolveRepositoryInput, type SourceControlProvider } from '@shipfox/api-integration-spi';
|
|
2
2
|
import type { GithubApiClient } from '#api/client.js';
|
|
3
3
|
type GithubIntegrationConnection = IntegrationConnection<'github'>;
|
|
4
4
|
export declare class GithubSourceControlProvider implements SourceControlProvider<GithubIntegrationConnection> {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"source-control.d.ts","sourceRoot":"","sources":["../../src/core/source-control.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,YAAY,EACjB,KAAK,uBAAuB,EAC5B,KAAK,cAAc,EACnB,KAAK,QAAQ,EACb,KAAK,YAAY,EACjB,KAAK,qBAAqB,EAC1B,KAAK,cAAc,EACnB,KAAK,qBAAqB,EAG1B,KAAK,cAAc,EACnB,KAAK,kBAAkB,EAEvB,KAAK,sBAAsB,EAC3B,KAAK,qBAAqB,EAC3B,MAAM,
|
|
1
|
+
{"version":3,"file":"source-control.d.ts","sourceRoot":"","sources":["../../src/core/source-control.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,YAAY,EACjB,KAAK,uBAAuB,EAC5B,KAAK,cAAc,EACnB,KAAK,QAAQ,EACb,KAAK,YAAY,EACjB,KAAK,qBAAqB,EAC1B,KAAK,cAAc,EACnB,KAAK,qBAAqB,EAG1B,KAAK,cAAc,EACnB,KAAK,kBAAkB,EAEvB,KAAK,sBAAsB,EAC3B,KAAK,qBAAqB,EAC3B,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EAAC,eAAe,EAAmB,MAAM,gBAAgB,CAAC;AAKtE,KAAK,2BAA2B,GAAG,qBAAqB,CAAC,QAAQ,CAAC,CAAC;AAOnE,qBAAa,2BACX,YAAW,qBAAqB,CAAC,2BAA2B,CAAC;IAEjD,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAN,MAAM,EAAE,eAAe;IAE9C,gBAAgB,CACpB,KAAK,EAAE,qBAAqB,CAAC,2BAA2B,CAAC,GACxD,OAAO,CAAC,cAAc,CAAC;IAiDpB,iBAAiB,CACrB,KAAK,EAAE,sBAAsB,CAAC,2BAA2B,CAAC,GACzD,OAAO,CAAC,kBAAkB,CAAC;IAWxB,SAAS,CAAC,KAAK,EAAE,cAAc,CAAC,2BAA2B,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC;IAkBhF,SAAS,CAAC,KAAK,EAAE,cAAc,CAAC,2BAA2B,CAAC,GAAG,OAAO,CAAC,YAAY,CAAC;IA2BpF,kBAAkB,CACtB,KAAK,EAAE,uBAAuB,CAAC,2BAA2B,CAAC,GAC1D,OAAO,CAAC,YAAY,CAAC;YAoBV,cAAc;CAW7B"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Buffer } from 'node:buffer';
|
|
2
|
-
import { buildProviderRepositoryId, MAX_REPOSITORY_FILE_BYTES, parseProviderRepositoryId } from '@shipfox/api-integration-
|
|
2
|
+
import { buildProviderRepositoryId, MAX_REPOSITORY_FILE_BYTES, parseProviderRepositoryId } from '@shipfox/api-integration-spi';
|
|
3
3
|
import { config } from '#config.js';
|
|
4
4
|
import { getGithubInstallationByConnectionId } from '#db/installations.js';
|
|
5
5
|
import { GithubIntegrationProviderError } from './errors.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/core/source-control.ts"],"sourcesContent":["import {Buffer} from 'node:buffer';\nimport {\n buildProviderRepositoryId,\n type CheckoutSpec,\n type CreateCheckoutSpecInput,\n type FetchFileInput,\n type FilePage,\n type FileSnapshot,\n type IntegrationConnection,\n type ListFilesInput,\n type ListRepositoriesInput,\n MAX_REPOSITORY_FILE_BYTES,\n parseProviderRepositoryId,\n type RepositoryPage,\n type RepositorySnapshot,\n type RepositoryVisibility,\n type ResolveRepositoryInput,\n type SourceControlProvider,\n} from '@shipfox/api-integration-core-dto';\nimport type {GithubApiClient, GithubRepository} from '#api/client.js';\nimport {config} from '#config.js';\nimport {getGithubInstallationByConnectionId} from '#db/installations.js';\nimport {GithubIntegrationProviderError} from './errors.js';\n\ntype GithubIntegrationConnection = IntegrationConnection<'github'>;\n\nconst GITHUB_PROVIDER = 'github';\nconst GITHUB_APP_BOT_SUFFIX = '[bot]';\nconst SEARCH_PAGE_SIZE = 100;\nconst SEARCH_MAX_PAGES_PER_REQUEST = 5;\n\nexport class GithubSourceControlProvider\n implements SourceControlProvider<GithubIntegrationConnection>\n{\n constructor(private readonly github: GithubApiClient) {}\n\n async listRepositories(\n input: ListRepositoriesInput<GithubIntegrationConnection>,\n ): Promise<RepositoryPage> {\n const installation = await getGithubInstallationByConnectionId(input.connection.id);\n if (!installation) {\n throw new GithubIntegrationProviderError(\n 'access-denied',\n 'GitHub installation details were not found for the connection',\n );\n }\n\n const installationId = Number.parseInt(installation.installationId, 10);\n const needle = input.search?.trim().toLowerCase();\n\n if (!needle) {\n const page = await this.github.listInstallationRepositories({\n installationId,\n limit: input.limit,\n cursor: input.cursor,\n });\n return {\n repositories: page.repositories.map(toRepositorySnapshot),\n nextCursor: page.nextCursor,\n };\n }\n\n const matches: RepositorySnapshot[] = [];\n let cursor = input.cursor;\n let pagesScanned = 0;\n while (matches.length < input.limit && pagesScanned < SEARCH_MAX_PAGES_PER_REQUEST) {\n const page = await this.github.listInstallationRepositories({\n installationId,\n limit: SEARCH_PAGE_SIZE,\n cursor,\n });\n pagesScanned += 1;\n for (const repo of page.repositories) {\n if (repo.fullName.toLowerCase().includes(needle)) {\n matches.push(toRepositorySnapshot(repo));\n }\n }\n cursor = page.nextCursor ?? undefined;\n if (!cursor) break;\n }\n\n return {\n repositories: matches.slice(0, input.limit),\n nextCursor: cursor ?? null,\n };\n }\n\n async resolveRepository(\n input: ResolveRepositoryInput<GithubIntegrationConnection>,\n ): Promise<RepositorySnapshot> {\n const installationId = await this.installationId(input.connection.id);\n const {repositoryId} = parseGithubRepositoryLocator(input.externalRepositoryId);\n const repository = await this.github.getRepository({\n installationId,\n repositoryId,\n });\n\n return toRepositorySnapshot(repository);\n }\n\n async listFiles(input: ListFilesInput<GithubIntegrationConnection>): Promise<FilePage> {\n const installationId = await this.installationId(input.connection.id);\n const {repositoryId} = parseGithubRepositoryLocator(input.externalRepositoryId);\n const page = await this.github.listRepositoryFiles({\n installationId,\n repositoryId,\n ref: input.ref,\n prefix: input.prefix,\n limit: input.limit,\n cursor: input.cursor,\n });\n\n return {\n files: page.files.map((file) => ({path: file.path, type: 'file', size: file.size})),\n nextCursor: page.nextCursor,\n };\n }\n\n async fetchFile(input: FetchFileInput<GithubIntegrationConnection>): Promise<FileSnapshot> {\n const installationId = await this.installationId(input.connection.id);\n const {repositoryId} = parseGithubRepositoryLocator(input.externalRepositoryId);\n const file = await this.github.fetchRepositoryFile({\n installationId,\n repositoryId,\n ref: input.ref,\n path: input.path,\n });\n\n if (\n file.size > MAX_REPOSITORY_FILE_BYTES ||\n Buffer.byteLength(file.content, 'utf8') > MAX_REPOSITORY_FILE_BYTES\n ) {\n throw new GithubIntegrationProviderError(\n 'content-too-large',\n 'GitHub file content is larger than the supported limit',\n );\n }\n\n return {\n path: file.path,\n ref: input.ref,\n content: file.content,\n };\n }\n\n async createCheckoutSpec(\n input: CreateCheckoutSpecInput<GithubIntegrationConnection>,\n ): Promise<CheckoutSpec> {\n const installationId = await this.installationId(input.connection.id);\n const {repositoryId} = parseGithubRepositoryLocator(input.externalRepositoryId);\n const repository = await this.github.getRepository({installationId, repositoryId});\n const ref = input.ref?.trim() || repository.defaultBranch;\n const {token, expiresAt} = await this.github.createInstallationAccessToken({\n installationId,\n repositoryId,\n permissions: input.permissions,\n });\n const gitAuthor = githubAppGitAuthor();\n\n return {\n repositoryUrl: repository.cloneUrl,\n ref,\n credentials: {username: 'x-access-token', token, expiresAt},\n ...(gitAuthor ? {gitAuthor} : {}),\n };\n }\n\n private async installationId(connectionId: string): Promise<number> {\n const installation = await getGithubInstallationByConnectionId(connectionId);\n if (!installation) {\n throw new GithubIntegrationProviderError(\n 'access-denied',\n 'GitHub installation details were not found for the connection',\n );\n }\n\n return Number.parseInt(installation.installationId, 10);\n }\n}\n\nfunction githubAppGitAuthor(): CheckoutSpec['gitAuthor'] {\n const appUsername = config.GITHUB_APP_USERNAME?.trim();\n if (!appUsername) return undefined;\n const name = appUsername.endsWith(GITHUB_APP_BOT_SUFFIX)\n ? appUsername\n : `${appUsername}${GITHUB_APP_BOT_SUFFIX}`;\n return {name, email: `${config.GITHUB_APP_ID}+${name}@users.noreply.github.com`};\n}\n\nfunction toRepositorySnapshot(repository: GithubRepository): RepositorySnapshot {\n return {\n externalRepositoryId: buildProviderRepositoryId(GITHUB_PROVIDER, String(repository.id)),\n owner: repository.ownerLogin,\n name: repository.name,\n fullName: repository.fullName,\n defaultBranch: repository.defaultBranch,\n visibility: toRepositoryVisibility(repository),\n cloneUrl: repository.cloneUrl,\n htmlUrl: repository.htmlUrl,\n };\n}\n\nfunction parseGithubRepositoryLocator(externalRepositoryId: string): {\n repositoryId: number;\n} {\n const value = parseProviderRepositoryId(externalRepositoryId, GITHUB_PROVIDER);\n const repositoryId = Number.parseInt(value, 10);\n if (!Number.isInteger(repositoryId) || repositoryId <= 0 || String(repositoryId) !== value) {\n throw new GithubIntegrationProviderError(\n 'repository-not-found',\n `GitHub repository id ${externalRepositoryId} must follow the form ${GITHUB_PROVIDER}:<numeric-id>`,\n );\n }\n\n return {repositoryId};\n}\n\nfunction toRepositoryVisibility(repository: GithubRepository): RepositoryVisibility {\n if (repository.visibility === 'public') return 'public';\n if (repository.visibility === 'private') return 'private';\n if (repository.visibility === 'internal') return 'internal';\n return repository.private ? 'private' : 'public';\n}\n"],"names":["Buffer","buildProviderRepositoryId","MAX_REPOSITORY_FILE_BYTES","parseProviderRepositoryId","config","getGithubInstallationByConnectionId","GithubIntegrationProviderError","GITHUB_PROVIDER","GITHUB_APP_BOT_SUFFIX","SEARCH_PAGE_SIZE","SEARCH_MAX_PAGES_PER_REQUEST","GithubSourceControlProvider","github","listRepositories","input","installation","connection","id","installationId","Number","parseInt","needle","search","trim","toLowerCase","page","listInstallationRepositories","limit","cursor","repositories","map","toRepositorySnapshot","nextCursor","matches","pagesScanned","length","repo","fullName","includes","push","undefined","slice","resolveRepository","repositoryId","parseGithubRepositoryLocator","externalRepositoryId","repository","getRepository","listFiles","listRepositoryFiles","ref","prefix","files","file","path","type","size","fetchFile","fetchRepositoryFile","byteLength","content","createCheckoutSpec","defaultBranch","token","expiresAt","createInstallationAccessToken","permissions","gitAuthor","githubAppGitAuthor","repositoryUrl","cloneUrl","credentials","username","connectionId","appUsername","GITHUB_APP_USERNAME","name","endsWith","email","GITHUB_APP_ID","String","owner","ownerLogin","visibility","toRepositoryVisibility","htmlUrl","value","isInteger","private"],"mappings":"AAAA,SAAQA,MAAM,QAAO,cAAc;AACnC,SACEC,yBAAyB,EASzBC,yBAAyB,EACzBC,yBAAyB,QAMpB,oCAAoC;AAE3C,SAAQC,MAAM,QAAO,aAAa;AAClC,SAAQC,mCAAmC,QAAO,uBAAuB;AACzE,SAAQC,8BAA8B,QAAO,cAAc;AAI3D,MAAMC,kBAAkB;AACxB,MAAMC,wBAAwB;AAC9B,MAAMC,mBAAmB;AACzB,MAAMC,+BAA+B;AAErC,OAAO,MAAMC;IAGX,YAAY,AAAiBC,MAAuB,CAAE;aAAzBA,SAAAA;IAA0B;IAEvD,MAAMC,iBACJC,KAAyD,EAChC;QACzB,MAAMC,eAAe,MAAMV,oCAAoCS,MAAME,UAAU,CAACC,EAAE;QAClF,IAAI,CAACF,cAAc;YACjB,MAAM,IAAIT,+BACR,iBACA;QAEJ;QAEA,MAAMY,iBAAiBC,OAAOC,QAAQ,CAACL,aAAaG,cAAc,EAAE;QACpE,MAAMG,SAASP,MAAMQ,MAAM,EAAEC,OAAOC;QAEpC,IAAI,CAACH,QAAQ;YACX,MAAMI,OAAO,MAAM,IAAI,CAACb,MAAM,CAACc,4BAA4B,CAAC;gBAC1DR;gBACAS,OAAOb,MAAMa,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4B;IAGhE,MAAMyC,QAAQnF,0BAA0B0C,sBAAsBtC;IAC9D,MAAMoC,eAAexB,OAAOC,QAAQ,CAACkE,OAAO;IAC5C,IAAI,CAACnE,OAAOoE,SAAS,CAAC5C,iBAAiBA,gBAAgB,KAAKqC,OAAOrC,kBAAkB2C,OAAO;QAC1F,MAAM,IAAIhF,+BACR,wBACA,CAAC,qBAAqB,EAAEuC,qBAAqB,sBAAsB,EAAEtC,gBAAgB,aAAa,CAAC;IAEvG;IAEA,OAAO;QAACoC;IAAY;AACtB;AAEA,SAASyC,uBAAuBtC,UAA4B;IAC1D,IAAIA,WAAWqC,UAAU,KAAK,UAAU,OAAO;IAC/C,IAAIrC,WAAWqC,UAAU,KAAK,WAAW,OAAO;IAChD,IAAIrC,WAAWqC,UAAU,KAAK,YAAY,OAAO;IACjD,OAAOrC,WAAW0C,OAAO,GAAG,YAAY;AAC1C"}
|
|
1
|
+
{"version":3,"sources":["../../src/core/source-control.ts"],"sourcesContent":["import {Buffer} from 'node:buffer';\nimport {\n buildProviderRepositoryId,\n type CheckoutSpec,\n type CreateCheckoutSpecInput,\n type FetchFileInput,\n type FilePage,\n type FileSnapshot,\n type IntegrationConnection,\n type ListFilesInput,\n type ListRepositoriesInput,\n MAX_REPOSITORY_FILE_BYTES,\n parseProviderRepositoryId,\n type RepositoryPage,\n type RepositorySnapshot,\n type RepositoryVisibility,\n type ResolveRepositoryInput,\n type SourceControlProvider,\n} from '@shipfox/api-integration-spi';\nimport type {GithubApiClient, GithubRepository} from '#api/client.js';\nimport {config} from '#config.js';\nimport {getGithubInstallationByConnectionId} from '#db/installations.js';\nimport {GithubIntegrationProviderError} from './errors.js';\n\ntype GithubIntegrationConnection = IntegrationConnection<'github'>;\n\nconst GITHUB_PROVIDER = 'github';\nconst GITHUB_APP_BOT_SUFFIX = '[bot]';\nconst SEARCH_PAGE_SIZE = 100;\nconst SEARCH_MAX_PAGES_PER_REQUEST = 5;\n\nexport class GithubSourceControlProvider\n implements SourceControlProvider<GithubIntegrationConnection>\n{\n constructor(private readonly github: GithubApiClient) {}\n\n async listRepositories(\n input: ListRepositoriesInput<GithubIntegrationConnection>,\n ): Promise<RepositoryPage> {\n const installation = await getGithubInstallationByConnectionId(input.connection.id);\n if (!installation) {\n throw new GithubIntegrationProviderError(\n 'access-denied',\n 'GitHub installation details were not found for the connection',\n );\n }\n\n const installationId = Number.parseInt(installation.installationId, 10);\n const needle = input.search?.trim().toLowerCase();\n\n if (!needle) {\n const page = await this.github.listInstallationRepositories({\n installationId,\n limit: input.limit,\n cursor: input.cursor,\n });\n return {\n repositories: page.repositories.map(toRepositorySnapshot),\n nextCursor: page.nextCursor,\n };\n }\n\n const matches: RepositorySnapshot[] = [];\n let cursor = input.cursor;\n let pagesScanned = 0;\n while (matches.length < input.limit && pagesScanned < SEARCH_MAX_PAGES_PER_REQUEST) {\n const page = await this.github.listInstallationRepositories({\n installationId,\n limit: SEARCH_PAGE_SIZE,\n cursor,\n });\n pagesScanned += 1;\n for (const repo of page.repositories) {\n if (repo.fullName.toLowerCase().includes(needle)) {\n matches.push(toRepositorySnapshot(repo));\n }\n }\n cursor = page.nextCursor ?? undefined;\n if (!cursor) break;\n }\n\n return {\n repositories: matches.slice(0, input.limit),\n nextCursor: cursor ?? null,\n };\n }\n\n async resolveRepository(\n input: ResolveRepositoryInput<GithubIntegrationConnection>,\n ): Promise<RepositorySnapshot> {\n const installationId = await this.installationId(input.connection.id);\n const {repositoryId} = parseGithubRepositoryLocator(input.externalRepositoryId);\n const repository = await this.github.getRepository({\n installationId,\n repositoryId,\n });\n\n return toRepositorySnapshot(repository);\n }\n\n async listFiles(input: ListFilesInput<GithubIntegrationConnection>): Promise<FilePage> {\n const installationId = await this.installationId(input.connection.id);\n const {repositoryId} = parseGithubRepositoryLocator(input.externalRepositoryId);\n const page = await this.github.listRepositoryFiles({\n installationId,\n repositoryId,\n ref: input.ref,\n prefix: input.prefix,\n limit: input.limit,\n cursor: input.cursor,\n });\n\n return {\n files: page.files.map((file) => ({path: file.path, type: 'file', size: file.size})),\n nextCursor: page.nextCursor,\n };\n }\n\n async fetchFile(input: FetchFileInput<GithubIntegrationConnection>): Promise<FileSnapshot> {\n const installationId = await this.installationId(input.connection.id);\n const {repositoryId} = parseGithubRepositoryLocator(input.externalRepositoryId);\n const file = await this.github.fetchRepositoryFile({\n installationId,\n repositoryId,\n ref: input.ref,\n path: input.path,\n });\n\n if (\n file.size > MAX_REPOSITORY_FILE_BYTES ||\n Buffer.byteLength(file.content, 'utf8') > MAX_REPOSITORY_FILE_BYTES\n ) {\n throw new GithubIntegrationProviderError(\n 'content-too-large',\n 'GitHub file content is larger than the supported limit',\n );\n }\n\n return {\n path: file.path,\n ref: input.ref,\n content: file.content,\n };\n }\n\n async createCheckoutSpec(\n input: CreateCheckoutSpecInput<GithubIntegrationConnection>,\n ): Promise<CheckoutSpec> {\n const installationId = await this.installationId(input.connection.id);\n const {repositoryId} = parseGithubRepositoryLocator(input.externalRepositoryId);\n const repository = await this.github.getRepository({installationId, repositoryId});\n const ref = input.ref?.trim() || repository.defaultBranch;\n const {token, expiresAt} = await this.github.createInstallationAccessToken({\n installationId,\n repositoryId,\n permissions: input.permissions,\n });\n const gitAuthor = githubAppGitAuthor();\n\n return {\n repositoryUrl: repository.cloneUrl,\n ref,\n credentials: {username: 'x-access-token', token, expiresAt},\n ...(gitAuthor ? {gitAuthor} : {}),\n };\n }\n\n private async installationId(connectionId: string): Promise<number> {\n const installation = await getGithubInstallationByConnectionId(connectionId);\n if (!installation) {\n throw new GithubIntegrationProviderError(\n 'access-denied',\n 'GitHub installation details were not found for the connection',\n );\n }\n\n return Number.parseInt(installation.installationId, 10);\n }\n}\n\nfunction githubAppGitAuthor(): CheckoutSpec['gitAuthor'] {\n const appUsername = config.GITHUB_APP_USERNAME?.trim();\n if (!appUsername) return undefined;\n const name = appUsername.endsWith(GITHUB_APP_BOT_SUFFIX)\n ? appUsername\n : `${appUsername}${GITHUB_APP_BOT_SUFFIX}`;\n return {name, email: `${config.GITHUB_APP_ID}+${name}@users.noreply.github.com`};\n}\n\nfunction toRepositorySnapshot(repository: GithubRepository): RepositorySnapshot {\n return {\n externalRepositoryId: buildProviderRepositoryId(GITHUB_PROVIDER, String(repository.id)),\n owner: repository.ownerLogin,\n name: repository.name,\n fullName: repository.fullName,\n defaultBranch: repository.defaultBranch,\n visibility: toRepositoryVisibility(repository),\n cloneUrl: repository.cloneUrl,\n htmlUrl: repository.htmlUrl,\n };\n}\n\nfunction parseGithubRepositoryLocator(externalRepositoryId: string): {\n repositoryId: number;\n} {\n const value = parseProviderRepositoryId(externalRepositoryId, GITHUB_PROVIDER);\n const repositoryId = Number.parseInt(value, 10);\n if (!Number.isInteger(repositoryId) || repositoryId <= 0 || String(repositoryId) !== value) {\n throw new GithubIntegrationProviderError(\n 'repository-not-found',\n `GitHub repository id ${externalRepositoryId} must follow the form ${GITHUB_PROVIDER}:<numeric-id>`,\n );\n }\n\n return {repositoryId};\n}\n\nfunction toRepositoryVisibility(repository: GithubRepository): RepositoryVisibility {\n if (repository.visibility === 'public') return 'public';\n if (repository.visibility === 'private') return 'private';\n if (repository.visibility === 'internal') return 'internal';\n return repository.private ? 'private' : 'public';\n}\n"],"names":["Buffer","buildProviderRepositoryId","MAX_REPOSITORY_FILE_BYTES","parseProviderRepositoryId","config","getGithubInstallationByConnectionId","GithubIntegrationProviderError","GITHUB_PROVIDER","GITHUB_APP_BOT_SUFFIX","SEARCH_PAGE_SIZE","SEARCH_MAX_PAGES_PER_REQUEST","GithubSourceControlProvider","github","listRepositories","input","installation","connection","id","installationId","Number","parseInt","needle","search","trim","toLowerCase","page","listInstallationRepositories","limit","cursor","repositories","map","toRepositorySnapshot","nextCursor","matches","pagesScanned","length","repo","fullName","includes","push","undefined","slice","resolveRepository","repositoryId","parseGithubRepositoryLocator","externalRepositoryId","repository","getRepository","listFiles","listRepositoryFiles","ref","prefix","files","file","path","type","size","fetchFile","fetchRepositoryFile","byteLength","content","createCheckoutSpec","defaultBranch","token","expiresAt","createInstallationAccessToken","permissions","gitAuthor","githubAppGitAuthor","repositoryUrl","cloneUrl","credentials","username","connectionId","appUsername","GITHUB_APP_USERNAME","name","endsWith","email","GITHUB_APP_ID","String","owner","ownerLogin","visibility","toRepositoryVisibility","htmlUrl","value","isInteger","private"],"mappings":"AAAA,SAAQA,MAAM,QAAO,cAAc;AACnC,SACEC,yBAAyB,EASzBC,yBAAyB,EACzBC,yBAAyB,QAMpB,+BAA+B;AAEtC,SAAQC,MAAM,QAAO,aAAa;AAClC,SAAQC,mCAAmC,QAAO,uBAAuB;AACzE,SAAQC,8BAA8B,QAAO,cAAc;AAI3D,MAAMC,kBAAkB;AACxB,MAAMC,wBAAwB;AAC9B,MAAMC,mBAAmB;AACzB,MAAMC,+BAA+B;AAErC,OAAO,MAAMC;IAGX,YAAY,AAAiBC,MAAuB,CAAE;aAAzBA,SAAAA;IAA0B;IAEvD,MAAMC,iBACJC,KAAyD,EAChC;QACzB,MAAMC,eAAe,MAAMV,oCAAoCS,MAAME,UAAU,CAACC,EAAE;QAClF,IAAI,CAACF,cAAc;YACjB,MAAM,IAAIT,+BACR,iBACA;QAEJ;QAEA,MAAMY,iBAAiBC,OAAOC,QAAQ,CAACL,aAAaG,cAAc,EAAE;QACpE,MAAMG,SAASP,MAAMQ,MAAM,EAAEC,OAAOC;QAEpC,IAAI,CAACH,QAAQ;YACX,MAAMI,OAAO,MAAM,IAAI,CAACb,MAAM,CAACc,4BAA4B,CAAC;gBAC1DR;gBACAS,OAAOb,MAAMa,KAAK;gBAClBC,QAAQd,MAAMc,MAAM;YACtB;YACA,OAAO;gBACLC,cAAcJ,KAAKI,YAAY,CAACC,GAAG,CAACC;gBACpCC,YAAYP,KAAKO,UAAU;YAC7B;QACF;QAEA,MAAMC,UAAgC,EAAE;QACxC,IAAIL,SAASd,MAAMc,MAAM;QACzB,IAAIM,eAAe;QACnB,MAAOD,QAAQE,MAAM,GAAGrB,MAAMa,KAAK,IAAIO,eAAexB,6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gB,aAAa,CAAC;IAEvG;IAEA,OAAO;QAACoC;IAAY;AACtB;AAEA,SAASyC,uBAAuBtC,UAA4B;IAC1D,IAAIA,WAAWqC,UAAU,KAAK,UAAU,OAAO;IAC/C,IAAIrC,WAAWqC,UAAU,KAAK,WAAW,OAAO;IAChD,IAAIrC,WAAWqC,UAAU,KAAK,YAAY,OAAO;IACjD,OAAOrC,WAAW0C,OAAO,GAAG,YAAY;AAC1C"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type GetIntegrationConnectionByIdFn, type PublishIntegrationEventReceivedFn, type PublishSourcePushFn, type RecordDeliveryOnlyFn, type StoredWebhookRequest, type WebhookProcessingResult } from '@shipfox/api-integration-
|
|
1
|
+
import { type GetIntegrationConnectionByIdFn, type PublishIntegrationEventReceivedFn, type PublishSourcePushFn, type RecordDeliveryOnlyFn, type StoredWebhookRequest, type WebhookProcessingResult } from '@shipfox/api-integration-spi';
|
|
2
2
|
import type { NodePgDatabase } from 'drizzle-orm/node-postgres';
|
|
3
3
|
export interface CreateGithubWebhookProcessorOptions {
|
|
4
4
|
coreDb: () => NodePgDatabase<Record<string, unknown>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webhook-processor.d.ts","sourceRoot":"","sources":["../../src/core/webhook-processor.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,KAAK,8BAA8B,EACnC,KAAK,iCAAiC,EACtC,KAAK,mBAAmB,EACxB,KAAK,oBAAoB,EACzB,KAAK,oBAAoB,EACzB,KAAK,uBAAuB,EAC7B,MAAM,
|
|
1
|
+
{"version":3,"file":"webhook-processor.d.ts","sourceRoot":"","sources":["../../src/core/webhook-processor.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,KAAK,8BAA8B,EACnC,KAAK,iCAAiC,EACtC,KAAK,mBAAmB,EACxB,KAAK,oBAAoB,EACzB,KAAK,oBAAoB,EACzB,KAAK,uBAAuB,EAC7B,MAAM,8BAA8B,CAAC;AAEtC,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,2BAA2B,CAAC;AAQ9D,MAAM,WAAW,mCAAmC;IAClD,MAAM,EAAE,MAAM,cAAc,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IACtD,+BAA+B,EAAE,iCAAiC,CAAC;IACnE,iBAAiB,EAAE,mBAAmB,CAAC;IACvC,kBAAkB,EAAE,oBAAoB,CAAC;IACzC,4BAA4B,EAAE,8BAA8B,CAAC;IAC7D,6BAA6B,CAAC,EAC1B,CAAC,CAAC,MAAM,EAAE;QAAC,WAAW,EAAE,MAAM,CAAC;QAAC,cAAc,EAAE,MAAM,CAAA;KAAC,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC,GAC7E,SAAS,CAAC;CACf;AAED,MAAM,WAAW,sBAAsB;IACrC,OAAO,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,uBAAuB,CAAC,CAAC;CAC1E;AAED,wBAAgB,4BAA4B,CAC1C,OAAO,EAAE,mCAAmC,GAC3C,sBAAsB,CAGxB"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Buffer } from 'node:buffer';
|
|
2
2
|
import { Webhooks } from '@octokit/webhooks';
|
|
3
|
-
import { decodeWebhookBody } from '@shipfox/api-integration-
|
|
3
|
+
import { decodeWebhookBody } from '@shipfox/api-integration-spi';
|
|
4
4
|
import { logger } from '@shipfox/node-opentelemetry';
|
|
5
5
|
import { config } from '#config.js';
|
|
6
6
|
import { handleGithubEvent } from '#core/webhook.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/core/webhook-processor.ts"],"sourcesContent":["import {Buffer} from 'node:buffer';\nimport {Webhooks} from '@octokit/webhooks';\nimport {\n decodeWebhookBody,\n type GetIntegrationConnectionByIdFn,\n type PublishIntegrationEventReceivedFn,\n type PublishSourcePushFn,\n type RecordDeliveryOnlyFn,\n type StoredWebhookRequest,\n type WebhookProcessingResult,\n} from '@shipfox/api-integration-
|
|
1
|
+
{"version":3,"sources":["../../src/core/webhook-processor.ts"],"sourcesContent":["import {Buffer} from 'node:buffer';\nimport {Webhooks} from '@octokit/webhooks';\nimport {\n decodeWebhookBody,\n type GetIntegrationConnectionByIdFn,\n type PublishIntegrationEventReceivedFn,\n type PublishSourcePushFn,\n type RecordDeliveryOnlyFn,\n type StoredWebhookRequest,\n type WebhookProcessingResult,\n} from '@shipfox/api-integration-spi';\nimport {logger} from '@shipfox/node-opentelemetry';\nimport type {NodePgDatabase} from 'drizzle-orm/node-postgres';\nimport {config} from '#config.js';\nimport {handleGithubEvent} from '#core/webhook.js';\n\nconst DELIVERY_HEADER = 'x-github-delivery';\nconst EVENT_HEADER = 'x-github-event';\nconst SIGNATURE_HEADER = 'x-hub-signature-256';\n\nexport interface CreateGithubWebhookProcessorOptions {\n coreDb: () => NodePgDatabase<Record<string, unknown>>;\n publishIntegrationEventReceived: PublishIntegrationEventReceivedFn;\n publishSourcePush: PublishSourcePushFn;\n recordDeliveryOnly: RecordDeliveryOnlyFn;\n getIntegrationConnectionById: GetIntegrationConnectionByIdFn;\n deleteInstallationTokenSecret?:\n | ((params: {workspaceId: string; installationId: number}) => Promise<unknown>)\n | undefined;\n}\n\nexport interface GithubWebhookProcessor {\n process(request: StoredWebhookRequest): Promise<WebhookProcessingResult>;\n}\n\nexport function createGithubWebhookProcessor(\n options: CreateGithubWebhookProcessorOptions,\n): GithubWebhookProcessor {\n const webhooks = new Webhooks({secret: config.GITHUB_APP_WEBHOOK_SECRET});\n return {process: (request) => processGithubWebhookRequest(options, webhooks, request)};\n}\n\nasync function processGithubWebhookRequest(\n options: CreateGithubWebhookProcessorOptions,\n webhooks: Webhooks,\n request: StoredWebhookRequest,\n): Promise<WebhookProcessingResult> {\n if (request.route_id !== 'github') {\n throw new Error(`GitHub processor cannot process ${request.route_id} requests`);\n }\n\n const deliveryId = request.headers[DELIVERY_HEADER];\n const event = request.headers[EVENT_HEADER];\n const signature = request.headers[SIGNATURE_HEADER];\n if (!deliveryId || !event || !signature) {\n return {outcome: 'discarded', reason: 'missing_required_input'};\n }\n\n const rawBody = Buffer.from(decodeWebhookBody(request.body));\n let verified: boolean;\n try {\n verified = await webhooks.verify(rawBody.toString('utf8'), signature);\n } catch (error) {\n logger().warn({deliveryId, err: error}, 'github webhook signature verification threw');\n verified = false;\n }\n if (!verified) return {outcome: 'discarded', reason: 'invalid_signature', deliveryId};\n\n let payload: unknown;\n try {\n payload = JSON.parse(rawBody.toString('utf8'));\n } catch (error) {\n logger().warn({deliveryId, err: error}, 'github webhook payload JSON parse failed');\n return {outcome: 'discarded', reason: 'malformed_payload', deliveryId};\n }\n\n const result = await options.coreDb().transaction(async (tx) =>\n handleGithubEvent({\n tx,\n deliveryId,\n event,\n payload,\n publishIntegrationEventReceived: options.publishIntegrationEventReceived,\n publishSourcePush: options.publishSourcePush,\n recordDeliveryOnly: options.recordDeliveryOnly,\n getIntegrationConnectionById: options.getIntegrationConnectionById,\n }),\n );\n\n if (result.installationTokenCleanup && options.deleteInstallationTokenSecret) {\n await options.deleteInstallationTokenSecret(result.installationTokenCleanup);\n }\n\n return result.outcome.startsWith('duplicate')\n ? {outcome: 'duplicate', deliveryId}\n : {outcome: 'processed', deliveryId};\n}\n"],"names":["Buffer","Webhooks","decodeWebhookBody","logger","config","handleGithubEvent","DELIVERY_HEADER","EVENT_HEADER","SIGNATURE_HEADER","createGithubWebhookProcessor","options","webhooks","secret","GITHUB_APP_WEBHOOK_SECRET","process","request","processGithubWebhookRequest","route_id","Error","deliveryId","headers","event","signature","outcome","reason","rawBody","from","body","verified","verify","toString","error","warn","err","payload","JSON","parse","result","coreDb","transaction","tx","publishIntegrationEventReceived","publishSourcePush","recordDeliveryOnly","getIntegrationConnectionById","installationTokenCleanup","deleteInstallationTokenSecret","startsWith"],"mappings":"AAAA,SAAQA,MAAM,QAAO,cAAc;AACnC,SAAQC,QAAQ,QAAO,oBAAoB;AAC3C,SACEC,iBAAiB,QAOZ,+B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IAAI,CAAC;YAACb;YAAYc,KAAKF;QAAK,GAAG;QACxC,OAAO;YAACR,SAAS;YAAaC,QAAQ;YAAqBL;QAAU;IACvE;IAEA,MAAMkB,SAAS,MAAM3B,QAAQ4B,MAAM,GAAGC,WAAW,CAAC,OAAOC,KACvDnC,kBAAkB;YAChBmC;YACArB;YACAE;YACAa;YACAO,iCAAiC/B,QAAQ+B,+BAA+B;YACxEC,mBAAmBhC,QAAQgC,iBAAiB;YAC5CC,oBAAoBjC,QAAQiC,kBAAkB;YAC9CC,8BAA8BlC,QAAQkC,4BAA4B;QACpE;IAGF,IAAIP,OAAOQ,wBAAwB,IAAInC,QAAQoC,6BAA6B,EAAE;QAC5E,MAAMpC,QAAQoC,6BAA6B,CAACT,OAAOQ,wBAAwB;IAC7E;IAEA,OAAOR,OAAOd,OAAO,CAACwB,UAAU,CAAC,eAC7B;QAACxB,SAAS;QAAaJ;IAAU,IACjC;QAACI,SAAS;QAAaJ;IAAU;AACvC"}
|
package/dist/core/webhook.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type GetIntegrationConnectionByIdFn, type IntegrationTx, type PublishIntegrationEventReceivedFn, type PublishSourcePushFn, type RecordDeliveryOnlyFn } from '@shipfox/api-integration-
|
|
1
|
+
import { type GetIntegrationConnectionByIdFn, type IntegrationTx, type PublishIntegrationEventReceivedFn, type PublishSourcePushFn, type RecordDeliveryOnlyFn } from '@shipfox/api-integration-spi';
|
|
2
2
|
export interface HandleGithubEventParams {
|
|
3
3
|
tx: IntegrationTx;
|
|
4
4
|
deliveryId: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webhook.d.ts","sourceRoot":"","sources":["../../src/core/webhook.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"webhook.d.ts","sourceRoot":"","sources":["../../src/core/webhook.ts"],"names":[],"mappings":"AAMA,OAAO,EAEL,KAAK,8BAA8B,EACnC,KAAK,aAAa,EAClB,KAAK,iCAAiC,EACtC,KAAK,mBAAmB,EACxB,KAAK,oBAAoB,EAE1B,MAAM,8BAA8B,CAAC;AAStC,MAAM,WAAW,uBAAuB;IACtC,EAAE,EAAE,aAAa,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,OAAO,CAAC;IACjB,+BAA+B,EAAE,iCAAiC,CAAC;IACnE,iBAAiB,EAAE,mBAAmB,CAAC;IACvC,kBAAkB,EAAE,oBAAoB,CAAC;IACzC,4BAA4B,EAAE,8BAA8B,CAAC;CAC9D;AAED,MAAM,MAAM,wBAAwB,GAChC,WAAW,GACX,WAAW,GACX,oBAAoB,GACpB,oBAAoB,GACpB,8BAA8B,GAC9B,8BAA8B,GAC9B,sBAAsB,GACtB,oBAAoB,GACpB,qBAAqB,GACrB,oBAAoB,CAAC;AAEzB,MAAM,WAAW,uBAAuB;IACtC,OAAO,EAAE,wBAAwB,CAAC;IAClC,wBAAwB,CAAC,EAAE;QAAC,WAAW,EAAE,MAAM,CAAC;QAAC,cAAc,EAAE,MAAM,CAAA;KAAC,GAAG,SAAS,CAAC;CACtF;AAMD,wBAAsB,iBAAiB,CACrC,MAAM,EAAE,uBAAuB,GAC9B,OAAO,CAAC,uBAAuB,CAAC,CAqHlC"}
|
package/dist/core/webhook.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { buildProviderRepositoryId } from '@shipfox/api-integration-core-dto';
|
|
2
1
|
import { githubPushPayloadSchema, githubWebhookActionSchema, githubWebhookInstallationSchema } from '@shipfox/api-integration-github-dto';
|
|
2
|
+
import { buildProviderRepositoryId } from '@shipfox/api-integration-spi';
|
|
3
3
|
import { logger } from '@shipfox/node-opentelemetry';
|
|
4
4
|
import { getGithubInstallationByInstallationId } from '#db/installations.js';
|
|
5
5
|
const REFS_HEADS_PREFIX = 'refs/heads/';
|
package/dist/core/webhook.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/core/webhook.ts"],"sourcesContent":["import {\n buildProviderRepositoryId,\n type GetIntegrationConnectionByIdFn,\n type IntegrationTx,\n type PublishIntegrationEventReceivedFn,\n type PublishSourcePushFn,\n type RecordDeliveryOnlyFn,\n type SourcePushPayload,\n} from '@shipfox/api-integration-core-dto';\nimport {\n type GithubPushPayloadDto,\n githubPushPayloadSchema,\n githubWebhookActionSchema,\n githubWebhookInstallationSchema,\n} from '@shipfox/api-integration-github-dto';\nimport {logger} from '@shipfox/node-opentelemetry';\nimport {getGithubInstallationByInstallationId} from '#db/installations.js';\n\nconst REFS_HEADS_PREFIX = 'refs/heads/';\nconst GITHUB_SOURCE = 'github';\n// GitHub sends a `push` webhook for a branch deletion with `after` set to this all-zero SHA.\nconst DELETED_BRANCH_SHA = '0'.repeat(40);\n\nexport interface HandleGithubEventParams {\n tx: IntegrationTx;\n deliveryId: string;\n event: string;\n payload: unknown;\n publishIntegrationEventReceived: PublishIntegrationEventReceivedFn;\n publishSourcePush: PublishSourcePushFn;\n recordDeliveryOnly: RecordDeliveryOnlyFn;\n getIntegrationConnectionById: GetIntegrationConnectionByIdFn;\n}\n\nexport type HandleGithubEventOutcome =\n | 'published'\n | 'duplicate'\n | 'published-envelope'\n | 'duplicate-envelope'\n | 'published-push-envelope-only'\n | 'duplicate-push-envelope-only'\n | 'unknown-installation'\n | 'missing-connection'\n | 'inactive-connection'\n | 'no-installation-id';\n\nexport interface HandleGithubEventResult {\n outcome: HandleGithubEventOutcome;\n installationTokenCleanup?: {workspaceId: string; installationId: number} | undefined;\n}\n\nfunction isBranchDeletion(after: string): boolean {\n return after === DELETED_BRANCH_SHA;\n}\n\nexport async function handleGithubEvent(\n params: HandleGithubEventParams,\n): Promise<HandleGithubEventResult> {\n const actionEnvelope = githubWebhookActionSchema.safeParse(params.payload);\n const action = actionEnvelope.success ? actionEnvelope.data.action : undefined;\n const installationEnvelope = githubWebhookInstallationSchema.safeParse(params.payload);\n const installationId = installationEnvelope.success\n ? installationEnvelope.data.installation?.id\n : undefined;\n if (installationId === undefined) {\n await params.recordDeliveryOnly({\n tx: params.tx,\n provider: GITHUB_SOURCE,\n deliveryId: params.deliveryId,\n });\n return {outcome: 'no-installation-id'};\n }\n\n const installation = await getGithubInstallationByInstallationId(String(installationId), {\n tx: params.tx,\n });\n if (!installation) {\n logger().warn(\n {deliveryId: params.deliveryId, installationId},\n 'github webhook: unknown installation, dropping',\n );\n await params.recordDeliveryOnly({\n tx: params.tx,\n provider: GITHUB_SOURCE,\n deliveryId: params.deliveryId,\n });\n return {outcome: 'unknown-installation'};\n }\n\n const connection = await params.getIntegrationConnectionById(installation.connectionId, {\n tx: params.tx,\n });\n if (!connection) {\n logger().warn(\n {deliveryId: params.deliveryId, installationId, connectionId: installation.connectionId},\n 'github webhook: installation has no connection, dropping',\n );\n await params.recordDeliveryOnly({\n tx: params.tx,\n provider: GITHUB_SOURCE,\n deliveryId: params.deliveryId,\n });\n return {outcome: 'missing-connection'};\n }\n\n if (connection.lifecycleStatus !== 'active') {\n const logContext = {\n deliveryId: params.deliveryId,\n installationId,\n connectionId: connection.id,\n workspaceId: connection.workspaceId,\n lifecycleStatus: connection.lifecycleStatus,\n };\n // `disabled` is an expected steady state; only `error` is anomalous.\n if (connection.lifecycleStatus === 'error') {\n logger().warn(logContext, 'github webhook: connection in error state, dropping');\n } else {\n logger().info(logContext, 'github webhook: connection disabled, dropping');\n }\n await params.recordDeliveryOnly({\n tx: params.tx,\n provider: GITHUB_SOURCE,\n deliveryId: params.deliveryId,\n });\n return withInstallationTokenCleanup(\n {outcome: 'inactive-connection'},\n params.event,\n action,\n connection.workspaceId,\n installationId,\n );\n }\n\n if (params.event === 'push') {\n const validated = githubPushPayloadSchema.safeParse(params.payload);\n if (!validated.success) {\n logger().warn(\n {deliveryId: params.deliveryId, issues: validated.error.issues},\n 'github webhook push payload failed schema validation; publishing generic envelope only',\n );\n return publishGithubEnvelopeOnly({\n tx: params.tx,\n deliveryId: params.deliveryId,\n payload: params.payload,\n publishIntegrationEventReceived: params.publishIntegrationEventReceived,\n connection,\n event: 'push',\n });\n }\n\n return publishGithubPush({\n ...params,\n eventPayload: validated.data,\n rawPayload: params.payload,\n connection,\n });\n }\n\n const eventName = action ? `${params.event}.${action}` : params.event;\n const result = await publishGithubEnvelopeOnly({\n tx: params.tx,\n deliveryId: params.deliveryId,\n payload: params.payload,\n publishIntegrationEventReceived: params.publishIntegrationEventReceived,\n connection,\n event: eventName,\n });\n return withInstallationTokenCleanup(\n result,\n params.event,\n action,\n connection.workspaceId,\n installationId,\n );\n}\n\nfunction shouldDeleteInstallationTokenSecret(event: string, action: string | undefined): boolean {\n return event === 'installation' && (action === 'deleted' || action === 'suspend');\n}\n\nfunction withInstallationTokenCleanup(\n result: HandleGithubEventResult,\n event: string,\n action: string | undefined,\n workspaceId: string,\n installationId: number,\n): HandleGithubEventResult {\n if (!shouldDeleteInstallationTokenSecret(event, action)) return result;\n return {...result, installationTokenCleanup: {workspaceId, installationId}};\n}\n\nasync function publishGithubPush(params: {\n tx: IntegrationTx;\n deliveryId: string;\n publishIntegrationEventReceived: PublishIntegrationEventReceivedFn;\n publishSourcePush: PublishSourcePushFn;\n eventPayload: GithubPushPayloadDto;\n rawPayload: unknown;\n connection: {\n id: string;\n workspaceId: string;\n slug: string;\n displayName: string;\n };\n}): Promise<{outcome: HandleGithubEventOutcome}> {\n if (isBranchDeletion(params.eventPayload.after)) {\n const result = await params.publishIntegrationEventReceived({\n tx: params.tx,\n event: {\n provider: GITHUB_SOURCE,\n source: params.connection.slug,\n event: 'push',\n workspaceId: params.connection.workspaceId,\n connectionId: params.connection.id,\n connectionName: params.connection.displayName,\n deliveryId: params.deliveryId,\n receivedAt: new Date().toISOString(),\n payload: params.rawPayload,\n },\n });\n return {\n outcome: result.published ? 'published-push-envelope-only' : 'duplicate-push-envelope-only',\n };\n }\n\n const ref = stripRefsHeads(params.eventPayload.ref);\n const defaultBranch = params.eventPayload.repository.default_branch;\n const push: SourcePushPayload = {\n externalRepositoryId: buildProviderRepositoryId(\n GITHUB_SOURCE,\n String(params.eventPayload.repository.id),\n ),\n ref,\n headCommitSha: params.eventPayload.after,\n defaultBranch,\n isDefaultBranch: ref === defaultBranch,\n };\n const result = await params.publishSourcePush({\n tx: params.tx,\n provider: GITHUB_SOURCE,\n source: params.connection.slug,\n workspaceId: params.connection.workspaceId,\n connectionId: params.connection.id,\n connectionName: params.connection.displayName,\n deliveryId: params.deliveryId,\n receivedAt: new Date().toISOString(),\n rawPayload: params.rawPayload,\n push,\n });\n\n return {outcome: result.published ? 'published' : 'duplicate'};\n}\n\nasync function publishGithubEnvelopeOnly(params: {\n tx: IntegrationTx;\n deliveryId: string;\n payload: unknown;\n publishIntegrationEventReceived: PublishIntegrationEventReceivedFn;\n connection: {id: string; workspaceId: string; slug: string; displayName: string};\n event: string;\n}): Promise<{outcome: HandleGithubEventOutcome}> {\n const result = await params.publishIntegrationEventReceived({\n tx: params.tx,\n event: {\n provider: GITHUB_SOURCE,\n source: params.connection.slug,\n event: params.event,\n workspaceId: params.connection.workspaceId,\n connectionId: params.connection.id,\n connectionName: params.connection.displayName,\n deliveryId: params.deliveryId,\n receivedAt: new Date().toISOString(),\n payload: params.payload,\n },\n });\n return {outcome: result.published ? 'published-envelope' : 'duplicate-envelope'};\n}\n\nfunction stripRefsHeads(ref: string): string {\n return ref.startsWith(REFS_HEADS_PREFIX) ? ref.slice(REFS_HEADS_PREFIX.length) : ref;\n}\n"],"names":["buildProviderRepositoryId","githubPushPayloadSchema","githubWebhookActionSchema","githubWebhookInstallationSchema","logger","getGithubInstallationByInstallationId","REFS_HEADS_PREFIX","GITHUB_SOURCE","DELETED_BRANCH_SHA","repeat","isBranchDeletion","after","handleGithubEvent","params","actionEnvelope","safeParse","payload","action","success","data","undefined","installationEnvelope","installationId","installation","id","recordDeliveryOnly","tx","provider","deliveryId","outcome","String","warn","connection","getIntegrationConnectionById","connectionId","lifecycleStatus","logContext","workspaceId","info","withInstallationTokenCleanup","event","validated","issues","error","publishGithubEnvelopeOnly","publishIntegrationEventReceived","publishGithubPush","eventPayload","rawPayload","eventName","result","shouldDeleteInstallationTokenSecret","installationTokenCleanup","source","slug","connectionName","displayName","receivedAt","Date","toISOString","published","ref","stripRefsHeads","defaultBranch","repository","default_branch","push","externalRepositoryId","headCommitSha","isDefaultBranch","publishSourcePush","startsWith","slice","length"],"mappings":"AAAA,SACEA,yBAAyB,QAOpB,oCAAoC;AAC3C,SAEEC,uBAAuB,EACvBC,yBAAyB,EACzBC,+BAA+B,QAC1B,sCAAsC;AAC7C,SAAQC,MAAM,QAAO,8BAA8B;AACnD,SAAQC,qCAAqC,QAAO,uBAAuB;AAE3E,MAAMC,oBAAoB;AAC1B,MAAMC,gBAAgB;AACtB,6FAA6F;AAC7F,MAAMC,qBAAqB,IAAIC,MAAM,CAAC;AA8BtC,SAASC,iBAAiBC,KAAa;IACrC,OAAOA,UAAUH;AACnB;AAEA,OAAO,eAAeI,kBACpBC,MAA+B;IAE/B,MAAMC,iBAAiBZ,0BAA0Ba,SAAS,CAACF,OAAOG,OAAO;IACzE,MAAMC,SAASH,eAAeI,OAAO,GAAGJ,eAAeK,IAAI,CAACF,MAAM,GAAGG;IACrE,MAAMC,uBAAuBlB,gCAAgCY,SAAS,CAACF,OAAOG,OAAO;IACrF,MAAMM,iBAAiBD,qBAAqBH,OAAO,GAC/CG,qBAAqBF,IAAI,CAACI,YAAY,EAAEC,KACxCJ;IACJ,IAAIE,mBAAmBF,WAAW;QAChC,MAAMP,OAAOY,kBAAkB,CAAC;YAC9BC,IAAIb,OAAOa,EAAE;YACbC,UAAUpB;YACVqB,YAAYf,OAAOe,UAAU;QAC/B;QACA,OAAO;YAACC,SAAS;QAAoB;IACvC;IAEA,MAAMN,eAAe,MAAMlB,sCAAsCyB,OAAOR,iBAAiB;QACvFI,IAAIb,OAAOa,EAAE;IACf;IACA,IAAI,CAACH,cAAc;QACjBnB,SAAS2B,IAAI,CACX;YAACH,YAAYf,OA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0B/B,MAOxC;IACC,MAAMqC,SAAS,MAAMrC,OAAOgC,+BAA+B,CAAC;QAC1DnB,IAAIb,OAAOa,EAAE;QACbc,OAAO;YACLb,UAAUpB;YACV8C,QAAQxC,OAAOmB,UAAU,CAACsB,IAAI;YAC9Bd,OAAO3B,OAAO2B,KAAK;YACnBH,aAAaxB,OAAOmB,UAAU,CAACK,WAAW;YAC1CH,cAAcrB,OAAOmB,UAAU,CAACR,EAAE;YAClC+B,gBAAgB1C,OAAOmB,UAAU,CAACwB,WAAW;YAC7C5B,YAAYf,OAAOe,UAAU;YAC7B6B,YAAY,IAAIC,OAAOC,WAAW;YAClC3C,SAASH,OAAOG,OAAO;QACzB;IACF;IACA,OAAO;QAACa,SAASqB,OAAOU,SAAS,GAAG,uBAAuB;IAAoB;AACjF;AAEA,SAASE,eAAeD,GAAW;IACjC,OAAOA,IAAIU,UAAU,CAACjE,qBAAqBuD,IAAIW,KAAK,CAAClE,kBAAkBmE,MAAM,IAAIZ;AACnF"}
|
|
1
|
+
{"version":3,"sources":["../../src/core/webhook.ts"],"sourcesContent":["import {\n type GithubPushPayloadDto,\n githubPushPayloadSchema,\n githubWebhookActionSchema,\n githubWebhookInstallationSchema,\n} from '@shipfox/api-integration-github-dto';\nimport {\n buildProviderRepositoryId,\n type GetIntegrationConnectionByIdFn,\n type IntegrationTx,\n type PublishIntegrationEventReceivedFn,\n type PublishSourcePushFn,\n type RecordDeliveryOnlyFn,\n type SourcePushPayload,\n} from '@shipfox/api-integration-spi';\nimport {logger} from '@shipfox/node-opentelemetry';\nimport {getGithubInstallationByInstallationId} from '#db/installations.js';\n\nconst REFS_HEADS_PREFIX = 'refs/heads/';\nconst GITHUB_SOURCE = 'github';\n// GitHub sends a `push` webhook for a branch deletion with `after` set to this all-zero SHA.\nconst DELETED_BRANCH_SHA = '0'.repeat(40);\n\nexport interface HandleGithubEventParams {\n tx: IntegrationTx;\n deliveryId: string;\n event: string;\n payload: unknown;\n publishIntegrationEventReceived: PublishIntegrationEventReceivedFn;\n publishSourcePush: PublishSourcePushFn;\n recordDeliveryOnly: RecordDeliveryOnlyFn;\n getIntegrationConnectionById: GetIntegrationConnectionByIdFn;\n}\n\nexport type HandleGithubEventOutcome =\n | 'published'\n | 'duplicate'\n | 'published-envelope'\n | 'duplicate-envelope'\n | 'published-push-envelope-only'\n | 'duplicate-push-envelope-only'\n | 'unknown-installation'\n | 'missing-connection'\n | 'inactive-connection'\n | 'no-installation-id';\n\nexport interface HandleGithubEventResult {\n outcome: HandleGithubEventOutcome;\n installationTokenCleanup?: {workspaceId: string; installationId: number} | undefined;\n}\n\nfunction isBranchDeletion(after: string): boolean {\n return after === DELETED_BRANCH_SHA;\n}\n\nexport async function handleGithubEvent(\n params: HandleGithubEventParams,\n): Promise<HandleGithubEventResult> {\n const actionEnvelope = githubWebhookActionSchema.safeParse(params.payload);\n const action = actionEnvelope.success ? actionEnvelope.data.action : undefined;\n const installationEnvelope = githubWebhookInstallationSchema.safeParse(params.payload);\n const installationId = installationEnvelope.success\n ? installationEnvelope.data.installation?.id\n : undefined;\n if (installationId === undefined) {\n await params.recordDeliveryOnly({\n tx: params.tx,\n provider: GITHUB_SOURCE,\n deliveryId: params.deliveryId,\n });\n return {outcome: 'no-installation-id'};\n }\n\n const installation = await getGithubInstallationByInstallationId(String(installationId), {\n tx: params.tx,\n });\n if (!installation) {\n logger().warn(\n {deliveryId: params.deliveryId, installationId},\n 'github webhook: unknown installation, dropping',\n );\n await params.recordDeliveryOnly({\n tx: params.tx,\n provider: GITHUB_SOURCE,\n deliveryId: params.deliveryId,\n });\n return {outcome: 'unknown-installation'};\n }\n\n const connection = await params.getIntegrationConnectionById(installation.connectionId, {\n tx: params.tx,\n });\n if (!connection) {\n logger().warn(\n {deliveryId: params.deliveryId, installationId, connectionId: installation.connectionId},\n 'github webhook: installation has no connection, dropping',\n );\n await params.recordDeliveryOnly({\n tx: params.tx,\n provider: GITHUB_SOURCE,\n deliveryId: params.deliveryId,\n });\n return {outcome: 'missing-connection'};\n }\n\n if (connection.lifecycleStatus !== 'active') {\n const logContext = {\n deliveryId: params.deliveryId,\n installationId,\n connectionId: connection.id,\n workspaceId: connection.workspaceId,\n lifecycleStatus: connection.lifecycleStatus,\n };\n // `disabled` is an expected steady state; only `error` is anomalous.\n if (connection.lifecycleStatus === 'error') {\n logger().warn(logContext, 'github webhook: connection in error state, dropping');\n } else {\n logger().info(logContext, 'github webhook: connection disabled, dropping');\n }\n await params.recordDeliveryOnly({\n tx: params.tx,\n provider: GITHUB_SOURCE,\n deliveryId: params.deliveryId,\n });\n return withInstallationTokenCleanup(\n {outcome: 'inactive-connection'},\n params.event,\n action,\n connection.workspaceId,\n installationId,\n );\n }\n\n if (params.event === 'push') {\n const validated = githubPushPayloadSchema.safeParse(params.payload);\n if (!validated.success) {\n logger().warn(\n {deliveryId: params.deliveryId, issues: validated.error.issues},\n 'github webhook push payload failed schema validation; publishing generic envelope only',\n );\n return publishGithubEnvelopeOnly({\n tx: params.tx,\n deliveryId: params.deliveryId,\n payload: params.payload,\n publishIntegrationEventReceived: params.publishIntegrationEventReceived,\n connection,\n event: 'push',\n });\n }\n\n return publishGithubPush({\n ...params,\n eventPayload: validated.data,\n rawPayload: params.payload,\n connection,\n });\n }\n\n const eventName = action ? `${params.event}.${action}` : params.event;\n const result = await publishGithubEnvelopeOnly({\n tx: params.tx,\n deliveryId: params.deliveryId,\n payload: params.payload,\n publishIntegrationEventReceived: params.publishIntegrationEventReceived,\n connection,\n event: eventName,\n });\n return withInstallationTokenCleanup(\n result,\n params.event,\n action,\n connection.workspaceId,\n installationId,\n );\n}\n\nfunction shouldDeleteInstallationTokenSecret(event: string, action: string | undefined): boolean {\n return event === 'installation' && (action === 'deleted' || action === 'suspend');\n}\n\nfunction withInstallationTokenCleanup(\n result: HandleGithubEventResult,\n event: string,\n action: string | undefined,\n workspaceId: string,\n installationId: number,\n): HandleGithubEventResult {\n if (!shouldDeleteInstallationTokenSecret(event, action)) return result;\n return {...result, installationTokenCleanup: {workspaceId, installationId}};\n}\n\nasync function publishGithubPush(params: {\n tx: IntegrationTx;\n deliveryId: string;\n publishIntegrationEventReceived: PublishIntegrationEventReceivedFn;\n publishSourcePush: PublishSourcePushFn;\n eventPayload: GithubPushPayloadDto;\n rawPayload: unknown;\n connection: {\n id: string;\n workspaceId: string;\n slug: string;\n displayName: string;\n };\n}): Promise<{outcome: HandleGithubEventOutcome}> {\n if (isBranchDeletion(params.eventPayload.after)) {\n const result = await params.publishIntegrationEventReceived({\n tx: params.tx,\n event: {\n provider: GITHUB_SOURCE,\n source: params.connection.slug,\n event: 'push',\n workspaceId: params.connection.workspaceId,\n connectionId: params.connection.id,\n connectionName: params.connection.displayName,\n deliveryId: params.deliveryId,\n receivedAt: new Date().toISOString(),\n payload: params.rawPayload,\n },\n });\n return {\n outcome: result.published ? 'published-push-envelope-only' : 'duplicate-push-envelope-only',\n };\n }\n\n const ref = stripRefsHeads(params.eventPayload.ref);\n const defaultBranch = params.eventPayload.repository.default_branch;\n const push: SourcePushPayload = {\n externalRepositoryId: buildProviderRepositoryId(\n GITHUB_SOURCE,\n String(params.eventPayload.repository.id),\n ),\n ref,\n headCommitSha: params.eventPayload.after,\n defaultBranch,\n isDefaultBranch: ref === defaultBranch,\n };\n const result = await params.publishSourcePush({\n tx: params.tx,\n provider: GITHUB_SOURCE,\n source: params.connection.slug,\n workspaceId: params.connection.workspaceId,\n connectionId: params.connection.id,\n connectionName: params.connection.displayName,\n deliveryId: params.deliveryId,\n receivedAt: new Date().toISOString(),\n rawPayload: params.rawPayload,\n push,\n });\n\n return {outcome: result.published ? 'published' : 'duplicate'};\n}\n\nasync function publishGithubEnvelopeOnly(params: {\n tx: IntegrationTx;\n deliveryId: string;\n payload: unknown;\n publishIntegrationEventReceived: PublishIntegrationEventReceivedFn;\n connection: {id: string; workspaceId: string; slug: string; displayName: string};\n event: string;\n}): Promise<{outcome: HandleGithubEventOutcome}> {\n const result = await params.publishIntegrationEventReceived({\n tx: params.tx,\n event: {\n provider: GITHUB_SOURCE,\n source: params.connection.slug,\n event: params.event,\n workspaceId: params.connection.workspaceId,\n connectionId: params.connection.id,\n connectionName: params.connection.displayName,\n deliveryId: params.deliveryId,\n receivedAt: new Date().toISOString(),\n payload: params.payload,\n },\n });\n return {outcome: result.published ? 'published-envelope' : 'duplicate-envelope'};\n}\n\nfunction stripRefsHeads(ref: string): string {\n return ref.startsWith(REFS_HEADS_PREFIX) ? ref.slice(REFS_HEADS_PREFIX.length) : ref;\n}\n"],"names":["githubPushPayloadSchema","githubWebhookActionSchema","githubWebhookInstallationSchema","buildProviderRepositoryId","logger","getGithubInstallationByInstallationId","REFS_HEADS_PREFIX","GITHUB_SOURCE","DELETED_BRANCH_SHA","repeat","isBranchDeletion","after","handleGithubEvent","params","actionEnvelope","safeParse","payload","action","success","data","undefined","installationEnvelope","installationId","installation","id","recordDeliveryOnly","tx","provider","deliveryId","outcome","String","warn","connection","getIntegrationConnectionById","connectionId","lifecycleStatus","logContext","workspaceId","info","withInstallationTokenCleanup","event","validated","issues","error","publishGithubEnvelopeOnly","publishIntegrationEventReceived","publishGithubPush","eventPayload","rawPayload","eventName","result","shouldDeleteInstallationTokenSecret","installationTokenCleanup","source","slug","connectionName","displayName","receivedAt","Date","toISOString","published","ref","stripRefsHeads","defaultBranch","repository","default_branch","push","externalRepositoryId","headCommitSha","isDefaultBranch","publishSourcePush","startsWith","slice","length"],"mappings":"AAAA,SAEEA,uBAAuB,EACvBC,yBAAyB,EACzBC,+BAA+B,QAC1B,sCAAsC;AAC7C,SACEC,yBAAyB,QAOpB,+BAA+B;AACtC,SAAQC,MAAM,QAAO,8BAA8B;AACnD,SAAQC,qCAAqC,QAAO,uBAAuB;AAE3E,MAAMC,oBAAoB;AAC1B,MAAMC,gBAAgB;AACtB,6FAA6F;AAC7F,MAAMC,qBAAqB,IAAIC,MAAM,CAAC;AA8BtC,SAASC,iBAAiBC,KAAa;IACrC,OAAOA,UAAUH;AACnB;AAEA,OAAO,eAAeI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AM,IAAIZ;AACnF"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { GetIntegrationConnectionByIdFn, PublishIntegrationEventReceivedFn, PublishSourcePushFn, RecordDeliveryOnlyFn } from '@shipfox/api-integration-
|
|
1
|
+
import type { GetIntegrationConnectionByIdFn, PublishIntegrationEventReceivedFn, PublishSourcePushFn, RecordDeliveryOnlyFn } from '@shipfox/api-integration-spi';
|
|
2
2
|
import type { NodePgDatabase } from 'drizzle-orm/node-postgres';
|
|
3
3
|
import { type GithubApiClient } from '#api/client.js';
|
|
4
4
|
import type { GithubInstallationTokenProvider } from '#api/installation-token-provider.js';
|
|
@@ -12,7 +12,7 @@ import { type CreateGithubIntegrationRoutesOptions } from '#presentation/routes/
|
|
|
12
12
|
export type { GithubApiClient } from '#api/client.js';
|
|
13
13
|
export { encodeInstallationTokenEnvelope, githubInstallationTokenNamespace, } from '#api/installation-token-envelope.js';
|
|
14
14
|
export { createGithubInstallationTokenProvider, type GithubInstallationTokenProvider, } from '#api/installation-token-provider.js';
|
|
15
|
-
export { type GithubAgentToolCatalogEntry, type GithubAgentToolCategory, type GithubAgentToolId, type GithubAgentToolPermission, type GithubAgentToolPermissionAccess, type GithubAgentToolRequiredPermission, type GithubAgentToolRequiredScope, GithubAgentToolsProvider, githubAgentToolCatalog, } from '#core/agent-tools.js';
|
|
15
|
+
export { type GithubAgentToolCatalogEntry, type GithubAgentToolCategory, type GithubAgentToolId, type GithubAgentToolPermission, type GithubAgentToolPermissionAccess, type GithubAgentToolRequiredPermission, type GithubAgentToolRequiredScope, GithubAgentToolsProvider, githubAgentToolCatalog, githubAgentToolSelectionCatalog, } from '#core/agent-tools.js';
|
|
16
16
|
export { GithubIntegrationProviderError } from '#core/errors.js';
|
|
17
17
|
export type { ConnectGithubInstallationInput } from '#core/install.js';
|
|
18
18
|
export { handleGithubCallback } from '#core/install.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,8BAA8B,EAC9B,iCAAiC,EACjC,mBAAmB,EACnB,oBAAoB,EACrB,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,8BAA8B,EAC9B,iCAAiC,EACjC,mBAAmB,EACnB,oBAAoB,EACrB,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAwB,KAAK,eAAe,EAAC,MAAM,gBAAgB,CAAC;AAC3E,OAAO,KAAK,EAAC,+BAA+B,EAAC,MAAM,qCAAqC,CAAC;AAEzF,OAAO,EAAC,wBAAwB,EAAC,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EAAC,2BAA2B,EAAC,MAAM,yBAAyB,CAAC;AAEpE,OAAO,EAAC,OAAO,EAAE,EAAE,EAAC,MAAM,WAAW,CAAC;AACtC,OAAO,EAAC,mCAAmC,EAAC,MAAM,sBAAsB,CAAC;AACzE,OAAO,EAAC,cAAc,EAAC,MAAM,mBAAmB,CAAC;AACjD,OAAO,EACL,KAAK,4BAA4B,EACjC,qBAAqB,EACtB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EACL,KAAK,oCAAoC,EAE1C,MAAM,iCAAiC,CAAC;AAGzC,YAAY,EAAC,eAAe,EAAC,MAAM,gBAAgB,CAAC;AACpD,OAAO,EACL,+BAA+B,EAC/B,gCAAgC,GACjC,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EACL,qCAAqC,EACrC,KAAK,+BAA+B,GACrC,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EACL,KAAK,2BAA2B,EAChC,KAAK,uBAAuB,EAC5B,KAAK,iBAAiB,EACtB,KAAK,yBAAyB,EAC9B,KAAK,+BAA+B,EACpC,K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,CAAC,CAAC,MAAM,EAAE;QAAC,WAAW,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAC,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC,GACvE,SAAS,CAAC;IACd,UAAU,CAAC,EAAE;QAAC,aAAa,EAAE,+BAA+B,CAAA;KAAC,GAAG,SAAS,CAAC;CAC3E;AAED,wBAAgB,+BAA+B,CAAC,OAAO,EAAE,sCAAsC;;;;;;;sCA4BnD;QAAC,EAAE,EAAE,MAAM,CAAA;KAAC,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;;;;;;EA+BrF"}
|
package/dist/index.js
CHANGED
|
@@ -11,7 +11,7 @@ import { createGithubIntegrationRoutes } from '#presentation/routes/install.js';
|
|
|
11
11
|
import { createGithubWebhookRoutes } from '#presentation/routes/webhooks.js';
|
|
12
12
|
export { encodeInstallationTokenEnvelope, githubInstallationTokenNamespace } from '#api/installation-token-envelope.js';
|
|
13
13
|
export { createGithubInstallationTokenProvider } from '#api/installation-token-provider.js';
|
|
14
|
-
export { GithubAgentToolsProvider, githubAgentToolCatalog } from '#core/agent-tools.js';
|
|
14
|
+
export { GithubAgentToolsProvider, githubAgentToolCatalog, githubAgentToolSelectionCatalog } from '#core/agent-tools.js';
|
|
15
15
|
export { GithubIntegrationProviderError } from '#core/errors.js';
|
|
16
16
|
export { handleGithubCallback } from '#core/install.js';
|
|
17
17
|
export { signGithubInstallState, verifyGithubInstallState } from '#core/state.js';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type {\n GetIntegrationConnectionByIdFn,\n PublishIntegrationEventReceivedFn,\n PublishSourcePushFn,\n RecordDeliveryOnlyFn,\n} from '@shipfox/api-integration-
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type {\n GetIntegrationConnectionByIdFn,\n PublishIntegrationEventReceivedFn,\n PublishSourcePushFn,\n RecordDeliveryOnlyFn,\n} from '@shipfox/api-integration-spi';\nimport type {NodePgDatabase} from 'drizzle-orm/node-postgres';\nimport {createGithubApiClient, type GithubApiClient} from '#api/client.js';\nimport type {GithubInstallationTokenProvider} from '#api/installation-token-provider.js';\nimport {deleteGithubInstallationTokenSecret} from '#api/installation-token-provider.js';\nimport {GithubAgentToolsProvider} from '#core/agent-tools.js';\nimport {GithubSourceControlProvider} from '#core/source-control.js';\nimport {createGithubWebhookProcessor} from '#core/webhook-processor.js';\nimport {closeDb, db} from '#db/db.js';\nimport {getGithubInstallationByConnectionId} from '#db/installations.js';\nimport {migrationsPath} from '#db/migrations.js';\nimport {\n type CreateGithubE2eRoutesOptions,\n createGithubE2eRoutes,\n} from '#presentation/e2eRoutes/index.js';\nimport {\n type CreateGithubIntegrationRoutesOptions,\n createGithubIntegrationRoutes,\n} from '#presentation/routes/install.js';\nimport {createGithubWebhookRoutes} from '#presentation/routes/webhooks.js';\n\nexport type {GithubApiClient} from '#api/client.js';\nexport {\n encodeInstallationTokenEnvelope,\n githubInstallationTokenNamespace,\n} from '#api/installation-token-envelope.js';\nexport {\n createGithubInstallationTokenProvider,\n type GithubInstallationTokenProvider,\n} from '#api/installation-token-provider.js';\nexport {\n type GithubAgentToolCatalogEntry,\n type GithubAgentToolCategory,\n type GithubAgentToolId,\n type GithubAgentToolPermission,\n type GithubAgentToolPermissionAccess,\n type GithubAgentToolRequiredPermission,\n type GithubAgentToolRequiredScope,\n GithubAgentToolsProvider,\n githubAgentToolCatalog,\n githubAgentToolSelectionCatalog,\n} from '#core/agent-tools.js';\nexport {GithubIntegrationProviderError} from '#core/errors.js';\nexport type {ConnectGithubInstallationInput} from '#core/install.js';\nexport {handleGithubCallback} from '#core/install.js';\nexport {signGithubInstallState, verifyGithubInstallState} from '#core/state.js';\nexport type {HandleGithubEventOutcome} from '#core/webhook.js';\nexport {handleGithubEvent} from '#core/webhook.js';\nexport type {\n CreateGithubWebhookProcessorOptions,\n GithubWebhookProcessor,\n} from '#core/webhook-processor.js';\nexport {createGithubWebhookProcessor} from '#core/webhook-processor.js';\nexport type {GithubInstallation, UpsertGithubInstallationParams} from '#db/installations.js';\nexport {\n getGithubInstallationByConnectionId,\n getGithubInstallationByInstallationId,\n upsertGithubInstallation,\n} from '#db/installations.js';\nexport {type CreateGithubE2eRoutesOptions, closeDb, createGithubE2eRoutes, db, migrationsPath};\n\nexport interface CreateGithubIntegrationProviderOptions\n extends Omit<CreateGithubIntegrationRoutesOptions, 'github'> {\n github?: GithubApiClient | undefined;\n coreDb: () => NodePgDatabase<Record<string, unknown>>;\n publishIntegrationEventReceived: PublishIntegrationEventReceivedFn;\n publishSourcePush: PublishSourcePushFn;\n recordDeliveryOnly: RecordDeliveryOnlyFn;\n getIntegrationConnectionById: GetIntegrationConnectionByIdFn;\n getGithubInstallationByConnectionId?: typeof getGithubInstallationByConnectionId | undefined;\n deleteSecrets?:\n | ((params: {workspaceId: string; namespace: string}) => Promise<number>)\n | undefined;\n agentTools?: {tokenProvider: GithubInstallationTokenProvider} | undefined;\n}\n\nexport function createGithubIntegrationProvider(options: CreateGithubIntegrationProviderOptions) {\n const github = options.github ?? createGithubApiClient();\n const getInstallationByConnectionId =\n options.getGithubInstallationByConnectionId ?? getGithubInstallationByConnectionId;\n const deleteSecrets = options.deleteSecrets;\n const deleteInstallationTokenSecret = deleteSecrets\n ? (params: {workspaceId: string; installationId: number}) =>\n deleteGithubInstallationTokenSecret({\n workspaceId: params.workspaceId,\n installationId: params.installationId,\n deleteSecrets,\n })\n : undefined;\n const webhookProcessor = createGithubWebhookProcessor({\n ...options,\n deleteInstallationTokenSecret,\n });\n\n return {\n provider: 'github' as const,\n displayName: 'GitHub',\n adapters: {\n source_control: new GithubSourceControlProvider(github),\n agent_tools: new GithubAgentToolsProvider({\n getInstallationByConnectionId: getInstallationByConnectionId,\n tokenProvider: options.agentTools?.tokenProvider,\n }),\n },\n async connectionExternalUrl(connection: {id: string}): Promise<string | undefined> {\n const installation = await getInstallationByConnectionId(connection.id);\n if (!installation) return undefined;\n const installationId = encodeURIComponent(installation.installationId);\n if (installation.accountType === 'Organization') {\n const login = encodeURIComponent(installation.accountLogin);\n return `https://github.com/organizations/${login}/settings/installations/${installationId}`;\n }\n return `https://github.com/settings/installations/${installationId}`;\n },\n routes: [\n createGithubIntegrationRoutes({\n github,\n getExistingGithubConnection: options.getExistingGithubConnection,\n connectGithubInstallation: options.connectGithubInstallation,\n ...(options.requireActiveWorkspaceMembership\n ? {requireActiveWorkspaceMembership: options.requireActiveWorkspaceMembership}\n : {}),\n }),\n createGithubWebhookRoutes({\n coreDb: options.coreDb,\n publishIntegrationEventReceived: options.publishIntegrationEventReceived,\n publishSourcePush: options.publishSourcePush,\n recordDeliveryOnly: options.recordDeliveryOnly,\n getIntegrationConnectionById: options.getIntegrationConnectionById,\n deleteInstallationTokenSecret,\n processor: webhookProcessor,\n }),\n ],\n webhookProcessors: [{routeIds: ['github'] as const, processor: webhookProcessor}],\n };\n}\n"],"names":["createGithubApiClient","deleteGithubInstallationTokenSecret","GithubAgentToolsProvider","GithubSourceControlProvider","createGithubWebhookProcessor","closeDb","db","getGithubInstallationByConnectionId","migrationsPath","createGithubE2eRoutes","createGithubIntegrationRoutes","createGithubWebhookRoutes","encodeInstallationTokenEnvelope","githubInstallationTokenNamespace","createGithubInstallationTokenProvider","githubAgentToolCatalog","githubAgentToolSelectionCatalog","GithubIntegrationProviderError","handleGithubCallback","signGithubInstallState","verifyGithubInstallState","handleGithubEvent","getGithubInstallationByInstallationId","upsertGithubInstallation","createGithubIntegrationProvider","options","github","getInstallationByConnectionId","deleteSecrets","deleteInstallationTokenSecret","params","workspaceId","installationId","undefined","webhookProcessor","provider","displayName","adapters","source_control","agent_tools","tokenProvider","agentTools","connectionExternalUrl","connection","installation","id","encodeURIComponent","accountType","login","accountLogin","routes","getExistingGithubConnection","connectGithubInstallation","requireActiveWorkspaceMembership","coreDb","publishIntegrationEventReceived","publishSourcePush","recordDeliveryOnly","getInt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'@shipfox/api-integration-
|
|
1
|
+
import type { IntegrationProviderErrorReason } from '@shipfox/api-integration-spi';
|
|
2
2
|
import type { MintErrorClass } from '#api/installation-token-envelope.js';
|
|
3
3
|
export type GithubInstallationTokenLookupOutcome = 'ram-hit' | 'db-hit' | 'minted' | 'served-stale' | 'backoff' | 'contended-poll';
|
|
4
4
|
export declare function recordInstallationTokenLookup(outcome: GithubInstallationTokenLookupOutcome): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instance.d.ts","sourceRoot":"","sources":["../../src/metrics/instance.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,8BAA8B,EAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"instance.d.ts","sourceRoot":"","sources":["../../src/metrics/instance.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,8BAA8B,EAAC,MAAM,8BAA8B,CAAC;AAEjF,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,qCAAqC,CAAC;AAIxE,MAAM,MAAM,oCAAoC,GAC5C,SAAS,GACT,QAAQ,GACR,QAAQ,GACR,cAAc,GACd,SAAS,GACT,gBAAgB,CAAC;AA8CrB,wBAAgB,6BAA6B,CAAC,OAAO,EAAE,oCAAoC,GAAG,IAAI,CAEjG;AAED,wBAAgB,2BAA2B,CAAC,MAAM,EAAE;IAClD,OAAO,EAAE,SAAS,GAAG,SAAS,CAAC;IAC/B,UAAU,EAAE,MAAM,CAAC;CACpB,GAAG,IAAI,CAKP;AAED,wBAAgB,+BAA+B,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI,CAExE;AAED,wBAAgB,8BAA8B,CAAC,MAAM,EAAE;IACrD,MAAM,EAAE,8BAA8B,CAAC;IACvC,KAAK,EAAE,cAAc,CAAC;CACvB,GAAG,IAAI,CAEP"}
|