@ooneex/analytics 0.0.11 → 0.0.13
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.js +56 -2
- package/dist/index.js.map +2 -2
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -1,4 +1,58 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
|
|
2
|
+
// src/AnalyticsException.ts
|
|
3
|
+
import { Exception } from "@ooneex/exception";
|
|
4
|
+
import { HttpStatus } from "@ooneex/http-status";
|
|
3
5
|
|
|
4
|
-
|
|
6
|
+
class AnalyticsException extends Exception {
|
|
7
|
+
constructor(message, data = {}) {
|
|
8
|
+
super(message, {
|
|
9
|
+
status: HttpStatus.Code.InternalServerError,
|
|
10
|
+
data
|
|
11
|
+
});
|
|
12
|
+
this.name = "AnalyticsException";
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
// src/decorators.ts
|
|
16
|
+
import { container, EContainerScope } from "@ooneex/container";
|
|
17
|
+
var decorator = {
|
|
18
|
+
analytics: (scope = EContainerScope.Singleton) => {
|
|
19
|
+
return (target) => {
|
|
20
|
+
container.add(target, scope);
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
// src/PostHogAnalytics.ts
|
|
25
|
+
import { PostHog } from "posthog-node";
|
|
26
|
+
class PostHogAnalytics {
|
|
27
|
+
client = null;
|
|
28
|
+
constructor(options) {
|
|
29
|
+
const apiKey = options?.apiKey || Bun.env.ANALYTICS_POSTHOG_API_KEY;
|
|
30
|
+
if (!apiKey) {
|
|
31
|
+
throw new AnalyticsException("PostHog API key is required. Please provide an API key either through the constructor options or set the ANALYTICS_POSTHOG_API_KEY environment variable.");
|
|
32
|
+
}
|
|
33
|
+
if (options?.apiKey) {
|
|
34
|
+
this.client = new PostHog(apiKey, {
|
|
35
|
+
host: options.host || Bun.env.ANALYTICS_POSTHOG_HOST || "https://eu.i.posthog.com"
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
capture(options) {
|
|
40
|
+
this.client?.capture({
|
|
41
|
+
distinctId: options.id,
|
|
42
|
+
event: options.event,
|
|
43
|
+
properties: {
|
|
44
|
+
$set: options.properties
|
|
45
|
+
},
|
|
46
|
+
timestamp: new Date,
|
|
47
|
+
...options.groups && { groups: options.groups }
|
|
48
|
+
});
|
|
49
|
+
this.client?.shutdown();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
export {
|
|
53
|
+
decorator,
|
|
54
|
+
PostHogAnalytics,
|
|
55
|
+
AnalyticsException
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
//# debugId=250336E001DF36E364756E2164756E21
|
package/dist/index.js.map
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
"import { container, EContainerScope } from \"@ooneex/container\";\nimport type { AnalyticsClassType } from \"./types\";\n\nexport const decorator = {\n analytics: (scope: EContainerScope = EContainerScope.Singleton) => {\n return (target: AnalyticsClassType): void => {\n container.add(target, scope);\n };\n },\n};\n",
|
|
7
7
|
"import { PostHog } from \"posthog-node\";\nimport { AnalyticsException } from \"./AnalyticsException\";\nimport type { IAnalytics, PostHogCaptureOptionsType } from \"./types\";\n\nexport class PostHogAnalytics<T extends PostHogCaptureOptionsType = PostHogCaptureOptionsType>\n implements IAnalytics<T>\n{\n private client: PostHog | null = null;\n\n constructor(options?: { apiKey?: string; host?: string }) {\n const apiKey = options?.apiKey || Bun.env.ANALYTICS_POSTHOG_API_KEY;\n\n if (!apiKey) {\n throw new AnalyticsException(\n \"PostHog API key is required. Please provide an API key either through the constructor options or set the ANALYTICS_POSTHOG_API_KEY environment variable.\",\n );\n }\n\n if (options?.apiKey) {\n this.client = new PostHog(apiKey, {\n host: options.host || Bun.env.ANALYTICS_POSTHOG_HOST || \"https://eu.i.posthog.com\",\n });\n }\n }\n\n public capture(options: T): void {\n this.client?.capture({\n distinctId: options.id,\n event: options.event,\n properties: {\n $set: options.properties,\n },\n timestamp: new Date(),\n ...(options.groups && { groups: options.groups }),\n });\n this.client?.shutdown();\n }\n}\n"
|
|
8
8
|
],
|
|
9
|
-
"mappings": ";AAAA,
|
|
10
|
-
"debugId": "
|
|
9
|
+
"mappings": ";;AAAA;AACA;AAAA;AAEO,MAAM,2BAA2B,UAAU;AAAA,EAChD,WAAW,CAAC,SAAiB,OAAgC,CAAC,GAAG;AAAA,IAC/D,MAAM,SAAS;AAAA,MACb,QAAQ,WAAW,KAAK;AAAA,MACxB;AAAA,IACF,CAAC;AAAA,IAED,KAAK,OAAO;AAAA;AAEhB;;ACZA;AAGO,IAAM,YAAY;AAAA,EACvB,WAAW,CAAC,QAAyB,gBAAgB,cAAc;AAAA,IACjE,OAAO,CAAC,WAAqC;AAAA,MAC3C,UAAU,IAAI,QAAQ,KAAK;AAAA;AAAA;AAGjC;;ACTA;AAIO,MAAM,iBAEb;AAAA,EACU,SAAyB;AAAA,EAEjC,WAAW,CAAC,SAA8C;AAAA,IACxD,MAAM,SAAS,SAAS,UAAU,IAAI,IAAI;AAAA,IAE1C,IAAI,CAAC,QAAQ;AAAA,MACX,MAAM,IAAI,mBACR,0JACF;AAAA,IACF;AAAA,IAEA,IAAI,SAAS,QAAQ;AAAA,MACnB,KAAK,SAAS,IAAI,QAAQ,QAAQ;AAAA,QAChC,MAAM,QAAQ,QAAQ,IAAI,IAAI,0BAA0B;AAAA,MAC1D,CAAC;AAAA,IACH;AAAA;AAAA,EAGK,OAAO,CAAC,SAAkB;AAAA,IAC/B,KAAK,QAAQ,QAAQ;AAAA,MACnB,YAAY,QAAQ;AAAA,MACpB,OAAO,QAAQ;AAAA,MACf,YAAY;AAAA,QACV,MAAM,QAAQ;AAAA,MAChB;AAAA,MACA,WAAW,IAAI;AAAA,SACX,QAAQ,UAAU,EAAE,QAAQ,QAAQ,OAAO;AAAA,IACjD,CAAC;AAAA,IACD,KAAK,QAAQ,SAAS;AAAA;AAE1B;",
|
|
10
|
+
"debugId": "250336E001DF36E364756E2164756E21",
|
|
11
11
|
"names": []
|
|
12
12
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ooneex/analytics",
|
|
3
3
|
"description": "Analytics and event tracking integration with PostHog for user behavior insights and product analytics",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.13",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
7
7
|
"dist",
|
|
@@ -28,9 +28,9 @@
|
|
|
28
28
|
"npm:publish": "bun publish --tolerate-republish --access public"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@ooneex/container": "0.0.
|
|
32
|
-
"@ooneex/exception": "0.0.
|
|
33
|
-
"@ooneex/http-status": "0.0.
|
|
31
|
+
"@ooneex/container": "0.0.12",
|
|
32
|
+
"@ooneex/exception": "0.0.11",
|
|
33
|
+
"@ooneex/http-status": "0.0.11",
|
|
34
34
|
"posthog-node": "^5.11.0"
|
|
35
35
|
},
|
|
36
36
|
"keywords": [
|