@fuul/sdk 0.7.0 → 0.8.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/lib/cjs/index.js +30 -17
- package/lib/cjs/infrastructure/campaigns/campaignsService.js +29 -0
- package/lib/cjs/infrastructure/campaigns/dtos.js +2 -0
- package/lib/cjs/infrastructure/http/HttpClient.js +47 -0
- package/lib/cjs/types/index.d.ts +10 -4
- package/lib/cjs/types/index.d.ts.map +1 -1
- package/lib/cjs/types/infrastructure/campaigns/campaignsService.d.ts +8 -0
- package/lib/cjs/types/infrastructure/campaigns/campaignsService.d.ts.map +1 -0
- package/lib/cjs/types/infrastructure/campaigns/dtos.d.ts +32 -0
- package/lib/cjs/types/infrastructure/campaigns/dtos.d.ts.map +1 -0
- package/lib/cjs/types/infrastructure/http/HttpClient.d.ts +25 -0
- package/lib/cjs/types/infrastructure/http/HttpClient.d.ts.map +1 -0
- package/lib/esm/index.mjs +30 -14
- package/lib/esm/infrastructure/campaigns/campaignsService.js +25 -0
- package/lib/esm/infrastructure/campaigns/dtos.js +1 -0
- package/lib/esm/infrastructure/http/HttpClient.js +40 -0
- package/lib/esm/types/index.d.ts +10 -4
- package/lib/esm/types/index.d.ts.map +1 -1
- package/lib/esm/types/infrastructure/campaigns/campaignsService.d.ts +8 -0
- package/lib/esm/types/infrastructure/campaigns/campaignsService.d.ts.map +1 -0
- package/lib/esm/types/infrastructure/campaigns/dtos.d.ts +32 -0
- package/lib/esm/types/infrastructure/campaigns/dtos.d.ts.map +1 -0
- package/lib/esm/types/infrastructure/http/HttpClient.d.ts +25 -0
- package/lib/esm/types/infrastructure/http/HttpClient.d.ts.map +1 -0
- package/package.json +1 -1
package/lib/cjs/index.js
CHANGED
|
@@ -8,16 +8,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
12
|
exports.Fuul = void 0;
|
|
16
|
-
const axios_1 = __importDefault(require("axios"));
|
|
17
13
|
const nanoid_1 = require("nanoid");
|
|
18
14
|
const date_js_1 = require("./utils/date.js");
|
|
19
15
|
const localStorage_js_1 = require("./utils/localStorage.js");
|
|
20
16
|
const constants_js_1 = require("./constants.js");
|
|
17
|
+
const HttpClient_js_1 = require("./infrastructure/http/HttpClient.js");
|
|
18
|
+
const campaignsService_js_1 = require("./infrastructure/campaigns/campaignsService.js");
|
|
21
19
|
const saveSentEvent = (eventName, params) => {
|
|
22
20
|
const timestamp = Date.now();
|
|
23
21
|
const SENT_EVENT_KEY = `${constants_js_1.SENT_EVENT_ID_KEY}_${eventName}`;
|
|
@@ -41,9 +39,7 @@ const isEventAlreadySentAndInValidTimestamp = (eventName, params) => {
|
|
|
41
39
|
isSameDay);
|
|
42
40
|
}
|
|
43
41
|
};
|
|
44
|
-
const generateRandomId = () =>
|
|
45
|
-
return (0, nanoid_1.nanoid)();
|
|
46
|
-
};
|
|
42
|
+
const generateRandomId = () => (0, nanoid_1.nanoid)();
|
|
47
43
|
const saveSessionId = () => {
|
|
48
44
|
if (typeof window === "undefined")
|
|
49
45
|
return;
|
|
@@ -71,13 +67,29 @@ const buildTrackingLinkQueryParams = (r, c) => {
|
|
|
71
67
|
return `c=${c}&origin=fuul&r=${r}`;
|
|
72
68
|
};
|
|
73
69
|
class Fuul {
|
|
74
|
-
constructor(
|
|
75
|
-
this.BASE_API_URL = "https://api.fuul.xyz/api/v1";
|
|
76
|
-
this.
|
|
70
|
+
constructor(apiKey) {
|
|
71
|
+
this.BASE_API_URL = "https://api.fuul.xyz/api/v1/";
|
|
72
|
+
this.apiKey = apiKey;
|
|
73
|
+
this.checkApiKey();
|
|
77
74
|
saveSessionId();
|
|
78
75
|
saveTrackingId();
|
|
76
|
+
this.httpClient = new HttpClient_js_1.HttpClient({
|
|
77
|
+
baseURL: this.BASE_API_URL,
|
|
78
|
+
timeout: 10000,
|
|
79
|
+
apiKey: this.apiKey,
|
|
80
|
+
});
|
|
81
|
+
this.campaignsService = new campaignsService_js_1.CampaignsService(this.httpClient);
|
|
82
|
+
this.init();
|
|
83
|
+
}
|
|
84
|
+
init() {
|
|
85
|
+
this.sendEvent("pageview");
|
|
79
86
|
globalThis.Fuul = this;
|
|
80
87
|
}
|
|
88
|
+
checkApiKey() {
|
|
89
|
+
if (!this.apiKey) {
|
|
90
|
+
throw new Error("Fuul API key is required");
|
|
91
|
+
}
|
|
92
|
+
}
|
|
81
93
|
/**
|
|
82
94
|
* @param {EventType} name Event name.
|
|
83
95
|
* @param {EventArgsType} args Event additional arguments.
|
|
@@ -85,7 +97,7 @@ class Fuul {
|
|
|
85
97
|
* import { Fuul } from 'fuul-sdk'
|
|
86
98
|
*
|
|
87
99
|
* // Initialize Fuul in your app root file
|
|
88
|
-
* new Fuul('your-
|
|
100
|
+
* new Fuul('your-api-key')
|
|
89
101
|
*
|
|
90
102
|
* // Then you can send an event as follows:
|
|
91
103
|
* fuul.sendEvent('connect_wallet', {
|
|
@@ -95,7 +107,6 @@ class Fuul {
|
|
|
95
107
|
* ```
|
|
96
108
|
*/
|
|
97
109
|
sendEvent(name, args) {
|
|
98
|
-
var _a;
|
|
99
110
|
return __awaiter(this, void 0, void 0, function* () {
|
|
100
111
|
const session_id = (0, localStorage_js_1.getSessionId)();
|
|
101
112
|
const tracking_id = (0, localStorage_js_1.getTrackingId)();
|
|
@@ -122,21 +133,18 @@ class Fuul {
|
|
|
122
133
|
reqBody = {
|
|
123
134
|
name,
|
|
124
135
|
session_id,
|
|
125
|
-
project_id: (_a = this.projectId) !== null && _a !== void 0 ? _a : args === null || args === void 0 ? void 0 : args.project_id,
|
|
126
136
|
event_args: Object.assign(Object.assign({}, args), { referrer: referrer_id, campaign_id,
|
|
127
137
|
tracking_id }),
|
|
128
138
|
};
|
|
129
139
|
}
|
|
130
140
|
if (isEventAlreadySentAndInValidTimestamp(name, params))
|
|
131
141
|
return;
|
|
132
|
-
const url = `${this.BASE_API_URL}/events`;
|
|
133
142
|
try {
|
|
134
|
-
|
|
143
|
+
yield this.httpClient.post("events", reqBody);
|
|
135
144
|
saveSentEvent(name, params);
|
|
136
|
-
return response.data;
|
|
137
145
|
}
|
|
138
146
|
catch (error) {
|
|
139
|
-
|
|
147
|
+
throw new Error(error.message);
|
|
140
148
|
}
|
|
141
149
|
});
|
|
142
150
|
}
|
|
@@ -155,6 +163,11 @@ class Fuul {
|
|
|
155
163
|
generateTrackingLink({ address, cid, baseUrl, }) {
|
|
156
164
|
return `${baseUrl !== null && baseUrl !== void 0 ? baseUrl : window.location.href}?${buildTrackingLinkQueryParams(address, cid)}`;
|
|
157
165
|
}
|
|
166
|
+
getCampaignById(campaignId) {
|
|
167
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
168
|
+
return yield this.campaignsService.getCampaignyById(campaignId);
|
|
169
|
+
});
|
|
170
|
+
}
|
|
158
171
|
}
|
|
159
172
|
exports.Fuul = Fuul;
|
|
160
173
|
exports.default = {
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.CampaignsService = void 0;
|
|
13
|
+
class CampaignsService {
|
|
14
|
+
constructor(httpClient) {
|
|
15
|
+
this.httpClient = httpClient;
|
|
16
|
+
}
|
|
17
|
+
getCampaignyById(campaignId) {
|
|
18
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
try {
|
|
20
|
+
const { data } = yield this.httpClient.get(`/campaigns/${campaignId}`);
|
|
21
|
+
return data;
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
return error;
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.CampaignsService = CampaignsService;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.HttpClient = void 0;
|
|
16
|
+
const axios_1 = __importDefault(require("axios"));
|
|
17
|
+
class HttpClient {
|
|
18
|
+
constructor(options) {
|
|
19
|
+
this.client = axios_1.default.create(Object.assign(Object.assign({}, options), { headers: options.apiKey ? this._getHeaders(options.apiKey) : {} }));
|
|
20
|
+
}
|
|
21
|
+
get(path, params) {
|
|
22
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
+
return this.client.get(path, { params });
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
post(path, data) {
|
|
27
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
28
|
+
return this.client.post(path, data);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
put(path, data) {
|
|
32
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
33
|
+
return this.client.put(path, data);
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
delete(path) {
|
|
37
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
38
|
+
return this.client.delete(path);
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
_getHeaders(apiKey) {
|
|
42
|
+
const headers = {};
|
|
43
|
+
headers.Authorization = `Bearer ${apiKey}`;
|
|
44
|
+
return headers;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
exports.HttpClient = HttpClient;
|
package/lib/cjs/types/index.d.ts
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import { EventArgsType, EventType, IGenerateTrackingLink } from "./types/types.js";
|
|
2
|
+
import { CampaignDTO } from "./infrastructure/campaigns/dtos.js";
|
|
2
3
|
export declare class Fuul {
|
|
3
|
-
private
|
|
4
|
-
private BASE_API_URL;
|
|
5
|
-
|
|
4
|
+
private readonly apiKey;
|
|
5
|
+
private readonly BASE_API_URL;
|
|
6
|
+
private readonly httpClient;
|
|
7
|
+
private campaignsService;
|
|
8
|
+
constructor(apiKey: string);
|
|
9
|
+
init(): void;
|
|
10
|
+
checkApiKey(): void;
|
|
6
11
|
/**
|
|
7
12
|
* @param {EventType} name Event name.
|
|
8
13
|
* @param {EventArgsType} args Event additional arguments.
|
|
@@ -10,7 +15,7 @@ export declare class Fuul {
|
|
|
10
15
|
* import { Fuul } from 'fuul-sdk'
|
|
11
16
|
*
|
|
12
17
|
* // Initialize Fuul in your app root file
|
|
13
|
-
* new Fuul('your-
|
|
18
|
+
* new Fuul('your-api-key')
|
|
14
19
|
*
|
|
15
20
|
* // Then you can send an event as follows:
|
|
16
21
|
* fuul.sendEvent('connect_wallet', {
|
|
@@ -29,6 +34,7 @@ export declare class Fuul {
|
|
|
29
34
|
* @returns {string} tracking link
|
|
30
35
|
*/
|
|
31
36
|
generateTrackingLink({ address, cid, baseUrl, }: IGenerateTrackingLink): string;
|
|
37
|
+
getCampaignById(campaignId: string): Promise<CampaignDTO>;
|
|
32
38
|
}
|
|
33
39
|
declare const _default: {
|
|
34
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":"AAkBA,OAAO,EACL,aAAa,EACb,SAAS,EACT,qBAAqB,EAEtB,MAAM,kBAAkB,CAAC;AAI1B,OAAO,EAAE,WAAW,EAAE,MAAM,oCAAoC,CAAC;AA2EjE,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,gBAAgB,CAAmB;gBAE/B,MAAM,EAAE,MAAM;IAkB1B,IAAI;IAMJ,WAAW,IAAI,IAAI;IAMnB;;;;;;;;;;;;;;;OAeG;IACG,SAAS,CAAC,IAAI,EAAE,SAAS,EAAE,IAAI,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,GAAG,CAAC;IAuDpE,gBAAgB,IAAI,IAAI;IAMxB;;;;;;OAMG;IACH,oBAAoB,CAAC,EACnB,OAAO,EACP,GAAG,EACH,OAAO,GACR,EAAE,qBAAqB,GAAG,MAAM;IAO3B,eAAe,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;CAGhE;;;;AAMD,wBAEE"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { HttpClient } from "../http/HttpClient.js";
|
|
2
|
+
import { CampaignDTO } from "./dtos.js";
|
|
3
|
+
export declare class CampaignsService {
|
|
4
|
+
private httpClient;
|
|
5
|
+
constructor(httpClient: HttpClient);
|
|
6
|
+
getCampaignyById(campaignId: string): Promise<CampaignDTO>;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=campaignsService.d.ts.map
|
|
@@ -0,0 +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;AAExC,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,UAAU,CAAa;gBAEnB,UAAU,EAAE,UAAU;IAI5B,gBAAgB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;CAWjE"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export interface Project {
|
|
2
|
+
id: string;
|
|
3
|
+
name: string;
|
|
4
|
+
thumbnail_url: string;
|
|
5
|
+
}
|
|
6
|
+
export interface ConversionDTO {
|
|
7
|
+
id: string;
|
|
8
|
+
payment_type: string;
|
|
9
|
+
referrer_amount: number;
|
|
10
|
+
referral_amount: number;
|
|
11
|
+
payment_currency: string;
|
|
12
|
+
triggers?: TriggerDTO[];
|
|
13
|
+
}
|
|
14
|
+
export interface TriggerDTO {
|
|
15
|
+
name: string;
|
|
16
|
+
description: string;
|
|
17
|
+
contracts?: ContractDTO[];
|
|
18
|
+
}
|
|
19
|
+
export interface ContractDTO {
|
|
20
|
+
address: string;
|
|
21
|
+
network: string;
|
|
22
|
+
}
|
|
23
|
+
export interface CampaignDTO {
|
|
24
|
+
conversions?: ConversionDTO[];
|
|
25
|
+
id: string;
|
|
26
|
+
name: string;
|
|
27
|
+
project: Project;
|
|
28
|
+
referrer_excerpt?: string;
|
|
29
|
+
url: string;
|
|
30
|
+
user_excerpt?: string;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=dtos.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dtos.d.ts","sourceRoot":"","sources":["../../../../../src/infrastructure/campaigns/dtos.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,OAAO;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,aAAa,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,aAAa;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,YAAY,EAAE,MAAM,CAAC;IACrB,eAAe,EAAE,MAAM,CAAC;IACxB,eAAe,EAAE,MAAM,CAAC;IACxB,gBAAgB,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,EAAE,UAAU,EAAE,CAAC;CACzB;AAED,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,WAAW,EAAE,CAAC;CAC3B;AAED,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,WAAW;IAC1B,WAAW,CAAC,EAAE,aAAa,EAAE,CAAC;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,OAAO,CAAC;IACjB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,GAAG,EAAE,MAAM,CAAC;IACZ,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { AxiosResponse, RawAxiosRequestHeaders } from "axios";
|
|
2
|
+
interface HttpClientOptions {
|
|
3
|
+
baseURL: string;
|
|
4
|
+
timeout: number;
|
|
5
|
+
apiKey?: string;
|
|
6
|
+
}
|
|
7
|
+
export interface HttpError {
|
|
8
|
+
message: string;
|
|
9
|
+
status?: number;
|
|
10
|
+
}
|
|
11
|
+
export declare class HttpClient {
|
|
12
|
+
private readonly client;
|
|
13
|
+
constructor(options: HttpClientOptions);
|
|
14
|
+
get<T>(path: string, params?: any): Promise<AxiosResponse<T>>;
|
|
15
|
+
post<T>(path: string, data: {
|
|
16
|
+
[key: string]: any;
|
|
17
|
+
}): Promise<AxiosResponse<T>>;
|
|
18
|
+
put<T>(path: string, data: {
|
|
19
|
+
[key: string]: any;
|
|
20
|
+
}): Promise<AxiosResponse<T>>;
|
|
21
|
+
delete<T>(path: string): Promise<AxiosResponse<T>>;
|
|
22
|
+
_getHeaders(apiKey: string): RawAxiosRequestHeaders;
|
|
23
|
+
}
|
|
24
|
+
export {};
|
|
25
|
+
//# sourceMappingURL=HttpClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HttpClient.d.ts","sourceRoot":"","sources":["../../../../../src/infrastructure/http/HttpClient.ts"],"names":[],"mappings":"AAAA,OAAc,EAEZ,aAAa,EACb,sBAAsB,EACvB,MAAM,OAAO,CAAC;AAEf,UAAU,iBAAiB;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,SAAS;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,qBAAa,UAAU;IACrB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAgB;gBAE3B,OAAO,EAAE,iBAAiB;IAOhC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;IAI7D,IAAI,CAAC,CAAC,EACV,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE;QACJ,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;KACpB,GACA,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;IAItB,GAAG,CAAC,CAAC,EACT,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE;QACJ,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;KACpB,GACA,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;IAItB,MAAM,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;IAIxD,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,sBAAsB;CAOpD"}
|
package/lib/esm/index.mjs
CHANGED
|
@@ -7,11 +7,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import axios from "axios";
|
|
11
10
|
import { nanoid } from "nanoid";
|
|
12
11
|
import { datesAreOnSameDay } from "./utils/date.js";
|
|
13
12
|
import { getCampaignId, getReferrerId, getSessionId, getTrackingId, } from "./utils/localStorage.js";
|
|
14
13
|
import { CAMPAIGN_ID_KEY, REFERRER_ID_KEY, SENT_EVENT_ID_KEY, SESSION_ID_KEY, TRACKING_ID_KEY, } from "./constants.js";
|
|
14
|
+
import { HttpClient } from "./infrastructure/http/HttpClient.js";
|
|
15
|
+
import { CampaignsService } from "./infrastructure/campaigns/campaignsService.js";
|
|
15
16
|
const saveSentEvent = (eventName, params) => {
|
|
16
17
|
const timestamp = Date.now();
|
|
17
18
|
const SENT_EVENT_KEY = `${SENT_EVENT_ID_KEY}_${eventName}`;
|
|
@@ -35,9 +36,7 @@ const isEventAlreadySentAndInValidTimestamp = (eventName, params) => {
|
|
|
35
36
|
isSameDay);
|
|
36
37
|
}
|
|
37
38
|
};
|
|
38
|
-
const generateRandomId = () =>
|
|
39
|
-
return nanoid();
|
|
40
|
-
};
|
|
39
|
+
const generateRandomId = () => nanoid();
|
|
41
40
|
const saveSessionId = () => {
|
|
42
41
|
if (typeof window === "undefined")
|
|
43
42
|
return;
|
|
@@ -65,13 +64,29 @@ const buildTrackingLinkQueryParams = (r, c) => {
|
|
|
65
64
|
return `c=${c}&origin=fuul&r=${r}`;
|
|
66
65
|
};
|
|
67
66
|
export class Fuul {
|
|
68
|
-
constructor(
|
|
69
|
-
this.BASE_API_URL = "https://api.fuul.xyz/api/v1";
|
|
70
|
-
this.
|
|
67
|
+
constructor(apiKey) {
|
|
68
|
+
this.BASE_API_URL = "https://api.fuul.xyz/api/v1/";
|
|
69
|
+
this.apiKey = apiKey;
|
|
70
|
+
this.checkApiKey();
|
|
71
71
|
saveSessionId();
|
|
72
72
|
saveTrackingId();
|
|
73
|
+
this.httpClient = new HttpClient({
|
|
74
|
+
baseURL: this.BASE_API_URL,
|
|
75
|
+
timeout: 10000,
|
|
76
|
+
apiKey: this.apiKey,
|
|
77
|
+
});
|
|
78
|
+
this.campaignsService = new CampaignsService(this.httpClient);
|
|
79
|
+
this.init();
|
|
80
|
+
}
|
|
81
|
+
init() {
|
|
82
|
+
this.sendEvent("pageview");
|
|
73
83
|
globalThis.Fuul = this;
|
|
74
84
|
}
|
|
85
|
+
checkApiKey() {
|
|
86
|
+
if (!this.apiKey) {
|
|
87
|
+
throw new Error("Fuul API key is required");
|
|
88
|
+
}
|
|
89
|
+
}
|
|
75
90
|
/**
|
|
76
91
|
* @param {EventType} name Event name.
|
|
77
92
|
* @param {EventArgsType} args Event additional arguments.
|
|
@@ -79,7 +94,7 @@ export class Fuul {
|
|
|
79
94
|
* import { Fuul } from 'fuul-sdk'
|
|
80
95
|
*
|
|
81
96
|
* // Initialize Fuul in your app root file
|
|
82
|
-
* new Fuul('your-
|
|
97
|
+
* new Fuul('your-api-key')
|
|
83
98
|
*
|
|
84
99
|
* // Then you can send an event as follows:
|
|
85
100
|
* fuul.sendEvent('connect_wallet', {
|
|
@@ -89,7 +104,6 @@ export class Fuul {
|
|
|
89
104
|
* ```
|
|
90
105
|
*/
|
|
91
106
|
sendEvent(name, args) {
|
|
92
|
-
var _a;
|
|
93
107
|
return __awaiter(this, void 0, void 0, function* () {
|
|
94
108
|
const session_id = getSessionId();
|
|
95
109
|
const tracking_id = getTrackingId();
|
|
@@ -116,21 +130,18 @@ export class Fuul {
|
|
|
116
130
|
reqBody = {
|
|
117
131
|
name,
|
|
118
132
|
session_id,
|
|
119
|
-
project_id: (_a = this.projectId) !== null && _a !== void 0 ? _a : args === null || args === void 0 ? void 0 : args.project_id,
|
|
120
133
|
event_args: Object.assign(Object.assign({}, args), { referrer: referrer_id, campaign_id,
|
|
121
134
|
tracking_id }),
|
|
122
135
|
};
|
|
123
136
|
}
|
|
124
137
|
if (isEventAlreadySentAndInValidTimestamp(name, params))
|
|
125
138
|
return;
|
|
126
|
-
const url = `${this.BASE_API_URL}/events`;
|
|
127
139
|
try {
|
|
128
|
-
|
|
140
|
+
yield this.httpClient.post("events", reqBody);
|
|
129
141
|
saveSentEvent(name, params);
|
|
130
|
-
return response.data;
|
|
131
142
|
}
|
|
132
143
|
catch (error) {
|
|
133
|
-
|
|
144
|
+
throw new Error(error.message);
|
|
134
145
|
}
|
|
135
146
|
});
|
|
136
147
|
}
|
|
@@ -149,6 +160,11 @@ export class Fuul {
|
|
|
149
160
|
generateTrackingLink({ address, cid, baseUrl, }) {
|
|
150
161
|
return `${baseUrl !== null && baseUrl !== void 0 ? baseUrl : window.location.href}?${buildTrackingLinkQueryParams(address, cid)}`;
|
|
151
162
|
}
|
|
163
|
+
getCampaignById(campaignId) {
|
|
164
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
165
|
+
return yield this.campaignsService.getCampaignyById(campaignId);
|
|
166
|
+
});
|
|
167
|
+
}
|
|
152
168
|
}
|
|
153
169
|
export default {
|
|
154
170
|
Fuul,
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
export class CampaignsService {
|
|
11
|
+
constructor(httpClient) {
|
|
12
|
+
this.httpClient = httpClient;
|
|
13
|
+
}
|
|
14
|
+
getCampaignyById(campaignId) {
|
|
15
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
try {
|
|
17
|
+
const { data } = yield this.httpClient.get(`/campaigns/${campaignId}`);
|
|
18
|
+
return data;
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
return error;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import axios from "axios";
|
|
11
|
+
export class HttpClient {
|
|
12
|
+
constructor(options) {
|
|
13
|
+
this.client = axios.create(Object.assign(Object.assign({}, options), { headers: options.apiKey ? this._getHeaders(options.apiKey) : {} }));
|
|
14
|
+
}
|
|
15
|
+
get(path, params) {
|
|
16
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
17
|
+
return this.client.get(path, { params });
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
post(path, data) {
|
|
21
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
+
return this.client.post(path, data);
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
put(path, data) {
|
|
26
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
+
return this.client.put(path, data);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
delete(path) {
|
|
31
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
+
return this.client.delete(path);
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
_getHeaders(apiKey) {
|
|
36
|
+
const headers = {};
|
|
37
|
+
headers.Authorization = `Bearer ${apiKey}`;
|
|
38
|
+
return headers;
|
|
39
|
+
}
|
|
40
|
+
}
|
package/lib/esm/types/index.d.ts
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import { EventArgsType, EventType, IGenerateTrackingLink } from "./types/types.js";
|
|
2
|
+
import { CampaignDTO } from "./infrastructure/campaigns/dtos.js";
|
|
2
3
|
export declare class Fuul {
|
|
3
|
-
private
|
|
4
|
-
private BASE_API_URL;
|
|
5
|
-
|
|
4
|
+
private readonly apiKey;
|
|
5
|
+
private readonly BASE_API_URL;
|
|
6
|
+
private readonly httpClient;
|
|
7
|
+
private campaignsService;
|
|
8
|
+
constructor(apiKey: string);
|
|
9
|
+
init(): void;
|
|
10
|
+
checkApiKey(): void;
|
|
6
11
|
/**
|
|
7
12
|
* @param {EventType} name Event name.
|
|
8
13
|
* @param {EventArgsType} args Event additional arguments.
|
|
@@ -10,7 +15,7 @@ export declare class Fuul {
|
|
|
10
15
|
* import { Fuul } from 'fuul-sdk'
|
|
11
16
|
*
|
|
12
17
|
* // Initialize Fuul in your app root file
|
|
13
|
-
* new Fuul('your-
|
|
18
|
+
* new Fuul('your-api-key')
|
|
14
19
|
*
|
|
15
20
|
* // Then you can send an event as follows:
|
|
16
21
|
* fuul.sendEvent('connect_wallet', {
|
|
@@ -29,6 +34,7 @@ export declare class Fuul {
|
|
|
29
34
|
* @returns {string} tracking link
|
|
30
35
|
*/
|
|
31
36
|
generateTrackingLink({ address, cid, baseUrl, }: IGenerateTrackingLink): string;
|
|
37
|
+
getCampaignById(campaignId: string): Promise<CampaignDTO>;
|
|
32
38
|
}
|
|
33
39
|
declare const _default: {
|
|
34
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":"AAkBA,OAAO,EACL,aAAa,EACb,SAAS,EACT,qBAAqB,EAEtB,MAAM,kBAAkB,CAAC;AAI1B,OAAO,EAAE,WAAW,EAAE,MAAM,oCAAoC,CAAC;AA2EjE,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,gBAAgB,CAAmB;gBAE/B,MAAM,EAAE,MAAM;IAkB1B,IAAI;IAMJ,WAAW,IAAI,IAAI;IAMnB;;;;;;;;;;;;;;;OAeG;IACG,SAAS,CAAC,IAAI,EAAE,SAAS,EAAE,IAAI,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,GAAG,CAAC;IAuDpE,gBAAgB,IAAI,IAAI;IAMxB;;;;;;OAMG;IACH,oBAAoB,CAAC,EACnB,OAAO,EACP,GAAG,EACH,OAAO,GACR,EAAE,qBAAqB,GAAG,MAAM;IAO3B,eAAe,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;CAGhE;;;;AAMD,wBAEE"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { HttpClient } from "../http/HttpClient.js";
|
|
2
|
+
import { CampaignDTO } from "./dtos.js";
|
|
3
|
+
export declare class CampaignsService {
|
|
4
|
+
private httpClient;
|
|
5
|
+
constructor(httpClient: HttpClient);
|
|
6
|
+
getCampaignyById(campaignId: string): Promise<CampaignDTO>;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=campaignsService.d.ts.map
|
|
@@ -0,0 +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;AAExC,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,UAAU,CAAa;gBAEnB,UAAU,EAAE,UAAU;IAI5B,gBAAgB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;CAWjE"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export interface Project {
|
|
2
|
+
id: string;
|
|
3
|
+
name: string;
|
|
4
|
+
thumbnail_url: string;
|
|
5
|
+
}
|
|
6
|
+
export interface ConversionDTO {
|
|
7
|
+
id: string;
|
|
8
|
+
payment_type: string;
|
|
9
|
+
referrer_amount: number;
|
|
10
|
+
referral_amount: number;
|
|
11
|
+
payment_currency: string;
|
|
12
|
+
triggers?: TriggerDTO[];
|
|
13
|
+
}
|
|
14
|
+
export interface TriggerDTO {
|
|
15
|
+
name: string;
|
|
16
|
+
description: string;
|
|
17
|
+
contracts?: ContractDTO[];
|
|
18
|
+
}
|
|
19
|
+
export interface ContractDTO {
|
|
20
|
+
address: string;
|
|
21
|
+
network: string;
|
|
22
|
+
}
|
|
23
|
+
export interface CampaignDTO {
|
|
24
|
+
conversions?: ConversionDTO[];
|
|
25
|
+
id: string;
|
|
26
|
+
name: string;
|
|
27
|
+
project: Project;
|
|
28
|
+
referrer_excerpt?: string;
|
|
29
|
+
url: string;
|
|
30
|
+
user_excerpt?: string;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=dtos.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dtos.d.ts","sourceRoot":"","sources":["../../../../../src/infrastructure/campaigns/dtos.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,OAAO;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,aAAa,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,aAAa;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,YAAY,EAAE,MAAM,CAAC;IACrB,eAAe,EAAE,MAAM,CAAC;IACxB,eAAe,EAAE,MAAM,CAAC;IACxB,gBAAgB,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,EAAE,UAAU,EAAE,CAAC;CACzB;AAED,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,WAAW,EAAE,CAAC;CAC3B;AAED,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,WAAW;IAC1B,WAAW,CAAC,EAAE,aAAa,EAAE,CAAC;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,OAAO,CAAC;IACjB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,GAAG,EAAE,MAAM,CAAC;IACZ,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { AxiosResponse, RawAxiosRequestHeaders } from "axios";
|
|
2
|
+
interface HttpClientOptions {
|
|
3
|
+
baseURL: string;
|
|
4
|
+
timeout: number;
|
|
5
|
+
apiKey?: string;
|
|
6
|
+
}
|
|
7
|
+
export interface HttpError {
|
|
8
|
+
message: string;
|
|
9
|
+
status?: number;
|
|
10
|
+
}
|
|
11
|
+
export declare class HttpClient {
|
|
12
|
+
private readonly client;
|
|
13
|
+
constructor(options: HttpClientOptions);
|
|
14
|
+
get<T>(path: string, params?: any): Promise<AxiosResponse<T>>;
|
|
15
|
+
post<T>(path: string, data: {
|
|
16
|
+
[key: string]: any;
|
|
17
|
+
}): Promise<AxiosResponse<T>>;
|
|
18
|
+
put<T>(path: string, data: {
|
|
19
|
+
[key: string]: any;
|
|
20
|
+
}): Promise<AxiosResponse<T>>;
|
|
21
|
+
delete<T>(path: string): Promise<AxiosResponse<T>>;
|
|
22
|
+
_getHeaders(apiKey: string): RawAxiosRequestHeaders;
|
|
23
|
+
}
|
|
24
|
+
export {};
|
|
25
|
+
//# sourceMappingURL=HttpClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HttpClient.d.ts","sourceRoot":"","sources":["../../../../../src/infrastructure/http/HttpClient.ts"],"names":[],"mappings":"AAAA,OAAc,EAEZ,aAAa,EACb,sBAAsB,EACvB,MAAM,OAAO,CAAC;AAEf,UAAU,iBAAiB;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,SAAS;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,qBAAa,UAAU;IACrB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAgB;gBAE3B,OAAO,EAAE,iBAAiB;IAOhC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;IAI7D,IAAI,CAAC,CAAC,EACV,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE;QACJ,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;KACpB,GACA,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;IAItB,GAAG,CAAC,CAAC,EACT,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE;QACJ,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;KACpB,GACA,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;IAItB,MAAM,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;IAIxD,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,sBAAsB;CAOpD"}
|