tevrocsdk 0.1.82 → 0.1.83

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.82",
3
+ "version": "0.1.83",
4
4
  "description": "JavaScript SDK for the Tevroc API.",
5
5
  "main": "./tevroc-sdk.umd.js",
6
6
  "module": "./tevroc-sdk.esm.js",
@@ -14,7 +14,11 @@
14
14
  "YOCO",
15
15
  "google Auth",
16
16
  "Google Drive",
17
- "Firebase"
17
+ "Firebase",
18
+ "Ozow" ,
19
+ "Internet of Things",
20
+ "IoT",
21
+ "Bluetooth"
18
22
  ],
19
23
  "license": "MIT"
20
24
  }
package/tevroc-sdk.cjs.js CHANGED
@@ -48628,15 +48628,15 @@ async function downloadUrlToBase64(url) {
48628
48628
  if (!url) return null;
48629
48629
  if (!isNative) return null;
48630
48630
  try {
48631
- console.debug(`[tevrocsdk][fileoffline] downloadUrlToBase64 fetching`, url);
48631
+ debugLog(`[tevrocsdk][fileoffline] downloadUrlToBase64 fetching`, url);
48632
48632
  const res = await fetch(url, { cache: "no-store" });
48633
48633
  if (!res.ok) return null;
48634
48634
  const b = await res.blob();
48635
48635
  const base64 = await blobToBase642(b).catch(() => null);
48636
- console.debug(`[tevrocsdk][fileoffline] downloadUrlToBase64 fetched -> base64 length`, base64 ? base64.length : 0);
48636
+ debugLog(`[tevrocsdk][fileoffline] downloadUrlToBase64 fetched -> base64 length`, base64 ? base64.length : 0);
48637
48637
  return base64;
48638
48638
  } catch (e) {
48639
- console.warn(`[tevrocsdk][fileoffline] downloadUrlToBase64 failed`, e);
48639
+ debugWarn(`[tevrocsdk][fileoffline] downloadUrlToBase64 failed`, e);
48640
48640
  return null;
48641
48641
  }
48642
48642
  }
