UNPKG

@tolinax/ayoune

Version:

aYOUne - Business as a Service

40 lines (32 loc) 1.07 kB
import {IaYOUne} from "../aYOUne"; import {IAPIResult} from "@tolinax/ayoune-interfaces"; export class aYOUneApiResponseWrapper { response:IAPIResult; sdkInstance: IaYOUne; constructor(response:IAPIResult, sdkInstance:IaYOUne) { this.response = response; this.sdkInstance = sdkInstance; } // Return the rate limit information rateLimit() { return this.response.meta?.rateLimit; } // Return the links from the last response links() { return this.response.meta?.links; } // Retrieve the next page based on the 'next' link async next(): Promise<aYOUneApiResponseWrapper> { const nextLink = this.response.meta?.links.find(link => link.rel === "next"); if (nextLink) { return this.sdkInstance.fetchByUrl(nextLink.href); } throw new Error("Next page link not found."); } payload() { if (this.sdkInstance.queryParams?.hideMeta === 'true') { return this.response; } return this.response.payload; } }