@crvouga/mockingbird-service-rxvortex 1.1.0 → 1.1.2

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/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # Changelog — @crvouga/mockingbird-service-rxvortex
2
2
 
3
+ ## 1.1.2 (2026-09-26)
4
+
5
+ ### Fixes and improvements
6
+
7
+ - treat enum [""] branches as unset markers in form coercion ([7177835](https://github.com/crvouga/mockingbird/commit/7177835cc510e14245d6648ad2821daa694bb80c))
8
+
9
+ ## 1.1.1 (2026-09-25)
10
+
11
+ ### Fixes and improvements
12
+
13
+ - take the rejected-request byte count from content-length, never by reading the body ([a0e5fb2](https://github.com/crvouga/mockingbird/commit/a0e5fb2fc80ab725c3552b612f3f091fd6c857fb))
14
+ - reject a present body by media type, and log what a rejected request sent ([12e351a](https://github.com/crvouga/mockingbird/commit/12e351aba53cfb7b41e31a7809419455fc2902eb))
15
+
3
16
  ## 1.1.0 (2026-09-25)
4
17
 
5
18
  ### Features
@@ -1366,6 +1366,100 @@ var operationMetadata = (operation) => {
1366
1366
 
1367
1367
  // ../core/dist/service.js
1368
1368
  import { Hono } from "hono";
1369
+
1370
+ // ../core/dist/validation.js
1371
+ var requestBodyOf = (context) => {
1372
+ const requestBody = context.operation.operation.requestBody;
1373
+ return requestBody ? deref(context.document, requestBody) : void 0;
1374
+ };
1375
+ var mediaTypeMatches = (accepted, actual) => {
1376
+ const pattern = mediaTypeOf(accepted) ?? accepted.toLowerCase();
1377
+ if (pattern === actual || pattern === "*/*")
1378
+ return true;
1379
+ const [type, subtype] = pattern.split("/");
1380
+ const [actualType, actualSubtype] = actual.split("/");
1381
+ if (type !== actualType && type !== "*")
1382
+ return false;
1383
+ if (subtype === void 0 || subtype === "*")
1384
+ return true;
1385
+ if (subtype.startsWith("*+"))
1386
+ return actualSubtype?.endsWith(subtype.slice(1)) === true;
1387
+ return false;
1388
+ };
1389
+ var acceptedKeyFor = (content, mediaType) => {
1390
+ if (!content || mediaType === void 0)
1391
+ return void 0;
1392
+ const keys = Object.keys(content);
1393
+ return keys.find((key) => mediaTypeOf(key) === mediaType) ?? keys.find((key) => mediaTypeMatches(key, mediaType));
1394
+ };
1395
+ var unsupportedMediaType = (context, options = {}) => {
1396
+ if (context.body.kind === "empty" && options.includeEmpty !== true)
1397
+ return void 0;
1398
+ const content = requestBodyOf(context)?.content;
1399
+ if (!content || Object.keys(content).length === 0)
1400
+ return void 0;
1401
+ const mediaType = mediaTypeOf(context.request.headers.get("content-type"));
1402
+ if (acceptedKeyFor(content, mediaType) !== void 0)
1403
+ return void 0;
1404
+ return { mediaType: mediaType ?? null, accepted: Object.keys(content) };
1405
+ };
1406
+ var recorded = /* @__PURE__ */ new WeakMap();
1407
+ var recordedIssues = (request) => recorded.get(request);
1408
+ var bodyIssues = (context, contentType = "application/json") => {
1409
+ const issues = findBodyIssues(context, contentType);
1410
+ if (issues.length > 0)
1411
+ recorded.set(context.request, issues);
1412
+ return issues;
1413
+ };
1414
+ var findBodyIssues = (context, contentType) => {
1415
+ const resolved = requestBodyOf(context);
1416
+ if (!resolved)
1417
+ return [];
1418
+ const unsupported = unsupportedMediaType(context);
1419
+ if (unsupported) {
1420
+ return [
1421
+ {
1422
+ path: "",
1423
+ kind: "media_type",
1424
+ message: unsupported.mediaType === null ? "request body has no content-type" : `request body media type ${unsupported.mediaType} is not supported`
1425
+ }
1426
+ ];
1427
+ }
1428
+ const key = acceptedKeyFor(resolved.content, mediaTypeOf(context.request.headers.get("content-type"))) ?? contentType;
1429
+ const schema = resolved.content?.[key]?.schema;
1430
+ if (!schema)
1431
+ return [];
1432
+ if (context.body.kind === "invalid") {
1433
+ return [
1434
+ {
1435
+ path: "",
1436
+ kind: "syntax",
1437
+ message: `request body is not valid ${context.body.mediaType}`
1438
+ }
1439
+ ];
1440
+ }
1441
+ const value = context.body.kind === "json" || context.body.kind === "form" || context.body.kind === "text" ? context.body.value : void 0;
1442
+ if (value === void 0) {
1443
+ return resolved.required && context.body.kind === "empty" ? [{ path: "", kind: "required", message: "request body is required" }] : [];
1444
+ }
1445
+ return validateValue(context.document, resolveSchema(context.document, schema), value).map((issue) => ({ path: issue.path.join("."), kind: "schema", message: issue.message }));
1446
+ };
1447
+ var issuesByField = (issues) => {
1448
+ const out = {};
1449
+ for (const issue of issues) {
1450
+ const missing = /^missing required property (.+)$/.exec(issue.message);
1451
+ const field = missing ? [issue.path, missing[1]].filter(Boolean).join(".") : issue.path || "body";
1452
+ const message = missing ? `The ${field} field is required.` : `The ${field} field ${issue.message}.`;
1453
+ out[field] = [...out[field] ?? [], message];
1454
+ }
1455
+ return out;
1456
+ };
1457
+
1458
+ // ../core/dist/service.js
1459
+ var withIssues = (request, response) => {
1460
+ const issues = response.status >= 400 ? recordedIssues(request) : void 0;
1461
+ return issues && issues.length > 0 ? annotateResponse(response, { issues }) : response;
1462
+ };
1369
1463
  var defineOperations = (handlers) => handlers;
1370
1464
  var OperationRegistryError = class extends Error {
1371
1465
  problems;
@@ -1451,9 +1545,7 @@ var createService = (options) => {
1451
1545
  now
1452
1546
  };
1453
1547
  const short = await options.before?.(context);
1454
- if (short)
1455
- return short;
1456
- return handler(context);
1548
+ return withIssues(request, short ?? await handler(context));
1457
1549
  };
1458
1550
  app.on(operation.method.toUpperCase(), honoPath(operation.path), route);
1459
1551
  }
@@ -1490,7 +1582,7 @@ var restoreNamespace = (sqlite, namespace, snapshot) => {
1490
1582
  };
1491
1583
 
1492
1584
  // ../core/dist/version.js
1493
- var PACKAGE_VERSION = true ? "1.1.0" : UNRELEASED_VERSION;
1585
+ var PACKAGE_VERSION = true ? "1.1.2" : UNRELEASED_VERSION;
1494
1586
 
1495
1587
  // ../core/dist/signing.js
1496
1588
  var encoder = new TextEncoder();
@@ -2250,8 +2342,15 @@ var createRuntime = (options) => {
2250
2342
  const started = monotonicNow();
2251
2343
  const url = new URL(request.url);
2252
2344
  const operationId = operationIdFor(request, url.pathname);
2345
+ const contentLength = request.headers.get("content-length");
2346
+ const received = {
2347
+ contentType: request.headers.get("content-type"),
2348
+ bodyBytes: contentLength !== null && /^\d+$/.test(contentLength) ? Number(contentLength) : null,
2349
+ transferEncoding: request.headers.get("transfer-encoding")
2350
+ };
2253
2351
  const log = (status, faultId, response2) => {
2254
2352
  const noted = response2 ? responseNotes(response2) : void 0;
2353
+ const rejected = status >= 400 && faultId === void 0;
2255
2354
  const entry = {
2256
2355
  service: options.name,
2257
2356
  namespace,
@@ -2263,7 +2362,9 @@ var createRuntime = (options) => {
2263
2362
  unmatched: options.document !== void 0 && operationId === void 0,
2264
2363
  ...faultId !== void 0 ? { faultId } : {},
2265
2364
  ...noted?.ids && Object.keys(noted.ids).length > 0 ? { ids: noted.ids } : {},
2266
- ...noted?.adopted ? { adopted: true } : {}
2365
+ ...noted?.adopted ? { adopted: true } : {},
2366
+ ...rejected ? { request: { ...received } } : {},
2367
+ ...rejected && noted?.issues && noted.issues.length > 0 ? { issues: noted.issues.map((issue) => ({ ...issue })) } : {}
2267
2368
  };
2268
2369
  metrics.record(entry);
2269
2370
  journal.record({ ...entry, at: new Date(clock.now()).toISOString() });
@@ -2470,35 +2571,6 @@ var presetRoutes = (presets, runtime) => ({
2470
2571
  }
2471
2572
  });
2472
2573
 
2473
- // ../core/dist/validation.js
2474
- var bodyIssues = (context, contentType = "application/json") => {
2475
- const requestBody = context.operation.operation.requestBody;
2476
- if (!requestBody)
2477
- return [];
2478
- const resolved = deref(context.document, requestBody);
2479
- const schema = resolved.content?.[contentType]?.schema;
2480
- if (!schema)
2481
- return [];
2482
- const value = context.body.kind === "json" || context.body.kind === "form" ? context.body.value : void 0;
2483
- if (context.body.kind === "invalid") {
2484
- return [{ path: "", message: `request body is not valid ${context.body.mediaType}` }];
2485
- }
2486
- if (value === void 0) {
2487
- return resolved.required ? [{ path: "", message: "request body is required" }] : [];
2488
- }
2489
- return validateValue(context.document, resolveSchema(context.document, schema), value).map((issue) => ({ path: issue.path.join("."), message: issue.message }));
2490
- };
2491
- var issuesByField = (issues) => {
2492
- const out = {};
2493
- for (const issue of issues) {
2494
- const missing = /^missing required property (.+)$/.exec(issue.message);
2495
- const field = missing ? [issue.path, missing[1]].filter(Boolean).join(".") : issue.path || "body";
2496
- const message = missing ? `The ${field} field is required.` : `The ${field} field ${issue.message}.`;
2497
- out[field] = [...out[field] ?? [], message];
2498
- }
2499
- return out;
2500
- };
2501
-
2502
2574
  // src/generated/openapi.ts
2503
2575
  var document = JSON.parse(`{"openapi":"3.1.0","info":{"title":"RxVortex (Strive) pharmacy API (Mockingbird subset)","description":"Stateful mock subset of the RxVortex / Strive compounding-pharmacy API: client-credentials\\ntoken, order submit, status, cancel, lookup by sender order id (recovery), and the preset\\ncatalog. Hand-authored from the consumer's adapters (the vendor publishes no spec).\\n","version":"1","x-mockingbird-upstream":{"note":"Hand-authored from the wire shapes our consumer reads and writes (rxvortex-auth.service.ts, rxvortex-fulfillment.adapter.ts, rxvortex-live.client.ts)."}},"servers":[{"url":"https://sandbox.rxvortex.com"}],"security":[{"bearerAuth":[]}],"paths":{"/api/v1/generate-access-token":{"post":{"operationId":"GenerateAccessToken","security":[],"x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":true}},"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["client_id","client_secret"],"properties":{"client_id":{"type":"string","minLength":1,"maxLength":64},"client_secret":{"type":"string","minLength":1,"maxLength":64}}}}}},"responses":{"200":{"description":"Access token","content":{"application/json":{"schema":{"$ref":"#/components/schemas/TokenResponse"}}}},"401":{"description":"Bad credentials","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorBody"}}}},"422":{"description":"Validation failed","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ValidationError"}}}}}}},"/api/v1/orders":{"post":{"operationId":"CreateOrder","x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":false}},"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/CreateOrderBody"}}}},"responses":{"200":{"description":"Order accepted","content":{"application/json":{"schema":{"$ref":"#/components/schemas/CreateOrderResponse"}}}},"401":{"description":"Unauthenticated","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorBody"}}}},"409":{"description":"Duplicate sender_order_id","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorBody"}}}},"422":{"description":"Validation failed","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ValidationError"}}}}}}},"/api/v1/orders/{orderId}":{"parameters":[{"name":"orderId","in":"path","required":true,"description":"The vendor order tracking id, or the sender order id (our payment id).","schema":{"type":"string","x-mockingbird-resource-ref":{"type":"order","missing":"RXV-00000000-MISSING"}}}],"get":{"operationId":"GetOrder","x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":true}},"responses":{"200":{"description":"Order status","content":{"application/json":{"schema":{"$ref":"#/components/schemas/OrderStatus"}}}},"401":{"description":"Unauthenticated","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorBody"}}}},"404":{"description":"Unknown order","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorBody"}}}}}},"delete":{"operationId":"CancelOrder","x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":false}},"responses":{"200":{"description":"Cancelled","content":{"application/json":{"schema":{"$ref":"#/components/schemas/CancelResponse"}}}},"401":{"description":"Unauthenticated","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorBody"}}}},"404":{"description":"Unknown order","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorBody"}}}},"409":{"description":"Not cancellable in its current status","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorBody"}}}}}}},"/api/v1/preset-catalog-items":{"get":{"operationId":"ListPresetCatalogItems","x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":true}},"responses":{"200":{"description":"Preset catalog","content":{"application/json":{"schema":{"type":"object","required":["data"],"properties":{"data":{"type":"array","items":{"$ref":"#/components/schemas/CatalogItem"}}}}}}},"401":{"description":"Unauthenticated","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorBody"}}}}}}}},"components":{"securitySchemes":{"bearerAuth":{"type":"http","scheme":"bearer"}},"schemas":{"TokenResponse":{"type":"object","required":["access_token","token_type","expires_in"],"properties":{"access_token":{"type":"string","x-mockingbird-volatile":{"kind":"token"}},"token_type":{"type":"string","enum":["Bearer"]},"expires_in":{"type":"integer"}}},"Address":{"type":"object","required":["line1","city","state","postal_code","country"],"properties":{"line1":{"type":"string","minLength":1,"maxLength":80},"line2":{"type":"string","maxLength":80},"city":{"type":"string","minLength":1,"maxLength":40},"state":{"type":"string","pattern":"^[A-Z]{2}$"},"postal_code":{"type":"string","pattern":"^[0-9]{5}(-[0-9]{4})?$"},"country":{"type":"string","enum":["US"]}}},"Patient":{"type":"object","required":["sender_patient_id","first_name","last_name","dob","gender","email","phone","address"],"properties":{"sender_patient_id":{"type":"string","minLength":1,"maxLength":64},"first_name":{"type":"string","minLength":1,"maxLength":40},"last_name":{"type":"string","minLength":1,"maxLength":40},"dob":{"type":"string","pattern":"^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$"},"gender":{"type":"string","enum":["male","female"]},"email":{"type":"string","format":"email","maxLength":120},"phone":{"type":"string","pattern":"^[0-9]{3}-[0-9]{3}-[0-9]{4}$"},"address":{"$ref":"#/components/schemas/Address"}}},"Prescriber":{"type":"object","required":["first_name","last_name","npi"],"properties":{"first_name":{"type":"string","minLength":1,"maxLength":40},"last_name":{"type":"string","minLength":1,"maxLength":40},"npi":{"type":"string","pattern":"^[0-9]{10}$"},"dea_number":{"type":"string","maxLength":20},"license_number":{"type":"string","maxLength":20},"license_state":{"type":"string","maxLength":2},"phone":{"type":"string","maxLength":20},"address":{"$ref":"#/components/schemas/Address"}}},"MedicationRequest":{"type":"object","required":["type","preset_catalog_id","sender_med_request_id","medication_name","quantity","quantity_units","days_supply_duration","refills","instructions"],"properties":{"type":{"type":"string","enum":["new"]},"preset_catalog_id":{"type":"string","x-mockingbird-resource-ref":{"type":"catalog_item","missing":"00000000-0000-4000-8000-000000000000"}},"sender_med_request_id":{"type":"string","minLength":1,"maxLength":64},"medication_name":{"type":"string","minLength":1,"maxLength":120},"medication_strength":{"type":"string","maxLength":60},"medication_form":{"type":"string","maxLength":40},"quantity":{"type":"number","exclusiveMinimum":0,"maximum":1000},"quantity_units":{"type":"string","enum":["mL","grams","each"]},"days_supply_duration":{"type":"integer","minimum":1,"maximum":365},"refills":{"type":"integer","minimum":0,"maximum":12},"instructions":{"type":"string","minLength":1,"maxLength":500},"note":{"type":"string","maxLength":1000},"authored_on_datetime":{"type":"string","maxLength":40},"clinical_difference":{"type":"string","maxLength":1000},"schedule_code":{"type":"string","enum":["2","3","4","5"]}}},"ClinicalList":{"type":"object","properties":{"has_known_allergies":{"type":"boolean"},"has_known_diseases":{"type":"boolean"},"has_known_medications":{"type":"boolean"},"entries":{"type":"array","maxItems":5,"items":{"type":"object","required":["description"],"properties":{"description":{"type":"string","maxLength":200}}}}}},"CreateOrderBody":{"type":"object","required":["patient","prescriber","order","medication_requests"],"properties":{"patient":{"$ref":"#/components/schemas/Patient"},"prescriber":{"$ref":"#/components/schemas/Prescriber"},"order":{"type":"object","required":["bill_to","ship_to","sender_order_id"],"properties":{"bill_to":{"type":"string","enum":["practice","patient"]},"ship_to":{"type":"string","enum":["patient","practice"]},"sender_order_id":{"type":"string","minLength":1,"maxLength":64}}},"medication_requests":{"type":"array","minItems":1,"maxItems":3,"items":{"$ref":"#/components/schemas/MedicationRequest"}},"clinical":{"type":"object","properties":{"allergies":{"$ref":"#/components/schemas/ClinicalList"},"diseases":{"$ref":"#/components/schemas/ClinicalList"},"medications":{"$ref":"#/components/schemas/ClinicalList"}}},"shipment":{"type":"object","properties":{"recipient_first_name":{"type":"string","maxLength":40},"recipient_last_name":{"type":"string","maxLength":40},"recipient_email":{"type":"string","maxLength":80},"recipient_phone":{"type":"string","maxLength":20},"address":{"$ref":"#/components/schemas/Address"}}}}},"CreateOrderResponse":{"type":"object","required":["success","message","order_tracking_id","sender_order_id","status"],"properties":{"success":{"type":"boolean"},"message":{"type":"string"},"order_tracking_id":{"type":"string","x-mockingbird-resource":{"type":"order","identity":true},"x-mockingbird-volatile":{"kind":"id"}},"sender_order_id":{"type":"string"},"status":{"type":"string"}}},"OrderStatus":{"type":"object","required":["order_tracking_id","tracking_id","orderReferenceID","sender_order_id","rxstatus","orderstatus","shipping_status","cancellable","created_at","updated_at"],"properties":{"order_tracking_id":{"type":"string","x-mockingbird-volatile":{"kind":"id"}},"tracking_id":{"type":"string","x-mockingbird-volatile":{"kind":"id"}},"orderReferenceID":{"type":"string","x-mockingbird-volatile":{"kind":"id"}},"sender_order_id":{"type":"string"},"rxstatus":{"type":"string"},"orderstatus":{"type":"string"},"shipping_status":{"type":"string"},"delivered_date":{"type":["string","null"]},"trackingnumber":{"type":["string","null"]},"shippingservice":{"type":["string","null"]},"shippingcarrier":{"type":["string","null"]},"shipmenttrackingurl":{"type":["string","null"]},"cancellable":{"type":"boolean"},"created_at":{"type":"string","x-mockingbird-volatile":{"kind":"timestamp"}},"updated_at":{"type":"string","x-mockingbird-volatile":{"kind":"timestamp"}}}},"CancelResponse":{"type":"object","required":["success","message","order_tracking_id","rxstatus"],"properties":{"success":{"type":"boolean"},"message":{"type":"string"},"order_tracking_id":{"type":"string","x-mockingbird-volatile":{"kind":"id"}},"rxstatus":{"type":"string"}}},"CatalogItem":{"type":"object","required":["catalog_id","medication_name","status"],"properties":{"catalog_id":{"type":"string","x-mockingbird-resource":{"type":"catalog_item","identity":true}},"medication_name":{"type":"string"},"medication_strength":{"type":["string","null"]},"package_size":{"type":["string","null"]},"quantity":{"type":["number","null"]},"quantity_units":{"type":["string","null"]},"medication_form":{"type":["string","null"]},"route":{"type":["string","null"]},"states":{"type":"array","items":{"type":"string"}},"status":{"type":"string","enum":["active","inactive"]}}},"ErrorBody":{"type":"object","required":["message"],"properties":{"message":{"type":"string"},"success":{"type":"boolean"}}},"ValidationError":{"type":"object","required":["message","errors"],"properties":{"message":{"type":"string"},"errors":{"oneOf":[{"type":"object","additionalProperties":{"type":"array","items":{"type":"string"}}},{"type":"array","items":{"type":"object"}}]}}}}}}`);
2504
2576
  var operationIds = ["GenerateAccessToken", "CreateOrder", "GetOrder", "CancelOrder", "ListPresetCatalogItems"];
@@ -3294,4 +3366,4 @@ export {
3294
3366
  tokenCredential,
3295
3367
  RxVortexAPI
3296
3368
  };
3297
- //# sourceMappingURL=chunk-VQAJFAUO.js.map
3369
+ //# sourceMappingURL=chunk-5KK6W2PE.js.map