@embeddable.com/sdk-core 4.3.3 → 4.4.0-next.1
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/defineConfig.d.ts +10 -0
- package/lib/index.d.ts +1 -1
- package/lib/index.esm.js +44 -10
- package/lib/index.esm.js.map +1 -1
- package/lib/push.d.ts +1 -0
- package/package.json +1 -1
- package/src/defineConfig.test.ts +1 -0
- package/src/defineConfig.ts +10 -0
- package/src/dev.test.ts +149 -2
- package/src/dev.ts +28 -3
- package/src/generate.test.ts +65 -3
- package/src/generate.ts +5 -2
- package/src/index.ts +1 -1
- package/src/push.test.ts +163 -3
- package/src/push.ts +20 -2
- package/templates/component.tsx.template +13 -4
package/lib/defineConfig.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ export type EmbeddableConfig = {
|
|
|
12
12
|
})[];
|
|
13
13
|
pushModels?: boolean;
|
|
14
14
|
pushComponents?: boolean;
|
|
15
|
+
pushEmbeddables?: boolean;
|
|
15
16
|
pushBaseUrl?: string;
|
|
16
17
|
audienceUrl?: string;
|
|
17
18
|
authDomain?: string;
|
|
@@ -74,6 +75,7 @@ export type ResolvedEmbeddableConfig = {
|
|
|
74
75
|
};
|
|
75
76
|
pushModels: boolean;
|
|
76
77
|
pushComponents: boolean;
|
|
78
|
+
pushEmbeddables: boolean;
|
|
77
79
|
pushBaseUrl: string;
|
|
78
80
|
audienceUrl: string;
|
|
79
81
|
previewBaseUrl: string;
|
|
@@ -98,14 +100,19 @@ export type ResolvedEmbeddableConfig = {
|
|
|
98
100
|
buildName: string;
|
|
99
101
|
componentsEntryPointFilename: string;
|
|
100
102
|
};
|
|
103
|
+
pluginFlags?: PluginFlags;
|
|
101
104
|
};
|
|
102
105
|
};
|
|
106
|
+
export type PluginFlags = {
|
|
107
|
+
supportsOnComponentReadyHook: boolean;
|
|
108
|
+
};
|
|
103
109
|
export declare const embeddableConfigSchema: z.ZodObject<{
|
|
104
110
|
plugins: z.ZodArray<z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>, "many">;
|
|
105
111
|
region: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"EU">, z.ZodLiteral<"US">, z.ZodLiteral<"legacy-US">]>>;
|
|
106
112
|
starterEmbeddables: z.ZodOptional<z.ZodRecord<z.ZodEnum<["EU", "US", "legacy-US"]>, z.ZodArray<z.ZodString, "many">>>;
|
|
107
113
|
pushModels: z.ZodOptional<z.ZodBoolean>;
|
|
108
114
|
pushComponents: z.ZodOptional<z.ZodBoolean>;
|
|
115
|
+
pushEmbeddables: z.ZodOptional<z.ZodBoolean>;
|
|
109
116
|
pushBaseUrl: z.ZodOptional<z.ZodString>;
|
|
110
117
|
audienceUrl: z.ZodOptional<z.ZodString>;
|
|
111
118
|
authDomain: z.ZodOptional<z.ZodString>;
|
|
@@ -157,6 +164,7 @@ export declare const embeddableConfigSchema: z.ZodObject<{
|
|
|
157
164
|
starterEmbeddables?: Partial<Record<"EU" | "US" | "legacy-US", string[]>> | undefined;
|
|
158
165
|
pushModels?: boolean | undefined;
|
|
159
166
|
pushComponents?: boolean | undefined;
|
|
167
|
+
pushEmbeddables?: boolean | undefined;
|
|
160
168
|
pushBaseUrl?: string | undefined;
|
|
161
169
|
audienceUrl?: string | undefined;
|
|
162
170
|
authDomain?: string | undefined;
|
|
@@ -188,6 +196,7 @@ export declare const embeddableConfigSchema: z.ZodObject<{
|
|
|
188
196
|
starterEmbeddables?: Partial<Record<"EU" | "US" | "legacy-US", string[]>> | undefined;
|
|
189
197
|
pushModels?: boolean | undefined;
|
|
190
198
|
pushComponents?: boolean | undefined;
|
|
199
|
+
pushEmbeddables?: boolean | undefined;
|
|
191
200
|
pushBaseUrl?: string | undefined;
|
|
192
201
|
audienceUrl?: string | undefined;
|
|
193
202
|
authDomain?: string | undefined;
|
|
@@ -257,6 +266,7 @@ declare const _default: (config: EmbeddableConfig) => {
|
|
|
257
266
|
starterEmbeddables: Partial<Record<Region, string[]>> | undefined;
|
|
258
267
|
pushModels: boolean;
|
|
259
268
|
pushComponents: boolean;
|
|
269
|
+
pushEmbeddables: boolean;
|
|
260
270
|
pushBaseUrl: string;
|
|
261
271
|
audienceUrl: string;
|
|
262
272
|
previewBaseUrl: string;
|
package/lib/index.d.ts
CHANGED
|
@@ -4,4 +4,4 @@ export { default as push } from "./push";
|
|
|
4
4
|
export { default as dev } from "./dev";
|
|
5
5
|
export { default as defineConfig } from "./defineConfig";
|
|
6
6
|
export { default as buildPackage } from "./buildPackage";
|
|
7
|
-
export type { ResolvedEmbeddableConfig } from "./defineConfig";
|
|
7
|
+
export type { ResolvedEmbeddableConfig, PluginFlags } from "./defineConfig";
|
package/lib/index.esm.js
CHANGED
|
@@ -609,6 +609,7 @@ async function createComponentDir(dir) {
|
|
|
609
609
|
|
|
610
610
|
const STYLE_IMPORTS_TOKEN = "{{STYLES_IMPORT}}";
|
|
611
611
|
const RENDER_IMPORT_TOKEN = "{{RENDER_IMPORT}}";
|
|
612
|
+
const PLUGIN_FLAGS_TOKEN = "{{PLUGIN_FLAGS}}";
|
|
612
613
|
// stencil doesn't support dynamic component tag name, so we need to replace it manually
|
|
613
614
|
const COMPONENT_TAG_TOKEN = "replace-this-with-component-name";
|
|
614
615
|
let triggeredBuildCount = 0;
|
|
@@ -697,16 +698,18 @@ async function injectCSS(ctx, pluginName) {
|
|
|
697
698
|
await fs.writeFile(path$1.resolve(ctx.client.componentDir, "style.css"), content.replace(STYLE_IMPORTS_TOKEN, cssFilesImportsStr));
|
|
698
699
|
}
|
|
699
700
|
async function injectBundleRender(ctx, pluginName) {
|
|
700
|
-
var _a;
|
|
701
|
+
var _a, _b;
|
|
701
702
|
const importFilePath = path$1
|
|
702
703
|
.relative(ctx.client.componentDir, path$1.resolve(ctx.client.buildDir, ctx[pluginName].outputOptions.buildName))
|
|
703
704
|
.replaceAll("\\", "/");
|
|
704
705
|
const importStr = `import render from '${importFilePath}/${ctx[pluginName].outputOptions.fileName}';`;
|
|
706
|
+
const pluginFlags = (_a = ctx[pluginName].pluginFlags) !== null && _a !== void 0 ? _a : {};
|
|
707
|
+
const pluginFlagsStr = `const pluginFlags: Partial<PluginFlags> = ${JSON.stringify(pluginFlags)}`;
|
|
705
708
|
let content = await fs.readFile(path$1.resolve(ctx.core.templatesDir, "component.tsx.template"), "utf8");
|
|
706
|
-
if (!!((
|
|
709
|
+
if (!!((_b = ctx.dev) === null || _b === void 0 ? void 0 : _b.watch)) {
|
|
707
710
|
content = content.replace(COMPONENT_TAG_TOKEN, "embeddable-component");
|
|
708
711
|
}
|
|
709
|
-
await fs.writeFile(path$1.resolve(ctx.client.componentDir, "component.tsx"), content.replace(RENDER_IMPORT_TOKEN, importStr));
|
|
712
|
+
await fs.writeFile(path$1.resolve(ctx.client.componentDir, "component.tsx"), content.replace(RENDER_IMPORT_TOKEN, importStr).replace(PLUGIN_FLAGS_TOKEN, pluginFlagsStr));
|
|
710
713
|
}
|
|
711
714
|
async function injectEmptyCSS(ctx) {
|
|
712
715
|
await fs.writeFile(path$1.resolve(ctx.client.componentDir, "style.css"), "");
|
|
@@ -715,7 +718,7 @@ async function injectBundleRenderStub(ctx) {
|
|
|
715
718
|
const stubStr = `const render = (..._args: any[]) => {};`;
|
|
716
719
|
let content = await fs.readFile(path$1.resolve(ctx.core.templatesDir, "component.tsx.template"), "utf8");
|
|
717
720
|
content = content.replace(COMPONENT_TAG_TOKEN, "embeddable-component");
|
|
718
|
-
await fs.writeFile(path$1.resolve(ctx.client.componentDir, "component.tsx"), content.replace(RENDER_IMPORT_TOKEN, stubStr));
|
|
721
|
+
await fs.writeFile(path$1.resolve(ctx.client.componentDir, "component.tsx"), content.replace(RENDER_IMPORT_TOKEN, stubStr).replace(PLUGIN_FLAGS_TOKEN, "const pluginFlags: Partial<PluginFlags> = {}"));
|
|
719
722
|
}
|
|
720
723
|
async function addComponentTagName(filePath, bundleHash) {
|
|
721
724
|
// find entry file with a name *.entry.js
|
|
@@ -21447,6 +21450,7 @@ async function selectWorkspace(ora, ctx, token) {
|
|
|
21447
21450
|
const CUBE_FILES = /^(.*)\.cube\.(ya?ml|js)$/;
|
|
21448
21451
|
const CLIENT_CONTEXT_FILES = /^(.*)\.cc\.ya?ml$/;
|
|
21449
21452
|
const SECURITY_CONTEXT_FILES = /^(.*)\.sc\.ya?ml$/;
|
|
21453
|
+
const EMBEDDABLE_FILES = /^(.*)\.embeddable\.ya?ml$/;
|
|
21450
21454
|
var push = async () => {
|
|
21451
21455
|
var _a, _b, _c, _d, _f, _g;
|
|
21452
21456
|
await initLogger("push");
|
|
@@ -21512,6 +21516,7 @@ Read more about deployment regions at https://docs.embeddable.com/deployment/dep
|
|
|
21512
21516
|
const publishedSectionFeedback = (config, spinnerPushing) => {
|
|
21513
21517
|
config.pushModels && spinnerPushing.succeed("Models published");
|
|
21514
21518
|
config.pushComponents && spinnerPushing.succeed("Components published");
|
|
21519
|
+
config.pushEmbeddables && spinnerPushing.succeed("Embeddables published");
|
|
21515
21520
|
};
|
|
21516
21521
|
async function pushByApiKey(config, spinner, cubeVersion) {
|
|
21517
21522
|
const apiKey = getArgumentByKey(["--api-key", "-k"]);
|
|
@@ -21554,8 +21559,8 @@ async function verify(ctx) {
|
|
|
21554
21559
|
}
|
|
21555
21560
|
async function buildArchive(config) {
|
|
21556
21561
|
const spinnerArchive = ora("Building...").start();
|
|
21557
|
-
if (!config.pushModels && !config.pushComponents) {
|
|
21558
|
-
spinnerArchive.fail("Cannot push:
|
|
21562
|
+
if (!config.pushModels && !config.pushComponents && !config.pushEmbeddables) {
|
|
21563
|
+
spinnerArchive.fail("Cannot push: pushModels, pushComponents, and pushEmbeddables are all disabled");
|
|
21559
21564
|
process.exit(1);
|
|
21560
21565
|
}
|
|
21561
21566
|
const filesList = [];
|
|
@@ -21577,6 +21582,13 @@ async function buildArchive(config) {
|
|
|
21577
21582
|
entry[1],
|
|
21578
21583
|
]));
|
|
21579
21584
|
}
|
|
21585
|
+
if (config.pushEmbeddables) {
|
|
21586
|
+
const embeddableFilesList = await findFiles(config.client.srcDir, EMBEDDABLE_FILES);
|
|
21587
|
+
filesList.push(...embeddableFilesList.map((entry) => [
|
|
21588
|
+
path.basename(entry[1]),
|
|
21589
|
+
entry[1],
|
|
21590
|
+
]));
|
|
21591
|
+
}
|
|
21580
21592
|
await archive({
|
|
21581
21593
|
ctx: config,
|
|
21582
21594
|
filesList,
|
|
@@ -21632,6 +21644,7 @@ async function sendBuildByApiKey(ctx, { apiKey, email, message, cubeVersion, })
|
|
|
21632
21644
|
const form = await createFormData(ctx.client.archiveFile, {
|
|
21633
21645
|
pushModels: ctx.pushModels,
|
|
21634
21646
|
pushComponents: ctx.pushComponents,
|
|
21647
|
+
pushEmbeddables: ctx.pushEmbeddables,
|
|
21635
21648
|
starterEmbeddableIds: (_a = ctx.starterEmbeddables) === null || _a === void 0 ? void 0 : _a[ctx.region],
|
|
21636
21649
|
authorEmail: email,
|
|
21637
21650
|
description: message,
|
|
@@ -21647,6 +21660,7 @@ async function sendBuild(ctx, { workspaceId, token, message, cubeVersion, }) {
|
|
|
21647
21660
|
const form = await createFormData(ctx.client.archiveFile, {
|
|
21648
21661
|
pushModels: ctx.pushModels,
|
|
21649
21662
|
pushComponents: ctx.pushComponents,
|
|
21663
|
+
pushEmbeddables: ctx.pushEmbeddables,
|
|
21650
21664
|
starterEmbeddableIds: (_a = ctx.starterEmbeddables) === null || _a === void 0 ? void 0 : _a[ctx.region],
|
|
21651
21665
|
authorEmail: "",
|
|
21652
21666
|
description: message,
|
|
@@ -22111,6 +22125,13 @@ const cubeSecurityContextAndClientContextWatcher = async (ctx) => {
|
|
|
22111
22125
|
]);
|
|
22112
22126
|
filesToWatch = [...filesToWatch, ...cubeFiles, ...securityContextFiles];
|
|
22113
22127
|
}
|
|
22128
|
+
if (ctx.pushEmbeddables) {
|
|
22129
|
+
const embeddableFiles = await fg("**/*.embeddable.{yaml,yml}", {
|
|
22130
|
+
cwd: ctx.client.srcDir,
|
|
22131
|
+
absolute: true,
|
|
22132
|
+
});
|
|
22133
|
+
filesToWatch = [...filesToWatch, ...embeddableFiles];
|
|
22134
|
+
}
|
|
22114
22135
|
const fsWatcher = chokidar.watch(filesToWatch, chokidarWatchOptions);
|
|
22115
22136
|
fsWatcher.on("all", () => sendBuildChanges(ctx));
|
|
22116
22137
|
return fsWatcher;
|
|
@@ -22129,7 +22150,7 @@ const sendBuildChanges = async (ctx) => {
|
|
|
22129
22150
|
return sendMessage("dataModelsAndOrSecurityContextUpdateError");
|
|
22130
22151
|
}
|
|
22131
22152
|
sendMessage("dataModelsAndOrSecurityContextUpdateStart");
|
|
22132
|
-
const sending = ora("Synchronising data models and/or security contexts...").start();
|
|
22153
|
+
const sending = ora("Synchronising data models and/or security contexts and/or embeddables...").start();
|
|
22133
22154
|
let filesList = [];
|
|
22134
22155
|
if (ctx.pushComponents) {
|
|
22135
22156
|
const clientContextFilesList = await findFiles(ctx.client.presetsSrc, CLIENT_CONTEXT_FILES);
|
|
@@ -22154,6 +22175,16 @@ const sendBuildChanges = async (ctx) => {
|
|
|
22154
22175
|
].map((entry) => [path.basename(entry[1]), entry[1]]);
|
|
22155
22176
|
filesList = [...filesList, ...cubeAndSecurityContextFileList];
|
|
22156
22177
|
}
|
|
22178
|
+
if (ctx.pushEmbeddables) {
|
|
22179
|
+
const embeddableFilesList = await findFiles(ctx.client.srcDir, EMBEDDABLE_FILES);
|
|
22180
|
+
filesList = [
|
|
22181
|
+
...filesList,
|
|
22182
|
+
...embeddableFilesList.map((entry) => [
|
|
22183
|
+
path.basename(entry[1]),
|
|
22184
|
+
entry[1],
|
|
22185
|
+
]),
|
|
22186
|
+
];
|
|
22187
|
+
}
|
|
22157
22188
|
try {
|
|
22158
22189
|
const token = await getToken();
|
|
22159
22190
|
await archive({
|
|
@@ -22165,10 +22196,10 @@ const sendBuildChanges = async (ctx) => {
|
|
|
22165
22196
|
}
|
|
22166
22197
|
catch (e) {
|
|
22167
22198
|
const errorMessage = (_d = (_c = (_b = (_a = e.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.errorMessage) !== null && _c !== void 0 ? _c : e.message) !== null && _d !== void 0 ? _d : "Unknown error";
|
|
22168
|
-
sending.fail(`Data models and/or security context synchronization failed with error: ${errorMessage}`);
|
|
22199
|
+
sending.fail(`Data models and/or security context and/or embeddables synchronization failed with error: ${errorMessage}`);
|
|
22169
22200
|
return sendMessage("dataModelsAndOrSecurityContextUpdateError", { error: errorMessage });
|
|
22170
22201
|
}
|
|
22171
|
-
sending.succeed(`Data models and/or security context synchronized`);
|
|
22202
|
+
sending.succeed(`Data models and/or security context and/or embeddables synchronized`);
|
|
22172
22203
|
sendMessage("dataModelsAndOrSecurityContextUpdateSuccess");
|
|
22173
22204
|
};
|
|
22174
22205
|
const onClose = async (server, sys, watchers, config) => {
|
|
@@ -22206,6 +22237,7 @@ const getPreviewWorkspace = async (startedOra, ctx) => {
|
|
|
22206
22237
|
instanceUrl,
|
|
22207
22238
|
pushModels: ctx.pushModels,
|
|
22208
22239
|
pushComponents: ctx.pushComponents,
|
|
22240
|
+
pushEmbeddables: ctx.pushEmbeddables,
|
|
22209
22241
|
}, {
|
|
22210
22242
|
headers: {
|
|
22211
22243
|
Authorization: `Bearer ${token}`,
|
|
@@ -22297,6 +22329,7 @@ const embeddableConfigSchema = objectType({
|
|
|
22297
22329
|
starterEmbeddables: recordType(enumType(["EU", "US", "legacy-US"]), arrayType(stringType().uuid())).optional(),
|
|
22298
22330
|
pushModels: booleanType().optional(),
|
|
22299
22331
|
pushComponents: booleanType().optional(),
|
|
22332
|
+
pushEmbeddables: booleanType().optional(),
|
|
22300
22333
|
pushBaseUrl: stringType().optional(),
|
|
22301
22334
|
audienceUrl: stringType().optional(),
|
|
22302
22335
|
authDomain: stringType().optional(),
|
|
@@ -22334,7 +22367,7 @@ var defineConfig = (config) => {
|
|
|
22334
22367
|
if (errors.length > 0) {
|
|
22335
22368
|
throw new Error(`Invalid Embeddable Configuration: ${errors.join("\n")}}`);
|
|
22336
22369
|
}
|
|
22337
|
-
let { plugins, region = "legacy-US", pushModels = true, starterEmbeddables, pushComponents = true, pushBaseUrl, audienceUrl, authDomain, authClientId, errorFallbackComponent, applicationEnvironment, rollbarAccessToken, previewBaseUrl, modelsSrc = "src", presetsSrc = "src", componentsSrc = "src", customCanvasCss = "src/custom-canvas.css", viteConfig = {}, rollupOptions = {}, componentLibraries = [], customizationFile = "embeddable.theme.ts", lifecycleHooksFile = "lifecycle.config.ts", } = config;
|
|
22370
|
+
let { plugins, region = "legacy-US", pushModels = true, starterEmbeddables, pushComponents = true, pushEmbeddables = true, pushBaseUrl, audienceUrl, authDomain, authClientId, errorFallbackComponent, applicationEnvironment, rollbarAccessToken, previewBaseUrl, modelsSrc = "src", presetsSrc = "src", componentsSrc = "src", customCanvasCss = "src/custom-canvas.css", viteConfig = {}, rollupOptions = {}, componentLibraries = [], customizationFile = "embeddable.theme.ts", lifecycleHooksFile = "lifecycle.config.ts", } = config;
|
|
22338
22371
|
const regionConfig = REGION_CONFIGS[region];
|
|
22339
22372
|
const __dirname = import.meta.dirname;
|
|
22340
22373
|
const coreRoot = path$1.resolve(__dirname, "..");
|
|
@@ -22398,6 +22431,7 @@ var defineConfig = (config) => {
|
|
|
22398
22431
|
starterEmbeddables,
|
|
22399
22432
|
pushModels,
|
|
22400
22433
|
pushComponents,
|
|
22434
|
+
pushEmbeddables,
|
|
22401
22435
|
pushBaseUrl: pushBaseUrl !== null && pushBaseUrl !== void 0 ? pushBaseUrl : regionConfig.pushBaseUrl,
|
|
22402
22436
|
audienceUrl: audienceUrl !== null && audienceUrl !== void 0 ? audienceUrl : regionConfig.audienceUrl,
|
|
22403
22437
|
previewBaseUrl: previewBaseUrl !== null && previewBaseUrl !== void 0 ? previewBaseUrl : regionConfig.previewBaseUrl,
|