Skip to content

Instantly share code, notes, and snippets.

@Gozala
Created February 8, 2024 21:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Gozala/afa977f9e9c7e921700b60362cb6a984 to your computer and use it in GitHub Desktop.
Save Gozala/afa977f9e9c7e921700b60362cb6a984 to your computer and use it in GitHub Desktop.
interface Account {
subscriptions: AccountSubscriptions
// ...
}
interface AccountSubscriptions {
customer: AccountDID
request(): Subscription
list(): Subscription[]
// Verifies that plan.customer === this.customer
add(plan: Plan): Subscription
remove(subscription: Subscription): {}
}
type Subscription = Variant<{
active: ActiveSubscription
pending: PendingSubscription
}>
interface PendingSubscription {
// URL user can navigate to complete subscription setup
url: URL
customer: AccountDID
}
interface ActiveSubscription extends UCAN<{ with: ServiceDID: can: "subscription/*", nb: { customer: AccountDID } }> {
plan: Plan // terms of service
customer: AccountDID // Account that has a subscription
provisions: SubscriptionProvisions
// ensures that plan.customer === this.customer
update({ plan: Plan }): void
}
interface Plan extends UCAN<{ with: ProviderDID, nb: { customer: AccountDID } }> {
price: Price
provider: ProviderDID
customer: AccountDID
protocol: Record<Ability, Schema>
}
interface Price extends Record<string, number> {}
interface SubscriptionProvisions {
list(): Provision[]
add(provision: Provision): {}
remove(provision: Provision): {}
}
interface Provision {
consumer: SpaceDID
limits: Limits
}
interface Limits extends Record<PropertyKey, never> {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment