@zapier/zapier-sdk 0.0.2 → 0.1.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 (167) hide show
  1. package/dist/api/auth.d.ts +8 -0
  2. package/dist/api/auth.js +29 -0
  3. package/dist/api/client.d.ts +8 -0
  4. package/dist/api/client.js +102 -0
  5. package/dist/api/debug.d.ts +12 -0
  6. package/dist/api/debug.js +50 -0
  7. package/dist/api/index.d.ts +26 -0
  8. package/dist/api/index.js +51 -0
  9. package/dist/api/polling.d.ts +17 -0
  10. package/dist/api/polling.js +34 -0
  11. package/dist/{types.d.ts → api/types.d.ts} +37 -76
  12. package/dist/api/types.js +9 -0
  13. package/dist/functions/bundleCode/index.d.ts +11 -0
  14. package/dist/functions/bundleCode/index.js +91 -0
  15. package/dist/functions/bundleCode/info.d.ts +27 -0
  16. package/dist/functions/bundleCode/info.js +11 -0
  17. package/dist/functions/bundleCode/schemas.d.ts +27 -0
  18. package/dist/functions/bundleCode/schemas.js +22 -0
  19. package/dist/functions/generateTypes/index.d.ts +11 -0
  20. package/dist/functions/generateTypes/index.js +305 -0
  21. package/dist/functions/generateTypes/info.d.ts +21 -0
  22. package/dist/functions/generateTypes/info.js +11 -0
  23. package/dist/functions/generateTypes/schemas.d.ts +30 -0
  24. package/dist/functions/generateTypes/schemas.js +14 -0
  25. package/dist/functions/getAction/index.d.ts +12 -0
  26. package/dist/functions/getAction/index.js +26 -0
  27. package/dist/functions/getAction/info.d.ts +18 -0
  28. package/dist/functions/getAction/info.js +11 -0
  29. package/dist/functions/getAction/schemas.d.ts +30 -0
  30. package/dist/functions/getAction/schemas.js +13 -0
  31. package/dist/functions/getApp/index.d.ts +12 -0
  32. package/dist/functions/getApp/index.js +37 -0
  33. package/dist/functions/getApp/info.d.ts +12 -0
  34. package/dist/functions/getApp/info.js +11 -0
  35. package/dist/functions/getApp/schemas.d.ts +24 -0
  36. package/dist/functions/getApp/schemas.js +11 -0
  37. package/dist/functions/listActions/index.d.ts +12 -0
  38. package/dist/functions/listActions/index.js +128 -0
  39. package/dist/functions/listActions/info.d.ts +15 -0
  40. package/dist/functions/listActions/info.js +11 -0
  41. package/dist/functions/listActions/schemas.d.ts +27 -0
  42. package/dist/functions/listActions/schemas.js +14 -0
  43. package/dist/functions/listApps/index.d.ts +12 -0
  44. package/dist/functions/listApps/index.js +50 -0
  45. package/dist/functions/listApps/info.d.ts +18 -0
  46. package/dist/functions/listApps/info.js +11 -0
  47. package/dist/functions/listApps/schemas.d.ts +30 -0
  48. package/dist/functions/listApps/schemas.js +15 -0
  49. package/dist/functions/listAuths/index.d.ts +12 -0
  50. package/dist/functions/listAuths/index.js +118 -0
  51. package/dist/functions/listAuths/info.d.ts +24 -0
  52. package/dist/functions/listAuths/info.js +11 -0
  53. package/dist/functions/listAuths/schemas.d.ts +36 -0
  54. package/dist/functions/listAuths/schemas.js +17 -0
  55. package/dist/functions/listFields/index.d.ts +12 -0
  56. package/dist/functions/listFields/index.js +65 -0
  57. package/dist/functions/listFields/info.d.ts +24 -0
  58. package/dist/functions/listFields/info.js +11 -0
  59. package/dist/functions/listFields/schemas.d.ts +36 -0
  60. package/dist/functions/listFields/schemas.js +17 -0
  61. package/dist/functions/runAction/index.d.ts +12 -0
  62. package/dist/functions/runAction/index.js +157 -0
  63. package/dist/functions/runAction/info.d.ts +24 -0
  64. package/dist/functions/runAction/info.js +11 -0
  65. package/dist/functions/runAction/schemas.d.ts +36 -0
  66. package/dist/functions/runAction/schemas.js +15 -0
  67. package/dist/index.d.ts +15 -3
  68. package/dist/index.js +27 -4
  69. package/dist/plugins/apps/index.d.ts +8 -0
  70. package/dist/plugins/apps/index.js +77 -0
  71. package/dist/plugins/apps/info.d.ts +6 -0
  72. package/dist/plugins/apps/info.js +13 -0
  73. package/dist/plugins/apps/types.d.ts +21 -0
  74. package/dist/plugins/apps/types.js +2 -0
  75. package/dist/resolvers/actionKey.d.ts +8 -0
  76. package/dist/resolvers/actionKey.js +20 -0
  77. package/dist/resolvers/actionType.d.ts +8 -0
  78. package/dist/resolvers/actionType.js +21 -0
  79. package/dist/resolvers/appKey.d.ts +6 -0
  80. package/dist/resolvers/appKey.js +8 -0
  81. package/dist/resolvers/authenticationId.d.ts +8 -0
  82. package/dist/resolvers/authenticationId.js +29 -0
  83. package/dist/resolvers/index.d.ts +39 -0
  84. package/dist/resolvers/index.js +105 -0
  85. package/dist/resolvers/inputs.d.ts +7 -0
  86. package/dist/resolvers/inputs.js +15 -0
  87. package/dist/schema-utils.d.ts +39 -0
  88. package/dist/schema-utils.js +52 -0
  89. package/dist/schemas/Action.d.ts +21 -0
  90. package/dist/schemas/Action.js +31 -0
  91. package/dist/schemas/App.d.ts +19 -0
  92. package/dist/schemas/App.js +32 -0
  93. package/dist/schemas/Auth.d.ts +30 -0
  94. package/dist/schemas/Auth.js +49 -0
  95. package/dist/schemas/Field.d.ts +15 -0
  96. package/dist/schemas/Field.js +25 -0
  97. package/dist/sdk.d.ts +3 -4
  98. package/dist/sdk.js +96 -11
  99. package/dist/types/domain.d.ts +22 -0
  100. package/dist/types/domain.js +21 -0
  101. package/dist/types/properties.d.ts +21 -0
  102. package/dist/types/properties.js +45 -0
  103. package/dist/types/sdk.d.ts +21 -0
  104. package/dist/types/sdk.js +2 -0
  105. package/package.json +4 -2
  106. package/src/api/auth.ts +28 -0
  107. package/src/api/client.ts +148 -0
  108. package/src/api/debug.ts +58 -0
  109. package/src/api/index.ts +83 -0
  110. package/src/api/polling.ts +56 -0
  111. package/src/{types.ts → api/types.ts} +51 -118
  112. package/src/functions/bundleCode/index.ts +78 -0
  113. package/src/functions/bundleCode/info.ts +9 -0
  114. package/src/functions/bundleCode/schemas.ts +30 -0
  115. package/src/functions/generateTypes/index.ts +348 -0
  116. package/src/functions/generateTypes/info.ts +9 -0
  117. package/src/functions/generateTypes/schemas.ts +38 -0
  118. package/src/functions/getAction/index.ts +33 -0
  119. package/src/functions/getAction/info.ts +9 -0
  120. package/src/functions/getAction/schemas.ts +35 -0
  121. package/src/functions/getApp/index.ts +41 -0
  122. package/src/functions/getApp/info.ts +9 -0
  123. package/src/functions/getApp/schemas.ts +31 -0
  124. package/src/functions/listActions/index.ts +149 -0
  125. package/src/functions/listActions/info.ts +9 -0
  126. package/src/functions/listActions/schemas.ts +40 -0
  127. package/src/functions/listApps/index.ts +60 -0
  128. package/src/functions/listApps/info.ts +9 -0
  129. package/src/functions/listApps/schemas.ts +43 -0
  130. package/src/functions/listAuths/index.ts +153 -0
  131. package/src/functions/listAuths/info.ts +9 -0
  132. package/src/functions/listAuths/schemas.ts +48 -0
  133. package/src/functions/listFields/index.ts +86 -0
  134. package/src/functions/listFields/info.ts +9 -0
  135. package/src/functions/listFields/schemas.ts +46 -0
  136. package/src/functions/runAction/index.ts +258 -0
  137. package/src/functions/runAction/info.ts +9 -0
  138. package/src/functions/runAction/schemas.ts +41 -0
  139. package/src/index.ts +24 -4
  140. package/src/plugins/apps/index.ts +144 -0
  141. package/src/plugins/apps/info.ts +12 -0
  142. package/src/plugins/apps/types.ts +34 -0
  143. package/src/resolvers/actionKey.ts +33 -0
  144. package/src/resolvers/actionType.ts +30 -0
  145. package/src/resolvers/appKey.ts +11 -0
  146. package/src/resolvers/authenticationId.ts +38 -0
  147. package/src/resolvers/index.ts +117 -0
  148. package/src/resolvers/inputs.ts +23 -0
  149. package/src/schema-utils.ts +119 -0
  150. package/src/schemas/Action.ts +40 -0
  151. package/src/schemas/App.ts +43 -0
  152. package/src/schemas/Auth.ts +62 -0
  153. package/src/schemas/Field.ts +34 -0
  154. package/src/sdk.ts +153 -19
  155. package/src/types/domain.ts +54 -0
  156. package/src/types/properties.ts +67 -0
  157. package/src/types/sdk.ts +42 -0
  158. package/dist/actions-sdk.d.ts +0 -51
  159. package/dist/actions-sdk.js +0 -1194
  160. package/dist/output-schemas.d.ts +0 -95
  161. package/dist/output-schemas.js +0 -138
  162. package/dist/schemas.d.ts +0 -338
  163. package/dist/schemas.js +0 -336
  164. package/dist/types.js +0 -41
  165. package/src/actions-sdk.ts +0 -1685
  166. package/src/output-schemas.ts +0 -196
  167. package/src/schemas.ts +0 -467
