Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@masa-finance/analytics-sdk

Package Overview
Dependencies
Maintainers
5
Versions
45
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@masa-finance/analytics-sdk - npm Package Compare versions

Comparing version 0.0.5 to 0.0.6

2

dist/package.json
{
"name": "@masa-finance/analytics-sdk",
"version": "0.0.5",
"version": "0.0.6",
"main": "dist/src/index.js",

@@ -5,0 +5,0 @@ "license": "MIT",

@@ -11,2 +11,29 @@ "use strict";

};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (g && (g = 0, op[0] && (_ = 0)), _) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
var __importDefault = (this && this.__importDefault) || function (mod) {

@@ -17,43 +44,54 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

exports.logEvent = void 0;
const axios_1 = __importDefault(require("axios"));
const config_1 = require("./config");
const client = axios_1.default.create({
var axios_1 = __importDefault(require("axios"));
var config_1 = require("./config");
var client = axios_1.default.create({
baseURL: config_1.API_URL,
});
const logEvent = ({ type, user_address, client_id, event_data, endpoint, }) => __awaiter(void 0, void 0, void 0, function* () {
try {
const event = {
type,
user_address,
client_id,
timestamp: new Date(),
event_data,
};
const { status, statusText, data: responseData, } = yield client.post(`/${endpoint}`, event, {
headers: {
"Content-Type": "application/json",
},
var logEvent = function (_a) {
var type = _a.type, user_address = _a.user_address, client_id = _a.client_id, event_data = _a.event_data, endpoint = _a.endpoint;
return __awaiter(void 0, void 0, void 0, function () {
var event_1, _b, status_1, statusText, responseData, error_1;
return __generator(this, function (_c) {
switch (_c.label) {
case 0:
_c.trys.push([0, 2, , 3]);
event_1 = {
type: type,
user_address: user_address,
client_id: client_id,
timestamp: new Date(),
event_data: event_data,
};
return [4 /*yield*/, client.post("/".concat(endpoint), event_1, {
headers: {
"Content-Type": "application/json",
},
})];
case 1:
_b = _c.sent(), status_1 = _b.status, statusText = _b.statusText, responseData = _b.data;
if (
// ok
status_1 === 200 ||
// Created
status_1 === 201 ||
// Accepted
status_1 === 202) {
// eslint-disable-next-line no-console
console.log("".concat(type, " Event logged successfully"));
return [2 /*return*/, responseData];
}
// eslint-disable-next-line no-console
console.error("API error: ".concat(statusText));
return [2 /*return*/, undefined];
case 2:
error_1 = _c.sent();
// eslint-disable-next-line no-console
console.error("Error logging event:", error_1);
throw error_1;
case 3: return [2 /*return*/];
}
});
if (
// ok
status === 200 ||
// Created
status === 201 ||
// Accepted
status === 202) {
// eslint-disable-next-line no-console
console.log(`${type} Event logged successfully`);
return responseData;
}
// eslint-disable-next-line no-console
console.error(`API error: ${statusText}`);
return undefined;
}
catch (error) {
// eslint-disable-next-line no-console
console.error("Error logging event:", error);
throw error;
}
});
});
};
exports.logEvent = logEvent;
//# sourceMappingURL=event-logger.js.map
"use strict";
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

@@ -11,7 +22,34 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }

};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (g && (g = 0, op[0] && (_ = 0)), _) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.MasaAnalytics = void 0;
const event_logger_1 = require("./event-logger");
class MasaAnalytics {
constructor(config) {
var event_logger_1 = require("./event-logger");
var MasaAnalytics = /** @class */ (function () {
function MasaAnalytics(config) {
this.config = config;

@@ -22,112 +60,164 @@ }

*/
fireLoginEvent({ user_address }) {
return __awaiter(this, void 0, void 0, function* () {
const event_data = {
description: "User logged in",
client_app: this.config.clientApp,
client_name: this.config.clientName,
};
try {
yield (0, event_logger_1.logEvent)({
type: "login",
client_id: this.config.clientId,
user_address,
event_data,
endpoint: "tracking",
});
}
catch (error) {
// eslint-disable-next-line no-console
console.error("fireLoginEvent():", error);
}
MasaAnalytics.prototype.fireLoginEvent = function (_a) {
var user_address = _a.user_address;
return __awaiter(this, void 0, void 0, function () {
var event_data, error_1;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
event_data = {
description: "User logged in",
client_app: this.config.clientApp,
client_name: this.config.clientName,
};
_b.label = 1;
case 1:
_b.trys.push([1, 3, , 4]);
return [4 /*yield*/, (0, event_logger_1.logEvent)({
type: "login",
client_id: this.config.clientId,
user_address: user_address,
event_data: event_data,
endpoint: "tracking",
})];
case 2:
_b.sent();
return [3 /*break*/, 4];
case 3:
error_1 = _b.sent();
// eslint-disable-next-line no-console
console.error("fireLoginEvent():", error_1);
return [3 /*break*/, 4];
case 4: return [2 /*return*/];
}
});
});
}
};
/**
* Fire an event once the user changes the page
*/
firePageViewEvent({ page, user_address, }) {
return __awaiter(this, void 0, void 0, function* () {
const event_data = {
client_app: this.config.clientApp,
client_name: this.config.clientName,
page,
};
try {
yield (0, event_logger_1.logEvent)({
type: "pageView",
client_id: this.config.clientId,
user_address,
event_data,
endpoint: "tracking",
});
}
catch (error) {
// eslint-disable-next-line no-console
console.error("firePageViewEvent():", error);
}
MasaAnalytics.prototype.firePageViewEvent = function (_a) {
var page = _a.page, user_address = _a.user_address;
return __awaiter(this, void 0, void 0, function () {
var event_data, error_2;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
event_data = {
client_app: this.config.clientApp,
client_name: this.config.clientName,
page: page,
};
_b.label = 1;
case 1:
_b.trys.push([1, 3, , 4]);
return [4 /*yield*/, (0, event_logger_1.logEvent)({
type: "pageView",
client_id: this.config.clientId,
user_address: user_address,
event_data: event_data,
endpoint: "tracking",
})];
case 2:
_b.sent();
return [3 /*break*/, 4];
case 3:
error_2 = _b.sent();
// eslint-disable-next-line no-console
console.error("firePageViewEvent():", error_2);
return [3 /*break*/, 4];
case 4: return [2 /*return*/];
}
});
});
}
};
/**
* Fire an event once a user tries to mint a token
*/
fireMintEvent({ user_address, token_name, ticker, token_type, network, contract_address, mint_fee, mint_currency, fee_asset, asset_amount, additionalEventData, }) {
return __awaiter(this, void 0, void 0, function* () {
const event_data = {
client_app: this.config.clientApp,
client_name: this.config.clientName,
token_name,
ticker,
token_type,
network,
contract_address,
mint_fee,
mint_currency,
fee_asset,
asset_amount,
};
try {
yield (0, event_logger_1.logEvent)({
type: "mint",
user_address,
client_id: this.config.clientId,
event_data: Object.assign(Object.assign({}, event_data), additionalEventData),
endpoint: "tracking",
});
}
catch (error) {
// eslint-disable-next-line no-console
console.error("fireMintEvent():", error);
}
MasaAnalytics.prototype.fireMintEvent = function (_a) {
var user_address = _a.user_address, token_name = _a.token_name, ticker = _a.ticker, token_type = _a.token_type, network = _a.network, contract_address = _a.contract_address, mint_fee = _a.mint_fee, mint_currency = _a.mint_currency, fee_asset = _a.fee_asset, asset_amount = _a.asset_amount, additionalEventData = _a.additionalEventData;
return __awaiter(this, void 0, void 0, function () {
var event_data, error_3;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
event_data = {
client_app: this.config.clientApp,
client_name: this.config.clientName,
token_name: token_name,
ticker: ticker,
token_type: token_type,
network: network,
contract_address: contract_address,
mint_fee: mint_fee,
mint_currency: mint_currency,
fee_asset: fee_asset,
asset_amount: asset_amount,
};
_b.label = 1;
case 1:
_b.trys.push([1, 3, , 4]);
return [4 /*yield*/, (0, event_logger_1.logEvent)({
type: "mint",
user_address: user_address,
client_id: this.config.clientId,
event_data: __assign(__assign({}, event_data), additionalEventData),
endpoint: "tracking",
})];
case 2:
_b.sent();
return [3 /*break*/, 4];
case 3:
error_3 = _b.sent();
// eslint-disable-next-line no-console
console.error("fireMintEvent():", error_3);
return [3 /*break*/, 4];
case 4: return [2 /*return*/];
}
});
});
}
};
/**
* Fire an event once a user tries to mint a token
*/
fireConnectWalletEvent({ user_address, wallet_type, }) {
return __awaiter(this, void 0, void 0, function* () {
const event_data = {
client_app: this.config.clientApp,
client_name: this.config.clientName,
wallet_type,
// token_name,
// ticker,
// token_type,
// network,
// contract_address,
};
try {
yield (0, event_logger_1.logEvent)({
type: "connectWallet",
user_address,
client_id: this.config.clientId,
event_data,
endpoint: "tracking",
});
}
catch (error) {
// eslint-disable-next-line no-console
console.error("fireMintEvent():", error);
}
MasaAnalytics.prototype.fireConnectWalletEvent = function (_a) {
var user_address = _a.user_address, wallet_type = _a.wallet_type;
return __awaiter(this, void 0, void 0, function () {
var event_data, error_4;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
event_data = {
client_app: this.config.clientApp,
client_name: this.config.clientName,
wallet_type: wallet_type,
// token_name,
// ticker,
// token_type,
// network,
// contract_address,
};
_b.label = 1;
case 1:
_b.trys.push([1, 3, , 4]);
return [4 /*yield*/, (0, event_logger_1.logEvent)({
type: "connectWallet",
user_address: user_address,
client_id: this.config.clientId,
event_data: event_data,
endpoint: "tracking",
})];
case 2:
_b.sent();
return [3 /*break*/, 4];
case 3:
error_4 = _b.sent();
// eslint-disable-next-line no-console
console.error("fireMintEvent():", error_4);
return [3 /*break*/, 4];
case 4: return [2 /*return*/];
}
});
});
}
};
/**

@@ -137,30 +227,44 @@ * Fire a flexible event

*/
fireEvent(type, { user_address, network, contract_address, asset_amount, asset_ticker, additionalEventData, }) {
return __awaiter(this, void 0, void 0, function* () {
const event_data = {
client_app: this.config.clientApp,
client_name: this.config.clientName,
user_address,
network,
contract_address,
asset_amount,
asset_ticker,
};
try {
yield (0, event_logger_1.logEvent)({
type: type,
user_address,
client_id: this.config.clientId,
event_data: Object.assign(Object.assign({}, event_data), additionalEventData),
endpoint: "tracking",
});
}
catch (error) {
// eslint-disable-next-line no-console
console.error("fireEvent():", error);
}
MasaAnalytics.prototype.fireEvent = function (type, _a) {
var user_address = _a.user_address, network = _a.network, contract_address = _a.contract_address, asset_amount = _a.asset_amount, asset_ticker = _a.asset_ticker, additionalEventData = _a.additionalEventData;
return __awaiter(this, void 0, void 0, function () {
var event_data, error_5;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
event_data = {
client_app: this.config.clientApp,
client_name: this.config.clientName,
user_address: user_address,
network: network,
contract_address: contract_address,
asset_amount: asset_amount,
asset_ticker: asset_ticker,
};
_b.label = 1;
case 1:
_b.trys.push([1, 3, , 4]);
return [4 /*yield*/, (0, event_logger_1.logEvent)({
type: type,
user_address: user_address,
client_id: this.config.clientId,
event_data: __assign(__assign({}, event_data), additionalEventData),
endpoint: "tracking",
})];
case 2:
_b.sent();
return [3 /*break*/, 4];
case 3:
error_5 = _b.sent();
// eslint-disable-next-line no-console
console.error("fireEvent():", error_5);
return [3 /*break*/, 4];
case 4: return [2 /*return*/];
}
});
});
}
}
};
return MasaAnalytics;
}());
exports.MasaAnalytics = MasaAnalytics;
//# sourceMappingURL=masa-analytics.js.map

