@ooneex/analytics 1.0.1 → 1.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.ts +3 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +3 -3
- package/package.json +5 -4
package/dist/index.d.ts
CHANGED
|
@@ -20,9 +20,11 @@ type PostHogCaptureOptionsType = {
|
|
|
20
20
|
declare const decorator: {
|
|
21
21
|
analytics: (scope?: EContainerScope) => (target: AnalyticsClassType) => void;
|
|
22
22
|
};
|
|
23
|
+
import { AppEnv } from "@ooneex/app-env";
|
|
23
24
|
declare class PostHogAnalytics<T extends PostHogCaptureOptionsType = PostHogCaptureOptionsType> implements IAnalytics<T> {
|
|
25
|
+
private readonly env;
|
|
24
26
|
private client;
|
|
25
|
-
constructor(config?: PostHogConfigType);
|
|
27
|
+
constructor(env: AppEnv, config?: PostHogConfigType);
|
|
26
28
|
capture(options: T): void;
|
|
27
29
|
}
|
|
28
30
|
export { decorator, PostHogConfigType, PostHogCaptureOptionsType, PostHogAnalytics, IAnalytics, AnalyticsException, AnalyticsClassType };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
var l=function(t,e,
|
|
2
|
+
var l=function(t,e,o,i){var n=arguments.length,r=n<3?e:i===null?i=Object.getOwnPropertyDescriptor(e,o):i,p;if(typeof Reflect==="object"&&typeof Reflect.decorate==="function")r=Reflect.decorate(t,e,o,i);else for(var c=t.length-1;c>=0;c--)if(p=t[c])r=(n<3?p(r):n>3?p(e,o,r):p(e,o))||r;return n>3&&r&&Object.defineProperty(e,o,r),r},y=(t,e)=>(o,i)=>e(o,i,t),u=(t,e)=>{if(typeof Reflect==="object"&&typeof Reflect.metadata==="function")return Reflect.metadata(t,e)};import{Exception as h}from"@ooneex/exception";import{HttpStatus as T}from"@ooneex/http-status";class s extends h{constructor(t,e={}){super(t,{status:T.Code.InternalServerError,data:e});this.name="AnalyticsException"}}import{container as f,EContainerScope as A}from"@ooneex/container";var m={analytics:(t=A.Singleton)=>{return(e)=>{f.add(e,t)}}};import{AppEnv as d}from"@ooneex/app-env";import{inject as g}from"@ooneex/container";import{PostHog as P}from"posthog-node";class a{env;client=null;constructor(t,e){this.env=t;let o=e?.apiKey||this.env.ANALYTICS_POSTHOG_API_KEY?.trim();if(!o)throw new s("PostHog API key is required. Please provide an API key either through the constructor options or set the ANALYTICS_POSTHOG_API_KEY environment variable.");this.client=new P(o,{host:e?.host||this.env.ANALYTICS_POSTHOG_HOST?.trim()||"https://eu.i.posthog.com"})}capture(t){this.client?.capture({distinctId:t.id,event:t.event,properties:{$set:t.properties},timestamp:new Date,...t.groups&&{groups:t.groups}}),this.client?.shutdown()}}a=l([m.analytics(),y(0,g(d)),u("design:paramtypes",[typeof d==="undefined"?Object:d,typeof PostHogConfigType==="undefined"?Object:PostHogConfigType])],a);export{m as decorator,a as PostHogAnalytics,s as AnalyticsException};
|
|
3
3
|
|
|
4
|
-
//# debugId=
|
|
4
|
+
//# debugId=96498CEA1F1FCC2864756E2164756E21
|
package/dist/index.js.map
CHANGED
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
"sourcesContent": [
|
|
5
5
|
"import { Exception } from \"@ooneex/exception\";\nimport { HttpStatus } from \"@ooneex/http-status\";\n\nexport class AnalyticsException extends Exception {\n constructor(message: string, data: Record<string, unknown> = {}) {\n super(message, {\n status: HttpStatus.Code.InternalServerError,\n data,\n });\n\n this.name = \"AnalyticsException\";\n }\n}\n",
|
|
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
|
-
"import { PostHog } from \"posthog-node\";\nimport { AnalyticsException } from \"./AnalyticsException\";\nimport { decorator } from \"./decorators\";\nimport type { IAnalytics, PostHogCaptureOptionsType, PostHogConfigType } from \"./types\";\n\n@decorator.analytics()\nexport class PostHogAnalytics<T extends PostHogCaptureOptionsType = PostHogCaptureOptionsType>\n implements IAnalytics<T>\n{\n private client: PostHog | null = null;\n\n constructor(config?: PostHogConfigType) {\n const apiKey = config?.apiKey ||
|
|
7
|
+
"import { AppEnv } from \"@ooneex/app-env\";\nimport { inject } from \"@ooneex/container\";\nimport { PostHog } from \"posthog-node\";\nimport { AnalyticsException } from \"./AnalyticsException\";\nimport { decorator } from \"./decorators\";\nimport type { IAnalytics, PostHogCaptureOptionsType, PostHogConfigType } from \"./types\";\n\n@decorator.analytics()\nexport class PostHogAnalytics<T extends PostHogCaptureOptionsType = PostHogCaptureOptionsType>\n implements IAnalytics<T>\n{\n private client: PostHog | null = null;\n\n constructor(\n @inject(AppEnv) private readonly env: AppEnv,\n config?: PostHogConfigType,\n ) {\n const apiKey = config?.apiKey || this.env.ANALYTICS_POSTHOG_API_KEY?.trim();\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 this.client = new PostHog(apiKey, {\n host: config?.host || this.env.ANALYTICS_POSTHOG_HOST?.trim() || \"https://eu.i.posthog.com\",\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": ";
|
|
10
|
-
"debugId": "
|
|
9
|
+
"mappings": ";8cAAA,oBAAS,0BACT,qBAAS,4BAEF,MAAM,UAA2B,CAAU,CAChD,WAAW,CAAC,EAAiB,EAAgC,CAAC,EAAG,CAC/D,MAAM,EAAS,CACb,OAAQ,EAAW,KAAK,oBACxB,MACF,CAAC,EAED,KAAK,KAAO,qBAEhB,CCZA,oBAAS,qBAAW,0BAGb,IAAM,EAAY,CACvB,UAAW,CAAC,EAAyB,EAAgB,YAAc,CACjE,MAAO,CAAC,IAAqC,CAC3C,EAAU,IAAI,EAAQ,CAAK,GAGjC,ECTA,iBAAS,wBACT,iBAAS,0BACT,kBAAS,qBAMF,MAAM,CAEb,CAIqC,IAH3B,OAAyB,KAEjC,WAAW,CACwB,EACjC,EACA,CAFiC,WAGjC,IAAM,EAAS,GAAQ,QAAU,KAAK,IAAI,2BAA2B,KAAK,EAE1E,GAAI,CAAC,EACH,MAAM,IAAI,EACR,0JACF,EAGF,KAAK,OAAS,IAAI,EAAQ,EAAQ,CAChC,KAAM,GAAQ,MAAQ,KAAK,IAAI,wBAAwB,KAAK,GAAK,0BACnE,CAAC,EAGI,OAAO,CAAC,EAAkB,CAC/B,KAAK,QAAQ,QAAQ,CACnB,WAAY,EAAQ,GACpB,MAAO,EAAQ,MACf,WAAY,CACV,KAAM,EAAQ,UAChB,EACA,UAAW,IAAI,QACX,EAAQ,QAAU,CAAE,OAAQ,EAAQ,MAAO,CACjD,CAAC,EACD,KAAK,QAAQ,SAAS,EAE1B,CAlCa,EAAN,GADN,EAAU,UAAU,EAOhB,MAAO,CAAM,GANX,0HAAM",
|
|
10
|
+
"debugId": "96498CEA1F1FCC2864756E2164756E21",
|
|
11
11
|
"names": []
|
|
12
12
|
}
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ooneex/analytics",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"module": "./dist/index.js",
|
|
5
5
|
"dependencies": {
|
|
6
|
-
"@ooneex/
|
|
7
|
-
"@ooneex/
|
|
8
|
-
"@ooneex/
|
|
6
|
+
"@ooneex/app-env": "1.1.0",
|
|
7
|
+
"@ooneex/container": "1.1.0",
|
|
8
|
+
"@ooneex/exception": "1.1.0",
|
|
9
|
+
"@ooneex/http-status": "1.1.0",
|
|
9
10
|
"posthog-node": "^5.11.0"
|
|
10
11
|
},
|
|
11
12
|
"exports": {
|