@auth-craft/aws-cf-stack 1.0.1 → 1.1.1

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/README.md CHANGED
@@ -46,7 +46,7 @@ So `outputs`/`gateway` look up the api stack `<app>-<stage>-api`. The CDK output
46
46
  | `admin` | Create the super-admin (idempotent; **skips** if `LAMBDA_SUPER_ADMIN_*` / `LAMBDA_AUTH_SETUP_TOKEN` unset; "already exists" = success). |
47
47
  | `gateway` | Deploy the 3 gateway workers. Re-reads the Lambda outputs from CloudFormation if run as a separate invocation. |
48
48
  | `all` | `lambda` → `admin` → `gateway`, one run. |
49
- | `outputs` | Print the live api-stack outputs as JSON (no deploy), incl. derived `backendUrl`. For self-driving callers. |
49
+ | `outputs` | Print the live api-stack outputs as JSON (no deploy): `backendUrl`, `apiBasePath`, `dynamodbTable`, and the auth keys read **from the live Lambda config** (`jwtPublicKey`, `jwtIssuer`, `jwtAlgorithm`, `serviceJwtPublicKey`) + `gatewayUrls`/`routePrefixes`. Self-contained — works standalone (no env), so an orchestrator can auto-fill its `*_AUTH_*` vars. |
50
50
 
51
51
  ## Requirements (on the deploying machine)
52
52
 
package/lib/common.sh CHANGED
@@ -166,6 +166,17 @@ cfn_output() {
166
166
  --output text --region "$AWS_REGION" 2>/dev/null || true
167
167
  }
168
168
 
169
+ # Read one environment variable from a deployed Lambda's live config. Lets `outputs`
170
+ # be self-contained (read what the Lambda actually runs with) instead of depending on
171
+ # the caller's process env. Note the runtime var names differ from the LAMBDA_* inputs
172
+ # (e.g. JWT_PUBLIC_KEY, not LAMBDA_JWT_PUBLIC_KEY).
173
+ lambda_env() {
174
+ local fn="$1" key="$2"
175
+ require_cmd aws
176
+ aws lambda get-function-configuration --function-name "$fn" --region "$AWS_REGION" \
177
+ --query "Environment.Variables.${key}" --output text 2>/dev/null | sed 's/^None$//' || true
178
+ }
179
+
169
180
  # Derive a gateway worker URL for a scope (custom domain > workers.dev > empty).
