@zapier/zapier-sdk 0.13.3 → 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 +6 -0
- 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 +436 -5
- package/dist/index.d.mts +380 -156
- 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 +407 -9
- 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/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/schemas.d.ts +2 -2
- package/dist/plugins/request/schemas.d.ts +4 -4
- 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/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/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
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Simple utility functions for event emission
|
|
3
|
+
* These are pure functions that can be used to populate common event fields
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import * as os from "os";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Generate a unique event ID
|
|
10
|
+
*/
|
|
11
|
+
export function generateEventId(): string {
|
|
12
|
+
return crypto.randomUUID();
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Get current timestamp in milliseconds since epoch
|
|
17
|
+
*/
|
|
18
|
+
export function getCurrentTimestamp(): number {
|
|
19
|
+
return Date.now();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Get release ID (git SHA) - in production this would come from build process
|
|
24
|
+
*/
|
|
25
|
+
export function getReleaseId(): string {
|
|
26
|
+
return process?.env?.SDK_RELEASE_ID || "development";
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Get operating system information
|
|
31
|
+
*/
|
|
32
|
+
export function getOsInfo(): {
|
|
33
|
+
platform: string | null;
|
|
34
|
+
release: string | null;
|
|
35
|
+
architecture: string | null;
|
|
36
|
+
} {
|
|
37
|
+
try {
|
|
38
|
+
return {
|
|
39
|
+
platform: os.platform() || null,
|
|
40
|
+
release: os.release() || null,
|
|
41
|
+
architecture: os.arch() || null,
|
|
42
|
+
};
|
|
43
|
+
} catch {
|
|
44
|
+
// Browser environment - os module not available
|
|
45
|
+
return {
|
|
46
|
+
platform: null,
|
|
47
|
+
release: null,
|
|
48
|
+
architecture: null,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Get platform versions (Node.js, npm, etc.)
|
|
55
|
+
*/
|
|
56
|
+
export function getPlatformVersions(): Record<string, string | null> {
|
|
57
|
+
const versions: Record<string, string | null> = {};
|
|
58
|
+
if (typeof process?.versions === "object") {
|
|
59
|
+
for (const [key, value] of Object.entries(process.versions)) {
|
|
60
|
+
versions[key] = value || null;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return versions;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Check if running in CI environment
|
|
68
|
+
*/
|
|
69
|
+
export function isCi(): boolean {
|
|
70
|
+
return !!(
|
|
71
|
+
process?.env?.CI ||
|
|
72
|
+
process?.env?.CONTINUOUS_INTEGRATION ||
|
|
73
|
+
process?.env?.GITHUB_ACTIONS ||
|
|
74
|
+
process?.env?.JENKINS_URL ||
|
|
75
|
+
process?.env?.GITLAB_CI ||
|
|
76
|
+
process?.env?.CIRCLECI ||
|
|
77
|
+
process?.env?.TRAVIS ||
|
|
78
|
+
process?.env?.BUILDKITE ||
|
|
79
|
+
process?.env?.DRONE ||
|
|
80
|
+
process?.env?.BITBUCKET_PIPELINES_UUID
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Get CI platform name if running in CI
|
|
86
|
+
*/
|
|
87
|
+
export function getCiPlatform(): string | null {
|
|
88
|
+
if (process?.env?.GITHUB_ACTIONS) return "github-actions";
|
|
89
|
+
if (process?.env?.JENKINS_URL) return "jenkins";
|
|
90
|
+
if (process?.env?.GITLAB_CI) return "gitlab-ci";
|
|
91
|
+
if (process?.env?.CIRCLECI) return "circleci";
|
|
92
|
+
if (process?.env?.TRAVIS) return "travis";
|
|
93
|
+
if (process?.env?.BUILDKITE) return "buildkite";
|
|
94
|
+
if (process?.env?.DRONE) return "drone";
|
|
95
|
+
if (process?.env?.BITBUCKET_PIPELINES_UUID) return "bitbucket-pipelines";
|
|
96
|
+
if (process?.env?.CI || process?.env?.CONTINUOUS_INTEGRATION)
|
|
97
|
+
return "unknown-ci";
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Get memory usage in bytes
|
|
103
|
+
*/
|
|
104
|
+
export function getMemoryUsage(): number | null {
|
|
105
|
+
if (process?.memoryUsage) {
|
|
106
|
+
const usage = process.memoryUsage();
|
|
107
|
+
return usage.rss || null; // Resident Set Size
|
|
108
|
+
}
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Get CPU time in milliseconds
|
|
114
|
+
*/
|
|
115
|
+
export function getCpuTime(): number | null {
|
|
116
|
+
if (process?.cpuUsage) {
|
|
117
|
+
const usage = process.cpuUsage();
|
|
118
|
+
return Math.round((usage.user + usage.system) / 1000); // Convert to milliseconds
|
|
119
|
+
}
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
@@ -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";
|