@zapier/zapier-sdk 0.5.1 → 0.6.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 (137) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/README.md +107 -83
  3. package/dist/api/index.d.ts +1 -1
  4. package/dist/api/index.d.ts.map +1 -1
  5. package/dist/api/schemas.d.ts +6 -6
  6. package/dist/api/types.d.ts +7 -7
  7. package/dist/api/types.d.ts.map +1 -1
  8. package/dist/index.cjs +343 -67
  9. package/dist/index.d.mts +416 -347
  10. package/dist/index.d.ts.map +1 -1
  11. package/dist/index.js +0 -1
  12. package/dist/index.mjs +343 -67
  13. package/dist/plugins/api/index.js +1 -1
  14. package/dist/plugins/apps/types.d.ts +1 -1
  15. package/dist/plugins/apps/types.d.ts.map +1 -1
  16. package/dist/plugins/findFirstAuthentication/index.d.ts.map +1 -1
  17. package/dist/plugins/findFirstAuthentication/index.js +1 -0
  18. package/dist/plugins/findUniqueAuthentication/index.d.ts.map +1 -1
  19. package/dist/plugins/findUniqueAuthentication/index.js +1 -0
  20. package/dist/plugins/getAction/index.d.ts.map +1 -1
  21. package/dist/plugins/getAction/index.js +1 -0
  22. package/dist/plugins/getAction/index.test.js +1 -1
  23. package/dist/plugins/getApp/index.d.ts +6 -3
  24. package/dist/plugins/getApp/index.d.ts.map +1 -1
  25. package/dist/plugins/getApp/index.js +8 -18
  26. package/dist/plugins/getApp/index.test.js +2 -0
  27. package/dist/plugins/getAuthentication/index.d.ts.map +1 -1
  28. package/dist/plugins/getAuthentication/index.js +1 -0
  29. package/dist/plugins/getAuthentication/index.test.js +12 -1
  30. package/dist/plugins/getProfile/index.d.ts.map +1 -1
  31. package/dist/plugins/getProfile/index.js +1 -0
  32. package/dist/plugins/listActions/index.d.ts +5 -3
  33. package/dist/plugins/listActions/index.d.ts.map +1 -1
  34. package/dist/plugins/listActions/index.js +6 -6
  35. package/dist/plugins/listActions/index.test.js +26 -74
  36. package/dist/plugins/listActions/schemas.d.ts +4 -4
  37. package/dist/plugins/listApps/index.d.ts.map +1 -1
  38. package/dist/plugins/listApps/index.js +1 -0
  39. package/dist/plugins/listApps/schemas.d.ts +2 -2
  40. package/dist/plugins/listAuthentications/index.d.ts +4 -2
  41. package/dist/plugins/listAuthentications/index.d.ts.map +1 -1
  42. package/dist/plugins/listAuthentications/index.js +9 -12
  43. package/dist/plugins/listAuthentications/index.test.js +33 -40
  44. package/dist/plugins/listAuthentications/schemas.d.ts +4 -4
  45. package/dist/plugins/listInputFields/index.d.ts +3 -1
  46. package/dist/plugins/listInputFields/index.d.ts.map +1 -1
  47. package/dist/plugins/listInputFields/index.js +5 -5
  48. package/dist/plugins/listInputFields/index.test.js +10 -8
  49. package/dist/plugins/listInputFields/schemas.d.ts +4 -4
  50. package/dist/plugins/lockVersion/index.d.ts +24 -0
  51. package/dist/plugins/lockVersion/index.d.ts.map +1 -0
  52. package/dist/plugins/lockVersion/index.js +72 -0
  53. package/dist/plugins/lockVersion/index.test.d.ts +2 -0
  54. package/dist/plugins/lockVersion/index.test.d.ts.map +1 -0
  55. package/dist/plugins/lockVersion/index.test.js +129 -0
  56. package/dist/plugins/lockVersion/schemas.d.ts +10 -0
  57. package/dist/plugins/lockVersion/schemas.d.ts.map +1 -0
  58. package/dist/plugins/lockVersion/schemas.js +6 -0
  59. package/dist/plugins/manifest/index.d.ts +24 -0
  60. package/dist/plugins/manifest/index.d.ts.map +1 -0
  61. package/dist/plugins/manifest/index.js +119 -0
  62. package/dist/plugins/manifest/index.test.d.ts +2 -0
  63. package/dist/plugins/manifest/index.test.d.ts.map +1 -0
  64. package/dist/plugins/manifest/index.test.js +331 -0
  65. package/dist/plugins/manifest/schemas.d.ts +64 -0
  66. package/dist/plugins/manifest/schemas.d.ts.map +1 -0
  67. package/dist/plugins/manifest/schemas.js +25 -0
  68. package/dist/plugins/registry/index.d.ts +9 -1
  69. package/dist/plugins/registry/index.d.ts.map +1 -1
  70. package/dist/plugins/registry/index.js +68 -3
  71. package/dist/plugins/request/index.d.ts.map +1 -1
  72. package/dist/plugins/request/index.js +1 -0
  73. package/dist/plugins/request/index.test.js +6 -1
  74. package/dist/plugins/request/schemas.d.ts +4 -4
  75. package/dist/plugins/runAction/index.d.ts +2 -0
  76. package/dist/plugins/runAction/index.d.ts.map +1 -1
  77. package/dist/plugins/runAction/index.js +5 -5
  78. package/dist/plugins/runAction/index.test.js +9 -8
  79. package/dist/plugins/runAction/schemas.d.ts +4 -4
  80. package/dist/schemas/Auth.d.ts +4 -4
  81. package/dist/schemas/Field.d.ts.map +1 -1
  82. package/dist/sdk.d.ts +3 -3
  83. package/dist/sdk.d.ts.map +1 -1
  84. package/dist/sdk.js +18 -7
  85. package/dist/sdk.test.js +1 -1
  86. package/dist/types/errors.d.ts +6 -6
  87. package/dist/types/errors.d.ts.map +1 -1
  88. package/dist/types/events.d.ts +1 -1
  89. package/dist/types/events.d.ts.map +1 -1
  90. package/dist/types/plugin.d.ts +10 -2
  91. package/dist/types/plugin.d.ts.map +1 -1
  92. package/dist/types/sdk.d.ts +13 -2
  93. package/dist/types/sdk.d.ts.map +1 -1
  94. package/dist/utils/validation.test.js +2 -1
  95. package/package.json +2 -2
  96. package/src/api/client.ts +3 -3
  97. package/src/api/index.ts +2 -0
  98. package/src/api/types.ts +15 -7
  99. package/src/index.ts +0 -2
  100. package/src/plugins/api/index.ts +1 -1
  101. package/src/plugins/apps/types.ts +1 -1
  102. package/src/plugins/findFirstAuthentication/index.ts +1 -0
  103. package/src/plugins/findUniqueAuthentication/index.ts +1 -0
  104. package/src/plugins/getAction/index.test.ts +1 -1
  105. package/src/plugins/getAction/index.ts +1 -0
  106. package/src/plugins/getApp/index.test.ts +2 -0
  107. package/src/plugins/getApp/index.ts +12 -24
  108. package/src/plugins/getAuthentication/index.test.ts +13 -3
  109. package/src/plugins/getAuthentication/index.ts +1 -0
  110. package/src/plugins/getProfile/index.ts +1 -0
  111. package/src/plugins/listActions/index.test.ts +30 -89
  112. package/src/plugins/listActions/index.ts +34 -27
  113. package/src/plugins/listApps/index.ts +1 -0
  114. package/src/plugins/listAuthentications/index.test.ts +38 -47
  115. package/src/plugins/listAuthentications/index.ts +21 -18
  116. package/src/plugins/listInputFields/index.test.ts +12 -9
  117. package/src/plugins/listInputFields/index.ts +10 -6
  118. package/src/plugins/lockVersion/index.test.ts +176 -0
  119. package/src/plugins/lockVersion/index.ts +112 -0
  120. package/src/plugins/lockVersion/schemas.ts +9 -0
  121. package/src/plugins/manifest/index.test.ts +439 -0
  122. package/src/plugins/manifest/index.ts +171 -0
  123. package/src/plugins/manifest/schemas.ts +53 -0
  124. package/src/plugins/registry/index.ts +89 -8
  125. package/src/plugins/request/index.test.ts +8 -4
  126. package/src/plugins/request/index.ts +1 -0
  127. package/src/plugins/runAction/index.test.ts +9 -8
  128. package/src/plugins/runAction/index.ts +18 -9
  129. package/src/schemas/Field.ts +5 -2
  130. package/src/sdk.test.ts +1 -1
  131. package/src/sdk.ts +22 -7
  132. package/src/types/errors.ts +9 -6
  133. package/src/types/events.ts +1 -1
  134. package/src/types/plugin.ts +14 -2
  135. package/src/types/sdk.ts +15 -1
  136. package/src/utils/validation.test.ts +2 -1
  137. package/tsconfig.tsbuildinfo +1 -1
