@nexushub/client 0.0.4 → 0.0.6

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.
@@ -3,16 +3,19 @@ import React from 'react';
3
3
 
4
4
  interface MinimalNexusConfig {
5
5
  apiUrl?: string;
6
+ analyticsUrl?: string;
6
7
  apiKey?: string;
7
8
  projectId?: string;
8
9
  }
9
- declare const DEFAULT_API_URL = "https://api.nexushub.com/v1";
10
- declare const DEFAULT_CDN_URL = "https://cdn.nexushub.com";
10
+ declare const DEFAULT_API_URL = "http://localhost:3001";
11
+ declare const DEFAULT_ANALYTICS_URL = "http://localhost:3002";
12
+ declare const LOCAL_NEST_URL = "http://localhost:3001";
13
+ declare const LOCAL_RUST_URL = "http://localhost:3002";
11
14
  declare const getEnvConfig: () => MinimalNexusConfig;
15
+ /**
16
+ * Merges base environment config with manual overrides from the constructor
17
+ */
12
18
  declare const mergeConfigs: (base: MinimalNexusConfig, override: Partial<MinimalNexusConfig>) => MinimalNexusConfig;
13
- declare const hasRequiredConfig: (config: MinimalNexusConfig) => config is MinimalNexusConfig & {
14
- projectId: string;
15
- };
16
19
  declare const getFullConfig: (partialConfig?: Partial<MinimalNexusConfig>) => MinimalNexusConfig;
17
20
  declare const validateConfig: (config: MinimalNexusConfig) => string[];
18
21
 
