@formo/analytics 1.16.19 → 1.17.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/cjs/src/FormoAnalytics.d.ts.map +1 -1
- package/dist/cjs/src/FormoAnalytics.js +1 -0
- package/dist/cjs/src/FormoAnalytics.js.map +1 -1
- package/dist/cjs/src/FormoAnalyticsProvider.d.ts +1 -1
- package/dist/cjs/src/FormoAnalyticsProvider.d.ts.map +1 -1
- package/dist/cjs/src/constants/config.d.ts.map +1 -1
- package/dist/cjs/src/lib/event/utils.d.ts.map +1 -1
- package/dist/cjs/src/lib/ramda/internal/_curry1.d.ts.map +1 -1
- package/dist/cjs/src/lib/ramda/internal/_curry2.d.ts.map +1 -1
- package/dist/cjs/src/lib/ramda/internal/_curry3.d.ts.map +1 -1
- package/dist/cjs/src/lib/version.d.ts +1 -1
- package/dist/cjs/src/lib/version.js +1 -1
- package/dist/cjs/src/utils/address.d.ts.map +1 -1
- package/dist/cjs/src/utils/base.d.ts.map +1 -1
- package/dist/cjs/src/utils/converter.d.ts.map +1 -1
- package/dist/cjs/src/utils/timestamp.d.ts.map +1 -1
- package/dist/cjs/src/validators/address.d.ts.map +1 -1
- package/dist/cjs/src/validators/checks.d.ts.map +1 -1
- package/dist/cjs/src/validators/object.d.ts.map +1 -1
- package/dist/cjs/src/validators/string.d.ts.map +1 -1
- package/dist/cjs/tsconfig.tsbuildinfo +1 -1
- package/dist/esm/src/FormoAnalytics.d.ts.map +1 -1
- package/dist/esm/src/FormoAnalytics.js +2 -1
- package/dist/esm/src/FormoAnalytics.js.map +1 -1
- package/dist/esm/src/FormoAnalyticsProvider.d.ts +1 -1
- package/dist/esm/src/FormoAnalyticsProvider.d.ts.map +1 -1
- package/dist/esm/src/constants/config.d.ts.map +1 -1
- package/dist/esm/src/lib/event/utils.d.ts.map +1 -1
- package/dist/esm/src/lib/ramda/internal/_curry1.d.ts.map +1 -1
- package/dist/esm/src/lib/ramda/internal/_curry2.d.ts.map +1 -1
- package/dist/esm/src/lib/ramda/internal/_curry3.d.ts.map +1 -1
- package/dist/esm/src/lib/version.d.ts +1 -1
- package/dist/esm/src/lib/version.js +1 -1
- package/dist/esm/src/utils/address.d.ts.map +1 -1
- package/dist/esm/src/utils/base.d.ts.map +1 -1
- package/dist/esm/src/utils/converter.d.ts.map +1 -1
- package/dist/esm/src/utils/timestamp.d.ts.map +1 -1
- package/dist/esm/src/validators/address.d.ts.map +1 -1
- package/dist/esm/src/validators/checks.d.ts.map +1 -1
- package/dist/esm/src/validators/object.d.ts.map +1 -1
- package/dist/esm/src/validators/string.d.ts.map +1 -1
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/dist/index.umd.min.js +1 -1
- package/dist/index.umd.min.js.map +1 -1
- package/package.json +48 -41
- package/.env.example +0 -1
- package/.github/workflows/ci.yml +0 -51
- package/CONTRIBUTING.md +0 -93
- package/src/FormoAnalytics.ts +0 -1021
- package/src/FormoAnalyticsProvider.tsx +0 -84
- package/src/constants/base.ts +0 -6
- package/src/constants/config.ts +0 -660
- package/src/constants/events.ts +0 -21
- package/src/constants/index.ts +0 -3
- package/src/global.d.ts +0 -12
- package/src/index.ts +0 -3
- package/src/lib/event/EventFactory.ts +0 -519
- package/src/lib/event/EventManager.ts +0 -39
- package/src/lib/event/constants.ts +0 -4
- package/src/lib/event/index.ts +0 -3
- package/src/lib/event/type.ts +0 -9
- package/src/lib/event/utils.ts +0 -33
- package/src/lib/fetch.ts +0 -3
- package/src/lib/index.ts +0 -5
- package/src/lib/logger/Logger.ts +0 -115
- package/src/lib/logger/index.ts +0 -2
- package/src/lib/logger/type.ts +0 -14
- package/src/lib/queue/EventQueue.ts +0 -306
- package/src/lib/queue/index.ts +0 -2
- package/src/lib/queue/type.ts +0 -6
- package/src/lib/ramda/internal/_curry1.ts +0 -19
- package/src/lib/ramda/internal/_curry2.ts +0 -37
- package/src/lib/ramda/internal/_curry3.ts +0 -68
- package/src/lib/ramda/internal/_has.ts +0 -3
- package/src/lib/ramda/internal/_isObject.ts +0 -3
- package/src/lib/ramda/internal/_isPlaceholder.ts +0 -5
- package/src/lib/ramda/mergeDeepRight.ts +0 -13
- package/src/lib/ramda/mergeDeepWithKey.ts +0 -22
- package/src/lib/ramda/mergeWithKey.ts +0 -28
- package/src/lib/storage/StorageManager.ts +0 -51
- package/src/lib/storage/built-in/blueprint.ts +0 -17
- package/src/lib/storage/built-in/cookie.ts +0 -60
- package/src/lib/storage/built-in/memory.ts +0 -23
- package/src/lib/storage/built-in/web.ts +0 -57
- package/src/lib/storage/constant.ts +0 -2
- package/src/lib/storage/index.ts +0 -25
- package/src/lib/storage/type.ts +0 -21
- package/src/lib/version.ts +0 -2
- package/src/types/base.ts +0 -120
- package/src/types/events.ts +0 -126
- package/src/types/index.ts +0 -3
- package/src/types/provider.ts +0 -17
- package/src/utils/address.ts +0 -43
- package/src/utils/base.ts +0 -3
- package/src/utils/converter.ts +0 -44
- package/src/utils/generate.ts +0 -16
- package/src/utils/index.ts +0 -4
- package/src/utils/timestamp.ts +0 -9
- package/src/validators/address.ts +0 -69
- package/src/validators/agent.ts +0 -4
- package/src/validators/checks.ts +0 -160
- package/src/validators/index.ts +0 -7
- package/src/validators/network.ts +0 -34
- package/src/validators/object.ts +0 -4
- package/src/validators/string.ts +0 -4
- package/src/validators/uint8array.ts +0 -17
- package/test/lib/events.spec.ts +0 -12
- package/test/utils/address.spec.ts +0 -14
- package/test/utils/converter.spec.ts +0 -31
- package/test/validators/address.spec.ts +0 -15
- package/tsconfig.json +0 -28
- package/webpack.config.ts +0 -23
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { logger } from "../logger";
|
|
2
|
-
import CookieStorage from "./built-in/cookie";
|
|
3
|
-
import MemoryStorage from "./built-in/memory";
|
|
4
|
-
import WebStorage from "./built-in/web";
|
|
5
|
-
import { IStorage, StorageType } from "./type";
|
|
6
|
-
|
|
7
|
-
// Fallback as follows: cookieStorage, localStorage, sessionStorage, memoryStorage
|
|
8
|
-
const TYPES: StorageType[] = [
|
|
9
|
-
"cookieStorage",
|
|
10
|
-
"localStorage",
|
|
11
|
-
"sessionStorage",
|
|
12
|
-
"memoryStorage",
|
|
13
|
-
];
|
|
14
|
-
|
|
15
|
-
export class StorageManager {
|
|
16
|
-
private storages: Map<StorageType, IStorage> = new Map();
|
|
17
|
-
|
|
18
|
-
constructor(private readonly writeKey: string) {}
|
|
19
|
-
|
|
20
|
-
getStorage(type: StorageType): IStorage {
|
|
21
|
-
if (!this.storages.has(type)) {
|
|
22
|
-
let storage = this.createStorage(type);
|
|
23
|
-
// If storage is not available, try next
|
|
24
|
-
while (!storage.isAvailable()) {
|
|
25
|
-
const index = TYPES.indexOf(type);
|
|
26
|
-
logger.warn(
|
|
27
|
-
`Storage ${type} is not available, trying ${TYPES[index + 1]}`
|
|
28
|
-
);
|
|
29
|
-
storage = this.createStorage(TYPES[index + 1]);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// Add to cache
|
|
33
|
-
this.storages.set(type, storage);
|
|
34
|
-
}
|
|
35
|
-
return this.storages.get(type)!;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
private createStorage(type: StorageType): IStorage {
|
|
39
|
-
switch (type) {
|
|
40
|
-
case "cookieStorage":
|
|
41
|
-
return new CookieStorage(this.writeKey);
|
|
42
|
-
case "localStorage":
|
|
43
|
-
return new WebStorage(this.writeKey, localStorage);
|
|
44
|
-
case "sessionStorage":
|
|
45
|
-
return new WebStorage(this.writeKey, sessionStorage);
|
|
46
|
-
case "memoryStorage":
|
|
47
|
-
default:
|
|
48
|
-
return new MemoryStorage(this.writeKey);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { KEY_PREFIX } from "../constant";
|
|
2
|
-
import { CookieOptions, IStorage } from "../type";
|
|
3
|
-
|
|
4
|
-
abstract class StorageBlueprint implements IStorage {
|
|
5
|
-
constructor(private readonly writeKey: string) {}
|
|
6
|
-
|
|
7
|
-
abstract isAvailable(): boolean;
|
|
8
|
-
abstract set(key: string, value: string, options?: CookieOptions): void;
|
|
9
|
-
abstract get(key: string): any;
|
|
10
|
-
abstract remove(key: string): void;
|
|
11
|
-
|
|
12
|
-
protected getKey(key: string): string {
|
|
13
|
-
return `${KEY_PREFIX}_${this.writeKey}.${key}`;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export default StorageBlueprint;
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import StorageBlueprint from "./blueprint";
|
|
2
|
-
import { CookieOptions } from "../type";
|
|
3
|
-
|
|
4
|
-
class CookieStorage extends StorageBlueprint {
|
|
5
|
-
public override isAvailable(): boolean {
|
|
6
|
-
return (
|
|
7
|
-
typeof document !== "undefined" && typeof document.cookie === "string"
|
|
8
|
-
);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
public override set(
|
|
12
|
-
key: string,
|
|
13
|
-
value: string,
|
|
14
|
-
options?: CookieOptions
|
|
15
|
-
): void {
|
|
16
|
-
const expires = options?.expires;
|
|
17
|
-
const maxAge = options?.maxAge;
|
|
18
|
-
const path = options?.path || "/";
|
|
19
|
-
const domain = options?.domain;
|
|
20
|
-
const sameSite = options?.sameSite;
|
|
21
|
-
const secure = options?.secure || false;
|
|
22
|
-
|
|
23
|
-
let cookie = `${encodeURIComponent(this.getKey(key))}=${encodeURIComponent(
|
|
24
|
-
value
|
|
25
|
-
)}`;
|
|
26
|
-
if (maxAge) {
|
|
27
|
-
cookie += "; max-age=" + maxAge;
|
|
28
|
-
} else if (expires) {
|
|
29
|
-
cookie += "; expires=" + expires;
|
|
30
|
-
}
|
|
31
|
-
if (path) {
|
|
32
|
-
cookie += "; path=" + path;
|
|
33
|
-
}
|
|
34
|
-
if (domain) {
|
|
35
|
-
cookie += "; domain=" + domain;
|
|
36
|
-
}
|
|
37
|
-
if (sameSite) {
|
|
38
|
-
cookie += "; samesite=" + sameSite;
|
|
39
|
-
}
|
|
40
|
-
if (secure) {
|
|
41
|
-
cookie += "; secure";
|
|
42
|
-
}
|
|
43
|
-
document.cookie = cookie;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
public override get(key: string): string | null {
|
|
47
|
-
const match = document.cookie.match(
|
|
48
|
-
new RegExp(`(?:^|; )${encodeURIComponent(this.getKey(key))}=([^;]*)`)
|
|
49
|
-
);
|
|
50
|
-
return match ? decodeURIComponent(match[1]) : null;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
public override remove(key: string): void {
|
|
54
|
-
document.cookie = `${encodeURIComponent(
|
|
55
|
-
this.getKey(key)
|
|
56
|
-
)}=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT`;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export default CookieStorage;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import StorageBlueprint from "./blueprint";
|
|
2
|
-
|
|
3
|
-
class MemoryStorage extends StorageBlueprint {
|
|
4
|
-
private memoryStorage: Record<string, string> = {};
|
|
5
|
-
|
|
6
|
-
public override isAvailable(): boolean {
|
|
7
|
-
return true;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
public override set(key: string, value: string): void {
|
|
11
|
-
this.memoryStorage[this.getKey(key)] = value;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
public override get(key: string): string | null {
|
|
15
|
-
return this.memoryStorage[this.getKey(key)] || null;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
public override remove(key: string): void {
|
|
19
|
-
delete this.memoryStorage[this.getKey(key)];
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export default MemoryStorage;
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { logger } from "../../logger";
|
|
2
|
-
import { JSON_PREFIX } from "../constant";
|
|
3
|
-
import StorageBlueprint from "./blueprint";
|
|
4
|
-
|
|
5
|
-
class WebStorage extends StorageBlueprint {
|
|
6
|
-
constructor(writeKey: string, private readonly backend: Storage) {
|
|
7
|
-
super(writeKey);
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
public override isAvailable(): boolean {
|
|
11
|
-
try {
|
|
12
|
-
const testKey = "__storage_test__";
|
|
13
|
-
this.backend.setItem(testKey, "1");
|
|
14
|
-
this.backend.removeItem(testKey);
|
|
15
|
-
return true;
|
|
16
|
-
} catch {
|
|
17
|
-
return false;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
public override set(key: string, value: any): void {
|
|
22
|
-
if (typeof value === "boolean") value = value === true ? "true" : "false";
|
|
23
|
-
if (typeof value === "object") value = JSON_PREFIX + JSON.stringify(value);
|
|
24
|
-
this.backend.setItem(this.getKey(key), value);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
public override get(key: string): string | boolean | Record<any, any> | null {
|
|
28
|
-
const value = this.backend.getItem(this.getKey(key));
|
|
29
|
-
|
|
30
|
-
if (!value || typeof value !== "string") return null;
|
|
31
|
-
if (["null", "undefined"].some((item) => item == value)) return null;
|
|
32
|
-
|
|
33
|
-
if (value.startsWith(JSON_PREFIX)) {
|
|
34
|
-
try {
|
|
35
|
-
return JSON.parse(value.slice(JSON_PREFIX.length));
|
|
36
|
-
} catch (error) {
|
|
37
|
-
logger.error(
|
|
38
|
-
`[FORMO_ERROR] ${this.backend.constructor.name} failed to parse JSON`,
|
|
39
|
-
error
|
|
40
|
-
);
|
|
41
|
-
return null;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
if (["true", "false"].some((item) => item == value)) {
|
|
46
|
-
return JSON.parse(value);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return value;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
public override remove(key: string): void {
|
|
53
|
-
this.backend.removeItem(this.getKey(key));
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export default WebStorage;
|
package/src/lib/storage/index.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { IStorage, StorageType } from "./type";
|
|
2
|
-
import { StorageManager } from "./StorageManager";
|
|
3
|
-
export * from "./type";
|
|
4
|
-
|
|
5
|
-
let globalManager: StorageManager | null = null;
|
|
6
|
-
|
|
7
|
-
export function initStorageManager(writeKey: string): void {
|
|
8
|
-
if (!globalManager) {
|
|
9
|
-
globalManager = new StorageManager(writeKey);
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function getStorageInstance(type: StorageType): IStorage {
|
|
14
|
-
if (!globalManager) {
|
|
15
|
-
throw new Error(
|
|
16
|
-
"StorageManager not initialized. Call initStorageManager(writeKey) first."
|
|
17
|
-
);
|
|
18
|
-
}
|
|
19
|
-
return globalManager.getStorage(type);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export const cookie = () => getStorageInstance("cookieStorage");
|
|
23
|
-
export const local = () => getStorageInstance("localStorage");
|
|
24
|
-
export const session = () => getStorageInstance("sessionStorage");
|
|
25
|
-
export const memory = () => getStorageInstance("memoryStorage");
|
package/src/lib/storage/type.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
export type StorageType =
|
|
2
|
-
| "cookieStorage"
|
|
3
|
-
| "localStorage"
|
|
4
|
-
| "sessionStorage"
|
|
5
|
-
| "memoryStorage";
|
|
6
|
-
|
|
7
|
-
export type CookieOptions = {
|
|
8
|
-
maxAge?: number;
|
|
9
|
-
expires?: string;
|
|
10
|
-
path?: string;
|
|
11
|
-
domain?: string;
|
|
12
|
-
secure?: boolean;
|
|
13
|
-
sameSite?: "lax" | "strict" | "none";
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export interface IStorage {
|
|
17
|
-
isAvailable(): boolean;
|
|
18
|
-
set(key: string, value: string, options?: CookieOptions): void;
|
|
19
|
-
get(key: string): any;
|
|
20
|
-
remove(key: string): void;
|
|
21
|
-
}
|
package/src/lib/version.ts
DELETED
package/src/types/base.ts
DELETED
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import { LogLevel } from "../lib";
|
|
2
|
-
import {
|
|
3
|
-
IFormoEventContext,
|
|
4
|
-
IFormoEventProperties,
|
|
5
|
-
SignatureStatus,
|
|
6
|
-
TransactionStatus,
|
|
7
|
-
} from "./events";
|
|
8
|
-
import { EIP1193Provider } from "./provider";
|
|
9
|
-
|
|
10
|
-
export type Nullable<T> = T | null;
|
|
11
|
-
// Decimal chain ID
|
|
12
|
-
export type ChainID = number;
|
|
13
|
-
|
|
14
|
-
// Address (EVM, Solana, etc.)
|
|
15
|
-
export type Address = string;
|
|
16
|
-
|
|
17
|
-
export type ValidInputTypes = Uint8Array | bigint | string | number | boolean;
|
|
18
|
-
export interface IFormoAnalytics {
|
|
19
|
-
page(
|
|
20
|
-
category?: string,
|
|
21
|
-
name?: string,
|
|
22
|
-
properties?: IFormoEventProperties,
|
|
23
|
-
context?: IFormoEventContext,
|
|
24
|
-
callback?: (...args: unknown[]) => void
|
|
25
|
-
): void;
|
|
26
|
-
reset(): void;
|
|
27
|
-
detect(
|
|
28
|
-
params: { rdns: string; providerName: string },
|
|
29
|
-
properties?: IFormoEventProperties,
|
|
30
|
-
context?: IFormoEventContext,
|
|
31
|
-
callback?: (...args: unknown[]) => void
|
|
32
|
-
): Promise<void>;
|
|
33
|
-
connect(
|
|
34
|
-
params: { chainId: ChainID; address: Address },
|
|
35
|
-
properties?: IFormoEventProperties,
|
|
36
|
-
context?: IFormoEventContext,
|
|
37
|
-
callback?: (...args: unknown[]) => void
|
|
38
|
-
): Promise<void>;
|
|
39
|
-
disconnect(
|
|
40
|
-
params?: { chainId?: ChainID; address?: Address },
|
|
41
|
-
properties?: IFormoEventProperties,
|
|
42
|
-
context?: IFormoEventContext,
|
|
43
|
-
callback?: (...args: unknown[]) => void
|
|
44
|
-
): Promise<void>;
|
|
45
|
-
chain(
|
|
46
|
-
params: { chainId: ChainID; address?: Address },
|
|
47
|
-
properties?: IFormoEventProperties,
|
|
48
|
-
context?: IFormoEventContext,
|
|
49
|
-
callback?: (...args: unknown[]) => void
|
|
50
|
-
): Promise<void>;
|
|
51
|
-
signature(
|
|
52
|
-
params: {
|
|
53
|
-
status: SignatureStatus;
|
|
54
|
-
chainId?: ChainID;
|
|
55
|
-
address: Address;
|
|
56
|
-
message: string;
|
|
57
|
-
signatureHash?: string;
|
|
58
|
-
},
|
|
59
|
-
properties?: IFormoEventProperties,
|
|
60
|
-
context?: IFormoEventContext,
|
|
61
|
-
callback?: (...args: unknown[]) => void
|
|
62
|
-
): Promise<void>;
|
|
63
|
-
transaction(
|
|
64
|
-
params: {
|
|
65
|
-
status: TransactionStatus;
|
|
66
|
-
chainId: ChainID;
|
|
67
|
-
address: Address;
|
|
68
|
-
data?: string;
|
|
69
|
-
to?: string;
|
|
70
|
-
value?: string;
|
|
71
|
-
transactionHash?: string;
|
|
72
|
-
},
|
|
73
|
-
properties?: IFormoEventProperties,
|
|
74
|
-
context?: IFormoEventContext,
|
|
75
|
-
callback?: (...args: unknown[]) => void
|
|
76
|
-
): Promise<void>;
|
|
77
|
-
identify(
|
|
78
|
-
params: {
|
|
79
|
-
address: Address;
|
|
80
|
-
providerName?: string;
|
|
81
|
-
userId?: string;
|
|
82
|
-
rdns?: string;
|
|
83
|
-
},
|
|
84
|
-
properties?: IFormoEventProperties,
|
|
85
|
-
context?: IFormoEventContext,
|
|
86
|
-
callback?: (...args: unknown[]) => void
|
|
87
|
-
): Promise<void>;
|
|
88
|
-
track(
|
|
89
|
-
event: string,
|
|
90
|
-
properties?: IFormoEventProperties,
|
|
91
|
-
context?: IFormoEventContext,
|
|
92
|
-
callback?: (...args: unknown[]) => void
|
|
93
|
-
): Promise<void>;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
export interface Options {
|
|
97
|
-
provider?: EIP1193Provider;
|
|
98
|
-
trackLocalhost?: boolean;
|
|
99
|
-
|
|
100
|
-
flushAt?: number;
|
|
101
|
-
flushInterval?: number;
|
|
102
|
-
retryCount?: number;
|
|
103
|
-
maxQueueSize?: number;
|
|
104
|
-
logger?: {
|
|
105
|
-
enabled: boolean;
|
|
106
|
-
levels?: LogLevel[];
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
export interface FormoAnalyticsProviderProps {
|
|
111
|
-
writeKey: string;
|
|
112
|
-
options?: Options;
|
|
113
|
-
disabled?: boolean;
|
|
114
|
-
children: React.ReactNode;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
export interface Config {
|
|
118
|
-
writeKey: string;
|
|
119
|
-
trackLocalhost?: boolean;
|
|
120
|
-
}
|
package/src/types/events.ts
DELETED
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
import { UUID } from "crypto";
|
|
2
|
-
import { Address, ChainID, Nullable } from "./base";
|
|
3
|
-
import { TEventChannel, TEventType } from "../constants";
|
|
4
|
-
|
|
5
|
-
export type AnonymousID = UUID;
|
|
6
|
-
|
|
7
|
-
export interface ICommonProperties {
|
|
8
|
-
anonymous_id: AnonymousID;
|
|
9
|
-
user_id: Nullable<string>;
|
|
10
|
-
address: Nullable<string>;
|
|
11
|
-
type: TEventType;
|
|
12
|
-
channel: TEventChannel;
|
|
13
|
-
version: string;
|
|
14
|
-
original_timestamp: string;
|
|
15
|
-
event?: Nullable<string>;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export type IFormoEventProperties = Record<string, unknown>;
|
|
19
|
-
export type IFormoEventContext = Record<string, unknown>;
|
|
20
|
-
export type UTMParameters = {
|
|
21
|
-
utm_source: string;
|
|
22
|
-
utm_medium: string;
|
|
23
|
-
utm_campaign: string;
|
|
24
|
-
utm_term: string;
|
|
25
|
-
utm_content: string;
|
|
26
|
-
};
|
|
27
|
-
export type ITrafficSource = UTMParameters & {
|
|
28
|
-
ref: string;
|
|
29
|
-
referrer: string;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
export interface IFormoEvent extends ICommonProperties {
|
|
33
|
-
context: Nullable<IFormoEventContext>;
|
|
34
|
-
properties: Nullable<IFormoEventProperties>;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export type IFormoEventPayload = IFormoEvent & {
|
|
38
|
-
message_id: string;
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
//#region Specific Event Types
|
|
42
|
-
export interface PageAPIEvent {
|
|
43
|
-
type: "page";
|
|
44
|
-
name?: string;
|
|
45
|
-
category?: string;
|
|
46
|
-
}
|
|
47
|
-
export interface DetectAPIEvent {
|
|
48
|
-
type: "detect";
|
|
49
|
-
providerName: string;
|
|
50
|
-
rdns: string;
|
|
51
|
-
}
|
|
52
|
-
export interface IdentifyAPIEvent {
|
|
53
|
-
type: "identify";
|
|
54
|
-
address: string;
|
|
55
|
-
providerName: string;
|
|
56
|
-
rdns: string;
|
|
57
|
-
userId?: Nullable<string>;
|
|
58
|
-
}
|
|
59
|
-
export interface ChainAPIEvent {
|
|
60
|
-
type: "chain";
|
|
61
|
-
chainId: ChainID;
|
|
62
|
-
address: Address;
|
|
63
|
-
}
|
|
64
|
-
export interface TransactionAPIEvent {
|
|
65
|
-
type: "transaction";
|
|
66
|
-
status: TransactionStatus;
|
|
67
|
-
chainId: ChainID;
|
|
68
|
-
address: Address;
|
|
69
|
-
data: string;
|
|
70
|
-
to: string;
|
|
71
|
-
value: string;
|
|
72
|
-
transactionHash: string;
|
|
73
|
-
}
|
|
74
|
-
export interface SignatureAPIEvent {
|
|
75
|
-
type: "signature";
|
|
76
|
-
status: SignatureStatus;
|
|
77
|
-
chainId: ChainID;
|
|
78
|
-
address: Address;
|
|
79
|
-
message: string;
|
|
80
|
-
signatureHash: string;
|
|
81
|
-
}
|
|
82
|
-
export interface ConnectAPIEvent {
|
|
83
|
-
type: "connect";
|
|
84
|
-
chainId: ChainID;
|
|
85
|
-
address: Address;
|
|
86
|
-
}
|
|
87
|
-
export interface DisconnectAPIEvent {
|
|
88
|
-
type: "disconnect";
|
|
89
|
-
chainId: ChainID;
|
|
90
|
-
address: Address;
|
|
91
|
-
}
|
|
92
|
-
export interface TrackAPIEvent {
|
|
93
|
-
type: "track";
|
|
94
|
-
event: string;
|
|
95
|
-
revenue?: number;
|
|
96
|
-
currency?: string;
|
|
97
|
-
points?: number;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
export type APIEvent = {
|
|
101
|
-
properties?: IFormoEventProperties;
|
|
102
|
-
context?: IFormoEventContext;
|
|
103
|
-
callback?: (...args: unknown[]) => void;
|
|
104
|
-
} & (
|
|
105
|
-
| PageAPIEvent
|
|
106
|
-
| DetectAPIEvent
|
|
107
|
-
| IdentifyAPIEvent
|
|
108
|
-
| ChainAPIEvent
|
|
109
|
-
| TransactionAPIEvent
|
|
110
|
-
| SignatureAPIEvent
|
|
111
|
-
| ConnectAPIEvent
|
|
112
|
-
| DisconnectAPIEvent
|
|
113
|
-
| TrackAPIEvent
|
|
114
|
-
);
|
|
115
|
-
|
|
116
|
-
export enum SignatureStatus {
|
|
117
|
-
REQUESTED = "requested",
|
|
118
|
-
REJECTED = "rejected",
|
|
119
|
-
CONFIRMED = "confirmed",
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
export enum TransactionStatus {
|
|
123
|
-
STARTED = "started",
|
|
124
|
-
REJECTED = "rejected",
|
|
125
|
-
BROADCASTED = "broadcasted",
|
|
126
|
-
}
|
package/src/types/index.ts
DELETED
package/src/types/provider.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import EventEmitter from 'events'
|
|
2
|
-
|
|
3
|
-
export interface RequestArguments {
|
|
4
|
-
method: string
|
|
5
|
-
params?: unknown[] | Record<string, unknown>
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export interface EIP1193Provider extends EventEmitter {
|
|
9
|
-
request<T>(args: RequestArguments): Promise<T | null | undefined>
|
|
10
|
-
on(eventName: string | symbol, listener: (...args: unknown[]) => void): this
|
|
11
|
-
removeListener(eventName: string | symbol, listener: (...args: unknown[]) => void): this
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export interface RPCError extends Error {
|
|
15
|
-
code: number;
|
|
16
|
-
data?: unknown;
|
|
17
|
-
}
|
package/src/utils/address.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { Address } from "../types";
|
|
2
|
-
import { keccak256 } from "ethereum-cryptography/keccak.js";
|
|
3
|
-
import { utf8ToBytes } from "ethereum-cryptography/utils.js";
|
|
4
|
-
import {
|
|
5
|
-
ensureIfUint8Array,
|
|
6
|
-
isAddress,
|
|
7
|
-
uint8ArrayToHexString,
|
|
8
|
-
} from "../validators";
|
|
9
|
-
import { isNullish } from "../validators/object";
|
|
10
|
-
|
|
11
|
-
export const toChecksumAddress = (address: Address): string => {
|
|
12
|
-
if (!isAddress(address, false)) {
|
|
13
|
-
throw new Error("Invalid address " + address);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const lowerCaseAddress = address.toLowerCase().replace(/^0x/i, "");
|
|
17
|
-
|
|
18
|
-
const hash = uint8ArrayToHexString(
|
|
19
|
-
keccak256(ensureIfUint8Array(utf8ToBytes(lowerCaseAddress)))
|
|
20
|
-
);
|
|
21
|
-
|
|
22
|
-
if (
|
|
23
|
-
isNullish(hash) ||
|
|
24
|
-
hash ===
|
|
25
|
-
"0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"
|
|
26
|
-
)
|
|
27
|
-
return ""; // // EIP-1052 if hash is equal to c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470, keccak was given empty data
|
|
28
|
-
|
|
29
|
-
let checksumAddress = "0x";
|
|
30
|
-
|
|
31
|
-
const addressHash = hash.replace(/^0x/i, "");
|
|
32
|
-
|
|
33
|
-
for (let i = 0; i < lowerCaseAddress.length; i += 1) {
|
|
34
|
-
// If ith character is 8 to f then make it uppercase
|
|
35
|
-
if (parseInt(addressHash[i], 16) > 7) {
|
|
36
|
-
checksumAddress += lowerCaseAddress[i].toUpperCase();
|
|
37
|
-
} else {
|
|
38
|
-
checksumAddress += lowerCaseAddress[i];
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return checksumAddress;
|
|
43
|
-
};
|
package/src/utils/base.ts
DELETED
package/src/utils/converter.ts
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
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(data)) {
|
|
11
|
-
return data.map(convert); // Recursively handle array elements
|
|
12
|
-
} else if (data !== null && typeof data === "object") {
|
|
13
|
-
return Object.keys(data).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)
|
|
17
|
-
? data[key]
|
|
18
|
-
: convert(data[key]);
|
|
19
|
-
return acc;
|
|
20
|
-
}, {});
|
|
21
|
-
}
|
|
22
|
-
return data;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
return convert(obj);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export const millisecondsToSecond = (milliseconds: number): number =>
|
|
29
|
-
Math.ceil(milliseconds / 1_000);
|
|
30
|
-
|
|
31
|
-
export const toDateHourMinute = (date: Date) =>
|
|
32
|
-
date.getUTCFullYear() +
|
|
33
|
-
"-" +
|
|
34
|
-
("0" + (date.getUTCMonth() + 1)).slice(-2) +
|
|
35
|
-
"-" +
|
|
36
|
-
("0" + date.getUTCDate()).slice(-2) +
|
|
37
|
-
" " +
|
|
38
|
-
("0" + date.getUTCHours()).slice(-2) +
|
|
39
|
-
":" +
|
|
40
|
-
("0" + date.getUTCMinutes()).slice(-2);
|
|
41
|
-
|
|
42
|
-
export const clampNumber = (value: number, max: number, min: number) => {
|
|
43
|
-
return Math.min(Math.max(value, min), max);
|
|
44
|
-
};
|
package/src/utils/generate.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { UUID } from "crypto";
|
|
2
|
-
|
|
3
|
-
export async function hash(input: string): Promise<string> {
|
|
4
|
-
const hashBuffer = await crypto.subtle.digest(
|
|
5
|
-
"SHA-256",
|
|
6
|
-
new TextEncoder().encode(input)
|
|
7
|
-
);
|
|
8
|
-
const byteArray = new Uint8Array(hashBuffer);
|
|
9
|
-
return Array.from(byteArray)
|
|
10
|
-
.map((byte) => byte.toString(16).padStart(2, "0"))
|
|
11
|
-
.join("");
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export function generateNativeUUID(): UUID {
|
|
15
|
-
return crypto.randomUUID();
|
|
16
|
-
}
|
package/src/utils/index.ts
DELETED
package/src/utils/timestamp.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
const getFormattedTimestamp = (date: Date): string => date.toISOString();
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* To get the current timestamp in ISO string format
|
|
5
|
-
* @returns ISO formatted timestamp string
|
|
6
|
-
*/
|
|
7
|
-
const getCurrentTimeFormatted = (): string => getFormattedTimestamp(new Date());
|
|
8
|
-
|
|
9
|
-
export { getCurrentTimeFormatted, getFormattedTimestamp };
|