@flexbase/onbo-node-client
Advanced tools
| import type { Onbo, OnboOptions, OnboError } from '../'; | ||
| import type { WebhookApi, Endpoint } from './'; | ||
| export declare class EndpointApi { | ||
| client: Onbo; | ||
| webhook: WebhookApi; | ||
| constructor(client: Onbo, webhook: WebhookApi, _options?: OnboOptions); | ||
| create(data: Partial<Endpoint>): Promise<{ | ||
| success: boolean; | ||
| endpoint?: Endpoint; | ||
| error?: OnboError; | ||
| }>; | ||
| byId(endpointId: string): Promise<{ | ||
| success: boolean; | ||
| endpoint?: Endpoint; | ||
| error?: OnboError; | ||
| }>; | ||
| byUrl(endpointUrl: string): Promise<{ | ||
| success: boolean; | ||
| endpoint?: Endpoint; | ||
| error?: OnboError; | ||
| }>; | ||
| update(endpointId: string, data: Partial<Endpoint>): Promise<{ | ||
| success: boolean; | ||
| endpoint?: Endpoint; | ||
| error?: OnboError; | ||
| }>; | ||
| delete(endpointId: string): Promise<{ | ||
| success: boolean; | ||
| error?: OnboError; | ||
| }>; | ||
| list(): Promise<{ | ||
| success: boolean; | ||
| endpoints?: Endpoint[]; | ||
| error?: OnboError; | ||
| }>; | ||
| recoverFailedMessages(endpointId: string, data?: { | ||
| startDate?: string; | ||
| }): Promise<{ | ||
| success: boolean; | ||
| error?: OnboError; | ||
| }>; | ||
| } |
| "use strict"; | ||
| var __assign = (this && this.__assign) || function () { | ||
| __assign = Object.assign || function(t) { | ||
| for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
| s = arguments[i]; | ||
| for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
| t[p] = s[p]; | ||
| } | ||
| return t; | ||
| }; | ||
| return __assign.apply(this, arguments); | ||
| }; | ||
| var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
| function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
| return new (P || (P = Promise))(function (resolve, reject) { | ||
| function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
| function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
| function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
| step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
| }); | ||
| }; | ||
| var __generator = (this && this.__generator) || function (thisArg, body) { | ||
| var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
| return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
| function verb(n) { return function (v) { return step([n, v]); }; } | ||
| function step(op) { | ||
| if (f) throw new TypeError("Generator is already executing."); | ||
| while (_) try { | ||
| if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
| if (y = 0, t) op = [op[0] & 2, t.value]; | ||
| switch (op[0]) { | ||
| case 0: case 1: t = op; break; | ||
| case 4: _.label++; return { value: op[1], done: false }; | ||
| case 5: _.label++; y = op[1]; op = [0]; continue; | ||
| case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
| default: | ||
| if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
| if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
| if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
| if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
| if (t[2]) _.ops.pop(); | ||
| _.trys.pop(); continue; | ||
| } | ||
| op = body.call(thisArg, _); | ||
| } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
| if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
| } | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.EndpointApi = void 0; | ||
| var __1 = require("../"); | ||
| var EndpointApi = /** @class */ (function () { | ||
| function EndpointApi(client, webhook, _options) { | ||
| this.client = client; | ||
| this.webhook = webhook; | ||
| } | ||
| /* | ||
| * Function to create a new webhook endpoint for messages from Onbo to | ||
| * be sent. Onbo will send all messages to all endpoints, unless the | ||
| * endpoint is created with a specific list of events to receive. | ||
| */ | ||
| EndpointApi.prototype.create = function (data) { | ||
| var _a, _b, _c; | ||
| return __awaiter(this, void 0, void 0, function () { | ||
| var resp; | ||
| return __generator(this, function (_d) { | ||
| switch (_d.label) { | ||
| case 0: return [4 /*yield*/, this.client.fire('POST', 'webhooks/endpoints', undefined, undefined, data)]; | ||
| case 1: | ||
| resp = _d.sent(); | ||
| if ((((_a = resp === null || resp === void 0 ? void 0 : resp.response) === null || _a === void 0 ? void 0 : _a.status) >= 400) || !(0, __1.isEmpty)((_b = resp === null || resp === void 0 ? void 0 : resp.payload) === null || _b === void 0 ? void 0 : _b.message)) { | ||
| return [2 /*return*/, { | ||
| success: false, | ||
| error: { type: 'onbo', message: (_c = resp === null || resp === void 0 ? void 0 : resp.payload) === null || _c === void 0 ? void 0 : _c.message }, | ||
| }]; | ||
| } | ||
| return [2 /*return*/, { success: true, endpoint: resp === null || resp === void 0 ? void 0 : resp.payload }]; | ||
| } | ||
| }); | ||
| }); | ||
| }; | ||
| /* | ||
| * Function to return a single endpoint created for this Onbo account. | ||
| * This will be based on the Onbo 'uuid' identifier for the endpoint. | ||
| */ | ||
| EndpointApi.prototype.byId = function (endpointId) { | ||
| var _a, _b, _c; | ||
| return __awaiter(this, void 0, void 0, function () { | ||
| var resp; | ||
| return __generator(this, function (_d) { | ||
| switch (_d.label) { | ||
| case 0: return [4 /*yield*/, this.client.fire('GET', "webhooks/endpoints/".concat(endpointId))]; | ||
| case 1: | ||
| resp = _d.sent(); | ||
| if ((((_a = resp === null || resp === void 0 ? void 0 : resp.response) === null || _a === void 0 ? void 0 : _a.status) >= 400) || !(0, __1.isEmpty)((_b = resp === null || resp === void 0 ? void 0 : resp.payload) === null || _b === void 0 ? void 0 : _b.message)) { | ||
| return [2 /*return*/, { | ||
| success: false, | ||
| error: { type: 'onbo', message: (_c = resp === null || resp === void 0 ? void 0 : resp.payload) === null || _c === void 0 ? void 0 : _c.message }, | ||
| }]; | ||
| } | ||
| return [2 /*return*/, { success: true, endpoint: resp === null || resp === void 0 ? void 0 : resp.payload }]; | ||
| } | ||
| }); | ||
| }); | ||
| }; | ||
| /* | ||
| * Function to return a single endpoint created for this Onbo account. | ||
| * This will be based on the URL provided during the creation of the | ||
| * endpoint. | ||
| */ | ||
| EndpointApi.prototype.byUrl = function (endpointUrl) { | ||
| var _a; | ||
| return __awaiter(this, void 0, void 0, function () { | ||
| var lst, endpoint; | ||
| return __generator(this, function (_b) { | ||
| switch (_b.label) { | ||
| case 0: return [4 /*yield*/, this.list()]; | ||
| case 1: | ||
| lst = _b.sent(); | ||
| if (!(lst === null || lst === void 0 ? void 0 : lst.success)) { | ||
| return [2 /*return*/, __assign(__assign({}, lst), { success: false })]; | ||
| } | ||
| endpoint = (_a = lst.endpoints) === null || _a === void 0 ? void 0 : _a.find(function (ep) { return ep.url === endpointUrl; }); | ||
| return [2 /*return*/, { success: !!endpoint, endpoint: endpoint }]; | ||
| } | ||
| }); | ||
| }); | ||
| }; | ||
| /* | ||
| * Function to update an endpoint created for this Onbo account. | ||
| * This will be based on the Onbo 'uuid' identifier for the endpoint. | ||
| */ | ||
| EndpointApi.prototype.update = function (endpointId, data) { | ||
| var _a, _b, _c; | ||
| return __awaiter(this, void 0, void 0, function () { | ||
| var resp; | ||
| return __generator(this, function (_d) { | ||
| switch (_d.label) { | ||
| case 0: return [4 /*yield*/, this.client.fire('PUT', "webhooks/endpoints/".concat(endpointId), undefined, undefined, data)]; | ||
| case 1: | ||
| resp = _d.sent(); | ||
| if ((((_a = resp === null || resp === void 0 ? void 0 : resp.response) === null || _a === void 0 ? void 0 : _a.status) >= 400) || !(0, __1.isEmpty)((_b = resp === null || resp === void 0 ? void 0 : resp.payload) === null || _b === void 0 ? void 0 : _b.message)) { | ||
| return [2 /*return*/, { | ||
| success: false, | ||
| error: { type: 'onbo', message: (_c = resp === null || resp === void 0 ? void 0 : resp.payload) === null || _c === void 0 ? void 0 : _c.message }, | ||
| }]; | ||
| } | ||
| return [2 /*return*/, { success: true, endpoint: resp === null || resp === void 0 ? void 0 : resp.payload }]; | ||
| } | ||
| }); | ||
| }); | ||
| }; | ||
| /* | ||
| * Function to delete an endpoint created for this Onbo account. | ||
| * This will be based on the Onbo 'uuid' identifier for the endpoint. | ||
| */ | ||
| EndpointApi.prototype.delete = function (endpointId) { | ||
| var _a, _b, _c; | ||
| return __awaiter(this, void 0, void 0, function () { | ||
| var resp; | ||
| return __generator(this, function (_d) { | ||
| switch (_d.label) { | ||
| case 0: return [4 /*yield*/, this.client.fire('DELETE', "webhooks/endpoints/".concat(endpointId))]; | ||
| case 1: | ||
| resp = _d.sent(); | ||
| if ((((_a = resp === null || resp === void 0 ? void 0 : resp.response) === null || _a === void 0 ? void 0 : _a.status) >= 400) || !(0, __1.isEmpty)((_b = resp === null || resp === void 0 ? void 0 : resp.payload) === null || _b === void 0 ? void 0 : _b.message)) { | ||
| return [2 /*return*/, { | ||
| success: false, | ||
| error: { type: 'onbo', message: (_c = resp === null || resp === void 0 ? void 0 : resp.payload) === null || _c === void 0 ? void 0 : _c.message }, | ||
| }]; | ||
| } | ||
| return [2 /*return*/, { success: true }]; | ||
| } | ||
| }); | ||
| }); | ||
| }; | ||
| /* | ||
| * Function to return a list of all the endpoints defined for this Onbo | ||
| * account. Unlike the other listing functions, there is no pagination | ||
| * for this call - and all endpoints will be pulled on each call. | ||
| */ | ||
| EndpointApi.prototype.list = function () { | ||
| var _a, _b, _c; | ||
| return __awaiter(this, void 0, void 0, function () { | ||
| var resp; | ||
| return __generator(this, function (_d) { | ||
| switch (_d.label) { | ||
| case 0: return [4 /*yield*/, this.client.fire('GET', 'webhooks/endpoints')]; | ||
| case 1: | ||
| resp = _d.sent(); | ||
| if ((((_a = resp === null || resp === void 0 ? void 0 : resp.response) === null || _a === void 0 ? void 0 : _a.status) >= 400) || !(0, __1.isEmpty)((_b = resp === null || resp === void 0 ? void 0 : resp.payload) === null || _b === void 0 ? void 0 : _b.message)) { | ||
| return [2 /*return*/, { | ||
| success: false, | ||
| error: { type: 'onbo', message: (_c = resp === null || resp === void 0 ? void 0 : resp.payload) === null || _c === void 0 ? void 0 : _c.message }, | ||
| }]; | ||
| } | ||
| return [2 /*return*/, { success: true, endpoints: resp === null || resp === void 0 ? void 0 : resp.payload }]; | ||
| } | ||
| }); | ||
| }); | ||
| }; | ||
| /* | ||
| * Function to resend (recover) all failed messages for this Onbo account. | ||
| * The optional 'startDate' needs to be of the form 'YYYY-MM-DD', and | ||
| * will indicate the starting date of the missed messages to resend. | ||
| */ | ||
| EndpointApi.prototype.recoverFailedMessages = function (endpointId, data) { | ||
| var _a, _b, _c; | ||
| return __awaiter(this, void 0, void 0, function () { | ||
| var resp; | ||
| return __generator(this, function (_d) { | ||
| switch (_d.label) { | ||
| case 0: return [4 /*yield*/, this.client.fire('POST', "webhooks/endpoints/".concat(endpointId, "/resend"), undefined, undefined, data)]; | ||
| case 1: | ||
| resp = _d.sent(); | ||
| if ((((_a = resp === null || resp === void 0 ? void 0 : resp.response) === null || _a === void 0 ? void 0 : _a.status) >= 400) || !(0, __1.isEmpty)((_b = resp === null || resp === void 0 ? void 0 : resp.payload) === null || _b === void 0 ? void 0 : _b.message)) { | ||
| return [2 /*return*/, { | ||
| success: false, | ||
| error: { type: 'onbo', message: (_c = resp === null || resp === void 0 ? void 0 : resp.payload) === null || _c === void 0 ? void 0 : _c.message }, | ||
| }]; | ||
| } | ||
| return [2 /*return*/, { success: true }]; | ||
| } | ||
| }); | ||
| }); | ||
| }; | ||
| return EndpointApi; | ||
| }()); | ||
| exports.EndpointApi = EndpointApi; |
| import type { Onbo, OnboOptions } from '../'; | ||
| import { EndpointApi } from './endpoint'; | ||
| import { MessageApi } from './message'; | ||
| export interface Endpoint { | ||
| uuid: string; | ||
| url: string; | ||
| description?: string; | ||
| events?: string[]; | ||
| } | ||
| export interface Message { | ||
| uuid: string; | ||
| event: string; | ||
| payload: { | ||
| fees?: any; | ||
| uuid: string; | ||
| achId: string; | ||
| amount: number; | ||
| status: string; | ||
| product: string; | ||
| interest: any; | ||
| suspense: any; | ||
| principal: any; | ||
| achBatchId: string; | ||
| paymentType: any; | ||
| effectiveDate: string; | ||
| endingBalance: number; | ||
| completionDate: string; | ||
| initiationDate: string; | ||
| errorDescription: string; | ||
| borrowerBankAccountUuid: string; | ||
| }; | ||
| status: string; | ||
| createdAt: string; | ||
| } | ||
| export declare class WebhookApi { | ||
| client: Onbo; | ||
| endpoint: EndpointApi; | ||
| message: MessageApi; | ||
| constructor(client: Onbo, options?: OnboOptions); | ||
| isValid(url: string, headers: any, body: object): boolean; | ||
| } |
| "use strict"; | ||
| var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
| if (k2 === undefined) k2 = k; | ||
| var desc = Object.getOwnPropertyDescriptor(m, k); | ||
| if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
| desc = { enumerable: true, get: function() { return m[k]; } }; | ||
| } | ||
| Object.defineProperty(o, k2, desc); | ||
| }) : (function(o, m, k, k2) { | ||
| if (k2 === undefined) k2 = k; | ||
| o[k2] = m[k]; | ||
| })); | ||
| var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
| Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
| }) : function(o, v) { | ||
| o["default"] = v; | ||
| }); | ||
| var __importStar = (this && this.__importStar) || function (mod) { | ||
| if (mod && mod.__esModule) return mod; | ||
| var result = {}; | ||
| if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
| __setModuleDefault(result, mod); | ||
| return result; | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.WebhookApi = void 0; | ||
| var CryptoJS = __importStar(require("crypto-js")); | ||
| var endpoint_1 = require("./endpoint"); | ||
| var message_1 = require("./message"); | ||
| var WebhookApi = /** @class */ (function () { | ||
| function WebhookApi(client, options) { | ||
| this.client = client; | ||
| // now construct all the specific domain objects | ||
| this.endpoint = new endpoint_1.EndpointApi(this.client, this, options); | ||
| this.message = new message_1.MessageApi(this.client, this, options); | ||
| } | ||
| /* | ||
| * Function to take the endpoint URL, and the headers and body of the | ||
| * webhook call from Onbo, and verify that they HMAC hashing matches | ||
| * what they sent, and so this message is valid. | ||
| */ | ||
| WebhookApi.prototype.isValid = function (url, headers, body) { | ||
| var epoch = headers['EPOCH']; | ||
| var stripped = JSON.stringify(body).replace(/(\r\n|\n|\r|\s+)/gm, ''); | ||
| var md5 = ''; | ||
| if (stripped !== '') { | ||
| md5 = CryptoJS.MD5(stripped).toString(); | ||
| } | ||
| var hmac = CryptoJS.HmacSHA256(url + md5 + epoch, this.client.secret).toString(); | ||
| return (headers['X_STILT_HMAC'] === hmac); | ||
| }; | ||
| return WebhookApi; | ||
| }()); | ||
| exports.WebhookApi = WebhookApi; |
| import type { Onbo, OnboOptions, OnboError, OnboPagination } from '../'; | ||
| import type { WebhookApi, Message } from './'; | ||
| export declare class MessageApi { | ||
| client: Onbo; | ||
| webhook: WebhookApi; | ||
| constructor(client: Onbo, webhook: WebhookApi, _options?: OnboOptions); | ||
| byId(messageId: string): Promise<{ | ||
| success: boolean; | ||
| message?: Message; | ||
| error?: OnboError; | ||
| }>; | ||
| list(options?: { | ||
| startDate?: string; | ||
| endDate?: string; | ||
| event?: string; | ||
| offset?: number; | ||
| limit?: number; | ||
| }): Promise<{ | ||
| success: boolean; | ||
| messages?: Message[]; | ||
| error?: OnboError; | ||
| pagination?: OnboPagination; | ||
| }>; | ||
| recoverFailedMessage(messageId: string): Promise<{ | ||
| success: boolean; | ||
| error?: OnboError; | ||
| }>; | ||
| } |
| "use strict"; | ||
| var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
| function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
| return new (P || (P = Promise))(function (resolve, reject) { | ||
| function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
| function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
| function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
| step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
| }); | ||
| }; | ||
| var __generator = (this && this.__generator) || function (thisArg, body) { | ||
| var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
| return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
| function verb(n) { return function (v) { return step([n, v]); }; } | ||
| function step(op) { | ||
| if (f) throw new TypeError("Generator is already executing."); | ||
| while (_) try { | ||
| if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
| if (y = 0, t) op = [op[0] & 2, t.value]; | ||
| switch (op[0]) { | ||
| case 0: case 1: t = op; break; | ||
| case 4: _.label++; return { value: op[1], done: false }; | ||
| case 5: _.label++; y = op[1]; op = [0]; continue; | ||
| case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
| default: | ||
| if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
| if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
| if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
| if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
| if (t[2]) _.ops.pop(); | ||
| _.trys.pop(); continue; | ||
| } | ||
| op = body.call(thisArg, _); | ||
| } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
| if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
| } | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.MessageApi = void 0; | ||
| var __1 = require("../"); | ||
| var MessageApi = /** @class */ (function () { | ||
| function MessageApi(client, webhook, _options) { | ||
| this.client = client; | ||
| this.webhook = webhook; | ||
| } | ||
| /* | ||
| * Function to return a single message sent by Onbo to properly created | ||
| * webhook endpoints. This will be based on the Onbo 'uuid' identifier | ||
| * for the message. | ||
| */ | ||
| MessageApi.prototype.byId = function (messageId) { | ||
| var _a, _b, _c; | ||
| return __awaiter(this, void 0, void 0, function () { | ||
| var resp; | ||
| return __generator(this, function (_d) { | ||
| switch (_d.label) { | ||
| case 0: return [4 /*yield*/, this.client.fire('GET', "webhooks/endpoints/messages/".concat(messageId))]; | ||
| case 1: | ||
| resp = _d.sent(); | ||
| if ((((_a = resp === null || resp === void 0 ? void 0 : resp.response) === null || _a === void 0 ? void 0 : _a.status) >= 400) || !(0, __1.isEmpty)((_b = resp === null || resp === void 0 ? void 0 : resp.payload) === null || _b === void 0 ? void 0 : _b.message)) { | ||
| return [2 /*return*/, { | ||
| success: false, | ||
| error: { type: 'onbo', message: (_c = resp === null || resp === void 0 ? void 0 : resp.payload) === null || _c === void 0 ? void 0 : _c.message }, | ||
| }]; | ||
| } | ||
| return [2 /*return*/, { success: true, message: resp === null || resp === void 0 ? void 0 : resp.payload }]; | ||
| } | ||
| }); | ||
| }); | ||
| }; | ||
| /* | ||
| * Function to return a list of all the sent by Onbo to any of the | ||
| * endpoints defined for this account. This will include the standard | ||
| * Onbo pagination parameters, but also the the startDate, endDate, | ||
| * and event type for filtering. | ||
| */ | ||
| MessageApi.prototype.list = function (options) { | ||
| var _a, _b, _c, _d, _e; | ||
| return __awaiter(this, void 0, void 0, function () { | ||
| var resp; | ||
| return __generator(this, function (_f) { | ||
| switch (_f.label) { | ||
| case 0: return [4 /*yield*/, this.client.fire('GET', 'webhooks/endpoints/messages', undefined, (0, __1.mkQueryParams)(options))]; | ||
| case 1: | ||
| resp = _f.sent(); | ||
| if ((((_a = resp === null || resp === void 0 ? void 0 : resp.response) === null || _a === void 0 ? void 0 : _a.status) >= 400) || !(0, __1.isEmpty)((_b = resp === null || resp === void 0 ? void 0 : resp.payload) === null || _b === void 0 ? void 0 : _b.message)) { | ||
| return [2 /*return*/, { | ||
| success: false, | ||
| error: { type: 'onbo', message: (_c = resp === null || resp === void 0 ? void 0 : resp.payload) === null || _c === void 0 ? void 0 : _c.message }, | ||
| }]; | ||
| } | ||
| return [2 /*return*/, { | ||
| success: true, | ||
| messages: (_d = resp === null || resp === void 0 ? void 0 : resp.payload) === null || _d === void 0 ? void 0 : _d.data, | ||
| pagination: (_e = resp === null || resp === void 0 ? void 0 : resp.payload) === null || _e === void 0 ? void 0 : _e.pagination, | ||
| }]; | ||
| } | ||
| }); | ||
| }); | ||
| }; | ||
| /* | ||
| * Function to resend (recover) a specific failed message for this Onbo | ||
| * account. This will be resent on the existing webhook scheme, so this | ||
| * really just asks Onbo to queue it up. | ||
| */ | ||
| MessageApi.prototype.recoverFailedMessage = function (messageId) { | ||
| var _a, _b, _c; | ||
| return __awaiter(this, void 0, void 0, function () { | ||
| var resp; | ||
| return __generator(this, function (_d) { | ||
| switch (_d.label) { | ||
| case 0: return [4 /*yield*/, this.client.fire('POST', "webhooks/endpoints/messages/".concat(messageId, "/resend"))]; | ||
| case 1: | ||
| resp = _d.sent(); | ||
| if ((((_a = resp === null || resp === void 0 ? void 0 : resp.response) === null || _a === void 0 ? void 0 : _a.status) >= 400) || !(0, __1.isEmpty)((_b = resp === null || resp === void 0 ? void 0 : resp.payload) === null || _b === void 0 ? void 0 : _b.message)) { | ||
| return [2 /*return*/, { | ||
| success: false, | ||
| error: { type: 'onbo', message: (_c = resp === null || resp === void 0 ? void 0 : resp.payload) === null || _c === void 0 ? void 0 : _c.message }, | ||
| }]; | ||
| } | ||
| return [2 /*return*/, { success: true }]; | ||
| } | ||
| }); | ||
| }); | ||
| }; | ||
| return MessageApi; | ||
| }()); | ||
| exports.MessageApi = MessageApi; |
+2
-0
| import FormData = require('formdata'); | ||
| import { UserApi } from './user'; | ||
| import { LineOfCreditApi } from './loc'; | ||
| import { WebhookApi } from './webhook'; | ||
| export interface OnboOptions { | ||
@@ -25,2 +26,3 @@ host?: string; | ||
| loc: LineOfCreditApi; | ||
| webhook: WebhookApi; | ||
| constructor(clientId: string, secret: string, options?: OnboOptions); | ||
@@ -27,0 +29,0 @@ fire(method: string, uri: string, headers?: any, query?: { |
+11
-0
@@ -84,2 +84,3 @@ "use strict"; | ||
| var loc_1 = require("./loc"); | ||
| var webhook_1 = require("./webhook"); | ||
| var ClientVersion = require('../package.json').version; | ||
@@ -108,2 +109,3 @@ var PROTOCOL = 'https'; | ||
| this.loc = new loc_1.LineOfCreditApi(this, options); | ||
| this.webhook = new webhook_1.WebhookApi(this, options); | ||
| } | ||
@@ -290,2 +292,11 @@ /* | ||
| } | ||
| if (!isEmpty(arg === null || arg === void 0 ? void 0 : arg.event)) { | ||
| ans['event'] = arg.event; | ||
| } | ||
| if (!isEmpty(arg === null || arg === void 0 ? void 0 : arg.startDate)) { | ||
| ans['start_date'] = arg.startDate; | ||
| } | ||
| if (!isEmpty(arg === null || arg === void 0 ? void 0 : arg.endDate)) { | ||
| ans['end_date'] = arg.endDate; | ||
| } | ||
| return ans; | ||
@@ -292,0 +303,0 @@ } |
+1
-1
| { | ||
| "name": "@flexbase/onbo-node-client", | ||
| "version": "0.4.15", | ||
| "version": "0.5.0", | ||
| "description": "Node.js Client for Onbo API", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
137746
23.87%24
33.33%2321
29.96%