main
ts 85 lines 2.43 KB
Raw
1 import type { FlaskBaseResponse } from "@/types/flask.d"
2 import type {
3 CheckoutPayload,
4 License,
5 LicenseCheckoutSession,
6 LicenseFeatures,
7 LicenseKey,
8 SubscriptionFeature
9 } from "@/types/license.d"
10 import { HttpClient } from "../httpClient"
11
12 export interface NewLicensePayload {
13 name: string
14 email: string
15 companyName: string
16 }
17
18 export interface CancelSubscriptionPayload {
19 customer_email: string
20 subscription_price_id: string
21 feature_name: string
22 }
23
24 export default {
25 getLicense() {
26 return HttpClient.get<FlaskBaseResponse & { license_key: LicenseKey }>(`/license/get_license`)
27 },
28 getSubscriptionFeatures() {
29 return HttpClient.get<FlaskBaseResponse & { features: SubscriptionFeature[] }>(`/license/subscription_features`)
30 },
31 verifyLicense() {
32 return HttpClient.get<FlaskBaseResponse & { license: License }>(`/license/verify_license`)
33 },
34 getLicenseFeatures() {
35 return HttpClient.get<FlaskBaseResponse & { features: LicenseFeatures[] }>(`/license/get_license_features`)
36 },
37 isFeatureEnabled(feature_name: LicenseFeatures) {
38 return HttpClient.get<FlaskBaseResponse & { enabled: boolean }>(`/license/is_feature_enabled/${feature_name}`)
39 },
40 replaceLicense(license_key: LicenseKey) {
41 return HttpClient.post<FlaskBaseResponse>(`/license/replace_license_in_db`, {
42 license_key
43 })
44 },
45 createCheckoutSession(payload: CheckoutPayload) {
46 return HttpClient.post<FlaskBaseResponse & { session: LicenseCheckoutSession }>(
47 `/license/create_checkout_session`,
48 payload
49 )
50 },
51 retrieveLicenseByEmail(email: string) {
52 return HttpClient.post<FlaskBaseResponse & { license_key: LicenseKey }>(`/license/retrieve_license_by_email`, {
53 email
54 })
55 },
56 cancelSubscription(payload: CancelSubscriptionPayload) {
57 return HttpClient.post<FlaskBaseResponse>(`/license/cancel_subscription`, payload)
58 },
59 retrieveDockerCompose() {
60 return HttpClient.post<FlaskBaseResponse & { docker_compose: string }>(`/license/retrieve-docker-compose`)
61 },
62 // TODO-FE: remove, deprecated
63 /** @deprecated */
64 extendLicense(period: number) {
65 return HttpClient.post<FlaskBaseResponse>(
66 `/license/extend_license`,
67 {},
68 {
69 params: { period }
70 }
71 )
72 },
73 // TODO-FE: remove, deprecated
74 /** @deprecated */
75 createLicense({ name, email, companyName }: NewLicensePayload) {
76 return HttpClient.post<FlaskBaseResponse>(`/license/create_new_key`, {
77 product_id: 24355,
78 notes: "Test Key",
79 new_customer: true,
80 name,
81 email,
82 company_name: companyName
83 })
84 }
85 }