# JD Edwards customer-lookup orchestration contract

Companion to [Amazon Connect + JD Edwards EnterpriseOne: AIS and Orchestrator](/blog/amazon-connect-jd-edwards-integration-2026/).
It specifies what the orchestration you build in Orchestrator Studio must accept and return so the existing
[`../erp/jde.mjs`](../erp/jde.mjs) adapter can use it. It is a contract and a test, not an exported orchestration:
the orchestration itself is a User Defined Object in your own JD Edwards system.

## Contract

| Direction | Name | Type | Notes |
| --- | --- | --- | --- |
| Input | `phone` | string | E.164, for example `+14155550123`. The handler validates it before the call. Generic input format (`{"phone": "..."}`). |
| Output | `accountStatus` | string | `ACTIVE`, `INACTIVE` or `NOT_FOUND`. Always emit it, even for no match. A response without it is treated as `BAD_RESPONSE`. |
| Output | `openInvoiceCount` | string | Count of open receivables, or `0`. |
| Output | `lastOrderStatus` | string | Your status description, or `NONE`. |
| Output | `lastOrderRef` | string | Order reference, or `NONE`. |

Output names are flat, top level, and have no spaces. The handler replaces any character outside `[A-Za-z0-9_-]` with `_`
and truncates to 40 characters, because Connect's `STRING_MAP` response allows only those characters.

Matching rules to implement inside the orchestration (they are not enforceable from outside):

- Zero customers match the phone: `accountStatus` = `NOT_FOUND`, the other three = `NONE`.
- More than one customer matches: do not pick one. The adapter has no `AMBIGUOUS` value for JD Edwards, so abort the orchestration (HTTP 500, which the handler turns into `HTTP_500`) rather than guess.
- Use "Abort" on error for the lookup steps. "Continue" returns HTTP 200 with the error recorded in the response, which the handler can only catch if `accountStatus` is missing.

## Files

| File | Purpose |
| --- | --- |
| `request.example.json` | **Illustrative** request body. Not captured from a live system. |
| `response.example.json` | **Illustrative** response body. Not captured from a live system. |
| `contract.test.mjs` | Runs the shipped `../erp/handler.mjs` against those examples with a mocked `fetch`. |

## Run the test

```bash
cd examples/architecture-blog-2026/connect-commerce-context/jde-orchestration
node --test
```

Five tests pass. Nothing calls an AIS Server. The version 3 response envelope was not observed on a live server, so
compare `response.example.json` with the output your own orchestration returns (Run Orchestrations page, or
`/jderest/v3/open-api-catalog3/<name>`) before relying on the flat shape.
