@aws-blocks/core 0.1.13 → 0.1.18
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/README.md +180 -17
- package/dist/cdk/blocks-backend.d.ts +4 -0
- package/dist/cdk/blocks-backend.d.ts.map +1 -1
- package/dist/cdk/blocks-backend.js +23 -1
- package/dist/cdk/blocks-backend.test.js +71 -1
- package/dist/cdk/blocks-stack.test.js +32 -1
- package/dist/cdk/index.d.ts +13 -0
- package/dist/cdk/index.d.ts.map +1 -1
- package/dist/cdk/index.js +24 -0
- package/dist/cors.d.ts +27 -1
- package/dist/cors.d.ts.map +1 -1
- package/dist/cors.js +55 -2
- package/dist/cors.test.js +81 -2
- package/dist/errors.test.js +26 -1
- package/dist/hosting.d.ts.map +1 -1
- package/dist/hosting.js +26 -1
- package/dist/hosting.test.js +73 -0
- package/dist/lambda-handler.d.ts.map +1 -1
- package/dist/lambda-handler.js +4 -17
- package/dist/lambda-handler.test.js +59 -2
- package/dist/rpc.test.js +77 -1
- package/dist/scripts/console.d.ts.map +1 -1
- package/dist/scripts/console.js +30 -2
- package/dist/scripts/deploy-stream.d.ts +181 -0
- package/dist/scripts/deploy-stream.d.ts.map +1 -0
- package/dist/scripts/deploy-stream.js +332 -0
- package/dist/scripts/deploy-stream.test.d.ts +2 -0
- package/dist/scripts/deploy-stream.test.d.ts.map +1 -0
- package/dist/scripts/deploy-stream.test.js +845 -0
- package/dist/scripts/deploy.d.ts.map +1 -1
- package/dist/scripts/deploy.js +16 -9
- package/dist/scripts/dev-server-cors.test.js +19 -1
- package/dist/scripts/dev-server-rpc.test.js +50 -0
- package/dist/scripts/dev-server.d.ts +8 -0
- package/dist/scripts/dev-server.d.ts.map +1 -1
- package/dist/scripts/dev-server.js +35 -8
- package/dist/scripts/sandbox.js +1 -1
- package/dist/telemetry/client.js +4 -4
- package/dist/telemetry/telemetry-send-worker.js +4 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +10 -1
- package/src/cdk/blocks-backend.test.ts +90 -1
- package/src/cdk/blocks-backend.ts +24 -1
- package/src/cdk/blocks-stack.test.ts +41 -1
- package/src/cdk/index.ts +25 -0
- package/src/cors.test.ts +96 -2
- package/src/cors.ts +59 -2
- package/src/errors.test.ts +29 -1
- package/src/hosting.test.ts +107 -0
- package/src/hosting.ts +27 -1
- package/src/lambda-handler.test.ts +71 -2
- package/src/lambda-handler.ts +4 -20
- package/src/rpc.test.ts +96 -1
- package/src/scripts/console.ts +29 -2
- package/src/scripts/deploy-stream.test.ts +1035 -0
- package/src/scripts/deploy-stream.ts +475 -0
- package/src/scripts/deploy.ts +18 -11
- package/src/scripts/dev-server-cors.test.ts +26 -1
- package/src/scripts/dev-server-rpc.test.ts +54 -0
- package/src/scripts/dev-server.ts +38 -8
- package/src/scripts/sandbox.ts +1 -1
- package/src/telemetry/client.ts +4 -4
- package/src/telemetry/telemetry-send-worker.ts +5 -0
- package/src/version.ts +1 -1
|
@@ -13,6 +13,7 @@ import { ApiError } from '../errors.js';
|
|
|
13
13
|
import { BLOCKS_RPC_PREFIX, BLOCKS_SANDBOX_PREFIX } from '../constants.js';
|
|
14
14
|
import { BLOCKS_SANDBOX_DIR } from '../common/constants.js';
|
|
15
15
|
import { matchRoute, lockRouteRegistry } from '../raw-route.js';
|
|
16
|
+
import { CORS_MAX_AGE } from '../cors.js';
|
|
16
17
|
import { registerBuiltinRoutes } from '../builtin-routes.js';
|
|
17
18
|
import {
|
|
18
19
|
parseRpcRequest,
|
|
@@ -45,6 +46,24 @@ export function resolveDevCorsOrigin(origin: string): string {
|
|
|
45
46
|
return LOCALHOST_PATTERN.test(origin) ? origin : 'http://localhost:3000';
|
|
46
47
|
}
|
|
47
48
|
|
|
49
|
+
/**
|
|
50
|
+
* Build the CORS response headers the dev server sets on every request.
|
|
51
|
+
*
|
|
52
|
+
* Mirrors the Lambda path's cache posture — same {@link CORS_MAX_AGE} and the
|
|
53
|
+
* same `Vary: Origin` — so the reflected `Access-Control-Allow-Origin` can't be
|
|
54
|
+
* served across origins by a shared cache, and so the two sites can't drift.
|
|
55
|
+
*/
|
|
56
|
+
export function buildDevCorsHeaders(requestOrigin: string): Record<string, string> {
|
|
57
|
+
return {
|
|
58
|
+
'Access-Control-Allow-Origin': resolveDevCorsOrigin(requestOrigin),
|
|
59
|
+
'Vary': 'Origin',
|
|
60
|
+
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS',
|
|
61
|
+
'Access-Control-Allow-Headers': 'Content-Type',
|
|
62
|
+
'Access-Control-Allow-Credentials': 'true',
|
|
63
|
+
'Access-Control-Max-Age': CORS_MAX_AGE,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
48
67
|
/** Shape of the client runtime config the browser fetches to discover the API URL. */
|
|
49
68
|
export interface BlocksRuntimeConfig {
|
|
50
69
|
apiUrl: string;
|
|
@@ -854,12 +873,9 @@ export async function startDevServer(options: DevServerOptions) {
|
|
|
854
873
|
|
|
855
874
|
// CORS headers
|
|
856
875
|
const requestOrigin = req.headers.origin || '';
|
|
857
|
-
const
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
res.setHeader('Access-Control-Allow-Headers', 'Content-Type');
|
|
861
|
-
res.setHeader('Access-Control-Allow-Credentials', 'true');
|
|
862
|
-
res.setHeader('Access-Control-Max-Age', '86400');
|
|
876
|
+
for (const [name, value] of Object.entries(buildDevCorsHeaders(requestOrigin))) {
|
|
877
|
+
res.setHeader(name, value);
|
|
878
|
+
}
|
|
863
879
|
|
|
864
880
|
if (method === 'OPTIONS') {
|
|
865
881
|
res.writeHead(200);
|
|
@@ -1244,6 +1260,20 @@ function handleApiRequest(
|
|
|
1244
1260
|
return;
|
|
1245
1261
|
}
|
|
1246
1262
|
|
|
1247
|
-
|
|
1248
|
-
|
|
1263
|
+
// Anything that reaches here didn't match `POST /aws-blocks/api`. Returning a
|
|
1264
|
+
// bare empty 404 leaves a developer poking at the endpoint (e.g. opening it in
|
|
1265
|
+
// a browser, which sends a GET, or trying a REST-style URL) with no feedback.
|
|
1266
|
+
// Reply with a small JSON hint pointing at the one supported shape. When the
|
|
1267
|
+
// path was right but the method wasn't, say so explicitly.
|
|
1268
|
+
const wrongMethodOnApi = url.pathname === BLOCKS_RPC_PREFIX;
|
|
1269
|
+
const message = wrongMethodOnApi
|
|
1270
|
+
? `The AWS Blocks JSON-RPC API expects POST, not ${method}.`
|
|
1271
|
+
: 'Not found. The AWS Blocks JSON-RPC API is served at POST /aws-blocks/api.';
|
|
1272
|
+
res.writeHead(404, { 'Content-Type': 'application/json' });
|
|
1273
|
+
res.end(
|
|
1274
|
+
JSON.stringify({
|
|
1275
|
+
error: message,
|
|
1276
|
+
expected: { method: 'POST', path: BLOCKS_RPC_PREFIX },
|
|
1277
|
+
}),
|
|
1278
|
+
);
|
|
1249
1279
|
}
|
package/src/scripts/sandbox.ts
CHANGED
|
@@ -150,7 +150,7 @@ export async function startSandbox(options: SandboxOptions) {
|
|
|
150
150
|
console.log(`\n Open http://localhost:${clientPort}\n`);
|
|
151
151
|
|
|
152
152
|
const cdkWatch = spawnCommand("npx", [
|
|
153
|
-
"cdk", "watch",
|
|
153
|
+
"cdk", "watch",
|
|
154
154
|
`--outputs-file`, `${outDir}/outputs.json`,
|
|
155
155
|
`--context`, `projectRoot=${process.cwd()}`,
|
|
156
156
|
`--context`, `sandboxMode=true`,
|
package/src/telemetry/client.ts
CHANGED
|
@@ -199,16 +199,16 @@ export function sendEvent(event: BlocksTelemetryEvent): void {
|
|
|
199
199
|
const workerPath = path.join(dir, 'telemetry-send-worker.js');
|
|
200
200
|
const child = spawn(process.execPath, [workerPath, endpoint], {
|
|
201
201
|
detached: true,
|
|
202
|
-
stdio: ['pipe', 'ignore', 'ignore'],
|
|
202
|
+
stdio: ['pipe', 'ignore', process.env.NODE_DEBUG?.includes('blocks-telemetry') ? 'inherit' : 'ignore'],
|
|
203
203
|
// Clear NODE_OPTIONS so inherited flags (e.g. --conditions=cdk) don't interfere
|
|
204
204
|
env: { ...process.env, NODE_OPTIONS: '' },
|
|
205
205
|
});
|
|
206
206
|
|
|
207
|
-
child.stdin
|
|
207
|
+
child.stdin?.on('error', (err) => { debug('stdin write failed: %s', err.message); });
|
|
208
208
|
// Payload is small (<1KB JSON) so it fits in the kernel pipe buffer (~64KB)
|
|
209
209
|
// and survives the parent closing its fd on exit.
|
|
210
|
-
child.stdin
|
|
211
|
-
child.stdin
|
|
210
|
+
child.stdin?.write(payload);
|
|
211
|
+
child.stdin?.end();
|
|
212
212
|
child.on('error', (err) => { debug('spawn failed: %s', err.message); });
|
|
213
213
|
child.unref();
|
|
214
214
|
debug('spawned telemetry subprocess (pid=%d)', child.pid);
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
+
// NOTE: This worker is an intentional near-duplicate of
|
|
5
|
+
// packages/create-blocks-app/src/telemetry-send-worker.ts. It is kept separate
|
|
6
|
+
// because the worker must run with zero project/package imports. Any change
|
|
7
|
+
// here should be mirrored in both files.
|
|
8
|
+
|
|
4
9
|
/**
|
|
5
10
|
* Telemetry send worker — spawned as a detached subprocess.
|
|
6
11
|
* Reads JSON payload from stdin, POSTs it to the endpoint (argv[2]).
|
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.
|
|
2
|
+
export const CORE_VERSION = '0.1.18';
|