@fjall/deploy-core 0.89.2

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 (154) hide show
  1. package/LICENSE +21 -0
  2. package/dist/src/aws/AwsProvider.d.ts +39 -0
  3. package/dist/src/aws/AwsProvider.js +1 -0
  4. package/dist/src/aws/SimpleAwsProvider.d.ts +22 -0
  5. package/dist/src/aws/SimpleAwsProvider.js +73 -0
  6. package/dist/src/aws/index.d.ts +4 -0
  7. package/dist/src/aws/index.js +3 -0
  8. package/dist/src/aws/organisations/accounts.d.ts +21 -0
  9. package/dist/src/aws/organisations/accounts.js +99 -0
  10. package/dist/src/aws/organisations/backup.d.ts +12 -0
  11. package/dist/src/aws/organisations/backup.js +28 -0
  12. package/dist/src/aws/organisations/costAllocation.d.ts +12 -0
  13. package/dist/src/aws/organisations/costAllocation.js +26 -0
  14. package/dist/src/aws/organisations/identityCentre.d.ts +8 -0
  15. package/dist/src/aws/organisations/identityCentre.js +19 -0
  16. package/dist/src/aws/organisations/index.d.ts +16 -0
  17. package/dist/src/aws/organisations/index.js +12 -0
  18. package/dist/src/aws/organisations/ipam.d.ts +7 -0
  19. package/dist/src/aws/organisations/ipam.js +18 -0
  20. package/dist/src/aws/organisations/organisation.d.ts +12 -0
  21. package/dist/src/aws/organisations/organisation.js +94 -0
  22. package/dist/src/aws/organisations/organisationalUnits.d.ts +19 -0
  23. package/dist/src/aws/organisations/organisationalUnits.js +125 -0
  24. package/dist/src/aws/organisations/policies.d.ts +7 -0
  25. package/dist/src/aws/organisations/policies.js +36 -0
  26. package/dist/src/aws/organisations/ram.d.ts +7 -0
  27. package/dist/src/aws/organisations/ram.js +15 -0
  28. package/dist/src/aws/organisations/serviceAccess.d.ts +7 -0
  29. package/dist/src/aws/organisations/serviceAccess.js +38 -0
  30. package/dist/src/aws/organisations/trustedAccess.d.ts +7 -0
  31. package/dist/src/aws/organisations/trustedAccess.js +15 -0
  32. package/dist/src/aws/organisations/types.d.ts +29 -0
  33. package/dist/src/aws/organisations/types.js +16 -0
  34. package/dist/src/aws/utils/CloudFormationFailureAnalyser.d.ts +32 -0
  35. package/dist/src/aws/utils/CloudFormationFailureAnalyser.js +228 -0
  36. package/dist/src/aws/utils/cloudformationEvents.d.ts +98 -0
  37. package/dist/src/aws/utils/cloudformationEvents.js +596 -0
  38. package/dist/src/aws/utils/errors.d.ts +26 -0
  39. package/dist/src/aws/utils/errors.js +59 -0
  40. package/dist/src/aws/utils/regions.d.ts +1 -0
  41. package/dist/src/aws/utils/regions.js +1 -0
  42. package/dist/src/aws/utils/stackStatus.d.ts +23 -0
  43. package/dist/src/aws/utils/stackStatus.js +90 -0
  44. package/dist/src/index.d.ts +35 -0
  45. package/dist/src/index.js +45 -0
  46. package/dist/src/orchestration/applicationDeploy.d.ts +11 -0
  47. package/dist/src/orchestration/applicationDeploy.js +327 -0
  48. package/dist/src/orchestration/contextHelpers.d.ts +9 -0
  49. package/dist/src/orchestration/contextHelpers.js +14 -0
  50. package/dist/src/orchestration/deploy.d.ts +10 -0
  51. package/dist/src/orchestration/deploy.js +42 -0
  52. package/dist/src/orchestration/detectionPipeline.d.ts +23 -0
  53. package/dist/src/orchestration/detectionPipeline.js +65 -0
  54. package/dist/src/orchestration/dockerInterface.d.ts +56 -0
  55. package/dist/src/orchestration/dockerInterface.js +1 -0
  56. package/dist/src/orchestration/domainInterface.d.ts +37 -0
  57. package/dist/src/orchestration/domainInterface.js +1 -0
  58. package/dist/src/orchestration/index.d.ts +8 -0
  59. package/dist/src/orchestration/index.js +3 -0
  60. package/dist/src/orchestration/organisationDeploy.d.ts +16 -0
  61. package/dist/src/orchestration/organisationDeploy.js +382 -0
  62. package/dist/src/orchestration/organisationSetup.d.ts +42 -0
  63. package/dist/src/orchestration/organisationSetup.js +227 -0
  64. package/dist/src/orchestration/resolveOperation.d.ts +10 -0
  65. package/dist/src/orchestration/resolveOperation.js +53 -0
  66. package/dist/src/orchestration/serviceFactory.d.ts +15 -0
  67. package/dist/src/orchestration/serviceFactory.js +16 -0
  68. package/dist/src/services/application/ApplicationStackService.d.ts +93 -0
  69. package/dist/src/services/application/ApplicationStackService.js +436 -0
  70. package/dist/src/services/application/index.d.ts +1 -0
  71. package/dist/src/services/application/index.js +1 -0
  72. package/dist/src/services/infrastructure/CdkArgumentBuilder.d.ts +12 -0
  73. package/dist/src/services/infrastructure/CdkArgumentBuilder.js +67 -0
  74. package/dist/src/services/infrastructure/CdkCommandRunner.d.ts +30 -0
  75. package/dist/src/services/infrastructure/CdkCommandRunner.js +241 -0
  76. package/dist/src/services/infrastructure/CdkErrorFormatter.d.ts +4 -0
  77. package/dist/src/services/infrastructure/CdkErrorFormatter.js +194 -0
  78. package/dist/src/services/infrastructure/CdkEventMonitoring.d.ts +19 -0
  79. package/dist/src/services/infrastructure/CdkEventMonitoring.js +41 -0
  80. package/dist/src/services/infrastructure/CdkOutputAnalyser.d.ts +43 -0
  81. package/dist/src/services/infrastructure/CdkOutputAnalyser.js +125 -0
  82. package/dist/src/services/infrastructure/CdkOutputParser.d.ts +8 -0
  83. package/dist/src/services/infrastructure/CdkOutputParser.js +33 -0
  84. package/dist/src/services/infrastructure/CdkProcessManager.d.ts +20 -0
  85. package/dist/src/services/infrastructure/CdkProcessManager.js +244 -0
  86. package/dist/src/services/infrastructure/CdkService.d.ts +71 -0
  87. package/dist/src/services/infrastructure/CdkService.js +254 -0
  88. package/dist/src/services/infrastructure/CloudFormationService.d.ts +79 -0
  89. package/dist/src/services/infrastructure/CloudFormationService.js +249 -0
  90. package/dist/src/services/infrastructure/index.d.ts +8 -0
  91. package/dist/src/services/infrastructure/index.js +7 -0
  92. package/dist/src/services/supporting/CdkContextBuilder.d.ts +49 -0
  93. package/dist/src/services/supporting/CdkContextBuilder.js +44 -0
  94. package/dist/src/services/supporting/TemplateHashService.d.ts +67 -0
  95. package/dist/src/services/supporting/TemplateHashService.js +152 -0
  96. package/dist/src/services/supporting/helpers.d.ts +46 -0
  97. package/dist/src/services/supporting/helpers.js +81 -0
  98. package/dist/src/services/supporting/index.d.ts +3 -0
  99. package/dist/src/services/supporting/index.js +3 -0
  100. package/dist/src/types/FjallState.d.ts +50 -0
  101. package/dist/src/types/FjallState.js +118 -0
  102. package/dist/src/types/ProgressEvent.d.ts +35 -0
  103. package/dist/src/types/ProgressEvent.js +48 -0
  104. package/dist/src/types/apiClient.d.ts +34 -0
  105. package/dist/src/types/apiClient.js +1 -0
  106. package/dist/src/types/application/ApplicationServiceTypes.d.ts +56 -0
  107. package/dist/src/types/application/ApplicationServiceTypes.js +30 -0
  108. package/dist/src/types/application/index.d.ts +1 -0
  109. package/dist/src/types/application/index.js +1 -0
  110. package/dist/src/types/callbacks.d.ts +36 -0
  111. package/dist/src/types/callbacks.js +1 -0
  112. package/dist/src/types/constants.d.ts +6 -0
  113. package/dist/src/types/constants.js +6 -0
  114. package/dist/src/types/credentials.d.ts +30 -0
  115. package/dist/src/types/credentials.js +1 -0
  116. package/dist/src/types/deployment/DeploymentServiceTypes.d.ts +23 -0
  117. package/dist/src/types/deployment/DeploymentServiceTypes.js +1 -0
  118. package/dist/src/types/deployment/DeploymentTypes.d.ts +29 -0
  119. package/dist/src/types/deployment/DeploymentTypes.js +1 -0
  120. package/dist/src/types/deployment/cloudformation.d.ts +14 -0
  121. package/dist/src/types/deployment/cloudformation.js +1 -0
  122. package/dist/src/types/deployment/index.d.ts +5 -0
  123. package/dist/src/types/deployment/index.js +1 -0
  124. package/dist/src/types/deployment/parallel.d.ts +46 -0
  125. package/dist/src/types/deployment/parallel.js +10 -0
  126. package/dist/src/types/errors/CdkError.d.ts +14 -0
  127. package/dist/src/types/errors/CdkError.js +20 -0
  128. package/dist/src/types/errors/ServiceError.d.ts +86 -0
  129. package/dist/src/types/errors/ServiceError.js +119 -0
  130. package/dist/src/types/events.d.ts +40 -0
  131. package/dist/src/types/events.js +5 -0
  132. package/dist/src/types/index.d.ts +20 -0
  133. package/dist/src/types/index.js +9 -0
  134. package/dist/src/types/operations.d.ts +193 -0
  135. package/dist/src/types/operations.js +285 -0
  136. package/dist/src/types/orgConfig.d.ts +28 -0
  137. package/dist/src/types/orgConfig.js +11 -0
  138. package/dist/src/types/params.d.ts +74 -0
  139. package/dist/src/types/params.js +1 -0
  140. package/dist/src/types/patternDetection.d.ts +43 -0
  141. package/dist/src/types/patternDetection.js +92 -0
  142. package/dist/src/types/validation.d.ts +12 -0
  143. package/dist/src/types/validation.js +1 -0
  144. package/dist/src/util/fsHelpers.d.ts +4 -0
  145. package/dist/src/util/fsHelpers.js +16 -0
  146. package/dist/src/util/index.d.ts +3 -0
  147. package/dist/src/util/index.js +3 -0
  148. package/dist/src/util/securityHelpers.d.ts +31 -0
  149. package/dist/src/util/securityHelpers.js +124 -0
  150. package/dist/src/util/singleton.d.ts +2 -0
  151. package/dist/src/util/singleton.js +9 -0
  152. package/dist/src/util/sleep.d.ts +4 -0
  153. package/dist/src/util/sleep.js +4 -0
  154. package/package.json +42 -0
