@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
package/dist/api/client.js
CHANGED
|
@@ -10,6 +10,7 @@ exports.createZapierApi = createZapierApi;
|
|
|
10
10
|
const auth_1 = require("./auth");
|
|
11
11
|
const debug_1 = require("./debug");
|
|
12
12
|
const polling_1 = require("./polling");
|
|
13
|
+
const auth_2 = require("../auth");
|
|
13
14
|
function createZapierApi(options) {
|
|
14
15
|
const { baseUrl, token, getToken, debug = false, fetch: originalFetch = globalThis.fetch, } = options;
|
|
15
16
|
const debugLog = (0, debug_1.createDebugLogger)(debug);
|
|
@@ -37,7 +38,7 @@ function createZapierApi(options) {
|
|
|
37
38
|
resolvedToken = await getToken();
|
|
38
39
|
}
|
|
39
40
|
if (!resolvedToken) {
|
|
40
|
-
resolvedToken =
|
|
41
|
+
resolvedToken = (0, auth_2.getTokenFromEnv)();
|
|
41
42
|
}
|
|
42
43
|
if (resolvedToken) {
|
|
43
44
|
headers.Authorization = (0, auth_1.getAuthorizationHeader)(resolvedToken);
|
|
@@ -110,7 +111,7 @@ function createZapierApi(options) {
|
|
|
110
111
|
},
|
|
111
112
|
requireAuthTo(operation) {
|
|
112
113
|
// Check if any authentication method is available
|
|
113
|
-
if (!token && !getToken && !
|
|
114
|
+
if (!token && !getToken && !(0, auth_2.getTokenFromEnv)()) {
|
|
114
115
|
throw new Error(`Authentication token is required to ${operation}. Please provide token in options or set ZAPIER_TOKEN environment variable.`);
|
|
115
116
|
}
|
|
116
117
|
},
|
package/dist/api/types.d.ts
CHANGED
|
@@ -52,7 +52,7 @@ export interface Action {
|
|
|
52
52
|
name: string;
|
|
53
53
|
description: string;
|
|
54
54
|
appKey: string;
|
|
55
|
-
type: "
|
|
55
|
+
type: "read" | "read_bulk" | "write" | "run" | "search" | "search_or_write" | "search_and_write" | "filter";
|
|
56
56
|
inputFields: Field[];
|
|
57
57
|
outputFields: Field[];
|
|
58
58
|
}
|
package/dist/auth.d.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SDK Authentication Utilities
|
|
3
|
+
*
|
|
4
|
+
* This module provides SDK-level authentication utilities, including
|
|
5
|
+
* token acquisition, refresh, and user information extraction.
|
|
6
|
+
*/
|
|
7
|
+
import type { EventCallback } from "./types/events";
|
|
8
|
+
export type { SdkEvent, AuthEvent, ApiEvent, LoadingEvent, EventCallback, } from "./types/events";
|
|
9
|
+
export interface AuthOptions {
|
|
10
|
+
onEvent?: EventCallback;
|
|
11
|
+
fetch?: typeof globalThis.fetch;
|
|
12
|
+
}
|
|
13
|
+
export interface LoginData {
|
|
14
|
+
access_token: string;
|
|
15
|
+
refresh_token: string;
|
|
16
|
+
expires_in: number;
|
|
17
|
+
}
|
|
18
|
+
export declare function updateLogin(loginData: LoginData): void;
|
|
19
|
+
/**
|
|
20
|
+
* Attempts to read a valid JWT token from the CLI configuration.
|
|
21
|
+
* Automatically refreshes expired tokens when possible.
|
|
22
|
+
* Returns undefined if no valid token is found or refresh fails.
|
|
23
|
+
*/
|
|
24
|
+
export declare function getTokenFromConfig(options?: AuthOptions): Promise<string | undefined>;
|
|
25
|
+
/**
|
|
26
|
+
* Gets the ZAPIER_TOKEN from environment variables.
|
|
27
|
+
* Returns undefined if not set.
|
|
28
|
+
*/
|
|
29
|
+
export declare function getTokenFromEnv(): string | undefined;
|
|
30
|
+
/**
|
|
31
|
+
* Attempts to get a token with the following precedence:
|
|
32
|
+
* 1. ZAPIER_TOKEN environment variable
|
|
33
|
+
* 2. Valid JWT from CLI configuration (with auto-refresh)
|
|
34
|
+
*
|
|
35
|
+
* Returns undefined if no valid token is found.
|
|
36
|
+
*/
|
|
37
|
+
export declare function getTokenFromEnvOrConfig(options?: AuthOptions): Promise<string | undefined>;
|
|
38
|
+
/**
|
|
39
|
+
* Gets the current JWT token, refreshing if necessary.
|
|
40
|
+
* Returns undefined if no valid token is available.
|
|
41
|
+
*/
|
|
42
|
+
export declare function getValidJwt(options?: AuthOptions): Promise<string | undefined>;
|
|
43
|
+
/**
|
|
44
|
+
* Gets the logged-in user information from JWT token.
|
|
45
|
+
* Automatically refreshes token if expired.
|
|
46
|
+
*/
|
|
47
|
+
export declare function getLoggedInUser(options?: AuthOptions): Promise<{
|
|
48
|
+
accountId: number;
|
|
49
|
+
customUserId: number;
|
|
50
|
+
email: string;
|
|
51
|
+
}>;
|
|
52
|
+
/**
|
|
53
|
+
* Clears stored login information.
|
|
54
|
+
*/
|
|
55
|
+
export declare function logout(options?: Pick<AuthOptions, "onEvent">): void;
|
|
56
|
+
/**
|
|
57
|
+
* Gets the path to the configuration file.
|
|
58
|
+
*/
|
|
59
|
+
export declare function getConfigPath(): string;
|
package/dist/auth.js
ADDED
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* SDK Authentication Utilities
|
|
4
|
+
*
|
|
5
|
+
* This module provides SDK-level authentication utilities, including
|
|
6
|
+
* token acquisition, refresh, and user information extraction.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.updateLogin = updateLogin;
|
|
10
|
+
exports.getTokenFromConfig = getTokenFromConfig;
|
|
11
|
+
exports.getTokenFromEnv = getTokenFromEnv;
|
|
12
|
+
exports.getTokenFromEnvOrConfig = getTokenFromEnvOrConfig;
|
|
13
|
+
exports.getValidJwt = getValidJwt;
|
|
14
|
+
exports.getLoggedInUser = getLoggedInUser;
|
|
15
|
+
exports.logout = logout;
|
|
16
|
+
exports.getConfigPath = getConfigPath;
|
|
17
|
+
// Import type { RequestOptions } from "./api/types"; // Commented out - not used yet
|
|
18
|
+
let config;
|
|
19
|
+
// Constants needed for token refresh
|
|
20
|
+
const ZAPIER_BASE = "https://zapier.com";
|
|
21
|
+
const LOGIN_CLIENT_ID = "K5eEnRE9TTmSFATdkkWhKF8NOKwoiOnYAyIqJjae";
|
|
22
|
+
const AUTH_MODE_HEADER = "X-Auth";
|
|
23
|
+
// Utility functions for config management
|
|
24
|
+
function getConfig() {
|
|
25
|
+
if (!config) {
|
|
26
|
+
const ConfModule = require("conf");
|
|
27
|
+
const Conf = ConfModule.default || ConfModule;
|
|
28
|
+
config = new Conf({ projectName: "zapier-sdk-cli" });
|
|
29
|
+
}
|
|
30
|
+
return config;
|
|
31
|
+
}
|
|
32
|
+
function updateLogin(loginData) {
|
|
33
|
+
const cfg = getConfig();
|
|
34
|
+
cfg.set("login_jwt", loginData.access_token);
|
|
35
|
+
cfg.set("login_refresh_token", loginData.refresh_token);
|
|
36
|
+
cfg.set("login_expires_at", Date.now() + loginData.expires_in * 1000);
|
|
37
|
+
}
|
|
38
|
+
function clearLogin() {
|
|
39
|
+
const cfg = getConfig();
|
|
40
|
+
cfg.delete("login_jwt");
|
|
41
|
+
cfg.delete("login_refresh_token");
|
|
42
|
+
cfg.delete("login_expires_at");
|
|
43
|
+
}
|
|
44
|
+
// JWT utility functions
|
|
45
|
+
function decodeJwtOrThrow(jwt) {
|
|
46
|
+
if (typeof jwt !== "string") {
|
|
47
|
+
throw new Error("Expected JWT to be a string");
|
|
48
|
+
}
|
|
49
|
+
let jsonwebtoken;
|
|
50
|
+
try {
|
|
51
|
+
jsonwebtoken = require("jsonwebtoken");
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
throw new Error("jsonwebtoken not available - this function requires CLI dependencies");
|
|
55
|
+
}
|
|
56
|
+
const decodedJwt = jsonwebtoken.decode(jwt, { complete: true });
|
|
57
|
+
if (!decodedJwt) {
|
|
58
|
+
throw new Error("Could not decode JWT");
|
|
59
|
+
}
|
|
60
|
+
if (typeof decodedJwt.payload === "string") {
|
|
61
|
+
throw new Error("Did not expect JWT payload to be a string");
|
|
62
|
+
}
|
|
63
|
+
return decodedJwt;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Refreshes an expired JWT token using the refresh token.
|
|
67
|
+
* Returns the new access token or throws an error.
|
|
68
|
+
*/
|
|
69
|
+
async function refreshJwt(refreshToken, options = {}) {
|
|
70
|
+
const { onEvent, fetch = globalThis.fetch } = options;
|
|
71
|
+
try {
|
|
72
|
+
onEvent?.({
|
|
73
|
+
type: "auth_refreshing",
|
|
74
|
+
payload: {
|
|
75
|
+
message: "Refreshing your token...",
|
|
76
|
+
operation: "token_refresh",
|
|
77
|
+
},
|
|
78
|
+
timestamp: Date.now(),
|
|
79
|
+
});
|
|
80
|
+
const response = await fetch(`${ZAPIER_BASE}/oauth/token/`, {
|
|
81
|
+
method: "POST",
|
|
82
|
+
headers: {
|
|
83
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
84
|
+
[AUTH_MODE_HEADER]: "no",
|
|
85
|
+
},
|
|
86
|
+
body: new URLSearchParams({
|
|
87
|
+
client_id: LOGIN_CLIENT_ID,
|
|
88
|
+
refresh_token: refreshToken,
|
|
89
|
+
grant_type: "refresh_token",
|
|
90
|
+
}),
|
|
91
|
+
});
|
|
92
|
+
if (!response.ok) {
|
|
93
|
+
throw new Error(`Token refresh failed: ${response.status} ${response.statusText}`);
|
|
94
|
+
}
|
|
95
|
+
const data = await response.json();
|
|
96
|
+
// Update stored login data
|
|
97
|
+
updateLogin(data);
|
|
98
|
+
onEvent?.({
|
|
99
|
+
type: "auth_success",
|
|
100
|
+
payload: {
|
|
101
|
+
message: "Token refreshed successfully",
|
|
102
|
+
operation: "token_refresh",
|
|
103
|
+
},
|
|
104
|
+
timestamp: Date.now(),
|
|
105
|
+
});
|
|
106
|
+
return data.access_token;
|
|
107
|
+
}
|
|
108
|
+
catch (error) {
|
|
109
|
+
// If refresh fails, clear stored login
|
|
110
|
+
clearLogin();
|
|
111
|
+
const errorMessage = `Token refresh failed: ${error instanceof Error ? error.message : "Unknown error"}`;
|
|
112
|
+
onEvent?.({
|
|
113
|
+
type: "auth_error",
|
|
114
|
+
payload: {
|
|
115
|
+
message: errorMessage,
|
|
116
|
+
error: errorMessage,
|
|
117
|
+
operation: "token_refresh",
|
|
118
|
+
},
|
|
119
|
+
timestamp: Date.now(),
|
|
120
|
+
});
|
|
121
|
+
throw error;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Attempts to read a valid JWT token from the CLI configuration.
|
|
126
|
+
* Automatically refreshes expired tokens when possible.
|
|
127
|
+
* Returns undefined if no valid token is found or refresh fails.
|
|
128
|
+
*/
|
|
129
|
+
async function getTokenFromConfig(options = {}) {
|
|
130
|
+
try {
|
|
131
|
+
const cfg = getConfig();
|
|
132
|
+
const jwt = cfg.get("login_jwt");
|
|
133
|
+
const refreshToken = cfg.get("login_refresh_token");
|
|
134
|
+
const expiresAt = cfg.get("login_expires_at");
|
|
135
|
+
// Check if we have all required fields
|
|
136
|
+
if (!jwt || !refreshToken || !expiresAt) {
|
|
137
|
+
return undefined;
|
|
138
|
+
}
|
|
139
|
+
// Check if token is still valid (with 30 second buffer)
|
|
140
|
+
if (expiresAt > Date.now() + 30 * 1000) {
|
|
141
|
+
return jwt;
|
|
142
|
+
}
|
|
143
|
+
// Token is expired - attempt to refresh
|
|
144
|
+
try {
|
|
145
|
+
return await refreshJwt(refreshToken, options);
|
|
146
|
+
}
|
|
147
|
+
catch {
|
|
148
|
+
// If refresh fails, return undefined
|
|
149
|
+
return undefined;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
catch {
|
|
153
|
+
// If conf is not available or any other error occurs, return undefined
|
|
154
|
+
return undefined;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Gets the ZAPIER_TOKEN from environment variables.
|
|
159
|
+
* Returns undefined if not set.
|
|
160
|
+
*/
|
|
161
|
+
function getTokenFromEnv() {
|
|
162
|
+
return process.env.ZAPIER_TOKEN;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Attempts to get a token with the following precedence:
|
|
166
|
+
* 1. ZAPIER_TOKEN environment variable
|
|
167
|
+
* 2. Valid JWT from CLI configuration (with auto-refresh)
|
|
168
|
+
*
|
|
169
|
+
* Returns undefined if no valid token is found.
|
|
170
|
+
*/
|
|
171
|
+
async function getTokenFromEnvOrConfig(options = {}) {
|
|
172
|
+
// First priority: environment variable
|
|
173
|
+
const envToken = getTokenFromEnv();
|
|
174
|
+
if (envToken) {
|
|
175
|
+
return envToken;
|
|
176
|
+
}
|
|
177
|
+
// Second priority: CLI configuration (with auto-refresh)
|
|
178
|
+
return getTokenFromConfig(options);
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Gets the current JWT token, refreshing if necessary.
|
|
182
|
+
* Returns undefined if no valid token is available.
|
|
183
|
+
*/
|
|
184
|
+
async function getValidJwt(options = {}) {
|
|
185
|
+
try {
|
|
186
|
+
const cfg = getConfig();
|
|
187
|
+
const jwt = cfg.get("login_jwt");
|
|
188
|
+
const refreshToken = cfg.get("login_refresh_token");
|
|
189
|
+
const expiresAt = cfg.get("login_expires_at");
|
|
190
|
+
// Check if we have all required fields
|
|
191
|
+
if (!jwt || !refreshToken || !expiresAt) {
|
|
192
|
+
return undefined;
|
|
193
|
+
}
|
|
194
|
+
// Check if token is still valid (with 30 second buffer)
|
|
195
|
+
if (expiresAt > Date.now() + 30 * 1000) {
|
|
196
|
+
return jwt;
|
|
197
|
+
}
|
|
198
|
+
// Token is expired - attempt to refresh
|
|
199
|
+
return await refreshJwt(refreshToken, options);
|
|
200
|
+
}
|
|
201
|
+
catch {
|
|
202
|
+
return undefined;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Gets the logged-in user information from JWT token.
|
|
207
|
+
* Automatically refreshes token if expired.
|
|
208
|
+
*/
|
|
209
|
+
async function getLoggedInUser(options = {}) {
|
|
210
|
+
const jwt = await getValidJwt(options);
|
|
211
|
+
if (!jwt) {
|
|
212
|
+
throw new Error("No valid authentication token available. Please login first.");
|
|
213
|
+
}
|
|
214
|
+
let decodedJwt = decodeJwtOrThrow(jwt);
|
|
215
|
+
if (decodedJwt.payload["sub_type"] == "service") {
|
|
216
|
+
decodedJwt = decodeJwtOrThrow(decodedJwt.payload["njwt"]);
|
|
217
|
+
}
|
|
218
|
+
if (typeof decodedJwt.payload["zap:acc"] !== "string") {
|
|
219
|
+
throw new Error("JWT payload does not contain accountId");
|
|
220
|
+
}
|
|
221
|
+
const accountId = parseInt(decodedJwt.payload["zap:acc"], 10);
|
|
222
|
+
if (isNaN(accountId)) {
|
|
223
|
+
throw new Error("JWT accountId is not a number");
|
|
224
|
+
}
|
|
225
|
+
if (decodedJwt.payload["sub_type"] !== "customuser" ||
|
|
226
|
+
typeof decodedJwt.payload["sub"] !== "string") {
|
|
227
|
+
throw new Error("JWT payload does not contain customUserId");
|
|
228
|
+
}
|
|
229
|
+
const customUserId = parseInt(decodedJwt.payload["sub"], 10);
|
|
230
|
+
if (isNaN(customUserId)) {
|
|
231
|
+
throw new Error("JWT customUserId is not a number");
|
|
232
|
+
}
|
|
233
|
+
const email = decodedJwt.payload["zap:uname"];
|
|
234
|
+
if (typeof email !== "string") {
|
|
235
|
+
throw new Error("JWT payload does not contain email");
|
|
236
|
+
}
|
|
237
|
+
return {
|
|
238
|
+
accountId,
|
|
239
|
+
customUserId,
|
|
240
|
+
email,
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Clears stored login information.
|
|
245
|
+
*/
|
|
246
|
+
function logout(options = {}) {
|
|
247
|
+
const { onEvent } = options;
|
|
248
|
+
clearLogin();
|
|
249
|
+
onEvent?.({
|
|
250
|
+
type: "auth_logout",
|
|
251
|
+
payload: { message: "Logged out successfully", operation: "logout" },
|
|
252
|
+
timestamp: Date.now(),
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Gets the path to the configuration file.
|
|
257
|
+
*/
|
|
258
|
+
function getConfigPath() {
|
|
259
|
+
const cfg = getConfig();
|
|
260
|
+
return cfg.path;
|
|
261
|
+
}
|
|
@@ -3,15 +3,15 @@ export declare const getActionInfo: {
|
|
|
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
|
}, "strip", import("zod").ZodTypeAny, {
|
|
9
9
|
appKey: string;
|
|
10
|
-
actionType: "
|
|
10
|
+
actionType: "read" | "read_bulk" | "write" | "run" | "search" | "search_or_write" | "search_and_write" | "filter";
|
|
11
11
|
actionKey: string;
|
|
12
12
|
}, {
|
|
13
13
|
appKey: string;
|
|
14
|
-
actionType: "
|
|
14
|
+
actionType: "read" | "read_bulk" | "write" | "run" | "search" | "search_or_write" | "search_and_write" | "filter";
|
|
15
15
|
actionKey: string;
|
|
16
16
|
}>;
|
|
17
17
|
implementation: typeof getAction;
|
|
@@ -2,15 +2,15 @@ import { z } from "zod";
|
|
|
2
2
|
import type { Action } from "../../types/domain";
|
|
3
3
|
export declare const GetActionSchema: 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
|
}, "strip", z.ZodTypeAny, {
|
|
8
8
|
appKey: string;
|
|
9
|
-
actionType: "
|
|
9
|
+
actionType: "read" | "read_bulk" | "write" | "run" | "search" | "search_or_write" | "search_and_write" | "filter";
|
|
10
10
|
actionKey: string;
|
|
11
11
|
}, {
|
|
12
12
|
appKey: string;
|
|
13
|
-
actionType: "
|
|
13
|
+
actionType: "read" | "read_bulk" | "write" | "run" | "search" | "search_or_write" | "search_and_write" | "filter";
|
|
14
14
|
actionKey: string;
|
|
15
15
|
}>;
|
|
16
16
|
export type GetActionOptions = z.infer<typeof GetActionSchema> & {
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Authentication } from "../../types/domain";
|
|
2
|
+
import type { GetAuthenticationOptions } from "./schemas";
|
|
3
|
+
/**
|
|
4
|
+
* Get a specific authentication by ID
|
|
5
|
+
*
|
|
6
|
+
* This function can be used standalone without instantiating a full SDK,
|
|
7
|
+
* which enables better tree-shaking in applications that only need this functionality.
|
|
8
|
+
*
|
|
9
|
+
* @param options - Authentication ID and API configuration options
|
|
10
|
+
* @returns Promise<Authentication> - The authentication details
|
|
11
|
+
* @throws Error if authentication not found or access denied
|
|
12
|
+
*/
|
|
13
|
+
export declare function getAuthentication(options: GetAuthenticationOptions): Promise<Authentication>;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getAuthentication = getAuthentication;
|
|
4
|
+
const api_1 = require("../../api");
|
|
5
|
+
/**
|
|
6
|
+
* Get a specific authentication by ID
|
|
7
|
+
*
|
|
8
|
+
* This function can be used standalone without instantiating a full SDK,
|
|
9
|
+
* which enables better tree-shaking in applications that only need this functionality.
|
|
10
|
+
*
|
|
11
|
+
* @param options - Authentication ID and API configuration options
|
|
12
|
+
* @returns Promise<Authentication> - The authentication details
|
|
13
|
+
* @throws Error if authentication not found or access denied
|
|
14
|
+
*/
|
|
15
|
+
async function getAuthentication(options) {
|
|
16
|
+
const { authenticationId } = options;
|
|
17
|
+
const api = (0, api_1.getOrCreateApiClient)(options);
|
|
18
|
+
api.requireAuthTo("get authentication");
|
|
19
|
+
const data = await api.get(`/api/v4/authentications/${authenticationId}/`, {
|
|
20
|
+
customErrorHandler: (response) => {
|
|
21
|
+
if (response.status === 401) {
|
|
22
|
+
return new Error(`Authentication failed. Your token may not have permission to access authentications or may be expired. (HTTP ${response.status})`);
|
|
23
|
+
}
|
|
24
|
+
if (response.status === 403) {
|
|
25
|
+
return new Error(`Access forbidden. Your token may not have the required scopes to get authentication ${authenticationId}. (HTTP ${response.status})`);
|
|
26
|
+
}
|
|
27
|
+
if (response.status === 404) {
|
|
28
|
+
return new Error(`Authentication ${authenticationId} not found. It may not exist or you may not have access to it. (HTTP ${response.status})`);
|
|
29
|
+
}
|
|
30
|
+
return undefined;
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
// Coerce title from label if title is missing (API cleanup)
|
|
34
|
+
return {
|
|
35
|
+
...data,
|
|
36
|
+
title: data.title || data.label || undefined,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { getAuthentication } from "./index";
|
|
2
|
+
export declare const getAuthenticationInfo: {
|
|
3
|
+
name: string;
|
|
4
|
+
inputSchema: import("zod").ZodObject<{
|
|
5
|
+
authenticationId: import("zod").ZodNumber;
|
|
6
|
+
}, "strip", import("zod").ZodTypeAny, {
|
|
7
|
+
authenticationId: number;
|
|
8
|
+
}, {
|
|
9
|
+
authenticationId: number;
|
|
10
|
+
}>;
|
|
11
|
+
implementation: typeof getAuthentication;
|
|
12
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getAuthenticationInfo = void 0;
|
|
4
|
+
const index_1 = require("./index");
|
|
5
|
+
const schemas_1 = require("./schemas");
|
|
6
|
+
// Function registry info - imports both function and schema
|
|
7
|
+
exports.getAuthenticationInfo = {
|
|
8
|
+
name: index_1.getAuthentication.name,
|
|
9
|
+
inputSchema: schemas_1.GetAuthenticationSchema,
|
|
10
|
+
implementation: index_1.getAuthentication,
|
|
11
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { Authentication } from "../../types/domain";
|
|
3
|
+
export declare const GetAuthenticationSchema: z.ZodObject<{
|
|
4
|
+
authenticationId: z.ZodNumber;
|
|
5
|
+
}, "strip", z.ZodTypeAny, {
|
|
6
|
+
authenticationId: number;
|
|
7
|
+
}, {
|
|
8
|
+
authenticationId: number;
|
|
9
|
+
}>;
|
|
10
|
+
export type GetAuthenticationOptions = z.infer<typeof GetAuthenticationSchema> & {
|
|
11
|
+
/** Base URL for Zapier API */
|
|
12
|
+
baseUrl?: string;
|
|
13
|
+
/** Authentication token */
|
|
14
|
+
token?: string;
|
|
15
|
+
/** Function to dynamically resolve authentication token */
|
|
16
|
+
getToken?: () => Promise<string | undefined>;
|
|
17
|
+
/** Optional pre-instantiated API client */
|
|
18
|
+
api?: any;
|
|
19
|
+
/** Enable debug logging */
|
|
20
|
+
debug?: boolean;
|
|
21
|
+
/** Custom fetch implementation */
|
|
22
|
+
fetch?: typeof globalThis.fetch;
|
|
23
|
+
};
|
|
24
|
+
export interface GetAuthenticationSdkFunction {
|
|
25
|
+
getAuthentication: (options: GetAuthenticationOptions) => Promise<Authentication>;
|
|
26
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GetAuthenticationSchema = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const schema_utils_1 = require("../../schema-utils");
|
|
6
|
+
const Auth_1 = require("../../schemas/Auth");
|
|
7
|
+
// Pure Zod schema - no resolver metadata!
|
|
8
|
+
exports.GetAuthenticationSchema = (0, schema_utils_1.withOutputSchema)(zod_1.z
|
|
9
|
+
.object({
|
|
10
|
+
authenticationId: zod_1.z
|
|
11
|
+
.number()
|
|
12
|
+
.int()
|
|
13
|
+
.positive()
|
|
14
|
+
.describe("Authentication ID to retrieve"),
|
|
15
|
+
})
|
|
16
|
+
.describe("Get a specific authentication by ID"), Auth_1.AuthItemSchema);
|
|
@@ -3,12 +3,12 @@ export declare const listActionsInfo: {
|
|
|
3
3
|
name: string;
|
|
4
4
|
inputSchema: import("zod").ZodObject<{
|
|
5
5
|
appKey: import("zod").ZodOptional<import("zod").ZodString>;
|
|
6
|
-
type: import("zod").ZodOptional<import("zod").ZodEnum<["read", "write", "search", "
|
|
6
|
+
type: import("zod").ZodOptional<import("zod").ZodEnum<["read", "read_bulk", "write", "run", "search", "search_or_write", "search_and_write", "filter"]>>;
|
|
7
7
|
}, "strip", import("zod").ZodTypeAny, {
|
|
8
|
-
type?: "
|
|
8
|
+
type?: "read" | "read_bulk" | "write" | "run" | "search" | "search_or_write" | "search_and_write" | "filter" | undefined;
|
|
9
9
|
appKey?: string | undefined;
|
|
10
10
|
}, {
|
|
11
|
-
type?: "
|
|
11
|
+
type?: "read" | "read_bulk" | "write" | "run" | "search" | "search_or_write" | "search_and_write" | "filter" | undefined;
|
|
12
12
|
appKey?: string | undefined;
|
|
13
13
|
}>;
|
|
14
14
|
implementation: typeof listActions;
|
|
@@ -2,12 +2,12 @@ import { z } from "zod";
|
|
|
2
2
|
import type { Action } from "../../types/domain";
|
|
3
3
|
export declare const ListActionsSchema: z.ZodObject<{
|
|
4
4
|
appKey: z.ZodOptional<z.ZodString>;
|
|
5
|
-
type: z.ZodOptional<z.ZodEnum<["read", "write", "search", "
|
|
5
|
+
type: z.ZodOptional<z.ZodEnum<["read", "read_bulk", "write", "run", "search", "search_or_write", "search_and_write", "filter"]>>;
|
|
6
6
|
}, "strip", z.ZodTypeAny, {
|
|
7
|
-
type?: "
|
|
7
|
+
type?: "read" | "read_bulk" | "write" | "run" | "search" | "search_or_write" | "search_and_write" | "filter" | undefined;
|
|
8
8
|
appKey?: string | undefined;
|
|
9
9
|
}, {
|
|
10
|
-
type?: "
|
|
10
|
+
type?: "read" | "read_bulk" | "write" | "run" | "search" | "search_or_write" | "search_and_write" | "filter" | undefined;
|
|
11
11
|
appKey?: string | undefined;
|
|
12
12
|
}>;
|
|
13
13
|
export type ListActionsOptions = z.infer<typeof ListActionsSchema> & {
|
|
@@ -3,19 +3,19 @@ export declare const listFieldsInfo: {
|
|
|
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
|
authenticationId: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
9
9
|
params: import("zod").ZodOptional<import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodAny>>;
|
|
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
|
params?: 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
|
params?: Record<string, any> | undefined;
|
|
21
21
|
authenticationId?: number | undefined;
|
|
@@ -2,19 +2,19 @@ import { z } from "zod";
|
|
|
2
2
|
import type { ActionField } from "../../types/domain";
|
|
3
3
|
export declare const ListFieldsSchema: 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
|
authenticationId: z.ZodOptional<z.ZodNumber>;
|
|
8
8
|
params: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
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
|
params?: 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
|
params?: Record<string, any> | undefined;
|
|
20
20
|
authenticationId?: number | undefined;
|