@npaw/forge-web 9.6.1 → 9.7.1

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.d.cts CHANGED
@@ -90,8 +90,27 @@ interface ForgeRuntimeConfig {
90
90
  preSessionEventQueueLimitEvents?: number;
91
91
  preSessionEventQueueMaxAgeMs?: number;
92
92
  logLevel?: string;
93
+ /**
94
+ * Stable device identifier. Collected automatically unless
95
+ * `autoDeviceIdentity` is false; set this to supply your own.
96
+ */
97
+ deviceUuid?: string;
98
+ /**
99
+ * `deviceInfo` facts. Forge does not auto-detect these on Web: the browser
100
+ * already sends a User-Agent header on every request and NPAW resolves the
101
+ * device from it server-side, which is strictly better than anything a
102
+ * client-side parser can do. The v7 Web plugin makes the same choice. Set
103
+ * them only when you know something the User-Agent does not convey.
104
+ */
105
+ deviceInfo?: DeviceOverrides;
93
106
  }
94
107
  interface ForgeCreateOptions extends ForgeRuntimeConfig {
108
+ /**
109
+ * Disables automatic device identity collection (the persistent
110
+ * `deviceUUID`). An explicit `deviceUuid` is still honoured when disabled.
111
+ * Defaults to true.
112
+ */
113
+ autoDeviceIdentity?: boolean;
95
114
  startSessionOnInitialize?: boolean;
96
115
  initialSessionParams?: ForgeParams;
97
116
  capture?: ForgeCaptureOptions;
@@ -470,6 +489,16 @@ interface OverrideBundle {
470
489
  control?: OverrideControlOptions;
471
490
  }
472
491
  /** Mirrors `DeviceOverrides` in crates/forge-kernel/src/wire/bundle.rs (string-only fields). */
492
+ /**
493
+ * Device identity overrides.
494
+ *
495
+ * These are the *input* names. They are not the wire keys: the kernel emits
496
+ * `deviceInfo` using the v7 plugin contract, where `code` becomes `deviceCode`
497
+ * and `type` becomes `deviceType`. The short names here are kept because they
498
+ * are public API; the kernel accepts them as aliases. See
499
+ * `device_info_json` in crates/forge-kernel/src/wire/serialize.rs and the
500
+ * `deviceInfo` key table in docs/events.md.
501
+ */
473
502
  interface DeviceOverrides {
474
503
  brand?: string;
475
504
  code?: string;
package/dist/index.d.ts CHANGED
@@ -90,8 +90,27 @@ interface ForgeRuntimeConfig {
90
90
  preSessionEventQueueLimitEvents?: number;
91
91
  preSessionEventQueueMaxAgeMs?: number;
92
92
  logLevel?: string;
93
+ /**
94
+ * Stable device identifier. Collected automatically unless
95
+ * `autoDeviceIdentity` is false; set this to supply your own.
96
+ */
97
+ deviceUuid?: string;
98
+ /**
99
+ * `deviceInfo` facts. Forge does not auto-detect these on Web: the browser
100
+ * already sends a User-Agent header on every request and NPAW resolves the
101
+ * device from it server-side, which is strictly better than anything a
102
+ * client-side parser can do. The v7 Web plugin makes the same choice. Set
103
+ * them only when you know something the User-Agent does not convey.
104
+ */
105
+ deviceInfo?: DeviceOverrides;
93
106
  }
94
107
  interface ForgeCreateOptions extends ForgeRuntimeConfig {
108
+ /**
109
+ * Disables automatic device identity collection (the persistent
110
+ * `deviceUUID`). An explicit `deviceUuid` is still honoured when disabled.
111
+ * Defaults to true.
112
+ */
113
+ autoDeviceIdentity?: boolean;
95
114
  startSessionOnInitialize?: boolean;
96
115
  initialSessionParams?: ForgeParams;
97
116
  capture?: ForgeCaptureOptions;
@@ -470,6 +489,16 @@ interface OverrideBundle {
470
489
  control?: OverrideControlOptions;
471
490
  }
472
491
  /** Mirrors `DeviceOverrides` in crates/forge-kernel/src/wire/bundle.rs (string-only fields). */
492
+ /**
493
+ * Device identity overrides.
494
+ *
495
+ * These are the *input* names. They are not the wire keys: the kernel emits
496
+ * `deviceInfo` using the v7 plugin contract, where `code` becomes `deviceCode`
497
+ * and `type` becomes `deviceType`. The short names here are kept because they
498
+ * are public API; the kernel accepts them as aliases. See
499
+ * `device_info_json` in crates/forge-kernel/src/wire/serialize.rs and the
500
+ * `deviceInfo` key table in docs/events.md.
501
+ */
473
502
  interface DeviceOverrides {
474
503
  brand?: string;
475
504
  code?: string;
@@ -3485,6 +3485,52 @@ var NPAWForge = (() => {
3485
3485
  return (_b = (_a = globalLocation()) == null ? void 0 : _a.href) != null ? _b : "https://localhost/";
3486
3486
  }
3487
3487
 
3488
+ // src/device-identity.ts
3489
+ var DEVICE_UUID_STORAGE_KEY = "npawForgeDeviceUUID";
3490
+ function persistentDeviceUuid() {
3491
+ var _a;
3492
+ const stored = readStoredUuid();
3493
+ if (stored) {
3494
+ return stored;
3495
+ }
3496
+ const generated = randomUuid();
3497
+ try {
3498
+ (_a = globalThis.localStorage) == null ? void 0 : _a.setItem(DEVICE_UUID_STORAGE_KEY, generated);
3499
+ } catch (e2) {
3500
+ }
3501
+ return generated;
3502
+ }
3503
+ function readStoredUuid() {
3504
+ var _a;
3505
+ try {
3506
+ const value = (_a = globalThis.localStorage) == null ? void 0 : _a.getItem(DEVICE_UUID_STORAGE_KEY);
3507
+ return value && value.trim().length > 0 ? value : void 0;
3508
+ } catch (e2) {
3509
+ return void 0;
3510
+ }
3511
+ }
3512
+ function randomUuid() {
3513
+ const cryptoRef = globalThis.crypto;
3514
+ if (typeof (cryptoRef == null ? void 0 : cryptoRef.randomUUID) === "function") {
3515
+ return cryptoRef.randomUUID();
3516
+ }
3517
+ if (typeof (cryptoRef == null ? void 0 : cryptoRef.getRandomValues) === "function") {
3518
+ const bytes = cryptoRef.getRandomValues(new Uint8Array(16));
3519
+ bytes[6] = bytes[6] & 15 | 64;
3520
+ bytes[8] = bytes[8] & 63 | 128;
3521
+ const hex = Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");
3522
+ return [
3523
+ hex.slice(0, 8),
3524
+ hex.slice(8, 12),
3525
+ hex.slice(12, 16),
3526
+ hex.slice(16, 20),
3527
+ hex.slice(20, 32)
3528
+ ].join("-");
3529
+ }
3530
+ const random = () => Math.floor(Math.random() * 4294967296).toString(16).padStart(8, "0");
3531
+ return `${random()}-${random().slice(0, 4)}-4${random().slice(0, 3)}-a${random().slice(0, 3)}-${random()}${random().slice(0, 4)}`;
3532
+ }
3533
+
3488
3534
  // src/utils.ts
3489
3535
  function systemClock() {
3490
3536
  return {
@@ -4252,6 +4298,7 @@ var NPAWForge = (() => {
4252
4298
  return command.type === "httpCompleted" || command.type === "httpFailed" || command.type === "storageReadCompleted" || command.type === "storageWriteCompleted" || command.type === "storageDeleteCompleted";
4253
4299
  }
4254
4300
  function runtimeConfig(options) {
4301
+ var _a, _b;
4255
4302
  const config = {
4256
4303
  accountCode: options.accountCode
4257
4304
  };
@@ -4274,6 +4321,13 @@ var NPAWForge = (() => {
4274
4321
  options.preSessionEventQueueMaxAgeMs
4275
4322
  );
4276
4323
  assignOptional(config, "logLevel", options.logLevel);
4324
+ const autoDeviceIdentity = (_a = options.autoDeviceIdentity) != null ? _a : true;
4325
+ assignOptional(
4326
+ config,
4327
+ "deviceUuid",
4328
+ (_b = options.deviceUuid) != null ? _b : autoDeviceIdentity ? persistentDeviceUuid() : void 0
4329
+ );
4330
+ assignOptional(config, "deviceInfo", options.deviceInfo);
4277
4331
  return config;
4278
4332
  }
4279
4333
  function assignOptional(config, key, value) {