autumn-js
Version:
Autumn JS Library
81 lines (80 loc) • 1.73 kB
JavaScript
"use server";
import {
Autumn
} from "../../sdk";
import { withAuth } from "./auth/withAuth";
import { toServerResponse } from "./utils";
const createAutumnClient = (publishableKey) => {
return new Autumn({
publishableKey
});
};
const getOrCreateCustomer = withAuth({
fn: async ({
customerId,
customerData,
params
}) => {
const autumn = createAutumnClient();
const result = await autumn.customers.create({
id: customerId,
...customerData,
...params
});
return toServerResponse(result);
},
withCustomerData: true
});
const getCustomer = withAuth({
fn: async ({
customerId,
params
}) => {
const autumn = createAutumnClient();
const result = await autumn.customers.get(customerId, params);
return toServerResponse(result);
}
});
const getEntityAction = withAuth({
fn: async ({
customerId,
entityId,
params
}) => {
const autumn = createAutumnClient();
const result = await autumn.entities.get(
customerId,
entityId,
params
);
return toServerResponse(result);
}
});
const createEntityAction = withAuth({
fn: async ({
customerId,
entity
}) => {
const autumn = createAutumnClient();
const result = await autumn.entities.create(customerId, entity);
return toServerResponse(result);
}
});
const deleteEntityAction = withAuth({
fn: async ({
customerId,
entityId
}) => {
const autumn = createAutumnClient();
const result = await autumn.entities.delete(customerId, entityId);
return toServerResponse(result);
}
});
export {
createAutumnClient,
createEntityAction,
deleteEntityAction,
getCustomer,
getEntityAction,
getOrCreateCustomer
};