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/react.mjs CHANGED
@@ -4,7 +4,7 @@ import { createRoot } from 'react-dom/client';
4
4
  // src/geolocation/hooks.ts
5
5
 
6
6
  // src/core/version.ts
7
- var SDK_VERSION = "1.3.0";
7
+ var SDK_VERSION = "1.4.0";
8
8
 
9
9
  // src/shared/browser-utils.ts
10
10
  function generateUUID() {
@@ -199,9 +199,13 @@ function encodePayload(payload) {
199
199
  async function generateCipherText(options, config) {
200
200
  const warnings = [];
201
201
  let requestLocation = options.requestLocation ?? false;
202
+ let gpsRequiredByConfig = false;
202
203
  if (config?.require_gps) {
203
204
  const reason = options.reason;
204
205
  if (reason === "login" && config.require_gps.login || reason === "registration" && config.require_gps.registration || reason === "transaction" && config.require_gps.transaction) {
206
+ if (!requestLocation) {
207
+ gpsRequiredByConfig = true;
208
+ }
205
209
  requestLocation = true;
206
210
  }
207
211
  }
@@ -214,6 +218,10 @@ async function generateCipherText(options, config) {
214
218
  );
215
219
  if (location) {
216
220
  locationData = location;
221
+ } else if (gpsRequiredByConfig) {
222
+ throw new Error(
223
+ `GPS location is required for ${options.reason} by tenant configuration, but GPS was not available or permission was denied`
224
+ );
217
225
  } else {
218
226
  warnings.push("GPS location not available or permission denied");
219
227
  }
@@ -368,18 +376,19 @@ function createDeviceFingerprint() {
368
376
  };
369
377
  }
370
378
  function useCipherText(client) {
371
- const [config, setConfig] = useState(void 0);
372
379
  const [configLoading, setConfigLoading] = useState(!!client);
373
380
  const [configError, setConfigError] = useState(null);
374
381
  const configRef = useRef(void 0);
375
- configRef.current = config;
382
+ const configPromiseRef = useRef(null);
376
383
  useEffect(() => {
377
384
  if (!client) return;
378
385
  let cancelled = false;
379
386
  setConfigLoading(true);
380
- client.getGPSConfig().then((cfg) => {
387
+ const promise = client.getGPSConfig();
388
+ configPromiseRef.current = promise;
389
+ promise.then((cfg) => {
381
390
  if (!cancelled) {
382
- setConfig(cfg);
391
+ configRef.current = cfg;
383
392
  setConfigLoading(false);
384
393
  }
385
394
  }).catch((err) => {
@@ -395,6 +404,13 @@ function useCipherText(client) {
395
404
  const generate = useCallback(
396
405
  async (options) => {
397
406
  try {
407
+ if (configPromiseRef.current) {
408
+ try {
409
+ const cfg = await configPromiseRef.current;
410
+ configRef.current = cfg;
411
+ } catch {
412
+ }
413
+ }
398
414
  return await generateCipherText(options, configRef.current);
399
415
  } catch (error) {
400
416
  console.error("[CGS SDK] Failed to generate cipherText:", error);