@embeddable.com/sdk-core 3.1.3 → 3.1.5

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
@@ -8,6 +8,7 @@ var fs$2 = require('node:fs');
8
8
  var node = require('@stencil/core/sys/node');
9
9
  var compiler = require('@stencil/core/compiler');
10
10
  var YAML = require('yaml');
11
+ var url$2 = require('node:url');
11
12
  var path$2 = require('path');
12
13
  var require$$4$1 = require('util');
13
14
  var require$$1 = require('os');
@@ -44,6 +45,7 @@ var path__namespace = /*#__PURE__*/_interopNamespaceDefault(path$1);
44
45
  var vite__namespace = /*#__PURE__*/_interopNamespaceDefault(vite);
45
46
  var fs__namespace$1 = /*#__PURE__*/_interopNamespaceDefault(fs$2);
46
47
  var YAML__namespace = /*#__PURE__*/_interopNamespaceDefault(YAML);
48
+ var url__namespace = /*#__PURE__*/_interopNamespaceDefault(url$2);
47
49
  var path__namespace$1 = /*#__PURE__*/_interopNamespaceDefault(path$2);
48
50
  var os__namespace = /*#__PURE__*/_interopNamespaceDefault(os$1);
49
51
  var archiver__namespace = /*#__PURE__*/_interopNamespaceDefault(archiver);
