@stacksjs/ts-cloud 0.7.4 → 0.7.6

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 (58) hide show
  1. package/dist/aws/index.js +259 -0
  2. package/dist/bin/cli.js +316 -316
  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-dpkk640m.js +4392 -0
  13. package/dist/chunk-eq08r166.js +8 -0
  14. package/dist/chunk-hsk6fe6x.js +371 -0
  15. package/dist/chunk-mj1tmhte.js +13 -0
  16. package/dist/chunk-p6309384.js +12828 -0
  17. package/dist/chunk-pegd7rmf.js +10 -0
  18. package/dist/chunk-pqfzdg68.js +12 -0
  19. package/dist/chunk-qpj3edwz.js +601 -0
  20. package/dist/chunk-tjjgajbh.js +1032 -0
  21. package/dist/chunk-tnztxpcb.js +630 -0
  22. package/dist/chunk-tt4kxske.js +1788 -0
  23. package/dist/chunk-v0bahtg2.js +4 -0
  24. package/dist/chunk-vd87cpvn.js +1754 -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/hetzner/provision.d.ts +53 -0
  29. package/dist/drivers/index.d.ts +5 -1
  30. package/dist/drivers/index.js +98 -0
  31. package/dist/drivers/shared/remote-exec.d.ts +47 -0
  32. package/dist/index.d.ts +1 -1
  33. package/dist/index.js +4383 -91358
  34. package/dist/push/index.js +509 -0
  35. package/dist/ui/index.html +3 -3
  36. package/dist/ui/server/actions.html +3 -3
  37. package/dist/ui/server/backups.html +3 -3
  38. package/dist/ui/server/database.html +3 -3
  39. package/dist/ui/server/deployments.html +3 -3
  40. package/dist/ui/server/firewall.html +3 -3
  41. package/dist/ui/server/logs.html +3 -3
  42. package/dist/ui/server/services.html +3 -3
  43. package/dist/ui/server/sites.html +3 -3
  44. package/dist/ui/server/ssh-keys.html +3 -3
  45. package/dist/ui/server/terminal.html +3 -3
  46. package/dist/ui/server/workers.html +3 -3
  47. package/dist/ui/serverless/alarms.html +3 -3
  48. package/dist/ui/serverless/assets.html +3 -3
  49. package/dist/ui/serverless/data.html +3 -3
  50. package/dist/ui/serverless/deployments.html +3 -3
  51. package/dist/ui/serverless/functions.html +3 -3
  52. package/dist/ui/serverless/logs.html +3 -3
  53. package/dist/ui/serverless/queues.html +3 -3
  54. package/dist/ui/serverless/scheduler.html +3 -3
  55. package/dist/ui/serverless/secrets.html +3 -3
  56. package/dist/ui/serverless/traces.html +3 -3
  57. package/dist/ui/serverless.html +3 -3
  58. package/package.json +3 -3
