@fuul/sdk 0.8.1 → 0.8.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/lib/cjs/constants.js +2 -2
- package/lib/cjs/index.js +20 -21
- package/lib/cjs/infrastructure/campaigns/campaignsService.js +14 -8
- package/lib/cjs/types/constants.d.ts +1 -1
- package/lib/cjs/types/constants.d.ts.map +1 -1
- package/lib/cjs/types/index.d.ts +3 -3
- package/lib/cjs/types/index.d.ts.map +1 -1
- package/lib/cjs/types/infrastructure/campaigns/campaignsService.d.ts +1 -1
- package/lib/cjs/types/infrastructure/campaigns/campaignsService.d.ts.map +1 -1
- package/lib/cjs/types/types/types.d.ts +2 -3
- package/lib/cjs/types/types/types.d.ts.map +1 -1
- package/lib/cjs/types/utils/localStorage.d.ts +1 -1
- package/lib/cjs/types/utils/localStorage.d.ts.map +1 -1
- package/lib/cjs/utils/localStorage.js +3 -3
- package/lib/esm/constants.js +1 -1
- package/lib/esm/index.mjs +22 -23
- package/lib/esm/infrastructure/campaigns/campaignsService.js +14 -8
- package/lib/esm/types/constants.d.ts +1 -1
- package/lib/esm/types/constants.d.ts.map +1 -1
- package/lib/esm/types/index.d.ts +3 -3
- package/lib/esm/types/index.d.ts.map +1 -1
- package/lib/esm/types/infrastructure/campaigns/campaignsService.d.ts +1 -1
- package/lib/esm/types/infrastructure/campaigns/campaignsService.d.ts.map +1 -1
- package/lib/esm/types/types/types.d.ts +2 -3
- package/lib/esm/types/types/types.d.ts.map +1 -1
- package/lib/esm/types/utils/localStorage.d.ts +1 -1
- package/lib/esm/types/utils/localStorage.d.ts.map +1 -1
- package/lib/esm/utils/localStorage.js +2 -2
- package/package.json +1 -2
package/lib/cjs/constants.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SENT_EVENT_ID_KEY = exports.REFERRER_ID_KEY = exports.
|
|
3
|
+
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
|
-
exports.
|
|
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";
|
package/lib/cjs/index.js
CHANGED
|
@@ -34,7 +34,7 @@ const isEventAlreadySentAndInValidTimestamp = (eventName, params) => {
|
|
|
34
34
|
}
|
|
35
35
|
else {
|
|
36
36
|
return (parsedEvent["tracking_id"] === params.tracking_id &&
|
|
37
|
-
parsedEvent["
|
|
37
|
+
parsedEvent["project_id"] === params.project_id &&
|
|
38
38
|
parsedEvent["referrer_id"] === params.referrer_id &&
|
|
39
39
|
isSameDay);
|
|
40
40
|
}
|
|
@@ -46,11 +46,11 @@ const saveSessionId = () => {
|
|
|
46
46
|
localStorage.setItem(constants_js_1.SESSION_ID_KEY, generateRandomId());
|
|
47
47
|
};
|
|
48
48
|
const saveTrackingId = () => {
|
|
49
|
-
var _a
|
|
49
|
+
var _a;
|
|
50
50
|
if (typeof window === "undefined" || typeof document === "undefined")
|
|
51
51
|
return;
|
|
52
52
|
const queryParams = new URLSearchParams(window.location.search);
|
|
53
|
-
if (!queryParams.has("
|
|
53
|
+
if (!queryParams.has("p") ||
|
|
54
54
|
!queryParams.has("origin") ||
|
|
55
55
|
!queryParams.has("r"))
|
|
56
56
|
return;
|
|
@@ -60,15 +60,14 @@ const saveTrackingId = () => {
|
|
|
60
60
|
if (!(0, localStorage_js_1.getTrackingId)()) {
|
|
61
61
|
localStorage.setItem(constants_js_1.TRACKING_ID_KEY, generateRandomId());
|
|
62
62
|
}
|
|
63
|
-
localStorage.setItem(constants_js_1.
|
|
64
|
-
localStorage.setItem(constants_js_1.REFERRER_ID_KEY, (_b = queryParams.get("r")) !== null && _b !== void 0 ? _b : "");
|
|
63
|
+
localStorage.setItem(constants_js_1.REFERRER_ID_KEY, (_a = queryParams.get("r")) !== null && _a !== void 0 ? _a : "");
|
|
65
64
|
};
|
|
66
|
-
const buildTrackingLinkQueryParams = (r,
|
|
67
|
-
return `
|
|
65
|
+
const buildTrackingLinkQueryParams = (r, p) => {
|
|
66
|
+
return `p=${p}&origin=fuul&r=${r}`;
|
|
68
67
|
};
|
|
69
68
|
class Fuul {
|
|
70
69
|
constructor(apiKey) {
|
|
71
|
-
this.BASE_API_URL = "
|
|
70
|
+
this.BASE_API_URL = "http://localhost:14000/api/v1/";
|
|
72
71
|
this.apiKey = apiKey;
|
|
73
72
|
this.checkApiKey();
|
|
74
73
|
saveSessionId();
|
|
@@ -109,7 +108,6 @@ class Fuul {
|
|
|
109
108
|
return __awaiter(this, void 0, void 0, function* () {
|
|
110
109
|
const session_id = (0, localStorage_js_1.getSessionId)();
|
|
111
110
|
const tracking_id = (0, localStorage_js_1.getTrackingId)();
|
|
112
|
-
const campaign_id = (0, localStorage_js_1.getCampaignId)();
|
|
113
111
|
const referrer_id = (0, localStorage_js_1.getReferrerId)();
|
|
114
112
|
if (!tracking_id)
|
|
115
113
|
return;
|
|
@@ -125,25 +123,26 @@ class Fuul {
|
|
|
125
123
|
};
|
|
126
124
|
}
|
|
127
125
|
else {
|
|
128
|
-
if (!
|
|
126
|
+
if (!referrer_id)
|
|
129
127
|
return;
|
|
130
|
-
params = Object.assign(Object.assign({}, params), { referrer_id,
|
|
131
|
-
campaign_id });
|
|
128
|
+
params = Object.assign(Object.assign({}, params), { referrer_id, project_id: args === null || args === void 0 ? void 0 : args.project_id });
|
|
132
129
|
reqBody = {
|
|
133
130
|
name,
|
|
134
131
|
session_id,
|
|
135
|
-
event_args: Object.assign(Object.assign({}, args), { referrer: referrer_id,
|
|
136
|
-
tracking_id }),
|
|
132
|
+
event_args: Object.assign(Object.assign({}, args), { referrer: referrer_id, tracking_id }),
|
|
137
133
|
};
|
|
138
134
|
}
|
|
139
135
|
if (isEventAlreadySentAndInValidTimestamp(name, params))
|
|
140
136
|
return;
|
|
141
137
|
try {
|
|
142
|
-
|
|
138
|
+
const PATH = (args === null || args === void 0 ? void 0 : args.project_id)
|
|
139
|
+
? `events?project_id=${args.project_id}`
|
|
140
|
+
: "events";
|
|
141
|
+
yield this.httpClient.post(PATH, reqBody);
|
|
143
142
|
saveSentEvent(name, params);
|
|
144
143
|
}
|
|
145
144
|
catch (error) {
|
|
146
|
-
|
|
145
|
+
return error;
|
|
147
146
|
}
|
|
148
147
|
});
|
|
149
148
|
}
|
|
@@ -155,16 +154,16 @@ class Fuul {
|
|
|
155
154
|
/**
|
|
156
155
|
* Generates a tracking link for a referrer
|
|
157
156
|
* @param {string} address referrer address
|
|
158
|
-
* @param {string}
|
|
157
|
+
* @param {string} pid project id you want to refer the user
|
|
159
158
|
* @param {string} baseUrl base url of your app
|
|
160
159
|
* @returns {string} tracking link
|
|
161
160
|
*/
|
|
162
|
-
generateTrackingLink({ address,
|
|
163
|
-
return `${baseUrl !== null && baseUrl !== void 0 ? baseUrl : window.location.href}?${buildTrackingLinkQueryParams(address,
|
|
161
|
+
generateTrackingLink({ address, pid, baseUrl, }) {
|
|
162
|
+
return `${baseUrl !== null && baseUrl !== void 0 ? baseUrl : window.location.href}?${buildTrackingLinkQueryParams(address, pid)}`;
|
|
164
163
|
}
|
|
165
|
-
|
|
164
|
+
getAllCampaigns(args) {
|
|
166
165
|
return __awaiter(this, void 0, void 0, function* () {
|
|
167
|
-
return
|
|
166
|
+
return this.campaignsService.getAllCampaignsByProjectId(args);
|
|
168
167
|
});
|
|
169
168
|
}
|
|
170
169
|
}
|
|
@@ -10,19 +10,25 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.CampaignsService = void 0;
|
|
13
|
+
const buildQueryParams = (args) => {
|
|
14
|
+
let queryParams = "";
|
|
15
|
+
Object.keys(args).forEach((key) => {
|
|
16
|
+
queryParams =
|
|
17
|
+
queryParams === ""
|
|
18
|
+
? queryParams + `${key}=${args[key]}`
|
|
19
|
+
: queryParams + "&" + `${key}=${args[key]}`;
|
|
20
|
+
});
|
|
21
|
+
return queryParams;
|
|
22
|
+
};
|
|
13
23
|
class CampaignsService {
|
|
14
24
|
constructor(httpClient) {
|
|
15
25
|
this.httpClient = httpClient;
|
|
16
26
|
}
|
|
17
|
-
|
|
27
|
+
getAllCampaignsByProjectId(args) {
|
|
18
28
|
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
catch (error) {
|
|
24
|
-
return error;
|
|
25
|
-
}
|
|
29
|
+
const PATH = args ? `campaigns?${buildQueryParams(args)}` : `campaigns`;
|
|
30
|
+
const { data } = yield this.httpClient.get(PATH);
|
|
31
|
+
return data;
|
|
26
32
|
});
|
|
27
33
|
}
|
|
28
34
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export declare const SESSION_ID_KEY = "fuul.session_id";
|
|
2
2
|
export declare const TRACKING_ID_KEY = "fuul.tracking_id";
|
|
3
|
-
export declare const
|
|
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
6
|
//# 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,
|
|
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"}
|
package/lib/cjs/types/index.d.ts
CHANGED
|
@@ -29,12 +29,12 @@ export declare class Fuul {
|
|
|
29
29
|
/**
|
|
30
30
|
* Generates a tracking link for a referrer
|
|
31
31
|
* @param {string} address referrer address
|
|
32
|
-
* @param {string}
|
|
32
|
+
* @param {string} pid project id you want to refer the user
|
|
33
33
|
* @param {string} baseUrl base url of your app
|
|
34
34
|
* @returns {string} tracking link
|
|
35
35
|
*/
|
|
36
|
-
generateTrackingLink({ address,
|
|
37
|
-
|
|
36
|
+
generateTrackingLink({ address, pid, baseUrl, }: IGenerateTrackingLink): string;
|
|
37
|
+
getAllCampaigns(args?: Record<string, string>): Promise<CampaignDTO[]>;
|
|
38
38
|
}
|
|
39
39
|
declare const _default: {
|
|
40
40
|
Fuul: typeof Fuul;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAgBA,OAAO,EACL,aAAa,EACb,SAAS,EACT,qBAAqB,EAEtB,MAAM,kBAAkB,CAAC;AAI1B,OAAO,EAAE,WAAW,EAAE,MAAM,oCAAoC,CAAC;AA0EjE,qBAAa,IAAI;IACf,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAA4C;IACzE,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAa;IACxC,OAAO,CAAC,gBAAgB,CAAmB;gBAE/B,MAAM,EAAE,MAAM;IAkB1B,IAAI;IAIJ,WAAW,IAAI,IAAI;IAMnB;;;;;;;;;;;;;;;OAeG;IACG,SAAS,CAAC,IAAI,EAAE,SAAS,EAAE,IAAI,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,GAAG,CAAC;IAwDpE,gBAAgB,IAAI,IAAI;IAMxB;;;;;;OAMG;IACH,oBAAoB,CAAC,EACnB,OAAO,EACP,GAAG,EACH,OAAO,GACR,EAAE,qBAAqB,GAAG,MAAM;IAO3B,eAAe,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;CAG7E;;;;AAMD,wBAEE"}
|
|
@@ -3,6 +3,6 @@ import { CampaignDTO } from "./dtos.js";
|
|
|
3
3
|
export declare class CampaignsService {
|
|
4
4
|
private httpClient;
|
|
5
5
|
constructor(httpClient: HttpClient);
|
|
6
|
-
|
|
6
|
+
getAllCampaignsByProjectId(args?: Record<string, string>): Promise<CampaignDTO[]>;
|
|
7
7
|
}
|
|
8
8
|
//# sourceMappingURL=campaignsService.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"campaignsService.d.ts","sourceRoot":"","sources":["../../../../../src/infrastructure/campaigns/campaignsService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"campaignsService.d.ts","sourceRoot":"","sources":["../../../../../src/infrastructure/campaigns/campaignsService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAexC,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,UAAU,CAAa;gBAEnB,UAAU,EAAE,UAAU;IAI5B,0BAA0B,CAC9B,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC5B,OAAO,CAAC,WAAW,EAAE,CAAC;CAM1B"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
export interface SendEventParams {
|
|
2
2
|
name: EventType;
|
|
3
3
|
args?: EventArgsType;
|
|
4
|
-
projectId?: string;
|
|
5
4
|
}
|
|
6
5
|
export type EventArgsType = {
|
|
7
6
|
[key: string]: string;
|
|
@@ -9,12 +8,12 @@ export type EventArgsType = {
|
|
|
9
8
|
export type EventType = "connect_wallet" | "pageview";
|
|
10
9
|
export interface SentEventParams {
|
|
11
10
|
tracking_id: string;
|
|
12
|
-
|
|
11
|
+
project_id?: string;
|
|
13
12
|
referrer_id?: string;
|
|
14
13
|
}
|
|
15
14
|
export interface IGenerateTrackingLink {
|
|
16
15
|
address: string;
|
|
17
|
-
|
|
16
|
+
pid: string;
|
|
18
17
|
baseUrl?: string;
|
|
19
18
|
}
|
|
20
19
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -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;
|
|
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,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;CACtB;AAED,MAAM,WAAW,qBAAqB;IACpC,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export declare const getSessionId: () => string | null;
|
|
2
2
|
export declare const getTrackingId: () => string | null;
|
|
3
|
-
export declare const
|
|
3
|
+
export declare const getProjectId: () => string | null;
|
|
4
4
|
export declare const getReferrerId: () => string | null;
|
|
5
5
|
//# sourceMappingURL=localStorage.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"localStorage.d.ts","sourceRoot":"","sources":["../../../../src/utils/localStorage.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,YAAY,qBAA6C,CAAC;AACvE,eAAO,MAAM,aAAa,qBAA8C,CAAC;AACzE,eAAO,MAAM,
|
|
1
|
+
{"version":3,"file":"localStorage.d.ts","sourceRoot":"","sources":["../../../../src/utils/localStorage.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,YAAY,qBAA6C,CAAC;AACvE,eAAO,MAAM,aAAa,qBAA8C,CAAC;AACzE,eAAO,MAAM,YAAY,qBAA6C,CAAC;AACvE,eAAO,MAAM,aAAa,qBAA8C,CAAC"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getReferrerId = exports.
|
|
3
|
+
exports.getReferrerId = exports.getProjectId = exports.getTrackingId = exports.getSessionId = void 0;
|
|
4
4
|
const constants_js_1 = require("../constants.js");
|
|
5
5
|
const getSessionId = () => localStorage.getItem(constants_js_1.SESSION_ID_KEY);
|
|
6
6
|
exports.getSessionId = getSessionId;
|
|
7
7
|
const getTrackingId = () => localStorage.getItem(constants_js_1.TRACKING_ID_KEY);
|
|
8
8
|
exports.getTrackingId = getTrackingId;
|
|
9
|
-
const
|
|
10
|
-
exports.
|
|
9
|
+
const getProjectId = () => localStorage.getItem(constants_js_1.PROJECT_ID_KEY);
|
|
10
|
+
exports.getProjectId = getProjectId;
|
|
11
11
|
const getReferrerId = () => localStorage.getItem(constants_js_1.REFERRER_ID_KEY);
|
|
12
12
|
exports.getReferrerId = getReferrerId;
|
package/lib/esm/constants.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export const SESSION_ID_KEY = "fuul.session_id";
|
|
2
2
|
export const TRACKING_ID_KEY = "fuul.tracking_id";
|
|
3
|
-
export const
|
|
3
|
+
export const PROJECT_ID_KEY = "fuul.project_id";
|
|
4
4
|
export const REFERRER_ID_KEY = "fuul.referrer_id";
|
|
5
5
|
export const SENT_EVENT_ID_KEY = "fuul.sent";
|
package/lib/esm/index.mjs
CHANGED
|
@@ -9,8 +9,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import { nanoid } from "nanoid";
|
|
11
11
|
import { datesAreOnSameDay } from "./utils/date.js";
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
12
|
+
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";
|
|
14
14
|
import { HttpClient } from "./infrastructure/http/HttpClient.js";
|
|
15
15
|
import { CampaignsService } from "./infrastructure/campaigns/campaignsService.js";
|
|
16
16
|
const saveSentEvent = (eventName, params) => {
|
|
@@ -31,7 +31,7 @@ const isEventAlreadySentAndInValidTimestamp = (eventName, params) => {
|
|
|
31
31
|
}
|
|
32
32
|
else {
|
|
33
33
|
return (parsedEvent["tracking_id"] === params.tracking_id &&
|
|
34
|
-
parsedEvent["
|
|
34
|
+
parsedEvent["project_id"] === params.project_id &&
|
|
35
35
|
parsedEvent["referrer_id"] === params.referrer_id &&
|
|
36
36
|
isSameDay);
|
|
37
37
|
}
|
|
@@ -43,11 +43,11 @@ const saveSessionId = () => {
|
|
|
43
43
|
localStorage.setItem(SESSION_ID_KEY, generateRandomId());
|
|
44
44
|
};
|
|
45
45
|
const saveTrackingId = () => {
|
|
46
|
-
var _a
|
|
46
|
+
var _a;
|
|
47
47
|
if (typeof window === "undefined" || typeof document === "undefined")
|
|
48
48
|
return;
|
|
49
49
|
const queryParams = new URLSearchParams(window.location.search);
|
|
50
|
-
if (!queryParams.has("
|
|
50
|
+
if (!queryParams.has("p") ||
|
|
51
51
|
!queryParams.has("origin") ||
|
|
52
52
|
!queryParams.has("r"))
|
|
53
53
|
return;
|
|
@@ -57,15 +57,14 @@ const saveTrackingId = () => {
|
|
|
57
57
|
if (!getTrackingId()) {
|
|
58
58
|
localStorage.setItem(TRACKING_ID_KEY, generateRandomId());
|
|
59
59
|
}
|
|
60
|
-
localStorage.setItem(
|
|
61
|
-
localStorage.setItem(REFERRER_ID_KEY, (_b = queryParams.get("r")) !== null && _b !== void 0 ? _b : "");
|
|
60
|
+
localStorage.setItem(REFERRER_ID_KEY, (_a = queryParams.get("r")) !== null && _a !== void 0 ? _a : "");
|
|
62
61
|
};
|
|
63
|
-
const buildTrackingLinkQueryParams = (r,
|
|
64
|
-
return `
|
|
62
|
+
const buildTrackingLinkQueryParams = (r, p) => {
|
|
63
|
+
return `p=${p}&origin=fuul&r=${r}`;
|
|
65
64
|
};
|
|
66
65
|
export class Fuul {
|
|
67
66
|
constructor(apiKey) {
|
|
68
|
-
this.BASE_API_URL = "
|
|
67
|
+
this.BASE_API_URL = "http://localhost:14000/api/v1/";
|
|
69
68
|
this.apiKey = apiKey;
|
|
70
69
|
this.checkApiKey();
|
|
71
70
|
saveSessionId();
|
|
@@ -106,7 +105,6 @@ export class Fuul {
|
|
|
106
105
|
return __awaiter(this, void 0, void 0, function* () {
|
|
107
106
|
const session_id = getSessionId();
|
|
108
107
|
const tracking_id = getTrackingId();
|
|
109
|
-
const campaign_id = getCampaignId();
|
|
110
108
|
const referrer_id = getReferrerId();
|
|
111
109
|
if (!tracking_id)
|
|
112
110
|
return;
|
|
@@ -122,25 +120,26 @@ export class Fuul {
|
|
|
122
120
|
};
|
|
123
121
|
}
|
|
124
122
|
else {
|
|
125
|
-
if (!
|
|
123
|
+
if (!referrer_id)
|
|
126
124
|
return;
|
|
127
|
-
params = Object.assign(Object.assign({}, params), { referrer_id,
|
|
128
|
-
campaign_id });
|
|
125
|
+
params = Object.assign(Object.assign({}, params), { referrer_id, project_id: args === null || args === void 0 ? void 0 : args.project_id });
|
|
129
126
|
reqBody = {
|
|
130
127
|
name,
|
|
131
128
|
session_id,
|
|
132
|
-
event_args: Object.assign(Object.assign({}, args), { referrer: referrer_id,
|
|
133
|
-
tracking_id }),
|
|
129
|
+
event_args: Object.assign(Object.assign({}, args), { referrer: referrer_id, tracking_id }),
|
|
134
130
|
};
|
|
135
131
|
}
|
|
136
132
|
if (isEventAlreadySentAndInValidTimestamp(name, params))
|
|
137
133
|
return;
|
|
138
134
|
try {
|
|
139
|
-
|
|
135
|
+
const PATH = (args === null || args === void 0 ? void 0 : args.project_id)
|
|
136
|
+
? `events?project_id=${args.project_id}`
|
|
137
|
+
: "events";
|
|
138
|
+
yield this.httpClient.post(PATH, reqBody);
|
|
140
139
|
saveSentEvent(name, params);
|
|
141
140
|
}
|
|
142
141
|
catch (error) {
|
|
143
|
-
|
|
142
|
+
return error;
|
|
144
143
|
}
|
|
145
144
|
});
|
|
146
145
|
}
|
|
@@ -152,16 +151,16 @@ export class Fuul {
|
|
|
152
151
|
/**
|
|
153
152
|
* Generates a tracking link for a referrer
|
|
154
153
|
* @param {string} address referrer address
|
|
155
|
-
* @param {string}
|
|
154
|
+
* @param {string} pid project id you want to refer the user
|
|
156
155
|
* @param {string} baseUrl base url of your app
|
|
157
156
|
* @returns {string} tracking link
|
|
158
157
|
*/
|
|
159
|
-
generateTrackingLink({ address,
|
|
160
|
-
return `${baseUrl !== null && baseUrl !== void 0 ? baseUrl : window.location.href}?${buildTrackingLinkQueryParams(address,
|
|
158
|
+
generateTrackingLink({ address, pid, baseUrl, }) {
|
|
159
|
+
return `${baseUrl !== null && baseUrl !== void 0 ? baseUrl : window.location.href}?${buildTrackingLinkQueryParams(address, pid)}`;
|
|
161
160
|
}
|
|
162
|
-
|
|
161
|
+
getAllCampaigns(args) {
|
|
163
162
|
return __awaiter(this, void 0, void 0, function* () {
|
|
164
|
-
return
|
|
163
|
+
return this.campaignsService.getAllCampaignsByProjectId(args);
|
|
165
164
|
});
|
|
166
165
|
}
|
|
167
166
|
}
|
|
@@ -7,19 +7,25 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
+
const buildQueryParams = (args) => {
|
|
11
|
+
let queryParams = "";
|
|
12
|
+
Object.keys(args).forEach((key) => {
|
|
13
|
+
queryParams =
|
|
14
|
+
queryParams === ""
|
|
15
|
+
? queryParams + `${key}=${args[key]}`
|
|
16
|
+
: queryParams + "&" + `${key}=${args[key]}`;
|
|
17
|
+
});
|
|
18
|
+
return queryParams;
|
|
19
|
+
};
|
|
10
20
|
export class CampaignsService {
|
|
11
21
|
constructor(httpClient) {
|
|
12
22
|
this.httpClient = httpClient;
|
|
13
23
|
}
|
|
14
|
-
|
|
24
|
+
getAllCampaignsByProjectId(args) {
|
|
15
25
|
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
catch (error) {
|
|
21
|
-
return error;
|
|
22
|
-
}
|
|
26
|
+
const PATH = args ? `campaigns?${buildQueryParams(args)}` : `campaigns`;
|
|
27
|
+
const { data } = yield this.httpClient.get(PATH);
|
|
28
|
+
return data;
|
|
23
29
|
});
|
|
24
30
|
}
|
|
25
31
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export declare const SESSION_ID_KEY = "fuul.session_id";
|
|
2
2
|
export declare const TRACKING_ID_KEY = "fuul.tracking_id";
|
|
3
|
-
export declare const
|
|
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
6
|
//# 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,
|
|
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"}
|
package/lib/esm/types/index.d.ts
CHANGED
|
@@ -29,12 +29,12 @@ export declare class Fuul {
|
|
|
29
29
|
/**
|
|
30
30
|
* Generates a tracking link for a referrer
|
|
31
31
|
* @param {string} address referrer address
|
|
32
|
-
* @param {string}
|
|
32
|
+
* @param {string} pid project id you want to refer the user
|
|
33
33
|
* @param {string} baseUrl base url of your app
|
|
34
34
|
* @returns {string} tracking link
|
|
35
35
|
*/
|
|
36
|
-
generateTrackingLink({ address,
|
|
37
|
-
|
|
36
|
+
generateTrackingLink({ address, pid, baseUrl, }: IGenerateTrackingLink): string;
|
|
37
|
+
getAllCampaigns(args?: Record<string, string>): Promise<CampaignDTO[]>;
|
|
38
38
|
}
|
|
39
39
|
declare const _default: {
|
|
40
40
|
Fuul: typeof Fuul;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAgBA,OAAO,EACL,aAAa,EACb,SAAS,EACT,qBAAqB,EAEtB,MAAM,kBAAkB,CAAC;AAI1B,OAAO,EAAE,WAAW,EAAE,MAAM,oCAAoC,CAAC;AA0EjE,qBAAa,IAAI;IACf,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAA4C;IACzE,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAa;IACxC,OAAO,CAAC,gBAAgB,CAAmB;gBAE/B,MAAM,EAAE,MAAM;IAkB1B,IAAI;IAIJ,WAAW,IAAI,IAAI;IAMnB;;;;;;;;;;;;;;;OAeG;IACG,SAAS,CAAC,IAAI,EAAE,SAAS,EAAE,IAAI,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,GAAG,CAAC;IAwDpE,gBAAgB,IAAI,IAAI;IAMxB;;;;;;OAMG;IACH,oBAAoB,CAAC,EACnB,OAAO,EACP,GAAG,EACH,OAAO,GACR,EAAE,qBAAqB,GAAG,MAAM;IAO3B,eAAe,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;CAG7E;;;;AAMD,wBAEE"}
|
|
@@ -3,6 +3,6 @@ import { CampaignDTO } from "./dtos.js";
|
|
|
3
3
|
export declare class CampaignsService {
|
|
4
4
|
private httpClient;
|
|
5
5
|
constructor(httpClient: HttpClient);
|
|
6
|
-
|
|
6
|
+
getAllCampaignsByProjectId(args?: Record<string, string>): Promise<CampaignDTO[]>;
|
|
7
7
|
}
|
|
8
8
|
//# sourceMappingURL=campaignsService.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"campaignsService.d.ts","sourceRoot":"","sources":["../../../../../src/infrastructure/campaigns/campaignsService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"campaignsService.d.ts","sourceRoot":"","sources":["../../../../../src/infrastructure/campaigns/campaignsService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAexC,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,UAAU,CAAa;gBAEnB,UAAU,EAAE,UAAU;IAI5B,0BAA0B,CAC9B,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC5B,OAAO,CAAC,WAAW,EAAE,CAAC;CAM1B"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
export interface SendEventParams {
|
|
2
2
|
name: EventType;
|
|
3
3
|
args?: EventArgsType;
|
|
4
|
-
projectId?: string;
|
|
5
4
|
}
|
|
6
5
|
export type EventArgsType = {
|
|
7
6
|
[key: string]: string;
|
|
@@ -9,12 +8,12 @@ export type EventArgsType = {
|
|
|
9
8
|
export type EventType = "connect_wallet" | "pageview";
|
|
10
9
|
export interface SentEventParams {
|
|
11
10
|
tracking_id: string;
|
|
12
|
-
|
|
11
|
+
project_id?: string;
|
|
13
12
|
referrer_id?: string;
|
|
14
13
|
}
|
|
15
14
|
export interface IGenerateTrackingLink {
|
|
16
15
|
address: string;
|
|
17
|
-
|
|
16
|
+
pid: string;
|
|
18
17
|
baseUrl?: string;
|
|
19
18
|
}
|
|
20
19
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -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;
|
|
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,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;CACtB;AAED,MAAM,WAAW,qBAAqB;IACpC,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export declare const getSessionId: () => string | null;
|
|
2
2
|
export declare const getTrackingId: () => string | null;
|
|
3
|
-
export declare const
|
|
3
|
+
export declare const getProjectId: () => string | null;
|
|
4
4
|
export declare const getReferrerId: () => string | null;
|
|
5
5
|
//# sourceMappingURL=localStorage.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"localStorage.d.ts","sourceRoot":"","sources":["../../../../src/utils/localStorage.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,YAAY,qBAA6C,CAAC;AACvE,eAAO,MAAM,aAAa,qBAA8C,CAAC;AACzE,eAAO,MAAM,
|
|
1
|
+
{"version":3,"file":"localStorage.d.ts","sourceRoot":"","sources":["../../../../src/utils/localStorage.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,YAAY,qBAA6C,CAAC;AACvE,eAAO,MAAM,aAAa,qBAA8C,CAAC;AACzE,eAAO,MAAM,YAAY,qBAA6C,CAAC;AACvE,eAAO,MAAM,aAAa,qBAA8C,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PROJECT_ID_KEY, REFERRER_ID_KEY, SESSION_ID_KEY, TRACKING_ID_KEY, } from "../constants.js";
|
|
2
2
|
export const getSessionId = () => localStorage.getItem(SESSION_ID_KEY);
|
|
3
3
|
export const getTrackingId = () => localStorage.getItem(TRACKING_ID_KEY);
|
|
4
|
-
export const
|
|
4
|
+
export const getProjectId = () => localStorage.getItem(PROJECT_ID_KEY);
|
|
5
5
|
export const getReferrerId = () => localStorage.getItem(REFERRER_ID_KEY);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fuul/sdk",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Fuul SDK",
|
|
6
6
|
"types": "./lib/esm/types/index.d.ts",
|
|
@@ -9,7 +9,6 @@
|
|
|
9
9
|
"lib/**/*"
|
|
10
10
|
],
|
|
11
11
|
"scripts": {
|
|
12
|
-
"compile": "node compile.js",
|
|
13
12
|
"clean": "rm -rf ./lib",
|
|
14
13
|
"dev": "ts-node ./src/index.ts",
|
|
15
14
|
"build": "npm run clean && npm run build:esm && npm run build:cjs",
|