@zapier/zapier-sdk 0.15.1 → 0.15.2
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 +6 -0
- package/dist/api/client.d.ts.map +1 -1
- package/dist/api/client.integration.test.d.ts +5 -0
- package/dist/api/client.integration.test.d.ts.map +1 -0
- package/dist/api/client.integration.test.js +318 -0
- package/dist/api/client.js +31 -1
- package/dist/index.cjs +304 -104
- package/dist/index.d.mts +243 -31
- package/dist/index.mjs +304 -104
- package/dist/plugins/getApp/index.test.js +17 -21
- package/dist/plugins/listActions/schemas.d.ts +4 -4
- package/dist/plugins/listApps/index.d.ts +1 -3
- package/dist/plugins/listApps/index.d.ts.map +1 -1
- package/dist/plugins/listApps/index.js +18 -44
- package/dist/plugins/listApps/index.test.js +89 -288
- package/dist/plugins/listApps/schemas.d.ts +19 -26
- package/dist/plugins/listApps/schemas.d.ts.map +1 -1
- package/dist/plugins/listApps/schemas.js +19 -18
- package/dist/plugins/listAuthentications/schemas.d.ts +4 -4
- package/dist/plugins/listInputFieldChoices/schemas.d.ts +4 -4
- package/dist/plugins/listInputFields/schemas.d.ts +4 -4
- package/dist/plugins/runAction/schemas.d.ts +4 -4
- package/dist/sdk.d.ts +1 -1
- package/dist/temporary-internal-core/handlers/listApps.d.ts +67 -0
- package/dist/temporary-internal-core/handlers/listApps.d.ts.map +1 -0
- package/dist/temporary-internal-core/handlers/listApps.js +121 -0
- package/dist/temporary-internal-core/handlers/listApps.test.d.ts +2 -0
- package/dist/temporary-internal-core/handlers/listApps.test.d.ts.map +1 -0
- package/dist/temporary-internal-core/handlers/listApps.test.js +328 -0
- package/dist/temporary-internal-core/index.d.ts +4 -0
- package/dist/temporary-internal-core/index.d.ts.map +1 -1
- package/dist/temporary-internal-core/index.js +5 -1
- package/dist/temporary-internal-core/schemas/apps/index.d.ts +582 -0
- package/dist/temporary-internal-core/schemas/apps/index.d.ts.map +1 -0
- package/dist/temporary-internal-core/schemas/apps/index.js +95 -0
- package/dist/temporary-internal-core/schemas/implementations/index.d.ts +511 -0
- package/dist/temporary-internal-core/schemas/implementations/index.d.ts.map +1 -0
- package/dist/temporary-internal-core/schemas/implementations/index.js +79 -0
- package/dist/temporary-internal-core/types/handler.d.ts +51 -0
- package/dist/temporary-internal-core/types/handler.d.ts.map +1 -0
- package/dist/temporary-internal-core/types/handler.js +8 -0
- package/dist/temporary-internal-core/types/index.d.ts +5 -0
- package/dist/temporary-internal-core/types/index.d.ts.map +1 -0
- package/dist/temporary-internal-core/types/index.js +4 -0
- package/dist/temporary-internal-core/utils/app-locators.d.ts +54 -0
- package/dist/temporary-internal-core/utils/app-locators.d.ts.map +1 -0
- package/dist/temporary-internal-core/utils/app-locators.js +83 -0
- package/dist/temporary-internal-core/utils/transformations.d.ts +18 -0
- package/dist/temporary-internal-core/utils/transformations.d.ts.map +1 -0
- package/dist/temporary-internal-core/utils/transformations.js +36 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/dist/api/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/api/client.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EACV,SAAS,EACT,gBAAgB,EAGjB,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/api/client.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EACV,SAAS,EACT,gBAAgB,EAGjB,MAAM,SAAS,CAAC;AA2hBjB,eAAO,MAAM,eAAe,GAAI,SAAS,gBAAgB,KAAG,SAW3D,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.integration.test.d.ts","sourceRoot":"","sources":["../../src/api/client.integration.test.ts"],"names":[],"mappings":"AAAA;;GAEG"}
|
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Integration tests for API client handler override mechanism
|
|
3
|
+
*/
|
|
4
|
+
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
5
|
+
import { createZapierApi } from "./client";
|
|
6
|
+
describe("Handler Override Mechanism Integration", () => {
|
|
7
|
+
let mockFetch;
|
|
8
|
+
beforeEach(() => {
|
|
9
|
+
mockFetch = vi.fn();
|
|
10
|
+
});
|
|
11
|
+
describe("listApps handler override", () => {
|
|
12
|
+
it("should invoke handler instead of making HTTP request to /api/v0/apps", async () => {
|
|
13
|
+
// Mock the nested API call that the handler makes
|
|
14
|
+
mockFetch.mockResolvedValueOnce({
|
|
15
|
+
ok: true,
|
|
16
|
+
status: 200,
|
|
17
|
+
json: async () => ({
|
|
18
|
+
results: [
|
|
19
|
+
{
|
|
20
|
+
api: "slack",
|
|
21
|
+
name: "Slack",
|
|
22
|
+
id: "SlackAPI@1.0.0",
|
|
23
|
+
logo_url: "https://example.com/slack.png",
|
|
24
|
+
categories: ["communication"],
|
|
25
|
+
},
|
|
26
|
+
],
|
|
27
|
+
next: null,
|
|
28
|
+
}),
|
|
29
|
+
});
|
|
30
|
+
const api = createZapierApi({
|
|
31
|
+
fetch: mockFetch,
|
|
32
|
+
token: "test-token",
|
|
33
|
+
baseUrl: "https://api.zapier.com",
|
|
34
|
+
});
|
|
35
|
+
// Call the path with handler override
|
|
36
|
+
const result = await api.get("/api/v0/apps", {
|
|
37
|
+
searchParams: { implementationIds: "SlackAPI@1.0.0" },
|
|
38
|
+
});
|
|
39
|
+
// Assert: No direct call to /api/v0/apps (handler intercepted it)
|
|
40
|
+
const fetchCalls = mockFetch.mock.calls;
|
|
41
|
+
const appsEndpointCalls = fetchCalls.filter((call) => typeof call[0] === "string" && call[0].includes("/api/v0/apps"));
|
|
42
|
+
expect(appsEndpointCalls).toHaveLength(0);
|
|
43
|
+
// Assert: Handler made nested call to lookup endpoint
|
|
44
|
+
const lookupCalls = fetchCalls.filter((call) => typeof call[0] === "string" &&
|
|
45
|
+
call[0].includes("/zapier/api/v4/implementations-meta/lookup/"));
|
|
46
|
+
expect(lookupCalls.length).toBeGreaterThan(0);
|
|
47
|
+
// Assert: Result has correct structure from handler
|
|
48
|
+
expect(result).toHaveProperty("data");
|
|
49
|
+
expect(result).toHaveProperty("nextCursor");
|
|
50
|
+
expect(Array.isArray(result.data)).toBe(true);
|
|
51
|
+
expect(result.data).toHaveLength(1);
|
|
52
|
+
expect(result.data[0]).toMatchObject({
|
|
53
|
+
key: "SlackAPI",
|
|
54
|
+
title: "Slack",
|
|
55
|
+
implementation_id: "SlackAPI@1.0.0",
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
it("should pass httpClient to handler for nested API calls", async () => {
|
|
59
|
+
// Mock response for the nested lookup call
|
|
60
|
+
mockFetch.mockResolvedValueOnce({
|
|
61
|
+
ok: true,
|
|
62
|
+
status: 200,
|
|
63
|
+
json: async () => ({
|
|
64
|
+
results: [
|
|
65
|
+
{
|
|
66
|
+
api: "github",
|
|
67
|
+
name: "GitHub",
|
|
68
|
+
id: "GitHubAPI@2.1.0",
|
|
69
|
+
logo_url: "https://example.com/github.png",
|
|
70
|
+
categories: ["developer-tools"],
|
|
71
|
+
},
|
|
72
|
+
],
|
|
73
|
+
next: null,
|
|
74
|
+
}),
|
|
75
|
+
});
|
|
76
|
+
const api = createZapierApi({
|
|
77
|
+
fetch: mockFetch,
|
|
78
|
+
token: "test-token",
|
|
79
|
+
baseUrl: "https://api.zapier.com",
|
|
80
|
+
});
|
|
81
|
+
// Request with multiple implementation IDs
|
|
82
|
+
await api.get("/api/v0/apps", {
|
|
83
|
+
searchParams: {
|
|
84
|
+
implementationIds: "GitHubAPI@2.1.0,SlackAPI@1.0.0",
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
// Verify that nested API call was made
|
|
88
|
+
expect(mockFetch).toHaveBeenCalledWith(expect.stringContaining("/zapier/api/v4/implementations-meta/lookup/"), expect.any(Object));
|
|
89
|
+
// Verify the request includes proper configuration
|
|
90
|
+
const fetchCall = mockFetch.mock.calls[0];
|
|
91
|
+
expect(fetchCall[0]).toContain("selected_apis=GitHubAPI%402.1.0%2CSlackAPI%401.0.0");
|
|
92
|
+
expect(fetchCall[1]).toHaveProperty("method", "GET");
|
|
93
|
+
});
|
|
94
|
+
it("should handle search augmentation through handler", async () => {
|
|
95
|
+
// Mock search endpoint response
|
|
96
|
+
mockFetch
|
|
97
|
+
.mockResolvedValueOnce({
|
|
98
|
+
ok: true,
|
|
99
|
+
status: 200,
|
|
100
|
+
json: async () => ({
|
|
101
|
+
results: [
|
|
102
|
+
{
|
|
103
|
+
api: "gmail",
|
|
104
|
+
name: "Gmail",
|
|
105
|
+
id: "GmailAPI@1.5.0",
|
|
106
|
+
logo_url: "https://example.com/gmail.png",
|
|
107
|
+
categories: ["email"],
|
|
108
|
+
},
|
|
109
|
+
],
|
|
110
|
+
next: null,
|
|
111
|
+
}),
|
|
112
|
+
})
|
|
113
|
+
// Mock lookup endpoint response
|
|
114
|
+
.mockResolvedValueOnce({
|
|
115
|
+
ok: true,
|
|
116
|
+
status: 200,
|
|
117
|
+
json: async () => ({
|
|
118
|
+
results: [
|
|
119
|
+
{
|
|
120
|
+
api: "slack",
|
|
121
|
+
name: "Slack",
|
|
122
|
+
id: "SlackAPI@1.0.0",
|
|
123
|
+
logo_url: "https://example.com/slack.png",
|
|
124
|
+
categories: ["communication"],
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
api: "gmail",
|
|
128
|
+
name: "Gmail",
|
|
129
|
+
id: "GmailAPI@1.5.0",
|
|
130
|
+
logo_url: "https://example.com/gmail.png",
|
|
131
|
+
categories: ["email"],
|
|
132
|
+
},
|
|
133
|
+
],
|
|
134
|
+
next: null,
|
|
135
|
+
}),
|
|
136
|
+
});
|
|
137
|
+
const api = createZapierApi({
|
|
138
|
+
fetch: mockFetch,
|
|
139
|
+
token: "test-token",
|
|
140
|
+
baseUrl: "https://api.zapier.com",
|
|
141
|
+
});
|
|
142
|
+
// Request with search term and specific implementation
|
|
143
|
+
const result = await api.get("/api/v0/apps", {
|
|
144
|
+
searchParams: {
|
|
145
|
+
implementationIds: "SlackAPI@1.0.0",
|
|
146
|
+
search: "email",
|
|
147
|
+
},
|
|
148
|
+
});
|
|
149
|
+
// Verify search endpoint was called
|
|
150
|
+
const searchCalls = mockFetch.mock.calls.filter((call) => typeof call[0] === "string" &&
|
|
151
|
+
call[0].includes("/zapier/api/v4/implementations-meta/search/"));
|
|
152
|
+
expect(searchCalls.length).toBeGreaterThan(0);
|
|
153
|
+
// Verify lookup endpoint was called with augmented IDs
|
|
154
|
+
const lookupCalls = mockFetch.mock.calls.filter((call) => typeof call[0] === "string" &&
|
|
155
|
+
call[0].includes("/zapier/api/v4/implementations-meta/lookup/"));
|
|
156
|
+
expect(lookupCalls.length).toBeGreaterThan(0);
|
|
157
|
+
// Verify result contains both original and search results
|
|
158
|
+
expect(result.data).toHaveLength(2);
|
|
159
|
+
});
|
|
160
|
+
it("should handle pagination through handler", async () => {
|
|
161
|
+
// Mock first page response
|
|
162
|
+
mockFetch.mockResolvedValueOnce({
|
|
163
|
+
ok: true,
|
|
164
|
+
status: 200,
|
|
165
|
+
json: async () => ({
|
|
166
|
+
results: [
|
|
167
|
+
{
|
|
168
|
+
api: "app1",
|
|
169
|
+
name: "App 1",
|
|
170
|
+
id: "App1API@1.0.0",
|
|
171
|
+
logo_url: "https://example.com/app1.png",
|
|
172
|
+
categories: ["productivity"],
|
|
173
|
+
},
|
|
174
|
+
],
|
|
175
|
+
next: "https://example.com/api?offset=20",
|
|
176
|
+
}),
|
|
177
|
+
});
|
|
178
|
+
const api = createZapierApi({
|
|
179
|
+
fetch: mockFetch,
|
|
180
|
+
token: "test-token",
|
|
181
|
+
baseUrl: "https://api.zapier.com",
|
|
182
|
+
});
|
|
183
|
+
const result = await api.get("/api/v0/apps", {
|
|
184
|
+
searchParams: { pageSize: "10" },
|
|
185
|
+
});
|
|
186
|
+
// Verify pagination cursor is extracted
|
|
187
|
+
expect(result.nextCursor).toBe("20");
|
|
188
|
+
// Mock second page response
|
|
189
|
+
mockFetch.mockResolvedValueOnce({
|
|
190
|
+
ok: true,
|
|
191
|
+
status: 200,
|
|
192
|
+
json: async () => ({
|
|
193
|
+
results: [
|
|
194
|
+
{
|
|
195
|
+
api: "app2",
|
|
196
|
+
name: "App 2",
|
|
197
|
+
id: "App2API@1.0.0",
|
|
198
|
+
logo_url: "https://example.com/app2.png",
|
|
199
|
+
categories: ["productivity"],
|
|
200
|
+
},
|
|
201
|
+
],
|
|
202
|
+
next: null,
|
|
203
|
+
}),
|
|
204
|
+
});
|
|
205
|
+
// Request second page
|
|
206
|
+
const secondPageResult = await api.get("/api/v0/apps", {
|
|
207
|
+
searchParams: { cursor: "20" },
|
|
208
|
+
});
|
|
209
|
+
expect(secondPageResult.nextCursor).toBeUndefined();
|
|
210
|
+
});
|
|
211
|
+
it("should handle errors from handler correctly", async () => {
|
|
212
|
+
// Mock an error response from nested API call
|
|
213
|
+
mockFetch.mockResolvedValueOnce({
|
|
214
|
+
ok: false,
|
|
215
|
+
status: 404,
|
|
216
|
+
statusText: "Not Found",
|
|
217
|
+
json: async () => ({
|
|
218
|
+
errors: [
|
|
219
|
+
{
|
|
220
|
+
message: "Implementation not found",
|
|
221
|
+
},
|
|
222
|
+
],
|
|
223
|
+
}),
|
|
224
|
+
});
|
|
225
|
+
const api = createZapierApi({
|
|
226
|
+
fetch: mockFetch,
|
|
227
|
+
token: "test-token",
|
|
228
|
+
baseUrl: "https://api.zapier.com",
|
|
229
|
+
});
|
|
230
|
+
// Request should propagate the error from handler
|
|
231
|
+
await expect(api.get("/api/v0/apps", {
|
|
232
|
+
searchParams: { implementationIds: "NonExistentAPI" },
|
|
233
|
+
})).rejects.toThrow();
|
|
234
|
+
});
|
|
235
|
+
it("should handle empty search results correctly", async () => {
|
|
236
|
+
// Mock empty search response
|
|
237
|
+
mockFetch.mockResolvedValueOnce({
|
|
238
|
+
ok: true,
|
|
239
|
+
status: 200,
|
|
240
|
+
json: async () => ({
|
|
241
|
+
results: [],
|
|
242
|
+
next: null,
|
|
243
|
+
}),
|
|
244
|
+
});
|
|
245
|
+
const api = createZapierApi({
|
|
246
|
+
fetch: mockFetch,
|
|
247
|
+
token: "test-token",
|
|
248
|
+
baseUrl: "https://api.zapier.com",
|
|
249
|
+
});
|
|
250
|
+
const result = await api.get("/api/v0/apps", {
|
|
251
|
+
searchParams: {
|
|
252
|
+
implementationIds: "",
|
|
253
|
+
search: "nonexistentapp",
|
|
254
|
+
},
|
|
255
|
+
});
|
|
256
|
+
// Should return empty results without calling lookup endpoint
|
|
257
|
+
expect(result.data).toEqual([]);
|
|
258
|
+
expect(result.nextCursor).toBeUndefined();
|
|
259
|
+
// Verify only search endpoint was called, not lookup
|
|
260
|
+
const lookupCalls = mockFetch.mock.calls.filter((call) => typeof call[0] === "string" &&
|
|
261
|
+
call[0].includes("/zapier/api/v4/implementations-meta/lookup/"));
|
|
262
|
+
expect(lookupCalls).toHaveLength(0);
|
|
263
|
+
});
|
|
264
|
+
});
|
|
265
|
+
describe("standard path handling (non-override)", () => {
|
|
266
|
+
it("should make normal HTTP requests for paths without handler override", async () => {
|
|
267
|
+
mockFetch.mockResolvedValueOnce({
|
|
268
|
+
ok: true,
|
|
269
|
+
status: 200,
|
|
270
|
+
json: async () => ({ result: "direct HTTP response" }),
|
|
271
|
+
});
|
|
272
|
+
const api = createZapierApi({
|
|
273
|
+
fetch: mockFetch,
|
|
274
|
+
token: "test-token",
|
|
275
|
+
baseUrl: "https://api.zapier.com",
|
|
276
|
+
});
|
|
277
|
+
// Request to a path without handler override
|
|
278
|
+
await api.get("/zapier/some-other-endpoint");
|
|
279
|
+
// Verify HTTP request was made directly
|
|
280
|
+
expect(mockFetch).toHaveBeenCalledWith(expect.stringContaining("/zapier/some-other-endpoint"), expect.any(Object));
|
|
281
|
+
});
|
|
282
|
+
});
|
|
283
|
+
describe("handler override type safety", () => {
|
|
284
|
+
it("should handle handler request transformation correctly", async () => {
|
|
285
|
+
// Mock response for lookup
|
|
286
|
+
mockFetch.mockResolvedValueOnce({
|
|
287
|
+
ok: true,
|
|
288
|
+
status: 200,
|
|
289
|
+
json: async () => ({
|
|
290
|
+
results: [],
|
|
291
|
+
next: null,
|
|
292
|
+
}),
|
|
293
|
+
});
|
|
294
|
+
const api = createZapierApi({
|
|
295
|
+
fetch: mockFetch,
|
|
296
|
+
token: "test-token",
|
|
297
|
+
baseUrl: "https://api.zapier.com",
|
|
298
|
+
});
|
|
299
|
+
// Test that string implementationIds are properly handled
|
|
300
|
+
const result = await api.get("/api/v0/apps", {
|
|
301
|
+
searchParams: {
|
|
302
|
+
implementationIds: "App1,App2,App3",
|
|
303
|
+
pageSize: "15",
|
|
304
|
+
},
|
|
305
|
+
});
|
|
306
|
+
// Verify the handler received and processed the request
|
|
307
|
+
expect(result).toHaveProperty("data");
|
|
308
|
+
expect(Array.isArray(result.data)).toBe(true);
|
|
309
|
+
// Check that lookup endpoint was called with proper params
|
|
310
|
+
const lookupCall = mockFetch.mock.calls.find((call) => typeof call[0] === "string" &&
|
|
311
|
+
call[0].includes("/zapier/api/v4/implementations-meta/lookup/"));
|
|
312
|
+
expect(lookupCall).toBeDefined();
|
|
313
|
+
// Commas are URL-encoded as %2C
|
|
314
|
+
expect(lookupCall[0]).toContain("selected_apis=App1%2CApp2%2CApp3");
|
|
315
|
+
expect(lookupCall[0]).toContain("limit=15");
|
|
316
|
+
});
|
|
317
|
+
});
|
|
318
|
+
});
|
package/dist/api/client.js
CHANGED
|
@@ -10,6 +10,8 @@ import { pollUntilComplete } from "./polling";
|
|
|
10
10
|
import { getTokenFromEnvOrConfig } from "../auth";
|
|
11
11
|
import { getZapierBaseUrl } from "../utils/url-utils";
|
|
12
12
|
import { ZapierApiError, ZapierAuthenticationError, ZapierValidationError, ZapierNotFoundError, } from "../types/errors";
|
|
13
|
+
import { handleListApps } from "../temporary-internal-core";
|
|
14
|
+
// Configuration for paths
|
|
13
15
|
const pathConfig = {
|
|
14
16
|
// e.g. /relay -> https://sdkapi.zapier.com/api/v0/sdk/relay/...
|
|
15
17
|
"/relay": {
|
|
@@ -21,6 +23,9 @@ const pathConfig = {
|
|
|
21
23
|
authHeader: "Authorization",
|
|
22
24
|
pathPrefix: "/api/v0/sdk/zapier",
|
|
23
25
|
},
|
|
26
|
+
"/api/v0/apps": {
|
|
27
|
+
handlerOverride: handleListApps,
|
|
28
|
+
},
|
|
24
29
|
};
|
|
25
30
|
class ZapierApiClient {
|
|
26
31
|
constructor(options) {
|
|
@@ -195,6 +200,16 @@ class ZapierApiClient {
|
|
|
195
200
|
}
|
|
196
201
|
return undefined;
|
|
197
202
|
}
|
|
203
|
+
// Helper to check if a path config has a handler override
|
|
204
|
+
hasHandlerOverride(pathConfig) {
|
|
205
|
+
return (pathConfig !== undefined &&
|
|
206
|
+
"handlerOverride" in pathConfig &&
|
|
207
|
+
typeof pathConfig.handlerOverride === "function");
|
|
208
|
+
}
|
|
209
|
+
// Helper to check if a path config is a standard path config
|
|
210
|
+
isStandardPathConfig(pathConfig) {
|
|
211
|
+
return pathConfig !== undefined && !this.hasHandlerOverride(pathConfig);
|
|
212
|
+
}
|
|
198
213
|
// Helper to parse API error response
|
|
199
214
|
parseErrorResponse(errorInfo) {
|
|
200
215
|
// If we can't parse data, use status text
|
|
@@ -284,7 +299,9 @@ class ZapierApiClient {
|
|
|
284
299
|
// session!
|
|
285
300
|
const authToken = await this.getAuthToken();
|
|
286
301
|
if (authToken) {
|
|
287
|
-
const authHeaderName = pathConfig
|
|
302
|
+
const authHeaderName = this.isStandardPathConfig(pathConfig) && pathConfig.authHeader
|
|
303
|
+
? pathConfig.authHeader
|
|
304
|
+
: "Authorization";
|
|
288
305
|
headers.set(authHeaderName, getAuthorizationHeader(authToken));
|
|
289
306
|
}
|
|
290
307
|
// If we know auth is required, and we don't have a token, throw an error
|
|
@@ -298,6 +315,19 @@ class ZapierApiClient {
|
|
|
298
315
|
}
|
|
299
316
|
// Helper to perform HTTP requests with JSON handling
|
|
300
317
|
async fetchJson(method, path, data, options = {}) {
|
|
318
|
+
// Check if this path has a handler override
|
|
319
|
+
const { pathConfig } = this.buildUrl(path, options.searchParams);
|
|
320
|
+
if (this.hasHandlerOverride(pathConfig)) {
|
|
321
|
+
// Invoke the handler instead of making an HTTP request
|
|
322
|
+
// Pass searchParams for GET requests, data for other methods
|
|
323
|
+
const handlerRequest = method === "GET" ? options.searchParams : data;
|
|
324
|
+
return pathConfig.handlerOverride({
|
|
325
|
+
request: handlerRequest,
|
|
326
|
+
deps: {
|
|
327
|
+
httpClient: this,
|
|
328
|
+
},
|
|
329
|
+
});
|
|
330
|
+
}
|
|
301
331
|
const headers = { ...options.headers };
|
|
302
332
|
// Add Content-Type for JSON requests with body data
|
|
303
333
|
if (data && typeof data === "object") {
|