autumn-js
Version:
Autumn JS Library
103 lines (98 loc) • 3.51 kB
JavaScript
"use client";
;
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);
// src/libraries/react/client/clientGenMethods.ts
var clientGenMethods_exports = {};
__export(clientGenMethods_exports, {
attachMethod: () => attachMethod,
cancelMethod: () => cancelMethod,
checkMethod: () => checkMethod,
checkoutMethod: () => checkoutMethod,
openBillingPortalMethod: () => openBillingPortalMethod,
setupPaymentMethod: () => setupPaymentMethod,
trackMethod: () => trackMethod
});
module.exports = __toCommonJS(clientGenMethods_exports);
// src/libraries/react/utils/toSnakeCase.ts
function stringToSnakeCase(str) {
return str.replace(/([a-z])([A-Z])/g, "$1_$2").replace(/[-\s]+/g, "_").toLowerCase();
}
var toSnakeCase = (obj, excludeKeys) => {
if (Array.isArray(obj)) {
return obj.map((item) => toSnakeCase(item, excludeKeys));
} else if (obj !== null && typeof obj === "object") {
return Object.fromEntries(
Object.entries(obj).map(([key, value]) => {
const snakeKey = stringToSnakeCase(key);
if (excludeKeys && excludeKeys.includes(key)) {
return [snakeKey, value];
}
return [snakeKey, toSnakeCase(value, excludeKeys)];
})
);
}
return obj;
};
// src/libraries/react/client/clientGenMethods.ts
async function checkoutMethod(params) {
let snakeParams = toSnakeCase(params);
const res = await this.post(`${this.prefix}/checkout`, snakeParams);
return res;
}
async function attachMethod(params) {
let snakeParams = toSnakeCase(params, ["checkoutSessionparams"]);
const res = await this.post(`${this.prefix}/attach`, snakeParams);
return res;
}
async function setupPaymentMethod(params) {
let snakeParams = toSnakeCase(params, ["checkoutSessionParams"]);
const res = await this.post(`${this.prefix}/setup_payment`, snakeParams);
return res;
}
async function cancelMethod(params) {
let snakeParams = toSnakeCase(params);
const res = await this.post(`${this.prefix}/cancel`, snakeParams);
return res;
}
async function checkMethod(params) {
let { dialog, ...rest } = params;
let snakeParams = toSnakeCase(rest);
const res = await this.post(`${this.prefix}/check`, snakeParams);
return res;
}
async function trackMethod(params) {
let snakeParams = toSnakeCase(params);
const res = await this.post(`${this.prefix}/track`, snakeParams);
return res;
}
async function openBillingPortalMethod(params) {
let snakeParams = toSnakeCase(params || {});
const res = await this.post(`${this.prefix}/billing_portal`, snakeParams);
return res;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
attachMethod,
cancelMethod,
checkMethod,
checkoutMethod,
openBillingPortalMethod,
setupPaymentMethod,
trackMethod
});