@hyperdrive.bot/cli 1.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.
Files changed (127) hide show
  1. package/README.md +1598 -0
  2. package/bin/dev.cmd +3 -0
  3. package/bin/dev.js +3 -0
  4. package/bin/run.cmd +3 -0
  5. package/bin/run.js +5 -0
  6. package/dist/commands/account/add.d.ts +16 -0
  7. package/dist/commands/account/add.js +185 -0
  8. package/dist/commands/account/list.d.ts +6 -0
  9. package/dist/commands/account/list.js +37 -0
  10. package/dist/commands/account/remove.d.ts +11 -0
  11. package/dist/commands/account/remove.js +57 -0
  12. package/dist/commands/auth/login.d.ts +16 -0
  13. package/dist/commands/auth/login.js +178 -0
  14. package/dist/commands/auth/logout.d.ts +6 -0
  15. package/dist/commands/auth/logout.js +39 -0
  16. package/dist/commands/auth/refresh.d.ts +6 -0
  17. package/dist/commands/auth/refresh.js +66 -0
  18. package/dist/commands/auth/status.d.ts +6 -0
  19. package/dist/commands/auth/status.js +63 -0
  20. package/dist/commands/ci/account/create.d.ts +16 -0
  21. package/dist/commands/ci/account/create.js +158 -0
  22. package/dist/commands/ci/account/delete.d.ts +14 -0
  23. package/dist/commands/ci/account/delete.js +88 -0
  24. package/dist/commands/ci/account/list.d.ts +10 -0
  25. package/dist/commands/ci/account/list.js +65 -0
  26. package/dist/commands/config/get.d.ts +9 -0
  27. package/dist/commands/config/get.js +37 -0
  28. package/dist/commands/config/set.d.ts +10 -0
  29. package/dist/commands/config/set.js +48 -0
  30. package/dist/commands/config/show.d.ts +6 -0
  31. package/dist/commands/config/show.js +10 -0
  32. package/dist/commands/deployment/create.d.ts +30 -0
  33. package/dist/commands/deployment/create.js +188 -0
  34. package/dist/commands/deployment/get.d.ts +13 -0
  35. package/dist/commands/deployment/get.js +101 -0
  36. package/dist/commands/deployment/launch.d.ts +15 -0
  37. package/dist/commands/deployment/launch.js +105 -0
  38. package/dist/commands/deployment/list.d.ts +11 -0
  39. package/dist/commands/deployment/list.js +91 -0
  40. package/dist/commands/domain/current.d.ts +6 -0
  41. package/dist/commands/domain/current.js +18 -0
  42. package/dist/commands/domain/list.d.ts +6 -0
  43. package/dist/commands/domain/list.js +42 -0
  44. package/dist/commands/domain/switch.d.ts +9 -0
  45. package/dist/commands/domain/switch.js +40 -0
  46. package/dist/commands/example.d.ts +13 -0
  47. package/dist/commands/example.js +24 -0
  48. package/dist/commands/git/connect.d.ts +10 -0
  49. package/dist/commands/git/connect.js +56 -0
  50. package/dist/commands/git/disconnect.d.ts +11 -0
  51. package/dist/commands/git/disconnect.js +93 -0
  52. package/dist/commands/git/list.d.ts +10 -0
  53. package/dist/commands/git/list.js +53 -0
  54. package/dist/commands/git/sync.d.ts +18 -0
  55. package/dist/commands/git/sync.js +235 -0
  56. package/dist/commands/init.d.ts +188 -0
  57. package/dist/commands/init.js +817 -0
  58. package/dist/commands/jira/connect.d.ts +9 -0
  59. package/dist/commands/jira/connect.js +141 -0
  60. package/dist/commands/jira/status.d.ts +9 -0
  61. package/dist/commands/jira/status.js +118 -0
  62. package/dist/commands/module/analyze.d.ts +29 -0
  63. package/dist/commands/module/analyze.js +201 -0
  64. package/dist/commands/module/create.d.ts +42 -0
  65. package/dist/commands/module/create.js +498 -0
  66. package/dist/commands/module/destroy.d.ts +11 -0
  67. package/dist/commands/module/destroy.js +77 -0
  68. package/dist/commands/module/get.d.ts +10 -0
  69. package/dist/commands/module/get.js +43 -0
  70. package/dist/commands/module/link.d.ts +15 -0
  71. package/dist/commands/module/link.js +175 -0
  72. package/dist/commands/module/list.d.ts +9 -0
  73. package/dist/commands/module/list.js +51 -0
  74. package/dist/commands/module/reanalyze.d.ts +30 -0
  75. package/dist/commands/module/reanalyze.js +206 -0
  76. package/dist/commands/module/update.d.ts +27 -0
  77. package/dist/commands/module/update.js +102 -0
  78. package/dist/commands/parameter/add.d.ts +15 -0
  79. package/dist/commands/parameter/add.js +99 -0
  80. package/dist/commands/parameter/backfill.d.ts +12 -0
  81. package/dist/commands/parameter/backfill.js +113 -0
  82. package/dist/commands/parameter/clear.d.ts +14 -0
  83. package/dist/commands/parameter/clear.js +95 -0
  84. package/dist/commands/parameter/list.d.ts +14 -0
  85. package/dist/commands/parameter/list.js +92 -0
  86. package/dist/commands/parameter/pull.d.ts +14 -0
  87. package/dist/commands/parameter/pull.js +124 -0
  88. package/dist/commands/parameter/remove.d.ts +15 -0
  89. package/dist/commands/parameter/remove.js +90 -0
  90. package/dist/commands/parameter/sync.d.ts +14 -0
  91. package/dist/commands/parameter/sync.js +153 -0
  92. package/dist/commands/parameter/update.d.ts +15 -0
  93. package/dist/commands/parameter/update.js +100 -0
  94. package/dist/commands/stage/create.d.ts +28 -0
  95. package/dist/commands/stage/create.js +312 -0
  96. package/dist/commands/stage/list.d.ts +9 -0
  97. package/dist/commands/stage/list.js +63 -0
  98. package/dist/commands/test-api.d.ts +9 -0
  99. package/dist/commands/test-api.js +40 -0
  100. package/dist/index.d.ts +1 -0
  101. package/dist/index.js +1 -0
  102. package/dist/services/auth-service.d.ts +84 -0
  103. package/dist/services/auth-service.js +240 -0
  104. package/dist/services/git.d.ts +46 -0
  105. package/dist/services/git.js +409 -0
  106. package/dist/services/hyperdrive-sigv4.d.ts +449 -0
  107. package/dist/services/hyperdrive-sigv4.js +375 -0
  108. package/dist/services/hyperdrive.d.ts +87 -0
  109. package/dist/services/hyperdrive.js +108 -0
  110. package/dist/services/log-tailer.d.ts +95 -0
  111. package/dist/services/log-tailer.js +242 -0
  112. package/dist/services/tenant-service.d.ts +106 -0
  113. package/dist/services/tenant-service.js +332 -0
  114. package/dist/utils/account-flow.d.ts +74 -0
  115. package/dist/utils/account-flow.js +228 -0
  116. package/dist/utils/auth-flow.d.ts +146 -0
  117. package/dist/utils/auth-flow.js +477 -0
  118. package/dist/utils/git-flow.d.ts +72 -0
  119. package/dist/utils/git-flow.js +232 -0
  120. package/dist/utils/jira-flow.d.ts +71 -0
  121. package/dist/utils/jira-flow.js +120 -0
  122. package/dist/utils/summary-display.d.ts +59 -0
  123. package/dist/utils/summary-display.js +140 -0
  124. package/dist/utils/validation.d.ts +15 -0
  125. package/dist/utils/validation.js +32 -0
  126. package/oclif.manifest.json +2819 -0
  127. package/package.json +112 -0
