@devrev/typescript-sdk 1.1.51 → 1.1.53

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.
@@ -0,0 +1,9 @@
1
+ import { betaSDK } from '../index';
2
+ import { FileObject } from './util-types';
3
+ export declare class BetaSdkUtil {
4
+ private readonly devrevSdk;
5
+ constructor(devrevSdk: betaSDK.Api<unknown>);
6
+ getAllRevUsersFromAccount(accountId: string): Promise<betaSDK.RevUser[] | undefined>;
7
+ getFileContentFromArtifact(artifactId: string): Promise<any | undefined>;
8
+ uploadFileToArtifact(fileObject: FileObject): Promise<string | undefined>;
9
+ }
@@ -0,0 +1,121 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ var __importDefault = (this && this.__importDefault) || function (mod) {
35
+ return (mod && mod.__esModule) ? mod : { "default": mod };
36
+ };
37
+ Object.defineProperty(exports, "__esModule", { value: true });
38
+ exports.BetaSdkUtil = void 0;
39
+ const axios_1 = __importStar(require("axios"));
40
+ const form_data_1 = __importDefault(require("form-data"));
41
+ const stream_1 = require("stream");
42
+ const util_1 = require("./constants/util");
43
+ const error_1 = require("./error");
44
+ class BetaSdkUtil {
45
+ constructor(devrevSdk) {
46
+ this.devrevSdk = devrevSdk;
47
+ }
48
+ getAllRevUsersFromAccount(accountId) {
49
+ return __awaiter(this, void 0, void 0, function* () {
50
+ try {
51
+ const revUserListPayload = {
52
+ associations: [accountId],
53
+ };
54
+ const revUsers = [];
55
+ do {
56
+ const revUserListResponse = yield this.devrevSdk.revUsersList(revUserListPayload);
57
+ if (!revUserListResponse.data.rev_users || revUserListResponse.data.rev_users.length === 0)
58
+ break;
59
+ revUsers.push(...revUserListResponse.data.rev_users);
60
+ revUserListPayload.cursor = revUserListResponse.data.next_cursor;
61
+ } while (revUserListPayload.cursor);
62
+ return revUsers;
63
+ }
64
+ catch (error) {
65
+ (0, error_1.handleApiError)(error);
66
+ }
67
+ });
68
+ }
69
+ getFileContentFromArtifact(artifactId) {
70
+ return __awaiter(this, void 0, void 0, function* () {
71
+ try {
72
+ const response = yield this.devrevSdk.artifactsLocate({
73
+ id: artifactId,
74
+ });
75
+ const artifactData = response.data.url;
76
+ const fileContentResponse = yield axios_1.default.get(artifactData);
77
+ return fileContentResponse.data;
78
+ }
79
+ catch (error) {
80
+ (0, error_1.handleApiError)(error);
81
+ }
82
+ });
83
+ }
84
+ uploadFileToArtifact(fileObject) {
85
+ return __awaiter(this, void 0, void 0, function* () {
86
+ const stream = new stream_1.Readable();
87
+ try {
88
+ if (fileObject.file_type === util_1.MIMETypes.OTHERS && !fileObject.custom_file_type) {
89
+ throw new axios_1.AxiosError('Custom file type is required for OTHERS file type');
90
+ }
91
+ const fileType = fileObject.file_type === util_1.MIMETypes.OTHERS && fileObject.custom_file_type
92
+ ? fileObject.custom_file_type
93
+ : fileObject.file_type;
94
+ const response = yield this.devrevSdk.artifactsPrepare({
95
+ file_name: fileObject.file_name,
96
+ file_type: fileType,
97
+ });
98
+ const { url, form_data: formData, id } = response.data;
99
+ const form = new form_data_1.default();
100
+ for (const data of formData) {
101
+ form.append(data.key, data.value);
102
+ }
103
+ stream.push(fileObject.file);
104
+ stream.push(null);
105
+ form.append('file', stream, {
106
+ filename: url,
107
+ knownLength: stream.readableLength,
108
+ });
109
+ yield axios_1.default.post(url, form, undefined);
110
+ return id;
111
+ }
112
+ catch (error) {
113
+ (0, error_1.handleApiError)(error);
114
+ }
115
+ finally {
116
+ stream.destroy();
117
+ }
118
+ });
119
+ }
120
+ }
121
+ exports.BetaSdkUtil = BetaSdkUtil;
@@ -0,0 +1,5 @@
1
+ export declare const UNKNOWN_TYPE: string;
2
+ export declare const UNKNOWN_FUNCTION: string;
3
+ export declare const UNKNOWN_MESSAGE: string;
4
+ export declare const UNKNOWN_STATUS: number;
5
+ export declare const UNKNOWN_URL: string;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UNKNOWN_URL = exports.UNKNOWN_STATUS = exports.UNKNOWN_MESSAGE = exports.UNKNOWN_FUNCTION = exports.UNKNOWN_TYPE = void 0;
4
+ exports.UNKNOWN_TYPE = 'unknown_type';
5
+ exports.UNKNOWN_FUNCTION = 'unknown_function';
6
+ exports.UNKNOWN_MESSAGE = 'An unknown error occurred';
7
+ exports.UNKNOWN_STATUS = 500;
8
+ exports.UNKNOWN_URL = 'unknown_url';
@@ -0,0 +1,12 @@
1
+ export declare enum MIMETypes {
2
+ CSV = "text/csv",
3
+ HTML = "text/html",
4
+ JPEG = "image/jpeg",
5
+ JSON = "application/json",
6
+ PDF = "application/pdf",
7
+ PNG = "image/png",
8
+ TXT = "text/plain",
9
+ RTE = "devrev/rt",
10
+ XML = "application/xml",
11
+ OTHERS = "others"
12
+ }
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MIMETypes = void 0;
4
+ var MIMETypes;
5
+ (function (MIMETypes) {
6
+ MIMETypes["CSV"] = "text/csv";
7
+ MIMETypes["HTML"] = "text/html";
8
+ MIMETypes["JPEG"] = "image/jpeg";
9
+ MIMETypes["JSON"] = "application/json";
10
+ MIMETypes["PDF"] = "application/pdf";
11
+ MIMETypes["PNG"] = "image/png";
12
+ MIMETypes["TXT"] = "text/plain";
13
+ MIMETypes["RTE"] = "devrev/rt";
14
+ MIMETypes["XML"] = "application/xml";
15
+ MIMETypes["OTHERS"] = "others";
16
+ })(MIMETypes = exports.MIMETypes || (exports.MIMETypes = {}));
@@ -0,0 +1 @@
1
+ export declare const handleApiError: (error: unknown) => void;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.handleApiError = void 0;
4
+ const axios_1 = require("axios");
5
+ const error_1 = require("./constants/error");
6
+ const getCallerName = (error) => {
7
+ if (!error.stack) {
8
+ return error_1.UNKNOWN_FUNCTION;
9
+ }
10
+ const stackLines = error.stack.split('\n');
11
+ const callerLine = stackLines[stackLines.length - 2];
12
+ const callerMatch = callerLine.match(/at async\s+(\S+)/);
13
+ return callerMatch ? callerMatch[1] : error_1.UNKNOWN_FUNCTION;
14
+ };
15
+ const handleApiError = (error) => {
16
+ const errorDetails = {
17
+ api: error_1.UNKNOWN_URL,
18
+ function_name: error_1.UNKNOWN_FUNCTION,
19
+ message: error_1.UNKNOWN_MESSAGE,
20
+ status: error_1.UNKNOWN_STATUS,
21
+ type: error_1.UNKNOWN_TYPE,
22
+ };
23
+ if (error instanceof axios_1.AxiosError && error.response) {
24
+ errorDetails.api = error.response.config.url || error_1.UNKNOWN_URL;
25
+ errorDetails.function_name = getCallerName(error) || error_1.UNKNOWN_FUNCTION;
26
+ errorDetails.message = error.response.data.message || error_1.UNKNOWN_MESSAGE;
27
+ errorDetails.type = error.response.data.type || error_1.UNKNOWN_TYPE;
28
+ errorDetails.status = error.response.status || error_1.UNKNOWN_STATUS;
29
+ }
30
+ const logMessage = [
31
+ '\n=== Error Details ===',
32
+ `Service: ${errorDetails.function_name}`,
33
+ `API: ${errorDetails.api}`,
34
+ `Error Type: ${errorDetails.type}`,
35
+ `Status Code: ${errorDetails.status}`,
36
+ `Message: ${errorDetails.message}`,
37
+ ].filter(Boolean).join('\n');
38
+ console.error(logMessage);
39
+ return;
40
+ };
41
+ exports.handleApiError = handleApiError;
@@ -0,0 +1,13 @@
1
+ /// <reference types="node" />
2
+ import { betaSDK, publicSDK } from "../index";
3
+ import { MIMETypes } from "./constants/util";
4
+ export type FileObject = {
5
+ file_name: string;
6
+ file_type: MIMETypes;
7
+ file: Buffer;
8
+ custom_file_type?: string;
9
+ };
10
+ export type ErrorDetails = (betaSDK.Error | publicSDK.Error) & {
11
+ api: string;
12
+ function_name: string;
13
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,211 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ jest.mock('axios');
16
+ jest.mock('form-data');
17
+ const axios_1 = __importDefault(require("axios"));
18
+ const form_data_1 = __importDefault(require("form-data"));
19
+ const stream_1 = require("stream");
20
+ const util_1 = require("../snap-ins/constants/util");
21
+ const beta_devrev_sdk_util_1 = require("../snap-ins/beta-devrev-sdk-util");
22
+ describe('BetaSDKUtil', () => {
23
+ let mockDevrevBetaSdk;
24
+ let betaSDKUtil;
25
+ beforeEach(() => {
26
+ mockDevrevBetaSdk = {
27
+ revUsersList: jest.fn(),
28
+ artifactsLocate: jest.fn(),
29
+ artifactsPrepare: jest.fn(),
30
+ };
31
+ betaSDKUtil = new beta_devrev_sdk_util_1.BetaSdkUtil(mockDevrevBetaSdk);
32
+ jest.clearAllMocks();
33
+ });
34
+ describe('getAllRevUsersFromAccount', () => {
35
+ it('should retrieve all rev users for a given account', () => __awaiter(void 0, void 0, void 0, function* () {
36
+ const mockRevUsers1 = [
37
+ { id: '1', display_name: 'User 1' },
38
+ { id: '2', display_name: 'User 2' },
39
+ ];
40
+ const mockRevUsers2 = [
41
+ { id: '3', display_name: 'User 3' },
42
+ { id: '4', display_name: 'User 4' },
43
+ ];
44
+ mockDevrevBetaSdk.revUsersList
45
+ .mockResolvedValueOnce({
46
+ data: {
47
+ rev_users: mockRevUsers1,
48
+ next_cursor: 'cursor1',
49
+ },
50
+ })
51
+ .mockResolvedValueOnce({
52
+ data: {
53
+ rev_users: mockRevUsers2,
54
+ next_cursor: null,
55
+ },
56
+ });
57
+ const result = yield betaSDKUtil.getAllRevUsersFromAccount('accountId');
58
+ expect(result).toEqual([...mockRevUsers1, ...mockRevUsers2]);
59
+ }));
60
+ it('should handle empty response from API', () => __awaiter(void 0, void 0, void 0, function* () {
61
+ mockDevrevBetaSdk.revUsersList.mockResolvedValueOnce({
62
+ data: {
63
+ rev_users: [],
64
+ next_cursor: null,
65
+ },
66
+ });
67
+ const result = yield betaSDKUtil.getAllRevUsersFromAccount('accountId');
68
+ expect(result).toEqual([]);
69
+ expect(mockDevrevBetaSdk.revUsersList).toHaveBeenCalledTimes(1);
70
+ }));
71
+ it('should handle null response from API', () => __awaiter(void 0, void 0, void 0, function* () {
72
+ mockDevrevBetaSdk.revUsersList.mockResolvedValueOnce({
73
+ data: {
74
+ rev_users: null,
75
+ next_cursor: null,
76
+ },
77
+ });
78
+ const result = yield betaSDKUtil.getAllRevUsersFromAccount('accountId');
79
+ expect(result).toEqual([]);
80
+ expect(mockDevrevBetaSdk.revUsersList).toHaveBeenCalledTimes(1);
81
+ }));
82
+ });
83
+ describe('getFileContentFromArtifact', () => {
84
+ it('should retrieve file content from an artifact', () => __awaiter(void 0, void 0, void 0, function* () {
85
+ const mockArtifactUrl = 'https://example.com/artifact';
86
+ const mockFileContent = { data: 'File content' };
87
+ mockDevrevBetaSdk.artifactsLocate.mockResolvedValue({
88
+ data: { url: mockArtifactUrl },
89
+ });
90
+ axios_1.default.get.mockResolvedValue({
91
+ data: mockFileContent,
92
+ });
93
+ const result = yield betaSDKUtil.getFileContentFromArtifact('artifactId');
94
+ expect(result).toEqual(mockFileContent);
95
+ expect(mockDevrevBetaSdk.artifactsLocate).toHaveBeenCalledWith({
96
+ id: 'artifactId',
97
+ });
98
+ expect(axios_1.default.get).toHaveBeenCalledWith(mockArtifactUrl);
99
+ }));
100
+ it('should handle artifact location failure', () => __awaiter(void 0, void 0, void 0, function* () {
101
+ mockDevrevBetaSdk.artifactsLocate.mockRejectedValue(new Error('Failed to locate artifact'));
102
+ const result = yield betaSDKUtil.getFileContentFromArtifact('artifactId');
103
+ expect(result).toBeUndefined();
104
+ expect(mockDevrevBetaSdk.artifactsLocate).toHaveBeenCalledWith({
105
+ id: 'artifactId',
106
+ });
107
+ expect(axios_1.default.get).not.toHaveBeenCalled();
108
+ }));
109
+ });
110
+ describe('uploadFileToArtifact', () => {
111
+ it('should upload file with specific file type successfully', () => __awaiter(void 0, void 0, void 0, function* () {
112
+ const mockFileObject = {
113
+ file_name: 'test.json',
114
+ file_type: util_1.MIMETypes.JSON,
115
+ file: Buffer.from('test content'),
116
+ };
117
+ const mockPrepareResponse = {
118
+ data: {
119
+ url: 'https://example.com/upload',
120
+ form_data: [
121
+ { key: 'key1', value: 'value1' },
122
+ { key: 'key2', value: 'value2' },
123
+ ],
124
+ id: 'artifactId',
125
+ },
126
+ };
127
+ mockDevrevBetaSdk.artifactsPrepare.mockResolvedValue(mockPrepareResponse);
128
+ axios_1.default.post.mockResolvedValue({});
129
+ const result = yield betaSDKUtil.uploadFileToArtifact(mockFileObject);
130
+ expect(result).toBe('artifactId');
131
+ expect(mockDevrevBetaSdk.artifactsPrepare).toHaveBeenCalledWith({
132
+ file_name: 'test.json',
133
+ file_type: util_1.MIMETypes.JSON,
134
+ });
135
+ }));
136
+ it('should upload file with custom file type successfully', () => __awaiter(void 0, void 0, void 0, function* () {
137
+ const mockFileObject = {
138
+ file_name: 'test.custom',
139
+ file_type: util_1.MIMETypes.OTHERS,
140
+ custom_file_type: 'custom/type',
141
+ file: Buffer.from('test content'),
142
+ };
143
+ const mockPrepareResponse = {
144
+ data: {
145
+ url: 'https://example.com/upload',
146
+ form_data: [{ key: 'key1', value: 'value1' }],
147
+ id: 'artifactId',
148
+ },
149
+ };
150
+ mockDevrevBetaSdk.artifactsPrepare.mockResolvedValue(mockPrepareResponse);
151
+ axios_1.default.post.mockResolvedValue({});
152
+ const result = yield betaSDKUtil.uploadFileToArtifact(mockFileObject);
153
+ expect(result).toBe('artifactId');
154
+ expect(mockDevrevBetaSdk.artifactsPrepare).toHaveBeenCalledWith({
155
+ file_name: 'test.custom',
156
+ file_type: 'custom/type',
157
+ });
158
+ }));
159
+ it('should handle file upload failure', () => __awaiter(void 0, void 0, void 0, function* () {
160
+ const mockFileObject = {
161
+ file_name: 'test.json',
162
+ file_type: util_1.MIMETypes.JSON,
163
+ file: Buffer.from('test content'),
164
+ };
165
+ mockDevrevBetaSdk.artifactsPrepare.mockResolvedValue({
166
+ data: {
167
+ url: 'https://example.com/upload',
168
+ form_data: [{ key: 'key1', value: 'value1' }],
169
+ id: 'artifactId',
170
+ },
171
+ });
172
+ axios_1.default.post.mockRejectedValue(new Error('Upload failed'));
173
+ const result = yield betaSDKUtil.uploadFileToArtifact(mockFileObject);
174
+ expect(result).toBeUndefined();
175
+ }));
176
+ it('should handle artifact prepare failure', () => __awaiter(void 0, void 0, void 0, function* () {
177
+ const mockFileObject = {
178
+ file_name: 'test.json',
179
+ file_type: util_1.MIMETypes.JSON,
180
+ file: Buffer.from('test content'),
181
+ };
182
+ mockDevrevBetaSdk.artifactsPrepare.mockRejectedValue(new Error('Prepare failed'));
183
+ const result = yield betaSDKUtil.uploadFileToArtifact(mockFileObject);
184
+ expect(result).toBeUndefined();
185
+ expect(axios_1.default.post).not.toHaveBeenCalled();
186
+ }));
187
+ it('should validate FormData creation and stream handling', () => __awaiter(void 0, void 0, void 0, function* () {
188
+ const mockFileObject = {
189
+ file_name: 'test.json',
190
+ file_type: util_1.MIMETypes.JSON,
191
+ file: Buffer.from('test content'),
192
+ };
193
+ const mockPrepareResponse = {
194
+ data: {
195
+ url: 'https://example.com/upload',
196
+ form_data: [{ key: 'key1', value: 'value1' }],
197
+ id: 'artifactId',
198
+ },
199
+ };
200
+ mockDevrevBetaSdk.artifactsPrepare.mockResolvedValue(mockPrepareResponse);
201
+ axios_1.default.post.mockResolvedValue({});
202
+ const result = yield betaSDKUtil.uploadFileToArtifact(mockFileObject);
203
+ expect(result).toBe('artifactId');
204
+ // Verify FormData handling
205
+ expect(form_data_1.default).toHaveBeenCalled();
206
+ const formDataInstance = form_data_1.default.mock.instances[0];
207
+ expect(formDataInstance.append).toHaveBeenCalledWith('key1', 'value1');
208
+ expect(formDataInstance.append).toHaveBeenCalledWith('file', expect.any(stream_1.Readable), expect.any(Object));
209
+ }));
210
+ });
211
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,118 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const axios_1 = require("axios");
4
+ const error_1 = require("../snap-ins/constants/error");
5
+ const error_2 = require("../snap-ins/error");
6
+ // Mock console.error to prevent actual console logs during tests
7
+ const mockConsoleError = jest.spyOn(console, 'error').mockImplementation(() => { });
8
+ describe('handleApiError', () => {
9
+ beforeEach(() => {
10
+ // Clear mock calls before each test
11
+ mockConsoleError.mockClear();
12
+ });
13
+ afterAll(() => {
14
+ // Restore original console.error after all tests
15
+ mockConsoleError.mockRestore();
16
+ });
17
+ it('should handle valid AxiosError with complete response data', () => {
18
+ const mockAxiosError = new axios_1.AxiosError();
19
+ mockAxiosError.response = {
20
+ config: {
21
+ url: 'https://api.example.com/users',
22
+ headers: {},
23
+ },
24
+ data: {
25
+ message: 'User not found',
26
+ type: 'NOT_FOUND',
27
+ },
28
+ status: 404,
29
+ statusText: 'Not Found',
30
+ headers: {},
31
+ };
32
+ mockAxiosError.stack = '\nError: Request failed\nat process ticks\nat async getUserData\nat processRequest';
33
+ (0, error_2.handleApiError)(mockAxiosError);
34
+ // Expected log message
35
+ const expectedLog = [
36
+ '\n=== Error Details ===',
37
+ 'Service: getUserData',
38
+ 'API: https://api.example.com/users',
39
+ 'Error Type: NOT_FOUND',
40
+ 'Status Code: 404',
41
+ 'Message: User not found',
42
+ ].join('\n');
43
+ // Verify exact match of console.error message
44
+ expect(mockConsoleError).toHaveBeenCalledWith(expectedLog);
45
+ });
46
+ it('should handle AxiosError with missing response data', () => {
47
+ const mockAxiosError = new axios_1.AxiosError();
48
+ mockAxiosError.response = {
49
+ config: { headers: {} },
50
+ data: {},
51
+ status: 500,
52
+ statusText: 'Internal Server Error',
53
+ headers: {},
54
+ };
55
+ (0, error_2.handleApiError)(mockAxiosError);
56
+ const expectedLog = [
57
+ '\n=== Error Details ===',
58
+ `Service: runTestInternal`,
59
+ `API: ${error_1.UNKNOWN_URL}`,
60
+ `Error Type: ${error_1.UNKNOWN_TYPE}`,
61
+ 'Status Code: 500',
62
+ `Message: ${error_1.UNKNOWN_MESSAGE}`,
63
+ ].join('\n');
64
+ expect(mockConsoleError).toHaveBeenCalledWith(expectedLog);
65
+ });
66
+ it('should handle non-AxiosError', () => {
67
+ const regularError = new Error('Regular error');
68
+ (0, error_2.handleApiError)(regularError);
69
+ const expectedLog = [
70
+ '\n=== Error Details ===',
71
+ `Service: ${error_1.UNKNOWN_FUNCTION}`,
72
+ `API: ${error_1.UNKNOWN_URL}`,
73
+ `Error Type: ${error_1.UNKNOWN_TYPE}`,
74
+ `Status Code: ${error_1.UNKNOWN_STATUS}`,
75
+ `Message: ${error_1.UNKNOWN_MESSAGE}`,
76
+ ].join('\n');
77
+ expect(mockConsoleError).toHaveBeenCalledWith(expectedLog);
78
+ });
79
+ it('should handle undefined error', () => {
80
+ (0, error_2.handleApiError)(undefined);
81
+ const expectedLog = [
82
+ '\n=== Error Details ===',
83
+ `Service: ${error_1.UNKNOWN_FUNCTION}`,
84
+ `API: ${error_1.UNKNOWN_URL}`,
85
+ `Error Type: ${error_1.UNKNOWN_TYPE}`,
86
+ `Status Code: ${error_1.UNKNOWN_STATUS}`,
87
+ `Message: ${error_1.UNKNOWN_MESSAGE}`,
88
+ ].join('\n');
89
+ expect(mockConsoleError).toHaveBeenCalledWith(expectedLog);
90
+ });
91
+ it('should handle AxiosError with missing stack trace', () => {
92
+ const mockAxiosError = new axios_1.AxiosError();
93
+ mockAxiosError.response = {
94
+ config: {
95
+ url: 'https://api.example.com/users',
96
+ headers: {},
97
+ },
98
+ data: {
99
+ message: 'User not found',
100
+ type: 'NOT_FOUND',
101
+ },
102
+ status: 404,
103
+ statusText: 'Not Found',
104
+ headers: {},
105
+ };
106
+ mockAxiosError.stack = undefined;
107
+ (0, error_2.handleApiError)(mockAxiosError);
108
+ const expectedLog = [
109
+ '\n=== Error Details ===',
110
+ `Service: ${error_1.UNKNOWN_FUNCTION}`,
111
+ 'API: https://api.example.com/users',
112
+ 'Error Type: NOT_FOUND',
113
+ 'Status Code: 404',
114
+ 'Message: User not found',
115
+ ].join('\n');
116
+ expect(mockConsoleError).toHaveBeenCalledWith(expectedLog);
117
+ });
118
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devrev/typescript-sdk",
3
- "version": "1.1.51",
3
+ "version": "1.1.53",
4
4
  "description": "## SDK Generation",
5
5
  "main": "./dist/index.js",
6
6
  "scripts": {