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

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.2",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/getformo/sdk.git"
@@ -135,8 +135,8 @@ export class FormoAnalytics implements IFormoAnalytics {
135
135
  this.currentConnectedAddress = address;
136
136
 
137
137
  await this.trackEvent(Event.CONNECT, {
138
- chain_id: chainId,
139
- address: address,
138
+ chainId,
139
+ address,
140
140
  });
141
141
  }
142
142
 
@@ -188,7 +188,7 @@ export class FormoAnalytics implements IFormoAnalytics {
188
188
  this.currentChainId = chainId;
189
189
 
190
190
  await this.trackEvent(Event.CHAIN_CHANGED, {
191
- chain_id: chainId,
191
+ chainId,
192
192
  address: address || this.currentConnectedAddress,
193
193
  });
194
194
  }
@@ -217,7 +217,7 @@ export class FormoAnalytics implements IFormoAnalytics {
217
217
  }): Promise<void> {
218
218
  await this.trackEvent(Event.SIGNATURE, {
219
219
  status,
220
- chain_id: chainId,
220
+ chainId,
221
221
  address,
222
222
  message,
223
223
  ...(signatureHash && { signatureHash }),
@@ -254,7 +254,7 @@ export class FormoAnalytics implements IFormoAnalytics {
254
254
  }): Promise<void> {
255
255
  await this.trackEvent(Event.TRANSACTION, {
256
256
  status,
257
- chain_id: chainId,
257
+ chainId,
258
258
  address,
259
259
  data,
260
260
  to,
@@ -597,7 +597,7 @@ export class FormoAnalytics implements IFormoAnalytics {
597
597
  timestamp: new Date().toISOString(),
598
598
  action,
599
599
  version: "1",
600
- payload: await this.buildEventPayload(payload),
600
+ payload: await this.buildEventPayload(this.toSnakeCase(payload)),
601
601
  };
602
602
 
603
603
  try {
@@ -837,4 +837,31 @@ export class FormoAnalytics implements IFormoAnalytics {
837
837
  private getActionDescriptor(action: string, payload: any): string {
838
838
  return `${action}${payload.status ? ` ${payload.status}` : ""}`;
839
839
  }
840
+
841
+ // Converts object keys to snake_case, omitting keys in the omitKeys array
842
+ private toSnakeCase(obj: any, omitKeys: string[] = []) {
843
+ const toSnake = (str: string) =>
844
+ str
845
+ .replace(/([a-z])([A-Z])/g, "$1_$2")
846
+ .replace(/[\s-]+/g, "_")
847
+ .toLowerCase();
848
+
849
+ const convert = (data: any): any => {
850
+ if (Array.isArray(data)) {
851
+ return data.map(convert);
852
+ } else if (data !== null && typeof data === "object") {
853
+ return Object.keys(data).reduce((acc: any, key) => {
854
+ // If the key is in omitKeys, keep it as it is
855
+ const resultKey = omitKeys.includes(key) ? key : toSnake(key);
856
+ acc[resultKey] = omitKeys.includes(key)
857
+ ? data[key]
858
+ : convert(data[key]);
859
+ return acc;
860
+ }, {});
861
+ }
862
+ return data;
863
+ };
864
+
865
+ return convert(obj);
866
+ }
840
867
  }