@aws-blocks/core 0.2.0 → 0.3.0
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/dist/cdk/blocks-backend.d.ts +35 -9
- package/dist/cdk/blocks-backend.d.ts.map +1 -1
- package/dist/cdk/blocks-backend.js +52 -69
- package/dist/cdk/blocks-backend.test.js +61 -69
- package/dist/cdk/blocks-defaults.d.ts +27 -1
- package/dist/cdk/blocks-defaults.d.ts.map +1 -1
- package/dist/cdk/blocks-defaults.js +5 -1
- package/dist/cdk/blocks-defaults.test.js +4 -2
- package/dist/cdk/blocks-stack.test.js +73 -37
- package/dist/cdk/compute/default-compute-factory.d.ts +33 -0
- package/dist/cdk/compute/default-compute-factory.d.ts.map +1 -0
- package/dist/cdk/compute/default-compute-factory.js +3 -0
- package/dist/cdk/index.d.ts +46 -5
- package/dist/cdk/index.d.ts.map +1 -1
- package/dist/cdk/index.js +57 -7
- package/dist/cdk/internal.d.ts +1 -0
- package/dist/cdk/internal.d.ts.map +1 -1
- package/dist/hosting-secrets.d.ts +48 -0
- package/dist/hosting-secrets.d.ts.map +1 -0
- package/dist/hosting-secrets.js +57 -0
- package/dist/hosting-secrets.test.d.ts +2 -0
- package/dist/hosting-secrets.test.d.ts.map +1 -0
- package/dist/hosting-secrets.test.js +81 -0
- package/dist/hosting.d.ts +88 -6
- package/dist/hosting.d.ts.map +1 -1
- package/dist/hosting.js +83 -24
- package/dist/hosting.test.js +158 -10
- package/dist/index.cdk.d.ts +13 -12
- package/dist/index.cdk.d.ts.map +1 -1
- package/dist/index.cdk.js +13 -9
- package/dist/index.d.ts +8 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -5
- package/dist/lambda-handler.test.js +66 -0
- package/dist/pipeline/index.d.ts +24 -2
- package/dist/pipeline/index.d.ts.map +1 -1
- package/dist/pipeline/index.js +41 -1
- package/dist/pipeline.test.d.ts +2 -0
- package/dist/pipeline.test.d.ts.map +1 -0
- package/dist/pipeline.test.js +47 -0
- package/dist/rpc.d.ts +21 -0
- package/dist/rpc.d.ts.map +1 -1
- package/dist/rpc.js +34 -0
- package/dist/rpc.test.js +38 -1
- package/dist/scripts/config.d.ts +15 -0
- package/dist/scripts/config.d.ts.map +1 -0
- package/dist/scripts/config.js +29 -0
- package/dist/scripts/deploy.d.ts.map +1 -1
- package/dist/scripts/deploy.js +4 -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 +31 -0
- package/dist/scripts/generate-client.d.ts.map +1 -1
- package/dist/scripts/generate-client.js +9 -4
- package/dist/scripts/generate-client.test.js +19 -4
- package/dist/scripts/index.d.ts +13 -10
- package/dist/scripts/index.d.ts.map +1 -1
- package/dist/scripts/index.js +11 -8
- package/dist/scripts/preflight-credentials.d.ts +30 -0
- package/dist/scripts/preflight-credentials.d.ts.map +1 -0
- package/dist/scripts/preflight-credentials.js +108 -0
- package/dist/scripts/preflight-credentials.test.d.ts +2 -0
- package/dist/scripts/preflight-credentials.test.d.ts.map +1 -0
- package/dist/scripts/preflight-credentials.test.js +77 -0
- package/dist/scripts/sandbox-args.test.d.ts +2 -0
- package/dist/scripts/sandbox-args.test.d.ts.map +1 -0
- package/dist/scripts/sandbox-args.test.js +77 -0
- package/dist/scripts/sandbox.d.ts +52 -0
- package/dist/scripts/sandbox.d.ts.map +1 -1
- package/dist/scripts/sandbox.js +92 -15
- package/dist/scripts/secret.d.ts +15 -0
- package/dist/scripts/secret.d.ts.map +1 -0
- package/dist/scripts/secret.js +29 -0
- package/dist/scripts/secret.test.d.ts +2 -0
- package/dist/scripts/secret.test.d.ts.map +1 -0
- package/dist/scripts/secret.test.js +28 -0
- package/dist/scripts/typegen.d.ts +15 -0
- package/dist/scripts/typegen.d.ts.map +1 -0
- package/dist/scripts/typegen.js +16 -0
- package/dist/secret-naming.d.ts +58 -0
- package/dist/secret-naming.d.ts.map +1 -0
- package/dist/secret-naming.js +67 -0
- package/dist/secret-naming.test.d.ts +2 -0
- package/dist/secret-naming.test.d.ts.map +1 -0
- package/dist/secret-naming.test.js +40 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +2 -1
- package/src/cdk/blocks-backend.test.ts +267 -272
- package/src/cdk/blocks-backend.ts +71 -79
- package/src/cdk/blocks-defaults.test.ts +4 -2
- package/src/cdk/blocks-defaults.ts +27 -1
- package/src/cdk/blocks-stack.test.ts +161 -118
- package/src/cdk/compute/default-compute-factory.ts +37 -0
- package/src/cdk/index.ts +84 -8
- package/src/cdk/internal.ts +1 -0
- package/src/hosting-secrets.test.ts +106 -0
- package/src/hosting-secrets.ts +106 -0
- package/src/hosting.test.ts +244 -63
- package/src/hosting.ts +180 -68
- package/src/index.cdk.ts +77 -38
- package/src/index.ts +35 -16
- package/src/lambda-handler.test.ts +74 -0
- package/src/pipeline/index.ts +64 -11
- package/src/pipeline.test.ts +55 -0
- package/src/rpc.test.ts +44 -1
- package/src/rpc.ts +41 -0
- package/src/scripts/config.ts +35 -0
- package/src/scripts/deploy.ts +5 -0
- package/src/scripts/dev-server.ts +40 -0
- package/src/scripts/generate-client.test.ts +43 -8
- package/src/scripts/generate-client.ts +70 -65
- package/src/scripts/index.ts +20 -17
- package/src/scripts/preflight-credentials.test.ts +110 -0
- package/src/scripts/preflight-credentials.ts +131 -0
- package/src/scripts/sandbox-args.test.ts +92 -0
- package/src/scripts/sandbox.ts +102 -15
- package/src/scripts/secret.test.ts +35 -0
- package/src/scripts/secret.ts +35 -0
- package/src/scripts/typegen.ts +18 -0
- package/src/secret-naming.test.ts +59 -0
- package/src/secret-naming.ts +99 -0
- package/src/version.ts +1 -1
package/dist/index.js
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
// secret()/config() declare markers (CDK-free subpath). The runtime getters
|
|
4
|
+
// getSecret()/getConfig() are imported from '@aws-blocks/hosting' directly —
|
|
5
|
+
// core already exports a backend `getConfig` (config loader) under this name.
|
|
6
|
+
export { config, isConfig, isManagedValue, isSecret, secret, } from '@aws-blocks/hosting';
|
|
3
7
|
export { ApiNamespace } from './api.js';
|
|
4
|
-
export {
|
|
5
|
-
export { ApiError, isBlocksError, hasAuthError, DEFAULT_API_ERROR_NAME } from './errors.js';
|
|
8
|
+
export { _resetConfigCache, getConfig, getConfigSync, loadConfigToProcessEnv, preloadConfig } from './common/config.js';
|
|
6
9
|
export { Scope } from './common/index.js';
|
|
7
|
-
export {
|
|
8
|
-
export {
|
|
9
|
-
export {
|
|
10
|
+
export { _resetSdkRegistry, getAllSdkIdentifiers, getSdkIdentifiers, registerSdkIdentifiers, } from './common/sdk-registry.js';
|
|
11
|
+
export { BLOCKS_AUTH_PREFIX, BLOCKS_RPC_PREFIX } from './constants.js';
|
|
12
|
+
export { ApiError, DEFAULT_API_ERROR_NAME, hasAuthError, isBlocksError } from './errors.js';
|
|
13
|
+
export { clearRouteRegistry, getRegisteredRoutes, lockRouteRegistry, matchRoute, RawRouteErrors, registerRoute, unlockRouteRegistry, } from './raw-route.js';
|
|
10
14
|
export { RawRoute } from './raw-route.mock.js';
|
|
@@ -890,3 +890,69 @@ describe('createLambdaHandler — sandbox forwarded-host reaches the route', ()
|
|
|
890
890
|
assert.strictEqual(capturedHost, 'abc123.execute-api.us-east-1.amazonaws.com');
|
|
891
891
|
});
|
|
892
892
|
});
|
|
893
|
+
// ── SQS partial batch failure tests ─────────────────────────────────────────
|
|
894
|
+
/**
|
|
895
|
+
* These pin the runtime half of the bb-async-job BatchSize fix: with a batch
|
|
896
|
+
* larger than 1, failing records must be reported individually via
|
|
897
|
+
* `batchItemFailures` so SQS retries only those messages. If this response
|
|
898
|
+
* shape regresses, every successful sibling message in a partially-failing
|
|
899
|
+
* batch would be redelivered (or, worse, the failures silently dropped).
|
|
900
|
+
*/
|
|
901
|
+
function makeSqsBatchEvent(count) {
|
|
902
|
+
return {
|
|
903
|
+
Records: Array.from({ length: count }, (_, i) => ({
|
|
904
|
+
eventSource: 'aws:sqs',
|
|
905
|
+
eventSourceARN: 'arn:aws:sqs:us-east-1:123456789012:my-queue',
|
|
906
|
+
messageId: `msg-${i}`,
|
|
907
|
+
body: JSON.stringify({ n: i }),
|
|
908
|
+
})),
|
|
909
|
+
};
|
|
910
|
+
}
|
|
911
|
+
describe('handleEventSourceRecords — SQS partial batch responses', () => {
|
|
912
|
+
it('reports only the failed records of a mixed-success 10-record batch', async () => {
|
|
913
|
+
const processed = [];
|
|
914
|
+
const handlers = new Map();
|
|
915
|
+
handlers.set('aws:sqs:my-queue', async (record) => {
|
|
916
|
+
const { n } = JSON.parse(record.body);
|
|
917
|
+
if (n % 3 === 0)
|
|
918
|
+
throw new Error(`boom on ${n}`);
|
|
919
|
+
processed.push(n);
|
|
920
|
+
});
|
|
921
|
+
globalThis.__BLOCKS_LAMBDA_EVENT_HANDLERS__ = handlers;
|
|
922
|
+
try {
|
|
923
|
+
const handler = createLambdaHandler(async () => ({}));
|
|
924
|
+
const result = await handler(makeSqsBatchEvent(10));
|
|
925
|
+
assert.deepStrictEqual(result.batchItemFailures.map((f) => f.itemIdentifier).sort(), ['msg-0', 'msg-3', 'msg-6', 'msg-9']);
|
|
926
|
+
assert.deepStrictEqual(processed.sort((a, b) => a - b), [1, 2, 4, 5, 7, 8]);
|
|
927
|
+
}
|
|
928
|
+
finally {
|
|
929
|
+
delete globalThis.__BLOCKS_LAMBDA_EVENT_HANDLERS__;
|
|
930
|
+
}
|
|
931
|
+
});
|
|
932
|
+
it('returns no batchItemFailures when every record in the batch succeeds', async () => {
|
|
933
|
+
const handlers = new Map();
|
|
934
|
+
handlers.set('aws:sqs:my-queue', async () => { });
|
|
935
|
+
globalThis.__BLOCKS_LAMBDA_EVENT_HANDLERS__ = handlers;
|
|
936
|
+
try {
|
|
937
|
+
const handler = createLambdaHandler(async () => ({}));
|
|
938
|
+
const result = await handler(makeSqsBatchEvent(10));
|
|
939
|
+
assert.deepStrictEqual(result, {});
|
|
940
|
+
}
|
|
941
|
+
finally {
|
|
942
|
+
delete globalThis.__BLOCKS_LAMBDA_EVENT_HANDLERS__;
|
|
943
|
+
}
|
|
944
|
+
});
|
|
945
|
+
it('reports all records when the whole batch fails (no silent drop)', async () => {
|
|
946
|
+
const handlers = new Map();
|
|
947
|
+
handlers.set('aws:sqs:my-queue', async () => { throw new Error('always'); });
|
|
948
|
+
globalThis.__BLOCKS_LAMBDA_EVENT_HANDLERS__ = handlers;
|
|
949
|
+
try {
|
|
950
|
+
const handler = createLambdaHandler(async () => ({}));
|
|
951
|
+
const result = await handler(makeSqsBatchEvent(10));
|
|
952
|
+
assert.strictEqual(result.batchItemFailures.length, 10);
|
|
953
|
+
}
|
|
954
|
+
finally {
|
|
955
|
+
delete globalThis.__BLOCKS_LAMBDA_EVENT_HANDLERS__;
|
|
956
|
+
}
|
|
957
|
+
});
|
|
958
|
+
});
|
package/dist/pipeline/index.d.ts
CHANGED
|
@@ -1,3 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { __PIPELINE_STAGE_SCOPE__, DeployStage, Pipeline as LeafPipeline } from '@aws-blocks/pipeline';
|
|
2
|
+
import type { BranchConfig, DeployStageProps, PipelineProps, PipelineSourceConfig, PipelineStageConfig, PipelineSynthConfig } from '@aws-blocks/pipeline';
|
|
3
|
+
import type { Construct } from 'constructs';
|
|
4
|
+
export { __PIPELINE_STAGE_SCOPE__, DeployStage };
|
|
5
|
+
export type { BranchConfig, DeployStageProps, PipelineProps, PipelineSourceConfig, PipelineStageConfig, PipelineSynthConfig, };
|
|
6
|
+
/**
|
|
7
|
+
* Blocks `Pipeline` — the framework-neutral `@aws-blocks/pipeline` construct with
|
|
8
|
+
* the Blocks value namespace pinned. It defaults `secretStore` / `configStore` to
|
|
9
|
+
* `/blocks/secrets` and `/blocks/config` (the prefixes the Blocks `secret` /
|
|
10
|
+
* `config` CLIs write), mirroring how the Blocks `Hosting` block pins the same
|
|
11
|
+
* namespace — so a value set with `npm run secret`/`config` is the value the
|
|
12
|
+
* pipeline reads. Pass `secretStore` / `configStore` to override.
|
|
13
|
+
*
|
|
14
|
+
* @see {@link https://github.com/aws-devtools-labs/aws-blocks/blob/main/packages/pipeline/README.md}
|
|
15
|
+
*/
|
|
16
|
+
export declare class Pipeline<TConfig = Record<string, unknown>> extends LeafPipeline<TConfig> {
|
|
17
|
+
constructor(scope: Construct, id: string, props: PipelineProps<TConfig>);
|
|
18
|
+
/**
|
|
19
|
+
* Async constructor — required when `source.connectionArn` is a `config()`
|
|
20
|
+
* marker (resolved at synth time). Pins the Blocks namespace, then delegates to
|
|
21
|
+
* the leaf {@link LeafPipeline.create}.
|
|
22
|
+
*/
|
|
23
|
+
static create<TConfig = Record<string, unknown>>(scope: Construct, id: string, props: PipelineProps<TConfig>): Promise<LeafPipeline<TConfig>>;
|
|
24
|
+
}
|
|
3
25
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/pipeline/index.ts"],"names":[],"mappings":"AAGA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/pipeline/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,wBAAwB,EAAE,WAAW,EAAE,QAAQ,IAAI,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACvG,OAAO,KAAK,EACX,YAAY,EACZ,gBAAgB,EAChB,aAAa,EACb,oBAAoB,EACpB,mBAAmB,EACnB,mBAAmB,EACnB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAG5C,OAAO,EAAE,wBAAwB,EAAE,WAAW,EAAE,CAAC;AACjD,YAAY,EACX,YAAY,EACZ,gBAAgB,EAChB,aAAa,EACb,oBAAoB,EACpB,mBAAmB,EACnB,mBAAmB,GACnB,CAAC;AAkBF;;;;;;;;;GASG;AACH,qBAAa,QAAQ,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAE,SAAQ,YAAY,CAAC,OAAO,CAAC;gBACzE,KAAK,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,aAAa,CAAC,OAAO,CAAC;IAIvE;;;;OAIG;WACU,MAAM,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACpD,KAAK,EAAE,SAAS,EAChB,EAAE,EAAE,MAAM,EACV,KAAK,EAAE,aAAa,CAAC,OAAO,CAAC,GAC3B,OAAO,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;CAGjC"}
|
package/dist/pipeline/index.js
CHANGED
|
@@ -1,3 +1,43 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
|
|
3
|
+
import { __PIPELINE_STAGE_SCOPE__, DeployStage, Pipeline as LeafPipeline } from '@aws-blocks/pipeline';
|
|
4
|
+
import { blocksStoreConfig } from '../secret-naming.js';
|
|
5
|
+
export { __PIPELINE_STAGE_SCOPE__, DeployStage };
|
|
6
|
+
/**
|
|
7
|
+
* Merge the Blocks `/blocks/*` namespace as the DEFAULT store config, so a
|
|
8
|
+
* Blocks pipeline resolves `connectionArn` / `buildSecrets` from the same place
|
|
9
|
+
* the Blocks CLI (`npm run secret` / `npm run config`) writes. Per-kind and
|
|
10
|
+
* shallow: any field the caller sets (a custom `prefix`, a `stage`, a
|
|
11
|
+
* `cacheTtlSeconds`) wins over the Blocks default.
|
|
12
|
+
*/
|
|
13
|
+
function withBlocksDefaults(props) {
|
|
14
|
+
const blocks = blocksStoreConfig();
|
|
15
|
+
return {
|
|
16
|
+
...props,
|
|
17
|
+
secretStore: { ...blocks.secretStore, ...props.secretStore },
|
|
18
|
+
configStore: { ...blocks.configStore, ...props.configStore },
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Blocks `Pipeline` — the framework-neutral `@aws-blocks/pipeline` construct with
|
|
23
|
+
* the Blocks value namespace pinned. It defaults `secretStore` / `configStore` to
|
|
24
|
+
* `/blocks/secrets` and `/blocks/config` (the prefixes the Blocks `secret` /
|
|
25
|
+
* `config` CLIs write), mirroring how the Blocks `Hosting` block pins the same
|
|
26
|
+
* namespace — so a value set with `npm run secret`/`config` is the value the
|
|
27
|
+
* pipeline reads. Pass `secretStore` / `configStore` to override.
|
|
28
|
+
*
|
|
29
|
+
* @see {@link https://github.com/aws-devtools-labs/aws-blocks/blob/main/packages/pipeline/README.md}
|
|
30
|
+
*/
|
|
31
|
+
export class Pipeline extends LeafPipeline {
|
|
32
|
+
constructor(scope, id, props) {
|
|
33
|
+
super(scope, id, withBlocksDefaults(props));
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Async constructor — required when `source.connectionArn` is a `config()`
|
|
37
|
+
* marker (resolved at synth time). Pins the Blocks namespace, then delegates to
|
|
38
|
+
* the leaf {@link LeafPipeline.create}.
|
|
39
|
+
*/
|
|
40
|
+
static async create(scope, id, props) {
|
|
41
|
+
return LeafPipeline.create(scope, id, withBlocksDefaults(props));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pipeline.test.d.ts","sourceRoot":"","sources":["../src/pipeline.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import assert from 'node:assert';
|
|
4
|
+
import { afterEach, describe, it } from 'node:test';
|
|
5
|
+
import { _setSynthSecretFetcher } from '@aws-blocks/hosting/constructs';
|
|
6
|
+
import { config } from '@aws-blocks/hosting';
|
|
7
|
+
import { App, Stack } from 'aws-cdk-lib';
|
|
8
|
+
import { Pipeline } from './pipeline/index.js';
|
|
9
|
+
const MOCK_CONNECTION_ARN = 'arn:aws:codeconnections:us-east-1:123456789012:connection/test-connection-id';
|
|
10
|
+
function minimalStageFactory(scope, stageConfig) {
|
|
11
|
+
new Stack(scope, 'AppStack', { env: stageConfig.env });
|
|
12
|
+
}
|
|
13
|
+
// B2: the core Pipeline wrapper must resolve values from the SAME namespace the
|
|
14
|
+
// Blocks CLI writes (`/blocks/*`), not the leaf-neutral `/hosting/*` — otherwise
|
|
15
|
+
// `npm run config -- set CONNECTION_ARN` writes one name and the deploy reads
|
|
16
|
+
// another. The leaf default is `/hosting/config`; the wrapper must pin `/blocks/config`.
|
|
17
|
+
void describe('core Pipeline pins the Blocks namespace', () => {
|
|
18
|
+
afterEach(() => _setSynthSecretFetcher(null));
|
|
19
|
+
void it('resolves a config() connectionArn under /blocks/config by default', async () => {
|
|
20
|
+
const seen = [];
|
|
21
|
+
_setSynthSecretFetcher(async (locator) => {
|
|
22
|
+
seen.push(locator);
|
|
23
|
+
return MOCK_CONNECTION_ARN;
|
|
24
|
+
});
|
|
25
|
+
await Pipeline.create(new App(), 'BlocksPipeline', {
|
|
26
|
+
source: { repo: 'my-org/my-app', connectionArn: config('CONNECTION_ARN') },
|
|
27
|
+
branches: [{ branch: 'main', stages: [{ name: 'prod' }] }],
|
|
28
|
+
stageFactory: minimalStageFactory,
|
|
29
|
+
});
|
|
30
|
+
// The Blocks CLI writes /blocks/config/CONNECTION_ARN; the wrapper must read it there.
|
|
31
|
+
assert.deepStrictEqual(seen, ['/blocks/config/CONNECTION_ARN']);
|
|
32
|
+
});
|
|
33
|
+
void it('lets the caller override the pinned prefix', async () => {
|
|
34
|
+
const seen = [];
|
|
35
|
+
_setSynthSecretFetcher(async (locator) => {
|
|
36
|
+
seen.push(locator);
|
|
37
|
+
return MOCK_CONNECTION_ARN;
|
|
38
|
+
});
|
|
39
|
+
await Pipeline.create(new App(), 'OverridePipeline', {
|
|
40
|
+
source: { repo: 'my-org/my-app', connectionArn: config('CONNECTION_ARN') },
|
|
41
|
+
branches: [{ branch: 'main', stages: [{ name: 'prod' }] }],
|
|
42
|
+
stageFactory: minimalStageFactory,
|
|
43
|
+
configStore: { prefix: '/myapp/config' },
|
|
44
|
+
});
|
|
45
|
+
assert.deepStrictEqual(seen, ['/myapp/config/CONNECTION_ARN']);
|
|
46
|
+
});
|
|
47
|
+
});
|
package/dist/rpc.d.ts
CHANGED
|
@@ -14,6 +14,27 @@ export type RpcParseResult = {
|
|
|
14
14
|
ok: false;
|
|
15
15
|
response: string;
|
|
16
16
|
};
|
|
17
|
+
/**
|
|
18
|
+
* Maximum accepted request-body size, in bytes (10 MiB).
|
|
19
|
+
*
|
|
20
|
+
* Matches the payload limit API Gateway enforces in production (~10 MB for a
|
|
21
|
+
* REST API). In prod an oversized body is rejected by API Gateway at the edge —
|
|
22
|
+
* before the Lambda is invoked — so this guard's rejection path effectively
|
|
23
|
+
* runs on the dev/mock server, where there is no edge to stop it: an oversized
|
|
24
|
+
* body would otherwise buffer and wedge the local database (e.g. PGlite). By
|
|
25
|
+
* enforcing the *same* limit locally, the dev server rejects the same oversized
|
|
26
|
+
* body prod would 413 at the edge, instead of failing only in one environment.
|
|
27
|
+
* Enforced in `parseRpcRequest`, the single choke point both the Lambda handler
|
|
28
|
+
* and the dev server route through.
|
|
29
|
+
*
|
|
30
|
+
* Note: this value is the Lambda + API Gateway limit. It lives here (in the
|
|
31
|
+
* compute-agnostic parser) because Lambda is the only compute path today. When
|
|
32
|
+
* a non-API-Gateway compute (e.g. container/ALB) is introduced, this should
|
|
33
|
+
* become compute-aware — sourced from / overridden by the compute layer (via
|
|
34
|
+
* the Compute `setEnv` config hook) rather than a fixed constant in `core` —
|
|
35
|
+
* since an ALB has a different payload limit. Tracked with the multi-compute work.
|
|
36
|
+
*/
|
|
37
|
+
export declare const MAX_RPC_BODY_BYTES: number;
|
|
17
38
|
/** Reserved JSON-RPC error codes. */
|
|
18
39
|
export declare const RpcErrorCode: {
|
|
19
40
|
readonly ParseError: -32700;
|
package/dist/rpc.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rpc.d.ts","sourceRoot":"","sources":["../src/rpc.ts"],"names":[],"mappings":"AAgBA,0EAA0E;AAC1E,MAAM,WAAW,gBAAgB;IAC/B,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,wFAAwF;IACxF,IAAI,EAAE,OAAO,EAAE,CAAC;IAChB,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;CAC5B;AAED,yDAAyD;AACzD,MAAM,MAAM,cAAc,GACtB;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,OAAO,EAAE,gBAAgB,CAAA;CAAE,GACvC;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC;AAMpC,qCAAqC;AACrC,eAAO,MAAM,YAAY;;;;;;CAMf,CAAC;AAMX,8DAA8D;AAC9D,wBAAgB,gBAAgB,CAAC,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,MAAM,CAO9F;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAiBxD;AAID;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,cAAc,
|
|
1
|
+
{"version":3,"file":"rpc.d.ts","sourceRoot":"","sources":["../src/rpc.ts"],"names":[],"mappings":"AAgBA,0EAA0E;AAC1E,MAAM,WAAW,gBAAgB;IAC/B,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,wFAAwF;IACxF,IAAI,EAAE,OAAO,EAAE,CAAC;IAChB,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,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CHANGED
|
@@ -11,6 +11,27 @@
|
|
|
11
11
|
import { ApiError } from './errors.js';
|
|
12
12
|
// ── Constants ───────────────────────────────────────────────────────────────
|
|
13
13
|
const VERSION = '2.0';
|
|
14
|
+
/**
|
|
15
|
+
* Maximum accepted request-body size, in bytes (10 MiB).
|
|
16
|
+
*
|
|
17
|
+
* Matches the payload limit API Gateway enforces in production (~10 MB for a
|
|
18
|
+
* REST API). In prod an oversized body is rejected by API Gateway at the edge —
|
|
19
|
+
* before the Lambda is invoked — so this guard's rejection path effectively
|
|
20
|
+
* runs on the dev/mock server, where there is no edge to stop it: an oversized
|
|
21
|
+
* body would otherwise buffer and wedge the local database (e.g. PGlite). By
|
|
22
|
+
* enforcing the *same* limit locally, the dev server rejects the same oversized
|
|
23
|
+
* body prod would 413 at the edge, instead of failing only in one environment.
|
|
24
|
+
* Enforced in `parseRpcRequest`, the single choke point both the Lambda handler
|
|
25
|
+
* and the dev server route through.
|
|
26
|
+
*
|
|
27
|
+
* Note: this value is the Lambda + API Gateway limit. It lives here (in the
|
|
28
|
+
* compute-agnostic parser) because Lambda is the only compute path today. When
|
|
29
|
+
* a non-API-Gateway compute (e.g. container/ALB) is introduced, this should
|
|
30
|
+
* become compute-aware — sourced from / overridden by the compute layer (via
|
|
31
|
+
* the Compute `setEnv` config hook) rather than a fixed constant in `core` —
|
|
32
|
+
* since an ALB has a different payload limit. Tracked with the multi-compute work.
|
|
33
|
+
*/
|
|
34
|
+
export const MAX_RPC_BODY_BYTES = 10 * 1024 * 1024;
|
|
14
35
|
/** Reserved JSON-RPC error codes. */
|
|
15
36
|
export const RpcErrorCode = {
|
|
16
37
|
ParseError: -32700,
|
|
@@ -58,6 +79,19 @@ export function decodeRpcResponse(body) {
|
|
|
58
79
|
* anything about the JSON-RPC spec.
|
|
59
80
|
*/
|
|
60
81
|
export function parseRpcRequest(bodyText) {
|
|
82
|
+
// Reject oversized bodies before parsing or dispatch. See MAX_RPC_BODY_BYTES
|
|
83
|
+
// for the limit and its rationale.
|
|
84
|
+
if (Buffer.byteLength(bodyText, 'utf8') > MAX_RPC_BODY_BYTES) {
|
|
85
|
+
// Emit the real HTTP status (413) as the error code, not a reserved -32xxx:
|
|
86
|
+
// `decodeRpcResponse` maps a positive code straight to `ApiError.status`
|
|
87
|
+
// (reserved codes collapse to 500), mirroring the 504 handler-timeout path,
|
|
88
|
+
// so a caller's `e.status === 413` works. `name` (which crosses the wire,
|
|
89
|
+
// not the code) lets callers match with `isBlocksError(e, 'PayloadTooLarge')`.
|
|
90
|
+
return {
|
|
91
|
+
ok: false,
|
|
92
|
+
response: errorResponse(413, `Request body exceeds the ${MAX_RPC_BODY_BYTES} byte (${MAX_RPC_BODY_BYTES / (1024 * 1024)} MiB) limit`, null, { name: 'PayloadTooLarge' }),
|
|
93
|
+
};
|
|
94
|
+
}
|
|
61
95
|
let parsed;
|
|
62
96
|
try {
|
|
63
97
|
parsed = JSON.parse(bodyText || '{}');
|
package/dist/rpc.test.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
import { describe, it } from 'node:test';
|
|
4
4
|
import assert from 'node:assert';
|
|
5
|
-
import { decodeRpcResponse, errorResponseFromCatch, parseRpcRequest, RpcErrorCode } from './rpc.js';
|
|
5
|
+
import { decodeRpcResponse, errorResponseFromCatch, parseRpcRequest, RpcErrorCode, MAX_RPC_BODY_BYTES } from './rpc.js';
|
|
6
6
|
import { ApiError, isBlocksError } from './errors.js';
|
|
7
7
|
describe('-32600 Invalid Request error shape', () => {
|
|
8
8
|
it('returns proper JSON-RPC 2.0 envelope with error code', () => {
|
|
@@ -154,3 +154,40 @@ describe('ApiError status ↔ JSON-RPC error code', () => {
|
|
|
154
154
|
assert.throws(() => decodeRpcResponse({ jsonrpc: '2.0', error: { code: RpcErrorCode.InvalidRequest, message: 'Invalid Request' }, id: null }), (e) => e instanceof ApiError && e.status === 500);
|
|
155
155
|
});
|
|
156
156
|
});
|
|
157
|
+
describe('request body size limit', () => {
|
|
158
|
+
it('accepts a normal-sized body', () => {
|
|
159
|
+
const result = parseRpcRequest(JSON.stringify({ jsonrpc: '2.0', method: 'ns.method', params: [], id: 1 }));
|
|
160
|
+
assert.strictEqual(result.ok, true);
|
|
161
|
+
});
|
|
162
|
+
it('rejects a body larger than MAX_RPC_BODY_BYTES with a PayloadTooLarge error', () => {
|
|
163
|
+
// A JSON string just over the limit (a single huge param value).
|
|
164
|
+
const huge = 'x'.repeat(MAX_RPC_BODY_BYTES + 1);
|
|
165
|
+
const body = JSON.stringify({ jsonrpc: '2.0', method: 'ns.method', params: [huge], id: 1 });
|
|
166
|
+
assert.ok(Buffer.byteLength(body, 'utf8') > MAX_RPC_BODY_BYTES);
|
|
167
|
+
const result = parseRpcRequest(body);
|
|
168
|
+
assert.strictEqual(result.ok, false);
|
|
169
|
+
if (result.ok)
|
|
170
|
+
return; // narrow
|
|
171
|
+
const parsed = JSON.parse(result.response);
|
|
172
|
+
// Positive HTTP status (413), not a reserved -32xxx — so decodeRpcResponse
|
|
173
|
+
// surfaces it to the client as ApiError.status === 413.
|
|
174
|
+
assert.strictEqual(parsed.error.code, 413);
|
|
175
|
+
assert.strictEqual(parsed.error.data?.name, 'PayloadTooLarge');
|
|
176
|
+
assert.match(parsed.error.message, /exceeds/);
|
|
177
|
+
assert.match(parsed.error.message, /10 MiB/); // human-readable size crosses the wire
|
|
178
|
+
// Client round-trip: decodeRpcResponse surfaces it as ApiError.status 413
|
|
179
|
+
// (not 500), so consumer `e.status === 413` handling works.
|
|
180
|
+
assert.throws(() => decodeRpcResponse(parsed), (e) => e instanceof ApiError && e.status === 413 && isBlocksError(e, 'PayloadTooLarge'));
|
|
181
|
+
});
|
|
182
|
+
it('rejects an oversized body before attempting to parse it (invalid JSON still 413s, not a ParseError)', () => {
|
|
183
|
+
// Oversized AND not valid JSON — the size guard must win, proving the body
|
|
184
|
+
// is rejected before the (expensive) parse + before any handler/DB touch.
|
|
185
|
+
const oversizedGarbage = 'x'.repeat(MAX_RPC_BODY_BYTES + 1);
|
|
186
|
+
const result = parseRpcRequest(oversizedGarbage);
|
|
187
|
+
assert.strictEqual(result.ok, false);
|
|
188
|
+
if (result.ok)
|
|
189
|
+
return;
|
|
190
|
+
const parsed = JSON.parse(result.response);
|
|
191
|
+
assert.strictEqual(parsed.error.data?.name, 'PayloadTooLarge');
|
|
192
|
+
});
|
|
193
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** Set (create or overwrite) a Blocks config value. */
|
|
2
|
+
export declare function setConfig(key: string, value: string, opts?: {
|
|
3
|
+
stage?: string;
|
|
4
|
+
}): Promise<void>;
|
|
5
|
+
/** List Blocks config keys (names only). */
|
|
6
|
+
export declare function listConfig(opts?: {
|
|
7
|
+
stage?: string;
|
|
8
|
+
}): Promise<string[]>;
|
|
9
|
+
/** Remove a Blocks config value. */
|
|
10
|
+
export declare function removeConfig(key: string, opts?: {
|
|
11
|
+
stage?: string;
|
|
12
|
+
}): Promise<boolean>;
|
|
13
|
+
/** CLI dispatcher for `blocks config <set|list|remove> …`. */
|
|
14
|
+
export declare function runConfigCli(argv: string[]): Promise<void>;
|
|
15
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/scripts/config.ts"],"names":[],"mappings":"AAgBA,uDAAuD;AACvD,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,GAAE;IAAE,KAAK,CAAC,EAAE,MAAM,CAAA;CAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAElG;AAED,4CAA4C;AAC5C,wBAAgB,UAAU,CAAC,IAAI,GAAE;IAAE,KAAK,CAAC,EAAE,MAAM,CAAA;CAAO,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAE3E;AAED,oCAAoC;AACpC,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,GAAE;IAAE,KAAK,CAAC,EAAE,MAAM,CAAA;CAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAEzF;AAED,8DAA8D;AAC9D,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAE1D"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
/**
|
|
4
|
+
* `blocks config` — manage a Blocks app's non-sensitive **config** values (SSM
|
|
5
|
+
* Parameter Store), pinned to the Blocks `/blocks/<stackId>/config` namespace
|
|
6
|
+
* (scoped to the app's stable `stackId` from `.blocks/config.json`). Thin wrapper
|
|
7
|
+
* over the shared `@aws-blocks/hosting` CLI with the kind fixed to `config`. The
|
|
8
|
+
* `secret` counterpart is `./secret.ts`.
|
|
9
|
+
*
|
|
10
|
+
* @module
|
|
11
|
+
*/
|
|
12
|
+
import { listValues, removeValue, runValueCli, setValue } from '@aws-blocks/hosting/scripts';
|
|
13
|
+
import { blocksConfigPrefix } from '../secret-naming.js';
|
|
14
|
+
/** Set (create or overwrite) a Blocks config value. */
|
|
15
|
+
export function setConfig(key, value, opts = {}) {
|
|
16
|
+
return setValue('config', key, value, { prefix: blocksConfigPrefix(), ...opts });
|
|
17
|
+
}
|
|
18
|
+
/** List Blocks config keys (names only). */
|
|
19
|
+
export function listConfig(opts = {}) {
|
|
20
|
+
return listValues('config', { prefix: blocksConfigPrefix(), ...opts });
|
|
21
|
+
}
|
|
22
|
+
/** Remove a Blocks config value. */
|
|
23
|
+
export function removeConfig(key, opts = {}) {
|
|
24
|
+
return removeValue('config', key, { prefix: blocksConfigPrefix(), ...opts });
|
|
25
|
+
}
|
|
26
|
+
/** CLI dispatcher for `blocks config <set|list|remove> …`. */
|
|
27
|
+
export function runConfigCli(argv) {
|
|
28
|
+
return runValueCli(argv, { kind: 'config', prefix: blocksConfigPrefix(), label: 'blocks config' });
|
|
29
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deploy.d.ts","sourceRoot":"","sources":["../../src/scripts/deploy.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"deploy.d.ts","sourceRoot":"","sources":["../../src/scripts/deploy.ts"],"names":[],"mappings":"AAcA,MAAM,WAAW,aAAa;IAC5B,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,wBAAsB,MAAM,CAAC,OAAO,EAAE,aAAa,iBAqGlD"}
|
package/dist/scripts/deploy.js
CHANGED
|
@@ -5,6 +5,7 @@ import { readFileSync, writeFileSync, mkdirSync } from 'node:fs';
|
|
|
5
5
|
import { join, resolve, dirname } from 'node:path';
|
|
6
6
|
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
7
7
|
import { ensureSecrets, loadProductionEnv } from './ensure-secrets.js';
|
|
8
|
+
import { assertAwsCredentials } from './preflight-credentials.js';
|
|
8
9
|
import { applyExternalMigrations } from './external-migrations-step.js';
|
|
9
10
|
import { trackCommand } from '../telemetry/trackCommand.js';
|
|
10
11
|
import { getCdkTelemetryEnv } from './cdk-telemetry-env.js';
|
|
@@ -15,6 +16,9 @@ export async function deploy(options) {
|
|
|
15
16
|
// Load production environment (from .env.production or CI env vars)
|
|
16
17
|
loadProductionEnv();
|
|
17
18
|
process.env.BLOCKS_STAGE = 'production';
|
|
19
|
+
// Fail fast if AWS credentials are missing/expired, before generating the
|
|
20
|
+
// client and spending time in synth only to hit an opaque CDK credential error.
|
|
21
|
+
await assertAwsCredentials('deploy');
|
|
18
22
|
// Provision secrets for production. projectRoot must match the root cdk
|
|
19
23
|
// synth uses (passed as --context below) so the written parameter name
|
|
20
24
|
// equals the one the app resolves at synth.
|
|
@@ -43,6 +43,14 @@ export interface DevServerOptions {
|
|
|
43
43
|
frontendCommand?: string;
|
|
44
44
|
/** Port the frontend dev server listens on. Default: 3100. */
|
|
45
45
|
frontendPort?: number;
|
|
46
|
+
/**
|
|
47
|
+
* Watch `secret()` / `config()` calls and regenerate the type-safe key
|
|
48
|
+
* augmentation (so `getSecret`/`getConfig` autocomplete and reject typos) as you
|
|
49
|
+
* edit — all under this one `npm run dev`, no second command. Auto-detected: a
|
|
50
|
+
* no-op unless the app actually declares a `secret()`/`config()`, and never fatal
|
|
51
|
+
* (a failure only logs a warning). Set `false` to disable. Default: enabled.
|
|
52
|
+
*/
|
|
53
|
+
typegen?: boolean;
|
|
46
54
|
}
|
|
47
55
|
/**
|
|
48
56
|
* Single-shot TCP probe: resolves `true` iff a connection to `port` succeeds
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dev-server.d.ts","sourceRoot":"","sources":["../../src/scripts/dev-server.ts"],"names":[],"mappings":"AAsCA,eAAO,MAAM,iBAAiB,QAAiD,CAAC;AAEhF;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAE3D;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CASjF;AAED,sFAAsF;AACtF,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,OAAO,GAAG,SAAS,CAAC;CAClC;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,GAAG,mBAAmB,CAKvF;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAE/E;AAED,MAAM,WAAW,gBAAgB;IAC/B,2CAA2C;IAC3C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,oCAAoC;IACpC,WAAW,EAAE,MAAM,CAAC;IACpB;;;OAG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AAE,gBAAgB,iBA0iB7D"}
|
|
@@ -75,6 +75,31 @@ export function buildBlocksConfig(port, isSandbox) {
|
|
|
75
75
|
export function isBlocksConfigRequest(method, pathname) {
|
|
76
76
|
return method === 'GET' && pathname === `${BLOCKS_SANDBOX_PREFIX}/config.json`;
|
|
77
77
|
}
|
|
78
|
+
/**
|
|
79
|
+
* Bootstrap the type-safe `getSecret`/`getConfig` key generation for the dev
|
|
80
|
+
* session. Auto-detected and non-fatal: scans the app for `secret()`/`config()`
|
|
81
|
+
* calls and, only if it finds any, generates the augmentation `.d.ts` and starts a
|
|
82
|
+
* watcher that regenerates on save — so a single `npm run dev` gives type-safe keys
|
|
83
|
+
* with no second command. Returns a `stop()` (or `undefined` when the app declares
|
|
84
|
+
* no secrets, typegen is unavailable, or it is disabled). The watcher is `unref`'d
|
|
85
|
+
* so it can never block the dev server's shutdown.
|
|
86
|
+
*/
|
|
87
|
+
async function startTypegenWatch() {
|
|
88
|
+
try {
|
|
89
|
+
const { scanValueKeys, watchHostingValues } = await import('@aws-blocks/hosting/scripts');
|
|
90
|
+
const scan = await scanValueKeys();
|
|
91
|
+
if (scan.secretKeys.length === 0 && scan.configKeys.length === 0) {
|
|
92
|
+
return undefined; // app doesn't use secret()/config() → nothing to type, skip silently
|
|
93
|
+
}
|
|
94
|
+
console.log('🔑 Type-safe secret()/config() keys — watching for changes...');
|
|
95
|
+
return await watchHostingValues({ unref: true });
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
// Never break the dev server over typegen (e.g. `typescript` not installed).
|
|
99
|
+
console.warn(`⚠️ hosting-typegen skipped: ${error instanceof Error ? error.message : String(error)}`);
|
|
100
|
+
return undefined;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
78
103
|
/**
|
|
79
104
|
* Initialize all building blocks that have an initialize() method.
|
|
80
105
|
* This is the "local deploy" phase - mirrors CDK deploy.
|
|
@@ -790,6 +815,11 @@ export async function startDevServer(options) {
|
|
|
790
815
|
console.log('📝 Generating client code...');
|
|
791
816
|
await writeClientCode(resolvedPath, clientPath);
|
|
792
817
|
}
|
|
818
|
+
// Type-safe getSecret/getConfig: generate + watch the key augmentation so the
|
|
819
|
+
// getters autocomplete and reject typos, regenerating on save — all under this
|
|
820
|
+
// one `npm run dev`. Auto-detected (no-op unless the app uses secret()/config())
|
|
821
|
+
// and non-fatal.
|
|
822
|
+
const stopTypegen = options.typegen === false ? undefined : await startTypegenWatch();
|
|
793
823
|
// ── Startup reclaim ──────────────────────────────────────────────────────
|
|
794
824
|
// Free any port left bound by a crashed / SIGKILL'd predecessor before we bind
|
|
795
825
|
// the front door or spawn the `--strictPort` frontend. tsx-watch only gives the
|
|
@@ -875,6 +905,7 @@ export async function startDevServer(options) {
|
|
|
875
905
|
clearTimeout(respawnTimer);
|
|
876
906
|
respawnTimer = null;
|
|
877
907
|
}
|
|
908
|
+
stopTypegen?.(); // tear down the typegen watcher (unref'd, but close it cleanly)
|
|
878
909
|
// Detach our own listeners so repeated signals can't pile up handlers.
|
|
879
910
|
for (const sig of signals)
|
|
880
911
|
process.removeListener(sig, cleanup);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate-client.d.ts","sourceRoot":"","sources":["../../src/scripts/generate-client.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"generate-client.d.ts","sourceRoot":"","sources":["../../src/scripts/generate-client.ts"],"names":[],"mappings":"AASA;;;;;;;GAOG;AACH,wBAAsB,kBAAkB,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAgEhF;AAED;;GAEG;AACH,wBAAsB,eAAe,CAAC,cAAc,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAI/F"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
3
|
+
import { isManagedValue } from '@aws-blocks/hosting';
|
|
4
|
+
import { mkdirSync, writeFileSync } from 'node:fs';
|
|
5
|
+
import { dirname } from 'node:path';
|
|
6
|
+
import { pathToFileURL } from 'node:url';
|
|
6
7
|
import { API_NAMESPACE_MARKER } from '../api.js';
|
|
7
8
|
/**
|
|
8
9
|
* Generate browser-safe client code from backend exports.
|
|
@@ -43,6 +44,10 @@ export async function generateClientCode(foundationPath) {
|
|
|
43
44
|
const isScope = typeof value?.id === 'string' && typeof value?.fullId === 'string';
|
|
44
45
|
if (isScope)
|
|
45
46
|
continue;
|
|
47
|
+
// A secret()/config() marker is a deferred value, not an API — skip it, or
|
|
48
|
+
// `export const k = secret('K')` in index.ts would become a bogus HTTP namespace.
|
|
49
|
+
if (isManagedValue(value))
|
|
50
|
+
continue;
|
|
46
51
|
// Fallback: any exported function/object gets an ApiNamespace proxy.
|
|
47
52
|
if ((typeof value === 'function' || typeof value === 'object') && value !== null) {
|
|
48
53
|
lines.push(`export const ${name} = __BLOCKS_ApiNamespaceClient__('${name}');`);
|
|
@@ -50,7 +55,7 @@ export async function generateClientCode(foundationPath) {
|
|
|
50
55
|
}
|
|
51
56
|
}
|
|
52
57
|
// Emit generateClient — creates new ApiNamespaceClient instances with the given url
|
|
53
|
-
const nsEntries = namespaceNames.map(n => ` ${n}: __BLOCKS_ApiNamespaceClient__('${n}', config),`).join('\n');
|
|
58
|
+
const nsEntries = namespaceNames.map((n) => ` ${n}: __BLOCKS_ApiNamespaceClient__('${n}', config),`).join('\n');
|
|
54
59
|
lines.push('');
|
|
55
60
|
lines.push(`export const generateClient = (config) => ({\n${nsEntries}\n});`);
|
|
56
61
|
const header = [
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
import { describe, it, beforeEach, afterEach } from 'node:test';
|
|
4
3
|
import assert from 'node:assert';
|
|
4
|
+
import { afterEach, beforeEach, describe, it } from 'node:test';
|
|
5
|
+
import { mkdirSync, rmSync, writeFileSync } from 'node:fs';
|
|
6
|
+
import { tmpdir } from 'node:os';
|
|
7
|
+
import { join } from 'node:path';
|
|
5
8
|
import { generateClientCode } from './generate-client.js';
|
|
6
|
-
import { writeFileSync, mkdirSync, rmSync } from 'fs';
|
|
7
|
-
import { join } from 'path';
|
|
8
|
-
import { tmpdir } from 'os';
|
|
9
9
|
/**
|
|
10
10
|
* Regression test: generateClientCode collects middleware from whatever
|
|
11
11
|
* the backend registers via registerClientMiddleware(). In sandbox mode,
|
|
@@ -45,4 +45,19 @@ describe('generateClientCode — middleware collection', () => {
|
|
|
45
45
|
assert.ok(code.includes("import '@aws-blocks/bb-realtime/mock-middleware'"), 'Generated client must include mock-middleware in local dev mode');
|
|
46
46
|
assert.ok(!code.includes('aws-middleware'), 'Generated client must NOT include aws-middleware in local dev mode');
|
|
47
47
|
});
|
|
48
|
+
it('skips secret()/config() markers — they are values, not API namespaces', async () => {
|
|
49
|
+
// A secret()/config() marker is branded with Symbol.for('@aws-blocks/hosting.ManagedValue');
|
|
50
|
+
// build one inline so the fixture needs no imports. A real export still gets a proxy.
|
|
51
|
+
const backendPath = join(tmpDir, 'backend.mjs');
|
|
52
|
+
writeFileSync(backendPath, `
|
|
53
|
+
const BRAND = Symbol.for('@aws-blocks/hosting.ManagedValue');
|
|
54
|
+
export const stripeKey = { [BRAND]: true, key: 'STRIPE_KEY', kind: 'secret' };
|
|
55
|
+
export const featureFlags = { [BRAND]: true, key: 'FEATURE_FLAGS', kind: 'config' };
|
|
56
|
+
export function realApi() {}
|
|
57
|
+
`);
|
|
58
|
+
const code = await generateClientCode(backendPath);
|
|
59
|
+
assert.ok(!code.includes("__BLOCKS_ApiNamespaceClient__('stripeKey')"), 'a secret() marker must not become an HTTP namespace');
|
|
60
|
+
assert.ok(!code.includes("__BLOCKS_ApiNamespaceClient__('featureFlags')"), 'a config() marker must not become an HTTP namespace');
|
|
61
|
+
assert.ok(code.includes("export const realApi = __BLOCKS_ApiNamespaceClient__('realApi')"), 'a real (non-marker) export still becomes a namespace');
|
|
62
|
+
});
|
|
48
63
|
});
|