170
181
  gateway_url_for() {
171
182
  local scope="$1" upper dom_var custom
@@ -183,31 +194,46 @@ gateway_url_for() {
183
194
 
184
195
  # Print the live deploy outputs of the existing api stack as JSON, for an
185
196
  # orchestrator that drives its own steps between stages and wants to AUTO-FILL its
186
- # own *_AUTH_* vars without copying anything by hand. Includes:
197
+ # own *_AUTH_* vars without copying anything by hand. SELF-CONTAINED: the JWT keys /
198
+ # issuer / alg are read from the LIVE Lambda config (get-function-configuration), so it
199
+ # works when run standalone (no env), falling back to process env only if the read is
200
+ # empty. Includes:
187
201
  # - lambdaFunctionUrl, apiBasePath, authSystemName, dynamodbTable
188
202
  # - backendUrl (= functionUrl + basePath, the anti-drift value)
189
- # - jwtPublicKey + jwtIssuer (what verifiers need; issuer = LAMBDA_JWT_ISSUER || authSystemName)
203
+ # - jwtPublicKey + jwtIssuer + jwtAlgorithm + serviceJwtPublicKey (from the Lambda)
190
204
  # - gatewayUrls{system,tenant,customer} + routePrefixes{...}
191
205
  print_outputs_json() {
192
206
  require_cmd aws; require_cmd jq
193
207
  require_aws_identity
194
208
  local api_stack="${APP_NAME}-${STAGE}-api"
195
- local url base name table backend issuer
209
+ local url base name table fn backend issuer
196
210
  url="$(cfn_output "$api_stack" LambdaFunctionUrl)"
197
211
  base="$(cfn_output "$api_stack" ApiBasePath)"
198
212
  name="$(cfn_output "$api_stack" AuthSystemName)"
199
213
  table="$(cfn_output "$api_stack" DynamoDBTableName)"
214
+ fn="$(cfn_output "$api_stack" LambdaFunctionName)"
200
215
  [[ -n "$url" && "$url" != "None" ]] \
201
216
  || die "No outputs for stack $api_stack in $AWS_REGION — deploy the lambda stage first."
202
217
  backend="${url%/}${base}"
203
- issuer="${LAMBDA_JWT_ISSUER:-$name}"
218
+
219
+ # Read the auth-relevant values from the LIVE Lambda config so `outputs` is
220
+ # self-contained (works when run standalone, e.g. deploying the BFF later in a
221
+ # separate process). Fall back to the caller's process env if the Lambda read is
222
+ # empty. Runtime var names differ from the LAMBDA_* inputs.
223
+ local jwtPub jwtIssuer jwtAlg svcPub
224
+ [[ -n "$fn" && "$fn" != "None" ]] || fn="$name"
225
+ jwtPub="$(lambda_env "$fn" JWT_PUBLIC_KEY)"; jwtPub="${jwtPub:-${LAMBDA_JWT_PUBLIC_KEY:-}}"
226
+ jwtIssuer="$(lambda_env "$fn" JWT_ISSUER)"; jwtIssuer="${jwtIssuer:-${LAMBDA_JWT_ISSUER:-$name}}"
227
+ jwtAlg="$(lambda_env "$fn" JWT_ALGORITHM)"; jwtAlg="${jwtAlg:-${LAMBDA_JWT_ALGORITHM:-EdDSA}}"
228
+ svcPub="$(lambda_env "$fn" INTERNAL_JWT_PUBLIC_KEY)"; svcPub="${svcPub:-${LAMBDA_INTERNAL_JWT_PUBLIC_KEY:-}}"
229
+
204
230
  jq -n \
205
231
  --arg url "$url" --arg base "$base" --arg name "$name" \
206
232
  --arg table "$table" --arg backend "$backend" \
207
233
  --arg stage "$STAGE" --arg project "${PROJECT:-default}" --arg region "$AWS_REGION" \
208
- --arg jwtPub "${LAMBDA_JWT_PUBLIC_KEY:-}" --arg jwtIssuer "$issuer" \
209
- --arg jwtAlg "${LAMBDA_JWT_ALGORITHM:-EdDSA}" \
210
- --arg svcPub "${LAMBDA_INTERNAL_JWT_PUBLIC_KEY:-}" \
234
+ --arg jwtPub "$jwtPub" --arg jwtIssuer "$jwtIssuer" \
235
+ --arg jwtAlg "$jwtAlg" \
236
+ --arg svcPub "$svcPub" \
211
237
  --arg gwSystem "$(gateway_url_for system)" \
212
238
  --arg gwTenant "$(gateway_url_for tenant)" \
213
239
  --arg gwCustomer "$(gateway_url_for customer)" \
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@auth-craft/aws-cf-stack",
3
- "version": "1.0.1",
3
+ "version": "1.1.1",
4
4
  "description": "Self-contained, versioned distribution of the Auth Craft AWS (DynamoDB + Lambda) + Cloudflare gateway stack. Bundles prebuilt Lambda/worker artifacts + CDK app so consumers deploy without cloning auth-craft.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -16,17 +16,17 @@
16
16
  ".env.example"
17
17
  ],
18
18
  "dependencies": {
19
- "aws-cdk-lib": "^2.258.1",
19
+ "aws-cdk-lib": "^2.260.0",
20
20
  "constructs": "^10.6.0"
21
21
  },
22
22
  "devDependencies": {
23
- "@types/node": "^25.9.2",
23
+ "@types/node": "^25.9.3",
24
24
  "tsx": "^4.22.4",
25
25
  "typescript": "^6.0.3"
26
26
  },
27
27
  "peerDependencies": {
28
- "aws-cdk": "^2.1126.0",
29
- "wrangler": "^4.99.0"
28
+ "aws-cdk": "^2.1128.0",
29
+ "wrangler": "^4.101.0"
30
30
  },
31
31
  "peerDependenciesMeta": {
32
32
  "aws-cdk": {