@elumixor/devkit 0.12.13 → 0.12.15

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elumixor/devkit",
3
- "version": "0.12.13",
3
+ "version": "0.12.15",
4
4
  "description": "Dev orchestrator for bun monorepos — free ports, run apps side-by-side, open the browser when ready",
5
5
  "author": "elumixor",
6
6
  "license": "ISC",
package/src/cloud/aws.ts CHANGED
@@ -25,19 +25,30 @@ function lazy<T>(make: () => T) {
25
25
  return () => (instance ??= make());
26
26
  }
27
27
 
28
- export const lambda = lazy(() => new LambdaClient({ region: REGION }));
29
- export const s3 = lazy(() => new S3Client({ region: REGION }));
30
- export const ssm = lazy(() => new SSMClient({ region: REGION }));
31
- export const iam = lazy(() => new IAMClient({ region: REGION }));
32
- export const logs = lazy(() => new CloudWatchLogsClient({ region: REGION }));
33
- export const cloudwatch = lazy(() => new CloudWatchClient({ region: REGION }));
34
- export const scheduler = lazy(() => new SchedulerClient({ region: REGION }));
35
- export const sts = lazy(() => new STSClient({ region: REGION }));
36
- export const cloudfront = lazy(() => new CloudFrontClient({ region: GLOBAL_REGION }));
37
- export const kvs = lazy(() => new CloudFrontKeyValueStoreClient({ region: GLOBAL_REGION }));
38
- export const acm = lazy(() => new ACMClient({ region: GLOBAL_REGION }));
39
- export const budgets = lazy(() => new BudgetsClient({ region: GLOBAL_REGION }));
40
- export const costExplorer = lazy(() => new CostExplorerClient({ region: GLOBAL_REGION }));
28
+ /**
29
+ * A socket that goes quiet for this long is dropped and the call retried: without it a stalled S3
30
+ * request hangs a deploy forever.
31
+ */
32
+ const home = {
33
+ region: REGION,
34
+ maxAttempts: 5,
35
+ requestHandler: { connectionTimeout: 10_000, requestTimeout: 120_000 },
36
+ };
37
+ const edge = { ...home, region: GLOBAL_REGION };
38
+
39
+ export const lambda = lazy(() => new LambdaClient(home));
40
+ export const s3 = lazy(() => new S3Client(home));
41
+ export const ssm = lazy(() => new SSMClient(home));
42
+ export const iam = lazy(() => new IAMClient(home));
43
+ export const logs = lazy(() => new CloudWatchLogsClient(home));
44
+ export const cloudwatch = lazy(() => new CloudWatchClient(home));
45
+ export const scheduler = lazy(() => new SchedulerClient(home));
46
+ export const sts = lazy(() => new STSClient(home));
47
+ export const cloudfront = lazy(() => new CloudFrontClient(edge));
48
+ export const kvs = lazy(() => new CloudFrontKeyValueStoreClient(edge));
49
+ export const acm = lazy(() => new ACMClient(edge));
50
+ export const budgets = lazy(() => new BudgetsClient(edge));
51
+ export const costExplorer = lazy(() => new CostExplorerClient(edge));
41
52
 
42
53
  let account: Promise<string> | undefined;
43
54
 
@@ -34,8 +34,11 @@ export interface ProjectOverview {
34
34
  stages: StageOverview[];
35
35
  }
36
36
 
37
- /** What `status`, the MCP server and the dashboard all show: every stage, what is live on it, how it did today. */
38
- export async function overview(project?: string): Promise<ProjectOverview[]> {
37
+ /**
38
+ * What `status`, the MCP server and the dashboard all show: every stage, what is live on it, how it did today.
39
+ * CloudWatch bills every metric read, so a caller with its own numbers passes `metrics: false`.
40
+ */
41
+ export async function overview(project?: string, { metrics: withMetrics = true } = {}): Promise<ProjectOverview[]> {
39
42
  const registries = project
40
43
  ? [await readRegistry(project)].filter((registry) => registry !== undefined)
41
44
  : await listProjects();
@@ -47,7 +50,7 @@ export async function overview(project?: string): Promise<ProjectOverview[]> {
47
50
  const target = new Target(registry.project, stage);
48
51
  const [current, metrics, deploys] = await Promise.all([
49
52
  readCurrent(target),
50
- metricsFor(target.functionName),
53
+ withMetrics ? metricsFor(target.functionName) : NO_METRICS,
51
54
  listDeploys(target, 3),
52
55
  ]);
53
56
  return {
@@ -65,7 +68,22 @@ export async function overview(project?: string): Promise<ProjectOverview[]> {
65
68
  );
66
69
  }
67
70
 
68
- async function metricsFor(functionName: string): Promise<Metrics> {
71
+ const NO_METRICS: Metrics = { calls: 0, errors: 0, p95ms: 0 };
72
+
73
+ /** Each read costs money and the numbers move slowly: one function's are reused this long. */
74
+ const METRICS_MAX_AGE_MS = 10 * 60_000;
75
+ const recent = new Map<string, { at: number; metrics: Promise<Metrics> }>();
76
+
77
+ function metricsFor(functionName: string): Promise<Metrics> {
78
+ const kept = recent.get(functionName);
79
+ if (kept && Date.now() - kept.at < METRICS_MAX_AGE_MS) return kept.metrics;
80
+ const metrics = readMetrics(functionName);
81
+ recent.set(functionName, { at: Date.now(), metrics });
82
+ metrics.catch(() => recent.delete(functionName));
83
+ return metrics;
84
+ }
85
+
86
+ async function readMetrics(functionName: string): Promise<Metrics> {
69
87
  const end = new Date();
70
88
  const start = new Date(end.getTime() - DAY_SECONDS * 1000);
71
89
  const query = (id: string, metric: string, stat: string) => ({