@formo/analytics 1.13.3-alpha.2 → 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.2",
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;
@@ -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(this.toSnakeCase(payload)),
601
+ payload: await this.buildEventPayload(toSnakeCase(payload)),
601
602
  };
602
603
 
603
604
  try {
@@ -837,31 +838,4 @@ export class FormoAnalytics implements IFormoAnalytics {
837
838
  private getActionDescriptor(action: string, payload: any): string {
838
839
  return `${action}${payload.status ? ` ${payload.status}` : ""}`;
839
840
  }
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
- }
867
841
  }
@@ -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
+ }