@zapier/zapier-sdk 0.15.3 → 0.15.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.
- package/CHANGELOG.md +30 -0
- package/dist/api/auth.d.ts +10 -0
- package/dist/api/auth.d.ts.map +1 -1
- package/dist/api/auth.js +45 -0
- package/dist/api/auth.test.d.ts +2 -0
- package/dist/api/auth.test.d.ts.map +1 -0
- package/dist/api/auth.test.js +220 -0
- package/dist/api/client.d.ts.map +1 -1
- package/dist/api/client.js +18 -32
- package/dist/api/client.methods.test.d.ts +2 -0
- package/dist/api/client.methods.test.d.ts.map +1 -0
- package/dist/api/client.methods.test.js +158 -0
- package/dist/api/client.test.js +27 -11
- package/dist/api/router.d.ts +16 -0
- package/dist/api/router.d.ts.map +1 -0
- package/dist/api/router.js +37 -0
- package/dist/api/router.test.d.ts +2 -0
- package/dist/api/router.test.d.ts.map +1 -0
- package/dist/api/router.test.js +109 -0
- package/dist/api/schemas.d.ts +38 -38
- package/dist/auth.d.ts +15 -0
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +25 -0
- package/dist/index.cjs +350 -87
- package/dist/index.d.mts +430 -269
- package/dist/index.mjs +350 -88
- package/dist/plugins/eventEmission/index.d.ts +1 -1
- package/dist/plugins/eventEmission/index.d.ts.map +1 -1
- package/dist/plugins/eventEmission/index.js +94 -22
- package/dist/plugins/eventEmission/index.test.js +340 -2
- package/dist/plugins/getAuthentication/index.d.ts +2 -5
- package/dist/plugins/getAuthentication/index.d.ts.map +1 -1
- package/dist/plugins/getAuthentication/index.js +3 -24
- package/dist/plugins/getAuthentication/index.test.js +32 -144
- package/dist/plugins/getAuthentication/schemas.d.ts +4 -13
- package/dist/plugins/getAuthentication/schemas.d.ts.map +1 -1
- package/dist/plugins/getAuthentication/schemas.js +1 -11
- package/dist/schemas/Action.d.ts +1 -1
- package/dist/schemas/Auth.d.ts +6 -6
- package/dist/sdk.d.ts +1 -1
- package/dist/temporary-internal-core/handlers/getAuthentication.d.ts +94 -0
- package/dist/temporary-internal-core/handlers/getAuthentication.d.ts.map +1 -0
- package/dist/temporary-internal-core/handlers/getAuthentication.js +68 -0
- package/dist/temporary-internal-core/handlers/getAuthentication.test.d.ts +2 -0
- package/dist/temporary-internal-core/handlers/getAuthentication.test.d.ts.map +1 -0
- package/dist/temporary-internal-core/handlers/getAuthentication.test.js +248 -0
- package/dist/temporary-internal-core/handlers/listApps.js +1 -1
- package/dist/temporary-internal-core/index.d.ts +2 -0
- package/dist/temporary-internal-core/index.d.ts.map +1 -1
- package/dist/temporary-internal-core/index.js +2 -0
- package/dist/temporary-internal-core/schemas/authentications/index.d.ts +454 -0
- package/dist/temporary-internal-core/schemas/authentications/index.d.ts.map +1 -0
- package/dist/temporary-internal-core/schemas/authentications/index.js +96 -0
- package/dist/temporary-internal-core/schemas/errors/index.d.ts +139 -0
- package/dist/temporary-internal-core/schemas/errors/index.d.ts.map +1 -0
- package/dist/temporary-internal-core/schemas/errors/index.js +129 -0
- package/dist/temporary-internal-core/utils/app-locators.d.ts +0 -20
- package/dist/temporary-internal-core/utils/app-locators.d.ts.map +1 -1
- package/dist/temporary-internal-core/utils/app-locators.js +1 -45
- package/dist/temporary-internal-core/utils/string-utils.d.ts +28 -0
- package/dist/temporary-internal-core/utils/string-utils.d.ts.map +1 -0
- package/dist/temporary-internal-core/utils/string-utils.js +52 -0
- package/dist/temporary-internal-core/utils/transformations.d.ts +14 -0
- package/dist/temporary-internal-core/utils/transformations.d.ts.map +1 -1
- package/dist/temporary-internal-core/utils/transformations.js +37 -1
- package/package.json +1 -1
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
2
|
-
import { ZapierValidationError
|
|
2
|
+
import { ZapierValidationError } from "../../types/errors";
|
|
3
3
|
import { getAuthenticationPlugin } from "./index";
|
|
4
4
|
import { createSdk } from "../../sdk";
|
|
5
|
-
|
|
6
|
-
import { listAppsPlugin } from "../listApps";
|
|
7
|
-
const mockAuthenticationResponse = {
|
|
5
|
+
const mockAuthenticationItem = {
|
|
8
6
|
id: 123,
|
|
9
7
|
date: "2021-01-01",
|
|
10
8
|
account_id: 456,
|
|
11
|
-
|
|
9
|
+
implementation_id: "SlackCLIAPI@1.21.1",
|
|
12
10
|
is_invite_only: false,
|
|
13
11
|
is_private: false,
|
|
14
12
|
shared_with_all: false,
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
is_expired: "false",
|
|
14
|
+
expired_at: null,
|
|
17
15
|
label: "My Slack Workspace",
|
|
18
16
|
title: "My Slack Workspace",
|
|
17
|
+
app_key: "SlackCLIAPI",
|
|
18
|
+
app_version: "1.21.1",
|
|
19
19
|
};
|
|
20
20
|
describe("getAuthentication plugin", () => {
|
|
21
21
|
let mockApiClient;
|
|
22
22
|
beforeEach(() => {
|
|
23
23
|
vi.clearAllMocks();
|
|
24
24
|
mockApiClient = {
|
|
25
|
-
get: vi.fn().mockResolvedValue(
|
|
25
|
+
get: vi.fn().mockResolvedValue({ data: mockAuthenticationItem }),
|
|
26
26
|
};
|
|
27
27
|
});
|
|
28
28
|
const apiPlugin = () => ({
|
|
@@ -31,13 +31,9 @@ describe("getAuthentication plugin", () => {
|
|
|
31
31
|
},
|
|
32
32
|
});
|
|
33
33
|
function createTestSdk() {
|
|
34
|
-
return createSdk()
|
|
35
|
-
.addPlugin(apiPlugin)
|
|
36
|
-
.addPlugin(manifestPlugin)
|
|
37
|
-
.addPlugin(listAppsPlugin)
|
|
38
|
-
.addPlugin(getAuthenticationPlugin);
|
|
34
|
+
return createSdk().addPlugin(apiPlugin).addPlugin(getAuthenticationPlugin);
|
|
39
35
|
}
|
|
40
|
-
describe("
|
|
36
|
+
describe("input validation", () => {
|
|
41
37
|
it("should throw validation error for missing authenticationId", async () => {
|
|
42
38
|
const sdk = createTestSdk();
|
|
43
39
|
await expect(sdk.getAuthentication({})).rejects.toThrow(ZapierValidationError);
|
|
@@ -60,157 +56,49 @@ describe("getAuthentication plugin", () => {
|
|
|
60
56
|
authenticationId: 0,
|
|
61
57
|
})).rejects.toThrow(ZapierValidationError);
|
|
62
58
|
});
|
|
63
|
-
it("should
|
|
59
|
+
it("should accept valid authenticationId", async () => {
|
|
64
60
|
const sdk = createTestSdk();
|
|
65
61
|
const result = await sdk.getAuthentication({
|
|
66
62
|
authenticationId: 123,
|
|
67
63
|
});
|
|
68
64
|
expect(result.data).toBeDefined();
|
|
65
|
+
expect(result.data.id).toBe(123);
|
|
69
66
|
});
|
|
70
67
|
});
|
|
71
|
-
describe("API
|
|
72
|
-
it("should call the correct API endpoint", async () => {
|
|
68
|
+
describe("SDK API endpoint routing", () => {
|
|
69
|
+
it("should call the correct SDK API endpoint with path params", async () => {
|
|
73
70
|
const sdk = createTestSdk();
|
|
74
71
|
await sdk.getAuthentication({ authenticationId: 123 });
|
|
75
|
-
expect(mockApiClient.get).toHaveBeenCalledWith("/
|
|
76
|
-
authRequired: true,
|
|
77
|
-
customErrorHandler: expect.any(Function),
|
|
78
|
-
}));
|
|
72
|
+
expect(mockApiClient.get).toHaveBeenCalledWith("/api/v0/authentications/123");
|
|
79
73
|
});
|
|
80
|
-
it("should return
|
|
74
|
+
it("should return data from API response", async () => {
|
|
81
75
|
const sdk = createTestSdk();
|
|
82
76
|
const result = await sdk.getAuthentication({ authenticationId: 123 });
|
|
83
|
-
expect(result.data).toEqual(
|
|
84
|
-
id: 123,
|
|
85
|
-
date: "2021-01-01",
|
|
86
|
-
account_id: 456,
|
|
87
|
-
implementation_id: "SlackCLIAPI@1.21.1",
|
|
88
|
-
is_invite_only: false,
|
|
89
|
-
is_private: false,
|
|
90
|
-
shared_with_all: false,
|
|
91
|
-
is_expired: "false",
|
|
92
|
-
expired_at: null,
|
|
93
|
-
label: "My Slack Workspace",
|
|
94
|
-
title: "My Slack Workspace",
|
|
95
|
-
app_key: "SlackCLIAPI",
|
|
96
|
-
app_version: "1.21.1",
|
|
97
|
-
user_id: undefined, // customuser_id wasn't in mock data
|
|
98
|
-
is_stale: "false", // Original field preserved
|
|
99
|
-
marked_stale_at: null, // Original field preserved
|
|
100
|
-
});
|
|
101
|
-
});
|
|
102
|
-
});
|
|
103
|
-
describe("error handling", () => {
|
|
104
|
-
it("should throw ZapierAuthenticationError for 401 responses", async () => {
|
|
105
|
-
const customErrorHandler = vi
|
|
106
|
-
.fn()
|
|
107
|
-
.mockReturnValue(new ZapierAuthenticationError("Authentication failed. Your token may not have permission to access authentications or may be expired. (HTTP 401)", { statusCode: 401 }));
|
|
108
|
-
mockApiClient.get = vi.fn().mockImplementation(() => {
|
|
109
|
-
const error = customErrorHandler({ status: 401 });
|
|
110
|
-
throw error;
|
|
111
|
-
});
|
|
112
|
-
const sdk = createTestSdk();
|
|
113
|
-
await expect(sdk.getAuthentication({ authenticationId: 123 })).rejects.toThrow(ZapierAuthenticationError);
|
|
114
|
-
});
|
|
115
|
-
it("should throw ZapierAuthenticationError for 403 responses", async () => {
|
|
116
|
-
const customErrorHandler = vi
|
|
117
|
-
.fn()
|
|
118
|
-
.mockReturnValue(new ZapierAuthenticationError("Access forbidden. Your token may not have the required scopes to get authentication 123. (HTTP 403)", { statusCode: 403 }));
|
|
119
|
-
mockApiClient.get = vi.fn().mockImplementation(() => {
|
|
120
|
-
const error = customErrorHandler({ status: 403 });
|
|
121
|
-
throw error;
|
|
122
|
-
});
|
|
123
|
-
const sdk = createTestSdk();
|
|
124
|
-
await expect(sdk.getAuthentication({ authenticationId: 123 })).rejects.toThrow(ZapierAuthenticationError);
|
|
125
|
-
});
|
|
126
|
-
it("should throw ZapierResourceNotFoundError for 404 responses", async () => {
|
|
127
|
-
const customErrorHandler = vi.fn().mockReturnValue(new ZapierResourceNotFoundError("Authentication 123 not found. It may not exist or you may not have access to it. (HTTP 404)", {
|
|
128
|
-
resourceType: "Authentication",
|
|
129
|
-
resourceId: "123",
|
|
130
|
-
}));
|
|
131
|
-
mockApiClient.get = vi.fn().mockImplementation(() => {
|
|
132
|
-
const error = customErrorHandler({ status: 404 });
|
|
133
|
-
throw error;
|
|
134
|
-
});
|
|
135
|
-
const sdk = createTestSdk();
|
|
136
|
-
await expect(sdk.getAuthentication({ authenticationId: 123 })).rejects.toThrow(ZapierResourceNotFoundError);
|
|
137
|
-
});
|
|
138
|
-
it("should handle network errors", async () => {
|
|
139
|
-
mockApiClient.get = vi.fn().mockRejectedValue(new Error("Network error"));
|
|
140
|
-
const sdk = createTestSdk();
|
|
141
|
-
await expect(sdk.getAuthentication({ authenticationId: 123 })).rejects.toThrow("Network error");
|
|
77
|
+
expect(result.data).toEqual(mockAuthenticationItem);
|
|
142
78
|
});
|
|
143
79
|
});
|
|
144
|
-
describe("
|
|
145
|
-
it("should
|
|
146
|
-
|
|
147
|
-
...mockAuthenticationResponse,
|
|
148
|
-
is_stale: "true",
|
|
149
|
-
marked_stale_at: "2021-06-01",
|
|
150
|
-
};
|
|
151
|
-
mockApiClient.get = vi.fn().mockResolvedValue(authWithExpiration);
|
|
152
|
-
const sdk = createTestSdk();
|
|
153
|
-
const result = await sdk.getAuthentication({ authenticationId: 123 });
|
|
154
|
-
expect(result.data.is_expired).toBe("true");
|
|
155
|
-
expect(result.data.expired_at).toBe("2021-06-01");
|
|
156
|
-
});
|
|
157
|
-
it("should preserve all original authentication fields", async () => {
|
|
158
|
-
const authWithAllFields = {
|
|
159
|
-
id: 123,
|
|
160
|
-
date: "2021-01-01",
|
|
161
|
-
lastchanged: "2021-01-02",
|
|
162
|
-
account_id: 456,
|
|
163
|
-
customuser_id: 789,
|
|
164
|
-
selected_api: "SlackCLIAPI@1.21.1",
|
|
165
|
-
destination_selected_api: "SlackDestAPI@1.0.0",
|
|
166
|
-
is_invite_only: true,
|
|
167
|
-
is_private: true,
|
|
168
|
-
shared_with_all: false,
|
|
169
|
-
is_stale: "true",
|
|
170
|
-
is_shared: "false",
|
|
171
|
-
marked_stale_at: "2021-06-01",
|
|
172
|
-
label: "Auth Label",
|
|
173
|
-
title: "Auth Title",
|
|
174
|
-
identifier: "auth-identifier",
|
|
175
|
-
url: "https://example.com",
|
|
176
|
-
groups: "group1,group2",
|
|
177
|
-
members: "user1,user2",
|
|
178
|
-
permissions: { read: true, write: false },
|
|
179
|
-
};
|
|
180
|
-
mockApiClient.get = vi.fn().mockResolvedValue(authWithAllFields);
|
|
80
|
+
describe("error propagation", () => {
|
|
81
|
+
it("should propagate errors from API client", async () => {
|
|
82
|
+
mockApiClient.get = vi.fn().mockRejectedValue(new Error("API error"));
|
|
181
83
|
const sdk = createTestSdk();
|
|
182
|
-
|
|
183
|
-
const auth = result.data;
|
|
184
|
-
// Verify original fields are preserved
|
|
185
|
-
expect(auth.id).toBe(123);
|
|
186
|
-
expect(auth.date).toBe("2021-01-01");
|
|
187
|
-
expect(auth.lastchanged).toBe("2021-01-02");
|
|
188
|
-
expect(auth.account_id).toBe(456);
|
|
189
|
-
expect(auth.user_id).toBe(789);
|
|
190
|
-
expect(auth.implementation_id).toBe("SlackCLIAPI@1.21.1");
|
|
191
|
-
expect(auth.destination_selected_api).toBe("SlackDestAPI@1.0.0");
|
|
192
|
-
expect(auth.is_invite_only).toBe(true);
|
|
193
|
-
expect(auth.is_private).toBe(true);
|
|
194
|
-
expect(auth.shared_with_all).toBe(false);
|
|
195
|
-
expect(auth.is_shared).toBe("false");
|
|
196
|
-
expect(auth.label).toBe("Auth Label");
|
|
197
|
-
expect(auth.title).toBe("Auth Title");
|
|
198
|
-
expect(auth.identifier).toBe("auth-identifier");
|
|
199
|
-
expect(auth.url).toBe("https://example.com");
|
|
200
|
-
expect(auth.groups).toBe("group1,group2");
|
|
201
|
-
expect(auth.members).toBe("user1,user2");
|
|
202
|
-
expect(auth.permissions).toEqual({ read: true, write: false });
|
|
203
|
-
// Verify mapped fields
|
|
204
|
-
expect(auth.is_expired).toBe("true");
|
|
205
|
-
expect(auth.expired_at).toBe("2021-06-01");
|
|
84
|
+
await expect(sdk.getAuthentication({ authenticationId: 123 })).rejects.toThrow("API error");
|
|
206
85
|
});
|
|
207
86
|
});
|
|
208
|
-
describe("
|
|
209
|
-
it("should provide
|
|
87
|
+
describe("plugin metadata", () => {
|
|
88
|
+
it("should provide metadata in SDK context", () => {
|
|
210
89
|
const sdk = createTestSdk();
|
|
211
90
|
const context = sdk.getContext();
|
|
212
91
|
expect(context.meta.getAuthentication).toBeDefined();
|
|
213
92
|
expect(context.meta.getAuthentication.inputSchema).toBeDefined();
|
|
93
|
+
expect(context.meta.getAuthentication.outputSchema).toBeDefined();
|
|
94
|
+
expect(context.meta.getAuthentication.type).toBe("item");
|
|
95
|
+
expect(context.meta.getAuthentication.itemType).toBe("Authentication");
|
|
96
|
+
});
|
|
97
|
+
it("should include resolvers in metadata", () => {
|
|
98
|
+
const sdk = createTestSdk();
|
|
99
|
+
const context = sdk.getContext();
|
|
100
|
+
expect(context.meta.getAuthentication.resolvers).toBeDefined();
|
|
101
|
+
expect(context.meta.getAuthentication.resolvers.authenticationId).toBeDefined();
|
|
214
102
|
});
|
|
215
103
|
});
|
|
216
104
|
});
|
|
@@ -1,18 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type { AuthenticationItem } from "../../types/domain";
|
|
1
|
+
import type { GetAuthenticationResponse } from "../../temporary-internal-core";
|
|
3
2
|
import type { ZapierAuthenticationError, ZapierResourceNotFoundError, ZapierApiError, ZapierValidationError, ZapierUnknownError } from "../../types/errors";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}, "strip", z.ZodTypeAny, {
|
|
7
|
-
authenticationId: number;
|
|
8
|
-
}, {
|
|
9
|
-
authenticationId: number;
|
|
10
|
-
}>;
|
|
11
|
-
export type GetAuthenticationOptions = z.infer<typeof GetAuthenticationSchema>;
|
|
3
|
+
import type { GetAuthenticationOptions } from "../../temporary-internal-core/schemas/authentications";
|
|
4
|
+
export { GetAuthenticationOptionsSchema as GetAuthenticationSchema, GetAuthenticationHandlerRequestSchema, GetAuthenticationResponseSchema, type GetAuthenticationOptions, type GetAuthenticationHandlerRequest, type GetAuthenticationResponse, } from "../../temporary-internal-core/schemas/authentications";
|
|
12
5
|
export type GetAuthenticationError = ZapierAuthenticationError | ZapierResourceNotFoundError | ZapierApiError | ZapierValidationError | ZapierUnknownError;
|
|
13
6
|
export interface GetAuthenticationSdkFunction {
|
|
14
|
-
getAuthentication: (options: GetAuthenticationOptions) => Promise<
|
|
15
|
-
data: AuthenticationItem;
|
|
16
|
-
}>;
|
|
7
|
+
getAuthentication: (options: GetAuthenticationOptions) => Promise<GetAuthenticationResponse>;
|
|
17
8
|
}
|
|
18
9
|
//# sourceMappingURL=schemas.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../../src/plugins/getAuthentication/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../../src/plugins/getAuthentication/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,+BAA+B,CAAC;AAC/E,OAAO,KAAK,EACV,yBAAyB,EACzB,2BAA2B,EAC3B,cAAc,EACd,qBAAqB,EACrB,kBAAkB,EACnB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,uDAAuD,CAAC;AAEtG,OAAO,EACL,8BAA8B,IAAI,uBAAuB,EACzD,qCAAqC,EACrC,+BAA+B,EAC/B,KAAK,wBAAwB,EAC7B,KAAK,+BAA+B,EACpC,KAAK,yBAAyB,GAC/B,MAAM,uDAAuD,CAAC;AAG/D,MAAM,MAAM,sBAAsB,GAC9B,yBAAyB,GACzB,2BAA2B,GAC3B,cAAc,GACd,qBAAqB,GACrB,kBAAkB,CAAC;AAGvB,MAAM,WAAW,4BAA4B;IAC3C,iBAAiB,EAAE,CACjB,OAAO,EAAE,wBAAwB,KAC9B,OAAO,CAAC,yBAAyB,CAAC,CAAC;CACzC"}
|
|
@@ -1,11 +1 @@
|
|
|
1
|
-
|
|
2
|
-
// Pure Zod schema - no resolver metadata!
|
|
3
|
-
export const GetAuthenticationSchema = z
|
|
4
|
-
.object({
|
|
5
|
-
authenticationId: z
|
|
6
|
-
.number()
|
|
7
|
-
.int()
|
|
8
|
-
.positive()
|
|
9
|
-
.describe("Authentication ID to retrieve"),
|
|
10
|
-
})
|
|
11
|
-
.describe("Get a specific authentication by ID");
|
|
1
|
+
export { GetAuthenticationOptionsSchema as GetAuthenticationSchema, GetAuthenticationHandlerRequestSchema, GetAuthenticationResponseSchema, } from "../../temporary-internal-core/schemas/authentications";
|
package/dist/schemas/Action.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export declare const ActionItemSchema: z.ZodObject<Omit<{
|
|
|
8
8
|
is_important: z.ZodOptional<z.ZodBoolean>;
|
|
9
9
|
is_hidden: z.ZodOptional<z.ZodBoolean>;
|
|
10
10
|
selected_api: z.ZodOptional<z.ZodString>;
|
|
11
|
-
}, "type" | "
|
|
11
|
+
}, "type" | "selected_api" | "name"> & {
|
|
12
12
|
app_key: z.ZodString;
|
|
13
13
|
app_version: z.ZodOptional<z.ZodString>;
|
|
14
14
|
action_type: z.ZodEnum<["filter", "read", "read_bulk", "run", "search", "search_and_write", "search_or_write", "write"]>;
|
package/dist/schemas/Auth.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ export declare const AuthenticationItemSchema: z.ZodObject<Omit<{
|
|
|
20
20
|
groups: z.ZodOptional<z.ZodString>;
|
|
21
21
|
members: z.ZodOptional<z.ZodString>;
|
|
22
22
|
permissions: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodBoolean>>;
|
|
23
|
-
}, "
|
|
23
|
+
}, "customuser_id" | "selected_api"> & {
|
|
24
24
|
implementation_id: z.ZodOptional<z.ZodString>;
|
|
25
25
|
is_expired: z.ZodOptional<z.ZodString>;
|
|
26
26
|
expired_at: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
@@ -28,9 +28,9 @@ export declare const AuthenticationItemSchema: z.ZodObject<Omit<{
|
|
|
28
28
|
app_version: z.ZodOptional<z.ZodString>;
|
|
29
29
|
user_id: z.ZodOptional<z.ZodNumber>;
|
|
30
30
|
}, "strip", z.ZodTypeAny, {
|
|
31
|
+
account_id: number;
|
|
31
32
|
id: number;
|
|
32
33
|
date: string;
|
|
33
|
-
account_id: number;
|
|
34
34
|
is_invite_only: boolean;
|
|
35
35
|
is_private: boolean;
|
|
36
36
|
shared_with_all: boolean;
|
|
@@ -53,9 +53,9 @@ export declare const AuthenticationItemSchema: z.ZodObject<Omit<{
|
|
|
53
53
|
app_key?: string | undefined;
|
|
54
54
|
app_version?: string | undefined;
|
|
55
55
|
}, {
|
|
56
|
+
account_id: number;
|
|
56
57
|
id: number;
|
|
57
58
|
date: string;
|
|
58
|
-
account_id: number;
|
|
59
59
|
is_invite_only: boolean;
|
|
60
60
|
is_private: boolean;
|
|
61
61
|
shared_with_all: boolean;
|
|
@@ -99,7 +99,7 @@ export declare const AuthItemSchema: z.ZodObject<Omit<{
|
|
|
99
99
|
groups: z.ZodOptional<z.ZodString>;
|
|
100
100
|
members: z.ZodOptional<z.ZodString>;
|
|
101
101
|
permissions: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodBoolean>>;
|
|
102
|
-
}, "
|
|
102
|
+
}, "customuser_id" | "selected_api"> & {
|
|
103
103
|
implementation_id: z.ZodOptional<z.ZodString>;
|
|
104
104
|
is_expired: z.ZodOptional<z.ZodString>;
|
|
105
105
|
expired_at: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
@@ -107,9 +107,9 @@ export declare const AuthItemSchema: z.ZodObject<Omit<{
|
|
|
107
107
|
app_version: z.ZodOptional<z.ZodString>;
|
|
108
108
|
user_id: z.ZodOptional<z.ZodNumber>;
|
|
109
109
|
}, "strip", z.ZodTypeAny, {
|
|
110
|
+
account_id: number;
|
|
110
111
|
id: number;
|
|
111
112
|
date: string;
|
|
112
|
-
account_id: number;
|
|
113
113
|
is_invite_only: boolean;
|
|
114
114
|
is_private: boolean;
|
|
115
115
|
shared_with_all: boolean;
|
|
@@ -132,9 +132,9 @@ export declare const AuthItemSchema: z.ZodObject<Omit<{
|
|
|
132
132
|
app_key?: string | undefined;
|
|
133
133
|
app_version?: string | undefined;
|
|
134
134
|
}, {
|
|
135
|
+
account_id: number;
|
|
135
136
|
id: number;
|
|
136
137
|
date: string;
|
|
137
|
-
account_id: number;
|
|
138
138
|
is_invite_only: boolean;
|
|
139
139
|
is_private: boolean;
|
|
140
140
|
shared_with_all: boolean;
|
package/dist/sdk.d.ts
CHANGED
|
@@ -100,7 +100,7 @@ export declare function createZapierSdkWithoutRegistry(options?: ZapierSdkOption
|
|
|
100
100
|
} & {
|
|
101
101
|
meta: {
|
|
102
102
|
getAuthentication: {
|
|
103
|
-
inputSchema: typeof import("./
|
|
103
|
+
inputSchema: typeof import("./temporary-internal-core").GetAuthenticationOptionsSchema;
|
|
104
104
|
};
|
|
105
105
|
};
|
|
106
106
|
} & {
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Handler for getAuthentication operation
|
|
3
|
+
*
|
|
4
|
+
* This handler will become an SDK API endpoint handler.
|
|
5
|
+
* It encapsulates the business logic for retrieving a single authentication, including:
|
|
6
|
+
* - API call to internal authentication endpoint
|
|
7
|
+
* - Custom error handling (401, 403, 404)
|
|
8
|
+
* - Response transformation (field renaming, computed fields)
|
|
9
|
+
*
|
|
10
|
+
* The handler receives a validated authentication ID and returns normalized data.
|
|
11
|
+
*/
|
|
12
|
+
import type { Handler, HandlerDeps } from "../types";
|
|
13
|
+
import { type GetAuthenticationHandlerRequest, type GetAuthenticationResponse } from "../schemas/authentications";
|
|
14
|
+
/**
|
|
15
|
+
* Simple HTTP client interface for calling internal APIs
|
|
16
|
+
*
|
|
17
|
+
* Why pass this as a dependency instead of importing directly?
|
|
18
|
+
*
|
|
19
|
+
* 1. **Different implementations in different contexts:**
|
|
20
|
+
* - In the SDK: Uses the ApiClient wrapper (adds auth, error handling, etc.)
|
|
21
|
+
* - In the SDK API: Would use internal HTTP client or direct service calls
|
|
22
|
+
*
|
|
23
|
+
* 2. **Testability:**
|
|
24
|
+
* - Can mock httpClient in tests without complex setup
|
|
25
|
+
* - Can verify API calls and responses in isolation
|
|
26
|
+
*
|
|
27
|
+
* 3. **No hard coupling:**
|
|
28
|
+
* - Handler doesn't know/care how HTTP calls are made
|
|
29
|
+
* - Makes migration to SDK API easier (just swap implementation)
|
|
30
|
+
*/
|
|
31
|
+
export interface HttpClient {
|
|
32
|
+
get<T = unknown>(path: string, options?: {
|
|
33
|
+
searchParams?: Record<string, string>;
|
|
34
|
+
authRequired?: boolean;
|
|
35
|
+
customErrorHandler?: (errorInfo: {
|
|
36
|
+
status: number;
|
|
37
|
+
statusText: string;
|
|
38
|
+
data: unknown;
|
|
39
|
+
}) => Error | undefined;
|
|
40
|
+
}): Promise<T>;
|
|
41
|
+
post<T = unknown>(path: string, data?: unknown, options?: {
|
|
42
|
+
authRequired?: boolean;
|
|
43
|
+
customErrorHandler?: (errorInfo: {
|
|
44
|
+
status: number;
|
|
45
|
+
statusText: string;
|
|
46
|
+
data: unknown;
|
|
47
|
+
}) => Error | undefined;
|
|
48
|
+
}): Promise<T>;
|
|
49
|
+
delete<T = unknown>(path: string, options?: {
|
|
50
|
+
authRequired?: boolean;
|
|
51
|
+
customErrorHandler?: (errorInfo: {
|
|
52
|
+
status: number;
|
|
53
|
+
statusText: string;
|
|
54
|
+
data: unknown;
|
|
55
|
+
}) => Error | undefined;
|
|
56
|
+
}): Promise<T>;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Dependencies required by the getAuthentication handler
|
|
60
|
+
*
|
|
61
|
+
* Passed as a parameter (dependency injection) rather than imported directly
|
|
62
|
+
* to allow different implementations in different environments:
|
|
63
|
+
* - SDK plugin injects: { httpClient: api } (SDK's ApiClient)
|
|
64
|
+
* - SDK API would inject: { httpClient: internalHttpClient } (direct internal calls)
|
|
65
|
+
* - Tests inject: { httpClient: mockHttpClient } (mocked responses)
|
|
66
|
+
*
|
|
67
|
+
* Extends HandlerDeps to ensure compatibility with the Handler interface.
|
|
68
|
+
*/
|
|
69
|
+
export interface GetAuthenticationHandlerDeps extends HandlerDeps {
|
|
70
|
+
httpClient: HttpClient;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Handles getAuthentication operation
|
|
74
|
+
*
|
|
75
|
+
* Conforms to the Handler<TRequest, TResponse, TDeps> interface contract.
|
|
76
|
+
*
|
|
77
|
+
* Flow:
|
|
78
|
+
* 1. Validates request (schema validation happens at plugin boundary)
|
|
79
|
+
* 2. Makes API call to /authentications/{id}/ with custom error handler
|
|
80
|
+
* 3. Transforms response to normalized AuthenticationItem
|
|
81
|
+
* 4. Returns wrapped in { data } envelope
|
|
82
|
+
*
|
|
83
|
+
* Error handling:
|
|
84
|
+
* - 401: Authentication error (invalid/expired token)
|
|
85
|
+
* - 403: Forbidden (insufficient scopes)
|
|
86
|
+
* - 404: Authentication not found
|
|
87
|
+
* - Other: Propagates original error
|
|
88
|
+
*
|
|
89
|
+
* @param request - The authentication ID to retrieve
|
|
90
|
+
* @param deps - Dependencies injected by the caller (httpClient)
|
|
91
|
+
* @returns Single authentication item wrapped in data envelope
|
|
92
|
+
*/
|
|
93
|
+
export declare const handleGetAuthentication: Handler<GetAuthenticationHandlerRequest, GetAuthenticationResponse, GetAuthenticationHandlerDeps>;
|
|
94
|
+
//# sourceMappingURL=getAuthentication.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getAuthentication.d.ts","sourceRoot":"","sources":["../../../src/temporary-internal-core/handlers/getAuthentication.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACrD,OAAO,EAEL,KAAK,+BAA+B,EACpC,KAAK,yBAAyB,EAE/B,MAAM,4BAA4B,CAAC;AAOpC;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,WAAW,UAAU;IACzB,GAAG,CAAC,CAAC,GAAG,OAAO,EACb,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE;QACR,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACtC,YAAY,CAAC,EAAE,OAAO,CAAC;QACvB,kBAAkB,CAAC,EAAE,CAAC,SAAS,EAAE;YAC/B,MAAM,EAAE,MAAM,CAAC;YACf,UAAU,EAAE,MAAM,CAAC;YACnB,IAAI,EAAE,OAAO,CAAC;SACf,KAAK,KAAK,GAAG,SAAS,CAAC;KACzB,GACA,OAAO,CAAC,CAAC,CAAC,CAAC;IAEd,IAAI,CAAC,CAAC,GAAG,OAAO,EACd,IAAI,EAAE,MAAM,EACZ,IAAI,CAAC,EAAE,OAAO,EACd,OAAO,CAAC,EAAE;QACR,YAAY,CAAC,EAAE,OAAO,CAAC;QACvB,kBAAkB,CAAC,EAAE,CAAC,SAAS,EAAE;YAC/B,MAAM,EAAE,MAAM,CAAC;YACf,UAAU,EAAE,MAAM,CAAC;YACnB,IAAI,EAAE,OAAO,CAAC;SACf,KAAK,KAAK,GAAG,SAAS,CAAC;KACzB,GACA,OAAO,CAAC,CAAC,CAAC,CAAC;IAEd,MAAM,CAAC,CAAC,GAAG,OAAO,EAChB,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE;QACR,YAAY,CAAC,EAAE,OAAO,CAAC;QACvB,kBAAkB,CAAC,EAAE,CAAC,SAAS,EAAE;YAC/B,MAAM,EAAE,MAAM,CAAC;YACf,UAAU,EAAE,MAAM,CAAC;YACnB,IAAI,EAAE,OAAO,CAAC;SACf,KAAK,KAAK,GAAG,SAAS,CAAC;KACzB,GACA,OAAO,CAAC,CAAC,CAAC,CAAC;CACf;AAED;;;;;;;;;;GAUG;AACH,MAAM,WAAW,4BAA6B,SAAQ,WAAW;IAC/D,UAAU,EAAE,UAAU,CAAC;CACxB;AAMD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,uBAAuB,EAAE,OAAO,CAC3C,+BAA+B,EAC/B,yBAAyB,EACzB,4BAA4B,CA8C7B,CAAC"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Handler for getAuthentication operation
|
|
3
|
+
*
|
|
4
|
+
* This handler will become an SDK API endpoint handler.
|
|
5
|
+
* It encapsulates the business logic for retrieving a single authentication, including:
|
|
6
|
+
* - API call to internal authentication endpoint
|
|
7
|
+
* - Custom error handling (401, 403, 404)
|
|
8
|
+
* - Response transformation (field renaming, computed fields)
|
|
9
|
+
*
|
|
10
|
+
* The handler receives a validated authentication ID and returns normalized data.
|
|
11
|
+
*/
|
|
12
|
+
import { GetAuthenticationHandlerRequestSchema, } from "../schemas/authentications";
|
|
13
|
+
import { ZapierAuthenticationError, ZapierResourceNotFoundError, } from "../schemas/errors";
|
|
14
|
+
import { normalizeAuthenticationItem } from "../utils/transformations";
|
|
15
|
+
// ============================================================================
|
|
16
|
+
// Handler Implementation
|
|
17
|
+
// ============================================================================
|
|
18
|
+
/**
|
|
19
|
+
* Handles getAuthentication operation
|
|
20
|
+
*
|
|
21
|
+
* Conforms to the Handler<TRequest, TResponse, TDeps> interface contract.
|
|
22
|
+
*
|
|
23
|
+
* Flow:
|
|
24
|
+
* 1. Validates request (schema validation happens at plugin boundary)
|
|
25
|
+
* 2. Makes API call to /authentications/{id}/ with custom error handler
|
|
26
|
+
* 3. Transforms response to normalized AuthenticationItem
|
|
27
|
+
* 4. Returns wrapped in { data } envelope
|
|
28
|
+
*
|
|
29
|
+
* Error handling:
|
|
30
|
+
* - 401: Authentication error (invalid/expired token)
|
|
31
|
+
* - 403: Forbidden (insufficient scopes)
|
|
32
|
+
* - 404: Authentication not found
|
|
33
|
+
* - Other: Propagates original error
|
|
34
|
+
*
|
|
35
|
+
* @param request - The authentication ID to retrieve
|
|
36
|
+
* @param deps - Dependencies injected by the caller (httpClient)
|
|
37
|
+
* @returns Single authentication item wrapped in data envelope
|
|
38
|
+
*/
|
|
39
|
+
export const handleGetAuthentication = async ({ request, deps }) => {
|
|
40
|
+
// Validate and normalize request at handler boundary
|
|
41
|
+
const validatedRequest = GetAuthenticationHandlerRequestSchema.parse(request);
|
|
42
|
+
const { httpClient } = deps;
|
|
43
|
+
const { authenticationId } = validatedRequest;
|
|
44
|
+
// Make API call with custom error handling
|
|
45
|
+
const authentication = await httpClient.get(`/zapier/api/v4/authentications/${authenticationId}/`, {
|
|
46
|
+
authRequired: true,
|
|
47
|
+
customErrorHandler: ({ status }) => {
|
|
48
|
+
if (status === 401) {
|
|
49
|
+
return new ZapierAuthenticationError(`Authentication failed. Your token may not have permission to access authentications or may be expired. (HTTP ${status})`, { statusCode: status });
|
|
50
|
+
}
|
|
51
|
+
if (status === 403) {
|
|
52
|
+
return new ZapierAuthenticationError(`Access forbidden. Your token may not have the required scopes to get authentication ${authenticationId}. (HTTP ${status})`, { statusCode: status });
|
|
53
|
+
}
|
|
54
|
+
if (status === 404) {
|
|
55
|
+
return new ZapierResourceNotFoundError(`Authentication ${authenticationId} not found. It may not exist or you may not have access to it. (HTTP ${status})`, {
|
|
56
|
+
resourceType: "Authentication",
|
|
57
|
+
resourceId: String(authenticationId),
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
return undefined; // Let default error handling take over
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
// Transform to normalized AuthenticationItem
|
|
64
|
+
const normalizedAuthentication = normalizeAuthenticationItem(authentication);
|
|
65
|
+
return {
|
|
66
|
+
data: normalizedAuthentication,
|
|
67
|
+
};
|
|
68
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getAuthentication.test.d.ts","sourceRoot":"","sources":["../../../src/temporary-internal-core/handlers/getAuthentication.test.ts"],"names":[],"mappings":""}
|