@fuul/sdk 0.5.0 → 0.6.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 CHANGED
@@ -2,23 +2,23 @@
2
2
 
3
3
  **Setting up the Fuul SDK**
4
4
 
5
- ## **1. Install the Fuul SDK**
5
+ ## 1. Install the Fuul SDK
6
6
 
7
7
  Run one of the following commands to add Fuul SDK to your project:
8
8
 
9
9
  ### npm
10
10
 
11
11
  ```bash
12
- npm install fuul-sdk
12
+ npm install @fuul/sdk
13
13
  ```
14
14
 
15
15
  ### yarn
16
16
 
17
17
  ```bash
18
- yarn add fuul-sdk
18
+ yarn add @fuul/sdk
19
19
  ```
20
20
 
21
- ## 2**. Set up the Fuul SDK**
21
+ ## 2. Set up the Fuul SDK
22
22
 
23
23
  In order to authenticate to full with your project, you must execute the following in the root file of your app.
24
24
 
@@ -37,7 +37,7 @@ By this way, you’ll be available to use Fuul as a global object in any of your
37
37
 
38
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)
39
39
 
40
- ## 3**. Verifying the connection to Fuul SDK**
40
+ ## 3. Verifying the connection to Fuul SDK
41
41
 
42
42
  You can verify that everything was set up successfully with the following method
43
43
 
@@ -49,7 +49,7 @@ If everything is ok, you will see a prompt as below:
49
49
 
50
50
  ![Untitled](Getting%20started%20with%20Fuul%20SDK%205855c088f6d14fcf9dca9d3a13e9bd86/Untitled.png)
51
51
 
52
- ## 4**. Sending events**
52
+ ## 4. Sending events
53
53
 
54
54
  In order to send events such as `pageview` or `connect_wallet` you must do the following
55
55
 
@@ -83,7 +83,7 @@ const handlePageView = async () => {
83
83
  }
