@coralogix/rum-cli 1.1.17 → 1.1.19

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 (87) hide show
  1. package/.prettierrc +15 -0
  2. package/README.md +26 -19
  3. package/api/rum-api.ts +104 -91
  4. package/cli/commands/delete-source-maps-command.ts +34 -0
  5. package/cli/commands/index.ts +7 -0
  6. package/cli/commands/update-source-maps-command.ts +38 -0
  7. package/cli/commands/upload-source-maps-command.ts +38 -0
  8. package/cli/rum-cli.ts +13 -47
  9. package/cli/validators/index.ts +9 -10
  10. package/config/config.ts +21 -21
  11. package/consts/consts.ts +16 -0
  12. package/dist/api/rum-api.d.ts +4 -3
  13. package/dist/api/rum-api.js +60 -72
  14. package/dist/cli/commands/delete-source-maps-command.d.ts +2 -0
  15. package/dist/cli/commands/delete-source-maps-command.js +43 -0
  16. package/dist/cli/commands/index.d.ts +6 -0
  17. package/dist/cli/commands/index.js +8 -0
  18. package/dist/cli/commands/update-source-maps-command.d.ts +2 -0
  19. package/dist/cli/commands/update-source-maps-command.js +47 -0
  20. package/dist/cli/commands/upload-source-maps-command.d.ts +2 -0
  21. package/dist/cli/commands/upload-source-maps-command.js +47 -0
  22. package/dist/cli/rum-cli.js +14 -55
  23. package/dist/cli/validators/index.js +5 -6
  24. package/dist/config/config.js +6 -5
  25. package/dist/{cli/theme/index.d.ts → consts/consts.d.ts} +2 -0
  26. package/dist/consts/consts.js +16 -0
  27. package/dist/models/commands.model.d.ts +29 -0
  28. package/dist/models/commands.model.js +3 -0
  29. package/dist/proto-models/com/coralogix/rum/v2/audit_log.d.ts +1 -1
  30. package/dist/proto-models/com/coralogix/rum/v2/audit_log.js +5 -3
  31. package/dist/proto-models/com/coralogix/rum/v2/chunk.d.ts +1 -1
  32. package/dist/proto-models/com/coralogix/rum/v2/chunk.js +54 -49
  33. package/dist/proto-models/com/coralogix/rum/v2/file.d.ts +1 -1
  34. package/dist/proto-models/com/coralogix/rum/v2/file.js +24 -34
  35. package/dist/proto-models/com/coralogix/rum/v2/rum_service.d.ts +89 -2
  36. package/dist/proto-models/com/coralogix/rum/v2/rum_service.js +304 -78
  37. package/dist/proto-models/com/coralogix/rum/v2/rum_session_recording_service.d.ts +65 -0
  38. package/dist/proto-models/com/coralogix/rum/v2/rum_session_recording_service.js +174 -0
  39. package/dist/proto-models/com/coralogix/rum/v2/rum_source_map_service.d.ts +93 -1
  40. package/dist/proto-models/com/coralogix/rum/v2/rum_source_map_service.js +306 -17
  41. package/dist/proto-models/com/coralogix/rum/v2/source_code_file_mapping.d.ts +1 -1
  42. package/dist/proto-models/com/coralogix/rum/v2/source_code_file_mapping.js +47 -24
  43. package/dist/proto-models/com/coralogix/rum/v2/source_map_release.d.ts +14 -1
  44. package/dist/proto-models/com/coralogix/rum/v2/source_map_release.js +113 -33
  45. package/dist/proto-models/com/coralogix/rum/v2/template.d.ts +1 -1
  46. package/dist/proto-models/com/coralogix/rum/v2/template.js +66 -53
  47. package/dist/proto-models/google/protobuf/descriptor.d.ts +1 -1
  48. package/dist/proto-models/google/protobuf/descriptor.js +537 -427
  49. package/dist/services/source-maps.service.d.ts +5 -0
  50. package/dist/services/source-maps.service.js +80 -0
  51. package/dist/utils/index.d.ts +6 -0
  52. package/dist/utils/index.js +115 -0
  53. package/models/commands.model.ts +31 -0
  54. package/package.json +5 -3
  55. package/proto-models/com/coralogix/rum/v2/audit_log.ts +6 -4
  56. package/proto-models/com/coralogix/rum/v2/chunk.ts +55 -56
  57. package/proto-models/com/coralogix/rum/v2/file.ts +25 -39
  58. package/proto-models/com/coralogix/rum/v2/rum_service.ts +345 -89
  59. package/proto-models/com/coralogix/rum/v2/rum_session_recording_service.ts +202 -0
  60. package/proto-models/com/coralogix/rum/v2/rum_source_map_service.ts +355 -18
  61. package/proto-models/com/coralogix/rum/v2/source_code_file_mapping.ts +48 -27
  62. package/proto-models/com/coralogix/rum/v2/source_map_release.ts +126 -36
  63. package/proto-models/com/coralogix/rum/v2/template.ts +67 -60
  64. package/proto-models/google/protobuf/descriptor.ts +551 -464
  65. package/protofetch.lock +2 -2
  66. package/protofetch.toml +1 -1
  67. package/protos/com/coralogix/rum/v2/rum_service.proto +16 -1
  68. package/protos/com/coralogix/rum/v2/rum_session_recording_service.proto +15 -0
  69. package/protos/com/coralogix/rum/v2/rum_source_map_service.proto +18 -0
  70. package/protos/com/coralogix/rum/v2/source_map_release.proto +6 -0
  71. package/protoset.bin +0 -0
  72. package/services/source-maps.service.ts +96 -0
  73. package/utils/index.ts +93 -0
  74. package/cli/consts/consts.ts +0 -2
  75. package/cli/theme/index.ts +0 -5
  76. package/dist/cli/consts/consts.d.ts +0 -2
  77. package/dist/cli/consts/consts.js +0 -6
  78. package/dist/cli/theme/index.js +0 -7
  79. package/dist/model/cli.model.d.ts +0 -1
  80. package/dist/model/cli.model.js +0 -12
  81. package/dist/services/source-maps/source-maps.service.d.ts +0 -3
  82. package/dist/services/source-maps/source-maps.service.js +0 -42
  83. package/dist/services/source-maps/utils/traverse-folder.util.d.ts +0 -2
  84. package/dist/services/source-maps/utils/traverse-folder.util.js +0 -42
  85. package/model/cli.model.ts +0 -8
  86. package/services/source-maps/source-maps.service.ts +0 -31
  87. package/services/source-maps/utils/traverse-folder.util.ts +0 -33
