@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.
Files changed (71) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/api/schemas.d.ts +174 -174
  3. package/dist/constants.d.ts +4 -0
  4. package/dist/constants.d.ts.map +1 -1
  5. package/dist/constants.js +4 -0
  6. package/dist/index.cjs +436 -5
  7. package/dist/index.d.mts +380 -156
  8. package/dist/index.d.ts +3 -0
  9. package/dist/index.d.ts.map +1 -1
  10. package/dist/index.js +1 -0
  11. package/dist/index.mjs +407 -9
  12. package/dist/plugins/api/index.d.ts +1 -3
  13. package/dist/plugins/api/index.d.ts.map +1 -1
  14. package/dist/plugins/eventEmission/builders.d.ts +13 -0
  15. package/dist/plugins/eventEmission/builders.d.ts.map +1 -0
  16. package/dist/plugins/eventEmission/builders.js +78 -0
  17. package/dist/plugins/eventEmission/index.d.ts +34 -0
  18. package/dist/plugins/eventEmission/index.d.ts.map +1 -0
  19. package/dist/plugins/eventEmission/index.js +216 -0
  20. package/dist/plugins/eventEmission/index.test.d.ts +5 -0
  21. package/dist/plugins/eventEmission/index.test.d.ts.map +1 -0
  22. package/dist/plugins/eventEmission/index.test.js +143 -0
  23. package/dist/plugins/eventEmission/transport.d.ts +37 -0
  24. package/dist/plugins/eventEmission/transport.d.ts.map +1 -0
  25. package/dist/plugins/eventEmission/transport.js +96 -0
  26. package/dist/plugins/eventEmission/transport.test.d.ts +5 -0
  27. package/dist/plugins/eventEmission/transport.test.d.ts.map +1 -0
  28. package/dist/plugins/eventEmission/transport.test.js +153 -0
  29. package/dist/plugins/eventEmission/types.d.ts +53 -0
  30. package/dist/plugins/eventEmission/types.d.ts.map +1 -0
  31. package/dist/plugins/eventEmission/types.js +1 -0
  32. package/dist/plugins/eventEmission/utils.d.ts +45 -0
  33. package/dist/plugins/eventEmission/utils.d.ts.map +1 -0
  34. package/dist/plugins/eventEmission/utils.js +114 -0
  35. package/dist/plugins/fetch/schemas.d.ts +4 -4
  36. package/dist/plugins/getAction/schemas.d.ts +2 -2
  37. package/dist/plugins/listActions/schemas.d.ts +2 -2
  38. package/dist/plugins/listInputFieldChoices/schemas.d.ts +4 -4
  39. package/dist/plugins/listInputFields/schemas.d.ts +2 -2
  40. package/dist/plugins/request/schemas.d.ts +4 -4
  41. package/dist/plugins/runAction/schemas.d.ts +2 -2
  42. package/dist/resolvers/actionType.d.ts.map +1 -1
  43. package/dist/resolvers/actionType.js +2 -3
  44. package/dist/resolvers/authenticationId.d.ts.map +1 -1
  45. package/dist/schemas/Action.d.ts +2 -2
  46. package/dist/schemas/App.d.ts +30 -30
  47. package/dist/sdk.d.ts +2 -2
  48. package/dist/sdk.d.ts.map +1 -1
  49. package/dist/sdk.js +4 -1
  50. package/dist/types/sdk.d.ts +5 -1
  51. package/dist/types/sdk.d.ts.map +1 -1
  52. package/dist/types/telemetry-events.d.ts +76 -0
  53. package/dist/types/telemetry-events.d.ts.map +1 -0
  54. package/dist/types/telemetry-events.js +8 -0
  55. package/package.json +1 -1
  56. package/src/constants.ts +6 -0
  57. package/src/index.ts +24 -0
  58. package/src/plugins/api/index.ts +1 -5
  59. package/src/plugins/eventEmission/builders.ts +115 -0
  60. package/src/plugins/eventEmission/index.test.ts +169 -0
  61. package/src/plugins/eventEmission/index.ts +294 -0
  62. package/src/plugins/eventEmission/transport.test.ts +214 -0
  63. package/src/plugins/eventEmission/transport.ts +135 -0
  64. package/src/plugins/eventEmission/types.ts +58 -0
  65. package/src/plugins/eventEmission/utils.ts +121 -0
  66. package/src/resolvers/actionType.ts +4 -3
  67. package/src/resolvers/authenticationId.ts +2 -1
  68. package/src/sdk.ts +5 -1
  69. package/src/types/sdk.ts +7 -1
  70. package/src/types/telemetry-events.ts +85 -0
  71. package/tsconfig.tsbuildinfo +1 -1
