@npaw/forge-web 9.6.1 → 9.7.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.js CHANGED
@@ -2966,6 +2966,52 @@ function currentHref2() {
2966
2966
  return (_b = (_a = globalLocation()) == null ? void 0 : _a.href) != null ? _b : "https://localhost/";
2967
2967
  }
2968
2968
 
2969
+ // src/device-identity.ts
2970
+ var DEVICE_UUID_STORAGE_KEY = "npawForgeDeviceUUID";
2971
+ function persistentDeviceUuid() {
2972
+ var _a;
2973
+ const stored = readStoredUuid();
2974
+ if (stored) {
2975
+ return stored;
2976
+ }
2977
+ const generated = randomUuid();
2978
+ try {
2979
+ (_a = globalThis.localStorage) == null ? void 0 : _a.setItem(DEVICE_UUID_STORAGE_KEY, generated);
2980
+ } catch (e) {
2981
+ }
2982
+ return generated;
2983
+ }
2984
+ function readStoredUuid() {
2985
+ var _a;
2986
+ try {
2987
+ const value = (_a = globalThis.localStorage) == null ? void 0 : _a.getItem(DEVICE_UUID_STORAGE_KEY);
2988
+ return value && value.trim().length > 0 ? value : void 0;
2989
+ } catch (e) {
2990
+ return void 0;
2991
+ }
2992
+ }
2993
+ function randomUuid() {
2994
+ const cryptoRef = globalThis.crypto;
2995
+ if (typeof (cryptoRef == null ? void 0 : cryptoRef.randomUUID) === "function") {
2996
+ return cryptoRef.randomUUID();
2997
+ }
2998
+ if (typeof (cryptoRef == null ? void 0 : cryptoRef.getRandomValues) === "function") {
2999
+ const bytes = cryptoRef.getRandomValues(new Uint8Array(16));
3000
+ bytes[6] = bytes[6] & 15 | 64;
3001
+ bytes[8] = bytes[8] & 63 | 128;
3002
+ const hex = Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");
3003
+ return [
3004
+ hex.slice(0, 8),
3005
+ hex.slice(8, 12),
3006
+ hex.slice(12, 16),
3007
+ hex.slice(16, 20),
3008
+ hex.slice(20, 32)
3009
+ ].join("-");
3010
+ }
3011
+ const random = () => Math.floor(Math.random() * 4294967296).toString(16).padStart(8, "0");
3012
+ return `${random()}-${random().slice(0, 4)}-4${random().slice(0, 3)}-a${random().slice(0, 3)}-${random()}${random().slice(0, 4)}`;
3013
+ }
3014
+
2969
3015
  // src/utils.ts
2970
3016
  function systemClock() {
2971
3017
  return {
@@ -3733,6 +3779,7 @@ function isEffectCompletion(command) {
3733
3779
  return command.type === "httpCompleted" || command.type === "httpFailed" || command.type === "storageReadCompleted" || command.type === "storageWriteCompleted" || command.type === "storageDeleteCompleted";
3734
3780
  }
3735
3781
  function runtimeConfig(options) {
3782
+ var _a, _b;
3736
3783
  const config = {
3737
3784
  accountCode: options.accountCode
3738
3785
  };
@@ -3755,6 +3802,13 @@ function runtimeConfig(options) {
3755
3802
  options.preSessionEventQueueMaxAgeMs
3756
3803
  );
3757
3804
  assignOptional(config, "logLevel", options.logLevel);
3805
+ const autoDeviceIdentity = (_a = options.autoDeviceIdentity) != null ? _a : true;
3806
+ assignOptional(
3807
+ config,
3808
+ "deviceUuid",
3809
+ (_b = options.deviceUuid) != null ? _b : autoDeviceIdentity ? persistentDeviceUuid() : void 0
3810
+ );
3811
+ assignOptional(config, "deviceInfo", options.deviceInfo);
3758
3812
  return config;
3759
3813
  }
3760
3814
  function assignOptional(config, key, value) {