m2m-market 2.2.0 → 2.3.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 CHANGED
@@ -99,6 +99,24 @@ try {
99
99
  console.log(await M2MConnectionClient.fromEnvironment().testConnection());
100
100
  ```
101
101
 
102
+ ## Buy an x402 resource
103
+
104
+ M2M can buy resources listed in the x402 Bazaar for your Agent. M2M pays the
105
+ seller in USDC on Base and charges your Agent's M2M balance, within the limits
106
+ M2M sets for your account. Search matches whole words.
107
+
108
+ ```js
109
+ const found = await client.searchExternal("supported chains rpcs explorers", { limit: 10 });
110
+ const listing = found.listings[0]; // candidate_id, name, price_usdc_base_units, resource_url
111
+
112
+ const result = await client.purchaseExternal(listing.candidate_id);
113
+ console.log(result.purchase.status, result.purchase.response);
114
+ ```
115
+
116
+ Keep `result.idempotency_key`. If the result is `pending`, call
117
+ `purchaseExternal(candidateId, { idempotencyKey })` again with the same key
118
+ to get the outcome. The same key is never paid twice.
119
+
102
120
  ## OpenAI-compatible tool
103
121
 
104
122
  ```bash
package/index.d.ts CHANGED
@@ -70,6 +70,10 @@ export class M2MConnectionClient {
70
70
  submit(options: SubmitOptions): Promise<JsonObject>;
71
71
  /** Preview matching services without reserving funds or invoking a Provider. */
72
72
  discover(options?: DiscoverOptions): Promise<JsonObject>;
73
+ /** Buy one external x402 Bazaar resource for this Agent. Reuse idempotencyKey to fetch a pending result. */
74
+ /** Find x402 Bazaar resources M2M can buy for this Agent (read-only). */
75
+ searchExternal(intent: string, options?: { limit?: number; cursor?: string }): Promise<JsonObject>;
76
+ purchaseExternal(candidateId: string, options?: { idempotencyKey?: string }): Promise<JsonObject>;
73
77
  /** Evidence only; does not change settlement, reputation or ranking. */
74
78
  submitAcceptance(queryId: string, options: { acceptanceId: string; accepted: boolean }): Promise<JsonObject>;
75
79
  getQueryStatus(queryId: string): Promise<JsonObject>;
package/index.js CHANGED
@@ -171,6 +171,31 @@ export class M2MConnectionClient {
171
171
  return result.discovery;
172
172
  }
173
173
 
174
+ /**
175
+ * Buy one external x402 resource (an x402 Bazaar discovery candidate) for this Agent.
176
+ * M2M pays the seller in USDC on Base and charges the Agent's M2M balance within M2M's limits.
177
+ * Keep the returned idempotencyKey: if the result is pending, call again with the same key.
178
+ * The same key is never paid twice.
179
+ */
180
+ /** Find x402 Bazaar resources M2M can buy for this Agent (read-only). Search matches whole words. */
181
+ searchExternal(intent, { limit = 10, cursor } = {}) {
182
+ if (!String(intent || "").trim()) throw new Error("intent is required");
183
+ const body = { intent: String(intent).trim(), limit };
184
+ if (cursor) body.cursor = cursor;
185
+ return this.request("POST", "/connect/x402/search", body);
186
+ }
187
+
188
+ async purchaseExternal(candidateId, { idempotencyKey } = {}) {
189
+ const key = String(idempotencyKey || randomUUID());
190
+ if (key.length < 8 || key.length > 128) throw new Error("idempotencyKey must be 8-128 characters");
191
+ if (!String(candidateId || "").trim()) throw new Error("candidateId is required");
192
+ const result = await this.request("POST", "/connect/x402/purchase", {
193
+ candidate_id: String(candidateId).trim(),
194
+ idempotency_key: key,
195
+ });
196
+ return { idempotency_key: key, ...result };
197
+ }
198
+
174
199
  /** Evidence only: does not change settlement, reputation or ranking. */
175
200
  submitAcceptance(queryId, { acceptanceId, accepted } = {}) {
176
201
  if (typeof accepted !== "boolean") throw new TypeError("accepted must be a boolean");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "m2m-market",
3
- "version": "2.2.0",
3
+ "version": "2.3.0",
4
4
  "description": "Customer SDK for connecting AI Agents to M2M Market",
5
5
  "author": "M2M Market, Inc.",
6
6
  "type": "module",
package/protocols.js CHANGED
@@ -32,7 +32,7 @@ export async function connectMcp({ accessToken, timeoutMs = 30000, fetchImpl = g
32
32
  const transport = new sdk.StreamableHTTPClientTransport(new URL(MCP_RESOURCE), {
33
33
  fetch: guardedFetch, reconnectionOptions: { maxRetries: 0, initialReconnectionDelay: 1000, maxReconnectionDelay: 1000, reconnectionDelayGrowFactor: 1 }
34
34
  });
35
- const client = new sdk.Client({ name: 'm2m-market', version: '2.2.0' });
35
+ const client = new sdk.Client({ name: 'm2m-market', version: '2.3.0' });
36
36
  try { await client.connect(transport); }
37
37
  catch { await client.close().catch(() => {}); throw new M2MAPIError('mcp_connection_failed'); }
38
38
  return client; // caller closes it in finally; no automatic paid call or replay