UNPKG

starkinfra

Version:

SDK to facilitate Node integrations with Stark Infra

120 lines (111 loc) 4.89 kB
const rest = require('../../utils/rest.js'); const check = require('starkcore').check; const Resource = require('../../utils/resource.js').Resource class Log extends Resource { /** * * Ledger Log object * * @description Every time a Ledger entity is updated, a corresponding Ledger Log * is generated for the entity. This log is never generated by the * user, but it can be retrieved to check additional information * on the Ledger. * * Attributes: * @param id [string]: unique id returned when the log is created. ex: '5656565656565656' * @param created [string]: creation datetime for the log. ex: '2020-03-10 10:30:00.000' * @param type [string]: type of the Ledger event which triggered the log creation. ex: 'created' or 'updated' * @param errors [list of strings]: list of errors linked to this Ledger event * @param ledger [Ledger]: Ledger entity to which the log refers to. * */ constructor({ id=null, created=null, type=null, errors=null, ledger=null }) { super(id); this.created = check.datetime(created); this.type = type; this.errors = errors; this.ledger = ledger; } } exports.Log = Log; let resource = {'class': exports.Log, 'name': 'LedgerLog'}; exports.get = async function (id, {user} = {}) { /** * * Retrieve a specific Ledger Log * * @description Receive a single Ledger Log object previously created by the Stark Infra API by passing its id * * Parameters (required): * @param id [string]: object unique id. ex: '5656565656565656' * * Parameters (optional): * @param user [Organization/Project object]: Organization or Project object. Not necessary if starkinfra.user was set before function call * * Return: * @returns Ledger Log object with updated attributes * */ return rest.getId(resource, id, user); }; exports.query = async function ({ ids, limit, after, before, ledgerId, user } = {}) { /** * * Retrieve Ledger Logs * * @description Receive a generator of Ledger Log objects previously created in the Stark Infra API * * Parameters (optional): * @param ids [list of strings, default []]: list of Log ids to filter. ex: ['5656565656565656', '4545454545454545'] * @param limit [integer, default null]: maximum number of objects to be retrieved. Unlimited if null. ex: 35 * @param after [string, default null] date filter for objects created only after specified date. ex: '2020-03-10' * @param before [string, default null] date filter for objects created only before specified date. ex: '2020-03-10' * @param ledgerId [string, default null]: filter logs by Ledger id. ex: '5656565656565656' * @param user [Organization/Project object, default null]: Project object. Not necessary if starkinfra.user was set before function call * * Return: * @returns list of Ledger Log objects with updated attributes * */ let query = { ids: ids, limit: limit, after: after, before: before, ledgerId: ledgerId, }; return rest.getList(resource, query, user); }; exports.page = async function ({ cursor, ids, limit, after, before, ledgerId, user } = {}) { /** * * Retrieve paged Ledger Logs * * @description Receive a list of up to 100 Ledger.Log objects previously created in the Stark Infra API and the cursor to the next page. * Use this function instead of query if you want to manually page your requests. * * Parameters (optional): * @param cursor [string, default null]: cursor returned on the previous page function call * @param ids [list of strings, default []]: list of Log ids to filter. ex: ['5656565656565656', '4545454545454545'] * @param limit [integer, default 100]: maximum number of objects to be retrieved. It must be an integer between 1 and 100. ex: 35 * @param after [string, default null] date filter for objects created only after specified date. ex: '2020-03-10' * @param before [string, default null] date filter for objects created only before specified date. ex: '2020-03-10' * @param ledgerId [string, default null]: filter logs by Ledger id. ex: '5656565656565656' * @param user [Organization/Project object, default null]: Project object. Not necessary if starkinfra.user was set before function call * * Return: * @returns list of Ledger Log objects with updated attributes and cursor to retrieve the next page of Ledger Log objects * */ let query = { cursor: cursor, ids: ids, limit: limit, after: after, before: before, ledgerId: ledgerId, }; return rest.getPage(resource, query, user); };