@zapier/zapier-sdk 0.15.4 → 0.15.9

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 (64) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/dist/api/auth.d.ts.map +1 -1
  3. package/dist/api/auth.js +14 -4
  4. package/dist/api/auth.test.d.ts +2 -0
  5. package/dist/api/auth.test.d.ts.map +1 -0
  6. package/dist/api/auth.test.js +220 -0
  7. package/dist/api/client.d.ts.map +1 -1
  8. package/dist/api/client.js +18 -32
  9. package/dist/api/client.methods.test.d.ts +2 -0
  10. package/dist/api/client.methods.test.d.ts.map +1 -0
  11. package/dist/api/client.methods.test.js +158 -0
  12. package/dist/api/client.test.js +27 -11
  13. package/dist/api/router.d.ts +16 -0
  14. package/dist/api/router.d.ts.map +1 -0
  15. package/dist/api/router.js +37 -0
  16. package/dist/api/router.test.d.ts +2 -0
  17. package/dist/api/router.test.d.ts.map +1 -0
  18. package/dist/api/router.test.js +109 -0
  19. package/dist/auth.d.ts +15 -0
  20. package/dist/auth.d.ts.map +1 -1
  21. package/dist/auth.js +25 -0
  22. package/dist/index.cjs +247 -74
  23. package/dist/index.d.mts +402 -241
  24. package/dist/index.mjs +247 -75
  25. package/dist/plugins/eventEmission/index.d.ts.map +1 -1
  26. package/dist/plugins/eventEmission/index.js +9 -5
  27. package/dist/plugins/eventEmission/index.test.js +161 -0
  28. package/dist/plugins/getAction/index.d.ts.map +1 -1
  29. package/dist/plugins/getAction/index.js +2 -4
  30. package/dist/plugins/getAction/index.test.js +26 -3
  31. package/dist/plugins/getAuthentication/index.d.ts +2 -5
  32. package/dist/plugins/getAuthentication/index.d.ts.map +1 -1
  33. package/dist/plugins/getAuthentication/index.js +3 -24
  34. package/dist/plugins/getAuthentication/index.test.js +32 -144
  35. package/dist/plugins/getAuthentication/schemas.d.ts +4 -13
  36. package/dist/plugins/getAuthentication/schemas.d.ts.map +1 -1
  37. package/dist/plugins/getAuthentication/schemas.js +1 -11
  38. package/dist/sdk.d.ts +1 -1
  39. package/dist/temporary-internal-core/handlers/getAuthentication.d.ts +94 -0
  40. package/dist/temporary-internal-core/handlers/getAuthentication.d.ts.map +1 -0
  41. package/dist/temporary-internal-core/handlers/getAuthentication.js +68 -0
  42. package/dist/temporary-internal-core/handlers/getAuthentication.test.d.ts +2 -0
  43. package/dist/temporary-internal-core/handlers/getAuthentication.test.d.ts.map +1 -0
  44. package/dist/temporary-internal-core/handlers/getAuthentication.test.js +248 -0
  45. package/dist/temporary-internal-core/handlers/listApps.js +1 -1
  46. package/dist/temporary-internal-core/index.d.ts +2 -0
  47. package/dist/temporary-internal-core/index.d.ts.map +1 -1
  48. package/dist/temporary-internal-core/index.js +2 -0
  49. package/dist/temporary-internal-core/schemas/authentications/index.d.ts +454 -0
  50. package/dist/temporary-internal-core/schemas/authentications/index.d.ts.map +1 -0
  51. package/dist/temporary-internal-core/schemas/authentications/index.js +96 -0
  52. package/dist/temporary-internal-core/schemas/errors/index.d.ts +139 -0
  53. package/dist/temporary-internal-core/schemas/errors/index.d.ts.map +1 -0
  54. package/dist/temporary-internal-core/schemas/errors/index.js +129 -0
  55. package/dist/temporary-internal-core/utils/app-locators.d.ts +0 -20
  56. package/dist/temporary-internal-core/utils/app-locators.d.ts.map +1 -1
  57. package/dist/temporary-internal-core/utils/app-locators.js +1 -45
  58. package/dist/temporary-internal-core/utils/string-utils.d.ts +28 -0
  59. package/dist/temporary-internal-core/utils/string-utils.d.ts.map +1 -0
  60. package/dist/temporary-internal-core/utils/string-utils.js +52 -0
  61. package/dist/temporary-internal-core/utils/transformations.d.ts +14 -0
  62. package/dist/temporary-internal-core/utils/transformations.d.ts.map +1 -1
  63. package/dist/temporary-internal-core/utils/transformations.js +37 -1
  64. package/package.json +1 -1
