@optimizely-opal/opal-tool-ocp-sdk 1.0.0-OCP-1442.1 → 1.0.0-OCP-1442.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.
@@ -6,7 +6,9 @@ import * as App from '@zaiusinc/app-sdk';
6
6
  */
7
7
  export class ToolLogger {
8
8
  private static readonly SENSITIVE_FIELDS = [
9
+ // Authentication / secrets
9
10
  'password',
11
+ 'pass',
10
12
  'secret',
11
13
  'key',
12
14
  'token',
@@ -16,7 +18,34 @@ export class ToolLogger {
16
18
  'refresh_token',
17
19
  'api_key',
18
20
  'private_key',
19
- 'client_secret'
21
+ 'client_secret',
22
+ 'session_token',
23
+ 'authorization',
24
+
25
+ // Payment-related
26
+ 'card_number',
27
+ 'credit_card',
28
+ 'cvv',
29
+ 'expiry_date',
30
+
31
+ // Personal info
32
+ 'ssn', // social security number
33
+ 'nid', // national ID
34
+ 'passport',
35
+ 'dob', // date of birth
36
+ 'email',
37
+ 'phone',
38
+ 'address',
39
+
40
+ // Misc / environment
41
+ 'otp',
42
+ 'pin',
43
+ 'security_answer',
44
+ 'security_question',
45
+ 'signing_key',
46
+ 'encryption_key',
47
+ 'jwt',
48
+ 'bearer_token'
20
49
  ];
21
50
 
22
51
  private static readonly MAX_PARAM_LENGTH = 100;
@@ -31,8 +60,8 @@ export class ToolLogger {
31
60
  }
32
61
 
33
62
  if (typeof data === 'string') {
34
- return data.length > this.MAX_PARAM_LENGTH
35
- ? `${data.substring(0, this.MAX_PARAM_LENGTH)}... (truncated, ${data.length} chars total)`
63
+ return data.length > ToolLogger.MAX_PARAM_LENGTH
64
+ ? `${data.substring(0, ToolLogger.MAX_PARAM_LENGTH)}... (truncated, ${data.length} chars total)`
36
65
  : data;
37
66
  }
38
67
 
@@ -41,10 +70,10 @@ export class ToolLogger {
41
70
  }
42
71
 
43
72
  if (Array.isArray(data)) {
44
- const truncated = data.slice(0, this.MAX_ARRAY_ITEMS);
45
- const result = truncated.map((item) => this.redactSensitiveData(item, maxDepth - 1));
46
- if (data.length > this.MAX_ARRAY_ITEMS) {
47
- result.push(`... (${data.length - this.MAX_ARRAY_ITEMS} more items truncated)`);
73
+ const truncated = data.slice(0, ToolLogger.MAX_ARRAY_ITEMS);
74
+ const result = truncated.map((item) => ToolLogger.redactSensitiveData(item, maxDepth - 1));
75
+ if (data.length > ToolLogger.MAX_ARRAY_ITEMS) {
76
+ result.push(`... (${data.length - ToolLogger.MAX_ARRAY_ITEMS} more items truncated)`);
48
77
  }
49
78
  return result;
50
79
  }
@@ -53,12 +82,12 @@ export class ToolLogger {
53
82
  const result: any = {};
54
83
  for (const [key, value] of Object.entries(data)) {
55
84
  // Check if this field contains sensitive data
56
- const isSensitive = this.isSensitiveField(key);
85
+ const isSensitive = ToolLogger.isSensitiveField(key);
57
86
 
58
87
  if (isSensitive) {
59
88
  result[key] = '[REDACTED]';
60
89
  } else {
61
- result[key] = this.redactSensitiveData(value, maxDepth - 1);
90
+ result[key] = ToolLogger.redactSensitiveData(value, maxDepth - 1);
62
91
  }
63
92
  }
64
93
  return result;
@@ -72,7 +101,7 @@ export class ToolLogger {
72
101
  */
73
102
  private static isSensitiveField(fieldName: string): boolean {
74
103
  const lowerKey = fieldName.toLowerCase();
75
- return this.SENSITIVE_FIELDS.some((sensitiveField) =>
104
+ return ToolLogger.SENSITIVE_FIELDS.some((sensitiveField) =>
76
105
  lowerKey.includes(sensitiveField)
77
106
  );
78
107
  }
@@ -85,23 +114,30 @@ export class ToolLogger {
85
114
  return null;
86
115
  }
87
116
 
88
- return this.redactSensitiveData(params);
117
+ return ToolLogger.redactSensitiveData(params);
89
118
  }
90
119
 
91
120
  /**
92
121
  * Calculates content length of response data
93
122
  */
94
- private static calculateContentLength(responseData?: any): number | string {
95
- if (!responseData) {
123
+ private static calculateContentLength(response?: App.Response) {
124
+ if (!response) {
96
125
  return 0;
97
126
  }
98
127
 
99
128
  try {
100
- const serialized = JSON.stringify(responseData);
101
- return serialized.length;
129
+ if (response?.bodyJSON) {
130
+ const responseBodyJson = JSON.stringify(response.bodyJSON);
131
+ console.log('BodyJson length', responseBodyJson.length || 0);
132
+ return responseBodyJson.length;
133
+ }
102
134
  } catch {
135
+ console.log("Circular reference or JSON error, returning 'unknown'");
103
136
  return 'unknown';
104
137
  }
138
+
139
+ console.log('Body length', response.body?.length || 0);
140
+ return response.body?.length || 0;
105
141
  }
106
142
 
107
143
  /**
@@ -114,11 +150,11 @@ export class ToolLogger {
114
150
  const requestLog = {
115
151
  event: 'opal_tool_request',
116
152
  path: req.path,
117
- parameters: this.createParameterSummary(params)
153
+ parameters: ToolLogger.createParameterSummary(params)
118
154
  };
119
155
 
120
156
  // Log with Zaius audience so developers only see requests for accounts they have access to
121
- logger.info(LogVisibility.Zaius, requestLog);
157
+ logger.info(LogVisibility.Zaius, JSON.stringify(requestLog));
122
158
  }
123
159
 
124
160
  /**
@@ -129,18 +165,20 @@ export class ToolLogger {
129
165
  response: App.Response,
130
166
  processingTimeMs?: number
131
167
  ): void {
132
-
168
+ console.log('response', response);
169
+ console.log('response body json', response.bodyJSON);
170
+ console.log('response body', response.body);
133
171
  const responseLog = {
134
172
  event: 'opal_tool_response',
135
173
  path: req.path,
136
174
  duration: processingTimeMs ? `${processingTimeMs}ms` : undefined,
137
175
  status: response.status,
138
176
  contentType: response.headers?.get('content-type') || 'unknown',
139
- contentLength: this.calculateContentLength(response.bodyJSON),
177
+ contentLength: ToolLogger.calculateContentLength(response),
140
178
  success: response.status >= 200 && response.status < 300
141
179
  };
142
180
 
143
181
  // Log with Zaius audience so developers only see requests for accounts they have access to
144
- logger.info(LogVisibility.Zaius, responseLog);
182
+ logger.info(LogVisibility.Zaius, JSON.stringify(responseLog));
145
183
  }
146
184
  }