decap-cms-lib-util 3.1.0 → 3.3.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/README.md +1 -1
- package/dist/decap-cms-lib-util.js +1 -1
- package/dist/decap-cms-lib-util.js.LICENSE.txt +9 -0
- package/dist/decap-cms-lib-util.js.map +1 -1
- package/dist/esm/API.js +37 -61
- package/dist/esm/APIError.js +3 -17
- package/dist/esm/APIUtils.js +10 -23
- package/dist/esm/AccessTokenError.js +3 -14
- package/dist/esm/Cursor.js +16 -28
- package/dist/esm/EditorialWorkflowError.js +3 -15
- package/dist/esm/asyncLock.js +5 -12
- package/dist/esm/backendUtil.js +21 -34
- package/dist/esm/getBlobSHA.js +4 -11
- package/dist/esm/git-lfs.js +27 -46
- package/dist/esm/implementation.js +32 -51
- package/dist/esm/index.js +71 -409
- package/dist/esm/loadScript.js +1 -7
- package/dist/esm/localForage.js +4 -11
- package/dist/esm/path.js +4 -13
- package/dist/esm/promise.js +5 -14
- package/dist/esm/stega.js +129 -0
- package/dist/esm/types/semaphore.d.js +0 -1
- package/dist/esm/types.js +7 -0
- package/dist/esm/unsentRequest.js +21 -31
- package/package.json +5 -2
- package/CHANGELOG.md +0 -376
- package/src/API.ts +0 -376
- package/src/APIError.ts +0 -17
- package/src/APIUtils.ts +0 -38
- package/src/AccessTokenError.ts +0 -11
- package/src/Cursor.ts +0 -178
- package/src/EditorialWorkflowError.ts +0 -12
- package/src/__tests__/api.spec.js +0 -13
- package/src/__tests__/apiUtils.spec.js +0 -74
- package/src/__tests__/asyncLock.spec.js +0 -85
- package/src/__tests__/backendUtil.spec.js +0 -97
- package/src/__tests__/implementation.spec.js +0 -58
- package/src/__tests__/path.spec.js +0 -53
- package/src/__tests__/unsentRequest.spec.js +0 -19
- package/src/asyncLock.ts +0 -43
- package/src/backendUtil.ts +0 -120
- package/src/getBlobSHA.ts +0 -12
- package/src/git-lfs.ts +0 -133
- package/src/implementation.ts +0 -575
- package/src/index.ts +0 -213
- package/src/loadScript.js +0 -24
- package/src/localForage.ts +0 -21
- package/src/path.ts +0 -86
- package/src/promise.ts +0 -21
- package/src/types/semaphore.d.ts +0 -5
- package/src/unsentRequest.js +0 -133
- package/webpack.config.js +0 -3
package/dist/esm/API.js
CHANGED
|
@@ -1,31 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.PreviewState = void 0;
|
|
7
|
-
exports.apiRequest = apiRequest;
|
|
8
|
-
exports.endpointConstants = exports.apiRoots = void 0;
|
|
9
|
-
exports.getDefaultBranchName = getDefaultBranchName;
|
|
10
|
-
exports.getPreviewStatus = getPreviewStatus;
|
|
11
|
-
exports.isPreviewContext = isPreviewContext;
|
|
12
|
-
exports.parseResponse = parseResponse;
|
|
13
|
-
exports.readFile = readFile;
|
|
14
|
-
exports.readFileMetadata = readFileMetadata;
|
|
15
|
-
exports.requestWithBackoff = requestWithBackoff;
|
|
16
|
-
exports.throwOnConflictingBranches = throwOnConflictingBranches;
|
|
17
|
-
var _asyncLock = require("./asyncLock");
|
|
18
|
-
var _unsentRequest = _interopRequireDefault(require("./unsentRequest"));
|
|
19
|
-
var _APIError = _interopRequireDefault(require("./APIError"));
|
|
20
|
-
const _excluded = ["token", "backend"];
|
|
21
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
22
|
-
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
23
|
-
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
24
|
-
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
25
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
26
|
-
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
27
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
|
|
28
|
-
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
29
1
|
function _extendableBuiltin(cls) {
|
|
30
2
|
function ExtendableBuiltin() {
|
|
31
3
|
var instance = Reflect.construct(cls, Array.from(arguments));
|
|
@@ -47,10 +19,12 @@ function _extendableBuiltin(cls) {
|
|
|
47
19
|
}
|
|
48
20
|
return ExtendableBuiltin;
|
|
49
21
|
}
|
|
22
|
+
import { asyncLock } from './asyncLock';
|
|
23
|
+
import unsentRequest from './unsentRequest';
|
|
24
|
+
import APIError from './APIError';
|
|
50
25
|
class RateLimitError extends _extendableBuiltin(Error) {
|
|
51
26
|
constructor(message, resetSeconds) {
|
|
52
27
|
super(message);
|
|
53
|
-
_defineProperty(this, "resetSeconds", void 0);
|
|
54
28
|
if (resetSeconds < 0) {
|
|
55
29
|
this.resetSeconds = 1;
|
|
56
30
|
} else if (resetSeconds > 60 * 60) {
|
|
@@ -67,7 +41,7 @@ async function parseJsonResponse(response) {
|
|
|
67
41
|
}
|
|
68
42
|
return json;
|
|
69
43
|
}
|
|
70
|
-
function parseResponse(response) {
|
|
44
|
+
export function parseResponse(response) {
|
|
71
45
|
const contentType = response.headers.get('Content-Type');
|
|
72
46
|
if (contentType && contentType.match(/json/)) {
|
|
73
47
|
return parseJsonResponse(response);
|
|
@@ -78,13 +52,13 @@ function parseResponse(response) {
|
|
|
78
52
|
});
|
|
79
53
|
return textPromise;
|
|
80
54
|
}
|
|
81
|
-
async function requestWithBackoff(api, req, attempt = 1) {
|
|
55
|
+
export async function requestWithBackoff(api, req, attempt = 1) {
|
|
82
56
|
if (api.rateLimiter) {
|
|
83
57
|
await api.rateLimiter.acquire();
|
|
84
58
|
}
|
|
85
59
|
try {
|
|
86
60
|
const builtRequest = await api.buildRequest(req);
|
|
87
|
-
const requestFunction = api.requestFunction ||
|
|
61
|
+
const requestFunction = api.requestFunction || unsentRequest.performRequest;
|
|
88
62
|
const response = await requestFunction(builtRequest);
|
|
89
63
|
if (response.status === 429) {
|
|
90
64
|
// GitLab/Bitbucket too many requests
|
|
@@ -110,11 +84,10 @@ async function requestWithBackoff(api, req, attempt = 1) {
|
|
|
110
84
|
if (!api.rateLimiter) {
|
|
111
85
|
const timeout = err.resetSeconds || attempt * attempt;
|
|
112
86
|
console.log(`Pausing requests for ${timeout} ${attempt === 1 ? 'second' : 'seconds'} due to fetch failures:`, err.message);
|
|
113
|
-
api.rateLimiter =
|
|
87
|
+
api.rateLimiter = asyncLock();
|
|
114
88
|
api.rateLimiter.acquire();
|
|
115
89
|
setTimeout(() => {
|
|
116
|
-
|
|
117
|
-
(_api$rateLimiter = api.rateLimiter) === null || _api$rateLimiter === void 0 ? void 0 : _api$rateLimiter.release();
|
|
90
|
+
api.rateLimiter?.release();
|
|
118
91
|
api.rateLimiter = undefined;
|
|
119
92
|
console.log(`Done pausing requests`);
|
|
120
93
|
}, 1000 * timeout);
|
|
@@ -134,12 +107,12 @@ async function requestWithBackoff(api, req, attempt = 1) {
|
|
|
134
107
|
// - `params` property for customizing response
|
|
135
108
|
// - `backend`(compulsory) to specify which backend to be used: Github, Gitlab etc.
|
|
136
109
|
|
|
137
|
-
const apiRoots =
|
|
110
|
+
export const apiRoots = {
|
|
138
111
|
github: 'https://api.github.com',
|
|
139
112
|
gitlab: 'https://gitlab.com/api/v4',
|
|
140
113
|
bitbucket: 'https://api.bitbucket.org/2.0'
|
|
141
114
|
};
|
|
142
|
-
const endpointConstants =
|
|
115
|
+
export const endpointConstants = {
|
|
143
116
|
singleRepo: {
|
|
144
117
|
bitbucket: '/repositories',
|
|
145
118
|
github: '/repos',
|
|
@@ -168,38 +141,40 @@ async function constructRequestHeaders(headerConfig) {
|
|
|
168
141
|
token,
|
|
169
142
|
headers
|
|
170
143
|
} = headerConfig;
|
|
171
|
-
const baseHeaders =
|
|
172
|
-
'Content-Type': 'application/json; charset=utf-8'
|
|
173
|
-
|
|
144
|
+
const baseHeaders = {
|
|
145
|
+
'Content-Type': 'application/json; charset=utf-8',
|
|
146
|
+
...headers
|
|
147
|
+
};
|
|
174
148
|
if (token) {
|
|
175
149
|
baseHeaders['Authorization'] = `Bearer ${token}`;
|
|
176
150
|
}
|
|
177
151
|
return Promise.resolve(baseHeaders);
|
|
178
152
|
}
|
|
179
153
|
function handleRequestError(error, responseStatus, backend) {
|
|
180
|
-
throw new
|
|
154
|
+
throw new APIError(error.message, responseStatus, backend);
|
|
181
155
|
}
|
|
182
|
-
async function apiRequest(path, config, parser = response => parseResponse(response)) {
|
|
183
|
-
var _config$apiRoot;
|
|
156
|
+
export async function apiRequest(path, config, parser = response => parseResponse(response)) {
|
|
184
157
|
const {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
const options =
|
|
190
|
-
cache: 'no-cache'
|
|
191
|
-
|
|
158
|
+
token,
|
|
159
|
+
backend,
|
|
160
|
+
...props
|
|
161
|
+
} = config;
|
|
162
|
+
const options = {
|
|
163
|
+
cache: 'no-cache',
|
|
164
|
+
...props
|
|
165
|
+
};
|
|
192
166
|
const headers = await constructRequestHeaders({
|
|
193
167
|
headers: options.headers || {},
|
|
194
168
|
token
|
|
195
169
|
});
|
|
196
|
-
const baseUrl =
|
|
170
|
+
const baseUrl = config.apiRoot ?? apiRoots[backend];
|
|
197
171
|
const url = constructUrlWithParams(`${baseUrl}${path}`, options.params);
|
|
198
172
|
let responseStatus = 500;
|
|
199
173
|
try {
|
|
200
|
-
const req =
|
|
174
|
+
const req = unsentRequest.fromFetchArguments(url, {
|
|
175
|
+
...options,
|
|
201
176
|
headers
|
|
202
|
-
})
|
|
177
|
+
});
|
|
203
178
|
const response = await requestWithBackoff(api, req);
|
|
204
179
|
responseStatus = response.status;
|
|
205
180
|
const parsedResponse = await parser(response);
|
|
@@ -208,7 +183,7 @@ async function apiRequest(path, config, parser = response => parseResponse(respo
|
|
|
208
183
|
return handleRequestError(error, responseStatus, backend);
|
|
209
184
|
}
|
|
210
185
|
}
|
|
211
|
-
async function getDefaultBranchName(configs) {
|
|
186
|
+
export async function getDefaultBranchName(configs) {
|
|
212
187
|
let apiPath;
|
|
213
188
|
const {
|
|
214
189
|
token,
|
|
@@ -253,7 +228,7 @@ async function getDefaultBranchName(configs) {
|
|
|
253
228
|
}
|
|
254
229
|
return defaultBranchName;
|
|
255
230
|
}
|
|
256
|
-
async function readFile(id, fetchContent, localForage, isText) {
|
|
231
|
+
export async function readFile(id, fetchContent, localForage, isText) {
|
|
257
232
|
const key = id ? isText ? `gh.${id}` : `gh.${id}.blob` : null;
|
|
258
233
|
const cached = key ? await localForage.getItem(key) : null;
|
|
259
234
|
if (cached) {
|
|
@@ -268,7 +243,7 @@ async function readFile(id, fetchContent, localForage, isText) {
|
|
|
268
243
|
function getFileMetadataKey(id) {
|
|
269
244
|
return `gh.${id}.meta`;
|
|
270
245
|
}
|
|
271
|
-
async function readFileMetadata(id, fetchMetadata, localForage) {
|
|
246
|
+
export async function readFileMetadata(id, fetchMetadata, localForage) {
|
|
272
247
|
const key = id ? getFileMetadataKey(id) : null;
|
|
273
248
|
const cached = key && (await localForage.getItem(key));
|
|
274
249
|
if (cached) {
|
|
@@ -291,22 +266,23 @@ const PREVIEW_CONTEXT_KEYWORDS = ['deploy'];
|
|
|
291
266
|
* deploy preview. Checks for an exact match against `previewContext` if given,
|
|
292
267
|
* otherwise checks for inclusion of a value from `PREVIEW_CONTEXT_KEYWORDS`.
|
|
293
268
|
*/
|
|
294
|
-
function isPreviewContext(context, previewContext) {
|
|
269
|
+
export function isPreviewContext(context, previewContext) {
|
|
295
270
|
if (previewContext) {
|
|
296
271
|
return context === previewContext;
|
|
297
272
|
}
|
|
298
273
|
return PREVIEW_CONTEXT_KEYWORDS.some(keyword => context.includes(keyword));
|
|
299
274
|
}
|
|
300
|
-
let PreviewState =
|
|
275
|
+
export let PreviewState = /*#__PURE__*/function (PreviewState) {
|
|
301
276
|
PreviewState["Other"] = "other";
|
|
302
277
|
PreviewState["Success"] = "success";
|
|
303
278
|
return PreviewState;
|
|
304
279
|
}({});
|
|
280
|
+
|
|
305
281
|
/**
|
|
306
282
|
* Retrieve a deploy preview URL from an array of statuses. By default, a
|
|
307
283
|
* matching status is inferred via `isPreviewContext`.
|
|
308
284
|
*/
|
|
309
|
-
function getPreviewStatus(statuses, previewContext) {
|
|
285
|
+
export function getPreviewStatus(statuses, previewContext) {
|
|
310
286
|
return statuses.find(({
|
|
311
287
|
context
|
|
312
288
|
}) => {
|
|
@@ -323,11 +299,11 @@ function getConflictingBranches(branchName) {
|
|
|
323
299
|
}, []);
|
|
324
300
|
return conflictingBranches;
|
|
325
301
|
}
|
|
326
|
-
async function throwOnConflictingBranches(branchName, getBranch, apiName) {
|
|
302
|
+
export async function throwOnConflictingBranches(branchName, getBranch, apiName) {
|
|
327
303
|
const possibleConflictingBranches = getConflictingBranches(branchName);
|
|
328
304
|
const conflictingBranches = await Promise.all(possibleConflictingBranches.map(b => getBranch(b).then(b => b.name).catch(() => '')));
|
|
329
305
|
const conflictingBranch = conflictingBranches.filter(Boolean)[0];
|
|
330
306
|
if (conflictingBranch) {
|
|
331
|
-
throw new
|
|
307
|
+
throw new APIError(`Failed creating branch '${branchName}' since there is already a branch named '${conflictingBranch}'. Please delete the '${conflictingBranch}' branch and try again`, 500, apiName);
|
|
332
308
|
}
|
|
333
309
|
}
|
package/dist/esm/APIError.js
CHANGED
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = exports.API_ERROR = void 0;
|
|
7
|
-
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
8
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
|
|
9
|
-
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
10
1
|
function _extendableBuiltin(cls) {
|
|
11
2
|
function ExtendableBuiltin() {
|
|
12
3
|
var instance = Reflect.construct(cls, Array.from(arguments));
|
|
@@ -28,19 +19,14 @@ function _extendableBuiltin(cls) {
|
|
|
28
19
|
}
|
|
29
20
|
return ExtendableBuiltin;
|
|
30
21
|
}
|
|
31
|
-
const API_ERROR =
|
|
32
|
-
class APIError extends _extendableBuiltin(Error) {
|
|
22
|
+
export const API_ERROR = 'API_ERROR';
|
|
23
|
+
export default class APIError extends _extendableBuiltin(Error) {
|
|
33
24
|
constructor(message, status, api, meta = {}) {
|
|
34
25
|
super(message);
|
|
35
|
-
_defineProperty(this, "message", void 0);
|
|
36
|
-
_defineProperty(this, "status", void 0);
|
|
37
|
-
_defineProperty(this, "api", void 0);
|
|
38
|
-
_defineProperty(this, "meta", void 0);
|
|
39
26
|
this.message = message;
|
|
40
27
|
this.status = status;
|
|
41
28
|
this.api = api;
|
|
42
29
|
this.name = API_ERROR;
|
|
43
30
|
this.meta = meta;
|
|
44
31
|
}
|
|
45
|
-
}
|
|
46
|
-
exports.default = APIError;
|
|
32
|
+
}
|
package/dist/esm/APIUtils.js
CHANGED
|
@@ -1,45 +1,32 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.MERGE_COMMIT_MESSAGE = exports.DEFAULT_PR_BODY = exports.CMS_BRANCH_PREFIX = void 0;
|
|
7
|
-
exports.branchFromContentKey = branchFromContentKey;
|
|
8
|
-
exports.contentKeyFromBranch = contentKeyFromBranch;
|
|
9
|
-
exports.generateContentKey = generateContentKey;
|
|
10
|
-
exports.isCMSLabel = isCMSLabel;
|
|
11
|
-
exports.labelToStatus = labelToStatus;
|
|
12
|
-
exports.parseContentKey = parseContentKey;
|
|
13
|
-
exports.statusToLabel = statusToLabel;
|
|
14
|
-
const CMS_BRANCH_PREFIX = exports.CMS_BRANCH_PREFIX = 'cms';
|
|
15
|
-
const DEFAULT_PR_BODY = exports.DEFAULT_PR_BODY = 'Automatically generated by Decap CMS';
|
|
16
|
-
const MERGE_COMMIT_MESSAGE = exports.MERGE_COMMIT_MESSAGE = 'Automatically generated. Merged on Decap CMS.';
|
|
1
|
+
export const CMS_BRANCH_PREFIX = 'cms';
|
|
2
|
+
export const DEFAULT_PR_BODY = 'Automatically generated by Decap CMS';
|
|
3
|
+
export const MERGE_COMMIT_MESSAGE = 'Automatically generated. Merged on Decap CMS.';
|
|
17
4
|
const DEFAULT_DECAP_CMS_LABEL_PREFIX = 'decap-cms/';
|
|
18
5
|
function getLabelPrefix(labelPrefix) {
|
|
19
6
|
return labelPrefix || DEFAULT_DECAP_CMS_LABEL_PREFIX;
|
|
20
7
|
}
|
|
21
|
-
function isCMSLabel(label, labelPrefix) {
|
|
8
|
+
export function isCMSLabel(label, labelPrefix) {
|
|
22
9
|
return label.startsWith(getLabelPrefix(labelPrefix));
|
|
23
10
|
}
|
|
24
|
-
function labelToStatus(label, labelPrefix) {
|
|
11
|
+
export function labelToStatus(label, labelPrefix) {
|
|
25
12
|
return label.slice(getLabelPrefix(labelPrefix).length);
|
|
26
13
|
}
|
|
27
|
-
function statusToLabel(status, labelPrefix) {
|
|
14
|
+
export function statusToLabel(status, labelPrefix) {
|
|
28
15
|
return `${getLabelPrefix(labelPrefix)}${status}`;
|
|
29
16
|
}
|
|
30
|
-
function generateContentKey(collectionName, slug) {
|
|
17
|
+
export function generateContentKey(collectionName, slug) {
|
|
31
18
|
return `${collectionName}/${slug}`;
|
|
32
19
|
}
|
|
33
|
-
function parseContentKey(contentKey) {
|
|
20
|
+
export function parseContentKey(contentKey) {
|
|
34
21
|
const index = contentKey.indexOf('/');
|
|
35
22
|
return {
|
|
36
23
|
collection: contentKey.slice(0, index),
|
|
37
24
|
slug: contentKey.slice(index + 1)
|
|
38
25
|
};
|
|
39
26
|
}
|
|
40
|
-
function contentKeyFromBranch(branch) {
|
|
27
|
+
export function contentKeyFromBranch(branch) {
|
|
41
28
|
return branch.slice(`${CMS_BRANCH_PREFIX}/`.length);
|
|
42
29
|
}
|
|
43
|
-
function branchFromContentKey(contentKey) {
|
|
30
|
+
export function branchFromContentKey(contentKey) {
|
|
44
31
|
return `${CMS_BRANCH_PREFIX}/${contentKey}`;
|
|
45
32
|
}
|
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = exports.ACCESS_TOKEN_ERROR = void 0;
|
|
7
|
-
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
8
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
|
|
9
|
-
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
10
1
|
function _extendableBuiltin(cls) {
|
|
11
2
|
function ExtendableBuiltin() {
|
|
12
3
|
var instance = Reflect.construct(cls, Array.from(arguments));
|
|
@@ -28,13 +19,11 @@ function _extendableBuiltin(cls) {
|
|
|
28
19
|
}
|
|
29
20
|
return ExtendableBuiltin;
|
|
30
21
|
}
|
|
31
|
-
const ACCESS_TOKEN_ERROR =
|
|
32
|
-
class AccessTokenError extends _extendableBuiltin(Error) {
|
|
22
|
+
export const ACCESS_TOKEN_ERROR = 'ACCESS_TOKEN_ERROR';
|
|
23
|
+
export default class AccessTokenError extends _extendableBuiltin(Error) {
|
|
33
24
|
constructor(message) {
|
|
34
25
|
super(message);
|
|
35
|
-
_defineProperty(this, "message", void 0);
|
|
36
26
|
this.message = message;
|
|
37
27
|
this.name = ACCESS_TOKEN_ERROR;
|
|
38
28
|
}
|
|
39
|
-
}
|
|
40
|
-
exports.default = AccessTokenError;
|
|
29
|
+
}
|
package/dist/esm/Cursor.js
CHANGED
|
@@ -1,24 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = exports.CURSOR_COMPATIBILITY_SYMBOL = void 0;
|
|
7
|
-
var _immutable = require("immutable");
|
|
8
|
-
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
9
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
|
|
10
|
-
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
1
|
+
import { fromJS, Map, Set } from 'immutable';
|
|
11
2
|
function jsToMap(obj) {
|
|
12
3
|
if (obj === undefined) {
|
|
13
|
-
return
|
|
4
|
+
return Map();
|
|
14
5
|
}
|
|
15
|
-
const immutableObj =
|
|
16
|
-
if (!
|
|
6
|
+
const immutableObj = fromJS(obj);
|
|
7
|
+
if (!Map.isMap(immutableObj)) {
|
|
17
8
|
throw new Error('Object must be equivalent to a Map.');
|
|
18
9
|
}
|
|
19
10
|
return immutableObj;
|
|
20
11
|
}
|
|
21
|
-
const knownMetaKeys =
|
|
12
|
+
const knownMetaKeys = Set(['index', 'page', 'count', 'pageSize', 'pageCount', 'usingOldPaginationAPI', 'extension', 'folder', 'depth']);
|
|
22
13
|
function filterUnknownMetaKeys(meta) {
|
|
23
14
|
return meta.filter((_v, k) => knownMetaKeys.has(k));
|
|
24
15
|
}
|
|
@@ -39,9 +30,9 @@ function createCursorStore(...args) {
|
|
|
39
30
|
data: args[1],
|
|
40
31
|
meta: args[2]
|
|
41
32
|
};
|
|
42
|
-
return
|
|
33
|
+
return Map({
|
|
43
34
|
// actions are a Set, rather than a List, to ensure an efficient .has
|
|
44
|
-
actions:
|
|
35
|
+
actions: Set(actions),
|
|
45
36
|
// data and meta are Maps
|
|
46
37
|
data: jsToMap(data),
|
|
47
38
|
meta: jsToMap(meta).update(filterUnknownMetaKeys)
|
|
@@ -51,22 +42,20 @@ function hasAction(store, action) {
|
|
|
51
42
|
return store.hasIn(['actions', action]);
|
|
52
43
|
}
|
|
53
44
|
function getActionHandlers(store, handler) {
|
|
54
|
-
return store.get('actions',
|
|
45
|
+
return store.get('actions', Set()).toMap().map(action => handler(action));
|
|
55
46
|
}
|
|
56
47
|
|
|
57
48
|
// The cursor logic is entirely functional, so this class simply
|
|
58
49
|
// provides a chainable interface
|
|
59
|
-
class Cursor {
|
|
50
|
+
export default class Cursor {
|
|
51
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
52
|
+
|
|
53
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
54
|
+
|
|
60
55
|
static create(...args) {
|
|
61
56
|
return new Cursor(...args);
|
|
62
57
|
}
|
|
63
58
|
constructor(...args) {
|
|
64
|
-
_defineProperty(this, "store", void 0);
|
|
65
|
-
_defineProperty(this, "actions", void 0);
|
|
66
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
67
|
-
_defineProperty(this, "data", void 0);
|
|
68
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
69
|
-
_defineProperty(this, "meta", void 0);
|
|
70
59
|
if (args[0] instanceof Cursor) {
|
|
71
60
|
return args[0];
|
|
72
61
|
}
|
|
@@ -94,7 +83,7 @@ class Cursor {
|
|
|
94
83
|
return this.updateStore('actions', actions => actions.delete(action));
|
|
95
84
|
}
|
|
96
85
|
setActions(actions) {
|
|
97
|
-
return this.updateStore(store => store.set('actions',
|
|
86
|
+
return this.updateStore(store => store.set('actions', Set(actions)));
|
|
98
87
|
}
|
|
99
88
|
mergeActions(actions) {
|
|
100
89
|
return this.updateStore('actions', oldActions => oldActions.union(actions));
|
|
@@ -115,7 +104,7 @@ class Cursor {
|
|
|
115
104
|
return [this.store.get('data').delete('wrapped_cursor_data'), this.updateStore('data', data => data.get('wrapped_cursor_data'))];
|
|
116
105
|
}
|
|
117
106
|
clearData() {
|
|
118
|
-
return this.updateStore('data', () =>
|
|
107
|
+
return this.updateStore('data', () => Map());
|
|
119
108
|
}
|
|
120
109
|
setMeta(meta) {
|
|
121
110
|
return this.updateStore(store => store.set('meta', jsToMap(meta)));
|
|
@@ -130,5 +119,4 @@ class Cursor {
|
|
|
130
119
|
// backends at all. This should be removed in favor of wrapping old
|
|
131
120
|
// backends with a compatibility layer, as part of the backend API
|
|
132
121
|
// refactor.
|
|
133
|
-
|
|
134
|
-
const CURSOR_COMPATIBILITY_SYMBOL = exports.CURSOR_COMPATIBILITY_SYMBOL = Symbol('cursor key for compatibility with old backends');
|
|
122
|
+
export const CURSOR_COMPATIBILITY_SYMBOL = Symbol('cursor key for compatibility with old backends');
|
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = exports.EDITORIAL_WORKFLOW_ERROR = void 0;
|
|
7
|
-
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
8
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
|
|
9
|
-
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
10
1
|
function _extendableBuiltin(cls) {
|
|
11
2
|
function ExtendableBuiltin() {
|
|
12
3
|
var instance = Reflect.construct(cls, Array.from(arguments));
|
|
@@ -28,15 +19,12 @@ function _extendableBuiltin(cls) {
|
|
|
28
19
|
}
|
|
29
20
|
return ExtendableBuiltin;
|
|
30
21
|
}
|
|
31
|
-
const EDITORIAL_WORKFLOW_ERROR =
|
|
32
|
-
class EditorialWorkflowError extends _extendableBuiltin(Error) {
|
|
22
|
+
export const EDITORIAL_WORKFLOW_ERROR = 'EDITORIAL_WORKFLOW_ERROR';
|
|
23
|
+
export default class EditorialWorkflowError extends _extendableBuiltin(Error) {
|
|
33
24
|
constructor(message, notUnderEditorialWorkflow) {
|
|
34
25
|
super(message);
|
|
35
|
-
_defineProperty(this, "message", void 0);
|
|
36
|
-
_defineProperty(this, "notUnderEditorialWorkflow", void 0);
|
|
37
26
|
this.message = message;
|
|
38
27
|
this.notUnderEditorialWorkflow = notUnderEditorialWorkflow;
|
|
39
28
|
this.name = EDITORIAL_WORKFLOW_ERROR;
|
|
40
29
|
}
|
|
41
|
-
}
|
|
42
|
-
exports.default = EditorialWorkflowError;
|
|
30
|
+
}
|
package/dist/esm/asyncLock.js
CHANGED
|
@@ -1,19 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.asyncLock = asyncLock;
|
|
7
|
-
var _semaphore = _interopRequireDefault(require("semaphore"));
|
|
8
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
9
|
-
function asyncLock() {
|
|
10
|
-
let lock = (0, _semaphore.default)(1);
|
|
1
|
+
import semaphore from 'semaphore';
|
|
2
|
+
export function asyncLock() {
|
|
3
|
+
let lock = semaphore(1);
|
|
11
4
|
function acquire(timeout = 15000) {
|
|
12
5
|
const promise = new Promise(resolve => {
|
|
13
6
|
// this makes sure a caller doesn't gets stuck forever awaiting on the lock
|
|
14
7
|
const timeoutId = setTimeout(() => {
|
|
15
8
|
// we reset the lock in that case to allow future consumers to use it without being blocked
|
|
16
|
-
lock = (
|
|
9
|
+
lock = semaphore(1);
|
|
17
10
|
resolve(false);
|
|
18
11
|
}, timeout);
|
|
19
12
|
lock.take(() => {
|
|
@@ -34,7 +27,7 @@ function asyncLock() {
|
|
|
34
27
|
throw e;
|
|
35
28
|
} else {
|
|
36
29
|
console.warn('leave called too many times.');
|
|
37
|
-
lock = (
|
|
30
|
+
lock = semaphore(1);
|
|
38
31
|
}
|
|
39
32
|
}
|
|
40
33
|
}
|
package/dist/esm/backendUtil.js
CHANGED
|
@@ -1,23 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
exports.parseLinkHeader = parseLinkHeader;
|
|
10
|
-
exports.parseResponse = parseResponse;
|
|
11
|
-
exports.responseParser = responseParser;
|
|
12
|
-
var _map2 = _interopRequireDefault(require("lodash/fp/map"));
|
|
13
|
-
var _fromPairs2 = _interopRequireDefault(require("lodash/fromPairs"));
|
|
14
|
-
var _flow2 = _interopRequireDefault(require("lodash/flow"));
|
|
15
|
-
var _immutable = require("immutable");
|
|
16
|
-
var _unsentRequest = _interopRequireDefault(require("./unsentRequest"));
|
|
17
|
-
var _APIError = _interopRequireDefault(require("./APIError"));
|
|
18
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
|
-
function filterByExtension(file, extension) {
|
|
20
|
-
const path = (file === null || file === void 0 ? void 0 : file.path) || '';
|
|
1
|
+
import flow from 'lodash/flow';
|
|
2
|
+
import fromPairs from 'lodash/fromPairs';
|
|
3
|
+
import { map } from 'lodash/fp';
|
|
4
|
+
import { fromJS } from 'immutable';
|
|
5
|
+
import unsentRequest from './unsentRequest';
|
|
6
|
+
import APIError from './APIError';
|
|
7
|
+
export function filterByExtension(file, extension) {
|
|
8
|
+
const path = file?.path || '';
|
|
21
9
|
return path.endsWith(extension.startsWith('.') ? extension : `.${extension}`);
|
|
22
10
|
}
|
|
23
11
|
function catchFormatErrors(format, formatter) {
|
|
@@ -29,7 +17,7 @@ function catchFormatErrors(format, formatter) {
|
|
|
29
17
|
}
|
|
30
18
|
};
|
|
31
19
|
}
|
|
32
|
-
const responseFormatters =
|
|
20
|
+
const responseFormatters = fromJS({
|
|
33
21
|
json: async res => {
|
|
34
22
|
const contentType = res.headers.get('Content-Type') || '';
|
|
35
23
|
if (!contentType.startsWith('application/json') && !contentType.startsWith('text/json')) {
|
|
@@ -40,7 +28,7 @@ const responseFormatters = (0, _immutable.fromJS)({
|
|
|
40
28
|
text: async res => res.text(),
|
|
41
29
|
blob: async res => res.blob()
|
|
42
30
|
}).mapEntries(([format, formatter]) => [format, catchFormatErrors(format, formatter)]);
|
|
43
|
-
async function parseResponse(res, {
|
|
31
|
+
export async function parseResponse(res, {
|
|
44
32
|
expectingOk = true,
|
|
45
33
|
format = 'text',
|
|
46
34
|
apiName = ''
|
|
@@ -53,38 +41,37 @@ async function parseResponse(res, {
|
|
|
53
41
|
}
|
|
54
42
|
body = await formatter(res);
|
|
55
43
|
} catch (err) {
|
|
56
|
-
throw new
|
|
44
|
+
throw new APIError(err.message, res.status, apiName);
|
|
57
45
|
}
|
|
58
46
|
if (expectingOk && !res.ok) {
|
|
59
|
-
var _body$error;
|
|
60
47
|
const isJSON = format === 'json';
|
|
61
|
-
const message = isJSON ? body.message || body.msg ||
|
|
62
|
-
throw new
|
|
48
|
+
const message = isJSON ? body.message || body.msg || body.error?.message : body;
|
|
49
|
+
throw new APIError(isJSON && message ? message : body, res.status, apiName);
|
|
63
50
|
}
|
|
64
51
|
return body;
|
|
65
52
|
}
|
|
66
|
-
function responseParser(options) {
|
|
53
|
+
export function responseParser(options) {
|
|
67
54
|
return res => parseResponse(res, options);
|
|
68
55
|
}
|
|
69
|
-
function parseLinkHeader(header) {
|
|
56
|
+
export function parseLinkHeader(header) {
|
|
70
57
|
if (!header) {
|
|
71
58
|
return {};
|
|
72
59
|
}
|
|
73
|
-
return (
|
|
60
|
+
return flow([linksString => linksString.split(','), map(str => str.trim().split(';')), map(([linkStr, keyStr]) => [keyStr.match(/rel="(.*?)"/)[1], linkStr.trim().match(/<(.*?)>/)[1].replace(/\+/g, '%20')]), fromPairs])(header);
|
|
74
61
|
}
|
|
75
|
-
async function getAllResponses(url, options = {}, linkHeaderRelName, nextUrlProcessor) {
|
|
62
|
+
export async function getAllResponses(url, options = {}, linkHeaderRelName, nextUrlProcessor) {
|
|
76
63
|
const maxResponses = 30;
|
|
77
64
|
let responseCount = 1;
|
|
78
|
-
let req =
|
|
65
|
+
let req = unsentRequest.fromFetchArguments(url, options);
|
|
79
66
|
const pageResponses = [];
|
|
80
67
|
while (req && responseCount < maxResponses) {
|
|
81
|
-
const pageResponse = await
|
|
68
|
+
const pageResponse = await unsentRequest.performRequest(req);
|
|
82
69
|
const linkHeader = pageResponse.headers.get('Link');
|
|
83
70
|
const nextURL = linkHeader && parseLinkHeader(linkHeader)[linkHeaderRelName];
|
|
84
71
|
const {
|
|
85
72
|
headers = {}
|
|
86
73
|
} = options;
|
|
87
|
-
req = nextURL &&
|
|
74
|
+
req = nextURL && unsentRequest.fromFetchArguments(nextUrlProcessor(nextURL), {
|
|
88
75
|
headers
|
|
89
76
|
});
|
|
90
77
|
pageResponses.push(pageResponse);
|
|
@@ -92,7 +79,7 @@ async function getAllResponses(url, options = {}, linkHeaderRelName, nextUrlProc
|
|
|
92
79
|
}
|
|
93
80
|
return pageResponses;
|
|
94
81
|
}
|
|
95
|
-
function getPathDepth(path) {
|
|
82
|
+
export function getPathDepth(path) {
|
|
96
83
|
const depth = path.split('/').length;
|
|
97
84
|
return depth;
|
|
98
85
|
}
|
package/dist/esm/getBlobSHA.js
CHANGED
|
@@ -1,19 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _jsSha = require("js-sha256");
|
|
8
|
-
var _default = blob => new Promise((resolve, reject) => {
|
|
1
|
+
import { sha256 } from 'js-sha256';
|
|
2
|
+
export default blob => new Promise((resolve, reject) => {
|
|
9
3
|
const fr = new FileReader();
|
|
10
4
|
fr.onload = ({
|
|
11
5
|
target
|
|
12
|
-
}) => resolve(
|
|
6
|
+
}) => resolve(sha256(target?.result || ''));
|
|
13
7
|
fr.onerror = err => {
|
|
14
8
|
fr.abort();
|
|
15
9
|
reject(err);
|
|
16
10
|
};
|
|
17
11
|
fr.readAsArrayBuffer(blob);
|
|
18
|
-
});
|
|
19
|
-
exports.default = _default;
|
|
12
|
+
});
|