@@ -0,0 +1,1572 @@
1
+ import {
2
+ resolveCredentials
3
+ } from "./chunk-vd87cpvn.js";
4
+ import {
5
+ AWSClient
6
+ } from "./chunk-arsh1g5h.js";
7
+
8
+ // src/aws/cost-explorer-cache.ts
9
+ import { createHash } from "node:crypto";
10
+ import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
11
+ import { homedir } from "node:os";
12
+ import { join } from "node:path";
13
+ var CACHE_SCHEMA_VERSION = 1;
14
+ var HOUR_MS = 60 * 60 * 1000;
15
+ var DAY_MS = 24 * HOUR_MS;
16
+ var OPEN_PERIOD_TTL_MS = HOUR_MS;
17
+ var CLOSED_PERIOD_TTL_MS = 30 * DAY_MS;
18
+ function cacheRoot() {
19
+ const xdg = process.env.XDG_CACHE_HOME;
20
+ return join(xdg && xdg.trim() ? xdg : join(homedir(), ".cache"), "ts-cloud", "cost-explorer");
21
+ }
22
+ function profileDir(profile) {
23
+ return join(cacheRoot(), profile ?? "__default__");
24
+ }
25
+ function hashKey(key) {
26
+ const canonical = {
27
+ s: key.start,
28
+ e: key.end,
29
+ g: key.granularity,
30
+ m: [...key.metrics].sort(),
31
+ gb: [...key.groupBy].map((g) => `${g.Type}:${g.Key}`).sort()
32
+ };
33
+ return createHash("sha256").update(JSON.stringify(canonical)).digest("hex").slice(0, 24);
34
+ }
35
+ function isClosedPeriod(start, end) {
36
+ const endTs = Date.parse(`${end}T00:00:00Z`);
37
+ if (Number.isNaN(endTs))
38
+ return false;
39
+ const now = new Date;
40
+ const firstOfThisMonth = Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), 1);
41
+ return endTs <= firstOfThisMonth;
42
+ }
43
+ function ttlForPeriod(key) {
44
+ return isClosedPeriod(key.start, key.end) ? CLOSED_PERIOD_TTL_MS : OPEN_PERIOD_TTL_MS;
45
+ }
46
+ function loadCache(profile, key) {
47
+ const file = join(profileDir(profile), `${hashKey(key)}.json`);
48
+ if (!existsSync(file))
49
+ return null;
50
+ let entry;
51
+ try {
52
+ entry = JSON.parse(readFileSync(file, "utf-8"));
53
+ } catch {
54
+ return null;
55
+ }
56
+ if (entry.schema !== CACHE_SCHEMA_VERSION)
57
+ return null;
58
+ const ageMs = Date.now() - entry.savedAt;
59
+ if (ageMs < 0 || ageMs > ttlForPeriod(key))
60
+ return null;
61
+ return { response: entry.response, ageSeconds: Math.floor(ageMs / 1000) };
62
+ }
63
+ function saveCache(profile, key, response) {
64
+ const dir = profileDir(profile);
65
+ mkdirSync(dir, { recursive: true });
66
+ const entry = {
67
+ schema: CACHE_SCHEMA_VERSION,
68
+ savedAt: Date.now(),
69
+ key,
70
+ response
71
+ };
72
+ writeFileSync(join(dir, `${hashKey(key)}.json`), JSON.stringify(entry));
73
+ }
74
+
75
+ // src/aws/cost-explorer.ts
76
+ class CostExplorerClient {
77
+ client;
78
+ profile;
79
+ useCache;
80
+ lastCacheAgeSeconds = null;
81
+ constructor(profile, options) {
82
+ this.profile = profile;
83
+ this.useCache = options?.useCache ?? true;
84
+ this.client = new AWSClient(resolveCredentials(profile));
85
+ }
86
+ async getCostByService(params) {
87
+ const { start, end, granularity = "MONTHLY" } = params;
88
+ const metrics = ["UnblendedCost"];
89
+ const groupBy = [{ Type: "DIMENSION", Key: "SERVICE" }];
90
+ const cacheKey = { start, end, granularity, metrics, groupBy };
91
+ if (this.useCache) {
92
+ const hit = loadCache(this.profile, cacheKey);
93
+ if (hit) {
94
+ this.lastCacheAgeSeconds = hit.ageSeconds;
95
+ return hit.response;
96
+ }
97
+ }
98
+ this.lastCacheAgeSeconds = null;
99
+ const result = await this.client.request({
100
+ service: "ce",
101
+ region: "us-east-1",
102
+ method: "POST",
103
+ path: "/",
104
+ headers: {
105
+ "content-type": "application/x-amz-json-1.1",
106
+ "x-amz-target": "AWSInsightsIndexService.GetCostAndUsage"
107
+ },
108
+ body: JSON.stringify({
109
+ TimePeriod: { Start: start, End: end },
110
+ Granularity: granularity,
111
+ Metrics: metrics,
112
+ GroupBy: groupBy
113
+ })
114
+ });
115
+ const groups = result?.ResultsByTime?.[0]?.Groups ?? [];
116
+ const services = groups.map((g) => ({
117
+ service: g.Keys?.[0] ?? "Unknown",
118
+ amount: Number.parseFloat(g.Metrics?.UnblendedCost?.Amount ?? "0"),
119
+ unit: g.Metrics?.UnblendedCost?.Unit ?? "USD"
120
+ })).filter((g) => g.amount > 0).sort((a, b) => b.amount - a.amount);
121
+ if (this.useCache) {
122
+ saveCache(this.profile, cacheKey, services);
123
+ }
124
+ return services;
125
+ }
126
+ async getDailyTotals(params) {
127
+ const result = await this.client.request({
128
+ service: "ce",
129
+ region: "us-east-1",
130
+ method: "POST",
131
+ path: "/",
132
+ headers: {
133
+ "content-type": "application/x-amz-json-1.1",
134
+ "x-amz-target": "AWSInsightsIndexService.GetCostAndUsage"
135
+ },
136
+ body: JSON.stringify({
137
+ TimePeriod: { Start: params.start, End: params.end },
138
+ Granularity: "DAILY",
139
+ Metrics: ["UnblendedCost"]
140
+ })
141
+ });
142
+ const byTime = result?.ResultsByTime ?? [];
143
+ return byTime.map((t) => Number.parseFloat(t.Total?.UnblendedCost?.Amount ?? "0"));
144
+ }
145
+ }
146
+
147
+ // src/aws/secrets-manager.ts
148
+ class SecretsManagerClient {
149
+ client;
150
+ region;
151
+ constructor(region = "us-east-1", profile) {
152
+ this.region = region;
153
+ this.client = new AWSClient;
154
+ }
155
+ async createSecret(options) {
156
+ const params = {
157
+ Name: options.Name
158
+ };
159
+ if (options.Description) {
160
+ params.Description = options.Description;
161
+ }
162
+ if (options.KmsKeyId) {
163
+ params.KmsKeyId = options.KmsKeyId;
164
+ }
165
+ if (options.SecretBinary) {
166
+ params.SecretBinary = options.SecretBinary;
167
+ }
168
+ if (options.SecretString) {
169
+ params.SecretString = options.SecretString;
170
+ }
171
+ if (options.Tags && options.Tags.length > 0) {
172
+ params.Tags = options.Tags;
173
+ }
174
+ if (options.AddReplicaRegions && options.AddReplicaRegions.length > 0) {
175
+ params.AddReplicaRegions = options.AddReplicaRegions;
176
+ }
177
+ if (options.ForceOverwriteReplicaSecret !== undefined) {
178
+ params.ForceOverwriteReplicaSecret = options.ForceOverwriteReplicaSecret;
179
+ }
180
+ params.ClientRequestToken = options.ClientRequestToken || crypto.randomUUID();
181
+ const result = await this.client.request({
182
+ service: "secretsmanager",
183
+ region: this.region,
184
+ method: "POST",
185
+ path: "/",
186
+ headers: {
187
+ "X-Amz-Target": "secretsmanager.CreateSecret",
188
+ "Content-Type": "application/x-amz-json-1.1"
189
+ },
190
+ body: JSON.stringify(params)
191
+ });
192
+ return {
193
+ ARN: result.ARN,
194
+ Name: result.Name,
195
+ VersionId: result.VersionId,
196
+ ReplicationStatus: result.ReplicationStatus
197
+ };
198
+ }
199
+ async updateSecret(options) {
200
+ const params = {
201
+ SecretId: options.SecretId
202
+ };
203
+ if (options.Description) {
204
+ params.Description = options.Description;
205
+ }
206
+ if (options.KmsKeyId) {
207
+ params.KmsKeyId = options.KmsKeyId;
208
+ }
209
+ if (options.SecretBinary) {
210
+ params.SecretBinary = options.SecretBinary;
211
+ }
212
+ if (options.SecretString) {
213
+ params.SecretString = options.SecretString;
214
+ }
215
+ const result = await this.client.request({
216
+ service: "secretsmanager",
217
+ region: this.region,
218
+ method: "POST",
219
+ path: "/",
220
+ headers: {
221
+ "X-Amz-Target": "secretsmanager.UpdateSecret",
222
+ "Content-Type": "application/x-amz-json-1.1"
223
+ },
224
+ body: JSON.stringify(params)
225
+ });
226
+ return {
227
+ ARN: result.ARN,
228
+ Name: result.Name,
229
+ VersionId: result.VersionId
230
+ };
231
+ }
232
+ async putSecretValue(options) {
233
+ const params = {
234
+ SecretId: options.SecretId
235
+ };
236
+ if (options.SecretBinary) {
237
+ params.SecretBinary = options.SecretBinary;
238
+ }
239
+ if (options.SecretString) {
240
+ params.SecretString = options.SecretString;
241
+ }
242
+ if (options.VersionStages && options.VersionStages.length > 0) {
243
+ params.VersionStages = options.VersionStages;
244
+ }
245
+ if (options.ClientRequestToken) {
246
+ params.ClientRequestToken = options.ClientRequestToken;
247
+ }
248
+ const result = await this.client.request({
249
+ service: "secretsmanager",
250
+ region: this.region,
251
+ method: "POST",
252
+ path: "/",
253
+ headers: {
254
+ "X-Amz-Target": "secretsmanager.PutSecretValue",
255
+ "Content-Type": "application/x-amz-json-1.1"
256
+ },
257
+ body: JSON.stringify(params)
258
+ });
259
+ return {
260
+ ARN: result.ARN,
261
+ Name: result.Name,
262
+ VersionId: result.VersionId,
263
+ VersionStages: result.VersionStages
264
+ };
265
+ }
266
+ async getSecretValue(options) {
267
+ const params = {
268
+ SecretId: options.SecretId
269
+ };
270
+ if (options.VersionId) {
271
+ params.VersionId = options.VersionId;
272
+ }
273
+ if (options.VersionStage) {
274
+ params.VersionStage = options.VersionStage;
275
+ }
276
+ const result = await this.client.request({
277
+ service: "secretsmanager",
278
+ region: this.region,
279
+ method: "POST",
280
+ path: "/",
281
+ headers: {
282
+ "X-Amz-Target": "secretsmanager.GetSecretValue",
283
+ "Content-Type": "application/x-amz-json-1.1"
284
+ },
285
+ body: JSON.stringify(params)
286
+ });
287
+ return {
288
+ ARN: result.ARN,
289
+ Name: result.Name,
290
+ VersionId: result.VersionId,
291
+ SecretBinary: result.SecretBinary,
292
+ SecretString: result.SecretString,
293
+ VersionStages: result.VersionStages,
294
+ CreatedDate: result.CreatedDate
295
+ };
296
+ }
297
+ async describeSecret(secretId) {
298
+ const params = {
299
+ SecretId: secretId
300
+ };
301
+ const result = await this.client.request({
302
+ service: "secretsmanager",
303
+ region: this.region,
304
+ method: "POST",
305
+ path: "/",
306
+ headers: {
307
+ "X-Amz-Target": "secretsmanager.DescribeSecret",
308
+ "Content-Type": "application/x-amz-json-1.1"
309
+ },
310
+ body: JSON.stringify(params)
311
+ });
312
+ return this.parseSecret(result);
313
+ }
314
+ async listSecrets(options) {
315
+ const params = {};
316
+ if (options?.MaxResults) {
317
+ params.MaxResults = options.MaxResults;
318
+ }
319
+ if (options?.NextToken) {
320
+ params.NextToken = options.NextToken;
321
+ }
322
+ if (options?.Filters && options.Filters.length > 0) {
323
+ params.Filters = options.Filters;
324
+ }
325
+ if (options?.SortOrder) {
326
+ params.SortOrder = options.SortOrder;
327
+ }
328
+ const result = await this.client.request({
329
+ service: "secretsmanager",
330
+ region: this.region,
331
+ method: "POST",
332
+ path: "/",
333
+ headers: {
334
+ "X-Amz-Target": "secretsmanager.ListSecrets",
335
+ "Content-Type": "application/x-amz-json-1.1"
336
+ },
337
+ body: JSON.stringify(params)
338
+ });
339
+ return {
340
+ SecretList: result.SecretList?.map((s) => this.parseSecret(s)),
341
+ NextToken: result.NextToken
342
+ };
343
+ }
344
+ async deleteSecret(options) {
345
+ const params = {
346
+ SecretId: options.SecretId
347
+ };
348
+ if (options.RecoveryWindowInDays !== undefined) {
349
+ params.RecoveryWindowInDays = options.RecoveryWindowInDays;
350
+ }
351
+ if (options.ForceDeleteWithoutRecovery !== undefined) {
352
+ params.ForceDeleteWithoutRecovery = options.ForceDeleteWithoutRecovery;
353
+ }
354
+ const result = await this.client.request({
355
+ service: "secretsmanager",
356
+ region: this.region,
357
+ method: "POST",
358
+ path: "/",
359
+ headers: {
360
+ "X-Amz-Target": "secretsmanager.DeleteSecret",
361
+ "Content-Type": "application/x-amz-json-1.1"
362
+ },
363
+ body: JSON.stringify(params)
364
+ });
365
+ return {
366
+ ARN: result.ARN,
367
+ Name: result.Name,
368
+ DeletionDate: result.DeletionDate
369
+ };
370
+ }
371
+ async restoreSecret(secretId) {
372
+ const params = {
373
+ SecretId: secretId
374
+ };
375
+ const result = await this.client.request({
376
+ service: "secretsmanager",
377
+ region: this.region,
378
+ method: "POST",
379
+ path: "/",
380
+ headers: {
381
+ "X-Amz-Target": "secretsmanager.RestoreSecret",
382
+ "Content-Type": "application/x-amz-json-1.1"
383
+ },
384
+ body: JSON.stringify(params)
385
+ });
386
+ return {
387
+ ARN: result.ARN,
388
+ Name: result.Name
389
+ };
390
+ }
391
+ async rotateSecret(options) {
392
+ const params = {
393
+ SecretId: options.SecretId
394
+ };
395
+ if (options.ClientRequestToken) {
396
+ params.ClientRequestToken = options.ClientRequestToken;
397
+ }
398
+ if (options.RotationLambdaARN) {
399
+ params.RotationLambdaARN = options.RotationLambdaARN;
400
+ }
401
+ if (options.RotationRules) {
402
+ params.RotationRules = options.RotationRules;
403
+ }
404
+ if (options.RotateImmediately !== undefined) {
405
+ params.RotateImmediately = options.RotateImmediately;
406
+ }
407
+ const result = await this.client.request({
408
+ service: "secretsmanager",
409
+ region: this.region,
410
+ method: "POST",
411
+ path: "/",
412
+ headers: {
413
+ "X-Amz-Target": "secretsmanager.RotateSecret",
414
+ "Content-Type": "application/x-amz-json-1.1"
415
+ },
416
+ body: JSON.stringify(params)
417
+ });
418
+ return {
419
+ ARN: result.ARN,
420
+ Name: result.Name,
421
+ VersionId: result.VersionId
422
+ };
423
+ }
424
+ async cancelRotateSecret(secretId) {
425
+ const params = {
426
+ SecretId: secretId
427
+ };
428
+ const result = await this.client.request({
429
+ service: "secretsmanager",
430
+ region: this.region,
431
+ method: "POST",
432
+ path: "/",
433
+ headers: {
434
+ "X-Amz-Target": "secretsmanager.CancelRotateSecret",
435
+ "Content-Type": "application/x-amz-json-1.1"
436
+ },
437
+ body: JSON.stringify(params)
438
+ });
439
+ return {
440
+ ARN: result.ARN,
441
+ Name: result.Name
442
+ };
443
+ }
444
+ async getResourcePolicy(secretId) {
445
+ const params = {
446
+ SecretId: secretId
447
+ };
448
+ const result = await this.client.request({
449
+ service: "secretsmanager",
450
+ region: this.region,
451
+ method: "POST",
452
+ path: "/",
453
+ headers: {
454
+ "X-Amz-Target": "secretsmanager.GetResourcePolicy",
455
+ "Content-Type": "application/x-amz-json-1.1"
456
+ },
457
+ body: JSON.stringify(params)
458
+ });
459
+ return {
460
+ ARN: result.ARN,
461
+ Name: result.Name,
462
+ ResourcePolicy: result.ResourcePolicy
463
+ };
464
+ }
465
+ async putResourcePolicy(options) {
466
+ const params = {
467
+ SecretId: options.SecretId,
468
+ ResourcePolicy: options.ResourcePolicy
469
+ };
470
+ if (options.BlockPublicPolicy !== undefined) {
471
+ params.BlockPublicPolicy = options.BlockPublicPolicy;
472
+ }
473
+ const result = await this.client.request({
474
+ service: "secretsmanager",
475
+ region: this.region,
476
+ method: "POST",
477
+ path: "/",
478
+ headers: {
479
+ "X-Amz-Target": "secretsmanager.PutResourcePolicy",
480
+ "Content-Type": "application/x-amz-json-1.1"
481
+ },
482
+ body: JSON.stringify(params)
483
+ });
484
+ return {
485
+ ARN: result.ARN,
486
+ Name: result.Name
487
+ };
488
+ }
489
+ async deleteResourcePolicy(secretId) {
490
+ const params = {
491
+ SecretId: secretId
492
+ };
493
+ const result = await this.client.request({
494
+ service: "secretsmanager",
495
+ region: this.region,
496
+ method: "POST",
497
+ path: "/",
498
+ headers: {
499
+ "X-Amz-Target": "secretsmanager.DeleteResourcePolicy",
500
+ "Content-Type": "application/x-amz-json-1.1"
501
+ },
502
+ body: JSON.stringify(params)
503
+ });
504
+ return {
505
+ ARN: result.ARN,
506
+ Name: result.Name
507
+ };
508
+ }
509
+ async tagResource(options) {
510
+ const params = {
511
+ SecretId: options.SecretId,
512
+ Tags: options.Tags
513
+ };
514
+ await this.client.request({
515
+ service: "secretsmanager",
516
+ region: this.region,
517
+ method: "POST",
518
+ path: "/",
519
+ headers: {
520
+ "X-Amz-Target": "secretsmanager.TagResource",
521
+ "Content-Type": "application/x-amz-json-1.1"
522
+ },
523
+ body: JSON.stringify(params)
524
+ });
525
+ }
526
+ async untagResource(options) {
527
+ const params = {
528
+ SecretId: options.SecretId,
529
+ TagKeys: options.TagKeys
530
+ };
531
+ await this.client.request({
532
+ service: "secretsmanager",
533
+ region: this.region,
534
+ method: "POST",
535
+ path: "/",
536
+ headers: {
537
+ "X-Amz-Target": "secretsmanager.UntagResource",
538
+ "Content-Type": "application/x-amz-json-1.1"
539
+ },
540
+ body: JSON.stringify(params)
541
+ });
542
+ }
543
+ async setString(name, value, options) {
544
+ try {
545
+ const result = await this.putSecretValue({
546
+ SecretId: name,
547
+ SecretString: value
548
+ });
549
+ return { ARN: result.ARN, VersionId: result.VersionId };
550
+ } catch (error) {
551
+ if (error.code === "ResourceNotFoundException") {
552
+ const result = await this.createSecret({
553
+ Name: name,
554
+ SecretString: value,
555
+ Description: options?.description,
556
+ KmsKeyId: options?.kmsKeyId,
557
+ Tags: options?.tags
558
+ });
559
+ return { ARN: result.ARN, VersionId: result.VersionId };
560
+ }
561
+ throw error;
562
+ }
563
+ }
564
+ async setJson(name, value, options) {
565
+ return this.setString(name, JSON.stringify(value), options);
566
+ }
567
+ async getString(secretId) {
568
+ const result = await this.getSecretValue({ SecretId: secretId });
569
+ return result.SecretString;
570
+ }
571
+ async getJson(secretId) {
572
+ const str = await this.getString(secretId);
573
+ if (str) {
574
+ return JSON.parse(str);
575
+ }
576
+ return;
577
+ }
578
+ async listAll() {
579
+ const allSecrets = [];
580
+ let nextToken;
581
+ do {
582
+ const result = await this.listSecrets({ NextToken: nextToken });
583
+ if (result.SecretList) {
584
+ allSecrets.push(...result.SecretList);
585
+ }
586
+ nextToken = result.NextToken;
587
+ } while (nextToken);
588
+ return allSecrets;
589
+ }
590
+ parseSecret(s) {
591
+ return {
592
+ ARN: s.ARN,
593
+ Name: s.Name,
594
+ Description: s.Description,
595
+ KmsKeyId: s.KmsKeyId,
596
+ RotationEnabled: s.RotationEnabled,
597
+ RotationLambdaARN: s.RotationLambdaARN,
598
+ RotationRules: s.RotationRules,
599
+ LastRotatedDate: s.LastRotatedDate,
600
+ LastChangedDate: s.LastChangedDate,
601
+ LastAccessedDate: s.LastAccessedDate,
602
+ DeletedDate: s.DeletedDate,
603
+ NextRotationDate: s.NextRotationDate,
604
+ Tags: s.Tags,
605
+ SecretVersionsToStages: s.SecretVersionsToStages,
606
+ CreatedDate: s.CreatedDate,
607
+ PrimaryRegion: s.PrimaryRegion
608
+ };
609
+ }
610
+ }
611
+
612
+ // src/aws/sqs.ts
613
+ class SQSClient {
614
+ client;
615
+ region;
616
+ constructor(region = "us-east-1", profile) {
617
+ this.region = region;
618
+ this.client = new AWSClient;
619
+ }
620
+ async createQueue(options) {
621
+ const queueName = options.fifo && !options.queueName.endsWith(".fifo") ? `${options.queueName}.fifo` : options.queueName;
622
+ const params = {
623
+ Action: "CreateQueue",
624
+ QueueName: queueName,
625
+ Version: "2012-11-05"
626
+ };
627
+ let attrIndex = 1;
628
+ if (options.visibilityTimeout !== undefined) {
629
+ params[`Attribute.${attrIndex}.Name`] = "VisibilityTimeout";
630
+ params[`Attribute.${attrIndex}.Value`] = options.visibilityTimeout.toString();
631
+ attrIndex++;
632
+ }
633
+ if (options.messageRetentionPeriod !== undefined) {
634
+ params[`Attribute.${attrIndex}.Name`] = "MessageRetentionPeriod";
635
+ params[`Attribute.${attrIndex}.Value`] = options.messageRetentionPeriod.toString();
636
+ attrIndex++;
637
+ }
638
+ if (options.delaySeconds !== undefined) {
639
+ params[`Attribute.${attrIndex}.Name`] = "DelaySeconds";
640
+ params[`Attribute.${attrIndex}.Value`] = options.delaySeconds.toString();
641
+ attrIndex++;
642
+ }
643
+ if (options.maxMessageSize !== undefined) {
644
+ params[`Attribute.${attrIndex}.Name`] = "MaximumMessageSize";
645
+ params[`Attribute.${attrIndex}.Value`] = options.maxMessageSize.toString();
646
+ attrIndex++;
647
+ }
648
+ if (options.receiveMessageWaitTime !== undefined) {
649
+ params[`Attribute.${attrIndex}.Name`] = "ReceiveMessageWaitTimeSeconds";
650
+ params[`Attribute.${attrIndex}.Value`] = options.receiveMessageWaitTime.toString();
651
+ attrIndex++;
652
+ }
653
+ if (options.fifo) {
654
+ params[`Attribute.${attrIndex}.Name`] = "FifoQueue";
655
+ params[`Attribute.${attrIndex}.Value`] = "true";
656
+ attrIndex++;
657
+ if (options.contentBasedDeduplication) {
658
+ params[`Attribute.${attrIndex}.Name`] = "ContentBasedDeduplication";
659
+ params[`Attribute.${attrIndex}.Value`] = "true";
660
+ attrIndex++;
661
+ }
662
+ }
663
+ if (options.deadLetterTargetArn && options.maxReceiveCount) {
664
+ params[`Attribute.${attrIndex}.Name`] = "RedrivePolicy";
665
+ params[`Attribute.${attrIndex}.Value`] = JSON.stringify({
666
+ deadLetterTargetArn: options.deadLetterTargetArn,
667
+ maxReceiveCount: options.maxReceiveCount
668
+ });
669
+ attrIndex++;
670
+ }
671
+ if (options.tags && Object.keys(options.tags).length > 0) {
672
+ let tagIndex = 1;
673
+ for (const [key, value] of Object.entries(options.tags)) {
674
+ params[`Tag.${tagIndex}.Key`] = key;
675
+ params[`Tag.${tagIndex}.Value`] = value;
676
+ tagIndex++;
677
+ }
678
+ }
679
+ const result = await this.client.request({
680
+ service: "sqs",
681
+ region: this.region,
682
+ method: "POST",
683
+ path: "/",
684
+ body: new URLSearchParams(params).toString()
685
+ });
686
+ return { QueueUrl: result.QueueUrl || result.CreateQueueResult?.QueueUrl };
687
+ }
688
+ async listQueues(prefix) {
689
+ const params = {
690
+ Action: "ListQueues",
691
+ Version: "2012-11-05"
692
+ };
693
+ if (prefix) {
694
+ params.QueueNamePrefix = prefix;
695
+ }
696
+ const result = await this.client.request({
697
+ service: "sqs",
698
+ region: this.region,
699
+ method: "POST",
700
+ path: "/",
701
+ body: new URLSearchParams(params).toString()
702
+ });
703
+ const queueUrls = [];
704
+ if (result.QueueUrl) {
705
+ queueUrls.push(result.QueueUrl);
706
+ } else if (result.ListQueuesResult?.QueueUrl) {
707
+ if (Array.isArray(result.ListQueuesResult.QueueUrl)) {
708
+ queueUrls.push(...result.ListQueuesResult.QueueUrl);
709
+ } else {
710
+ queueUrls.push(result.ListQueuesResult.QueueUrl);
711
+ }
712
+ }
713
+ return { QueueUrls: queueUrls };
714
+ }
715
+ async getQueueAttributes(queueUrl) {
716
+ const params = {
717
+ Action: "GetQueueAttributes",
718
+ QueueUrl: queueUrl,
719
+ Version: "2012-11-05",
720
+ "AttributeName.1": "All"
721
+ };
722
+ const result = await this.client.request({
723
+ service: "sqs",
724
+ region: this.region,
725
+ method: "POST",
726
+ path: "/",
727
+ body: new URLSearchParams(params).toString()
728
+ });
729
+ return { Attributes: result.Attributes || result.GetQueueAttributesResult?.Attributes || {} };
730
+ }
731
+ async getQueueUrl(queueName) {
732
+ const params = {
733
+ Action: "GetQueueUrl",
734
+ QueueName: queueName,
735
+ Version: "2012-11-05"
736
+ };
737
+ const result = await this.client.request({
738
+ service: "sqs",
739
+ region: this.region,
740
+ method: "POST",
741
+ path: "/",
742
+ body: new URLSearchParams(params).toString()
743
+ });
744
+ return { QueueUrl: result.QueueUrl || result.GetQueueUrlResult?.QueueUrl };
745
+ }
746
+ async deleteQueue(queueUrl) {
747
+ const params = {
748
+ Action: "DeleteQueue",
749
+ QueueUrl: queueUrl,
750
+ Version: "2012-11-05"
751
+ };
752
+ await this.client.request({
753
+ service: "sqs",
754
+ region: this.region,
755
+ method: "POST",
756
+ path: "/",
757
+ body: new URLSearchParams(params).toString()
758
+ });
759
+ }
760
+ async purgeQueue(queueUrl) {
761
+ const params = {
762
+ Action: "PurgeQueue",
763
+ QueueUrl: queueUrl,
764
+ Version: "2012-11-05"
765
+ };
766
+ await this.client.request({
767
+ service: "sqs",
768
+ region: this.region,
769
+ method: "POST",
770
+ path: "/",
771
+ body: new URLSearchParams(params).toString()
772
+ });
773
+ }
774
+ async sendMessage(options) {
775
+ const params = {
776
+ Action: "SendMessage",
777
+ QueueUrl: options.queueUrl,
778
+ MessageBody: options.messageBody,
779
+ Version: "2012-11-05"
780
+ };
781
+ if (options.delaySeconds !== undefined) {
782
+ params.DelaySeconds = options.delaySeconds;
783
+ }
784
+ if (options.messageGroupId) {
785
+ params.MessageGroupId = options.messageGroupId;
786
+ }
787
+ if (options.messageDeduplicationId) {
788
+ params.MessageDeduplicationId = options.messageDeduplicationId;
789
+ }
790
+ const result = await this.client.request({
791
+ service: "sqs",
792
+ region: this.region,
793
+ method: "POST",
794
+ path: "/",
795
+ body: new URLSearchParams(params).toString()
796
+ });
797
+ return { MessageId: result.MessageId || result.SendMessageResult?.MessageId };
798
+ }
799
+ async receiveMessages(options) {
800
+ const params = {
801
+ Action: "ReceiveMessage",
802
+ QueueUrl: options.queueUrl,
803
+ Version: "2012-11-05"
804
+ };
805
+ if (options.maxMessages !== undefined) {
806
+ params.MaxNumberOfMessages = options.maxMessages;
807
+ }
808
+ if (options.visibilityTimeout !== undefined) {
809
+ params.VisibilityTimeout = options.visibilityTimeout;
810
+ }
811
+ if (options.waitTimeSeconds !== undefined) {
812
+ params.WaitTimeSeconds = options.waitTimeSeconds;
813
+ }
814
+ const result = await this.client.request({
815
+ service: "sqs",
816
+ region: this.region,
817
+ method: "POST",
818
+ path: "/",
819
+ body: new URLSearchParams(params).toString()
820
+ });
821
+ const messages = [];
822
+ const msgData = result.Message || result.ReceiveMessageResult?.Message;
823
+ if (msgData) {
824
+ if (Array.isArray(msgData)) {
825
+ messages.push(...msgData.map((m) => ({
826
+ MessageId: m.MessageId,
827
+ ReceiptHandle: m.ReceiptHandle,
828
+ Body: m.Body
829
+ })));
830
+ } else {
831
+ messages.push({
832
+ MessageId: msgData.MessageId,
833
+ ReceiptHandle: msgData.ReceiptHandle,
834
+ Body: msgData.Body
835
+ });
836
+ }
837
+ }
838
+ return { Messages: messages };
839
+ }
840
+ async deleteMessage(queueUrl, receiptHandle) {
841
+ const params = {
842
+ Action: "DeleteMessage",
843
+ QueueUrl: queueUrl,
844
+ ReceiptHandle: receiptHandle,
845
+ Version: "2012-11-05"
846
+ };
847
+ await this.client.request({
848
+ service: "sqs",
849
+ region: this.region,
850
+ method: "POST",
851
+ path: "/",
852
+ body: new URLSearchParams(params).toString()
853
+ });
854
+ }
855
+ }
856
+
857
+ // src/aws/lambda.ts
858
+ import { deflateRawSync } from "zlib";
859
+ function createZipFile(filename, content) {
860
+ const data = typeof content === "string" ? Buffer.from(content, "utf-8") : content;
861
+ const compressedData = deflateRawSync(data);
862
+ const crc32 = calculateCrc32(data);
863
+ const now = new Date;
864
+ const dosTime = (now.getHours() << 11 | now.getMinutes() << 5 | now.getSeconds() >> 1) & 65535;
865
+ const dosDate = (now.getFullYear() - 1980 << 9 | now.getMonth() + 1 << 5 | now.getDate()) & 65535;
866
+ const filenameBuffer = Buffer.from(filename, "utf-8");
867
+ const localHeader = Buffer.alloc(30 + filenameBuffer.length);
868
+ localHeader.writeUInt32LE(67324752, 0);
869
+ localHeader.writeUInt16LE(20, 4);
870
+ localHeader.writeUInt16LE(0, 6);
871
+ localHeader.writeUInt16LE(8, 8);
872
+ localHeader.writeUInt16LE(dosTime, 10);
873
+ localHeader.writeUInt16LE(dosDate, 12);
874
+ localHeader.writeUInt32LE(crc32, 14);
875
+ localHeader.writeUInt32LE(compressedData.length, 18);
876
+ localHeader.writeUInt32LE(data.length, 22);
877
+ localHeader.writeUInt16LE(filenameBuffer.length, 26);
878
+ localHeader.writeUInt16LE(0, 28);
879
+ filenameBuffer.copy(localHeader, 30);
880
+ const centralHeader = Buffer.alloc(46 + filenameBuffer.length);
881
+ centralHeader.writeUInt32LE(33639248, 0);
882
+ centralHeader.writeUInt16LE(20, 4);
883
+ centralHeader.writeUInt16LE(20, 6);
884
+ centralHeader.writeUInt16LE(0, 8);
885
+ centralHeader.writeUInt16LE(8, 10);
886
+ centralHeader.writeUInt16LE(dosTime, 12);
887
+ centralHeader.writeUInt16LE(dosDate, 14);
888
+ centralHeader.writeUInt32LE(crc32, 16);
889
+ centralHeader.writeUInt32LE(compressedData.length, 20);
890
+ centralHeader.writeUInt32LE(data.length, 24);
891
+ centralHeader.writeUInt16LE(filenameBuffer.length, 28);
892
+ centralHeader.writeUInt16LE(0, 30);
893
+ centralHeader.writeUInt16LE(0, 32);
894
+ centralHeader.writeUInt16LE(0, 34);
895
+ centralHeader.writeUInt16LE(0, 36);
896
+ centralHeader.writeUInt32LE(0, 38);
897
+ centralHeader.writeUInt32LE(0, 42);
898
+ filenameBuffer.copy(centralHeader, 46);
899
+ const centralDirOffset = localHeader.length + compressedData.length;
900
+ const centralDirSize = centralHeader.length;
901
+ const endRecord = Buffer.alloc(22);
902
+ endRecord.writeUInt32LE(101010256, 0);
903
+ endRecord.writeUInt16LE(0, 4);
904
+ endRecord.writeUInt16LE(0, 6);
905
+ endRecord.writeUInt16LE(1, 8);
906
+ endRecord.writeUInt16LE(1, 10);
907
+ endRecord.writeUInt32LE(centralDirSize, 12);
908
+ endRecord.writeUInt32LE(centralDirOffset, 16);
909
+ endRecord.writeUInt16LE(0, 20);
910
+ return Buffer.concat([localHeader, compressedData, centralHeader, endRecord]);
911
+ }
912
+ function calculateCrc32(data) {
913
+ const table = [];
914
+ for (let i = 0;i < 256; i++) {
915
+ let c = i;
916
+ for (let j = 0;j < 8; j++) {
917
+ c = c & 1 ? 3988292384 ^ c >>> 1 : c >>> 1;
918
+ }
919
+ table[i] = c;
920
+ }
921
+ let crc = 4294967295;
922
+ for (let i = 0;i < data.length; i++) {
923
+ crc = table[(crc ^ data[i]) & 255] ^ crc >>> 8;
924
+ }
925
+ return (crc ^ 4294967295) >>> 0;
926
+ }
927
+
928
+ class LambdaClient {
929
+ client;
930
+ region;
931
+ constructor(region = "us-east-1") {
932
+ this.region = region;
933
+ this.client = new AWSClient;
934
+ }
935
+ async createFunction(params) {
936
+ const result = await this.client.request({
937
+ service: "lambda",
938
+ region: this.region,
939
+ method: "POST",
940
+ path: "/2015-03-31/functions",
941
+ headers: {
942
+ "Content-Type": "application/json"
943
+ },
944
+ body: JSON.stringify(params)
945
+ });
946
+ return result;
947
+ }
948
+ async getFunction(functionName) {
949
+ const result = await this.client.request({
950
+ service: "lambda",
951
+ region: this.region,
952
+ method: "GET",
953
+ path: `/2015-03-31/functions/${encodeURIComponent(functionName)}`,
954
+ headers: {
955
+ "Content-Type": "application/json"
956
+ }
957
+ });
958
+ return result;
959
+ }
960
+ async updateFunctionCode(params) {
961
+ const { FunctionName, ...rest } = params;
962
+ const result = await this.client.request({
963
+ service: "lambda",
964
+ region: this.region,
965
+ method: "PUT",
966
+ path: `/2015-03-31/functions/${encodeURIComponent(FunctionName)}/code`,
967
+ headers: {
968
+ "Content-Type": "application/json"
969
+ },
970
+ body: JSON.stringify(rest)
971
+ });
972
+ return result;
973
+ }
974
+ async updateFunctionCodeInline(functionName, code, filename = "index.js") {
975
+ const zipBuffer = createZipFile(filename, code);
976
+ return this.updateFunctionCode({
977
+ FunctionName: functionName,
978
+ ZipFile: zipBuffer.toString("base64")
979
+ });
980
+ }
981
+ async updateFunctionConfiguration(params) {
982
+ const { FunctionName, ...rest } = params;
983
+ const result = await this.client.request({
984
+ service: "lambda",
985
+ region: this.region,
986
+ method: "PUT",
987
+ path: `/2015-03-31/functions/${encodeURIComponent(FunctionName)}/configuration`,
988
+ headers: {
989
+ "Content-Type": "application/json"
990
+ },
991
+ body: JSON.stringify(rest)
992
+ });
993
+ return result;
994
+ }
995
+ async deleteFunction(functionName) {
996
+ await this.client.request({
997
+ service: "lambda",
998
+ region: this.region,
999
+ method: "DELETE",
1000
+ path: `/2015-03-31/functions/${encodeURIComponent(functionName)}`,
1001
+ headers: {
1002
+ "Content-Type": "application/json"
1003
+ }
1004
+ });
1005
+ }
1006
+ async invoke(params) {
1007
+ const { FunctionName, InvocationType = "RequestResponse", Payload, LogType } = params;
1008
+ const headers = {
1009
+ "Content-Type": "application/json",
1010
+ "X-Amz-Invocation-Type": InvocationType
1011
+ };
1012
+ if (LogType) {
1013
+ headers["X-Amz-Log-Type"] = LogType;
1014
+ }
1015
+ const body = Payload ? typeof Payload === "string" ? Payload : JSON.stringify(Payload) : undefined;
1016
+ const result = await this.client.request({
1017
+ service: "lambda",
1018
+ region: this.region,
1019
+ method: "POST",
1020
+ path: `/2015-03-31/functions/${encodeURIComponent(FunctionName)}/invocations`,
1021
+ headers,
1022
+ body,
1023
+ returnHeaders: true
1024
+ });
1025
+ return {
1026
+ StatusCode: result.statusCode || 200,
1027
+ FunctionError: result.headers?.["x-amz-function-error"],
1028
+ LogResult: result.headers?.["x-amz-log-result"],
1029
+ Payload: typeof result.body === "string" ? result.body : JSON.stringify(result.body),
1030
+ ExecutedVersion: result.headers?.["x-amz-executed-version"]
1031
+ };
1032
+ }
1033
+ async listFunctions(params) {
1034
+ const queryParams = {};
1035
+ if (params?.MaxItems)
1036
+ queryParams.MaxItems = String(params.MaxItems);
1037
+ if (params?.Marker)
1038
+ queryParams.Marker = params.Marker;
1039
+ if (params?.FunctionVersion)
1040
+ queryParams.FunctionVersion = params.FunctionVersion;
1041
+ const result = await this.client.request({
1042
+ service: "lambda",
1043
+ region: this.region,
1044
+ method: "GET",
1045
+ path: "/2015-03-31/functions",
1046
+ queryParams: Object.keys(queryParams).length > 0 ? queryParams : undefined,
1047
+ headers: {
1048
+ "Content-Type": "application/json"
1049
+ }
1050
+ });
1051
+ return result;
1052
+ }
1053
+ async addPermission(params) {
1054
+ const { FunctionName, ...rest } = params;
1055
+ const result = await this.client.request({
1056
+ service: "lambda",
1057
+ region: this.region,
1058
+ method: "POST",
1059
+ path: `/2015-03-31/functions/${encodeURIComponent(FunctionName)}/policy`,
1060
+ headers: {
1061
+ "Content-Type": "application/json"
1062
+ },
1063
+ body: JSON.stringify(rest)
1064
+ });
1065
+ return result;
1066
+ }
1067
+ async removePermission(functionName, statementId) {
1068
+ await this.client.request({
1069
+ service: "lambda",
1070
+ region: this.region,
1071
+ method: "DELETE",
1072
+ path: `/2015-03-31/functions/${encodeURIComponent(functionName)}/policy/${encodeURIComponent(statementId)}`,
1073
+ headers: {
1074
+ "Content-Type": "application/json"
1075
+ }
1076
+ });
1077
+ }
1078
+ async publishVersion(params) {
1079
+ const { FunctionName, ...rest } = params;
1080
+ const result = await this.client.request({
1081
+ service: "lambda",
1082
+ region: this.region,
1083
+ method: "POST",
1084
+ path: `/2015-03-31/functions/${encodeURIComponent(FunctionName)}/versions`,
1085
+ headers: {
1086
+ "Content-Type": "application/json"
1087
+ },
1088
+ body: JSON.stringify(rest)
1089
+ });
1090
+ return result;
1091
+ }
1092
+ async createAlias(params) {
1093
+ const { FunctionName, ...rest } = params;
1094
+ const result = await this.client.request({
1095
+ service: "lambda",
1096
+ region: this.region,
1097
+ method: "POST",
1098
+ path: `/2015-03-31/functions/${encodeURIComponent(FunctionName)}/aliases`,
1099
+ headers: {
1100
+ "Content-Type": "application/json"
1101
+ },
1102
+ body: JSON.stringify(rest)
1103
+ });
1104
+ return result;
1105
+ }
1106
+ async updateAlias(params) {
1107
+ const { FunctionName, Name, ...rest } = params;
1108
+ return this.client.request({
1109
+ service: "lambda",
1110
+ region: this.region,
1111
+ method: "PUT",
1112
+ path: `/2015-03-31/functions/${encodeURIComponent(FunctionName)}/aliases/${encodeURIComponent(Name)}`,
1113
+ headers: { "Content-Type": "application/json" },
1114
+ body: JSON.stringify(rest)
1115
+ });
1116
+ }
1117
+ async getAlias(functionName, name) {
1118
+ try {
1119
+ return await this.client.request({
1120
+ service: "lambda",
1121
+ region: this.region,
1122
+ method: "GET",
1123
+ path: `/2015-03-31/functions/${encodeURIComponent(functionName)}/aliases/${encodeURIComponent(name)}`
1124
+ });
1125
+ } catch (err) {
1126
+ if (/ResourceNotFound/i.test(String(err?.message)))
1127
+ return null;
1128
+ throw err;
1129
+ }
1130
+ }
1131
+ async getProvisionedConcurrencyConfig(functionName, qualifier) {
1132
+ try {
1133
+ return await this.client.request({
1134
+ service: "lambda",
1135
+ region: this.region,
1136
+ method: "GET",
1137
+ path: `/2019-09-30/functions/${encodeURIComponent(functionName)}/provisioned-concurrency`,
1138
+ queryParams: { Qualifier: qualifier }
1139
+ });
1140
+ } catch (err) {
1141
+ if (/ProvisionedConcurrencyConfigNotFound|ResourceNotFound/i.test(String(err?.message)))
1142
+ return null;
1143
+ throw err;
1144
+ }
1145
+ }
1146
+ async putProvisionedConcurrencyConfig(params) {
1147
+ const { FunctionName, Qualifier, ProvisionedConcurrentExecutions } = params;
1148
+ return this.client.request({
1149
+ service: "lambda",
1150
+ region: this.region,
1151
+ method: "PUT",
1152
+ path: `/2019-09-30/functions/${encodeURIComponent(FunctionName)}/provisioned-concurrency`,
1153
+ queryParams: { Qualifier },
1154
+ headers: { "Content-Type": "application/json" },
1155
+ body: JSON.stringify({ ProvisionedConcurrentExecutions })
1156
+ });
1157
+ }
1158
+ async deleteProvisionedConcurrencyConfig(functionName, qualifier) {
1159
+ await this.client.request({
1160
+ service: "lambda",
1161
+ region: this.region,
1162
+ method: "DELETE",
1163
+ path: `/2019-09-30/functions/${encodeURIComponent(functionName)}/provisioned-concurrency`,
1164
+ queryParams: { Qualifier: qualifier }
1165
+ });
1166
+ }
1167
+ async waitForFunctionActive(functionName, maxWaitSeconds = 60) {
1168
+ const startTime = Date.now();
1169
+ const maxWaitMs = maxWaitSeconds * 1000;
1170
+ while (Date.now() - startTime < maxWaitMs) {
1171
+ try {
1172
+ const response = await this.getFunction(functionName);
1173
+ const state = response.Configuration?.State;
1174
+ if (state === "Active") {
1175
+ return response.Configuration;
1176
+ }
1177
+ if (state === "Failed") {
1178
+ throw new Error(`Function ${functionName} failed: ${response.Configuration?.StateReason}`);
1179
+ }
1180
+ await new Promise((resolve) => setTimeout(resolve, 2000));
1181
+ } catch (error) {
1182
+ if (error.code === "ResourceNotFoundException") {
1183
+ await new Promise((resolve) => setTimeout(resolve, 2000));
1184
+ continue;
1185
+ }
1186
+ throw error;
1187
+ }
1188
+ }
1189
+ throw new Error(`Timeout waiting for function ${functionName} to become active`);
1190
+ }
1191
+ async functionExists(functionName) {
1192
+ try {
1193
+ await this.getFunction(functionName);
1194
+ return true;
1195
+ } catch (error) {
1196
+ if (error.code === "ResourceNotFoundException" || error.statusCode === 404) {
1197
+ return false;
1198
+ }
1199
+ throw error;
1200
+ }
1201
+ }
1202
+ async createFunctionUrl(params) {
1203
+ const { FunctionName, ...rest } = params;
1204
+ const result = await this.client.request({
1205
+ service: "lambda",
1206
+ region: this.region,
1207
+ method: "POST",
1208
+ path: `/2021-10-31/functions/${encodeURIComponent(FunctionName)}/url`,
1209
+ headers: {
1210
+ "Content-Type": "application/json"
1211
+ },
1212
+ body: JSON.stringify(rest)
1213
+ });
1214
+ return result;
1215
+ }
1216
+ async getFunctionUrl(functionName) {
1217
+ try {
1218
+ const result = await this.client.request({
1219
+ service: "lambda",
1220
+ region: this.region,
1221
+ method: "GET",
1222
+ path: `/2021-10-31/functions/${encodeURIComponent(functionName)}/url`,
1223
+ headers: {
1224
+ "Content-Type": "application/json"
1225
+ }
1226
+ });
1227
+ return result;
1228
+ } catch (error) {
1229
+ if (error.statusCode === 404) {
1230
+ return null;
1231
+ }
1232
+ throw error;
1233
+ }
1234
+ }
1235
+ async deleteFunctionUrl(functionName) {
1236
+ await this.client.request({
1237
+ service: "lambda",
1238
+ region: this.region,
1239
+ method: "DELETE",
1240
+ path: `/2021-10-31/functions/${encodeURIComponent(functionName)}/url`,
1241
+ headers: {
1242
+ "Content-Type": "application/json"
1243
+ }
1244
+ });
1245
+ }
1246
+ async createFunctionWithCode(params) {
1247
+ const { Code, Filename = "index.js", ...rest } = params;
1248
+ const zipBuffer = createZipFile(Filename, Code);
1249
+ return this.createFunction({
1250
+ ...rest,
1251
+ Code: {
1252
+ ZipFile: zipBuffer.toString("base64")
1253
+ }
1254
+ });
1255
+ }
1256
+ async addFunctionUrlPermission(functionName) {
1257
+ return this.addPermission({
1258
+ FunctionName: functionName,
1259
+ StatementId: "FunctionURLAllowPublicAccess",
1260
+ Action: "lambda:InvokeFunctionUrl",
1261
+ Principal: "*",
1262
+ FunctionUrlAuthType: "NONE"
1263
+ });
1264
+ }
1265
+ async publishLayerVersion(params) {
1266
+ const { LayerName, ...rest } = params;
1267
+ const result = await this.client.request({
1268
+ service: "lambda",
1269
+ region: this.region,
1270
+ method: "POST",
1271
+ path: `/2018-10-31/layers/${encodeURIComponent(LayerName)}/versions`,
1272
+ headers: {
1273
+ "Content-Type": "application/json"
1274
+ },
1275
+ body: JSON.stringify(rest)
1276
+ });
1277
+ return result;
1278
+ }
1279
+ async listLayerVersions(layerName, params) {
1280
+ const queryParams = {};
1281
+ if (params?.CompatibleRuntime)
1282
+ queryParams.CompatibleRuntime = params.CompatibleRuntime;
1283
+ if (params?.CompatibleArchitecture)
1284
+ queryParams.CompatibleArchitecture = params.CompatibleArchitecture;
1285
+ if (params?.MaxItems)
1286
+ queryParams.MaxItems = String(params.MaxItems);
1287
+ if (params?.Marker)
1288
+ queryParams.Marker = params.Marker;
1289
+ const result = await this.client.request({
1290
+ service: "lambda",
1291
+ region: this.region,
1292
+ method: "GET",
1293
+ path: `/2018-10-31/layers/${encodeURIComponent(layerName)}/versions`,
1294
+ queryParams: Object.keys(queryParams).length > 0 ? queryParams : undefined,
1295
+ headers: {
1296
+ "Content-Type": "application/json"
1297
+ }
1298
+ });
1299
+ return result;
1300
+ }
1301
+ async getLayerVersion(layerName, versionNumber) {
1302
+ const result = await this.client.request({
1303
+ service: "lambda",
1304
+ region: this.region,
1305
+ method: "GET",
1306
+ path: `/2018-10-31/layers/${encodeURIComponent(layerName)}/versions/${versionNumber}`,
1307
+ headers: {
1308
+ "Content-Type": "application/json"
1309
+ }
1310
+ });
1311
+ return result;
1312
+ }
1313
+ async addLayerVersionPermission(params) {
1314
+ const { LayerName, VersionNumber, ...rest } = params;
1315
+ const result = await this.client.request({
1316
+ service: "lambda",
1317
+ region: this.region,
1318
+ method: "POST",
1319
+ path: `/2018-10-31/layers/${encodeURIComponent(LayerName)}/versions/${VersionNumber}/policy`,
1320
+ headers: {
1321
+ "Content-Type": "application/json"
1322
+ },
1323
+ body: JSON.stringify(rest)
1324
+ });
1325
+ return result;
1326
+ }
1327
+ async deleteLayerVersion(layerName, versionNumber) {
1328
+ await this.client.request({
1329
+ service: "lambda",
1330
+ region: this.region,
1331
+ method: "DELETE",
1332
+ path: `/2018-10-31/layers/${encodeURIComponent(layerName)}/versions/${versionNumber}`,
1333
+ headers: {
1334
+ "Content-Type": "application/json"
1335
+ }
1336
+ });
1337
+ }
1338
+ }
1339
+
1340
+ // src/aws/cloudwatch-logs.ts
1341
+ class CloudWatchLogsClient {
1342
+ client;
1343
+ region;
1344
+ constructor(region = "us-east-1", profile) {
1345
+ this.region = region;
1346
+ this.client = new AWSClient;
1347
+ }
1348
+ async describeLogStreams(options) {
1349
+ const params = {
1350
+ logGroupName: options.logGroupName
1351
+ };
1352
+ if (options.logStreamNamePrefix)
1353
+ params.logStreamNamePrefix = options.logStreamNamePrefix;
1354
+ if (options.orderBy)
1355
+ params.orderBy = options.orderBy;
1356
+ if (options.descending !== undefined)
1357
+ params.descending = options.descending;
1358
+ if (options.limit)
1359
+ params.limit = options.limit;
1360
+ const result = await this.client.request({
1361
+ service: "logs",
1362
+ region: this.region,
1363
+ method: "POST",
1364
+ path: "/",
1365
+ headers: {
1366
+ "X-Amz-Target": "Logs_20140328.DescribeLogStreams",
1367
+ "Content-Type": "application/x-amz-json-1.1"
1368
+ },
1369
+ body: JSON.stringify(params)
1370
+ });
1371
+ return result;
1372
+ }
1373
+ async getLogEvents(options) {
1374
+ const params = {
1375
+ logGroupName: options.logGroupName,
1376
+ logStreamName: options.logStreamName
1377
+ };
1378
+ if (options.startTime)
1379
+ params.startTime = options.startTime;
1380
+ if (options.endTime)
1381
+ params.endTime = options.endTime;
1382
+ if (options.limit)
1383
+ params.limit = options.limit;
1384
+ if (options.startFromHead !== undefined)
1385
+ params.startFromHead = options.startFromHead;
1386
+ const result = await this.client.request({
1387
+ service: "logs",
1388
+ region: this.region,
1389
+ method: "POST",
1390
+ path: "/",
1391
+ headers: {
1392
+ "X-Amz-Target": "Logs_20140328.GetLogEvents",
1393
+ "Content-Type": "application/x-amz-json-1.1"
1394
+ },
1395
+ body: JSON.stringify(params)
1396
+ });
1397
+ return result;
1398
+ }
1399
+ async describeLogGroups(options) {
1400
+ const params = {};
1401
+ if (options?.logGroupNamePrefix)
1402
+ params.logGroupNamePrefix = options.logGroupNamePrefix;
1403
+ if (options?.limit)
1404
+ params.limit = options.limit;
1405
+ const result = await this.client.request({
1406
+ service: "logs",
1407
+ region: this.region,
1408
+ method: "POST",
1409
+ path: "/",
1410
+ headers: {
1411
+ "X-Amz-Target": "Logs_20140328.DescribeLogGroups",
1412
+ "Content-Type": "application/x-amz-json-1.1"
1413
+ },
1414
+ body: JSON.stringify(params)
1415
+ });
1416
+ return result;
1417
+ }
1418
+ async deleteLogGroup(logGroupName) {
1419
+ await this.client.request({
1420
+ service: "logs",
1421
+ region: this.region,
1422
+ method: "POST",
1423
+ path: "/",
1424
+ headers: {
1425
+ "X-Amz-Target": "Logs_20140328.DeleteLogGroup",
1426
+ "Content-Type": "application/x-amz-json-1.1"
1427
+ },
1428
+ body: JSON.stringify({ logGroupName })
1429
+ });
1430
+ }
1431
+ async filterLogEvents(options) {
1432
+ const params = {
1433
+ logGroupName: options.logGroupName
1434
+ };
1435
+ if (options.logStreamNames)
1436
+ params.logStreamNames = options.logStreamNames;
1437
+ if (options.startTime)
1438
+ params.startTime = options.startTime;
1439
+ if (options.endTime)
1440
+ params.endTime = options.endTime;
1441
+ if (options.filterPattern)
1442
+ params.filterPattern = options.filterPattern;
1443
+ if (options.limit)
1444
+ params.limit = options.limit;
1445
+ const result = await this.client.request({
1446
+ service: "logs",
1447
+ region: this.region,
1448
+ method: "POST",
1449
+ path: "/",
1450
+ headers: {
1451
+ "X-Amz-Target": "Logs_20140328.FilterLogEvents",
1452
+ "Content-Type": "application/x-amz-json-1.1"
1453
+ },
1454
+ body: JSON.stringify(params)
1455
+ });
1456
+ return result;
1457
+ }
1458
+ }
1459
+
1460
+ // src/aws/eventbridge.ts
1461
+ class EventBridgeClient {
1462
+ client;
1463
+ region;
1464
+ constructor(region = "us-east-1") {
1465
+ this.region = region;
1466
+ this.client = new AWSClient;
1467
+ }
1468
+ async request(action, params) {
1469
+ return this.client.request({
1470
+ service: "events",
1471
+ region: this.region,
1472
+ method: "POST",
1473
+ path: "/",
1474
+ headers: {
1475
+ "Content-Type": "application/x-amz-json-1.1",
1476
+ "X-Amz-Target": `AWSEvents.${action}`
1477
+ },
1478
+ body: JSON.stringify(params)
1479
+ });
1480
+ }
1481
+ async putRule(params) {
1482
+ return this.request("PutRule", params);
1483
+ }
1484
+ async deleteRule(params) {
1485
+ return this.request("DeleteRule", params);
1486
+ }
1487
+ async describeRule(params) {
1488
+ return this.request("DescribeRule", params);
1489
+ }
1490
+ async listRules(params) {
1491
+ return this.request("ListRules", params || {});
1492
+ }
1493
+ async listEventBuses(params) {
1494
+ return this.request("ListEventBuses", params || {});
1495
+ }
1496
+ async enableRule(params) {
1497
+ return this.request("EnableRule", params);
1498
+ }
1499
+ async disableRule(params) {
1500
+ return this.request("DisableRule", params);
1501
+ }
1502
+ async putTargets(params) {
1503
+ return this.request("PutTargets", params);
1504
+ }
1505
+ async removeTargets(params) {
1506
+ return this.request("RemoveTargets", params);
1507
+ }
1508
+ async listTargetsByRule(params) {
1509
+ return this.request("ListTargetsByRule", params);
1510
+ }
1511
+ async putEvents(params) {
1512
+ return this.request("PutEvents", params);
1513
+ }
1514
+ async createSchedule(params) {
1515
+ return this.client.request({
1516
+ service: "scheduler",
1517
+ region: this.region,
1518
+ method: "POST",
1519
+ path: `/schedules/${params.Name}`,
1520
+ headers: { "Content-Type": "application/json" },
1521
+ body: JSON.stringify(params)
1522
+ });
1523
+ }
1524
+ }
1525
+
1526
+ // src/aws/efs.ts
1527
+ class EFSClient {
1528
+ client;
1529
+ region;
1530
+ constructor(region = "us-east-1") {
1531
+ this.region = region;
1532
+ this.client = new AWSClient;
1533
+ }
1534
+ async describeFileSystems(options) {
1535
+ const queryParams = [];
1536
+ if (options?.FileSystemId) {
1537
+ queryParams.push(`FileSystemId=${encodeURIComponent(options.FileSystemId)}`);
1538
+ }
1539
+ if (options?.CreationToken) {
1540
+ queryParams.push(`CreationToken=${encodeURIComponent(options.CreationToken)}`);
1541
+ }
1542
+ const path = `/2015-02-01/file-systems${queryParams.length > 0 ? `?${queryParams.join("&")}` : ""}`;
1543
+ const result = await this.client.request({
1544
+ service: "elasticfilesystem",
1545
+ region: this.region,
1546
+ method: "GET",
1547
+ path,
1548
+ headers: {
1549
+ "Content-Type": "application/json"
1550
+ }
1551
+ });
1552
+ return {
1553
+ FileSystems: (result.FileSystems || []).map((fs) => ({
1554
+ FileSystemId: fs.FileSystemId,
1555
+ Name: fs.Name,
1556
+ CreationTime: fs.CreationTime,
1557
+ LifeCycleState: fs.LifeCycleState,
1558
+ NumberOfMountTargets: fs.NumberOfMountTargets,
1559
+ SizeInBytes: fs.SizeInBytes ? {
1560
+ Value: fs.SizeInBytes.Value,
1561
+ Timestamp: fs.SizeInBytes.Timestamp
1562
+ } : undefined,
1563
+ PerformanceMode: fs.PerformanceMode,
1564
+ Encrypted: fs.Encrypted,
1565
+ ThroughputMode: fs.ThroughputMode,
1566
+ Tags: fs.Tags
1567
+ }))
1568
+ };
1569
+ }
1570
+ }
1571
+
1572
+ export { CostExplorerClient, SecretsManagerClient, SQSClient, LambdaClient, CloudWatchLogsClient, EventBridgeClient, EFSClient };