@embeddable.com/sdk-core 3.7.1 → 3.7.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/lib/index.js CHANGED
@@ -566,10 +566,9 @@ const CREDENTIALS_DIR = path__namespace.resolve(os__namespace.homedir(), ".embed
566
566
  const CREDENTIALS_FILE = path__namespace.resolve(CREDENTIALS_DIR, "credentials");
567
567
 
568
568
  const oraP$3 = import('ora');
569
- let ora$2;
570
569
  const checkNodeVersion = async () => {
571
- ora$2 = (await oraP$3).default;
572
- const spinner = ora$2("Checking node version...");
570
+ const ora = (await oraP$3).default;
571
+ const spinner = ora("Checking node version...").start();
573
572
  const [major, minor] = process.versions.node.split(".").map(Number);
574
573
  const packageJson = await Promise.resolve().then(function () { return _package$1; });
575
574
  const { engines: { node }, } = packageJson;
@@ -578,10 +577,7 @@ const checkNodeVersion = async () => {
578
577
  .map((v) => v.replace(/[^\d]/g, ""))
579
578
  .map(Number);
580
579
  if (major < minMajor || (major === minMajor && minor < minMinor)) {
581
- spinner.fail({
582
- text: `Node version ${minMajor}.${minMinor} or higher is required. You are running ${major}.${minor}.`,
583
- color: "red",
584
- });
580
+ spinner.fail(`Node version ${minMajor}.${minMinor} or higher is required. You are running ${major}.${minor}.`);
585
581
  process.exit(1);
586
582
  }
587
583
  else {
@@ -20564,8 +20560,58 @@ async function resolveFiles() {
20564
20560
  }
20565
20561
  }
20566
20562
 
20567
- const oraP$1 = import('ora');
20568
20563
  const inquirerSelect = import('@inquirer/select');
20564
+ async function getWorkspaces(ctx, token, workspaceSpinner) {
20565
+ var _a;
20566
+ try {
20567
+ const response = await axios.get(`${ctx.pushBaseUrl}/workspace`, {
20568
+ headers: {
20569
+ Authorization: `Bearer ${token}`,
20570
+ },
20571
+ });
20572
+ return (_a = response.data) === null || _a === void 0 ? void 0 : _a.filter((w) => !w.devWorkspace);
20573
+ }
20574
+ catch (e) {
20575
+ if (e.response.status === 401) {
20576
+ workspaceSpinner.fail('Unauthorized. Please login using "embeddable login" command.');
20577
+ }
20578
+ else {
20579
+ workspaceSpinner.fail("Failed to fetch workspaces");
20580
+ }
20581
+ process.exit(1);
20582
+ }
20583
+ }
20584
+ async function selectWorkspace(ora, ctx, token) {
20585
+ const workspaceSpinner = ora({
20586
+ text: `Fetching workspaces using ${ctx.pushBaseUrl}...`,
20587
+ color: "green",
20588
+ discardStdin: false,
20589
+ }).start();
20590
+ const availableWorkspaces = await getWorkspaces(ctx, token, workspaceSpinner);
20591
+ let selectedWorkspace;
20592
+ if (availableWorkspaces.length === 0) {
20593
+ workspaceSpinner.fail("No workspaces found");
20594
+ process.exit(1);
20595
+ }
20596
+ workspaceSpinner.info(`Found ${availableWorkspaces.length} workspace(s)`);
20597
+ if (availableWorkspaces.length === 1) {
20598
+ selectedWorkspace = availableWorkspaces[0];
20599
+ }
20600
+ else {
20601
+ const select = (await inquirerSelect).default;
20602
+ selectedWorkspace = await select({
20603
+ message: "Select workspace to push changes",
20604
+ choices: availableWorkspaces.map((workspace) => ({
20605
+ name: `${workspace.name} (${workspace.workspaceId})`,
20606
+ value: workspace,
20607
+ })),
20608
+ });
20609
+ }
20610
+ workspaceSpinner.succeed(`Workspace: ${selectedWorkspace.name} (${selectedWorkspace.workspaceId})`);
20611
+ return selectedWorkspace;
20612
+ }
20613
+
20614
+ const oraP$1 = import('ora');
20569
20615
  // grab .cube.yml|js and .sc.yml|js files
20570
20616
  const YAML_OR_JS_FILES = /^(.*)\.(cube|sc)\.(ya?ml|js)$/;
20571
20617
  // grab all files in self-serve-customization folder
@@ -20594,7 +20640,7 @@ var push = async () => {
20594
20640
  spinnerPushing = ora$1()
20595
20641
  .start()
20596
20642
  .info("No API Key provided. Standard login will be used.");
20597
- const { workspaceId, name: workspaceName } = await selectWorkspace(config, token);
20643
+ const { workspaceId, name: workspaceName } = await selectWorkspace(ora$1, config, token);
20598
20644
  const workspacePreviewUrl = `${config.previewBaseUrl}/workspace/${workspaceId}`;
20599
20645
  await buildArchive(config);
20600
20646
  spinnerPushing.info(`Publishing to ${workspaceName} using ${workspacePreviewUrl}...`);
@@ -20633,35 +20679,6 @@ async function pushByApiKey(config, spinner) {
20633
20679
  message,
20634
20680
  });
20635
20681
  }
20636
- async function selectWorkspace(ctx, token) {
20637
- const workspaceSpinner = ora$1({
20638
- text: `Fetching workspaces using ${ctx.pushBaseUrl}...`,
20639
- color: "green",
20640
- discardStdin: false,
20641
- }).start();
20642
- const availableWorkspaces = await getWorkspaces(ctx, token, workspaceSpinner);
20643
- let selectedWorkspace;
20644
- if (availableWorkspaces.length === 0) {
20645
- workspaceSpinner.fail("No workspaces found");
20646
- process.exit(1);
20647
- }
20648
- workspaceSpinner.info(`Found ${availableWorkspaces.length} workspace(s)`);
20649
- if (availableWorkspaces.length === 1) {
20650
- selectedWorkspace = availableWorkspaces[0];
20651
- }
20652
- else {
20653
- const select = (await inquirerSelect).default;
20654
- selectedWorkspace = await select({
20655
- message: "Select workspace to push changes",
20656
- choices: availableWorkspaces.map((workspace) => ({
20657
- name: `${workspace.name} (${workspace.workspaceId})`,
20658
- value: workspace,
20659
- })),
20660
- });
20661
- }
20662
- workspaceSpinner.succeed(`Workspace: ${selectedWorkspace.name} (${selectedWorkspace.workspaceId})`);
20663
- return selectedWorkspace;
20664
- }
20665
20682
  async function verify(ctx) {
20666
20683
  try {
20667
20684
  await fs__namespace.access(ctx.client.buildDir);
@@ -20681,7 +20698,13 @@ async function verify(ctx) {
20681
20698
  async function buildArchive(config) {
20682
20699
  const spinnerArchive = ora$1("Building...").start();
20683
20700
  const filesList = await findFiles(config.client.modelsSrc || config.client.srcDir, YAML_OR_JS_FILES);
20684
- const selfServeFiles = await findFiles(`${config.client.selfServeCustomizationDir}`, SELF_SERVE_CUSTOM_FILES);
20701
+ let selfServeFiles = [];
20702
+ // check existance of self-serve-customization folder
20703
+ try {
20704
+ await fs__namespace.access(config.client.selfServeCustomizationDir);
20705
+ selfServeFiles = await findFiles(`${config.client.selfServeCustomizationDir}`, SELF_SERVE_CUSTOM_FILES);
20706
+ }
20707
+ catch (e) { }
20685
20708
  await archive(config, filesList, selfServeFiles);
20686
20709
  return spinnerArchive.succeed("Bundling completed");
20687
20710
  }
@@ -20745,26 +20768,6 @@ async function uploadFile(formData, url, token) {
20745
20768
  maxBodyLength: Infinity,
20746
20769
  });
20747
20770
  }
20748
- async function getWorkspaces(ctx, token, workspaceSpinner) {
20749
- var _a;
20750
- try {
20751
- const response = await axios.get(`${ctx.pushBaseUrl}/workspace`, {
20752
- headers: {
20753
- Authorization: `Bearer ${token}`,
20754
- },
20755
- });
20756
- return (_a = response.data) === null || _a === void 0 ? void 0 : _a.filter((w) => !w.devWorkspace);
20757
- }
20758
- catch (e) {
20759
- if (e.response.status === 401) {
20760
- workspaceSpinner.fail('Unauthorized. Please login using "embeddable login" command.');
20761
- }
20762
- else {
20763
- workspaceSpinner.fail("Failed to fetch workspaces");
20764
- }
20765
- process.exit(1);
20766
- }
20767
- }
20768
20771
 
20769
20772
  const minimist = require("minimist");
20770
20773
  const oraP = import('ora');
@@ -20825,7 +20828,7 @@ var dev = async () => {
20825
20828
  const serveSelfeServe = serveStatic(config.client.selfServeCustomizationDir);
20826
20829
  const workspacePreparation = ora("Preparing workspace...").start();
20827
20830
  try {
20828
- previewWorkspace = await getPreviewWorkspace(config);
20831
+ previewWorkspace = await getPreviewWorkspace(workspacePreparation, config);
20829
20832
  }
20830
20833
  catch (e) {
20831
20834
  workspacePreparation.fail((_a = e.response.data) === null || _a === void 0 ? void 0 : _a.errorMessage);
@@ -20988,10 +20991,16 @@ const onClose = async (server, sys, watchers, config) => {
20988
20991
  await sys.destroy();
20989
20992
  process.exit(0);
20990
20993
  };
20991
- const getPreviewWorkspace = async (ctx) => {
20994
+ const getPreviewWorkspace = async (startedOra, ctx) => {
20992
20995
  const token = await getToken();
20993
20996
  const params = minimist(process.argv.slice(2));
20994
- const primaryWorkspace = params.w || params.workspace;
20997
+ let primaryWorkspace = params.w || params.workspace;
20998
+ if (!primaryWorkspace) {
20999
+ startedOra.stop(); // Stop current Ora, otherwise the last option will get hidden by it.
21000
+ const { workspaceId } = await selectWorkspace(ora, ctx, token);
21001
+ primaryWorkspace = workspaceId;
21002
+ startedOra.start();
21003
+ }
20995
21004
  try {
20996
21005
  const response = await axios.get(`${ctx.pushBaseUrl}/workspace/dev-workspace`, {
20997
21006
  params: { primaryWorkspace },
@@ -21005,7 +21014,7 @@ const getPreviewWorkspace = async (ctx) => {
21005
21014
  if (e.response.status === 401) {
21006
21015
  // login and retry
21007
21016
  await login();
21008
- return await getPreviewWorkspace(ctx);
21017
+ return await getPreviewWorkspace(startedOra, ctx);
21009
21018
  }
21010
21019
  else {
21011
21020
  throw e;
@@ -21066,7 +21075,7 @@ var defineConfig = ({ plugins, pushBaseUrl, audienceUrl, authDomain, authClientI
21066
21075
  };
21067
21076
 
21068
21077
  var name = "@embeddable.com/sdk-core";
21069
- var version = "3.7.1";
21078
+ var version = "3.7.3";
21070
21079
  var description = "Core Embeddable SDK module responsible for web-components bundling and publishing.";
21071
21080
  var keywords = [
21072
21081
  "embeddable",