m2m-market 2.7.0 → 2.8.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/README.md +13 -0
- package/index.d.ts +8 -0
- package/index.js +12 -4
- package/package.json +1 -1
- package/protocols.js +1 -1
package/README.md
CHANGED
|
@@ -151,6 +151,19 @@ With `candidateId` and a `null` need, the request is sent as given:
|
|
|
151
151
|
- Each attempt uses its own key derived from your `idempotencyKey` and the listing, so repeating a call never pays twice.
|
|
152
152
|
- Input is checked against the listing's schema before anything is signed or charged. A refusal rejects the promise with the reason in `error.payload.code` (`input_required`, `input_invalid` with a `fields` list, `candidate_not_consumable`, `method_mismatch`, `input_too_large`, and others). Nothing is charged.
|
|
153
153
|
|
|
154
|
+
### Status and payment
|
|
155
|
+
A purchase result also carries two standard fields, lifted to the top level from `purchase`
|
|
156
|
+
when a purchase happened (they are absent for `planned`, `needs_input`, `no_match` and
|
|
157
|
+
`over_price_cap`). `status` and `purchase` keep their existing values.
|
|
158
|
+
|
|
159
|
+
| Field | Values |
|
|
160
|
+
|---|---|
|
|
161
|
+
| `standard_status` | `Pending`, `Completed`, `Failed` |
|
|
162
|
+
| `standard_payment` | `Pending`, `Charged`, `Refunded` |
|
|
163
|
+
|
|
164
|
+
External purchases also carry the fee, when M2M has recorded it: `protocol_fee_m2m`,
|
|
165
|
+
`protocol_fee_bps`, `seller_m2m` and `fee_state` (`held`, `charged` or `returned`).
|
|
166
|
+
|
|
154
167
|
### Pending and rejected purchases
|
|
155
168
|
If `status` is `pending`, collect the result with the request in `resume`. The same
|
|
156
169
|
key is never paid twice:
|
package/index.d.ts
CHANGED
|
@@ -80,6 +80,14 @@ export interface BuyExternalResult extends JsonObject {
|
|
|
80
80
|
candidate_id?: string;
|
|
81
81
|
idempotency_key?: string;
|
|
82
82
|
attempts?: Array<{ candidate_id: string; outcome: string }>;
|
|
83
|
+
/** Lifted from purchase when a purchase happened. Absent for planned, needs_input, no_match and over_price_cap. */
|
|
84
|
+
standard_status?: 'Pending' | 'Completed' | 'Failed';
|
|
85
|
+
standard_payment?: 'Pending' | 'Charged' | 'Refunded';
|
|
86
|
+
/** Fee fields of an external purchase, when recorded. Amounts are M2M units as strings. */
|
|
87
|
+
protocol_fee_m2m?: string;
|
|
88
|
+
protocol_fee_bps?: number;
|
|
89
|
+
seller_m2m?: string;
|
|
90
|
+
fee_state?: 'held' | 'charged' | 'returned';
|
|
83
91
|
candidates?: BuyExternalCandidate[];
|
|
84
92
|
/** Dry run only: other listings with price and any missing fields. */
|
|
85
93
|
alternatives?: BuyExternalCandidate[];
|
package/index.js
CHANGED
|
@@ -33,12 +33,18 @@ function deprecated(name, replacement) {
|
|
|
33
33
|
process.emitWarning(`${name} is deprecated; use ${replacement}`, "DeprecationWarning");
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
+
// Standard status, payment and fee fields the server puts on `purchase`. Copied to the top level
|
|
37
|
+
// when present (additive: `purchase` and `status` keep their values).
|
|
38
|
+
const LIFTED_PURCHASE_FIELDS = ["standard_status", "standard_payment", "protocol_fee_m2m", "protocol_fee_bps", "seller_m2m", "fee_state"];
|
|
36
39
|
// Shape a purchase reply: status, candidate, attempts and, when pending, a resume request.
|
|
37
40
|
function finishExternal(result, candidateId, key, options, attempts) {
|
|
38
41
|
const purchase = result.purchase && typeof result.purchase === "object" ? result.purchase : {};
|
|
39
42
|
const status = String(purchase.status || result.status || "");
|
|
40
43
|
attempts.push({ candidate_id: candidateId, outcome: status });
|
|
41
44
|
const out = { ...result, status, candidate_id: candidateId, attempts };
|
|
45
|
+
for (const field of LIFTED_PURCHASE_FIELDS) {
|
|
46
|
+
if (Object.prototype.hasOwnProperty.call(purchase, field)) out[field] = purchase[field];
|
|
47
|
+
}
|
|
42
48
|
if (status === "pending") {
|
|
43
49
|
const values = {};
|
|
44
50
|
if (Object.prototype.hasOwnProperty.call(options, "body")) values.body = options.body;
|
|
@@ -48,7 +54,7 @@ function finishExternal(result, candidateId, key, options, attempts) {
|
|
|
48
54
|
return out;
|
|
49
55
|
}
|
|
50
56
|
|
|
51
|
-
export const SDK_VERSION = "2.
|
|
57
|
+
export const SDK_VERSION = "2.8.1";
|
|
52
58
|
|
|
53
59
|
const ms = (value) => Math.max(0, Math.round(value));
|
|
54
60
|
|
|
@@ -143,7 +149,7 @@ export class M2MConnectionClient {
|
|
|
143
149
|
_sendTiming(target, agent) {
|
|
144
150
|
if (!this.reportTiming || !agent || agent.call_total_ms === undefined) return;
|
|
145
151
|
const controller = new AbortController();
|
|
146
|
-
const timer = setTimeout(() => controller.abort(),
|
|
152
|
+
const timer = setTimeout(() => controller.abort(), 5000);
|
|
147
153
|
if (typeof timer.unref === "function") timer.unref();
|
|
148
154
|
Promise.resolve()
|
|
149
155
|
.then(() => this.fetchImpl(`${this.baseUrl}/connect/timing`, {
|
|
@@ -296,9 +302,11 @@ export class M2MConnectionClient {
|
|
|
296
302
|
}
|
|
297
303
|
|
|
298
304
|
/** @deprecated Use buyExternal(null, { body, query }, { candidateId, idempotencyKey }). */
|
|
299
|
-
purchaseExternal(candidateId, options) {
|
|
305
|
+
async purchaseExternal(candidateId, options) {
|
|
300
306
|
deprecated("purchaseExternal", "buyExternal(null, { body, query }, { candidateId, idempotencyKey })");
|
|
301
|
-
|
|
307
|
+
const result = await this._purchaseExternal(candidateId, options);
|
|
308
|
+
if (!(options && options.dryRun)) this._sendTiming({ idempotency_key: result.idempotency_key }, { ...this._lastTiming });
|
|
309
|
+
return result;
|
|
302
310
|
}
|
|
303
311
|
|
|
304
312
|
/**
|
package/package.json
CHANGED
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.
|
|
35
|
+
const client = new sdk.Client({ name: 'm2m-market', version: '2.8.1' });
|
|
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
|