@fuul/sdk 0.7.1 → 0.8.1

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 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,28 @@ const buildTrackingLinkQueryParams = (r, c) => {
71
67
  return `c=${c}&origin=fuul&r=${r}`;
72
68
  };
73
69
  class Fuul {
74
- constructor(projectId) {
75
- this.BASE_API_URL = "https://api.fuul.xyz/api/v1";
76
- this.projectId = projectId;
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() {
79
85
  globalThis.Fuul = this;
80
86
  }
87
+ checkApiKey() {
88
+ if (!this.apiKey) {
89
+ throw new Error("Fuul API key is required");
90
+ }
91
+ }
81
92
  /**
82
93
  * @param {EventType} name Event name.
83
94
  * @param {EventArgsType} args Event additional arguments.
@@ -85,7 +96,7 @@ class Fuul {
85
96
  * import { Fuul } from 'fuul-sdk'
86
97
  *
87
98
  * // Initialize Fuul in your app root file
88
- * new Fuul('your-project-id')
99
+ * new Fuul('your-api-key')
89
100
  *
90
101
  * // Then you can send an event as follows:
91
102
  * fuul.sendEvent('connect_wallet', {
@@ -95,7 +106,6 @@ class Fuul {
95
106
  * ```
96
107
  */
97
108
  sendEvent(name, args) {
98
- var _a;
99
109
  return __awaiter(this, void 0, void 0, function* () {
100
110
  const session_id = (0, localStorage_js_1.getSessionId)();
101
111
  const tracking_id = (0, localStorage_js_1.getTrackingId)();
@@ -122,21 +132,18 @@ class Fuul {
122
132
  reqBody = {
123
133
  name,
124
134
  session_id,
125
- project_id: (_a = this.projectId) !== null && _a !== void 0 ? _a : args === null || args === void 0 ? void 0 : args.project_id,
126
135
  event_args: Object.assign(Object.assign({}, args), { referrer: referrer_id, campaign_id,
127
136
  tracking_id }),
128
137
  };
129
138
  }
130
139
  if (isEventAlreadySentAndInValidTimestamp(name, params))
131
140
  return;
132
- const url = `${this.BASE_API_URL}/events`;
133
141
  try {
134
- const response = yield axios_1.default.post(url, reqBody);
142
+ yield this.httpClient.post("events", reqBody);
135
143
  saveSentEvent(name, params);
136
- return response.data;
137
144
  }
138
145
  catch (error) {
139
- return error;
146
+ throw new Error(error.message);
140
147
  }
141
148
  });
142
149
  }
@@ -155,6 +162,11 @@ class Fuul {
155
162
  generateTrackingLink({ address, cid, baseUrl, }) {
156
163
  return `${baseUrl !== null && baseUrl !== void 0 ? baseUrl : window.location.href}?${buildTrackingLinkQueryParams(address, cid)}`;
157
164
  }
165
+ getCampaignById(campaignId) {
166
+ return __awaiter(this, void 0, void 0, function* () {
167
+ return yield this.campaignsService.getCampaignyById(campaignId);
168
+ });
169
+ }
158
170
  }
159
171
  exports.Fuul = Fuul;
160
172
  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,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -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;
@@ -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 projectId?;
4
- private BASE_API_URL;
5
- constructor(projectId?: string);
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-project-id')
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":"AAmBA,OAAO,EACL,aAAa,EACb,SAAS,EACT,qBAAqB,EAEtB,MAAM,kBAAkB,CAAC;AA6E1B,qBAAa,IAAI;IACf,OAAO,CAAC,SAAS,CAAC,CAAS;IAC3B,OAAO,CAAC,YAAY,CAAyC;gBAEjD,SAAS,CAAC,EAAE,MAAM;IAS9B;;;;;;;;;;;;;;;OAeG;IACG,SAAS,CAAC,IAAI,EAAE,SAAS,EAAE,IAAI,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,GAAG,CAAC;IA4DpE,gBAAgB,IAAI,IAAI;IAMxB;;;;;;OAMG;IACH,oBAAoB,CAAC,EACnB,OAAO,EACP,GAAG,EACH,OAAO,GACR,EAAE,qBAAqB,GAAG,MAAM;CAMlC;;;;AAMD,wBAEE"}
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;IAIJ,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,28 @@ const buildTrackingLinkQueryParams = (r, c) => {
65
64
  return `c=${c}&origin=fuul&r=${r}`;
66
65
  };
67
66
  export class Fuul {
68
- constructor(projectId) {
69
- this.BASE_API_URL = "https://api.fuul.xyz/api/v1";
70
- this.projectId = projectId;
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() {
73
82
  globalThis.Fuul = this;
74
83
  }
84
+ checkApiKey() {
85
+ if (!this.apiKey) {
86
+ throw new Error("Fuul API key is required");
87
+ }
88
+ }
75
89
  /**
76
90
  * @param {EventType} name Event name.
77
91
  * @param {EventArgsType} args Event additional arguments.
@@ -79,7 +93,7 @@ export class Fuul {
79
93
  * import { Fuul } from 'fuul-sdk'
80
94
  *
81
95
  * // Initialize Fuul in your app root file
82
- * new Fuul('your-project-id')
96
+ * new Fuul('your-api-key')
83
97
  *
84
98
  * // Then you can send an event as follows:
85
99
  * fuul.sendEvent('connect_wallet', {
@@ -89,7 +103,6 @@ export class Fuul {
89
103
  * ```
90
104
  */
91
105
  sendEvent(name, args) {
92
- var _a;
93
106
  return __awaiter(this, void 0, void 0, function* () {
94
107
  const session_id = getSessionId();
95
108
  const tracking_id = getTrackingId();
@@ -116,21 +129,18 @@ export class Fuul {
116
129
  reqBody = {
117
130
  name,
118
131
  session_id,
119
- project_id: (_a = this.projectId) !== null && _a !== void 0 ? _a : args === null || args === void 0 ? void 0 : args.project_id,
120
132
  event_args: Object.assign(Object.assign({}, args), { referrer: referrer_id, campaign_id,
121
133
  tracking_id }),
122
134
  };
123
135
  }
124
136
  if (isEventAlreadySentAndInValidTimestamp(name, params))
125
137
  return;
126
- const url = `${this.BASE_API_URL}/events`;
127
138
  try {
128
- const response = yield axios.post(url, reqBody);
139
+ yield this.httpClient.post("events", reqBody);
129
140
  saveSentEvent(name, params);
130
- return response.data;
131
141
  }
132
142
  catch (error) {
133
- return error;
143
+ throw new Error(error.message);
134
144
  }
135
145
  });
136
146
  }
@@ -149,6 +159,11 @@ export class Fuul {
149
159
  generateTrackingLink({ address, cid, baseUrl, }) {
150
160
  return `${baseUrl !== null && baseUrl !== void 0 ? baseUrl : window.location.href}?${buildTrackingLinkQueryParams(address, cid)}`;
151
161
  }
162
+ getCampaignById(campaignId) {
163
+ return __awaiter(this, void 0, void 0, function* () {
164
+ return yield this.campaignsService.getCampaignyById(campaignId);
165
+ });
166
+ }
152
167
  }
153
168
  export default {
154
169
  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
+ }
@@ -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 projectId?;
4
- private BASE_API_URL;
5
- constructor(projectId?: string);
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-project-id')
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":"AAmBA,OAAO,EACL,aAAa,EACb,SAAS,EACT,qBAAqB,EAEtB,MAAM,kBAAkB,CAAC;AA6E1B,qBAAa,IAAI;IACf,OAAO,CAAC,SAAS,CAAC,CAAS;IAC3B,OAAO,CAAC,YAAY,CAAyC;gBAEjD,SAAS,CAAC,EAAE,MAAM;IAS9B;;;;;;;;;;;;;;;OAeG;IACG,SAAS,CAAC,IAAI,EAAE,SAAS,EAAE,IAAI,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,GAAG,CAAC;IA4DpE,gBAAgB,IAAI,IAAI;IAMxB;;;;;;OAMG;IACH,oBAAoB,CAAC,EACnB,OAAO,EACP,GAAG,EACH,OAAO,GACR,EAAE,qBAAqB,GAAG,MAAM;CAMlC;;;;AAMD,wBAEE"}
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;IAIJ,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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fuul/sdk",
3
- "version": "0.7.1",
3
+ "version": "0.8.1",
4
4
  "type": "module",
5
5
  "description": "Fuul SDK",
6
6
  "types": "./lib/esm/types/index.d.ts",