Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

z wip

Manav Rathi7fb2fb6ddef4
diff --git a/web/packages/new/photos/services/family.ts b/web/packages/new/photos/services/family.ts
index f5f0e5a6a5..dc4b5575b3 100644
--- a/web/packages/new/photos/services/family.ts
+++ b/web/packages/new/photos/services/family.ts
@@ -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 {
diff --git a/web/packages/new/photos/services/plan.ts b/web/packages/new/photos/services/plan.ts
index 80b44bf8fc..93beff3e11 100644
--- a/web/packages/new/photos/services/plan.ts
+++ b/web/packages/new/photos/services/plan.ts
@@ -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(),
diff --git a/web/packages/new/photos/services/user.ts b/web/packages/new/photos/services/user.ts
index 6d62b83b08..ca0a1c42b2 100644
--- a/web/packages/new/photos/services/user.ts
+++ b/web/packages/new/photos/services/user.ts
@@ -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";
-
-export interface Bonus {
- storage: number;
- type: string;
- validTill: number;
- isRevoked: boolean;
-}
+import { FamilyData } from "./family";
+import { Subscription } from "./plan";
-export interface BonusData {
- storageBonuses: Bonus[];
-}
+const BonusData = z.object({
+ /**
+ * List of bonuses applied for the user.
+ */
+ storageBonuses: z
+ .object({
+ /**
+ * The type of the bonus.
+ */
+ type: z.string(),
+ })
+ .array(),
+});
+
+/**
+ * Information about bonuses applied to the user.
+ */
+export type BonusData = z.infer<typeof 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)[] = [];
-export interface UserDetails {
- email: string;
- usage: number;
- fileCount: number;
- sharedCollectionCount: number;
- subscription: Subscription;
- familyData?: FamilyData;
- storageBonus?: number;
- bonusData?: BonusData;
+ /**
+ * Snapshot of the {@link UserDetails} returned by the
+ * {@link userDetailsSnapshot} function.
+ */
+ userDetailsSnapshot: UserDetails | undefined;
}
/**