tevrocsdk 0.1.76 → 0.1.77

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tevrocsdk",
3
- "version": "0.1.76",
3
+ "version": "0.1.77",
4
4
  "description": "JavaScript SDK for the Tevroc API.",
5
5
  "main": "./tevroc-sdk.umd.js",
6
6
  "module": "./tevroc-sdk.esm.js",
package/tevroc-sdk.cjs.js CHANGED
@@ -3803,7 +3803,7 @@ var init_useGoogleAuth = __esm({
3803
3803
  debugLog("appId:", appId, "serviceUrl:", serviceUrl);
3804
3804
  debugLog(isCapacitor, isTauri);
3805
3805
  await initializeGoogleLogin();
3806
- let authUrl = `${serviceUrl}/login?mode=mobile&app=${encodeURIComponent(appId)}&name=${encodeURIComponent(appName)}`;
3806
+ let authUrl = `${serviceUrl}/auth/google/login?mode=mobile&app=${encodeURIComponent(appId)}&name=${encodeURIComponent(appName)}`;
3807
3807
  if (isCapacitor) {
3808
3808
  const { Browser } = await getCapacitorPlugins();
3809
3809
  await Browser.open({ url: authUrl });
@@ -3812,7 +3812,7 @@ var init_useGoogleAuth = __esm({
3812
3812
  if (isTauri) {
3813
3813
  const WebviewWindow2 = await getTauriWebviewWindow();
3814
3814
  await closeAllTauriWebviews();
3815
- const url = `${serviceUrl}/login?mode=desktop&app=${encodeURIComponent(appId)}&name=${encodeURIComponent(appName)}`;
3815
+ const url = `${serviceUrl}/auth/google/login?mode=desktop&app=${encodeURIComponent(appId)}&name=${encodeURIComponent(appName)}`;
3816
3816
  const win = new WebviewWindow2("auth", {
3817
3817
  url,
3818
3818
  title: `${appName} Login`,
@@ -3833,7 +3833,7 @@ var init_useGoogleAuth = __esm({
3833
3833
  const isLocalhost = true;
3834
3834
  const detectedAppId = typeof window !== "undefined" ? window.location.host : appId;
3835
3835
  const mode = isLocalhost ? "localhost" : "netlify";
3836
- const finalUrl = `${serviceUrl}/login?mode=${mode}&app=${encodeURIComponent(
3836
+ const finalUrl = `${serviceUrl}/auth/google/login?mode=${mode}&app=${encodeURIComponent(
3837
3837
  detectedAppId
3838
3838
  )}&name=${encodeURIComponent(appName)}`;
3839
3839
  if (isLocalhost) {
@@ -47243,6 +47243,131 @@ function createPdfApi() {
47243
47243
  };
47244
47244
  }
47245
47245
 
47246
+ // src/services/notifications.js
47247
+ var isBrowser = () => typeof window !== "undefined" && typeof Notification !== "undefined";
47248
+ function createNotificationService() {
47249
+ const listeners2 = /* @__PURE__ */ new Set();
47250
+ const scheduled = /* @__PURE__ */ new Map();
47251
+ let nativeListenerInstalled = false;
47252
+ const emit2 = (event) => listeners2.forEach((listener) => listener(event));
47253
+ const appPlugin = () => globalThis?.Capacitor?.Plugins?.AppNotifications;
47254
+ const installNativeListener = () => {
47255
+ if (nativeListenerInstalled) return;
47256
+ const plugin = appPlugin();
47257
+ if (!plugin?.addListener) return;
47258
+ nativeListenerInstalled = true;
47259
+ plugin.addListener("notificationAction", (event) => {
47260
+ let data = event?.data || {};
47261
+ if (typeof data === "string") {
47262
+ try {
47263
+ data = JSON.parse(data);
47264
+ } catch {
47265
+ data = {};
47266
+ }
47267
+ }
47268
+ emit2({
47269
+ id: event?.id,
47270
+ action: event?.action || "open",
47271
+ reply: event?.reply || "",
47272
+ data,
47273
+ platform: "capacitor"
47274
+ });
47275
+ });
47276
+ plugin.consumePendingAction?.().catch?.(() => {
47277
+ });
47278
+ };
47279
+ const permission = async () => {
47280
+ const plugin = appPlugin();
47281
+ if (plugin?.checkPermissions) return plugin.checkPermissions();
47282
+ if (globalThis?.__TAURI_INTERNALS__) {
47283
+ try {
47284
+ const tauri = await new Function("name", "return import(name)")("@tauri-apps/plugin-notification");
47285
+ return { display: await tauri.isPermissionGranted() ? "granted" : "prompt" };
47286
+ } catch {
47287
+ return { display: "denied" };
47288
+ }
47289
+ }
47290
+ return { display: isBrowser() ? Notification.permission : "denied" };
47291
+ };
47292
+ const requestPermission = async () => {
47293
+ const plugin = appPlugin();
47294
+ if (plugin?.requestPermissions) return plugin.requestPermissions();
47295
+ if (globalThis?.__TAURI_INTERNALS__) {
47296
+ try {
47297
+ const tauri = await new Function("name", "return import(name)")("@tauri-apps/plugin-notification");
47298
+ return { display: await tauri.requestPermission() };
47299
+ } catch {
47300
+ return { display: "denied" };
47301
+ }
47302
+ }
47303
+ return { display: isBrowser() ? await Notification.requestPermission() : "denied" };
47304
+ };
47305
+ const show = async (options = {}) => {
47306
+ const id = String(options.id || `notification_${Date.now()}_${Math.random().toString(36).slice(2)}`);
47307
+ const request = {
47308
+ id,
47309
+ title: options.title || "Notification",
47310
+ body: options.body || "",
47311
+ data: options.data || {},
47312
+ actions: options.actions || [],
47313
+ silent: Boolean(options.silent),
47314
+ channel: options.channel || "general",
47315
+ style: options.style || {}
47316
+ };
47317
+ const plugin = appPlugin();
47318
+ if (plugin?.show) {
47319
+ installNativeListener();
47320
+ await plugin.show(request);
47321
+ return { id, platform: "capacitor" };
47322
+ }
47323
+ if (globalThis?.__TAURI_INTERNALS__) {
47324
+ try {
47325
+ const tauri = await new Function("name", "return import(name)")("@tauri-apps/plugin-notification");
47326
+ const current = await tauri.isPermissionGranted() ? "granted" : await tauri.requestPermission();
47327
+ if (current === "granted") {
47328
+ tauri.sendNotification({ title: request.title, body: request.body, extra: request.data });
47329
+ return { id, platform: "tauri" };
47330
+ }
47331
+ } catch {
47332
+ }
47333
+ }
47334
+ if (!isBrowser()) throw new Error("Notifications are not supported on this platform.");
47335
+ const state = Notification.permission === "default" ? await Notification.requestPermission() : Notification.permission;
47336
+ if (state !== "granted") throw new Error("Notification permission was not granted.");
47337
+ const notification = new Notification(request.title, { body: request.body, tag: id, data: request.data, silent: request.silent });
47338
+ notification.onclick = () => emit2({ id, action: "open", data: request.data, platform: "web" });
47339
+ return { id, platform: "web", notification };
47340
+ };
47341
+ const schedule = async (options = {}) => {
47342
+ const at = new Date(options.at || Date.now()).getTime();
47343
+ const delay = Math.max(0, at - Date.now());
47344
+ const id = String(options.id || `notification_${at}_${Math.random().toString(36).slice(2)}`);
47345
+ const timeout = setTimeout(() => {
47346
+ scheduled.delete(id);
47347
+ show({ ...options, id }).catch((error) => emit2({ type: "error", error }));
47348
+ }, delay);
47349
+ scheduled.set(id, timeout);
47350
+ return { id, at };
47351
+ };
47352
+ const cancel = async (id) => {
47353
+ const timeout = scheduled.get(String(id));
47354
+ if (timeout) clearTimeout(timeout);
47355
+ scheduled.delete(String(id));
47356
+ await appPlugin()?.cancel?.({ id: String(id) });
47357
+ };
47358
+ const cancelAll = async () => {
47359
+ for (const timeout of scheduled.values()) clearTimeout(timeout);
47360
+ scheduled.clear();
47361
+ await appPlugin()?.cancelAll?.();
47362
+ };
47363
+ const onAction = (listener) => {
47364
+ installNativeListener();
47365
+ listeners2.add(listener);
47366
+ return () => listeners2.delete(listener);
47367
+ };
47368
+ return { permission, requestPermission, show, schedule, cancel, cancelAll, onAction };
47369
+ }
47370
+
47246
47371
  // src/services/agentNotifications.js
47247
47372
  var toList = (result) => Array.isArray(result) ? result : result?.data || [];
47248
47373
  var latestByTime = (records) => [...records].sort((a, b) => {
@@ -47251,6 +47376,7 @@ var latestByTime = (records) => [...records].sort((a, b) => {
47251
47376
  return right - left;
47252
47377
  })[0] || null;
47253
47378
  function createAgentNotificationService(client) {
47379
+ const notifications = client.notifications || createNotificationService();
47254
47380
  let timer = null;
47255
47381
  let stopped = true;
47256
47382
  const seen = /* @__PURE__ */ new Map();
@@ -47331,7 +47457,7 @@ function createAgentNotificationService(client) {
47331
47457
  if (action === "reject") return reject(session);
47332
47458
  if (action === "reply") return reply(session, text);
47333
47459
  };
47334
- const showNative = (request) => client.notifications.show({
47460
+ const showNative = (request) => notifications.show({
47335
47461
  id: `agent-request-${request.sessionId}`,
47336
47462
  title: request.title,
47337
47463
  body: request.body,
@@ -47410,7 +47536,7 @@ function createAgentNotificationService(client) {
47410
47536
  listeners2.add(listener);
47411
47537
  return () => listeners2.delete(listener);
47412
47538
  };
47413
- client.notifications.onAction(({ action, data, reply: text }) => {
47539
+ notifications.onAction(({ action, data, reply: text }) => {
47414
47540
  if (data?.sessionId && String(data.kind || "").startsWith("agent_")) {
47415
47541
  dispatchAction({ action, sessionId: data.sessionId, reply: text }).catch((error) => notify({ type: "error", error }));
47416
47542
  }
@@ -47418,138 +47544,14 @@ function createAgentNotificationService(client) {
47418
47544
  return { start, stop, check, onEvent, accept, reject, reply, dispatchAction };
47419
47545
  }
47420
47546
 
47421
- // src/services/notifications.js
47422
- var isBrowser = () => typeof window !== "undefined" && typeof Notification !== "undefined";
47423
- function createNotificationService() {
47424
- const listeners2 = /* @__PURE__ */ new Set();
47425
- const scheduled = /* @__PURE__ */ new Map();
47426
- let nativeListenerInstalled = false;
47427
- const emit2 = (event) => listeners2.forEach((listener) => listener(event));
47428
- const appPlugin = () => globalThis?.Capacitor?.Plugins?.AppNotifications;
47429
- const installNativeListener = () => {
47430
- if (nativeListenerInstalled) return;
47431
- const plugin = appPlugin();
47432
- if (!plugin?.addListener) return;
47433
- nativeListenerInstalled = true;
47434
- plugin.addListener("notificationAction", (event) => {
47435
- let data = event?.data || {};
47436
- if (typeof data === "string") {
47437
- try {
47438
- data = JSON.parse(data);
47439
- } catch {
47440
- data = {};
47441
- }
47442
- }
47443
- emit2({
47444
- id: event?.id,
47445
- action: event?.action || "open",
47446
- reply: event?.reply || "",
47447
- data,
47448
- platform: "capacitor"
47449
- });
47450
- });
47451
- plugin.consumePendingAction?.().catch?.(() => {
47452
- });
47453
- };
47454
- const permission = async () => {
47455
- const plugin = appPlugin();
47456
- if (plugin?.checkPermissions) return plugin.checkPermissions();
47457
- if (globalThis?.__TAURI_INTERNALS__) {
47458
- try {
47459
- const tauri = await new Function("name", "return import(name)")("@tauri-apps/plugin-notification");
47460
- return { display: await tauri.isPermissionGranted() ? "granted" : "prompt" };
47461
- } catch {
47462
- return { display: "denied" };
47463
- }
47464
- }
47465
- return { display: isBrowser() ? Notification.permission : "denied" };
47466
- };
47467
- const requestPermission = async () => {
47468
- const plugin = appPlugin();
47469
- if (plugin?.requestPermissions) return plugin.requestPermissions();
47470
- if (globalThis?.__TAURI_INTERNALS__) {
47471
- try {
47472
- const tauri = await new Function("name", "return import(name)")("@tauri-apps/plugin-notification");
47473
- return { display: await tauri.requestPermission() };
47474
- } catch {
47475
- return { display: "denied" };
47476
- }
47477
- }
47478
- return { display: isBrowser() ? await Notification.requestPermission() : "denied" };
47479
- };
47480
- const show = async (options = {}) => {
47481
- const id = String(options.id || `notification_${Date.now()}_${Math.random().toString(36).slice(2)}`);
47482
- const request = {
47483
- id,
47484
- title: options.title || "Notification",
47485
- body: options.body || "",
47486
- data: options.data || {},
47487
- actions: options.actions || [],
47488
- silent: Boolean(options.silent),
47489
- channel: options.channel || "general",
47490
- style: options.style || {}
47491
- };
47492
- const plugin = appPlugin();
47493
- if (plugin?.show) {
47494
- installNativeListener();
47495
- await plugin.show(request);
47496
- return { id, platform: "capacitor" };
47497
- }
47498
- if (globalThis?.__TAURI_INTERNALS__) {
47499
- try {
47500
- const tauri = await new Function("name", "return import(name)")("@tauri-apps/plugin-notification");
47501
- const current = await tauri.isPermissionGranted() ? "granted" : await tauri.requestPermission();
47502
- if (current === "granted") {
47503
- tauri.sendNotification({ title: request.title, body: request.body, extra: request.data });
47504
- return { id, platform: "tauri" };
47505
- }
47506
- } catch {
47507
- }
47508
- }
47509
- if (!isBrowser()) throw new Error("Notifications are not supported on this platform.");
47510
- const state = Notification.permission === "default" ? await Notification.requestPermission() : Notification.permission;
47511
- if (state !== "granted") throw new Error("Notification permission was not granted.");
47512
- const notification = new Notification(request.title, { body: request.body, tag: id, data: request.data, silent: request.silent });
47513
- notification.onclick = () => emit2({ id, action: "open", data: request.data, platform: "web" });
47514
- return { id, platform: "web", notification };
47515
- };
47516
- const schedule = async (options = {}) => {
47517
- const at = new Date(options.at || Date.now()).getTime();
47518
- const delay = Math.max(0, at - Date.now());
47519
- const id = String(options.id || `notification_${at}_${Math.random().toString(36).slice(2)}`);
47520
- const timeout = setTimeout(() => {
47521
- scheduled.delete(id);
47522
- show({ ...options, id }).catch((error) => emit2({ type: "error", error }));
47523
- }, delay);
47524
- scheduled.set(id, timeout);
47525
- return { id, at };
47526
- };
47527
- const cancel = async (id) => {
47528
- const timeout = scheduled.get(String(id));
47529
- if (timeout) clearTimeout(timeout);
47530
- scheduled.delete(String(id));
47531
- await appPlugin()?.cancel?.({ id: String(id) });
47532
- };
47533
- const cancelAll = async () => {
47534
- for (const timeout of scheduled.values()) clearTimeout(timeout);
47535
- scheduled.clear();
47536
- await appPlugin()?.cancelAll?.();
47537
- };
47538
- const onAction = (listener) => {
47539
- installNativeListener();
47540
- listeners2.add(listener);
47541
- return () => listeners2.delete(listener);
47542
- };
47543
- return { permission, requestPermission, show, schedule, cancel, cancelAll, onAction };
47544
- }
47545
-
47546
47547
  // src/services/chatNotifications.js
47547
47548
  function createChatNotificationService(client) {
47549
+ const notifications = client.notifications || createNotificationService();
47548
47550
  const listeners2 = /* @__PURE__ */ new Set();
47549
47551
  const emit2 = (event) => listeners2.forEach((listener) => listener(event));
47550
47552
  const showMessage = async ({ sessionId, title = "New chat message", body = "", data = {}, style } = {}) => {
47551
47553
  if (!sessionId) return null;
47552
- return client.notifications.show({
47554
+ return notifications.show({
47553
47555
  id: `chat-message-${sessionId}-${Date.now()}`,
47554
47556
  title,
47555
47557
  body,
@@ -47564,7 +47566,7 @@ function createChatNotificationService(client) {
47564
47566
  };
47565
47567
  const showStatus = async ({ sessionId, title = "Chat update", body = "", data = {}, style } = {}) => {
47566
47568
  if (!sessionId) return null;
47567
- return client.notifications.show({
47569
+ return notifications.show({
47568
47570
  id: `chat-status-${sessionId}-${Date.now()}`,
47569
47571
  title,
47570
47572
  body,
@@ -47578,7 +47580,7 @@ function createChatNotificationService(client) {
47578
47580
  listeners2.add(listener);
47579
47581
  return () => listeners2.delete(listener);
47580
47582
  };
47581
- client.notifications.onAction(({ action, data, reply }) => {
47583
+ notifications.onAction(({ action, data, reply }) => {
47582
47584
  if (data?.sessionId && ["chat_message", "chat_status"].includes(data.kind)) {
47583
47585
  emit2({ type: action === "reply" ? "reply" : action, action, sessionId: data.sessionId, reply: reply || "", data });
47584
47586
  }