core: add endpoints for getting all products for new plans

This commit is contained in:
Abdullah Atta
2025-08-13 10:27:13 +05:00
parent ea1ffc59b8
commit d3e3ef5986
2 changed files with 63 additions and 8 deletions

View File

@@ -17,26 +17,59 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { SubscriptionPlan, SubscriptionPlanId } from "../types.js";
import http from "../utils/http.js";
export type Product = {
export type SKUResponse = {
country: string;
countryCode: string;
sku?: string;
price?: string;
discount: number;
};
const BASE_URL = `https://notesnook.com/api/v1/prices`;
export interface PlanPrice {
gross: number;
net: number;
tax: number;
currency?: string;
}
export type Period = "monthly" | "yearly" | "5-year";
export type Discount = {
type: "regional" | "promo";
code?: string;
recurring: boolean;
amount: number;
};
export interface Plan {
plan: SubscriptionPlan;
recurring: boolean;
id: string;
name?: string;
period: Period;
price: PlanPrice;
currency: string;
currencySymbol?: string;
originalPrice?: PlanPrice;
discount?: Discount;
country: string;
}
const BASE_URL = `https://notesnook.com/api/v2/prices`;
export class Pricing {
static sku(
platform: "android" | "ios" | "web",
period: "monthly" | "yearly"
): Promise<Product> {
return http.get(`${BASE_URL}/skus/${platform}/${period}`);
period: Period,
plan: SubscriptionPlanId
): Promise<SKUResponse> {
return http.get(
`${BASE_URL}/skus?platform=${platform}&period=${period}&plan=${plan}`
);
}
static price(period: "monthly" | "yearly" = "monthly"): Promise<Product> {
return http.get(`${BASE_URL}/${period}`);
static products(): Promise<Plan[]> {
return http.get(`${BASE_URL}/products`);
}
}