@@ -0,0 +1,76 @@
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
+ export interface BaseEvent {
9
+ event_id: string;
10
+ timestamp_ms: number;
11
+ release_id: string;
12
+ customuser_id?: number | null;
13
+ account_id?: number | null;
14
+ identity_id?: number | null;
15
+ visitor_id?: string | null;
16
+ correlation_id?: string | null;
17
+ }
18
+ export interface ErrorOccurredEvent extends BaseEvent {
19
+ zap_id?: number | null;
20
+ node_id?: number | null;
21
+ selected_api?: string | null;
22
+ app_id?: number | null;
23
+ app_version_id?: number | null;
24
+ error_message: string;
25
+ error_type?: string | null;
26
+ error_status_code?: number | null;
27
+ error_stack_trace?: string | null;
28
+ error_source_method?: string | null;
29
+ error_source_file?: string | null;
30
+ error_line_number?: number | null;
31
+ operation_type?: string | null;
32
+ operation_key?: string | null;
33
+ error_severity?: string | null;
34
+ is_user_facing: boolean;
35
+ is_recoverable?: boolean | null;
36
+ sdk_version?: string | null;
37
+ error_metadata?: Record<string, string | null> | null;
38
+ parent_error_id?: string | null;
39
+ error_occurred_timestamp_ms?: number | null;
40
+ error_code?: string | null;
41
+ recovery_attempted?: boolean | null;
42
+ recovery_action?: string | null;
43
+ recovery_successful?: boolean | null;
44
+ environment?: string | null;
45
+ execution_time_before_error_ms?: number | null;
46
+ }
47
+ export interface ApplicationLifecycleEvent extends BaseEvent {
48
+ lifecycle_event_type: "startup" | "exit" | "signal_termination";
49
+ selected_api?: string | null;
50
+ app_id?: number | null;
51
+ app_version_id?: number | null;
52
+ sdk_version?: string | null;
53
+ cli_version?: string | null;
54
+ exit_code?: number | null;
55
+ signal_name?: string | null;
56
+ uptime_ms?: number | null;
57
+ memory_usage_bytes?: number | null;
58
+ peak_memory_usage_bytes?: number | null;
59
+ cpu_time_ms?: number | null;
60
+ os_platform?: string | null;
61
+ os_release?: string | null;
62
+ os_architecture?: string | null;
63
+ platform_versions?: Record<string, string | null> | null;
64
+ environment?: string | null;
65
+ is_ci_environment?: boolean | null;
66
+ ci_platform?: string | null;
67
+ session_id?: string | null;
68
+ metadata?: Record<string, string | null> | null;
69
+ process_argv?: (string | null)[] | null;
70
+ is_graceful_shutdown?: boolean | null;
71
+ shutdown_duration_ms?: number | null;
72
+ active_requests_count?: number | null;
73
+ }
74
+ export type TelemetryEvent = ErrorOccurredEvent | ApplicationLifecycleEvent;
75
+ export type TelemetryEventType = "error_occurred" | "application_lifecycle";
76
+ //# sourceMappingURL=telemetry-events.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"telemetry-events.d.ts","sourceRoot":"","sources":["../../src/types/telemetry-events.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,MAAM,WAAW,SAAS;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAChC;AAGD,MAAM,WAAW,kBAAmB,SAAQ,SAAS;IACnD,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,iBAAiB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAClC,iBAAiB,CAAC,EAAE,MAAM,GAAG,IAAI,C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0,0 +1,8 @@
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
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zapier/zapier-sdk",
3
- "version": "0.13.3",
3
+ "version": "0.13.4",
4
4
  "description": "Complete Zapier SDK - combines all Zapier SDK packages",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.mjs",
