@zapier/zapier-sdk 0.15.10 → 0.15.11
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/CHANGELOG.md +6 -0
- package/dist/index.cjs +583 -337
- package/dist/index.d.mts +184 -39
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.mjs +583 -338
- package/dist/plugins/eventEmission/builders.d.ts +3 -2
- package/dist/plugins/eventEmission/builders.d.ts.map +1 -1
- package/dist/plugins/eventEmission/builders.js +32 -0
- package/dist/plugins/eventEmission/index.d.ts +4 -2
- package/dist/plugins/eventEmission/index.d.ts.map +1 -1
- package/dist/plugins/eventEmission/index.js +8 -2
- package/dist/plugins/eventEmission/types.d.ts +10 -0
- package/dist/plugins/eventEmission/types.d.ts.map +1 -1
- package/dist/plugins/fetch/index.d.ts +2 -1
- package/dist/plugins/fetch/index.d.ts.map +1 -1
- package/dist/plugins/fetch/index.js +39 -11
- package/dist/plugins/findFirstAuthentication/index.d.ts +2 -1
- package/dist/plugins/findFirstAuthentication/index.d.ts.map +1 -1
- package/dist/plugins/findFirstAuthentication/index.js +4 -2
- package/dist/plugins/findFirstAuthentication/index.test.js +11 -4
- package/dist/plugins/findUniqueAuthentication/index.d.ts +2 -1
- package/dist/plugins/findUniqueAuthentication/index.d.ts.map +1 -1
- package/dist/plugins/findUniqueAuthentication/index.js +4 -2
- package/dist/plugins/findUniqueAuthentication/index.test.js +9 -2
- package/dist/plugins/getAction/index.d.ts +3 -1
- package/dist/plugins/getAction/index.d.ts.map +1 -1
- package/dist/plugins/getAction/index.js +6 -3
- package/dist/plugins/getAction/index.test.js +5 -3
- package/dist/plugins/getAction/schemas.d.ts +14 -0
- package/dist/plugins/getAction/schemas.d.ts.map +1 -1
- package/dist/plugins/getAction/schemas.js +2 -0
- package/dist/plugins/getApp/index.d.ts +2 -1
- package/dist/plugins/getApp/index.d.ts.map +1 -1
- package/dist/plugins/getApp/index.js +9 -3
- package/dist/plugins/getApp/index.test.js +7 -0
- package/dist/plugins/getAuthentication/index.d.ts +3 -1
- package/dist/plugins/getAuthentication/index.d.ts.map +1 -1
- package/dist/plugins/getAuthentication/index.js +2 -1
- package/dist/plugins/getAuthentication/index.test.js +10 -1
- package/dist/plugins/getInputFieldsSchema/index.d.ts +2 -1
- package/dist/plugins/getInputFieldsSchema/index.d.ts.map +1 -1
- package/dist/plugins/getInputFieldsSchema/index.js +2 -1
- package/dist/plugins/getInputFieldsSchema/index.test.js +3 -0
- package/dist/plugins/getProfile/index.d.ts +3 -1
- package/dist/plugins/getProfile/index.d.ts.map +1 -1
- package/dist/plugins/getProfile/index.js +2 -1
- package/dist/plugins/listActions/index.d.ts +2 -1
- package/dist/plugins/listActions/index.d.ts.map +1 -1
- package/dist/plugins/listActions/index.js +14 -12
- package/dist/plugins/listActions/index.test.js +7 -0
- package/dist/plugins/listActions/schemas.d.ts +18 -4
- package/dist/plugins/listActions/schemas.d.ts.map +1 -1
- package/dist/plugins/listActions/schemas.js +2 -0
- package/dist/plugins/listApps/index.d.ts +2 -1
- package/dist/plugins/listApps/index.d.ts.map +1 -1
- package/dist/plugins/listApps/index.js +2 -1
- package/dist/plugins/listApps/index.test.js +7 -0
- package/dist/plugins/listAuthentications/index.d.ts +2 -1
- package/dist/plugins/listAuthentications/index.d.ts.map +1 -1
- package/dist/plugins/listAuthentications/index.js +2 -1
- package/dist/plugins/listAuthentications/index.test.js +7 -0
- package/dist/plugins/listAuthentications/schemas.d.ts +18 -4
- package/dist/plugins/listAuthentications/schemas.d.ts.map +1 -1
- package/dist/plugins/listAuthentications/schemas.js +2 -0
- package/dist/plugins/listInputFieldChoices/index.d.ts +3 -1
- package/dist/plugins/listInputFieldChoices/index.d.ts.map +1 -1
- package/dist/plugins/listInputFieldChoices/index.js +2 -1
- package/dist/plugins/listInputFieldChoices/index.test.js +5 -2
- package/dist/plugins/listInputFieldChoices/schemas.d.ts +4 -4
- package/dist/plugins/listInputFields/index.d.ts +3 -1
- package/dist/plugins/listInputFields/index.d.ts.map +1 -1
- package/dist/plugins/listInputFields/index.js +2 -1
- package/dist/plugins/listInputFields/index.test.js +3 -0
- package/dist/plugins/listInputFields/schemas.d.ts +4 -4
- package/dist/plugins/manifest/index.test.js +10 -1
- package/dist/plugins/request/index.d.ts +3 -1
- package/dist/plugins/request/index.d.ts.map +1 -1
- package/dist/plugins/request/index.js +2 -1
- package/dist/plugins/request/index.test.js +10 -1
- package/dist/plugins/request/schemas.d.ts +28 -0
- package/dist/plugins/request/schemas.d.ts.map +1 -1
- package/dist/plugins/request/schemas.js +2 -0
- package/dist/plugins/runAction/index.d.ts +3 -1
- package/dist/plugins/runAction/index.d.ts.map +1 -1
- package/dist/plugins/runAction/index.js +3 -1
- package/dist/plugins/runAction/index.test.js +20 -8
- package/dist/plugins/runAction/schemas.d.ts +4 -4
- package/dist/temporary-internal-core/schemas/apps/index.d.ts +21 -7
- package/dist/temporary-internal-core/schemas/apps/index.d.ts.map +1 -1
- package/dist/temporary-internal-core/schemas/apps/index.js +2 -0
- package/dist/types/telemetry-events.d.ts +31 -2
- package/dist/types/telemetry-events.d.ts.map +1 -1
- package/dist/utils/function-utils.d.ts +42 -3
- package/dist/utils/function-utils.d.ts.map +1 -1
- package/dist/utils/function-utils.js +83 -8
- package/dist/utils/telemetry-utils.d.ts +32 -0
- package/dist/utils/telemetry-utils.d.ts.map +1 -0
- package/dist/utils/telemetry-utils.js +43 -0
- package/dist/utils/telemetry-utils.test.d.ts +2 -0
- package/dist/utils/telemetry-utils.test.d.ts.map +1 -0
- package/dist/utils/telemetry-utils.test.js +94 -0
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"function-utils.d.ts","sourceRoot":"","sources":["../../src/utils/function-utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"function-utils.d.ts","sourceRoot":"","sources":["../../src/utils/function-utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAKxB;;;GAGG;AACH,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;EAMhC,CAAC;AAEH;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAEpE;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,cAAc,CAAC,EAAE,CAAC,IAAI,EAAE;QACtB,UAAU,EAAE,MAAM,CAAC;QACnB,UAAU,EAAE,MAAM,CAAC;QACnB,OAAO,EAAE,OAAO,CAAC;QACjB,KAAK,CAAC,EAAE,KAAK,CAAC;QACd,aAAa,EAAE,MAAM,CAAC;QACtB,WAAW,EAAE,OAAO,CAAC;KACtB,KAAK,IAAI,CAAC;CACZ;AAED;;GAEG;AACH,wBAAgB,aAAa,CAC3B,IAAI,EAAE;IAAE,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,GAAG,IAAI,GAAG,SAAS,GAChD,MAAM,GAAG,SAAS,CAYpB;AAcD;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAC5B,QAAQ,EACR,OAAO,EACP,cAAc,SAAS,QAAQ,GAAG,QAAQ,EAE1C,MAAM,EAAE,CAAC,OAAO,EAAE,QAAQ,KAAK,OAAO,CAAC,OAAO,CAAC,EAC/C,MAAM,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,cAAc,CAAC,EACpC,SAAS,CAAC,EAAE,kBAAkB,cAMc,QAAQ,KAAG,OAAO,CAAC,OAAO,CAAC,CAsExE;AAiDD;;;;;GAKG;AACH,KAAK,eAAe,CAAC,OAAO,IAAI,OAAO,SAAS;IAC9C,IAAI,EAAE,GAAG,CAAC;IACV,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,GACG,OAAO,GACP;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAE3C,KAAK,QAAQ,CAAC,OAAO,IAAI,OAAO,SAAS;IAAE,IAAI,EAAE,MAAM,KAAK,CAAA;CAAE,GAC1D,KAAK,SAAS,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE,GACpC,KAAK,GACL,KAAK,GACP,OAAO,SAAS,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE,GACtC,KAAK,GACL,OAAO,CAAC;AAEd,wBAAgB,uBAAuB,CACrC,QAAQ,EACR,OAAO,EACP,cAAc,SAAS,QAAQ,GAAG,QAAQ,EAE1C,MAAM,EAAE,CAAC,OAAO,EAAE,QAAQ,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,KAAK,OAAO,CAAC,OAAO,CAAC,EACtE,MAAM,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,cAAc,CAAC,EACpC,SAAS,CAAC,EAAE,kBAAkB,GAC7B,CACD,OAAO,CAAC,EAAE,QAAQ,GAAG;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,KACE,OAAO,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,GACpC,aAAa,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,GAAG;IACxC,KAAK,IAAI,aAAa,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC;CAC3C,CAgHF"}
|
|
@@ -1,9 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Generic utility functions for creating paginated SDK functions
|
|
3
3
|
*/
|
|
4
|
+
import { z } from "zod";
|
|
4
5
|
import { ZapierError, ZapierUnknownError } from "../types/errors";
|
|
5
6
|
import { paginate } from "./pagination-utils";
|
|
6
7
|
import { createValidator, validateOptions } from "./validation";
|
|
8
|
+
/**
|
|
9
|
+
* Zod schema for telemetry marker to prevent nested telemetry emissions.
|
|
10
|
+
* Used to extend options schemas with proper typing.
|
|
11
|
+
*/
|
|
12
|
+
export const TelemetryMarkerSchema = z.object({
|
|
13
|
+
_telemetry: z
|
|
14
|
+
.object({
|
|
15
|
+
isNested: z.boolean().optional(),
|
|
16
|
+
})
|
|
17
|
+
.optional(),
|
|
18
|
+
});
|
|
7
19
|
/**
|
|
8
20
|
* Helper function to extract cursor from pagination data
|
|
9
21
|
*/
|
|
@@ -35,28 +47,64 @@ function normalizeError(error) {
|
|
|
35
47
|
*
|
|
36
48
|
* @param coreFn - Function that returns T directly or throws errors
|
|
37
49
|
* @param schema - Optional Zod schema for validation
|
|
50
|
+
* @param telemetry - Optional telemetry callbacks
|
|
38
51
|
* @returns A function that normalizes and rethrows errors
|
|
39
52
|
*/
|
|
40
|
-
export function createFunction(coreFn, schema) {
|
|
53
|
+
export function createFunction(coreFn, schema, telemetry) {
|
|
41
54
|
const functionName = coreFn.name;
|
|
42
55
|
// Create a named function using dynamic property access
|
|
43
56
|
const namedFunctions = {
|
|
44
57
|
[functionName]: async function (options) {
|
|
58
|
+
const startTime = Date.now();
|
|
59
|
+
const normalizedOptions = (options ?? {});
|
|
60
|
+
const isNested = normalizedOptions?._telemetry?.isNested === true;
|
|
45
61
|
try {
|
|
46
|
-
// Convert undefined options to empty object
|
|
47
|
-
const normalizedOptions = (options ?? {});
|
|
48
62
|
if (schema) {
|
|
49
63
|
const validatedOptions = validateOptions(schema, normalizedOptions);
|
|
50
|
-
|
|
64
|
+
const result = await coreFn({
|
|
51
65
|
...normalizedOptions,
|
|
52
66
|
...validatedOptions,
|
|
53
67
|
});
|
|
68
|
+
// Emit telemetry only for top-level calls
|
|
69
|
+
if (!isNested && telemetry?.onMethodCalled) {
|
|
70
|
+
const argumentCount = Object.keys(normalizedOptions).filter((k) => k !== "_telemetry").length;
|
|
71
|
+
telemetry.onMethodCalled({
|
|
72
|
+
methodName: functionName,
|
|
73
|
+
durationMs: Date.now() - startTime,
|
|
74
|
+
success: true,
|
|
75
|
+
argumentCount,
|
|
76
|
+
isPaginated: false,
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
return result;
|
|
54
80
|
}
|
|
55
|
-
|
|
81
|
+
const result = await coreFn(normalizedOptions);
|
|
82
|
+
if (!isNested && telemetry?.onMethodCalled) {
|
|
83
|
+
const argumentCount = Object.keys(normalizedOptions).filter((k) => k !== "_telemetry").length;
|
|
84
|
+
telemetry.onMethodCalled({
|
|
85
|
+
methodName: functionName,
|
|
86
|
+
durationMs: Date.now() - startTime,
|
|
87
|
+
success: true,
|
|
88
|
+
argumentCount,
|
|
89
|
+
isPaginated: false,
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
return result;
|
|
56
93
|
}
|
|
57
94
|
catch (error) {
|
|
58
|
-
|
|
59
|
-
|
|
95
|
+
const normalizedError = normalizeError(error);
|
|
96
|
+
if (!isNested && telemetry?.onMethodCalled) {
|
|
97
|
+
const argumentCount = Object.keys(normalizedOptions).filter((k) => k !== "_telemetry").length;
|
|
98
|
+
telemetry.onMethodCalled({
|
|
99
|
+
methodName: functionName,
|
|
100
|
+
durationMs: Date.now() - startTime,
|
|
101
|
+
success: false,
|
|
102
|
+
error: normalizedError,
|
|
103
|
+
argumentCount,
|
|
104
|
+
isPaginated: false,
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
throw normalizedError;
|
|
60
108
|
}
|
|
61
109
|
},
|
|
62
110
|
};
|
|
@@ -96,15 +144,17 @@ function createPageFunction(coreFn) {
|
|
|
96
144
|
};
|
|
97
145
|
return namedFunctions[functionName];
|
|
98
146
|
}
|
|
99
|
-
export function createPaginatedFunction(coreFn, schema) {
|
|
147
|
+
export function createPaginatedFunction(coreFn, schema, telemetry) {
|
|
100
148
|
const pageFunction = createPageFunction(coreFn);
|
|
101
149
|
const functionName = coreFn.name;
|
|
102
150
|
const validator = schema ? createValidator(schema) : null;
|
|
103
151
|
// Create the main paginated function
|
|
104
152
|
const namedFunctions = {
|
|
105
153
|
[functionName]: function (options) {
|
|
154
|
+
const startTime = Date.now();
|
|
106
155
|
// Convert undefined options to empty object
|
|
107
156
|
const normalizedOptions = (options ?? {});
|
|
157
|
+
const isNested = normalizedOptions?._telemetry?.isNested === true;
|
|
108
158
|
// Validate options if schema provided (validated fields take precedence)
|
|
109
159
|
const validatedOptions = {
|
|
110
160
|
...normalizedOptions,
|
|
@@ -124,6 +174,31 @@ export function createPaginatedFunction(coreFn, schema) {
|
|
|
124
174
|
}
|
|
125
175
|
return result.value;
|
|
126
176
|
});
|
|
177
|
+
// Emit telemetry after first page completes
|
|
178
|
+
if (!isNested && telemetry?.onMethodCalled) {
|
|
179
|
+
firstPagePromise
|
|
180
|
+
.then(() => {
|
|
181
|
+
const argumentCount = Object.keys(normalizedOptions).filter((k) => k !== "_telemetry").length;
|
|
182
|
+
telemetry.onMethodCalled({
|
|
183
|
+
methodName: functionName,
|
|
184
|
+
durationMs: Date.now() - startTime,
|
|
185
|
+
success: true,
|
|
186
|
+
argumentCount,
|
|
187
|
+
isPaginated: true,
|
|
188
|
+
});
|
|
189
|
+
})
|
|
190
|
+
.catch((error) => {
|
|
191
|
+
const argumentCount = Object.keys(normalizedOptions).filter((k) => k !== "_telemetry").length;
|
|
192
|
+
telemetry.onMethodCalled({
|
|
193
|
+
methodName: functionName,
|
|
194
|
+
durationMs: Date.now() - startTime,
|
|
195
|
+
success: false,
|
|
196
|
+
error: error instanceof Error ? error : new Error(String(error)),
|
|
197
|
+
argumentCount,
|
|
198
|
+
isPaginated: true,
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
}
|
|
127
202
|
// Add Symbol.asyncIterator to make the promise iterable
|
|
128
203
|
return Object.assign(firstPagePromise, {
|
|
129
204
|
[Symbol.asyncIterator]: async function* () {
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { TelemetryCallbacks } from "./function-utils";
|
|
2
|
+
import type { EventEmissionContext } from "../plugins/eventEmission";
|
|
3
|
+
/**
|
|
4
|
+
* Creates a standardized telemetry callback for SDK method invocations.
|
|
5
|
+
*
|
|
6
|
+
* This factory eliminates boilerplate by providing a consistent implementation
|
|
7
|
+
* of the onMethodCalled callback used by createFunction and createPaginatedFunction.
|
|
8
|
+
*
|
|
9
|
+
* @param emitMethodCalled - The event emission function from EventEmissionContext
|
|
10
|
+
* @param methodName - The explicit method name to use in telemetry. This avoids bundler
|
|
11
|
+
* mangling where esbuild/tsup renames inner functions to avoid collisions. For example:
|
|
12
|
+
* ```typescript
|
|
13
|
+
* // Source code:
|
|
14
|
+
* const getAction = createFunction(async function getAction(options) { ... });
|
|
15
|
+
*
|
|
16
|
+
* // Bundled output (inner function renamed to avoid collision with outer const):
|
|
17
|
+
* const getAction = createFunction(async function getAction2(options) { ... });
|
|
18
|
+
* ```
|
|
19
|
+
* Without an explicit methodName, telemetry would report "getAction2" instead of "getAction".
|
|
20
|
+
* @returns TelemetryCallbacks object with standardized onMethodCalled implementation
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* const listApps = createFunction(
|
|
25
|
+
* async function listApps(options) { ... },
|
|
26
|
+
* ListAppsSchema,
|
|
27
|
+
* createTelemetryCallback(context.eventEmission.emitMethodCalled, "listApps"),
|
|
28
|
+
* );
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare function createTelemetryCallback(emitMethodCalled: EventEmissionContext["eventEmission"]["emitMethodCalled"], methodName: string): TelemetryCallbacks;
|
|
32
|
+
//# sourceMappingURL=telemetry-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"telemetry-utils.d.ts","sourceRoot":"","sources":["../../src/utils/telemetry-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAErE;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,uBAAuB,CACrC,gBAAgB,EAAE,oBAAoB,CAAC,eAAe,CAAC,CAAC,kBAAkB,CAAC,EAC3E,UAAU,EAAE,MAAM,GACjB,kBAAkB,CAcpB"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a standardized telemetry callback for SDK method invocations.
|
|
3
|
+
*
|
|
4
|
+
* This factory eliminates boilerplate by providing a consistent implementation
|
|
5
|
+
* of the onMethodCalled callback used by createFunction and createPaginatedFunction.
|
|
6
|
+
*
|
|
7
|
+
* @param emitMethodCalled - The event emission function from EventEmissionContext
|
|
8
|
+
* @param methodName - The explicit method name to use in telemetry. This avoids bundler
|
|
9
|
+
* mangling where esbuild/tsup renames inner functions to avoid collisions. For example:
|
|
10
|
+
* ```typescript
|
|
11
|
+
* // Source code:
|
|
12
|
+
* const getAction = createFunction(async function getAction(options) { ... });
|
|
13
|
+
*
|
|
14
|
+
* // Bundled output (inner function renamed to avoid collision with outer const):
|
|
15
|
+
* const getAction = createFunction(async function getAction2(options) { ... });
|
|
16
|
+
* ```
|
|
17
|
+
* Without an explicit methodName, telemetry would report "getAction2" instead of "getAction".
|
|
18
|
+
* @returns TelemetryCallbacks object with standardized onMethodCalled implementation
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* const listApps = createFunction(
|
|
23
|
+
* async function listApps(options) { ... },
|
|
24
|
+
* ListAppsSchema,
|
|
25
|
+
* createTelemetryCallback(context.eventEmission.emitMethodCalled, "listApps"),
|
|
26
|
+
* );
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export function createTelemetryCallback(emitMethodCalled, methodName) {
|
|
30
|
+
return {
|
|
31
|
+
onMethodCalled: (data) => {
|
|
32
|
+
emitMethodCalled({
|
|
33
|
+
method_name: methodName,
|
|
34
|
+
execution_duration_ms: data.durationMs,
|
|
35
|
+
success_flag: data.success,
|
|
36
|
+
error_message: data.error?.message ?? null,
|
|
37
|
+
error_type: data.error?.constructor.name ?? null,
|
|
38
|
+
argument_count: data.argumentCount,
|
|
39
|
+
is_paginated: data.isPaginated,
|
|
40
|
+
});
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"telemetry-utils.test.d.ts","sourceRoot":"","sources":["../../src/utils/telemetry-utils.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { describe, it, expect, vi } from "vitest";
|
|
2
|
+
import { createTelemetryCallback } from "./telemetry-utils";
|
|
3
|
+
describe("createTelemetryCallback", () => {
|
|
4
|
+
it("should create callback that emits telemetry with explicit method name", () => {
|
|
5
|
+
const mockEmit = vi.fn();
|
|
6
|
+
const callback = createTelemetryCallback(mockEmit, "testMethod");
|
|
7
|
+
callback.onMethodCalled({
|
|
8
|
+
methodName: "ignoredName",
|
|
9
|
+
durationMs: 123,
|
|
10
|
+
success: true,
|
|
11
|
+
argumentCount: 2,
|
|
12
|
+
isPaginated: false,
|
|
13
|
+
});
|
|
14
|
+
expect(mockEmit).toHaveBeenCalledWith({
|
|
15
|
+
method_name: "testMethod",
|
|
16
|
+
execution_duration_ms: 123,
|
|
17
|
+
success_flag: true,
|
|
18
|
+
error_message: null,
|
|
19
|
+
error_type: null,
|
|
20
|
+
argument_count: 2,
|
|
21
|
+
is_paginated: false,
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
it("should include error details when method fails", () => {
|
|
25
|
+
const mockEmit = vi.fn();
|
|
26
|
+
const callback = createTelemetryCallback(mockEmit, "failingMethod");
|
|
27
|
+
const testError = new Error("Test failure");
|
|
28
|
+
callback.onMethodCalled({
|
|
29
|
+
methodName: "ignoredName",
|
|
30
|
+
durationMs: 50,
|
|
31
|
+
success: false,
|
|
32
|
+
error: testError,
|
|
33
|
+
argumentCount: 1,
|
|
34
|
+
isPaginated: false,
|
|
35
|
+
});
|
|
36
|
+
expect(mockEmit).toHaveBeenCalledWith({
|
|
37
|
+
method_name: "failingMethod",
|
|
38
|
+
execution_duration_ms: 50,
|
|
39
|
+
success_flag: false,
|
|
40
|
+
error_message: "Test failure",
|
|
41
|
+
error_type: "Error",
|
|
42
|
+
argument_count: 1,
|
|
43
|
+
is_paginated: false,
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
it("should handle paginated method calls", () => {
|
|
47
|
+
const mockEmit = vi.fn();
|
|
48
|
+
const callback = createTelemetryCallback(mockEmit, "listItems");
|
|
49
|
+
callback.onMethodCalled({
|
|
50
|
+
methodName: "ignoredName",
|
|
51
|
+
durationMs: 200,
|
|
52
|
+
success: true,
|
|
53
|
+
argumentCount: 1,
|
|
54
|
+
isPaginated: true,
|
|
55
|
+
});
|
|
56
|
+
expect(mockEmit).toHaveBeenCalledWith({
|
|
57
|
+
method_name: "listItems",
|
|
58
|
+
execution_duration_ms: 200,
|
|
59
|
+
success_flag: true,
|
|
60
|
+
error_message: null,
|
|
61
|
+
error_type: null,
|
|
62
|
+
argument_count: 1,
|
|
63
|
+
is_paginated: true,
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
it("should handle custom error types", () => {
|
|
67
|
+
const mockEmit = vi.fn();
|
|
68
|
+
const callback = createTelemetryCallback(mockEmit, "customFailMethod");
|
|
69
|
+
class CustomError extends Error {
|
|
70
|
+
constructor(message) {
|
|
71
|
+
super(message);
|
|
72
|
+
this.name = "CustomError";
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
const customError = new CustomError("Custom failure");
|
|
76
|
+
callback.onMethodCalled({
|
|
77
|
+
methodName: "ignoredName",
|
|
78
|
+
durationMs: 75,
|
|
79
|
+
success: false,
|
|
80
|
+
error: customError,
|
|
81
|
+
argumentCount: 3,
|
|
82
|
+
isPaginated: false,
|
|
83
|
+
});
|
|
84
|
+
expect(mockEmit).toHaveBeenCalledWith({
|
|
85
|
+
method_name: "customFailMethod",
|
|
86
|
+
execution_duration_ms: 75,
|
|
87
|
+
success_flag: false,
|
|
88
|
+
error_message: "Custom failure",
|
|
89
|
+
error_type: "CustomError",
|
|
90
|
+
argument_count: 3,
|
|
91
|
+
is_paginated: false,
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
});
|