@@ -0,0 +1,248 @@
1
+ import { describe, it, expect, vi, beforeEach } from "vitest";
2
+ import { handleGetAuthentication, } from "./getAuthentication";
3
+ import { ZapierAuthenticationError, ZapierResourceNotFoundError, } from "../schemas/errors";
4
+ const mockAuthenticationResponse = {
5
+ id: 123,
6
+ date: "2021-01-01",
7
+ account_id: 456,
8
+ selected_api: "SlackCLIAPI@1.21.1",
9
+ is_invite_only: false,
10
+ is_private: false,
11
+ shared_with_all: false,
12
+ is_stale: "false",
13
+ marked_stale_at: null,
14
+ label: "My Slack Workspace",
15
+ title: "My Slack Workspace",
16
+ };
17
+ describe("handleGetAuthentication", () => {
18
+ let mockHttpClient;
19
+ beforeEach(() => {
20
+ vi.clearAllMocks();
21
+ mockHttpClient = {
22
+ get: vi.fn().mockResolvedValue(mockAuthenticationResponse),
23
+ post: vi.fn(),
24
+ delete: vi.fn(),
25
+ };
26
+ });
27
+ describe("request validation", () => {
28
+ it("should reject request with missing authenticationId", async () => {
29
+ const invalidRequest = {};
30
+ const deps = {
31
+ httpClient: mockHttpClient,
32
+ };
33
+ await expect(handleGetAuthentication({ request: invalidRequest, deps })).rejects.toThrow();
34
+ });
35
+ it("should reject request with invalid authenticationId type", async () => {
36
+ const invalidRequest = {
37
+ authenticationId: { invalid: true },
38
+ };
39
+ const deps = {
40
+ httpClient: mockHttpClient,
41
+ };
42
+ await expect(handleGetAuthentication({ request: invalidRequest, deps })).rejects.toThrow();
43
+ });
44
+ it("should accept string authenticationId and convert to number", async () => {
45
+ // Note: The schema accepts string or number as input and transforms to number
46
+ const request = {
47
+ authenticationId: "123",
48
+ };
49
+ const deps = {
50
+ httpClient: mockHttpClient,
51
+ };
52
+ const result = await handleGetAuthentication({ request, deps });
53
+ expect(mockHttpClient.get).toHaveBeenCalledWith("/zapier/api/v4/authentications/123/", expect.any(Object));
54
+ expect(result.data).toBeDefined();
55
+ });
56
+ it("should accept number authenticationId", async () => {
57
+ const request = {
58
+ authenticationId: 123,
59
+ };
60
+ const deps = {
61
+ httpClient: mockHttpClient,
62
+ };
63
+ const result = await handleGetAuthentication({ request, deps });
64
+ expect(result.data).toBeDefined();
65
+ });
66
+ });
67
+ describe("API integration", () => {
68
+ it("should call the correct API endpoint", async () => {
69
+ const request = {
70
+ authenticationId: 123,
71
+ };
72
+ const deps = {
73
+ httpClient: mockHttpClient,
74
+ };
75
+ await handleGetAuthentication({ request, deps });
76
+ expect(mockHttpClient.get).toHaveBeenCalledWith("/zapier/api/v4/authentications/123/", expect.objectContaining({
77
+ authRequired: true,
78
+ customErrorHandler: expect.any(Function),
79
+ }));
80
+ });
81
+ it("should return normalized authentication data", async () => {
82
+ const request = {
83
+ authenticationId: 123,
84
+ };
85
+ const deps = {
86
+ httpClient: mockHttpClient,
87
+ };
88
+ const result = await handleGetAuthentication({ request, deps });
89
+ expect(result.data).toEqual({
90
+ id: 123,
91
+ date: "2021-01-01",
92
+ account_id: 456,
93
+ implementation_id: "SlackCLIAPI@1.21.1",
94
+ is_invite_only: false,
95
+ is_private: false,
96
+ shared_with_all: false,
97
+ is_expired: "false",
98
+ expired_at: null,
99
+ label: "My Slack Workspace",
100
+ title: "My Slack Workspace",
101
+ app_key: "SlackCLIAPI",
102
+ app_version: "1.21.1",
103
+ user_id: undefined, // customuser_id wasn't in mock data
104
+ is_stale: "false", // Original field preserved
105
+ marked_stale_at: null, // Original field preserved
106
+ });
107
+ });
108
+ });
109
+ describe("error handling", () => {
110
+ it("should throw ZapierAuthenticationError for 401 responses", async () => {
111
+ mockHttpClient.get = vi.fn().mockImplementation((_path, options) => {
112
+ const error = options?.customErrorHandler?.({
113
+ status: 401,
114
+ statusText: "Unauthorized",
115
+ data: {},
116
+ });
117
+ throw error;
118
+ });
119
+ const request = {
120
+ authenticationId: 123,
121
+ };
122
+ const deps = {
123
+ httpClient: mockHttpClient,
124
+ };
125
+ await expect(handleGetAuthentication({ request, deps })).rejects.toThrow(ZapierAuthenticationError);
126
+ });
127
+ it("should throw ZapierAuthenticationError for 403 responses", async () => {
128
+ mockHttpClient.get = vi.fn().mockImplementation((_path, options) => {
129
+ const error = options?.customErrorHandler?.({
130
+ status: 403,
131
+ statusText: "Forbidden",
132
+ data: {},
133
+ });
134
+ throw error;
135
+ });
136
+ const request = {
137
+ authenticationId: 123,
138
+ };
139
+ const deps = {
140
+ httpClient: mockHttpClient,
141
+ };
142
+ await expect(handleGetAuthentication({ request, deps })).rejects.toThrow(ZapierAuthenticationError);
143
+ });
144
+ it("should throw ZapierResourceNotFoundError for 404 responses", async () => {
145
+ mockHttpClient.get = vi.fn().mockImplementation((_path, options) => {
146
+ const error = options?.customErrorHandler?.({
147
+ status: 404,
148
+ statusText: "Not Found",
149
+ data: {},
150
+ });
151
+ throw error;
152
+ });
153
+ const request = {
154
+ authenticationId: 123,
155
+ };
156
+ const deps = {
157
+ httpClient: mockHttpClient,
158
+ };
159
+ await expect(handleGetAuthentication({ request, deps })).rejects.toThrow(ZapierResourceNotFoundError);
160
+ });
161
+ it("should handle network errors", async () => {
162
+ mockHttpClient.get = vi
163
+ .fn()
164
+ .mockRejectedValue(new Error("Network error"));
165
+ const request = {
166
+ authenticationId: 123,
167
+ };
168
+ const deps = {
169
+ httpClient: mockHttpClient,
170
+ };
171
+ await expect(handleGetAuthentication({ request, deps })).rejects.toThrow("Network error");
172
+ });
173
+ });
174
+ describe("data transformation", () => {
175
+ it("should map is_stale to is_expired and marked_stale_at to expired_at", async () => {
176
+ const authWithExpiration = {
177
+ ...mockAuthenticationResponse,
178
+ is_stale: "true",
179
+ marked_stale_at: "2021-06-01",
180
+ };
181
+ mockHttpClient.get = vi.fn().mockResolvedValue(authWithExpiration);
182
+ const request = {
183
+ authenticationId: 123,
184
+ };
185
+ const deps = {
186
+ httpClient: mockHttpClient,
187
+ };
188
+ const result = await handleGetAuthentication({ request, deps });
189
+ expect(result.data.is_expired).toBe("true");
190
+ expect(result.data.expired_at).toBe("2021-06-01");
191
+ });
192
+ it("should preserve all original authentication fields", async () => {
193
+ const authWithAllFields = {
194
+ id: 123,
195
+ date: "2021-01-01",
196
+ lastchanged: "2021-01-02",
197
+ account_id: 456,
198
+ customuser_id: 789,
199
+ selected_api: "SlackCLIAPI@1.21.1",
200
+ destination_selected_api: "SlackDestAPI@1.0.0",
201
+ is_invite_only: true,
202
+ is_private: true,
203
+ shared_with_all: false,
204
+ is_stale: "true",
205
+ is_shared: "false",
206
+ marked_stale_at: "2021-06-01",
207
+ label: "Auth Label",
208
+ title: "Auth Title",
209
+ identifier: "auth-identifier",
210
+ url: "https://example.com",
211
+ groups: "group1,group2",
212
+ members: "user1,user2",
213
+ permissions: { read: true, write: false },
214
+ };
215
+ mockHttpClient.get = vi.fn().mockResolvedValue(authWithAllFields);
216
+ const request = {
217
+ authenticationId: 123,
218
+ };
219
+ const deps = {
220
+ httpClient: mockHttpClient,
221
+ };
222
+ const result = await handleGetAuthentication({ request, deps });
223
+ const auth = result.data;
224
+ // Verify original fields are preserved
225
+ expect(auth.id).toBe(123);
226
+ expect(auth.date).toBe("2021-01-01");
227
+ expect(auth.lastchanged).toBe("2021-01-02");
228
+ expect(auth.account_id).toBe(456);
229
+ expect(auth.user_id).toBe(789);
230
+ expect(auth.implementation_id).toBe("SlackCLIAPI@1.21.1");
231
+ expect(auth.destination_selected_api).toBe("SlackDestAPI@1.0.0");
232
+ expect(auth.is_invite_only).toBe(true);
233
+ expect(auth.is_private).toBe(true);
234
+ expect(auth.shared_with_all).toBe(false);
235
+ expect(auth.is_shared).toBe("false");
236
+ expect(auth.label).toBe("Auth Label");
237
+ expect(auth.title).toBe("Auth Title");
238
+ expect(auth.identifier).toBe("auth-identifier");
239
+ expect(auth.url).toBe("https://example.com");
240
+ expect(auth.groups).toBe("group1,group2");
241
+ expect(auth.members).toBe("user1,user2");
242
+ expect(auth.permissions).toEqual({ read: true, write: false });
243
+ // Verify mapped fields
244
+ expect(auth.is_expired).toBe("true");
245
+ expect(auth.expired_at).toBe("2021-06-01");
246
+ });
247
+ });
248
+ });
@@ -12,7 +12,7 @@
12
12
  * The handler receives pre-resolved implementation IDs and performs search augmentation.
