MCPcopy
hub / github.com/MODSetter/SurfSense / request

Method request

surfsense_web/lib/apis/base-api.service.ts:43–214  ·  view source on GitHub ↗
(
		url: string,
		responseSchema?: ZodType<T>,
		options?: RequestOptions & { responseType?: R }
	)

Source from the content-addressed store, hash-verified

41 }
42
43 async request<T, R extends ResponseType = ResponseType.JSON>(
44 url: string,
45 responseSchema?: ZodType<T>,
46 options?: RequestOptions & { responseType?: R }
47 ): Promise<
48 R extends ResponseType.JSON
49 ? T
50 : R extends ResponseType.TEXT
51 ? string
52 : R extends ResponseType.BLOB
53 ? Blob
54 : R extends ResponseType.ARRAY_BUFFER
55 ? ArrayBuffer
56 : unknown
57 > {
58 try {
59 /**
60 * ----------
61 * REQUEST
62 * ----------
63 */
64 const defaultOptions: RequestOptions = {
65 headers: {
66 Authorization: `Bearer ${this.bearerToken || ""}`,
67 },
68 method: "GET",
69 responseType: ResponseType.JSON,
70 };
71
72 const mergedOptions: RequestOptions = {
73 ...defaultOptions,
74 ...(options ?? {}),
75 headers: {
76 ...defaultOptions.headers,
77 ...(options?.headers ?? {}),
78 },
79 };
80
81 // Validate the base URL
82 if (!this.baseUrl) {
83 throw new AppError("Base URL is not set.");
84 }
85
86 // Validate the bearer token
87 if (!this.bearerToken && !this.noAuthEndpoints.includes(url)) {
88 throw new AuthenticationError("You are not authenticated. Please login again.");
89 }
90
91 // Construct the full URL
92 const fullUrl = new URL(url, this.baseUrl).toString();
93
94 // Prepare fetch options
95 const fetchOptions: RequestInit = {
96 method: mergedOptions.method,
97 headers: mergedOptions.headers,
98 signal: mergedOptions.signal,
99 };
100

Callers 8

getMethod · 0.95
postMethod · 0.95
putMethod · 0.95
deleteMethod · 0.95
patchMethod · 0.95
getBlobMethod · 0.95
postFormDataMethod · 0.95
_make_requestMethod · 0.80

Calls 1

handleUnauthorizedFunction · 0.90

Tested by

no test coverage detected