@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,209 +0,0 @@
1
- import { describe, it, expect, vi, beforeEach } from "vitest";
2
- import { ZapierValidationError } from "../../types/errors";
3
- import { findFirstAuthenticationPlugin } from "./index";
4
- import { createSdk } from "../../sdk";
5
- import type { AuthenticationItem } from "../../types/domain";
6
- import { ListAuthenticationsSchema } from "../listAuthentications/schemas";
7
-
8
- const mockAuthentications: AuthenticationItem[] = [
9
- {
10
- id: 123,
11
- title: "My Slack",
12
- date: "2021-01-01",
13
- account_id: 123,
14
- implementation_id: "api_123",
15
- is_expired: "false",
16
- expired_at: null,
17
- is_invite_only: false,
18
- is_private: false,
19
- shared_with_all: false,
20
- },
21
- {
22
- id: 456,
23
- title: "Slack Workspace 2",
24
- is_expired: "false",
25
- expired_at: null,
26
- date: "2021-01-01",
27
- account_id: 123,
28
- implementation_id: "api_123",
29
- is_invite_only: false,
30
- is_private: false,
31
- shared_with_all: false,
32
- },
33
- ];
34
-
35
- describe("findFirstAuthentication plugin", () => {
36
- let mockListAuthentications: any;
37
-
38
- beforeEach(() => {
39
- vi.clearAllMocks();
40
- mockListAuthentications = vi.fn().mockResolvedValue({
41
- data: mockAuthentications,
42
- });
43
- });
44
-
45
- function createTestSdk() {
46
- // Create a proper plugin chain: first add a mock listAuthentications plugin, then add findFirstAuthentication
47
- const mockListAuthenticationsPlugin = () => ({
48
- listAuthentications: mockListAuthentications,
49
- context: {
50
- meta: {
51
- listAuthentications: {
52
- inputSchema: ListAuthenticationsSchema,
53
- },
54
- },
55
- },
56
- });
57
-
58
- // Build SDK with proper plugin composition
59
- return createSdk()
60
- .addPlugin(mockListAuthenticationsPlugin)
61
- .addPlugin(findFirstAuthenticationPlugin);
62
- }
63
-
64
- describe("schema validation", () => {
65
- it("should pass validation with empty options", async () => {
66
- const sdk = createTestSdk();
67
- const result = await sdk.findFirstAuthentication({});
68
- expect(result.data).toBeDefined();
69
- });
70
-
71
- it("should pass validation with undefined options", async () => {
72
- const sdk = createTestSdk();
73
- const result = await sdk.findFirstAuthentication();
74
- expect(result.data).toBeDefined();
75
- });
76
-
77
- it("should throw validation error for invalid appKey type", async () => {
78
- const sdk = createTestSdk();
79
- await expect(
80
- sdk.findFirstAuthentication({
81
- appKey: 123 as any, // intentionally wrong type for testing
82
- }),
83
- ).rejects.toThrow(ZapierValidationError);
84
- });
85
-
86
- it("should throw validation error for invalid search type", async () => {
87
- const sdk = createTestSdk();
88
- await expect(
89
- sdk.findFirstAuthentication({
90
- search: 123 as any,
91
- }),
92
- ).rejects.toThrow(ZapierValidationError);
93
- });
94
-
95
- it("should throw validation error for invalid parameter types", async () => {
96
- const sdk = createTestSdk();
97
- await expect(
98
- sdk.findFirstAuthentication({
99
- title: 123 as any,
100
- accountId: 456 as any,
101
- owner: true as any,
102
- }),
103
- ).rejects.toThrow(ZapierValidationError);
104
- });
105
-
106
- it("should pass validation with all valid fields", async () => {
107
- const sdk = createTestSdk();
108
- const result = await sdk.findFirstAuthentication({
109
- appKey: "slack",
110
- search: "workspace",
111
- title: "My Slack Workspace",
112
- accountId: "acc_123",
113
- owner: "me",
114
- });
115
-
116
- expect(result.data).toBeDefined();
117
- });
118
- });
119
-
120
- describe("business logic", () => {
121
- it("should return first authentication when found", async () => {
122
- const mockAuth = mockAuthentications[0];
123
- mockListAuthentications.mockResolvedValue({
124
- data: [mockAuth],
125
- });
126
-
127
- const sdk = createTestSdk();
128
- const result = await sdk.findFirstAuthentication({
129
- appKey: "slack",
130
- });
131
-
132
- expect(result.data).toEqual(mockAuth);
133
- });
134
-
135
- it("should throw error when no authentications found", async () => {
136
- mockListAuthentications.mockResolvedValue({
137
- data: [],
138
- });
139
-
140
- const sdk = createTestSdk();
141
-
142
- await expect(
143
- sdk.findFirstAuthentication({
144
- appKey: "nonexistent",
145
- }),
146
- ).rejects.toThrow(
147
- "No authentication found matching the specified criteria",
148
- );
149
- });
150
-
151
- it("should return first authentication when multiple found", async () => {
152
- const mockAuth = mockAuthentications[0];
153
- mockListAuthentications.mockResolvedValue({
154
- data: [mockAuth, mockAuthentications[1]],
155
- });
156
-
157
- const sdk = createTestSdk();
158
- const result = await sdk.findFirstAuthentication({
159
- search: "Slack",
160
- });
161
-
162
- expect(result.data).toEqual(mockAuth);
163
- });
164
- });
165
-
166
- describe("options forwarding", () => {
167
- it("should forward all options to listAuthentications", async () => {
168
- const sdk = createTestSdk();
169
- const options = {
170
- appKey: "slack",
171
- search: "workspace",
172
- title: "My Slack Workspace",
173
- accountId: "acc_123",
174
- owner: "me",
175
- };
176
-
177
- await sdk.findFirstAuthentication(options);
178
-
179
- expect(mockListAuthentications).toHaveBeenCalledWith({
180
- ...options,
181
- maxItems: 1,
182
- });
183
- });
184
- });
185
-
186
- describe("limit enforcement", () => {
187
- it("should automatically set maxItems to 1", async () => {
188
- const sdk = createTestSdk();
189
- await sdk.findFirstAuthentication({
190
- appKey: "slack",
191
- });
192
-
193
- expect(mockListAuthentications).toHaveBeenCalledWith({
194
- appKey: "slack",
195
- maxItems: 1,
196
- });
197
- });
198
- });
199
-
200
- describe("context and metadata", () => {
201
- it("should provide context with meta information", () => {
202
- const sdk = createTestSdk();
203
- const context = sdk.getContext();
204
-
205
- expect(context.meta.findFirstAuthentication).toBeDefined();
206
- expect(context.meta.findFirstAuthentication.inputSchema).toBeDefined();
207
- });
208
- });
209
- });
@@ -1,68 +0,0 @@
1
- import type { Plugin, GetSdkType } from "../../types/plugin";
2
- import type { AuthenticationItem } from "../../types/domain";
3
- import {
4
- FindFirstAuthenticationSchema,
5
- type FindFirstAuthenticationOptions,
6
- } from "./schemas";
7
- import { createFunction } from "../../utils/function-utils";
8
- import type { ListAuthenticationsPluginProvides } from "../listAuthentications";
9
- import { AuthenticationItemSchema } from "../../schemas/Auth";
10
- import { ZapierResourceNotFoundError } from "../../types/errors";
11
-
12
- export interface FindFirstAuthenticationPluginProvides {
13
- findFirstAuthentication: (
14
- options?: FindFirstAuthenticationOptions,
15
- ) => Promise<{ data: AuthenticationItem }>;
16
- context: {
17
- meta: {
18
- findFirstAuthentication: {
19
- inputSchema: typeof FindFirstAuthenticationSchema;
20
- };
21
- };
22
- };
23
- }
24
-
25
- export const findFirstAuthenticationPlugin: Plugin<
26
- GetSdkType<ListAuthenticationsPluginProvides>, // requires listAuthentications in SDK
27
- {}, // no context requirements
28
- FindFirstAuthenticationPluginProvides
29
- > = ({ sdk }) => {
30
- const findFirstAuthentication = createFunction(
31
- async function findFirstAuthentication(
32
- options: FindFirstAuthenticationOptions = {},
33
- ) {
34
- // Use listAuthentications with maxItems 1 to get the first result
35
- const authsResponse = await sdk.listAuthentications({
36
- ...options,
37
- maxItems: 1,
38
- });
39
-
40
- if (authsResponse.data.length === 0) {
41
- throw new ZapierResourceNotFoundError(
42
- "No authentication found matching the specified criteria",
43
- { resourceType: "Authentication" },
44
- );
45
- }
46
-
47
- return {
48
- data: authsResponse.data[0],
49
- };
50
- },
51
- FindFirstAuthenticationSchema,
52
- );
53
-
54
- return {
55
- findFirstAuthentication,
56
- context: {
57
- meta: {
58
- findFirstAuthentication: {
59
- categories: ["authentication"],
60
- type: "item",
61
- itemType: "Authentication",
62
- inputSchema: FindFirstAuthenticationSchema,
63
- outputSchema: AuthenticationItemSchema,
64
- },
65
- },
66
- },
67
- };
68
- };
@@ -1,47 +0,0 @@
1
- import { z } from "zod";
2
- import { AppKeyPropertySchema } from "../../types/properties";
3
- import type { AuthenticationItem } from "../../types/domain";
4
- import type {
5
- ZapierAuthenticationError,
6
- ZapierApiError,
7
- ZapierValidationError,
8
- ZapierUnknownError,
9
- } from "../../types/errors";
10
-
11
- // Pure Zod schema - no resolver metadata!
12
- export const FindFirstAuthenticationSchema = z
13
- .object({
14
- appKey: AppKeyPropertySchema.optional().describe(
15
- "App key of authentication to find (e.g., 'SlackCLIAPI' or slug like 'github')",
16
- ),
17
- search: z
18
- .string()
19
- .optional()
20
- .describe("Search term to filter authentications by title"),
21
- title: z
22
- .string()
23
- .optional()
24
- .describe("Filter authentications by exact title match"),
25
- accountId: z.string().optional().describe("Filter by account ID"),
26
- owner: z.string().optional().describe("Filter by owner"),
27
- })
28
- .describe("Find the first authentication matching the criteria");
29
-
30
- // Type inferred from schema
31
- export type FindFirstAuthenticationOptions = z.infer<
32
- typeof FindFirstAuthenticationSchema
33
- >;
34
-
35
- // Error union for this function (inherits from listAuthenticationsSafe)
36
- export type FindFirstAuthenticationError =
37
- | ZapierAuthenticationError
38
- | ZapierApiError
39
- | ZapierValidationError
40
- | ZapierUnknownError;
41
-
42
- // SDK function interface
43
- export interface FindFirstAuthenticationSdkFunction {
44
- findFirstAuthentication: (
45
- options?: FindFirstAuthenticationOptions,
46
- ) => Promise<{ data: AuthenticationItem | null }>;
47
- }
@@ -1,197 +0,0 @@
1
- import { describe, it, expect, vi, beforeEach } from "vitest";
2
- import {
3
- ZapierValidationError,
4
- ZapierResourceNotFoundError,
5
- } from "../../types/errors";
6
- import { findUniqueAuthenticationPlugin } from "./index";
7
- import { createSdk } from "../../sdk";
8
- import type { AuthenticationItem } from "../../types/domain";
9
- import { ListAuthenticationsSchema } from "../listAuthentications/schemas";
10
-
11
- const mockAuthentication: AuthenticationItem = {
12
- id: 123,
13
- title: "My Slack",
14
- date: "2021-01-01",
15
- account_id: 123,
16
- implementation_id: "api_123",
17
- is_expired: "false",
18
- expired_at: null,
19
- is_invite_only: false,
20
- is_private: false,
21
- shared_with_all: false,
22
- };
23
-
24
- const mockAuthentications: AuthenticationItem[] = [
25
- mockAuthentication,
26
- {
27
- id: 456,
28
- title: "Slack Workspace 2",
29
- is_expired: "false",
30
- expired_at: null,
31
- date: "2021-01-01",
32
- account_id: 123,
33
- implementation_id: "api_123",
34
- is_invite_only: false,
35
- is_private: false,
36
- shared_with_all: false,
37
- },
38
- ];
39
-
40
- describe("findUniqueAuthentication plugin", () => {
41
- let mockListAuthentications: any;
42
-
43
- beforeEach(() => {
44
- vi.clearAllMocks();
45
- mockListAuthentications = vi.fn().mockResolvedValue({
46
- data: [mockAuthentication],
47
- });
48
- });
49
-
50
- function createTestSdk() {
51
- // Create a proper plugin chain: first add a mock listAuthentications plugin, then add findUniqueAuthentication
52
- const mockListAuthenticationsPlugin = () => ({
53
- listAuthentications: mockListAuthentications,
54
- context: {
55
- meta: {
56
- listAuthentications: {
57
- inputSchema: ListAuthenticationsSchema,
58
- },
59
- },
60
- },
61
- });
62
-
63
- // Build SDK with proper plugin composition
64
- return createSdk()
65
- .addPlugin(mockListAuthenticationsPlugin)
66
- .addPlugin(findUniqueAuthenticationPlugin);
67
- }
68
-
69
- describe("schema validation", () => {
70
- it("should pass validation with empty options", async () => {
71
- const sdk = createTestSdk();
72
- const result = await sdk.findUniqueAuthentication({});
73
- expect(result.data).toBeDefined();
74
- });
75
-
76
- it("should throw validation error for invalid appKey type", async () => {
77
- const sdk = createTestSdk();
78
- await expect(
79
- sdk.findUniqueAuthentication({
80
- appKey: 123 as any,
81
- }),
82
- ).rejects.toThrow(ZapierValidationError);
83
- });
84
-
85
- it("should throw validation error for invalid parameter types", async () => {
86
- const sdk = createTestSdk();
87
- await expect(
88
- sdk.findUniqueAuthentication({
89
- search: 123 as any,
90
- title: 456 as any,
91
- accountId: 789 as any,
92
- owner: false as any,
93
- }),
94
- ).rejects.toThrow(ZapierValidationError);
95
- });
96
-
97
- it("should pass validation with all valid fields", async () => {
98
- const sdk = createTestSdk();
99
- const result = await sdk.findUniqueAuthentication({
100
- appKey: "slack",
101
- search: "Workspace",
102
- title: "My Slack",
103
- accountId: "acc_123",
104
- owner: "me",
105
- });
106
-
107
- expect(result.data).toBeDefined();
108
- });
109
- });
110
-
111
- describe("business logic", () => {
112
- it("should return the first authentication when exactly one is found", async () => {
113
- mockListAuthentications.mockResolvedValue({
114
- data: [mockAuthentication],
115
- });
116
-
117
- const sdk = createTestSdk();
118
- const result = await sdk.findUniqueAuthentication({
119
- appKey: "slack",
120
- });
121
-
122
- expect(result.data).toEqual(mockAuthentication);
123
- });
124
-
125
- it("should throw ZapierResourceNotFoundError when no authentications found", async () => {
126
- mockListAuthentications.mockResolvedValue({
127
- data: [],
128
- });
129
-
130
- const sdk = createTestSdk();
131
- await expect(
132
- sdk.findUniqueAuthentication({
133
- appKey: "nonexistent",
134
- }),
135
- ).rejects.toThrow(ZapierResourceNotFoundError);
136
-
137
- await expect(
138
- sdk.findUniqueAuthentication({
139
- appKey: "nonexistent",
140
- }),
141
- ).rejects.toThrow(
142
- "No authentication found matching the specified criteria",
143
- );
144
- });
145
-
146
- it("should throw ZapierValidationError when multiple authentications found", async () => {
147
- mockListAuthentications.mockResolvedValue({
148
- data: mockAuthentications, // Two authentications
149
- });
150
-
151
- const sdk = createTestSdk();
152
- await expect(
153
- sdk.findUniqueAuthentication({
154
- search: "Workspace",
155
- }),
156
- ).rejects.toThrow(ZapierValidationError);
157
-
158
- await expect(
159
- sdk.findUniqueAuthentication({
160
- search: "Workspace",
161
- }),
162
- ).rejects.toThrow(
163
- "Multiple authentications found matching the specified criteria. Expected exactly one.",
164
- );
165
- });
166
- });
167
-
168
- describe("options forwarding", () => {
169
- it("should forward all options to listAuthentications with maxItems=2", async () => {
170
- const sdk = createTestSdk();
171
- const options = {
172
- appKey: "slack",
173
- search: "workspace",
174
- title: "My Slack Workspace",
175
- accountId: "acc_123",
176
- owner: "me",
177
- };
178
-
179
- await sdk.findUniqueAuthentication(options);
180
-
181
- expect(mockListAuthentications).toHaveBeenCalledWith({
182
- ...options,
183
- maxItems: 2,
184
- });
185
- });
186
- });
187
-
188
- describe("context and metadata", () => {
189
- it("should provide context with meta information", () => {
190
- const sdk = createTestSdk();
191
- const context = sdk.getContext();
192
-
193
- expect(context.meta.findUniqueAuthentication).toBeDefined();
194
- expect(context.meta.findUniqueAuthentication.inputSchema).toBeDefined();
195
- });
196
- });
197
- });
@@ -1,77 +0,0 @@
1
- import type { Plugin, GetSdkType } from "../../types/plugin";
2
- import type { AuthenticationItem } from "../../types/domain";
3
- import {
4
- FindUniqueAuthenticationSchema,
5
- type FindUniqueAuthenticationOptions,
6
- } from "./schemas";
7
- import {
8
- ZapierResourceNotFoundError,
9
- ZapierValidationError,
10
- } from "../../types/errors";
11
- import { createFunction } from "../../utils/function-utils";
12
- import type { ListAuthenticationsPluginProvides } from "../listAuthentications";
13
- import { AuthenticationItemSchema } from "../../schemas/Auth";
14
-
15
- export interface FindUniqueAuthenticationPluginProvides {
16
- findUniqueAuthentication: (
17
- options?: FindUniqueAuthenticationOptions,
18
- ) => Promise<{ data: AuthenticationItem }>;
19
- context: {
20
- meta: {
21
- findUniqueAuthentication: {
22
- inputSchema: typeof FindUniqueAuthenticationSchema;
23
- };
24
- };
25
- };
26
- }
27
-
28
- export const findUniqueAuthenticationPlugin: Plugin<
29
- GetSdkType<ListAuthenticationsPluginProvides>, // requires listAuthentications in SDK
30
- {}, // no context requirements
31
- FindUniqueAuthenticationPluginProvides
32
- > = ({ sdk }) => {
33
- const findUniqueAuthentication = createFunction(
34
- async function findUniqueAuthentication(
35
- options: FindUniqueAuthenticationOptions = {},
36
- ) {
37
- // Use listAuthentications with maxItems 2 to check for uniqueness
38
- const authsResponse = await sdk.listAuthentications({
39
- ...options,
40
- maxItems: 2, // Get up to 2 to check for uniqueness
41
- });
42
-
43
- if (authsResponse.data.length === 0) {
44
- throw new ZapierResourceNotFoundError(
45
- "No authentication found matching the specified criteria",
46
- { resourceType: "Authentication" },
47
- );
48
- }
49
-
50
- if (authsResponse.data.length > 1) {
51
- throw new ZapierValidationError(
52
- "Multiple authentications found matching the specified criteria. Expected exactly one.",
53
- );
54
- }
55
-
56
- return {
57
- data: authsResponse.data[0],
58
- };
59
- },
60
- FindUniqueAuthenticationSchema,
61
- );
62
-
63
- return {
64
- findUniqueAuthentication,
65
- context: {
66
- meta: {
67
- findUniqueAuthentication: {
68
- categories: ["authentication"],
69
- type: "item",
70
- itemType: "Authentication",
71
- inputSchema: FindUniqueAuthenticationSchema,
72
- outputSchema: AuthenticationItemSchema,
73
- },
74
- },
75
- },
76
- };
77
- };
@@ -1,49 +0,0 @@
1
- import { z } from "zod";
2
- import { AppKeyPropertySchema } from "../../types/properties";
3
- import type { AuthenticationItem } from "../../types/domain";
4
- import type {
5
- ZapierAuthenticationError,
6
- ZapierApiError,
7
- ZapierResourceNotFoundError,
8
- ZapierValidationError,
9
- ZapierUnknownError,
10
- } from "../../types/errors";
11
-
12
- // Pure Zod schema - no resolver metadata!
13
- export const FindUniqueAuthenticationSchema = z
14
- .object({
15
- appKey: AppKeyPropertySchema.optional().describe(
16
- "App key of authentication to find (e.g., 'SlackCLIAPI' or slug like 'github')",
17
- ),
18
- search: z
19
- .string()
20
- .optional()
21
- .describe("Search term to filter authentications by title"),
22
- title: z
23
- .string()
24
- .optional()
25
- .describe("Filter authentications by exact title match"),
26
- accountId: z.string().optional().describe("Filter by account ID"),
27
- owner: z.string().optional().describe("Filter by owner"),
28
- })
29
- .describe("Find a unique authentication matching the criteria");
30
-
31
- // Type inferred from schema
32
- export type FindUniqueAuthenticationOptions = z.infer<
33
- typeof FindUniqueAuthenticationSchema
34
- >;
35
-
36
- // Error union for this function
37
- export type FindUniqueAuthenticationError =
38
- | ZapierAuthenticationError
39
- | ZapierApiError
40
- | ZapierResourceNotFoundError
41
- | ZapierValidationError
42
- | ZapierUnknownError;
43
-
44
- // SDK function interface
45
- export interface FindUniqueAuthenticationSdkFunction {
46
- findUniqueAuthentication: (
47
- options?: FindUniqueAuthenticationOptions,
48
- ) => Promise<{ data: AuthenticationItem }>;
49
- }