@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
|
@@ -4,10 +4,11 @@
|
|
|
4
4
|
* Provides builder functions that auto-populate common fields and ensure
|
|
5
5
|
* schema compliance for all event types.
|
|
6
6
|
*/
|
|
7
|
-
import type { ErrorOccurredEvent, ApplicationLifecycleEvent, BaseEvent } from "../../types/telemetry-events";
|
|
8
|
-
import type { ApplicationLifecycleEventData, EnhancedErrorEventData, ErrorEventData, EventContext } from "./types";
|
|
7
|
+
import type { ErrorOccurredEvent, ApplicationLifecycleEvent, BaseEvent, MethodCalledEvent } from "../../types/telemetry-events";
|
|
8
|
+
import type { ApplicationLifecycleEventData, EnhancedErrorEventData, ErrorEventData, EventContext, MethodCalledEventData } from "./types";
|
|
9
9
|
export declare function createBaseEvent(context?: EventContext): BaseEvent;
|
|
10
10
|
export declare function buildErrorEvent(data: ErrorEventData, context?: EventContext): ErrorOccurredEvent;
|
|
11
11
|
export declare function buildApplicationLifecycleEvent(data: ApplicationLifecycleEventData, context?: EventContext): ApplicationLifecycleEvent;
|
|
12
12
|
export declare function buildErrorEventWithContext(data: EnhancedErrorEventData, context?: EventContext): ErrorOccurredEvent;
|
|
13
|
+
export declare function buildMethodCalledEvent(data: MethodCalledEventData, context?: EventContext): MethodCalledEvent;
|
|
13
14
|
//# sourceMappingURL=builders.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"builders.d.ts","sourceRoot":"","sources":["../../../src/plugins/eventEmission/builders.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EACV,kBAAkB,EAClB,yBAAyB,EACzB,SAAS,
|
|
1
|
+
{"version":3,"file":"builders.d.ts","sourceRoot":"","sources":["../../../src/plugins/eventEmission/builders.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EACV,kBAAkB,EAClB,yBAAyB,EACzB,SAAS,EACT,iBAAiB,EAClB,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EACV,6BAA6B,EAC7B,sBAAsB,EACtB,cAAc,EACd,YAAY,EACZ,qBAAqB,EACtB,MAAM,SAAS,CAAC;AAgBjB,wBAAgB,eAAe,CAAC,OAAO,GAAE,YAAiB,GAAG,SAAS,CAWrE;AAED,wBAAgB,eAAe,CAC7B,IAAI,EAAE,cAAc,EACpB,OAAO,GAAE,YAAiB,GACzB,kBAAkB,CAYpB;AAED,wBAAgB,8BAA8B,CAC5C,IAAI,EAAE,6BAA6B,EACnC,OAAO,GAAE,YAAiB,GACzB,yBAAyB,CAyB3B;AAED,wBAAgB,0BAA0B,CACxC,IAAI,EAAE,sBAAsB,EAC5B,OAAO,GAAE,YAAiB,GACzB,kBAAkB,CAiBpB;AAED,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,qBAAqB,EAC3B,OAAO,GAAE,YAAiB,GACzB,iBAAiB,CA+BnB"}
|
|
@@ -75,3 +75,35 @@ export function buildErrorEventWithContext(data, context = {}) {
|
|
|
75
75
|
...data,
|
|
76
76
|
};
|
|
77
77
|
}
|
|
78
|
+
export function buildMethodCalledEvent(data, context = {}) {
|
|
79
|
+
return {
|
|
80
|
+
...createBaseEvent(context),
|
|
81
|
+
method_name: data.method_name ?? null,
|
|
82
|
+
method_module: data.method_module ?? null,
|
|
83
|
+
execution_duration_ms: data.execution_duration_ms,
|
|
84
|
+
success_flag: data.success_flag,
|
|
85
|
+
error_message: data.error_message ?? null,
|
|
86
|
+
error_type: data.error_type ?? null,
|
|
87
|
+
argument_count: data.argument_count,
|
|
88
|
+
is_paginated: data.is_paginated ?? false,
|
|
89
|
+
sdk_version: sdkPackageJson.version,
|
|
90
|
+
environment: context.environment ?? (process?.env?.NODE_ENV || null),
|
|
91
|
+
selected_api: context.selected_api ?? null,
|
|
92
|
+
app_id: context.app_id ?? null,
|
|
93
|
+
app_version_id: context.app_version_id ?? null,
|
|
94
|
+
zap_id: context.zap_id ?? null,
|
|
95
|
+
node_id: context.node_id ?? null,
|
|
96
|
+
operation_type: null,
|
|
97
|
+
operation_key: null,
|
|
98
|
+
call_context: null,
|
|
99
|
+
is_retry: false,
|
|
100
|
+
retry_attempt: null,
|
|
101
|
+
argument_types: null,
|
|
102
|
+
return_type: null,
|
|
103
|
+
caller_method: null,
|
|
104
|
+
call_stack_depth: null,
|
|
105
|
+
is_synchronous: false,
|
|
106
|
+
cpu_time_ms: null,
|
|
107
|
+
memory_usage_bytes: null,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
import type { Plugin } from "../../types/plugin";
|
|
8
8
|
import type { BaseEvent } from "../../types/telemetry-events";
|
|
9
9
|
import type { EventTransport, TransportConfig } from "./transport";
|
|
10
|
+
import type { MethodCalledEventData } from "./types";
|
|
10
11
|
export interface EventEmissionConfig {
|
|
11
12
|
enabled?: boolean;
|
|
12
13
|
transport?: TransportConfig;
|
|
@@ -17,6 +18,7 @@ export interface EventEmissionContext {
|
|
|
17
18
|
config: EventEmissionConfig;
|
|
18
19
|
emit<T extends any>(subject: string, event: T): void;
|
|
19
20
|
createBaseEvent(): Promise<BaseEvent>;
|
|
21
|
+
emitMethodCalled(data: MethodCalledEventData): void;
|
|
20
22
|
};
|
|
21
23
|
}
|
|
22
24
|
export interface EventEmissionProvides {
|
|
@@ -29,8 +31,8 @@ export declare const eventEmissionPlugin: Plugin<{}, {
|
|
|
29
31
|
baseUrl?: string;
|
|
30
32
|
};
|
|
31
33
|
}, EventEmissionProvides>;
|
|
32
|
-
export type { EventContext, ApplicationLifecycleEventData, EnhancedErrorEventData, } from "./types";
|
|
33
|
-
export { buildApplicationLifecycleEvent, buildErrorEventWithContext, buildErrorEvent, createBaseEvent, } from "./builders";
|
|
34
|
+
export type { EventContext, ApplicationLifecycleEventData, EnhancedErrorEventData, MethodCalledEventData, } from "./types";
|
|
35
|
+
export { buildApplicationLifecycleEvent, buildErrorEventWithContext, buildErrorEvent, createBaseEvent, buildMethodCalledEvent, } from "./builders";
|
|
34
36
|
export type { BaseEvent } from "../../types/telemetry-events";
|
|
35
37
|
export * from "./utils";
|
|
36
38
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/eventEmission/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/eventEmission/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAWnE,OAAO,KAAK,EAAgB,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAMnE,MAAM,WAAW,mBAAmB;IAClC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,SAAS,CAAC,EAAE,eAAe,CAAC;CAC7B;AAGD,MAAM,WAAW,oBAAoB;IACnC,aAAa,EAAE;QACb,SAAS,EAAE,cAAc,CAAC;QAC1B,MAAM,EAAE,mBAAmB,CAAC;QAE5B,IAAI,CAAC,CAAC,SAAS,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI,CAAC;QAErD,eAAe,IAAI,OAAO,CAAC,SAAS,CAAC,CAAC;QAEtC,gBAAgB,CAAC,IAAI,EAAE,qBAAqB,GAAG,IAAI,CAAC;KACrD,CAAC;CACH;AAED,MAAM,WAAW,qBAAqB;IACpC,OAAO,EAAE,oBAAoB,CAAC;CAC/B;AA6FD,eAAO,MAAM,mBAAmB,EAAE,MAAM,CACtC,EAAE,EACF;IACE,OAAO,EAAE;QACP,aAAa,CAAC,EAAE,mBAAmB,CAAC;QACpC,eAAe,CAAC,EAAE,MAAM,CAAC;QACzB,OAAO,CAAC,EAAE,MAAM,CAAC;KAClB,CAAC;CACH,EACD,qBAAqB,CAuRtB,CAAC;AAGF,YAAY,EACV,YAAY,EACZ,6BAA6B,EAC7B,sBAAsB,EACtB,qBAAqB,GACtB,MAAM,SAAS,CAAC;AACjB,OAAO,EACL,8BAA8B,EAC9B,0BAA0B,EAC1B,eAAe,EACf,eAAe,EACf,sBAAsB,GACvB,MAAM,YAAY,CAAC;AACpB,YAAY,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAC9D,cAAc,SAAS,CAAC"}
|
|
@@ -8,12 +8,13 @@ import { createTransport } from "./transport";
|
|
|
8
8
|
import { generateEventId, getCurrentTimestamp, getReleaseId } from "./utils";
|
|
9
9
|
import { extractUserIdsFromJwt } from "../../api/auth";
|
|
10
10
|
import { resolveAuthToken } from "../../auth";
|
|
11
|
-
import { buildApplicationLifecycleEvent, buildErrorEventWithContext, } from "./builders";
|
|
11
|
+
import { buildApplicationLifecycleEvent, buildErrorEventWithContext, buildMethodCalledEvent, } from "./builders";
|
|
12
12
|
import { getTrackingBaseUrl } from "../../utils/url-utils";
|
|
13
13
|
// Maximum time to wait for telemetry emission before allowing process to exit
|
|
14
14
|
const TELEMETRY_EMIT_TIMEOUT_MS = 300;
|
|
15
15
|
const APPLICATION_LIFECYCLE_EVENT_SUBJECT = "platform.sdk.ApplicationLifecycleEvent";
|
|
16
16
|
const ERROR_OCCURRED_EVENT_SUBJECT = "platform.sdk.ErrorOccurredEvent";
|
|
17
|
+
const METHOD_CALLED_EVENT_SUBJECT = "platform.sdk.MethodCalledEvent";
|
|
17
18
|
// Track transport success/failure so we only log failure once.
|
|
18
19
|
const transportStates = new WeakMap();
|
|
19
20
|
// Silent emission wrapper with smart first-failure logging
|
|
@@ -133,6 +134,7 @@ export const eventEmissionPlugin = ({ context }) => {
|
|
|
133
134
|
visitor_id: null,
|
|
134
135
|
correlation_id: null,
|
|
135
136
|
}),
|
|
137
|
+
emitMethodCalled: () => { },
|
|
136
138
|
},
|
|
137
139
|
},
|
|
138
140
|
};
|
|
@@ -306,9 +308,13 @@ export const eventEmissionPlugin = ({ context }) => {
|
|
|
306
308
|
silentEmit(transport, subject, event, getUserContext);
|
|
307
309
|
},
|
|
308
310
|
createBaseEvent: createBaseEventHelper,
|
|
311
|
+
emitMethodCalled: (data) => {
|
|
312
|
+
const event = buildMethodCalledEvent(data);
|
|
313
|
+
silentEmit(transport, METHOD_CALLED_EVENT_SUBJECT, event, getUserContext);
|
|
314
|
+
},
|
|
309
315
|
},
|
|
310
316
|
},
|
|
311
317
|
};
|
|
312
318
|
};
|
|
313
|
-
export { buildApplicationLifecycleEvent, buildErrorEventWithContext, buildErrorEvent, createBaseEvent, } from "./builders";
|
|
319
|
+
export { buildApplicationLifecycleEvent, buildErrorEventWithContext, buildErrorEvent, createBaseEvent, buildMethodCalledEvent, } from "./builders";
|
|
314
320
|
export * from "./utils";
|
|
@@ -50,4 +50,14 @@ export interface ApplicationLifecycleEventData {
|
|
|
50
50
|
cpu_time_ms?: number | null;
|
|
51
51
|
active_requests_count?: number | null;
|
|
52
52
|
}
|
|
53
|
+
export interface MethodCalledEventData {
|
|
54
|
+
method_name: string;
|
|
55
|
+
method_module?: string | null;
|
|
56
|
+
execution_duration_ms: number;
|
|
57
|
+
success_flag: boolean;
|
|
58
|
+
error_message?: string | null;
|
|
59
|
+
error_type?: string | null;
|
|
60
|
+
argument_count: number;
|
|
61
|
+
is_paginated?: boolean;
|
|
62
|
+
}
|
|
53
63
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/plugins/eventEmission/types.ts"],"names":[],"mappings":"AACA,MAAM,WAAW,YAAY;IAC3B,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,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,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Plugin, GetSdkType } from "../../types/plugin";
|
|
2
2
|
import type { RequestPluginProvides } from "../request";
|
|
3
3
|
import type { z } from "zod";
|
|
4
|
+
import type { EventEmissionContext } from "../eventEmission";
|
|
4
5
|
export interface FetchPluginProvides {
|
|
5
6
|
fetch: (url: string | URL, init?: RequestInit & {
|
|
6
7
|
authenticationId?: number;
|
|
@@ -25,7 +26,7 @@ export interface FetchPluginProvides {
|
|
|
25
26
|
* Direct plugin function - takes options + sdk + context in one object
|
|
26
27
|
*/
|
|
27
28
|
export declare const fetchPlugin: Plugin<GetSdkType<RequestPluginProvides>, // requires request in SDK
|
|
28
|
-
|
|
29
|
+
EventEmissionContext, // requires eventEmission context for telemetry
|
|
29
30
|
FetchPluginProvides>;
|
|
30
31
|
export type ZapierFetchInitOptions = RequestInit & {
|
|
31
32
|
authenticationId?: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/fetch/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAExD,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/fetch/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAExD,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAC7B,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAE7D,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,CACL,GAAG,EAAE,MAAM,GAAG,GAAG,EACjB,IAAI,CAAC,EAAE,WAAW,GAAG;QACnB,gBAAgB,CAAC,EAAE,MAAM,CAAC;QAC1B,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,sBAAsB,CAAC,EAAE,MAAM,CAAC;KACjC,KACE,OAAO,CAAC,QAAQ,CAAC,CAAC;IACvB,OAAO,EAAE;QACP,IAAI,EAAE;YACJ,KAAK,EAAE;gBACL,QAAQ,EAAE,MAAM,EAAE,CAAC;gBACnB,UAAU,EAAE,MAAM,EAAE,CAAC;gBACrB,UAAU,EAAE,MAAM,CAAC;gBACnB,eAAe,EAAE,KAAK,CAAC;oBAAE,IAAI,EAAE,MAAM,CAAC;oBAAC,MAAM,EAAE,CAAC,CAAC,SAAS,CAAA;iBAAE,CAAC,CAAC;aAC/D,CAAC;SACH,CAAC;KACH,CAAC;CACH;AAED;;GAEG;AACH,eAAO,MAAM,WAAW,EAAE,MAAM,CAC9B,UAAU,CAAC,qBAAqB,CAAC,EAAE,0BAA0B;AAC7D,oBAAoB,EAAE,+CAA+C;AACrE,mBAAmB,CA2EpB,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG,WAAW,GAAG;IACjD,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,sBAAsB,CAAC,EAAE,MAAM,CAAC;CACjC,CAAC"}
|
|
@@ -2,20 +2,48 @@ import { FetchUrlSchema, FetchInitSchema } from "./schemas";
|
|
|
2
2
|
/**
|
|
3
3
|
* Direct plugin function - takes options + sdk + context in one object
|
|
4
4
|
*/
|
|
5
|
-
export const fetchPlugin = ({ sdk }) => {
|
|
5
|
+
export const fetchPlugin = ({ sdk, context }) => {
|
|
6
6
|
// Return flat structure - fetch goes directly to SDK
|
|
7
7
|
return {
|
|
8
8
|
fetch: async function fetch(url, init) {
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
9
|
+
const startTime = Date.now();
|
|
10
|
+
try {
|
|
11
|
+
const { authenticationId, callbackUrl, authenticationTemplate, ...fetchInit } = init || {};
|
|
12
|
+
const result = await sdk.request({
|
|
13
|
+
url: url.toString(),
|
|
14
|
+
method: fetchInit.method,
|
|
15
|
+
body: fetchInit.body,
|
|
16
|
+
headers: fetchInit.headers,
|
|
17
|
+
authenticationId,
|
|
18
|
+
callbackUrl,
|
|
19
|
+
authenticationTemplate,
|
|
20
|
+
_telemetry: { isNested: true },
|
|
21
|
+
});
|
|
22
|
+
// Emit success telemetry
|
|
23
|
+
context.eventEmission.emitMethodCalled({
|
|
24
|
+
method_name: "fetch",
|
|
25
|
+
execution_duration_ms: Date.now() - startTime,
|
|
26
|
+
success_flag: true,
|
|
27
|
+
error_message: null,
|
|
28
|
+
error_type: null,
|
|
29
|
+
argument_count: init ? 2 : 1,
|
|
30
|
+
is_paginated: false,
|
|
31
|
+
});
|
|
32
|
+
return result;
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
// Emit failure telemetry
|
|
36
|
+
context.eventEmission.emitMethodCalled({
|
|
37
|
+
method_name: "fetch",
|
|
38
|
+
execution_duration_ms: Date.now() - startTime,
|
|
39
|
+
success_flag: false,
|
|
40
|
+
error_message: error instanceof Error ? error.message : String(error),
|
|
41
|
+
error_type: error instanceof Error ? error.constructor.name : "Unknown",
|
|
42
|
+
argument_count: init ? 2 : 1,
|
|
43
|
+
is_paginated: false,
|
|
44
|
+
});
|
|
45
|
+
throw error;
|
|
46
|
+
}
|
|
19
47
|
},
|
|
20
48
|
context: {
|
|
21
49
|
meta: {
|
|
@@ -2,6 +2,7 @@ import type { Plugin, GetSdkType } from "../../types/plugin";
|
|
|
2
2
|
import type { AuthenticationItem } from "../../types/domain";
|
|
3
3
|
import { FindFirstAuthenticationSchema, type FindFirstAuthenticationOptions } from "./schemas";
|
|
4
4
|
import type { ListAuthenticationsPluginProvides } from "../listAuthentications";
|
|
5
|
+
import type { EventEmissionContext } from "../eventEmission";
|
|
5
6
|
export interface FindFirstAuthenticationPluginProvides {
|
|
6
7
|
findFirstAuthentication: (options?: FindFirstAuthenticationOptions) => Promise<{
|
|
7
8
|
data: AuthenticationItem;
|
|
@@ -15,6 +16,6 @@ export interface FindFirstAuthenticationPluginProvides {
|
|
|
15
16
|
};
|
|
16
17
|
}
|
|
17
18
|
export declare const findFirstAuthenticationPlugin: Plugin<GetSdkType<ListAuthenticationsPluginProvides>, // requires listAuthentications in SDK
|
|
18
|
-
|
|
19
|
+
EventEmissionContext, // requires eventEmission in context
|
|
19
20
|
FindFirstAuthenticationPluginProvides>;
|
|
20
21
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/findFirstAuthentication/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,EACL,6BAA6B,EAC7B,KAAK,8BAA8B,EACpC,MAAM,WAAW,CAAC;AAEnB,OAAO,KAAK,EAAE,iCAAiC,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/findFirstAuthentication/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,EACL,6BAA6B,EAC7B,KAAK,8BAA8B,EACpC,MAAM,WAAW,CAAC;AAEnB,OAAO,KAAK,EAAE,iCAAiC,EAAE,MAAM,wBAAwB,CAAC;AAGhF,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAG7D,MAAM,WAAW,qCAAqC;IACpD,uBAAuB,EAAE,CACvB,OAAO,CAAC,EAAE,8BAA8B,KACrC,OAAO,CAAC;QAAE,IAAI,EAAE,kBAAkB,CAAA;KAAE,CAAC,CAAC;IAC3C,OAAO,EAAE;QACP,IAAI,EAAE;YACJ,uBAAuB,EAAE;gBACvB,WAAW,EAAE,OAAO,6BAA6B,CAAC;aACnD,CAAC;SACH,CAAC;KACH,CAAC;CACH;AAED,eAAO,MAAM,6BAA6B,EAAE,MAAM,CAChD,UAAU,CAAC,iCAAiC,CAAC,EAAE,sCAAsC;AACrF,oBAAoB,EAAE,oCAAoC;AAC1D,qCAAqC,CA+CtC,CAAC"}
|
|
@@ -2,12 +2,14 @@ import { FindFirstAuthenticationSchema, } from "./schemas";
|
|
|
2
2
|
import { createFunction } from "../../utils/function-utils";
|
|
3
3
|
import { AuthenticationItemSchema } from "../../schemas/Auth";
|
|
4
4
|
import { ZapierResourceNotFoundError } from "../../types/errors";
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
import { createTelemetryCallback } from "../../utils/telemetry-utils";
|
|
6
|
+
export const findFirstAuthenticationPlugin = ({ sdk, context }) => {
|
|
7
|
+
async function findFirstAuthentication(options = {}) {
|
|
7
8
|
// Use listAuthentications with maxItems 1 to get the first result
|
|
8
9
|
const authsResponse = await sdk.listAuthentications({
|
|
9
10
|
...options,
|
|
10
11
|
maxItems: 1,
|
|
12
|
+
_telemetry: { isNested: true },
|
|
11
13
|
});
|
|
12
14
|
if (authsResponse.data.length === 0) {
|
|
13
15
|
throw new ZapierResourceNotFoundError("No authentication found matching the specified criteria", { resourceType: "Authentication" });
|
|
@@ -15,9 +17,10 @@ export const findFirstAuthenticationPlugin = ({ sdk }) => {
|
|
|
15
17
|
return {
|
|
16
18
|
data: authsResponse.data[0],
|
|
17
19
|
};
|
|
18
|
-
}
|
|
20
|
+
}
|
|
21
|
+
const findFirstAuthenticationDefinition = createFunction(findFirstAuthentication, FindFirstAuthenticationSchema, createTelemetryCallback(context.eventEmission.emitMethodCalled, findFirstAuthentication.name));
|
|
19
22
|
return {
|
|
20
|
-
findFirstAuthentication,
|
|
23
|
+
findFirstAuthentication: findFirstAuthenticationDefinition,
|
|
21
24
|
context: {
|
|
22
25
|
meta: {
|
|
23
26
|
findFirstAuthentication: {
|
|
@@ -3,6 +3,7 @@ import { ZapierValidationError } from "../../types/errors";
|
|
|
3
3
|
import { findFirstAuthenticationPlugin } from "./index";
|
|
4
4
|
import { createSdk } from "../../sdk";
|
|
5
5
|
import { ListAuthenticationsSchema } from "../listAuthentications/schemas";
|
|
6
|
+
import { eventEmissionPlugin } from "../eventEmission";
|
|
6
7
|
const mockAuthentications = [
|
|
7
8
|
{
|
|
8
9
|
id: 123,
|
|
@@ -51,6 +52,12 @@ describe("findFirstAuthentication plugin", () => {
|
|
|
51
52
|
});
|
|
52
53
|
// Build SDK with proper plugin composition
|
|
53
54
|
return createSdk()
|
|
55
|
+
.addPlugin(() => ({
|
|
56
|
+
context: {
|
|
57
|
+
options: {},
|
|
58
|
+
},
|
|
59
|
+
}))
|
|
60
|
+
.addPlugin(eventEmissionPlugin)
|
|
54
61
|
.addPlugin(mockListAuthenticationsPlugin)
|
|
55
62
|
.addPlugin(findFirstAuthenticationPlugin);
|
|
56
63
|
}
|
|
@@ -141,10 +148,10 @@ describe("findFirstAuthentication plugin", () => {
|
|
|
141
148
|
owner: "me",
|
|
142
149
|
};
|
|
143
150
|
await sdk.findFirstAuthentication(options);
|
|
144
|
-
expect(mockListAuthentications).toHaveBeenCalledWith({
|
|
151
|
+
expect(mockListAuthentications).toHaveBeenCalledWith(expect.objectContaining({
|
|
145
152
|
...options,
|
|
146
153
|
maxItems: 1,
|
|
147
|
-
});
|
|
154
|
+
}));
|
|
148
155
|
});
|
|
149
156
|
});
|
|
150
157
|
describe("limit enforcement", () => {
|
|
@@ -153,10 +160,10 @@ describe("findFirstAuthentication plugin", () => {
|
|
|
153
160
|
await sdk.findFirstAuthentication({
|
|
154
161
|
appKey: "slack",
|
|
155
162
|
});
|
|
156
|
-
expect(mockListAuthentications).toHaveBeenCalledWith({
|
|
163
|
+
expect(mockListAuthentications).toHaveBeenCalledWith(expect.objectContaining({
|
|
157
164
|
appKey: "slack",
|
|
158
165
|
maxItems: 1,
|
|
159
|
-
});
|
|
166
|
+
}));
|
|
160
167
|
});
|
|
161
168
|
});
|
|
162
169
|
describe("context and metadata", () => {
|
|
@@ -2,6 +2,7 @@ import type { Plugin, GetSdkType } from "../../types/plugin";
|
|
|
2
2
|
import type { AuthenticationItem } from "../../types/domain";
|
|
3
3
|
import { FindUniqueAuthenticationSchema, type FindUniqueAuthenticationOptions } from "./schemas";
|
|
4
4
|
import type { ListAuthenticationsPluginProvides } from "../listAuthentications";
|
|
5
|
+
import type { EventEmissionContext } from "../eventEmission";
|
|
5
6
|
export interface FindUniqueAuthenticationPluginProvides {
|
|
6
7
|
findUniqueAuthentication: (options?: FindUniqueAuthenticationOptions) => Promise<{
|
|
7
8
|
data: AuthenticationItem;
|
|
@@ -15,6 +16,6 @@ export interface FindUniqueAuthenticationPluginProvides {
|
|
|
15
16
|
};
|
|
16
17
|
}
|
|
17
18
|
export declare const findUniqueAuthenticationPlugin: Plugin<GetSdkType<ListAuthenticationsPluginProvides>, // requires listAuthentications in SDK
|
|
18
|
-
|
|
19
|
+
EventEmissionContext, // requires eventEmission in context
|
|
19
20
|
FindUniqueAuthenticationPluginProvides>;
|
|
20
21
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/findUniqueAuthentication/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,EACL,8BAA8B,EAC9B,KAAK,+BAA+B,EACrC,MAAM,WAAW,CAAC;AAMnB,OAAO,KAAK,EAAE,iCAAiC,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/findUniqueAuthentication/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,EACL,8BAA8B,EAC9B,KAAK,+BAA+B,EACrC,MAAM,WAAW,CAAC;AAMnB,OAAO,KAAK,EAAE,iCAAiC,EAAE,MAAM,wBAAwB,CAAC;AAEhF,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAG7D,MAAM,WAAW,sCAAsC;IACrD,wBAAwB,EAAE,CACxB,OAAO,CAAC,EAAE,+BAA+B,KACtC,OAAO,CAAC;QAAE,IAAI,EAAE,kBAAkB,CAAA;KAAE,CAAC,CAAC;IAC3C,OAAO,EAAE;QACP,IAAI,EAAE;YACJ,wBAAwB,EAAE;gBACxB,WAAW,EAAE,OAAO,8BAA8B,CAAC;aACpD,CAAC;SACH,CAAC;KACH,CAAC;CACH;AAED,eAAO,MAAM,8BAA8B,EAAE,MAAM,CACjD,UAAU,CAAC,iCAAiC,CAAC,EAAE,sCAAsC;AACrF,oBAAoB,EAAE,oCAAoC;AAC1D,sCAAsC,CAqDvC,CAAC"}
|
|
@@ -2,12 +2,14 @@ import { FindUniqueAuthenticationSchema, } from "./schemas";
|
|
|
2
2
|
import { ZapierResourceNotFoundError, ZapierValidationError, } from "../../types/errors";
|
|
3
3
|
import { createFunction } from "../../utils/function-utils";
|
|
4
4
|
import { AuthenticationItemSchema } from "../../schemas/Auth";
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
import { createTelemetryCallback } from "../../utils/telemetry-utils";
|
|
6
|
+
export const findUniqueAuthenticationPlugin = ({ sdk, context }) => {
|
|
7
|
+
async function findUniqueAuthentication(options = {}) {
|
|
7
8
|
// Use listAuthentications with maxItems 2 to check for uniqueness
|
|
8
9
|
const authsResponse = await sdk.listAuthentications({
|
|
9
10
|
...options,
|
|
10
11
|
maxItems: 2, // Get up to 2 to check for uniqueness
|
|
12
|
+
_telemetry: { isNested: true },
|
|
11
13
|
});
|
|
12
14
|
if (authsResponse.data.length === 0) {
|
|
13
15
|
throw new ZapierResourceNotFoundError("No authentication found matching the specified criteria", { resourceType: "Authentication" });
|
|
@@ -18,9 +20,10 @@ export const findUniqueAuthenticationPlugin = ({ sdk }) => {
|
|
|
18
20
|
return {
|
|
19
21
|
data: authsResponse.data[0],
|
|
20
22
|
};
|
|
21
|
-
}
|
|
23
|
+
}
|
|
24
|
+
const findUniqueAuthenticationDefinition = createFunction(findUniqueAuthentication, FindUniqueAuthenticationSchema, createTelemetryCallback(context.eventEmission.emitMethodCalled, findUniqueAuthentication.name));
|
|
22
25
|
return {
|
|
23
|
-
findUniqueAuthentication,
|
|
26
|
+
findUniqueAuthentication: findUniqueAuthenticationDefinition,
|
|
24
27
|
context: {
|
|
25
28
|
meta: {
|
|
26
29
|
findUniqueAuthentication: {
|
|
@@ -3,6 +3,7 @@ import { ZapierValidationError, ZapierResourceNotFoundError, } from "../../types
|
|
|
3
3
|
import { findUniqueAuthenticationPlugin } from "./index";
|
|
4
4
|
import { createSdk } from "../../sdk";
|
|
5
5
|
import { ListAuthenticationsSchema } from "../listAuthentications/schemas";
|
|
6
|
+
import { eventEmissionPlugin } from "../eventEmission";
|
|
6
7
|
const mockAuthentication = {
|
|
7
8
|
id: 123,
|
|
8
9
|
title: "My Slack",
|
|
@@ -52,6 +53,12 @@ describe("findUniqueAuthentication plugin", () => {
|
|
|
52
53
|
});
|
|
53
54
|
// Build SDK with proper plugin composition
|
|
54
55
|
return createSdk()
|
|
56
|
+
.addPlugin(() => ({
|
|
57
|
+
context: {
|
|
58
|
+
options: {},
|
|
59
|
+
},
|
|
60
|
+
}))
|
|
61
|
+
.addPlugin(eventEmissionPlugin)
|
|
55
62
|
.addPlugin(mockListAuthenticationsPlugin)
|
|
56
63
|
.addPlugin(findUniqueAuthenticationPlugin);
|
|
57
64
|
}
|
|
@@ -135,10 +142,10 @@ describe("findUniqueAuthentication plugin", () => {
|
|
|
135
142
|
owner: "me",
|
|
136
143
|
};
|
|
137
144
|
await sdk.findUniqueAuthentication(options);
|
|
138
|
-
expect(mockListAuthentications).toHaveBeenCalledWith({
|
|
145
|
+
expect(mockListAuthentications).toHaveBeenCalledWith(expect.objectContaining({
|
|
139
146
|
...options,
|
|
140
147
|
maxItems: 2,
|
|
141
|
-
});
|
|
148
|
+
}));
|
|
142
149
|
});
|
|
143
150
|
});
|
|
144
151
|
describe("context and metadata", () => {
|
|
@@ -3,6 +3,7 @@ import type { ApiClient } from "../../api";
|
|
|
3
3
|
import type { ActionItem } from "../../types/domain";
|
|
4
4
|
import { GetActionSchema, type GetActionOptions } from "./schemas";
|
|
5
5
|
import type { ListActionsPluginProvides } from "../listActions";
|
|
6
|
+
import type { EventEmissionContext } from "../eventEmission";
|
|
6
7
|
export interface GetActionPluginProvides {
|
|
7
8
|
getAction: (options: GetActionOptions) => Promise<{
|
|
8
9
|
data: ActionItem;
|
|
@@ -16,8 +17,9 @@ export interface GetActionPluginProvides {
|
|
|
16
17
|
};
|
|
17
18
|
}
|
|
18
19
|
export declare const getActionPlugin: Plugin<GetSdkType<ListActionsPluginProvides>, // requires listActions in SDK
|
|
20
|
+
// requires listActions in SDK
|
|
19
21
|
{
|
|
20
22
|
api: ApiClient;
|
|
21
|
-
}, // requires api in context
|
|
23
|
+
} & EventEmissionContext, // requires api in context
|
|
22
24
|
GetActionPluginProvides>;
|
|
23
25
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/getAction/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,KAAK,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAGnE,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/getAction/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,KAAK,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAGnE,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAC;AAOhE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAG7D,MAAM,WAAW,uBAAuB;IACtC,SAAS,EAAE,CAAC,OAAO,EAAE,gBAAgB,KAAK,OAAO,CAAC;QAAE,IAAI,EAAE,UAAU,CAAA;KAAE,CAAC,CAAC;IACxE,OAAO,EAAE;QACP,IAAI,EAAE;YACJ,SAAS,EAAE;gBACT,WAAW,EAAE,OAAO,eAAe,CAAC;aACrC,CAAC;SACH,CAAC;KACH,CAAC;CACH;AAED,eAAO,MAAM,eAAe,EAAE,MAAM,CAClC,UAAU,CAAC,yBAAyB,CAAC,EAAE,8BAA8B;AACrE,AADuC,8BAA8B;AACrE;IAAE,GAAG,EAAE,SAAS,CAAA;CAAE,GAAG,oBAAoB,EAAE,0BAA0B;AACrE,uBAAuB,CAoDxB,CAAC"}
|
|
@@ -3,11 +3,14 @@ import { ZapierResourceNotFoundError } from "../../types/errors";
|
|
|
3
3
|
import { createFunction } from "../../utils/function-utils";
|
|
4
4
|
import { appKeyResolver, actionTypeResolver, actionKeyResolver, } from "../../resolvers";
|
|
5
5
|
import { ActionItemSchema } from "../../schemas/Action";
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
import { createTelemetryCallback } from "../../utils/telemetry-utils";
|
|
7
|
+
export const getActionPlugin = ({ sdk, context }) => {
|
|
8
|
+
async function getAction(options) {
|
|
8
9
|
const { actionKey, actionType, appKey } = options;
|
|
9
10
|
// Use the listActions function from the SDK to search for the specific action across all pages
|
|
10
|
-
for await (const action of sdk
|
|
11
|
+
for await (const action of sdk
|
|
12
|
+
.listActions({ appKey, _telemetry: { isNested: true } })
|
|
13
|
+
.items()) {
|
|
11
14
|
if ((action.key === actionKey || action.id === actionKey) &&
|
|
12
15
|
action.action_type === actionType) {
|
|
13
16
|
return { data: action };
|
|
@@ -15,9 +18,10 @@ export const getActionPlugin = ({ sdk }) => {
|
|
|
15
18
|
}
|
|
16
19
|
// If we get here, action was not found
|
|
17
20
|
throw new ZapierResourceNotFoundError(`Action not found: ${actionKey} with type ${actionType}`, { resourceType: "Action", resourceId: `${actionKey} (${actionType})` });
|
|
18
|
-
}
|
|
21
|
+
}
|
|
22
|
+
const getActionDefinition = createFunction(getAction, GetActionSchema, createTelemetryCallback(context.eventEmission.emitMethodCalled, getAction.name));
|
|
19
23
|
return {
|
|
20
|
-
getAction,
|
|
24
|
+
getAction: getActionDefinition,
|
|
21
25
|
context: {
|
|
22
26
|
meta: {
|
|
23
27
|
getAction: {
|
|
@@ -3,6 +3,7 @@ import { ZapierValidationError, ZapierResourceNotFoundError, } from "../../types
|
|
|
3
3
|
import { getActionPlugin } from "./index";
|
|
4
4
|
import { createSdk } from "../../sdk";
|
|
5
5
|
import { ListActionsSchema } from "../listActions/schemas";
|
|
6
|
+
import { eventEmissionPlugin } from "../eventEmission";
|
|
6
7
|
const mockActions = [
|
|
7
8
|
{
|
|
8
9
|
type: "action",
|
|
@@ -65,7 +66,8 @@ describe("getAction plugin", () => {
|
|
|
65
66
|
},
|
|
66
67
|
});
|
|
67
68
|
// Build SDK with proper plugin composition, providing API in initial context
|
|
68
|
-
return createSdk({}, {}, { api: mockApiClient, meta: {} })
|
|
69
|
+
return createSdk({}, {}, { api: mockApiClient, meta: {}, options: {} })
|
|
70
|
+
.addPlugin(eventEmissionPlugin)
|
|
69
71
|
.addPlugin(mockListActionsPlugin)
|
|
70
72
|
.addPlugin(getActionPlugin);
|
|
71
73
|
}
|
|
@@ -149,9 +151,9 @@ describe("getAction plugin", () => {
|
|
|
149
151
|
actionType: "search",
|
|
150
152
|
actionKey: "user_by_email",
|
|
151
153
|
});
|
|
152
|
-
expect(mockListActions).toHaveBeenCalledWith({
|
|
154
|
+
expect(mockListActions).toHaveBeenCalledWith(expect.objectContaining({
|
|
153
155
|
appKey: "slack",
|
|
154
|
-
});
|
|
156
|
+
}));
|
|
155
157
|
});
|
|
156
158
|
it("should return the correct action when found", async () => {
|
|
157
159
|
const sdk = createTestSdk();
|
|
@@ -7,14 +7,28 @@ export declare const GetActionSchema: z.ZodObject<{
|
|
|
7
7
|
};
|
|
8
8
|
actionType: z.ZodEnum<["read", "read_bulk", "write", "run", "search", "search_or_write", "search_and_write", "filter"]>;
|
|
9
9
|
actionKey: z.ZodString;
|
|
10
|
+
} & {
|
|
11
|
+
_telemetry: z.ZodOptional<z.ZodObject<{
|
|
12
|
+
isNested: z.ZodOptional<z.ZodBoolean>;
|
|
13
|
+
}, "strip", z.ZodTypeAny, {
|
|
14
|
+
isNested?: boolean | undefined;
|
|
15
|
+
}, {
|
|
16
|
+
isNested?: boolean | undefined;
|
|
17
|
+
}>>;
|
|
10
18
|
}, "strip", z.ZodTypeAny, {
|
|
11
19
|
appKey: string;
|
|
12
20
|
actionKey: string;
|
|
13
21
|
actionType: "search" | "filter" | "read" | "read_bulk" | "run" | "search_and_write" | "search_or_write" | "write";
|
|
22
|
+
_telemetry?: {
|
|
23
|
+
isNested?: boolean | undefined;
|
|
24
|
+
} | undefined;
|
|
14
25
|
}, {
|
|
15
26
|
appKey: string;
|
|
16
27
|
actionKey: string;
|
|
17
28
|
actionType: "search" | "filter" | "read" | "read_bulk" | "run" | "search_and_write" | "search_or_write" | "write";
|
|
29
|
+
_telemetry?: {
|
|
30
|
+
isNested?: boolean | undefined;
|
|
31
|
+
} | undefined;
|
|
18
32
|
}>;
|
|
19
33
|
export type GetActionOptions = z.infer<typeof GetActionSchema>;
|
|
20
34
|
export type GetActionError = ZapierAuthenticationError | ZapierApiError | ZapierAppNotFoundError | ZapierValidationError | ZapierResourceNotFoundError | ZapierUnknownError;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../../src/plugins/getAction/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAMxB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,KAAK,EACV,yBAAyB,EACzB,cAAc,EACd,sBAAsB,EACtB,qBAAqB,EACrB,2BAA2B,EAC3B,kBAAkB,EACnB,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../../src/plugins/getAction/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAMxB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,KAAK,EACV,yBAAyB,EACzB,cAAc,EACd,sBAAsB,EACtB,qBAAqB,EACrB,2BAA2B,EAC3B,kBAAkB,EACnB,MAAM,oBAAoB,CAAC;AAI5B,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAOmC,CAAC;AAGhE,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,eAAe,CAAC,CAAC;AAG/D,MAAM,MAAM,cAAc,GACtB,yBAAyB,GACzB,cAAc,GACd,sBAAsB,GACtB,qBAAqB,GACrB,2BAA2B,GAC3B,kBAAkB,CAAC;AAGvB,MAAM,WAAW,oBAAoB;IACnC,SAAS,EAAE,CAAC,OAAO,EAAE,gBAAgB,KAAK,OAAO,CAAC;QAAE,IAAI,EAAE,UAAU,CAAA;KAAE,CAAC,CAAC;CACzE"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { AppKeyPropertySchema, ActionTypePropertySchema, ActionKeyPropertySchema, } from "../../types/properties";
|
|
3
|
+
import { TelemetryMarkerSchema } from "../../utils/function-utils";
|
|
3
4
|
// Pure Zod schema - no resolver metadata!
|
|
4
5
|
export const GetActionSchema = z
|
|
5
6
|
.object({
|
|
@@ -7,4 +8,5 @@ export const GetActionSchema = z
|
|
|
7
8
|
actionType: ActionTypePropertySchema,
|
|
8
9
|
actionKey: ActionKeyPropertySchema,
|
|
9
10
|
})
|
|
11
|
+
.merge(TelemetryMarkerSchema)
|
|
10
12
|
.describe("Get detailed information about a specific action");
|
|
@@ -4,6 +4,7 @@ import type { GetAppOptions } from "./schemas";
|
|
|
4
4
|
import type { AppItem } from "../../types/domain";
|
|
5
5
|
import type { GetSdkType } from "../../types/plugin";
|
|
6
6
|
import type { ListAppsPluginProvides } from "../listApps";
|
|
7
|
+
import type { EventEmissionContext } from "../eventEmission";
|
|
7
8
|
export interface GetAppPluginProvides {
|
|
8
9
|
getApp: (options: GetAppOptions) => Promise<{
|
|
9
10
|
data: AppItem;
|
|
@@ -16,5 +17,5 @@ export interface GetAppPluginProvides {
|
|
|
16
17
|
};
|
|
17
18
|
};
|
|
18
19
|
}
|
|
19
|
-
export declare const getAppPlugin: Plugin<GetSdkType<ListAppsPluginProvides>,
|
|
20
|
+
export declare const getAppPlugin: Plugin<GetSdkType<ListAppsPluginProvides>, EventEmissionContext, GetAppPluginProvides>;
|
|
20
21
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/getApp/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAEjD,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAGlD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/getApp/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAEjD,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAGlD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAE1D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAI7D,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,CAAC,OAAO,EAAE,aAAa,KAAK,OAAO,CAAC;QAAE,IAAI,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC;IAC/D,OAAO,EAAE;QACP,IAAI,EAAE;YACJ,MAAM,EAAE;gBACN,WAAW,EAAE,OAAO,YAAY,CAAC;aAClC,CAAC;SACH,CAAC;KACH,CAAC;CACH;AAGD,eAAO,MAAM,YAAY,EAAE,MAAM,CAC/B,UAAU,CAAC,sBAAsB,CAAC,EAClC,oBAAoB,EACpB,oBAAoB,CA8CrB,CAAC"}
|