punchout-simulator 0.1.0 → 0.1.5

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.
@@ -1237,23 +1237,16 @@ flowRoute.post("/:id/setup", async (c) => {
1237
1237
  response: respLog
1238
1238
  });
1239
1239
  });
1240
- flowRoute.post("/:id/order", async (c) => {
1241
- const conn = getConnection(c.req.param("id"));
1242
- const err = requireVirtualBuyer(conn);
1243
- if (err) return c.json({ error: err }, 400);
1244
- const body = await c.req.json().catch(() => ({}));
1245
- const sessionId = body.sessionId || `pos-${nanoid5(16)}`;
1240
+ function buildOrderXml(conn, body) {
1246
1241
  const items = body.items ?? [];
1247
1242
  const currency = body.currency || items[0]?.currency || "USD";
1248
1243
  const total = body.total ?? items.reduce((s, it) => s + (it.unitPriceAmount ?? 0) * it.quantity, 0);
1249
1244
  const orderId = body.orderId || `PO-${nanoid5(8)}`;
1250
- const dangling = !!body.danglingCid;
1251
- const inputAtts = body.attachments ?? [];
1252
- const attMeta = inputAtts.map((a) => ({
1245
+ const attMeta = (body.attachments ?? []).map((a) => ({
1253
1246
  contentId: a.contentId,
1254
1247
  scope: a.scope === "order" || a.scope == null ? "order" : { itemIndex: Number(a.scope) }
1255
1248
  }));
1256
- const xml = body.xml || buildOrderRequest({
1249
+ const xml = buildOrderRequest({
1257
1250
  from: conn.from,
1258
1251
  to: conn.to,
1259
1252
  sender: conn.sender,
@@ -1270,6 +1263,25 @@ flowRoute.post("/:id/order", async (c) => {
1270
1263
  billTo: body.billTo,
1271
1264
  attachments: attMeta
1272
1265
  });
1266
+ return { xml, orderId };
1267
+ }
1268
+ flowRoute.post("/:id/order/preview", async (c) => {
1269
+ const conn = getConnection(c.req.param("id"));
1270
+ const err = requireVirtualBuyer(conn);
1271
+ if (err) return c.json({ error: err }, 400);
1272
+ const body = await c.req.json().catch(() => ({}));
1273
+ const { xml, orderId } = buildOrderXml(conn, body);
1274
+ return c.json({ xml, orderId });
1275
+ });
1276
+ flowRoute.post("/:id/order", async (c) => {
1277
+ const conn = getConnection(c.req.param("id"));
1278
+ const err = requireVirtualBuyer(conn);
1279
+ if (err) return c.json({ error: err }, 400);
1280
+ const body = await c.req.json().catch(() => ({}));
1281
+ const sessionId = body.sessionId || `pos-${nanoid5(16)}`;
1282
+ const dangling = !!body.danglingCid;
1283
+ const inputAtts = body.attachments ?? [];
1284
+ const xml = body.xml || buildOrderXml(conn, body).xml;
1273
1285
  let wireBody = xml;
1274
1286
  let wireContentType = "text/xml; charset=UTF-8";
1275
1287
  const availableContentIds = /* @__PURE__ */ new Set();