@aws-blocks/core 0.1.18 → 0.2.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/__fixtures__/import-meta-handler.d.ts +6 -0
- package/dist/cdk/__fixtures__/import-meta-handler.d.ts.map +1 -0
- package/dist/cdk/__fixtures__/import-meta-handler.js +13 -0
- package/dist/cdk/blocks-backend.d.ts +11 -0
- package/dist/cdk/blocks-backend.d.ts.map +1 -1
- package/dist/cdk/blocks-backend.js +22 -6
- package/dist/cdk/blocks-backend.test.js +66 -0
- package/dist/cdk/blocks-defaults.d.ts +44 -0
- package/dist/cdk/blocks-defaults.d.ts.map +1 -0
- package/dist/cdk/blocks-defaults.js +23 -0
- package/dist/cdk/blocks-defaults.test.d.ts +2 -0
- package/dist/cdk/blocks-defaults.test.d.ts.map +1 -0
- package/dist/cdk/blocks-defaults.test.js +22 -0
- package/dist/cdk/blocks-stack.test.js +8 -1
- package/dist/cdk/bundling.d.ts +42 -0
- package/dist/cdk/bundling.d.ts.map +1 -0
- package/dist/cdk/bundling.js +72 -0
- package/dist/cdk/bundling.test.d.ts +2 -0
- package/dist/cdk/bundling.test.d.ts.map +1 -0
- package/dist/cdk/bundling.test.js +80 -0
- package/dist/cdk/compute/compute.d.ts +33 -0
- package/dist/cdk/compute/compute.d.ts.map +1 -0
- package/dist/cdk/compute/compute.js +28 -0
- package/dist/cdk/index.d.ts +46 -7
- package/dist/cdk/index.d.ts.map +1 -1
- package/dist/cdk/index.js +84 -18
- package/dist/cdk/internal.d.ts +24 -0
- package/dist/cdk/internal.d.ts.map +1 -0
- package/dist/cdk/internal.js +27 -0
- package/dist/cdk/mixins.d.ts +18 -4
- package/dist/cdk/mixins.d.ts.map +1 -1
- package/dist/cdk/mixins.js +31 -7
- package/dist/cdk/mixins.test.js +45 -0
- package/dist/common/index.d.ts +9 -0
- package/dist/common/index.d.ts.map +1 -1
- package/dist/index.cdk.d.ts +2 -1
- package/dist/index.cdk.d.ts.map +1 -1
- package/dist/index.cdk.js +2 -1
- package/dist/rpc.d.ts.map +1 -1
- package/dist/rpc.js +12 -3
- package/dist/rpc.test.js +20 -0
- package/dist/scripts/telemetry.test.js +2 -0
- package/dist/telemetry/environment.d.ts.map +1 -1
- package/dist/telemetry/environment.js +3 -1
- package/dist/telemetry/telemetry.test.js +10 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +1 -1
- package/package.json +6 -1
- package/src/cdk/__fixtures__/import-meta-handler.ts +16 -0
- package/src/cdk/blocks-backend.test.ts +76 -0
- package/src/cdk/blocks-backend.ts +35 -6
- package/src/cdk/blocks-defaults.test.ts +25 -0
- package/src/cdk/blocks-defaults.ts +49 -0
- package/src/cdk/blocks-stack.test.ts +8 -1
- package/src/cdk/bundling.test.ts +90 -0
- package/src/cdk/bundling.ts +76 -0
- package/src/cdk/compute/compute.ts +37 -0
- package/src/cdk/index.ts +94 -19
- package/src/cdk/internal.ts +29 -0
- package/src/cdk/mixins.test.ts +56 -1
- package/src/cdk/mixins.ts +32 -7
- package/src/common/index.ts +9 -0
- package/src/index.cdk.ts +5 -1
- package/src/rpc.test.ts +22 -0
- package/src/rpc.ts +19 -3
- package/src/scripts/telemetry.test.ts +2 -0
- package/src/telemetry/environment.ts +3 -1
- package/src/telemetry/telemetry.test.ts +12 -0
- package/src/version.ts +1 -1
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import { test, describe } from 'node:test';
|
|
4
|
+
import assert from 'node:assert';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
6
|
+
import { dirname, join } from 'node:path';
|
|
7
|
+
import { mkdtempSync, rmSync } from 'node:fs';
|
|
8
|
+
import { tmpdir } from 'node:os';
|
|
9
|
+
import { createRequire } from 'node:module';
|
|
10
|
+
import { build } from 'esbuild';
|
|
11
|
+
import { OutputFormat } from 'aws-cdk-lib/aws-lambda-nodejs';
|
|
12
|
+
import { blocksNodejsBundling } from './bundling.js';
|
|
13
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
14
|
+
const importMetaFixture = join(__dirname, '__fixtures__', 'import-meta-handler.js');
|
|
15
|
+
const requireCjs = createRequire(import.meta.url);
|
|
16
|
+
describe('blocksNodejsBundling', () => {
|
|
17
|
+
test('injects the import.meta.* CJS shim for the default (CJS) output', () => {
|
|
18
|
+
const out = blocksNodejsBundling({ minify: true, esbuildArgs: { '--conditions': 'aws-runtime' } });
|
|
19
|
+
// Caller options are preserved.
|
|
20
|
+
assert.equal(out.minify, true);
|
|
21
|
+
assert.equal(out.esbuildArgs?.['--conditions'], 'aws-runtime');
|
|
22
|
+
// All three import.meta path properties are substituted.
|
|
23
|
+
assert.ok(out.esbuildArgs?.['--define:import.meta.url']);
|
|
24
|
+
assert.ok(out.esbuildArgs?.['--define:import.meta.dirname']);
|
|
25
|
+
assert.ok(out.esbuildArgs?.['--define:import.meta.filename']);
|
|
26
|
+
// The banner defines the substituted identifiers via CommonJS primitives.
|
|
27
|
+
assert.match(out.banner ?? '', /pathToFileURL\(__filename\)/);
|
|
28
|
+
assert.match(out.banner ?? '', /__dirname/);
|
|
29
|
+
assert.match(out.banner ?? '', /__filename/);
|
|
30
|
+
});
|
|
31
|
+
test('leaves ESM output untouched (import.meta works natively there)', () => {
|
|
32
|
+
const input = { format: OutputFormat.ESM, esbuildArgs: { '--conditions': 'aws-runtime' } };
|
|
33
|
+
const out = blocksNodejsBundling(input);
|
|
34
|
+
assert.deepEqual(out, input);
|
|
35
|
+
assert.equal(out.esbuildArgs?.['--define:import.meta.url'], undefined);
|
|
36
|
+
assert.equal(out.banner, undefined);
|
|
37
|
+
});
|
|
38
|
+
test('prepends the shim while keeping a caller-supplied banner', () => {
|
|
39
|
+
const out = blocksNodejsBundling({ banner: '// caller banner' });
|
|
40
|
+
assert.match(out.banner ?? '', /pathToFileURL\(__filename\)/);
|
|
41
|
+
assert.ok((out.banner ?? '').includes('// caller banner'));
|
|
42
|
+
});
|
|
43
|
+
test('a CJS bundle built with the shim resolves import.meta.url at load (no crash)', async () => {
|
|
44
|
+
// Bundle the fixture exactly as NodejsFunction would: apply the helper's `banner`
|
|
45
|
+
// and its `--define:import.meta.*` esbuildArgs. Without the shim this fixture's
|
|
46
|
+
// top-level `fileURLToPath(import.meta.url)` becomes `fileURLToPath(undefined)`
|
|
47
|
+
// and throws when the module is loaded.
|
|
48
|
+
const opts = blocksNodejsBundling({ minify: true });
|
|
49
|
+
const define = {};
|
|
50
|
+
for (const [key, value] of Object.entries(opts.esbuildArgs ?? {})) {
|
|
51
|
+
const m = key.match(/^--define:(.+)$/);
|
|
52
|
+
if (m)
|
|
53
|
+
define[m[1]] = String(value);
|
|
54
|
+
}
|
|
55
|
+
const tmp = mkdtempSync(join(tmpdir(), 'bb-shim-'));
|
|
56
|
+
const outfile = join(tmp, 'out.cjs');
|
|
57
|
+
try {
|
|
58
|
+
await build({
|
|
59
|
+
entryPoints: [importMetaFixture],
|
|
60
|
+
bundle: true,
|
|
61
|
+
platform: 'node',
|
|
62
|
+
format: 'cjs',
|
|
63
|
+
minify: true,
|
|
64
|
+
banner: { js: opts.banner ?? '' },
|
|
65
|
+
define,
|
|
66
|
+
outfile,
|
|
67
|
+
logLevel: 'silent',
|
|
68
|
+
});
|
|
69
|
+
// Loading the bundle must not throw, and import.meta.url must resolve to a real
|
|
70
|
+
// (file-URL-derived) path rather than being undefined.
|
|
71
|
+
const mod = requireCjs(outfile);
|
|
72
|
+
assert.equal(typeof mod.moduleDir, 'string');
|
|
73
|
+
assert.ok(mod.moduleDir.length > 0, 'moduleDir should resolve to a non-empty path');
|
|
74
|
+
assert.equal(typeof mod.handler, 'function');
|
|
75
|
+
}
|
|
76
|
+
finally {
|
|
77
|
+
rmSync(tmp, { recursive: true, force: true });
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Scope } from '../index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Base class for a Blocks *compute* — a runtime that executes handler code
|
|
4
|
+
* (Lambda today; containers later). A compute owns the physical function/service
|
|
5
|
+
* plus its ingress, and receives config via {@link setEnv}.
|
|
6
|
+
*
|
|
7
|
+
* The backend entry and stack name a compute needs are inherited from
|
|
8
|
+
* {@link Scope} (`backendHandlerPath` / `backendStackName`), which resolve them
|
|
9
|
+
* from the owning BlocksStack/BlocksBackend — never caller-supplied, so every
|
|
10
|
+
* compute in an app runs the same backend and agrees on the resource-name
|
|
11
|
+
* namespace.
|
|
12
|
+
*
|
|
13
|
+
* The abstract base lives in core (a framework primitive); concrete computes
|
|
14
|
+
* live in their own packages (e.g. `LambdaCompute` in `@aws-blocks/bb-lambda-compute`).
|
|
15
|
+
*
|
|
16
|
+
* @internal Not exported from the package's public entry points. Customers
|
|
17
|
+
* cannot instantiate a compute until the customer-facing surface exists.
|
|
18
|
+
*/
|
|
19
|
+
export declare abstract class Compute extends Scope {
|
|
20
|
+
/**
|
|
21
|
+
* API namespaces assigned to run on this compute — recorded so request
|
|
22
|
+
* routing can map a namespace to the compute that hosts it. Currently
|
|
23
|
+
* unpopulated (no compute assignment surface yet).
|
|
24
|
+
*/
|
|
25
|
+
readonly namespaces: string[];
|
|
26
|
+
/**
|
|
27
|
+
* Inject a runtime configuration value (an environment variable) into this
|
|
28
|
+
* compute. The framework calls this instead of `handler.addEnvironment()`
|
|
29
|
+
* directly so config targets the right compute.
|
|
30
|
+
*/
|
|
31
|
+
abstract setEnv(key: string, value: string): void;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=compute.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compute.d.ts","sourceRoot":"","sources":["../../../src/cdk/compute/compute.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEpC;;;;;;;;;;;;;;;;GAgBG;AACH,8BAAsB,OAAQ,SAAQ,KAAK;IAC1C;;;;OAIG;IACH,QAAQ,CAAC,UAAU,EAAE,MAAM,EAAE,CAAM;IAEnC;;;;OAIG;IACH,QAAQ,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;CACjD"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import { Scope } from '../index.js';
|
|
4
|
+
/**
|
|
5
|
+
* Base class for a Blocks *compute* — a runtime that executes handler code
|
|
6
|
+
* (Lambda today; containers later). A compute owns the physical function/service
|
|
7
|
+
* plus its ingress, and receives config via {@link setEnv}.
|
|
8
|
+
*
|
|
9
|
+
* The backend entry and stack name a compute needs are inherited from
|
|
10
|
+
* {@link Scope} (`backendHandlerPath` / `backendStackName`), which resolve them
|
|
11
|
+
* from the owning BlocksStack/BlocksBackend — never caller-supplied, so every
|
|
12
|
+
* compute in an app runs the same backend and agrees on the resource-name
|
|
13
|
+
* namespace.
|
|
14
|
+
*
|
|
15
|
+
* The abstract base lives in core (a framework primitive); concrete computes
|
|
16
|
+
* live in their own packages (e.g. `LambdaCompute` in `@aws-blocks/bb-lambda-compute`).
|
|
17
|
+
*
|
|
18
|
+
* @internal Not exported from the package's public entry points. Customers
|
|
19
|
+
* cannot instantiate a compute until the customer-facing surface exists.
|
|
20
|
+
*/
|
|
21
|
+
export class Compute extends Scope {
|
|
22
|
+
/**
|
|
23
|
+
* API namespaces assigned to run on this compute — recorded so request
|
|
24
|
+
* routing can map a namespace to the compute that hosts it. Currently
|
|
25
|
+
* unpopulated (no compute assignment surface yet).
|
|
26
|
+
*/
|
|
27
|
+
namespaces = [];
|
|
28
|
+
}
|
package/dist/cdk/index.d.ts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import * as cdk from 'aws-cdk-lib';
|
|
2
2
|
import { Construct } from 'constructs';
|
|
3
3
|
import { type BlocksStackProps, type BlocksStack as BaseBlocksStack, type ScopeParent, type ScopeOptions } from '../common/index.js';
|
|
4
|
+
import { type BlocksDefaults } from './blocks-defaults.js';
|
|
4
5
|
export { BlocksBackend, type BlocksBackendProps } from './blocks-backend.js';
|
|
5
6
|
export { DEFAULT_NODE_RUNTIME } from './node-version.js';
|
|
7
|
+
export { blocksNodejsBundling } from './bundling.js';
|
|
6
8
|
export { SandboxDisableDeletionProtection } from './mixins.js';
|
|
7
9
|
export { registerConfig, finalizeConfigRegistry } from './config-registry.js';
|
|
10
|
+
export { type BlocksDefaults, BlocksPresets, } from './blocks-defaults.js';
|
|
8
11
|
export { synthGuard } from './synth-guard.js';
|
|
9
12
|
export type { ScopeOptions } from '../index.js';
|
|
10
13
|
export { ApiError, isBlocksError, hasAuthError, DEFAULT_API_ERROR_NAME } from '../errors.js';
|
|
@@ -16,6 +19,8 @@ export declare class BlocksStack extends cdk.Stack implements BaseBlocksStack {
|
|
|
16
19
|
readonly backendHandlerPath: string;
|
|
17
20
|
/** Shared IAM role assumed by all Blocks compute. Building Blocks grant to this role. */
|
|
18
21
|
readonly executionRole: cdk.aws_iam.IRole;
|
|
22
|
+
/** Infrastructure defaults for Building Blocks created under this stack. */
|
|
23
|
+
readonly defaults: BlocksDefaults;
|
|
19
24
|
private constructor();
|
|
20
25
|
static create(scope: Construct, id: string, props: BlocksStackProps): Promise<BlocksStack>;
|
|
21
26
|
}
|
|
@@ -24,20 +29,54 @@ export declare class Scope extends Construct {
|
|
|
24
29
|
readonly parent: ScopeParent;
|
|
25
30
|
readonly bbName?: string;
|
|
26
31
|
readonly bbVersion?: string;
|
|
32
|
+
/**
|
|
33
|
+
* The owning stack/backend (the root of the Blocks construct tree), resolved
|
|
34
|
+
* once at construction: the nearest BlocksStack/BlocksBackend up the construct
|
|
35
|
+
* tree, or the ambient `globalThis.CURRENT_BLOCKS_STACK` fallback. All
|
|
36
|
+
* root-derived accessors below read from this instead of each repeating the
|
|
37
|
+
* tree walk.
|
|
38
|
+
*/
|
|
39
|
+
private readonly root;
|
|
27
40
|
constructor(id: string, options?: ScopeOptions);
|
|
41
|
+
/**
|
|
42
|
+
* Walk up the construct tree to the nearest owning BlocksStack/BlocksBackend;
|
|
43
|
+
* fall back to the ambient `globalThis.CURRENT_BLOCKS_STACK`. Called once from
|
|
44
|
+
* the constructor; the result is cached in {@link root}.
|
|
45
|
+
*/
|
|
46
|
+
private resolveRoot;
|
|
28
47
|
get handler(): cdk.aws_lambda_nodejs.NodejsFunction;
|
|
29
48
|
/**
|
|
30
49
|
* The shared IAM role assumed by all Blocks compute. Building Blocks grant
|
|
31
|
-
* their permissions to this role
|
|
32
|
-
*
|
|
33
|
-
* to the role's default (inline) policy — exactly where they landed on the
|
|
34
|
-
* auto-generated role before.
|
|
35
|
-
*
|
|
36
|
-
* Resolves the same way as {@link handler}: walk up to the owning
|
|
37
|
-
* BlocksStack/BlocksBackend, falling back to the ambient stack.
|
|
50
|
+
* their permissions to this role; CDK's `grant*()` / `addToPrincipalPolicy()`
|
|
51
|
+
* route those grants to the role's default (inline) policy.
|
|
38
52
|
*/
|
|
39
53
|
get executionRole(): cdk.aws_iam.IRole;
|
|
54
|
+
/**
|
|
55
|
+
* The backend entry file the owning BlocksStack/BlocksBackend runs — the
|
|
56
|
+
* single handler entry shared across the whole app.
|
|
57
|
+
*/
|
|
58
|
+
get backendHandlerPath(): string;
|
|
59
|
+
/**
|
|
60
|
+
* The owning stack/backend's token-free root identity. This is the value the
|
|
61
|
+
* runtime receives as `BLOCKS_STACK_NAME` and rebuilds `fullId` from, so
|
|
62
|
+
* physical resource names (DynamoDB tables, env-var keys, IAM ARNs) derived
|
|
63
|
+
* from `fullId` match byte-for-byte between synth and runtime — otherwise the
|
|
64
|
+
* runtime looks up names that were never created. `BlocksBackend` exposes this
|
|
65
|
+
* as `fullId` ({@link BlocksBackend.fullId}); `BlocksStack` as `id`.
|
|
66
|
+
*/
|
|
67
|
+
get backendStackName(): string;
|
|
40
68
|
get fullId(): string;
|
|
69
|
+
/**
|
|
70
|
+
* The stack-wide infrastructure {@link BlocksDefaults} registered by
|
|
71
|
+
* `BlocksStack.create` / `BlocksBackend.create`. Read these in a Building
|
|
72
|
+
* Block's CDK constructor to resolve a durability value, letting a per-block
|
|
73
|
+
* option override:
|
|
74
|
+
*
|
|
75
|
+
* ```ts
|
|
76
|
+
* const removalPolicy = options?.removalPolicy ?? this.defaults.removalPolicy;
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
get defaults(): BlocksDefaults;
|
|
41
80
|
protected buildUserAgentChain(): [string, string][];
|
|
42
81
|
registerClientMiddleware(_packageSpecifier: string): void;
|
|
43
82
|
registerDevAttachment(_packageSpecifier: string): void;
|
package/dist/cdk/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cdk/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,GAAG,MAAM,aAAa,CAAC;AACnC,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAGvC,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,WAAW,IAAI,eAAe,EACnC,KAAK,WAAW,EAChB,KAAK,YAAY,EAElB,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cdk/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,GAAG,MAAM,aAAa,CAAC;AACnC,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAGvC,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,WAAW,IAAI,eAAe,EACnC,KAAK,WAAW,EAChB,KAAK,YAAY,EAElB,MAAM,oBAAoB,CAAC;AAI5B,OAAO,EAAE,KAAK,cAAc,EAAiB,MAAM,sBAAsB,CAAC;AAE1E,OAAO,E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C;IACzB,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAE5B;;;;;;OAMG;IACH,OAAO,CAAC,QAAQ,CAAC,IAAI,CAA8B;gBAEvC,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY;IAQ9C;;;;OAIG;IACH,OAAO,CAAC,WAAW;IAcnB,IAAI,OAAO,yCAEV;IAED;;;;OAIG;IACH,IAAI,aAAa,IAAI,GAAG,CAAC,OAAO,CAAC,KAAK,CAErC;IAED;;;OAGG;IACH,IAAI,kBAAkB,IAAI,MAAM,CAE/B;IAED;;;;;;;OAOG;IACH,IAAI,gBAAgB,IAAI,MAAM,CAM7B;IAED,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED;;;;;;;;;OASG;IACH,IAAI,QAAQ,IAAI,cAAc,CAuB7B;IAED,SAAS,CAAC,mBAAmB,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE;IAKnD,wBAAwB,CAAC,iBAAiB,EAAE,MAAM,GAAG,IAAI;IACzD,qBAAqB,CAAC,iBAAiB,EAAE,MAAM,GAAG,IAAI;IACtD,0BAA0B,CAAC,YAAY,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,MAAM,EAAE,GAAG,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI;IACrH,IAAI,gBAAgB,IAAI,SAAS,MAAM,EAAE,CAAe;IACxD,IAAI,cAAc,IAAI,SAAS,MAAM,EAAE,CAAe;CACvD"}
|
package/dist/cdk/index.js
CHANGED
|
@@ -8,10 +8,13 @@ import { computeScopeFullId, } from '../common/index.js';
|
|
|
8
8
|
import { setupBlocksInfra, BlocksBackend, assertCdkConditionActive } from './blocks-backend.js';
|
|
9
9
|
import { addBlocksStackMetadata } from './stack-metadata.js';
|
|
10
10
|
import { finalizeConfigRegistry } from './config-registry.js';
|
|
11
|
+
import { BlocksPresets } from './blocks-defaults.js';
|
|
11
12
|
export { BlocksBackend } from './blocks-backend.js';
|
|
12
13
|
export { DEFAULT_NODE_RUNTIME } from './node-version.js';
|
|
14
|
+
export { blocksNodejsBundling } from './bundling.js';
|
|
13
15
|
export { SandboxDisableDeletionProtection } from './mixins.js';
|
|
14
16
|
export { registerConfig, finalizeConfigRegistry } from './config-registry.js';
|
|
17
|
+
export { BlocksPresets, } from './blocks-defaults.js';
|
|
15
18
|
export { synthGuard } from './synth-guard.js';
|
|
16
19
|
export { ApiError, isBlocksError, hasAuthError, DEFAULT_API_ERROR_NAME } from '../errors.js';
|
|
17
20
|
export class BlocksStack extends cdk.Stack {
|
|
@@ -22,10 +25,13 @@ export class BlocksStack extends cdk.Stack {
|
|
|
22
25
|
backendHandlerPath;
|
|
23
26
|
/** Shared IAM role assumed by all Blocks compute. Building Blocks grant to this role. */
|
|
24
27
|
executionRole;
|
|
28
|
+
/** Infrastructure defaults for Building Blocks created under this stack. */
|
|
29
|
+
defaults;
|
|
25
30
|
constructor(scope, id, props) {
|
|
26
31
|
super(scope, id, props);
|
|
27
32
|
this.id = id;
|
|
28
33
|
this.backendHandlerPath = props.backendHandlerPath;
|
|
34
|
+
this.defaults = props.defaults;
|
|
29
35
|
// Set globalThis so Building Blocks attach directly to this stack
|
|
30
36
|
globalThis.CURRENT_BLOCKS_STACK = this;
|
|
31
37
|
const infra = setupBlocksInfra(this, props, id);
|
|
@@ -65,47 +71,107 @@ export class Scope extends Construct {
|
|
|
65
71
|
parent;
|
|
66
72
|
bbName;
|
|
67
73
|
bbVersion;
|
|
74
|
+
/**
|
|
75
|
+
* The owning stack/backend (the root of the Blocks construct tree), resolved
|
|
76
|
+
* once at construction: the nearest BlocksStack/BlocksBackend up the construct
|
|
77
|
+
* tree, or the ambient `globalThis.CURRENT_BLOCKS_STACK` fallback. All
|
|
78
|
+
* root-derived accessors below read from this instead of each repeating the
|
|
79
|
+
* tree walk.
|
|
80
|
+
*/
|
|
81
|
+
root;
|
|
68
82
|
constructor(id, options) {
|
|
69
83
|
const parent = options?.parent || globalThis.CURRENT_BLOCKS_STACK;
|
|
70
84
|
super(parent, id);
|
|
71
85
|
this.id = id;
|
|
72
86
|
this.parent = parent;
|
|
87
|
+
this.root = this.resolveRoot();
|
|
73
88
|
}
|
|
74
|
-
|
|
75
|
-
|
|
89
|
+
/**
|
|
90
|
+
* Walk up the construct tree to the nearest owning BlocksStack/BlocksBackend;
|
|
91
|
+
* fall back to the ambient `globalThis.CURRENT_BLOCKS_STACK`. Called once from
|
|
92
|
+
* the constructor; the result is cached in {@link root}.
|
|
93
|
+
*/
|
|
94
|
+
resolveRoot() {
|
|
76
95
|
let current = this;
|
|
77
96
|
while (current.node.scope) {
|
|
78
97
|
current = current.node.scope;
|
|
79
98
|
if (current instanceof BlocksStack || current instanceof BlocksBackend) {
|
|
80
|
-
return current
|
|
99
|
+
return current;
|
|
81
100
|
}
|
|
82
101
|
}
|
|
83
|
-
// Fallback to
|
|
84
|
-
|
|
102
|
+
// Fallback to the ambient stack. In production this is always a real
|
|
103
|
+
// BlocksStack/BlocksBackend; the cast also admits the test doubles that set
|
|
104
|
+
// globalThis.CURRENT_BLOCKS_STACK to a stub exposing the same surface.
|
|
105
|
+
return globalThis.CURRENT_BLOCKS_STACK;
|
|
106
|
+
}
|
|
107
|
+
get handler() {
|
|
108
|
+
return this.root.handler;
|
|
85
109
|
}
|
|
86
110
|
/**
|
|
87
111
|
* The shared IAM role assumed by all Blocks compute. Building Blocks grant
|
|
88
|
-
* their permissions to this role
|
|
89
|
-
*
|
|
90
|
-
* to the role's default (inline) policy — exactly where they landed on the
|
|
91
|
-
* auto-generated role before.
|
|
92
|
-
*
|
|
93
|
-
* Resolves the same way as {@link handler}: walk up to the owning
|
|
94
|
-
* BlocksStack/BlocksBackend, falling back to the ambient stack.
|
|
112
|
+
* their permissions to this role; CDK's `grant*()` / `addToPrincipalPolicy()`
|
|
113
|
+
* route those grants to the role's default (inline) policy.
|
|
95
114
|
*/
|
|
96
115
|
get executionRole() {
|
|
116
|
+
return this.root.executionRole;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* The backend entry file the owning BlocksStack/BlocksBackend runs — the
|
|
120
|
+
* single handler entry shared across the whole app.
|
|
121
|
+
*/
|
|
122
|
+
get backendHandlerPath() {
|
|
123
|
+
return this.root.backendHandlerPath;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* The owning stack/backend's token-free root identity. This is the value the
|
|
127
|
+
* runtime receives as `BLOCKS_STACK_NAME` and rebuilds `fullId` from, so
|
|
128
|
+
* physical resource names (DynamoDB tables, env-var keys, IAM ARNs) derived
|
|
129
|
+
* from `fullId` match byte-for-byte between synth and runtime — otherwise the
|
|
130
|
+
* runtime looks up names that were never created. `BlocksBackend` exposes this
|
|
131
|
+
* as `fullId` ({@link BlocksBackend.fullId}); `BlocksStack` as `id`.
|
|
132
|
+
*/
|
|
133
|
+
get backendStackName() {
|
|
134
|
+
const name = this.root instanceof BlocksBackend ? this.root.fullId : this.root.id;
|
|
135
|
+
if (!name) {
|
|
136
|
+
throw new Error('Owning Blocks stack/backend has no id to derive BLOCKS_STACK_NAME');
|
|
137
|
+
}
|
|
138
|
+
return name;
|
|
139
|
+
}
|
|
140
|
+
get fullId() {
|
|
141
|
+
return computeScopeFullId(this);
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* The stack-wide infrastructure {@link BlocksDefaults} registered by
|
|
145
|
+
* `BlocksStack.create` / `BlocksBackend.create`. Read these in a Building
|
|
146
|
+
* Block's CDK constructor to resolve a durability value, letting a per-block
|
|
147
|
+
* option override:
|
|
148
|
+
*
|
|
149
|
+
* ```ts
|
|
150
|
+
* const removalPolicy = options?.removalPolicy ?? this.defaults.removalPolicy;
|
|
151
|
+
* ```
|
|
152
|
+
*/
|
|
153
|
+
get defaults() {
|
|
154
|
+
// Resolve the same way as handler/executionRole: walk up to the owning
|
|
155
|
+
// BlocksStack/BlocksBackend and read its defaults, so several backends in
|
|
156
|
+
// one stack each keep their own posture. Falls back to the ambient stack,
|
|
157
|
+
// then to the production preset when none was registered.
|
|
97
158
|
let current = this;
|
|
98
159
|
while (current.node.scope) {
|
|
99
160
|
current = current.node.scope;
|
|
100
161
|
if (current instanceof BlocksStack || current instanceof BlocksBackend) {
|
|
101
|
-
return current.
|
|
162
|
+
return current.defaults;
|
|
102
163
|
}
|
|
103
164
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
165
|
+
const ambient = globalThis.CURRENT_BLOCKS_STACK?.defaults;
|
|
166
|
+
if (ambient)
|
|
167
|
+
return ambient;
|
|
168
|
+
// No owning BlocksStack/BlocksBackend in the tree and none ambient — this is
|
|
169
|
+
// usually a deliberate test stub, but could be a real misconfiguration (a
|
|
170
|
+
// block built outside any Blocks backend). Fall back to the safe production
|
|
171
|
+
// posture, and log so it's debuggable if it fires unexpectedly.
|
|
172
|
+
console.warn(`[Blocks] Scope "${this.id}" resolved infrastructure defaults with no owning ` +
|
|
173
|
+
'BlocksStack/BlocksBackend in scope; falling back to BlocksPresets.production.');
|
|
174
|
+
return BlocksPresets.production;
|
|
109
175
|
}
|
|
110
176
|
buildUserAgentChain() {
|
|
111
177
|
return [];
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal CDK entry point — framework- and test-only surface that is
|
|
3
|
+
* intentionally NOT part of the public API (`@aws-blocks/core` /
|
|
4
|
+
* `@aws-blocks/core/cdk`).
|
|
5
|
+
*
|
|
6
|
+
* The compute abstraction lives behind this path while it has no public,
|
|
7
|
+
* customer-facing surface. Importing from here is a signal that you are inside
|
|
8
|
+
* the framework or a test, not a customer.
|
|
9
|
+
*
|
|
10
|
+
* Planned removal: once a customer can assign a compute and have it actually
|
|
11
|
+
* take effect — i.e. `this.compute` resolution and request routing to the
|
|
12
|
+
* chosen compute both exist, plus a synth-time guard that rejects an assignment
|
|
13
|
+
* with no route — these exports move to the public CDK entry point
|
|
14
|
+
* (`@aws-blocks/core/cdk`, re-exported from `index.cdk.ts`) and this file is
|
|
15
|
+
* deleted. It must NOT be made public before then: a compute a customer can
|
|
16
|
+
* declare but that is silently ignored is a worse experience than not having
|
|
17
|
+
* the feature. Until that flip, treat everything here as unstable — no
|
|
18
|
+
* backward-compatibility guarantee.
|
|
19
|
+
*
|
|
20
|
+
* @internal
|
|
21
|
+
*/
|
|
22
|
+
export { Compute } from './compute/compute.js';
|
|
23
|
+
export { BLOCKS_NAMESPACE } from '../constants.js';
|
|
24
|
+
//# sourceMappingURL=internal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../../src/cdk/internal.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAG/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
/**
|
|
4
|
+
* Internal CDK entry point — framework- and test-only surface that is
|
|
5
|
+
* intentionally NOT part of the public API (`@aws-blocks/core` /
|
|
6
|
+
* `@aws-blocks/core/cdk`).
|
|
7
|
+
*
|
|
8
|
+
* The compute abstraction lives behind this path while it has no public,
|
|
9
|
+
* customer-facing surface. Importing from here is a signal that you are inside
|
|
10
|
+
* the framework or a test, not a customer.
|
|
11
|
+
*
|
|
12
|
+
* Planned removal: once a customer can assign a compute and have it actually
|
|
13
|
+
* take effect — i.e. `this.compute` resolution and request routing to the
|
|
14
|
+
* chosen compute both exist, plus a synth-time guard that rejects an assignment
|
|
15
|
+
* with no route — these exports move to the public CDK entry point
|
|
16
|
+
* (`@aws-blocks/core/cdk`, re-exported from `index.cdk.ts`) and this file is
|
|
17
|
+
* deleted. It must NOT be made public before then: a compute a customer can
|
|
18
|
+
* declare but that is silently ignored is a worse experience than not having
|
|
19
|
+
* the feature. Until that flip, treat everything here as unstable — no
|
|
20
|
+
* backward-compatibility guarantee.
|
|
21
|
+
*
|
|
22
|
+
* @internal
|
|
23
|
+
*/
|
|
24
|
+
export { Compute } from './compute/compute.js';
|
|
25
|
+
// Reserved `/aws-blocks` path segment, needed by concrete computes (e.g.
|
|
26
|
+
// LambdaCompute in @aws-blocks/bb-lambda-compute) to build their API route tree.
|
|
27
|
+
export { BLOCKS_NAMESPACE } from '../constants.js';
|
package/dist/cdk/mixins.d.ts
CHANGED
|
@@ -2,13 +2,27 @@ import { Mixin } from 'aws-cdk-lib';
|
|
|
2
2
|
import type { IConstruct } from 'constructs';
|
|
3
3
|
import type { IMixin } from 'constructs';
|
|
4
4
|
/**
|
|
5
|
-
* Disables deletion protection on any construct that
|
|
6
|
-
* property (e.g. RDS clusters, RDS instances).
|
|
7
|
-
* automatically covers current and future resource
|
|
5
|
+
* Disables deletion protection on any construct that exposes a deletion
|
|
6
|
+
* protection property (e.g. RDS clusters, RDS instances, DynamoDB tables).
|
|
7
|
+
* Uses duck-typing so it automatically covers current and future resource
|
|
8
|
+
* types, matching both the `deletionProtection` and
|
|
9
|
+
* `deletionProtectionEnabled` spellings.
|
|
10
|
+
*
|
|
11
|
+
* Note that a DynamoDB L2 `Table` only accepts `deletionProtection` as a prop
|
|
12
|
+
* and does not re-expose it, so tables are matched through their underlying
|
|
13
|
+
* L1 `CfnTable.deletionProtectionEnabled`.
|
|
8
14
|
*
|
|
9
15
|
* Intended for sandbox teardown — use in the CDK layer alongside
|
|
10
16
|
* `RemovalPolicies.of(stack).destroy()` to ensure `sandbox:destroy` can
|
|
11
|
-
* delete the entire stack without manual cleanup.
|
|
17
|
+
* delete the entire stack without manual cleanup. DynamoDB refuses
|
|
18
|
+
* `DeleteTable` while deletion protection is enabled, regardless of the
|
|
19
|
+
* CloudFormation `DeletionPolicy`.
|
|
20
|
+
*
|
|
21
|
+
* @deprecated Prefer the stack-wide `defaults` prop on `BlocksStack`/`BlocksBackend`
|
|
22
|
+
* (`defaults: BlocksPresets.sandbox` / `.production`, or `sandboxMode ? … : …`).
|
|
23
|
+
* Amazon-authored Building Blocks now read removal policy + deletion protection
|
|
24
|
+
* from `defaults`, so this mixin is no longer needed; it is retained only for
|
|
25
|
+
* backward compatibility.
|
|
12
26
|
*
|
|
13
27
|
* @example
|
|
14
28
|
* ```ts
|
package/dist/cdk/mixins.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mixins.d.ts","sourceRoot":"","sources":["../../src/cdk/mixins.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"mixins.d.ts","sourceRoot":"","sources":["../../src/cdk/mixins.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAWzC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,qBAAa,gCAAiC,SAAQ,KAAM,YAAW,MAAM;IAC3E,QAAQ,CAAC,SAAS,EAAE,GAAG,GAAG,OAAO;IAGjC,OAAO,CAAC,IAAI,EAAE,UAAU,GAAG,IAAI;CAWhC"}
|
package/dist/cdk/mixins.js
CHANGED
|
@@ -2,13 +2,35 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
import { Mixin } from 'aws-cdk-lib';
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* Property names used across CloudFormation resources to express deletion
|
|
6
|
+
* protection. L2 constructs and most L1s use `deletionProtection` (e.g. RDS
|
|
7
|
+
* clusters and instances, ELBv2 load balancers), while others spell it
|
|
8
|
+
* `deletionProtectionEnabled` (e.g. the DynamoDB `CfnTable` behind an L2
|
|
9
|
+
* `Table`, Aurora DSQL clusters).
|
|
10
|
+
*/
|
|
11
|
+
const DELETION_PROTECTION_PROPERTIES = ['deletionProtection', 'deletionProtectionEnabled'];
|
|
12
|
+
/**
|
|
13
|
+
* Disables deletion protection on any construct that exposes a deletion
|
|
14
|
+
* protection property (e.g. RDS clusters, RDS instances, DynamoDB tables).
|
|
15
|
+
* Uses duck-typing so it automatically covers current and future resource
|
|
16
|
+
* types, matching both the `deletionProtection` and
|
|
17
|
+
* `deletionProtectionEnabled` spellings.
|
|
18
|
+
*
|
|
19
|
+
* Note that a DynamoDB L2 `Table` only accepts `deletionProtection` as a prop
|
|
20
|
+
* and does not re-expose it, so tables are matched through their underlying
|
|
21
|
+
* L1 `CfnTable.deletionProtectionEnabled`.
|
|
8
22
|
*
|
|
9
23
|
* Intended for sandbox teardown — use in the CDK layer alongside
|
|
10
24
|
* `RemovalPolicies.of(stack).destroy()` to ensure `sandbox:destroy` can
|
|
11
|
-
* delete the entire stack without manual cleanup.
|
|
25
|
+
* delete the entire stack without manual cleanup. DynamoDB refuses
|
|
26
|
+
* `DeleteTable` while deletion protection is enabled, regardless of the
|
|
27
|
+
* CloudFormation `DeletionPolicy`.
|
|
28
|
+
*
|
|
29
|
+
* @deprecated Prefer the stack-wide `defaults` prop on `BlocksStack`/`BlocksBackend`
|
|
30
|
+
* (`defaults: BlocksPresets.sandbox` / `.production`, or `sandboxMode ? … : …`).
|
|
31
|
+
* Amazon-authored Building Blocks now read removal policy + deletion protection
|
|
32
|
+
* from `defaults`, so this mixin is no longer needed; it is retained only for
|
|
33
|
+
* backward compatibility.
|
|
12
34
|
*
|
|
13
35
|
* @example
|
|
14
36
|
* ```ts
|
|
@@ -23,15 +45,17 @@ import { Mixin } from 'aws-cdk-lib';
|
|
|
23
45
|
*/
|
|
24
46
|
export class SandboxDisableDeletionProtection extends Mixin {
|
|
25
47
|
supports(construct) {
|
|
26
|
-
return
|
|
48
|
+
return DELETION_PROTECTION_PROPERTIES.some((property) => property in construct);
|
|
27
49
|
}
|
|
28
50
|
applyTo(node) {
|
|
29
51
|
// Only flip explicitly-enabled protection. When undefined (the default),
|
|
30
52
|
// deletion protection is already off — setting it to false would emit the
|
|
31
53
|
// property in the CloudFormation template, which breaks Aurora DB instances
|
|
32
54
|
// (RDS rejects DeletionProtection on cluster members).
|
|
33
|
-
|
|
34
|
-
node
|
|
55
|
+
for (const property of DELETION_PROTECTION_PROPERTIES) {
|
|
56
|
+
if (node[property] === true) {
|
|
57
|
+
node[property] = false;
|
|
58
|
+
}
|
|
35
59
|
}
|
|
36
60
|
}
|
|
37
61
|
}
|
package/dist/cdk/mixins.test.js
CHANGED
|
@@ -92,6 +92,51 @@ describe('sandbox removal policy', () => {
|
|
|
92
92
|
DeletionProtection: Match.absent(),
|
|
93
93
|
});
|
|
94
94
|
});
|
|
95
|
+
test('SandboxDisableDeletionProtection mixin: deletionProtection disabled on DynamoDB table', () => {
|
|
96
|
+
const app = new cdk.App({ context: { sandboxMode: 'true' } });
|
|
97
|
+
const stack = new cdk.Stack(app, 'TestStack');
|
|
98
|
+
new Table(stack, 'MyTable', {
|
|
99
|
+
partitionKey: { name: 'pk', type: AttributeType.STRING },
|
|
100
|
+
billingMode: BillingMode.PAY_PER_REQUEST,
|
|
101
|
+
deletionProtection: true,
|
|
102
|
+
});
|
|
103
|
+
RemovalPolicies.of(stack).destroy();
|
|
104
|
+
Mixins.of(stack).apply(new SandboxDisableDeletionProtection());
|
|
105
|
+
const template = Template.fromStack(stack);
|
|
106
|
+
// DynamoDB refuses DeleteTable while protection is on, regardless of DeletionPolicy
|
|
107
|
+
template.hasResourceProperties('AWS::DynamoDB::Table', {
|
|
108
|
+
DeletionProtectionEnabled: false,
|
|
109
|
+
});
|
|
110
|
+
template.hasResource('AWS::DynamoDB::Table', {
|
|
111
|
+
DeletionPolicy: 'Delete',
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
test('production mode: deletionProtection stays enabled on DynamoDB table when mixin is not applied', () => {
|
|
115
|
+
const app = new cdk.App();
|
|
116
|
+
const stack = new cdk.Stack(app, 'TestStack');
|
|
117
|
+
new Table(stack, 'MyTable', {
|
|
118
|
+
partitionKey: { name: 'pk', type: AttributeType.STRING },
|
|
119
|
+
billingMode: BillingMode.PAY_PER_REQUEST,
|
|
120
|
+
deletionProtection: true,
|
|
121
|
+
});
|
|
122
|
+
const template = Template.fromStack(stack);
|
|
123
|
+
template.hasResourceProperties('AWS::DynamoDB::Table', {
|
|
124
|
+
DeletionProtectionEnabled: true,
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
test('SandboxDisableDeletionProtection mixin: does not set DeletionProtectionEnabled on unprotected tables', () => {
|
|
128
|
+
const app = new cdk.App({ context: { sandboxMode: 'true' } });
|
|
129
|
+
const stack = new cdk.Stack(app, 'TestStack');
|
|
130
|
+
new Table(stack, 'MyTable', {
|
|
131
|
+
partitionKey: { name: 'pk', type: AttributeType.STRING },
|
|
132
|
+
billingMode: BillingMode.PAY_PER_REQUEST,
|
|
133
|
+
});
|
|
134
|
+
Mixins.of(stack).apply(new SandboxDisableDeletionProtection());
|
|
135
|
+
const template = Template.fromStack(stack);
|
|
136
|
+
template.hasResourceProperties('AWS::DynamoDB::Table', {
|
|
137
|
+
DeletionProtectionEnabled: Match.absent(),
|
|
138
|
+
});
|
|
139
|
+
});
|
|
95
140
|
test('SandboxDisableDeletionProtection mixin: skips constructs without deletionProtection', () => {
|
|
96
141
|
const app = new cdk.App();
|
|
97
142
|
const stack = new cdk.Stack(app, 'TestStack');
|
package/dist/common/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { StackProps } from 'aws-cdk-lib';
|
|
2
2
|
import type { Construct } from 'constructs';
|
|
3
|
+
import type { BlocksDefaults } from '../cdk/blocks-defaults.js';
|
|
3
4
|
export { OFFICIAL_BB_NAMES } from './official-bb-names.generated.js';
|
|
4
5
|
export interface ScopeOptions {
|
|
5
6
|
parent?: ScopeParent;
|
|
@@ -212,6 +213,14 @@ export declare function computeScopeFullId(scope: {
|
|
|
212
213
|
export interface BlocksStackProps extends StackProps {
|
|
213
214
|
backendHandlerPath: string;
|
|
214
215
|
backendCDKPath: string;
|
|
216
|
+
/**
|
|
217
|
+
* Stack-wide infrastructure defaults applied to every Building Block (removal
|
|
218
|
+
* policy, deletion protection, …). Start from `BlocksPresets.sandbox` or
|
|
219
|
+
* `BlocksPresets.production` and override individual fields as needed. Any
|
|
220
|
+
* field a block also exposes as a per-block option is overridden by that
|
|
221
|
+
* option. See `BlocksDefaults` in `@aws-blocks/core/cdk`.
|
|
222
|
+
*/
|
|
223
|
+
defaults: BlocksDefaults;
|
|
215
224
|
}
|
|
216
225
|
export declare class BlocksStack {
|
|
217
226
|
readonly id: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/common/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/common/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAGhE,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAErE,MAAM,WAAW,YAAY;IAC3B,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,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