@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.
Files changed (96) hide show
  1. package/CHANGELOG.md +209 -0
  2. package/LICENSE +21 -0
  3. package/README.md +667 -0
  4. package/SECURITY.md +498 -0
  5. package/dist/GitHubAppInternalContext.d.ts +44 -0
  6. package/dist/GitHubAppInternalContext.js +2 -0
  7. package/dist/GitHubAppPlugin.d.ts +45 -0
  8. package/dist/GitHubAppPlugin.js +367 -0
  9. package/dist/GitHubAppPluginContext.d.ts +242 -0
  10. package/dist/GitHubAppPluginContext.js +2 -0
  11. package/dist/GitHubAppPluginOptions.d.ts +369 -0
  12. package/dist/GitHubAppPluginOptions.js +2 -0
  13. package/dist/handlers/InitiateInstallation.d.ts +32 -0
  14. package/dist/handlers/InitiateInstallation.js +66 -0
  15. package/dist/handlers/InstallationCallback.d.ts +42 -0
  16. package/dist/handlers/InstallationCallback.js +248 -0
  17. package/dist/handlers/UninstallHandler.d.ts +37 -0
  18. package/dist/handlers/UninstallHandler.js +153 -0
  19. package/dist/handlers/WebhookHandler.d.ts +54 -0
  20. package/dist/handlers/WebhookHandler.js +157 -0
  21. package/dist/index.d.ts +19 -0
  22. package/dist/index.js +23 -0
  23. package/dist/repos/GitHubAppSessionRepo.d.ts +24 -0
  24. package/dist/repos/GitHubAppSessionRepo.js +32 -0
  25. package/dist/repos/GitHubInstallationRepo.d.ts +53 -0
  26. package/dist/repos/GitHubInstallationRepo.js +83 -0
  27. package/dist/repos/GitHubWebhookEventRepo.d.ts +29 -0
  28. package/dist/repos/GitHubWebhookEventRepo.js +42 -0
  29. package/dist/schemas/GitHubAppSession.d.ts +13 -0
  30. package/dist/schemas/GitHubAppSession.js +2 -0
  31. package/dist/schemas/GitHubInstallation.d.ts +28 -0
  32. package/dist/schemas/GitHubInstallation.js +2 -0
  33. package/dist/schemas/InstallationCallbackRequest.d.ts +10 -0
  34. package/dist/schemas/InstallationCallbackRequest.js +2 -0
  35. package/dist/schemas/WebhookEvent.d.ts +16 -0
  36. package/dist/schemas/WebhookEvent.js +2 -0
  37. package/dist/schemas/WebhookPayload.d.ts +35 -0
  38. package/dist/schemas/WebhookPayload.js +2 -0
  39. package/dist/services/GitHubAPIClient.d.ts +143 -0
  40. package/dist/services/GitHubAPIClient.js +167 -0
  41. package/dist/services/GitHubAuthService.d.ts +85 -0
  42. package/dist/services/GitHubAuthService.js +160 -0
  43. package/dist/services/WebhookValidator.d.ts +93 -0
  44. package/dist/services/WebhookValidator.js +123 -0
  45. package/dist/utils/error-utils.d.ts +67 -0
  46. package/dist/utils/error-utils.js +121 -0
  47. package/dist/utils/jwt-utils.d.ts +35 -0
  48. package/dist/utils/jwt-utils.js +67 -0
  49. package/dist/utils/state-utils.d.ts +38 -0
  50. package/dist/utils/state-utils.js +74 -0
  51. package/dist/utils/token-cache-utils.d.ts +47 -0
  52. package/dist/utils/token-cache-utils.js +74 -0
  53. package/dist/utils/webhook-signature-utils.d.ts +22 -0
  54. package/dist/utils/webhook-signature-utils.js +57 -0
  55. package/examples/basic-installation.ts +246 -0
  56. package/examples/create-issue.ts +392 -0
  57. package/examples/error-handling.ts +396 -0
  58. package/examples/multi-event-webhook.ts +367 -0
  59. package/examples/organization-installation.ts +316 -0
  60. package/examples/repository-access.ts +480 -0
  61. package/examples/webhook-handling.ts +343 -0
  62. package/examples/with-jwt-auth.ts +319 -0
  63. package/package.json +41 -0
  64. package/spec/core-utilities.spec.ts +243 -0
  65. package/spec/handlers.spec.ts +216 -0
  66. package/spec/helpers/reporter.ts +41 -0
  67. package/spec/integration-and-security.spec.ts +483 -0
  68. package/spec/plugin-core.spec.ts +258 -0
  69. package/spec/project-setup.spec.ts +56 -0
  70. package/spec/repos-and-schemas.spec.ts +288 -0
  71. package/spec/services.spec.ts +108 -0
  72. package/spec/support/jasmine.json +7 -0
  73. package/src/GitHubAppPlugin.ts +411 -0
  74. package/src/GitHubAppPluginContext.ts +254 -0
  75. package/src/GitHubAppPluginOptions.ts +412 -0
  76. package/src/handlers/InstallationCallback.ts +292 -0
  77. package/src/handlers/WebhookHandler.ts +179 -0
  78. package/src/index.ts +29 -0
  79. package/src/repos/GitHubAppSessionRepo.ts +36 -0
  80. package/src/repos/GitHubInstallationRepo.ts +95 -0
  81. package/src/repos/GitHubWebhookEventRepo.ts +48 -0
  82. package/src/schemas/GitHubAppSession.ts +13 -0
  83. package/src/schemas/GitHubInstallation.ts +28 -0
  84. package/src/schemas/InstallationCallbackRequest.ts +10 -0
  85. package/src/schemas/WebhookEvent.ts +16 -0
  86. package/src/schemas/WebhookPayload.ts +35 -0
  87. package/src/services/GitHubAPIClient.ts +244 -0
  88. package/src/services/GitHubAuthService.ts +188 -0
  89. package/src/services/WebhookValidator.ts +159 -0
  90. package/src/utils/error-utils.ts +148 -0
  91. package/src/utils/jwt-utils.ts +64 -0
  92. package/src/utils/state-utils.ts +72 -0
  93. package/src/utils/token-cache-utils.ts +89 -0
  94. package/src/utils/webhook-signature-utils.ts +57 -0
  95. package/tsconfig.dist.json +4 -0
  96. package/tsconfig.json +24 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,209 @@
