Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Lu Nguyen committed Dec 6, 2023
2 parents 3ffaf41 + 1621254 commit f3342b2
Show file tree
Hide file tree
Showing 18 changed files with 755 additions and 5 deletions.
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "aesirx-lib",
"version": "2.0.2",
"version": "2.0.3",
"license": "GPL-3.0-only",
"author": "AesirX",
"repository": "https://github.com/aesirxio/aesirx-lib",
Expand All @@ -13,6 +13,7 @@
"date-fns": "^2.30.0",
"date-fns-tz": "^2.0.0",
"moment": "^2.29.4",
"murmurhash-js": "^1.0.0",
"query-string": "7",
"react-secure-storage": "^1.2.2"
},
Expand Down Expand Up @@ -45,7 +46,8 @@
"prettier": "^2.8.8",
"ts-jest": "^29.1.1",
"tsup": "^6.7.0",
"typescript": "^5.0.4"
"typescript": "^5.0.4",
"@types/murmurhash-js": "^1.0.3"
},
"files": [
"dist"
Expand Down
5 changes: 5 additions & 0 deletions src/Authentication/Authentication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,15 @@ class AesirxAuthenticationApiService {
let tokenType = '';
let accessToken = '';
let refreshToken = '';
let jwt = '';

if (tokenRefreshResponse && tokenRefreshResponse.data) {
tokenType = tokenRefreshResponse.data.token_type ?? 'Bearer';
accessToken = tokenRefreshResponse.data.access_token ?? '';
authorizationHeader = authorizationHeader.concat(tokenType).concat(' ').concat(accessToken);
refreshToken = tokenRefreshResponse.data[AUTHORIZATION_KEY.REFRESH_TOKEN] ?? '';
jwt = tokenRefreshResponse.data[AUTHORIZATION_KEY.JWT] ?? '';
const isJwtChange = jwt !== this.getStore(AUTHORIZATION_KEY.JWT);
if (process.env.NODE_ENV === 'test') {
return tokenRefreshResponse.data;
} else {
Expand All @@ -185,8 +188,10 @@ class AesirxAuthenticationApiService {
[key[AUTHORIZATION_KEY.TOKEN_TYPE]]: tokenType,
[key[AUTHORIZATION_KEY.AUTHORIZED_TOKEN_HEADER]]: authorizationHeader,
[key[AUTHORIZATION_KEY.REFRESH_TOKEN]]: refreshToken,
[key[AUTHORIZATION_KEY.JWT]]: jwt,
};
this.setStore(setStore);
process.env.REACT_APP_HEADER_JWT === 'true' && isJwtChange && location.reload();
}
} else {
return logout();
Expand Down
2 changes: 1 addition & 1 deletion src/Authentication/Logout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const logout = () => {
return 'logout';
} else {
localStorage.clear();
window.location.reload();
typeof window !== 'undefined' && window.location.reload();
}
};

Expand Down
97 changes: 97 additions & 0 deletions src/Bi/Bi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import {
BrowsersModel,
CitiesModel,
ConsentsDateModel,
ConsentsListModel,
ConsentsTierModel,
CountriesModel,
DevicesModel,
DomainModel,
Expand All @@ -14,6 +17,7 @@ import {
LanguagesModel,
MetricsModel,
PagesModel,
RefererModel,
SummaryModel,
VisitorModel,
VisitorsModel,
Expand Down Expand Up @@ -502,6 +506,99 @@ class AesirxBiApiService {
} else throw error;
}
};
getConsentsList = async (dataFilter: any, dateFilter: any) => {
try {
const data = await this.route.getConsentsList(dataFilter, dateFilter);

let results = null;
let pagination = null;
if (data) {
results = new ConsentsListModel(data);
pagination = results.getBiPagination();
}
if (results) {
results = results.toJSON();
}
return {
list: results,
pagination: pagination,
};
} catch (error) {
if (axios.isCancel(error)) {
return { message: 'isCancle' };
} else throw error;
}
};
getConsentsDate = async (dataFilter: any, dateFilter: any) => {
try {
const data = await this.route.getConsentsDate(dataFilter, dateFilter);

let results = null;
let pagination = null;
if (data) {
results = new ConsentsDateModel(data);
pagination = results.getBiPagination();
}
if (results) {
results = results.toJSON();
}
return {
list: results,
pagination: pagination,
};
} catch (error) {
if (axios.isCancel(error)) {
return { message: 'isCancle' };
} else throw error;
}
};
getConsentsTier = async (dataFilter: any, dateFilter: any) => {
try {
const data = await this.route.getConsentsTier(dataFilter, dateFilter);

let results = null;
let pagination = null;
if (data) {
results = new ConsentsTierModel(data);
pagination = results.getBiPagination();
}
if (results) {
results = results.toJSON();
}
return {
list: results,
pagination: pagination,
};
} catch (error) {
if (axios.isCancel(error)) {
return { message: 'isCancle' };
} else throw error;
}
};

getReferer = async (dataFilter: any, dateFilter: any) => {
try {
const data = await this.route.getReferer(dataFilter, dateFilter);

let results = null;
let pagination = null;
if (data) {
results = new RefererModel(data);
pagination = results.getBiPagination();
}
if (results) {
results = results.toJSON();
}
return {
list: results,
pagination: pagination,
};
} catch (error) {
if (axios.isCancel(error)) {
return { message: 'isCancle' };
} else throw error;
}
};
}

export { AesirxBiApiService };
159 changes: 159 additions & 0 deletions src/Bi/BiModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ import {
BI_WOOCOMMERCE_PRODUCT_CHART_FIELD_KEY,
BI_WOOCOMMERCE_STATISTIC_CHART_FIELD_KEY,
BI_WOOCOMMERCE_STATISTIC_FIELD_KEY,
BI_CONSENTS_LIST_FIELD_KEY,
BI_CONSENTS_DATE_FIELD_KEY,
BI_CONSENTS_TIER_FIELD_KEY,
BI_REFERER_FIELD_KEY,
} from '../Constant/BiConstant';
import BaseModel from '../Abstract/BaseModel';

Expand Down Expand Up @@ -833,6 +837,157 @@ class WoocommerceProductItemModel extends BaseItemModel {
};
}

