UNPKG

payrex-js-sdk

Version:
156 lines (151 loc) 5.38 kB
"use strict"; var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getOwnPropSymbols = Object.getOwnPropertySymbols; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __propIsEnum = Object.prototype.propertyIsEnumerable; var __objRest = (source, exclude) => { var target = {}; for (var prop in source) if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0) target[prop] = source[prop]; if (source != null && __getOwnPropSymbols) for (var prop of __getOwnPropSymbols(source)) { if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop)) target[prop] = source[prop]; } return target; }; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var __async = (__this, __arguments, generator) => { return new Promise((resolve, reject) => { var fulfilled = (value) => { try { step(generator.next(value)); } catch (e) { reject(e); } }; var rejected = (value) => { try { step(generator.throw(value)); } catch (e) { reject(e); } }; var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected); step((generator = generator.apply(__this, __arguments)).next()); }); }; // src/customer/service.ts var service_exports = {}; __export(service_exports, { default: () => CustomerService }); module.exports = __toCommonJS(service_exports); // src/utils.ts var import_qs = __toESM(require("qs"), 1); function formatRequestPayload(params) { return import_qs.default.stringify(params, { arrayFormat: "brackets" }); } // src/customer/dto.ts var CustomerDto = class { constructor(resource) { this.id = resource.id; this.resource = resource.resource; this.billing_statement_prefix = resource.billing_statement_prefix; this.email = resource.email; this.currency = resource.currency; this.livemode = resource.livemode; this.metadata = resource.metadata; this.name = resource.name; this.next_billing_statement_sequence_number = resource.next_billing_statement_sequence_number; this.created_at = resource.created_at; this.updated_at = resource.updated_at; } }; // src/customer/service.ts var CustomerService = class { constructor(client) { this.client = client; this.basePath = "/customers"; } create(params) { return __async(this, null, function* () { const response = yield this.client.send( "post", this.basePath, formatRequestPayload(params) ); return new CustomerDto(response.body); }); } update(_a) { return __async(this, null, function* () { var _b = _a, { id } = _b, params = __objRest(_b, ["id"]); const response = yield this.client.send( "put", `${this.basePath}/${id}`, formatRequestPayload(params) ); return new CustomerDto(response.body); }); } getAll(searchParams) { return __async(this, null, function* () { let finalUrl = this.basePath; if (searchParams) { const _a = searchParams, { limit, metadata } = _a, compatibleParams = __objRest(_a, ["limit", "metadata"]); const queryParams = new URLSearchParams(compatibleParams); if (typeof limit !== "undefined" && limit > 0) { queryParams.append("limit", limit.toString()); } if (typeof metadata !== "undefined") { for (const key in metadata) { queryParams.append(`metadata[${key}]`, metadata[key]); } } finalUrl += `?${queryParams.toString()}`; } const response = yield this.client.send("get", finalUrl); return response.body.data.map( (customer) => new CustomerDto(customer) ); }); } getById(id) { return __async(this, null, function* () { const response = yield this.client.send("get", `${this.basePath}/${id}`); return new CustomerDto(response.body); }); } delete(id) { return __async(this, null, function* () { const response = yield this.client.send("delete", `${this.basePath}/${id}`); return new CustomerDto(response.body); }); } };