@stacksjs/ts-cloud 0.9.3 → 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 (143) hide show
  1. package/dist/aws/index.js +1 -269
  2. package/dist/bin/chunk-00kg80qg.js +1 -0
  3. package/dist/bin/{chunk-hzqw8xm5.js → chunk-1k5kszjp.js} +1 -1
  4. package/dist/bin/{chunk-9v39615t.js → chunk-21e0mavm.js} +1 -1
  5. package/dist/bin/{chunk-waayf9ay.js → chunk-2empps47.js} +1 -1
  6. package/dist/bin/{chunk-14cwr6eh.js → chunk-3vqfexc4.js} +1 -1
  7. package/dist/bin/chunk-5ectjq0b.js +1 -0
  8. package/dist/bin/{chunk-b5gd39s8.js → chunk-5erkxpt7.js} +4 -4
  9. package/dist/bin/{chunk-41x17hw1.js → chunk-5mrtzemj.js} +1 -1
  10. package/dist/bin/{chunk-p8q9bq9g.js → chunk-5n9fmabb.js} +1 -1
  11. package/dist/bin/{chunk-gqf6jsmy.js → chunk-9knpg30y.js} +1 -1
  12. package/dist/bin/{chunk-r3kv0vm9.js → chunk-ddk4rt4j.js} +1 -1
  13. package/dist/bin/{chunk-avm7tnwe.js → chunk-e0rkrq70.js} +1 -1
  14. package/dist/bin/{chunk-ry030a6b.js → chunk-etrb03mt.js} +1 -1
  15. package/dist/bin/{chunk-8v7ddyvf.js → chunk-k9t9wvms.js} +1 -1
  16. package/dist/bin/{chunk-92mea34a.js → chunk-m7dgskt1.js} +1 -1
  17. package/dist/bin/{chunk-3r4fb59r.js → chunk-mz0wbbsj.js} +1 -1
  18. package/dist/bin/{chunk-b9qbp8j1.js → chunk-qk9qgepa.js} +1 -1
  19. package/dist/bin/chunk-rxcvf10f.js +7364 -0
  20. package/dist/bin/{chunk-r9hjwcj9.js → chunk-tga3hhwk.js} +1 -1
  21. package/dist/bin/{chunk-ynjvbphf.js → chunk-tx0tqq2k.js} +1 -1
  22. package/dist/bin/{chunk-57y1zxbf.js → chunk-vm3q5gf2.js} +1 -1
  23. package/dist/bin/{chunk-bz828v8q.js → chunk-y7s5r8y6.js} +1 -1
  24. package/dist/bin/{chunk-sgyffpgm.js → chunk-zmegvjp8.js} +1 -1
  25. package/dist/bin/cli.js +14 -14
  26. package/dist/bin/dashboard-server.js +1 -1
  27. package/dist/chunk-0ccta6z6.js +6 -0
  28. package/dist/chunk-0k1cs6pp.js +1 -0
  29. package/dist/chunk-1egjn203.js +704 -0
  30. package/dist/chunk-2wx29qga.js +5 -0
  31. package/dist/chunk-5m5rqmv7.js +1 -0
  32. package/dist/chunk-8ea5022g.js +114 -0
  33. package/dist/chunk-8xqn3c0w.js +2 -0
  34. package/dist/chunk-b4esxhmw.js +2 -0
  35. package/dist/chunk-b8e5wzwn.js +44 -0
  36. package/dist/chunk-bggt4n6e.js +2 -0
  37. package/dist/chunk-cwkg37rs.js +37 -0
  38. package/dist/chunk-dskvqt67.js +7355 -0
  39. package/dist/chunk-gahsdmxf.js +1617 -0
  40. package/dist/chunk-gnv3r2jg.js +1 -0
  41. package/dist/chunk-hg3c48cp.js +34 -0
  42. package/dist/chunk-m5azeva3.js +2 -0
  43. package/dist/chunk-r3qf56b3.js +92 -0
  44. package/dist/chunk-sdqa9ghv.js +141 -0
  45. package/dist/chunk-svrvvcm7.js +1 -0
  46. package/dist/chunk-v0p3hpc3.js +60 -0
  47. package/dist/chunk-wdzjbecg.js +50 -0
  48. package/dist/chunk-ww8k3g7j.js +1 -0
  49. package/dist/chunk-xmqfc62w.js +1 -0
  50. package/dist/chunk-xrebj679.js +435 -0
  51. package/dist/chunk-xt3s24vr.js +2 -0
  52. package/dist/chunk-y21zk0pn.js +4 -0
  53. package/dist/deploy/index.js +1 -168
  54. package/dist/dns/index.js +1 -41
  55. package/dist/drivers/index.js +1 -154
  56. package/dist/index.js +100 -6129
  57. package/dist/protection/index.js +1 -89
  58. package/dist/push/index.js +1 -509
  59. package/dist/spend/index.js +1 -173
  60. package/dist/ui/404.html +1 -1
  61. package/dist/ui/accept-invitation.html +1 -1
  62. package/dist/ui/access-denied.html +1 -1
  63. package/dist/ui/account/automation.html +6 -6
  64. package/dist/ui/account/security.html +2 -2
  65. package/dist/ui/applications/compose.html +6 -6
  66. package/dist/ui/applications/new.html +2 -2
  67. package/dist/ui/data/backups.html +5 -5
  68. package/dist/ui/data/services.html +5 -5
  69. package/dist/ui/data/volumes.html +6 -6
  70. package/dist/ui/index.html +6 -6
  71. package/dist/ui/infrastructure/topology.html +5 -5
  72. package/dist/ui/integrations.html +1 -1
  73. package/dist/ui/operations/alerts.html +5 -5
  74. package/dist/ui/operations/configuration.html +5 -5
  75. package/dist/ui/operations/jobs.html +5 -5
  76. package/dist/ui/operations/maintenance.html +5 -5
  77. package/dist/ui/operations/observability.html +6 -6
  78. package/dist/ui/operations/previews.html +6 -6
  79. package/dist/ui/operations/queue.html +6 -6
  80. package/dist/ui/operations/regions.html +6 -6
  81. package/dist/ui/operations/releases.html +6 -6
  82. package/dist/ui/operations/spend.html +6 -6
  83. package/dist/ui/operations/workloads.html +6 -6
  84. package/dist/ui/security.html +1 -1
  85. package/dist/ui/server/actions.html +5 -5
  86. package/dist/ui/server/activity.html +1 -1
  87. package/dist/ui/server/capacity.html +6 -6
  88. package/dist/ui/server/database.html +6 -6
  89. package/dist/ui/server/deployments.html +6 -6
  90. package/dist/ui/server/diagnostics.html +2 -2
  91. package/dist/ui/server/firewall.html +6 -6
  92. package/dist/ui/server/fleet.html +6 -6
  93. package/dist/ui/server/logs.html +6 -6
  94. package/dist/ui/server/metrics.html +6 -6
  95. package/dist/ui/server/security.html +2 -2
  96. package/dist/ui/server/services.html +1 -1
  97. package/dist/ui/server/sites.html +6 -6
  98. package/dist/ui/server/ssh-keys.html +6 -6
  99. package/dist/ui/server/team.html +6 -6
  100. package/dist/ui/server/terminal.html +1 -1
  101. package/dist/ui/serverless/alarms.html +5 -5
  102. package/dist/ui/serverless/assets.html +2 -2
  103. package/dist/ui/serverless/cost.html +1 -1
  104. package/dist/ui/serverless/data.html +6 -6
  105. package/dist/ui/serverless/deployments.html +2 -2
  106. package/dist/ui/serverless/firewall.html +1 -1
  107. package/dist/ui/serverless/functions.html +6 -6
  108. package/dist/ui/serverless/logs.html +6 -6
  109. package/dist/ui/serverless/metrics.html +2 -2
  110. package/dist/ui/serverless/queues.html +6 -6
  111. package/dist/ui/serverless/secrets.html +6 -6
  112. package/dist/ui/serverless/traces.html +6 -6
  113. package/dist/ui/serverless.html +5 -5
  114. package/package.json +3 -3
  115. package/dist/bin/chunk-jpjamjey.js +0 -6935
  116. package/dist/bin/chunk-m2zwtapr.js +0 -1
  117. package/dist/bin/chunk-rtczra13.js +0 -1
  118. package/dist/chunk-01d86gt1.js +0 -1324
  119. package/dist/chunk-050r7ycy.js +0 -46516
  120. package/dist/chunk-1c8dbv57.js +0 -7278
  121. package/dist/chunk-29rse4p1.js +0 -12203
  122. package/dist/chunk-32e7ya18.js +0 -642
  123. package/dist/chunk-4cjrg98a.js +0 -597
  124. package/dist/chunk-50jpda9q.js +0 -371
  125. package/dist/chunk-6a1t7fnq.js +0 -12121
  126. package/dist/chunk-728jvrr0.js +0 -1701
  127. package/dist/chunk-7m60qnc8.js +0 -1762
  128. package/dist/chunk-aa2dkn7b.js +0 -205
  129. package/dist/chunk-d48vtdj4.js +0 -433
  130. package/dist/chunk-f55nkpvb.js +0 -8
  131. package/dist/chunk-fgk8cqew.js +0 -152
  132. package/dist/chunk-he9a874b.js +0 -769
  133. package/dist/chunk-k2yyatfw.js +0 -10
  134. package/dist/chunk-k4px0bnv.js +0 -23
  135. package/dist/chunk-nsgqsmrh.js +0 -1779
  136. package/dist/chunk-q0st3se8.js +0 -42033
  137. package/dist/chunk-qr803fye.js +0 -2122
  138. package/dist/chunk-rds0sy87.js +0 -1771
  139. package/dist/chunk-ttz2ra5j.js +0 -12
  140. package/dist/chunk-v0bahtg2.js +0 -4
  141. package/dist/chunk-va2yd85b.js +0 -200
  142. package/dist/chunk-x9s0cqfx.js +0 -13
  143. 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 };