package/.prettierrc ADDED
@@ -0,0 +1,15 @@
1
+ {
2
+ "printWidth": 140,
3
+ "tabWidth": 2,
4
+ "useTabs": false,
5
+ "semi": true,
6
+ "singleQuote": true,
7
+ "quoteProps": "preserve",
8
+ "trailingComma": "all",
9
+ "bracketSpacing": true,
10
+ "arrowParens": "avoid",
11
+ "requirePragma": false,
12
+ "insertPragma": false,
13
+ "proseWrap": "preserve",
14
+ "endOfLine": "lf"
15
+ }
package/README.md CHANGED
@@ -18,20 +18,28 @@ To install the Coralogix RUM CLI, follow these steps:
18
18
  2. Run the following command to install the CLI globally: `npm install -g coralogix-rum-cli`
19
19
  3. Once the installation is complete, you can use the CLI by running the `coralogix-rum-cli` command in your terminal.
20
20
 
21
- # Examples
21
+
22
+ ## Commands
22
23
 
23
24
  Here are some examples of how to use the Coralogix RUM CLI:
24
25
 
25
- 1. Upload source maps:
26
+ 1. Create source maps:
27
+
28
+ - `coralogix-rum-cli upload-source-maps -k <privateKey> -a <application> -v <version> -f <folderPath> -e <env> -c <commitHash> -n <repoName> -o <orgName>`
26
29
 
27
- - `coralogix-rum-cli upload-source-maps -k <privateKey> -a <application> -v <version> -f <folderPath> -e <env> -c <commitHash> -n <repoName> -o <orgName>`
30
+ 2. Delete source maps:
28
31
 
29
- 2. Display help:
32
+ - `coralogix-rum-cli delete-source-maps -k <privateKey> -a <application> -v <version> -e <env>`
30
33
 
