@aws-blocks/core 0.1.18 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (159) hide show
  1. package/dist/cdk/__fixtures__/import-meta-handler.d.ts +6 -0
  2. package/dist/cdk/__fixtures__/import-meta-handler.d.ts.map +1 -0
  3. package/dist/cdk/__fixtures__/import-meta-handler.js +13 -0
  4. package/dist/cdk/blocks-backend.d.ts +46 -9
  5. package/dist/cdk/blocks-backend.d.ts.map +1 -1
  6. package/dist/cdk/blocks-backend.js +66 -67
  7. package/dist/cdk/blocks-backend.test.js +114 -56
  8. package/dist/cdk/blocks-defaults.d.ts +70 -0
  9. package/dist/cdk/blocks-defaults.d.ts.map +1 -0
  10. package/dist/cdk/blocks-defaults.js +27 -0
  11. package/dist/cdk/blocks-defaults.test.d.ts +2 -0
  12. package/dist/cdk/blocks-defaults.test.d.ts.map +1 -0
  13. package/dist/cdk/blocks-defaults.test.js +24 -0
  14. package/dist/cdk/blocks-stack.test.js +74 -31
  15. package/dist/cdk/bundling.d.ts +42 -0
  16. package/dist/cdk/bundling.d.ts.map +1 -0
  17. package/dist/cdk/bundling.js +72 -0
  18. package/dist/cdk/bundling.test.d.ts +2 -0
  19. package/dist/cdk/bundling.test.d.ts.map +1 -0
  20. package/dist/cdk/bundling.test.js +80 -0
  21. package/dist/cdk/compute/compute.d.ts +33 -0
  22. package/dist/cdk/compute/compute.d.ts.map +1 -0
  23. package/dist/cdk/compute/compute.js +28 -0
  24. package/dist/cdk/compute/default-compute-factory.d.ts +33 -0
  25. package/dist/cdk/compute/default-compute-factory.d.ts.map +1 -0
  26. package/dist/cdk/compute/default-compute-factory.js +3 -0
  27. package/dist/cdk/index.d.ts +92 -12
  28. package/dist/cdk/index.d.ts.map +1 -1
  29. package/dist/cdk/index.js +141 -25
  30. package/dist/cdk/internal.d.ts +25 -0
  31. package/dist/cdk/internal.d.ts.map +1 -0
  32. package/dist/cdk/internal.js +27 -0
  33. package/dist/cdk/mixins.d.ts +18 -4
  34. package/dist/cdk/mixins.d.ts.map +1 -1
  35. package/dist/cdk/mixins.js +31 -7
  36. package/dist/cdk/mixins.test.js +45 -0
  37. package/dist/common/index.d.ts +9 -0
  38. package/dist/common/index.d.ts.map +1 -1
  39. package/dist/hosting-secrets.d.ts +48 -0
  40. package/dist/hosting-secrets.d.ts.map +1 -0
  41. package/dist/hosting-secrets.js +57 -0
  42. package/dist/hosting-secrets.test.d.ts +2 -0
  43. package/dist/hosting-secrets.test.d.ts.map +1 -0
  44. package/dist/hosting-secrets.test.js +81 -0
  45. package/dist/hosting.d.ts +88 -6
  46. package/dist/hosting.d.ts.map +1 -1
  47. package/dist/hosting.js +83 -24
  48. package/dist/hosting.test.js +158 -10
  49. package/dist/index.cdk.d.ts +13 -11
  50. package/dist/index.cdk.d.ts.map +1 -1
  51. package/dist/index.cdk.js +13 -8
  52. package/dist/index.d.ts +8 -7
  53. package/dist/index.d.ts.map +1 -1
  54. package/dist/index.js +9 -5
  55. package/dist/lambda-handler.test.js +66 -0
  56. package/dist/pipeline/index.d.ts +24 -2
  57. package/dist/pipeline/index.d.ts.map +1 -1
  58. package/dist/pipeline/index.js +41 -1
  59. package/dist/pipeline.test.d.ts +2 -0
  60. package/dist/pipeline.test.d.ts.map +1 -0
  61. package/dist/pipeline.test.js +47 -0
  62. package/dist/rpc.d.ts +21 -0
  63. package/dist/rpc.d.ts.map +1 -1
  64. package/dist/rpc.js +46 -3
  65. package/dist/rpc.test.js +58 -1
  66. package/dist/scripts/config.d.ts +15 -0
  67. package/dist/scripts/config.d.ts.map +1 -0
  68. package/dist/scripts/config.js +29 -0
  69. package/dist/scripts/deploy.d.ts.map +1 -1
  70. package/dist/scripts/deploy.js +4 -0
  71. package/dist/scripts/dev-server.d.ts +8 -0
  72. package/dist/scripts/dev-server.d.ts.map +1 -1
  73. package/dist/scripts/dev-server.js +31 -0
  74. package/dist/scripts/generate-client.d.ts.map +1 -1
  75. package/dist/scripts/generate-client.js +9 -4
  76. package/dist/scripts/generate-client.test.js +19 -4
  77. package/dist/scripts/index.d.ts +13 -10
  78. package/dist/scripts/index.d.ts.map +1 -1
  79. package/dist/scripts/index.js +11 -8
  80. package/dist/scripts/preflight-credentials.d.ts +30 -0
  81. package/dist/scripts/preflight-credentials.d.ts.map +1 -0
  82. package/dist/scripts/preflight-credentials.js +108 -0
  83. package/dist/scripts/preflight-credentials.test.d.ts +2 -0
  84. package/dist/scripts/preflight-credentials.test.d.ts.map +1 -0
  85. package/dist/scripts/preflight-credentials.test.js +77 -0
  86. package/dist/scripts/sandbox-args.test.d.ts +2 -0
  87. package/dist/scripts/sandbox-args.test.d.ts.map +1 -0
  88. package/dist/scripts/sandbox-args.test.js +77 -0
  89. package/dist/scripts/sandbox.d.ts +52 -0
  90. package/dist/scripts/sandbox.d.ts.map +1 -1
  91. package/dist/scripts/sandbox.js +92 -15
  92. package/dist/scripts/secret.d.ts +15 -0
  93. package/dist/scripts/secret.d.ts.map +1 -0
  94. package/dist/scripts/secret.js +29 -0
  95. package/dist/scripts/secret.test.d.ts +2 -0
  96. package/dist/scripts/secret.test.d.ts.map +1 -0
  97. package/dist/scripts/secret.test.js +28 -0
  98. package/dist/scripts/telemetry.test.js +2 -0
  99. package/dist/scripts/typegen.d.ts +15 -0
  100. package/dist/scripts/typegen.d.ts.map +1 -0
  101. package/dist/scripts/typegen.js +16 -0
  102. package/dist/secret-naming.d.ts +58 -0
  103. package/dist/secret-naming.d.ts.map +1 -0
  104. package/dist/secret-naming.js +67 -0
  105. package/dist/secret-naming.test.d.ts +2 -0
  106. package/dist/secret-naming.test.d.ts.map +1 -0
  107. package/dist/secret-naming.test.js +40 -0
  108. package/dist/telemetry/environment.d.ts.map +1 -1
  109. package/dist/telemetry/environment.js +3 -1
  110. package/dist/telemetry/telemetry.test.js +10 -0
  111. package/dist/version.d.ts +1 -1
  112. package/dist/version.d.ts.map +1 -1
  113. package/dist/version.js +1 -1
  114. package/package.json +7 -1
  115. package/src/cdk/__fixtures__/import-meta-handler.ts +16 -0
  116. package/src/cdk/blocks-backend.test.ts +308 -237
  117. package/src/cdk/blocks-backend.ts +98 -77
  118. package/src/cdk/blocks-defaults.test.ts +27 -0
  119. package/src/cdk/blocks-defaults.ts +75 -0
  120. package/src/cdk/blocks-stack.test.ts +160 -110
  121. package/src/cdk/bundling.test.ts +90 -0
  122. package/src/cdk/bundling.ts +76 -0
  123. package/src/cdk/compute/compute.ts +37 -0
  124. package/src/cdk/compute/default-compute-factory.ts +37 -0
  125. package/src/cdk/index.ts +178 -27
  126. package/src/cdk/internal.ts +30 -0
  127. package/src/cdk/mixins.test.ts +56 -1
  128. package/src/cdk/mixins.ts +32 -7
  129. package/src/common/index.ts +9 -0
  130. package/src/hosting-secrets.test.ts +106 -0
  131. package/src/hosting-secrets.ts +106 -0
  132. package/src/hosting.test.ts +244 -63
  133. package/src/hosting.ts +180 -68
  134. package/src/index.cdk.ts +79 -36
  135. package/src/index.ts +35 -16
  136. package/src/lambda-handler.test.ts +74 -0
  137. package/src/pipeline/index.ts +64 -11
  138. package/src/pipeline.test.ts +55 -0
  139. package/src/rpc.test.ts +66 -1
  140. package/src/rpc.ts +60 -3
  141. package/src/scripts/config.ts +35 -0
  142. package/src/scripts/deploy.ts +5 -0
  143. package/src/scripts/dev-server.ts +40 -0
  144. package/src/scripts/generate-client.test.ts +43 -8
  145. package/src/scripts/generate-client.ts +70 -65
  146. package/src/scripts/index.ts +20 -17
  147. package/src/scripts/preflight-credentials.test.ts +110 -0
  148. package/src/scripts/preflight-credentials.ts +131 -0
  149. package/src/scripts/sandbox-args.test.ts +92 -0
  150. package/src/scripts/sandbox.ts +102 -15
  151. package/src/scripts/secret.test.ts +35 -0
  152. package/src/scripts/secret.ts +35 -0
  153. package/src/scripts/telemetry.test.ts +2 -0
  154. package/src/scripts/typegen.ts +18 -0
  155. package/src/secret-naming.test.ts +59 -0
  156. package/src/secret-naming.ts +99 -0
  157. package/src/telemetry/environment.ts +3 -1
  158. package/src/telemetry/telemetry.test.ts +12 -0
  159. package/src/version.ts +1 -1
