@optimizely-opal/opal-tool-ocp-sdk 1.0.0-OCP-1442.5 → 1.0.0-OCP-1449.1

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 (64) hide show
  1. package/README.md +114 -72
  2. package/dist/auth/AuthUtils.d.ts +12 -5
  3. package/dist/auth/AuthUtils.d.ts.map +1 -1
  4. package/dist/auth/AuthUtils.js +80 -25
  5. package/dist/auth/AuthUtils.js.map +1 -1
  6. package/dist/auth/AuthUtils.test.js +161 -117
  7. package/dist/auth/AuthUtils.test.js.map +1 -1
  8. package/dist/function/GlobalToolFunction.d.ts +1 -1
  9. package/dist/function/GlobalToolFunction.d.ts.map +1 -1
  10. package/dist/function/GlobalToolFunction.js +17 -4
  11. package/dist/function/GlobalToolFunction.js.map +1 -1
  12. package/dist/function/GlobalToolFunction.test.js +54 -8
  13. package/dist/function/GlobalToolFunction.test.js.map +1 -1
  14. package/dist/function/ToolFunction.d.ts +1 -1
  15. package/dist/function/ToolFunction.d.ts.map +1 -1
  16. package/dist/function/ToolFunction.js +24 -4
  17. package/dist/function/ToolFunction.js.map +1 -1
  18. package/dist/function/ToolFunction.test.js +260 -8
  19. package/dist/function/ToolFunction.test.js.map +1 -1
  20. package/dist/index.d.ts +1 -0
  21. package/dist/index.d.ts.map +1 -1
  22. package/dist/index.js +1 -0
  23. package/dist/index.js.map +1 -1
  24. package/dist/logging/ToolLogger.d.ts.map +1 -1
  25. package/dist/logging/ToolLogger.js +13 -12
  26. package/dist/logging/ToolLogger.js.map +1 -1
  27. package/dist/logging/ToolLogger.test.js +171 -0
  28. package/dist/logging/ToolLogger.test.js.map +1 -1
  29. package/dist/service/Service.d.ts +88 -2
  30. package/dist/service/Service.d.ts.map +1 -1
  31. package/dist/service/Service.js +227 -55
  32. package/dist/service/Service.js.map +1 -1
  33. package/dist/service/Service.test.js +464 -36
  34. package/dist/service/Service.test.js.map +1 -1
  35. package/dist/types/ToolError.d.ts +59 -0
  36. package/dist/types/ToolError.d.ts.map +1 -0
  37. package/dist/types/ToolError.js +79 -0
  38. package/dist/types/ToolError.js.map +1 -0
  39. package/dist/types/ToolError.test.d.ts +2 -0
  40. package/dist/types/ToolError.test.d.ts.map +1 -0
  41. package/dist/types/ToolError.test.js +161 -0
  42. package/dist/types/ToolError.test.js.map +1 -0
  43. package/dist/validation/ParameterValidator.d.ts +5 -16
  44. package/dist/validation/ParameterValidator.d.ts.map +1 -1
  45. package/dist/validation/ParameterValidator.js +10 -3
  46. package/dist/validation/ParameterValidator.js.map +1 -1
  47. package/dist/validation/ParameterValidator.test.js +186 -146
  48. package/dist/validation/ParameterValidator.test.js.map +1 -1
  49. package/package.json +1 -1
  50. package/src/auth/AuthUtils.test.ts +176 -157
  51. package/src/auth/AuthUtils.ts +96 -33
  52. package/src/function/GlobalToolFunction.test.ts +54 -8
  53. package/src/function/GlobalToolFunction.ts +26 -6
  54. package/src/function/ToolFunction.test.ts +274 -8
  55. package/src/function/ToolFunction.ts +33 -7
  56. package/src/index.ts +1 -0
  57. package/src/logging/ToolLogger.test.ts +184 -0
  58. package/src/logging/ToolLogger.ts +13 -12
  59. package/src/service/Service.test.ts +577 -34
  60. package/src/service/Service.ts +286 -54
  61. package/src/types/ToolError.test.ts +192 -0
  62. package/src/types/ToolError.ts +95 -0
  63. package/src/validation/ParameterValidator.test.ts +185 -158
  64. package/src/validation/ParameterValidator.ts +17 -20
