@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,128 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.listActions = listActions;
4
+ const api_1 = require("../../api");
5
+ const getApp_1 = require("../getApp");
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
+ async function listActions(options = {}) {
16
+ const api = (0, api_1.getOrCreateApiClient)(options);
17
+ // If filtering by appKey, use optimized approach with selected_apis parameter
18
+ if (options.appKey) {
19
+ try {
20
+ // Use the standalone getApp function
21
+ const appData = await (0, getApp_1.getApp)({
22
+ appKey: options.appKey,
23
+ api,
24
+ token: options.token,
25
+ baseUrl: options.baseUrl,
26
+ debug: options.debug,
27
+ fetch: options.fetch,
28
+ });
29
+ // Extract implementation name from current_implementation_id (e.g., "SlackCLIAPI@1.20.0" -> "SlackCLIAPI")
30
+ const implementationId = appData.current_implementation_id?.split("@")[0];
31
+ if (!implementationId) {
32
+ throw new Error("No current_implementation_id found for app");
33
+ }
34
+ const searchParams = {
35
+ global: "true",
36
+ public_only: "true",
37
+ selected_apis: implementationId,
38
+ };
39
+ const data = await api.get("/api/v4/implementations/", {
40
+ searchParams,
41
+ });
42
+ const actions = [];
43
+ // Transform implementations to actions
44
+ for (const implementation of data.results || []) {
45
+ if (implementation.actions) {
46
+ for (const action of implementation.actions) {
47
+ const transformedAction = {
48
+ key: action.key,
49
+ name: action.name || action.label,
50
+ description: action.description || "",
51
+ appKey: implementation.slug || "",
52
+ type: action.type || action.type_of || "read",
53
+ inputFields: [], // Would need additional API call for detailed fields
54
+ outputFields: [],
55
+ };
56
+ // Apply type filter if provided
57
+ if (options?.type && transformedAction.type !== options.type) {
58
+ continue;
59
+ }
60
+ actions.push(transformedAction);
61
+ }
62
+ }
63
+ }
64
+ // Add pagination metadata for app-specific queries
65
+ if (actions.length > 0) {
66
+ actions.__pagination = {
67
+ count: data.count,
68
+ hasNext: !!data.next,
69
+ hasPrevious: !!data.previous,
70
+ nextUrl: data.next,
71
+ previousUrl: data.previous,
72
+ };
73
+ }
74
+ return actions;
75
+ }
76
+ catch (error) {
77
+ // If it's an AppNotFoundError, don't try fallback - just re-throw
78
+ if (error instanceof Error && error.name === "AppNotFoundError") {
79
+ throw error;
80
+ }
81
+ // Fallback to original approach if optimized approach fails
82
+ console.warn("Optimized app lookup failed, falling back to full scan:", error);
83
+ }
84
+ }
85
+ // Original approach for general queries or when optimization fails
86
+ const searchParams = {
87
+ global: "true",
88
+ public_only: "true",
89
+ };
90
+ const data = await api.get("/api/v4/implementations/", { searchParams });
91
+ const actions = [];
92
+ // Transform implementations to actions
93
+ for (const implementation of data.results || []) {
94
+ if (implementation.actions) {
95
+ for (const action of implementation.actions) {
96
+ const transformedAction = {
97
+ key: action.key,
98
+ name: action.name || action.label,
99
+ description: action.description || "",
100
+ appKey: implementation.slug || "",
101
+ type: action.type || action.type_of || "read",
102
+ inputFields: [], // Would need additional API call for detailed fields
103
+ outputFields: [],
104
+ };
105
+ // Apply filters
106
+ if (options?.appKey && transformedAction.appKey !== options.appKey) {
107
+ continue;
108
+ }
109
+ if (options?.type && transformedAction.type !== options.type) {
110
+ continue;
111
+ }
112
+ actions.push(transformedAction);
113
+ }
114
+ }
115
+ }
116
+ // Add pagination metadata for general queries
117
+ if (actions.length > 0) {
118
+ actions.__pagination = {
119
+ count: data.count,
120
+ hasNext: !!data.next,
121
+ hasPrevious: !!data.previous,
122
+ nextUrl: data.next,
123
+ previousUrl: data.previous,
124
+ };
125
+ }
126
+ return actions;
127
+ }
128
+ // No registry info here - moved to info.ts for proper tree-shaking
@@ -0,0 +1,15 @@
1
+ import { listActions } from "./index";
2
+ export declare const listActionsInfo: {
3
+ name: string;
4
+ inputSchema: import("zod").ZodObject<{
5
+ appKey: import("zod").ZodOptional<import("zod").ZodString>;
6
+ type: import("zod").ZodOptional<import("zod").ZodEnum<["read", "write", "search", "create", "update", "delete"]>>;
7
+ }, "strip", import("zod").ZodTypeAny, {
8
+ type?: "create" | "update" | "search" | "delete" | "read" | "write" | undefined;
9
+ appKey?: string | undefined;
10
+ }, {
11
+ type?: "create" | "update" | "search" | "delete" | "read" | "write" | undefined;
12
+ appKey?: string | undefined;
13
+ }>;
14
+ implementation: typeof listActions;
15
+ };
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.listActionsInfo = 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.listActionsInfo = {
8
+ name: index_1.listActions.name,
9
+ inputSchema: schemas_1.ListActionsSchema,
10
+ implementation: index_1.listActions,
11
+ };
@@ -0,0 +1,27 @@
1
+ import { z } from "zod";
2
+ import type { Action } from "../../types/domain";
3
+ export declare const ListActionsSchema: z.ZodObject<{
4
+ appKey: z.ZodOptional<z.ZodString>;
5
+ type: z.ZodOptional<z.ZodEnum<["read", "write", "search", "create", "update", "delete"]>>;
6
+ }, "strip", z.ZodTypeAny, {
7
+ type?: "create" | "update" | "search" | "delete" | "read" | "write" | undefined;
8
+ appKey?: string | undefined;
9
+ }, {
10
+ type?: "create" | "update" | "search" | "delete" | "read" | "write" | undefined;
11
+ appKey?: string | undefined;
12
+ }>;
13
+ export type ListActionsOptions = z.infer<typeof ListActionsSchema> & {
14
+ /** Base URL for Zapier API */
15
+ baseUrl?: string;
16
+ /** Authentication token */
17
+ token?: string;
18
+ /** Optional pre-instantiated API client */
19
+ api?: any;
20
+ /** Enable debug logging */
21
+ debug?: boolean;
22
+ /** Custom fetch implementation */
23
+ fetch?: typeof globalThis.fetch;
24
+ };
25
+ export interface ListActionsSdkFunction {
26
+ listActions: (options?: Partial<ListActionsOptions>) => Promise<Action[]>;
27
+ }
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ListActionsSchema = 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 Action_1 = require("../../schemas/Action");
8
+ // Pure Zod schema - no resolver metadata!
9
+ exports.ListActionsSchema = (0, schema_utils_1.withOutputSchema)(zod_1.z
10
+ .object({
11
+ appKey: properties_1.AppKeyPropertySchema.optional(),
12
+ type: properties_1.ActionTypePropertySchema.optional().describe("Filter actions by type"),
13
+ })
14
+ .describe("List all actions for a specific app"), Action_1.ActionItemSchema);
@@ -0,0 +1,12 @@
1
+ import type { Integration } from "../../types/domain";
2
+ import type { ListAppsOptions } from "./schemas";
3
+ /**
4
+ * List available apps with optional filtering
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, pagination, and API configuration options
10
+ * @returns Promise<Integration[]> with pagination metadata
11
+ */
12
+ export declare function listApps(options?: ListAppsOptions): Promise<Integration[]>;
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.listApps = listApps;
4
+ const api_1 = require("../../api");
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
+ async function listApps(options = {}) {
15
+ const api = (0, api_1.getOrCreateApiClient)(options);
16
+ // Build search parameters
17
+ const searchParams = {};
18
+ if (options.category) {
19
+ searchParams.category = options.category;
20
+ }
21
+ if (options.limit) {
22
+ searchParams.limit = options.limit.toString();
23
+ }
24
+ if (options.offset) {
25
+ searchParams.offset = options.offset.toString();
26
+ }
27
+ const data = await api.get("/api/v4/apps/", { searchParams });
28
+ // Transform API response to our Integration interface
29
+ const apps = data.results?.map((app) => ({
30
+ key: app.slug,
31
+ name: app.name,
32
+ description: app.description,
33
+ version: "1.0.0", // API doesn't provide version
34
+ category: app.category?.name,
35
+ actions: [], // Will be populated separately
36
+ triggers: [],
37
+ current_implementation_id: app.current_implementation_id,
38
+ })) || [];
39
+ // Add pagination metadata to the response
40
+ if (apps.length > 0) {
41
+ apps.__pagination = {
42
+ count: data.count,
43
+ hasNext: !!data.next,
44
+ hasPrevious: !!data.previous,
45
+ nextUrl: data.next,
46
+ previousUrl: data.previous,
47
+ };
48
+ }
49
+ return apps;
50
+ }
@@ -0,0 +1,18 @@
1
+ import { listApps } from "./index";
2
+ export declare const listAppsInfo: {
3
+ name: string;
4
+ inputSchema: import("zod").ZodObject<{
5
+ category: import("zod").ZodOptional<import("zod").ZodString>;
6
+ limit: import("zod").ZodOptional<import("zod").ZodDefault<import("zod").ZodNumber>>;
7
+ offset: import("zod").ZodOptional<import("zod").ZodDefault<import("zod").ZodNumber>>;
8
+ }, "strip", import("zod").ZodTypeAny, {
9
+ category?: string | undefined;
10
+ limit?: number | undefined;
11
+ offset?: number | undefined;
12
+ }, {
13
+ category?: string | undefined;
14
+ limit?: number | undefined;
15
+ offset?: number | undefined;
16
+ }>;
17
+ implementation: typeof listApps;
18
+ };
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.listAppsInfo = 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.listAppsInfo = {
8
+ name: index_1.listApps.name,
9
+ inputSchema: schemas_1.ListAppsSchema,
10
+ implementation: index_1.listApps,
11
+ };
@@ -0,0 +1,30 @@
1
+ import { z } from "zod";
2
+ import type { Integration } from "../../types/domain";
3
+ export declare const ListAppsSchema: z.ZodObject<{
4
+ category: z.ZodOptional<z.ZodString>;
5
+ limit: z.ZodOptional<z.ZodDefault<z.ZodNumber>>;
6
+ offset: z.ZodOptional<z.ZodDefault<z.ZodNumber>>;
7
+ }, "strip", z.ZodTypeAny, {
8
+ category?: string | undefined;
9
+ limit?: number | undefined;
10
+ offset?: number | undefined;
11
+ }, {
12
+ category?: string | undefined;
13
+ limit?: number | undefined;
14
+ offset?: number | undefined;
15
+ }>;
16
+ export type ListAppsOptions = z.infer<typeof ListAppsSchema> & {
17
+ /** Base URL for Zapier API */
18
+ baseUrl?: string;
19
+ /** Authentication token */
20
+ token?: string;
21
+ /** Optional pre-instantiated API client */
22
+ api?: any;
23
+ /** Enable debug logging */
24
+ debug?: boolean;
25
+ /** Custom fetch implementation */
26
+ fetch?: typeof globalThis.fetch;
27
+ };
28
+ export interface ListAppsSdkFunction {
29
+ listApps: (options?: Partial<ListAppsOptions>) => Promise<Integration[]>;
30
+ }
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ListAppsSchema = 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 App_1 = require("../../schemas/App");
8
+ // Pure Zod schema - no resolver metadata!
9
+ exports.ListAppsSchema = (0, schema_utils_1.withOutputSchema)(zod_1.z
10
+ .object({
11
+ category: zod_1.z.string().optional().describe("Filter apps by category"),
12
+ limit: properties_1.LimitPropertySchema.optional().describe("Maximum number of items to return (1-200)"),
13
+ offset: properties_1.OffsetPropertySchema.optional().describe("Number of items to skip for pagination"),
14
+ })
15
+ .describe("List all available apps with optional filtering"), App_1.AppItemSchema);
@@ -0,0 +1,12 @@
1
+ import type { Authentication } from "../../types/domain";
2
+ import type { ListAuthsOptions } from "./schemas";
3
+ /**
4
+ * List available authentications with optional filtering
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, pagination, and API configuration options
10
+ * @returns Promise<Authentication[]> with pagination metadata
11
+ */
12
+ export declare function listAuths(options?: Partial<ListAuthsOptions>): Promise<Authentication[]>;
@@ -0,0 +1,118 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.listAuths = listAuths;
4
+ const api_1 = require("../../api");
5
+ const getApp_1 = require("../getApp");
6
+ /**
7
+ * List available authentications 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, pagination, and API configuration options
13
+ * @returns Promise<Authentication[]> with pagination metadata
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
+ }
20
+ const api = (0, api_1.getOrCreateApiClient)(options);
21
+ // Local function to handle the actual API fetching
22
+ const listAuthsInternal = async (options = {}) => {
23
+ // Build search parameters
24
+ const searchParams = {};
25
+ // Handle appKey filtering by getting the selected_api first
26
+ if (options.appKey) {
27
+ try {
28
+ // Use the standalone getApp function
29
+ const app = await (0, getApp_1.getApp)({
30
+ appKey: options.appKey,
31
+ api,
32
+ token: options.token,
33
+ baseUrl: options.baseUrl,
34
+ debug: options.debug,
35
+ fetch: options.fetch,
36
+ });
37
+ const selectedApi = app.current_implementation_id;
38
+ if (selectedApi) {
39
+ // Use versionless_selected_api to find auths across all app versions
40
+ // Extract the base name without the version (e.g., "SlackCLIAPI" from "SlackCLIAPI@1.21.1")
41
+ const versionlessApi = selectedApi.split("@")[0];
42
+ searchParams.versionless_selected_api = versionlessApi;
43
+ }
44
+ }
45
+ catch (error) {
46
+ // If it's an AppNotFoundError, re-throw it
47
+ if (error instanceof Error && error.name === "AppNotFoundError") {
48
+ throw error;
49
+ }
50
+ // For other errors, continue without app filtering
51
+ console.warn(`Warning: Could not filter by app ${options.appKey}:`, error instanceof Error ? error.message : "Unknown error");
52
+ }
53
+ }
54
+ // Add other query parameters if provided
55
+ if (options.account_id) {
56
+ searchParams.account_id = options.account_id;
57
+ }
58
+ if (options.owner) {
59
+ searchParams.owner = options.owner;
60
+ }
61
+ if (options.limit) {
62
+ searchParams.limit = options.limit.toString();
63
+ }
64
+ if (options.offset) {
65
+ searchParams.offset = options.offset.toString();
66
+ }
67
+ const data = await api.get("/api/v4/authentications/", {
68
+ searchParams,
69
+ customErrorHandler: (response) => {
70
+ if (response.status === 401) {
71
+ return new Error(`Authentication failed. Your token may not have permission to access authentications or may be expired. (HTTP ${response.status})`);
72
+ }
73
+ if (response.status === 403) {
74
+ return new Error(`Access forbidden. Your token may not have the required scopes to list authentications. (HTTP ${response.status})`);
75
+ }
76
+ return undefined;
77
+ },
78
+ });
79
+ // Transform API response
80
+ const auths = data.results || [];
81
+ // Add pagination metadata to the response
82
+ if (auths.length > 0) {
83
+ auths.__pagination = {
84
+ count: data.count,
85
+ hasNext: !!data.next,
86
+ hasPrevious: !!data.previous,
87
+ nextUrl: data.next,
88
+ previousUrl: data.previous,
89
+ };
90
+ }
91
+ return auths;
92
+ };
93
+ // If a limit is provided and no specific owner filter, prioritize owned auths
94
+ if (options.limit && options.owner === undefined) {
95
+ // First get owned auths
96
+ const ownedAuths = await listAuthsInternal({
97
+ ...options,
98
+ owner: "me",
99
+ });
100
+ // If we have enough owned auths, just slice and return
101
+ if (ownedAuths.length >= options.limit) {
102
+ return ownedAuths.slice(0, options.limit);
103
+ }
104
+ // Get all auths up to the original limit to fill remaining slots
105
+ const allAuths = await listAuthsInternal({
106
+ ...options,
107
+ owner: undefined,
108
+ });
109
+ // Filter out auths the user already owns to avoid duplicates
110
+ const ownedAuthenticationIds = new Set(ownedAuths.map((auth) => auth.id));
111
+ const additionalAuths = allAuths.filter((auth) => !ownedAuthenticationIds.has(auth.id));
112
+ // Combine and slice to the requested limit
113
+ const combined = [...ownedAuths, ...additionalAuths];
114
+ return combined.slice(0, options.limit);
115
+ }
116
+ // Standard implementation for non-prioritized requests
117
+ return listAuthsInternal(options);
118
+ }
@@ -0,0 +1,24 @@
1
+ import { listAuths } from "./index";
2
+ export declare const listAuthsInfo: {
3
+ name: string;
4
+ inputSchema: import("zod").ZodObject<{
5
+ appKey: import("zod").ZodOptional<import("zod").ZodString>;
6
+ account_id: import("zod").ZodOptional<import("zod").ZodString>;
7
+ owner: import("zod").ZodOptional<import("zod").ZodString>;
8
+ limit: import("zod").ZodOptional<import("zod").ZodDefault<import("zod").ZodNumber>>;
9
+ offset: import("zod").ZodOptional<import("zod").ZodDefault<import("zod").ZodNumber>>;
10
+ }, "strip", import("zod").ZodTypeAny, {
11
+ appKey?: string | undefined;
12
+ account_id?: string | undefined;
13
+ owner?: string | undefined;
14
+ limit?: number | undefined;
15
+ offset?: number | undefined;
16
+ }, {
17
+ appKey?: string | undefined;
18
+ account_id?: string | undefined;
19
+ owner?: string | undefined;
20
+ limit?: number | undefined;
21
+ offset?: number | undefined;
22
+ }>;
23
+ implementation: typeof listAuths;
24
+ };
@@ -0,0 +1,11 @@
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
+ };
@@ -0,0 +1,36 @@
1
+ import { z } from "zod";
2
+ import type { Authentication } from "../../types/domain";
3
+ export declare const ListAuthsSchema: z.ZodObject<{
4
+ appKey: z.ZodOptional<z.ZodString>;
5
+ account_id: z.ZodOptional<z.ZodString>;
6
+ owner: z.ZodOptional<z.ZodString>;
7
+ limit: z.ZodOptional<z.ZodDefault<z.ZodNumber>>;
8
+ offset: z.ZodOptional<z.ZodDefault<z.ZodNumber>>;
9
+ }, "strip", z.ZodTypeAny, {
10
+ appKey?: string | undefined;
11
+ account_id?: string | undefined;
12
+ owner?: string | undefined;
13
+ limit?: number | undefined;
14
+ offset?: number | undefined;
15
+ }, {
16
+ appKey?: string | undefined;
17
+ account_id?: string | undefined;
18
+ owner?: string | undefined;
19
+ limit?: number | undefined;
20
+ offset?: number | undefined;
21
+ }>;
22
+ export type ListAuthsOptions = z.infer<typeof ListAuthsSchema> & {
23
+ /** Base URL for Zapier API */
24
+ baseUrl?: string;
25
+ /** Authentication token */
26
+ token?: string;
27
+ /** Optional pre-instantiated API client */
28
+ api?: any;
29
+ /** Enable debug logging */
30
+ debug?: boolean;
31
+ /** Custom fetch implementation */
32
+ fetch?: typeof globalThis.fetch;
33
+ };
34
+ export interface ListAuthsSdkFunction {
35
+ listAuths: (options?: Partial<ListAuthsOptions>) => Promise<Authentication[]>;
36
+ }
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ListAuthsSchema = 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.ListAuthsSchema = (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
+ account_id: zod_1.z.string().optional().describe("Filter by account ID"),
13
+ owner: zod_1.z.string().optional().describe("Filter by owner"),
14
+ limit: properties_1.LimitPropertySchema.optional().describe("Maximum number of items to return (1-200)"),
15
+ offset: properties_1.OffsetPropertySchema.optional().describe("Number of items to skip for pagination"),
16
+ })
17
+ .describe("List available authentications with optional filtering"), Auth_1.AuthItemSchema);
@@ -0,0 +1,12 @@
1
+ import type { ActionField } from "../../types/domain";
2
+ import type { ListFieldsOptions } from "./schemas";
3
+ /**
4
+ * List available fields for an action
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 - Action details, authentication ID, params, and API configuration options
10
+ * @returns Promise<ActionField[]>
11
+ */
12
+ export declare function listFields(options: ListFieldsOptions): Promise<ActionField[]>;
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.listFields = listFields;
4
+ const api_1 = require("../../api");
5
+ const getApp_1 = require("../getApp");
6
+ /**
7
+ * List available fields for an action
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 - Action details, authentication ID, params, and API configuration options
13
+ * @returns Promise<ActionField[]>
14
+ */
15
+ async function listFields(options) {
16
+ const api = (0, api_1.getOrCreateApiClient)(options);
17
+ // Extract parameters
18
+ const { appKey, actionKey, actionType, authenticationId, params } = options;
19
+ // Use the standalone getApp function
20
+ const appData = await (0, getApp_1.getApp)({
21
+ appKey,
22
+ api,
23
+ token: options.token,
24
+ baseUrl: options.baseUrl,
25
+ debug: options.debug,
26
+ fetch: options.fetch,
27
+ });
28
+ const selectedApi = appData.current_implementation_id;
29
+ if (!selectedApi) {
30
+ throw new Error("No current_implementation_id found for app");
31
+ }
32
+ // Build needs request
33
+ const needsRequest = {
34
+ selected_api: selectedApi,
35
+ action: actionKey,
36
+ type_of: actionType,
37
+ authentication_id: authenticationId,
38
+ params: params || {},
39
+ };
40
+ const needsData = await api.post("/api/v4/implementations/needs/", needsRequest);
41
+ if (!needsData.success) {
42
+ throw new Error(`Failed to get action fields: ${needsData.errors?.join(", ") || "Unknown error"}`);
43
+ }
44
+ // Transform API response to our ActionField interface
45
+ return (needsData.needs || []).map((need) => ({
46
+ key: need.key,
47
+ label: need.label,
48
+ required: need.required || false,
49
+ type: need.type,
50
+ helpText: need.help_text,
51
+ helpTextHtml: need.help_text_html,
52
+ choices: need.choices?.map((choice) => ({
53
+ value: choice.value,
54
+ label: choice.label,
55
+ })),
56
+ default: need.default,
57
+ placeholder: need.placeholder,
58
+ computed: need.computed,
59
+ customField: need.custom_field,
60
+ dependsOn: need.depends_on,
61
+ format: need.format,
62
+ inputFormat: need.input_format,
63
+ }));
64
+ }
65
+ // No registry info here - moved to info.ts for proper tree-shaking