chase-moskal / xiome

open-source cloud-powered web components
https://xiome.io/
MIT License
10 stars 13 forks source link

write new obtain-subscription-plans.ts #213

Closed chase-moskal closed 1 year ago

chase-moskal commented 1 year ago

this is a replacement for fetch-subscription-plans.ts

desirable traits of an improved system

chase-moskal commented 1 year ago

ideas for an improved listing service


import * as renraku from "renraku"
import {StoreServiceOptions} from "../../types/options.js"

export const makeSubscriptionListingService = (options: StoreServiceOptions) =>
renraku
.service()
.policy(options.storePolicies.connected)
.expose(auth => ({

    async listPlans() {

        const {planRows, tierRows} =
            await queryDatabaseAboutSubscriptionPlans(auth)

        const {stripeProducts, stripePrices} =
            await queryStripeAboutSubscriptionPlans({
                auth,
                planRows,
                tierRows,
            })

        await performSelfHealingRoutinesForSubscriptionPlans({
            auth,
            planRows,
            tierRows,
            stripeProducts,
            stripePrices,
        })

        return compileDataTogetherIntoSubscriptionPlansForFrontend({
            auth,
            planRows,
            tierRows,
            stripeProducts,
            stripePrices,
        })
    },
}))
chase-moskal commented 1 year ago