@@ -395,4 +398,4 @@ declare class BrowserCache {
395
398
 
396
399
  declare const VERSION = "0.0.1";
397
400
 
398
- export { AnalyticsEngine, type AuthContextType, type AuthError, AuthProvider, type AuthState, BrowserCache, type CacheEntry, type CacheMetadata, CacheTags, type CollectionQuery, type CollectionResponse, ContentEngine, type ContentResponse, DEFAULT_API_URL, DEFAULT_CDN_URL, type ErrorResponse, LocalCache, type LoginCredentials, MemoryCache, type MinimalNexusConfig, NexusClient, type NexusConfig, NexusProvider, type RegisterCredentials, type SiteUser, VERSION, createNexusClient, getEnvConfig, getFullConfig, hasRequiredConfig, mergeConfigs, nexus, useNexusAuth, validateConfig };
401
+ export { AnalyticsEngine, type AuthContextType, type AuthError, AuthProvider, type AuthState, BrowserCache, type CacheEntry, type CacheMetadata, CacheTags, type CollectionQuery, type CollectionResponse, ContentEngine, type ContentResponse, DEFAULT_ANALYTICS_URL, DEFAULT_API_URL, type ErrorResponse, LOCAL_NEST_URL, LOCAL_RUST_URL, LocalCache, type LoginCredentials, MemoryCache, type MinimalNexusConfig, NexusClient, type NexusConfig, NexusProvider, type RegisterCredentials, type SiteUser, VERSION, createNexusClient, getEnvConfig, getFullConfig, mergeConfigs, nexus, useNexusAuth, validateConfig };
@@ -3,16 +3,19 @@ import React from 'react';
3
3
 
4
4
  interface MinimalNexusConfig {
5
5
  apiUrl?: string;
6
+ analyticsUrl?: string;
6
7
  apiKey?: string;
7
8
  projectId?: string;
8
9
  }
9
- declare const DEFAULT_API_URL = "https://api.nexushub.com/v1";
10
- declare const DEFAULT_CDN_URL = "https://cdn.nexushub.com";
10
+ declare const DEFAULT_API_URL = "http://localhost:3001";
11
+ declare const DEFAULT_ANALYTICS_URL = "http://localhost:3002";
12
+ declare const LOCAL_NEST_URL = "http://localhost:3001";
13
+ declare const LOCAL_RUST_URL = "http://localhost:3002";
11
14
  declare const getEnvConfig: () => MinimalNexusConfig;
15
+ /**
16
+ * Merges base environment config with manual overrides from the constructor
17
+ */
12
18
  declare const mergeConfigs: (base: MinimalNexusConfig, override: Partial<MinimalNexusConfig>) => MinimalNexusConfig;
13
- declare const hasRequiredConfig: (config: MinimalNexusConfig) => config is MinimalNexusConfig & {
14
- projectId: string;
15
- };
16
19
  declare const getFullConfig: (partialConfig?: Partial<MinimalNexusConfig>) => MinimalNexusConfig;
17
20
  declare const validateConfig: (config: MinimalNexusConfig) => string[];
18
21
 
@@ -395,4 +398,4 @@ declare class BrowserCache {
395
398
 
396
399
  declare const VERSION = "0.0.1";
397
400
 
398
- export { AnalyticsEngine, type AuthContextType, type AuthError, AuthProvider, type AuthState, BrowserCache, type CacheEntry, type CacheMetadata, CacheTags, type CollectionQuery, type CollectionResponse, ContentEngine, type ContentResponse, DEFAULT_API_URL, DEFAULT_CDN_URL, type ErrorResponse, LocalCache, type LoginCredentials, MemoryCache, type MinimalNexusConfig, NexusClient, type NexusConfig, NexusProvider, type RegisterCredentials, type SiteUser, VERSION, createNexusClient, getEnvConfig, getFullConfig, hasRequiredConfig, mergeConfigs, nexus, useNexusAuth, validateConfig };
401
+ export { AnalyticsEngine, type AuthContextType, type AuthError, AuthProvider, type AuthState, BrowserCache, type CacheEntry, type CacheMetadata, CacheTags, type CollectionQuery, type CollectionResponse, ContentEngine, type ContentResponse, DEFAULT_ANALYTICS_URL, DEFAULT_API_URL, type ErrorResponse, LOCAL_NEST_URL, LOCAL_RUST_URL, LocalCache, type LoginCredentials, MemoryCache, type MinimalNexusConfig, NexusClient, type NexusConfig, NexusProvider, type RegisterCredentials, type SiteUser, VERSION, createNexusClient, getEnvConfig, getFullConfig, mergeConfigs, nexus, useNexusAuth, validateConfig };
package/dist/src/index.js CHANGED
@@ -5190,8 +5190,10 @@ __export(src_exports, {
5190
5190
  BrowserCache: () => BrowserCache,
5191
5191
  CacheTags: () => CacheTags,
5192
5192
  ContentEngine: () => ContentEngine,
5193
+ DEFAULT_ANALYTICS_URL: () => DEFAULT_ANALYTICS_URL,
5193
5194
  DEFAULT_API_URL: () => DEFAULT_API_URL,
5194
- DEFAULT_CDN_URL: () => DEFAULT_CDN_URL,
5195
+ LOCAL_NEST_URL: () => LOCAL_NEST_URL,
5196
+ LOCAL_RUST_URL: () => LOCAL_RUST_URL,
5195
5197
  LocalCache: () => LocalCache,
5196
5198
  MemoryCache: () => MemoryCache,
5197
5199
  NexusClient: () => NexusClient,
@@ -5200,7 +5202,6 @@ __export(src_exports, {
5200
5202
  createNexusClient: () => createNexusClient,
5201
5203
  getEnvConfig: () => getEnvConfig,
5202
5204
  getFullConfig: () => getFullConfig,
5203
- hasRequiredConfig: () => hasRequiredConfig,
5204
5205
  mergeConfigs: () => mergeConfigs,
5205
5206
  nexus: () => nexus,
5206
5207
  useNexusAuth: () => useNexusAuth,
@@ -5209,56 +5210,48 @@ __export(src_exports, {
5209
5210
  module.exports = __toCommonJS(src_exports);
5210
5211
 
5211
5212
  // src/config.ts
5212
- var DEFAULT_API_URL = "https://api.nexushub.com/v1";
5213
- var DEFAULT_CDN_URL = "https://cdn.nexushub.com";
5213
+ var DEFAULT_API_URL = "http://localhost:3001";
5214
+ var DEFAULT_ANALYTICS_URL = "http://localhost:3002";
5215
+ var LOCAL_NEST_URL = "http://localhost:3001";
5216
+ var LOCAL_RUST_URL = "http://localhost:3002";
5214
5217
  var hasEnv = () => {
5215
5218
  return typeof process !== "undefined" && typeof process.env !== "undefined" && Object.keys(process.env).length > 0;
5216
5219
  };
5217
5220
  var getEnvConfig = () => {
5218
- if (!hasEnv()) {
5219
- return {
5220
- apiUrl: DEFAULT_API_URL
5221
- };
5222
- }
5223
- const env = process.env;
5224
- const projectId = env.NEXT_PUBLIC_NEXUS_ID ?? env.NEXUS_PROJECT_ID ?? env.NEXUS_PROJECT_ID;
5225
- const apiKey = env.NEXT_PUBLIC_NEXUS_KEY ?? env.NEXUS_API_KEY ?? env.NEXUS_API_KEY;
5226
- const apiUrl = env.NEXT_PUBLIC_NEXUS_API_URL ?? env.NEXUS_API_URL ?? DEFAULT_API_URL;
5221
+ const env = hasEnv() ? process.env : {};
5222
+ const isDev = env.NODE_ENV === "development" || env.NEXT_PUBLIC_NODE_ENV === "development";
5223
+ const projectId = env.NEXT_PUBLIC_NEXUS_ID ?? env.NEXUS_PROJECT_ID;
5224
+ const apiKey = env.NEXT_PUBLIC_NEXUS_KEY ?? env.NEXUS_API_KEY;
5225
+ const apiUrl = env.NEXT_PUBLIC_NEXUS_API_URL ?? env.NEXUS_API_URL ?? (isDev ? LOCAL_NEST_URL : DEFAULT_API_URL);
5226
+ const analyticsUrl = env.NEXT_PUBLIC_NEXUS_ANALYTICS_URL ?? (apiUrl.includes("localhost") ? LOCAL_RUST_URL : DEFAULT_ANALYTICS_URL);
5227
5227
  return {
5228
5228
  projectId,
5229
5229
  apiKey,
5230
- apiUrl
5230
+ apiUrl,
5231
+ analyticsUrl
5231
5232
  };
5232
5233
  };
5233
5234
  var mergeConfigs = (base, override) => {
5235
+ const mergedApiUrl = override.apiUrl || base.apiUrl || DEFAULT_API_URL;
5236
+ const mergedAnalyticsUrl = override.analyticsUrl || base.analyticsUrl || (mergedApiUrl.includes("localhost") ? LOCAL_RUST_URL : DEFAULT_ANALYTICS_URL);
5234
5237
  return {
5235
5238
  ...base,
5236
5239
  ...override,
5237
- apiUrl: override.apiUrl || base.apiUrl || DEFAULT_API_URL,
5240
+ apiUrl: mergedApiUrl,
5241
+ analyticsUrl: mergedAnalyticsUrl,
5238
5242
  projectId: override.projectId || base.projectId
5239
5243
  };
5240
5244
  };
5241
- var hasRequiredConfig = (config) => {
5242
- return !!config.projectId && !!config.apiUrl;
5243
- };
5244
5245
  var getFullConfig = (partialConfig) => {
5245
5246
  const envConfig = getEnvConfig();
5246
- const merged = mergeConfigs(envConfig, partialConfig || {});
5247
- if (!merged.apiUrl) {
5248
- merged.apiUrl = DEFAULT_API_URL;
5249
- }
5250
- return merged;
5247
+ return mergeConfigs(envConfig, partialConfig || {});
5251
5248
  };
5252
5249
  var validateConfig = (config) => {
5253
5250
  const errors = [];
5254
- if (!config.projectId) {
5255
- errors.push("Missing projectId");
5256
- }
5257
- if (!config.apiUrl) {
5258
- errors.push("Missing apiUrl");
5259
- }
5251
+ if (!config.projectId) errors.push("Missing projectId");
5252
+ if (!config.apiUrl) errors.push("Missing apiUrl");
5260
5253
  if (config.apiUrl && !config.apiUrl.startsWith("http")) {
5261
- errors.push("apiUrl must be a valid URL starting with http:// or https://");
5254
+ errors.push("apiUrl must be a valid URL (http:// or https://)");
5262
5255
  }
5263
5256
  return errors;
5264
5257
  };
@@ -6613,7 +6606,7 @@ var Tracker = class {
6613
6606
  this.isFlushing = false;
6614
6607
  this.config = config;
6615
6608
  const baseUrl = this.config.apiUrl.replace("/v1", "").replace(/\/$/, "");
6616
- this.endpoint = `${baseUrl}:3002/api/collect`;
6609
+ this.endpoint = `${this.config.analyticsUrl}/api/collect`;
6617
6610
  this.circuitBreaker = new CircuitBreaker();
6618
6611
  this.sessionStart = Date.now();
6619
6612
  if (typeof window !== "undefined") {
@@ -6700,7 +6693,7 @@ var Tracker = class {
6700
6693
  method: "POST",
6701
6694
  headers: {
6702
6695
  "Content-Type": "application/json",
6703
- "Authorization": `Bearer ${this.config.apiKey}`
6696
+ Authorization: `Bearer ${this.config.apiKey}`
6704
6697
  },
6705
6698
  body: JSON.stringify(event),
6706
6699
  keepalive: useBeacon
@@ -6836,29 +6829,34 @@ var AnalyticsEngine = class {
6836
6829
  * 4. RESET: Clear local data and (optionally) request GDPR scrub
6837
6830
  */
6838
6831
  reset(performGdprScrub = false) {
6832
+ const config = this.tracker["config"];
6839
6833
  this.tracker.stop();
6840
6834
  localStorage.removeItem("nexus_sid");
6841
6835
  localStorage.removeItem("nexus_vid");
6842
6836
  if (performGdprScrub) {
6843
- const baseUrl = this.tracker["config"].apiUrl.replace("/v1", "").replace(/\/$/, "");
6837
+ const endpoint = `${config.analyticsUrl}/api/privacy/scrub`;
6844
6838
  const userId = this.tracker.visitorId;
6845
- fetch(`${baseUrl}:3002/api/privacy/scrub`, {
6839
+ fetch(endpoint, {
6846
6840
  method: "DELETE",
6847
6841
  headers: {
6848
6842
  "Content-Type": "application/json",
6849
- "Authorization": `Bearer ${this.tracker["config"].apiKey}`
6843
+ Authorization: `Bearer ${config.apiKey}`
6850
6844
  },
6851
6845
  body: JSON.stringify({
6852
- project_id: this.tracker["config"].projectId,
6846
+ project_id: config.projectId,
6853
6847
  user_id: userId
6854
6848
  })
6855
- }).catch(console.error);
6849
+ }).catch((err) => console.error("[NexusHub] Privacy scrub failed:", err));
6856
6850
  }
6857
6851
  window.location.reload();
6858
6852
  }
6859
6853
  // --- E-COMMERCE & CUSTOM ---
6860
6854
  track(eventName, properties = {}) {
6861
- this.tracker.send("custom_event", { event_name: eventName, ...properties }, eventName);
6855
+ this.tracker.send(
6856
+ "custom_event",
6857
+ { event_name: eventName, ...properties },
6858
+ eventName
6859
+ );
6862
6860
  }
6863
6861
  trackPurchase(orderData) {
6864
6862
  this.tracker.send("purchase", {
@@ -6878,8 +6876,8 @@ var AnalyticsEngine = class {
6878
6876
  // --- INTERNAL HELPER ---
6879
6877
  async sendIdentityRequest(type, data) {
6880
6878
  try {
6881
- const baseUrl = this.tracker["config"].apiUrl.replace("/v1", "").replace(/\/$/, "");
6882
- const endpoint = `${baseUrl}:3002/api/${type}`;
6879
+ const config = this.tracker["config"];
6880
+ const endpoint = `${config.analyticsUrl}/api/${type}`;
6883
6881
  const payload = {
6884
6882
  project_id: this.tracker["config"].projectId,
6885
6883
  session_id: this.tracker.getSession(),
@@ -6893,7 +6891,7 @@ var AnalyticsEngine = class {
6893
6891
  method: "POST",
6894
6892
  headers: {
6895
6893
  "Content-Type": "application/json",
6896
- "Authorization": `Bearer ${this.tracker["config"].apiKey}`
6894
+ Authorization: `Bearer ${this.tracker["config"].apiKey}`
6897
6895
  },
6898
6896
  body: JSON.stringify(payload)
6899
6897
  });
@@ -6935,7 +6933,9 @@ var AnalyticsEngine = class {
6935
6933
  }
6936
6934
  };
6937
6935
  window.addEventListener("click", clickHandler, { passive: true });
6938
- this.cleanupFns.push(() => window.removeEventListener("click", clickHandler));
6936
+ this.cleanupFns.push(
6937
+ () => window.removeEventListener("click", clickHandler)
6938
+ );
6939
6939
  }
6940
6940
  setupFormTracking() {
6941
6941
  if (typeof document === "undefined") return;
@@ -6951,10 +6951,13 @@ var AnalyticsEngine = class {
6951
6951
  }
6952
6952
  };
6953
6953
  document.addEventListener("submit", submitHandler, { passive: true });
6954
- this.cleanupFns.push(() => document.removeEventListener("submit", submitHandler));
6954
+ this.cleanupFns.push(
6955
+ () => document.removeEventListener("submit", submitHandler)
6956
+ );
6955
6957
  }
6956
6958
  setupRouteTracking() {
6957
- if (typeof window === "undefined" || typeof window.history === "undefined") return;
6959
+ if (typeof window === "undefined" || typeof window.history === "undefined")
6960
+ return;
6958
6961
  const originalPushState = history.pushState;
6959
6962
  const originalReplaceState = history.replaceState;
6960
6963
  history.pushState = (...args) => {
@@ -6967,7 +6970,9 @@ var AnalyticsEngine = class {
6967
6970
  };
6968
6971
  const popStateHandler = () => this.pageView();
6969
6972
  window.addEventListener("popstate", popStateHandler);
6970
- this.cleanupFns.push(() => window.removeEventListener("popstate", popStateHandler));
6973
+ this.cleanupFns.push(
6974
+ () => window.removeEventListener("popstate", popStateHandler)
6975
+ );
6971
6976
  }
6972
6977
  getSessionId() {
6973
6978
  return this.tracker.getSession();
@@ -7241,8 +7246,10 @@ var VERSION = "0.0.1";
7241
7246
  BrowserCache,
7242
7247
  CacheTags,
7243
7248
  ContentEngine,
7249
+ DEFAULT_ANALYTICS_URL,
7244
7250
  DEFAULT_API_URL,
7245
- DEFAULT_CDN_URL,
7251
+ LOCAL_NEST_URL,
7252
+ LOCAL_RUST_URL,
7246
7253
  LocalCache,
7247
7254
  MemoryCache,
7248
7255
  NexusClient,
@@ -7251,7 +7258,6 @@ var VERSION = "0.0.1";
7251
7258
  createNexusClient,
7252
7259
  getEnvConfig,
7253
7260
  getFullConfig,
7254
- hasRequiredConfig,
7255
7261
  mergeConfigs,
7256
7262
  nexus,
7257
7263
  useNexusAuth,
@@ -5183,56 +5183,48 @@ var require_navigation2 = __commonJS({
5183
5183
  });
5184
5184
 
5185
5185
  // src/config.ts
5186
- var DEFAULT_API_URL = "https://api.nexushub.com/v1";
5187
- var DEFAULT_CDN_URL = "https://cdn.nexushub.com";
5186
+ var DEFAULT_API_URL = "http://localhost:3001";
5187
+ var DEFAULT_ANALYTICS_URL = "http://localhost:3002";
5188
+ var LOCAL_NEST_URL = "http://localhost:3001";
5189
+ var LOCAL_RUST_URL = "http://localhost:3002";
5188
5190
  var hasEnv = () => {
5189
5191
  return typeof process !== "undefined" && typeof process.env !== "undefined" && Object.keys(process.env).length > 0;
5190
5192
  };
5191
5193
  var getEnvConfig = () => {
5192
- if (!hasEnv()) {
5193
- return {
5194
- apiUrl: DEFAULT_API_URL
5195
- };
5196
- }
5197
- const env = process.env;
5198
- const projectId = env.NEXT_PUBLIC_NEXUS_ID ?? env.NEXUS_PROJECT_ID ?? env.NEXUS_PROJECT_ID;
5199
- const apiKey = env.NEXT_PUBLIC_NEXUS_KEY ?? env.NEXUS_API_KEY ?? env.NEXUS_API_KEY;
5200
- const apiUrl = env.NEXT_PUBLIC_NEXUS_API_URL ?? env.NEXUS_API_URL ?? DEFAULT_API_URL;
5194
+ const env = hasEnv() ? process.env : {};
5195
+ const isDev = env.NODE_ENV === "development" || env.NEXT_PUBLIC_NODE_ENV === "development";
5196
+ const projectId = env.NEXT_PUBLIC_NEXUS_ID ?? env.NEXUS_PROJECT_ID;
5197
+ const apiKey = env.NEXT_PUBLIC_NEXUS_KEY ?? env.NEXUS_API_KEY;
5198
+ const apiUrl = env.NEXT_PUBLIC_NEXUS_API_URL ?? env.NEXUS_API_URL ?? (isDev ? LOCAL_NEST_URL : DEFAULT_API_URL);
5199
+ const analyticsUrl = env.NEXT_PUBLIC_NEXUS_ANALYTICS_URL ?? (apiUrl.includes("localhost") ? LOCAL_RUST_URL : DEFAULT_ANALYTICS_URL);
5201
5200
  return {
5202
5201
  projectId,
5203
5202
  apiKey,
5204
- apiUrl
5203
+ apiUrl,
5204
+ analyticsUrl
5205
5205
  };
5206
5206
  };
5207
5207
  var mergeConfigs = (base, override) => {
5208
+ const mergedApiUrl = override.apiUrl || base.apiUrl || DEFAULT_API_URL;
5209
+ const mergedAnalyticsUrl = override.analyticsUrl || base.analyticsUrl || (mergedApiUrl.includes("localhost") ? LOCAL_RUST_URL : DEFAULT_ANALYTICS_URL);
5208
5210
  return {
5209
5211
  ...base,
5210
5212
  ...override,
5211
- apiUrl: override.apiUrl || base.apiUrl || DEFAULT_API_URL,
5213
+ apiUrl: mergedApiUrl,
5214
+ analyticsUrl: mergedAnalyticsUrl,
5212
5215
  projectId: override.projectId || base.projectId
5213
5216
  };
5214
5217
  };
5215
- var hasRequiredConfig = (config) => {
5216
- return !!config.projectId && !!config.apiUrl;
5217
- };
5218
5218
  var getFullConfig = (partialConfig) => {
5219
5219
  const envConfig = getEnvConfig();
5220
- const merged = mergeConfigs(envConfig, partialConfig || {});
5221
- if (!merged.apiUrl) {
5222
- merged.apiUrl = DEFAULT_API_URL;
5223
- }
5224
- return merged;
5220
+ return mergeConfigs(envConfig, partialConfig || {});
5225
5221
  };
5226
5222
  var validateConfig = (config) => {
5227
5223
  const errors = [];
5228
- if (!config.projectId) {
5229
- errors.push("Missing projectId");
5230
- }
5231
- if (!config.apiUrl) {
5232
- errors.push("Missing apiUrl");
5233
- }
5224
+ if (!config.projectId) errors.push("Missing projectId");
5225
+ if (!config.apiUrl) errors.push("Missing apiUrl");
5234
5226
  if (config.apiUrl && !config.apiUrl.startsWith("http")) {
5235
- errors.push("apiUrl must be a valid URL starting with http:// or https://");
5227
+ errors.push("apiUrl must be a valid URL (http:// or https://)");
5236
5228
  }
5237
5229
  return errors;
5238
5230
  };
@@ -6593,7 +6585,7 @@ var Tracker = class {
6593
6585
  this.isFlushing = false;
6594
6586
  this.config = config;
6595
6587
  const baseUrl = this.config.apiUrl.replace("/v1", "").replace(/\/$/, "");
6596
- this.endpoint = `${baseUrl}:3002/api/collect`;
6588
+ this.endpoint = `${this.config.analyticsUrl}/api/collect`;
6597
6589
  this.circuitBreaker = new CircuitBreaker();
6598
6590
  this.sessionStart = Date.now();
6599
6591
  if (typeof window !== "undefined") {
@@ -6680,7 +6672,7 @@ var Tracker = class {
6680
6672
  method: "POST",
6681
6673
  headers: {
6682
6674
  "Content-Type": "application/json",
6683
- "Authorization": `Bearer ${this.config.apiKey}`
6675
+ Authorization: `Bearer ${this.config.apiKey}`
6684
6676
  },
6685
6677
  body: JSON.stringify(event),
6686
6678
  keepalive: useBeacon
@@ -6816,29 +6808,34 @@ var AnalyticsEngine = class {
6816
6808
  * 4. RESET: Clear local data and (optionally) request GDPR scrub
6817
6809
  */
6818
6810
  reset(performGdprScrub = false) {
6811
+ const config = this.tracker["config"];
6819
6812
  this.tracker.stop();
6820
6813
  localStorage.removeItem("nexus_sid");
6821
6814
  localStorage.removeItem("nexus_vid");
6822
6815
  if (performGdprScrub) {
6823
- const baseUrl = this.tracker["config"].apiUrl.replace("/v1", "").replace(/\/$/, "");
6816
+ const endpoint = `${config.analyticsUrl}/api/privacy/scrub`;
6824
6817
  const userId = this.tracker.visitorId;
6825
- fetch(`${baseUrl}:3002/api/privacy/scrub`, {
6818
+ fetch(endpoint, {
6826
6819
  method: "DELETE",
6827
6820
  headers: {
6828
6821
  "Content-Type": "application/json",
6829
- "Authorization": `Bearer ${this.tracker["config"].apiKey}`
6822
+ Authorization: `Bearer ${config.apiKey}`
6830
6823
  },
6831
6824
  body: JSON.stringify({
6832
- project_id: this.tracker["config"].projectId,
6825
+ project_id: config.projectId,
6833
6826
  user_id: userId
6834
6827
  })
6835
- }).catch(console.error);
6828
+ }).catch((err) => console.error("[NexusHub] Privacy scrub failed:", err));
6836
6829
  }
6837
6830
  window.location.reload();
6838
6831
  }
6839
6832
  // --- E-COMMERCE & CUSTOM ---
6840
6833
  track(eventName, properties = {}) {
6841
- this.tracker.send("custom_event", { event_name: eventName, ...properties }, eventName);
6834
+ this.tracker.send(
6835
+ "custom_event",
6836
+ { event_name: eventName, ...properties },
6837
+ eventName
6838
+ );
6842
6839
  }
6843
6840
  trackPurchase(orderData) {
6844
6841
  this.tracker.send("purchase", {
@@ -6858,8 +6855,8 @@ var AnalyticsEngine = class {
6858
6855
  // --- INTERNAL HELPER ---
6859
6856
  async sendIdentityRequest(type, data) {
6860
6857
  try {
6861
- const baseUrl = this.tracker["config"].apiUrl.replace("/v1", "").replace(/\/$/, "");
6862
- const endpoint = `${baseUrl}:3002/api/${type}`;
6858
+ const config = this.tracker["config"];
6859
+ const endpoint = `${config.analyticsUrl}/api/${type}`;
6863
6860
  const payload = {
6864
6861
  project_id: this.tracker["config"].projectId,
6865
6862
  session_id: this.tracker.getSession(),
@@ -6873,7 +6870,7 @@ var AnalyticsEngine = class {
6873
6870
  method: "POST",
6874
6871
  headers: {
6875
6872
  "Content-Type": "application/json",
6876
- "Authorization": `Bearer ${this.tracker["config"].apiKey}`
6873
+ Authorization: `Bearer ${this.tracker["config"].apiKey}`
6877
6874
  },
6878
6875
  body: JSON.stringify(payload)
6879
6876
  });
@@ -6915,7 +6912,9 @@ var AnalyticsEngine = class {
6915
6912
  }
6916
6913
  };
6917
6914
  window.addEventListener("click", clickHandler, { passive: true });
6918
- this.cleanupFns.push(() => window.removeEventListener("click", clickHandler));
6915
+ this.cleanupFns.push(
6916
+ () => window.removeEventListener("click", clickHandler)
6917
+ );
6919
6918
  }
6920
6919
  setupFormTracking() {
6921
6920
  if (typeof document === "undefined") return;
@@ -6931,10 +6930,13 @@ var AnalyticsEngine = class {
6931
6930
  }
6932
6931
  };
6933
6932
  document.addEventListener("submit", submitHandler, { passive: true });
6934
- this.cleanupFns.push(() => document.removeEventListener("submit", submitHandler));
6933
+ this.cleanupFns.push(
6934
+ () => document.removeEventListener("submit", submitHandler)
6935
+ );
6935
6936
  }
6936
6937
  setupRouteTracking() {
6937
- if (typeof window === "undefined" || typeof window.history === "undefined") return;
6938
+ if (typeof window === "undefined" || typeof window.history === "undefined")
6939
+ return;
6938
6940
  const originalPushState = history.pushState;
6939
6941
  const originalReplaceState = history.replaceState;
6940
6942
  history.pushState = (...args) => {
@@ -6947,7 +6949,9 @@ var AnalyticsEngine = class {
6947
6949
  };
6948
6950
  const popStateHandler = () => this.pageView();
6949
6951
  window.addEventListener("popstate", popStateHandler);
6950
- this.cleanupFns.push(() => window.removeEventListener("popstate", popStateHandler));
6952
+ this.cleanupFns.push(
6953
+ () => window.removeEventListener("popstate", popStateHandler)
6954
+ );
6951
6955
  }
6952
6956
  getSessionId() {
6953
6957
  return this.tracker.getSession();
@@ -7220,8 +7224,10 @@ export {
7220
7224
  BrowserCache,
7221
7225
  CacheTags,
7222
7226
  ContentEngine,
7227
+ DEFAULT_ANALYTICS_URL,
7223
7228
  DEFAULT_API_URL,
7224
- DEFAULT_CDN_URL,
7229
+ LOCAL_NEST_URL,
7230
+ LOCAL_RUST_URL,
7225
7231
  LocalCache,
7226
7232
  MemoryCache,
7227
7233
  NexusClient,
@@ -7230,7 +7236,6 @@ export {
7230
7236
  createNexusClient,
7231
7237
  getEnvConfig,
7232
7238
  getFullConfig,
7233
- hasRequiredConfig,
7234
7239
  mergeConfigs,
7235
7240
  nexus,
7236
7241
  useNexusAuth,
package/dist/tools/cli.js CHANGED
@@ -266,7 +266,7 @@ async function syncContent(options) {
266
266
  const [pages, collections, globals] = await Promise.all([
267
267
  fetchWithAuth(`${apiUrl}/content/${projectId}/pages`, apiKey),
268
268
  fetchCollections(`${apiUrl}/content/${projectId}`, apiKey, projectId),
269
- fetchWithAuth(`${apiUrl}/project/${projectId}/globals`, apiKey)
269
+ fetchWithAuth(`${apiUrl}/projects/${projectId}/globals`, apiKey)
270
270
  ]);
271
271
  const cacheData = {
272
272
  pages: pages.data || pages,
@@ -477,7 +477,7 @@ async function seedCollections(collectionsDir, apiUrl, projectId, apiKey) {
477
477
  }
478
478
  async function seedGlobals(globals, apiUrl, projectId, apiKey) {
479
479
  try {
480
- await (0, import_node_fetch.default)(`${apiUrl}/project/${projectId}/globals`, {
480
+ await (0, import_node_fetch.default)(`${apiUrl}/projects/${projectId}/globals`, {
481
481
  method: "PUT",
482
482
  headers: {
483
483
  Authorization: `Bearer ${apiKey}`,
@@ -243,7 +243,7 @@ async function syncContent(options) {
243
243
  const [pages, collections, globals] = await Promise.all([
244
244
  fetchWithAuth(`${apiUrl}/content/${projectId}/pages`, apiKey),
245
245
  fetchCollections(`${apiUrl}/content/${projectId}`, apiKey, projectId),
246
- fetchWithAuth(`${apiUrl}/project/${projectId}/globals`, apiKey)
246
+ fetchWithAuth(`${apiUrl}/projects/${projectId}/globals`, apiKey)
247
247
  ]);
248
248
  const cacheData = {
249
249
  pages: pages.data || pages,
@@ -454,7 +454,7 @@ async function seedCollections(collectionsDir, apiUrl, projectId, apiKey) {
454
454
  }
455
455
  async function seedGlobals(globals, apiUrl, projectId, apiKey) {
456
456
  try {
457
- await fetch(`${apiUrl}/project/${projectId}/globals`, {
457
+ await fetch(`${apiUrl}/projects/${projectId}/globals`, {
458
458
  method: "PUT",
459
459
  headers: {
460
460
  Authorization: `Bearer ${apiKey}`,
package/package.json CHANGED
@@ -1,13 +1,21 @@
1
1
  {
2
2
  "name": "@nexushub/client",
3
3
  "private": false,
4
- "version": "0.0.4",
4
+ "version": "0.0.6",
5
5
  "description": "The God-Tier NexusHub SDK",
6
6
  "main": "dist/src/index.js",
7
7
  "types": "dist/src/index.d.ts",
8
+ "module": "./dist/src/index.mjs",
8
9
  "bin": {
9
10
  "nexus": "dist/tools/cli.js"
10
11
  },
12
+ "exports": {
13
+ ".": {
14
+ "types": "./dist/src/index.d.ts",
15
+ "import": "./dist/src/index.mjs",
16
+ "require": "./dist/src/index.js"
17
+ }
18
+ },
11
19
  "files": [
12
20
  "dist",
13
21
  "README.md"