@@ -0,0 +1,59 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import assert from 'node:assert';
5
+ import { describe, it } from 'node:test';
6
+ import { secretStoreLocator } from '@aws-blocks/hosting';
7
+ import {
8
+ BLOCKS_CONFIG_PARAMETER_PREFIX,
9
+ BLOCKS_SECRET_PARAMETER_PREFIX,
10
+ blocksConfigParameterName,
11
+ blocksConfigPrefix,
12
+ blocksSecretParameterName,
13
+ blocksSecretPrefix,
14
+ blocksStoreConfig,
15
+ } from './secret-naming.js';
16
+
17
+ // These run with no `.blocks/config.json` in cwd, so they exercise the UNSCOPED
18
+ // fallback. A real Blocks app has the file, so it gets the `stackId`-scoped path
19
+ // (covered by the explicit-stackId cases below).
20
+ void describe('Blocks value namespaces — fallback (no .blocks/config.json)', () => {
21
+ void it('falls back to the unscoped /blocks/secrets and /blocks/config bases', () => {
22
+ assert.strictEqual(BLOCKS_SECRET_PARAMETER_PREFIX, '/blocks/secrets');
23
+ assert.strictEqual(BLOCKS_CONFIG_PARAMETER_PREFIX, '/blocks/config');
24
+ // Secrets Manager names are slash-free at the root; SSM keeps the leading slash.
25
+ assert.strictEqual(blocksSecretParameterName('STRIPE_KEY'), 'blocks/secrets/STRIPE_KEY');
26
+ assert.strictEqual(blocksConfigParameterName('FEATURE_FLAGS'), '/blocks/config/FEATURE_FLAGS');
27
+ assert.deepStrictEqual(blocksStoreConfig(), {
28
+ secretStore: { prefix: '/blocks/secrets' },
29
+ configStore: { prefix: '/blocks/config' },
30
+ });
31
+ });
32
+
33
+ void it('matches the store locator the CLI/grant/runtime actually use (no divergent name)', () => {
34
+ assert.strictEqual(
35
+ blocksSecretParameterName('K'),
36
+ secretStoreLocator('K', { prefix: BLOCKS_SECRET_PARAMETER_PREFIX, store: 'secrets-manager' }),
37
+ );
38
+ assert.strictEqual(
39
+ blocksConfigParameterName('K'),
40
+ secretStoreLocator('K', { prefix: BLOCKS_CONFIG_PARAMETER_PREFIX, store: 'ssm' }),
41
+ );
42
+ });
43
+ });
44
+
45
+ void describe('Blocks value namespaces — stackId-scoped (B5)', () => {
46
+ void it('scopes the prefix by stackId so two apps in one account never collide', () => {
47
+ assert.strictEqual(blocksSecretPrefix('myapp'), '/blocks/myapp/secrets');
48
+ assert.strictEqual(blocksConfigPrefix('myapp'), '/blocks/myapp/config');
49
+ assert.deepStrictEqual(blocksStoreConfig('myapp'), {
50
+ secretStore: { prefix: '/blocks/myapp/secrets' },
51
+ configStore: { prefix: '/blocks/myapp/config' },
52
+ });
53
+ });
54
+
55
+ void it('scoped store names match secretStoreLocator (SM slash-free, SSM leading-slash)', () => {
56
+ assert.strictEqual(blocksSecretParameterName('STRIPE_KEY', 'myapp'), 'blocks/myapp/secrets/STRIPE_KEY');
57
+ assert.strictEqual(blocksConfigParameterName('FEATURE_FLAGS', 'myapp'), '/blocks/myapp/config/FEATURE_FLAGS');
58
+ });
59
+ });
@@ -0,0 +1,99 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ /**
5
+ * Blocks-owned namespaces for hosting values.
6
+ *
7
+ * The mechanism (markers, resolvers, path/env naming) lives in the
8
+ * framework-neutral `@aws-blocks/hosting` package, which defaults to neutral
9
+ * `/hosting/secrets` and `/hosting/config` prefixes so a non-Blocks consumer
10
+ * never inherits Blocks branding.
11
+ *
12
+ * This module is the ONE place Blocks pins its own namespaces. The prefixes are
13
+ * **scoped to the app's stable `stackId`** (from the committed `.blocks/config.json`)
14
+ * — `/blocks/<stackId>/secrets` (Secrets Manager) and `/blocks/<stackId>/config`
15
+ * (SSM Parameter Store) — so two Blocks apps in one account/region never collide.
16
+ *
17
+ * Both sides derive the scope from the SAME source: the out-of-band CLI
18
+ * (`npm run secret`/`config`) and the CDK synth both call {@link blocksStoreConfig},
19
+ * which reads `stackId` via {@link getStackId}. When `.blocks/config.json` is absent
20
+ * (e.g. a bare unit test) both sides fall back to the unscoped `/blocks/secrets` /
21
+ * `/blocks/config` identically — so the CLI write and the deploy read can never
22
+ * diverge, whether the id is present or not. `stackId` is stage-independent
23
+ * (prod and sandbox share it); use the opt-in `stage` segment for per-stage values.
24
+ *
25
+ * @module
26
+ */
27
+
28
+ import type { StoreConfig } from '@aws-blocks/hosting/constructs';
29
+ import { secretStoreLocator } from '@aws-blocks/hosting';
30
+ import { getStackId } from './scripts/stack-id.js';
31
+
32
+ /** Base Blocks prefix for `secret()` values (Secrets Manager); scoped by `stackId`. */
33
+ export const BLOCKS_SECRET_PARAMETER_PREFIX = '/blocks/secrets';
34
+
35
+ /** Base Blocks prefix for `config()` values (SSM Parameter Store); scoped by `stackId`. */
36
+ export const BLOCKS_CONFIG_PARAMETER_PREFIX = '/blocks/config';
37
+
38
+ /**
39
+ * Resolve the app's `stackId` (stable, stage-independent, from `.blocks/config.json`),
40
+ * or `undefined` when it can't be read. Never throws — a missing id means both the
41
+ * CLI and synth fall back to the unscoped base prefix, so they still agree.
42
+ */
43
+ function resolveStackId(explicit?: string): string | undefined {
44
+ if (explicit) return explicit;
45
+ try {
46
+ return getStackId();
47
+ } catch {
48
+ return undefined;
49
+ }
50
+ }
51
+
52
+ /** The Blocks `secret()` prefix, scoped to `stackId` when available. */
53
+ export function blocksSecretPrefix(stackId?: string): string {
54
+ const id = resolveStackId(stackId);
55
+ return id ? `/blocks/${id}/secrets` : BLOCKS_SECRET_PARAMETER_PREFIX;
56
+ }
57
+
58
+ /** The Blocks `config()` prefix, scoped to `stackId` when available. */
59
+ export function blocksConfigPrefix(stackId?: string): string {
60
+ const id = resolveStackId(stackId);
61
+ return id ? `/blocks/${id}/config` : BLOCKS_CONFIG_PARAMETER_PREFIX;
62
+ }
63
+
64
+ /**
65
+ * The **actual store name** of a Blocks `secret()` key in AWS Secrets Manager —
66
+ * routed through {@link secretStoreLocator} so it matches exactly what the CLI
67
+ * writes, the IAM grant scopes to, and the runtime resolver reads. Secrets Manager
68
+ * names are slash-free at the root, so this is `blocks/<stackId>/secrets/<KEY>`
69
+ * (no leading slash), NOT an SSM-style path. Pass `stackId` to compute it without
70
+ * reading `.blocks/config.json`.
71
+ *
72
+ * @example 'blocks/myapp/secrets/STRIPE_KEY'
73
+ */
74
+ export function blocksSecretParameterName(key: string, stackId?: string): string {
75
+ return secretStoreLocator(key, { prefix: blocksSecretPrefix(stackId), store: 'secrets-manager' });
76
+ }
77
+
78
+ /**
79
+ * The **actual store name** of a Blocks `config()` key in SSM Parameter Store —
80
+ * routed through {@link secretStoreLocator} for consistency with the CLI/grant/
81
+ * runtime path. SSM keeps the leading-slash path.
82
+ *
83
+ * @example '/blocks/myapp/config/FEATURE_FLAGS'
84
+ */
85
+ export function blocksConfigParameterName(key: string, stackId?: string): string {
86
+ return secretStoreLocator(key, { prefix: blocksConfigPrefix(stackId), store: 'ssm' });
87
+ }
88
+
89
+ /**
90
+ * The Blocks store config passed to the shared hosting engine — `stackId`-scoped
91
+ * prefixes (falling back to the unscoped base when `.blocks/config.json` is absent).
92
+ * Both the CLI and the CDK synth call this, so they resolve identical names.
93
+ */
94
+ export function blocksStoreConfig(stackId?: string): StoreConfig {
95
+ return {
96
+ secretStore: { prefix: blocksSecretPrefix(stackId) },
97
+ configStore: { prefix: blocksConfigPrefix(stackId) },
98
+ };
99
+ }
@@ -29,7 +29,9 @@ export function isCI(): boolean {
29
29
  process.env.JENKINS_URL ||
30
30
  process.env.TF_BUILD ||
31
31
  process.env.BITBUCKET_BUILD_NUMBER ||
32
- process.env.BUILDKITE
32
+ process.env.BUILDKITE ||
33
+ process.env.RENDER ||
34
+ process.env.TASKCLUSTER_ROOT_URL
33
35
  );
