|
| 1 | +# EPCIS Plugin |
| 2 | + |
| 3 | +The EPCIS plugin integrates EPCIS 2.0 supply-chain event data with the DKG Node. |
| 4 | + |
| 5 | +It provides both HTTP endpoints and MCP tools for: |
| 6 | + |
| 7 | +- capturing EPCIS documents |
| 8 | +- checking capture status |
| 9 | +- querying events with filters |
| 10 | +- retrieving published assets by UAL |
| 11 | + |
| 12 | +## Source |
| 13 | + |
| 14 | +- Plugin code: `packages/plugin-epcis/src/index.ts` |
| 15 | +- Query service: `packages/plugin-epcis/src/services/epcisQueryService.ts` |
| 16 | +- Integration guide: `packages/plugin-epcis/docs/EPCIS-Integration-Guide.md` |
| 17 | + |
| 18 | +## Quick Start |
| 19 | + |
| 20 | +1. Ensure publisher plugin and epcis plugin is enabled in server plugin registration: |
| 21 | + - `apps/agent/src/server/index.ts` should include `dkgPublisherPlugin` in the `plugins` array. |
| 22 | + - `apps/agent/src/server/index.ts` should include `epcisPlugin` in the `plugins` array. |
| 23 | +2. Run publisher plugin setup: |
| 24 | + - `cd packages/plugin-dkg-publisher && npm run setup` |
| 25 | + - This initializes publisher configuration (including `.env.publisher`) for the publisher flow. |
| 26 | +3. Configure runtime environment: |
| 27 | + - `EXPO_PUBLIC_MCP_URL=http://localhost:9200` (local same-host setup) |
| 28 | +4. Start the DKG Node server. |
| 29 | +5. Submit an EPCIS document via `POST /epcis/capture`. |
| 30 | +6. Query captured events via `GET /epcis/events`. |
| 31 | + |
| 32 | +## Capabilities |
| 33 | + |
| 34 | +### API Endpoints |
| 35 | + |
| 36 | +- `POST /epcis/capture` |
| 37 | + Accepts an EPCIS document and sends it to publisher flow. |
| 38 | + Returns a numeric `captureID` on success. |
| 39 | + |
| 40 | +- `GET /epcis/capture/:captureID` |
| 41 | + Gets publisher-tracked status for numeric capture IDs. |
| 42 | + |
| 43 | +- `GET /epcis/events` |
| 44 | + Queries EPCIS events with filtering and pagination. |
| 45 | + |
| 46 | +- `GET /epcis/asset/*ual` |
| 47 | + Retrieves an EPCIS asset by UAL. |
| 48 | + |
| 49 | +### MCP Tools |
| 50 | + |
| 51 | +- `epcis-query` |
| 52 | +- `epcis-track-item` |
| 53 | + |
| 54 | +## Configuration |
| 55 | + |
| 56 | +Required runtime env var: |
| 57 | + |
| 58 | +- `EXPO_PUBLIC_MCP_URL` (example local setup: `http://localhost:9200`) |
| 59 | + |
| 60 | +Runtime dependency: |
| 61 | + |
| 62 | +- Publisher API must be available through the same server URL (or routed URL) used by `EXPO_PUBLIC_MCP_URL`. |
| 63 | + |
| 64 | +If `EXPO_PUBLIC_MCP_URL` is not set, capture and status calls that depend on publisher will fail. |
| 65 | + |
| 66 | +## Example Requests |
| 67 | + |
| 68 | +### Capture EPCIS document |
| 69 | + |
| 70 | +```bash |
| 71 | +curl -X POST "http://localhost:9200/epcis/capture" \ |
| 72 | + -H "Content-Type: application/json" \ |
| 73 | + -d '{ |
| 74 | + "epcisDocument": { |
| 75 | + "@context": { |
| 76 | + "@vocab": "https://gs1.github.io/EPCIS/", |
| 77 | + "epcis": "https://gs1.github.io/EPCIS/", |
| 78 | + "cbv": "https://ref.gs1.org/cbv/", |
| 79 | + "type": "@type", |
| 80 | + "id": "@id" |
| 81 | + }, |
| 82 | + "type": "EPCISDocument", |
| 83 | + "schemaVersion": "2.0", |
| 84 | + "creationDate": "2024-03-01T08:00:00Z", |
| 85 | + "epcisBody": { |
| 86 | + "eventList": [ |
| 87 | + { |
| 88 | + "type": "ObjectEvent", |
| 89 | + "eventTime": "2024-03-01T08:00:00.000Z", |
| 90 | + "eventTimeZoneOffset": "+00:00", |
| 91 | + "epcList": ["urn:epc:id:sgtin:4012345.011111.1001"], |
| 92 | + "action": "ADD", |
| 93 | + "bizStep": "https://ref.gs1.org/cbv/BizStep-receiving", |
| 94 | + "disposition": "https://ref.gs1.org/cbv/Disp-in_progress", |
| 95 | + "readPoint": { "id": "urn:epc:id:sgln:4012345.00001.0" }, |
| 96 | + "bizLocation": { "id": "urn:epc:id:sgln:4012345.00001.0" }, |
| 97 | + "bizTransactionList": [ |
| 98 | + { |
| 99 | + "type": "https://ref.gs1.org/cbv/BTT-po", |
| 100 | + "bizTransaction": "urn:epc:id:gdti:4012345.00001.PO-2024-001" |
| 101 | + } |
| 102 | + ] |
| 103 | + } |
| 104 | + ] |
| 105 | + } |
| 106 | + }, |
| 107 | + "publishOptions": { |
| 108 | + "privacy": "private", |
| 109 | + "epochs": 12 |
| 110 | + } |
| 111 | + }' |
| 112 | +``` |
| 113 | + |
| 114 | +### Check capture status |
| 115 | + |
| 116 | +```bash |
| 117 | +curl "http://localhost:9200/epcis/capture/123" |
| 118 | +``` |
| 119 | + |
| 120 | +### Query events with filters |
| 121 | + |
| 122 | +```bash |
| 123 | +curl "http://localhost:9200/epcis/events?epc=urn:epc:id:sgtin:4012345.011111.1001&fullTrace=true&limit=50&offset=0" |
| 124 | +``` |
| 125 | + |
| 126 | +## Query Notes |
| 127 | + |
| 128 | +- `fullTrace` (HTTP query) supports: `"true"` or `"false"` |
| 129 | +- `limit`: integer `1..1000` |
| 130 | +- `offset`: integer `>= 0` |
| 131 | +- `bizStep` accepts shorthand (for example `assembling`) or full URI |
| 132 | + |
| 133 | +## Response and Validation Notes |
| 134 | + |
| 135 | +- `POST /epcis/capture` validates the EPCIS document structure before publishing. |
| 136 | +- `GET /epcis/capture/:captureID` expects numeric capture IDs from publisher responses. |
| 137 | +- `GET /epcis/events` rejects invalid pagination and empty-string filter parameters. |
| 138 | + |
| 139 | +## Troubleshooting |
| 140 | + |
| 141 | +- `Publisher endpoint not configured. Set EXPO_PUBLIC_MCP_URL in .env` |
| 142 | + Set `EXPO_PUBLIC_MCP_URL` in runtime environment. |
| 143 | + |
| 144 | +- `Invalid captureID format` |
| 145 | + Use numeric capture IDs returned by `POST /epcis/capture`. |
| 146 | + |
| 147 | +- `Parameter 'limit' must be an integer between 1 and 1000` |
| 148 | + Ensure pagination values are valid integers. |
| 149 | + |
| 150 | +## Related Documentation |
| 151 | + |
| 152 | +For full EPCIS field-level details and examples, see: |
| 153 | + |
| 154 | +- `packages/plugin-epcis/docs/EPCIS-Integration-Guide.md` |
| 155 | + |
0 commit comments