@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.
- package/CHANGELOG.md +7 -0
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +7 -2
- package/src/api/auth.ts +0 -28
- package/src/api/client.ts +0 -491
- package/src/api/debug.test.ts +0 -76
- package/src/api/debug.ts +0 -154
- package/src/api/index.ts +0 -90
- package/src/api/polling.test.ts +0 -405
- package/src/api/polling.ts +0 -253
- package/src/api/schemas.ts +0 -465
- package/src/api/types.ts +0 -152
- package/src/auth.ts +0 -72
- package/src/constants.ts +0 -16
- package/src/index.ts +0 -111
- package/src/plugins/api/index.ts +0 -43
- package/src/plugins/apps/index.ts +0 -203
- package/src/plugins/apps/schemas.ts +0 -64
- package/src/plugins/eventEmission/builders.ts +0 -115
- package/src/plugins/eventEmission/index.test.ts +0 -169
- package/src/plugins/eventEmission/index.ts +0 -294
- package/src/plugins/eventEmission/transport.test.ts +0 -214
- package/src/plugins/eventEmission/transport.ts +0 -135
- package/src/plugins/eventEmission/types.ts +0 -58
- package/src/plugins/eventEmission/utils.ts +0 -121
- package/src/plugins/fetch/index.ts +0 -83
- package/src/plugins/fetch/schemas.ts +0 -37
- package/src/plugins/findFirstAuthentication/index.test.ts +0 -209
- package/src/plugins/findFirstAuthentication/index.ts +0 -68
- package/src/plugins/findFirstAuthentication/schemas.ts +0 -47
- package/src/plugins/findUniqueAuthentication/index.test.ts +0 -197
- package/src/plugins/findUniqueAuthentication/index.ts +0 -77
- package/src/plugins/findUniqueAuthentication/schemas.ts +0 -49
- package/src/plugins/getAction/index.test.ts +0 -239
- package/src/plugins/getAction/index.ts +0 -75
- package/src/plugins/getAction/schemas.ts +0 -41
- package/src/plugins/getApp/index.test.ts +0 -181
- package/src/plugins/getApp/index.ts +0 -60
- package/src/plugins/getApp/schemas.ts +0 -33
- package/src/plugins/getAuthentication/index.test.ts +0 -294
- package/src/plugins/getAuthentication/index.ts +0 -95
- package/src/plugins/getAuthentication/schemas.ts +0 -38
- package/src/plugins/getProfile/index.ts +0 -60
- package/src/plugins/getProfile/schemas.ts +0 -24
- package/src/plugins/listActions/index.test.ts +0 -526
- package/src/plugins/listActions/index.ts +0 -132
- package/src/plugins/listActions/schemas.ts +0 -55
- package/src/plugins/listApps/index.test.ts +0 -378
- package/src/plugins/listApps/index.ts +0 -159
- package/src/plugins/listApps/schemas.ts +0 -41
- package/src/plugins/listAuthentications/index.test.ts +0 -739
- package/src/plugins/listAuthentications/index.ts +0 -152
- package/src/plugins/listAuthentications/schemas.ts +0 -77
- package/src/plugins/listInputFieldChoices/index.test.ts +0 -653
- package/src/plugins/listInputFieldChoices/index.ts +0 -173
- package/src/plugins/listInputFieldChoices/schemas.ts +0 -125
- package/src/plugins/listInputFields/index.test.ts +0 -439
- package/src/plugins/listInputFields/index.ts +0 -294
- package/src/plugins/listInputFields/schemas.ts +0 -68
- package/src/plugins/manifest/index.test.ts +0 -776
- package/src/plugins/manifest/index.ts +0 -461
- package/src/plugins/manifest/schemas.ts +0 -60
- package/src/plugins/registry/index.ts +0 -160
- package/src/plugins/request/index.test.ts +0 -333
- package/src/plugins/request/index.ts +0 -105
- package/src/plugins/request/schemas.ts +0 -69
- package/src/plugins/runAction/index.test.ts +0 -388
- package/src/plugins/runAction/index.ts +0 -215
- package/src/plugins/runAction/schemas.ts +0 -60
- package/src/resolvers/actionKey.ts +0 -37
- package/src/resolvers/actionType.ts +0 -34
- package/src/resolvers/appKey.ts +0 -7
- package/src/resolvers/authenticationId.ts +0 -54
- package/src/resolvers/index.ts +0 -11
- package/src/resolvers/inputFieldKey.ts +0 -70
- package/src/resolvers/inputs.ts +0 -69
- package/src/schemas/Action.ts +0 -52
- package/src/schemas/App.ts +0 -45
- package/src/schemas/Auth.ts +0 -59
- package/src/schemas/Field.ts +0 -169
- package/src/schemas/Run.ts +0 -40
- package/src/schemas/UserProfile.ts +0 -60
- package/src/sdk.test.ts +0 -212
- package/src/sdk.ts +0 -178
- package/src/types/domain.test.ts +0 -50
- package/src/types/domain.ts +0 -66
- package/src/types/errors.ts +0 -278
- package/src/types/events.ts +0 -43
- package/src/types/functions.ts +0 -28
- package/src/types/optional-zapier-sdk-cli-login.d.ts +0 -37
- package/src/types/plugin.ts +0 -125
- package/src/types/properties.ts +0 -80
- package/src/types/sdk.ts +0 -111
- package/src/types/telemetry-events.ts +0 -85
- package/src/utils/array-utils.test.ts +0 -131
- package/src/utils/array-utils.ts +0 -41
- package/src/utils/domain-utils.test.ts +0 -433
- package/src/utils/domain-utils.ts +0 -267
- package/src/utils/file-utils.test.ts +0 -73
- package/src/utils/file-utils.ts +0 -94
- package/src/utils/function-utils.test.ts +0 -141
- package/src/utils/function-utils.ts +0 -245
- package/src/utils/pagination-utils.test.ts +0 -620
- package/src/utils/pagination-utils.ts +0 -242
- package/src/utils/schema-utils.ts +0 -207
- package/src/utils/string-utils.test.ts +0 -45
- package/src/utils/string-utils.ts +0 -54
- package/src/utils/validation.test.ts +0 -51
- package/src/utils/validation.ts +0 -44
- package/tsconfig.build.json +0 -18
- package/tsconfig.json +0 -20
- package/tsconfig.tsbuildinfo +0 -1
- package/tsup.config.ts +0 -23
|
@@ -1,294 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
2
|
-
import {
|
|
3
|
-
ZapierValidationError,
|
|
4
|
-
ZapierAuthenticationError,
|
|
5
|
-
ZapierResourceNotFoundError,
|
|
6
|
-
} from "../../types/errors";
|
|
7
|
-
import { getAuthenticationPlugin } from "./index";
|
|
8
|
-
import { createSdk } from "../../sdk";
|
|
9
|
-
import type { ApiClient } from "../../api";
|
|
10
|
-
import type { GetAuthenticationOptions } from "./schemas";
|
|
11
|
-
import type { Authentication } from "../../api/types";
|
|
12
|
-
import { manifestPlugin } from "../manifest";
|
|
13
|
-
import { listAppsPlugin } from "../listApps";
|
|
14
|
-
|
|
15
|
-
const mockAuthenticationResponse: Authentication = {
|
|
16
|
-
id: 123,
|
|
17
|
-
date: "2021-01-01",
|
|
18
|
-
account_id: 456 as any,
|
|
19
|
-
selected_api: "SlackCLIAPI@1.21.1",
|
|
20
|
-
is_invite_only: false,
|
|
21
|
-
is_private: false,
|
|
22
|
-
shared_with_all: false,
|
|
23
|
-
is_stale: "false",
|
|
24
|
-
marked_stale_at: null,
|
|
25
|
-
label: "My Slack Workspace",
|
|
26
|
-
title: "My Slack Workspace",
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
describe("getAuthentication plugin", () => {
|
|
30
|
-
let mockApiClient: ApiClient;
|
|
31
|
-
|
|
32
|
-
beforeEach(() => {
|
|
33
|
-
vi.clearAllMocks();
|
|
34
|
-
mockApiClient = {
|
|
35
|
-
get: vi.fn().mockResolvedValue(mockAuthenticationResponse),
|
|
36
|
-
} as Partial<ApiClient> as ApiClient;
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
const apiPlugin = () => ({
|
|
40
|
-
context: {
|
|
41
|
-
api: mockApiClient,
|
|
42
|
-
},
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
function createTestSdk() {
|
|
46
|
-
return createSdk()
|
|
47
|
-
.addPlugin(apiPlugin)
|
|
48
|
-
.addPlugin(manifestPlugin)
|
|
49
|
-
.addPlugin(listAppsPlugin)
|
|
50
|
-
.addPlugin(getAuthenticationPlugin);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
describe("schema validation", () => {
|
|
54
|
-
it("should throw validation error for missing authenticationId", async () => {
|
|
55
|
-
const sdk = createTestSdk();
|
|
56
|
-
await expect(
|
|
57
|
-
sdk.getAuthentication({} as GetAuthenticationOptions),
|
|
58
|
-
).rejects.toThrow(ZapierValidationError);
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it("should throw validation error for invalid authenticationId type", async () => {
|
|
62
|
-
const sdk = createTestSdk();
|
|
63
|
-
await expect(
|
|
64
|
-
sdk.getAuthentication({
|
|
65
|
-
authenticationId: "invalid" as any,
|
|
66
|
-
}),
|
|
67
|
-
).rejects.toThrow(ZapierValidationError);
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
it("should throw validation error for negative authenticationId", async () => {
|
|
71
|
-
const sdk = createTestSdk();
|
|
72
|
-
await expect(
|
|
73
|
-
sdk.getAuthentication({
|
|
74
|
-
authenticationId: -1,
|
|
75
|
-
}),
|
|
76
|
-
).rejects.toThrow(ZapierValidationError);
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
it("should throw validation error for zero authenticationId", async () => {
|
|
80
|
-
const sdk = createTestSdk();
|
|
81
|
-
await expect(
|
|
82
|
-
sdk.getAuthentication({
|
|
83
|
-
authenticationId: 0,
|
|
84
|
-
}),
|
|
85
|
-
).rejects.toThrow(ZapierValidationError);
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
it("should pass validation with valid authenticationId", async () => {
|
|
89
|
-
const sdk = createTestSdk();
|
|
90
|
-
const result = await sdk.getAuthentication({
|
|
91
|
-
authenticationId: 123,
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
expect(result.data).toBeDefined();
|
|
95
|
-
});
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
describe("API integration", () => {
|
|
99
|
-
it("should call the correct API endpoint", async () => {
|
|
100
|
-
const sdk = createTestSdk();
|
|
101
|
-
await sdk.getAuthentication({ authenticationId: 123 });
|
|
102
|
-
|
|
103
|
-
expect(mockApiClient.get).toHaveBeenCalledWith(
|
|
104
|
-
"/api/v4/authentications/123/",
|
|
105
|
-
expect.objectContaining({
|
|
106
|
-
authRequired: true,
|
|
107
|
-
customErrorHandler: expect.any(Function),
|
|
108
|
-
}),
|
|
109
|
-
);
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
it("should return normalized authentication data", async () => {
|
|
113
|
-
const sdk = createTestSdk();
|
|
114
|
-
const result = await sdk.getAuthentication({ authenticationId: 123 });
|
|
115
|
-
|
|
116
|
-
expect(result.data).toEqual({
|
|
117
|
-
id: 123,
|
|
118
|
-
date: "2021-01-01",
|
|
119
|
-
account_id: 456 as any,
|
|
120
|
-
implementation_id: "SlackCLIAPI@1.21.1",
|
|
121
|
-
is_invite_only: false,
|
|
122
|
-
is_private: false,
|
|
123
|
-
shared_with_all: false,
|
|
124
|
-
is_expired: "false",
|
|
125
|
-
expired_at: null,
|
|
126
|
-
label: "My Slack Workspace",
|
|
127
|
-
title: "My Slack Workspace",
|
|
128
|
-
app_key: "SlackCLIAPI",
|
|
129
|
-
app_version: "1.21.1",
|
|
130
|
-
user_id: undefined, // customuser_id wasn't in mock data
|
|
131
|
-
is_stale: "false", // Original field preserved
|
|
132
|
-
marked_stale_at: null, // Original field preserved
|
|
133
|
-
});
|
|
134
|
-
});
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
describe("error handling", () => {
|
|
138
|
-
it("should throw ZapierAuthenticationError for 401 responses", async () => {
|
|
139
|
-
const customErrorHandler = vi
|
|
140
|
-
.fn()
|
|
141
|
-
.mockReturnValue(
|
|
142
|
-
new ZapierAuthenticationError(
|
|
143
|
-
"Authentication failed. Your token may not have permission to access authentications or may be expired. (HTTP 401)",
|
|
144
|
-
{ statusCode: 401 },
|
|
145
|
-
),
|
|
146
|
-
);
|
|
147
|
-
|
|
148
|
-
mockApiClient.get = vi.fn().mockImplementation(() => {
|
|
149
|
-
const error = customErrorHandler({ status: 401 });
|
|
150
|
-
throw error;
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
const sdk = createTestSdk();
|
|
154
|
-
await expect(
|
|
155
|
-
sdk.getAuthentication({ authenticationId: 123 }),
|
|
156
|
-
).rejects.toThrow(ZapierAuthenticationError);
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
it("should throw ZapierAuthenticationError for 403 responses", async () => {
|
|
160
|
-
const customErrorHandler = vi
|
|
161
|
-
.fn()
|
|
162
|
-
.mockReturnValue(
|
|
163
|
-
new ZapierAuthenticationError(
|
|
164
|
-
"Access forbidden. Your token may not have the required scopes to get authentication 123. (HTTP 403)",
|
|
165
|
-
{ statusCode: 403 },
|
|
166
|
-
),
|
|
167
|
-
);
|
|
168
|
-
|
|
169
|
-
mockApiClient.get = vi.fn().mockImplementation(() => {
|
|
170
|
-
const error = customErrorHandler({ status: 403 });
|
|
171
|
-
throw error;
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
const sdk = createTestSdk();
|
|
175
|
-
await expect(
|
|
176
|
-
sdk.getAuthentication({ authenticationId: 123 }),
|
|
177
|
-
).rejects.toThrow(ZapierAuthenticationError);
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
it("should throw ZapierResourceNotFoundError for 404 responses", async () => {
|
|
181
|
-
const customErrorHandler = vi.fn().mockReturnValue(
|
|
182
|
-
new ZapierResourceNotFoundError(
|
|
183
|
-
"Authentication 123 not found. It may not exist or you may not have access to it. (HTTP 404)",
|
|
184
|
-
{
|
|
185
|
-
resourceType: "Authentication",
|
|
186
|
-
resourceId: "123",
|
|
187
|
-
},
|
|
188
|
-
),
|
|
189
|
-
);
|
|
190
|
-
|
|
191
|
-
mockApiClient.get = vi.fn().mockImplementation(() => {
|
|
192
|
-
const error = customErrorHandler({ status: 404 });
|
|
193
|
-
throw error;
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
const sdk = createTestSdk();
|
|
197
|
-
await expect(
|
|
198
|
-
sdk.getAuthentication({ authenticationId: 123 }),
|
|
199
|
-
).rejects.toThrow(ZapierResourceNotFoundError);
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
it("should handle network errors", async () => {
|
|
203
|
-
mockApiClient.get = vi.fn().mockRejectedValue(new Error("Network error"));
|
|
204
|
-
|
|
205
|
-
const sdk = createTestSdk();
|
|
206
|
-
await expect(
|
|
207
|
-
sdk.getAuthentication({ authenticationId: 123 }),
|
|
208
|
-
).rejects.toThrow("Network error");
|
|
209
|
-
});
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
describe("data transformation", () => {
|
|
213
|
-
it("should map is_stale to is_expired and marked_stale_at to expired_at", async () => {
|
|
214
|
-
const authWithExpiration = {
|
|
215
|
-
...mockAuthenticationResponse,
|
|
216
|
-
is_stale: "true",
|
|
217
|
-
marked_stale_at: "2021-06-01",
|
|
218
|
-
};
|
|
219
|
-
|
|
220
|
-
mockApiClient.get = vi.fn().mockResolvedValue(authWithExpiration);
|
|
221
|
-
|
|
222
|
-
const sdk = createTestSdk();
|
|
223
|
-
const result = await sdk.getAuthentication({ authenticationId: 123 });
|
|
224
|
-
|
|
225
|
-
expect(result.data.is_expired).toBe("true");
|
|
226
|
-
expect(result.data.expired_at).toBe("2021-06-01");
|
|
227
|
-
});
|
|
228
|
-
|
|
229
|
-
it("should preserve all original authentication fields", async () => {
|
|
230
|
-
const authWithAllFields = {
|
|
231
|
-
id: 123,
|
|
232
|
-
date: "2021-01-01",
|
|
233
|
-
lastchanged: "2021-01-02",
|
|
234
|
-
account_id: 456 as any,
|
|
235
|
-
customuser_id: 789,
|
|
236
|
-
selected_api: "SlackCLIAPI@1.21.1",
|
|
237
|
-
destination_selected_api: "SlackDestAPI@1.0.0",
|
|
238
|
-
is_invite_only: true,
|
|
239
|
-
is_private: true,
|
|
240
|
-
shared_with_all: false,
|
|
241
|
-
is_stale: "true",
|
|
242
|
-
is_shared: "false",
|
|
243
|
-
marked_stale_at: "2021-06-01",
|
|
244
|
-
label: "Auth Label",
|
|
245
|
-
title: "Auth Title",
|
|
246
|
-
identifier: "auth-identifier",
|
|
247
|
-
url: "https://example.com",
|
|
248
|
-
groups: "group1,group2",
|
|
249
|
-
members: "user1,user2",
|
|
250
|
-
permissions: { read: true, write: false },
|
|
251
|
-
};
|
|
252
|
-
|
|
253
|
-
mockApiClient.get = vi.fn().mockResolvedValue(authWithAllFields);
|
|
254
|
-
|
|
255
|
-
const sdk = createTestSdk();
|
|
256
|
-
const result = await sdk.getAuthentication({ authenticationId: 123 });
|
|
257
|
-
const auth = result.data;
|
|
258
|
-
|
|
259
|
-
// Verify original fields are preserved
|
|
260
|
-
expect(auth.id).toBe(123);
|
|
261
|
-
expect(auth.date).toBe("2021-01-01");
|
|
262
|
-
expect(auth.lastchanged).toBe("2021-01-02");
|
|
263
|
-
expect(auth.account_id).toBe(456);
|
|
264
|
-
expect(auth.user_id).toBe(789);
|
|
265
|
-
expect(auth.implementation_id).toBe("SlackCLIAPI@1.21.1");
|
|
266
|
-
expect(auth.destination_selected_api).toBe("SlackDestAPI@1.0.0");
|
|
267
|
-
expect(auth.is_invite_only).toBe(true);
|
|
268
|
-
expect(auth.is_private).toBe(true);
|
|
269
|
-
expect(auth.shared_with_all).toBe(false);
|
|
270
|
-
expect(auth.is_shared).toBe("false");
|
|
271
|
-
expect(auth.label).toBe("Auth Label");
|
|
272
|
-
expect(auth.title).toBe("Auth Title");
|
|
273
|
-
expect(auth.identifier).toBe("auth-identifier");
|
|
274
|
-
expect(auth.url).toBe("https://example.com");
|
|
275
|
-
expect(auth.groups).toBe("group1,group2");
|
|
276
|
-
expect(auth.members).toBe("user1,user2");
|
|
277
|
-
expect(auth.permissions).toEqual({ read: true, write: false });
|
|
278
|
-
|
|
279
|
-
// Verify mapped fields
|
|
280
|
-
expect(auth.is_expired).toBe("true");
|
|
281
|
-
expect(auth.expired_at).toBe("2021-06-01");
|
|
282
|
-
});
|
|
283
|
-
});
|
|
284
|
-
|
|
285
|
-
describe("context and metadata", () => {
|
|
286
|
-
it("should provide context with meta information", () => {
|
|
287
|
-
const sdk = createTestSdk();
|
|
288
|
-
const context = sdk.getContext();
|
|
289
|
-
|
|
290
|
-
expect((context.meta as any).getAuthentication).toBeDefined();
|
|
291
|
-
expect((context.meta as any).getAuthentication.inputSchema).toBeDefined();
|
|
292
|
-
});
|
|
293
|
-
});
|
|
294
|
-
});
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import type { Plugin } from "../../types/plugin";
|
|
2
|
-
import type { ApiClient } from "../../api";
|
|
3
|
-
import type { Authentication } from "../../api/types";
|
|
4
|
-
import type { AuthenticationItem } from "../../types/domain";
|
|
5
|
-
import {
|
|
6
|
-
GetAuthenticationSchema,
|
|
7
|
-
type GetAuthenticationOptions,
|
|
8
|
-
} from "./schemas";
|
|
9
|
-
import {
|
|
10
|
-
ZapierAuthenticationError,
|
|
11
|
-
ZapierResourceNotFoundError,
|
|
12
|
-
} from "../../types/errors";
|
|
13
|
-
import { createFunction } from "../../utils/function-utils";
|
|
14
|
-
import { normalizeAuthenticationItem } from "../../utils/domain-utils";
|
|
15
|
-
import { authenticationIdGenericResolver } from "../../resolvers";
|
|
16
|
-
import { AuthenticationItemSchema } from "../../schemas/Auth";
|
|
17
|
-
|
|
18
|
-
export interface GetAuthenticationPluginProvides {
|
|
19
|
-
getAuthentication: (
|
|
20
|
-
options: GetAuthenticationOptions,
|
|
21
|
-
) => Promise<{ data: AuthenticationItem }>;
|
|
22
|
-
context: {
|
|
23
|
-
meta: {
|
|
24
|
-
getAuthentication: {
|
|
25
|
-
inputSchema: typeof GetAuthenticationSchema;
|
|
26
|
-
};
|
|
27
|
-
};
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export const getAuthenticationPlugin: Plugin<
|
|
32
|
-
{}, // no SDK dependencies
|
|
33
|
-
{ api: ApiClient }, // requires api in context
|
|
34
|
-
GetAuthenticationPluginProvides
|
|
35
|
-
> = ({ context }) => {
|
|
36
|
-
const getAuthentication = createFunction(async function getAuthentication(
|
|
37
|
-
options: GetAuthenticationOptions,
|
|
38
|
-
) {
|
|
39
|
-
const { api } = context;
|
|
40
|
-
const { authenticationId } = options;
|
|
41
|
-
|
|
42
|
-
const data: Authentication = await api.get(
|
|
43
|
-
`/api/v4/authentications/${authenticationId}/`,
|
|
44
|
-
{
|
|
45
|
-
customErrorHandler: ({ status }: { status: number }) => {
|
|
46
|
-
if (status === 401) {
|
|
47
|
-
return new ZapierAuthenticationError(
|
|
48
|
-
`Authentication failed. Your token may not have permission to access authentications or may be expired. (HTTP ${status})`,
|
|
49
|
-
{ statusCode: status },
|
|
50
|
-
);
|
|
51
|
-
}
|
|
52
|
-
if (status === 403) {
|
|
53
|
-
return new ZapierAuthenticationError(
|
|
54
|
-
`Access forbidden. Your token may not have the required scopes to get authentication ${authenticationId}. (HTTP ${status})`,
|
|
55
|
-
{ statusCode: status },
|
|
56
|
-
);
|
|
57
|
-
}
|
|
58
|
-
if (status === 404) {
|
|
59
|
-
return new ZapierResourceNotFoundError(
|
|
60
|
-
`Authentication ${authenticationId} not found. It may not exist or you may not have access to it. (HTTP ${status})`,
|
|
61
|
-
{
|
|
62
|
-
resourceType: "Authentication",
|
|
63
|
-
resourceId: String(authenticationId),
|
|
64
|
-
},
|
|
65
|
-
);
|
|
66
|
-
}
|
|
67
|
-
return undefined;
|
|
68
|
-
},
|
|
69
|
-
authRequired: true,
|
|
70
|
-
},
|
|
71
|
-
);
|
|
72
|
-
|
|
73
|
-
return {
|
|
74
|
-
data: normalizeAuthenticationItem(data),
|
|
75
|
-
};
|
|
76
|
-
}, GetAuthenticationSchema);
|
|
77
|
-
|
|
78
|
-
return {
|
|
79
|
-
getAuthentication,
|
|
80
|
-
context: {
|
|
81
|
-
meta: {
|
|
82
|
-
getAuthentication: {
|
|
83
|
-
categories: ["authentication"],
|
|
84
|
-
type: "item",
|
|
85
|
-
itemType: "Authentication",
|
|
86
|
-
inputSchema: GetAuthenticationSchema,
|
|
87
|
-
outputSchema: AuthenticationItemSchema,
|
|
88
|
-
resolvers: {
|
|
89
|
-
authenticationId: authenticationIdGenericResolver,
|
|
90
|
-
},
|
|
91
|
-
},
|
|
92
|
-
},
|
|
93
|
-
},
|
|
94
|
-
};
|
|
95
|
-
};
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
import type { AuthenticationItem } from "../../types/domain";
|
|
3
|
-
import type {
|
|
4
|
-
ZapierAuthenticationError,
|
|
5
|
-
ZapierResourceNotFoundError,
|
|
6
|
-
ZapierApiError,
|
|
7
|
-
ZapierValidationError,
|
|
8
|
-
ZapierUnknownError,
|
|
9
|
-
} from "../../types/errors";
|
|
10
|
-
|
|
11
|
-
// Pure Zod schema - no resolver metadata!
|
|
12
|
-
export const GetAuthenticationSchema = z
|
|
13
|
-
.object({
|
|
14
|
-
authenticationId: z
|
|
15
|
-
.number()
|
|
16
|
-
.int()
|
|
17
|
-
.positive()
|
|
18
|
-
.describe("Authentication ID to retrieve"),
|
|
19
|
-
})
|
|
20
|
-
.describe("Get a specific authentication by ID");
|
|
21
|
-
|
|
22
|
-
// Type inferred from schema
|
|
23
|
-
export type GetAuthenticationOptions = z.infer<typeof GetAuthenticationSchema>;
|
|
24
|
-
|
|
25
|
-
// Error union for this function
|
|
26
|
-
export type GetAuthenticationError =
|
|
27
|
-
| ZapierAuthenticationError
|
|
28
|
-
| ZapierResourceNotFoundError
|
|
29
|
-
| ZapierApiError
|
|
30
|
-
| ZapierValidationError
|
|
31
|
-
| ZapierUnknownError;
|
|
32
|
-
|
|
33
|
-
// SDK function interface - ready to be mixed into main SDK interface
|
|
34
|
-
export interface GetAuthenticationSdkFunction {
|
|
35
|
-
getAuthentication: (
|
|
36
|
-
options: GetAuthenticationOptions,
|
|
37
|
-
) => Promise<{ data: AuthenticationItem }>;
|
|
38
|
-
}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import type { GetProfileOptions } from "./schemas";
|
|
2
|
-
import type { UserProfile, ApiClient } from "../../api/types";
|
|
3
|
-
import { createFunction } from "../../utils/function-utils";
|
|
4
|
-
import type { Plugin } from "../../types/plugin";
|
|
5
|
-
import type { UserProfileItem } from "../../types/domain";
|
|
6
|
-
import { GetProfileSchema } from "./schemas";
|
|
7
|
-
import { UserProfileItemSchema } from "../../schemas/UserProfile";
|
|
8
|
-
|
|
9
|
-
// GetProfile plugin provides interface - getProfile goes directly to SDK root
|
|
10
|
-
export interface GetProfilePluginProvides {
|
|
11
|
-
getProfile: (
|
|
12
|
-
options?: GetProfileOptions,
|
|
13
|
-
) => Promise<{ data: UserProfileItem }>;
|
|
14
|
-
context: {
|
|
15
|
-
meta: {
|
|
16
|
-
getProfile: {
|
|
17
|
-
inputSchema: typeof GetProfileSchema;
|
|
18
|
-
};
|
|
19
|
-
};
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
// Direct plugin function - takes options + sdk + context in one object
|
|
24
|
-
export const getProfilePlugin: Plugin<
|
|
25
|
-
{}, // no SDK dependencies
|
|
26
|
-
{ api: ApiClient }, // requires api in context
|
|
27
|
-
GetProfilePluginProvides
|
|
28
|
-
> = ({ context }) => {
|
|
29
|
-
const getProfile = createFunction(async function getProfile() {
|
|
30
|
-
const profile: UserProfile = await context.api.get("/api/v4/profile/", {
|
|
31
|
-
authRequired: true,
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
// Remove user_id since that's our internal user ID which could confuse things!
|
|
35
|
-
const { user_id: _unusedUserId, ...data } = profile;
|
|
36
|
-
|
|
37
|
-
return {
|
|
38
|
-
data: {
|
|
39
|
-
...data, // Pass through all API response fields
|
|
40
|
-
full_name: `${profile.first_name} ${profile.last_name}`, // Computed field
|
|
41
|
-
},
|
|
42
|
-
};
|
|
43
|
-
}, GetProfileSchema);
|
|
44
|
-
|
|
45
|
-
// Return flat structure - getProfile goes directly to SDK
|
|
46
|
-
return {
|
|
47
|
-
getProfile,
|
|
48
|
-
context: {
|
|
49
|
-
meta: {
|
|
50
|
-
getProfile: {
|
|
51
|
-
categories: ["account"],
|
|
52
|
-
type: "item",
|
|
53
|
-
itemType: "Profile",
|
|
54
|
-
inputSchema: GetProfileSchema,
|
|
55
|
-
outputSchema: UserProfileItemSchema,
|
|
56
|
-
},
|
|
57
|
-
},
|
|
58
|
-
},
|
|
59
|
-
};
|
|
60
|
-
};
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
import type { FunctionOptions } from "../../types/functions";
|
|
3
|
-
import type { UserProfileItem } from "../../types/domain";
|
|
4
|
-
import type { ZapierApiError, ZapierValidationError } from "../../types/errors";
|
|
5
|
-
|
|
6
|
-
// Union of all possible errors for getProfile
|
|
7
|
-
export type GetProfileError = ZapierApiError | ZapierValidationError;
|
|
8
|
-
|
|
9
|
-
// Pure Zod schema - no resolver metadata!
|
|
10
|
-
export const GetProfileSchema = z
|
|
11
|
-
.object({})
|
|
12
|
-
.optional()
|
|
13
|
-
.describe("Get current user's profile information");
|
|
14
|
-
|
|
15
|
-
// Type inferred from schema + function config
|
|
16
|
-
export type GetProfileOptions = z.infer<typeof GetProfileSchema> &
|
|
17
|
-
FunctionOptions;
|
|
18
|
-
|
|
19
|
-
// SDK function interface - ready to be mixed into main SDK interface
|
|
20
|
-
export interface GetProfileSdkFunction {
|
|
21
|
-
getProfile: (
|
|
22
|
-
options?: GetProfileOptions,
|
|
23
|
-
) => Promise<{ data: UserProfileItem }>;
|
|
24
|
-
}
|