@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.
@@ -16,6 +16,7 @@ export type EmbeddableConfig = {
16
16
  previewBaseUrl?: string;
17
17
  componentsSrc?: string;
18
18
  modelsSrc?: string;
19
+ presetsSrc?: string;
19
20
  globalCss?: string;
20
21
  viteConfig?: {
21
22
  resolve?: {
@@ -24,7 +25,7 @@ export type EmbeddableConfig = {
24
25
  };
25
26
  rollupOptions?: RollupOptions;
26
27
  };
27
- declare const _default: ({ plugins, pushBaseUrl, audienceUrl, authDomain, authClientId, errorFallbackComponent, applicationEnvironment, rollbarAccessToken, previewBaseUrl, modelsSrc, componentsSrc, globalCss, viteConfig, rollupOptions, }: EmbeddableConfig) => {
28
+ declare const _default: ({ plugins, pushBaseUrl, audienceUrl, authDomain, authClientId, errorFallbackComponent, applicationEnvironment, rollbarAccessToken, previewBaseUrl, modelsSrc, presetsSrc, componentsSrc, globalCss, viteConfig, rollupOptions, }: EmbeddableConfig) => {
28
29
  core: {
29
30
  rootDir: string;
30
31
  templatesDir: string;
@@ -34,6 +35,7 @@ declare const _default: ({ plugins, pushBaseUrl, audienceUrl, authDomain, authCl
34
35
  rootDir: string;
35
36
  srcDir: string;
36
37
  modelsSrc: string | undefined;
38
+ presetsSrc: string | undefined;
37
39
  buildDir: string;
38
40
  tmpDir: string;
39
41
  globalCss: string;
package/lib/index.esm.js CHANGED
@@ -669,6 +669,19 @@ const getSDKVersions = () => {
669
669
  }, {});
670
670
  return sdkVersions;
671
671
  };
672
+ const hrtimeToISO8601 = (hrtime) => {
673
+ if (hrtime === null || hrtime === undefined) {
674
+ return "";
675
+ }
676
+ const seconds = hrtime[0];
677
+ const nanoseconds = hrtime[1];
678
+ // Convert time components
679
+ const totalSeconds = seconds + nanoseconds / 1e9;
680
+ const minutes = Math.floor(totalSeconds / 60);
681
+ const remainingSeconds = totalSeconds % 60;
682
+ // Format ISO 8601 duration without hours
683
+ return `PT${minutes > 0 ? minutes + "M" : ""}${remainingSeconds.toFixed(3)}S`;
684
+ };
672
685
 
673
686
  var cleanup = async (ctx) => {
674
687
  await extractBuild(ctx);
@@ -703,6 +716,9 @@ async function createManifest({ ctx, typesFileName, metaFileName, editorsMetaFil
703
716
  sdkVersions,
704
717
  packageManager,
705
718
  packageManagerVersion,
719
+ metrics: {
720
+ buildTime: hrtimeToISO8601(ctx.buildTime),
721
+ },
706
722
  },
707
723
  };
708
724
  await fs.writeFile(path.join(ctx.client.tmpDir, "embeddable-manifest.json"), JSON.stringify(manifest));
@@ -4973,13 +4989,15 @@ var z = /*#__PURE__*/Object.freeze({
4973
4989
 
4974
4990
  const CUBE_YAML_FILE_REGEX = /^(.*)\.cube\.ya?ml$/;
4975
4991
  const SECURITY_CONTEXT_FILE_REGEX = /^(.*)\.sc\.ya?ml$/;
4992
+ const CLIENT_CONTEXT_FILE_REGEX = /^(.*)\.cc\.ya?ml$/;
4976
4993
  var validate = async (ctx, exitIfInvalid = true) => {
4977
4994
  checkNodeVersion();
4978
4995
  const ora = (await import('ora')).default;
4979
4996
  const spinnerValidate = ora("Data model validation...").start();
4980
- const filesList = await findFiles(ctx.client.srcDir, CUBE_YAML_FILE_REGEX);
4981
- const securityContextFilesList = await findFiles(ctx.client.modelsSrc || ctx.client.srcDir, SECURITY_CONTEXT_FILE_REGEX);
4982
- const dataModelErrors = await dataModelsValidation(filesList);
4997
+ const cubeFilesList = await findFiles(ctx.client.modelsSrc || ctx.client.srcDir, CUBE_YAML_FILE_REGEX);
4998
+ const securityContextFilesList = await findFiles(ctx.client.presetsSrc || ctx.client.srcDir, SECURITY_CONTEXT_FILE_REGEX);
4999
+ const clientContextFilesList = await findFiles(ctx.client.presetsSrc || ctx.client.srcDir, CLIENT_CONTEXT_FILE_REGEX);
5000
+ const dataModelErrors = await dataModelsValidation(cubeFilesList);
4983
5001
  if (dataModelErrors.length) {
4984
5002
  spinnerValidate.fail("One or more cube.yaml files are invalid:");
4985
5003
  dataModelErrors.forEach((errorMessage) => spinnerValidate.info(errorMessage));
@@ -4989,6 +5007,7 @@ var validate = async (ctx, exitIfInvalid = true) => {
4989
5007
  }
4990
5008
  spinnerValidate.succeed("Data model validation completed");
4991
5009
  const securityContextErrors = await securityContextValidation(securityContextFilesList);
5010
+ const clientContextErrors = await clientContextValidation(clientContextFilesList);
4992
5011
  if (securityContextErrors.length) {
4993
5012
  spinnerValidate.fail("One or more security context files are invalid:");
4994
5013
  securityContextErrors.forEach((errorMessage) => spinnerValidate.info(errorMessage));
@@ -4996,7 +5015,16 @@ var validate = async (ctx, exitIfInvalid = true) => {
4996
5015
  process.exit(1);
4997
5016
  }
4998
5017
  }
4999
- return dataModelErrors.length === 0 && securityContextErrors.length === 0;
5018
+ if (clientContextErrors.length) {
5019
+ spinnerValidate.fail("One or more client context files are invalid:");
5020
+ clientContextErrors.forEach((errorMessage) => spinnerValidate.info(errorMessage));
5021
+ if (exitIfInvalid) {
5022
+ process.exit(1);
5023
+ }
5024
+ }
5025
+ return (dataModelErrors.length === 0 &&
5026
+ securityContextErrors.length === 0 &&
5027
+ clientContextErrors.length === 0);
5000
5028
  };
5001
5029
  async function dataModelsValidation(filesList) {
5002
5030
  const errors = [];
@@ -5049,6 +5077,29 @@ async function securityContextValidation(filesList) {
5049
5077
  }
5050
5078
  return errors;
5051
5079
  }
5080
+ async function clientContextValidation(filesList) {
5081
+ const errors = [];
5082
+ const nameSet = new Set();
5083
+ for (const [_, filePath] of filesList) {
5084
+ const fileContentRaw = await fs.readFile(filePath, "utf8");
5085
+ const cube = YAML.parse(fileContentRaw);
5086
+ cube.forEach((item) => {
5087
+ if (nameSet.has(item.name)) {
5088
+ errors.push(`${filePath}: client context with name "${item.name}" already exists`);
5089
+ }
5090
+ else {
5091
+ nameSet.add(item.name);
5092
+ }
5093
+ });
5094
+ const safeParse = clientContextSchema.safeParse(cube);
5095
+ if (!safeParse.success) {
5096
+ errorFormatter(safeParse.error.issues).forEach((error) => {
5097
+ errors.push(`${filePath}: ${error}`);
5098
+ });
5099
+ }
5100
+ }
5101
+ return errors;
5102
+ }
5052
5103
  var MeasureTypeEnum;
5053
5104
  (function (MeasureTypeEnum) {
5054
5105
  MeasureTypeEnum["string"] = "string";
@@ -5115,6 +5166,10 @@ const securityContextSchema = z.array(z.object({
5115
5166
  name: z.string(),
5116
5167
  securityContext: z.object({}), // can be any object
5117
5168
  }));
5169
+ const clientContextSchema = z.array(z.object({
5170
+ name: z.string(),
5171
+ clientContext: z.object({}), // can be any object
5172
+ }));
5118
5173
 
5119
5174
  var provideConfig = async () => {
5120
5175
  const configFilePath = `${process.cwd()}/embeddable.config.js`;
@@ -21289,6 +21344,7 @@ var build = async () => {
21289
21344
  await initLogger("build");
21290
21345
  const breadcrumbs = [];
21291
21346
  try {
21347
+ const startTime = process.hrtime();
21292
21348
  checkNodeVersion();
21293
21349
  breadcrumbs.push("checkNodeVersion");
21294
21350
  removeBuildSuccessFlag();
@@ -21308,6 +21364,8 @@ var build = async () => {
21308
21364
  // NOTE: likely this will be called inside the loop above if we decide to support clients with mixed frameworks simultaneously.
21309
21365
  breadcrumbs.push("generate");
21310
21366
  await generate(config, "sdk-react");
21367
+ // Calculating build time in seconds
21368
+ config.buildTime = process.hrtime(startTime);
21311
21369
  breadcrumbs.push("cleanup");
21312
21370
  await cleanup(config);
21313
21371
  await storeBuildSuccessFlag();
@@ -21454,8 +21512,10 @@ async function selectWorkspace(ora, ctx, token) {
21454
21512
  }
21455
21513
 
21456
21514
  const oraP$1 = import('ora');
21457
- // grab .cube.yml|js and .sc.yml|js files
21458
- const YAML_OR_JS_FILES = /^(.*)\.(cube|sc)\.(ya?ml|js)$/;
21515
+ // grab cube files
21516
+ const CUBE_FILES = /^(.*)\.cube\.(ya?ml|js)$/;
21517
+ // grab security context and client context files
21518
+ const PRESET_FILES = /^(.*)\.(sc|cc)\.ya?ml$/;
21459
21519
  let ora$1;
21460
21520
  var push = async () => {
21461
21521
  await initLogger("push");
@@ -21538,8 +21598,9 @@ async function verify(ctx) {
21538
21598
  }
21539
21599
  async function buildArchive(config) {
21540
21600
  const spinnerArchive = ora$1("Building...").start();
21541
- const filesList = await findFiles(config.client.modelsSrc || config.client.srcDir, YAML_OR_JS_FILES);
21542
- await archive(config, filesList);
21601
+ const cubeFilesList = await findFiles(config.client.modelsSrc || config.client.srcDir, CUBE_FILES);
21602
+ const contextFilesList = await findFiles(config.client.presetsSrc || config.client.srcDir, PRESET_FILES);
21603
+ await archive(config, [...cubeFilesList, ...contextFilesList]);
21543
21604
  return spinnerArchive.succeed("Bundling completed");
21544
21605
  }
21545
21606
  async function archive(ctx, yamlFiles, isDev = false) {
@@ -21718,7 +21779,7 @@ var dev = async () => {
21718
21779
  metaFileName: "embeddable-components-meta.js",
21719
21780
  editorsMetaFileName: "embeddable-editors-meta.js",
21720
21781
  });
21721
- await sendDataModelsAndSecurityContextsChanges(config);
21782
+ await sendDataModelsAndContextsChanges(config);
21722
21783
  for (const getPlugin of config.plugins) {
21723
21784
  const plugin = getPlugin();
21724
21785
  breadcrumbs.push("validate plugin");
@@ -21787,9 +21848,12 @@ const onBundleBuildEnd = async (ctx) => {
21787
21848
  }
21788
21849
  };
21789
21850
  const dataModelAndSecurityContextWatcher = (ctx) => {
21790
- const fsWatcher = chokidar.watch([path$1.resolve(ctx.client.modelsSrc, "**/*.{cube,sc}.{yaml,yml,js}")], chokidarWatchOptions);
21851
+ const fsWatcher = chokidar.watch([
21852
+ path$1.resolve(ctx.client.modelsSrc, "**/*.{cube}.{yaml,yml,js}"),
21853
+ path$1.resolve(ctx.client.presetsSrc, "**/*.{sc,cc}.{yaml,yml}"),
21854
+ ], chokidarWatchOptions);
21791
21855
  fsWatcher.on("all", async () => {
21792
- await sendDataModelsAndSecurityContextsChanges(ctx);
21856
+ await sendDataModelsAndContextsChanges(ctx);
21793
21857
  });
21794
21858
  return fsWatcher;
21795
21859
  };
@@ -21800,13 +21864,15 @@ const globalCssWatcher = (ctx) => {
21800
21864
  });
21801
21865
  return fsWatcher;
21802
21866
  };
21803
- const sendDataModelsAndSecurityContextsChanges = async (ctx) => {
21867
+ const sendDataModelsAndContextsChanges = async (ctx) => {
21804
21868
  sendMessage("dataModelsAndOrSecurityContextUpdateStart");
21805
21869
  const isValid = await validate(ctx, false);
21806
21870
  if (isValid) {
21807
21871
  const token = await getToken();
21808
21872
  const sending = ora("Synchronising data models and/or security contexts...").start();
21809
- const filesList = await findFiles(ctx.client.modelsSrc, YAML_OR_JS_FILES);
21873
+ const cubeFilesList = await findFiles(ctx.client.modelsSrc, CUBE_FILES);
21874
+ const contextFilesList = await findFiles(ctx.client.presetsSrc, PRESET_FILES);
21875
+ const filesList = [...cubeFilesList, ...contextFilesList];
21810
21876
  // add manifest to the archive
21811
21877
  filesList.push([
21812
21878
  "embeddable-manifest",
@@ -21869,7 +21935,7 @@ const getPreviewWorkspace = async (startedOra, ctx) => {
21869
21935
  }
21870
21936
  };
21871
21937
 
21872
- var defineConfig = ({ plugins, pushBaseUrl, audienceUrl, authDomain, authClientId, errorFallbackComponent, applicationEnvironment, rollbarAccessToken, previewBaseUrl, modelsSrc = "src", componentsSrc = "src", globalCss = "src/global.css", viteConfig = {}, rollupOptions = {}, }) => {
21938
+ var defineConfig = ({ plugins, pushBaseUrl, audienceUrl, authDomain, authClientId, errorFallbackComponent, applicationEnvironment, rollbarAccessToken, previewBaseUrl, modelsSrc = "src", presetsSrc = "src", componentsSrc = "src", globalCss = "src/global.css", viteConfig = {}, rollupOptions = {}, }) => {
21873
21939
  const coreRoot = path.resolve(__dirname, "..");
21874
21940
  const clientRoot = process.cwd();
21875
21941
  if (!path.isAbsolute(componentsSrc)) {
@@ -21884,6 +21950,12 @@ var defineConfig = ({ plugins, pushBaseUrl, audienceUrl, authDomain, authClientI
21884
21950
  throw new Error(`modelsSrc directory ${modelsSrc} does not exist`);
21885
21951
  }
21886
21952
  }
21953
+ if (presetsSrc && !path.isAbsolute(presetsSrc)) {
21954
+ presetsSrc = path.resolve(clientRoot, presetsSrc);
21955
+ if (!existsSync(presetsSrc)) {
21956
+ throw new Error(`presetsSrc directory ${presetsSrc} does not exist`);
21957
+ }
21958
+ }
21887
21959
  return {
21888
21960
  core: {
21889
21961
  rootDir: coreRoot,
@@ -21894,6 +21966,7 @@ var defineConfig = ({ plugins, pushBaseUrl, audienceUrl, authDomain, authClientI
21894
21966
  rootDir: clientRoot,
21895
21967
  srcDir: path.resolve(clientRoot, componentsSrc),
21896
21968
  modelsSrc: modelsSrc ? path.resolve(clientRoot, modelsSrc) : undefined,
21969
+ presetsSrc: presetsSrc ? path.resolve(clientRoot, presetsSrc) : undefined,
21897
21970
  buildDir: path.resolve(clientRoot, ".embeddable-build"),
21898
21971
  tmpDir: path.resolve(clientRoot, ".embeddable-tmp"),
21899
21972
  globalCss: path.resolve(clientRoot, globalCss),
@@ -21922,7 +21995,7 @@ var defineConfig = ({ plugins, pushBaseUrl, audienceUrl, authDomain, authClientI
21922
21995
  };
21923
21996
 
21924
21997
  var name = "@embeddable.com/sdk-core";
21925
- var version = "3.9.3";
21998
+ var version = "3.9.5";
21926
21999
  var description = "Core Embeddable SDK module responsible for web-components bundling and publishing.";
21927
22000
  var keywords = [
21928
22001
  "embeddable",