@embeddable.com/sdk-core 4.0.3 → 4.1.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/lib/index.js CHANGED
@@ -8,7 +8,9 @@ var crypto = require('node:crypto');
8
8
  var fs$1 = require('node:fs');
9
9
  var node = require('@stencil/core/sys/node');
10
10
  var compiler = require('@stencil/core/compiler');
11
+ var sorcery = require('sorcery');
11
12
  var os = require('node:os');
13
+ var ora = require('ora');
12
14
  var YAML = require('yaml');
13
15
  var url = require('node:url');
14
16
  var require$$4$1 = require('util');
@@ -24,6 +26,7 @@ var prompts = require('@inquirer/prompts');
24
26
  var http = require('node:http');
25
27
  var ws = require('ws');
26
28
  var chokidar = require('chokidar');
29
+ var minimist = require('minimist');
27
30
  var fg = require('fast-glob');
28
31
  var dotenv = require('dotenv');
29
32
  var promises = require('fs/promises');
@@ -50,6 +53,7 @@ var path__namespace = /*#__PURE__*/_interopNamespaceDefault(path);
50
53
  var vite__namespace = /*#__PURE__*/_interopNamespaceDefault(vite);
51
54
  var crypto__namespace = /*#__PURE__*/_interopNamespaceDefault(crypto);
52
55
  var fs__namespace$1 = /*#__PURE__*/_interopNamespaceDefault(fs$1);
56
+ var sorcery__namespace = /*#__PURE__*/_interopNamespaceDefault(sorcery);
53
57
  var os__namespace = /*#__PURE__*/_interopNamespaceDefault(os);
54
58
  var YAML__namespace = /*#__PURE__*/_interopNamespaceDefault(YAML);
55
59
  var url__namespace = /*#__PURE__*/_interopNamespaceDefault(url);
@@ -396,11 +400,11 @@ const getContentHash = (contentString) => {
396
400
  .substring(0, 5);
397
401
  };
398
402
 
399
- const oraP$4 = import('ora');
403
+ const oraP$1 = import('ora');
400
404
  const EMB_TYPE_FILE_REGEX = /^(.*)\.type\.emb\.[jt]s$/;
401
405
  const EMB_OPTIONS_FILE_REGEX = /^(.*)\.options\.emb\.[jt]s$/;
