sb-mig 5.6.0-beta.1 → 5.6.0-beta.3
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 +2 -15
- package/dist/api/auth/auth.types.d.ts +1 -1
- 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 +47 -0
- package/dist/api-v2/discover/discover.js +328 -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 +53 -100
- 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 +368 -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 +43 -27
- package/dist/utils/pkg-require.d.ts +0 -2
- package/dist/utils/pkg-require.js +0 -4
package/dist/api/migrate.js
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import { apiConfig } from "../cli/api-config.js";
|
|
2
2
|
import { compare, discover, discoverMany, discoverManyByPackageName, discoverStories, LOOKUP_TYPE, SCOPE, } from "../cli/utils/discover.js";
|
|
3
|
-
import { dumpToFile } from "../utils/files.js";
|
|
3
|
+
import { dumpToFile, getFileContentWithRequire, getFilesContentWithRequire, } from "../utils/files.js";
|
|
4
4
|
import Logger from "../utils/logger.js";
|
|
5
|
-
import { getFileContentWithRequire, getFilesContentWithRequire, isObjectEmpty, } from "../utils/main.js";
|
|
6
5
|
import { getAllAssets, migrateAsset } from "./assets/assets.js";
|
|
6
|
+
import { syncComponentsData } from "./components/components.sync.js";
|
|
7
7
|
import { contentHubApi } from "./contentHubApi.js";
|
|
8
8
|
import { managementApi } from "./managementApi.js";
|
|
9
9
|
import { backupStories } from "./stories/backup.js";
|
|
10
10
|
import { getAllStories } from "./stories/stories.js";
|
|
11
11
|
import { createTree, traverseAndCreate } from "./stories/tree.js";
|
|
12
|
-
import { _uniqueValuesFrom } from "./utils/helper-functions.js";
|
|
13
12
|
import { resolveGlobalTransformations } from "./utils/resolverTransformations.js";
|
|
14
13
|
const _checkAndPrepareGroups = async (groupsToCheck, config) => {
|
|
15
14
|
const componentsGroups = await managementApi.components.getAllComponentsGroups(config);
|
|
@@ -65,51 +64,7 @@ export const syncComponents = async (specifiedComponents, presets, config) => {
|
|
|
65
64
|
* - .sb.resolvers.ts files resolvers
|
|
66
65
|
*/
|
|
67
66
|
specifiedComponentsContent = await resolveGlobalTransformations(specifiedComponentsContent);
|
|
68
|
-
|
|
69
|
-
.filter((component) => component.component_group_name)
|
|
70
|
-
.map((component) => component.component_group_name));
|
|
71
|
-
await _checkAndPrepareGroups(groupsToCheck, config);
|
|
72
|
-
// after checkAndPrepareGroups remoteComponents will have synced groups with local groups
|
|
73
|
-
// updates of the groups had to happen before creation of them, cause creation/updates of components
|
|
74
|
-
// happens async, so if one component will have the same group, as other one
|
|
75
|
-
// it will be race of condition kinda issue - we will never now, if the group for current processed component
|
|
76
|
-
// already exist or is being created by other request
|
|
77
|
-
const remoteComponents = await managementApi.components.getAllComponents(config);
|
|
78
|
-
const componentsToUpdate = [];
|
|
79
|
-
const componentsToCreate = [];
|
|
80
|
-
for (const component of specifiedComponentsContent) {
|
|
81
|
-
if (!isObjectEmpty(component)) {
|
|
82
|
-
const shouldBeUpdated = remoteComponents.find((remoteComponent) => component.name === remoteComponent.name);
|
|
83
|
-
if (shouldBeUpdated) {
|
|
84
|
-
componentsToUpdate.push({
|
|
85
|
-
id: shouldBeUpdated.id,
|
|
86
|
-
...component,
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
else {
|
|
90
|
-
componentsToCreate.push(component);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
const componentsGroups = await managementApi.components.getAllComponentsGroups(config);
|
|
95
|
-
const groupsResolvedForComponentsToUpdate = componentsToUpdate.length > 0 &&
|
|
96
|
-
(await Promise.all(componentsToUpdate.map((component) => _resolveGroups(component, groupsToCheck, componentsGroups, config))));
|
|
97
|
-
Logger.log("Components to update after check: ");
|
|
98
|
-
if (groupsResolvedForComponentsToUpdate) {
|
|
99
|
-
await Promise.allSettled(groupsResolvedForComponentsToUpdate.map((component) => {
|
|
100
|
-
Logger.warning(` ${component.name}`);
|
|
101
|
-
return managementApi.components.updateComponent(component, presets, config);
|
|
102
|
-
}));
|
|
103
|
-
}
|
|
104
|
-
const groupsResolvedForComponentToCreate = componentsToCreate.length > 0 &&
|
|
105
|
-
(await Promise.all(componentsToCreate.map((component) => _resolveGroups(component, groupsToCheck, componentsGroups, config))));
|
|
106
|
-
Logger.log("Components to create after check: ");
|
|
107
|
-
if (groupsResolvedForComponentToCreate) {
|
|
108
|
-
await Promise.allSettled(groupsResolvedForComponentToCreate.map((component) => {
|
|
109
|
-
Logger.warning(` ${component.name}`);
|
|
110
|
-
return managementApi.components.createComponent(component, presets, config);
|
|
111
|
-
}));
|
|
112
|
-
}
|
|
67
|
+
await syncComponentsData({ components: specifiedComponentsContent, presets }, config);
|
|
113
68
|
};
|
|
114
69
|
export const syncAllComponents = async (presets, config) => {
|
|
115
70
|
// #1: discover all external .sb.js files
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export { getAllPlugins, getPlugin, updatePlugin, createPlugin, getPluginDetails,
|
|
1
|
+
export { getAllPlugins, getPlugin, updatePlugin, createPlugin, getPluginDetails, } from "./plugins.js";
|
|
2
|
+
export { syncProvidedPlugins } from "./plugins.sync.js";
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export { getAllPlugins, getPlugin, updatePlugin, createPlugin, getPluginDetails,
|
|
1
|
+
export { getAllPlugins, getPlugin, updatePlugin, createPlugin, getPluginDetails, } from "./plugins.js";
|
|
2
|
+
export { syncProvidedPlugins } from "./plugins.sync.js";
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import type { CreatePlugin, GetAllPlugins, GetPlugin, GetPluginDetails, UpdatePlugin } from "./plugins.types.js";
|
|
2
|
-
import type {
|
|
2
|
+
import type { SyncResult } from "../sync/sync.types.js";
|
|
3
3
|
export declare const getAllPlugins: GetAllPlugins;
|
|
4
4
|
export declare const getPlugin: GetPlugin;
|
|
5
5
|
export declare const getPluginDetails: GetPluginDetails;
|
|
6
6
|
export declare const updatePlugin: UpdatePlugin;
|
|
7
7
|
export declare const createPlugin: CreatePlugin;
|
|
8
|
-
export declare const
|
|
8
|
+
export declare const syncPluginsData: ({ plugins }: {
|
|
9
|
+
plugins: {
|
|
10
|
+
name: string;
|
|
11
|
+
body: string;
|
|
12
|
+
}[];
|
|
13
|
+
}, config: any) => Promise<SyncResult>;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { readFile } from "../../utils/files.js";
|
|
2
1
|
import Logger from "../../utils/logger.js";
|
|
3
2
|
import { getAllItemsWithPagination } from "../utils/request.js";
|
|
4
3
|
export const getAllPlugins = (config) => {
|
|
@@ -87,21 +86,35 @@ export const createPlugin = (pluginName, config) => {
|
|
|
87
86
|
console.error("Error happened :()");
|
|
88
87
|
});
|
|
89
88
|
};
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
89
|
+
// File-based sync wrapper lives in `plugins.sync.ts` to keep this module CJS-safe.
|
|
90
|
+
export const syncPluginsData = async ({ plugins }, config) => {
|
|
91
|
+
const result = {
|
|
92
|
+
created: [],
|
|
93
|
+
updated: [],
|
|
94
|
+
skipped: [],
|
|
95
|
+
errors: [],
|
|
96
|
+
};
|
|
97
|
+
for (const p of plugins) {
|
|
98
|
+
const name = String(p?.name ?? "unknown");
|
|
99
|
+
if (!p?.name) {
|
|
100
|
+
result.skipped.push(name);
|
|
101
|
+
continue;
|
|
99
102
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
103
|
+
try {
|
|
104
|
+
const plugin = await getPlugin(name, config);
|
|
105
|
+
if (plugin) {
|
|
106
|
+
await updatePlugin({ plugin: plugin.field_type, body: p.body }, config);
|
|
107
|
+
result.updated.push(name);
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
const created = await createPlugin(name, config);
|
|
111
|
+
await updatePlugin({ plugin: created.field_type, body: p.body }, config);
|
|
112
|
+
result.created.push(name);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
catch (e) {
|
|
116
|
+
result.errors.push({ name, message: String(e) });
|
|
105
117
|
}
|
|
106
118
|
}
|
|
119
|
+
return result;
|
|
107
120
|
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { readFile } from "../../utils/files.js";
|
|
2
|
+
import { syncPluginsData } from "./plugins.js";
|
|
3
|
+
export const syncProvidedPlugins = async ({ plugins }, config) => {
|
|
4
|
+
const body = await readFile("dist/export.js");
|
|
5
|
+
if (!body) {
|
|
6
|
+
throw new Error("Unable to read plugin bundle from dist/export.js");
|
|
7
|
+
}
|
|
8
|
+
await syncPluginsData({
|
|
9
|
+
plugins: plugins.map((name) => ({ name: String(name), body })),
|
|
10
|
+
}, config);
|
|
11
|
+
};
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export { createRole, getRole, getAllRoles,
|
|
1
|
+
export { createRole, getRole, getAllRoles, updateRole } from "./roles.js";
|
|
2
|
+
export { syncRoles } from "./roles.sync.js";
|
package/dist/api/roles/index.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export { createRole, getRole, getAllRoles,
|
|
1
|
+
export { createRole, getRole, getAllRoles, updateRole } from "./roles.js";
|
|
2
|
+
export { syncRoles } from "./roles.sync.js";
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import type { CreateRole, GetAllRoles, GetRole,
|
|
1
|
+
import type { CreateRole, GetAllRoles, GetRole, UpdateRole } from "./roles.types.js";
|
|
2
|
+
import type { SyncResult } from "../sync/sync.types.js";
|
|
2
3
|
export declare const createRole: CreateRole;
|
|
3
4
|
export declare const updateRole: UpdateRole;
|
|
4
5
|
export declare const getAllRoles: GetAllRoles;
|
|
5
6
|
export declare const getRole: GetRole;
|
|
6
|
-
export declare const
|
|
7
|
+
export declare const syncRolesData: ({ roles }: {
|
|
8
|
+
roles: any[];
|
|
9
|
+
}, config: any) => Promise<SyncResult>;
|
package/dist/api/roles/roles.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import Logger from "../../utils/logger.js";
|
|
2
|
-
import { getFileContentWithRequire } from "../../utils/main.js";
|
|
3
2
|
import { getAllItemsWithPagination } from "../utils/request.js";
|
|
4
3
|
// POST
|
|
5
4
|
export const createRole = (role, config) => {
|
|
6
5
|
const { sbApi, spaceId } = config;
|
|
7
|
-
sbApi
|
|
6
|
+
return sbApi
|
|
8
7
|
.post(`spaces/${spaceId}/space_roles/`, {
|
|
9
8
|
space_role: role,
|
|
10
9
|
})
|
|
@@ -14,12 +13,13 @@ export const createRole = (role, config) => {
|
|
|
14
13
|
.catch((err) => {
|
|
15
14
|
Logger.error("error happened... :(");
|
|
16
15
|
console.log(`${err.message} in migration of ${role.role} in createRole function`);
|
|
16
|
+
throw err;
|
|
17
17
|
});
|
|
18
18
|
};
|
|
19
19
|
// PUT
|
|
20
20
|
export const updateRole = (role, config) => {
|
|
21
21
|
const { sbApi, spaceId } = config;
|
|
22
|
-
sbApi
|
|
22
|
+
return sbApi
|
|
23
23
|
.put(`spaces/${spaceId}/space_roles/${role.id}`, {
|
|
24
24
|
space_role: role,
|
|
25
25
|
})
|
|
@@ -29,6 +29,7 @@ export const updateRole = (role, config) => {
|
|
|
29
29
|
.catch((err) => {
|
|
30
30
|
Logger.error("error happened... :(");
|
|
31
31
|
console.log(`${err.message} in migration of ${role.role} in updateRole function`);
|
|
32
|
+
throw err;
|
|
32
33
|
});
|
|
33
34
|
};
|
|
34
35
|
// GET
|
|
@@ -74,12 +75,22 @@ export const getRole = async (roleName, config) => {
|
|
|
74
75
|
})
|
|
75
76
|
.catch((err) => Logger.error(err));
|
|
76
77
|
};
|
|
77
|
-
export const
|
|
78
|
-
const
|
|
79
|
-
|
|
78
|
+
export const syncRolesData = async ({ roles }, config) => {
|
|
79
|
+
const result = {
|
|
80
|
+
created: [],
|
|
81
|
+
updated: [],
|
|
82
|
+
skipped: [],
|
|
83
|
+
errors: [],
|
|
84
|
+
};
|
|
85
|
+
const space_roles_raw = await getAllRoles(config);
|
|
86
|
+
const space_roles = Array.isArray(space_roles_raw) ? space_roles_raw : [];
|
|
80
87
|
const rolesToUpdate = [];
|
|
81
88
|
const rolesToCreate = [];
|
|
82
|
-
for (const role of
|
|
89
|
+
for (const role of roles) {
|
|
90
|
+
if (!role || typeof role !== "object" || !("role" in role)) {
|
|
91
|
+
result.skipped.push(String(role?.role ?? "unknown"));
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
83
94
|
const shouldBeUpdated = space_roles.find((remoteRole) => role.role === remoteRole.role);
|
|
84
95
|
if (shouldBeUpdated) {
|
|
85
96
|
rolesToUpdate.push({ id: shouldBeUpdated.id, ...role });
|
|
@@ -88,10 +99,22 @@ export const syncRoles = async ({ specifiedRoles }, config) => {
|
|
|
88
99
|
rolesToCreate.push(role);
|
|
89
100
|
}
|
|
90
101
|
}
|
|
91
|
-
rolesToUpdate.map(
|
|
92
|
-
|
|
102
|
+
const updateResults = await Promise.allSettled(rolesToUpdate.map((role) => updateRole(role, config)));
|
|
103
|
+
updateResults.forEach((r, idx) => {
|
|
104
|
+
const name = String(rolesToUpdate[idx]?.role ?? "unknown");
|
|
105
|
+
if (r.status === "fulfilled")
|
|
106
|
+
result.updated.push(name);
|
|
107
|
+
else
|
|
108
|
+
result.errors.push({ name, message: String(r.reason) });
|
|
93
109
|
});
|
|
94
|
-
rolesToCreate.map(
|
|
95
|
-
|
|
110
|
+
const createResults = await Promise.allSettled(rolesToCreate.map((role) => createRole(role, config)));
|
|
111
|
+
createResults.forEach((r, idx) => {
|
|
112
|
+
const name = String(rolesToCreate[idx]?.role ?? "unknown");
|
|
113
|
+
if (r.status === "fulfilled")
|
|
114
|
+
result.created.push(name);
|
|
115
|
+
else
|
|
116
|
+
result.errors.push({ name, message: String(r.reason) });
|
|
96
117
|
});
|
|
118
|
+
return result;
|
|
97
119
|
};
|
|
120
|
+
// File-based sync wrapper lives in `roles.sync.ts` to keep this module CJS-safe.
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { getFileContentWithRequire } from "../../utils/files.js";
|
|
2
|
+
import { syncRolesData } from "./roles.js";
|
|
3
|
+
export const syncRoles = async ({ specifiedRoles }, config) => {
|
|
4
|
+
const specifiedRolesContent = await Promise.all(specifiedRoles.map((roles) => getFileContentWithRequire({ file: roles.p })));
|
|
5
|
+
await syncRolesData({ roles: specifiedRolesContent }, config);
|
|
6
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { OneFileElement } from "../../
|
|
1
|
+
import type { OneFileElement } from "../../utils/path-utils.js";
|
|
2
2
|
import type { RequestBaseConfig } from "../utils/request.js";
|
|
3
3
|
export type GetRole = (roleName: string | undefined, config: RequestBaseConfig) => Promise<void>;
|
|
4
4
|
export type GetAllRoles = (config: RequestBaseConfig) => Promise<any>;
|
|
@@ -1,15 +1,7 @@
|
|
|
1
1
|
import chalk from "chalk";
|
|
2
2
|
import Logger from "../../utils/logger.js";
|
|
3
|
-
import {
|
|
3
|
+
import { notNullish } from "../../utils/object-utils.js";
|
|
4
4
|
import { getAllItemsWithPagination } from "../utils/request.js";
|
|
5
|
-
const notNullish = (params) => {
|
|
6
|
-
return Object.keys(params).reduce((acc, key) => {
|
|
7
|
-
if (params[key] !== null && params[key] !== undefined) {
|
|
8
|
-
acc[key] = params[key];
|
|
9
|
-
}
|
|
10
|
-
return acc;
|
|
11
|
-
}, {});
|
|
12
|
-
};
|
|
13
5
|
export const removeStory = (args, config) => {
|
|
14
6
|
const { storyId } = args;
|
|
15
7
|
const { spaceId, sbApi } = config;
|
|
@@ -151,7 +143,7 @@ export const upsertStory = async (args, config) => {
|
|
|
151
143
|
else if (storySlug) {
|
|
152
144
|
// if this exist than we update story with this slug (probably when we try to add story from one space to another,
|
|
153
145
|
console.log("You've selected slug!");
|
|
154
|
-
const foundStory = await
|
|
146
|
+
const foundStory = await getStoryBySlug(storySlug, config);
|
|
155
147
|
console.log("This is story");
|
|
156
148
|
console.log(foundStory);
|
|
157
149
|
if (foundStory) {
|
|
@@ -160,7 +152,7 @@ export const upsertStory = async (args, config) => {
|
|
|
160
152
|
else {
|
|
161
153
|
const { story: { parent_id, id, parent, ...rest }, } = content;
|
|
162
154
|
console.log("We are going to create story");
|
|
163
|
-
const response = await
|
|
155
|
+
const response = await createStory(rest, config);
|
|
164
156
|
console.log("This is response");
|
|
165
157
|
console.log(response);
|
|
166
158
|
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export type SyncError = {
|
|
2
|
+
name: string;
|
|
3
|
+
message: string;
|
|
4
|
+
};
|
|
5
|
+
export interface SyncResult {
|
|
6
|
+
created: string[];
|
|
7
|
+
updated: string[];
|
|
8
|
+
skipped: string[];
|
|
9
|
+
errors: SyncError[];
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Progress event emitted during sync operations
|
|
13
|
+
*/
|
|
14
|
+
export interface SyncProgressEvent {
|
|
15
|
+
type: "start" | "progress" | "complete";
|
|
16
|
+
/** Current item index (1-based) */
|
|
17
|
+
current?: number;
|
|
18
|
+
/** Total number of items */
|
|
19
|
+
total?: number;
|
|
20
|
+
/** Name of the component/resource being synced */
|
|
21
|
+
name?: string;
|
|
22
|
+
/** Action performed */
|
|
23
|
+
action?: "creating" | "updating" | "created" | "updated" | "skipped" | "error";
|
|
24
|
+
/** Optional message */
|
|
25
|
+
message?: string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Callback function for reporting sync progress
|
|
29
|
+
*/
|
|
30
|
+
export type SyncProgressCallback = (event: SyncProgressEvent) => void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/api/testApi.d.ts
CHANGED
|
@@ -25,8 +25,8 @@ export declare const testApi: {
|
|
|
25
25
|
createDatasource: import("./datasources/datasources.types.js").CreateDatasource;
|
|
26
26
|
getDatasource: import("./datasources/datasources.types.js").GetDatasource;
|
|
27
27
|
getAllDatasources: import("./datasources/datasources.types.js").GetAllDatasources;
|
|
28
|
-
syncDatasources: import("./datasources/datasources.types.js").SyncDatasources;
|
|
29
28
|
updateDatasource: import("./datasources/datasources.types.js").UpdateDatasource;
|
|
29
|
+
syncDatasources: import("./datasources/datasources.types.js").SyncDatasources;
|
|
30
30
|
};
|
|
31
31
|
plugins: {
|
|
32
32
|
getAllPlugins: import("./plugins/plugins.types.js").GetAllPlugins;
|
|
@@ -48,8 +48,8 @@ export declare const testApi: {
|
|
|
48
48
|
createRole: import("./roles/roles.types.js").CreateRole;
|
|
49
49
|
getRole: import("./roles/roles.types.js").GetRole;
|
|
50
50
|
getAllRoles: import("./roles/roles.types.js").GetAllRoles;
|
|
51
|
-
syncRoles: import("./roles/roles.types.js").SyncRoles;
|
|
52
51
|
updateRole: import("./roles/roles.types.js").UpdateRole;
|
|
52
|
+
syncRoles: import("./roles/roles.types.js").SyncRoles;
|
|
53
53
|
};
|
|
54
54
|
stories: {
|
|
55
55
|
createStory: import("./stories/stories.types.js").CreateStory;
|
|
@@ -1 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Re-exports for backwards compatibility
|
|
3
|
+
* Functions have been moved to their proper modules
|
|
4
|
+
*/
|
|
5
|
+
// Array utilities - now in utils/array-utils.ts
|
|
6
|
+
export { _uniqueValuesFrom, uniqueValuesFrom, } from "../../utils/array-utils.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { IStoryblokConfig } from "../../config/config.js";
|
|
1
|
+
import type { IStoryblokConfig } from "../../config/config.types.js";
|
|
2
2
|
import type StoryblokClient from "storyblok-js-client";
|
|
3
3
|
export interface RequestBaseConfig extends Partial<Omit<IStoryblokConfig, "sbApi">> {
|
|
4
4
|
spaceId: string;
|
|
@@ -7,8 +7,14 @@ export const getAllItemsWithPagination = async ({ apiFn, params, itemsKey, }) =>
|
|
|
7
7
|
let amountOfFetchedItems = 0;
|
|
8
8
|
do {
|
|
9
9
|
const response = await apiFn({ per_page, page, ...params });
|
|
10
|
+
// Handle case where API call failed and returned undefined
|
|
11
|
+
if (!response || !response.data) {
|
|
12
|
+
Logger.warning(`API returned no data for ${itemsKey}`);
|
|
13
|
+
return allItems;
|
|
14
|
+
}
|
|
10
15
|
if (!totalPages) {
|
|
11
|
-
totalPages =
|
|
16
|
+
totalPages =
|
|
17
|
+
Math.ceil((response.total ?? 0) / (response.perPage ?? per_page)) || 1;
|
|
12
18
|
}
|
|
13
19
|
/**
|
|
14
20
|
*
|
|
@@ -25,7 +31,10 @@ export const getAllItemsWithPagination = async ({ apiFn, params, itemsKey, }) =>
|
|
|
25
31
|
Logger.success(`${amountOfFetchedItems} of ${response.total} items fetched.`);
|
|
26
32
|
}
|
|
27
33
|
}
|
|
28
|
-
|
|
34
|
+
const items = response.data?.[itemsKey];
|
|
35
|
+
if (Array.isArray(items)) {
|
|
36
|
+
allItems.push(...items);
|
|
37
|
+
}
|
|
29
38
|
page++;
|
|
30
39
|
} while (page <= totalPages);
|
|
31
40
|
return allItems;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { discoverResolvers, LOOKUP_TYPE, SCOPE, } from "../../cli/utils/discover.js";
|
|
2
2
|
import config from "../../config/config.js";
|
|
3
|
-
import { getFileContentWithRequire } from "../../utils/
|
|
3
|
+
import { getFileContentWithRequire } from "../../utils/files.js";
|
|
4
|
+
import { deepTransform, extendField, isContentAvailableAsBloks, isItemsAvailableAsBloks, } from "../../utils/transform-utils.js";
|
|
4
5
|
export const transformWithResolverFiles = async (componentsContent) => {
|
|
5
6
|
componentsContent = structuredClone(componentsContent);
|
|
6
7
|
const resolversFilenames = await discoverResolvers({
|
|
@@ -20,12 +21,6 @@ export const transformWithResolverFiles = async (componentsContent) => {
|
|
|
20
21
|
}
|
|
21
22
|
return componentsContent;
|
|
22
23
|
};
|
|
23
|
-
const isContentAvailableAsBloks = (component) => "content" in component.schema &&
|
|
24
|
-
component.schema.content.component_whitelist &&
|
|
25
|
-
component.schema.content.type === "bloks";
|
|
26
|
-
const isItemsAvailableAsBloks = (component) => "items" in component.schema &&
|
|
27
|
-
component.schema.items.component_whitelist &&
|
|
28
|
-
component.schema.items.type === "bloks";
|
|
29
24
|
const updateComponentWhitelist = ({ component, update, }) => {
|
|
30
25
|
if (isContentAvailableAsBloks(component)) {
|
|
31
26
|
component.schema.content.component_whitelist = [
|
|
@@ -73,31 +68,6 @@ export const resolveGlobalTransformations = async (componentsContent) => {
|
|
|
73
68
|
componentsContent = await transformWithMainConfigFile(componentsContent);
|
|
74
69
|
return componentsContent;
|
|
75
70
|
};
|
|
76
|
-
const extendField = (obj, targetField, newValue) => {
|
|
77
|
-
if (typeof obj !== "object" || obj === null) {
|
|
78
|
-
return false;
|
|
79
|
-
}
|
|
80
|
-
if (obj.hasOwnProperty(targetField)) {
|
|
81
|
-
if (Array.isArray(obj[targetField])) {
|
|
82
|
-
for (const element of newValue) {
|
|
83
|
-
if (!obj[targetField].includes(element)) {
|
|
84
|
-
obj[targetField] = [...obj[targetField], element];
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
else if (typeof obj[targetField] === "object") {
|
|
89
|
-
// this is something i have to fix, comparing to object is stupid
|
|
90
|
-
obj[targetField] = { ...obj[targetField], ...newValue };
|
|
91
|
-
}
|
|
92
|
-
return true;
|
|
93
|
-
}
|
|
94
|
-
for (const key in obj) {
|
|
95
|
-
if (extendField(obj[key], targetField, newValue)) {
|
|
96
|
-
return true;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
return false;
|
|
100
|
-
};
|
|
101
71
|
const resolveAll = (resolver, componentsContent) => {
|
|
102
72
|
if (!resolver.all)
|
|
103
73
|
return componentsContent;
|
|
@@ -109,31 +79,6 @@ export const extendFields = (componentNamesResolver, component) => {
|
|
|
109
79
|
console.log(targetField);
|
|
110
80
|
extendField(component, targetField, componentNamesResolver.methods.extend[targetField]);
|
|
111
81
|
};
|
|
112
|
-
function deepTransform(obj, transformers) {
|
|
113
|
-
if (typeof obj !== "object" || obj === null) {
|
|
114
|
-
return obj;
|
|
115
|
-
}
|
|
116
|
-
const result = Array.isArray(obj) ? [...obj] : { ...obj };
|
|
117
|
-
for (const key in transformers) {
|
|
118
|
-
if (typeof transformers[key] === "function") {
|
|
119
|
-
result[key] = transformers[key](obj[key]);
|
|
120
|
-
}
|
|
121
|
-
else if (typeof transformers[key] === "object" &&
|
|
122
|
-
transformers[key] !== null) {
|
|
123
|
-
result[key] = deepTransform(obj[key] || {}, transformers[key]);
|
|
124
|
-
}
|
|
125
|
-
else {
|
|
126
|
-
result[key] = transformers[key];
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
// Preserve untransformed properties
|
|
130
|
-
for (const key in obj) {
|
|
131
|
-
if (!(key in transformers)) {
|
|
132
|
-
result[key] = obj[key];
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
return result;
|
|
136
|
-
}
|
|
137
82
|
export const resolverTransformations = (componentsContent, resolverFilesContent) => {
|
|
138
83
|
let resolvedComponents = [];
|
|
139
84
|
resolvedComponents = resolveComponentNames(resolverFilesContent, componentsContent);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ApiClient } from "../client.js";
|
|
2
|
+
export declare function getAllAssets(client: ApiClient, args: {
|
|
3
|
+
spaceId: string;
|
|
4
|
+
search?: string;
|
|
5
|
+
}): Promise<any>;
|
|
6
|
+
export declare function getAssetById(client: ApiClient, args: {
|
|
7
|
+
spaceId: string;
|
|
8
|
+
assetId: number;
|
|
9
|
+
}): Promise<any>;
|
|
10
|
+
export declare function getAssetByName(client: ApiClient, args: {
|
|
11
|
+
spaceId: string;
|
|
12
|
+
fileName: string;
|
|
13
|
+
}): Promise<any>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export async function getAllAssets(client, args) {
|
|
2
|
+
const { spaceId, search } = args;
|
|
3
|
+
return client.sbApi
|
|
4
|
+
.get(`spaces/${spaceId}/assets/`, {
|
|
5
|
+
// @ts-ignore storyblok-js-client mismatch: documentation uses `search`
|
|
6
|
+
search: search ?? "",
|
|
7
|
+
per_page: 100,
|
|
8
|
+
})
|
|
9
|
+
.then(({ data }) => data);
|
|
10
|
+
}
|
|
11
|
+
export async function getAssetById(client, args) {
|
|
12
|
+
const { spaceId, assetId } = args;
|
|
13
|
+
return client.sbApi
|
|
14
|
+
.get(`spaces/${spaceId}/assets/${assetId}`)
|
|
15
|
+
.then(({ data }) => data);
|
|
16
|
+
}
|
|
17
|
+
export async function getAssetByName(client, args) {
|
|
18
|
+
const result = await getAllAssets(client, {
|
|
19
|
+
spaceId: args.spaceId,
|
|
20
|
+
search: args.fileName,
|
|
21
|
+
});
|
|
22
|
+
if (result?.assets?.length === 1)
|
|
23
|
+
return result.assets[0];
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { getCurrentUser as apiGetCurrentUser, hasAccessToSpace as apiHasAccessToSpace, } from "../../api/auth/auth.js";
|
|
2
|
+
import { toRequestConfig } from "../requestConfig.js";
|
|
3
|
+
export async function getCurrentUser(client) {
|
|
4
|
+
return await apiGetCurrentUser(toRequestConfig(client));
|
|
5
|
+
}
|
|
6
|
+
export async function hasAccessToSpace(client, spaceId) {
|
|
7
|
+
return await apiHasAccessToSpace({ spaceId }, toRequestConfig(client));
|
|
8
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import StoryblokClient from "storyblok-js-client";
|
|
2
|
+
export interface ClientConfig {
|
|
3
|
+
oauthToken: string;
|
|
4
|
+
spaceId: string;
|
|
5
|
+
accessToken?: string;
|
|
6
|
+
rateLimit?: number;
|
|
7
|
+
}
|
|
8
|
+
export interface ApiClient {
|
|
9
|
+
config: ClientConfig;
|
|
10
|
+
sbApi: StoryblokClient;
|
|
11
|
+
spaceId: string;
|
|
12
|
+
}
|
|
13
|
+
export declare function createClient(options: ClientConfig): ApiClient;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import StoryblokClient from "storyblok-js-client";
|
|
2
|
+
export function createClient(options) {
|
|
3
|
+
const sbApi = new StoryblokClient({
|
|
4
|
+
oauthToken: options.oauthToken,
|
|
5
|
+
accessToken: options.accessToken,
|
|
6
|
+
rateLimit: options.rateLimit ?? 3,
|
|
7
|
+
cache: {
|
|
8
|
+
clear: "auto",
|
|
9
|
+
type: "none",
|
|
10
|
+
},
|
|
11
|
+
}, "https://mapi.storyblok.com/v1");
|
|
12
|
+
return {
|
|
13
|
+
config: options,
|
|
14
|
+
sbApi,
|
|
15
|
+
spaceId: options.spaceId,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ApiClient } from "../client.js";
|
|
2
|
+
export declare function getAllComponents(client: ApiClient): Promise<any[]>;
|
|
3
|
+
export declare function getComponent(client: ApiClient, componentName: string): Promise<any>;
|
|
4
|
+
export declare function getAllComponentsGroups(client: ApiClient): Promise<any[]>;
|
|
5
|
+
export declare function getComponentsGroup(client: ApiClient, groupName: string): Promise<any>;
|
|
6
|
+
export declare function createComponentsGroup(client: ApiClient, groupName: string): Promise<any>;
|
|
7
|
+
export declare function removeComponentGroup(client: ApiClient, componentGroup: any): Promise<any>;
|
|
8
|
+
export declare function removeComponent(client: ApiClient, component: any): Promise<any>;
|
|
9
|
+
export declare function createComponent(client: ApiClient, component: any, presets?: boolean): Promise<any>;
|
|
10
|
+
export declare function updateComponent(client: ApiClient, component: any, presets?: boolean): Promise<any>;
|