@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
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for Event Transport Layer
|
|
3
|
+
*/
|
|
4
|
+
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
5
|
+
import { HttpTransport, ConsoleTransport, NoopTransport, createTransport, } from "./transport";
|
|
6
|
+
// Mock fetch globally
|
|
7
|
+
const mockFetch = vi.fn();
|
|
8
|
+
global.fetch = mockFetch;
|
|
9
|
+
// Mock console.log
|
|
10
|
+
const mockConsoleLog = vi.spyOn(console, "log").mockImplementation(() => { });
|
|
11
|
+
describe("Transport Layer", () => {
|
|
12
|
+
const sampleEvent = {
|
|
13
|
+
event_id: "test-123",
|
|
14
|
+
timestamp_ms: Date.now(),
|
|
15
|
+
release_id: "test-release",
|
|
16
|
+
error_message: "Test error",
|
|
17
|
+
is_user_facing: false,
|
|
18
|
+
};
|
|
19
|
+
const sampleSubject = "platform.sdk.ErrorOccurredEvent";
|
|
20
|
+
beforeEach(() => {
|
|
21
|
+
vi.clearAllMocks();
|
|
22
|
+
});
|
|
23
|
+
describe("HttpTransport", () => {
|
|
24
|
+
it("should emit events via HTTP successfully", async () => {
|
|
25
|
+
mockFetch.mockResolvedValueOnce({
|
|
26
|
+
ok: true,
|
|
27
|
+
status: 200,
|
|
28
|
+
});
|
|
29
|
+
const transport = new HttpTransport({
|
|
30
|
+
endpoint: "https://telemetry.example.com/events",
|
|
31
|
+
headers: { "x-api-key": "test-key" },
|
|
32
|
+
});
|
|
33
|
+
await transport.emit(sampleSubject, sampleEvent);
|
|
34
|
+
expect(mockFetch).toHaveBeenCalledWith("https://telemetry.example.com/events", {
|
|
35
|
+
method: "POST",
|
|
36
|
+
headers: {
|
|
37
|
+
"Content-Type": "application/json",
|
|
38
|
+
"x-api-key": "test-key",
|
|
39
|
+
},
|
|
40
|
+
body: JSON.stringify({
|
|
41
|
+
subject: sampleSubject,
|
|
42
|
+
properties: sampleEvent,
|
|
43
|
+
}),
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
it("should retry on HTTP failures", async () => {
|
|
47
|
+
// Fail twice, then succeed
|
|
48
|
+
mockFetch
|
|
49
|
+
.mockResolvedValueOnce({ ok: false, status: 500 })
|
|
50
|
+
.mockResolvedValueOnce({ ok: false, status: 500 })
|
|
51
|
+
.mockResolvedValueOnce({ ok: true, status: 200 });
|
|
52
|
+
const transport = new HttpTransport({
|
|
53
|
+
endpoint: "https://telemetry.example.com/events",
|
|
54
|
+
retryAttempts: 3,
|
|
55
|
+
retryDelayMs: 10, // Short delay for testing
|
|
56
|
+
});
|
|
57
|
+
await transport.emit(sampleSubject, sampleEvent);
|
|
58
|
+
expect(mockFetch).toHaveBeenCalledTimes(3);
|
|
59
|
+
});
|
|
60
|
+
it("should handle network errors silently", async () => {
|
|
61
|
+
mockFetch.mockRejectedValue(new Error("Network error"));
|
|
62
|
+
const transport = new HttpTransport({
|
|
63
|
+
endpoint: "https://telemetry.example.com/events",
|
|
64
|
+
retryAttempts: 1,
|
|
65
|
+
retryDelayMs: 1,
|
|
66
|
+
});
|
|
67
|
+
// Should not throw despite network error
|
|
68
|
+
await expect(transport.emit(sampleSubject, sampleEvent)).resolves.toBeUndefined();
|
|
69
|
+
});
|
|
70
|
+
it("should stop retrying after max attempts", async () => {
|
|
71
|
+
mockFetch.mockResolvedValue({ ok: false, status: 500 });
|
|
72
|
+
const transport = new HttpTransport({
|
|
73
|
+
endpoint: "https://telemetry.example.com/events",
|
|
74
|
+
retryAttempts: 2,
|
|
75
|
+
retryDelayMs: 1,
|
|
76
|
+
});
|
|
77
|
+
await transport.emit(sampleSubject, sampleEvent);
|
|
78
|
+
expect(mockFetch).toHaveBeenCalledTimes(2);
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
describe("ConsoleTransport", () => {
|
|
82
|
+
it("should log events to console", async () => {
|
|
83
|
+
const transport = new ConsoleTransport();
|
|
84
|
+
await transport.emit(sampleSubject, sampleEvent);
|
|
85
|
+
expect(mockConsoleLog).toHaveBeenCalledWith("[SDK Telemetry]", JSON.stringify({ subject: sampleSubject, properties: sampleEvent }, null, 2));
|
|
86
|
+
});
|
|
87
|
+
it("should handle console errors silently", async () => {
|
|
88
|
+
mockConsoleLog.mockImplementation(() => {
|
|
89
|
+
throw new Error("Console error");
|
|
90
|
+
});
|
|
91
|
+
const transport = new ConsoleTransport();
|
|
92
|
+
// Should not throw despite console error
|
|
93
|
+
await expect(transport.emit(sampleSubject, sampleEvent)).resolves.toBeUndefined();
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
describe("NoopTransport", () => {
|
|
97
|
+
it("should do nothing when emitting events", async () => {
|
|
98
|
+
const transport = new NoopTransport();
|
|
99
|
+
await transport.emit(sampleSubject, sampleEvent);
|
|
100
|
+
// Verify no side effects
|
|
101
|
+
expect(mockFetch).not.toHaveBeenCalled();
|
|
102
|
+
expect(mockConsoleLog).not.toHaveBeenCalled();
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
describe("createTransport", () => {
|
|
106
|
+
it("should create HTTP transport with valid config", () => {
|
|
107
|
+
const transport = createTransport({
|
|
108
|
+
type: "http",
|
|
109
|
+
endpoint: "https://example.com",
|
|
110
|
+
headers: { "x-key": "value" },
|
|
111
|
+
retryAttempts: 5,
|
|
112
|
+
retryDelayMs: 2000,
|
|
113
|
+
});
|
|
114
|
+
expect(transport).toBeInstanceOf(HttpTransport);
|
|
115
|
+
});
|
|
116
|
+
it("should create console transport", () => {
|
|
117
|
+
const transport = createTransport({
|
|
118
|
+
type: "console",
|
|
119
|
+
});
|
|
120
|
+
expect(transport).toBeInstanceOf(ConsoleTransport);
|
|
121
|
+
});
|
|
122
|
+
it("should create noop transport by default", () => {
|
|
123
|
+
const transport = createTransport({
|
|
124
|
+
type: "noop",
|
|
125
|
+
});
|
|
126
|
+
expect(transport).toBeInstanceOf(NoopTransport);
|
|
127
|
+
});
|
|
128
|
+
it("should fallback to noop transport on invalid HTTP config", () => {
|
|
129
|
+
const transport = createTransport({
|
|
130
|
+
type: "http",
|
|
131
|
+
// Missing endpoint
|
|
132
|
+
});
|
|
133
|
+
expect(transport).toBeInstanceOf(NoopTransport);
|
|
134
|
+
});
|
|
135
|
+
it("should fallback to noop transport on unknown type", () => {
|
|
136
|
+
const transport = createTransport({
|
|
137
|
+
type: "unknown",
|
|
138
|
+
});
|
|
139
|
+
expect(transport).toBeInstanceOf(NoopTransport);
|
|
140
|
+
});
|
|
141
|
+
it("should handle transport creation errors gracefully", () => {
|
|
142
|
+
// Since createTransport already handles errors internally,
|
|
143
|
+
// this test verifies that invalid configs don't throw
|
|
144
|
+
expect(() => {
|
|
145
|
+
const transport = createTransport({
|
|
146
|
+
type: "http",
|
|
147
|
+
// Missing required endpoint - should fallback to noop
|
|
148
|
+
});
|
|
149
|
+
expect(transport).toBeInstanceOf(NoopTransport);
|
|
150
|
+
}).not.toThrow();
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
});
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
export interface EventContext {
|
|
2
|
+
customuser_id?: number | null;
|
|
3
|
+
account_id?: number | null;
|
|
4
|
+
identity_id?: number | null;
|
|
5
|
+
visitor_id?: string | null;
|
|
6
|
+
correlation_id?: string | null;
|
|
7
|
+
selected_api?: string | null;
|
|
8
|
+
app_id?: number | null;
|
|
9
|
+
app_version_id?: number | null;
|
|
10
|
+
zap_id?: number | null;
|
|
11
|
+
node_id?: number | null;
|
|
12
|
+
environment?: string | null;
|
|
13
|
+
sdk_version?: string | null;
|
|
14
|
+
operation_type?: string | null;
|
|
15
|
+
}
|
|
16
|
+
export interface ErrorEventData {
|
|
17
|
+
error_message: string;
|
|
18
|
+
is_user_facing: boolean;
|
|
19
|
+
error_type?: string | null;
|
|
20
|
+
error_status_code?: number | null;
|
|
21
|
+
error_stack_trace?: string | null;
|
|
22
|
+
error_source_method?: string | null;
|
|
23
|
+
error_source_file?: string | null;
|
|
24
|
+
error_line_number?: number | null;
|
|
25
|
+
operation_type?: string | null;
|
|
26
|
+
operation_key?: string | null;
|
|
27
|
+
error_severity?: string | null;
|
|
28
|
+
is_recoverable?: boolean | null;
|
|
29
|
+
error_metadata?: Record<string, string | null> | null;
|
|
30
|
+
parent_error_id?: string | null;
|
|
31
|
+
error_occurred_timestamp_ms?: number | null;
|
|
32
|
+
error_code?: string | null;
|
|
33
|
+
recovery_attempted?: boolean | null;
|
|
34
|
+
recovery_action?: string | null;
|
|
35
|
+
recovery_successful?: boolean | null;
|
|
36
|
+
execution_time_before_error_ms?: number | null;
|
|
37
|
+
}
|
|
38
|
+
export interface EnhancedErrorEventData extends ErrorEventData {
|
|
39
|
+
execution_start_time?: number | null;
|
|
40
|
+
}
|
|
41
|
+
export interface ApplicationLifecycleEventData {
|
|
42
|
+
lifecycle_event_type: "startup" | "exit" | "signal_termination";
|
|
43
|
+
exit_code?: number | null;
|
|
44
|
+
signal_name?: string | null;
|
|
45
|
+
uptime_ms?: number | null;
|
|
46
|
+
is_graceful_shutdown?: boolean | null;
|
|
47
|
+
shutdown_duration_ms?: number | null;
|
|
48
|
+
memory_usage_bytes?: number | null;
|
|
49
|
+
peak_memory_usage_bytes?: number | null;
|
|
50
|
+
cpu_time_ms?: number | null;
|
|
51
|
+
active_requests_count?: number | null;
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +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,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,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,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAChC;AAED,MAAM,WAAW,cAAc;IAC7B,aAAa,EAAE,MAAM,CAAC;IACtB,cAAc,EAAE,OAAO,CAAC;IACxB,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,iBAAiB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAClC,iBAAiB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAClC,mBAAmB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACpC,iBAAiB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAClC,iBAAiB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAClC,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,cAAc,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IAChC,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC;IACtD,eAAe,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,2BAA2B,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5C,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,kBAAkB,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IACpC,eAAe,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,mBAAmB,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IACrC,8BAA8B,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAChD;AAGD,MAAM,WAAW,sBAAuB,SAAQ,cAAc;IAC5D,oBAAoB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACtC;AAED,MAAM,WAAW,6BAA6B;IAC5C,oBAAoB,EAAE,SAAS,GAAG,MAAM,GAAG,oBAAoB,CAAC;IAChE,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,oBAAoB,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IACtC,oBAAoB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAErC,kBAAkB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACnC,uBAAuB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACxC,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,qBAAqB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACvC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,45 @@
|
|
|
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
|
+
* Generate a unique event ID
|
|
7
|
+
*/
|
|
8
|
+
export declare function generateEventId(): string;
|
|
9
|
+
/**
|
|
10
|
+
* Get current timestamp in milliseconds since epoch
|
|
11
|
+
*/
|
|
12
|
+
export declare function getCurrentTimestamp(): number;
|
|
13
|
+
/**
|
|
14
|
+
* Get release ID (git SHA) - in production this would come from build process
|
|
15
|
+
*/
|
|
16
|
+
export declare function getReleaseId(): string;
|
|
17
|
+
/**
|
|
18
|
+
* Get operating system information
|
|
19
|
+
*/
|
|
20
|
+
export declare function getOsInfo(): {
|
|
21
|
+
platform: string | null;
|
|
22
|
+
release: string | null;
|
|
23
|
+
architecture: string | null;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Get platform versions (Node.js, npm, etc.)
|
|
27
|
+
*/
|
|
28
|
+
export declare function getPlatformVersions(): Record<string, string | null>;
|
|
29
|
+
/**
|
|
30
|
+
* Check if running in CI environment
|
|
31
|
+
*/
|
|
32
|
+
export declare function isCi(): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Get CI platform name if running in CI
|
|
35
|
+
*/
|
|
36
|
+
export declare function getCiPlatform(): string | null;
|
|
37
|
+
/**
|
|
38
|
+
* Get memory usage in bytes
|
|
39
|
+
*/
|
|
40
|
+
export declare function getMemoryUsage(): number | null;
|
|
41
|
+
/**
|
|
42
|
+
* Get CPU time in milliseconds
|
|
43
|
+
*/
|
|
44
|
+
export declare function getCpuTime(): number | null;
|
|
45
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/plugins/eventEmission/utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH;;GAEG;AACH,wBAAgB,eAAe,IAAI,MAAM,CAExC;AAED;;GAEG;AACH,wBAAgB,mBAAmB,IAAI,MAAM,CAE5C;AAED;;GAEG;AACH,wBAAgB,YAAY,IAAI,MAAM,CAErC;AAED;;GAEG;AACH,wBAAgB,SAAS,IAAI;IAC3B,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B,CAeA;AAED;;GAEG;AACH,wBAAgB,mBAAmB,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,CAQnE;AAED;;GAEG;AACH,wBAAgB,IAAI,IAAI,OAAO,CAa9B;AAED;;GAEG;AACH,wBAAgB,aAAa,IAAI,MAAM,GAAG,IAAI,CAY7C;AAED;;GAEG;AACH,wBAAgB,cAAc,IAAI,MAAM,GAAG,IAAI,CAM9C;AAED;;GAEG;AACH,wBAAgB,UAAU,IAAI,MAAM,GAAG,IAAI,CAM1C"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Simple utility functions for event emission
|
|
3
|
+
* These are pure functions that can be used to populate common event fields
|
|
4
|
+
*/
|
|
5
|
+
import * as os from "os";
|
|
6
|
+
/**
|
|
7
|
+
* Generate a unique event ID
|
|
8
|
+
*/
|
|
9
|
+
export function generateEventId() {
|
|
10
|
+
return crypto.randomUUID();
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Get current timestamp in milliseconds since epoch
|
|
14
|
+
*/
|
|
15
|
+
export function getCurrentTimestamp() {
|
|
16
|
+
return Date.now();
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Get release ID (git SHA) - in production this would come from build process
|
|
20
|
+
*/
|
|
21
|
+
export function getReleaseId() {
|
|
22
|
+
return process?.env?.SDK_RELEASE_ID || "development";
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Get operating system information
|
|
26
|
+
*/
|
|
27
|
+
export function getOsInfo() {
|
|
28
|
+
try {
|
|
29
|
+
return {
|
|
30
|
+
platform: os.platform() || null,
|
|
31
|
+
release: os.release() || null,
|
|
32
|
+
architecture: os.arch() || null,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
// Browser environment - os module not available
|
|
37
|
+
return {
|
|
38
|
+
platform: null,
|
|
39
|
+
release: null,
|
|
40
|
+
architecture: null,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Get platform versions (Node.js, npm, etc.)
|
|
46
|
+
*/
|
|
47
|
+
export function getPlatformVersions() {
|
|
48
|
+
const versions = {};
|
|
49
|
+
if (typeof process?.versions === "object") {
|
|
50
|
+
for (const [key, value] of Object.entries(process.versions)) {
|
|
51
|
+
versions[key] = value || null;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return versions;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Check if running in CI environment
|
|
58
|
+
*/
|
|
59
|
+
export function isCi() {
|
|
60
|
+
return !!(process?.env?.CI ||
|
|
61
|
+
process?.env?.CONTINUOUS_INTEGRATION ||
|
|
62
|
+
process?.env?.GITHUB_ACTIONS ||
|
|
63
|
+
process?.env?.JENKINS_URL ||
|
|
64
|
+
process?.env?.GITLAB_CI ||
|
|
65
|
+
process?.env?.CIRCLECI ||
|
|
66
|
+
process?.env?.TRAVIS ||
|
|
67
|
+
process?.env?.BUILDKITE ||
|
|
68
|
+
process?.env?.DRONE ||
|
|
69
|
+
process?.env?.BITBUCKET_PIPELINES_UUID);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Get CI platform name if running in CI
|
|
73
|
+
*/
|
|
74
|
+
export function getCiPlatform() {
|
|
75
|
+
if (process?.env?.GITHUB_ACTIONS)
|
|
76
|
+
return "github-actions";
|
|
77
|
+
if (process?.env?.JENKINS_URL)
|
|
78
|
+
return "jenkins";
|
|
79
|
+
if (process?.env?.GITLAB_CI)
|
|
80
|
+
return "gitlab-ci";
|
|
81
|
+
if (process?.env?.CIRCLECI)
|
|
82
|
+
return "circleci";
|
|
83
|
+
if (process?.env?.TRAVIS)
|
|
84
|
+
return "travis";
|
|
85
|
+
if (process?.env?.BUILDKITE)
|
|
86
|
+
return "buildkite";
|
|
87
|
+
if (process?.env?.DRONE)
|
|
88
|
+
return "drone";
|
|
89
|
+
if (process?.env?.BITBUCKET_PIPELINES_UUID)
|
|
90
|
+
return "bitbucket-pipelines";
|
|
91
|
+
if (process?.env?.CI || process?.env?.CONTINUOUS_INTEGRATION)
|
|
92
|
+
return "unknown-ci";
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Get memory usage in bytes
|
|
97
|
+
*/
|
|
98
|
+
export function getMemoryUsage() {
|
|
99
|
+
if (process?.memoryUsage) {
|
|
100
|
+
const usage = process.memoryUsage();
|
|
101
|
+
return usage.rss || null; // Resident Set Size
|
|
102
|
+
}
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Get CPU time in milliseconds
|
|
107
|
+
*/
|
|
108
|
+
export function getCpuTime() {
|
|
109
|
+
if (process?.cpuUsage) {
|
|
110
|
+
const usage = process.cpuUsage();
|
|
111
|
+
return Math.round((usage.user + usage.system) / 1000); // Convert to milliseconds
|
|
112
|
+
}
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
@@ -8,16 +8,16 @@ export declare const FetchInitSchema: z.ZodOptional<z.ZodObject<{
|
|
|
8
8
|
callbackUrl: z.ZodOptional<z.ZodString>;
|
|
9
9
|
authenticationTemplate: z.ZodOptional<z.ZodString>;
|
|
10
10
|
}, "strip", z.ZodTypeAny, {
|
|
11
|
-
method?: "
|
|
11
|
+
method?: "POST" | "GET" | "PUT" | "DELETE" | "PATCH" | "HEAD" | "OPTIONS" | undefined;
|
|
12
12
|
authenticationId?: number | undefined;
|
|
13
|
-
body?: string |
|
|
13
|
+
body?: string | FormData | URLSearchParams | undefined;
|
|
14
14
|
callbackUrl?: string | undefined;
|
|
15
15
|
authenticationTemplate?: string | undefined;
|
|
16
16
|
headers?: Record<string, string> | undefined;
|
|
17
17
|
}, {
|
|
18
|
-
method?: "
|
|
18
|
+
method?: "POST" | "GET" | "PUT" | "DELETE" | "PATCH" | "HEAD" | "OPTIONS" | undefined;
|
|
19
19
|
authenticationId?: number | undefined;
|
|
20
|
-
body?: string |
|
|
20
|
+
body?: string | FormData | URLSearchParams | undefined;
|
|
21
21
|
callbackUrl?: string | undefined;
|
|
22
22
|
authenticationTemplate?: string | undefined;
|
|
23
23
|
headers?: Record<string, string> | undefined;
|
|
@@ -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;AAQhE,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;IAAE,GAAG,EAAE,SAAS,CAAA;CAAE,EAAE,0BAA0B;AAC9C,uBAAuB,
|
|
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;AAQhE,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;IAAE,GAAG,EAAE,SAAS,CAAA;CAAE,EAAE,0BAA0B;AAC9C,uBAAuB,CA8CxB,CAAC"}
|
|
@@ -8,9 +8,10 @@ export const getActionPlugin = ({ sdk }) => {
|
|
|
8
8
|
const { actionKey, actionType, appKey } = options;
|
|
9
9
|
// Use the listActions function from the SDK to search for the specific action
|
|
10
10
|
const actionsResult = await sdk.listActions({ appKey });
|
|
11
|
-
// Search through all actions to find the matching one
|
|
11
|
+
// Search through all actions to find the matching one (by key or ID)
|
|
12
12
|
for (const action of actionsResult.data) {
|
|
13
|
-
if (action.key === actionKey
|
|
13
|
+
if ((action.key === actionKey || action.id === actionKey) &&
|
|
14
|
+
action.action_type === actionType) {
|
|
14
15
|
return { data: action };
|
|
15
16
|
}
|
|
16
17
|
}
|
|
@@ -9,11 +9,11 @@ export declare const GetActionSchema: z.ZodObject<{
|
|
|
9
9
|
actionKey: z.ZodString;
|
|
10
10
|
}, "strip", z.ZodTypeAny, {
|
|
11
11
|
appKey: string;
|
|
12
|
-
actionType: "filter" | "read" | "read_bulk" | "write" | "run" | "
|
|
12
|
+
actionType: "search" | "filter" | "read" | "read_bulk" | "write" | "run" | "search_or_write" | "search_and_write";
|
|
13
13
|
actionKey: string;
|
|
14
14
|
}, {
|
|
15
15
|
appKey: string;
|
|
16
|
-
actionType: "filter" | "read" | "read_bulk" | "write" | "run" | "
|
|
16
|
+
actionType: "search" | "filter" | "read" | "read_bulk" | "write" | "run" | "search_or_write" | "search_and_write";
|
|
17
17
|
actionKey: string;
|
|
18
18
|
}>;
|
|
19
19
|
export type GetActionOptions = z.infer<typeof GetActionSchema>;
|
|
@@ -12,13 +12,13 @@ export declare const ListActionsSchema: z.ZodObject<{
|
|
|
12
12
|
cursor: z.ZodOptional<z.ZodString>;
|
|
13
13
|
}, "strip", z.ZodTypeAny, {
|
|
14
14
|
appKey: string;
|
|
15
|
-
actionType?: "filter" | "read" | "read_bulk" | "write" | "run" | "
|
|
15
|
+
actionType?: "search" | "filter" | "read" | "read_bulk" | "write" | "run" | "search_or_write" | "search_and_write" | undefined;
|
|
16
16
|
pageSize?: number | undefined;
|
|
17
17
|
maxItems?: number | undefined;
|
|
18
18
|
cursor?: string | undefined;
|
|
19
19
|
}, {
|
|
20
20
|
appKey: string;
|
|
21
|
-
actionType?: "filter" | "read" | "read_bulk" | "write" | "run" | "
|
|
21
|
+
actionType?: "search" | "filter" | "read" | "read_bulk" | "write" | "run" | "search_or_write" | "search_and_write" | undefined;
|
|
22
22
|
pageSize?: number | undefined;
|
|
23
23
|
maxItems?: number | undefined;
|
|
24
24
|
cursor?: string | undefined;
|
|
@@ -7,13 +7,13 @@ export declare const InputFieldChoiceItemSchema: z.ZodObject<{
|
|
|
7
7
|
sample: z.ZodOptional<z.ZodString>;
|
|
8
8
|
value: z.ZodOptional<z.ZodString>;
|
|
9
9
|
}, "strip", z.ZodTypeAny, {
|
|
10
|
-
value?: string | undefined;
|
|
11
10
|
key?: string | undefined;
|
|
11
|
+
value?: string | undefined;
|
|
12
12
|
label?: string | undefined;
|
|
13
13
|
sample?: string | undefined;
|
|
14
14
|
}, {
|
|
15
|
-
value?: string | undefined;
|
|
16
15
|
key?: string | undefined;
|
|
16
|
+
value?: string | undefined;
|
|
17
17
|
label?: string | undefined;
|
|
18
18
|
sample?: string | undefined;
|
|
19
19
|
}>;
|
|
@@ -33,7 +33,7 @@ export declare const ListInputFieldChoicesSchema: z.ZodObject<{
|
|
|
33
33
|
cursor: z.ZodOptional<z.ZodString>;
|
|
34
34
|
}, "strip", z.ZodTypeAny, {
|
|
35
35
|
appKey: string;
|
|
36
|
-
actionType: "filter" | "read" | "read_bulk" | "write" | "run" | "
|
|
36
|
+
actionType: "search" | "filter" | "read" | "read_bulk" | "write" | "run" | "search_or_write" | "search_and_write";
|
|
37
37
|
actionKey: string;
|
|
38
38
|
inputFieldKey: string;
|
|
39
39
|
page?: number | undefined;
|
|
@@ -44,7 +44,7 @@ export declare const ListInputFieldChoicesSchema: z.ZodObject<{
|
|
|
44
44
|
cursor?: string | undefined;
|
|
45
45
|
}, {
|
|
46
46
|
appKey: string;
|
|
47
|
-
actionType: "filter" | "read" | "read_bulk" | "write" | "run" | "
|
|
47
|
+
actionType: "search" | "filter" | "read" | "read_bulk" | "write" | "run" | "search_or_write" | "search_and_write";
|
|
48
48
|
actionKey: string;
|
|
49
49
|
inputFieldKey: string;
|
|
50
50
|
page?: number | undefined;
|
|
@@ -3,6 +3,7 @@ import type { ApiClient } from "../../api";
|
|
|
3
3
|
import type { InputFieldItem, InfoFieldItem, FieldsetItem, RootFieldItem } from "../../types/domain";
|
|
4
4
|
import { ListInputFieldsSchema, type ListInputFieldsOptions } from "./schemas";
|
|
5
5
|
import type { GetAppPluginProvides } from "../getApp";
|
|
6
|
+
import type { GetActionPluginProvides } from "../getAction";
|
|
6
7
|
import type { GetVersionedImplementationId } from "../manifest/schemas";
|
|
7
8
|
export interface ListInputFieldsPluginProvides {
|
|
8
9
|
listInputFields: (options?: ListInputFieldsOptions) => Promise<{
|
|
@@ -22,7 +23,7 @@ export interface ListInputFieldsPluginProvides {
|
|
|
22
23
|
};
|
|
23
24
|
};
|
|
24
25
|
}
|
|
25
|
-
export declare const listInputFieldsPlugin: Plugin<GetSdkType<GetAppPluginProvides>, // requires getApp in SDK
|
|
26
|
+
export declare const listInputFieldsPlugin: Plugin<GetSdkType<GetAppPluginProvides & GetActionPluginProvides>, // requires getApp and getAction in SDK
|
|
26
27
|
{
|
|
27
28
|
api: ApiClient;
|
|
28
29
|
getVersionedImplementationId: GetVersionedImplementationId;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/listInputFields/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAE3C,OAAO,KAAK,EACV,cAAc,EACd,aAAa,EACb,YAAY,EACZ,aAAa,EACd,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,qBAAqB,EACrB,KAAK,sBAAsB,EAE5B,MAAM,WAAW,CAAC;AAGnB,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AACtD,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,qBAAqB,CAAC;AAmKxE,MAAM,WAAW,6BAA6B;IAC5C,eAAe,EAAE,CAAC,OAAO,CAAC,EAAE,sBAAsB,KAAK,OAAO,CAAC;QAC7D,IAAI,EAAE,aAAa,EAAE,CAAC;QACtB,UAAU,CAAC,EAAE,MAAM,CAAC;KACrB,CAAC,GACA,aAAa,CAAC;QAAE,IAAI,EAAE,aAAa,EAAE,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,GAAG;QAC9D,KAAK,IAAI,aAAa,CAAC,cAAc,GAAG,aAAa,GAAG,YAAY,CAAC,CAAC;KACvE,CAAC;IACJ,OAAO,EAAE;QACP,IAAI,EAAE;YACJ,eAAe,EAAE;gBACf,WAAW,EAAE,OAAO,qBAAqB,CAAC;aAC3C,CAAC;SACH,CAAC;KACH,CAAC;CACH;AAED,eAAO,MAAM,qBAAqB,EAAE,MAAM,CACxC,UAAU,CAAC,oBAAoB,CAAC,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/listInputFields/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAE3C,OAAO,KAAK,EACV,cAAc,EACd,aAAa,EACb,YAAY,EACZ,aAAa,EACd,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,qBAAqB,EACrB,KAAK,sBAAsB,EAE5B,MAAM,WAAW,CAAC;AAGnB,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AACtD,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AAC5D,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,qBAAqB,CAAC;AAmKxE,MAAM,WAAW,6BAA6B;IAC5C,eAAe,EAAE,CAAC,OAAO,CAAC,EAAE,sBAAsB,KAAK,OAAO,CAAC;QAC7D,IAAI,EAAE,aAAa,EAAE,CAAC;QACtB,UAAU,CAAC,EAAE,MAAM,CAAC;KACrB,CAAC,GACA,aAAa,CAAC;QAAE,IAAI,EAAE,aAAa,EAAE,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,GAAG;QAC9D,KAAK,IAAI,aAAa,CAAC,cAAc,GAAG,aAAa,GAAG,YAAY,CAAC,CAAC;KACvE,CAAC;IACJ,OAAO,EAAE;QACP,IAAI,EAAE;YACJ,eAAe,EAAE;gBACf,WAAW,EAAE,OAAO,qBAAqB,CAAC;aAC3C,CAAC;SACH,CAAC;KACH,CAAC;CACH;AAED,eAAO,MAAM,qBAAqB,EAAE,MAAM,CACxC,UAAU,CAAC,oBAAoB,GAAG,uBAAuB,CAAC,EAAE,uCAAuC;AACnG;IACE,GAAG,EAAE,SAAS,CAAC;IACf,4BAA4B,EAAE,4BAA4B,CAAC;CAC5D,EAAE,2DAA2D;AAC9D,6BAA6B,CAyF9B,CAAC"}
|
|
@@ -142,7 +142,7 @@ function transformNeedsToFields(needs) {
|
|
|
142
142
|
}
|
|
143
143
|
return rootFields;
|
|
144
144
|
}
|
|
145
|
-
export const listInputFieldsPlugin = ({ context }) => {
|
|
145
|
+
export const listInputFieldsPlugin = ({ sdk, context }) => {
|
|
146
146
|
const listInputFields = createPaginatedFunction(async function listInputFieldsPage(options) {
|
|
147
147
|
// Note: This function ignores pageSize and cursor since it's not actually paginated internally
|
|
148
148
|
const { api, getVersionedImplementationId } = context;
|
|
@@ -153,10 +153,15 @@ export const listInputFieldsPlugin = ({ context }) => {
|
|
|
153
153
|
if (!selectedApi) {
|
|
154
154
|
throw new ZapierConfigurationError("No current_implementation_id found for app", { configType: "current_implementation_id" });
|
|
155
155
|
}
|
|
156
|
+
const { data: action } = await sdk.getAction({
|
|
157
|
+
appKey,
|
|
158
|
+
actionType,
|
|
159
|
+
actionKey,
|
|
160
|
+
});
|
|
156
161
|
// Build needs request
|
|
157
162
|
const needsRequest = {
|
|
158
163
|
selected_api: selectedApi,
|
|
159
|
-
action:
|
|
164
|
+
action: action.key,
|
|
160
165
|
type_of: actionType,
|
|
161
166
|
params: inputs || {},
|
|
162
167
|
};
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
2
2
|
import { ZapierValidationError, ZapierConfigurationError, ZapierApiError, } from "../../types/errors";
|
|
3
3
|
import { listInputFieldsPlugin } from "./index";
|
|
4
|
+
import { getActionPlugin } from "../getAction";
|
|
5
|
+
import { getAppPlugin } from "../getApp";
|
|
6
|
+
import { listActionsPlugin } from "../listActions";
|
|
7
|
+
import { listAppsPlugin } from "../listApps";
|
|
4
8
|
import { createSdk } from "../../sdk";
|
|
5
9
|
const mockNeeds = [
|
|
6
10
|
{
|
|
@@ -35,12 +39,34 @@ const mockNeedsResponse = {
|
|
|
35
39
|
success: true,
|
|
36
40
|
needs: mockNeeds,
|
|
37
41
|
};
|
|
42
|
+
const mockActionsResponse = {
|
|
43
|
+
results: [
|
|
44
|
+
{
|
|
45
|
+
slug: "slack",
|
|
46
|
+
selected_api: "slack",
|
|
47
|
+
actions: [
|
|
48
|
+
{
|
|
49
|
+
key: "send_message",
|
|
50
|
+
name: "Send Message",
|
|
51
|
+
description: "Send a message to a channel",
|
|
52
|
+
type_of: "write",
|
|
53
|
+
type: "write",
|
|
54
|
+
id: "core:12345",
|
|
55
|
+
},
|
|
56
|
+
],
|
|
57
|
+
},
|
|
58
|
+
],
|
|
59
|
+
meta: {
|
|
60
|
+
next_cursor: null,
|
|
61
|
+
},
|
|
62
|
+
};
|
|
38
63
|
describe("listInputFields plugin", () => {
|
|
39
64
|
let mockApiClient;
|
|
40
65
|
let mockGetVersionedImplementationId;
|
|
41
66
|
beforeEach(() => {
|
|
42
67
|
vi.clearAllMocks();
|
|
43
68
|
mockApiClient = {
|
|
69
|
+
get: vi.fn().mockResolvedValue(mockActionsResponse),
|
|
44
70
|
post: vi.fn().mockResolvedValue(mockNeedsResponse),
|
|
45
71
|
};
|
|
46
72
|
mockGetVersionedImplementationId = vi
|
|
@@ -52,7 +78,12 @@ describe("listInputFields plugin", () => {
|
|
|
52
78
|
api: mockApiClient,
|
|
53
79
|
meta: {},
|
|
54
80
|
getVersionedImplementationId: mockGetVersionedImplementationId,
|
|
55
|
-
})
|
|
81
|
+
})
|
|
82
|
+
.addPlugin(listAppsPlugin)
|
|
83
|
+
.addPlugin(listActionsPlugin)
|
|
84
|
+
.addPlugin(getAppPlugin)
|
|
85
|
+
.addPlugin(getActionPlugin)
|
|
86
|
+
.addPlugin(listInputFieldsPlugin);
|
|
56
87
|
}
|
|
57
88
|
describe("schema validation", () => {
|
|
58
89
|
it("should throw validation error for missing required fields", () => {
|
|
@@ -255,19 +286,19 @@ describe("listInputFields plugin", () => {
|
|
|
255
286
|
it("should throw ZapierApiError when API response indicates failure", async () => {
|
|
256
287
|
mockApiClient.post = vi.fn().mockResolvedValue({
|
|
257
288
|
success: false,
|
|
258
|
-
errors: ["
|
|
289
|
+
errors: ["Authentication failed", "Invalid credentials"],
|
|
259
290
|
});
|
|
260
291
|
const sdk = createTestSdk();
|
|
261
292
|
await expect(sdk.listInputFields({
|
|
262
293
|
appKey: "slack",
|
|
263
294
|
actionType: "write",
|
|
264
|
-
actionKey: "
|
|
295
|
+
actionKey: "send_message", // Use valid action so we get to the POST call
|
|
265
296
|
})).rejects.toThrow(ZapierApiError);
|
|
266
297
|
await expect(sdk.listInputFields({
|
|
267
298
|
appKey: "slack",
|
|
268
299
|
actionType: "write",
|
|
269
|
-
actionKey: "
|
|
270
|
-
})).rejects.toThrow("Failed to get action fields:
|
|
300
|
+
actionKey: "send_message", // Use valid action so we get to the POST call
|
|
301
|
+
})).rejects.toThrow("Failed to get action fields: Authentication failed, Invalid credentials");
|
|
271
302
|
});
|
|
272
303
|
it("should handle API errors gracefully", async () => {
|
|
273
304
|
mockApiClient.post = vi
|
|
@@ -15,7 +15,7 @@ export declare const ListInputFieldsSchema: z.ZodObject<{
|
|
|
15
15
|
cursor: z.ZodOptional<z.ZodString>;
|
|
16
16
|
}, "strip", z.ZodTypeAny, {
|
|
17
17
|
appKey: string;
|
|
18
|
-
actionType: "filter" | "read" | "read_bulk" | "write" | "run" | "
|
|
18
|
+
actionType: "search" | "filter" | "read" | "read_bulk" | "write" | "run" | "search_or_write" | "search_and_write";
|
|
19
19
|
actionKey: string;
|
|
20
20
|
authenticationId?: number | null | undefined;
|
|
21
21
|
inputs?: Record<string, unknown> | undefined;
|
|
@@ -24,7 +24,7 @@ export declare const ListInputFieldsSchema: z.ZodObject<{
|
|
|
24
24
|
cursor?: string | undefined;
|
|
25
25
|
}, {
|
|
26
26
|
appKey: string;
|
|
27
|
-
actionType: "filter" | "read" | "read_bulk" | "write" | "run" | "
|
|
27
|
+
actionType: "search" | "filter" | "read" | "read_bulk" | "write" | "run" | "search_or_write" | "search_and_write";
|
|
28
28
|
actionKey: string;
|
|
29
29
|
authenticationId?: number | null | undefined;
|
|
30
30
|
inputs?: Record<string, unknown> | undefined;
|