402
406
  var buildTypes = async (ctx) => {
403
- const ora = (await oraP$4).default;
407
+ const ora = (await oraP$1).default;
404
408
  const progress = ora("Building types...").start();
405
409
  await generate$1(ctx);
406
410
  await build$1(ctx);
@@ -462,7 +466,6 @@ async function createComponentDir(dir) {
462
466
  await fs__namespace.mkdir(dir);
463
467
  }
464
468
 
465
- const sorcery = require("sorcery");
466
469
  const STYLE_IMPORTS_TOKEN = "{{STYLES_IMPORT}}";
467
470
  const RENDER_IMPORT_TOKEN = "{{RENDER_IMPORT}}";
468
471
  // stencil doesn't support dynamic component tag name, so we need to replace it manually
@@ -576,7 +579,7 @@ async function generateSourceMap(ctx, pluginName) {
576
579
  const jsFiles = stencilFiles.filter((file) => file.toLowerCase().endsWith(".js"));
577
580
  await Promise.all(jsFiles.map(async (jsFile) => {
578
581
  try {
579
- const chain = await sorcery.load(path__namespace.resolve(stencilBuild, jsFile));
582
+ const chain = await sorcery__namespace.load(path__namespace.resolve(stencilBuild, jsFile));
580
583
  // overwrite the existing file
581
584
  await chain.write();
582
585
  }
@@ -590,12 +593,16 @@ async function generateSourceMap(ctx, pluginName) {
590
593
  const CREDENTIALS_DIR = path__namespace.resolve(os__namespace.homedir(), ".embeddable");
591
594
  const CREDENTIALS_FILE = path__namespace.resolve(CREDENTIALS_DIR, "credentials");
592
595
 
593
- const oraP$3 = import('ora');
594
596
  const checkNodeVersion = async () => {
595
- const ora = (await oraP$3).default;
596
597
  const spinner = ora("Checking node version...").start();
597
598
  const [major, minor] = process.versions.node.split(".").map(Number);
598
- const packageJson = await Promise.resolve().then(function () { return _package$1; });
599
+ let packageJson;
600
+ try {
601
+ packageJson = JSON.parse(fs$1.readFileSync(path.join(undefined, "../package.json"), "utf-8"));
602
+ }
603
+ catch (e) {
604
+ throw new Error("Failed to read package.json of core-sdk");
605
+ }
599
606
  const { engines: { node }, } = packageJson;
600
607
  const [minMajor, minMinor] = node
601
608
  .split(".")
@@ -5206,6 +5213,7 @@ var provideConfig = async () => {
5206
5213
  ? tsConfigFilePath
5207
5214
  : configFilePath;
5208
5215
  const pathOrUrl = isWindows ? url__namespace.pathToFileURL(configPath).href : configPath;
5216
+ console.log(pathOrUrl);
5209
5217
  return (await import(pathOrUrl)).default;
5210
5218
  };
5211
5219
 
@@ -5238,25 +5246,25 @@ function getAugmentedNamespace(n) {
5238
5246
  return a;
5239
5247
  }
5240
5248
 
5241
- var name$1 = "rollbar";
5242
- var version$1 = "2.26.4";
5243
- var repository$1 = {
5249
+ var name = "rollbar";
5250
+ var version = "2.26.4";
5251
+ var repository = {
5244
5252
  type: "git",
5245
5253
  url: "http://github.com/rollbar/rollbar.js"
5246
5254
  };
5247
- var description$1 = "Effortlessly track and debug errors in your JavaScript applications with Rollbar. This package includes advanced error tracking features and an intuitive interface to help you identify and fix issues more quickly.";
5248
- var keywords$1 = [
5255
+ var description = "Effortlessly track and debug errors in your JavaScript applications with Rollbar. This package includes advanced error tracking features and an intuitive interface to help you identify and fix issues more quickly.";
5256
+ var keywords = [
5249
5257
  "error",
5250
5258
  "tracking",
5251
5259
  "logging",
5252
5260
  "debugging",
5253
5261
  "javascript"
5254
5262
  ];
5255
- var license$1 = "MIT";
5256
- var main$1 = "src/server/rollbar.js";
5263
+ var license = "MIT";
5264
+ var main = "src/server/rollbar.js";
5257
5265
  var browser = "dist/rollbar.umd.min.js";
5258
- var types$1 = "./index.d.ts";
5259
- var dependencies$1 = {
5266
+ var types = "./index.d.ts";
5267
+ var dependencies = {
5260
5268
  async: "~3.2.3",
5261
5269
  "console-polyfill": "0.3.0",
5262
5270
  "error-stack-parser": "^2.0.4",
@@ -5265,7 +5273,7 @@ var dependencies$1 = {
5265
5273
  "request-ip": "~3.3.0",
5266
5274
  "source-map": "^0.5.7"
5267
5275
  };
5268
- var devDependencies$1 = {
5276
+ var devDependencies = {
5269
5277
  "@babel/core": "^7.22.11",
5270
5278
  "babel-eslint": "^10.0.3",
5271
5279
  "babel-loader": "^8.0.4",
@@ -5325,7 +5333,7 @@ var devDependencies$1 = {
5325
5333
  var optionalDependencies = {
5326
5334
  decache: "^3.0.5"
5327
5335
  };
5328
- var scripts$1 = {
5336
+ var scripts = {
5329
5337
  build: "./node_modules/.bin/grunt",
5330
5338
  test: "./node_modules/.bin/grunt test",
5331
5339
  "test-browser": "./node_modules/.bin/grunt test-browser",
@@ -5399,19 +5407,19 @@ var plugins = {
5399
5407
  }
5400
5408
  };
5401
5409
  var require$$2 = {
5402
- name: name$1,
5403
- version: version$1,
5404
- repository: repository$1,
5405
- description: description$1,
5406
- keywords: keywords$1,
5407
- license: license$1,
5408
- main: main$1,
5410
+ name: name,
5411
+ version: version,
5412
+ repository: repository,
5413
+ description: description,
5414
+ keywords: keywords,
5415
+ license: license,
5416
+ main: main,
5409
5417
  browser: browser,
5410
- types: types$1,
5411
- dependencies: dependencies$1,
5412
- devDependencies: devDependencies$1,
5418
+ types: types,
5419
+ dependencies: dependencies,
5420
+ devDependencies: devDependencies,
5413
5421
  optionalDependencies: optionalDependencies,
5414
- scripts: scripts$1,
5422
+ scripts: scripts,
5415
5423
  cdn: cdn,
5416
5424
  defaults: defaults,
5417
5425
  plugins: plugins
@@ -21401,13 +21409,13 @@ var build = async () => {
21401
21409
  }
21402
21410
  };
21403
21411
 
21404
- const oraP$2 = import('ora');
21412
+ const oraP = import('ora');
21405
21413
  const openP = import('open');
21406
21414
  var login = async () => {
21407
21415
  var _a;
21408
21416
  await initLogger("login");
21409
21417
  const breadcrumbs = [];
21410
- const ora = (await oraP$2).default;
21418
+ const ora = (await oraP).default;
21411
21419
  const authenticationSpinner = ora("Waiting for code verification...").start();
21412
21420
  try {
21413
21421
  const open = (await openP).default;
@@ -21497,7 +21505,7 @@ async function resolveFiles() {
21497
21505
  }
21498
21506
 
21499
21507
  async function getWorkspaces(ctx, token, workspaceSpinner) {
21500
- var _a, _b;
21508
+ var _a, _b, _c;
21501
21509
  try {
21502
21510
  const response = await axios.get(`${ctx.pushBaseUrl}/workspace`, {
21503
21511
  headers: {
@@ -21507,7 +21515,11 @@ async function getWorkspaces(ctx, token, workspaceSpinner) {
21507
21515
  return (_a = response.data) === null || _a === void 0 ? void 0 : _a.filter((w) => !w.devWorkspace);
21508
21516
  }
21509
21517
  catch (e) {
21510
- if (((_b = e.response) === null || _b === void 0 ? void 0 : _b.status) === 401) {
21518
+ if ((_b = ctx.dev) === null || _b === void 0 ? void 0 : _b.watch) {
21519
+ workspaceSpinner.stop();
21520
+ throw e;
21521
+ }
21522
+ if (((_c = e.response) === null || _c === void 0 ? void 0 : _c.status) === 401) {
21511
21523
  workspaceSpinner.fail('Unauthorized. Please login using "embeddable login" command.');
21512
21524
  }
21513
21525
  else {
@@ -21545,12 +21557,10 @@ async function selectWorkspace(ora, ctx, token) {
21545
21557
  return selectedWorkspace;
21546
21558
  }
21547
21559
 
21548
- const oraP$1 = import('ora');
21549
21560
  // grab cube files
21550
21561
  const CUBE_FILES = /^(.*)\.cube\.(ya?ml|js)$/;
21551
21562
  // grab security context and client context files
21552
21563
  const PRESET_FILES = /^(.*)\.(sc|cc)\.ya?ml$/;
21553
- let ora$1;
21554
21564
  var push = async () => {
21555
21565
  var _a;
21556
21566
  await initLogger("push");
@@ -21564,10 +21574,9 @@ var push = async () => {
21564
21574
  console.error("Build failed or not completed. Please run `embeddable:build` first.");
21565
21575
  process.exit(1);
21566
21576
  }
21567
- ora$1 = (await oraP$1).default;
21568
21577
  const config = await provideConfig();
21569
21578
  if (process.argv.includes("--api-key") || process.argv.includes("-k")) {
21570
- spinnerPushing = ora$1("Using API key...").start();
21579
+ spinnerPushing = ora("Using API key...").start();
21571
21580
  breadcrumbs.push("push by api key");
21572
21581
  await pushByApiKey(config, spinnerPushing);
21573
21582
  spinnerPushing.succeed("Published using API key");
@@ -21575,11 +21584,11 @@ var push = async () => {
21575
21584
  }
21576
21585
  breadcrumbs.push("push by standard login");
21577
21586
  const token = await verify(config);
21578
- spinnerPushing = ora$1()
21587
+ spinnerPushing = ora()
21579
21588
  .start()
21580
21589
  .info("No API Key provided. Standard login will be used.");
21581
21590
  breadcrumbs.push("select workspace");
21582
- const { workspaceId, name: workspaceName } = await selectWorkspace(ora$1, config, token);
21591
+ const { workspaceId, name: workspaceName } = await selectWorkspace(ora, config, token);
21583
21592
  const workspacePreviewUrl = `${config.previewBaseUrl}/workspace/${workspaceId}`;
21584
21593
  breadcrumbs.push("build archive");
21585
21594
  await buildArchive(config);
@@ -21633,7 +21642,7 @@ async function verify(ctx) {
21633
21642
  return token;
21634
21643
  }
21635
21644
  async function buildArchive(config) {
21636
- const spinnerArchive = ora$1("Building...").start();
21645
+ const spinnerArchive = ora("Building...").start();
21637
21646
  const cubeFilesList = await findFiles(config.client.modelsSrc || config.client.srcDir, CUBE_FILES);
21638
21647
  const contextFilesList = await findFiles(config.client.presetsSrc || config.client.srcDir, PRESET_FILES);
21639
21648
  // Map the files to include their full filenames
@@ -21696,13 +21705,10 @@ async function uploadFile(formData, url, token) {
21696
21705
  });
21697
21706
  }
21698
21707
 
21699
- const minimist = require("minimist");
21700
21708
  dotenv__namespace.config();
21701
- const oraP = import('ora');
21702
21709
  let wss;
21703
21710
  let changedFiles = [];
21704
21711
  let browserWindow = null;
21705
- let ora;
21706
21712
  let previewWorkspace;
21707
21713
  const SERVER_PORT = 8926;
21708
21714
  const BUILD_DEV_DIR = ".embeddable-dev-build";
@@ -21732,14 +21738,13 @@ const chokidarWatchOptions = {
21732
21738
  },
21733
21739
  };
21734
21740
  var dev = async () => {
21735
- var _a, _b;
21741
+ var _a, _b, _c;
21736
21742
  await initLogger("dev");
21737
21743
  const breadcrumbs = [];
21738
21744
  try {
21739
21745
  breadcrumbs.push("run dev");
21740
21746
  checkNodeVersion();
21741
21747
  addToGitingore();
21742
- ora = (await oraP).default;
21743
21748
  process.on("warning", (e) => console.warn(e.stack));
21744
21749
  const logger = node.createNodeLogger();
21745
21750
  const sys = node.createNodeSys({ process });
@@ -21765,14 +21770,22 @@ var dev = async () => {
21765
21770
  const finalhandler = require("finalhandler");
21766
21771
  const serveStatic = require("serve-static");
21767
21772
  const serve = serveStatic(config.client.buildDir);
21768
- const workspacePreparation = ora("Preparing workspace...").start();
21773
+ let workspacePreparation = ora("Preparing workspace...").start();
21769
21774
  breadcrumbs.push("get preview workspace");
21770
21775
  try {
21771
21776
  previewWorkspace = await getPreviewWorkspace(workspacePreparation, config);
21772
21777
  }
21773
21778
  catch (e) {
21774
- workspacePreparation.fail(((_b = (_a = e.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.errorMessage) || "Unknown error: " + e.message);
21775
- process.exit(1);
21779
+ if (((_a = e.response) === null || _a === void 0 ? void 0 : _a.status) === 401) {
21780
+ // login and retry
21781
+ await login();
21782
+ workspacePreparation = ora("Preparing workspace...").start();
21783
+ previewWorkspace = await getPreviewWorkspace(workspacePreparation, config);
21784
+ }
21785
+ else {
21786
+ workspacePreparation.fail(((_c = (_b = e.response) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.errorMessage) || "Unknown error: " + e.message);
21787
+ process.exit(1);
21788
+ }
21776
21789
  }
21777
21790
  workspacePreparation.succeed("Workspace is ready");
21778
21791
  const server = http__namespace.createServer((request, res) => {
@@ -22007,52 +22020,12 @@ const REGION_CONFIGS = {
22007
22020
  authClientId: "dygrSUmI6HmgY5ymVbEAoLDEBxIOyr1V",
22008
22021
  },
22009
22022
  };
22010
- const embeddableConfigSchema = z
22011
- .object({
22012
- plugins: z.array(z.function()),
22013
- region: z
22014
- .union([z.literal("EU"), z.literal("US"), z.literal("legacy-US")])
22015
- .optional(),
22016
- pushBaseUrl: z.string().optional(),
22017
- audienceUrl: z.string().optional(),
22018
- authDomain: z.string().optional(),
22019
- authClientId: z.string().optional(),
22020
- errorFallbackComponent: z.string().optional(),
22021
- applicationEnvironment: z.string().optional(),
22022
- rollbarAccessToken: z.string().optional(),
22023
- previewBaseUrl: z.string().optional(),
22024
- modelsSrc: z.string().optional(),
22025
- presetsSrc: z.string().optional(),
22026
- componentsSrc: z.string().optional(),
22027
- globalCss: z.string().optional(),
22028
- viteConfig: z
22029
- .object({
22030
- resolve: z
22031
- .object({
22032
- alias: z.record(z.string()),
22033
- })
22034
- .optional(),
22035
- })
22036
- .optional(),
22037
- rollupOptions: z.object({}).optional(),
22038
- })
22039
- .strict();
22040
- var defineConfig = (config) => {
22041
- const safeParse = embeddableConfigSchema.safeParse(config);
22042
- const errors = [];
22043
- if (!safeParse.success) {
22044
- errorFormatter(safeParse.error.issues).forEach((error) => {
22045
- errors.push(`${error}`);
22046
- });
22047
- }
22048
- if (errors.length > 0) {
22049
- throw new Error(`Invalid Embeddable Configuration: ${errors.join("\n")}}`);
22050
- }
22051
- let { plugins, region = "legacy-US", pushBaseUrl, audienceUrl, authDomain, authClientId, errorFallbackComponent, applicationEnvironment, rollbarAccessToken, previewBaseUrl, modelsSrc = "src", presetsSrc = "src", componentsSrc = "src", globalCss = "src/global.css", viteConfig = {}, rollupOptions = {}, } = config;
22023
+ var defineConfig = ({ plugins, region = "legacy-US", pushBaseUrl, audienceUrl, authDomain, authClientId, errorFallbackComponent, applicationEnvironment, rollbarAccessToken, previewBaseUrl, modelsSrc = "src", presetsSrc = "src", componentsSrc = "src", globalCss = "src/global.css", viteConfig = {}, rollupOptions = {}, }) => {
22052
22024
  if (region && !REGION_CONFIGS[region]) {
22053
22025
  throw new Error(`Unsupported region: ${region}. Supported regions are: ${Object.keys(REGION_CONFIGS).join(", ")}`);
22054
22026
  }
22055
22027
  const regionConfig = REGION_CONFIGS[region];
22028
+ const __dirname = undefined;
22056
22029
  const coreRoot = path__namespace.resolve(__dirname, "..");
22057
22030
  const clientRoot = process.cwd();
22058
22031
  if (!path__namespace.isAbsolute(componentsSrc)) {
@@ -22111,114 +22084,6 @@ var defineConfig = (config) => {
22111
22084
  };
22112
22085
  };
22113
22086
 
22114
- var name = "@embeddable.com/sdk-core";
22115
- var version = "3.12.4-next.1";
22116
- var description = "Core Embeddable SDK module responsible for web-components bundling and publishing.";
22117
- var keywords = [
22118
- "embeddable",
22119
- "sdk",
22120
- "web-components"
22121
- ];
22122
- var main = "lib/index.js";
22123
- var module$1 = "lib/index.esm.js";
22124
- var types = "lib/index.d.ts";
22125
- var repository = {
22126
- type: "git",
22127
- url: "git+https://github.com/embeddable-hq/embeddable-sdk.git",
22128
- directory: "packages/core-sdk"
22129
- };
22130
- var scripts = {
22131
- build: "rollup -c",
22132
- test: "vitest run",
22133
- "test:watch": "vitest",
22134
- "license-report": "license-report --output=csv --csvHeaders --fields name --fields link --fields licenseType --fields installedVersion --fields author > license-report-sdk-core-sdk.csv"
22135
- };
22136
- var author = "Embeddable.com <engineering@embeddable.com>";
22137
- var files = [
22138
- "bin/",
22139
- "src/",
22140
- "lib/",
22141
- "loader/",
22142
- "templates/",
22143
- "configs/"
22144
- ];
22145
- var bin = {
22146
- embeddable: "bin/embeddable"
22147
- };
22148
- var engines = {
22149
- node: ">=20.0.0"
22150
- };
22151
- var license = "MIT";
22152
- var dependencies = {
22153
- "@embeddable.com/sdk-utils": "0.6.2-next.0",
22154
- "@inquirer/prompts": "^7.2.1",
22155
- "@stencil/core": "^4.23.0",
22156
- "@swc-node/register": "^1.10.9",
22157
- archiver: "^5.3.2",
22158
- axios: "^1.7.9",
22159
- chokidar: "^4.0.3",
22160
- dotenv: "^16.4.7",
22161
- "fast-glob": "^3.3.2",
22162
- finalhandler: "^1.3.1",
22163
- "formdata-node": "^6.0.3",
22164
- minimist: "^1.2.8",
22165
- open: "^9.1.0",
22166
- ora: "^8.1.1",
22167
- "serve-static": "^1.16.2",
22168
- sorcery: "^0.11.1",
22169
- vite: "^5.4.11",
22170
- ws: "^8.18.0",
22171
- yaml: "^2.6.1"
22172
- };
22173
- var devDependencies = {
22174
- "@types/archiver": "^5.3.4",
22175
- "@types/ws": "^8.5.13"
22176
- };
22177
- var _package = {
22178
- name: name,
22179
- version: version,
22180
- description: description,
22181
- keywords: keywords,
22182
- main: main,
22183
- module: module$1,
22184
- types: types,
22185
- repository: repository,
22186
- scripts: scripts,
22187
- author: author,
22188
- files: files,
22189
- bin: bin,
22190
- engines: engines,
22191
- license: license,
22192
- dependencies: dependencies,
22193
- "lint-staged": {
22194
- "*.{js,ts,json}": [
22195
- "prettier --write"
22196
- ]
22197
- },
22198
- devDependencies: devDependencies
22199
- };
22200
-
22201
- var _package$1 = /*#__PURE__*/Object.freeze({
22202
- __proto__: null,
22203
- author: author,
22204
- bin: bin,
22205
- default: _package,
22206
- dependencies: dependencies,
22207
- description: description,
22208
- devDependencies: devDependencies,
22209
- engines: engines,
22210
- files: files,
22211
- keywords: keywords,
22212
- license: license,
22213
- main: main,
22214
- module: module$1,
22215
- name: name,
22216
- repository: repository,
22217
- scripts: scripts,
22218
- types: types,
22219
- version: version
22220
- });
22221
-
22222
22087
  var __accessCheck = (obj, member, msg) => {
22223
22088
  if (!member.has(obj))
22224
22089
  throw TypeError("Cannot " + msg);