kenobi-js 0.1.37 → 0.1.39

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/browser/dist.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Kenobi SDK v0.1.35
2
+ * Kenobi SDK v0.1.38
3
3
  * (c) 2025 Kenobi.ai
4
4
  */
5
5
  "use strict";
@@ -2398,6 +2398,11 @@ var KenobiLib = (() => {
2398
2398
  };
2399
2399
  __name(_TransitionOrchestrator, "TransitionOrchestrator");
2400
2400
  var TransitionOrchestrator = _TransitionOrchestrator;
2401
+ var isCueCardConfigResponse = /* @__PURE__ */ __name((value) => {
2402
+ if (typeof value !== "object" || value === null) return false;
2403
+ const candidate = value;
2404
+ return typeof candidate.enabled === "boolean";
2405
+ }, "isCueCardConfigResponse");
2401
2406
  var TRANSFORMATION_ACTIONS = /* @__PURE__ */ new Set(["Replace", "InsertBefore", "InsertAfter", "Delete", "SetFormField"]);
2402
2407
  var isString = /* @__PURE__ */ __name((value) => typeof value === "string", "isString");
2403
2408
  var isStringArray = /* @__PURE__ */ __name((value) => Array.isArray(value) && value.every((item) => isString(item)), "isStringArray");
@@ -2568,16 +2573,11 @@ var KenobiLib = (() => {
2568
2573
  __publicField(this, "formatThousands", /* @__PURE__ */ __name((number) => new Intl.NumberFormat("en-US").format(number), "formatThousands"));
2569
2574
  __publicField(this, "setDebug", /* @__PURE__ */ __name((value) => this.config.debug = value, "setDebug"));
2570
2575
  /**
2571
- * Checks if a path matches a pattern.
2572
- * Supports exact matches ("/pricing") and wildcard suffixes ("/blog/*").
2576
+ * Checks if a path matches a pattern (exact match only).
2573
2577
  */
2574
2578
  __publicField(this, "matchesPathPattern", /* @__PURE__ */ __name((path, pattern) => {
2575
2579
  const normalizedPath = path === "/" ? "/" : path.replace(/\/$/, "");
2576
2580
  const normalizedPattern = pattern === "/" ? "/" : pattern.replace(/\/$/, "");
2577
- if (normalizedPattern.endsWith("/*")) {
2578
- const base = normalizedPattern.slice(0, -2);
2579
- return normalizedPath === base || normalizedPath.startsWith(base + "/");
2580
- }
2581
2581
  return normalizedPath === normalizedPattern;
2582
2582
  }, "matchesPathPattern"));
2583
2583
  /**
@@ -3056,13 +3056,48 @@ var KenobiLib = (() => {
3056
3056
  ----
3057
3057
  */
3058
3058
  /**
3059
- * Initializes and mounts a CueCard with default configuration.
3059
+ * Fetches the CueCard configuration from the API to check if an active
3060
+ * template exists for the given path.
3061
+ *
3062
+ * @param pagePath - The page path to check for active template
3063
+ * @returns The config response, or null if the request failed
3064
+ */
3065
+ __publicField(this, "fetchCueCardConfig", /* @__PURE__ */ __name(async (pagePath) => {
3066
+ if (!this.config.publicKey) return null;
3067
+ try {
3068
+ const searchParams = new URLSearchParams({
3069
+ publicKey: this.config.publicKey,
3070
+ pagePath
3071
+ });
3072
+ const response = await fetch(
3073
+ `${this.config.apiHost}/v1/cue-card-config?${searchParams.toString()}`
3074
+ );
3075
+ if (!response.ok) {
3076
+ this.log(
3077
+ "warn",
3078
+ `CueCard config request failed with status ${response.status}`
3079
+ );
3080
+ return null;
3081
+ }
3082
+ const data = await response.json();
3083
+ if (!isCueCardConfigResponse(data)) {
3084
+ this.log("warn", "Invalid CueCard config response format");
3085
+ return null;
3086
+ }
3087
+ return data;
3088
+ } catch (error) {
3089
+ this.log("error", "Failed to fetch CueCard config:", error);
3090
+ return null;
3091
+ }
3092
+ }, "fetchCueCardConfig"));
3093
+ /**
3094
+ * Initializes and mounts a CueCard with configuration from the API.
3060
3095
  * Called automatically when publicKey is provided.
3061
3096
  *
3062
- * Default config matches the template editor settings.
3063
- * Future: This config will be fetched per-org from the database.
3097
+ * The CueCard will only be mounted if an active template exists for
3098
+ * the current path on the server.
3064
3099
  */
3065
- __publicField(this, "initCueCard", /* @__PURE__ */ __name(() => {
3100
+ __publicField(this, "initCueCard", /* @__PURE__ */ __name(async () => {
3066
3101
  if (this.cueCardInstance) {
3067
3102
  this.log("warn", "CueCard already initialized, skipping...");
3068
3103
  return;
@@ -3074,10 +3109,21 @@ var KenobiLib = (() => {
3074
3109
  );
3075
3110
  return;
3076
3111
  }
3112
+ const configResponse = await this.fetchCueCardConfig(this.currentPath);
3113
+ if (!configResponse || !configResponse.enabled) {
3114
+ this.log(
3115
+ "debug",
3116
+ `CueCard not mounted: no active template for path "${this.currentPath}"`
3117
+ );
3118
+ return;
3119
+ }
3120
+ this.log("debug", "Active template found, mounting CueCard...");
3121
+ const serverConfig = configResponse.config;
3077
3122
  this.cueCardInstance = new CueCard({
3078
- theme: "light",
3079
- position: "top-center",
3080
- fields: [
3123
+ theme: serverConfig?.theme ?? "light",
3124
+ position: serverConfig?.position ?? "top-center",
3125
+ direction: serverConfig?.direction ?? "top-to-bottom",
3126
+ fields: serverConfig?.fields ?? [
3081
3127
  {
3082
3128
  name: "companyDomain",
3083
3129
  label: "Company Name or Domain",
@@ -3088,10 +3134,12 @@ var KenobiLib = (() => {
3088
3134
  }
3089
3135
  ],
3090
3136
  isVisible: true,
3091
- enableFocusMode: false,
3092
- showWatermark: false,
3093
- showKeyboardHints: true,
3094
- enableLauncher: true,
3137
+ enableFocusMode: serverConfig?.enableFocusMode ?? false,
3138
+ showWatermark: serverConfig?.showWatermark ?? false,
3139
+ showKeyboardHints: serverConfig?.showKeyboardHints ?? true,
3140
+ enableLauncher: serverConfig?.enableLauncher ?? true,
3141
+ customTheme: serverConfig?.customTheme,
3142
+ textOverrides: serverConfig?.textOverrides,
3095
3143
  onDismiss: /* @__PURE__ */ __name(() => {
3096
3144
  this.log("debug", "CueCard dismissed by user");
3097
3145
  }, "onDismiss"),
@@ -3108,7 +3156,7 @@ var KenobiLib = (() => {
3108
3156
  }, "initCueCard"));
3109
3157
  /**
3110
3158
  * Syncs CueCard visibility based on the current path.
3111
- * Mounts CueCard if on an allowed path, unmounts if not.
3159
+ * Mounts CueCard if on an allowed path and active template exists, unmounts if not.
3112
3160
  * Called after navigation changes.
3113
3161
  */
3114
3162
  __publicField(this, "syncCueCardVisibility", /* @__PURE__ */ __name(() => {
@@ -3117,9 +3165,9 @@ var KenobiLib = (() => {
3117
3165
  if (isAllowed && !this.cueCardInstance) {
3118
3166
  this.log(
3119
3167
  "debug",
3120
- `Navigated to allowed path "${this.currentPath}", mounting CueCard`
3168
+ `Navigated to allowed path "${this.currentPath}", checking for active template...`
3121
3169
  );
3122
- this.initCueCard();
3170
+ void this.initCueCard();
3123
3171
  } else if (!isAllowed && this.cueCardInstance) {
3124
3172
  this.log(
3125
3173
  "debug",
@@ -3226,8 +3274,8 @@ var KenobiLib = (() => {
3226
3274
  void this.startAutoTransform();
3227
3275
  }
3228
3276
  if (this.config.publicKey) {
3229
- this.log("debug", "Public key provided, auto-mounting CueCard...");
3230
- this.initCueCard();
3277
+ this.log("debug", "Public key provided, checking for active template...");
3278
+ void this.initCueCard();
3231
3279
  }
3232
3280
  }
3233
3281
  };