@optimizely-opal/opal-tool-ocp-sdk 1.0.0-OCP-1441.4 → 1.0.0-OCP-1442.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.
- package/README.md +72 -0
- package/dist/function/GlobalToolFunction.d.ts +1 -0
- package/dist/function/GlobalToolFunction.d.ts.map +1 -1
- package/dist/function/GlobalToolFunction.js +8 -0
- package/dist/function/GlobalToolFunction.js.map +1 -1
- package/dist/function/GlobalToolFunction.test.js +3 -0
- package/dist/function/GlobalToolFunction.test.js.map +1 -1
- package/dist/function/ToolFunction.d.ts +7 -1
- package/dist/function/ToolFunction.d.ts.map +1 -1
- package/dist/function/ToolFunction.js +16 -2
- package/dist/function/ToolFunction.js.map +1 -1
- package/dist/function/ToolFunction.test.d.ts +2 -0
- package/dist/function/ToolFunction.test.d.ts.map +1 -0
- package/dist/function/ToolFunction.test.js +317 -0
- package/dist/function/ToolFunction.test.js.map +1 -0
- package/dist/logging/ToolLogger.d.ts +34 -0
- package/dist/logging/ToolLogger.d.ts.map +1 -0
- package/dist/logging/ToolLogger.js +151 -0
- package/dist/logging/ToolLogger.js.map +1 -0
- package/dist/logging/ToolLogger.test.d.ts +2 -0
- package/dist/logging/ToolLogger.test.d.ts.map +1 -0
- package/dist/logging/ToolLogger.test.js +533 -0
- package/dist/logging/ToolLogger.test.js.map +1 -0
- package/package.json +1 -1
- package/src/function/GlobalToolFunction.test.ts +3 -0
- package/src/function/GlobalToolFunction.ts +11 -0
- package/src/function/ToolFunction.test.ts +377 -0
- package/src/function/ToolFunction.ts +21 -2
- package/src/logging/ToolLogger.test.ts +623 -0
- package/src/logging/ToolLogger.ts +175 -0
|
@@ -0,0 +1,533 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const ToolLogger_1 = require("./ToolLogger");
|
|
4
|
+
const app_sdk_1 = require("@zaiusinc/app-sdk");
|
|
5
|
+
// Mock the logger
|
|
6
|
+
jest.mock('@zaiusinc/app-sdk', () => ({
|
|
7
|
+
logger: {
|
|
8
|
+
info: jest.fn()
|
|
9
|
+
},
|
|
10
|
+
LogVisibility: {
|
|
11
|
+
Zaius: 'zaius'
|
|
12
|
+
},
|
|
13
|
+
Headers: jest.fn(),
|
|
14
|
+
Response: jest.fn()
|
|
15
|
+
}));
|
|
16
|
+
describe('ToolLogger', () => {
|
|
17
|
+
const mockLogger = app_sdk_1.logger;
|
|
18
|
+
beforeEach(() => {
|
|
19
|
+
jest.clearAllMocks();
|
|
20
|
+
});
|
|
21
|
+
// Helper function to check JSON string logs
|
|
22
|
+
const expectJsonLog = (expectedData) => {
|
|
23
|
+
expect(mockLogger.info).toHaveBeenCalledWith(app_sdk_1.LogVisibility.Zaius, JSON.stringify(expectedData));
|
|
24
|
+
};
|
|
25
|
+
const createMockRequest = (overrides = {}) => {
|
|
26
|
+
const defaultRequest = {
|
|
27
|
+
path: '/test-tool',
|
|
28
|
+
bodyJSON: {
|
|
29
|
+
parameters: {
|
|
30
|
+
name: 'test',
|
|
31
|
+
value: 'data'
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
headers: {
|
|
35
|
+
get: jest.fn().mockReturnValue('application/json')
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
return { ...defaultRequest, ...overrides };
|
|
39
|
+
};
|
|
40
|
+
const createMockResponse = (status = 200, bodyJSON = {}, headers = {}) => {
|
|
41
|
+
const mockHeaders = {
|
|
42
|
+
get: jest.fn().mockImplementation((name) => {
|
|
43
|
+
if (name === 'content-type')
|
|
44
|
+
return 'application/json';
|
|
45
|
+
return headers[name] || null;
|
|
46
|
+
})
|
|
47
|
+
};
|
|
48
|
+
return {
|
|
49
|
+
status,
|
|
50
|
+
bodyJSON,
|
|
51
|
+
headers: mockHeaders
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
describe('logRequest', () => {
|
|
55
|
+
it('should log request with parameters', () => {
|
|
56
|
+
const req = createMockRequest();
|
|
57
|
+
ToolLogger_1.ToolLogger.logRequest(req);
|
|
58
|
+
const expectedLog = {
|
|
59
|
+
event: 'opal_tool_request',
|
|
60
|
+
path: '/test-tool',
|
|
61
|
+
parameters: {
|
|
62
|
+
name: 'test',
|
|
63
|
+
value: 'data'
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
expect(mockLogger.info).toHaveBeenCalledWith(app_sdk_1.LogVisibility.Zaius, JSON.stringify(expectedLog));
|
|
67
|
+
});
|
|
68
|
+
it('should handle request without parameters', () => {
|
|
69
|
+
const req = createMockRequest({
|
|
70
|
+
bodyJSON: null
|
|
71
|
+
});
|
|
72
|
+
ToolLogger_1.ToolLogger.logRequest(req);
|
|
73
|
+
expectJsonLog({
|
|
74
|
+
event: 'opal_tool_request',
|
|
75
|
+
path: '/test-tool',
|
|
76
|
+
parameters: null
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
it('should use bodyJSON as parameters when no parameters field exists', () => {
|
|
80
|
+
const req = createMockRequest({
|
|
81
|
+
bodyJSON: {
|
|
82
|
+
name: 'direct',
|
|
83
|
+
action: 'test'
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
ToolLogger_1.ToolLogger.logRequest(req);
|
|
87
|
+
expectJsonLog({
|
|
88
|
+
event: 'opal_tool_request',
|
|
89
|
+
path: '/test-tool',
|
|
90
|
+
parameters: {
|
|
91
|
+
name: 'direct',
|
|
92
|
+
action: 'test'
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
it('should redact all sensitive field variations', () => {
|
|
97
|
+
const req = createMockRequest({
|
|
98
|
+
bodyJSON: {
|
|
99
|
+
parameters: {
|
|
100
|
+
username: 'john',
|
|
101
|
+
password: 'secret123',
|
|
102
|
+
api_key: 'key123',
|
|
103
|
+
secret: 'mysecret',
|
|
104
|
+
token: 'abc123',
|
|
105
|
+
auth: 'authdata',
|
|
106
|
+
credentials: 'creds',
|
|
107
|
+
access_token: 'access123',
|
|
108
|
+
refresh_token: 'refresh123',
|
|
109
|
+
private_key: 'privatekey',
|
|
110
|
+
client_secret: 'clientsecret',
|
|
111
|
+
normal_field: 'visible'
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
ToolLogger_1.ToolLogger.logRequest(req);
|
|
116
|
+
expectJsonLog({
|
|
117
|
+
event: 'opal_tool_request',
|
|
118
|
+
path: '/test-tool',
|
|
119
|
+
parameters: {
|
|
120
|
+
username: 'john',
|
|
121
|
+
password: '[REDACTED]',
|
|
122
|
+
api_key: '[REDACTED]',
|
|
123
|
+
secret: '[REDACTED]',
|
|
124
|
+
token: '[REDACTED]',
|
|
125
|
+
auth: '[REDACTED]',
|
|
126
|
+
credentials: '[REDACTED]',
|
|
127
|
+
access_token: '[REDACTED]',
|
|
128
|
+
refresh_token: '[REDACTED]',
|
|
129
|
+
private_key: '[REDACTED]',
|
|
130
|
+
client_secret: '[REDACTED]',
|
|
131
|
+
normal_field: 'visible'
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
it('should redact sensitive fields with case variations', () => {
|
|
136
|
+
const req = createMockRequest({
|
|
137
|
+
bodyJSON: {
|
|
138
|
+
parameters: {
|
|
139
|
+
PASSWORD: 'secret1',
|
|
140
|
+
API_KEY: 'secret2',
|
|
141
|
+
clientSecret: 'secret3',
|
|
142
|
+
user_password: 'secret4',
|
|
143
|
+
oauth_token: 'secret5',
|
|
144
|
+
ssh_key: 'secret6',
|
|
145
|
+
normal_field: 'visible'
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
ToolLogger_1.ToolLogger.logRequest(req);
|
|
150
|
+
expectJsonLog({
|
|
151
|
+
event: 'opal_tool_request',
|
|
152
|
+
path: '/test-tool',
|
|
153
|
+
parameters: {
|
|
154
|
+
PASSWORD: '[REDACTED]',
|
|
155
|
+
API_KEY: '[REDACTED]',
|
|
156
|
+
clientSecret: '[REDACTED]',
|
|
157
|
+
user_password: '[REDACTED]',
|
|
158
|
+
oauth_token: '[REDACTED]',
|
|
159
|
+
ssh_key: '[REDACTED]',
|
|
160
|
+
normal_field: 'visible'
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
it('should truncate long string values', () => {
|
|
165
|
+
const longString = 'a'.repeat(150);
|
|
166
|
+
const req = createMockRequest({
|
|
167
|
+
bodyJSON: {
|
|
168
|
+
parameters: {
|
|
169
|
+
description: longString,
|
|
170
|
+
short_field: 'normal'
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
ToolLogger_1.ToolLogger.logRequest(req);
|
|
175
|
+
expectJsonLog({
|
|
176
|
+
event: 'opal_tool_request',
|
|
177
|
+
path: '/test-tool',
|
|
178
|
+
parameters: {
|
|
179
|
+
description: `${'a'.repeat(100)}... (truncated, 150 chars total)`,
|
|
180
|
+
short_field: 'normal'
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
it('should truncate large arrays', () => {
|
|
185
|
+
const largeArray = Array.from({ length: 15 }, (_, i) => `item${i}`);
|
|
186
|
+
const req = createMockRequest({
|
|
187
|
+
bodyJSON: {
|
|
188
|
+
parameters: {
|
|
189
|
+
items: largeArray,
|
|
190
|
+
small_array: ['a', 'b']
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
ToolLogger_1.ToolLogger.logRequest(req);
|
|
195
|
+
expectJsonLog({
|
|
196
|
+
event: 'opal_tool_request',
|
|
197
|
+
path: '/test-tool',
|
|
198
|
+
parameters: {
|
|
199
|
+
items: [
|
|
200
|
+
...largeArray.slice(0, 10),
|
|
201
|
+
'... (5 more items truncated)'
|
|
202
|
+
],
|
|
203
|
+
small_array: ['a', 'b']
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
});
|
|
207
|
+
it('should handle nested objects with sensitive fields', () => {
|
|
208
|
+
const req = createMockRequest({
|
|
209
|
+
bodyJSON: {
|
|
210
|
+
parameters: {
|
|
211
|
+
user: {
|
|
212
|
+
name: 'John',
|
|
213
|
+
email: 'john@example.com',
|
|
214
|
+
password: 'secret123'
|
|
215
|
+
},
|
|
216
|
+
config: {
|
|
217
|
+
database: {
|
|
218
|
+
host: 'localhost',
|
|
219
|
+
port: 5432,
|
|
220
|
+
password: 'dbpass'
|
|
221
|
+
},
|
|
222
|
+
api_key: 'apikey123'
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
ToolLogger_1.ToolLogger.logRequest(req);
|
|
228
|
+
expectJsonLog({
|
|
229
|
+
event: 'opal_tool_request',
|
|
230
|
+
path: '/test-tool',
|
|
231
|
+
parameters: {
|
|
232
|
+
user: {
|
|
233
|
+
name: 'John',
|
|
234
|
+
email: '[REDACTED]',
|
|
235
|
+
password: '[REDACTED]'
|
|
236
|
+
},
|
|
237
|
+
config: {
|
|
238
|
+
database: {
|
|
239
|
+
host: 'localhost',
|
|
240
|
+
port: 5432,
|
|
241
|
+
password: '[REDACTED]'
|
|
242
|
+
},
|
|
243
|
+
api_key: '[REDACTED]'
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
});
|
|
248
|
+
it('should handle null and undefined values', () => {
|
|
249
|
+
const req = createMockRequest({
|
|
250
|
+
bodyJSON: {
|
|
251
|
+
parameters: {
|
|
252
|
+
nullValue: null,
|
|
253
|
+
undefinedValue: undefined,
|
|
254
|
+
emptyString: '',
|
|
255
|
+
zero: 0,
|
|
256
|
+
false: false,
|
|
257
|
+
password: null // sensitive field with null value
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
});
|
|
261
|
+
ToolLogger_1.ToolLogger.logRequest(req);
|
|
262
|
+
expectJsonLog({
|
|
263
|
+
event: 'opal_tool_request',
|
|
264
|
+
path: '/test-tool',
|
|
265
|
+
parameters: {
|
|
266
|
+
nullValue: null,
|
|
267
|
+
emptyString: '',
|
|
268
|
+
zero: 0,
|
|
269
|
+
false: false,
|
|
270
|
+
password: '[REDACTED]'
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
});
|
|
274
|
+
it('should handle arrays in sensitive fields', () => {
|
|
275
|
+
const req = createMockRequest({
|
|
276
|
+
bodyJSON: {
|
|
277
|
+
parameters: {
|
|
278
|
+
credentials: ['user', 'pass', 'token'],
|
|
279
|
+
public_list: ['item1', 'item2']
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
});
|
|
283
|
+
ToolLogger_1.ToolLogger.logRequest(req);
|
|
284
|
+
expectJsonLog({
|
|
285
|
+
event: 'opal_tool_request',
|
|
286
|
+
path: '/test-tool',
|
|
287
|
+
parameters: {
|
|
288
|
+
credentials: '[REDACTED]',
|
|
289
|
+
public_list: ['item1', 'item2']
|
|
290
|
+
}
|
|
291
|
+
});
|
|
292
|
+
});
|
|
293
|
+
it('should handle objects in sensitive fields', () => {
|
|
294
|
+
const req = createMockRequest({
|
|
295
|
+
bodyJSON: {
|
|
296
|
+
parameters: {
|
|
297
|
+
auth: {
|
|
298
|
+
username: 'john',
|
|
299
|
+
password: 'secret'
|
|
300
|
+
},
|
|
301
|
+
public_config: {
|
|
302
|
+
timeout: 30,
|
|
303
|
+
retries: 3
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
});
|
|
308
|
+
ToolLogger_1.ToolLogger.logRequest(req);
|
|
309
|
+
expectJsonLog({
|
|
310
|
+
event: 'opal_tool_request',
|
|
311
|
+
path: '/test-tool',
|
|
312
|
+
parameters: {
|
|
313
|
+
auth: '[REDACTED]',
|
|
314
|
+
public_config: {
|
|
315
|
+
timeout: 30,
|
|
316
|
+
retries: 3
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
});
|
|
320
|
+
});
|
|
321
|
+
it('should respect max depth to prevent infinite recursion', () => {
|
|
322
|
+
const deepObject = { level: 0, data: 'test' };
|
|
323
|
+
let current = deepObject;
|
|
324
|
+
// Create a very deep nested object (deeper than maxDepth)
|
|
325
|
+
for (let i = 1; i <= 10; i++) {
|
|
326
|
+
current.nested = { level: i, data: `level${i}` };
|
|
327
|
+
current = current.nested;
|
|
328
|
+
}
|
|
329
|
+
const req = createMockRequest({
|
|
330
|
+
bodyJSON: { parameters: { deep: deepObject } }
|
|
331
|
+
});
|
|
332
|
+
// Should not throw error or cause infinite recursion
|
|
333
|
+
expect(() => ToolLogger_1.ToolLogger.logRequest(req)).not.toThrow();
|
|
334
|
+
expect(mockLogger.info).toHaveBeenCalled();
|
|
335
|
+
});
|
|
336
|
+
});
|
|
337
|
+
describe('logResponse', () => {
|
|
338
|
+
it('should log successful response with all details', () => {
|
|
339
|
+
const req = createMockRequest();
|
|
340
|
+
const response = createMockResponse(200, { result: 'success', data: 'test' });
|
|
341
|
+
ToolLogger_1.ToolLogger.logResponse(req, response, 150);
|
|
342
|
+
const expectedLog = {
|
|
343
|
+
event: 'opal_tool_response',
|
|
344
|
+
path: '/test-tool',
|
|
345
|
+
duration: '150ms',
|
|
346
|
+
status: 200,
|
|
347
|
+
contentType: 'application/json',
|
|
348
|
+
contentLength: 34, // JSON.stringify({ result: 'success', data: 'test' }).length
|
|
349
|
+
success: true
|
|
350
|
+
};
|
|
351
|
+
expect(mockLogger.info).toHaveBeenCalledWith(app_sdk_1.LogVisibility.Zaius, JSON.stringify(expectedLog));
|
|
352
|
+
});
|
|
353
|
+
it('should log error response', () => {
|
|
354
|
+
const req = createMockRequest();
|
|
355
|
+
const response = createMockResponse(400, { error: 'Bad request' });
|
|
356
|
+
ToolLogger_1.ToolLogger.logResponse(req, response, 75);
|
|
357
|
+
expectJsonLog({
|
|
358
|
+
event: 'opal_tool_response',
|
|
359
|
+
path: '/test-tool',
|
|
360
|
+
duration: '75ms',
|
|
361
|
+
status: 400,
|
|
362
|
+
contentType: 'application/json',
|
|
363
|
+
contentLength: 23,
|
|
364
|
+
success: false
|
|
365
|
+
});
|
|
366
|
+
});
|
|
367
|
+
it('should handle response without bodyJSON', () => {
|
|
368
|
+
const req = createMockRequest();
|
|
369
|
+
const response = createMockResponse(204);
|
|
370
|
+
response.bodyJSON = undefined;
|
|
371
|
+
ToolLogger_1.ToolLogger.logResponse(req, response);
|
|
372
|
+
expectJsonLog({
|
|
373
|
+
event: 'opal_tool_response',
|
|
374
|
+
path: '/test-tool',
|
|
375
|
+
status: 204,
|
|
376
|
+
contentType: 'application/json',
|
|
377
|
+
contentLength: 0,
|
|
378
|
+
success: true
|
|
379
|
+
});
|
|
380
|
+
});
|
|
381
|
+
it('should handle response without processing time', () => {
|
|
382
|
+
const req = createMockRequest();
|
|
383
|
+
const response = createMockResponse(200, { data: 'test' });
|
|
384
|
+
ToolLogger_1.ToolLogger.logResponse(req, response);
|
|
385
|
+
expectJsonLog({
|
|
386
|
+
event: 'opal_tool_response',
|
|
387
|
+
path: '/test-tool',
|
|
388
|
+
status: 200,
|
|
389
|
+
contentType: 'application/json',
|
|
390
|
+
contentLength: 15,
|
|
391
|
+
success: true
|
|
392
|
+
});
|
|
393
|
+
});
|
|
394
|
+
it('should handle unknown content type', () => {
|
|
395
|
+
const req = createMockRequest();
|
|
396
|
+
const response = createMockResponse(200, { data: 'test' });
|
|
397
|
+
response.headers.get = jest.fn().mockReturnValue(null);
|
|
398
|
+
ToolLogger_1.ToolLogger.logResponse(req, response);
|
|
399
|
+
expectJsonLog({
|
|
400
|
+
event: 'opal_tool_response',
|
|
401
|
+
path: '/test-tool',
|
|
402
|
+
status: 200,
|
|
403
|
+
contentType: 'unknown',
|
|
404
|
+
contentLength: 15,
|
|
405
|
+
success: true
|
|
406
|
+
});
|
|
407
|
+
});
|
|
408
|
+
it('should handle content length calculation error', () => {
|
|
409
|
+
const req = createMockRequest();
|
|
410
|
+
const circularObj = { name: 'test' };
|
|
411
|
+
circularObj.self = circularObj; // Create circular reference
|
|
412
|
+
const response = createMockResponse(200, circularObj);
|
|
413
|
+
ToolLogger_1.ToolLogger.logResponse(req, response);
|
|
414
|
+
expectJsonLog({
|
|
415
|
+
event: 'opal_tool_response',
|
|
416
|
+
path: '/test-tool',
|
|
417
|
+
status: 200,
|
|
418
|
+
contentType: 'application/json',
|
|
419
|
+
contentLength: 'unknown',
|
|
420
|
+
success: true
|
|
421
|
+
});
|
|
422
|
+
});
|
|
423
|
+
it('should correctly identify success status codes', () => {
|
|
424
|
+
const req = createMockRequest();
|
|
425
|
+
const testCases = [
|
|
426
|
+
{ status: 200, expected: true },
|
|
427
|
+
{ status: 201, expected: true },
|
|
428
|
+
{ status: 204, expected: true },
|
|
429
|
+
{ status: 299, expected: true },
|
|
430
|
+
{ status: 300, expected: false },
|
|
431
|
+
{ status: 400, expected: false },
|
|
432
|
+
{ status: 404, expected: false },
|
|
433
|
+
{ status: 500, expected: false }
|
|
434
|
+
];
|
|
435
|
+
testCases.forEach(({ status, expected }) => {
|
|
436
|
+
mockLogger.info.mockClear();
|
|
437
|
+
const response = createMockResponse(status);
|
|
438
|
+
ToolLogger_1.ToolLogger.logResponse(req, response);
|
|
439
|
+
expectJsonLog({
|
|
440
|
+
event: 'opal_tool_response',
|
|
441
|
+
path: '/test-tool',
|
|
442
|
+
status,
|
|
443
|
+
contentType: 'application/json',
|
|
444
|
+
contentLength: 2,
|
|
445
|
+
success: expected
|
|
446
|
+
});
|
|
447
|
+
});
|
|
448
|
+
});
|
|
449
|
+
it('should handle different content types', () => {
|
|
450
|
+
const req = createMockRequest();
|
|
451
|
+
const testCases = [
|
|
452
|
+
'application/json',
|
|
453
|
+
'text/plain',
|
|
454
|
+
'application/xml',
|
|
455
|
+
'text/html'
|
|
456
|
+
];
|
|
457
|
+
testCases.forEach((contentType) => {
|
|
458
|
+
mockLogger.info.mockClear();
|
|
459
|
+
const response = createMockResponse(200, { data: 'test' });
|
|
460
|
+
response.headers.get = jest.fn().mockReturnValue(contentType);
|
|
461
|
+
ToolLogger_1.ToolLogger.logResponse(req, response);
|
|
462
|
+
expectJsonLog({
|
|
463
|
+
event: 'opal_tool_response',
|
|
464
|
+
path: '/test-tool',
|
|
465
|
+
status: 200,
|
|
466
|
+
contentType,
|
|
467
|
+
contentLength: 15,
|
|
468
|
+
success: true
|
|
469
|
+
});
|
|
470
|
+
});
|
|
471
|
+
});
|
|
472
|
+
});
|
|
473
|
+
describe('edge cases', () => {
|
|
474
|
+
it('should handle empty request bodyJSON', () => {
|
|
475
|
+
const req = createMockRequest({
|
|
476
|
+
bodyJSON: {}
|
|
477
|
+
});
|
|
478
|
+
ToolLogger_1.ToolLogger.logRequest(req);
|
|
479
|
+
expectJsonLog({
|
|
480
|
+
event: 'opal_tool_request',
|
|
481
|
+
path: '/test-tool',
|
|
482
|
+
parameters: {}
|
|
483
|
+
});
|
|
484
|
+
});
|
|
485
|
+
it('should handle request with only parameters field', () => {
|
|
486
|
+
const req = createMockRequest({
|
|
487
|
+
bodyJSON: {
|
|
488
|
+
parameters: {
|
|
489
|
+
field: 'value' // Changed from 'key' to 'field' to avoid sensitive field detection
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
});
|
|
493
|
+
ToolLogger_1.ToolLogger.logRequest(req);
|
|
494
|
+
expectJsonLog({
|
|
495
|
+
event: 'opal_tool_request',
|
|
496
|
+
path: '/test-tool',
|
|
497
|
+
parameters: {
|
|
498
|
+
field: 'value'
|
|
499
|
+
}
|
|
500
|
+
});
|
|
501
|
+
});
|
|
502
|
+
it('should handle mixed data types in parameters', () => {
|
|
503
|
+
const req = createMockRequest({
|
|
504
|
+
bodyJSON: {
|
|
505
|
+
parameters: {
|
|
506
|
+
string: 'text',
|
|
507
|
+
number: 42,
|
|
508
|
+
boolean: true,
|
|
509
|
+
array: [1, 2, 3],
|
|
510
|
+
object: { nested: 'value' },
|
|
511
|
+
nullValue: null,
|
|
512
|
+
password: 'secret'
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
});
|
|
516
|
+
ToolLogger_1.ToolLogger.logRequest(req);
|
|
517
|
+
expectJsonLog({
|
|
518
|
+
event: 'opal_tool_request',
|
|
519
|
+
path: '/test-tool',
|
|
520
|
+
parameters: {
|
|
521
|
+
string: 'text',
|
|
522
|
+
number: 42,
|
|
523
|
+
boolean: true,
|
|
524
|
+
array: [1, 2, 3],
|
|
525
|
+
object: { nested: 'value' },
|
|
526
|
+
nullValue: null,
|
|
527
|
+
password: '[REDACTED]'
|
|
528
|
+
}
|
|
529
|
+
});
|
|
530
|
+
});
|
|
531
|
+
});
|
|
532
|
+
});
|
|
533
|
+
//# sourceMappingURL=ToolLogger.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ToolLogger.test.js","sourceRoot":"","sources":["../../src/logging/ToolLogger.test.ts"],"names":[],"mappings":";;AAAA,6CAA0C;AAC1C,+CAA0D;AAG1D,kBAAkB;AAClB,IAAI,CAAC,IAAI,CAAC,mBAAmB,EAAE,GAAG,EAAE,CAAC,CAAC;IACpC,MAAM,EAAE;QACN,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE;KAChB;IACD,aAAa,EAAE;QACb,KAAK,EAAE,OAAO;KACf;IACD,OAAO,EAAE,IAAI,CAAC,EAAE,EAAE;IAClB,QAAQ,EAAE,IAAI,CAAC,EAAE,EAAE;CACpB,CAAC,CAAC,CAAC;AAEJ,QAAQ,CAAC,YAAY,EAAE,GAAG,EAAE;IAC1B,MAAM,UAAU,GAAG,gBAAoC,CAAC;IAExD,UAAU,CAAC,GAAG,EAAE;QACd,IAAI,CAAC,aAAa,EAAE,CAAC;IACvB,CAAC,CAAC,CAAC;IAEH,4CAA4C;IAC5C,MAAM,aAAa,GAAG,CAAC,YAAiB,EAAE,EAAE;QAC1C,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,oBAAoB,CAC1C,uBAAa,CAAC,KAAK,EACnB,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,CAC7B,CAAC;IACJ,CAAC,CAAC;IAEF,MAAM,iBAAiB,GAAG,CAAC,YAAiB,EAAE,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3B,aAAa,CAAC;gBACZ,KAAK,EAAE,mBAAmB;gBAC1B,IAAI,EAAE,YAAY;gBAClB,UAAU,EAAE;oBACV,MAAM,EAAE,MAAM;oBACd,MAAM,EAAE,EAAE;oBACV,OAAO,EAAE,IAAI;oBACb,KAAK,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;oBAChB,MAAM,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE;oBAC3B,SAAS,EAAE,IAAI;oBACf,QAAQ,EAAE,YAAY;iBACvB;aACF,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { GlobalFunction, Response, amendLogContext } from '@zaiusinc/app-sdk';
|
|
2
2
|
import { authenticateGlobalRequest, extractAuthData } from '../auth/AuthUtils';
|
|
3
3
|
import { toolsService } from '../service/Service';
|
|
4
|
+
import { ToolLogger } from '../logging/ToolLogger';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Abstract base class for global tool-based function execution
|
|
@@ -24,6 +25,8 @@ export abstract class GlobalToolFunction extends GlobalFunction {
|
|
|
24
25
|
* @returns Response as the HTTP response
|
|
25
26
|
*/
|
|
26
27
|
public async perform(): Promise<Response> {
|
|
28
|
+
const startTime = Date.now();
|
|
29
|
+
|
|
27
30
|
// Extract customer_id from auth data for global context attribution
|
|
28
31
|
const authInfo = extractAuthData(this.request);
|
|
29
32
|
const customerId = authInfo?.authData?.credentials?.customer_id;
|
|
@@ -33,6 +36,14 @@ export abstract class GlobalToolFunction extends GlobalFunction {
|
|
|
33
36
|
customerId: customerId || ''
|
|
34
37
|
});
|
|
35
38
|
|
|
39
|
+
ToolLogger.logRequest(this.request);
|
|
40
|
+
|
|
41
|
+
const response = await this.handleRequest();
|
|
42
|
+
ToolLogger.logResponse(this.request, response, Date.now() - startTime);
|
|
43
|
+
return response;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
private async handleRequest(): Promise<Response> {
|
|
36
47
|
if (!(await this.authorizeRequest())) {
|
|
37
48
|
return new Response(403, { error: 'Forbidden' });
|
|
38
49
|
}
|