@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,195 @@
|
|
|
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 { Scope } from './index.js';
|
|
6
|
+
import { CORE_VERSION } from '../version.js';
|
|
7
|
+
/**
|
|
8
|
+
* Test subclass that exposes the protected buildUserAgentChain method.
|
|
9
|
+
*/
|
|
10
|
+
class TestBB extends Scope {
|
|
11
|
+
bbName;
|
|
12
|
+
bbVersion;
|
|
13
|
+
constructor(id, opts) {
|
|
14
|
+
super(id, { parent: opts?.parent });
|
|
15
|
+
this.bbName = opts?.bbName;
|
|
16
|
+
this.bbVersion = opts?.bbVersion;
|
|
17
|
+
}
|
|
18
|
+
/** Expose protected method for testing */
|
|
19
|
+
testBuildUserAgentChain() {
|
|
20
|
+
return this.buildUserAgentChain();
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
// ── buildUserAgentChain: standalone BB (no BB parent) ───────────────────────
|
|
24
|
+
describe('buildUserAgentChain', () => {
|
|
25
|
+
test('standalone BB returns [aws-blocks, bb] pair', () => {
|
|
26
|
+
const root = { id: 'my-app' };
|
|
27
|
+
const bb = new TestBB('store', {
|
|
28
|
+
parent: root,
|
|
29
|
+
bbName: 'KVStore',
|
|
30
|
+
bbVersion: '0.4.0',
|
|
31
|
+
});
|
|
32
|
+
const chain = bb.testBuildUserAgentChain();
|
|
33
|
+
assert.deepStrictEqual(chain, [
|
|
34
|
+
['aws-blocks', CORE_VERSION],
|
|
35
|
+
['bb', 'KVStore/0.4.0'],
|
|
36
|
+
]);
|
|
37
|
+
});
|
|
38
|
+
// ── Nested BB (one level) ─────────────────────────────────────────────
|
|
39
|
+
test('BB nested inside another BB includes parent BB in chain', () => {
|
|
40
|
+
const root = { id: 'my-app' };
|
|
41
|
+
const parentBB = new TestBB('auth', {
|
|
42
|
+
parent: root,
|
|
43
|
+
bbName: 'AuthBasic',
|
|
44
|
+
bbVersion: '1.0.1',
|
|
45
|
+
});
|
|
46
|
+
const childBB = new TestBB('store', {
|
|
47
|
+
parent: parentBB,
|
|
48
|
+
bbName: 'KVStore',
|
|
49
|
+
bbVersion: '0.4.0',
|
|
50
|
+
});
|
|
51
|
+
const chain = childBB.testBuildUserAgentChain();
|
|
52
|
+
assert.deepStrictEqual(chain, [
|
|
53
|
+
['aws-blocks', CORE_VERSION],
|
|
54
|
+
['bb', 'AuthBasic/1.0.1'],
|
|
55
|
+
['bb', 'KVStore/0.4.0'],
|
|
56
|
+
]);
|
|
57
|
+
});
|
|
58
|
+
// ── Deeply nested BB (2+ levels) ──────────────────────────────────────
|
|
59
|
+
test('BB nested 2+ levels deep builds the full chain in root-to-leaf order', () => {
|
|
60
|
+
const root = { id: 'my-app' };
|
|
61
|
+
const grandparentBB = new TestBB('dashboard', {
|
|
62
|
+
parent: root,
|
|
63
|
+
bbName: 'Dashboard',
|
|
64
|
+
bbVersion: '2.0.0',
|
|
65
|
+
});
|
|
66
|
+
const parentBB = new TestBB('auth', {
|
|
67
|
+
parent: grandparentBB,
|
|
68
|
+
bbName: 'AuthBasic',
|
|
69
|
+
bbVersion: '1.0.1',
|
|
70
|
+
});
|
|
71
|
+
const childBB = new TestBB('store', {
|
|
72
|
+
parent: parentBB,
|
|
73
|
+
bbName: 'KVStore',
|
|
74
|
+
bbVersion: '0.4.0',
|
|
75
|
+
});
|
|
76
|
+
const chain = childBB.testBuildUserAgentChain();
|
|
77
|
+
assert.deepStrictEqual(chain, [
|
|
78
|
+
['aws-blocks', CORE_VERSION],
|
|
79
|
+
['bb', 'Dashboard/2.0.0'],
|
|
80
|
+
['bb', 'AuthBasic/1.0.1'],
|
|
81
|
+
['bb', 'KVStore/0.4.0'],
|
|
82
|
+
]);
|
|
83
|
+
});
|
|
84
|
+
// ── Parent without BB metadata (non-BB scope in the chain) ────────────
|
|
85
|
+
test('parent scope without bbName/bbVersion is skipped in chain', () => {
|
|
86
|
+
const root = { id: 'my-app' };
|
|
87
|
+
// A plain Scope (not a BB) in between
|
|
88
|
+
const middleScope = new TestBB('middleware', {
|
|
89
|
+
parent: root,
|
|
90
|
+
// no bbName/bbVersion
|
|
91
|
+
});
|
|
92
|
+
const childBB = new TestBB('store', {
|
|
93
|
+
parent: middleScope,
|
|
94
|
+
bbName: 'KVStore',
|
|
95
|
+
bbVersion: '0.4.0',
|
|
96
|
+
});
|
|
97
|
+
const chain = childBB.testBuildUserAgentChain();
|
|
98
|
+
assert.deepStrictEqual(chain, [
|
|
99
|
+
['aws-blocks', CORE_VERSION],
|
|
100
|
+
['bb', 'KVStore/0.4.0'],
|
|
101
|
+
]);
|
|
102
|
+
});
|
|
103
|
+
test('non-BB parent between two BBs is skipped', () => {
|
|
104
|
+
const root = { id: 'my-app' };
|
|
105
|
+
const parentBB = new TestBB('auth', {
|
|
106
|
+
parent: root,
|
|
107
|
+
bbName: 'AuthBasic',
|
|
108
|
+
bbVersion: '1.0.1',
|
|
109
|
+
});
|
|
110
|
+
// Plain scope between parent BB and child BB
|
|
111
|
+
const middleScope = new TestBB('internal', {
|
|
112
|
+
parent: parentBB,
|
|
113
|
+
// no bbName/bbVersion
|
|
114
|
+
});
|
|
115
|
+
const childBB = new TestBB('store', {
|
|
116
|
+
parent: middleScope,
|
|
117
|
+
bbName: 'KVStore',
|
|
118
|
+
bbVersion: '0.4.0',
|
|
119
|
+
});
|
|
120
|
+
const chain = childBB.testBuildUserAgentChain();
|
|
121
|
+
assert.deepStrictEqual(chain, [
|
|
122
|
+
['aws-blocks', CORE_VERSION],
|
|
123
|
+
['bb', 'AuthBasic/1.0.1'],
|
|
124
|
+
['bb', 'KVStore/0.4.0'],
|
|
125
|
+
]);
|
|
126
|
+
});
|
|
127
|
+
// ── Edge case: bbName set but bbVersion missing ───────────────────────
|
|
128
|
+
test('self not added to chain when bbVersion is missing', () => {
|
|
129
|
+
const root = { id: 'my-app' };
|
|
130
|
+
const bb = new TestBB('store', {
|
|
131
|
+
parent: root,
|
|
132
|
+
bbName: 'KVStore',
|
|
133
|
+
// bbVersion missing
|
|
134
|
+
});
|
|
135
|
+
const chain = bb.testBuildUserAgentChain();
|
|
136
|
+
assert.deepStrictEqual(chain, [
|
|
137
|
+
['aws-blocks', CORE_VERSION],
|
|
138
|
+
]);
|
|
139
|
+
});
|
|
140
|
+
// ── Edge case: bbVersion set but bbName missing ───────────────────────
|
|
141
|
+
test('self not added to chain when bbName is missing', () => {
|
|
142
|
+
const root = { id: 'my-app' };
|
|
143
|
+
const bb = new TestBB('store', {
|
|
144
|
+
parent: root,
|
|
145
|
+
// bbName missing
|
|
146
|
+
bbVersion: '0.4.0',
|
|
147
|
+
});
|
|
148
|
+
const chain = bb.testBuildUserAgentChain();
|
|
149
|
+
assert.deepStrictEqual(chain, [
|
|
150
|
+
['aws-blocks', CORE_VERSION],
|
|
151
|
+
]);
|
|
152
|
+
});
|
|
153
|
+
// ── Edge case: neither bbName nor bbVersion set ───────────────────────
|
|
154
|
+
test('self not added to chain when neither bbName nor bbVersion is set', () => {
|
|
155
|
+
const root = { id: 'my-app' };
|
|
156
|
+
const bb = new TestBB('store', {
|
|
157
|
+
parent: root,
|
|
158
|
+
});
|
|
159
|
+
const chain = bb.testBuildUserAgentChain();
|
|
160
|
+
assert.deepStrictEqual(chain, [
|
|
161
|
+
['aws-blocks', CORE_VERSION],
|
|
162
|
+
]);
|
|
163
|
+
});
|
|
164
|
+
// ── Edge case: parent with only bbName (no bbVersion) is skipped ──────
|
|
165
|
+
test('parent with bbName but no bbVersion is skipped', () => {
|
|
166
|
+
const root = { id: 'my-app' };
|
|
167
|
+
const parentPartial = new TestBB('partial', {
|
|
168
|
+
parent: root,
|
|
169
|
+
bbName: 'PartialBB',
|
|
170
|
+
// bbVersion missing
|
|
171
|
+
});
|
|
172
|
+
const childBB = new TestBB('store', {
|
|
173
|
+
parent: parentPartial,
|
|
174
|
+
bbName: 'KVStore',
|
|
175
|
+
bbVersion: '0.4.0',
|
|
176
|
+
});
|
|
177
|
+
const chain = childBB.testBuildUserAgentChain();
|
|
178
|
+
assert.deepStrictEqual(chain, [
|
|
179
|
+
['aws-blocks', CORE_VERSION],
|
|
180
|
+
['bb', 'KVStore/0.4.0'],
|
|
181
|
+
]);
|
|
182
|
+
});
|
|
183
|
+
// ── Verifies CORE_VERSION is used as the aws-blocks version ───────────
|
|
184
|
+
test('CORE_VERSION is used as the aws-blocks version', () => {
|
|
185
|
+
const root = { id: 'my-app' };
|
|
186
|
+
const bb = new TestBB('store', {
|
|
187
|
+
parent: root,
|
|
188
|
+
bbName: 'KVStore',
|
|
189
|
+
bbVersion: '1.0.0',
|
|
190
|
+
});
|
|
191
|
+
const chain = bb.testBuildUserAgentChain();
|
|
192
|
+
assert.strictEqual(chain[0][0], 'aws-blocks');
|
|
193
|
+
assert.strictEqual(chain[0][1], CORE_VERSION);
|
|
194
|
+
});
|
|
195
|
+
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { Scope } from './index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Options for {@link getMockDataDir}.
|
|
4
|
+
*/
|
|
5
|
+
export interface MockDataDirOptions {
|
|
6
|
+
/**
|
|
7
|
+
* When true, returns the root `.bb-data/` directory without appending
|
|
8
|
+
* the scope's fullId. Use this to consolidate all data from a single resource
|
|
9
|
+
* type into a single file or folder. E.g., `settings.json`.
|
|
10
|
+
*/
|
|
11
|
+
root?: boolean;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Returns the mock data directory for a Building Block instance, creating it
|
|
15
|
+
* if it doesn't already exist.
|
|
16
|
+
*
|
|
17
|
+
* Resolves to `<cwd>/.bb-data/{scope.fullId}/` by default. The BB owns this
|
|
18
|
+
* folder and can store whatever files it needs inside it.
|
|
19
|
+
*
|
|
20
|
+
* If `root: true` are specified, returns `<cwd>/.bb-data/`. The BB must then
|
|
21
|
+
* take responsibility not to conflict with other files and folders.
|
|
22
|
+
*
|
|
23
|
+
* @param scope - The Building Block's Scope instance.
|
|
24
|
+
* @param options - Optional configuration.
|
|
25
|
+
* @returns Absolute path to the BB's data directory (guaranteed to exist).
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* const dir = getMockDataDir(this);
|
|
30
|
+
* const filePath = join(dir, 'store.json');
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @example Root directory for shared files
|
|
34
|
+
* ```typescript
|
|
35
|
+
* const dir = getMockDataDir(this, { root: true });
|
|
36
|
+
* const settingsPath = join(dir, 'settings.json');
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export declare function getMockDataDir(scope: Scope, options?: MockDataDirOptions): string;
|
|
40
|
+
//# sourceMappingURL=mock-data.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mock-data.d.ts","sourceRoot":"","sources":["../../src/common/mock-data.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAExC;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC;;;;OAIG;IACH,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,CAAC,EAAE,kBAAkB,GAAG,MAAM,CAMjF"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { existsSync, mkdirSync } from 'node:fs';
|
|
5
|
+
/**
|
|
6
|
+
* Returns the mock data directory for a Building Block instance, creating it
|
|
7
|
+
* if it doesn't already exist.
|
|
8
|
+
*
|
|
9
|
+
* Resolves to `<cwd>/.bb-data/{scope.fullId}/` by default. The BB owns this
|
|
10
|
+
* folder and can store whatever files it needs inside it.
|
|
11
|
+
*
|
|
12
|
+
* If `root: true` are specified, returns `<cwd>/.bb-data/`. The BB must then
|
|
13
|
+
* take responsibility not to conflict with other files and folders.
|
|
14
|
+
*
|
|
15
|
+
* @param scope - The Building Block's Scope instance.
|
|
16
|
+
* @param options - Optional configuration.
|
|
17
|
+
* @returns Absolute path to the BB's data directory (guaranteed to exist).
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* const dir = getMockDataDir(this);
|
|
22
|
+
* const filePath = join(dir, 'store.json');
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @example Root directory for shared files
|
|
26
|
+
* ```typescript
|
|
27
|
+
* const dir = getMockDataDir(this, { root: true });
|
|
28
|
+
* const settingsPath = join(dir, 'settings.json');
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export function getMockDataDir(scope, options) {
|
|
32
|
+
const segments = [process.cwd(), '.bb-data'];
|
|
33
|
+
if (!options?.root)
|
|
34
|
+
segments.push(scope.fullId);
|
|
35
|
+
const dir = join(...segments);
|
|
36
|
+
if (!existsSync(dir))
|
|
37
|
+
mkdirSync(dir, { recursive: true });
|
|
38
|
+
return dir;
|
|
39
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Set of official Building Block display names recognized by telemetry.
|
|
3
|
+
* Any BB whose `bbName` matches one of these entries is reported in the
|
|
4
|
+
* `product.buildingBlocks` array; others still contribute to `totalCount`.
|
|
5
|
+
*/
|
|
6
|
+
export declare const OFFICIAL_BB_NAMES: ReadonlySet<string>;
|
|
7
|
+
//# sourceMappingURL=official-bb-names.generated.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"official-bb-names.generated.d.ts","sourceRoot":"","sources":["../../src/common/official-bb-names.generated.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,EAAE,WAAW,CAAC,MAAM,CAoBhD,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// DO NOT EDIT — auto-generated by scripts/generate-bb-names.mjs
|
|
2
|
+
// Source: packages/blocks/package.json → aws-blocks.vendorize
|
|
3
|
+
/**
|
|
4
|
+
* Set of official Building Block display names recognized by telemetry.
|
|
5
|
+
* Any BB whose `bbName` matches one of these entries is reported in the
|
|
6
|
+
* `product.buildingBlocks` array; others still contribute to `totalCount`.
|
|
7
|
+
*/
|
|
8
|
+
export const OFFICIAL_BB_NAMES = new Set([
|
|
9
|
+
'Agent',
|
|
10
|
+
'AppSetting',
|
|
11
|
+
'AsyncJob',
|
|
12
|
+
'AuthBasic',
|
|
13
|
+
'AuthCognito',
|
|
14
|
+
'AuthOidc',
|
|
15
|
+
'CronJob',
|
|
16
|
+
'Dashboard',
|
|
17
|
+
'Database',
|
|
18
|
+
'DistributedDatabase',
|
|
19
|
+
'DistributedTable',
|
|
20
|
+
'EmailClient',
|
|
21
|
+
'FileBucket',
|
|
22
|
+
'KVStore',
|
|
23
|
+
'KnowledgeBase',
|
|
24
|
+
'Logger',
|
|
25
|
+
'Metrics',
|
|
26
|
+
'Realtime',
|
|
27
|
+
'Tracer',
|
|
28
|
+
]);
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SDK Identifier Registry — centralized map of Building Block AWS resource identifiers.
|
|
3
|
+
*
|
|
4
|
+
* Each Building Block registers its AWS resource identifiers (table names, bucket names,
|
|
5
|
+
* queue URLs, etc.) upon construction. Application code retrieves these identifiers via
|
|
6
|
+
* {@link getSdkIdentifiers} to interact with BB-managed resources using the raw AWS SDK.
|
|
7
|
+
*
|
|
8
|
+
* This module serves a complementary role to `mock-data.ts`:
|
|
9
|
+
* - `mock-data.ts` → provides local file paths for mock persistence (`.bb-data/`)
|
|
10
|
+
* - `sdk-registry.ts` → provides AWS resource identifiers for SDK access
|
|
11
|
+
*
|
|
12
|
+
* Together, these two modules form the runtime discovery layer — `mock-data.ts` for
|
|
13
|
+
* local development, and `sdk-registry.ts` for deployed AWS environments.
|
|
14
|
+
*
|
|
15
|
+
* @see {@link docs/guides/extending-with-existing-aws-resources.md} — "SDK Identifiers" section
|
|
16
|
+
* @module
|
|
17
|
+
*/
|
|
18
|
+
type ResourceEntry = Record<string, string>;
|
|
19
|
+
/**
|
|
20
|
+
* Register SDK identifiers for a Building Block instance.
|
|
21
|
+
*
|
|
22
|
+
* Called internally by Building Blocks during construction — **not intended for
|
|
23
|
+
* application code**. Each BB registers its resolved AWS resource identifiers
|
|
24
|
+
* (e.g., DynamoDB table name, S3 bucket name) so they can be retrieved later
|
|
25
|
+
* via {@link getSdkIdentifiers}.
|
|
26
|
+
*
|
|
27
|
+
* If the same `fullId` is registered multiple times (e.g., a BB that manages
|
|
28
|
+
* multiple resources), entries are merged — later calls augment rather than
|
|
29
|
+
* replace earlier ones.
|
|
30
|
+
*
|
|
31
|
+
* @param fullId - The Building Block's fully-qualified scope ID (e.g., `"myapp-users"`).
|
|
32
|
+
* @param identifiers - Key-value map of resource identifiers to register.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```typescript
|
|
36
|
+
* // Inside a Building Block constructor (internal use only):
|
|
37
|
+
* registerSdkIdentifiers(this.fullId, { tableName: 'myapp-users' });
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export declare function registerSdkIdentifiers(fullId: string, identifiers: ResourceEntry): void;
|
|
41
|
+
/**
|
|
42
|
+
* Retrieve the SDK identifiers for a specific Building Block instance.
|
|
43
|
+
*
|
|
44
|
+
* This is the base (untyped) version that returns `Record<string, string>`.
|
|
45
|
+
* For full type safety with per-BB return types, import the overloaded
|
|
46
|
+
* `getSdkIdentifiers` from `@aws-blocks/blocks` instead.
|
|
47
|
+
*
|
|
48
|
+
* @param bb - Any object with a `fullId` property (typically a Building Block instance).
|
|
49
|
+
* @returns A record of the BB's registered resource identifiers.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```typescript
|
|
53
|
+
* import { getSdkIdentifiers } from '@aws-blocks/blocks';
|
|
54
|
+
* import { KVStore } from '@aws-blocks/bb-kv-store';
|
|
55
|
+
* import { DynamoDBClient, QueryCommand } from '@aws-sdk/client-dynamodb';
|
|
56
|
+
*
|
|
57
|
+
* const store = new KVStore(scope, 'users', {});
|
|
58
|
+
*
|
|
59
|
+
* // Retrieve the underlying DynamoDB table name (typed via overloads)
|
|
60
|
+
* const { tableName } = getSdkIdentifiers(store);
|
|
61
|
+
*
|
|
62
|
+
* // Use it with the raw AWS SDK for advanced operations
|
|
63
|
+
* const client = new DynamoDBClient({});
|
|
64
|
+
* const result = await client.send(new QueryCommand({
|
|
65
|
+
* TableName: tableName,
|
|
66
|
+
* KeyConditionExpression: 'pk = :pk',
|
|
67
|
+
* ExpressionAttributeValues: { ':pk': { S: 'user#123' } },
|
|
68
|
+
* }));
|
|
69
|
+
* ```
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```typescript
|
|
73
|
+
* import { getSdkIdentifiers } from '@aws-blocks/blocks';
|
|
74
|
+
* import { FileBucket } from '@aws-blocks/bb-file-bucket';
|
|
75
|
+
* import { S3Client, GetObjectCommand } from '@aws-sdk/client-s3';
|
|
76
|
+
* import { getSignedUrl } from '@aws-sdk/s3-request-presigner';
|
|
77
|
+
*
|
|
78
|
+
* const bucket = new FileBucket(scope, 'uploads', {});
|
|
79
|
+
* const { bucketName } = getSdkIdentifiers(bucket);
|
|
80
|
+
*
|
|
81
|
+
* // Generate a presigned download URL
|
|
82
|
+
* const url = await getSignedUrl(
|
|
83
|
+
* new S3Client({}),
|
|
84
|
+
* new GetObjectCommand({ Bucket: bucketName, Key: 'report.pdf' }),
|
|
85
|
+
* { expiresIn: 3600 },
|
|
86
|
+
* );
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
export declare function getSdkIdentifiers(bb: {
|
|
90
|
+
fullId: string;
|
|
91
|
+
}): Record<string, string>;
|
|
92
|
+
/**
|
|
93
|
+
* Return a read-only snapshot of all registered SDK identifiers.
|
|
94
|
+
*
|
|
95
|
+
* Primarily useful for debugging, tooling, and diagnostics — lists every
|
|
96
|
+
* Building Block that has registered identifiers in the current process.
|
|
97
|
+
* The returned map is keyed by `fullId` with each value being the identifier
|
|
98
|
+
* record for that BB.
|
|
99
|
+
*
|
|
100
|
+
* @returns A read-only `Map<fullId, identifiers>` of all registered entries.
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```typescript
|
|
104
|
+
* import { getAllSdkIdentifiers } from '@aws-blocks/core';
|
|
105
|
+
*
|
|
106
|
+
* // Log all registered identifiers for debugging
|
|
107
|
+
* for (const [fullId, ids] of getAllSdkIdentifiers()) {
|
|
108
|
+
* console.log(`${fullId}:`, ids);
|
|
109
|
+
* }
|
|
110
|
+
* // Output:
|
|
111
|
+
* // myapp-users: { tableName: 'myapp-users' }
|
|
112
|
+
* // myapp-uploads: { bucketName: 'myapp-uploads' }
|
|
113
|
+
* // myapp-auth: { userPoolId: 'us-east-1_abc', clientId: '123abc' }
|
|
114
|
+
* ```
|
|
115
|
+
*/
|
|
116
|
+
export declare function getAllSdkIdentifiers(): ReadonlyMap<string, ResourceEntry>;
|
|
117
|
+
/**
|
|
118
|
+
* Clear the SDK identifier registry. **For test cleanup only.**
|
|
119
|
+
*
|
|
120
|
+
* Resets the global registry to an empty state. Use this in test teardown
|
|
121
|
+
* (`afterEach`) to prevent state leakage between test cases that construct
|
|
122
|
+
* Building Blocks.
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* ```typescript
|
|
126
|
+
* import { _resetSdkRegistry } from '@aws-blocks/core';
|
|
127
|
+
* import { afterEach } from 'node:test';
|
|
128
|
+
*
|
|
129
|
+
* afterEach(() => {
|
|
130
|
+
* _resetSdkRegistry();
|
|
131
|
+
* });
|
|
132
|
+
* ```
|
|
133
|
+
*/
|
|
134
|
+
export declare function _resetSdkRegistry(): void;
|
|
135
|
+
export {};
|
|
136
|
+
//# sourceMappingURL=sdk-registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sdk-registry.d.ts","sourceRoot":"","sources":["../../src/common/sdk-registry.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;GAgBG;AAEH,KAAK,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAI5C;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,aAAa,GAAG,IAAI,CAEvF;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AACH,wBAAgB,iBAAiB,CAAC,EAAE,EAAE;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAEhF;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,oBAAoB,IAAI,WAAW,CAAC,MAAM,EAAE,aAAa,CAAC,CAEzE;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,iBAAiB,IAAI,IAAI,CAExC"}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
const registry = new Map();
|
|
4
|
+
/**
|
|
5
|
+
* Register SDK identifiers for a Building Block instance.
|
|
6
|
+
*
|
|
7
|
+
* Called internally by Building Blocks during construction — **not intended for
|
|
8
|
+
* application code**. Each BB registers its resolved AWS resource identifiers
|
|
9
|
+
* (e.g., DynamoDB table name, S3 bucket name) so they can be retrieved later
|
|
10
|
+
* via {@link getSdkIdentifiers}.
|
|
11
|
+
*
|
|
12
|
+
* If the same `fullId` is registered multiple times (e.g., a BB that manages
|
|
13
|
+
* multiple resources), entries are merged — later calls augment rather than
|
|
14
|
+
* replace earlier ones.
|
|
15
|
+
*
|
|
16
|
+
* @param fullId - The Building Block's fully-qualified scope ID (e.g., `"myapp-users"`).
|
|
17
|
+
* @param identifiers - Key-value map of resource identifiers to register.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* // Inside a Building Block constructor (internal use only):
|
|
22
|
+
* registerSdkIdentifiers(this.fullId, { tableName: 'myapp-users' });
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export function registerSdkIdentifiers(fullId, identifiers) {
|
|
26
|
+
registry.set(fullId, { ...registry.get(fullId), ...identifiers });
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Retrieve the SDK identifiers for a specific Building Block instance.
|
|
30
|
+
*
|
|
31
|
+
* This is the base (untyped) version that returns `Record<string, string>`.
|
|
32
|
+
* For full type safety with per-BB return types, import the overloaded
|
|
33
|
+
* `getSdkIdentifiers` from `@aws-blocks/blocks` instead.
|
|
34
|
+
*
|
|
35
|
+
* @param bb - Any object with a `fullId` property (typically a Building Block instance).
|
|
36
|
+
* @returns A record of the BB's registered resource identifiers.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```typescript
|
|
40
|
+
* import { getSdkIdentifiers } from '@aws-blocks/blocks';
|
|
41
|
+
* import { KVStore } from '@aws-blocks/bb-kv-store';
|
|
42
|
+
* import { DynamoDBClient, QueryCommand } from '@aws-sdk/client-dynamodb';
|
|
43
|
+
*
|
|
44
|
+
* const store = new KVStore(scope, 'users', {});
|
|
45
|
+
*
|
|
46
|
+
* // Retrieve the underlying DynamoDB table name (typed via overloads)
|
|
47
|
+
* const { tableName } = getSdkIdentifiers(store);
|
|
48
|
+
*
|
|
49
|
+
* // Use it with the raw AWS SDK for advanced operations
|
|
50
|
+
* const client = new DynamoDBClient({});
|
|
51
|
+
* const result = await client.send(new QueryCommand({
|
|
52
|
+
* TableName: tableName,
|
|
53
|
+
* KeyConditionExpression: 'pk = :pk',
|
|
54
|
+
* ExpressionAttributeValues: { ':pk': { S: 'user#123' } },
|
|
55
|
+
* }));
|
|
56
|
+
* ```
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```typescript
|
|
60
|
+
* import { getSdkIdentifiers } from '@aws-blocks/blocks';
|
|
61
|
+
* import { FileBucket } from '@aws-blocks/bb-file-bucket';
|
|
62
|
+
* import { S3Client, GetObjectCommand } from '@aws-sdk/client-s3';
|
|
63
|
+
* import { getSignedUrl } from '@aws-sdk/s3-request-presigner';
|
|
64
|
+
*
|
|
65
|
+
* const bucket = new FileBucket(scope, 'uploads', {});
|
|
66
|
+
* const { bucketName } = getSdkIdentifiers(bucket);
|
|
67
|
+
*
|
|
68
|
+
* // Generate a presigned download URL
|
|
69
|
+
* const url = await getSignedUrl(
|
|
70
|
+
* new S3Client({}),
|
|
71
|
+
* new GetObjectCommand({ Bucket: bucketName, Key: 'report.pdf' }),
|
|
72
|
+
* { expiresIn: 3600 },
|
|
73
|
+
* );
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
export function getSdkIdentifiers(bb) {
|
|
77
|
+
return registry.get(bb.fullId) ?? {};
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Return a read-only snapshot of all registered SDK identifiers.
|
|
81
|
+
*
|
|
82
|
+
* Primarily useful for debugging, tooling, and diagnostics — lists every
|
|
83
|
+
* Building Block that has registered identifiers in the current process.
|
|
84
|
+
* The returned map is keyed by `fullId` with each value being the identifier
|
|
85
|
+
* record for that BB.
|
|
86
|
+
*
|
|
87
|
+
* @returns A read-only `Map<fullId, identifiers>` of all registered entries.
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* ```typescript
|
|
91
|
+
* import { getAllSdkIdentifiers } from '@aws-blocks/core';
|
|
92
|
+
*
|
|
93
|
+
* // Log all registered identifiers for debugging
|
|
94
|
+
* for (const [fullId, ids] of getAllSdkIdentifiers()) {
|
|
95
|
+
* console.log(`${fullId}:`, ids);
|
|
96
|
+
* }
|
|
97
|
+
* // Output:
|
|
98
|
+
* // myapp-users: { tableName: 'myapp-users' }
|
|
99
|
+
* // myapp-uploads: { bucketName: 'myapp-uploads' }
|
|
100
|
+
* // myapp-auth: { userPoolId: 'us-east-1_abc', clientId: '123abc' }
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
export function getAllSdkIdentifiers() {
|
|
104
|
+
return new Map(registry);
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Clear the SDK identifier registry. **For test cleanup only.**
|
|
108
|
+
*
|
|
109
|
+
* Resets the global registry to an empty state. Use this in test teardown
|
|
110
|
+
* (`afterEach`) to prevent state leakage between test cases that construct
|
|
111
|
+
* Building Blocks.
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* ```typescript
|
|
115
|
+
* import { _resetSdkRegistry } from '@aws-blocks/core';
|
|
116
|
+
* import { afterEach } from 'node:test';
|
|
117
|
+
*
|
|
118
|
+
* afterEach(() => {
|
|
119
|
+
* _resetSdkRegistry();
|
|
120
|
+
* });
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
123
|
+
export function _resetSdkRegistry() {
|
|
124
|
+
registry.clear();
|
|
125
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reserved namespace for AWS-managed framework features.
|
|
3
|
+
* No user routes can be registered under this path.
|
|
4
|
+
*/
|
|
5
|
+
export declare const BLOCKS_NAMESPACE = "/aws-blocks";
|
|
6
|
+
/**
|
|
7
|
+
* URL path prefix for the Blocks RPC endpoint.
|
|
8
|
+
*
|
|
9
|
+
* CloudFront behaviors route this path (and children) to the API Gateway
|
|
10
|
+
* origin. Namespaced under `/aws-blocks/api` so it doesn't shadow
|
|
11
|
+
* framework-conventional `/api/*` SSR routes (Next.js `pages/api/*`,
|
|
12
|
+
* `app/api/*`, Nuxt `server/api/*`) on CloudFront's first-match-wins
|
|
13
|
+
* behavior resolution.
|
|
14
|
+
*/
|
|
15
|
+
export declare const BLOCKS_RPC_PREFIX = "/aws-blocks/api";
|
|
16
|
+
/**
|
|
17
|
+
* Reserved subtree for the auth Building Block's HTTP routes.
|
|
18
|
+
*
|
|
19
|
+
* Like {@link BLOCKS_RPC_PREFIX}, this lives under the reserved `/aws-blocks`
|
|
20
|
+
* namespace so Hosting can proxy the whole auth flow (callback, sign-in,
|
|
21
|
+
* exchange, authorize-params, the stub IdP, …) to the API Gateway origin with a
|
|
22
|
+
* single CloudFront behavior — and so it never collides with a customer's own
|
|
23
|
+
* `/auth/*` frontend routes. The auth BB mounts every route it owns under this
|
|
24
|
+
* prefix; CloudFront forwards the subtree and the Lambda dispatches by path.
|
|
25
|
+
*/
|
|
26
|
+
export declare const BLOCKS_AUTH_PREFIX = "/aws-blocks/auth";
|
|
27
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,eAAO,MAAM,gBAAgB,gBAAgB,CAAC;AAE9C;;;;;;;;GAQG;AACH,eAAO,MAAM,iBAAiB,oBAAoB,CAAC;AAEnD;;;;;;;;;GASG;AACH,eAAO,MAAM,kBAAkB,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
/**
|
|
4
|
+
* Reserved namespace for AWS-managed framework features.
|
|
5
|
+
* No user routes can be registered under this path.
|
|
6
|
+
*/
|
|
7
|
+
export const BLOCKS_NAMESPACE = '/aws-blocks';
|
|
8
|
+
/**
|
|
9
|
+
* URL path prefix for the Blocks RPC endpoint.
|
|
10
|
+
*
|
|
11
|
+
* CloudFront behaviors route this path (and children) to the API Gateway
|
|
12
|
+
* origin. Namespaced under `/aws-blocks/api` so it doesn't shadow
|
|
13
|
+
* framework-conventional `/api/*` SSR routes (Next.js `pages/api/*`,
|
|
14
|
+
* `app/api/*`, Nuxt `server/api/*`) on CloudFront's first-match-wins
|
|
15
|
+
* behavior resolution.
|
|
16
|
+
*/
|
|
17
|
+
export const BLOCKS_RPC_PREFIX = '/aws-blocks/api';
|
|
18
|
+
/**
|
|
19
|
+
* Reserved subtree for the auth Building Block's HTTP routes.
|
|
20
|
+
*
|
|
21
|
+
* Like {@link BLOCKS_RPC_PREFIX}, this lives under the reserved `/aws-blocks`
|
|
22
|
+
* namespace so Hosting can proxy the whole auth flow (callback, sign-in,
|
|
23
|
+
* exchange, authorize-params, the stub IdP, …) to the API Gateway origin with a
|
|
24
|
+
* single CloudFront behavior — and so it never collides with a customer's own
|
|
25
|
+
* `/auth/*` frontend routes. The auth BB mounts every route it owns under this
|
|
26
|
+
* prefix; CloudFront forwards the subtree and the Lambda dispatches by path.
|
|
27
|
+
*/
|
|
28
|
+
export const BLOCKS_AUTH_PREFIX = '/aws-blocks/auth';
|