@embeddable.com/sdk-core 3.9.2 → 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.js CHANGED
@@ -680,14 +680,7 @@ const getPackageVersion = (packageName) => {
680
680
  return undefined;
681
681
  }
682
682
  };
683
-
684
- var cleanup = async (ctx) => {
685
- await extractBuild(ctx);
686
- await removeObsoleteDir(ctx.client.buildDir);
687
- await moveBuildTOBuildDir(ctx);
688
- };
689
- async function createManifest({ ctx, typesFileName, metaFileName, editorsMetaFileName, stencilWrapperFileName, }) {
690
- var _a, _b, _c, _d;
683
+ const getSDKVersions = () => {
691
684
  const packageNames = [
692
685
  "@embeddable.com/core",
693
686
  "@embeddable.com/react",
@@ -702,6 +695,17 @@ async function createManifest({ ctx, typesFileName, metaFileName, editorsMetaFil
702
695
  }
703
696
  return acc;
704
697
  }, {});
698
+ return sdkVersions;
699
+ };
700
+
701
+ var cleanup = async (ctx) => {
702
+ await extractBuild(ctx);
703
+ await removeObsoleteDir(ctx.client.buildDir);
704
+ await moveBuildTOBuildDir(ctx);
705
+ };
706
+ async function createManifest({ ctx, typesFileName, metaFileName, editorsMetaFileName, stencilWrapperFileName, }) {
707
+ var _a, _b, _c, _d;
708
+ const sdkVersions = getSDKVersions();
705
709
  // identify user's package manager and its version
706
710
  let packageManager = "npm";
707
711
  if ((_a = process.env.npm_config_user_agent) === null || _a === void 0 ? void 0 : _a.includes("yarn")) {
@@ -21226,9 +21230,95 @@ async function getUserData() {
21226
21230
  }
21227
21231
  }
21228
21232
 
21233
+ const LOG_DIR = path__namespace.join(process.cwd(), ".embeddable", "logs");
21234
+ const ERROR_LOG_FILE = path__namespace.join(LOG_DIR, "error.log");
21235
+ const MAX_LOG_SIZE = 5 * 1024 * 1024; // 5 MB
21236
+ const MAX_LOG_FILES = 5;
21237
+ async function initLogger(command) {
21238
+ try {
21239
+ await fs__namespace.mkdir(LOG_DIR, { recursive: true });
21240
+ }
21241
+ catch (error) {
21242
+ console.error("Failed to create log directory:", error);
21243
+ }
21244
+ setupGlobalErrorHandlers(command);
21245
+ }
21246
+ async function logError({ command, breadcrumbs, error, }) {
21247
+ const sdkVersions = getSDKVersions();
21248
+ const logEntry = {
21249
+ timestamp: new Date().toISOString(),
21250
+ command,
21251
+ breadcrumbs,
21252
+ error: error instanceof Error
21253
+ ? `${error.name}: ${error.message}\n${error.stack}`
21254
+ : String(error),
21255
+ };
21256
+ const logMessage = `
21257
+ [${logEntry.timestamp}] Command: ${logEntry.command}
21258
+ Breadcrumbs: ${logEntry.breadcrumbs.join(" > ")}
21259
+ Error: ${logEntry.error}
21260
+ OS: ${process.platform}
21261
+ Node: ${process.version}
21262
+ SDK Versions: ${JSON.stringify(sdkVersions, null, 2)}
21263
+ ----------------------------------------
21264
+ `;
21265
+ try {
21266
+ await rotateLogIfNeeded();
21267
+ await fs__namespace.appendFile(ERROR_LOG_FILE, logMessage);
21268
+ console.error(`An error occurred during ${command}. Check the log file for details: ${ERROR_LOG_FILE}`);
21269
+ }
21270
+ catch (error) {
21271
+ console.error("Failed to write to log file:", error);
21272
+ }
21273
+ }
21274
+ async function rotateLogIfNeeded() {
21275
+ try {
21276
+ const stats = await fs__namespace.stat(ERROR_LOG_FILE);
21277
+ if (stats.size < MAX_LOG_SIZE) {
21278
+ return;
21279
+ }
21280
+ for (let i = MAX_LOG_FILES - 1; i > 0; i--) {
21281
+ const oldFile = `${ERROR_LOG_FILE}.${i}`;
21282
+ const newFile = `${ERROR_LOG_FILE}.${i + 1}`;
21283
+ try {
21284
+ await fs__namespace.rename(oldFile, newFile);
21285
+ }
21286
+ catch (error) {
21287
+ // Ignore error if file doesn't exist
21288
+ }
21289
+ }
21290
+ await fs__namespace.rename(ERROR_LOG_FILE, `${ERROR_LOG_FILE}.1`);
21291
+ await fs__namespace.writeFile(ERROR_LOG_FILE, ""); // Create a new empty log file
21292
+ }
21293
+ catch (error) {
21294
+ if (error.code !== "ENOENT") {
21295
+ console.error("Error rotating log file:", error);
21296
+ }
21297
+ }
21298
+ }
21299
+ function setupGlobalErrorHandlers(command) {
21300
+ process.on("uncaughtException", async (error) => {
21301
+ await logError({ command, breadcrumbs: ["uncaughtException"], error });
21302
+ console.error("An uncaught error occurred. Check the log file for details.");
21303
+ process.exit(1);
21304
+ });
21305
+ process.on("unhandledRejection", async (reason) => {
21306
+ await logError({
21307
+ command,
21308
+ breadcrumbs: ["unhandledRejection"],
21309
+ error: reason,
21310
+ });
21311
+ console.error("An unhandled rejection occurred. Check the log file for details.");
21312
+ process.exit(1);
21313
+ });
21314
+ }
21315
+
21229
21316
  var build = async () => {
21317
+ await initLogger("build");
21318
+ const breadcrumbs = [];
21230
21319
  try {
21231
21320
  checkNodeVersion();
21321
+ breadcrumbs.push("checkNodeVersion");
21232
21322
  removeBuildSuccessFlag();
21233
21323
  const config = await provideConfig();
21234
21324
  await validate(config);
@@ -21236,16 +21326,22 @@ var build = async () => {
21236
21326
  await buildTypes(config);
21237
21327
  for (const getPlugin of config.plugins) {
21238
21328
  const plugin = getPlugin();
21329
+ breadcrumbs.push(`${plugin.pluginName}: validate`);
21239
21330
  await plugin.validate(config);
21331
+ breadcrumbs.push(`${plugin.pluginName}: build`);
21240
21332
  await plugin.build(config);
21333
+ breadcrumbs.push(`${plugin.pluginName}: cleanup`);
21241
21334
  await plugin.cleanup(config);
21242
21335
  }
21243
21336
  // NOTE: likely this will be called inside the loop above if we decide to support clients with mixed frameworks simultaneously.
21337
+ breadcrumbs.push("generate");
21244
21338
  await generate(config, "sdk-react");
21339
+ breadcrumbs.push("cleanup");
21245
21340
  await cleanup(config);
21246
21341
  await storeBuildSuccessFlag();
21247
21342
  }
21248
21343
  catch (error) {
21344
+ await logError({ command: "build", breadcrumbs, error });
21249
21345
  await reportErrorToRollbar(error);
21250
21346
  console.log(error);
21251
21347
  process.exit(1);
@@ -21256,12 +21352,16 @@ const oraP$2 = import('ora');
21256
21352
  const openP = import('open');
21257
21353
  var login = async () => {
21258
21354
  var _a;
21355
+ await initLogger("login");
21356
+ const breadcrumbs = [];
21259
21357
  const ora = (await oraP$2).default;
21260
21358
  const authenticationSpinner = ora("Waiting for code verification...").start();
21261
21359
  try {
21262
21360
  const open = (await openP).default;
21263
21361
  const config = await provideConfig();
21362
+ breadcrumbs.push("provideConfig");
21264
21363
  await resolveFiles();
21364
+ breadcrumbs.push("resolveFiles");
21265
21365
  const deviceCodePayload = {
21266
21366
  client_id: config.authClientId,
21267
21367
  audience: config.audienceUrl,
@@ -21297,6 +21397,7 @@ var login = async () => {
21297
21397
  }
21298
21398
  catch (error) {
21299
21399
  authenticationSpinner.fail("Authentication failed. Please try again.");
21400
+ await logError({ command: "login", breadcrumbs, error });
21300
21401
  await reportErrorToRollbar(error);
21301
21402
  console.log(error);
21302
21403
  process.exit(1);
@@ -21385,10 +21486,12 @@ const oraP$1 = import('ora');
21385
21486
  const YAML_OR_JS_FILES = /^(.*)\.(cube|sc)\.(ya?ml|js)$/;
21386
21487
  let ora$1;
21387
21488
  var push = async () => {
21388
- var _a, _b;
21489
+ await initLogger("push");
21490
+ const breadcrumbs = [];
21389
21491
  let spinnerPushing;
21390
21492
  try {
21391
21493
  checkNodeVersion();
21494
+ breadcrumbs.push("checkNodeVersion");
21392
21495
  const isBuildSuccess = await checkBuildSuccess();
21393
21496
  if (!isBuildSuccess) {
21394
21497
  console.error("Build failed or not completed. Please run `embeddable:build` first.");
@@ -21398,29 +21501,29 @@ var push = async () => {
21398
21501
  const config = await provideConfig();
21399
21502
  if (process.argv.includes("--api-key") || process.argv.includes("-k")) {
21400
21503
  spinnerPushing = ora$1("Using API key...").start();
21504
+ breadcrumbs.push("push by api key");
21401
21505
  await pushByApiKey(config, spinnerPushing);
21402
21506
  spinnerPushing.succeed("Published using API key");
21403
21507
  return;
21404
21508
  }
21509
+ breadcrumbs.push("push by standard login");
21405
21510
  const token = await verify(config);
21406
21511
  spinnerPushing = ora$1()
21407
21512
  .start()
21408
21513
  .info("No API Key provided. Standard login will be used.");
21514
+ breadcrumbs.push("select workspace");
21409
21515
  const { workspaceId, name: workspaceName } = await selectWorkspace(ora$1, config, token);
21410
21516
  const workspacePreviewUrl = `${config.previewBaseUrl}/workspace/${workspaceId}`;
21517
+ breadcrumbs.push("build archive");
21411
21518
  await buildArchive(config);
21412
21519
  spinnerPushing.info(`Publishing to ${workspaceName} using ${workspacePreviewUrl}...`);
21520
+ breadcrumbs.push("send build");
21413
21521
  await sendBuild(config, { workspaceId, token });
21414
21522
  spinnerPushing.succeed(`Published to ${workspaceName} using ${workspacePreviewUrl}`);
21415
21523
  }
21416
21524
  catch (error) {
21417
21525
  spinnerPushing === null || spinnerPushing === void 0 ? void 0 : spinnerPushing.fail("Publishing failed");
21418
- if (((_a = error.response) === null || _a === void 0 ? void 0 : _a.statusText) === "Unauthorized") {
21419
- console.error("Unauthorized. Please check your credentials.");
21420
- }
21421
- else {
21422
- console.error(((_b = error.response) === null || _b === void 0 ? void 0 : _b.data) || (error === null || error === void 0 ? void 0 : error.message) || error);
21423
- }
21526
+ await logError({ command: "push", breadcrumbs, error });
21424
21527
  await reportErrorToRollbar(error);
21425
21528
  process.exit(1);
21426
21529
  }
@@ -21559,96 +21662,111 @@ const chokidarWatchOptions = {
21559
21662
  };
21560
21663
  var dev = async () => {
21561
21664
  var _a, _b;
21562
- checkNodeVersion();
21563
- addToGitingore();
21564
- ora = (await oraP).default;
21565
- process.on("warning", (e) => console.warn(e.stack));
21566
- const logger = node.createNodeLogger();
21567
- const sys = node.createNodeSys({ process });
21568
- const defaultConfig = await provideConfig();
21569
- const buildDir = path__namespace$1.resolve(defaultConfig.client.rootDir, BUILD_DEV_DIR);
21570
- const config = {
21571
- ...defaultConfig,
21572
- dev: {
21573
- watch: true,
21574
- logger,
21575
- sys,
21576
- },
21577
- client: {
21578
- ...defaultConfig.client,
21579
- buildDir,
21580
- componentDir: path__namespace$1.resolve(buildDir, "component"),
21581
- stencilBuild: path__namespace$1.resolve(buildDir, "dist", "embeddable-wrapper"),
21582
- tmpDir: path__namespace$1.resolve(defaultConfig.client.rootDir, ".embeddable-dev-tmp"),
21583
- },
21584
- };
21585
- await prepare(config);
21586
- const finalhandler = require("finalhandler");
21587
- const serveStatic = require("serve-static");
21588
- const serve = serveStatic(config.client.buildDir);
21589
- const workspacePreparation = ora("Preparing workspace...").start();
21665
+ await initLogger("dev");
21666
+ const breadcrumbs = [];
21590
21667
  try {
21591
- previewWorkspace = await getPreviewWorkspace(workspacePreparation, config);
21592
- }
21593
- catch (e) {
21594
- 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);
21595
- process.exit(1);
21596
- }
21597
- workspacePreparation.succeed("Workspace is ready");
21598
- const server = http__namespace.createServer((request, res) => {
21599
- var _a;
21600
- res.setHeader("Access-Control-Allow-Origin", "*");
21601
- res.setHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
21602
- res.setHeader("Access-Control-Allow-Headers", "Content-Type, Authorization");
21603
- if (request.method === "OPTIONS") {
21604
- // Respond to OPTIONS requests with just the CORS headers and a 200 status code
21605
- res.writeHead(200);
21606
- res.end();
21607
- return;
21608
- }
21609
- const done = finalhandler(request, res);
21668
+ breadcrumbs.push("run dev");
21669
+ checkNodeVersion();
21670
+ addToGitingore();
21671
+ ora = (await oraP).default;
21672
+ process.on("warning", (e) => console.warn(e.stack));
21673
+ const logger = node.createNodeLogger();
21674
+ const sys = node.createNodeSys({ process });
21675
+ const defaultConfig = await provideConfig();
21676
+ const buildDir = path__namespace$1.resolve(defaultConfig.client.rootDir, BUILD_DEV_DIR);
21677
+ const config = {
21678
+ ...defaultConfig,
21679
+ dev: {
21680
+ watch: true,
21681
+ logger,
21682
+ sys,
21683
+ },
21684
+ client: {
21685
+ ...defaultConfig.client,
21686
+ buildDir,
21687
+ componentDir: path__namespace$1.resolve(buildDir, "component"),
21688
+ stencilBuild: path__namespace$1.resolve(buildDir, "dist", "embeddable-wrapper"),
21689
+ tmpDir: path__namespace$1.resolve(defaultConfig.client.rootDir, ".embeddable-dev-tmp"),
21690
+ },
21691
+ };
21692
+ breadcrumbs.push("prepare config");
21693
+ await prepare(config);
21694
+ const finalhandler = require("finalhandler");
21695
+ const serveStatic = require("serve-static");
21696
+ const serve = serveStatic(config.client.buildDir);
21697
+ const workspacePreparation = ora("Preparing workspace...").start();
21698
+ breadcrumbs.push("get preview workspace");
21610
21699
  try {
21611
- if ((_a = request.url) === null || _a === void 0 ? void 0 : _a.endsWith(GLOBAL_CSS)) {
21612
- res.writeHead(200, { "Content-Type": "text/css" });
21613
- res.end(require$$2__namespace.readFileSync(config.client.globalCss));
21614
- return;
21615
- }
21700
+ previewWorkspace = await getPreviewWorkspace(workspacePreparation, config);
21616
21701
  }
21617
- catch (_b) { }
21618
- serve(request, res, done);
21619
- });
21620
- wss = new ws.WebSocketServer({ server });
21621
- server.listen(SERVER_PORT, async () => {
21622
- const watchers = [];
21623
- if (sys === null || sys === void 0 ? void 0 : sys.onProcessInterrupt) {
21624
- sys.onProcessInterrupt(async () => await onClose(server, sys, watchers, config));
21702
+ catch (e) {
21703
+ 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);
21704
+ process.exit(1);
21625
21705
  }
21626
- await createManifest({
21627
- ctx: {
21628
- ...config,
21629
- client: {
21630
- ...config.client,
21631
- tmpDir: buildDir,
21706
+ workspacePreparation.succeed("Workspace is ready");
21707
+ const server = http__namespace.createServer((request, res) => {
21708
+ var _a;
21709
+ res.setHeader("Access-Control-Allow-Origin", "*");
21710
+ res.setHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
21711
+ res.setHeader("Access-Control-Allow-Headers", "Content-Type, Authorization");
21712
+ if (request.method === "OPTIONS") {
21713
+ // Respond to OPTIONS requests with just the CORS headers and a 200 status code
21714
+ res.writeHead(200);
21715
+ res.end();
21716
+ return;
21717
+ }
21718
+ const done = finalhandler(request, res);
21719
+ try {
21720
+ if ((_a = request.url) === null || _a === void 0 ? void 0 : _a.endsWith(GLOBAL_CSS)) {
21721
+ res.writeHead(200, { "Content-Type": "text/css" });
21722
+ res.end(require$$2__namespace.readFileSync(config.client.globalCss));
21723
+ return;
21724
+ }
21725
+ }
21726
+ catch (_b) { }
21727
+ serve(request, res, done);
21728
+ });
21729
+ wss = new ws.WebSocketServer({ server });
21730
+ server.listen(SERVER_PORT, async () => {
21731
+ const watchers = [];
21732
+ if (sys === null || sys === void 0 ? void 0 : sys.onProcessInterrupt) {
21733
+ sys.onProcessInterrupt(async () => await onClose(server, sys, watchers, config));
21734
+ }
21735
+ breadcrumbs.push("create manifest");
21736
+ await createManifest({
21737
+ ctx: {
21738
+ ...config,
21739
+ client: {
21740
+ ...config.client,
21741
+ tmpDir: buildDir,
21742
+ },
21632
21743
  },
21633
- },
21634
- typesFileName: "embeddable-types.js",
21635
- stencilWrapperFileName: "embeddable-wrapper.js",
21636
- metaFileName: "embeddable-components-meta.js",
21637
- editorsMetaFileName: "embeddable-editors-meta.js",
21744
+ typesFileName: "embeddable-types.js",
21745
+ stencilWrapperFileName: "embeddable-wrapper.js",
21746
+ metaFileName: "embeddable-components-meta.js",
21747
+ editorsMetaFileName: "embeddable-editors-meta.js",
21748
+ });
21749
+ await sendDataModelsAndSecurityContextsChanges(config);
21750
+ for (const getPlugin of config.plugins) {
21751
+ const plugin = getPlugin();
21752
+ breadcrumbs.push("validate plugin");
21753
+ await plugin.validate(config);
21754
+ breadcrumbs.push("build plugin");
21755
+ const watcher = await plugin.build(config);
21756
+ breadcrumbs.push("configure watcher");
21757
+ await configureWatcher(watcher, config);
21758
+ watchers.push(watcher);
21759
+ }
21760
+ const dataModelAndSecurityContextWatch = dataModelAndSecurityContextWatcher(config);
21761
+ const customGlobalCssWatch = globalCssWatcher(config);
21762
+ watchers.push(dataModelAndSecurityContextWatch);
21763
+ watchers.push(customGlobalCssWatch);
21638
21764
  });
21639
- await sendDataModelsAndSecurityContextsChanges(config);
21640
- for (const getPlugin of config.plugins) {
21641
- const plugin = getPlugin();
21642
- await plugin.validate(config);
21643
- const watcher = await plugin.build(config);
21644
- await configureWatcher(watcher, config);
21645
- watchers.push(watcher);
21646
- }
21647
- const dataModelAndSecurityContextWatch = dataModelAndSecurityContextWatcher(config);
21648
- const customGlobalCssWatch = globalCssWatcher(config);
21649
- watchers.push(dataModelAndSecurityContextWatch);
21650
- watchers.push(customGlobalCssWatch);
21651
- });
21765
+ }
21766
+ catch (error) {
21767
+ await logError({ command: "dev", breadcrumbs, error });
21768
+ process.exit(1);
21769
+ }
21652
21770
  };
21653
21771
  const configureWatcher = async (watcher, ctx) => {
21654
21772
  watcher.on("change", (path) => {
@@ -21832,7 +21950,7 @@ var defineConfig = ({ plugins, pushBaseUrl, audienceUrl, authDomain, authClientI
21832
21950
  };
21833
21951
 
21834
21952
  var name = "@embeddable.com/sdk-core";
21835
- var version = "3.9.2";
21953
+ var version = "3.9.3";
21836
21954
  var description = "Core Embeddable SDK module responsible for web-components bundling and publishing.";
21837
21955
  var keywords = [
21838
21956
  "embeddable",