feat: implement renewal/complete new
This commit is contained in:
@ -22,6 +22,22 @@ export interface Subscription {
|
||||
type: SubscriptionType;
|
||||
created: string;
|
||||
expires: string;
|
||||
state: "new" | "expired" | "paid";
|
||||
}
|
||||
|
||||
export enum SubscriptionErrorCode {
|
||||
InternalError = 1,
|
||||
SubscriptionActive = 2,
|
||||
Duplicate = 3,
|
||||
}
|
||||
|
||||
export class SubscriptionError extends Error {
|
||||
code: SubscriptionErrorCode;
|
||||
|
||||
constructor(msg: string, code: SubscriptionErrorCode) {
|
||||
super(msg);
|
||||
this.code = code;
|
||||
}
|
||||
}
|
||||
|
||||
export default class SnortApi {
|
||||
@ -49,6 +65,10 @@ export default class SnortApi {
|
||||
return this.#getJsonAuthd<InvoiceResponse>(`api/v1/subscription?type=${type}`, "PUT");
|
||||
}
|
||||
|
||||
renewSubscription(id: string) {
|
||||
return this.#getJsonAuthd<InvoiceResponse>(`api/v1/subscription/${id}/renew`, "GET");
|
||||
}
|
||||
|
||||
listSubscriptions() {
|
||||
return this.#getJsonAuthd<Array<Subscription>>("api/v1/subscription");
|
||||
}
|
||||
@ -93,7 +113,7 @@ export default class SnortApi {
|
||||
|
||||
const obj = await rsp.json();
|
||||
if ("error" in obj) {
|
||||
throw new Error(obj.error);
|
||||
throw new SubscriptionError(obj.error, obj.code);
|
||||
}
|
||||
return obj as T;
|
||||
}
|
||||
|
Reference in New Issue
Block a user