@zapier/zapier-sdk 0.3.1 → 0.4.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 (158) hide show
  1. package/dist/index.cjs +2001 -0
  2. package/dist/index.d.mts +840 -0
  3. package/dist/index.d.ts +840 -20
  4. package/dist/index.mjs +1955 -0
  5. package/package.json +19 -7
  6. package/src/api/client.ts +84 -16
  7. package/src/api/types.ts +9 -1
  8. package/src/auth.ts +19 -287
  9. package/src/functions/fetch/index.ts +180 -0
  10. package/src/functions/fetch/info.ts +8 -0
  11. package/src/functions/fetch/schemas.ts +46 -0
  12. package/src/functions/findFirstAuthentication/schemas.ts +3 -13
  13. package/src/functions/findUniqueAuthentication/schemas.ts +3 -13
  14. package/src/functions/generateTypes/index.ts +15 -0
  15. package/src/functions/generateTypes/schemas.ts +3 -10
  16. package/src/functions/getAction/schemas.ts +3 -13
  17. package/src/functions/getApp/schemas.ts +2 -13
  18. package/src/functions/getAuthentication/index.ts +0 -1
  19. package/src/functions/getAuthentication/schemas.ts +3 -17
  20. package/src/functions/listActions/schemas.ts +3 -13
  21. package/src/functions/listApps/schemas.ts +2 -13
  22. package/src/functions/listAuthentications/index.ts +0 -1
  23. package/src/functions/listAuthentications/schemas.ts +3 -15
  24. package/src/functions/listFields/schemas.ts +3 -13
  25. package/src/functions/runAction/index.ts +0 -1
  26. package/src/functions/runAction/schemas.ts +6 -15
  27. package/src/index.ts +4 -2
  28. package/src/plugins/apps/index.ts +35 -9
  29. package/src/sdk.ts +20 -22
  30. package/src/types/domain.ts +16 -0
  31. package/src/types/sdk.ts +13 -1
  32. package/tsconfig.json +2 -2
  33. package/tsup.config.ts +21 -0
  34. package/dist/api/auth.d.ts +0 -8
  35. package/dist/api/auth.js +0 -29
  36. package/dist/api/client.d.ts +0 -8
  37. package/dist/api/client.js +0 -119
  38. package/dist/api/debug.d.ts +0 -12
  39. package/dist/api/debug.js +0 -50
  40. package/dist/api/index.d.ts +0 -28
  41. package/dist/api/index.js +0 -52
  42. package/dist/api/polling.d.ts +0 -17
  43. package/dist/api/polling.js +0 -34
  44. package/dist/api/types.d.ts +0 -147
  45. package/dist/api/types.js +0 -9
  46. package/dist/auth.d.ts +0 -59
  47. package/dist/auth.js +0 -261
  48. package/dist/functions/bundleCode/index.d.ts +0 -11
  49. package/dist/functions/bundleCode/index.js +0 -91
  50. package/dist/functions/bundleCode/info.d.ts +0 -27
  51. package/dist/functions/bundleCode/info.js +0 -11
  52. package/dist/functions/bundleCode/schemas.d.ts +0 -27
  53. package/dist/functions/bundleCode/schemas.js +0 -22
  54. package/dist/functions/findFirstAuthentication/index.d.ts +0 -12
  55. package/dist/functions/findFirstAuthentication/index.js +0 -21
  56. package/dist/functions/findFirstAuthentication/info.d.ts +0 -30
  57. package/dist/functions/findFirstAuthentication/info.js +0 -11
  58. package/dist/functions/findFirstAuthentication/schemas.d.ts +0 -42
  59. package/dist/functions/findFirstAuthentication/schemas.js +0 -25
  60. package/dist/functions/findUniqueAuthentication/index.d.ts +0 -13
  61. package/dist/functions/findUniqueAuthentication/index.js +0 -28
  62. package/dist/functions/findUniqueAuthentication/info.d.ts +0 -30
  63. package/dist/functions/findUniqueAuthentication/info.js +0 -11
  64. package/dist/functions/findUniqueAuthentication/schemas.d.ts +0 -42
  65. package/dist/functions/findUniqueAuthentication/schemas.js +0 -25
  66. package/dist/functions/generateTypes/index.d.ts +0 -11
  67. package/dist/functions/generateTypes/index.js +0 -305
  68. package/dist/functions/generateTypes/info.d.ts +0 -21
  69. package/dist/functions/generateTypes/info.js +0 -11
  70. package/dist/functions/generateTypes/schemas.d.ts +0 -30
  71. package/dist/functions/generateTypes/schemas.js +0 -14
  72. package/dist/functions/getAction/index.d.ts +0 -12
  73. package/dist/functions/getAction/index.js +0 -26
  74. package/dist/functions/getAction/info.d.ts +0 -18
  75. package/dist/functions/getAction/info.js +0 -11
  76. package/dist/functions/getAction/schemas.d.ts +0 -30
  77. package/dist/functions/getAction/schemas.js +0 -13
  78. package/dist/functions/getApp/index.d.ts +0 -12
  79. package/dist/functions/getApp/index.js +0 -37
  80. package/dist/functions/getApp/info.d.ts +0 -12
  81. package/dist/functions/getApp/info.js +0 -11
  82. package/dist/functions/getApp/schemas.d.ts +0 -24
  83. package/dist/functions/getApp/schemas.js +0 -11
  84. package/dist/functions/getAuthentication/index.d.ts +0 -13
  85. package/dist/functions/getAuthentication/index.js +0 -38
  86. package/dist/functions/getAuthentication/info.d.ts +0 -12
  87. package/dist/functions/getAuthentication/info.js +0 -11
  88. package/dist/functions/getAuthentication/schemas.d.ts +0 -26
  89. package/dist/functions/getAuthentication/schemas.js +0 -16
  90. package/dist/functions/listActions/index.d.ts +0 -12
  91. package/dist/functions/listActions/index.js +0 -128
  92. package/dist/functions/listActions/info.d.ts +0 -15
  93. package/dist/functions/listActions/info.js +0 -11
  94. package/dist/functions/listActions/schemas.d.ts +0 -27
  95. package/dist/functions/listActions/schemas.js +0 -14
  96. package/dist/functions/listApps/index.d.ts +0 -12
  97. package/dist/functions/listApps/index.js +0 -50
  98. package/dist/functions/listApps/info.d.ts +0 -18
  99. package/dist/functions/listApps/info.js +0 -11
  100. package/dist/functions/listApps/schemas.d.ts +0 -30
  101. package/dist/functions/listApps/schemas.js +0 -15
  102. package/dist/functions/listAuthentications/index.d.ts +0 -12
  103. package/dist/functions/listAuthentications/index.js +0 -131
  104. package/dist/functions/listAuthentications/info.d.ts +0 -30
  105. package/dist/functions/listAuthentications/info.js +0 -11
  106. package/dist/functions/listAuthentications/schemas.d.ts +0 -44
  107. package/dist/functions/listAuthentications/schemas.js +0 -25
  108. package/dist/functions/listFields/index.d.ts +0 -12
  109. package/dist/functions/listFields/index.js +0 -65
  110. package/dist/functions/listFields/info.d.ts +0 -24
  111. package/dist/functions/listFields/info.js +0 -11
  112. package/dist/functions/listFields/schemas.d.ts +0 -36
  113. package/dist/functions/listFields/schemas.js +0 -17
  114. package/dist/functions/runAction/index.d.ts +0 -12
  115. package/dist/functions/runAction/index.js +0 -86
  116. package/dist/functions/runAction/info.d.ts +0 -24
  117. package/dist/functions/runAction/info.js +0 -11
  118. package/dist/functions/runAction/schemas.d.ts +0 -38
  119. package/dist/functions/runAction/schemas.js +0 -15
  120. package/dist/index.js +0 -57
  121. package/dist/plugins/apps/index.d.ts +0 -8
  122. package/dist/plugins/apps/index.js +0 -77
  123. package/dist/plugins/apps/info.d.ts +0 -6
  124. package/dist/plugins/apps/info.js +0 -13
  125. package/dist/plugins/apps/types.d.ts +0 -21
  126. package/dist/plugins/apps/types.js +0 -2
  127. package/dist/resolvers/actionKey.d.ts +0 -8
  128. package/dist/resolvers/actionKey.js +0 -20
  129. package/dist/resolvers/actionType.d.ts +0 -8
  130. package/dist/resolvers/actionType.js +0 -21
  131. package/dist/resolvers/appKey.d.ts +0 -6
  132. package/dist/resolvers/appKey.js +0 -8
  133. package/dist/resolvers/authenticationId.d.ts +0 -8
  134. package/dist/resolvers/authenticationId.js +0 -29
  135. package/dist/resolvers/index.d.ts +0 -39
  136. package/dist/resolvers/index.js +0 -105
  137. package/dist/resolvers/inputs.d.ts +0 -7
  138. package/dist/resolvers/inputs.js +0 -15
  139. package/dist/schema-utils.d.ts +0 -44
  140. package/dist/schema-utils.js +0 -76
  141. package/dist/schemas/Action.d.ts +0 -21
  142. package/dist/schemas/Action.js +0 -31
  143. package/dist/schemas/App.d.ts +0 -19
  144. package/dist/schemas/App.js +0 -32
  145. package/dist/schemas/Auth.d.ts +0 -27
  146. package/dist/schemas/Auth.js +0 -42
  147. package/dist/schemas/Field.d.ts +0 -15
  148. package/dist/schemas/Field.js +0 -25
  149. package/dist/sdk.d.ts +0 -6
  150. package/dist/sdk.js +0 -90
  151. package/dist/types/domain.d.ts +0 -25
  152. package/dist/types/domain.js +0 -21
  153. package/dist/types/events.d.ts +0 -37
  154. package/dist/types/events.js +0 -8
  155. package/dist/types/properties.d.ts +0 -21
  156. package/dist/types/properties.js +0 -52
  157. package/dist/types/sdk.d.ts +0 -24
  158. package/dist/types/sdk.js +0 -2
