UNPKG

autumn-js

Version:

Autumn JS Library

107 lines (105 loc) 2.65 kB
"use client"; import { AutumnClient } from "../../libraries/react/client/ReactAutumnClient"; import { createCusAction, createEntityAction, deleteEntityAction, getEntityAction } from "../server/cusActions"; import { getPricingTableAction } from "../server/componentActions"; import { attachAction, cancelAction, checkAction, getBillingPortalAction, trackAction } from "../server/genActions"; class NextAutumnClient extends AutumnClient { encryptedCustomerId; constructor({ encryptedCustomerId, customerData }) { super({ customerData }); this.encryptedCustomerId = encryptedCustomerId; } // Override createCustomer to use Next.js server actions instead of HTTP requests async createCustomer(params) { const res = await createCusAction({ encryptedCustomerId: this.encryptedCustomerId, customerData: this.customerData, ...params }); return res; } // Pricing table async getPricingTable() { return await getPricingTableAction({ encryptedCustomerId: this.encryptedCustomerId }); } // Entities attach = async (params) => { const res = await attachAction({ encryptedCustomerId: this.encryptedCustomerId, customerData: this.customerData, ...params }); return res; }; cancel = async (params) => { return await cancelAction({ encryptedCustomerId: this.encryptedCustomerId, ...params }); }; check = async (params) => { return await checkAction({ encryptedCustomerId: this.encryptedCustomerId, ...params }); }; track = async (params) => { return await trackAction({ encryptedCustomerId: this.encryptedCustomerId, ...params }); }; openBillingPortal = async (params) => { return await getBillingPortalAction({ encryptedCustomerId: this.encryptedCustomerId, ...params || {} }); }; entities = { create: async (params) => { return await createEntityAction({ encryptedCustomerId: this.encryptedCustomerId, entity: params }); }, get: async (entityId, params) => { return await getEntityAction({ encryptedCustomerId: this.encryptedCustomerId, entityId, ...params }); }, delete: async (entityId) => { return await deleteEntityAction({ encryptedCustomerId: this.encryptedCustomerId, entityId }); } }; referrals = { createCode: async (params) => { throw new Error("Not implemented"); }, redeemCode: async (params) => { throw new Error("Not implemented"); } }; } export { NextAutumnClient };