@plyaz/types 1.46.11 → 1.47.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.
@@ -23,3 +23,4 @@ export type * from './frontend';
23
23
  export * from './frameworks';
24
24
  export type * from './hooks';
25
25
  export type * from './utils';
26
+ export type * from './validation';
@@ -2,4 +2,4 @@
2
2
  * Core Init Types
3
3
  * Service registry and initialization type definitions
4
4
  */
5
- export type { CoreDomainServiceInstance, CoreServiceInitConfig, CoreServiceCreateOptions, CoreInitializableDomainService, CoreServiceEntry, CoreServiceRegistryConfig, CoreExtractServiceConfig, CoreExtractServiceInstance, CoreFeatureFlagInitConfig, CoreErrorHandlerInitConfig, CoreCacheConfig, CoreStorageConfig, CoreNotificationConfig, CoreObservabilityConfig, CoreStreamConfig, CoreInitOptionsBase, CoreServicesResultBase, CoreNestJsMiddlewareConfig, CoreNestJsRateLimitConfig, CoreNestJsValidationConfig, CoreNestJsSwaggerConfig, } from './types';
5
+ export type { CoreDomainServiceInstance, CoreServiceInitConfig, CoreServiceCreateOptions, CoreInitializableDomainService, CoreServiceEntry, CoreServiceRegistryConfig, CoreExtractServiceConfig, CoreExtractServiceInstance, CoreFeatureFlagInitConfig, CoreErrorHandlerInitConfig, CoreCacheConfig, CoreStorageConfig, CoreNotificationConfig, CoreObservabilityConfig, CoreStreamConfig, CoreInitOptionsBase, CoreServicesResultBase, CoreMiddlewareConfig, CoreRateLimitConfig, CoreCorsConfig, ConfigureAppResult, CoreNestJsMiddlewareConfig, CoreNestJsRateLimitConfig, CoreNestJsValidationConfig, CoreNestJsSwaggerConfig, CoreNestJsVersioningConfig, CoreExpressMiddlewareConfig, CoreNextJsMiddlewareConfig, } from './types';
@@ -788,16 +788,115 @@ export interface CoreStreamConfig {
788
788
  };
789
789
  }
790
790
  /**
791
- * Rate limiting configuration for NestJS
791
+ * Common rate limiting configuration.
792
+ * Shared across all frameworks (NestJS, Express, Hono, etc.)
792
793
  */
