Skip to content

Instantly share code, notes, and snippets.

@Gozala
Created February 8, 2024 22:04

Revisions

  1. Gozala created this gist Feb 8, 2024.
    61 changes: 61 additions & 0 deletions take2.ts
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,61 @@
    interface Account {
    plan: AccountPlan
    // ...
    }

    interface AccountPlan {
    customer: AccountDID

    request(): Plan
    list(): Plan[]

    // Verifies that plan.customer === this.customer
    add(terms: Terms): Plan
    remove(plan: Plan): {}
    }

    type Plan = Variant<{
    active: ActivePlan
    pending: PendingPlan
    }>

    interface PendingPlan {
    // URL user can navigate to complete setup
    url: URL
    customer: AccountDID
    }

    interface ActivePlan extends UCAN<{ with: ServiceDID: can: "plan/*", nb: { customer: AccountDID } }> {
    terms: Terms // terms of service
    customer: AccountDID // Account that has a subscription

    subscription: PlanSubscription

    // ensures that terms.customer === this.customer
    update({ terms: Terms }): void
    }

    interface Terms extends UCAN<{ with: ProviderDID, nb: { customer: AccountDID } }> {
    price: Price
    provider: ProviderDID
    customer: AccountDID
    protocol: Record<Ability, Schema>
    }

    interface Price extends Record<string, number> {}


    interface PlanSubscription {
    list(): Subscription[]
    add(subscripton: Subscription): {}
    remove(subscription: Subscription): {}
    }


    interface Subscription {
    consumer: SpaceDID
    limit: Limit
    }

    interface Limit extends Record<PropertyKey, never> {
    }