31
- - `coralogix-rum-cli upload-source-maps --help`
34
+ 3. Update source maps:
32
35
 
33
- # Upload source maps
36
+ - `coralogix-rum-cli update-source-maps -k <privateKey> -a <application> -v <version> -f <folderPath> -e <env> -c <commitHash> -n <repoName> -o <orgName>`
34
37
 
38
+ 4. Display help for upload command:
39
+
40
+ - `coralogix-rum-cli upload-source-maps --help`
41
+
42
+
35
43
  ## Options
36
44
 
37
45
  - `-k, --private-key <privateKey>`: Private key to authenticate with the Coralogix API.
@@ -44,6 +52,18 @@ Here are some examples of how to use the Coralogix RUM CLI:
44
52
  - `-o, --org-name <orgName>`: GitHub organization name (optional).
45
53
  - `-h, --help`: Display help.
46
54
 
55
+ ## Environments
56
+
57
+ The Coralogix RUM CLI supports the following environments:
58
+
59
+ - AP1
60
+ - AP2
61
+ - EU1
62
+ - EU2
63
+ - US1
64
+
65
+ Please use the appropriate environment value when specifying the `-e, --env` option.
66
+
47
67
  ## Source maps folder size limit
48
68
 
49
69
  The source map folder size limit is 100MB in this project. Please ensure that it does not exceed this limit.
@@ -87,19 +107,6 @@ coralogix-rum-cli upload-source-maps -k "$PRIVATE_KEY" -a "$APPLICATION" -v "$VE
87
107
  | IMPORTANT: The $VERSION param must align with the content of the version field in your CoralogixRum.init() configuration in [Coralogix SDK for Browsers](https://www.npmjs.com/package/@coralogix/browser) |
88
108
  |------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
89
109
 
90
- <br>
91
-
92
- ## Available Environments
93
-
94
- The Coralogix RUM CLI supports the following environments:
95
-
96
- - AP1
97
- - AP2
98
- - EU1
99
- - EU2
100
- - US1
101
-
102
- Please use the appropriate environment value when specifying the `-e, --env` option.
103
110
 
104
111
  ## Optional GitHub Information
105
112
 
package/api/rum-api.ts CHANGED
@@ -1,101 +1,114 @@
1
- import {Client, createChannel, createClient, Metadata} from 'nice-grpc';
2
- import {envToDomain} from "../model/cli.model";
3
- import * as pako from 'pako';
4
- import config from "../config/config";
5
- import {RED_COLOR} from "../cli/theme";
6
- import {FileMetadata} from "../proto-models/com/coralogix/rum/v2/file";
1
+ import { Client, createChannel, createClient, Metadata } from 'nice-grpc';
2
+ import config from '../config/config';
7
3
  import {
8
- RumSourceMapServiceDefinition,
9
- UploadSourceMapsRequest
10
- } from "../proto-models/com/coralogix/rum/v2/rum_source_map_service";
11
- import {MB} from "../cli/consts/consts";
4
+ DeleteSourceMapRequest,
5
+ RumSourceMapServiceDefinition,
6
+ UpdateSourceMapRequest,
7
+ UploadSourceMapsRequest,
8
+ } from '../proto-models/com/coralogix/rum/v2/rum_source_map_service';
9
+ import { compressFileContentChunks, validateCompressedFilesSize } from '../utils';
10
+ import { envToDomain } from '../consts/consts';
11
+ import { FileMetadata } from '../proto-models/com/coralogix/rum/v2/file';
12
12
 