@@ -1,21 +0,0 @@
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
- }
@@ -1,30 +0,0 @@
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
- };
@@ -1,11 +0,0 @@
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
- };
@@ -1,42 +0,0 @@
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
- }
@@ -1,25 +0,0 @@
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);
@@ -1,13 +0,0 @@
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>;
@@ -1,28 +0,0 @@
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
- }
@@ -1,30 +0,0 @@
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
- };
@@ -1,11 +0,0 @@
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,42 +0,0 @@
1
- import { z } from "zod";
2
- import type { Authentication } from "../../types/domain";
3
- export declare const FindUniqueAuthenticationSchema: 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 FindUniqueAuthenticationOptions = z.infer<typeof FindUniqueAuthenticationSchema> & {
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 FindUniqueAuthenticationSdkFunction {
41
- findUniqueAuthentication: (options?: Partial<FindUniqueAuthenticationOptions>) => Promise<Authentication>;
42
- }
@@ -1,25 +0,0 @@
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,11 +0,0 @@
1
- import type { GenerateTypesOptions } from "./schemas";
2
- /**
3
- * Generate TypeScript types for a specific app
4
- *
5
- * This function can be used standalone without instantiating a full SDK,
6
- * which enables better tree-shaking in applications that only need this functionality.
7
- *
8
- * @param options - App key, authentication ID, output path, and API configuration options
9
- * @returns Promise<string> - Generated TypeScript code
10
- */
11
- export declare function generateTypes(options: GenerateTypesOptions): Promise<string>;
@@ -1,305 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.generateTypes = generateTypes;
37
- const listActions_1 = require("../listActions");
38
- const listFields_1 = require("../listFields");
39
- /**
40
- * Generate TypeScript types for a specific app
41
- *
42
- * This function can be used standalone without instantiating a full SDK,
43
- * which enables better tree-shaking in applications that only need this functionality.
44
- *
45
- * @param options - App key, authentication ID, output path, and API configuration options
46
- * @returns Promise<string> - Generated TypeScript code
47
- */
48
- async function generateTypes(options) {
49
- const { appKey, authenticationId, output = `./types/${appKey}.d.ts`, } = options;
50
- // Parse app identifier (support app@version format)
51
- const { app, version } = parseAppIdentifier(appKey);
52
- // Fetch all actions for the app
53
- const actions = await (0, listActions_1.listActions)({
54
- ...options,
55
- appKey: app,
56
- });
57
- if (actions.length === 0) {
58
- const typeDefinitions = generateEmptyTypesFile(app, version);
59
- if (output) {
60
- const fs = await Promise.resolve().then(() => __importStar(require("fs")));
61
- const path = await Promise.resolve().then(() => __importStar(require("path")));
62
- fs.mkdirSync(path.dirname(output), { recursive: true });
63
- fs.writeFileSync(output, typeDefinitions, "utf8");
64
- }
65
- return typeDefinitions;
66
- }
67
- // Fetch input fields for each action
68
- const actionsWithFields = [];
69
- if (authenticationId) {
70
- for (const action of actions) {
71
- try {
72
- const fields = await (0, listFields_1.listFields)({
73
- ...options,
74
- appKey: action.appKey,
75
- actionKey: action.key,
76
- actionType: action.type,
77
- authenticationId: authenticationId,
78
- });
79
- actionsWithFields.push({ ...action, inputFields: fields });
80
- }
81
- catch {
82
- // If we can't get fields for an action, include it without fields
83
- actionsWithFields.push({ ...action, inputFields: [] });
84
- }
85
- }
86
- }
87
- else {
88
- // Convert actions to have empty input fields (will generate generic types)
89
- actions.forEach((action) => {
90
- actionsWithFields.push({ ...action, inputFields: [] });
91
- });
92
- }
93
- // Generate TypeScript types
94
- const typeDefinitions = generateTypeDefinitions(app, actionsWithFields, version);
95
- // Write to file if output path specified
96
- if (output) {
97
- const fs = await Promise.resolve().then(() => __importStar(require("fs")));
98
- const path = await Promise.resolve().then(() => __importStar(require("path")));
99
- fs.mkdirSync(path.dirname(output), { recursive: true });
100
- fs.writeFileSync(output, typeDefinitions, "utf8");
101
- }
102
- return typeDefinitions;
103
- }
104
- function parseAppIdentifier(identifier) {
105
- const parts = identifier.split("@");
106
- return {
107
- app: parts[0],
108
- version: parts[1],
109
- };
110
- }
111
- function generateTypeDefinitions(appKey, actions, version) {
112
- // Handle empty actions
113
- if (actions.length === 0) {
114
- return generateEmptyTypesFile(appKey, version);
115
- }
116
- // Group actions by type
117
- const actionsByType = actions.reduce((acc, action) => {
118
- if (!acc[action.type]) {
119
- acc[action.type] = [];
120
- }
121
- acc[action.type].push(action);
122
- return acc;
123
- }, {});
124
- const appName = capitalize(appKey);
125
- const versionComment = version
126
- ? ` * Generated for ${appKey}@${version}`
127
- : ` * Generated for ${appKey}`;
128
- let output = `/* eslint-disable @typescript-eslint/naming-convention */
129
- /**
130
- * Auto-generated TypeScript types for Zapier ${appKey} actions
131
- ${versionComment}
132
- * Generated on: ${new Date().toISOString()}
133
- *
134
- * Usage:
135
- * import type { ${appName}Sdk } from './path/to/this/file'
136
- * const sdk = createZapierSdk() as unknown as ${appName}Sdk
137
- *
138
- * // Direct usage (per-call auth):
139
- * await sdk.apps.${appKey}.search.user_by_email({ authenticationId: 123, inputs: { email } })
140
- *
141
- * // Factory usage (pinned auth):
142
- * const my${appName} = sdk.apps.${appKey}({ authenticationId: 123 })
143
- * await my${appName}.search.user_by_email({ inputs: { email } })
144
- */
145
-
146
- import type { ActionExecutionOptions, ActionExecutionResult } from '@zapier/zapier-sdk'
147
-
148
- `;
149
- // Generate input types for each action
150
- actions.forEach((action) => {
151
- if (action.inputFields.length > 0) {
152
- const inputTypeName = `${appName}${capitalize(action.type)}${capitalize(sanitizeActionName(action.key))}Inputs`;
153
- output += `interface ${inputTypeName} {\n`;
154
- action.inputFields.forEach((field) => {
155
- const isOptional = !field.required;
156
- const fieldType = mapFieldTypeToTypeScript(field);
157
- const description = field.helpText
158
- ? ` /** ${escapeComment(field.helpText)} */\n`
159
- : "";
160
- output += `${description} ${sanitizeFieldName(field.key)}${isOptional ? "?" : ""}: ${fieldType}\n`;
161
- });
162
- output += `}\n\n`;
163
- }
164
- });
165
- // Generate action type interfaces for each action type
166
- Object.entries(actionsByType).forEach(([actionType, typeActions]) => {
167
- const typeName = `${appName}${capitalize(actionType)}Actions`;
168
- output += `interface ${typeName} {\n`;
169
- typeActions.forEach((action) => {
170
- const actionName = sanitizeActionName(action.key);
171
- const description = action.description
172
- ? ` /** ${escapeComment(action.description)} */\n`
173
- : "";
174
- // Generate type-safe action method signature
175
- if (action.inputFields.length > 0) {
176
- const inputTypeName = `${appName}${capitalize(action.type)}${capitalize(sanitizeActionName(action.key))}Inputs`;
177
- output += `${description} ${actionName}: (options: { inputs: ${inputTypeName} } & Omit<ActionExecutionOptions, 'inputs'>) => Promise<ActionExecutionResult>\n`;
178
- }
179
- else {
180
- // No specific input fields available - use generic Record<string, any> for inputs
181
- output += `${description} ${actionName}: (options?: { inputs?: Record<string, any> } & ActionExecutionOptions) => Promise<ActionExecutionResult>\n`;
182
- }
183
- });
184
- output += `}\n\n`;
185
- });
186
- // Generate the main app SDK interface with factory pattern support
187
- // Generate the app proxy interface (actions grouped by type)
188
- output += `interface ${appName}AppProxy {\n`;
189
- Object.keys(actionsByType).forEach((actionType) => {
190
- const typeName = `${appName}${capitalize(actionType)}Actions`;
191
- output += ` ${actionType}: ${typeName}\n`;
192
- });
193
- output += `}\n\n`;
194
- // Generate the factory function interface
195
- output += `interface ${appName}AppFactory {\n`;
196
- output += ` (options: { authenticationId: number }): ${appName}AppProxy\n`;
197
- output += `}\n\n`;
198
- // Combine factory and direct access
199
- output += `type ${appName}AppWithFactory = ${appName}AppFactory & ${appName}AppProxy\n\n`;
200
- // Generate the main SDK interface
201
- output += `export interface ${appName}Sdk {\n`;
202
- output += ` apps: {\n`;
203
- output += ` ${appKey}: ${appName}AppWithFactory\n`;
204
- output += ` }\n`;
205
- output += `}\n`;
206
- return output;
207
- }
208
- function generateEmptyTypesFile(appKey, version) {
209
- const appName = capitalize(appKey);
210
- const versionComment = version
211
- ? ` * Generated for ${appKey}@${version}`
212
- : ` * Generated for ${appKey}`;
213
- return `/* eslint-disable @typescript-eslint/naming-convention */
214
- /**
215
- * Auto-generated TypeScript types for Zapier ${appKey} actions
216
- ${versionComment}
217
- * Generated on: ${new Date().toISOString()}
218
- *
219
- * No actions found for this app.
220
- */
221
-
222
- import type { ActionExecutionOptions, ActionExecutionResult } from '@zapier/zapier-sdk'
223
-
224
- interface ${appName}AppProxy {
225
- // No actions available
226
- }
227
-
228
- interface ${appName}AppFactory {
229
- (options: { authenticationId: number }): ${appName}AppProxy
230
- }
231
-
232
- type ${appName}AppWithFactory = ${appName}AppFactory & ${appName}AppProxy
233
-
234
- export interface ${appName}Sdk {
235
- apps: {
236
- ${appKey}: ${appName}AppWithFactory
237
- }
238
- }
239
- `;
240
- }
241
- function capitalize(str) {
242
- return str.charAt(0).toUpperCase() + str.slice(1).replace(/[-_]/g, "");
243
- }
244
- function sanitizeActionName(actionKey) {
245
- // Ensure the action name is a valid TypeScript identifier
246
- let sanitized = actionKey.replace(/[^a-zA-Z0-9_$]/g, "_");
247
- // If it starts with a number, prepend an underscore
248
- if (/^[0-9]/.test(sanitized)) {
249
- sanitized = "_" + sanitized;
250
- }
251
- return sanitized;
252
- }
253
- function sanitizeFieldName(fieldKey) {
254
- // Ensure the field name is a valid TypeScript identifier
255
- let sanitized = fieldKey.replace(/[^a-zA-Z0-9_$]/g, "_");
256
- // If it starts with a number, prepend an underscore
257
- if (/^[0-9]/.test(sanitized)) {
258
- sanitized = "_" + sanitized;
259
- }
260
- return sanitized;
261
- }
262
- function escapeComment(comment) {
263
- // Escape comment text to prevent breaking the JSDoc comment
264
- return comment.replace(/\*\//g, "*\\/").replace(/\r?\n/g, " ");
265
- }
266
- function mapFieldTypeToTypeScript(field) {
267
- // Handle choices (enum-like fields)
268
- if (field.choices && field.choices.length > 0) {
269
- const choiceValues = field.choices
270
- .filter((choice) => choice.value !== undefined &&
271
- choice.value !== null &&
272
- choice.value !== "")
273
- .map((choice) => typeof choice.value === "string" ? `"${choice.value}"` : choice.value);
274
- if (choiceValues.length > 0) {
275
- return choiceValues.join(" | ");
276
- }
277
- // If all choices were filtered out, fall through to default type handling
278
- }
279
- // Map Zapier field types to TypeScript types
280
- switch (field.type?.toLowerCase()) {
281
- case "string":
282
- case "text":
283
- case "email":
284
- case "url":
285
- case "password":
286
- return "string";
287
- case "integer":
288
- case "number":
289
- return "number";
290
- case "boolean":
291
- return "boolean";
292
- case "datetime":
293
- case "date":
294
- return "string"; // ISO date strings
295
- case "file":
296
- return "string"; // File URL or content
297
- case "array":
298
- return "any[]";
299
- case "object":
300
- return "Record<string, any>";
301
- default:
302
- // Default to string for unknown types, with union for common cases
303
- return "string | number | boolean";
304
- }
305
- }
@@ -1,21 +0,0 @@
1
- import { generateTypes } from "./index";
2
- export declare const generateTypesInfo: {
3
- name: string;
4
- inputSchema: import("zod").ZodObject<{
5
- appKey: import("zod").ZodString;
6
- authenticationId: import("zod").ZodOptional<import("zod").ZodNumber>;
7
- output: import("zod").ZodOptional<import("zod").ZodString>;
8
- debug: import("zod").ZodDefault<import("zod").ZodBoolean>;
9
- }, "strip", import("zod").ZodTypeAny, {
10
- debug: boolean;
11
- appKey: string;
12
- authenticationId?: number | undefined;
13
- output?: string | undefined;
14
- }, {
15
- appKey: string;
16
- debug?: boolean | undefined;
17
- authenticationId?: number | undefined;
18
- output?: string | undefined;
19
- }>;
20
- implementation: typeof generateTypes;
21
- };
@@ -1,11 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generateTypesInfo = 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.generateTypesInfo = {
8
- name: index_1.generateTypes.name,
9
- inputSchema: schemas_1.GenerateTypesSchema,
10
- implementation: index_1.generateTypes,
11
- };