Skip to content

armgit / ente

Public Imported from GitHub
0

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

[web][contacts] make web lint pass locally

Neeraj Guptafc8e45b6a63d
diff --git a/web/packages/contacts/eslint.config.mjs b/web/packages/contacts/eslint.config.mjs
new file mode 100644
index 0000000000..d6ebbf8464
--- /dev/null
+++ b/web/packages/contacts/eslint.config.mjs
@@ -0,0 +1 @@
+export { default } from "ente-build-config/eslintrc-base.mjs";
diff --git a/web/packages/contacts/index.test.ts b/web/packages/contacts/index.test.ts
index 5c5abcdc83..98c9e2ea88 100644
--- a/web/packages/contacts/index.test.ts
+++ b/web/packages/contacts/index.test.ts
@@ -70,25 +70,25 @@ beforeEach(() => {
vi.useRealTimers();
});
-type SetupOptions = {
+interface SetupOptions {
diff?: object[];
getProfilePictureError?: Error;
getProfilePictureBytes?: Uint8Array;
-};
+}
const setupContactsModule = async (options: SetupOptions = {}) => {
const kv = new Map<string, unknown>();
- const setKV = vi.fn(async (key: string, value: unknown) => {
+ const setKV = vi.fn((key: string, value: unknown) => {
kv.set(key, JSON.parse(JSON.stringify(value)));
});
- const getKV = vi.fn(async (key: string) => kv.get(key));
- const getKVN = vi.fn(async (key: string) => {
+ const getKV = vi.fn((key: string) => kv.get(key));
+ const getKVN = vi.fn((key: string) => {
const value = kv.get(key);
return typeof value === "number" ? value : undefined;
});
- const savedAuthToken = vi.fn(async () => "auth-token-secret");
- const apiOrigin = vi.fn(async () => "https://api.example");
+ const savedAuthToken = vi.fn(() => "auth-token-secret");
+ const apiOrigin = vi.fn(() => "https://api.example");
const info = vi.fn();
const warn = vi.fn();
const error = vi.fn();
@@ -114,7 +114,7 @@ const setupContactsModule = async (options: SetupOptions = {}) => {
.fn()
.mockResolvedValueOnce(diff)
.mockResolvedValueOnce([]);
- const get_profile_picture = vi.fn(async () => {
+ const get_profile_picture = vi.fn(() => {
if (options.getProfilePictureBytes) {
return options.getProfilePictureBytes;
}
@@ -131,7 +131,7 @@ const setupContactsModule = async (options: SetupOptions = {}) => {
isDesktop: false,
}));
vi.doMock("ente-wasm", () => ({
- contacts_open_ctx: vi.fn(async () => ({
+ contacts_open_ctx: vi.fn(() => ({
update_auth_token,
current_wrapped_root_key,
get_diff,
@@ -197,7 +197,10 @@ describe("profile picture loading", () => {
});
test("uses the inferred image mime type for avatar blobs", async () => {
- const createObjectURL = vi.fn((_blob: Blob) => "blob:contact");
+ const createObjectURL = vi.fn((blob: Blob) => {
+ void blob;
+ return "blob:contact";
+ });
vi.stubGlobal("URL", { createObjectURL, revokeObjectURL: vi.fn() });
const pngBytes = Uint8Array.from([
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00,
@@ -213,7 +216,7 @@ describe("profile picture loading", () => {
});
await contacts.__testing.preloadResolvedContactAvatar({ userID: 101 });
- const blobArg = createObjectURL.mock.calls[0]?.[0] as Blob | undefined;
+ const blobArg = createObjectURL.mock.calls[0]?.[0];
expect(blobArg?.type).toBe("image/png");
});
});
diff --git a/web/packages/contacts/index.ts b/web/packages/contacts/index.ts
index 4c431ea8b1..f1e76f9c25 100644
--- a/web/packages/contacts/index.ts
+++ b/web/packages/contacts/index.ts
@@ -31,7 +31,7 @@ const AVATAR_FAILURE_TTL_MS = 60_000;
const READY_RETRY_COOLDOWN_MS = 5_000;
const CONTACTS_CACHE_SCHEMA_VERSION = 2;
-type RemoteContactRecord = {
+interface RemoteContactRecord {
id: string;
contactUserId: number | bigint;
email?: string | null;
@@ -40,11 +40,14 @@ type RemoteContactRecord = {
profilePictureAttachmentId?: string | null;
isDeleted: boolean;
updatedAt: number | bigint;
-};
+}
-type ContactsReadyInput = { userID: number; masterKeyB64: string };
+interface ContactsReadyInput {
+ userID: number;
+ masterKeyB64: string;
+}
-type ContactsState = {
+interface ContactsState {
snapshot: ContactsDisplaySnapshot;
listeners: Set<() => void>;
currentSessionKey: string | undefined;
@@ -61,7 +64,7 @@ type ContactsState = {
avatarListenersByContactID: Map<string, Set<() => void>>;
lastReadyInput: ContactsReadyInput | undefined;
retryTimer: ReturnType<typeof setTimeout> | undefined;
-};
+}
const emptySnapshot = (): ContactsDisplaySnapshot => ({
isHydrated: false,
@@ -308,7 +311,10 @@ const syncContacts = async ({
userId: userID,
masterKeyB64,
cachedRootKey,
- userAgent: globalThis.navigator?.userAgent,
+ userAgent:
+ typeof navigator === "undefined"
+ ? undefined
+ : navigator.userAgent,
clientPackage: clientPackageName,
clientVersion: isDesktop ? desktopAppVersion : undefined,
});
@@ -327,7 +333,7 @@ const syncContacts = async ({
ctx.update_auth_token(authToken);
}
- if (!ctx || !isCurrentSession(sessionKey, generation)) {
+ if (!isCurrentSession(sessionKey, generation)) {
return;
}
@@ -409,7 +415,7 @@ export const ensureContactsReady = async ({
state.retryTimer = undefined;
}
})
- .catch((error) => {
+ .catch((error: unknown) => {
if (state.retryTimer) {
clearTimeout(state.retryTimer);
}