84
84
  ```
85
85
 
86
- ## 5**. Generating tracking links**
86
+ ## 5. Generating tracking links
87
87
 
88
88
  You can also generate the tracking link for a given wallet `address` and `campaign id`
89
89
 
package/lib/cjs/index.js CHANGED
@@ -1,27 +1,4 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
3
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
4
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -37,22 +14,23 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
37
14
  Object.defineProperty(exports, "__esModule", { value: true });
38
15
  exports.Fuul = void 0;
39
16
  const axios_1 = __importDefault(require("axios"));
40
- const date_1 = require("./utils/date");
41
- const localStorage_1 = require("./utils/localStorage");
42
- const constants_1 = require("./constants");
17
+ const nanoid_1 = require("nanoid");
18
+ const date_js_1 = require("./utils/date.js");
19
+ const localStorage_js_1 = require("./utils/localStorage.js");
20
+ const constants_js_1 = require("./constants.js");
43
21
  const saveSentEvent = (eventName, params) => {
44
22
  const timestamp = Date.now();
45
- const SENT_EVENT_KEY = `${constants_1.SENT_EVENT_ID_KEY}_${eventName}`;
23
+ const SENT_EVENT_KEY = `${constants_js_1.SENT_EVENT_ID_KEY}_${eventName}`;
46
24
  const eventParams = Object.assign(Object.assign({}, params), { timestamp });
47
25
  localStorage.setItem(SENT_EVENT_KEY, JSON.stringify(eventParams));
48
26
  };
49
27
  const isEventAlreadySentAndInValidTimestamp = (eventName, params) => {
50
- const SENT_EVENT_KEY = `${constants_1.SENT_EVENT_ID_KEY}_${eventName}`;
28
+ const SENT_EVENT_KEY = `${constants_js_1.SENT_EVENT_ID_KEY}_${eventName}`;
51
29
  const storedEvent = localStorage.getItem(SENT_EVENT_KEY);
52
30
  if (!storedEvent)
53
31
  return false;
54
32
  const parsedEvent = JSON.parse(storedEvent);
55
- const isSameDay = (0, date_1.datesAreOnSameDay)(new Date(Date.now()), new Date(parsedEvent.timestamp));
33
+ const isSameDay = (0, date_js_1.datesAreOnSameDay)(new Date(Date.now()), new Date(parsedEvent.timestamp));
56
34
  if (eventName === "connect_wallet") {
57
35
  return parsedEvent["tracking_id"] === params.tracking_id && isSameDay;
58
36
  }
@@ -63,16 +41,15 @@ const isEventAlreadySentAndInValidTimestamp = (eventName, params) => {
63
41
  isSameDay);
64
42
  }
65
43
  };
66
- const generateRandomId = () => __awaiter(void 0, void 0, void 0, function* () {
67
- const nanoid = yield Promise.resolve().then(() => __importStar(require("nanoid"))).then((m) => m.nanoid);
68
- return nanoid();
69
- });
70
- const saveSessionId = () => __awaiter(void 0, void 0, void 0, function* () {
44
+ const generateRandomId = () => {
45
+ return (0, nanoid_1.nanoid)();
46
+ };
47
+ const saveSessionId = () => {
71
48
  if (typeof window === "undefined")
72
49
  return;
73
- localStorage.setItem(constants_1.SESSION_ID_KEY, yield generateRandomId());
74
- });
75
- const saveTrackingId = () => __awaiter(void 0, void 0, void 0, function* () {
50
+ localStorage.setItem(constants_js_1.SESSION_ID_KEY, generateRandomId());
51
+ };
52
+ const saveTrackingId = () => {
76
53
  var _a, _b;
77
54
  if (typeof window === "undefined" || typeof document === "undefined")
78
55
  return;
@@ -84,12 +61,12 @@ const saveTrackingId = () => __awaiter(void 0, void 0, void 0, function* () {
84
61
  const isFuulOrigin = queryParams.get("origin") === "fuul";
85
62
  if (!isFuulOrigin)
86
63
  return;
87
- if (!(0, localStorage_1.getTrackingId)()) {
88
- localStorage.setItem(constants_1.TRACKING_ID_KEY, yield generateRandomId());
64
+ if (!(0, localStorage_js_1.getTrackingId)()) {
65
+ localStorage.setItem(constants_js_1.TRACKING_ID_KEY, generateRandomId());
89
66
  }
90
- localStorage.setItem(constants_1.CAMPAIGN_ID_KEY, (_a = queryParams.get("c")) !== null && _a !== void 0 ? _a : "");
91
- localStorage.setItem(constants_1.REFERRER_ID_KEY, (_b = queryParams.get("r")) !== null && _b !== void 0 ? _b : "");
92
- });
67
+ localStorage.setItem(constants_js_1.CAMPAIGN_ID_KEY, (_a = queryParams.get("c")) !== null && _a !== void 0 ? _a : "");
68
+ localStorage.setItem(constants_js_1.REFERRER_ID_KEY, (_b = queryParams.get("r")) !== null && _b !== void 0 ? _b : "");
69
+ };
93
70
  const buildTrackingLinkQueryParams = (r, c) => {
94
71
  return `c=${c}&origin=fuul&r=${r}`;
95
72
  };
@@ -120,10 +97,10 @@ class Fuul {
120
97
  sendEvent(name, args) {
121
98
  var _a;
122
99
  return __awaiter(this, void 0, void 0, function* () {
123
- const session_id = (0, localStorage_1.getSessionId)();
124
- const tracking_id = (0, localStorage_1.getTrackingId)();
125
- const campaign_id = (0, localStorage_1.getCampaignId)();
126
- const referrer_id = (0, localStorage_1.getReferrerId)();
100
+ const session_id = (0, localStorage_js_1.getSessionId)();
101
+ const tracking_id = (0, localStorage_js_1.getTrackingId)();
102
+ const campaign_id = (0, localStorage_js_1.getCampaignId)();
103
+ const referrer_id = (0, localStorage_js_1.getReferrerId)();
127
104
  if (!tracking_id)
128
105
  return;
129
106
  let params = {
@@ -1,4 +1,4 @@
1
- import { EventArgsType, EventType, IGenerateTrackingLink } from "./types/types";
1
+ import { EventArgsType, EventType, IGenerateTrackingLink } from "./types/types.js";
2
2
  export declare class Fuul {
3
3
  private projectId?;
4
4
  private BASE_API_URL;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAkBA,OAAO,EACL,aAAa,EACb,SAAS,EACT,qBAAqB,EAEtB,MAAM,eAAe,CAAC;AA+EvB,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":"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,12 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getReferrerId = exports.getCampaignId = exports.getTrackingId = exports.getSessionId = void 0;
4
- const constants_1 = require("../constants");
5
- const getSessionId = () => localStorage.getItem(constants_1.SESSION_ID_KEY);
4
+ const constants_js_1 = require("../constants.js");
5
+ const getSessionId = () => localStorage.getItem(constants_js_1.SESSION_ID_KEY);
6
6
  exports.getSessionId = getSessionId;
7
- const getTrackingId = () => localStorage.getItem(constants_1.TRACKING_ID_KEY);
7
+ const getTrackingId = () => localStorage.getItem(constants_js_1.TRACKING_ID_KEY);
8
8
  exports.getTrackingId = getTrackingId;
9
- const getCampaignId = () => localStorage.getItem(constants_1.CAMPAIGN_ID_KEY);
9
+ const getCampaignId = () => localStorage.getItem(constants_js_1.CAMPAIGN_ID_KEY);
10
10
  exports.getCampaignId = getCampaignId;
11
- const getReferrerId = () => localStorage.getItem(constants_1.REFERRER_ID_KEY);
11
+ const getReferrerId = () => localStorage.getItem(constants_js_1.REFERRER_ID_KEY);
12
12
  exports.getReferrerId = getReferrerId;
package/lib/esm/index.mjs CHANGED
@@ -8,9 +8,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import axios from "axios";
11
- import { datesAreOnSameDay } from "./utils/date";
12
- import { getCampaignId, getReferrerId, getSessionId, getTrackingId, } from "./utils/localStorage";
13
- import { CAMPAIGN_ID_KEY, REFERRER_ID_KEY, SENT_EVENT_ID_KEY, SESSION_ID_KEY, TRACKING_ID_KEY, } from "./constants";
11
+ import { nanoid } from "nanoid";
12
+ import { datesAreOnSameDay } from "./utils/date.js";
13
+ import { getCampaignId, getReferrerId, getSessionId, getTrackingId, } from "./utils/localStorage.js";
14
+ import { CAMPAIGN_ID_KEY, REFERRER_ID_KEY, SENT_EVENT_ID_KEY, SESSION_ID_KEY, TRACKING_ID_KEY, } from "./constants.js";
14
15
  const saveSentEvent = (eventName, params) => {
15
16
  const timestamp = Date.now();
16
17
  const SENT_EVENT_KEY = `${SENT_EVENT_ID_KEY}_${eventName}`;
@@ -34,16 +35,15 @@ const isEventAlreadySentAndInValidTimestamp = (eventName, params) => {
34
35
  isSameDay);
35
36
  }
36
37
  };
37
- const generateRandomId = () => __awaiter(void 0, void 0, void 0, function* () {
38
- const nanoid = yield import("nanoid").then((m) => m.nanoid);
38
+ const generateRandomId = () => {
39
39
  return nanoid();
40
- });
41
- const saveSessionId = () => __awaiter(void 0, void 0, void 0, function* () {
40
+ };
41
+ const saveSessionId = () => {
42
42
  if (typeof window === "undefined")
43
43
  return;
44
- localStorage.setItem(SESSION_ID_KEY, yield generateRandomId());
45
- });
46
- const saveTrackingId = () => __awaiter(void 0, void 0, void 0, function* () {
44
+ localStorage.setItem(SESSION_ID_KEY, generateRandomId());
45
+ };
46
+ const saveTrackingId = () => {
47
47
  var _a, _b;
48
48
  if (typeof window === "undefined" || typeof document === "undefined")
49
49
  return;
@@ -56,11 +56,11 @@ const saveTrackingId = () => __awaiter(void 0, void 0, void 0, function* () {
56
56
  if (!isFuulOrigin)
57
57
  return;
58
58
  if (!getTrackingId()) {
59
- localStorage.setItem(TRACKING_ID_KEY, yield generateRandomId());
59
+ localStorage.setItem(TRACKING_ID_KEY, generateRandomId());
60
60
  }
61
61
  localStorage.setItem(CAMPAIGN_ID_KEY, (_a = queryParams.get("c")) !== null && _a !== void 0 ? _a : "");
62
62
  localStorage.setItem(REFERRER_ID_KEY, (_b = queryParams.get("r")) !== null && _b !== void 0 ? _b : "");
63
- });
63
+ };
64
64
  const buildTrackingLinkQueryParams = (r, c) => {
65
65
  return `c=${c}&origin=fuul&r=${r}`;
66
66
  };
@@ -1,4 +1,4 @@
1
- import { EventArgsType, EventType, IGenerateTrackingLink } from "./types/types";
1
+ import { EventArgsType, EventType, IGenerateTrackingLink } from "./types/types.js";
2
2
  export declare class Fuul {
3
3
  private projectId?;
4
4
  private BASE_API_URL;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAkBA,OAAO,EACL,aAAa,EACb,SAAS,EACT,qBAAqB,EAEtB,MAAM,eAAe,CAAC;AA+EvB,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":"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,4 +1,4 @@
1
- import { CAMPAIGN_ID_KEY, REFERRER_ID_KEY, SESSION_ID_KEY, TRACKING_ID_KEY, } from "../constants";
1
+ import { CAMPAIGN_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
4
  export const getCampaignId = () => localStorage.getItem(CAMPAIGN_ID_KEY);
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@fuul/sdk",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
+ "type": "module",
4
5
  "description": "Fuul SDK",
5
6
  "types": "./lib/esm/types/index.d.ts",
6
7
  "main": "./lib/esm/index.mjs",