ts-packages 1.0.0

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,64 @@
1
+ import express from 'express';
2
+
3
+ export interface CorsOptions {
4
+ origin?: string | string[] | boolean | RegExp | ((origin: string | undefined, callback: (err: Error | null, allow?: boolean) => void) => void);
5
+ methods?: string | string[];
6
+ allowedHeaders?: string | string[];
7
+ exposedHeaders?: string | string[];
8
+ credentials?: boolean;
9
+ maxAge?: number;
10
+ preflightContinue?: boolean;
11
+ optionsSuccessStatus?: number;
12
+ }
13
+
14
+ export interface ServerConfig {
15
+ port?: number;
16
+ cors?: boolean | CorsOptions;
17
+ helmet?: boolean;
18
+ json?: boolean;
19
+ customMiddleware?: express.RequestHandler[];
20
+ healthCheck?: boolean | string;
21
+ gracefulShutdown?: boolean;
22
+ socketIO?: SocketIOConfig;
23
+ name?: string;
24
+ version?: string;
25
+ }
26
+
27
+ export interface SocketIOConfig {
28
+ enabled?: boolean;
29
+ cors?: boolean | {
30
+ origin?: string | string[] | boolean;
31
+ methods?: string[];
32
+ credentials?: boolean;
33
+ };
34
+ onConnection?: (socket: unknown) => void;
35
+ onDisconnection?: (socket: unknown, reason: string) => void;
36
+ path?: string;
37
+ }
38
+
39
+ export interface HealthCheckConfig {
40
+ path?: string;
41
+ customChecks?: HealthCheck[];
42
+ }
43
+
44
+ export interface HealthCheck {
45
+ name: string;
46
+ check: () => Promise<boolean>;
47
+ }
48
+
49
+ export interface GracefulShutdownConfig {
50
+ timeout?: number;
51
+ onShutdown?: () => Promise<void>;
52
+ }
53
+
54
+ export interface SocketInstance {
55
+ id: string;
56
+ emit: (event: string, data?: unknown) => void;
57
+ on: (event: string, handler: (...args: unknown[]) => void) => void;
58
+ broadcast: {
59
+ emit: (event: string, data?: unknown) => void;
60
+ };
61
+ disconnect: () => void;
62
+ }
63
+
64
+ export type ServerPlugin = (app: express.Application, config: ServerConfig) => void;
@@ -0,0 +1,34 @@
1
+ // Environment utilities
2
+ export function getEnv(key: string, defaultValue?: string): string {
3
+ const value = process.env[key];
4
+ if (value === undefined && defaultValue === undefined) {
5
+ throw new Error(`Environment variable ${key} is required`);
6
+ }
7
+ return value || defaultValue!;
8
+ }
9
+
10
+ export function getEnvNumber(key: string, defaultValue?: number): number {
11
+ const value = process.env[key];
12
+ if (value === undefined) {
13
+ if (defaultValue === undefined) {
14
+ throw new Error(`Environment variable ${key} is required`);
15
+ }
16
+ return defaultValue;
17
+ }
18
+ const parsed = parseInt(value, 10);
19
+ if (isNaN(parsed)) {
20
+ throw new Error(`Environment variable ${key} must be a number`);
21
+ }
22
+ return parsed;
23
+ }
24
+
25
+ export function getEnvBoolean(key: string, defaultValue?: boolean): boolean {
26
+ const value = process.env[key];
27
+ if (value === undefined) {
28
+ if (defaultValue === undefined) {
29
+ throw new Error(`Environment variable ${key} is required`);
30
+ }
31
+ return defaultValue;
32
+ }
33
+ return value.toLowerCase() === 'true';
34
+ }
@@ -0,0 +1,21 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "module": "CommonJS",
5
+ "moduleResolution": "node",
6
+ "rootDir": "./src",
7
+ "outDir": "./dist",
8
+ "strict": true,
9
+ "esModuleInterop": true,
10
+ "allowSyntheticDefaultImports": true,
11
+ "skipLibCheck": true,
12
+ "forceConsistentCasingInFileNames": true,
13
+ "declaration": true,
14
+ "baseUrl": ".",
15
+ "paths": {
16
+ "*": ["*", "*.ts", "*.js"]
17
+ }
18
+ },
19
+ "include": ["src/**/*"],
20
+ "exclude": ["node_modules", "dist"]
21
+ }
@@ -0,0 +1,2 @@
1
+ packages:
2
+ - "packages/*"