UNPKG

autumn-js

Version:
91 lines (90 loc) 2.4 kB
"use server"; import { createAutumnClient } from "../server/cusActions"; import { withAuth } from "./auth/withNextAuth"; import { toServerResponse } from "./utils"; import { toSnakeCase } from "@utils/toSnakeCase"; const attachAction = withAuth({ fn: async (params) => { const autumn = createAutumnClient(); let res = await autumn.attach({ customer_id: params.customerId, customer_data: params.customerData, ...toSnakeCase({ obj: params }) }); return toServerResponse(res); }, withCustomerData: true }); const cancelAction = withAuth({ fn: async (params) => { const autumn = createAutumnClient(); let res = await autumn.cancel(toSnakeCase({ obj: params })); return toServerResponse(res); } }); const checkAction = withAuth({ fn: async (params) => { const autumn = createAutumnClient(); let res = await autumn.check({ customer_id: params.customerId, customer_data: params.customerData, ...toSnakeCase({ obj: params }) }); return toServerResponse(res); }, withCustomerData: true }); const trackAction = withAuth({ fn: async (params) => { const autumn = createAutumnClient(); let res = await autumn.track({ customer_id: params.customerId, customer_data: params.customerData, ...toSnakeCase({ obj: params }) }); return toServerResponse(res); }, withCustomerData: true }); const getBillingPortalAction = withAuth({ fn: async ({ customerId, params }) => { const autumn = createAutumnClient(); let result = await autumn.customers.billingPortal(customerId, params); return toServerResponse(result); } }); const generateReferralCodeAction = withAuth({ fn: async ({ customerId, programId }) => { const autumn = createAutumnClient(); let result = await autumn.referrals.createCode({ customer_id: customerId, program_id: programId }); return toServerResponse(result); } }); const redeemReferralCodeAction = withAuth({ fn: async ({ code, customerId }) => { const autumn = createAutumnClient(); let result = await autumn.referrals.redeemCode({ code, customer_id: customerId }); return toServerResponse(result); } }); export { attachAction, cancelAction, checkAction, generateReferralCodeAction, getBillingPortalAction, redeemReferralCodeAction, trackAction };