Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\""
},
"dependencies": {
"@xstreamroll/types": "*",
"@nestjs/cache-manager": "^2.3.0",
"@nestjs/common": "^10.3.0",
"@nestjs/core": "^10.3.0",
Expand Down
9 changes: 2 additions & 7 deletions api/src/admin/admin-stats.service.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import { Injectable } from "@nestjs/common"
import { AdminStats } from "@xstreamroll/types"

export interface AdminStats {
totalUsers: number
totalStreams: number
activeStreams: number
eventsLast24h: number
generatedAt: string
}
export type { AdminStats }

/**
* Aggregates platform-wide stats for the admin dashboard.
Expand Down
13 changes: 13 additions & 0 deletions api/src/streams/stream.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
* defined in `database/schema.sql`. The controller and service layers
* depend on this interface so they stay unchanged when the repository
* is swapped for a real DB-backed implementation.
*
* Note: uses number IDs and Date types (DB representation). The wire
* format (string IDs, ISO string dates) is defined in @xstreamroll/types.
*/
export interface Stream {
id: number
Expand All @@ -13,3 +16,13 @@ export interface Stream {
createdAt: Date
updatedAt: Date
}

export type {
StreamStatus,
StreamVisibility,
CreateStreamDto,
UpdateStreamDto,
StreamEvent,
StreamEventType,
StreamEventRecord,
} from "@xstreamroll/types"
5 changes: 5 additions & 0 deletions api/src/tags/tag.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
* In-memory representation of a tag. The shape mirrors what a future
* Postgres-backed entity will expose so the controller / service layer
* does not need to change when we swap the repository implementation.
*
* Note: uses Date type (DB representation). The wire format (string dates)
* is defined in @xstreamroll/types.
*/
export interface Tag {
id: number
Expand All @@ -18,3 +21,5 @@ export interface StreamTag {
tagId: number
createdAt: Date
}

export type { PagedTags } from "@xstreamroll/types"
5 changes: 4 additions & 1 deletion api/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
"declarationMap": true,
"sourceMap": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true
"emitDecoratorMetadata": true,
"paths": {
"@xstreamroll/types": ["../packages/types/src/index.ts"]
}
}
}
8 changes: 1 addition & 7 deletions app/lib/api/admin-stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,7 @@
* GET /admin/stats -> AdminStats
*/

export interface AdminStats {
totalUsers: number
totalStreams: number
activeStreams: number
eventsLast24h: number
generatedAt: string
}
export type { AdminStats } from "@xstreamroll/types"

const DEFAULT_API_BASE = "http://localhost:3001"

Expand Down
19 changes: 1 addition & 18 deletions app/lib/api/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,7 @@
* POST /notifications/:id/read -> { id, readAt }
*/

export interface Notification {
id: string
/** ISO-8601 timestamp. */
createdAt: string
/** ISO-8601 timestamp; null when the notification is unread. */
readAt: string | null
title: string
body: string
/** Optional URL the UI should navigate to on click. */
href?: string
/** Lightweight category — used to pick the icon. */
category?: "stream" | "system" | "billing" | "default"
}

export interface NotificationsPage {
items: Notification[]
unreadCount: number
}
export type { Notification, NotificationsPage } from "@xstreamroll/types"

const DEFAULT_API_BASE = "http://localhost:3001"

Expand Down
15 changes: 1 addition & 14 deletions app/lib/api/tags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,7 @@
* DELETE /streams/:id/tags/:tagId -> 204
*/

export interface Tag {
id: number
name: string
slug: string
createdAt: string
}

export interface PagedTags {
items: Tag[]
page: number
limit: number
total: number
hasMore: boolean
}
export type { Tag, PagedTags } from "@xstreamroll/types"

const DEFAULT_API_BASE = "http://localhost:3001"

Expand Down
1 change: 1 addition & 0 deletions app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
]
},
"dependencies": {
"@xstreamroll/types": "*",
"@hookform/resolvers": "^3.10.0",
"@radix-ui/react-accordion": "1.2.2",
"@radix-ui/react-alert-dialog": "1.1.4",
Expand Down
3 changes: 3 additions & 0 deletions app/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
"paths": {
"@/*": [
"./*"
],
"@xstreamroll/types": [
"../packages/types/src/index.ts"
]
}
},
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"description": "XStreamRoll Platform - Monorepo",
"private": true,
"workspaces": [
"packages/types",
"app",
"api",
"xstreamroll-sdk",
Expand Down
14 changes: 14 additions & 0 deletions packages/types/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "@xstreamroll/types",
"version": "1.0.0",
"description": "Shared TypeScript types for the XStreamRoll platform",
"main": "src/index.ts",
"types": "src/index.ts",
"private": true,
"scripts": {
"typecheck": "tsc --noEmit"
},
"devDependencies": {
"typescript": "^5.3.0"
}
}
7 changes: 7 additions & 0 deletions packages/types/src/admin-stats.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export interface AdminStats {
totalUsers: number
totalStreams: number
activeStreams: number
eventsLast24h: number
generatedAt: string
}
27 changes: 27 additions & 0 deletions packages/types/src/auth.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
export type UserRole = "admin" | "viewer"