package/src/constants.ts CHANGED
@@ -8,3 +8,9 @@
8
8
  * Maximum number of items that can be requested per page across all paginated functions
9
9
  */
10
10
  export const MAX_PAGE_LIMIT = 10000;
11
+
12
+ /**
13
+ * Default telemetry endpoint for the Tracking API
14
+ */
15
+ export const TRACKING_API_ENDPOINT =
16
+ "https://zapier.com/api/v4/tracking/event/";
package/src/index.ts CHANGED
@@ -85,3 +85,27 @@ export { registryPlugin } from "./plugins/registry";
85
85
 
86
86
  // Export ZapierSdk from sdk.ts (it's now ReturnType<typeof createZapierSdk>)
87
87
  export type { ZapierSdk } from "./types/sdk";
88
+
89
+ // Export event types and utilities for external packages
90
+ export type { BaseEvent } from "./types/telemetry-events";
91
+ export type {
92
+ EventEmissionContext,
93
+ EventContext,
94
+ ApplicationLifecycleEventData,
95
+ EnhancedErrorEventData,
96
+ } from "./plugins/eventEmission";
97
+ export {
98
+ generateEventId,
99
+ getCurrentTimestamp,
100
+ getReleaseId,
101
+ getOsInfo,
102
+ getPlatformVersions,
103
+ isCi,
104
+ getCiPlatform,
105
+ getMemoryUsage,
106
+ getCpuTime,
107
+ buildApplicationLifecycleEvent,
108
+ buildErrorEventWithContext,
109
+ buildErrorEvent,
110
+ createBaseEvent,
111
+ } from "./plugins/eventEmission";
@@ -13,11 +13,7 @@ export interface ApiPluginProvides {
13
13
  }
14
14
 
15
15
  // API plugin requires no context and provides api in context
