evernode-js-client 0.6.32 → 0.6.34
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/index.js
CHANGED
@@ -9149,7 +9149,7 @@ module.exports = { mask, unmask };
|
|
9149
9149
|
|
9150
9150
|
|
9151
9151
|
try {
|
9152
|
-
module.exports = require(__nccwpck_require__.ab + "prebuilds/linux-x64/node.
|
9152
|
+
module.exports = require(__nccwpck_require__.ab + "prebuilds/linux-x64/node.napi1.node");
|
9153
9153
|
} catch (e) {
|
9154
9154
|
module.exports = __nccwpck_require__(2567);
|
9155
9155
|
}
|
@@ -33340,7 +33340,7 @@ module.exports = isValidUTF8;
|
|
33340
33340
|
|
33341
33341
|
|
33342
33342
|
try {
|
33343
|
-
module.exports = require(__nccwpck_require__.ab + "prebuilds/linux-x64/node.
|
33343
|
+
module.exports = require(__nccwpck_require__.ab + "prebuilds/linux-x64/node.napi.node");
|
33344
33344
|
} catch (e) {
|
33345
33345
|
module.exports = __nccwpck_require__(9372);
|
33346
33346
|
}
|
@@ -51836,7 +51836,6 @@ const { Defaults } = __nccwpck_require__(8262);
|
|
51836
51836
|
const { EncryptionHelper } = __nccwpck_require__(4832);
|
51837
51837
|
const { EventEmitter } = __nccwpck_require__(6170);
|
51838
51838
|
const { UtilHelpers } = __nccwpck_require__(6687);
|
51839
|
-
const { FirestoreHandler } = __nccwpck_require__(9718);
|
51840
51839
|
const { StateHelpers } = __nccwpck_require__(3860);
|
51841
51840
|
const { EvernodeHelpers } = __nccwpck_require__(2523);
|
51842
51841
|
const { HookHelpers } = __nccwpck_require__(4675);
|
@@ -51860,7 +51859,6 @@ class BaseEvernodeClient {
|
|
51860
51859
|
#watchEvents;
|
51861
51860
|
#autoSubscribe;
|
51862
51861
|
#ownsXrplApi = false;
|
51863
|
-
#firestoreHandler;
|
51864
51862
|
|
51865
51863
|
constructor(xrpAddress, xrpSecret, watchEvents, autoSubscribe = false, options = {}) {
|
51866
51864
|
|
@@ -51879,7 +51877,6 @@ class BaseEvernodeClient {
|
|
51879
51877
|
this.#watchEvents = watchEvents;
|
51880
51878
|
this.#autoSubscribe = autoSubscribe;
|
51881
51879
|
this.events = new EventEmitter();
|
51882
|
-
this.#firestoreHandler = new FirestoreHandler()
|
51883
51880
|
|
51884
51881
|
this.xrplAcc.on(XrplApiEvents.PAYMENT, (tx, error) => this.#handleEvernodeEvent(tx, error));
|
51885
51882
|
this.xrplAcc.on(XrplApiEvents.URI_TOKEN_BUY, (tx, error) => this.#handleEvernodeEvent(tx, error));
|
@@ -52487,29 +52484,6 @@ class BaseEvernodeClient {
|
|
52487
52484
|
return null;
|
52488
52485
|
}
|
52489
52486
|
|
52490
|
-
/**
|
52491
|
-
* Get the hosts registered in Evernode. The result's are paginated. Default page size is 20. _Note: Specifying both filter and pagination does not supported._
|
52492
|
-
* @param {object} filters [Optional] Filter criteria to filter the hosts. The filter key can be a either property of the host.
|
52493
|
-
* @param {number} pageSize [Optional] Page size for the results.
|
52494
|
-
* @param {string} nextPageToken [Optional] Next page's token, If received by the previous result set.
|
52495
|
-
* @returns The list of active hosts. The response will be in '{data: [], nextPageToken: ''}' only if there are more pages. Otherwise the response will only contain the host list.
|
52496
|
-
*/
|
52497
|
-
async getHosts(filters = null, pageSize = null, nextPageToken = null) {
|
52498
|
-
const hosts = await this.#firestoreHandler.getHosts(filters, pageSize, nextPageToken);
|
52499
|
-
const curMomentStartIdx = await this.getMomentStartIndex();
|
52500
|
-
const res = await Promise.all((hosts.nextPageToken ? hosts.data : hosts).map(async host => {
|
52501
|
-
const hostAcc = new XrplAccount(host.address, null, { xrplApi: this.xrplApi });
|
52502
|
-
host.domain = await hostAcc.getDomain();
|
52503
|
-
|
52504
|
-
host.active = (host.lastHeartbeatIndex > (this.config.hostHeartbeatFreq * this.config.momentSize) ?
|
52505
|
-
(host.lastHeartbeatIndex >= (curMomentStartIdx - (this.config.hostHeartbeatFreq * this.config.momentSize))) :
|
52506
|
-
(host.lastHeartbeatIndex > 0));
|
52507
|
-
return host;
|
52508
|
-
}));
|
52509
|
-
|
52510
|
-
return (hosts.nextPageToken ? { ...hosts, data: res } : res);
|
52511
|
-
}
|
52512
|
-
|
52513
52487
|
/**
|
52514
52488
|
* Get the hosts registered in Evernode.
|
52515
52489
|
* @returns The list of hosts.
|
@@ -52545,94 +52519,25 @@ class BaseEvernodeClient {
|
|
52545
52519
|
}
|
52546
52520
|
|
52547
52521
|
/**
|
52548
|
-
* Get the
|
52549
|
-
* @
|
52550
|
-
* @param {number} pageSize [Optional] Page size for the results.
|
52551
|
-
* @param {string} nextPageToken [Optional] Next page's token, If received by the previous result set.
|
52552
|
-
* @returns The list of candidates. The response will be in '{data: [], nextPageToken: ''}' only if there are more pages. Otherwise the response will only contain the host list.
|
52522
|
+
* Get the governor in Evernode.
|
52523
|
+
* @returns The list of candidates.
|
52553
52524
|
*/
|
52554
|
-
async
|
52555
|
-
const
|
52556
|
-
|
52557
|
-
}
|
52558
|
-
|
52559
|
-
/**
|
52560
|
-
* Get all Evernode configuration without paginating.
|
52561
|
-
* @returns The list of configuration.
|
52562
|
-
*/
|
52563
|
-
async getAllConfigs() {
|
52564
|
-
let fullConfigList = [];
|
52565
|
-
const configs = await this.#firestoreHandler.getConfigs();
|
52566
|
-
if (configs.nextPageToken) {
|
52567
|
-
let currentPageToken = configs.nextPageToken;
|
52568
|
-
let nextConfigs = null;
|
52569
|
-
fullConfigList = fullConfigList.concat(configs.data);
|
52570
|
-
while (currentPageToken) {
|
52571
|
-
nextConfigs = await this.#firestoreHandler.getConfigs(null, 50, currentPageToken);
|
52572
|
-
fullConfigList = fullConfigList.concat(nextConfigs.nextPageToken ? nextConfigs.data : nextConfigs);
|
52573
|
-
currentPageToken = nextConfigs.nextPageToken;
|
52574
|
-
}
|
52575
|
-
} else {
|
52576
|
-
fullConfigList = fullConfigList.concat(configs);
|
52577
|
-
}
|
52578
|
-
|
52579
|
-
return fullConfigList;
|
52580
|
-
}
|
52581
|
-
|
52582
|
-
/**
|
52583
|
-
* Get all the hosts without paginating.
|
52584
|
-
* @returns The list of hosts.
|
52585
|
-
*/
|
52586
|
-
async getAllHosts() {
|
52587
|
-
let fullHostList = [];
|
52588
|
-
const hosts = await this.#firestoreHandler.getHosts();
|
52589
|
-
if (hosts.nextPageToken) {
|
52590
|
-
let currentPageToken = hosts.nextPageToken;
|
52591
|
-
let nextHosts = null;
|
52592
|
-
fullHostList = fullHostList.concat(hosts.data);
|
52593
|
-
while (currentPageToken) {
|
52594
|
-
nextHosts = await this.#firestoreHandler.getHosts(null, 50, currentPageToken);
|
52595
|
-
fullHostList = fullHostList.concat(nextHosts.nextPageToken ? nextHosts.data : nextHosts);
|
52596
|
-
currentPageToken = nextHosts.nextPageToken;
|
52597
|
-
}
|
52598
|
-
} else {
|
52599
|
-
fullHostList = fullHostList.concat(hosts);
|
52600
|
-
}
|
52601
|
-
|
52602
|
-
const curMomentStartIdx = await this.getMomentStartIndex();
|
52603
|
-
await Promise.all((fullHostList).map(async host => {
|
52604
|
-
const hostAcc = new XrplAccount(host.address, null, { xrplApi: this.xrplApi });
|
52605
|
-
host.domain = await hostAcc.getDomain();
|
52606
|
-
host.active = (host.lastHeartbeatIndex > (this.config.hostHeartbeatFreq * this.config.momentSize) ?
|
52607
|
-
(host.lastHeartbeatIndex >= (curMomentStartIdx - (this.config.hostHeartbeatFreq * this.config.momentSize))) :
|
52608
|
-
(host.lastHeartbeatIndex > 0));
|
52609
|
-
return host;
|
52610
|
-
}));
|
52611
|
-
|
52612
|
-
return fullHostList;
|
52613
|
-
}
|
52525
|
+
async getAllCandidatesFromLedger() {
|
52526
|
+
const states = await this.getHookStates();
|
52527
|
+
let candidates = [];
|
52614
52528
|
|
52615
|
-
|
52616
|
-
|
52617
|
-
|
52618
|
-
|
52619
|
-
|
52620
|
-
|
52621
|
-
|
52622
|
-
|
52623
|
-
let currentPageToken = candidates.nextPageToken;
|
52624
|
-
let nextCandidates = null;
|
52625
|
-
fullCandidateList = fullCandidateList.concat(candidates.data);
|
52626
|
-
while (currentPageToken) {
|
52627
|
-
nextCandidates = await this.#firestoreHandler.getCandidates(null, 50, currentPageToken);
|
52628
|
-
fullCandidateList = fullCandidateList.concat(nextCandidates.nextPageToken ? nextCandidates.data : nextCandidates);
|
52629
|
-
currentPageToken = nextCandidates.nextPageToken;
|
52529
|
+
for (const state of states) {
|
52530
|
+
const stateKey = Buffer.from(state.key, 'hex');
|
52531
|
+
if (state.data) {
|
52532
|
+
const stateData = Buffer.from(state.data, 'hex');
|
52533
|
+
const decoded = StateHelpers.decodeStateData(stateKey, stateData);
|
52534
|
+
if (decoded.type == StateHelpers.StateTypes.CANDIDATE_ID) {
|
52535
|
+
candidates.push(decoded);
|
52536
|
+
}
|
52630
52537
|
}
|
52631
|
-
} else {
|
52632
|
-
fullCandidateList = fullCandidateList.concat(candidates);
|
52633
52538
|
}
|
52634
52539
|
|
52635
|
-
return
|
52540
|
+
return candidates;
|
52636
52541
|
}
|
52637
52542
|
|
52638
52543
|
/**
|
@@ -52717,10 +52622,11 @@ class BaseEvernodeClient {
|
|
52717
52622
|
*/
|
52718
52623
|
async getDudHostCandidatesByOwner(ownerAddress = this.xrplAcc.address) {
|
52719
52624
|
try {
|
52720
|
-
|
52721
|
-
|
52722
|
-
|
52723
|
-
|
52625
|
+
const candidates = await this.getAllCandidatesFromLedger();
|
52626
|
+
let filteredCandidates = candidates.filter(c => c.ownerAddress === ownerAddress);
|
52627
|
+
if (filteredCandidates && filteredCandidates.length > 0) {
|
52628
|
+
filteredCandidates = filteredCandidates.filter(c => StateHelpers.getCandidateType(c.uniqueId) == EvernodeConstants.CandidateTypes.DudHost);
|
52629
|
+
return filteredCandidates;
|
52724
52630
|
}
|
52725
52631
|
} catch (error) {
|
52726
52632
|
console.log(error)
|
@@ -53443,7 +53349,8 @@ class HostClient extends BaseEvernodeClient {
|
|
53443
53349
|
else if (e.status === "TOOK_LONG") {
|
53444
53350
|
feeUplift += (options?.feeUplift || 0);
|
53445
53351
|
}
|
53446
|
-
console.error(
|
53352
|
+
console.error(e);
|
53353
|
+
console.error(`Submission attempt ${attempt} failed. Retrying...`);
|
53447
53354
|
await new Promise(resolve => setTimeout(resolve, TX_RETRY_INTERVAL));
|
53448
53355
|
}
|
53449
53356
|
}
|
@@ -54665,8 +54572,7 @@ const https = __nccwpck_require__(5687);
|
|
54665
54572
|
const DefinitionsUrl = 'https://raw.githubusercontent.com/EvernodeXRPL/evernode-resources/main/definitions/definitions.json';
|
54666
54573
|
|
54667
54574
|
const DefaultValues = {
|
54668
|
-
xrplApi: null
|
54669
|
-
useCentralizedRegistry: false,
|
54575
|
+
xrplApi: null
|
54670
54576
|
}
|
54671
54577
|
|
54672
54578
|
const HookTypes = {
|
@@ -55416,334 +55322,6 @@ module.exports = {
|
|
55416
55322
|
|
55417
55323
|
/***/ }),
|
55418
55324
|
|
55419
|
-
/***/ 9718:
|
55420
|
-
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
|
55421
|
-
|
55422
|
-
const https = __nccwpck_require__(5687);
|
55423
|
-
const { Defaults } = __nccwpck_require__(8262);
|
55424
|
-
|
55425
|
-
const FirestoreOperations = {
|
55426
|
-
EQUAL: 'EQUAL',
|
55427
|
-
AND: 'AND'
|
55428
|
-
}
|
55429
|
-
|
55430
|
-
class FirestoreHandler {
|
55431
|
-
#projectId = null;
|
55432
|
-
#collectionPrefix = null;
|
55433
|
-
|
55434
|
-
constructor(options = {}) {
|
55435
|
-
this.#projectId = options.stateIndexId || Defaults.values.stateIndexId;
|
55436
|
-
this.#collectionPrefix = options.collectionPrefix || Defaults.values.governorAddress;
|
55437
|
-
}
|
55438
|
-
|
55439
|
-
/**
|
55440
|
-
* Convert given document value object to real format and snake_case key to camelCase.
|
55441
|
-
* @param key Name of the property.
|
55442
|
-
* @param value Value to be parsed.
|
55443
|
-
* @returns Parsed key and value.
|
55444
|
-
*/
|
55445
|
-
#parseValue(key, value) {
|
55446
|
-
// Convert snake_case to camelCase.
|
55447
|
-
const ccKey = key.replace(/_([a-z])/g, function (g) { return g[1].toUpperCase(); });
|
55448
|
-
const type = Object.keys(value)[0];
|
55449
|
-
let parsed;
|
55450
|
-
switch (type) {
|
55451
|
-
case 'integerValue':
|
55452
|
-
parsed = parseInt(value[type]);
|
55453
|
-
break;
|
55454
|
-
case 'floatValue':
|
55455
|
-
parsed = parseFloat(value[type]);
|
55456
|
-
break;
|
55457
|
-
case 'mapValue':
|
55458
|
-
parsed = {};
|
55459
|
-
for (const [subKey, subValue] of Object.entries(value[type].fields)) {
|
55460
|
-
const field = this.#parseValue(subKey, subValue);
|
55461
|
-
parsed[field.key] = field.value;
|
55462
|
-
}
|
55463
|
-
break;
|
55464
|
-
default:
|
55465
|
-
parsed = value[type];
|
55466
|
-
break;
|
55467
|
-
}
|
55468
|
-
return { key: ccKey, value: parsed };
|
55469
|
-
}
|
55470
|
-
|
55471
|
-
/**
|
55472
|
-
* Get values filtered according to the given body.
|
55473
|
-
* @param body Body to parsed in to the query reqest.
|
55474
|
-
* @returns Result set.
|
55475
|
-
*/
|
55476
|
-
async #runQuery(body) {
|
55477
|
-
const url = this.buildApiPath(null, null, true);
|
55478
|
-
return await this.sendRequest('POST', url, null, body);
|
55479
|
-
}
|
55480
|
-
|
55481
|
-
/**
|
55482
|
-
* Get documents from a collection.
|
55483
|
-
* @param collectionId Name of the collection.
|
55484
|
-
* @param pageSize Optianal page size if result set needed to be paginated
|
55485
|
-
* @param nextPageToken Next page token of a paginated result set.
|
55486
|
-
* @returns Result set.
|
55487
|
-
*/
|
55488
|
-
async #read(collectionId, pageSize = null, nextPageToken = null) {
|
55489
|
-
if (!collectionId)
|
55490
|
-
throw { type: 'Validation Error', message: 'collectionId is required' };
|
55491
|
-
|
55492
|
-
const url = this.buildApiPath(collectionId);
|
55493
|
-
let params = (pageSize || nextPageToken) ? {} : null;
|
55494
|
-
if (pageSize)
|
55495
|
-
params = { pageSize: pageSize };
|
55496
|
-
if (nextPageToken)
|
55497
|
-
params = { pageToken: nextPageToken, ...params };
|
55498
|
-
|
55499
|
-
return await this.sendRequest('GET', url, params);
|
55500
|
-
}
|
55501
|
-
|
55502
|
-
/**
|
55503
|
-
* Get documents from a collection with filtering support.
|
55504
|
-
* @param collectionId Name of the collection.
|
55505
|
-
* @param filter Optional filters to filter documents.
|
55506
|
-
* @param pageSize Optianal page size if result set needed to be paginated
|
55507
|
-
* @param nextPageToken Next page token of a paginated result set.
|
55508
|
-
* @returns Parsed readable result set.
|
55509
|
-
*/
|
55510
|
-
async #getDocuments(collectionId, filters = null, pageSize = null, nextPageToken = null) {
|
55511
|
-
if (filters && (pageSize || nextPageToken))
|
55512
|
-
throw { type: 'Validation Error', message: 'Pagination isn\'t supported with filter.' };
|
55513
|
-
|
55514
|
-
let data;
|
55515
|
-
// If there are filters send requst in query mode.
|
55516
|
-
if (filters) {
|
55517
|
-
// Prepare the query body from given filters.
|
55518
|
-
let where = {
|
55519
|
-
compositeFilter: {
|
55520
|
-
filters: Object.entries(filters).map(([key, value]) => {
|
55521
|
-
const field = this.convertValue(key, value);
|
55522
|
-
return {
|
55523
|
-
fieldFilter: {
|
55524
|
-
field: { fieldPath: field.key },
|
55525
|
-
op: FirestoreOperations.EQUAL,
|
55526
|
-
value: field.value
|
55527
|
-
}
|
55528
|
-
}
|
55529
|
-
}),
|
55530
|
-
op: filters.operator ? filters.operator : FirestoreOperations.AND
|
55531
|
-
}
|
55532
|
-
};
|
55533
|
-
for (const [key, value] of Object.entries(filters)) {
|
55534
|
-
const field = this.convertValue(key, value);
|
55535
|
-
let fieldFilter = {
|
55536
|
-
field: { fieldPath: field.key },
|
55537
|
-
op: FirestoreOperations.EQUAL,
|
55538
|
-
value: field.value
|
55539
|
-
}
|
55540
|
-
where.compositeFilter.filters.push({ fieldFilter: fieldFilter });
|
55541
|
-
}
|
55542
|
-
|
55543
|
-
let body = {
|
55544
|
-
structuredQuery: {
|
55545
|
-
where: where,
|
55546
|
-
from: [{ collectionId: collectionId }]
|
55547
|
-
}
|
55548
|
-
};
|
55549
|
-
data = await this.#runQuery(body);
|
55550
|
-
data = data ? JSON.parse(data) : [];
|
55551
|
-
if (data && data.length && data[0].document) {
|
55552
|
-
return data.map(d => {
|
55553
|
-
return this.parseDocument(d.document);
|
55554
|
-
});
|
55555
|
-
}
|
55556
|
-
}
|
55557
|
-
else {
|
55558
|
-
data = await this.#read(collectionId, pageSize, nextPageToken);
|
55559
|
-
data = data ? JSON.parse(data) : {};
|
55560
|
-
if (data.documents && data.documents.length) {
|
55561
|
-
const list = data.documents.map(d => {
|
55562
|
-
return this.parseDocument(d);
|
55563
|
-
});
|
55564
|
-
return data.nextPageToken ? {
|
55565
|
-
data: list,
|
55566
|
-
nextPageToken: data.nextPageToken
|
55567
|
-
} : list;
|
55568
|
-
}
|
55569
|
-
}
|
55570
|
-
|
55571
|
-
return [];
|
55572
|
-
}
|
55573
|
-
|
55574
|
-
getCollectionId(collection) {
|
55575
|
-
// Document if is generated with given prefix.
|
55576
|
-
return `${this.#collectionPrefix}_${collection}`;
|
55577
|
-
}
|
55578
|
-
|
55579
|
-
/**
|
55580
|
-
* Send http requst.
|
55581
|
-
* @param httpMethod GET/POST/PATCH/DELETE
|
55582
|
-
* @param url Url for the request.
|
55583
|
-
* @param params Optional query params.
|
55584
|
-
* @param data Optional request body.
|
55585
|
-
* @param options Optional options.
|
55586
|
-
* @returns Result set.
|
55587
|
-
*/
|
55588
|
-
async sendRequest(httpMethod, url, params = null, data = null, options = null) {
|
55589
|
-
if (!Defaults.values.useCentralizedRegistry) {
|
55590
|
-
console.warn("Please change the useCentralizedRegistry flag to true in Defaults if you want to use this function!")
|
55591
|
-
throw new Error("Centralized function is in use!!")
|
55592
|
-
}
|
55593
|
-
|
55594
|
-
const urlObj = new URL(url);
|
55595
|
-
// Populate uri params to the URL object.
|
55596
|
-
if (params) {
|
55597
|
-
for (const [key, value] of Object.entries(params)) {
|
55598
|
-
if (value) {
|
55599
|
-
// If value is a array, populate it with same name.
|
55600
|
-
if (typeof value === 'object') {
|
55601
|
-
for (const val of value) {
|
55602
|
-
if (val)
|
55603
|
-
urlObj.searchParams.append(key, val);
|
55604
|
-
}
|
55605
|
-
}
|
55606
|
-
else
|
55607
|
-
urlObj.searchParams.set(key, value);
|
55608
|
-
}
|
55609
|
-
}
|
55610
|
-
}
|
55611
|
-
|
55612
|
-
let reqOptions = {
|
55613
|
-
method: httpMethod,
|
55614
|
-
protocol: urlObj.protocol,
|
55615
|
-
hostname: urlObj.hostname,
|
55616
|
-
port: urlObj.port,
|
55617
|
-
path: `${urlObj.pathname}?${urlObj.searchParams.toString()}`,
|
55618
|
-
...(options ? options : {})
|
55619
|
-
};
|
55620
|
-
|
55621
|
-
return new Promise(async (resolve, reject) => {
|
55622
|
-
// Send request and collect data chuncks to a buffer. Then return the result set on end event.
|
55623
|
-
// Resolve only if the status is 200.
|
55624
|
-
const req = https.request(reqOptions, (res) => {
|
55625
|
-
let resData = '';
|
55626
|
-
res.on('data', (d) => {
|
55627
|
-
resData += d;
|
55628
|
-
});
|
55629
|
-
res.on('end', async () => {
|
55630
|
-
if (res.statusCode === 200) {
|
55631
|
-
resolve(resData);
|
55632
|
-
return;
|
55633
|
-
}
|
55634
|
-
reject({ status: res.statusCode, data: resData });
|
55635
|
-
return;
|
55636
|
-
});
|
55637
|
-
}).on('error', async (e) => {
|
55638
|
-
reject(e);
|
55639
|
-
return;
|
55640
|
-
});
|
55641
|
-
|
55642
|
-
if (data)
|
55643
|
-
req.write(typeof data === 'object' ? JSON.stringify(data) : data);
|
55644
|
-
|
55645
|
-
req.end();
|
55646
|
-
});
|
55647
|
-
}
|
55648
|
-
|
55649
|
-
/**
|
55650
|
-
* Generate url for firestore.
|
55651
|
-
* @param collectionId Optional collection name.
|
55652
|
-
* @param documentId Optional document name.
|
55653
|
-
* @param isQuery Whether a query request or not.
|
55654
|
-
* @returns The generated url.
|
55655
|
-
*/
|
55656
|
-
buildApiPath(collectionId = null, documentId = null, isQuery = false) {
|
55657
|
-
let path = `https://firestore.googleapis.com/v1/projects/${this.#projectId}/databases/(default)/documents`;
|
55658
|
-
if (collectionId)
|
55659
|
-
path += `/${collectionId.toString()}`;
|
55660
|
-
if (documentId)
|
55661
|
-
path += `/${documentId.toString()}`;
|
55662
|
-
if (isQuery)
|
55663
|
-
path += ':runQuery';
|
55664
|
-
return path;
|
55665
|
-
}
|
55666
|
-
|
55667
|
-
/**
|
55668
|
-
* Generate firestore document value object from given key and value, Convert camelCase key to snake_case.
|
55669
|
-
* @param key Name of the value.
|
55670
|
-
* @param value Value to be parsed.
|
55671
|
-
* @returns Generated firestore document object.
|
55672
|
-
*/
|
55673
|
-
convertValue(key, value) {
|
55674
|
-
// Convert camelCase to snake_case.
|
55675
|
-
const uKey = key.replace(/([A-Z])/g, function (g) { return `_${g[0].toLocaleLowerCase()}`; });
|
55676
|
-
let val = {};
|
55677
|
-
let type
|
55678
|
-
switch (typeof value) {
|
55679
|
-
case 'number':
|
55680
|
-
type = (value % 1 > 0 ? 'float' : 'integer');
|
55681
|
-
val = value;
|
55682
|
-
break;
|
55683
|
-
case 'object':
|
55684
|
-
type = 'map';
|
55685
|
-
val = {
|
55686
|
-
fields: {}
|
55687
|
-
}
|
55688
|
-
// Prepare the firestore write body with the given data object.
|
55689
|
-
for (const [subKey, subValue] of Object.entries(value)) {
|
55690
|
-
const field = this.convertValue(subKey, subValue);
|
55691
|
-
val.fields[field.key] = field.value;
|
55692
|
-
}
|
55693
|
-
break;
|
55694
|
-
case 'boolean':
|
55695
|
-
type = 'boolean';
|
55696
|
-
val = value;
|
55697
|
-
break;
|
55698
|
-
default:
|
55699
|
-
type = 'string';
|
55700
|
-
val = value;
|
55701
|
-
break;
|
55702
|
-
}
|
55703
|
-
type = `${type}Value`;
|
55704
|
-
let obj = {};
|
55705
|
-
obj[type] = val;
|
55706
|
-
return { key: uKey, value: obj };
|
55707
|
-
}
|
55708
|
-
|
55709
|
-
/**
|
55710
|
-
* Convert the firestore document to human readable simplified json object.
|
55711
|
-
* @param document Firestore document.
|
55712
|
-
* @returns Simplified json object for the document.
|
55713
|
-
*/
|
55714
|
-
parseDocument(document) {
|
55715
|
-
let item = {
|
55716
|
-
id: document.name.split('/').pop(),
|
55717
|
-
createTime: new Date(document.createTime),
|
55718
|
-
updateTime: new Date(document.updateTime)
|
55719
|
-
};
|
55720
|
-
for (const [key, value] of Object.entries(document.fields)) {
|
55721
|
-
const field = this.#parseValue(key, value);
|
55722
|
-
item[field.key] = field.value;
|
55723
|
-
}
|
55724
|
-
return item;
|
55725
|
-
}
|
55726
|
-
|
55727
|
-
async getCandidates(filters = null, pageSize = null, nextPageToken = null) {
|
55728
|
-
return await this.#getDocuments(this.getCollectionId('candidates'), filters, pageSize, nextPageToken);
|
55729
|
-
}
|
55730
|
-
|
55731
|
-
async getHosts(filters = null, pageSize = null, nextPageToken = null) {
|
55732
|
-
return await this.#getDocuments(this.getCollectionId('hosts'), filters, pageSize, nextPageToken);
|
55733
|
-
}
|
55734
|
-
|
55735
|
-
async getConfigs(filters = null, pageSize = null, nextPageToken = null) {
|
55736
|
-
return await this.#getDocuments(this.getCollectionId('configs'), filters, pageSize, nextPageToken);
|
55737
|
-
}
|
55738
|
-
}
|
55739
|
-
|
55740
|
-
module.exports = {
|
55741
|
-
FirestoreHandler,
|
55742
|
-
FirestoreOperations
|
55743
|
-
}
|
55744
|
-
|
55745
|
-
/***/ }),
|
55746
|
-
|
55747
55325
|
/***/ 4675:
|
55748
55326
|
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
|
55749
55327
|
|
@@ -55799,7 +55377,6 @@ const { XrplApiEvents, XrplConstants } = __nccwpck_require__(3307);
|
|
55799
55377
|
const { XrplAccount } = __nccwpck_require__(9329);
|
55800
55378
|
const { EvernodeConstants, HookStateKeys, HookParamKeys, EventTypes } = __nccwpck_require__(9849);
|
55801
55379
|
const { XflHelpers } = __nccwpck_require__(3243);
|
55802
|
-
const { FirestoreHandler } = __nccwpck_require__(9718);
|
55803
55380
|
const { StateHelpers } = __nccwpck_require__(3860);
|
55804
55381
|
const { UtilHelpers } = __nccwpck_require__(6687);
|
55805
55382
|
const { TransactionHelper } = __nccwpck_require__(7071);
|
@@ -55828,7 +55405,6 @@ module.exports = {
|
|
55828
55405
|
Defaults,
|
55829
55406
|
XflHelpers,
|
55830
55407
|
StateHelpers,
|
55831
|
-
FirestoreHandler,
|
55832
55408
|
UtilHelpers,
|
55833
55409
|
TransactionHelper,
|
55834
55410
|
EncryptionHelper,
|
package/package.json
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
],
|
7
7
|
"homepage": "https://github.com/HotPocketDev/evernode-js-client",
|
8
8
|
"license": "SEE LICENSE IN https://raw.githubusercontent.com/EvernodeXRPL/evernode-resources/main/license/evernode-license.pdf",
|
9
|
-
"version": "0.6.
|
9
|
+
"version": "0.6.34",
|
10
10
|
"dependencies": {
|
11
11
|
"elliptic": "6.5.4",
|
12
12
|
"libsodium-wrappers": "0.7.10",
|
Binary file
|
Binary file
|