@zapier/zapier-sdk 0.2.0 → 0.3.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/client.js +3 -2
- package/dist/api/types.d.ts +1 -1
- package/dist/auth.d.ts +59 -0
- package/dist/auth.js +261 -0
- package/dist/functions/getAction/info.d.ts +3 -3
- package/dist/functions/getAction/schemas.d.ts +3 -3
- package/dist/functions/getAuthentication/index.d.ts +13 -0
- package/dist/functions/getAuthentication/index.js +38 -0
- package/dist/functions/getAuthentication/info.d.ts +12 -0
- package/dist/functions/getAuthentication/info.js +11 -0
- package/dist/functions/getAuthentication/schemas.d.ts +26 -0
- package/dist/functions/getAuthentication/schemas.js +16 -0
- package/dist/functions/listActions/info.d.ts +3 -3
- package/dist/functions/listActions/schemas.d.ts +3 -3
- package/dist/functions/listFields/info.d.ts +3 -3
- package/dist/functions/listFields/schemas.d.ts +3 -3
- package/dist/functions/runAction/index.js +7 -76
- package/dist/functions/runAction/info.d.ts +3 -3
- package/dist/functions/runAction/schemas.d.ts +3 -3
- package/dist/index.d.ts +2 -0
- package/dist/index.js +5 -1
- package/dist/sdk.js +31 -39
- package/dist/types/domain.d.ts +2 -0
- package/dist/types/events.d.ts +37 -0
- package/dist/types/events.js +8 -0
- package/dist/types/properties.d.ts +1 -1
- package/dist/types/properties.js +10 -1
- package/dist/types/sdk.d.ts +2 -1
- package/package.json +4 -1
- package/src/api/client.ts +3 -2
- package/src/api/types.ts +9 -1
- package/src/auth.ts +340 -0
- package/src/functions/getAuthentication/index.ts +51 -0
- package/src/functions/getAuthentication/info.ts +9 -0
- package/src/functions/getAuthentication/schemas.ts +43 -0
- package/src/functions/runAction/index.ts +10 -135
- package/src/index.ts +4 -0
- package/src/sdk.ts +24 -61
- package/src/types/domain.ts +4 -0
- package/src/types/events.ts +43 -0
- package/src/types/properties.ts +10 -1
- package/src/types/sdk.ts +2 -0
- package/dist/utils/getTokenFromConfig.d.ts +0 -7
- package/dist/utils/getTokenFromConfig.js +0 -29
- package/src/utils/getTokenFromConfig.ts +0 -28
|
@@ -14,7 +14,7 @@ const getApp_1 = require("../getApp");
|
|
|
14
14
|
* @returns Promise<ActionExecutionResult>
|
|
15
15
|
*/
|
|
16
16
|
async function runAction(options) {
|
|
17
|
-
const { appKey, actionType, actionKey, inputs, authenticationId: providedAuthenticationId,
|
|
17
|
+
const { appKey, actionType, actionKey, inputs, authenticationId: providedAuthenticationId, } = options;
|
|
18
18
|
const api = (0, api_1.getOrCreateApiClient)(options);
|
|
19
19
|
api.requireAuthTo("run actions");
|
|
20
20
|
// Validate that the action exists
|
|
@@ -28,17 +28,15 @@ async function runAction(options) {
|
|
|
28
28
|
if (actionData.type !== actionType) {
|
|
29
29
|
throw new Error(`Action type mismatch: expected ${actionType}, got ${actionData.type}`);
|
|
30
30
|
}
|
|
31
|
-
// Execute the action using the
|
|
31
|
+
// Execute the action using the Actions API (supports all action types)
|
|
32
32
|
const startTime = Date.now();
|
|
33
|
-
const result = await
|
|
33
|
+
const result = await executeAction({
|
|
34
34
|
api,
|
|
35
35
|
appSlug: appKey,
|
|
36
36
|
actionKey: actionKey,
|
|
37
37
|
actionType: actionData.type,
|
|
38
38
|
executionOptions: { inputs: inputs || {} },
|
|
39
|
-
|
|
40
|
-
? { token: token, authentication_id: providedAuthenticationId }
|
|
41
|
-
: undefined,
|
|
39
|
+
authenticationId: providedAuthenticationId,
|
|
42
40
|
options,
|
|
43
41
|
});
|
|
44
42
|
const executionTime = Date.now() - startTime;
|
|
@@ -51,37 +49,8 @@ async function runAction(options) {
|
|
|
51
49
|
},
|
|
52
50
|
};
|
|
53
51
|
}
|
|
54
|
-
async function
|
|
55
|
-
const { api, appSlug, actionKey, actionType, executionOptions,
|
|
56
|
-
// Actions API supports: read, read_bulk, write
|
|
57
|
-
// Invoke API supports: search, read, write, read_bulk, and more
|
|
58
|
-
const actionsApiTypes = ["read", "read_bulk", "write"];
|
|
59
|
-
const useActionsApi = actionsApiTypes.includes(actionType);
|
|
60
|
-
if (useActionsApi) {
|
|
61
|
-
return executeActionViaActionsApi({
|
|
62
|
-
api,
|
|
63
|
-
appSlug,
|
|
64
|
-
actionKey,
|
|
65
|
-
actionType,
|
|
66
|
-
executionOptions,
|
|
67
|
-
auth,
|
|
68
|
-
options,
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
else {
|
|
72
|
-
return executeActionViaInvokeApi({
|
|
73
|
-
api,
|
|
74
|
-
appSlug,
|
|
75
|
-
actionKey,
|
|
76
|
-
actionType,
|
|
77
|
-
executionOptions,
|
|
78
|
-
auth,
|
|
79
|
-
options,
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
async function executeActionViaActionsApi(apiOptions) {
|
|
84
|
-
const { api, appSlug, actionKey, actionType, executionOptions, auth, options, } = apiOptions;
|
|
52
|
+
async function executeAction(actionOptions) {
|
|
53
|
+
const { api, appSlug, actionKey, actionType, executionOptions, authenticationId, options, } = actionOptions;
|
|
85
54
|
// Use the standalone getApp function
|
|
86
55
|
const appData = await (0, getApp_1.getApp)({
|
|
87
56
|
appKey: appSlug,
|
|
@@ -95,13 +64,10 @@ async function executeActionViaActionsApi(apiOptions) {
|
|
|
95
64
|
if (!selectedApi) {
|
|
96
65
|
throw new Error("No current_implementation_id found for app");
|
|
97
66
|
}
|
|
98
|
-
if (!auth?.token) {
|
|
99
|
-
throw new Error("Authentication token is required. Please provide token when creating the SDK.");
|
|
100
|
-
}
|
|
101
67
|
// Step 1: POST to /actions/v1/runs to start execution
|
|
102
68
|
const runRequest = {
|
|
103
69
|
data: {
|
|
104
|
-
authentication_id:
|
|
70
|
+
authentication_id: authenticationId || 1,
|
|
105
71
|
selected_api: selectedApi,
|
|
106
72
|
action_key: actionKey,
|
|
107
73
|
action_type: actionType,
|
|
@@ -117,39 +83,4 @@ async function executeActionViaActionsApi(apiOptions) {
|
|
|
117
83
|
resultExtractor: (result) => result.data,
|
|
118
84
|
});
|
|
119
85
|
}
|
|
120
|
-
async function executeActionViaInvokeApi(apiOptions) {
|
|
121
|
-
const { api, appSlug, actionKey, actionType, executionOptions, auth, options, } = apiOptions;
|
|
122
|
-
// Use the standalone getApp function
|
|
123
|
-
const appData = await (0, getApp_1.getApp)({
|
|
124
|
-
appKey: appSlug,
|
|
125
|
-
api,
|
|
126
|
-
token: options.token,
|
|
127
|
-
baseUrl: options.baseUrl,
|
|
128
|
-
debug: options.debug,
|
|
129
|
-
fetch: options.fetch,
|
|
130
|
-
});
|
|
131
|
-
const selectedApi = appData.current_implementation_id;
|
|
132
|
-
if (!selectedApi) {
|
|
133
|
-
throw new Error("No current_implementation_id found for app");
|
|
134
|
-
}
|
|
135
|
-
if (!auth?.token) {
|
|
136
|
-
throw new Error("Authentication token is required. Please provide token when creating the SDK.");
|
|
137
|
-
}
|
|
138
|
-
// Step 1: POST to /invoke/v1/invoke to start execution
|
|
139
|
-
const invokeRequest = {
|
|
140
|
-
selected_api: selectedApi,
|
|
141
|
-
action: actionKey,
|
|
142
|
-
type_of: actionType,
|
|
143
|
-
authentication_id: auth.authentication_id || 1,
|
|
144
|
-
params: executionOptions.inputs || {},
|
|
145
|
-
};
|
|
146
|
-
const invokeData = await api.post("/api/invoke/v1/invoke", invokeRequest);
|
|
147
|
-
const invocationId = invokeData.invocation_id;
|
|
148
|
-
// Step 2: Poll GET /invoke/v1/invoke/{invocation_id} for results
|
|
149
|
-
return await api.poll(`/api/invoke/v1/invoke/${invocationId}`, {
|
|
150
|
-
successStatus: 200,
|
|
151
|
-
pendingStatus: 202,
|
|
152
|
-
resultExtractor: (result) => result.results || result,
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
86
|
// No registry info here - moved to info.ts for proper tree-shaking
|
|
@@ -3,19 +3,19 @@ export declare const runActionInfo: {
|
|
|
3
3
|
name: string;
|
|
4
4
|
inputSchema: import("zod").ZodObject<{
|
|
5
5
|
appKey: import("zod").ZodString;
|
|
6
|
-
actionType: import("zod").ZodEnum<["read", "write", "search", "
|
|
6
|
+
actionType: import("zod").ZodEnum<["read", "read_bulk", "write", "run", "search", "search_or_write", "search_and_write", "filter"]>;
|
|
7
7
|
actionKey: import("zod").ZodString;
|
|
8
8
|
inputs: import("zod").ZodOptional<import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodAny>>;
|
|
9
9
|
authenticationId: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
10
10
|
}, "strip", import("zod").ZodTypeAny, {
|
|
11
11
|
appKey: string;
|
|
12
|
-
actionType: "
|
|
12
|
+
actionType: "read" | "read_bulk" | "write" | "run" | "search" | "search_or_write" | "search_and_write" | "filter";
|
|
13
13
|
actionKey: string;
|
|
14
14
|
inputs?: Record<string, any> | undefined;
|
|
15
15
|
authenticationId?: number | undefined;
|
|
16
16
|
}, {
|
|
17
17
|
appKey: string;
|
|
18
|
-
actionType: "
|
|
18
|
+
actionType: "read" | "read_bulk" | "write" | "run" | "search" | "search_or_write" | "search_and_write" | "filter";
|
|
19
19
|
actionKey: string;
|
|
20
20
|
inputs?: Record<string, any> | undefined;
|
|
21
21
|
authenticationId?: number | undefined;
|
|
@@ -2,19 +2,19 @@ import { z } from "zod";
|
|
|
2
2
|
import type { ActionExecutionResult } from "../../types/domain";
|
|
3
3
|
export declare const RunActionSchema: z.ZodObject<{
|
|
4
4
|
appKey: z.ZodString;
|
|
5
|
-
actionType: z.ZodEnum<["read", "write", "search", "
|
|
5
|
+
actionType: z.ZodEnum<["read", "read_bulk", "write", "run", "search", "search_or_write", "search_and_write", "filter"]>;
|
|
6
6
|
actionKey: z.ZodString;
|
|
7
7
|
inputs: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
8
8
|
authenticationId: z.ZodOptional<z.ZodNumber>;
|
|
9
9
|
}, "strip", z.ZodTypeAny, {
|
|
10
10
|
appKey: string;
|
|
11
|
-
actionType: "
|
|
11
|
+
actionType: "read" | "read_bulk" | "write" | "run" | "search" | "search_or_write" | "search_and_write" | "filter";
|
|
12
12
|
actionKey: string;
|
|
13
13
|
inputs?: Record<string, any> | undefined;
|
|
14
14
|
authenticationId?: number | undefined;
|
|
15
15
|
}, {
|
|
16
16
|
appKey: string;
|
|
17
|
-
actionType: "
|
|
17
|
+
actionType: "read" | "read_bulk" | "write" | "run" | "search" | "search_or_write" | "search_and_write" | "filter";
|
|
18
18
|
actionKey: string;
|
|
19
19
|
inputs?: Record<string, any> | undefined;
|
|
20
20
|
authenticationId?: number | undefined;
|
package/dist/index.d.ts
CHANGED
|
@@ -2,8 +2,10 @@ export * from "./types/domain";
|
|
|
2
2
|
export * from "./types/properties";
|
|
3
3
|
export * from "./plugins/apps";
|
|
4
4
|
export { isPositional } from "./schema-utils";
|
|
5
|
+
export * from "./auth";
|
|
5
6
|
export * from "./resolvers";
|
|
6
7
|
export { listAuthentications } from "./functions/listAuthentications";
|
|
8
|
+
export { getAuthentication } from "./functions/getAuthentication";
|
|
7
9
|
export { findFirstAuthentication } from "./functions/findFirstAuthentication";
|
|
8
10
|
export { findUniqueAuthentication } from "./functions/findUniqueAuthentication";
|
|
9
11
|
export { listApps } from "./functions/listApps";
|
package/dist/index.js
CHANGED
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.createZapierSdk = exports.bundleCode = exports.generateTypes = exports.listFields = exports.runAction = exports.getAction = exports.listActions = exports.getApp = exports.listApps = exports.findUniqueAuthentication = exports.findFirstAuthentication = exports.listAuthentications = exports.isPositional = void 0;
|
|
17
|
+
exports.createZapierSdk = exports.bundleCode = exports.generateTypes = exports.listFields = exports.runAction = exports.getAction = exports.listActions = exports.getApp = exports.listApps = exports.findUniqueAuthentication = exports.findFirstAuthentication = exports.getAuthentication = exports.listAuthentications = exports.isPositional = void 0;
|
|
18
18
|
// Export everything from types and plugins
|
|
19
19
|
__exportStar(require("./types/domain"), exports);
|
|
20
20
|
__exportStar(require("./types/properties"), exports);
|
|
@@ -22,12 +22,16 @@ __exportStar(require("./plugins/apps"), exports);
|
|
|
22
22
|
// Export schema utilities for CLI
|
|
23
23
|
var schema_utils_1 = require("./schema-utils");
|
|
24
24
|
Object.defineProperty(exports, "isPositional", { enumerable: true, get: function () { return schema_utils_1.isPositional; } });
|
|
25
|
+
// Export auth utilities for CLI use
|
|
26
|
+
__exportStar(require("./auth"), exports);
|
|
25
27
|
// Export resolvers for CLI use
|
|
26
28
|
__exportStar(require("./resolvers"), exports);
|
|
27
29
|
// Note: SdkSchemas is now available via SDK.__registry
|
|
28
30
|
// Export individual functions for tree-shaking
|
|
29
31
|
var listAuthentications_1 = require("./functions/listAuthentications");
|
|
30
32
|
Object.defineProperty(exports, "listAuthentications", { enumerable: true, get: function () { return listAuthentications_1.listAuthentications; } });
|
|
33
|
+
var getAuthentication_1 = require("./functions/getAuthentication");
|
|
34
|
+
Object.defineProperty(exports, "getAuthentication", { enumerable: true, get: function () { return getAuthentication_1.getAuthentication; } });
|
|
31
35
|
var findFirstAuthentication_1 = require("./functions/findFirstAuthentication");
|
|
32
36
|
Object.defineProperty(exports, "findFirstAuthentication", { enumerable: true, get: function () { return findFirstAuthentication_1.findFirstAuthentication; } });
|
|
33
37
|
var findUniqueAuthentication_1 = require("./functions/findUniqueAuthentication");
|
package/dist/sdk.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createZapierSdk = createZapierSdk;
|
|
4
4
|
const api_1 = require("./api");
|
|
5
|
+
const auth_1 = require("./auth");
|
|
5
6
|
// Import function implementations
|
|
6
7
|
const listApps_1 = require("./functions/listApps");
|
|
7
8
|
const getApp_1 = require("./functions/getApp");
|
|
@@ -9,6 +10,7 @@ const listActions_1 = require("./functions/listActions");
|
|
|
9
10
|
const getAction_1 = require("./functions/getAction");
|
|
10
11
|
const runAction_1 = require("./functions/runAction");
|
|
11
12
|
const listAuthentications_1 = require("./functions/listAuthentications");
|
|
13
|
+
const getAuthentication_1 = require("./functions/getAuthentication");
|
|
12
14
|
const findFirstAuthentication_1 = require("./functions/findFirstAuthentication");
|
|
13
15
|
const findUniqueAuthentication_1 = require("./functions/findUniqueAuthentication");
|
|
14
16
|
const listFields_1 = require("./functions/listFields");
|
|
@@ -21,11 +23,12 @@ const info_3 = require("./functions/listActions/info");
|
|
|
21
23
|
const info_4 = require("./functions/getAction/info");
|
|
22
24
|
const info_5 = require("./functions/runAction/info");
|
|
23
25
|
const info_6 = require("./functions/listAuthentications/info");
|
|
24
|
-
const info_7 = require("./functions/
|
|
25
|
-
const info_8 = require("./functions/
|
|
26
|
-
const info_9 = require("./functions/
|
|
27
|
-
const info_10 = require("./functions/
|
|
28
|
-
const info_11 = require("./functions/
|
|
26
|
+
const info_7 = require("./functions/getAuthentication/info");
|
|
27
|
+
const info_8 = require("./functions/findFirstAuthentication/info");
|
|
28
|
+
const info_9 = require("./functions/findUniqueAuthentication/info");
|
|
29
|
+
const info_10 = require("./functions/listFields/info");
|
|
30
|
+
const info_11 = require("./functions/generateTypes/info");
|
|
31
|
+
const info_12 = require("./functions/bundleCode/info");
|
|
29
32
|
// Function registry as array - uses names from function info objects
|
|
30
33
|
const functionRegistry = [
|
|
31
34
|
info_1.listAppsInfo,
|
|
@@ -34,26 +37,37 @@ const functionRegistry = [
|
|
|
34
37
|
info_4.getActionInfo,
|
|
35
38
|
info_5.runActionInfo,
|
|
36
39
|
info_6.listAuthenticationsInfo,
|
|
37
|
-
info_7.
|
|
38
|
-
info_8.
|
|
39
|
-
info_9.
|
|
40
|
-
info_10.
|
|
41
|
-
info_11.
|
|
40
|
+
info_7.getAuthenticationInfo,
|
|
41
|
+
info_8.findFirstAuthenticationInfo,
|
|
42
|
+
info_9.findUniqueAuthenticationInfo,
|
|
43
|
+
info_10.listFieldsInfo,
|
|
44
|
+
info_11.generateTypesInfo,
|
|
45
|
+
info_12.bundleCodeInfo,
|
|
42
46
|
];
|
|
43
47
|
// Import plugin functions
|
|
44
48
|
const index_1 = require("./plugins/apps/index");
|
|
45
|
-
function
|
|
46
|
-
const { fetch: customFetch = globalThis.fetch, baseUrl = "https://zapier.com", token, getToken, debug = false, } = options;
|
|
49
|
+
function createZapierSdk(options = {}) {
|
|
50
|
+
const { fetch: customFetch = globalThis.fetch, baseUrl = "https://zapier.com", token, getToken, onEvent, debug = false, } = options;
|
|
51
|
+
// If no explicit token or getToken provided, try env var then CLI config with event callbacks
|
|
52
|
+
const resolvedGetToken = getToken ||
|
|
53
|
+
(!token
|
|
54
|
+
? () => (0, auth_1.getTokenFromEnvOrConfig)({ onEvent, fetch: customFetch })
|
|
55
|
+
: undefined);
|
|
47
56
|
// Create the API client
|
|
48
57
|
const api = (0, api_1.createZapierApi)({
|
|
49
58
|
baseUrl,
|
|
50
59
|
token,
|
|
51
|
-
getToken,
|
|
60
|
+
getToken: resolvedGetToken,
|
|
52
61
|
debug,
|
|
53
62
|
fetch: customFetch,
|
|
54
63
|
});
|
|
55
|
-
//
|
|
56
|
-
const
|
|
64
|
+
// Create plugins directly - TypeScript will enforce correct implementation
|
|
65
|
+
const appsPlugin = (0, index_1.createAppsPlugin)({
|
|
66
|
+
api,
|
|
67
|
+
token,
|
|
68
|
+
});
|
|
69
|
+
// Compose final SDK - TypeScript will enforce we have all required properties
|
|
70
|
+
const fullSdk = {
|
|
57
71
|
// Registry for CLI
|
|
58
72
|
__registry: functionRegistry,
|
|
59
73
|
// Function implementations with API config injection
|
|
@@ -63,35 +77,13 @@ function createBaseZapierSdk(options = {}) {
|
|
|
63
77
|
getAction: (options) => (0, getAction_1.getAction)({ ...options, api }),
|
|
64
78
|
runAction: (options) => (0, runAction_1.runAction)({ ...options, api }),
|
|
65
79
|
listAuthentications: (options = {}) => (0, listAuthentications_1.listAuthentications)({ ...options, api }),
|
|
80
|
+
getAuthentication: (options) => (0, getAuthentication_1.getAuthentication)({ ...options, api }),
|
|
66
81
|
findFirstAuthentication: (options = {}) => (0, findFirstAuthentication_1.findFirstAuthentication)({ ...options, api }),
|
|
67
82
|
findUniqueAuthentication: (options = {}) => (0, findUniqueAuthentication_1.findUniqueAuthentication)({ ...options, api }),
|
|
68
83
|
listFields: (options) => (0, listFields_1.listFields)({ ...options, api }),
|
|
69
84
|
generateTypes: (options) => (0, generateTypes_1.generateTypes)({ ...options, api }),
|
|
70
85
|
bundleCode: (options) => (0, bundleCode_1.bundleCode)(options), // No API config needed
|
|
71
|
-
|
|
72
|
-
return sdk;
|
|
73
|
-
}
|
|
74
|
-
function createZapierSdk(options = {}) {
|
|
75
|
-
// Create base SDK
|
|
76
|
-
const baseSdk = createBaseZapierSdk(options);
|
|
77
|
-
// Extract options needed for plugins
|
|
78
|
-
const { fetch: customFetch = globalThis.fetch, baseUrl = "https://zapier.com", token, getToken, debug = false, } = options;
|
|
79
|
-
// Create the API client for plugins
|
|
80
|
-
const api = (0, api_1.createZapierApi)({
|
|
81
|
-
baseUrl,
|
|
82
|
-
token,
|
|
83
|
-
getToken,
|
|
84
|
-
debug,
|
|
85
|
-
fetch: customFetch,
|
|
86
|
-
});
|
|
87
|
-
// Create plugins directly - TypeScript will enforce correct implementation
|
|
88
|
-
const appsPlugin = (0, index_1.createAppsPlugin)({
|
|
89
|
-
api,
|
|
90
|
-
token,
|
|
91
|
-
});
|
|
92
|
-
// Compose final SDK - TypeScript will enforce we have all required properties
|
|
93
|
-
const fullSdk = {
|
|
94
|
-
...baseSdk,
|
|
86
|
+
// Add plugins
|
|
95
87
|
apps: appsPlugin,
|
|
96
88
|
};
|
|
97
89
|
return fullSdk;
|
package/dist/types/domain.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export type { Integration, Action, Trigger, Field, Choice, ActionExecutionResult, ActionField, ActionFieldChoice, NeedsRequest, NeedsResponse, Authentication, AuthenticationsResponse, } from "../api/types";
|
|
2
|
+
import type { EventCallback } from "./events";
|
|
2
3
|
export interface ActionExecutionOptions {
|
|
3
4
|
inputs?: Record<string, any>;
|
|
4
5
|
authenticationId?: number;
|
|
@@ -9,6 +10,7 @@ export interface AuthObject {
|
|
|
9
10
|
export interface BaseSdkOptions {
|
|
10
11
|
token?: string;
|
|
11
12
|
getToken?: () => Promise<string | undefined>;
|
|
13
|
+
onEvent?: EventCallback;
|
|
12
14
|
fetch?: typeof fetch;
|
|
13
15
|
baseUrl?: string;
|
|
14
16
|
debug?: boolean;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SDK Event System
|
|
3
|
+
*
|
|
4
|
+
* This module provides common event type definitions for the SDK's
|
|
5
|
+
* event system, including authentication, API, and loading events.
|
|
6
|
+
*/
|
|
7
|
+
export interface SdkEvent {
|
|
8
|
+
type: string;
|
|
9
|
+
payload?: Record<string, any>;
|
|
10
|
+
timestamp?: number;
|
|
11
|
+
}
|
|
12
|
+
export interface AuthEvent extends SdkEvent {
|
|
13
|
+
type: "auth_refreshing" | "auth_success" | "auth_error" | "auth_logout";
|
|
14
|
+
payload?: {
|
|
15
|
+
message?: string;
|
|
16
|
+
error?: string;
|
|
17
|
+
operation?: string;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export interface ApiEvent extends SdkEvent {
|
|
21
|
+
type: "api_request" | "api_response" | "api_error";
|
|
22
|
+
payload?: {
|
|
23
|
+
url?: string;
|
|
24
|
+
method?: string;
|
|
25
|
+
status?: number;
|
|
26
|
+
duration?: number;
|
|
27
|
+
error?: string;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export interface LoadingEvent extends SdkEvent {
|
|
31
|
+
type: "loading_start" | "loading_end";
|
|
32
|
+
payload?: {
|
|
33
|
+
operation?: string;
|
|
34
|
+
resource?: string;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
export type EventCallback = (event: SdkEvent) => void;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
export declare const AppKeyPropertySchema: z.ZodString;
|
|
3
|
-
export declare const ActionTypePropertySchema: z.ZodEnum<["read", "write", "search", "
|
|
3
|
+
export declare const ActionTypePropertySchema: z.ZodEnum<["read", "read_bulk", "write", "run", "search", "search_or_write", "search_and_write", "filter"]>;
|
|
4
4
|
export declare const ActionKeyPropertySchema: z.ZodString;
|
|
5
5
|
export declare const AuthenticationIdPropertySchema: z.ZodNumber;
|
|
6
6
|
export declare const InputsPropertySchema: z.ZodRecord<z.ZodString, z.ZodAny>;
|
package/dist/types/properties.js
CHANGED
|
@@ -7,7 +7,16 @@ const schema_utils_1 = require("../schema-utils");
|
|
|
7
7
|
// These can be reused in function schemas without duplication
|
|
8
8
|
exports.AppKeyPropertySchema = (0, schema_utils_1.withPositional)(zod_1.z.string().min(1).describe("App slug (e.g., 'slack', 'github')"));
|
|
9
9
|
exports.ActionTypePropertySchema = zod_1.z
|
|
10
|
-
.enum([
|
|
10
|
+
.enum([
|
|
11
|
+
"read",
|
|
12
|
+
"read_bulk",
|
|
13
|
+
"write",
|
|
14
|
+
"run",
|
|
15
|
+
"search",
|
|
16
|
+
"search_or_write",
|
|
17
|
+
"search_and_write",
|
|
18
|
+
"filter",
|
|
19
|
+
])
|
|
11
20
|
.describe("Action type that matches the action's defined type");
|
|
12
21
|
exports.ActionKeyPropertySchema = zod_1.z
|
|
13
22
|
.string()
|
package/dist/types/sdk.d.ts
CHANGED
|
@@ -4,13 +4,14 @@ import type { GetAppSdkFunction } from "../functions/getApp/schemas";
|
|
|
4
4
|
import type { RunActionSdkFunction } from "../functions/runAction/schemas";
|
|
5
5
|
import type { ListFieldsSdkFunction } from "../functions/listFields/schemas";
|
|
6
6
|
import type { ListAuthenticationsSdkFunction } from "../functions/listAuthentications/schemas";
|
|
7
|
+
import type { GetAuthenticationSdkFunction } from "../functions/getAuthentication/schemas";
|
|
7
8
|
import type { FindFirstAuthenticationSdkFunction } from "../functions/findFirstAuthentication/schemas";
|
|
8
9
|
import type { FindUniqueAuthenticationSdkFunction } from "../functions/findUniqueAuthentication/schemas";
|
|
9
10
|
import type { GenerateTypesSdkFunction } from "../functions/generateTypes/schemas";
|
|
10
11
|
import type { ListAppsSdkFunction } from "../functions/listApps/schemas";
|
|
11
12
|
import type { BundleCodeSdkFunction } from "../functions/bundleCode/schemas";
|
|
12
13
|
import type { AppsPluginSdkExtension } from "../plugins/apps/types";
|
|
13
|
-
export interface ZapierSdkFunctions extends ListActionsSdkFunction, GetActionSdkFunction, GetAppSdkFunction, RunActionSdkFunction, ListFieldsSdkFunction, ListAuthenticationsSdkFunction, FindFirstAuthenticationSdkFunction, FindUniqueAuthenticationSdkFunction, GenerateTypesSdkFunction, ListAppsSdkFunction, BundleCodeSdkFunction {
|
|
14
|
+
export interface ZapierSdkFunctions extends ListActionsSdkFunction, GetActionSdkFunction, GetAppSdkFunction, RunActionSdkFunction, ListFieldsSdkFunction, ListAuthenticationsSdkFunction, GetAuthenticationSdkFunction, FindFirstAuthenticationSdkFunction, FindUniqueAuthenticationSdkFunction, GenerateTypesSdkFunction, ListAppsSdkFunction, BundleCodeSdkFunction {
|
|
14
15
|
}
|
|
15
16
|
export interface ZapierSdkPlugins extends AppsPluginSdkExtension {
|
|
16
17
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zapier/zapier-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.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",
|
|
@@ -18,10 +18,13 @@
|
|
|
18
18
|
"access": "restricted"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
+
"conf": "^14.0.0",
|
|
21
22
|
"esbuild": "^0.25.5",
|
|
23
|
+
"jsonwebtoken": "^9.0.2",
|
|
22
24
|
"zod": "^3.25.67"
|
|
23
25
|
},
|
|
24
26
|
"devDependencies": {
|
|
27
|
+
"@types/jsonwebtoken": "^9.0.10",
|
|
25
28
|
"@types/node": "^24.0.1",
|
|
26
29
|
"typescript": "^5.8.3"
|
|
27
30
|
},
|
package/src/api/client.ts
CHANGED
|
@@ -14,6 +14,7 @@ import type {
|
|
|
14
14
|
import { getAuthorizationHeader } from "./auth";
|
|
15
15
|
import { createDebugLogger, createDebugFetch } from "./debug";
|
|
16
16
|
import { pollUntilComplete } from "./polling";
|
|
17
|
+
import { getTokenFromEnv } from "../auth";
|
|
17
18
|
|
|
18
19
|
export function createZapierApi(options: ApiClientOptions): ApiClient {
|
|
19
20
|
const {
|
|
@@ -59,7 +60,7 @@ export function createZapierApi(options: ApiClientOptions): ApiClient {
|
|
|
59
60
|
}
|
|
60
61
|
|
|
61
62
|
if (!resolvedToken) {
|
|
62
|
-
resolvedToken =
|
|
63
|
+
resolvedToken = getTokenFromEnv();
|
|
63
64
|
}
|
|
64
65
|
|
|
65
66
|
if (resolvedToken) {
|
|
@@ -163,7 +164,7 @@ export function createZapierApi(options: ApiClientOptions): ApiClient {
|
|
|
163
164
|
|
|
164
165
|
requireAuthTo(operation: string): void {
|
|
165
166
|
// Check if any authentication method is available
|
|
166
|
-
if (!token && !getToken && !
|
|
167
|
+
if (!token && !getToken && !getTokenFromEnv()) {
|
|
167
168
|
throw new Error(
|
|
168
169
|
`Authentication token is required to ${operation}. Please provide token in options or set ZAPIER_TOKEN environment variable.`,
|
|
169
170
|
);
|
package/src/api/types.ts
CHANGED
|
@@ -67,7 +67,15 @@ export interface Action {
|
|
|
67
67
|
name: string;
|
|
68
68
|
description: string;
|
|
69
69
|
appKey: string;
|
|
70
|
-
type:
|
|
70
|
+
type:
|
|
71
|
+
| "read"
|
|
72
|
+
| "read_bulk"
|
|
73
|
+
| "write"
|
|
74
|
+
| "run"
|
|
75
|
+
| "search"
|
|
76
|
+
| "search_or_write"
|
|
77
|
+
| "search_and_write"
|
|
78
|
+
| "filter";
|
|
71
79
|
inputFields: Field[];
|
|
72
80
|
outputFields: Field[];
|
|
73
81
|
}
|