mirror of
https://github.com/Sea-Haven-Industries/meal-order-manager.git
synced 2026-10-07 16:18:54 +00:00
Compare commits
6 commits
c25e371a72
...
aaa0e0e7f2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
aaa0e0e7f2 | ||
|
|
63b31fcdc3 | ||
|
|
449cc10b9f | ||
|
|
78f6d1dbe4 | ||
|
|
77780899c2 | ||
|
|
d7ad49d00f |
23 changed files with 915 additions and 40 deletions
3
.github/workflows/ci.yml
vendored
3
.github/workflows/ci.yml
vendored
|
|
@ -34,6 +34,9 @@ jobs:
|
|||
- name: Check template JavaScript
|
||||
run: npm run check:templates
|
||||
|
||||
- name: Lint OpenAPI
|
||||
run: npm run openapi:lint
|
||||
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 15
|
||||
|
|
|
|||
2
.github/workflows/deploy-api.yaml
vendored
2
.github/workflows/deploy-api.yaml
vendored
|
|
@ -123,7 +123,7 @@ jobs:
|
|||
echo "Building ${sha}"
|
||||
|
||||
- name: Configure AWS credentials using OIDC
|
||||
uses: aws-actions/configure-aws-credentials@cbe3b392738ccf3f987d68400dafcf4b0624a56c # v6.2.4
|
||||
uses: aws-actions/configure-aws-credentials@e1253824e5c10ff9df46874f81ed3ec929e19cfd # v6.3.0
|
||||
with:
|
||||
role-to-assume: ${{ env.DEPLOY_ROLE_ARN }}
|
||||
aws-region: us-east-1
|
||||
|
|
|
|||
2
.github/workflows/weekly-menu.yml
vendored
2
.github/workflows/weekly-menu.yml
vendored
|
|
@ -55,7 +55,7 @@ jobs:
|
|||
|
||||
- name: Configure AWS credentials
|
||||
if: env.SKIP_RUN != 'true'
|
||||
uses: aws-actions/configure-aws-credentials@cbe3b392738ccf3f987d68400dafcf4b0624a56c # v6.2.4
|
||||
uses: aws-actions/configure-aws-credentials@e1253824e5c10ff9df46874f81ed3ec929e19cfd # v6.3.0
|
||||
with:
|
||||
role-to-assume: ${{ secrets.AWS_WEEKLY_MENU_ROLE_ARN }}
|
||||
aws-region: us-east-1
|
||||
|
|
|
|||
32
.redocly.yaml
Normal file
32
.redocly.yaml
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
# Same Redocly recommended ruleset as internal-portal (DEV-223 / DEV-289).
|
||||
# Recommended operation-2xx-response does not count 302. Login-style redirects
|
||||
# succeed with 302, so that rule is replaced by operation-2xx-or-3xx-response
|
||||
# at error. operation-4xx-response is promoted to error so missing 4xx fails CI.
|
||||
extends:
|
||||
- recommended
|
||||
|
||||
rules:
|
||||
operation-2xx-response: off
|
||||
operation-4xx-response: error
|
||||
rule/operation-2xx-or-3xx-response:
|
||||
subject:
|
||||
type: Responses
|
||||
message: Operation must define a 2XX or 3XX response.
|
||||
severity: error
|
||||
assertions:
|
||||
requireAny:
|
||||
- "200"
|
||||
- "201"
|
||||
- "202"
|
||||
- "204"
|
||||
- "301"
|
||||
- "302"
|
||||
- "303"
|
||||
- "307"
|
||||
- "308"
|
||||
- "2XX"
|
||||
- "3XX"
|
||||
|
||||
apis:
|
||||
meals@v1:
|
||||
root: openapi.yaml
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
FROM python:3.12-slim
|
||||
FROM python:3.12-slim@sha256:2f17fc044b579bab302c2e8054d3a686e2cb9a83de48e70534b94cd8ebbe06a9
|
||||
|
||||
WORKDIR /app
|
||||
COPY src/shared/requirements.txt /tmp/shared-requirements.txt
|
||||
|
|
|
|||
|
|
@ -74,6 +74,8 @@ Publish routes are omitted from CloudFront. The generated form uses relative
|
|||
Workspace: `meal-order-manager-prod` / `meal-order-manager-dev` (us-east-1)
|
||||
|
||||
- **ECS Fargate** — Flask + gunicorn + SQS job consumer. Desired count 2 in prod, 1 in dev.
|
||||
- **VPC** — Prod attaches to the After Hours VPC (`existing_vpc_id` / `existing_public_subnet_ids` from afterhours-shift-manager outputs). The 10.60 CIDR is unused fallback.
|
||||
- **HTTP contract** — `openapi.yaml`, linted in CI with `npm run openapi:lint` (Redocly `extends: recommended`, same as internal-portal and afterhours-shift-manager).
|
||||
- **ALB** — origin for CloudFront `/api` behaviors and weekly-menu HMAC publish. Idle timeout 120s.
|
||||
- **ECR** — API image. GitHub Actions `deploy-api.yaml` owns the image; Terraform ignores `container_definitions`.
|
||||
- **S3** — `meal-order-manager-form-*` (static form hosting), `meal-order-manager-reports-*` (CSV reports + weekly summary PDF)
|
||||
|
|
@ -186,9 +188,11 @@ meal-order-manager/
|
|||
├── .github/workflows/
|
||||
│ ├── weekly-menu.yml # Monday cron: scrape + HMAC publish + notify
|
||||
│ ├── deploy-api.yaml # Image CD to Fargate
|
||||
│ ├── ci.yml # PR checks
|
||||
│ ├── ci.yml # PR checks (pytest, template JS, OpenAPI lint)
|
||||
│ └── ci-terraform.yaml # terraform fmt / validate
|
||||
├── terraform/ # HCP Terraform (cluster, ALB, ECR, jobs queue)
|
||||
├── openapi.yaml # Employee HTTP contract (Redocly recommended)
|
||||
├── .redocly.yaml
|
||||
├── Dockerfile
|
||||
├── src/
|
||||
│ ├── scraper/ # Playwright menu scraper
|
||||
|
|
|
|||
665
openapi.yaml
Normal file
665
openapi.yaml
Normal file
|
|
@ -0,0 +1,665 @@
|
|||
openapi: 3.1.0
|
||||
info:
|
||||
title: Meal Order Manager
|
||||
version: 0.1.0
|
||||
description: >
|
||||
Flask HTTP API on ECS Fargate behind orders.seahaven.com. The internal
|
||||
portal SPA calls menu, submit, and admin with a Cognito ID token from
|
||||
GET /api/auth/meals-token. Weekly-menu GitHub Actions uses HMAC publish
|
||||
routes that CloudFront does not expose. JSON errors are currently
|
||||
`{ error: string }`. Health matches the portal BFF `{ stage, sha }`.
|
||||
Lint with the same Redocly `extends: recommended` config as
|
||||
internal-portal and afterhours-shift-manager.
|
||||
contact:
|
||||
name: Sea Haven Engineering
|
||||
license:
|
||||
name: Proprietary
|
||||
identifier: LicenseRef-SeaHaven
|
||||
|
||||
servers:
|
||||
- url: /
|
||||
description: orders.seahaven.com CloudFront / local Flask :5050
|
||||
|
||||
tags:
|
||||
- name: Runtime
|
||||
description: Unauthenticated health
|
||||
- name: Menu
|
||||
description: Public weekly menu and form status
|
||||
- name: Orders
|
||||
description: Employee submit and own-order lookup
|
||||
- name: Admin
|
||||
description: Admin order edit and summary PDF
|
||||
- name: Publish
|
||||
description: Weekly-menu HMAC publish (not on CloudFront)
|
||||
|
||||
paths:
|
||||
/api/health:
|
||||
get:
|
||||
operationId: getHealth
|
||||
tags: [Runtime]
|
||||
summary: Runtime health
|
||||
security: []
|
||||
responses:
|
||||
"200":
|
||||
description: Process is up
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/Health"
|
||||
"403":
|
||||
$ref: "#/components/responses/StringError"
|
||||
|
||||
/api/menu/{week}:
|
||||
get:
|
||||
operationId: getMenu
|
||||
tags: [Menu]
|
||||
summary: Published menu for a week
|
||||
security: []
|
||||
parameters:
|
||||
- $ref: "#/components/parameters/MenuWeekPath"
|
||||
responses:
|
||||
"200":
|
||||
description: Menu payload
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/MenuPayload"
|
||||
"400":
|
||||
$ref: "#/components/responses/StringError"
|
||||
"404":
|
||||
$ref: "#/components/responses/StringError"
|
||||
|
||||
/api/form-status/{week}:
|
||||
get:
|
||||
operationId: getFormStatus
|
||||
tags: [Menu]
|
||||
summary: Open or closed for a week
|
||||
security: []
|
||||
parameters:
|
||||
- $ref: "#/components/parameters/MenuWeekPath"
|
||||
responses:
|
||||
"200":
|
||||
description: Form status
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/FormStatus"
|
||||
"400":
|
||||
$ref: "#/components/responses/StringError"
|
||||
|
||||
/api/submit-order:
|
||||
post:
|
||||
operationId: submitOrder
|
||||
tags: [Orders]
|
||||
summary: Place or replace this week's order
|
||||
security:
|
||||
- portalCognito: []
|
||||
requestBody:
|
||||
required: true
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/SubmitBody"
|
||||
responses:
|
||||
"200":
|
||||
description: Order saved
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/SubmitResult"
|
||||
"400":
|
||||
$ref: "#/components/responses/StringError"
|
||||
"403":
|
||||
$ref: "#/components/responses/StringError"
|
||||
"404":
|
||||
$ref: "#/components/responses/StringError"
|
||||
"410":
|
||||
$ref: "#/components/responses/StringError"
|
||||
"429":
|
||||
$ref: "#/components/responses/StringError"
|
||||
"503":
|
||||
$ref: "#/components/responses/StringError"
|
||||
|
||||
/api/orders/{week}:
|
||||
get:
|
||||
operationId: getMyOrder
|
||||
tags: [Orders]
|
||||
summary: Caller's order only
|
||||
security:
|
||||
- portalCognito: []
|
||||
parameters:
|
||||
- $ref: "#/components/parameters/OrderWeekPath"
|
||||
responses:
|
||||
"200":
|
||||
description: Empty list when the caller has no order
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/MyOrders"
|
||||
"400":
|
||||
$ref: "#/components/responses/StringError"
|
||||
"403":
|
||||
$ref: "#/components/responses/StringError"
|
||||
"503":
|
||||
$ref: "#/components/responses/StringError"
|
||||
|
||||
/api/admin/orders:
|
||||
get:
|
||||
operationId: adminListOrders
|
||||
tags: [Admin]
|
||||
summary: List weeks or one week's orders
|
||||
security:
|
||||
- portalCognito: []
|
||||
parameters:
|
||||
- name: week
|
||||
in: query
|
||||
schema:
|
||||
type: string
|
||||
responses:
|
||||
"200":
|
||||
description: Weeks list or week detail
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/AdminOrdersResponse"
|
||||
"403":
|
||||
$ref: "#/components/responses/StringError"
|
||||
put:
|
||||
operationId: adminUpdateOrder
|
||||
tags: [Admin]
|
||||
summary: Recalculate and replace an order
|
||||
security:
|
||||
- portalCognito: []
|
||||
requestBody:
|
||||
required: true
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/AdminUpdateBody"
|
||||
responses:
|
||||
"200":
|
||||
description: Updated
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/AdminMutation"
|
||||
"400":
|
||||
$ref: "#/components/responses/StringError"
|
||||
"403":
|
||||
$ref: "#/components/responses/StringError"
|
||||
"404":
|
||||
$ref: "#/components/responses/StringError"
|
||||
"503":
|
||||
$ref: "#/components/responses/StringError"
|
||||
delete:
|
||||
operationId: adminDeleteOrder
|
||||
tags: [Admin]
|
||||
summary: Delete an order
|
||||
security:
|
||||
- portalCognito: []
|
||||
parameters:
|
||||
- name: week
|
||||
in: query
|
||||
required: true
|
||||
schema:
|
||||
type: string
|
||||
- name: email
|
||||
in: query
|
||||
required: true
|
||||
schema:
|
||||
type: string
|
||||
responses:
|
||||
"200":
|
||||
description: Deleted
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/AdminMutation"
|
||||
"400":
|
||||
$ref: "#/components/responses/StringError"
|
||||
"403":
|
||||
$ref: "#/components/responses/StringError"
|
||||
"404":
|
||||
$ref: "#/components/responses/StringError"
|
||||
|
||||
/api/admin/summary-pdf:
|
||||
get:
|
||||
operationId: adminSummaryPdf
|
||||
tags: [Admin]
|
||||
summary: Presigned summary PDF URL
|
||||
security:
|
||||
- portalCognito: []
|
||||
parameters:
|
||||
- name: week
|
||||
in: query
|
||||
required: true
|
||||
schema:
|
||||
type: string
|
||||
responses:
|
||||
"200":
|
||||
description: Short-lived URL
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/SummaryPdf"
|
||||
"400":
|
||||
$ref: "#/components/responses/StringError"
|
||||
"403":
|
||||
$ref: "#/components/responses/StringError"
|
||||
"404":
|
||||
$ref: "#/components/responses/StringError"
|
||||
"500":
|
||||
$ref: "#/components/responses/StringError"
|
||||
|
||||
/api/roster:
|
||||
get:
|
||||
operationId: getRoster
|
||||
tags: [Orders]
|
||||
summary: Name and email list used by the static form
|
||||
security: []
|
||||
responses:
|
||||
"200":
|
||||
description: Roster
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/FormRoster"
|
||||
"403":
|
||||
$ref: "#/components/responses/StringError"
|
||||
|
||||
/api/publish/settings:
|
||||
get:
|
||||
operationId: publishSettings
|
||||
tags: [Publish]
|
||||
summary: Bulk discount and subsidy for scrape
|
||||
security:
|
||||
- publishKey: []
|
||||
responses:
|
||||
"200":
|
||||
description: Pricing fields only
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/PublishSettings"
|
||||
"403":
|
||||
$ref: "#/components/responses/StringError"
|
||||
|
||||
/api/publish/menu:
|
||||
post:
|
||||
operationId: publishMenu
|
||||
tags: [Publish]
|
||||
summary: Write this week's scraped menu
|
||||
security:
|
||||
- publishKey: []
|
||||
requestBody:
|
||||
required: true
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/PublishMenuBody"
|
||||
responses:
|
||||
"200":
|
||||
description: Published
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/PublishMenuResult"
|
||||
"400":
|
||||
$ref: "#/components/responses/StringError"
|
||||
"403":
|
||||
$ref: "#/components/responses/StringError"
|
||||
|
||||
components:
|
||||
securitySchemes:
|
||||
portalCognito:
|
||||
type: http
|
||||
scheme: bearer
|
||||
bearerFormat: JWT
|
||||
description: Portal Cognito ID token. GIS google_id_token is also accepted on submit until cutover.
|
||||
publishKey:
|
||||
type: apiKey
|
||||
in: header
|
||||
name: X-Meals-Publish-Key
|
||||
|
||||
parameters:
|
||||
MenuWeekPath:
|
||||
name: week
|
||||
in: path
|
||||
required: true
|
||||
description: "`current` or `YYYY-WNN`. Other values are 400."
|
||||
schema:
|
||||
type: string
|
||||
minLength: 1
|
||||
OrderWeekPath:
|
||||
name: week
|
||||
in: path
|
||||
required: true
|
||||
description: "`YYYY-WNN` or `YYYY-MM-DD`. `current` is 400."
|
||||
schema:
|
||||
type: string
|
||||
minLength: 1
|
||||
|
||||
responses:
|
||||
StringError:
|
||||
description: Current meals JSON error
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/StringErrorBody"
|
||||
|
||||
schemas:
|
||||
Health:
|
||||
type: object
|
||||
additionalProperties: false
|
||||
required: [stage, sha]
|
||||
properties:
|
||||
stage:
|
||||
type: string
|
||||
minLength: 1
|
||||
description: Workspace stage (`dev`, `prod`, or `local`)
|
||||
sha:
|
||||
type: string
|
||||
minLength: 1
|
||||
description: Git SHA or `unknown` locally
|
||||
|
||||
StringErrorBody:
|
||||
type: object
|
||||
additionalProperties: false
|
||||
required: [error]
|
||||
properties:
|
||||
error:
|
||||
type: string
|
||||
minLength: 1
|
||||
|
||||
Meal:
|
||||
type: object
|
||||
additionalProperties: true
|
||||
required: [name, price]
|
||||
properties:
|
||||
name:
|
||||
type: string
|
||||
price:
|
||||
type: number
|
||||
calories:
|
||||
type: [string, number, "null"]
|
||||
protein:
|
||||
type: [string, number, "null"]
|
||||
description:
|
||||
type: [string, "null"]
|
||||
dietary_tags:
|
||||
type: [array, "null"]
|
||||
items:
|
||||
type: string
|
||||
image_url:
|
||||
type: [string, "null"]
|
||||
is_new:
|
||||
type: boolean
|
||||
|
||||
MenuPayload:
|
||||
type: object
|
||||
additionalProperties: false
|
||||
required:
|
||||
- week
|
||||
- form_status
|
||||
- meal_count
|
||||
- meals
|
||||
- bulk_discount_percent
|
||||
- company_subsidy_percent
|
||||
properties:
|
||||
week:
|
||||
type: string
|
||||
form_status:
|
||||
type: string
|
||||
scraped_at:
|
||||
type: [string, "null"]
|
||||
menu_url:
|
||||
type: [string, "null"]
|
||||
meal_count:
|
||||
type: integer
|
||||
meals:
|
||||
type: array
|
||||
items:
|
||||
$ref: "#/components/schemas/Meal"
|
||||
bulk_discount_percent:
|
||||
type: number
|
||||
company_subsidy_percent:
|
||||
type: number
|
||||
order_deadline:
|
||||
type: string
|
||||
|
||||
FormStatus:
|
||||
type: object
|
||||
additionalProperties: false
|
||||
required: [week, status]
|
||||
properties:
|
||||
week:
|
||||
type: string
|
||||
status:
|
||||
type: string
|
||||
reopen_at:
|
||||
type: integer
|
||||
|
||||
SubmitItem:
|
||||
type: object
|
||||
additionalProperties: true
|
||||
required: [name, quantity]
|
||||
properties:
|
||||
name:
|
||||
type: string
|
||||
quantity:
|
||||
type: number
|
||||
retail_price:
|
||||
type: number
|
||||
|
||||
SubmitBody:
|
||||
type: object
|
||||
additionalProperties: true
|
||||
required: [items]
|
||||
properties:
|
||||
items:
|
||||
type: array
|
||||
items:
|
||||
$ref: "#/components/schemas/SubmitItem"
|
||||
google_id_token:
|
||||
type: string
|
||||
|
||||
SubmitResult:
|
||||
type: object
|
||||
additionalProperties: false
|
||||
required: [status]
|
||||
properties:
|
||||
status:
|
||||
type: string
|
||||
message:
|
||||
type: string
|
||||
total:
|
||||
type: number
|
||||
|
||||
MyOrders:
|
||||
type: object
|
||||
additionalProperties: false
|
||||
required: [week, orders]
|
||||
properties:
|
||||
week:
|
||||
type: string
|
||||
orders:
|
||||
type: array
|
||||
items:
|
||||
type: object
|
||||
additionalProperties: false
|
||||
required: [employee_email]
|
||||
properties:
|
||||
employee_email:
|
||||
type: string
|
||||
|
||||
AdminWeek:
|
||||
type: object
|
||||
additionalProperties: true
|
||||
required: [week]
|
||||
properties:
|
||||
week:
|
||||
type: string
|
||||
form_status:
|
||||
type: string
|
||||
meal_count:
|
||||
type: integer
|
||||
order_count:
|
||||
type: integer
|
||||
|
||||
AdminOrderItem:
|
||||
type: object
|
||||
additionalProperties: false
|
||||
required: [name, quantity, retail_price, price, subtotal]
|
||||
properties:
|
||||
name:
|
||||
type: string
|
||||
quantity:
|
||||
type: integer
|
||||
retail_price:
|
||||
type: number
|
||||
price:
|
||||
type: number
|
||||
subtotal:
|
||||
type: number
|
||||
|
||||
AdminOrder:
|
||||
type: object
|
||||
additionalProperties: false
|
||||
required: [employee_name, employee_email, items, total, submitted_at]
|
||||
properties:
|
||||
employee_name:
|
||||
type: string
|
||||
employee_email:
|
||||
type: string
|
||||
items:
|
||||
type: array
|
||||
items:
|
||||
$ref: "#/components/schemas/AdminOrderItem"
|
||||
total:
|
||||
type: number
|
||||
submitted_at:
|
||||
type: string
|
||||
|
||||
AdminWeeks:
|
||||
type: object
|
||||
additionalProperties: false
|
||||
required: [weeks]
|
||||
properties:
|
||||
weeks:
|
||||
type: array
|
||||
items:
|
||||
$ref: "#/components/schemas/AdminWeek"
|
||||
|
||||
AdminWeekOrders:
|
||||
type: object
|
||||
additionalProperties: false
|
||||
required: [week, orders, total_employees, grand_total]
|
||||
properties:
|
||||
week:
|
||||
type: string
|
||||
orders:
|
||||
type: array
|
||||
items:
|
||||
$ref: "#/components/schemas/AdminOrder"
|
||||
total_employees:
|
||||
type: integer
|
||||
grand_total:
|
||||
type: number
|
||||
|
||||
AdminOrdersResponse:
|
||||
oneOf:
|
||||
- $ref: "#/components/schemas/AdminWeeks"
|
||||
- $ref: "#/components/schemas/AdminWeekOrders"
|
||||
|
||||
AdminUpdateBody:
|
||||
type: object
|
||||
additionalProperties: false
|
||||
required: [week, email, items]
|
||||
properties:
|
||||
week:
|
||||
type: string
|
||||
email:
|
||||
type: string
|
||||
items:
|
||||
type: array
|
||||
items:
|
||||
$ref: "#/components/schemas/SubmitItem"
|
||||
|
||||
AdminMutation:
|
||||
type: object
|
||||
additionalProperties: false
|
||||
required: [status, week]
|
||||
properties:
|
||||
status:
|
||||
type: string
|
||||
week:
|
||||
type: string
|
||||
email:
|
||||
type: string
|
||||
total:
|
||||
type: number
|
||||
|
||||
SummaryPdf:
|
||||
type: object
|
||||
additionalProperties: false
|
||||
required: [week, url]
|
||||
properties:
|
||||
week:
|
||||
type: string
|
||||
url:
|
||||
type: string
|
||||
format: uri
|
||||
|
||||
FormRoster:
|
||||
type: object
|
||||
additionalProperties: false
|
||||
required: [employees]
|
||||
properties:
|
||||
employees:
|
||||
type: array
|
||||
items:
|
||||
type: object
|
||||
additionalProperties: false
|
||||
required: [name, email]
|
||||
properties:
|
||||
name:
|
||||
type: string
|
||||
email:
|
||||
type: string
|
||||
|
||||
PublishSettings:
|
||||
type: object
|
||||
additionalProperties: false
|
||||
required: [bulk_discount_percent, company_subsidy_percent]
|
||||
properties:
|
||||
bulk_discount_percent:
|
||||
type: number
|
||||
company_subsidy_percent:
|
||||
type: number
|
||||
|
||||
PublishMenuBody:
|
||||
type: object
|
||||
additionalProperties: true
|
||||
required: [meals]
|
||||
properties:
|
||||
meals:
|
||||
type: array
|
||||
minItems: 1
|
||||
items:
|
||||
$ref: "#/components/schemas/Meal"
|
||||
scraped_at:
|
||||
type: string
|
||||
menu_url:
|
||||
type: string
|
||||
|
||||
PublishMenuResult:
|
||||
type: object
|
||||
additionalProperties: false
|
||||
required: [status, week, meal_count]
|
||||
properties:
|
||||
status:
|
||||
type: string
|
||||
week:
|
||||
type: string
|
||||
meal_count:
|
||||
type: integer
|
||||
16
package-lock.json
generated
16
package-lock.json
generated
|
|
@ -9,6 +9,7 @@
|
|||
"version": "1.0.0",
|
||||
"devDependencies": {
|
||||
"@eslint/js": "10.0.1",
|
||||
"@redocly/cli": "2.52.1",
|
||||
"eslint": "10.10.0",
|
||||
"globals": "17.12.0",
|
||||
"prettier": "3.9.8"
|
||||
|
|
@ -256,6 +257,21 @@
|
|||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@redocly/cli": {
|
||||
"version": "2.52.1",
|
||||
"resolved": "https://registry.npmjs.org/@redocly/cli/-/cli-2.52.1.tgz",
|
||||
"integrity": "sha512-gwfx1WelVDHU/cw+GkpLV9+xksOI3obJGgL1nUVrAFUyXNDxM+aifXDUZk7BfbOIpF69Sea2ant0cOqbQfg/KQ==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"bin": {
|
||||
"openapi": "bin/cli.js",
|
||||
"redocly": "bin/cli.js"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=22.12.0 || >=20.19.0 <21.0.0",
|
||||
"npm": ">=10"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/esrecurse": {
|
||||
"version": "4.3.1",
|
||||
"resolved": "https://registry.npmjs.org/@types/esrecurse/-/esrecurse-4.3.1.tgz",
|
||||
|
|
|
|||
|
|
@ -6,10 +6,12 @@
|
|||
"check:templates": "npm run lint:templates && npm run format:templates",
|
||||
"format:templates": "prettier --check \"src/server/templates/*.js\"",
|
||||
"format:templates:write": "prettier --write \"src/server/templates/*.js\"",
|
||||
"lint:templates": "eslint \"src/server/templates/*.js\""
|
||||
"lint:templates": "eslint \"src/server/templates/*.js\"",
|
||||
"openapi:lint": "redocly lint --config .redocly.yaml openapi.yaml"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@eslint/js": "10.0.1",
|
||||
"@redocly/cli": "2.52.1",
|
||||
"eslint": "10.10.0",
|
||||
"globals": "17.12.0",
|
||||
"prettier": "3.9.8"
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
flask==3.1.3
|
||||
gunicorn==23.0.0
|
||||
boto3==1.43.97
|
||||
gunicorn==26.2.0
|
||||
boto3==1.43.98
|
||||
sentry-sdk==2.69.2
|
||||
jinja2==3.1.6
|
||||
fpdf2==2.8.8
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
playwright==1.63.0
|
||||
flask==3.1.3
|
||||
boto3==1.43.97
|
||||
boto3==1.43.98
|
||||
jinja2==3.1.6
|
||||
|
|
|
|||
|
|
@ -279,15 +279,20 @@ def lambda_handler(event, context):
|
|||
return response(405, {"error": "Method not allowed"})
|
||||
|
||||
|
||||
def handle_menu(event):
|
||||
"""Return the published menu in the portal's public MenuPayload shape."""
|
||||
def _week_from_path(event):
|
||||
requested_week = (event.get("pathParameters") or {}).get("week", "")
|
||||
if requested_week == "current":
|
||||
week = current_week()
|
||||
elif re.fullmatch(r"\d{4}-W\d{2}", requested_week):
|
||||
week = requested_week
|
||||
else:
|
||||
return response(400, {"error": "week path param must be current or YYYY-WNN"})
|
||||
return current_week(), None
|
||||
if re.fullmatch(r"\d{4}-W\d{2}", requested_week):
|
||||
return requested_week, None
|
||||
return None, response(400, {"error": "week path param must be current or YYYY-WNN"})
|
||||
|
||||
|
||||
def handle_menu(event):
|
||||
"""Return the published menu in the portal's public MenuPayload shape."""
|
||||
week, error = _week_from_path(event)
|
||||
if error is not None:
|
||||
return error
|
||||
|
||||
menu = get_menu(week)
|
||||
if menu is None:
|
||||
|
|
@ -623,7 +628,9 @@ def handle_my_orders(event):
|
|||
|
||||
|
||||
def handle_form_status(event):
|
||||
week = event.get("pathParameters", {}).get("week", current_week())
|
||||
week, error = _week_from_path(event)
|
||||
if error is not None:
|
||||
return error
|
||||
status = get_form_status(week)
|
||||
result = {"week": week, "status": status}
|
||||
if status == "closed":
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
boto3==1.43.97
|
||||
boto3==1.43.98
|
||||
fpdf2==2.8.8
|
||||
PyJWT[crypto]==2.14.0
|
||||
|
|
|
|||
42
terraform/.terraform.lock.hcl
generated
42
terraform/.terraform.lock.hcl
generated
|
|
@ -40,23 +40,33 @@ provider "registry.terraform.io/hashicorp/aws" {
|
|||
}
|
||||
|
||||
provider "registry.terraform.io/hashicorp/random" {
|
||||
version = "3.8.1"
|
||||
constraints = "3.8.1"
|
||||
version = "3.9.1"
|
||||
constraints = "3.9.1"
|
||||
hashes = [
|
||||
"h1:Eexl06+6J+s75uD46+WnZtpJZYRVUMB0AiuPBifK6Jc=",
|
||||
"h1:fdfOl1HabDT42XLH8qjmfTbVZpgQZ5lyOyOa+GQhm0w=",
|
||||
"h1:u8AKlWVDTH5r9YLSeswoVEjiY72Rt4/ch7U+61ZDkiQ=",
|
||||
"zh:08dd03b918c7b55713026037c5400c48af5b9f468f483463321bd18e17b907b4",
|
||||
"zh:0eee654a5542dc1d41920bbf2419032d6f0d5625b03bd81339e5b33394a3e0ae",
|
||||
"zh:229665ddf060aa0ed315597908483eee5b818a17d09b6417a0f52fd9405c4f57",
|
||||
"zh:2469d2e48f28076254a2a3fc327f184914566d9e40c5780b8d96ebf7205f8bc0",
|
||||
"zh:37d7eb334d9561f335e748280f5535a384a88675af9a9eac439d4cfd663bcb66",
|
||||
"zh:741101426a2f2c52dee37122f0f4a2f2d6af6d852cb1db634480a86398fa3511",
|
||||
"h1:0rmWNCsP90oLS9KtLiqcNmkRzsaOZD95THXyuGYUfOM=",
|
||||
"h1:4AN630toDK+4Is2MQcbGA37yR56nIEDPO0qv8ivZD2M=",
|
||||
"h1:7uiStw0Rl9KOdX5UNMG/sp9nyadoD4LZekQTiYlYPhE=",
|
||||
"h1:9RiO3l/4iDguiVMryazTvf8ZAOAwbS0LPWl/XRo2El4=",
|
||||
"h1:AjDEYpTXfyc3CupsrJYjgxCYnqxdpCLPkaLKPiw9WTA=",
|
||||
"h1:PYbnOqRuGn4c0/Ae1f7yOS/0zvmXNHFJRZjuF4KECnM=",
|
||||
"h1:PlW+UZ4EElQF3NQwf41KQwavFujab3Czc51zu9dyVM8=",
|
||||
"h1:VGeIpAn+nL6i8a6Y1W7XIq+Z6XFIWu5al4f2PNageoo=",
|
||||
"h1:g40qr7yDmIpaur4SsK5BcOda3HSo1RJ6zHVMqN4EJ+0=",
|
||||
"h1:nozfr4CZq73d4HjubKJundX/8A+Mj282oS/hyNfjUPU=",
|
||||
"h1:uFgaD8lhFrHzFm88V3/+wypq5AzCUdzXR60vLSlZ2cI=",
|
||||
"h1:xxRd4yd9LvPiDqeiGQj7FhZHwD08tDcIToAAePfoahE=",
|
||||
"zh:05f4734c1f0be840b711b3eff259ebc5fca436784c728955b1678078466f48d7",
|
||||
"zh:0b91bf19371d012434eba1deeb6aab77158def9b39601dcbd94450b3974a2a26",
|
||||
"zh:0ee6eacd47ec00183d55d726a4b6c4ce951a199f944bf22f1aa58392ebdfa7a2",
|
||||
"zh:19388a4074b76a89a43a6c8328d7ae8ee2e7de3d346af51e80d3e6d3d12925f1",
|
||||
"zh:23e74d48c5e2ac2e823fd527f49fee9db37d32a1990c9e3bf126ead697b843eb",
|
||||
"zh:3cabf7fbd096c520064aae3aba61aba670af83ab91291a71fa1b1332929c2b7f",
|
||||
"zh:5c0a3b8af0be60be4eca12ddee385cfa8babc1ec8e98cdf9de2f2274c73eabfa",
|
||||
"zh:60b4f8a8ef18f52bf8e19215229dae408bee732825964092db7c989fd2de4097",
|
||||
"zh:7359015acfedcbd6366f2329c854cf8d3c8ca5cd0faa89d2d37db358d6eba6c5",
|
||||
"zh:78d5eefdd9e494defcb3c68d282b8f96630502cac21d1ea161f53cfe9bb483b3",
|
||||
"zh:a902473f08ef8df62cfe6116bd6c157070a93f66622384300de235a533e9d4a9",
|
||||
"zh:b85c511a23e57a2147355932b3b6dce2a11e856b941165793a0c3d7578d94d05",
|
||||
"zh:c5172226d18eaac95b1daac80172287b69d4ce32750c82ad77fa0768be4ea4b8",
|
||||
"zh:dab4434dba34aad569b0bc243c2d3f3ff86dd7740def373f2a49816bd2ff819b",
|
||||
"zh:f49fd62aa8c5525a5c17abd51e27ca5e213881d58882fd42fec4a545b53c9699",
|
||||
"zh:7b38758402f0e13a1071162da28994023cd2ac676e54af350c9ffd8dfa73fa7b",
|
||||
"zh:7c7fbb8895eb75bb4de1f933e98553bd99c8d048c89a925ddba490aa5a67f7dc",
|
||||
"zh:8c2b8c6a7ccdec16b73e2fb9f3700ea097f58c592571e4c5de60c93d2301732c",
|
||||
]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -69,6 +69,13 @@ check "dev_has_no_custom_domain" {
|
|||
}
|
||||
}
|
||||
|
||||
check "prod_reuses_afterhours_vpc" {
|
||||
assert {
|
||||
condition = !local.is_prod || var.existing_vpc_id != ""
|
||||
error_message = "Prod must set existing_vpc_id to the afterhours VPC. Do not mint 10.60."
|
||||
}
|
||||
}
|
||||
|
||||
check "existing_vpc_pair" {
|
||||
assert {
|
||||
condition = (var.existing_vpc_id == "") == (length(var.existing_public_subnet_ids) == 0)
|
||||
|
|
|
|||
|
|
@ -7,8 +7,9 @@ locals {
|
|||
|
||||
github_oidc_provider_arn = "arn:aws:iam::${local.account_id}:oidc-provider/token.actions.githubusercontent.com"
|
||||
|
||||
# Created only when existing_vpc_id is empty. 10.60 is unused in 011934824531.
|
||||
manage_vpc = var.existing_vpc_id == ""
|
||||
# Created only when existing_vpc_id is empty. Prod attaches to afterhours 10.70.
|
||||
# 10.60 is the unused fallback CIDR, not a second prod VPC.
|
||||
manage_vpc = var.existing_vpc_id == "" && !local.is_prod
|
||||
vpc_cidr = "10.60.0.0/16"
|
||||
public_subnet_cidrs = ["10.60.0.0/24", "10.60.1.0/24"]
|
||||
|
||||
|
|
|
|||
|
|
@ -57,3 +57,13 @@ output "ecs_task_role_arn" {
|
|||
description = "ECS task role; paychex-checkcomponents queue policy must allow this ARN."
|
||||
value = aws_iam_role.ecs_task.arn
|
||||
}
|
||||
|
||||
output "vpc_id" {
|
||||
description = "VPC the ALB and Fargate tasks run in. Prod attaches to afterhours."
|
||||
value = local.vpc_id
|
||||
}
|
||||
|
||||
output "public_subnet_ids" {
|
||||
description = "Public subnet IDs for the ALB and Fargate tasks."
|
||||
value = local.public_subnet_ids
|
||||
}
|
||||
|
|
|
|||
|
|
@ -93,7 +93,7 @@ variable "checkcomponents_queue_arn" {
|
|||
}
|
||||
|
||||
variable "existing_vpc_id" {
|
||||
description = "When set, place the ALB and Fargate tasks in this VPC instead of creating one."
|
||||
description = "When set, place the ALB and Fargate tasks in this VPC instead of creating one. Prod attaches to the afterhours VPC."
|
||||
type = string
|
||||
default = ""
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ terraform {
|
|||
}
|
||||
random = {
|
||||
source = "hashicorp/random"
|
||||
version = "3.8.1"
|
||||
version = "3.9.1"
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ data "aws_availability_zones" "available" {
|
|||
}
|
||||
|
||||
data "aws_vpc" "existing" {
|
||||
count = local.manage_vpc ? 0 : 1
|
||||
count = var.existing_vpc_id == "" ? 0 : 1
|
||||
id = var.existing_vpc_id
|
||||
}
|
||||
|
||||
|
|
@ -13,6 +13,17 @@ data "aws_subnet" "existing_public" {
|
|||
id = each.value
|
||||
}
|
||||
|
||||
resource "terraform_data" "prod_requires_afterhours_vpc" {
|
||||
input = var.existing_vpc_id
|
||||
|
||||
lifecycle {
|
||||
precondition {
|
||||
condition = !local.is_prod || var.existing_vpc_id != ""
|
||||
error_message = "Prod must set existing_vpc_id to the afterhours VPC. Do not mint 10.60."
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_vpc" "this" {
|
||||
count = local.manage_vpc ? 1 : 0
|
||||
|
||||
|
|
@ -24,6 +35,13 @@ resource "aws_vpc" "this" {
|
|||
Name = "${local.project}-vpc"
|
||||
}
|
||||
|
||||
lifecycle {
|
||||
precondition {
|
||||
condition = !local.is_prod
|
||||
error_message = "Prod must set existing_vpc_id to the afterhours VPC. Do not mint 10.60."
|
||||
}
|
||||
}
|
||||
|
||||
# First apply updates the live hcptf apply role before CreateVpc.
|
||||
depends_on = [
|
||||
aws_iam_role_policy_attachments_exclusive.hcptf_apply,
|
||||
|
|
@ -80,7 +98,7 @@ resource "aws_route_table_association" "public" {
|
|||
}
|
||||
|
||||
locals {
|
||||
vpc_id = local.manage_vpc ? aws_vpc.this[0].id : data.aws_vpc.existing[0].id
|
||||
vpc_id = local.manage_vpc ? aws_vpc.this[0].id : try(data.aws_vpc.existing[0].id, var.existing_vpc_id)
|
||||
public_subnet_ids = local.manage_vpc ? aws_subnet.public[*].id : var.existing_public_subnet_ids
|
||||
}
|
||||
|
||||
|
|
|
|||
45
tests/test_openapi_contract.py
Normal file
45
tests/test_openapi_contract.py
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
"""OpenAPI 3.1 + Redocly recommended, matching internal-portal (DEV-289)."""
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
|
||||
|
||||
def test_openapi_uses_redocly_recommended():
|
||||
redocly = (ROOT / ".redocly.yaml").read_text()
|
||||
package = (ROOT / "package.json").read_text()
|
||||
spec = (ROOT / "openapi.yaml").read_text()
|
||||
ci = (ROOT / ".github" / "workflows" / "ci.yml").read_text()
|
||||
assert "extends:" in redocly
|
||||
assert "- recommended" in redocly
|
||||
assert "operation-2xx-response: off" in redocly
|
||||
assert "operation-4xx-response: error" in redocly
|
||||
assert "rule/operation-2xx-or-3xx-response" in redocly
|
||||
assert "severity: error" in redocly
|
||||
health = spec.split("/api/health:", 1)[1].split("\n /", 1)[0]
|
||||
assert '"403":' in health
|
||||
assert '"400":' not in health
|
||||
roster = spec.split("/api/roster:", 1)[1].split("\n /", 1)[0]
|
||||
assert '"403":' in roster
|
||||
assert '"400":' not in roster
|
||||
form_status = spec.split("/api/form-status/{week}:", 1)[1].split("\n /", 1)[0]
|
||||
assert '"400":' in form_status
|
||||
menu = spec.split("/api/menu/{week}:", 1)[1].split("\n /", 1)[0]
|
||||
orders = spec.split("/api/orders/{week}:", 1)[1].split("\n /", 1)[0]
|
||||
assert "MenuWeekPath" in menu
|
||||
assert "MenuWeekPath" in form_status
|
||||
assert "OrderWeekPath" in orders
|
||||
assert "WeekPath" not in spec.split("components:", 1)[1].split("MenuWeekPath", 1)[0]
|
||||
assert "`current` or `YYYY-WNN`" in spec
|
||||
assert "`YYYY-WNN` or `YYYY-MM-DD`" in spec
|
||||
meal = spec.split(" Meal:", 1)[1].split("\n MenuPayload:", 1)[0]
|
||||
assert 'type: [string, number, "null"]' in meal
|
||||
assert 'type: [string, "null"]' in meal
|
||||
assert 'menu_url:\n type: [string, "null"]' in spec
|
||||
assert "root: openapi.yaml" in redocly
|
||||
assert '"openapi:lint"' in package
|
||||
assert '"@redocly/cli": "2.52.1"' in package
|
||||
assert "npm run openapi:lint" in ci
|
||||
assert "openapi: 3.1.0" in spec
|
||||
assert "required: [stage, sha]" in spec
|
||||
assert "{ error: string }" in spec or "`{ error: string }`" in spec
|
||||
|
|
@ -1446,6 +1446,33 @@ def test_form_status_open(mock_week, mock_status):
|
|||
assert "reopen_at" not in body, "reopen_at should NOT be present when form is open"
|
||||
|
||||
|
||||
@patch("submit_order_handler.get_form_status", return_value="open")
|
||||
@patch("submit_order_handler.current_week", return_value="2026-W20")
|
||||
def test_form_status_current_maps_to_current_week(mock_week, mock_status):
|
||||
from submit_order_handler import lambda_handler
|
||||
|
||||
event = _make_event(
|
||||
method="GET", path="/form-status/current", path_parameters={"week": "current"}
|
||||
)
|
||||
status, body = _parse_response(lambda_handler(event, None))
|
||||
assert status == 200, f"Expected 200, got {status}: {body}"
|
||||
assert body["week"] == "2026-W20"
|
||||
mock_status.assert_called_once_with("2026-W20")
|
||||
|
||||
|
||||
@patch("submit_order_handler.get_form_status")
|
||||
def test_form_status_rejects_invalid_week(mock_status):
|
||||
from submit_order_handler import lambda_handler
|
||||
|
||||
event = _make_event(
|
||||
method="GET", path="/form-status/nope", path_parameters={"week": "nope"}
|
||||
)
|
||||
status, body = _parse_response(lambda_handler(event, None))
|
||||
assert status == 400, f"Expected 400, got {status}: {body}"
|
||||
assert "week path param" in body["error"]
|
||||
mock_status.assert_not_called()
|
||||
|
||||
|
||||
@patch("submit_order_handler.get_form_status", return_value="closed")
|
||||
@patch("submit_order_handler.current_week", return_value="2026-W20")
|
||||
def test_form_status_closed_reopen_at(mock_week, mock_status):
|
||||
|
|
@ -2137,6 +2164,24 @@ def test_my_orders_empty_when_none(mock_looks_like, mock_portal, mock_get):
|
|||
assert body == {"week": "2026-W36", "orders": []}
|
||||
|
||||
|
||||
@patch("submit_order_handler.get_order")
|
||||
@patch(
|
||||
"submit_order_handler._verify_portal_token",
|
||||
return_value={
|
||||
"name": "Portal Employee",
|
||||
"email": "portal.employee@seahavenind.com",
|
||||
},
|
||||
)
|
||||
@patch("submit_order_handler.looks_like_cognito_token", return_value=True)
|
||||
def test_my_orders_rejects_current_week(mock_looks_like, mock_portal, mock_get):
|
||||
status, body = _parse_response(
|
||||
submit_order_handler.lambda_handler(_orders_event(week="current"), None)
|
||||
)
|
||||
assert status == 400
|
||||
assert "YYYY-WNN" in body["error"]
|
||||
mock_get.assert_not_called()
|
||||
|
||||
|
||||
def test_my_orders_requires_bearer():
|
||||
status, body = _parse_response(
|
||||
submit_order_handler.lambda_handler(_orders_event(token=""), None)
|
||||
|
|
|
|||
|
|
@ -21,7 +21,9 @@ def test_meals_owns_a_vpc_instead_of_looking_up_default():
|
|||
assert "count = local.manage_vpc ? 1 : 0" in vpc
|
||||
assert 'variable "existing_vpc_id"' in variables
|
||||
assert 'variable "existing_public_subnet_ids"' in variables
|
||||
assert 'manage_vpc = var.existing_vpc_id == ""' in locals_tf
|
||||
assert (
|
||||
'manage_vpc = var.existing_vpc_id == "" && !local.is_prod' in locals_tf
|
||||
)
|
||||
assert 'data "aws_vpc" "default"' not in ecs
|
||||
assert "data.aws_vpc.default" not in ecs
|
||||
assert "data.aws_subnets.default" not in ecs
|
||||
|
|
@ -33,3 +35,11 @@ def test_meals_owns_a_vpc_instead_of_looking_up_default():
|
|||
assert 'check "existing_subnets_in_vpc"' in data
|
||||
assert "from = aws_vpc.this" in vpc
|
||||
assert "to = aws_vpc.this[0]" in vpc
|
||||
outputs = _read("outputs.tf")
|
||||
assert 'output "vpc_id"' in outputs
|
||||
assert "value = local.vpc_id" in outputs
|
||||
assert 'output "public_subnet_ids"' in outputs
|
||||
assert 'check "prod_reuses_afterhours_vpc"' in data
|
||||
assert "prod_requires_afterhours_vpc" in vpc
|
||||
assert "Do not mint 10.60." in vpc
|
||||
assert 'count = var.existing_vpc_id == "" ? 0 : 1' in vpc
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue