@zapier/zapier-sdk 0.0.3 → 0.1.1
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/findFirstAuthentication/index.d.ts +12 -0
- package/dist/functions/findFirstAuthentication/index.js +21 -0
- package/dist/functions/findFirstAuthentication/info.d.ts +30 -0
- package/dist/functions/findFirstAuthentication/info.js +11 -0
- package/dist/functions/findFirstAuthentication/schemas.d.ts +42 -0
- package/dist/functions/findFirstAuthentication/schemas.js +25 -0
- package/dist/functions/findUniqueAuthentication/index.d.ts +13 -0
- package/dist/functions/findUniqueAuthentication/index.js +28 -0
- package/dist/functions/findUniqueAuthentication/info.d.ts +30 -0
- package/dist/functions/findUniqueAuthentication/info.js +11 -0
- package/dist/functions/findUniqueAuthentication/schemas.d.ts +42 -0
- package/dist/functions/findUniqueAuthentication/schemas.js +25 -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 → listAuthentications/index.d.ts} +3 -9
- package/dist/functions/{listAuths.js → listAuthentications/index.js} +28 -12
- package/dist/functions/listAuthentications/info.d.ts +30 -0
- package/dist/functions/listAuthentications/info.js +11 -0
- package/dist/functions/listAuthentications/schemas.d.ts +42 -0
- package/dist/functions/listAuthentications/schemas.js +25 -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 +10 -4
- package/dist/index.js +17 -6
- 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 +44 -0
- package/dist/schema-utils.js +76 -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 +27 -0
- package/dist/schemas/Auth.js +42 -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 +104 -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 +43 -0
- package/dist/types/sdk.d.ts +23 -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/findFirstAuthentication/index.ts +24 -0
- package/src/functions/findFirstAuthentication/info.ts +9 -0
- package/src/functions/findFirstAuthentication/schemas.ts +60 -0
- package/src/functions/findUniqueAuthentication/index.ts +35 -0
- package/src/functions/findUniqueAuthentication/info.ts +9 -0
- package/src/functions/findUniqueAuthentication/schemas.ts +60 -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 → listAuthentications/index.ts} +32 -23
- package/src/functions/listAuthentications/info.ts +9 -0
- package/src/functions/listAuthentications/schemas.ts +60 -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 +19 -5
- 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 +154 -0
- package/src/schemas/Action.ts +40 -0
- package/src/schemas/App.ts +43 -0
- package/src/schemas/Auth.ts +54 -0
- package/src/schemas/Field.ts +34 -0
- package/src/sdk.ts +165 -19
- package/src/types/domain.ts +54 -0
- package/src/types/properties.ts +67 -0
- package/src/types/sdk.ts +46 -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,21 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const AppKeyPropertySchema: z.ZodString;
|
|
3
|
+
export declare const ActionTypePropertySchema: z.ZodEnum<["read", "write", "search", "create", "update", "delete"]>;
|
|
4
|
+
export declare const ActionKeyPropertySchema: z.ZodString;
|
|
5
|
+
export declare const AuthenticationIdPropertySchema: z.ZodNumber;
|
|
6
|
+
export declare const InputsPropertySchema: z.ZodRecord<z.ZodString, z.ZodAny>;
|
|
7
|
+
export declare const LimitPropertySchema: z.ZodDefault<z.ZodNumber>;
|
|
8
|
+
export declare const OffsetPropertySchema: z.ZodDefault<z.ZodNumber>;
|
|
9
|
+
export declare const OutputPropertySchema: z.ZodString;
|
|
10
|
+
export declare const DebugPropertySchema: z.ZodDefault<z.ZodBoolean>;
|
|
11
|
+
export declare const ParamsPropertySchema: z.ZodRecord<z.ZodString, z.ZodAny>;
|
|
12
|
+
export type AppKeyProperty = z.infer<typeof AppKeyPropertySchema>;
|
|
13
|
+
export type ActionTypeProperty = z.infer<typeof ActionTypePropertySchema>;
|
|
14
|
+
export type ActionKeyProperty = z.infer<typeof ActionKeyPropertySchema>;
|
|
15
|
+
export type AuthenticationIdProperty = z.infer<typeof AuthenticationIdPropertySchema>;
|
|
16
|
+
export type InputsProperty = z.infer<typeof InputsPropertySchema>;
|
|
17
|
+
export type LimitProperty = z.infer<typeof LimitPropertySchema>;
|
|
18
|
+
export type OffsetProperty = z.infer<typeof OffsetPropertySchema>;
|
|
19
|
+
export type OutputProperty = z.infer<typeof OutputPropertySchema>;
|
|
20
|
+
export type DebugProperty = z.infer<typeof DebugPropertySchema>;
|
|
21
|
+
export type ParamsProperty = z.infer<typeof ParamsPropertySchema>;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ParamsPropertySchema = exports.DebugPropertySchema = exports.OutputPropertySchema = exports.OffsetPropertySchema = exports.LimitPropertySchema = exports.InputsPropertySchema = exports.AuthenticationIdPropertySchema = exports.ActionKeyPropertySchema = exports.ActionTypePropertySchema = exports.AppKeyPropertySchema = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const schema_utils_1 = require("../schema-utils");
|
|
6
|
+
// Shared property definitions for common parameters across functions
|
|
7
|
+
// These can be reused in function schemas without duplication
|
|
8
|
+
exports.AppKeyPropertySchema = (0, schema_utils_1.withPositional)(zod_1.z.string().min(1).describe("App slug (e.g., 'slack', 'github')"));
|
|
9
|
+
exports.ActionTypePropertySchema = zod_1.z
|
|
10
|
+
.enum(["read", "write", "search", "create", "update", "delete"])
|
|
11
|
+
.describe("Action type that matches the action's defined type");
|
|
12
|
+
exports.ActionKeyPropertySchema = zod_1.z
|
|
13
|
+
.string()
|
|
14
|
+
.min(1)
|
|
15
|
+
.describe("Action key to execute");
|
|
16
|
+
exports.AuthenticationIdPropertySchema = zod_1.z
|
|
17
|
+
.number()
|
|
18
|
+
.int()
|
|
19
|
+
.describe("Authentication ID to use for this action");
|
|
20
|
+
exports.InputsPropertySchema = zod_1.z
|
|
21
|
+
.record(zod_1.z.any())
|
|
22
|
+
.describe("Input parameters for the action");
|
|
23
|
+
exports.LimitPropertySchema = zod_1.z
|
|
24
|
+
.number()
|
|
25
|
+
.int()
|
|
26
|
+
.min(1)
|
|
27
|
+
.max(1000)
|
|
28
|
+
.default(50)
|
|
29
|
+
.describe("Maximum number of items to return");
|
|
30
|
+
exports.OffsetPropertySchema = zod_1.z
|
|
31
|
+
.number()
|
|
32
|
+
.int()
|
|
33
|
+
.min(0)
|
|
34
|
+
.default(0)
|
|
35
|
+
.describe("Number of items to skip for pagination");
|
|
36
|
+
exports.OutputPropertySchema = zod_1.z.string().describe("Output file path");
|
|
37
|
+
exports.DebugPropertySchema = zod_1.z
|
|
38
|
+
.boolean()
|
|
39
|
+
.default(false)
|
|
40
|
+
.describe("Enable debug logging");
|
|
41
|
+
exports.ParamsPropertySchema = zod_1.z
|
|
42
|
+
.record(zod_1.z.any())
|
|
43
|
+
.describe("Additional parameters");
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { ListActionsSdkFunction } from "../functions/listActions/schemas";
|
|
2
|
+
import type { GetActionSdkFunction } from "../functions/getAction/schemas";
|
|
3
|
+
import type { GetAppSdkFunction } from "../functions/getApp/schemas";
|
|
4
|
+
import type { RunActionSdkFunction } from "../functions/runAction/schemas";
|
|
5
|
+
import type { ListFieldsSdkFunction } from "../functions/listFields/schemas";
|
|
6
|
+
import type { ListAuthenticationsSdkFunction } from "../functions/listAuthentications/schemas";
|
|
7
|
+
import type { FindFirstAuthenticationSdkFunction } from "../functions/findFirstAuthentication/schemas";
|
|
8
|
+
import type { FindUniqueAuthenticationSdkFunction } from "../functions/findUniqueAuthentication/schemas";
|
|
9
|
+
import type { GenerateTypesSdkFunction } from "../functions/generateTypes/schemas";
|
|
10
|
+
import type { ListAppsSdkFunction } from "../functions/listApps/schemas";
|
|
11
|
+
import type { BundleCodeSdkFunction } from "../functions/bundleCode/schemas";
|
|
12
|
+
import type { AppsPluginSdkExtension } from "../plugins/apps/types";
|
|
13
|
+
export interface ZapierSdkFunctions extends ListActionsSdkFunction, GetActionSdkFunction, GetAppSdkFunction, RunActionSdkFunction, ListFieldsSdkFunction, ListAuthenticationsSdkFunction, FindFirstAuthenticationSdkFunction, FindUniqueAuthenticationSdkFunction, GenerateTypesSdkFunction, ListAppsSdkFunction, BundleCodeSdkFunction {
|
|
14
|
+
}
|
|
15
|
+
export interface ZapierSdkPlugins extends AppsPluginSdkExtension {
|
|
16
|
+
}
|
|
17
|
+
export interface ZapierSdk extends ZapierSdkFunctions, ZapierSdkPlugins {
|
|
18
|
+
__registry: Array<{
|
|
19
|
+
name: string;
|
|
20
|
+
inputSchema: any;
|
|
21
|
+
implementation: Function;
|
|
22
|
+
}>;
|
|
23
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zapier/zapier-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Complete Zapier SDK - combines all Zapier SDK packages",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -28,7 +28,9 @@
|
|
|
28
28
|
"typescript": "^5.8.3"
|
|
29
29
|
},
|
|
30
30
|
"scripts": {
|
|
31
|
-
"build": "tsc --project tsconfig.build.json",
|
|
31
|
+
"build": "rm -rf dist && tsc --project tsconfig.build.json",
|
|
32
|
+
"clean": "rm -rf dist",
|
|
33
|
+
"rebuild": "pnpm clean && pnpm build",
|
|
32
34
|
"dev": "tsc --watch",
|
|
33
35
|
"typecheck": "tsc --project tsconfig.build.json --noEmit"
|
|
34
36
|
}
|
package/src/api/auth.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Authentication Utilities
|
|
3
|
+
*
|
|
4
|
+
* This module provides utilities for handling authentication tokens,
|
|
5
|
+
* including JWT detection and authorization header generation.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export function isJwt(token: string): boolean {
|
|
9
|
+
// JWT tokens have exactly 3 parts separated by dots
|
|
10
|
+
const parts = token.split(".");
|
|
11
|
+
if (parts.length !== 3) {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// Each part should be base64url encoded (no padding)
|
|
16
|
+
// Basic validation - each part should be non-empty and contain valid base64url characters
|
|
17
|
+
const base64UrlPattern = /^[A-Za-z0-9_-]+$/;
|
|
18
|
+
return parts.every((part) => part.length > 0 && base64UrlPattern.test(part));
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function getAuthorizationHeader(token: string): string {
|
|
22
|
+
// Check if token is a JWT (has 3 parts separated by dots)
|
|
23
|
+
if (isJwt(token)) {
|
|
24
|
+
return `JWT ${token}`;
|
|
25
|
+
}
|
|
26
|
+
// Default to Bearer for other token types
|
|
27
|
+
return `Bearer ${token}`;
|
|
28
|
+
}
|
|
@@ -0,0 +1,148 @@
|
|
|
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
|
+
|
|
8
|
+
import type {
|
|
9
|
+
ApiClient,
|
|
10
|
+
ApiClientOptions,
|
|
11
|
+
RequestOptions,
|
|
12
|
+
PollOptions,
|
|
13
|
+
} from "./types";
|
|
14
|
+
import { getAuthorizationHeader } from "./auth";
|
|
15
|
+
import { createDebugLogger, createDebugFetch } from "./debug";
|
|
16
|
+
import { pollUntilComplete } from "./polling";
|
|
17
|
+
|
|
18
|
+
export function createZapierApi(options: ApiClientOptions): ApiClient {
|
|
19
|
+
const {
|
|
20
|
+
baseUrl,
|
|
21
|
+
token,
|
|
22
|
+
debug = false,
|
|
23
|
+
fetch: originalFetch = globalThis.fetch,
|
|
24
|
+
} = options;
|
|
25
|
+
|
|
26
|
+
const debugLog = createDebugLogger(debug);
|
|
27
|
+
const fetch = createDebugFetch({ originalFetch, debugLog });
|
|
28
|
+
|
|
29
|
+
// Helper to build full URLs
|
|
30
|
+
function buildUrl(
|
|
31
|
+
path: string,
|
|
32
|
+
searchParams?: Record<string, string>,
|
|
33
|
+
): string {
|
|
34
|
+
const url = new URL(path, baseUrl);
|
|
35
|
+
if (searchParams) {
|
|
36
|
+
Object.entries(searchParams).forEach(([key, value]) => {
|
|
37
|
+
url.searchParams.set(key, value);
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
return url.toString();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Helper to build headers
|
|
44
|
+
function buildHeaders(options: RequestOptions = {}): Record<string, string> {
|
|
45
|
+
const headers: Record<string, string> = {
|
|
46
|
+
...options.headers,
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
// Add auth header if token provided and not explicitly disabled
|
|
50
|
+
if (token && options.authRequired !== false) {
|
|
51
|
+
headers.Authorization = getAuthorizationHeader(token);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return headers;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Helper to handle responses
|
|
58
|
+
async function handleResponse(
|
|
59
|
+
response: Response,
|
|
60
|
+
customErrorHandler?: (response: Response) => Error | undefined,
|
|
61
|
+
): Promise<any> {
|
|
62
|
+
if (!response.ok) {
|
|
63
|
+
// Check for custom error handling first
|
|
64
|
+
if (customErrorHandler) {
|
|
65
|
+
const customError = customErrorHandler(response);
|
|
66
|
+
if (customError) {
|
|
67
|
+
throw customError;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Try to parse JSON, fall back to text if that fails
|
|
75
|
+
try {
|
|
76
|
+
return await response.json();
|
|
77
|
+
} catch {
|
|
78
|
+
return await response.text();
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Helper to perform HTTP requests with JSON handling
|
|
83
|
+
async function fetchJson(
|
|
84
|
+
method: string,
|
|
85
|
+
path: string,
|
|
86
|
+
data?: any,
|
|
87
|
+
options: RequestOptions = {},
|
|
88
|
+
): Promise<any> {
|
|
89
|
+
const url = buildUrl(path, options.searchParams);
|
|
90
|
+
const headers = buildHeaders(options);
|
|
91
|
+
|
|
92
|
+
// Add Content-Type for JSON requests with body data
|
|
93
|
+
if (data && typeof data === "object") {
|
|
94
|
+
headers["Content-Type"] = "application/json";
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const response = await fetch(url, {
|
|
98
|
+
method,
|
|
99
|
+
headers,
|
|
100
|
+
body: data ? JSON.stringify(data) : undefined,
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
return handleResponse(response, options.customErrorHandler);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return {
|
|
107
|
+
async get(path: string, options: RequestOptions = {}): Promise<any> {
|
|
108
|
+
return fetchJson("GET", path, undefined, options);
|
|
109
|
+
},
|
|
110
|
+
|
|
111
|
+
async post(
|
|
112
|
+
path: string,
|
|
113
|
+
data?: any,
|
|
114
|
+
options: RequestOptions = {},
|
|
115
|
+
): Promise<any> {
|
|
116
|
+
return fetchJson("POST", path, data, options);
|
|
117
|
+
},
|
|
118
|
+
|
|
119
|
+
async put(
|
|
120
|
+
path: string,
|
|
121
|
+
data?: any,
|
|
122
|
+
options: RequestOptions = {},
|
|
123
|
+
): Promise<any> {
|
|
124
|
+
return fetchJson("PUT", path, data, options);
|
|
125
|
+
},
|
|
126
|
+
|
|
127
|
+
async delete(path: string, options: RequestOptions = {}): Promise<any> {
|
|
128
|
+
return fetchJson("DELETE", path, undefined, options);
|
|
129
|
+
},
|
|
130
|
+
|
|
131
|
+
async poll(path: string, options: PollOptions = {}): Promise<any> {
|
|
132
|
+
const url = buildUrl(path, options.searchParams);
|
|
133
|
+
const headers = buildHeaders(options);
|
|
134
|
+
|
|
135
|
+
return pollUntilComplete({
|
|
136
|
+
fetch,
|
|
137
|
+
url,
|
|
138
|
+
headers,
|
|
139
|
+
maxAttempts: options.maxAttempts,
|
|
140
|
+
initialDelay: options.initialDelay,
|
|
141
|
+
maxDelay: options.maxDelay,
|
|
142
|
+
successStatus: options.successStatus,
|
|
143
|
+
pendingStatus: options.pendingStatus,
|
|
144
|
+
resultExtractor: options.resultExtractor,
|
|
145
|
+
});
|
|
146
|
+
},
|
|
147
|
+
};
|
|
148
|
+
}
|
package/src/api/debug.ts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
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
|
+
|
|
8
|
+
import type { DebugLogger } from "./types";
|
|
9
|
+
|
|
10
|
+
export function createDebugLogger(enabled: boolean): DebugLogger {
|
|
11
|
+
if (!enabled) {
|
|
12
|
+
return () => {}; // No-op function when debug is disabled
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return (message: string, data?: any) => {
|
|
16
|
+
console.log(`[Zapier SDK] ${message}`, data || "");
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function createDebugFetch(options: {
|
|
21
|
+
originalFetch: typeof globalThis.fetch;
|
|
22
|
+
debugLog: DebugLogger;
|
|
23
|
+
}) {
|
|
24
|
+
const { originalFetch, debugLog } = options;
|
|
25
|
+
return async (input: RequestInfo | URL, options?: RequestInit) => {
|
|
26
|
+
const startTime = Date.now();
|
|
27
|
+
|
|
28
|
+
// Convert input to URL string for logging
|
|
29
|
+
const url = typeof input === "string" ? input : input.toString();
|
|
30
|
+
const method = options?.method || "GET";
|
|
31
|
+
|
|
32
|
+
debugLog(`→ ${method} ${url}`, {
|
|
33
|
+
headers: options?.headers,
|
|
34
|
+
body: options?.body ? JSON.parse(options.body as string) : undefined,
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
try {
|
|
38
|
+
const response = await originalFetch(input, options);
|
|
39
|
+
const duration = Date.now() - startTime;
|
|
40
|
+
|
|
41
|
+
debugLog(`← ${response.status} ${response.statusText} (${duration}ms)`, {
|
|
42
|
+
url,
|
|
43
|
+
method,
|
|
44
|
+
status: response.status,
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
return response;
|
|
48
|
+
} catch (error) {
|
|
49
|
+
const duration = Date.now() - startTime;
|
|
50
|
+
debugLog(`✖ Request failed (${duration}ms)`, {
|
|
51
|
+
url,
|
|
52
|
+
method,
|
|
53
|
+
error: error instanceof Error ? error.message : error,
|
|
54
|
+
});
|
|
55
|
+
throw error;
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}
|
package/src/api/index.ts
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
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
|
+
|
|
9
|
+
// Re-export all types
|
|
10
|
+
export type {
|
|
11
|
+
// API Client Infrastructure Types
|
|
12
|
+
ApiClient,
|
|
13
|
+
ApiClientOptions,
|
|
14
|
+
RequestOptions,
|
|
15
|
+
PollOptions,
|
|
16
|
+
DebugLogger,
|
|
17
|
+
// API Response Model Types
|
|
18
|
+
Integration,
|
|
19
|
+
Action,
|
|
20
|
+
Trigger,
|
|
21
|
+
Field,
|
|
22
|
+
Choice,
|
|
23
|
+
ActionExecutionResult,
|
|
24
|
+
ActionField,
|
|
25
|
+
ActionFieldChoice,
|
|
26
|
+
NeedsRequest,
|
|
27
|
+
NeedsResponse,
|
|
28
|
+
Authentication,
|
|
29
|
+
AuthenticationsResponse,
|
|
30
|
+
} from "./types";
|
|
31
|
+
|
|
32
|
+
// Re-export authentication utilities
|
|
33
|
+
export { isJwt, getAuthorizationHeader } from "./auth";
|
|
34
|
+
|
|
35
|
+
// Re-export debug utilities
|
|
36
|
+
export { createDebugLogger, createDebugFetch } from "./debug";
|
|
37
|
+
|
|
38
|
+
// Re-export polling utilities
|
|
39
|
+
export { pollUntilComplete } from "./polling";
|
|
40
|
+
|
|
41
|
+
// Re-export the main client factory
|
|
42
|
+
export { createZapierApi } from "./client";
|
|
43
|
+
|
|
44
|
+
// Utility Functions
|
|
45
|
+
export function generateRequestId(): string {
|
|
46
|
+
return Math.random().toString(36).substring(2) + Date.now().toString(36);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Utility function to get or create an API client for standalone functions
|
|
51
|
+
*
|
|
52
|
+
* @param config - Configuration that may include an existing API client
|
|
53
|
+
* @returns ApiClient instance
|
|
54
|
+
*/
|
|
55
|
+
export function getOrCreateApiClient(config: {
|
|
56
|
+
baseUrl?: string;
|
|
57
|
+
token?: string;
|
|
58
|
+
api?: import("./types").ApiClient;
|
|
59
|
+
debug?: boolean;
|
|
60
|
+
fetch?: typeof globalThis.fetch;
|
|
61
|
+
}): import("./types").ApiClient {
|
|
62
|
+
const {
|
|
63
|
+
baseUrl = "https://zapier.com",
|
|
64
|
+
token = process.env.ZAPIER_TOKEN,
|
|
65
|
+
api: providedApi,
|
|
66
|
+
debug = false,
|
|
67
|
+
fetch: customFetch,
|
|
68
|
+
} = config;
|
|
69
|
+
|
|
70
|
+
// Use provided API client or create a new one
|
|
71
|
+
if (providedApi) {
|
|
72
|
+
return providedApi;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Import createZapierApi locally to avoid circular imports
|
|
76
|
+
const { createZapierApi } = require("./client");
|
|
77
|
+
return createZapierApi({
|
|
78
|
+
baseUrl,
|
|
79
|
+
token,
|
|
80
|
+
debug,
|
|
81
|
+
fetch: customFetch,
|
|
82
|
+
});
|
|
83
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
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
|
+
|
|
8
|
+
export async function pollUntilComplete(options: {
|
|
9
|
+
fetch: typeof globalThis.fetch;
|
|
10
|
+
url: string;
|
|
11
|
+
headers?: Record<string, string>;
|
|
12
|
+
maxAttempts?: number;
|
|
13
|
+
initialDelay?: number;
|
|
14
|
+
maxDelay?: number;
|
|
15
|
+
successStatus?: number;
|
|
16
|
+
pendingStatus?: number;
|
|
17
|
+
resultExtractor?: (response: any) => any;
|
|
18
|
+
}): Promise<any> {
|
|
19
|
+
const {
|
|
20
|
+
fetch,
|
|
21
|
+
url,
|
|
22
|
+
headers = {},
|
|
23
|
+
maxAttempts = 30,
|
|
24
|
+
initialDelay = 50,
|
|
25
|
+
maxDelay = 1000,
|
|
26
|
+
successStatus = 200,
|
|
27
|
+
pendingStatus = 202,
|
|
28
|
+
resultExtractor = (response) => response,
|
|
29
|
+
} = options;
|
|
30
|
+
|
|
31
|
+
let delay = initialDelay;
|
|
32
|
+
|
|
33
|
+
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
|
34
|
+
const response = await fetch(url, { headers });
|
|
35
|
+
|
|
36
|
+
if (response.status === successStatus) {
|
|
37
|
+
// Success - extract and return results
|
|
38
|
+
const result = await response.json();
|
|
39
|
+
return resultExtractor(result);
|
|
40
|
+
} else if (response.status === pendingStatus) {
|
|
41
|
+
// Still processing - wait and retry
|
|
42
|
+
if (attempt < maxAttempts - 1) {
|
|
43
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
44
|
+
delay = Math.min(delay * 2, maxDelay); // Exponential backoff
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
} else {
|
|
48
|
+
// Error occurred
|
|
49
|
+
throw new Error(
|
|
50
|
+
`Request failed: GET ${url} - ${response.status} ${response.statusText}`,
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
throw new Error(`Operation timed out after ${maxAttempts} attempts`);
|
|
56
|
+
}
|
package/src/api/types.ts
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
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
|
+
|
|
9
|
+
// ============================================================================
|
|
10
|
+
// API Client Infrastructure Types
|
|
11
|
+
// ============================================================================
|
|
12
|
+
|
|
13
|
+
export interface ApiClientOptions {
|
|
14
|
+
baseUrl: string;
|
|
15
|
+
token?: string;
|
|
16
|
+
debug?: boolean;
|
|
17
|
+
fetch?: typeof globalThis.fetch;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface ApiClient {
|
|
21
|
+
get: (path: string, options?: RequestOptions) => Promise<any>;
|
|
22
|
+
post: (path: string, data?: any, options?: RequestOptions) => Promise<any>;
|
|
23
|
+
put: (path: string, data?: any, options?: RequestOptions) => Promise<any>;
|
|
24
|
+
delete: (path: string, options?: RequestOptions) => Promise<any>;
|
|
25
|
+
poll: (path: string, options?: PollOptions) => Promise<any>;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface RequestOptions {
|
|
29
|
+
headers?: Record<string, string>;
|
|
30
|
+
searchParams?: Record<string, string>;
|
|
31
|
+
authRequired?: boolean;
|
|
32
|
+
customErrorHandler?: (response: Response) => Error | undefined;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface PollOptions extends RequestOptions {
|
|
36
|
+
maxAttempts?: number;
|
|
37
|
+
initialDelay?: number;
|
|
38
|
+
maxDelay?: number;
|
|
39
|
+
successStatus?: number;
|
|
40
|
+
pendingStatus?: number;
|
|
41
|
+
resultExtractor?: (response: any) => any;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface DebugLogger {
|
|
45
|
+
(message: string, data?: any): void;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// ============================================================================
|
|
49
|
+
// API Response Models
|
|
50
|
+
// ============================================================================
|
|
51
|
+
|
|
52
|
+
export interface Integration {
|
|
53
|
+
key: string;
|
|
54
|
+
name: string;
|
|
55
|
+
description: string;
|
|
56
|
+
version: string;
|
|
57
|
+
category?: string;
|
|
58
|
+
actions: Action[];
|
|
59
|
+
triggers: Trigger[];
|
|
60
|
+
current_implementation_id?: string;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export interface Action {
|
|
64
|
+
key: string;
|
|
65
|
+
name: string;
|
|
66
|
+
description: string;
|
|
67
|
+
appKey: string;
|
|
68
|
+
type: "create" | "update" | "search" | "delete" | "read";
|
|
69
|
+
inputFields: Field[];
|
|
70
|
+
outputFields: Field[];
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export interface Trigger {
|
|
74
|
+
key: string;
|
|
75
|
+
name: string;
|
|
76
|
+
description: string;
|
|
77
|
+
appKey: string;
|
|
78
|
+
type: "instant" | "polling" | "webhook";
|
|
79
|
+
outputFields: Field[];
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export interface Field {
|
|
83
|
+
key: string;
|
|
84
|
+
label: string;
|
|
85
|
+
type:
|
|
86
|
+
| "string"
|
|
87
|
+
| "number"
|
|
88
|
+
| "boolean"
|
|
89
|
+
| "datetime"
|
|
90
|
+
| "file"
|
|
91
|
+
| "object"
|
|
92
|
+
| "array";
|
|
93
|
+
required: boolean;
|
|
94
|
+
description?: string;
|
|
95
|
+
choices?: Choice[];
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export interface Choice {
|
|
99
|
+
value: string | number;
|
|
100
|
+
label: string;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export interface ActionExecutionResult {
|
|
104
|
+
success: boolean;
|
|
105
|
+
data?: any;
|
|
106
|
+
error?: string;
|
|
107
|
+
metadata?: {
|
|
108
|
+
executionTime?: number;
|
|
109
|
+
requestId?: string;
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export interface ActionField {
|
|
114
|
+
key: string;
|
|
115
|
+
label?: string;
|
|
116
|
+
required: boolean;
|
|
117
|
+
type?: string;
|
|
118
|
+
helpText?: string;
|
|
119
|
+
helpTextHtml?: string;
|
|
120
|
+
choices?: ActionFieldChoice[];
|
|
121
|
+
default?: string;
|
|
122
|
+
placeholder?: string;
|
|
123
|
+
computed?: boolean;
|
|
124
|
+
customField?: boolean;
|
|
125
|
+
dependsOn?: string[];
|
|
126
|
+
format?: string;
|
|
127
|
+
inputFormat?: string[];
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export interface ActionFieldChoice {
|
|
131
|
+
value: string | number;
|
|
132
|
+
label: string;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export interface NeedsRequest {
|
|
136
|
+
selected_api: string;
|
|
137
|
+
action: string;
|
|
138
|
+
type_of: string;
|
|
139
|
+
authentication_id?: number;
|
|
140
|
+
params?: Record<string, any>;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export interface NeedsResponse {
|
|
144
|
+
success: boolean;
|
|
145
|
+
needs?: ActionField[];
|
|
146
|
+
errors?: string[];
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export interface Authentication {
|
|
150
|
+
id: number;
|
|
151
|
+
date: string;
|
|
152
|
+
lastchanged?: string;
|
|
153
|
+
account_id: number;
|
|
154
|
+
customuser_id?: number;
|
|
155
|
+
selected_api: string;
|
|
156
|
+
destination_selected_api?: string | null;
|
|
157
|
+
is_invite_only: boolean;
|
|
158
|
+
is_private: boolean;
|
|
159
|
+
shared_with_all: boolean;
|
|
160
|
+
is_stale?: string;
|
|
161
|
+
is_shared?: string;
|
|
162
|
+
marked_stale_at?: string | null;
|
|
163
|
+
label?: string | null;
|
|
164
|
+
identifier?: string | null;
|
|
165
|
+
title?: string | null;
|
|
166
|
+
url?: string;
|
|
167
|
+
groups?: string;
|
|
168
|
+
members?: string;
|
|
169
|
+
permissions?: Record<string, boolean>;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export interface AuthenticationsResponse {
|
|
173
|
+
count: number;
|
|
174
|
+
next?: string | null;
|
|
175
|
+
previous?: string | null;
|
|
176
|
+
results: Authentication[];
|
|
177
|
+
}
|
|
@@ -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
|
/**
|
|
11
4
|
* Bundle TypeScript code into executable JavaScript
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { bundleCode } from "./index";
|
|
2
|
+
import { BundleCodeSchema } from "./schemas";
|
|
3
|
+
|
|
4
|
+
// Function registry info - imports both function and schema
|
|
5
|
+
export const bundleCodeInfo = {
|
|
6
|
+
name: bundleCode.name,
|
|
7
|
+
inputSchema: BundleCodeSchema,
|
|
8
|
+
implementation: bundleCode,
|
|
9
|
+
};
|