@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
@@ -0,0 +1,35 @@
1
+ import type { Authentication } from "../../types/domain";
2
+ import { listAuthentications } from "../listAuthentications";
3
+ import type { FindUniqueAuthenticationOptions } from "./schemas";
4
+
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
+ export async function findUniqueAuthentication(
16
+ options: Partial<FindUniqueAuthenticationOptions> = {},
17
+ ): Promise<Authentication> {
18
+ // Use listAuthentications with a reasonable limit to check for uniqueness
19
+ const auths = await listAuthentications({
20
+ ...options,
21
+ limit: 2, // Get up to 2 to check for uniqueness
22
+ });
23
+
24
+ if (auths.length === 0) {
25
+ throw new Error("No authentication found matching the specified criteria");
26
+ }
27
+
28
+ if (auths.length > 1) {
29
+ throw new Error(
30
+ "Multiple authentications found matching the specified criteria. Expected exactly one.",
31
+ );
32
+ }
33
+
34
+ return auths[0];
35
+ }
@@ -0,0 +1,9 @@
1
+ import { findUniqueAuthentication } from "./index";
2
+ import { FindUniqueAuthenticationSchema } from "./schemas";
3
+
4
+ // Function registry info - imports both function and schema
5
+ export const findUniqueAuthenticationInfo = {
6
+ name: findUniqueAuthentication.name,
7
+ inputSchema: FindUniqueAuthenticationSchema,
8
+ implementation: findUniqueAuthentication,
9
+ };
@@ -0,0 +1,60 @@
1
+ import { z } from "zod";
2
+ import {
3
+ AppKeyPropertySchema,
4
+ LimitPropertySchema,
5
+ OffsetPropertySchema,
6
+ } from "../../types/properties";
7
+ import { withOutputSchema } from "../../schema-utils";
8
+ import { AuthItemSchema } from "../../schemas/Auth";
9
+ import type { Authentication } from "../../types/domain";
10
+
11
+ // Pure Zod schema - no resolver metadata!
12
+ export const FindUniqueAuthenticationSchema = withOutputSchema(
13
+ z
14
+ .object({
15
+ appKey: AppKeyPropertySchema.optional().describe(
16
+ "App slug to get authentications for (e.g., 'slack', 'github')",
17
+ ),
18
+ search: z
19
+ .string()
20
+ .optional()
21
+ .describe("Search term to filter authentications by title"),
22
+ title: z
23
+ .string()
24
+ .optional()
25
+ .describe("Filter authentications by exact title match"),
26
+ account_id: z.string().optional().describe("Filter by account ID"),
27
+ owner: z.string().optional().describe("Filter by owner"),
28
+ limit: LimitPropertySchema.optional().describe(
29
+ "Maximum number of items to return (1-200)",
30
+ ),
31
+ offset: OffsetPropertySchema.optional().describe(
32
+ "Number of items to skip for pagination",
33
+ ),
34
+ })
35
+ .describe("Find a unique authentication matching the criteria"),
36
+ AuthItemSchema,
37
+ );
38
+
39
+ // Type inferred from schema + function config
40
+ export type FindUniqueAuthenticationOptions = z.infer<
41
+ typeof FindUniqueAuthenticationSchema
42
+ > & {
43
+ /** Base URL for Zapier API */
44
+ baseUrl?: string;
45
+ /** Authentication token */
46
+ token?: string;
47
+ /** Optional pre-instantiated API client */
48
+ api?: any;
49
+ /** Enable debug logging */
50
+ debug?: boolean;
51
+ /** Custom fetch implementation */
52
+ fetch?: typeof globalThis.fetch;
53
+ };
54
+
55
+ // SDK function interface - ready to be mixed into main SDK interface
56
+ export interface FindUniqueAuthenticationSdkFunction {
57
+ findUniqueAuthentication: (
58
+ options?: Partial<FindUniqueAuthenticationOptions>,
59
+ ) => Promise<Authentication>;
60
+ }
@@ -4,7 +4,7 @@ import type {
4
4
  AuthenticationsResponse,
5
5
  } from "../../types/domain";