@@ -0,0 +1,124 @@
1
+ /**
2
+ * Security helpers for spawn operations
3
+ *
4
+ * Provides environment variable filtering and credential masking
5
+ * to prevent command injection and credential leakage.
6
+ */
7
+ /**
8
+ * Environment variables that MUST NOT be passed from user input to spawned processes.
9
+ * These can be exploited for:
10
+ * - Code execution hijacking (PATH, NODE_OPTIONS)
11
+ * - Dynamic linker injection (LD_PRELOAD, DYLD_INSERT_LIBRARIES)
12
+ * - Interpreter code injection (PYTHONPATH, RUBYLIB)
13
+ * - Credential/identity hijacking (HOME, AWS_CONFIG_FILE)
14
+ * - Shell injection (BASH_ENV, ENV)
15
+ */
16
+ export const DANGEROUS_ENV_VARS = new Set([
17
+ // Execution hijacking
18
+ // NOTE: PATH is intentionally NOT included here - it's required for spawn() to find executables
19
+ // See: aiDocs/patterns/spawn-security-pattern.md for rationale
20
+ "NODE_OPTIONS",
21
+ "NODE_PATH",
22
+ "NODE_EXTRA_CA_CERTS",
23
+ "NODE_DEBUG",
24
+ "NODE_PRESERVE_SYMLINKS",
25
+ // Dynamic linker injection (Linux)
26
+ "LD_PRELOAD",
27
+ "LD_LIBRARY_PATH",
28
+ "LD_AUDIT",
29
+ "LD_BIND_NOW",
30
+ // Dynamic linker injection (macOS)
31
+ "DYLD_INSERT_LIBRARIES",
32
+ "DYLD_LIBRARY_PATH",
33
+ "DYLD_FRAMEWORK_PATH",
34
+ // Interpreter code injection
35
+ "PYTHONPATH",
36
+ "PYTHONSTARTUP",
37
+ "PERL5LIB",
38
+ "PERL5OPT",
39
+ "RUBYLIB",
40
+ "RUBYOPT",
41
+ // Credential/identity hijacking
42
+ "HOME",
43
+ "XDG_CONFIG_HOME",
44
+ "AWS_SHARED_CREDENTIALS_FILE",
45
+ "AWS_CONFIG_FILE",
46
+ // Shell injection
47
+ "SHELL",
48
+ "BASH_ENV",
49
+ "ENV",
50
+ "ZDOTDIR"
51
+ ]);
52
+ /**
53
+ * Filter dangerous environment variables from a record.
54
+ * Returns a new object with only safe environment variables.
55
+ */
56
+ export function filterDangerousEnvVars(env) {
57
+ return Object.fromEntries(Object.entries(env).filter(([key]) => !DANGEROUS_ENV_VARS.has(key.toUpperCase())));
58
+ }
59
+ /**
60
+ * Mask sensitive information in output strings to prevent credential leakage.
61
+ * Patterns: postgres://user:pass@host, password=xxx, secret=xxx, apikey=xxx
62
+ */
63
+ export function maskSensitiveOutput(output) {
64
+ return (output
65
+ // Mask postgres/mysql connection strings with credentials
66
+ .replace(/(\w+:\/\/[^:]+:)[^@]+(@)/gi, "$1***$2")
67
+ // Mask common credential patterns
68
+ .replace(/(password|passwd|secret|api[_-]?key|token|auth|credential)[=:]["']?[^\s"']+/gi, "$1=***")
69
+ // Mask GitHub tokens (ghu_, ghs_, ghp_, github_pat_) appearing as bare values
70
+ .replace(/\b(ghu_|ghs_|ghp_|github_pat_)[A-Za-z0-9_]+/g, "***")
71
+ // Mask AWS secret access keys (40 chars, base64-ish) — only when preceded
72
+ // by a known credential context to avoid false-positive masking of ARNs,
73
+ // physical resource IDs, and other legitimate 40-char strings.
74
+ .replace(/(?<=AWS_SECRET_ACCESS_KEY=|SecretAccessKey[=:]\s*|"secretAccessKey":\s*")[A-Za-z0-9/+=]{40}/g, "***"));
75
+ }
76
+ /**
77
+ * Parse a shell command string into an array of arguments.
78
+ * Handles single quotes, double quotes, and escaped characters.
79
+ */
80
+ export function parseShellArgs(command) {
81
+ const args = [];
82
+ let current = "";
83
+ let inSingleQuote = false;
84
+ let inDoubleQuote = false;
85
+ let escaped = false;
86
+ for (const char of command) {
87
+ if (escaped) {
88
+ current += char;
89
+ escaped = false;
90
+ continue;
91
+ }
92
+ if (char === "\\") {
93
+ escaped = true;
94
+ continue;
95
+ }
96
+ if (char === "'" && !inDoubleQuote) {
97
+ inSingleQuote = !inSingleQuote;
98
+ continue;
99
+ }
100
+ if (char === '"' && !inSingleQuote) {
101
+ inDoubleQuote = !inDoubleQuote;
102
+ continue;
103
+ }
104
+ if (char === " " && !inSingleQuote && !inDoubleQuote) {
105
+ if (current) {
106
+ args.push(current);
107
+ current = "";
108
+ }
109
+ continue;
110
+ }
111
+ current += char;
112
+ }
113
+ if (inSingleQuote || inDoubleQuote) {
114
+ // Unbalanced quotes — include the partial token. Callers should validate
115
+ // their input if quote-balancing is required.
116
+ if (current) {
117
+ args.push(current);
118
+ }
119
+ }
120
+ else if (current) {
121
+ args.push(current);
122
+ }
123
+ return args;
124
+ }
@@ -0,0 +1,2 @@
1
+ /** Lazily creates one instance per factory — shared singleton helper. */
2
+ export declare function singleton<T>(factory: () => T): () => T;
@@ -0,0 +1,9 @@
1
+ /** Lazily creates one instance per factory — shared singleton helper. */
2
+ export function singleton(factory) {
3
+ let instance;
4
+ return () => {
5
+ if (instance === undefined)
6
+ instance = factory();
7
+ return instance;
8
+ };
9
+ }
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Delay execution for the given number of milliseconds.
3
+ */
4
+ export declare const sleep: (ms: number) => Promise<void>;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Delay execution for the given number of milliseconds.
3
+ */
4
+ export const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@fjall/deploy-core",
3
+ "version": "0.89.2",
4
+ "description": "Shared deployment engine for Fjall — used by CLI and webapp worker",
5
+ "type": "module",
6
+ "main": "dist/src/index.js",
7
+ "types": "dist/src/index.d.ts",
8
+ "files": [
9
+ "dist/"
10
+ ],
11
+ "scripts": {
12
+ "clean": "rm -rf ./dist",
13
+ "build": "npm run clean && tsc",
14
+ "typecheck": "tsc --noEmit",
15
+ "test": "vitest run",
16
+ "test:watch": "vitest",
17
+ "format": "prettier --write \"src/**/*.ts\"",
18
+ "format:check": "prettier --check \"src/**/*.ts\"",
19
+ "lint": "eslint src/"
20
+ },
21
+ "engines": {
22
+ "node": ">=18.0.0"
23
+ },
24
+ "license": "MIT",
25
+ "dependencies": {
26
+ "@aws-sdk/client-backup": "^3.1009.0",
27
+ "@aws-sdk/client-cloudformation": "^3.1009.0",
28
+ "@aws-sdk/client-cost-explorer": "^3.1009.0",
29
+ "@aws-sdk/client-ec2": "^3.1009.0",
30
+ "@aws-sdk/client-organizations": "^3.1009.0",
31
+ "@aws-sdk/client-ram": "^3.1009.0",
32
+ "@aws-sdk/client-sso-admin": "^3.1009.0",
33
+ "@aws-sdk/client-sts": "^3.1009.0",
34
+ "@fjall/generator": "^0.89.2",
35
+ "@fjall/util": "^0.89.2",
36
+ "zod": "^4.3.6"
37
+ },
38
+ "devDependencies": {
39
+ "vitest": "^3.2.3"
40
+ },
41
+ "gitHead": "5bb039ff669fbe96d656ae1467e9986cf4327e92"
42
+ }