Umami is a privacy-first web and product analytics platform. Traffic, campaigns, behavior, conversions, and revenue in one place. No cookies, no surveillance, self-hosted or in the cloud.
TypeScript analyticsaudience-segmentationchartscohort-analysisgoogle-analyticsproduct-analyticsstatisticsuser-journeyweb-analytics
Updated redis client. Soft deletes reset username.
Mike Caoe92d958b2411
diff --git a/lib/cache.ts b/lib/cache.tsindex 2aad7ed8d..528dd0128 100644--- a/lib/cache.ts+++ b/lib/cache.ts@@ -2,35 +2,7 @@ import { User, Website } from '@prisma/client';import redis from '@umami/redis-client';import { getSession, getUser, getWebsite } from '../queries';-const DELETED = 'DELETED';--async function fetchObject(key, query) {- const obj = await redis.get(key);-- if (obj === DELETED) {- return null;- }-- if (!obj) {- return query().then(async data => {- if (data) {- await redis.set(key, data);- }-- return data;- });- }-- return obj;-}--async function storeObject(key, data) {- return redis.set(key, data);-}--async function deleteObject(key, soft = false) {- return soft ? redis.set(key, DELETED) : redis.del(key);-}+const { fetchObject, storeObject, deleteObject } = redis;async function fetchWebsite(id): Promise<Website> {return fetchObject(`website:${id}`, () => getWebsite({ id }));diff --git a/package.json b/package.jsonindex 736ec6599..0db07f49c 100644--- a/package.json+++ b/package.json@@ -62,7 +62,7 @@"@prisma/client": "4.13.0","@tanstack/react-query": "^4.16.1","@umami/prisma-client": "^0.2.0",- "@umami/redis-client": "^0.2.0",+ "@umami/redis-client": "^0.5.0","chalk": "^4.1.1","chart.js": "^4.2.1","chartjs-adapter-date-fns": "^3.0.0",diff --git a/pages/api/users/[id]/index.ts b/pages/api/users/[id]/index.tsindex 8219c4a77..de4642cb9 100644--- a/pages/api/users/[id]/index.ts+++ b/pages/api/users/[id]/index.ts@@ -51,11 +51,11 @@ export default async (data.password = hashPassword(password);}+ // Only admin can change these fieldsif (role && isAdmin) {data.role = role;}- // Only admin can change these fieldsif (username && isAdmin) {data.username = username;}diff --git a/pages/api/websites/[id]/index.ts b/pages/api/websites/[id]/index.tsindex c1907fce9..3f660a910 100644--- a/pages/api/websites/[id]/index.ts+++ b/pages/api/websites/[id]/index.ts@@ -1,8 +1,8 @@+import { NextApiResponse } from 'next';+import { methodNotAllowed, ok, serverError, unauthorized } from 'next-basics';import { Website, NextApiRequestQueryBody } from 'lib/types';import { canViewWebsite, canUpdateWebsite, canDeleteWebsite } from 'lib/auth';import { useAuth, useCors } from 'lib/middleware';-import { NextApiResponse } from 'next';-import { methodNotAllowed, ok, serverError, unauthorized } from 'next-basics';import { deleteWebsite, getWebsite, updateWebsite } from 'queries';export interface WebsiteRequestQuery {diff --git a/queries/admin/user.ts b/queries/admin/user.tsindex 412c7785d..a81a76ef3 100644--- a/queries/admin/user.ts+++ b/queries/admin/user.ts@@ -1,4 +1,5 @@import { Prisma, Team, TeamUser } from '@prisma/client';+import { getRandomChars } from 'next-basics';import cache from 'lib/cache';import { ROLES } from 'lib/constants';import prisma from 'lib/prisma';@@ -222,6 +223,7 @@ export async function deleteUser(cloudMode? client.user.update({data: {+ username: getRandomChars(32),deletedAt: new Date(),},where: {diff --git a/yarn.lock b/yarn.lockindex d98ada117..41cca4343 100644--- a/yarn.lock+++ b/yarn.lock@@ -3272,10 +3272,10 @@dependencies:debug "^4.3.4"-"@umami/redis-client@^0.2.0":- version "0.2.0"- resolved "https://registry.yarnpkg.com/@umami/redis-client/-/redis-client-0.2.0.tgz#bdb1cd8b5c99afc5230621f19296c6d3559d68af"- integrity sha512-TONWhkuC//K2hRo3Psk7FHsuvu3XkQIYMY62/CERPtlIJz4Ac7DqsmYw4jO9/RkljA9XLl/5u+OggD4ARhMV8A==+"@umami/redis-client@^0.5.0":+ version "0.5.0"+ resolved "https://registry.yarnpkg.com/@umami/redis-client/-/redis-client-0.5.0.tgz#09b15458001bc172fc856d65316efbe5ff749461"+ integrity sha512-x7wx/pMjyg3AAYzgjGOw031bNhyZ81h6tRMAl60RQQI9xlJaJEA1r0TEUrWfFi21gHAvdBLJGYCsvHzpix4LKQ==dependencies:debug "^4.3.4"redis "^4.5.1"