@codaco/analytics 0.0.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/.eslintrc.js ADDED
@@ -0,0 +1,4 @@
1
+ module.exports = {
2
+ root: true,
3
+ extends: ["custom/next"],
4
+ };
@@ -0,0 +1,18 @@
1
+
2
+ > @codaco/analytics@0.0.1 build /Users/buckhalt/Code/complexdatacollective/error-analytics-microservice/packages/analytics
3
+ > tsup src/index.ts --format cjs,esm --dts
4
+
5
+ CLI Building entry: src/index.ts
6
+ CLI Using tsconfig: tsconfig.json
7
+ CLI tsup v7.2.0
8
+ CLI Target: es2022
9
+ CJS Build start
10
+ ESM Build start
11
+ ESM dist/index.mjs 958.00 B
12
+ ESM ⚡️ Build success in 33ms
13
+ CJS dist/index.js 1.95 KB
14
+ CJS ⚡️ Build success in 34ms
15
+ DTS Build start
16
+ DTS ⚡️ Build success in 578ms
17
+ DTS dist/index.d.ts 583.00 B
18
+ DTS dist/index.d.mts 583.00 B
@@ -0,0 +1,5 @@
1
+
2
+ > @codaco/analytics@0.0.1 lint /Users/buckhalt/Code/complexdatacollective/error-analytics-microservice/packages/analytics
3
+ > eslint .
4
+
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 ADDED
@@ -0,0 +1,41 @@
1
+ # @codaco/analytics
2
+
3
+ This npm package implements methods and types for sending analytics and errors from Fresco instances to a custom error and analytics microservice.
4
+
5
+ It exports two methods:
6
+
7
+ 1. trackEvent - sends an event payload to the microservice.
8
+
9
+ ```ts
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
+ ```
@@ -0,0 +1,20 @@
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 };
@@ -0,0 +1,20 @@
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 ADDED
@@ -0,0 +1,65 @@
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 = "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 = "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({ errorPayload: 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
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,39 @@
1
+ // src/index.ts
2
+ async function trackEvent(event) {
3
+ const endpoint = "localhost:3000/api/event";
4
+ try {
5
+ const response = await fetch(endpoint, {
6
+ method: "POST",
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");
17
+ }
18
+ }
19
+ async function trackError(error) {
20
+ const endpoint = "localhost:3000/api/error";
21
+ try {
22
+ const response = await fetch(endpoint, {
23
+ method: "POST",
24
+ headers: {
25
+ "Content-Type": "application/json"
26
+ },
27
+ body: JSON.stringify({ errorPayload: error })
28
+ });
29
+ if (!response.ok) {
30
+ throw new Error(`HTTP error! Status: ${response.status}`);
31
+ }
32
+ } catch (error2) {
33
+ throw new Error("Failed to make the request");
34
+ }
35
+ }
36
+ export {
37
+ trackError,
38
+ trackEvent
39
+ };
package/package.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "@codaco/analytics",
3
+ "version": "0.0.1",
4
+ "main": "./dist/index.js",
5
+ "module": "./dist/index.mjs",
6
+ "types": "./dist/index.d.ts",
7
+ "author": "Complex Data Collective <developers@coda.co>",
8
+ "description": "Utilities for tracking analytics and error reporting in Fresco",
9
+ "dependencies": {
10
+ "tsup": "^7.2.0",
11
+ "typescript": "latest"
12
+ },
13
+ "devDependencies": {
14
+ "@types/node": "^20.5.2",
15
+ "@types/react": "^18.2.0",
16
+ "@types/react-dom": "^18.2.0",
17
+ "react": "^18.2.0",
18
+ "typescript": "^5.2.2",
19
+ "tsconfig": "0.0.0",
20
+ "eslint-config-custom": "0.0.0"
21
+ },
22
+ "scripts": {
23
+ "build": "tsup src/index.ts --format cjs,esm --dts",
24
+ "lint": "eslint ."
25
+ }
26
+ }
package/src/index.ts ADDED
@@ -0,0 +1,59 @@
1
+ export type EventPayload = {
2
+ type:
3
+ | "InterviewCompleted"
4
+ | "InterviewStarted"
5
+ | "ProtocolInstalled"
6
+ | "AppSetup";
7
+ metadata?: string;
8
+ timestamp?: string;
9
+ isocode?: string;
10
+ installationid: string;
11
+ };
12
+
13
+ export type ErrorPayload = {
14
+ code: number;
15
+ message: string;
16
+ details: string;
17
+ stacktrace: string;
18
+ installationid: string;
19
+ timestamp?: string;
20
+ path: string;
21
+ };
22
+
23
+ export async function trackEvent(event: EventPayload) {
24
+ const endpoint = "localhost:3000/api/event";
25
+ try {
26
+ const response = await fetch(endpoint, {
27
+ method: "POST",
28
+ headers: {
29
+ "Content-Type": "application/json",
30
+ },
31
+ body: JSON.stringify({ event: event }),
32
+ });
33
+
34
+ if (!response.ok) {
35
+ throw new Error(`HTTP error! Status: ${response.status}`);
36
+ }
37
+ } catch (error) {
38
+ throw new Error("Failed to make the request");
39
+ }
40
+ }
41
+
42
+ export async function trackError(error: ErrorPayload) {
43
+ const endpoint = "localhost:3000/api/error";
44
+ try {
45
+ const response = await fetch(endpoint, {
46
+ method: "POST",
47
+ headers: {
48
+ "Content-Type": "application/json",
49
+ },
50
+ body: JSON.stringify({ errorPayload: error }),
51
+ });
52
+
53
+ if (!response.ok) {
54
+ throw new Error(`HTTP error! Status: ${response.status}`);
55
+ }
56
+ } catch (error) {
57
+ throw new Error("Failed to make the request");
58
+ }
59
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,11 @@
1
+ {
2
+ "extends": "tsconfig/react-library.json",
3
+ "include": [
4
+ "."
5
+ ],
6
+ "exclude": [
7
+ "dist",
8
+ "build",
9
+ "node_modules"
10
+ ]
11
+ }