1
+ # Changelog
2
+
3
+ All notable changes to the GitHub App Plugin will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [0.1.0-alpha.1] - 2025-10-26
9
+
10
+ ### Added
11
+
12
+ #### Core Features
13
+ - GitHub App installation flow with CSRF protection using state parameter
14
+ - JWT signing with RSA private key (RS256 algorithm)
15
+ - Automatic detection of PKCS#1 and PKCS#8 private key formats
16
+ - Installation access token management with automatic caching (55-minute TTL)
17
+ - Automatic token refresh when expired
18
+ - Webhook integration with HMAC-SHA256 signature validation
19
+ - Constant-time comparison for security-critical validations
20
+ - GitHub API client wrapper with automatic token injection
21
+ - Repository access verification
22
+ - Standalone plugin architecture (works without JWT Auth Plugin)
23
+
24
+ #### Database
25
+ - `GitHubAppSessionRepo` for CSRF session storage with TTL index (default: 10 minutes)
26
+ - `GitHubInstallationRepo` for installation-to-user mappings
27
+ - `GitHubWebhookEventRepo` for optional webhook event logging
28
+ - Configurable collection names for all repositories
29
+ - Automatic TTL index creation for session cleanup
30
+
31
+ #### API Handlers
32
+ - `GET /github-app/install` - Initiate GitHub App installation
33
+ - `GET /github-app/callback` - Handle installation callback
34
+ - `POST /github-app/webhook` - Receive and validate webhook events
35
+ - `DELETE /github-app/installation/:id` - Uninstall GitHub App
36
+ - Optional handler registration via `registerRoutes` config option
37
+
38
+ #### Context API
39
+ - `getClient(installationId)` - Get GitHub API client for installation
40
+ - `getInstallation(userId)` - Get first installation for user
41
+ - `getInstallations(userId)` - Get all installations for user
42
+ - `deleteInstallation(userId, installationId)` - Delete installation
43
+ - `hasRepositoryAccess(userId, owner, repo)` - Verify repository access
44
+ - `getInstallationToken(installationId)` - Get raw installation token (advanced usage)
45
+ - `clearTokenCache()` - Clear all cached installation tokens
46
+ - `options` - Read-only access to plugin configuration
47
+
48
+ #### GitHub API Client Methods
49
+ - `getRepositories()` - List accessible repositories
50
+ - `getRepository(owner, repo)` - Get repository details
51
+ - `getContents(owner, repo, path)` - Get file contents
52
+ - `createIssue(owner, repo, params)` - Create GitHub issue
53
+ - `request(method, endpoint, data)` - Generic API request with retry logic
54
+
55
+ #### Configuration Options
56
+ - Required: `appId`, `privateKey`, `webhookSecret`, `clientId`, `clientSecret`
57
+ - Optional: `appSlug`, `baseUrl` (default: https://api.github.com)
58
+ - Callbacks: `onInstallationSuccess` (required), `onInstallationError`, `onWebhookEvent`
59
+ - Database: `sessionsCollectionName`, `installationsCollectionName`, `webhookEventsCollectionName`
60
+ - Cache: `tokenCacheTTL` (default: 3300 seconds), `sessionTTL` (default: 600 seconds)
61
+ - Features: `registerRoutes` (default: true), `logWebhookEvents` (default: false)
62
+
63
+ #### Security Features
64
+ - Private key validation on plugin initialization
65
+ - CSRF protection with cryptographically secure state parameter (32 bytes)
66
+ - Webhook signature validation using HMAC-SHA256
67
+ - Constant-time comparison for state and signature validation
68
+ - Installation tokens cached in memory only (never in database)
69
+ - One-time use sessions (deleted after successful callback)
70
+ - Automatic session expiration via MongoDB TTL indexes
71
+
72
+ #### Error Handling
73
+ - Kebab-case error codes for frontend translation
74
+ - Comprehensive error codes: `invalid-state`, `session-expired`, `installation-not-found`, `invalid-private-key`, `jwt-signing-failed`, `token-exchange-failed`, `webhook-signature-invalid`, `webhook-payload-invalid`, `repository-not-accessible`, `installation-suspended`, `installation-not-owned`, `api-rate-limit`, `network-error`, `server-error`
75
+ - User-friendly error messages with actionable hints
76
+ - Detailed error logging for debugging
77
+ - Graceful handling of GitHub API failures
78
+ - Retry logic with exponential backoff for rate limits
79
+
80
+ #### Documentation
81
+ - Comprehensive README.md with step-by-step guides
82
+ - SECURITY.md covering all security considerations
83
+ - 8 complete usage examples:
84
+ - `basic-installation.ts` - Basic GitHub App installation with standalone auth
85
+ - `webhook-handling.ts` - Process webhook events (push, PR, installation)
86
+ - `repository-access.ts` - Access repositories via API client
87
+ - `create-issue.ts` - Create GitHub issue with permission check
88
+ - `with-jwt-auth.ts` - Optional integration with JWT Auth Plugin
89
+ - `organization-installation.ts` - Organization-level installation
90
+ - `error-handling.ts` - Comprehensive error handling
91
+ - `multi-event-webhook.ts` - Handle multiple webhook event types
92
+ - JSDoc comments on all public interfaces
93
+ - TypeScript type exports for all schemas and interfaces
94
+
95
+ #### Testing
96
+ - Project initialization tests
97
+ - Schema and repository tests
98
+ - JWT utilities tests (PKCS#1 and PKCS#8 support)
99
+ - Webhook signature validation tests
100
+ - Token cache tests
101
+ - Error utilities tests
102
+ - Authentication service tests
103
+ - API client tests
104
+ - Handler tests (installation flow, callbacks, webhooks)
105
+ - Plugin initialization tests
106
+ - Integration tests for end-to-end flows
107
+ - Security tests for CSRF and signature validation
108
+
109
+ ### Features Highlights
110
+
111
+ #### Standalone Architecture
112
+ - **No dependencies on JWT Auth Plugin** - Works with any authentication system
113
+ - Plugin agnostic about authentication mechanism
114
+ - Developers can use sessions, custom tokens, or any auth system
115
+ - Optional integration with JWT Auth Plugin available
116
+
117
+ #### Token Management
118
+ - **Automatic caching** - Reduces GitHub API calls
119
+ - **Smart expiration** - Caches for 55 minutes (tokens expire at 60 minutes)
120
+ - **Automatic refresh** - Seamless token renewal
121
+ - **Memory-only storage** - Enhanced security
122
+
123
+ #### Webhook Security
124
+ - **Signature validation** - HMAC-SHA256 with constant-time comparison
125
+ - **Automatic validation** - No manual verification needed
126
+ - **Rejection of invalid webhooks** - Returns 401 for invalid signatures
127
+
128
+ #### Developer Experience
129
+ - **TypeScript-first** - Full type safety
130
+ - **Auto-registration** - Handlers, repos, and jobs automatically registered
131
+ - **Comprehensive examples** - 8 working examples covering all use cases
132
+ - **Clear error messages** - Actionable error codes with hints
133
+ - **Flexible configuration** - Sensible defaults, customizable when needed
134
+
135
+ ### Known Limitations
136
+
137
+ - Single GitHub App per Flink application (multi-tenant support deferred to future)
138
+ - No proactive token refresh before expiration (refreshes on-demand when expired)
139
+ - GitHub Enterprise Server support via `baseUrl` option but not explicitly tested
140
+ - No GraphQL API support (REST API only)
141
+ - No advanced rate limit handling with queuing (basic retry logic included)
142
+ - No webhook event replay mechanism
143
+ - No repository permission auditing features
144
+
145
+ ### Breaking Changes
146
+
147
+ None (initial release)
148
+
149
+ ### Migration Guide
150
+
151
+ Not applicable (initial release)
152
+
153
+ ### Deprecations
154
+
155
+ None (initial release)
156
+
157
+ ## Roadmap
158
+
159
+ ### Planned for v0.2.0
160
+ - Multi-tenant support (multiple GitHub Apps per Flink application)
161
+ - Proactive token refresh before expiration
162
+ - Enhanced rate limit handling with request queuing
163
+ - Webhook event replay mechanism for failed deliveries
164
+ - GitHub Actions integration
165
+ - GraphQL API support
166
+
167
+ ### Planned for v0.3.0
168
+ - Repository permission auditing
169
+ - Installation analytics and reporting
170
+ - Batch operations for multiple repositories
171
+ - Advanced webhook event filtering
172
+ - Custom event processors registry
173
+ - Webhook event transformation pipeline
174
+
175
+ ### Planned for v1.0.0
176
+ - Production-ready stability
177
+ - Comprehensive GitHub Enterprise Server testing
178
+ - Performance optimizations
179
+ - Advanced caching strategies
180
+ - Complete test coverage (>90%)
181
+ - Security audit and hardening
182
+
183
+ ### Future Considerations
184
+ - GitHub Packages integration
185
+ - Container Registry support
186
+ - Deployment status integration
187
+ - Check runs and check suites support
188
+ - Team management features
189
+ - Marketplace integration
190
+
191
+ ## Support
192
+
193
+ - **Documentation:** [README.md](./README.md)
194
+ - **Security:** [SECURITY.md](./SECURITY.md)
195
+ - **Examples:** [examples/](./examples/)
196
+ - **Issues:** [GitHub Issues](https://github.com/your-org/flink-framework/issues)
197
+ - **Discussions:** [GitHub Discussions](https://github.com/your-org/flink-framework/discussions)
198
+
199
+ ## Contributing
200
+
201
+ We welcome contributions! Please see our [Contributing Guide](../../CONTRIBUTING.md) for details.
202
+
203
+ ## License
204
+
205
+ MIT
206
+
207
+ ---
208
+
209
+ [0.1.0-alpha.1]: https://github.com/your-org/flink-framework/releases/tag/github-app-plugin-v0.1.0-alpha.1
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) Frost Experience AB https://www.frost.se
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.