@flink-app/github-app-plugin 0.12.1-alpha.38
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/CHANGELOG.md +209 -0
- package/LICENSE +21 -0
- package/README.md +667 -0
- package/SECURITY.md +498 -0
- package/dist/GitHubAppInternalContext.d.ts +44 -0
- package/dist/GitHubAppInternalContext.js +2 -0
- package/dist/GitHubAppPlugin.d.ts +45 -0
- package/dist/GitHubAppPlugin.js +367 -0
- package/dist/GitHubAppPluginContext.d.ts +242 -0
- package/dist/GitHubAppPluginContext.js +2 -0
- package/dist/GitHubAppPluginOptions.d.ts +369 -0
- package/dist/GitHubAppPluginOptions.js +2 -0
- package/dist/handlers/InitiateInstallation.d.ts +32 -0
- package/dist/handlers/InitiateInstallation.js +66 -0
- package/dist/handlers/InstallationCallback.d.ts +42 -0
- package/dist/handlers/InstallationCallback.js +248 -0
- package/dist/handlers/UninstallHandler.d.ts +37 -0
- package/dist/handlers/UninstallHandler.js +153 -0
- package/dist/handlers/WebhookHandler.d.ts +54 -0
- package/dist/handlers/WebhookHandler.js +157 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +23 -0
- package/dist/repos/GitHubAppSessionRepo.d.ts +24 -0
- package/dist/repos/GitHubAppSessionRepo.js +32 -0
- package/dist/repos/GitHubInstallationRepo.d.ts +53 -0
- package/dist/repos/GitHubInstallationRepo.js +83 -0
- package/dist/repos/GitHubWebhookEventRepo.d.ts +29 -0
- package/dist/repos/GitHubWebhookEventRepo.js +42 -0
- package/dist/schemas/GitHubAppSession.d.ts +13 -0
- package/dist/schemas/GitHubAppSession.js +2 -0
- package/dist/schemas/GitHubInstallation.d.ts +28 -0
- package/dist/schemas/GitHubInstallation.js +2 -0
- package/dist/schemas/InstallationCallbackRequest.d.ts +10 -0
- package/dist/schemas/InstallationCallbackRequest.js +2 -0
- package/dist/schemas/WebhookEvent.d.ts +16 -0
- package/dist/schemas/WebhookEvent.js +2 -0
- package/dist/schemas/WebhookPayload.d.ts +35 -0
- package/dist/schemas/WebhookPayload.js +2 -0
- package/dist/services/GitHubAPIClient.d.ts +143 -0
- package/dist/services/GitHubAPIClient.js +167 -0
- package/dist/services/GitHubAuthService.d.ts +85 -0
- package/dist/services/GitHubAuthService.js +160 -0
- package/dist/services/WebhookValidator.d.ts +93 -0
- package/dist/services/WebhookValidator.js +123 -0
- package/dist/utils/error-utils.d.ts +67 -0
- package/dist/utils/error-utils.js +121 -0
- package/dist/utils/jwt-utils.d.ts +35 -0
- package/dist/utils/jwt-utils.js +67 -0
- package/dist/utils/state-utils.d.ts +38 -0
- package/dist/utils/state-utils.js +74 -0
- package/dist/utils/token-cache-utils.d.ts +47 -0
- package/dist/utils/token-cache-utils.js +74 -0
- package/dist/utils/webhook-signature-utils.d.ts +22 -0
- package/dist/utils/webhook-signature-utils.js +57 -0
- package/examples/basic-installation.ts +246 -0
- package/examples/create-issue.ts +392 -0
- package/examples/error-handling.ts +396 -0
- package/examples/multi-event-webhook.ts +367 -0
- package/examples/organization-installation.ts +316 -0
- package/examples/repository-access.ts +480 -0
- package/examples/webhook-handling.ts +343 -0
- package/examples/with-jwt-auth.ts +319 -0
- package/package.json +41 -0
- package/spec/core-utilities.spec.ts +243 -0
- package/spec/handlers.spec.ts +216 -0
- package/spec/helpers/reporter.ts +41 -0
- package/spec/integration-and-security.spec.ts +483 -0
- package/spec/plugin-core.spec.ts +258 -0
- package/spec/project-setup.spec.ts +56 -0
- package/spec/repos-and-schemas.spec.ts +288 -0
- package/spec/services.spec.ts +108 -0
- package/spec/support/jasmine.json +7 -0
- package/src/GitHubAppPlugin.ts +411 -0
- package/src/GitHubAppPluginContext.ts +254 -0
- package/src/GitHubAppPluginOptions.ts +412 -0
- package/src/handlers/InstallationCallback.ts +292 -0
- package/src/handlers/WebhookHandler.ts +179 -0
- package/src/index.ts +29 -0
- package/src/repos/GitHubAppSessionRepo.ts +36 -0
- package/src/repos/GitHubInstallationRepo.ts +95 -0
- package/src/repos/GitHubWebhookEventRepo.ts +48 -0
- package/src/schemas/GitHubAppSession.ts +13 -0
- package/src/schemas/GitHubInstallation.ts +28 -0
- package/src/schemas/InstallationCallbackRequest.ts +10 -0
- package/src/schemas/WebhookEvent.ts +16 -0
- package/src/schemas/WebhookPayload.ts +35 -0
- package/src/services/GitHubAPIClient.ts +244 -0
- package/src/services/GitHubAuthService.ts +188 -0
- package/src/services/WebhookValidator.ts +159 -0
- package/src/utils/error-utils.ts +148 -0
- package/src/utils/jwt-utils.ts +64 -0
- package/src/utils/state-utils.ts +72 -0
- package/src/utils/token-cache-utils.ts +89 -0
- package/src/utils/webhook-signature-utils.ts +57 -0
- package/tsconfig.dist.json +4 -0
- package/tsconfig.json +24 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* GitHub App Plugin for Flink Framework
|
|
4
|
+
*
|
|
5
|
+
* Provides GitHub App integration with:
|
|
6
|
+
* - Installation management
|
|
7
|
+
* - JWT-based authentication
|
|
8
|
+
* - Webhook handling with signature validation
|
|
9
|
+
* - API client wrapper
|
|
10
|
+
*/
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.GitHubAppErrorCodes = exports.GitHubAuthService = exports.GitHubAPIClient = exports.githubAppPlugin = void 0;
|
|
13
|
+
// Plugin factory
|
|
14
|
+
var GitHubAppPlugin_1 = require("./GitHubAppPlugin");
|
|
15
|
+
Object.defineProperty(exports, "githubAppPlugin", { enumerable: true, get: function () { return GitHubAppPlugin_1.githubAppPlugin; } });
|
|
16
|
+
// Service exports (for advanced usage)
|
|
17
|
+
var GitHubAPIClient_1 = require("./services/GitHubAPIClient");
|
|
18
|
+
Object.defineProperty(exports, "GitHubAPIClient", { enumerable: true, get: function () { return GitHubAPIClient_1.GitHubAPIClient; } });
|
|
19
|
+
var GitHubAuthService_1 = require("./services/GitHubAuthService");
|
|
20
|
+
Object.defineProperty(exports, "GitHubAuthService", { enumerable: true, get: function () { return GitHubAuthService_1.GitHubAuthService; } });
|
|
21
|
+
// Error utilities
|
|
22
|
+
var error_utils_1 = require("./utils/error-utils");
|
|
23
|
+
Object.defineProperty(exports, "GitHubAppErrorCodes", { enumerable: true, get: function () { return error_utils_1.GitHubAppErrorCodes; } });
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { FlinkRepo } from "@flink-app/flink";
|
|
2
|
+
import { Db } from "mongodb";
|
|
3
|
+
import GitHubAppSession from "../schemas/GitHubAppSession";
|
|
4
|
+
/**
|
|
5
|
+
* Repository for managing temporary GitHub App installation sessions with TTL.
|
|
6
|
+
* Sessions are used during the installation flow to prevent CSRF attacks.
|
|
7
|
+
*/
|
|
8
|
+
declare class GitHubAppSessionRepo extends FlinkRepo<any, GitHubAppSession> {
|
|
9
|
+
constructor(ctx: any, db: Db, collectionName?: string);
|
|
10
|
+
/**
|
|
11
|
+
* Find a GitHub App session by its unique session ID.
|
|
12
|
+
* @param sessionId - The unique session identifier
|
|
13
|
+
* @returns The session if found, null otherwise
|
|
14
|
+
*/
|
|
15
|
+
findBySessionId(sessionId: string): Promise<GitHubAppSession | null>;
|
|
16
|
+
/**
|
|
17
|
+
* Delete a GitHub App session by its unique session ID.
|
|
18
|
+
* Used after the installation callback is processed to prevent session reuse.
|
|
19
|
+
* @param sessionId - The unique session identifier
|
|
20
|
+
* @returns The number of deleted sessions (0 or 1)
|
|
21
|
+
*/
|
|
22
|
+
deleteBySessionId(sessionId: string): Promise<number>;
|
|
23
|
+
}
|
|
24
|
+
export default GitHubAppSessionRepo;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const flink_1 = require("@flink-app/flink");
|
|
4
|
+
/**
|
|
5
|
+
* Repository for managing temporary GitHub App installation sessions with TTL.
|
|
6
|
+
* Sessions are used during the installation flow to prevent CSRF attacks.
|
|
7
|
+
*/
|
|
8
|
+
class GitHubAppSessionRepo extends flink_1.FlinkRepo {
|
|
9
|
+
constructor(ctx, db, collectionName = "github_app_sessions") {
|
|
10
|
+
super(collectionName, db);
|
|
11
|
+
this.ctx = ctx;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Find a GitHub App session by its unique session ID.
|
|
15
|
+
* @param sessionId - The unique session identifier
|
|
16
|
+
* @returns The session if found, null otherwise
|
|
17
|
+
*/
|
|
18
|
+
async findBySessionId(sessionId) {
|
|
19
|
+
return this.getOne({ sessionId });
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Delete a GitHub App session by its unique session ID.
|
|
23
|
+
* Used after the installation callback is processed to prevent session reuse.
|
|
24
|
+
* @param sessionId - The unique session identifier
|
|
25
|
+
* @returns The number of deleted sessions (0 or 1)
|
|
26
|
+
*/
|
|
27
|
+
async deleteBySessionId(sessionId) {
|
|
28
|
+
const { deletedCount } = await this.collection.deleteOne({ sessionId });
|
|
29
|
+
return deletedCount || 0;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.default = GitHubAppSessionRepo;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { FlinkRepo } from "@flink-app/flink";
|
|
2
|
+
import { Db } from "mongodb";
|
|
3
|
+
import GitHubInstallation from "../schemas/GitHubInstallation";
|
|
4
|
+
/**
|
|
5
|
+
* Repository for managing GitHub App installations.
|
|
6
|
+
* Stores installation-to-user mappings and repository access information.
|
|
7
|
+
*/
|
|
8
|
+
declare class GitHubInstallationRepo extends FlinkRepo<any, GitHubInstallation> {
|
|
9
|
+
constructor(ctx: any, db: Db, collectionName?: string);
|
|
10
|
+
/**
|
|
11
|
+
* Find an installation by user ID and installation ID.
|
|
12
|
+
* @param userId - The application user ID
|
|
13
|
+
* @param installationId - The GitHub installation ID
|
|
14
|
+
* @returns The installation if found, null otherwise
|
|
15
|
+
*/
|
|
16
|
+
findByUserAndInstallationId(userId: string, installationId: number): Promise<GitHubInstallation | null>;
|
|
17
|
+
/**
|
|
18
|
+
* Find all installations for a specific user.
|
|
19
|
+
* @param userId - The application user ID
|
|
20
|
+
* @returns Array of installations for the user
|
|
21
|
+
*/
|
|
22
|
+
findByUserId(userId: string): Promise<GitHubInstallation[]>;
|
|
23
|
+
/**
|
|
24
|
+
* Find an installation by its GitHub installation ID.
|
|
25
|
+
* @param installationId - The GitHub installation ID
|
|
26
|
+
* @returns The installation if found, null otherwise
|
|
27
|
+
*/
|
|
28
|
+
findByInstallationId(installationId: number): Promise<GitHubInstallation | null>;
|
|
29
|
+
/**
|
|
30
|
+
* Update the repositories list for an installation.
|
|
31
|
+
* @param installationId - The GitHub installation ID
|
|
32
|
+
* @param repositories - The new repositories list
|
|
33
|
+
* @returns The updated installation
|
|
34
|
+
*/
|
|
35
|
+
updateRepositories(installationId: number, repositories: GitHubInstallation["repositories"]): Promise<GitHubInstallation | null>;
|
|
36
|
+
/**
|
|
37
|
+
* Suspend an installation.
|
|
38
|
+
* @param installationId - The GitHub installation ID
|
|
39
|
+
* @param suspendedBy - Information about who suspended the installation
|
|
40
|
+
* @returns The updated installation
|
|
41
|
+
*/
|
|
42
|
+
suspend(installationId: number, suspendedBy: {
|
|
43
|
+
id: number;
|
|
44
|
+
login: string;
|
|
45
|
+
}): Promise<GitHubInstallation | null>;
|
|
46
|
+
/**
|
|
47
|
+
* Delete an installation by its GitHub installation ID.
|
|
48
|
+
* @param installationId - The GitHub installation ID
|
|
49
|
+
* @returns The number of deleted installations (0 or 1)
|
|
50
|
+
*/
|
|
51
|
+
deleteByInstallationId(installationId: number): Promise<number>;
|
|
52
|
+
}
|
|
53
|
+
export default GitHubInstallationRepo;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const flink_1 = require("@flink-app/flink");
|
|
4
|
+
/**
|
|
5
|
+
* Repository for managing GitHub App installations.
|
|
6
|
+
* Stores installation-to-user mappings and repository access information.
|
|
7
|
+
*/
|
|
8
|
+
class GitHubInstallationRepo extends flink_1.FlinkRepo {
|
|
9
|
+
constructor(ctx, db, collectionName = "github_installations") {
|
|
10
|
+
super(collectionName, db);
|
|
11
|
+
this.ctx = ctx;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Find an installation by user ID and installation ID.
|
|
15
|
+
* @param userId - The application user ID
|
|
16
|
+
* @param installationId - The GitHub installation ID
|
|
17
|
+
* @returns The installation if found, null otherwise
|
|
18
|
+
*/
|
|
19
|
+
async findByUserAndInstallationId(userId, installationId) {
|
|
20
|
+
return this.getOne({ userId, installationId });
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Find all installations for a specific user.
|
|
24
|
+
* @param userId - The application user ID
|
|
25
|
+
* @returns Array of installations for the user
|
|
26
|
+
*/
|
|
27
|
+
async findByUserId(userId) {
|
|
28
|
+
return this.findAll({ userId });
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Find an installation by its GitHub installation ID.
|
|
32
|
+
* @param installationId - The GitHub installation ID
|
|
33
|
+
* @returns The installation if found, null otherwise
|
|
34
|
+
*/
|
|
35
|
+
async findByInstallationId(installationId) {
|
|
36
|
+
return this.getOne({ installationId });
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Update the repositories list for an installation.
|
|
40
|
+
* @param installationId - The GitHub installation ID
|
|
41
|
+
* @param repositories - The new repositories list
|
|
42
|
+
* @returns The updated installation
|
|
43
|
+
*/
|
|
44
|
+
async updateRepositories(installationId, repositories) {
|
|
45
|
+
const installation = await this.getOne({ installationId });
|
|
46
|
+
if (!installation) {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
const updated = await this.updateOne(installation._id, {
|
|
50
|
+
repositories,
|
|
51
|
+
updatedAt: new Date(),
|
|
52
|
+
});
|
|
53
|
+
return updated;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Suspend an installation.
|
|
57
|
+
* @param installationId - The GitHub installation ID
|
|
58
|
+
* @param suspendedBy - Information about who suspended the installation
|
|
59
|
+
* @returns The updated installation
|
|
60
|
+
*/
|
|
61
|
+
async suspend(installationId, suspendedBy) {
|
|
62
|
+
const installation = await this.getOne({ installationId });
|
|
63
|
+
if (!installation) {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
const updated = await this.updateOne(installation._id, {
|
|
67
|
+
suspendedAt: new Date(),
|
|
68
|
+
suspendedBy,
|
|
69
|
+
updatedAt: new Date(),
|
|
70
|
+
});
|
|
71
|
+
return updated;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Delete an installation by its GitHub installation ID.
|
|
75
|
+
* @param installationId - The GitHub installation ID
|
|
76
|
+
* @returns The number of deleted installations (0 or 1)
|
|
77
|
+
*/
|
|
78
|
+
async deleteByInstallationId(installationId) {
|
|
79
|
+
const { deletedCount } = await this.collection.deleteOne({ installationId });
|
|
80
|
+
return deletedCount || 0;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
exports.default = GitHubInstallationRepo;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { FlinkRepo } from "@flink-app/flink";
|
|
2
|
+
import { Db } from "mongodb";
|
|
3
|
+
import WebhookEvent from "../schemas/WebhookEvent";
|
|
4
|
+
/**
|
|
5
|
+
* Repository for managing GitHub webhook events.
|
|
6
|
+
* Only used if logWebhookEvents config option is enabled.
|
|
7
|
+
* Provides webhook event logging for debugging and auditing.
|
|
8
|
+
*/
|
|
9
|
+
declare class GitHubWebhookEventRepo extends FlinkRepo<any, WebhookEvent> {
|
|
10
|
+
constructor(ctx: any, db: Db, collectionName?: string);
|
|
11
|
+
/**
|
|
12
|
+
* Find all unprocessed webhook events.
|
|
13
|
+
* @returns Array of unprocessed events
|
|
14
|
+
*/
|
|
15
|
+
findUnprocessed(): Promise<WebhookEvent[]>;
|
|
16
|
+
/**
|
|
17
|
+
* Mark a webhook event as processed.
|
|
18
|
+
* @param eventId - The webhook event ID
|
|
19
|
+
* @returns The updated event
|
|
20
|
+
*/
|
|
21
|
+
markProcessed(eventId: string): Promise<WebhookEvent | null>;
|
|
22
|
+
/**
|
|
23
|
+
* Find all webhook events for a specific installation.
|
|
24
|
+
* @param installationId - The GitHub installation ID
|
|
25
|
+
* @returns Array of webhook events for the installation
|
|
26
|
+
*/
|
|
27
|
+
findByInstallationId(installationId: number): Promise<WebhookEvent[]>;
|
|
28
|
+
}
|
|
29
|
+
export default GitHubWebhookEventRepo;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const flink_1 = require("@flink-app/flink");
|
|
4
|
+
/**
|
|
5
|
+
* Repository for managing GitHub webhook events.
|
|
6
|
+
* Only used if logWebhookEvents config option is enabled.
|
|
7
|
+
* Provides webhook event logging for debugging and auditing.
|
|
8
|
+
*/
|
|
9
|
+
class GitHubWebhookEventRepo extends flink_1.FlinkRepo {
|
|
10
|
+
constructor(ctx, db, collectionName = "github_webhook_events") {
|
|
11
|
+
super(collectionName, db);
|
|
12
|
+
this.ctx = ctx;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Find all unprocessed webhook events.
|
|
16
|
+
* @returns Array of unprocessed events
|
|
17
|
+
*/
|
|
18
|
+
async findUnprocessed() {
|
|
19
|
+
return this.findAll({ processed: false });
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Mark a webhook event as processed.
|
|
23
|
+
* @param eventId - The webhook event ID
|
|
24
|
+
* @returns The updated event
|
|
25
|
+
*/
|
|
26
|
+
async markProcessed(eventId) {
|
|
27
|
+
const updated = await this.updateOne(eventId, {
|
|
28
|
+
processed: true,
|
|
29
|
+
processedAt: new Date(),
|
|
30
|
+
});
|
|
31
|
+
return updated;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Find all webhook events for a specific installation.
|
|
35
|
+
* @param installationId - The GitHub installation ID
|
|
36
|
+
* @returns Array of webhook events for the installation
|
|
37
|
+
*/
|
|
38
|
+
async findByInstallationId(installationId) {
|
|
39
|
+
return this.findAll({ installationId });
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.default = GitHubWebhookEventRepo;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Temporary session storage for GitHub App installation flow.
|
|
3
|
+
* Used for CSRF protection via state parameter.
|
|
4
|
+
* Sessions automatically expire after TTL (default 10 minutes).
|
|
5
|
+
*/
|
|
6
|
+
export default interface GitHubAppSession {
|
|
7
|
+
_id?: string;
|
|
8
|
+
sessionId: string;
|
|
9
|
+
state: string;
|
|
10
|
+
userId?: string;
|
|
11
|
+
metadata?: Record<string, any>;
|
|
12
|
+
createdAt: Date;
|
|
13
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GitHub App installation data linked to a user.
|
|
3
|
+
* Stores which repositories the user granted access to and installation metadata.
|
|
4
|
+
*/
|
|
5
|
+
export default interface GitHubInstallation {
|
|
6
|
+
_id?: string;
|
|
7
|
+
userId: string;
|
|
8
|
+
installationId: number;
|
|
9
|
+
accountId: number;
|
|
10
|
+
accountLogin: string;
|
|
11
|
+
accountType: 'User' | 'Organization';
|
|
12
|
+
avatarUrl?: string;
|
|
13
|
+
repositories: {
|
|
14
|
+
id: number;
|
|
15
|
+
name: string;
|
|
16
|
+
fullName: string;
|
|
17
|
+
private: boolean;
|
|
18
|
+
}[];
|
|
19
|
+
permissions: Record<string, string>;
|
|
20
|
+
events: string[];
|
|
21
|
+
suspendedAt?: Date;
|
|
22
|
+
suspendedBy?: {
|
|
23
|
+
id: number;
|
|
24
|
+
login: string;
|
|
25
|
+
};
|
|
26
|
+
createdAt: Date;
|
|
27
|
+
updatedAt: Date;
|
|
28
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Query parameters received from GitHub after app installation.
|
|
3
|
+
*/
|
|
4
|
+
export default interface InstallationCallbackRequest {
|
|
5
|
+
installation_id: string;
|
|
6
|
+
setup_action: 'install' | 'update' | 'request';
|
|
7
|
+
state: string;
|
|
8
|
+
code?: string;
|
|
9
|
+
[key: string]: string | undefined;
|
|
10
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Optional webhook event logging for debugging and auditing.
|
|
3
|
+
* Only stored if logWebhookEvents config option is enabled.
|
|
4
|
+
*/
|
|
5
|
+
export default interface WebhookEvent {
|
|
6
|
+
_id?: string;
|
|
7
|
+
installationId: number;
|
|
8
|
+
event: string;
|
|
9
|
+
action?: string;
|
|
10
|
+
deliveryId: string;
|
|
11
|
+
payload: Record<string, any>;
|
|
12
|
+
processed: boolean;
|
|
13
|
+
processedAt?: Date;
|
|
14
|
+
error?: string;
|
|
15
|
+
createdAt: Date;
|
|
16
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic webhook event payload structure from GitHub.
|
|
3
|
+
* Contains common fields; specific events may have additional fields.
|
|
4
|
+
*/
|
|
5
|
+
export default interface WebhookPayload {
|
|
6
|
+
action?: string;
|
|
7
|
+
installation?: {
|
|
8
|
+
id: number;
|
|
9
|
+
account: {
|
|
10
|
+
id: number;
|
|
11
|
+
login: string;
|
|
12
|
+
type: 'User' | 'Organization';
|
|
13
|
+
avatar_url?: string;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
repositories?: {
|
|
17
|
+
id: number;
|
|
18
|
+
name: string;
|
|
19
|
+
full_name: string;
|
|
20
|
+
private: boolean;
|
|
21
|
+
}[];
|
|
22
|
+
repository?: {
|
|
23
|
+
id: number;
|
|
24
|
+
name: string;
|
|
25
|
+
full_name: string;
|
|
26
|
+
private: boolean;
|
|
27
|
+
owner: {
|
|
28
|
+
login: string;
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
sender?: {
|
|
32
|
+
id: number;
|
|
33
|
+
login: string;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GitHub API Client
|
|
3
|
+
*
|
|
4
|
+
* Wrapper for GitHub API calls with automatic token injection,
|
|
5
|
+
* retry logic, and error handling.
|
|
6
|
+
*/
|
|
7
|
+
import { GitHubAuthService } from "./GitHubAuthService";
|
|
8
|
+
/**
|
|
9
|
+
* Repository data structure
|
|
10
|
+
*/
|
|
11
|
+
export interface Repository {
|
|
12
|
+
id: number;
|
|
13
|
+
name: string;
|
|
14
|
+
full_name: string;
|
|
15
|
+
private: boolean;
|
|
16
|
+
owner: {
|
|
17
|
+
login: string;
|
|
18
|
+
id: number;
|
|
19
|
+
};
|
|
20
|
+
html_url: string;
|
|
21
|
+
description?: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Content data structure
|
|
25
|
+
*/
|
|
26
|
+
export interface Content {
|
|
27
|
+
name: string;
|
|
28
|
+
path: string;
|
|
29
|
+
sha: string;
|
|
30
|
+
size: number;
|
|
31
|
+
url: string;
|
|
32
|
+
html_url: string;
|
|
33
|
+
git_url: string;
|
|
34
|
+
download_url?: string;
|
|
35
|
+
type: "file" | "dir" | "symlink" | "submodule";
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Issue data structure
|
|
39
|
+
*/
|
|
40
|
+
export interface Issue {
|
|
41
|
+
id: number;
|
|
42
|
+
number: number;
|
|
43
|
+
title: string;
|
|
44
|
+
body?: string;
|
|
45
|
+
state: "open" | "closed";
|
|
46
|
+
html_url: string;
|
|
47
|
+
user: {
|
|
48
|
+
login: string;
|
|
49
|
+
id: number;
|
|
50
|
+
};
|
|
51
|
+
created_at: string;
|
|
52
|
+
updated_at: string;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Create issue parameters
|
|
56
|
+
*/
|
|
57
|
+
export interface CreateIssueParams {
|
|
58
|
+
title: string;
|
|
59
|
+
body?: string;
|
|
60
|
+
assignees?: string[];
|
|
61
|
+
labels?: string[];
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* GitHub API Client
|
|
65
|
+
*
|
|
66
|
+
* Provides wrapper methods for common GitHub API operations with:
|
|
67
|
+
* - Automatic token injection
|
|
68
|
+
* - Retry logic with exponential backoff for rate limits
|
|
69
|
+
* - Error handling and transformation
|
|
70
|
+
*/
|
|
71
|
+
export declare class GitHubAPIClient {
|
|
72
|
+
private installationId;
|
|
73
|
+
private authService;
|
|
74
|
+
private baseUrl;
|
|
75
|
+
private maxRetries;
|
|
76
|
+
private retryDelayMs;
|
|
77
|
+
/**
|
|
78
|
+
* Create GitHub API Client
|
|
79
|
+
*
|
|
80
|
+
* @param installationId - GitHub installation ID
|
|
81
|
+
* @param authService - GitHub Auth Service instance
|
|
82
|
+
* @param baseUrl - GitHub API base URL (default: https://api.github.com)
|
|
83
|
+
*/
|
|
84
|
+
constructor(installationId: number, authService: GitHubAuthService, baseUrl?: string);
|
|
85
|
+
/**
|
|
86
|
+
* Generic API request method with automatic token injection
|
|
87
|
+
*
|
|
88
|
+
* @param method - HTTP method (GET, POST, PUT, DELETE)
|
|
89
|
+
* @param endpoint - API endpoint (e.g., "/repos/owner/repo")
|
|
90
|
+
* @param data - Request body data (for POST, PUT)
|
|
91
|
+
* @param retryCount - Current retry attempt (internal use)
|
|
92
|
+
* @returns Response data
|
|
93
|
+
* @throws Error if request fails after retries
|
|
94
|
+
*/
|
|
95
|
+
request<T = any>(method: "GET" | "POST" | "PUT" | "DELETE", endpoint: string, data?: any, retryCount?: number): Promise<T>;
|
|
96
|
+
/**
|
|
97
|
+
* Get repositories accessible by this installation
|
|
98
|
+
*
|
|
99
|
+
* @returns Array of repositories
|
|
100
|
+
*/
|
|
101
|
+
getRepositories(): Promise<Repository[]>;
|
|
102
|
+
/**
|
|
103
|
+
* Get repository details
|
|
104
|
+
*
|
|
105
|
+
* @param owner - Repository owner (user or org)
|
|
106
|
+
* @param repo - Repository name
|
|
107
|
+
* @returns Repository details
|
|
108
|
+
*/
|
|
109
|
+
getRepository(owner: string, repo: string): Promise<Repository>;
|
|
110
|
+
/**
|
|
111
|
+
* Get repository contents
|
|
112
|
+
*
|
|
113
|
+
* @param owner - Repository owner
|
|
114
|
+
* @param repo - Repository name
|
|
115
|
+
* @param path - File or directory path
|
|
116
|
+
* @returns Content array (for directories) or single content (for files)
|
|
117
|
+
*/
|
|
118
|
+
getContents(owner: string, repo: string, path: string): Promise<Content | Content[]>;
|
|
119
|
+
/**
|
|
120
|
+
* Create an issue
|
|
121
|
+
*
|
|
122
|
+
* @param owner - Repository owner
|
|
123
|
+
* @param repo - Repository name
|
|
124
|
+
* @param params - Issue creation parameters
|
|
125
|
+
* @returns Created issue
|
|
126
|
+
*/
|
|
127
|
+
createIssue(owner: string, repo: string, params: CreateIssueParams): Promise<Issue>;
|
|
128
|
+
/**
|
|
129
|
+
* Sleep utility for retry delays
|
|
130
|
+
*
|
|
131
|
+
* @param ms - Milliseconds to sleep
|
|
132
|
+
* @private
|
|
133
|
+
*/
|
|
134
|
+
private sleep;
|
|
135
|
+
/**
|
|
136
|
+
* Determine if error should trigger retry
|
|
137
|
+
*
|
|
138
|
+
* @param error - Error to check
|
|
139
|
+
* @returns true if should retry
|
|
140
|
+
* @private
|
|
141
|
+
*/
|
|
142
|
+
private shouldRetry;
|
|
143
|
+
}
|