growlytics-tracking 1.0.0 → 1.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.
@@ -1,7 +1,12 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.Growlytic = void 0;
4
7
  const engagement_1 = require("./engagement");
8
+ const axios_1 = __importDefault(require("axios"));
9
+ const storage_1 = require("./storage");
5
10
  class GrowlyticSDK {
6
11
  clientId;
7
12
  workspaceId;
@@ -12,21 +17,21 @@ class GrowlyticSDK {
12
17
  this.clientId = options.client_id;
13
18
  this.workspaceId = options.workspace_id;
14
19
  this.appId = options.app_id;
15
- const existingAnonymousId = localStorage.getItem("growlytic_anonymous_id");
16
- const existingSessionId = sessionStorage.getItem("growlytic_session_id");
20
+ const existingAnonymousId = storage_1.localStore.getItem("growlytic_anonymous_id");
21
+ const existingSessionId = storage_1.sessionStore.getItem("growlytic_session_id");
17
22
  if (existingAnonymousId) {
18
23
  this.anonymousId = existingAnonymousId;
19
24
  }
20
25
  else {
21
26
  this.anonymousId = crypto.randomUUID();
22
- localStorage.setItem("growlytic_anonymous_id", this.anonymousId);
27
+ storage_1.localStore.setItem("growlytic_anonymous_id", this.anonymousId);
23
28
  }
24
29
  if (existingSessionId) {
25
30
  this.sessionId = existingSessionId;
26
31
  }
27
32
  else {
28
33
  this.sessionId = crypto.randomUUID();
29
- sessionStorage.setItem("growlytic_session_id", this.sessionId);
34
+ storage_1.sessionStore.setItem("growlytic_session_id", this.sessionId);
30
35
  }
31
36
  console.log("[Nexora] Initialized", options);
32
37
  }
@@ -50,6 +55,11 @@ class GrowlyticSDK {
50
55
  custom: payload.custom
51
56
  };
52
57
  console.log(event);
58
+ axios_1.default.post("http://localhost:8050/api/v1/public/initiate", event).then((res) => {
59
+ console.log("Event sent successfully:", res.data);
60
+ }).catch((err) => {
61
+ console.error("Axios error:", err.message);
62
+ });
53
63
  }
54
64
  }
55
65
  exports.Growlytic = new GrowlyticSDK();
@@ -0,0 +1,8 @@
1
+ interface StorageLike {
2
+ getItem(key: string): string | null;
3
+ setItem(key: string, value: string): void;
4
+ removeItem(key: string): void;
5
+ }
6
+ export declare const localStore: StorageLike;
7
+ export declare const sessionStore: StorageLike;
8
+ export {};
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sessionStore = exports.localStore = void 0;
4
+ class MemoryStorage {
5
+ store = {};
6
+ getItem(key) {
7
+ return this.store[key] || null;
8
+ }
9
+ setItem(key, value) {
10
+ this.store[key] = value;
11
+ }
12
+ removeItem(key) {
13
+ delete this.store[key];
14
+ }
15
+ }
16
+ const isBrowser = () => typeof window !== "undefined" &&
17
+ typeof window.localStorage !== "undefined";
18
+ exports.localStore = isBrowser() ? window.localStorage : new MemoryStorage();
19
+ exports.sessionStore = isBrowser() ? window.sessionStorage : new MemoryStorage();
@@ -1,7 +1,12 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.Growlytic = void 0;
4
7
  const engagement_1 = require("./engagement");
8
+ const axios_1 = __importDefault(require("axios"));
9
+ const storage_1 = require("./storage");
5
10
  class GrowlyticSDK {
6
11
  clientId;
7
12
  workspaceId;
@@ -12,21 +17,21 @@ class GrowlyticSDK {
12
17
  this.clientId = options.client_id;
13
18
  this.workspaceId = options.workspace_id;
14
19
  this.appId = options.app_id;
15
- const existingAnonymousId = localStorage.getItem("growlytic_anonymous_id");
16
- const existingSessionId = sessionStorage.getItem("growlytic_session_id");
20
+ const existingAnonymousId = storage_1.localStore.getItem("growlytic_anonymous_id");
21
+ const existingSessionId = storage_1.sessionStore.getItem("growlytic_session_id");
17
22
  if (existingAnonymousId) {
18
23
  this.anonymousId = existingAnonymousId;
19
24
  }
20
25
  else {
21
26
  this.anonymousId = crypto.randomUUID();
22
- localStorage.setItem("growlytic_anonymous_id", this.anonymousId);
27
+ storage_1.localStore.setItem("growlytic_anonymous_id", this.anonymousId);
23
28
  }
24
29
  if (existingSessionId) {
25
30
  this.sessionId = existingSessionId;
26
31
  }
27
32
  else {
28
33
  this.sessionId = crypto.randomUUID();
29
- sessionStorage.setItem("growlytic_session_id", this.sessionId);
34
+ storage_1.sessionStore.setItem("growlytic_session_id", this.sessionId);
30
35
  }
31
36
  console.log("[Nexora] Initialized", options);
32
37
  }
@@ -50,6 +55,11 @@ class GrowlyticSDK {
50
55
  custom: payload.custom
51
56
  };
52
57
  console.log(event);
58
+ axios_1.default.post("http://localhost:8050/api/v1/public/initiate", event).then((res) => {
59
+ console.log("Event sent successfully:", res.data);
60
+ }).catch((err) => {
61
+ console.error("Axios error:", err.message);
62
+ });
53
63
  }
54
64
  }
55
65
  exports.Growlytic = new GrowlyticSDK();
@@ -0,0 +1,8 @@
1
+ interface StorageLike {
2
+ getItem(key: string): string | null;
3
+ setItem(key: string, value: string): void;
4
+ removeItem(key: string): void;
5
+ }
6
+ export declare const localStore: StorageLike;
7
+ export declare const sessionStore: StorageLike;
8
+ export {};
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sessionStore = exports.localStore = void 0;
4
+ class MemoryStorage {
5
+ store = {};
6
+ getItem(key) {
7
+ return this.store[key] || null;
8
+ }
9
+ setItem(key, value) {
10
+ this.store[key] = value;
11
+ }
12
+ removeItem(key) {
13
+ delete this.store[key];
14
+ }
15
+ }
16
+ const isBrowser = () => typeof window !== "undefined" &&
17
+ typeof window.localStorage !== "undefined";
18
+ exports.localStore = isBrowser() ? window.localStorage : new MemoryStorage();
19
+ exports.sessionStore = isBrowser() ? window.sessionStorage : new MemoryStorage();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "growlytics-tracking",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Enterprise-grade Node.js SDK for Growlytics tracking service with high performance batching, queueing, retries, and offline resilience.",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "module": "./dist/esm/index.js",
@@ -51,6 +51,7 @@
51
51
  "example": "examples"
52
52
  },
53
53
  "dependencies": {
54
+ "axios": "^1.17.0",
54
55
  "undici-types": "^7.24.6"
55
56
  }
56
57
  }