@stacksjs/ts-cloud 0.9.2 → 0.9.4

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 (191) hide show
  1. package/dist/aws/index.js +1 -269
  2. package/dist/bin/chunk-00kg80qg.js +1 -0
  3. package/dist/bin/chunk-09nwf2gy.js +34 -0
  4. package/dist/bin/chunk-1k5kszjp.js +111 -0
  5. package/dist/bin/chunk-21e0mavm.js +1 -0
  6. package/dist/bin/chunk-271gk1n2.js +6 -0
  7. package/dist/bin/chunk-2empps47.js +2 -0
  8. package/dist/bin/chunk-38pq971s.js +2 -0
  9. package/dist/bin/chunk-3gykfyq4.js +37 -0
  10. package/dist/bin/chunk-3vqfexc4.js +70 -0
  11. package/dist/bin/chunk-4vrqm9h0.js +2 -0
  12. package/dist/bin/chunk-598yf4bs.js +1 -0
  13. package/dist/bin/chunk-5ectjq0b.js +1 -0
  14. package/dist/bin/chunk-5erkxpt7.js +512 -0
  15. package/dist/bin/chunk-5mrtzemj.js +1 -0
  16. package/dist/bin/chunk-5n9fmabb.js +1 -0
  17. package/dist/bin/chunk-9knpg30y.js +1 -0
  18. package/dist/bin/chunk-9pvsff8g.js +1 -0
  19. package/dist/bin/chunk-ax9mr6wm.js +44 -0
  20. package/dist/bin/chunk-axhnkn5g.js +2 -0
  21. package/dist/bin/chunk-c1vcdgvr.js +1 -0
  22. package/dist/bin/chunk-ctd2vg9w.js +2 -0
  23. package/dist/bin/chunk-dbgffky8.js +1 -0
  24. package/dist/bin/chunk-ddk4rt4j.js +6 -0
  25. package/dist/bin/chunk-dwr30vbv.js +1 -0
  26. package/dist/bin/chunk-e0rkrq70.js +1 -0
  27. package/dist/bin/chunk-e3xrwh9z.js +1 -0
  28. package/dist/bin/chunk-etrb03mt.js +1507 -0
  29. package/dist/bin/chunk-fhc6ntvd.js +2 -0
  30. package/dist/bin/chunk-fpm59y25.js +6 -0
  31. package/dist/bin/chunk-fvbxvq6b.js +1 -0
  32. package/dist/bin/chunk-fy8j3y8p.js +92 -0
  33. package/dist/bin/chunk-fz21b57w.js +1 -0
  34. package/dist/bin/chunk-gavvf0pg.js +141 -0
  35. package/dist/bin/chunk-ggn7ax8p.js +4 -0
  36. package/dist/bin/chunk-gpe2prkm.js +1 -0
  37. package/dist/bin/chunk-h5pa5men.js +2 -0
  38. package/dist/bin/chunk-hm08xdxf.js +2 -0
  39. package/dist/bin/chunk-hzgz13nf.js +1 -0
  40. package/dist/bin/chunk-j703btc5.js +50 -0
  41. package/dist/bin/chunk-k9t9wvms.js +1 -0
  42. package/dist/bin/chunk-m669wtgr.js +1 -0
  43. package/dist/bin/chunk-m7dgskt1.js +1 -0
  44. package/dist/bin/chunk-mh0kdzqp.js +2 -0
  45. package/dist/bin/chunk-mr0atd2s.js +2 -0
  46. package/dist/bin/chunk-mz0wbbsj.js +3 -0
  47. package/dist/bin/chunk-ngcyftm2.js +1 -0
  48. package/dist/bin/chunk-p66ptpmr.js +2 -0
  49. package/dist/bin/chunk-qk9qgepa.js +1 -0
  50. package/dist/bin/chunk-rxcvf10f.js +7364 -0
  51. package/dist/bin/chunk-rytk89az.js +60 -0
  52. package/dist/bin/chunk-tga3hhwk.js +6 -0
  53. package/dist/bin/chunk-tx0tqq2k.js +8 -0
  54. package/dist/bin/chunk-vek8a0w6.js +1 -0
  55. package/dist/bin/chunk-vm3q5gf2.js +3 -0
  56. package/dist/bin/chunk-y7s5r8y6.js +3 -0
  57. package/dist/bin/chunk-yv9sth30.js +1 -0
  58. package/dist/bin/chunk-zmegvjp8.js +581 -0
  59. package/dist/bin/cli.js +417 -10597
  60. package/dist/bin/dashboard-server.js +1 -6998
  61. package/dist/chunk-0ccta6z6.js +6 -0
  62. package/dist/chunk-0k1cs6pp.js +1 -0
  63. package/dist/chunk-1egjn203.js +704 -0
  64. package/dist/chunk-2wx29qga.js +5 -0
  65. package/dist/chunk-5m5rqmv7.js +1 -0
  66. package/dist/chunk-8ea5022g.js +114 -0
  67. package/dist/chunk-8xqn3c0w.js +2 -0
  68. package/dist/chunk-b4esxhmw.js +2 -0
  69. package/dist/chunk-b8e5wzwn.js +44 -0
  70. package/dist/chunk-bggt4n6e.js +2 -0
  71. package/dist/chunk-cwkg37rs.js +37 -0
  72. package/dist/chunk-dskvqt67.js +7355 -0
  73. package/dist/chunk-gahsdmxf.js +1617 -0
  74. package/dist/chunk-gnv3r2jg.js +1 -0
  75. package/dist/chunk-hg3c48cp.js +34 -0
  76. package/dist/chunk-m5azeva3.js +2 -0
  77. package/dist/chunk-r3qf56b3.js +92 -0
  78. package/dist/chunk-sdqa9ghv.js +141 -0
  79. package/dist/chunk-svrvvcm7.js +1 -0
  80. package/dist/chunk-v0p3hpc3.js +60 -0
  81. package/dist/chunk-wdzjbecg.js +50 -0
  82. package/dist/chunk-ww8k3g7j.js +1 -0
  83. package/dist/chunk-xmqfc62w.js +1 -0
  84. package/dist/chunk-xrebj679.js +435 -0
  85. package/dist/chunk-xt3s24vr.js +2 -0
  86. package/dist/chunk-y21zk0pn.js +4 -0
  87. package/dist/deploy/attach-credentials.d.ts +57 -0
  88. package/dist/deploy/index.js +1 -168
  89. package/dist/deploy/site-ports.d.ts +151 -0
  90. package/dist/deploy/site-target.d.ts +24 -1
  91. package/dist/dns/index.js +1 -41
  92. package/dist/drivers/index.js +1 -154
  93. package/dist/index.js +100 -6129
  94. package/dist/protection/index.js +1 -89
  95. package/dist/push/index.js +1 -509
  96. package/dist/spend/index.js +1 -173
  97. package/dist/ui/404.html +16 -548
  98. package/dist/ui/_stx/chunk.5ddb5087.js +90 -0
  99. package/dist/ui/_stx/chunk.9fd39d5b.js +86 -0
  100. package/dist/ui/_stx/chunk.d5301f79.js +119 -0
  101. package/dist/ui/_stx/crosswind.222ed683.css +1 -0
  102. package/dist/ui/_stx/crosswind.616c25f3.css +1 -0
  103. package/dist/ui/_stx/crosswind.80baa894.css +320 -0
  104. package/dist/ui/_stx/crosswind.906ee17c.css +1 -0
  105. package/dist/ui/_stx/crosswind.996ed49e.css +1 -0
  106. package/dist/ui/_stx/crosswind.b7a99a5c.css +1 -0
  107. package/dist/ui/_stx/router.fa5bc4dc.js +4 -0
  108. package/dist/ui/_stx/runtime.c696d17a.js +1 -0
  109. package/dist/ui/_stx/style.448ab192.css +1 -0
  110. package/dist/ui/accept-invitation.html +2 -1133
  111. package/dist/ui/access-denied.html +7 -1130
  112. package/dist/ui/account/automation.html +12 -1134
  113. package/dist/ui/account/security.html +13 -1136
  114. package/dist/ui/applications/compose.html +12 -1134
  115. package/dist/ui/applications/new.html +13 -1137
  116. package/dist/ui/data/backups.html +91 -1136
  117. package/dist/ui/data/services.html +89 -1136
  118. package/dist/ui/data/volumes.html +61 -1136
  119. package/dist/ui/index.html +60 -1136
  120. package/dist/ui/infrastructure/topology.html +128 -1135
  121. package/dist/ui/integrations.html +13 -1138
  122. package/dist/ui/operations/alerts.html +59 -1136
  123. package/dist/ui/operations/configuration.html +13 -1135
  124. package/dist/ui/operations/jobs.html +87 -1136
  125. package/dist/ui/operations/maintenance.html +12 -1134
  126. package/dist/ui/operations/observability.html +93 -1136
  127. package/dist/ui/operations/previews.html +12 -1134
  128. package/dist/ui/operations/queue.html +12 -1134
  129. package/dist/ui/operations/regions.html +12 -1134
  130. package/dist/ui/operations/releases.html +12 -1134
  131. package/dist/ui/operations/spend.html +65 -1136
  132. package/dist/ui/operations/workloads.html +115 -1136
  133. package/dist/ui/robots.txt +2 -0
  134. package/dist/ui/security.html +24 -1136
  135. package/dist/ui/server/actions.html +67 -1138
  136. package/dist/ui/server/activity.html +7 -1130
  137. package/dist/ui/server/capacity.html +12 -1134
  138. package/dist/ui/server/database.html +166 -1135
  139. package/dist/ui/server/deployments.html +60 -1136
  140. package/dist/ui/server/diagnostics.html +7 -1130
  141. package/dist/ui/server/firewall.html +286 -1212
  142. package/dist/ui/server/fleet.html +45 -1136
  143. package/dist/ui/server/logs.html +34 -1135
  144. package/dist/ui/server/metrics.html +124 -1140
  145. package/dist/ui/server/security.html +7 -1130
  146. package/dist/ui/server/services.html +46 -1133
  147. package/dist/ui/server/sites.html +287 -1137
  148. package/dist/ui/server/ssh-keys.html +62 -1135
  149. package/dist/ui/server/team.html +155 -1136
  150. package/dist/ui/server/terminal.html +97 -1183
  151. package/dist/ui/serverless/alarms.html +62 -1135
  152. package/dist/ui/serverless/assets.html +47 -1132
  153. package/dist/ui/serverless/cost.html +7 -1130
  154. package/dist/ui/serverless/data.html +46 -1135
  155. package/dist/ui/serverless/deployments.html +47 -1132
  156. package/dist/ui/serverless/firewall.html +7 -1130
  157. package/dist/ui/serverless/functions.html +50 -1136
  158. package/dist/ui/serverless/logs.html +34 -1135
  159. package/dist/ui/serverless/metrics.html +7 -1130
  160. package/dist/ui/serverless/queues.html +58 -1135
  161. package/dist/ui/serverless/secrets.html +62 -1136
  162. package/dist/ui/serverless/traces.html +12 -1134
  163. package/dist/ui/serverless.html +64 -1137
  164. package/dist/ui-src/pages/server/firewall.stx +14 -14
  165. package/package.json +3 -3
  166. package/dist/chunk-01d86gt1.js +0 -1324
  167. package/dist/chunk-050r7ycy.js +0 -46516
  168. package/dist/chunk-29rse4p1.js +0 -12203
  169. package/dist/chunk-32e7ya18.js +0 -642
  170. package/dist/chunk-4cjrg98a.js +0 -597
  171. package/dist/chunk-50jpda9q.js +0 -371
  172. package/dist/chunk-6a1t7fnq.js +0 -12121
  173. package/dist/chunk-728jvrr0.js +0 -1701
  174. package/dist/chunk-7m60qnc8.js +0 -1762
  175. package/dist/chunk-aa2dkn7b.js +0 -205
  176. package/dist/chunk-d48vtdj4.js +0 -433
  177. package/dist/chunk-f55nkpvb.js +0 -8
  178. package/dist/chunk-fgk8cqew.js +0 -152
  179. package/dist/chunk-he9a874b.js +0 -769
  180. package/dist/chunk-hg7rhrgd.js +0 -7274
  181. package/dist/chunk-k2yyatfw.js +0 -10
  182. package/dist/chunk-k4px0bnv.js +0 -23
  183. package/dist/chunk-nsgqsmrh.js +0 -1779
  184. package/dist/chunk-qr803fye.js +0 -2122
  185. package/dist/chunk-rds0sy87.js +0 -1771
  186. package/dist/chunk-rxgchb08.js +0 -42033
  187. package/dist/chunk-ttz2ra5j.js +0 -12
  188. package/dist/chunk-v0bahtg2.js +0 -4
  189. package/dist/chunk-va2yd85b.js +0 -200
  190. package/dist/chunk-x9s0cqfx.js +0 -13
  191. package/dist/chunk-zqtpg06c.js +0 -1752
