2018-08-07 14:46:54 -06:00
|
|
|
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';
|
2020-04-01 06:13:27 +03:00
|
|
|
import { unsentRequest, ApiRequest } from 'netlify-cms-lib-util';
|
2020-01-15 00:15:14 +02:00
|
|
|
|
|
|
|
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-04-01 06:13:27 +03:00
|
|
|
withAuthorizationHeaders = async (req: ApiRequest) => {
|
|
|
|
const token = await this.tokenPromise();
|
|
|
|
return unsentRequest.withHeaders(
|
2018-08-07 14:46:54 -06:00
|
|
|
{
|
2020-04-01 06:13:27 +03:00
|
|
|
Authorization: `Bearer ${token}`,
|
2018-08-07 14:46:54 -06:00
|
|
|
},
|
|
|
|
req,
|
|
|
|
);
|
2020-04-01 06:13:27 +03:00
|
|
|
};
|
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
|
|
|
}
|