A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
core: add endpoints for getting all products for new plans
Abdullah Attad3e3ef5986fc
diff --git a/packages/core/src/api/pricing.ts b/packages/core/src/api/pricing.tsindex bbbfc7747..b332238dd 100644--- a/packages/core/src/api/pricing.ts+++ b/packages/core/src/api/pricing.ts@@ -17,26 +17,59 @@ You should have received a copy of the GNU General Public Licensealong 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`);}}diff --git a/packages/core/src/types.ts b/packages/core/src/types.tsindex 76428d70d..005056577 100644--- a/packages/core/src/types.ts+++ b/packages/core/src/types.ts@@ -550,6 +550,13 @@ export type TrashItem = BaseTrashItem<Note> | BaseTrashItem<Notebook>;export type AuthenticatorType = "app" | "sms" | "email";+export type SubscriptionPlanId =+ | "free"+ | "essential"+ | "pro"+ | "believer"+ | "education";+export enum SubscriptionPlan {FREE = 0,ESSENTIAL = 1,@@ -665,3 +672,18 @@ export function isEncryptedContent(): content is NoteContent<true> {return isCipher(content.data);}++export function planToId(plan: SubscriptionPlan): SubscriptionPlanId {+ switch (plan) {+ case SubscriptionPlan.FREE:+ return "free";+ case SubscriptionPlan.BELIEVER:+ return "believer";+ case SubscriptionPlan.EDUCATION:+ return "education";+ case SubscriptionPlan.ESSENTIAL:+ return "essential";+ case SubscriptionPlan.PRO:+ return "pro";+ }+}