@@ -1,597 +0,0 @@
1
- import {
2
- AWSClient
3
- } from "./chunk-zqtpg06c.js";
4
-
5
- // src/aws/cloudformation.ts
6
- class CloudFormationClient {
7
- client;
8
- region;
9
- constructor(region = "us-east-1", profile) {
10
- this.region = region;
11
- this.client = new AWSClient(undefined, { profile });
12
- }
13
- async createStack(options) {
14
- const params = {
15
- Action: "CreateStack",
16
- StackName: options.stackName,
17
- Version: "2010-05-15"
18
- };
19
- if (options.templateBody) {
20
- params.TemplateBody = options.templateBody;
21
- } else if (options.templateUrl) {
22
- params.TemplateURL = options.templateUrl;
23
- } else {
24
- throw new Error("Either templateBody or templateUrl must be provided");
25
- }
26
- if (options.parameters) {
27
- options.parameters.forEach((param, index) => {
28
- params[`Parameters.member.${index + 1}.ParameterKey`] = param.ParameterKey;
29
- params[`Parameters.member.${index + 1}.ParameterValue`] = param.ParameterValue;
30
- });
31
- }
32
- if (options.capabilities) {
33
- options.capabilities.forEach((cap, index) => {
34
- params[`Capabilities.member.${index + 1}`] = cap;
35
- });
36
- }
37
- if (options.roleArn) {
38
- params.RoleARN = options.roleArn;
39
- }
40
- if (options.tags) {
41
- options.tags.forEach((tag, index) => {
42
- params[`Tags.member.${index + 1}.Key`] = tag.Key;
43
- params[`Tags.member.${index + 1}.Value`] = tag.Value;
44
- });
45
- }
46
- if (options.timeoutInMinutes) {
47
- params.TimeoutInMinutes = options.timeoutInMinutes;
48
- }
49
- if (options.onFailure) {
50
- params.OnFailure = options.onFailure;
51
- }
52
- const result = await this.client.request({
53
- service: "cloudformation",
54
- region: this.region,
55
- method: "POST",
56
- path: "/",
57
- body: new URLSearchParams(params).toString()
58
- });
59
- return { StackId: result.StackId || result.CreateStackResult?.StackId };
60
- }
61
- async updateStack(options) {
62
- const params = {
63
- Action: "UpdateStack",
64
- StackName: options.stackName,
65
- Version: "2010-05-15"
66
- };
67
- if (options.templateBody) {
68
- params.TemplateBody = options.templateBody;
69
- } else if (options.templateUrl) {
70
- params.TemplateURL = options.templateUrl;
71
- }
72
- if (options.parameters) {
73
- options.parameters.forEach((param, index) => {
74
- params[`Parameters.member.${index + 1}.ParameterKey`] = param.ParameterKey;
75
- if (param.UsePreviousValue) {
76
- params[`Parameters.member.${index + 1}.UsePreviousValue`] = "true";
77
- } else {
78
- params[`Parameters.member.${index + 1}.ParameterValue`] = param.ParameterValue;
79
- }
80
- });
81
- }
82
- if (options.capabilities) {
83
- options.capabilities.forEach((cap, index) => {
84
- params[`Capabilities.member.${index + 1}`] = cap;
85
- });
86
- }
87
- if (options.roleArn) {
88
- params.RoleARN = options.roleArn;
89
- }
90
- if (options.tags) {
91
- options.tags.forEach((tag, index) => {
92
- params[`Tags.member.${index + 1}.Key`] = tag.Key;
93
- params[`Tags.member.${index + 1}.Value`] = tag.Value;
94
- });
95
- }
96
- const result = await this.client.request({
97
- service: "cloudformation",
98
- region: this.region,
99
- method: "POST",
100
- path: "/",
101
- body: new URLSearchParams(params).toString()
102
- });
103
- return { StackId: result.StackId || result.UpdateStackResult?.StackId };
104
- }
105
- async deleteStack(stackName, roleArn, retainResources) {
106
- const params = {
107
- Action: "DeleteStack",
108
- StackName: stackName,
109
- Version: "2010-05-15"
110
- };
111
- if (roleArn) {
112
- params.RoleARN = roleArn;
113
- }
114
- if (retainResources && retainResources.length > 0) {
115
- retainResources.forEach((resource, index) => {
116
- params[`RetainResources.member.${index + 1}`] = resource;
117
- });
118
- }
119
- await this.client.request({
120
- service: "cloudformation",
121
- region: this.region,
122
- method: "POST",
123
- path: "/",
124
- body: new URLSearchParams(params).toString()
125
- });
126
- }
127
- async describeStacks(options = {}) {
128
- const params = {
129
- Action: "DescribeStacks",
130
- Version: "2010-05-15"
131
- };
132
- if (options.stackName) {
133
- params.StackName = options.stackName;
134
- }
135
- const result = await this.client.request({
136
- service: "cloudformation",
137
- region: this.region,
138
- method: "POST",
139
- path: "/",
140
- body: new URLSearchParams(params).toString()
141
- });
142
- const stacks = this.parseStacksResponse(result);
143
- return { Stacks: stacks };
144
- }
145
- async describeStackEvents(stackName) {
146
- const params = {
147
- Action: "DescribeStackEvents",
148
- StackName: stackName,
149
- Version: "2010-05-15"
150
- };
151
- const result = await this.client.request({
152
- service: "cloudformation",
153
- region: this.region,
154
- method: "POST",
155
- path: "/",
156
- body: new URLSearchParams(params).toString()
157
- });
158
- return { StackEvents: this.parseStackEvents(result) };
159
- }
160
- async listStackResources(stackName) {
161
- const params = {
162
- Action: "ListStackResources",
163
- StackName: stackName,
164
- Version: "2010-05-15"
165
- };
166
- const result = await this.client.request({
167
- service: "cloudformation",
168
- region: this.region,
169
- method: "POST",
170
- path: "/",
171
- body: new URLSearchParams(params).toString()
172
- });
173
- const member = result?.ListStackResourcesResult?.StackResourceSummaries?.member;
174
- let resources = [];
175
- if (member) {
176
- resources = Array.isArray(member) ? member : [member];
177
- }
178
- return { StackResourceSummaries: resources };
179
- }
180
- async waitForStack(stackName, waitType) {
181
- const targetStatuses = {
182
- "stack-create-complete": ["CREATE_COMPLETE"],
183
- "stack-update-complete": ["UPDATE_COMPLETE"],
184
- "stack-delete-complete": ["DELETE_COMPLETE"]
185
- };
186
- const failureStatuses = [
187
- "CREATE_FAILED",
188
- "ROLLBACK_FAILED",
189
- "ROLLBACK_COMPLETE",
190
- "UPDATE_ROLLBACK_FAILED",
191
- "UPDATE_ROLLBACK_COMPLETE"
192
- ];
193
- const targets = targetStatuses[waitType];
194
- const maxAttempts = 360;
195
- let attempts = 0;
196
- while (attempts < maxAttempts) {
197
- try {
198
- const result = await this.describeStacks({ stackName });
199
- if (result.Stacks.length === 0) {
200
- if (waitType === "stack-delete-complete") {
201
- return;
202
- }
203
- if (attempts % 10 === 0) {
204
- console.log(`[waitForStack] Attempt ${attempts}: Stack not visible yet`);
205
- }
206
- await new Promise((resolve) => setTimeout(resolve, 2000));
207
- attempts++;
208
- continue;
209
- }
210
- const stack = result.Stacks[0];
211
- if (attempts % 10 === 0) {
212
- console.log(`[waitForStack] Attempt ${attempts}: Status = ${stack.StackStatus}${stack.StackStatusReason ? ` (${stack.StackStatusReason})` : ""}`);
213
- }
214
- if (targets.includes(stack.StackStatus)) {
215
- return;
216
- }
217
- if ((waitType === "stack-create-complete" || waitType === "stack-update-complete") && (stack.StackStatus === "DELETE_IN_PROGRESS" || stack.StackStatus === "DELETE_COMPLETE")) {
218
- console.log(`[waitForStack] Stack is being deleted (creation/update failed)`);
219
- let failedEventReason = "";
220
- try {
221
- const eventsResult = await this.describeStackEvents(stackName);
222
- console.log("[waitForStack] Stack events (most recent first):");
223
- for (const event of eventsResult.StackEvents.slice(0, 15)) {
224
- if (event.ResourceStatus.includes("FAILED") || event.ResourceStatusReason) {
225
- console.log(` ${event.LogicalResourceId}: ${event.ResourceStatus} - ${event.ResourceStatusReason || "No reason provided"}`);
226
- if (event.ResourceStatus.includes("FAILED") && event.ResourceStatusReason && !failedEventReason) {
227
- failedEventReason = event.ResourceStatusReason;
228
- }
229
- }
230
- }
231
- } catch {}
232
- const errorReason = failedEventReason || stack.StackStatusReason || "Check CloudFormation console for details.";
233
- throw new Error(`Stack creation/update failed - stack is being deleted. Reason: ${errorReason}`);
234
- }
235
- if (stack.StackStatus === "DELETE_FAILED" && waitType === "stack-delete-complete") {
236
- const error = new Error(`Stack deletion failed - may have resources that need to be retained`);
237
- error.code = "DELETE_FAILED";
238
- error.stackStatus = stack.StackStatus;
239
- error.statusReason = stack.StackStatusReason;
240
- throw error;
241
- }
242
- if (failureStatuses.includes(stack.StackStatus)) {
243
- throw new Error(`Stack reached failure status: ${stack.StackStatus}`);
244
- }
245
- await new Promise((resolve) => setTimeout(resolve, 5000));
246
- attempts++;
247
- } catch (error) {
248
- if (waitType === "stack-delete-complete" && error.message?.includes("does not exist")) {
249
- return;
250
- }
251
- if (waitType === "stack-create-complete" && error.message?.includes("does not exist")) {
252
- if (attempts % 10 === 0) {
253
- console.log(`[waitForStack] Attempt ${attempts}: Stack does not exist (error), retrying...`);
254
- }
255
- await new Promise((resolve) => setTimeout(resolve, 2000));
256
- attempts++;
257
- continue;
258
- }
259
- console.log(`[waitForStack] Unexpected error: ${error.message}`);
260
- throw error;
261
- }
262
- }
263
- console.log(`[waitForStack] Timeout after ${attempts} attempts`);
264
- throw new Error(`Timeout waiting for stack to reach ${waitType}`);
265
- }
266
- async validateTemplate(templateBody) {
267
- const params = {
268
- Action: "ValidateTemplate",
269
- TemplateBody: templateBody,
270
- Version: "2010-05-15"
271
- };
272
- return await this.client.request({
273
- service: "cloudformation",
274
- region: this.region,
275
- method: "POST",
276
- path: "/",
277
- body: new URLSearchParams(params).toString()
278
- });
279
- }
280
- async listStacks(statusFilter) {
281
- const params = {
282
- Action: "ListStacks",
283
- Version: "2010-05-15"
284
- };
285
- if (statusFilter) {
286
- statusFilter.forEach((status, index) => {
287
- params[`StackStatusFilter.member.${index + 1}`] = status;
288
- });
289
- }
290
- const result = await this.client.request({
291
- service: "cloudformation",
292
- region: this.region,
293
- method: "POST",
294
- path: "/",
295
- body: new URLSearchParams(params).toString()
296
- });
297
- const response = result.ListStacksResponse || result;
298
- const summariesResult = response.ListStacksResult || response;
299
- const members = summariesResult.StackSummaries?.member || summariesResult.StackSummaries || [];
300
- const items = Array.isArray(members) ? members : members ? [members] : [];
301
- return {
302
- StackSummaries: items.map((s) => ({
303
- StackId: s.StackId || "",
304
- StackName: s.StackName || "",
305
- TemplateDescription: s.TemplateDescription,
306
- CreationTime: s.CreationTime || "",
307
- LastUpdatedTime: s.LastUpdatedTime,
308
- DeletionTime: s.DeletionTime,
309
- StackStatus: s.StackStatus || ""
310
- }))
311
- };
312
- }
313
- async createChangeSet(options) {
314
- const params = {
315
- Action: "CreateChangeSet",
316
- StackName: options.stackName,
317
- ChangeSetName: options.changeSetName,
318
- Version: "2010-05-15"
319
- };
320
- if (options.templateBody) {
321
- params.TemplateBody = options.templateBody;
322
- } else if (options.templateUrl) {
323
- params.TemplateURL = options.templateUrl;
324
- }
325
- if (options.parameters) {
326
- options.parameters.forEach((param, index) => {
327
- params[`Parameters.member.${index + 1}.ParameterKey`] = param.ParameterKey;
328
- params[`Parameters.member.${index + 1}.ParameterValue`] = param.ParameterValue;
329
- });
330
- }
331
- if (options.capabilities) {
332
- options.capabilities.forEach((cap, index) => {
333
- params[`Capabilities.member.${index + 1}`] = cap;
334
- });
335
- }
336
- if (options.changeSetType) {
337
- params.ChangeSetType = options.changeSetType;
338
- }
339
- const result = await this.client.request({
340
- service: "cloudformation",
341
- region: this.region,
342
- method: "POST",
343
- path: "/",
344
- body: new URLSearchParams(params).toString()
345
- });
346
- return { Id: result.Id, StackId: result.StackId };
347
- }
348
- async describeChangeSet(stackName, changeSetName) {
349
- const params = {
350
- Action: "DescribeChangeSet",
351
- StackName: stackName,
352
- ChangeSetName: changeSetName,
353
- Version: "2010-05-15"
354
- };
355
- return await this.client.request({
356
- service: "cloudformation",
357
- region: this.region,
358
- method: "POST",
359
- path: "/",
360
- body: new URLSearchParams(params).toString()
361
- });
362
- }
363
- async executeChangeSet(stackName, changeSetName) {
364
- const params = {
365
- Action: "ExecuteChangeSet",
366
- StackName: stackName,
367
- ChangeSetName: changeSetName,
368
- Version: "2010-05-15"
369
- };
370
- await this.client.request({
371
- service: "cloudformation",
372
- region: this.region,
373
- method: "POST",
374
- path: "/",
375
- body: new URLSearchParams(params).toString()
376
- });
377
- }
378
- async deleteChangeSet(stackName, changeSetName) {
379
- const params = {
380
- Action: "DeleteChangeSet",
381
- StackName: stackName,
382
- ChangeSetName: changeSetName,
383
- Version: "2010-05-15"
384
- };
385
- await this.client.request({
386
- service: "cloudformation",
387
- region: this.region,
388
- method: "POST",
389
- path: "/",
390
- body: new URLSearchParams(params).toString()
391
- });
392
- }
393
- async getStackOutputs(stackName) {
394
- const result = await this.describeStacks({ stackName });
395
- if (!result.Stacks || result.Stacks.length === 0) {
396
- throw new Error(`Stack ${stackName} not found`);
397
- }
398
- const stack = result.Stacks[0];
399
- const outputs = {};
400
- if (stack.Outputs) {
401
- for (const output of stack.Outputs) {
402
- outputs[output.OutputKey] = output.OutputValue;
403
- }
404
- }
405
- return outputs;
406
- }
407
- async getTemplate(stackName) {
408
- const params = {
409
- Action: "GetTemplate",
410
- StackName: stackName,
411
- Version: "2010-05-15"
412
- };
413
- const result = await this.client.request({
414
- service: "cloudformation",
415
- region: this.region,
416
- method: "POST",
417
- path: "/",
418
- body: new URLSearchParams(params).toString()
419
- });
420
- const templateBody = result?.GetTemplateResult?.TemplateBody || result?.TemplateBody || "";
421
- return { TemplateBody: templateBody };
422
- }
423
- parseStacksResponse(result) {
424
- const stacks = [];
425
- let stackData = result?.DescribeStacksResult?.Stacks?.member || result?.Stacks?.member || result?.Stacks || result;
426
- if (stackData && !Array.isArray(stackData)) {
427
- stackData = [stackData];
428
- }
429
- if (Array.isArray(stackData)) {
430
- for (const s of stackData) {
431
- if (s.StackId || s.StackName) {
432
- let outputs;
433
- if (s.Outputs?.member) {
434
- const outputData = Array.isArray(s.Outputs.member) ? s.Outputs.member : [s.Outputs.member];
435
- outputs = outputData.map((o) => ({
436
- OutputKey: o.OutputKey,
437
- OutputValue: o.OutputValue,
438
- Description: o.Description,
439
- ExportName: o.ExportName
440
- }));
441
- }
442
- stacks.push({
443
- StackId: s.StackId,
444
- StackName: s.StackName,
445
- StackStatus: s.StackStatus,
446
- CreationTime: s.CreationTime,
447
- LastUpdatedTime: s.LastUpdatedTime,
448
- StackStatusReason: s.StackStatusReason,
449
- Outputs: outputs
450
- });
451
- }
452
- }
453
- } else if (result.StackId) {
454
- stacks.push({
455
- StackId: result.StackId,
456
- StackName: result.StackName,
457
- StackStatus: result.StackStatus,
458
- CreationTime: result.CreationTime,
459
- LastUpdatedTime: result.LastUpdatedTime
460
- });
461
- }
462
- return stacks;
463
- }
464
- parseStackEvents(result) {
465
- const events = [];
466
- let eventData = result?.DescribeStackEventsResult?.StackEvents?.member || result?.StackEvents?.member || result?.StackEvents || [];
467
- if (eventData && !Array.isArray(eventData)) {
468
- eventData = [eventData];
469
- }
470
- for (const e of eventData) {
471
- if (e.LogicalResourceId) {
472
- events.push({
473
- Timestamp: e.Timestamp,
474
- ResourceType: e.ResourceType,
475
- LogicalResourceId: e.LogicalResourceId,
476
- ResourceStatus: e.ResourceStatus,
477
- ResourceStatusReason: e.ResourceStatusReason
478
- });
479
- }
480
- }
481
- return events;
482
- }
483
- async waitForStackWithProgress(stackName, waitType, onProgress) {
484
- const targetStatuses = {
485
- "stack-create-complete": ["CREATE_COMPLETE"],
486
- "stack-update-complete": ["UPDATE_COMPLETE"],
487
- "stack-delete-complete": ["DELETE_COMPLETE"]
488
- };
489
- const failureStatuses = [
490
- "CREATE_FAILED",
491
- "ROLLBACK_FAILED",
492
- "ROLLBACK_COMPLETE",
493
- "UPDATE_ROLLBACK_FAILED",
494
- "UPDATE_ROLLBACK_COMPLETE"
495
- ];
496
- const targets = targetStatuses[waitType];
497
- const maxAttempts = 360;
498
- let attempts = 0;
499
- const seenEvents = new Set;
500
- while (attempts < maxAttempts) {
501
- try {
502
- if (onProgress) {
503
- try {
504
- const eventsResult = await this.describeStackEvents(stackName);
505
- const events = [...eventsResult.StackEvents || []].reverse();
506
- for (const event of events) {
507
- const eventKey = `${event.LogicalResourceId}-${event.ResourceStatus}-${event.Timestamp}`;
508
- if (!seenEvents.has(eventKey)) {
509
- seenEvents.add(eventKey);
510
- onProgress({
511
- resourceId: event.LogicalResourceId,
512
- resourceType: event.ResourceType,
513
- status: event.ResourceStatus,
514
- reason: event.ResourceStatusReason,
515
- timestamp: event.Timestamp
516
- });
517
- }
518
- }
519
- } catch {}
520
- }
521
- const result = await this.describeStacks({ stackName });
522
- if (result.Stacks.length === 0) {
523
- if (waitType === "stack-delete-complete") {
524
- return;
525
- }
526
- await new Promise((resolve) => setTimeout(resolve, 2000));
527
- attempts++;
528
- continue;
529
- }
530
- const stack = result.Stacks[0];
531
- if (targets.includes(stack.StackStatus)) {
532
- return;
533
- }
534
- if (stack.StackStatus === "DELETE_FAILED" && waitType === "stack-delete-complete") {
535
- const error = new Error(`Stack deletion failed - may have resources that need to be retained`);
536
- error.code = "DELETE_FAILED";
537
- error.stackStatus = stack.StackStatus;
538
- error.statusReason = stack.StackStatusReason;
539
- throw error;
540
- }
541
- if (failureStatuses.includes(stack.StackStatus)) {
542
- throw new Error(`Stack reached failure status: ${stack.StackStatus}`);
543
- }
544
- await new Promise((resolve) => setTimeout(resolve, 3000));
545
- attempts++;
546
- } catch (error) {
547
- if (waitType === "stack-delete-complete" && error.message?.includes("does not exist")) {
548
- return;
549
- }
550
- if (waitType === "stack-create-complete" && error.message?.includes("does not exist")) {
551
- await new Promise((resolve) => setTimeout(resolve, 2000));
552
- attempts++;
553
- continue;
554
- }
555
- throw error;
556
- }
557
- }
558
- throw new Error(`Timeout waiting for stack to reach ${waitType}`);
559
- }
560
- async waitForStackComplete(stackName, maxAttempts = 120, delayMs = 5000) {
561
- const successStatuses = ["CREATE_COMPLETE", "UPDATE_COMPLETE", "DELETE_COMPLETE"];
562
- const failureStatuses = [
563
- "CREATE_FAILED",
564
- "UPDATE_FAILED",
565
- "DELETE_FAILED",
566
- "ROLLBACK_COMPLETE",
567
- "ROLLBACK_FAILED",
568
- "UPDATE_ROLLBACK_COMPLETE",
569
- "UPDATE_ROLLBACK_FAILED"
570
- ];
571
- for (let i = 0;i < maxAttempts; i++) {
572
- try {
573
- const result = await this.describeStacks({ stackName });
574
- if (result.Stacks.length === 0) {
575
- return { success: true, status: "DELETE_COMPLETE" };
576
- }
577
- const stack = result.Stacks[0];
578
- const status = stack.StackStatus;
579
- if (successStatuses.includes(status)) {
580
- return { success: true, status };
581
- }
582
- if (failureStatuses.includes(status)) {
583
- return { success: false, status, reason: stack.StackStatusReason };
584
- }
585
- await new Promise((resolve) => setTimeout(resolve, delayMs));
586
- } catch (error) {
587
- if (error.message?.includes("does not exist")) {
588
- return { success: true, status: "DELETE_COMPLETE" };
589
- }
590
- throw error;
591
- }
592
- }
593
- return { success: false, status: "TIMEOUT", reason: "Timeout waiting for stack operation" };
594
- }
595
- }
596
-
597
- export { CloudFormationClient };