@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.
Files changed (68) hide show
  1. package/LICENSE +101 -0
  2. package/README.md +495 -0
  3. package/out/dist/bin/index.js +212 -0
  4. package/out/dist/bin/purenow.js +218 -0
  5. package/out/dist/bin/templates/runtime-web/cdk/.gitignore.template +25 -0
  6. package/out/dist/bin/templates/runtime-web/cdk/README.md.template +267 -0
  7. package/out/dist/bin/templates/runtime-web/cdk/bin/app.ts.template +173 -0
  8. package/out/dist/bin/templates/runtime-web/cdk/cdk.json.template +79 -0
  9. package/out/dist/bin/templates/runtime-web/cdk/package.json.template +28 -0
  10. package/out/dist/bin/templates/runtime-web/cdk/tsconfig.json.template +38 -0
  11. package/out/dist/bin/templates/runtime-web/purenow-basic/.env.example +15 -0
  12. package/out/dist/bin/templates/runtime-web/purenow-basic/README.md +118 -0
  13. package/out/dist/bin/templates/runtime-web/purenow-basic/gitignore.template +64 -0
  14. package/out/dist/bin/templates/runtime-web/purenow-basic/package.json +34 -0
  15. package/out/dist/bin/templates/runtime-web/purenow-basic/purenow.config.ts +105 -0
  16. package/out/dist/bin/templates/runtime-web/purenow-basic/src/app.tsx +35 -0
  17. package/out/dist/bin/templates/runtime-web/purenow-basic/src/handlers/users/index.ts +17 -0
  18. package/out/dist/bin/templates/runtime-web/purenow-basic/src/handlers/users/users.handlers.ts +222 -0
  19. package/out/dist/bin/templates/runtime-web/purenow-basic/src/index.tsx +71 -0
  20. package/out/dist/bin/templates/runtime-web/purenow-basic/src/pages/about-page.tsx +65 -0
  21. package/out/dist/bin/templates/runtime-web/purenow-basic/src/pages/home-page.tsx +55 -0
  22. package/out/dist/bin/templates/runtime-web/purenow-basic/src/pages/users-page.tsx +66 -0
  23. package/out/dist/bin/templates/runtime-web/purenow-basic/src/routes.tsx +61 -0
  24. package/out/dist/bin/templates/runtime-web/purenow-basic/src/services/index.ts +17 -0
  25. package/out/dist/bin/templates/runtime-web/purenow-basic/src/services/users.service.ts +133 -0
  26. package/out/dist/bin/templates/runtime-web/purenow-basic/src/ties/index.ts +17 -0
  27. package/out/dist/bin/templates/runtime-web/purenow-basic/src/ties/users.ties.ts +53 -0
  28. package/out/dist/bin/templates/runtime-web/purenow-basic/tsconfig.json +53 -0
  29. package/out/dist/lib/index.d.ts +4 -0
  30. package/out/dist/lib/index.js +4 -0
  31. package/out/dist/lib/lib/index.d.ts +3 -0
  32. package/out/dist/lib/lib/runtime-web/index.d.ts +17 -0
  33. package/out/dist/lib/lib/runtime-web/pipelines/browser-pipeline.d.ts +110 -0
  34. package/out/dist/lib/lib/runtime-web/pipelines/index.d.ts +2 -0
  35. package/out/dist/lib/lib/runtime-web/pureweb.d.ts +65 -0
  36. package/out/dist/lib/lib/runtime-web/types/config.types.d.ts +301 -0
  37. package/out/dist/lib/lib/runtime-web/types/http.types.d.ts +171 -0
  38. package/out/dist/lib/lib/runtime-web/types/index.d.ts +14 -0
  39. package/out/dist/lib/lib/runtime-web/types/infra.types.d.ts +225 -0
  40. package/out/dist/lib/lib/runtime-web/types/lambda.types.d.ts +175 -0
  41. package/out/dist/lib/lib/runtime-web/types/microservice.types.d.ts +70 -0
  42. package/out/dist/lib/lib/runtime-web/types/runtime.types.d.ts +55 -0
  43. package/out/dist/lib/utils/index.d.ts +2 -0
  44. package/out/dist/lib/utils/types/index.d.ts +3 -0
  45. package/out/dist/lib/utils/types/runtime.config.types.d.ts +71 -0
  46. package/out/dist/src/bin/index.d.ts +5 -0
  47. package/out/dist/src/bin/index.unix.d.ts +5 -0
  48. package/out/dist/src/bin/purenow-runtime-cli.d.ts +31 -0
  49. package/out/dist/src/bin/services/index.d.ts +8 -0
  50. package/out/dist/src/bin/services/purenow-runtime-deployment.strategy.d.ts +37 -0
  51. package/out/dist/src/bin/services/purenow-runtime-stacks-deploy.service.d.ts +58 -0
  52. package/out/dist/src/bin/services/purenow-runtime-stacks-deploy.service.types.d.ts +18 -0
  53. package/out/dist/src/bin/services/runtime-web-cli-extensions.d.ts +2 -0
  54. package/out/dist/src/bin/services/template.service.d.ts +53 -0
  55. package/out/dist/src/bin/services/utils/index.d.ts +2 -0
  56. package/out/dist/src/bin/utils/errors.d.ts +68 -0
  57. package/out/dist/src/lib/runtime-web/index.d.ts +17 -0
  58. package/out/dist/src/lib/runtime-web/pipelines/browser-pipeline.d.ts +110 -0
  59. package/out/dist/src/lib/runtime-web/pipelines/index.d.ts +2 -0
  60. package/out/dist/src/lib/runtime-web/pureweb.d.ts +65 -0
  61. package/out/dist/src/lib/runtime-web/types/config.types.d.ts +301 -0
  62. package/out/dist/src/lib/runtime-web/types/http.types.d.ts +171 -0
  63. package/out/dist/src/lib/runtime-web/types/index.d.ts +14 -0
  64. package/out/dist/src/lib/runtime-web/types/infra.types.d.ts +225 -0
  65. package/out/dist/src/lib/runtime-web/types/lambda.types.d.ts +175 -0
  66. package/out/dist/src/lib/runtime-web/types/microservice.types.d.ts +70 -0
  67. package/out/dist/src/lib/runtime-web/types/runtime.types.d.ts +55 -0
  68. package/package.json +133 -0
