Skip to content

OpenPanel is an open-source web and product analytics platform, an open-source alternative to Mixpanel with optional self-hosting.

ralph(M15-010): R21: @openpanel/shared created - dependency-free utilities below every package, Node-only code under /server - and the five duplicated copies deleted

ralph0fbe81f184cc
diff --git a/.dependency-cruiser.cjs b/.dependency-cruiser.cjs
index b31faa158..fb449c5a5 100644
--- a/.dependency-cruiser.cjs
+++ b/.dependency-cruiser.cjs
@@ -12,8 +12,12 @@
* - core-layers-*: ADR-022 R22, one rule per layer boundary (see below).
* - constants-stay-isomorphic: a `*.constants.ts` file may depend on nothing
* but zod, another `*.constants.ts` file, or a type-only specifier.
- * - frontend-values-only-constants: apps/start may only VALUE-import
- * @openpanel/core or @openpanel/db through a `*.constants.ts` path.
+ * - frontend-values-only-constants: a web app (apps/start, apps/public,
+ * packages/sdks/*) may only VALUE-import @openpanel/core or @openpanel/db
+ * through a `*.constants.ts` path.
+ * - shared-root-stays-isomorphic: nothing reachable from @openpanel/shared's
+ * root entrypoint imports a node: builtin or the server/ subtree.
+ * - no-web-to-server: a web app may not import @openpanel/shared/server.
*
* Both rules match by filename pattern, not by a hardcoded package.json
* "exists" check, so they hold vacuously (0 matches, exit 0) today, while
@@ -141,6 +145,11 @@ const R22_COMMENT =
'macro instead of imported by it, and the two registry reads moved into the ' +
'registry. A rule that fires is the only durable fix.';
+// ADR-022 R12/R21 — the web tier: everything that ends up in a browser bundle.
+// apps/public and packages/sdks/* joined apps/start in M15-010; before that
+// only apps/start was named, so R12 was unguarded for the other two.
+const FRONTENDS = '^(apps/(start|public)|packages/sdks/)';
+
// The composition root and everything above it.
const COMPOSITION_AND_ABOVE =
'^packages/core/src/(services|rpc\\.router|rest\\.routes|jobs\\.registry|index)\\.ts$';
@@ -330,14 +339,57 @@ module.exports = {
name: 'frontend-values-only-constants',
severity: 'error',
comment:
- 'apps/start may value-import @openpanel/core or @openpanel/db only via a *.constants.ts path.',
- from: { path: '^apps/start' },
+ 'ADR-022 R12: a web app value-imports @openpanel/core or @openpanel/db only through a ' +
+ '*.constants.ts path — everything else arrives as `import type`, which is erased, so no ' +
+ 'server code reaches a browser bundle. M15-010 widened the FROM side: it read `apps/start` ' +
+ 'alone, which left apps/public and packages/sdks/* unguarded by R12 (ADR-022, "The ' +
+ 'existing frontend boundary needs widening at the same time"). @openpanel/shared is ' +
+ 'deliberately NOT in the TO list — its root entrypoint is meant to be value-imported by a ' +
+ 'browser, which is what `shared-root-stays-isomorphic` below makes safe. NOTE: only ' +
+ "`apps/start packages` are cruised today (package.json's check:deps), so the " +
+ 'apps/public half of this rule holds vacuously until that command names it.',
+ from: { path: FRONTENDS },
to: {
path: '^packages/(core|db)/',
pathNot: '\\.constants\\.ts$',
dependencyTypesNot: ['type-only'],
},
},
+ {
+ name: 'shared-root-stays-isomorphic',
+ severity: 'error',
+ comment:
+ "ADR-022 R21: nothing reachable from @openpanel/shared's ROOT entrypoint may import a " +
+ "node: builtin or the server/ subtree. This is the load-bearing half of R21's pair: a " +
+ 'root-reachable file that quietly imports node:crypto still type-checks, still bundles, ' +
+ 'and puts a Node polyfill (or a broken bundle) in every browser that loads the ' +
+ 'dashboard — and the import looks isomorphic at the call site, so nothing else would ' +
+ 'catch it. Node-only code has its own entrypoint, @openpanel/shared/server, and the ' +
+ 'reachability is computed from src/index.ts rather than per-file so a helper added three ' +
+ 'hops down is covered too. dependency-cruiser reports a node: specifier with the prefix ' +
+ 'stripped, hence the two spellings.',
+ from: { path: '^packages/shared/src/index\\.ts$' },
+ to: {
+ path: [
+ '^(node:)?(assert|async_hooks|buffer|child_process|cluster|crypto|dgram|dns|events|fs|http|http2|https|inspector|module|net|os|path|perf_hooks|process|querystring|readline|repl|stream|string_decoder|timers|tls|tty|url|util|v8|vm|worker_threads|zlib)(/|$)',
+ '^packages/shared/src/server/',
+ ],
+ reachable: true,
+ },
+ },
+ {
+ name: 'no-web-to-server',
+ severity: 'error',
+ comment:
+ 'ADR-022 R21: a web app may not import @openpanel/shared/server. This is the readable ' +
+ "half of R21's pair — the deliberate wrong import, a frontend reaching for a " +
+ 'server-only helper (crypto, encryption, safe-fetch, ssrf, parser-user-agent). Unlike ' +
+ 'the root rule above it does not need reachability: the specifier itself is the ' +
+ 'violation. Same caveat as frontend-values-only-constants — apps/public is not cruised ' +
+ "by package.json's check:deps yet, so that third of the FROM side is vacuous today.",
+ from: { path: FRONTENDS },
+ to: { path: '^packages/shared/src/server/' },
+ },
],
options: {
// Only stops the crawl from recursing INTO node_modules (so we don't
diff --git a/apps/start/package.json b/apps/start/package.json
index 88e9d885b..63e1984eb 100644
--- a/apps/start/package.json
+++ b/apps/start/package.json
@@ -35,6 +35,7 @@
"@openpanel/core": "workspace:^",
"@openpanel/payments": "workspace:*",
"@openpanel/sdk-info": "workspace:^",
+ "@openpanel/shared": "workspace:*",
"@openpanel/web": "1.0.5",
"@radix-ui/react-accordion": "1.2.12",
"@radix-ui/react-alert-dialog": "1.1.15",
@@ -112,10 +113,8 @@
"lodash.throttle": "4.1.1",
"lottie-react": "2.4.0",
"lucide-react": "0.555.0",
- "mathjs": "12.3.2",
"mitt": "3.0.1",
"motion": "12.40.0",
- "nanoid": "5.1.6",
"nuqs": "2.5.2",
"prisma-error-enum": "0.1.3",
"pushmodal": "1.0.3",
@@ -148,7 +147,6 @@
"remark-rehype": "11.1.2",
"rrweb-player": "2.0.0-alpha.20",
"short-unique-id": "5.0.3",
- "slugify": "1.6.6",
"sonner": "1.4.0",
"superjson": "2.2.2",
"tailwind-merge": "3.3.1",
diff --git a/apps/start/src/components/charts/op-tooltip.tsx b/apps/start/src/components/charts/op-tooltip.tsx
index b33a52b8d..9eab395bd 100644
--- a/apps/start/src/components/charts/op-tooltip.tsx
+++ b/apps/start/src/components/charts/op-tooltip.tsx
@@ -1,6 +1,6 @@
import type { IInterval } from '@openpanel/core/modules/report/report.constants';
import { type ReactNode, useMemo } from 'react';
-import { getPreviousMetric } from '../../utils/math';
+import { getPreviousMetric } from '../../utils/previous-metric';
import { PreviousDiffIndicatorPure } from '../report-chart/common/previous-diff-indicator';
import { useChart } from './chart-context';
import type { ChartMarker } from './markers/marker-group';
diff --git a/apps/start/src/components/forms/checkbox-item.tsx b/apps/start/src/components/forms/checkbox-item.tsx
index ea86a5e04..7129251dc 100644
--- a/apps/start/src/components/forms/checkbox-item.tsx
+++ b/apps/start/src/components/forms/checkbox-item.tsx
@@ -1,5 +1,5 @@
import { cn } from '@/utils/cn';
-import { slug } from '@/utils/slug';
+import { slug } from '@openpanel/shared';
import type { LucideIcon } from 'lucide-react';
import { forwardRef } from 'react';
import type { ControllerRenderProps } from 'react-hook-form';
diff --git a/apps/start/src/components/organization/billing-usage.tsx b/apps/start/src/components/organization/billing-usage.tsx
index 02c8ea5d8..e3ee5c825 100644
--- a/apps/start/src/components/organization/billing-usage.tsx
+++ b/apps/start/src/components/organization/billing-usage.tsx
@@ -1,4 +1,5 @@
import type { IServiceOrganization } from '@openpanel/core';
+import { sum } from '@openpanel/shared';
import { useQuery } from '@tanstack/react-query';
import { Loader2Icon } from 'lucide-react';
import {
@@ -10,7 +11,6 @@ import {
XAxis,
YAxis,
} from 'recharts';
-import { sum } from '../../utils/math';
import { BarShapeBlue } from '../charts/common-bar';
import {
useXAxisProps,
diff --git a/apps/start/src/components/overview/overview-metric-card.tsx b/apps/start/src/components/overview/overview-metric-card.tsx
index 0dd9b414e..ddafac6b8 100644
--- a/apps/start/src/components/overview/overview-metric-card.tsx
+++ b/apps/start/src/components/overview/overview-metric-card.tsx
@@ -1,7 +1,7 @@
import type { IInterval } from '@openpanel/core/modules/report/report.constants';
import { timeWindows } from '@openpanel/core/modules/report/report.constants';
import { type ReactNode, useState } from 'react';
-import { getPreviousMetric } from '../../utils/math';
+import { getPreviousMetric } from '../../utils/previous-metric';
import { Bar } from '../charts/bar';
import { BarChart } from '../charts/bar-chart';
import {
diff --git a/apps/start/src/components/overview/overview-user-journey.tsx b/apps/start/src/components/overview/overview-user-journey.tsx
index 9f95f6d4f..9e8e7d1b3 100644
--- a/apps/start/src/components/overview/overview-user-journey.tsx
+++ b/apps/start/src/components/overview/overview-user-journey.tsx
@@ -6,7 +6,7 @@ import {
import { useEventQueryFilters } from '@/hooks/use-event-query-filters';
import { useNumber } from '@/hooks/use-numer-formatter';
import { cn } from '@/utils/cn';
-import { round } from '@/utils/math';
+import { round } from '@openpanel/shared';
import { ResponsiveSankey } from '@nivo/sankey';
import { parseAsInteger, useQueryState } from 'nuqs';
import {
diff --git a/apps/start/src/components/report-chart/bar/chart.tsx b/apps/start/src/components/report-chart/bar/chart.tsx
index 31e65a641..0fa19fde2 100644
--- a/apps/start/src/components/report-chart/bar/chart.tsx
+++ b/apps/start/src/components/report-chart/bar/chart.tsx
@@ -1,8 +1,8 @@
import { NOT_SET_VALUE } from '@openpanel/core/modules/report/report.constants';
+import { round } from '@openpanel/shared';
import { DropdownMenuPortal } from '@radix-ui/react-dropdown-menu';
import { SearchIcon } from 'lucide-react';
import { useMemo, useState } from 'react';
-import { round } from '../../../utils/math';
import { SerieIcon } from '../common/serie-icon';
import { SerieName } from '../common/serie-name';
import { useReportChartContext } from '../context';
diff --git a/apps/start/src/components/report-chart/conversion/chart.tsx b/apps/start/src/components/report-chart/conversion/chart.tsx
index b75c730d2..b6befc406 100644
--- a/apps/start/src/components/report-chart/conversion/chart.tsx
+++ b/apps/start/src/components/report-chart/conversion/chart.tsx
@@ -1,4 +1,5 @@
import type { IInterval } from '@openpanel/core/modules/report/report.constants';
+import { average, round } from '@openpanel/shared';
import { useQuery } from '@tanstack/react-query';
import React, { useCallback, useMemo } from 'react';
import {
@@ -11,7 +12,7 @@ import {
XAxis,
YAxis,
} from 'recharts';
-import { average, getPreviousMetric, round } from '../../../utils/math';
+import { getPreviousMetric } from '../../../utils/previous-metric';
import { useXAxisProps, useYAxisProps } from '../common/axis';
import { PreviousDiffIndicator } from '../common/previous-diff-indicator';
import { SerieIcon } from '../common/serie-icon';
diff --git a/apps/start/src/components/report-chart/conversion/conversion-table.tsx b/apps/start/src/components/report-chart/conversion/conversion-table.tsx
index 316e7cf8f..a2d080c7e 100644
--- a/apps/start/src/components/report-chart/conversion/conversion-table.tsx
+++ b/apps/start/src/components/report-chart/conversion/conversion-table.tsx
@@ -1,6 +1,6 @@
import type { SortingState } from '@tanstack/react-table';
import { useMemo, useState } from 'react';
-import { getPreviousMetric } from '../../../utils/math';
+import { getPreviousMetric } from '../../../utils/previous-metric';
import { PreviousDiffIndicatorPure } from '../common/previous-diff-indicator';
import { ReportTableToolbar } from '../common/report-table-toolbar';
import { SerieIcon } from '../common/serie-icon';
diff --git a/apps/start/src/components/report-chart/conversion/summary.tsx b/apps/start/src/components/report-chart/conversion/summary.tsx
index 98411db08..431239b07 100644
--- a/apps/start/src/components/report-chart/conversion/summary.tsx
+++ b/apps/start/src/components/report-chart/conversion/summary.tsx
@@ -1,3 +1,4 @@
+import { average, sum } from '@openpanel/shared';
import {
ArrowDownRight,
ArrowUpRight,
@@ -9,7 +10,6 @@ import {
} from 'lucide-react';
import type React from 'react';
import { useMemo } from 'react';
-import { average, sum } from '../../../utils/math';
import { useReportChartContext } from '../context';
import { useNumber } from '@/hooks/use-numer-formatter';
import type { RouterOutputs } from '@/trpc/client';
diff --git a/apps/start/src/components/report-chart/funnel/breakdown-list.tsx b/apps/start/src/components/report-chart/funnel/breakdown-list.tsx
index f08ea1fb8..f3f8004ed 100644
--- a/apps/start/src/components/report-chart/funnel/breakdown-list.tsx
+++ b/apps/start/src/components/report-chart/funnel/breakdown-list.tsx
@@ -1,6 +1,6 @@
import { ChevronDown, ChevronRight } from 'lucide-react';
import { useState } from 'react';
-import { getPreviousMetric } from '../../../utils/math';
+import { getPreviousMetric } from '../../../utils/previous-metric';
import { PreviousDiffIndicatorPure } from '../common/previous-diff-indicator';
import { Tables } from './chart';
import { Checkbox } from '@/components/ui/checkbox';
diff --git a/apps/start/src/components/report-chart/funnel/chart.tsx b/apps/start/src/components/report-chart/funnel/chart.tsx
index 7cc2d593f..82deef418 100644
--- a/apps/start/src/components/report-chart/funnel/chart.tsx
+++ b/apps/start/src/components/report-chart/funnel/chart.tsx
@@ -11,7 +11,7 @@ import {
XAxis,
YAxis,
} from 'recharts';
-import { getPreviousMetric } from '../../../utils/math';
+import { getPreviousMetric } from '../../../utils/previous-metric';
import { useXAxisProps, useYAxisProps } from '../common/axis';
import { PreviousDiffIndicatorPure } from '../common/previous-diff-indicator';
import { SerieIcon } from '../common/serie-icon';
diff --git a/apps/start/src/components/report-chart/pie/chart.tsx b/apps/start/src/components/report-chart/pie/chart.tsx
index ae19c3104..e5bce7802 100644
--- a/apps/start/src/components/report-chart/pie/chart.tsx
+++ b/apps/start/src/components/report-chart/pie/chart.tsx
@@ -3,7 +3,7 @@ import { useVisibleSeries } from '@/hooks/use-visible-series';
import { useDispatch } from '@/redux';
import type { IChartData } from '@/trpc/client';
import { cn } from '@/utils/cn';
-import { round } from '@/utils/math';
+import { round } from '@openpanel/shared';
import { getChartColor } from '@/utils/theme';
import { truncate } from '@/utils/truncate';
import { Fragment } from 'react';
diff --git a/apps/start/src/components/report-chart/retention/chart.tsx b/apps/start/src/components/report-chart/retention/chart.tsx
index 2016529cb..5ef311b5d 100644
--- a/apps/start/src/components/report-chart/retention/chart.tsx
+++ b/apps/start/src/components/report-chart/retention/chart.tsx
@@ -1,3 +1,4 @@
+import { average, round } from '@openpanel/shared';
import {
Area,
CartesianGrid,
@@ -8,7 +9,6 @@ import {
XAxis,
YAxis,
} from 'recharts';
-import { average, round } from '../../../utils/math';
import { useXAxisProps, useYAxisProps } from '../common/axis';
import { useReportChartContext } from '../context';
import { RetentionTooltip } from './tooltip';
diff --git a/apps/start/src/components/report-chart/retention/table.tsx b/apps/start/src/components/report-chart/retention/table.tsx
index 2e830428c..467a29a76 100644
--- a/apps/start/src/components/report-chart/retention/table.tsx
+++ b/apps/start/src/components/report-chart/retention/table.tsx
@@ -1,4 +1,4 @@
-import { max, min } from '../../../utils/math';
+import { max, min } from '@openpanel/shared';
import { useReportChartContext } from '../context';
import { useNumber } from '@/hooks/use-numer-formatter';
import type { RouterOutputs } from '@/trpc/client';
diff --git a/apps/start/src/components/report-chart/sankey/chart.tsx b/apps/start/src/components/report-chart/sankey/chart.tsx
index 57cd4a2d6..73605914f 100644
--- a/apps/start/src/components/report-chart/sankey/chart.tsx
+++ b/apps/start/src/components/report-chart/sankey/chart.tsx
@@ -4,7 +4,7 @@ import {
ChartTooltipItem,
} from '@/components/charts/chart-tooltip';
import { useNumber } from '@/hooks/use-numer-formatter';
-import { round } from '@/utils/math';
+import { round } from '@openpanel/shared';
import { ResponsiveSankey } from '@nivo/sankey';
import {
type ReactNode,
diff --git a/apps/start/src/components/report/reportSlice.ts b/apps/start/src/components/report/reportSlice.ts
index 3b23862c2..c693be607 100644
--- a/apps/start/src/components/report/reportSlice.ts
+++ b/apps/start/src/components/report/reportSlice.ts
@@ -17,10 +17,10 @@ import {
isHourIntervalEnabledByRange,
isMinuteIntervalEnabledByRange,
} from '@openpanel/core/modules/report/report.constants';
+import { shortId } from '@openpanel/shared';
import type { PayloadAction } from '@reduxjs/toolkit';
import { createSlice } from '@reduxjs/toolkit';
import type { z } from 'zod';
-import { shortId } from '../../utils/math';
import type { UnionOmit } from '../../utils/union-omit';
type InitialState = IReport & {
diff --git a/apps/start/src/components/report/sidebar/ReportGlobalFilters.tsx b/apps/start/src/components/report/sidebar/ReportGlobalFilters.tsx
index 40426ace2..a9d76a0d0 100644
--- a/apps/start/src/components/report/sidebar/ReportGlobalFilters.tsx
+++ b/apps/start/src/components/report/sidebar/ReportGlobalFilters.tsx
@@ -1,5 +1,5 @@
+import { shortId } from '@openpanel/shared';
import { FilterIcon, type LucideIcon } from 'lucide-react';
-import { shortId } from '../../../utils/math';
import { addGlobalFilter } from '../reportSlice';
import { GlobalFilterItem } from './filters/GlobalFilterItem';
import { PropertiesCombobox } from './PropertiesCombobox';
diff --git a/apps/start/src/components/report/sidebar/ReportSeriesItem.tsx b/apps/start/src/components/report/sidebar/ReportSeriesItem.tsx
index b09208006..8ccb62e62 100644
--- a/apps/start/src/components/report/sidebar/ReportSeriesItem.tsx
+++ b/apps/start/src/components/report/sidebar/ReportSeriesItem.tsx
@@ -3,8 +3,8 @@ import type {
IChartEventItem,
} from '@openpanel/core/modules/report/report.constants';
import { alphabetIds } from '@openpanel/core/modules/report/report.constants';
+import { shortId } from '@openpanel/shared';
import { DatabaseIcon, FilterIcon, type LucideIcon } from 'lucide-react';
-import { shortId } from '../../../utils/math';
import { ReportSegment } from '../ReportSegment';
import { changeEvent } from '../reportSlice';
import { FiltersList } from './filters/FiltersList';
diff --git a/apps/start/src/components/sessions/table/columns.tsx b/apps/start/src/components/sessions/table/columns.tsx
index 204bcb567..aa1f5ed6e 100644
--- a/apps/start/src/components/sessions/table/columns.tsx
+++ b/apps/start/src/components/sessions/table/columns.tsx
@@ -1,7 +1,7 @@
import type { IServiceSession } from '@openpanel/core';
+import { round } from '@openpanel/shared';
import type { ColumnDef } from '@tanstack/react-table';
import { Video } from 'lucide-react';
-import { round } from '../../../utils/math';
import { ColumnCreatedAt } from '@/components/column-created-at';
import { ProjectLink } from '@/components/links';
import { ProfileAvatar } from '@/components/profiles/profile-avatar';
diff --git a/apps/start/src/components/settings/edit-project-filters.tsx b/apps/start/src/components/settings/edit-project-filters.tsx
index 165b8a118..8bba2cc01 100644
--- a/apps/start/src/components/settings/edit-project-filters.tsx
+++ b/apps/start/src/components/settings/edit-project-filters.tsx
@@ -10,12 +10,12 @@ import type {
IChartEventFilterOperator,
IChartEventFilterValue,
} from '@openpanel/core/modules/report/report.constants';
+import { shortId } from '@openpanel/shared';
import { useMutation } from '@tanstack/react-query';
import { PlusIcon, SaveIcon, Trash2Icon } from 'lucide-react';
import { Controller, useForm } from 'react-hook-form';
import { toast } from 'sonner';
import { z } from 'zod';
-import { shortId } from '../../utils/math';
import { WithLabel } from '@/components/forms/input-with-label';
import TagInput from '@/components/forms/tag-input';
import { PureFilterItem } from '@/components/report/sidebar/filters/FilterItem';
diff --git a/apps/start/src/components/ui/progress.tsx b/apps/start/src/components/ui/progress.tsx
index 34bfc1449..fb883408f 100644
--- a/apps/start/src/components/ui/progress.tsx
+++ b/apps/start/src/components/ui/progress.tsx
@@ -1,5 +1,5 @@
import { cn } from '@/utils/cn';
-import { round } from '@/utils/math';
+import { round } from '@openpanel/shared';
import * as ProgressPrimitive from '@radix-ui/react-progress';
import * as React from 'react';
diff --git a/apps/start/src/hooks/use-numer-formatter.ts b/apps/start/src/hooks/use-numer-formatter.ts
index 46827c072..45fa485e9 100644
--- a/apps/start/src/hooks/use-numer-formatter.ts
+++ b/apps/start/src/hooks/use-numer-formatter.ts
@@ -1,4 +1,4 @@
-import { round } from '@/utils/math';
+import { round } from '@openpanel/shared';
import { isNil } from 'ramda';
export function fancyMinutes(time: number) {
diff --git a/apps/start/src/hooks/use-ws.ts b/apps/start/src/hooks/use-ws.ts
index 4b86c96b7..31919c654 100644
--- a/apps/start/src/hooks/use-ws.ts
+++ b/apps/start/src/hooks/use-ws.ts
@@ -1,7 +1,7 @@
+import { getSuperJson } from '@openpanel/shared';
import debounce from 'lodash.debounce';
import { useEffect, useMemo, useRef, useState } from 'react';
import { useWebSocket } from 'react-use-websocket/dist/lib/use-websocket';
-import { getSuperJson } from '../utils/super-json';
import { useAppContext } from './use-app-context';
type UseWSOptions = {
diff --git a/apps/start/src/modals/add-notification-rule.tsx b/apps/start/src/modals/add-notification-rule.tsx
index 8f75f169d..acca30cce 100644
--- a/apps/start/src/modals/add-notification-rule.tsx
+++ b/apps/start/src/modals/add-notification-rule.tsx
@@ -1,6 +1,7 @@
import { zodResolver } from '@hookform/resolvers/zod';
import { isKind } from '@openpanel/core/modules/integration/integration.constants';
import { zCreateNotificationRule } from '@openpanel/core/modules/notification/notification.constants';
+import { shortId } from '@openpanel/shared';
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
import { FilterIcon, PlusIcon, SaveIcon, TrashIcon } from 'lucide-react';
import {
@@ -13,7 +14,6 @@ import {
} from 'react-hook-form';
import { toast } from 'sonner';
import type { z } from 'zod';
-import { shortId } from '../utils/math';
import { popModal } from '.';
import { ModalHeader } from './Modal/Container';
import { ColorSquare } from '@/components/color-square';
diff --git a/apps/start/src/utils/math.test.ts b/apps/start/src/utils/math.test.ts
deleted file mode 100644
index 624288c31..000000000
--- a/apps/start/src/utils/math.test.ts
+++ /dev/null
@@ -1,15 +0,0 @@
-// Ported from packages/core/src/shared/id.test.ts's `describe('shortId')`
-// block — the only id.test.ts coverage relevant here, since generateId
-// isn't one of the seven utilities copied into this file.
-import { describe, expect, test } from 'vitest';
-import { shortId } from './math';
-
-describe('shortId', () => {
- test('is 4 characters', () => {
- expect(shortId()).toHaveLength(4);
- });
-
- test('is not the same twice in a row', () => {
- expect(shortId()).not.toBe(shortId());
- });
-});
diff --git a/apps/start/src/utils/math.ts b/apps/start/src/utils/math.ts
deleted file mode 100644
index 8fccb12f0..000000000
--- a/apps/start/src/utils/math.ts
+++ /dev/null
@@ -1,88 +0,0 @@
-// Copied from @openpanel/core/src/shared/math.ts + id.ts (ADR-007/ADR-008:
-// frontend-values-only-constants forbids apps/start value-importing core
-// outside a *.constants.ts path, so these seven common utils are duplicated
-// here rather than re-exported).
-//
-// `isNumber` is mathjs's, not `typeof n === 'number'` — it is the filter
-// predicate for every chart aggregate below, so it stays exactly as it was.
-
-import type { PreviousValue } from '@openpanel/core/modules/report/report.constants';
-import { isNumber } from 'mathjs';
-import { nanoid } from 'nanoid/non-secure';
-import { isNil } from 'ramda';
-
-const SHORT_ID_LENGTH = 4;
-
-export function shortId(): string {
- return nanoid(SHORT_ID_LENGTH);
-}
-
-export const round = (num: number, decimals = 2) => {
- const factor = 10 ** decimals;
- return Math.round((num + Number.EPSILON) * factor) / factor;
-};
-
-export const average = (arr: (number | null)[], includeZero = false) => {
- const filtered = arr.filter(
- (n): n is number =>
- isNumber(n) &&
- !Number.isNaN(n) &&
- Number.isFinite(n) &&
- (includeZero || n !== 0)
- );
- const avg = filtered.reduce((p, c) => p + c, 0) / filtered.length;
- return Number.isNaN(avg) ? 0 : avg;
-};
-
-export const sum = (arr: (number | null | undefined)[]): number =>
- round(arr.filter(isNumber).reduce((acc, item) => acc + item, 0));
-
-export const min = (arr: (number | null | undefined)[]): number => {
- const filtered = arr.filter(isNumber);
- if (filtered.length === 0) {
- return 0;
- }
- return filtered.reduce((a, b) => (b < a ? b : a), filtered[0]!);
-};
-
-export const max = (arr: (number | null | undefined)[]): number => {
- const filtered = arr.filter(isNumber);
- if (filtered.length === 0) {
- return 0;
- }
- return filtered.reduce((a, b) => (b > a ? b : a), filtered[0]!);
-};
-
-export function getPreviousMetric(
- current: number,
- previous: number | null | undefined
-): PreviousValue {
- if (isNil(previous)) {
- return undefined;
- }
-
- const diff = round(
- ((current > previous
- ? current / previous
- : current < previous
- ? previous / current
- : 0) -
- 1) *
- 100,
- 1
- );
-
- return {
- diff:
- Number.isNaN(diff) || !Number.isFinite(diff) || current === previous
- ? null
- : diff,
- state:
- current > previous
- ? 'positive'
- : current < previous
- ? 'negative'
- : 'neutral',
- value: previous,
- };
-}
diff --git a/apps/start/src/utils/previous-metric.test.ts b/apps/start/src/utils/previous-metric.test.ts
new file mode 100644
index 000000000..dab7bf051
--- /dev/null
+++ b/apps/start/src/utils/previous-metric.test.ts
@@ -0,0 +1,56 @@
+// Replaces utils/math.test.ts: the `shortId` it covered moved to
+// @openpanel/shared (M15-010) and is tested there
+// (packages/core/src/shared/id.test.ts). What is left in this file is the one
+// helper that stays duplicated between the dashboard and core, so it is the
+// one worth a test here.
+import { describe, expect, test } from 'vitest';
+import { getPreviousMetric } from './previous-metric';
+
+describe('getPreviousMetric', () => {
+ test('is undefined without a previous value', () => {
+ expect(getPreviousMetric(5, undefined)).toBeUndefined();
+ expect(getPreviousMetric(5, null)).toBeUndefined();
+ });
+
+ test('reports growth as a positive percentage', () => {
+ expect(getPreviousMetric(100, 50)).toEqual({
+ diff: 100,
+ state: 'positive',
+ value: 50,
+ });
+ });
+
+ test('reports a drop as negative, with the ratio the other way round', () => {
+ expect(getPreviousMetric(50, 100)).toEqual({
+ diff: 100,
+ state: 'negative',
+ value: 100,
+ });
+ expect(getPreviousMetric(3, 7)).toEqual({
+ diff: 133.3,
+ state: 'negative',
+ value: 7,
+ });
+ });
+
+ test('an unchanged value is neutral with no diff', () => {
+ expect(getPreviousMetric(10, 10)).toEqual({
+ diff: null,
+ state: 'neutral',
+ value: 10,
+ });
+ });
+
+ test('a zero on either side keeps the direction but drops the diff', () => {
+ expect(getPreviousMetric(5, 0)).toEqual({
+ diff: null,
+ state: 'positive',
+ value: 0,
+ });
+ expect(getPreviousMetric(0, 5)).toEqual({
+ diff: null,
+ state: 'negative',
+ value: 5,
+ });
+ });
+});
diff --git a/apps/start/src/utils/previous-metric.ts b/apps/start/src/utils/previous-metric.ts
new file mode 100644
index 000000000..9f49188ce
--- /dev/null
+++ b/apps/start/src/utils/previous-metric.ts
@@ -0,0 +1,45 @@
+// The dashboard's copy of packages/core/src/modules/report/src/previous-metric.ts.
+//
+// M15-010 moved the six generic aggregates and `shortId` that used to sit
+// beside it into @openpanel/shared, which the dashboard now imports directly.
+// This one function stays duplicated: it returns `PreviousValue`, report
+// vocabulary, and ADR-022 R21 keeps domain constants out of @openpanel/shared
+// while R12 keeps apps/start from value-importing core outside a
+// `*.constants.ts` path. The type is safe to import — it is erased.
+import type { PreviousValue } from '@openpanel/core/modules/report/report.constants';
+import { round } from '@openpanel/shared';
+import { isNil } from 'ramda';
+
+export function getPreviousMetric(
+ current: number,
+ previous: number | null | undefined
+): PreviousValue {
+ if (isNil(previous)) {
+ return undefined;
+ }
+
+ const diff = round(
+ ((current > previous
+ ? current / previous
+ : current < previous
+ ? previous / current
+ : 0) -
+ 1) *
+ 100,
+ 1
+ );
+
+ return {
+ diff:
+ Number.isNaN(diff) || !Number.isFinite(diff) || current === previous
+ ? null
+ : diff,
+ state:
+ current > previous
+ ? 'positive'
+ : current < previous
+ ? 'negative'
+ : 'neutral',
+ value: previous,
+ };
+}
diff --git a/apps/start/src/utils/slug.ts b/apps/start/src/utils/slug.ts
deleted file mode 100644
index 3197ae0c9..000000000
--- a/apps/start/src/utils/slug.ts
+++ /dev/null
@@ -1,22 +0,0 @@
-// Copied from @openpanel/core/src/shared/slug.ts (ADR-007/ADR-008:
-// frontend-values-only-constants forbids apps/start value-importing core
-// outside a *.constants.ts path).
-import _slugify from 'slugify';
-
-const slugify = (str: string) => {
- return _slugify(
- str
- .replaceAll('å', 'a')
- .replaceAll('ä', 'a')
- .replaceAll('ö', 'o')
- .replaceAll('Å', 'A')
- .replaceAll('Ä', 'A')
- .replaceAll('Ö', 'O')
- .replace(/\|+/g, '-'),
- { lower: true, strict: true, trim: true }
- );
-};
-
-export function slug(str: string): string {
- return slugify(str);
-}
diff --git a/apps/start/src/utils/super-json.ts b/apps/start/src/utils/super-json.ts
deleted file mode 100644
index 1b2cbf56a..000000000
--- a/apps/start/src/utils/super-json.ts
+++ /dev/null
@@ -1,22 +0,0 @@
-// Copied from @openpanel/core/src/shared/json.ts (ADR-007/ADR-008:
-// frontend-values-only-constants forbids apps/start value-importing core
-// outside a *.constants.ts path). getSuperJson only hands off to superjson's
-// parser when the payload looks like its own `{ json, meta }` envelope; a
-// plain JSON payload round-trips through JSON.parse instead.
-import superjson from 'superjson';
-
-function getSafeJson<T>(str: string): T | null {
- try {
- return JSON.parse(str);
- } catch {
- return null;
- }
-}
-
-export function getSuperJson<T>(str: string): T | null {
- const json = getSafeJson<T>(str);
- if (typeof json === 'object' && json !== null && 'json' in json) {
- return superjson.parse<T>(str);
- }
- return json;
-}
diff --git a/bun.lock b/bun.lock
index 5f82f0e1a..9e7a55b58 100644
--- a/bun.lock
+++ b/bun.lock
@@ -111,6 +111,7 @@
"@openpanel/core": "workspace:^",
"@openpanel/payments": "workspace:*",
"@openpanel/sdk-info": "workspace:^",
+ "@openpanel/shared": "workspace:*",
"@openpanel/web": "1.0.5",
"@radix-ui/react-accordion": "1.2.12",
"@radix-ui/react-alert-dialog": "1.1.15",
@@ -188,10 +189,8 @@
"lodash.throttle": "4.1.1",
"lottie-react": "2.4.0",
"lucide-react": "0.555.0",
- "mathjs": "12.3.2",
"mitt": "3.0.1",
"motion": "12.40.0",
- "nanoid": "5.1.6",
"nuqs": "2.5.2",
"prisma-error-enum": "0.1.3",
"pushmodal": "1.0.3",
@@ -224,7 +223,6 @@
"remark-rehype": "11.1.2",
"rrweb-player": "2.0.0-alpha.20",
"short-unique-id": "5.0.3",
- "slugify": "1.6.6",
"sonner": "1.4.0",
"superjson": "2.2.2",
"tailwind-merge": "3.3.1",
@@ -302,6 +300,7 @@
"@openpanel/email": "workspace:*",
"@openpanel/payments": "workspace:*",
"@openpanel/redis": "workspace:*",
+ "@openpanel/shared": "workspace:*",
"@oslojs/crypto": "1.0.1",
"@oslojs/encoding": "1.1.0",
"@oslojs/otp": "1.1.0",
@@ -316,13 +315,10 @@
"elysia": "1.4.30",
"fast-deep-equal": "3.1.3",
"fast-json-stable-hash": "1.0.3",
- "ipaddr.js": "2.5.0",
"js-yaml": "4.1.1",
"kafkajs": "2.2.4",
"lru-cache": "11.5.1",
- "luxon": "3.7.2",
"mathjs": "12.3.2",
- "nanoid": "5.1.6",
"pino": "catalog:",
"pino-pretty": "catalog:",
"prisma-error-enum": "0.1.3",
@@ -331,10 +327,7 @@
"ramda": "0.29.1",
"sharp": "0.33.5",
"short-unique-id": "5.0.3",
- "slugify": "1.6.6",
"superjson": "2.2.2",
- "ua-parser-js": "2.0.6",
- "undici": "8.10.0",
"unzipper": "0.12.5",
"url-metadata": "5.4.1",
"uuid": "9.0.1",
@@ -344,7 +337,6 @@
"@clickhouse/client": "1.18.5",
"@openpanel/tsconfig": "workspace:*",
"@types/js-yaml": "4.0.9",
- "@types/luxon": "3.7.1",
"@types/qrcode": "1.5.6",
"@types/ramda": "0.31.0",
"@types/unzipper": "0.10.11",
@@ -423,9 +415,9 @@
"name": "@openpanel/redis",
"version": "0.0.1",
"dependencies": {
+ "@openpanel/shared": "workspace:*",
"ioredis": "5.8.2",
"lru-cache": "11.5.1",
- "superjson": "2.2.2",
},
"devDependencies": {
"@openpanel/core": "workspace:*",
@@ -562,6 +554,29 @@
"typescript": "catalog:",
},
},
+ "packages/shared": {
+ "name": "@openpanel/shared",
+ "version": "0.0.1",
+ "dependencies": {
+ "ipaddr.js": "2.5.0",
+ "lru-cache": "11.5.1",
+ "luxon": "3.7.2",
+ "mathjs": "12.3.2",
+ "nanoid": "5.1.6",
+ "ramda": "0.29.1",
+ "slugify": "1.6.6",
+ "superjson": "2.2.2",
+ "ua-parser-js": "2.0.6",
+ "undici": "8.10.0",
+ },
+ "devDependencies": {
+ "@openpanel/tsconfig": "workspace:*",
+ "@types/luxon": "3.7.1",
+ "@types/node": "catalog:",
+ "@types/ramda": "0.31.0",
+ "typescript": "catalog:",
+ },
+ },
"tooling/publish": {
"name": "@openpanel/publish",
"version": "0.1.0",
@@ -1565,6 +1580,8 @@
"@openpanel/sdk-info": ["@openpanel/sdk-info@workspace:packages/sdks/_info"],
+ "@openpanel/shared": ["@openpanel/shared@workspace:packages/shared"],
+
"@openpanel/testbed": ["@openpanel/testbed@workspace:apps/testbed"],
"@openpanel/tsconfig": ["@openpanel/tsconfig@workspace:tooling/typescript"],
diff --git a/packages/core/package.json b/packages/core/package.json
index 65fba95d1..8a1ee6288 100644
--- a/packages/core/package.json
+++ b/packages/core/package.json
@@ -37,6 +37,7 @@
"@openpanel/email": "workspace:*",
"@openpanel/payments": "workspace:*",
"@openpanel/redis": "workspace:*",
+ "@openpanel/shared": "workspace:*",
"@oslojs/crypto": "1.0.1",
"@oslojs/encoding": "1.1.0",
"@oslojs/otp": "1.1.0",
@@ -51,13 +52,10 @@
"elysia": "1.4.30",
"fast-deep-equal": "3.1.3",
"fast-json-stable-hash": "1.0.3",
- "ipaddr.js": "2.5.0",
"js-yaml": "4.1.1",
"kafkajs": "2.2.4",
"lru-cache": "11.5.1",
- "luxon": "3.7.2",
"mathjs": "12.3.2",
- "nanoid": "5.1.6",
"pino": "catalog:",
"pino-pretty": "catalog:",
"prisma-error-enum": "0.1.3",
@@ -66,10 +64,7 @@
"ramda": "0.29.1",
"sharp": "0.33.5",
"short-unique-id": "5.0.3",
- "slugify": "1.6.6",
"superjson": "2.2.2",
- "ua-parser-js": "2.0.6",
- "undici": "8.10.0",
"unzipper": "0.12.5",
"url-metadata": "5.4.1",
"uuid": "9.0.1",
@@ -79,7 +74,6 @@
"@clickhouse/client": "1.18.5",
"@openpanel/tsconfig": "workspace:*",
"@types/js-yaml": "4.0.9",
- "@types/luxon": "3.7.1",
"@types/qrcode": "1.5.6",
"@types/ramda": "0.31.0",
"@types/unzipper": "0.10.11",
diff --git a/packages/core/src/buffers/base-buffer.ts b/packages/core/src/buffers/base-buffer.ts
index d665801aa..5289ef48c 100644
--- a/packages/core/src/buffers/base-buffer.ts
+++ b/packages/core/src/buffers/base-buffer.ts
@@ -1,11 +1,11 @@
import { Readable } from 'node:stream';
import type { ClickHouseSettings } from '@clickhouse/client';
import { getRedisCache } from '@openpanel/redis';
+import { generateSecureId } from '@openpanel/shared';
import { type ChQueryInput, type ChScope, chQuery } from '../ch-query';
import type { CoreConfig } from '../config';
import type { Logger } from '../logger';
import type { ServiceDeps } from '../services';
-import { generateSecureId } from '../shared/id';
/**
* What a buffer needs from the boot scope. Buffers are built once by
diff --git a/packages/core/src/buffers/group-buffer.ts b/packages/core/src/buffers/group-buffer.ts
index 1ecc6f163..80e9a68c1 100644
--- a/packages/core/src/buffers/group-buffer.ts
+++ b/packages/core/src/buffers/group-buffer.ts
@@ -1,10 +1,9 @@
import { sql } from '@openpanel/db/src/clickhouse/sql';
import { getRedisCache, type Redis } from '@openpanel/redis';
+import { getSafeJson, toDots } from '@openpanel/shared';
import shallowEqual from 'fast-deep-equal';
import { formatClickhouseDate } from '../shared/ch-dates';
import { TABLE_NAMES } from '../shared/ch-tables';
-import { getSafeJson } from '../shared/json';
-import { toDots } from '../shared/object';
import { BaseBuffer, type BufferDeps } from './base-buffer';
type IGroupBufferEntry = {
diff --git a/packages/core/src/buffers/profile-backfill-buffer.ts b/packages/core/src/buffers/profile-backfill-buffer.ts
index 5a4e6c533..d51a30263 100644
--- a/packages/core/src/buffers/profile-backfill-buffer.ts
+++ b/packages/core/src/buffers/profile-backfill-buffer.ts
@@ -1,7 +1,7 @@
import { sql } from '@openpanel/db/src/clickhouse/sql';
import { getRedisCache, type Redis } from '@openpanel/redis';
+import { getSafeJson } from '@openpanel/shared';
import { getReplicatedTableName, TABLE_NAMES } from '../shared/ch-tables';
-import { getSafeJson } from '../shared/json';
import { BaseBuffer, type BufferDeps } from './base-buffer';
export interface ProfileBackfillEntry {
diff --git a/packages/core/src/buffers/profile-buffer.ts b/packages/core/src/buffers/profile-buffer.ts
index 812a65f7d..421e00372 100644
--- a/packages/core/src/buffers/profile-buffer.ts
+++ b/packages/core/src/buffers/profile-buffer.ts
@@ -1,10 +1,9 @@
import { sql } from '@openpanel/db/src/clickhouse/sql';
import { getRedisCache, type Redis } from '@openpanel/redis';
+import { deepMergeObjects, getSafeJson } from '@openpanel/shared';
import { omit, uniq } from 'ramda';
import type { IClickhouseProfile } from '../modules/profile/profile.service';
import { TABLE_NAMES } from '../shared/ch-tables';
-import { getSafeJson } from '../shared/json';
-import { deepMergeObjects } from '../shared/object';
import { BaseBuffer, type BufferDeps } from './base-buffer';
// Inlined to avoid a circular value-import with `profile.service.ts`
diff --git a/packages/core/src/buffers/session-buffer.ts b/packages/core/src/buffers/session-buffer.ts
index 6e2fe448b..ad20c616a 100644
--- a/packages/core/src/buffers/session-buffer.ts
+++ b/packages/core/src/buffers/session-buffer.ts
@@ -1,10 +1,9 @@
import { getRedisCache, type Redis } from '@openpanel/redis';
+import { DateTime, getSafeJson } from '@openpanel/shared';
import type { CoreConfig } from '../config';
import type { IServiceCreateEventPayload } from '../modules/event/event.service';
import type { IClickhouseSession } from '../modules/session/session.service';
import { TABLE_NAMES } from '../shared/ch-tables';
-import { DateTime } from '../shared/date';
-import { getSafeJson } from '../shared/json';
import { BaseBuffer, type BufferDeps } from './base-buffer';
// 30min of idle in event-time → session ends. Matches industry default.
diff --git a/packages/core/src/code-migrations/7-migrate-events-to-series.ts b/packages/core/src/code-migrations/7-migrate-events-to-series.ts
index bb15c31b9..cd2eb0774 100644
--- a/packages/core/src/code-migrations/7-migrate-events-to-series.ts
+++ b/packages/core/src/code-migrations/7-migrate-events-to-series.ts
@@ -1,10 +1,10 @@
import { db } from '@openpanel/db';
+import { shortId } from '@openpanel/shared';
import type {
IChartEvent,
IChartEventItem,
IChartFormula,
} from '../modules/report/report.constants';
-import { shortId } from '../shared/id';
import { printBoxMessage } from './helpers';
export async function up() {
diff --git a/packages/core/src/http/client-auth.ts b/packages/core/src/http/client-auth.ts
index 7453ee2e8..52f1d7fd2 100644
--- a/packages/core/src/http/client-auth.ts
+++ b/packages/core/src/http/client-auth.ts
@@ -19,9 +19,9 @@
// below. MCP is NOT here — it authenticates its own `token` form inside
// `modules/mcp/src/auth.ts`, exactly as V1's mcp router did.
+import { verifyPassword } from '@openpanel/shared/server';
import type { DbScope } from '../cacheable-per-deps';
import type { HttpCtx } from '../context';
-import { verifyPassword } from '../shared/crypto';
import { headerValue, type IngestHeaders } from '../shared/headers';
/** V1 refuses a client id that is not a UUID before it ever queries
diff --git a/packages/core/src/http/hooks.ts b/packages/core/src/http/hooks.ts
index cfd14167a..2b96ad4ab 100644
--- a/packages/core/src/http/hooks.ts
+++ b/packages/core/src/http/hooks.ts
@@ -12,11 +12,11 @@
// reads the request logger off `ctx` and would otherwise import this file's
// consumer.
+import { generateId } from '@openpanel/shared';
import { Elysia } from 'elysia';
import type { IpHeaderConfig } from '../config';
import { REQUEST_ID_HEADER, REQUEST_ID_LENGTH } from '../logger';
import { getClientIpFromHeaders } from '../shared/get-client-ip';
-import { generateId } from '../shared/id';
import { sanitizeRequestId } from '../shared/request-id';
/**
diff --git a/packages/core/src/http/query.ts b/packages/core/src/http/query.ts
index d0ef84ebf..f9e586512 100644
--- a/packages/core/src/http/query.ts
+++ b/packages/core/src/http/query.ts
@@ -14,7 +14,7 @@
// in place: reassigning the destructured binding would not reach the object
// the validator then reads.
-import { getSafeJson } from '../shared/json';
+import { getSafeJson } from '@openpanel/shared';
const NUMERIC = /^-?[0-9]+(\.[0-9]+)?$/i;
diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts
index 4cab7208f..85b9acd81 100644
--- a/packages/core/src/index.ts
+++ b/packages/core/src/index.ts
@@ -6,6 +6,39 @@
// once and mount the three route surfaces plus the tRPC router over it; a
// service, a client or a buffer is not reachable from here by design.
+// packages/db reads ClickHouse row JSON through this (P11: packages/json's
+// only definition already lived here; the barrel is how a package outside
+// core reaches it, since the exports map has no ./shared/* entry).
+export { generateId, generateSecureId, getChartPrevStartEndDate, getSafeJson, resolveDateRange, shortId } from '@openpanel/shared';
+export type {
+ SafeFetchOptions,
+ SafeFetchResult,
+ SafeFetchStreamResult,
+ UserAgentInfo,
+ UserAgentResult,
+} from '@openpanel/shared/server';
+// Dissolved from packages/common/server (M4-003) — a still-live V1 package
+// (db, queue, apps/worker) reaches these the same way apps/api and core
+// itself do, until its own module lands. mcp reaches it as an internal
+// relative import now that it lives inside core (M5-007).
+export {
+ assertPublicHostname,
+ assertPublicUrl,assertSafeUrl,
+ BlockedUrlError,
+ createHash,
+ createPinnedAgent,createPinnedLookup,
+ decrypt,
+ decryptCredential,
+ encrypt,
+ encryptCredential,
+ generateSalt,getDevice,
+ hashPassword,
+ isBlockedIp,
+ isEncrypted,parseUserAgent,
+ safeFetch,
+ safeFetchStream,
+ verifyPassword
+} from '@openpanel/shared/server';
// The seven buffers (moved from packages/db/src/buffers, M8-001). Only the
// FACTORY is on the barrel: they are boot singletons on `AppDeps`, built once
// by `main.ts`, never module singletons (ADR-007). V1's
@@ -129,8 +162,9 @@ export { createAssistantService } from './modules/assistant/assistant.service';
// Dissolved from @openpanel/auth (M4-007) — apps/api's OAuth callbacks call
// these directly; V1's now-deleted @openpanel/trpc auth/share/user/gsc
// routers did too, the same way they reached the other dissolved leaf
-// packages here. `hashPassword` is renamed on the way out: `./shared/crypto`
-// already owns that name for the (unrelated) scrypt hash client secrets use.
+// packages here. `hashPassword` is renamed on the way out:
+// `@openpanel/shared/server` already owns that name for the (unrelated) scrypt
+// hash client secrets use.
//
// The sign-up/sign-in/TOTP/reset-password/share/OAuth-callback half (M6-003)
// joined it here — V1's now-deleted packages/trpc auth router and
@@ -941,57 +975,14 @@ export {
getAlsSessionId,
runWithAlsSession,
} from './shared/als-session';
-// Dissolved from packages/common/server (M4-003) — a still-live V1 package
-// (db, queue, apps/worker) reaches these the same way apps/api and core
-// itself do, until its own module lands. mcp reaches it as an internal
-// relative import now that it lives inside core (M5-007).
-export {
- createHash,
- generateSalt,
- hashPassword,
- verifyPassword,
-} from './shared/crypto';
-export { getChartPrevStartEndDate, resolveDateRange } from './shared/date';
-export {
- decrypt,
- decryptCredential,
- encrypt,
- encryptCredential,
- isEncrypted,
-} from './shared/encryption';
export {
DEFAULT_IP_HEADER_ORDER,
getClientIpFromHeaders,
getTrustedIpFromHeaders,
TRUSTED_IP_HEADER_ORDER,
} from './shared/get-client-ip';
-export { generateId, generateSecureId, shortId } from './shared/id';
-// packages/db reads ClickHouse row JSON through this (P11: packages/json's
-// only definition already lived here; the barrel is how a package outside
-// core reaches it, since the exports map has no ./shared/* entry).
-export { getSafeJson } from './shared/json';
export { getReferrerWithQuery, parseReferrer } from './shared/parse-referrer';
-export type {
- UserAgentInfo,
- UserAgentResult,
-} from './shared/parser-user-agent';
-export { getDevice, parseUserAgent } from './shared/parser-user-agent';
export { generateDeviceId } from './shared/profileId';
-export type {
- SafeFetchOptions,
- SafeFetchResult,
- SafeFetchStreamResult,
-} from './shared/safe-fetch';
-export {
- assertPublicHostname,
- assertPublicUrl,
- BlockedUrlError,
- createPinnedAgent,
- isBlockedIp,
- safeFetch,
- safeFetchStream,
-} from './shared/safe-fetch';
// Below the transports since M15-007 (ADR-022 R22): `rpc/base.ts` needs the
// empty shape and may not deep-import a module to get it.
export { EMPTY_SESSION } from './shared/session';
-export { assertSafeUrl, createPinnedLookup } from './shared/ssrf';
diff --git a/packages/core/src/jobs/workers.ts b/packages/core/src/jobs/workers.ts
index 135ed46a8..10bbb13c6 100644
--- a/packages/core/src/jobs/workers.ts
+++ b/packages/core/src/jobs/workers.ts
@@ -1,3 +1,4 @@
+import { generateId } from '@openpanel/shared';
import {
type Job as BullJob,
Worker as BullWorker,
@@ -5,7 +6,6 @@ import {
} from 'bullmq';
import { type AppDeps, createCtx, extendCtx, type JobCtx } from '../context';
import { REQUEST_ID_LENGTH, REQUEST_ID_LOG_FIELD } from '../logger';
-import { generateId } from '../shared/id';
import { resolveJob } from './compat';
import type { QueueDefinition, QueueMap } from './define';
import { isEnvelope } from './envelope';
diff --git a/packages/core/src/modules/assistant/src/filter-command.ts b/packages/core/src/modules/assistant/src/filter-command.ts
index 2530269a0..729f7b9ca 100644
--- a/packages/core/src/modules/assistant/src/filter-command.ts
+++ b/packages/core/src/modules/assistant/src/filter-command.ts
@@ -13,10 +13,10 @@ import {
defineTool,
type ToolRunContext,
} from '@better-agent/core';
+import { resolveDateRange as resolveDateRangeCore } from '@openpanel/shared';
import { z } from 'zod';
import type { CoreConfig } from '../../../config';
import type { ServiceDeps } from '../../../services';
-import { resolveDateRange as resolveDateRangeCore } from '../../../shared/date';
import { listEventNamesCore } from '../../event/event.service';
import { getTrafficBreakdownCore } from '../../overview/overview.service';
import { getTopPagesCore } from '../../overview/pages.service';
diff --git a/packages/core/src/modules/assistant/src/tools/helpers.ts b/packages/core/src/modules/assistant/src/tools/helpers.ts
index 3baa24152..dfc97d39a 100644
--- a/packages/core/src/modules/assistant/src/tools/helpers.ts
+++ b/packages/core/src/modules/assistant/src/tools/helpers.ts
@@ -3,9 +3,9 @@ import {
defineTool,
type ToolRunContext,
} from '@better-agent/core';
+import { resolveDateRange as resolveDateRangeCore } from '@openpanel/shared';
import type { z } from 'zod';
import type { CoreConfig } from '../../../../config';
-import { resolveDateRange as resolveDateRangeCore } from '../../../../shared/date';
import type {
IChartEventFilter,
IChartRange,
diff --git a/packages/core/src/modules/auth/auth.service.ts b/packages/core/src/modules/auth/auth.service.ts
index e7610c913..86815b6cd 100644
--- a/packages/core/src/modules/auth/auth.service.ts
+++ b/packages/core/src/modules/auth/auth.service.ts
@@ -263,11 +263,11 @@ export function createAuthService(
// (`setCookie`, `cookies.get`, `logger`), so this file has no dependency on
// the rpc layer that calls it.
+import { generateSecureId } from '@openpanel/shared';
+import { decrypt, encrypt } from '@openpanel/shared/server';
import { sendEmail } from '../../clients/email';
import type { Logger } from '../../logger';
import { TRPCAccessError, TRPCNotFoundError } from '../../rpc/errors';
-import { decrypt, encrypt } from '../../shared/encryption';
-import { generateSecureId } from '../../shared/id';
import { connectUserToOrganization } from '../organization/organization.service';
import { getUserAccount } from '../user/user.service';
import {
diff --git a/packages/core/src/modules/chart/chart.service.ts b/packages/core/src/modules/chart/chart.service.ts
index edc79b384..8e24572ad 100644
--- a/packages/core/src/modules/chart/chart.service.ts
+++ b/packages/core/src/modules/chart/chart.service.ts
@@ -18,9 +18,9 @@
// ADR-013's `sql` tag, which ADR-007 keeps in `packages/db` by name: a
// compile-time template tag, no client and no request scope.
+import { getChartPrevStartEndDate } from '@openpanel/shared';
import { flatten, map, pipe, prop, sort, uniq } from 'ramda';
import type { ServiceDeps, Services } from '../../services';
-import { getChartPrevStartEndDate } from '../../shared/date';
import { getEventMetasCached } from '../event/event.service';
import { getSettingsForProject } from '../organization/organization.service';
import {
diff --git a/packages/core/src/modules/chart/funnel.service.ts b/packages/core/src/modules/chart/funnel.service.ts
index 5718ebe41..aa6055a73 100644
--- a/packages/core/src/modules/chart/funnel.service.ts
+++ b/packages/core/src/modules/chart/funnel.service.ts
@@ -3,9 +3,9 @@
// byte-equivalent to V1 in src/funnel.sql.proof.md; V1's funnel.service is a
// re-export shim onto this module (DELEGATE PATTERN).
+import { ifNaN } from '@openpanel/shared';
import { last, reverse } from 'ramda';
import type { ServiceDeps, Services } from '../../services';
-import { ifNaN } from '../../shared/math';
import { getSettingsForProject } from '../organization/organization.service';
import type {
IChartBreakdown,
diff --git a/packages/core/src/modules/chart/retention.service.test.ts b/packages/core/src/modules/chart/retention.service.test.ts
index 1dc6c0d07..bcab277fa 100644
--- a/packages/core/src/modules/chart/retention.service.test.ts
+++ b/packages/core/src/modules/chart/retention.service.test.ts
@@ -1,5 +1,6 @@
import { afterAll, beforeAll, describe, expect, it } from 'bun:test';
import { chQuery, TABLE_NAMES } from '@openpanel/db/src/clickhouse/client';
+import { round } from '@openpanel/shared';
import {
RETENTION_BLUEPRINT,
RETENTION_FIXTURE,
@@ -8,7 +9,6 @@ import {
} from '../../../../../test/retention-fixtures';
import { testServiceDeps } from '../../../test/service-deps';
import type { ServiceDeps } from '../../services';
-import { round } from '../../shared/math';
import {
getRetentionCohort,
getRetentionSeries,
diff --git a/packages/core/src/modules/chart/retention.service.ts b/packages/core/src/modules/chart/retention.service.ts
index 14c72053c..82ca6425a 100644
--- a/packages/core/src/modules/chart/retention.service.ts
+++ b/packages/core/src/modules/chart/retention.service.ts
@@ -7,10 +7,9 @@
// it powers the dashboard retention chart (via the tRPC `cohort` procedure) as
// well as the MCP / agent / REST retention endpoints.
+import { DateTime, round } from '@openpanel/shared';
import { range } from 'ramda';
import type { ServiceDeps, Services } from '../../services';
-import { DateTime } from '../../shared/date';
-import { round } from '../../shared/math';
import type { IChartEventFilter } from '../report/report.constants';
import {
type IRetentionCriteria,
diff --git a/packages/core/src/modules/chart/src/engine/compute.ts b/packages/core/src/modules/chart/src/engine/compute.ts
index cf5095cbe..800bfab24 100644
--- a/packages/core/src/modules/chart/src/engine/compute.ts
+++ b/packages/core/src/modules/chart/src/engine/compute.ts
@@ -1,4 +1,4 @@
-import { round } from '../../../../shared/math';
+import { round } from '@openpanel/shared';
import type { IChartFormula } from '../../../report/report.constants';
import { alphabetIds } from '../../../report/report.constants';
import { evaluateFormula } from './formula';
diff --git a/packages/core/src/modules/chart/src/engine/execute.ts b/packages/core/src/modules/chart/src/engine/execute.ts
index 7abd83832..f2a0110ef 100644
--- a/packages/core/src/modules/chart/src/engine/execute.ts
+++ b/packages/core/src/modules/chart/src/engine/execute.ts
@@ -1,5 +1,5 @@
+import { getChartPrevStartEndDate } from '@openpanel/shared';
import type { ServiceDeps } from '../../../../services';
-import { getChartPrevStartEndDate } from '../../../../shared/date';
import {
getOrganizationSubscriptionChartEndDate,
getSettingsForProject,
diff --git a/packages/core/src/modules/chart/src/engine/format.ts b/packages/core/src/modules/chart/src/engine/format.ts
index 3f5d909ca..0159dd466 100644
--- a/packages/core/src/modules/chart/src/engine/format.ts
+++ b/packages/core/src/modules/chart/src/engine/format.ts
@@ -1,5 +1,4 @@
-import { average, max, min, round, sum } from '../../../../shared/math';
-import { slug } from '../../../../shared/slug';
+import { average, max, min, round, slug, sum } from '@openpanel/shared';
import type { FinalChart } from '../../../report/report.constants';
import { alphabetIds } from '../../../report/report.constants';
import { getPreviousMetric } from '../../../report/src/previous-metric';
diff --git a/packages/core/src/modules/chart/src/engine/plan.ts b/packages/core/src/modules/chart/src/engine/plan.ts
index 490b2ede4..cc1f0418a 100644
--- a/packages/core/src/modules/chart/src/engine/plan.ts
+++ b/packages/core/src/modules/chart/src/engine/plan.ts
@@ -1,5 +1,5 @@
+import { slug } from '@openpanel/shared';
import type { ServiceDeps } from '../../../../services';
-import { slug } from '../../../../shared/slug';
import { getSettingsForProject } from '../../../organization/organization.service';
import type { IChartEventItem } from '../../../report/report.constants';
import { alphabetIds } from '../../../report/report.constants';
diff --git a/packages/core/src/modules/chart/src/filter-where.ts b/packages/core/src/modules/chart/src/filter-where.ts
index ec4087513..414704cae 100644
--- a/packages/core/src/modules/chart/src/filter-where.ts
+++ b/packages/core/src/modules/chart/src/filter-where.ts
@@ -10,7 +10,7 @@ import {
type SqlSlot,
sql,
} from '@openpanel/db/src/clickhouse/sql';
-import { stripLeadingAndTrailingSlashes } from '../../../shared/string';
+import { stripLeadingAndTrailingSlashes } from '@openpanel/shared';
import type { IChartEventFilter } from '../../report/report.constants';
import { getCohortIds } from '../../report/report.constants';
import {
diff --git a/packages/core/src/modules/event/event.service.ts b/packages/core/src/modules/event/event.service.ts
index 93c1e9934..c65824c68 100644
--- a/packages/core/src/modules/event/event.service.ts
+++ b/packages/core/src/modules/event/event.service.ts
@@ -28,12 +28,11 @@
import type { SqlFragment } from '@openpanel/db/src/clickhouse/sql';
import type { EventMeta, Prisma } from '@openpanel/db/src/prisma-client';
+import { DateTime, resolveDateRange, toDots } from '@openpanel/shared';
import { clone, mergeDeepRight, uniq } from 'ramda';
import { cacheablePerDeps } from '../../cacheable-per-deps';
import { chQuery } from '../../ch-query';
import type { ServiceDeps, Services } from '../../services';
-import { DateTime, resolveDateRange } from '../../shared/date';
-import { toDots } from '../../shared/object';
import { getEventFiltersWhereClause } from '../chart/src/filter-where';
import {
getProfileById,
diff --git a/packages/core/src/modules/export/export.routes.ts b/packages/core/src/modules/export/export.routes.ts
index d148cbb75..342a6d934 100644
--- a/packages/core/src/modules/export/export.routes.ts
+++ b/packages/core/src/modules/export/export.routes.ts
@@ -26,12 +26,12 @@
// what `defineRoutes`'s `const T` inference can carry, same reason every
// other module here writes its routes as one static `.get()`/`.post()` chain.
+import { DateTime } from '@openpanel/shared';
import { z } from 'zod';
import type { Ctx } from '../../context';
import type { ClientType } from '../../http/client-auth';
import { defineRoutes } from '../../http/define';
import { parseQueryStringTransform } from '../../http/query';
-import { DateTime } from '../../shared/date';
import { HttpError } from '../../shared/errors';
import type { GetEventListOptions } from '../event/event.service';
import {
diff --git a/packages/core/src/modules/export/export.service.ts b/packages/core/src/modules/export/export.service.ts
index d5ef42424..c004f7eb9 100644
--- a/packages/core/src/modules/export/export.service.ts
+++ b/packages/core/src/modules/export/export.service.ts
@@ -13,9 +13,9 @@
// this package's own barrel (`@openpanel/core`) mid-evaluation, which a
// relative import cannot do (docs/TECH_DEBT.md §4).
+import { resolveDateRange } from '@openpanel/shared';
import type { AuthenticatedClient } from '../../http/client-auth';
import type { ServiceDeps, Services } from '../../services';
-import { resolveDateRange } from '../../shared/date';
import { getSettingsForProject } from '../organization/organization.service';
import { resolveClientProjectId } from '../project/project.service';
import type { IChartRange } from '../report/report.constants';
diff --git a/packages/core/src/modules/group/group.service.ts b/packages/core/src/modules/group/group.service.ts
index 38851d2b5..c6be1d1e7 100644
--- a/packages/core/src/modules/group/group.service.ts
+++ b/packages/core/src/modules/group/group.service.ts
@@ -12,9 +12,9 @@
// through `deps.ch.insert`. The `loadChClient` lazy loader is gone
// (docs/TECH_DEBT.md §2, §4).
+import { toDots } from '@openpanel/shared';
import { chQuery } from '../../ch-query';
import type { ServiceDeps, Services } from '../../services';
-import { toDots } from '../../shared/object';
import { getProfiles, type IServiceProfile } from '../profile/profile.service';
import { formatClickhouseDate, toNullIfDefaultMinDate } from './src/dates';
import {
diff --git a/packages/core/src/modules/gsc/gsc.service.ts b/packages/core/src/modules/gsc/gsc.service.ts
index 4a80e3616..f368260a7 100644
--- a/packages/core/src/modules/gsc/gsc.service.ts
+++ b/packages/core/src/modules/gsc/gsc.service.ts
@@ -24,6 +24,7 @@
// tag: ADR-013 converts the analytics read path one query per P7 task, and
// this module's queries haven't been converted yet.
+import { decrypt, encrypt } from '@openpanel/shared/server';
import { cacheablePerDeps } from '../../cacheable-per-deps';
import { chQuery } from '../../ch-query';
import type { CoreConfig } from '../../config';
@@ -31,7 +32,6 @@ import type { Logger } from '../../logger';
import { TRPCNotFoundError } from '../../rpc/errors';
import type { ServiceDeps, Services } from '../../services';
import { TABLE_NAMES } from '../../shared/ch-tables';
-import { decrypt, encrypt } from '../../shared/encryption';
import { googleGscClient } from '../auth/auth.service';
const BACKFILL_MONTHS = 6;
diff --git a/packages/core/src/modules/health/health.routes.ts b/packages/core/src/modules/health/health.routes.ts
index 99ae3834b..418632e4d 100644
--- a/packages/core/src/modules/health/health.routes.ts
+++ b/packages/core/src/modules/health/health.routes.ts
@@ -13,10 +13,10 @@
// (apps/api/src/app.ts:400), hidden from the OpenAPI document like the probes,
// and self-hosters use it as a "is this thing on" check.
+import { tryCatch } from '@openpanel/shared';
import { z } from 'zod';
import { chQuery } from '../../ch-query';
import { defineRoutes } from '../../http/define';
-import { tryCatch } from '../../shared/try-catch';
import { currentReadiness } from './src/readiness';
// The first zod schema through the OpenAPI plugin (ADR-003): response schemas
diff --git a/packages/core/src/modules/import/import.service.ts b/packages/core/src/modules/import/import.service.ts
index 0c982aacc..df29873dc 100644
--- a/packages/core/src/modules/import/import.service.ts
+++ b/packages/core/src/modules/import/import.service.ts
@@ -20,6 +20,7 @@
import { createHash } from 'node:crypto';
import type { Prisma } from '@openpanel/db/src/prisma-client';
+import { toDots } from '@openpanel/shared';
import type { Logger } from '../../logger';
import type { ServiceDeps, Services } from '../../services';
import {
@@ -27,7 +28,6 @@ import {
formatClickhouseDate,
} from '../../shared/ch-dates';
import { getReplicatedTableName, TABLE_NAMES } from '../../shared/ch-tables';
-import { toDots } from '../../shared/object';
import type { IClickhouseEvent } from '../event/event.service';
import type { IClickhouseProfile } from '../profile/profile.service';
import type { IImportConfig } from './import.constants';
diff --git a/packages/core/src/modules/import/src/providers/amplitude.ts b/packages/core/src/modules/import/src/providers/amplitude.ts
index fc6ff14d2..61246d139 100644
--- a/packages/core/src/modules/import/src/providers/amplitude.ts
+++ b/packages/core/src/modules/import/src/providers/amplitude.ts
@@ -2,17 +2,16 @@ import { randomUUID } from 'node:crypto';
import { createInterface } from 'node:readline';
import { Readable } from 'node:stream';
import { createBrotliDecompress, createGunzip } from 'node:zlib';
+import { isSameDomain, parsePath, toDots } from '@openpanel/shared';
import unzipper from 'unzipper';
import { z } from 'zod';
import type { Logger } from '../../../../logger';
// core's own date helper, not @openpanel/db's — see umami.ts's header.
import { formatClickhouseDate } from '../../../../shared/ch-dates';
-import { toDots } from '../../../../shared/object';
import {
getReferrerWithQuery,
parseReferrer,
} from '../../../../shared/parse-referrer';
-import { isSameDomain, parsePath } from '../../../../shared/url';
import type { IClickhouseEvent } from '../../../event/event.service';
import type { IClickhouseProfile } from '../../../profile/profile.service';
import type { IAmplitudeImportConfig } from '../../import.constants';
diff --git a/packages/core/src/modules/import/src/providers/mixpanel.ts b/packages/core/src/modules/import/src/providers/mixpanel.ts
index da76ea051..9056186b2 100644
--- a/packages/core/src/modules/import/src/providers/mixpanel.ts
+++ b/packages/core/src/modules/import/src/providers/mixpanel.ts
@@ -1,18 +1,17 @@
import { randomUUID } from 'node:crypto';
+import { isSameDomain, parsePath, toDots } from '@openpanel/shared';
+import {
+ parseUserAgent,
+ type UserAgentInfo,
+} from '@openpanel/shared/server';
import { z } from 'zod';
import type { Logger } from '../../../../logger';
// core's own date helper, not @openpanel/db's — see umami.ts's header.
import { formatClickhouseDate } from '../../../../shared/ch-dates';
-import { toDots } from '../../../../shared/object';
import {
getReferrerWithQuery,
parseReferrer,
} from '../../../../shared/parse-referrer';
-import {
- parseUserAgent,
- type UserAgentInfo,
-} from '../../../../shared/parser-user-agent';
-import { isSameDomain, parsePath } from '../../../../shared/url';
import type { IClickhouseEvent } from '../../../event/event.service';
import type { IClickhouseProfile } from '../../../profile/profile.service';
import type { IMixpanelImportConfig } from '../../import.constants';
diff --git a/packages/core/src/modules/import/src/providers/umami.ts b/packages/core/src/modules/import/src/providers/umami.ts
index ac51364ad..872251c4c 100644
--- a/packages/core/src/modules/import/src/providers/umami.ts
+++ b/packages/core/src/modules/import/src/providers/umami.ts
@@ -2,6 +2,8 @@ import { randomUUID } from 'node:crypto';
import { Readable } from 'node:stream';
import { pipeline } from 'node:stream/promises';
import { createBrotliDecompress, createGunzip } from 'node:zlib';
+import { isSameDomain, parsePath, toDots } from '@openpanel/shared';
+import { safeFetchStream } from '@openpanel/shared/server';
import { parse } from 'csv-parse';
import { assocPath } from 'ramda';
import { z } from 'zod';
@@ -12,14 +14,11 @@ import type { Logger } from '../../../../logger';
// worker threads, AGENTS.md's eager-barrel-chain hazard) and is a value
// import of `@openpanel/db` from core. See shared/ch-dates.ts's header.
import { formatClickhouseDate } from '../../../../shared/ch-dates';
-import { toDots } from '../../../../shared/object';
import {
getReferrerWithQuery,
parseReferrer,
} from '../../../../shared/parse-referrer';
import { generateDeviceId } from '../../../../shared/profileId';
-import { safeFetchStream } from '../../../../shared/safe-fetch';
-import { isSameDomain, parsePath } from '../../../../shared/url';
import type { IClickhouseEvent } from '../../../event/event.service';
import type { IUmamiImportConfig } from '../../import.constants';
import { BaseImportProvider } from '../base-provider';
diff --git a/packages/core/src/modules/ingest/ingest.service.ts b/packages/core/src/modules/ingest/ingest.service.ts
index 81a39446b..1b5e6fa05 100644
--- a/packages/core/src/modules/ingest/ingest.service.ts
+++ b/packages/core/src/modules/ingest/ingest.service.ts
@@ -13,6 +13,8 @@
// workaround and no longer travels through `AppDeps` — it stays an argument
// only so a test can assert on what was produced without a broker.
+import { generateId } from '@openpanel/shared';
+import { parseUserAgent } from '@openpanel/shared/server';
import { assocPath, pathOr, pick } from 'ramda';
import { v4 as uuid } from 'uuid';
import type { Buffers } from '../../buffers/create-buffers';
@@ -27,8 +29,6 @@ import {
import type { Logger } from '../../logger';
import type { ServiceDeps, Services } from '../../services';
import { headerValue, type IngestHeaders } from '../../shared/headers';
-import { generateId } from '../../shared/id';
-import { parseUserAgent } from '../../shared/parser-user-agent';
import { generateDeviceId } from '../../shared/profileId';
import { createBotEvent } from '../event/event.service';
import { getOrganizationByProjectIdCached } from '../organization/organization.service';
diff --git a/packages/core/src/modules/ingest/src/client-auth.ts b/packages/core/src/modules/ingest/src/client-auth.ts
index 778472142..bb9145e5d 100644
--- a/packages/core/src/modules/ingest/src/client-auth.ts
+++ b/packages/core/src/modules/ingest/src/client-auth.ts
@@ -14,9 +14,9 @@
// ADR-011 leaves to Carl, not to a port.
import { getCache } from '@openpanel/redis';
+import { verifyPassword } from '@openpanel/shared/server';
import { path } from 'ramda';
import type { DbScope } from '../../../cacheable-per-deps';
-import { verifyPassword } from '../../../shared/crypto';
import { headerValue, type IngestHeaders } from '../../../shared/headers';
import {
getClientByIdCached,
diff --git a/packages/core/src/modules/ingest/src/incoming-event-handler.ts b/packages/core/src/modules/ingest/src/incoming-event-handler.ts
index 12362cc3a..14987b513 100644
--- a/packages/core/src/modules/ingest/src/incoming-event-handler.ts
+++ b/packages/core/src/modules/ingest/src/incoming-event-handler.ts
@@ -11,16 +11,15 @@
// the row the consumer writes (ADR-018 R1). The two lookups a work scope
// cannot supply arrive as `IncomingEventBindings` from the composition root.
+import { getTime, isSameDomain, parsePath } from '@openpanel/shared';
import { anyPass, isEmpty, isNil, mergeDeepRight, omit, reject } from 'ramda';
import type { SessionIngestResult } from '../../../buffers/session-buffer';
import type { Ctx } from '../../../context';
import type { Logger } from '../../../logger';
-import { getTime } from '../../../shared/date';
import {
getReferrerWithQuery,
parseReferrer,
} from '../../../shared/parse-referrer';
-import { isSameDomain, parsePath } from '../../../shared/url';
import {
createEvent,
type IServiceCreateEventPayload,
diff --git a/packages/core/src/modules/ingest/src/incoming-event.ts b/packages/core/src/modules/ingest/src/incoming-event.ts
index be476e2e5..559984903 100644
--- a/packages/core/src/modules/ingest/src/incoming-event.ts
+++ b/packages/core/src/modules/ingest/src/incoming-event.ts
@@ -6,8 +6,8 @@
// file, so both ./kafka.ts's producer and the consumer can name the payload
// without reaching into the ingest service.
+import type { parseUserAgent } from '@openpanel/shared/server';
import type { GeoLocation } from '../../../clients/geo';
-import type { parseUserAgent } from '../../../shared/parser-user-agent';
import type { ITrackPayload } from '../ingest.constants';
export interface IncomingEventPayload {
diff --git a/packages/core/src/modules/integration/src/export/batch-creator.ts b/packages/core/src/modules/integration/src/export/batch-creator.ts
index 3cd742cc7..b349a10e1 100644
--- a/packages/core/src/modules/integration/src/export/batch-creator.ts
+++ b/packages/core/src/modules/integration/src/export/batch-creator.ts
@@ -1,8 +1,8 @@
import { Readable } from 'node:stream';
import { pipeline } from 'node:stream/promises';
import { createGzip } from 'node:zlib';
+import { generateSecureId } from '@openpanel/shared';
import type { Logger } from '../../../../logger';
-import { generateSecureId } from '../../../../shared/id';
import type { IExportEvent } from './export-event';
/**
diff --git a/packages/core/src/modules/integration/src/flush-exports.ts b/packages/core/src/modules/integration/src/flush-exports.ts
index 7d5c6ee79..6c2175668 100644
--- a/packages/core/src/modules/integration/src/flush-exports.ts
+++ b/packages/core/src/modules/integration/src/flush-exports.ts
@@ -9,10 +9,10 @@
// value through ClickHouse's own `{name:Type}` params, and converting it to the
// `sql` tag would change the emitted statement. Kept byte-identical.
+import { DateTime } from '@openpanel/shared';
import { isProviderError } from '../../../clients/provider-error';
import type { CoreConfig } from '../../../config';
import type { Logger } from '../../../logger';
-import { DateTime } from '../../../shared/date';
import type { IClickhouseEvent } from '../../event/event.service';
import {
type IGCSExportConfig,
diff --git a/packages/core/src/modules/integration/src/object-store/gcs-adapter.test.ts b/packages/core/src/modules/integration/src/object-store/gcs-adapter.test.ts
index 894d37c7b..19a04e6e6 100644
--- a/packages/core/src/modules/integration/src/object-store/gcs-adapter.test.ts
+++ b/packages/core/src/modules/integration/src/object-store/gcs-adapter.test.ts
@@ -1,7 +1,7 @@
import { beforeAll, describe, expect, it } from 'bun:test';
import { gunzipSync, gzipSync } from 'node:zlib';
+import { encryptCredential } from '@openpanel/shared/server';
import { testCoreConfig } from '../../../../../test/config-fixture';
-import { encryptCredential } from '../../../../shared/encryption';
import { createGCSAdapter } from './gcs-adapter';
/**
diff --git a/packages/core/src/modules/integration/src/object-store/gcs-adapter.ts b/packages/core/src/modules/integration/src/object-store/gcs-adapter.ts
index f8b70c2c3..e2343cec0 100644
--- a/packages/core/src/modules/integration/src/object-store/gcs-adapter.ts
+++ b/packages/core/src/modules/integration/src/object-store/gcs-adapter.ts
@@ -1,11 +1,11 @@
// Ported from @openpanel/integrations (dissolved into core — M4-005).
import { Storage } from '@google-cloud/storage';
+import { decryptCredential } from '@openpanel/shared/server';
import {
callProvider,
ProviderError,
} from '../../../../clients/provider-error';
import type { CoreConfig } from '../../../../config';
-import { decryptCredential } from '../../../../shared/encryption';
import {
type IGCSExportConfig,
parseServiceAccountKey,
diff --git a/packages/core/src/modules/integration/src/object-store/s3-adapter.ts b/packages/core/src/modules/integration/src/object-store/s3-adapter.ts
index 9d1cbaf26..2f61290e0 100644
--- a/packages/core/src/modules/integration/src/object-store/s3-adapter.ts
+++ b/packages/core/src/modules/integration/src/object-store/s3-adapter.ts
@@ -9,14 +9,13 @@ import {
S3Client,
} from '@aws-sdk/client-s3';
import { AssumeRoleCommand, STSClient } from '@aws-sdk/client-sts';
+import { assertSafeUrl, createPinnedLookup, decryptCredential } from '@openpanel/shared/server';
import {
callProvider,
ProviderError,
providerErrorFrom,
} from '../../../../clients/provider-error';
import type { CoreConfig } from '../../../../config';
-import { decryptCredential } from '../../../../shared/encryption';
-import { assertSafeUrl, createPinnedLookup } from '../../../../shared/ssrf';
import type { IS3ExportConfig } from '../../integration.constants';
import type {
IObjectStoreAdapter,
diff --git a/packages/core/src/modules/integration/src/registry.ts b/packages/core/src/modules/integration/src/registry.ts
index 9730a4cb9..edd23a1c5 100644
--- a/packages/core/src/modules/integration/src/registry.ts
+++ b/packages/core/src/modules/integration/src/registry.ts
@@ -3,6 +3,10 @@
// own transports, so leaving it below them would have made every one of those
// edges point upward (ADR-022 R22/A2).
+import {
+ type EncryptionKey,
+ encryptCredential,
+} from '@openpanel/shared/server';
import {
sendDiscordNotification,
sendTestDiscordNotification,
@@ -13,10 +17,6 @@ import {
} from '../../../clients/integrations/fetcher';
import { ProviderError } from '../../../clients/provider-error';
import type { CoreConfig } from '../../../config';
-import {
- type EncryptionKey,
- encryptCredential,
-} from '../../../shared/encryption';
import {
execute as executeJavaScriptTemplate,
validate as validateJavaScriptTemplate,
diff --git a/packages/core/src/modules/integration/src/safe-fetcher.ts b/packages/core/src/modules/integration/src/safe-fetcher.ts
index 70a6c7f85..5e888924e 100644
--- a/packages/core/src/modules/integration/src/safe-fetcher.ts
+++ b/packages/core/src/modules/integration/src/safe-fetcher.ts
@@ -1,7 +1,7 @@
// Ported from @openpanel/integrations (dissolved into core — M4-005).
+import { safeFetch } from '@openpanel/shared/server';
import type { WebhookFetcher } from '../../../clients/integrations/fetcher';
-import { safeFetch } from '../../../shared/safe-fetch';
/**
* Server-side webhook transport. Resolves the host, refuses non-publicly
diff --git a/packages/core/src/modules/mcp/mcp.service.test.ts b/packages/core/src/modules/mcp/mcp.service.test.ts
index 739444e71..2604191de 100644
--- a/packages/core/src/modules/mcp/mcp.service.test.ts
+++ b/packages/core/src/modules/mcp/mcp.service.test.ts
@@ -38,16 +38,16 @@ mock.module('@openpanel/redis', () => ({
}));
const mockVerifyPassword = mock(async () => true);
-const actualCrypto = await import('../../shared/crypto');
+const actualCrypto = await import('@openpanel/shared/server');
const realCrypto = { ...actualCrypto };
-mock.module('../../shared/crypto', () => ({
+mock.module('@openpanel/shared/server', () => ({
...realCrypto,
verifyPassword: mockVerifyPassword,
}));
afterAll(() => {
mock.module('@openpanel/redis', () => realRedis);
- mock.module('../../shared/crypto', () => realCrypto);
+ mock.module('@openpanel/shared/server', () => realCrypto);
});
let handleStatelessMcpRequest: typeof import('./mcp.service').handleStatelessMcpRequest;
diff --git a/packages/core/src/modules/mcp/src/auth.test.ts b/packages/core/src/modules/mcp/src/auth.test.ts
index 46c66f4c0..65876b0cd 100644
--- a/packages/core/src/modules/mcp/src/auth.test.ts
+++ b/packages/core/src/modules/mcp/src/auth.test.ts
@@ -37,8 +37,8 @@ mock.module('@openpanel/redis', () => ({
getCache: mockGetCache,
}));
-const actualCrypto = await import('../../../shared/crypto');
-mock.module('../../../shared/crypto', () => ({
+const actualCrypto = await import('@openpanel/shared/server');
+mock.module('@openpanel/shared/server', () => ({
...actualCrypto,
verifyPassword: mockVerifyPassword,
}));
diff --git a/packages/core/src/modules/mcp/src/auth.ts b/packages/core/src/modules/mcp/src/auth.ts
index 08bff91eb..e23581023 100644
--- a/packages/core/src/modules/mcp/src/auth.ts
+++ b/packages/core/src/modules/mcp/src/auth.ts
@@ -1,7 +1,7 @@
import { createHash } from 'node:crypto';
import { getCache } from '@openpanel/redis';
+import { verifyPassword } from '@openpanel/shared/server';
import type { ServiceDeps, Services } from '../../../services';
-import { verifyPassword } from '../../../shared/crypto';
export interface McpAuthContext {
/**
diff --git a/packages/core/src/modules/misc/misc.service.ts b/packages/core/src/modules/misc/misc.service.ts
index fcb9b1c18..e780ffe82 100644
--- a/packages/core/src/modules/misc/misc.service.ts
+++ b/packages/core/src/modules/misc/misc.service.ts
@@ -24,6 +24,11 @@
import crypto from 'node:crypto';
import { getRedisCache } from '@openpanel/redis';
+import {
+ assertPublicUrl,
+ BlockedUrlError,
+ safeFetch,
+} from '@openpanel/shared/server';
import { chQuery } from '../../ch-query';
import { type GeoLocation, getGeoLocation } from '../../clients/geo';
import type { CoreConfig } from '../../config';
@@ -35,11 +40,6 @@ import {
DEFAULT_IP_HEADER_ORDER,
getClientIpFromHeaders,
} from '../../shared/get-client-ip';
-import {
- assertPublicUrl,
- BlockedUrlError,
- safeFetch,
-} from '../../shared/safe-fetch';
import {
ALLOWED_IMAGE_CONTENT_TYPES,
normalizeContentType,
diff --git a/packages/core/src/modules/notification/notification.service.ts b/packages/core/src/modules/notification/notification.service.ts
index c0811b606..c97d6d983 100644
--- a/packages/core/src/modules/notification/notification.service.ts
+++ b/packages/core/src/modules/notification/notification.service.ts
@@ -17,12 +17,12 @@
// would spawn a pino-pretty transport worker thread per test file).
import type { Integration, Prisma } from '@openpanel/db/src/prisma-client';
+import { stripLeadingAndTrailingSlashes } from '@openpanel/shared';
import { pathOr } from 'ramda';
import { cacheablePerDeps } from '../../cacheable-per-deps';
import { sendEmail } from '../../clients/email';
import { TRPCBadRequestError, TRPCForbiddenError } from '../../rpc/errors';
import type { ServiceDeps, Services } from '../../services';
-import { stripLeadingAndTrailingSlashes } from '../../shared/string';
import type {
IServiceCreateEventPayload,
IServiceEvent,
diff --git a/packages/core/src/modules/onboarding/onboarding.service.ts b/packages/core/src/modules/onboarding/onboarding.service.ts
index 3b45a8a6d..3e3ea1ced 100644
--- a/packages/core/src/modules/onboarding/onboarding.service.ts
+++ b/packages/core/src/modules/onboarding/onboarding.service.ts
@@ -12,10 +12,10 @@
import crypto from 'node:crypto';
import { getRecommendedPlan } from '@openpanel/payments';
+import { stripTrailingSlash } from '@openpanel/shared';
import { format } from 'date-fns';
import type { Logger } from '../../logger';
import type { ServiceDeps, Services } from '../../services';
-import { stripTrailingSlash } from '../../shared/string';
import { hashPassword } from '../auth/auth.service';
import {
runSequence,
diff --git a/packages/core/src/modules/organization/organization.service.ts b/packages/core/src/modules/organization/organization.service.ts
index 2dbbbc237..53e9251c7 100644
--- a/packages/core/src/modules/organization/organization.service.ts
+++ b/packages/core/src/modules/organization/organization.service.ts
@@ -39,6 +39,7 @@ import type {
ProjectAccess,
User,
} from '@openpanel/db/src/prisma-client';
+import { DateTime, generateSecureId } from '@openpanel/shared';
import { cacheablePerDeps } from '../../cacheable-per-deps';
import { chQuery } from '../../ch-query';
import { sendEmail } from '../../clients/email';
@@ -50,8 +51,6 @@ import {
} from '../../shared/access-lookups';
import { formatClickhouseDate } from '../../shared/ch-dates';
import { TABLE_NAMES } from '../../shared/ch-tables';
-import { DateTime } from '../../shared/date';
-import { generateSecureId } from '../../shared/id';
export type IServiceOrganization = Awaited<
ReturnType<typeof getOrganizationById>
diff --git a/packages/core/src/modules/overview/overview.rpc.ts b/packages/core/src/modules/overview/overview.rpc.ts
index ff616b953..20356bf4e 100644
--- a/packages/core/src/modules/overview/overview.rpc.ts
+++ b/packages/core/src/modules/overview/overview.rpc.ts
@@ -12,6 +12,7 @@
// router; they moved to `services.overview.getLiveData` (src/overview.sql.ts)
// so every query this module runs goes through the same `sql` tag (M7-005).
+import { getChartPrevStartEndDate } from '@openpanel/shared';
import { format } from 'date-fns';
import { z } from 'zod';
import {
@@ -22,7 +23,6 @@ import {
} from '../../rpc/base';
import { TRPCForbiddenError } from '../../rpc/errors';
import type { ServiceDeps } from '../../services';
-import { getChartPrevStartEndDate } from '../../shared/date';
import { pageContextSchema } from '../assistant/assistant.constants';
import { getConversionEventNames } from '../event/event.service';
import { getReferrerSpikes } from '../insight/insight.service';
diff --git a/packages/core/src/modules/overview/overview.service.ts b/packages/core/src/modules/overview/overview.service.ts
index b01740c8b..b69e84645 100644
--- a/packages/core/src/modules/overview/overview.service.ts
+++ b/packages/core/src/modules/overview/overview.service.ts
@@ -11,9 +11,9 @@
// is what puts the request's id on the query's log line (ADR-018 R1).
import type { SqlFragment } from '@openpanel/db/src/clickhouse/sql';
+import { average, sum } from '@openpanel/shared';
import { z } from 'zod';
import type { ServiceDeps, Services } from '../../services';
-import { average, sum } from '../../shared/math';
import { convertClickhouseDateToJs } from '../chart/src/dates';
import {
getEventFiltersWhereClause,
diff --git a/packages/core/src/modules/profile/profile.routes.ts b/packages/core/src/modules/profile/profile.routes.ts
index 9b9941567..7001e9ad2 100644
--- a/packages/core/src/modules/profile/profile.routes.ts
+++ b/packages/core/src/modules/profile/profile.routes.ts
@@ -18,9 +18,9 @@
// /event and /tools have no request schemas today, and adding them would be a
// behaviour change"), so the bodies are typed but not shape-validated.
+import { parseUserAgent } from '@openpanel/shared/server';
import { getGeoLocation } from '../../clients/geo';
import { defineRoutes } from '../../http/define';
-import { parseUserAgent } from '../../shared/parser-user-agent';
import { validateIngestRequest } from '../ingest/src/client-auth';
import {
type AdjustProfilePropertyResult,
diff --git a/packages/core/src/modules/profile/profile.service.ts b/packages/core/src/modules/profile/profile.service.ts
index 70c969bd3..c4dd7572d 100644
--- a/packages/core/src/modules/profile/profile.service.ts
+++ b/packages/core/src/modules/profile/profile.service.ts
@@ -16,11 +16,11 @@
// loaders are gone (docs/TECH_DEBT.md §2, §4); `loadFilterCompiler` stays and
// reaches a core sibling, not @openpanel/db.
+import { strip, toObject } from '@openpanel/shared';
import { assocPath, flatten, map, pathOr, pipe, prop, sort, uniq } from 'ramda';
import { cacheablePerDeps } from '../../cacheable-per-deps';
import { chQuery } from '../../ch-query';
import type { ServiceDeps, Services } from '../../services';
-import { strip, toObject } from '../../shared/object';
import type { IClickhouseEvent } from '../event/event.service';
import type { IChartEventFilter } from '../report/report.constants';
import type { IClickhouseSession } from '../session/session.service';
diff --git a/packages/core/src/modules/project/project.service.ts b/packages/core/src/modules/project/project.service.ts
index 9f6ee27f6..d0f7b8afa 100644
--- a/packages/core/src/modules/project/project.service.ts
+++ b/packages/core/src/modules/project/project.service.ts
@@ -27,13 +27,13 @@ import type {
Project,
ProjectType,
} from '@openpanel/db/src/prisma-client';
+import { stripTrailingSlash } from '@openpanel/shared';
import { cacheablePerDb, type DbScope } from '../../cacheable-per-deps';
import { chQuery } from '../../ch-query';
import { TRPCBadRequestError } from '../../rpc/errors';
import type { ServiceDeps, Services } from '../../services';
import { convertClickhouseDateToJs } from '../../shared/ch-dates';
import { TABLE_NAMES } from '../../shared/ch-tables';
-import { stripTrailingSlash } from '../../shared/string';
import { getId } from '../../slug-id';
import { hashPassword } from '../auth/auth.service';
import { getClientByIdCached } from '../client/client.service';
diff --git a/packages/core/src/modules/realtime/realtime.routes.test.ts b/packages/core/src/modules/realtime/realtime.routes.test.ts
index 66ff605c4..07af282e5 100644
--- a/packages/core/src/modules/realtime/realtime.routes.test.ts
+++ b/packages/core/src/modules/realtime/realtime.routes.test.ts
@@ -25,9 +25,9 @@
// module's own (docs/TECH_DEBT.md's no-lazy-loaders ruling).
import { afterAll, afterEach, beforeEach, expect, mock, test } from 'bun:test';
+import { getSuperJson } from '@openpanel/shared';
import { stubAppDeps } from '../../../test/http-fixtures';
import * as actualAccessLookups from '../../shared/access-lookups';
-import { getSuperJson } from '../../shared/json';
import { realtimeRoutes } from './realtime.routes';
import * as actualService from './realtime.service';
diff --git a/packages/core/src/modules/realtime/realtime.routes.ts b/packages/core/src/modules/realtime/realtime.routes.ts
index c7adb3d98..34a6f24a8 100644
--- a/packages/core/src/modules/realtime/realtime.routes.ts
+++ b/packages/core/src/modules/realtime/realtime.routes.ts
@@ -25,9 +25,9 @@
// close every connection immediately after upgrade. That is the same gap
// http/auth.test.ts already documents for every other session-macro route.
+import { setSuperJson } from '@openpanel/shared';
import { z } from 'zod';
import { defineRoutes } from '../../http/define';
-import { setSuperJson } from '../../shared/json';
import {
getActiveVisitorCount,
subscribeToOrganizationSubscriptionUpdates,
diff --git a/packages/core/src/modules/report/src/chart-dates.ts b/packages/core/src/modules/report/src/chart-dates.ts
index 9b01557bb..2aa3f634c 100644
--- a/packages/core/src/modules/report/src/chart-dates.ts
+++ b/packages/core/src/modules/report/src/chart-dates.ts
@@ -4,7 +4,7 @@
// bottom layer could not hold them. The generic Date/Luxon math they build on
// stays in `shared/date.ts`.
-import { DateTime } from '../../../shared/date';
+import { DateTime } from '@openpanel/shared';
import type { IChartRange, IReportInput } from '../report.constants';
export function getDatesFromRange(range: IChartRange, timezone: string) {
diff --git a/packages/core/src/modules/report/src/previous-metric.ts b/packages/core/src/modules/report/src/previous-metric.ts
index 7913a8236..7e18fba14 100644
--- a/packages/core/src/modules/report/src/previous-metric.ts
+++ b/packages/core/src/modules/report/src/previous-metric.ts
@@ -4,8 +4,8 @@
// the layer below every transport. The generic aggregates it is built on stay
// in `shared/math.ts`.
+import { round } from '@openpanel/shared';
import { isNil } from 'ramda';
-import { round } from '../../../shared/math';
import type { PreviousValue } from '../report.constants';
const PERCENT = 100;
diff --git a/packages/core/src/modules/salt/salt.service.ts b/packages/core/src/modules/salt/salt.service.ts
index 89227cd5c..38f5cf2ba 100644
--- a/packages/core/src/modules/salt/salt.service.ts
+++ b/packages/core/src/modules/salt/salt.service.ts
@@ -14,9 +14,9 @@
// passes the scope it holds instead of reading a boot-scoped singleton through
// the deleted compat seam. `generateNewSalt` clears the same instance.
+import { generateSalt } from '@openpanel/shared/server';
import { cacheablePerDb } from '../../cacheable-per-deps';
import type { ServiceDeps, Services } from '../../services';
-import { generateSalt } from '../../shared/crypto';
const SALT_CACHE_NAME = 'op:salt';
const SALT_CACHE_TTL_SECONDS = 60 * 5;
diff --git a/packages/core/src/modules/session/session.service.ts b/packages/core/src/modules/session/session.service.ts
index 8ccc6884a..f61e0edf7 100644
--- a/packages/core/src/modules/session/session.service.ts
+++ b/packages/core/src/modules/session/session.service.ts
@@ -15,12 +15,13 @@
// (packages/redis/cachable.ts), so the caller's deps travel beside the key
// rather than inside it, and the Redis key stays byte-identical. The remaining
// `load*` functions are intra-package lazy imports, kept lazy for a cycle, not
-// for a client.
+// for a client — the date helpers left that set in M15-010, because
+// @openpanel/shared sits below this package and cannot cycle back into it.
+import { getSafeJson, resolveDateRange } from '@openpanel/shared';
import { cacheablePerDeps } from '../../cacheable-per-deps';
import { chQuery } from '../../ch-query';
import type { ServiceDeps, Services } from '../../services';
-import { getSafeJson } from '../../shared/json';
import type { IServiceProfile } from '../profile/profile.service';
import type { IChartEventFilter } from '../report/report.constants';
import { convertClickhouseDateToJs } from './src/dates';
@@ -51,10 +52,6 @@ function loadFilterCompiler() {
return import('../chart/src/table-filter-where');
}
-function loadDateService() {
- return import('../../shared/date');
-}
-
export interface IClickhouseSession {
id: string;
profile_id: string;
@@ -461,7 +458,6 @@ export async function querySessionsCore(
deps: ServiceDeps,
input: QuerySessionsInput
): Promise<IClickhouseSession[]> {
- const { resolveDateRange } = await loadDateService();
const { startDate, endDate } = resolveDateRange(
input.startDate,
input.endDate
diff --git a/packages/core/src/modules/tools/src/site-checker.ts b/packages/core/src/modules/tools/src/site-checker.ts
index 40ae0a7ed..d7af29dba 100644
--- a/packages/core/src/modules/tools/src/site-checker.ts
+++ b/packages/core/src/modules/tools/src/site-checker.ts
@@ -4,18 +4,18 @@
import * as dns from 'node:dns/promises';
import * as net from 'node:net';
import * as tls from 'node:tls';
-import * as cheerio from 'cheerio';
-import { getGeoLocation } from '../../../clients/geo';
-import type { CoreConfig } from '../../../config';
-import type { Logger } from '../../../logger';
-import { getClientIpFromHeaders } from '../../../shared/get-client-ip';
import {
assertPublicHostname,
assertPublicUrl,
BlockedUrlError,
isBlockedIp,
safeFetch,
-} from '../../../shared/safe-fetch';
+} from '@openpanel/shared/server';
+import * as cheerio from 'cheerio';
+import { getGeoLocation } from '../../../clients/geo';
+import type { CoreConfig } from '../../../config';
+import type { Logger } from '../../../logger';
+import { getClientIpFromHeaders } from '../../../shared/get-client-ip';
import { checkRateLimit } from './rate-limit';
const TIMEOUT_MS = 10_000;
diff --git a/packages/core/src/shared/encryption.test.ts b/packages/core/src/shared/encryption.test.ts
index c471d6e64..d56345fbd 100644
--- a/packages/core/src/shared/encryption.test.ts
+++ b/packages/core/src/shared/encryption.test.ts
@@ -1,3 +1,8 @@
+// Subject moved to @openpanel/shared (M15-010, ADR-022 R21); the suite did
+// not follow it. Nothing runs a `test` script in packages/shared yet — the
+// root `test` script names its four workspaces explicitly and root
+// package.json was outside M15-010's scope — so moving this file would take
+// it out of every gate. Move it when that line can gain the filter.
import { describe, expect, it } from 'bun:test';
import {
decrypt,
@@ -5,7 +10,7 @@ import {
encrypt,
encryptCredential,
isEncrypted,
-} from './encryption';
+} from '@openpanel/shared/server';
// Deterministic key for the round-trips — the value the config loader would
// hand down as `config.encryptionKey`.
diff --git a/packages/core/src/shared/id.test.ts b/packages/core/src/shared/id.test.ts
index 1d37c3f88..0af5f2b93 100644
--- a/packages/core/src/shared/id.test.ts
+++ b/packages/core/src/shared/id.test.ts
@@ -1,5 +1,10 @@
+// Subject moved to @openpanel/shared (M15-010, ADR-022 R21); the suite did
+// not follow it. Nothing runs a `test` script in packages/shared yet — the
+// root `test` script names its four workspaces explicitly and root
+// package.json was outside M15-010's scope — so moving this file would take
+// it out of every gate. Move it when that line can gain the filter.
import { describe, expect, test } from 'bun:test';
-import { generateId, shortId } from './id';
+import { generateId, shortId } from '@openpanel/shared';
describe('shortId', () => {
test('is 4 characters', () => {
diff --git a/packages/core/src/shared/json.test.ts b/packages/core/src/shared/json.test.ts
index 71b401f6e..2dda50cd5 100644
--- a/packages/core/src/shared/json.test.ts
+++ b/packages/core/src/shared/json.test.ts
@@ -1,5 +1,10 @@
+// Subject moved to @openpanel/shared (M15-010, ADR-022 R21); the suite did
+// not follow it. Nothing runs a `test` script in packages/shared yet — the
+// root `test` script names its four workspaces explicitly and root
+// package.json was outside M15-010's scope — so moving this file would take
+// it out of every gate. Move it when that line can gain the filter.
import { describe, expect, test } from 'bun:test';
-import { getSafeJson, getSuperJson, setSuperJson } from './json';
+import { getSafeJson, getSuperJson, setSuperJson } from '@openpanel/shared';
describe('getSafeJson', () => {
test('parses valid JSON', () => {
diff --git a/packages/core/src/shared/json.ts b/packages/core/src/shared/json.ts
index 711452699..2b20787eb 100644
--- a/packages/core/src/shared/json.ts
+++ b/packages/core/src/shared/json.ts
@@ -1,25 +1,11 @@
-// Ported from packages/json, same semantics: getSafeJson never throws, and
-// getSuperJson only hands off to superjson's parser when the payload looks
-// like superjson's own `{ json, meta }` envelope — a plain JSON payload
-// round-trips through JSON.parse instead.
-import superjson from 'superjson';
-
-export function getSafeJson<T>(str: string): T | null {
- try {
- return JSON.parse(str);
- } catch {
- return null;
- }
-}
-
-export function getSuperJson<T>(str: string): T | null {
- const json = getSafeJson<T>(str);
- if (typeof json === 'object' && json !== null && 'json' in json) {
- return superjson.parse<T>(str);
- }
- return json;
-}
-
-export function setSuperJson(value: unknown): string {
- return superjson.stringify(value);
-}
+// A re-export seam, not an implementation: the JSON helpers moved to
+// @openpanel/shared in M15-010 (ADR-022 R21), and every caller inside core
+// imports them from there.
+//
+// This file survives for ONE importer: packages/db/src/clickhouse/client.ts
+// reaches `getSafeJson` by relative path across the package boundary
+// (`../../../core/src/shared/json`), because core depends on @openpanel/db and
+// importing the core barrel there would invert that edge. That import is now
+// pointed at the wrong package — the fix is one line in packages/db, which was
+// outside M15-010's scope. Delete this file with it.
+export { getSafeJson, getSuperJson, setSuperJson } from '@openpanel/shared';
diff --git a/packages/core/src/shared/object.test.ts b/packages/core/src/shared/object.test.ts
index dde579a02..87853dcd4 100644
--- a/packages/core/src/shared/object.test.ts
+++ b/packages/core/src/shared/object.test.ts
@@ -1,5 +1,10 @@
+// Subject moved to @openpanel/shared (M15-010, ADR-022 R21); the suite did
+// not follow it. Nothing runs a `test` script in packages/shared yet — the
+// root `test` script names its four workspaces explicitly and root
+// package.json was outside M15-010's scope — so moving this file would take
+// it out of every gate. Move it when that line can gain the filter.
import { describe, expect, it } from 'bun:test';
-import { toDots } from './object';
+import { toDots } from '@openpanel/shared';
describe('toDots', () => {
it('should convert an object to a dot object', () => {
diff --git a/packages/core/src/shared/parse-referrer.ts b/packages/core/src/shared/parse-referrer.ts
index 87cd6f2b2..b5b11f125 100644
--- a/packages/core/src/shared/parse-referrer.ts
+++ b/packages/core/src/shared/parse-referrer.ts
@@ -1,5 +1,5 @@
+import { stripTrailingSlash } from '@openpanel/shared';
import referrers from './referrers';
-import { stripTrailingSlash } from './string';
function getHostname(url: string | undefined) {
if (!url) {
diff --git a/packages/core/src/shared/parser-user-agent.test.ts b/packages/core/src/shared/parser-user-agent.test.ts
index a5ab6f398..e4bf3c2ce 100644
--- a/packages/core/src/shared/parser-user-agent.test.ts
+++ b/packages/core/src/shared/parser-user-agent.test.ts
@@ -1,5 +1,10 @@
+// Subject moved to @openpanel/shared (M15-010, ADR-022 R21); the suite did
+// not follow it. Nothing runs a `test` script in packages/shared yet — the
+// root `test` script names its four workspaces explicitly and root
+// package.json was outside M15-010's scope — so moving this file would take
+// it out of every gate. Move it when that line can gain the filter.
import { describe, expect, it } from 'bun:test';
-import { getDevice, parseUserAgent } from './parser-user-agent';
+import { getDevice, parseUserAgent } from '@openpanel/shared/server';
describe('parseUserAgent', () => {
it('should return server UA for null/undefined input', () => {
diff --git a/packages/core/src/shared/profileId.ts b/packages/core/src/shared/profileId.ts
index 3f2e92dcc..49ada8c7a 100644
--- a/packages/core/src/shared/profileId.ts
+++ b/packages/core/src/shared/profileId.ts
@@ -1,4 +1,4 @@
-import { createHash } from './crypto';
+import { createHash } from '@openpanel/shared/server';
interface GenerateDeviceIdOptions {
salt: string;
diff --git a/packages/core/src/shared/request-id.ts b/packages/core/src/shared/request-id.ts
index 444dc3215..4e0e0ab1a 100644
--- a/packages/core/src/shared/request-id.ts
+++ b/packages/core/src/shared/request-id.ts
@@ -4,8 +4,8 @@
// which reads the id the producer stamped into the envelope — so the rule that
// decides what is safe to bind to a logger lives here rather than in either.
+import { generateId } from '@openpanel/shared';
import { REQUEST_ID_LENGTH } from '../logger';
-import { generateId } from './id';
const DISALLOWED_REQUEST_ID_CHARS = /[^A-Za-z0-9_-]/g;
const REQUEST_ID_MAX_LENGTH = 64;
diff --git a/packages/core/src/shared/safe-fetch.test.ts b/packages/core/src/shared/safe-fetch.test.ts
index 2ca97cf65..c4c2cd187 100644
--- a/packages/core/src/shared/safe-fetch.test.ts
+++ b/packages/core/src/shared/safe-fetch.test.ts
@@ -1,3 +1,8 @@
+// Subject moved to @openpanel/shared (M15-010, ADR-022 R21); the suite did
+// not follow it. Nothing runs a `test` script in packages/shared yet — the
+// root `test` script names its four workspaces explicitly and root
+// package.json was outside M15-010's scope — so moving this file would take
+// it out of every gate. Move it when that line can gain the filter.
import { afterAll, beforeAll, describe, expect, it } from 'bun:test';
import http from 'node:http';
import type { AddressInfo } from 'node:net';
@@ -6,7 +11,7 @@ import {
isBlockedIp,
safeFetch,
safeFetchStream,
-} from './safe-fetch';
+} from '@openpanel/shared/server';
describe('isBlockedIp', () => {
it('blocks the ranges an SSRF payload aims at', () => {
diff --git a/packages/core/src/shared/slug.test.ts b/packages/core/src/shared/slug.test.ts
index 64d369a2f..cdda4e724 100644
--- a/packages/core/src/shared/slug.test.ts
+++ b/packages/core/src/shared/slug.test.ts
@@ -1,5 +1,10 @@
+// Subject moved to @openpanel/shared (M15-010, ADR-022 R21); the suite did
+// not follow it. Nothing runs a `test` script in packages/shared yet — the
+// root `test` script names its four workspaces explicitly and root
+// package.json was outside M15-010's scope — so moving this file would take
+// it out of every gate. Move it when that line can gain the filter.
import { describe, expect, it } from 'bun:test';
-import { slug } from './slug';
+import { slug } from '@openpanel/shared';
describe('slug', () => {
it('should remove pipes from string', () => {
diff --git a/packages/core/src/shared/ssrf.test.ts b/packages/core/src/shared/ssrf.test.ts
index aaf0161e9..fd933f47b 100644
--- a/packages/core/src/shared/ssrf.test.ts
+++ b/packages/core/src/shared/ssrf.test.ts
@@ -1,5 +1,10 @@
+// Subject moved to @openpanel/shared (M15-010, ADR-022 R21); the suite did
+// not follow it. Nothing runs a `test` script in packages/shared yet — the
+// root `test` script names its four workspaces explicitly and root
+// package.json was outside M15-010's scope — so moving this file would take
+// it out of every gate. Move it when that line can gain the filter.
import { describe, expect, it, mock } from 'bun:test';
-import { assertSafeUrl, createPinnedLookup } from './ssrf';
+import { assertSafeUrl, createPinnedLookup } from '@openpanel/shared/server';
// SELF_HOSTED arrives as `config.selfHosted`; the loader is what decides that
// only `true`/`1` mean self-hosted (`apps/api/src/config/env.test.ts`).
diff --git a/packages/core/src/shared/try-catch.test.ts b/packages/core/src/shared/try-catch.test.ts
index 13a47d54a..2aae51018 100644
--- a/packages/core/src/shared/try-catch.test.ts
+++ b/packages/core/src/shared/try-catch.test.ts
@@ -1,5 +1,10 @@
+// Subject moved to @openpanel/shared (M15-010, ADR-022 R21); the suite did
+// not follow it. Nothing runs a `test` script in packages/shared yet — the
+// root `test` script names its four workspaces explicitly and root
+// package.json was outside M15-010's scope — so moving this file would take
+// it out of every gate. Move it when that line can gain the filter.
import { describe, expect, test } from 'bun:test';
-import { tryCatch } from './try-catch';
+import { tryCatch } from '@openpanel/shared';
describe('tryCatch', () => {
test('wraps a resolved promise', async () => {
diff --git a/packages/core/src/slug-id.ts b/packages/core/src/slug-id.ts
index eb49449cd..bed787fff 100644
--- a/packages/core/src/slug-id.ts
+++ b/packages/core/src/slug-id.ts
@@ -10,8 +10,8 @@
// `@modelcontextprotocol/sdk` signature and only ever hold the db the route
// closed over.
+import { slug } from '@openpanel/shared';
import type { ServiceDeps } from './services';
-import { slug } from './shared/slug';
export async function getId(
deps: Pick<ServiceDeps, 'db'>,
diff --git a/packages/redis/json.ts b/packages/redis/json.ts
deleted file mode 100644
index e2355b9df..000000000
--- a/packages/redis/json.ts
+++ /dev/null
@@ -1,26 +0,0 @@
-// Local copy of @openpanel/core's shared/json.ts (deleted with @openpanel/json
-// in M11-009). packages/redis cannot import @openpanel/core at runtime —
-// @openpanel/core depends on @openpanel/redis, so a runtime import here would
-// invert that edge. Keep in sync with packages/core/src/shared/json.ts if the
-// semantics ever change.
-import superjson from 'superjson';
-
-export function getSafeJson<T>(str: string): T | null {
- try {
- return JSON.parse(str);
- } catch {
- return null;
- }
-}
-
-export function getSuperJson<T>(str: string): T | null {
- const json = getSafeJson<T>(str);
- if (typeof json === 'object' && json !== null && 'json' in json) {
- return superjson.parse<T>(str);
- }
- return json;
-}
-
-export function setSuperJson(value: unknown): string {
- return superjson.stringify(value);
-}
diff --git a/packages/redis/package.json b/packages/redis/package.json
index 737d1e6c9..f019f818a 100644
--- a/packages/redis/package.json
+++ b/packages/redis/package.json
@@ -7,9 +7,9 @@
"typecheck": "tsc --noEmit"
},
"dependencies": {
+ "@openpanel/shared": "workspace:*",
"ioredis": "5.8.2",
- "lru-cache": "11.5.1",
- "superjson": "2.2.2"
+ "lru-cache": "11.5.1"
},
"devDependencies": {
"@openpanel/core": "workspace:*",
diff --git a/packages/redis/publisher.ts b/packages/redis/publisher.ts
index 4e58b5eef..2c2c6ccb9 100644
--- a/packages/redis/publisher.ts
+++ b/packages/redis/publisher.ts
@@ -2,7 +2,7 @@ import { type Redis, getRedisPub, getRedisSub } from './redis';
import type { IServiceEvent } from '@openpanel/core';
import type { Notification, Prisma } from '@openpanel/db';
-import { getSuperJson, setSuperJson } from './json';
+import { getSuperJson, setSuperJson } from '@openpanel/shared';
export type IPublishChannels = {
organization: {
diff --git a/packages/redis/redis.ts b/packages/redis/redis.ts
index af2533688..1655db6d0 100644
--- a/packages/redis/redis.ts
+++ b/packages/redis/redis.ts
@@ -1,4 +1,4 @@
-import { getSuperJson, setSuperJson } from './json';
+import { getSuperJson, setSuperJson } from '@openpanel/shared';
import type { RedisOptions } from 'ioredis';
import { Redis } from 'ioredis';
diff --git a/packages/shared/package.json b/packages/shared/package.json
new file mode 100644
index 000000000..9927a510e
--- /dev/null
+++ b/packages/shared/package.json
@@ -0,0 +1,33 @@
+{
+ "name": "@openpanel/shared",
+ "version": "0.0.1",
+ "type": "module",
+ "private": true,
+ "sideEffects": false,
+ "exports": {
+ ".": "./src/index.ts",
+ "./server": "./src/server/index.ts"
+ },
+ "scripts": {
+ "typecheck": "tsc --noEmit"
+ },
+ "dependencies": {
+ "ipaddr.js": "2.5.0",
+ "lru-cache": "11.5.1",
+ "luxon": "3.7.2",
+ "mathjs": "12.3.2",
+ "nanoid": "5.1.6",
+ "ramda": "0.29.1",
+ "slugify": "1.6.6",
+ "superjson": "2.2.2",
+ "ua-parser-js": "2.0.6",
+ "undici": "8.10.0"
+ },
+ "devDependencies": {
+ "@openpanel/tsconfig": "workspace:*",
+ "@types/luxon": "3.7.1",
+ "@types/node": "catalog:",
+ "@types/ramda": "0.31.0",
+ "typescript": "catalog:"
+ }
+}
diff --git a/packages/core/src/shared/date.ts b/packages/shared/src/date.ts
similarity index 90%
rename from packages/core/src/shared/date.ts
rename to packages/shared/src/date.ts
index 0f3f0a3d3..70a34cb6f 100644
--- a/packages/core/src/shared/date.ts
+++ b/packages/shared/src/date.ts
@@ -8,8 +8,10 @@
//
// M15-009: `getDatesFromRange` and `getChartStartEndDate` left with the report
// vocabulary they read (`IChartRange`, `IReportInput`) — they are
-// `modules/report/src/chart-dates.ts` now. What stays here knows nothing above
-// it (ADR-022 R22).
+// `packages/core/src/modules/report/src/chart-dates.ts` now.
+//
+// M15-010: what was left knows nothing above it and nothing about the domain,
+// so it is @openpanel/shared's (ADR-022 R21).
import { DateTime } from 'luxon';
export { DateTime } from 'luxon';
diff --git a/packages/core/src/shared/id.ts b/packages/shared/src/id.ts
similarity index 75%
rename from packages/core/src/shared/id.ts
rename to packages/shared/src/id.ts
index 7c143bc3f..161481f50 100644
--- a/packages/core/src/shared/id.ts
+++ b/packages/shared/src/id.ts
@@ -1,5 +1,7 @@
-// Ported from packages/common's id.ts, unchanged. nanoid/non-secure is
-// deliberate: these are correlation/display ids, not secrets.
+// Ported from packages/common's id.ts, then to @openpanel/shared (M15-010,
+// ADR-022 R21) — apps/start had copied `shortId` into its own utils/math.ts.
+// nanoid/non-secure is deliberate: these are correlation/display ids, not
+// secrets.
// Ported from packages/common/server's id.ts (M4-003). Regular `nanoid`,
// not the non-secure variant above: these ids back password-reset tokens and
diff --git a/packages/shared/src/index.ts b/packages/shared/src/index.ts
new file mode 100644
index 000000000..ef0a7908b
--- /dev/null
+++ b/packages/shared/src/index.ts
@@ -0,0 +1,27 @@
+// The isomorphic entrypoint of @openpanel/shared (ADR-022 R21).
+//
+// What may live behind this file: pure functions and types with no workspace
+// import, no db/redis/env/logger/services and no domain vocabulary. Anything
+// that needs one of those stays in the package that owns it.
+//
+// Nothing reachable from here may import a `node:*` builtin or `./server` —
+// this is a browser bundle's entrypoint too, and the leak would be invisible
+// at the call site. The `shared-root-stays-isomorphic` cruiser rule is what
+// enforces it.
+export {
+ DateTime,
+ getChartPrevStartEndDate,
+ getTime,
+ resolveDateRange,
+} from './date';
+export { generateId, generateSecureId, shortId } from './id';
+export { getSafeJson, getSuperJson, setSuperJson } from './json';
+export { average, ifNaN, max, min, round, sum } from './math';
+export { deepMergeObjects, strip, toDots, toObject } from './object';
+export { slug } from './slug';
+export {
+ stripLeadingAndTrailingSlashes,
+ stripTrailingSlash,
+} from './string';
+export { type TryCatchResult, tryCatch } from './try-catch';
+export { isSameDomain, parsePath, parseSearchParams } from './url';
diff --git a/packages/shared/src/json.ts b/packages/shared/src/json.ts
new file mode 100644
index 000000000..c289e1c41
--- /dev/null
+++ b/packages/shared/src/json.ts
@@ -0,0 +1,28 @@
+// Ported from packages/json, then to @openpanel/shared (M15-010, ADR-022
+// R21): packages/redis and apps/start each carried a copy, and redis' copy
+// carried the "keep in sync with packages/core" comment that is the whole
+// argument for a package below both. Same semantics: getSafeJson never throws, and
+// getSuperJson only hands off to superjson's parser when the payload looks
+// like superjson's own `{ json, meta }` envelope — a plain JSON payload
+// round-trips through JSON.parse instead.
+import superjson from 'superjson';
+
+export function getSafeJson<T>(str: string): T | null {
+ try {
+ return JSON.parse(str);
+ } catch {
+ return null;
+ }
+}
+
+export function getSuperJson<T>(str: string): T | null {
+ const json = getSafeJson<T>(str);
+ if (typeof json === 'object' && json !== null && 'json' in json) {
+ return superjson.parse<T>(str);
+ }
+ return json;
+}
+
+export function setSuperJson(value: unknown): string {
+ return superjson.stringify(value);
+}
diff --git a/packages/core/src/shared/math.ts b/packages/shared/src/math.ts
similarity index 85%
rename from packages/core/src/shared/math.ts
rename to packages/shared/src/math.ts
index 1150dfa84..7fa7ae240 100644
--- a/packages/core/src/shared/math.ts
+++ b/packages/shared/src/math.ts
@@ -3,8 +3,11 @@
// `isFloat` does NOT come along: no importer, anywhere.
//
// M15-009: `getPreviousMetric` left with the report vocabulary it returns —
-// it is `modules/report/src/previous-metric.ts` now. What stays here is the
-// generic arithmetic, which knows nothing above it (ADR-022 R22).
+// it is `packages/core/src/modules/report/src/previous-metric.ts` now.
+//
+// M15-010: what was left is generic arithmetic, so it is @openpanel/shared's
+// (ADR-022 R21). apps/start had copied all six of these functions verbatim;
+// that copy is deleted and the dashboard imports them from here.
//
// `isNumber` is mathjs's, not `typeof n === 'number'` — it is the filter
// predicate for every chart aggregate below, so it stays exactly as it was.
diff --git a/packages/core/src/shared/object.ts b/packages/shared/src/object.ts
similarity index 100%
rename from packages/core/src/shared/object.ts
rename to packages/shared/src/object.ts
diff --git a/packages/core/src/shared/crypto.ts b/packages/shared/src/server/crypto.ts
similarity index 100%
rename from packages/core/src/shared/crypto.ts
rename to packages/shared/src/server/crypto.ts
diff --git a/packages/core/src/shared/encryption.ts b/packages/shared/src/server/encryption.ts
similarity index 100%
rename from packages/core/src/shared/encryption.ts
rename to packages/shared/src/server/encryption.ts
diff --git a/packages/shared/src/server/index.ts b/packages/shared/src/server/index.ts
new file mode 100644
index 000000000..a25f364d3
--- /dev/null
+++ b/packages/shared/src/server/index.ts
@@ -0,0 +1,39 @@
+// The Node-only entrypoint of @openpanel/shared (ADR-022 R21):
+// `@openpanel/shared/server`. Everything behind it may use `node:*`.
+//
+// A web app may not import it — `no-web-to-server` in .dependency-cruiser.cjs
+// forbids apps/start, apps/public and packages/sdks/* from reaching this path.
+export {
+ createHash,
+ generateSalt,
+ hashPassword,
+ verifyPassword,
+} from './crypto';
+export {
+ decrypt,
+ decryptCredential,
+ type EncryptionKey,
+ encrypt,
+ encryptCredential,
+ isEncrypted,
+} from './encryption';
+export {
+ getDevice,
+ parseUserAgent,
+ type UserAgentInfo,
+ type UserAgentResult,
+} from './parser-user-agent';
+export {
+ assertPublicHostname,
+ assertPublicUrl,
+ BlockedUrlError,
+ createPinnedAgent,
+ createPinnedLookup,
+ isBlockedIp,
+ type SafeFetchOptions,
+ type SafeFetchResult,
+ type SafeFetchStreamResult,
+ safeFetch,
+ safeFetchStream,
+} from './safe-fetch';
+export { assertSafeUrl } from './ssrf';
diff --git a/packages/core/src/shared/parser-user-agent.ts b/packages/shared/src/server/parser-user-agent.ts
similarity index 100%
rename from packages/core/src/shared/parser-user-agent.ts
rename to packages/shared/src/server/parser-user-agent.ts
diff --git a/packages/core/src/shared/safe-fetch.ts b/packages/shared/src/server/safe-fetch.ts
similarity index 100%
rename from packages/core/src/shared/safe-fetch.ts
rename to packages/shared/src/server/safe-fetch.ts
diff --git a/packages/core/src/shared/ssrf.ts b/packages/shared/src/server/ssrf.ts
similarity index 96%
rename from packages/core/src/shared/ssrf.ts
rename to packages/shared/src/server/ssrf.ts
index 4213d2a02..e50a7d87b 100644
--- a/packages/core/src/shared/ssrf.ts
+++ b/packages/shared/src/server/ssrf.ts
@@ -1,7 +1,5 @@
import { assertPublicUrl } from './safe-fetch';
-export { createPinnedLookup } from './safe-fetch';
-
/**
* Guard a stored, tenant-supplied URL that we are about to connect to with a
* client we don't control the transport of (the AWS SDK, a TLS probe). When the
diff --git a/packages/core/src/shared/slug.ts b/packages/shared/src/slug.ts
similarity index 64%
rename from packages/core/src/shared/slug.ts
rename to packages/shared/src/slug.ts
index 33d7c6f0c..ab122c229 100644
--- a/packages/core/src/shared/slug.ts
+++ b/packages/shared/src/slug.ts
@@ -1,5 +1,7 @@
-// Moved from packages/common/src/slug.ts (M11-006, ADR-007 shared/ layout).
-// Not to be confused with ./slug-id.ts, which calls this.
+// Moved from packages/common/src/slug.ts (M11-006), then to
+// @openpanel/shared (M15-010, ADR-022 R21) — apps/start carried a verbatim
+// copy of it, which is deleted. Not to be confused with core's slug-id.ts,
+// which calls this.
import _slugify from 'slugify';
const slugify = (str: string) => {
diff --git a/packages/core/src/shared/string.ts b/packages/shared/src/string.ts
similarity index 100%
rename from packages/core/src/shared/string.ts
rename to packages/shared/src/string.ts
diff --git a/packages/core/src/shared/try-catch.ts b/packages/shared/src/try-catch.ts
similarity index 100%
rename from packages/core/src/shared/try-catch.ts
rename to packages/shared/src/try-catch.ts
diff --git a/packages/core/src/shared/url.ts b/packages/shared/src/url.ts
similarity index 100%
rename from packages/core/src/shared/url.ts
rename to packages/shared/src/url.ts
diff --git a/packages/shared/tsconfig.json b/packages/shared/tsconfig.json
new file mode 100644
index 000000000..e7c1b79a0
--- /dev/null
+++ b/packages/shared/tsconfig.json
@@ -0,0 +1,10 @@
+{
+ "extends": "@openpanel/tsconfig/base.json",
+ "compilerOptions": {
+ "lib": ["ESNext", "DOM"],
+ "types": ["node"],
+ "tsBuildInfoFile": "node_modules/.cache/tsbuildinfo.json"
+ },
+ "include": ["src"],
+ "exclude": ["node_modules"]
+}