@@ -11,31 +11,61 @@ "use strict";

};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (g && (g = 0, op[0] && (_ = 0)), _) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.generateSignature = void 0;
const uuid_1 = require("uuid");
var uuid_1 = require("uuid");
// Function to generate a random nonce using a UUID
const generateRandomNonce = () => {
var generateRandomNonce = function () {
return (0, uuid_1.v4)();
};
const generateSignature = (wallet, client_app, client_name) => __awaiter(void 0, void 0, void 0, function* () {
// Generate a unique nonce
const nonce = generateRandomNonce();
// Log the generated nonce
console.log("Nonce:", nonce);
// Request body
const requestBody = {
client_app,
client_name,
};
// Convert the request body to a string
const requestBodyString = JSON.stringify(requestBody);
// Construct the message to sign, including the nonce and request body
const message = `Please sign this message to confirm your request. Nonce: ${nonce}. Request Body: ${requestBodyString}`;
// Sign the message
const signature = yield wallet.signMessage(message);
return {
message,
signature,
};
});
var generateSignature = function (wallet, client_app, client_name) { return __awaiter(void 0, void 0, void 0, function () {
var nonce, requestBody, requestBodyString, message, signature;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
nonce = generateRandomNonce();
// Log the generated nonce
console.log("Nonce:", nonce);
requestBody = {
client_app: client_app,
client_name: client_name,
};
requestBodyString = JSON.stringify(requestBody);
message = "Please sign this message to confirm your request. Nonce: ".concat(nonce, ". Request Body: ").concat(requestBodyString);
return [4 /*yield*/, wallet.signMessage(message)];
case 1:
signature = _a.sent();
return [2 /*return*/, {
message: message,
signature: signature,
}];
}
});
}); };
exports.generateSignature = generateSignature;
//# sourceMappingURL=tools.js.map
{
"name": "@masa-finance/analytics-sdk",
"version": "0.0.5",
"version": "0.0.6",
"main": "dist/src/index.js",

@@ -5,0 +5,0 @@ "license": "MIT",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc