@zapier/zapier-sdk 0.13.6 → 0.13.7

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 (114) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/index.cjs +1 -1
  3. package/dist/index.mjs +1 -1
  4. package/package.json +7 -2
  5. package/src/api/auth.ts +0 -28
  6. package/src/api/client.ts +0 -491
  7. package/src/api/debug.test.ts +0 -76
  8. package/src/api/debug.ts +0 -154
  9. package/src/api/index.ts +0 -90
  10. package/src/api/polling.test.ts +0 -405
  11. package/src/api/polling.ts +0 -253
  12. package/src/api/schemas.ts +0 -465
  13. package/src/api/types.ts +0 -152
  14. package/src/auth.ts +0 -72
  15. package/src/constants.ts +0 -16
  16. package/src/index.ts +0 -111
  17. package/src/plugins/api/index.ts +0 -43
  18. package/src/plugins/apps/index.ts +0 -203
  19. package/src/plugins/apps/schemas.ts +0 -64
  20. package/src/plugins/eventEmission/builders.ts +0 -115
  21. package/src/plugins/eventEmission/index.test.ts +0 -169
  22. package/src/plugins/eventEmission/index.ts +0 -294
  23. package/src/plugins/eventEmission/transport.test.ts +0 -214
  24. package/src/plugins/eventEmission/transport.ts +0 -135
  25. package/src/plugins/eventEmission/types.ts +0 -58
  26. package/src/plugins/eventEmission/utils.ts +0 -121
  27. package/src/plugins/fetch/index.ts +0 -83
  28. package/src/plugins/fetch/schemas.ts +0 -37
  29. package/src/plugins/findFirstAuthentication/index.test.ts +0 -209
  30. package/src/plugins/findFirstAuthentication/index.ts +0 -68
  31. package/src/plugins/findFirstAuthentication/schemas.ts +0 -47
  32. package/src/plugins/findUniqueAuthentication/index.test.ts +0 -197
  33. package/src/plugins/findUniqueAuthentication/index.ts +0 -77
  34. package/src/plugins/findUniqueAuthentication/schemas.ts +0 -49
  35. package/src/plugins/getAction/index.test.ts +0 -239
  36. package/src/plugins/getAction/index.ts +0 -75
  37. package/src/plugins/getAction/schemas.ts +0 -41
  38. package/src/plugins/getApp/index.test.ts +0 -181
  39. package/src/plugins/getApp/index.ts +0 -60
  40. package/src/plugins/getApp/schemas.ts +0 -33
  41. package/src/plugins/getAuthentication/index.test.ts +0 -294
  42. package/src/plugins/getAuthentication/index.ts +0 -95
  43. package/src/plugins/getAuthentication/schemas.ts +0 -38
  44. package/src/plugins/getProfile/index.ts +0 -60
  45. package/src/plugins/getProfile/schemas.ts +0 -24
  46. package/src/plugins/listActions/index.test.ts +0 -526
  47. package/src/plugins/listActions/index.ts +0 -132
  48. package/src/plugins/listActions/schemas.ts +0 -55
  49. package/src/plugins/listApps/index.test.ts +0 -378
  50. package/src/plugins/listApps/index.ts +0 -159
  51. package/src/plugins/listApps/schemas.ts +0 -41
  52. package/src/plugins/listAuthentications/index.test.ts +0 -739
  53. package/src/plugins/listAuthentications/index.ts +0 -152
  54. package/src/plugins/listAuthentications/schemas.ts +0 -77
  55. package/src/plugins/listInputFieldChoices/index.test.ts +0 -653
  56. package/src/plugins/listInputFieldChoices/index.ts +0 -173
  57. package/src/plugins/listInputFieldChoices/schemas.ts +0 -125
  58. package/src/plugins/listInputFields/index.test.ts +0 -439
  59. package/src/plugins/listInputFields/index.ts +0 -294
  60. package/src/plugins/listInputFields/schemas.ts +0 -68
  61. package/src/plugins/manifest/index.test.ts +0 -776
  62. package/src/plugins/manifest/index.ts +0 -461
  63. package/src/plugins/manifest/schemas.ts +0 -60
  64. package/src/plugins/registry/index.ts +0 -160
  65. package/src/plugins/request/index.test.ts +0 -333
  66. package/src/plugins/request/index.ts +0 -105
  67. package/src/plugins/request/schemas.ts +0 -69
  68. package/src/plugins/runAction/index.test.ts +0 -388
  69. package/src/plugins/runAction/index.ts +0 -215
  70. package/src/plugins/runAction/schemas.ts +0 -60
  71. package/src/resolvers/actionKey.ts +0 -37
  72. package/src/resolvers/actionType.ts +0 -34
  73. package/src/resolvers/appKey.ts +0 -7
  74. package/src/resolvers/authenticationId.ts +0 -54
  75. package/src/resolvers/index.ts +0 -11
  76. package/src/resolvers/inputFieldKey.ts +0 -70
  77. package/src/resolvers/inputs.ts +0 -69
  78. package/src/schemas/Action.ts +0 -52
  79. package/src/schemas/App.ts +0 -45
  80. package/src/schemas/Auth.ts +0 -59
  81. package/src/schemas/Field.ts +0 -169
  82. package/src/schemas/Run.ts +0 -40
  83. package/src/schemas/UserProfile.ts +0 -60
  84. package/src/sdk.test.ts +0 -212
  85. package/src/sdk.ts +0 -178
  86. package/src/types/domain.test.ts +0 -50
  87. package/src/types/domain.ts +0 -66
  88. package/src/types/errors.ts +0 -278
  89. package/src/types/events.ts +0 -43
  90. package/src/types/functions.ts +0 -28
  91. package/src/types/optional-zapier-sdk-cli-login.d.ts +0 -37
  92. package/src/types/plugin.ts +0 -125
  93. package/src/types/properties.ts +0 -80
  94. package/src/types/sdk.ts +0 -111
  95. package/src/types/telemetry-events.ts +0 -85
  96. package/src/utils/array-utils.test.ts +0 -131
  97. package/src/utils/array-utils.ts +0 -41
  98. package/src/utils/domain-utils.test.ts +0 -433
  99. package/src/utils/domain-utils.ts +0 -267
  100. package/src/utils/file-utils.test.ts +0 -73
  101. package/src/utils/file-utils.ts +0 -94
  102. package/src/utils/function-utils.test.ts +0 -141
  103. package/src/utils/function-utils.ts +0 -245
  104. package/src/utils/pagination-utils.test.ts +0 -620
  105. package/src/utils/pagination-utils.ts +0 -242
  106. package/src/utils/schema-utils.ts +0 -207
  107. package/src/utils/string-utils.test.ts +0 -45
  108. package/src/utils/string-utils.ts +0 -54
  109. package/src/utils/validation.test.ts +0 -51
  110. package/src/utils/validation.ts +0 -44
  111. package/tsconfig.build.json +0 -18
  112. package/tsconfig.json +0 -20
  113. package/tsconfig.tsbuildinfo +0 -1
  114. package/tsup.config.ts +0 -23