13
13
  */
14
14
  import { ListAppsHandlerRequestSchema, } from "../schemas/apps";
15
- import { splitVersionedKey } from "../utils/app-locators";
15
+ import { splitVersionedKey } from "../utils/string-utils";
16
16
  import { transformImplementationMetaToAppItem, extractPaginationCursor, } from "../utils/transformations";
17
17
  // ============================================================================
18
18
  // Constants
@@ -14,5 +14,7 @@
14
14
  export type { HandlerDeps, Handler, ValidatedHandler } from "./types";
15
15
  export * from "./schemas/apps";
16
16
  export * from "./schemas/implementations";
17
+ export * from "./schemas/authentications";
17
18
  export { handleListApps, type ListAppsHandlerDeps } from "./handlers/listApps";
19
+ export { handleGetAuthentication, type GetAuthenticationHandlerDeps, } from "./handlers/getAuthentication";
18
20
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/temporary-internal-core/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAGH,YAAY,EAAE,WAAW,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAGtE,cAAc,gBAAgB,CAAC;AAC/B,cAAc,2BAA2B,CAAC;AAG1C,OAAO,EAAE,cAAc,EAAE,KAAK,mBAAmB,EAAE,MAAM,qBAAqB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/temporary-internal-core/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAGH,YAAY,EAAE,WAAW,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAGtE,cAAc,gBAAgB,CAAC;AAC/B,cAAc,2BAA2B,CAAC;AAC1C,cAAc,2BAA2B,CAAC;AAG1C,OAAO,EAAE,cAAc,EAAE,KAAK,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC/E,OAAO,EACL,uBAAuB,EACvB,KAAK,4BAA4B,GAClC,MAAM,8BAA8B,CAAC"}
@@ -14,5 +14,7 @@
14
14
  // Schemas
15
15
  export * from "./schemas/apps";
16
16
  export * from "./schemas/implementations";
17
+ export * from "./schemas/authentications";
17
18
  // Handlers
18
19
  export { handleListApps } from "./handlers/listApps";
20
+ export { handleGetAuthentication, } from "./handlers/getAuthentication";