MCPcopy Create free account
hub / github.com/decaporg/decap-cms / API

Class API

packages/decap-cms-backend-azure/src/API.ts:223–807  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

221}
222
223export default class API {
224 apiVersion: string;
225 token: string;
226 branch: string;
227 mergeStrategy: string;
228 endpointUrl: string;
229 initialWorkflowStatus: string;
230 cmsLabelPrefix: string;
231
232 constructor(config: AzureApiConfig, token: string) {
233 const { repo } = config;
234 const apiRoot = trim(config.apiRoot, '/');
235 this.endpointUrl = `${apiRoot}/${repo.org}/${repo.project}/_apis/git/repositories/${repo.repoName}`;
236 this.token = token;
237 this.branch = config.branch;
238 this.mergeStrategy = config.squashMerges ? 'squash' : 'noFastForward';
239 this.initialWorkflowStatus = config.initialWorkflowStatus;
240 this.apiVersion = config.apiVersion;
241 this.cmsLabelPrefix = config.cmsLabelPrefix;
242 }
243
244 withHeaders = (req: ApiRequest) => {
245 const withHeaders = unsentRequest.withHeaders(
246 {
247 Authorization: `Bearer ${this.token}`,
248 'Content-Type': 'application/json; charset=utf-8',
249 },
250 req,
251 );
252 return withHeaders;
253 };
254
255 withAzureFeatures = (req: Map<string, Map<string, string>>) => {
256 if (req.hasIn(['params', API_VERSION])) {
257 return req;
258 }
259 const withParams = unsentRequest.withParams(
260 {
261 [API_VERSION]: `${this.apiVersion}`,
262 },
263 req,
264 );
265
266 return withParams;
267 };
268
269 buildRequest = (req: ApiRequest) => {
270 const withHeaders = this.withHeaders(req);
271 const withAzureFeatures = this.withAzureFeatures(withHeaders);
272 if (withAzureFeatures.has('cache')) {
273 return withAzureFeatures;
274 } else {
275 const withNoCache = unsentRequest.withNoCache(withAzureFeatures);
276 return withNoCache;
277 }
278 };
279
280 request = (req: ApiRequest): Promise<Response> => {

Callers

nothing calls this directly

Calls 8

requestMethod · 0.95
requestWithBackoffFunction · 0.90
responseParserFunction · 0.90
readFileFunction · 0.90
basenameFunction · 0.90
hasMethod · 0.80
mapMethod · 0.80
filterMethod · 0.80

Tested by

no test coverage detected