@formo/analytics 1.16.3 → 1.16.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@formo/analytics",
3
- "version": "1.16.3",
3
+ "version": "1.16.4",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/getformo/sdk.git"
@@ -23,7 +23,6 @@
23
23
  "dependencies": {
24
24
  "ethereum-cryptography": "^3.1.0",
25
25
  "fetch-retry": "^6.0.0",
26
- "is-network-error": "^1.1.0",
27
26
  "mipd": "^0.0.7"
28
27
  },
29
28
  "devDependencies": {
@@ -1,4 +1,4 @@
1
- import isNetworkError from "is-network-error";
1
+ import { isNetworkError } from "../../validators";
2
2
  import { IFormoEvent, IFormoEventPayload } from "../../types";
3
3
  import {
4
4
  clampNumber,
@@ -1,5 +1,6 @@
1
1
  export * from "./address";
2
2
  export * from "./agent";
3
+ export * from "./network";
3
4
  export * from "./object";
4
5
  export * from "./string";
5
6
  export * from "./type-check";
@@ -0,0 +1,34 @@
1
+ const objectToString = Object.prototype.toString;
2
+
3
+ const isError = (value: any) => objectToString.call(value) === "[object Error]";
4
+
5
+ const errorMessages = new Set([
6
+ "network error", // Chrome
7
+ "Failed to fetch", // Chrome
8
+ "NetworkError when attempting to fetch resource.", // Firefox
9
+ "The Internet connection appears to be offline.", // Safari 16
10
+ "Load failed", // Safari 17+
11
+ "Network request failed", // `cross-fetch`
12
+ "fetch failed", // Undici (Node.js)
13
+ "terminated", // Undici (Node.js)
14
+ ]);
15
+
16
+ export function isNetworkError(error: any) {
17
+ const isValid =
18
+ error &&
19
+ isError(error) &&
20
+ error.name === "TypeError" &&
21
+ typeof error.message === "string";
22
+
23
+ if (!isValid) {
24
+ return false;
25
+ }
26
+
27
+ // We do an extra check for Safari 17+ as it has a very generic error message.
28
+ // Network errors in Safari have no stack.
29
+ if (error.message === "Load failed") {
30
+ return error.stack === undefined;
31
+ }
32
+
33
+ return errorMessages.has(error.message);
34
+ }