@aws-blocks/core 0.1.4 → 0.1.10

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 (91) hide show
  1. package/dist/cdk/index.d.ts +1 -1
  2. package/dist/cdk/index.d.ts.map +1 -1
  3. package/dist/cdk/index.js +1 -1
  4. package/dist/client/index.d.ts +1 -1
  5. package/dist/client/index.d.ts.map +1 -1
  6. package/dist/client/index.js +1 -1
  7. package/dist/db-naming.d.ts +17 -5
  8. package/dist/db-naming.d.ts.map +1 -1
  9. package/dist/db-naming.js +18 -6
  10. package/dist/db-naming.test.js +44 -3
  11. package/dist/errors.d.ts +28 -0
  12. package/dist/errors.d.ts.map +1 -1
  13. package/dist/errors.js +27 -1
  14. package/dist/errors.test.d.ts +2 -0
  15. package/dist/errors.test.d.ts.map +1 -0
  16. package/dist/errors.test.js +47 -0
  17. package/dist/hosting.d.ts +71 -1
  18. package/dist/hosting.d.ts.map +1 -1
  19. package/dist/hosting.js +47 -8
  20. package/dist/hosting.test.js +60 -0
  21. package/dist/index.cdk.d.ts +1 -1
  22. package/dist/index.cdk.d.ts.map +1 -1
  23. package/dist/index.cdk.js +1 -1
  24. package/dist/index.d.ts +1 -1
  25. package/dist/index.d.ts.map +1 -1
  26. package/dist/index.js +1 -1
  27. package/dist/scripts/deploy.d.ts.map +1 -1
  28. package/dist/scripts/deploy.js +4 -2
  29. package/dist/scripts/dev-server-supervisor.test.d.ts +2 -0
  30. package/dist/scripts/dev-server-supervisor.test.d.ts.map +1 -0
  31. package/dist/scripts/dev-server-supervisor.test.js +551 -0
  32. package/dist/scripts/dev-server.d.ts +73 -0
  33. package/dist/scripts/dev-server.d.ts.map +1 -1
  34. package/dist/scripts/dev-server.js +279 -29
  35. package/dist/scripts/ensure-secrets.d.ts +5 -2
  36. package/dist/scripts/ensure-secrets.d.ts.map +1 -1
  37. package/dist/scripts/ensure-secrets.js +14 -6
  38. package/dist/scripts/external-migrations-step.d.ts.map +1 -1
  39. package/dist/scripts/external-migrations-step.js +5 -1
  40. package/dist/scripts/index.d.ts +1 -0
  41. package/dist/scripts/index.d.ts.map +1 -1
  42. package/dist/scripts/index.js +1 -0
  43. package/dist/scripts/process-tree.d.ts +126 -0
  44. package/dist/scripts/process-tree.d.ts.map +1 -0
  45. package/dist/scripts/process-tree.js +198 -0
  46. package/dist/scripts/sandbox.d.ts.map +1 -1
  47. package/dist/scripts/sandbox.js +51 -4
  48. package/dist/scripts/stack-id.d.ts +37 -0
  49. package/dist/scripts/stack-id.d.ts.map +1 -0
  50. package/dist/scripts/stack-id.js +79 -0
  51. package/dist/scripts/stack-id.test.d.ts +2 -0
  52. package/dist/scripts/stack-id.test.d.ts.map +1 -0
  53. package/dist/scripts/stack-id.test.js +104 -0
  54. package/dist/telemetry/client.d.ts +3 -1
  55. package/dist/telemetry/client.d.ts.map +1 -1
  56. package/dist/telemetry/client.js +20 -24
  57. package/dist/telemetry/telemetry-send-worker.d.ts +2 -0
  58. package/dist/telemetry/telemetry-send-worker.d.ts.map +1 -0
  59. package/dist/telemetry/telemetry-send-worker.js +58 -0
  60. package/dist/telemetry/telemetry.test.js +77 -1
  61. package/dist/telemetry/trackCommand.d.ts +1 -1
  62. package/dist/telemetry/trackCommand.js +3 -3
  63. package/dist/version.d.ts +1 -1
  64. package/dist/version.d.ts.map +1 -1
  65. package/dist/version.js +1 -1
  66. package/package.json +1 -1
  67. package/src/cdk/index.ts +1 -1
  68. package/src/client/index.ts +1 -1
  69. package/src/db-naming.test.ts +50 -5
  70. package/src/db-naming.ts +18 -6
  71. package/src/errors.test.ts +55 -0
  72. package/src/errors.ts +32 -1
  73. package/src/hosting.test.ts +79 -0
  74. package/src/hosting.ts +127 -13
  75. package/src/index.cdk.ts +1 -1
  76. package/src/index.ts +1 -1
  77. package/src/scripts/deploy.ts +4 -2
  78. package/src/scripts/dev-server-supervisor.test.ts +621 -0
  79. package/src/scripts/dev-server.ts +316 -27
  80. package/src/scripts/ensure-secrets.ts +17 -6
  81. package/src/scripts/external-migrations-step.ts +5 -1
  82. package/src/scripts/index.ts +1 -0
  83. package/src/scripts/process-tree.ts +245 -0
  84. package/src/scripts/sandbox.ts +50 -4
  85. package/src/scripts/stack-id.test.ts +123 -0
  86. package/src/scripts/stack-id.ts +87 -0
  87. package/src/telemetry/client.ts +22 -30
  88. package/src/telemetry/telemetry-send-worker.ts +60 -0
  89. package/src/telemetry/telemetry.test.ts +91 -1
  90. package/src/telemetry/trackCommand.ts +3 -3
  91. package/src/version.ts +1 -1
