@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.d.ts CHANGED
@@ -209,9 +209,17 @@ type ParamsProperty = z.infer<typeof ParamsPropertySchema>;
209
209
  interface AppFactoryOptions {
210
210
  authenticationId: number;
211
211
  }
212
- interface ActionTypeProxy {
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 RelayFetchSchema: z.ZodObject<{
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 RelayFetchOptions$1 = z.infer<typeof RelayFetchSchema> & FunctionOptions & {
523
+ type RelayRequestOptions$1 = z.infer<typeof RelayRequestSchema> & FunctionOptions & {
516
524
  /** Base URL for Relay service */
517
525
  relayBaseUrl?: string;
518
526
  };
519
- interface RelayFetchSdkFunction {
520
- fetch: (options: RelayFetchOptions$1) => Promise<Response>;
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, RelayFetchSdkFunction {
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 RelayFetchOptions {
841
+ interface RelayRequestOptions {
790
842
  /** HTTP method */
791
843
  method?: string;
792
- /** Request body as a string */
793
- body?: string;
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 fetch functionality
872
+ * Schema-compatible wrapper function for the request functionality
821
873
  */
822
- declare function fetch$1(options: {
874
+ declare function request(options: {
823
875
  url: string;
824
876
  method?: string;
825
- body?: string;
826
- headers?: Record<string, string>;
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?: RelayFetchOptions, config?: RelayFetchConfig): Promise<Response>;
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, createZapierSdk, fetch$1 as fetch, findFirstAuthentication, findUniqueAuthentication, generateTypes, getAction, getApp, getAuthentication, getResolutionOrder, getResolutionOrderForParams, getResolvableParams, getResolver, getResolversForMissingParams, getTokenFromCliLogin, getTokenFromEnv, getTokenFromEnvOrConfig, hasResolver, inputsResolver, isPositional, listActions, listApps, listAuthentications, listFields, relayFetch, resolverRegistry, runAction };
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 };
package/dist/index.mjs CHANGED
@@ -1,70 +1,5 @@
1
1
  import { z } from 'zod';
2
2
 
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __esm = (fn, res) => function __init() {
6
- return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
7
- };
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
-
13
- // src/auth.ts
14
- var auth_exports = {};
15
- __export(auth_exports, {
16
- getTokenFromCliLogin: () => getTokenFromCliLogin,
17
- getTokenFromEnv: () => getTokenFromEnv,
18
- getTokenFromEnvOrConfig: () => getTokenFromEnvOrConfig
19
- });
20
- function getTokenFromEnv() {
21
- return process.env.ZAPIER_TOKEN;
22
- }
23
- async function getTokenFromCliLogin(options = {}) {
24
- try {
25
- const { getToken } = await import('@zapier/zapier-sdk-cli-login');
26
- return await getToken(options);
27
- } catch {
28
- return void 0;
29
- }
30
- }
31
- async function getTokenFromEnvOrConfig(options = {}) {
32
- const envToken = getTokenFromEnv();
33
- if (envToken) {
34
- return envToken;
35
- }
36
- return getTokenFromCliLogin(options);
37
- }
38
- var init_auth = __esm({
39
- "src/auth.ts"() {
40
- }
41
- });
42
-
43
- // src/api/auth.ts
44
- var auth_exports2 = {};
45
- __export(auth_exports2, {
46
- getAuthorizationHeader: () => getAuthorizationHeader,
47
- isJwt: () => isJwt
48
- });
49
- function isJwt(token) {
50
- const parts = token.split(".");
51
- if (parts.length !== 3) {
52
- return false;
53
- }
54
- const base64UrlPattern = /^[A-Za-z0-9_-]+$/;
55
- return parts.every((part) => part.length > 0 && base64UrlPattern.test(part));
56
- }
57
- function getAuthorizationHeader(token) {
58
- if (isJwt(token)) {
59
- return `JWT ${token}`;
60
- }
61
- return `Bearer ${token}`;
62
- }
63
- var init_auth2 = __esm({
64
- "src/api/auth.ts"() {
65
- }
66
- });
67
-
68
3
  // src/types/domain.ts
69
4
  var ZapierSdkError = class extends Error {
70
5
  constructor(message, code) {
@@ -151,16 +86,16 @@ function createActionFunction(appKey, actionType, actionKey, options, pinnedAuth
151
86
  }
152
87
  function createActionTypeProxy(appKey, actionType, options, pinnedAuthId) {
153
88
  if (actionType === "fetch") {
154
- return async (fetchOptions) => {
89
+ return async (url, init) => {
155
90
  const { sdk } = options;
156
- const authenticationId = pinnedAuthId || fetchOptions.authenticationId;
91
+ const authenticationId = pinnedAuthId || init?.authenticationId;
157
92
  if (!authenticationId) {
158
93
  throw new Error(
159
94
  `Authentication ID is required for fetch. Either use the factory pattern: sdk.apps.${appKey}({ authenticationId }).fetch(...) or provide authenticationId in the fetch call.`
160
95
  );
161
96
  }
162
- return sdk.fetch({
163
- ...fetchOptions,
97
+ return sdk.fetch(url, {
98
+ ...init,
164
99
  authenticationId
165
100
  });
166
101
  };
@@ -233,8 +168,47 @@ function createAppsPlugin(options) {
233
168
  return createAppsProxy(options);
234
169
  }
235
170
 
236
- // src/index.ts
237
- init_auth();
171
+ // src/plugins/fetch/index.ts
172
+ function createFetchPlugin(options) {
173
+ const { sdk } = options;
174
+ return async function fetch(url, init) {
175
+ const {
176
+ authenticationId,
177
+ callbackUrl,
178
+ authenticationTemplate,
179
+ ...fetchInit
180
+ } = init || {};
181
+ return sdk.request({
182
+ url: url.toString(),
183
+ method: fetchInit.method,
184
+ body: fetchInit.body,
185
+ headers: fetchInit.headers,
186
+ authenticationId,
187
+ callbackUrl,
188
+ authenticationTemplate
189
+ });
190
+ };
191
+ }
192
+
193
+ // src/auth.ts
194
+ function getTokenFromEnv() {
195
+ return process.env.ZAPIER_TOKEN;
196
+ }
197
+ async function getTokenFromCliLogin(options = {}) {
198
+ try {
199
+ const { getToken } = await import('@zapier/zapier-sdk-cli-login');
200
+ return await getToken(options);
201
+ } catch {
202
+ return void 0;
203
+ }
204
+ }
205
+ async function getTokenFromEnvOrConfig(options = {}) {
206
+ const envToken = getTokenFromEnv();
207
+ if (envToken) {
208
+ return envToken;
209
+ }
210
+ return getTokenFromCliLogin(options);
211
+ }
238
212
 
239
213
  // src/resolvers/appKey.ts
240
214
  var appKeyResolver = {
@@ -386,8 +360,21 @@ function getResolutionOrderForParams(paramNames) {
386
360
  return order;
387
361
  }
388
362
 
389
- // src/api/index.ts
390
- init_auth2();
363
+ // src/api/auth.ts
364
+ function isJwt(token) {
365
+ const parts = token.split(".");
366
+ if (parts.length !== 3) {
367
+ return false;
368
+ }
369
+ const base64UrlPattern = /^[A-Za-z0-9_-]+$/;
370
+ return parts.every((part) => part.length > 0 && base64UrlPattern.test(part));
371
+ }
372
+ function getAuthorizationHeader(token) {
373
+ if (isJwt(token)) {
374
+ return `JWT ${token}`;
375
+ }
376
+ return `Bearer ${token}`;
377
+ }
391
378
 
392
379
  // src/api/debug.ts
393
380
  function createDebugLogger(enabled) {
@@ -433,9 +420,7 @@ function createDebugFetch(options) {
433
420
  // src/api/polling.ts
434
421
  async function pollUntilComplete(options) {
435
422
  const {
436
- fetch: fetch2,
437
- url,
438
- headers = {},
423
+ fetchPoll,
439
424
  maxAttempts = 30,
440
425
  initialDelay = 50,
441
426
  maxDelay = 1e3,
@@ -445,7 +430,7 @@ async function pollUntilComplete(options) {
445
430
  } = options;
446
431
  let delay = initialDelay;
447
432
  for (let attempt = 0; attempt < maxAttempts; attempt++) {
448
- const response = await fetch2(url, { headers });
433
+ const response = await fetchPoll();
449
434
  if (response.status === successStatus) {
450
435
  const result = await response.json();
451
436
  return resultExtractor(result);
@@ -457,7 +442,7 @@ async function pollUntilComplete(options) {
457
442
  }
458
443
  } else {
459
444
  throw new Error(
460
- `Request failed: GET ${url} - ${response.status} ${response.statusText}`
445
+ `Poll request failed: ${response.status} ${response.statusText}`
461
446
  );
462
447
  }
463
448
  }
@@ -465,9 +450,11 @@ async function pollUntilComplete(options) {
465
450
  }
466
451
 
467
452
  // src/api/client.ts
468
- init_auth2();
469
- init_auth();
470
- var SUBDOMAIN_PREFIXES = /* @__PURE__ */ new Set(["relay"]);
453
+ var SUBDOMAIN_PREFIXES = {
454
+ relay: {
455
+ authHeader: "X-Relay-Authorization"
456
+ }
457
+ };
471
458
  function createZapierApi(options) {
472
459
  const {
473
460
  baseUrl,
@@ -478,12 +465,14 @@ function createZapierApi(options) {
478
465
  onEvent
479
466
  } = options;
480
467
  const debugLog = createDebugLogger(debug);
481
- const fetch2 = createDebugFetch({ originalFetch, debugLog });
468
+ const fetch = createDebugFetch({ originalFetch, debugLog });
482
469
  function buildUrl(path, searchParams) {
483
470
  const pathSegments = path.split("/").filter(Boolean);
484
471
  let finalBaseUrl = baseUrl;
485
- if (pathSegments.length > 0 && SUBDOMAIN_PREFIXES.has(pathSegments[0])) {
472
+ let subdomainConfig;
473
+ if (pathSegments.length > 0 && pathSegments[0] in SUBDOMAIN_PREFIXES) {
486
474
  const subdomain = pathSegments[0];
475
+ subdomainConfig = SUBDOMAIN_PREFIXES[subdomain];
487
476
  const baseUrlObj = new URL(baseUrl);
488
477
  baseUrlObj.hostname = `${subdomain}.${baseUrlObj.hostname}`;
489
478
  finalBaseUrl = baseUrlObj.toString();
@@ -495,9 +484,9 @@ function createZapierApi(options) {
495
484
  url.searchParams.set(key, value);
496
485
  });
497
486
  }
498
- return url.toString();
487
+ return { url: url.toString(), subdomainConfig };
499
488
  }
500
- async function buildHeaders(options2 = {}) {
489
+ async function buildHeaders(options2 = {}, subdomainConfig) {
501
490
  const headers = {
502
491
  ...options2.headers
503
492
  };
@@ -513,7 +502,8 @@ function createZapierApi(options) {
513
502
  });
514
503
  }
515
504
  if (resolvedToken) {
516
- headers.Authorization = getAuthorizationHeader(resolvedToken);
505
+ const authHeaderName = subdomainConfig?.authHeader || "Authorization";
506
+ headers[authHeaderName] = getAuthorizationHeader(resolvedToken);
517
507
  }
518
508
  }
519
509
  return headers;
@@ -526,7 +516,7 @@ function createZapierApi(options) {
526
516
  throw customError;
527
517
  }
528
518
  }
529
- if (response.status >= 400 && response.status < 500 && !hadAuthToken) {
519
+ if (response.status >= 400 && response.status < 500 && true) {
530
520
  throw new Error(
531
521
  `Authentication required (HTTP ${response.status}). Please provide a token in options or set ZAPIER_TOKEN environment variable.`
532
522
  );
@@ -539,14 +529,19 @@ function createZapierApi(options) {
539
529
  return await response.text();
540
530
  }
541
531
  }
542
- async function plainFetch(input, init) {
543
- const url = typeof input === "string" && !input.startsWith("http") ? buildUrl(input, init?.searchParams) : input.toString();
544
- const headers = await buildHeaders(init);
532
+ async function plainFetch(path, init) {
533
+ if (!path.startsWith("/")) {
534
+ throw new Error(
535
+ `plainFetch expects a path starting with '/', got: ${path}`
536
+ );
537
+ }
538
+ const { url, subdomainConfig } = buildUrl(path, init?.searchParams);
539
+ const headers = await buildHeaders(init, subdomainConfig);
545
540
  const finalHeaders = {
546
541
  ...headers,
547
542
  ...init?.headers ? init.headers instanceof Headers ? Object.fromEntries(init.headers.entries()) : init.headers : {}
548
543
  };
549
- return await fetch2(url, {
544
+ return await fetch(url, {
550
545
  ...init,
551
546
  headers: finalHeaders
552
547
  });
@@ -561,11 +556,9 @@ function createZapierApi(options) {
561
556
  body: data ? JSON.stringify(data) : void 0,
562
557
  headers,
563
558
  searchParams: options2.searchParams,
564
- authRequired: options2.authRequired,
565
- customErrorHandler: options2.customErrorHandler
559
+ authRequired: options2.authRequired
566
560
  });
567
- const hadAuthToken = !!(await buildHeaders(options2)).Authorization;
568
- return handleResponse(response, options2.customErrorHandler, hadAuthToken);
561
+ return handleResponse(response, options2.customErrorHandler);
569
562
  }
570
563
  return {
571
564
  async get(path, options2 = {}) {
@@ -581,12 +574,12 @@ function createZapierApi(options) {
581
574
  return fetchJson("DELETE", path, void 0, options2);
582
575
  },
583
576
  async poll(path, options2 = {}) {
584
- const url = buildUrl(path, options2.searchParams);
585
- const headers = await buildHeaders(options2);
586
577
  return pollUntilComplete({
587
- fetch: fetch2,
588
- url,
589
- headers,
578
+ fetchPoll: () => plainFetch(path, {
579
+ method: "GET",
580
+ searchParams: options2.searchParams,
581
+ authRequired: options2.authRequired
582
+ }),
590
583
  maxAttempts: options2.maxAttempts,
591
584
  initialDelay: options2.initialDelay,
592
585
  maxDelay: options2.maxDelay,
@@ -595,8 +588,8 @@ function createZapierApi(options) {
595
588
  resultExtractor: options2.resultExtractor
596
589
  });
597
590
  },
598
- async fetch(input, init) {
599
- return plainFetch(input, init);
591
+ async fetch(path, init) {
592
+ return plainFetch(path, init);
600
593
  }
601
594
  };
602
595
  }
@@ -1443,13 +1436,13 @@ async function bundleCode(options) {
1443
1436
  }
1444
1437
  }
1445
1438
 
1446
- // src/functions/fetch/index.ts
1439
+ // src/functions/request/index.ts
1447
1440
  function transformUrlToRelayPath(url) {
1448
1441
  const targetUrl = new URL(url);
1449
1442
  const relayPath = `/relay/${targetUrl.hostname}${targetUrl.pathname}${targetUrl.search}${targetUrl.hash}`;
1450
1443
  return relayPath;
1451
1444
  }
1452
- async function fetch(options) {
1445
+ async function request(options) {
1453
1446
  const {
1454
1447
  url,
1455
1448
  method = "GET",
@@ -1500,44 +1493,14 @@ async function relayFetch(url, options = {}, config = {}) {
1500
1493
  if (authenticationTemplate) {
1501
1494
  headers["X-Authentication-Template"] = authenticationTemplate;
1502
1495
  }
1503
- const requestOptions = {
1504
- headers,
1505
- authRequired: false,
1506
- // Disable automatic Authorization header
1507
- customErrorHandler: (response) => {
1508
- if (!response.ok) {
1509
- return new Error(
1510
- `Relay request failed: ${response.status} ${response.statusText}`
1511
- );
1512
- }
1513
- return void 0;
1514
- }
1515
- };
1516
- let token = config.token;
1517
- if (!token && config.getToken) {
1518
- token = await config.getToken();
1519
- }
1520
- if (!token) {
1521
- const { getTokenFromEnvOrConfig: getTokenFromEnvOrConfig2 } = await Promise.resolve().then(() => (init_auth(), auth_exports));
1522
- token = await getTokenFromEnvOrConfig2({
1523
- onEvent: config.onEvent,
1524
- fetch: config.fetch
1525
- });
1526
- }
1527
- if (token) {
1528
- const { getAuthorizationHeader: getAuthorizationHeader2 } = await Promise.resolve().then(() => (init_auth2(), auth_exports2));
1529
- headers["X-Relay-Authorization"] = getAuthorizationHeader2(token);
1530
- }
1531
1496
  return await api.fetch(relayPath, {
1532
1497
  method,
1533
1498
  body,
1534
- headers: requestOptions.headers,
1535
- authRequired: requestOptions.authRequired,
1536
- customErrorHandler: requestOptions.customErrorHandler
1499
+ headers
1537
1500
  });
1538
1501
  }
1539
- var RelayFetchSchema = z.object({
1540
- url: z.string().url().describe("The URL to fetch (will be proxied through Relay)"),
1502
+ var RelayRequestSchema = z.object({
1503
+ url: z.string().url().describe("The URL to request (will be proxied through Relay)"),
1541
1504
  method: z.enum(["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS"]).optional().describe("HTTP method"),
1542
1505
  body: z.string().optional().describe("Request body as a string"),
1543
1506
  authenticationId: z.number().int().optional().describe("Zapier authentication ID to use for the request"),
@@ -1547,6 +1510,7 @@ var RelayFetchSchema = z.object({
1547
1510
  ),
1548
1511
  headers: z.record(z.string()).optional().describe("Request headers")
1549
1512
  }).describe("Make authenticated HTTP requests through Zapier's Relay service");
1513
+ var RelayFetchSchema = RelayRequestSchema;
1550
1514
  var AppItemSchema = withFormatter(
1551
1515
  z.object({
1552
1516
  key: z.string(),
@@ -1882,11 +1846,11 @@ var bundleCodeInfo = {
1882
1846
  implementation: bundleCode
1883
1847
  };
1884
1848
 
1885
- // src/functions/fetch/info.ts
1886
- var fetchInfo = {
1887
- name: "fetch",
1888
- inputSchema: RelayFetchSchema,
1889
- implementation: fetch
1849
+ // src/functions/request/info.ts
1850
+ var requestInfo = {
1851
+ name: "request",
1852
+ inputSchema: RelayRequestSchema,
1853
+ implementation: request
1890
1854
  };
1891
1855
 
1892
1856
  // src/sdk.ts
@@ -1903,7 +1867,7 @@ var functionRegistry = [
1903
1867
  listFieldsInfo,
1904
1868
  generateTypesInfo,
1905
1869
  bundleCodeInfo,
1906
- fetchInfo
1870
+ requestInfo
1907
1871
  ];
1908
1872
  function createZapierSdk(options = {}) {
1909
1873
  const {
@@ -1939,17 +1903,12 @@ function createZapierSdk(options = {}) {
1939
1903
  generateTypes: (options2) => generateTypes({ ...options2, api }),
1940
1904
  bundleCode: (options2) => bundleCode(options2),
1941
1905
  // No API config needed
1942
- fetch: (options2) => fetch({ ...options2, api })
1943
- };
1944
- const fullSdk = {
1945
- ...baseSdk,
1946
- // Add plugins - apps plugin gets the base SDK cast as full ZapierSdk type
1947
- // This is safe because by the time plugin functions are called, fullSdk will be complete
1948
- apps: createAppsPlugin({
1949
- sdk: baseSdk
1950
- })
1906
+ request: (options2) => request({ ...options2, api })
1951
1907
  };
1908
+ const fullSdk = baseSdk;
1909
+ fullSdk.apps = createAppsPlugin({ sdk: fullSdk });
1910
+ fullSdk.fetch = createFetchPlugin({ sdk: fullSdk });
1952
1911
  return fullSdk;
1953
1912
  }
1954
1913
 
1955
- export { ActionKeyPropertySchema, ActionTypePropertySchema, AppKeyPropertySchema, AppNotFoundError, AuthenticationIdPropertySchema, DebugPropertySchema, InputsPropertySchema, LimitPropertySchema, OffsetPropertySchema, OutputPropertySchema, ParamsPropertySchema, RelayFetchSchema, ZapierSdkError, actionKeyResolver, actionTypeResolver, appKeyResolver, authenticationIdResolver, bundleCode, createAppsPlugin, createZapierSdk, fetch, findFirstAuthentication, findUniqueAuthentication, generateTypes, getAction, getApp, getAuthentication, getResolutionOrder, getResolutionOrderForParams, getResolvableParams, getResolver, getResolversForMissingParams, getTokenFromCliLogin, getTokenFromEnv, getTokenFromEnvOrConfig, hasResolver, inputsResolver, isPositional, listActions, listApps, listAuthentications, listFields, relayFetch, resolverRegistry, runAction };
1914
+ export { ActionKeyPropertySchema, ActionTypePropertySchema, AppKeyPropertySchema, AppNotFoundError, AuthenticationIdPropertySchema, DebugPropertySchema, InputsPropertySchema, LimitPropertySchema, OffsetPropertySchema, OutputPropertySchema, ParamsPropertySchema, RelayFetchSchema, RelayRequestSchema, ZapierSdkError, 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 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zapier/zapier-sdk",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "description": "Complete Zapier SDK - combines all Zapier SDK packages",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.mjs",