decap-cms-backend-github 3.3.1 → 3.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -26,7 +26,7 @@ import AuthenticationPage from './AuthenticationPage';
26
26
  import API, { API_NAME } from './API';
27
27
  import GraphQLAPI from './GraphQLAPI';
28
28
 
29
- import type { Octokit } from '@octokit/rest';
29
+ import type { Endpoints } from '@octokit/types';
30
30
  import type {
31
31
  AsyncLock,
32
32
  Implementation,
@@ -42,7 +42,7 @@ import type {
42
42
  } from 'decap-cms-lib-util';
43
43
  import type { Semaphore } from 'semaphore';
44
44
 
45
- export type GitHubUser = Octokit.UsersGetAuthenticatedResponse;
45
+ export type GitHubUser = Endpoints['GET /user']['response']['data'];
46
46
 
47
47
  const MAX_CONCURRENT_DOWNLOADS = 10;
48
48
 
@@ -210,13 +210,20 @@ export default class GitHub implements Implementation {
210
210
  return Promise.resolve();
211
211
  }
212
212
 
213
- async currentUser({ token }: { token: string }) {
213
+ async currentUser({ token }: { token: string }): Promise<GitHubUser> {
214
214
  if (!this._currentUserPromise) {
215
- this._currentUserPromise = fetch(`${this.apiRoot}/user`, {
216
- headers: {
217
- Authorization: `${this.tokenKeyword} ${token}`,
218
- },
219
- }).then(res => res.json());
215
+ this._currentUserPromise = (async () => {
216
+ const res = await fetch(`${this.apiRoot}/user`, {
217
+ headers: {
218
+ Authorization: `${this.tokenKeyword} ${token}`,
219
+ },
220
+ });
221
+ const user = await res.json();
222
+ return {
223
+ ...user,
224
+ name: user.name || 'Unknown',
225
+ } as GitHubUser;
226
+ })();
220
227
  }
221
228
  return this._currentUserPromise;
222
229
  }
@@ -346,7 +353,7 @@ export default class GitHub implements Implementation {
346
353
  useOpenAuthoring: this.useOpenAuthoring,
347
354
  initialWorkflowStatus: this.options.initialWorkflowStatus,
348
355
  baseUrl: this.baseUrl,
349
- getUser: this.currentUser,
356
+ getUser: args => this.currentUser(args),
350
357
  });
351
358
  const user = await this.api!.user();
352
359
  const isCollab = await this.api!.hasWriteAccess().catch(error => {