@@ -0,0 +1,60 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ /**
5
+ * Telemetry send worker — spawned as a detached subprocess.
6
+ * Reads JSON payload from stdin, POSTs it to the endpoint (argv[2]).
7
+ *
8
+ * Uses only Node built-ins — no project imports — so the compiled .js
9
+ * runs with bare `node` (no tsx needed).
10
+ */
11
+
12
+ import { request as httpsRequest } from 'node:https';
13
+ import { request as httpRequest } from 'node:http';
14
+
15
+ const TIMEOUT_MS = 500;
16
+ const debug = (process.env.NODE_DEBUG || '').includes('blocks-telemetry');
17
+
18
+ const endpoint = process.argv[2];
19
+ if (!endpoint) process.exit(1);
20
+
21
+ let payload = '';
22
+ process.stdin.setEncoding('utf-8');
23
+ process.stdin.on('data', (chunk: string) => { payload += chunk; });
24
+ process.stdin.on('end', () => {
25
+ try {
26
+ const url = new URL(endpoint);
27
+ const isHttps = url.protocol === 'https:';
28
+ const requestFn = isHttps ? httpsRequest : httpRequest;
29
+
30
+ const req = requestFn({
31
+ hostname: url.hostname,
32
+ port: url.port || (isHttps ? '443' : '80'),
33
+ path: url.pathname + url.search,
34
+ method: 'POST',
35
+ headers: {
36
+ 'Content-Type': 'application/json',
37
+ 'Content-Length': Buffer.byteLength(payload),
38
+ },
39
+ timeout: TIMEOUT_MS,
40
+ }, (res) => {
41
+ res.resume();
42
+ if (debug) process.stderr.write(`BLOCKS-TELEMETRY: sent (status=${res.statusCode})\n`);
43
+ process.exit(0);
44
+ });
45
+
46
+ req.on('error', (e) => {
47
+ if (debug) process.stderr.write(`BLOCKS-TELEMETRY: error: ${(e as Error).message}\n`);
48
+ process.exit(1);
49
+ });
50
+ req.on('timeout', () => {
51
+ if (debug) process.stderr.write(`BLOCKS-TELEMETRY: timed out\n`);
52
+ req.destroy();
53
+ process.exit(1);
54
+ });
55
+ req.write(payload);
56
+ req.end();
57
+ } catch {
58
+ process.exit(1);
59
+ }
60
+ });
@@ -11,7 +11,7 @@ import { isCI, detectOS, detectNodeVersion, detectPackageManager, detectAgent, c
11
11
  import { trackCommand, classifyError } from './trackCommand.js';
12
12
  import { buildAndSendEvent, buildEvent, sendEvent, getTelemetryFilePath } from './client.js';
13
13
  import { getInstallationId, getProjectId, generateEventId } from './identifiers.js';
14
- import { spawnSync } from 'node:child_process';
14
+ import { spawnSync, spawn as spawnChild } from 'node:child_process';
15
15
  import type { BlocksTelemetryEvent } from './types.js';
16
16
  import { Scope, OFFICIAL_BB_NAMES } from '../common/index.js';
17
17
  import type { ScopeParent } from '../common/index.js';
@@ -533,6 +533,96 @@ describe('telemetry/client', () => {
533
533
  });
534
534
  });
535
535
 
