@npaw/forge-web 10.0.3 → 10.1.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.d.cts CHANGED
@@ -1273,20 +1273,6 @@ declare class BrowserForgeTransport implements ForgeTransport {
1273
1273
  }
1274
1274
  declare function requestUrl(request: ForgeTransportRequest): string;
1275
1275
 
1276
- /**
1277
- * Copyright (C) NPAW - All Rights Reserved
1278
- *
1279
- * This source code is protected under international copyright law. All rights
1280
- * reserved and protected by the copyright holders.
1281
- * This file is confidential and only available to authorized individuals with the
1282
- * permission of the copyright holders. If you encounter this file and do not have
1283
- * permission, please contact the copyright holders and delete this file.
1284
- *
1285
- *
1286
- * @author: Victor Soto <victor.soto@nicepeopleatwork.com>
1287
- * @description: Browser storage implementations for Forge Web host effects.
1288
- */
1289
-
1290
1276
  declare class MemoryForgeStorage implements ForgeStorage {
1291
1277
  private readonly values;
1292
1278
  read(key: string): string | null;
package/dist/index.d.ts CHANGED
@@ -1273,20 +1273,6 @@ declare class BrowserForgeTransport implements ForgeTransport {
1273
1273
  }
1274
1274
  declare function requestUrl(request: ForgeTransportRequest): string;
1275
1275
 
1276
- /**
1277
- * Copyright (C) NPAW - All Rights Reserved
1278
- *
1279
- * This source code is protected under international copyright law. All rights
1280
- * reserved and protected by the copyright holders.
1281
- * This file is confidential and only available to authorized individuals with the
1282
- * permission of the copyright holders. If you encounter this file and do not have
1283
- * permission, please contact the copyright holders and delete this file.
1284
- *
1285
- *
1286
- * @author: Victor Soto <victor.soto@nicepeopleatwork.com>
1287
- * @description: Browser storage implementations for Forge Web host effects.
1288
- */
1289
-
1290
1276
  declare class MemoryForgeStorage implements ForgeStorage {
1291
1277
  private readonly values;
1292
1278
  read(key: string): string | null;
@@ -121,6 +121,70 @@ var NPAWForge = (() => {
121
121
  withoutNetworkCapture: () => withoutNetworkCapture
122
122
  });
123
123
 
124
+ // src/global.ts
125
+ function getGlobalObject() {
126
+ if (typeof globalThis !== "undefined") {
127
+ return globalThis;
128
+ }
129
+ if (typeof self !== "undefined") {
130
+ return self;
131
+ }
132
+ if (typeof window !== "undefined") {
133
+ return window;
134
+ }
135
+ throw new Error("no global object available");
136
+ }
137
+
138
+ // src/compat-bootstrap.ts
139
+ function installLegacyRuntimeShims(target) {
140
+ var _a;
141
+ let host;
142
+ try {
143
+ host = target != null ? target : getGlobalObject();
144
+ } catch (e2) {
145
+ return;
146
+ }
147
+ try {
148
+ if (typeof host.globalThis === "undefined") {
149
+ host.globalThis = host;
150
+ }
151
+ } catch (e2) {
152
+ }
153
+ try {
154
+ if (typeof host.queueMicrotask !== "function") {
155
+ host.queueMicrotask = function queueMicrotask2(callback) {
156
+ Promise.resolve().then(callback).catch((error) => {
157
+ setTimeout(() => {
158
+ throw error;
159
+ }, 0);
160
+ });
161
+ };
162
+ }
163
+ } catch (e2) {
164
+ }
165
+ try {
166
+ const arrayProto = (_a = host.Array) == null ? void 0 : _a.prototype;
167
+ if (arrayProto && typeof arrayProto.at !== "function") {
168
+ Object.defineProperty(arrayProto, "at", {
169
+ value: function at(index) {
170
+ const length = this.length >>> 0;
171
+ const relative = Math.trunc(Number(index) || 0);
172
+ const resolved = relative >= 0 ? relative : length + relative;
173
+ if (resolved < 0 || resolved >= length) {
174
+ return void 0;
175
+ }
176
+ return this[resolved];
177
+ },
178
+ writable: true,
179
+ configurable: true,
180
+ // Non-enumerable so host-app for..in loops over arrays stay safe.
181
+ enumerable: false
182
+ });
183
+ }
184
+ } catch (e2) {
185
+ }
186
+ }
187
+
124
188
  // src/types.ts
125
189
  var CAPTURE_PLAN_BITS = {
126
190
  NAVIGATION: 1 << 0,
@@ -1264,7 +1328,7 @@ var NPAWForge = (() => {
1264
1328
  if (environment.intersectionObserverFactory) {
1265
1329
  return environment.intersectionObserverFactory;
1266
1330
  }
1267
- const ctor = globalThis.IntersectionObserver;
1331
+ const ctor = getGlobalObject().IntersectionObserver;
1268
1332
  if (typeof ctor !== "function") {
1269
1333
  return void 0;
1270
1334
  }
@@ -1274,7 +1338,7 @@ var NPAWForge = (() => {
1274
1338
  if (environment.mutationObserverFactory) {
1275
1339
  return environment.mutationObserverFactory;
1276
1340
  }
1277
- const ctor = globalThis.MutationObserver;
1341
+ const ctor = getGlobalObject().MutationObserver;
1278
1342
  if (typeof ctor !== "function") {
1279
1343
  return void 0;
1280
1344
  }
@@ -3801,7 +3865,7 @@ var NPAWForge = (() => {
3801
3865
  }
3802
3866
  const generated = randomUuid();
3803
3867
  try {
3804
- (_a = globalThis.localStorage) == null ? void 0 : _a.setItem(DEVICE_UUID_STORAGE_KEY, generated);
3868
+ (_a = getGlobalObject().localStorage) == null ? void 0 : _a.setItem(DEVICE_UUID_STORAGE_KEY, generated);
3805
3869
  } catch (e2) {
3806
3870
  }
3807
3871
  return generated;
@@ -3809,14 +3873,14 @@ var NPAWForge = (() => {
3809
3873
  function readStoredUuid() {
3810
3874
  var _a;
3811
3875
  try {
3812
- const value = (_a = globalThis.localStorage) == null ? void 0 : _a.getItem(DEVICE_UUID_STORAGE_KEY);
3876
+ const value = (_a = getGlobalObject().localStorage) == null ? void 0 : _a.getItem(DEVICE_UUID_STORAGE_KEY);
3813
3877
  return value && value.trim().length > 0 ? value : void 0;
3814
3878
  } catch (e2) {
3815
3879
  return void 0;
3816
3880
  }
3817
3881
  }
3818
3882
  function randomUuid() {
3819
- const cryptoRef = globalThis.crypto;
3883
+ const cryptoRef = getGlobalObject().crypto;
3820
3884
  if (typeof (cryptoRef == null ? void 0 : cryptoRef.randomUUID) === "function") {
3821
3885
  return cryptoRef.randomUUID();
3822
3886
  }
@@ -3950,11 +4014,11 @@ var NPAWForge = (() => {
3950
4014
  }
3951
4015
  function readBrowserDeviceInsightsEnvironment() {
3952
4016
  const environment = {};
3953
- const performanceRef = globalThis.performance;
4017
+ const performanceRef = getGlobalObject().performance;
3954
4018
  if (performanceRef && typeof performanceRef.memory === "object" && performanceRef.memory !== null) {
3955
4019
  environment.memory = () => performanceRef.memory;
3956
4020
  }
3957
- const navigatorRef = globalThis.navigator;
4021
+ const navigatorRef = getGlobalObject().navigator;
3958
4022
  if (navigatorRef && typeof navigatorRef.getBattery === "function") {
3959
4023
  environment.getBattery = () => navigatorRef.getBattery();
3960
4024
  }
@@ -4045,6 +4109,13 @@ var NPAWForge = (() => {
4045
4109
  function isPromiseLike(value) {
4046
4110
  return Boolean(value && typeof value.then === "function");
4047
4111
  }
4112
+ function fromEntries(entries) {
4113
+ const result = {};
4114
+ for (const entry of entries) {
4115
+ result[entry[0]] = entry[1];
4116
+ }
4117
+ return result;
4118
+ }
4048
4119
 
4049
4120
  // src/effects.ts
4050
4121
  var BrowserEffectExecutor = class {
@@ -4344,13 +4415,14 @@ var NPAWForge = (() => {
4344
4415
  }
4345
4416
  function safeLocalStorage() {
4346
4417
  try {
4347
- if (typeof globalThis.localStorage === "undefined") {
4418
+ const host = getGlobalObject();
4419
+ if (typeof host.localStorage === "undefined") {
4348
4420
  return null;
4349
4421
  }
4350
4422
  const probe = "__npaw_forge_storage_probe__";
4351
- globalThis.localStorage.setItem(probe, "1");
4352
- globalThis.localStorage.removeItem(probe);
4353
- return globalThis.localStorage;
4423
+ host.localStorage.setItem(probe, "1");
4424
+ host.localStorage.removeItem(probe);
4425
+ return host.localStorage;
4354
4426
  } catch (e2) {
4355
4427
  return null;
4356
4428
  }
@@ -4359,10 +4431,11 @@ var NPAWForge = (() => {
4359
4431
  // src/transport.ts
4360
4432
  var BrowserForgeTransport = class {
4361
4433
  async send(request) {
4362
- if (typeof globalThis.fetch === "function") {
4434
+ const host = getGlobalObject();
4435
+ if (typeof host.fetch === "function") {
4363
4436
  return sendWithFetch(request);
4364
4437
  }
4365
- if (typeof globalThis.XMLHttpRequest === "function") {
4438
+ if (typeof host.XMLHttpRequest === "function") {
4366
4439
  return sendWithXhr(request);
4367
4440
  }
4368
4441
  throw new Error("fetch and XMLHttpRequest are unavailable");
@@ -4377,7 +4450,7 @@ var NPAWForge = (() => {
4377
4450
  if (body !== void 0) {
4378
4451
  init.body = body;
4379
4452
  }
4380
- const response = await withoutNetworkCapture(() => globalThis.fetch(requestUrl(request), init));
4453
+ const response = await withoutNetworkCapture(() => getGlobalObject().fetch(requestUrl(request), init));
4381
4454
  const headers = {};
4382
4455
  response.headers.forEach((value, key) => {
4383
4456
  headers[key] = value;
@@ -4430,8 +4503,9 @@ var NPAWForge = (() => {
4430
4503
  return base.toString();
4431
4504
  }
4432
4505
  function browserBaseUrl() {
4433
- if (typeof globalThis.location !== "undefined" && globalThis.location.href) {
4434
- return globalThis.location.href;
4506
+ const host = getGlobalObject();
4507
+ if (typeof host.location !== "undefined" && host.location.href) {
4508
+ return host.location.href;
4435
4509
  }
4436
4510
  return "https://localhost/";
4437
4511
  }
@@ -4519,6 +4593,9 @@ var NPAWForge = (() => {
4519
4593
  if (typeof ArrayBuffer === "undefined" || typeof Uint8Array === "undefined") {
4520
4594
  throw new Error("typed arrays are unavailable");
4521
4595
  }
4596
+ if (typeof TextEncoder === "undefined" || typeof TextDecoder === "undefined") {
4597
+ throw new Error("TextEncoder/TextDecoder are unavailable");
4598
+ }
4522
4599
  }
4523
4600
 
4524
4601
  // src/runtime.ts
@@ -4557,7 +4634,20 @@ var NPAWForge = (() => {
4557
4634
  attributes: {}
4558
4635
  });
4559
4636
  }
4560
- const module = await normalizeWasmLoader(options.wasm).load();
4637
+ let module;
4638
+ try {
4639
+ module = await normalizeWasmLoader(options.wasm).load();
4640
+ } catch (error) {
4641
+ if (error instanceof ForgeCreateError) {
4642
+ throw error;
4643
+ }
4644
+ throw new ForgeCreateError({
4645
+ code: "wasm_instantiate_failed",
4646
+ message: describeWasmLoadError(error),
4647
+ recoverable: false,
4648
+ attributes: {}
4649
+ });
4650
+ }
4561
4651
  const response = module.forgeRuntimeCreate(runtimeConfig(options));
4562
4652
  if (!response.ok || !response.value) {
4563
4653
  throw new ForgeCreateError(boundaryDiagnostic(response.error));
@@ -4841,6 +4931,13 @@ var NPAWForge = (() => {
4841
4931
  const diagnostic = boundaryDiagnostic(error);
4842
4932
  return errorBatch(diagnostic.code, diagnostic.message);
4843
4933
  }
4934
+ function describeWasmLoadError(error) {
4935
+ if (error instanceof Error) {
4936
+ const name = error.name && error.name !== "Error" ? `${error.name}: ` : "";
4937
+ return `WASM kernel failed to load: ${name}${error.message}`;
4938
+ }
4939
+ return `WASM kernel failed to load: ${String(error)}`;
4940
+ }
4844
4941
  function boundaryDiagnostic(error) {
4845
4942
  if (!error) {
4846
4943
  return {
@@ -4931,7 +5028,7 @@ var NPAWForge = (() => {
4931
5028
  }
4932
5029
  };
4933
5030
  function readNavigatorConnection() {
4934
- const navigatorRef = globalThis.navigator;
5031
+ const navigatorRef = getGlobalObject().navigator;
4935
5032
  return navigatorRef == null ? void 0 : navigatorRef.connection;
4936
5033
  }
4937
5034
 
@@ -4996,7 +5093,7 @@ var NPAWForge = (() => {
4996
5093
  };
4997
5094
  }
4998
5095
  function readGeolocationEnvironment() {
4999
- const navigatorRef = globalThis.navigator;
5096
+ const navigatorRef = getGlobalObject().navigator;
5000
5097
  const geolocation = navigatorRef == null ? void 0 : navigatorRef.geolocation;
5001
5098
  const permissions = navigatorRef == null ? void 0 : navigatorRef.permissions;
5002
5099
  if (!geolocation || !(permissions == null ? void 0 : permissions.query)) {
@@ -12186,7 +12283,7 @@ var NPAWForge = (() => {
12186
12283
  if (this.fetchAttempts >= maxFetchRetries) {
12187
12284
  return;
12188
12285
  }
12189
- const fetchFn = (_d = (_c = this.options) == null ? void 0 : _c.fetch) != null ? _d : globalThis.fetch;
12286
+ const fetchFn = (_d = (_c = this.options) == null ? void 0 : _c.fetch) != null ? _d : getGlobalObject().fetch;
12190
12287
  if (typeof fetchFn !== "function") {
12191
12288
  return;
12192
12289
  }
@@ -13718,7 +13815,7 @@ var NPAWForge = (() => {
13718
13815
  ERROR_VAST_XML_PARSING: "ERROR_VAST_XML_PARSING",
13719
13816
  ERROR_PARSE: "ERROR_PARSE"
13720
13817
  };
13721
- return Object.fromEntries(
13818
+ return fromEntries(
13722
13819
  Object.entries(fallback).map(([key, value]) => {
13723
13820
  var _a;
13724
13821
  return [key, (_a = stringValue(read(sdk, key))) != null ? _a : value];
@@ -13856,7 +13953,7 @@ var NPAWForge = (() => {
13856
13953
  StallStarted: "StallStarted",
13857
13954
  StallEnded: "StallEnded"
13858
13955
  };
13859
- return Object.fromEntries(
13956
+ return fromEntries(
13860
13957
  Object.entries(fallback).map(([key, value]) => {
13861
13958
  var _a;
13862
13959
  return [key, (_a = stringValue(read(events, key))) != null ? _a : value];
@@ -14217,7 +14314,7 @@ var NPAWForge = (() => {
14217
14314
  }
14218
14315
  }
14219
14316
  function cleanObject(value) {
14220
- return Object.fromEntries(
14317
+ return fromEntries(
14221
14318
  Object.entries(value).filter((entry) => entry[1] !== void 0)
14222
14319
  );
14223
14320
  }
@@ -14302,7 +14399,7 @@ var NPAWForge = (() => {
14302
14399
  return value == null ? void 0 : value.split("?")[0];
14303
14400
  }
14304
14401
  function globalRecord(name) {
14305
- return memberRecord(globalThis[name]);
14402
+ return memberRecord(getGlobalObject()[name]);
14306
14403
  }
14307
14404
  function realmOf(candidate) {
14308
14405
  var _a;
@@ -14329,6 +14426,7 @@ var NPAWForge = (() => {
14329
14426
  var adapters = NPAWForge.adapters;
14330
14427
 
14331
14428
  // src/script-entry.ts
14429
+ installLegacyRuntimeShims();
14332
14430
  var defaultInstancePromise2 = autoBootstrapFromCurrentScript();
14333
14431
  return __toCommonJS(script_entry_exports);
14334
14432
  })();