@@ -0,0 +1,240 @@
1
+ import { CognitoIdentityClient, GetCredentialsForIdentityCommand, GetIdCommand } from '@aws-sdk/client-cognito-identity';
2
+ import axios from 'axios';
3
+ import { existsSync, mkdirSync, readFileSync, unlinkSync, writeFileSync } from 'fs';
4
+ import { homedir } from 'os';
5
+ import { join } from 'path';
6
+ export class AuthService {
7
+ cognitoConfig = {
8
+ clientId: process.env.HYPERDRIVE_COGNITO_CLIENT_ID || '',
9
+ domain: process.env.HYPERDRIVE_COGNITO_DOMAIN || 'hyperdrive.auth.us-east-1.amazoncognito.com',
10
+ identityPoolId: process.env.HYPERDRIVE_COGNITO_IDENTITY_POOL_ID || '',
11
+ region: process.env.HYPERDRIVE_AWS_REGION || 'us-east-1',
12
+ userPoolId: process.env.HYPERDRIVE_COGNITO_USER_POOL_ID || '',
13
+ };
14
+ credDir;
15
+ credPath;
16
+ domain;
17
+ constructor(domain) {
18
+ this.credDir = join(homedir(), '.hyperdrive');
19
+ this.domain = domain;
20
+ this.credPath = this.getCredentialsPath();
21
+ }
22
+ /**
23
+ * Clear stored credentials
24
+ */
25
+ clearCredentials() {
26
+ if (existsSync(this.credPath)) {
27
+ unlinkSync(this.credPath);
28
+ }
29
+ }
30
+ /**
31
+ * Ensure credentials are valid, refresh if needed
32
+ * Returns valid credentials or throws error
33
+ */
34
+ async ensureValidCredentials() {
35
+ const credentials = this.loadCredentials();
36
+ if (!credentials) {
37
+ throw new Error('Not authenticated. Please run "hd auth login" first.');
38
+ }
39
+ // Auto-refresh if needed
40
+ if (this.needsRefresh(credentials)) {
41
+ if (!credentials.cognitoConfig) {
42
+ throw new Error('Cognito configuration not found. Please run "hd auth login" again.');
43
+ }
44
+ console.log('⏳ Credentials expiring soon, refreshing...');
45
+ const newTokens = await this.refreshTokens(credentials.refresh_token, credentials.cognitoConfig);
46
+ const newAwsCredentials = await this.getAWSCredentials(newTokens.id_token, credentials.region, credentials.cognitoConfig);
47
+ const updatedCredentials = {
48
+ ...newTokens,
49
+ apiUrl: credentials.apiUrl,
50
+ awsCredentials: newAwsCredentials,
51
+ cognitoConfig: credentials.cognitoConfig,
52
+ obtainedAt: new Date().toISOString(),
53
+ region: credentials.region,
54
+ tenantDomain: credentials.tenantDomain,
55
+ tenantId: credentials.tenantId,
56
+ };
57
+ this.saveCredentials(updatedCredentials);
58
+ console.log('✅ Credentials refreshed automatically');
59
+ return updatedCredentials;
60
+ }
61
+ return credentials;
62
+ }
63
+ /**
64
+ * Get AWS credentials from Cognito Identity Pool using ID token
65
+ */
66
+ async getAWSCredentials(idToken, region, cognitoConfig) {
67
+ const client = new CognitoIdentityClient({ region });
68
+ try {
69
+ // Step 1: Get Identity ID
70
+ const getIdResponse = await client.send(new GetIdCommand({
71
+ IdentityPoolId: cognitoConfig.identityPoolId,
72
+ Logins: {
73
+ [`cognito-idp.${region}.amazonaws.com/${cognitoConfig.userPoolId}`]: idToken,
74
+ },
75
+ }));
76
+ if (!getIdResponse.IdentityId) {
77
+ throw new Error('Failed to get Identity ID from Cognito');
78
+ }
79
+ // Step 2: Get temporary AWS credentials
80
+ const getCredentialsResponse = await client.send(new GetCredentialsForIdentityCommand({
81
+ IdentityId: getIdResponse.IdentityId,
82
+ Logins: {
83
+ [`cognito-idp.${region}.amazonaws.com/${cognitoConfig.userPoolId}`]: idToken,
84
+ },
85
+ }));
86
+ if (!getCredentialsResponse.Credentials) {
87
+ throw new Error('Failed to get AWS credentials from Cognito');
88
+ }
89
+ const { AccessKeyId, Expiration, SecretKey, SessionToken } = getCredentialsResponse.Credentials;
90
+ if (!AccessKeyId || !SecretKey || !SessionToken || !Expiration) {
91
+ throw new Error('Incomplete AWS credentials received from Cognito');
92
+ }
93
+ return {
94
+ accessKeyId: AccessKeyId,
95
+ expiration: Expiration,
96
+ secretAccessKey: SecretKey,
97
+ sessionToken: SessionToken,
98
+ };
99
+ }
100
+ catch (error) {
101
+ if (error instanceof Error) {
102
+ throw new Error(`Failed to obtain AWS credentials: ${error.message}`);
103
+ }
104
+ throw error;
105
+ }
106
+ }
107
+ /**
108
+ * Get all domains with stored credentials
109
+ */
110
+ getCredentialDomains() {
111
+ try {
112
+ if (!existsSync(this.credDir)) {
113
+ return [];
114
+ }
115
+ const files = require('fs').readdirSync(this.credDir);
116
+ const domains = [];
117
+ for (const file of files) {
118
+ // Match files like "credentials.example.com"
119
+ const match = file.match(/^credentials\.(.+)$/);
120
+ if (match) {
121
+ domains.push(match[1]);
122
+ }
123
+ }
124
+ return domains;
125
+ }
126
+ catch (error) {
127
+ return [];
128
+ }
129
+ }
130
+ /**
131
+ * Check if credentials are expired
132
+ */
133
+ isExpired(credentials) {
134
+ const expiration = new Date(credentials.awsCredentials.expiration);
135
+ return new Date() >= expiration;
136
+ }
137
+ /**
138
+ * Load stored credentials from domain-specific path
139
+ *
140
+ * Always uses domain-specific credentials (credentials.<domain>)
141
+ * Domain is either explicitly specified or uses default domain
142
+ */
143
+ loadCredentials() {
144
+ try {
145
+ if (!existsSync(this.credPath)) {
146
+ return null;
147
+ }
148
+ const data = readFileSync(this.credPath, 'utf8');
149
+ const credentials = JSON.parse(data);
150
+ // Convert expiration string back to Date object
151
+ credentials.awsCredentials.expiration = new Date(credentials.awsCredentials.expiration);
152
+ return credentials;
153
+ }
154
+ catch (error) {
155
+ console.error('Failed to load credentials:', error);
156
+ return null;
157
+ }
158
+ }
159
+ /**
160
+ * Check if credentials need refresh
161
+ * Returns true if AWS credentials expire in less than 5 minutes
162
+ */
163
+ needsRefresh(credentials) {
164
+ const expiration = new Date(credentials.awsCredentials.expiration);
165
+ const now = new Date();
166
+ const timeUntilExpiry = expiration.getTime() - now.getTime();
167
+ const fiveMinutes = 5 * 60 * 1000;
168
+ return timeUntilExpiry < fiveMinutes;
169
+ }
170
+ /**
171
+ * Refresh Cognito tokens using refresh token
172
+ */
173
+ async refreshTokens(refreshToken, cognitoConfig) {
174
+ try {
175
+ const response = await axios.post(`https://${cognitoConfig.domain}/oauth2/token`, new URLSearchParams({
176
+ client_id: cognitoConfig.clientId,
177
+ grant_type: 'refresh_token',
178
+ refresh_token: refreshToken,
179
+ }), {
180
+ headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
181
+ });
182
+ // Cognito doesn't return a new refresh token on refresh, so we need to keep the old one
183
+ return {
184
+ ...response.data,
185
+ refresh_token: refreshToken, // Preserve original refresh token
186
+ };
187
+ }
188
+ catch (error) {
189
+ if (axios.isAxiosError(error)) {
190
+ throw new Error(`Token refresh failed: ${error.response?.data?.error_description || error.message}`);
191
+ }
192
+ throw error;
193
+ }
194
+ }
195
+ /**
196
+ * Save credentials to ~/.hyperdrive/credentials
197
+ */
198
+ saveCredentials(credentials) {
199
+ // Prevent saving test/mock credentials to production path
200
+ const testPatterns = ['test-client-id', 'us-east-1_TEST', 'test-identity', 'test.auth.amazoncognito'];
201
+ const credString = JSON.stringify(credentials);
202
+ for (const pattern of testPatterns) {
203
+ if (credString.includes(pattern)) {
204
+ throw new Error(`Refusing to save credentials containing test value: "${pattern}". This looks like test data.`);
205
+ }
206
+ }
207
+ // Ensure directory exists
208
+ if (!existsSync(this.credDir)) {
209
+ mkdirSync(this.credDir, { recursive: true });
210
+ }
211
+ // Write with secure permissions (owner read/write only)
212
+ writeFileSync(this.credPath, JSON.stringify(credentials, null, 2), { mode: 0o600 });
213
+ }
214
+ /**
215
+ * Get the credentials file path (always domain-specific)
216
+ */
217
+ getCredentialsPath() {
218
+ const domain = this.domain || this.getDefaultDomain();
219
+ if (!domain) {
220
+ throw new Error('No domain specified and no default domain configured');
221
+ }
222
+ // Domain-specific credentials: ~/.hyperdrive/credentials.{domain}
223
+ return join(this.credDir, `credentials.${domain}`);
224
+ }
225
+ /**
226
+ * Get default domain from TenantService (avoid circular dependency by reading file directly)
227
+ */
228
+ getDefaultDomain() {
229
+ try {
230
+ const defaultDomainPath = join(this.credDir, 'default-domain');
231
+ if (!existsSync(defaultDomainPath)) {
232
+ return null;
233
+ }
234
+ return readFileSync(defaultDomainPath, 'utf8').trim();
235
+ }
236
+ catch (error) {
237
+ return null;
238
+ }
239
+ }
240
+ }
@@ -0,0 +1,46 @@
1
+ export interface SyncBranchResult {
2
+ branch: string;
3
+ conflicts?: boolean;
4
+ error?: string;
5
+ success: boolean;
6
+ }
7
+ export interface SyncOptions {
8
+ all: boolean;
9
+ mergeStrategy: string;
10
+ remote: string;
11
+ sourceBranch: string;
12
+ targetBranches?: string[];
13
+ tmpDir?: string;
14
+ verbose?: boolean;
15
+ }
16
+ export declare class GitService {
17
+ private readonly DEFAULT_EXCLUDES;
18
+ branchExists(tmpProjectPath: string, branchName: string, remote: string): Promise<boolean>;
19
+ checkoutBranch(tmpProjectPath: string, branchName: string, remote: string): Promise<{
20
+ error?: string;
21
+ success: boolean;
22
+ }>;
23
+ cleanupTmpDir(tmpDir: string): Promise<void>;
24
+ copyProjectToTmp(sourcePath: string, tmpDir: string, verbose?: boolean, progressCallback?: (emoji: string, color: string, step: string) => void): Promise<void>;
25
+ createTmpDir(): Promise<string>;
26
+ fetchRemote(tmpProjectPath: string, remote: string): Promise<void>;
27
+ getAllRemoteBranches(tmpProjectPath: string, remote: string): Promise<string[]>;
28
+ getCurrentBranch(tmpProjectPath: string): Promise<string>;
29
+ mergeBranch(tmpProjectPath: string, sourceBranch: string, remote: string, mergeStrategy: string): Promise<{
30
+ error?: string;
31
+ hasConflicts: boolean;
32
+ success: boolean;
33
+ }>;
34
+ pushBranch(tmpProjectPath: string, branchName: string, remote: string): Promise<{
35
+ error?: string;
36
+ success: boolean;
37
+ }>;
38
+ syncBranches(options: SyncOptions, progressCallback?: (emoji: string, color: string, step: string) => void): Promise<SyncBranchResult[]>;
39
+ private copyDirectoryRecursive;
40
+ private copyWithExclusions;
41
+ private executeCommand;
42
+ private getExcludePatterns;
43
+ private gitignorePatternToRegex;
44
+ private parseGitignore;
45
+ private tryRsyncCopy;
46
+ }