@zapier/zapier-sdk 0.13.2 → 0.13.4
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/api/debug.d.ts.map +1 -1
- package/dist/api/debug.js +36 -1
- package/dist/api/schemas.d.ts +174 -174
- package/dist/constants.d.ts +4 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +4 -0
- package/dist/index.cjs +475 -9
- package/dist/index.d.mts +381 -157
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.mjs +446 -13
- package/dist/plugins/api/index.d.ts +1 -3
- package/dist/plugins/api/index.d.ts.map +1 -1
- package/dist/plugins/eventEmission/builders.d.ts +13 -0
- package/dist/plugins/eventEmission/builders.d.ts.map +1 -0
- package/dist/plugins/eventEmission/builders.js +78 -0
- package/dist/plugins/eventEmission/index.d.ts +34 -0
- package/dist/plugins/eventEmission/index.d.ts.map +1 -0
- package/dist/plugins/eventEmission/index.js +216 -0
- package/dist/plugins/eventEmission/index.test.d.ts +5 -0
- package/dist/plugins/eventEmission/index.test.d.ts.map +1 -0
- package/dist/plugins/eventEmission/index.test.js +143 -0
- package/dist/plugins/eventEmission/transport.d.ts +37 -0
- package/dist/plugins/eventEmission/transport.d.ts.map +1 -0
- package/dist/plugins/eventEmission/transport.js +96 -0
- package/dist/plugins/eventEmission/transport.test.d.ts +5 -0
- package/dist/plugins/eventEmission/transport.test.d.ts.map +1 -0
- package/dist/plugins/eventEmission/transport.test.js +153 -0
- package/dist/plugins/eventEmission/types.d.ts +53 -0
- package/dist/plugins/eventEmission/types.d.ts.map +1 -0
- package/dist/plugins/eventEmission/types.js +1 -0
- package/dist/plugins/eventEmission/utils.d.ts +45 -0
- package/dist/plugins/eventEmission/utils.d.ts.map +1 -0
- package/dist/plugins/eventEmission/utils.js +114 -0
- package/dist/plugins/fetch/schemas.d.ts +4 -4
- package/dist/plugins/getAction/index.d.ts.map +1 -1
- package/dist/plugins/getAction/index.js +3 -2
- package/dist/plugins/getAction/schemas.d.ts +2 -2
- package/dist/plugins/listActions/schemas.d.ts +2 -2
- package/dist/plugins/listInputFieldChoices/schemas.d.ts +4 -4
- package/dist/plugins/listInputFields/index.d.ts +2 -1
- package/dist/plugins/listInputFields/index.d.ts.map +1 -1
- package/dist/plugins/listInputFields/index.js +7 -2
- package/dist/plugins/listInputFields/index.test.js +36 -5
- package/dist/plugins/listInputFields/schemas.d.ts +2 -2
- package/dist/plugins/request/schemas.d.ts +4 -4
- package/dist/plugins/runAction/index.d.ts.map +1 -1
- package/dist/plugins/runAction/index.js +6 -1
- package/dist/plugins/runAction/schemas.d.ts +2 -2
- package/dist/resolvers/actionType.d.ts.map +1 -1
- package/dist/resolvers/actionType.js +2 -3
- package/dist/resolvers/authenticationId.d.ts.map +1 -1
- package/dist/schemas/Action.d.ts +2 -2
- package/dist/schemas/App.d.ts +30 -30
- package/dist/sdk.d.ts +2 -2
- package/dist/sdk.d.ts.map +1 -1
- package/dist/sdk.js +4 -1
- package/dist/types/sdk.d.ts +5 -1
- package/dist/types/sdk.d.ts.map +1 -1
- package/dist/types/telemetry-events.d.ts +76 -0
- package/dist/types/telemetry-events.d.ts.map +1 -0
- package/dist/types/telemetry-events.js +8 -0
- package/package.json +1 -1
- package/src/api/debug.ts +44 -1
- package/src/constants.ts +6 -0
- package/src/index.ts +24 -0
- package/src/plugins/api/index.ts +1 -5
- package/src/plugins/eventEmission/builders.ts +115 -0
- package/src/plugins/eventEmission/index.test.ts +169 -0
- package/src/plugins/eventEmission/index.ts +294 -0
- package/src/plugins/eventEmission/transport.test.ts +214 -0
- package/src/plugins/eventEmission/transport.ts +135 -0
- package/src/plugins/eventEmission/types.ts +58 -0
- package/src/plugins/eventEmission/utils.ts +121 -0
- package/src/plugins/getAction/index.ts +5 -2
- package/src/plugins/listInputFields/index.test.ts +37 -5
- package/src/plugins/listInputFields/index.ts +10 -3
- package/src/plugins/runAction/index.ts +9 -0
- package/src/resolvers/actionType.ts +4 -3
- package/src/resolvers/authenticationId.ts +2 -1
- package/src/sdk.ts +5 -1
- package/src/types/sdk.ts +7 -1
- package/src/types/telemetry-events.ts +85 -0
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -46,6 +46,7 @@ interface ExecuteActionOptions {
|
|
|
46
46
|
getVersionedImplementationId: GetVersionedImplementationId;
|
|
47
47
|
};
|
|
48
48
|
appKey: string;
|
|
49
|
+
actionId?: string;
|
|
49
50
|
actionKey: string;
|
|
50
51
|
actionType: string;
|
|
51
52
|
executionOptions: { inputs: Record<string, unknown> };
|
|
@@ -61,6 +62,7 @@ async function executeAction(actionOptions: ExecuteActionOptions): Promise<{
|
|
|
61
62
|
api,
|
|
62
63
|
context,
|
|
63
64
|
appKey,
|
|
65
|
+
actionId,
|
|
64
66
|
actionKey,
|
|
65
67
|
actionType,
|
|
66
68
|
executionOptions,
|
|
@@ -80,12 +82,14 @@ async function executeAction(actionOptions: ExecuteActionOptions): Promise<{
|
|
|
80
82
|
// Step 1: POST to /actions/v1/runs to start execution
|
|
81
83
|
const runRequestData: {
|
|
82
84
|
selected_api: string;
|
|
85
|
+
action_id?: string;
|
|
83
86
|
action_key: string;
|
|
84
87
|
action_type: string;
|
|
85
88
|
inputs: Record<string, unknown>;
|
|
86
89
|
authentication_id?: number | null;
|
|
87
90
|
} = {
|
|
88
91
|
selected_api: selectedApi,
|
|
92
|
+
action_id: actionId,
|
|
89
93
|
action_key: actionKey,
|
|
90
94
|
action_type: actionType,
|
|
91
95
|
inputs: executionOptions.inputs || {},
|
|
@@ -148,11 +152,16 @@ export const runActionPlugin: Plugin<
|
|
|
148
152
|
);
|
|
149
153
|
}
|
|
150
154
|
|
|
155
|
+
const actionId = actionData.data.id;
|
|
156
|
+
|
|
151
157
|
// Execute the action using the Actions API (supports all action types)
|
|
152
158
|
const result = await executeAction({
|
|
153
159
|
api,
|
|
154
160
|
context,
|
|
155
161
|
appKey,
|
|
162
|
+
// Some actions require the action ID to run them, but technically the ID is not guaranteed to be available when
|
|
163
|
+
// we retrieve actions (probably legacy reasons), so we just pass along all the things!
|
|
164
|
+
actionId,
|
|
156
165
|
actionKey,
|
|
157
166
|
actionType,
|
|
158
167
|
executionOptions: { inputs },
|
|
@@ -16,9 +16,10 @@ export const actionTypeResolver: DynamicResolver<
|
|
|
16
16
|
appKey: resolvedParams.appKey,
|
|
17
17
|
});
|
|
18
18
|
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
const actionTypes = actionsResponse.data.map(
|
|
20
|
+
(action) => action.action_type,
|
|
21
|
+
);
|
|
22
|
+
const types: string[] = [...new Set(actionTypes)];
|
|
22
23
|
return types.map((type) => ({ key: type, name: type }));
|
|
23
24
|
},
|
|
24
25
|
prompt: (types) => ({
|
|
@@ -23,7 +23,8 @@ export const authenticationIdResolver: AuthenticationIdResolver = {
|
|
|
23
23
|
|
|
24
24
|
// Filter out myAuths from allAuths
|
|
25
25
|
const otherAuths = allAuths.data.filter(
|
|
26
|
-
(auth
|
|
26
|
+
(auth: { id: number }) =>
|
|
27
|
+
!myAuths.data.some((myAuth: { id: number }) => myAuth.id === auth.id),
|
|
27
28
|
);
|
|
28
29
|
return [...myAuths.data, ...otherAuths];
|
|
29
30
|
},
|
package/src/sdk.ts
CHANGED
|
@@ -33,6 +33,7 @@ import { listInputFieldsPlugin } from "./plugins/listInputFields";
|
|
|
33
33
|
import { listInputFieldChoicesPlugin } from "./plugins/listInputFieldChoices";
|
|
34
34
|
import { requestPlugin } from "./plugins/request";
|
|
35
35
|
import { manifestPlugin } from "./plugins/manifest";
|
|
36
|
+
import { eventEmissionPlugin } from "./plugins/eventEmission";
|
|
36
37
|
|
|
37
38
|
// Full SDK interface with plugins applied
|
|
38
39
|
// Note: ZapierSdk is now defined as ReturnType<typeof createZapierSdk> at the bottom of this file
|
|
@@ -130,10 +131,13 @@ export function createSdk<
|
|
|
130
131
|
export function createZapierSdkWithoutRegistry(options: ZapierSdkOptions = {}) {
|
|
131
132
|
return (
|
|
132
133
|
createSdk(options)
|
|
134
|
+
// Event emission (must be first to be available to other plugins)
|
|
135
|
+
.addPlugin(eventEmissionPlugin)
|
|
136
|
+
|
|
133
137
|
// Provides the API client in context
|
|
134
138
|
.addPlugin(apiPlugin)
|
|
135
139
|
|
|
136
|
-
// Manifest plugin (provides version locking context)
|
|
140
|
+
// Manifest plugin (provides version locking context) - must come after apiPlugin
|
|
137
141
|
.addPlugin(manifestPlugin)
|
|
138
142
|
|
|
139
143
|
// Apps/actions/fields
|
package/src/types/sdk.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import type { EventCallback } from "./events";
|
|
6
|
+
import type { EventEmissionConfig } from "../plugins/eventEmission";
|
|
6
7
|
|
|
7
8
|
// SDK Configuration Types
|
|
8
9
|
export interface BaseSdkOptions {
|
|
@@ -21,6 +22,7 @@ export interface BaseSdkOptions {
|
|
|
21
22
|
};
|
|
22
23
|
};
|
|
23
24
|
};
|
|
25
|
+
eventEmission?: EventEmissionConfig;
|
|
24
26
|
}
|
|
25
27
|
|
|
26
28
|
// SDK interface composed from individual function interfaces
|
|
@@ -33,6 +35,8 @@ import type { RelayRequestSdkFunction } from "../plugins/request/schemas";
|
|
|
33
35
|
import type { z } from "zod";
|
|
34
36
|
import type { RegistryPluginProvides } from "../plugins/registry";
|
|
35
37
|
import type { GetProfilePluginProvides } from "../plugins/getProfile";
|
|
38
|
+
import type { EventEmissionProvides } from "../plugins/eventEmission";
|
|
39
|
+
import type { ApiPluginProvides } from "../plugins/api";
|
|
36
40
|
import type { AppsPluginProvides, ZapierSdkApps } from "../plugins/apps";
|
|
37
41
|
import type { ActionProxy } from "../plugins/apps/schemas";
|
|
38
42
|
import type { FetchPluginProvides } from "../plugins/fetch";
|
|
@@ -104,7 +108,9 @@ export interface ZapierSdk
|
|
|
104
108
|
ListInputFieldsPluginProvides &
|
|
105
109
|
ListInputFieldChoicesPluginProvides &
|
|
106
110
|
RequestPluginProvides &
|
|
107
|
-
GetProfilePluginProvides
|
|
111
|
+
GetProfilePluginProvides &
|
|
112
|
+
EventEmissionProvides &
|
|
113
|
+
ApiPluginProvides
|
|
108
114
|
> {
|
|
109
115
|
// Override apps property to intersect ActionProxy with our typed apps
|
|
110
116
|
apps: ActionProxy & ZapierSdkApps;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Event emission types matching Avro schemas for SDK telemetry
|
|
3
|
+
*
|
|
4
|
+
* These interfaces correspond to the Avro schemas:
|
|
5
|
+
* - application_lifecycle_event.avsc
|
|
6
|
+
* - error_occurred_event.avsc
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
// Common fields present in all events
|
|
10
|
+
export interface BaseEvent {
|
|
11
|
+
event_id: string;
|
|
12
|
+
timestamp_ms: number;
|
|
13
|
+
release_id: string;
|
|
14
|
+
customuser_id?: number | null;
|
|
15
|
+
account_id?: number | null;
|
|
16
|
+
identity_id?: number | null;
|
|
17
|
+
visitor_id?: string | null;
|
|
18
|
+
correlation_id?: string | null;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// Error Event - tracks SDK errors and exceptions
|
|
22
|
+
export interface ErrorOccurredEvent extends BaseEvent {
|
|
23
|
+
zap_id?: number | null;
|
|
24
|
+
node_id?: number | null;
|
|
25
|
+
selected_api?: string | null;
|
|
26
|
+
app_id?: number | null;
|
|
27
|
+
app_version_id?: number | null;
|
|
28
|
+
error_message: string;
|
|
29
|
+
error_type?: string | null;
|
|
30
|
+
error_status_code?: number | null;
|
|
31
|
+
error_stack_trace?: string | null;
|
|
32
|
+
error_source_method?: string | null;
|
|
33
|
+
error_source_file?: string | null;
|
|
34
|
+
error_line_number?: number | null;
|
|
35
|
+
operation_type?: string | null;
|
|
36
|
+
operation_key?: string | null;
|
|
37
|
+
error_severity?: string | null;
|
|
38
|
+
is_user_facing: boolean;
|
|
39
|
+
is_recoverable?: boolean | null;
|
|
40
|
+
sdk_version?: string | null;
|
|
41
|
+
error_metadata?: Record<string, string | null> | null;
|
|
42
|
+
parent_error_id?: string | null;
|
|
43
|
+
error_occurred_timestamp_ms?: number | null;
|
|
44
|
+
error_code?: string | null;
|
|
45
|
+
recovery_attempted?: boolean | null;
|
|
46
|
+
recovery_action?: string | null;
|
|
47
|
+
recovery_successful?: boolean | null;
|
|
48
|
+
environment?: string | null;
|
|
49
|
+
execution_time_before_error_ms?: number | null;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Application Lifecycle Event - tracks SDK application lifecycle transitions
|
|
53
|
+
export interface ApplicationLifecycleEvent extends BaseEvent {
|
|
54
|
+
lifecycle_event_type: "startup" | "exit" | "signal_termination";
|
|
55
|
+
selected_api?: string | null;
|
|
56
|
+
app_id?: number | null;
|
|
57
|
+
app_version_id?: number | null;
|
|
58
|
+
sdk_version?: string | null;
|
|
59
|
+
cli_version?: string | null;
|
|
60
|
+
exit_code?: number | null;
|
|
61
|
+
signal_name?: string | null;
|
|
62
|
+
uptime_ms?: number | null;
|
|
63
|
+
memory_usage_bytes?: number | null;
|
|
64
|
+
peak_memory_usage_bytes?: number | null;
|
|
65
|
+
cpu_time_ms?: number | null;
|
|
66
|
+
os_platform?: string | null;
|
|
67
|
+
os_release?: string | null;
|
|
68
|
+
os_architecture?: string | null;
|
|
69
|
+
platform_versions?: Record<string, string | null> | null;
|
|
70
|
+
environment?: string | null;
|
|
71
|
+
is_ci_environment?: boolean | null;
|
|
72
|
+
ci_platform?: string | null;
|
|
73
|
+
session_id?: string | null;
|
|
74
|
+
metadata?: Record<string, string | null> | null;
|
|
75
|
+
process_argv?: (string | null)[] | null;
|
|
76
|
+
is_graceful_shutdown?: boolean | null;
|
|
77
|
+
shutdown_duration_ms?: number | null;
|
|
78
|
+
active_requests_count?: number | null;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Union type for all telemetry events
|
|
82
|
+
export type TelemetryEvent = ErrorOccurredEvent | ApplicationLifecycleEvent;
|
|
83
|
+
|
|
84
|
+
// Event type discriminator
|
|
85
|
+
export type TelemetryEventType = "error_occurred" | "application_lifecycle";
|