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,118 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.USE_OPEN_AUTHORING = exports.LOGOUT = exports.AUTH_SUCCESS = exports.AUTH_REQUEST_DONE = exports.AUTH_REQUEST = exports.AUTH_FAILURE = void 0;
|
|
7
|
+
exports.authError = authError;
|
|
8
|
+
exports.authenticate = authenticate;
|
|
9
|
+
exports.authenticateUser = authenticateUser;
|
|
10
|
+
exports.authenticating = authenticating;
|
|
11
|
+
exports.doneAuthenticating = doneAuthenticating;
|
|
12
|
+
exports.loginUser = loginUser;
|
|
13
|
+
exports.logout = logout;
|
|
14
|
+
exports.logoutUser = logoutUser;
|
|
15
|
+
exports.useOpenAuthoring = useOpenAuthoring;
|
|
16
|
+
var _backend = require("../backend");
|
|
17
|
+
var _notifications = require("./notifications");
|
|
18
|
+
const AUTH_REQUEST = 'AUTH_REQUEST';
|
|
19
|
+
exports.AUTH_REQUEST = AUTH_REQUEST;
|
|
20
|
+
const AUTH_SUCCESS = 'AUTH_SUCCESS';
|
|
21
|
+
exports.AUTH_SUCCESS = AUTH_SUCCESS;
|
|
22
|
+
const AUTH_FAILURE = 'AUTH_FAILURE';
|
|
23
|
+
exports.AUTH_FAILURE = AUTH_FAILURE;
|
|
24
|
+
const AUTH_REQUEST_DONE = 'AUTH_REQUEST_DONE';
|
|
25
|
+
exports.AUTH_REQUEST_DONE = AUTH_REQUEST_DONE;
|
|
26
|
+
const USE_OPEN_AUTHORING = 'USE_OPEN_AUTHORING';
|
|
27
|
+
exports.USE_OPEN_AUTHORING = USE_OPEN_AUTHORING;
|
|
28
|
+
const LOGOUT = 'LOGOUT';
|
|
29
|
+
exports.LOGOUT = LOGOUT;
|
|
30
|
+
function authenticating() {
|
|
31
|
+
return {
|
|
32
|
+
type: AUTH_REQUEST
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
function authenticate(userData) {
|
|
36
|
+
return {
|
|
37
|
+
type: AUTH_SUCCESS,
|
|
38
|
+
payload: userData
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function authError(error) {
|
|
42
|
+
return {
|
|
43
|
+
type: AUTH_FAILURE,
|
|
44
|
+
error: 'Failed to authenticate',
|
|
45
|
+
payload: error
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
function doneAuthenticating() {
|
|
49
|
+
return {
|
|
50
|
+
type: AUTH_REQUEST_DONE
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
function useOpenAuthoring() {
|
|
54
|
+
return {
|
|
55
|
+
type: USE_OPEN_AUTHORING
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
function logout() {
|
|
59
|
+
return {
|
|
60
|
+
type: LOGOUT
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Check if user data token is cached and is valid
|
|
65
|
+
function authenticateUser() {
|
|
66
|
+
return (dispatch, getState) => {
|
|
67
|
+
const state = getState();
|
|
68
|
+
const backend = (0, _backend.currentBackend)(state.config);
|
|
69
|
+
dispatch(authenticating());
|
|
70
|
+
return Promise.resolve(backend.currentUser()).then(user => {
|
|
71
|
+
if (user) {
|
|
72
|
+
if (user.useOpenAuthoring) {
|
|
73
|
+
dispatch(useOpenAuthoring());
|
|
74
|
+
}
|
|
75
|
+
dispatch(authenticate(user));
|
|
76
|
+
} else {
|
|
77
|
+
dispatch(doneAuthenticating());
|
|
78
|
+
}
|
|
79
|
+
}).catch(error => {
|
|
80
|
+
dispatch(authError(error));
|
|
81
|
+
dispatch(logoutUser());
|
|
82
|
+
});
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
function loginUser(credentials) {
|
|
86
|
+
return (dispatch, getState) => {
|
|
87
|
+
const state = getState();
|
|
88
|
+
const backend = (0, _backend.currentBackend)(state.config);
|
|
89
|
+
dispatch(authenticating());
|
|
90
|
+
return backend.authenticate(credentials).then(user => {
|
|
91
|
+
if (user.useOpenAuthoring) {
|
|
92
|
+
dispatch(useOpenAuthoring());
|
|
93
|
+
}
|
|
94
|
+
dispatch(authenticate(user));
|
|
95
|
+
}).catch(error => {
|
|
96
|
+
console.error(error);
|
|
97
|
+
dispatch((0, _notifications.addNotification)({
|
|
98
|
+
message: {
|
|
99
|
+
details: error.message,
|
|
100
|
+
key: 'ui.toast.onFailToAuth'
|
|
101
|
+
},
|
|
102
|
+
type: 'error',
|
|
103
|
+
dismissAfter: 8000
|
|
104
|
+
}));
|
|
105
|
+
dispatch(authError(error));
|
|
106
|
+
});
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
function logoutUser() {
|
|
110
|
+
return (dispatch, getState) => {
|
|
111
|
+
const state = getState();
|
|
112
|
+
const backend = (0, _backend.currentBackend)(state.config);
|
|
113
|
+
Promise.resolve(backend.logout()).then(() => {
|
|
114
|
+
dispatch(logout());
|
|
115
|
+
dispatch((0, _notifications.clearNotifications)());
|
|
116
|
+
});
|
|
117
|
+
};
|
|
118
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createNewEntry = createNewEntry;
|
|
7
|
+
exports.searchCollections = searchCollections;
|
|
8
|
+
exports.showCollection = showCollection;
|
|
9
|
+
var _history = require("../routing/history");
|
|
10
|
+
var _urlHelper = require("../lib/urlHelper");
|
|
11
|
+
function searchCollections(query, collection) {
|
|
12
|
+
if (collection) {
|
|
13
|
+
_history.history.push(`/collections/${collection}/search/${query}`);
|
|
14
|
+
} else {
|
|
15
|
+
_history.history.push(`/search/${query}`);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
function showCollection(collectionName) {
|
|
19
|
+
_history.history.push((0, _urlHelper.getCollectionUrl)(collectionName));
|
|
20
|
+
}
|
|
21
|
+
function createNewEntry(collectionName) {
|
|
22
|
+
_history.history.push((0, _urlHelper.getNewEntryUrl)(collectionName));
|
|
23
|
+
}
|
|
@@ -0,0 +1,482 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.CONFIG_SUCCESS = exports.CONFIG_REQUEST = exports.CONFIG_FAILURE = void 0;
|
|
7
|
+
exports.applyDefaults = applyDefaults;
|
|
8
|
+
exports.configFailed = configFailed;
|
|
9
|
+
exports.configLoaded = configLoaded;
|
|
10
|
+
exports.configLoading = configLoading;
|
|
11
|
+
exports.detectProxyServer = detectProxyServer;
|
|
12
|
+
exports.handleLocalBackend = handleLocalBackend;
|
|
13
|
+
exports.loadConfig = loadConfig;
|
|
14
|
+
exports.normalizeConfig = normalizeConfig;
|
|
15
|
+
exports.parseConfig = parseConfig;
|
|
16
|
+
var _isEmpty2 = _interopRequireDefault(require("lodash/isEmpty"));
|
|
17
|
+
var _trim2 = _interopRequireDefault(require("lodash/trim"));
|
|
18
|
+
var _trimStart2 = _interopRequireDefault(require("lodash/trimStart"));
|
|
19
|
+
var _yaml = _interopRequireDefault(require("yaml"));
|
|
20
|
+
var _immutable = require("immutable");
|
|
21
|
+
var _deepmerge = _interopRequireDefault(require("deepmerge"));
|
|
22
|
+
var _immer = require("immer");
|
|
23
|
+
var _publishModes = require("../constants/publishModes");
|
|
24
|
+
var _configSchema = require("../constants/configSchema");
|
|
25
|
+
var _collections = require("../reducers/collections");
|
|
26
|
+
var _integrations = require("../reducers/integrations");
|
|
27
|
+
var _backend = require("../backend");
|
|
28
|
+
var _i18n = require("../lib/i18n");
|
|
29
|
+
var _collectionTypes = require("../constants/collectionTypes");
|
|
30
|
+
const _excluded = ["sortableFields"];
|
|
31
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
32
|
+
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; }
|
|
33
|
+
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; }
|
|
34
|
+
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; }
|
|
35
|
+
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; }
|
|
36
|
+
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; }
|
|
37
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
38
|
+
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); }
|
|
39
|
+
const CONFIG_REQUEST = 'CONFIG_REQUEST';
|
|
40
|
+
exports.CONFIG_REQUEST = CONFIG_REQUEST;
|
|
41
|
+
const CONFIG_SUCCESS = 'CONFIG_SUCCESS';
|
|
42
|
+
exports.CONFIG_SUCCESS = CONFIG_SUCCESS;
|
|
43
|
+
const CONFIG_FAILURE = 'CONFIG_FAILURE';
|
|
44
|
+
exports.CONFIG_FAILURE = CONFIG_FAILURE;
|
|
45
|
+
function isObjectField(field) {
|
|
46
|
+
return 'fields' in field;
|
|
47
|
+
}
|
|
48
|
+
function isFieldList(field) {
|
|
49
|
+
return 'types' in field || 'field' in field;
|
|
50
|
+
}
|
|
51
|
+
function traverseFieldsJS(fields, updater) {
|
|
52
|
+
return fields.map(field => {
|
|
53
|
+
const newField = updater(field);
|
|
54
|
+
if (isObjectField(newField)) {
|
|
55
|
+
return _objectSpread(_objectSpread({}, newField), {}, {
|
|
56
|
+
fields: traverseFieldsJS(newField.fields, updater)
|
|
57
|
+
});
|
|
58
|
+
} else if (isFieldList(newField) && newField.field) {
|
|
59
|
+
return _objectSpread(_objectSpread({}, newField), {}, {
|
|
60
|
+
field: traverseFieldsJS([newField.field], updater)[0]
|
|
61
|
+
});
|
|
62
|
+
} else if (isFieldList(newField) && newField.types) {
|
|
63
|
+
return _objectSpread(_objectSpread({}, newField), {}, {
|
|
64
|
+
types: traverseFieldsJS(newField.types, updater)
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
return newField;
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
function getConfigUrl() {
|
|
71
|
+
const validTypes = {
|
|
72
|
+
'text/yaml': 'yaml',
|
|
73
|
+
'application/x-yaml': 'yaml'
|
|
74
|
+
};
|
|
75
|
+
const configLinkEl = document.querySelector('link[rel="cms-config-url"]');
|
|
76
|
+
if (configLinkEl && validTypes[configLinkEl.type] && configLinkEl.href) {
|
|
77
|
+
console.log(`Using config file path: "${configLinkEl.href}"`);
|
|
78
|
+
return configLinkEl.href;
|
|
79
|
+
}
|
|
80
|
+
return 'config.yml';
|
|
81
|
+
}
|
|
82
|
+
function setDefaultPublicFolderForField(field) {
|
|
83
|
+
if ('media_folder' in field && !('public_folder' in field)) {
|
|
84
|
+
return _objectSpread(_objectSpread({}, field), {}, {
|
|
85
|
+
public_folder: field.media_folder
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
return field;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Mapping between existing camelCase and its snake_case counterpart
|
|
92
|
+
const WIDGET_KEY_MAP = {
|
|
93
|
+
dateFormat: 'date_format',
|
|
94
|
+
timeFormat: 'time_format',
|
|
95
|
+
pickerUtc: 'picker_utc',
|
|
96
|
+
editorComponents: 'editor_components',
|
|
97
|
+
valueType: 'value_type',
|
|
98
|
+
valueField: 'value_field',
|
|
99
|
+
searchFields: 'search_fields',
|
|
100
|
+
displayFields: 'display_fields',
|
|
101
|
+
optionsLength: 'options_length'
|
|
102
|
+
};
|
|
103
|
+
function setSnakeCaseConfig(field) {
|
|
104
|
+
const deprecatedKeys = Object.keys(WIDGET_KEY_MAP).filter(camel => camel in field);
|
|
105
|
+
const snakeValues = deprecatedKeys.map(camel => {
|
|
106
|
+
const snake = WIDGET_KEY_MAP[camel];
|
|
107
|
+
console.warn(`Field ${field.name} is using a deprecated configuration '${camel}'. Please use '${snake}'`);
|
|
108
|
+
return {
|
|
109
|
+
[snake]: field[camel]
|
|
110
|
+
};
|
|
111
|
+
});
|
|
112
|
+
return Object.assign({}, field, ...snakeValues);
|
|
113
|
+
}
|
|
114
|
+
function setI18nField(field) {
|
|
115
|
+
if (field[_i18n.I18N] === true) {
|
|
116
|
+
return _objectSpread(_objectSpread({}, field), {}, {
|
|
117
|
+
[_i18n.I18N]: _i18n.I18N_FIELD.TRANSLATE
|
|
118
|
+
});
|
|
119
|
+
} else if (field[_i18n.I18N] === false || !field[_i18n.I18N]) {
|
|
120
|
+
return _objectSpread(_objectSpread({}, field), {}, {
|
|
121
|
+
[_i18n.I18N]: _i18n.I18N_FIELD.NONE
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
return field;
|
|
125
|
+
}
|
|
126
|
+
function getI18nDefaults(collectionOrFileI18n, defaultI18n) {
|
|
127
|
+
if (typeof collectionOrFileI18n === 'boolean') {
|
|
128
|
+
return defaultI18n;
|
|
129
|
+
} else {
|
|
130
|
+
const locales = collectionOrFileI18n.locales || defaultI18n.locales;
|
|
131
|
+
const defaultLocale = collectionOrFileI18n.default_locale || locales[0];
|
|
132
|
+
const mergedI18n = (0, _deepmerge.default)(defaultI18n, collectionOrFileI18n);
|
|
133
|
+
mergedI18n.locales = locales;
|
|
134
|
+
mergedI18n.default_locale = defaultLocale;
|
|
135
|
+
throwOnMissingDefaultLocale(mergedI18n);
|
|
136
|
+
return mergedI18n;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
function setI18nDefaultsForFields(collectionOrFileFields, hasI18n) {
|
|
140
|
+
if (hasI18n) {
|
|
141
|
+
return traverseFieldsJS(collectionOrFileFields, setI18nField);
|
|
142
|
+
} else {
|
|
143
|
+
return traverseFieldsJS(collectionOrFileFields, field => {
|
|
144
|
+
const newField = _objectSpread({}, field);
|
|
145
|
+
delete newField[_i18n.I18N];
|
|
146
|
+
return newField;
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
function throwOnInvalidFileCollectionStructure(i18n) {
|
|
151
|
+
if (i18n && i18n.structure !== _i18n.I18N_STRUCTURE.SINGLE_FILE) {
|
|
152
|
+
throw new Error(`i18n configuration for files collections is limited to ${_i18n.I18N_STRUCTURE.SINGLE_FILE} structure`);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
function throwOnMissingDefaultLocale(i18n) {
|
|
156
|
+
if (i18n && i18n.default_locale && !i18n.locales.includes(i18n.default_locale)) {
|
|
157
|
+
throw new Error(`i18n locales '${i18n.locales.join(', ')}' are missing the default locale ${i18n.default_locale}`);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
function hasIntegration(config, collection) {
|
|
161
|
+
// TODO remove fromJS when Immutable is removed from the integrations state slice
|
|
162
|
+
const integrations = (0, _integrations.getIntegrations)((0, _immutable.fromJS)(config));
|
|
163
|
+
const integration = (0, _integrations.selectIntegration)(integrations, collection.name, 'listEntries');
|
|
164
|
+
return !!integration;
|
|
165
|
+
}
|
|
166
|
+
function normalizeConfig(config) {
|
|
167
|
+
const {
|
|
168
|
+
collections = []
|
|
169
|
+
} = config;
|
|
170
|
+
const normalizedCollections = collections.map(collection => {
|
|
171
|
+
const {
|
|
172
|
+
fields,
|
|
173
|
+
files
|
|
174
|
+
} = collection;
|
|
175
|
+
let normalizedCollection = collection;
|
|
176
|
+
if (fields) {
|
|
177
|
+
const normalizedFields = traverseFieldsJS(fields, setSnakeCaseConfig);
|
|
178
|
+
normalizedCollection = _objectSpread(_objectSpread({}, normalizedCollection), {}, {
|
|
179
|
+
fields: normalizedFields
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
if (files) {
|
|
183
|
+
const normalizedFiles = files.map(file => {
|
|
184
|
+
const normalizedFileFields = traverseFieldsJS(file.fields, setSnakeCaseConfig);
|
|
185
|
+
return _objectSpread(_objectSpread({}, file), {}, {
|
|
186
|
+
fields: normalizedFileFields
|
|
187
|
+
});
|
|
188
|
+
});
|
|
189
|
+
normalizedCollection = _objectSpread(_objectSpread({}, normalizedCollection), {}, {
|
|
190
|
+
files: normalizedFiles
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
if (normalizedCollection.sortableFields) {
|
|
194
|
+
const {
|
|
195
|
+
sortableFields
|
|
196
|
+
} = normalizedCollection,
|
|
197
|
+
rest = _objectWithoutProperties(normalizedCollection, _excluded);
|
|
198
|
+
normalizedCollection = _objectSpread(_objectSpread({}, rest), {}, {
|
|
199
|
+
sortable_fields: sortableFields
|
|
200
|
+
});
|
|
201
|
+
console.warn(`Collection ${collection.name} is using a deprecated configuration 'sortableFields'. Please use 'sortable_fields'`);
|
|
202
|
+
}
|
|
203
|
+
return normalizedCollection;
|
|
204
|
+
});
|
|
205
|
+
return _objectSpread(_objectSpread({}, config), {}, {
|
|
206
|
+
collections: normalizedCollections
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
function applyDefaults(originalConfig) {
|
|
210
|
+
return (0, _immer.produce)(originalConfig, config => {
|
|
211
|
+
config.publish_mode = config.publish_mode || _publishModes.SIMPLE;
|
|
212
|
+
config.slug = config.slug || {};
|
|
213
|
+
config.collections = config.collections || [];
|
|
214
|
+
|
|
215
|
+
// Use `site_url` as default `display_url`.
|
|
216
|
+
if (!config.display_url && config.site_url) {
|
|
217
|
+
config.display_url = config.site_url;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// Use media_folder as default public_folder.
|
|
221
|
+
const defaultPublicFolder = `/${(0, _trimStart2.default)(config.media_folder, '/')}`;
|
|
222
|
+
if (!('public_folder' in config)) {
|
|
223
|
+
config.public_folder = defaultPublicFolder;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// default values for the slug config
|
|
227
|
+
if (!('encoding' in config.slug)) {
|
|
228
|
+
config.slug.encoding = 'unicode';
|
|
229
|
+
}
|
|
230
|
+
if (!('clean_accents' in config.slug)) {
|
|
231
|
+
config.slug.clean_accents = false;
|
|
232
|
+
}
|
|
233
|
+
if (!('sanitize_replacement' in config.slug)) {
|
|
234
|
+
config.slug.sanitize_replacement = '-';
|
|
235
|
+
}
|
|
236
|
+
const i18n = config[_i18n.I18N];
|
|
237
|
+
if (i18n) {
|
|
238
|
+
i18n.default_locale = i18n.default_locale || i18n.locales[0];
|
|
239
|
+
}
|
|
240
|
+
throwOnMissingDefaultLocale(i18n);
|
|
241
|
+
const backend = (0, _backend.resolveBackend)(config);
|
|
242
|
+
for (const collection of config.collections) {
|
|
243
|
+
if (!('publish' in collection)) {
|
|
244
|
+
collection.publish = true;
|
|
245
|
+
}
|
|
246
|
+
let collectionI18n = collection[_i18n.I18N];
|
|
247
|
+
if (i18n && collectionI18n) {
|
|
248
|
+
collectionI18n = getI18nDefaults(collectionI18n, i18n);
|
|
249
|
+
collection[_i18n.I18N] = collectionI18n;
|
|
250
|
+
} else {
|
|
251
|
+
collectionI18n = undefined;
|
|
252
|
+
delete collection[_i18n.I18N];
|
|
253
|
+
}
|
|
254
|
+
if (collection.fields) {
|
|
255
|
+
collection.fields = setI18nDefaultsForFields(collection.fields, Boolean(collectionI18n));
|
|
256
|
+
}
|
|
257
|
+
const {
|
|
258
|
+
folder,
|
|
259
|
+
files,
|
|
260
|
+
view_filters,
|
|
261
|
+
view_groups,
|
|
262
|
+
meta
|
|
263
|
+
} = collection;
|
|
264
|
+
if (folder) {
|
|
265
|
+
collection.type = _collectionTypes.FOLDER;
|
|
266
|
+
if (collection.path && !collection.media_folder) {
|
|
267
|
+
// default value for media folder when using the path config
|
|
268
|
+
collection.media_folder = '';
|
|
269
|
+
}
|
|
270
|
+
if ('media_folder' in collection && !('public_folder' in collection)) {
|
|
271
|
+
collection.public_folder = collection.media_folder;
|
|
272
|
+
}
|
|
273
|
+
if (collection.fields) {
|
|
274
|
+
collection.fields = traverseFieldsJS(collection.fields, setDefaultPublicFolderForField);
|
|
275
|
+
}
|
|
276
|
+
collection.folder = (0, _trim2.default)(folder, '/');
|
|
277
|
+
if (meta && meta.path) {
|
|
278
|
+
const metaField = _objectSpread({
|
|
279
|
+
name: 'path',
|
|
280
|
+
meta: true,
|
|
281
|
+
required: true
|
|
282
|
+
}, meta.path);
|
|
283
|
+
collection.fields = [metaField, ...(collection.fields || [])];
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
if (files) {
|
|
287
|
+
collection.type = _collectionTypes.FILES;
|
|
288
|
+
throwOnInvalidFileCollectionStructure(collectionI18n);
|
|
289
|
+
delete collection.nested;
|
|
290
|
+
delete collection.meta;
|
|
291
|
+
for (const file of files) {
|
|
292
|
+
file.file = (0, _trimStart2.default)(file.file, '/');
|
|
293
|
+
if ('media_folder' in file && !('public_folder' in file)) {
|
|
294
|
+
file.public_folder = file.media_folder;
|
|
295
|
+
}
|
|
296
|
+
if (file.fields) {
|
|
297
|
+
file.fields = traverseFieldsJS(file.fields, setDefaultPublicFolderForField);
|
|
298
|
+
}
|
|
299
|
+
let fileI18n = file[_i18n.I18N];
|
|
300
|
+
if (fileI18n && collectionI18n) {
|
|
301
|
+
fileI18n = getI18nDefaults(fileI18n, collectionI18n);
|
|
302
|
+
file[_i18n.I18N] = fileI18n;
|
|
303
|
+
} else {
|
|
304
|
+
fileI18n = undefined;
|
|
305
|
+
delete file[_i18n.I18N];
|
|
306
|
+
}
|
|
307
|
+
throwOnInvalidFileCollectionStructure(fileI18n);
|
|
308
|
+
if (file.fields) {
|
|
309
|
+
file.fields = setI18nDefaultsForFields(file.fields, Boolean(fileI18n));
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
if (!collection.sortable_fields) {
|
|
314
|
+
collection.sortable_fields = (0, _collections.selectDefaultSortableFields)(
|
|
315
|
+
// TODO remove fromJS when Immutable is removed from the collections state slice
|
|
316
|
+
(0, _immutable.fromJS)(collection), backend, hasIntegration(config, collection));
|
|
317
|
+
}
|
|
318
|
+
collection.view_filters = (view_filters || []).map(filter => {
|
|
319
|
+
return _objectSpread(_objectSpread({}, filter), {}, {
|
|
320
|
+
id: `${filter.field}__${filter.pattern}`
|
|
321
|
+
});
|
|
322
|
+
});
|
|
323
|
+
collection.view_groups = (view_groups || []).map(group => {
|
|
324
|
+
return _objectSpread(_objectSpread({}, group), {}, {
|
|
325
|
+
id: `${group.field}__${group.pattern}`
|
|
326
|
+
});
|
|
327
|
+
});
|
|
328
|
+
if (config.editor && !collection.editor) {
|
|
329
|
+
collection.editor = {
|
|
330
|
+
preview: config.editor.preview
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
function parseConfig(data) {
|
|
337
|
+
const config = _yaml.default.parse(data, {
|
|
338
|
+
maxAliasCount: -1,
|
|
339
|
+
prettyErrors: true,
|
|
340
|
+
merge: true
|
|
341
|
+
});
|
|
342
|
+
if (typeof window !== 'undefined' && typeof window.CMS_ENV === 'string' && config[window.CMS_ENV]) {
|
|
343
|
+
const configKeys = Object.keys(config[window.CMS_ENV]);
|
|
344
|
+
for (const key of configKeys) {
|
|
345
|
+
config[key] = config[window.CMS_ENV][key];
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
return config;
|
|
349
|
+
}
|
|
350
|
+
async function getConfigYaml(file, hasManualConfig) {
|
|
351
|
+
const response = await fetch(file, {
|
|
352
|
+
credentials: 'same-origin'
|
|
353
|
+
}).catch(error => error);
|
|
354
|
+
if (response instanceof Error || response.status !== 200) {
|
|
355
|
+
if (hasManualConfig) {
|
|
356
|
+
return {};
|
|
357
|
+
}
|
|
358
|
+
const message = response instanceof Error ? response.message : response.status;
|
|
359
|
+
throw new Error(`Failed to load config.yml (${message})`);
|
|
360
|
+
}
|
|
361
|
+
const contentType = response.headers.get('Content-Type') || 'Not-Found';
|
|
362
|
+
const isYaml = contentType.indexOf('yaml') !== -1;
|
|
363
|
+
if (!isYaml) {
|
|
364
|
+
console.log(`Response for ${file} was not yaml. (Content-Type: ${contentType})`);
|
|
365
|
+
if (hasManualConfig) {
|
|
366
|
+
return {};
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
return parseConfig(await response.text());
|
|
370
|
+
}
|
|
371
|
+
function configLoaded(config) {
|
|
372
|
+
return {
|
|
373
|
+
type: CONFIG_SUCCESS,
|
|
374
|
+
payload: config
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
function configLoading() {
|
|
378
|
+
return {
|
|
379
|
+
type: CONFIG_REQUEST
|
|
380
|
+
};
|
|
381
|
+
}
|
|
382
|
+
function configFailed(err) {
|
|
383
|
+
return {
|
|
384
|
+
type: CONFIG_FAILURE,
|
|
385
|
+
error: 'Error loading config',
|
|
386
|
+
payload: err
|
|
387
|
+
};
|
|
388
|
+
}
|
|
389
|
+
async function detectProxyServer(localBackend) {
|
|
390
|
+
const allowedHosts = ['localhost', '127.0.0.1', ...(typeof localBackend === 'boolean' ? [] : (localBackend === null || localBackend === void 0 ? void 0 : localBackend.allowed_hosts) || [])];
|
|
391
|
+
if (!allowedHosts.includes(location.hostname) || !localBackend) {
|
|
392
|
+
return {};
|
|
393
|
+
}
|
|
394
|
+
const defaultUrl = 'http://localhost:8081/api/v1';
|
|
395
|
+
const proxyUrl = localBackend === true ? defaultUrl : localBackend.url || defaultUrl.replace('localhost', location.hostname);
|
|
396
|
+
try {
|
|
397
|
+
console.log(`Looking for Decap CMS Proxy Server at '${proxyUrl}'`);
|
|
398
|
+
const res = await fetch(`${proxyUrl}`, {
|
|
399
|
+
method: 'POST',
|
|
400
|
+
headers: {
|
|
401
|
+
'Content-Type': 'application/json'
|
|
402
|
+
},
|
|
403
|
+
body: JSON.stringify({
|
|
404
|
+
action: 'info'
|
|
405
|
+
})
|
|
406
|
+
});
|
|
407
|
+
const {
|
|
408
|
+
repo,
|
|
409
|
+
publish_modes,
|
|
410
|
+
type
|
|
411
|
+
} = await res.json();
|
|
412
|
+
if (typeof repo === 'string' && Array.isArray(publish_modes) && typeof type === 'string') {
|
|
413
|
+
console.log(`Detected Decap CMS Proxy Server at '${proxyUrl}' with repo: '${repo}'`);
|
|
414
|
+
return {
|
|
415
|
+
proxyUrl,
|
|
416
|
+
publish_modes,
|
|
417
|
+
type
|
|
418
|
+
};
|
|
419
|
+
} else {
|
|
420
|
+
console.log(`Decap CMS Proxy Server not detected at '${proxyUrl}'`);
|
|
421
|
+
return {};
|
|
422
|
+
}
|
|
423
|
+
} catch {
|
|
424
|
+
console.log(`Decap CMS Proxy Server not detected at '${proxyUrl}'`);
|
|
425
|
+
return {};
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
function getPublishMode(config, publishModes, backendType) {
|
|
429
|
+
if (config.publish_mode && publishModes && !publishModes.includes(config.publish_mode)) {
|
|
430
|
+
const newPublishMode = publishModes[0];
|
|
431
|
+
console.log(`'${config.publish_mode}' is not supported by '${backendType}' backend, switching to '${newPublishMode}'`);
|
|
432
|
+
return newPublishMode;
|
|
433
|
+
}
|
|
434
|
+
return config.publish_mode;
|
|
435
|
+
}
|
|
436
|
+
async function handleLocalBackend(originalConfig) {
|
|
437
|
+
if (!originalConfig.local_backend) {
|
|
438
|
+
return originalConfig;
|
|
439
|
+
}
|
|
440
|
+
const {
|
|
441
|
+
proxyUrl,
|
|
442
|
+
publish_modes: publishModes,
|
|
443
|
+
type: backendType
|
|
444
|
+
} = await detectProxyServer(originalConfig.local_backend);
|
|
445
|
+
if (!proxyUrl) {
|
|
446
|
+
return originalConfig;
|
|
447
|
+
}
|
|
448
|
+
return (0, _immer.produce)(originalConfig, config => {
|
|
449
|
+
config.backend.name = 'proxy';
|
|
450
|
+
config.backend.proxy_url = proxyUrl;
|
|
451
|
+
if (config.publish_mode) {
|
|
452
|
+
config.publish_mode = getPublishMode(config, publishModes, backendType);
|
|
453
|
+
}
|
|
454
|
+
});
|
|
455
|
+
}
|
|
456
|
+
function loadConfig(manualConfig = {}, onLoad) {
|
|
457
|
+
if (window.CMS_CONFIG) {
|
|
458
|
+
return configLoaded(window.CMS_CONFIG);
|
|
459
|
+
}
|
|
460
|
+
return async dispatch => {
|
|
461
|
+
dispatch(configLoading());
|
|
462
|
+
try {
|
|
463
|
+
const configUrl = getConfigUrl();
|
|
464
|
+
const hasManualConfig = !(0, _isEmpty2.default)(manualConfig);
|
|
465
|
+
const configYaml = manualConfig.load_config_file === false ? {} : await getConfigYaml(configUrl, hasManualConfig);
|
|
466
|
+
|
|
467
|
+
// Merge manual config into the config.yml one
|
|
468
|
+
const mergedConfig = (0, _deepmerge.default)(configYaml, manualConfig);
|
|
469
|
+
(0, _configSchema.validateConfig)(mergedConfig);
|
|
470
|
+
const withLocalBackend = await handleLocalBackend(mergedConfig);
|
|
471
|
+
const normalizedConfig = normalizeConfig(withLocalBackend);
|
|
472
|
+
const config = applyDefaults(normalizedConfig);
|
|
473
|
+
dispatch(configLoaded(config));
|
|
474
|
+
if (typeof onLoad === 'function') {
|
|
475
|
+
onLoad();
|
|
476
|
+
}
|
|
477
|
+
} catch (err) {
|
|
478
|
+
dispatch(configFailed(err));
|
|
479
|
+
throw err;
|
|
480
|
+
}
|
|
481
|
+
};
|
|
482
|
+
}
|