export interface User {
id: string
email: string
displayName: string
role: UserRole
createdAt: string
updatedAt: string
}

export interface CreateUserDto {
email: string
password: string
displayName: string
}

export interface UpdateUserDto {
displayName?: string
email?: string
}

export interface AuthTokens {
accessToken: string
refreshToken: string
expiresIn: number
}
22 changes: 22 additions & 0 deletions packages/types/src/errors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
export interface ValidationError {
field: string
message: string
}

export interface ApiErrorResponse {
statusCode: number
message: string | string[]
error: string
validationErrors?: ValidationError[]
}

export class ApiError extends Error {
constructor(
public readonly statusCode: number,
message: string,
public readonly response?: ApiErrorResponse
) {
super(message)
this.name = "ApiError"
}
}
7 changes: 7 additions & 0 deletions packages/types/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export * from "./admin-stats"
export * from "./auth"
export * from "./errors"
export * from "./notification"
export * from "./pagination"
export * from "./stream"
export * from "./tag"
14 changes: 14 additions & 0 deletions packages/types/src/notification.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export interface Notification {
id: string
createdAt: string
readAt: string | null
title: string
body: string
href?: string
category?: "stream" | "system" | "billing" | "default"
}

export interface NotificationsPage {
items: Notification[]
unreadCount: number
}
11 changes: 11 additions & 0 deletions packages/types/src/pagination.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export interface PaginatedResponse<T> {
data: T[]
total: number
page: number
limit: number
}

export interface PaginationParams {
page?: number
limit?: number
}
49 changes: 49 additions & 0 deletions packages/types/src/stream.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
export type StreamStatus = "active" | "inactive" | "error"
export type StreamVisibility = "public" | "private"

export interface Stream {
id: string
userId: string
name: string
description: string | null
status: StreamStatus
visibility: StreamVisibility
createdAt: string
updatedAt: string
}

export interface CreateStreamDto {
name: string
description?: string
visibility?: StreamVisibility
}

export interface UpdateStreamDto {
name?: string
description?: string
status?: StreamStatus
visibility?: StreamVisibility
}

export type StreamEventType =
| "stream:started"
| "stream:stopped"
| "stream:error"
| "viewer:joined"
| "viewer:left"
| "data"

export interface StreamEvent {
streamId: string
eventType: StreamEventType
data: Record<string, unknown>
timestamp?: string
}

export interface StreamEventRecord {
id: string
streamId: string
eventType: StreamEventType
payload: Record<string, unknown>
occurredAt: string
}
14 changes: 14 additions & 0 deletions packages/types/src/tag.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export interface Tag {
id: number
name: string
slug: string
createdAt: string
}

export interface PagedTags {
items: Tag[]
page: number
limit: number
total: number
hasMore: boolean
}
12 changes: 12 additions & 0 deletions packages/types/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"compilerOptions": {
"target": "ES2020",
"module": "commonjs",
"strict": true,
"skipLibCheck": true,
"esModuleInterop": true,
"declaration": true,
"noEmit": true
},
"include": ["src"]
}
1 change: 1 addition & 0 deletions xstreamroll-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
]
},
"dependencies": {
"@xstreamroll/types": "*",
"axios": "^1.6.0"
},
"devDependencies": {
Expand Down
Loading
Loading