@zapier/zapier-sdk 0.13.6 → 0.13.8

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 (155) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/api/client.d.ts.map +1 -1
  3. package/dist/api/client.js +5 -5
  4. package/dist/api/client.test.d.ts +2 -0
  5. package/dist/api/client.test.d.ts.map +1 -0
  6. package/dist/api/client.test.js +80 -0
  7. package/dist/api/index.d.ts +1 -0
  8. package/dist/api/index.d.ts.map +1 -1
  9. package/dist/api/index.js +3 -1
  10. package/dist/api/schemas.d.ts +20 -20
  11. package/dist/api/types.d.ts +2 -0
  12. package/dist/api/types.d.ts.map +1 -1
  13. package/dist/auth.d.ts +3 -0
  14. package/dist/auth.d.ts.map +1 -1
  15. package/dist/auth.test.d.ts +2 -0
  16. package/dist/auth.test.d.ts.map +1 -0
  17. package/dist/auth.test.js +102 -0
  18. package/dist/constants.d.ts +4 -4
  19. package/dist/constants.d.ts.map +1 -1
  20. package/dist/constants.js +4 -4
  21. package/dist/index.cjs +89 -21
  22. package/dist/index.d.mts +21 -1
  23. package/dist/index.d.ts +1 -0
  24. package/dist/index.d.ts.map +1 -1
  25. package/dist/index.js +2 -0
  26. package/dist/index.mjs +88 -22
  27. package/dist/plugins/api/index.d.ts.map +1 -1
  28. package/dist/plugins/api/index.js +4 -1
  29. package/dist/plugins/eventEmission/index.d.ts +2 -0
  30. package/dist/plugins/eventEmission/index.d.ts.map +1 -1
  31. package/dist/plugins/eventEmission/index.js +35 -9
  32. package/dist/plugins/eventEmission/index.test.js +100 -0
  33. package/dist/schemas/Action.d.ts +2 -2
  34. package/dist/schemas/Auth.d.ts +4 -4
  35. package/dist/schemas/Field.d.ts +10 -10
  36. package/dist/sdk.test.js +121 -1
  37. package/dist/types/sdk.d.ts +3 -0
  38. package/dist/types/sdk.d.ts.map +1 -1
  39. package/dist/utils/url-utils.d.ts +19 -0
  40. package/dist/utils/url-utils.d.ts.map +1 -0
  41. package/dist/utils/url-utils.js +62 -0
  42. package/dist/utils/url-utils.test.d.ts +2 -0
  43. package/dist/utils/url-utils.test.d.ts.map +1 -0
  44. package/dist/utils/url-utils.test.js +103 -0
  45. package/package.json +8 -3
  46. package/src/api/auth.ts +0 -28
  47. package/src/api/client.ts +0 -491
  48. package/src/api/debug.test.ts +0 -76
  49. package/src/api/debug.ts +0 -154
  50. package/src/api/index.ts +0 -90
  51. package/src/api/polling.test.ts +0 -405
  52. package/src/api/polling.ts +0 -253
  53. package/src/api/schemas.ts +0 -465
  54. package/src/api/types.ts +0 -152
  55. package/src/auth.ts +0 -72
  56. package/src/constants.ts +0 -16
  57. package/src/index.ts +0 -111
  58. package/src/plugins/api/index.ts +0 -43
  59. package/src/plugins/apps/index.ts +0 -203
  60. package/src/plugins/apps/schemas.ts +0 -64
  61. package/src/plugins/eventEmission/builders.ts +0 -115
  62. package/src/plugins/eventEmission/index.test.ts +0 -169
  63. package/src/plugins/eventEmission/index.ts +0 -294
  64. package/src/plugins/eventEmission/transport.test.ts +0 -214
  65. package/src/plugins/eventEmission/transport.ts +0 -135
  66. package/src/plugins/eventEmission/types.ts +0 -58
  67. package/src/plugins/eventEmission/utils.ts +0 -121
  68. package/src/plugins/fetch/index.ts +0 -83
  69. package/src/plugins/fetch/schemas.ts +0 -37
  70. package/src/plugins/findFirstAuthentication/index.test.ts +0 -209
  71. package/src/plugins/findFirstAuthentication/index.ts +0 -68
  72. package/src/plugins/findFirstAuthentication/schemas.ts +0 -47
  73. package/src/plugins/findUniqueAuthentication/index.test.ts +0 -197
  74. package/src/plugins/findUniqueAuthentication/index.ts +0 -77
  75. package/src/plugins/findUniqueAuthentication/schemas.ts +0 -49
  76. package/src/plugins/getAction/index.test.ts +0 -239
  77. package/src/plugins/getAction/index.ts +0 -75
  78. package/src/plugins/getAction/schemas.ts +0 -41
  79. package/src/plugins/getApp/index.test.ts +0 -181
  80. package/src/plugins/getApp/index.ts +0 -60
  81. package/src/plugins/getApp/schemas.ts +0 -33
  82. package/src/plugins/getAuthentication/index.test.ts +0 -294
  83. package/src/plugins/getAuthentication/index.ts +0 -95
  84. package/src/plugins/getAuthentication/schemas.ts +0 -38
  85. package/src/plugins/getProfile/index.ts +0 -60
  86. package/src/plugins/getProfile/schemas.ts +0 -24
  87. package/src/plugins/listActions/index.test.ts +0 -526
  88. package/src/plugins/listActions/index.ts +0 -132
  89. package/src/plugins/listActions/schemas.ts +0 -55
  90. package/src/plugins/listApps/index.test.ts +0 -378
  91. package/src/plugins/listApps/index.ts +0 -159
  92. package/src/plugins/listApps/schemas.ts +0 -41
  93. package/src/plugins/listAuthentications/index.test.ts +0 -739
  94. package/src/plugins/listAuthentications/index.ts +0 -152
  95. package/src/plugins/listAuthentications/schemas.ts +0 -77
  96. package/src/plugins/listInputFieldChoices/index.test.ts +0 -653
  97. package/src/plugins/listInputFieldChoices/index.ts +0 -173
  98. package/src/plugins/listInputFieldChoices/schemas.ts +0 -125
  99. package/src/plugins/listInputFields/index.test.ts +0 -439
  100. package/src/plugins/listInputFields/index.ts +0 -294
  101. package/src/plugins/listInputFields/schemas.ts +0 -68
  102. package/src/plugins/manifest/index.test.ts +0 -776
  103. package/src/plugins/manifest/index.ts +0 -461
  104. package/src/plugins/manifest/schemas.ts +0 -60
  105. package/src/plugins/registry/index.ts +0 -160
  106. package/src/plugins/request/index.test.ts +0 -333
  107. package/src/plugins/request/index.ts +0 -105
  108. package/src/plugins/request/schemas.ts +0 -69
  109. package/src/plugins/runAction/index.test.ts +0 -388
  110. package/src/plugins/runAction/index.ts +0 -215
  111. package/src/plugins/runAction/schemas.ts +0 -60
  112. package/src/resolvers/actionKey.ts +0 -37
  113. package/src/resolvers/actionType.ts +0 -34
  114. package/src/resolvers/appKey.ts +0 -7
  115. package/src/resolvers/authenticationId.ts +0 -54
  116. package/src/resolvers/index.ts +0 -11
  117. package/src/resolvers/inputFieldKey.ts +0 -70
  118. package/src/resolvers/inputs.ts +0 -69
  119. package/src/schemas/Action.ts +0 -52
  120. package/src/schemas/App.ts +0 -45
  121. package/src/schemas/Auth.ts +0 -59
  122. package/src/schemas/Field.ts +0 -169
  123. package/src/schemas/Run.ts +0 -40
  124. package/src/schemas/UserProfile.ts +0 -60
  125. package/src/sdk.test.ts +0 -212
  126. package/src/sdk.ts +0 -178
  127. package/src/types/domain.test.ts +0 -50
  128. package/src/types/domain.ts +0 -66
  129. package/src/types/errors.ts +0 -278
  130. package/src/types/events.ts +0 -43
  131. package/src/types/functions.ts +0 -28
  132. package/src/types/optional-zapier-sdk-cli-login.d.ts +0 -37
  133. package/src/types/plugin.ts +0 -125
  134. package/src/types/properties.ts +0 -80
  135. package/src/types/sdk.ts +0 -111
  136. package/src/types/telemetry-events.ts +0 -85
  137. package/src/utils/array-utils.test.ts +0 -131
  138. package/src/utils/array-utils.ts +0 -41
  139. package/src/utils/domain-utils.test.ts +0 -433
  140. package/src/utils/domain-utils.ts +0 -267
  141. package/src/utils/file-utils.test.ts +0 -73
  142. package/src/utils/file-utils.ts +0 -94
  143. package/src/utils/function-utils.test.ts +0 -141
  144. package/src/utils/function-utils.ts +0 -245
  145. package/src/utils/pagination-utils.test.ts +0 -620
  146. package/src/utils/pagination-utils.ts +0 -242
  147. package/src/utils/schema-utils.ts +0 -207
  148. package/src/utils/string-utils.test.ts +0 -45
  149. package/src/utils/string-utils.ts +0 -54
  150. package/src/utils/validation.test.ts +0 -51
  151. package/src/utils/validation.ts +0 -44
  152. package/tsconfig.build.json +0 -18
  153. package/tsconfig.json +0 -20
  154. package/tsconfig.tsbuildinfo +0 -1
  155. package/tsup.config.ts +0 -23