6
6
  import { getApp } from "../getApp";
7
- import type { ListAuthsOptions } from "./schemas";
7
+ import type { ListAuthenticationsOptions } from "./schemas";
8
8
 
9
9
  /**
10
10
  * List available authentications with optional filtering
@@ -15,22 +15,15 @@ import type { ListAuthsOptions } from "./schemas";
15
15
  * @param options - Filtering, pagination, and API configuration options
16
16
  * @returns Promise<Authentication[]> with pagination metadata
17
17
  */
18
- export async function listAuths(
19
- options: Partial<ListAuthsOptions> = {},
18
+ export async function listAuthentications(
19
+ options: Partial<ListAuthenticationsOptions> = {},
20
20
  ): Promise<Authentication[]> {
21
- const { token } = options;
22
-
23
- if (!token && !process.env.ZAPIER_TOKEN) {
24
- throw new Error(
25
- "Authentication token is required to list authentications. Please provide token in options or set ZAPIER_TOKEN environment variable.",
26
- );
27
- }
28
-
29
21
  const api = getOrCreateApiClient(options);
22
+ api.requireAuthTo("list authentications");
30
23
 
31
24
  // Local function to handle the actual API fetching
32
- const listAuthsInternal = async (
33
- options: ListAuthsOptions = {},
25
+ const listAuthenticationsInternal = async (
26
+ options: ListAuthenticationsOptions = {},
34
27
  ): Promise<Authentication[]> => {
35
28
  // Build search parameters
36
29
  const searchParams: Record<string, string> = {};
@@ -68,6 +61,12 @@ export async function listAuths(
68
61
  }
69
62
 
70
63
  // Add other query parameters if provided
64
+ // Use title as search if no explicit search provided
65
+ if (options.search) {
66
+ searchParams.search = options.search;
67
+ } else if (options.title) {
68
+ searchParams.search = options.title;
69
+ }
71
70
  if (options.account_id) {
72
71
  searchParams.account_id = options.account_id;
73
72
  }
@@ -102,7 +101,18 @@ export async function listAuths(
102
101
  );
103
102
 
104
103
  // Transform API response
105
- const auths = data.results || [];
104
+ let auths = data.results || [];
105
+
106
+ // Coerce title from label if title is missing (API cleanup)
107
+ auths = auths.map((auth) => ({
108
+ ...auth,
109
+ title: auth.title || (auth as any).label || undefined,
110
+ }));
111
+
112
+ // Filter by exact title match if specified
113
+ if (options.title) {
114
+ auths = auths.filter((auth) => auth.title === options.title);
115
+ }
106
116
 
107
117
  // Add pagination metadata to the response
108
118
  if (auths.length > 0) {
@@ -121,7 +131,7 @@ export async function listAuths(
121
131
  // If a limit is provided and no specific owner filter, prioritize owned auths
122
132
  if (options.limit && options.owner === undefined) {
123
133
  // First get owned auths
124
- const ownedAuths = await listAuthsInternal({
134
+ const ownedAuths = await listAuthenticationsInternal({
125
135
  ...options,
126
136
  owner: "me",
127
137
  });
@@ -132,7 +142,7 @@ export async function listAuths(
132
142
  }
133
143
 
134
144
  // Get all auths up to the original limit to fill remaining slots
135
- const allAuths = await listAuthsInternal({
145
+ const allAuths = await listAuthenticationsInternal({
136
146
  ...options,
137
147
  owner: undefined,
138
148
  });
@@ -149,5 +159,5 @@ export async function listAuths(
149
159
  }
150
160
 
151
161
  // Standard implementation for non-prioritized requests
152
- return listAuthsInternal(options);
162
+ return listAuthenticationsInternal(options);
153
163
  }
@@ -0,0 +1,9 @@
1
+ import { listAuthentications } from "./index";
2
+ import { ListAuthenticationsSchema } from "./schemas";
3
+
4
+ // Function registry info - imports both function and schema
5
+ export const listAuthenticationsInfo = {
6
+ name: listAuthentications.name,
7
+ inputSchema: ListAuthenticationsSchema,
8
+ implementation: listAuthentications,
9
+ };
@@ -9,12 +9,20 @@ import { AuthItemSchema } from "../../schemas/Auth";
9
9
  import type { Authentication } from "../../types/domain";
10
10
 
11
11
  // Pure Zod schema - no resolver metadata!
12
- export const ListAuthsSchema = withOutputSchema(
12
+ export const ListAuthenticationsSchema = withOutputSchema(
13
13
  z
14
14
  .object({
15
15
  appKey: AppKeyPropertySchema.optional().describe(
16
16
  "App slug to get authentications for (e.g., 'slack', 'github')",
17
17
  ),
18
+ search: z
19
+ .string()
20
+ .optional()
21
+ .describe("Search term to filter authentications by title"),
22
+ title: z
23
+ .string()
24
+ .optional()
25
+ .describe("Filter authentications by exact title match"),
18
26
  account_id: z.string().optional().describe("Filter by account ID"),
19
27
  owner: z.string().optional().describe("Filter by owner"),
20
28
  limit: LimitPropertySchema.optional().describe(
@@ -29,11 +37,15 @@ export const ListAuthsSchema = withOutputSchema(
29
37
  );
30
38
 
31
39
  // Type inferred from schema + function config
32
- export type ListAuthsOptions = z.infer<typeof ListAuthsSchema> & {
40
+ export type ListAuthenticationsOptions = z.infer<
41
+ typeof ListAuthenticationsSchema
42
+ > & {
33
43
  /** Base URL for Zapier API */
34
44
  baseUrl?: string;
35
45
  /** Authentication token */
36
46
  token?: string;
47
+ /** Function to dynamically resolve authentication token */
48
+ getToken?: () => Promise<string | undefined>;
37
49
  /** Optional pre-instantiated API client */
38
50
  api?: any;
39
51
  /** Enable debug logging */
@@ -43,6 +55,8 @@ export type ListAuthsOptions = z.infer<typeof ListAuthsSchema> & {
43
55
  };
44
56
 
45
57
  // SDK function interface - ready to be mixed into main SDK interface
46
- export interface ListAuthsSdkFunction {
47
- listAuths: (options?: Partial<ListAuthsOptions>) => Promise<Authentication[]>;
58
+ export interface ListAuthenticationsSdkFunction {
59
+ listAuthentications: (
60
+ options?: Partial<ListAuthenticationsOptions>,
61
+ ) => Promise<Authentication[]>;
48
62
  }
@@ -25,13 +25,8 @@ export async function runAction(
25
25
  token,
26
26
  } = options;
27
27
 
28
- if (!token && !process.env.ZAPIER_TOKEN) {
29
- throw new Error(
30
- "Authentication token is required to run actions. Please provide token in options or set ZAPIER_TOKEN environment variable.",
31
- );
32
- }
33
-
34
28
  const api = getOrCreateApiClient(options);
29
+ api.requireAuthTo("run actions");
35
30
 
36
31
  // Validate that the action exists
37
32
  const actionData = await getAction({
@@ -27,6 +27,8 @@ export type RunActionOptions = z.infer<typeof RunActionSchema> & {
27
27
  baseUrl?: string;
28
28
  /** Authentication token */
29
29
  token?: string;
30
+ /** Function to dynamically resolve authentication token */
31
+ getToken?: () => Promise<string | undefined>;
30
32
  /** Optional pre-instantiated API client */
31
33
  api?: any;
32
34
  /** Enable debug logging */
package/src/index.ts CHANGED
@@ -3,13 +3,18 @@ export * from "./types/domain";
3
3
  export * from "./types/properties";
4
4
  export * from "./plugins/apps";
5
5
 
6
+ // Export schema utilities for CLI
7
+ export { isPositional } from "./schema-utils";
8
+
6
9
  // Export resolvers for CLI use
7
10
  export * from "./resolvers";
8
11
 
9
12
  // Note: SdkSchemas is now available via SDK.__registry
10
13
 
11
14
  // Export individual functions for tree-shaking
12
- export { listAuths } from "./functions/listAuths";
15
+ export { listAuthentications } from "./functions/listAuthentications";
16
+ export { findFirstAuthentication } from "./functions/findFirstAuthentication";
17
+ export { findUniqueAuthentication } from "./functions/findUniqueAuthentication";
13
18
  export { listApps } from "./functions/listApps";
14
19
  export { getApp } from "./functions/getApp";
15
20
  export { listActions } from "./functions/listActions";
@@ -15,7 +15,7 @@ export const authenticationIdResolver: AuthenticationIdResolver = {
15
15
  depends: ["appKey"] as const,
16
16
  fetch: async (sdk: ZapierSdk, resolvedParams: Record<string, any>) => {
17
17
  // Get auths for the specific app (owned auths will be prioritized automatically)
18
- return await sdk.listAuths({
18
+ return await sdk.listAuthentications({
19
19
  appKey: resolvedParams.appKey,
20
20
  limit: 1000,
21
21
  });
@@ -117,3 +117,38 @@ export function getFieldDescriptions(
117
117
 
118
118
  return descriptions;
119
119
  }
120
+
121
+ // ============================================================================
122
+ // Positional Parameter Metadata
123
+ // ============================================================================
124
+
125
+ export interface PositionalMetadata {
126
+ positional: true;
127
+ }
128
+
129
+ // Helper function to mark a parameter as positional for CLI
130
+ export function withPositional<T extends z.ZodType>(schema: T): T {
131
+ // Store positional metadata on the schema definition
132
+ (schema._def as any).positionalMeta = { positional: true };
133
+ return schema;
134
+ }
135
+
136
+ // Helper function to check if a parameter should be positional
137
+ export function isPositional(schema: z.ZodType): boolean {
138
+ // Check the current schema first
139
+ if ((schema._def as any).positionalMeta?.positional) {
140
+ return true;
141
+ }
142
+
143
+ // If this is a ZodOptional, check the inner type
144
+ if (schema instanceof z.ZodOptional) {
145
+ return isPositional(schema._def.innerType);
146
+ }
147
+
148
+ // If this is a ZodDefault, check the inner type
149
+ if (schema instanceof z.ZodDefault) {
150
+ return isPositional(schema._def.innerType);
151
+ }
152
+
153
+ return false;
154
+ }
@@ -9,7 +9,6 @@ export const AuthItemSchema = withFormatter(
9
9
  z.object({
10
10
  id: z.number(),
11
11
  title: z.string().optional(),
12
- label: z.string().optional(),
13
12
  identifier: z.string().optional(),
14
13
  account_id: z.string().optional(),
15
14
  is_private: z.boolean().optional(),
@@ -27,13 +26,6 @@ export const AuthItemSchema = withFormatter(
27
26
  });
28
27
  }
29
28
 
30
- if (item.label && item.title && item.label !== item.title) {
31
- details.push({
32
- text: `Label: ${item.label}`,
33
- style: "normal" as const,
34
- });
35
- }
36
-
37
29
  details.push({
38
30
  text: `Account: ${item.account_id || "unknown"} | Private: ${item.is_private || false} | Shared: ${item.shared_with_all || false}`,
39
31
  style: "dim" as const,
@@ -47,7 +39,7 @@ export const AuthItemSchema = withFormatter(
47
39
  }
48
40
 
49
41
  return {
50
- title: item.title || item.label || `Authentication ${item.id}`,
42
+ title: item.title || `Authentication ${item.id}`,
51
43
  subtitle: `(ID: ${item.id})`,
52
44
  details,
53
45
  };
package/src/sdk.ts CHANGED
@@ -6,7 +6,9 @@ import { getApp } from "./functions/getApp";
6
6
  import { listActions } from "./functions/listActions";
7
7
  import { getAction } from "./functions/getAction";
8
8
  import { runAction } from "./functions/runAction";
9
- import { listAuths } from "./functions/listAuths";
9
+ import { listAuthentications } from "./functions/listAuthentications";
10
+ import { findFirstAuthentication } from "./functions/findFirstAuthentication";
11
+ import { findUniqueAuthentication } from "./functions/findUniqueAuthentication";
10
12
  import { listFields } from "./functions/listFields";
11
13
  import { generateTypes } from "./functions/generateTypes";
12
14
  import { bundleCode } from "./functions/bundleCode";
@@ -17,7 +19,9 @@ import { getAppInfo } from "./functions/getApp/info";
17
19
  import { listActionsInfo } from "./functions/listActions/info";
18
20
  import { getActionInfo } from "./functions/getAction/info";
19
21
  import { runActionInfo } from "./functions/runAction/info";
20
- import { listAuthsInfo } from "./functions/listAuths/info";
22
+ import { listAuthenticationsInfo } from "./functions/listAuthentications/info";
23
+ import { findFirstAuthenticationInfo } from "./functions/findFirstAuthentication/info";
24
+ import { findUniqueAuthenticationInfo } from "./functions/findUniqueAuthentication/info";
21
25
  import { listFieldsInfo } from "./functions/listFields/info";
22
26
  import { generateTypesInfo } from "./functions/generateTypes/info";
23
27
  import { bundleCodeInfo } from "./functions/bundleCode/info";
@@ -29,7 +33,9 @@ const functionRegistry = [
29
33
  listActionsInfo,
30
34
  getActionInfo,
31
35
  runActionInfo,
32
- listAuthsInfo,
36
+ listAuthenticationsInfo,
37
+ findFirstAuthenticationInfo,
38
+ findUniqueAuthenticationInfo,
33
39
  listFieldsInfo,
34
40
  generateTypesInfo,
35
41
  bundleCodeInfo,
@@ -55,7 +61,9 @@ interface BaseZapierSdkWithFunctions {
55
61
  listActions: ZapierSdk["listActions"];
56
62
  getAction: ZapierSdk["getAction"];
57
63
  runAction: ZapierSdk["runAction"];
58
- listAuths: ZapierSdk["listAuths"];
64
+ listAuthentications: ZapierSdk["listAuthentications"];
65
+ findFirstAuthentication: ZapierSdk["findFirstAuthentication"];
66
+ findUniqueAuthentication: ZapierSdk["findUniqueAuthentication"];
59
67
  listFields: ZapierSdk["listFields"];
60
68
  generateTypes: ZapierSdk["generateTypes"];
61
69
  bundleCode: ZapierSdk["bundleCode"];
@@ -69,31 +77,19 @@ export interface ZapierSdkOptions extends BaseSdkOptions {}
69
77
  function createBaseZapierSdk(
70
78
  options: ZapierSdkOptions = {},
71
79
  ): BaseZapierSdkWithFunctions {
72
- // Auto-load .env files (searches up directory tree)
73
- try {
74
- const { findUpSync } = require("find-up");
75
- const envPath = findUpSync(".env");
76
- if (envPath) {
77
- require("dotenv").config({ path: envPath, quiet: true });
78
- }
79
- } catch {
80
- // Silently fail if dotenv/find-up not available or .env not found
81
- }
82
-
83
80
  const {
84
81
  fetch: customFetch = globalThis.fetch,
85
82
  baseUrl = "https://zapier.com",
86
83
  token,
84
+ getToken,
87
85
  debug = false,
88
86
  } = options;
89
87
 
90
- // If no token provided, try to get it from environment variable
91
- const finalToken = token || process.env.ZAPIER_TOKEN;
92
-
93
88
  // Create the API client
94
89
  const api = createZapierApi({
95
90
  baseUrl,
96
- token: finalToken,
91
+ token,
92
+ getToken,
97
93
  debug,
98
94
  fetch: customFetch,
99
95
  });
@@ -104,18 +100,19 @@ function createBaseZapierSdk(
104
100
  __registry: functionRegistry,
105
101
 
106
102
  // Function implementations with API config injection
107
- listApps: (options = {}) =>
108
- listApps({ ...options, api, token: finalToken }),
109
- getApp: (options) => getApp({ ...options, api, token: finalToken }),
110
- listActions: (options = {}) =>
111
- listActions({ ...options, api, token: finalToken }),
112
- getAction: (options) => getAction({ ...options, api, token: finalToken }),
113
- runAction: (options) => runAction({ ...options, api, token: finalToken }),
114
- listAuths: (options = {}) =>
115
- listAuths({ ...options, api, token: finalToken }),
116
- listFields: (options) => listFields({ ...options, api, token: finalToken }),
117
- generateTypes: (options) =>
118
- generateTypes({ ...options, api, token: finalToken }),
103
+ listApps: (options = {}) => listApps({ ...options, api }),
104
+ getApp: (options) => getApp({ ...options, api }),
105
+ listActions: (options = {}) => listActions({ ...options, api }),
106
+ getAction: (options) => getAction({ ...options, api }),
107
+ runAction: (options) => runAction({ ...options, api }),
108
+ listAuthentications: (options = {}) =>
109
+ listAuthentications({ ...options, api }),
110
+ findFirstAuthentication: (options = {}) =>
111
+ findFirstAuthentication({ ...options, api }),
112
+ findUniqueAuthentication: (options = {}) =>
113
+ findUniqueAuthentication({ ...options, api }),
114
+ listFields: (options) => listFields({ ...options, api }),
115
+ generateTypes: (options) => generateTypes({ ...options, api }),
119
116
  bundleCode: (options) => bundleCode(options), // No API config needed
120
117
  };
121
118
 
@@ -131,15 +128,15 @@ export function createZapierSdk(options: ZapierSdkOptions = {}): ZapierSdk {
131
128
  fetch: customFetch = globalThis.fetch,
132
129
  baseUrl = "https://zapier.com",
133
130
  token,
131
+ getToken,
134
132
  debug = false,
135
133
  } = options;
136
134
 
137
- const finalToken = token || process.env.ZAPIER_TOKEN;
138
-
139
135
  // Create the API client for plugins
140
136
  const api = createZapierApi({
141
137
  baseUrl,
142
- token: finalToken,
138
+ token,
139
+ getToken,
143
140
  debug,
144
141
  fetch: customFetch,
145
142
  });
@@ -147,7 +144,7 @@ export function createZapierSdk(options: ZapierSdkOptions = {}): ZapierSdk {
147
144
  // Create plugins directly - TypeScript will enforce correct implementation
148
145
  const appsPlugin = createAppsPlugin({
149
146
  api,
150
- token: finalToken,
147
+ token,
151
148
  });
152
149
 
153
150
  // Compose final SDK - TypeScript will enforce we have all required properties
@@ -26,6 +26,7 @@ export interface AuthObject {
26
26
 
27
27
  export interface BaseSdkOptions {
28
28
  token?: string;
29
+ getToken?: () => Promise<string | undefined>;
29
30
  fetch?: typeof fetch;
30
31
  baseUrl?: string;
31
32
  debug?: boolean;
@@ -1,12 +1,12 @@
1
1
  import { z } from "zod";
2
+ import { withPositional } from "../schema-utils";
2
3
 
3
4
  // Shared property definitions for common parameters across functions
4
5
  // These can be reused in function schemas without duplication
5
6
 
6
- export const AppKeyPropertySchema = z
7
- .string()
8
- .min(1)
9
- .describe("App slug (e.g., 'slack', 'github')");
7
+ export const AppKeyPropertySchema = withPositional(
8
+ z.string().min(1).describe("App slug (e.g., 'slack', 'github')"),
9
+ );
10
10
 
11
11
  export const ActionTypePropertySchema = z
12
12
  .enum(["read", "write", "search", "create", "update", "delete"])
package/src/types/sdk.ts CHANGED
@@ -4,7 +4,9 @@ import type { GetActionSdkFunction } from "../functions/getAction/schemas";
4
4
  import type { GetAppSdkFunction } from "../functions/getApp/schemas";
5
5
  import type { RunActionSdkFunction } from "../functions/runAction/schemas";
6
6
  import type { ListFieldsSdkFunction } from "../functions/listFields/schemas";
7
- import type { ListAuthsSdkFunction } from "../functions/listAuths/schemas";
7
+ import type { ListAuthenticationsSdkFunction } from "../functions/listAuthentications/schemas";
8
+ import type { FindFirstAuthenticationSdkFunction } from "../functions/findFirstAuthentication/schemas";
9
+ import type { FindUniqueAuthenticationSdkFunction } from "../functions/findUniqueAuthentication/schemas";
8
10
  import type { GenerateTypesSdkFunction } from "../functions/generateTypes/schemas";
9
11
  import type { ListAppsSdkFunction } from "../functions/listApps/schemas";
10
12
  import type { BundleCodeSdkFunction } from "../functions/bundleCode/schemas";
@@ -19,7 +21,9 @@ export interface ZapierSdkFunctions
19
21
  GetAppSdkFunction,
20
22
  RunActionSdkFunction,
21
23
  ListFieldsSdkFunction,
22
- ListAuthsSdkFunction,
24
+ ListAuthenticationsSdkFunction,
25
+ FindFirstAuthenticationSdkFunction,
26
+ FindUniqueAuthenticationSdkFunction,
23
27
  GenerateTypesSdkFunction,
24
28
  ListAppsSdkFunction,
25
29
  BundleCodeSdkFunction {
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Attempts to read the JWT token from the CLI config file.
3
+ * This is a synchronous function that only returns valid, non-expired tokens.
4
+ * For token refresh logic, the CLI should handle that separately.
5
+ * Returns undefined if config file doesn't exist, token is not available, or token is expired.
6
+ */
7
+ export function getTokenFromConfig(): string | undefined {
8
+ try {
9
+ // Dynamically import conf to avoid dependency issues if not installed
10
+ const Conf = require("conf");
11
+ const config = new Conf({ projectName: "zapier-sdk-cli" });
12
+
13
+ // Get the stored JWT token
14
+ const jwt = config.get("login_jwt") as string | undefined;
15
+ const expiresAt = config.get("login_expires_at") as number | undefined;
16
+
17
+ // Check if token exists and is not expired (with 30s buffer)
18
+ if (jwt && expiresAt && expiresAt > Date.now() + 30 * 1000) {
19
+ return jwt;
20
+ }
21
+
22
+ // Token is missing or expired - return undefined so SDK will require explicit auth
23
+ return undefined;
24
+ } catch {
25
+ // Config package not available or other error - silently fail
26
+ return undefined;
27
+ }
28
+ }
@@ -1,11 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.listAuthsInfo = 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.listAuthsInfo = {
8
- name: index_1.listAuths.name,
9
- inputSchema: schemas_1.ListAuthsSchema,
10
- implementation: index_1.listAuths,
11
- };
@@ -1,9 +0,0 @@
1
- import { listAuths } from "./index";
2
- import { ListAuthsSchema } from "./schemas";
3
-
4
- // Function registry info - imports both function and schema
5
- export const listAuthsInfo = {
6
- name: listAuths.name,
7
- inputSchema: ListAuthsSchema,
8
- implementation: listAuths,
9
- };