@@ -1,214 +0,0 @@
1
- /**
2
- * Tests for Event Transport Layer
3
- */
4
-
5
- import { describe, it, expect, vi, beforeEach } from "vitest";
6
- import {
7
- HttpTransport,
8
- ConsoleTransport,
9
- NoopTransport,
10
- createTransport,
11
- } from "./transport";
12
- import type { TelemetryEvent } from "../../types/telemetry-events";
13
-
14
- // Mock fetch globally
15
- const mockFetch = vi.fn();
16
- global.fetch = mockFetch;
17
-
18
- // Mock console.log
19
- const mockConsoleLog = vi.spyOn(console, "log").mockImplementation(() => {});
20
-
21
- describe("Transport Layer", () => {
22
- const sampleEvent: TelemetryEvent = {
23
- event_id: "test-123",
24
- timestamp_ms: Date.now(),
25
- release_id: "test-release",
26
- error_message: "Test error",
27
- is_user_facing: false,
28
- } as any;
29
-
30
- const sampleSubject = "platform.sdk.ErrorOccurredEvent";
31
-
32
- beforeEach(() => {
33
- vi.clearAllMocks();
34
- });
35
-
36
- describe("HttpTransport", () => {
37
- it("should emit events via HTTP successfully", async () => {
38
- mockFetch.mockResolvedValueOnce({
39
- ok: true,
40
- status: 200,
41
- });
42
-
43
- const transport = new HttpTransport({
44
- endpoint: "https://telemetry.example.com/events",
45
- headers: { "x-api-key": "test-key" },
46
- });
47
-
48
- await transport.emit(sampleSubject, sampleEvent);
49
-
50
- expect(mockFetch).toHaveBeenCalledWith(
51
- "https://telemetry.example.com/events",
52
- {
53
- method: "POST",
54
- headers: {
55
- "Content-Type": "application/json",
56
- "x-api-key": "test-key",
57
- },
58
- body: JSON.stringify({
59
- subject: sampleSubject,
60
- properties: sampleEvent,
61
- }),
62
- },
63
- );
64
- });
65
-
66
- it("should retry on HTTP failures", async () => {
67
- // Fail twice, then succeed
68
- mockFetch
69
- .mockResolvedValueOnce({ ok: false, status: 500 })
70
- .mockResolvedValueOnce({ ok: false, status: 500 })
71
- .mockResolvedValueOnce({ ok: true, status: 200 });
72
-
73
- const transport = new HttpTransport({
74
- endpoint: "https://telemetry.example.com/events",
75
- retryAttempts: 3,
76
- retryDelayMs: 10, // Short delay for testing
77
- });
78
-
79
- await transport.emit(sampleSubject, sampleEvent);
80
-
81
- expect(mockFetch).toHaveBeenCalledTimes(3);
82
- });
83
-
84
- it("should handle network errors silently", async () => {
85
- mockFetch.mockRejectedValue(new Error("Network error"));
86
-
87
- const transport = new HttpTransport({
88
- endpoint: "https://telemetry.example.com/events",
89
- retryAttempts: 1,
90
- retryDelayMs: 1,
91
- });
92
-
93
- // Should not throw despite network error
94
- await expect(
95
- transport.emit(sampleSubject, sampleEvent),
96
- ).resolves.toBeUndefined();
97
- });
98
-
99
- it("should stop retrying after max attempts", async () => {
100
- mockFetch.mockResolvedValue({ ok: false, status: 500 });
101
-
102
- const transport = new HttpTransport({
103
- endpoint: "https://telemetry.example.com/events",
104
- retryAttempts: 2,
105
- retryDelayMs: 1,
106
- });
107
-
108
- await transport.emit(sampleSubject, sampleEvent);
109
-
110
- expect(mockFetch).toHaveBeenCalledTimes(2);
111
- });
112
- });
113
-
114
- describe("ConsoleTransport", () => {
115
- it("should log events to console", async () => {
116
- const transport = new ConsoleTransport();
117
-
118
- await transport.emit(sampleSubject, sampleEvent);
119
-
120
- expect(mockConsoleLog).toHaveBeenCalledWith(
121
- "[SDK Telemetry]",
122
- JSON.stringify(
123
- { subject: sampleSubject, properties: sampleEvent },
124
- null,
125
- 2,
126
- ),
127
- );
128
- });
129
-
130
- it("should handle console errors silently", async () => {
131
- mockConsoleLog.mockImplementation(() => {
132
- throw new Error("Console error");
133
- });
134
-
135
- const transport = new ConsoleTransport();
136
-
137
- // Should not throw despite console error
138
- await expect(
139
- transport.emit(sampleSubject, sampleEvent),
140
- ).resolves.toBeUndefined();
141
- });
142
- });
143
-
144
- describe("NoopTransport", () => {
145
- it("should do nothing when emitting events", async () => {
146
- const transport = new NoopTransport();
147
-
148
- await transport.emit(sampleSubject, sampleEvent);
149
-
150
- // Verify no side effects
151
- expect(mockFetch).not.toHaveBeenCalled();
152
- expect(mockConsoleLog).not.toHaveBeenCalled();
153
- });
154
- });
155
-
156
- describe("createTransport", () => {
157
- it("should create HTTP transport with valid config", () => {
158
- const transport = createTransport({
159
- type: "http",
160
- endpoint: "https://example.com",
161
- headers: { "x-key": "value" },
162
- retryAttempts: 5,
163
- retryDelayMs: 2000,
164
- });
165
-
166
- expect(transport).toBeInstanceOf(HttpTransport);
167
- });
168
-
169
- it("should create console transport", () => {
170
- const transport = createTransport({
171
- type: "console",
172
- });
173
-
174
- expect(transport).toBeInstanceOf(ConsoleTransport);
175
- });
176
-
177
- it("should create noop transport by default", () => {
178
- const transport = createTransport({
179
- type: "noop",
180
- });
181
-
182
- expect(transport).toBeInstanceOf(NoopTransport);
183
- });
184
-
185
- it("should fallback to noop transport on invalid HTTP config", () => {
186
- const transport = createTransport({
187
- type: "http",
188
- // Missing endpoint
189
- });
190
-
191
- expect(transport).toBeInstanceOf(NoopTransport);
192
- });
193
-
194
- it("should fallback to noop transport on unknown type", () => {
195
- const transport = createTransport({
196
- type: "unknown" as any,
197
- });
198
-
199
- expect(transport).toBeInstanceOf(NoopTransport);
200
- });
201
-
202
- it("should handle transport creation errors gracefully", () => {
203
- // Since createTransport already handles errors internally,
204
- // this test verifies that invalid configs don't throw
205
- expect(() => {
206
- const transport = createTransport({
207
- type: "http" as const,
208
- // Missing required endpoint - should fallback to noop
209
- });
210
- expect(transport).toBeInstanceOf(NoopTransport);
211
- }).not.toThrow();
212
- });
213
- });
214
- });
@@ -1,135 +0,0 @@
1
- /**
2
- * Transport abstraction layer for event emission
3
- *
4
- * Provides configurable transport mechanisms for emitting telemetry events.
5
- * All transports implement silent failure to prevent SDK disruption.
6
- */
7
-
8
- // Constants for transport configuration
9
- const DEFAULT_RETRY_ATTEMPTS = 2;
10
- const DEFAULT_RETRY_DELAY_MS = 300;
11
-
12
- // Transport interface - all implementations must be async and silent
13
- export interface EventTransport {
14
- emit<T extends any>(subject: string, event: T): Promise<void>;
15
- close?(): Promise<void>;
16
- }
17
-
18
- // Transport configuration
19
- export interface TransportConfig {
20
- type: "http" | "console" | "noop";
21
- endpoint?: string;
22
- headers?: Record<string, string>;
23
- retryAttempts?: number;
24
- retryDelayMs?: number;
25
- }
26
-
27
- // HTTP Transport - sends events to remote endpoint
28
- export class HttpTransport implements EventTransport {
29
- constructor(
30
- private config: {
31
- endpoint: string;
32
- headers?: Record<string, string>;
33
- retryAttempts?: number;
34
- retryDelayMs?: number;
35
- },
36
- ) {}
37
-
38
- async emit<T extends any>(subject: string, event: T): Promise<void> {
39
- try {
40
- await this.emitWithRetry(
41
- subject,
42
- event,
43
- this.config.retryAttempts || DEFAULT_RETRY_ATTEMPTS,
44
- );
45
- } catch {
46
- // Silent failure - never throw
47
- }
48
- }
49
-
50
- private async emitWithRetry<T extends any>(
51
- subject: string,
52
- event: T,
53
- attemptsLeft: number,
54
- ): Promise<void> {
55
- try {
56
- const payload = {
57
- subject,
58
- properties: event,
59
- };
60
-
61
- const response = await fetch(this.config.endpoint, {
62
- method: "POST",
63
- headers: {
64
- "Content-Type": "application/json",
65
- ...this.config.headers,
66
- },
67
- body: JSON.stringify(payload),
68
- });
69
-
70
- if (!response.ok && attemptsLeft > 1) {
71
- await this.delay(this.config.retryDelayMs || DEFAULT_RETRY_DELAY_MS);
72
- return this.emitWithRetry(subject, event, attemptsLeft - 1);
73
- }
74
- } catch (error) {
75
- if (attemptsLeft > 1) {
76
- await this.delay(this.config.retryDelayMs || DEFAULT_RETRY_DELAY_MS);
77
- return this.emitWithRetry(subject, event, attemptsLeft - 1);
78
- }
79
- throw error;
80
- }
81
- }
82
-
83
- private async delay(ms: number): Promise<void> {
84
- return new Promise((resolve) => setTimeout(resolve, ms));
85
- }
86
- }
87
-
88
- // Console Transport - logs events to console (for development)
89
- export class ConsoleTransport implements EventTransport {
90
- async emit<T extends any>(subject: string, event: T): Promise<void> {
91
- try {
92
- console.log(
93
- "[SDK Telemetry]",
94
- JSON.stringify({ subject, properties: event }, null, 2),
95
- );
96
- } catch {
97
- // Silent failure - never throw
98
- }
99
- }
100
- }
101
-
102
- // No-op Transport - discards all events (for testing/disabled state)
103
- export class NoopTransport implements EventTransport {
104
- async emit<T extends any>(_subject: string, _event: T): Promise<void> {
105
- // Intentionally do nothing
106
- }
107
- }
108
-
109
- // Transport factory
110
- export function createTransport(config: TransportConfig): EventTransport {
111
- try {
112
- switch (config.type) {
113
- case "http":
114
- if (!config.endpoint) {
115
- throw new Error("HTTP transport requires endpoint");
116
- }
117
- return new HttpTransport({
118
- endpoint: config.endpoint,
119
- headers: config.headers,
120
- retryAttempts: config.retryAttempts,
121
- retryDelayMs: config.retryDelayMs,
122
- });
123
-
124
- case "console":
125
- return new ConsoleTransport();
126
-
127
- case "noop":
128
- default:
129
- return new NoopTransport();
130
- }
131
- } catch {
132
- // If transport creation fails, return noop to maintain silent operation
133
- return new NoopTransport();
134
- }
135
- }
@@ -1,58 +0,0 @@
1
- // Common context that can be injected into events
2
- export interface EventContext {
3
- customuser_id?: number | null;
4
- account_id?: number | null;
5
- identity_id?: number | null;
6
- visitor_id?: string | null;
7
- correlation_id?: string | null;
8
- selected_api?: string | null;
9
- app_id?: number | null;
10
- app_version_id?: number | null;
11
- zap_id?: number | null;
12
- node_id?: number | null;
13
- environment?: string | null;
14
- sdk_version?: string | null;
15
- operation_type?: string | null;
16
- }
17
-
18
- export interface ErrorEventData {
19
- error_message: string;
20
- is_user_facing: boolean;
21
- error_type?: string | null;
22
- error_status_code?: number | null;
23
- error_stack_trace?: string | null;
24
- error_source_method?: string | null;
25
- error_source_file?: string | null;
26
- error_line_number?: number | null;
27
- operation_type?: string | null;
28
- operation_key?: string | null;
29
- error_severity?: string | null;
30
- is_recoverable?: boolean | null;
31
- error_metadata?: Record<string, string | null> | null;
32
- parent_error_id?: string | null;
33
- error_occurred_timestamp_ms?: number | null;
34
- error_code?: string | null;
35
- recovery_attempted?: boolean | null;
36
- recovery_action?: string | null;
37
- recovery_successful?: boolean | null;
38
- execution_time_before_error_ms?: number | null;
39
- }
40
-
41
- // Enhanced Error Event Builder with runtime context
42
- export interface EnhancedErrorEventData extends ErrorEventData {
43
- execution_start_time?: number | null;
44
- }
45
-
46
- export interface ApplicationLifecycleEventData {
47
- lifecycle_event_type: "startup" | "exit" | "signal_termination";
48
- exit_code?: number | null;
49
- signal_name?: string | null;
50
- uptime_ms?: number | null;
51
- is_graceful_shutdown?: boolean | null;
52
- shutdown_duration_ms?: number | null;
53
- // Allow overriding auto-gathered system info if needed
54
- memory_usage_bytes?: number | null;
55
- peak_memory_usage_bytes?: number | null;
56
- cpu_time_ms?: number | null;
57
- active_requests_count?: number | null;
58
- }
@@ -1,121 +0,0 @@
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
- }
@@ -1,83 +0,0 @@
1
- import type { RelayRequestOptions } from "../request/schemas";
2
- import type { Plugin, GetSdkType } from "../../types/plugin";
3
- import type { RequestPluginProvides } from "../request";
4
- import { FetchUrlSchema, FetchInitSchema } from "./schemas";
5
- import type { z } from "zod";
6
-
7
- export interface FetchPluginProvides {
8
- fetch: (
9
- url: string | URL,
10
- init?: RequestInit & {
11
- authenticationId?: number;
12
- callbackUrl?: string;
13
- authenticationTemplate?: string;
14
- },
15
- ) => Promise<Response>;
16
- context: {
17
- meta: {
18
- fetch: {
19
- packages: string[];
20
- categories: string[];
21
- returnType: string;
22
- inputParameters: Array<{ name: string; schema: z.ZodSchema }>;
23
- };
24
- };
25
- };
26
- }
27
-
28
- /**
29
- * Direct plugin function - takes options + sdk + context in one object
30
- */
31
- export const fetchPlugin: Plugin<
32
- GetSdkType<RequestPluginProvides>, // requires request in SDK
33
- {}, // requires no context (uses SDK methods)
34
- FetchPluginProvides
35
- > = ({ sdk }) => {
36
- // Return flat structure - fetch goes directly to SDK
37
- return {
38
- fetch: async function fetch(
39
- url: string | URL,
40
- init?: RequestInit & {
41
- authenticationId?: number;
42
- callbackUrl?: string;
43
- authenticationTemplate?: string;
44
- },
45
- ): Promise<Response> {
46
- const {
47
- authenticationId,
48
- callbackUrl,
49
- authenticationTemplate,
50
- ...fetchInit
51
- } = init || {};
52
-
53
- return sdk.request({
54
- url: url.toString(),
55
- method: fetchInit.method as RelayRequestOptions["method"],
56
- body: fetchInit.body,
57
- headers: fetchInit.headers,
58
- authenticationId,
59
- callbackUrl,
60
- authenticationTemplate,
61
- });
62
- },
63
- context: {
64
- meta: {
65
- fetch: {
66
- packages: ["sdk"],
67
- categories: ["http"],
68
- returnType: "Response",
69
- inputParameters: [
70
- { name: "url", schema: FetchUrlSchema },
71
- { name: "init", schema: FetchInitSchema },
72
- ],
73
- },
74
- },
75
- },
76
- };
77
- };
78
-
79
- export type ZapierFetchInitOptions = RequestInit & {
80
- authenticationId?: number;
81
- callbackUrl?: string;
82
- authenticationTemplate?: string;
83
- };
@@ -1,37 +0,0 @@
1
- import { z } from "zod";
2
-
3
- // Schemas for fetch function parameters
4
- export const FetchUrlSchema = z
5
- .union([z.string(), z.instanceof(URL)])
6
- .describe("The URL to fetch");
7
-
8
- export const FetchInitSchema = z
9
- .object({
10
- method: z
11
- .enum(["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS"])
12
- .optional(),
13
- headers: z.record(z.string()).optional(),
14
- body: z
15
- .union([
16
- z.string(),
17
- z.instanceof(FormData),
18
- z.instanceof(URLSearchParams),
19
- ])
20
- .optional(),
21
- authenticationId: z
22
- .number()
23
- .optional()
24
- .describe("Zapier authentication ID to use for the request"),
25
- callbackUrl: z
26
- .string()
27
- .optional()
28
- .describe("URL to send async response to (makes request async)"),
29
- authenticationTemplate: z
30
- .string()
31
- .optional()
32
- .describe(
33
- "Optional JSON string authentication template to bypass Notary lookup",
34
- ),
35
- })
36
- .optional()
37
- .describe("Fetch options including authentication");