@zapier/zapier-sdk 0.1.0 → 0.2.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.
Files changed (63) hide show
  1. package/dist/api/client.js +22 -6
  2. package/dist/api/index.d.ts +4 -2
  3. package/dist/api/index.js +5 -4
  4. package/dist/api/types.d.ts +2 -0
  5. package/dist/functions/findFirstAuthentication/index.d.ts +12 -0
  6. package/dist/functions/findFirstAuthentication/index.js +21 -0
  7. package/dist/functions/findFirstAuthentication/info.d.ts +30 -0
  8. package/dist/functions/findFirstAuthentication/info.js +11 -0
  9. package/dist/functions/findFirstAuthentication/schemas.d.ts +42 -0
  10. package/dist/functions/findFirstAuthentication/schemas.js +25 -0
  11. package/dist/functions/findUniqueAuthentication/index.d.ts +13 -0
  12. package/dist/functions/findUniqueAuthentication/index.js +28 -0
  13. package/dist/functions/findUniqueAuthentication/info.d.ts +30 -0
  14. package/dist/functions/findUniqueAuthentication/info.js +11 -0
  15. package/dist/functions/{listAuths → findUniqueAuthentication}/schemas.d.ts +10 -4
  16. package/dist/functions/findUniqueAuthentication/schemas.js +25 -0
  17. package/dist/functions/{listAuths → listAuthentications}/index.d.ts +2 -2
  18. package/dist/functions/{listAuths → listAuthentications}/index.js +24 -11
  19. package/dist/functions/{listAuths → listAuthentications}/info.d.ts +9 -3
  20. package/dist/functions/listAuthentications/info.js +11 -0
  21. package/dist/functions/listAuthentications/schemas.d.ts +44 -0
  22. package/dist/functions/{listAuths → listAuthentications}/schemas.js +10 -2
  23. package/dist/functions/runAction/index.js +1 -3
  24. package/dist/functions/runAction/schemas.d.ts +2 -0
  25. package/dist/index.d.ts +4 -1
  26. package/dist/index.js +10 -3
  27. package/dist/resolvers/authenticationId.js +1 -1
  28. package/dist/schema-utils.d.ts +5 -0
  29. package/dist/schema-utils.js +24 -0
  30. package/dist/schemas/Auth.d.ts +0 -3
  31. package/dist/schemas/Auth.js +1 -8
  32. package/dist/sdk.js +32 -36
  33. package/dist/types/domain.d.ts +1 -0
  34. package/dist/types/properties.js +2 -4
  35. package/dist/types/sdk.d.ts +4 -2
  36. package/dist/utils/getTokenFromConfig.d.ts +7 -0
  37. package/dist/utils/getTokenFromConfig.js +29 -0
  38. package/package.json +1 -3
  39. package/src/api/client.ts +30 -5
  40. package/src/api/index.ts +12 -5
  41. package/src/api/types.ts +2 -0
  42. package/src/functions/findFirstAuthentication/index.ts +24 -0
  43. package/src/functions/findFirstAuthentication/info.ts +9 -0
  44. package/src/functions/findFirstAuthentication/schemas.ts +60 -0
  45. package/src/functions/findUniqueAuthentication/index.ts +35 -0
  46. package/src/functions/findUniqueAuthentication/info.ts +9 -0
  47. package/src/functions/findUniqueAuthentication/schemas.ts +60 -0
  48. package/src/functions/{listAuths → listAuthentications}/index.ts +27 -17
  49. package/src/functions/listAuthentications/info.ts +9 -0
  50. package/src/functions/{listAuths → listAuthentications}/schemas.ts +18 -4
  51. package/src/functions/runAction/index.ts +1 -6
  52. package/src/functions/runAction/schemas.ts +2 -0
  53. package/src/index.ts +6 -1
  54. package/src/resolvers/authenticationId.ts +1 -1
  55. package/src/schema-utils.ts +35 -0
  56. package/src/schemas/Auth.ts +1 -9
  57. package/src/sdk.ts +32 -35
  58. package/src/types/domain.ts +1 -0
  59. package/src/types/properties.ts +4 -4
  60. package/src/types/sdk.ts +6 -2
  61. package/src/utils/getTokenFromConfig.ts +28 -0
  62. package/dist/functions/listAuths/info.js +0 -11
  63. package/src/functions/listAuths/info.ts +0 -9
