@fuul/sdk 0.13.0 → 0.14.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/README.md +35 -45
- package/lib/cjs/constants.js +2 -1
- package/lib/cjs/index.js +32 -14
- package/lib/cjs/types/constants.d.ts +1 -0
- package/lib/cjs/types/constants.d.ts.map +1 -1
- package/lib/cjs/types/index.d.ts +3 -1
- package/lib/cjs/types/index.d.ts.map +1 -1
- package/lib/cjs/types/types/types.d.ts +1 -0
- package/lib/cjs/types/types/types.d.ts.map +1 -1
- package/lib/esm/constants.js +1 -0
- package/lib/esm/index.mjs +33 -15
- package/lib/esm/types/constants.d.ts +1 -0
- package/lib/esm/types/constants.d.ts.map +1 -1
- package/lib/esm/types/index.d.ts +3 -1
- package/lib/esm/types/index.d.ts.map +1 -1
- package/lib/esm/types/types/types.d.ts +1 -0
- package/lib/esm/types/types/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/lib/cjs/types/utils/date.d.ts +0 -2
- package/lib/cjs/types/utils/date.d.ts.map +0 -1
- package/lib/cjs/utils/date.js +0 -7
- package/lib/esm/types/utils/date.d.ts +0 -2
- package/lib/esm/types/utils/date.d.ts.map +0 -1
- package/lib/esm/utils/date.js +0 -3
package/README.md
CHANGED
|
@@ -20,80 +20,70 @@ yarn add @fuul/sdk
|
|
|
20
20
|
|
|
21
21
|
## 2. Set up the Fuul SDK
|
|
22
22
|
|
|
23
|
-
In order to authenticate to
|
|
23
|
+
In order to authenticate to Fuul with your project, you must execute the following in the root file of your app.
|
|
24
24
|
|
|
25
|
-
```
|
|
25
|
+
```
|
|
26
26
|
// App.tsx
|
|
27
27
|
|
|
28
28
|
// Settings config object
|
|
29
29
|
const settings = {
|
|
30
|
-
|
|
30
|
+
apiKey: "your-fuul-api-key"
|
|
31
31
|
};
|
|
32
32
|
|
|
33
33
|
const fuul = new Fuul(settings);
|
|
34
34
|
```
|
|
35
35
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
- Please note that `projectId` is not required when you initialize Fuul sdk, but it is mandatory in order to send a `“connect_wallet”` event. But don’t worry, you can send it later as an argument using the `Fuul.sendEvent()` method if needed (please refer to section 3 of this guide)
|
|
36
|
+
Now you’ll be able to use Fuul as a global object in any of your files, so you don’t have to create a new instance every time.
|
|
39
37
|
|
|
40
|
-
## 3.
|
|
38
|
+
## 3. Test your integration
|
|
41
39
|
|
|
42
|
-
|
|
40
|
+
Test your integration with the following method:
|
|
43
41
|
|
|
44
|
-
```tsx
|
|
45
|
-
Fuul.verifyConnection()
|
|
46
42
|
```
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
43
|
+
function main() {
|
|
44
|
+
fuul.verifyConnection();
|
|
45
|
+
}
|
|
46
|
+
main();
|
|
47
|
+
```
|
|
51
48
|
|
|
52
49
|
## 4. Sending events
|
|
53
50
|
|
|
54
|
-
|
|
51
|
+
For Fuul to attribute conversion events to your visitors, you'll need to report the connect_wallet event.
|
|
55
52
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
await Fuul.sendEvent("pageview");
|
|
60
|
-
}
|
|
53
|
+
### Connect wallet event
|
|
54
|
+
Projects must send this event every time users connect a wallet to their website (both when connecting a wallet for the first time and when changing wallets during the session).
|
|
55
|
+
For this type of event, projects must send the user address that is being connected to the website as an argument.
|
|
61
56
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}
|
|
57
|
+
```
|
|
58
|
+
await Fuul.sendEvent("connect_wallet", {
|
|
59
|
+
address: <address>,
|
|
60
|
+
signing_message: <message>,
|
|
61
|
+
signature: <signature>
|
|
62
|
+
});
|
|
63
|
+
```
|
|
70
64
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
await Fuul.sendEvent("connect_wallet", {
|
|
74
|
-
address: "0x3Ec0590BC79c74B0145f94C0bE1C5d63E491569f"
|
|
75
|
-
});
|
|
76
|
-
}
|
|
65
|
+
### Sending custom events (optional)
|
|
66
|
+
Apart from the necessary `connect wallet` event, we allow projects to send any custom event to track as pleased.
|
|
77
67
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}
|
|
68
|
+
```
|
|
69
|
+
await fuul.sendEvent("myCustomEvent", {
|
|
70
|
+
foo,
|
|
71
|
+
bar,
|
|
72
|
+
...myWonderfulArguments
|
|
73
|
+
});
|
|
84
74
|
```
|
|
85
75
|
|
|
86
76
|
## 5. Generating tracking links
|
|
87
77
|
|
|
88
|
-
You can also generate the tracking link for a given wallet `address` and `
|
|
78
|
+
You can also generate the tracking link for a given wallet `address` and `project id`
|
|
89
79
|
|
|
90
80
|
```tsx
|
|
91
81
|
// Let's assume you are testing in localhost:3000
|
|
92
82
|
|
|
93
83
|
const myWonderfulReferrerAddress: string = "0xE8BF39dCd16CF20d39006ba3C722A02e701bf0eE"
|
|
94
|
-
const
|
|
84
|
+
const projectId: string = "79e72760-c730-4422-9e7b-3b730e8800dc"
|
|
95
85
|
|
|
96
|
-
const myTrackingId: string = Fuul.generateTrackingLink(myWonderfulReferrerAddress,
|
|
86
|
+
const myTrackingId: string = Fuul.generateTrackingLink(myWonderfulReferrerAddress, projectId);
|
|
97
87
|
|
|
98
|
-
console.log(myTrackingId) // http://localhost:3000?
|
|
99
|
-
```
|
|
88
|
+
console.log(myTrackingId) // http://localhost:3000?p=79e72760-c730-4422-9e7b-3b730e8800dc&origin=fuul&r=0xE8BF39dCd16CF20d39006ba3C722A02e701bf0eE
|
|
89
|
+
```
|
package/lib/cjs/constants.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SENT_EVENT_ID_KEY = exports.REFERRER_ID_KEY = exports.PROJECT_ID_KEY = exports.TRACKING_ID_KEY = exports.SESSION_ID_KEY = void 0;
|
|
3
|
+
exports.SENT_EVENT_VALIDITY_PERIOD_MS = exports.SENT_EVENT_ID_KEY = exports.REFERRER_ID_KEY = exports.PROJECT_ID_KEY = exports.TRACKING_ID_KEY = exports.SESSION_ID_KEY = void 0;
|
|
4
4
|
exports.SESSION_ID_KEY = "fuul.session_id";
|
|
5
5
|
exports.TRACKING_ID_KEY = "fuul.tracking_id";
|
|
6
6
|
exports.PROJECT_ID_KEY = "fuul.project_id";
|
|
7
7
|
exports.REFERRER_ID_KEY = "fuul.referrer_id";
|
|
8
8
|
exports.SENT_EVENT_ID_KEY = "fuul.sent";
|
|
9
|
+
exports.SENT_EVENT_VALIDITY_PERIOD_MS = 60000;
|
package/lib/cjs/index.js
CHANGED
|
@@ -11,7 +11,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.Fuul = void 0;
|
|
13
13
|
const nanoid_1 = require("nanoid");
|
|
14
|
-
const date_js_1 = require("./utils/date.js");
|
|
15
14
|
const localStorage_js_1 = require("./utils/localStorage.js");
|
|
16
15
|
const constants_js_1 = require("./constants.js");
|
|
17
16
|
const HttpClient_js_1 = require("./infrastructure/http/HttpClient.js");
|
|
@@ -22,22 +21,32 @@ const saveSentEvent = (eventName, params) => {
|
|
|
22
21
|
const eventParams = Object.assign(Object.assign({}, params), { timestamp });
|
|
23
22
|
localStorage.setItem(SENT_EVENT_KEY, JSON.stringify(eventParams));
|
|
24
23
|
};
|
|
25
|
-
const
|
|
24
|
+
const shouldEventBeSent = (eventName, params) => {
|
|
26
25
|
const SENT_EVENT_KEY = `${constants_js_1.SENT_EVENT_ID_KEY}_${eventName}`;
|
|
27
|
-
const
|
|
28
|
-
if (!
|
|
29
|
-
return
|
|
30
|
-
|
|
31
|
-
const
|
|
26
|
+
const sentEvent = localStorage.getItem(SENT_EVENT_KEY);
|
|
27
|
+
if (!sentEvent) {
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
const parsedEvent = JSON.parse(sentEvent);
|
|
31
|
+
const nowTimestamp = Date.now();
|
|
32
|
+
const timespanMillis = nowTimestamp - parsedEvent.timestamp;
|
|
33
|
+
const sentEventExpired = timespanMillis > constants_js_1.SENT_EVENT_VALIDITY_PERIOD_MS;
|
|
34
|
+
if (sentEventExpired) {
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
let eventArgsMatch = false;
|
|
32
38
|
if (eventName === "connect_wallet") {
|
|
33
|
-
|
|
39
|
+
eventArgsMatch =
|
|
40
|
+
parsedEvent["tracking_id"] === params.tracking_id &&
|
|
41
|
+
parsedEvent["address"] === params.address;
|
|
34
42
|
}
|
|
35
43
|
else {
|
|
36
|
-
|
|
37
|
-
parsedEvent["
|
|
38
|
-
|
|
39
|
-
|
|
44
|
+
eventArgsMatch =
|
|
45
|
+
parsedEvent["tracking_id"] === params.tracking_id &&
|
|
46
|
+
parsedEvent["project_id"] === params.project_id &&
|
|
47
|
+
parsedEvent["referrer_id"] === params.referrer_id;
|
|
40
48
|
}
|
|
49
|
+
return !eventArgsMatch;
|
|
41
50
|
};
|
|
42
51
|
const generateRandomId = () => (0, nanoid_1.nanoid)();
|
|
43
52
|
const saveSessionId = () => {
|
|
@@ -96,6 +105,8 @@ class Fuul {
|
|
|
96
105
|
/**
|
|
97
106
|
* @param {EventType} name Event name.
|
|
98
107
|
* @param {EventArgsType} args Event additional arguments.
|
|
108
|
+
* @param {String} signature Event signature.
|
|
109
|
+
* @param {String} signature_message Event signature message.
|
|
99
110
|
* ```js
|
|
100
111
|
* import { Fuul } from 'fuul-sdk'
|
|
101
112
|
*
|
|
@@ -109,7 +120,7 @@ class Fuul {
|
|
|
109
120
|
* })
|
|
110
121
|
* ```
|
|
111
122
|
*/
|
|
112
|
-
sendEvent(name, args) {
|
|
123
|
+
sendEvent(name, args, signature, signature_message) {
|
|
113
124
|
return __awaiter(this, void 0, void 0, function* () {
|
|
114
125
|
const session_id = (0, localStorage_js_1.getSessionId)();
|
|
115
126
|
const tracking_id = (0, localStorage_js_1.getTrackingId)();
|
|
@@ -121,6 +132,7 @@ class Fuul {
|
|
|
121
132
|
};
|
|
122
133
|
let reqBody = {};
|
|
123
134
|
if (name === "connect_wallet") {
|
|
135
|
+
params = Object.assign(Object.assign({}, params), { address: args === null || args === void 0 ? void 0 : args.address });
|
|
124
136
|
reqBody = {
|
|
125
137
|
name,
|
|
126
138
|
session_id,
|
|
@@ -137,8 +149,14 @@ class Fuul {
|
|
|
137
149
|
event_args: Object.assign(Object.assign({}, args), { referrer: referrer_id, tracking_id }),
|
|
138
150
|
};
|
|
139
151
|
}
|
|
140
|
-
|
|
152
|
+
reqBody = Object.assign(Object.assign(Object.assign({}, reqBody), (signature && {
|
|
153
|
+
signature,
|
|
154
|
+
})), (signature_message && {
|
|
155
|
+
signature_message,
|
|
156
|
+
}));
|
|
157
|
+
if (!shouldEventBeSent(name, params)) {
|
|
141
158
|
return;
|
|
159
|
+
}
|
|
142
160
|
try {
|
|
143
161
|
yield this.httpClient.post("events", reqBody);
|
|
144
162
|
saveSentEvent(name, params);
|
|
@@ -3,4 +3,5 @@ export declare const TRACKING_ID_KEY = "fuul.tracking_id";
|
|
|
3
3
|
export declare const PROJECT_ID_KEY = "fuul.project_id";
|
|
4
4
|
export declare const REFERRER_ID_KEY = "fuul.referrer_id";
|
|
5
5
|
export declare const SENT_EVENT_ID_KEY = "fuul.sent";
|
|
6
|
+
export declare const SENT_EVENT_VALIDITY_PERIOD_MS = 60000;
|
|
6
7
|
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc,oBAAoB,CAAC;AAChD,eAAO,MAAM,eAAe,qBAAqB,CAAC;AAClD,eAAO,MAAM,cAAc,oBAAoB,CAAC;AAChD,eAAO,MAAM,eAAe,qBAAqB,CAAC;AAClD,eAAO,MAAM,iBAAiB,cAAc,CAAC"}
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc,oBAAoB,CAAC;AAChD,eAAO,MAAM,eAAe,qBAAqB,CAAC;AAClD,eAAO,MAAM,cAAc,oBAAoB,CAAC;AAChD,eAAO,MAAM,eAAe,qBAAqB,CAAC;AAClD,eAAO,MAAM,iBAAiB,cAAc,CAAC;AAC7C,eAAO,MAAM,6BAA6B,QAAQ,CAAC"}
|
package/lib/cjs/types/index.d.ts
CHANGED
|
@@ -12,6 +12,8 @@ export declare class Fuul {
|
|
|
12
12
|
/**
|
|
13
13
|
* @param {EventType} name Event name.
|
|
14
14
|
* @param {EventArgsType} args Event additional arguments.
|
|
15
|
+
* @param {String} signature Event signature.
|
|
16
|
+
* @param {String} signature_message Event signature message.
|
|
15
17
|
* ```js
|
|
16
18
|
* import { Fuul } from 'fuul-sdk'
|
|
17
19
|
*
|
|
@@ -25,7 +27,7 @@ export declare class Fuul {
|
|
|
25
27
|
* })
|
|
26
28
|
* ```
|
|
27
29
|
*/
|
|
28
|
-
sendEvent(name: EventType, args?: EventArgsType): Promise<any>;
|
|
30
|
+
sendEvent(name: EventType, args?: EventArgsType, signature?: string, signature_message?: string): Promise<any>;
|
|
29
31
|
verifyConnection(): void;
|
|
30
32
|
/**
|
|
31
33
|
* Generates a tracking link for a referrer
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAgBA,OAAO,EACL,aAAa,EACb,SAAS,EACT,YAAY,EACZ,qBAAqB,EAEtB,MAAM,kBAAkB,CAAC;AAI1B,OAAO,EAAE,WAAW,EAAE,MAAM,oCAAoC,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAgBA,OAAO,EACL,aAAa,EACb,SAAS,EACT,YAAY,EACZ,qBAAqB,EAEtB,MAAM,kBAAkB,CAAC;AAI1B,OAAO,EAAE,WAAW,EAAE,MAAM,oCAAoC,CAAC;AAkFjE,qBAAa,IAAI;IACf,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAA0C;IACvE,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAa;IACxC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAe;IAExC,OAAO,CAAC,gBAAgB,CAAmB;gBAE/B,MAAM,EAAE,MAAM,EAAE,QAAQ,GAAE,YAAiB;IAuBjD,IAAI;IAQV,WAAW,IAAI,IAAI;IAMnB;;;;;;;;;;;;;;;;;OAiBG;IACG,SAAS,CACb,IAAI,EAAE,SAAS,EACf,IAAI,CAAC,EAAE,aAAa,EACpB,SAAS,CAAC,EAAE,MAAM,EAClB,iBAAiB,CAAC,EAAE,MAAM,GACzB,OAAO,CAAC,GAAG,CAAC;IAsEf,gBAAgB,IAAI,IAAI;IAMxB;;;;;;OAMG;IACH,oBAAoB,CAAC,EACnB,OAAO,EACP,GAAG,EACH,OAAO,GACR,EAAE,qBAAqB,GAAG,MAAM;IAO3B,eAAe,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC;CAGhD;;;;AAMD,wBAEE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/types/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,SAAS,CAAC;IAChB,IAAI,CAAC,EAAE,aAAa,CAAC;CACtB;AAED,MAAM,MAAM,aAAa,GAAG;IAC1B,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IACzB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAChD,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG,gBAAgB,GAAG,UAAU,CAAC;AAEtD,MAAM,WAAW,eAAe;IAC9B,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/types/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,SAAS,CAAC;IAChB,IAAI,CAAC,EAAE,aAAa,CAAC;CACtB;AAED,MAAM,MAAM,aAAa,GAAG;IAC1B,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IACzB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAChD,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG,gBAAgB,GAAG,UAAU,CAAC;AAEtD,MAAM,WAAW,eAAe;IAC9B,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,qBAAqB;IACpC,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB"}
|
package/lib/esm/constants.js
CHANGED
package/lib/esm/index.mjs
CHANGED
|
@@ -8,9 +8,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { nanoid } from "nanoid";
|
|
11
|
-
import { datesAreOnSameDay } from "./utils/date.js";
|
|
12
11
|
import { getReferrerId, getSessionId, getTrackingId, } from "./utils/localStorage.js";
|
|
13
|
-
import { REFERRER_ID_KEY, SENT_EVENT_ID_KEY, SESSION_ID_KEY, TRACKING_ID_KEY, } from "./constants.js";
|
|
12
|
+
import { REFERRER_ID_KEY, SENT_EVENT_ID_KEY, SESSION_ID_KEY, TRACKING_ID_KEY, SENT_EVENT_VALIDITY_PERIOD_MS, } from "./constants.js";
|
|
14
13
|
import { HttpClient } from "./infrastructure/http/HttpClient.js";
|
|
15
14
|
import { CampaignsService } from "./infrastructure/campaigns/campaignsService.js";
|
|
16
15
|
const saveSentEvent = (eventName, params) => {
|
|
@@ -19,22 +18,32 @@ const saveSentEvent = (eventName, params) => {
|
|
|
19
18
|
const eventParams = Object.assign(Object.assign({}, params), { timestamp });
|
|
20
19
|
localStorage.setItem(SENT_EVENT_KEY, JSON.stringify(eventParams));
|
|
21
20
|
};
|
|
22
|
-
const
|
|
21
|
+
const shouldEventBeSent = (eventName, params) => {
|
|
23
22
|
const SENT_EVENT_KEY = `${SENT_EVENT_ID_KEY}_${eventName}`;
|
|
24
|
-
const
|
|
25
|
-
if (!
|
|
26
|
-
return
|
|
27
|
-
|
|
28
|
-
const
|
|
23
|
+
const sentEvent = localStorage.getItem(SENT_EVENT_KEY);
|
|
24
|
+
if (!sentEvent) {
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
const parsedEvent = JSON.parse(sentEvent);
|
|
28
|
+
const nowTimestamp = Date.now();
|
|
29
|
+
const timespanMillis = nowTimestamp - parsedEvent.timestamp;
|
|
30
|
+
const sentEventExpired = timespanMillis > SENT_EVENT_VALIDITY_PERIOD_MS;
|
|
31
|
+
if (sentEventExpired) {
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
let eventArgsMatch = false;
|
|
29
35
|
if (eventName === "connect_wallet") {
|
|
30
|
-
|
|
36
|
+
eventArgsMatch =
|
|
37
|
+
parsedEvent["tracking_id"] === params.tracking_id &&
|
|
38
|
+
parsedEvent["address"] === params.address;
|
|
31
39
|
}
|
|
32
40
|
else {
|
|
33
|
-
|
|
34
|
-
parsedEvent["
|
|
35
|
-
|
|
36
|
-
|
|
41
|
+
eventArgsMatch =
|
|
42
|
+
parsedEvent["tracking_id"] === params.tracking_id &&
|
|
43
|
+
parsedEvent["project_id"] === params.project_id &&
|
|
44
|
+
parsedEvent["referrer_id"] === params.referrer_id;
|
|
37
45
|
}
|
|
46
|
+
return !eventArgsMatch;
|
|
38
47
|
};
|
|
39
48
|
const generateRandomId = () => nanoid();
|
|
40
49
|
const saveSessionId = () => {
|
|
@@ -93,6 +102,8 @@ export class Fuul {
|
|
|
93
102
|
/**
|
|
94
103
|
* @param {EventType} name Event name.
|
|
95
104
|
* @param {EventArgsType} args Event additional arguments.
|
|
105
|
+
* @param {String} signature Event signature.
|
|
106
|
+
* @param {String} signature_message Event signature message.
|
|
96
107
|
* ```js
|
|
97
108
|
* import { Fuul } from 'fuul-sdk'
|
|
98
109
|
*
|
|
@@ -106,7 +117,7 @@ export class Fuul {
|
|
|
106
117
|
* })
|
|
107
118
|
* ```
|
|
108
119
|
*/
|
|
109
|
-
sendEvent(name, args) {
|
|
120
|
+
sendEvent(name, args, signature, signature_message) {
|
|
110
121
|
return __awaiter(this, void 0, void 0, function* () {
|
|
111
122
|
const session_id = getSessionId();
|
|
112
123
|
const tracking_id = getTrackingId();
|
|
@@ -118,6 +129,7 @@ export class Fuul {
|
|
|
118
129
|
};
|
|
119
130
|
let reqBody = {};
|
|
120
131
|
if (name === "connect_wallet") {
|
|
132
|
+
params = Object.assign(Object.assign({}, params), { address: args === null || args === void 0 ? void 0 : args.address });
|
|
121
133
|
reqBody = {
|
|
122
134
|
name,
|
|
123
135
|
session_id,
|
|
@@ -134,8 +146,14 @@ export class Fuul {
|
|
|
134
146
|
event_args: Object.assign(Object.assign({}, args), { referrer: referrer_id, tracking_id }),
|
|
135
147
|
};
|
|
136
148
|
}
|
|
137
|
-
|
|
149
|
+
reqBody = Object.assign(Object.assign(Object.assign({}, reqBody), (signature && {
|
|
150
|
+
signature,
|
|
151
|
+
})), (signature_message && {
|
|
152
|
+
signature_message,
|
|
153
|
+
}));
|
|
154
|
+
if (!shouldEventBeSent(name, params)) {
|
|
138
155
|
return;
|
|
156
|
+
}
|
|
139
157
|
try {
|
|
140
158
|
yield this.httpClient.post("events", reqBody);
|
|
141
159
|
saveSentEvent(name, params);
|
|
@@ -3,4 +3,5 @@ export declare const TRACKING_ID_KEY = "fuul.tracking_id";
|
|
|
3
3
|
export declare const PROJECT_ID_KEY = "fuul.project_id";
|
|
4
4
|
export declare const REFERRER_ID_KEY = "fuul.referrer_id";
|
|
5
5
|
export declare const SENT_EVENT_ID_KEY = "fuul.sent";
|
|
6
|
+
export declare const SENT_EVENT_VALIDITY_PERIOD_MS = 60000;
|
|
6
7
|
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc,oBAAoB,CAAC;AAChD,eAAO,MAAM,eAAe,qBAAqB,CAAC;AAClD,eAAO,MAAM,cAAc,oBAAoB,CAAC;AAChD,eAAO,MAAM,eAAe,qBAAqB,CAAC;AAClD,eAAO,MAAM,iBAAiB,cAAc,CAAC"}
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc,oBAAoB,CAAC;AAChD,eAAO,MAAM,eAAe,qBAAqB,CAAC;AAClD,eAAO,MAAM,cAAc,oBAAoB,CAAC;AAChD,eAAO,MAAM,eAAe,qBAAqB,CAAC;AAClD,eAAO,MAAM,iBAAiB,cAAc,CAAC;AAC7C,eAAO,MAAM,6BAA6B,QAAQ,CAAC"}
|
package/lib/esm/types/index.d.ts
CHANGED
|
@@ -12,6 +12,8 @@ export declare class Fuul {
|
|
|
12
12
|
/**
|
|
13
13
|
* @param {EventType} name Event name.
|
|
14
14
|
* @param {EventArgsType} args Event additional arguments.
|
|
15
|
+
* @param {String} signature Event signature.
|
|
16
|
+
* @param {String} signature_message Event signature message.
|
|
15
17
|
* ```js
|
|
16
18
|
* import { Fuul } from 'fuul-sdk'
|
|
17
19
|
*
|
|
@@ -25,7 +27,7 @@ export declare class Fuul {
|
|
|
25
27
|
* })
|
|
26
28
|
* ```
|
|
27
29
|
*/
|
|
28
|
-
sendEvent(name: EventType, args?: EventArgsType): Promise<any>;
|
|
30
|
+
sendEvent(name: EventType, args?: EventArgsType, signature?: string, signature_message?: string): Promise<any>;
|
|
29
31
|
verifyConnection(): void;
|
|
30
32
|
/**
|
|
31
33
|
* Generates a tracking link for a referrer
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAgBA,OAAO,EACL,aAAa,EACb,SAAS,EACT,YAAY,EACZ,qBAAqB,EAEtB,MAAM,kBAAkB,CAAC;AAI1B,OAAO,EAAE,WAAW,EAAE,MAAM,oCAAoC,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAgBA,OAAO,EACL,aAAa,EACb,SAAS,EACT,YAAY,EACZ,qBAAqB,EAEtB,MAAM,kBAAkB,CAAC;AAI1B,OAAO,EAAE,WAAW,EAAE,MAAM,oCAAoC,CAAC;AAkFjE,qBAAa,IAAI;IACf,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAA0C;IACvE,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAa;IACxC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAe;IAExC,OAAO,CAAC,gBAAgB,CAAmB;gBAE/B,MAAM,EAAE,MAAM,EAAE,QAAQ,GAAE,YAAiB;IAuBjD,IAAI;IAQV,WAAW,IAAI,IAAI;IAMnB;;;;;;;;;;;;;;;;;OAiBG;IACG,SAAS,CACb,IAAI,EAAE,SAAS,EACf,IAAI,CAAC,EAAE,aAAa,EACpB,SAAS,CAAC,EAAE,MAAM,EAClB,iBAAiB,CAAC,EAAE,MAAM,GACzB,OAAO,CAAC,GAAG,CAAC;IAsEf,gBAAgB,IAAI,IAAI;IAMxB;;;;;;OAMG;IACH,oBAAoB,CAAC,EACnB,OAAO,EACP,GAAG,EACH,OAAO,GACR,EAAE,qBAAqB,GAAG,MAAM;IAO3B,eAAe,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC;CAGhD;;;;AAMD,wBAEE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/types/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,SAAS,CAAC;IAChB,IAAI,CAAC,EAAE,aAAa,CAAC;CACtB;AAED,MAAM,MAAM,aAAa,GAAG;IAC1B,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IACzB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAChD,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG,gBAAgB,GAAG,UAAU,CAAC;AAEtD,MAAM,WAAW,eAAe;IAC9B,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/types/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,SAAS,CAAC;IAChB,IAAI,CAAC,EAAE,aAAa,CAAC;CACtB;AAED,MAAM,MAAM,aAAa,GAAG;IAC1B,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IACzB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAChD,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG,gBAAgB,GAAG,UAAU,CAAC;AAEtD,MAAM,WAAW,eAAe;IAC9B,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,qBAAqB;IACpC,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB"}
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"date.d.ts","sourceRoot":"","sources":["../../../../src/utils/date.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,iBAAiB,UAAW,IAAI,UAAU,IAAI,YAGrB,CAAC"}
|
package/lib/cjs/utils/date.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.datesAreOnSameDay = void 0;
|
|
4
|
-
const datesAreOnSameDay = (first, second) => first.getFullYear() === second.getFullYear() &&
|
|
5
|
-
first.getMonth() === second.getMonth() &&
|
|
6
|
-
first.getDate() === second.getDate();
|
|
7
|
-
exports.datesAreOnSameDay = datesAreOnSameDay;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"date.d.ts","sourceRoot":"","sources":["../../../../src/utils/date.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,iBAAiB,UAAW,IAAI,UAAU,IAAI,YAGrB,CAAC"}
|
package/lib/esm/utils/date.js
DELETED