@closedloop-ai/cli 0.2.0 → 0.2.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 (79) hide show
  1. package/CONTRIBUTING.md +437 -0
  2. package/LICENSE +21 -0
  3. package/README.md +265 -0
  4. package/docs/CLI_COMMANDS.md +508 -0
  5. package/package.json +49 -26
  6. package/packages/cli/dist/api/team.js +45 -0
  7. package/packages/cli/dist/api/team.js.map +1 -0
  8. package/{dist → packages/cli/dist}/cli.js +7 -0
  9. package/packages/cli/dist/cli.js.map +1 -0
  10. package/packages/cli/dist/commands/team.js +44 -0
  11. package/packages/cli/dist/commands/team.js.map +1 -0
  12. package/dist/cli.js.map +0 -1
  13. package/jest.config.js +0 -14
  14. package/src/__tests__/cli.test.ts +0 -44
  15. package/src/__tests__/config.test.ts +0 -38
  16. package/src/__tests__/errors.test.ts +0 -132
  17. package/src/__tests__/setup.ts +0 -21
  18. package/src/__tests__/validation.test.ts +0 -156
  19. package/src/api/auth.ts +0 -21
  20. package/src/api/feedback.ts +0 -64
  21. package/src/api/input.ts +0 -55
  22. package/src/api/usage.ts +0 -45
  23. package/src/cli.ts +0 -158
  24. package/src/commands/config.ts +0 -192
  25. package/src/commands/feedback.ts +0 -250
  26. package/src/commands/input.ts +0 -389
  27. package/src/commands/list.ts +0 -84
  28. package/src/commands/status.ts +0 -96
  29. package/src/commands/submit.ts +0 -214
  30. package/src/config/constants.ts +0 -36
  31. package/src/config/index.ts +0 -59
  32. package/src/types/index.ts +0 -119
  33. package/src/utils/errors.ts +0 -98
  34. package/src/utils/validation.ts +0 -166
  35. package/tsconfig.json +0 -25
  36. /package/{dist → packages/cli/dist}/__tests__/cli.test.js +0 -0
  37. /package/{dist → packages/cli/dist}/__tests__/cli.test.js.map +0 -0
  38. /package/{dist → packages/cli/dist}/__tests__/config.test.js +0 -0
  39. /package/{dist → packages/cli/dist}/__tests__/config.test.js.map +0 -0
  40. /package/{dist → packages/cli/dist}/__tests__/errors.test.js +0 -0
  41. /package/{dist → packages/cli/dist}/__tests__/errors.test.js.map +0 -0
  42. /package/{dist → packages/cli/dist}/__tests__/setup.js +0 -0
  43. /package/{dist → packages/cli/dist}/__tests__/setup.js.map +0 -0
  44. /package/{dist → packages/cli/dist}/__tests__/validation.test.js +0 -0
  45. /package/{dist → packages/cli/dist}/__tests__/validation.test.js.map +0 -0
  46. /package/{dist → packages/cli/dist}/api/auth.js +0 -0
  47. /package/{dist → packages/cli/dist}/api/auth.js.map +0 -0
  48. /package/{dist → packages/cli/dist}/api/feedback.js +0 -0
  49. /package/{dist → packages/cli/dist}/api/feedback.js.map +0 -0
  50. /package/{dist → packages/cli/dist}/api/input.js +0 -0
  51. /package/{dist → packages/cli/dist}/api/input.js.map +0 -0
  52. /package/{dist → packages/cli/dist}/api/usage.js +0 -0
  53. /package/{dist → packages/cli/dist}/api/usage.js.map +0 -0
  54. /package/{dist → packages/cli/dist}/commands/config.js +0 -0
  55. /package/{dist → packages/cli/dist}/commands/config.js.map +0 -0
  56. /package/{dist → packages/cli/dist}/commands/feedback.js +0 -0
  57. /package/{dist → packages/cli/dist}/commands/feedback.js.map +0 -0
  58. /package/{dist → packages/cli/dist}/commands/input.js +0 -0
  59. /package/{dist → packages/cli/dist}/commands/input.js.map +0 -0
  60. /package/{dist → packages/cli/dist}/commands/list.js +0 -0
  61. /package/{dist → packages/cli/dist}/commands/list.js.map +0 -0
  62. /package/{dist → packages/cli/dist}/commands/status.js +0 -0
  63. /package/{dist → packages/cli/dist}/commands/status.js.map +0 -0
  64. /package/{dist → packages/cli/dist}/commands/submit.js +0 -0
  65. /package/{dist → packages/cli/dist}/commands/submit.js.map +0 -0
  66. /package/{dist → packages/cli/dist}/commands/usage.js +0 -0
  67. /package/{dist → packages/cli/dist}/commands/usage.js.map +0 -0
  68. /package/{dist → packages/cli/dist}/config/constants.js +0 -0
  69. /package/{dist → packages/cli/dist}/config/constants.js.map +0 -0
  70. /package/{dist → packages/cli/dist}/config/index.js +0 -0
  71. /package/{dist → packages/cli/dist}/config/index.js.map +0 -0
  72. /package/{dist → packages/cli/dist}/types/index.js +0 -0
  73. /package/{dist → packages/cli/dist}/types/index.js.map +0 -0
  74. /package/{dist → packages/cli/dist}/utils/config.js +0 -0
  75. /package/{dist → packages/cli/dist}/utils/config.js.map +0 -0
  76. /package/{dist → packages/cli/dist}/utils/errors.js +0 -0
  77. /package/{dist → packages/cli/dist}/utils/errors.js.map +0 -0
  78. /package/{dist → packages/cli/dist}/utils/validation.js +0 -0
  79. /package/{dist → packages/cli/dist}/utils/validation.js.map +0 -0
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.teamCommand = void 0;
7
+ const commander_1 = require("commander");
8
+ const chalk_1 = __importDefault(require("chalk"));
9
+ const ora_1 = __importDefault(require("ora"));
10
+ const team_1 = require("../api/team");
11
+ exports.teamCommand = new commander_1.Command('team')
12
+ .description('Manage team settings')
13
+ .action(async (options) => {
14
+ console.log(chalk_1.default.yellow('Use team subcommands to manage team settings'));
15
+ console.log(chalk_1.default.black('Available commands: website'));
16
+ });
17
+ // Team website subcommand
18
+ const teamWebsiteCommand = new commander_1.Command('website')
19
+ .description('Manage team website')
20
+ .action(async (options) => {
21
+ console.log(chalk_1.default.yellow('Use website subcommands to manage team website'));
22
+ console.log(chalk_1.default.black('Available commands: update'));
23
+ });
24
+ // Update team website
25
+ const teamWebsiteUpdateCommand = new commander_1.Command('update')
26
+ .description('Update team website')
27
+ .argument('<website>', 'Team website URL (must include http:// or https://)')
28
+ .action(async (website, options) => {
29
+ try {
30
+ const spinner = (0, ora_1.default)('Updating team website...').start();
31
+ const result = await (0, team_1.updateTeamWebsite)(website);
32
+ spinner.succeed('Team website updated successfully');
33
+ console.log(chalk_1.default.green(`Website: ${result.website}`));
34
+ console.log(chalk_1.default.gray(`Updated: ${result.updated_at}`));
35
+ }
36
+ catch (error) {
37
+ (0, ora_1.default)().fail('Failed to update team website');
38
+ console.error(chalk_1.default.red(error.message));
39
+ process.exit(1);
40
+ }
41
+ });
42
+ teamWebsiteCommand.addCommand(teamWebsiteUpdateCommand);
43
+ exports.teamCommand.addCommand(teamWebsiteCommand);
44
+ //# sourceMappingURL=team.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"team.js","sourceRoot":"","sources":["../../src/commands/team.ts"],"names":[],"mappings":";;;;;;AAAA,yCAAoC;AACpC,kDAA0B;AAC1B,8CAAsB;AAEtB,sCAAgD;AAEnC,QAAA,WAAW,GAAG,IAAI,mBAAO,CAAC,MAAM,CAAC;KAC3C,WAAW,CAAC,sBAAsB,CAAC;KACnC,MAAM,CAAC,KAAK,EAAE,OAAuB,EAAE,EAAE;IACxC,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,MAAM,CAAC,8CAA8C,CAAC,CAAC,CAAC;IAC1E,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,KAAK,CAAC,6BAA6B,CAAC,CAAC,CAAC;AAC1D,CAAC,CAAC,CAAC;AAEL,0BAA0B;AAC1B,MAAM,kBAAkB,GAAG,IAAI,mBAAO,CAAC,SAAS,CAAC;KAC9C,WAAW,CAAC,qBAAqB,CAAC;KAClC,MAAM,CAAC,KAAK,EAAE,OAAuB,EAAE,EAAE;IACxC,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,MAAM,CAAC,gDAAgD,CAAC,CAAC,CAAC;IAC5E,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,KAAK,CAAC,4BAA4B,CAAC,CAAC,CAAC;AACzD,CAAC,CAAC,CAAC;AAEL,sBAAsB;AACtB,MAAM,wBAAwB,GAAG,IAAI,mBAAO,CAAC,QAAQ,CAAC;KACnD,WAAW,CAAC,qBAAqB,CAAC;KAClC,QAAQ,CAAC,WAAW,EAAE,qDAAqD,CAAC;KAC5E,MAAM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OAAO,CAAC,EAAE,CAAC,WAAW,EAAE,CAAC,QAAQ,EAAE,EAAE;IACnC,OAAO,CAAC,KAAK,CAAC,eAAK,CAAC,GAAG,CAAC,oBAAoB,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAC5D,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,IAAI,CAAC,2CAA2C,CAAC,CAAC,CAAC;IACrE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC;AAEH,+BAA+B;AAC/B,OAAO,CAAC,KAAK,EAAE,CAAC;AAEhB,oCAAoC;AACpC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;IAClC,OAAO,CAAC,UAAU,EAAE,CAAC;AACvB,CAAC"}
package/jest.config.js DELETED
@@ -1,14 +0,0 @@
1
- module.exports = {
2
- preset: 'ts-jest',
3
- testEnvironment: 'node',
4
- roots: ['<rootDir>/src'],
5
- testMatch: ['**/__tests__/**/*.test.ts'],
6
- collectCoverageFrom: [
7
- 'src/**/*.ts',
8
- '!src/**/*.d.ts',
9
- '!src/__tests__/**/*'
10
- ],
11
- coverageDirectory: 'coverage',
12
- coverageReporters: ['text', 'lcov', 'html'],
13
- setupFilesAfterEnv: ['<rootDir>/src/__tests__/setup.ts']
14
- };
@@ -1,44 +0,0 @@
1
- import { Command } from 'commander';
2
-
3
- // Mock the command handlers
4
- jest.mock('../commands/input', () => ({
5
- handleInputCommand: jest.fn()
6
- }));
7
-
8
- jest.mock('../commands/feedback', () => ({
9
- handleFeedbackCommand: jest.fn()
10
- }));
11
-
12
- jest.mock('../commands/config', () => ({
13
- configCommand: new Command('config')
14
- }));
15
-
16
- describe('CLI Structure', () => {
17
- it('should have correct command structure', () => {
18
- // This is a basic smoke test to ensure the CLI can be imported
19
- // without errors
20
- expect(() => {
21
- require('../cli');
22
- }).not.toThrow();
23
- });
24
-
25
- it('should handle input command', async () => {
26
- const { handleInputCommand } = require('../commands/input');
27
-
28
- // Mock successful execution
29
- (handleInputCommand as jest.Mock).mockResolvedValue(undefined);
30
-
31
- await handleInputCommand('test content', {});
32
- expect(handleInputCommand).toHaveBeenCalledWith('test content', {});
33
- });
34
-
35
- it('should handle feedback command', async () => {
36
- const { handleFeedbackCommand } = require('../commands/feedback');
37
-
38
- // Mock successful execution
39
- (handleFeedbackCommand as jest.Mock).mockResolvedValue(undefined);
40
-
41
- await handleFeedbackCommand('test-id', {});
42
- expect(handleFeedbackCommand).toHaveBeenCalledWith('test-id', {});
43
- });
44
- });
@@ -1,38 +0,0 @@
1
- import { config } from '../config';
2
-
3
- // Mock the config for testing
4
- jest.mock('../config', () => ({
5
- config: {
6
- get: jest.fn(),
7
- set: jest.fn(),
8
- getConfigPath: jest.fn()
9
- }
10
- }));
11
-
12
- describe('Config Manager', () => {
13
- beforeEach(() => {
14
- jest.clearAllMocks();
15
- });
16
-
17
- it('should get config values', () => {
18
- (config.get as jest.Mock).mockReturnValue({ apiKey: 'test-key' });
19
-
20
- const result = config.get();
21
- expect(result).toEqual({ apiKey: 'test-key' });
22
- expect(config.get).toHaveBeenCalled();
23
- });
24
-
25
- it('should set config values', () => {
26
- (config.set as jest.Mock).mockImplementation(() => {});
27
-
28
- config.set('apiKey', 'new-key');
29
- expect(config.set).toHaveBeenCalledWith('apiKey', 'new-key');
30
- });
31
-
32
- it('should get config path', () => {
33
- (config.getConfigPath as jest.Mock).mockReturnValue('/path/to/config.json');
34
-
35
- const result = config.getConfigPath();
36
- expect(result).toBe('/path/to/config.json');
37
- });
38
- });
@@ -1,132 +0,0 @@
1
- import {
2
- CliError,
3
- ERROR_CODES,
4
- handleApiError,
5
- handleValidationError,
6
- handleInputError,
7
- handleProcessingError
8
- } from '../utils/errors';
9
-
10
- describe('Error Utils', () => {
11
- describe('CliError', () => {
12
- it('should create error with message and code', () => {
13
- const error = new CliError('Test error', ERROR_CODES.VALIDATION_ERROR);
14
- expect(error.message).toBe('Test error');
15
- expect(error.code).toBe(ERROR_CODES.VALIDATION_ERROR);
16
- expect(error.exitCode).toBe(1);
17
- });
18
-
19
- it('should create error with custom exit code', () => {
20
- const error = new CliError('Test error', ERROR_CODES.VALIDATION_ERROR, 2);
21
- expect(error.exitCode).toBe(2);
22
- });
23
- });
24
-
25
- describe('handleApiError', () => {
26
- it('should handle 401 errors', () => {
27
- const mockError = {
28
- response: {
29
- status: 401,
30
- data: { message: 'Unauthorized' }
31
- }
32
- };
33
-
34
- const result = handleApiError(mockError);
35
- expect(result.message).toContain('Invalid API key');
36
- expect(result.code).toBe(ERROR_CODES.UNAUTHORIZED);
37
- });
38
-
39
- it('should handle 404 errors', () => {
40
- const mockError = {
41
- response: {
42
- status: 404,
43
- data: { message: 'Not found' }
44
- }
45
- };
46
-
47
- const result = handleApiError(mockError);
48
- expect(result.message).toContain('Resource not found');
49
- expect(result.code).toBe(ERROR_CODES.NOT_FOUND);
50
- });
51
-
52
- it('should handle 429 errors', () => {
53
- const mockError = {
54
- response: {
55
- status: 429,
56
- data: { message: 'Rate limited' }
57
- }
58
- };
59
-
60
- const result = handleApiError(mockError);
61
- expect(result.message).toContain('Rate limit exceeded');
62
- expect(result.code).toBe(ERROR_CODES.RATE_LIMITED);
63
- });
64
-
65
- it('should handle 500 errors', () => {
66
- const mockError = {
67
- response: {
68
- status: 500,
69
- data: { message: 'Internal server error' }
70
- }
71
- };
72
-
73
- const result = handleApiError(mockError);
74
- expect(result.message).toContain('Server error');
75
- expect(result.code).toBe(ERROR_CODES.SERVER_ERROR);
76
- });
77
-
78
- it('should handle connection errors', () => {
79
- const mockError = {
80
- code: 'ENOTFOUND'
81
- };
82
-
83
- const result = handleApiError(mockError);
84
- expect(result.message).toContain('Cannot connect to ClosedLoop servers');
85
- expect(result.code).toBe(ERROR_CODES.CONNECTION_ERROR);
86
- });
87
-
88
- it('should handle timeout errors', () => {
89
- const mockError = {
90
- code: 'ETIMEDOUT'
91
- };
92
-
93
- const result = handleApiError(mockError);
94
- expect(result.message).toContain('Request timed out');
95
- expect(result.code).toBe(ERROR_CODES.CONNECTION_ERROR);
96
- });
97
-
98
- it('should handle unknown errors', () => {
99
- const mockError = {
100
- message: 'Unknown error'
101
- };
102
-
103
- const result = handleApiError(mockError);
104
- expect(result.message).toBe('Unknown error');
105
- expect(result.code).toBe(ERROR_CODES.UNKNOWN_ERROR);
106
- });
107
- });
108
-
109
- describe('handleValidationError', () => {
110
- it('should create validation error', () => {
111
- const result = handleValidationError('Validation failed');
112
- expect(result.message).toBe('Validation failed');
113
- expect(result.code).toBe(ERROR_CODES.VALIDATION_ERROR);
114
- });
115
- });
116
-
117
- describe('handleInputError', () => {
118
- it('should create input error', () => {
119
- const result = handleInputError('Input invalid');
120
- expect(result.message).toBe('Input invalid');
121
- expect(result.code).toBe(ERROR_CODES.INVALID_INPUT);
122
- });
123
- });
124
-
125
- describe('handleProcessingError', () => {
126
- it('should create processing error', () => {
127
- const result = handleProcessingError('Processing failed');
128
- expect(result.message).toBe('Processing failed');
129
- expect(result.code).toBe(ERROR_CODES.PROCESSING_ERROR);
130
- });
131
- });
132
- });
@@ -1,21 +0,0 @@
1
- // Test setup file
2
- // This file runs before each test file
3
-
4
- // Mock console methods to avoid cluttering test output
5
- global.console = {
6
- ...console,
7
- log: jest.fn(),
8
- error: jest.fn(),
9
- warn: jest.fn(),
10
- info: jest.fn()
11
- };
12
-
13
- // Mock process.exit to prevent tests from actually exiting
14
- const originalExit = process.exit;
15
- beforeAll(() => {
16
- process.exit = jest.fn() as any;
17
- });
18
-
19
- afterAll(() => {
20
- process.exit = originalExit;
21
- });
@@ -1,156 +0,0 @@
1
- import {
2
- validateUuid,
3
- validateInputContent,
4
- validateApiKey,
5
- validateEmail,
6
- validateUrl,
7
- validatePagination,
8
- validateTitle,
9
- validateCustomerId,
10
- validateName,
11
- sanitizeInput,
12
- validateAndSanitizeInput
13
- } from '../utils/validation';
14
- import { CliError } from '../utils/errors';
15
-
16
- describe('Validation Utils', () => {
17
- describe('validateUuid', () => {
18
- it('should validate correct UUIDs', () => {
19
- expect(validateUuid('123e4567-e89b-12d3-a456-426614174000')).toBe(true);
20
- expect(validateUuid('00000000-0000-0000-0000-000000000000')).toBe(true);
21
- });
22
-
23
- it('should reject invalid UUIDs', () => {
24
- expect(validateUuid('invalid-uuid')).toBe(false);
25
- expect(validateUuid('123e4567-e89b-12d3-a456')).toBe(false);
26
- expect(validateUuid('')).toBe(false);
27
- });
28
- });
29
-
30
- describe('validateInputContent', () => {
31
- it('should validate correct content', () => {
32
- expect(validateInputContent('Valid content')).toBe('Valid content');
33
- expect(validateInputContent(' Valid content ')).toBe('Valid content');
34
- });
35
-
36
- it('should reject empty content', () => {
37
- expect(() => validateInputContent('')).toThrow(CliError);
38
- expect(() => validateInputContent(' ')).toThrow(CliError);
39
- });
40
-
41
- it('should reject content that is too long', () => {
42
- const longContent = 'a'.repeat(10001);
43
- expect(() => validateInputContent(longContent)).toThrow(CliError);
44
- });
45
- });
46
-
47
- describe('validateApiKey', () => {
48
- it('should validate correct API keys', () => {
49
- expect(validateApiKey('valid-api-key-123')).toBe('valid-api-key-123');
50
- expect(validateApiKey(' valid-api-key-123 ')).toBe('valid-api-key-123');
51
- });
52
-
53
- it('should reject empty API keys', () => {
54
- expect(() => validateApiKey('')).toThrow(CliError);
55
- expect(() => validateApiKey(' ')).toThrow(CliError);
56
- });
57
-
58
- it('should reject API keys that are too short', () => {
59
- expect(() => validateApiKey('short')).toThrow(CliError);
60
- });
61
- });
62
-
63
- describe('validateEmail', () => {
64
- it('should validate correct emails', () => {
65
- expect(validateEmail('test@example.com')).toBe('test@example.com');
66
- expect(validateEmail(' TEST@EXAMPLE.COM ')).toBe('test@example.com');
67
- });
68
-
69
- it('should reject invalid emails', () => {
70
- expect(() => validateEmail('invalid-email')).toThrow(CliError);
71
- expect(() => validateEmail('test@')).toThrow(CliError);
72
- expect(() => validateEmail('@example.com')).toThrow(CliError);
73
- });
74
- });
75
-
76
- describe('validateUrl', () => {
77
- it('should validate correct URLs', () => {
78
- expect(validateUrl('https://example.com')).toBe('https://example.com/');
79
- expect(validateUrl('http://example.com')).toBe('http://example.com/');
80
- });
81
-
82
- it('should reject invalid URLs', () => {
83
- expect(() => validateUrl('invalid-url')).toThrow(CliError);
84
- expect(() => validateUrl('ftp://example.com')).toThrow(CliError);
85
- });
86
- });
87
-
88
- describe('validatePagination', () => {
89
- it('should validate correct pagination', () => {
90
- expect(validatePagination(1, 20)).toEqual({ page: 1, limit: 20 });
91
- expect(validatePagination(undefined, undefined)).toEqual({ page: 1, limit: 20 });
92
- });
93
-
94
- it('should enforce minimum values', () => {
95
- expect(validatePagination(0, 0)).toEqual({ page: 1, limit: 20 });
96
- expect(validatePagination(-1, -1)).toEqual({ page: 1, limit: 1 });
97
- });
98
-
99
- it('should enforce maximum limit', () => {
100
- const result = validatePagination(1, 1000);
101
- expect(result.limit).toBeLessThanOrEqual(100);
102
- });
103
- });
104
-
105
- describe('sanitizeInput', () => {
106
- it('should sanitize dangerous content', () => {
107
- expect(sanitizeInput('<script>alert("xss")</script>')).toBe('scriptalert("xss")/script');
108
- expect(sanitizeInput('javascript:alert("xss")')).toBe('alert("xss")');
109
- expect(sanitizeInput('onclick="alert(\'xss\')"')).toBe('"alert(\'xss\')"');
110
- });
111
-
112
- it('should preserve safe content', () => {
113
- expect(sanitizeInput('Safe content')).toBe('Safe content');
114
- expect(sanitizeInput(' Safe content ')).toBe('Safe content');
115
- });
116
- });
117
-
118
- describe('validateAndSanitizeInput', () => {
119
- it('should validate and sanitize complete input data', () => {
120
- const inputData = {
121
- content: 'Test content',
122
- title: 'Test title',
123
- source_url: 'https://example.com',
124
- customer_id: 'customer-123',
125
- reporter_name: 'John Doe',
126
- reporter_email: 'john@example.com'
127
- };
128
-
129
- const result = validateAndSanitizeInput(inputData);
130
- expect(result.content).toBe('Test content');
131
- expect(result.title).toBe('Test title');
132
- expect(result.source_url).toBe('https://example.com/');
133
- expect(result.customer_id).toBe('customer-123');
134
- expect(result.reporter_name).toBe('John Doe');
135
- expect(result.reporter_email).toBe('john@example.com');
136
- });
137
-
138
- it('should handle optional fields', () => {
139
- const inputData = {
140
- content: 'Test content'
141
- };
142
-
143
- const result = validateAndSanitizeInput(inputData);
144
- expect(result.content).toBe('Test content');
145
- expect(result.title).toBeUndefined();
146
- });
147
-
148
- it('should reject invalid content', () => {
149
- const inputData = {
150
- content: ''
151
- };
152
-
153
- expect(() => validateAndSanitizeInput(inputData)).toThrow(CliError);
154
- });
155
- });
156
- });
package/src/api/auth.ts DELETED
@@ -1,21 +0,0 @@
1
- import axios from 'axios';
2
- import { CONFIG } from '../config/constants';
3
- import { CliError, handleApiError, ERROR_CODES } from '../utils/errors';
4
-
5
- export async function validateApiKey(apiKey: string): Promise<boolean> {
6
- try {
7
- const response = await axios.get(`${CONFIG.API_BASE_URL}/health`, {
8
- headers: {
9
- 'Authorization': `Bearer ${apiKey}`
10
- },
11
- timeout: CONFIG.TIMEOUT_MS
12
- });
13
-
14
- return response.status === 200;
15
- } catch (error: any) {
16
- if (error.response?.status === 401) {
17
- return false;
18
- }
19
- throw handleApiError(error);
20
- }
21
- }
@@ -1,64 +0,0 @@
1
- import axios from 'axios';
2
- import { config } from '../config';
3
- import { FeedbackData, ListResponse, CommandOptions, InputData } from '../types';
4
- import { CONFIG, MESSAGES } from '../config/constants';
5
- import { CliError, handleApiError, ERROR_CODES } from '../utils/errors';
6
-
7
- const getClient = () => {
8
- const apiKey = config.get('apiKey');
9
-
10
- if (!apiKey) {
11
- throw new CliError(MESSAGES.NO_API_KEY, ERROR_CODES.NO_API_KEY);
12
- }
13
-
14
- return axios.create({
15
- baseURL: CONFIG.API_BASE_URL,
16
- headers: {
17
- 'Authorization': `Bearer ${apiKey}`,
18
- 'Content-Type': 'application/json',
19
- 'User-Agent': CONFIG.USER_AGENT
20
- },
21
- timeout: CONFIG.TIMEOUT_MS
22
- });
23
- };
24
-
25
- export async function submitFeedback(data: Partial<InputData>): Promise<{ id: string }> {
26
- try {
27
- const client = getClient();
28
- const response = await client.post('/feedbacks', data);
29
- return response.data.data;
30
- } catch (error) {
31
- throw handleApiError(error);
32
- }
33
- }
34
-
35
- export async function listFeedbacks(params: CommandOptions, isNew = false): Promise<ListResponse<FeedbackData>> {
36
- try {
37
- const client = getClient();
38
- const endpoint = isNew ? '/feedbacks/new' : '/feedbacks';
39
- const response = await client.get(endpoint, { params });
40
- return response.data.data;
41
- } catch (error) {
42
- throw handleApiError(error);
43
- }
44
- }
45
-
46
- export async function getFeedbackStatus(id: string): Promise<FeedbackData> {
47
- try {
48
- const client = getClient();
49
- const response = await client.get(`/feedbacks/new/${id}`);
50
- return response.data.data;
51
- } catch (error) {
52
- throw handleApiError(error);
53
- }
54
- }
55
-
56
- export async function getFeedbackDetail(id: string): Promise<FeedbackData> {
57
- try {
58
- const client = getClient();
59
- const response = await client.get(`/feedbacks/${id}`);
60
- return response.data.data;
61
- } catch (error) {
62
- throw handleApiError(error);
63
- }
64
- }
package/src/api/input.ts DELETED
@@ -1,55 +0,0 @@
1
- import axios from 'axios';
2
- import { config } from '../config';
3
- import { InputData, ListResponse, CommandOptions } from '../types';
4
- import { CONFIG, MESSAGES } from '../config/constants';
5
- import { CliError, handleApiError, ERROR_CODES } from '../utils/errors';
6
-
7
- const getClient = () => {
8
- const apiKey = config.get('apiKey');
9
-
10
- if (!apiKey) {
11
- throw new CliError(MESSAGES.NO_API_KEY, ERROR_CODES.NO_API_KEY);
12
- }
13
-
14
- return axios.create({
15
- baseURL: CONFIG.API_BASE_URL,
16
- headers: {
17
- 'Authorization': `Bearer ${apiKey}`,
18
- 'Content-Type': 'application/json',
19
- 'User-Agent': CONFIG.USER_AGENT
20
- },
21
- timeout: CONFIG.TIMEOUT_MS
22
- });
23
- };
24
-
25
- export async function listInputs(page: number = 1, limit: number = 20): Promise<ListResponse<InputData>> {
26
- try {
27
- const client = getClient();
28
- const response = await client.get('/inputs', {
29
- params: { page, limit }
30
- });
31
- return response.data.data;
32
- } catch (error) {
33
- throw handleApiError(error);
34
- }
35
- }
36
-
37
- export async function getInputDetail(id: string): Promise<InputData> {
38
- try {
39
- const client = getClient();
40
- const response = await client.get(`/inputs/${id}`);
41
- return response.data.data;
42
- } catch (error) {
43
- throw handleApiError(error);
44
- }
45
- }
46
-
47
- export async function getInputStatus(id: string): Promise<InputData> {
48
- try {
49
- const client = getClient();
50
- const response = await client.get(`/inputs/${id}`);
51
- return response.data.data;
52
- } catch (error) {
53
- throw handleApiError(error);
54
- }
55
- }
package/src/api/usage.ts DELETED
@@ -1,45 +0,0 @@
1
- import axios from 'axios';
2
- import { config } from '../config';
3
- import { UsageData, ListResponse } from '../types';
4
- import { CONFIG, MESSAGES } from '../config/constants';
5
- import { CliError, handleApiError, ERROR_CODES } from '../utils/errors';
6
-
7
- const getClient = () => {
8
- const apiKey = config.get('apiKey');
9
-
10
- if (!apiKey) {
11
- throw new CliError(MESSAGES.NO_API_KEY, ERROR_CODES.NO_API_KEY);
12
- }
13
-
14
- return axios.create({
15
- baseURL: CONFIG.API_BASE_URL,
16
- headers: {
17
- 'Authorization': `Bearer ${apiKey}`,
18
- 'Content-Type': 'application/json',
19
- 'User-Agent': CONFIG.USER_AGENT
20
- },
21
- timeout: CONFIG.TIMEOUT_MS
22
- });
23
- };
24
-
25
- export async function listUsage(page: number = 1, limit: number = 20): Promise<ListResponse<UsageData>> {
26
- try {
27
- const client = getClient();
28
- const response = await client.get('/usage', {
29
- params: { page, limit }
30
- });
31
- return response.data.data;
32
- } catch (error) {
33
- throw handleApiError(error);
34
- }
35
- }
36
-
37
- export async function getUsageDetail(id: string): Promise<UsageData> {
38
- try {
39
- const client = getClient();
40
- const response = await client.get(`/usage/${id}`);
41
- return response.data.data;
42
- } catch (error) {
43
- throw handleApiError(error);
44
- }
45
- }