@mnemopay/sdk 0.7.5 → 0.9.0
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/README.md +182 -211
- package/dist/cli/dashboard.d.ts +9 -0
- package/dist/cli/dashboard.d.ts.map +1 -0
- package/dist/cli/dashboard.js +78 -0
- package/dist/cli/dashboard.js.map +1 -0
- package/dist/client.d.ts +182 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +177 -0
- package/dist/client.js.map +1 -0
- package/dist/commerce.d.ts +225 -0
- package/dist/commerce.d.ts.map +1 -0
- package/dist/commerce.js +420 -0
- package/dist/commerce.js.map +1 -0
- package/dist/fraud.d.ts +75 -1
- package/dist/fraud.d.ts.map +1 -1
- package/dist/fraud.js +247 -26
- package/dist/fraud.js.map +1 -1
- package/dist/identity.d.ts +154 -0
- package/dist/identity.d.ts.map +1 -0
- package/dist/identity.js +269 -0
- package/dist/identity.js.map +1 -0
- package/dist/index.d.ts +44 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +196 -37
- package/dist/index.js.map +1 -1
- package/dist/ledger.d.ts +137 -0
- package/dist/ledger.d.ts.map +1 -0
- package/dist/ledger.js +250 -0
- package/dist/ledger.js.map +1 -0
- package/dist/mcp/server.d.ts.map +1 -1
- package/dist/mcp/server.js +298 -6
- package/dist/mcp/server.js.map +1 -1
- package/dist/network.d.ts +155 -0
- package/dist/network.d.ts.map +1 -0
- package/dist/network.js +263 -0
- package/dist/network.js.map +1 -0
- package/dist/rails/index.d.ts +2 -0
- package/dist/rails/index.d.ts.map +1 -1
- package/dist/rails/index.js +19 -4
- package/dist/rails/index.js.map +1 -1
- package/dist/rails/paystack.d.ts +157 -0
- package/dist/rails/paystack.d.ts.map +1 -0
- package/dist/rails/paystack.js +366 -0
- package/dist/rails/paystack.js.map +1 -0
- package/package.json +34 -17
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MnemoPay Universal Client
|
|
3
|
+
*
|
|
4
|
+
* Thin client that works everywhere: browser, React Native, Node.js, Deno.
|
|
5
|
+
* Zero dependencies. Talks to a MnemoPay server via REST API.
|
|
6
|
+
*
|
|
7
|
+
* Usage:
|
|
8
|
+
* import { MnemoPayClient } from "@mnemopay/sdk/client";
|
|
9
|
+
*
|
|
10
|
+
* const client = new MnemoPayClient("http://localhost:3200", "your-token");
|
|
11
|
+
* await client.remember("User prefers monthly billing");
|
|
12
|
+
* const memories = await client.recall("billing preferences");
|
|
13
|
+
* const tx = await client.charge(25, "Monthly access");
|
|
14
|
+
* await client.settle(tx.txId);
|
|
15
|
+
*
|
|
16
|
+
* Works from:
|
|
17
|
+
* - Browser (any modern browser with fetch)
|
|
18
|
+
* - React Native
|
|
19
|
+
* - Node.js 18+
|
|
20
|
+
* - Deno
|
|
21
|
+
* - Any HTTP client
|
|
22
|
+
*/
|
|
23
|
+
export interface ClientConfig {
|
|
24
|
+
/** MnemoPay server URL (e.g. "http://localhost:3200") */
|
|
25
|
+
baseUrl: string;
|
|
26
|
+
/** Bearer token for authentication (MNEMOPAY_MCP_TOKEN) */
|
|
27
|
+
token?: string;
|
|
28
|
+
/** Request timeout in ms (default: 30000) */
|
|
29
|
+
timeoutMs?: number;
|
|
30
|
+
/** Custom fetch implementation (for React Native polyfills, etc.) */
|
|
31
|
+
fetch?: typeof globalThis.fetch;
|
|
32
|
+
}
|
|
33
|
+
export interface ApiResponse<T = any> {
|
|
34
|
+
ok: boolean;
|
|
35
|
+
tool?: string;
|
|
36
|
+
result?: T;
|
|
37
|
+
error?: string;
|
|
38
|
+
}
|
|
39
|
+
export interface MemoryResult {
|
|
40
|
+
id: string;
|
|
41
|
+
status: string;
|
|
42
|
+
}
|
|
43
|
+
export interface TransactionResult {
|
|
44
|
+
txId: string;
|
|
45
|
+
amount: number;
|
|
46
|
+
status: string;
|
|
47
|
+
reason?: string;
|
|
48
|
+
rail?: string;
|
|
49
|
+
}
|
|
50
|
+
export interface BalanceResult {
|
|
51
|
+
wallet: number;
|
|
52
|
+
reputation: number;
|
|
53
|
+
}
|
|
54
|
+
export interface ProductResult {
|
|
55
|
+
productId: string;
|
|
56
|
+
title: string;
|
|
57
|
+
price: number;
|
|
58
|
+
url: string;
|
|
59
|
+
merchant: string;
|
|
60
|
+
category?: string;
|
|
61
|
+
rating?: number;
|
|
62
|
+
freeShipping?: boolean;
|
|
63
|
+
}
|
|
64
|
+
export interface PurchaseOrder {
|
|
65
|
+
id: string;
|
|
66
|
+
agentId: string;
|
|
67
|
+
product: ProductResult;
|
|
68
|
+
txId: string;
|
|
69
|
+
status: string;
|
|
70
|
+
trackingUrl?: string;
|
|
71
|
+
approved: boolean;
|
|
72
|
+
}
|
|
73
|
+
export interface ShoppingMandate {
|
|
74
|
+
budget: number;
|
|
75
|
+
maxPerItem?: number;
|
|
76
|
+
categories?: string[];
|
|
77
|
+
blockedCategories?: string[];
|
|
78
|
+
allowedMerchants?: string[];
|
|
79
|
+
blockedMerchants?: string[];
|
|
80
|
+
approvalThreshold?: number;
|
|
81
|
+
expiresAt?: string;
|
|
82
|
+
issuedBy: string;
|
|
83
|
+
}
|
|
84
|
+
export interface SpendingSummary {
|
|
85
|
+
totalSpent: number;
|
|
86
|
+
remainingBudget: number;
|
|
87
|
+
orderCount: number;
|
|
88
|
+
deliveredCount: number;
|
|
89
|
+
pendingCount: number;
|
|
90
|
+
}
|
|
91
|
+
export declare class MnemoPayClient {
|
|
92
|
+
private baseUrl;
|
|
93
|
+
private token?;
|
|
94
|
+
private timeoutMs;
|
|
95
|
+
private _fetch;
|
|
96
|
+
constructor(baseUrl: string, token?: string, config?: Partial<ClientConfig>);
|
|
97
|
+
private request;
|
|
98
|
+
private post;
|
|
99
|
+
private get;
|
|
100
|
+
/** Store a memory */
|
|
101
|
+
remember(content: string, options?: {
|
|
102
|
+
importance?: number;
|
|
103
|
+
tags?: string[];
|
|
104
|
+
}): Promise<MemoryResult>;
|
|
105
|
+
/** Recall memories, optionally filtered by semantic query */
|
|
106
|
+
recall(queryOrLimit?: string | number, limit?: number): Promise<string>;
|
|
107
|
+
/** Delete a memory by ID */
|
|
108
|
+
forget(id: string): Promise<string>;
|
|
109
|
+
/** Boost a memory's importance */
|
|
110
|
+
reinforce(id: string, boost?: number): Promise<string>;
|
|
111
|
+
/** Prune stale memories */
|
|
112
|
+
consolidate(): Promise<string>;
|
|
113
|
+
/** Create an escrow charge */
|
|
114
|
+
charge(amount: number, reason: string): Promise<TransactionResult>;
|
|
115
|
+
/** Settle a pending escrow */
|
|
116
|
+
settle(txId: string, counterpartyId?: string): Promise<TransactionResult>;
|
|
117
|
+
/** Refund a transaction */
|
|
118
|
+
refund(txId: string): Promise<TransactionResult>;
|
|
119
|
+
/** Check wallet balance and reputation */
|
|
120
|
+
balance(): Promise<string>;
|
|
121
|
+
/** Full agent profile */
|
|
122
|
+
profile(): Promise<any>;
|
|
123
|
+
/** Transaction history */
|
|
124
|
+
history(limit?: number): Promise<string>;
|
|
125
|
+
/** Audit logs */
|
|
126
|
+
logs(limit?: number): Promise<string>;
|
|
127
|
+
/** Reputation report */
|
|
128
|
+
reputation(): Promise<any>;
|
|
129
|
+
/** File a dispute */
|
|
130
|
+
dispute(txId: string, reason: string): Promise<any>;
|
|
131
|
+
/** Fraud detection stats */
|
|
132
|
+
fraudStats(): Promise<any>;
|
|
133
|
+
/** Set a shopping mandate (budget, categories, merchant restrictions) */
|
|
134
|
+
setMandate(mandate: ShoppingMandate): Promise<{
|
|
135
|
+
mandate: ShoppingMandate;
|
|
136
|
+
remainingBudget: number;
|
|
137
|
+
}>;
|
|
138
|
+
/** Search for products within mandate constraints */
|
|
139
|
+
search(query: string, options?: {
|
|
140
|
+
limit?: number;
|
|
141
|
+
minPrice?: number;
|
|
142
|
+
maxPrice?: number;
|
|
143
|
+
category?: string;
|
|
144
|
+
sortBy?: "price_asc" | "price_desc" | "rating" | "relevance";
|
|
145
|
+
freeShippingOnly?: boolean;
|
|
146
|
+
}): Promise<{
|
|
147
|
+
results: ProductResult[];
|
|
148
|
+
remainingBudget: number;
|
|
149
|
+
}>;
|
|
150
|
+
/** Purchase a product (creates escrow, executes purchase) */
|
|
151
|
+
purchase(product: ProductResult, deliveryInstructions?: string): Promise<{
|
|
152
|
+
order: PurchaseOrder;
|
|
153
|
+
}>;
|
|
154
|
+
/** Confirm delivery (settles escrow) */
|
|
155
|
+
confirmDelivery(orderId: string): Promise<{
|
|
156
|
+
order: PurchaseOrder;
|
|
157
|
+
}>;
|
|
158
|
+
/** Cancel an order (refunds escrow) */
|
|
159
|
+
cancelOrder(orderId: string, reason?: string): Promise<{
|
|
160
|
+
order: PurchaseOrder;
|
|
161
|
+
}>;
|
|
162
|
+
/** List orders, optionally filtered by status */
|
|
163
|
+
orders(status?: string): Promise<{
|
|
164
|
+
orders: PurchaseOrder[];
|
|
165
|
+
summary: SpendingSummary;
|
|
166
|
+
}>;
|
|
167
|
+
/** Check server health */
|
|
168
|
+
health(): Promise<{
|
|
169
|
+
status: string;
|
|
170
|
+
mode: string;
|
|
171
|
+
}>;
|
|
172
|
+
/** List available tools */
|
|
173
|
+
tools(): Promise<{
|
|
174
|
+
tools: Array<{
|
|
175
|
+
name: string;
|
|
176
|
+
description: string;
|
|
177
|
+
}>;
|
|
178
|
+
version: string;
|
|
179
|
+
}>;
|
|
180
|
+
}
|
|
181
|
+
export default MnemoPayClient;
|
|
182
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAIH,MAAM,WAAW,YAAY;IAC3B,yDAAyD;IACzD,OAAO,EAAE,MAAM,CAAC;IAChB,2DAA2D;IAC3D,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,6CAA6C;IAC7C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,qEAAqE;IACrE,KAAK,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|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* MnemoPay Universal Client
|
|
4
|
+
*
|
|
5
|
+
* Thin client that works everywhere: browser, React Native, Node.js, Deno.
|
|
6
|
+
* Zero dependencies. Talks to a MnemoPay server via REST API.
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
* import { MnemoPayClient } from "@mnemopay/sdk/client";
|
|
10
|
+
*
|
|
11
|
+
* const client = new MnemoPayClient("http://localhost:3200", "your-token");
|
|
12
|
+
* await client.remember("User prefers monthly billing");
|
|
13
|
+
* const memories = await client.recall("billing preferences");
|
|
14
|
+
* const tx = await client.charge(25, "Monthly access");
|
|
15
|
+
* await client.settle(tx.txId);
|
|
16
|
+
*
|
|
17
|
+
* Works from:
|
|
18
|
+
* - Browser (any modern browser with fetch)
|
|
19
|
+
* - React Native
|
|
20
|
+
* - Node.js 18+
|
|
21
|
+
* - Deno
|
|
22
|
+
* - Any HTTP client
|
|
23
|
+
*/
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
exports.MnemoPayClient = void 0;
|
|
26
|
+
// ─── Client ─────────────────────────────────────────────────────────────────
|
|
27
|
+
class MnemoPayClient {
|
|
28
|
+
baseUrl;
|
|
29
|
+
token;
|
|
30
|
+
timeoutMs;
|
|
31
|
+
_fetch;
|
|
32
|
+
constructor(baseUrl, token, config) {
|
|
33
|
+
this.baseUrl = baseUrl.replace(/\/$/, "");
|
|
34
|
+
this.token = token;
|
|
35
|
+
this.timeoutMs = config?.timeoutMs ?? 30_000;
|
|
36
|
+
this._fetch = config?.fetch ?? globalThis.fetch.bind(globalThis);
|
|
37
|
+
}
|
|
38
|
+
// ── Core HTTP ───────────────────────────────────────────────────────────
|
|
39
|
+
async request(method, path, body) {
|
|
40
|
+
const controller = new AbortController();
|
|
41
|
+
const timeout = setTimeout(() => controller.abort(), this.timeoutMs);
|
|
42
|
+
const headers = { "Content-Type": "application/json" };
|
|
43
|
+
if (this.token)
|
|
44
|
+
headers["Authorization"] = `Bearer ${this.token}`;
|
|
45
|
+
try {
|
|
46
|
+
const res = await this._fetch(`${this.baseUrl}${path}`, {
|
|
47
|
+
method,
|
|
48
|
+
headers,
|
|
49
|
+
body: body !== undefined ? JSON.stringify(body) : undefined,
|
|
50
|
+
signal: controller.signal,
|
|
51
|
+
});
|
|
52
|
+
const json = await res.json();
|
|
53
|
+
if (!res.ok || json.ok === false) {
|
|
54
|
+
throw new Error(json.error ?? `Request failed (${res.status})`);
|
|
55
|
+
}
|
|
56
|
+
return json.result !== undefined ? json.result : json;
|
|
57
|
+
}
|
|
58
|
+
catch (err) {
|
|
59
|
+
if (err.name === "AbortError") {
|
|
60
|
+
throw new Error(`Request timed out after ${this.timeoutMs}ms`);
|
|
61
|
+
}
|
|
62
|
+
throw err;
|
|
63
|
+
}
|
|
64
|
+
finally {
|
|
65
|
+
clearTimeout(timeout);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
post(path, body) {
|
|
69
|
+
return this.request("POST", path, body);
|
|
70
|
+
}
|
|
71
|
+
get(path) {
|
|
72
|
+
return this.request("GET", path);
|
|
73
|
+
}
|
|
74
|
+
// ── Memory ──────────────────────────────────────────────────────────────
|
|
75
|
+
/** Store a memory */
|
|
76
|
+
async remember(content, options) {
|
|
77
|
+
return this.post("/api/remember", { content, ...options });
|
|
78
|
+
}
|
|
79
|
+
/** Recall memories, optionally filtered by semantic query */
|
|
80
|
+
async recall(queryOrLimit, limit) {
|
|
81
|
+
if (typeof queryOrLimit === "number") {
|
|
82
|
+
return this.post("/api/recall", { limit: queryOrLimit });
|
|
83
|
+
}
|
|
84
|
+
return this.post("/api/recall", { query: queryOrLimit, limit });
|
|
85
|
+
}
|
|
86
|
+
/** Delete a memory by ID */
|
|
87
|
+
async forget(id) {
|
|
88
|
+
return this.post("/api/forget", { id });
|
|
89
|
+
}
|
|
90
|
+
/** Boost a memory's importance */
|
|
91
|
+
async reinforce(id, boost) {
|
|
92
|
+
return this.post("/api/reinforce", { id, boost });
|
|
93
|
+
}
|
|
94
|
+
/** Prune stale memories */
|
|
95
|
+
async consolidate() {
|
|
96
|
+
return this.post("/api/consolidate", {});
|
|
97
|
+
}
|
|
98
|
+
// ── Payments ────────────────────────────────────────────────────────────
|
|
99
|
+
/** Create an escrow charge */
|
|
100
|
+
async charge(amount, reason) {
|
|
101
|
+
return this.post("/api/charge", { amount, reason });
|
|
102
|
+
}
|
|
103
|
+
/** Settle a pending escrow */
|
|
104
|
+
async settle(txId, counterpartyId) {
|
|
105
|
+
return this.post("/api/settle", { txId, counterpartyId });
|
|
106
|
+
}
|
|
107
|
+
/** Refund a transaction */
|
|
108
|
+
async refund(txId) {
|
|
109
|
+
return this.post("/api/refund", { txId });
|
|
110
|
+
}
|
|
111
|
+
/** Check wallet balance and reputation */
|
|
112
|
+
async balance() {
|
|
113
|
+
return this.post("/api/balance", {});
|
|
114
|
+
}
|
|
115
|
+
/** Full agent profile */
|
|
116
|
+
async profile() {
|
|
117
|
+
return this.post("/api/profile", {});
|
|
118
|
+
}
|
|
119
|
+
/** Transaction history */
|
|
120
|
+
async history(limit) {
|
|
121
|
+
return this.post("/api/history", { limit });
|
|
122
|
+
}
|
|
123
|
+
/** Audit logs */
|
|
124
|
+
async logs(limit) {
|
|
125
|
+
return this.post("/api/logs", { limit });
|
|
126
|
+
}
|
|
127
|
+
/** Reputation report */
|
|
128
|
+
async reputation() {
|
|
129
|
+
return this.post("/api/reputation", {});
|
|
130
|
+
}
|
|
131
|
+
/** File a dispute */
|
|
132
|
+
async dispute(txId, reason) {
|
|
133
|
+
return this.post("/api/dispute", { txId, reason });
|
|
134
|
+
}
|
|
135
|
+
/** Fraud detection stats */
|
|
136
|
+
async fraudStats() {
|
|
137
|
+
return this.post("/api/fraud_stats", {});
|
|
138
|
+
}
|
|
139
|
+
// ── Commerce ────────────────────────────────────────────────────────────
|
|
140
|
+
/** Set a shopping mandate (budget, categories, merchant restrictions) */
|
|
141
|
+
async setMandate(mandate) {
|
|
142
|
+
return this.request("POST", "/api/commerce/mandate", mandate);
|
|
143
|
+
}
|
|
144
|
+
/** Search for products within mandate constraints */
|
|
145
|
+
async search(query, options) {
|
|
146
|
+
return this.request("POST", "/api/commerce/search", { query, options });
|
|
147
|
+
}
|
|
148
|
+
/** Purchase a product (creates escrow, executes purchase) */
|
|
149
|
+
async purchase(product, deliveryInstructions) {
|
|
150
|
+
return this.request("POST", "/api/commerce/purchase", { product, deliveryInstructions });
|
|
151
|
+
}
|
|
152
|
+
/** Confirm delivery (settles escrow) */
|
|
153
|
+
async confirmDelivery(orderId) {
|
|
154
|
+
return this.request("POST", "/api/commerce/confirm", { orderId });
|
|
155
|
+
}
|
|
156
|
+
/** Cancel an order (refunds escrow) */
|
|
157
|
+
async cancelOrder(orderId, reason) {
|
|
158
|
+
return this.request("POST", "/api/commerce/cancel", { orderId, reason });
|
|
159
|
+
}
|
|
160
|
+
/** List orders, optionally filtered by status */
|
|
161
|
+
async orders(status) {
|
|
162
|
+
const qs = status ? `?status=${encodeURIComponent(status)}` : "";
|
|
163
|
+
return this.request("GET", `/api/commerce/orders${qs}`);
|
|
164
|
+
}
|
|
165
|
+
// ── Utility ─────────────────────────────────────────────────────────────
|
|
166
|
+
/** Check server health */
|
|
167
|
+
async health() {
|
|
168
|
+
return this.get("/health");
|
|
169
|
+
}
|
|
170
|
+
/** List available tools */
|
|
171
|
+
async tools() {
|
|
172
|
+
return this.get("/api/tools");
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
exports.MnemoPayClient = MnemoPayClient;
|
|
176
|
+
exports.default = MnemoPayClient;
|
|
177
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;;;AAiFH,+EAA+E;AAE/E,MAAa,cAAc;IACjB,OAAO,CAAS;IAChB,KAAK,CAAU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Ae;QACnC,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,uBAAuB,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;IACpE,CAAC;IAED,uCAAuC;IACvC,KAAK,CAAC,WAAW,CAAC,OAAe,EAAE,MAAe;QAChD,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,sBAAsB,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC;IAC3E,CAAC;IAED,iDAAiD;IACjD,KAAK,CAAC,MAAM,CAAC,MAAe;QAC1B,MAAM,EAAE,GAAG,MAAM,CAAC,CAAC,CAAC,WAAW,kBAAkB,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACjE,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,uBAAuB,EAAE,EAAE,CAAC,CAAC;IAC1D,CAAC;IAED,2EAA2E;IAE3E,0BAA0B;IAC1B,KAAK,CAAC,MAAM;QACV,OAAO,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IAC7B,CAAC;IAED,2BAA2B;IAC3B,KAAK,CAAC,KAAK;QACT,OAAO,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;IAChC,CAAC;CACF;AA5LD,wCA4LC;AAED,kBAAe,cAAc,CAAC"}
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Commerce Engine for MnemoPay
|
|
3
|
+
*
|
|
4
|
+
* Autonomous shopping for AI agents. An agent can search products, compare
|
|
5
|
+
* prices, create a purchase order, pay via escrow, and confirm delivery.
|
|
6
|
+
* Every purchase is scoped by a ShoppingMandate — cryptographically enforced
|
|
7
|
+
* spend limits, category restrictions, and merchant whitelists.
|
|
8
|
+
*
|
|
9
|
+
* The escrow flow:
|
|
10
|
+
* 1. Agent searches products → returns ranked results
|
|
11
|
+
* 2. Agent (or user) approves a purchase → creates a PurchaseOrder
|
|
12
|
+
* 3. SDK calls charge() to hold funds in escrow
|
|
13
|
+
* 4. Agent executes the purchase via the commerce provider
|
|
14
|
+
* 5. On delivery confirmation → settle() releases funds
|
|
15
|
+
* 6. On failure/cancellation → refund() returns funds
|
|
16
|
+
*
|
|
17
|
+
* Security model:
|
|
18
|
+
* - ShoppingMandate defines what the agent CAN buy (budget, categories, merchants)
|
|
19
|
+
* - Every purchase validated against mandate before escrow is created
|
|
20
|
+
* - Purchases above approvalThreshold require explicit user confirmation
|
|
21
|
+
* - Full audit trail via MnemoPay's existing audit system
|
|
22
|
+
* - Agent remembers user preferences (sizes, brands, past purchases)
|
|
23
|
+
*
|
|
24
|
+
* Usage:
|
|
25
|
+
* const agent = MnemoPay.quick("shopper");
|
|
26
|
+
* const commerce = new CommerceEngine(agent);
|
|
27
|
+
* commerce.setMandate({ budget: 200, categories: ["electronics"] });
|
|
28
|
+
* const results = await commerce.search("USB-C cable under $15");
|
|
29
|
+
* const order = await commerce.purchase(results[0]);
|
|
30
|
+
* // ... later, on delivery ...
|
|
31
|
+
* await commerce.confirmDelivery(order.id);
|
|
32
|
+
*/
|
|
33
|
+
export interface ShoppingMandate {
|
|
34
|
+
/** Maximum total budget for this mandate (USD) */
|
|
35
|
+
budget: number;
|
|
36
|
+
/** Maximum per-item spend (USD). Defaults to budget. */
|
|
37
|
+
maxPerItem?: number;
|
|
38
|
+
/** Allowed product categories (empty = any) */
|
|
39
|
+
categories?: string[];
|
|
40
|
+
/** Blocked product categories */
|
|
41
|
+
blockedCategories?: string[];
|
|
42
|
+
/** Allowed merchant domains (empty = any) */
|
|
43
|
+
allowedMerchants?: string[];
|
|
44
|
+
/** Blocked merchant domains */
|
|
45
|
+
blockedMerchants?: string[];
|
|
46
|
+
/** Purchases above this amount require user approval callback (USD) */
|
|
47
|
+
approvalThreshold?: number;
|
|
48
|
+
/** Mandate expiry (ISO timestamp). Defaults to 24h from creation. */
|
|
49
|
+
expiresAt?: string;
|
|
50
|
+
/** Who issued this mandate (user ID or "system") */
|
|
51
|
+
issuedBy: string;
|
|
52
|
+
}
|
|
53
|
+
export interface ProductResult {
|
|
54
|
+
/** Unique product ID from the provider */
|
|
55
|
+
productId: string;
|
|
56
|
+
/** Product title */
|
|
57
|
+
title: string;
|
|
58
|
+
/** Price in USD */
|
|
59
|
+
price: number;
|
|
60
|
+
/** Currency (default USD) */
|
|
61
|
+
currency?: string;
|
|
62
|
+
/** Product URL */
|
|
63
|
+
url: string;
|
|
64
|
+
/** Image URL */
|
|
65
|
+
imageUrl?: string;
|
|
66
|
+
/** Merchant/seller name */
|
|
67
|
+
merchant: string;
|
|
68
|
+
/** Merchant domain */
|
|
69
|
+
merchantDomain?: string;
|
|
70
|
+
/** Product category */
|
|
71
|
+
category?: string;
|
|
72
|
+
/** Rating (0-5) */
|
|
73
|
+
rating?: number;
|
|
74
|
+
/** Number of reviews */
|
|
75
|
+
reviewCount?: number;
|
|
76
|
+
/** Estimated delivery days */
|
|
77
|
+
deliveryDays?: number;
|
|
78
|
+
/** Whether free shipping */
|
|
79
|
+
freeShipping?: boolean;
|
|
80
|
+
/** Raw provider data */
|
|
81
|
+
raw?: Record<string, unknown>;
|
|
82
|
+
}
|
|
83
|
+
export interface PurchaseOrder {
|
|
84
|
+
/** Unique order ID */
|
|
85
|
+
id: string;
|
|
86
|
+
/** Agent ID that placed the order */
|
|
87
|
+
agentId: string;
|
|
88
|
+
/** Product being purchased */
|
|
89
|
+
product: ProductResult;
|
|
90
|
+
/** MnemoPay transaction ID (escrow) */
|
|
91
|
+
txId: string;
|
|
92
|
+
/** Order status */
|
|
93
|
+
status: "pending_approval" | "escrowed" | "purchased" | "shipped" | "delivered" | "cancelled" | "failed";
|
|
94
|
+
/** Shipping address or delivery instructions */
|
|
95
|
+
deliveryInstructions?: string;
|
|
96
|
+
/** Tracking number */
|
|
97
|
+
trackingNumber?: string;
|
|
98
|
+
/** Tracking URL */
|
|
99
|
+
trackingUrl?: string;
|
|
100
|
+
/** Created timestamp */
|
|
101
|
+
createdAt: Date;
|
|
102
|
+
/** Last updated */
|
|
103
|
+
updatedAt: Date;
|
|
104
|
+
/** Mandate snapshot at time of purchase */
|
|
105
|
+
mandate: ShoppingMandate;
|
|
106
|
+
/** User approval status */
|
|
107
|
+
approved: boolean;
|
|
108
|
+
/** Failure reason if failed */
|
|
109
|
+
failureReason?: string;
|
|
110
|
+
}
|
|
111
|
+
export type ApprovalCallback = (order: PurchaseOrder) => Promise<boolean>;
|
|
112
|
+
/**
|
|
113
|
+
* Product search provider interface. Implement this to connect
|
|
114
|
+
* any product catalog (eBay, custom API, local inventory, etc.)
|
|
115
|
+
*/
|
|
116
|
+
export interface CommerceProvider {
|
|
117
|
+
readonly name: string;
|
|
118
|
+
/** Search for products matching a query */
|
|
119
|
+
search(query: string, options?: SearchOptions): Promise<ProductResult[]>;
|
|
120
|
+
/** Get full product details by ID */
|
|
121
|
+
getProduct(productId: string): Promise<ProductResult | null>;
|
|
122
|
+
/** Execute a purchase (returns external order reference) */
|
|
123
|
+
executePurchase(product: ProductResult, deliveryInstructions?: string): Promise<{
|
|
124
|
+
externalOrderId: string;
|
|
125
|
+
status: string;
|
|
126
|
+
trackingUrl?: string;
|
|
127
|
+
}>;
|
|
128
|
+
/** Check order/delivery status */
|
|
129
|
+
checkStatus(externalOrderId: string): Promise<{
|
|
130
|
+
status: string;
|
|
131
|
+
trackingNumber?: string;
|
|
132
|
+
trackingUrl?: string;
|
|
133
|
+
deliveredAt?: string;
|
|
134
|
+
}>;
|
|
135
|
+
}
|
|
136
|
+
export interface SearchOptions {
|
|
137
|
+
/** Maximum results to return (default: 10) */
|
|
138
|
+
limit?: number;
|
|
139
|
+
/** Minimum price filter */
|
|
140
|
+
minPrice?: number;
|
|
141
|
+
/** Maximum price filter */
|
|
142
|
+
maxPrice?: number;
|
|
143
|
+
/** Category filter */
|
|
144
|
+
category?: string;
|
|
145
|
+
/** Sort by: "price_asc", "price_desc", "rating", "relevance" */
|
|
146
|
+
sortBy?: "price_asc" | "price_desc" | "rating" | "relevance";
|
|
147
|
+
/** Free shipping only */
|
|
148
|
+
freeShippingOnly?: boolean;
|
|
149
|
+
}
|
|
150
|
+
export declare class MockCommerceProvider implements CommerceProvider {
|
|
151
|
+
readonly name = "mock";
|
|
152
|
+
private counter;
|
|
153
|
+
private catalog;
|
|
154
|
+
search(query: string, options?: SearchOptions): Promise<ProductResult[]>;
|
|
155
|
+
getProduct(productId: string): Promise<ProductResult | null>;
|
|
156
|
+
executePurchase(product: ProductResult, _deliveryInstructions?: string): Promise<{
|
|
157
|
+
externalOrderId: string;
|
|
158
|
+
status: string;
|
|
159
|
+
trackingUrl?: string;
|
|
160
|
+
}>;
|
|
161
|
+
checkStatus(externalOrderId: string): Promise<{
|
|
162
|
+
status: string;
|
|
163
|
+
trackingNumber?: string;
|
|
164
|
+
trackingUrl?: string;
|
|
165
|
+
deliveredAt?: string;
|
|
166
|
+
}>;
|
|
167
|
+
}
|
|
168
|
+
export declare class CommerceEngine {
|
|
169
|
+
private agent;
|
|
170
|
+
private provider;
|
|
171
|
+
private mandate;
|
|
172
|
+
private orders;
|
|
173
|
+
private totalSpent;
|
|
174
|
+
private approvalCallback;
|
|
175
|
+
private externalOrderMap;
|
|
176
|
+
constructor(agent: any, provider?: CommerceProvider);
|
|
177
|
+
/**
|
|
178
|
+
* Set a shopping mandate that defines what this agent can buy.
|
|
179
|
+
* All purchases are validated against this mandate.
|
|
180
|
+
*/
|
|
181
|
+
setMandate(mandate: ShoppingMandate): void;
|
|
182
|
+
/** Get the current active mandate */
|
|
183
|
+
getMandate(): ShoppingMandate | null;
|
|
184
|
+
/** Remaining budget under current mandate */
|
|
185
|
+
get remainingBudget(): number;
|
|
186
|
+
/** Set a callback for user approval of high-value purchases */
|
|
187
|
+
onApprovalRequired(callback: ApprovalCallback): void;
|
|
188
|
+
/**
|
|
189
|
+
* Search for products. Uses agent memory to personalize results
|
|
190
|
+
* (e.g., preferred brands, past purchase satisfaction).
|
|
191
|
+
*/
|
|
192
|
+
search(query: string, options?: SearchOptions): Promise<ProductResult[]>;
|
|
193
|
+
/**
|
|
194
|
+
* Create a purchase order for a product. Validates against mandate,
|
|
195
|
+
* creates escrow hold, optionally requests user approval.
|
|
196
|
+
*/
|
|
197
|
+
purchase(product: ProductResult, deliveryInstructions?: string): Promise<PurchaseOrder>;
|
|
198
|
+
/**
|
|
199
|
+
* Confirm delivery of an order. Settles the escrow, releasing funds.
|
|
200
|
+
*/
|
|
201
|
+
confirmDelivery(orderId: string): Promise<PurchaseOrder>;
|
|
202
|
+
/**
|
|
203
|
+
* Cancel an order and refund the escrow.
|
|
204
|
+
*/
|
|
205
|
+
cancelOrder(orderId: string, reason?: string): Promise<PurchaseOrder>;
|
|
206
|
+
/**
|
|
207
|
+
* Check delivery status of an order via the commerce provider.
|
|
208
|
+
*/
|
|
209
|
+
checkDeliveryStatus(orderId: string): Promise<PurchaseOrder>;
|
|
210
|
+
/** Get an order by ID */
|
|
211
|
+
getOrder(orderId: string): PurchaseOrder | null;
|
|
212
|
+
/** List all orders */
|
|
213
|
+
listOrders(status?: PurchaseOrder["status"]): PurchaseOrder[];
|
|
214
|
+
/** Get spending summary under current mandate */
|
|
215
|
+
spendingSummary(): {
|
|
216
|
+
totalSpent: number;
|
|
217
|
+
remainingBudget: number;
|
|
218
|
+
orderCount: number;
|
|
219
|
+
deliveredCount: number;
|
|
220
|
+
pendingCount: number;
|
|
221
|
+
};
|
|
222
|
+
/** Validate a product against the current mandate. Returns null if OK, or violation string. */
|
|
223
|
+
private validateProduct;
|
|
224
|
+
}
|
|
225
|
+
//# sourceMappingURL=commerce.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commerce.d.ts","sourceRoot":"","sources":["../src/commerce.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAIH,MAAM,WAAW,eAAe;IAC9B,kDAAkD;IAClD,MAAM,EAAE,MAAM,CAAC;IACf,wDAAwD;IACxD,UAAU,CAAC,EAAE,M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