2018-08-07 14:46:54 -06:00
|
|
|
import { flow } from 'lodash';
|
|
|
|
import { API as GitlabAPI } from 'netlify-cms-backend-gitlab';
|
2020-01-15 00:15:14 +02:00
|
|
|
import { Config as GitHubConfig, CommitAuthor } from 'netlify-cms-backend-gitlab/src/API';
|
|
|
|
import { unsentRequest, then, ApiRequest } from 'netlify-cms-lib-util';
|
|
|
|
|
|
|
|
type Config = GitHubConfig & { tokenPromise: () => Promise<string>; commitAuthor: CommitAuthor };
|
2018-06-11 19:03:43 -07:00
|
|
|
|
|
|
|
export default class API extends GitlabAPI {
|
2020-01-15 00:15:14 +02:00
|
|
|
tokenPromise: () => Promise<string>;
|
|
|
|
|
|
|
|
constructor(config: Config) {
|
2018-06-11 19:03:43 -07:00
|
|
|
super(config);
|
|
|
|
this.tokenPromise = config.tokenPromise;
|
|
|
|
this.commitAuthor = config.commitAuthor;
|
2018-08-07 14:46:54 -06:00
|
|
|
this.repoURL = '';
|
2018-06-11 19:03:43 -07:00
|
|
|
}
|
|
|
|
|
2020-01-15 00:15:14 +02:00
|
|
|
authenticateRequest = async (req: ApiRequest) =>
|
2018-08-07 14:46:54 -06:00
|
|
|
unsentRequest.withHeaders(
|
|
|
|
{
|
|
|
|
Authorization: `Bearer ${await this.tokenPromise()}`,
|
|
|
|
},
|
|
|
|
req,
|
|
|
|
);
|
2018-06-11 19:03:43 -07:00
|
|
|
|
2020-01-15 00:15:14 +02:00
|
|
|
request = async (req: ApiRequest) =>
|
2018-08-07 14:46:54 -06:00
|
|
|
flow([this.buildRequest, this.authenticateRequest, then(unsentRequest.performRequest)])(req);
|
2018-06-11 19:03:43 -07:00
|
|
|
|
2018-08-07 14:46:54 -06:00
|
|
|
hasWriteAccess = () => Promise.resolve(true);
|
2018-06-11 19:03:43 -07:00
|
|
|
}
|