sb-mig 5.6.0-beta.1 → 5.6.0-beta.2
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 +20 -19
- package/dist/api/assets/assets.js +1 -14
- package/dist/api/components/components.js +2 -1
- package/dist/api/components/components.sync.d.ts +8 -0
- package/dist/api/components/components.sync.js +193 -0
- package/dist/api/data-migration/component-data-migration.js +2 -2
- package/dist/api/datasources/datasource-entries.js +4 -5
- package/dist/api/datasources/datasources.d.ts +5 -2
- package/dist/api/datasources/datasources.js +42 -35
- package/dist/api/datasources/datasources.sync.d.ts +2 -0
- package/dist/api/datasources/datasources.sync.js +11 -0
- package/dist/api/datasources/datasources.types.d.ts +1 -1
- package/dist/api/datasources/index.d.ts +2 -1
- package/dist/api/datasources/index.js +2 -1
- package/dist/api/managementApi.d.ts +2 -2
- package/dist/api/migrate.d.ts +1 -1
- package/dist/api/migrate.js +3 -48
- package/dist/api/plugins/index.d.ts +2 -1
- package/dist/api/plugins/index.js +2 -1
- package/dist/api/plugins/plugins.d.ts +7 -2
- package/dist/api/plugins/plugins.js +28 -15
- package/dist/api/plugins/plugins.sync.d.ts +2 -0
- package/dist/api/plugins/plugins.sync.js +11 -0
- package/dist/api/roles/index.d.ts +2 -1
- package/dist/api/roles/index.js +2 -1
- package/dist/api/roles/roles.d.ts +5 -2
- package/dist/api/roles/roles.js +34 -11
- package/dist/api/roles/roles.sync.d.ts +2 -0
- package/dist/api/roles/roles.sync.js +6 -0
- package/dist/api/roles/roles.types.d.ts +1 -1
- package/dist/api/stories/stories.js +3 -11
- package/dist/api/sync/sync.types.d.ts +30 -0
- package/dist/api/sync/sync.types.js +1 -0
- package/dist/api/testApi.d.ts +2 -2
- package/dist/api/utils/helper-functions.d.ts +5 -1
- package/dist/api/utils/helper-functions.js +6 -1
- package/dist/api/utils/request.d.ts +1 -1
- package/dist/api/utils/request.js +11 -2
- package/dist/api/utils/resolverTransformations.js +2 -57
- package/dist/api-v2/assets/index.d.ts +13 -0
- package/dist/api-v2/assets/index.js +25 -0
- package/dist/api-v2/auth/index.d.ts +3 -0
- package/dist/api-v2/auth/index.js +8 -0
- package/dist/api-v2/client.d.ts +13 -0
- package/dist/api-v2/client.js +17 -0
- package/dist/api-v2/components/index.d.ts +10 -0
- package/dist/api-v2/components/index.js +29 -0
- package/dist/api-v2/datasources/index.d.ts +8 -0
- package/dist/api-v2/datasources/index.js +58 -0
- package/dist/api-v2/discover/discover.d.ts +36 -0
- package/dist/api-v2/discover/discover.js +281 -0
- package/dist/api-v2/discover/index.d.ts +2 -0
- package/dist/api-v2/discover/index.js +1 -0
- package/dist/api-v2/index.d.ts +19 -0
- package/dist/api-v2/index.js +21 -0
- package/dist/api-v2/plugins/index.d.ts +9 -0
- package/dist/api-v2/plugins/index.js +42 -0
- package/dist/api-v2/precompile/index.d.ts +2 -0
- package/dist/api-v2/precompile/index.js +1 -0
- package/dist/api-v2/precompile/precompile.d.ts +65 -0
- package/dist/api-v2/precompile/precompile.js +127 -0
- package/dist/api-v2/presets/index.d.ts +13 -0
- package/dist/api-v2/presets/index.js +25 -0
- package/dist/api-v2/requestConfig.d.ts +5 -0
- package/dist/api-v2/requestConfig.js +34 -0
- package/dist/api-v2/roles/index.d.ts +5 -0
- package/dist/api-v2/roles/index.js +35 -0
- package/dist/api-v2/spaces/index.d.ts +7 -0
- package/dist/api-v2/spaces/index.js +11 -0
- package/dist/api-v2/stories/index.d.ts +34 -0
- package/dist/api-v2/stories/index.js +172 -0
- package/dist/api-v2/stories/types.d.ts +28 -0
- package/dist/api-v2/stories/types.js +1 -0
- package/dist/api-v2/sync/index.d.ts +24 -0
- package/dist/api-v2/sync/index.js +109 -0
- package/dist/api-v2/sync/types.d.ts +1 -0
- package/dist/api-v2/sync/types.js +1 -0
- package/dist/api-v2/test.d.ts +15 -0
- package/dist/api-v2/test.js +21 -0
- package/dist/cli/commands/backup.js +7 -3
- package/dist/cli/commands/copy.js +2 -2
- package/dist/cli/commands/migrate.js +1 -2
- package/dist/cli/commands/migrations.js +2 -2
- package/dist/cli/commands/remove.js +1 -1
- package/dist/cli/commands/revert.js +2 -2
- package/dist/cli/commands/sync.js +1 -2
- package/dist/cli/index.js +1 -1
- package/dist/cli/utils/cli-utils.d.ts +69 -0
- package/dist/cli/utils/cli-utils.js +100 -0
- package/dist/cli/utils/discover.d.ts +3 -22
- package/dist/cli/utils/discover.js +4 -51
- package/dist/config/config.d.ts +2 -39
- package/dist/config/config.types.d.ts +40 -0
- package/dist/config/config.types.js +1 -0
- package/dist/config/defaultConfig.d.ts +1 -1
- package/dist/config/defaultConfig.js +2 -2
- package/dist/utils/array-utils.d.ts +20 -0
- package/dist/utils/array-utils.js +20 -0
- package/dist/utils/async-utils.d.ts +13 -0
- package/dist/utils/async-utils.js +13 -0
- package/dist/utils/date-utils.d.ts +14 -0
- package/dist/utils/date-utils.js +21 -0
- package/dist/utils/files.d.ts +35 -0
- package/dist/utils/files.js +57 -2
- package/dist/utils/main.d.ts +8 -18
- package/dist/utils/main.js +12 -104
- package/dist/utils/migrations.d.ts +9 -3
- package/dist/utils/object-utils.d.ts +46 -0
- package/dist/utils/object-utils.js +71 -0
- package/dist/utils/others.d.ts +6 -9
- package/dist/utils/others.js +8 -15
- package/dist/utils/path-utils.d.ts +89 -0
- package/dist/utils/path-utils.js +106 -0
- package/dist/utils/pkg.d.ts +16 -2
- package/dist/utils/pkg.js +16 -3
- package/dist/utils/string-utils.d.ts +33 -0
- package/dist/utils/string-utils.js +45 -0
- package/dist/utils/transform-utils.d.ts +62 -0
- package/dist/utils/transform-utils.js +113 -0
- package/dist-cjs/api/auth/auth.js +28 -0
- package/dist-cjs/api/auth/auth.types.js +2 -0
- package/dist-cjs/api/components/components.js +202 -0
- package/dist-cjs/api/components/components.sync.js +199 -0
- package/dist-cjs/api/components/components.types.js +2 -0
- package/dist-cjs/api/datasources/datasource-entries.js +166 -0
- package/dist-cjs/api/datasources/datasources.js +166 -0
- package/dist-cjs/api/datasources/datasources.types.js +2 -0
- package/dist-cjs/api/plugins/plugins.js +132 -0
- package/dist-cjs/api/plugins/plugins.types.js +2 -0
- package/dist-cjs/api/presets/componentPresets.js +25 -0
- package/dist-cjs/api/presets/presets.js +92 -0
- package/dist-cjs/api/presets/presets.types.js +2 -0
- package/dist-cjs/api/presets/resolvePresets.js +49 -0
- package/dist-cjs/api/roles/roles.js +131 -0
- package/dist-cjs/api/roles/roles.types.js +2 -0
- package/dist-cjs/api/spaces/spaces.js +34 -0
- package/dist-cjs/api/spaces/spaces.types.js +2 -0
- package/dist-cjs/api/stories/stories.js +214 -0
- package/dist-cjs/api/stories/stories.types.js +2 -0
- package/dist-cjs/api/sync/sync.types.js +2 -0
- package/dist-cjs/api/utils/request.js +48 -0
- package/dist-cjs/api/utils/resolvers.types.js +2 -0
- package/dist-cjs/api-v2/assets/index.js +30 -0
- package/dist-cjs/api-v2/auth/index.js +12 -0
- package/dist-cjs/api-v2/client.js +23 -0
- package/dist-cjs/api-v2/components/index.js +40 -0
- package/dist-cjs/api-v2/datasources/index.js +64 -0
- package/dist-cjs/api-v2/discover/discover.js +321 -0
- package/dist-cjs/api-v2/discover/index.js +9 -0
- package/dist-cjs/api-v2/index.js +60 -0
- package/dist-cjs/api-v2/plugins/index.js +49 -0
- package/dist-cjs/api-v2/precompile/index.js +7 -0
- package/dist-cjs/api-v2/precompile/precompile.js +136 -0
- package/dist-cjs/api-v2/presets/index.js +33 -0
- package/dist-cjs/api-v2/requestConfig.js +37 -0
- package/dist-cjs/api-v2/roles/index.js +41 -0
- package/dist-cjs/api-v2/spaces/index.js +16 -0
- package/dist-cjs/api-v2/stories/index.js +180 -0
- package/dist-cjs/api-v2/stories/types.js +2 -0
- package/dist-cjs/api-v2/sync/index.js +115 -0
- package/dist-cjs/api-v2/sync/types.js +2 -0
- package/dist-cjs/api-v2/test.js +25 -0
- package/dist-cjs/config/config.types.js +2 -0
- package/dist-cjs/config/constants.js +29 -0
- package/dist-cjs/package.json +3 -0
- package/dist-cjs/utils/array-utils.js +24 -0
- package/dist-cjs/utils/logger.js +32 -0
- package/dist-cjs/utils/object-utils.js +77 -0
- package/dist-cjs/utils/path-utils.js +115 -0
- package/package.json +37 -20
- package/dist/utils/pkg-require.d.ts +0 -2
- package/dist/utils/pkg-require.js +0 -4
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.updateDatasourceEntry = exports.createDatasourceEntry = exports.createDatasourceEntries = exports.getDatasourceEntries = void 0;
|
|
7
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
+
const logger_js_1 = __importDefault(require("../../utils/logger.js"));
|
|
9
|
+
const object_utils_js_1 = require("../../utils/object-utils.js");
|
|
10
|
+
const datasources_js_1 = require("./datasources.js");
|
|
11
|
+
const _decorateWithDimensions = async (args, config) => {
|
|
12
|
+
const { currentDatasource, dimensionsData, _callback } = args;
|
|
13
|
+
const { spaceId, sbApi } = config;
|
|
14
|
+
// callback for create or update
|
|
15
|
+
await _callback();
|
|
16
|
+
const dimensionValueEntries = Object.entries(dimensionsData.dimensionValues);
|
|
17
|
+
return dimensionValueEntries.map(([name, value]) => {
|
|
18
|
+
const data = dimensionsData.datasourceDimensions.find((dimension) => dimension.name === name);
|
|
19
|
+
const params = {
|
|
20
|
+
datasource_entry: {
|
|
21
|
+
...dimensionsData.finalDatasource_entry,
|
|
22
|
+
id: dimensionsData.finalDatasource_entry.datasource_id,
|
|
23
|
+
dimension_value: value,
|
|
24
|
+
},
|
|
25
|
+
dimension_id: data.id,
|
|
26
|
+
};
|
|
27
|
+
return sbApi
|
|
28
|
+
.put(`spaces/${spaceId}/datasource_entries/${dimensionsData.finalDatasource_entry.id}`, params)
|
|
29
|
+
.then((_) => {
|
|
30
|
+
console.log(`${chalk_1.default.green("✓ Datasource Entry Dimension value for")} ${chalk_1.default.blue(dimensionsData.finalDatasource_entry.name)} and dimension ${chalk_1.default.blue(name)} in ${chalk_1.default.red(currentDatasource.datasource.name)} datasource ${chalk_1.default.green("was successfully updated.")}`);
|
|
31
|
+
return true;
|
|
32
|
+
})
|
|
33
|
+
.catch((err) => {
|
|
34
|
+
logger_js_1.default.error(err);
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
const getDatasourceEntries = async (args, config) => {
|
|
39
|
+
const { datasourceName } = args;
|
|
40
|
+
const { spaceId, sbApi } = config;
|
|
41
|
+
logger_js_1.default.log(`Trying to get '${datasourceName}' datasource entries.`);
|
|
42
|
+
const data = await (0, datasources_js_1.getDatasource)({ datasourceName }, config); // TODO: maybe this step is not needed, i think we can retrieve entries directly using slug (but using delivery api, not management)
|
|
43
|
+
if (data) {
|
|
44
|
+
return sbApi
|
|
45
|
+
.get(`spaces/${spaceId}/datasource_entries/`, {
|
|
46
|
+
datasource_id: data[0].id,
|
|
47
|
+
})
|
|
48
|
+
.then(async (response) => {
|
|
49
|
+
logger_js_1.default.success(`Datasource Entries for '${datasourceName}' datasource successfully retrieved.`);
|
|
50
|
+
const { data } = response;
|
|
51
|
+
return data;
|
|
52
|
+
})
|
|
53
|
+
.catch((err) => logger_js_1.default.error(err));
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
exports.getDatasourceEntries = getDatasourceEntries;
|
|
57
|
+
const createDatasourceEntries = (args, config) => {
|
|
58
|
+
const { datasource_entries, remoteDatasourceEntries, data } = args;
|
|
59
|
+
Promise.all(datasource_entries.map((datasourceEntry) => {
|
|
60
|
+
const datasourceToBeUpdated = remoteDatasourceEntries.datasource_entries.find((remoteDatasourceEntry) => remoteDatasourceEntry.name ===
|
|
61
|
+
Object.values(datasourceEntry)[0]);
|
|
62
|
+
if (datasourceToBeUpdated) {
|
|
63
|
+
return (0, exports.updateDatasourceEntry)({ data, datasourceEntry, datasourceToBeUpdated }, config);
|
|
64
|
+
}
|
|
65
|
+
return (0, exports.createDatasourceEntry)({ data, datasourceEntry }, config);
|
|
66
|
+
}))
|
|
67
|
+
.then((_) => {
|
|
68
|
+
logger_js_1.default.success(`Datasource entries for ${data.datasource.id} datasource id has been successfully synced.`);
|
|
69
|
+
return data;
|
|
70
|
+
})
|
|
71
|
+
.catch((err) => logger_js_1.default.error(err));
|
|
72
|
+
};
|
|
73
|
+
exports.createDatasourceEntries = createDatasourceEntries;
|
|
74
|
+
const _createDatasourceEntry = (args, config) => {
|
|
75
|
+
const { currentDatasource, finalDatasource_entry } = args;
|
|
76
|
+
const { spaceId, sbApi } = config;
|
|
77
|
+
if (config.debug) {
|
|
78
|
+
console.log("############# Entity to Create: ");
|
|
79
|
+
console.log(finalDatasource_entry);
|
|
80
|
+
console.log("################################");
|
|
81
|
+
}
|
|
82
|
+
return sbApi
|
|
83
|
+
.post(`spaces/${spaceId}/datasource_entries/`, {
|
|
84
|
+
datasource_entry: finalDatasource_entry,
|
|
85
|
+
})
|
|
86
|
+
.then(({ data }) => {
|
|
87
|
+
console.log(`${chalk_1.default.green("✓ Datasource Entry")} ${chalk_1.default.blue(data.datasource_entry.name)} in ${chalk_1.default.red(currentDatasource.datasource.name)} datasource ${chalk_1.default.green("was successfully created.")}`);
|
|
88
|
+
return data;
|
|
89
|
+
})
|
|
90
|
+
.catch((err) => {
|
|
91
|
+
if (config.debug) {
|
|
92
|
+
console.log("Full Create error: ");
|
|
93
|
+
console.log(err);
|
|
94
|
+
}
|
|
95
|
+
logger_js_1.default.error(`Unable to create datasource entry in ${currentDatasource.datasource.name} datasource.`);
|
|
96
|
+
});
|
|
97
|
+
};
|
|
98
|
+
const createDatasourceEntry = (args, config) => {
|
|
99
|
+
const { datasourceEntry, data } = args;
|
|
100
|
+
const finalDatasource_entry = {
|
|
101
|
+
name: datasourceEntry.name,
|
|
102
|
+
value: datasourceEntry.value,
|
|
103
|
+
datasource_id: data.datasource.id,
|
|
104
|
+
};
|
|
105
|
+
if ((0, object_utils_js_1.isObjectEmpty)(datasourceEntry.dimension_values)) {
|
|
106
|
+
return _createDatasourceEntry({ currentDatasource: data, finalDatasource_entry }, config);
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
return _decorateWithDimensions({
|
|
110
|
+
currentDatasource: data,
|
|
111
|
+
dimensionsData: {
|
|
112
|
+
finalDatasource_entry,
|
|
113
|
+
dimensionValues: datasourceEntry.dimension_values,
|
|
114
|
+
datasourceDimensions: data.datasource.dimensions,
|
|
115
|
+
},
|
|
116
|
+
_callback: () => _createDatasourceEntry({ currentDatasource: data, finalDatasource_entry }, config),
|
|
117
|
+
}, config);
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
exports.createDatasourceEntry = createDatasourceEntry;
|
|
121
|
+
const _updateDatasourceEntry = (args, config) => {
|
|
122
|
+
const { currentDatasource, finalDatasource_entry } = args;
|
|
123
|
+
const { spaceId, sbApi } = config;
|
|
124
|
+
return sbApi
|
|
125
|
+
.put(`spaces/${spaceId}/datasource_entries/${finalDatasource_entry.id}`, {
|
|
126
|
+
datasource_entry: finalDatasource_entry,
|
|
127
|
+
})
|
|
128
|
+
.then((_) => {
|
|
129
|
+
console.log(`${chalk_1.default.green("✓ Datasource Entry")} ${chalk_1.default.blue(finalDatasource_entry.name)} in ${chalk_1.default.red(currentDatasource.datasource.name)} datasource ${chalk_1.default.green("was successfully updated.")}`);
|
|
130
|
+
return true;
|
|
131
|
+
})
|
|
132
|
+
.catch((err) => {
|
|
133
|
+
if (config.debug) {
|
|
134
|
+
console.log("Full update error: ");
|
|
135
|
+
console.log(err);
|
|
136
|
+
}
|
|
137
|
+
logger_js_1.default.error(`Unable to update datasource entry in ${currentDatasource.datasource.name} datasource.`);
|
|
138
|
+
});
|
|
139
|
+
};
|
|
140
|
+
const updateDatasourceEntry = (args, config) => {
|
|
141
|
+
const { datasourceEntry, datasourceToBeUpdated, data } = args;
|
|
142
|
+
const finalDatasource_entry = {
|
|
143
|
+
name: datasourceEntry.name,
|
|
144
|
+
value: datasourceEntry.value,
|
|
145
|
+
datasource_id: data.datasource.id,
|
|
146
|
+
id: datasourceToBeUpdated.id,
|
|
147
|
+
};
|
|
148
|
+
if ((0, object_utils_js_1.isObjectEmpty)(datasourceEntry.dimension_values)) {
|
|
149
|
+
return _updateDatasourceEntry({ currentDatasource: data, finalDatasource_entry }, config);
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
return _decorateWithDimensions({
|
|
153
|
+
currentDatasource: data,
|
|
154
|
+
_callback: () => _updateDatasourceEntry({
|
|
155
|
+
currentDatasource: data,
|
|
156
|
+
finalDatasource_entry,
|
|
157
|
+
}, config),
|
|
158
|
+
dimensionsData: {
|
|
159
|
+
finalDatasource_entry,
|
|
160
|
+
dimensionValues: datasourceEntry.dimension_values,
|
|
161
|
+
datasourceDimensions: data.datasource.dimensions,
|
|
162
|
+
},
|
|
163
|
+
}, config);
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
exports.updateDatasourceEntry = updateDatasourceEntry;
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.syncDatasourcesData = exports.updateDatasource = exports.createDatasource = exports.getDatasource = exports.getAllDatasources = void 0;
|
|
7
|
+
const logger_js_1 = __importDefault(require("../../utils/logger.js"));
|
|
8
|
+
const request_js_1 = require("../utils/request.js");
|
|
9
|
+
const datasource_entries_js_1 = require("./datasource-entries.js");
|
|
10
|
+
// GET
|
|
11
|
+
const getAllDatasources = (config) => {
|
|
12
|
+
const { sbApi, spaceId } = config;
|
|
13
|
+
logger_js_1.default.log("Trying to get all Datasources.");
|
|
14
|
+
return (0, request_js_1.getAllItemsWithPagination)({
|
|
15
|
+
// @ts-ignore
|
|
16
|
+
apiFn: ({ per_page, page }) => {
|
|
17
|
+
return sbApi
|
|
18
|
+
.get(`spaces/${spaceId}/datasources/`)
|
|
19
|
+
.then((res) => {
|
|
20
|
+
if (res.total) {
|
|
21
|
+
logger_js_1.default.log(`Amount of datasources: ${res.total}`);
|
|
22
|
+
}
|
|
23
|
+
return res;
|
|
24
|
+
})
|
|
25
|
+
.catch((err) => {
|
|
26
|
+
if (err.response.status === 404) {
|
|
27
|
+
logger_js_1.default.error(`There is no datasources in your Storyblok ${spaceId} space.`);
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
logger_js_1.default.error(err);
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
},
|
|
36
|
+
params: {
|
|
37
|
+
spaceId,
|
|
38
|
+
},
|
|
39
|
+
itemsKey: "datasources",
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
exports.getAllDatasources = getAllDatasources;
|
|
43
|
+
const getDatasource = (args, config) => {
|
|
44
|
+
const { datasourceName } = args;
|
|
45
|
+
logger_js_1.default.log(`Trying to get '${datasourceName}' datasource.`);
|
|
46
|
+
return (0, exports.getAllDatasources)(config)
|
|
47
|
+
.then((res) => {
|
|
48
|
+
if (res) {
|
|
49
|
+
return res.filter((datasource) => datasource.name === datasourceName);
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
return [];
|
|
53
|
+
}
|
|
54
|
+
})
|
|
55
|
+
.then((res) => {
|
|
56
|
+
if (Array.isArray(res) && res.length === 0) {
|
|
57
|
+
logger_js_1.default.warning(`There is no datasource named '${datasourceName}'`);
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
return res;
|
|
61
|
+
})
|
|
62
|
+
.catch((err) => logger_js_1.default.error(err));
|
|
63
|
+
};
|
|
64
|
+
exports.getDatasource = getDatasource;
|
|
65
|
+
// POST
|
|
66
|
+
const createDatasource = (args, config) => {
|
|
67
|
+
const { datasource } = args;
|
|
68
|
+
const { sbApi, spaceId } = config;
|
|
69
|
+
const finalDatasource = {
|
|
70
|
+
name: datasource.name,
|
|
71
|
+
slug: datasource.slug,
|
|
72
|
+
dimensions: [...datasource.dimensions],
|
|
73
|
+
dimensions_attributes: [...datasource.dimensions],
|
|
74
|
+
};
|
|
75
|
+
return sbApi
|
|
76
|
+
.post(`spaces/${spaceId}/datasources/`, {
|
|
77
|
+
datasource: finalDatasource,
|
|
78
|
+
})
|
|
79
|
+
.then(({ data }) => {
|
|
80
|
+
logger_js_1.default.success(`Datasource '${data.datasource.name}' with id '${data.datasource.id}' created.`);
|
|
81
|
+
return {
|
|
82
|
+
data,
|
|
83
|
+
datasource_entries: datasource.datasource_entries,
|
|
84
|
+
};
|
|
85
|
+
})
|
|
86
|
+
.catch((err) => logger_js_1.default.error(err));
|
|
87
|
+
};
|
|
88
|
+
exports.createDatasource = createDatasource;
|
|
89
|
+
const updateDatasource = (args, config) => {
|
|
90
|
+
const { datasource, datasourceToBeUpdated } = args;
|
|
91
|
+
const { sbApi, spaceId } = config;
|
|
92
|
+
const dimensionsToCreate = datasource.dimensions.filter((dimension) => {
|
|
93
|
+
const isDimensionInRemoteDatasource = datasourceToBeUpdated.dimensions.find((d) => dimension.name === d.name);
|
|
94
|
+
return !isDimensionInRemoteDatasource;
|
|
95
|
+
});
|
|
96
|
+
return sbApi
|
|
97
|
+
.put(`spaces/${spaceId}/datasources/${datasourceToBeUpdated.id}`, {
|
|
98
|
+
datasource: {
|
|
99
|
+
id: datasourceToBeUpdated.id,
|
|
100
|
+
name: datasource.name,
|
|
101
|
+
slug: datasource.slug,
|
|
102
|
+
dimensions: [
|
|
103
|
+
...datasourceToBeUpdated.dimensions,
|
|
104
|
+
...dimensionsToCreate,
|
|
105
|
+
],
|
|
106
|
+
dimensions_attributes: [
|
|
107
|
+
...datasourceToBeUpdated.dimensions,
|
|
108
|
+
...dimensionsToCreate,
|
|
109
|
+
],
|
|
110
|
+
},
|
|
111
|
+
})
|
|
112
|
+
.then(({ data }) => {
|
|
113
|
+
logger_js_1.default.success(`Datasource '${data.datasource.name}' with id '${data.datasource.id}' created.`);
|
|
114
|
+
return {
|
|
115
|
+
data,
|
|
116
|
+
datasource_entries: datasource.datasource_entries,
|
|
117
|
+
};
|
|
118
|
+
})
|
|
119
|
+
.catch((err) => logger_js_1.default.error(err));
|
|
120
|
+
};
|
|
121
|
+
exports.updateDatasource = updateDatasource;
|
|
122
|
+
// File-based sync wrapper lives in `datasources.sync.ts` to keep this module CJS-safe.
|
|
123
|
+
const syncDatasourcesData = async ({ datasources }, config) => {
|
|
124
|
+
const result = {
|
|
125
|
+
created: [],
|
|
126
|
+
updated: [],
|
|
127
|
+
skipped: [],
|
|
128
|
+
errors: [],
|
|
129
|
+
};
|
|
130
|
+
const remoteDatasourcesRaw = await (0, exports.getAllDatasources)(config);
|
|
131
|
+
const remoteDatasources = Array.isArray(remoteDatasourcesRaw)
|
|
132
|
+
? remoteDatasourcesRaw
|
|
133
|
+
: [];
|
|
134
|
+
for (const datasource of datasources) {
|
|
135
|
+
const name = String(datasource?.name ?? "unknown");
|
|
136
|
+
if (!datasource || typeof datasource !== "object" || !datasource.name) {
|
|
137
|
+
result.skipped.push(name);
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
try {
|
|
141
|
+
const datasourceToBeUpdated = remoteDatasources.find((remoteDatasource) => datasource.name === remoteDatasource.name);
|
|
142
|
+
const opResult = datasourceToBeUpdated
|
|
143
|
+
? await (0, exports.updateDatasource)({ datasource, datasourceToBeUpdated }, config)
|
|
144
|
+
: await (0, exports.createDatasource)({ datasource }, config);
|
|
145
|
+
if (datasourceToBeUpdated)
|
|
146
|
+
result.updated.push(name);
|
|
147
|
+
else
|
|
148
|
+
result.created.push(name);
|
|
149
|
+
if (opResult?.data?.datasource && opResult?.datasource_entries) {
|
|
150
|
+
const remoteDatasourceEntries = await (0, datasource_entries_js_1.getDatasourceEntries)({
|
|
151
|
+
datasourceName: opResult.data.datasource.name,
|
|
152
|
+
}, config);
|
|
153
|
+
await (0, datasource_entries_js_1.createDatasourceEntries)({
|
|
154
|
+
data: opResult.data,
|
|
155
|
+
datasource_entries: opResult.datasource_entries,
|
|
156
|
+
remoteDatasourceEntries,
|
|
157
|
+
}, config);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
catch (e) {
|
|
161
|
+
result.errors.push({ name, message: String(e) });
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return result;
|
|
165
|
+
};
|
|
166
|
+
exports.syncDatasourcesData = syncDatasourcesData;
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.syncPluginsData = exports.createPlugin = exports.updatePlugin = exports.getPluginDetails = exports.getPlugin = exports.getAllPlugins = void 0;
|
|
7
|
+
const logger_js_1 = __importDefault(require("../../utils/logger.js"));
|
|
8
|
+
const request_js_1 = require("../utils/request.js");
|
|
9
|
+
const getAllPlugins = (config) => {
|
|
10
|
+
const { sbApi, spaceId } = config;
|
|
11
|
+
logger_js_1.default.log("Trying to get all plugins.");
|
|
12
|
+
return (0, request_js_1.getAllItemsWithPagination)({
|
|
13
|
+
apiFn: ({ per_page, page }) => sbApi
|
|
14
|
+
.get(`field_types`, {
|
|
15
|
+
per_page,
|
|
16
|
+
page,
|
|
17
|
+
})
|
|
18
|
+
.then((res) => {
|
|
19
|
+
logger_js_1.default.log(`Amount of field types: ${res.total}`);
|
|
20
|
+
return res;
|
|
21
|
+
})
|
|
22
|
+
.catch((err) => logger_js_1.default.error(err)),
|
|
23
|
+
params: {},
|
|
24
|
+
itemsKey: "field_types",
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
exports.getAllPlugins = getAllPlugins;
|
|
28
|
+
const getPlugin = (pluginName, config) => {
|
|
29
|
+
return (0, exports.getAllPlugins)(config)
|
|
30
|
+
.then((res) => res.find((plugin) => plugin.name === pluginName))
|
|
31
|
+
.then((res) => {
|
|
32
|
+
if (!res) {
|
|
33
|
+
throw Error("Not Found - plugins does not exist");
|
|
34
|
+
}
|
|
35
|
+
if (Array.isArray(res) && res.length === 0) {
|
|
36
|
+
console.info(`There is no plugin named '${pluginName}'`);
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
return res;
|
|
40
|
+
})
|
|
41
|
+
.then((plugin) => {
|
|
42
|
+
return (0, exports.getPluginDetails)(plugin, config)
|
|
43
|
+
.then((res) => res)
|
|
44
|
+
.catch((err) => console.error(err));
|
|
45
|
+
})
|
|
46
|
+
.catch((err) => {
|
|
47
|
+
logger_js_1.default.warning(err.message);
|
|
48
|
+
return false;
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
exports.getPlugin = getPlugin;
|
|
52
|
+
const getPluginDetails = (plugin, config) => {
|
|
53
|
+
const { sbApi } = config;
|
|
54
|
+
console.log(`Trying to get ${plugin.name} details `);
|
|
55
|
+
return sbApi
|
|
56
|
+
.get(`field_types/${plugin.id}`)
|
|
57
|
+
.then((res) => res.data)
|
|
58
|
+
.catch((err) => console.error(err));
|
|
59
|
+
};
|
|
60
|
+
exports.getPluginDetails = getPluginDetails;
|
|
61
|
+
const updatePlugin = ({ plugin, body }, config) => {
|
|
62
|
+
const { sbApi, spaceId } = config;
|
|
63
|
+
return sbApi
|
|
64
|
+
.put(`field_types/${plugin.id}`, {
|
|
65
|
+
publish: true,
|
|
66
|
+
field_type: {
|
|
67
|
+
body,
|
|
68
|
+
compiled_body: "",
|
|
69
|
+
},
|
|
70
|
+
})
|
|
71
|
+
.then((res) => {
|
|
72
|
+
logger_js_1.default.success(`'${plugin.name}' plugin updated!`);
|
|
73
|
+
return res.data;
|
|
74
|
+
})
|
|
75
|
+
.catch((err) => {
|
|
76
|
+
console.log(err);
|
|
77
|
+
console.error("Error happened :()");
|
|
78
|
+
});
|
|
79
|
+
};
|
|
80
|
+
exports.updatePlugin = updatePlugin;
|
|
81
|
+
const createPlugin = (pluginName, config) => {
|
|
82
|
+
const { sbApi, spaceId } = config;
|
|
83
|
+
return sbApi
|
|
84
|
+
.post(`field_types`, {
|
|
85
|
+
publish: true,
|
|
86
|
+
field_type: {
|
|
87
|
+
name: pluginName,
|
|
88
|
+
},
|
|
89
|
+
})
|
|
90
|
+
.then((res) => {
|
|
91
|
+
logger_js_1.default.success(`'${pluginName}' plugin created!`);
|
|
92
|
+
return res.data;
|
|
93
|
+
})
|
|
94
|
+
.catch((err) => {
|
|
95
|
+
console.log(err);
|
|
96
|
+
console.error("Error happened :()");
|
|
97
|
+
});
|
|
98
|
+
};
|
|
99
|
+
exports.createPlugin = createPlugin;
|
|
100
|
+
// File-based sync wrapper lives in `plugins.sync.ts` to keep this module CJS-safe.
|
|
101
|
+
const syncPluginsData = async ({ plugins }, config) => {
|
|
102
|
+
const result = {
|
|
103
|
+
created: [],
|
|
104
|
+
updated: [],
|
|
105
|
+
skipped: [],
|
|
106
|
+
errors: [],
|
|
107
|
+
};
|
|
108
|
+
for (const p of plugins) {
|
|
109
|
+
const name = String(p?.name ?? "unknown");
|
|
110
|
+
if (!p?.name) {
|
|
111
|
+
result.skipped.push(name);
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
try {
|
|
115
|
+
const plugin = await (0, exports.getPlugin)(name, config);
|
|
116
|
+
if (plugin) {
|
|
117
|
+
await (0, exports.updatePlugin)({ plugin: plugin.field_type, body: p.body }, config);
|
|
118
|
+
result.updated.push(name);
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
const created = await (0, exports.createPlugin)(name, config);
|
|
122
|
+
await (0, exports.updatePlugin)({ plugin: created.field_type, body: p.body }, config);
|
|
123
|
+
result.created.push(name);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
catch (e) {
|
|
127
|
+
result.errors.push({ name, message: String(e) });
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return result;
|
|
131
|
+
};
|
|
132
|
+
exports.syncPluginsData = syncPluginsData;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getComponentPresets = void 0;
|
|
7
|
+
const logger_js_1 = __importDefault(require("../../utils/logger.js"));
|
|
8
|
+
const components_js_1 = require("../components/components.js");
|
|
9
|
+
const presets_js_1 = require("./presets.js");
|
|
10
|
+
const getComponentPresets = (componentName, config) => {
|
|
11
|
+
logger_js_1.default.log(`Trying to get all '${componentName}' presets.`);
|
|
12
|
+
return (0, components_js_1.getAllComponents)(config).then(async (res) => {
|
|
13
|
+
const componentPresets = res.filter((component) => component.name === componentName);
|
|
14
|
+
if (componentPresets.length > 0) {
|
|
15
|
+
if (componentPresets[0].all_presets.length === 0) {
|
|
16
|
+
logger_js_1.default.warning(`There is no presets for: '${componentName}' component`);
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
return Promise.all(componentPresets[0].all_presets.map((preset) => (0, presets_js_1.getPreset)({ presetId: preset.id }, config).catch((err) => logger_js_1.default.error(err))));
|
|
20
|
+
}
|
|
21
|
+
logger_js_1.default.warning(`There is no '${componentName}' component`);
|
|
22
|
+
return false;
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
exports.getComponentPresets = getComponentPresets;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.updatePresets = exports.updatePreset = exports.createPreset = exports.getAllPresets = exports.getPreset = void 0;
|
|
7
|
+
const logger_js_1 = __importDefault(require("../../utils/logger.js"));
|
|
8
|
+
const request_js_1 = require("../utils/request.js");
|
|
9
|
+
// GET
|
|
10
|
+
const getPreset = (args, config) => {
|
|
11
|
+
const { presetId } = args;
|
|
12
|
+
const { spaceId, sbApi } = config;
|
|
13
|
+
logger_js_1.default.log(`Trying to get preset by id: ${presetId}`);
|
|
14
|
+
return sbApi
|
|
15
|
+
.get(`spaces/${spaceId}/presets/${presetId}`)
|
|
16
|
+
.then((response) => response.data)
|
|
17
|
+
.then((response) => {
|
|
18
|
+
if (Array.isArray(response.presets)) {
|
|
19
|
+
logger_js_1.default.warning(`There is no preset for '${presetId}' preset id`);
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
return response;
|
|
23
|
+
})
|
|
24
|
+
.catch((err) => logger_js_1.default.error(err));
|
|
25
|
+
};
|
|
26
|
+
exports.getPreset = getPreset;
|
|
27
|
+
const getAllPresets = (config) => {
|
|
28
|
+
const { spaceId, sbApi } = config;
|
|
29
|
+
logger_js_1.default.log("Trying to get all Presets.");
|
|
30
|
+
// TODO: All Presets doesnt support pagination...
|
|
31
|
+
// https://github.com/storyblok/storyblok-js-client/issues/535
|
|
32
|
+
return (0, request_js_1.getAllItemsWithPagination)({
|
|
33
|
+
apiFn: ({ per_page, page, spaceId }) => sbApi
|
|
34
|
+
.get(`spaces/${spaceId}/presets/`, { per_page, page })
|
|
35
|
+
.then((res) => {
|
|
36
|
+
logger_js_1.default.log(`Amount of presets: ${res.total}`);
|
|
37
|
+
return res;
|
|
38
|
+
})
|
|
39
|
+
.catch((err) => logger_js_1.default.error(err)),
|
|
40
|
+
params: {
|
|
41
|
+
spaceId,
|
|
42
|
+
},
|
|
43
|
+
itemsKey: "presets",
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
exports.getAllPresets = getAllPresets;
|
|
47
|
+
// CREATE
|
|
48
|
+
const createPreset = (p, config) => {
|
|
49
|
+
const { spaceId, sbApi } = config;
|
|
50
|
+
return sbApi
|
|
51
|
+
.post(`spaces/${spaceId}/presets/`, {
|
|
52
|
+
preset: p.preset,
|
|
53
|
+
})
|
|
54
|
+
.then((res) => {
|
|
55
|
+
logger_js_1.default.warning(`Preset: '${p.preset.name}' has been created.`);
|
|
56
|
+
return res;
|
|
57
|
+
})
|
|
58
|
+
.catch((e) => {
|
|
59
|
+
console.log("!!!!!!!!!!");
|
|
60
|
+
console.log(e);
|
|
61
|
+
logger_js_1.default.error(`Error happened. Preset: '${p.preset.name}' has been not created.`);
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
exports.createPreset = createPreset;
|
|
65
|
+
// UPDATE
|
|
66
|
+
const updatePreset = (args, config) => {
|
|
67
|
+
const { p } = args;
|
|
68
|
+
const { spaceId, sbApi } = config;
|
|
69
|
+
return sbApi
|
|
70
|
+
.put(`spaces/${spaceId}/presets/${p.preset.id}`, {
|
|
71
|
+
preset: p.preset,
|
|
72
|
+
})
|
|
73
|
+
.then((res) => {
|
|
74
|
+
logger_js_1.default.warning(`Preset: '${p.preset.name}' with '${p.preset.id}' id has been updated.`);
|
|
75
|
+
return res;
|
|
76
|
+
})
|
|
77
|
+
.catch(() => {
|
|
78
|
+
logger_js_1.default.error(`Error happened. Preset: '${p.preset.name}' with '${p.preset.id}' id has been not updated.`);
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
exports.updatePreset = updatePreset;
|
|
82
|
+
const updatePresets = (args, config) => {
|
|
83
|
+
const { presets, spaceId } = args;
|
|
84
|
+
return Promise.allSettled(presets.map(async (item) => {
|
|
85
|
+
return (0, exports.updatePreset)({
|
|
86
|
+
p: {
|
|
87
|
+
preset: item,
|
|
88
|
+
},
|
|
89
|
+
}, { ...config, spaceId });
|
|
90
|
+
}));
|
|
91
|
+
};
|
|
92
|
+
exports.updatePresets = updatePresets;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const logger_js_1 = __importDefault(require("../../utils/logger.js"));
|
|
7
|
+
const componentPresets_js_1 = require("./componentPresets.js");
|
|
8
|
+
const presets_js_1 = require("./presets.js");
|
|
9
|
+
const _resolvePresets = async (res, all_presets, component, config) => {
|
|
10
|
+
const componentId = res.data.component.id;
|
|
11
|
+
if (all_presets && all_presets.length > 0) {
|
|
12
|
+
const all_presets_modified = all_presets.map((p) => {
|
|
13
|
+
return { preset: { ...p.preset, component_id: componentId } };
|
|
14
|
+
});
|
|
15
|
+
logger_js_1.default.log(`Checking preset for '${component.name}' component`);
|
|
16
|
+
const allRemoteComponentPresets = await (0, componentPresets_js_1.getComponentPresets)(component.name, config);
|
|
17
|
+
const presetsToUpdate = [];
|
|
18
|
+
const presetsToCreate = [];
|
|
19
|
+
for (const componentPreset of all_presets_modified) {
|
|
20
|
+
const shouldBeUpdated = allRemoteComponentPresets &&
|
|
21
|
+
allRemoteComponentPresets.find((remotePreset) => componentPreset.preset.name ===
|
|
22
|
+
remotePreset.preset.name);
|
|
23
|
+
if (shouldBeUpdated) {
|
|
24
|
+
presetsToUpdate.push({
|
|
25
|
+
...componentPreset,
|
|
26
|
+
preset: {
|
|
27
|
+
id: shouldBeUpdated.preset.id,
|
|
28
|
+
...componentPreset.preset,
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
presetsToCreate.push(componentPreset);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
const presetsToUpdateResult = await Promise.all(presetsToUpdate.map((preset) => {
|
|
37
|
+
return (0, presets_js_1.updatePreset)({ p: preset }, config);
|
|
38
|
+
}));
|
|
39
|
+
const presetsToCreateResult = await Promise.all(presetsToCreate.map((preset) => {
|
|
40
|
+
return (0, presets_js_1.createPreset)(preset, config);
|
|
41
|
+
}));
|
|
42
|
+
return [...presetsToCreateResult, presetsToUpdateResult];
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
logger_js_1.default.warning("There are no presets for this component.");
|
|
46
|
+
return [];
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
exports.default = _resolvePresets;
|