vesant-sdk 1.3.1 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -239,7 +239,7 @@ var noopLogger = {
239
239
  };
240
240
 
241
241
  // src/core/version.ts
242
- var SDK_VERSION = "1.3.0";
242
+ var SDK_VERSION = "1.4.0";
243
243
 
244
244
  // src/shared/browser-utils.ts
245
245
  function generateUUID() {
@@ -333,6 +333,12 @@ var BaseClient = class {
333
333
  interceptors: this.interceptors,
334
334
  logger: this.logger
335
335
  };
336
+ if (this.config.environment === "sandbox" && this.config.apiKey?.startsWith("pk_live_")) {
337
+ this.logger.warn("Production API key used with sandbox environment. Use your sandbox API key (sk_sandbox_) instead.");
338
+ }
339
+ if (this.config.environment !== "sandbox" && this.config.apiKey?.startsWith("sk_sandbox_")) {
340
+ this.logger.warn("Sandbox API key used with production environment. Use your production API key (pk_live_) instead.");
341
+ }
336
342
  if (config.circuitBreaker) {
337
343
  this.circuitBreaker = new CircuitBreaker(config.circuitBreaker);
338
344
  }
@@ -356,8 +362,9 @@ var BaseClient = class {
356
362
  error.requestId = requestId;
357
363
  throw error;
358
364
  }
359
- const baseURL = this.config.environment === "sandbox" && this.config.sandboxBaseURL ? this.config.sandboxBaseURL : serviceURL || this.config.baseURL;
360
- const url = `${serviceURL || baseURL}${endpoint}`;
365
+ const DEFAULT_SANDBOX_URL = "https://sandbox-api.vesant.ai";
366
+ const resolvedBaseURL = this.config.environment === "sandbox" ? this.config.sandboxBaseURL || DEFAULT_SANDBOX_URL : serviceURL || this.config.baseURL;
367
+ const url = `${serviceURL || resolvedBaseURL}${endpoint}`;
361
368
  const headers = {
362
369
  "Content-Type": "application/json",
363
370
  "X-Tenant-ID": this.config.tenantId,
@@ -767,9 +774,13 @@ function encodePayload(payload) {
767
774
  async function generateCipherText(options, config) {
768
775
  const warnings = [];
769
776
  let requestLocation = options.requestLocation ?? false;
777
+ let gpsRequiredByConfig = false;
770
778
  if (config?.require_gps) {
771
779
  const reason = options.reason;
772
780
  if (reason === "login" && config.require_gps.login || reason === "registration" && config.require_gps.registration || reason === "transaction" && config.require_gps.transaction) {
781
+ if (!requestLocation) {
782
+ gpsRequiredByConfig = true;
783
+ }
773
784
  requestLocation = true;
774
785
  }
775
786
  }
@@ -782,6 +793,10 @@ async function generateCipherText(options, config) {
782
793
  );
783
794
  if (location) {
784
795
  locationData = location;
796
+ } else if (gpsRequiredByConfig) {
797
+ throw new Error(
798
+ `GPS location is required for ${options.reason} by tenant configuration, but GPS was not available or permission was denied`
799
+ );
785
800
  } else {
786
801
  warnings.push("GPS location not available or permission denied");
787
802
  }
@@ -1233,13 +1248,17 @@ var GeolocationClient = class extends BaseClient {
1233
1248
  */
1234
1249
  async generateCipherText(options, gpsConfig) {
1235
1250
  let signingKey = this.cachedSigningKey;
1251
+ let resolvedGpsConfig = gpsConfig;
1236
1252
  if (!signingKey) {
1237
1253
  const config = await this.getGPSConfig();
1238
1254
  signingKey = config.signing_key;
1255
+ if (!resolvedGpsConfig) {
1256
+ resolvedGpsConfig = config;
1257
+ }
1239
1258
  }
1240
1259
  return generateCipherText(
1241
1260
  { ...options, signingKey: signingKey || void 0 },
1242
- gpsConfig
1261
+ resolvedGpsConfig
1243
1262
  );
1244
1263
  }
1245
1264
  // ============================================================================