@@ -0,0 +1,37 @@
1
+ import { DeploymentStrategy, PurenowCliContext } from '@worktif/purenow/bin';
2
+ import { PurenowRuntimeStacksDeployService } from './purenow-runtime-stacks-deploy.service';
3
+ /**
4
+ * Represents the runtime context for the Purenow CLI, extending the base Purenow CLI context
5
+ * with additional properties specific to the runtime environment.
6
+ */
7
+ export interface PurenowRuntimeCliContext extends PurenowCliContext {
8
+ stacksDeployService: PurenowRuntimeStacksDeployService;
9
+ }
10
+ /**
11
+ * Runtime deployment strategy that implements Runtime Target deployment
12
+ *
13
+ * This strategy extends purenow's two-stack deployment to support three stacks:
14
+ * 1. Infrastructure Stack (existing)
15
+ * 2. Runtime Stack (existing)
16
+ * 3. Additional Runtime Stack (new)
17
+ */
18
+ export declare class RuntimeDeploymentStrategy implements DeploymentStrategy {
19
+ readonly role = "deployment";
20
+ readonly name = "runtime-purenow-runtime-stacks";
21
+ /**
22
+ * Pre-deployment validation for runtime-specific requirements
23
+ */
24
+ validateDeployment<T extends PurenowCliContext = PurenowCliContext>(context: T): Promise<boolean>;
25
+ /**
26
+ * Execute Runtime Target deployment instead of two stacks
27
+ */
28
+ executeDeployment<T extends PurenowCliContext = PurenowCliContext>(context: T, config: unknown): Promise<void>;
29
+ /**
30
+ * Post-deployment actions for runtime-specific tasks
31
+ */
32
+ postDeployment(result: {
33
+ success: boolean;
34
+ error?: unknown;
35
+ }): Promise<void>;
36
+ }
37
+ //# sourceMappingURL=purenow-runtime-deployment.strategy.d.ts.map
@@ -0,0 +1,58 @@
1
+ import { PurenowInfraResourceOptions, PurenowInfraResources } from '@worktif/purenow/infra';
2
+ import { type DeploymentOutputs, StacksDeployOptions, StacksDeployService } from '@worktif/purenow/bin';
3
+ import { PurenowRuntimeStacksDeployResult } from './purenow-runtime-stacks-deploy.service.types';
4
+ export declare class PurenowRuntimeStacksDeployService extends StacksDeployService implements PurenowInfraResources {
5
+ protected readonly cwd: string;
6
+ protected readonly DEFAULT_CDK_DIR = "cdk";
7
+ /**
8
+ * Creates a new TwoStackDeployService instance.
9
+ *
10
+ * @param cwd - Current working directory (project root)
11
+ */
12
+ constructor(cwd?: string);
13
+ /**
14
+ * Executes first deployment workflow: deploy Infra → read outputs → deploy Runtime.
15
+ *
16
+ * @param options - Deployment options
17
+ * @param startTime - Deployment start timestamp
18
+ * @returns Promise that resolves to deployment result
19
+ * @throws {DeploymentError} If Infra or Runtime deployment fails
20
+ *
21
+ * @todo: complete extensible deployment approach with duration metric attendance
22
+ *
23
+ * @private
24
+ */
25
+ protected executeDeploy<T extends PurenowRuntimeStacksDeployResult = PurenowRuntimeStacksDeployResult>(options: StacksDeployOptions, startTime: number): Promise<T>;
26
+ /**
27
+ * Parses deployment outputs from CDK outputs file.
28
+ *
29
+ * @param stackName - Name of the CloudFormation stack
30
+ * @returns Deployment outputs map
31
+ *
32
+ * @important: OPTIMISE THIS SOLUTION
33
+ *
34
+ * @private
35
+ * @param outputsPath
36
+ */
37
+ protected parseStackOutputs(stackName: string, outputsPath: string): DeploymentOutputs;
38
+ /**
39
+ * Generates a signature for the provided region by extracting the first character of each segment in the region string, delimited by hyphens.
40
+ *
41
+ * @param {string} region - The region string to generate the signature from. It is expected to be a hyphen-separated string.
42
+ * @return {string} The generated region signature, formed by concatenating the first character of each valid segment. Returns an empty string if the input is invalid or empty.
43
+ */
44
+ protected getRegionSignature(region: string): string;
45
+ /**
46
+ * Generates a resource name by concatenating service name, resource name,
47
+ * simplified region, and stage with hyphens as separators.
48
+ *
49
+ * @param {Object} params - An object containing the required parameters.
50
+ * @param {string} params.name - The name of the resource.
51
+ * @param {string} params.serviceName - The name of the service associated with the resource.
52
+ * @param {string} params.regionSimplified - The simplified region identifier.
53
+ * @param {string} params.stage - The deployment stage of the resource.
54
+ * @returns {string} The concatenated resource name.
55
+ */
56
+ resourceName({ name, serviceName, stage, region }: PurenowInfraResourceOptions): string;
57
+ }
58
+ //# sourceMappingURL=purenow-runtime-stacks-deploy.service.d.ts.map
@@ -0,0 +1,18 @@
1
+ import 'reflect-metadata';
2
+ import { type DeploymentResult, StacksDeployResult, DeploymentOutputs } from '@worktif/purenow/bin';
3
+ /**
4
+ * Represents the result of deploying runtime stacks in the Purenow system.
5
+ * This type extends the StacksDeployResult, adding a specific result for the runtime stack deployment.
6
+ *
7
+ * Properties:
8
+ * - runtimeStack: Provides the deployment result specific to the runtime stack, containing details and status of the runtime stack deployment process.
9
+ *
10
+ * Use this type to encapsulate and manage results related to both general stack deployments and specific runtime stack deployments.
11
+ */
12
+ export type PurenowRuntimeStacksDeployResult = StacksDeployResult & {
13
+ runtimeStack: DeploymentResult;
14
+ };
15
+ export type PurenowRuntimeDeploymentOutputs = DeploymentOutputs & {
16
+ lambdaArnList: string[];
17
+ };
18
+ //# sourceMappingURL=purenow-runtime-stacks-deploy.service.types.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=runtime-web-cli-extensions.d.ts.map
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Options for scaffolding a new project
3
+ */
4
+ export interface ScaffoldOptions {
5
+ /** Project name */
6
+ projectName: string;
7
+ /** Force overwrite existing files */
8
+ force: boolean;
9
+ }
10
+ /**
11
+ * Template variable substitution context
12
+ */
13
+ export interface TemplateContext {
14
+ projectName: string;
15
+ [key: string]: string;
16
+ }
17
+ /**
18
+ * Service for project scaffolding and template management
19
+ */
20
+ export declare class TemplateService {
21
+ private cwd;
22
+ private readonly templatesDir;
23
+ constructor(cwd?: string);
24
+ /**
25
+ * Scaffold a new project from a template
26
+ */
27
+ scaffold(templateName: string, targetDir: string, options: ScaffoldOptions, coreDir?: string): Promise<void>;
28
+ /**
29
+ * Generate purenow.config.ts file
30
+ */
31
+ generateConfig(targetDir: string, projectName: string): Promise<void>;
32
+ /**
33
+ * Generate tsconfig.json file
34
+ */
35
+ generateTsConfig(targetDir: string): Promise<void>;
36
+ /**
37
+ * Validate target directory
38
+ */
39
+ private validateTargetDirectory;
40
+ /**
41
+ * Check if CDK directory already exists
42
+ */
43
+ cdkDirectoryExists(cwd?: string): boolean;
44
+ /**
45
+ * Copy template files recursively with variable substitution
46
+ */
47
+ private copyTemplateFiles;
48
+ /**
49
+ * Substitute template variables in content
50
+ */
51
+ private substituteVariables;
52
+ }
53
+ //# sourceMappingURL=template.service.d.ts.map
@@ -0,0 +1,2 @@
1
+ export declare function buildStaticHtml(shouldExit?: boolean): void;
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Base error class for all Runtime CLI errors
3
+ * Follows purenow error patterns without emoji
4
+ */
5
+ export declare class RuntimeCliError extends Error {
6
+ readonly code: string;
7
+ readonly hint?: string | undefined;
8
+ constructor(message: string, code: string, hint?: string | undefined);
9
+ }
10
+ /**
11
+ * Error thrown when runtime configuration is invalid or missing
12
+ * Extends purenow ConfigError pattern
13
+ */
14
+ export declare class RuntimeConfigError extends RuntimeCliError {
15
+ constructor(message: string, hint?: string);
16
+ }
17
+ /**
18
+ * Error thrown when runtime build operations fail
19
+ * Extends purenow BuildError pattern
20
+ */
21
+ export declare class RuntimeBuildError extends RuntimeCliError {
22
+ constructor(message: string, hint?: string);
23
+ }
24
+ /**
25
+ * Error thrown when runtime deployment operations fail
26
+ * Extends purenow DeploymentError pattern
27
+ */
28
+ export declare class RuntimeDeploymentError extends RuntimeCliError {
29
+ constructor(message: string, hint?: string);
30
+ }
31
+ /**
32
+ * Error thrown when runtime validation checks fail
33
+ * Extends purenow ValidationError pattern
34
+ */
35
+ export declare class RuntimeValidationError extends RuntimeCliError {
36
+ constructor(message: string, hint?: string);
37
+ }
38
+ /**
39
+ * Friendly error formatter for runtime workspace
40
+ * Follows purenow FriendlyErrorFormatter pattern without emoji
41
+ */
42
+ export declare class RuntimeFriendlyErrorFormatter {
43
+ /**
44
+ * Format error as human-readable message without emoji
45
+ */
46
+ formatError(error: Error, verbose?: boolean): string;
47
+ /**
48
+ * Format validation error without emoji
49
+ */
50
+ formatValidationError(fieldName: string, message: string, verbose?: boolean): string;
51
+ /**
52
+ * Format deployment error without emoji
53
+ */
54
+ formatDeploymentError(stackName: string, operation: string, message: string, verbose?: boolean): string;
55
+ }
56
+ /**
57
+ * Structured logger for runtime workspace
58
+ * Follows purenow logging patterns without emoji
59
+ */
60
+ export declare class RuntimeStructuredLogger {
61
+ private verbose;
62
+ constructor(verbose?: boolean);
63
+ info(message: string, metadata?: Record<string, any>): void;
64
+ warn(message: string, metadata?: Record<string, any>): void;
65
+ error(message: string, metadata?: Record<string, any>): void;
66
+ debug(message: string, metadata?: Record<string, any>): void;
67
+ }
68
+ //# sourceMappingURL=errors.d.ts.map
@@ -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,2 @@
1
+ export { BrowserPipeline } from './browser-pipeline';
2
+ //# sourceMappingURL=index.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