decap-cms-lib-util 3.0.4 → 3.1.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.
package/dist/esm/API.js CHANGED
@@ -172,7 +172,7 @@ async function constructRequestHeaders(headerConfig) {
172
172
  'Content-Type': 'application/json; charset=utf-8'
173
173
  }, headers);
174
174
  if (token) {
175
- baseHeaders['Authorization'] = `token ${token}`;
175
+ baseHeaders['Authorization'] = `Bearer ${token}`;
176
176
  }
177
177
  return Promise.resolve(baseHeaders);
178
178
  }
@@ -180,6 +180,7 @@ function handleRequestError(error, responseStatus, backend) {
180
180
  throw new _APIError.default(error.message, responseStatus, backend);
181
181
  }
182
182
  async function apiRequest(path, config, parser = response => parseResponse(response)) {
183
+ var _config$apiRoot;
183
184
  const {
184
185
  token,
185
186
  backend
@@ -192,7 +193,7 @@ async function apiRequest(path, config, parser = response => parseResponse(respo
192
193
  headers: options.headers || {},
193
194
  token
194
195
  });
195
- const baseUrl = apiRoots[backend];
196
+ const baseUrl = (_config$apiRoot = config.apiRoot) !== null && _config$apiRoot !== void 0 ? _config$apiRoot : apiRoots[backend];
196
197
  const url = constructUrlWithParams(`${baseUrl}${path}`, options.params);
197
198
  let responseStatus = 500;
198
199
  try {
@@ -212,7 +213,8 @@ async function getDefaultBranchName(configs) {
212
213
  const {
213
214
  token,
214
215
  backend,
215
- repo
216
+ repo,
217
+ apiRoot
216
218
  } = configs;
217
219
  switch (backend) {
218
220
  case 'gitlab':
@@ -232,7 +234,8 @@ async function getDefaultBranchName(configs) {
232
234
  }
233
235
  const repoInfo = await apiRequest(apiPath, {
234
236
  token,
235
- backend
237
+ backend,
238
+ apiRoot
236
239
  });
237
240
  let defaultBranchName;
238
241
  if (backend === 'bitbucket') {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "decap-cms-lib-util",
3
3
  "description": "Shared utilities for Decap CMS.",
4
- "version": "3.0.4",
4
+ "version": "3.1.0",
5
5
  "repository": "https://github.com/decaporg/decap-cms/tree/main/packages/decap-cms-lib-util",
6
6
  "bugs": "https://github.com/decaporg/decap-cms/issues",
7
7
  "module": "dist/esm/index.js",
@@ -25,5 +25,5 @@
25
25
  "immutable": "^3.7.6",
26
26
  "lodash": "^4.17.11"
27
27
  },
28
- "gitHead": "d3678b0ad1b9f93b841c85e4ee2de48167aa8906"
28
+ "gitHead": "86c93a4fae0fd954d043acc176b0618ab715623b"
29
29
  }
package/src/API.ts CHANGED
@@ -142,6 +142,7 @@ type Backend = 'github' | 'gitlab' | 'bitbucket';
142
142
  type RequestConfig = Omit<RequestInit, 'headers'> &
143
143
  HeaderConfig & {
144
144
  backend: Backend;
145
+ apiRoot?: string;
145
146
  params?: ParamObject;
146
147
  };
147
148
 
@@ -182,7 +183,7 @@ async function constructRequestHeaders(headerConfig: HeaderConfig) {
182
183
  const { token, headers } = headerConfig;
183
184
  const baseHeaders: HeaderObj = { 'Content-Type': 'application/json; charset=utf-8', ...headers };
184
185
  if (token) {
185
- baseHeaders['Authorization'] = `token ${token}`;
186
+ baseHeaders['Authorization'] = `Bearer ${token}`;
186
187
  }
187
188
  return Promise.resolve(baseHeaders);
188
189
  }
@@ -199,7 +200,7 @@ export async function apiRequest(
199
200
  const { token, backend, ...props } = config;
200
201
  const options = { cache: 'no-cache', ...props };
201
202
  const headers = await constructRequestHeaders({ headers: options.headers || {}, token });
202
- const baseUrl = apiRoots[backend];
203
+ const baseUrl = config.apiRoot ?? apiRoots[backend];
203
204
  const url = constructUrlWithParams(`${baseUrl}${path}`, options.params);
204
205
  let responseStatus = 500;
205
206
  try {
@@ -220,9 +221,10 @@ export async function getDefaultBranchName(configs: {
220
221
  backend: Backend;
221
222
  repo: string;
222
223
  token?: string;
224
+ apiRoot?: string;
223
225
  }) {
224
226
  let apiPath;
225
- const { token, backend, repo } = configs;
227
+ const { token, backend, repo, apiRoot } = configs;
226
228
  switch (backend) {
227
229
  case 'gitlab': {
228
230
  apiPath = `/projects/${encodeURIComponent(repo)}`;
@@ -236,7 +238,7 @@ export async function getDefaultBranchName(configs: {
236
238
  apiPath = `/repos/${repo}`;
237
239
  }
238
240
  }
239
- const repoInfo = await apiRequest(apiPath, { token, backend });
241
+ const repoInfo = await apiRequest(apiPath, { token, backend, apiRoot });
240
242
  let defaultBranchName;
241
243
  if (backend === 'bitbucket') {
242
244
  const {