@zeruxjs/reports 0.0.0-stage → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,103 @@
1
+ import type { AnalyticsManager, AnalyticsRow, AnalyticsSummaryQuery, AnalyticsAggregateQuery, AnalyticsAggregateResult, AnalyticsNumericAggregateQuery, AnalyticsNumericAggregateResult } from '@zeruxjs/analytics';
2
+ export type ChartKind = 'bar' | 'horizontal-bar' | 'line' | 'area' | 'pie' | 'doughnut' | 'scatter' | 'stacked-bar' | 'table' | 'kpi';
3
+ export type Metric = 'count' | 'sum' | 'average' | 'min' | 'max' | 'distinct';
4
+ export interface ChartDefinition {
5
+ id: string;
6
+ title: string;
7
+ type: ChartKind;
8
+ groupBy: 'event' | 'day' | 'source' | 'site' | 'pathname' | `property:${string}`;
9
+ metric: Metric;
10
+ valueField?: string;
11
+ eventName?: string;
12
+ source?: string;
13
+ site?: string;
14
+ since?: number;
15
+ until?: number;
16
+ limit?: number;
17
+ }
18
+ export interface ReportPage {
19
+ id: string;
20
+ name: string;
21
+ charts: ChartDefinition[];
22
+ }
23
+ export interface ReportDefinition {
24
+ id: string;
25
+ name: string;
26
+ description?: string;
27
+ pages: ReportPage[];
28
+ }
29
+ export interface ReportsDocument {
30
+ version: number;
31
+ reports: ReportDefinition[];
32
+ }
33
+ export interface ReportsStore {
34
+ load(): Promise<ReportsDocument>;
35
+ save(document: ReportsDocument, expectedVersion: number): Promise<boolean>;
36
+ }
37
+ /** Custom aggregate adapters remove the built-in 500-row query limit. */
38
+ export interface AnalyticsReportSource {
39
+ events(query: AnalyticsSummaryQuery): Promise<AnalyticsRow[]>;
40
+ aggregate?(query: AnalyticsAggregateQuery): Promise<AnalyticsAggregateResult>;
41
+ aggregateNumeric?(query: AnalyticsNumericAggregateQuery): Promise<AnalyticsNumericAggregateResult>;
42
+ supportsNumericField?(field: string): boolean;
43
+ }
44
+ export type ReportAction = 'read' | 'edit' | 'export' | 'sensitive' | 'campaign';
45
+ /** A trusted application callback supplies both tenant storage and a fixed analytics site.
46
+ * Never derive this from query parameters, Host or unverified cookies. */
47
+ export interface ReportTenantScope {
48
+ site: string;
49
+ store: ReportsStore;
50
+ source?: AnalyticsReportSource;
51
+ }
52
+ export interface MarketingReportPage {
53
+ campaignCode: string;
54
+ status: string;
55
+ scanned: number;
56
+ states: Record<string, number>;
57
+ nextCursor: string | null;
58
+ done: boolean;
59
+ scope: 'complete' | 'page';
60
+ disclaimer: string;
61
+ }
62
+ /** The marketing service must authorize campaign access independently of Reports.
63
+ * Supplying campaign callbacks does not grant access to another tenant's campaigns. */
64
+ export interface CampaignReportsSource {
65
+ report(code: string, options: {
66
+ cursor: string | null;
67
+ limit: number;
68
+ site?: string;
69
+ }): Promise<MarketingReportPage>;
70
+ performance?(code: string, site?: string): Promise<unknown>;
71
+ dailyTrends?(code: string, from: string, to: string, site?: string): Promise<unknown>;
72
+ activity?(code: string, from: string, to: string, site?: string): Promise<unknown>;
73
+ }
74
+ export interface ReportsOptions {
75
+ analytics: AnalyticsManager;
76
+ store?: ReportsStore;
77
+ source?: AnalyticsReportSource;
78
+ prefix?: string;
79
+ /** Distinct read, edit, export and campaign authorization; legacy single-argument callbacks remain valid. */
80
+ authorize: (request: Request, action?: ReportAction, resourceId?: string) => boolean | Promise<boolean>;
81
+ dashboardHost?: string;
82
+ maxSourceRows?: number;
83
+ /** Static site is appropriate only for dedicated single-tenant instances. */
84
+ site?: string;
85
+ /** Dynamic tenant mode REQUIRES tenant-specific persisted stores; authorization precedes resolution. */
86
+ resolveScope?: (request: Request) => Promise<ReportTenantScope> | ReportTenantScope;
87
+ /** Opt-in marketing reporting; all callbacks must enforce their own campaign tenant boundary. */
88
+ campaigns?: CampaignReportsSource;
89
+ }
90
+ export interface ChartData {
91
+ id: string;
92
+ title: string;
93
+ type: ChartKind;
94
+ labels: string[];
95
+ values: number[];
96
+ total: number;
97
+ sampledRows: number;
98
+ truncated: boolean; /** Native DB counts are exact; limited source rows are explicitly sampled. */
99
+ queryMode?: 'database' | 'sampled' | 'materialized'; /** Materialized numeric totals cover only successfully indexed numeric facts. */
100
+ numericCoverage?: 'indexed-only';
101
+ matchedFacts?: number; /** Scope and interpretation, not an assertion of exactness. */
102
+ coverage?: string;
103
+ }
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,40 @@
1
1
  {
2
2
  "name": "@zeruxjs/reports",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.0.2",
4
+ "type": "module",
5
+ "description": "Authenticated report builder backed by internal Zerux analytics",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "default": "./dist/index.js"
12
+ }
13
+ },
14
+ "scripts": {
15
+ "build": "tsc",
16
+ "test": "npm run build && node --test test/*.test.mjs",
17
+ "prepack": "npm run build"
18
+ },
19
+ "peerDependencies": {
20
+ "@zeruxjs/analytics": "0.0.2"
21
+ },
22
+ "files": [
23
+ "dist/",
24
+ "README.md",
25
+ "LICENSE-MIT",
26
+ "LICENSE-APACHE"
27
+ ],
28
+ "publishConfig": {
29
+ "access": "public"
30
+ },
31
+ "license": "(MIT OR Apache-2.0)",
32
+ "devDependencies": {
33
+ "typescript": "^5.9.3",
34
+ "@types/node": "^25.4.0"
35
+ },
36
+ "repository": {
37
+ "type": "git",
38
+ "url": "git+https://github.com/zeruxjs/zeruxjs.git"
39
+ }
40
+ }