**import** http **from** "../../http.app.mjs";
**import** axios **from** "axios";
// Core HTTP component
// Returns a 200 OK response, emits the HTTP payload as an event
export
**default** {
key: "http-new-requests-payload-only",
name: "New Requests (Payload Only)",
// eslint-disable-next-line
description: "Get a URL and emit the HTTP body as an event on every request",
version: "0.1.1",
type: "source",
props: {
// eslint-disable-next-line
httpInterface: {
type: "$.interface.http",
customResponse: **false**,
},
http,
timer: {
type: "$.interface.timer",
**default**: {
cron: "0 0 ** ** **", _// Run job once a day_
},
},
invoice_ninja_auth_api_token: {
type: "string",
optional: **false**,
label: "Invoice Ninja Auth Api Token"
},
invoice_ninja_auth_domain: {
type: "string",
optional: **false**,
label: "Invoice Ninja Auth Domain"
}
},
**async** run(event) {
**const** { body } = event;
/** this.httpInterface.respond({
status: 200,
body,
});
_`**/`_
`**this**.httpInterface.respond({`
`status: 200,`
`body: "Successful processing",`
`headers: {`
`"content-type": "application/json",`
`},`
`});`
//Basic sleep function
async
**function** __sleep(milliseconds) {
**const** date = Date.now();
**let** currentDate = **null**;
**do** {
currentDate = Date.now();
} **while** (currentDate - date < milliseconds);
}
**function** delay(ms) {
return
**new** Promise(resolve => {
setTimeout(resolve, ms);
});
}
**const** results = [];
**let** page = 1;
**let** total = 0;
**do** {
**try**{
`**var** response = **await** axios({`
_`// url: `${this.invoice_ninja.$auth.domain}/api/v1/products/${hashed_id}`,`_
`url: `${**this**.invoice_ninja_auth_domain}/api/v1/invoices/?page=${page}`,`
`headers: {`
`"X-api-Token": `${**this**.invoice_ninja_auth_api_token}`,`
`},`
`data: {`
`status_id:"3"`
`}`
`})`
//console.log(response.data.data)
// console.log(
${this.invoice_ninja_auth_domain}/api/v1/invoices/?page=${page}&created_at=2023-1-01)
results.push(...response.data.data);
console.log(results.length)
total = 10_// response.data.meta.pagination.total;_
page++;
**await** delay(200)
}
**catch**(error){
console.log("Error")
console.log(error)
}
} **while** (results.length < total);
//return results;
**let** count = 1
// Emit the HTTP payload
results.map(product=>{
`**if** (!product.custom_value3 && product.amount!==0 && !product.is_deleted && (!product.number.toLowerCase().includes("delete"))){`
**this*.$emit({body: product}, {
summary:
Emitting row ${count} + product.number,
})
count++
}
`});`
},
};