Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

Commit

Permalink
feat: added GetAttachedPlans and GetAttachedProducts to subs (#927)
Browse files Browse the repository at this point in the history
BREAKING CHANGE
  • Loading branch information
rostyk-kanafotskyy authored May 24, 2024
1 parent a1e84f7 commit 1538c77
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
7 changes: 7 additions & 0 deletions src/endpoints/subscriptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ class SubscriptionsEndpoint extends CRUDExtend {
return this.request.send(`${this.endpoint}/${id}/invoices`, 'GET')
}

GetAttachedProducts(id) {
return this.request.send(`${this.endpoint}/${id}/products`, 'GET')
}

GetAttachedPlans(id) {
return this.request.send(`${this.endpoint}/${id}/plans`, 'GET')
}
}

export default SubscriptionsEndpoint
13 changes: 12 additions & 1 deletion src/types/subscription-offerings.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,18 @@ export interface SubscriptionOfferingFilter {
}
}

export type SubscriptionOfferingPlan = SubscriptionPlan & SubscriptionOfferingAttachmentsRelationships
type SubscriptionOfferingPlanMeta = {
meta: {
active_plan?: boolean
owner: string
timestamps: {
created_at: string
updated_at: string
}
}
}

export type SubscriptionOfferingPlan = Omit<SubscriptionPlan, 'meta'> & SubscriptionOfferingAttachmentsRelationships & SubscriptionOfferingPlanMeta
export type SubscriptionOfferingProduct = SubscriptionProduct & SubscriptionOfferingAttachmentsRelationships
/**
* Subscription Offering Endpoints
Expand Down
20 changes: 17 additions & 3 deletions src/types/subscriptions.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
import {
Identifiable,
CrudQueryableResource,
Resource
Resource,
ResourcePage
} from './core'
import { SubscriptionOfferingPlan, SubscriptionOfferingProduct } from './subscription-offerings'

/**
* Core Subscription Base Interface
Expand Down Expand Up @@ -109,6 +111,12 @@ export interface Subscription extends Identifiable, SubscriptionBase {
}
}

export type SubscriptionsInclude = 'plans'

export interface SubscriptionsIncluded {
plans: SubscriptionOfferingPlan[]
}

/**
* Subscription Endpoints
* DOCS: TODO: add docs when ready
Expand All @@ -120,9 +128,15 @@ export interface SubscriptionsEndpoint
never,
SubscriptionFilter,
never,
never
>, "Limit" | "Offset" | "Sort" | "With" | "Attributes" | "Update" | "Link" > {
SubscriptionsInclude
>, "All" | "Limit" | "Offset" | "Sort" | "Attributes" | "Update" | "Link" > {
endpoint: 'subscriptions'

All(token?: string): Promise<ResourcePage<Subscription, SubscriptionsIncluded>>

GetInvoices(id: string): Promise<Resource<SubscriptionInvoice[]>>

GetAttachedProducts(id: string) : Promise<Resource<SubscriptionOfferingProduct[]>>

GetAttachedPlans(id: string) : Promise<Resource<SubscriptionOfferingPlan[]>>
}

0 comments on commit 1538c77

Please sign in to comment.