Simpl-Resultat/src/services/licenseService.ts
le king fu 2da2de183a
All checks were successful
PR Check / rust (push) Successful in 16m19s
PR Check / frontend (push) Successful in 2m14s
feat: license card in settings (#47)
Adds the user-facing layer on top of the Rust license commands shipped
in #46.

- `licenseService.ts` thin wrapper around the new Tauri commands
- `useLicense` hook follows the project's useReducer pattern (idle,
  loading, ready, validating, error) and exposes `submitKey`,
  `refresh`, and `checkEntitlement` for cross-component use
- `LicenseCard` shows the current edition, the expiry date when set,
  accepts a license key with inline validation feedback, and links to
  the purchase page via `openUrl` from `@tauri-apps/plugin-opener`
- Card is inserted at the top of `SettingsPage` so the edition is the
  first thing users see when looking for license-related actions
- i18n: new `license.*` keys in both `fr.json` and `en.json`
- Bilingual CHANGELOG entries
2026-04-09 15:47:04 -04:00

36 lines
998 B
TypeScript

import { invoke } from "@tauri-apps/api/core";
export type Edition = "free" | "base" | "premium";
export interface LicenseInfo {
edition: Edition;
email: string;
features: string[];
machine_limit: number;
issued_at: number;
expires_at: number;
}
export async function validateLicenseKey(key: string): Promise<LicenseInfo> {
return invoke<LicenseInfo>("validate_license_key", { key });
}
export async function storeLicense(key: string): Promise<LicenseInfo> {
return invoke<LicenseInfo>("store_license", { key });
}
export async function readLicense(): Promise<LicenseInfo | null> {
return invoke<LicenseInfo | null>("read_license");
}
export async function getEdition(): Promise<Edition> {
return invoke<Edition>("get_edition");
}
export async function getMachineId(): Promise<string> {
return invoke<string>("get_machine_id");
}
export async function checkEntitlement(feature: string): Promise<boolean> {
return invoke<boolean>("check_entitlement", { feature });
}