{"openapi":"3.1.0","info":{"title":"SupplyChain Rescue — Coordination Engine API","description":"Ranks recipients, splits donations, selects transporters and runs Rescue Mode.\n\n**Authentication.** Send the same session token issued by the core platform: `Authorization: Token <token>`. The engine verifies it against the core platform and enforces ownership (donors may only allocate their own donations).\n\n**Persistence.** The engine is stateless. It reads a matching context from the core platform and writes the resulting allocation plan back in a single atomic call, so retries never duplicate allocations, jobs or notifications.","version":"1.0.0"},"servers":[{"url":"https://supply-chain-rescue-engine.fly.dev/engine","description":"Coordination engine"}],"tags":[{"name":"coordination","description":"Recipient ranking, allocation and rescue for platform users."},{"name":"internal","description":"Service-to-service endpoints. Require the internal service token (X-Internal-Token)."}],"paths":{"/api/v1/internal/rescue/{donationId}":{"post":{"tags":["internal"],"summary":"Automatic rescue","description":"Called by the expiry monitor when a donation turns critical while unallocated.","operationId":"rescue","parameters":[{"name":"donationId","in":"path","required":true,"schema":{"type":"string","pattern":"^[A-Za-z0-9-]{1,64}$"}}],"responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"$ref":"#/components/schemas/AllocationResponse"}}}}},"security":[{"InternalServiceToken":[]}]}},"/api/v1/internal/assign-transport/{donationId}":{"post":{"tags":["internal"],"summary":"Find transporters","description":"Offers pickups for allocations without a transporter, skipping transporters who declined them.","operationId":"assignTransport","parameters":[{"name":"donationId","in":"path","required":true,"schema":{"type":"string","pattern":"^[A-Za-z0-9-]{1,64}$"}}],"responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"$ref":"#/components/schemas/AllocationResponse"}}}}},"security":[{"InternalServiceToken":[]}]}},"/api/v1/internal/allocate/{donationId}":{"post":{"tags":["internal"],"summary":"Scheduled allocation","description":"Allocates a donation published by a recurring schedule, with the normal radius and rules.","operationId":"allocate","parameters":[{"name":"donationId","in":"path","required":true,"schema":{"type":"string","pattern":"^[A-Za-z0-9-]{1,64}$"}}],"responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"$ref":"#/components/schemas/AllocationResponse"}}}}},"security":[{"InternalServiceToken":[]}]}},"/api/v1/coordination/rescue/{donationId}":{"post":{"tags":["coordination"],"summary":"Start a rescue","description":"Rescue Mode allocation: searches a wider radius and, when no recipient has a matching need, offers the food to the best-placed recipients.","operationId":"rescue_1","parameters":[{"name":"donationId","in":"path","required":true,"schema":{"type":"string","pattern":"^[A-Za-z0-9-]{1,64}$"}}],"responses":{"200":{"description":"Rescue allocation applied","content":{"application/json":{"schema":{"$ref":"#/components/schemas/AllocationResponse"}}}}},"security":[{"TokenAuth":[]}]}},"/api/v1/coordination/allocate/{donationId}":{"post":{"tags":["coordination"],"summary":"Allocate a donation","description":"Builds a plan that may split the donation across several recipients (respecting min/max allocation, open needs and storage capacity), assigns the nearest capable transporter to each share and persists everything atomically. Safe to retry.","operationId":"allocate_1","parameters":[{"name":"donationId","in":"path","description":"Donation id","required":true,"schema":{"type":"string","pattern":"^[A-Za-z0-9-]{1,64}$"}}],"responses":{"200":{"description":"Allocation plan applied","content":{"application/json":{"schema":{"$ref":"#/components/schemas/AllocationResponse"}}}},"409":{"description":"Donation is no longer available","content":{"application/json":{"schema":{"$ref":"#/components/schemas/AllocationResponse"}}}},"422":{"description":"No eligible recipient in range","content":{"application/json":{"schema":{"$ref":"#/components/schemas/AllocationResponse"}}}}},"security":[{"TokenAuth":[]}]}},"/api/v1/coordination/matches":{"get":{"tags":["coordination"],"summary":"Rank recipients for a donation","description":"Scores every verified recipient in range: 35% time fit, 25% distance, 20% demand, 10% storage, 10% need priority. Each match includes the factor breakdown and whether the recipient is eligible.","operationId":"matches","parameters":[{"name":"donation_id","in":"query","required":true,"schema":{"type":"string","pattern":"^[A-Za-z0-9-]{1,64}$"}},{"name":"radius_km","in":"query","required":false,"schema":{"type":"number","format":"double","maximum":500.0,"minimum":1.0}}],"responses":{"200":{"description":"Ranked recipients","content":{"application/json":{"schema":{"$ref":"#/components/schemas/MatchesResponse"}}}},"403":{"description":"Caller does not own the donation","content":{"application/json":{"schema":{"$ref":"#/components/schemas/MatchesResponse"}}}}},"security":[{"TokenAuth":[]}]}}},"components":{"schemas":{"AllocationResponse":{"type":"object","properties":{"donationId":{"type":"string"},"trigger":{"type":"string"},"ranking":{"type":"array","items":{"$ref":"#/components/schemas/RankedRecipient"}},"plan":{"type":"array","items":{"$ref":"#/components/schemas/PlanItem"}},"unallocatedQuantity":{"type":"number","format":"double"},"notes":{"type":"array","items":{"type":"string"}},"allocations":{"$ref":"#/components/schemas/JsonNode"}}},"Breakdown":{"type":"object","properties":{"timeFit":{"type":"number","format":"double"},"distance":{"type":"number","format":"double"},"demand":{"type":"number","format":"double"},"storage":{"type":"number","format":"double"},"priority":{"type":"number","format":"double"}}},"JsonNode":{"type":"object"},"PlanItem":{"type":"object","properties":{"recipientId":{"type":"string"},"quantity":{"type":"number","format":"double"},"matchScore":{"type":"integer","format":"int32"},"distanceKm":{"type":"number","format":"double"},"transporterId":{"type":"string"},"breakdown":{"$ref":"#/components/schemas/Breakdown"}}},"RankedRecipient":{"type":"object","properties":{"recipientId":{"type":"string"},"name":{"type":"string"},"score":{"type":"integer","format":"int32"},"distanceKm":{"type":"number","format":"double"},"openNeed":{"type":"number","format":"double"},"needPriority":{"type":"string"},"eligible":{"type":"boolean"},"reason":{"type":"string"},"breakdown":{"$ref":"#/components/schemas/Breakdown"}}},"MatchesResponse":{"type":"object","properties":{"donationId":{"type":"string"},"radiusKm":{"type":"number","format":"double"},"matches":{"type":"array","items":{"$ref":"#/components/schemas/RankedRecipient"}}}}},"securitySchemes":{"TokenAuth":{"type":"apiKey","description":"`Token <key>` from `POST /api/v1/auth/login/` on the core platform.","name":"Authorization","in":"header"},"InternalServiceToken":{"type":"apiKey","description":"Service-to-service secret shared with the core platform; never issued to users.","name":"X-Internal-Token","in":"header"}}}}