UNPKG

amberflo-metering-typescript

Version:
93 lines 3.81 kB
"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 __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.CustomerDetailsClient = void 0; const baseClient_1 = __importDefault(require("./baseClient")); /** * See: https://docs.amberflo.io/reference/post_customers */ class CustomerDetailsClient extends baseClient_1.default { /** * Initialize a new `CustomerDetailsClient` * `debug`: Whether to issue debug level logs or not. * `retry`: Whether to retry idempotent requests on 5xx or network errors, or retry configuration (see https://github.com/softonic/axios-retry). */ constructor(apiKey, debug = false, retry = true) { super(apiKey, debug, 'CustomerDetailsClient', retry); /** * Convenience method. Performs a `get` followed by either `add` or `update`. * The update has PUT semantics (i.e. it discards existing data). * * This method is provided for backward compatibility. Please prefer using the `.addOrUpdate()` one instead. */ this.post = this.addOrUpdate; } /** * List all customers. */ list() { return __awaiter(this, void 0, void 0, function* () { return this.doGet('/customers'); }); } /** * Get customer by id. */ get(customerId) { return __awaiter(this, void 0, void 0, function* () { return this.doGet('/customers', { customerId }); }); } /** * Add a new customer. * See: https://docs.amberflo.io/reference/post_customers * `createInStripe`: Whether or not to add create the customer in Stripe and add a `stripeId` trait to the customer. */ add(payload, createInStripe = false) { return __awaiter(this, void 0, void 0, function* () { payload.validate(); const params = createInStripe ? { autoCreateCustomerInStripe: true } : undefined; return this.doPost('/customers', payload, params); }); } /** * Update an existing customer. * This has PUT semantics (i.e. it discards existing data). * See: https://docs.amberflo.io/reference/put_customers-customer-id */ update(payload) { return __awaiter(this, void 0, void 0, function* () { payload.validate(); return this.doPut('/customers', payload); }); } /** * Convenience method. Performs a `get` followed by either `add` or `update`. * The update has PUT semantics (i.e. it discards existing data). */ addOrUpdate(payload) { return __awaiter(this, void 0, void 0, function* () { payload.validate(); const customer = yield this.get(payload.customerId); if (customer.id) { return this.update(payload); } else { return this.add(payload); } }); } } exports.CustomerDetailsClient = CustomerDetailsClient; //# sourceMappingURL=customerDetailsClient.js.map