@formo/analytics 1.13.3-alpha.1 → 1.13.3-alpha.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@formo/analytics",
3
- "version": "1.13.3-alpha.1",
3
+ "version": "1.13.3-alpha.3",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/getformo/sdk.git"
@@ -18,6 +18,7 @@ import {
18
18
  SignatureStatus,
19
19
  TransactionStatus,
20
20
  } from "./types";
21
+ import { toSnakeCase } from "./lib/utils";
21
22
 
22
23
  interface IFormoAnalytics {
23
24
  page(): void;
@@ -135,8 +136,8 @@ export class FormoAnalytics implements IFormoAnalytics {
135
136
  this.currentConnectedAddress = address;
136
137
 
137
138
  await this.trackEvent(Event.CONNECT, {
138
- chain_id: chainId,
139
- address: address,
139
+ chainId,
140
+ address,
140
141
  });
141
142
  }
142
143
 
@@ -188,7 +189,7 @@ export class FormoAnalytics implements IFormoAnalytics {
188
189
  this.currentChainId = chainId;
189
190
 
190
191
  await this.trackEvent(Event.CHAIN_CHANGED, {
191
- chain_id: chainId,
192
+ chainId,
192
193
  address: address || this.currentConnectedAddress,
193
194
  });
194
195
  }
@@ -217,7 +218,7 @@ export class FormoAnalytics implements IFormoAnalytics {
217
218
  }): Promise<void> {
218
219
  await this.trackEvent(Event.SIGNATURE, {
219
220
  status,
220
- chain_id: chainId,
221
+ chainId,
221
222
  address,
222
223
  message,
223
224
  ...(signatureHash && { signatureHash }),
@@ -254,7 +255,7 @@ export class FormoAnalytics implements IFormoAnalytics {
254
255
  }): Promise<void> {
255
256
  await this.trackEvent(Event.TRANSACTION, {
256
257
  status,
257
- chain_id: chainId,
258
+ chainId,
258
259
  address,
259
260
  data,
260
261
  to,
@@ -597,7 +598,7 @@ export class FormoAnalytics implements IFormoAnalytics {
597
598
  timestamp: new Date().toISOString(),
598
599
  action,
599
600
  version: "1",
600
- payload: await this.buildEventPayload(payload),
601
+ payload: await this.buildEventPayload(toSnakeCase(payload)),
601
602
  };
602
603
 
603
604
  try {
@@ -0,0 +1,24 @@
1
+ const toSnake = (str: string) =>
2
+ str
3
+ .replace(/([a-z])([A-Z])/g, "$1_$2")
4
+ .replace(/[\s-]+/g, "_")
5
+ .toLowerCase();
6
+
7
+ // Converts object keys to snake_case, omitting keys in the omitKeys array
8
+ export function toSnakeCase(obj: any, omitKeys: string[] = []) {
9
+ const convert = (data: any): any => {
10
+ if (Array.isArray(obj)) {
11
+ return obj.map(convert);
12
+ } else if (obj !== null && typeof obj === "object") {
13
+ return Object.keys(obj).reduce((acc: any, key) => {
14
+ // If the key is in omitKeys, keep it as it is
15
+ const resultKey = omitKeys.includes(key) ? key : toSnake(key);
16
+ acc[resultKey] = omitKeys.includes(key) ? obj[key] : convert(obj[key]);
17
+ return acc;
18
+ }, {});
19
+ }
20
+ return data;
21
+ };
22
+
23
+ return convert(obj);
24
+ }