@@ -11,7 +11,7 @@ const auth_1 = require("./auth");
11
11
  const debug_1 = require("./debug");
12
12
  const polling_1 = require("./polling");
13
13
  function createZapierApi(options) {
14
- const { baseUrl, token, debug = false, fetch: originalFetch = globalThis.fetch, } = options;
14
+ const { baseUrl, token, getToken, debug = false, fetch: originalFetch = globalThis.fetch, } = options;
15
15
  const debugLog = (0, debug_1.createDebugLogger)(debug);
16
16
  const fetch = (0, debug_1.createDebugFetch)({ originalFetch, debugLog });
17
17
  // Helper to build full URLs
@@ -25,13 +25,23 @@ function createZapierApi(options) {
25
25
  return url.toString();
26
26
  }
27
27
  // Helper to build headers
28
- function buildHeaders(options = {}) {
28
+ async function buildHeaders(options = {}) {
29
29
  const headers = {
30
30
  ...options.headers,
31
31
  };
32
32
  // Add auth header if token provided and not explicitly disabled
33
- if (token && options.authRequired !== false) {
34
- headers.Authorization = (0, auth_1.getAuthorizationHeader)(token);
33
+ if (options.authRequired !== false) {
34
+ let resolvedToken = token;
35
+ // Token resolution precedence: explicit token > getToken() > env var
36
+ if (!resolvedToken && getToken) {
37
+ resolvedToken = await getToken();
38
+ }
39
+ if (!resolvedToken) {
40
+ resolvedToken = process.env.ZAPIER_TOKEN;
41
+ }
42
+ if (resolvedToken) {
43
+ headers.Authorization = (0, auth_1.getAuthorizationHeader)(resolvedToken);
44
+ }
35
45
  }
36
46
  return headers;
37
47
  }
@@ -58,7 +68,7 @@ function createZapierApi(options) {
58
68
  // Helper to perform HTTP requests with JSON handling
59
69
  async function fetchJson(method, path, data, options = {}) {
60
70
  const url = buildUrl(path, options.searchParams);
61
- const headers = buildHeaders(options);
71
+ const headers = await buildHeaders(options);
62
72
  // Add Content-Type for JSON requests with body data
63
73
  if (data && typeof data === "object") {
64
74
  headers["Content-Type"] = "application/json";
@@ -85,7 +95,7 @@ function createZapierApi(options) {
85
95
  },
86
96
  async poll(path, options = {}) {
87
97
  const url = buildUrl(path, options.searchParams);
88
- const headers = buildHeaders(options);
98
+ const headers = await buildHeaders(options);
89
99
  return (0, polling_1.pollUntilComplete)({
90
100
  fetch,
91
101
  url,
@@ -98,5 +108,11 @@ function createZapierApi(options) {
98
108
  resultExtractor: options.resultExtractor,
99
109
  });
100
110
  },
111
+ requireAuthTo(operation) {
112
+ // Check if any authentication method is available
113
+ if (!token && !getToken && !process.env.ZAPIER_TOKEN) {
114
+ throw new Error(`Authentication token is required to ${operation}. Please provide token in options or set ZAPIER_TOKEN environment variable.`);
115
+ }
116
+ },
101
117
  };
102
118
  }
@@ -6,6 +6,7 @@
6
6
  * polling, and provides consistent patterns across all services.
7
7
  */
8
8
  export type { ApiClient, ApiClientOptions, RequestOptions, PollOptions, DebugLogger, Integration, Action, Trigger, Field, Choice, ActionExecutionResult, ActionField, ActionFieldChoice, NeedsRequest, NeedsResponse, Authentication, AuthenticationsResponse, } from "./types";
9
+ import type { ApiClient } from "./types";
9
10
  export { isJwt, getAuthorizationHeader } from "./auth";
10
11
  export { createDebugLogger, createDebugFetch } from "./debug";
11
12
  export { pollUntilComplete } from "./polling";
@@ -20,7 +21,8 @@ export declare function generateRequestId(): string;
20
21
  export declare function getOrCreateApiClient(config: {
21
22
  baseUrl?: string;
22
23
  token?: string;
23
- api?: import("./types").ApiClient;
24
+ getToken?: () => Promise<string | undefined>;
25
+ api?: ApiClient;
24
26
  debug?: boolean;
25
27
  fetch?: typeof globalThis.fetch;
26
- }): import("./types").ApiClient;
28
+ }): ApiClient;
package/dist/api/index.js CHANGED
@@ -24,6 +24,8 @@ Object.defineProperty(exports, "pollUntilComplete", { enumerable: true, get: fun
24
24
  // Re-export the main client factory
25
25
  var client_1 = require("./client");
26
26
  Object.defineProperty(exports, "createZapierApi", { enumerable: true, get: function () { return client_1.createZapierApi; } });
27
+ // Import for local use
28
+ const client_2 = require("./client");
27
29
  // Utility Functions
28
30
  function generateRequestId() {
29
31
  return Math.random().toString(36).substring(2) + Date.now().toString(36);
@@ -35,16 +37,15 @@ function generateRequestId() {
35
37
  * @returns ApiClient instance
36
38
  */
37
39
  function getOrCreateApiClient(config) {
38
- const { baseUrl = "https://zapier.com", token = process.env.ZAPIER_TOKEN, api: providedApi, debug = false, fetch: customFetch, } = config;
40
+ const { baseUrl = "https://zapier.com", token, getToken, api: providedApi, debug = false, fetch: customFetch, } = config;
39
41
  // Use provided API client or create a new one
40
42
  if (providedApi) {
41
43
  return providedApi;
42
44
  }
43
- // Import createZapierApi locally to avoid circular imports
44
- const { createZapierApi } = require("./client");
45
- return createZapierApi({
45
+ return (0, client_2.createZapierApi)({
46
46
  baseUrl,
47
47
  token,
48
+ getToken,
48
49
  debug,
49
50
  fetch: customFetch,
50
51
  });
@@ -8,6 +8,7 @@
8
8
  export interface ApiClientOptions {
9
9
  baseUrl: string;
10
10
  token?: string;
11
+ getToken?: () => Promise<string | undefined>;
11
12
  debug?: boolean;
12
13
  fetch?: typeof globalThis.fetch;
13
14
  }
@@ -17,6 +18,7 @@ export interface ApiClient {
17
18
  put: (path: string, data?: any, options?: RequestOptions) => Promise<any>;
18
19
  delete: (path: string, options?: RequestOptions) => Promise<any>;
19
20
  poll: (path: string, options?: PollOptions) => Promise<any>;
21
+ requireAuthTo: (operation: string) => void;
20
22
  }
21
23
  export interface RequestOptions {
22
24
  headers?: Record<string, string>;
@@ -0,0 +1,12 @@
1
+ import type { Authentication } from "../../types/domain";
2
+ import type { FindFirstAuthenticationOptions } from "./schemas";
3
+ /**
4
+ * Find the first authentication matching the given criteria
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 - Filtering and API configuration options
10
+ * @returns Promise<Authentication | null> - First matching authentication or null if not found
11
+ */
12
+ export declare function findFirstAuthentication(options?: Partial<FindFirstAuthenticationOptions>): Promise<Authentication | null>;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.findFirstAuthentication = findFirstAuthentication;
4
+ const listAuthentications_1 = require("../listAuthentications");
5
+ /**
6
+ * Find the first authentication matching the given criteria
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 - Filtering and API configuration options
12
+ * @returns Promise<Authentication | null> - First matching authentication or null if not found
13
+ */
14
+ async function findFirstAuthentication(options = {}) {
15
+ // Use listAuthentications with limit 1 to get the first result
16
+ const auths = await (0, listAuthentications_1.listAuthentications)({
17
+ ...options,
18
+ limit: 1,
19
+ });
20
+ return auths.length > 0 ? auths[0] : null;
21
+ }
@@ -0,0 +1,30 @@
1
+ import { findFirstAuthentication } from "./index";
2
+ export declare const findFirstAuthenticationInfo: {
3
+ name: string;
4
+ inputSchema: import("zod").ZodObject<{
5
+ appKey: import("zod").ZodOptional<import("zod").ZodString>;
6
+ search: import("zod").ZodOptional<import("zod").ZodString>;
7
+ title: import("zod").ZodOptional<import("zod").ZodString>;
8
+ account_id: import("zod").ZodOptional<import("zod").ZodString>;
9
+ owner: import("zod").ZodOptional<import("zod").ZodString>;
10
+ limit: import("zod").ZodOptional<import("zod").ZodDefault<import("zod").ZodNumber>>;
11
+ offset: import("zod").ZodOptional<import("zod").ZodDefault<import("zod").ZodNumber>>;
12
+ }, "strip", import("zod").ZodTypeAny, {
13
+ search?: string | undefined;
14
+ appKey?: string | undefined;
15
+ title?: string | undefined;
16
+ account_id?: string | undefined;
17
+ owner?: string | undefined;
18
+ limit?: number | undefined;
19
+ offset?: number | undefined;
20
+ }, {
21
+ search?: string | undefined;
22
+ appKey?: string | undefined;
23
+ title?: string | undefined;
24
+ account_id?: string | undefined;
25
+ owner?: string | undefined;
26
+ limit?: number | undefined;
27
+ offset?: number | undefined;
28
+ }>;
29
+ implementation: typeof findFirstAuthentication;
30
+ };
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.findFirstAuthenticationInfo = 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.findFirstAuthenticationInfo = {
8
+ name: index_1.findFirstAuthentication.name,
9
+ inputSchema: schemas_1.FindFirstAuthenticationSchema,
10
+ implementation: index_1.findFirstAuthentication,
11
+ };
@@ -0,0 +1,42 @@
1
+ import { z } from "zod";
2
+ import type { Authentication } from "../../types/domain";
3
+ export declare const FindFirstAuthenticationSchema: z.ZodObject<{
4
+ appKey: z.ZodOptional<z.ZodString>;
5
+ search: z.ZodOptional<z.ZodString>;
6
+ title: z.ZodOptional<z.ZodString>;
7
+ account_id: z.ZodOptional<z.ZodString>;
8
+ owner: z.ZodOptional<z.ZodString>;
9
+ limit: z.ZodOptional<z.ZodDefault<z.ZodNumber>>;
10
+ offset: z.ZodOptional<z.ZodDefault<z.ZodNumber>>;
11
+ }, "strip", z.ZodTypeAny, {
12
+ search?: string | undefined;
13
+ appKey?: string | undefined;
14
+ title?: string | undefined;
15
+ account_id?: string | undefined;
16
+ owner?: string | undefined;
17
+ limit?: number | undefined;
18
+ offset?: number | undefined;
19
+ }, {
20
+ search?: string | undefined;
21
+ appKey?: string | undefined;
22
+ title?: string | undefined;
23
+ account_id?: string | undefined;
24
+ owner?: string | undefined;
25
+ limit?: number | undefined;
26
+ offset?: number | undefined;
27
+ }>;
28
+ export type FindFirstAuthenticationOptions = z.infer<typeof FindFirstAuthenticationSchema> & {
29
+ /** Base URL for Zapier API */
30
+ baseUrl?: string;
31
+ /** Authentication token */
32
+ token?: string;
33
+ /** Optional pre-instantiated API client */
34
+ api?: any;
35
+ /** Enable debug logging */
36
+ debug?: boolean;
37
+ /** Custom fetch implementation */
38
+ fetch?: typeof globalThis.fetch;
39
+ };
40
+ export interface FindFirstAuthenticationSdkFunction {
41
+ findFirstAuthentication: (options?: Partial<FindFirstAuthenticationOptions>) => Promise<Authentication | null>;
42
+ }
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FindFirstAuthenticationSchema = void 0;
4
+ const zod_1 = require("zod");
5
+ const properties_1 = require("../../types/properties");
6
+ const schema_utils_1 = require("../../schema-utils");
7
+ const Auth_1 = require("../../schemas/Auth");
8
+ // Pure Zod schema - no resolver metadata!
9
+ exports.FindFirstAuthenticationSchema = (0, schema_utils_1.withOutputSchema)(zod_1.z
10
+ .object({
11
+ appKey: properties_1.AppKeyPropertySchema.optional().describe("App slug to get authentications for (e.g., 'slack', 'github')"),
12
+ search: zod_1.z
13
+ .string()
14
+ .optional()
15
+ .describe("Search term to filter authentications by title"),
16
+ title: zod_1.z
17
+ .string()
18
+ .optional()
19
+ .describe("Filter authentications by exact title match"),
20
+ account_id: zod_1.z.string().optional().describe("Filter by account ID"),
21
+ owner: zod_1.z.string().optional().describe("Filter by owner"),
22
+ limit: properties_1.LimitPropertySchema.optional().describe("Maximum number of items to return (1-200)"),
23
+ offset: properties_1.OffsetPropertySchema.optional().describe("Number of items to skip for pagination"),
24
+ })
25
+ .describe("Find the first authentication matching the criteria"), Auth_1.AuthItemSchema);
@@ -0,0 +1,13 @@
1
+ import type { Authentication } from "../../types/domain";
2
+ import type { FindUniqueAuthenticationOptions } from "./schemas";
3
+ /**
4
+ * Find a unique authentication matching the given criteria
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 - Filtering and API configuration options
10
+ * @returns Promise<Authentication> - The unique matching authentication
11
+ * @throws Error if no authentication found or multiple authentications found
12
+ */
13
+ export declare function findUniqueAuthentication(options?: Partial<FindUniqueAuthenticationOptions>): Promise<Authentication>;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.findUniqueAuthentication = findUniqueAuthentication;
4
+ const listAuthentications_1 = require("../listAuthentications");
5
+ /**
6
+ * Find a unique authentication matching the given criteria
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 - Filtering and API configuration options
12
+ * @returns Promise<Authentication> - The unique matching authentication
13
+ * @throws Error if no authentication found or multiple authentications found
14
+ */
15
+ async function findUniqueAuthentication(options = {}) {
16
+ // Use listAuthentications with a reasonable limit to check for uniqueness
17
+ const auths = await (0, listAuthentications_1.listAuthentications)({
18
+ ...options,
19
+ limit: 2, // Get up to 2 to check for uniqueness
20
+ });
21
+ if (auths.length === 0) {
22
+ throw new Error("No authentication found matching the specified criteria");
23
+ }
24
+ if (auths.length > 1) {
25
+ throw new Error("Multiple authentications found matching the specified criteria. Expected exactly one.");
26
+ }
27
+ return auths[0];
28
+ }
@@ -0,0 +1,30 @@
1
+ import { findUniqueAuthentication } from "./index";
2
+ export declare const findUniqueAuthenticationInfo: {
3
+ name: string;
4
+ inputSchema: import("zod").ZodObject<{
5
+ appKey: import("zod").ZodOptional<import("zod").ZodString>;
6
+ search: import("zod").ZodOptional<import("zod").ZodString>;
7
+ title: import("zod").ZodOptional<import("zod").ZodString>;
8
+ account_id: import("zod").ZodOptional<import("zod").ZodString>;
9
+ owner: import("zod").ZodOptional<import("zod").ZodString>;
10
+ limit: import("zod").ZodOptional<import("zod").ZodDefault<import("zod").ZodNumber>>;
11
+ offset: import("zod").ZodOptional<import("zod").ZodDefault<import("zod").ZodNumber>>;
12
+ }, "strip", import("zod").ZodTypeAny, {
13
+ search?: string | undefined;
14
+ appKey?: string | undefined;
15
+ title?: string | undefined;
16
+ account_id?: string | undefined;
17
+ owner?: string | undefined;
18
+ limit?: number | undefined;
19
+ offset?: number | undefined;
20
+ }, {
21
+ search?: string | undefined;
22
+ appKey?: string | undefined;
23
+ title?: string | undefined;
24
+ account_id?: string | undefined;
25
+ owner?: string | undefined;
26
+ limit?: number | undefined;
27
+ offset?: number | undefined;
28
+ }>;
29
+ implementation: typeof findUniqueAuthentication;
30
+ };
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.findUniqueAuthenticationInfo = 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.findUniqueAuthenticationInfo = {
8
+ name: index_1.findUniqueAuthentication.name,
9
+ inputSchema: schemas_1.FindUniqueAuthenticationSchema,
10
+ implementation: index_1.findUniqueAuthentication,
11
+ };
@@ -1,25 +1,31 @@
1
1
  import { z } from "zod";
2
2
  import type { Authentication } from "../../types/domain";
3
- export declare const ListAuthsSchema: z.ZodObject<{
3
+ export declare const FindUniqueAuthenticationSchema: z.ZodObject<{
4
4
  appKey: z.ZodOptional<z.ZodString>;
5
+ search: z.ZodOptional<z.ZodString>;
6
+ title: z.ZodOptional<z.ZodString>;
5
7
  account_id: z.ZodOptional<z.ZodString>;
6
8
  owner: z.ZodOptional<z.ZodString>;
7
9
  limit: z.ZodOptional<z.ZodDefault<z.ZodNumber>>;
8
10
  offset: z.ZodOptional<z.ZodDefault<z.ZodNumber>>;
9
11
  }, "strip", z.ZodTypeAny, {
12
+ search?: string | undefined;
10
13
  appKey?: string | undefined;
14
+ title?: string | undefined;
11
15
  account_id?: string | undefined;
12
16
  owner?: string | undefined;
13
17
  limit?: number | undefined;
14
18
  offset?: number | undefined;
15
19
  }, {
20
+ search?: string | undefined;
16
21
  appKey?: string | undefined;
22
+ title?: string | undefined;
17
23
  account_id?: string | undefined;
18
24
  owner?: string | undefined;
19
25
  limit?: number | undefined;
20
26
  offset?: number | undefined;
21
27
  }>;
22
- export type ListAuthsOptions = z.infer<typeof ListAuthsSchema> & {
28
+ export type FindUniqueAuthenticationOptions = z.infer<typeof FindUniqueAuthenticationSchema> & {
23
29
  /** Base URL for Zapier API */
24
30
  baseUrl?: string;
25
31
  /** Authentication token */
@@ -31,6 +37,6 @@ export type ListAuthsOptions = z.infer<typeof ListAuthsSchema> & {
31
37
  /** Custom fetch implementation */
32
38
  fetch?: typeof globalThis.fetch;
33
39
  };
34
- export interface ListAuthsSdkFunction {
35
- listAuths: (options?: Partial<ListAuthsOptions>) => Promise<Authentication[]>;
40
+ export interface FindUniqueAuthenticationSdkFunction {
41
+ findUniqueAuthentication: (options?: Partial<FindUniqueAuthenticationOptions>) => Promise<Authentication>;
36
42
  }
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FindUniqueAuthenticationSchema = void 0;
4
+ const zod_1 = require("zod");
5
+ const properties_1 = require("../../types/properties");
6
+ const schema_utils_1 = require("../../schema-utils");
7
+ const Auth_1 = require("../../schemas/Auth");
8
+ // Pure Zod schema - no resolver metadata!
9
+ exports.FindUniqueAuthenticationSchema = (0, schema_utils_1.withOutputSchema)(zod_1.z
10
+ .object({
11
+ appKey: properties_1.AppKeyPropertySchema.optional().describe("App slug to get authentications for (e.g., 'slack', 'github')"),
12
+ search: zod_1.z
13
+ .string()
14
+ .optional()
15
+ .describe("Search term to filter authentications by title"),
16
+ title: zod_1.z
17
+ .string()
18
+ .optional()
19
+ .describe("Filter authentications by exact title match"),
20
+ account_id: zod_1.z.string().optional().describe("Filter by account ID"),
21
+ owner: zod_1.z.string().optional().describe("Filter by owner"),
22
+ limit: properties_1.LimitPropertySchema.optional().describe("Maximum number of items to return (1-200)"),
23
+ offset: properties_1.OffsetPropertySchema.optional().describe("Number of items to skip for pagination"),
24
+ })
25
+ .describe("Find a unique authentication matching the criteria"), Auth_1.AuthItemSchema);
@@ -1,5 +1,5 @@
1
1
  import type { Authentication } from "../../types/domain";
2
- import type { ListAuthsOptions } from "./schemas";
2
+ import type { ListAuthenticationsOptions } from "./schemas";
3
3
  /**
4
4
  * List available authentications with optional filtering
5
5
  *
@@ -9,4 +9,4 @@ import type { ListAuthsOptions } from "./schemas";
9
9
  * @param options - Filtering, pagination, and API configuration options
10
10
  * @returns Promise<Authentication[]> with pagination metadata
11
11
  */
12
- export declare function listAuths(options?: Partial<ListAuthsOptions>): Promise<Authentication[]>;
12
+ export declare function listAuthentications(options?: Partial<ListAuthenticationsOptions>): Promise<Authentication[]>;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.listAuths = listAuths;
3
+ exports.listAuthentications = listAuthentications;
4
4
  const api_1 = require("../../api");
5
5
  const getApp_1 = require("../getApp");
6
6
  /**
@@ -12,14 +12,11 @@ const getApp_1 = require("../getApp");
12
12
  * @param options - Filtering, pagination, and API configuration options
13
13
  * @returns Promise<Authentication[]> with pagination metadata
14
14
  */
15
- async function listAuths(options = {}) {
16
- const { token } = options;
17
- if (!token && !process.env.ZAPIER_TOKEN) {
18
- throw new Error("Authentication token is required to list authentications. Please provide token in options or set ZAPIER_TOKEN environment variable.");
19
- }
15
+ async function listAuthentications(options = {}) {
20
16
  const api = (0, api_1.getOrCreateApiClient)(options);
17
+ api.requireAuthTo("list authentications");
21
18
  // Local function to handle the actual API fetching
22
- const listAuthsInternal = async (options = {}) => {
19
+ const listAuthenticationsInternal = async (options = {}) => {
23
20
  // Build search parameters
24
21
  const searchParams = {};
25
22
  // Handle appKey filtering by getting the selected_api first
@@ -52,6 +49,13 @@ async function listAuths(options = {}) {
52
49
  }
53
50
  }
54
51
  // Add other query parameters if provided
52
+ // Use title as search if no explicit search provided
53
+ if (options.search) {
54
+ searchParams.search = options.search;
55
+ }
56
+ else if (options.title) {
57
+ searchParams.search = options.title;
58
+ }
55
59
  if (options.account_id) {
56
60
  searchParams.account_id = options.account_id;
57
61
  }
@@ -77,7 +81,16 @@ async function listAuths(options = {}) {
77
81
  },
78
82
  });
79
83
  // Transform API response
80
- const auths = data.results || [];
84
+ let auths = data.results || [];
85
+ // Coerce title from label if title is missing (API cleanup)
86
+ auths = auths.map((auth) => ({
87
+ ...auth,
88
+ title: auth.title || auth.label || undefined,
89
+ }));
90
+ // Filter by exact title match if specified
91
+ if (options.title) {
92
+ auths = auths.filter((auth) => auth.title === options.title);
93
+ }
81
94
  // Add pagination metadata to the response
82
95
  if (auths.length > 0) {
83
96
  auths.__pagination = {
@@ -93,7 +106,7 @@ async function listAuths(options = {}) {
93
106
  // If a limit is provided and no specific owner filter, prioritize owned auths
94
107
  if (options.limit && options.owner === undefined) {
95
108
  // First get owned auths
96
- const ownedAuths = await listAuthsInternal({
109
+ const ownedAuths = await listAuthenticationsInternal({
97
110
  ...options,
98
111
  owner: "me",
99
112
  });
@@ -102,7 +115,7 @@ async function listAuths(options = {}) {
102
115
  return ownedAuths.slice(0, options.limit);
103
116
  }
104
117
  // Get all auths up to the original limit to fill remaining slots
105
- const allAuths = await listAuthsInternal({
118
+ const allAuths = await listAuthenticationsInternal({
106
119
  ...options,
107
120
  owner: undefined,
108
121
  });
@@ -114,5 +127,5 @@ async function listAuths(options = {}) {
114
127
  return combined.slice(0, options.limit);
115
128
  }
116
129
  // Standard implementation for non-prioritized requests
117
- return listAuthsInternal(options);
130
+ return listAuthenticationsInternal(options);
118
131
  }
@@ -1,24 +1,30 @@
1
- import { listAuths } from "./index";
2
- export declare const listAuthsInfo: {
1
+ import { listAuthentications } from "./index";
2
+ export declare const listAuthenticationsInfo: {
3
3
  name: string;
4
4
  inputSchema: import("zod").ZodObject<{
5
5
  appKey: import("zod").ZodOptional<import("zod").ZodString>;
6
+ search: import("zod").ZodOptional<import("zod").ZodString>;
7
+ title: import("zod").ZodOptional<import("zod").ZodString>;
6
8
  account_id: import("zod").ZodOptional<import("zod").ZodString>;
7
9
  owner: import("zod").ZodOptional<import("zod").ZodString>;
8
10
  limit: import("zod").ZodOptional<import("zod").ZodDefault<import("zod").ZodNumber>>;
9
11
  offset: import("zod").ZodOptional<import("zod").ZodDefault<import("zod").ZodNumber>>;
10
12
  }, "strip", import("zod").ZodTypeAny, {
13
+ search?: string | undefined;
11
14
  appKey?: string | undefined;
15
+ title?: string | undefined;
12
16
  account_id?: string | undefined;
13
17
  owner?: string | undefined;
14
18
  limit?: number | undefined;
15
19
  offset?: number | undefined;
16
20
  }, {
21
+ search?: string | undefined;
17
22
  appKey?: string | undefined;
23
+ title?: string | undefined;
18
24
  account_id?: string | undefined;
19
25
  owner?: string | undefined;
20
26
  limit?: number | undefined;
21
27
  offset?: number | undefined;
22
28
  }>;
23
- implementation: typeof listAuths;
29
+ implementation: typeof listAuthentications;
24
30
  };
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.listAuthenticationsInfo = 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.listAuthenticationsInfo = {
8
+ name: index_1.listAuthentications.name,
9
+ inputSchema: schemas_1.ListAuthenticationsSchema,
10
+ implementation: index_1.listAuthentications,
11
+ };
@@ -0,0 +1,44 @@
1
+ import { z } from "zod";
2
+ import type { Authentication } from "../../types/domain";
3
+ export declare const ListAuthenticationsSchema: z.ZodObject<{
4
+ appKey: z.ZodOptional<z.ZodString>;
5
+ search: z.ZodOptional<z.ZodString>;
6
+ title: z.ZodOptional<z.ZodString>;
7
+ account_id: z.ZodOptional<z.ZodString>;
8
+ owner: z.ZodOptional<z.ZodString>;
9
+ limit: z.ZodOptional<z.ZodDefault<z.ZodNumber>>;
10
+ offset: z.ZodOptional<z.ZodDefault<z.ZodNumber>>;
11
+ }, "strip", z.ZodTypeAny, {
12
+ search?: string | undefined;
13
+ appKey?: string | undefined;
14
+ title?: string | undefined;
15
+ account_id?: string | undefined;
16
+ owner?: string | undefined;
17
+ limit?: number | undefined;
18
+ offset?: number | undefined;
19
+ }, {
20
+ search?: string | undefined;
21
+ appKey?: string | undefined;
22
+ title?: string | undefined;
23
+ account_id?: string | undefined;
24
+ owner?: string | undefined;
25
+ limit?: number | undefined;
26
+ offset?: number | undefined;
27
+ }>;
28
+ export type ListAuthenticationsOptions = z.infer<typeof ListAuthenticationsSchema> & {
29
+ /** Base URL for Zapier API */
30
+ baseUrl?: string;
31
+ /** Authentication token */
32
+ token?: string;
33
+ /** Function to dynamically resolve authentication token */
34
+ getToken?: () => Promise<string | undefined>;
35
+ /** Optional pre-instantiated API client */
36
+ api?: any;
37
+ /** Enable debug logging */
38
+ debug?: boolean;
39
+ /** Custom fetch implementation */
40
+ fetch?: typeof globalThis.fetch;
41
+ };
42
+ export interface ListAuthenticationsSdkFunction {
43
+ listAuthentications: (options?: Partial<ListAuthenticationsOptions>) => Promise<Authentication[]>;
44
+ }
@@ -1,14 +1,22 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ListAuthsSchema = void 0;
3
+ exports.ListAuthenticationsSchema = void 0;
4
4
  const zod_1 = require("zod");
5
5
  const properties_1 = require("../../types/properties");
6
6
  const schema_utils_1 = require("../../schema-utils");
7
7
  const Auth_1 = require("../../schemas/Auth");
8
8
  // Pure Zod schema - no resolver metadata!
9
- exports.ListAuthsSchema = (0, schema_utils_1.withOutputSchema)(zod_1.z
9
+ exports.ListAuthenticationsSchema = (0, schema_utils_1.withOutputSchema)(zod_1.z
10
10
  .object({
11
11
  appKey: properties_1.AppKeyPropertySchema.optional().describe("App slug to get authentications for (e.g., 'slack', 'github')"),
12
+ search: zod_1.z
13
+ .string()
14
+ .optional()
15
+ .describe("Search term to filter authentications by title"),
16
+ title: zod_1.z
17
+ .string()
18
+ .optional()
19
+ .describe("Filter authentications by exact title match"),
12
20
  account_id: zod_1.z.string().optional().describe("Filter by account ID"),
13
21
  owner: zod_1.z.string().optional().describe("Filter by owner"),
14
22
  limit: properties_1.LimitPropertySchema.optional().describe("Maximum number of items to return (1-200)"),