13
13
  export class RumApi {
14
- static async uploadSourceMaps(request: UploadSourceMapsRequest, env: string, privateKey: string) {
15
-
16
- const {maxMessageSize, keepaliveTimeMs, keepaliveTimeoutMs, maxCompressedFilesSize} = config.rumApi;
17
-
18
- try {
19
- const channel = createChannel(envToDomain[env], undefined, {
20
- "grpc.max_receive_message_length": maxMessageSize,
21
- "grpc.max_send_message_length": maxMessageSize,
22
- 'grpc.keepalive_time_ms': keepaliveTimeMs,
23
- 'grpc.keepalive_timeout_ms': keepaliveTimeoutMs,
24
- });
25
-
26
- const client: Client<typeof RumSourceMapServiceDefinition> = createClient(RumSourceMapServiceDefinition, channel);
27
-
28
- const {files, releaseId, application, repoName, commitHash, user} = request;
29
-
30
- const compressedFiles: FileMetadata[] = await Promise.all(
31
- files.map(async (file: FileMetadata) => {
32
- const compressedChunks = this.compressFileContentChunks(file.content);
33
-
34
- const size = compressedChunks.length;
35
-
36
- return {chunkName: file.chunkName, size, content: compressedChunks};
37
- })
38
- );
39
-
40
- this.validateCompressedFilesSize(compressedFiles, maxCompressedFilesSize);
41
-
42
- const metadata = new Metadata();
43
-
44
- metadata.set('Authorization', `Bearer ${privateKey}`);
45
-
46
- await client.uploadSourceMaps({
47
- files: compressedFiles,
48
- releaseId,
49
- application,
50
- repoName,
51
- commitHash,
52
- user
53
- }, {metadata});
54
-
55
- } catch (error) {
56
- throw error;
57
- }
58
- };
59
-
60
- private static compressFileContentChunks = (fileContent: Uint8Array): Uint8Array => {
61
- const {chunkSize} = config.rumApi; // 512 KB chunk size
62
- const deflate = new pako.Deflate();
63
- const totalChunks = Math.ceil(fileContent.length / chunkSize);
64
-
65
- for (let i = 0; i < totalChunks; i++) {
66
- const start = i * chunkSize;
67
- const end = start + chunkSize;
68
- const chunk = fileContent.subarray(start, end);
69
-
70
- const isLastChunk = i === totalChunks - 1;
71
-
72
- deflate.push(chunk, isLastChunk);
73
- }
74
-
75
- const {err, msg, result} = deflate;
76
-
77
- if (err) console.error(RED_COLOR, msg);
78
-
79
- return result;
14
+ private static getGrpcClient(env: string) {
15
+ const { maxMessageSize, keepaliveTimeMs, keepaliveTimeoutMs } = config.rumApi;
16
+
17
+ const channel = createChannel(envToDomain[env], undefined, {
18
+ 'grpc.max_receive_message_length': maxMessageSize,
19
+ 'grpc.max_send_message_length': maxMessageSize,
20
+ 'grpc.keepalive_time_ms': keepaliveTimeMs,
21
+ 'grpc.keepalive_timeout_ms': keepaliveTimeoutMs,
22
+ });
23
+
24
+ return createClient(RumSourceMapServiceDefinition, channel);
25
+ }
26
+
27
+ static async uploadSourceMaps(request: UploadSourceMapsRequest, env: string, privateKey: string) {
28
+ try {
29
+ const client: Client<typeof RumSourceMapServiceDefinition> = this.getGrpcClient(env);
30
+
31
+ const { files, releaseId, application, repoName, commitHash, user } = request;
32
+
33
+ const compressedFiles: FileMetadata[] = await Promise.all(
34
+ files.map(async (file: FileMetadata) => {
35
+ const content = compressFileContentChunks(file.content);
36
+ const size = content.length;
37
+ const chunkName = file.chunkName;
38
+ return { chunkName, size, content };
39
+ }),
40
+ );
41
+
42
+ validateCompressedFilesSize(compressedFiles, config.rumApi.maxCompressedFilesSize);
43
+
44
+ const metadata = new Metadata();
45
+
46
+ metadata.set('Authorization', `Bearer ${privateKey}`);
47
+
48
+ await client.uploadSourceMaps(
49
+ {
50
+ files: compressedFiles,
51
+ releaseId,
52
+ application,
53
+ repoName,
54
+ commitHash,
55
+ user,
56
+ },
57
+ { metadata },
58
+ );
59
+ } catch (error) {
60
+ throw error;
80
61
  }
62
+ }
63
+
64
+ static async updateSourceMap(request: UpdateSourceMapRequest, env: string, privateKey: string) {
65
+ try {
66
+ const client: Client<typeof RumSourceMapServiceDefinition> = this.getGrpcClient(env);
67
+
68
+ const { files, releaseId, application, repoName, commitHash, user } = request;
69
+
70
+ const compressedFiles: FileMetadata[] = await Promise.all(
71
+ files.map(async (file: FileMetadata) => {
72
+ const content = compressFileContentChunks(file.content);
73
+ const size = content.length;
74
+ const chunkName = file.chunkName;
75
+ return { chunkName, size, content };
76
+ }),
77
+ );
78
+
79
+ validateCompressedFilesSize(compressedFiles, config.rumApi.maxCompressedFilesSize);
80
+
81
+ const metadata = new Metadata();
82
+
83
+ metadata.set('Authorization', `Bearer ${privateKey}`);
84
+
85
+ await client.updateSourceMap(
86
+ {
87
+ files: compressedFiles,
88
+ releaseId,
89
+ application,
90
+ repoName,
91
+ commitHash,
92
+ user,
93
+ },
94
+ { metadata },
95
+ );
96
+ } catch (error) {
97
+ throw error;
98
+ }
99
+ }
81
100
 
82
- private static validateCompressedFilesSize(compressedFiles: FileMetadata[], maxCompressedFilesSize: number): void {
83
- const compressedFilesSize = compressedFiles.reduce((sum, file) => sum + file.content.length, 0);
101
+ static async deleteSourceMap(request: DeleteSourceMapRequest, env: string, privateKey: string) {
102
+ try {
103
+ const client: Client<typeof RumSourceMapServiceDefinition> = this.getGrpcClient(env);
84
104
 
85
- if (compressedFilesSize > maxCompressedFilesSize) {
86
- // Convert sizes to megabytes (MB)
87
- const compressedFilesSizeMB: string = (compressedFilesSize / MB).toFixed(2);
88
- const maxCompressedFilesSizeMB: string = (maxCompressedFilesSize / MB).toFixed(2);
105
+ const metadata = new Metadata();
89
106
 
90
- const errorMessage = `
91
- ❌ Error: The total size of compressed files exceeds the maximum allowed size.
92
- Total Compressed Files Size: ${compressedFilesSizeMB} MB
93
- Maximum Allowed Size: ${maxCompressedFilesSizeMB} MB
94
- `;
107
+ metadata.set('Authorization', `Bearer ${privateKey}`);
95
108
 
96
- console.error(RED_COLOR, errorMessage);
97
- process.exit(1);
98
- }
109
+ await client.deleteSourceMap(request, { metadata });
110
+ } catch (error) {
111
+ throw error;
99
112
  }
113
+ }
100
114
  }
101
-
@@ -0,0 +1,34 @@
1
+ import { Command } from 'commander';
2
+ import { validateEnvironment } from '../validators';
3
+ import { RED_COLOR } from '../../consts/consts';
4
+ import { SourceMapsService } from '../../services/source-maps.service';
5
+ import { checkMissingArguments } from '../../utils';
6
+ import { DeleteCommandOptions } from '../../models/commands.model';
7
+
8
+ export const deleteCommand = () => {
9
+ const deleteCommand = new Command('delete-source-maps')
10
+ .option('-k, --private-key <privateKey>', 'Private key to authenticate with the API')
11
+ .option('-a, --application <application>', 'Name of the application')
12
+ .option('-v, --version <version>', 'The application version - must match the version used by RUM sdk')
13
+ .option('-e, --env <env>', 'Your environment', validateEnvironment)
14
+ .description('Delete source maps')
15
+ .action(async (options: DeleteCommandOptions) => {
16
+ try {
17
+ if (options.help) {
18
+ deleteCommand.outputHelp();
19
+ process.exit(0);
20
+ }
21
+
22
+ const { privateKey, application, version, env } = options;
23
+
24
+ checkMissingArguments<DeleteCommandOptions>(options, ['privateKey', 'application', 'version', 'env']);
25
+
26
+ await SourceMapsService.delete(application, version, env, privateKey);
27
+ } catch (error) {
28
+ console.error(RED_COLOR, '❌ An error occurred:');
29
+ console.error(RED_COLOR, error);
30
+ }
31
+ });
32
+
33
+ return deleteCommand;
34
+ };
@@ -0,0 +1,7 @@
1
+ import { updateCommand } from './update-source-maps-command';
2
+ import { uploadCommand } from './upload-source-maps-command';
3
+ import { deleteCommand } from './delete-source-maps-command';
4
+
5
+ const commands = { uploadCommand, updateCommand, deleteCommand };
6
+
7
+ export default commands;
@@ -0,0 +1,38 @@
1
+ import { Command } from 'commander';
2
+ import { validateEnvironment } from '../validators';
3
+ import { RED_COLOR } from '../../consts/consts';
4
+ import { SourceMapsService } from '../../services/source-maps.service';
5
+ import { checkMissingArguments } from '../../utils';
6
+ import { UpdateCommandOptions } from '../../models/commands.model';
7
+
8
+ export const updateCommand = () => {
9
+ const updateCommand = new Command('update-source-maps')
10
+ .option('-k, --private-key <privateKey>', 'Private key to authenticate with the API')
11
+ .option('-a, --application <application>', 'Name of the application')
12
+ .option('-v, --version <version>', 'The application version - must match the version used by RUM sdk')
13
+ .option('-f, --folder-path <folderPath>', 'Path to the folder containing the source maps')
14
+ .option('-e, --env <env>', 'Your environment', validateEnvironment)
15
+ .option('-c, --commit-hash <commitHash>', 'GitHub commit hash (optional)')
16
+ .option('-n, --repo-name <repoName>', 'GitHub Repository name (optional)')
17
+ .option('-o, --org-name <orgName>', 'GitHub user name (optional)')
18
+ .description('Update source maps')
19
+ .action(async (options: UpdateCommandOptions) => {
20
+ try {
21
+ if (options.help) {
22
+ updateCommand.outputHelp();
23
+ process.exit(0);
24
+ }
25
+
26
+ const { privateKey, application, version, folderPath, commitHash, repoName, orgName, env } = options;
27
+
28
+ checkMissingArguments<UpdateCommandOptions>(options, ['privateKey', 'application', 'version', 'folderPath', 'env']);
29
+
30
+ await SourceMapsService.update(application, version, repoName, commitHash, orgName, folderPath, env, privateKey);
31
+ } catch (error) {
32
+ console.error(RED_COLOR, '❌ An error occurred:');
33
+ console.error(RED_COLOR, error);
34
+ }
35
+ });
36
+
37
+ return updateCommand;
38
+ };
@@ -0,0 +1,38 @@
1
+ import { Command } from 'commander';
2
+ import { validateEnvironment } from '../validators';
3
+ import { RED_COLOR } from '../../consts/consts';
4
+ import { SourceMapsService } from '../../services/source-maps.service';
5
+ import { checkMissingArguments } from '../../utils';
6
+ import { UploadCommandOptions } from '../../models/commands.model';
7
+
8
+ export const uploadCommand = () => {
9
+ const uploadCommand = new Command('upload-source-maps')
10
+ .option('-k, --private-key <privateKey>', 'Private key to authenticate with the API')
11
+ .option('-a, --application <application>', 'Name of the application')
12
+ .option('-v, --version <version>', 'The application version - must match the version used by RUM sdk')
13
+ .option('-f, --folder-path <folderPath>', 'Path to the folder containing the source maps')
14
+ .option('-e, --env <env>', 'Your environment', validateEnvironment)
15
+ .option('-c, --commit-hash <commitHash>', 'GitHub commit hash (optional)')
16
+ .option('-n, --repo-name <repoName>', 'GitHub Repository name (optional)')
17
+ .option('-o, --org-name <orgName>', 'GitHub user name (optional)')
18
+ .description('Update source maps')
19
+ .action(async (options: UploadCommandOptions) => {
20
+ try {
21
+ if (options.help) {
22
+ uploadCommand.outputHelp();
23
+ process.exit(0);
24
+ }
25
+
26
+ const { privateKey, application, version, folderPath, commitHash, repoName, orgName, env } = options;
27
+
28
+ checkMissingArguments<UploadCommandOptions>(options, ['privateKey', 'application', 'version', 'folderPath', 'env']);
29
+
30
+ await SourceMapsService.upload(application, version, repoName, commitHash, orgName, folderPath, env, privateKey);
31
+ } catch (error) {
32
+ console.error(RED_COLOR, '❌ An error occurred:');
33
+ console.error(RED_COLOR, error);
34
+ }
35
+ });
36
+
37
+ return uploadCommand;
38
+ };
package/cli/rum-cli.ts CHANGED
@@ -1,54 +1,20 @@
1
1
  #!/usr/bin/env node
2
- import {Command} from 'commander';
3
- import {SourceMapsService} from "../services/source-maps/source-maps.service";
4
- import {validateEnvironment} from "./validators";
5
- import {RED_COLOR} from "./theme";
2
+ import { Command } from 'commander';
3
+ import commands from './commands';
6
4
 
7
- const program = new Command();
5
+ const program: Command = new Command();
8
6
 
9
- program.name('coralogix-rum-cli').description('cli for upload source maps')
7
+ program.name('coralogix-rum-cli').description('CLI for upload, update, and delete source maps');
10
8
 
11
- const uploadCommand = program.command('upload-source-maps');
9
+ // Create instances for each command
10
+ const uploadCommand: Command = commands.uploadCommand();
11
+ const updateCommand: Command = commands.updateCommand();
12
+ const deleteCommand: Command = commands.deleteCommand();
12
13
 
13
- uploadCommand
14
- .option('-k, --private-key <privateKey>', 'Private key to authenticate with the API')
15
- .option('-a, --application <application>', 'Name of the application')
16
- .option('-v, --version <version>', 'The application version - must match the version used by RUM sdk')
17
- .option('-f, --folder-path <folderPath>', 'Path to the folder containing the source maps')
18
- .option('-e, --env <env>', 'Your environment', validateEnvironment)
19
- .option('-c, --commit-hash <commitHash>', 'GitHub commit hash (optional)')
20
- .option('-n, --repo-name <repoName>', 'GitHub Repository name (optional)')
21
- .option('-o, --org-name <orgName>', 'GitHub user name (optional)')
22
- .description('Upload source maps')
23
- .action(async (options) => {
24
- try {
25
- if (options.help) {
26
- program.outputHelp();
27
- process.exit(0);
28
- }
29
-
30
- const {privateKey, application, version, folderPath, commitHash, repoName, orgName, env} = options;
31
-
32
- const missingArgs = [];
33
-
34
- if (!privateKey) missingArgs.push('private-key');
35
- if (!application) missingArgs.push('application');
36
- if (!version) missingArgs.push('version');
37
- if (!folderPath) missingArgs.push('folder-path');
38
- if (!env) missingArgs.push('env');
39
-
40
- if (missingArgs.length > 0) {
41
- const missingArgsList = missingArgs.map(arg => `- ${arg}`).join('\n');
42
- const errorMessage = `❌ Missing required arguments:\n${missingArgsList}\nPlease provide the necessary options`;
43
- console.error(RED_COLOR, errorMessage);
44
- process.exit(1);
45
- }
46
-
47
- await SourceMapsService.upload(application, version, repoName, commitHash, orgName, folderPath, env, privateKey)
48
- } catch (error) {
49
- console.error(RED_COLOR, '❌ An error occurred:');
50
- console.error(RED_COLOR, error);
51
- }
52
- });
14
+ // Register commands
15
+ program.addCommand(uploadCommand);
16
+ program.addCommand(updateCommand);
17
+ program.addCommand(deleteCommand);
53
18
 
19
+ // Parse command line arguments
54
20
  program.parse(process.argv);
@@ -1,14 +1,13 @@
1
- import {envToDomain} from "../../model/cli.model";
2
- import {RED_COLOR} from "../theme";
1
+ import { envToDomain, RED_COLOR } from '../../consts/consts';
3
2
 
4
3
  export const validateEnvironment = (env: string): string => {
5
- const validEnvironments = Object.keys(envToDomain).join(', ');
4
+ const validEnvironments = Object.keys(envToDomain).join(', ');
6
5
 
7
- if (!(env in envToDomain)) {
8
- const errorMessage = `❌ Invalid environment: ${env}. Possible values are: ${validEnvironments}`;
9
- console.error(RED_COLOR, errorMessage);
10
- process.exit(1);
11
- }
6
+ if (!(env in envToDomain)) {
7
+ const errorMessage = `❌ Invalid environment: ${env}. Possible values are: ${validEnvironments}`;
8
+ console.error(RED_COLOR, errorMessage);
9
+ process.exit(1);
10
+ }
12
11
 
13
- return env;
14
- }
12
+ return env;
13
+ };
package/config/config.ts CHANGED
@@ -1,35 +1,35 @@
1
- import {KB, MB} from "../cli/consts/consts";
1
+ import { MB } from '../consts/consts';
2
2
 
3
3
  export interface LoggerConfig {
4
- maxLogSize: number;
5
- logLevel: string;
4
+ maxLogSize: number;
5
+ logLevel: string;
6
6
  }
7
7
 
8
8
  export interface rumApiConfig {
9
- maxMessageSize: number,
10
- keepaliveTimeMs: number
11
- keepaliveTimeoutMs: number
12
- chunkSize: number,
13
- maxCompressedFilesSize :number
9
+ maxMessageSize: number;
10
+ keepaliveTimeMs: number;
11
+ keepaliveTimeoutMs: number;
12
+ chunkSize: number;
13
+ maxCompressedFilesSize: number;
14
14
  }
15
15
 
16
16
  export interface Config {
17
- logger: LoggerConfig;
18
- rumApi: rumApiConfig;
17
+ logger: LoggerConfig;
18
+ rumApi: rumApiConfig;
19
19
  }
20
20
 
21
21
  const config: Config = {
22
- logger: {
23
- maxLogSize: 10000,
24
- logLevel: 'debug',
25
- },
26
- rumApi: {
27
- keepaliveTimeMs: 240000,
28
- keepaliveTimeoutMs: 240000,
29
- maxMessageSize: 200 * 1024 * 1024, // 200MB(in bytes)
30
- maxCompressedFilesSize: 200 * 1024 * 1024, // 200MB (in bytes)
31
- chunkSize: 1024 * 1024, // 1MB (in bytes)
32
- }
22
+ logger: {
23
+ maxLogSize: 10000,
24
+ logLevel: 'debug',
25
+ },
26
+ rumApi: {
27
+ keepaliveTimeMs: 240000,
28
+ keepaliveTimeoutMs: 240000,
29
+ maxMessageSize: 200 * MB, // 200MB(in bytes)
30
+ maxCompressedFilesSize: 200 * MB, // 200MB (in bytes)
31
+ chunkSize: MB, // 1MB (in bytes)
32
+ },
33
33
  };
34
34
 
35
35
  export default config;
@@ -0,0 +1,16 @@
1
+ export const MB = 1024 * 1024;
2
+
3
+ export const GREEN_COLOR = '\x1b[32m%s\x1b[0m';
4
+
5
+ export const RED_COLOR = '\x1b[31m%s\x1b[0m';
6
+
7
+ export const GRAY_COLOR = '\x1b[37m%s\x1b[0m';
8
+
9
+ export const envToDomain: Record<string, string> = {
10
+ EU1: 'https://ng-api-grpc.coralogix.com:443', // eu-west-1 (Ireland)
11
+ EU2: 'https://ng-api-grpc.eu2.coralogix.com:443', // eu-north-1 (Stockholm)
12
+ US1: 'https://ng-api-grpc.coralogix.us:443', // us-east-2 (Ohio)
13
+ US2: 'https://ng-api-grpc.cx498.coralogix.com:443', // us-west-2 (Oregon)
14
+ AP1: 'https://ng-api-grpc.app.coralogix.in:443', // ap-south-1 (Mumbai)
15
+ AP2: 'https://ng-api-grpc.coralogixsg.com:443', // ap-southeast-1 (Singapore)
16
+ };
@@ -1,6 +1,7 @@
1
- import { UploadSourceMapsRequest } from "../proto-models/com/coralogix/rum/v2/rum_source_map_service";
1
+ import { DeleteSourceMapRequest, UpdateSourceMapRequest, UploadSourceMapsRequest } from '../proto-models/com/coralogix/rum/v2/rum_source_map_service';
2
2
  export declare class RumApi {
3
+ private static getGrpcClient;
3
4
  static uploadSourceMaps(request: UploadSourceMapsRequest, env: string, privateKey: string): Promise<void>;
4
- private static compressFileContentChunks;
5
- private static validateCompressedFilesSize;
5
+ static updateSourceMap(request: UpdateSourceMapRequest, env: string, privateKey: string): Promise<void>;
6
+ static deleteSourceMap(request: DeleteSourceMapRequest, env: string, privateKey: string): Promise<void>;
6
7
  }