@@ -0,0 +1,33 @@
1
+ import type { Action } from "../../types/domain";
2
+ import { listActions } from "../listActions";
3
+ import type { GetActionOptions } from "./schemas";
4
+
5
+ /**
6
+ * Get a specific action by app, action key, and type
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 - App key, action key, type, and API configuration options
12
+ * @returns Promise<Action>
13
+ */
14
+ export async function getAction(options: GetActionOptions): Promise<Action> {
15
+ const { appKey, actionKey, actionType } = options;
16
+
17
+ const actions = await listActions({
18
+ ...options,
19
+ appKey: appKey,
20
+ });
21
+
22
+ const action = actions.find(
23
+ (a) => a.key === actionKey && a.type === actionType,
24
+ );
25
+
26
+ if (!action) {
27
+ throw new Error(`Action not found: ${actionKey} with type ${actionType}`);
28
+ }
29
+
30
+ return action;
31
+ }
32
+
33
+ // No registry info here - moved to info.ts for proper tree-shaking
@@ -0,0 +1,9 @@
1
+ import { getAction } from "./index";
2
+ import { GetActionSchema } from "./schemas";
3
+
4
+ // Function registry info - imports both function and schema
5
+ export const getActionInfo = {
6
+ name: getAction.name,
7
+ inputSchema: GetActionSchema,
8
+ implementation: getAction,
9
+ };
@@ -0,0 +1,35 @@
1
+ import { z } from "zod";
2
+ import {
3
+ AppKeyPropertySchema,
4
+ ActionTypePropertySchema,
5
+ ActionKeyPropertySchema,
6
+ } from "../../types/properties";
7
+ import type { Action } from "../../types/domain";
8
+
9
+ // Pure Zod schema - no resolver metadata!
10
+ export const GetActionSchema = z
11
+ .object({
12
+ appKey: AppKeyPropertySchema,
13
+ actionType: ActionTypePropertySchema,
14
+ actionKey: ActionKeyPropertySchema,
15
+ })
16
+ .describe("Get detailed information about a specific action");
17
+
18
+ // Type inferred from schema + function config
19
+ export type GetActionOptions = z.infer<typeof GetActionSchema> & {
20
+ /** Base URL for Zapier API */
21
+ baseUrl?: string;
22
+ /** Authentication token */
23
+ token?: string;
24
+ /** Optional pre-instantiated API client */
25
+ api?: any;
26
+ /** Enable debug logging */
27
+ debug?: boolean;
28
+ /** Custom fetch implementation */
29
+ fetch?: typeof globalThis.fetch;
30
+ };
31
+
32
+ // SDK function interface - ready to be mixed into main SDK interface
33
+ export interface GetActionSdkFunction {
34
+ getAction: (options: GetActionOptions) => Promise<Action>;
35
+ }
@@ -0,0 +1,41 @@
1
+ import { getOrCreateApiClient } from "../../api";
2
+ import type { Integration } from "../../types/domain";
3
+ import { AppNotFoundError } from "../../types/domain";
4
+ import type { GetAppOptions } from "./schemas";
5
+
6
+ /**
7
+ * Get a specific app by key
8
+ *
9
+ * This function can be used standalone without instantiating a full SDK,
10
+ * which enables better tree-shaking in applications that only need this functionality.
11
+ *
12
+ * @param options - App key and API configuration options
13
+ * @returns Promise<Integration>
14
+ */
15
+ export async function getApp(options: GetAppOptions): Promise<Integration> {
16
+ const api = getOrCreateApiClient(options);
17
+
18
+ const { appKey } = options;
19
+
20
+ const app = await api.get(`/api/v4/apps/${appKey}/`, {
21
+ customErrorHandler: (response) => {
22
+ if (response.status === 404) {
23
+ return new AppNotFoundError(appKey);
24
+ }
25
+ return undefined;
26
+ },
27
+ });
28
+
29
+ return {
30
+ key: app.slug,
31
+ name: app.name,
32
+ description: app.description,
33
+ version: "1.0.0",
34
+ category: app.category?.name,
35
+ actions: [],
36
+ triggers: [],
37
+ current_implementation_id: app.current_implementation_id,
38
+ };
39
+ }
40
+
41
+ // No registry info here - moved to info.ts for proper tree-shaking
@@ -0,0 +1,9 @@
1
+ import { getApp } from "./index";
2
+ import { GetAppSchema } from "./schemas";
3
+
4
+ // Function registry info - imports both function and schema
5
+ export const getAppInfo = {
6
+ name: getApp.name,
7
+ inputSchema: GetAppSchema,
8
+ implementation: getApp,
9
+ };
@@ -0,0 +1,31 @@
1
+ import { z } from "zod";
2
+ import { AppKeyPropertySchema } from "../../types/properties";
3
+ import type { Integration } from "../../types/domain";
4
+
5
+ // Pure Zod schema - no resolver metadata!
6
+ export const GetAppSchema = z
7
+ .object({
8
+ appKey: AppKeyPropertySchema.describe(
9
+ "App key or slug to fetch (e.g., google-sheets, slack, github)",
10
+ ),
11
+ })
12
+ .describe("Get detailed information about a specific app");
13
+
14
+ // Type inferred from schema + function config
15
+ export type GetAppOptions = z.infer<typeof GetAppSchema> & {
16
+ /** Base URL for Zapier API */
17
+ baseUrl?: string;
18
+ /** Authentication token */
19
+ token?: string;
20
+ /** Optional pre-instantiated API client */
21
+ api?: any;
22
+ /** Enable debug logging */
23
+ debug?: boolean;
24
+ /** Custom fetch implementation */
25
+ fetch?: typeof globalThis.fetch;
26
+ };
27
+
28
+ // SDK function interface - ready to be mixed into main SDK interface
29
+ export interface GetAppSdkFunction {
30
+ getApp: (options: GetAppOptions) => Promise<Integration>;
31
+ }
@@ -0,0 +1,149 @@
1
+ import { getOrCreateApiClient } from "../../api";
2
+ import type { Action } from "../../types/domain";
3
+ import { getApp } from "../getApp";
4
+ import type { ListActionsOptions } from "./schemas";
5
+
6
+ /**
7
+ * List available actions with optional filtering
8
+ *
9
+ * This function can be used standalone without instantiating a full SDK,
10
+ * which enables better tree-shaking in applications that only need this functionality.
11
+ *
12
+ * @param options - Filtering and API configuration options
13
+ * @returns Promise<Action[]> with pagination metadata
14
+ */
15
+ export async function listActions(
16
+ options: Partial<ListActionsOptions> = {},
17
+ ): Promise<Action[]> {
18
+ const api = getOrCreateApiClient(options);
19
+
20
+ // If filtering by appKey, use optimized approach with selected_apis parameter
21
+ if (options.appKey) {
22
+ try {
23
+ // Use the standalone getApp function
24
+ const appData = await getApp({
25
+ appKey: options.appKey,
26
+ api,
27
+ token: options.token,
28
+ baseUrl: options.baseUrl,
29
+ debug: options.debug,
30
+ fetch: options.fetch,
31
+ });
32
+
33
+ // Extract implementation name from current_implementation_id (e.g., "SlackCLIAPI@1.20.0" -> "SlackCLIAPI")
34
+ const implementationId = appData.current_implementation_id?.split("@")[0];
35
+ if (!implementationId) {
36
+ throw new Error("No current_implementation_id found for app");
37
+ }
38
+
39
+ const searchParams = {
40
+ global: "true",
41
+ public_only: "true",
42
+ selected_apis: implementationId,
43
+ };
44
+
45
+ const data = await api.get("/api/v4/implementations/", {
46
+ searchParams,
47
+ });
48
+ const actions: Action[] = [];
49
+
50
+ // Transform implementations to actions
51
+ for (const implementation of data.results || []) {
52
+ if (implementation.actions) {
53
+ for (const action of implementation.actions) {
54
+ const transformedAction: Action = {
55
+ key: action.key,
56
+ name: action.name || action.label,
57
+ description: action.description || "",
58
+ appKey: implementation.slug || "",
59
+ type: action.type || action.type_of || "read",
60
+ inputFields: [], // Would need additional API call for detailed fields
61
+ outputFields: [],
62
+ };
63
+
64
+ // Apply type filter if provided
65
+ if (options?.type && transformedAction.type !== options.type) {
66
+ continue;
67
+ }
68
+
69
+ actions.push(transformedAction);
70
+ }
71
+ }
72
+ }
73
+
74
+ // Add pagination metadata for app-specific queries
75
+ if (actions.length > 0) {
76
+ (actions as any).__pagination = {
77
+ count: data.count,
78
+ hasNext: !!data.next,
79
+ hasPrevious: !!data.previous,
80
+ nextUrl: data.next,
81
+ previousUrl: data.previous,
82
+ };
83
+ }
84
+
85
+ return actions;
86
+ } catch (error) {
87
+ // If it's an AppNotFoundError, don't try fallback - just re-throw
88
+ if (error instanceof Error && error.name === "AppNotFoundError") {
89
+ throw error;
90
+ }
91
+ // Fallback to original approach if optimized approach fails
92
+ console.warn(
93
+ "Optimized app lookup failed, falling back to full scan:",
94
+ error,
95
+ );
96
+ }
97
+ }
98
+
99
+ // Original approach for general queries or when optimization fails
100
+ const searchParams = {
101
+ global: "true",
102
+ public_only: "true",
103
+ };
104
+
105
+ const data = await api.get("/api/v4/implementations/", { searchParams });
106
+ const actions: Action[] = [];
107
+
108
+ // Transform implementations to actions
109
+ for (const implementation of data.results || []) {
110
+ if (implementation.actions) {
111
+ for (const action of implementation.actions) {
112
+ const transformedAction: Action = {
113
+ key: action.key,
114
+ name: action.name || action.label,
115
+ description: action.description || "",
116
+ appKey: implementation.slug || "",
117
+ type: action.type || action.type_of || "read",
118
+ inputFields: [], // Would need additional API call for detailed fields
119
+ outputFields: [],
120
+ };
121
+
122
+ // Apply filters
123
+ if (options?.appKey && transformedAction.appKey !== options.appKey) {
124
+ continue;
125
+ }
126
+ if (options?.type && transformedAction.type !== options.type) {
127
+ continue;
128
+ }
129
+
130
+ actions.push(transformedAction);
131
+ }
132
+ }
133
+ }
134
+
135
+ // Add pagination metadata for general queries
136
+ if (actions.length > 0) {
137
+ (actions as any).__pagination = {
138
+ count: data.count,
139
+ hasNext: !!data.next,
140
+ hasPrevious: !!data.previous,
141
+ nextUrl: data.next,
142
+ previousUrl: data.previous,
143
+ };
144
+ }
145
+
146
+ return actions;
147
+ }
148
+
149
+ // No registry info here - moved to info.ts for proper tree-shaking
@@ -0,0 +1,9 @@
1
+ import { listActions } from "./index";
2
+ import { ListActionsSchema } from "./schemas";
3
+
4
+ // Function registry info - imports both function and schema
5
+ export const listActionsInfo = {
6
+ name: listActions.name,
7
+ inputSchema: ListActionsSchema,
8
+ implementation: listActions,
9
+ };
@@ -0,0 +1,40 @@
1
+ import { z } from "zod";
2
+ import {
3
+ AppKeyPropertySchema,
4
+ ActionTypePropertySchema,
5
+ } from "../../types/properties";
6
+ import { withOutputSchema } from "../../schema-utils";
7
+ import { ActionItemSchema } from "../../schemas/Action";
8
+ import type { Action } from "../../types/domain";
9
+
10
+ // Pure Zod schema - no resolver metadata!
11
+ export const ListActionsSchema = withOutputSchema(
12
+ z
13
+ .object({
14
+ appKey: AppKeyPropertySchema.optional(),
15
+ type: ActionTypePropertySchema.optional().describe(
16
+ "Filter actions by type",
17
+ ),
18
+ })
19
+ .describe("List all actions for a specific app"),
20
+ ActionItemSchema,
21
+ );
22
+
23
+ // Type inferred from schema + function config
24
+ export type ListActionsOptions = z.infer<typeof ListActionsSchema> & {
25
+ /** Base URL for Zapier API */
26
+ baseUrl?: string;
27
+ /** Authentication token */
28
+ token?: string;
29
+ /** Optional pre-instantiated API client */
30
+ api?: any;
31
+ /** Enable debug logging */
32
+ debug?: boolean;
33
+ /** Custom fetch implementation */
34
+ fetch?: typeof globalThis.fetch;
35
+ };
36
+
37
+ // SDK function interface - ready to be mixed into main SDK interface
38
+ export interface ListActionsSdkFunction {
39
+ listActions: (options?: Partial<ListActionsOptions>) => Promise<Action[]>;
40
+ }
@@ -0,0 +1,60 @@
1
+ import { getOrCreateApiClient } from "../../api";
2
+ import type { Integration } from "../../types/domain";
3
+ import type { ListAppsOptions } from "./schemas";
4
+
5
+ /**
6
+ * List available apps with optional filtering
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, pagination, and API configuration options
12
+ * @returns Promise<Integration[]> with pagination metadata
13
+ */
14
+ export async function listApps(
15
+ options: ListAppsOptions = {},
16
+ ): Promise<Integration[]> {
17
+ const api = getOrCreateApiClient(options);
18
+
19
+ // Build search parameters
20
+ const searchParams: Record<string, string> = {};
21
+ if (options.category) {
22
+ searchParams.category = options.category;
23
+ }
24
+ if (options.limit) {
25
+ searchParams.limit = options.limit.toString();
26
+ }
27
+ if (options.offset) {
28
+ searchParams.offset = options.offset.toString();
29
+ }
30
+
31
+ const data = await api.get("/api/v4/apps/", { searchParams });
32
+
33
+ // Transform API response to our Integration interface
34
+ const apps =
35
+ data.results?.map(
36
+ (app: any): Integration => ({
37
+ key: app.slug,
38
+ name: app.name,
39
+ description: app.description,
40
+ version: "1.0.0", // API doesn't provide version
41
+ category: app.category?.name,
42
+ actions: [], // Will be populated separately
43
+ triggers: [],
44
+ current_implementation_id: app.current_implementation_id,
45
+ }),
46
+ ) || [];
47
+
48
+ // Add pagination metadata to the response
49
+ if (apps.length > 0) {
50
+ (apps as any).__pagination = {
51
+ count: data.count,
52
+ hasNext: !!data.next,
53
+ hasPrevious: !!data.previous,
54
+ nextUrl: data.next,
55
+ previousUrl: data.previous,
56
+ };
57
+ }
58
+
59
+ return apps;
60
+ }
@@ -0,0 +1,9 @@
1
+ import { listApps } from "./index";
2
+ import { ListAppsSchema } from "./schemas";
3
+
4
+ // Function registry info - imports both function and schema
5
+ export const listAppsInfo = {
6
+ name: listApps.name,
7
+ inputSchema: ListAppsSchema,
8
+ implementation: listApps,
9
+ };
@@ -0,0 +1,43 @@
1
+ import { z } from "zod";
2
+ import {
3
+ LimitPropertySchema,
4
+ OffsetPropertySchema,
5
+ } from "../../types/properties";
6
+ import { withOutputSchema } from "../../schema-utils";
7
+ import { AppItemSchema } from "../../schemas/App";
8
+ import type { Integration } from "../../types/domain";
9
+
10
+ // Pure Zod schema - no resolver metadata!
11
+ export const ListAppsSchema = withOutputSchema(
12
+ z
13
+ .object({
14
+ category: z.string().optional().describe("Filter apps by category"),
15
+ limit: LimitPropertySchema.optional().describe(
16
+ "Maximum number of items to return (1-200)",
17
+ ),
18
+ offset: OffsetPropertySchema.optional().describe(
19
+ "Number of items to skip for pagination",
20
+ ),
21
+ })
22
+ .describe("List all available apps with optional filtering"),
23
+ AppItemSchema,
24
+ );
25
+
26
+ // Type inferred from schema + function config
27
+ export type ListAppsOptions = z.infer<typeof ListAppsSchema> & {
28
+ /** Base URL for Zapier API */
29
+ baseUrl?: string;
30
+ /** Authentication token */
31
+ token?: string;
32
+ /** Optional pre-instantiated API client */
33
+ api?: any;
34
+ /** Enable debug logging */
35
+ debug?: boolean;
36
+ /** Custom fetch implementation */
37
+ fetch?: typeof globalThis.fetch;
38
+ };
39
+
40
+ // SDK function interface - ready to be mixed into main SDK interface
41
+ export interface ListAppsSdkFunction {
42
+ listApps: (options?: Partial<ListAppsOptions>) => Promise<Integration[]>;
43
+ }
@@ -0,0 +1,153 @@
1
+ import { getOrCreateApiClient } from "../../api";
2
+ import type {
3
+ Authentication,
4
+ AuthenticationsResponse,
5
+ } from "../../types/domain";
6
+ import { getApp } from "../getApp";
7
+ import type { ListAuthsOptions } from "./schemas";
8
+
9
+ /**
10
+ * List available authentications with optional filtering
11
+ *
12
+ * This function can be used standalone without instantiating a full SDK,
13
+ * which enables better tree-shaking in applications that only need this functionality.
14
+ *
15
+ * @param options - Filtering, pagination, and API configuration options
16
+ * @returns Promise<Authentication[]> with pagination metadata
17
+ */
18
+ export async function listAuths(
19
+ options: Partial<ListAuthsOptions> = {},
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
+ const api = getOrCreateApiClient(options);
30
+
31
+ // Local function to handle the actual API fetching
32
+ const listAuthsInternal = async (
33
+ options: ListAuthsOptions = {},
34
+ ): Promise<Authentication[]> => {
35
+ // Build search parameters
36
+ const searchParams: Record<string, string> = {};
37
+
38
+ // Handle appKey filtering by getting the selected_api first
39
+ if (options.appKey) {
40
+ try {
41
+ // Use the standalone getApp function
42
+ const app = await getApp({
43
+ appKey: options.appKey,
44
+ api,
45
+ token: options.token,
46
+ baseUrl: options.baseUrl,
47
+ debug: options.debug,
48
+ fetch: options.fetch,
49
+ });
50
+ const selectedApi = app.current_implementation_id;
51
+ if (selectedApi) {
52
+ // Use versionless_selected_api to find auths across all app versions
53
+ // Extract the base name without the version (e.g., "SlackCLIAPI" from "SlackCLIAPI@1.21.1")
54
+ const versionlessApi = selectedApi.split("@")[0];
55
+ searchParams.versionless_selected_api = versionlessApi;
56
+ }
57
+ } catch (error) {
58
+ // If it's an AppNotFoundError, re-throw it
59
+ if (error instanceof Error && error.name === "AppNotFoundError") {
60
+ throw error;
61
+ }
62
+ // For other errors, continue without app filtering
63
+ console.warn(
64
+ `Warning: Could not filter by app ${options.appKey}:`,
65
+ error instanceof Error ? error.message : "Unknown error",
66
+ );
67
+ }
68
+ }
69
+
70
+ // Add other query parameters if provided
71
+ if (options.account_id) {
72
+ searchParams.account_id = options.account_id;
73
+ }
74
+ if (options.owner) {
75
+ searchParams.owner = options.owner;
76
+ }
77
+ if (options.limit) {
78
+ searchParams.limit = options.limit.toString();
79
+ }
80
+ if (options.offset) {
81
+ searchParams.offset = options.offset.toString();
82
+ }
83
+
84
+ const data: AuthenticationsResponse = await api.get(
85
+ "/api/v4/authentications/",
86
+ {
87
+ searchParams,
88
+ customErrorHandler: (response) => {
89
+ if (response.status === 401) {
90
+ return new Error(
91
+ `Authentication failed. Your token may not have permission to access authentications or may be expired. (HTTP ${response.status})`,
92
+ );
93
+ }
94
+ if (response.status === 403) {
95
+ return new Error(
96
+ `Access forbidden. Your token may not have the required scopes to list authentications. (HTTP ${response.status})`,
97
+ );
98
+ }
99
+ return undefined;
100
+ },
101
+ },
102
+ );
103
+
104
+ // Transform API response
105
+ const auths = data.results || [];
106
+
107
+ // Add pagination metadata to the response
108
+ if (auths.length > 0) {
109
+ (auths as any).__pagination = {
110
+ count: data.count,
111
+ hasNext: !!data.next,
112
+ hasPrevious: !!data.previous,
113
+ nextUrl: data.next,
114
+ previousUrl: data.previous,
115
+ };
116
+ }
117
+
118
+ return auths;
119
+ };
120
+
121
+ // If a limit is provided and no specific owner filter, prioritize owned auths
122
+ if (options.limit && options.owner === undefined) {
123
+ // First get owned auths
124
+ const ownedAuths = await listAuthsInternal({
125
+ ...options,
126
+ owner: "me",
127
+ });
128
+
129
+ // If we have enough owned auths, just slice and return
130
+ if (ownedAuths.length >= options.limit) {
131
+ return ownedAuths.slice(0, options.limit);
132
+ }
133
+
134
+ // Get all auths up to the original limit to fill remaining slots
135
+ const allAuths = await listAuthsInternal({
136
+ ...options,
137
+ owner: undefined,
138
+ });
139
+
140
+ // Filter out auths the user already owns to avoid duplicates
141
+ const ownedAuthenticationIds = new Set(ownedAuths.map((auth) => auth.id));
142
+ const additionalAuths = allAuths.filter(
143
+ (auth) => !ownedAuthenticationIds.has(auth.id),
144
+ );
145
+
146
+ // Combine and slice to the requested limit
147
+ const combined = [...ownedAuths, ...additionalAuths];
148
+ return combined.slice(0, options.limit);
149
+ }
150
+
151
+ // Standard implementation for non-prioritized requests
152
+ return listAuthsInternal(options);
153
+ }
@@ -0,0 +1,9 @@
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
+ };