@redwoodjs-stripe/api
Version:
API-side code for RedwoodJS-Stripe projects
68 lines (67 loc) • 2.69 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var customers_exports = {};
__export(customers_exports, {
createStripeCustomer: () => createStripeCustomer,
retrieveStripeCustomer: () => retrieveStripeCustomer,
stripeCustomerSearch: () => stripeCustomerSearch
});
module.exports = __toCommonJS(customers_exports);
var import_deepOmitNils = require("../../lib/deepOmitNils.js");
var import_lastStripeObject = require("../../lib/lastStripeObject.js");
var import_nonNilAssertionError = require("../../lib/nonNilAssertionError.js");
var import_parseStripeResponse = require("../../lib/parseStripeResponse.js");
var import_stripe = require("../../lib/stripe.js");
const stripeCustomerSearch = async ({
query
}) => {
const customer = await import_stripe.stripe.customers.search({
query: query ?? ""
});
return (0, import_parseStripeResponse.parseStripeResponse)((0, import_lastStripeObject.lastStripeObject)(customer.data));
};
const retrieveStripeCustomer = async ({
data
}) => {
const { id, addProps } = data ?? {};
if (id == null) {
throw (0, import_nonNilAssertionError.nonNilAssertionError)("retrieveStripeCustomer:id", data);
}
const customer = await import_stripe.stripe.customers.retrieve(
id,
(0, import_deepOmitNils.deepOmitNils)(addProps) ?? {}
);
return (0, import_parseStripeResponse.parseStripeResponse)(customer);
};
const createStripeCustomer = async ({
data
}) => {
const params = (0, import_deepOmitNils.deepOmitNils)(data) ?? {};
if (params.name == null) {
throw (0, import_nonNilAssertionError.nonNilAssertionError)("createStripeCustomer:name", params);
}
const newCustomer = await import_stripe.stripe.customers.create(params);
return (0, import_parseStripeResponse.parseStripeResponse)(newCustomer);
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
createStripeCustomer,
retrieveStripeCustomer,
stripeCustomerSearch
});