@optimizely-opal/opal-tool-ocp-sdk 1.0.0-beta.2 → 1.0.0-beta.3
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/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 +14 -1
- package/dist/function/ToolFunction.js.map +1 -1
- package/dist/function/ToolFunction.test.js +3 -0
- package/dist/function/ToolFunction.test.js.map +1 -1
- package/dist/logging/ToolLogger.d.ts +34 -0
- package/dist/logging/ToolLogger.d.ts.map +1 -0
- package/dist/logging/ToolLogger.js +153 -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 +646 -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 +3 -0
- package/src/function/ToolFunction.ts +19 -1
- package/src/logging/ToolLogger.test.ts +753 -0
- package/src/logging/ToolLogger.ts +177 -0
|
@@ -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
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Function, Response, amendLogContext } from '@zaiusinc/app-sdk';
|
|
2
2
|
import { authenticateRegularRequest } 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 tool-based function execution
|
|
@@ -19,12 +20,28 @@ export abstract class ToolFunction extends Function {
|
|
|
19
20
|
}
|
|
20
21
|
|
|
21
22
|
/**
|
|
22
|
-
* Process the incoming request
|
|
23
|
+
* Process the incoming request with logging
|
|
23
24
|
*
|
|
24
25
|
* @returns Response as the HTTP response
|
|
25
26
|
*/
|
|
26
27
|
public async perform(): Promise<Response> {
|
|
28
|
+
const startTime = Date.now();
|
|
27
29
|
amendLogContext({ opalThreadId: this.request.headers.get('x-opal-thread-id') || '' });
|
|
30
|
+
|
|
31
|
+
ToolLogger.logRequest(this.request);
|
|
32
|
+
|
|
33
|
+
const response = await this.handleRequest();
|
|
34
|
+
|
|
35
|
+
ToolLogger.logResponse(this.request, response, Date.now() - startTime);
|
|
36
|
+
return response;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Handle the core request processing logic
|
|
41
|
+
*
|
|
42
|
+
* @returns Response as the HTTP response
|
|
43
|
+
*/
|
|
44
|
+
private async handleRequest(): Promise<Response> {
|
|
28
45
|
if (!(await this.authorizeRequest())) {
|
|
29
46
|
return new Response(403, { error: 'Forbidden' });
|
|
30
47
|
}
|
|
@@ -33,6 +50,7 @@ export abstract class ToolFunction extends Function {
|
|
|
33
50
|
const isReady = await this.ready();
|
|
34
51
|
return new Response(200, { ready: isReady });
|
|
35
52
|
}
|
|
53
|
+
|
|
36
54
|
// Pass 'this' as context so decorated methods can use the existing instance
|
|
37
55
|
return toolsService.processRequest(this.request, this);
|
|
38
56
|
}
|