@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,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AuthItemSchema = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const schema_utils_1 = require("../schema-utils");
|
|
6
|
+
// ============================================================================
|
|
7
|
+
// Auth Schemas
|
|
8
|
+
// ============================================================================
|
|
9
|
+
exports.AuthItemSchema = (0, schema_utils_1.withFormatter)(zod_1.z.object({
|
|
10
|
+
id: zod_1.z.number(),
|
|
11
|
+
title: zod_1.z.string().optional(),
|
|
12
|
+
label: zod_1.z.string().optional(),
|
|
13
|
+
identifier: zod_1.z.string().optional(),
|
|
14
|
+
account_id: zod_1.z.string().optional(),
|
|
15
|
+
is_private: zod_1.z.boolean().optional(),
|
|
16
|
+
shared_with_all: zod_1.z.boolean().optional(),
|
|
17
|
+
marked_stale_at: zod_1.z.string().optional(),
|
|
18
|
+
}), {
|
|
19
|
+
format: (item) => {
|
|
20
|
+
const details = [];
|
|
21
|
+
if (item.identifier) {
|
|
22
|
+
details.push({
|
|
23
|
+
text: `Identifier: ${item.identifier}`,
|
|
24
|
+
style: "accent",
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
if (item.label && item.title && item.label !== item.title) {
|
|
28
|
+
details.push({
|
|
29
|
+
text: `Label: ${item.label}`,
|
|
30
|
+
style: "normal",
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
details.push({
|
|
34
|
+
text: `Account: ${item.account_id || "unknown"} | Private: ${item.is_private || false} | Shared: ${item.shared_with_all || false}`,
|
|
35
|
+
style: "dim",
|
|
36
|
+
});
|
|
37
|
+
if (item.marked_stale_at) {
|
|
38
|
+
details.push({
|
|
39
|
+
text: `⚠️ Marked stale: ${new Date(item.marked_stale_at).toLocaleDateString()}`,
|
|
40
|
+
style: "warning",
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
title: item.title || item.label || `Authentication ${item.id}`,
|
|
45
|
+
subtitle: `(ID: ${item.id})`,
|
|
46
|
+
details,
|
|
47
|
+
};
|
|
48
|
+
},
|
|
49
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const FieldItemSchema: z.ZodObject<{
|
|
3
|
+
key: z.ZodString;
|
|
4
|
+
name: z.ZodOptional<z.ZodString>;
|
|
5
|
+
description: z.ZodOptional<z.ZodString>;
|
|
6
|
+
}, "strip", z.ZodTypeAny, {
|
|
7
|
+
key: string;
|
|
8
|
+
name?: string | undefined;
|
|
9
|
+
description?: string | undefined;
|
|
10
|
+
}, {
|
|
11
|
+
key: string;
|
|
12
|
+
name?: string | undefined;
|
|
13
|
+
description?: string | undefined;
|
|
14
|
+
}>;
|
|
15
|
+
export type FieldItem = z.infer<typeof FieldItemSchema>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FieldItemSchema = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const schema_utils_1 = require("../schema-utils");
|
|
6
|
+
// ============================================================================
|
|
7
|
+
// Field Schemas
|
|
8
|
+
// ============================================================================
|
|
9
|
+
exports.FieldItemSchema = (0, schema_utils_1.withFormatter)(zod_1.z.object({
|
|
10
|
+
key: zod_1.z.string(),
|
|
11
|
+
name: zod_1.z.string().optional(),
|
|
12
|
+
description: zod_1.z.string().optional(),
|
|
13
|
+
}), {
|
|
14
|
+
format: (item) => {
|
|
15
|
+
const details = [];
|
|
16
|
+
if (item.description) {
|
|
17
|
+
details.push({ text: item.description, style: "dim" });
|
|
18
|
+
}
|
|
19
|
+
return {
|
|
20
|
+
title: item.name || item.key,
|
|
21
|
+
subtitle: `(${item.key})`,
|
|
22
|
+
details,
|
|
23
|
+
};
|
|
24
|
+
},
|
|
25
|
+
});
|
package/dist/sdk.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
export
|
|
4
|
-
}
|
|
1
|
+
import { BaseSdkOptions } from "./types/domain";
|
|
2
|
+
import type { ZapierSdk } from "./types/sdk";
|
|
3
|
+
export type { ZapierSdk } from "./types/sdk";
|
|
5
4
|
export interface ZapierSdkOptions extends BaseSdkOptions {
|
|
6
5
|
}
|
|
7
6
|
export declare function createZapierSdk(options?: ZapierSdkOptions): ZapierSdk;
|
package/dist/sdk.js
CHANGED
|
@@ -1,17 +1,102 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createZapierSdk = createZapierSdk;
|
|
4
|
-
const
|
|
4
|
+
const api_1 = require("./api");
|
|
5
|
+
// Import function implementations
|
|
6
|
+
const listApps_1 = require("./functions/listApps");
|
|
7
|
+
const getApp_1 = require("./functions/getApp");
|
|
8
|
+
const listActions_1 = require("./functions/listActions");
|
|
9
|
+
const getAction_1 = require("./functions/getAction");
|
|
10
|
+
const runAction_1 = require("./functions/runAction");
|
|
11
|
+
const listAuths_1 = require("./functions/listAuths");
|
|
12
|
+
const listFields_1 = require("./functions/listFields");
|
|
13
|
+
const generateTypes_1 = require("./functions/generateTypes");
|
|
14
|
+
const bundleCode_1 = require("./functions/bundleCode");
|
|
15
|
+
// Import function registry info objects (only for CLI registry)
|
|
16
|
+
const info_1 = require("./functions/listApps/info");
|
|
17
|
+
const info_2 = require("./functions/getApp/info");
|
|
18
|
+
const info_3 = require("./functions/listActions/info");
|
|
19
|
+
const info_4 = require("./functions/getAction/info");
|
|
20
|
+
const info_5 = require("./functions/runAction/info");
|
|
21
|
+
const info_6 = require("./functions/listAuths/info");
|
|
22
|
+
const info_7 = require("./functions/listFields/info");
|
|
23
|
+
const info_8 = require("./functions/generateTypes/info");
|
|
24
|
+
const info_9 = require("./functions/bundleCode/info");
|
|
25
|
+
// Function registry as array - uses names from function info objects
|
|
26
|
+
const functionRegistry = [
|
|
27
|
+
info_1.listAppsInfo,
|
|
28
|
+
info_2.getAppInfo,
|
|
29
|
+
info_3.listActionsInfo,
|
|
30
|
+
info_4.getActionInfo,
|
|
31
|
+
info_5.runActionInfo,
|
|
32
|
+
info_6.listAuthsInfo,
|
|
33
|
+
info_7.listFieldsInfo,
|
|
34
|
+
info_8.generateTypesInfo,
|
|
35
|
+
info_9.bundleCodeInfo,
|
|
36
|
+
];
|
|
37
|
+
// Import plugin functions
|
|
38
|
+
const index_1 = require("./plugins/apps/index");
|
|
39
|
+
function createBaseZapierSdk(options = {}) {
|
|
40
|
+
// Auto-load .env files (searches up directory tree)
|
|
41
|
+
try {
|
|
42
|
+
const { findUpSync } = require("find-up");
|
|
43
|
+
const envPath = findUpSync(".env");
|
|
44
|
+
if (envPath) {
|
|
45
|
+
require("dotenv").config({ path: envPath, quiet: true });
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
// Silently fail if dotenv/find-up not available or .env not found
|
|
50
|
+
}
|
|
51
|
+
const { fetch: customFetch = globalThis.fetch, baseUrl = "https://zapier.com", token, debug = false, } = options;
|
|
52
|
+
// If no token provided, try to get it from environment variable
|
|
53
|
+
const finalToken = token || process.env.ZAPIER_TOKEN;
|
|
54
|
+
// Create the API client
|
|
55
|
+
const api = (0, api_1.createZapierApi)({
|
|
56
|
+
baseUrl,
|
|
57
|
+
token: finalToken,
|
|
58
|
+
debug,
|
|
59
|
+
fetch: customFetch,
|
|
60
|
+
});
|
|
61
|
+
// Build SDK directly - TypeScript will enforce correct implementation
|
|
62
|
+
const sdk = {
|
|
63
|
+
// Registry for CLI
|
|
64
|
+
__registry: functionRegistry,
|
|
65
|
+
// Function implementations with API config injection
|
|
66
|
+
listApps: (options = {}) => (0, listApps_1.listApps)({ ...options, api, token: finalToken }),
|
|
67
|
+
getApp: (options) => (0, getApp_1.getApp)({ ...options, api, token: finalToken }),
|
|
68
|
+
listActions: (options = {}) => (0, listActions_1.listActions)({ ...options, api, token: finalToken }),
|
|
69
|
+
getAction: (options) => (0, getAction_1.getAction)({ ...options, api, token: finalToken }),
|
|
70
|
+
runAction: (options) => (0, runAction_1.runAction)({ ...options, api, token: finalToken }),
|
|
71
|
+
listAuths: (options = {}) => (0, listAuths_1.listAuths)({ ...options, api, token: finalToken }),
|
|
72
|
+
listFields: (options) => (0, listFields_1.listFields)({ ...options, api, token: finalToken }),
|
|
73
|
+
generateTypes: (options) => (0, generateTypes_1.generateTypes)({ ...options, api, token: finalToken }),
|
|
74
|
+
bundleCode: (options) => (0, bundleCode_1.bundleCode)(options), // No API config needed
|
|
75
|
+
};
|
|
76
|
+
return sdk;
|
|
77
|
+
}
|
|
5
78
|
function createZapierSdk(options = {}) {
|
|
6
|
-
// Create
|
|
7
|
-
const
|
|
8
|
-
//
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
79
|
+
// Create base SDK
|
|
80
|
+
const baseSdk = createBaseZapierSdk(options);
|
|
81
|
+
// Extract options needed for plugins
|
|
82
|
+
const { fetch: customFetch = globalThis.fetch, baseUrl = "https://zapier.com", token, debug = false, } = options;
|
|
83
|
+
const finalToken = token || process.env.ZAPIER_TOKEN;
|
|
84
|
+
// Create the API client for plugins
|
|
85
|
+
const api = (0, api_1.createZapierApi)({
|
|
86
|
+
baseUrl,
|
|
87
|
+
token: finalToken,
|
|
88
|
+
debug,
|
|
89
|
+
fetch: customFetch,
|
|
90
|
+
});
|
|
91
|
+
// Create plugins directly - TypeScript will enforce correct implementation
|
|
92
|
+
const appsPlugin = (0, index_1.createAppsPlugin)({
|
|
93
|
+
api,
|
|
94
|
+
token: finalToken,
|
|
95
|
+
});
|
|
96
|
+
// Compose final SDK - TypeScript will enforce we have all required properties
|
|
97
|
+
const fullSdk = {
|
|
98
|
+
...baseSdk,
|
|
99
|
+
apps: appsPlugin,
|
|
16
100
|
};
|
|
101
|
+
return fullSdk;
|
|
17
102
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export type { Integration, Action, Trigger, Field, Choice, ActionExecutionResult, ActionField, ActionFieldChoice, NeedsRequest, NeedsResponse, Authentication, AuthenticationsResponse, } from "../api/types";
|
|
2
|
+
export interface ActionExecutionOptions {
|
|
3
|
+
inputs?: Record<string, any>;
|
|
4
|
+
authenticationId?: number;
|
|
5
|
+
}
|
|
6
|
+
export interface AuthObject {
|
|
7
|
+
id: number;
|
|
8
|
+
}
|
|
9
|
+
export interface BaseSdkOptions {
|
|
10
|
+
token?: string;
|
|
11
|
+
fetch?: typeof fetch;
|
|
12
|
+
baseUrl?: string;
|
|
13
|
+
debug?: boolean;
|
|
14
|
+
}
|
|
15
|
+
export declare class ZapierSdkError extends Error {
|
|
16
|
+
code?: string | undefined;
|
|
17
|
+
constructor(message: string, code?: string | undefined);
|
|
18
|
+
}
|
|
19
|
+
export declare class AppNotFoundError extends ZapierSdkError {
|
|
20
|
+
appKey: string;
|
|
21
|
+
constructor(appKey: string);
|
|
22
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AppNotFoundError = exports.ZapierSdkError = void 0;
|
|
4
|
+
// Error Classes
|
|
5
|
+
class ZapierSdkError extends Error {
|
|
6
|
+
constructor(message, code) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.code = code;
|
|
9
|
+
this.name = "ZapierSdkError";
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.ZapierSdkError = ZapierSdkError;
|
|
13
|
+
class AppNotFoundError extends ZapierSdkError {
|
|
14
|
+
constructor(appKey) {
|
|
15
|
+
super(`App "${appKey}" not found`);
|
|
16
|
+
this.name = "AppNotFoundError";
|
|
17
|
+
this.code = "APP_NOT_FOUND";
|
|
18
|
+
this.appKey = appKey;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.AppNotFoundError = AppNotFoundError;
|
|
@@ -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,45 @@
|
|
|
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
|
+
// Shared property definitions for common parameters across functions
|
|
6
|
+
// These can be reused in function schemas without duplication
|
|
7
|
+
exports.AppKeyPropertySchema = zod_1.z
|
|
8
|
+
.string()
|
|
9
|
+
.min(1)
|
|
10
|
+
.describe("App slug (e.g., 'slack', 'github')");
|
|
11
|
+
exports.ActionTypePropertySchema = zod_1.z
|
|
12
|
+
.enum(["read", "write", "search", "create", "update", "delete"])
|
|
13
|
+
.describe("Action type that matches the action's defined type");
|
|
14
|
+
exports.ActionKeyPropertySchema = zod_1.z
|
|
15
|
+
.string()
|
|
16
|
+
.min(1)
|
|
17
|
+
.describe("Action key to execute");
|
|
18
|
+
exports.AuthenticationIdPropertySchema = zod_1.z
|
|
19
|
+
.number()
|
|
20
|
+
.int()
|
|
21
|
+
.describe("Authentication ID to use for this action");
|
|
22
|
+
exports.InputsPropertySchema = zod_1.z
|
|
23
|
+
.record(zod_1.z.any())
|
|
24
|
+
.describe("Input parameters for the action");
|
|
25
|
+
exports.LimitPropertySchema = zod_1.z
|
|
26
|
+
.number()
|
|
27
|
+
.int()
|
|
28
|
+
.min(1)
|
|
29
|
+
.max(1000)
|
|
30
|
+
.default(50)
|
|
31
|
+
.describe("Maximum number of items to return");
|
|
32
|
+
exports.OffsetPropertySchema = zod_1.z
|
|
33
|
+
.number()
|
|
34
|
+
.int()
|
|
35
|
+
.min(0)
|
|
36
|
+
.default(0)
|
|
37
|
+
.describe("Number of items to skip for pagination");
|
|
38
|
+
exports.OutputPropertySchema = zod_1.z.string().describe("Output file path");
|
|
39
|
+
exports.DebugPropertySchema = zod_1.z
|
|
40
|
+
.boolean()
|
|
41
|
+
.default(false)
|
|
42
|
+
.describe("Enable debug logging");
|
|
43
|
+
exports.ParamsPropertySchema = zod_1.z
|
|
44
|
+
.record(zod_1.z.any())
|
|
45
|
+
.describe("Additional parameters");
|
|
@@ -0,0 +1,21 @@
|
|
|
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 { ListAuthsSdkFunction } from "../functions/listAuths/schemas";
|
|
7
|
+
import type { GenerateTypesSdkFunction } from "../functions/generateTypes/schemas";
|
|
8
|
+
import type { ListAppsSdkFunction } from "../functions/listApps/schemas";
|
|
9
|
+
import type { BundleCodeSdkFunction } from "../functions/bundleCode/schemas";
|
|
10
|
+
import type { AppsPluginSdkExtension } from "../plugins/apps/types";
|
|
11
|
+
export interface ZapierSdkFunctions extends ListActionsSdkFunction, GetActionSdkFunction, GetAppSdkFunction, RunActionSdkFunction, ListFieldsSdkFunction, ListAuthsSdkFunction, GenerateTypesSdkFunction, ListAppsSdkFunction, BundleCodeSdkFunction {
|
|
12
|
+
}
|
|
13
|
+
export interface ZapierSdkPlugins extends AppsPluginSdkExtension {
|
|
14
|
+
}
|
|
15
|
+
export interface ZapierSdk extends ZapierSdkFunctions, ZapierSdkPlugins {
|
|
16
|
+
__registry: Array<{
|
|
17
|
+
name: string;
|
|
18
|
+
inputSchema: any;
|
|
19
|
+
implementation: Function;
|
|
20
|
+
}>;
|
|
21
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zapier/zapier-sdk",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
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
|
+
}
|