@zapier/zapier-sdk 0.13.6 → 0.13.7

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 (114) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/index.cjs +1 -1
  3. package/dist/index.mjs +1 -1
  4. package/package.json +7 -2
  5. package/src/api/auth.ts +0 -28
  6. package/src/api/client.ts +0 -491
  7. package/src/api/debug.test.ts +0 -76
  8. package/src/api/debug.ts +0 -154
  9. package/src/api/index.ts +0 -90
  10. package/src/api/polling.test.ts +0 -405
  11. package/src/api/polling.ts +0 -253
  12. package/src/api/schemas.ts +0 -465
  13. package/src/api/types.ts +0 -152
  14. package/src/auth.ts +0 -72
  15. package/src/constants.ts +0 -16
  16. package/src/index.ts +0 -111
  17. package/src/plugins/api/index.ts +0 -43
  18. package/src/plugins/apps/index.ts +0 -203
  19. package/src/plugins/apps/schemas.ts +0 -64
  20. package/src/plugins/eventEmission/builders.ts +0 -115
  21. package/src/plugins/eventEmission/index.test.ts +0 -169
  22. package/src/plugins/eventEmission/index.ts +0 -294
  23. package/src/plugins/eventEmission/transport.test.ts +0 -214
  24. package/src/plugins/eventEmission/transport.ts +0 -135
  25. package/src/plugins/eventEmission/types.ts +0 -58
  26. package/src/plugins/eventEmission/utils.ts +0 -121
  27. package/src/plugins/fetch/index.ts +0 -83
  28. package/src/plugins/fetch/schemas.ts +0 -37
  29. package/src/plugins/findFirstAuthentication/index.test.ts +0 -209
  30. package/src/plugins/findFirstAuthentication/index.ts +0 -68
  31. package/src/plugins/findFirstAuthentication/schemas.ts +0 -47
  32. package/src/plugins/findUniqueAuthentication/index.test.ts +0 -197
  33. package/src/plugins/findUniqueAuthentication/index.ts +0 -77
  34. package/src/plugins/findUniqueAuthentication/schemas.ts +0 -49
  35. package/src/plugins/getAction/index.test.ts +0 -239
  36. package/src/plugins/getAction/index.ts +0 -75
  37. package/src/plugins/getAction/schemas.ts +0 -41
  38. package/src/plugins/getApp/index.test.ts +0 -181
  39. package/src/plugins/getApp/index.ts +0 -60
  40. package/src/plugins/getApp/schemas.ts +0 -33
  41. package/src/plugins/getAuthentication/index.test.ts +0 -294
  42. package/src/plugins/getAuthentication/index.ts +0 -95
  43. package/src/plugins/getAuthentication/schemas.ts +0 -38
  44. package/src/plugins/getProfile/index.ts +0 -60
  45. package/src/plugins/getProfile/schemas.ts +0 -24
  46. package/src/plugins/listActions/index.test.ts +0 -526
  47. package/src/plugins/listActions/index.ts +0 -132
  48. package/src/plugins/listActions/schemas.ts +0 -55
  49. package/src/plugins/listApps/index.test.ts +0 -378
  50. package/src/plugins/listApps/index.ts +0 -159
  51. package/src/plugins/listApps/schemas.ts +0 -41
  52. package/src/plugins/listAuthentications/index.test.ts +0 -739
  53. package/src/plugins/listAuthentications/index.ts +0 -152
  54. package/src/plugins/listAuthentications/schemas.ts +0 -77
  55. package/src/plugins/listInputFieldChoices/index.test.ts +0 -653
  56. package/src/plugins/listInputFieldChoices/index.ts +0 -173
  57. package/src/plugins/listInputFieldChoices/schemas.ts +0 -125
  58. package/src/plugins/listInputFields/index.test.ts +0 -439
  59. package/src/plugins/listInputFields/index.ts +0 -294
  60. package/src/plugins/listInputFields/schemas.ts +0 -68
  61. package/src/plugins/manifest/index.test.ts +0 -776
  62. package/src/plugins/manifest/index.ts +0 -461
  63. package/src/plugins/manifest/schemas.ts +0 -60
  64. package/src/plugins/registry/index.ts +0 -160
  65. package/src/plugins/request/index.test.ts +0 -333
  66. package/src/plugins/request/index.ts +0 -105
  67. package/src/plugins/request/schemas.ts +0 -69
  68. package/src/plugins/runAction/index.test.ts +0 -388
  69. package/src/plugins/runAction/index.ts +0 -215
  70. package/src/plugins/runAction/schemas.ts +0 -60
  71. package/src/resolvers/actionKey.ts +0 -37
  72. package/src/resolvers/actionType.ts +0 -34
  73. package/src/resolvers/appKey.ts +0 -7
  74. package/src/resolvers/authenticationId.ts +0 -54
  75. package/src/resolvers/index.ts +0 -11
  76. package/src/resolvers/inputFieldKey.ts +0 -70
  77. package/src/resolvers/inputs.ts +0 -69
  78. package/src/schemas/Action.ts +0 -52
  79. package/src/schemas/App.ts +0 -45
  80. package/src/schemas/Auth.ts +0 -59
  81. package/src/schemas/Field.ts +0 -169
  82. package/src/schemas/Run.ts +0 -40
  83. package/src/schemas/UserProfile.ts +0 -60
  84. package/src/sdk.test.ts +0 -212
  85. package/src/sdk.ts +0 -178
  86. package/src/types/domain.test.ts +0 -50
  87. package/src/types/domain.ts +0 -66
  88. package/src/types/errors.ts +0 -278
  89. package/src/types/events.ts +0 -43
  90. package/src/types/functions.ts +0 -28
  91. package/src/types/optional-zapier-sdk-cli-login.d.ts +0 -37
  92. package/src/types/plugin.ts +0 -125
  93. package/src/types/properties.ts +0 -80
  94. package/src/types/sdk.ts +0 -111
  95. package/src/types/telemetry-events.ts +0 -85
  96. package/src/utils/array-utils.test.ts +0 -131
  97. package/src/utils/array-utils.ts +0 -41
  98. package/src/utils/domain-utils.test.ts +0 -433
  99. package/src/utils/domain-utils.ts +0 -267
  100. package/src/utils/file-utils.test.ts +0 -73
  101. package/src/utils/file-utils.ts +0 -94
  102. package/src/utils/function-utils.test.ts +0 -141
  103. package/src/utils/function-utils.ts +0 -245
  104. package/src/utils/pagination-utils.test.ts +0 -620
  105. package/src/utils/pagination-utils.ts +0 -242
  106. package/src/utils/schema-utils.ts +0 -207
  107. package/src/utils/string-utils.test.ts +0 -45
  108. package/src/utils/string-utils.ts +0 -54
  109. package/src/utils/validation.test.ts +0 -51
  110. package/src/utils/validation.ts +0 -44
  111. package/tsconfig.build.json +0 -18
  112. package/tsconfig.json +0 -20
  113. package/tsconfig.tsbuildinfo +0 -1
  114. 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
- }