@worktif/runtime 0.3.0-edge.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.
- package/LICENSE +101 -0
- package/README.md +495 -0
- package/out/dist/bin/index.js +212 -0
- package/out/dist/bin/purenow.js +218 -0
- package/out/dist/bin/templates/runtime-web/cdk/.gitignore.template +25 -0
- package/out/dist/bin/templates/runtime-web/cdk/README.md.template +267 -0
- package/out/dist/bin/templates/runtime-web/cdk/bin/app.ts.template +173 -0
- package/out/dist/bin/templates/runtime-web/cdk/cdk.json.template +79 -0
- package/out/dist/bin/templates/runtime-web/cdk/package.json.template +28 -0
- package/out/dist/bin/templates/runtime-web/cdk/tsconfig.json.template +38 -0
- package/out/dist/bin/templates/runtime-web/purenow-basic/.env.example +15 -0
- package/out/dist/bin/templates/runtime-web/purenow-basic/README.md +118 -0
- package/out/dist/bin/templates/runtime-web/purenow-basic/gitignore.template +64 -0
- package/out/dist/bin/templates/runtime-web/purenow-basic/package.json +34 -0
- package/out/dist/bin/templates/runtime-web/purenow-basic/purenow.config.ts +105 -0
- package/out/dist/bin/templates/runtime-web/purenow-basic/src/app.tsx +35 -0
- package/out/dist/bin/templates/runtime-web/purenow-basic/src/handlers/users/index.ts +17 -0
- package/out/dist/bin/templates/runtime-web/purenow-basic/src/handlers/users/users.handlers.ts +222 -0
- package/out/dist/bin/templates/runtime-web/purenow-basic/src/index.tsx +71 -0
- package/out/dist/bin/templates/runtime-web/purenow-basic/src/pages/about-page.tsx +65 -0
- package/out/dist/bin/templates/runtime-web/purenow-basic/src/pages/home-page.tsx +55 -0
- package/out/dist/bin/templates/runtime-web/purenow-basic/src/pages/users-page.tsx +66 -0
- package/out/dist/bin/templates/runtime-web/purenow-basic/src/routes.tsx +61 -0
- package/out/dist/bin/templates/runtime-web/purenow-basic/src/services/index.ts +17 -0
- package/out/dist/bin/templates/runtime-web/purenow-basic/src/services/users.service.ts +133 -0
- package/out/dist/bin/templates/runtime-web/purenow-basic/src/ties/index.ts +17 -0
- package/out/dist/bin/templates/runtime-web/purenow-basic/src/ties/users.ties.ts +53 -0
- package/out/dist/bin/templates/runtime-web/purenow-basic/tsconfig.json +53 -0
- package/out/dist/lib/index.d.ts +4 -0
- package/out/dist/lib/index.js +4 -0
- package/out/dist/lib/lib/index.d.ts +3 -0
- package/out/dist/lib/lib/runtime-web/index.d.ts +17 -0
- package/out/dist/lib/lib/runtime-web/pipelines/browser-pipeline.d.ts +110 -0
- package/out/dist/lib/lib/runtime-web/pipelines/index.d.ts +2 -0
- package/out/dist/lib/lib/runtime-web/pureweb.d.ts +65 -0
- package/out/dist/lib/lib/runtime-web/types/config.types.d.ts +301 -0
- package/out/dist/lib/lib/runtime-web/types/http.types.d.ts +171 -0
- package/out/dist/lib/lib/runtime-web/types/index.d.ts +14 -0
- package/out/dist/lib/lib/runtime-web/types/infra.types.d.ts +225 -0
- package/out/dist/lib/lib/runtime-web/types/lambda.types.d.ts +175 -0
- package/out/dist/lib/lib/runtime-web/types/microservice.types.d.ts +70 -0
- package/out/dist/lib/lib/runtime-web/types/runtime.types.d.ts +55 -0
- package/out/dist/lib/utils/index.d.ts +2 -0
- package/out/dist/lib/utils/types/index.d.ts +3 -0
- package/out/dist/lib/utils/types/runtime.config.types.d.ts +71 -0
- package/out/dist/src/bin/index.d.ts +5 -0
- package/out/dist/src/bin/index.unix.d.ts +5 -0
- package/out/dist/src/bin/purenow-runtime-cli.d.ts +31 -0
- package/out/dist/src/bin/services/index.d.ts +8 -0
- package/out/dist/src/bin/services/purenow-runtime-deployment.strategy.d.ts +37 -0
- package/out/dist/src/bin/services/purenow-runtime-stacks-deploy.service.d.ts +58 -0
- package/out/dist/src/bin/services/purenow-runtime-stacks-deploy.service.types.d.ts +18 -0
- package/out/dist/src/bin/services/runtime-web-cli-extensions.d.ts +2 -0
- package/out/dist/src/bin/services/template.service.d.ts +53 -0
- package/out/dist/src/bin/services/utils/index.d.ts +2 -0
- package/out/dist/src/bin/utils/errors.d.ts +68 -0
- package/out/dist/src/lib/runtime-web/index.d.ts +17 -0
- package/out/dist/src/lib/runtime-web/pipelines/browser-pipeline.d.ts +110 -0
- package/out/dist/src/lib/runtime-web/pipelines/index.d.ts +2 -0
- package/out/dist/src/lib/runtime-web/pureweb.d.ts +65 -0
- package/out/dist/src/lib/runtime-web/types/config.types.d.ts +301 -0
- package/out/dist/src/lib/runtime-web/types/http.types.d.ts +171 -0
- package/out/dist/src/lib/runtime-web/types/index.d.ts +14 -0
- package/out/dist/src/lib/runtime-web/types/infra.types.d.ts +225 -0
- package/out/dist/src/lib/runtime-web/types/lambda.types.d.ts +175 -0
- package/out/dist/src/lib/runtime-web/types/microservice.types.d.ts +70 -0
- package/out/dist/src/lib/runtime-web/types/runtime.types.d.ts +55 -0
- package/package.json +133 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime Web Core - Library (Isomorphic/Browser)
|
|
3
|
+
*
|
|
4
|
+
* **ARCHITECTURE NOTE**: This module contains browser-safe code that:
|
|
5
|
+
* - Runs in browser environment (client-side)
|
|
6
|
+
* - Uses browser APIs (window, document, hydrateRoot)
|
|
7
|
+
* - Must be isomorphic-safe (no Node.js APIs)
|
|
8
|
+
* - NEVER runs in Lambda
|
|
9
|
+
* - Bundled into browser builds
|
|
10
|
+
*
|
|
11
|
+
* **Exports**:
|
|
12
|
+
* - BrowserPipeline: Client-side React hydration and routing
|
|
13
|
+
*/
|
|
14
|
+
export * from './pipelines';
|
|
15
|
+
export * from './types';
|
|
16
|
+
export * from './pureweb';
|
|
17
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import type { BrowserMetadata, RuntimeWebConfig } from '../../runtime-web/types';
|
|
2
|
+
/**
|
|
3
|
+
* Browser execution pipeline for Runtime Target Core.
|
|
4
|
+
*
|
|
5
|
+
* @todo: ordinate this class to infra or core cause we have Node.js responsibility
|
|
6
|
+
* ---- OR –> REMOVE LOGGER
|
|
7
|
+
*
|
|
8
|
+
* **ARCHITECTURE NOTE**: This file is in `src/lib/` because it:
|
|
9
|
+
* - Uses browser-only APIs (window, document, hydrateRoot)
|
|
10
|
+
* - Runs ONLY in browser environment
|
|
11
|
+
* - Must be isomorphic-safe (no Node.js APIs)
|
|
12
|
+
* - NEVER runs in Lambda
|
|
13
|
+
*
|
|
14
|
+
* Handles client-side hydration of React applications with pre-loaded data
|
|
15
|
+
* from server-side rendering. Sets up client-side routing and HTTP client
|
|
16
|
+
* for post-hydration API calls to Lambda endpoints.
|
|
17
|
+
*
|
|
18
|
+
* **Execution Flow**:
|
|
19
|
+
* 1. Hydrate React app with existing PurenowRouter
|
|
20
|
+
* 2. Call config.app({ router }) to get React element
|
|
21
|
+
* 3. Initialize client-side navigation
|
|
22
|
+
* 4. Set up HTTP client for Lambda endpoint calls
|
|
23
|
+
*
|
|
24
|
+
* **Requirements**: REQ-06, REQ-12
|
|
25
|
+
*/
|
|
26
|
+
export declare class BrowserPipeline {
|
|
27
|
+
/**
|
|
28
|
+
* Execute browser pipeline for client-side hydration.
|
|
29
|
+
*
|
|
30
|
+
* Hydrates the React application with pre-loaded data from SSR and sets up
|
|
31
|
+
* client-side routing. Uses React hydration (not render) to match the
|
|
32
|
+
* server-rendered HTML exactly.
|
|
33
|
+
*
|
|
34
|
+
* @param config - Purenow configuration with app factory and router
|
|
35
|
+
* @param context - Browser environment context with metadata
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```typescript
|
|
39
|
+
* const pipeline = new BrowserPipeline();
|
|
40
|
+
* await pipeline.execute(config, {
|
|
41
|
+
* type: 'browser',
|
|
42
|
+
* metadata: {
|
|
43
|
+
* userAgent: navigator.userAgent,
|
|
44
|
+
* url: window.location.href,
|
|
45
|
+
* viewport: { width: window.innerWidth, height: window.innerHeight }
|
|
46
|
+
* }
|
|
47
|
+
* });
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
execute(config: RuntimeWebConfig, context: {
|
|
51
|
+
type: 'browser';
|
|
52
|
+
metadata: BrowserMetadata;
|
|
53
|
+
}): Promise<void>;
|
|
54
|
+
/**
|
|
55
|
+
* Create browser router from PurenowRouter configuration.
|
|
56
|
+
*
|
|
57
|
+
* Uses the existing PurenowRouter to get routes and creates a React Router
|
|
58
|
+
* browser router for client-side navigation.
|
|
59
|
+
*
|
|
60
|
+
* @param config - Purenow configuration
|
|
61
|
+
* @returns Browser router instance
|
|
62
|
+
* @private
|
|
63
|
+
*/
|
|
64
|
+
private createBrowserRouter;
|
|
65
|
+
/**
|
|
66
|
+
* Create React element from app factory function.
|
|
67
|
+
*
|
|
68
|
+
* Calls the user's app factory function with the router dependency
|
|
69
|
+
* to get the root React element for the application.
|
|
70
|
+
*
|
|
71
|
+
* @param config - Purenow configuration
|
|
72
|
+
* @returns Root React element
|
|
73
|
+
* @private
|
|
74
|
+
*/
|
|
75
|
+
private createAppElement;
|
|
76
|
+
/**
|
|
77
|
+
* Hydrate the React application in the browser.
|
|
78
|
+
*
|
|
79
|
+
* Uses React's hydrateRoot to hydrate the server-rendered HTML with
|
|
80
|
+
* the client-side React application. This ensures the client matches
|
|
81
|
+
* the server exactly to avoid hydration mismatches.
|
|
82
|
+
*
|
|
83
|
+
* @param routerProvider - Router provider element to hydrate
|
|
84
|
+
* @private
|
|
85
|
+
*/
|
|
86
|
+
private hydrateApplication;
|
|
87
|
+
/**
|
|
88
|
+
* Set up HTTP client for Lambda endpoint calls.
|
|
89
|
+
*
|
|
90
|
+
* Configures the HTTP client for making API calls to Lambda endpoints
|
|
91
|
+
* after hydration. This is used for post-hydration interactions that
|
|
92
|
+
* require server-side data.
|
|
93
|
+
*
|
|
94
|
+
* @param config - Purenow configuration
|
|
95
|
+
* @private
|
|
96
|
+
*/
|
|
97
|
+
private setupHttpClient;
|
|
98
|
+
/**
|
|
99
|
+
* Get API base URL based on deployment stage.
|
|
100
|
+
*
|
|
101
|
+
* Determines the appropriate API base URL for making HTTP requests
|
|
102
|
+
* to Lambda endpoints based on the deployment stage.
|
|
103
|
+
*
|
|
104
|
+
* @param stage - Deployment stage
|
|
105
|
+
* @returns API base URL
|
|
106
|
+
* @private
|
|
107
|
+
*/
|
|
108
|
+
private getApiBaseUrl;
|
|
109
|
+
}
|
|
110
|
+
//# sourceMappingURL=browser-pipeline.d.ts.map
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { RuntimeWebConfig } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Error thrown when configuration validation fails.
|
|
4
|
+
* Follows purenow error patterns without emoji.
|
|
5
|
+
*/
|
|
6
|
+
export declare class ConfigValidationError extends Error {
|
|
7
|
+
/** Array of validation error messages */
|
|
8
|
+
readonly errors: string[];
|
|
9
|
+
constructor(errors: string[]);
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Error thrown when environment detection fails.
|
|
13
|
+
* Follows purenow error patterns without emoji.
|
|
14
|
+
*/
|
|
15
|
+
export declare class EnvironmentDetectionError extends Error {
|
|
16
|
+
constructor(message: string);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Unified entry point for Runtime Target Core.
|
|
20
|
+
*
|
|
21
|
+
* This function provides a single API that works across all execution contexts:
|
|
22
|
+
* - **Browser**: Hydrates React application with client-side routing
|
|
23
|
+
* - **Lambda**: Executes server-side rendering and business logic with DI
|
|
24
|
+
* - **CDK**: Synthesizes CloudFormation infrastructure templates
|
|
25
|
+
*
|
|
26
|
+
* The function automatically detects the runtime environment and routes
|
|
27
|
+
* execution to the appropriate pipeline without user intervention.
|
|
28
|
+
*
|
|
29
|
+
* **Note**: For Lambda and CDK contexts, use the server-side entry point
|
|
30
|
+
* from `@core/runtime-web` instead. This browser-compatible version
|
|
31
|
+
* only supports browser hydration.
|
|
32
|
+
*
|
|
33
|
+
* @param config - Unified configuration for all contexts
|
|
34
|
+
* @returns Promise that resolves when execution completes
|
|
35
|
+
* @throws ConfigValidationError if configuration is invalid
|
|
36
|
+
* @throws EnvironmentDetectionError if environment cannot be detected
|
|
37
|
+
* @throws Error if execution fails
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```typescript
|
|
41
|
+
* import { purenow } from '@worktif/purenow/runtime-web';
|
|
42
|
+
* import { PurenowRouter } from '@worktif/purenow';
|
|
43
|
+
*
|
|
44
|
+
* purenow({
|
|
45
|
+
* app: ({ router }) => <App router={router} />,
|
|
46
|
+
* router: new PurenowRouter({ routes, defaults: {} }),
|
|
47
|
+
* serviceName: 'my-app',
|
|
48
|
+
* stage: 'dev',
|
|
49
|
+
* register: {
|
|
50
|
+
* payments: {
|
|
51
|
+
* ties: [PaymentsTies],
|
|
52
|
+
* lambdas: [chargeHandler, refundHandler]
|
|
53
|
+
* }
|
|
54
|
+
* },
|
|
55
|
+
* infra: {
|
|
56
|
+
* env: { account: '123456789012', region: 'us-east-1' },
|
|
57
|
+
* stage: 'dev',
|
|
58
|
+
* reactEntry: './src/index.tsx',
|
|
59
|
+
* apiMode: 'apiGateway'
|
|
60
|
+
* }
|
|
61
|
+
* });
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
export declare function pureweb(config: RuntimeWebConfig): void;
|
|
65
|
+
//# sourceMappingURL=pureweb.d.ts.map
|
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import type { InfraOptions } from './infra.types';
|
|
3
|
+
import type { MicroserviceDefinition } from './microservice.types';
|
|
4
|
+
/**
|
|
5
|
+
* PurenowRouter interface for runtime-web integration.
|
|
6
|
+
*
|
|
7
|
+
* Defines the essential methods needed by the runtime-web pipelines.
|
|
8
|
+
* This interface matches the actual PurenowRouter class from @lib/react/purenow.router.
|
|
9
|
+
*/
|
|
10
|
+
interface PurenowRouter {
|
|
11
|
+
/**
|
|
12
|
+
* Get all route objects as an array.
|
|
13
|
+
* Used for creating browser routers and SSR static handlers.
|
|
14
|
+
*/
|
|
15
|
+
getRoutes(): Array<{
|
|
16
|
+
path?: string;
|
|
17
|
+
element?: unknown;
|
|
18
|
+
loader?: unknown;
|
|
19
|
+
children?: unknown;
|
|
20
|
+
[key: string]: unknown;
|
|
21
|
+
}>;
|
|
22
|
+
/**
|
|
23
|
+
* Find a route by its ID.
|
|
24
|
+
*/
|
|
25
|
+
getRouteById?(id: string): unknown;
|
|
26
|
+
/**
|
|
27
|
+
* Find a route by its path.
|
|
28
|
+
*/
|
|
29
|
+
getRouteByPath?(path: string): unknown;
|
|
30
|
+
/**
|
|
31
|
+
* Get the routes array (getter).
|
|
32
|
+
*/
|
|
33
|
+
routes?: Array<unknown>;
|
|
34
|
+
/**
|
|
35
|
+
* Get the default configuration.
|
|
36
|
+
*/
|
|
37
|
+
defaults?: unknown;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Stage environment for deployment.
|
|
41
|
+
*
|
|
42
|
+
* - `dev`: Development environment
|
|
43
|
+
* - `staging`: Staging/pre-production environment
|
|
44
|
+
* - `prod`: Production environment
|
|
45
|
+
*/
|
|
46
|
+
export type Stage = 'dev' | 'staging' | 'prod';
|
|
47
|
+
/**
|
|
48
|
+
* Utility type to extract service names from register configuration.
|
|
49
|
+
*
|
|
50
|
+
* This enables compile-time validation of service names and provides
|
|
51
|
+
* type-safe access to service identifiers throughout the framework.
|
|
52
|
+
*
|
|
53
|
+
* @template T - The register configuration object type
|
|
54
|
+
*/
|
|
55
|
+
export type ServiceNames<T extends Record<string, MicroserviceDefinition>> = keyof T;
|
|
56
|
+
/**
|
|
57
|
+
* Utility type to generate Lambda IDs from service configuration.
|
|
58
|
+
*
|
|
59
|
+
* Combines service names with Lambda IDs to create fully qualified
|
|
60
|
+
* Lambda identifiers for type-safe Lambda resolution.
|
|
61
|
+
*
|
|
62
|
+
* @template T - The register configuration object type
|
|
63
|
+
*/
|
|
64
|
+
export type LambdaIds<T extends Record<string, MicroserviceDefinition>> = {
|
|
65
|
+
[K in keyof T]: T[K]['lambdas'][number] extends {
|
|
66
|
+
id: infer I;
|
|
67
|
+
} ? I extends string ? `${K & string}.${I}` : never : never;
|
|
68
|
+
}[keyof T];
|
|
69
|
+
/**
|
|
70
|
+
* Type constraint for valid service names.
|
|
71
|
+
*
|
|
72
|
+
* Ensures service names follow the validation pattern:
|
|
73
|
+
* - Must start with a letter (a-z, A-Z)
|
|
74
|
+
* - Can contain letters, numbers, and hyphens
|
|
75
|
+
* - Maximum length: 128 characters
|
|
76
|
+
*
|
|
77
|
+
* This is a branded type that provides compile-time validation.
|
|
78
|
+
*/
|
|
79
|
+
export type ValidServiceName = string & {
|
|
80
|
+
readonly __brand: 'ValidServiceName';
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* Type guard to validate service name format.
|
|
84
|
+
*
|
|
85
|
+
* @param serviceName - The service name to validate
|
|
86
|
+
* @returns Type predicate indicating if the service name is valid
|
|
87
|
+
*/
|
|
88
|
+
export declare function isValidServiceName(serviceName: string): serviceName is ValidServiceName;
|
|
89
|
+
/**
|
|
90
|
+
* Main configuration interface for Runtime Target Core.
|
|
91
|
+
*
|
|
92
|
+
* This interface provides a unified configuration that works across all execution contexts:
|
|
93
|
+
* - Browser: Hydrates React application with client-side routing
|
|
94
|
+
* - Lambda: Executes server-side rendering and business logic
|
|
95
|
+
* - CDK: Synthesizes CloudFormation infrastructure
|
|
96
|
+
*
|
|
97
|
+
* @template TRegister - The register configuration type for type-safe service names
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* ```typescript
|
|
101
|
+
* import { purenow } from '@worktif/purenow/runtime-web';
|
|
102
|
+
* import { PurenowRouter } from '@worktif/purenow';
|
|
103
|
+
*
|
|
104
|
+
* const config = {
|
|
105
|
+
* app: ({ router }) => <App router={router} />,
|
|
106
|
+
* router: new PurenowRouter({ router: routes, defaults: {} }),
|
|
107
|
+
* serviceName: 'my-app',
|
|
108
|
+
* stage: 'dev',
|
|
109
|
+
* register: {
|
|
110
|
+
* payments: {
|
|
111
|
+
* ties: [PaymentsTies],
|
|
112
|
+
* lambdas: [chargeHandler, refundHandler]
|
|
113
|
+
* },
|
|
114
|
+
* users: {
|
|
115
|
+
* ties: [UsersTies],
|
|
116
|
+
* lambdas: [createUserHandler, getUserHandler]
|
|
117
|
+
* }
|
|
118
|
+
* } as const, // Use 'as const' for better type inference
|
|
119
|
+
* infra: {
|
|
120
|
+
* env: { account: '123456789012', region: 'us-east-1' },
|
|
121
|
+
* stage: 'dev',
|
|
122
|
+
* reactEntry: './src/index.tsx',
|
|
123
|
+
* apiMode: 'apiGateway'
|
|
124
|
+
* }
|
|
125
|
+
* } satisfies PurenowConfig;
|
|
126
|
+
*
|
|
127
|
+
* purenow(config);
|
|
128
|
+
* ```
|
|
129
|
+
*
|
|
130
|
+
* @todo: after RuntimeWeb repo will be resolved, RuntimeWebConfig MUST extend PurenowConfig Core
|
|
131
|
+
*/
|
|
132
|
+
export interface RuntimeWebConfig<TRegister extends Record<string, MicroserviceDefinition> = Record<string, MicroserviceDefinition>> {
|
|
133
|
+
/**
|
|
134
|
+
* React application component factory function.
|
|
135
|
+
*
|
|
136
|
+
* Receives the router instance as a dependency and returns the root React element.
|
|
137
|
+
* This pattern enables dependency injection of the router into your application.
|
|
138
|
+
*
|
|
139
|
+
* @param deps - Dependencies object containing the router
|
|
140
|
+
* @param deps.router - PurenowRouter instance for navigation and routing
|
|
141
|
+
* @returns Root React element (React.ReactElement)
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* ```typescript
|
|
145
|
+
* app: ({ router }) => <App router={router} />
|
|
146
|
+
* ```
|
|
147
|
+
*/
|
|
148
|
+
app: (deps: {
|
|
149
|
+
router: PurenowRouter;
|
|
150
|
+
}) => React.ReactElement;
|
|
151
|
+
/**
|
|
152
|
+
* PurenowRouter instance for application routing.
|
|
153
|
+
*
|
|
154
|
+
* Defines all routes, loaders, and navigation configuration.
|
|
155
|
+
* The router is used in both server-side rendering (Lambda) and client-side hydration (browser).
|
|
156
|
+
*
|
|
157
|
+
* @see {@link PurenowRouter} for router configuration
|
|
158
|
+
*
|
|
159
|
+
* @example
|
|
160
|
+
* ```typescript
|
|
161
|
+
* router: new PurenowRouter({
|
|
162
|
+
* router: [
|
|
163
|
+
* { path: '/', element: <Home /> },
|
|
164
|
+
* { path: '/about', element: <About /> }
|
|
165
|
+
* ],
|
|
166
|
+
* defaults: {}
|
|
167
|
+
* })
|
|
168
|
+
* ```
|
|
169
|
+
*/
|
|
170
|
+
router: PurenowRouter;
|
|
171
|
+
/**
|
|
172
|
+
* Service name identifier for the application.
|
|
173
|
+
*
|
|
174
|
+
* Used as a prefix for all AWS resources (Lambda functions, API Gateway, S3 buckets, etc.).
|
|
175
|
+
* Must be unique within your AWS account and region.
|
|
176
|
+
*
|
|
177
|
+
* **Validation Rules**:
|
|
178
|
+
* - Must start with a letter (a-z, A-Z)
|
|
179
|
+
* - Can contain letters, numbers, and hyphens
|
|
180
|
+
* - Maximum length: 128 characters
|
|
181
|
+
* - Pattern: `/^[a-zA-Z][a-zA-Z0-9-]{0,127}$/`
|
|
182
|
+
*
|
|
183
|
+
* **Examples**:
|
|
184
|
+
* - Valid: `my-app`, `MyApp`, `app123`, `my-app-v2`
|
|
185
|
+
* - Invalid: `123app` (starts with number), `my_app` (underscore), `my app` (space)
|
|
186
|
+
*
|
|
187
|
+
* @example
|
|
188
|
+
* ```typescript
|
|
189
|
+
* serviceName: 'my-application'
|
|
190
|
+
* ```
|
|
191
|
+
*/
|
|
192
|
+
serviceName: string;
|
|
193
|
+
/**
|
|
194
|
+
* Deployment stage/environment.
|
|
195
|
+
*
|
|
196
|
+
* Determines the environment-specific configuration and resource naming.
|
|
197
|
+
* Used to create separate infrastructure stacks for different environments.
|
|
198
|
+
*
|
|
199
|
+
* **Values**:
|
|
200
|
+
* - `dev`: Development environment (local testing, rapid iteration)
|
|
201
|
+
* - `staging`: Staging/pre-production environment (QA, integration testing)
|
|
202
|
+
* - `prod`: Production environment (live users)
|
|
203
|
+
*
|
|
204
|
+
* **Impact**:
|
|
205
|
+
* - Resource naming: `{serviceName}-{resource}-{stage}`
|
|
206
|
+
* - Environment variables: Different configs per stage
|
|
207
|
+
* - Cache TTL: Shorter in dev, longer in prod
|
|
208
|
+
* - Logging: More verbose in dev, structured in prod
|
|
209
|
+
*
|
|
210
|
+
* @example
|
|
211
|
+
* ```typescript
|
|
212
|
+
* stage: 'dev'
|
|
213
|
+
* ```
|
|
214
|
+
*/
|
|
215
|
+
stage: Stage;
|
|
216
|
+
/**
|
|
217
|
+
* Microservice registry (runtime-level configuration).
|
|
218
|
+
*
|
|
219
|
+
* **Required**: Defines all microservices, their DI containers, and Lambda endpoints.
|
|
220
|
+
* **Used in all contexts**: Browser (for type generation), Lambda (for DI), CDK (for infrastructure).
|
|
221
|
+
* **Architecture**: This is runtime configuration, separate from infrastructure concerns.
|
|
222
|
+
*
|
|
223
|
+
* Each microservice gets its own PureContainer instance built from the Ties classes.
|
|
224
|
+
* Lambda functions are automatically created and wired with dependency injection.
|
|
225
|
+
*
|
|
226
|
+
* **Type Safety**: Service names are derived from object keys, ensuring compile-time validation.
|
|
227
|
+
* **No Magic Strings**: All service identifiers are type-safe and auto-generated.
|
|
228
|
+
*
|
|
229
|
+
* @see {@link MicroserviceDefinition} for microservice structure
|
|
230
|
+
*
|
|
231
|
+
* @example
|
|
232
|
+
* ```typescript
|
|
233
|
+
* register: {
|
|
234
|
+
* payments: {
|
|
235
|
+
* ties: [PaymentsTies, BillingTies],
|
|
236
|
+
* lambdas: [chargeHandler, refundHandler, webhookHandler]
|
|
237
|
+
* },
|
|
238
|
+
* users: {
|
|
239
|
+
* ties: [UsersTies, AuthTies],
|
|
240
|
+
* lambdas: [createUserHandler, getUserHandler, loginHandler]
|
|
241
|
+
* }
|
|
242
|
+
* } as const // Use 'as const' for better type inference
|
|
243
|
+
* ```
|
|
244
|
+
*/
|
|
245
|
+
register: TRegister;
|
|
246
|
+
/**
|
|
247
|
+
* Infrastructure configuration for CDK deployment.
|
|
248
|
+
*
|
|
249
|
+
* **Optional**: Only required when running in CDK context (synthesizing CloudFormation templates).
|
|
250
|
+
* **Not used**: In browser and Lambda contexts (runtime configuration is in register).
|
|
251
|
+
* **Pure infrastructure**: Contains only AWS resource configuration, no business logic.
|
|
252
|
+
*
|
|
253
|
+
* Defines:
|
|
254
|
+
* - AWS account and region
|
|
255
|
+
* - Lambda configuration (memory, timeout, VPC)
|
|
256
|
+
* - API Gateway or Lambda URL mode
|
|
257
|
+
* - Custom domain configuration
|
|
258
|
+
* - React entry point for SSR Lambda
|
|
259
|
+
*
|
|
260
|
+
* @see {@link InfraOptions} for detailed configuration options
|
|
261
|
+
*
|
|
262
|
+
* @example
|
|
263
|
+
* ```typescript
|
|
264
|
+
* infra: {
|
|
265
|
+
* env: { account: '123456789012', region: 'us-east-1' },
|
|
266
|
+
* stage: 'dev',
|
|
267
|
+
* reactEntry: './src/index.tsx',
|
|
268
|
+
* apiMode: 'apiGateway',
|
|
269
|
+
* lambdaMemorySize: 1024,
|
|
270
|
+
* lambdaTimeout: 30,
|
|
271
|
+
* domain: {
|
|
272
|
+
* rootDomain: 'myapp.com',
|
|
273
|
+
* subdomain: 'api'
|
|
274
|
+
* }
|
|
275
|
+
* }
|
|
276
|
+
* ```
|
|
277
|
+
*/
|
|
278
|
+
infra?: InfraOptions;
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Type-safe Purenow configuration with inferred service names.
|
|
282
|
+
*
|
|
283
|
+
* This type provides Runtime Core type safety by inferring service names from the register
|
|
284
|
+
* configuration, enabling compile-time validation of service references.
|
|
285
|
+
*
|
|
286
|
+
* @template TRegister - The register configuration type
|
|
287
|
+
*/
|
|
288
|
+
export type TypeSafePurenowConfig<TRegister extends Record<string, MicroserviceDefinition>> = RuntimeWebConfig<TRegister> & {
|
|
289
|
+
/**
|
|
290
|
+
* Type-safe service names derived from register keys.
|
|
291
|
+
* Available at compile-time for type checking and IDE autocomplete.
|
|
292
|
+
*/
|
|
293
|
+
readonly serviceNames?: ServiceNames<TRegister>;
|
|
294
|
+
/**
|
|
295
|
+
* Type-safe Lambda IDs derived from register configuration.
|
|
296
|
+
* Available at compile-time for type checking and IDE autocomplete.
|
|
297
|
+
*/
|
|
298
|
+
readonly lambdaIds?: LambdaIds<TRegister>;
|
|
299
|
+
};
|
|
300
|
+
export {};
|
|
301
|
+
//# sourceMappingURL=config.types.d.ts.map
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP methods supported by API Gateway integration.
|
|
3
|
+
*/
|
|
4
|
+
export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS';
|
|
5
|
+
/**
|
|
6
|
+
* Authentication types for HTTP endpoints.
|
|
7
|
+
*
|
|
8
|
+
* Maps to appropriate CDK authorizer configurations:
|
|
9
|
+
* - `none`: No authentication required
|
|
10
|
+
* - `jwt`: JWT token validation (Cognito User Pools or custom)
|
|
11
|
+
* - `iam`: AWS IAM signature validation
|
|
12
|
+
* - `cognito`: Cognito User Pool authorizer
|
|
13
|
+
* - `custom`: Custom Lambda authorizer
|
|
14
|
+
*/
|
|
15
|
+
export type AuthType = 'none' | 'jwt' | 'iam' | 'cognito' | 'custom';
|
|
16
|
+
/**
|
|
17
|
+
* CORS configuration for HTTP endpoints.
|
|
18
|
+
*
|
|
19
|
+
* Provides fine-grained control over Cross-Origin Resource Sharing settings.
|
|
20
|
+
* Used when cors: true and corsConfig is provided in HttpIntegration.
|
|
21
|
+
*/
|
|
22
|
+
export interface CorsConfig {
|
|
23
|
+
/**
|
|
24
|
+
* Allowed origins for CORS requests.
|
|
25
|
+
*
|
|
26
|
+
* **Examples**:
|
|
27
|
+
* - `['*']`: Allow all origins (development only)
|
|
28
|
+
* - `['https://myapp.com']`: Specific domain
|
|
29
|
+
* - `['https://myapp.com', 'https://staging.myapp.com']`: Multiple domains
|
|
30
|
+
*
|
|
31
|
+
* @default ['*'] in dev, specific domains in staging/prod
|
|
32
|
+
*/
|
|
33
|
+
allowOrigins?: string[];
|
|
34
|
+
/**
|
|
35
|
+
* Allowed HTTP methods for CORS requests.
|
|
36
|
+
*
|
|
37
|
+
* **Examples**:
|
|
38
|
+
* - `['GET', 'POST']`: Specific methods
|
|
39
|
+
* - `['*']`: All methods
|
|
40
|
+
*
|
|
41
|
+
* @default All methods used by registered Lambda endpoints
|
|
42
|
+
*/
|
|
43
|
+
allowMethods?: HttpMethod[] | ['*'];
|
|
44
|
+
/**
|
|
45
|
+
* Allowed headers for CORS requests.
|
|
46
|
+
*
|
|
47
|
+
* **Common headers**:
|
|
48
|
+
* - `Content-Type`: For JSON/form data
|
|
49
|
+
* - `Authorization`: For auth tokens
|
|
50
|
+
* - `X-Requested-With`: For AJAX requests
|
|
51
|
+
*
|
|
52
|
+
* @default ['Content-Type', 'Authorization', 'X-Requested-With']
|
|
53
|
+
*/
|
|
54
|
+
allowHeaders?: string[];
|
|
55
|
+
/**
|
|
56
|
+
* Whether to allow credentials (cookies, auth headers) in CORS requests.
|
|
57
|
+
*
|
|
58
|
+
* **Important**: Cannot be true when allowOrigins includes '*'
|
|
59
|
+
*
|
|
60
|
+
* @default false
|
|
61
|
+
*/
|
|
62
|
+
allowCredentials?: boolean;
|
|
63
|
+
/**
|
|
64
|
+
* Maximum age (seconds) for CORS preflight cache.
|
|
65
|
+
*
|
|
66
|
+
* How long browsers can cache the CORS preflight response.
|
|
67
|
+
*
|
|
68
|
+
* @default 86400 (24 hours)
|
|
69
|
+
*/
|
|
70
|
+
maxAge?: number;
|
|
71
|
+
/**
|
|
72
|
+
* Headers exposed to the client in CORS responses.
|
|
73
|
+
*
|
|
74
|
+
* **Common exposed headers**:
|
|
75
|
+
* - `X-Request-ID`: For request tracking
|
|
76
|
+
* - `X-RateLimit-*`: For rate limiting info
|
|
77
|
+
*
|
|
78
|
+
* @default []
|
|
79
|
+
*/
|
|
80
|
+
exposeHeaders?: string[];
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* HTTP integration configuration for Lambda endpoints.
|
|
84
|
+
*
|
|
85
|
+
* Defines how a Lambda function is exposed as an HTTP endpoint through
|
|
86
|
+
* API Gateway. Provides high-level configuration that maps to CDK constructs.
|
|
87
|
+
*/
|
|
88
|
+
export interface HttpIntegration {
|
|
89
|
+
/**
|
|
90
|
+
* HTTP method for the endpoint.
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```typescript
|
|
94
|
+
* method: 'POST' // For creating resources
|
|
95
|
+
* method: 'GET' // For retrieving data
|
|
96
|
+
* method: 'PUT' // For updating resources
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
method: HttpMethod;
|
|
100
|
+
/**
|
|
101
|
+
* URL path for the endpoint.
|
|
102
|
+
*
|
|
103
|
+
* **Path Parameters**: Use `{param}` syntax for dynamic segments
|
|
104
|
+
* **Examples**:
|
|
105
|
+
* - `/api/users`: Static path
|
|
106
|
+
* - `/api/users/{id}`: Path with parameter
|
|
107
|
+
* - `/api/users/{id}/orders/{orderId}`: Multiple parameters
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```typescript
|
|
111
|
+
* path: '/api/payments/charge'
|
|
112
|
+
* path: '/api/users/{userId}/payments'
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
path: string;
|
|
116
|
+
/**
|
|
117
|
+
* Authentication type for the endpoint.
|
|
118
|
+
*
|
|
119
|
+
* The framework automatically maps these to appropriate CDK authorizer configurations:
|
|
120
|
+
* - `none`: Public endpoint, no authentication
|
|
121
|
+
* - `jwt`: JWT token validation (requires token in Authorization header)
|
|
122
|
+
* - `iam`: AWS IAM signature validation (for service-to-service calls)
|
|
123
|
+
* - `cognito`: Cognito User Pool authorizer
|
|
124
|
+
* - `custom`: Custom Lambda authorizer function
|
|
125
|
+
*
|
|
126
|
+
* @default 'none'
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* ```typescript
|
|
130
|
+
* auth: 'jwt' // Requires valid JWT token
|
|
131
|
+
* auth: 'none' // Public endpoint
|
|
132
|
+
* auth: 'iam' // AWS service calls
|
|
133
|
+
* ```
|
|
134
|
+
*/
|
|
135
|
+
auth?: AuthType;
|
|
136
|
+
/**
|
|
137
|
+
* Enable CORS for the endpoint.
|
|
138
|
+
*
|
|
139
|
+
* **Simple CORS**: Set to `true` for default CORS configuration
|
|
140
|
+
* **Custom CORS**: Set to `true` and provide `corsConfig` for fine-grained control
|
|
141
|
+
*
|
|
142
|
+
* @default true
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* ```typescript
|
|
146
|
+
* cors: true // Enable with defaults
|
|
147
|
+
* ```
|
|
148
|
+
*/
|
|
149
|
+
cors?: boolean;
|
|
150
|
+
/**
|
|
151
|
+
* Detailed CORS configuration.
|
|
152
|
+
*
|
|
153
|
+
* **Required**: `cors` must be `true` for this to take effect
|
|
154
|
+
* **Optional**: If omitted, uses sensible defaults based on stage
|
|
155
|
+
*
|
|
156
|
+
* @see {@link CorsConfig}
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* ```typescript
|
|
160
|
+
* corsConfig: {
|
|
161
|
+
* allowOrigins: ['https://myapp.com'],
|
|
162
|
+
* allowMethods: ['GET', 'POST'],
|
|
163
|
+
* allowHeaders: ['Content-Type', 'Authorization'],
|
|
164
|
+
* allowCredentials: true,
|
|
165
|
+
* maxAge: 3600
|
|
166
|
+
* }
|
|
167
|
+
* ```
|
|
168
|
+
*/
|
|
169
|
+
corsConfig?: CorsConfig;
|
|
170
|
+
}
|
|
171
|
+
//# sourceMappingURL=http.types.d.ts.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime Web Core Types
|
|
3
|
+
*
|
|
4
|
+
* Barrel export for all Runtime Web Core type definitions.
|
|
5
|
+
* Organized by functional area for clean imports.
|
|
6
|
+
*/
|
|
7
|
+
export type { RuntimeWebConfig, TypeSafePurenowConfig, Stage, ServiceNames, LambdaIds, ValidServiceName, } from './config.types';
|
|
8
|
+
export { isValidServiceName } from './config.types';
|
|
9
|
+
export type { InfraOptions, AwsEnvironment, DomainConfig, VpcConfig } from './infra.types';
|
|
10
|
+
export type { MicroserviceDefinition, TiesInstance } from './microservice.types';
|
|
11
|
+
export type { LambdaDefinition, LambdaHandlerFactory, LambdaConfig } from './lambda.types';
|
|
12
|
+
export type { HttpIntegration, HttpMethod, AuthType, CorsConfig } from './http.types';
|
|
13
|
+
export type { EnvironmentContext, BrowserMetadata, LambdaMetadata, CDKMetadata, } from './runtime.types';
|
|
14
|
+
//# sourceMappingURL=index.d.ts.map
|