793
- export interface CoreNestJsRateLimitConfig {
794
+ export interface CoreRateLimitConfig {
794
795
  /** Time window in seconds (default: 60) */
795
796
  ttl?: number;
796
797
  /** Max requests per window (default: 100) */
797
798
  limit?: number;
798
- /** Skip rate limiting for certain paths */
799
+ /** Skip rate limiting for certain requests */
799
800
  skipIf?: (request: unknown) => boolean;
800
801
  }
802
+ /**
803
+ * Common CORS configuration.
804
+ * Shared across all frameworks.
805
+ */
806
+ export interface CoreCorsConfig {
807
+ /** Allowed origins (default: true for all) */
808
+ origin?: string | string[] | boolean;
809
+ /** Allow credentials (default: true) */
810
+ credentials?: boolean;
811
+ /** Allowed methods */
812
+ methods?: string[];
813
+ /** Allowed headers */
814
+ allowedHeaders?: string[];
815
+ }
816
+ /**
817
+ * Base middleware configuration shared across all frameworks.
818
+ * NestJS, Express, Next.js, Hono, etc. all extend this interface.
819
+ *
820
+ * @example
821
+ * ```typescript
822
+ * const config: CoreMiddlewareConfig = {
823
+ * compression: true,
824
+ * helmet: true,
825
+ * rateLimit: { ttl: 60, limit: 100 },
826
+ * bodyLimit: '10mb',
827
+ * timeout: 30000,
828
+ * cors: { origin: ['http://localhost:3000'] },
829
+ * gracefulShutdown: true,
830
+ * };
831
+ * ```
832
+ */
833
+ export interface CoreMiddlewareConfig {
834
+ /**
835
+ * Enable response compression (default: true in production).
836
+ * Uses compression middleware for gzip/brotli.
837
+ */
838
+ compression?: boolean;
839
+ /**
840
+ * Enable Helmet security headers (default: true).
841
+ * Adds XSS protection, content security policy, etc.
842
+ */
843
+ helmet?: boolean | Record<string, unknown>;
844
+ /**
845
+ * Rate limiting configuration.
846
+ * Set to false to disable, true for defaults, or object for custom config.
847
+ */
848
+ rateLimit?: boolean | CoreRateLimitConfig;
849
+ /**
850
+ * Maximum request body size (default: '10mb').
851
+ * Accepts string like '1mb', '10kb', or number in bytes.
852
+ */
853
+ bodyLimit?: string | number;
854
+ /**
855
+ * Request timeout in milliseconds (default: 30000).
856
+ * Set to 0 to disable timeout.
857
+ */
858
+ timeout?: number;
859
+ /**
860
+ * CORS configuration.
861
+ * Set to false to disable, true for defaults, or object for custom config.
862
+ */
863
+ cors?: boolean | CoreCorsConfig;
864
+ /**
865
+ * Enable graceful shutdown handling (default: true).
866
+ * Registers SIGTERM/SIGINT handlers for clean shutdown.
867
+ */
868
+ gracefulShutdown?: boolean;
869
+ /**
870
+ * Shutdown timeout in milliseconds (default: 10000).
871
+ * Time to wait for graceful shutdown before force exit.
872
+ */
873
+ shutdownTimeout?: number;
874
+ }
875
+ /**
876
+ * Result of configuring an app (framework-agnostic).
877
+ * Returned by configureNestApp, configureExpressApp, etc.
878
+ */
879
+ export interface ConfigureAppResult {
880
+ /** Features that were enabled */
881
+ enabled: string[];
882
+ /** Features that were skipped (not configured or dependencies missing) */
883
+ skipped: string[];
884
+ /** Any warnings during configuration */
885
+ warnings: string[];
886
+ /** Configured paths */
887
+ paths: {
888
+ /** API prefix (e.g., 'api') */
889
+ prefix?: string;
890
+ /** Documentation path (e.g., 'api/docs') */
891
+ docs?: string;
892
+ };
893
+ }
894
+ /**
895
+ * Rate limiting configuration for NestJS.
896
+ * @deprecated Use CoreRateLimitConfig instead
897
+ */
898
+ export interface CoreNestJsRateLimitConfig extends CoreRateLimitConfig {
899
+ }
801
900
  /**
802
901
  * Validation pipe configuration for NestJS
803
902
  */
@@ -828,8 +927,48 @@ export interface CoreNestJsSwaggerConfig {
828
927
  /** Bearer auth enabled */
829
928
  bearerAuth?: boolean;
830
929
  }
930
+ /**
931
+ * API versioning configuration for NestJS.
932
+ * Enables per-controller versioning via @Version() decorator.
933
+ */
934
+ export interface CoreNestJsVersioningConfig {
935
+ /**
936
+ * Versioning type.
937
+ * - 'uri': Version in URL path (e.g., /v1/users) - default
938
+ * - 'header': Version in request header
939
+ * - 'media-type': Version in Accept header media type
940
+ * - 'custom': Custom version extractor
941
+ */
942
+ type?: 'uri' | 'header' | 'media-type' | 'custom';
943
+ /**
944
+ * Default version when none specified.
945
+ * Can be a single version or array of versions.
946
+ * @example '1' or ['1', '2']
947
+ */
948
+ defaultVersion?: string | string[];
949
+ /**
950
+ * URI prefix for URI versioning (default: 'v').
951
+ * @example prefix: 'v' results in /v1/users
952
+ */
953
+ prefix?: string;
954
+ /**
955
+ * Header name for header versioning (default: 'X-API-Version').
956
+ */
957
+ header?: string;
958
+ /**
959
+ * Media type key for media-type versioning (default: 'v').
960
+ * @example Accept: application/json;v=1
961
+ */
962
+ key?: string;
963
+ /**
964
+ * Custom version extractor function.
965
+ * Only used when type is 'custom'.
966
+ */
967
+ extractor?: (request: unknown) => string | string[];
968
+ }
831
969
  /**
832
970
  * NestJS middleware and configuration options.
971
+ * Extends CoreMiddlewareConfig with NestJS-specific features.
833
972
  * Applied during app bootstrap via configureNestApp().
834
973
  *
835
974
  * @example
@@ -848,37 +987,77 @@ export interface CoreNestJsSwaggerConfig {
848
987
  * });
849
988
  * ```
850
989
  */
851
- export interface CoreNestJsMiddlewareConfig {
990
+ export interface CoreNestJsMiddlewareConfig extends CoreMiddlewareConfig {
852
991
  /**
853
- * Enable response compression (default: true in production).
854
- * Uses compression middleware for gzip/brotli.
992
+ * Global validation pipe configuration.
993
+ * Enables class-validator for DTO validation.
994
+ * NestJS-specific feature.
855
995
  */
856
- compression?: boolean;
996
+ validation?: boolean | CoreNestJsValidationConfig;
857
997
  /**
858
- * Enable Helmet security headers (default: true).
859
- * Adds XSS protection, content security policy, etc.
998
+ * Enable raw body parsing for webhooks (default: false).
999
+ * Required for signature verification (Stripe, GitHub, etc.).
1000
+ * When enabled, raw body is available on request.rawBody.
860
1001
  */
861
- helmet?: boolean | Record<string, unknown>;
1002
+ rawBody?: boolean | {
1003
+ paths?: string[];
1004
+ };
862
1005
  /**
863
- * Rate limiting configuration.
1006
+ * Swagger/OpenAPI documentation configuration.
864
1007
  * Set to false to disable, true for defaults, or object for custom config.
1008
+ * NestJS-specific feature.
865
1009
  */
866
- rateLimit?: boolean | CoreNestJsRateLimitConfig;
1010
+ swagger?: boolean | CoreNestJsSwaggerConfig;
867
1011
  /**
868
- * Global validation pipe configuration.
869
- * Enables class-validator for DTO validation.
1012
+ * Global prefix for all routes (default: 'api').
1013
+ * Set to false to disable prefix.
870
1014
  */
871
- validation?: boolean | CoreNestJsValidationConfig;
1015
+ globalPrefix?: string | false;
872
1016
  /**
873
- * Maximum request body size (default: '10mb').
874
- * Accepts string like '1mb', '10kb', or number in bytes.
1017
+ * Routes to exclude from global prefix.
1018
+ * @example ['health', 'metrics', 'webhooks/*']
875
1019
  */
876
- bodyLimit?: string | number;
1020
+ excludeFromPrefix?: string[];
877
1021
  /**
878
- * Request timeout in milliseconds (default: 30000).
879
- * Set to 0 to disable timeout.
1022
+ * API versioning configuration.
1023
+ * Enables per-controller versioning via @Version() decorator.
1024
+ * NestJS-specific feature.
1025
+ *
1026
+ * @example URI versioning (default)
1027
+ * ```typescript
1028
+ * versioning: { type: 'uri', defaultVersion: '1' }
1029
+ * // Routes: /v1/users, /v2/users
1030
+ * ```
1031
+ *
1032
+ * @example Header versioning
1033
+ * ```typescript
1034
+ * versioning: { type: 'header', header: 'X-API-Version' }
1035
+ * // Use header: X-API-Version: 1
1036
+ * ```
880
1037
  */
881
- timeout?: number;
1038
+ versioning?: CoreNestJsVersioningConfig;
1039
+ }
1040
+ /**
1041
+ * Express middleware and configuration options.
1042
+ * Extends CoreMiddlewareConfig with Express-specific features.
1043
+ * Applied during app bootstrap via configureExpressApp().
1044
+ *
1045
+ * @example
1046
+ * ```typescript
1047
+ * const app = express();
1048
+ * await configureExpressApp(app, {
1049
+ * express: {
1050
+ * compression: true,
1051
+ * helmet: true,
1052
+ * rateLimit: { ttl: 60, limit: 100 },
1053
+ * bodyLimit: '10mb',
1054
+ * trustProxy: true,
1055
+ * rawBody: { paths: ['/webhooks'] },
1056
+ * },
1057
+ * });
1058
+ * ```
1059
+ */
1060
+ export interface CoreExpressMiddlewareConfig extends CoreMiddlewareConfig {
882
1061
  /**
883
1062
  * Enable raw body parsing for webhooks (default: false).
884
1063
  * Required for signature verification (Stripe, GitHub, etc.).
@@ -888,40 +1067,76 @@ export interface CoreNestJsMiddlewareConfig {
888
1067
  paths?: string[];
889
1068
  };
890
1069
  /**
891
- * Swagger/OpenAPI documentation configuration.
892
- * Set to false to disable, true for defaults, or object for custom config.
1070
+ * Trust proxy setting for Express.
1071
+ * Required when behind a reverse proxy (nginx, load balancer).
1072
+ * @see https://expressjs.com/en/guide/behind-proxies.html
893
1073
  */
894
- swagger?: boolean | CoreNestJsSwaggerConfig;
1074
+ trustProxy?: boolean | string | number;
895
1075
  /**
896
- * CORS configuration override.
897
- * By default, uses app-level CORS. Set here to override.
1076
+ * Mount path for the Express app.
1077
+ * @example '/api' mounts all routes under /api/*
898
1078
  */
899
- cors?: boolean | {
900
- origin?: string | string[] | boolean;
901
- credentials?: boolean;
902
- methods?: string[];
903
- allowedHeaders?: string[];
904
- };
1079
+ mountPath?: string;
905
1080
  /**
906
- * Global prefix for all routes (default: 'api').
907
- * Set to false to disable prefix.
1081
+ * Extended URL encoding for body parser.
1082
+ * @default true
908
1083
  */
909
- globalPrefix?: string | false;
1084
+ extendedUrlEncoded?: boolean;
1085
+ }
1086
+ /**
1087
+ * Next.js middleware and configuration options.
1088
+ * Extends CoreMiddlewareConfig with Next.js-specific features.
1089
+ * Applied via middleware.ts or API route wrappers.
1090
+ *
1091
+ * @example App Router API
1092
+ * ```typescript
1093
+ * // app/api/users/route.ts
1094
+ * import { withCoreMiddleware } from '@plyaz/core/nextjs';
1095
+ *
1096
+ * export const GET = withCoreMiddleware(async (req) => {
1097
+ * return Response.json({ users: [] });
1098
+ * }, {
1099
+ * rateLimit: { ttl: 60, limit: 100 },
1100
+ * });
1101
+ * ```
1102
+ *
1103
+ * @example Pages Router API
1104
+ * ```typescript
1105
+ * // pages/api/users.ts
1106
+ * import { withCoreApiHandler } from '@plyaz/core/nextjs';
1107
+ *
1108
+ * export default withCoreApiHandler(async (req, res) => {
1109
+ * res.json({ users: [] });
1110
+ * }, {
1111
+ * rateLimit: { ttl: 60, limit: 100 },
1112
+ * });
1113
+ * ```
1114
+ */
1115
+ export interface CoreNextJsMiddlewareConfig extends CoreMiddlewareConfig {
910
1116
  /**
911
- * Routes to exclude from global prefix.
912
- * @example ['health', 'metrics', 'webhooks/*']
1117
+ * Enable raw body parsing for webhooks (default: false).
1118
+ * Required for signature verification (Stripe, GitHub, etc.).
1119
+ * Note: Next.js App Router requires config.api.bodyParser = false
913
1120
  */
914
- excludeFromPrefix?: string[];
1121
+ rawBody?: boolean | {
1122
+ paths?: string[];
1123
+ };
915
1124
  /**
916
- * Enable graceful shutdown handling (default: true).
917
- * Registers SIGTERM/SIGINT handlers for clean shutdown.
1125
+ * API base path for Next.js routes.
1126
+ * @default '/api'
918
1127
  */
919
- gracefulShutdown?: boolean;
1128
+ apiBasePath?: string;
920
1129
  /**
921
- * Shutdown timeout in milliseconds (default: 10000).
922
- * Time to wait for graceful shutdown before force exit.
1130
+ * Enable Edge runtime compatibility mode.
1131
+ * Some middleware (compression, helmet) may not work on Edge.
1132
+ * @default false
923
1133
  */
924
- shutdownTimeout?: number;
1134
+ edgeCompatible?: boolean;
1135
+ /**
1136
+ * Skip middleware for certain paths (regex patterns).
1137
+ * @example ['^/api/health$', '^/_next/.*']
1138
+ */
1139
+ skipPaths?: string[];
925
1140
  }
926
1141
  /**
927
1142
  * Base core initialization options
@@ -990,6 +1205,18 @@ export interface CoreInitOptionsBase<TDb = unknown, TApi = unknown, TStorage = u
990
1205
  * Only used when runtime is 'nestjs'.
991
1206
  */
992
1207
  nestjs?: CoreNestJsMiddlewareConfig;
1208
+ /**
1209
+ * Express-specific middleware and configuration.
1210
+ * Applied during app bootstrap via configureExpressApp().
1211
+ * Only used when runtime is 'express'.
1212
+ */
1213
+ express?: CoreExpressMiddlewareConfig;
1214
+ /**
1215
+ * Next.js-specific middleware and configuration.
1216
+ * Applied via middleware.ts or API route wrappers.
1217
+ * Only used when runtime is 'nextjs'.
1218
+ */
1219
+ nextjs?: CoreNextJsMiddlewareConfig;
993
1220
  }
994
1221
  /**
995
1222
  * Core services result from initialization
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Validation Types
3
+ *
4
+ * Types for schema validation across the Plyaz ecosystem.
5
+ * Compatible with Zod schemas without complex type inference issues.
6
+ */
7
+ /**
8
+ * Minimal schema interface for validation pipes.
9
+ * Compatible with Zod schemas without complex type inference issues.
10
+ *
11
+ * Use this type instead of ZodSchema<T> to avoid TypeScript
12
+ * "type instantiation excessively deep" errors with complex schemas.
13
+ *
14
+ * Note: This uses Zod's actual API structure where error is an object
15
+ * with an `issues` array, not the abstracted `ValidationSchema` from
16
+ * errors/validation.ts which uses a flat `errors` array.
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * import type { ValidatableSchema } from '@plyaz/types/core';
21
+ *
22
+ * class ValidationPipe<T> {
23
+ * constructor(private schema: ValidatableSchema<T>) {}
24
+ *
25
+ * transform(value: unknown): T {
26
+ * const result = this.schema.safeParse(value);
27
+ * if (!result.success) throw result.error;
28
+ * return result.data;
29
+ * }
30
+ * }
31
+ * ```
32
+ */
33
+ export interface ValidatableSchema<T = unknown> {
34
+ safeParse(value: unknown): {
35
+ success: true;
36
+ data: T;
37
+ } | {
38
+ success: false;
39
+ error: {
40
+ issues: ReadonlyArray<{
41
+ path: PropertyKey[];
42
+ message: string;
43
+ code: string;
44
+ }>;
45
+ };
46
+ };
47
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plyaz/types",
3
- "version": "1.46.11",
3
+ "version": "1.47.0",
4
4
  "author": "Redeemer Pace",
5
5
  "license": "ISC",
6
6
  "description": "Provides shared TypeScript types and schema utilities for validation and parsing in the @playz ecosystem.",