Skip to content

Built for people who want to own their automations. Join the waitlist for an invite.

Package listing

@kody/stripe

src/index.ts

214 lines · 4.9 KB · TypeScript
export {
	API_BASE_URL,
	API_HOST,
	API_KEY_SETUP_URL,
	DASHBOARD_API_KEYS_URL,
	DASHBOARD_WEBHOOKS_URL,
	DEFAULT_API_KEY_SECRET,
	DEFAULT_WEBHOOK_SECRET,
	FILES_BASE_URL,
	FILES_HOST,
	StripeApiError,
	WEBHOOK_SECRET_SETUP_URL,
	formatStripeAmount,
	mutationPreview,
	resolveApiKeySecretName,
	resolveWebhookSecretName,
	secretSetupUrl,
	stripeDate,
	stripeList,
	stripeParams,
	stripeRequest,
	stripeSearch,
	stripeUploadFile,
	webhookSecretSetupUrl,
} from './stripe-core.ts'
export {
	getAccount,
	getBalance,
	listBalanceTransactions,
	listEvents,
	listPayouts,
} from './account.ts'
export {
	createCustomer,
	deleteCustomer,
	getCustomer,
	listCustomers,
	searchCustomers,
	updateCustomer,
} from './customers.ts'
export {
	createRefund,
	getCharge,
	getPaymentIntent,
	listCharges,
	listPaymentIntents,
	listRefunds,
	searchCharges,
	searchPaymentIntents,
} from './payments.ts'
export {
	createInvoice,
	deleteDraftInvoice,
	finalizeInvoice,
	getInvoice,
	listInvoices,
	searchInvoices,
	sendInvoice,
	voidInvoice,
} from './invoices.ts'
export {
	cancelSubscription,
	createSubscription,
	getSubscription,
	listSubscriptions,
	searchSubscriptions,
} from './subscriptions.ts'
export {
	archiveProduct,
	createPaymentLink,
	createPrice,
	createProduct,
	deactivatePaymentLink,
	getProduct,
	listPaymentLinks,
	listPrices,
	listProducts,
} from './products.ts'
export {
	createTestSignatureHeader,
	getWebhookEndpoint,
	listWebhookEndpoints,
	loadVerifiedEvent,
	verifyWebhookSignature,
} from './webhooks.ts'
export { smokeTest } from './smoke-test.ts'

import {
	getAccount,
	getBalance,
	listBalanceTransactions,
	listEvents,
	listPayouts,
} from './account.ts'
import {
	createCustomer,
	deleteCustomer,
	getCustomer,
	listCustomers,
	searchCustomers,
	updateCustomer,
} from './customers.ts'
import {
	createInvoice,
	deleteDraftInvoice,
	finalizeInvoice,
	getInvoice,
	listInvoices,
	searchInvoices,
	sendInvoice,
	voidInvoice,
} from './invoices.ts'
import {
	createRefund,
	getCharge,
	getPaymentIntent,
	listCharges,
	listPaymentIntents,
	listRefunds,
	searchCharges,
	searchPaymentIntents,
} from './payments.ts'
import {
	archiveProduct,
	createPaymentLink,
	createPrice,
	createProduct,
	deactivatePaymentLink,
	getProduct,
	listPaymentLinks,
	listPrices,
	listProducts,
} from './products.ts'
import { smokeTest } from './smoke-test.ts'
import { parseAction, stripeRequest } from './stripe-core.ts'
import {
	cancelSubscription,
	createSubscription,
	getSubscription,
	listSubscriptions,
	searchSubscriptions,
} from './subscriptions.ts'
import {
	getWebhookEndpoint,
	listWebhookEndpoints,
	loadVerifiedEvent,
	verifyWebhookSignature,
} from './webhooks.ts'

const actions = {
	'smoke-test': smokeTest,
	'get-account': getAccount,
	'get-balance': getBalance,
	'list-balance-transactions': listBalanceTransactions,
	'list-payouts': listPayouts,
	'list-events': listEvents,
	'list-customers': listCustomers,
	'search-customers': searchCustomers,
	'get-customer': getCustomer,
	'create-customer': createCustomer,
	'update-customer': updateCustomer,
	'delete-customer': deleteCustomer,
	'list-payment-intents': listPaymentIntents,
	'get-payment-intent': getPaymentIntent,
	'search-payment-intents': searchPaymentIntents,
	'list-charges': listCharges,
	'get-charge': getCharge,
	'search-charges': searchCharges,
	'list-refunds': listRefunds,
	'create-refund': createRefund,
	'list-invoices': listInvoices,
	'get-invoice': getInvoice,
	'search-invoices': searchInvoices,
	'create-invoice': createInvoice,
	'finalize-invoice': finalizeInvoice,
	'send-invoice': sendInvoice,
	'void-invoice': voidInvoice,
	'delete-draft-invoice': deleteDraftInvoice,
	'list-subscriptions': listSubscriptions,
	'get-subscription': getSubscription,
	'search-subscriptions': searchSubscriptions,
	'create-subscription': createSubscription,
	'cancel-subscription': cancelSubscription,
	'list-products': listProducts,
	'get-product': getProduct,
	'create-product': createProduct,
	'archive-product': archiveProduct,
	'list-prices': listPrices,
	'create-price': createPrice,
	'list-payment-links': listPaymentLinks,
	'create-payment-link': createPaymentLink,
	'deactivate-payment-link': deactivatePaymentLink,
	'verify-webhook-signature': verifyWebhookSignature,
	'load-verified-event': loadVerifiedEvent,
	'list-webhook-endpoints': listWebhookEndpoints,
	'get-webhook-endpoint': getWebhookEndpoint,
	request: stripeRequest,
} as const

export type StripeAction = keyof typeof actions

const actionNames = Object.keys(actions) as StripeAction[]

/**
 * Root dispatcher for Stripe helpers. Defaults to the read-only smoke test.
 * @example
 * import stripe from 'kody:@kody/stripe'
 * const result = await stripe({ action: 'list-customers', email: 'ada@example.com' })
 */
export default async function stripe(input: Record<string, unknown> = {}) {
	const action = parseAction(input.action, actionNames, 'smoke-test', 'Stripe')
	const handler = actions[action]
	return await handler(input as never)
}