From 9f485f3e960c56ca54fc49a5e50c608144c50606 Mon Sep 17 00:00:00 2001 From: Marko Ognjenovic Date: Wed, 22 Feb 2023 13:33:37 +0100 Subject: [PATCH 1/8] Support plan API --- src/endpoints/Billing/Client.ts | 8 +++++++ src/types/Plan.ts | 37 +++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/src/endpoints/Billing/Client.ts b/src/endpoints/Billing/Client.ts index 74b76fe6..a817fe7e 100644 --- a/src/endpoints/Billing/Client.ts +++ b/src/endpoints/Billing/Client.ts @@ -2,6 +2,7 @@ import type { DeferredJobsApiClient } from '../../api'; import { routing } from '../../routing'; import type { SignupRequest, SignupResponse } from './types'; +import type { Plan } from "../../types"; export class Client { private readonly apiClient: DeferredJobsApiClient; @@ -14,4 +15,11 @@ export class Client { const url = `${routing.billing}/signup`; return this.apiClient.post(url, { payload }); } + + async getPlan(): Promise { + const { plan } = await this.apiClient.get<{ plan: Plan }>( + `${routing.billing}/plan` + ); + return plan; + } } diff --git a/src/types/Plan.ts b/src/types/Plan.ts index 127eff7b..82b2f600 100644 --- a/src/types/Plan.ts +++ b/src/types/Plan.ts @@ -1,3 +1,40 @@ +import type {Limit} from "../endpoints/PricingTables"; + +export interface Plan { + display_name: string; + description: string | null; + is_legacy: boolean; + is_deprecated: boolean; + is_superior: boolean; + is_trial: boolean; + pricing_table_option_id: string | null; + billing_cycle: string; + currency: string; + ends_at: string | null; + discount: Discount | null; + usage: Usage[]; + items: Item[]; +} + +export interface Discount { + amount_off: number; + percent_off: number; +} + +export interface Usage { + limit: Limit; + used: number; +} + +export interface Item { + amount: number; + quantity: number; + unit: string | null; + billing_cycle: string; + currency: string; +} + +/** @deprecated Will be dropped in future */ export enum PlanLevel { BASIC = 'basic', CORE = 'core', From 593e343a95f274f2f86780d3d31ebe841b04d00e Mon Sep 17 00:00:00 2001 From: Marko Ognjenovic Date: Wed, 22 Feb 2023 13:34:27 +0100 Subject: [PATCH 2/8] Fix code style --- src/types/Plan.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/types/Plan.ts b/src/types/Plan.ts index 82b2f600..30c74427 100644 --- a/src/types/Plan.ts +++ b/src/types/Plan.ts @@ -1,4 +1,4 @@ -import type {Limit} from "../endpoints/PricingTables"; +import type { Limit } from "../endpoints/PricingTables"; export interface Plan { display_name: string; From a5f18535a0609e577722c9440898e5290eff38aa Mon Sep 17 00:00:00 2001 From: Marko Ognjenovic Date: Wed, 22 Feb 2023 13:37:36 +0100 Subject: [PATCH 3/8] Fix code style --- src/endpoints/Billing/Client.ts | 6 ++---- src/types/Plan.ts | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/endpoints/Billing/Client.ts b/src/endpoints/Billing/Client.ts index a817fe7e..352658d4 100644 --- a/src/endpoints/Billing/Client.ts +++ b/src/endpoints/Billing/Client.ts @@ -1,8 +1,8 @@ import type { DeferredJobsApiClient } from '../../api'; import { routing } from '../../routing'; +import type { Plan } from '../../types'; import type { SignupRequest, SignupResponse } from './types'; -import type { Plan } from "../../types"; export class Client { private readonly apiClient: DeferredJobsApiClient; @@ -17,9 +17,7 @@ export class Client { } async getPlan(): Promise { - const { plan } = await this.apiClient.get<{ plan: Plan }>( - `${routing.billing}/plan` - ); + const { plan } = await this.apiClient.get<{ plan: Plan }>(`${routing.billing}/plan`); return plan; } } diff --git a/src/types/Plan.ts b/src/types/Plan.ts index 30c74427..5050740e 100644 --- a/src/types/Plan.ts +++ b/src/types/Plan.ts @@ -1,4 +1,4 @@ -import type { Limit } from "../endpoints/PricingTables"; +import type { Limit } from '../endpoints/PricingTables'; export interface Plan { display_name: string; From ea963e140e4e4acfd9c4d55f549d9fb68f9b554a Mon Sep 17 00:00:00 2001 From: Marko Ognjenovic Date: Wed, 22 Feb 2023 14:31:58 +0100 Subject: [PATCH 4/8] Drop plan items property --- src/types/Plan.ts | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/types/Plan.ts b/src/types/Plan.ts index 5050740e..fe56a427 100644 --- a/src/types/Plan.ts +++ b/src/types/Plan.ts @@ -13,7 +13,6 @@ export interface Plan { ends_at: string | null; discount: Discount | null; usage: Usage[]; - items: Item[]; } export interface Discount { @@ -26,14 +25,6 @@ export interface Usage { used: number; } -export interface Item { - amount: number; - quantity: number; - unit: string | null; - billing_cycle: string; - currency: string; -} - /** @deprecated Will be dropped in future */ export enum PlanLevel { BASIC = 'basic', From 6efc10807db842428c2908530277a639646db749 Mon Sep 17 00:00:00 2001 From: Marko Ognjenovic Date: Wed, 22 Feb 2023 14:42:18 +0100 Subject: [PATCH 5/8] Drop discount from plan interface --- src/types/Plan.ts | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/types/Plan.ts b/src/types/Plan.ts index fe56a427..0206ebc0 100644 --- a/src/types/Plan.ts +++ b/src/types/Plan.ts @@ -11,15 +11,9 @@ export interface Plan { billing_cycle: string; currency: string; ends_at: string | null; - discount: Discount | null; usage: Usage[]; } -export interface Discount { - amount_off: number; - percent_off: number; -} - export interface Usage { limit: Limit; used: number; From c2ded69d774488128482dbb2df8be8cfa7f1272a Mon Sep 17 00:00:00 2001 From: Marko Ognjenovic Date: Wed, 22 Feb 2023 14:45:29 +0100 Subject: [PATCH 6/8] Drop plan ends_at property --- src/types/Plan.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/types/Plan.ts b/src/types/Plan.ts index 0206ebc0..c02af04a 100644 --- a/src/types/Plan.ts +++ b/src/types/Plan.ts @@ -10,7 +10,6 @@ export interface Plan { pricing_table_option_id: string | null; billing_cycle: string; currency: string; - ends_at: string | null; usage: Usage[]; } From 0202872e3729d5fc70ae6c56fcb9863eedab35d4 Mon Sep 17 00:00:00 2001 From: Marko Ognjenovic Date: Wed, 22 Feb 2023 14:49:16 +0100 Subject: [PATCH 7/8] Implement and use PlanReference interface --- src/types/License.ts | 12 ++---------- src/types/Plan.ts | 5 ++++- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/src/types/License.ts b/src/types/License.ts index de2322df..7416382f 100644 --- a/src/types/License.ts +++ b/src/types/License.ts @@ -1,5 +1,5 @@ import type { Currency } from './Currency'; -import type { PlanLevel } from './Plan'; +import type {PlanLevel, PlanReference} from './Plan'; export interface LicenseRef { id: number; @@ -62,7 +62,7 @@ export interface License extends LicenseRef { * use "plan" instead. */ plan_level: PlanLevel | null; - plan: License.Plan | null; + plan: PlanReference | null; status: License.Status; subscription_lockout: boolean; /** @@ -112,12 +112,4 @@ export namespace License { CANCELED = 'canceled', UNPAID = 'unpaid', } - - export interface Plan { - display_name: string | null; - description: string | null; - is_legacy: boolean; - is_superior: boolean; - pricing_table_option_id: string | null; - } } diff --git a/src/types/Plan.ts b/src/types/Plan.ts index c02af04a..50d2c9f6 100644 --- a/src/types/Plan.ts +++ b/src/types/Plan.ts @@ -1,6 +1,6 @@ import type { Limit } from '../endpoints/PricingTables'; -export interface Plan { +export interface PlanReference { display_name: string; description: string | null; is_legacy: boolean; @@ -8,6 +8,9 @@ export interface Plan { is_superior: boolean; is_trial: boolean; pricing_table_option_id: string | null; +} + +export interface Plan extends PlanReference{ billing_cycle: string; currency: string; usage: Usage[]; From 7240c897edc47a30d5c3a853c6b0e561d9bcfa1f Mon Sep 17 00:00:00 2001 From: Marko Ognjenovic Date: Wed, 22 Feb 2023 14:50:01 +0100 Subject: [PATCH 8/8] Fix code style --- src/types/License.ts | 2 +- src/types/Plan.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/types/License.ts b/src/types/License.ts index 7416382f..d3b393fc 100644 --- a/src/types/License.ts +++ b/src/types/License.ts @@ -1,5 +1,5 @@ import type { Currency } from './Currency'; -import type {PlanLevel, PlanReference} from './Plan'; +import type { PlanLevel, PlanReference } from './Plan'; export interface LicenseRef { id: number; diff --git a/src/types/Plan.ts b/src/types/Plan.ts index 50d2c9f6..ab499983 100644 --- a/src/types/Plan.ts +++ b/src/types/Plan.ts @@ -10,7 +10,7 @@ export interface PlanReference { pricing_table_option_id: string | null; } -export interface Plan extends PlanReference{ +export interface Plan extends PlanReference { billing_cycle: string; currency: string; usage: Usage[];