@formo/analytics 1.17.3 → 1.17.4
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 +4 -1
- package/.env.example +0 -1
- package/.github/workflows/ci.yml +0 -50
- package/.github/workflows/release.yml +0 -54
- package/.husky/post-commit +0 -7
- package/.husky/pre-commit +0 -11
- package/.releaserc.js +0 -35
- package/CONTRIBUTING.md +0 -83
- package/scripts/generate-sri.sh +0 -52
- package/src/FormoAnalytics.ts +0 -1031
- 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
package/src/global.d.ts
DELETED
package/src/index.ts
DELETED
|
@@ -1,519 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
COUNTRY_LIST,
|
|
3
|
-
LOCAL_ANONYMOUS_ID_KEY,
|
|
4
|
-
SESSION_TRAFFIC_SOURCE_KEY,
|
|
5
|
-
} from "../../constants";
|
|
6
|
-
import {
|
|
7
|
-
Address,
|
|
8
|
-
APIEvent,
|
|
9
|
-
ChainID,
|
|
10
|
-
IFormoEvent,
|
|
11
|
-
IFormoEventContext,
|
|
12
|
-
IFormoEventProperties,
|
|
13
|
-
ITrafficSource,
|
|
14
|
-
Nullable,
|
|
15
|
-
SignatureStatus,
|
|
16
|
-
TransactionStatus,
|
|
17
|
-
UTMParameters,
|
|
18
|
-
} from "../../types";
|
|
19
|
-
import { toChecksumAddress, toSnakeCase } from "../../utils";
|
|
20
|
-
import { getCurrentTimeFormatted } from "../../utils/timestamp";
|
|
21
|
-
import { isUndefined } from "../../validators";
|
|
22
|
-
import { logger } from "../logger";
|
|
23
|
-
import mergeDeepRight from "../ramda/mergeDeepRight";
|
|
24
|
-
import { session } from "../storage";
|
|
25
|
-
import { version } from "../version";
|
|
26
|
-
import { CHANNEL, VERSION } from "./constants";
|
|
27
|
-
import { IEventFactory } from "./type";
|
|
28
|
-
import { generateAnonymousId } from "./utils";
|
|
29
|
-
|
|
30
|
-
class EventFactory implements IEventFactory {
|
|
31
|
-
private getTimezone(): string {
|
|
32
|
-
try {
|
|
33
|
-
return Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
34
|
-
} catch (error) {
|
|
35
|
-
logger.error("Error resolving timezone:", error);
|
|
36
|
-
return "";
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
private getLocation(): string | undefined {
|
|
41
|
-
try {
|
|
42
|
-
const timezone = this.getTimezone();
|
|
43
|
-
if (timezone in COUNTRY_LIST)
|
|
44
|
-
return COUNTRY_LIST[timezone as keyof typeof COUNTRY_LIST];
|
|
45
|
-
return timezone;
|
|
46
|
-
} catch (error) {
|
|
47
|
-
logger.error("Error resolving location:", error);
|
|
48
|
-
return "";
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
private getLanguage(): string {
|
|
53
|
-
try {
|
|
54
|
-
return (
|
|
55
|
-
(navigator.languages && navigator.languages.length
|
|
56
|
-
? navigator.languages[0]
|
|
57
|
-
: navigator.language) || "en"
|
|
58
|
-
);
|
|
59
|
-
} catch (error) {
|
|
60
|
-
logger.error("Error resolving language:", error);
|
|
61
|
-
return "en";
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
private getLibraryVersion(): string {
|
|
66
|
-
return version;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
private extractUTMParameters = (url: string): UTMParameters => {
|
|
70
|
-
const result: UTMParameters = {
|
|
71
|
-
utm_campaign: "",
|
|
72
|
-
utm_content: "",
|
|
73
|
-
utm_medium: "",
|
|
74
|
-
utm_source: "",
|
|
75
|
-
utm_term: "",
|
|
76
|
-
};
|
|
77
|
-
try {
|
|
78
|
-
const urlObj = new URL(url);
|
|
79
|
-
const UTM_PREFIX = "utm_";
|
|
80
|
-
urlObj.searchParams.forEach((value, sParam) => {
|
|
81
|
-
if (sParam.startsWith(UTM_PREFIX)) {
|
|
82
|
-
result[sParam as keyof UTMParameters] = value.trim();
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
} catch (error) {}
|
|
86
|
-
return result;
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
private getTrafficSources = (url: string): ITrafficSource => {
|
|
90
|
-
const urlObj = new URL(url);
|
|
91
|
-
const contextTrafficSources: ITrafficSource = {
|
|
92
|
-
...this.extractUTMParameters(url),
|
|
93
|
-
ref: urlObj.searchParams.get("ref")?.trim() || "",
|
|
94
|
-
referrer: document.referrer,
|
|
95
|
-
};
|
|
96
|
-
const storedTrafficSources =
|
|
97
|
-
(session().get(SESSION_TRAFFIC_SOURCE_KEY) as ITrafficSource) || {};
|
|
98
|
-
|
|
99
|
-
const finalTrafficSources: ITrafficSource = {
|
|
100
|
-
ref: contextTrafficSources.ref || storedTrafficSources?.ref || "",
|
|
101
|
-
referrer:
|
|
102
|
-
contextTrafficSources.referrer || storedTrafficSources?.referrer,
|
|
103
|
-
utm_campaign:
|
|
104
|
-
contextTrafficSources.utm_campaign ||
|
|
105
|
-
storedTrafficSources?.utm_campaign ||
|
|
106
|
-
"",
|
|
107
|
-
utm_content:
|
|
108
|
-
contextTrafficSources.utm_content ||
|
|
109
|
-
storedTrafficSources?.utm_content ||
|
|
110
|
-
"",
|
|
111
|
-
utm_medium:
|
|
112
|
-
contextTrafficSources.utm_medium ||
|
|
113
|
-
storedTrafficSources?.utm_medium ||
|
|
114
|
-
"",
|
|
115
|
-
utm_source:
|
|
116
|
-
contextTrafficSources.utm_source ||
|
|
117
|
-
storedTrafficSources?.utm_source ||
|
|
118
|
-
"",
|
|
119
|
-
utm_term:
|
|
120
|
-
contextTrafficSources.utm_term || storedTrafficSources?.utm_term || "",
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
// Store to session
|
|
124
|
-
const sessionStoredTrafficSources = Object.keys(finalTrafficSources).reduce(
|
|
125
|
-
(res: any, key: any) => {
|
|
126
|
-
const value = finalTrafficSources[key as keyof ITrafficSource];
|
|
127
|
-
if (!isUndefined(value) && value !== "") {
|
|
128
|
-
res[key as keyof ITrafficSource] = value;
|
|
129
|
-
}
|
|
130
|
-
return res;
|
|
131
|
-
},
|
|
132
|
-
{}
|
|
133
|
-
);
|
|
134
|
-
|
|
135
|
-
if (Object.keys(sessionStoredTrafficSources).length)
|
|
136
|
-
session().set(SESSION_TRAFFIC_SOURCE_KEY, sessionStoredTrafficSources);
|
|
137
|
-
|
|
138
|
-
return finalTrafficSources;
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
// Contextual fields that are automatically collected and populated by the Formo SDK
|
|
142
|
-
private generateContext(context?: IFormoEventContext): IFormoEventContext {
|
|
143
|
-
const path = globalThis.location.pathname;
|
|
144
|
-
const language = this.getLanguage();
|
|
145
|
-
const timezone = this.getTimezone();
|
|
146
|
-
const location = this.getLocation();
|
|
147
|
-
const library_version = this.getLibraryVersion();
|
|
148
|
-
|
|
149
|
-
// contextual properties
|
|
150
|
-
const defaultContext = {
|
|
151
|
-
user_agent: globalThis.navigator.userAgent,
|
|
152
|
-
locale: language,
|
|
153
|
-
timezone,
|
|
154
|
-
location,
|
|
155
|
-
...this.getTrafficSources(globalThis.location.href),
|
|
156
|
-
page_path: path,
|
|
157
|
-
page_title: document.title,
|
|
158
|
-
page_url: globalThis.location.href,
|
|
159
|
-
library_name: "Formo Web SDK",
|
|
160
|
-
library_version,
|
|
161
|
-
};
|
|
162
|
-
|
|
163
|
-
const mergedContext = mergeDeepRight(
|
|
164
|
-
defaultContext,
|
|
165
|
-
context || {}
|
|
166
|
-
) as IFormoEventContext;
|
|
167
|
-
|
|
168
|
-
return mergedContext;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
/**
|
|
172
|
-
* Add any missing default page properties using values from options and defaults
|
|
173
|
-
* @param properties Input page properties
|
|
174
|
-
* @param options API options
|
|
175
|
-
*/
|
|
176
|
-
private getPageProperties = (
|
|
177
|
-
properties: IFormoEventProperties
|
|
178
|
-
): IFormoEventProperties => {
|
|
179
|
-
const pageProps = properties;
|
|
180
|
-
|
|
181
|
-
if (isUndefined(pageProps.url)) {
|
|
182
|
-
pageProps.url = new URL(globalThis.location.href).href;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
if (isUndefined(pageProps.path)) {
|
|
186
|
-
pageProps.path = globalThis.location.pathname;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
if (isUndefined(pageProps.hash)) {
|
|
190
|
-
pageProps.hash = globalThis.location.hash;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
return pageProps;
|
|
194
|
-
};
|
|
195
|
-
|
|
196
|
-
private getEnrichedEvent = (
|
|
197
|
-
formoEvent: Partial<IFormoEvent>,
|
|
198
|
-
context?: IFormoEventContext
|
|
199
|
-
): IFormoEvent => {
|
|
200
|
-
const commonEventData = {
|
|
201
|
-
context: this.generateContext(context),
|
|
202
|
-
original_timestamp: getCurrentTimeFormatted(),
|
|
203
|
-
user_id: formoEvent.user_id,
|
|
204
|
-
type: formoEvent.type,
|
|
205
|
-
channel: CHANNEL,
|
|
206
|
-
version: VERSION,
|
|
207
|
-
} as Partial<IFormoEvent>;
|
|
208
|
-
|
|
209
|
-
commonEventData.anonymous_id = generateAnonymousId(LOCAL_ANONYMOUS_ID_KEY);
|
|
210
|
-
|
|
211
|
-
if (formoEvent.address) {
|
|
212
|
-
commonEventData.address = toChecksumAddress(formoEvent.address);
|
|
213
|
-
} else {
|
|
214
|
-
commonEventData.address = formoEvent.address;
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
const processedEvent = mergeDeepRight(
|
|
218
|
-
formoEvent,
|
|
219
|
-
commonEventData
|
|
220
|
-
) as IFormoEvent;
|
|
221
|
-
|
|
222
|
-
if (processedEvent.event === undefined) {
|
|
223
|
-
processedEvent.event = null;
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
if (processedEvent.properties === undefined) {
|
|
227
|
-
processedEvent.properties = null;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
return toSnakeCase(processedEvent);
|
|
231
|
-
};
|
|
232
|
-
|
|
233
|
-
generatePageEvent(
|
|
234
|
-
category?: string,
|
|
235
|
-
name?: string,
|
|
236
|
-
properties?: IFormoEventProperties,
|
|
237
|
-
context?: IFormoEventContext
|
|
238
|
-
): IFormoEvent {
|
|
239
|
-
let props = properties ?? {};
|
|
240
|
-
props.category = category;
|
|
241
|
-
props.name = name;
|
|
242
|
-
props = this.getPageProperties(props);
|
|
243
|
-
|
|
244
|
-
const pageEvent: Partial<IFormoEvent> = {
|
|
245
|
-
properties: props,
|
|
246
|
-
type: "page",
|
|
247
|
-
};
|
|
248
|
-
|
|
249
|
-
return this.getEnrichedEvent(pageEvent, context);
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
generateDetectWalletEvent(
|
|
253
|
-
providerName: string,
|
|
254
|
-
rdns: string,
|
|
255
|
-
properties?: IFormoEventProperties,
|
|
256
|
-
context?: IFormoEventContext
|
|
257
|
-
) {
|
|
258
|
-
const detectEvent: Partial<IFormoEvent> = {
|
|
259
|
-
properties: {
|
|
260
|
-
providerName,
|
|
261
|
-
rdns,
|
|
262
|
-
...properties,
|
|
263
|
-
},
|
|
264
|
-
type: "detect",
|
|
265
|
-
};
|
|
266
|
-
|
|
267
|
-
return this.getEnrichedEvent(detectEvent, context);
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
generateIdentifyEvent(
|
|
271
|
-
providerName: string,
|
|
272
|
-
rdns: string,
|
|
273
|
-
address: Nullable<Address>,
|
|
274
|
-
userId?: Nullable<string>,
|
|
275
|
-
properties?: IFormoEventProperties,
|
|
276
|
-
context?: IFormoEventContext
|
|
277
|
-
) {
|
|
278
|
-
const identifyEvent: Partial<IFormoEvent> = {
|
|
279
|
-
properties: {
|
|
280
|
-
providerName,
|
|
281
|
-
rdns,
|
|
282
|
-
...properties,
|
|
283
|
-
},
|
|
284
|
-
user_id: userId,
|
|
285
|
-
address,
|
|
286
|
-
type: "identify",
|
|
287
|
-
};
|
|
288
|
-
|
|
289
|
-
return this.getEnrichedEvent(identifyEvent, context);
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
generateConnectEvent(
|
|
293
|
-
chainId: ChainID,
|
|
294
|
-
address: Address,
|
|
295
|
-
properties?: IFormoEventProperties,
|
|
296
|
-
context?: IFormoEventContext
|
|
297
|
-
) {
|
|
298
|
-
const connectEvent: Partial<IFormoEvent> = {
|
|
299
|
-
properties: {
|
|
300
|
-
chainId,
|
|
301
|
-
...properties,
|
|
302
|
-
},
|
|
303
|
-
address,
|
|
304
|
-
type: "connect",
|
|
305
|
-
};
|
|
306
|
-
|
|
307
|
-
return this.getEnrichedEvent(connectEvent, context);
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
generateDisconnectEvent(
|
|
311
|
-
chainId: ChainID,
|
|
312
|
-
address: Address,
|
|
313
|
-
properties?: IFormoEventProperties,
|
|
314
|
-
context?: IFormoEventContext
|
|
315
|
-
) {
|
|
316
|
-
const disconnectEvent: Partial<IFormoEvent> = {
|
|
317
|
-
properties: {
|
|
318
|
-
chainId,
|
|
319
|
-
...properties,
|
|
320
|
-
},
|
|
321
|
-
address,
|
|
322
|
-
type: "disconnect",
|
|
323
|
-
};
|
|
324
|
-
|
|
325
|
-
return this.getEnrichedEvent(disconnectEvent, context);
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
generateChainChangedEvent(
|
|
329
|
-
chainId: ChainID,
|
|
330
|
-
address: Address,
|
|
331
|
-
properties?: IFormoEventProperties,
|
|
332
|
-
context?: IFormoEventContext
|
|
333
|
-
) {
|
|
334
|
-
const chainEvent: Partial<IFormoEvent> = {
|
|
335
|
-
properties: {
|
|
336
|
-
chainId,
|
|
337
|
-
...properties,
|
|
338
|
-
},
|
|
339
|
-
address,
|
|
340
|
-
type: "chain",
|
|
341
|
-
};
|
|
342
|
-
|
|
343
|
-
return this.getEnrichedEvent(chainEvent, context);
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
generateSignatureEvent(
|
|
347
|
-
status: SignatureStatus,
|
|
348
|
-
chainId: ChainID,
|
|
349
|
-
address: Address,
|
|
350
|
-
message: string,
|
|
351
|
-
signatureHash: string,
|
|
352
|
-
properties?: IFormoEventProperties,
|
|
353
|
-
context?: IFormoEventContext
|
|
354
|
-
) {
|
|
355
|
-
const signatureEvent: Partial<IFormoEvent> = {
|
|
356
|
-
properties: {
|
|
357
|
-
status,
|
|
358
|
-
chainId,
|
|
359
|
-
message,
|
|
360
|
-
signatureHash,
|
|
361
|
-
...properties,
|
|
362
|
-
},
|
|
363
|
-
address,
|
|
364
|
-
type: "signature",
|
|
365
|
-
};
|
|
366
|
-
|
|
367
|
-
return this.getEnrichedEvent(signatureEvent, context);
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
generateTransactionEvent(
|
|
371
|
-
status: TransactionStatus,
|
|
372
|
-
chainId: ChainID,
|
|
373
|
-
address: Address,
|
|
374
|
-
data: string,
|
|
375
|
-
to: string,
|
|
376
|
-
value: string,
|
|
377
|
-
transactionHash: string,
|
|
378
|
-
properties?: IFormoEventProperties,
|
|
379
|
-
context?: IFormoEventContext
|
|
380
|
-
) {
|
|
381
|
-
const transactionEvent: Partial<IFormoEvent> = {
|
|
382
|
-
properties: {
|
|
383
|
-
status,
|
|
384
|
-
chainId,
|
|
385
|
-
data,
|
|
386
|
-
to,
|
|
387
|
-
value,
|
|
388
|
-
transactionHash,
|
|
389
|
-
...properties,
|
|
390
|
-
},
|
|
391
|
-
address,
|
|
392
|
-
type: "transaction",
|
|
393
|
-
};
|
|
394
|
-
|
|
395
|
-
return this.getEnrichedEvent(transactionEvent, context);
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
generateTrackEvent(
|
|
399
|
-
event: string,
|
|
400
|
-
properties?: IFormoEventProperties,
|
|
401
|
-
context?: IFormoEventContext
|
|
402
|
-
) {
|
|
403
|
-
const trackEvent: Partial<IFormoEvent> = {
|
|
404
|
-
properties: {
|
|
405
|
-
...properties,
|
|
406
|
-
...(properties?.revenue !== undefined && {
|
|
407
|
-
revenue: Number(properties.revenue),
|
|
408
|
-
currency: (typeof properties?.currency === "string"
|
|
409
|
-
? properties.currency
|
|
410
|
-
: "USD"
|
|
411
|
-
).toLowerCase(),
|
|
412
|
-
}),
|
|
413
|
-
...(properties?.points !== undefined && {
|
|
414
|
-
points: Number(properties.points),
|
|
415
|
-
}),
|
|
416
|
-
},
|
|
417
|
-
event,
|
|
418
|
-
type: "track",
|
|
419
|
-
};
|
|
420
|
-
|
|
421
|
-
return this.getEnrichedEvent(trackEvent, context);
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
// Returns an event with type, context, properties, and common properties
|
|
425
|
-
create(event: APIEvent, address?: Address, userId?: string): IFormoEvent {
|
|
426
|
-
let formoEvent: Partial<IFormoEvent> = {};
|
|
427
|
-
|
|
428
|
-
formoEvent.address = address || null;
|
|
429
|
-
formoEvent.user_id = userId || null;
|
|
430
|
-
|
|
431
|
-
switch (event.type) {
|
|
432
|
-
case "page":
|
|
433
|
-
formoEvent = this.generatePageEvent(
|
|
434
|
-
event.category,
|
|
435
|
-
event.name,
|
|
436
|
-
event.properties,
|
|
437
|
-
event.context
|
|
438
|
-
);
|
|
439
|
-
break;
|
|
440
|
-
case "detect":
|
|
441
|
-
formoEvent = this.generateDetectWalletEvent(
|
|
442
|
-
event.providerName,
|
|
443
|
-
event.rdns,
|
|
444
|
-
event.properties,
|
|
445
|
-
event.context
|
|
446
|
-
);
|
|
447
|
-
break;
|
|
448
|
-
case "identify":
|
|
449
|
-
formoEvent = this.generateIdentifyEvent(
|
|
450
|
-
event.providerName,
|
|
451
|
-
event.rdns,
|
|
452
|
-
event.address,
|
|
453
|
-
event.userId,
|
|
454
|
-
event.properties,
|
|
455
|
-
event.context
|
|
456
|
-
);
|
|
457
|
-
break;
|
|
458
|
-
case "chain":
|
|
459
|
-
formoEvent = this.generateChainChangedEvent(
|
|
460
|
-
event.chainId,
|
|
461
|
-
event.address,
|
|
462
|
-
event.properties,
|
|
463
|
-
event.context
|
|
464
|
-
);
|
|
465
|
-
break;
|
|
466
|
-
case "connect":
|
|
467
|
-
formoEvent = this.generateConnectEvent(
|
|
468
|
-
event.chainId,
|
|
469
|
-
event.address,
|
|
470
|
-
event.properties,
|
|
471
|
-
event.context
|
|
472
|
-
);
|
|
473
|
-
break;
|
|
474
|
-
case "disconnect":
|
|
475
|
-
formoEvent = this.generateDisconnectEvent(
|
|
476
|
-
event.chainId,
|
|
477
|
-
event.address,
|
|
478
|
-
event.properties,
|
|
479
|
-
event.context
|
|
480
|
-
);
|
|
481
|
-
break;
|
|
482
|
-
case "signature":
|
|
483
|
-
formoEvent = this.generateSignatureEvent(
|
|
484
|
-
event.status,
|
|
485
|
-
event.chainId,
|
|
486
|
-
event.address,
|
|
487
|
-
event.message,
|
|
488
|
-
event.signatureHash,
|
|
489
|
-
event.properties,
|
|
490
|
-
event.context
|
|
491
|
-
);
|
|
492
|
-
break;
|
|
493
|
-
case "transaction":
|
|
494
|
-
formoEvent = this.generateTransactionEvent(
|
|
495
|
-
event.status,
|
|
496
|
-
event.chainId,
|
|
497
|
-
event.address,
|
|
498
|
-
event.data,
|
|
499
|
-
event.to,
|
|
500
|
-
event.value,
|
|
501
|
-
event.transactionHash,
|
|
502
|
-
event.properties,
|
|
503
|
-
event.context
|
|
504
|
-
);
|
|
505
|
-
break;
|
|
506
|
-
case "track":
|
|
507
|
-
default:
|
|
508
|
-
formoEvent = this.generateTrackEvent(
|
|
509
|
-
event.event,
|
|
510
|
-
event.properties,
|
|
511
|
-
event.context
|
|
512
|
-
);
|
|
513
|
-
break;
|
|
514
|
-
}
|
|
515
|
-
return formoEvent as IFormoEvent;
|
|
516
|
-
}
|
|
517
|
-
}
|
|
518
|
-
|
|
519
|
-
export { EventFactory };
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { Address, APIEvent } from "../../types";
|
|
2
|
-
import { logger } from "../logger";
|
|
3
|
-
import { IEventQueue } from "../queue";
|
|
4
|
-
import { EventFactory } from "./EventFactory";
|
|
5
|
-
import { IEventFactory, IEventManager } from "./type";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* A service to generate valid event payloads and queue them for processing
|
|
9
|
-
*/
|
|
10
|
-
class EventManager implements IEventManager {
|
|
11
|
-
eventQueue: IEventQueue;
|
|
12
|
-
eventFactory: IEventFactory;
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
*
|
|
16
|
-
* @param eventQueue Event queue instance
|
|
17
|
-
*/
|
|
18
|
-
constructor(eventQueue: IEventQueue) {
|
|
19
|
-
this.eventQueue = eventQueue;
|
|
20
|
-
this.eventFactory = new EventFactory();
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Consumes a new incoming event
|
|
25
|
-
* @param event Incoming event data
|
|
26
|
-
*/
|
|
27
|
-
addEvent(event: APIEvent, address?: Address, userId?: string): void {
|
|
28
|
-
const { callback, ..._event } = event;
|
|
29
|
-
const formoEvent = this.eventFactory.create(_event, address, userId);
|
|
30
|
-
this.eventQueue.enqueue(formoEvent, (err, _, data) => {
|
|
31
|
-
if (err) {
|
|
32
|
-
logger.error("Error sending events:", err);
|
|
33
|
-
} else logger.info(`Events sent successfully: ${data.length} events`);
|
|
34
|
-
callback?.(err, _, data);
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export { EventManager };
|
package/src/lib/event/index.ts
DELETED
package/src/lib/event/type.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { Address, APIEvent, IFormoEvent } from "../../types";
|
|
2
|
-
|
|
3
|
-
export interface IEventManager {
|
|
4
|
-
addEvent(event: APIEvent, address?: Address, userId?: string): void;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export interface IEventFactory {
|
|
8
|
-
create(event: APIEvent, address?: Address, userId?: string): IFormoEvent;
|
|
9
|
-
}
|
package/src/lib/event/utils.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { AnonymousID } from "../../types";
|
|
2
|
-
import { generateNativeUUID } from "../../utils";
|
|
3
|
-
import { cookie } from "../storage";
|
|
4
|
-
|
|
5
|
-
const generateAnonymousId = (key: string): AnonymousID => {
|
|
6
|
-
const storedAnonymousId = cookie().get(key);
|
|
7
|
-
if (storedAnonymousId && typeof storedAnonymousId === "string")
|
|
8
|
-
return storedAnonymousId as AnonymousID;
|
|
9
|
-
const newAnonymousId = generateNativeUUID();
|
|
10
|
-
cookie().set(key, newAnonymousId, {
|
|
11
|
-
maxAge: Date.now() + 1000 * 60 * 60 * 24 * 365, // 1 year
|
|
12
|
-
domain: getCookieDomain(),
|
|
13
|
-
path: "/",
|
|
14
|
-
});
|
|
15
|
-
return newAnonymousId;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
function getCookieDomain(hostname: string = window.location.hostname): string {
|
|
19
|
-
// Special cases
|
|
20
|
-
if (
|
|
21
|
-
hostname.includes("localhost") ||
|
|
22
|
-
/^\d{1,3}(\.\d{1,3}){3}$/.test(hostname)
|
|
23
|
-
) {
|
|
24
|
-
// Localhost or IP address
|
|
25
|
-
return "";
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const parts = hostname.split(".");
|
|
29
|
-
if (parts.includes("www")) parts.splice(parts.indexOf("www"), 1);
|
|
30
|
-
return `.${parts.join(".")}`;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export { generateAnonymousId, getCookieDomain };
|
package/src/lib/fetch.ts
DELETED