storyblok 4.3.4 → 4.4.0
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/dist/index.mjs +103 -34
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -62,6 +62,13 @@ const regionsDomain = {
|
|
|
62
62
|
ca: "api-ca.storyblok.com",
|
|
63
63
|
ap: "api-ap.storyblok.com"
|
|
64
64
|
};
|
|
65
|
+
const managementApiRegions = {
|
|
66
|
+
eu: "mapi.storyblok.com",
|
|
67
|
+
us: "api-us.storyblok.com",
|
|
68
|
+
cn: "app.storyblokchina.cn",
|
|
69
|
+
ca: "api-ca.storyblok.com",
|
|
70
|
+
ap: "api-ap.storyblok.com"
|
|
71
|
+
};
|
|
65
72
|
const appDomains = {
|
|
66
73
|
eu: "app.storyblok.com",
|
|
67
74
|
us: "app-us.storyblok.com",
|
|
@@ -532,7 +539,7 @@ function getProgram() {
|
|
|
532
539
|
|
|
533
540
|
const API_VERSION = "v1";
|
|
534
541
|
const getStoryblokUrl = (region = "eu") => {
|
|
535
|
-
return `https://${
|
|
542
|
+
return `https://${managementApiRegions[region]}/${API_VERSION}`;
|
|
536
543
|
};
|
|
537
544
|
|
|
538
545
|
const loginWithToken = async (token, region) => {
|
|
@@ -723,7 +730,7 @@ function createSession() {
|
|
|
723
730
|
async function persistCredentials(region) {
|
|
724
731
|
if (state.isLoggedIn && state.login && state.password && state.region) {
|
|
725
732
|
await addCredentials({
|
|
726
|
-
machineName: regionsDomain[region] || "
|
|
733
|
+
machineName: regionsDomain[region] || "mapi.storyblok.com",
|
|
727
734
|
login: state.login,
|
|
728
735
|
password: state.password,
|
|
729
736
|
region: state.region
|
|
@@ -1003,6 +1010,7 @@ const getUser = async (token, region) => {
|
|
|
1003
1010
|
const program$f = getProgram();
|
|
1004
1011
|
program$f.command(commands.USER).description("Get the current user").action(async () => {
|
|
1005
1012
|
konsola.title(`${commands.USER}`, colorPalette.USER);
|
|
1013
|
+
const verbose = program$f.opts().verbose;
|
|
1006
1014
|
const { state, initializeSession } = session();
|
|
1007
1015
|
await initializeSession();
|
|
1008
1016
|
if (!requireAuthentication(state)) {
|
|
@@ -1018,6 +1026,9 @@ program$f.command(commands.USER).description("Get the current user").action(asyn
|
|
|
1018
1026
|
}
|
|
1019
1027
|
const { user } = await getUser(password, region);
|
|
1020
1028
|
spinner.succeed();
|
|
1029
|
+
if (verbose) {
|
|
1030
|
+
konsola.info(JSON.stringify(user, null, 2));
|
|
1031
|
+
}
|
|
1021
1032
|
konsola.ok(`Hi ${chalk.bold(user.friendly_name)}, you are currently logged in with ${chalk.hex(colorPalette.PRIMARY)(user.email)} on ${chalk.bold(region)} region`, true);
|
|
1022
1033
|
} catch (error) {
|
|
1023
1034
|
spinner.failed();
|
|
@@ -4671,7 +4682,12 @@ STORYBLOK_DELIVERY_API_TOKEN=${accessToken}
|
|
|
4671
4682
|
};
|
|
4672
4683
|
const generateSpaceUrl = (spaceId, region) => {
|
|
4673
4684
|
const domain = appDomains[region];
|
|
4674
|
-
|
|
4685
|
+
const utmParams = new URLSearchParams({
|
|
4686
|
+
utm_source: "storyblok-cli",
|
|
4687
|
+
utm_medium: "cli",
|
|
4688
|
+
utm_campaign: "create"
|
|
4689
|
+
});
|
|
4690
|
+
return `https://${domain}/#/me/spaces/${spaceId}/dashboard?${utmParams.toString()}`;
|
|
4675
4691
|
};
|
|
4676
4692
|
const openSpaceInBrowser = async (spaceId, region) => {
|
|
4677
4693
|
try {
|
|
@@ -4691,7 +4707,7 @@ const extractPortFromTopics = (topics) => {
|
|
|
4691
4707
|
}
|
|
4692
4708
|
return "3000";
|
|
4693
4709
|
};
|
|
4694
|
-
const
|
|
4710
|
+
const repositoryToTemplate = (repo) => {
|
|
4695
4711
|
const technology = repo.name.replace("blueprint-core-", "");
|
|
4696
4712
|
const port = extractPortFromTopics(repo.topics || []);
|
|
4697
4713
|
return {
|
|
@@ -4712,7 +4728,7 @@ const fetchBlueprintRepositories = async () => {
|
|
|
4712
4728
|
order: "desc",
|
|
4713
4729
|
per_page: 100
|
|
4714
4730
|
});
|
|
4715
|
-
const blueprints = data.items.filter((repo) => repo.name.startsWith("blueprint-core-")).map(
|
|
4731
|
+
const blueprints = data.items.filter((repo) => repo.name.startsWith("blueprint-core-")).map(repositoryToTemplate).sort((a, b) => a.name.localeCompare(b.name));
|
|
4716
4732
|
return blueprints;
|
|
4717
4733
|
} catch (error) {
|
|
4718
4734
|
handleAPIError("fetch_blueprints", error, "Failed to fetch blueprints from GitHub");
|
|
@@ -4732,10 +4748,17 @@ const createSpace = async (space) => {
|
|
|
4732
4748
|
};
|
|
4733
4749
|
|
|
4734
4750
|
const program$1 = getProgram();
|
|
4735
|
-
program$1.command(`${commands.CREATE} [project-path]`).alias("c").description(`Scaffold a new project using Storyblok`).option("-
|
|
4751
|
+
program$1.command(`${commands.CREATE} [project-path]`).alias("c").description(`Scaffold a new project using Storyblok`).option("-t, --template <template>", "technology starter template").option("-b, --blueprint <blueprint>", "[DEPRECATED] use --template instead").option("--skip-space", "skip space creation").action(async (projectPath, options) => {
|
|
4736
4752
|
konsola.title(`${commands.CREATE}`, colorPalette.CREATE);
|
|
4737
4753
|
const verbose = program$1.opts().verbose;
|
|
4738
|
-
const { blueprint } = options;
|
|
4754
|
+
const { template, blueprint } = options;
|
|
4755
|
+
let selectedTemplate = template;
|
|
4756
|
+
if (blueprint && !template) {
|
|
4757
|
+
konsola.warn(`The --blueprint flag is deprecated. Please use --template instead.`);
|
|
4758
|
+
selectedTemplate = blueprint;
|
|
4759
|
+
} else if (blueprint && template) {
|
|
4760
|
+
konsola.warn(`Both --blueprint and --template provided. Using --template and ignoring --blueprint.`);
|
|
4761
|
+
}
|
|
4739
4762
|
const { state, initializeSession } = session();
|
|
4740
4763
|
await initializeSession();
|
|
4741
4764
|
if (!requireAuthentication(state, verbose)) {
|
|
@@ -4752,33 +4775,42 @@ program$1.command(`${commands.CREATE} [project-path]`).alias("c").description(`S
|
|
|
4752
4775
|
const spinnerSpace = new Spinner({
|
|
4753
4776
|
verbose: !isVitest
|
|
4754
4777
|
});
|
|
4778
|
+
let userData;
|
|
4755
4779
|
try {
|
|
4756
|
-
|
|
4757
|
-
|
|
4758
|
-
|
|
4759
|
-
|
|
4780
|
+
const { user } = await getUser(password, region);
|
|
4781
|
+
userData = user;
|
|
4782
|
+
} catch (error) {
|
|
4783
|
+
konsola.error("Failed to fetch user info. Please login again.", error);
|
|
4784
|
+
konsola.br();
|
|
4785
|
+
return;
|
|
4786
|
+
}
|
|
4787
|
+
try {
|
|
4788
|
+
spinnerBlueprints.start("Fetching starter templates...");
|
|
4789
|
+
const templates = await fetchBlueprintRepositories();
|
|
4790
|
+
spinnerBlueprints.succeed("Starter templates fetched successfully");
|
|
4791
|
+
if (!templates) {
|
|
4760
4792
|
spinnerBlueprints.failed();
|
|
4761
|
-
konsola.warn("No starter
|
|
4793
|
+
konsola.warn("No starter templates found. Please contact support@storyblok.com");
|
|
4762
4794
|
konsola.br();
|
|
4763
4795
|
return;
|
|
4764
4796
|
}
|
|
4765
|
-
let
|
|
4766
|
-
if (
|
|
4767
|
-
const
|
|
4768
|
-
const
|
|
4769
|
-
if (!
|
|
4770
|
-
const validOptions =
|
|
4771
|
-
konsola.warn(`Invalid
|
|
4797
|
+
let technologyTemplate = selectedTemplate;
|
|
4798
|
+
if (selectedTemplate) {
|
|
4799
|
+
const validTemplates = templates;
|
|
4800
|
+
const isValidTemplate = validTemplates.find((bp) => bp.value === selectedTemplate);
|
|
4801
|
+
if (!isValidTemplate) {
|
|
4802
|
+
const validOptions = validTemplates.map((bp) => bp.value).join(", ");
|
|
4803
|
+
konsola.warn(`Invalid template "${chalk.hex(colorPalette.CREATE)(selectedTemplate)}". Valid options are: ${chalk.hex(colorPalette.CREATE)(validOptions)}`);
|
|
4772
4804
|
konsola.br();
|
|
4773
|
-
|
|
4805
|
+
technologyTemplate = void 0;
|
|
4774
4806
|
}
|
|
4775
4807
|
}
|
|
4776
|
-
if (!
|
|
4777
|
-
|
|
4808
|
+
if (!technologyTemplate) {
|
|
4809
|
+
technologyTemplate = await select({
|
|
4778
4810
|
message: "Please select the technology you would like to use:",
|
|
4779
|
-
choices:
|
|
4780
|
-
name:
|
|
4781
|
-
value:
|
|
4811
|
+
choices: templates.map((template2) => ({
|
|
4812
|
+
name: template2.name,
|
|
4813
|
+
value: template2.value
|
|
4782
4814
|
}))
|
|
4783
4815
|
});
|
|
4784
4816
|
}
|
|
@@ -4786,7 +4818,7 @@ program$1.command(`${commands.CREATE} [project-path]`).alias("c").description(`S
|
|
|
4786
4818
|
if (!projectPath) {
|
|
4787
4819
|
finalProjectPath = await input({
|
|
4788
4820
|
message: "What is the path for your project?",
|
|
4789
|
-
default: `./my-${
|
|
4821
|
+
default: `./my-${technologyTemplate}-project`,
|
|
4790
4822
|
validate: (value) => {
|
|
4791
4823
|
if (!value.trim()) {
|
|
4792
4824
|
return "Project path is required";
|
|
@@ -4803,19 +4835,50 @@ program$1.command(`${commands.CREATE} [project-path]`).alias("c").description(`S
|
|
|
4803
4835
|
const targetDirectory = path.dirname(resolvedPath);
|
|
4804
4836
|
const projectName = path.basename(resolvedPath);
|
|
4805
4837
|
konsola.br();
|
|
4806
|
-
konsola.info(`Scaffolding your project using the ${chalk.hex(colorPalette.CREATE)(
|
|
4807
|
-
await generateProject(
|
|
4838
|
+
konsola.info(`Scaffolding your project using the ${chalk.hex(colorPalette.CREATE)(technologyTemplate)} template...`);
|
|
4839
|
+
await generateProject(technologyTemplate, projectName, targetDirectory);
|
|
4808
4840
|
konsola.ok(`Project ${chalk.hex(colorPalette.PRIMARY)(projectName)} created successfully in ${chalk.hex(colorPalette.PRIMARY)(finalProjectPath)}`, true);
|
|
4809
4841
|
let createdSpace;
|
|
4842
|
+
const choices = [
|
|
4843
|
+
{ name: "My personal account", value: "personal" }
|
|
4844
|
+
];
|
|
4845
|
+
if (userData.has_org) {
|
|
4846
|
+
choices.push({ name: `Organization (${userData.org.name})`, value: "org" });
|
|
4847
|
+
}
|
|
4848
|
+
if (userData.has_partner) {
|
|
4849
|
+
choices.push({ name: "Partner Portal", value: "partner" });
|
|
4850
|
+
}
|
|
4851
|
+
let whereToCreateSpace = "personal";
|
|
4852
|
+
if (region === "eu" && (userData.has_partner || userData.has_org)) {
|
|
4853
|
+
whereToCreateSpace = await select({
|
|
4854
|
+
message: `Where would you like to create this space?`,
|
|
4855
|
+
choices
|
|
4856
|
+
});
|
|
4857
|
+
}
|
|
4858
|
+
if (region !== "eu" && userData.has_org) {
|
|
4859
|
+
whereToCreateSpace = "org";
|
|
4860
|
+
}
|
|
4861
|
+
if (region !== "eu" && !userData.has_org) {
|
|
4862
|
+
konsola.warn(`Space creation in this region is limited to Enterprise accounts. If you're part of an organization, please ensure you have the required permissions. For more information about Enterprise access, contact our Sales Team.`);
|
|
4863
|
+
konsola.br();
|
|
4864
|
+
return;
|
|
4865
|
+
}
|
|
4810
4866
|
if (!options.skipSpace) {
|
|
4811
4867
|
try {
|
|
4812
4868
|
spinnerSpace.start(`Creating space "${toHumanReadable(projectName)}"`);
|
|
4813
|
-
const selectedBlueprint =
|
|
4869
|
+
const selectedBlueprint = templates.find((bp) => bp.value === technologyTemplate);
|
|
4814
4870
|
const blueprintDomain = selectedBlueprint?.location || "https://localhost:3000/";
|
|
4815
|
-
|
|
4871
|
+
const spaceToCreate = {
|
|
4816
4872
|
name: toHumanReadable(projectName),
|
|
4817
4873
|
domain: blueprintDomain
|
|
4818
|
-
}
|
|
4874
|
+
};
|
|
4875
|
+
if (whereToCreateSpace === "org") {
|
|
4876
|
+
spaceToCreate.org = userData.org;
|
|
4877
|
+
spaceToCreate.in_org = true;
|
|
4878
|
+
} else if (whereToCreateSpace === "partner") {
|
|
4879
|
+
spaceToCreate.assign_partner = true;
|
|
4880
|
+
}
|
|
4881
|
+
createdSpace = await createSpace(spaceToCreate);
|
|
4819
4882
|
spinnerSpace.succeed(`Space "${chalk.hex(colorPalette.PRIMARY)(toHumanReadable(projectName))}" created successfully`);
|
|
4820
4883
|
} catch (error) {
|
|
4821
4884
|
spinnerSpace.failed();
|
|
@@ -4844,9 +4907,15 @@ program$1.command(`${commands.CREATE} [project-path]`).alias("c").description(`S
|
|
|
4844
4907
|
}
|
|
4845
4908
|
}
|
|
4846
4909
|
konsola.br();
|
|
4847
|
-
konsola.ok(`Your ${chalk.hex(colorPalette.PRIMARY)(
|
|
4910
|
+
konsola.ok(`Your ${chalk.hex(colorPalette.PRIMARY)(technologyTemplate)} project is ready \u{1F389} !`);
|
|
4848
4911
|
if (createdSpace?.first_token) {
|
|
4849
|
-
|
|
4912
|
+
if (whereToCreateSpace === "org") {
|
|
4913
|
+
konsola.ok(`Storyblok space created in organization ${chalk.hex(colorPalette.PRIMARY)(userData.org.name)}, preview url and .env configured automatically. You can now open your space in the browser at ${chalk.hex(colorPalette.PRIMARY)(generateSpaceUrl(createdSpace.id, region))}`);
|
|
4914
|
+
} else if (whereToCreateSpace === "partner") {
|
|
4915
|
+
konsola.ok(`Storyblok space created in partner portal, preview url and .env configured automatically. You can now open your space in the browser at ${chalk.hex(colorPalette.PRIMARY)(generateSpaceUrl(createdSpace.id, region))}`);
|
|
4916
|
+
} else {
|
|
4917
|
+
konsola.ok(`Storyblok space created, preview url and .env configured automatically. You can now open your space in the browser at ${chalk.hex(colorPalette.PRIMARY)(generateSpaceUrl(createdSpace.id, region))}`);
|
|
4918
|
+
}
|
|
4850
4919
|
}
|
|
4851
4920
|
konsola.br();
|
|
4852
4921
|
konsola.info(`Next steps:
|
|
@@ -4863,7 +4932,7 @@ program$1.command(`${commands.CREATE} [project-path]`).alias("c").description(`S
|
|
|
4863
4932
|
konsola.br();
|
|
4864
4933
|
});
|
|
4865
4934
|
|
|
4866
|
-
const version = "4.
|
|
4935
|
+
const version = "4.4.0";
|
|
4867
4936
|
const pkg = {
|
|
4868
4937
|
version: version};
|
|
4869
4938
|
|