@embeddable.com/sdk-core 3.9.1 → 3.9.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.esm.js CHANGED
@@ -652,14 +652,7 @@ const getPackageVersion = (packageName) => {
652
652
  return undefined;
653
653
  }
654
654
  };
655
-
656
- var cleanup = async (ctx) => {
657
- await extractBuild(ctx);
658
- await removeObsoleteDir(ctx.client.buildDir);
659
- await moveBuildTOBuildDir(ctx);
660
- };
661
- async function createManifest({ ctx, typesFileName, metaFileName, editorsMetaFileName, stencilWrapperFileName, }) {
662
- var _a, _b, _c, _d;
655
+ const getSDKVersions = () => {
663
656
  const packageNames = [
664
657
  "@embeddable.com/core",
665
658
  "@embeddable.com/react",
@@ -674,6 +667,17 @@ async function createManifest({ ctx, typesFileName, metaFileName, editorsMetaFil
674
667
  }
675
668
  return acc;
676
669
  }, {});
670
+ return sdkVersions;
671
+ };
672
+
673
+ var cleanup = async (ctx) => {
674
+ await extractBuild(ctx);
675
+ await removeObsoleteDir(ctx.client.buildDir);
676
+ await moveBuildTOBuildDir(ctx);
677
+ };
678
+ async function createManifest({ ctx, typesFileName, metaFileName, editorsMetaFileName, stencilWrapperFileName, }) {
679
+ var _a, _b, _c, _d;
680
+ const sdkVersions = getSDKVersions();
677
681
  // identify user's package manager and its version
678
682
  let packageManager = "npm";
679
683
  if ((_a = process.env.npm_config_user_agent) === null || _a === void 0 ? void 0 : _a.includes("yarn")) {
@@ -21198,9 +21202,95 @@ async function getUserData() {
21198
21202
  }
21199
21203
  }
21200
21204
 
21205
+ const LOG_DIR = path.join(process.cwd(), ".embeddable", "logs");
21206
+ const ERROR_LOG_FILE = path.join(LOG_DIR, "error.log");
21207
+ const MAX_LOG_SIZE = 5 * 1024 * 1024; // 5 MB
21208
+ const MAX_LOG_FILES = 5;
21209
+ async function initLogger(command) {
21210
+ try {
21211
+ await fs.mkdir(LOG_DIR, { recursive: true });
21212
+ }
21213
+ catch (error) {
21214
+ console.error("Failed to create log directory:", error);
21215
+ }
21216
+ setupGlobalErrorHandlers(command);
21217
+ }
21218
+ async function logError({ command, breadcrumbs, error, }) {
21219
+ const sdkVersions = getSDKVersions();
21220
+ const logEntry = {
21221
+ timestamp: new Date().toISOString(),
21222
+ command,
21223
+ breadcrumbs,
21224
+ error: error instanceof Error
21225
+ ? `${error.name}: ${error.message}\n${error.stack}`
21226
+ : String(error),
21227
+ };
21228
+ const logMessage = `
21229
+ [${logEntry.timestamp}] Command: ${logEntry.command}
21230
+ Breadcrumbs: ${logEntry.breadcrumbs.join(" > ")}
21231
+ Error: ${logEntry.error}
21232
+ OS: ${process.platform}
21233
+ Node: ${process.version}
21234
+ SDK Versions: ${JSON.stringify(sdkVersions, null, 2)}
21235
+ ----------------------------------------
21236
+ `;
21237
+ try {
21238
+ await rotateLogIfNeeded();
21239
+ await fs.appendFile(ERROR_LOG_FILE, logMessage);
21240
+ console.error(`An error occurred during ${command}. Check the log file for details: ${ERROR_LOG_FILE}`);
21241
+ }
21242
+ catch (error) {
21243
+ console.error("Failed to write to log file:", error);
21244
+ }
21245
+ }
21246
+ async function rotateLogIfNeeded() {
21247
+ try {
21248
+ const stats = await fs.stat(ERROR_LOG_FILE);
21249
+ if (stats.size < MAX_LOG_SIZE) {
21250
+ return;
21251
+ }
21252
+ for (let i = MAX_LOG_FILES - 1; i > 0; i--) {
21253
+ const oldFile = `${ERROR_LOG_FILE}.${i}`;
21254
+ const newFile = `${ERROR_LOG_FILE}.${i + 1}`;
21255
+ try {
21256
+ await fs.rename(oldFile, newFile);
21257
+ }
21258
+ catch (error) {
21259
+ // Ignore error if file doesn't exist
21260
+ }
21261
+ }
21262
+ await fs.rename(ERROR_LOG_FILE, `${ERROR_LOG_FILE}.1`);
21263
+ await fs.writeFile(ERROR_LOG_FILE, ""); // Create a new empty log file
21264
+ }
21265
+ catch (error) {
21266
+ if (error.code !== "ENOENT") {
21267
+ console.error("Error rotating log file:", error);
21268
+ }
21269
+ }
21270
+ }
21271
+ function setupGlobalErrorHandlers(command) {
21272
+ process.on("uncaughtException", async (error) => {
21273
+ await logError({ command, breadcrumbs: ["uncaughtException"], error });
21274
+ console.error("An uncaught error occurred. Check the log file for details.");
21275
+ process.exit(1);
21276
+ });
21277
+ process.on("unhandledRejection", async (reason) => {
21278
+ await logError({
21279
+ command,
21280
+ breadcrumbs: ["unhandledRejection"],
21281
+ error: reason,
21282
+ });
21283
+ console.error("An unhandled rejection occurred. Check the log file for details.");
21284
+ process.exit(1);
21285
+ });
21286
+ }
21287
+
21201
21288
  var build = async () => {
21289
+ await initLogger("build");
21290
+ const breadcrumbs = [];
21202
21291
  try {
21203
21292
  checkNodeVersion();
21293
+ breadcrumbs.push("checkNodeVersion");
21204
21294
  removeBuildSuccessFlag();
21205
21295
  const config = await provideConfig();
21206
21296
  await validate(config);
@@ -21208,16 +21298,22 @@ var build = async () => {
21208
21298
  await buildTypes(config);
21209
21299
  for (const getPlugin of config.plugins) {
21210
21300
  const plugin = getPlugin();
21301
+ breadcrumbs.push(`${plugin.pluginName}: validate`);
21211
21302
  await plugin.validate(config);
21303
+ breadcrumbs.push(`${plugin.pluginName}: build`);
21212
21304
  await plugin.build(config);
21305
+ breadcrumbs.push(`${plugin.pluginName}: cleanup`);
21213
21306
  await plugin.cleanup(config);
21214
21307
  }
21215
21308
  // NOTE: likely this will be called inside the loop above if we decide to support clients with mixed frameworks simultaneously.
21309
+ breadcrumbs.push("generate");
21216
21310
  await generate(config, "sdk-react");
21311
+ breadcrumbs.push("cleanup");
21217
21312
  await cleanup(config);
21218
21313
  await storeBuildSuccessFlag();
21219
21314
  }
21220
21315
  catch (error) {
21316
+ await logError({ command: "build", breadcrumbs, error });
21221
21317
  await reportErrorToRollbar(error);
21222
21318
  console.log(error);
21223
21319
  process.exit(1);
@@ -21228,12 +21324,16 @@ const oraP$2 = import('ora');
21228
21324
  const openP = import('open');
21229
21325
  var login = async () => {
21230
21326
  var _a;
21327
+ await initLogger("login");
21328
+ const breadcrumbs = [];
21231
21329
  const ora = (await oraP$2).default;
21232
21330
  const authenticationSpinner = ora("Waiting for code verification...").start();
21233
21331
  try {
21234
21332
  const open = (await openP).default;
21235
21333
  const config = await provideConfig();
21334
+ breadcrumbs.push("provideConfig");
21236
21335
  await resolveFiles();
21336
+ breadcrumbs.push("resolveFiles");
21237
21337
  const deviceCodePayload = {
21238
21338
  client_id: config.authClientId,
21239
21339
  audience: config.audienceUrl,
@@ -21269,6 +21369,7 @@ var login = async () => {
21269
21369
  }
21270
21370
  catch (error) {
21271
21371
  authenticationSpinner.fail("Authentication failed. Please try again.");
21372
+ await logError({ command: "login", breadcrumbs, error });
21272
21373
  await reportErrorToRollbar(error);
21273
21374
  console.log(error);
21274
21375
  process.exit(1);
@@ -21357,10 +21458,12 @@ const oraP$1 = import('ora');
21357
21458
  const YAML_OR_JS_FILES = /^(.*)\.(cube|sc)\.(ya?ml|js)$/;
21358
21459
  let ora$1;
21359
21460
  var push = async () => {
21360
- var _a, _b;
21461
+ await initLogger("push");
21462
+ const breadcrumbs = [];
21361
21463
  let spinnerPushing;
21362
21464
  try {
21363
21465
  checkNodeVersion();
21466
+ breadcrumbs.push("checkNodeVersion");
21364
21467
  const isBuildSuccess = await checkBuildSuccess();
21365
21468
  if (!isBuildSuccess) {
21366
21469
  console.error("Build failed or not completed. Please run `embeddable:build` first.");
@@ -21370,29 +21473,29 @@ var push = async () => {
21370
21473
  const config = await provideConfig();
21371
21474
  if (process.argv.includes("--api-key") || process.argv.includes("-k")) {
21372
21475
  spinnerPushing = ora$1("Using API key...").start();
21476
+ breadcrumbs.push("push by api key");
21373
21477
  await pushByApiKey(config, spinnerPushing);
21374
21478
  spinnerPushing.succeed("Published using API key");
21375
21479
  return;
21376
21480
  }
21481
+ breadcrumbs.push("push by standard login");
21377
21482
  const token = await verify(config);
21378
21483
  spinnerPushing = ora$1()
21379
21484
  .start()
21380
21485
  .info("No API Key provided. Standard login will be used.");
21486
+ breadcrumbs.push("select workspace");
21381
21487
  const { workspaceId, name: workspaceName } = await selectWorkspace(ora$1, config, token);
21382
21488
  const workspacePreviewUrl = `${config.previewBaseUrl}/workspace/${workspaceId}`;
21489
+ breadcrumbs.push("build archive");
21383
21490
  await buildArchive(config);
21384
21491
  spinnerPushing.info(`Publishing to ${workspaceName} using ${workspacePreviewUrl}...`);
21492
+ breadcrumbs.push("send build");
21385
21493
  await sendBuild(config, { workspaceId, token });
21386
21494
  spinnerPushing.succeed(`Published to ${workspaceName} using ${workspacePreviewUrl}`);
21387
21495
  }
21388
21496
  catch (error) {
21389
21497
  spinnerPushing === null || spinnerPushing === void 0 ? void 0 : spinnerPushing.fail("Publishing failed");
21390
- if (((_a = error.response) === null || _a === void 0 ? void 0 : _a.statusText) === "Unauthorized") {
21391
- console.error("Unauthorized. Please check your credentials.");
21392
- }
21393
- else {
21394
- console.error(((_b = error.response) === null || _b === void 0 ? void 0 : _b.data) || (error === null || error === void 0 ? void 0 : error.message) || error);
21395
- }
21498
+ await logError({ command: "push", breadcrumbs, error });
21396
21499
  await reportErrorToRollbar(error);
21397
21500
  process.exit(1);
21398
21501
  }
@@ -21531,93 +21634,111 @@ const chokidarWatchOptions = {
21531
21634
  };
21532
21635
  var dev = async () => {
21533
21636
  var _a, _b;
21534
- checkNodeVersion();
21535
- addToGitingore();
21536
- ora = (await oraP).default;
21537
- process.on("warning", (e) => console.warn(e.stack));
21538
- const logger = createNodeLogger();
21539
- const sys = createNodeSys({ process });
21540
- const defaultConfig = await provideConfig();
21541
- const buildDir = path$1.resolve(defaultConfig.client.rootDir, BUILD_DEV_DIR);
21542
- const config = {
21543
- ...defaultConfig,
21544
- dev: {
21545
- watch: true,
21546
- logger,
21547
- sys,
21548
- },
21549
- client: {
21550
- ...defaultConfig.client,
21551
- buildDir,
21552
- componentDir: path$1.resolve(buildDir, "component"),
21553
- stencilBuild: path$1.resolve(buildDir, "dist", "embeddable-wrapper"),
21554
- tmpDir: path$1.resolve(defaultConfig.client.rootDir, ".embeddable-dev-tmp"),
21555
- },
21556
- };
21557
- await prepare(config);
21558
- const finalhandler = require("finalhandler");
21559
- const serveStatic = require("serve-static");
21560
- const serve = serveStatic(config.client.buildDir);
21561
- const workspacePreparation = ora("Preparing workspace...").start();
21637
+ await initLogger("dev");
21638
+ const breadcrumbs = [];
21562
21639
  try {
21563
- previewWorkspace = await getPreviewWorkspace(workspacePreparation, config);
21564
- }
21565
- catch (e) {
21566
- 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);
21567
- process.exit(1);
21568
- }
21569
- workspacePreparation.succeed("Workspace is ready");
21570
- const server = http.createServer((request, res) => {
21571
- var _a;
21572
- res.setHeader("Access-Control-Allow-Origin", "*");
21573
- res.setHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
21574
- res.setHeader("Access-Control-Allow-Headers", "Content-Type, Authorization");
21575
- if (request.method === "OPTIONS") {
21576
- // Respond to OPTIONS requests with just the CORS headers and a 200 status code
21577
- res.writeHead(200);
21578
- res.end();
21579
- return;
21580
- }
21581
- const done = finalhandler(request, res);
21582
- if ((_a = request.url) === null || _a === void 0 ? void 0 : _a.endsWith(GLOBAL_CSS)) {
21583
- res.writeHead(200, { "Content-Type": "text/css" });
21584
- res.end(require$$2$1.readFileSync(config.client.globalCss));
21585
- return;
21640
+ breadcrumbs.push("run dev");
21641
+ checkNodeVersion();
21642
+ addToGitingore();
21643
+ ora = (await oraP).default;
21644
+ process.on("warning", (e) => console.warn(e.stack));
21645
+ const logger = createNodeLogger();
21646
+ const sys = createNodeSys({ process });
21647
+ const defaultConfig = await provideConfig();
21648
+ const buildDir = path$1.resolve(defaultConfig.client.rootDir, BUILD_DEV_DIR);
21649
+ const config = {
21650
+ ...defaultConfig,
21651
+ dev: {
21652
+ watch: true,
21653
+ logger,
21654
+ sys,
21655
+ },
21656
+ client: {
21657
+ ...defaultConfig.client,
21658
+ buildDir,
21659
+ componentDir: path$1.resolve(buildDir, "component"),
21660
+ stencilBuild: path$1.resolve(buildDir, "dist", "embeddable-wrapper"),
21661
+ tmpDir: path$1.resolve(defaultConfig.client.rootDir, ".embeddable-dev-tmp"),
21662
+ },
21663
+ };
21664
+ breadcrumbs.push("prepare config");
21665
+ await prepare(config);
21666
+ const finalhandler = require("finalhandler");
21667
+ const serveStatic = require("serve-static");
21668
+ const serve = serveStatic(config.client.buildDir);
21669
+ const workspacePreparation = ora("Preparing workspace...").start();
21670
+ breadcrumbs.push("get preview workspace");
21671
+ try {
21672
+ previewWorkspace = await getPreviewWorkspace(workspacePreparation, config);
21586
21673
  }
21587
- serve(request, res, done);
21588
- });
21589
- wss = new WebSocketServer({ server });
21590
- server.listen(SERVER_PORT, async () => {
21591
- const watchers = [];
21592
- if (sys === null || sys === void 0 ? void 0 : sys.onProcessInterrupt) {
21593
- sys.onProcessInterrupt(async () => await onClose(server, sys, watchers, config));
21674
+ catch (e) {
21675
+ 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);
21676
+ process.exit(1);
21594
21677
  }
21595
- await createManifest({
21596
- ctx: {
21597
- ...config,
21598
- client: {
21599
- ...config.client,
21600
- tmpDir: buildDir,
21678
+ workspacePreparation.succeed("Workspace is ready");
21679
+ const server = http.createServer((request, res) => {
21680
+ var _a;
21681
+ res.setHeader("Access-Control-Allow-Origin", "*");
21682
+ res.setHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
21683
+ res.setHeader("Access-Control-Allow-Headers", "Content-Type, Authorization");
21684
+ if (request.method === "OPTIONS") {
21685
+ // Respond to OPTIONS requests with just the CORS headers and a 200 status code
21686
+ res.writeHead(200);
21687
+ res.end();
21688
+ return;
21689
+ }
21690
+ const done = finalhandler(request, res);
21691
+ try {
21692
+ if ((_a = request.url) === null || _a === void 0 ? void 0 : _a.endsWith(GLOBAL_CSS)) {
21693
+ res.writeHead(200, { "Content-Type": "text/css" });
21694
+ res.end(require$$2$1.readFileSync(config.client.globalCss));
21695
+ return;
21696
+ }
21697
+ }
21698
+ catch (_b) { }
21699
+ serve(request, res, done);
21700
+ });
21701
+ wss = new WebSocketServer({ server });
21702
+ server.listen(SERVER_PORT, async () => {
21703
+ const watchers = [];
21704
+ if (sys === null || sys === void 0 ? void 0 : sys.onProcessInterrupt) {
21705
+ sys.onProcessInterrupt(async () => await onClose(server, sys, watchers, config));
21706
+ }
21707
+ breadcrumbs.push("create manifest");
21708
+ await createManifest({
21709
+ ctx: {
21710
+ ...config,
21711
+ client: {
21712
+ ...config.client,
21713
+ tmpDir: buildDir,
21714
+ },
21601
21715
  },
21602
- },
21603
- typesFileName: "embeddable-types.js",
21604
- stencilWrapperFileName: "embeddable-wrapper.js",
21605
- metaFileName: "embeddable-components-meta.js",
21606
- editorsMetaFileName: "embeddable-editors-meta.js",
21716
+ typesFileName: "embeddable-types.js",
21717
+ stencilWrapperFileName: "embeddable-wrapper.js",
21718
+ metaFileName: "embeddable-components-meta.js",
21719
+ editorsMetaFileName: "embeddable-editors-meta.js",
21720
+ });
21721
+ await sendDataModelsAndSecurityContextsChanges(config);
21722
+ for (const getPlugin of config.plugins) {
21723
+ const plugin = getPlugin();
21724
+ breadcrumbs.push("validate plugin");
21725
+ await plugin.validate(config);
21726
+ breadcrumbs.push("build plugin");
21727
+ const watcher = await plugin.build(config);
21728
+ breadcrumbs.push("configure watcher");
21729
+ await configureWatcher(watcher, config);
21730
+ watchers.push(watcher);
21731
+ }
21732
+ const dataModelAndSecurityContextWatch = dataModelAndSecurityContextWatcher(config);
21733
+ const customGlobalCssWatch = globalCssWatcher(config);
21734
+ watchers.push(dataModelAndSecurityContextWatch);
21735
+ watchers.push(customGlobalCssWatch);
21607
21736
  });
21608
- await sendDataModelsAndSecurityContextsChanges(config);
21609
- for (const getPlugin of config.plugins) {
21610
- const plugin = getPlugin();
21611
- await plugin.validate(config);
21612
- const watcher = await plugin.build(config);
21613
- await configureWatcher(watcher, config);
21614
- watchers.push(watcher);
21615
- }
21616
- const dataModelAndSecurityContextWatch = dataModelAndSecurityContextWatcher(config);
21617
- const customGlobalCssWatch = globalCssWatcher(config);
21618
- watchers.push(dataModelAndSecurityContextWatch);
21619
- watchers.push(customGlobalCssWatch);
21620
- });
21737
+ }
21738
+ catch (error) {
21739
+ await logError({ command: "dev", breadcrumbs, error });
21740
+ process.exit(1);
21741
+ }
21621
21742
  };
21622
21743
  const configureWatcher = async (watcher, ctx) => {
21623
21744
  watcher.on("change", (path) => {
@@ -21801,7 +21922,7 @@ var defineConfig = ({ plugins, pushBaseUrl, audienceUrl, authDomain, authClientI
21801
21922
  };
21802
21923
 
21803
21924
  var name = "@embeddable.com/sdk-core";
21804
- var version = "3.9.1";
21925
+ var version = "3.9.3";
21805
21926
  var description = "Core Embeddable SDK module responsible for web-components bundling and publishing.";
21806
21927
  var keywords = [
21807
21928
  "embeddable",