2021-12-29 23:08:41 +00:00
|
|
|
export var OfferFieldsEnum;
|
|
|
|
(function (OfferFieldsEnum) {
|
|
|
|
OfferFieldsEnum["BOLT12"] = "bolt12";
|
2022-10-14 20:53:36 +00:00
|
|
|
OfferFieldsEnum["AMOUNTMSAT"] = "amountMSat";
|
2021-12-29 23:08:41 +00:00
|
|
|
OfferFieldsEnum["TITLE"] = "title";
|
2023-02-21 07:54:28 +00:00
|
|
|
OfferFieldsEnum["ISSUER"] = "issuer";
|
2021-12-29 23:08:41 +00:00
|
|
|
OfferFieldsEnum["DESCRIPTION"] = "description";
|
|
|
|
})(OfferFieldsEnum || (OfferFieldsEnum = {}));
|
|
|
|
export class Offer {
|
2023-02-21 07:54:28 +00:00
|
|
|
constructor(bolt12, amountMSat, title, issuer, description, lastUpdatedAt) {
|
2021-12-29 23:08:41 +00:00
|
|
|
this.bolt12 = bolt12;
|
2022-10-14 20:53:36 +00:00
|
|
|
this.amountMSat = amountMSat;
|
2021-12-29 23:08:41 +00:00
|
|
|
this.title = title;
|
2023-02-21 07:54:28 +00:00
|
|
|
this.issuer = issuer;
|
2021-12-29 23:08:41 +00:00
|
|
|
this.description = description;
|
|
|
|
this.lastUpdatedAt = lastUpdatedAt;
|
|
|
|
}
|
|
|
|
}
|
2022-10-15 00:10:58 +00:00
|
|
|
export const validateDocument = (collectionName, documentToValidate) => {
|
|
|
|
switch (collectionName) {
|
|
|
|
case CollectionsEnum.OFFERS:
|
|
|
|
return validateOffer(documentToValidate);
|
|
|
|
case CollectionsEnum.PAGE_SETTINGS:
|
|
|
|
return validatePageSettings(documentToValidate);
|
|
|
|
default:
|
|
|
|
return ({ isValid: false, error: 'Collection does not exist' });
|
|
|
|
}
|
|
|
|
};
|
2021-12-29 23:08:41 +00:00
|
|
|
export const validateOffer = (documentToValidate) => {
|
|
|
|
if (!documentToValidate.hasOwnProperty(CollectionFieldsEnum.BOLT12)) {
|
2022-10-15 23:35:39 +00:00
|
|
|
return ({ isValid: false, error: 'Bolt12 is mandatory.' });
|
2021-12-29 23:08:41 +00:00
|
|
|
}
|
|
|
|
if (!documentToValidate.hasOwnProperty(CollectionFieldsEnum.AMOUNTMSAT)) {
|
2022-10-15 23:35:39 +00:00
|
|
|
return ({ isValid: false, error: 'Amount mSat is mandatory.' });
|
2021-12-29 23:08:41 +00:00
|
|
|
}
|
|
|
|
if (!documentToValidate.hasOwnProperty(CollectionFieldsEnum.TITLE)) {
|
2022-10-15 23:35:39 +00:00
|
|
|
return ({ isValid: false, error: 'Title is mandatory.' });
|
2021-12-29 23:08:41 +00:00
|
|
|
}
|
|
|
|
if ((typeof documentToValidate[CollectionFieldsEnum.AMOUNTMSAT] !== 'number')) {
|
2022-10-15 23:35:39 +00:00
|
|
|
return ({ isValid: false, error: 'Amount mSat should be a number.' });
|
2022-10-14 20:53:36 +00:00
|
|
|
}
|
|
|
|
return ({ isValid: true });
|
|
|
|
};
|
|
|
|
export var SortOrderEnum;
|
|
|
|
(function (SortOrderEnum) {
|
2022-10-17 15:37:58 +00:00
|
|
|
SortOrderEnum["ASCENDING"] = "asc";
|
|
|
|
SortOrderEnum["DESCENDING"] = "desc";
|
2022-10-14 20:53:36 +00:00
|
|
|
})(SortOrderEnum || (SortOrderEnum = {}));
|
|
|
|
export var PageSettingsFieldsEnum;
|
|
|
|
(function (PageSettingsFieldsEnum) {
|
2022-10-15 00:10:58 +00:00
|
|
|
PageSettingsFieldsEnum["PAGE_ID"] = "pageId";
|
2022-10-14 20:53:36 +00:00
|
|
|
PageSettingsFieldsEnum["TABLES"] = "tables";
|
|
|
|
})(PageSettingsFieldsEnum || (PageSettingsFieldsEnum = {}));
|
|
|
|
export var TableSettingsFieldsEnum;
|
|
|
|
(function (TableSettingsFieldsEnum) {
|
|
|
|
TableSettingsFieldsEnum["TABLE_ID"] = "tableId";
|
|
|
|
TableSettingsFieldsEnum["RECORDS_PER_PAGE"] = "recordsPerPage";
|
|
|
|
TableSettingsFieldsEnum["SORT_BY"] = "sortBy";
|
|
|
|
TableSettingsFieldsEnum["SORT_ORDER"] = "sortOrder";
|
2022-10-17 23:58:21 +00:00
|
|
|
TableSettingsFieldsEnum["COLUMN_SELECTION"] = "columnSelection";
|
|
|
|
TableSettingsFieldsEnum["COLUMN_SELECTION_SM"] = "columnSelectionSM";
|
2022-10-14 20:53:36 +00:00
|
|
|
})(TableSettingsFieldsEnum || (TableSettingsFieldsEnum = {}));
|
|
|
|
export class TableSetting {
|
2022-10-17 23:58:21 +00:00
|
|
|
constructor(tableId, recordsPerPage, sortBy, sortOrder, columnSelection) {
|
2022-10-14 20:53:36 +00:00
|
|
|
this.tableId = tableId;
|
|
|
|
this.recordsPerPage = recordsPerPage;
|
|
|
|
this.sortBy = sortBy;
|
|
|
|
this.sortOrder = sortOrder;
|
2022-10-17 23:58:21 +00:00
|
|
|
this.columnSelection = columnSelection;
|
2022-10-14 20:53:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
export class PageSettings {
|
2022-10-15 00:10:58 +00:00
|
|
|
constructor(pageId, tables) {
|
|
|
|
this.pageId = pageId;
|
|
|
|
this.tables = tables;
|
2022-10-14 20:53:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
export const validatePageSettings = (documentToValidate) => {
|
2022-10-15 01:59:47 +00:00
|
|
|
let errorMessages = '';
|
|
|
|
if (!documentToValidate.hasOwnProperty(CollectionFieldsEnum.PAGE_ID)) {
|
2022-10-15 23:35:39 +00:00
|
|
|
errorMessages = errorMessages + 'Page ID is mandatory.';
|
2022-10-15 01:59:47 +00:00
|
|
|
}
|
|
|
|
if (!documentToValidate.hasOwnProperty(CollectionFieldsEnum.TABLES)) {
|
2022-10-15 23:35:39 +00:00
|
|
|
errorMessages = errorMessages + 'Tables is mandatory.';
|
2022-10-15 01:59:47 +00:00
|
|
|
}
|
|
|
|
const tablesMessages = documentToValidate.tables.reduce((tableAcc, table, tableIdx) => {
|
|
|
|
let errMsg = '';
|
|
|
|
if (!table.hasOwnProperty(CollectionFieldsEnum.TABLE_ID)) {
|
2022-10-15 23:35:39 +00:00
|
|
|
errMsg = errMsg + 'Table ID is mandatory.';
|
2022-10-15 01:59:47 +00:00
|
|
|
}
|
|
|
|
if (!table.hasOwnProperty(CollectionFieldsEnum.SORT_BY)) {
|
2022-10-15 23:35:39 +00:00
|
|
|
errMsg = errMsg + 'Sort By is mandatory.';
|
2022-10-15 01:59:47 +00:00
|
|
|
}
|
|
|
|
if (!table.hasOwnProperty(CollectionFieldsEnum.SORT_ORDER)) {
|
2022-10-15 23:35:39 +00:00
|
|
|
errMsg = errMsg + 'Sort Order is mandatory.';
|
2022-10-15 00:10:58 +00:00
|
|
|
}
|
2022-10-17 23:58:21 +00:00
|
|
|
if (!table.hasOwnProperty(CollectionFieldsEnum.COLUMN_SELECTION_SM)) {
|
2022-11-21 21:44:43 +00:00
|
|
|
errMsg = errMsg + 'Column Selection (Mobile Resolution) is mandatory.';
|
2022-10-16 05:51:29 +00:00
|
|
|
}
|
2022-10-17 23:58:21 +00:00
|
|
|
if (table[CollectionFieldsEnum.COLUMN_SELECTION_SM].length < 1) {
|
2022-11-21 21:44:43 +00:00
|
|
|
errMsg = errMsg + 'Column Selection (Mobile Resolution) should have at least 1 field.';
|
2022-10-16 05:51:29 +00:00
|
|
|
}
|
2022-10-18 21:51:20 +00:00
|
|
|
if (table[CollectionFieldsEnum.COLUMN_SELECTION_SM].length > 3) {
|
2022-11-21 21:44:43 +00:00
|
|
|
errMsg = errMsg + 'Column Selection (Mobile Resolution) should have maximum 3 fields.';
|
2022-10-16 05:51:29 +00:00
|
|
|
}
|
2022-10-17 23:58:21 +00:00
|
|
|
if (!table.hasOwnProperty(CollectionFieldsEnum.COLUMN_SELECTION)) {
|
2022-11-21 21:44:43 +00:00
|
|
|
errMsg = errMsg + 'Column Selection (Desktop Resolution) is mandatory.';
|
2022-10-15 00:10:58 +00:00
|
|
|
}
|
2022-10-17 23:58:21 +00:00
|
|
|
if (table[CollectionFieldsEnum.COLUMN_SELECTION].length < 2) {
|
2022-11-21 21:44:43 +00:00
|
|
|
errMsg = errMsg + 'Column Selection (Desktop Resolution) should have at least 2 fields.';
|
2022-10-15 00:10:58 +00:00
|
|
|
}
|
2022-10-15 01:59:47 +00:00
|
|
|
if (errMsg.trim() !== '') {
|
|
|
|
tableAcc.push({ table: (table.hasOwnProperty(CollectionFieldsEnum.TABLE_ID) ? table[CollectionFieldsEnum.TABLE_ID] : (tableIdx + 1)), message: errMsg });
|
|
|
|
}
|
|
|
|
return tableAcc;
|
|
|
|
}, []);
|
2022-10-15 23:35:39 +00:00
|
|
|
if (errorMessages.trim() === '' && tablesMessages.length === 0) {
|
2022-10-15 01:59:47 +00:00
|
|
|
return ({ isValid: true });
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
const errObj = { page: (documentToValidate.hasOwnProperty(CollectionFieldsEnum.PAGE_ID) ? documentToValidate[CollectionFieldsEnum.PAGE_ID] : 'Unknown') };
|
|
|
|
if (errorMessages.trim() !== '') {
|
|
|
|
errObj['message'] = errorMessages;
|
|
|
|
}
|
|
|
|
if (tablesMessages.length && tablesMessages.length > 0) {
|
|
|
|
errObj['tables'] = tablesMessages;
|
|
|
|
}
|
|
|
|
return ({ isValid: false, error: JSON.stringify(errObj) });
|
2021-12-29 23:08:41 +00:00
|
|
|
}
|
|
|
|
};
|
2022-10-14 20:53:36 +00:00
|
|
|
export var CollectionsEnum;
|
|
|
|
(function (CollectionsEnum) {
|
|
|
|
CollectionsEnum["OFFERS"] = "Offers";
|
|
|
|
CollectionsEnum["PAGE_SETTINGS"] = "PageSettings";
|
|
|
|
})(CollectionsEnum || (CollectionsEnum = {}));
|
2022-11-24 02:20:23 +00:00
|
|
|
export const CollectionFieldsEnum = { ...OfferFieldsEnum, ...PageSettingsFieldsEnum, ...TableSettingsFieldsEnum };
|
2022-10-28 16:41:38 +00:00
|
|
|
export const LNDCollection = [CollectionsEnum.PAGE_SETTINGS];
|
|
|
|
export const ECLCollection = [CollectionsEnum.PAGE_SETTINGS];
|
|
|
|
export const CLNCollection = [CollectionsEnum.PAGE_SETTINGS, CollectionsEnum.OFFERS];
|
2023-09-29 03:18:14 +00:00
|
|
|
export const ECL_UPDATED_DB = [
|
|
|
|
{
|
|
|
|
pageId: 'peers_channels',
|
|
|
|
tables: [
|
|
|
|
{
|
|
|
|
tableId: 'open_channels',
|
|
|
|
removed: ['buried', 'feeRatePerKw'],
|
|
|
|
renamed: ['isFunder:isInitiator']
|
|
|
|
},
|
|
|
|
{
|
|
|
|
tableId: 'pending_channels',
|
|
|
|
removed: ['buried', 'feeRatePerKw'],
|
|
|
|
renamed: ['isFunder:isInitiator']
|
|
|
|
},
|
|
|
|
{
|
|
|
|
tableId: 'inactive_channels',
|
|
|
|
removed: ['buried', 'feeRatePerKw'],
|
|
|
|
renamed: ['isFunder:isInitiator']
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
];
|