@@ -10,6 +10,7 @@ import {
10
10
  import { ZapierConfigurationError, ZapierApiError } from "../../types/errors";
11
11
  import { createPaginatedFunction } from "../../utils/function-utils";
12
12
  import type { GetAppPluginProvides } from "../getApp";
13
+ import { GetVersionedImplementationId } from "../manifest/schemas";
13
14
 
14
15
  // Enums for input field transformation
15
16
  enum InputFieldType {
@@ -125,9 +126,12 @@ export interface ListInputFieldsPluginProvides {
125
126
 
126
127
  export const listInputFieldsPlugin: Plugin<
127
128
  GetSdkType<GetAppPluginProvides>, // requires getApp in SDK
128
- { api: ApiClient }, // requires api in context
129
+ {
130
+ api: ApiClient;
131
+ getVersionedImplementationId: GetVersionedImplementationId;
132
+ }, // requires api and getVersionedImplementationId in context
129
133
  ListInputFieldsPluginProvides
130
- > = ({ sdk, context }) => {
134
+ > = ({ context }) => {
131
135
  const listInputFields = createPaginatedFunction(
132
136
  async function listInputFieldsPage(
133
137
  options: ListInputFieldsOptions & { cursor?: string } & {
@@ -135,15 +139,14 @@ export const listInputFieldsPlugin: Plugin<
135
139
  },
136
140
  ): Promise<ListInputFieldsPage> {
137
141
  // Note: This function ignores pageSize and cursor since it's not actually paginated internally
138
- const { api } = context;
142
+ const { api, getVersionedImplementationId } = context;
139
143
 
140
144
  // Extract parameters
141
145
  const { appKey, actionKey, actionType, authenticationId, inputs } =
142
146
  options;
143
147
 
144
- // Use the getApp plugin
145
- const appData = await sdk.getApp({ appKey });
146
- const selectedApi = appData.data.current_implementation_id;
148
+ // Use the manifest plugin
149
+ const selectedApi = await getVersionedImplementationId(appKey);
147
150
 
148
151
  if (!selectedApi) {
149
152
  throw new ZapierConfigurationError(
@@ -196,6 +199,7 @@ export const listInputFieldsPlugin: Plugin<
196
199
  context: {
197
200
  meta: {
198
201
  listInputFields: {
202
+ categories: ["action"],
199
203
  inputSchema: ListInputFieldsSchema,
200
204
  },
201
205
  },
@@ -0,0 +1,176 @@
1
+ import { describe, it, expect, vi, beforeEach } from "vitest";
2
+ import { lockVersionPlugin } from "./index";
3
+ import { createSdk } from "../../sdk";
4
+
5
+ // Mock fs module
6
+ vi.mock("fs", () => ({
7
+ readFileSync: vi.fn(),
8
+ writeFileSync: vi.fn(),
9
+ existsSync: vi.fn(),
10
+ }));
11
+
12
+ // Mock path module
13
+ vi.mock("path", () => ({
14
+ resolve: vi.fn((path) => `/resolved/${path}`),
15
+ }));
16
+
17
+ import { readFileSync, writeFileSync, existsSync } from "fs";
18
+ import { resolve } from "path";
19
+ import { apiPlugin } from "../api";
20
+
21
+ const mockReadFileSync = vi.mocked(readFileSync);
22
+ const mockWriteFileSync = vi.mocked(writeFileSync);
23
+ const mockExistsSync = vi.mocked(existsSync);
24
+ const mockResolve = vi.mocked(resolve);
25
+
26
+ describe("lockVersion plugin", () => {
27
+ let mockSdk: any;
28
+
29
+ beforeEach(() => {
30
+ vi.clearAllMocks();
31
+
32
+ mockSdk = {
33
+ listApps: vi.fn().mockReturnValue({
34
+ items: vi.fn().mockReturnValue(
35
+ [
36
+ {
37
+ title: "Gmail",
38
+ key: "GmailCLIAPI",
39
+ current_implementation_id: "GmailCLIAPI@2.1.0",
40
+ description: "Email service",
41
+ },
42
+ ][Symbol.iterator](),
43
+ ),
44
+ }),
45
+ };
46
+ });
47
+
48
+ const listAppsPlugin = () => ({
49
+ listApps: mockSdk.listApps,
50
+ context: {
51
+ meta: {
52
+ listApps: {
53
+ inputSchema: {} as any,
54
+ },
55
+ },
56
+ },
57
+ });
58
+
59
+ function createTestSdk() {
60
+ return createSdk()
61
+ .addPlugin(apiPlugin)
62
+ .addPlugin(listAppsPlugin)
63
+ .addPlugin(lockVersionPlugin);
64
+ }
65
+
66
+ describe("version locking", () => {
67
+ it("should extract implementation name and version and write to file", async () => {
68
+ mockExistsSync.mockReturnValue(false);
69
+ mockResolve.mockReturnValue("/resolved/.zapierrc");
70
+
71
+ const sdk = createTestSdk();
72
+ const result = await sdk.lockVersion({ appKey: "gmail" });
73
+
74
+ expect((result.data as any).implementationName).toBe("GmailCLIAPI");
75
+ expect((result.data as any).version).toBe("2.1.0");
76
+ expect(result.data.current_implementation_id).toBe("GmailCLIAPI@2.1.0");
77
+ expect(result.configPath).toBe("/resolved/.zapierrc");
78
+
79
+ // Verify file was written
80
+ expect(mockWriteFileSync).toHaveBeenCalledWith(
81
+ "/resolved/.zapierrc",
82
+ JSON.stringify(
83
+ {
84
+ apps: {
85
+ gmail: {
86
+ implementationName: "GmailCLIAPI",
87
+ version: "2.1.0",
88
+ },
89
+ },
90
+ },
91
+ null,
92
+ 2,
93
+ ),
94
+ );
95
+ });
96
+
97
+ it("should update existing .zapierrc file", async () => {
98
+ const existingConfig = {
99
+ apps: {
100
+ slack: {
101
+ implementationName: "SlackCLIAPI",
102
+ version: "1.27.1",
103
+ },
104
+ },
105
+ };
106
+
107
+ mockExistsSync.mockReturnValue(true);
108
+ mockReadFileSync.mockReturnValue(JSON.stringify(existingConfig));
109
+ mockResolve.mockReturnValue("/resolved/.zapierrc");
110
+
111
+ const sdk = createTestSdk();
112
+ const result = await sdk.lockVersion({ appKey: "gmail" });
113
+
114
+ expect(mockReadFileSync).toHaveBeenCalledWith(
115
+ "/resolved/.zapierrc",
116
+ "utf8",
117
+ );
118
+ expect(result.configPath).toBe("/resolved/.zapierrc");
119
+
120
+ // Verify file was updated with both apps
121
+ expect(mockWriteFileSync).toHaveBeenCalledWith(
122
+ "/resolved/.zapierrc",
123
+ JSON.stringify(
124
+ {
125
+ apps: {
126
+ slack: {
127
+ implementationName: "SlackCLIAPI",
128
+ version: "1.27.1",
129
+ },
130
+ gmail: {
131
+ implementationName: "GmailCLIAPI",
132
+ version: "2.1.0",
133
+ },
134
+ },
135
+ },
136
+ null,
137
+ 2,
138
+ ),
139
+ );
140
+ });
141
+
142
+ it("should handle invalid implementation ID format", async () => {
143
+ mockSdk.listApps = vi.fn().mockReturnValue({
144
+ items: vi.fn().mockReturnValue(
145
+ [
146
+ {
147
+ title: "Invalid App",
148
+ key: "InvalidApp",
149
+ current_implementation_id: "InvalidFormat",
150
+ },
151
+ ][Symbol.iterator](),
152
+ ),
153
+ });
154
+
155
+ const sdk = createTestSdk();
156
+
157
+ await expect(sdk.lockVersion({ appKey: "invalid" })).rejects.toThrow(
158
+ "Invalid implementation ID format: InvalidFormat. Expected format: <implementationName>@<version>",
159
+ );
160
+ });
161
+
162
+ it("should use custom config path when provided", async () => {
163
+ mockExistsSync.mockReturnValue(false);
164
+ mockResolve.mockReturnValue("/resolved/custom-config.json");
165
+
166
+ const sdk = createTestSdk();
167
+ const result = await sdk.lockVersion({
168
+ appKey: "gmail",
169
+ configPath: "custom-config.json",
170
+ });
171
+
172
+ expect(mockResolve).toHaveBeenCalledWith("custom-config.json");
173
+ expect(result.configPath).toBe("/resolved/custom-config.json");
174
+ });
175
+ });
176
+ });
@@ -0,0 +1,112 @@
1
+ import type { Plugin, GetSdkType } from "../../types/plugin";
2
+ import { createFunction } from "../../utils/function-utils";
3
+ import { LockVersionSchema } from "./schemas";
4
+ import type { LockVersionOptions } from "./schemas";
5
+ import type { AppItem } from "../../types/domain";
6
+ import { readFileSync, writeFileSync, existsSync } from "fs";
7
+ import { resolve } from "path";
8
+ import { z } from "zod";
9
+ import { ListAppsPluginProvides } from "../listApps";
10
+
11
+ export interface LockVersionPluginProvides {
12
+ lockVersion: (
13
+ options: LockVersionOptions & { configPath?: string },
14
+ ) => Promise<{ data: AppItem; configPath: string }>;
15
+ context: {
16
+ meta: {
17
+ lockVersion: {
18
+ inputSchema: typeof LockVersionSchema;
19
+ };
20
+ };
21
+ };
22
+ }
23
+
24
+ export const lockVersionPlugin: Plugin<
25
+ GetSdkType<ListAppsPluginProvides>, // requires getApp in SDK
26
+ {}, // requires manifest context
27
+ LockVersionPluginProvides
28
+ > = ({ sdk }) => {
29
+ const lockVersion = createFunction(
30
+ async function lockVersion(
31
+ options: LockVersionOptions & { configPath?: string },
32
+ ) {
33
+ const { appKey, configPath = ".zapierrc" } = options;
34
+ const resolvedPath = resolve(configPath);
35
+
36
+ // Get the current app information
37
+ const appsIterator = sdk.listApps({ appKeys: [appKey] }).items();
38
+ const apps = [];
39
+ for await (const app of appsIterator) {
40
+ apps.push(app);
41
+ break; // Only need the first result
42
+ }
43
+ const app = apps[0];
44
+
45
+ // Extract implementation name and version from current_implementation_id
46
+ const currentImplementationId = app.current_implementation_id;
47
+ const [implementationName, version] = currentImplementationId.split("@");
48
+
49
+ if (!implementationName || !version) {
50
+ throw new Error(
51
+ `Invalid implementation ID format: ${currentImplementationId}. Expected format: <implementationName>@<version>`,
52
+ );
53
+ }
54
+
55
+ // Read existing config or create new one
56
+ let config: { apps: Record<string, any> } = { apps: {} };
57
+
58
+ if (existsSync(resolvedPath)) {
59
+ try {
60
+ const configContent = readFileSync(resolvedPath, "utf8");
61
+ config = JSON.parse(configContent);
62
+
63
+ // Ensure apps property exists
64
+ if (!config.apps) {
65
+ config.apps = {};
66
+ }
67
+ } catch (error) {
68
+ console.warn(
69
+ `⚠️ Failed to parse existing config file, creating new one: ${error}`,
70
+ );
71
+ config = { apps: {} };
72
+ }
73
+ }
74
+
75
+ // Update the apps section
76
+ config.apps[appKey] = {
77
+ implementationName,
78
+ version,
79
+ };
80
+
81
+ // Write the updated config
82
+ writeFileSync(resolvedPath, JSON.stringify(config, null, 2));
83
+
84
+ return {
85
+ data: {
86
+ ...app,
87
+ implementationName,
88
+ version,
89
+ },
90
+ configPath: resolvedPath,
91
+ };
92
+ },
93
+ LockVersionSchema.extend({
94
+ configPath: z
95
+ .string()
96
+ .optional()
97
+ .describe("Path to .zapierrc file (defaults to '.zapierrc')"),
98
+ }),
99
+ );
100
+
101
+ return {
102
+ lockVersion,
103
+ context: {
104
+ meta: {
105
+ lockVersion: {
106
+ categories: ["utility"],
107
+ inputSchema: LockVersionSchema,
108
+ },
109
+ },
110
+ },
111
+ };
112
+ };
@@ -0,0 +1,9 @@
1
+ import { z } from "zod";
2
+
3
+ export const LockVersionSchema = z.object({
4
+ appKey: z
5
+ .string()
6
+ .describe("The app key to lock version for (e.g., 'slack', 'gmail')"),
7
+ });
8
+
9
+ export type LockVersionOptions = z.infer<typeof LockVersionSchema>;