@csaimonitor/sdk 0.1.0

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,53 @@
1
+ /**
2
+ * Utility functions for CSMonitor SDK.
3
+ *
4
+ * This module provides helper functions for logging, serialization, and data handling.
5
+ */
6
+ /**
7
+ * Get current timestamp in ISO 8601 format.
8
+ * @returns ISO 8601 formatted timestamp string (UTC)
9
+ */
10
+ export declare function getIsoTimestamp(): string;
11
+ /**
12
+ * Safely serialize data to JSON-compatible format.
13
+ * @param data - Data to serialize (object, array, primitive, or any value)
14
+ * @returns JSON-serializable object
15
+ */
16
+ export declare function safeSerialize(data: unknown): Record<string, unknown>;
17
+ /**
18
+ * Redact sensitive fields from data recursively.
19
+ * @param data - Dictionary to redact from
20
+ * @param redactKeys - List of keys to redact (case-insensitive)
21
+ * @returns Dictionary with redacted values
22
+ */
23
+ export declare function redactSensitiveData(data: Record<string, unknown>, redactKeys: string[]): Record<string, unknown>;
24
+ /**
25
+ * Validate API key format.
26
+ * @param apiKey - API key to validate
27
+ * @returns True if valid, False otherwise
28
+ */
29
+ export declare function validateApiKey(apiKey: string): boolean;
30
+ /**
31
+ * Validate agent ID format.
32
+ * @param agentId - Agent ID to validate
33
+ * @returns True if valid, False otherwise
34
+ */
35
+ export declare function validateAgentId(agentId: string): boolean;
36
+ /**
37
+ * Format an exception as a clean error message.
38
+ * @param error - Error to format
39
+ * @returns Formatted error message string
40
+ */
41
+ export declare function formatErrorMessage(error: unknown): string;
42
+ /**
43
+ * Setup a simple logger for the SDK.
44
+ * @param debug - Enable debug logging
45
+ * @returns Logger object with log methods
46
+ */
47
+ export declare function setupLogger(debug?: boolean): {
48
+ debug: (message: string, ...args: unknown[]) => void;
49
+ info: (message: string, ...args: unknown[]) => void;
50
+ warn: (message: string, ...args: unknown[]) => void;
51
+ error: (message: string, ...args: unknown[]) => void;
52
+ };
53
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;GAGG;AACH,wBAAgB,eAAe,IAAI,MAAM,CAExC;AAkCD;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CA4BpE;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,UAAU,EAAE,MAAM,EAAE,GACnB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAyBzB;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAWtD;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAWxD;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAYzD;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,KAAK,GAAE,OAAe;qBAE7B,MAAM,WAAW,OAAO,EAAE;oBAK3B,MAAM,WAAW,OAAO,EAAE;oBAG1B,MAAM,WAAW,OAAO,EAAE;qBAGzB,MAAM,WAAW,OAAO,EAAE;EAI9C"}
package/dist/utils.js ADDED
@@ -0,0 +1,176 @@
1
+ "use strict";
2
+ /**
3
+ * Utility functions for CSMonitor SDK.
4
+ *
5
+ * This module provides helper functions for logging, serialization, and data handling.
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.getIsoTimestamp = getIsoTimestamp;
9
+ exports.safeSerialize = safeSerialize;
10
+ exports.redactSensitiveData = redactSensitiveData;
11
+ exports.validateApiKey = validateApiKey;
12
+ exports.validateAgentId = validateAgentId;
13
+ exports.formatErrorMessage = formatErrorMessage;
14
+ exports.setupLogger = setupLogger;
15
+ /**
16
+ * Get current timestamp in ISO 8601 format.
17
+ * @returns ISO 8601 formatted timestamp string (UTC)
18
+ */
19
+ function getIsoTimestamp() {
20
+ return new Date().toISOString();
21
+ }
22
+ /**
23
+ * Serialize a value for JSON encoding.
24
+ * Handles common JavaScript/TypeScript types that might need special handling.
25
+ */
26
+ function serializeValue(value) {
27
+ if (value === null || value === undefined) {
28
+ return null;
29
+ }
30
+ if (value instanceof Date) {
31
+ return value.toISOString();
32
+ }
33
+ if (typeof value === 'bigint') {
34
+ return value.toString();
35
+ }
36
+ if (value instanceof Error) {
37
+ return {
38
+ name: value.name,
39
+ message: value.message,
40
+ stack: value.stack,
41
+ };
42
+ }
43
+ if (typeof value === 'object' && 'toJSON' in value && typeof value.toJSON === 'function') {
44
+ return value.toJSON();
45
+ }
46
+ return value;
47
+ }
48
+ /**
49
+ * Safely serialize data to JSON-compatible format.
50
+ * @param data - Data to serialize (object, array, primitive, or any value)
51
+ * @returns JSON-serializable object
52
+ */
53
+ function safeSerialize(data) {
54
+ if (data === null || data === undefined) {
55
+ return {};
56
+ }
57
+ if (typeof data === 'object') {
58
+ if (Array.isArray(data)) {
59
+ return { items: data.map(serializeValue) };
60
+ }
61
+ if (data instanceof Map) {
62
+ return { items: Array.from(data.entries()).map(([k, v]) => ({ key: serializeValue(k), value: serializeValue(v) })) };
63
+ }
64
+ if (data instanceof Set) {
65
+ return { items: Array.from(data).map(serializeValue) };
66
+ }
67
+ // Plain object
68
+ const result = {};
69
+ for (const [key, value] of Object.entries(data)) {
70
+ result[key] = serializeValue(value);
71
+ }
72
+ return result;
73
+ }
74
+ // Primitive types
75
+ return { value: serializeValue(data) };
76
+ }
77
+ /**
78
+ * Redact sensitive fields from data recursively.
79
+ * @param data - Dictionary to redact from
80
+ * @param redactKeys - List of keys to redact (case-insensitive)
81
+ * @returns Dictionary with redacted values
82
+ */
83
+ function redactSensitiveData(data, redactKeys) {
84
+ if (!data || !redactKeys || redactKeys.length === 0) {
85
+ return data;
86
+ }
87
+ const redactKeysLower = redactKeys.map((key) => key.toLowerCase());
88
+ const result = {};
89
+ for (const [key, value] of Object.entries(data)) {
90
+ if (redactKeysLower.includes(key.toLowerCase())) {
91
+ result[key] = '[REDACTED]';
92
+ }
93
+ else if (value && typeof value === 'object' && !Array.isArray(value) && !(value instanceof Date)) {
94
+ result[key] = redactSensitiveData(value, redactKeys);
95
+ }
96
+ else if (Array.isArray(value)) {
97
+ result[key] = value.map((item) => item && typeof item === 'object' && !Array.isArray(item) && !(item instanceof Date)
98
+ ? redactSensitiveData(item, redactKeys)
99
+ : item);
100
+ }
101
+ else {
102
+ result[key] = value;
103
+ }
104
+ }
105
+ return result;
106
+ }
107
+ /**
108
+ * Validate API key format.
109
+ * @param apiKey - API key to validate
110
+ * @returns True if valid, False otherwise
111
+ */
112
+ function validateApiKey(apiKey) {
113
+ if (!apiKey || typeof apiKey !== 'string') {
114
+ return false;
115
+ }
116
+ // API key must be at least 32 characters
117
+ if (apiKey.length < 32) {
118
+ return false;
119
+ }
120
+ return true;
121
+ }
122
+ /**
123
+ * Validate agent ID format.
124
+ * @param agentId - Agent ID to validate
125
+ * @returns True if valid, False otherwise
126
+ */
127
+ function validateAgentId(agentId) {
128
+ if (!agentId || typeof agentId !== 'string') {
129
+ return false;
130
+ }
131
+ // Agent ID should be non-empty
132
+ if (agentId.trim().length === 0) {
133
+ return false;
134
+ }
135
+ return true;
136
+ }
137
+ /**
138
+ * Format an exception as a clean error message.
139
+ * @param error - Error to format
140
+ * @returns Formatted error message string
141
+ */
142
+ function formatErrorMessage(error) {
143
+ if (error instanceof Error) {
144
+ const errorType = error.constructor.name;
145
+ const errorMsg = error.message;
146
+ return errorMsg ? `${errorType}: ${errorMsg}` : errorType;
147
+ }
148
+ if (typeof error === 'string') {
149
+ return error;
150
+ }
151
+ return 'Unknown error';
152
+ }
153
+ /**
154
+ * Setup a simple logger for the SDK.
155
+ * @param debug - Enable debug logging
156
+ * @returns Logger object with log methods
157
+ */
158
+ function setupLogger(debug = false) {
159
+ return {
160
+ debug: (message, ...args) => {
161
+ if (debug) {
162
+ console.debug(`[CSMonitor] ${message}`, ...args);
163
+ }
164
+ },
165
+ info: (message, ...args) => {
166
+ console.info(`[CSMonitor] ${message}`, ...args);
167
+ },
168
+ warn: (message, ...args) => {
169
+ console.warn(`[CSMonitor] ${message}`, ...args);
170
+ },
171
+ error: (message, ...args) => {
172
+ console.error(`[CSMonitor] ${message}`, ...args);
173
+ },
174
+ };
175
+ }
176
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;AAMH,0CAEC;AAuCD,sCA4BC;AAQD,kDA4BC;AAOD,wCAWC;AAOD,0CAWC;AAOD,gDAYC;AAOD,kCAiBC;AA5LD;;;GAGG;AACH,SAAgB,eAAe;IAC7B,OAAO,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;AAClC,CAAC;AAED;;;GAGG;AACH,SAAS,cAAc,CAAC,KAAc;IACpC,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QAC1C,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAI,KAAK,YAAY,IAAI,EAAE,CAAC;QAC1B,OAAO,KAAK,CAAC,WAAW,EAAE,CAAC;IAC7B,CAAC;IAED,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,KAAK,CAAC,QAAQ,EAAE,CAAC;IAC1B,CAAC;IAED,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;QAC3B,OAAO;YACL,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,OAAO,EAAE,KAAK,CAAC,OAAO;YACtB,KAAK,EAAE,KAAK,CAAC,KAAK;SACnB,CAAC;IACJ,CAAC;IAED,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,QAAQ,IAAI,KAAK,IAAI,OAAO,KAAK,CAAC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AAW,CAAC,QAAiB,KAAK;IAChD,OAAO;QACL,KAAK,EAAE,CAAC,OAAe,EAAE,GAAG,IAAe,EAAE,EAAE;YAC7C,IAAI,KAAK,EAAE,CAAC;gBACV,OAAO,CAAC,KAAK,CAAC,eAAe,OAAO,EAAE,EAAE,GAAG,IAAI,CAAC,CAAC;YACnD,CAAC;QACH,CAAC;QACD,IAAI,EAAE,CAAC,OAAe,EAAE,GAAG,IAAe,EAAE,EAAE;YAC5C,OAAO,CAAC,IAAI,CAAC,eAAe,OAAO,EAAE,EAAE,GAAG,IAAI,CAAC,CAAC;QAClD,CAAC;QACD,IAAI,EAAE,CAAC,OAAe,EAAE,GAAG,IAAe,EAAE,EAAE;YAC5C,OAAO,CAAC,IAAI,CAAC,eAAe,OAAO,EAAE,EAAE,GAAG,IAAI,CAAC,CAAC;QAClD,CAAC;QACD,KAAK,EAAE,CAAC,OAAe,EAAE,GAAG,IAAe,EAAE,EAAE;YAC7C,OAAO,CAAC,KAAK,CAAC,eAAe,OAAO,EAAE,EAAE,GAAG,IAAI,CAAC,CAAC;QACnD,CAAC;KACF,CAAC;AACJ,CAAC"}
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "@csaimonitor/sdk",
3
+ "version": "0.1.0",
4
+ "description": "Production-ready Node.js/TypeScript SDK for Customer Support AI Monitor",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "scripts": {
8
+ "build": "tsc",
9
+ "prepublishOnly": "npm run build",
10
+ "test": "jest",
11
+ "test:watch": "jest --watch",
12
+ "test:integration": "jest tests/integration.test.ts",
13
+ "test:e2e": "ts-node test-e2e.ts",
14
+ "lint": "eslint src/**/*.ts",
15
+ "format": "prettier --write src/**/*.ts"
16
+ },
17
+ "keywords": [
18
+ "ai",
19
+ "monitoring",
20
+ "customer-support",
21
+ "sdk",
22
+ "typescript",
23
+ "observability"
24
+ ],
25
+ "author": "Customer Support AI Monitor Team",
26
+ "license": "MIT",
27
+ "engines": {
28
+ "node": ">=16.0.0"
29
+ },
30
+ "devDependencies": {
31
+ "@types/jest": "^29.0.0",
32
+ "@types/node": "^20.0.0",
33
+ "@typescript-eslint/eslint-plugin": "^6.0.0",
34
+ "@typescript-eslint/parser": "^6.0.0",
35
+ "eslint": "^8.0.0",
36
+ "jest": "^29.0.0",
37
+ "prettier": "^3.0.0",
38
+ "ts-jest": "^29.0.0",
39
+ "ts-node": "^10.9.2",
40
+ "typescript": "^5.0.0"
41
+ },
42
+ "files": [
43
+ "dist/**/*",
44
+ "README.md",
45
+ "LICENSE",
46
+ "CHANGELOG.md"
47
+ ],
48
+ "repository": {
49
+ "type": "git",
50
+ "url": "git+https://github.com/csaimonitor/sdk-nodejs.git"
51
+ }
52
+ }