@zapier/zapier-sdk 0.0.3 → 0.1.0
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/dist/api/auth.d.ts +8 -0
- package/dist/api/auth.js +29 -0
- package/dist/api/client.d.ts +8 -0
- package/dist/api/client.js +102 -0
- package/dist/api/debug.d.ts +12 -0
- package/dist/api/debug.js +50 -0
- package/dist/api/index.d.ts +26 -0
- package/dist/api/index.js +51 -0
- package/dist/api/polling.d.ts +17 -0
- package/dist/api/polling.js +34 -0
- package/dist/{types.d.ts → api/types.d.ts} +37 -88
- package/dist/api/types.js +9 -0
- package/dist/functions/{bundleCode.d.ts → bundleCode/index.d.ts} +1 -8
- package/dist/functions/bundleCode/info.d.ts +27 -0
- package/dist/functions/bundleCode/info.js +11 -0
- package/dist/functions/bundleCode/schemas.d.ts +27 -0
- package/dist/functions/bundleCode/schemas.js +22 -0
- package/dist/functions/{generateTypes.d.ts → generateTypes/index.d.ts} +2 -7
- package/dist/functions/{generateTypes.js → generateTypes/index.js} +58 -24
- package/dist/functions/generateTypes/info.d.ts +21 -0
- package/dist/functions/generateTypes/info.js +11 -0
- package/dist/functions/generateTypes/schemas.d.ts +30 -0
- package/dist/functions/generateTypes/schemas.js +14 -0
- package/dist/functions/{getAction.d.ts → getAction/index.d.ts} +2 -6
- package/dist/functions/{getAction.js → getAction/index.js} +6 -5
- package/dist/functions/getAction/info.d.ts +18 -0
- package/dist/functions/getAction/info.js +11 -0
- package/dist/functions/getAction/schemas.d.ts +30 -0
- package/dist/functions/getAction/schemas.js +13 -0
- package/dist/functions/{getApp.d.ts → getApp/index.d.ts} +2 -4
- package/dist/functions/{getApp.js → getApp/index.js} +6 -10
- package/dist/functions/getApp/info.d.ts +12 -0
- package/dist/functions/getApp/info.js +11 -0
- package/dist/functions/getApp/schemas.d.ts +24 -0
- package/dist/functions/getApp/schemas.js +11 -0
- package/dist/functions/{listActions.d.ts → listActions/index.d.ts} +3 -6
- package/dist/functions/{listActions.js → listActions/index.js} +4 -3
- package/dist/functions/listActions/info.d.ts +15 -0
- package/dist/functions/listActions/info.js +11 -0
- package/dist/functions/listActions/schemas.d.ts +27 -0
- package/dist/functions/listActions/schemas.js +14 -0
- package/dist/functions/{listApps.d.ts → listApps/index.d.ts} +2 -6
- package/dist/functions/{listApps.js → listApps/index.js} +1 -1
- package/dist/functions/listApps/info.d.ts +18 -0
- package/dist/functions/listApps/info.js +11 -0
- package/dist/functions/listApps/schemas.d.ts +30 -0
- package/dist/functions/listApps/schemas.js +15 -0
- package/dist/functions/{listAuths.d.ts → listAuths/index.d.ts} +3 -9
- package/dist/functions/{listAuths.js → listAuths/index.js} +5 -5
- package/dist/functions/listAuths/info.d.ts +24 -0
- package/dist/functions/listAuths/info.js +11 -0
- package/dist/functions/listAuths/schemas.d.ts +36 -0
- package/dist/functions/listAuths/schemas.js +17 -0
- package/dist/functions/{listFields.d.ts → listFields/index.d.ts} +3 -9
- package/dist/functions/{listFields.js → listFields/index.js} +8 -10
- package/dist/functions/listFields/info.d.ts +24 -0
- package/dist/functions/listFields/info.js +11 -0
- package/dist/functions/listFields/schemas.d.ts +36 -0
- package/dist/functions/listFields/schemas.js +17 -0
- package/dist/functions/{runAction.d.ts → runAction/index.d.ts} +2 -8
- package/dist/functions/{runAction.js → runAction/index.js} +15 -14
- package/dist/functions/runAction/info.d.ts +24 -0
- package/dist/functions/runAction/info.js +11 -0
- package/dist/functions/runAction/schemas.d.ts +36 -0
- package/dist/functions/runAction/schemas.js +15 -0
- package/dist/index.d.ts +6 -3
- package/dist/index.js +7 -3
- package/dist/plugins/apps/index.d.ts +8 -0
- package/dist/plugins/apps/index.js +77 -0
- package/dist/plugins/apps/info.d.ts +6 -0
- package/dist/plugins/apps/info.js +13 -0
- package/dist/plugins/apps/types.d.ts +21 -0
- package/dist/plugins/apps/types.js +2 -0
- package/dist/resolvers/actionKey.d.ts +8 -0
- package/dist/resolvers/actionKey.js +20 -0
- package/dist/resolvers/actionType.d.ts +8 -0
- package/dist/resolvers/actionType.js +21 -0
- package/dist/resolvers/appKey.d.ts +6 -0
- package/dist/resolvers/appKey.js +8 -0
- package/dist/resolvers/authenticationId.d.ts +8 -0
- package/dist/resolvers/authenticationId.js +29 -0
- package/dist/resolvers/index.d.ts +39 -0
- package/dist/resolvers/index.js +105 -0
- package/dist/resolvers/inputs.d.ts +7 -0
- package/dist/resolvers/inputs.js +15 -0
- package/dist/schema-utils.d.ts +39 -0
- package/dist/schema-utils.js +52 -0
- package/dist/schemas/Action.d.ts +21 -0
- package/dist/schemas/Action.js +31 -0
- package/dist/schemas/App.d.ts +19 -0
- package/dist/schemas/App.js +32 -0
- package/dist/schemas/Auth.d.ts +30 -0
- package/dist/schemas/Auth.js +49 -0
- package/dist/schemas/Field.d.ts +15 -0
- package/dist/schemas/Field.js +25 -0
- package/dist/sdk.d.ts +3 -4
- package/dist/sdk.js +96 -11
- package/dist/types/domain.d.ts +22 -0
- package/dist/types/domain.js +21 -0
- package/dist/types/properties.d.ts +21 -0
- package/dist/types/properties.js +45 -0
- package/dist/types/sdk.d.ts +21 -0
- package/dist/types/sdk.js +2 -0
- package/package.json +4 -2
- package/src/api/auth.ts +28 -0
- package/src/api/client.ts +148 -0
- package/src/api/debug.ts +58 -0
- package/src/api/index.ts +83 -0
- package/src/api/polling.ts +56 -0
- package/src/api/types.ts +177 -0
- package/src/functions/{bundleCode.ts → bundleCode/index.ts} +1 -8
- package/src/functions/bundleCode/info.ts +9 -0
- package/src/functions/bundleCode/schemas.ts +30 -0
- package/src/functions/{generateTypes.ts → generateTypes/index.ts} +70 -31
- package/src/functions/generateTypes/info.ts +9 -0
- package/src/functions/generateTypes/schemas.ts +38 -0
- package/src/functions/{getAction.ts → getAction/index.ts} +11 -12
- package/src/functions/getAction/info.ts +9 -0
- package/src/functions/getAction/schemas.ts +35 -0
- package/src/functions/{getApp.ts → getApp/index.ts} +9 -15
- package/src/functions/getApp/info.ts +9 -0
- package/src/functions/getApp/schemas.ts +31 -0
- package/src/functions/{listActions.ts → listActions/index.ts} +8 -10
- package/src/functions/listActions/info.ts +9 -0
- package/src/functions/listActions/schemas.ts +40 -0
- package/src/functions/{listApps.ts → listApps/index.ts} +3 -8
- package/src/functions/listApps/info.ts +9 -0
- package/src/functions/listApps/schemas.ts +43 -0
- package/src/functions/{listAuths.ts → listAuths/index.ts} +8 -16
- package/src/functions/listAuths/info.ts +9 -0
- package/src/functions/listAuths/schemas.ts +48 -0
- package/src/functions/{listFields.ts → listFields/index.ts} +11 -20
- package/src/functions/listFields/info.ts +9 -0
- package/src/functions/listFields/schemas.ts +46 -0
- package/src/functions/{runAction.ts → runAction/index.ts} +25 -23
- package/src/functions/runAction/info.ts +9 -0
- package/src/functions/runAction/schemas.ts +41 -0
- package/src/index.ts +13 -4
- package/src/plugins/apps/index.ts +144 -0
- package/src/plugins/apps/info.ts +12 -0
- package/src/plugins/apps/types.ts +34 -0
- package/src/resolvers/actionKey.ts +33 -0
- package/src/resolvers/actionType.ts +30 -0
- package/src/resolvers/appKey.ts +11 -0
- package/src/resolvers/authenticationId.ts +38 -0
- package/src/resolvers/index.ts +117 -0
- package/src/resolvers/inputs.ts +23 -0
- package/src/schema-utils.ts +119 -0
- package/src/schemas/Action.ts +40 -0
- package/src/schemas/App.ts +43 -0
- package/src/schemas/Auth.ts +62 -0
- package/src/schemas/Field.ts +34 -0
- package/src/sdk.ts +153 -19
- package/src/types/domain.ts +54 -0
- package/src/types/properties.ts +67 -0
- package/src/types/sdk.ts +42 -0
- package/dist/actions-sdk.d.ts +0 -47
- package/dist/actions-sdk.js +0 -208
- package/dist/api.d.ts +0 -62
- package/dist/api.js +0 -227
- package/dist/output-schemas.d.ts +0 -95
- package/dist/output-schemas.js +0 -138
- package/dist/schemas.d.ts +0 -338
- package/dist/schemas.js +0 -336
- package/dist/types.js +0 -41
- package/src/actions-sdk.ts +0 -356
- package/src/api.ts +0 -361
- package/src/output-schemas.ts +0 -196
- package/src/schemas.ts +0 -467
- package/src/types.ts +0 -257
- /package/dist/functions/{bundleCode.js → bundleCode/index.js} +0 -0
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Authentication Utilities
|
|
3
|
+
*
|
|
4
|
+
* This module provides utilities for handling authentication tokens,
|
|
5
|
+
* including JWT detection and authorization header generation.
|
|
6
|
+
*/
|
|
7
|
+
export declare function isJwt(token: string): boolean;
|
|
8
|
+
export declare function getAuthorizationHeader(token: string): string;
|
package/dist/api/auth.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Authentication Utilities
|
|
4
|
+
*
|
|
5
|
+
* This module provides utilities for handling authentication tokens,
|
|
6
|
+
* including JWT detection and authorization header generation.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.isJwt = isJwt;
|
|
10
|
+
exports.getAuthorizationHeader = getAuthorizationHeader;
|
|
11
|
+
function isJwt(token) {
|
|
12
|
+
// JWT tokens have exactly 3 parts separated by dots
|
|
13
|
+
const parts = token.split(".");
|
|
14
|
+
if (parts.length !== 3) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
// Each part should be base64url encoded (no padding)
|
|
18
|
+
// Basic validation - each part should be non-empty and contain valid base64url characters
|
|
19
|
+
const base64UrlPattern = /^[A-Za-z0-9_-]+$/;
|
|
20
|
+
return parts.every((part) => part.length > 0 && base64UrlPattern.test(part));
|
|
21
|
+
}
|
|
22
|
+
function getAuthorizationHeader(token) {
|
|
23
|
+
// Check if token is a JWT (has 3 parts separated by dots)
|
|
24
|
+
if (isJwt(token)) {
|
|
25
|
+
return `JWT ${token}`;
|
|
26
|
+
}
|
|
27
|
+
// Default to Bearer for other token types
|
|
28
|
+
return `Bearer ${token}`;
|
|
29
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* API Client Implementation
|
|
3
|
+
*
|
|
4
|
+
* This module contains the core API client implementation, including
|
|
5
|
+
* HTTP method handlers, response processing, and client factory functions.
|
|
6
|
+
*/
|
|
7
|
+
import type { ApiClient, ApiClientOptions } from "./types";
|
|
8
|
+
export declare function createZapierApi(options: ApiClientOptions): ApiClient;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* API Client Implementation
|
|
4
|
+
*
|
|
5
|
+
* This module contains the core API client implementation, including
|
|
6
|
+
* HTTP method handlers, response processing, and client factory functions.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.createZapierApi = createZapierApi;
|
|
10
|
+
const auth_1 = require("./auth");
|
|
11
|
+
const debug_1 = require("./debug");
|
|
12
|
+
const polling_1 = require("./polling");
|
|
13
|
+
function createZapierApi(options) {
|
|
14
|
+
const { baseUrl, token, debug = false, fetch: originalFetch = globalThis.fetch, } = options;
|
|
15
|
+
const debugLog = (0, debug_1.createDebugLogger)(debug);
|
|
16
|
+
const fetch = (0, debug_1.createDebugFetch)({ originalFetch, debugLog });
|
|
17
|
+
// Helper to build full URLs
|
|
18
|
+
function buildUrl(path, searchParams) {
|
|
19
|
+
const url = new URL(path, baseUrl);
|
|
20
|
+
if (searchParams) {
|
|
21
|
+
Object.entries(searchParams).forEach(([key, value]) => {
|
|
22
|
+
url.searchParams.set(key, value);
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
return url.toString();
|
|
26
|
+
}
|
|
27
|
+
// Helper to build headers
|
|
28
|
+
function buildHeaders(options = {}) {
|
|
29
|
+
const headers = {
|
|
30
|
+
...options.headers,
|
|
31
|
+
};
|
|
32
|
+
// Add auth header if token provided and not explicitly disabled
|
|
33
|
+
if (token && options.authRequired !== false) {
|
|
34
|
+
headers.Authorization = (0, auth_1.getAuthorizationHeader)(token);
|
|
35
|
+
}
|
|
36
|
+
return headers;
|
|
37
|
+
}
|
|
38
|
+
// Helper to handle responses
|
|
39
|
+
async function handleResponse(response, customErrorHandler) {
|
|
40
|
+
if (!response.ok) {
|
|
41
|
+
// Check for custom error handling first
|
|
42
|
+
if (customErrorHandler) {
|
|
43
|
+
const customError = customErrorHandler(response);
|
|
44
|
+
if (customError) {
|
|
45
|
+
throw customError;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
|
|
49
|
+
}
|
|
50
|
+
// Try to parse JSON, fall back to text if that fails
|
|
51
|
+
try {
|
|
52
|
+
return await response.json();
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
return await response.text();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
// Helper to perform HTTP requests with JSON handling
|
|
59
|
+
async function fetchJson(method, path, data, options = {}) {
|
|
60
|
+
const url = buildUrl(path, options.searchParams);
|
|
61
|
+
const headers = buildHeaders(options);
|
|
62
|
+
// Add Content-Type for JSON requests with body data
|
|
63
|
+
if (data && typeof data === "object") {
|
|
64
|
+
headers["Content-Type"] = "application/json";
|
|
65
|
+
}
|
|
66
|
+
const response = await fetch(url, {
|
|
67
|
+
method,
|
|
68
|
+
headers,
|
|
69
|
+
body: data ? JSON.stringify(data) : undefined,
|
|
70
|
+
});
|
|
71
|
+
return handleResponse(response, options.customErrorHandler);
|
|
72
|
+
}
|
|
73
|
+
return {
|
|
74
|
+
async get(path, options = {}) {
|
|
75
|
+
return fetchJson("GET", path, undefined, options);
|
|
76
|
+
},
|
|
77
|
+
async post(path, data, options = {}) {
|
|
78
|
+
return fetchJson("POST", path, data, options);
|
|
79
|
+
},
|
|
80
|
+
async put(path, data, options = {}) {
|
|
81
|
+
return fetchJson("PUT", path, data, options);
|
|
82
|
+
},
|
|
83
|
+
async delete(path, options = {}) {
|
|
84
|
+
return fetchJson("DELETE", path, undefined, options);
|
|
85
|
+
},
|
|
86
|
+
async poll(path, options = {}) {
|
|
87
|
+
const url = buildUrl(path, options.searchParams);
|
|
88
|
+
const headers = buildHeaders(options);
|
|
89
|
+
return (0, polling_1.pollUntilComplete)({
|
|
90
|
+
fetch,
|
|
91
|
+
url,
|
|
92
|
+
headers,
|
|
93
|
+
maxAttempts: options.maxAttempts,
|
|
94
|
+
initialDelay: options.initialDelay,
|
|
95
|
+
maxDelay: options.maxDelay,
|
|
96
|
+
successStatus: options.successStatus,
|
|
97
|
+
pendingStatus: options.pendingStatus,
|
|
98
|
+
resultExtractor: options.resultExtractor,
|
|
99
|
+
});
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Debug Logging Utilities
|
|
3
|
+
*
|
|
4
|
+
* This module provides debug logging capabilities for API requests and responses,
|
|
5
|
+
* including request timing and detailed logging of HTTP interactions.
|
|
6
|
+
*/
|
|
7
|
+
import type { DebugLogger } from "./types";
|
|
8
|
+
export declare function createDebugLogger(enabled: boolean): DebugLogger;
|
|
9
|
+
export declare function createDebugFetch(options: {
|
|
10
|
+
originalFetch: typeof globalThis.fetch;
|
|
11
|
+
debugLog: DebugLogger;
|
|
12
|
+
}): (input: RequestInfo | URL, options?: RequestInit) => Promise<Response>;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Debug Logging Utilities
|
|
4
|
+
*
|
|
5
|
+
* This module provides debug logging capabilities for API requests and responses,
|
|
6
|
+
* including request timing and detailed logging of HTTP interactions.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.createDebugLogger = createDebugLogger;
|
|
10
|
+
exports.createDebugFetch = createDebugFetch;
|
|
11
|
+
function createDebugLogger(enabled) {
|
|
12
|
+
if (!enabled) {
|
|
13
|
+
return () => { }; // No-op function when debug is disabled
|
|
14
|
+
}
|
|
15
|
+
return (message, data) => {
|
|
16
|
+
console.log(`[Zapier SDK] ${message}`, data || "");
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
function createDebugFetch(options) {
|
|
20
|
+
const { originalFetch, debugLog } = options;
|
|
21
|
+
return async (input, options) => {
|
|
22
|
+
const startTime = Date.now();
|
|
23
|
+
// Convert input to URL string for logging
|
|
24
|
+
const url = typeof input === "string" ? input : input.toString();
|
|
25
|
+
const method = options?.method || "GET";
|
|
26
|
+
debugLog(`→ ${method} ${url}`, {
|
|
27
|
+
headers: options?.headers,
|
|
28
|
+
body: options?.body ? JSON.parse(options.body) : undefined,
|
|
29
|
+
});
|
|
30
|
+
try {
|
|
31
|
+
const response = await originalFetch(input, options);
|
|
32
|
+
const duration = Date.now() - startTime;
|
|
33
|
+
debugLog(`← ${response.status} ${response.statusText} (${duration}ms)`, {
|
|
34
|
+
url,
|
|
35
|
+
method,
|
|
36
|
+
status: response.status,
|
|
37
|
+
});
|
|
38
|
+
return response;
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
const duration = Date.now() - startTime;
|
|
42
|
+
debugLog(`✖ Request failed (${duration}ms)`, {
|
|
43
|
+
url,
|
|
44
|
+
method,
|
|
45
|
+
error: error instanceof Error ? error.message : error,
|
|
46
|
+
});
|
|
47
|
+
throw error;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zapier API Client Module
|
|
3
|
+
*
|
|
4
|
+
* This module provides a centralized API layer for all HTTP interactions
|
|
5
|
+
* with Zapier's various APIs. It handles authentication, error handling,
|
|
6
|
+
* polling, and provides consistent patterns across all services.
|
|
7
|
+
*/
|
|
8
|
+
export type { ApiClient, ApiClientOptions, RequestOptions, PollOptions, DebugLogger, Integration, Action, Trigger, Field, Choice, ActionExecutionResult, ActionField, ActionFieldChoice, NeedsRequest, NeedsResponse, Authentication, AuthenticationsResponse, } from "./types";
|
|
9
|
+
export { isJwt, getAuthorizationHeader } from "./auth";
|
|
10
|
+
export { createDebugLogger, createDebugFetch } from "./debug";
|
|
11
|
+
export { pollUntilComplete } from "./polling";
|
|
12
|
+
export { createZapierApi } from "./client";
|
|
13
|
+
export declare function generateRequestId(): string;
|
|
14
|
+
/**
|
|
15
|
+
* Utility function to get or create an API client for standalone functions
|
|
16
|
+
*
|
|
17
|
+
* @param config - Configuration that may include an existing API client
|
|
18
|
+
* @returns ApiClient instance
|
|
19
|
+
*/
|
|
20
|
+
export declare function getOrCreateApiClient(config: {
|
|
21
|
+
baseUrl?: string;
|
|
22
|
+
token?: string;
|
|
23
|
+
api?: import("./types").ApiClient;
|
|
24
|
+
debug?: boolean;
|
|
25
|
+
fetch?: typeof globalThis.fetch;
|
|
26
|
+
}): import("./types").ApiClient;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Zapier API Client Module
|
|
4
|
+
*
|
|
5
|
+
* This module provides a centralized API layer for all HTTP interactions
|
|
6
|
+
* with Zapier's various APIs. It handles authentication, error handling,
|
|
7
|
+
* polling, and provides consistent patterns across all services.
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.createZapierApi = exports.pollUntilComplete = exports.createDebugFetch = exports.createDebugLogger = exports.getAuthorizationHeader = exports.isJwt = void 0;
|
|
11
|
+
exports.generateRequestId = generateRequestId;
|
|
12
|
+
exports.getOrCreateApiClient = getOrCreateApiClient;
|
|
13
|
+
// Re-export authentication utilities
|
|
14
|
+
var auth_1 = require("./auth");
|
|
15
|
+
Object.defineProperty(exports, "isJwt", { enumerable: true, get: function () { return auth_1.isJwt; } });
|
|
16
|
+
Object.defineProperty(exports, "getAuthorizationHeader", { enumerable: true, get: function () { return auth_1.getAuthorizationHeader; } });
|
|
17
|
+
// Re-export debug utilities
|
|
18
|
+
var debug_1 = require("./debug");
|
|
19
|
+
Object.defineProperty(exports, "createDebugLogger", { enumerable: true, get: function () { return debug_1.createDebugLogger; } });
|
|
20
|
+
Object.defineProperty(exports, "createDebugFetch", { enumerable: true, get: function () { return debug_1.createDebugFetch; } });
|
|
21
|
+
// Re-export polling utilities
|
|
22
|
+
var polling_1 = require("./polling");
|
|
23
|
+
Object.defineProperty(exports, "pollUntilComplete", { enumerable: true, get: function () { return polling_1.pollUntilComplete; } });
|
|
24
|
+
// Re-export the main client factory
|
|
25
|
+
var client_1 = require("./client");
|
|
26
|
+
Object.defineProperty(exports, "createZapierApi", { enumerable: true, get: function () { return client_1.createZapierApi; } });
|
|
27
|
+
// Utility Functions
|
|
28
|
+
function generateRequestId() {
|
|
29
|
+
return Math.random().toString(36).substring(2) + Date.now().toString(36);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Utility function to get or create an API client for standalone functions
|
|
33
|
+
*
|
|
34
|
+
* @param config - Configuration that may include an existing API client
|
|
35
|
+
* @returns ApiClient instance
|
|
36
|
+
*/
|
|
37
|
+
function getOrCreateApiClient(config) {
|
|
38
|
+
const { baseUrl = "https://zapier.com", token = process.env.ZAPIER_TOKEN, api: providedApi, debug = false, fetch: customFetch, } = config;
|
|
39
|
+
// Use provided API client or create a new one
|
|
40
|
+
if (providedApi) {
|
|
41
|
+
return providedApi;
|
|
42
|
+
}
|
|
43
|
+
// Import createZapierApi locally to avoid circular imports
|
|
44
|
+
const { createZapierApi } = require("./client");
|
|
45
|
+
return createZapierApi({
|
|
46
|
+
baseUrl,
|
|
47
|
+
token,
|
|
48
|
+
debug,
|
|
49
|
+
fetch: customFetch,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Polling Utilities
|
|
3
|
+
*
|
|
4
|
+
* This module provides utilities for polling HTTP endpoints until completion,
|
|
5
|
+
* with configurable retry logic and exponential backoff.
|
|
6
|
+
*/
|
|
7
|
+
export declare function pollUntilComplete(options: {
|
|
8
|
+
fetch: typeof globalThis.fetch;
|
|
9
|
+
url: string;
|
|
10
|
+
headers?: Record<string, string>;
|
|
11
|
+
maxAttempts?: number;
|
|
12
|
+
initialDelay?: number;
|
|
13
|
+
maxDelay?: number;
|
|
14
|
+
successStatus?: number;
|
|
15
|
+
pendingStatus?: number;
|
|
16
|
+
resultExtractor?: (response: any) => any;
|
|
17
|
+
}): Promise<any>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Polling Utilities
|
|
4
|
+
*
|
|
5
|
+
* This module provides utilities for polling HTTP endpoints until completion,
|
|
6
|
+
* with configurable retry logic and exponential backoff.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.pollUntilComplete = pollUntilComplete;
|
|
10
|
+
async function pollUntilComplete(options) {
|
|
11
|
+
const { fetch, url, headers = {}, maxAttempts = 30, initialDelay = 50, maxDelay = 1000, successStatus = 200, pendingStatus = 202, resultExtractor = (response) => response, } = options;
|
|
12
|
+
let delay = initialDelay;
|
|
13
|
+
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
|
14
|
+
const response = await fetch(url, { headers });
|
|
15
|
+
if (response.status === successStatus) {
|
|
16
|
+
// Success - extract and return results
|
|
17
|
+
const result = await response.json();
|
|
18
|
+
return resultExtractor(result);
|
|
19
|
+
}
|
|
20
|
+
else if (response.status === pendingStatus) {
|
|
21
|
+
// Still processing - wait and retry
|
|
22
|
+
if (attempt < maxAttempts - 1) {
|
|
23
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
24
|
+
delay = Math.min(delay * 2, maxDelay); // Exponential backoff
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
// Error occurred
|
|
30
|
+
throw new Error(`Request failed: GET ${url} - ${response.status} ${response.statusText}`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
throw new Error(`Operation timed out after ${maxAttempts} attempts`);
|
|
34
|
+
}
|
|
@@ -1,3 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* API Client Type Definitions
|
|
3
|
+
*
|
|
4
|
+
* This module contains all type definitions related to the Zapier API client,
|
|
5
|
+
* including configuration options, client interfaces, request/response types,
|
|
6
|
+
* and API response models.
|
|
7
|
+
*/
|
|
8
|
+
export interface ApiClientOptions {
|
|
9
|
+
baseUrl: string;
|
|
10
|
+
token?: string;
|
|
11
|
+
debug?: boolean;
|
|
12
|
+
fetch?: typeof globalThis.fetch;
|
|
13
|
+
}
|
|
14
|
+
export interface ApiClient {
|
|
15
|
+
get: (path: string, options?: RequestOptions) => Promise<any>;
|
|
16
|
+
post: (path: string, data?: any, options?: RequestOptions) => Promise<any>;
|
|
17
|
+
put: (path: string, data?: any, options?: RequestOptions) => Promise<any>;
|
|
18
|
+
delete: (path: string, options?: RequestOptions) => Promise<any>;
|
|
19
|
+
poll: (path: string, options?: PollOptions) => Promise<any>;
|
|
20
|
+
}
|
|
21
|
+
export interface RequestOptions {
|
|
22
|
+
headers?: Record<string, string>;
|
|
23
|
+
searchParams?: Record<string, string>;
|
|
24
|
+
authRequired?: boolean;
|
|
25
|
+
customErrorHandler?: (response: Response) => Error | undefined;
|
|
26
|
+
}
|
|
27
|
+
export interface PollOptions extends RequestOptions {
|
|
28
|
+
maxAttempts?: number;
|
|
29
|
+
initialDelay?: number;
|
|
30
|
+
maxDelay?: number;
|
|
31
|
+
successStatus?: number;
|
|
32
|
+
pendingStatus?: number;
|
|
33
|
+
resultExtractor?: (response: any) => any;
|
|
34
|
+
}
|
|
35
|
+
export interface DebugLogger {
|
|
36
|
+
(message: string, data?: any): void;
|
|
37
|
+
}
|
|
1
38
|
export interface Integration {
|
|
2
39
|
key: string;
|
|
3
40
|
name: string;
|
|
@@ -37,17 +74,6 @@ export interface Choice {
|
|
|
37
74
|
value: string | number;
|
|
38
75
|
label: string;
|
|
39
76
|
}
|
|
40
|
-
export interface ListOptions {
|
|
41
|
-
category?: string;
|
|
42
|
-
appKey?: string;
|
|
43
|
-
type?: string;
|
|
44
|
-
limit?: number;
|
|
45
|
-
offset?: number;
|
|
46
|
-
}
|
|
47
|
-
export interface ActionExecutionOptions {
|
|
48
|
-
inputs?: Record<string, any>;
|
|
49
|
-
authId?: number;
|
|
50
|
-
}
|
|
51
77
|
export interface ActionExecutionResult {
|
|
52
78
|
success: boolean;
|
|
53
79
|
data?: any;
|
|
@@ -89,34 +115,6 @@ export interface NeedsResponse {
|
|
|
89
115
|
needs?: ActionField[];
|
|
90
116
|
errors?: string[];
|
|
91
117
|
}
|
|
92
|
-
export interface Workflow {
|
|
93
|
-
id: string;
|
|
94
|
-
name: string;
|
|
95
|
-
description: string;
|
|
96
|
-
steps: WorkflowStep[];
|
|
97
|
-
}
|
|
98
|
-
export interface WorkflowStep {
|
|
99
|
-
id: string;
|
|
100
|
-
type: "trigger" | "action";
|
|
101
|
-
appKey: string;
|
|
102
|
-
actionKey?: string;
|
|
103
|
-
triggerKey?: string;
|
|
104
|
-
}
|
|
105
|
-
export interface Interface {
|
|
106
|
-
key: string;
|
|
107
|
-
name: string;
|
|
108
|
-
fields: Field[];
|
|
109
|
-
}
|
|
110
|
-
export interface Table {
|
|
111
|
-
key: string;
|
|
112
|
-
name: string;
|
|
113
|
-
columns: TableColumn[];
|
|
114
|
-
}
|
|
115
|
-
export interface TableColumn {
|
|
116
|
-
key: string;
|
|
117
|
-
name: string;
|
|
118
|
-
type: string;
|
|
119
|
-
}
|
|
120
118
|
export interface Authentication {
|
|
121
119
|
id: number;
|
|
122
120
|
date: string;
|
|
@@ -145,52 +143,3 @@ export interface AuthenticationsResponse {
|
|
|
145
143
|
previous?: string | null;
|
|
146
144
|
results: Authentication[];
|
|
147
145
|
}
|
|
148
|
-
export interface AuthenticationListOptions {
|
|
149
|
-
account_id?: string;
|
|
150
|
-
owner?: string;
|
|
151
|
-
appKey?: string;
|
|
152
|
-
limit?: number;
|
|
153
|
-
offset?: number;
|
|
154
|
-
}
|
|
155
|
-
export declare class ZapierSdkError extends Error {
|
|
156
|
-
code?: string | undefined;
|
|
157
|
-
constructor(message: string, code?: string | undefined);
|
|
158
|
-
}
|
|
159
|
-
export declare class AppNotFoundError extends ZapierSdkError {
|
|
160
|
-
constructor(appKey: string);
|
|
161
|
-
}
|
|
162
|
-
export declare class ActionNotFoundError extends ZapierSdkError {
|
|
163
|
-
constructor(appKey: string, actionKey: string);
|
|
164
|
-
}
|
|
165
|
-
export declare class AuthenticationError extends ZapierSdkError {
|
|
166
|
-
constructor(message: string);
|
|
167
|
-
}
|
|
168
|
-
export interface AuthObject {
|
|
169
|
-
id: number;
|
|
170
|
-
}
|
|
171
|
-
export interface BaseSdkOptions {
|
|
172
|
-
token?: string;
|
|
173
|
-
authentications?: {
|
|
174
|
-
[appKey: string]: AuthObject[];
|
|
175
|
-
};
|
|
176
|
-
fetch?: typeof fetch;
|
|
177
|
-
baseUrl?: string;
|
|
178
|
-
debug?: boolean;
|
|
179
|
-
}
|
|
180
|
-
export interface FunctionConfig {
|
|
181
|
-
/** Base URL for Zapier API */
|
|
182
|
-
baseUrl?: string;
|
|
183
|
-
/** Authentication token */
|
|
184
|
-
token?: string;
|
|
185
|
-
/** Optional pre-instantiated API client */
|
|
186
|
-
api?: any;
|
|
187
|
-
/** Enable debug logging */
|
|
188
|
-
debug?: boolean;
|
|
189
|
-
/** Custom fetch implementation */
|
|
190
|
-
fetch?: typeof globalThis.fetch;
|
|
191
|
-
}
|
|
192
|
-
export interface CombinedSdk {
|
|
193
|
-
[namespace: string]: any;
|
|
194
|
-
}
|
|
195
|
-
export type SdkFactory<T = any> = (options: BaseSdkOptions) => T;
|
|
196
|
-
export declare function combineSdks(sdks: Record<string, any>): CombinedSdk;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* API Client Type Definitions
|
|
4
|
+
*
|
|
5
|
+
* This module contains all type definitions related to the Zapier API client,
|
|
6
|
+
* including configuration options, client interfaces, request/response types,
|
|
7
|
+
* and API response models.
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
input: string;
|
|
3
|
-
output?: string;
|
|
4
|
-
target?: string;
|
|
5
|
-
cjs?: boolean;
|
|
6
|
-
minify?: boolean;
|
|
7
|
-
string?: boolean;
|
|
8
|
-
}
|
|
1
|
+
import type { BundleCodeOptions } from "./schemas";
|
|
9
2
|
/**
|
|
10
3
|
* Bundle TypeScript code into executable JavaScript
|
|
11
4
|
*
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { bundleCode } from "./index";
|
|
2
|
+
export declare const bundleCodeInfo: {
|
|
3
|
+
name: string;
|
|
4
|
+
inputSchema: import("zod").ZodObject<{
|
|
5
|
+
input: import("zod").ZodString;
|
|
6
|
+
output: import("zod").ZodOptional<import("zod").ZodString>;
|
|
7
|
+
string: import("zod").ZodDefault<import("zod").ZodBoolean>;
|
|
8
|
+
minify: import("zod").ZodDefault<import("zod").ZodBoolean>;
|
|
9
|
+
target: import("zod").ZodDefault<import("zod").ZodString>;
|
|
10
|
+
cjs: import("zod").ZodDefault<import("zod").ZodBoolean>;
|
|
11
|
+
}, "strip", import("zod").ZodTypeAny, {
|
|
12
|
+
string: boolean;
|
|
13
|
+
input: string;
|
|
14
|
+
minify: boolean;
|
|
15
|
+
target: string;
|
|
16
|
+
cjs: boolean;
|
|
17
|
+
output?: string | undefined;
|
|
18
|
+
}, {
|
|
19
|
+
input: string;
|
|
20
|
+
string?: boolean | undefined;
|
|
21
|
+
output?: string | undefined;
|
|
22
|
+
minify?: boolean | undefined;
|
|
23
|
+
target?: string | undefined;
|
|
24
|
+
cjs?: boolean | undefined;
|
|
25
|
+
}>;
|
|
26
|
+
implementation: typeof bundleCode;
|
|
27
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.bundleCodeInfo = void 0;
|
|
4
|
+
const index_1 = require("./index");
|
|
5
|
+
const schemas_1 = require("./schemas");
|
|
6
|
+
// Function registry info - imports both function and schema
|
|
7
|
+
exports.bundleCodeInfo = {
|
|
8
|
+
name: index_1.bundleCode.name,
|
|
9
|
+
inputSchema: schemas_1.BundleCodeSchema,
|
|
10
|
+
implementation: index_1.bundleCode,
|
|
11
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const BundleCodeSchema: z.ZodObject<{
|
|
3
|
+
input: z.ZodString;
|
|
4
|
+
output: z.ZodOptional<z.ZodString>;
|
|
5
|
+
string: z.ZodDefault<z.ZodBoolean>;
|
|
6
|
+
minify: z.ZodDefault<z.ZodBoolean>;
|
|
7
|
+
target: z.ZodDefault<z.ZodString>;
|
|
8
|
+
cjs: z.ZodDefault<z.ZodBoolean>;
|
|
9
|
+
}, "strip", z.ZodTypeAny, {
|
|
10
|
+
string: boolean;
|
|
11
|
+
input: string;
|
|
12
|
+
minify: boolean;
|
|
13
|
+
target: string;
|
|
14
|
+
cjs: boolean;
|
|
15
|
+
output?: string | undefined;
|
|
16
|
+
}, {
|
|
17
|
+
input: string;
|
|
18
|
+
string?: boolean | undefined;
|
|
19
|
+
output?: string | undefined;
|
|
20
|
+
minify?: boolean | undefined;
|
|
21
|
+
target?: string | undefined;
|
|
22
|
+
cjs?: boolean | undefined;
|
|
23
|
+
}>;
|
|
24
|
+
export type BundleCodeOptions = z.infer<typeof BundleCodeSchema>;
|
|
25
|
+
export interface BundleCodeSdkFunction {
|
|
26
|
+
bundleCode: (options: BundleCodeOptions) => Promise<string>;
|
|
27
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BundleCodeSchema = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const properties_1 = require("../../types/properties");
|
|
6
|
+
// Pure Zod schema - no resolver metadata!
|
|
7
|
+
exports.BundleCodeSchema = zod_1.z
|
|
8
|
+
.object({
|
|
9
|
+
input: zod_1.z.string().min(1).describe("Input TypeScript file path to bundle"),
|
|
10
|
+
output: properties_1.OutputPropertySchema.optional().describe("Output file path (defaults to input with .js extension)"),
|
|
11
|
+
string: zod_1.z
|
|
12
|
+
.boolean()
|
|
13
|
+
.default(false)
|
|
14
|
+
.describe("Return bundled code as string instead of writing to file"),
|
|
15
|
+
minify: zod_1.z.boolean().default(false).describe("Minify the bundled output"),
|
|
16
|
+
target: zod_1.z.string().default("es2017").describe("ECMAScript target version"),
|
|
17
|
+
cjs: zod_1.z
|
|
18
|
+
.boolean()
|
|
19
|
+
.default(false)
|
|
20
|
+
.describe("Output CommonJS format instead of ESM"),
|
|
21
|
+
})
|
|
22
|
+
.describe("Bundle TypeScript code into executable JavaScript");
|
|
@@ -1,16 +1,11 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export interface GenerateTypesOptions extends FunctionConfig {
|
|
3
|
-
appKey: string;
|
|
4
|
-
authId?: number;
|
|
5
|
-
output?: string;
|
|
6
|
-
}
|
|
1
|
+
import type { GenerateTypesOptions } from "./schemas";
|
|
7
2
|
/**
|
|
8
3
|
* Generate TypeScript types for a specific app
|
|
9
4
|
*
|
|
10
5
|
* This function can be used standalone without instantiating a full SDK,
|
|
11
6
|
* which enables better tree-shaking in applications that only need this functionality.
|
|
12
7
|
*
|
|
13
|
-
* @param options - App key,
|
|
8
|
+
* @param options - App key, authentication ID, output path, and API configuration options
|
|
14
9
|
* @returns Promise<string> - Generated TypeScript code
|
|
15
10
|
*/
|
|
16
11
|
export declare function generateTypes(options: GenerateTypesOptions): Promise<string>;
|