decap-cms-core 2.56.0-beta.1
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/LICENSE +22 -0
- package/README.md +9 -0
- package/dist/decap-cms-core.js +47 -0
- package/dist/decap-cms-core.js.LICENSE.txt +109 -0
- package/dist/decap-cms-core.js.map +1 -0
- package/dist/esm/actions/auth.js +118 -0
- package/dist/esm/actions/collections.js +23 -0
- package/dist/esm/actions/config.js +482 -0
- package/dist/esm/actions/deploys.js +89 -0
- package/dist/esm/actions/editorialWorkflow.js +511 -0
- package/dist/esm/actions/entries.js +940 -0
- package/dist/esm/actions/media.js +168 -0
- package/dist/esm/actions/mediaLibrary.js +606 -0
- package/dist/esm/actions/notifications.js +32 -0
- package/dist/esm/actions/search.js +156 -0
- package/dist/esm/actions/status.js +93 -0
- package/dist/esm/actions/waitUntil.js +39 -0
- package/dist/esm/backend.js +1073 -0
- package/dist/esm/bootstrap.js +107 -0
- package/dist/esm/components/App/App.js +301 -0
- package/dist/esm/components/App/Header.js +162 -0
- package/dist/esm/components/App/NotFoundPage.js +27 -0
- package/dist/esm/components/Collection/Collection.js +210 -0
- package/dist/esm/components/Collection/CollectionControls.js +54 -0
- package/dist/esm/components/Collection/CollectionSearch.js +235 -0
- package/dist/esm/components/Collection/CollectionTop.js +77 -0
- package/dist/esm/components/Collection/ControlButton.js +23 -0
- package/dist/esm/components/Collection/Entries/Entries.js +74 -0
- package/dist/esm/components/Collection/Entries/EntriesCollection.js +193 -0
- package/dist/esm/components/Collection/Entries/EntriesSearch.js +117 -0
- package/dist/esm/components/Collection/Entries/EntryCard.js +134 -0
- package/dist/esm/components/Collection/Entries/EntryListing.js +120 -0
- package/dist/esm/components/Collection/FilterControl.js +41 -0
- package/dist/esm/components/Collection/GroupControl.js +41 -0
- package/dist/esm/components/Collection/NestedCollection.js +311 -0
- package/dist/esm/components/Collection/Sidebar.js +102 -0
- package/dist/esm/components/Collection/SortControl.js +67 -0
- package/dist/esm/components/Collection/ViewStyleControl.js +47 -0
- package/dist/esm/components/Editor/Editor.js +479 -0
- package/dist/esm/components/Editor/EditorControlPane/EditorControl.js +393 -0
- package/dist/esm/components/Editor/EditorControlPane/EditorControlPane.js +259 -0
- package/dist/esm/components/Editor/EditorControlPane/Widget.js +355 -0
- package/dist/esm/components/Editor/EditorInterface.js +401 -0
- package/dist/esm/components/Editor/EditorPreviewPane/EditorPreview.js +56 -0
- package/dist/esm/components/Editor/EditorPreviewPane/EditorPreviewContent.js +34 -0
- package/dist/esm/components/Editor/EditorPreviewPane/EditorPreviewPane.js +252 -0
- package/dist/esm/components/Editor/EditorPreviewPane/PreviewHOC.js +39 -0
- package/dist/esm/components/Editor/EditorToolbar.js +551 -0
- package/dist/esm/components/Editor/withWorkflow.js +64 -0
- package/dist/esm/components/EditorWidgets/Unknown/UnknownControl.js +26 -0
- package/dist/esm/components/EditorWidgets/Unknown/UnknownPreview.js +28 -0
- package/dist/esm/components/EditorWidgets/index.js +7 -0
- package/dist/esm/components/MediaLibrary/EmptyMessage.js +30 -0
- package/dist/esm/components/MediaLibrary/MediaLibrary.js +444 -0
- package/dist/esm/components/MediaLibrary/MediaLibraryButtons.js +110 -0
- package/dist/esm/components/MediaLibrary/MediaLibraryCard.js +108 -0
- package/dist/esm/components/MediaLibrary/MediaLibraryCardGrid.js +211 -0
- package/dist/esm/components/MediaLibrary/MediaLibraryHeader.js +40 -0
- package/dist/esm/components/MediaLibrary/MediaLibraryModal.js +163 -0
- package/dist/esm/components/MediaLibrary/MediaLibrarySearch.js +60 -0
- package/dist/esm/components/MediaLibrary/MediaLibraryTop.js +134 -0
- package/dist/esm/components/UI/DragDrop.js +84 -0
- package/dist/esm/components/UI/ErrorBoundary.js +184 -0
- package/dist/esm/components/UI/FileUploadButton.js +34 -0
- package/dist/esm/components/UI/Modal.js +113 -0
- package/dist/esm/components/UI/Notifications.js +74 -0
- package/dist/esm/components/UI/SettingsDropdown.js +118 -0
- package/dist/esm/components/UI/index.js +60 -0
- package/dist/esm/components/Workflow/Workflow.js +144 -0
- package/dist/esm/components/Workflow/WorkflowCard.js +137 -0
- package/dist/esm/components/Workflow/WorkflowList.js +219 -0
- package/dist/esm/constants/collectionTypes.js +10 -0
- package/dist/esm/constants/collectionViews.js +10 -0
- package/dist/esm/constants/commitProps.js +10 -0
- package/dist/esm/constants/configSchema.js +594 -0
- package/dist/esm/constants/fieldInference.js +67 -0
- package/dist/esm/constants/publishModes.js +28 -0
- package/dist/esm/constants/validationErrorTypes.js +13 -0
- package/dist/esm/formats/formats.js +82 -0
- package/dist/esm/formats/frontmatter.js +163 -0
- package/dist/esm/formats/helpers.js +18 -0
- package/dist/esm/formats/json.js +15 -0
- package/dist/esm/formats/toml.js +40 -0
- package/dist/esm/formats/yaml.js +63 -0
- package/dist/esm/index.js +20 -0
- package/dist/esm/integrations/index.js +37 -0
- package/dist/esm/integrations/providers/algolia/implementation.js +184 -0
- package/dist/esm/integrations/providers/assetStore/implementation.js +175 -0
- package/dist/esm/lib/consoleError.js +9 -0
- package/dist/esm/lib/formatters.js +204 -0
- package/dist/esm/lib/i18n.js +381 -0
- package/dist/esm/lib/phrases.js +13 -0
- package/dist/esm/lib/registry.js +322 -0
- package/dist/esm/lib/serializeEntryValues.js +74 -0
- package/dist/esm/lib/textHelper.js +15 -0
- package/dist/esm/lib/urlHelper.js +128 -0
- package/dist/esm/mediaLibrary.js +42 -0
- package/dist/esm/reducers/auth.js +35 -0
- package/dist/esm/reducers/collections.js +424 -0
- package/dist/esm/reducers/combinedReducer.js +19 -0
- package/dist/esm/reducers/config.js +42 -0
- package/dist/esm/reducers/cursors.js +38 -0
- package/dist/esm/reducers/deploys.js +53 -0
- package/dist/esm/reducers/editorialWorkflow.js +98 -0
- package/dist/esm/reducers/entries.js +591 -0
- package/dist/esm/reducers/entryDraft.js +184 -0
- package/dist/esm/reducers/globalUI.js +32 -0
- package/dist/esm/reducers/index.js +84 -0
- package/dist/esm/reducers/integrations.js +68 -0
- package/dist/esm/reducers/mediaLibrary.js +265 -0
- package/dist/esm/reducers/medias.js +76 -0
- package/dist/esm/reducers/notifications.js +36 -0
- package/dist/esm/reducers/search.js +89 -0
- package/dist/esm/reducers/status.js +37 -0
- package/dist/esm/redux/index.js +14 -0
- package/dist/esm/redux/middleware/waitUntilAction.js +56 -0
- package/dist/esm/routing/history.js +21 -0
- package/dist/esm/types/diacritics.d.js +1 -0
- package/dist/esm/types/global.d.js +5 -0
- package/dist/esm/types/immutable.js +5 -0
- package/dist/esm/types/redux.js +16 -0
- package/dist/esm/types/tomlify-j0.4.d.js +1 -0
- package/dist/esm/valueObjects/AssetProxy.js +60 -0
- package/dist/esm/valueObjects/EditorComponent.js +48 -0
- package/dist/esm/valueObjects/Entry.js +27 -0
- package/index.d.ts +587 -0
- package/package.json +102 -0
- package/src/__tests__/backend.spec.js +934 -0
- package/src/actions/__tests__/config.spec.js +1009 -0
- package/src/actions/__tests__/editorialWorkflow.spec.js +216 -0
- package/src/actions/__tests__/entries.spec.js +575 -0
- package/src/actions/__tests__/media.spec.ts +171 -0
- package/src/actions/__tests__/mediaLibrary.spec.js +327 -0
- package/src/actions/__tests__/search.spec.js +209 -0
- package/src/actions/auth.ts +127 -0
- package/src/actions/collections.ts +18 -0
- package/src/actions/config.ts +538 -0
- package/src/actions/deploys.ts +104 -0
- package/src/actions/editorialWorkflow.ts +567 -0
- package/src/actions/entries.ts +1041 -0
- package/src/actions/media.ts +139 -0
- package/src/actions/mediaLibrary.ts +574 -0
- package/src/actions/notifications.ts +36 -0
- package/src/actions/search.ts +194 -0
- package/src/actions/status.ts +99 -0
- package/src/actions/waitUntil.ts +49 -0
- package/src/backend.ts +1342 -0
- package/src/bootstrap.js +102 -0
- package/src/components/App/App.js +280 -0
- package/src/components/App/Header.js +236 -0
- package/src/components/App/NotFoundPage.js +23 -0
- package/src/components/Collection/Collection.js +205 -0
- package/src/components/Collection/CollectionControls.js +58 -0
- package/src/components/Collection/CollectionSearch.js +238 -0
- package/src/components/Collection/CollectionTop.js +81 -0
- package/src/components/Collection/ControlButton.js +27 -0
- package/src/components/Collection/Entries/Entries.js +73 -0
- package/src/components/Collection/Entries/EntriesCollection.js +165 -0
- package/src/components/Collection/Entries/EntriesSearch.js +91 -0
- package/src/components/Collection/Entries/EntryCard.js +167 -0
- package/src/components/Collection/Entries/EntryListing.js +86 -0
- package/src/components/Collection/Entries/__tests__/EntriesCollection.spec.js +155 -0
- package/src/components/Collection/Entries/__tests__/__snapshots__/EntriesCollection.spec.js.snap +49 -0
- package/src/components/Collection/FilterControl.js +39 -0
- package/src/components/Collection/GroupControl.js +39 -0
- package/src/components/Collection/NestedCollection.js +309 -0
- package/src/components/Collection/Sidebar.js +130 -0
- package/src/components/Collection/SortControl.js +68 -0
- package/src/components/Collection/ViewStyleControl.js +50 -0
- package/src/components/Collection/__tests__/Collection.spec.js +75 -0
- package/src/components/Collection/__tests__/NestedCollection.spec.js +442 -0
- package/src/components/Collection/__tests__/Sidebar.spec.js +87 -0
- package/src/components/Collection/__tests__/__snapshots__/Collection.spec.js.snap +144 -0
- package/src/components/Collection/__tests__/__snapshots__/NestedCollection.spec.js.snap +550 -0
- package/src/components/Collection/__tests__/__snapshots__/Sidebar.spec.js.snap +308 -0
- package/src/components/Editor/Editor.js +494 -0
- package/src/components/Editor/EditorControlPane/EditorControl.js +428 -0
- package/src/components/Editor/EditorControlPane/EditorControlPane.js +256 -0
- package/src/components/Editor/EditorControlPane/Widget.js +351 -0
- package/src/components/Editor/EditorInterface.js +434 -0
- package/src/components/Editor/EditorPreviewPane/EditorPreview.js +40 -0
- package/src/components/Editor/EditorPreviewPane/EditorPreviewContent.js +34 -0
- package/src/components/Editor/EditorPreviewPane/EditorPreviewPane.js +278 -0
- package/src/components/Editor/EditorPreviewPane/PreviewHOC.js +33 -0
- package/src/components/Editor/EditorToolbar.js +678 -0
- package/src/components/Editor/__tests__/Editor.spec.js +219 -0
- package/src/components/Editor/__tests__/EditorToolbar.spec.js +120 -0
- package/src/components/Editor/__tests__/__snapshots__/Editor.spec.js.snap +45 -0
- package/src/components/Editor/__tests__/__snapshots__/EditorToolbar.spec.js.snap +4020 -0
- package/src/components/Editor/withWorkflow.js +61 -0
- package/src/components/EditorWidgets/Unknown/UnknownControl.js +17 -0
- package/src/components/EditorWidgets/Unknown/UnknownPreview.js +19 -0
- package/src/components/EditorWidgets/index.js +5 -0
- package/src/components/MediaLibrary/EmptyMessage.js +28 -0
- package/src/components/MediaLibrary/MediaLibrary.js +407 -0
- package/src/components/MediaLibrary/MediaLibraryButtons.js +136 -0
- package/src/components/MediaLibrary/MediaLibraryCard.js +128 -0
- package/src/components/MediaLibrary/MediaLibraryCardGrid.js +199 -0
- package/src/components/MediaLibrary/MediaLibraryHeader.js +48 -0
- package/src/components/MediaLibrary/MediaLibraryModal.js +200 -0
- package/src/components/MediaLibrary/MediaLibrarySearch.js +61 -0
- package/src/components/MediaLibrary/MediaLibraryTop.js +143 -0
- package/src/components/MediaLibrary/__tests__/MediaLibraryButtons.spec.js +45 -0
- package/src/components/MediaLibrary/__tests__/MediaLibraryCard.spec.js +49 -0
- package/src/components/MediaLibrary/__tests__/__snapshots__/MediaLibraryCard.spec.js.snap +216 -0
- package/src/components/UI/DragDrop.js +66 -0
- package/src/components/UI/ErrorBoundary.js +209 -0
- package/src/components/UI/FileUploadButton.js +24 -0
- package/src/components/UI/Modal.js +109 -0
- package/src/components/UI/Notifications.tsx +83 -0
- package/src/components/UI/SettingsDropdown.js +103 -0
- package/src/components/UI/__tests__/ErrorBoundary.spec.js +57 -0
- package/src/components/UI/index.js +6 -0
- package/src/components/Workflow/Workflow.js +166 -0
- package/src/components/Workflow/WorkflowCard.js +177 -0
- package/src/components/Workflow/WorkflowList.js +269 -0
- package/src/constants/__tests__/configSchema.spec.js +511 -0
- package/src/constants/collectionTypes.ts +2 -0
- package/src/constants/collectionViews.js +2 -0
- package/src/constants/commitProps.ts +2 -0
- package/src/constants/configSchema.js +399 -0
- package/src/constants/fieldInference.tsx +78 -0
- package/src/constants/publishModes.ts +22 -0
- package/src/constants/validationErrorTypes.js +6 -0
- package/src/formats/__tests__/frontmatter.spec.js +429 -0
- package/src/formats/__tests__/toml.spec.js +9 -0
- package/src/formats/__tests__/yaml.spec.js +162 -0
- package/src/formats/formats.ts +86 -0
- package/src/formats/frontmatter.ts +150 -0
- package/src/formats/helpers.ts +14 -0
- package/src/formats/json.ts +9 -0
- package/src/formats/toml.ts +33 -0
- package/src/formats/yaml.ts +58 -0
- package/src/index.js +8 -0
- package/src/integrations/index.js +35 -0
- package/src/integrations/providers/algolia/implementation.js +176 -0
- package/src/integrations/providers/assetStore/implementation.js +147 -0
- package/src/lib/__tests__/formatters.spec.js +723 -0
- package/src/lib/__tests__/i18n.spec.js +792 -0
- package/src/lib/__tests__/phrases.spec.js +119 -0
- package/src/lib/__tests__/registry.spec.js +246 -0
- package/src/lib/__tests__/serializeEntryValues.spec.js +22 -0
- package/src/lib/__tests__/urlHelper.spec.js +138 -0
- package/src/lib/consoleError.js +7 -0
- package/src/lib/formatters.ts +267 -0
- package/src/lib/i18n.ts +427 -0
- package/src/lib/phrases.js +8 -0
- package/src/lib/registry.js +282 -0
- package/src/lib/serializeEntryValues.js +75 -0
- package/src/lib/textHelper.js +11 -0
- package/src/lib/urlHelper.ts +125 -0
- package/src/mediaLibrary.ts +51 -0
- package/src/reducers/__tests__/auth.spec.ts +38 -0
- package/src/reducers/__tests__/collections.spec.js +571 -0
- package/src/reducers/__tests__/config.spec.js +38 -0
- package/src/reducers/__tests__/entries.spec.js +694 -0
- package/src/reducers/__tests__/entryDraft.spec.js +198 -0
- package/src/reducers/__tests__/globalUI.js +43 -0
- package/src/reducers/__tests__/integrations.spec.ts +76 -0
- package/src/reducers/__tests__/mediaLibrary.spec.js +154 -0
- package/src/reducers/__tests__/medias.spec.ts +49 -0
- package/src/reducers/auth.ts +46 -0
- package/src/reducers/collections.ts +483 -0
- package/src/reducers/combinedReducer.ts +11 -0
- package/src/reducers/config.ts +38 -0
- package/src/reducers/cursors.js +36 -0
- package/src/reducers/deploys.ts +52 -0
- package/src/reducers/editorialWorkflow.ts +163 -0
- package/src/reducers/entries.ts +806 -0
- package/src/reducers/entryDraft.js +218 -0
- package/src/reducers/globalUI.ts +45 -0
- package/src/reducers/index.ts +82 -0
- package/src/reducers/integrations.ts +59 -0
- package/src/reducers/mediaLibrary.ts +296 -0
- package/src/reducers/medias.ts +66 -0
- package/src/reducers/notifications.ts +53 -0
- package/src/reducers/search.ts +89 -0
- package/src/reducers/status.ts +40 -0
- package/src/redux/index.ts +18 -0
- package/src/redux/middleware/waitUntilAction.ts +64 -0
- package/src/routing/__tests__/history.spec.ts +49 -0
- package/src/routing/history.ts +17 -0
- package/src/types/diacritics.d.ts +1 -0
- package/src/types/global.d.ts +8 -0
- package/src/types/immutable.ts +39 -0
- package/src/types/redux.ts +810 -0
- package/src/types/tomlify-j0.4.d.ts +13 -0
- package/src/valueObjects/AssetProxy.ts +48 -0
- package/src/valueObjects/EditorComponent.js +38 -0
- package/src/valueObjects/Entry.ts +63 -0
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _trimEnd2 = _interopRequireDefault(require("lodash/trimEnd"));
|
|
8
|
+
var _pickBy2 = _interopRequireDefault(require("lodash/pickBy"));
|
|
9
|
+
var _decapCmsLibUtil = require("decap-cms-lib-util");
|
|
10
|
+
var _urlHelper = require("../../../lib/urlHelper");
|
|
11
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
13
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
14
|
+
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; }
|
|
15
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
16
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
17
|
+
const {
|
|
18
|
+
fetchWithTimeout: fetch
|
|
19
|
+
} = _decapCmsLibUtil.unsentRequest;
|
|
20
|
+
class AssetStore {
|
|
21
|
+
constructor(config, getToken) {
|
|
22
|
+
this.config = config;
|
|
23
|
+
if (config.get('getSignedFormURL') == null) {
|
|
24
|
+
throw 'The AssetStore integration needs the getSignedFormURL in the integration configuration.';
|
|
25
|
+
}
|
|
26
|
+
this.getToken = getToken;
|
|
27
|
+
this.shouldConfirmUpload = config.get('shouldConfirmUpload', false);
|
|
28
|
+
this.getSignedFormURL = (0, _trimEnd2.default)(config.get('getSignedFormURL'), '/');
|
|
29
|
+
}
|
|
30
|
+
parseJsonResponse(response) {
|
|
31
|
+
return response.json().then(json => {
|
|
32
|
+
if (!response.ok) {
|
|
33
|
+
return Promise.reject(json);
|
|
34
|
+
}
|
|
35
|
+
return json;
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
urlFor(path, options) {
|
|
39
|
+
const params = [];
|
|
40
|
+
if (options.params) {
|
|
41
|
+
for (const key in options.params) {
|
|
42
|
+
params.push(`${key}=${encodeURIComponent(options.params[key])}`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
if (params.length) {
|
|
46
|
+
path += `?${params.join('&')}`;
|
|
47
|
+
}
|
|
48
|
+
return path;
|
|
49
|
+
}
|
|
50
|
+
requestHeaders(headers = {}) {
|
|
51
|
+
return _objectSpread({}, headers);
|
|
52
|
+
}
|
|
53
|
+
confirmRequest(assetID) {
|
|
54
|
+
this.getToken().then(token => this.request(`${this.getSignedFormURL}/${assetID}`, {
|
|
55
|
+
method: 'PUT',
|
|
56
|
+
headers: {
|
|
57
|
+
'Content-Type': 'application/json',
|
|
58
|
+
Authorization: `Bearer ${token}`
|
|
59
|
+
},
|
|
60
|
+
body: JSON.stringify({
|
|
61
|
+
state: 'uploaded'
|
|
62
|
+
})
|
|
63
|
+
}));
|
|
64
|
+
}
|
|
65
|
+
async request(path, options = {}) {
|
|
66
|
+
const headers = this.requestHeaders(options.headers || {});
|
|
67
|
+
const url = this.urlFor(path, options);
|
|
68
|
+
const response = await fetch(url, _objectSpread(_objectSpread({}, options), {}, {
|
|
69
|
+
headers
|
|
70
|
+
}));
|
|
71
|
+
const contentType = response.headers.get('Content-Type');
|
|
72
|
+
const isJson = contentType && contentType.match(/json/);
|
|
73
|
+
const content = isJson ? await this.parseJsonResponse(response) : response.text();
|
|
74
|
+
return content;
|
|
75
|
+
}
|
|
76
|
+
async retrieve(query, page, privateUpload) {
|
|
77
|
+
const params = (0, _pickBy2.default)({
|
|
78
|
+
search: query,
|
|
79
|
+
page,
|
|
80
|
+
filter: privateUpload ? 'private' : 'public'
|
|
81
|
+
}, val => !!val);
|
|
82
|
+
const url = (0, _urlHelper.addParams)(this.getSignedFormURL, params);
|
|
83
|
+
const token = await this.getToken();
|
|
84
|
+
const headers = {
|
|
85
|
+
'Content-Type': 'application/json',
|
|
86
|
+
Authorization: `Bearer ${token}`
|
|
87
|
+
};
|
|
88
|
+
const response = await this.request(url, {
|
|
89
|
+
headers
|
|
90
|
+
});
|
|
91
|
+
const files = response.map(({
|
|
92
|
+
id,
|
|
93
|
+
name,
|
|
94
|
+
size,
|
|
95
|
+
url
|
|
96
|
+
}) => {
|
|
97
|
+
return {
|
|
98
|
+
id,
|
|
99
|
+
name,
|
|
100
|
+
size,
|
|
101
|
+
displayURL: url,
|
|
102
|
+
url,
|
|
103
|
+
path: url
|
|
104
|
+
};
|
|
105
|
+
});
|
|
106
|
+
return files;
|
|
107
|
+
}
|
|
108
|
+
delete(assetID) {
|
|
109
|
+
const url = `${this.getSignedFormURL}/${assetID}`;
|
|
110
|
+
return this.getToken().then(token => this.request(url, {
|
|
111
|
+
method: 'DELETE',
|
|
112
|
+
headers: {
|
|
113
|
+
'Content-Type': 'application/json',
|
|
114
|
+
Authorization: `Bearer ${token}`
|
|
115
|
+
}
|
|
116
|
+
}));
|
|
117
|
+
}
|
|
118
|
+
async upload(file, privateUpload = false) {
|
|
119
|
+
const fileData = {
|
|
120
|
+
name: file.name,
|
|
121
|
+
size: file.size
|
|
122
|
+
};
|
|
123
|
+
if (file.type) {
|
|
124
|
+
fileData.content_type = file.type;
|
|
125
|
+
}
|
|
126
|
+
if (privateUpload) {
|
|
127
|
+
fileData.visibility = 'private';
|
|
128
|
+
}
|
|
129
|
+
try {
|
|
130
|
+
const token = await this.getToken();
|
|
131
|
+
const response = await this.request(this.getSignedFormURL, {
|
|
132
|
+
method: 'POST',
|
|
133
|
+
headers: {
|
|
134
|
+
'Content-Type': 'application/json',
|
|
135
|
+
Authorization: `Bearer ${token}`
|
|
136
|
+
},
|
|
137
|
+
body: JSON.stringify(fileData)
|
|
138
|
+
});
|
|
139
|
+
const formURL = response.form.url;
|
|
140
|
+
const formFields = response.form.fields;
|
|
141
|
+
const {
|
|
142
|
+
id,
|
|
143
|
+
name,
|
|
144
|
+
size,
|
|
145
|
+
url
|
|
146
|
+
} = response.asset;
|
|
147
|
+
const formData = new FormData();
|
|
148
|
+
Object.keys(formFields).forEach(key => formData.append(key, formFields[key]));
|
|
149
|
+
formData.append('file', file, file.name);
|
|
150
|
+
await this.request(formURL, {
|
|
151
|
+
method: 'POST',
|
|
152
|
+
body: formData
|
|
153
|
+
});
|
|
154
|
+
if (this.shouldConfirmUpload) {
|
|
155
|
+
await this.confirmRequest(id);
|
|
156
|
+
}
|
|
157
|
+
const asset = {
|
|
158
|
+
id,
|
|
159
|
+
name,
|
|
160
|
+
size,
|
|
161
|
+
displayURL: url,
|
|
162
|
+
url,
|
|
163
|
+
path: url
|
|
164
|
+
};
|
|
165
|
+
return {
|
|
166
|
+
success: true,
|
|
167
|
+
asset
|
|
168
|
+
};
|
|
169
|
+
} catch (error) {
|
|
170
|
+
console.error(error);
|
|
171
|
+
throw error;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
exports.default = AssetStore;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = consoleError;
|
|
7
|
+
function consoleError(title, description) {
|
|
8
|
+
console.error(`%c ⛔ ${title}\n` + `%c${description}\n\n`, 'color: black; font-weight: bold; font-size: 16px; line-height: 50px;', 'color: black;');
|
|
9
|
+
}
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.commitMessageFormatter = commitMessageFormatter;
|
|
7
|
+
exports.folderFormatter = folderFormatter;
|
|
8
|
+
exports.getProcessSegment = getProcessSegment;
|
|
9
|
+
exports.prepareSlug = prepareSlug;
|
|
10
|
+
exports.previewUrlFormatter = previewUrlFormatter;
|
|
11
|
+
exports.slugFormatter = slugFormatter;
|
|
12
|
+
exports.summaryFormatter = summaryFormatter;
|
|
13
|
+
var _trimStart2 = _interopRequireDefault(require("lodash/trimStart"));
|
|
14
|
+
var _trimEnd2 = _interopRequireDefault(require("lodash/trimEnd"));
|
|
15
|
+
var _partialRight2 = _interopRequireDefault(require("lodash/partialRight"));
|
|
16
|
+
var _flow2 = _interopRequireDefault(require("lodash/flow"));
|
|
17
|
+
var _decapCmsLibWidgets = require("decap-cms-lib-widgets");
|
|
18
|
+
var _commonTags = require("common-tags");
|
|
19
|
+
var _collections = require("../reducers/collections");
|
|
20
|
+
var _urlHelper = require("./urlHelper");
|
|
21
|
+
var _collectionTypes = require("../constants/collectionTypes");
|
|
22
|
+
var _commitProps = require("../constants/commitProps");
|
|
23
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
24
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
25
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
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(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
28
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
29
|
+
const {
|
|
30
|
+
compileStringTemplate,
|
|
31
|
+
parseDateFromEntry,
|
|
32
|
+
SLUG_MISSING_REQUIRED_DATE,
|
|
33
|
+
keyToPathArray,
|
|
34
|
+
addFileTemplateFields
|
|
35
|
+
} = _decapCmsLibWidgets.stringTemplate;
|
|
36
|
+
const commitMessageTemplates = {
|
|
37
|
+
create: 'Create {{collection}} “{{slug}}”',
|
|
38
|
+
update: 'Update {{collection}} “{{slug}}”',
|
|
39
|
+
delete: 'Delete {{collection}} “{{slug}}”',
|
|
40
|
+
uploadMedia: 'Upload “{{path}}”',
|
|
41
|
+
deleteMedia: 'Delete “{{path}}”',
|
|
42
|
+
openAuthoring: '{{message}}'
|
|
43
|
+
};
|
|
44
|
+
const variableRegex = /\{\{([^}]+)\}\}/g;
|
|
45
|
+
function commitMessageFormatter(type, config, {
|
|
46
|
+
slug,
|
|
47
|
+
path,
|
|
48
|
+
collection,
|
|
49
|
+
authorLogin,
|
|
50
|
+
authorName
|
|
51
|
+
}, isOpenAuthoring) {
|
|
52
|
+
const templates = _objectSpread(_objectSpread({}, commitMessageTemplates), config.backend.commit_messages || {});
|
|
53
|
+
const commitMessage = templates[type].replace(variableRegex, (_, variable) => {
|
|
54
|
+
switch (variable) {
|
|
55
|
+
case 'slug':
|
|
56
|
+
return slug || '';
|
|
57
|
+
case 'path':
|
|
58
|
+
return path || '';
|
|
59
|
+
case 'collection':
|
|
60
|
+
return collection ? collection.get('label_singular') || collection.get('label') : '';
|
|
61
|
+
case 'author-login':
|
|
62
|
+
return authorLogin || '';
|
|
63
|
+
case 'author-name':
|
|
64
|
+
return authorName || '';
|
|
65
|
+
default:
|
|
66
|
+
console.warn(`Ignoring unknown variable “${variable}” in commit message template.`);
|
|
67
|
+
return '';
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
if (!isOpenAuthoring) {
|
|
71
|
+
return commitMessage;
|
|
72
|
+
}
|
|
73
|
+
const message = templates.openAuthoring.replace(variableRegex, (_, variable) => {
|
|
74
|
+
switch (variable) {
|
|
75
|
+
case 'message':
|
|
76
|
+
return commitMessage;
|
|
77
|
+
case 'author-login':
|
|
78
|
+
return authorLogin || '';
|
|
79
|
+
case 'author-name':
|
|
80
|
+
return authorName || '';
|
|
81
|
+
default:
|
|
82
|
+
console.warn(`Ignoring unknown variable “${variable}” in open authoring message template.`);
|
|
83
|
+
return '';
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
return message;
|
|
87
|
+
}
|
|
88
|
+
function prepareSlug(slug) {
|
|
89
|
+
return slug.trim()
|
|
90
|
+
// Convert slug to lower-case
|
|
91
|
+
.toLocaleLowerCase()
|
|
92
|
+
|
|
93
|
+
// Remove single quotes.
|
|
94
|
+
.replace(/[']/g, '')
|
|
95
|
+
|
|
96
|
+
// Replace periods with dashes.
|
|
97
|
+
.replace(/[.]/g, '-');
|
|
98
|
+
}
|
|
99
|
+
function getProcessSegment(slugConfig, ignoreValues) {
|
|
100
|
+
return value => ignoreValues && ignoreValues.includes(value) ? value : (0, _flow2.default)([value => String(value), prepareSlug, (0, _partialRight2.default)(_urlHelper.sanitizeSlug, slugConfig)])(value);
|
|
101
|
+
}
|
|
102
|
+
function slugFormatter(collection, entryData, slugConfig) {
|
|
103
|
+
const slugTemplate = collection.get('slug') || '{{slug}}';
|
|
104
|
+
const identifier = entryData.getIn(keyToPathArray((0, _collections.selectIdentifier)(collection)));
|
|
105
|
+
if (!identifier) {
|
|
106
|
+
throw new Error('Collection must have a field name that is a valid entry identifier, or must have `identifier_field` set');
|
|
107
|
+
}
|
|
108
|
+
const processSegment = getProcessSegment(slugConfig);
|
|
109
|
+
const date = new Date();
|
|
110
|
+
const slug = compileStringTemplate(slugTemplate, date, identifier, entryData, processSegment);
|
|
111
|
+
if (!collection.has('path')) {
|
|
112
|
+
return slug;
|
|
113
|
+
} else {
|
|
114
|
+
const pathTemplate = prepareSlug(collection.get('path'));
|
|
115
|
+
return compileStringTemplate(pathTemplate, date, slug, entryData, value => value === slug ? value : processSegment(value));
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
function previewUrlFormatter(baseUrl, collection, slug, entry, slugConfig) {
|
|
119
|
+
/**
|
|
120
|
+
* Preview URL can't be created without `baseUrl`. This makes preview URLs
|
|
121
|
+
* optional for backends that don't support them.
|
|
122
|
+
*/
|
|
123
|
+
if (!baseUrl) {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
const basePath = (0, _trimEnd2.default)(baseUrl, '/');
|
|
127
|
+
const isFileCollection = collection.get('type') === _collectionTypes.FILES;
|
|
128
|
+
const file = isFileCollection ? (0, _collections.getFileFromSlug)(collection, entry.get('slug')) : undefined;
|
|
129
|
+
function getPathTemplate() {
|
|
130
|
+
var _file$get;
|
|
131
|
+
return (_file$get = file === null || file === void 0 ? void 0 : file.get('preview_path')) !== null && _file$get !== void 0 ? _file$get : collection.get('preview_path');
|
|
132
|
+
}
|
|
133
|
+
function getDateField() {
|
|
134
|
+
var _file$get2;
|
|
135
|
+
return (_file$get2 = file === null || file === void 0 ? void 0 : file.get('preview_path_date_field')) !== null && _file$get2 !== void 0 ? _file$get2 : collection.get('preview_path_date_field');
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* If a `previewPath` is provided for the collection/file, use it to construct the
|
|
140
|
+
* URL path.
|
|
141
|
+
*/
|
|
142
|
+
const pathTemplate = getPathTemplate();
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Without a `previewPath` for the collection/file (via config), the preview URL
|
|
146
|
+
* will be the URL provided by the backend.
|
|
147
|
+
*/
|
|
148
|
+
if (!pathTemplate) {
|
|
149
|
+
return baseUrl;
|
|
150
|
+
}
|
|
151
|
+
let fields = entry.get('data');
|
|
152
|
+
fields = addFileTemplateFields(entry.get('path'), fields, collection.get('folder'));
|
|
153
|
+
const dateFieldName = getDateField() || (0, _collections.selectInferedField)(collection, 'date');
|
|
154
|
+
const date = parseDateFromEntry(entry, dateFieldName);
|
|
155
|
+
|
|
156
|
+
// Prepare and sanitize slug variables only, leave the rest of the
|
|
157
|
+
// `preview_path` template as is.
|
|
158
|
+
const processSegment = getProcessSegment(slugConfig, [fields.get('dirname')]);
|
|
159
|
+
let compiledPath;
|
|
160
|
+
try {
|
|
161
|
+
compiledPath = compileStringTemplate(pathTemplate, date, slug, fields, processSegment);
|
|
162
|
+
} catch (err) {
|
|
163
|
+
// Print an error and ignore `preview_path` if both:
|
|
164
|
+
// 1. Date is invalid (according to Moment), and
|
|
165
|
+
// 2. A date expression (eg. `{{year}}`) is used in `preview_path`
|
|
166
|
+
if (err.name === SLUG_MISSING_REQUIRED_DATE) {
|
|
167
|
+
console.error((0, _commonTags.stripIndent)`
|
|
168
|
+
Collection "${collection.get('name')}" configuration error:
|
|
169
|
+
\`preview_path_date_field\` must be a field with a valid date. Ignoring \`preview_path\`.
|
|
170
|
+
`);
|
|
171
|
+
return basePath;
|
|
172
|
+
}
|
|
173
|
+
throw err;
|
|
174
|
+
}
|
|
175
|
+
const previewPath = (0, _trimStart2.default)(compiledPath, ' /');
|
|
176
|
+
return `${basePath}/${previewPath}`;
|
|
177
|
+
}
|
|
178
|
+
function summaryFormatter(summaryTemplate, entry, collection) {
|
|
179
|
+
let entryData = entry.get('data');
|
|
180
|
+
const date = parseDateFromEntry(entry, (0, _collections.selectInferedField)(collection, 'date')) || null;
|
|
181
|
+
const identifier = entryData.getIn(keyToPathArray((0, _collections.selectIdentifier)(collection)));
|
|
182
|
+
entryData = addFileTemplateFields(entry.get('path'), entryData, collection.get('folder'));
|
|
183
|
+
// allow commit information in summary template
|
|
184
|
+
if (entry.get('author') && !(0, _collections.selectField)(collection, _commitProps.COMMIT_AUTHOR)) {
|
|
185
|
+
entryData = entryData.set(_commitProps.COMMIT_AUTHOR, entry.get('author'));
|
|
186
|
+
}
|
|
187
|
+
if (entry.get('updatedOn') && !(0, _collections.selectField)(collection, _commitProps.COMMIT_DATE)) {
|
|
188
|
+
entryData = entryData.set(_commitProps.COMMIT_DATE, entry.get('updatedOn'));
|
|
189
|
+
}
|
|
190
|
+
const summary = compileStringTemplate(summaryTemplate, date, identifier, entryData);
|
|
191
|
+
return summary;
|
|
192
|
+
}
|
|
193
|
+
function folderFormatter(folderTemplate, entry, collection, defaultFolder, folderKey, slugConfig) {
|
|
194
|
+
if (!entry || !entry.get('data')) {
|
|
195
|
+
return folderTemplate;
|
|
196
|
+
}
|
|
197
|
+
let fields = entry.get('data').set(folderKey, defaultFolder);
|
|
198
|
+
fields = addFileTemplateFields(entry.get('path'), fields, collection.get('folder'));
|
|
199
|
+
const date = parseDateFromEntry(entry, (0, _collections.selectInferedField)(collection, 'date')) || null;
|
|
200
|
+
const identifier = fields.getIn(keyToPathArray((0, _collections.selectIdentifier)(collection)));
|
|
201
|
+
const processSegment = getProcessSegment(slugConfig, [defaultFolder, fields.get('dirname')]);
|
|
202
|
+
const mediaFolder = compileStringTemplate(folderTemplate, date, identifier, fields, processSegment);
|
|
203
|
+
return mediaFolder;
|
|
204
|
+
}
|