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
|
@@ -0,0 +1,23 @@
|
|
|
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.createClient = createClient;
|
|
7
|
+
const storyblok_js_client_1 = __importDefault(require("storyblok-js-client"));
|
|
8
|
+
function createClient(options) {
|
|
9
|
+
const sbApi = new storyblok_js_client_1.default({
|
|
10
|
+
oauthToken: options.oauthToken,
|
|
11
|
+
accessToken: options.accessToken,
|
|
12
|
+
rateLimit: options.rateLimit ?? 3,
|
|
13
|
+
cache: {
|
|
14
|
+
clear: "auto",
|
|
15
|
+
type: "none",
|
|
16
|
+
},
|
|
17
|
+
}, "https://mapi.storyblok.com/v1");
|
|
18
|
+
return {
|
|
19
|
+
config: options,
|
|
20
|
+
sbApi,
|
|
21
|
+
spaceId: options.spaceId,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getAllComponents = getAllComponents;
|
|
4
|
+
exports.getComponent = getComponent;
|
|
5
|
+
exports.getAllComponentsGroups = getAllComponentsGroups;
|
|
6
|
+
exports.getComponentsGroup = getComponentsGroup;
|
|
7
|
+
exports.createComponentsGroup = createComponentsGroup;
|
|
8
|
+
exports.removeComponentGroup = removeComponentGroup;
|
|
9
|
+
exports.removeComponent = removeComponent;
|
|
10
|
+
exports.createComponent = createComponent;
|
|
11
|
+
exports.updateComponent = updateComponent;
|
|
12
|
+
const components_js_1 = require("../../api/components/components.js");
|
|
13
|
+
const requestConfig_js_1 = require("../requestConfig.js");
|
|
14
|
+
async function getAllComponents(client) {
|
|
15
|
+
return await (0, components_js_1.getAllComponents)((0, requestConfig_js_1.toRequestConfig)(client));
|
|
16
|
+
}
|
|
17
|
+
async function getComponent(client, componentName) {
|
|
18
|
+
return await (0, components_js_1.getComponent)(componentName, (0, requestConfig_js_1.toRequestConfig)(client));
|
|
19
|
+
}
|
|
20
|
+
async function getAllComponentsGroups(client) {
|
|
21
|
+
return await (0, components_js_1.getAllComponentsGroups)((0, requestConfig_js_1.toRequestConfig)(client));
|
|
22
|
+
}
|
|
23
|
+
async function getComponentsGroup(client, groupName) {
|
|
24
|
+
return await (0, components_js_1.getComponentsGroup)(groupName, (0, requestConfig_js_1.toRequestConfig)(client));
|
|
25
|
+
}
|
|
26
|
+
async function createComponentsGroup(client, groupName) {
|
|
27
|
+
return await (0, components_js_1.createComponentsGroup)(groupName, (0, requestConfig_js_1.toRequestConfig)(client));
|
|
28
|
+
}
|
|
29
|
+
async function removeComponentGroup(client, componentGroup) {
|
|
30
|
+
return await (0, components_js_1.removeComponentGroup)(componentGroup, (0, requestConfig_js_1.toRequestConfig)(client));
|
|
31
|
+
}
|
|
32
|
+
async function removeComponent(client, component) {
|
|
33
|
+
return await (0, components_js_1.removeComponent)(component, (0, requestConfig_js_1.toRequestConfig)(client));
|
|
34
|
+
}
|
|
35
|
+
async function createComponent(client, component, presets = false) {
|
|
36
|
+
return await (0, components_js_1.createComponent)(component, presets, (0, requestConfig_js_1.toRequestConfig)(client));
|
|
37
|
+
}
|
|
38
|
+
async function updateComponent(client, component, presets = false) {
|
|
39
|
+
return await (0, components_js_1.updateComponent)(component, presets, (0, requestConfig_js_1.toRequestConfig)(client));
|
|
40
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getAllDatasources = getAllDatasources;
|
|
4
|
+
exports.getDatasource = getDatasource;
|
|
5
|
+
exports.createDatasource = createDatasource;
|
|
6
|
+
exports.updateDatasource = updateDatasource;
|
|
7
|
+
const request_js_1 = require("../../api/utils/request.js");
|
|
8
|
+
async function getAllDatasources(client) {
|
|
9
|
+
const spaceId = client.spaceId;
|
|
10
|
+
return (0, request_js_1.getAllItemsWithPagination)({
|
|
11
|
+
apiFn: ({ per_page, page }) => client.sbApi.get(`spaces/${spaceId}/datasources/`, {
|
|
12
|
+
per_page,
|
|
13
|
+
page,
|
|
14
|
+
}),
|
|
15
|
+
params: { spaceId },
|
|
16
|
+
itemsKey: "datasources",
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
async function getDatasource(client, datasourceName) {
|
|
20
|
+
const datasources = await getAllDatasources(client);
|
|
21
|
+
const match = datasources.filter((d) => d.name === datasourceName);
|
|
22
|
+
if (Array.isArray(match) && match.length === 0)
|
|
23
|
+
return false;
|
|
24
|
+
return match;
|
|
25
|
+
}
|
|
26
|
+
async function createDatasource(client, datasource) {
|
|
27
|
+
const spaceId = client.spaceId;
|
|
28
|
+
const finalDatasource = {
|
|
29
|
+
name: datasource.name,
|
|
30
|
+
slug: datasource.slug,
|
|
31
|
+
dimensions: [...(datasource.dimensions ?? [])],
|
|
32
|
+
dimensions_attributes: [...(datasource.dimensions ?? [])],
|
|
33
|
+
};
|
|
34
|
+
return client.sbApi
|
|
35
|
+
.post(`spaces/${spaceId}/datasources/`, {
|
|
36
|
+
datasource: finalDatasource,
|
|
37
|
+
})
|
|
38
|
+
.then((res) => res.data);
|
|
39
|
+
}
|
|
40
|
+
async function updateDatasource(client, args) {
|
|
41
|
+
const spaceId = client.spaceId;
|
|
42
|
+
const { datasource, datasourceToBeUpdated } = args;
|
|
43
|
+
const dimensionsToCreate = (datasource.dimensions ?? []).filter((dimension) => {
|
|
44
|
+
const isDimensionInRemoteDatasource = datasourceToBeUpdated.dimensions?.find((d) => dimension.name === d.name);
|
|
45
|
+
return !isDimensionInRemoteDatasource;
|
|
46
|
+
});
|
|
47
|
+
return client.sbApi
|
|
48
|
+
.put(`spaces/${spaceId}/datasources/${datasourceToBeUpdated.id}`, {
|
|
49
|
+
datasource: {
|
|
50
|
+
id: datasourceToBeUpdated.id,
|
|
51
|
+
name: datasource.name,
|
|
52
|
+
slug: datasource.slug,
|
|
53
|
+
dimensions: [
|
|
54
|
+
...(datasourceToBeUpdated.dimensions ?? []),
|
|
55
|
+
...dimensionsToCreate,
|
|
56
|
+
],
|
|
57
|
+
dimensions_attributes: [
|
|
58
|
+
...(datasourceToBeUpdated.dimensions ?? []),
|
|
59
|
+
...dimensionsToCreate,
|
|
60
|
+
],
|
|
61
|
+
},
|
|
62
|
+
})
|
|
63
|
+
.then((res) => res.data);
|
|
64
|
+
}
|
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.loadResourceContent = loadResourceContent;
|
|
37
|
+
exports.loadResources = loadResources;
|
|
38
|
+
exports.discoverComponents = discoverComponents;
|
|
39
|
+
exports.discoverDatasources = discoverDatasources;
|
|
40
|
+
exports.discoverRoles = discoverRoles;
|
|
41
|
+
const promises_1 = require("fs/promises");
|
|
42
|
+
const path_1 = require("path");
|
|
43
|
+
const url_1 = require("url");
|
|
44
|
+
/**
|
|
45
|
+
* Load the content of a resource file (.sb.js, .datasource.js, etc.)
|
|
46
|
+
* Uses dynamic import to load ES modules and CommonJS
|
|
47
|
+
*/
|
|
48
|
+
async function loadResourceContent(filePath) {
|
|
49
|
+
try {
|
|
50
|
+
// Use dynamic import which works for both ESM and CJS
|
|
51
|
+
const fileUrl = (0, url_1.pathToFileURL)(filePath).href;
|
|
52
|
+
const module = await Promise.resolve(`${fileUrl}`).then(s => __importStar(require(s)));
|
|
53
|
+
return module.default || module;
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
throw new Error(`Failed to load ${filePath}: ${error instanceof Error ? error.message : String(error)}`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Load multiple resources by file path
|
|
61
|
+
*/
|
|
62
|
+
async function loadResources(filePaths) {
|
|
63
|
+
const results = [];
|
|
64
|
+
for (const filePath of filePaths) {
|
|
65
|
+
const name = filePath
|
|
66
|
+
.split("/")
|
|
67
|
+
.pop()
|
|
68
|
+
?.replace(/\.sb\.(js|cjs|mjs|ts)$/, "")
|
|
69
|
+
.replace(/\.(datasource|roles)\.(js|cjs|ts)$/, "")
|
|
70
|
+
.replace(/\.sb\.(datasource|roles)\.(js|cjs|ts)$/, "") ||
|
|
71
|
+
"unknown";
|
|
72
|
+
try {
|
|
73
|
+
const data = await loadResourceContent(filePath);
|
|
74
|
+
results.push({ name, filePath, data });
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
results.push({
|
|
78
|
+
name,
|
|
79
|
+
filePath,
|
|
80
|
+
data: null,
|
|
81
|
+
error: error instanceof Error ? error.message : String(error),
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return results;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Read componentsDirectories from storyblok.config.js if it exists
|
|
89
|
+
*/
|
|
90
|
+
async function readComponentDirectories(workingDir) {
|
|
91
|
+
const configFiles = [
|
|
92
|
+
"storyblok.config.js",
|
|
93
|
+
"storyblok.config.cjs",
|
|
94
|
+
"storyblok.config.mjs",
|
|
95
|
+
];
|
|
96
|
+
for (const configFile of configFiles) {
|
|
97
|
+
try {
|
|
98
|
+
const configPath = (0, path_1.join)(workingDir, configFile);
|
|
99
|
+
const configContent = await (0, promises_1.readFile)(configPath, "utf-8");
|
|
100
|
+
const match = configContent.match(/componentsDirectories\s*:\s*\[([\s\S]*?)\]/);
|
|
101
|
+
if (match && match[1]) {
|
|
102
|
+
const dirsMatch = match[1].match(/['"]([^'"]+)['"]/g);
|
|
103
|
+
if (dirsMatch) {
|
|
104
|
+
return dirsMatch.map((d) => d.replace(/['"]/g, ""));
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
break;
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
// Config file doesn't exist, continue
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return ["src", "components", "storyblok"];
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Check if a path is within the project directory
|
|
117
|
+
* Resolves symlinks and ensures we don't escape the project bounds
|
|
118
|
+
*/
|
|
119
|
+
async function isWithinProject(targetPath, projectRoot) {
|
|
120
|
+
try {
|
|
121
|
+
// Resolve both paths to handle symlinks
|
|
122
|
+
const resolvedTarget = await (0, promises_1.realpath)(targetPath);
|
|
123
|
+
const resolvedRoot = await (0, promises_1.realpath)(projectRoot);
|
|
124
|
+
// Check if target is within project root
|
|
125
|
+
return (resolvedTarget.startsWith(resolvedRoot + "/") ||
|
|
126
|
+
resolvedTarget === resolvedRoot);
|
|
127
|
+
}
|
|
128
|
+
catch {
|
|
129
|
+
// If we can't resolve the path, assume it's not safe
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Discover components in the working directory
|
|
135
|
+
* Prefers .ts for local files and .cjs for external (node_modules) files
|
|
136
|
+
* to avoid duplicates when both ESM and CJS versions exist
|
|
137
|
+
*
|
|
138
|
+
* Security: Stays within project bounds and doesn't follow symlinks outside
|
|
139
|
+
*/
|
|
140
|
+
async function discoverComponents(workingDir, options) {
|
|
141
|
+
const components = [];
|
|
142
|
+
// Priority order: .ts first (local), then .cjs (for node_modules)
|
|
143
|
+
// Skip .js and .mjs to avoid duplicates
|
|
144
|
+
const extensions = options?.extensions ?? [".sb.ts", ".sb.cjs"];
|
|
145
|
+
const includeExternal = options?.includeExternal ?? true;
|
|
146
|
+
const maxDepth = options?.maxDepth ?? 20;
|
|
147
|
+
// Resolve the project root for security checks
|
|
148
|
+
const projectRoot = (0, path_1.resolve)(workingDir);
|
|
149
|
+
const componentDirs = await readComponentDirectories(workingDir);
|
|
150
|
+
const scanDir = async (dir, isExternal, depth) => {
|
|
151
|
+
// Prevent excessive depth
|
|
152
|
+
if (depth > maxDepth) {
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
// Security: Ensure we're still within project bounds
|
|
156
|
+
if (!(await isWithinProject(dir, projectRoot))) {
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
try {
|
|
160
|
+
const entries = await (0, promises_1.readdir)(dir, { withFileTypes: true });
|
|
161
|
+
for (const entry of entries) {
|
|
162
|
+
const fullPath = (0, path_1.join)(dir, entry.name);
|
|
163
|
+
if (entry.isDirectory()) {
|
|
164
|
+
// Skip common non-source directories
|
|
165
|
+
if (entry.name === ".git" ||
|
|
166
|
+
entry.name === ".next" ||
|
|
167
|
+
entry.name === "dist" ||
|
|
168
|
+
entry.name === ".cache" ||
|
|
169
|
+
entry.name === "coverage") {
|
|
170
|
+
continue;
|
|
171
|
+
}
|
|
172
|
+
// Skip node_modules entirely if not including external
|
|
173
|
+
if (entry.name === "node_modules" && !includeExternal) {
|
|
174
|
+
continue;
|
|
175
|
+
}
|
|
176
|
+
const isNowExternal = isExternal || entry.name === "node_modules";
|
|
177
|
+
await scanDir(fullPath, isNowExternal, depth + 1);
|
|
178
|
+
}
|
|
179
|
+
else if (entry.isFile()) {
|
|
180
|
+
// Skip external files if not including them
|
|
181
|
+
if (isExternal && !includeExternal) {
|
|
182
|
+
continue;
|
|
183
|
+
}
|
|
184
|
+
for (const ext of extensions) {
|
|
185
|
+
if (entry.name.endsWith(ext) &&
|
|
186
|
+
!entry.name.startsWith("_")) {
|
|
187
|
+
const componentName = entry.name.replace(ext, "");
|
|
188
|
+
components.push({
|
|
189
|
+
name: componentName,
|
|
190
|
+
filePath: fullPath,
|
|
191
|
+
type: isExternal ? "external" : "local",
|
|
192
|
+
});
|
|
193
|
+
break;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
catch {
|
|
200
|
+
// Directory doesn't exist or can't be read
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
for (const dir of componentDirs) {
|
|
204
|
+
const fullDir = (0, path_1.join)(workingDir, dir);
|
|
205
|
+
// Skip if the directory path includes node_modules and we're not including external
|
|
206
|
+
if (dir.includes("node_modules") && !includeExternal) {
|
|
207
|
+
continue;
|
|
208
|
+
}
|
|
209
|
+
try {
|
|
210
|
+
const dirStat = await (0, promises_1.stat)(fullDir);
|
|
211
|
+
if (dirStat.isDirectory()) {
|
|
212
|
+
await scanDir(fullDir, dir.includes("node_modules"), 0);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
catch {
|
|
216
|
+
// Directory doesn't exist
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
// Also scan root
|
|
220
|
+
try {
|
|
221
|
+
const rootEntries = await (0, promises_1.readdir)(workingDir, { withFileTypes: true });
|
|
222
|
+
for (const entry of rootEntries) {
|
|
223
|
+
if (entry.isFile()) {
|
|
224
|
+
for (const ext of extensions) {
|
|
225
|
+
if (entry.name.endsWith(ext) &&
|
|
226
|
+
!entry.name.startsWith("_")) {
|
|
227
|
+
const componentName = entry.name.replace(ext, "");
|
|
228
|
+
if (!components.find((c) => c.name === componentName)) {
|
|
229
|
+
components.push({
|
|
230
|
+
name: componentName,
|
|
231
|
+
filePath: (0, path_1.join)(workingDir, entry.name),
|
|
232
|
+
type: "local",
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
break;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
catch {
|
|
242
|
+
// Ignore
|
|
243
|
+
}
|
|
244
|
+
// Deduplicate: prefer .ts over .cjs for same component name
|
|
245
|
+
const seen = new Map();
|
|
246
|
+
for (const component of components) {
|
|
247
|
+
const existing = seen.get(component.name);
|
|
248
|
+
if (!existing) {
|
|
249
|
+
seen.set(component.name, component);
|
|
250
|
+
}
|
|
251
|
+
else {
|
|
252
|
+
// Prefer .ts files over .cjs
|
|
253
|
+
if (component.filePath.endsWith(".ts") &&
|
|
254
|
+
!existing.filePath.endsWith(".ts")) {
|
|
255
|
+
seen.set(component.name, component);
|
|
256
|
+
}
|
|
257
|
+
// Prefer local over external
|
|
258
|
+
else if (component.type === "local" &&
|
|
259
|
+
existing.type === "external") {
|
|
260
|
+
seen.set(component.name, component);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
const deduplicated = Array.from(seen.values());
|
|
265
|
+
// Sort: local first, then by name
|
|
266
|
+
deduplicated.sort((a, b) => {
|
|
267
|
+
if (a.type !== b.type) {
|
|
268
|
+
return a.type === "local" ? -1 : 1;
|
|
269
|
+
}
|
|
270
|
+
return a.name.localeCompare(b.name);
|
|
271
|
+
});
|
|
272
|
+
return deduplicated;
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Discover datasources in the working directory
|
|
276
|
+
*/
|
|
277
|
+
async function discoverDatasources(workingDir) {
|
|
278
|
+
const datasources = [];
|
|
279
|
+
const extensions = [
|
|
280
|
+
".datasource.js",
|
|
281
|
+
".datasource.cjs",
|
|
282
|
+
".sb.datasource.js",
|
|
283
|
+
".sb.datasource.cjs",
|
|
284
|
+
];
|
|
285
|
+
const scanDir = async (dir) => {
|
|
286
|
+
try {
|
|
287
|
+
const entries = await (0, promises_1.readdir)(dir, { withFileTypes: true });
|
|
288
|
+
for (const entry of entries) {
|
|
289
|
+
const fullPath = (0, path_1.join)(dir, entry.name);
|
|
290
|
+
if (entry.isDirectory()) {
|
|
291
|
+
if (entry.name === ".git" ||
|
|
292
|
+
entry.name === ".next" ||
|
|
293
|
+
entry.name === "dist" ||
|
|
294
|
+
entry.name === "node_modules") {
|
|
295
|
+
continue;
|
|
296
|
+
}
|
|
297
|
+
await scanDir(fullPath);
|
|
298
|
+
}
|
|
299
|
+
else if (entry.isFile()) {
|
|
300
|
+
for (const ext of extensions) {
|
|
301
|
+
if (entry.name.endsWith(ext) &&
|
|
302
|
+
!entry.name.startsWith("_")) {
|
|
303
|
+
const name = entry.name
|
|
304
|
+
.replace(ext, "")
|
|
305
|
+
.replace(".sb", "");
|
|
306
|
+
datasources.push({
|
|
307
|
+
name,
|
|
308
|
+
filePath: fullPath,
|
|
309
|
+
type: "local",
|
|
310
|
+
});
|
|
311
|
+
break;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
catch {
|
|
318
|
+
// Skip
|
|
319
|
+
}
|
|
320
|
+
};
|
|
321
|
+
await scanDir(workingDir);
|
|
322
|
+
datasources.sort((a, b) => a.name.localeCompare(b.name));
|
|
323
|
+
return datasources;
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* Discover roles in the working directory
|
|
327
|
+
*/
|
|
328
|
+
async function discoverRoles(workingDir) {
|
|
329
|
+
const roles = [];
|
|
330
|
+
const extensions = [".sb.roles.js", ".sb.roles.cjs", ".sb.roles.ts"];
|
|
331
|
+
const scanDir = async (dir) => {
|
|
332
|
+
try {
|
|
333
|
+
const entries = await (0, promises_1.readdir)(dir, { withFileTypes: true });
|
|
334
|
+
for (const entry of entries) {
|
|
335
|
+
const fullPath = (0, path_1.join)(dir, entry.name);
|
|
336
|
+
if (entry.isDirectory()) {
|
|
337
|
+
if (entry.name === ".git" ||
|
|
338
|
+
entry.name === ".next" ||
|
|
339
|
+
entry.name === "dist" ||
|
|
340
|
+
entry.name === "node_modules") {
|
|
341
|
+
continue;
|
|
342
|
+
}
|
|
343
|
+
await scanDir(fullPath);
|
|
344
|
+
}
|
|
345
|
+
else if (entry.isFile()) {
|
|
346
|
+
for (const ext of extensions) {
|
|
347
|
+
if (entry.name.endsWith(ext) &&
|
|
348
|
+
!entry.name.startsWith("_")) {
|
|
349
|
+
const name = entry.name.replace(ext, "");
|
|
350
|
+
roles.push({
|
|
351
|
+
name,
|
|
352
|
+
filePath: fullPath,
|
|
353
|
+
type: "local",
|
|
354
|
+
});
|
|
355
|
+
break;
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
catch {
|
|
362
|
+
// Skip
|
|
363
|
+
}
|
|
364
|
+
};
|
|
365
|
+
await scanDir(workingDir);
|
|
366
|
+
roles.sort((a, b) => a.name.localeCompare(b.name));
|
|
367
|
+
return roles;
|
|
368
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.loadResources = exports.loadResourceContent = exports.discoverRoles = exports.discoverDatasources = exports.discoverComponents = void 0;
|
|
4
|
+
var discover_js_1 = require("./discover.js");
|
|
5
|
+
Object.defineProperty(exports, "discoverComponents", { enumerable: true, get: function () { return discover_js_1.discoverComponents; } });
|
|
6
|
+
Object.defineProperty(exports, "discoverDatasources", { enumerable: true, get: function () { return discover_js_1.discoverDatasources; } });
|
|
7
|
+
Object.defineProperty(exports, "discoverRoles", { enumerable: true, get: function () { return discover_js_1.discoverRoles; } });
|
|
8
|
+
Object.defineProperty(exports, "loadResourceContent", { enumerable: true, get: function () { return discover_js_1.loadResourceContent; } });
|
|
9
|
+
Object.defineProperty(exports, "loadResources", { enumerable: true, get: function () { return discover_js_1.loadResources; } });
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.precompile = exports.discover = exports.sync = exports.spaces = exports.roles = exports.presets = exports.plugins = exports.datasources = exports.components = exports.auth = exports.assets = exports.stories = exports.createClient = exports.testAsyncConnection = exports.testConnection = void 0;
|
|
37
|
+
// Test functions for ESM/CJS interop testing
|
|
38
|
+
var test_js_1 = require("./test.js");
|
|
39
|
+
Object.defineProperty(exports, "testConnection", { enumerable: true, get: function () { return test_js_1.testConnection; } });
|
|
40
|
+
Object.defineProperty(exports, "testAsyncConnection", { enumerable: true, get: function () { return test_js_1.testAsyncConnection; } });
|
|
41
|
+
// Client
|
|
42
|
+
var client_js_1 = require("./client.js");
|
|
43
|
+
Object.defineProperty(exports, "createClient", { enumerable: true, get: function () { return client_js_1.createClient; } });
|
|
44
|
+
// Stories
|
|
45
|
+
exports.stories = __importStar(require("./stories/index.js"));
|
|
46
|
+
// Resources (thin wrappers)
|
|
47
|
+
exports.assets = __importStar(require("./assets/index.js"));
|
|
48
|
+
exports.auth = __importStar(require("./auth/index.js"));
|
|
49
|
+
exports.components = __importStar(require("./components/index.js"));
|
|
50
|
+
exports.datasources = __importStar(require("./datasources/index.js"));
|
|
51
|
+
exports.plugins = __importStar(require("./plugins/index.js"));
|
|
52
|
+
exports.presets = __importStar(require("./presets/index.js"));
|
|
53
|
+
exports.roles = __importStar(require("./roles/index.js"));
|
|
54
|
+
exports.spaces = __importStar(require("./spaces/index.js"));
|
|
55
|
+
// Sync (data-only)
|
|
56
|
+
exports.sync = __importStar(require("./sync/index.js"));
|
|
57
|
+
// Discovery
|
|
58
|
+
exports.discover = __importStar(require("./discover/index.js"));
|
|
59
|
+
// Precompile (TypeScript to JS using Rollup + SWC)
|
|
60
|
+
exports.precompile = __importStar(require("./precompile/index.js"));
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getAllPlugins = getAllPlugins;
|
|
4
|
+
exports.getPlugin = getPlugin;
|
|
5
|
+
exports.getPluginDetails = getPluginDetails;
|
|
6
|
+
exports.updatePlugin = updatePlugin;
|
|
7
|
+
exports.createPlugin = createPlugin;
|
|
8
|
+
const request_js_1 = require("../../api/utils/request.js");
|
|
9
|
+
async function getAllPlugins(client) {
|
|
10
|
+
return (0, request_js_1.getAllItemsWithPagination)({
|
|
11
|
+
apiFn: ({ per_page, page }) => client.sbApi.get("field_types", { per_page, page }),
|
|
12
|
+
params: {},
|
|
13
|
+
itemsKey: "field_types",
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
async function getPlugin(client, pluginName) {
|
|
17
|
+
const plugins = await getAllPlugins(client);
|
|
18
|
+
const plugin = plugins.find((p) => p.name === pluginName);
|
|
19
|
+
if (!plugin)
|
|
20
|
+
return false;
|
|
21
|
+
return await getPluginDetails(client, plugin);
|
|
22
|
+
}
|
|
23
|
+
async function getPluginDetails(client, plugin) {
|
|
24
|
+
return client.sbApi
|
|
25
|
+
.get(`field_types/${plugin.id}`)
|
|
26
|
+
.then((res) => res.data);
|
|
27
|
+
}
|
|
28
|
+
async function updatePlugin(client, args) {
|
|
29
|
+
const { plugin, body } = args;
|
|
30
|
+
return client.sbApi
|
|
31
|
+
.put(`field_types/${plugin.id}`, {
|
|
32
|
+
publish: true,
|
|
33
|
+
field_type: {
|
|
34
|
+
body,
|
|
35
|
+
compiled_body: "",
|
|
36
|
+
},
|
|
37
|
+
})
|
|
38
|
+
.then((res) => res.data);
|
|
39
|
+
}
|
|
40
|
+
async function createPlugin(client, pluginName) {
|
|
41
|
+
return client.sbApi
|
|
42
|
+
.post("field_types", {
|
|
43
|
+
publish: true,
|
|
44
|
+
field_type: {
|
|
45
|
+
name: pluginName,
|
|
46
|
+
},
|
|
47
|
+
})
|
|
48
|
+
.then((res) => res.data);
|
|
49
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getCompiledPath = exports.extractComponentName = exports.precompile = void 0;
|
|
4
|
+
var precompile_js_1 = require("./precompile.js");
|
|
5
|
+
Object.defineProperty(exports, "precompile", { enumerable: true, get: function () { return precompile_js_1.precompile; } });
|
|
6
|
+
Object.defineProperty(exports, "extractComponentName", { enumerable: true, get: function () { return precompile_js_1.extractComponentName; } });
|
|
7
|
+
Object.defineProperty(exports, "getCompiledPath", { enumerable: true, get: function () { return precompile_js_1.getCompiledPath; } });
|