veo-sdk 0.2.0 → 0.3.0

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/dist/index.d.cts CHANGED
@@ -33,8 +33,6 @@ interface VeoAutocaptureConfig {
33
33
  interface VeoConfig {
34
34
  /** API key pública del workspace (formato pk_xxx). */
35
35
  apiKey: string;
36
- /** URL base del backend de Veo. */
37
- apiUrl: string;
38
36
  /** Intervalo en ms para flush automático de la queue. Default: 5000. */
39
37
  flushInterval?: number;
40
38
  /** Tamaño máximo del batch antes de flush. Default: 20. */
@@ -243,10 +241,8 @@ declare function spaRouterPlugin(): VeoPlugin;
243
241
  * ```ts
244
242
  * import { init } from '@veo/sdk';
245
243
  *
246
- * const veo = init({
247
- * apiKey: 'pk_xxx',
248
- * apiUrl: 'https://api.veo.io'
249
- * });
244
+ * // apiUrl es opcional: por defecto apunta al backend gestionado de Veo.
245
+ * const veo = init({ apiKey: 'pk_xxx' });
250
246
  *
251
247
  * veo.identify({ visitor: { id: 'user_123' } });
252
248
  * veo.track('button_clicked');
package/dist/index.d.ts CHANGED
@@ -33,8 +33,6 @@ interface VeoAutocaptureConfig {
33
33
  interface VeoConfig {
34
34
  /** API key pública del workspace (formato pk_xxx). */
35
35
  apiKey: string;
36
- /** URL base del backend de Veo. */
37
- apiUrl: string;
38
36
  /** Intervalo en ms para flush automático de la queue. Default: 5000. */
39
37
  flushInterval?: number;
40
38
  /** Tamaño máximo del batch antes de flush. Default: 20. */
@@ -243,10 +241,8 @@ declare function spaRouterPlugin(): VeoPlugin;
243
241
  * ```ts
244
242
  * import { init } from '@veo/sdk';
245
243
  *
246
- * const veo = init({
247
- * apiKey: 'pk_xxx',
248
- * apiUrl: 'https://api.veo.io'
249
- * });
244
+ * // apiUrl es opcional: por defecto apunta al backend gestionado de Veo.
245
+ * const veo = init({ apiKey: 'pk_xxx' });
250
246
  *
251
247
  * veo.identify({ visitor: { id: 'user_123' } });
252
248
  * veo.track('button_clicked');
package/dist/index.mjs CHANGED
@@ -1,25 +1,28 @@
1
- import { definePlugin, hasWindow, hasDocument, uuidv7, DEFAULT_AUTOCAPTURE_CONFIG, MAX_ANCESTORS, hasLocalStorage, hasNavigatorSendBeacon, ALWAYS_BLOCK_SELECTORS, buildSelectorPath, filterHumanClasses, PRIORITY_ATTRIBUTES, SENSITIVE_ATTRIBUTES, guidesPlugin, runPreviewMode, previewGuide, closeGuidePreview } from './chunk-BBAA5BRS.mjs';
2
- export { closeGuidePreview, definePlugin, guidesPlugin, previewGuide } from './chunk-BBAA5BRS.mjs';
1
+ import { definePlugin, guidesPlugin, runPreviewMode } from './chunk-G5CKTGEG.mjs';
2
+ export { definePlugin, guidesPlugin } from './chunk-G5CKTGEG.mjs';
3
+ import { hasWindow, hasDocument, uuidv7, DEFAULT_AUTOCAPTURE_CONFIG, MAX_ANCESTORS, hasLocalStorage, hasNavigatorSendBeacon, ALWAYS_BLOCK_SELECTORS, buildSelectorPath, resolveBuilderToken, filterHumanClasses, PRIORITY_ATTRIBUTES, SENSITIVE_ATTRIBUTES, isBuilderMode, previewGuide, closeGuidePreview } from './chunk-CI7NWEH2.mjs';
4
+ export { closeGuidePreview, previewGuide } from './chunk-CI7NWEH2.mjs';
5
+ import './chunk-JIU5JLI3.mjs';
3
6
 
4
- // src/core/builder-loader.ts
5
- var BUILDER_TOKEN_PARAM = "veoBuilder";
6
- function isBuilderMode() {
7
- if (!hasWindow()) return false;
8
- try {
9
- return new URLSearchParams(window.location.search).has(BUILDER_TOKEN_PARAM);
10
- } catch {
11
- return false;
12
- }
7
+ // src/contract/v1.ts
8
+ var SDK_VERSION = "0.0.1";
9
+ var DEFAULT_FLUSH_INTERVAL_MS = 5e3;
10
+ var DEFAULT_FLUSH_BATCH_SIZE = 20;
11
+ var DEFAULT_API_URL = "https://veo-backend-production-8c78.up.railway.app";
12
+
13
+ // src/core/api-url.ts
14
+ function resolveApiUrl(config) {
15
+ const fromConfig = config?.apiUrl;
16
+ if (typeof fromConfig === "string" && fromConfig.trim()) return fromConfig;
17
+ const fromGlobal = globalThis.__VEO_API_URL__;
18
+ if (typeof fromGlobal === "string" && fromGlobal.trim()) return fromGlobal;
19
+ return DEFAULT_API_URL;
13
20
  }
21
+
22
+ // src/core/builder-loader.ts
14
23
  function maybeLoadBuilder(opts) {
15
24
  if (!hasWindow() || !hasDocument()) return;
16
- let params;
17
- try {
18
- params = new URLSearchParams(window.location.search);
19
- } catch {
20
- return;
21
- }
22
- if (!params.has(BUILDER_TOKEN_PARAM)) return;
25
+ if (resolveBuilderToken() === null) return;
23
26
  if (opts.apiKey && opts.apiUrl) {
24
27
  window.__veoBuilder = {
25
28
  apiKey: opts.apiKey,
@@ -28,20 +31,26 @@ function maybeLoadBuilder(opts) {
28
31
  }
29
32
  if (window.veoBuilder) return;
30
33
  const url = opts.builderUrl ?? deriveBuilderUrl();
31
- if (!url) {
34
+ if (url) {
35
+ if (document.querySelector(`script[src="${url}"]`)) return;
36
+ const script = document.createElement("script");
37
+ script.src = url;
38
+ script.async = true;
32
39
  if (opts.debug) {
33
- console.warn("[veo] builder mode pedido pero no pude resolver la URL de veo-builder.js");
40
+ script.addEventListener("error", () => console.error("[veo] no pude cargar", url));
34
41
  }
42
+ document.head.appendChild(script);
43
+ return;
44
+ }
45
+ if (opts.loadBuilder) {
46
+ void opts.loadBuilder().catch((err) => {
47
+ if (opts.debug) console.error("[veo] no pude cargar el builder (import din\xE1mico)", err);
48
+ });
35
49
  return;
36
50
  }
37
- if (document.querySelector(`script[src="${url}"]`)) return;
38
- const script = document.createElement("script");
39
- script.src = url;
40
- script.async = true;
41
51
  if (opts.debug) {
42
- script.addEventListener("error", () => console.error("[veo] no pude cargar", url));
52
+ console.warn("[veo] builder mode pedido pero no pude resolver la URL de veo-builder.js");
43
53
  }
44
- document.head.appendChild(script);
45
54
  }
46
55
  function deriveBuilderUrl() {
47
56
  const scripts = document.querySelectorAll("script[src]");
@@ -294,11 +303,6 @@ function spaRouterPlugin() {
294
303
  });
295
304
  }
296
305
 
297
- // src/contract/v1.ts
298
- var SDK_VERSION = "0.0.1";
299
- var DEFAULT_FLUSH_INTERVAL_MS = 5e3;
300
- var DEFAULT_FLUSH_BATCH_SIZE = 20;
301
-
302
306
  // src/core/queue.ts
303
307
  var RETRY_MAX_DELAY_MS = 3e4;
304
308
  var Queue = class {
@@ -606,12 +610,11 @@ var Client = class {
606
610
  identify: /* @__PURE__ */ new Set()
607
611
  };
608
612
  if (!config.apiKey) throw new Error("apiKey is required");
609
- if (!config.apiUrl) throw new Error("apiUrl is required");
610
613
  this.storage = createStorage(config.storage ?? "localStorage");
611
614
  this.session = new Session(this.storage);
612
615
  this.transport = new Transport({
613
616
  apiKey: config.apiKey,
614
- apiUrl: config.apiUrl.replace(/\/$/, ""),
617
+ apiUrl: resolveApiUrl(config).replace(/\/$/, ""),
615
618
  sdkVersion: SDK_VERSION
616
619
  });
617
620
  this.queue = new Queue({
@@ -787,7 +790,7 @@ var Client = class {
787
790
  };
788
791
 
789
792
  // src/core/setup.ts
790
- function setupClient(config, onGuides) {
793
+ function setupClient(config, onGuides, loadBuilder) {
791
794
  const client = new Client(config);
792
795
  client.use(spaRouterPlugin());
793
796
  if (config.autocapture !== false) {
@@ -815,7 +818,8 @@ function setupClient(config, onGuides) {
815
818
  ...config.builderUrl !== void 0 ? { builderUrl: config.builderUrl } : {},
816
819
  ...config.debug !== void 0 ? { debug: config.debug } : {},
817
820
  ...config.apiKey !== void 0 ? { apiKey: config.apiKey } : {},
818
- ...config.apiUrl !== void 0 ? { apiUrl: config.apiUrl } : {}
821
+ apiUrl: resolveApiUrl(config),
822
+ ...loadBuilder ? { loadBuilder } : {}
819
823
  });
820
824
  }
821
825
  return client;
@@ -823,28 +827,36 @@ function setupClient(config, onGuides) {
823
827
 
824
828
  // src/index.ts
825
829
  function init(config) {
826
- return setupClient(config, (client) => {
827
- const previewToken = getPreviewToken();
828
- if (config.guides === true && !isBuilderMode() && previewToken === null) {
829
- client.use(
830
- guidesPlugin({
831
- apiUrl: config.apiUrl,
830
+ const apiUrl = resolveApiUrl(config);
831
+ return setupClient(
832
+ config,
833
+ (client) => {
834
+ const previewToken = getPreviewToken();
835
+ if (config.guides === true && !isBuilderMode() && previewToken === null) {
836
+ client.use(
837
+ guidesPlugin({
838
+ apiUrl,
839
+ apiKey: config.apiKey,
840
+ ...config.debug !== void 0 ? { debug: config.debug } : {}
841
+ })
842
+ );
843
+ }
844
+ if (previewToken !== null) {
845
+ void runPreviewMode({
832
846
  apiKey: config.apiKey,
847
+ apiUrl,
848
+ token: previewToken,
833
849
  ...config.debug !== void 0 ? { debug: config.debug } : {}
834
- })
835
- );
836
- }
837
- if (previewToken !== null) {
838
- void runPreviewMode({
839
- apiKey: config.apiKey,
840
- apiUrl: config.apiUrl,
841
- token: previewToken,
842
- ...config.debug !== void 0 ? { debug: config.debug } : {}
843
- });
844
- }
845
- client.preview = previewGuide;
846
- client.closePreview = closeGuidePreview;
847
- });
850
+ });
851
+ }
852
+ client.preview = previewGuide;
853
+ client.closePreview = closeGuidePreview;
854
+ },
855
+ // Fallback de carga del builder para bundlers: `import()` dinámico → el bundler
856
+ // lo code-splitea (solo se descarga en modo builder). Así el consumidor por
857
+ // bundler NO necesita copiar `veo-builder.js` ni setear `builderUrl`.
858
+ () => import('./builder-UEGKG2UR.mjs').then((m) => m.initBuilderMode())
859
+ );
848
860
  }
849
861
 
850
862
  export { Client, SDK_VERSION, autocapturePlugin, init, spaRouterPlugin };