@zapier/zapier-sdk 0.4.0 → 0.4.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/index.cjs +114 -153
- package/dist/index.d.mts +68 -16
- package/dist/index.d.ts +68 -16
- package/dist/index.mjs +112 -153
- package/package.json +1 -1
- package/src/api/client.ts +41 -28
- package/src/api/polling.ts +4 -8
- package/src/api/types.ts +1 -2
- package/src/functions/{fetch → request}/index.ts +13 -43
- package/src/functions/request/info.ts +11 -0
- package/src/functions/{fetch → request}/schemas.ts +11 -4
- package/src/index.ts +6 -2
- package/src/plugins/apps/index.ts +11 -12
- package/src/plugins/apps/types.ts +17 -1
- package/src/plugins/fetch/index.ts +50 -0
- package/src/plugins/fetch/types.ts +2 -0
- package/src/sdk.ts +11 -13
- package/src/types/sdk.ts +6 -3
- package/src/functions/fetch/info.ts +0 -8
package/dist/index.cjs
CHANGED
|
@@ -2,71 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
var zod = require('zod');
|
|
4
4
|
|
|
5
|
-
var __defProp = Object.defineProperty;
|
|
6
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
-
var __esm = (fn, res) => function __init() {
|
|
8
|
-
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
9
|
-
};
|
|
10
|
-
var __export = (target, all) => {
|
|
11
|
-
for (var name in all)
|
|
12
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
// src/auth.ts
|
|
16
|
-
var auth_exports = {};
|
|
17
|
-
__export(auth_exports, {
|
|
18
|
-
getTokenFromCliLogin: () => getTokenFromCliLogin,
|
|
19
|
-
getTokenFromEnv: () => getTokenFromEnv,
|
|
20
|
-
getTokenFromEnvOrConfig: () => getTokenFromEnvOrConfig
|
|
21
|
-
});
|
|
22
|
-
function getTokenFromEnv() {
|
|
23
|
-
return process.env.ZAPIER_TOKEN;
|
|
24
|
-
}
|
|
25
|
-
async function getTokenFromCliLogin(options = {}) {
|
|
26
|
-
try {
|
|
27
|
-
const { getToken } = await import('@zapier/zapier-sdk-cli-login');
|
|
28
|
-
return await getToken(options);
|
|
29
|
-
} catch {
|
|
30
|
-
return void 0;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
async function getTokenFromEnvOrConfig(options = {}) {
|
|
34
|
-
const envToken = getTokenFromEnv();
|
|
35
|
-
if (envToken) {
|
|
36
|
-
return envToken;
|
|
37
|
-
}
|
|
38
|
-
return getTokenFromCliLogin(options);
|
|
39
|
-
}
|
|
40
|
-
var init_auth = __esm({
|
|
41
|
-
"src/auth.ts"() {
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
// src/api/auth.ts
|
|
46
|
-
var auth_exports2 = {};
|
|
47
|
-
__export(auth_exports2, {
|
|
48
|
-
getAuthorizationHeader: () => getAuthorizationHeader,
|
|
49
|
-
isJwt: () => isJwt
|
|
50
|
-
});
|
|
51
|
-
function isJwt(token) {
|
|
52
|
-
const parts = token.split(".");
|
|
53
|
-
if (parts.length !== 3) {
|
|
54
|
-
return false;
|
|
55
|
-
}
|
|
56
|
-
const base64UrlPattern = /^[A-Za-z0-9_-]+$/;
|
|
57
|
-
return parts.every((part) => part.length > 0 && base64UrlPattern.test(part));
|
|
58
|
-
}
|
|
59
|
-
function getAuthorizationHeader(token) {
|
|
60
|
-
if (isJwt(token)) {
|
|
61
|
-
return `JWT ${token}`;
|
|
62
|
-
}
|
|
63
|
-
return `Bearer ${token}`;
|
|
64
|
-
}
|
|
65
|
-
var init_auth2 = __esm({
|
|
66
|
-
"src/api/auth.ts"() {
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
|
|
70
5
|
// src/types/domain.ts
|
|
71
6
|
var ZapierSdkError = class extends Error {
|
|
72
7
|
constructor(message, code) {
|
|
@@ -153,16 +88,16 @@ function createActionFunction(appKey, actionType, actionKey, options, pinnedAuth
|
|
|
153
88
|
}
|
|
154
89
|
function createActionTypeProxy(appKey, actionType, options, pinnedAuthId) {
|
|
155
90
|
if (actionType === "fetch") {
|
|
156
|
-
return async (
|
|
91
|
+
return async (url, init) => {
|
|
157
92
|
const { sdk } = options;
|
|
158
|
-
const authenticationId = pinnedAuthId ||
|
|
93
|
+
const authenticationId = pinnedAuthId || init?.authenticationId;
|
|
159
94
|
if (!authenticationId) {
|
|
160
95
|
throw new Error(
|
|
161
96
|
`Authentication ID is required for fetch. Either use the factory pattern: sdk.apps.${appKey}({ authenticationId }).fetch(...) or provide authenticationId in the fetch call.`
|
|
162
97
|
);
|
|
163
98
|
}
|
|
164
|
-
return sdk.fetch({
|
|
165
|
-
...
|
|
99
|
+
return sdk.fetch(url, {
|
|
100
|
+
...init,
|
|
166
101
|
authenticationId
|
|
167
102
|
});
|
|
168
103
|
};
|
|
@@ -235,8 +170,47 @@ function createAppsPlugin(options) {
|
|
|
235
170
|
return createAppsProxy(options);
|
|
236
171
|
}
|
|
237
172
|
|
|
238
|
-
// src/index.ts
|
|
239
|
-
|
|
173
|
+
// src/plugins/fetch/index.ts
|
|
174
|
+
function createFetchPlugin(options) {
|
|
175
|
+
const { sdk } = options;
|
|
176
|
+
return async function fetch(url, init) {
|
|
177
|
+
const {
|
|
178
|
+
authenticationId,
|
|
179
|
+
callbackUrl,
|
|
180
|
+
authenticationTemplate,
|
|
181
|
+
...fetchInit
|
|
182
|
+
} = init || {};
|
|
183
|
+
return sdk.request({
|
|
184
|
+
url: url.toString(),
|
|
185
|
+
method: fetchInit.method,
|
|
186
|
+
body: fetchInit.body,
|
|
187
|
+
headers: fetchInit.headers,
|
|
188
|
+
authenticationId,
|
|
189
|
+
callbackUrl,
|
|
190
|
+
authenticationTemplate
|
|
191
|
+
});
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// src/auth.ts
|
|
196
|
+
function getTokenFromEnv() {
|
|
197
|
+
return process.env.ZAPIER_TOKEN;
|
|
198
|
+
}
|
|
199
|
+
async function getTokenFromCliLogin(options = {}) {
|
|
200
|
+
try {
|
|
201
|
+
const { getToken } = await import('@zapier/zapier-sdk-cli-login');
|
|
202
|
+
return await getToken(options);
|
|
203
|
+
} catch {
|
|
204
|
+
return void 0;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
async function getTokenFromEnvOrConfig(options = {}) {
|
|
208
|
+
const envToken = getTokenFromEnv();
|
|
209
|
+
if (envToken) {
|
|
210
|
+
return envToken;
|
|
211
|
+
}
|
|
212
|
+
return getTokenFromCliLogin(options);
|
|
213
|
+
}
|
|
240
214
|
|
|
241
215
|
// src/resolvers/appKey.ts
|
|
242
216
|
var appKeyResolver = {
|
|
@@ -388,8 +362,21 @@ function getResolutionOrderForParams(paramNames) {
|
|
|
388
362
|
return order;
|
|
389
363
|
}
|
|
390
364
|
|
|
391
|
-
// src/api/
|
|
392
|
-
|
|
365
|
+
// src/api/auth.ts
|
|
366
|
+
function isJwt(token) {
|
|
367
|
+
const parts = token.split(".");
|
|
368
|
+
if (parts.length !== 3) {
|
|
369
|
+
return false;
|
|
370
|
+
}
|
|
371
|
+
const base64UrlPattern = /^[A-Za-z0-9_-]+$/;
|
|
372
|
+
return parts.every((part) => part.length > 0 && base64UrlPattern.test(part));
|
|
373
|
+
}
|
|
374
|
+
function getAuthorizationHeader(token) {
|
|
375
|
+
if (isJwt(token)) {
|
|
376
|
+
return `JWT ${token}`;
|
|
377
|
+
}
|
|
378
|
+
return `Bearer ${token}`;
|
|
379
|
+
}
|
|
393
380
|
|
|
394
381
|
// src/api/debug.ts
|
|
395
382
|
function createDebugLogger(enabled) {
|
|
@@ -435,9 +422,7 @@ function createDebugFetch(options) {
|
|
|
435
422
|
// src/api/polling.ts
|
|
436
423
|
async function pollUntilComplete(options) {
|
|
437
424
|
const {
|
|
438
|
-
|
|
439
|
-
url,
|
|
440
|
-
headers = {},
|
|
425
|
+
fetchPoll,
|
|
441
426
|
maxAttempts = 30,
|
|
442
427
|
initialDelay = 50,
|
|
443
428
|
maxDelay = 1e3,
|
|
@@ -447,7 +432,7 @@ async function pollUntilComplete(options) {
|
|
|
447
432
|
} = options;
|
|
448
433
|
let delay = initialDelay;
|
|
449
434
|
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
|
450
|
-
const response = await
|
|
435
|
+
const response = await fetchPoll();
|
|
451
436
|
if (response.status === successStatus) {
|
|
452
437
|
const result = await response.json();
|
|
453
438
|
return resultExtractor(result);
|
|
@@ -459,7 +444,7 @@ async function pollUntilComplete(options) {
|
|
|
459
444
|
}
|
|
460
445
|
} else {
|
|
461
446
|
throw new Error(
|
|
462
|
-
`
|
|
447
|
+
`Poll request failed: ${response.status} ${response.statusText}`
|
|
463
448
|
);
|
|
464
449
|
}
|
|
465
450
|
}
|
|
@@ -467,9 +452,11 @@ async function pollUntilComplete(options) {
|
|
|
467
452
|
}
|
|
468
453
|
|
|
469
454
|
// src/api/client.ts
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
455
|
+
var SUBDOMAIN_PREFIXES = {
|
|
456
|
+
relay: {
|
|
457
|
+
authHeader: "X-Relay-Authorization"
|
|
458
|
+
}
|
|
459
|
+
};
|
|
473
460
|
function createZapierApi(options) {
|
|
474
461
|
const {
|
|
475
462
|
baseUrl,
|
|
@@ -480,12 +467,14 @@ function createZapierApi(options) {
|
|
|
480
467
|
onEvent
|
|
481
468
|
} = options;
|
|
482
469
|
const debugLog = createDebugLogger(debug);
|
|
483
|
-
const
|
|
470
|
+
const fetch = createDebugFetch({ originalFetch, debugLog });
|
|
484
471
|
function buildUrl(path, searchParams) {
|
|
485
472
|
const pathSegments = path.split("/").filter(Boolean);
|
|
486
473
|
let finalBaseUrl = baseUrl;
|
|
487
|
-
|
|
474
|
+
let subdomainConfig;
|
|
475
|
+
if (pathSegments.length > 0 && pathSegments[0] in SUBDOMAIN_PREFIXES) {
|
|
488
476
|
const subdomain = pathSegments[0];
|
|
477
|
+
subdomainConfig = SUBDOMAIN_PREFIXES[subdomain];
|
|
489
478
|
const baseUrlObj = new URL(baseUrl);
|
|
490
479
|
baseUrlObj.hostname = `${subdomain}.${baseUrlObj.hostname}`;
|
|
491
480
|
finalBaseUrl = baseUrlObj.toString();
|
|
@@ -497,9 +486,9 @@ function createZapierApi(options) {
|
|
|
497
486
|
url.searchParams.set(key, value);
|
|
498
487
|
});
|
|
499
488
|
}
|
|
500
|
-
return url.toString();
|
|
489
|
+
return { url: url.toString(), subdomainConfig };
|
|
501
490
|
}
|
|
502
|
-
async function buildHeaders(options2 = {}) {
|
|
491
|
+
async function buildHeaders(options2 = {}, subdomainConfig) {
|
|
503
492
|
const headers = {
|
|
504
493
|
...options2.headers
|
|
505
494
|
};
|
|
@@ -515,7 +504,8 @@ function createZapierApi(options) {
|
|
|
515
504
|
});
|
|
516
505
|
}
|
|
517
506
|
if (resolvedToken) {
|
|
518
|
-
|
|
507
|
+
const authHeaderName = subdomainConfig?.authHeader || "Authorization";
|
|
508
|
+
headers[authHeaderName] = getAuthorizationHeader(resolvedToken);
|
|
519
509
|
}
|
|
520
510
|
}
|
|
521
511
|
return headers;
|
|
@@ -528,7 +518,7 @@ function createZapierApi(options) {
|
|
|
528
518
|
throw customError;
|
|
529
519
|
}
|
|
530
520
|
}
|
|
531
|
-
if (response.status >= 400 && response.status < 500 &&
|
|
521
|
+
if (response.status >= 400 && response.status < 500 && true) {
|
|
532
522
|
throw new Error(
|
|
533
523
|
`Authentication required (HTTP ${response.status}). Please provide a token in options or set ZAPIER_TOKEN environment variable.`
|
|
534
524
|
);
|
|
@@ -541,14 +531,19 @@ function createZapierApi(options) {
|
|
|
541
531
|
return await response.text();
|
|
542
532
|
}
|
|
543
533
|
}
|
|
544
|
-
async function plainFetch(
|
|
545
|
-
|
|
546
|
-
|
|
534
|
+
async function plainFetch(path, init) {
|
|
535
|
+
if (!path.startsWith("/")) {
|
|
536
|
+
throw new Error(
|
|
537
|
+
`plainFetch expects a path starting with '/', got: ${path}`
|
|
538
|
+
);
|
|
539
|
+
}
|
|
540
|
+
const { url, subdomainConfig } = buildUrl(path, init?.searchParams);
|
|
541
|
+
const headers = await buildHeaders(init, subdomainConfig);
|
|
547
542
|
const finalHeaders = {
|
|
548
543
|
...headers,
|
|
549
544
|
...init?.headers ? init.headers instanceof Headers ? Object.fromEntries(init.headers.entries()) : init.headers : {}
|
|
550
545
|
};
|
|
551
|
-
return await
|
|
546
|
+
return await fetch(url, {
|
|
552
547
|
...init,
|
|
553
548
|
headers: finalHeaders
|
|
554
549
|
});
|
|
@@ -563,11 +558,9 @@ function createZapierApi(options) {
|
|
|
563
558
|
body: data ? JSON.stringify(data) : void 0,
|
|
564
559
|
headers,
|
|
565
560
|
searchParams: options2.searchParams,
|
|
566
|
-
authRequired: options2.authRequired
|
|
567
|
-
customErrorHandler: options2.customErrorHandler
|
|
561
|
+
authRequired: options2.authRequired
|
|
568
562
|
});
|
|
569
|
-
|
|
570
|
-
return handleResponse(response, options2.customErrorHandler, hadAuthToken);
|
|
563
|
+
return handleResponse(response, options2.customErrorHandler);
|
|
571
564
|
}
|
|
572
565
|
return {
|
|
573
566
|
async get(path, options2 = {}) {
|
|
@@ -583,12 +576,12 @@ function createZapierApi(options) {
|
|
|
583
576
|
return fetchJson("DELETE", path, void 0, options2);
|
|
584
577
|
},
|
|
585
578
|
async poll(path, options2 = {}) {
|
|
586
|
-
const url = buildUrl(path, options2.searchParams);
|
|
587
|
-
const headers = await buildHeaders(options2);
|
|
588
579
|
return pollUntilComplete({
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
580
|
+
fetchPoll: () => plainFetch(path, {
|
|
581
|
+
method: "GET",
|
|
582
|
+
searchParams: options2.searchParams,
|
|
583
|
+
authRequired: options2.authRequired
|
|
584
|
+
}),
|
|
592
585
|
maxAttempts: options2.maxAttempts,
|
|
593
586
|
initialDelay: options2.initialDelay,
|
|
594
587
|
maxDelay: options2.maxDelay,
|
|
@@ -597,8 +590,8 @@ function createZapierApi(options) {
|
|
|
597
590
|
resultExtractor: options2.resultExtractor
|
|
598
591
|
});
|
|
599
592
|
},
|
|
600
|
-
async fetch(
|
|
601
|
-
return plainFetch(
|
|
593
|
+
async fetch(path, init) {
|
|
594
|
+
return plainFetch(path, init);
|
|
602
595
|
}
|
|
603
596
|
};
|
|
604
597
|
}
|
|
@@ -1445,13 +1438,13 @@ async function bundleCode(options) {
|
|
|
1445
1438
|
}
|
|
1446
1439
|
}
|
|
1447
1440
|
|
|
1448
|
-
// src/functions/
|
|
1441
|
+
// src/functions/request/index.ts
|
|
1449
1442
|
function transformUrlToRelayPath(url) {
|
|
1450
1443
|
const targetUrl = new URL(url);
|
|
1451
1444
|
const relayPath = `/relay/${targetUrl.hostname}${targetUrl.pathname}${targetUrl.search}${targetUrl.hash}`;
|
|
1452
1445
|
return relayPath;
|
|
1453
1446
|
}
|
|
1454
|
-
async function
|
|
1447
|
+
async function request(options) {
|
|
1455
1448
|
const {
|
|
1456
1449
|
url,
|
|
1457
1450
|
method = "GET",
|
|
@@ -1502,44 +1495,14 @@ async function relayFetch(url, options = {}, config = {}) {
|
|
|
1502
1495
|
if (authenticationTemplate) {
|
|
1503
1496
|
headers["X-Authentication-Template"] = authenticationTemplate;
|
|
1504
1497
|
}
|
|
1505
|
-
const requestOptions = {
|
|
1506
|
-
headers,
|
|
1507
|
-
authRequired: false,
|
|
1508
|
-
// Disable automatic Authorization header
|
|
1509
|
-
customErrorHandler: (response) => {
|
|
1510
|
-
if (!response.ok) {
|
|
1511
|
-
return new Error(
|
|
1512
|
-
`Relay request failed: ${response.status} ${response.statusText}`
|
|
1513
|
-
);
|
|
1514
|
-
}
|
|
1515
|
-
return void 0;
|
|
1516
|
-
}
|
|
1517
|
-
};
|
|
1518
|
-
let token = config.token;
|
|
1519
|
-
if (!token && config.getToken) {
|
|
1520
|
-
token = await config.getToken();
|
|
1521
|
-
}
|
|
1522
|
-
if (!token) {
|
|
1523
|
-
const { getTokenFromEnvOrConfig: getTokenFromEnvOrConfig2 } = await Promise.resolve().then(() => (init_auth(), auth_exports));
|
|
1524
|
-
token = await getTokenFromEnvOrConfig2({
|
|
1525
|
-
onEvent: config.onEvent,
|
|
1526
|
-
fetch: config.fetch
|
|
1527
|
-
});
|
|
1528
|
-
}
|
|
1529
|
-
if (token) {
|
|
1530
|
-
const { getAuthorizationHeader: getAuthorizationHeader2 } = await Promise.resolve().then(() => (init_auth2(), auth_exports2));
|
|
1531
|
-
headers["X-Relay-Authorization"] = getAuthorizationHeader2(token);
|
|
1532
|
-
}
|
|
1533
1498
|
return await api.fetch(relayPath, {
|
|
1534
1499
|
method,
|
|
1535
1500
|
body,
|
|
1536
|
-
headers
|
|
1537
|
-
authRequired: requestOptions.authRequired,
|
|
1538
|
-
customErrorHandler: requestOptions.customErrorHandler
|
|
1501
|
+
headers
|
|
1539
1502
|
});
|
|
1540
1503
|
}
|
|
1541
|
-
var
|
|
1542
|
-
url: zod.z.string().url().describe("The URL to
|
|
1504
|
+
var RelayRequestSchema = zod.z.object({
|
|
1505
|
+
url: zod.z.string().url().describe("The URL to request (will be proxied through Relay)"),
|
|
1543
1506
|
method: zod.z.enum(["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS"]).optional().describe("HTTP method"),
|
|
1544
1507
|
body: zod.z.string().optional().describe("Request body as a string"),
|
|
1545
1508
|
authenticationId: zod.z.number().int().optional().describe("Zapier authentication ID to use for the request"),
|
|
@@ -1549,6 +1512,7 @@ var RelayFetchSchema = zod.z.object({
|
|
|
1549
1512
|
),
|
|
1550
1513
|
headers: zod.z.record(zod.z.string()).optional().describe("Request headers")
|
|
1551
1514
|
}).describe("Make authenticated HTTP requests through Zapier's Relay service");
|
|
1515
|
+
var RelayFetchSchema = RelayRequestSchema;
|
|
1552
1516
|
var AppItemSchema = withFormatter(
|
|
1553
1517
|
zod.z.object({
|
|
1554
1518
|
key: zod.z.string(),
|
|
@@ -1884,11 +1848,11 @@ var bundleCodeInfo = {
|
|
|
1884
1848
|
implementation: bundleCode
|
|
1885
1849
|
};
|
|
1886
1850
|
|
|
1887
|
-
// src/functions/
|
|
1888
|
-
var
|
|
1889
|
-
name: "
|
|
1890
|
-
inputSchema:
|
|
1891
|
-
implementation:
|
|
1851
|
+
// src/functions/request/info.ts
|
|
1852
|
+
var requestInfo = {
|
|
1853
|
+
name: "request",
|
|
1854
|
+
inputSchema: RelayRequestSchema,
|
|
1855
|
+
implementation: request
|
|
1892
1856
|
};
|
|
1893
1857
|
|
|
1894
1858
|
// src/sdk.ts
|
|
@@ -1905,7 +1869,7 @@ var functionRegistry = [
|
|
|
1905
1869
|
listFieldsInfo,
|
|
1906
1870
|
generateTypesInfo,
|
|
1907
1871
|
bundleCodeInfo,
|
|
1908
|
-
|
|
1872
|
+
requestInfo
|
|
1909
1873
|
];
|
|
1910
1874
|
function createZapierSdk(options = {}) {
|
|
1911
1875
|
const {
|
|
@@ -1941,16 +1905,11 @@ function createZapierSdk(options = {}) {
|
|
|
1941
1905
|
generateTypes: (options2) => generateTypes({ ...options2, api }),
|
|
1942
1906
|
bundleCode: (options2) => bundleCode(options2),
|
|
1943
1907
|
// No API config needed
|
|
1944
|
-
|
|
1945
|
-
};
|
|
1946
|
-
const fullSdk = {
|
|
1947
|
-
...baseSdk,
|
|
1948
|
-
// Add plugins - apps plugin gets the base SDK cast as full ZapierSdk type
|
|
1949
|
-
// This is safe because by the time plugin functions are called, fullSdk will be complete
|
|
1950
|
-
apps: createAppsPlugin({
|
|
1951
|
-
sdk: baseSdk
|
|
1952
|
-
})
|
|
1908
|
+
request: (options2) => request({ ...options2, api })
|
|
1953
1909
|
};
|
|
1910
|
+
const fullSdk = baseSdk;
|
|
1911
|
+
fullSdk.apps = createAppsPlugin({ sdk: fullSdk });
|
|
1912
|
+
fullSdk.fetch = createFetchPlugin({ sdk: fullSdk });
|
|
1954
1913
|
return fullSdk;
|
|
1955
1914
|
}
|
|
1956
1915
|
|
|
@@ -1966,6 +1925,7 @@ exports.OffsetPropertySchema = OffsetPropertySchema;
|
|
|
1966
1925
|
exports.OutputPropertySchema = OutputPropertySchema;
|
|
1967
1926
|
exports.ParamsPropertySchema = ParamsPropertySchema;
|
|
1968
1927
|
exports.RelayFetchSchema = RelayFetchSchema;
|
|
1928
|
+
exports.RelayRequestSchema = RelayRequestSchema;
|
|
1969
1929
|
exports.ZapierSdkError = ZapierSdkError;
|
|
1970
1930
|
exports.actionKeyResolver = actionKeyResolver;
|
|
1971
1931
|
exports.actionTypeResolver = actionTypeResolver;
|
|
@@ -1973,8 +1933,8 @@ exports.appKeyResolver = appKeyResolver;
|
|
|
1973
1933
|
exports.authenticationIdResolver = authenticationIdResolver;
|
|
1974
1934
|
exports.bundleCode = bundleCode;
|
|
1975
1935
|
exports.createAppsPlugin = createAppsPlugin;
|
|
1936
|
+
exports.createFetchPlugin = createFetchPlugin;
|
|
1976
1937
|
exports.createZapierSdk = createZapierSdk;
|
|
1977
|
-
exports.fetch = fetch;
|
|
1978
1938
|
exports.findFirstAuthentication = findFirstAuthentication;
|
|
1979
1939
|
exports.findUniqueAuthentication = findUniqueAuthentication;
|
|
1980
1940
|
exports.generateTypes = generateTypes;
|
|
@@ -1997,5 +1957,6 @@ exports.listApps = listApps;
|
|
|
1997
1957
|
exports.listAuthentications = listAuthentications;
|
|
1998
1958
|
exports.listFields = listFields;
|
|
1999
1959
|
exports.relayFetch = relayFetch;
|
|
1960
|
+
exports.request = request;
|
|
2000
1961
|
exports.resolverRegistry = resolverRegistry;
|
|
2001
1962
|
exports.runAction = runAction;
|
package/dist/index.d.mts
CHANGED
|
@@ -209,9 +209,17 @@ type ParamsProperty = z.infer<typeof ParamsPropertySchema>;
|
|
|
209
209
|
interface AppFactoryOptions {
|
|
210
210
|
authenticationId: number;
|
|
211
211
|
}
|
|
212
|
-
interface
|
|
212
|
+
interface BaseActionTypeProxy {
|
|
213
213
|
[action: string]: (options?: ActionExecutionOptions) => Promise<ActionExecutionResult>;
|
|
214
214
|
}
|
|
215
|
+
interface FetchActionType {
|
|
216
|
+
fetch: (url: string | URL, init?: RequestInit & {
|
|
217
|
+
authenticationId?: number;
|
|
218
|
+
callbackUrl?: string;
|
|
219
|
+
authenticationTemplate?: string;
|
|
220
|
+
}) => Promise<Response>;
|
|
221
|
+
}
|
|
222
|
+
type ActionTypeProxy = BaseActionTypeProxy & Partial<FetchActionType>;
|
|
215
223
|
interface AppProxy {
|
|
216
224
|
[type: string]: ActionTypeProxy;
|
|
217
225
|
}
|
|
@@ -487,7 +495,7 @@ interface BundleCodeSdkFunction {
|
|
|
487
495
|
bundleCode: (options: BundleCodeOptions) => Promise<string>;
|
|
488
496
|
}
|
|
489
497
|
|
|
490
|
-
declare const
|
|
498
|
+
declare const RelayRequestSchema: z.ZodObject<{
|
|
491
499
|
url: z.ZodString;
|
|
492
500
|
method: z.ZodOptional<z.ZodEnum<["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS"]>>;
|
|
493
501
|
body: z.ZodOptional<z.ZodString>;
|
|
@@ -512,17 +520,61 @@ declare const RelayFetchSchema: z.ZodObject<{
|
|
|
512
520
|
authenticationTemplate?: string | undefined;
|
|
513
521
|
headers?: Record<string, string> | undefined;
|
|
514
522
|
}>;
|
|
515
|
-
type
|
|
523
|
+
type RelayRequestOptions$1 = z.infer<typeof RelayRequestSchema> & FunctionOptions & {
|
|
516
524
|
/** Base URL for Relay service */
|
|
517
525
|
relayBaseUrl?: string;
|
|
518
526
|
};
|
|
519
|
-
interface
|
|
520
|
-
|
|
527
|
+
interface RelayRequestSdkFunction {
|
|
528
|
+
request: (options: RelayRequestOptions$1) => Promise<Response>;
|
|
529
|
+
}
|
|
530
|
+
declare const RelayFetchSchema: z.ZodObject<{
|
|
531
|
+
url: z.ZodString;
|
|
532
|
+
method: z.ZodOptional<z.ZodEnum<["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS"]>>;
|
|
533
|
+
body: z.ZodOptional<z.ZodString>;
|
|
534
|
+
authenticationId: z.ZodOptional<z.ZodNumber>;
|
|
535
|
+
callbackUrl: z.ZodOptional<z.ZodString>;
|
|
536
|
+
authenticationTemplate: z.ZodOptional<z.ZodString>;
|
|
537
|
+
headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
538
|
+
}, "strip", z.ZodTypeAny, {
|
|
539
|
+
url: string;
|
|
540
|
+
authenticationId?: number | undefined;
|
|
541
|
+
method?: "GET" | "POST" | "PUT" | "DELETE" | "PATCH" | "HEAD" | "OPTIONS" | undefined;
|
|
542
|
+
body?: string | undefined;
|
|
543
|
+
callbackUrl?: string | undefined;
|
|
544
|
+
authenticationTemplate?: string | undefined;
|
|
545
|
+
headers?: Record<string, string> | undefined;
|
|
546
|
+
}, {
|
|
547
|
+
url: string;
|
|
548
|
+
authenticationId?: number | undefined;
|
|
549
|
+
method?: "GET" | "POST" | "PUT" | "DELETE" | "PATCH" | "HEAD" | "OPTIONS" | undefined;
|
|
550
|
+
body?: string | undefined;
|
|
551
|
+
callbackUrl?: string | undefined;
|
|
552
|
+
authenticationTemplate?: string | undefined;
|
|
553
|
+
headers?: Record<string, string> | undefined;
|
|
554
|
+
}>;
|
|
555
|
+
|
|
556
|
+
interface FetchPluginOptions {
|
|
557
|
+
sdk: ZapierSdk;
|
|
558
|
+
}
|
|
559
|
+
/**
|
|
560
|
+
* Creates a fetch function with standard fetch signature that delegates to sdk.request
|
|
561
|
+
*/
|
|
562
|
+
declare function createFetchPlugin(options: FetchPluginOptions): (url: string | URL, init?: RequestInit & {
|
|
563
|
+
authenticationId?: number;
|
|
564
|
+
callbackUrl?: string;
|
|
565
|
+
authenticationTemplate?: string;
|
|
566
|
+
}) => Promise<Response>;
|
|
567
|
+
interface FetchPluginSdkExtension {
|
|
568
|
+
fetch: (url: string | URL, init?: RequestInit & {
|
|
569
|
+
authenticationId?: number;
|
|
570
|
+
callbackUrl?: string;
|
|
571
|
+
authenticationTemplate?: string;
|
|
572
|
+
}) => Promise<Response>;
|
|
521
573
|
}
|
|
522
574
|
|
|
523
|
-
interface ZapierSdkFunctions extends ListActionsSdkFunction, GetActionSdkFunction, GetAppSdkFunction, RunActionSdkFunction, ListFieldsSdkFunction, ListAuthenticationsSdkFunction, GetAuthenticationSdkFunction, FindFirstAuthenticationSdkFunction, FindUniqueAuthenticationSdkFunction, GenerateTypesSdkFunction, ListAppsSdkFunction, BundleCodeSdkFunction,
|
|
575
|
+
interface ZapierSdkFunctions extends ListActionsSdkFunction, GetActionSdkFunction, GetAppSdkFunction, RunActionSdkFunction, ListFieldsSdkFunction, ListAuthenticationsSdkFunction, GetAuthenticationSdkFunction, FindFirstAuthenticationSdkFunction, FindUniqueAuthenticationSdkFunction, GenerateTypesSdkFunction, ListAppsSdkFunction, BundleCodeSdkFunction, RelayRequestSdkFunction {
|
|
524
576
|
}
|
|
525
|
-
interface ZapierSdkPlugins extends AppsPluginSdkExtension {
|
|
577
|
+
interface ZapierSdkPlugins extends AppsPluginSdkExtension, FetchPluginSdkExtension {
|
|
526
578
|
}
|
|
527
579
|
interface BaseZapierSdk extends ZapierSdkFunctions {
|
|
528
580
|
__registry: Array<{
|
|
@@ -786,11 +838,11 @@ declare function generateTypes(options: GenerateTypesOptions): Promise<string>;
|
|
|
786
838
|
*/
|
|
787
839
|
declare function bundleCode(options: BundleCodeOptions): Promise<string>;
|
|
788
840
|
|
|
789
|
-
interface
|
|
841
|
+
interface RelayRequestOptions {
|
|
790
842
|
/** HTTP method */
|
|
791
843
|
method?: string;
|
|
792
|
-
/** Request body
|
|
793
|
-
body?:
|
|
844
|
+
/** Request body (can be string, FormData, Blob, etc.) */
|
|
845
|
+
body?: BodyInit | null;
|
|
794
846
|
/** Request headers */
|
|
795
847
|
headers?: HeadersInit;
|
|
796
848
|
/** Zapier authentication ID to use for the request */
|
|
@@ -817,13 +869,13 @@ interface RelayFetchConfig extends FunctionOptions {
|
|
|
817
869
|
* @returns Promise<Response> - The response from the request
|
|
818
870
|
*/
|
|
819
871
|
/**
|
|
820
|
-
* Schema-compatible wrapper function for the
|
|
872
|
+
* Schema-compatible wrapper function for the request functionality
|
|
821
873
|
*/
|
|
822
|
-
declare function
|
|
874
|
+
declare function request(options: {
|
|
823
875
|
url: string;
|
|
824
876
|
method?: string;
|
|
825
|
-
body?:
|
|
826
|
-
headers?:
|
|
877
|
+
body?: BodyInit | null;
|
|
878
|
+
headers?: HeadersInit;
|
|
827
879
|
authenticationId?: number;
|
|
828
880
|
callbackUrl?: string;
|
|
829
881
|
authenticationTemplate?: string;
|
|
@@ -831,10 +883,10 @@ declare function fetch$1(options: {
|
|
|
831
883
|
/**
|
|
832
884
|
* Internal fetch implementation
|
|
833
885
|
*/
|
|
834
|
-
declare function relayFetch(url: string | URL, options?:
|
|
886
|
+
declare function relayFetch(url: string | URL, options?: RelayRequestOptions, config?: RelayFetchConfig): Promise<Response>;
|
|
835
887
|
|
|
836
888
|
interface ZapierSdkOptions extends BaseSdkOptions {
|
|
837
889
|
}
|
|
838
890
|
declare function createZapierSdk(options?: ZapierSdkOptions): ZapierSdk;
|
|
839
891
|
|
|
840
|
-
export { type Action, type ActionExecutionOptions, type ActionExecutionResult, type ActionField, type ActionFieldChoice, type ActionKeyProperty, ActionKeyPropertySchema, type ActionProxy, type ActionTypeProperty, ActionTypePropertySchema, type ApiEvent, type AppKeyProperty, AppKeyPropertySchema, AppNotFoundError, type AppsPluginOptions, type AppsPluginSdkExtension, type AuthEvent, type AuthObject, type AuthOptions, type Authentication, type AuthenticationIdProperty, AuthenticationIdPropertySchema, type AuthenticationsResponse, type BaseSdkOptions, type BaseZapierSdk, type Choice, type DebugProperty, DebugPropertySchema, type EventCallback, type Field, type FunctionOptions, type InputsProperty, InputsPropertySchema, type Integration, type LimitProperty, LimitPropertySchema, type LoadingEvent, type NeedsRequest, type NeedsResponse, type OffsetProperty, OffsetPropertySchema, type OutputProperty, OutputPropertySchema, type ParamsProperty, ParamsPropertySchema, RelayFetchSchema, type ResolverName, type ResolverType, type SdkEvent, type Trigger, type ZapierSdk, ZapierSdkError, type ZapierSdkOptions, actionKeyResolver, actionTypeResolver, appKeyResolver, authenticationIdResolver, bundleCode, createAppsPlugin,
|
|
892
|
+
export { type Action, type ActionExecutionOptions, type ActionExecutionResult, type ActionField, type ActionFieldChoice, type ActionKeyProperty, ActionKeyPropertySchema, type ActionProxy, type ActionTypeProperty, ActionTypePropertySchema, type ApiEvent, type AppKeyProperty, AppKeyPropertySchema, AppNotFoundError, type AppsPluginOptions, type AppsPluginSdkExtension, type AuthEvent, type AuthObject, type AuthOptions, type Authentication, type AuthenticationIdProperty, AuthenticationIdPropertySchema, type AuthenticationsResponse, type BaseSdkOptions, type BaseZapierSdk, type Choice, type DebugProperty, DebugPropertySchema, type EventCallback, type FetchPluginOptions, type FetchPluginSdkExtension, type Field, type FunctionOptions, type InputsProperty, InputsPropertySchema, type Integration, type LimitProperty, LimitPropertySchema, type LoadingEvent, type NeedsRequest, type NeedsResponse, type OffsetProperty, OffsetPropertySchema, type OutputProperty, OutputPropertySchema, type ParamsProperty, ParamsPropertySchema, RelayFetchSchema, RelayRequestSchema, type ResolverName, type ResolverType, type SdkEvent, type Trigger, type ZapierSdk, ZapierSdkError, type ZapierSdkOptions, actionKeyResolver, actionTypeResolver, appKeyResolver, authenticationIdResolver, bundleCode, createAppsPlugin, createFetchPlugin, createZapierSdk, findFirstAuthentication, findUniqueAuthentication, generateTypes, getAction, getApp, getAuthentication, getResolutionOrder, getResolutionOrderForParams, getResolvableParams, getResolver, getResolversForMissingParams, getTokenFromCliLogin, getTokenFromEnv, getTokenFromEnvOrConfig, hasResolver, inputsResolver, isPositional, listActions, listApps, listAuthentications, listFields, relayFetch, request, resolverRegistry, runAction };
|