@@ -48654,34 +48654,34 @@ function deriveKeyFromUrl(url) {
48654
48654
  async function persistFileToNative(client, key, base64, contentType) {
48655
48655
  try {
48656
48656
  if (!isNative) return false;
48657
- console.debug("[tevrocsdk][fileoffline] persistFileToNative", { key, contentType, hasBase64: !!base64 });
48657
+ debugLog("[tevrocsdk][fileoffline] persistFileToNative", { key, contentType, hasBase64: !!base64 });
48658
48658
  if (!client?.native?.store || !base64) {
48659
- console.warn("[tevrocsdk][fileoffline] persistFileToNative skipped - missing native.store or base64");
48659
+ debugWarn("[tevrocsdk][fileoffline] persistFileToNative skipped - missing native.store or base64");
48660
48660
  return false;
48661
48661
  }
48662
48662
  const now = (/* @__PURE__ */ new Date()).toISOString();
48663
48663
  await client.native.store.set(`downloaded_files/${key}`, { data: base64, contentType: contentType || "application/octet-stream", key, updatedAt: now });
48664
- console.debug("[tevrocsdk][fileoffline] persistFileToNative stored", { key, updatedAt: now });
48664
+ debugLog("[tevrocsdk][fileoffline] persistFileToNative stored", { key, updatedAt: now });
48665
48665
  return true;
48666
48666
  } catch (e) {
48667
- console.warn("[tevrocsdk][fileoffline] persistFileToNative error", e);
48667
+ debugWarn("[tevrocsdk][fileoffline] persistFileToNative error", e);
48668
48668
  return false;
48669
48669
  }
48670
48670
  }
48671
48671
  async function walkAndPersistFiles(client, obj) {
48672
48672
  if (!obj || typeof obj !== "object") return;
48673
48673
  if (!isNative || !client?.native?.store) return;
48674
- console.debug("[tevrocsdk][fileoffline] walkAndPersistFiles start");
48674
+ debugLog("[tevrocsdk][fileoffline] walkAndPersistFiles start");
48675
48675
  for (const k of Object.keys(obj)) {
48676
48676
  const v = obj[k];
48677
48677
  if (typeof v === "string") {
48678
48678
  if (isDataUrl(v)) {
48679
- console.debug("[tevrocsdk][fileoffline] walkAndPersistFiles found data URL at key", k);
48679
+ debugLog("[tevrocsdk][fileoffline] walkAndPersistFiles found data URL at key", k);
48680
48680
  const base64 = extractBase64FromDataUrl(v);
48681
48681
  const key = deriveKeyFromUrl(k) || `inline_${Date.now()}`;
48682
48682
  await persistFileToNative(client, key, base64, (v.match(/^data:([^;]+);/) || [])[1] || "application/octet-stream");
48683
48683
  } else if (/^https?:\/\//.test(v) || v.startsWith("filebase://")) {
48684
- console.debug("[tevrocsdk][fileoffline] walkAndPersistFiles found URL at key", k, v);
48684
+ debugLog("[tevrocsdk][fileoffline] walkAndPersistFiles found URL at key", k, v);
48685
48685
  const url = v.startsWith("filebase://") ? v.replace(/^filebase:\/\//, "") : v;
48686
48686
  const base64 = await downloadUrlToBase64(v).catch(() => null);
48687
48687
  if (base64) {
@@ -48689,16 +48689,16 @@ async function walkAndPersistFiles(client, obj) {
48689
48689
  await persistFileToNative(client, key, base64, "application/octet-stream");
48690
48690
  }
48691
48691
  } else if (isLikelyBase64(v)) {
48692
- console.debug("[tevrocsdk][fileoffline] walkAndPersistFiles found inline base64 at key", k);
48692
+ debugLog("[tevrocsdk][fileoffline] walkAndPersistFiles found inline base64 at key", k);
48693
48693
  const key = deriveKeyFromUrl(k) || `inline_${Date.now()}`;
48694
48694
  await persistFileToNative(client, key, v, "application/octet-stream");
48695
48695
  }
48696
48696
  } else if (v && typeof v === "object") {
48697
- console.debug("[tevrocsdk][fileoffline] walkAndPersistFiles recursing into", k);
48697
+ debugLog("[tevrocsdk][fileoffline] walkAndPersistFiles recursing into", k);
48698
48698
  await walkAndPersistFiles(client, v);
48699
48699
  }
48700
48700
  }
48701
- console.debug("[tevrocsdk][fileoffline] walkAndPersistFiles end");
48701
+ debugLog("[tevrocsdk][fileoffline] walkAndPersistFiles end");
48702
48702
  }
48703
48703
  function createOfflineManager(client) {
48704
48704
  const store = createNativeStore(client.appId);
@@ -49210,6 +49210,7 @@ var TevrocClient = class {
49210
49210
  this.baseUrl = normalizeBaseUrl(baseUrl);
49211
49211
  this.serviceUrl = normalizeBaseUrl(serviceUrl);
49212
49212
  this.vpsUrl = normalizeBaseUrl(vpsUrl);
49213
+ this.vpsConfig = { ...options.vpsConfig || options.config || {} };
49213
49214
  this.appId = options.appId;
49214
49215
  this.appName = options.appName;
49215
49216
  this.payAccount = options.payAccount ?? "default";
@@ -49218,11 +49219,14 @@ var TevrocClient = class {
49218
49219
  throw new TypeError("No fetch implementation available");
49219
49220
  }
49220
49221
  this.timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
49222
+ this.axios = options.axios;
49221
49223
  this.defaultHeaders = normalizeHeaders(options.headers);
49222
49224
  this.token = options.token ?? null;
49223
49225
  this.debug = options.debug ?? false;
49224
49226
  setSdkDebug(this.debug);
49225
49227
  this.auth = createAuthApi(this);
49228
+ this.vps = createVpsApi(this);
49229
+ this.database = this.vps.database;
49226
49230
  this.entities = createEntityRegistry(this);
49227
49231
  this.functions = createFunctionRegistry(this);
49228
49232
  this.integrations = createIntegrationApi(this);
@@ -49279,7 +49283,15 @@ var TevrocClient = class {
49279
49283
  }
49280
49284
  clearToken() {
49281
49285
  this.token = null;
49282
- safeLocalStorage()?.removeItem("tevroc_access_token");
49286
+ const storage = safeLocalStorage();
49287
+ [
49288
+ "tevroc_access_token",
49289
+ "base44_access_token",
49290
+ "native_access_token",
49291
+ "token",
49292
+ "idToken",
49293
+ "user"
49294
+ ].forEach((key) => storage?.removeItem(key));
49283
49295
  return this;
49284
49296
  }
49285
49297
  setDebug(enabled) {
@@ -49291,7 +49303,8 @@ var TevrocClient = class {
49291
49303
  const method = (options.method ?? "GET").toUpperCase();
49292
49304
  const headers = new Headers(this.defaultHeaders);
49293
49305
  const query = options.query ? toSearchParams(options.query) : "";
49294
- const url = `${this.baseUrl}${path.startsWith("/") ? path : `/${path}`}${query}`;
49306
+ const requestBaseUrl = options.baseUrl ?? this.baseUrl;
49307
+ const url = `${requestBaseUrl}${path.startsWith("/") ? path : `/${path}`}${query}`;
49295
49308
  const controller = new AbortController();
49296
49309
  const timeoutMsActual = options.timeoutMs || this.timeoutMs || 2500;
49297
49310
  let timeout = null;
@@ -49332,13 +49345,23 @@ var TevrocClient = class {
49332
49345
  debugWarn2(this, "[tevrocsdk] pending sync failed", err);
49333
49346
  }
49334
49347
  }
49335
- let fetchPromise;
49336
- fetchPromise = this.fetch(url, {
49337
- method,
49338
- headers,
49339
- body,
49340
- signal: options.signal ?? controller.signal
49341
- });
49348
+ let requestPromise;
49349
+ if (this.axios?.request) {
49350
+ requestPromise = this.axios.request({
49351
+ url,
49352
+ method,
49353
+ headers: Object.fromEntries(headers.entries()),
49354
+ data: body,
49355
+ signal: options.signal ?? controller.signal
49356
+ }).then((response) => parseAxiosResponse(response, options.parseAs));
49357
+ } else {
49358
+ requestPromise = this.fetch(url, {
49359
+ method,
49360
+ headers,
49361
+ body,
49362
+ signal: options.signal ?? controller.signal
49363
+ }).then((response) => parseResponse(response, options.parseAs));
49364
+ }
49342
49365
  const timeoutPromise = new Promise((_, reject) => {
49343
49366
  timeout = setTimeout(() => {
49344
49367
  try {
@@ -49348,8 +49371,7 @@ var TevrocClient = class {
49348
49371
  reject(new TevrocError("Request timed out", { code: "timeout" }));
49349
49372
  }, timeoutMsActual);
49350
49373
  });
49351
- const response = await Promise.race([fetchPromise, timeoutPromise]);
49352
- let ret = await parseResponse(response, options.parseAs);
49374
+ let ret = await Promise.race([requestPromise, timeoutPromise]);
49353
49375
  debugLog2(this, "Response from request:", ret);
49354
49376
  return ret;
49355
49377
  } catch (error) {
@@ -49362,6 +49384,67 @@ var TevrocClient = class {
49362
49384
  }
49363
49385
  }
49364
49386
  };
49387
+ function createVpsApi(client) {
49388
+ const request = (path, options = {}) => client.request(path, { ...options, baseUrl: client.vpsUrl });
49389
+ const withSession = (session, query = {}) => ({
49390
+ ...query,
49391
+ session: session ?? client.vpsConfig.session
49392
+ });
49393
+ const encodeSql = (sql) => {
49394
+ if (typeof sql !== "string" || !sql.trim()) throw new TypeError("sql must be a non-empty string");
49395
+ if (typeof btoa === "function") return btoa(unescape(encodeURIComponent(sql)));
49396
+ return Buffer.from(sql, "utf8").toString("base64");
49397
+ };
49398
+ const database = {
49399
+ dialect: () => request("/database/sql", { auth: false }),
49400
+ tables: (options = {}) => request("/database/tables", { query: withSession(options.session, options), auth: false }),
49401
+ table: (table, options = {}) => request("/database/table", {
49402
+ query: withSession(options.session, { ...options, table }),
49403
+ auth: false
49404
+ }),
49405
+ exec: (sql, options = {}) => request("/database/query/exec", {
49406
+ query: withSession(options.session, { ...options, query: encodeSql(sql) }),
49407
+ auth: false
49408
+ }),
49409
+ query: (sql, options = {}) => database.exec(sql, options)
49410
+ };
49411
+ const auth = {
49412
+ login: async (email, password, options = {}) => {
49413
+ const result = await request("/login", { query: { ...options, email, password }, auth: false });
49414
+ if (result?.session) client.setToken(result.session);
49415
+ return result;
49416
+ },
49417
+ verifyOtp: async (email, otp, options = {}) => {
49418
+ const result = await request("/auth-otp", { query: { ...options, email, otp }, auth: false });
49419
+ if (result?.session) client.setToken(result.session);
49420
+ return result;
49421
+ },
49422
+ register: (input, options = {}) => request(options.path || "/auth/register", { method: "POST", body: input, auth: false }),
49423
+ resetPassword: (input, options = {}) => request(options.path || "/auth/reset-password", { method: "POST", body: input, auth: false }),
49424
+ changePassword: (input, options = {}) => request(options.path || "/auth/change-password", { method: "POST", body: input }),
49425
+ session: (session = client.token, options = {}) => request("/session", { query: withSession(session, options), auth: false }),
49426
+ userType: (session = client.token, options = {}) => request("/get-usertype", { query: withSession(session, options), auth: false }),
49427
+ user: (session = client.token, options = {}) => request("/get-user", { query: withSession(session, options), auth: false }),
49428
+ hasOnboarded: (session = client.token, options = {}) => request("/has-onboarded", { query: withSession(session, options), auth: false }),
49429
+ hasVerified: (session = client.token, options = {}) => request("/has-verified", { query: withSession(session, options), auth: false }),
49430
+ updateProfile: (session, data, options = {}) => request("/update-profile", { query: withSession(session, { ...options, jsonObject: JSON.stringify(data) }), auth: false }),
49431
+ updateOnboarding: (session, data, options = {}) => request("/update-onboarding", { query: withSession(session, { ...options, jsonObject: JSON.stringify(data) }), auth: false }),
49432
+ logout: () => {
49433
+ client.clearToken();
49434
+ return Promise.resolve({ ok: true });
49435
+ }
49436
+ };
49437
+ return {
49438
+ request,
49439
+ auth,
49440
+ database,
49441
+ environment: () => request("/api/environment", { auth: false }),
49442
+ platform: () => request("/platform", { auth: false }),
49443
+ notifications: (options = {}) => request("/api/notifications", { query: options, auth: false }),
49444
+ accountContext: (session = client.token, options = {}) => request("/api/mobile/account-context", { query: withSession(session, options), auth: false }),
49445
+ avatarUrl: (options = {}) => `${client.vpsUrl}/api/avatar${toSearchParams(options)}`
49446
+ };
49447
+ }
49365
49448
  function createShiplogicApi(client) {
49366
49449
  return {
49367
49450
  getRates: (payload = {}) => client.request("/shiplogic/rates", { method: "POST", body: payload }),
@@ -49556,7 +49639,7 @@ function createAuthApi(client) {
49556
49639
  // base44
49557
49640
  loginWithProvider: async (provider, redirectTo, setToken = async () => {
49558
49641
  }) => {
49559
- console.log(client, "loginWithProvider called", { provider, redirectTo });
49642
+ debugLog2(client, "loginWithProvider called", { provider, redirectTo });
49560
49643
  if (provider === "google") {
49561
49644
  const { createGoogleLogin: createGoogleLogin2, subscribeGoogleLogin: subscribeGoogleLogin2 } = await getGoogleModule();
49562
49645
  debugLog2(client, {
@@ -49564,11 +49647,6 @@ function createAuthApi(client) {
49564
49647
  appId: client.appId,
49565
49648
  appName: client.appName
49566
49649
  });
49567
- await createGoogleLogin2({
49568
- serviceUrl: client.serviceUrl,
49569
- appId: client.appId,
49570
- appName: client.appName
49571
- });
49572
49650
  if (redirectTo) {
49573
49651
  const unsub = subscribeGoogleLogin2(async (user, err) => {
49574
49652
  debugLog2(client, "Google callback:", user, err);
@@ -49584,6 +49662,22 @@ function createAuthApi(client) {
49584
49662
  debugLog2(client, "Redirecting to:", redirectTo);
49585
49663
  window.location.href = redirectTo;
49586
49664
  });
49665
+ try {
49666
+ await createGoogleLogin2({
49667
+ serviceUrl: client.serviceUrl,
49668
+ appId: client.appId,
49669
+ appName: client.appName
49670
+ });
49671
+ } catch (error) {
49672
+ unsub();
49673
+ throw error;
49674
+ }
49675
+ } else {
49676
+ await createGoogleLogin2({
49677
+ serviceUrl: client.serviceUrl,
49678
+ appId: client.appId,
49679
+ appName: client.appName
49680
+ });
49587
49681
  }
49588
49682
  }
49589
49683
  if (provider === "facebook") {
@@ -49715,9 +49809,11 @@ function createAuthApi(client) {
49715
49809
  return result;
49716
49810
  },
49717
49811
  async logout() {
49718
- const result = await client.request("/auth/logout", { method: "POST", body: buildAuthPayload({}, client) });
49719
- client.clearToken();
49720
- return result;
49812
+ try {
49813
+ return await client.request("/auth/logout", { method: "POST", body: buildAuthPayload({}, client) });
49814
+ } finally {
49815
+ client.clearToken();
49816
+ }
49721
49817
  },
49722
49818
  inviteUser: (input) => client.request("/users/invite", { method: "POST", body: buildAuthPayload(input, client) }),
49723
49819
  acceptInvite: (input) => client.request("/auth/accept-invite", { method: "POST", body: buildAuthPayload(input, client), auth: false }),
@@ -50253,10 +50349,10 @@ async function blobToBase643(blob) {
50253
50349
  async function readCachedFileResponse(client, key) {
50254
50350
  if (!client.native?.store || !isNative) return null;
50255
50351
  const cached = (await client.native.store.get(`downloaded_files/${key}`)).val();
50256
- console.debug("[tevrocsdk][files] readCachedFileResponse", { key, hasCached: !!cached?.data });
50352
+ debugLog2(client, "[tevrocsdk][files] readCachedFileResponse", { key, hasCached: !!cached?.data });
50257
50353
  if (!cached?.data) return null;
50258
50354
  const blob = base64ToBlob(cached.data, cached.contentType || "application/octet-stream");
50259
- console.debug("[tevrocsdk][files] readCachedFileResponse built blob", { key, size: blob && blob.size });
50355
+ debugLog2(client, "[tevrocsdk][files] readCachedFileResponse built blob", { key, size: blob && blob.size });
50260
50356
  return new Response(blob, {
50261
50357
  headers: { "content-type": cached.contentType || "application/octet-stream" }
50262
50358
  });
@@ -50264,14 +50360,14 @@ async function readCachedFileResponse(client, key) {
50264
50360
  async function storeCachedFileResponse(client, key, response, fallbackContentType = "application/octet-stream") {
50265
50361
  if (!client.native?.store || !isNative || !key) return;
50266
50362
  try {
50267
- console.debug("[tevrocsdk][files] storeCachedFileResponse", { key });
50363
+ debugLog2(client, "[tevrocsdk][files] storeCachedFileResponse", { key });
50268
50364
  const clone = response instanceof Response ? response.clone() : null;
50269
50365
  const blob = clone ? await clone.blob() : null;
50270
50366
  const contentType = clone && clone.headers.get("content-type") || fallbackContentType;
50271
50367
  const data = blob ? await blobToBase643(blob) : "";
50272
- console.debug("[tevrocsdk][files] storeCachedFileResponse data length", { key, length: data ? data.length : 0, contentType });
50368
+ debugLog2(client, "[tevrocsdk][files] storeCachedFileResponse data length", { key, length: data ? data.length : 0, contentType });
50273
50369
  if (!data) {
50274
- console.warn("[tevrocsdk][files] storeCachedFileResponse no data to store", { key });
50370
+ debugWarn2(client, "[tevrocsdk][files] storeCachedFileResponse no data to store", { key });
50275
50371
  return;
50276
50372
  }
50277
50373
  await client.native.store.set(`downloaded_files/${key}`, {
@@ -50280,18 +50376,18 @@ async function storeCachedFileResponse(client, key, response, fallbackContentTyp
50280
50376
  key,
50281
50377
  updatedAt: (/* @__PURE__ */ new Date()).toISOString()
50282
50378
  });
50283
- console.debug("[tevrocsdk][files] storeCachedFileResponse stored", { key });
50379
+ debugLog2(client, "[tevrocsdk][files] storeCachedFileResponse stored", { key });
50284
50380
  } catch (error) {
50285
50381
  debugWarn2(client, "Failed to cache downloaded file", error);
50286
- console.warn("[tevrocsdk][files] storeCachedFileResponse error", error);
50382
+ debugWarn2(client, "[tevrocsdk][files] storeCachedFileResponse error", error);
50287
50383
  }
50288
50384
  }
50289
50385
  async function readCachedFileDataUrl(client, key) {
50290
50386
  if (!client.native?.store || !isNative || !key) return null;
50291
50387
  const cached = (await client.native.store.get(`downloaded_files/${key}`)).val();
50292
- console.debug("[tevrocsdk][files] readCachedFileDataUrl", { key, hasCached: !!cached?.data });
50388
+ debugLog2(client, "[tevrocsdk][files] readCachedFileDataUrl", { key, hasCached: !!cached?.data });
50293
50389
  if (!cached?.data) return null;
50294
- console.debug("[tevrocsdk][files] readCachedFileDataUrl returning data url", { key, length: cached.data.length });
50390
+ debugLog2(client, "[tevrocsdk][files] readCachedFileDataUrl returning data url", { key, length: cached.data.length });
50295
50391
  return `data:${cached.contentType || "application/octet-stream"};base64,${cached.data}`;
50296
50392
  }
50297
50393
  function base64ToBlob(base64, contentType = "application/octet-stream") {
@@ -50323,7 +50419,7 @@ function createFileApi(client) {
50323
50419
  }
50324
50420
  rounds += 1;
50325
50421
  } while (rawKey !== prev && rawKey.includes("%25") && rounds < 5);
50326
- if (rounds > 0) console.debug("[tevrocsdk][files] iterative decode performed", { original: key, rawKey, rounds });
50422
+ if (rounds > 0) debugLog2(client, "[tevrocsdk][files] iterative decode performed", { original: key, rawKey, rounds });
50327
50423
  } catch (e) {
50328
50424
  }
50329
50425
  debugLog2(client, "[tevrocsdk][files:url]", { key, rawKey, online, offline, isNative });
@@ -50353,7 +50449,7 @@ function createFileApi(client) {
50353
50449
  }
50354
50450
  rounds += 1;
50355
50451
  } while (rawKey !== prev && rawKey.includes("%25") && rounds < 5);
50356
- if (rounds > 0) console.debug("[tevrocsdk][files] iterative decode performed (privateUrl)", { original: key, rawKey, rounds });
50452
+ if (rounds > 0) debugLog2(client, "[tevrocsdk][files] iterative decode performed (privateUrl)", { original: key, rawKey, rounds });
50357
50453
  } catch (e) {
50358
50454
  }
50359
50455
  debugLog2(client, "[tevrocsdk][files:privateUrl]", { key, rawKey, online, offline, isNative });
@@ -50393,7 +50489,7 @@ function createFileApi(client) {
50393
50489
  }
50394
50490
  rounds += 1;
50395
50491
  } while (rawKey !== prev && rawKey.includes("%25") && rounds < 5);
50396
- if (rounds > 0) console.debug("[tevrocsdk][files] iterative decode performed (get)", { original: key, rawKey, rounds });
50492
+ if (rounds > 0) debugLog2(client, "[tevrocsdk][files] iterative decode performed (get)", { original: key, rawKey, rounds });
50397
50493
  } catch (e) {
50398
50494
  }
50399
50495
  debugLog2(client, "[tevrocsdk][files] get", { key, rawKey, isNative, online, offline });
@@ -50423,7 +50519,7 @@ function createFileApi(client) {
50423
50519
  }
50424
50520
  rounds += 1;
50425
50521
  } while (rawKey !== prev && rawKey.includes("%25") && rounds < 5);
50426
- if (rounds > 0) console.debug("[tevrocsdk][files] iterative decode performed (getPrivate)", { original: key, rawKey, rounds });
50522
+ if (rounds > 0) debugLog2(client, "[tevrocsdk][files] iterative decode performed (getPrivate)", { original: key, rawKey, rounds });
50427
50523
  } catch (e) {
50428
50524
  }
50429
50525
  debugLog2(client, "[tevrocsdk][files] getPrivate", { key, rawKey, isNative, online, offline });
@@ -50461,7 +50557,7 @@ async function detectElectronEnvironment(client) {
50461
50557
  }
50462
50558
  }
50463
50559
  } catch (error) {
50464
- console.debug("[tevrocsdk][env] /api/environment fallback", error);
50560
+ debugLog2(client, "[tevrocsdk][env] /api/environment fallback", error);
50465
50561
  }
50466
50562
  if (typeof navigator !== "undefined") {
50467
50563
  const userAgent = navigator.userAgent || "";
@@ -50609,6 +50705,23 @@ async function uploadViaGoogleStorage(client, file, options = {}) {
50609
50705
  }
50610
50706
  return { ...result, runtime: "gcs" };
50611
50707
  }
50708
+ async function parseAxiosResponse(response, parseAs) {
50709
+ if (parseAs === "response") return response;
50710
+ const headers = response.headers ?? {};
50711
+ const contentType = typeof headers.get === "function" ? headers.get("content-type") ?? "" : String(headers["content-type"] ?? headers["Content-Type"] ?? "");
50712
+ const isJson = contentType.includes("application/json");
50713
+ const data = response.data;
50714
+ if (response.status < 200 || response.status >= 300) {
50715
+ const error = isJson && data?.error ? data.error : {};
50716
+ throw new TevrocError(error.message ?? response.statusText ?? "Request failed", {
50717
+ status: response.status,
50718
+ code: error.code ?? "api_error",
50719
+ details: error.details ?? data,
50720
+ response
50721
+ });
50722
+ }
50723
+ return data;
50724
+ }
50612
50725
  async function parseResponse(response, parseAs) {
50613
50726
  if (parseAs === "response") return response;
50614
50727
  const contentType = response.headers.get("content-type") ?? "";
@@ -50645,13 +50758,13 @@ function normalizeHeaders(headers = {}) {
50645
50758
  return Object.fromEntries(new Headers(headers).entries());
50646
50759
  }
50647
50760
  function debugLog2(client, ...args) {
50648
- if (client?.debug) console.log(...args);
50761
+ debugLog(...args);
50649
50762
  }
50650
50763
  function debugWarn2(client, ...args) {
50651
- if (client?.debug) console.warn(...args);
50764
+ debugWarn(...args);
50652
50765
  }
50653
50766
  function debugError2(client, ...args) {
50654
- if (client?.debug) console.error(...args);
50767
+ debugError(...args);
50655
50768
  }
50656
50769
  function safeLocalStorage() {
50657
50770
  return typeof globalThis !== "undefined" ? globalThis.localStorage : void 0;