@zapier/zapier-sdk 0.15.10 → 0.15.12
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 +12 -0
- package/dist/index.cjs +520 -257
- 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 +520 -258
- 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 +7 -4
- 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 +7 -4
- 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 +9 -5
- 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 +12 -5
- 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 +5 -3
- 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 +5 -3
- 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 +5 -3
- 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 +19 -14
- 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 +7 -3
- 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 +7 -3
- 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 +7 -3
- 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 +7 -4
- 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 +5 -3
- 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 +8 -3
- 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 +84 -9
- package/dist/utils/string-utils.d.ts +19 -0
- package/dist/utils/string-utils.d.ts.map +1 -1
- package/dist/utils/string-utils.js +21 -0
- package/dist/utils/string-utils.test.js +24 -1
- package/dist/utils/telemetry-utils.d.ts +44 -0
- package/dist/utils/telemetry-utils.d.ts.map +1 -0
- package/dist/utils/telemetry-utils.js +55 -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
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import { z } from "zod";
|
|
10
10
|
import { ImplementationMetaSchema } from "../implementations";
|
|
11
|
+
import { TelemetryMarkerSchema } from "../../../utils/function-utils";
|
|
11
12
|
/**
|
|
12
13
|
* Public API schema for listApps operation
|
|
13
14
|
*
|
|
@@ -29,6 +30,7 @@ export const ListAppsOptionsSchema = z
|
|
|
29
30
|
.describe("Maximum total items to return across all pages"),
|
|
30
31
|
cursor: z.string().optional().describe("Cursor to start from"),
|
|
31
32
|
})
|
|
33
|
+
.merge(TelemetryMarkerSchema)
|
|
32
34
|
.describe("List all available apps with optional filtering");
|
|
33
35
|
/**
|
|
34
36
|
* Normalized app item returned by listApps
|
|
@@ -71,6 +71,35 @@ export interface ApplicationLifecycleEvent extends BaseEvent {
|
|
|
71
71
|
shutdown_duration_ms?: number | null;
|
|
72
72
|
active_requests_count?: number | null;
|
|
73
73
|
}
|
|
74
|
-
export
|
|
75
|
-
|
|
74
|
+
export interface MethodCalledEvent extends BaseEvent {
|
|
75
|
+
method_name: string;
|
|
76
|
+
method_module: string | null;
|
|
77
|
+
execution_duration_ms: number;
|
|
78
|
+
success_flag: boolean;
|
|
79
|
+
error_message: string | null;
|
|
80
|
+
error_type: string | null;
|
|
81
|
+
argument_count: number;
|
|
82
|
+
is_paginated: boolean;
|
|
83
|
+
sdk_version: string;
|
|
84
|
+
environment: string | null;
|
|
85
|
+
selected_api: string | null;
|
|
86
|
+
app_id: number | null;
|
|
87
|
+
app_version_id: number | null;
|
|
88
|
+
zap_id: number | null;
|
|
89
|
+
node_id: number | null;
|
|
90
|
+
operation_type: string | null;
|
|
91
|
+
operation_key: string | null;
|
|
92
|
+
call_context: string | null;
|
|
93
|
+
is_retry: boolean;
|
|
94
|
+
retry_attempt: number | null;
|
|
95
|
+
argument_types: string[] | null;
|
|
96
|
+
return_type: string | null;
|
|
97
|
+
caller_method: string | null;
|
|
98
|
+
call_stack_depth: number | null;
|
|
99
|
+
is_synchronous: boolean | null;
|
|
100
|
+
cpu_time_ms: number | null;
|
|
101
|
+
memory_usage_bytes: number | null;
|
|
102
|
+
}
|
|
103
|
+
export type TelemetryEvent = ErrorOccurredEvent | ApplicationLifecycleEvent | MethodCalledEvent;
|
|
104
|
+
export type TelemetryEventType = "error_occurred" | "application_lifecycle" | "method_called";
|
|
76
105
|
//# sourceMappingURL=telemetry-events.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"telemetry-events.d.ts","sourceRoot":"","sources":["../../src/types/telemetry-events.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,MAAM,WAAW,SAAS;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAChC;AAGD,MAAM,WAAW,kBAAmB,SAAQ,SAAS;IACnD,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,iBAAiB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAClC,iBAAiB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAClC,mBAAmB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACpC,iBAAiB,CAAC,EAAE,MAAM,GAAG,IAAI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,IAAI,CAAC;IACvB,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,QAAQ,EAAE,OAAO,CAAC;IAClB,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,cAAc,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;IAChC,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,cAAc,EAAE,OAAO,GAAG,IAAI,CAAC;IAC/B,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,kBAAkB,EAAE,MAAM,GAAG,IAAI,CAAC;CACnC;AAGD,MAAM,MAAM,cAAc,GACtB,kBAAkB,GAClB,yBAAyB,GACzB,iBAAiB,CAAC;AAGtB,MAAM,MAAM,kBAAkB,GAC1B,gBAAgB,GAChB,uBAAuB,GACvB,eAAe,CAAC"}
|
|
@@ -1,7 +1,45 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Generic utility functions for creating paginated SDK functions
|
|
3
3
|
*/
|
|
4
|
-
import
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
/**
|
|
6
|
+
* Zod schema for telemetry marker to prevent nested telemetry emissions.
|
|
7
|
+
* Used to extend options schemas with proper typing.
|
|
8
|
+
*/
|
|
9
|
+
export declare const TelemetryMarkerSchema: z.ZodObject<{
|
|
10
|
+
_telemetry: z.ZodOptional<z.ZodObject<{
|
|
11
|
+
isNested: z.ZodOptional<z.ZodBoolean>;
|
|
12
|
+
}, "strip", z.ZodTypeAny, {
|
|
13
|
+
isNested?: boolean | undefined;
|
|
14
|
+
}, {
|
|
15
|
+
isNested?: boolean | undefined;
|
|
16
|
+
}>>;
|
|
17
|
+
}, "strip", z.ZodTypeAny, {
|
|
18
|
+
_telemetry?: {
|
|
19
|
+
isNested?: boolean | undefined;
|
|
20
|
+
} | undefined;
|
|
21
|
+
}, {
|
|
22
|
+
_telemetry?: {
|
|
23
|
+
isNested?: boolean | undefined;
|
|
24
|
+
} | undefined;
|
|
25
|
+
}>;
|
|
26
|
+
/**
|
|
27
|
+
* Marker for SDK method calls to control telemetry behavior
|
|
28
|
+
*/
|
|
29
|
+
export type TelemetryMarker = z.infer<typeof TelemetryMarkerSchema>;
|
|
30
|
+
/**
|
|
31
|
+
* Callbacks for telemetry events during function execution
|
|
32
|
+
*/
|
|
33
|
+
export interface TelemetryCallbacks {
|
|
34
|
+
onMethodCalled?: (data: {
|
|
35
|
+
methodName: string;
|
|
36
|
+
durationMs: number;
|
|
37
|
+
success: boolean;
|
|
38
|
+
error?: Error;
|
|
39
|
+
argumentCount: number;
|
|
40
|
+
isPaginated: boolean;
|
|
41
|
+
}) => void;
|
|
42
|
+
}
|
|
5
43
|
/**
|
|
6
44
|
* Helper function to extract cursor from pagination data
|
|
7
45
|
*/
|
|
@@ -13,9 +51,10 @@ export declare function extractCursor(data: {
|
|
|
13
51
|
*
|
|
14
52
|
* @param coreFn - Function that returns T directly or throws errors
|
|
15
53
|
* @param schema - Optional Zod schema for validation
|
|
54
|
+
* @param telemetry - Optional telemetry callbacks
|
|
16
55
|
* @returns A function that normalizes and rethrows errors
|
|
17
56
|
*/
|
|
18
|
-
export declare function createFunction<TOptions, TResult, TSchemaOptions extends TOptions = TOptions>(coreFn: (options: TOptions) => Promise<TResult>, schema?: z.ZodSchema<TSchemaOptions
|
|
57
|
+
export declare function createFunction<TOptions, TResult, TSchemaOptions extends TOptions = TOptions>(coreFn: (options: TOptions) => Promise<TResult>, schema?: z.ZodSchema<TSchemaOptions>, telemetry?: TelemetryCallbacks): (options?: TOptions) => Promise<TResult>;
|
|
19
58
|
/**
|
|
20
59
|
* Higher-order function that creates a paginated function that wraps results in {data}
|
|
21
60
|
*
|
|
@@ -34,7 +73,7 @@ type ItemType<TResult> = TResult extends {
|
|
|
34
73
|
} ? TData extends readonly (infer TItem)[] ? TItem : TData : TResult extends readonly (infer TItem)[] ? TItem : TResult;
|
|
35
74
|
export declare function createPaginatedFunction<TOptions, TResult, TSchemaOptions extends TOptions = TOptions>(coreFn: (options: TOptions & {
|
|
36
75
|
pageSize: number;
|
|
37
|
-
}) => Promise<TResult>, schema?: z.ZodSchema<TSchemaOptions
|
|
76
|
+
}) => Promise<TResult>, schema?: z.ZodSchema<TSchemaOptions>, telemetry?: TelemetryCallbacks, explicitFunctionName?: string): (options?: TOptions & {
|
|
38
77
|
cursor?: string;
|
|
39
78
|
pageSize?: number;
|
|
40
79
|
maxItems?: number;
|
|
@@ -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,aAA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C9B,oBAAoB,CAAC,EAAE,MAAM,GAC5B,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, explicitFunctionName) {
|
|
100
148
|
const pageFunction = createPageFunction(coreFn);
|
|
101
|
-
const functionName = coreFn.name;
|
|
149
|
+
const functionName = explicitFunctionName || 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* () {
|
|
@@ -18,4 +18,23 @@ export declare function toTitleCase(input: string): string;
|
|
|
18
18
|
* - starts with number: "123abc" → "_123abc"
|
|
19
19
|
*/
|
|
20
20
|
export declare function toSnakeCase(input: string): string;
|
|
21
|
+
/**
|
|
22
|
+
* Strips the "Page" suffix from a function name, used for deriving method names
|
|
23
|
+
* from paginated function implementations.
|
|
24
|
+
*
|
|
25
|
+
* This is commonly used with `createPaginatedFunction` where the internal function
|
|
26
|
+
* has a "Page" suffix (e.g., "listAppsPage") but the public method name should not
|
|
27
|
+
* (e.g., "listApps").
|
|
28
|
+
*
|
|
29
|
+
* @param functionName - The function name, typically from `function.name`
|
|
30
|
+
* @returns The function name with "Page" suffix removed, or original if no suffix
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* stripPageSuffix("listAppsPage") // "listApps"
|
|
35
|
+
* stripPageSuffix("listApps") // "listApps" (no change)
|
|
36
|
+
* stripPageSuffix("myPageFunction") // "myPageFunction" (only strips from end)
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export declare function stripPageSuffix(functionName: string): string;
|
|
21
40
|
//# sourceMappingURL=string-utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"string-utils.d.ts","sourceRoot":"","sources":["../../src/utils/string-utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAcjD;AAED;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAkBjD"}
|
|
1
|
+
{"version":3,"file":"string-utils.d.ts","sourceRoot":"","sources":["../../src/utils/string-utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAcjD;AAED;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAkBjD;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,eAAe,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAE5D"}
|
|
@@ -46,3 +46,24 @@ export function toSnakeCase(input) {
|
|
|
46
46
|
}
|
|
47
47
|
return result;
|
|
48
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* Strips the "Page" suffix from a function name, used for deriving method names
|
|
51
|
+
* from paginated function implementations.
|
|
52
|
+
*
|
|
53
|
+
* This is commonly used with `createPaginatedFunction` where the internal function
|
|
54
|
+
* has a "Page" suffix (e.g., "listAppsPage") but the public method name should not
|
|
55
|
+
* (e.g., "listApps").
|
|
56
|
+
*
|
|
57
|
+
* @param functionName - The function name, typically from `function.name`
|
|
58
|
+
* @returns The function name with "Page" suffix removed, or original if no suffix
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```typescript
|
|
62
|
+
* stripPageSuffix("listAppsPage") // "listApps"
|
|
63
|
+
* stripPageSuffix("listApps") // "listApps" (no change)
|
|
64
|
+
* stripPageSuffix("myPageFunction") // "myPageFunction" (only strips from end)
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
export function stripPageSuffix(functionName) {
|
|
68
|
+
return functionName.replace(/Page$/, "");
|
|
69
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, it, expect } from "vitest";
|
|
2
|
-
import { toTitleCase } from "./string-utils";
|
|
2
|
+
import { toTitleCase, stripPageSuffix } from "./string-utils";
|
|
3
3
|
describe("toTitleCase", () => {
|
|
4
4
|
it("converts snake_case to title case", () => {
|
|
5
5
|
expect(toTitleCase("first_name")).toBe("First Name");
|
|
@@ -34,3 +34,26 @@ describe("toTitleCase", () => {
|
|
|
34
34
|
expect(toTitleCase("_")).toBe("");
|
|
35
35
|
});
|
|
36
36
|
});
|
|
37
|
+
describe("stripPageSuffix", () => {
|
|
38
|
+
it("strips Page suffix from function names", () => {
|
|
39
|
+
expect(stripPageSuffix("listAppsPage")).toBe("listApps");
|
|
40
|
+
expect(stripPageSuffix("listActionsPage")).toBe("listActions");
|
|
41
|
+
expect(stripPageSuffix("runActionPage")).toBe("runAction");
|
|
42
|
+
expect(stripPageSuffix("listAuthenticationsPage")).toBe("listAuthentications");
|
|
43
|
+
});
|
|
44
|
+
it("leaves names without Page suffix unchanged", () => {
|
|
45
|
+
expect(stripPageSuffix("listApps")).toBe("listApps");
|
|
46
|
+
expect(stripPageSuffix("getProfile")).toBe("getProfile");
|
|
47
|
+
expect(stripPageSuffix("request")).toBe("request");
|
|
48
|
+
});
|
|
49
|
+
it("only strips Page from the end", () => {
|
|
50
|
+
expect(stripPageSuffix("myPageFunction")).toBe("myPageFunction");
|
|
51
|
+
expect(stripPageSuffix("PageList")).toBe("PageList");
|
|
52
|
+
expect(stripPageSuffix("getPageData")).toBe("getPageData");
|
|
53
|
+
});
|
|
54
|
+
it("handles edge cases", () => {
|
|
55
|
+
expect(stripPageSuffix("Page")).toBe("");
|
|
56
|
+
expect(stripPageSuffix("")).toBe("");
|
|
57
|
+
expect(stripPageSuffix("p")).toBe("p");
|
|
58
|
+
});
|
|
59
|
+
});
|
|
@@ -0,0 +1,44 @@
|
|
|
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 method name to report in telemetry. Use `function.name` to derive
|
|
11
|
+
* this automatically from the function declaration, ensuring DRY principles and making
|
|
12
|
+
* refactoring easier. Function names are preserved through bundling.
|
|
13
|
+
* @returns TelemetryCallbacks object with standardized onMethodCalled implementation
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* Basic usage with createFunction:
|
|
17
|
+
* ```typescript
|
|
18
|
+
* async function listApps(options: ListAppsOptions) { ... }
|
|
19
|
+
*
|
|
20
|
+
* const listAppsDefinition = createFunction(
|
|
21
|
+
* listApps,
|
|
22
|
+
* ListAppsSchema,
|
|
23
|
+
* createTelemetryCallback(context.eventEmission.emitMethodCalled, listApps.name),
|
|
24
|
+
* );
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* For paginated functions, use stripPageSuffix to remove the "Page" suffix:
|
|
29
|
+
* ```typescript
|
|
30
|
+
* import { stripPageSuffix } from "./string-utils";
|
|
31
|
+
*
|
|
32
|
+
* async function listAppsPage(options: ListAppsOptions & { pageSize: number }) { ... }
|
|
33
|
+
*
|
|
34
|
+
* const methodName = stripPageSuffix(listAppsPage.name);
|
|
35
|
+
* const listAppsDefinition = createPaginatedFunction(
|
|
36
|
+
* listAppsPage,
|
|
37
|
+
* ListAppsSchema,
|
|
38
|
+
* createTelemetryCallback(context.eventEmission.emitMethodCalled, methodName),
|
|
39
|
+
* methodName,
|
|
40
|
+
* );
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export declare function createTelemetryCallback(emitMethodCalled: EventEmissionContext["eventEmission"]["emitMethodCalled"], methodName: string): TelemetryCallbacks;
|
|
44
|
+
//# 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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,wBAAgB,uBAAuB,CACrC,gBAAgB,EAAE,oBAAoB,CAAC,eAAe,CAAC,CAAC,kBAAkB,CAAC,EAC3E,UAAU,EAAE,MAAM,GACjB,kBAAkB,CAcpB"}
|
|
@@ -0,0 +1,55 @@
|
|
|
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 method name to report in telemetry. Use `function.name` to derive
|
|
9
|
+
* this automatically from the function declaration, ensuring DRY principles and making
|
|
10
|
+
* refactoring easier. Function names are preserved through bundling.
|
|
11
|
+
* @returns TelemetryCallbacks object with standardized onMethodCalled implementation
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* Basic usage with createFunction:
|
|
15
|
+
* ```typescript
|
|
16
|
+
* async function listApps(options: ListAppsOptions) { ... }
|
|
17
|
+
*
|
|
18
|
+
* const listAppsDefinition = createFunction(
|
|
19
|
+
* listApps,
|
|
20
|
+
* ListAppsSchema,
|
|
21
|
+
* createTelemetryCallback(context.eventEmission.emitMethodCalled, listApps.name),
|
|
22
|
+
* );
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* For paginated functions, use stripPageSuffix to remove the "Page" suffix:
|
|
27
|
+
* ```typescript
|
|
28
|
+
* import { stripPageSuffix } from "./string-utils";
|
|
29
|
+
*
|
|
30
|
+
* async function listAppsPage(options: ListAppsOptions & { pageSize: number }) { ... }
|
|
31
|
+
*
|
|
32
|
+
* const methodName = stripPageSuffix(listAppsPage.name);
|
|
33
|
+
* const listAppsDefinition = createPaginatedFunction(
|
|
34
|
+
* listAppsPage,
|
|
35
|
+
* ListAppsSchema,
|
|
36
|
+
* createTelemetryCallback(context.eventEmission.emitMethodCalled, methodName),
|
|
37
|
+
* methodName,
|
|
38
|
+
* );
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export function createTelemetryCallback(emitMethodCalled, methodName) {
|
|
42
|
+
return {
|
|
43
|
+
onMethodCalled: (data) => {
|
|
44
|
+
emitMethodCalled({
|
|
45
|
+
method_name: methodName,
|
|
46
|
+
execution_duration_ms: data.durationMs,
|
|
47
|
+
success_flag: data.success,
|
|
48
|
+
error_message: data.error?.message ?? null,
|
|
49
|
+
error_type: data.error?.constructor.name ?? null,
|
|
50
|
+
argument_count: data.argumentCount,
|
|
51
|
+
is_paginated: data.isPaginated,
|
|
52
|
+
});
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
}
|
|
@@ -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
|
+
});
|