@stacksjs/ts-cloud 0.7.5 → 0.7.7

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 (57) hide show
  1. package/dist/aws/index.js +259 -0
  2. package/dist/bin/cli.js +231 -231
  3. package/dist/chunk-0wxyppza.js +146 -0
  4. package/dist/chunk-3knnr7wh.js +601 -0
  5. package/dist/chunk-3rsfns7x.js +10427 -0
  6. package/dist/chunk-93hjhs78.js +1752 -0
  7. package/dist/chunk-arsh1g5h.js +1749 -0
  8. package/dist/chunk-b82pbxyp.js +1572 -0
  9. package/dist/chunk-c6rgvg1j.js +46124 -0
  10. package/dist/chunk-d2p5n2aq.js +23 -0
  11. package/dist/chunk-d7p84vz5.js +1699 -0
  12. package/dist/chunk-eq08r166.js +8 -0
  13. package/dist/chunk-hsk6fe6x.js +371 -0
  14. package/dist/chunk-mj1tmhte.js +13 -0
  15. package/dist/chunk-pegd7rmf.js +10 -0
  16. package/dist/chunk-pqfzdg68.js +12 -0
  17. package/dist/chunk-qpj3edwz.js +601 -0
  18. package/dist/chunk-tjjgajbh.js +1032 -0
  19. package/dist/chunk-tnztxpcb.js +630 -0
  20. package/dist/chunk-tt4kxske.js +1788 -0
  21. package/dist/chunk-v0bahtg2.js +4 -0
  22. package/dist/chunk-vd87cpvn.js +1754 -0
  23. package/dist/chunk-x07dz3sd.js +12828 -0
  24. package/dist/chunk-xzn0ntr0.js +4616 -0
  25. package/dist/chunk-zn0nxxa8.js +1779 -0
  26. package/dist/deploy/index.js +87 -0
  27. package/dist/dns/index.js +31 -0
  28. package/dist/drivers/index.d.ts +2 -0
  29. package/dist/drivers/index.js +108 -0
  30. package/dist/drivers/shared/box-provision.d.ts +102 -0
  31. package/dist/index.d.ts +1 -1
  32. package/dist/index.js +4383 -91358
  33. package/dist/push/index.js +509 -0
  34. package/dist/ui/index.html +3 -3
  35. package/dist/ui/server/actions.html +3 -3
  36. package/dist/ui/server/backups.html +3 -3
  37. package/dist/ui/server/database.html +3 -3
  38. package/dist/ui/server/deployments.html +3 -3
  39. package/dist/ui/server/firewall.html +3 -3
  40. package/dist/ui/server/logs.html +3 -3
  41. package/dist/ui/server/services.html +3 -3
  42. package/dist/ui/server/sites.html +3 -3
  43. package/dist/ui/server/ssh-keys.html +3 -3
  44. package/dist/ui/server/terminal.html +3 -3
  45. package/dist/ui/server/workers.html +3 -3
  46. package/dist/ui/serverless/alarms.html +3 -3
  47. package/dist/ui/serverless/assets.html +3 -3
  48. package/dist/ui/serverless/data.html +3 -3
  49. package/dist/ui/serverless/deployments.html +3 -3
  50. package/dist/ui/serverless/functions.html +3 -3
  51. package/dist/ui/serverless/logs.html +3 -3
  52. package/dist/ui/serverless/queues.html +3 -3
  53. package/dist/ui/serverless/scheduler.html +3 -3
  54. package/dist/ui/serverless/secrets.html +3 -3
  55. package/dist/ui/serverless/traces.html +3 -3
  56. package/dist/ui/serverless.html +3 -3
  57. package/package.json +3 -3
@@ -0,0 +1,601 @@
1
+ import {
2
+ AWSClient
3
+ } from "./chunk-arsh1g5h.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;
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 = [
562
+ "CREATE_COMPLETE",
563
+ "UPDATE_COMPLETE",
564
+ "DELETE_COMPLETE"
565
+ ];
566
+ const failureStatuses = [
567
+ "CREATE_FAILED",
568
+ "UPDATE_FAILED",
569
+ "DELETE_FAILED",
570
+ "ROLLBACK_COMPLETE",
571
+ "ROLLBACK_FAILED",
572
+ "UPDATE_ROLLBACK_COMPLETE",
573
+ "UPDATE_ROLLBACK_FAILED"
574
+ ];
575
+ for (let i = 0;i < maxAttempts; i++) {
576
+ try {
577
+ const result = await this.describeStacks({ stackName });
578
+ if (result.Stacks.length === 0) {
579
+ return { success: true, status: "DELETE_COMPLETE" };
580
+ }
581
+ const stack = result.Stacks[0];
582
+ const status = stack.StackStatus;
583
+ if (successStatuses.includes(status)) {
584
+ return { success: true, status };
585
+ }
586
+ if (failureStatuses.includes(status)) {
587
+ return { success: false, status, reason: stack.StackStatusReason };
588
+ }
589
+ await new Promise((resolve) => setTimeout(resolve, delayMs));
590
+ } catch (error) {
591
+ if (error.message?.includes("does not exist")) {
592
+ return { success: true, status: "DELETE_COMPLETE" };
593
+ }
594
+ throw error;
595
+ }
596
+ }
597
+ return { success: false, status: "TIMEOUT", reason: "Timeout waiting for stack operation" };
598
+ }
599
+ }
600
+
601
+ export { CloudFormationClient };