z wip
This commit is contained in:
@@ -20,18 +20,22 @@ const FamilyMember = z.object({
|
||||
*
|
||||
* This field will not be present for invited members until they accept.
|
||||
*/
|
||||
usage: z.number().nullable().transform(nullToUndefined),
|
||||
usage: z.number().nullish().transform(nullToUndefined),
|
||||
/**
|
||||
* `true` if this is the admin.
|
||||
*
|
||||
* This field will not be sent for invited members until they accept.
|
||||
*/
|
||||
isAdmin: z.boolean().nullable().transform(nullToUndefined),
|
||||
isAdmin: z.boolean().nullish().transform(nullToUndefined),
|
||||
});
|
||||
|
||||
type FamilyMember = z.infer<typeof FamilyMember>;
|
||||
|
||||
const FamilyData = z.object({
|
||||
/**
|
||||
* Zod schema for details about the family plan (if any) that the user is a part
|
||||
* of.
|
||||
*/
|
||||
export const FamilyData = z.object({
|
||||
members: z.array(FamilyMember),
|
||||
/**
|
||||
* Family admin subscription storage capacity.
|
||||
@@ -41,6 +45,9 @@ const FamilyData = z.object({
|
||||
storage: z.number(),
|
||||
});
|
||||
|
||||
/**
|
||||
* Details about the family plan (if any) that the user is a part of.
|
||||
*/
|
||||
export type FamilyData = z.infer<typeof FamilyData>;
|
||||
|
||||
export function getLocalFamilyData(): FamilyData {
|
||||
|
||||
@@ -20,7 +20,7 @@ const PlanPeriod = z.enum(["month", "year"]);
|
||||
*/
|
||||
export type PlanPeriod = z.infer<typeof PlanPeriod>;
|
||||
|
||||
const Subscription = z.object({
|
||||
export const Subscription = z.object({
|
||||
productID: z.string(),
|
||||
storage: z.number(),
|
||||
expiryTime: z.number(),
|
||||
|
||||
@@ -1,29 +1,61 @@
|
||||
import { authenticatedRequestHeaders, ensureOk } from "@/base/http";
|
||||
import { apiURL } from "@/base/origins";
|
||||
import { z } from "zod";
|
||||
import type { FamilyData } from "./family";
|
||||
import type { Subscription } from "./plan";
|
||||
import { FamilyData } from "./family";
|
||||
import { Subscription } from "./plan";
|
||||
|
||||
export interface Bonus {
|
||||
storage: number;
|
||||
type: string;
|
||||
validTill: number;
|
||||
isRevoked: boolean;
|
||||
}
|
||||
const BonusData = z.object({
|
||||
/**
|
||||
* List of bonuses applied for the user.
|
||||
*/
|
||||
storageBonuses: z
|
||||
.object({
|
||||
/**
|
||||
* The type of the bonus.
|
||||
*/
|
||||
type: z.string(),
|
||||
})
|
||||
.array(),
|
||||
});
|
||||
|
||||
export interface BonusData {
|
||||
storageBonuses: Bonus[];
|
||||
}
|
||||
/**
|
||||
* Information about bonuses applied to the user.
|
||||
*/
|
||||
export type BonusData = z.infer<typeof BonusData>;
|
||||
|
||||
export interface UserDetails {
|
||||
email: string;
|
||||
usage: number;
|
||||
fileCount: number;
|
||||
sharedCollectionCount: number;
|
||||
subscription: Subscription;
|
||||
familyData?: FamilyData;
|
||||
storageBonus?: number;
|
||||
bonusData?: BonusData;
|
||||
/**
|
||||
* Zod schema for {@link UserDetails}
|
||||
*/
|
||||
const UserDetails = z.object({
|
||||
email: z.string(),
|
||||
usage: z.number(),
|
||||
fileCount: z.number().optional(),
|
||||
subscription: Subscription,
|
||||
familyData: FamilyData.optional(),
|
||||
storageBonus: z.number().optional(),
|
||||
bonusData: BonusData.optional(),
|
||||
});
|
||||
|
||||
export type UserDetails = z.infer<typeof UserDetails>;
|
||||
|
||||
/**
|
||||
* Internal in-memory state shared by the functions in this module.
|
||||
*
|
||||
* This entire object will be reset on logout.
|
||||
*/
|
||||
class UserState {
|
||||
/**
|
||||
* Subscriptions to {@link UserDetails} updates.
|
||||
*
|
||||
* See {@link userDetailsSubscribe}.
|
||||
*/
|
||||
userDetailsListeners: (() => void)[] = [];
|
||||
|
||||
/**
|
||||
* Snapshot of the {@link UserDetails} returned by the
|
||||
* {@link userDetailsSnapshot} function.
|
||||
*/
|
||||
userDetailsSnapshot: UserDetails | undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user