@embeddable.com/sdk-core 2.4.18 → 2.4.20

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
@@ -4496,6 +4496,7 @@ var z = /*#__PURE__*/Object.freeze({
4496
4496
  });
4497
4497
 
4498
4498
  const CUBE_YAML_FILE_REGEX = /^(.*)\.cube\.ya?ml$/;
4499
+ const SECURITY_CONTEXT_FILE_REGEX = /^(.*)\.sc\.ya?ml$/;
4499
4500
  const checkNodeVersion$1 = () => {
4500
4501
  const [major, minor] = process.versions.node.split(".").map(Number);
4501
4502
  const engines = require("../package.json").engines.node;
@@ -4509,6 +4510,7 @@ var validate = async (ctx, exitIfInvalid = true) => {
4509
4510
  const ora = (await import('ora')).default;
4510
4511
  const spinnerValidate = ora("data model validation...").start();
4511
4512
  const filesList = await findFiles(ctx.client.srcDir, CUBE_YAML_FILE_REGEX);
4513
+ const securityContextFilesList = await findFiles(ctx.client.srcDir, SECURITY_CONTEXT_FILE_REGEX);
4512
4514
  const dataModelErrors = await dataModelsValidation(filesList);
4513
4515
  if (dataModelErrors.length) {
4514
4516
  spinnerValidate.fail("One or more cube.yaml files are invalid:");
@@ -4518,7 +4520,15 @@ var validate = async (ctx, exitIfInvalid = true) => {
4518
4520
  }
4519
4521
  }
4520
4522
  spinnerValidate.succeed("data model validation completed");
4521
- return dataModelErrors.length === 0;
4523
+ const securityContextErrors = await securityContextValidation(securityContextFilesList);
4524
+ if (securityContextErrors.length) {
4525
+ spinnerValidate.fail("One or more security context files are invalid:");
4526
+ securityContextErrors.forEach((errorMessage) => spinnerValidate.info(errorMessage));
4527
+ if (exitIfInvalid) {
4528
+ process.exit(1);
4529
+ }
4530
+ }
4531
+ return dataModelErrors.length === 0 && securityContextErrors.length === 0;
4522
4532
  };
4523
4533
  async function dataModelsValidation(filesList) {
4524
4534
  const errors = [];
@@ -4534,6 +4544,20 @@ async function dataModelsValidation(filesList) {
4534
4544
  }
4535
4545
  return errors;
4536
4546
  }
4547
+ async function securityContextValidation(filesList) {
4548
+ const errors = [];
4549
+ for (const [_, filePath] of filesList) {
4550
+ const fileContentRaw = await fs$1.readFile(filePath, "utf8");
4551
+ const cube = YAML.parse(fileContentRaw);
4552
+ const safeParse = securityContextSchema.safeParse(cube);
4553
+ if (!safeParse.success) {
4554
+ errorFormatter(safeParse.error.issues).forEach((error) => {
4555
+ errors.push(`${filePath}: ${error}`);
4556
+ });
4557
+ }
4558
+ }
4559
+ return errors;
4560
+ }
4537
4561
  const cubeModelSchema = z
4538
4562
  .object({
4539
4563
  cubes: z
@@ -4561,6 +4585,10 @@ const cubeModelSchema = z
4561
4585
  message: "At least one measure or dimension must be defined",
4562
4586
  path: ["cubes"],
4563
4587
  });
4588
+ const securityContextSchema = z.array(z.object({
4589
+ name: z.string(),
4590
+ securityContext: z.object({}), // can be any object
4591
+ }));
4564
4592
 
4565
4593
  var provideConfig = async () => {
4566
4594
  const configFilePath = `${process.cwd()}/embeddable.config.js`;
@@ -20011,7 +20039,8 @@ async function resolveFiles() {
20011
20039
 
20012
20040
  const oraP$1 = import('ora');
20013
20041
  const inquirerSelect = import('@inquirer/select');
20014
- const CUBE_YAML_OR_JS_FILE_REGEX = /^(.*)\.cube\.(ya?ml|js)$/;
20042
+ // grab .cube.yml|js and .sc.yml|js files
20043
+ const YAML_OR_JS_FILES = /^(.*)\.(cube|sc)\.(ya?ml|js)$/;
20015
20044
  let ora$1;
20016
20045
  var push = async () => {
20017
20046
  try {
@@ -20021,7 +20050,7 @@ var push = async () => {
20021
20050
  const token = await verify(config);
20022
20051
  const { workspaceId, name: workspaceName } = await selectWorkspace(config, token);
20023
20052
  const spinnerArchive = ora$1("archivation...").start();
20024
- const filesList = await findFiles(config.client.srcDir, CUBE_YAML_OR_JS_FILE_REGEX);
20053
+ const filesList = await findFiles(config.client.srcDir, YAML_OR_JS_FILES);
20025
20054
  await archive(config, filesList);
20026
20055
  spinnerArchive.succeed("archivation competed");
20027
20056
  const spinnerPushing = ora$1(`publishing to ${workspaceName} using ${config.pushBaseUrl}...`).start();
@@ -20089,9 +20118,9 @@ async function archive(ctx, yamlFiles, includeBuild = true) {
20089
20118
  _archiver.directory(ctx.client.buildDir, false);
20090
20119
  }
20091
20120
  for (const fileData of yamlFiles) {
20092
- const fileExtension = fileData[1].split(".").pop();
20121
+ const fileName = fileData[1].split("/").pop();
20093
20122
  _archiver.file(fileData[1], {
20094
- name: `${fileData[0]}.cube.${fileExtension}`,
20123
+ name: fileName,
20095
20124
  });
20096
20125
  }
20097
20126
  await _archiver.finalize();
@@ -20237,7 +20266,7 @@ const onBundleBuildEnd = async (ctx) => {
20237
20266
  }
20238
20267
  };
20239
20268
  const dataModelWatcher = (ctx) => {
20240
- const fsWatcher = chokidar.watch([path$2.resolve(ctx.client.srcDir, "**/*.cube.{yaml,yml}")], {
20269
+ const fsWatcher = chokidar.watch([path$2.resolve(ctx.client.srcDir, "**/*.cube.{yaml,yml,js}")], {
20241
20270
  ignoreInitial: true,
20242
20271
  });
20243
20272
  fsWatcher.on("all", async () => {
@@ -20251,7 +20280,7 @@ const sendDataModels = async (ctx) => {
20251
20280
  if (isValid) {
20252
20281
  const token = await getToken();
20253
20282
  const sending = ora("synchronising data models...").start();
20254
- const filesList = await findFiles(ctx.client.srcDir, CUBE_YAML_OR_JS_FILE_REGEX);
20283
+ const filesList = await findFiles(ctx.client.srcDir, YAML_OR_JS_FILES);
20255
20284
  await archive(ctx, filesList, false);
20256
20285
  await sendBuild(ctx, { workspaceId: previewWorkspace, token });
20257
20286
  sending.succeed(`data models synchronized`);