16
- export const apiPlugin: Plugin<
17
- {}, // no SDK dependencies
18
- {}, // requires no context
19
- ApiPluginProvides
20
- > = (params) => {
16
+ export const apiPlugin: Plugin<{}, {}, ApiPluginProvides> = (params) => {
21
17
  // Extract all options - everything passed to the plugin
22
18
  const {
23
19
  fetch: customFetch = globalThis.fetch,
@@ -0,0 +1,115 @@
1
+ /**
2
+ * Event builder utilities for creating telemetry events
3
+ *
4
+ * Provides builder functions that auto-populate common fields and ensure
5
+ * schema compliance for all event types.
6
+ */
7
+
8
+ import type {
9
+ ErrorOccurredEvent,
10
+ ApplicationLifecycleEvent,
11
+ BaseEvent,
12
+ } from "../../types/telemetry-events";
13
+ import type {
14
+ ApplicationLifecycleEventData,
15
+ EnhancedErrorEventData,
16
+ ErrorEventData,
17
+ EventContext,
18
+ } from "./types";
19
+ import {
20
+ generateEventId,
21
+ getCurrentTimestamp,
22
+ getReleaseId,
23
+ getOsInfo,
24
+ getPlatformVersions,
25
+ getMemoryUsage,
26
+ getCpuTime,
27
+ isCi,
28
+ getCiPlatform,
29
+ } from "./utils";
30
+ import sdkPackageJson from "../../../package.json";
31
+
32
+ // Create base event with auto-populated common fields
33
+ // Kept for backward compatibility but can be replaced with direct construction
34
+ export function createBaseEvent(context: EventContext = {}): BaseEvent {
35
+ return {
36
+ event_id: generateEventId(),
37
+ timestamp_ms: getCurrentTimestamp(),
38
+ release_id: getReleaseId(),
39
+ customuser_id: context.customuser_id,
40
+ account_id: context.account_id,
41
+ identity_id: context.identity_id,
42
+ visitor_id: context.visitor_id,
43
+ correlation_id: context.correlation_id,
44
+ };
45
+ }
46
+
47
+ export function buildErrorEvent(
48
+ data: ErrorEventData,
49
+ context: EventContext = {},
50
+ ): ErrorOccurredEvent {
51
+ return {
52
+ ...createBaseEvent(context),
53
+ zap_id: context.zap_id,
54
+ node_id: context.node_id,
55
+ selected_api: context.selected_api,
56
+ app_id: context.app_id,
57
+ app_version_id: context.app_version_id,
58
+ environment: context.environment,
59
+ sdk_version: sdkPackageJson.version,
60
+ ...data,
61
+ };
62
+ }
63
+
64
+ export function buildApplicationLifecycleEvent(
65
+ data: ApplicationLifecycleEventData,
66
+ context: EventContext = {},
67
+ ): ApplicationLifecycleEvent {
68
+ const osInfo = getOsInfo();
69
+ const platformVersions = getPlatformVersions();
70
+
71
+ return {
72
+ ...createBaseEvent(context),
73
+ selected_api: context.selected_api,
74
+ app_id: context.app_id,
75
+ app_version_id: context.app_version_id,
76
+ sdk_version: sdkPackageJson.version,
77
+ cli_version: null,
78
+ memory_usage_bytes: data.memory_usage_bytes ?? getMemoryUsage(),
79
+ peak_memory_usage_bytes: data.peak_memory_usage_bytes ?? getMemoryUsage(),
80
+ cpu_time_ms: data.cpu_time_ms ?? getCpuTime(),
81
+ os_platform: osInfo.platform,
82
+ os_release: osInfo.release,
83
+ os_architecture: osInfo.architecture,
84
+ platform_versions: platformVersions,
85
+ environment: context.environment ?? (process.env.NODE_ENV || null),
86
+ is_ci_environment: isCi(),
87
+ ci_platform: getCiPlatform(),
88
+ session_id: null,
89
+ metadata: null,
90
+ process_argv: process.argv || null,
91
+ ...data,
92
+ };
93
+ }
94
+
95
+ export function buildErrorEventWithContext(
96
+ data: EnhancedErrorEventData,
97
+ context: EventContext = {},
98
+ ): ErrorOccurredEvent {
99
+ const executionTime = data.execution_start_time
100
+ ? Date.now() - data.execution_start_time
101
+ : null;
102
+
103
+ return {
104
+ ...createBaseEvent(context),
105
+ zap_id: context.zap_id,
106
+ node_id: context.node_id,
107
+ selected_api: context.selected_api,
108
+ app_id: context.app_id,
109
+ app_version_id: context.app_version_id,
110
+ environment: context.environment ?? (process.env.NODE_ENV || null),
111
+ sdk_version: sdkPackageJson.version,
112
+ execution_time_before_error_ms: executionTime,
113
+ ...data,
114
+ };
115
+ }
@@ -0,0 +1,169 @@
1
+ /**
2
+ * Tests for Event Emission Plugin
3
+ */
4
+
5
+ import { describe, it, expect, vi, beforeEach } from "vitest";
6
+ import { eventEmissionPlugin } from "./index";
7
+ import { createTransport } from "./transport";
8
+ import type { EventEmissionConfig } from "./index";
9
+
10
+ // Mock transport for testing
11
+ const mockTransport = {
12
+ emit: vi.fn().mockResolvedValue(undefined),
13
+ close: vi.fn().mockResolvedValue(undefined),
14
+ };
15
+
16
+ vi.mock("./transport", () => ({
17
+ createTransport: vi.fn(() => mockTransport),
18
+ }));
19
+
20
+ describe("eventEmissionPlugin", () => {
21
+ beforeEach(() => {
22
+ vi.clearAllMocks();
23
+ });
24
+
25
+ it("should create plugin with default configuration", () => {
26
+ const plugin = eventEmissionPlugin({
27
+ sdk: {},
28
+ context: {
29
+ meta: {},
30
+ options: {},
31
+ },
32
+ });
33
+
34
+ expect(plugin.context.eventEmission).toBeDefined();
35
+ expect(plugin.context.eventEmission.emit).toBeDefined();
36
+ expect(plugin.context.eventEmission.transport).toBeDefined();
37
+ expect(plugin.context.eventEmission.config).toBeDefined();
38
+ });
39
+
40
+ it("should create noop implementations when disabled", () => {
41
+ const config: EventEmissionConfig = { enabled: false };
42
+ const plugin = eventEmissionPlugin({
43
+ sdk: {},
44
+ context: {
45
+ meta: {},
46
+ options: { eventEmission: config },
47
+ },
48
+ });
49
+
50
+ // Should not emit any events when disabled
51
+ plugin.context.eventEmission.emit("platform.sdk.TestEvent", {
52
+ test_event: "data",
53
+ });
54
+
55
+ expect(mockTransport.emit).not.toHaveBeenCalled();
56
+ });
57
+
58
+ it("should emit events using generic emit method", async () => {
59
+ const plugin = eventEmissionPlugin({
60
+ sdk: {},
61
+ context: {
62
+ meta: {},
63
+ options: {
64
+ eventEmission: {
65
+ enabled: true,
66
+ transport: { type: "console" as const },
67
+ },
68
+ },
69
+ },
70
+ });
71
+
72
+ const testEvent = {
73
+ test_data: "example",
74
+ value: 123,
75
+ };
76
+
77
+ const testSubject = "test.event.TestEvent";
78
+
79
+ plugin.context.eventEmission.emit(testSubject, testEvent);
80
+
81
+ // Give async emission time to complete
82
+ await new Promise((resolve) => setTimeout(resolve, 0));
83
+
84
+ expect(mockTransport.emit).toHaveBeenCalledWith(testSubject, testEvent);
85
+ });
86
+
87
+ it("should handle transport creation failures silently", () => {
88
+ // Mock createTransport to throw an error
89
+ vi.mocked(createTransport).mockImplementationOnce(() => {
90
+ throw new Error("Transport creation failed");
91
+ });
92
+
93
+ expect(() => {
94
+ eventEmissionPlugin({
95
+ sdk: {},
96
+ context: {
97
+ meta: {},
98
+ options: {
99
+ eventEmission: {
100
+ enabled: true,
101
+ transport: { type: "http" as const, endpoint: "invalid-url" },
102
+ },
103
+ },
104
+ },
105
+ });
106
+ }).not.toThrow();
107
+ });
108
+
109
+ it("should handle event emission failures silently", async () => {
110
+ // Mock transport to throw error
111
+ const failingTransport = {
112
+ emit: vi.fn().mockRejectedValue(new Error("Network error")),
113
+ close: vi.fn().mockResolvedValue(undefined),
114
+ };
115
+
116
+ vi.mocked(createTransport).mockReturnValueOnce(failingTransport);
117
+
118
+ const plugin = eventEmissionPlugin({
119
+ sdk: {},
120
+ context: {
121
+ meta: {},
122
+ options: {
123
+ eventEmission: {
124
+ enabled: true,
125
+ transport: {
126
+ type: "http" as const,
127
+ endpoint: "https://example.com",
128
+ },
129
+ },
130
+ },
131
+ },
132
+ });
133
+
134
+ // Should not throw even if transport fails
135
+ expect(() => {
136
+ plugin.context.eventEmission.emit("test.event.TestEvent", {
137
+ test_event: "data",
138
+ });
139
+ }).not.toThrow();
140
+
141
+ // Give async emission time to complete
142
+ await new Promise((resolve) => setTimeout(resolve, 10));
143
+
144
+ expect(failingTransport.emit).toHaveBeenCalled();
145
+ });
146
+
147
+ it("should merge options with defaults", () => {
148
+ const plugin = eventEmissionPlugin({
149
+ sdk: {},
150
+ context: {
151
+ meta: {},
152
+ options: {
153
+ eventEmission: {
154
+ transport: {
155
+ type: "http" as const,
156
+ endpoint: "https://example.com",
157
+ },
158
+ },
159
+ },
160
+ },
161
+ });
162
+
163
+ expect(plugin.context.eventEmission.config.enabled).toBe(true);
164
+ expect(plugin.context.eventEmission.config.transport).toEqual({
165
+ type: "http",
166
+ endpoint: "https://example.com",
167
+ });
168
+ });
169
+ });