mirror of
https://github.com/kremalicious/umami.git
synced 2025-02-14 21:10:34 +01:00
Merge branch 'dev' into analytics
This commit is contained in:
commit
46b3da1b07
@ -11,7 +11,7 @@ import useDateRange from 'hooks/useDateRange';
|
||||
function RefreshButton({ websiteId }) {
|
||||
const [dateRange] = useDateRange(websiteId);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const selector = useCallback(state => state[`/website/${websiteId}/stats`], [websiteId]);
|
||||
const selector = useCallback(state => state[`/websites/${websiteId}/stats`], [websiteId]);
|
||||
const completed = useStore(selector);
|
||||
|
||||
function handleClick() {
|
||||
|
@ -18,7 +18,7 @@ export default function UpdateNotice() {
|
||||
function handleViewClick() {
|
||||
updateCheck();
|
||||
setDismissed(true);
|
||||
location.href = releaseUrl || REPO_URL;
|
||||
open(releaseUrl || REPO_URL, '_blank');
|
||||
}
|
||||
|
||||
function handleDismissClick() {
|
||||
|
@ -33,7 +33,8 @@ export default function AccountEditForm({ values, onSave, onClose }) {
|
||||
const [message, setMessage] = useState();
|
||||
|
||||
const handleSubmit = async values => {
|
||||
const { ok, data } = await post('/account', values);
|
||||
const { user_id } = values;
|
||||
const { ok, data } = await post(user_id ? `/accounts/${user_id}` : '/accounts', values);
|
||||
|
||||
if (ok) {
|
||||
onSave();
|
||||
|
@ -9,6 +9,7 @@ import FormLayout, {
|
||||
FormRow,
|
||||
} from 'components/layout/FormLayout';
|
||||
import useApi from 'hooks/useApi';
|
||||
import useUser from '../../hooks/useUser';
|
||||
|
||||
const initialValues = {
|
||||
current_password: '',
|
||||
@ -39,9 +40,10 @@ const validate = ({ current_password, new_password, confirm_password }) => {
|
||||
export default function ChangePasswordForm({ values, onSave, onClose }) {
|
||||
const { post } = useApi();
|
||||
const [message, setMessage] = useState();
|
||||
const { user } = useUser();
|
||||
|
||||
const handleSubmit = async values => {
|
||||
const { ok, data } = await post('/account/password', values);
|
||||
const { ok, data } = await post(`/accounts/${user.user_id}/password`, values);
|
||||
|
||||
if (ok) {
|
||||
onSave();
|
||||
|
@ -38,7 +38,6 @@ const validate = ({ name, domain }) => {
|
||||
};
|
||||
|
||||
const OwnerDropDown = ({ user, accounts }) => {
|
||||
console.info(styles);
|
||||
const { setFieldValue, values } = useFormikContext();
|
||||
|
||||
useEffect(() => {
|
||||
@ -79,7 +78,8 @@ export default function WebsiteEditForm({ values, onSave, onClose }) {
|
||||
const [message, setMessage] = useState();
|
||||
|
||||
const handleSubmit = async values => {
|
||||
const { ok, data } = await post('/website', values);
|
||||
const { website_id } = values;
|
||||
const { ok, data } = await post(website_id ? `/websites/${website_id}` : '/websites', values);
|
||||
|
||||
if (ok) {
|
||||
onSave();
|
||||
@ -137,6 +137,7 @@ export default function WebsiteEditForm({ values, onSave, onClose }) {
|
||||
defaultMessage="Enable share URL"
|
||||
/>
|
||||
}
|
||||
value={null}
|
||||
/>
|
||||
)}
|
||||
</Field>
|
||||
|
@ -6,7 +6,7 @@ import Dot from 'components/common/Dot';
|
||||
import styles from './ActiveUsers.module.css';
|
||||
|
||||
export default function ActiveUsers({ websiteId, className, value, interval = 60000 }) {
|
||||
const url = websiteId ? `/website/${websiteId}/active` : null;
|
||||
const url = websiteId ? `/websites/${websiteId}/active` : null;
|
||||
const { data } = useFetch(url, {
|
||||
interval,
|
||||
});
|
||||
|
@ -16,7 +16,7 @@ export default function EventsChart({ websiteId, className, token }) {
|
||||
} = usePageQuery();
|
||||
|
||||
const { data, loading } = useFetch(
|
||||
`/website/${websiteId}/events`,
|
||||
`/websites/${websiteId}/events`,
|
||||
{
|
||||
params: {
|
||||
start_at: +startDate,
|
||||
|
@ -19,7 +19,7 @@ export default function MetricsBar({ websiteId, className }) {
|
||||
} = usePageQuery();
|
||||
|
||||
const { data, error, loading } = useFetch(
|
||||
`/website/${websiteId}/stats`,
|
||||
`/websites/${websiteId}/stats`,
|
||||
{
|
||||
params: {
|
||||
start_at: +startDate,
|
||||
|
@ -38,7 +38,7 @@ export default function MetricsTable({
|
||||
const { formatMessage } = useIntl();
|
||||
|
||||
const { data, loading, error } = useFetch(
|
||||
`/website/${websiteId}/metrics`,
|
||||
`/websites/${websiteId}/metrics`,
|
||||
{
|
||||
params: {
|
||||
type,
|
||||
|
@ -15,6 +15,7 @@ import Visitor from 'assets/visitor.svg';
|
||||
import Eye from 'assets/eye.svg';
|
||||
import { stringToColor } from 'lib/format';
|
||||
import { dateFormat } from 'lib/date';
|
||||
import { safeDecodeURI } from 'next-basics';
|
||||
import styles from './RealtimeLog.module.css';
|
||||
|
||||
const TYPE_ALL = 0;
|
||||
@ -113,7 +114,7 @@ export default function RealtimeLog({ data, websites, websiteId }) {
|
||||
target="_blank"
|
||||
rel="noreferrer noopener"
|
||||
>
|
||||
{url}
|
||||
{safeDecodeURI(url)}
|
||||
</a>
|
||||
);
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ export default function WebsiteChart({
|
||||
const { get } = useApi();
|
||||
|
||||
const { data, loading, error } = useFetch(
|
||||
`/website/${websiteId}/pageviews`,
|
||||
`/websites/${websiteId}/pageviews`,
|
||||
{
|
||||
params: {
|
||||
start_at: +startDate,
|
||||
@ -70,7 +70,7 @@ export default function WebsiteChart({
|
||||
|
||||
async function handleDateChange(value) {
|
||||
if (value === 'all') {
|
||||
const { data, ok } = await get(`/website/${websiteId}`);
|
||||
const { data, ok } = await get(`/websites/${websiteId}`);
|
||||
if (ok) {
|
||||
setDateRange({ value, ...getDateRangeValues(new Date(data.created_at), Date.now()) });
|
||||
}
|
||||
|
@ -17,8 +17,8 @@ export default function WebsiteHeader({ websiteId, title, domain, showLink = fal
|
||||
<Favicon domain={domain} />
|
||||
<Link
|
||||
className={styles.titleLink}
|
||||
href="/website/[...id]"
|
||||
as={`/website/${websiteId}/${title}`}
|
||||
href="/websites/[...id]"
|
||||
as={`/websites/${websiteId}/${title}`}
|
||||
>
|
||||
<OverflowText tooltipId={`${websiteId}-title`}>{title}</OverflowText>
|
||||
</Link>
|
||||
@ -41,8 +41,8 @@ export default function WebsiteHeader({ websiteId, title, domain, showLink = fal
|
||||
<RefreshButton websiteId={websiteId} />
|
||||
{showLink && (
|
||||
<Link
|
||||
href="/website/[...id]"
|
||||
as={`/website/${websiteId}/${title}`}
|
||||
href="/websites/[...id]"
|
||||
as={`/websites/${websiteId}/${title}`}
|
||||
className={styles.link}
|
||||
icon={<Arrow />}
|
||||
size="small"
|
||||
|
@ -52,7 +52,7 @@ const views = {
|
||||
};
|
||||
|
||||
export default function WebsiteDetails({ websiteId }) {
|
||||
const { data } = useFetch(`/website/${websiteId}`);
|
||||
const { data } = useFetch(`/websites/${websiteId}`);
|
||||
const [chartLoaded, setChartLoaded] = useState(false);
|
||||
const [countryData, setCountryData] = useState();
|
||||
const [eventsData, setEventsData] = useState();
|
||||
|
@ -86,8 +86,8 @@ export default function WebsiteSettings() {
|
||||
const DetailsLink = ({ website_id, name, domain }) => (
|
||||
<Link
|
||||
className={styles.detailLink}
|
||||
href="/website/[...id]"
|
||||
as={`/website/${website_id}/${name}`}
|
||||
href="/websites/[...id]"
|
||||
as={`/websites/${website_id}/${name}`}
|
||||
>
|
||||
<Favicon domain={domain} />
|
||||
<OverflowText tooltipId={`${website_id}-name`}>{name}</OverflowText>
|
||||
|
@ -1,130 +0,0 @@
|
||||
SET allow_experimental_object_type = 1;
|
||||
|
||||
-- Create Pageview
|
||||
CREATE TABLE pageview
|
||||
(
|
||||
website_id UInt32,
|
||||
session_uuid UUID,
|
||||
created_at DateTime('UTC'),
|
||||
url String,
|
||||
referrer String
|
||||
)
|
||||
engine = MergeTree PRIMARY KEY (session_uuid, created_at)
|
||||
ORDER BY (session_uuid, created_at)
|
||||
SETTINGS index_granularity = 8192;
|
||||
|
||||
CREATE TABLE pageview_queue (
|
||||
website_id UInt32,
|
||||
session_uuid UUID,
|
||||
created_at DateTime('UTC'),
|
||||
url String,
|
||||
referrer String
|
||||
)
|
||||
ENGINE = Kafka
|
||||
SETTINGS kafka_broker_list = 'kafka1:19092,kafka2:19093,kafka3:19094', -- input broker list
|
||||
kafka_topic_list = 'pageview',
|
||||
kafka_group_name = 'pageview_consumer_group',
|
||||
kafka_format = 'JSONEachRow',
|
||||
kafka_max_block_size = 1048576,
|
||||
kafka_skip_broken_messages = 1;
|
||||
|
||||
CREATE MATERIALIZED VIEW pageview_queue_mv TO pageview AS
|
||||
SELECT website_id,
|
||||
session_uuid,
|
||||
created_at,
|
||||
url,
|
||||
referrer
|
||||
FROM pageview_queue;
|
||||
|
||||
-- Create Session
|
||||
CREATE TABLE session
|
||||
(
|
||||
session_uuid UUID,
|
||||
website_id UInt32,
|
||||
created_at DateTime('UTC'),
|
||||
hostname LowCardinality(String),
|
||||
browser LowCardinality(String),
|
||||
os LowCardinality(String),
|
||||
device LowCardinality(String),
|
||||
screen LowCardinality(String),
|
||||
language LowCardinality(String),
|
||||
country LowCardinality(String)
|
||||
)
|
||||
engine = MergeTree PRIMARY KEY (session_uuid, created_at)
|
||||
ORDER BY (session_uuid, created_at)
|
||||
SETTINGS index_granularity = 8192;
|
||||
|
||||
CREATE TABLE session_queue (
|
||||
session_uuid UUID,
|
||||
website_id UInt32,
|
||||
created_at DateTime('UTC'),
|
||||
hostname LowCardinality(String),
|
||||
browser LowCardinality(String),
|
||||
os LowCardinality(String),
|
||||
device LowCardinality(String),
|
||||
screen LowCardinality(String),
|
||||
language LowCardinality(String),
|
||||
country LowCardinality(String)
|
||||
)
|
||||
ENGINE = Kafka
|
||||
SETTINGS kafka_broker_list = 'kafka1:19092,kafka2:19093,kafka3:19094', -- input broker list
|
||||
kafka_topic_list = 'session',
|
||||
kafka_group_name = 'session_consumer_group',
|
||||
kafka_format = 'JSONEachRow',
|
||||
kafka_max_block_size = 1048576,
|
||||
kafka_skip_broken_messages = 1;
|
||||
|
||||
CREATE MATERIALIZED VIEW session_queue_mv TO session AS
|
||||
SELECT session_uuid,
|
||||
website_id,
|
||||
created_at,
|
||||
hostname,
|
||||
browser,
|
||||
os,
|
||||
device,
|
||||
screen,
|
||||
language,
|
||||
country
|
||||
FROM session_queue;
|
||||
|
||||
-- Create event
|
||||
CREATE TABLE event
|
||||
(
|
||||
event_uuid UUID,
|
||||
website_id UInt32,
|
||||
session_uuid UUID,
|
||||
created_at DateTime('UTC'),
|
||||
url String,
|
||||
event_name String,
|
||||
event_data JSON
|
||||
)
|
||||
engine = MergeTree PRIMARY KEY (event_uuid, created_at)
|
||||
ORDER BY (event_uuid, created_at)
|
||||
SETTINGS index_granularity = 8192;
|
||||
|
||||
CREATE TABLE event_queue (
|
||||
event_uuid UUID,
|
||||
website_id UInt32,
|
||||
session_uuid UUID,
|
||||
created_at DateTime('UTC'),
|
||||
url String,
|
||||
event_name String,
|
||||
event_data String
|
||||
)
|
||||
ENGINE = Kafka
|
||||
SETTINGS kafka_broker_list = 'kafka1:19092,kafka2:19093,kafka3:19094', -- input broker list
|
||||
kafka_topic_list = 'event',
|
||||
kafka_group_name = 'event_consumer_group',
|
||||
kafka_format = 'JSONEachRow',
|
||||
kafka_max_block_size = 1048576,
|
||||
kafka_skip_broken_messages = 1;
|
||||
|
||||
CREATE MATERIALIZED VIEW event_queue_mv TO event AS
|
||||
SELECT event_uuid,
|
||||
website_id,
|
||||
session_uuid,
|
||||
created_at,
|
||||
url,
|
||||
event_name,
|
||||
event_data
|
||||
FROM event_queue;
|
70
db/clickhouse/schema.sql
Normal file
70
db/clickhouse/schema.sql
Normal file
@ -0,0 +1,70 @@
|
||||
SET allow_experimental_object_type = 1;
|
||||
|
||||
-- Create Event
|
||||
CREATE TABLE event
|
||||
(
|
||||
website_id UInt32,
|
||||
session_uuid UUID,
|
||||
event_uuid Nullable(UUID),
|
||||
--session
|
||||
hostname LowCardinality(String),
|
||||
browser LowCardinality(String),
|
||||
os LowCardinality(String),
|
||||
device LowCardinality(String),
|
||||
screen LowCardinality(String),
|
||||
language LowCardinality(String),
|
||||
country LowCardinality(String),
|
||||
--pageview
|
||||
url String,
|
||||
referrer String,
|
||||
--event
|
||||
event_name String,
|
||||
event_data JSON,
|
||||
created_at DateTime('UTC')
|
||||
)
|
||||
engine = MergeTree
|
||||
ORDER BY (website_id, session_uuid, created_at)
|
||||
SETTINGS index_granularity = 8192;
|
||||
|
||||
CREATE TABLE event_queue (
|
||||
website_id UInt32,
|
||||
session_uuid UUID,
|
||||
event_uuid Nullable(UUID),
|
||||
url String,
|
||||
referrer String,
|
||||
hostname LowCardinality(String),
|
||||
browser LowCardinality(String),
|
||||
os LowCardinality(String),
|
||||
device LowCardinality(String),
|
||||
screen LowCardinality(String),
|
||||
language LowCardinality(String),
|
||||
country LowCardinality(String),
|
||||
event_name String,
|
||||
event_data String,
|
||||
created_at DateTime('UTC')
|
||||
)
|
||||
ENGINE = Kafka
|
||||
SETTINGS kafka_broker_list = 'domain:9092,domain:9093,domain:9094', -- input broker list
|
||||
kafka_topic_list = 'event',
|
||||
kafka_group_name = 'event_consumer_group',
|
||||
kafka_format = 'JSONEachRow',
|
||||
kafka_max_block_size = 1048576,
|
||||
kafka_skip_broken_messages = 1;
|
||||
|
||||
CREATE MATERIALIZED VIEW event_queue_mv TO event AS
|
||||
SELECT website_id,
|
||||
session_uuid,
|
||||
event_uuid,
|
||||
url,
|
||||
referrer,
|
||||
hostname,
|
||||
browser,
|
||||
os,
|
||||
device,
|
||||
screen,
|
||||
language,
|
||||
country,
|
||||
event_name,
|
||||
event_data,
|
||||
created_at
|
||||
FROM event_queue;
|
11
db/mysql/migrations/04_account_uuid/migration.sql
Normal file
11
db/mysql/migrations/04_account_uuid/migration.sql
Normal file
@ -0,0 +1,11 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE `account` ADD COLUMN `account_uuid` VARCHAR(36);
|
||||
|
||||
-- Backfill UUID
|
||||
UPDATE `account` SET account_uuid=(SELECT uuid());
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE `account` MODIFY `account_uuid` VARCHAR(36) NOT NULL;
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX `account_account_uuid_key` ON `account`(`account_uuid`);
|
@ -8,13 +8,14 @@ datasource db {
|
||||
}
|
||||
|
||||
model account {
|
||||
user_id Int @id @default(autoincrement()) @db.UnsignedInt
|
||||
username String @unique() @db.VarChar(255)
|
||||
password String @db.VarChar(60)
|
||||
is_admin Boolean @default(false)
|
||||
created_at DateTime? @default(now()) @db.Timestamp(0)
|
||||
updated_at DateTime? @default(now()) @db.Timestamp(0)
|
||||
website website[]
|
||||
user_id Int @id @default(autoincrement()) @db.UnsignedInt
|
||||
username String @unique() @db.VarChar(255)
|
||||
password String @db.VarChar(60)
|
||||
is_admin Boolean @default(false)
|
||||
created_at DateTime? @default(now()) @db.Timestamp(0)
|
||||
updated_at DateTime? @default(now()) @db.Timestamp(0)
|
||||
account_uuid String @unique() @db.VarChar(36)
|
||||
website website[]
|
||||
}
|
||||
|
||||
model event {
|
||||
|
12
db/postgresql/migrations/04_account_uuid/migration.sql
Normal file
12
db/postgresql/migrations/04_account_uuid/migration.sql
Normal file
@ -0,0 +1,12 @@
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "account" ADD COLUMN "account_uuid" UUID NULL;
|
||||
|
||||
-- Backfill UUID
|
||||
UPDATE "account" SET account_uuid = gen_random_uuid();
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "account" ALTER COLUMN "account_uuid" SET NOT NULL;
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "account_account_uuid_key" ON "account"("account_uuid");
|
@ -8,13 +8,14 @@ datasource db {
|
||||
}
|
||||
|
||||
model account {
|
||||
user_id Int @id @default(autoincrement())
|
||||
username String @unique @db.VarChar(255)
|
||||
password String @db.VarChar(60)
|
||||
is_admin Boolean @default(false)
|
||||
created_at DateTime? @default(now()) @db.Timestamptz(6)
|
||||
updated_at DateTime? @default(now()) @db.Timestamptz(6)
|
||||
website website[]
|
||||
user_id Int @id @default(autoincrement())
|
||||
username String @unique @db.VarChar(255)
|
||||
password String @db.VarChar(60)
|
||||
is_admin Boolean @default(false)
|
||||
created_at DateTime? @default(now()) @db.Timestamptz(6)
|
||||
updated_at DateTime? @default(now()) @db.Timestamptz(6)
|
||||
account_uuid String @unique @db.Uuid
|
||||
website website[]
|
||||
}
|
||||
|
||||
model event {
|
||||
|
@ -62,6 +62,7 @@
|
||||
"label.username": "用户名",
|
||||
"label.view-details": "查看更多",
|
||||
"label.websites": "网站",
|
||||
"label.yesterday": "昨天",
|
||||
"message.active-users": "当前在线 {x} 人",
|
||||
"message.confirm-delete": "你确定要删除 {target} 吗?",
|
||||
"message.confirm-reset": "您确定要重置 {target} 的数据吗?",
|
||||
|
@ -62,7 +62,7 @@ function getBetweenDates(field, start_at, end_at) {
|
||||
and ${getDateFormat(end_at)}`;
|
||||
}
|
||||
|
||||
function getFilterQuery(table, column, filters = {}, params = []) {
|
||||
function getFilterQuery(column, filters = {}, params = []) {
|
||||
const query = Object.keys(filters).reduce((arr, key) => {
|
||||
const filter = filters[key];
|
||||
|
||||
@ -72,48 +72,28 @@ function getFilterQuery(table, column, filters = {}, params = []) {
|
||||
|
||||
switch (key) {
|
||||
case 'url':
|
||||
if (table === 'pageview' || table === 'event') {
|
||||
arr.push(`and ${table}.${key}=$${params.length + 1}`);
|
||||
params.push(decodeURIComponent(filter));
|
||||
}
|
||||
break;
|
||||
|
||||
case 'os':
|
||||
case 'browser':
|
||||
case 'device':
|
||||
case 'country':
|
||||
if (table === 'session') {
|
||||
arr.push(`and ${table}.${key}=$${params.length + 1}`);
|
||||
params.push(decodeURIComponent(filter));
|
||||
}
|
||||
break;
|
||||
|
||||
case 'event_name':
|
||||
if (table === 'event') {
|
||||
arr.push(`and ${table}.${key}=$${params.length + 1}`);
|
||||
params.push(decodeURIComponent(filter));
|
||||
}
|
||||
arr.push(`and ${key}=$${params.length + 1}`);
|
||||
params.push(decodeURIComponent(filter));
|
||||
break;
|
||||
|
||||
case 'referrer':
|
||||
if (table === 'pageview' || table === 'event') {
|
||||
arr.push(`and ${table}.referrer like $${params.length + 1}`);
|
||||
params.push(`%${decodeURIComponent(filter)}%`);
|
||||
}
|
||||
arr.push(`and referrer like $${params.length + 1}`);
|
||||
params.push(`%${decodeURIComponent(filter)}%`);
|
||||
break;
|
||||
|
||||
case 'domain':
|
||||
if (table === 'pageview') {
|
||||
arr.push(`and ${table}.referrer not like $${params.length + 1}`);
|
||||
arr.push(`and ${table}.referrer not like '/%'`);
|
||||
params.push(`%://${filter}/%`);
|
||||
}
|
||||
arr.push(`and referrer not like $${params.length + 1}`);
|
||||
arr.push(`and referrer not like '/%'`);
|
||||
params.push(`%://${filter}/%`);
|
||||
break;
|
||||
|
||||
case 'query':
|
||||
if (table === 'pageview') {
|
||||
arr.push(`and ${table}.url like '%?%'`);
|
||||
}
|
||||
arr.push(`and url like '%?%'`);
|
||||
}
|
||||
|
||||
return arr;
|
||||
@ -122,7 +102,7 @@ function getFilterQuery(table, column, filters = {}, params = []) {
|
||||
return query.join('\n');
|
||||
}
|
||||
|
||||
function parseFilters(table, column, filters = {}, params = [], sessionKey = 'session_id') {
|
||||
function parseFilters(column, filters = {}, params = []) {
|
||||
const { domain, url, event_url, referrer, os, browser, device, country, event_name, query } =
|
||||
filters;
|
||||
|
||||
@ -135,13 +115,9 @@ function parseFilters(table, column, filters = {}, params = [], sessionKey = 'se
|
||||
sessionFilters,
|
||||
eventFilters,
|
||||
event: { event_name },
|
||||
joinSession:
|
||||
os || browser || device || country
|
||||
? `inner join session on ${table}.${sessionKey} = session.${sessionKey}`
|
||||
: '',
|
||||
pageviewQuery: getFilterQuery('pageview', column, pageviewFilters, params),
|
||||
sessionQuery: getFilterQuery('session', column, sessionFilters, params),
|
||||
eventQuery: getFilterQuery('event', column, eventFilters, params),
|
||||
pageviewQuery: getFilterQuery(column, pageviewFilters, params),
|
||||
sessionQuery: getFilterQuery(column, sessionFilters, params),
|
||||
eventQuery: getFilterQuery(column, eventFilters, params),
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,7 @@ BigInt.prototype.toJSON = function () {
|
||||
};
|
||||
|
||||
export function getDatabaseType(url = process.env.DATABASE_URL) {
|
||||
const type = process.env.DATABASE_TYPE || (url && url.split(':')[0]);
|
||||
const type = url && url.split(':')[0];
|
||||
|
||||
if (type === 'postgres') {
|
||||
return POSTGRESQL;
|
||||
|
37
lib/kafka.js
37
lib/kafka.js
@ -12,7 +12,12 @@ function getClient() {
|
||||
const ssl =
|
||||
username && password
|
||||
? {
|
||||
ssl: true,
|
||||
ssl: {
|
||||
checkServerIdentity: () => undefined,
|
||||
ca: [process.env.CA_CERT],
|
||||
key: process.env.CLIENT_KEY,
|
||||
cert: process.env.CLIENT_CERT,
|
||||
},
|
||||
sasl: {
|
||||
mechanism: 'plain',
|
||||
username,
|
||||
@ -33,6 +38,8 @@ function getClient() {
|
||||
global[KAFKA] = client;
|
||||
}
|
||||
|
||||
log('Kafka initialized');
|
||||
|
||||
return client;
|
||||
}
|
||||
|
||||
@ -44,6 +51,8 @@ async function getProducer() {
|
||||
global[KAFKA_PRODUCER] = producer;
|
||||
}
|
||||
|
||||
log('Kafka producer initialized');
|
||||
|
||||
return producer;
|
||||
}
|
||||
|
||||
@ -52,6 +61,8 @@ function getDateFormat(date) {
|
||||
}
|
||||
|
||||
async function sendMessage(params, topic) {
|
||||
await getKafka();
|
||||
|
||||
await producer.send({
|
||||
topic,
|
||||
messages: [
|
||||
@ -59,25 +70,29 @@ async function sendMessage(params, topic) {
|
||||
value: JSON.stringify(params),
|
||||
},
|
||||
],
|
||||
acks: 0,
|
||||
acks: 1,
|
||||
});
|
||||
}
|
||||
|
||||
async function getKafka() {
|
||||
if (!kafka) {
|
||||
kafka = process.env.KAFKA_URL && process.env.KAFKA_BROKER && (global[KAFKA] || getClient());
|
||||
|
||||
if (kafka) {
|
||||
producer = global[KAFKA_PRODUCER] || (await getProducer());
|
||||
}
|
||||
}
|
||||
|
||||
return kafka;
|
||||
}
|
||||
|
||||
// Initialization
|
||||
let kafka;
|
||||
let producer;
|
||||
|
||||
(async () => {
|
||||
kafka = process.env.KAFKA_URL && process.env.KAFKA_BROKER && (global[KAFKA] || getClient());
|
||||
|
||||
if (kafka) {
|
||||
producer = global[KAFKA_PRODUCER] || (await getProducer());
|
||||
}
|
||||
})();
|
||||
|
||||
export default {
|
||||
client: kafka,
|
||||
producer: producer,
|
||||
producer,
|
||||
log,
|
||||
getDateFormat,
|
||||
sendMessage,
|
||||
|
@ -13,7 +13,12 @@ function getClient() {
|
||||
return null;
|
||||
}
|
||||
|
||||
const redis = new Redis(process.env.REDIS_URL);
|
||||
const redis = new Redis(process.env.REDIS_URL, {
|
||||
retryStrategy(times) {
|
||||
log(`Redis reconnecting attempt: ${times}`);
|
||||
return 5000;
|
||||
},
|
||||
});
|
||||
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
global[REDIS] = redis;
|
||||
|
@ -4,9 +4,12 @@ import { uuid } from 'lib/crypto';
|
||||
import redis, { DELETED } from 'lib/redis';
|
||||
import { getClientInfo, getJsonBody } from 'lib/request';
|
||||
import { createSession, getSessionByUuid, getWebsiteByUuid } from 'queries';
|
||||
import clickhouse from 'lib/clickhouse';
|
||||
|
||||
export async function getSession(req) {
|
||||
const { payload } = getJsonBody(req);
|
||||
const hasRedis = redis.client;
|
||||
const hasClickhouse = clickhouse.client;
|
||||
|
||||
if (!payload) {
|
||||
throw new Error('Invalid request');
|
||||
@ -31,11 +34,11 @@ export async function getSession(req) {
|
||||
let websiteId = null;
|
||||
|
||||
// Check if website exists
|
||||
if (redis.client) {
|
||||
websiteId = await redis.client.get(`website:${website_uuid}`);
|
||||
if (hasRedis) {
|
||||
websiteId = Number(await redis.client.get(`website:${website_uuid}`));
|
||||
}
|
||||
|
||||
// Check database if redis does not have
|
||||
// Check database if does not exists in Redis
|
||||
if (!websiteId) {
|
||||
const website = await getWebsiteByUuid(website_uuid);
|
||||
websiteId = website ? website.website_id : null;
|
||||
@ -46,49 +49,57 @@ export async function getSession(req) {
|
||||
}
|
||||
|
||||
const { userAgent, browser, os, ip, country, device } = await getClientInfo(req, payload);
|
||||
|
||||
const session_uuid = uuid(websiteId, hostname, ip, userAgent);
|
||||
|
||||
let sessionCreated = false;
|
||||
let sessionId = null;
|
||||
let session = null;
|
||||
|
||||
// Check if session exists
|
||||
if (redis.client) {
|
||||
sessionCreated = !!(await redis.client.get(`session:${session_uuid}`));
|
||||
}
|
||||
|
||||
// Check database if redis does not have
|
||||
if (!sessionCreated) {
|
||||
session = await getSessionByUuid(session_uuid);
|
||||
sessionCreated = !!session;
|
||||
sessionId = session ? session.session_id : null;
|
||||
}
|
||||
|
||||
if (!sessionCreated) {
|
||||
try {
|
||||
session = await createSession(websiteId, {
|
||||
session_uuid,
|
||||
hostname,
|
||||
browser,
|
||||
os,
|
||||
screen,
|
||||
language,
|
||||
country,
|
||||
device,
|
||||
});
|
||||
if (!hasClickhouse) {
|
||||
// Check if session exists
|
||||
if (hasRedis) {
|
||||
sessionId = Number(await redis.client.get(`session:${session_uuid}`));
|
||||
}
|
||||
|
||||
// Check database if does not exists in Redis
|
||||
if (!sessionId) {
|
||||
session = await getSessionByUuid(session_uuid);
|
||||
sessionId = session ? session.session_id : null;
|
||||
} catch (e) {
|
||||
if (!e.message.toLowerCase().includes('unique constraint')) {
|
||||
throw e;
|
||||
}
|
||||
|
||||
if (!sessionId) {
|
||||
try {
|
||||
session = await createSession(websiteId, {
|
||||
session_uuid,
|
||||
hostname,
|
||||
browser,
|
||||
os,
|
||||
screen,
|
||||
language,
|
||||
country,
|
||||
device,
|
||||
});
|
||||
} catch (e) {
|
||||
if (!e.message.toLowerCase().includes('unique constraint')) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
session = {
|
||||
session_id: sessionId,
|
||||
session_uuid,
|
||||
hostname,
|
||||
browser,
|
||||
os,
|
||||
screen,
|
||||
language,
|
||||
country,
|
||||
device,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
website_id: websiteId,
|
||||
session_id: sessionId,
|
||||
session_uuid,
|
||||
session,
|
||||
};
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "umami",
|
||||
"version": "1.38.0",
|
||||
"version": "1.39.0-beta.1",
|
||||
"description": "A simple, fast, privacy-focused alternative to Google Analytics.",
|
||||
"author": "Mike Cao <mike@mikecao.com>",
|
||||
"license": "MIT",
|
||||
@ -84,7 +84,7 @@
|
||||
"maxmind": "^4.3.6",
|
||||
"moment-timezone": "^0.5.35",
|
||||
"next": "^12.2.5",
|
||||
"next-basics": "^0.7.0",
|
||||
"next-basics": "^0.12.0",
|
||||
"node-fetch": "^3.2.8",
|
||||
"npm-run-all": "^4.1.5",
|
||||
"prop-types": "^15.7.2",
|
||||
|
@ -1,29 +0,0 @@
|
||||
import { getAccountById, deleteAccount } from 'queries';
|
||||
import { useAuth } from 'lib/middleware';
|
||||
import { methodNotAllowed, ok, unauthorized } from 'next-basics';
|
||||
|
||||
export default async (req, res) => {
|
||||
await useAuth(req, res);
|
||||
|
||||
const { is_admin } = req.auth;
|
||||
const { id } = req.query;
|
||||
const user_id = +id;
|
||||
|
||||
if (!is_admin) {
|
||||
return unauthorized(res);
|
||||
}
|
||||
|
||||
if (req.method === 'GET') {
|
||||
const account = await getAccountById(user_id);
|
||||
|
||||
return ok(res, account);
|
||||
}
|
||||
|
||||
if (req.method === 'DELETE') {
|
||||
await deleteAccount(user_id);
|
||||
|
||||
return ok(res);
|
||||
}
|
||||
|
||||
return methodNotAllowed(res);
|
||||
};
|
@ -1,57 +0,0 @@
|
||||
import { ok, unauthorized, methodNotAllowed, badRequest, hashPassword } from 'next-basics';
|
||||
import { getAccountById, getAccountByUsername, updateAccount, createAccount } from 'queries';
|
||||
import { useAuth } from 'lib/middleware';
|
||||
|
||||
export default async (req, res) => {
|
||||
await useAuth(req, res);
|
||||
|
||||
const { user_id: current_user_id, is_admin: current_user_is_admin } = req.auth;
|
||||
|
||||
if (req.method === 'POST') {
|
||||
const { user_id, username, password, is_admin } = req.body;
|
||||
|
||||
if (user_id) {
|
||||
const account = await getAccountById(user_id);
|
||||
|
||||
if (account.user_id === current_user_id || current_user_is_admin) {
|
||||
const data = {};
|
||||
|
||||
if (password) {
|
||||
data.password = hashPassword(password);
|
||||
}
|
||||
|
||||
// Only admin can change these fields
|
||||
if (current_user_is_admin) {
|
||||
data.username = username;
|
||||
data.is_admin = is_admin;
|
||||
}
|
||||
|
||||
if (data.username && account.username !== data.username) {
|
||||
const accountByUsername = await getAccountByUsername(username);
|
||||
|
||||
if (accountByUsername) {
|
||||
return badRequest(res, 'Account already exists');
|
||||
}
|
||||
}
|
||||
|
||||
const updated = await updateAccount(user_id, data);
|
||||
|
||||
return ok(res, updated);
|
||||
}
|
||||
|
||||
return unauthorized(res);
|
||||
} else {
|
||||
const accountByUsername = await getAccountByUsername(username);
|
||||
|
||||
if (accountByUsername) {
|
||||
return badRequest(res, 'Account already exists');
|
||||
}
|
||||
|
||||
const created = await createAccount({ username, password: hashPassword(password) });
|
||||
|
||||
return ok(res, created);
|
||||
}
|
||||
}
|
||||
|
||||
return methodNotAllowed(res);
|
||||
};
|
68
pages/api/accounts/[id]/index.js
Normal file
68
pages/api/accounts/[id]/index.js
Normal file
@ -0,0 +1,68 @@
|
||||
import { badRequest, hashPassword, methodNotAllowed, ok, unauthorized } from 'next-basics';
|
||||
import { getAccountById, deleteAccount, getAccountByUsername, updateAccount } from 'queries';
|
||||
import { useAuth } from 'lib/middleware';
|
||||
|
||||
export default async (req, res) => {
|
||||
await useAuth(req, res);
|
||||
|
||||
const { is_admin: currentUserIsAdmin, user_id: currentUserId } = req.auth;
|
||||
const { id } = req.query;
|
||||
const userId = +id;
|
||||
|
||||
if (req.method === 'GET') {
|
||||
if (userId !== currentUserId && !currentUserIsAdmin) {
|
||||
return unauthorized(res);
|
||||
}
|
||||
|
||||
const account = await getAccountById(userId);
|
||||
|
||||
return ok(res, account);
|
||||
}
|
||||
|
||||
if (req.method === 'POST') {
|
||||
const { username, password, is_admin } = req.body;
|
||||
|
||||
if (userId !== currentUserId && !currentUserIsAdmin) {
|
||||
return unauthorized(res);
|
||||
}
|
||||
|
||||
const account = await getAccountById(userId);
|
||||
|
||||
const data = {};
|
||||
|
||||
if (password) {
|
||||
data.password = hashPassword(password);
|
||||
}
|
||||
|
||||
// Only admin can change these fields
|
||||
if (currentUserIsAdmin) {
|
||||
data.username = username;
|
||||
data.is_admin = is_admin;
|
||||
}
|
||||
|
||||
// Check when username changes
|
||||
if (data.username && account.username !== data.username) {
|
||||
const accountByUsername = await getAccountByUsername(username);
|
||||
|
||||
if (accountByUsername) {
|
||||
return badRequest(res, 'Account already exists');
|
||||
}
|
||||
}
|
||||
|
||||
const updated = await updateAccount(userId, data);
|
||||
|
||||
return ok(res, updated);
|
||||
}
|
||||
|
||||
if (req.method === 'DELETE') {
|
||||
if (!currentUserIsAdmin) {
|
||||
return unauthorized(res);
|
||||
}
|
||||
|
||||
await deleteAccount(userId);
|
||||
|
||||
return ok(res);
|
||||
}
|
||||
|
||||
return methodNotAllowed(res);
|
||||
};
|
@ -12,24 +12,25 @@ import {
|
||||
export default async (req, res) => {
|
||||
await useAuth(req, res);
|
||||
|
||||
const { user_id: auth_user_id, is_admin } = req.auth;
|
||||
const { user_id, current_password, new_password } = req.body;
|
||||
const { user_id: currentUserId, is_admin: currentUserIsAdmin } = req.auth;
|
||||
const { current_password, new_password } = req.body;
|
||||
const { id } = req.query;
|
||||
const userId = +id;
|
||||
|
||||
if (!is_admin && user_id !== auth_user_id) {
|
||||
if (!currentUserIsAdmin && userId !== currentUserId) {
|
||||
return unauthorized(res);
|
||||
}
|
||||
|
||||
if (req.method === 'POST') {
|
||||
const account = await getAccountById(user_id);
|
||||
const valid = checkPassword(current_password, account.password);
|
||||
const account = await getAccountById(userId);
|
||||
|
||||
if (!valid) {
|
||||
if (!checkPassword(current_password, account.password)) {
|
||||
return badRequest(res, 'Current password is incorrect');
|
||||
}
|
||||
|
||||
const password = hashPassword(new_password);
|
||||
|
||||
const updated = await updateAccount(user_id, { password });
|
||||
const updated = await updateAccount(userId, { password });
|
||||
|
||||
return ok(res, updated);
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
import { getAccounts } from 'queries';
|
||||
import { ok, unauthorized, methodNotAllowed, badRequest, hashPassword } from 'next-basics';
|
||||
import { useAuth } from 'lib/middleware';
|
||||
import { ok, unauthorized, methodNotAllowed } from 'next-basics';
|
||||
import { uuid } from 'lib/crypto';
|
||||
import { createAccount, getAccountByUsername, getAccounts } from 'queries';
|
||||
|
||||
export default async (req, res) => {
|
||||
await useAuth(req, res);
|
||||
@ -17,5 +18,23 @@ export default async (req, res) => {
|
||||
return ok(res, accounts);
|
||||
}
|
||||
|
||||
if (req.method === 'POST') {
|
||||
const { username, password, account_uuid } = req.body;
|
||||
|
||||
const accountByUsername = await getAccountByUsername(username);
|
||||
|
||||
if (accountByUsername) {
|
||||
return badRequest(res, 'Account already exists');
|
||||
}
|
||||
|
||||
const created = await createAccount({
|
||||
username,
|
||||
password: hashPassword(password),
|
||||
account_uuid: account_uuid || uuid(),
|
||||
});
|
||||
|
||||
return ok(res, created);
|
||||
}
|
||||
|
||||
return methodNotAllowed(res);
|
||||
};
|
||||
|
@ -59,7 +59,7 @@ export default async (req, res) => {
|
||||
await useSession(req, res);
|
||||
|
||||
const {
|
||||
session: { website_id, session_id, session_uuid },
|
||||
session: { website_id, session },
|
||||
} = req;
|
||||
|
||||
const { type, payload } = getJsonBody(req);
|
||||
@ -73,12 +73,11 @@ export default async (req, res) => {
|
||||
const event_uuid = uuid();
|
||||
|
||||
if (type === 'pageview') {
|
||||
await savePageView(website_id, { session_id, session_uuid, url, referrer });
|
||||
await savePageView(website_id, { session, url, referrer });
|
||||
} else if (type === 'event') {
|
||||
await saveEvent(website_id, {
|
||||
session,
|
||||
event_uuid,
|
||||
session_id,
|
||||
session_uuid,
|
||||
url,
|
||||
event_name,
|
||||
event_data,
|
||||
@ -87,7 +86,10 @@ export default async (req, res) => {
|
||||
return badRequest(res);
|
||||
}
|
||||
|
||||
const token = createToken({ website_id, session_id, session_uuid }, secret());
|
||||
const token = createToken(
|
||||
{ website_id, session_id: session.session_id, session_uuid: session.session_uuid },
|
||||
secret(),
|
||||
);
|
||||
|
||||
return send(res, token);
|
||||
};
|
||||
|
@ -1,34 +0,0 @@
|
||||
import { methodNotAllowed, ok, unauthorized } from 'next-basics';
|
||||
import { deleteWebsite, getWebsiteById } from 'queries';
|
||||
import { allowQuery } from 'lib/auth';
|
||||
import { useCors } from 'lib/middleware';
|
||||
|
||||
export default async (req, res) => {
|
||||
const { id } = req.query;
|
||||
|
||||
const websiteId = +id;
|
||||
|
||||
if (req.method === 'GET') {
|
||||
await useCors(req, res);
|
||||
|
||||
if (!(await allowQuery(req))) {
|
||||
return unauthorized(res);
|
||||
}
|
||||
|
||||
const website = await getWebsiteById(websiteId);
|
||||
|
||||
return ok(res, website);
|
||||
}
|
||||
|
||||
if (req.method === 'DELETE') {
|
||||
if (!(await allowQuery(req, true))) {
|
||||
return unauthorized(res);
|
||||
}
|
||||
|
||||
await deleteWebsite(websiteId);
|
||||
|
||||
return ok(res);
|
||||
}
|
||||
|
||||
return methodNotAllowed(res);
|
||||
};
|
@ -1,44 +0,0 @@
|
||||
import { ok, unauthorized, methodNotAllowed, getRandomChars } from 'next-basics';
|
||||
import { updateWebsite, createWebsite, getWebsiteById } from 'queries';
|
||||
import { useAuth } from 'lib/middleware';
|
||||
import { uuid } from 'lib/crypto';
|
||||
|
||||
export default async (req, res) => {
|
||||
await useAuth(req, res);
|
||||
|
||||
const { user_id, is_admin } = req.auth;
|
||||
const { website_id, enable_share_url } = req.body;
|
||||
|
||||
if (req.method === 'POST') {
|
||||
const { name, domain, owner } = req.body;
|
||||
const website_owner = parseInt(owner);
|
||||
|
||||
if (website_id) {
|
||||
const website = await getWebsiteById(website_id);
|
||||
|
||||
if (website.user_id !== user_id && !is_admin) {
|
||||
return unauthorized(res);
|
||||
}
|
||||
|
||||
let { share_id } = website;
|
||||
|
||||
if (enable_share_url) {
|
||||
share_id = share_id ? share_id : getRandomChars(8);
|
||||
} else {
|
||||
share_id = null;
|
||||
}
|
||||
|
||||
await updateWebsite(website_id, { name, domain, share_id, user_id: website_owner });
|
||||
|
||||
return ok(res);
|
||||
} else {
|
||||
const website_uuid = uuid();
|
||||
const share_id = enable_share_url ? getRandomChars(8) : null;
|
||||
const website = await createWebsite(website_owner, { website_uuid, name, domain, share_id });
|
||||
|
||||
return ok(res, website);
|
||||
}
|
||||
}
|
||||
|
||||
return methodNotAllowed(res);
|
||||
};
|
59
pages/api/websites/[id]/index.js
Normal file
59
pages/api/websites/[id]/index.js
Normal file
@ -0,0 +1,59 @@
|
||||
import { getRandomChars, methodNotAllowed, ok, unauthorized } from 'next-basics';
|
||||
import { deleteWebsite, getWebsiteById, updateWebsite } from 'queries';
|
||||
import { allowQuery } from 'lib/auth';
|
||||
import { useAuth, useCors } from 'lib/middleware';
|
||||
|
||||
export default async (req, res) => {
|
||||
const { id } = req.query;
|
||||
|
||||
const websiteId = +id;
|
||||
|
||||
if (req.method === 'GET') {
|
||||
await useCors(req, res);
|
||||
|
||||
if (!(await allowQuery(req))) {
|
||||
return unauthorized(res);
|
||||
}
|
||||
|
||||
const website = await getWebsiteById(websiteId);
|
||||
|
||||
return ok(res, website);
|
||||
}
|
||||
|
||||
if (req.method === 'POST') {
|
||||
await useAuth(req, res);
|
||||
|
||||
const { is_admin: currentUserIsAdmin, user_id: currentUserId } = req.auth;
|
||||
const { name, domain, owner, enable_share_url } = req.body;
|
||||
|
||||
const website = await getWebsiteById(websiteId);
|
||||
|
||||
if (website.user_id !== currentUserId && !currentUserIsAdmin) {
|
||||
return unauthorized(res);
|
||||
}
|
||||
|
||||
let { share_id } = website;
|
||||
|
||||
if (enable_share_url) {
|
||||
share_id = share_id ? share_id : getRandomChars(8);
|
||||
} else {
|
||||
share_id = null;
|
||||
}
|
||||
|
||||
await updateWebsite(websiteId, { name, domain, share_id, user_id: +owner });
|
||||
|
||||
return ok(res);
|
||||
}
|
||||
|
||||
if (req.method === 'DELETE') {
|
||||
if (!(await allowQuery(req, true))) {
|
||||
return unauthorized(res);
|
||||
}
|
||||
|
||||
await deleteWebsite(websiteId);
|
||||
|
||||
return ok(res);
|
||||
}
|
||||
|
||||
return methodNotAllowed(res);
|
||||
};
|
@ -48,11 +48,16 @@ export default async (req, res) => {
|
||||
const endDate = new Date(+end_at);
|
||||
|
||||
if (sessionColumns.includes(type)) {
|
||||
let data = await getSessionMetrics(websiteId, startDate, endDate, type, {
|
||||
os,
|
||||
browser,
|
||||
device,
|
||||
country,
|
||||
let data = await getSessionMetrics(websiteId, {
|
||||
startDate,
|
||||
endDate,
|
||||
field: type,
|
||||
filters: {
|
||||
os,
|
||||
browser,
|
||||
device,
|
||||
country,
|
||||
},
|
||||
});
|
||||
|
||||
if (type === 'language') {
|
||||
@ -101,7 +106,13 @@ export default async (req, res) => {
|
||||
query: type === 'query' && table !== 'event' ? true : undefined,
|
||||
};
|
||||
|
||||
const data = await getPageviewMetrics(websiteId, startDate, endDate, column, table, filters);
|
||||
const data = await getPageviewMetrics(websiteId, {
|
||||
startDate,
|
||||
endDate,
|
||||
column,
|
||||
table,
|
||||
filters,
|
||||
});
|
||||
|
||||
return ok(res, data);
|
||||
}
|
@ -26,20 +26,34 @@ export default async (req, res) => {
|
||||
}
|
||||
|
||||
const [pageviews, sessions] = await Promise.all([
|
||||
getPageviewStats(websiteId, startDate, endDate, tz, unit, '*', {
|
||||
url,
|
||||
referrer,
|
||||
os,
|
||||
browser,
|
||||
device,
|
||||
country,
|
||||
getPageviewStats(websiteId, {
|
||||
start_at: startDate,
|
||||
end_at: endDate,
|
||||
timezone: tz,
|
||||
unit,
|
||||
count: '*',
|
||||
filters: {
|
||||
url,
|
||||
referrer,
|
||||
os,
|
||||
browser,
|
||||
device,
|
||||
country,
|
||||
},
|
||||
}),
|
||||
getPageviewStats(websiteId, startDate, endDate, tz, unit, 'distinct pageview.', {
|
||||
url,
|
||||
os,
|
||||
browser,
|
||||
device,
|
||||
country,
|
||||
getPageviewStats(websiteId, {
|
||||
start_at: startDate,
|
||||
end_at: endDate,
|
||||
timezone: tz,
|
||||
unit,
|
||||
count: 'distinct pageview.',
|
||||
filters: {
|
||||
url,
|
||||
os,
|
||||
browser,
|
||||
device,
|
||||
country,
|
||||
},
|
||||
}),
|
||||
]);
|
||||
|
@ -21,21 +21,29 @@ export default async (req, res) => {
|
||||
const prevStartDate = new Date(+start_at - distance);
|
||||
const prevEndDate = new Date(+end_at - distance);
|
||||
|
||||
const metrics = await getWebsiteStats(websiteId, startDate, endDate, {
|
||||
url,
|
||||
referrer,
|
||||
os,
|
||||
browser,
|
||||
device,
|
||||
country,
|
||||
const metrics = await getWebsiteStats(websiteId, {
|
||||
start_at: startDate,
|
||||
end_at: endDate,
|
||||
filters: {
|
||||
url,
|
||||
referrer,
|
||||
os,
|
||||
browser,
|
||||
device,
|
||||
country,
|
||||
},
|
||||
});
|
||||
const prevPeriod = await getWebsiteStats(websiteId, prevStartDate, prevEndDate, {
|
||||
url,
|
||||
referrer,
|
||||
os,
|
||||
browser,
|
||||
device,
|
||||
country,
|
||||
const prevPeriod = await getWebsiteStats(websiteId, {
|
||||
start_at: prevStartDate,
|
||||
end_at: prevEndDate,
|
||||
filters: {
|
||||
url,
|
||||
referrer,
|
||||
os,
|
||||
browser,
|
||||
device,
|
||||
country,
|
||||
},
|
||||
});
|
||||
|
||||
const stats = Object.keys(metrics[0]).reduce((obj, key) => {
|
@ -1,13 +1,20 @@
|
||||
import { getAllWebsites, getUserWebsites } from 'queries';
|
||||
import { createWebsite, getAccount, getAllWebsites, getUserWebsites } from 'queries';
|
||||
import { ok, methodNotAllowed, unauthorized, getRandomChars } from 'next-basics';
|
||||
import { useAuth } from 'lib/middleware';
|
||||
import { ok, methodNotAllowed, unauthorized } from 'next-basics';
|
||||
import { uuid } from 'lib/crypto';
|
||||
|
||||
export default async (req, res) => {
|
||||
await useAuth(req, res);
|
||||
|
||||
const { user_id: current_user_id, is_admin } = req.auth;
|
||||
const { user_id: current_user_id, is_admin, account_uuid } = req.auth;
|
||||
const { user_id, include_all } = req.query;
|
||||
const userId = +user_id;
|
||||
let account;
|
||||
|
||||
if (account_uuid) {
|
||||
account = await getAccount({ account_uuid });
|
||||
}
|
||||
|
||||
const userId = account ? account.user_id : +user_id;
|
||||
|
||||
if (req.method === 'GET') {
|
||||
if (userId && userId !== current_user_id && !is_admin) {
|
||||
@ -22,5 +29,24 @@ export default async (req, res) => {
|
||||
return ok(res, websites);
|
||||
}
|
||||
|
||||
if (req.method === 'POST') {
|
||||
await useAuth(req, res);
|
||||
|
||||
const { is_admin: currentUserIsAdmin, user_id: currentUserId } = req.auth;
|
||||
const { name, domain, owner, enable_share_url } = req.body;
|
||||
|
||||
const website_owner = account ? account.user_id : +owner;
|
||||
|
||||
if (website_owner !== currentUserId && !currentUserIsAdmin) {
|
||||
return unauthorized(res);
|
||||
}
|
||||
|
||||
const website_uuid = uuid();
|
||||
const share_id = enable_share_url ? getRandomChars(8) : null;
|
||||
const website = await createWebsite(website_owner, { website_uuid, name, domain, share_id });
|
||||
|
||||
return ok(res, website);
|
||||
}
|
||||
|
||||
return methodNotAllowed(res);
|
||||
};
|
||||
|
@ -244,7 +244,7 @@
|
||||
"label.none": [
|
||||
{
|
||||
"type": 0,
|
||||
"value": "None"
|
||||
"value": "Байхгүй"
|
||||
}
|
||||
],
|
||||
"label.owner": [
|
||||
@ -397,6 +397,12 @@
|
||||
"value": "Вебүүд"
|
||||
}
|
||||
],
|
||||
"label.yesterday": [
|
||||
{
|
||||
"type": 0,
|
||||
"value": "Өчигдөр"
|
||||
}
|
||||
],
|
||||
"message.active-users": [
|
||||
{
|
||||
"type": 0,
|
||||
@ -456,7 +462,7 @@
|
||||
"message.confirm-reset": [
|
||||
{
|
||||
"type": 0,
|
||||
"value": "Are your sure you want to reset "
|
||||
"value": "Та "
|
||||
},
|
||||
{
|
||||
"type": 1,
|
||||
@ -464,7 +470,7 @@
|
||||
},
|
||||
{
|
||||
"type": 0,
|
||||
"value": "'s statistics?"
|
||||
"value": "-н тоон үзүүлэлтүүдийг устгахдаа итгэлтэй байна уу?"
|
||||
}
|
||||
],
|
||||
"message.copied": [
|
||||
@ -482,7 +488,7 @@
|
||||
"message.edit-dashboard": [
|
||||
{
|
||||
"type": 0,
|
||||
"value": "Edit dashboard"
|
||||
"value": "Хянах самбар засах"
|
||||
}
|
||||
],
|
||||
"message.failure": [
|
||||
@ -770,7 +776,7 @@
|
||||
"metrics.query-parameters": [
|
||||
{
|
||||
"type": 0,
|
||||
"value": "Query parameters"
|
||||
"value": "Query параметр"
|
||||
}
|
||||
],
|
||||
"metrics.referrers": [
|
||||
@ -782,7 +788,7 @@
|
||||
"metrics.screens": [
|
||||
{
|
||||
"type": 0,
|
||||
"value": "Screens"
|
||||
"value": "Дэлгэц"
|
||||
}
|
||||
],
|
||||
"metrics.unique-visitors": [
|
||||
|
@ -397,6 +397,12 @@
|
||||
"value": "网站"
|
||||
}
|
||||
],
|
||||
"label.yesterday": [
|
||||
{
|
||||
"type": 0,
|
||||
"value": "昨天"
|
||||
}
|
||||
],
|
||||
"message.active-users": [
|
||||
{
|
||||
"type": 0,
|
||||
|
7
queries/admin/account/getAccount.js
Normal file
7
queries/admin/account/getAccount.js
Normal file
@ -0,0 +1,7 @@
|
||||
import prisma from 'lib/prisma';
|
||||
|
||||
export async function getAccount(where) {
|
||||
return prisma.client.account.findUnique({
|
||||
where,
|
||||
});
|
||||
}
|
@ -52,7 +52,8 @@ async function clickhouseQuery(
|
||||
${getDateQuery('created_at', unit, timezone)} t,
|
||||
count(*) y
|
||||
from event
|
||||
where website_id= $1
|
||||
where event_name != ''
|
||||
and website_id= $1
|
||||
and ${getBetweenDates('created_at', start_at, end_at)}
|
||||
${getFilterQuery('event', filters, params)}
|
||||
group by x, t
|
||||
|
@ -29,14 +29,15 @@ function clickhouseQuery(websites, start_at) {
|
||||
|
||||
return rawQuery(
|
||||
`select
|
||||
event_id,
|
||||
event_uuid,
|
||||
website_id,
|
||||
session_id,
|
||||
session_uuid,
|
||||
created_at,
|
||||
url,
|
||||
event_name
|
||||
from event
|
||||
where website_id in (${websites.join[',']}
|
||||
and created_at >= ${getDateFormat(start_at)})`,
|
||||
where event_name != ''
|
||||
and ${websites && websites.length > 0 ? `website_id in (${websites.join(',')})` : '0 = 0'}
|
||||
and created_at >= ${getDateFormat(start_at)}`,
|
||||
);
|
||||
}
|
||||
|
@ -33,17 +33,19 @@ async function relationalQuery(website_id, { session_id, url, event_name, event_
|
||||
|
||||
async function clickhouseQuery(
|
||||
website_id,
|
||||
{ event_uuid, session_uuid, url, event_name, event_data },
|
||||
{ session: { country, ...sessionArgs }, event_uuid, url, event_name, event_data },
|
||||
) {
|
||||
const { getDateFormat, sendMessage } = kafka;
|
||||
|
||||
const params = {
|
||||
event_uuid,
|
||||
website_id,
|
||||
session_uuid,
|
||||
created_at: getDateFormat(new Date()),
|
||||
url: url?.substring(0, URL_LENGTH),
|
||||
event_name: event_name?.substring(0, EVENT_NAME_LENGTH),
|
||||
event_data: JSON.stringify(event_data),
|
||||
...sessionArgs,
|
||||
country: country ? country : null,
|
||||
};
|
||||
|
||||
await sendMessage(params, 'event');
|
||||
|
@ -9,9 +9,9 @@ export async function getPageviewMetrics(...args) {
|
||||
});
|
||||
}
|
||||
|
||||
async function relationalQuery(website_id, start_at, end_at, column, table, filters = {}) {
|
||||
async function relationalQuery(website_id, { startDate, endDate, column, table, filters = {} }) {
|
||||
const { rawQuery, parseFilters } = prisma;
|
||||
const params = [website_id, start_at, end_at];
|
||||
const params = [website_id, startDate, endDate];
|
||||
const { pageviewQuery, sessionQuery, eventQuery, joinSession } = parseFilters(
|
||||
table,
|
||||
column,
|
||||
@ -34,26 +34,20 @@ async function relationalQuery(website_id, start_at, end_at, column, table, filt
|
||||
);
|
||||
}
|
||||
|
||||
async function clickhouseQuery(website_id, start_at, end_at, column, table, filters = {}) {
|
||||
async function clickhouseQuery(website_id, { startDate, endDate, column, filters = {} }) {
|
||||
const { rawQuery, parseFilters, getBetweenDates } = clickhouse;
|
||||
const params = [website_id];
|
||||
const { pageviewQuery, sessionQuery, eventQuery, joinSession } = parseFilters(
|
||||
table,
|
||||
column,
|
||||
filters,
|
||||
params,
|
||||
'session_uuid',
|
||||
);
|
||||
const { pageviewQuery, sessionQuery, eventQuery } = parseFilters(column, filters, params);
|
||||
|
||||
return rawQuery(
|
||||
`select ${column} x, count(*) y
|
||||
from ${table}
|
||||
${joinSession}
|
||||
where ${table}.website_id= $1
|
||||
and ${getBetweenDates(table + '.created_at', start_at, end_at)}
|
||||
${pageviewQuery}
|
||||
${joinSession && sessionQuery}
|
||||
${eventQuery}
|
||||
from event
|
||||
where website_id= $1
|
||||
${column !== 'event_name' ? `and event_name = ''` : `and event_name != ''`}
|
||||
and ${getBetweenDates('created_at', startDate, endDate)}
|
||||
${pageviewQuery}
|
||||
${sessionQuery}
|
||||
${eventQuery}
|
||||
group by x
|
||||
order by y desc`,
|
||||
params,
|
||||
|
@ -11,13 +11,15 @@ export async function getPageviewStats(...args) {
|
||||
|
||||
async function relationalQuery(
|
||||
website_id,
|
||||
start_at,
|
||||
end_at,
|
||||
timezone = 'utc',
|
||||
unit = 'day',
|
||||
count = '*',
|
||||
filters = {},
|
||||
sessionKey = 'session_id',
|
||||
{
|
||||
start_at,
|
||||
end_at,
|
||||
timezone = 'utc',
|
||||
unit = 'day',
|
||||
count = '*',
|
||||
filters = {},
|
||||
sessionKey = 'session_id',
|
||||
},
|
||||
) {
|
||||
const { getDateQuery, parseFilters, rawQuery } = prisma;
|
||||
const params = [website_id, start_at, end_at];
|
||||
@ -44,23 +46,11 @@ async function relationalQuery(
|
||||
|
||||
async function clickhouseQuery(
|
||||
website_id,
|
||||
start_at,
|
||||
end_at,
|
||||
timezone = 'UTC',
|
||||
unit = 'day',
|
||||
count = '*',
|
||||
filters = {},
|
||||
sessionKey = 'session_uuid',
|
||||
{ start_at, end_at, timezone = 'UTC', unit = 'day', count = '*', filters = {} },
|
||||
) {
|
||||
const { parseFilters, rawQuery, getDateStringQuery, getDateQuery, getBetweenDates } = clickhouse;
|
||||
const params = [website_id];
|
||||
const { pageviewQuery, sessionQuery, joinSession } = parseFilters(
|
||||
'pageview',
|
||||
null,
|
||||
filters,
|
||||
params,
|
||||
sessionKey,
|
||||
);
|
||||
const { pageviewQuery, sessionQuery } = parseFilters(null, filters, params);
|
||||
|
||||
return rawQuery(
|
||||
`select
|
||||
@ -69,11 +59,11 @@ async function clickhouseQuery(
|
||||
from
|
||||
(select
|
||||
${getDateQuery('created_at', unit, timezone)} t,
|
||||
count(${count !== '*' ? `${count}${sessionKey}` : count}) y
|
||||
from pageview
|
||||
${joinSession}
|
||||
where pageview.website_id= $1
|
||||
and ${getBetweenDates('pageview.created_at', start_at, end_at)}
|
||||
count(${count !== '*' ? 'distinct session_uuid' : count}) y
|
||||
from event
|
||||
where event_name = ''
|
||||
and website_id= $1
|
||||
and ${getBetweenDates('created_at', start_at, end_at)}
|
||||
${pageviewQuery}
|
||||
${sessionQuery}
|
||||
group by t) g
|
||||
|
@ -27,13 +27,13 @@ async function relationalQuery(websites, start_at) {
|
||||
async function clickhouseQuery(websites, start_at) {
|
||||
return clickhouse.rawQuery(
|
||||
`select
|
||||
view_id,
|
||||
website_id,
|
||||
session_id,
|
||||
session_uuid,
|
||||
created_at,
|
||||
url
|
||||
from pageview
|
||||
where website_id in (${websites.join[',']}
|
||||
and created_at >= ${clickhouse.getDateFormat(start_at)})`,
|
||||
from event
|
||||
where event_name = ''
|
||||
and ${websites && websites.length > 0 ? `website_id in (${websites.join(',')})` : '0 = 0'}
|
||||
and created_at >= ${clickhouse.getDateFormat(start_at)}`,
|
||||
);
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ export async function savePageView(...args) {
|
||||
});
|
||||
}
|
||||
|
||||
async function relationalQuery(website_id, { session_id, url, referrer }) {
|
||||
async function relationalQuery(website_id, { session: { session_id }, url, referrer }) {
|
||||
return prisma.client.pageview.create({
|
||||
data: {
|
||||
website_id,
|
||||
@ -21,15 +21,19 @@ async function relationalQuery(website_id, { session_id, url, referrer }) {
|
||||
});
|
||||
}
|
||||
|
||||
async function clickhouseQuery(website_id, { session_uuid, url, referrer }) {
|
||||
async function clickhouseQuery(
|
||||
website_id,
|
||||
{ session: { country, ...sessionArgs }, url, referrer },
|
||||
) {
|
||||
const { getDateFormat, sendMessage } = kafka;
|
||||
const params = {
|
||||
website_id: website_id,
|
||||
session_uuid: session_uuid,
|
||||
created_at: getDateFormat(new Date()),
|
||||
url: url?.substring(0, URL_LENGTH),
|
||||
referrer: referrer?.substring(0, URL_LENGTH),
|
||||
...sessionArgs,
|
||||
country: country ? country : null,
|
||||
};
|
||||
|
||||
await sendMessage(params, 'pageview');
|
||||
await sendMessage(params, 'event');
|
||||
}
|
||||
|
@ -19,11 +19,19 @@ async function relationalQuery(website_id, data) {
|
||||
},
|
||||
select: {
|
||||
session_id: true,
|
||||
session_uuid: true,
|
||||
hostname: true,
|
||||
browser: true,
|
||||
os: true,
|
||||
screen: true,
|
||||
language: true,
|
||||
country: true,
|
||||
device: true,
|
||||
},
|
||||
})
|
||||
.then(async res => {
|
||||
if (redis.client && res) {
|
||||
await redis.client.set(`session:${res.session_uuid}`, 1);
|
||||
await redis.client.set(`session:${res.session_uuid}`, res.session_id);
|
||||
}
|
||||
|
||||
return res;
|
||||
@ -35,20 +43,21 @@ async function clickhouseQuery(
|
||||
{ session_uuid, hostname, browser, os, screen, language, country, device },
|
||||
) {
|
||||
const { getDateFormat, sendMessage } = kafka;
|
||||
|
||||
const params = {
|
||||
session_uuid: session_uuid,
|
||||
website_id: website_id,
|
||||
session_uuid,
|
||||
website_id,
|
||||
created_at: getDateFormat(new Date()),
|
||||
hostname: hostname,
|
||||
browser: browser,
|
||||
os: os,
|
||||
device: device,
|
||||
screen: screen,
|
||||
language: language,
|
||||
hostname,
|
||||
browser,
|
||||
os,
|
||||
device,
|
||||
screen,
|
||||
language,
|
||||
country: country ? country : null,
|
||||
};
|
||||
|
||||
await sendMessage(params, 'session');
|
||||
await sendMessage(params, 'event');
|
||||
|
||||
if (redis.client) {
|
||||
await redis.client.set(`session:${session_uuid}`, 1);
|
||||
|
@ -19,7 +19,7 @@ async function relationalQuery(session_uuid) {
|
||||
})
|
||||
.then(async res => {
|
||||
if (redis.client && res) {
|
||||
await redis.client.set(`session:${res.session_uuid}`, 1);
|
||||
await redis.client.set(`session:${res.session_uuid}`, res.session_id);
|
||||
}
|
||||
|
||||
return res;
|
||||
@ -31,7 +31,7 @@ async function clickhouseQuery(session_uuid) {
|
||||
const params = [session_uuid];
|
||||
|
||||
return rawQuery(
|
||||
`select
|
||||
`select distinct
|
||||
session_uuid,
|
||||
website_id,
|
||||
created_at,
|
||||
@ -42,7 +42,7 @@ async function clickhouseQuery(session_uuid) {
|
||||
screen,
|
||||
language,
|
||||
country
|
||||
from session
|
||||
from event
|
||||
where session_uuid = $1`,
|
||||
params,
|
||||
)
|
||||
|
@ -9,15 +9,10 @@ export async function getSessionMetrics(...args) {
|
||||
});
|
||||
}
|
||||
|
||||
async function relationalQuery(website_id, start_at, end_at, field, filters = {}) {
|
||||
async function relationalQuery(website_id, { startDate, endDate, field, filters = {} }) {
|
||||
const { parseFilters, rawQuery } = prisma;
|
||||
const params = [website_id, start_at, end_at];
|
||||
const { pageviewQuery, sessionQuery, joinSession } = parseFilters(
|
||||
'pageview',
|
||||
null,
|
||||
filters,
|
||||
params,
|
||||
);
|
||||
const params = [website_id, startDate, endDate];
|
||||
const { pageviewQuery, sessionQuery, joinSession } = parseFilters(null, filters, params);
|
||||
|
||||
return rawQuery(
|
||||
`select ${field} x, count(*) y
|
||||
@ -37,29 +32,19 @@ async function relationalQuery(website_id, start_at, end_at, field, filters = {}
|
||||
);
|
||||
}
|
||||
|
||||
async function clickhouseQuery(website_id, start_at, end_at, field, filters = {}) {
|
||||
async function clickhouseQuery(website_id, { startDate, endDate, field, filters = {} }) {
|
||||
const { parseFilters, getBetweenDates, rawQuery } = clickhouse;
|
||||
const params = [website_id];
|
||||
const { pageviewQuery, sessionQuery, joinSession } = parseFilters(
|
||||
'pageview',
|
||||
null,
|
||||
filters,
|
||||
params,
|
||||
'session_uuid',
|
||||
);
|
||||
const { pageviewQuery, sessionQuery } = parseFilters(null, filters, params);
|
||||
|
||||
return rawQuery(
|
||||
`select ${field} x, count(*) y
|
||||
from session as x
|
||||
where x.session_uuid in (
|
||||
select pageview.session_uuid
|
||||
from pageview
|
||||
${joinSession}
|
||||
where pageview.website_id=$1
|
||||
and ${getBetweenDates('pageview.created_at', start_at, end_at)}
|
||||
from event as x
|
||||
where website_id=$1
|
||||
and event_name = ''
|
||||
and ${getBetweenDates('created_at', startDate, endDate)}
|
||||
${pageviewQuery}
|
||||
${sessionQuery}
|
||||
)
|
||||
group by x
|
||||
order by y desc`,
|
||||
params,
|
||||
|
@ -32,7 +32,7 @@ async function clickhouseQuery(websites, start_at) {
|
||||
const { rawQuery, getDateFormat } = clickhouse;
|
||||
|
||||
return rawQuery(
|
||||
`select
|
||||
`select distinct
|
||||
session_uuid,
|
||||
website_id,
|
||||
created_at,
|
||||
@ -43,8 +43,8 @@ async function clickhouseQuery(websites, start_at) {
|
||||
screen,
|
||||
language,
|
||||
country
|
||||
from session
|
||||
where ${websites && websites.length > 0 ? `(website_id in (${websites.join[',']})` : '0 = 0'}
|
||||
from event
|
||||
where ${websites && websites.length > 0 ? `website_id in (${websites.join(',')})` : '0 = 0'}
|
||||
and created_at >= ${getDateFormat(start_at)}`,
|
||||
);
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ async function clickhouseQuery(website_id) {
|
||||
|
||||
return rawQuery(
|
||||
`select count(distinct session_uuid) x
|
||||
from pageview
|
||||
from event
|
||||
where website_id = $1
|
||||
and created_at >= ${getDateFormat(subMinutes(new Date(), 5))}`,
|
||||
params,
|
||||
|
@ -9,7 +9,7 @@ export async function getWebsiteStats(...args) {
|
||||
});
|
||||
}
|
||||
|
||||
async function relationalQuery(website_id, start_at, end_at, filters = {}) {
|
||||
async function relationalQuery(website_id, { start_at, end_at, filters = {} }) {
|
||||
const { getDateQuery, getTimestampInterval, parseFilters, rawQuery } = prisma;
|
||||
const params = [website_id, start_at, end_at];
|
||||
const { pageviewQuery, sessionQuery, joinSession } = parseFilters(
|
||||
@ -41,16 +41,10 @@ async function relationalQuery(website_id, start_at, end_at, filters = {}) {
|
||||
);
|
||||
}
|
||||
|
||||
async function clickhouseQuery(website_id, start_at, end_at, filters = {}) {
|
||||
async function clickhouseQuery(website_id, { start_at, end_at, filters = {} }) {
|
||||
const { rawQuery, getDateQuery, getBetweenDates, parseFilters } = clickhouse;
|
||||
const params = [website_id];
|
||||
const { pageviewQuery, sessionQuery, joinSession } = parseFilters(
|
||||
'pageview',
|
||||
null,
|
||||
filters,
|
||||
params,
|
||||
'session_uuid',
|
||||
);
|
||||
const { pageviewQuery, sessionQuery } = parseFilters(null, filters, params);
|
||||
|
||||
return rawQuery(
|
||||
`select
|
||||
@ -59,18 +53,18 @@ async function clickhouseQuery(website_id, start_at, end_at, filters = {}) {
|
||||
sum(if(t.c = 1, 1, 0)) as "bounces",
|
||||
sum(if(max_time < min_time + interval 1 hour, max_time-min_time, 0)) as "totaltime"
|
||||
from (
|
||||
select pageview.session_uuid,
|
||||
${getDateQuery('pageview.created_at', 'day')} time_series,
|
||||
select session_uuid,
|
||||
${getDateQuery('created_at', 'day')} time_series,
|
||||
count(*) c,
|
||||
min(created_at) min_time,
|
||||
max(created_at) max_time
|
||||
from pageview
|
||||
${joinSession}
|
||||
where pageview.website_id = $1
|
||||
and ${getBetweenDates('pageview.created_at', start_at, end_at)}
|
||||
from event
|
||||
where event_name = ''
|
||||
and website_id = $1
|
||||
and ${getBetweenDates('created_at', start_at, end_at)}
|
||||
${pageviewQuery}
|
||||
${sessionQuery}
|
||||
group by pageview.session_uuid, time_series
|
||||
group by session_uuid, time_series
|
||||
) t;`,
|
||||
params,
|
||||
);
|
||||
|
@ -1,63 +1,31 @@
|
||||
import { createAccount } from './admin/account/createAccount';
|
||||
import { deleteAccount } from './admin/account/deleteAccount';
|
||||
import { getAccountById } from './admin/account/getAccountById';
|
||||
import { getAccountByUsername } from './admin/account/getAccountByUsername';
|
||||
import { getAccounts } from './admin/account/getAccounts';
|
||||
import { updateAccount } from './admin/account/updateAccount';
|
||||
import { createWebsite } from './admin/website/createWebsite';
|
||||
import { deleteWebsite } from './admin/website/deleteWebsite';
|
||||
import { getAllWebsites } from './admin/website/getAllWebsites';
|
||||
import { getUserWebsites } from './admin/website/getUserWebsites';
|
||||
import { getWebsiteById } from './admin/website/getWebsiteById';
|
||||
import { getWebsiteByShareId } from './admin/website/getWebsiteByShareId';
|
||||
import { getWebsiteByUuid } from './admin/website/getWebsiteByUuid';
|
||||
import { resetWebsite } from './admin/website/resetWebsite';
|
||||
import { updateWebsite } from './admin/website/updateWebsite';
|
||||
import { getEventMetrics } from './analytics/event/getEventMetrics';
|
||||
import { getEvents } from './analytics/event/getEvents';
|
||||
import { saveEvent } from './analytics/event/saveEvent';
|
||||
import { getPageviewMetrics } from './analytics/pageview/getPageviewMetrics';
|
||||
import { getPageviewParams } from './analytics/pageview/getPageviewParams';
|
||||
import { getPageviews } from './analytics/pageview/getPageviews';
|
||||
import { getPageviewStats } from './analytics/pageview/getPageviewStats';
|
||||
import { savePageView } from './analytics/pageview/savePageView';
|
||||
import { createSession } from './analytics/session/createSession';
|
||||
import { getSessionByUuid } from './analytics/session/getSessionByUuid';
|
||||
import { getSessionMetrics } from './analytics/session/getSessionMetrics';
|
||||
import { getSessions } from './analytics/session/getSessions';
|
||||
import { getActiveVisitors } from './analytics/stats/getActiveVisitors';
|
||||
import { getRealtimeData } from './analytics/stats/getRealtimeData';
|
||||
import { getWebsiteStats } from './analytics/stats/getWebsiteStats';
|
||||
|
||||
export {
|
||||
createWebsite,
|
||||
deleteWebsite,
|
||||
getAllWebsites,
|
||||
getUserWebsites,
|
||||
getWebsiteById,
|
||||
getWebsiteByShareId,
|
||||
getWebsiteByUuid,
|
||||
resetWebsite,
|
||||
updateWebsite,
|
||||
createAccount,
|
||||
deleteAccount,
|
||||
getAccountById,
|
||||
getAccountByUsername,
|
||||
getAccounts,
|
||||
updateAccount,
|
||||
getEventMetrics,
|
||||
getEvents,
|
||||
saveEvent,
|
||||
getPageviewMetrics,
|
||||
getPageviewParams,
|
||||
getPageviews,
|
||||
getPageviewStats,
|
||||
savePageView,
|
||||
createSession,
|
||||
getSessionByUuid,
|
||||
getSessionMetrics,
|
||||
getSessions,
|
||||
getActiveVisitors,
|
||||
getRealtimeData,
|
||||
getWebsiteStats,
|
||||
};
|
||||
export * from './admin/account/createAccount';
|
||||
export * from './admin/account/deleteAccount';
|
||||
export * from './admin/account/getAccount';
|
||||
export * from './admin/account/getAccountById';
|
||||
export * from './admin/account/getAccountByUsername';
|
||||
export * from './admin/account/getAccounts';
|
||||
export * from './admin/account/updateAccount';
|
||||
export * from './admin/website/createWebsite';
|
||||
export * from './admin/website/deleteWebsite';
|
||||
export * from './admin/website/getAllWebsites';
|
||||
export * from './admin/website/getUserWebsites';
|
||||
export * from './admin/website/getWebsiteById';
|
||||
export * from './admin/website/getWebsiteByShareId';
|
||||
export * from './admin/website/getWebsiteByUuid';
|
||||
export * from './admin/website/resetWebsite';
|
||||
export * from './admin/website/updateWebsite';
|
||||
export * from './analytics/event/getEventMetrics';
|
||||
export * from './analytics/event/getEvents';
|
||||
export * from './analytics/event/saveEvent';
|
||||
export * from './analytics/pageview/getPageviewMetrics';
|
||||
export * from './analytics/pageview/getPageviewParams';
|
||||
export * from './analytics/pageview/getPageviews';
|
||||
export * from './analytics/pageview/getPageviewStats';
|
||||
export * from './analytics/pageview/savePageView';
|
||||
export * from './analytics/session/createSession';
|
||||
export * from './analytics/session/getSessionByUuid';
|
||||
export * from './analytics/session/getSessionMetrics';
|
||||
export * from './analytics/session/getSessions';
|
||||
export * from './analytics/stats/getActiveVisitors';
|
||||
export * from './analytics/stats/getRealtimeData';
|
||||
export * from './analytics/stats/getWebsiteStats';
|
||||
|
@ -1,3 +1,4 @@
|
||||
/* eslint-disable no-console */
|
||||
require('dotenv').config();
|
||||
const { PrismaClient } = require('@prisma/client');
|
||||
const chalk = require('chalk');
|
||||
@ -39,7 +40,7 @@ async function checkConnection() {
|
||||
|
||||
async function checkTables() {
|
||||
try {
|
||||
await prisma.account.findFirst();
|
||||
await prisma.$queryRaw`select * from account limit 1`;
|
||||
|
||||
success('Database tables found.');
|
||||
} catch (e) {
|
||||
|
@ -4731,10 +4731,10 @@ natural-compare@^1.4.0:
|
||||
resolved "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz"
|
||||
integrity sha1-Sr6/7tdUHywnrPspvbvRXI1bpPc=
|
||||
|
||||
next-basics@^0.7.0:
|
||||
version "0.7.0"
|
||||
resolved "https://registry.yarnpkg.com/next-basics/-/next-basics-0.7.0.tgz#ef2a23dcb3bbfb2170df26b8b5f50c823edc1a2a"
|
||||
integrity sha512-Z6u8IU77XqadrntFx98CVmfOBcDOiHvemUW753STMte81W9TLflRgOSg1thIg5iwgzQfvCIaU5I1sd06XvvdeA==
|
||||
next-basics@^0.12.0:
|
||||
version "0.12.0"
|
||||
resolved "https://registry.yarnpkg.com/next-basics/-/next-basics-0.12.0.tgz#e946cdb3f32d5d84f67e7c35b6e2e96750763c62"
|
||||
integrity sha512-3meED1Z9m8QvOsG4bz5OAuyjROdV9Cf75Wq2t+cHiGBh+y8qhTluJduqIXuoY5x0S72/5XvY1mwthW+Og47H9A==
|
||||
dependencies:
|
||||
bcryptjs "^2.4.3"
|
||||
jsonwebtoken "^8.5.1"
|
||||
|
Loading…
Reference in New Issue
Block a user