@aws-blocks/core 0.1.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/LICENSE +174 -0
- package/dist/api.d.ts +147 -0
- package/dist/api.d.ts.map +1 -0
- package/dist/api.js +10 -0
- package/dist/api.test.d.ts +2 -0
- package/dist/api.test.d.ts.map +1 -0
- package/dist/api.test.js +19 -0
- package/dist/bb-utils.d.ts +11 -0
- package/dist/bb-utils.d.ts.map +1 -0
- package/dist/bb-utils.js +12 -0
- package/dist/builtin-routes.d.ts +6 -0
- package/dist/builtin-routes.d.ts.map +1 -0
- package/dist/builtin-routes.js +57 -0
- package/dist/cdk/__fixtures__/factory-backend.d.ts +3 -0
- package/dist/cdk/__fixtures__/factory-backend.d.ts.map +1 -0
- package/dist/cdk/__fixtures__/factory-backend.js +6 -0
- package/dist/cdk/__fixtures__/fullid-construct-backend.d.ts +2 -0
- package/dist/cdk/__fixtures__/fullid-construct-backend.d.ts.map +1 -0
- package/dist/cdk/__fixtures__/fullid-construct-backend.js +37 -0
- package/dist/cdk/__fixtures__/handler.d.ts +5 -0
- package/dist/cdk/__fixtures__/handler.d.ts.map +1 -0
- package/dist/cdk/__fixtures__/handler.js +3 -0
- package/dist/cdk/__fixtures__/side-effect-backend.d.ts +2 -0
- package/dist/cdk/__fixtures__/side-effect-backend.d.ts.map +1 -0
- package/dist/cdk/__fixtures__/side-effect-backend.js +5 -0
- package/dist/cdk/blocks-backend.d.ts +68 -0
- package/dist/cdk/blocks-backend.d.ts.map +1 -0
- package/dist/cdk/blocks-backend.js +214 -0
- package/dist/cdk/blocks-backend.test.d.ts +2 -0
- package/dist/cdk/blocks-backend.test.d.ts.map +1 -0
- package/dist/cdk/blocks-backend.test.js +151 -0
- package/dist/cdk/blocks-stack.test.d.ts +2 -0
- package/dist/cdk/blocks-stack.test.d.ts.map +1 -0
- package/dist/cdk/blocks-stack.test.js +78 -0
- package/dist/cdk/config-registry.d.ts +26 -0
- package/dist/cdk/config-registry.d.ts.map +1 -0
- package/dist/cdk/config-registry.js +80 -0
- package/dist/cdk/index.d.ts +35 -0
- package/dist/cdk/index.d.ts.map +1 -0
- package/dist/cdk/index.js +90 -0
- package/dist/cdk/mixins.d.ts +28 -0
- package/dist/cdk/mixins.d.ts.map +1 -0
- package/dist/cdk/mixins.js +37 -0
- package/dist/cdk/mixins.test.d.ts +2 -0
- package/dist/cdk/mixins.test.d.ts.map +1 -0
- package/dist/cdk/mixins.test.js +108 -0
- package/dist/cdk/node-version.d.ts +14 -0
- package/dist/cdk/node-version.d.ts.map +1 -0
- package/dist/cdk/node-version.js +15 -0
- package/dist/cdk/stack-metadata.d.ts +12 -0
- package/dist/cdk/stack-metadata.d.ts.map +1 -0
- package/dist/cdk/stack-metadata.js +22 -0
- package/dist/cdk/stack-metadata.test.d.ts +2 -0
- package/dist/cdk/stack-metadata.test.d.ts.map +1 -0
- package/dist/cdk/stack-metadata.test.js +56 -0
- package/dist/cdk/synth-guard.d.ts +14 -0
- package/dist/cdk/synth-guard.d.ts.map +1 -0
- package/dist/cdk/synth-guard.js +20 -0
- package/dist/cdk/synth-guard.test.d.ts +2 -0
- package/dist/cdk/synth-guard.test.d.ts.map +1 -0
- package/dist/cdk/synth-guard.test.js +15 -0
- package/dist/client/index.d.ts +97 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +238 -0
- package/dist/client/index.test.d.ts +2 -0
- package/dist/client/index.test.d.ts.map +1 -0
- package/dist/client/index.test.js +113 -0
- package/dist/common/config.d.ts +45 -0
- package/dist/common/config.d.ts.map +1 -0
- package/dist/common/config.js +154 -0
- package/dist/common/config.test.d.ts +2 -0
- package/dist/common/config.test.d.ts.map +1 -0
- package/dist/common/config.test.js +173 -0
- package/dist/common/constants.d.ts +11 -0
- package/dist/common/constants.d.ts.map +1 -0
- package/dist/common/constants.js +12 -0
- package/dist/common/crypto.d.ts +6 -0
- package/dist/common/crypto.d.ts.map +1 -0
- package/dist/common/crypto.js +14 -0
- package/dist/common/index.d.ts +220 -0
- package/dist/common/index.d.ts.map +1 -0
- package/dist/common/index.js +180 -0
- package/dist/common/index.test.d.ts +2 -0
- package/dist/common/index.test.d.ts.map +1 -0
- package/dist/common/index.test.js +195 -0
- package/dist/common/mock-data.d.ts +40 -0
- package/dist/common/mock-data.d.ts.map +1 -0
- package/dist/common/mock-data.js +39 -0
- package/dist/common/official-bb-names.generated.d.ts +7 -0
- package/dist/common/official-bb-names.generated.d.ts.map +1 -0
- package/dist/common/official-bb-names.generated.js +28 -0
- package/dist/common/sdk-registry.d.ts +136 -0
- package/dist/common/sdk-registry.d.ts.map +1 -0
- package/dist/common/sdk-registry.js +125 -0
- package/dist/constants.d.ts +27 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +28 -0
- package/dist/cors.d.ts +39 -0
- package/dist/cors.d.ts.map +1 -0
- package/dist/cors.js +85 -0
- package/dist/cors.test.d.ts +2 -0
- package/dist/cors.test.d.ts.map +1 -0
- package/dist/cors.test.js +241 -0
- package/dist/db-naming.d.ts +21 -0
- package/dist/db-naming.d.ts.map +1 -0
- package/dist/db-naming.js +38 -0
- package/dist/db-naming.test.d.ts +2 -0
- package/dist/db-naming.test.d.ts.map +1 -0
- package/dist/db-naming.test.js +29 -0
- package/dist/errors.d.ts +67 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +69 -0
- package/dist/hosting.d.ts +258 -0
- package/dist/hosting.d.ts.map +1 -0
- package/dist/hosting.js +340 -0
- package/dist/hosting.test.d.ts +2 -0
- package/dist/hosting.test.d.ts.map +1 -0
- package/dist/hosting.test.js +1077 -0
- package/dist/index.cdk.d.ts +13 -0
- package/dist/index.cdk.d.ts.map +1 -0
- package/dist/index.cdk.js +13 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -0
- package/dist/lambda-handler.d.ts +131 -0
- package/dist/lambda-handler.d.ts.map +1 -0
- package/dist/lambda-handler.js +610 -0
- package/dist/lambda-handler.test.d.ts +2 -0
- package/dist/lambda-handler.test.d.ts.map +1 -0
- package/dist/lambda-handler.test.js +835 -0
- package/dist/pipeline/index.d.ts +4 -0
- package/dist/pipeline/index.d.ts.map +1 -0
- package/dist/pipeline/index.js +3 -0
- package/dist/pipeline/pipeline-construct.d.ts +130 -0
- package/dist/pipeline/pipeline-construct.d.ts.map +1 -0
- package/dist/pipeline/pipeline-construct.js +484 -0
- package/dist/pipeline/pipeline.test.d.ts +2 -0
- package/dist/pipeline/pipeline.test.d.ts.map +1 -0
- package/dist/pipeline/pipeline.test.js +1231 -0
- package/dist/pipeline/types.d.ts +351 -0
- package/dist/pipeline/types.d.ts.map +1 -0
- package/dist/pipeline/types.js +3 -0
- package/dist/raw-route.cdk.d.ts +47 -0
- package/dist/raw-route.cdk.d.ts.map +1 -0
- package/dist/raw-route.cdk.js +51 -0
- package/dist/raw-route.d.ts +119 -0
- package/dist/raw-route.d.ts.map +1 -0
- package/dist/raw-route.js +239 -0
- package/dist/raw-route.mock.d.ts +47 -0
- package/dist/raw-route.mock.d.ts.map +1 -0
- package/dist/raw-route.mock.js +51 -0
- package/dist/raw-route.test.d.ts +2 -0
- package/dist/raw-route.test.d.ts.map +1 -0
- package/dist/raw-route.test.js +597 -0
- package/dist/redact.d.ts +51 -0
- package/dist/redact.d.ts.map +1 -0
- package/dist/redact.js +134 -0
- package/dist/redact.test.d.ts +2 -0
- package/dist/redact.test.d.ts.map +1 -0
- package/dist/redact.test.js +199 -0
- package/dist/rpc.d.ts +54 -0
- package/dist/rpc.d.ts.map +1 -0
- package/dist/rpc.js +127 -0
- package/dist/rpc.test.d.ts +2 -0
- package/dist/rpc.test.d.ts.map +1 -0
- package/dist/rpc.test.js +60 -0
- package/dist/scripts/cdk-telemetry-env.d.ts +13 -0
- package/dist/scripts/cdk-telemetry-env.d.ts.map +1 -0
- package/dist/scripts/cdk-telemetry-env.js +21 -0
- package/dist/scripts/cdk-telemetry-env.test.d.ts +2 -0
- package/dist/scripts/cdk-telemetry-env.test.d.ts.map +1 -0
- package/dist/scripts/cdk-telemetry-env.test.js +56 -0
- package/dist/scripts/cleanup.d.ts +3 -0
- package/dist/scripts/cleanup.d.ts.map +1 -0
- package/dist/scripts/cleanup.js +35 -0
- package/dist/scripts/console.d.ts +6 -0
- package/dist/scripts/console.d.ts.map +1 -0
- package/dist/scripts/console.js +25 -0
- package/dist/scripts/deploy.d.ts +6 -0
- package/dist/scripts/deploy.d.ts.map +1 -0
- package/dist/scripts/deploy.js +82 -0
- package/dist/scripts/destroy.d.ts +6 -0
- package/dist/scripts/destroy.d.ts.map +1 -0
- package/dist/scripts/destroy.js +30 -0
- package/dist/scripts/dev-server-cors.test.d.ts +2 -0
- package/dist/scripts/dev-server-cors.test.d.ts.map +1 -0
- package/dist/scripts/dev-server-cors.test.js +23 -0
- package/dist/scripts/dev-server-telemetry.test.d.ts +2 -0
- package/dist/scripts/dev-server-telemetry.test.d.ts.map +1 -0
- package/dist/scripts/dev-server-telemetry.test.js +113 -0
- package/dist/scripts/dev-server.d.ts +21 -0
- package/dist/scripts/dev-server.d.ts.map +1 -0
- package/dist/scripts/dev-server.js +456 -0
- package/dist/scripts/ensure-secrets.d.ts +31 -0
- package/dist/scripts/ensure-secrets.d.ts.map +1 -0
- package/dist/scripts/ensure-secrets.js +100 -0
- package/dist/scripts/ensure-secrets.test.d.ts +2 -0
- package/dist/scripts/ensure-secrets.test.d.ts.map +1 -0
- package/dist/scripts/ensure-secrets.test.js +44 -0
- package/dist/scripts/external-migrations-step.d.ts +62 -0
- package/dist/scripts/external-migrations-step.d.ts.map +1 -0
- package/dist/scripts/external-migrations-step.js +243 -0
- package/dist/scripts/external-migrations-step.test.d.ts +2 -0
- package/dist/scripts/external-migrations-step.test.d.ts.map +1 -0
- package/dist/scripts/external-migrations-step.test.js +47 -0
- package/dist/scripts/extract-ts-types.d.ts +65 -0
- package/dist/scripts/extract-ts-types.d.ts.map +1 -0
- package/dist/scripts/extract-ts-types.js +664 -0
- package/dist/scripts/extract-ts-types.test.d.ts +2 -0
- package/dist/scripts/extract-ts-types.test.d.ts.map +1 -0
- package/dist/scripts/extract-ts-types.test.js +497 -0
- package/dist/scripts/generate-client-worker.d.ts +2 -0
- package/dist/scripts/generate-client-worker.d.ts.map +1 -0
- package/dist/scripts/generate-client-worker.js +13 -0
- package/dist/scripts/generate-client.d.ts +14 -0
- package/dist/scripts/generate-client.d.ts.map +1 -0
- package/dist/scripts/generate-client.js +73 -0
- package/dist/scripts/generate-client.test.d.ts +2 -0
- package/dist/scripts/generate-client.test.d.ts.map +1 -0
- package/dist/scripts/generate-client.test.js +48 -0
- package/dist/scripts/generate-spec-cli.d.ts +3 -0
- package/dist/scripts/generate-spec-cli.d.ts.map +1 -0
- package/dist/scripts/generate-spec-cli.js +77 -0
- package/dist/scripts/generate-spec-cli.test.d.ts +14 -0
- package/dist/scripts/generate-spec-cli.test.d.ts.map +1 -0
- package/dist/scripts/generate-spec-cli.test.js +90 -0
- package/dist/scripts/generate-spec.d.ts +61 -0
- package/dist/scripts/generate-spec.d.ts.map +1 -0
- package/dist/scripts/generate-spec.js +746 -0
- package/dist/scripts/generate-spec.test.d.ts +12 -0
- package/dist/scripts/generate-spec.test.d.ts.map +1 -0
- package/dist/scripts/generate-spec.test.js +88 -0
- package/dist/scripts/index.d.ts +12 -0
- package/dist/scripts/index.d.ts.map +1 -0
- package/dist/scripts/index.js +13 -0
- package/dist/scripts/sandbox.d.ts +11 -0
- package/dist/scripts/sandbox.d.ts.map +1 -0
- package/dist/scripts/sandbox.js +200 -0
- package/dist/scripts/telemetry-cli.d.ts +3 -0
- package/dist/scripts/telemetry-cli.d.ts.map +1 -0
- package/dist/scripts/telemetry-cli.js +8 -0
- package/dist/scripts/telemetry.d.ts +17 -0
- package/dist/scripts/telemetry.d.ts.map +1 -0
- package/dist/scripts/telemetry.js +150 -0
- package/dist/scripts/telemetry.test.d.ts +2 -0
- package/dist/scripts/telemetry.test.d.ts.map +1 -0
- package/dist/scripts/telemetry.test.js +203 -0
- package/dist/scripts/validate-spec.d.ts +22 -0
- package/dist/scripts/validate-spec.d.ts.map +1 -0
- package/dist/scripts/validate-spec.js +159 -0
- package/dist/server/index.d.ts +3 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +3 -0
- package/dist/server/withAuth.d.ts +142 -0
- package/dist/server/withAuth.d.ts.map +1 -0
- package/dist/server/withAuth.js +261 -0
- package/dist/server/withAuth.test.d.ts +2 -0
- package/dist/server/withAuth.test.d.ts.map +1 -0
- package/dist/server/withAuth.test.js +278 -0
- package/dist/telemetry/client.d.ts +59 -0
- package/dist/telemetry/client.d.ts.map +1 -0
- package/dist/telemetry/client.js +215 -0
- package/dist/telemetry/config-writer.d.ts +16 -0
- package/dist/telemetry/config-writer.d.ts.map +1 -0
- package/dist/telemetry/config-writer.js +36 -0
- package/dist/telemetry/consent-commands.test.d.ts +2 -0
- package/dist/telemetry/consent-commands.test.d.ts.map +1 -0
- package/dist/telemetry/consent-commands.test.js +161 -0
- package/dist/telemetry/consent.d.ts +60 -0
- package/dist/telemetry/consent.d.ts.map +1 -0
- package/dist/telemetry/consent.js +122 -0
- package/dist/telemetry/environment.d.ts +33 -0
- package/dist/telemetry/environment.d.ts.map +1 -0
- package/dist/telemetry/environment.js +87 -0
- package/dist/telemetry/identifiers.d.ts +20 -0
- package/dist/telemetry/identifiers.d.ts.map +1 -0
- package/dist/telemetry/identifiers.js +86 -0
- package/dist/telemetry/index.d.ts +6 -0
- package/dist/telemetry/index.d.ts.map +1 -0
- package/dist/telemetry/index.js +4 -0
- package/dist/telemetry/telemetry.test.d.ts +2 -0
- package/dist/telemetry/telemetry.test.d.ts.map +1 -0
- package/dist/telemetry/telemetry.test.js +1131 -0
- package/dist/telemetry/trackCommand.d.ts +32 -0
- package/dist/telemetry/trackCommand.d.ts.map +1 -0
- package/dist/telemetry/trackCommand.js +102 -0
- package/dist/telemetry/types.d.ts +92 -0
- package/dist/telemetry/types.d.ts.map +1 -0
- package/dist/telemetry/types.js +1 -0
- package/dist/types.d.ts +24 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +2 -0
- package/package.json +83 -0
- package/src/api.test.ts +25 -0
- package/src/api.ts +163 -0
- package/src/bb-utils.ts +13 -0
- package/src/builtin-routes.ts +62 -0
- package/src/cdk/__fixtures__/factory-backend.ts +8 -0
- package/src/cdk/__fixtures__/fullid-construct-backend.ts +42 -0
- package/src/cdk/__fixtures__/handler.ts +4 -0
- package/src/cdk/__fixtures__/side-effect-backend.ts +7 -0
- package/src/cdk/blocks-backend.test.ts +207 -0
- package/src/cdk/blocks-backend.ts +249 -0
- package/src/cdk/blocks-stack.test.ts +106 -0
- package/src/cdk/config-registry.ts +106 -0
- package/src/cdk/index.ts +115 -0
- package/src/cdk/mixins.test.ts +129 -0
- package/src/cdk/mixins.ts +41 -0
- package/src/cdk/node-version.ts +17 -0
- package/src/cdk/stack-metadata.test.ts +71 -0
- package/src/cdk/stack-metadata.ts +29 -0
- package/src/cdk/synth-guard.test.ts +21 -0
- package/src/cdk/synth-guard.ts +23 -0
- package/src/client/index.test.ts +118 -0
- package/src/client/index.ts +320 -0
- package/src/common/config.test.ts +236 -0
- package/src/common/config.ts +169 -0
- package/src/common/constants.ts +15 -0
- package/src/common/crypto.ts +15 -0
- package/src/common/index.test.ts +242 -0
- package/src/common/index.ts +335 -0
- package/src/common/mock-data.ts +52 -0
- package/src/common/official-bb-names.generated.ts +29 -0
- package/src/common/sdk-registry.ts +150 -0
- package/src/constants.ts +31 -0
- package/src/cors.test.ts +279 -0
- package/src/cors.ts +91 -0
- package/src/db-naming.test.ts +48 -0
- package/src/db-naming.ts +41 -0
- package/src/errors.ts +72 -0
- package/src/hosting.test.ts +1431 -0
- package/src/hosting.ts +626 -0
- package/src/index.cdk.ts +45 -0
- package/src/index.ts +22 -0
- package/src/lambda-handler.test.ts +1005 -0
- package/src/lambda-handler.ts +706 -0
- package/src/pipeline/index.ts +12 -0
- package/src/pipeline/pipeline-construct.ts +662 -0
- package/src/pipeline/pipeline.test.ts +1565 -0
- package/src/pipeline/types.ts +384 -0
- package/src/raw-route.cdk.ts +56 -0
- package/src/raw-route.mock.ts +56 -0
- package/src/raw-route.test.ts +819 -0
- package/src/raw-route.ts +316 -0
- package/src/redact.test.ts +222 -0
- package/src/redact.ts +143 -0
- package/src/rpc.test.ts +73 -0
- package/src/rpc.ts +174 -0
- package/src/scripts/cdk-telemetry-env.test.ts +75 -0
- package/src/scripts/cdk-telemetry-env.ts +23 -0
- package/src/scripts/cleanup.ts +39 -0
- package/src/scripts/console.ts +34 -0
- package/src/scripts/deploy.ts +106 -0
- package/src/scripts/destroy.ts +42 -0
- package/src/scripts/dev-server-cors.test.ts +28 -0
- package/src/scripts/dev-server-telemetry.test.ts +127 -0
- package/src/scripts/dev-server.ts +515 -0
- package/src/scripts/ensure-secrets.test.ts +50 -0
- package/src/scripts/ensure-secrets.ts +113 -0
- package/src/scripts/external-migrations-step.test.ts +64 -0
- package/src/scripts/external-migrations-step.ts +269 -0
- package/src/scripts/extract-ts-types.test.ts +516 -0
- package/src/scripts/extract-ts-types.ts +773 -0
- package/src/scripts/generate-client-worker.ts +15 -0
- package/src/scripts/generate-client.test.ts +69 -0
- package/src/scripts/generate-client.ts +86 -0
- package/src/scripts/generate-spec-cli.test.ts +106 -0
- package/src/scripts/generate-spec-cli.ts +92 -0
- package/src/scripts/generate-spec.test.ts +99 -0
- package/src/scripts/generate-spec.ts +833 -0
- package/src/scripts/index.ts +21 -0
- package/src/scripts/sandbox.ts +230 -0
- package/src/scripts/telemetry-cli.ts +10 -0
- package/src/scripts/telemetry.test.ts +239 -0
- package/src/scripts/telemetry.ts +173 -0
- package/src/scripts/validate-spec.ts +199 -0
- package/src/server/index.ts +5 -0
- package/src/server/withAuth.test.ts +348 -0
- package/src/server/withAuth.ts +323 -0
- package/src/telemetry/client.ts +226 -0
- package/src/telemetry/config-writer.ts +52 -0
- package/src/telemetry/consent-commands.test.ts +196 -0
- package/src/telemetry/consent.ts +154 -0
- package/src/telemetry/environment.ts +100 -0
- package/src/telemetry/identifiers.ts +94 -0
- package/src/telemetry/index.ts +11 -0
- package/src/telemetry/telemetry.test.ts +1343 -0
- package/src/telemetry/trackCommand.ts +110 -0
- package/src/telemetry/types.ts +92 -0
- package/src/types.ts +33 -0
- package/src/version.ts +2 -0
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import type { StackProps } from 'aws-cdk-lib';
|
|
5
|
+
import type { Construct } from 'constructs';
|
|
6
|
+
import { CORE_VERSION } from '../version.js';
|
|
7
|
+
import { OFFICIAL_BB_NAMES } from './official-bb-names.generated.js';
|
|
8
|
+
export { OFFICIAL_BB_NAMES } from './official-bb-names.generated.js';
|
|
9
|
+
|
|
10
|
+
export interface ScopeOptions {
|
|
11
|
+
parent?: ScopeParent;
|
|
12
|
+
bbName?: string;
|
|
13
|
+
bbVersion?: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export type ScopeParent = Scope | { id: string };
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Scope defines a logical boundary for your backend resources.
|
|
20
|
+
*
|
|
21
|
+
* Building Blocks are instantiated within a scope. The scope provides namespacing and resource organization.
|
|
22
|
+
*
|
|
23
|
+
* ## Usage
|
|
24
|
+
*
|
|
25
|
+
* Create a scope at the top of your backend file:
|
|
26
|
+
*
|
|
27
|
+
* ```typescript
|
|
28
|
+
* import { Scope } from '@aws-blocks/core';
|
|
29
|
+
*
|
|
30
|
+
* const scope = new Scope('my-app');
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* Then instantiate Building Blocks within that scope:
|
|
34
|
+
*
|
|
35
|
+
* ```typescript
|
|
36
|
+
* import { KVStore } from '@aws-blocks/bb-kv-store';
|
|
37
|
+
*
|
|
38
|
+
* const store = new KVStore(scope, 'user-prefs', {});
|
|
39
|
+
* ```
|
|
40
|
+
*
|
|
41
|
+
* ## Available Building Blocks
|
|
42
|
+
*
|
|
43
|
+
* **IMPORTANT: Always use Blocks Building Blocks instead of creating your own storage, data structures, or AWS SDK calls.**
|
|
44
|
+
*
|
|
45
|
+
* Building Blocks provide:
|
|
46
|
+
* - **Local mocking** - Run in-process during development (`npm run dev`) with no AWS resources
|
|
47
|
+
* - **Production deployment** - Automatically provision and configure AWS resources (`npm run sandbox` or `npm run deploy`)
|
|
48
|
+
* - **Same code, both environments** - Your application logic works identically in local and production
|
|
49
|
+
*
|
|
50
|
+
* Each Building Block has comprehensive docstrings with use-cases, scaling characteristics, performance metrics, and best practices. Import and explore:
|
|
51
|
+
*
|
|
52
|
+
* - **`ApiNamespace`** from `@aws-blocks/core` - Define type-safe APIs with automatic frontend/backend integration
|
|
53
|
+
* - **`KVStore`** from `@aws-blocks/bb-kv-store` - Simple key-value storage (DynamoDB)
|
|
54
|
+
* - **`DistributedTable`** from `@aws-blocks/bb-distributed-table` - Type-safe tables with Zod schemas, indexes, and queries (DynamoDB)
|
|
55
|
+
* - **`AuthBasic`** from `@aws-blocks/bb-auth-basic` - Username/password authentication with JWT tokens and built-in UI components
|
|
56
|
+
* - **`Database`** from `@aws-blocks/bb-data` - SQL database with Kysely query builder (Aurora Serverless)
|
|
57
|
+
*
|
|
58
|
+
* Read each Building Block's class and method docstrings for detailed documentation.
|
|
59
|
+
*
|
|
60
|
+
* ## Choosing the Right Building Block
|
|
61
|
+
*
|
|
62
|
+
* **For authentication:**
|
|
63
|
+
* - Use `AuthBasic` for username/password auth (includes built-in UI component)
|
|
64
|
+
* - Provides JWT tokens, password hashing, and session management
|
|
65
|
+
*
|
|
66
|
+
* **For data storage, choose based on your access patterns:**
|
|
67
|
+
*
|
|
68
|
+
* - **`KVStore`** - Simple key-value lookups (user preferences, feature flags, session data)
|
|
69
|
+
* - Get/set by key only
|
|
70
|
+
* - No queries or indexes
|
|
71
|
+
* - Simplest option
|
|
72
|
+
*
|
|
73
|
+
* - **`DistributedTable`** - Structured data with queries and indexes
|
|
74
|
+
* - Query by partition key with optional filtering
|
|
75
|
+
* - Secondary indexes for alternate access patterns
|
|
76
|
+
* - Supports filtering, sorting, pagination
|
|
77
|
+
* - Use Zod schemas for type safety
|
|
78
|
+
* - **Zero cost to start, highly scalable**
|
|
79
|
+
* - **Default choice for most application data**
|
|
80
|
+
*
|
|
81
|
+
* - **`Database`** - SQL database with full relational features
|
|
82
|
+
* - Use when you need: complex multi-table JOINs, SQL transactions across tables, foreign key constraints
|
|
83
|
+
* - Avoid when: DynamoDB limitations are acceptable (no ad-hoc queries, eventual consistency on indexes, 400KB item limit)
|
|
84
|
+
* - Requires migrations folder with .sql files
|
|
85
|
+
* - Local dev requires manual schema setup (see Database README)
|
|
86
|
+
* - Higher baseline cost than DistributedTable
|
|
87
|
+
*
|
|
88
|
+
* **Rule of thumb:** Use DistributedTable unless you specifically need SQL JOINs or transactions.
|
|
89
|
+
*
|
|
90
|
+
* ## Data Modeling
|
|
91
|
+
*
|
|
92
|
+
* - **For DistributedTable**: Use Zod schemas for runtime validation and type inference. Install: `npm install zod`
|
|
93
|
+
* - For flexible key-value fields: `z.record(z.string(), z.any())`
|
|
94
|
+
* - **For Database**: Define TypeScript interfaces and create migrations folder with .sql files
|
|
95
|
+
* - **For KVStore**: Store strings only (serialize objects as JSON)
|
|
96
|
+
*
|
|
97
|
+
* ## Local Development
|
|
98
|
+
*
|
|
99
|
+
* In local dev mode (`npm run dev`), Building Blocks run in-process with mock implementations.
|
|
100
|
+
* No AWS resources are created. State is ephemeral.
|
|
101
|
+
*
|
|
102
|
+
* ## Deployed to AWS
|
|
103
|
+
*
|
|
104
|
+
* When deployed (`npm run sandbox` or `npm run deploy`), Blocks provisions real AWS resources:
|
|
105
|
+
* - Lambda functions for your APIs
|
|
106
|
+
* - DynamoDB tables for KVStore and DistributedTable
|
|
107
|
+
* - Aurora Serverless for Database
|
|
108
|
+
* - S3 buckets for file storage
|
|
109
|
+
* - IAM roles and policies
|
|
110
|
+
*
|
|
111
|
+
* Infrastructure is **inferred from your code**. You write application logic; Blocks determines
|
|
112
|
+
* what AWS resources are needed and provisions them automatically.
|
|
113
|
+
*
|
|
114
|
+
* ## Best Practices
|
|
115
|
+
*
|
|
116
|
+
* - Use one scope per application or major feature boundary
|
|
117
|
+
* - Give scopes descriptive IDs (e.g., 'user-service', 'orders')
|
|
118
|
+
* - Nest scopes for complex applications using the `parent` option
|
|
119
|
+
* - Always use Building Blocks for storage - never create your own in-memory Maps or custom storage
|
|
120
|
+
*/
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Metadata identifying a Building Block for user-agent attribution.
|
|
124
|
+
* BBs that want to participate in user-agent chains must set these on their class.
|
|
125
|
+
*/
|
|
126
|
+
export interface BuildingBlockMeta {
|
|
127
|
+
/** Short BB name used in user-agent strings, e.g. "KVStore", "AuthCognito" */
|
|
128
|
+
readonly bbName: string;
|
|
129
|
+
/** Package version from the BB's own package.json (build-time generated) */
|
|
130
|
+
readonly bbVersion: string;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export class Scope {
|
|
134
|
+
public readonly id: string;
|
|
135
|
+
public readonly parent: ScopeParent;
|
|
136
|
+
|
|
137
|
+
/** Short BB name used in user-agent strings. Set by subclass BBs. */
|
|
138
|
+
readonly bbName?: string;
|
|
139
|
+
/** Package version from the BB's own package.json. Set by subclass BBs. */
|
|
140
|
+
readonly bbVersion?: string;
|
|
141
|
+
|
|
142
|
+
/** Static registry — collects BB names as they're instantiated */
|
|
143
|
+
private static _bbRegistry: Map<string, { version: string; count: number }> = new Map();
|
|
144
|
+
|
|
145
|
+
constructor(id: string, options?: ScopeOptions) {
|
|
146
|
+
this.id = id;
|
|
147
|
+
this.parent = options?.parent || (globalThis as any).CURRENT_BLOCKS_STACK || {
|
|
148
|
+
id: typeof process !== 'undefined' ? process.env?.BLOCKS_STACK_NAME : undefined
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
if (options?.bbName) {
|
|
152
|
+
this.bbName = options.bbName;
|
|
153
|
+
this.bbVersion = options.bbVersion;
|
|
154
|
+
const existing = Scope._bbRegistry.get(options.bbName);
|
|
155
|
+
Scope._bbRegistry.set(options.bbName, {
|
|
156
|
+
version: options.bbVersion || 'unknown',
|
|
157
|
+
count: (existing?.count || 0) + 1,
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Get registered BBs filtered for telemetry privacy.
|
|
164
|
+
*
|
|
165
|
+
* Only official BB names (in OFFICIAL_BB_NAMES) are returned in `blocks`.
|
|
166
|
+
* Custom BBs are counted in `customBlocksCount` but their names are never exposed.
|
|
167
|
+
*
|
|
168
|
+
* @returns Official blocks, total instance count, and total number of custom BB instances.
|
|
169
|
+
* @internal
|
|
170
|
+
*/
|
|
171
|
+
static getRegisteredBlocks(): { blocks: Array<{ name: string; version: string }>; totalCount: number; customBlocksCount: number } {
|
|
172
|
+
const blocks: Array<{ name: string; version: string }> = [];
|
|
173
|
+
let totalCount = 0;
|
|
174
|
+
let customBlocksCount = 0;
|
|
175
|
+
for (const [name, { version, count }] of Scope._bbRegistry.entries()) {
|
|
176
|
+
totalCount += count;
|
|
177
|
+
if (OFFICIAL_BB_NAMES.has(name)) {
|
|
178
|
+
blocks.push({ name, version });
|
|
179
|
+
} else {
|
|
180
|
+
customBlocksCount += count;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
return { blocks, totalCount, customBlocksCount };
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/** Reset registry (useful for testing). */
|
|
187
|
+
static _resetRegistry(): void {
|
|
188
|
+
Scope._bbRegistry.clear();
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
get fullId(): string {
|
|
192
|
+
return computeScopeFullId(this);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Register a Lambda event handler for non-HTTP events (e.g., SQS, WebSocket).
|
|
197
|
+
* The handler receives the raw Lambda event record and processes it.
|
|
198
|
+
* Used by Building Blocks that consume event sources (e.g., AsyncJob → SQS,
|
|
199
|
+
* Realtime → API Gateway WebSocket).
|
|
200
|
+
*
|
|
201
|
+
* @param eventSource - Event source prefix (e.g., 'blocks.asyncjob', 'blocks.websocket').
|
|
202
|
+
* @param identifier - Building Block's fullId (scope-qualified ID, e.g., 'myapp-rt').
|
|
203
|
+
* Combined with eventSource to form the registry key '{eventSource}:{identifier}'.
|
|
204
|
+
* @param handler - Async function that processes the raw Lambda event.
|
|
205
|
+
*/
|
|
206
|
+
registerLambdaEventHandler(eventSource: string, identifier: string, handler: (record: any) => Promise<void>): void {
|
|
207
|
+
if (!(globalThis as any).__BLOCKS_LAMBDA_EVENT_HANDLERS__) {
|
|
208
|
+
(globalThis as any).__BLOCKS_LAMBDA_EVENT_HANDLERS__ = new Map<string, (record: any) => Promise<void>>();
|
|
209
|
+
}
|
|
210
|
+
(globalThis as any).__BLOCKS_LAMBDA_EVENT_HANDLERS__.set(`${eventSource}:${identifier}`, handler);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Register a client middleware package to be imported in the generated browser client.
|
|
215
|
+
* Used by Building Blocks that need browser-side protocol support (e.g., Realtime WebSocket).
|
|
216
|
+
* Only has effect during codegen — pushes to a global collector if one is active.
|
|
217
|
+
*/
|
|
218
|
+
registerClientMiddleware(packageSpecifier: string): void {
|
|
219
|
+
(globalThis as any).__BLOCKS_CLIENT_MIDDLEWARE__?.push(packageSpecifier);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Register a dev server attachment package to be attached to the local HTTP server.
|
|
224
|
+
* Used by Building Blocks that need special local dev protocols (e.g., WebSocket server).
|
|
225
|
+
* Only has effect during dev server startup — pushes to a global collector if one is active.
|
|
226
|
+
*
|
|
227
|
+
* Dev attachments use an **explicit registration** pattern: the dev server imports
|
|
228
|
+
* the module and calls its exported `attach(server)` function, passing the HTTP
|
|
229
|
+
* server instance. This differs intentionally from client middleware, which uses
|
|
230
|
+
* self-registering side-effect imports — dev attachments need the server instance
|
|
231
|
+
* at registration time, which isn't available during a bare import.
|
|
232
|
+
*/
|
|
233
|
+
registerDevAttachment(packageSpecifier: string): void {
|
|
234
|
+
(globalThis as any).__BLOCKS_DEV_ATTACHMENTS__?.push(packageSpecifier);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Build the customUserAgent chain by walking the scope tree.
|
|
239
|
+
*
|
|
240
|
+
* Produces an array of `[key, value]` pairs suitable for passing directly
|
|
241
|
+
* to any AWS SDK v3 client's `customUserAgent` configuration option.
|
|
242
|
+
*
|
|
243
|
+
* The chain encodes the nesting hierarchy:
|
|
244
|
+
* - `['aws-blocks', coreVersion]` — always first
|
|
245
|
+
* - `['bb', 'ParentBB/parentVersion']` — if this BB is nested inside another BB
|
|
246
|
+
* - `['bb', 'SelfBB/selfVersion']` — the current BB
|
|
247
|
+
*
|
|
248
|
+
* @param coreVersion - The version of @aws-blocks/core
|
|
249
|
+
* @returns Array of [key, value] pairs for customUserAgent
|
|
250
|
+
*
|
|
251
|
+
* @example
|
|
252
|
+
* ```typescript
|
|
253
|
+
* const client = new DynamoDBClient({
|
|
254
|
+
* customUserAgent: this.buildUserAgentChain(),
|
|
255
|
+
* });
|
|
256
|
+
* ```
|
|
257
|
+
*/
|
|
258
|
+
protected buildUserAgentChain(): [string, string][] {
|
|
259
|
+
const chain: [string, string][] = [['aws-blocks', CORE_VERSION]];
|
|
260
|
+
|
|
261
|
+
const parents = collectBBParents(this.parent);
|
|
262
|
+
for (const parent of parents) {
|
|
263
|
+
chain.push(['bb', `${parent.bbName}/${parent.bbVersion}`]);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
if (this.bbName && this.bbVersion && OFFICIAL_BB_NAMES.has(this.bbName)) {
|
|
267
|
+
chain.push(['bb', `${this.bbName}/${this.bbVersion}`]);
|
|
268
|
+
}
|
|
269
|
+
return chain;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* Walk up the scope tree collecting any parent that has BuildingBlockMeta.
|
|
275
|
+
* Returns them in root-to-leaf order (outermost parent first).
|
|
276
|
+
*/
|
|
277
|
+
function collectBBParents(parent: ScopeParent | undefined): BuildingBlockMeta[] {
|
|
278
|
+
const result: BuildingBlockMeta[] = [];
|
|
279
|
+
let current: ScopeParent | undefined = parent;
|
|
280
|
+
|
|
281
|
+
while (current) {
|
|
282
|
+
if (isOfficialBuildingBlock(current)) {
|
|
283
|
+
result.unshift(current);
|
|
284
|
+
}
|
|
285
|
+
current = 'parent' in current ? (current as any).parent : undefined;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
return result;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
function isBuildingBlock(obj: unknown): obj is BuildingBlockMeta {
|
|
294
|
+
return (
|
|
295
|
+
obj !== null &&
|
|
296
|
+
typeof obj === 'object' &&
|
|
297
|
+
'bbName' in obj &&
|
|
298
|
+
'bbVersion' in obj &&
|
|
299
|
+
typeof (obj as any).bbName === 'string' &&
|
|
300
|
+
typeof (obj as any).bbVersion === 'string'
|
|
301
|
+
);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* Returns true if the object is a Building Block with an official AWS name.
|
|
306
|
+
* Custom BBs (with names not in the allowlist) return false, ensuring
|
|
307
|
+
* customer-chosen names never appear in user-agent telemetry.
|
|
308
|
+
*/
|
|
309
|
+
function isOfficialBuildingBlock(obj: unknown): obj is BuildingBlockMeta {
|
|
310
|
+
return isBuildingBlock(obj) && OFFICIAL_BB_NAMES.has(obj.bbName);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
export function computeScopeFullId(scope: { id: string; parent?: any }) {
|
|
314
|
+
if (scope.parent) {
|
|
315
|
+
if ('fullId' in scope.parent && scope.parent.fullId) {
|
|
316
|
+
return `${scope.parent.fullId}-${scope.id}`;
|
|
317
|
+
}
|
|
318
|
+
if ('id' in scope.parent && scope.parent.id) {
|
|
319
|
+
return `${scope.parent.id}-${scope.id}`;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
return scope.id;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
export interface BlocksStackProps extends StackProps {
|
|
326
|
+
backendHandlerPath: string;
|
|
327
|
+
backendCDKPath: string;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
export class BlocksStack {
|
|
331
|
+
public readonly id: string;
|
|
332
|
+
constructor(scope: Construct, id: string, props: BlocksStackProps) {
|
|
333
|
+
this.id = id;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
import { existsSync, mkdirSync } from 'node:fs';
|
|
6
|
+
import type { Scope } from './index.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Options for {@link getMockDataDir}.
|
|
10
|
+
*/
|
|
11
|
+
export interface MockDataDirOptions {
|
|
12
|
+
/**
|
|
13
|
+
* When true, returns the root `.bb-data/` directory without appending
|
|
14
|
+
* the scope's fullId. Use this to consolidate all data from a single resource
|
|
15
|
+
* type into a single file or folder. E.g., `settings.json`.
|
|
16
|
+
*/
|
|
17
|
+
root?: boolean;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Returns the mock data directory for a Building Block instance, creating it
|
|
22
|
+
* if it doesn't already exist.
|
|
23
|
+
*
|
|
24
|
+
* Resolves to `<cwd>/.bb-data/{scope.fullId}/` by default. The BB owns this
|
|
25
|
+
* folder and can store whatever files it needs inside it.
|
|
26
|
+
*
|
|
27
|
+
* If `root: true` are specified, returns `<cwd>/.bb-data/`. The BB must then
|
|
28
|
+
* take responsibility not to conflict with other files and folders.
|
|
29
|
+
*
|
|
30
|
+
* @param scope - The Building Block's Scope instance.
|
|
31
|
+
* @param options - Optional configuration.
|
|
32
|
+
* @returns Absolute path to the BB's data directory (guaranteed to exist).
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```typescript
|
|
36
|
+
* const dir = getMockDataDir(this);
|
|
37
|
+
* const filePath = join(dir, 'store.json');
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* @example Root directory for shared files
|
|
41
|
+
* ```typescript
|
|
42
|
+
* const dir = getMockDataDir(this, { root: true });
|
|
43
|
+
* const settingsPath = join(dir, 'settings.json');
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export function getMockDataDir(scope: Scope, options?: MockDataDirOptions): string {
|
|
47
|
+
const segments = [process.cwd(), '.bb-data'];
|
|
48
|
+
if (!options?.root) segments.push(scope.fullId);
|
|
49
|
+
const dir = join(...segments);
|
|
50
|
+
if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
|
|
51
|
+
return dir;
|
|
52
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// DO NOT EDIT — auto-generated by scripts/generate-bb-names.mjs
|
|
2
|
+
// Source: packages/blocks/package.json → aws-blocks.vendorize
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Set of official Building Block display names recognized by telemetry.
|
|
6
|
+
* Any BB whose `bbName` matches one of these entries is reported in the
|
|
7
|
+
* `product.buildingBlocks` array; others still contribute to `totalCount`.
|
|
8
|
+
*/
|
|
9
|
+
export const OFFICIAL_BB_NAMES: ReadonlySet<string> = new Set([
|
|
10
|
+
'Agent',
|
|
11
|
+
'AppSetting',
|
|
12
|
+
'AsyncJob',
|
|
13
|
+
'AuthBasic',
|
|
14
|
+
'AuthCognito',
|
|
15
|
+
'AuthOidc',
|
|
16
|
+
'CronJob',
|
|
17
|
+
'Dashboard',
|
|
18
|
+
'Database',
|
|
19
|
+
'DistributedDatabase',
|
|
20
|
+
'DistributedTable',
|
|
21
|
+
'EmailClient',
|
|
22
|
+
'FileBucket',
|
|
23
|
+
'KVStore',
|
|
24
|
+
'KnowledgeBase',
|
|
25
|
+
'Logger',
|
|
26
|
+
'Metrics',
|
|
27
|
+
'Realtime',
|
|
28
|
+
'Tracer',
|
|
29
|
+
]);
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* SDK Identifier Registry — centralized map of Building Block AWS resource identifiers.
|
|
6
|
+
*
|
|
7
|
+
* Each Building Block registers its AWS resource identifiers (table names, bucket names,
|
|
8
|
+
* queue URLs, etc.) upon construction. Application code retrieves these identifiers via
|
|
9
|
+
* {@link getSdkIdentifiers} to interact with BB-managed resources using the raw AWS SDK.
|
|
10
|
+
*
|
|
11
|
+
* This module serves a complementary role to `mock-data.ts`:
|
|
12
|
+
* - `mock-data.ts` → provides local file paths for mock persistence (`.bb-data/`)
|
|
13
|
+
* - `sdk-registry.ts` → provides AWS resource identifiers for SDK access
|
|
14
|
+
*
|
|
15
|
+
* Together, these two modules form the runtime discovery layer — `mock-data.ts` for
|
|
16
|
+
* local development, and `sdk-registry.ts` for deployed AWS environments.
|
|
17
|
+
*
|
|
18
|
+
* @see {@link docs/guides/extending-with-existing-aws-resources.md} — "SDK Identifiers" section
|
|
19
|
+
* @module
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
type ResourceEntry = Record<string, string>;
|
|
23
|
+
|
|
24
|
+
const registry = new Map<string, ResourceEntry>();
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Register SDK identifiers for a Building Block instance.
|
|
28
|
+
*
|
|
29
|
+
* Called internally by Building Blocks during construction — **not intended for
|
|
30
|
+
* application code**. Each BB registers its resolved AWS resource identifiers
|
|
31
|
+
* (e.g., DynamoDB table name, S3 bucket name) so they can be retrieved later
|
|
32
|
+
* via {@link getSdkIdentifiers}.
|
|
33
|
+
*
|
|
34
|
+
* If the same `fullId` is registered multiple times (e.g., a BB that manages
|
|
35
|
+
* multiple resources), entries are merged — later calls augment rather than
|
|
36
|
+
* replace earlier ones.
|
|
37
|
+
*
|
|
38
|
+
* @param fullId - The Building Block's fully-qualified scope ID (e.g., `"myapp-users"`).
|
|
39
|
+
* @param identifiers - Key-value map of resource identifiers to register.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```typescript
|
|
43
|
+
* // Inside a Building Block constructor (internal use only):
|
|
44
|
+
* registerSdkIdentifiers(this.fullId, { tableName: 'myapp-users' });
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export function registerSdkIdentifiers(fullId: string, identifiers: ResourceEntry): void {
|
|
48
|
+
registry.set(fullId, { ...registry.get(fullId), ...identifiers });
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Retrieve the SDK identifiers for a specific Building Block instance.
|
|
53
|
+
*
|
|
54
|
+
* This is the base (untyped) version that returns `Record<string, string>`.
|
|
55
|
+
* For full type safety with per-BB return types, import the overloaded
|
|
56
|
+
* `getSdkIdentifiers` from `@aws-blocks/blocks` instead.
|
|
57
|
+
*
|
|
58
|
+
* @param bb - Any object with a `fullId` property (typically a Building Block instance).
|
|
59
|
+
* @returns A record of the BB's registered resource identifiers.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```typescript
|
|
63
|
+
* import { getSdkIdentifiers } from '@aws-blocks/blocks';
|
|
64
|
+
* import { KVStore } from '@aws-blocks/bb-kv-store';
|
|
65
|
+
* import { DynamoDBClient, QueryCommand } from '@aws-sdk/client-dynamodb';
|
|
66
|
+
*
|
|
67
|
+
* const store = new KVStore(scope, 'users', {});
|
|
68
|
+
*
|
|
69
|
+
* // Retrieve the underlying DynamoDB table name (typed via overloads)
|
|
70
|
+
* const { tableName } = getSdkIdentifiers(store);
|
|
71
|
+
*
|
|
72
|
+
* // Use it with the raw AWS SDK for advanced operations
|
|
73
|
+
* const client = new DynamoDBClient({});
|
|
74
|
+
* const result = await client.send(new QueryCommand({
|
|
75
|
+
* TableName: tableName,
|
|
76
|
+
* KeyConditionExpression: 'pk = :pk',
|
|
77
|
+
* ExpressionAttributeValues: { ':pk': { S: 'user#123' } },
|
|
78
|
+
* }));
|
|
79
|
+
* ```
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```typescript
|
|
83
|
+
* import { getSdkIdentifiers } from '@aws-blocks/blocks';
|
|
84
|
+
* import { FileBucket } from '@aws-blocks/bb-file-bucket';
|
|
85
|
+
* import { S3Client, GetObjectCommand } from '@aws-sdk/client-s3';
|
|
86
|
+
* import { getSignedUrl } from '@aws-sdk/s3-request-presigner';
|
|
87
|
+
*
|
|
88
|
+
* const bucket = new FileBucket(scope, 'uploads', {});
|
|
89
|
+
* const { bucketName } = getSdkIdentifiers(bucket);
|
|
90
|
+
*
|
|
91
|
+
* // Generate a presigned download URL
|
|
92
|
+
* const url = await getSignedUrl(
|
|
93
|
+
* new S3Client({}),
|
|
94
|
+
* new GetObjectCommand({ Bucket: bucketName, Key: 'report.pdf' }),
|
|
95
|
+
* { expiresIn: 3600 },
|
|
96
|
+
* );
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
export function getSdkIdentifiers(bb: { fullId: string }): Record<string, string> {
|
|
100
|
+
return registry.get(bb.fullId) ?? {};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Return a read-only snapshot of all registered SDK identifiers.
|
|
105
|
+
*
|
|
106
|
+
* Primarily useful for debugging, tooling, and diagnostics — lists every
|
|
107
|
+
* Building Block that has registered identifiers in the current process.
|
|
108
|
+
* The returned map is keyed by `fullId` with each value being the identifier
|
|
109
|
+
* record for that BB.
|
|
110
|
+
*
|
|
111
|
+
* @returns A read-only `Map<fullId, identifiers>` of all registered entries.
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* ```typescript
|
|
115
|
+
* import { getAllSdkIdentifiers } from '@aws-blocks/core';
|
|
116
|
+
*
|
|
117
|
+
* // Log all registered identifiers for debugging
|
|
118
|
+
* for (const [fullId, ids] of getAllSdkIdentifiers()) {
|
|
119
|
+
* console.log(`${fullId}:`, ids);
|
|
120
|
+
* }
|
|
121
|
+
* // Output:
|
|
122
|
+
* // myapp-users: { tableName: 'myapp-users' }
|
|
123
|
+
* // myapp-uploads: { bucketName: 'myapp-uploads' }
|
|
124
|
+
* // myapp-auth: { userPoolId: 'us-east-1_abc', clientId: '123abc' }
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
127
|
+
export function getAllSdkIdentifiers(): ReadonlyMap<string, ResourceEntry> {
|
|
128
|
+
return new Map(registry);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Clear the SDK identifier registry. **For test cleanup only.**
|
|
133
|
+
*
|
|
134
|
+
* Resets the global registry to an empty state. Use this in test teardown
|
|
135
|
+
* (`afterEach`) to prevent state leakage between test cases that construct
|
|
136
|
+
* Building Blocks.
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* ```typescript
|
|
140
|
+
* import { _resetSdkRegistry } from '@aws-blocks/core';
|
|
141
|
+
* import { afterEach } from 'node:test';
|
|
142
|
+
*
|
|
143
|
+
* afterEach(() => {
|
|
144
|
+
* _resetSdkRegistry();
|
|
145
|
+
* });
|
|
146
|
+
* ```
|
|
147
|
+
*/
|
|
148
|
+
export function _resetSdkRegistry(): void {
|
|
149
|
+
registry.clear();
|
|
150
|
+
}
|
package/src/constants.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Reserved namespace for AWS-managed framework features.
|
|
6
|
+
* No user routes can be registered under this path.
|
|
7
|
+
*/
|
|
8
|
+
export const BLOCKS_NAMESPACE = '/aws-blocks';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* URL path prefix for the Blocks RPC endpoint.
|
|
12
|
+
*
|
|
13
|
+
* CloudFront behaviors route this path (and children) to the API Gateway
|
|
14
|
+
* origin. Namespaced under `/aws-blocks/api` so it doesn't shadow
|
|
15
|
+
* framework-conventional `/api/*` SSR routes (Next.js `pages/api/*`,
|
|
16
|
+
* `app/api/*`, Nuxt `server/api/*`) on CloudFront's first-match-wins
|
|
17
|
+
* behavior resolution.
|
|
18
|
+
*/
|
|
19
|
+
export const BLOCKS_RPC_PREFIX = '/aws-blocks/api';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Reserved subtree for the auth Building Block's HTTP routes.
|
|
23
|
+
*
|
|
24
|
+
* Like {@link BLOCKS_RPC_PREFIX}, this lives under the reserved `/aws-blocks`
|
|
25
|
+
* namespace so Hosting can proxy the whole auth flow (callback, sign-in,
|
|
26
|
+
* exchange, authorize-params, the stub IdP, …) to the API Gateway origin with a
|
|
27
|
+
* single CloudFront behavior — and so it never collides with a customer's own
|
|
28
|
+
* `/auth/*` frontend routes. The auth BB mounts every route it owns under this
|
|
29
|
+
* prefix; CloudFront forwards the subtree and the Lambda dispatches by path.
|
|
30
|
+
*/
|
|
31
|
+
export const BLOCKS_AUTH_PREFIX = '/aws-blocks/auth';
|