class ConsentsListModel extends BaseModel {
items: any = null;
constructor(entities: any) {
super(entities);
if (entities) {
this.items = entities.collection.map((element: any) => {
return new ConsentsListItemModel(element);
});
this.items.pagination = this.getBiPagination();
}
}
}
class ConsentsListItemModel extends BaseItemModel {
consent: any = null;
tier: any = null;
datetime: any = null;
expiration: any = null;
uuid: any = null;
wallet: any = null;
web3id: any = null;
constructor(entity: any) {
super(entity);
if (entity) {
this.consent = entity[BI_CONSENTS_LIST_FIELD_KEY.CONSENT] ?? '';
this.tier = entity[BI_CONSENTS_LIST_FIELD_KEY.TIER] ?? '';
this.datetime = entity[BI_CONSENTS_LIST_FIELD_KEY.DATETIME] ?? '';
this.expiration = entity[BI_CONSENTS_LIST_FIELD_KEY.EXPIRATION] ?? '';
this.uuid = entity[BI_CONSENTS_LIST_FIELD_KEY.UUID] ?? '';
this.wallet = entity[BI_CONSENTS_LIST_FIELD_KEY.WALLET] ?? '';
this.web3id = entity[BI_CONSENTS_LIST_FIELD_KEY.WEB3ID] ?? '';
}
}
toObject = () => {
return {};
};
toJSON = () => {
return {
...this.baseToJSON(),
[BI_CONSENTS_LIST_FIELD_KEY.CONSENT]: this.consent,
[BI_CONSENTS_LIST_FIELD_KEY.TIER]: this.tier,
[BI_CONSENTS_LIST_FIELD_KEY.DATETIME]: this.datetime,
[BI_CONSENTS_LIST_FIELD_KEY.EXPIRATION]: this.expiration,
[BI_CONSENTS_LIST_FIELD_KEY.UUID]: this.uuid,
[BI_CONSENTS_LIST_FIELD_KEY.WALLET]: this.wallet,
[BI_CONSENTS_LIST_FIELD_KEY.WEB3ID]: this.web3id,
};
};
}

class ConsentsDateModel extends BaseModel {
items: any = null;
constructor(entities: any) {
super(entities);
if (entities) {
this.items = entities.collection.map((element: any) => {
return new ConsentsDateItemModel(element);
});
this.items.pagination = this.getBiPagination();
}
}
}
class ConsentsDateItemModel extends BaseItemModel {
date: any = null;
total: any = null;
constructor(entity: any) {
super(entity);
if (entity) {
this.date = entity[BI_CONSENTS_DATE_FIELD_KEY.DATE] ?? '';
this.total = entity[BI_CONSENTS_DATE_FIELD_KEY.TOTAL] ?? '';
}
}
toObject = () => {
return {};
};
toJSON = () => {
return {
...this.baseToJSON(),
[BI_CONSENTS_DATE_FIELD_KEY.DATE]: this.date,
[BI_CONSENTS_DATE_FIELD_KEY.TOTAL]: this.total,
};
};
}

class ConsentsTierModel extends BaseModel {
items: any = null;
constructor(entities: any) {
super(entities);
if (entities) {
this.items = entities.collection.map((element: any) => {
return new ConsentsTierItemModel(element);
});
this.items.pagination = this.getBiPagination();
}
}
}
class ConsentsTierItemModel extends BaseItemModel {
tier: any = null;
total: any = null;
constructor(entity: any) {
super(entity);
if (entity) {
this.tier = entity[BI_CONSENTS_TIER_FIELD_KEY.TIER] ?? '';
this.total = entity[BI_CONSENTS_TIER_FIELD_KEY.TOTAL] ?? '';
}
}
toObject = () => {
return {};
};
toJSON = () => {
return {
...this.baseToJSON(),
[BI_CONSENTS_TIER_FIELD_KEY.TIER]: this.tier,
[BI_CONSENTS_TIER_FIELD_KEY.TOTAL]: this.total,
};
};
}

class RefererModel extends BaseModel {
items: any = null;
constructor(entities: any) {
super(entities);
if (entities) {
this.items = entities.collection.map((element: any) => {
return new RefererItemModel(element);
});
this.items.pagination = this.getBiPagination();
}
}
}
class RefererItemModel extends BaseItemModel {
number_of_visitors: any = null;
referer: any = null;
constructor(entity: any) {
super(entity);
if (entity) {
this.number_of_visitors = entity[BI_SUMMARY_FIELD_KEY.NUMBER_OF_VISITORS] ?? '';
this.referer = entity[BI_REFERER_FIELD_KEY.REFERER] ?? '';
}
}
toObject = () => {
return {};
};
toJSON = () => {
return {
...this.baseToJSON(),
[BI_SUMMARY_FIELD_KEY.NUMBER_OF_VISITORS]: this.number_of_visitors,
[BI_REFERER_FIELD_KEY.REFERER]: this.referer,
};
};
}

export {
DomainModel,
VisitorsModel,
Expand All @@ -854,4 +1009,8 @@ export {
WoocommerceStatisticChartModel,
WoocommerceProductModel,
WoocommerceProductChartModel,
ConsentsListModel,
ConsentsDateModel,
ConsentsTierModel,
RefererModel,
};
Loading

0 comments on commit f3342b2

Please sign in to comment.