@codaco/analytics 1.0.0-alpha → 1.0.1-alpha-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/.turbo/turbo-build.log +8 -10
- package/.turbo/turbo-lint.log +1 -1
- package/README.md +3 -35
- package/dist/index.d.mts +39 -16
- package/dist/index.mjs +100 -25
- package/dist/index.mjs.map +1 -0
- package/jest.config.js +198 -0
- package/package.json +10 -12
- package/src/index.ts +156 -53
- package/src/utils.ts +19 -0
- package/dist/index.d.ts +0 -20
- package/dist/index.js +0 -65
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,18 +1,16 @@
|
|
|
1
1
|
|
|
2
|
-
> @codaco/analytics@1.0.
|
|
3
|
-
> tsup src/index.ts --format
|
|
2
|
+
> @codaco/analytics@1.0.1-alpha-1 build /Users/buckhalt/Code/complexdatacollective/error-analytics-microservice/packages/analytics
|
|
3
|
+
> tsup src/index.ts --format esm --dts --clean --sourcemap
|
|
4
4
|
|
|
5
5
|
CLI Building entry: src/index.ts
|
|
6
6
|
CLI Using tsconfig: tsconfig.json
|
|
7
7
|
CLI tsup v7.2.0
|
|
8
8
|
CLI Target: es2022
|
|
9
|
-
|
|
9
|
+
CLI Cleaning output folder
|
|
10
10
|
ESM Build start
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
ESM
|
|
14
|
-
ESM ⚡️ Build success in 65ms
|
|
11
|
+
ESM dist/index.mjs 2.91 KB
|
|
12
|
+
ESM dist/index.mjs.map 6.65 KB
|
|
13
|
+
ESM ⚡️ Build success in 44ms
|
|
15
14
|
DTS Build start
|
|
16
|
-
DTS ⚡️ Build success in
|
|
17
|
-
DTS dist/index.d.
|
|
18
|
-
DTS dist/index.d.mts 583.00 B
|
|
15
|
+
DTS ⚡️ Build success in 985ms
|
|
16
|
+
DTS dist/index.d.mts 1.63 KB
|
package/.turbo/turbo-lint.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @codaco/analytics@1.0.
|
|
2
|
+
> @codaco/analytics@1.0.1-alpha-1 lint /Users/buckhalt/Code/complexdatacollective/error-analytics-microservice/packages/analytics
|
|
3
3
|
> eslint .
|
|
4
4
|
|
|
5
5
|
Pages directory cannot be found at /Users/buckhalt/Code/complexdatacollective/error-analytics-microservice/packages/analytics/pages or /Users/buckhalt/Code/complexdatacollective/error-analytics-microservice/packages/analytics/src/pages. If using a custom path, please configure with the `no-html-link-for-pages` rule in your eslint config file.
|
package/README.md
CHANGED
|
@@ -2,40 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
This npm package implements methods and types for sending analytics and errors from Fresco instances to a custom error and analytics microservice.
|
|
4
4
|
|
|
5
|
-
It exports two
|
|
5
|
+
It exports two functions:
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
**createRouteHandler** - A function that creates a NextJs route handler which geolocates requests, and forwards the event payload to the microservice.
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
type EventPayload = {
|
|
11
|
-
type:
|
|
12
|
-
| "InterviewCompleted"
|
|
13
|
-
| "InterviewStarted"
|
|
14
|
-
| "ProtocolInstalled"
|
|
15
|
-
| "AppSetup";
|
|
16
|
-
metadata?: string;
|
|
17
|
-
timestamp?: string;
|
|
18
|
-
isocode?: string;
|
|
19
|
-
installationid: string;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
trackEvent(event: EventPayload);
|
|
23
|
-
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
2. trackError - sends an error payload to the microservice.
|
|
27
|
-
|
|
28
|
-
```ts
|
|
29
|
-
type ErrorPayload = {
|
|
30
|
-
code: number;
|
|
31
|
-
message: string;
|
|
32
|
-
details: string;
|
|
33
|
-
stacktrace: string;
|
|
34
|
-
installationid: string;
|
|
35
|
-
timestamp?: string;
|
|
36
|
-
path: string;
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
trackError(error: ErrorPayload);
|
|
40
|
-
|
|
41
|
-
```
|
|
9
|
+
**makeEventTracker** - A function that returns a `trackEvent` function, which attaches timestamp data to an event, and then calls the route handler.
|
package/dist/index.d.mts
CHANGED
|
@@ -1,20 +1,43 @@
|
|
|
1
|
-
|
|
1
|
+
import { NextRequest } from 'next/server';
|
|
2
|
+
import { WebServiceClient } from '@maxmind/geoip2-node';
|
|
3
|
+
|
|
4
|
+
type GeoLocation = {
|
|
5
|
+
countryCode: string;
|
|
6
|
+
};
|
|
7
|
+
type AnalyticsEventBase = {
|
|
8
|
+
type: "InterviewCompleted" | "InterviewStarted" | "ProtocolInstalled" | "AppSetup" | "Error";
|
|
9
|
+
};
|
|
10
|
+
type AnalyticsEvent = AnalyticsEventBase & {
|
|
2
11
|
type: "InterviewCompleted" | "InterviewStarted" | "ProtocolInstalled" | "AppSetup";
|
|
3
|
-
metadata?: string
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
12
|
+
metadata?: Record<string, unknown>;
|
|
13
|
+
};
|
|
14
|
+
type AnalyticsError = AnalyticsEventBase & {
|
|
15
|
+
type: "Error";
|
|
16
|
+
error: {
|
|
17
|
+
message: string;
|
|
18
|
+
details: string;
|
|
19
|
+
stacktrace: string;
|
|
20
|
+
path: string;
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
type AnalyticsEventOrError = AnalyticsEvent | AnalyticsError;
|
|
24
|
+
type AnalyticsEventOrErrorWithTimestamp = AnalyticsEventOrError & {
|
|
25
|
+
timestamp: Date;
|
|
26
|
+
};
|
|
27
|
+
type DispatchableAnalyticsEvent = AnalyticsEventOrErrorWithTimestamp & {
|
|
28
|
+
installationId: string;
|
|
29
|
+
geolocation?: GeoLocation;
|
|
7
30
|
};
|
|
8
|
-
type
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
timestamp?: string;
|
|
15
|
-
path: string;
|
|
31
|
+
type RouteHandlerConfiguration = {
|
|
32
|
+
maxMindAccountId: string;
|
|
33
|
+
maxMindLicenseKey: string;
|
|
34
|
+
platformUrl?: string;
|
|
35
|
+
getInstallationId: () => Promise<string>;
|
|
36
|
+
WebServiceClient: typeof WebServiceClient;
|
|
16
37
|
};
|
|
17
|
-
declare
|
|
18
|
-
declare
|
|
38
|
+
declare const createRouteHandler: ({ maxMindAccountId, maxMindLicenseKey, platformUrl, getInstallationId, WebServiceClient, }: RouteHandlerConfiguration) => (request: NextRequest) => Promise<Response>;
|
|
39
|
+
declare const makeEventTracker: ({ endpoint }: {
|
|
40
|
+
endpoint: string;
|
|
41
|
+
}) => (event: AnalyticsEventOrError) => Promise<void>;
|
|
19
42
|
|
|
20
|
-
export {
|
|
43
|
+
export { AnalyticsError, AnalyticsEvent, AnalyticsEventBase, AnalyticsEventOrError, AnalyticsEventOrErrorWithTimestamp, DispatchableAnalyticsEvent, createRouteHandler, makeEventTracker };
|
package/dist/index.mjs
CHANGED
|
@@ -1,39 +1,114 @@
|
|
|
1
|
-
// src/
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
// src/utils.ts
|
|
2
|
+
function ensureError(value) {
|
|
3
|
+
if (!value)
|
|
4
|
+
return new Error("No value was thrown");
|
|
5
|
+
if (value instanceof Error)
|
|
6
|
+
return value;
|
|
7
|
+
if (value.isPrototypeOf(Error))
|
|
8
|
+
return value;
|
|
9
|
+
let stringified = "[Unable to stringify the thrown value]";
|
|
4
10
|
try {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
headers: {
|
|
8
|
-
"Content-Type": "application/json"
|
|
9
|
-
},
|
|
10
|
-
body: JSON.stringify(event)
|
|
11
|
-
});
|
|
12
|
-
if (!response.ok) {
|
|
13
|
-
throw new Error(`HTTP error! Status: ${response.status}`);
|
|
14
|
-
}
|
|
15
|
-
} catch (error) {
|
|
16
|
-
throw new Error("Failed to make the request");
|
|
11
|
+
stringified = JSON.stringify(value);
|
|
12
|
+
} catch {
|
|
17
13
|
}
|
|
14
|
+
const error = new Error(
|
|
15
|
+
`This value was thrown as is, not through an Error: ${stringified}`
|
|
16
|
+
);
|
|
17
|
+
return error;
|
|
18
18
|
}
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var createRouteHandler = ({
|
|
22
|
+
maxMindAccountId,
|
|
23
|
+
maxMindLicenseKey,
|
|
24
|
+
platformUrl = "https://analytics.networkcanvas.com",
|
|
25
|
+
getInstallationId,
|
|
26
|
+
WebServiceClient
|
|
27
|
+
}) => {
|
|
28
|
+
return async (request) => {
|
|
29
|
+
try {
|
|
30
|
+
const maxMindClient = new WebServiceClient(
|
|
31
|
+
maxMindAccountId,
|
|
32
|
+
maxMindLicenseKey,
|
|
33
|
+
{
|
|
34
|
+
host: "geolite.info"
|
|
35
|
+
}
|
|
36
|
+
);
|
|
37
|
+
const installationId = await getInstallationId();
|
|
38
|
+
const event = await request.json();
|
|
39
|
+
const ip = await fetch("https://api64.ipify.org").then(
|
|
40
|
+
(res) => res.text()
|
|
41
|
+
);
|
|
42
|
+
const { country } = await maxMindClient.country(ip);
|
|
43
|
+
const countryCode = country?.isoCode ?? "Unknown";
|
|
44
|
+
const dispatchableEvent = {
|
|
45
|
+
...event,
|
|
46
|
+
installationId,
|
|
47
|
+
geolocation: {
|
|
48
|
+
countryCode
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
console.log(dispatchableEvent);
|
|
52
|
+
const response = await fetch(`${platformUrl}/api/event`, {
|
|
53
|
+
keepalive: true,
|
|
54
|
+
method: "POST",
|
|
55
|
+
headers: {
|
|
56
|
+
"Content-Type": "application/json"
|
|
57
|
+
},
|
|
58
|
+
body: JSON.stringify(dispatchableEvent)
|
|
59
|
+
});
|
|
60
|
+
if (!response.ok) {
|
|
61
|
+
throw new Error(
|
|
62
|
+
`Failed to forward event to microservice: ${response.statusText}`
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
return new Response(
|
|
66
|
+
JSON.stringify({ message: "Event forwarded successfully" }),
|
|
67
|
+
{
|
|
68
|
+
status: 200,
|
|
69
|
+
headers: {
|
|
70
|
+
"Content-Type": "application/json"
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
);
|
|
74
|
+
} catch (e) {
|
|
75
|
+
const error = ensureError(e);
|
|
76
|
+
console.error("Error in route handler:", error);
|
|
77
|
+
return new Response(JSON.stringify({ error: "Internal Server Error" }), {
|
|
78
|
+
status: 500,
|
|
79
|
+
headers: {
|
|
80
|
+
"Content-Type": "application/json"
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
var makeEventTracker = ({ endpoint }) => async (event) => {
|
|
87
|
+
const eventWithTimeStamp = {
|
|
88
|
+
...event,
|
|
89
|
+
timestamp: /* @__PURE__ */ new Date()
|
|
90
|
+
};
|
|
21
91
|
try {
|
|
22
92
|
const response = await fetch(endpoint, {
|
|
23
93
|
method: "POST",
|
|
94
|
+
keepalive: true,
|
|
95
|
+
body: JSON.stringify(eventWithTimeStamp),
|
|
24
96
|
headers: {
|
|
25
97
|
"Content-Type": "application/json"
|
|
26
|
-
}
|
|
27
|
-
body: JSON.stringify(error)
|
|
98
|
+
}
|
|
28
99
|
});
|
|
29
100
|
if (!response.ok) {
|
|
30
|
-
throw new Error(
|
|
101
|
+
throw new Error(
|
|
102
|
+
`Failed to send analytics event: ${response.statusText}`
|
|
103
|
+
);
|
|
31
104
|
}
|
|
32
|
-
} catch (
|
|
33
|
-
|
|
105
|
+
} catch (e) {
|
|
106
|
+
const error = ensureError(e);
|
|
107
|
+
console.error("Error sending analytics event:", error.message);
|
|
34
108
|
}
|
|
35
|
-
}
|
|
109
|
+
};
|
|
36
110
|
export {
|
|
37
|
-
|
|
38
|
-
|
|
111
|
+
createRouteHandler,
|
|
112
|
+
makeEventTracker
|
|
39
113
|
};
|
|
114
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/utils.ts","../src/index.ts"],"sourcesContent":["// Helper function that ensures that a value is an Error\nexport function ensureError(value: unknown): Error {\n if (!value) return new Error(\"No value was thrown\");\n\n if (value instanceof Error) return value;\n\n // Test if value inherits from Error\n if (value.isPrototypeOf(Error)) return value as Error & typeof value;\n\n let stringified = \"[Unable to stringify the thrown value]\";\n try {\n stringified = JSON.stringify(value);\n } catch {}\n\n const error = new Error(\n `This value was thrown as is, not through an Error: ${stringified}`\n );\n return error;\n}\n","import type { NextRequest } from \"next/server\";\nimport { WebServiceClient } from \"@maxmind/geoip2-node\";\nimport { ensureError } from \"./utils\";\n\ntype GeoLocation = {\n countryCode: string;\n};\n\nexport type AnalyticsEventBase = {\n type:\n | \"InterviewCompleted\"\n | \"InterviewStarted\"\n | \"ProtocolInstalled\"\n | \"AppSetup\"\n | \"Error\";\n};\n\nexport type AnalyticsEvent = AnalyticsEventBase & {\n type:\n | \"InterviewCompleted\"\n | \"InterviewStarted\"\n | \"ProtocolInstalled\"\n | \"AppSetup\";\n metadata?: Record<string, unknown>;\n};\n\nexport type AnalyticsError = AnalyticsEventBase & {\n type: \"Error\";\n error: {\n message: string;\n details: string;\n stacktrace: string;\n path: string;\n };\n};\n\nexport type AnalyticsEventOrError = AnalyticsEvent | AnalyticsError;\n\nexport type AnalyticsEventOrErrorWithTimestamp = AnalyticsEventOrError & {\n timestamp: Date;\n};\n\nexport type DispatchableAnalyticsEvent = AnalyticsEventOrErrorWithTimestamp & {\n installationId: string;\n geolocation?: GeoLocation;\n};\n\ntype RouteHandlerConfiguration = {\n maxMindAccountId: string;\n maxMindLicenseKey: string;\n platformUrl?: string;\n getInstallationId: () => Promise<string>;\n WebServiceClient: typeof WebServiceClient;\n};\n\nexport const createRouteHandler = ({\n maxMindAccountId,\n maxMindLicenseKey,\n platformUrl = \"https://analytics.networkcanvas.com\",\n getInstallationId,\n WebServiceClient,\n}: RouteHandlerConfiguration) => {\n return async (request: NextRequest) => {\n try {\n const maxMindClient = new WebServiceClient(\n maxMindAccountId,\n maxMindLicenseKey,\n {\n host: \"geolite.info\",\n }\n );\n\n const installationId = await getInstallationId();\n\n const event =\n (await request.json()) as AnalyticsEventOrErrorWithTimestamp;\n\n const ip = await fetch(\"https://api64.ipify.org\").then((res) =>\n res.text()\n );\n\n const { country } = await maxMindClient.country(ip);\n const countryCode = country?.isoCode ?? \"Unknown\";\n\n const dispatchableEvent: DispatchableAnalyticsEvent = {\n ...event,\n installationId,\n geolocation: {\n countryCode,\n },\n };\n\n console.log(dispatchableEvent);\n\n // Forward to microservice\n const response = await fetch(`${platformUrl}/api/event`, {\n keepalive: true,\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n },\n body: JSON.stringify(dispatchableEvent),\n });\n\n if (!response.ok) {\n throw new Error(\n `Failed to forward event to microservice: ${response.statusText}`\n );\n }\n\n return new Response(\n JSON.stringify({ message: \"Event forwarded successfully\" }),\n {\n status: 200,\n headers: {\n \"Content-Type\": \"application/json\",\n },\n }\n );\n } catch (e) {\n const error = ensureError(e);\n console.error(\"Error in route handler:\", error);\n\n // Return an appropriate error response\n return new Response(JSON.stringify({ error: \"Internal Server Error\" }), {\n status: 500,\n headers: {\n \"Content-Type\": \"application/json\",\n },\n });\n }\n };\n};\n\nexport const makeEventTracker =\n ({ endpoint }: { endpoint: string }) =>\n async (event: AnalyticsEventOrError) => {\n const eventWithTimeStamp = {\n ...event,\n timestamp: new Date(),\n };\n\n try {\n const response = await fetch(endpoint, {\n method: \"POST\",\n keepalive: true,\n body: JSON.stringify(eventWithTimeStamp),\n headers: {\n \"Content-Type\": \"application/json\",\n },\n });\n\n if (!response.ok) {\n throw new Error(\n `Failed to send analytics event: ${response.statusText}`\n );\n }\n } catch (e) {\n const error = ensureError(e);\n\n console.error(\"Error sending analytics event:\", error.message);\n }\n };\n"],"mappings":";AACO,SAAS,YAAY,OAAuB;AACjD,MAAI,CAAC;AAAO,WAAO,IAAI,MAAM,qBAAqB;AAElD,MAAI,iBAAiB;AAAO,WAAO;AAGnC,MAAI,MAAM,cAAc,KAAK;AAAG,WAAO;AAEvC,MAAI,cAAc;AAClB,MAAI;AACF,kBAAc,KAAK,UAAU,KAAK;AAAA,EACpC,QAAQ;AAAA,EAAC;AAET,QAAM,QAAQ,IAAI;AAAA,IAChB,sDAAsD,WAAW;AAAA,EACnE;AACA,SAAO;AACT;;;ACqCO,IAAM,qBAAqB,CAAC;AAAA,EACjC;AAAA,EACA;AAAA,EACA,cAAc;AAAA,EACd;AAAA,EACA;AACF,MAAiC;AAC/B,SAAO,OAAO,YAAyB;AACrC,QAAI;AACF,YAAM,gBAAgB,IAAI;AAAA,QACxB;AAAA,QACA;AAAA,QACA;AAAA,UACE,MAAM;AAAA,QACR;AAAA,MACF;AAEA,YAAM,iBAAiB,MAAM,kBAAkB;AAE/C,YAAM,QACH,MAAM,QAAQ,KAAK;AAEtB,YAAM,KAAK,MAAM,MAAM,yBAAyB,EAAE;AAAA,QAAK,CAAC,QACtD,IAAI,KAAK;AAAA,MACX;AAEA,YAAM,EAAE,QAAQ,IAAI,MAAM,cAAc,QAAQ,EAAE;AAClD,YAAM,cAAc,SAAS,WAAW;AAExC,YAAM,oBAAgD;AAAA,QACpD,GAAG;AAAA,QACH;AAAA,QACA,aAAa;AAAA,UACX;AAAA,QACF;AAAA,MACF;AAEA,cAAQ,IAAI,iBAAiB;AAG7B,YAAM,WAAW,MAAM,MAAM,GAAG,WAAW,cAAc;AAAA,QACvD,WAAW;AAAA,QACX,QAAQ;AAAA,QACR,SAAS;AAAA,UACP,gBAAgB;AAAA,QAClB;AAAA,QACA,MAAM,KAAK,UAAU,iBAAiB;AAAA,MACxC,CAAC;AAED,UAAI,CAAC,SAAS,IAAI;AAChB,cAAM,IAAI;AAAA,UACR,4CAA4C,SAAS,UAAU;AAAA,QACjE;AAAA,MACF;AAEA,aAAO,IAAI;AAAA,QACT,KAAK,UAAU,EAAE,SAAS,+BAA+B,CAAC;AAAA,QAC1D;AAAA,UACE,QAAQ;AAAA,UACR,SAAS;AAAA,YACP,gBAAgB;AAAA,UAClB;AAAA,QACF;AAAA,MACF;AAAA,IACF,SAAS,GAAG;AACV,YAAM,QAAQ,YAAY,CAAC;AAC3B,cAAQ,MAAM,2BAA2B,KAAK;AAG9C,aAAO,IAAI,SAAS,KAAK,UAAU,EAAE,OAAO,wBAAwB,CAAC,GAAG;AAAA,QACtE,QAAQ;AAAA,QACR,SAAS;AAAA,UACP,gBAAgB;AAAA,QAClB;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AACF;AAEO,IAAM,mBACX,CAAC,EAAE,SAAS,MACZ,OAAO,UAAiC;AACtC,QAAM,qBAAqB;AAAA,IACzB,GAAG;AAAA,IACH,WAAW,oBAAI,KAAK;AAAA,EACtB;AAEA,MAAI;AACF,UAAM,WAAW,MAAM,MAAM,UAAU;AAAA,MACrC,QAAQ;AAAA,MACR,WAAW;AAAA,MACX,MAAM,KAAK,UAAU,kBAAkB;AAAA,MACvC,SAAS;AAAA,QACP,gBAAgB;AAAA,MAClB;AAAA,IACF,CAAC;AAED,QAAI,CAAC,SAAS,IAAI;AAChB,YAAM,IAAI;AAAA,QACR,mCAAmC,SAAS,UAAU;AAAA,MACxD;AAAA,IACF;AAAA,EACF,SAAS,GAAG;AACV,UAAM,QAAQ,YAAY,CAAC;AAE3B,YAAQ,MAAM,kCAAkC,MAAM,OAAO;AAAA,EAC/D;AACF;","names":[]}
|
package/jest.config.js
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* For a detailed explanation regarding each configuration property, visit:
|
|
3
|
+
* https://jestjs.io/docs/configuration
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/** @type {import('jest').Config} */
|
|
7
|
+
const config = {
|
|
8
|
+
// All imported modules in your tests should be mocked automatically
|
|
9
|
+
// automock: false,
|
|
10
|
+
|
|
11
|
+
// Stop running tests after `n` failures
|
|
12
|
+
// bail: 0,
|
|
13
|
+
|
|
14
|
+
// The directory where Jest should store its cached dependency information
|
|
15
|
+
// cacheDirectory: "/private/var/folders/vc/szx71k5j5sqcmrljl1w44ryddl7zmw/T/jest_pb0330",
|
|
16
|
+
|
|
17
|
+
// Automatically clear mock calls, instances, contexts and results before every test
|
|
18
|
+
// clearMocks: false,
|
|
19
|
+
|
|
20
|
+
// Indicates whether the coverage information should be collected while executing the test
|
|
21
|
+
// collectCoverage: false,
|
|
22
|
+
|
|
23
|
+
// An array of glob patterns indicating a set of files for which coverage information should be collected
|
|
24
|
+
// collectCoverageFrom: undefined,
|
|
25
|
+
|
|
26
|
+
// The directory where Jest should output its coverage files
|
|
27
|
+
// coverageDirectory: undefined,
|
|
28
|
+
|
|
29
|
+
// An array of regexp pattern strings used to skip coverage collection
|
|
30
|
+
// coveragePathIgnorePatterns: [
|
|
31
|
+
// "/node_modules/"
|
|
32
|
+
// ],
|
|
33
|
+
|
|
34
|
+
// Indicates which provider should be used to instrument code for coverage
|
|
35
|
+
coverageProvider: "v8",
|
|
36
|
+
|
|
37
|
+
// A list of reporter names that Jest uses when writing coverage reports
|
|
38
|
+
// coverageReporters: [
|
|
39
|
+
// "json",
|
|
40
|
+
// "text",
|
|
41
|
+
// "lcov",
|
|
42
|
+
// "clover"
|
|
43
|
+
// ],
|
|
44
|
+
|
|
45
|
+
// An object that configures minimum threshold enforcement for coverage results
|
|
46
|
+
// coverageThreshold: undefined,
|
|
47
|
+
|
|
48
|
+
// A path to a custom dependency extractor
|
|
49
|
+
// dependencyExtractor: undefined,
|
|
50
|
+
|
|
51
|
+
// Make calling deprecated APIs throw helpful error messages
|
|
52
|
+
// errorOnDeprecated: false,
|
|
53
|
+
|
|
54
|
+
// The default configuration for fake timers
|
|
55
|
+
// fakeTimers: {
|
|
56
|
+
// "enableGlobally": false
|
|
57
|
+
// },
|
|
58
|
+
|
|
59
|
+
// Force coverage collection from ignored files using an array of glob patterns
|
|
60
|
+
// forceCoverageMatch: [],
|
|
61
|
+
|
|
62
|
+
// A path to a module which exports an async function that is triggered once before all test suites
|
|
63
|
+
// globalSetup: undefined,
|
|
64
|
+
|
|
65
|
+
// A path to a module which exports an async function that is triggered once after all test suites
|
|
66
|
+
// globalTeardown: undefined,
|
|
67
|
+
|
|
68
|
+
// A set of global variables that need to be available in all test environments
|
|
69
|
+
// globals: {},
|
|
70
|
+
|
|
71
|
+
// The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers.
|
|
72
|
+
// maxWorkers: "50%",
|
|
73
|
+
|
|
74
|
+
// An array of directory names to be searched recursively up from the requiring module's location
|
|
75
|
+
// moduleDirectories: [
|
|
76
|
+
// "node_modules"
|
|
77
|
+
// ],
|
|
78
|
+
|
|
79
|
+
// An array of file extensions your modules use
|
|
80
|
+
// moduleFileExtensions: [
|
|
81
|
+
// "js",
|
|
82
|
+
// "mjs",
|
|
83
|
+
// "cjs",
|
|
84
|
+
// "jsx",
|
|
85
|
+
// "ts",
|
|
86
|
+
// "tsx",
|
|
87
|
+
// "json",
|
|
88
|
+
// "node"
|
|
89
|
+
// ],
|
|
90
|
+
|
|
91
|
+
// A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
|
|
92
|
+
// moduleNameMapper: {},
|
|
93
|
+
|
|
94
|
+
// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
|
|
95
|
+
// modulePathIgnorePatterns: [],
|
|
96
|
+
|
|
97
|
+
// Activates notifications for test results
|
|
98
|
+
// notify: false,
|
|
99
|
+
|
|
100
|
+
// An enum that specifies notification mode. Requires { notify: true }
|
|
101
|
+
// notifyMode: "failure-change",
|
|
102
|
+
|
|
103
|
+
// A preset that is used as a base for Jest's configuration
|
|
104
|
+
// preset: undefined,
|
|
105
|
+
|
|
106
|
+
// Run tests from one or more projects
|
|
107
|
+
// projects: undefined,
|
|
108
|
+
|
|
109
|
+
// Use this configuration option to add custom reporters to Jest
|
|
110
|
+
// reporters: undefined,
|
|
111
|
+
|
|
112
|
+
// Automatically reset mock state before every test
|
|
113
|
+
// resetMocks: false,
|
|
114
|
+
|
|
115
|
+
// Reset the module registry before running each individual test
|
|
116
|
+
// resetModules: false,
|
|
117
|
+
|
|
118
|
+
// A path to a custom resolver
|
|
119
|
+
// resolver: undefined,
|
|
120
|
+
|
|
121
|
+
// Automatically restore mock state and implementation before every test
|
|
122
|
+
// restoreMocks: false,
|
|
123
|
+
|
|
124
|
+
// The root directory that Jest should scan for tests and modules within
|
|
125
|
+
// rootDir: undefined,
|
|
126
|
+
|
|
127
|
+
// A list of paths to directories that Jest should use to search for files in
|
|
128
|
+
// roots: [
|
|
129
|
+
// "<rootDir>"
|
|
130
|
+
// ],
|
|
131
|
+
|
|
132
|
+
// Allows you to use a custom runner instead of Jest's default test runner
|
|
133
|
+
// runner: "jest-runner",
|
|
134
|
+
|
|
135
|
+
// The paths to modules that run some code to configure or set up the testing environment before each test
|
|
136
|
+
// setupFiles: [],
|
|
137
|
+
|
|
138
|
+
// A list of paths to modules that run some code to configure or set up the testing framework before each test
|
|
139
|
+
// setupFilesAfterEnv: [],
|
|
140
|
+
|
|
141
|
+
// The number of seconds after which a test is considered as slow and reported as such in the results.
|
|
142
|
+
// slowTestThreshold: 5,
|
|
143
|
+
|
|
144
|
+
// A list of paths to snapshot serializer modules Jest should use for snapshot testing
|
|
145
|
+
// snapshotSerializers: [],
|
|
146
|
+
|
|
147
|
+
// The test environment that will be used for testing
|
|
148
|
+
testEnvironment: "node",
|
|
149
|
+
|
|
150
|
+
// Options that will be passed to the testEnvironment
|
|
151
|
+
// testEnvironmentOptions: {},
|
|
152
|
+
|
|
153
|
+
// Adds a location field to test results
|
|
154
|
+
// testLocationInResults: false,
|
|
155
|
+
|
|
156
|
+
// The glob patterns Jest uses to detect test files
|
|
157
|
+
testMatch: [
|
|
158
|
+
"**/__tests__/**/*.[jt]s?(x)",
|
|
159
|
+
"**/?(*.)+(spec|test).m[tj]s?(x)"
|
|
160
|
+
],
|
|
161
|
+
|
|
162
|
+
// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
|
|
163
|
+
// testPathIgnorePatterns: [
|
|
164
|
+
// "/node_modules/"
|
|
165
|
+
// ],
|
|
166
|
+
|
|
167
|
+
// The regexp pattern or array of patterns that Jest uses to detect test files
|
|
168
|
+
// testRegex: [],
|
|
169
|
+
|
|
170
|
+
// This option allows the use of a custom results processor
|
|
171
|
+
// testResultsProcessor: undefined,
|
|
172
|
+
|
|
173
|
+
// This option allows use of a custom test runner
|
|
174
|
+
// testRunner: "jest-circus/runner",
|
|
175
|
+
|
|
176
|
+
// A map from regular expressions to paths to transformers
|
|
177
|
+
// transform: undefined,
|
|
178
|
+
|
|
179
|
+
// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
|
|
180
|
+
// transformIgnorePatterns: [
|
|
181
|
+
// "/node_modules/",
|
|
182
|
+
// "\\.pnp\\.[^\\/]+$"
|
|
183
|
+
// ],
|
|
184
|
+
|
|
185
|
+
// An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
|
|
186
|
+
// unmockedModulePathPatterns: undefined,
|
|
187
|
+
|
|
188
|
+
// Indicates whether each individual test should be reported during the run
|
|
189
|
+
// verbose: undefined,
|
|
190
|
+
|
|
191
|
+
// An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode
|
|
192
|
+
// watchPathIgnorePatterns: [],
|
|
193
|
+
|
|
194
|
+
// Whether to use watchman for file crawling
|
|
195
|
+
// watchman: true,
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
module.exports = config;
|
package/package.json
CHANGED
|
@@ -1,26 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codaco/analytics",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"main": "./dist/index.js",
|
|
3
|
+
"version": "1.0.1-alpha-1",
|
|
5
4
|
"module": "./dist/index.mjs",
|
|
6
|
-
"types": "./dist/index.d.
|
|
5
|
+
"types": "./dist/index.d.mts",
|
|
7
6
|
"author": "Complex Data Collective <developers@coda.co>",
|
|
8
7
|
"description": "Utilities for tracking analytics and error reporting in Fresco",
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
"typescript": "latest"
|
|
8
|
+
"peerDependencies": {
|
|
9
|
+
"next": "13 || 14"
|
|
12
10
|
},
|
|
13
11
|
"devDependencies": {
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"@types/react-dom": "^18.2.0",
|
|
17
|
-
"react": "^18.2.0",
|
|
18
|
-
"typescript": "^5.2.2",
|
|
12
|
+
"tsup": "^7.2.0",
|
|
13
|
+
"typescript": "^5.3.2",
|
|
19
14
|
"eslint-config-custom": "0.0.0",
|
|
20
15
|
"tsconfig": "0.0.0"
|
|
21
16
|
},
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"@maxmind/geoip2-node": "^5.0.0"
|
|
19
|
+
},
|
|
22
20
|
"scripts": {
|
|
23
|
-
"build": "tsup src/index.ts --format
|
|
21
|
+
"build": "tsup src/index.ts --format esm --dts --clean --sourcemap",
|
|
24
22
|
"lint": "eslint .",
|
|
25
23
|
"dev": "npm run build -- --watch"
|
|
26
24
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,60 +1,163 @@
|
|
|
1
|
-
|
|
1
|
+
import type { NextRequest } from "next/server";
|
|
2
|
+
import { WebServiceClient } from "@maxmind/geoip2-node";
|
|
3
|
+
import { ensureError } from "./utils";
|
|
4
|
+
|
|
5
|
+
type GeoLocation = {
|
|
6
|
+
countryCode: string;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export type AnalyticsEventBase = {
|
|
10
|
+
type:
|
|
11
|
+
| "InterviewCompleted"
|
|
12
|
+
| "InterviewStarted"
|
|
13
|
+
| "ProtocolInstalled"
|
|
14
|
+
| "AppSetup"
|
|
15
|
+
| "Error";
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export type AnalyticsEvent = AnalyticsEventBase & {
|
|
2
19
|
type:
|
|
3
20
|
| "InterviewCompleted"
|
|
4
21
|
| "InterviewStarted"
|
|
5
22
|
| "ProtocolInstalled"
|
|
6
23
|
| "AppSetup";
|
|
7
|
-
metadata?: string
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
24
|
+
metadata?: Record<string, unknown>;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export type AnalyticsError = AnalyticsEventBase & {
|
|
28
|
+
type: "Error";
|
|
29
|
+
error: {
|
|
30
|
+
message: string;
|
|
31
|
+
details: string;
|
|
32
|
+
stacktrace: string;
|
|
33
|
+
path: string;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export type AnalyticsEventOrError = AnalyticsEvent | AnalyticsError;
|
|
38
|
+
|
|
39
|
+
export type AnalyticsEventOrErrorWithTimestamp = AnalyticsEventOrError & {
|
|
40
|
+
timestamp: Date;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export type DispatchableAnalyticsEvent = AnalyticsEventOrErrorWithTimestamp & {
|
|
44
|
+
installationId: string;
|
|
45
|
+
geolocation?: GeoLocation;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
type RouteHandlerConfiguration = {
|
|
49
|
+
maxMindAccountId: string;
|
|
50
|
+
maxMindLicenseKey: string;
|
|
51
|
+
platformUrl?: string;
|
|
52
|
+
getInstallationId: () => Promise<string>;
|
|
53
|
+
WebServiceClient: typeof WebServiceClient;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export const createRouteHandler = ({
|
|
57
|
+
maxMindAccountId,
|
|
58
|
+
maxMindLicenseKey,
|
|
59
|
+
platformUrl = "https://analytics.networkcanvas.com",
|
|
60
|
+
getInstallationId,
|
|
61
|
+
WebServiceClient,
|
|
62
|
+
}: RouteHandlerConfiguration) => {
|
|
63
|
+
return async (request: NextRequest) => {
|
|
64
|
+
try {
|
|
65
|
+
const maxMindClient = new WebServiceClient(
|
|
66
|
+
maxMindAccountId,
|
|
67
|
+
maxMindLicenseKey,
|
|
68
|
+
{
|
|
69
|
+
host: "geolite.info",
|
|
70
|
+
}
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
const installationId = await getInstallationId();
|
|
74
|
+
|
|
75
|
+
const event =
|
|
76
|
+
(await request.json()) as AnalyticsEventOrErrorWithTimestamp;
|
|
77
|
+
|
|
78
|
+
const ip = await fetch("https://api64.ipify.org").then((res) =>
|
|
79
|
+
res.text()
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
const { country } = await maxMindClient.country(ip);
|
|
83
|
+
const countryCode = country?.isoCode ?? "Unknown";
|
|
84
|
+
|
|
85
|
+
const dispatchableEvent: DispatchableAnalyticsEvent = {
|
|
86
|
+
...event,
|
|
87
|
+
installationId,
|
|
88
|
+
geolocation: {
|
|
89
|
+
countryCode,
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
console.log(dispatchableEvent);
|
|
94
|
+
|
|
95
|
+
// Forward to microservice
|
|
96
|
+
const response = await fetch(`${platformUrl}/api/event`, {
|
|
97
|
+
keepalive: true,
|
|
98
|
+
method: "POST",
|
|
99
|
+
headers: {
|
|
100
|
+
"Content-Type": "application/json",
|
|
101
|
+
},
|
|
102
|
+
body: JSON.stringify(dispatchableEvent),
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
if (!response.ok) {
|
|
106
|
+
throw new Error(
|
|
107
|
+
`Failed to forward event to microservice: ${response.statusText}`
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return new Response(
|
|
112
|
+
JSON.stringify({ message: "Event forwarded successfully" }),
|
|
113
|
+
{
|
|
114
|
+
status: 200,
|
|
115
|
+
headers: {
|
|
116
|
+
"Content-Type": "application/json",
|
|
117
|
+
},
|
|
118
|
+
}
|
|
119
|
+
);
|
|
120
|
+
} catch (e) {
|
|
121
|
+
const error = ensureError(e);
|
|
122
|
+
console.error("Error in route handler:", error);
|
|
123
|
+
|
|
124
|
+
// Return an appropriate error response
|
|
125
|
+
return new Response(JSON.stringify({ error: "Internal Server Error" }), {
|
|
126
|
+
status: 500,
|
|
127
|
+
headers: {
|
|
128
|
+
"Content-Type": "application/json",
|
|
129
|
+
},
|
|
130
|
+
});
|
|
37
131
|
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
132
|
+
};
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
export const makeEventTracker =
|
|
136
|
+
({ endpoint }: { endpoint: string }) =>
|
|
137
|
+
async (event: AnalyticsEventOrError) => {
|
|
138
|
+
const eventWithTimeStamp = {
|
|
139
|
+
...event,
|
|
140
|
+
timestamp: new Date(),
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
try {
|
|
144
|
+
const response = await fetch(endpoint, {
|
|
145
|
+
method: "POST",
|
|
146
|
+
keepalive: true,
|
|
147
|
+
body: JSON.stringify(eventWithTimeStamp),
|
|
148
|
+
headers: {
|
|
149
|
+
"Content-Type": "application/json",
|
|
150
|
+
},
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
if (!response.ok) {
|
|
154
|
+
throw new Error(
|
|
155
|
+
`Failed to send analytics event: ${response.statusText}`
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
} catch (e) {
|
|
159
|
+
const error = ensureError(e);
|
|
160
|
+
|
|
161
|
+
console.error("Error sending analytics event:", error.message);
|
|
56
162
|
}
|
|
57
|
-
}
|
|
58
|
-
throw new Error("Failed to make the request");
|
|
59
|
-
}
|
|
60
|
-
}
|
|
163
|
+
};
|
package/src/utils.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// Helper function that ensures that a value is an Error
|
|
2
|
+
export function ensureError(value: unknown): Error {
|
|
3
|
+
if (!value) return new Error("No value was thrown");
|
|
4
|
+
|
|
5
|
+
if (value instanceof Error) return value;
|
|
6
|
+
|
|
7
|
+
// Test if value inherits from Error
|
|
8
|
+
if (value.isPrototypeOf(Error)) return value as Error & typeof value;
|
|
9
|
+
|
|
10
|
+
let stringified = "[Unable to stringify the thrown value]";
|
|
11
|
+
try {
|
|
12
|
+
stringified = JSON.stringify(value);
|
|
13
|
+
} catch {}
|
|
14
|
+
|
|
15
|
+
const error = new Error(
|
|
16
|
+
`This value was thrown as is, not through an Error: ${stringified}`
|
|
17
|
+
);
|
|
18
|
+
return error;
|
|
19
|
+
}
|
package/dist/index.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
type EventPayload = {
|
|
2
|
-
type: "InterviewCompleted" | "InterviewStarted" | "ProtocolInstalled" | "AppSetup";
|
|
3
|
-
metadata?: string;
|
|
4
|
-
timestamp?: string;
|
|
5
|
-
isocode?: string;
|
|
6
|
-
installationid: string;
|
|
7
|
-
};
|
|
8
|
-
type ErrorPayload = {
|
|
9
|
-
code: number;
|
|
10
|
-
message: string;
|
|
11
|
-
details: string;
|
|
12
|
-
stacktrace: string;
|
|
13
|
-
installationid: string;
|
|
14
|
-
timestamp?: string;
|
|
15
|
-
path: string;
|
|
16
|
-
};
|
|
17
|
-
declare function trackEvent(event: EventPayload): Promise<void>;
|
|
18
|
-
declare function trackError(error: ErrorPayload): Promise<void>;
|
|
19
|
-
|
|
20
|
-
export { ErrorPayload, EventPayload, trackError, trackEvent };
|
package/dist/index.js
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/index.ts
|
|
21
|
-
var src_exports = {};
|
|
22
|
-
__export(src_exports, {
|
|
23
|
-
trackError: () => trackError,
|
|
24
|
-
trackEvent: () => trackEvent
|
|
25
|
-
});
|
|
26
|
-
module.exports = __toCommonJS(src_exports);
|
|
27
|
-
async function trackEvent(event) {
|
|
28
|
-
const endpoint = "http://localhost:3000/api/event";
|
|
29
|
-
try {
|
|
30
|
-
const response = await fetch(endpoint, {
|
|
31
|
-
method: "POST",
|
|
32
|
-
headers: {
|
|
33
|
-
"Content-Type": "application/json"
|
|
34
|
-
},
|
|
35
|
-
body: JSON.stringify(event)
|
|
36
|
-
});
|
|
37
|
-
if (!response.ok) {
|
|
38
|
-
throw new Error(`HTTP error! Status: ${response.status}`);
|
|
39
|
-
}
|
|
40
|
-
} catch (error) {
|
|
41
|
-
throw new Error("Failed to make the request");
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
async function trackError(error) {
|
|
45
|
-
const endpoint = "http://localhost:3000/api/error";
|
|
46
|
-
try {
|
|
47
|
-
const response = await fetch(endpoint, {
|
|
48
|
-
method: "POST",
|
|
49
|
-
headers: {
|
|
50
|
-
"Content-Type": "application/json"
|
|
51
|
-
},
|
|
52
|
-
body: JSON.stringify(error)
|
|
53
|
-
});
|
|
54
|
-
if (!response.ok) {
|
|
55
|
-
throw new Error(`HTTP error! Status: ${response.status}`);
|
|
56
|
-
}
|
|
57
|
-
} catch (error2) {
|
|
58
|
-
throw new Error("Failed to make the request");
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
62
|
-
0 && (module.exports = {
|
|
63
|
-
trackError,
|
|
64
|
-
trackEvent
|
|
65
|
-
});
|