@@ -1,239 +0,0 @@
1
- import { describe, it, expect, vi, beforeEach } from "vitest";
2
- import {
3
- ZapierValidationError,
4
- ZapierResourceNotFoundError,
5
- } from "../../types/errors";
6
- import { getActionPlugin } from "./index";
7
- import { createSdk } from "../../sdk";
8
- import type { GetActionOptions } from "./schemas";
9
- import type { ActionItem } from "../../types/domain";
10
- import type { ApiClient } from "../../api";
11
- import { ListActionsSchema } from "../listActions/schemas";
12
-
13
- const mockActions: ActionItem[] = [
14
- {
15
- type: "action",
16
- key: "user_by_email",
17
- title: "Search User by Email",
18
- description: "Find a user by email address",
19
- app_key: "slack",
20
- action_type: "search",
21
- },
22
- {
23
- type: "action",
24
- key: "search_messages",
25
- title: "Search Messages",
26
- description: "Search for messages in channels",
27
- app_key: "slack",
28
- action_type: "search",
29
- },
30
- {
31
- type: "action",
32
- key: "user_by_email",
33
- title: "Search User by Email",
34
- description: "Find a user by email address",
35
- app_key: "slack",
36
- action_type: "write", // Different action type for testing mismatch
37
- },
38
- ];
39
-
40
- describe("getAction plugin", () => {
41
- let mockListActions: any;
42
- let mockApiClient: ApiClient;
43
-
44
- beforeEach(() => {
45
- vi.clearAllMocks();
46
- mockListActions = vi.fn().mockResolvedValue({
47
- data: mockActions,
48
- });
49
- mockApiClient = {} as ApiClient;
50
- });
51
-
52
- function createTestSdk() {
53
- // Create a proper plugin chain with context dependencies
54
- const mockListActionsPlugin = () => ({
55
- listActions: mockListActions,
56
- context: {
57
- meta: {
58
- listActions: {
59
- inputSchema: ListActionsSchema,
60
- },
61
- },
62
- },
63
- });
64
-
65
- // Build SDK with proper plugin composition, providing API in initial context
66
- return createSdk({}, {}, { api: mockApiClient, meta: {} })
67
- .addPlugin(mockListActionsPlugin)
68
- .addPlugin(getActionPlugin);
69
- }
70
-
71
- describe("schema validation", () => {
72
- it("should throw validation error for missing appKey", async () => {
73
- const sdk = createTestSdk();
74
- await expect(
75
- sdk.getAction({
76
- actionType: "search",
77
- actionKey: "user_by_email",
78
- } as Partial<GetActionOptions> as GetActionOptions),
79
- ).rejects.toThrow(ZapierValidationError);
80
- });
81
-
82
- it("should throw validation error for missing actionType", async () => {
83
- const sdk = createTestSdk();
84
- await expect(
85
- sdk.getAction({
86
- appKey: "slack",
87
- actionKey: "user_by_email",
88
- } as Partial<GetActionOptions> as GetActionOptions),
89
- ).rejects.toThrow(ZapierValidationError);
90
- });
91
-
92
- it("should throw validation error for missing actionKey", async () => {
93
- const sdk = createTestSdk();
94
- await expect(
95
- sdk.getAction({
96
- appKey: "slack",
97
- actionType: "search",
98
- } as Partial<GetActionOptions> as GetActionOptions),
99
- ).rejects.toThrow(ZapierValidationError);
100
- });
101
-
102
- it("should throw validation error for invalid appKey type", async () => {
103
- const sdk = createTestSdk();
104
- await expect(
105
- sdk.getAction({
106
- appKey: 123 as any,
107
- actionType: "search",
108
- actionKey: "user_by_email",
109
- } as any),
110
- ).rejects.toThrow(ZapierValidationError);
111
- });
112
-
113
- it("should throw validation error for invalid actionType", async () => {
114
- const sdk = createTestSdk();
115
- await expect(
116
- sdk.getAction({
117
- appKey: "slack",
118
- actionType: "invalid-type" as any,
119
- actionKey: "user_by_email",
120
- } as any),
121
- ).rejects.toThrow(ZapierValidationError);
122
- });
123
-
124
- it("should throw validation error for invalid actionKey type", async () => {
125
- const sdk = createTestSdk();
126
- await expect(
127
- sdk.getAction({
128
- appKey: "slack",
129
- actionType: "search",
130
- actionKey: 123,
131
- } as any),
132
- ).rejects.toThrow(ZapierValidationError);
133
- });
134
-
135
- it("should throw validation error for empty appKey", async () => {
136
- const sdk = createTestSdk();
137
- await expect(
138
- sdk.getAction({
139
- appKey: "",
140
- actionType: "search",
141
- actionKey: "user_by_email",
142
- }),
143
- ).rejects.toThrow(ZapierValidationError);
144
- });
145
-
146
- it("should throw validation error for empty actionKey", async () => {
147
- const sdk = createTestSdk();
148
- await expect(
149
- sdk.getAction({
150
- appKey: "slack",
151
- actionType: "search",
152
- actionKey: "",
153
- }),
154
- ).rejects.toThrow(ZapierValidationError);
155
- });
156
-
157
- it("should pass validation with all required fields", async () => {
158
- const sdk = createTestSdk();
159
- const result = await sdk.getAction({
160
- appKey: "slack",
161
- actionType: "search",
162
- actionKey: "user_by_email",
163
- });
164
-
165
- expect(result.data).toEqual(mockActions[0]);
166
- });
167
- });
168
-
169
- describe("action lookup", () => {
170
- it("should call listActions with correct parameters", async () => {
171
- const sdk = createTestSdk();
172
- await sdk.getAction({
173
- appKey: "slack",
174
- actionType: "search",
175
- actionKey: "user_by_email",
176
- });
177
-
178
- expect(mockListActions).toHaveBeenCalledWith({
179
- appKey: "slack",
180
- });
181
- });
182
-
183
- it("should return the correct action when found", async () => {
184
- const sdk = createTestSdk();
185
- const result = await sdk.getAction({
186
- appKey: "slack",
187
- actionType: "search",
188
- actionKey: "user_by_email",
189
- });
190
-
191
- expect(result.data).toEqual(mockActions[0]);
192
- });
193
-
194
- it("should throw error when action key not found", async () => {
195
- const sdk = createTestSdk();
196
- await expect(
197
- sdk.getAction({
198
- appKey: "slack",
199
- actionType: "search",
200
- actionKey: "nonexistent_action",
201
- }),
202
- ).rejects.toThrow(ZapierResourceNotFoundError);
203
- });
204
-
205
- it("should throw error when action type doesn't match", async () => {
206
- const sdk = createTestSdk();
207
- await expect(
208
- sdk.getAction({
209
- appKey: "slack",
210
- actionType: "write",
211
- actionKey: "search_messages", // This action is type "search" in mock
212
- }),
213
- ).rejects.toThrow(ZapierResourceNotFoundError);
214
- });
215
-
216
- it("should handle listActions errors", async () => {
217
- mockListActions.mockRejectedValue(new Error("API Error"));
218
-
219
- const sdk = createTestSdk();
220
- await expect(
221
- sdk.getAction({
222
- appKey: "slack",
223
- actionType: "search",
224
- actionKey: "user_by_email",
225
- }),
226
- ).rejects.toThrow("API Error");
227
- });
228
- });
229
-
230
- describe("plugin integration", () => {
231
- it("should provide metadata in context", () => {
232
- const sdk = createTestSdk();
233
- const context = sdk.getContext();
234
-
235
- expect(context.meta.getAction).toBeDefined();
236
- expect(context.meta.getAction.inputSchema).toBeDefined();
237
- });
238
- });
239
- });
@@ -1,75 +0,0 @@
1
- import type { Plugin, GetSdkType } from "../../types/plugin";
2
- import type { ApiClient } from "../../api";
3
- import type { ActionItem } from "../../types/domain";
4
- import { GetActionSchema, type GetActionOptions } from "./schemas";
5
- import { ZapierResourceNotFoundError } from "../../types/errors";
6
- import { createFunction } from "../../utils/function-utils";
7
- import type { ListActionsPluginProvides } from "../listActions";
8
- import {
9
- appKeyResolver,
10
- actionTypeResolver,
11
- actionKeyResolver,
12
- } from "../../resolvers";
13
- import { ActionItemSchema } from "../../schemas/Action";
14
-
15
- export interface GetActionPluginProvides {
16
- getAction: (options: GetActionOptions) => Promise<{ data: ActionItem }>;
17
- context: {
18
- meta: {
19
- getAction: {
20
- inputSchema: typeof GetActionSchema;
21
- };
22
- };
23
- };
24
- }
25
-
26
- export const getActionPlugin: Plugin<
27
- GetSdkType<ListActionsPluginProvides>, // requires listActions in SDK
28
- { api: ApiClient }, // requires api in context
29
- GetActionPluginProvides
30
- > = ({ sdk }) => {
31
- const getAction = createFunction(async function getAction(
32
- options: GetActionOptions,
33
- ) {
34
- const { actionKey, actionType, appKey } = options;
35
-
36
- // Use the listActions function from the SDK to search for the specific action
37
- const actionsResult = await sdk.listActions({ appKey });
38
-
39
- // Search through all actions to find the matching one (by key or ID)
40
- for (const action of actionsResult.data) {
41
- if (
42
- (action.key === actionKey || action.id === actionKey) &&
43
- action.action_type === actionType
44
- ) {
45
- return { data: action };
46
- }
47
- }
48
-
49
- // If we get here, action was not found
50
- throw new ZapierResourceNotFoundError(
51
- `Action not found: ${actionKey} with type ${actionType}`,
52
- { resourceType: "Action", resourceId: `${actionKey} (${actionType})` },
53
- );
54
- }, GetActionSchema);
55
-
56
- return {
57
- getAction,
58
- context: {
59
- meta: {
60
- getAction: {
61
- categories: ["action"],
62
- type: "item",
63
- itemType: "Action",
64
- inputSchema: GetActionSchema,
65
- outputSchema: ActionItemSchema,
66
- resolvers: {
67
- appKey: appKeyResolver,
68
- actionType: actionTypeResolver,
69
- actionKey: actionKeyResolver,
70
- },
71
- },
72
- },
73
- },
74
- };
75
- };
@@ -1,41 +0,0 @@
1
- import { z } from "zod";
2
- import {
3
- AppKeyPropertySchema,
4
- ActionTypePropertySchema,
5
- ActionKeyPropertySchema,
6
- } from "../../types/properties";
7
- import type { ActionItem } from "../../types/domain";
8
- import type {
9
- ZapierAuthenticationError,
10
- ZapierApiError,
11
- ZapierAppNotFoundError,
12
- ZapierValidationError,
13
- ZapierResourceNotFoundError,
14
- ZapierUnknownError,
15
- } from "../../types/errors";
16
-
17
- // Pure Zod schema - no resolver metadata!
18
- export const GetActionSchema = z
19
- .object({
20
- appKey: AppKeyPropertySchema,
21
- actionType: ActionTypePropertySchema,
22
- actionKey: ActionKeyPropertySchema,
23
- })
24
- .describe("Get detailed information about a specific action");
25
-
26
- // Type inferred from schema
27
- export type GetActionOptions = z.infer<typeof GetActionSchema>;
28
-
29
- // Error union for this function (inherits from listActionsSafe + resource not found)
30
- export type GetActionError =
31
- | ZapierAuthenticationError
32
- | ZapierApiError
33
- | ZapierAppNotFoundError
34
- | ZapierValidationError
35
- | ZapierResourceNotFoundError
36
- | ZapierUnknownError;
37
-
38
- // SDK function interface
39
- export interface GetActionSdkFunction {
40
- getAction: (options: GetActionOptions) => Promise<{ data: ActionItem }>;
41
- }
@@ -1,181 +0,0 @@
1
- import { describe, it, expect, vi, beforeEach } from "vitest";
2
- import {
3
- ZapierValidationError,
4
- ZapierAppNotFoundError,
5
- } from "../../types/errors";
6
- import { getAppPlugin } from "./index";
7
- import { createSdk } from "../../sdk";
8
- import { apiPlugin } from "../api/index";
9
- import { listAppsPlugin } from "../listApps";
10
- import { manifestPlugin } from "../manifest";
11
-
12
- function createTestSdk() {
13
- return createSdk()
14
- .addPlugin(apiPlugin, { fetch: global.fetch })
15
- .addPlugin(manifestPlugin)
16
- .addPlugin(listAppsPlugin)
17
- .addPlugin(getAppPlugin);
18
- }
19
-
20
- describe("getApp plugin", () => {
21
- beforeEach(() => {
22
- vi.clearAllMocks();
23
- });
24
-
25
- describe("schema validation", () => {
26
- it("should throw validation error for missing appKey", async () => {
27
- const sdk = createTestSdk();
28
- await expect(sdk.getApp({} as any)).rejects.toThrow(
29
- ZapierValidationError,
30
- );
31
- });
32
-
33
- it("should throw validation error for invalid appKey type", async () => {
34
- const sdk = createTestSdk();
35
- await expect(
36
- sdk.getApp({
37
- appKey: 123 as any,
38
- } as any),
39
- ).rejects.toThrow(ZapierValidationError);
40
- });
41
-
42
- it("should throw validation error for empty string appKey", async () => {
43
- const sdk = createTestSdk();
44
- await expect(
45
- sdk.getApp({
46
- appKey: "",
47
- }),
48
- ).rejects.toThrow(ZapierValidationError);
49
- });
50
-
51
- it("should pass validation with valid appKey", async () => {
52
- const sdk = createTestSdk();
53
- const context = sdk.getContext();
54
-
55
- // Mock the API client to handle both resolveAppKeys and listApps calls
56
- (context.api as any).get = vi
57
- .fn()
58
- // First call: resolveAppKeys may call to resolve slug to implementation name
59
- .mockResolvedValueOnce({
60
- results: [
61
- {
62
- id: "SlackCLIAPI@1.0.0",
63
- name: "Slack",
64
- description: "Team communication",
65
- primary_color: "#4A154B",
66
- categories: ["communication"],
67
- slug: "slack",
68
- key: "SlackCLIAPI",
69
- version: "1.0.0",
70
- },
71
- ],
72
- next: null,
73
- })
74
- // Second call: listApps main API call
75
- .mockResolvedValueOnce({
76
- results: [
77
- {
78
- id: "SlackCLIAPI@1.0.0",
79
- name: "Slack",
80
- description: "Team communication",
81
- primary_color: "#4A154B",
82
- categories: ["communication"],
83
- slug: "slack",
84
- key: "SlackCLIAPI",
85
- version: "1.0.0",
86
- },
87
- ],
88
- next: null,
89
- });
90
-
91
- const result = await sdk.getApp({
92
- appKey: "slack",
93
- });
94
-
95
- expect(result.data.title).toBe("Slack");
96
- expect(result.data.key).toBe("SlackCLIAPI");
97
- expect(result.data.implementation_id).toBe("SlackCLIAPI@1.0.0");
98
- expect(result.data.version).toBe("1.0.0");
99
- });
100
- });
101
-
102
- describe("error handling", () => {
103
- it("should throw ZapierAppNotFoundError when app does not exist", async () => {
104
- const sdk = createTestSdk();
105
- const context = sdk.getContext();
106
-
107
- // Mock API to return empty results for both potential calls
108
- (context.api as any).get = vi
109
- .fn()
110
- // First call: resolveAppKeys may call to resolve slug
111
- .mockResolvedValueOnce({
112
- results: [],
113
- next: null,
114
- })
115
- // Second call: listApps main API call
116
- .mockResolvedValueOnce({
117
- results: [],
118
- next: null,
119
- });
120
-
121
- await expect(
122
- sdk.getApp({
123
- appKey: "nonexistent-app",
124
- }),
125
- ).rejects.toThrow(ZapierAppNotFoundError);
126
- });
127
- });
128
-
129
- describe("data mapping", () => {
130
- it("should return essential app properties", async () => {
131
- const sdk = createTestSdk();
132
- const context = sdk.getContext();
133
-
134
- // Mock the API client to handle both resolveAppKeys and listApps calls
135
- (context.api as any).get = vi
136
- .fn()
137
- // First call: resolveAppKeys may call to resolve slug to implementation name
138
- .mockResolvedValueOnce({
139
- results: [
140
- {
141
- id: "TestCLIAPI@1.0.0",
142
- name: "Test App",
143
- description: "Test description",
144
- primary_color: "#FF0000",
145
- categories: ["testing"],
146
- slug: "test",
147
- key: "TestCLIAPI",
148
- version: "1.0.0",
149
- },
150
- ],
151
- next: null,
152
- })
153
- // Second call: listApps main API call
154
- .mockResolvedValueOnce({
155
- results: [
156
- {
157
- id: "TestCLIAPI@1.0.0",
158
- name: "Test App",
159
- description: "Test description",
160
- primary_color: "#FF0000",
161
- categories: ["testing"],
162
- slug: "test",
163
- key: "TestCLIAPI",
164
- version: "1.0.0",
165
- },
166
- ],
167
- next: null,
168
- });
169
-
170
- const result = await sdk.getApp({
171
- appKey: "test",
172
- });
173
-
174
- expect(result.data.title).toBeDefined();
175
- expect(result.data.key).toBeDefined();
176
- expect(result.data.implementation_id).toBeDefined();
177
- expect(result.data.title).toBe("Test App");
178
- expect(result.data.key).toBe("TestCLIAPI");
179
- });
180
- });
181
- });
@@ -1,60 +0,0 @@
1
- import type { Plugin } from "../../types/plugin";
2
- import { createFunction } from "../../utils/function-utils";
3
- import { GetAppSchema } from "./schemas";
4
- import type { GetAppOptions } from "./schemas";
5
- import type { AppItem } from "../../types/domain";
6
- import { AppItemSchema } from "../../schemas/App";
7
- import { ZapierAppNotFoundError } from "../../types/errors";
8
- import type { GetSdkType } from "../../types/plugin";
9
- import type { ListAppsPluginProvides } from "../listApps";
10
- import { appKeyResolver } from "../../resolvers";
11
-
12
- // GetApp plugin provides interface - getApp goes directly to SDK root
13
- export interface GetAppPluginProvides {
14
- getApp: (options: GetAppOptions) => Promise<{ data: AppItem }>;
15
- context: {
16
- meta: {
17
- getApp: {
18
- inputSchema: typeof GetAppSchema;
19
- };
20
- };
21
- };
22
- }
23
-
24
- // GetApp plugin depends on listApps SDK function
25
- export const getAppPlugin: Plugin<
26
- GetSdkType<ListAppsPluginProvides>,
27
- {},
28
- GetAppPluginProvides
29
- > = ({ sdk }) => {
30
- const getApp = createFunction(async function getApp(options: GetAppOptions) {
31
- const appsIterator = sdk.listApps({ appKeys: [options.appKey] }).items();
32
- for await (const app of appsIterator) {
33
- return {
34
- data: app,
35
- };
36
- }
37
- throw new ZapierAppNotFoundError("App not found", {
38
- appKey: options.appKey,
39
- });
40
- }, GetAppSchema);
41
-
42
- // Return flat structure - getApp goes directly to SDK
43
- return {
44
- getApp,
45
- context: {
46
- meta: {
47
- getApp: {
48
- categories: ["app"],
49
- type: "item",
50
- itemType: "App",
51
- inputSchema: GetAppSchema,
52
- outputSchema: AppItemSchema,
53
- resolvers: {
54
- appKey: appKeyResolver,
55
- },
56
- },
57
- },
58
- },
59
- };
60
- };
@@ -1,33 +0,0 @@
1
- import { z } from "zod";
2
- import { AppKeyPropertySchema } from "../../types/properties";
3
- import type { AppItem } from "../../types/domain";
4
- import type {
5
- ZapierApiError,
6
- ZapierAppNotFoundError,
7
- ZapierValidationError,
8
- } from "../../types/errors";
9
-
10
- // Error types (now imported from types/errors)
11
-
12
- // Union of all possible errors for getApp
13
- export type GetAppError =
14
- | ZapierAppNotFoundError
15
- | ZapierApiError
16
- | ZapierValidationError;
17
-
18
- // Pure Zod schema - no resolver metadata!
19
- export const GetAppSchema = z
20
- .object({
21
- appKey: AppKeyPropertySchema.describe(
22
- "App key of app to fetch (e.g., 'SlackCLIAPI' or slug like 'github')",
23
- ),
24
- })
25
- .describe("Get detailed information about a specific app");
26
-
27
- // Type inferred from schema
28
- export type GetAppOptions = z.infer<typeof GetAppSchema>;
29
-
30
- // SDK function interface - ready to be mixed into main SDK interface
31
- export interface GetAppSdkFunction {
32
- getApp: (options: GetAppOptions) => Promise<{ data: AppItem }>;
33
- }