MCPcopy
hub / github.com/goauthentik/authentik / createFetchParams

Method createFetchParams

packages/client-ts/src/runtime.ts:150–204  ·  view source on GitHub ↗
(
        context: RequestOpts,
        initOverrides?: RequestInit | InitOverrideFunction,
    )

Source from the content-addressed store, hash-verified

148 }
149
150 private async createFetchParams(
151 context: RequestOpts,
152 initOverrides?: RequestInit | InitOverrideFunction,
153 ) {
154 let url = this.configuration.basePath + context.path;
155 if (context.query !== undefined && Object.keys(context.query).length !== 0) {
156 // only add the querystring to the URL if there are query parameters.
157 // this is done to avoid urls ending with a "?" character which buggy webservers
158 // do not handle correctly sometimes.
159 url += "?" + this.configuration.queryParamsStringify(context.query);
160 }
161
162 const headers = Object.assign({}, this.configuration.headers, context.headers);
163 Object.keys(headers).forEach((key) =>
164 headers[key] === undefined ? delete headers[key] : {},
165 );
166
167 const initOverrideFn =
168 typeof initOverrides === "function" ? initOverrides : async () => initOverrides;
169
170 const initParams = {
171 method: context.method,
172 headers,
173 body: context.body,
174 credentials: this.configuration.credentials,
175 };
176
177 const overriddenInit: RequestInit = {
178 ...initParams,
179 ...(await initOverrideFn({
180 init: initParams,
181 context,
182 })),
183 };
184
185 let body: any;
186 if (
187 isFormData(overriddenInit.body) ||
188 overriddenInit.body instanceof URLSearchParams ||
189 isBlob(overriddenInit.body)
190 ) {
191 body = overriddenInit.body;
192 } else if (this.isJsonMime(headers["Content-Type"])) {
193 body = JSON.stringify(overriddenInit.body);
194 } else {
195 body = overriddenInit.body;
196 }
197
198 const init: RequestInit = {
199 ...overriddenInit,
200 body,
201 };
202
203 return { url, init };
204 }
205
206 private fetchApi = async (url: string, init: RequestInit) => {
207 let fetchParams = { url, init };

Callers 1

requestMethod · 0.95

Calls 6

isJsonMimeMethod · 0.95
isFormDataFunction · 0.85
isBlobFunction · 0.85
keysMethod · 0.80
queryParamsStringifyMethod · 0.80
assignMethod · 0.80

Tested by

no test coverage detected