@embeddable.com/sdk-core 3.13.0-next.2 → 3.13.0-next.4

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.
@@ -1,4 +1,5 @@
1
1
  import { RollupOptions } from "rollup";
2
+ import { z } from "zod";
2
3
  export type Region = "EU" | "US" | "legacy-US";
3
4
  export type EmbeddableConfig = {
4
5
  plugins: (() => {
@@ -7,6 +8,8 @@ export type EmbeddableConfig = {
7
8
  cleanup: (config: EmbeddableConfig) => Promise<unknown>;
8
9
  validate: (config: EmbeddableConfig) => Promise<unknown>;
9
10
  })[];
11
+ pushModels?: boolean;
12
+ pushComponents?: boolean;
10
13
  pushBaseUrl?: string;
11
14
  audienceUrl?: string;
12
15
  authDomain?: string;
@@ -27,7 +30,129 @@ export type EmbeddableConfig = {
27
30
  rollupOptions?: RollupOptions;
28
31
  region?: Region;
29
32
  };
30
- declare const _default: ({ plugins, region, pushBaseUrl, audienceUrl, authDomain, authClientId, errorFallbackComponent, applicationEnvironment, rollbarAccessToken, previewBaseUrl, modelsSrc, presetsSrc, componentsSrc, globalCss, viteConfig, rollupOptions, }: EmbeddableConfig) => {
33
+ export type ResolvedEmbeddableConfig = {
34
+ core: {
35
+ rootDir: string;
36
+ templatesDir: string;
37
+ configsDir: string;
38
+ };
39
+ client: {
40
+ rootDir: string;
41
+ srcDir: string;
42
+ modelsSrc?: string;
43
+ presetsSrc?: string;
44
+ buildDir: string;
45
+ tmpDir: string;
46
+ globalCss: string;
47
+ componentDir: string;
48
+ stencilBuild: string;
49
+ archiveFile: string;
50
+ errorFallbackComponent?: string;
51
+ bundleHash?: string;
52
+ viteConfig: {
53
+ resolve?: {
54
+ alias?: Record<string, string>;
55
+ };
56
+ };
57
+ rollupOptions: RollupOptions;
58
+ };
59
+ outputOptions: {
60
+ typesEntryPointFilename: string;
61
+ };
62
+ pushModels: boolean;
63
+ pushComponents: boolean;
64
+ pushBaseUrl: string;
65
+ audienceUrl: string;
66
+ previewBaseUrl: string;
67
+ authDomain: string;
68
+ authClientId: string;
69
+ applicationEnvironment: string;
70
+ rollbarAccessToken: string;
71
+ plugins: EmbeddableConfig["plugins"];
72
+ };
73
+ export declare const embeddableConfigSchema: z.ZodObject<{
74
+ plugins: z.ZodArray<z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>, "many">;
75
+ region: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"EU">, z.ZodLiteral<"US">, z.ZodLiteral<"legacy-US">]>>;
76
+ pushModels: z.ZodOptional<z.ZodBoolean>;
77
+ pushComponents: z.ZodOptional<z.ZodBoolean>;
78
+ pushBaseUrl: z.ZodOptional<z.ZodString>;
79
+ audienceUrl: z.ZodOptional<z.ZodString>;
80
+ authDomain: z.ZodOptional<z.ZodString>;
81
+ authClientId: z.ZodOptional<z.ZodString>;
82
+ errorFallbackComponent: z.ZodOptional<z.ZodString>;
83
+ applicationEnvironment: z.ZodOptional<z.ZodString>;
84
+ rollbarAccessToken: z.ZodOptional<z.ZodString>;
85
+ previewBaseUrl: z.ZodOptional<z.ZodString>;
86
+ modelsSrc: z.ZodOptional<z.ZodString>;
87
+ presetsSrc: z.ZodOptional<z.ZodString>;
88
+ componentsSrc: z.ZodOptional<z.ZodString>;
89
+ globalCss: z.ZodOptional<z.ZodString>;
90
+ viteConfig: z.ZodOptional<z.ZodObject<{
91
+ resolve: z.ZodOptional<z.ZodObject<{
92
+ alias: z.ZodRecord<z.ZodString, z.ZodString>;
93
+ }, "strip", z.ZodTypeAny, {
94
+ alias: Record<string, string>;
95
+ }, {
96
+ alias: Record<string, string>;
97
+ }>>;
98
+ }, "strip", z.ZodTypeAny, {
99
+ resolve?: {
100
+ alias: Record<string, string>;
101
+ } | undefined;
102
+ }, {
103
+ resolve?: {
104
+ alias: Record<string, string>;
105
+ } | undefined;
106
+ }>>;
107
+ rollupOptions: z.ZodOptional<z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>>;
108
+ }, "strict", z.ZodTypeAny, {
109
+ plugins: ((...args: unknown[]) => unknown)[];
110
+ region?: "EU" | "US" | "legacy-US" | undefined;
111
+ pushModels?: boolean | undefined;
112
+ pushComponents?: boolean | undefined;
113
+ pushBaseUrl?: string | undefined;
114
+ audienceUrl?: string | undefined;
115
+ authDomain?: string | undefined;
116
+ authClientId?: string | undefined;
117
+ errorFallbackComponent?: string | undefined;
118
+ applicationEnvironment?: string | undefined;
119
+ rollbarAccessToken?: string | undefined;
120
+ previewBaseUrl?: string | undefined;
121
+ modelsSrc?: string | undefined;
122
+ presetsSrc?: string | undefined;
123
+ componentsSrc?: string | undefined;
124
+ globalCss?: string | undefined;
125
+ viteConfig?: {
126
+ resolve?: {
127
+ alias: Record<string, string>;
128
+ } | undefined;
129
+ } | undefined;
130
+ rollupOptions?: {} | undefined;
131
+ }, {
132
+ plugins: ((...args: unknown[]) => unknown)[];
133
+ region?: "EU" | "US" | "legacy-US" | undefined;
134
+ pushModels?: boolean | undefined;
135
+ pushComponents?: boolean | undefined;
136
+ pushBaseUrl?: string | undefined;
137
+ audienceUrl?: string | undefined;
138
+ authDomain?: string | undefined;
139
+ authClientId?: string | undefined;
140
+ errorFallbackComponent?: string | undefined;
141
+ applicationEnvironment?: string | undefined;
142
+ rollbarAccessToken?: string | undefined;
143
+ previewBaseUrl?: string | undefined;
144
+ modelsSrc?: string | undefined;
145
+ presetsSrc?: string | undefined;
146
+ componentsSrc?: string | undefined;
147
+ globalCss?: string | undefined;
148
+ viteConfig?: {
149
+ resolve?: {
150
+ alias: Record<string, string>;
151
+ } | undefined;
152
+ } | undefined;
153
+ rollupOptions?: {} | undefined;
154
+ }>;
155
+ declare const _default: (config: EmbeddableConfig) => {
31
156
  core: {
32
157
  rootDir: string;
33
158
  templatesDir: string;
@@ -56,6 +181,8 @@ declare const _default: ({ plugins, region, pushBaseUrl, audienceUrl, authDomain
56
181
  outputOptions: {
57
182
  typesEntryPointFilename: string;
58
183
  };
184
+ pushModels: boolean;
185
+ pushComponents: boolean;
59
186
  pushBaseUrl: string;
60
187
  audienceUrl: string;
61
188
  previewBaseUrl: string;
package/lib/index.esm.js CHANGED
@@ -21611,26 +21611,44 @@ async function verify(ctx) {
21611
21611
  }
21612
21612
  async function buildArchive(config) {
21613
21613
  const spinnerArchive = ora("Building...").start();
21614
- const cubeFilesList = await findFiles(config.client.modelsSrc || config.client.srcDir, CUBE_FILES);
21615
- const contextFilesList = await findFiles(config.client.presetsSrc || config.client.srcDir, PRESET_FILES);
21616
- // Map the files to include their full filenames
21617
- const filesList = [...cubeFilesList, ...contextFilesList].map((entry) => [path$1.basename(entry[1]), entry[1]]);
21618
- await archive(config, filesList);
21614
+ if (!config.pushModels && !config.pushComponents) {
21615
+ spinnerArchive.fail("Cannot push: both pushModels and pushComponents are disabled");
21616
+ process.exit(1);
21617
+ }
21618
+ const filesList = [];
21619
+ if (config.pushModels) {
21620
+ const cubeFilesList = await findFiles(config.client.modelsSrc || config.client.srcDir, CUBE_FILES);
21621
+ const contextFilesList = await findFiles(config.client.presetsSrc || config.client.srcDir, PRESET_FILES);
21622
+ filesList.push(...cubeFilesList.map((entry) => [
21623
+ path$1.basename(entry[1]),
21624
+ entry[1],
21625
+ ]), ...contextFilesList.map((entry) => [
21626
+ path$1.basename(entry[1]),
21627
+ entry[1],
21628
+ ]));
21629
+ }
21630
+ await archive({
21631
+ ctx: config,
21632
+ filesList,
21633
+ isDev: false,
21634
+ includeComponents: config.pushComponents,
21635
+ });
21619
21636
  return spinnerArchive.succeed("Bundling completed");
21620
21637
  }
21621
- async function archive(ctx, yamlFiles, isDev = false) {
21638
+ async function archive(args) {
21639
+ const { ctx, filesList, isDev, includeComponents } = args;
21622
21640
  const output = fs$1.createWriteStream(ctx.client.archiveFile);
21623
21641
  const archive = archiver.create("zip", {
21624
21642
  zlib: { level: 9 },
21625
21643
  });
21626
21644
  archive.pipe(output);
21627
- if (!isDev) {
21645
+ if (!isDev && includeComponents) {
21628
21646
  archive.directory(ctx.client.buildDir, false);
21629
21647
  archive.file(ctx.client.globalCss, {
21630
21648
  name: "global.css",
21631
21649
  });
21632
21650
  }
21633
- for (const fileData of yamlFiles) {
21651
+ for (const fileData of filesList) {
21634
21652
  archive.file(fileData[1], {
21635
21653
  name: fileData[0],
21636
21654
  });
@@ -21640,7 +21658,7 @@ async function archive(ctx, yamlFiles, isDev = false) {
21640
21658
  output.on("close", resolve);
21641
21659
  });
21642
21660
  }
21643
- async function sendBuildByApiKey(ctx, { apiKey, email, message }) {
21661
+ async function sendBuildByApiKey(ctx, { apiKey, email, message, }) {
21644
21662
  var _a;
21645
21663
  const { FormData, Blob } = await import('formdata-node');
21646
21664
  const { fileFromPath } = await Promise.resolve().then(function () { return fileFromPath$1; });
@@ -21901,7 +21919,12 @@ const sendDataModelsAndContextsChanges = async (ctx) => {
21901
21919
  "embeddable-manifest.json",
21902
21920
  path$1.resolve(ctx.client.buildDir, "embeddable-manifest.json"),
21903
21921
  ]);
21904
- await archive(ctx, filesList, true);
21922
+ await archive({
21923
+ ctx,
21924
+ filesList,
21925
+ isDev: true,
21926
+ includeComponents: false,
21927
+ });
21905
21928
  await sendBuild(ctx, { workspaceId: previewWorkspace, token });
21906
21929
  sending.succeed(`Data models and/or security context synchronized`);
21907
21930
  sendMessage("dataModelsAndOrSecurityContextUpdateSuccess");
@@ -21985,10 +22008,50 @@ const REGION_CONFIGS = {
21985
22008
  authClientId: "dygrSUmI6HmgY5ymVbEAoLDEBxIOyr1V",
21986
22009
  },
21987
22010
  };
21988
- var defineConfig = ({ plugins, region = "legacy-US", pushBaseUrl, audienceUrl, authDomain, authClientId, errorFallbackComponent, applicationEnvironment, rollbarAccessToken, previewBaseUrl, modelsSrc = "src", presetsSrc = "src", componentsSrc = "src", globalCss = "src/global.css", viteConfig = {}, rollupOptions = {}, }) => {
21989
- if (region && !REGION_CONFIGS[region]) {
21990
- throw new Error(`Unsupported region: ${region}. Supported regions are: ${Object.keys(REGION_CONFIGS).join(", ")}`);
22011
+ const embeddableConfigSchema = z
22012
+ .object({
22013
+ plugins: z.array(z.function()),
22014
+ region: z
22015
+ .union([z.literal("EU"), z.literal("US"), z.literal("legacy-US")])
22016
+ .optional(),
22017
+ pushModels: z.boolean().optional(),
22018
+ pushComponents: z.boolean().optional(),
22019
+ pushBaseUrl: z.string().optional(),
22020
+ audienceUrl: z.string().optional(),
22021
+ authDomain: z.string().optional(),
22022
+ authClientId: z.string().optional(),
22023
+ errorFallbackComponent: z.string().optional(),
22024
+ applicationEnvironment: z.string().optional(),
22025
+ rollbarAccessToken: z.string().optional(),
22026
+ previewBaseUrl: z.string().optional(),
22027
+ modelsSrc: z.string().optional(),
22028
+ presetsSrc: z.string().optional(),
22029
+ componentsSrc: z.string().optional(),
22030
+ globalCss: z.string().optional(),
22031
+ viteConfig: z
22032
+ .object({
22033
+ resolve: z
22034
+ .object({
22035
+ alias: z.record(z.string()),
22036
+ })
22037
+ .optional(),
22038
+ })
22039
+ .optional(),
22040
+ rollupOptions: z.object({}).optional(),
22041
+ })
22042
+ .strict();
22043
+ var defineConfig = (config) => {
22044
+ const safeParse = embeddableConfigSchema.safeParse(config);
22045
+ const errors = [];
22046
+ if (!safeParse.success) {
22047
+ errorFormatter(safeParse.error.issues).forEach((error) => {
22048
+ errors.push(`${error}`);
22049
+ });
22050
+ }
22051
+ if (errors.length > 0) {
22052
+ throw new Error(`Invalid Embeddable Configuration: ${errors.join("\n")}}`);
21991
22053
  }
22054
+ let { plugins, region = "legacy-US", pushModels = true, pushComponents = true, pushBaseUrl, audienceUrl, authDomain, authClientId, errorFallbackComponent, applicationEnvironment, rollbarAccessToken, previewBaseUrl, modelsSrc = "src", presetsSrc = "src", componentsSrc = "src", globalCss = "src/global.css", viteConfig = {}, rollupOptions = {}, } = config;
21992
22055
  const regionConfig = REGION_CONFIGS[region];
21993
22056
  const __dirname = import.meta.dirname;
21994
22057
  const coreRoot = path.resolve(__dirname, "..");
@@ -22038,6 +22101,8 @@ var defineConfig = ({ plugins, region = "legacy-US", pushBaseUrl, audienceUrl, a
22038
22101
  outputOptions: {
22039
22102
  typesEntryPointFilename: "embeddable-types-entry-point.js",
22040
22103
  },
22104
+ pushModels,
22105
+ pushComponents,
22041
22106
  pushBaseUrl: pushBaseUrl !== null && pushBaseUrl !== undefined ? pushBaseUrl : regionConfig.pushBaseUrl,
22042
22107
  audienceUrl: audienceUrl !== null && audienceUrl !== undefined ? audienceUrl : regionConfig.audienceUrl,
22043
22108
  previewBaseUrl: previewBaseUrl !== null && previewBaseUrl !== undefined ? previewBaseUrl : regionConfig.previewBaseUrl,