@almadar/ui 2.46.1 → 2.47.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.
@@ -39,6 +39,7 @@ var patterns = require('@almadar/patterns');
39
39
  var reactRouterDom = require('react-router-dom');
40
40
  var reactQuery = require('@tanstack/react-query');
41
41
 
42
+ var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
42
43
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
43
44
 
44
45
  function _interopNamespace(e) {
@@ -91,6 +92,67 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
91
92
  function cn(...inputs) {
92
93
  return tailwindMerge.twMerge(clsx.clsx(inputs));
93
94
  }
95
+
96
+ // lib/logger.ts
97
+ var LEVEL_PRIORITY = { DEBUG: 0, INFO: 1, WARN: 2, ERROR: 3 };
98
+ var ENV = typeof process !== "undefined" && process.env ? process.env : {};
99
+ var VITE_ENV = typeof globalThis !== "undefined" && globalThis.__vite_env__ ? globalThis.__vite_env__ : {};
100
+ function getViteEnv(key) {
101
+ try {
102
+ const meta = ({ url: (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)) });
103
+ return meta?.env?.[key];
104
+ } catch {
105
+ return void 0;
106
+ }
107
+ }
108
+ function envGet(key, viteKey) {
109
+ return ENV[key] ?? (viteKey ? getViteEnv(viteKey) : void 0) ?? VITE_ENV[viteKey ?? key];
110
+ }
111
+ var NODE_ENV = envGet("NODE_ENV", "VITE_NODE_ENV") ?? "development";
112
+ var CONFIGURED_LEVEL = (envGet("LOG_LEVEL", "VITE_LOG_LEVEL") ?? (NODE_ENV === "production" ? "info" : "debug")).toUpperCase();
113
+ var MIN_PRIORITY = LEVEL_PRIORITY[CONFIGURED_LEVEL] ?? 0;
114
+ var DEBUG_FILTER = (envGet("ALMADAR_DEBUG", "VITE_ALMADAR_DEBUG") ?? "").split(",").map((s) => s.trim()).filter(Boolean);
115
+ function matchesNamespace(namespace) {
116
+ if (DEBUG_FILTER.length === 0) return true;
117
+ return DEBUG_FILTER.some((pattern) => {
118
+ if (pattern === "*" || pattern === "almadar:*") return true;
119
+ if (pattern.endsWith(":*")) return namespace.startsWith(pattern.slice(0, -1));
120
+ return namespace === pattern;
121
+ });
122
+ }
123
+ function createLogger(namespace) {
124
+ const nsAllowed = matchesNamespace(namespace);
125
+ const log3 = (level, message, data, correlationId) => {
126
+ if (LEVEL_PRIORITY[level] < MIN_PRIORITY) return;
127
+ if (level === "DEBUG" && !nsAllowed) return;
128
+ const prefix = `[${namespace}]`;
129
+ const logData = correlationId ? { ...data, cid: correlationId } : data;
130
+ switch (level) {
131
+ case "DEBUG":
132
+ console.debug(prefix, message, logData ?? "");
133
+ break;
134
+ case "INFO":
135
+ console.info(prefix, message, logData ?? "");
136
+ break;
137
+ case "WARN":
138
+ console.warn(prefix, message, logData ?? "");
139
+ break;
140
+ case "ERROR":
141
+ console.error(prefix, message, logData ?? "");
142
+ break;
143
+ }
144
+ };
145
+ return {
146
+ debug: (msg, data, cid) => log3("DEBUG", msg, data, cid),
147
+ info: (msg, data, cid) => log3("INFO", msg, data, cid),
148
+ warn: (msg, data, cid) => log3("WARN", msg, data, cid),
149
+ error: (msg, data, cid) => log3("ERROR", msg, data, cid)
150
+ };
151
+ }
152
+
153
+ // hooks/useEventBus.ts
154
+ var log = createLogger("almadar:eventbus");
155
+ var subLog = createLogger("almadar:eventbus:subscribe");
94
156
  function getGlobalEventBus() {
95
157
  if (typeof window !== "undefined") {
96
158
  return window.__kflowEventBus ?? null;
@@ -107,6 +169,7 @@ var fallbackEventBus = {
107
169
  timestamp: Date.now()
108
170
  };
109
171
  const handlers = fallbackListeners.get(type);
172
+ log.debug("emit", { type, payloadKeys: payload ? Object.keys(payload).length : 0, listenerCount: (handlers?.size ?? 0) + fallbackAnyListeners.size });
110
173
  if (handlers) {
111
174
  handlers.forEach((handler) => {
112
175
  try {
@@ -129,6 +192,7 @@ var fallbackEventBus = {
129
192
  fallbackListeners.set(type, /* @__PURE__ */ new Set());
130
193
  }
131
194
  fallbackListeners.get(type).add(listener);
195
+ subLog.debug("subscribe", { type, totalListeners: fallbackListeners.get(type).size });
132
196
  return () => {
133
197
  const handlers = fallbackListeners.get(type);
134
198
  if (handlers) {
@@ -152,6 +216,7 @@ var fallbackEventBus = {
152
216
  },
153
217
  onAny: (listener) => {
154
218
  fallbackAnyListeners.add(listener);
219
+ subLog.debug("subscribe:any", { totalAnyListeners: fallbackAnyListeners.size });
155
220
  return () => {
156
221
  fallbackAnyListeners.delete(listener);
157
222
  };
@@ -11626,6 +11691,7 @@ function GameOverScreen({
11626
11691
  GameOverScreen.displayName = "GameOverScreen";
11627
11692
 
11628
11693
  // lib/verificationRegistry.ts
11694
+ createLogger("almadar:bridge");
11629
11695
  function getState() {
11630
11696
  if (typeof window !== "undefined") {
11631
11697
  const w = window;
@@ -29152,6 +29218,7 @@ function calculateDamage(attack, defense, isDefending = false, criticalChance =
29152
29218
  function generateCombatMessage(event) {
29153
29219
  return event.message;
29154
29220
  }
29221
+ var storeLog = createLogger("almadar:entity:store");
29155
29222
  var store = /* @__PURE__ */ new Map();
29156
29223
  var storeListeners = /* @__PURE__ */ new Set();
29157
29224
  var watchCallbacks = /* @__PURE__ */ new Map();
@@ -29191,7 +29258,9 @@ function setAll(entityType, records) {
29191
29258
  }
29192
29259
  }
29193
29260
  const prev = store.get(entityType);
29194
- store.set(entityType, { entities: entities2, ids, version: (prev?.version ?? 0) + 1 });
29261
+ const newVersion = (prev?.version ?? 0) + 1;
29262
+ store.set(entityType, { entities: entities2, ids, version: newVersion });
29263
+ storeLog.debug("setAll", { entityType, recordCount: records.length, version: newVersion });
29195
29264
  notifyListeners(entityType, prev);
29196
29265
  }
29197
29266
  function upsertOne(entityType, record) {
@@ -29203,6 +29272,7 @@ function upsertOne(entityType, record) {
29203
29272
  if (!snapshot.ids.includes(id)) snapshot.ids.push(id);
29204
29273
  snapshot.version++;
29205
29274
  store.set(entityType, snapshot);
29275
+ storeLog.debug("upsertOne", { entityType, id, version: snapshot.version });
29206
29276
  notifyListeners(entityType, prev);
29207
29277
  }
29208
29278
  function addOne(entityType, record) {
@@ -29219,6 +29289,7 @@ function updateOne(entityType, id, changes) {
29219
29289
  snapshot.entities.set(id, { ...snapshot.entities.get(id), ...changes });
29220
29290
  snapshot.version++;
29221
29291
  store.set(entityType, snapshot);
29292
+ storeLog.debug("updateOne", { entityType, id, changedFields: Object.keys(changes), version: snapshot.version });
29222
29293
  notifyListeners(entityType, prev);
29223
29294
  }
29224
29295
  function removeOne(entityType, id) {
@@ -29232,6 +29303,7 @@ function removeOne(entityType, id) {
29232
29303
  snapshot.entities.delete(id);
29233
29304
  snapshot.version++;
29234
29305
  store.set(entityType, snapshot);
29306
+ storeLog.debug("removeOne", { entityType, id, remainingCount: snapshot.ids.length, version: snapshot.version });
29235
29307
  notifyListeners(entityType, prev);
29236
29308
  }
29237
29309
  function getSnapshot2(entityType) {
@@ -33386,7 +33458,7 @@ function getAllEvents(traits2) {
33386
33458
  }
33387
33459
  function EventDispatcherTab({ traits: traits2, schema }) {
33388
33460
  const eventBus = useEventBus();
33389
- const [log, setLog] = React90__namespace.useState([]);
33461
+ const [log3, setLog] = React90__namespace.useState([]);
33390
33462
  const prevStatesRef = React90__namespace.useRef(/* @__PURE__ */ new Map());
33391
33463
  React90__namespace.useEffect(() => {
33392
33464
  for (const trait of traits2) {
@@ -33450,9 +33522,9 @@ function EventDispatcherTab({ traits: traits2, schema }) {
33450
33522
  /* @__PURE__ */ jsxRuntime.jsx(Typography, { variant: "small", weight: "medium", className: "text-gray-500 mb-1", children: "Other Events (not available from current state)" }),
33451
33523
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-wrap gap-1", children: unavailableEvents.map((event) => /* @__PURE__ */ jsxRuntime.jsx(Badge, { variant: "default", size: "sm", className: "opacity-50", children: event }, event)) })
33452
33524
  ] }),
33453
- log.length > 0 && /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
33525
+ log3.length > 0 && /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
33454
33526
  /* @__PURE__ */ jsxRuntime.jsx(Typography, { variant: "small", weight: "medium", className: "text-gray-500 mb-1", children: "Recent Transitions" }),
33455
- /* @__PURE__ */ jsxRuntime.jsx(Stack, { gap: "xs", children: log.map((entry, i) => /* @__PURE__ */ jsxRuntime.jsxs(Typography, { variant: "small", className: "font-mono text-xs", children: [
33527
+ /* @__PURE__ */ jsxRuntime.jsx(Stack, { gap: "xs", children: log3.map((entry, i) => /* @__PURE__ */ jsxRuntime.jsxs(Typography, { variant: "small", className: "font-mono text-xs", children: [
33456
33528
  /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-purple-400", children: entry.traitName }),
33457
33529
  " ",
33458
33530
  /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-gray-500", children: entry.from }),
@@ -37275,21 +37347,21 @@ function useOrbitalMutations(entityName, orbitalName, options) {
37275
37347
  update: options?.events?.update || ENTITY_EVENTS.UPDATE,
37276
37348
  delete: options?.events?.delete || ENTITY_EVENTS.DELETE
37277
37349
  };
37278
- const log = (message, data) => {
37350
+ const log3 = (message, data) => {
37279
37351
  if (options?.debug) {
37280
37352
  console.log(`[useOrbitalMutations:${orbitalName}] ${message}`, data ?? "");
37281
37353
  }
37282
37354
  };
37283
37355
  const createMutation = reactQuery.useMutation({
37284
37356
  mutationFn: async (data) => {
37285
- log("Creating entity", data);
37357
+ log3("Creating entity", data);
37286
37358
  return sendOrbitalEvent(orbitalName, {
37287
37359
  event: events2.create,
37288
37360
  payload: { data, entityType: entityName }
37289
37361
  });
37290
37362
  },
37291
37363
  onSuccess: (response) => {
37292
- log("Create succeeded", response);
37364
+ log3("Create succeeded", response);
37293
37365
  queryClient.invalidateQueries({ queryKey: entityDataKeys.list(entityName) });
37294
37366
  },
37295
37367
  onError: (error) => {
@@ -37301,7 +37373,7 @@ function useOrbitalMutations(entityName, orbitalName, options) {
37301
37373
  id,
37302
37374
  data
37303
37375
  }) => {
37304
- log(`Updating entity ${id}`, data);
37376
+ log3(`Updating entity ${id}`, data);
37305
37377
  return sendOrbitalEvent(orbitalName, {
37306
37378
  event: events2.update,
37307
37379
  entityId: id,
@@ -37309,7 +37381,7 @@ function useOrbitalMutations(entityName, orbitalName, options) {
37309
37381
  });
37310
37382
  },
37311
37383
  onSuccess: (response, variables) => {
37312
- log("Update succeeded", response);
37384
+ log3("Update succeeded", response);
37313
37385
  queryClient.invalidateQueries({ queryKey: entityDataKeys.list(entityName) });
37314
37386
  queryClient.invalidateQueries({
37315
37387
  queryKey: entityDataKeys.detail(entityName, variables.id)
@@ -37321,7 +37393,7 @@ function useOrbitalMutations(entityName, orbitalName, options) {
37321
37393
  });
37322
37394
  const deleteMutation = reactQuery.useMutation({
37323
37395
  mutationFn: async (id) => {
37324
- log(`Deleting entity ${id}`);
37396
+ log3(`Deleting entity ${id}`);
37325
37397
  return sendOrbitalEvent(orbitalName, {
37326
37398
  event: events2.delete,
37327
37399
  entityId: id,
@@ -37329,7 +37401,7 @@ function useOrbitalMutations(entityName, orbitalName, options) {
37329
37401
  });
37330
37402
  },
37331
37403
  onSuccess: (response, id) => {
37332
- log("Delete succeeded", response);
37404
+ log3("Delete succeeded", response);
37333
37405
  queryClient.invalidateQueries({ queryKey: entityDataKeys.list(entityName) });
37334
37406
  queryClient.removeQueries({ queryKey: entityDataKeys.detail(entityName, id) });
37335
37407
  },
@@ -45,6 +45,67 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
45
45
  function cn(...inputs) {
46
46
  return twMerge(clsx(inputs));
47
47
  }
48
+
49
+ // lib/logger.ts
50
+ var LEVEL_PRIORITY = { DEBUG: 0, INFO: 1, WARN: 2, ERROR: 3 };
51
+ var ENV = typeof process !== "undefined" && process.env ? process.env : {};
52
+ var VITE_ENV = typeof globalThis !== "undefined" && globalThis.__vite_env__ ? globalThis.__vite_env__ : {};
53
+ function getViteEnv(key) {
54
+ try {
55
+ const meta = import.meta;
56
+ return meta?.env?.[key];
57
+ } catch {
58
+ return void 0;
59
+ }
60
+ }
61
+ function envGet(key, viteKey) {
62
+ return ENV[key] ?? (viteKey ? getViteEnv(viteKey) : void 0) ?? VITE_ENV[viteKey ?? key];
63
+ }
64
+ var NODE_ENV = envGet("NODE_ENV", "VITE_NODE_ENV") ?? "development";
65
+ var CONFIGURED_LEVEL = (envGet("LOG_LEVEL", "VITE_LOG_LEVEL") ?? (NODE_ENV === "production" ? "info" : "debug")).toUpperCase();
66
+ var MIN_PRIORITY = LEVEL_PRIORITY[CONFIGURED_LEVEL] ?? 0;
67
+ var DEBUG_FILTER = (envGet("ALMADAR_DEBUG", "VITE_ALMADAR_DEBUG") ?? "").split(",").map((s) => s.trim()).filter(Boolean);
68
+ function matchesNamespace(namespace) {
69
+ if (DEBUG_FILTER.length === 0) return true;
70
+ return DEBUG_FILTER.some((pattern) => {
71
+ if (pattern === "*" || pattern === "almadar:*") return true;
72
+ if (pattern.endsWith(":*")) return namespace.startsWith(pattern.slice(0, -1));
73
+ return namespace === pattern;
74
+ });
75
+ }
76
+ function createLogger(namespace) {
77
+ const nsAllowed = matchesNamespace(namespace);
78
+ const log3 = (level, message, data, correlationId) => {
79
+ if (LEVEL_PRIORITY[level] < MIN_PRIORITY) return;
80
+ if (level === "DEBUG" && !nsAllowed) return;
81
+ const prefix = `[${namespace}]`;
82
+ const logData = correlationId ? { ...data, cid: correlationId } : data;
83
+ switch (level) {
84
+ case "DEBUG":
85
+ console.debug(prefix, message, logData ?? "");
86
+ break;
87
+ case "INFO":
88
+ console.info(prefix, message, logData ?? "");
89
+ break;
90
+ case "WARN":
91
+ console.warn(prefix, message, logData ?? "");
92
+ break;
93
+ case "ERROR":
94
+ console.error(prefix, message, logData ?? "");
95
+ break;
96
+ }
97
+ };
98
+ return {
99
+ debug: (msg, data, cid) => log3("DEBUG", msg, data, cid),
100
+ info: (msg, data, cid) => log3("INFO", msg, data, cid),
101
+ warn: (msg, data, cid) => log3("WARN", msg, data, cid),
102
+ error: (msg, data, cid) => log3("ERROR", msg, data, cid)
103
+ };
104
+ }
105
+
106
+ // hooks/useEventBus.ts
107
+ var log = createLogger("almadar:eventbus");
108
+ var subLog = createLogger("almadar:eventbus:subscribe");
48
109
  function getGlobalEventBus() {
49
110
  if (typeof window !== "undefined") {
50
111
  return window.__kflowEventBus ?? null;
@@ -61,6 +122,7 @@ var fallbackEventBus = {
61
122
  timestamp: Date.now()
62
123
  };
63
124
  const handlers = fallbackListeners.get(type);
125
+ log.debug("emit", { type, payloadKeys: payload ? Object.keys(payload).length : 0, listenerCount: (handlers?.size ?? 0) + fallbackAnyListeners.size });
64
126
  if (handlers) {
65
127
  handlers.forEach((handler) => {
66
128
  try {
@@ -83,6 +145,7 @@ var fallbackEventBus = {
83
145
  fallbackListeners.set(type, /* @__PURE__ */ new Set());
84
146
  }
85
147
  fallbackListeners.get(type).add(listener);
148
+ subLog.debug("subscribe", { type, totalListeners: fallbackListeners.get(type).size });
86
149
  return () => {
87
150
  const handlers = fallbackListeners.get(type);
88
151
  if (handlers) {
@@ -106,6 +169,7 @@ var fallbackEventBus = {
106
169
  },
107
170
  onAny: (listener) => {
108
171
  fallbackAnyListeners.add(listener);
172
+ subLog.debug("subscribe:any", { totalAnyListeners: fallbackAnyListeners.size });
109
173
  return () => {
110
174
  fallbackAnyListeners.delete(listener);
111
175
  };
@@ -11580,6 +11644,7 @@ function GameOverScreen({
11580
11644
  GameOverScreen.displayName = "GameOverScreen";
11581
11645
 
11582
11646
  // lib/verificationRegistry.ts
11647
+ createLogger("almadar:bridge");
11583
11648
  function getState() {
11584
11649
  if (typeof window !== "undefined") {
11585
11650
  const w = window;
@@ -29106,6 +29171,7 @@ function calculateDamage(attack, defense, isDefending = false, criticalChance =
29106
29171
  function generateCombatMessage(event) {
29107
29172
  return event.message;
29108
29173
  }
29174
+ var storeLog = createLogger("almadar:entity:store");
29109
29175
  var store = /* @__PURE__ */ new Map();
29110
29176
  var storeListeners = /* @__PURE__ */ new Set();
29111
29177
  var watchCallbacks = /* @__PURE__ */ new Map();
@@ -29145,7 +29211,9 @@ function setAll(entityType, records) {
29145
29211
  }
29146
29212
  }
29147
29213
  const prev = store.get(entityType);
29148
- store.set(entityType, { entities: entities2, ids, version: (prev?.version ?? 0) + 1 });
29214
+ const newVersion = (prev?.version ?? 0) + 1;
29215
+ store.set(entityType, { entities: entities2, ids, version: newVersion });
29216
+ storeLog.debug("setAll", { entityType, recordCount: records.length, version: newVersion });
29149
29217
  notifyListeners(entityType, prev);
29150
29218
  }
29151
29219
  function upsertOne(entityType, record) {
@@ -29157,6 +29225,7 @@ function upsertOne(entityType, record) {
29157
29225
  if (!snapshot.ids.includes(id)) snapshot.ids.push(id);
29158
29226
  snapshot.version++;
29159
29227
  store.set(entityType, snapshot);
29228
+ storeLog.debug("upsertOne", { entityType, id, version: snapshot.version });
29160
29229
  notifyListeners(entityType, prev);
29161
29230
  }
29162
29231
  function addOne(entityType, record) {
@@ -29173,6 +29242,7 @@ function updateOne(entityType, id, changes) {
29173
29242
  snapshot.entities.set(id, { ...snapshot.entities.get(id), ...changes });
29174
29243
  snapshot.version++;
29175
29244
  store.set(entityType, snapshot);
29245
+ storeLog.debug("updateOne", { entityType, id, changedFields: Object.keys(changes), version: snapshot.version });
29176
29246
  notifyListeners(entityType, prev);
29177
29247
  }
29178
29248
  function removeOne(entityType, id) {
@@ -29186,6 +29256,7 @@ function removeOne(entityType, id) {
29186
29256
  snapshot.entities.delete(id);
29187
29257
  snapshot.version++;
29188
29258
  store.set(entityType, snapshot);
29259
+ storeLog.debug("removeOne", { entityType, id, remainingCount: snapshot.ids.length, version: snapshot.version });
29189
29260
  notifyListeners(entityType, prev);
29190
29261
  }
29191
29262
  function getSnapshot2(entityType) {
@@ -33340,7 +33411,7 @@ function getAllEvents(traits2) {
33340
33411
  }
33341
33412
  function EventDispatcherTab({ traits: traits2, schema }) {
33342
33413
  const eventBus = useEventBus();
33343
- const [log, setLog] = React90.useState([]);
33414
+ const [log3, setLog] = React90.useState([]);
33344
33415
  const prevStatesRef = React90.useRef(/* @__PURE__ */ new Map());
33345
33416
  React90.useEffect(() => {
33346
33417
  for (const trait of traits2) {
@@ -33404,9 +33475,9 @@ function EventDispatcherTab({ traits: traits2, schema }) {
33404
33475
  /* @__PURE__ */ jsx(Typography, { variant: "small", weight: "medium", className: "text-gray-500 mb-1", children: "Other Events (not available from current state)" }),
33405
33476
  /* @__PURE__ */ jsx("div", { className: "flex flex-wrap gap-1", children: unavailableEvents.map((event) => /* @__PURE__ */ jsx(Badge, { variant: "default", size: "sm", className: "opacity-50", children: event }, event)) })
33406
33477
  ] }),
33407
- log.length > 0 && /* @__PURE__ */ jsxs("div", { children: [
33478
+ log3.length > 0 && /* @__PURE__ */ jsxs("div", { children: [
33408
33479
  /* @__PURE__ */ jsx(Typography, { variant: "small", weight: "medium", className: "text-gray-500 mb-1", children: "Recent Transitions" }),
33409
- /* @__PURE__ */ jsx(Stack, { gap: "xs", children: log.map((entry, i) => /* @__PURE__ */ jsxs(Typography, { variant: "small", className: "font-mono text-xs", children: [
33480
+ /* @__PURE__ */ jsx(Stack, { gap: "xs", children: log3.map((entry, i) => /* @__PURE__ */ jsxs(Typography, { variant: "small", className: "font-mono text-xs", children: [
33410
33481
  /* @__PURE__ */ jsx("span", { className: "text-purple-400", children: entry.traitName }),
33411
33482
  " ",
33412
33483
  /* @__PURE__ */ jsx("span", { className: "text-gray-500", children: entry.from }),
@@ -37229,21 +37300,21 @@ function useOrbitalMutations(entityName, orbitalName, options) {
37229
37300
  update: options?.events?.update || ENTITY_EVENTS.UPDATE,
37230
37301
  delete: options?.events?.delete || ENTITY_EVENTS.DELETE
37231
37302
  };
37232
- const log = (message, data) => {
37303
+ const log3 = (message, data) => {
37233
37304
  if (options?.debug) {
37234
37305
  console.log(`[useOrbitalMutations:${orbitalName}] ${message}`, data ?? "");
37235
37306
  }
37236
37307
  };
37237
37308
  const createMutation = useMutation({
37238
37309
  mutationFn: async (data) => {
37239
- log("Creating entity", data);
37310
+ log3("Creating entity", data);
37240
37311
  return sendOrbitalEvent(orbitalName, {
37241
37312
  event: events2.create,
37242
37313
  payload: { data, entityType: entityName }
37243
37314
  });
37244
37315
  },
37245
37316
  onSuccess: (response) => {
37246
- log("Create succeeded", response);
37317
+ log3("Create succeeded", response);
37247
37318
  queryClient.invalidateQueries({ queryKey: entityDataKeys.list(entityName) });
37248
37319
  },
37249
37320
  onError: (error) => {
@@ -37255,7 +37326,7 @@ function useOrbitalMutations(entityName, orbitalName, options) {
37255
37326
  id,
37256
37327
  data
37257
37328
  }) => {
37258
- log(`Updating entity ${id}`, data);
37329
+ log3(`Updating entity ${id}`, data);
37259
37330
  return sendOrbitalEvent(orbitalName, {
37260
37331
  event: events2.update,
37261
37332
  entityId: id,
@@ -37263,7 +37334,7 @@ function useOrbitalMutations(entityName, orbitalName, options) {
37263
37334
  });
37264
37335
  },
37265
37336
  onSuccess: (response, variables) => {
37266
- log("Update succeeded", response);
37337
+ log3("Update succeeded", response);
37267
37338
  queryClient.invalidateQueries({ queryKey: entityDataKeys.list(entityName) });
37268
37339
  queryClient.invalidateQueries({
37269
37340
  queryKey: entityDataKeys.detail(entityName, variables.id)
@@ -37275,7 +37346,7 @@ function useOrbitalMutations(entityName, orbitalName, options) {
37275
37346
  });
37276
37347
  const deleteMutation = useMutation({
37277
37348
  mutationFn: async (id) => {
37278
- log(`Deleting entity ${id}`);
37349
+ log3(`Deleting entity ${id}`);
37279
37350
  return sendOrbitalEvent(orbitalName, {
37280
37351
  event: events2.delete,
37281
37352
  entityId: id,
@@ -37283,7 +37354,7 @@ function useOrbitalMutations(entityName, orbitalName, options) {
37283
37354
  });
37284
37355
  },
37285
37356
  onSuccess: (response, id) => {
37286
- log("Delete succeeded", response);
37357
+ log3("Delete succeeded", response);
37287
37358
  queryClient.invalidateQueries({ queryKey: entityDataKeys.list(entityName) });
37288
37359
  queryClient.removeQueries({ queryKey: entityDataKeys.detail(entityName, id) });
37289
37360
  },
@@ -14,6 +14,7 @@ var clsx = require('clsx');
14
14
  var tailwindMerge = require('tailwind-merge');
15
15
  var postprocessing = require('@react-three/postprocessing');
16
16
 
17
+ var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
17
18
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
18
19
 
19
20
  function _interopNamespace(e) {
@@ -1375,6 +1376,67 @@ function useRaycaster(options) {
1375
1376
  isWithinCanvas
1376
1377
  };
1377
1378
  }
1379
+
1380
+ // lib/logger.ts
1381
+ var LEVEL_PRIORITY = { DEBUG: 0, INFO: 1, WARN: 2, ERROR: 3 };
1382
+ var ENV = typeof process !== "undefined" && process.env ? process.env : {};
1383
+ var VITE_ENV = typeof globalThis !== "undefined" && globalThis.__vite_env__ ? globalThis.__vite_env__ : {};
1384
+ function getViteEnv(key) {
1385
+ try {
1386
+ const meta = ({ url: (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)) });
1387
+ return meta?.env?.[key];
1388
+ } catch {
1389
+ return void 0;
1390
+ }
1391
+ }
1392
+ function envGet(key, viteKey) {
1393
+ return ENV[key] ?? (viteKey ? getViteEnv(viteKey) : void 0) ?? VITE_ENV[viteKey ?? key];
1394
+ }
1395
+ var NODE_ENV = envGet("NODE_ENV", "VITE_NODE_ENV") ?? "development";
1396
+ var CONFIGURED_LEVEL = (envGet("LOG_LEVEL", "VITE_LOG_LEVEL") ?? (NODE_ENV === "production" ? "info" : "debug")).toUpperCase();
1397
+ var MIN_PRIORITY = LEVEL_PRIORITY[CONFIGURED_LEVEL] ?? 0;
1398
+ var DEBUG_FILTER = (envGet("ALMADAR_DEBUG", "VITE_ALMADAR_DEBUG") ?? "").split(",").map((s) => s.trim()).filter(Boolean);
1399
+ function matchesNamespace(namespace) {
1400
+ if (DEBUG_FILTER.length === 0) return true;
1401
+ return DEBUG_FILTER.some((pattern) => {
1402
+ if (pattern === "*" || pattern === "almadar:*") return true;
1403
+ if (pattern.endsWith(":*")) return namespace.startsWith(pattern.slice(0, -1));
1404
+ return namespace === pattern;
1405
+ });
1406
+ }
1407
+ function createLogger(namespace) {
1408
+ const nsAllowed = matchesNamespace(namespace);
1409
+ const log2 = (level, message, data, correlationId) => {
1410
+ if (LEVEL_PRIORITY[level] < MIN_PRIORITY) return;
1411
+ if (level === "DEBUG" && !nsAllowed) return;
1412
+ const prefix = `[${namespace}]`;
1413
+ const logData = correlationId ? { ...data, cid: correlationId } : data;
1414
+ switch (level) {
1415
+ case "DEBUG":
1416
+ console.debug(prefix, message, logData ?? "");
1417
+ break;
1418
+ case "INFO":
1419
+ console.info(prefix, message, logData ?? "");
1420
+ break;
1421
+ case "WARN":
1422
+ console.warn(prefix, message, logData ?? "");
1423
+ break;
1424
+ case "ERROR":
1425
+ console.error(prefix, message, logData ?? "");
1426
+ break;
1427
+ }
1428
+ };
1429
+ return {
1430
+ debug: (msg, data, cid) => log2("DEBUG", msg, data, cid),
1431
+ info: (msg, data, cid) => log2("INFO", msg, data, cid),
1432
+ warn: (msg, data, cid) => log2("WARN", msg, data, cid),
1433
+ error: (msg, data, cid) => log2("ERROR", msg, data, cid)
1434
+ };
1435
+ }
1436
+
1437
+ // hooks/useEventBus.ts
1438
+ var log = createLogger("almadar:eventbus");
1439
+ var subLog = createLogger("almadar:eventbus:subscribe");
1378
1440
  function getGlobalEventBus() {
1379
1441
  if (typeof window !== "undefined") {
1380
1442
  return window.__kflowEventBus ?? null;
@@ -1391,6 +1453,7 @@ var fallbackEventBus = {
1391
1453
  timestamp: Date.now()
1392
1454
  };
1393
1455
  const handlers = fallbackListeners.get(type);
1456
+ log.debug("emit", { type, payloadKeys: payload ? Object.keys(payload).length : 0, listenerCount: (handlers?.size ?? 0) + fallbackAnyListeners.size });
1394
1457
  if (handlers) {
1395
1458
  handlers.forEach((handler) => {
1396
1459
  try {
@@ -1413,6 +1476,7 @@ var fallbackEventBus = {
1413
1476
  fallbackListeners.set(type, /* @__PURE__ */ new Set());
1414
1477
  }
1415
1478
  fallbackListeners.get(type).add(listener);
1479
+ subLog.debug("subscribe", { type, totalListeners: fallbackListeners.get(type).size });
1416
1480
  return () => {
1417
1481
  const handlers = fallbackListeners.get(type);
1418
1482
  if (handlers) {
@@ -1436,6 +1500,7 @@ var fallbackEventBus = {
1436
1500
  },
1437
1501
  onAny: (listener) => {
1438
1502
  fallbackAnyListeners.add(listener);
1503
+ subLog.debug("subscribe:any", { totalAnyListeners: fallbackAnyListeners.size });
1439
1504
  return () => {
1440
1505
  fallbackAnyListeners.delete(listener);
1441
1506
  };
@@ -1351,6 +1351,67 @@ function useRaycaster(options) {
1351
1351
  isWithinCanvas
1352
1352
  };
1353
1353
  }
1354
+
1355
+ // lib/logger.ts
1356
+ var LEVEL_PRIORITY = { DEBUG: 0, INFO: 1, WARN: 2, ERROR: 3 };
1357
+ var ENV = typeof process !== "undefined" && process.env ? process.env : {};
1358
+ var VITE_ENV = typeof globalThis !== "undefined" && globalThis.__vite_env__ ? globalThis.__vite_env__ : {};
1359
+ function getViteEnv(key) {
1360
+ try {
1361
+ const meta = import.meta;
1362
+ return meta?.env?.[key];
1363
+ } catch {
1364
+ return void 0;
1365
+ }
1366
+ }
1367
+ function envGet(key, viteKey) {
1368
+ return ENV[key] ?? (viteKey ? getViteEnv(viteKey) : void 0) ?? VITE_ENV[viteKey ?? key];
1369
+ }
1370
+ var NODE_ENV = envGet("NODE_ENV", "VITE_NODE_ENV") ?? "development";
1371
+ var CONFIGURED_LEVEL = (envGet("LOG_LEVEL", "VITE_LOG_LEVEL") ?? (NODE_ENV === "production" ? "info" : "debug")).toUpperCase();
1372
+ var MIN_PRIORITY = LEVEL_PRIORITY[CONFIGURED_LEVEL] ?? 0;
1373
+ var DEBUG_FILTER = (envGet("ALMADAR_DEBUG", "VITE_ALMADAR_DEBUG") ?? "").split(",").map((s) => s.trim()).filter(Boolean);
1374
+ function matchesNamespace(namespace) {
1375
+ if (DEBUG_FILTER.length === 0) return true;
1376
+ return DEBUG_FILTER.some((pattern) => {
1377
+ if (pattern === "*" || pattern === "almadar:*") return true;
1378
+ if (pattern.endsWith(":*")) return namespace.startsWith(pattern.slice(0, -1));
1379
+ return namespace === pattern;
1380
+ });
1381
+ }
1382
+ function createLogger(namespace) {
1383
+ const nsAllowed = matchesNamespace(namespace);
1384
+ const log2 = (level, message, data, correlationId) => {
1385
+ if (LEVEL_PRIORITY[level] < MIN_PRIORITY) return;
1386
+ if (level === "DEBUG" && !nsAllowed) return;
1387
+ const prefix = `[${namespace}]`;
1388
+ const logData = correlationId ? { ...data, cid: correlationId } : data;
1389
+ switch (level) {
1390
+ case "DEBUG":
1391
+ console.debug(prefix, message, logData ?? "");
1392
+ break;
1393
+ case "INFO":
1394
+ console.info(prefix, message, logData ?? "");
1395
+ break;
1396
+ case "WARN":
1397
+ console.warn(prefix, message, logData ?? "");
1398
+ break;
1399
+ case "ERROR":
1400
+ console.error(prefix, message, logData ?? "");
1401
+ break;
1402
+ }
1403
+ };
1404
+ return {
1405
+ debug: (msg, data, cid) => log2("DEBUG", msg, data, cid),
1406
+ info: (msg, data, cid) => log2("INFO", msg, data, cid),
1407
+ warn: (msg, data, cid) => log2("WARN", msg, data, cid),
1408
+ error: (msg, data, cid) => log2("ERROR", msg, data, cid)
1409
+ };
1410
+ }
1411
+
1412
+ // hooks/useEventBus.ts
1413
+ var log = createLogger("almadar:eventbus");
1414
+ var subLog = createLogger("almadar:eventbus:subscribe");
1354
1415
  function getGlobalEventBus() {
1355
1416
  if (typeof window !== "undefined") {
1356
1417
  return window.__kflowEventBus ?? null;
@@ -1367,6 +1428,7 @@ var fallbackEventBus = {
1367
1428
  timestamp: Date.now()
1368
1429
  };
1369
1430
  const handlers = fallbackListeners.get(type);
1431
+ log.debug("emit", { type, payloadKeys: payload ? Object.keys(payload).length : 0, listenerCount: (handlers?.size ?? 0) + fallbackAnyListeners.size });
1370
1432
  if (handlers) {
1371
1433
  handlers.forEach((handler) => {
1372
1434
  try {
@@ -1389,6 +1451,7 @@ var fallbackEventBus = {
1389
1451
  fallbackListeners.set(type, /* @__PURE__ */ new Set());
1390
1452
  }
1391
1453
  fallbackListeners.get(type).add(listener);
1454
+ subLog.debug("subscribe", { type, totalListeners: fallbackListeners.get(type).size });
1392
1455
  return () => {
1393
1456
  const handlers = fallbackListeners.get(type);
1394
1457
  if (handlers) {
@@ -1412,6 +1475,7 @@ var fallbackEventBus = {
1412
1475
  },
1413
1476
  onAny: (listener) => {
1414
1477
  fallbackAnyListeners.add(listener);
1478
+ subLog.debug("subscribe:any", { totalAnyListeners: fallbackAnyListeners.size });
1415
1479
  return () => {
1416
1480
  fallbackAnyListeners.delete(listener);
1417
1481
  };