@embeddable.com/sdk-core 3.9.3 → 3.9.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
@@ -697,6 +697,19 @@ const getSDKVersions = () => {
697
697
  }, {});
698
698
  return sdkVersions;
699
699
  };
700
+ const hrtimeToISO8601 = (hrtime) => {
701
+ if (hrtime === null || hrtime === undefined) {
702
+ return "";
703
+ }
704
+ const seconds = hrtime[0];
705
+ const nanoseconds = hrtime[1];
706
+ // Convert time components
707
+ const totalSeconds = seconds + nanoseconds / 1e9;
708
+ const minutes = Math.floor(totalSeconds / 60);
709
+ const remainingSeconds = totalSeconds % 60;
710
+ // Format ISO 8601 duration without hours
711
+ return `PT${minutes > 0 ? minutes + "M" : ""}${remainingSeconds.toFixed(3)}S`;
712
+ };
700
713
 
701
714
  var cleanup = async (ctx) => {
702
715
  await extractBuild(ctx);
@@ -731,6 +744,9 @@ async function createManifest({ ctx, typesFileName, metaFileName, editorsMetaFil
731
744
  sdkVersions,
732
745
  packageManager,
733
746
  packageManagerVersion,
747
+ metrics: {
748
+ buildTime: hrtimeToISO8601(ctx.buildTime),
749
+ },
734
750
  },
735
751
  };
736
752
  await fs__namespace.writeFile(path__namespace.join(ctx.client.tmpDir, "embeddable-manifest.json"), JSON.stringify(manifest));
@@ -5001,13 +5017,15 @@ var z = /*#__PURE__*/Object.freeze({
5001
5017
 
5002
5018
  const CUBE_YAML_FILE_REGEX = /^(.*)\.cube\.ya?ml$/;
5003
5019
  const SECURITY_CONTEXT_FILE_REGEX = /^(.*)\.sc\.ya?ml$/;
5020
+ const CLIENT_CONTEXT_FILE_REGEX = /^(.*)\.cc\.ya?ml$/;
5004
5021
  var validate = async (ctx, exitIfInvalid = true) => {
5005
5022
  checkNodeVersion();
5006
5023
  const ora = (await import('ora')).default;
5007
5024
  const spinnerValidate = ora("Data model validation...").start();
5008
- const filesList = await findFiles(ctx.client.srcDir, CUBE_YAML_FILE_REGEX);
5009
- const securityContextFilesList = await findFiles(ctx.client.modelsSrc || ctx.client.srcDir, SECURITY_CONTEXT_FILE_REGEX);
5010
- const dataModelErrors = await dataModelsValidation(filesList);
5025
+ const cubeFilesList = await findFiles(ctx.client.modelsSrc || ctx.client.srcDir, CUBE_YAML_FILE_REGEX);
5026
+ const securityContextFilesList = await findFiles(ctx.client.presetsSrc || ctx.client.srcDir, SECURITY_CONTEXT_FILE_REGEX);
5027
+ const clientContextFilesList = await findFiles(ctx.client.presetsSrc || ctx.client.srcDir, CLIENT_CONTEXT_FILE_REGEX);
5028
+ const dataModelErrors = await dataModelsValidation(cubeFilesList);
5011
5029
  if (dataModelErrors.length) {
5012
5030
  spinnerValidate.fail("One or more cube.yaml files are invalid:");
5013
5031
  dataModelErrors.forEach((errorMessage) => spinnerValidate.info(errorMessage));
@@ -5017,6 +5035,7 @@ var validate = async (ctx, exitIfInvalid = true) => {
5017
5035
  }
5018
5036
  spinnerValidate.succeed("Data model validation completed");
5019
5037
  const securityContextErrors = await securityContextValidation(securityContextFilesList);
5038
+ const clientContextErrors = await clientContextValidation(clientContextFilesList);
5020
5039
  if (securityContextErrors.length) {
5021
5040
  spinnerValidate.fail("One or more security context files are invalid:");
5022
5041
  securityContextErrors.forEach((errorMessage) => spinnerValidate.info(errorMessage));
@@ -5024,7 +5043,16 @@ var validate = async (ctx, exitIfInvalid = true) => {
5024
5043
  process.exit(1);
5025
5044
  }
5026
5045
  }
5027
- return dataModelErrors.length === 0 && securityContextErrors.length === 0;
5046
+ if (clientContextErrors.length) {
5047
+ spinnerValidate.fail("One or more client context files are invalid:");
5048
+ clientContextErrors.forEach((errorMessage) => spinnerValidate.info(errorMessage));
5049
+ if (exitIfInvalid) {
5050
+ process.exit(1);
5051
+ }
5052
+ }
5053
+ return (dataModelErrors.length === 0 &&
5054
+ securityContextErrors.length === 0 &&
5055
+ clientContextErrors.length === 0);
5028
5056
  };
5029
5057
  async function dataModelsValidation(filesList) {
5030
5058
  const errors = [];
@@ -5077,6 +5105,29 @@ async function securityContextValidation(filesList) {
5077
5105
  }
5078
5106
  return errors;
5079
5107
  }
5108
+ async function clientContextValidation(filesList) {
5109
+ const errors = [];
5110
+ const nameSet = new Set();
5111
+ for (const [_, filePath] of filesList) {
5112
+ const fileContentRaw = await fs__namespace.readFile(filePath, "utf8");
5113
+ const cube = YAML__namespace.parse(fileContentRaw);
5114
+ cube.forEach((item) => {
5115
+ if (nameSet.has(item.name)) {
5116
+ errors.push(`${filePath}: client context with name "${item.name}" already exists`);
5117
+ }
5118
+ else {
5119
+ nameSet.add(item.name);
5120
+ }
5121
+ });
5122
+ const safeParse = clientContextSchema.safeParse(cube);
5123
+ if (!safeParse.success) {
5124
+ errorFormatter(safeParse.error.issues).forEach((error) => {
5125
+ errors.push(`${filePath}: ${error}`);
5126
+ });
5127
+ }
5128
+ }
5129
+ return errors;
5130
+ }
5080
5131
  var MeasureTypeEnum;
5081
5132
  (function (MeasureTypeEnum) {
5082
5133
  MeasureTypeEnum["string"] = "string";
@@ -5143,6 +5194,10 @@ const securityContextSchema = z.array(z.object({
5143
5194
  name: z.string(),
5144
5195
  securityContext: z.object({}), // can be any object
5145
5196
  }));
5197
+ const clientContextSchema = z.array(z.object({
5198
+ name: z.string(),
5199
+ clientContext: z.object({}), // can be any object
5200
+ }));
5146
5201
 
5147
5202
  var provideConfig = async () => {
5148
5203
  const configFilePath = `${process.cwd()}/embeddable.config.js`;
@@ -21317,6 +21372,7 @@ var build = async () => {
21317
21372
  await initLogger("build");
21318
21373
  const breadcrumbs = [];
21319
21374
  try {
21375
+ const startTime = process.hrtime();
21320
21376
  checkNodeVersion();
21321
21377
  breadcrumbs.push("checkNodeVersion");
21322
21378
  removeBuildSuccessFlag();
@@ -21336,6 +21392,8 @@ var build = async () => {
21336
21392
  // NOTE: likely this will be called inside the loop above if we decide to support clients with mixed frameworks simultaneously.
21337
21393
  breadcrumbs.push("generate");
21338
21394
  await generate(config, "sdk-react");
21395
+ // Calculating build time in seconds
21396
+ config.buildTime = process.hrtime(startTime);
21339
21397
  breadcrumbs.push("cleanup");
21340
21398
  await cleanup(config);
21341
21399
  await storeBuildSuccessFlag();
@@ -21482,8 +21540,10 @@ async function selectWorkspace(ora, ctx, token) {
21482
21540
  }
21483
21541
 
21484
21542
  const oraP$1 = import('ora');
21485
- // grab .cube.yml|js and .sc.yml|js files
21486
- const YAML_OR_JS_FILES = /^(.*)\.(cube|sc)\.(ya?ml|js)$/;
21543
+ // grab cube files
21544
+ const CUBE_FILES = /^(.*)\.cube\.(ya?ml|js)$/;
21545
+ // grab security context and client context files
21546
+ const PRESET_FILES = /^(.*)\.(sc|cc)\.ya?ml$/;
21487
21547
  let ora$1;
21488
21548
  var push = async () => {
21489
21549
  await initLogger("push");
@@ -21566,8 +21626,9 @@ async function verify(ctx) {
21566
21626
  }
21567
21627
  async function buildArchive(config) {
21568
21628
  const spinnerArchive = ora$1("Building...").start();
21569
- const filesList = await findFiles(config.client.modelsSrc || config.client.srcDir, YAML_OR_JS_FILES);
21570
- await archive(config, filesList);
21629
+ const cubeFilesList = await findFiles(config.client.modelsSrc || config.client.srcDir, CUBE_FILES);
21630
+ const contextFilesList = await findFiles(config.client.presetsSrc || config.client.srcDir, PRESET_FILES);
21631
+ await archive(config, [...cubeFilesList, ...contextFilesList]);
21571
21632
  return spinnerArchive.succeed("Bundling completed");
21572
21633
  }
21573
21634
  async function archive(ctx, yamlFiles, isDev = false) {
@@ -21746,7 +21807,7 @@ var dev = async () => {
21746
21807
  metaFileName: "embeddable-components-meta.js",
21747
21808
  editorsMetaFileName: "embeddable-editors-meta.js",
21748
21809
  });
21749
- await sendDataModelsAndSecurityContextsChanges(config);
21810
+ await sendDataModelsAndContextsChanges(config);
21750
21811
  for (const getPlugin of config.plugins) {
21751
21812
  const plugin = getPlugin();
21752
21813
  breadcrumbs.push("validate plugin");
@@ -21815,9 +21876,12 @@ const onBundleBuildEnd = async (ctx) => {
21815
21876
  }
21816
21877
  };
21817
21878
  const dataModelAndSecurityContextWatcher = (ctx) => {
21818
- const fsWatcher = chokidar__namespace.watch([path__namespace$1.resolve(ctx.client.modelsSrc, "**/*.{cube,sc}.{yaml,yml,js}")], chokidarWatchOptions);
21879
+ const fsWatcher = chokidar__namespace.watch([
21880
+ path__namespace$1.resolve(ctx.client.modelsSrc, "**/*.{cube}.{yaml,yml,js}"),
21881
+ path__namespace$1.resolve(ctx.client.presetsSrc, "**/*.{sc,cc}.{yaml,yml}"),
21882
+ ], chokidarWatchOptions);
21819
21883
  fsWatcher.on("all", async () => {
21820
- await sendDataModelsAndSecurityContextsChanges(ctx);
21884
+ await sendDataModelsAndContextsChanges(ctx);
21821
21885
  });
21822
21886
  return fsWatcher;
21823
21887
  };
@@ -21828,13 +21892,15 @@ const globalCssWatcher = (ctx) => {
21828
21892
  });
21829
21893
  return fsWatcher;
21830
21894
  };
21831
- const sendDataModelsAndSecurityContextsChanges = async (ctx) => {
21895
+ const sendDataModelsAndContextsChanges = async (ctx) => {
21832
21896
  sendMessage("dataModelsAndOrSecurityContextUpdateStart");
21833
21897
  const isValid = await validate(ctx, false);
21834
21898
  if (isValid) {
21835
21899
  const token = await getToken();
21836
21900
  const sending = ora("Synchronising data models and/or security contexts...").start();
21837
- const filesList = await findFiles(ctx.client.modelsSrc, YAML_OR_JS_FILES);
21901
+ const cubeFilesList = await findFiles(ctx.client.modelsSrc, CUBE_FILES);
21902
+ const contextFilesList = await findFiles(ctx.client.presetsSrc, PRESET_FILES);
21903
+ const filesList = [...cubeFilesList, ...contextFilesList];
21838
21904
  // add manifest to the archive
21839
21905
  filesList.push([
21840
21906
  "embeddable-manifest",
@@ -21897,7 +21963,7 @@ const getPreviewWorkspace = async (startedOra, ctx) => {
21897
21963
  }
21898
21964
  };
21899
21965
 
21900
- var defineConfig = ({ plugins, pushBaseUrl, audienceUrl, authDomain, authClientId, errorFallbackComponent, applicationEnvironment, rollbarAccessToken, previewBaseUrl, modelsSrc = "src", componentsSrc = "src", globalCss = "src/global.css", viteConfig = {}, rollupOptions = {}, }) => {
21966
+ var defineConfig = ({ plugins, pushBaseUrl, audienceUrl, authDomain, authClientId, errorFallbackComponent, applicationEnvironment, rollbarAccessToken, previewBaseUrl, modelsSrc = "src", presetsSrc = "src", componentsSrc = "src", globalCss = "src/global.css", viteConfig = {}, rollupOptions = {}, }) => {
21901
21967
  const coreRoot = path__namespace.resolve(__dirname, "..");
21902
21968
  const clientRoot = process.cwd();
21903
21969
  if (!path__namespace.isAbsolute(componentsSrc)) {
@@ -21912,6 +21978,12 @@ var defineConfig = ({ plugins, pushBaseUrl, audienceUrl, authDomain, authClientI
21912
21978
  throw new Error(`modelsSrc directory ${modelsSrc} does not exist`);
21913
21979
  }
21914
21980
  }
21981
+ if (presetsSrc && !path__namespace.isAbsolute(presetsSrc)) {
21982
+ presetsSrc = path__namespace.resolve(clientRoot, presetsSrc);
21983
+ if (!fs$1.existsSync(presetsSrc)) {
21984
+ throw new Error(`presetsSrc directory ${presetsSrc} does not exist`);
21985
+ }
21986
+ }
21915
21987
  return {
21916
21988
  core: {
21917
21989
  rootDir: coreRoot,
@@ -21922,6 +21994,7 @@ var defineConfig = ({ plugins, pushBaseUrl, audienceUrl, authDomain, authClientI
21922
21994
  rootDir: clientRoot,
21923
21995
  srcDir: path__namespace.resolve(clientRoot, componentsSrc),
21924
21996
  modelsSrc: modelsSrc ? path__namespace.resolve(clientRoot, modelsSrc) : undefined,
21997
+ presetsSrc: presetsSrc ? path__namespace.resolve(clientRoot, presetsSrc) : undefined,
21925
21998
  buildDir: path__namespace.resolve(clientRoot, ".embeddable-build"),
21926
21999
  tmpDir: path__namespace.resolve(clientRoot, ".embeddable-tmp"),
21927
22000
  globalCss: path__namespace.resolve(clientRoot, globalCss),
@@ -21950,7 +22023,7 @@ var defineConfig = ({ plugins, pushBaseUrl, audienceUrl, authDomain, authClientI
21950
22023
  };
21951
22024
 
21952
22025
  var name = "@embeddable.com/sdk-core";
21953
- var version = "3.9.3";
22026
+ var version = "3.9.5";
21954
22027
  var description = "Core Embeddable SDK module responsible for web-components bundling and publishing.";
21955
22028
  var keywords = [
21956
22029
  "embeddable",