@zapier/zapier-sdk 0.30.0 → 0.31.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.
- package/CHANGELOG.md +12 -0
- package/README.md +23 -9
- package/dist/api/schemas.d.ts +2 -2
- package/dist/index.cjs +120 -18
- package/dist/index.d.mts +206 -56
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.mjs +114 -19
- package/dist/plugins/eventEmission/builders.js +3 -3
- package/dist/plugins/eventEmission/builders.test.d.ts +2 -0
- package/dist/plugins/eventEmission/builders.test.d.ts.map +1 -0
- package/dist/plugins/eventEmission/builders.test.js +56 -0
- package/dist/plugins/eventEmission/types.d.ts +3 -0
- package/dist/plugins/eventEmission/types.d.ts.map +1 -1
- package/dist/plugins/findFirstConnection/schemas.d.ts +1 -1
- package/dist/plugins/findUniqueConnection/schemas.d.ts +1 -1
- package/dist/plugins/getAction/index.d.ts.map +1 -1
- package/dist/plugins/getAction/index.js +7 -0
- package/dist/plugins/getInputFieldsSchema/index.d.ts.map +1 -1
- package/dist/plugins/getInputFieldsSchema/index.js +6 -0
- package/dist/plugins/listActions/index.d.ts.map +1 -1
- package/dist/plugins/listActions/index.js +6 -0
- package/dist/plugins/listConnections/index.d.ts.map +1 -1
- package/dist/plugins/listConnections/index.js +2 -0
- package/dist/plugins/listConnections/schemas.d.ts +1 -1
- package/dist/plugins/listInputFieldChoices/index.d.ts.map +1 -1
- package/dist/plugins/listInputFieldChoices/index.js +6 -0
- package/dist/plugins/listInputFields/index.d.ts.map +1 -1
- package/dist/plugins/listInputFields/index.js +6 -0
- package/dist/plugins/runAction/index.d.ts.map +1 -1
- package/dist/plugins/runAction/index.js +12 -8
- package/dist/schemas/Action.d.ts +2 -2
- package/dist/types/credentials.d.ts +137 -17
- package/dist/types/credentials.d.ts.map +1 -1
- package/dist/types/credentials.js +80 -0
- package/dist/types/meta.d.ts +9 -0
- package/dist/types/meta.d.ts.map +1 -0
- package/dist/types/meta.js +3 -0
- package/dist/types/sdk.d.ts +61 -35
- package/dist/types/sdk.d.ts.map +1 -1
- package/dist/types/sdk.js +55 -1
- package/dist/utils/telemetry-context.d.ts +12 -0
- package/dist/utils/telemetry-context.d.ts.map +1 -1
- package/dist/utils/telemetry-context.js +18 -0
- package/dist/utils/telemetry-context.test.js +63 -1
- package/dist/utils/telemetry-utils.d.ts.map +1 -1
- package/dist/utils/telemetry-utils.js +5 -0
- package/dist/utils/telemetry-utils.test.js +61 -0
- package/package.json +1 -1
|
@@ -8,6 +8,86 @@
|
|
|
8
8
|
* - PKCE: OAuth client ID for interactive login (CLI only)
|
|
9
9
|
* - Function: Lazy/dynamic credential resolution
|
|
10
10
|
*/
|
|
11
|
+
import { z } from "zod";
|
|
12
|
+
/**
|
|
13
|
+
* Client credentials for OAuth client_credentials flow.
|
|
14
|
+
* The SDK will exchange these for an access token.
|
|
15
|
+
*/
|
|
16
|
+
export const ClientCredentialsObjectSchema = z.object({
|
|
17
|
+
type: z.enum(["client_credentials"]).optional().meta({ internal: true }),
|
|
18
|
+
clientId: z
|
|
19
|
+
.string()
|
|
20
|
+
.describe("OAuth client ID for authentication.")
|
|
21
|
+
.meta({ valueHint: "id" }),
|
|
22
|
+
clientSecret: z
|
|
23
|
+
.string()
|
|
24
|
+
.describe("OAuth client secret for authentication.")
|
|
25
|
+
.meta({ valueHint: "secret" }),
|
|
26
|
+
baseUrl: z
|
|
27
|
+
.string()
|
|
28
|
+
.optional()
|
|
29
|
+
.describe("Override authentication base URL.")
|
|
30
|
+
.meta({ valueHint: "url" }),
|
|
31
|
+
scope: z
|
|
32
|
+
.string()
|
|
33
|
+
.optional()
|
|
34
|
+
.describe("Authentication scope.")
|
|
35
|
+
.meta({ internal: true }),
|
|
36
|
+
});
|
|
37
|
+
/**
|
|
38
|
+
* PKCE credentials for interactive OAuth flow.
|
|
39
|
+
* Only works when @zapier/zapier-sdk-cli-login is available.
|
|
40
|
+
*/
|
|
41
|
+
export const PkceCredentialsObjectSchema = z.object({
|
|
42
|
+
type: z.enum(["pkce"]).optional().meta({ internal: true }),
|
|
43
|
+
clientId: z
|
|
44
|
+
.string()
|
|
45
|
+
.describe("OAuth client ID for authentication.")
|
|
46
|
+
.meta({ valueHint: "id" }),
|
|
47
|
+
baseUrl: z
|
|
48
|
+
.string()
|
|
49
|
+
.optional()
|
|
50
|
+
.describe("Override authentication base URL.")
|
|
51
|
+
.meta({ valueHint: "url" }),
|
|
52
|
+
scope: z
|
|
53
|
+
.string()
|
|
54
|
+
.optional()
|
|
55
|
+
.describe("Authentication scope.")
|
|
56
|
+
.meta({ internal: true }),
|
|
57
|
+
});
|
|
58
|
+
/**
|
|
59
|
+
* Union of all credential object types.
|
|
60
|
+
*/
|
|
61
|
+
export const CredentialsObjectSchema = z.union([
|
|
62
|
+
ClientCredentialsObjectSchema,
|
|
63
|
+
PkceCredentialsObjectSchema,
|
|
64
|
+
]);
|
|
65
|
+
/**
|
|
66
|
+
* Resolved credentials - what a credentials function must return.
|
|
67
|
+
* Either a string (token) or a credentials object.
|
|
68
|
+
* Functions are not allowed to return other functions.
|
|
69
|
+
*/
|
|
70
|
+
export const ResolvedCredentialsSchema = z.union([
|
|
71
|
+
z.string().describe("Authentication token.").meta({ valueHint: "token" }),
|
|
72
|
+
CredentialsObjectSchema,
|
|
73
|
+
]);
|
|
74
|
+
/**
|
|
75
|
+
* Lazy/dynamic credential resolution — a function returning resolved credentials.
|
|
76
|
+
*/
|
|
77
|
+
export const CredentialsFunctionSchema = z
|
|
78
|
+
.function()
|
|
79
|
+
.input([])
|
|
80
|
+
.output(z.union([ResolvedCredentialsSchema, z.promise(ResolvedCredentialsSchema)]));
|
|
81
|
+
/**
|
|
82
|
+
* Credentials can be:
|
|
83
|
+
* - A string (token or API key)
|
|
84
|
+
* - A credentials object (client_credentials or pkce)
|
|
85
|
+
* - A function that returns credentials (sync or async)
|
|
86
|
+
*/
|
|
87
|
+
export const CredentialsSchema = z.union([
|
|
88
|
+
ResolvedCredentialsSchema,
|
|
89
|
+
CredentialsFunctionSchema,
|
|
90
|
+
]);
|
|
11
91
|
/**
|
|
12
92
|
* Type guard for client credentials objects.
|
|
13
93
|
*/
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"meta.d.ts","sourceRoot":"","sources":["../../src/types/meta.ts"],"names":[],"mappings":"AAGA,OAAO,QAAQ,KAAK,CAAC;IACnB,UAAU,UAAU;QAClB,QAAQ,CAAC,EAAE,OAAO,CAAC;QACnB,UAAU,CAAC,EAAE,OAAO,CAAC;QACrB,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB;CACF;AAGD,OAAO,EAAE,CAAC"}
|
package/dist/types/sdk.d.ts
CHANGED
|
@@ -1,49 +1,75 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* SDK-related types and interfaces
|
|
3
3
|
*/
|
|
4
|
+
import { z } from "zod";
|
|
4
5
|
import type { EventCallback } from "./events";
|
|
5
6
|
import type { EventEmissionConfig } from "../plugins/eventEmission";
|
|
6
7
|
import type { Manifest } from "../plugins/manifest";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
8
|
+
export declare const BaseSdkOptionsSchema: z.ZodObject<{
|
|
9
|
+
credentials: z.ZodOptional<z.ZodUnion<readonly [z.ZodUnion<readonly [z.ZodString, z.ZodUnion<readonly [z.ZodObject<{
|
|
10
|
+
type: z.ZodOptional<z.ZodEnum<{
|
|
11
|
+
client_credentials: "client_credentials";
|
|
12
|
+
}>>;
|
|
13
|
+
clientId: z.ZodString;
|
|
14
|
+
clientSecret: z.ZodString;
|
|
15
|
+
baseUrl: z.ZodOptional<z.ZodString>;
|
|
16
|
+
scope: z.ZodOptional<z.ZodString>;
|
|
17
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
18
|
+
type: z.ZodOptional<z.ZodEnum<{
|
|
19
|
+
pkce: "pkce";
|
|
20
|
+
}>>;
|
|
21
|
+
clientId: z.ZodString;
|
|
22
|
+
baseUrl: z.ZodOptional<z.ZodString>;
|
|
23
|
+
scope: z.ZodOptional<z.ZodString>;
|
|
24
|
+
}, z.core.$strip>]>]>, z.ZodFunction<z.core.$ZodTuple<readonly [], z.core.$ZodFunctionOut>, z.ZodUnion<readonly [z.ZodUnion<readonly [z.ZodString, z.ZodUnion<readonly [z.ZodObject<{
|
|
25
|
+
type: z.ZodOptional<z.ZodEnum<{
|
|
26
|
+
client_credentials: "client_credentials";
|
|
27
|
+
}>>;
|
|
28
|
+
clientId: z.ZodString;
|
|
29
|
+
clientSecret: z.ZodString;
|
|
30
|
+
baseUrl: z.ZodOptional<z.ZodString>;
|
|
31
|
+
scope: z.ZodOptional<z.ZodString>;
|
|
32
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
33
|
+
type: z.ZodOptional<z.ZodEnum<{
|
|
34
|
+
pkce: "pkce";
|
|
35
|
+
}>>;
|
|
36
|
+
clientId: z.ZodString;
|
|
37
|
+
baseUrl: z.ZodOptional<z.ZodString>;
|
|
38
|
+
scope: z.ZodOptional<z.ZodString>;
|
|
39
|
+
}, z.core.$strip>]>]>, z.ZodPromise<z.ZodUnion<readonly [z.ZodString, z.ZodUnion<readonly [z.ZodObject<{
|
|
40
|
+
type: z.ZodOptional<z.ZodEnum<{
|
|
41
|
+
client_credentials: "client_credentials";
|
|
42
|
+
}>>;
|
|
43
|
+
clientId: z.ZodString;
|
|
44
|
+
clientSecret: z.ZodString;
|
|
45
|
+
baseUrl: z.ZodOptional<z.ZodString>;
|
|
46
|
+
scope: z.ZodOptional<z.ZodString>;
|
|
47
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
48
|
+
type: z.ZodOptional<z.ZodEnum<{
|
|
49
|
+
pkce: "pkce";
|
|
50
|
+
}>>;
|
|
51
|
+
clientId: z.ZodString;
|
|
52
|
+
baseUrl: z.ZodOptional<z.ZodString>;
|
|
53
|
+
scope: z.ZodOptional<z.ZodString>;
|
|
54
|
+
}, z.core.$strip>]>]>>]>>]>>;
|
|
55
|
+
debug: z.ZodOptional<z.ZodBoolean>;
|
|
56
|
+
baseUrl: z.ZodOptional<z.ZodString>;
|
|
57
|
+
trackingBaseUrl: z.ZodOptional<z.ZodString>;
|
|
58
|
+
maxNetworkRetries: z.ZodOptional<z.ZodNumber>;
|
|
59
|
+
maxNetworkRetryDelayMs: z.ZodOptional<z.ZodNumber>;
|
|
60
|
+
manifestPath: z.ZodOptional<z.ZodString>;
|
|
61
|
+
manifest: z.ZodOptional<z.ZodCustom<Manifest, Manifest>>;
|
|
62
|
+
onEvent: z.ZodOptional<z.ZodCustom<EventCallback, EventCallback>>;
|
|
63
|
+
fetch: z.ZodOptional<z.ZodCustom<typeof fetch, typeof fetch>>;
|
|
64
|
+
eventEmission: z.ZodOptional<z.ZodCustom<EventEmissionConfig, EventEmissionConfig>>;
|
|
65
|
+
token: z.ZodOptional<z.ZodString>;
|
|
66
|
+
}, z.core.$strip>;
|
|
67
|
+
export type BaseSdkOptions = z.infer<typeof BaseSdkOptionsSchema>;
|
|
41
68
|
import type { ListInputFieldsSdkFunction } from "../plugins/listInputFields/schemas";
|
|
42
69
|
import type { GetConnectionSdkFunction } from "../plugins/getConnection/schemas";
|
|
43
70
|
import type { FindFirstConnectionSdkFunction } from "../plugins/findFirstConnection/schemas";
|
|
44
71
|
import type { FindUniqueConnectionSdkFunction } from "../plugins/findUniqueConnection/schemas";
|
|
45
72
|
import type { RelayRequestSdkFunction } from "../plugins/request/schemas";
|
|
46
|
-
import type { z } from "zod";
|
|
47
73
|
import type { RegistryPluginProvides } from "../plugins/registry";
|
|
48
74
|
import type { GetProfilePluginProvides } from "../plugins/getProfile";
|
|
49
75
|
import type { EventEmissionProvides } from "../plugins/eventEmission";
|
package/dist/types/sdk.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sdk.d.ts","sourceRoot":"","sources":["../../src/types/sdk.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,
|
|
1
|
+
{"version":3,"file":"sdk.d.ts","sourceRoot":"","sources":["../../src/types/sdk.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAC9C,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AACpE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAIpD,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAuD/B,CAAC;AAEH,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAGlE,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,oCAAoC,CAAC;AACrF,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,kCAAkC,CAAC;AACjF,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,wCAAwC,CAAC;AAC7F,OAAO,KAAK,EAAE,+BAA+B,EAAE,MAAM,yCAAyC,CAAC;AAC/F,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAC;AAE1E,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CA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AC/B,uBAAuB;CAE1B;AAUD,MAAM,WAAW,SACf,SAAQ,UAAU,CAChB,sBAAsB,GACpB,mBAAmB,GACnB,kBAAkB,GAClB,sBAAsB,GACtB,sBAAsB,GACtB,oBAAoB,GACpB,yBAAyB,GACzB,uBAAuB,GACvB,uBAAuB,GAEvB,6BAA6B,GAC7B,2BAA2B,GAC3B,iCAAiC,GACjC,kCAAkC,GAElC,iCAAiC,GACjC,+BAA+B,GAC/B,qCAAqC,GACrC,sCAAsC,GACtC,mCAAmC,GACnC,qCAAqC,GACrC,qCAAqC,GACrC,6BAA6B,GAC7B,kCAAkC,GAClC,mCAAmC,GACnC,qBAAqB,GACrB,wBAAwB,GACxB,qBAAqB,GACrB,iBAAiB,CACpB;IAED,IAAI,EAAE,WAAW,GAAG,aAAa,CAAC;CACnC"}
|
package/dist/types/sdk.js
CHANGED
|
@@ -1,4 +1,58 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* SDK-related types and interfaces
|
|
3
3
|
*/
|
|
4
|
-
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
import { CredentialsSchema } from "./credentials";
|
|
6
|
+
// SDK Configuration Types
|
|
7
|
+
export const BaseSdkOptionsSchema = z.object({
|
|
8
|
+
credentials: CredentialsSchema.optional().describe("Authentication credentials. Can be a string (token or API key), a client credentials object ({ clientId, clientSecret }), a PKCE object ({ clientId }), or a function returning any of those."),
|
|
9
|
+
debug: z.boolean().optional().describe("Enable debug logging."),
|
|
10
|
+
baseUrl: z
|
|
11
|
+
.string()
|
|
12
|
+
.optional()
|
|
13
|
+
.describe("Base URL for Zapier API endpoints.")
|
|
14
|
+
.meta({ valueHint: "url" }),
|
|
15
|
+
trackingBaseUrl: z
|
|
16
|
+
.string()
|
|
17
|
+
.optional()
|
|
18
|
+
.describe("Base URL for Zapier tracking endpoints.")
|
|
19
|
+
.meta({ valueHint: "url" }),
|
|
20
|
+
/**
|
|
21
|
+
* Maximum number of retries for rate-limited requests (429 responses).
|
|
22
|
+
* Set to 0 to disable retries. Default is 3.
|
|
23
|
+
*/
|
|
24
|
+
maxNetworkRetries: z
|
|
25
|
+
.number()
|
|
26
|
+
.optional()
|
|
27
|
+
.describe("Max retries for rate-limited requests (default: 3).")
|
|
28
|
+
.meta({ valueHint: "count" }),
|
|
29
|
+
/**
|
|
30
|
+
* Maximum delay in milliseconds to wait for a rate limit retry.
|
|
31
|
+
* If the server requests a longer delay, the request fails immediately.
|
|
32
|
+
* Default is 60000 (60 seconds).
|
|
33
|
+
*/
|
|
34
|
+
maxNetworkRetryDelayMs: z
|
|
35
|
+
.number()
|
|
36
|
+
.optional()
|
|
37
|
+
.describe("Max delay in ms to wait for retry (default: 60000).")
|
|
38
|
+
.meta({ valueHint: "ms" }),
|
|
39
|
+
// Internal
|
|
40
|
+
manifestPath: z
|
|
41
|
+
.string()
|
|
42
|
+
.optional()
|
|
43
|
+
.describe("Path to a .zapierrc manifest file for app version locking.")
|
|
44
|
+
.meta({ internal: true }),
|
|
45
|
+
manifest: z
|
|
46
|
+
.custom()
|
|
47
|
+
.optional()
|
|
48
|
+
.describe("Manifest for app version locking.")
|
|
49
|
+
.meta({ internal: true }),
|
|
50
|
+
onEvent: z.custom().optional().meta({ internal: true }),
|
|
51
|
+
fetch: z.custom().optional().meta({ internal: true }),
|
|
52
|
+
eventEmission: z
|
|
53
|
+
.custom()
|
|
54
|
+
.optional()
|
|
55
|
+
.meta({ internal: true }),
|
|
56
|
+
// Deprecated
|
|
57
|
+
token: z.string().optional().meta({ deprecated: true }), // Use credentials instead
|
|
58
|
+
});
|
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Async-local storage context for per-invocation telemetry state. Each top-level
|
|
3
|
+
* SDK method call runs in its own ALS scope (via runWithTelemetryContext), isolating
|
|
4
|
+
* its depth counter and method metadata from concurrent calls.
|
|
5
|
+
*/
|
|
6
|
+
export interface MethodMetadata {
|
|
7
|
+
selectedApi?: string | null;
|
|
8
|
+
operationType?: string | null;
|
|
9
|
+
operationKey?: string | null;
|
|
10
|
+
}
|
|
1
11
|
export declare function isTelemetryNested(): boolean;
|
|
2
12
|
export declare function runWithTelemetryContext<T>(fn: () => T): T;
|
|
13
|
+
export declare function setMethodMetadata(metadata: MethodMetadata): void;
|
|
14
|
+
export declare function getMethodMetadata(): MethodMetadata | undefined;
|
|
3
15
|
//# sourceMappingURL=telemetry-context.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"telemetry-context.d.ts","sourceRoot":"","sources":["../../src/utils/telemetry-context.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"telemetry-context.d.ts","sourceRoot":"","sources":["../../src/utils/telemetry-context.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,MAAM,WAAW,cAAc;IAC7B,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC9B;AAoBD,wBAAgB,iBAAiB,IAAI,OAAO,CAI3C;AAED,wBAAgB,uBAAuB,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,CAIzD;AAED,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,cAAc,GAAG,IAAI,CAKhE;AAED,wBAAgB,iBAAiB,IAAI,cAAc,GAAG,SAAS,CAG9D"}
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Async-local storage context for per-invocation telemetry state. Each top-level
|
|
3
|
+
* SDK method call runs in its own ALS scope (via runWithTelemetryContext), isolating
|
|
4
|
+
* its depth counter and method metadata from concurrent calls.
|
|
5
|
+
*/
|
|
1
6
|
// Intentional dynamic require — one-time environment detection for AsyncLocalStorage
|
|
2
7
|
// availability (e.g., unavailable in browsers). This is NOT lazy loading.
|
|
3
8
|
let telemetryStore = null;
|
|
@@ -21,3 +26,16 @@ export function runWithTelemetryContext(fn) {
|
|
|
21
26
|
const currentDepth = telemetryStore.getStore()?.depth ?? -1;
|
|
22
27
|
return telemetryStore.run({ depth: currentDepth + 1 }, fn);
|
|
23
28
|
}
|
|
29
|
+
export function setMethodMetadata(metadata) {
|
|
30
|
+
if (!telemetryStore)
|
|
31
|
+
return;
|
|
32
|
+
const store = telemetryStore.getStore();
|
|
33
|
+
if (!store)
|
|
34
|
+
return;
|
|
35
|
+
store.methodMetadata = { ...store.methodMetadata, ...metadata };
|
|
36
|
+
}
|
|
37
|
+
export function getMethodMetadata() {
|
|
38
|
+
if (!telemetryStore)
|
|
39
|
+
return undefined;
|
|
40
|
+
return telemetryStore.getStore()?.methodMetadata;
|
|
41
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, it, expect } from "vitest";
|
|
2
|
-
import { isTelemetryNested, runWithTelemetryContext, } from "./telemetry-context";
|
|
2
|
+
import { isTelemetryNested, runWithTelemetryContext, setMethodMetadata, getMethodMetadata, } from "./telemetry-context";
|
|
3
3
|
describe("telemetry-context", () => {
|
|
4
4
|
describe("isTelemetryNested", () => {
|
|
5
5
|
it("returns false outside any context", () => {
|
|
@@ -69,6 +69,68 @@ describe("telemetry-context", () => {
|
|
|
69
69
|
expect(task2Result?.nested).toBe(false);
|
|
70
70
|
});
|
|
71
71
|
});
|
|
72
|
+
describe("setMethodMetadata / getMethodMetadata", () => {
|
|
73
|
+
it("round-trips metadata within ALS context", () => {
|
|
74
|
+
runWithTelemetryContext(() => {
|
|
75
|
+
setMethodMetadata({
|
|
76
|
+
selectedApi: "SlackCLIAPI@1.0.0",
|
|
77
|
+
operationType: "write",
|
|
78
|
+
operationKey: "send_message",
|
|
79
|
+
});
|
|
80
|
+
const metadata = getMethodMetadata();
|
|
81
|
+
expect(metadata).toEqual({
|
|
82
|
+
selectedApi: "SlackCLIAPI@1.0.0",
|
|
83
|
+
operationType: "write",
|
|
84
|
+
operationKey: "send_message",
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
it("returns undefined outside any ALS context", () => {
|
|
89
|
+
expect(getMethodMetadata()).toBeUndefined();
|
|
90
|
+
});
|
|
91
|
+
it("is isolated between different runWithTelemetryContext scopes", () => {
|
|
92
|
+
runWithTelemetryContext(() => {
|
|
93
|
+
setMethodMetadata({ selectedApi: "parent" });
|
|
94
|
+
runWithTelemetryContext(() => {
|
|
95
|
+
setMethodMetadata({ selectedApi: "child" });
|
|
96
|
+
expect(getMethodMetadata()?.selectedApi).toBe("child");
|
|
97
|
+
});
|
|
98
|
+
expect(getMethodMetadata()?.selectedApi).toBe("parent");
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
it("merges partial metadata updates", () => {
|
|
102
|
+
runWithTelemetryContext(() => {
|
|
103
|
+
setMethodMetadata({ selectedApi: "SlackCLIAPI@1.0.0" });
|
|
104
|
+
setMethodMetadata({ operationType: "write" });
|
|
105
|
+
const metadata = getMethodMetadata();
|
|
106
|
+
expect(metadata).toEqual({
|
|
107
|
+
selectedApi: "SlackCLIAPI@1.0.0",
|
|
108
|
+
operationType: "write",
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
it("is readable in .then() handler within same ALS scope (paginated pattern)", async () => {
|
|
113
|
+
await runWithTelemetryContext(async () => {
|
|
114
|
+
setMethodMetadata({
|
|
115
|
+
selectedApi: "SlackCLIAPI@1.0.0",
|
|
116
|
+
operationType: "write",
|
|
117
|
+
operationKey: "send_message",
|
|
118
|
+
});
|
|
119
|
+
const result = await Promise.resolve("done").then(() => {
|
|
120
|
+
return getMethodMetadata();
|
|
121
|
+
});
|
|
122
|
+
expect(result).toEqual({
|
|
123
|
+
selectedApi: "SlackCLIAPI@1.0.0",
|
|
124
|
+
operationType: "write",
|
|
125
|
+
operationKey: "send_message",
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
it("is a no-op outside ALS context", () => {
|
|
130
|
+
setMethodMetadata({ selectedApi: "test" });
|
|
131
|
+
expect(getMethodMetadata()).toBeUndefined();
|
|
132
|
+
});
|
|
133
|
+
});
|
|
72
134
|
describe("runWithTelemetryContext", () => {
|
|
73
135
|
it("returns the value from the wrapped function", () => {
|
|
74
136
|
const result = runWithTelemetryContext(() => 42);
|
|
@@ -1 +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;
|
|
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;AAGrE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,wBAAgB,uBAAuB,CACrC,gBAAgB,EAAE,oBAAoB,CAAC,eAAe,CAAC,CAAC,kBAAkB,CAAC,EAC3E,UAAU,EAAE,MAAM,GACjB,kBAAkB,CAkBpB"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getMethodMetadata } from "./telemetry-context";
|
|
1
2
|
/**
|
|
2
3
|
* Creates a standardized telemetry callback for SDK method invocations.
|
|
3
4
|
*
|
|
@@ -41,6 +42,7 @@
|
|
|
41
42
|
export function createTelemetryCallback(emitMethodCalled, methodName) {
|
|
42
43
|
return {
|
|
43
44
|
onMethodCalled: (data) => {
|
|
45
|
+
const metadata = getMethodMetadata();
|
|
44
46
|
emitMethodCalled({
|
|
45
47
|
method_name: methodName,
|
|
46
48
|
execution_duration_ms: data.durationMs,
|
|
@@ -49,6 +51,9 @@ export function createTelemetryCallback(emitMethodCalled, methodName) {
|
|
|
49
51
|
error_type: data.error?.constructor.name ?? null,
|
|
50
52
|
argument_count: data.argumentCount,
|
|
51
53
|
is_paginated: data.isPaginated,
|
|
54
|
+
selected_api: metadata?.selectedApi ?? null,
|
|
55
|
+
operation_type: metadata?.operationType ?? null,
|
|
56
|
+
operation_key: metadata?.operationKey ?? null,
|
|
52
57
|
});
|
|
53
58
|
},
|
|
54
59
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { describe, it, expect, vi } from "vitest";
|
|
2
2
|
import { createTelemetryCallback } from "./telemetry-utils";
|
|
3
|
+
import { runWithTelemetryContext, setMethodMetadata, } from "./telemetry-context";
|
|
3
4
|
describe("createTelemetryCallback", () => {
|
|
4
5
|
it("should create callback that emits telemetry with explicit method name", () => {
|
|
5
6
|
const mockEmit = vi.fn();
|
|
@@ -19,6 +20,9 @@ describe("createTelemetryCallback", () => {
|
|
|
19
20
|
error_type: null,
|
|
20
21
|
argument_count: 2,
|
|
21
22
|
is_paginated: false,
|
|
23
|
+
selected_api: null,
|
|
24
|
+
operation_type: null,
|
|
25
|
+
operation_key: null,
|
|
22
26
|
});
|
|
23
27
|
});
|
|
24
28
|
it("should include error details when method fails", () => {
|
|
@@ -41,6 +45,9 @@ describe("createTelemetryCallback", () => {
|
|
|
41
45
|
error_type: "Error",
|
|
42
46
|
argument_count: 1,
|
|
43
47
|
is_paginated: false,
|
|
48
|
+
selected_api: null,
|
|
49
|
+
operation_type: null,
|
|
50
|
+
operation_key: null,
|
|
44
51
|
});
|
|
45
52
|
});
|
|
46
53
|
it("should handle paginated method calls", () => {
|
|
@@ -61,6 +68,9 @@ describe("createTelemetryCallback", () => {
|
|
|
61
68
|
error_type: null,
|
|
62
69
|
argument_count: 1,
|
|
63
70
|
is_paginated: true,
|
|
71
|
+
selected_api: null,
|
|
72
|
+
operation_type: null,
|
|
73
|
+
operation_key: null,
|
|
64
74
|
});
|
|
65
75
|
});
|
|
66
76
|
it("should handle custom error types", () => {
|
|
@@ -89,6 +99,57 @@ describe("createTelemetryCallback", () => {
|
|
|
89
99
|
error_type: "CustomError",
|
|
90
100
|
argument_count: 3,
|
|
91
101
|
is_paginated: false,
|
|
102
|
+
selected_api: null,
|
|
103
|
+
operation_type: null,
|
|
104
|
+
operation_key: null,
|
|
92
105
|
});
|
|
93
106
|
});
|
|
107
|
+
it("should include ALS metadata when set", () => {
|
|
108
|
+
const mockEmit = vi.fn();
|
|
109
|
+
const callback = createTelemetryCallback(mockEmit, "runAction");
|
|
110
|
+
runWithTelemetryContext(() => {
|
|
111
|
+
setMethodMetadata({
|
|
112
|
+
selectedApi: "SlackCLIAPI@1.0.0",
|
|
113
|
+
operationType: "write",
|
|
114
|
+
operationKey: "send_message",
|
|
115
|
+
});
|
|
116
|
+
callback.onMethodCalled({
|
|
117
|
+
methodName: "ignoredName",
|
|
118
|
+
durationMs: 100,
|
|
119
|
+
success: true,
|
|
120
|
+
argumentCount: 1,
|
|
121
|
+
isPaginated: false,
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
expect(mockEmit).toHaveBeenCalledWith({
|
|
125
|
+
method_name: "runAction",
|
|
126
|
+
execution_duration_ms: 100,
|
|
127
|
+
success_flag: true,
|
|
128
|
+
error_message: null,
|
|
129
|
+
error_type: null,
|
|
130
|
+
argument_count: 1,
|
|
131
|
+
is_paginated: false,
|
|
132
|
+
selected_api: "SlackCLIAPI@1.0.0",
|
|
133
|
+
operation_type: "write",
|
|
134
|
+
operation_key: "send_message",
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
it("should default metadata fields to null when no ALS metadata is set", () => {
|
|
138
|
+
const mockEmit = vi.fn();
|
|
139
|
+
const callback = createTelemetryCallback(mockEmit, "listApps");
|
|
140
|
+
runWithTelemetryContext(() => {
|
|
141
|
+
callback.onMethodCalled({
|
|
142
|
+
methodName: "ignoredName",
|
|
143
|
+
durationMs: 50,
|
|
144
|
+
success: true,
|
|
145
|
+
argumentCount: 0,
|
|
146
|
+
isPaginated: false,
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
expect(mockEmit).toHaveBeenCalledWith(expect.objectContaining({
|
|
150
|
+
selected_api: null,
|
|
151
|
+
operation_type: null,
|
|
152
|
+
operation_key: null,
|
|
153
|
+
}));
|
|
154
|
+
});
|
|
94
155
|
});
|