@kuralle-agents/commerce 0.11.0 → 0.11.1

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/dist/order.d.ts CHANGED
@@ -20,7 +20,7 @@ export interface OrderLedger {
20
20
  putIfAbsent(contentKey: string, order: Order): Promise<Order>;
21
21
  }
22
22
  export declare function createInMemoryOrderLedger(): OrderLedger;
23
- export declare function orderContentKey(sessionId: string, items: CartItem[]): string;
23
+ export declare function orderContentKey(sessionId: string, items: CartItem[]): Promise<string>;
24
24
  export interface SubmitOrderArgs {
25
25
  sessionId: string;
26
26
  userId?: string;
package/dist/order.js CHANGED
@@ -1,4 +1,3 @@
1
- import { createHash } from 'node:crypto';
2
1
  import { z } from 'zod';
3
2
  import { defineTool } from '@kuralle-agents/core';
4
3
  import { cartTotal } from './types.js';
@@ -18,12 +17,15 @@ export function createInMemoryOrderLedger() {
18
17
  },
19
18
  };
20
19
  }
21
- export function orderContentKey(sessionId, items) {
20
+ export async function orderContentKey(sessionId, items) {
22
21
  const lines = items
23
22
  .map((item) => `${item.productId}x${item.quantity}@${item.unitPrice.amount}${item.unitPrice.currency}`)
24
23
  .sort()
25
24
  .join('|');
26
- return createHash('sha256').update(`${sessionId}::${lines}`).digest('hex').slice(0, 32);
25
+ // Web Crypto (global) — works on workerd without nodejs_compat, unlike node:crypto.
26
+ const data = new TextEncoder().encode(`${sessionId}::${lines}`);
27
+ const digest = await crypto.subtle.digest('SHA-256', data);
28
+ return [...new Uint8Array(digest)].map((b) => b.toString(16).padStart(2, '0')).join('').slice(0, 32);
27
29
  }
28
30
  const createOrderInput = z.object({
29
31
  note: z.union([z.string(), z.null()]).describe('Optional order note from the user'),
@@ -43,7 +45,7 @@ export function createOrderTool(options) {
43
45
  throw new Error('cart_empty');
44
46
  }
45
47
  const sessionId = ctx.session.id;
46
- const contentKey = orderContentKey(sessionId, cart.items);
48
+ const contentKey = await orderContentKey(sessionId, cart.items);
47
49
  const existing = await ledger.get(contentKey);
48
50
  if (existing) {
49
51
  return existing;
package/package.json CHANGED
@@ -6,7 +6,7 @@
6
6
  "url": "git+https://github.com/kuralle/kuralle-agents.git",
7
7
  "directory": "packages/kuralle-commerce"
8
8
  },
9
- "version": "0.11.0",
9
+ "version": "0.11.1",
10
10
  "description": "Conversational commerce primitives for Kuralle agents: carts, idempotent orders, catalog contracts",
11
11
  "type": "module",
12
12
  "main": "dist/index.js",