@@ -446,12 +448,14 @@ async function runStencil(ctx) {
446
448
  const logger = ((_a = ctx.dev) === null || _a === void 0 ? void 0 : _a.logger) || node.createNodeLogger({ process });
447
449
  const sys = ((_b = ctx.dev) === null || _b === void 0 ? void 0 : _b.sys) || node.createNodeSys({ process });
448
450
  const devMode = !!ctx.dev;
451
+ const isWindows = process.platform === "win32";
449
452
  const validated = await compiler.loadConfig({
450
453
  initTsConfig: true,
451
454
  logger,
452
455
  sys,
453
456
  config: {
454
457
  devMode,
458
+ maxConcurrentWorkers: isWindows ? 0 : 8, // workers break on windows
455
459
  rootDir: ctx.client.buildDir,
456
460
  configPath: path__namespace.resolve(ctx.client.buildDir, "stencil.config.ts"),
457
461
  tsconfig: path__namespace.resolve(ctx.client.buildDir, "tsconfig.json"),
@@ -4656,10 +4660,12 @@ var provideConfig = async () => {
4656
4660
  console.log("Please create a proper `embeddable.config.js` or `embeddable.config.ts` file in the root of your project.");
4657
4661
  process.exit(1);
4658
4662
  }
4663
+ const isWindows = process.platform === "win32";
4659
4664
  const configPath = fs__namespace$1.existsSync(tsConfigFilePath)
4660
4665
  ? tsConfigFilePath
4661
4666
  : configFilePath;
4662
- return (await import(configPath)).default;
4667
+ const pathOrUrl = isWindows ? url__namespace.pathToFileURL(configPath).href : configPath;
4668
+ return (await import(pathOrUrl)).default;
4663
4669
  };
4664
4670
 
4665
4671
  function getDefaultExportFromCjs (x) {
@@ -19998,6 +20004,25 @@ const checkNodeVersion = async () => {
19998
20004
  process.exit(1);
19999
20005
  }
20000
20006
  };
20007
+ /**
20008
+ * Get the value of a process argument by key
20009
+ * Example: getArgumentByKey("--email") or getArgumentByKey(["--email", "-e"])
20010
+ * @param key The key to search for in the process arguments
20011
+ * @returns
20012
+ */
20013
+ const getArgumentByKey = (key) => {
20014
+ if (Array.isArray(key)) {
20015
+ for (const k of key) {
20016
+ if (process.argv.includes(k)) {
20017
+ const index = process.argv.indexOf(k);
20018
+ return index !== -1 ? process.argv[index + 1] : undefined;
20019
+ }
20020
+ }
20021
+ return undefined;
20022
+ }
20023
+ const index = process.argv.indexOf(key);
20024
+ return index !== -1 ? process.argv[index + 1] : undefined;
20025
+ };
20001
20026
 
20002
20027
  var build = async () => {
20003
20028
  try {
@@ -20108,29 +20133,57 @@ const inquirerSelect = import('@inquirer/select');
20108
20133
  const YAML_OR_JS_FILES = /^(.*)\.(cube|sc)\.(ya?ml|js)$/;
20109
20134
  let ora$1;
20110
20135
  var push = async () => {
20111
- var _a;
20136
+ var _a, _b;
20112
20137
  let spinnerPushing;
20113
20138
  try {
20114
20139
  checkNodeVersion();
20115
20140
  ora$1 = (await oraP$1).default;
20116
20141
  const config = await provideConfig();
20117
20142
  const token = await verify(config);
20143
+ if (process.argv.includes("--api-key") || process.argv.includes("-k")) {
20144
+ spinnerPushing = ora$1("Using API key...").start();
20145
+ await pushByApiKey(config, spinnerPushing);
20146
+ spinnerPushing.succeed("Published using API key");
20147
+ return;
20148
+ }
20118
20149
  const { workspaceId, name: workspaceName } = await selectWorkspace(config, token);
20119
- const spinnerArchive = ora$1("Building...").start();
20120
- const filesList = await findFiles(config.client.srcDir, YAML_OR_JS_FILES);
20121
- await archive(config, filesList);
20122
- spinnerArchive.succeed("Bundling completed");
20150
+ await buildArchive(config);
20123
20151
  spinnerPushing = ora$1(`Publishing to ${workspaceName} using ${config.pushBaseUrl}...`).start();
20124
20152
  await sendBuild(config, { workspaceId, token });
20125
20153
  spinnerPushing.succeed(`Published to ${workspaceName} using ${config.pushBaseUrl}`);
20126
20154
  }
20127
20155
  catch (error) {
20128
20156
  spinnerPushing === null || spinnerPushing === void 0 ? void 0 : spinnerPushing.fail("Publishing failed");
20129
- console.error(((_a = error.response) === null || _a === void 0 ? void 0 : _a.data) || (error === null || error === void 0 ? void 0 : error.message) || error);
20157
+ if (((_a = error.response) === null || _a === void 0 ? void 0 : _a.statusText) === "Unauthorized") {
20158
+ console.error("Unauthorized. Please check your credentials.");
20159
+ }
20160
+ else {
20161
+ console.error(((_b = error.response) === null || _b === void 0 ? void 0 : _b.data) || (error === null || error === void 0 ? void 0 : error.message) || error);
20162
+ }
20130
20163
  await reportErrorToRollbar(error);
20131
20164
  process.exit(1);
20132
20165
  }
20133
20166
  };
20167
+ async function pushByApiKey(config, spinner) {
20168
+ const apiKey = getArgumentByKey(["--api-key", "-k"]);
20169
+ if (!apiKey) {
20170
+ spinner.fail("No API key provided");
20171
+ process.exit(1);
20172
+ }
20173
+ const email = getArgumentByKey(["--email", "-e"]);
20174
+ if (!email || !/\S+@\S+\.\S+/.test(email)) {
20175
+ spinner.fail("Invalid email provided. Please provide a valid email using --email (-e) flag");
20176
+ process.exit(1);
20177
+ }
20178
+ // message is optional
20179
+ const message = getArgumentByKey(["--message", "-m"]);
20180
+ await buildArchive(config);
20181
+ return sendBuildByApiKey(config, {
20182
+ apiKey,
20183
+ email,
20184
+ message,
20185
+ });
20186
+ }
20134
20187
  async function selectWorkspace(ctx, token) {
20135
20188
  const workspaceSpinner = ora$1({
20136
20189
  text: `Fetching workspaces using ${ctx.pushBaseUrl}...`,
@@ -20176,6 +20229,12 @@ async function verify(ctx) {
20176
20229
  }
20177
20230
  return token;
20178
20231
  }
20232
+ async function buildArchive(config) {
20233
+ const spinnerArchive = ora$1("Building...").start();
20234
+ const filesList = await findFiles(config.client.srcDir, YAML_OR_JS_FILES);
20235
+ await archive(config, filesList);
20236
+ return spinnerArchive.succeed("Bundling completed");
20237
+ }
20179
20238
  async function archive(ctx, yamlFiles, includeBuild = true) {
20180
20239
  const output = fs__namespace$1.createWriteStream(ctx.client.archiveFile);
20181
20240
  const _archiver = archiver__namespace.create("zip", {
@@ -20196,13 +20255,30 @@ async function archive(ctx, yamlFiles, includeBuild = true) {
20196
20255
  output.on("close", resolve);
20197
20256
  });
20198
20257
  }
20258
+ async function sendBuildByApiKey(ctx, { apiKey, email, message }) {
20259
+ var _a;
20260
+ const { FormData, Blob } = await import('formdata-node');
20261
+ const { fileFromPath } = await Promise.resolve().then(function () { return fileFromPath$1; });
20262
+ const file = await fileFromPath(ctx.client.archiveFile, "embeddable-build.zip");
20263
+ const form = new FormData();
20264
+ form.set("file", file, "embeddable-build.zip");
20265
+ const metadataBlob = new Blob([JSON.stringify({ authorEmail: email, description: message })], { type: "application/json" });
20266
+ form.set("metadata", metadataBlob, "metadata.json");
20267
+ const response = await uploadFile(form, `${ctx.pushBaseUrl}/api/v1/bundle/upload`, apiKey);
20268
+ await fs__namespace.rm(ctx.client.archiveFile);
20269
+ return { bundleId: (_a = response.data) === null || _a === void 0 ? void 0 : _a.bundleId, email, message };
20270
+ }
20199
20271
  async function sendBuild(ctx, { workspaceId, token }) {
20200
20272
  const { FormData } = await import('formdata-node');
20201
20273
  const { fileFromPath } = await Promise.resolve().then(function () { return fileFromPath$1; });
20202
20274
  const file = await fileFromPath(ctx.client.archiveFile, "embeddable-build.zip");
20203
20275
  const form = new FormData();
20204
20276
  form.set("file", file, "embeddable-build.zip");
20205
- await axios.post(`${ctx.pushBaseUrl}/bundle/${workspaceId}/upload`, form, {
20277
+ await uploadFile(form, `${ctx.pushBaseUrl}/bundle/${workspaceId}/upload`, token);
20278
+ await fs__namespace.rm(ctx.client.archiveFile);
20279
+ }
20280
+ async function uploadFile(formData, url, token) {
20281
+ return axios.post(url, formData, {
20206
20282
  headers: {
20207
20283
  "Content-Type": "multipart/form-data",
20208
20284
  Authorization: `Bearer ${token}`,
@@ -20210,7 +20286,6 @@ async function sendBuild(ctx, { workspaceId, token }) {
20210
20286
  maxContentLength: Infinity,
20211
20287
  maxBodyLength: Infinity,
20212
20288
  });
20213
- await fs__namespace.rm(ctx.client.archiveFile);
20214
20289
  }
20215
20290
  async function getWorkspaces(ctx, token, workspaceSpinner) {
20216
20291
  var _a;