@@ -64,8 +64,8 @@ export class ToolLogger {
64
64
  }
65
65
 
66
66
  if (typeof data === 'string') {
67
- return data.length > ToolLogger.MAX_PARAM_LENGTH
68
- ? `${data.substring(0, ToolLogger.MAX_PARAM_LENGTH)}... (truncated, ${data.length} chars total)`
67
+ return data.length > this.MAX_PARAM_LENGTH
68
+ ? `${data.substring(0, this.MAX_PARAM_LENGTH)}... (truncated, ${data.length} chars total)`
69
69
  : data;
70
70
  }
71
71
 
@@ -74,10 +74,10 @@ export class ToolLogger {
74
74
  }
75
75
 
76
76
  if (Array.isArray(data)) {
77
- const truncated = data.slice(0, ToolLogger.MAX_ARRAY_ITEMS);
78
- const result = truncated.map((item) => ToolLogger.redactSensitiveData(item, maxDepth - 1));
79
- if (data.length > ToolLogger.MAX_ARRAY_ITEMS) {
80
- result.push(`... (${data.length - ToolLogger.MAX_ARRAY_ITEMS} more items truncated)`);
77
+ const truncated = data.slice(0, this.MAX_ARRAY_ITEMS);
78
+ const result = truncated.map((item) => this.redactSensitiveData(item, maxDepth));
79
+ if (data.length > this.MAX_ARRAY_ITEMS) {
80
+ result.push(`... (${data.length - this.MAX_ARRAY_ITEMS} more items truncated)`);
81
81
  }
82
82
  return result;
83
83
  }
@@ -86,12 +86,12 @@ export class ToolLogger {
86
86
  const result: any = {};
87
87
  for (const [key, value] of Object.entries(data)) {
88
88
  // Check if this field contains sensitive data
89
- const isSensitive = ToolLogger.isSensitiveField(key);
89
+ const isSensitive = this.isSensitiveField(key);
90
90
 
91
91
  if (isSensitive) {
92
92
  result[key] = '[REDACTED]';
93
93
  } else {
94
- result[key] = ToolLogger.redactSensitiveData(value, maxDepth - 1);
94
+ result[key] = this.redactSensitiveData(value, maxDepth - 1);
95
95
  }
96
96
  }
97
97
  return result;
@@ -105,7 +105,7 @@ export class ToolLogger {
105
105
  */
106
106
  private static isSensitiveField(fieldName: string): boolean {
107
107
  const lowerKey = fieldName.toLowerCase();
108
- return ToolLogger.SENSITIVE_FIELDS.some((sensitiveField) =>
108
+ return this.SENSITIVE_FIELDS.some((sensitiveField) =>
109
109
  lowerKey.includes(sensitiveField)
110
110
  );
111
111
  }
@@ -118,7 +118,7 @@ export class ToolLogger {
118
118
  return null;
119
119
  }
120
120
 
121
- return ToolLogger.redactSensitiveData(params);
121
+ return this.redactSensitiveData(params);
122
122
  }
123
123
 
124
124
  /**
@@ -146,7 +146,8 @@ export class ToolLogger {
146
146
  const requestLog = {
147
147
  event: 'opal_tool_request',
148
148
  path: req.path,
149
- parameters: ToolLogger.createParameterSummary(params)
149
+ method: req.method,
150
+ parameters: this.createParameterSummary(params)
150
151
  };
151
152
 
152
153
  // Log with Zaius audience so developers only see requests for accounts they have access to
@@ -167,7 +168,7 @@ export class ToolLogger {
167
168
  duration: processingTimeMs ? `${processingTimeMs}ms` : undefined,
168
169
  status: response.status,
169
170
  contentType: response.headers?.get('content-type') || 'unknown',
170
- contentLength: ToolLogger.calculateContentLength(response),
171
+ contentLength: this.calculateContentLength(response),
171
172
  success: response.status >= 200 && response.status < 300
172
173
  };
173
174