536
+ describe('telemetry/send-worker', () => {
537
+ it('worker POSTs payload from stdin to endpoint', async () => {
538
+ const received: string[] = [];
539
+
540
+ const server: Server = await new Promise((resolve) => {
541
+ const s = createServer((req, res) => {
542
+ let body = '';
543
+ req.on('data', (chunk) => { body += chunk; });
544
+ req.on('end', () => {
545
+ received.push(body);
546
+ res.writeHead(200);
547
+ res.end();
548
+ });
549
+ });
550
+ s.listen(0, '127.0.0.1', () => resolve(s));
551
+ });
552
+
553
+ const addr = server.address() as { port: number };
554
+ const endpoint = `http://127.0.0.1:${addr.port}/collect`;
555
+ const payload = JSON.stringify({ test: true, command: 'dev' });
556
+ const workerPath = join(__dirname, 'telemetry-send-worker.js');
557
+
558
+ const exitCode = await new Promise<number | null>((resolve) => {
559
+ const proc = spawnChild(process.execPath, [workerPath, endpoint], {
560
+ stdio: ['pipe', 'ignore', 'ignore'],
561
+ env: { ...process.env, NODE_OPTIONS: '' },
562
+ });
563
+ proc.stdin!.write(payload);
564
+ proc.stdin!.end();
565
+ proc.on('close', (code) => resolve(code));
566
+ });
567
+
568
+ assert.strictEqual(exitCode, 0);
569
+ assert.strictEqual(received.length, 1);
570
+ assert.deepStrictEqual(JSON.parse(received[0]), { test: true, command: 'dev' });
571
+
572
+ server.close();
573
+ });
574
+
575
+ it('worker exits with 1 on unreachable endpoint', async () => {
576
+ const payload = JSON.stringify({ test: true });
577
+ const workerPath = join(__dirname, 'telemetry-send-worker.js');
578
+
579
+ const exitCode = await new Promise<number | null>((resolve) => {
580
+ const proc = spawnChild(process.execPath, [workerPath, 'http://127.0.0.1:1/unreachable'], {
581
+ stdio: ['pipe', 'ignore', 'ignore'],
582
+ env: { ...process.env, NODE_OPTIONS: '' },
583
+ });
584
+ proc.stdin!.write(payload);
585
+ proc.stdin!.end();
586
+ proc.on('close', (code) => resolve(code));
587
+ });
588
+
589
+ assert.strictEqual(exitCode, 1);
590
+ });
591
+
592
+ it('worker writes debug output to stderr when NODE_DEBUG is set', async () => {
593
+ const server: Server = await new Promise((resolve) => {
594
+ const s = createServer((req, res) => {
595
+ let body = '';
596
+ req.on('data', (chunk) => { body += chunk; });
597
+ req.on('end', () => { res.writeHead(200); res.end(); });
598
+ });
599
+ s.listen(0, '127.0.0.1', () => resolve(s));
600
+ });
601
+
602
+ const addr = server.address() as { port: number };
603
+ const endpoint = `http://127.0.0.1:${addr.port}/collect`;
604
+ const payload = JSON.stringify({ test: true });
605
+ const workerPath = join(__dirname, 'telemetry-send-worker.js');
606
+
607
+ const result = await new Promise<{ code: number | null; stderr: string }>((resolve) => {
608
+ const proc = spawnChild(process.execPath, [workerPath, endpoint], {
609
+ stdio: ['pipe', 'ignore', 'pipe'],
610
+ env: { ...process.env, NODE_OPTIONS: '', NODE_DEBUG: 'blocks-telemetry' },
611
+ });
612
+ let stderr = '';
613
+ proc.stderr!.on('data', (chunk: Buffer) => { stderr += chunk.toString(); });
614
+ proc.stdin!.write(payload);
615
+ proc.stdin!.end();
616
+ proc.on('close', (code) => resolve({ code, stderr }));
617
+ });
618
+
619
+ assert.strictEqual(result.code, 0);
620
+ assert.ok(result.stderr.includes('BLOCKS-TELEMETRY: sent (status=200)'), `Expected debug output, got: ${result.stderr}`);
621
+
622
+ server.close();
623
+ });
624
+ });
625
+
536
626
  describe('telemetry/trackCommand integration', () => {
537
627
  const originalEnv = { ...process.env };
538
628
 
@@ -22,10 +22,10 @@ export function classifyError(error: unknown): { code: string; phase: string } {
22
22
  if (msg.includes('cdk synth') || msg.includes('synthesis')) {
23
23
  return { code: 'CDK_SYNTH_FAILED', phase: 'synth' };
24
24
  }
25
- if (msg.includes('cdk deploy') || msg.includes('deployment failed')) {
25
+ if (msg.includes('cdk deploy') || msg.includes('deployment failed') || (msg.includes('cdk') && msg.includes('deploy') && msg.includes('exited with code'))) {
26
26
  return { code: 'CDK_DEPLOY_FAILED', phase: 'deploy' };
27
27
  }
28
- if (msg.includes('cdk destroy') || msg.includes('destroy failed')) {
28
+ if (msg.includes('cdk destroy') || msg.includes('destroy failed') || (msg.includes('cdk') && msg.includes('destroy') && msg.includes('exited with code'))) {
29
29
  return { code: 'CDK_DESTROY_FAILED', phase: 'destroy' };
30
30
  }
31
31
  if (msg.includes('npm install') || msg.includes('npm err')) {
@@ -52,7 +52,7 @@ export function classifyError(error: unknown): { code: string; phase: string } {
52
52
  *
53
53
  * Measures wall-clock duration, classifies errors, and sends a single telemetry event
54
54
  * after the command completes (success or failure). The telemetry send is fire-and-forget
55
- * and bounded by a 5s timeout — it will never delay the command or affect its exit code.
55
+ * and bounded by a 500ms timeout — it will never delay the command or affect its exit code.
56
56
  *
57
57
  * If telemetry is disabled (via env var or config), the function is executed directly
58
58
  * with zero overhead.
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  // Auto-generated by scripts/generate-version.mjs — do not edit manually
2
- export const CORE_VERSION = '0.1.4';
2
+ export const CORE_VERSION = '0.1.10';