34
36
  }
35
37
 
@@ -133,6 +133,8 @@ describe('telemetry/environment', () => {
133
133
  delete process.env.TF_BUILD;
134
134
  delete process.env.BITBUCKET_BUILD_NUMBER;
135
135
  delete process.env.BUILDKITE;
136
+ delete process.env.RENDER;
137
+ delete process.env.TASKCLUSTER_ROOT_URL;
136
138
  });
137
139
 
138
140
  it('returns false when no CI env vars set', () => {
@@ -153,6 +155,16 @@ describe('telemetry/environment', () => {
153
155
  process.env.CODEBUILD_BUILD_ID = 'build-123';
154
156
  assert.strictEqual(isCI(), true);
155
157
  });
158
+
159
+ it('returns true when RENDER is set', () => {
160
+ process.env.RENDER = 'true';
161
+ assert.strictEqual(isCI(), true);
162
+ });
163
+
164
+ it('returns true when TASKCLUSTER_ROOT_URL is set', () => {
165
+ process.env.TASKCLUSTER_ROOT_URL = 'https://tc.example.com';
166
+ assert.strictEqual(isCI(), true);
167
+ });
156
168
  });
157
169
 
158
170
  it('detectOS returns a valid platform', () => {
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  // Auto-generated by scripts/generate-version.mjs — do not edit manually
2
- export const CORE_VERSION = '0.1.18';
2
+ export const CORE_VERSION = '0.3.0';