@evomap/evolver-adapter-public 2.0.29 → 2.0.31
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/wireMap.d.ts +1 -1
- package/dist/wireMap.js +76 -16
- package/package.json +2 -2
package/dist/wireMap.d.ts
CHANGED
|
@@ -26,5 +26,5 @@ export type AtpRetryClass = 'permanent' | 'cooldown' | 'recoverable';
|
|
|
26
26
|
* cooldown → backoff, recoverable → retry next tick. Same map, different retry policy per caller.
|
|
27
27
|
*/
|
|
28
28
|
export declare function atpRetryClass(status: number): AtpRetryClass;
|
|
29
|
-
/** /a2a/publish 响应 → PublishReceipt.
|
|
29
|
+
/** /a2a/publish 响应 → PublishReceipt. 2xx 必须包含显式成功/拒绝决议;缺失或畸形回执 fail closed. */
|
|
30
30
|
export declare function publishRespToReceipt(status: number, body: Record<string, unknown>, retryAfterMs?: number): hub.PublishReceipt;
|
package/dist/wireMap.js
CHANGED
|
@@ -64,29 +64,62 @@ export function atpRetryClass(status) {
|
|
|
64
64
|
return 'cooldown';
|
|
65
65
|
return 'recoverable';
|
|
66
66
|
}
|
|
67
|
-
/** /a2a/publish 响应 → PublishReceipt.
|
|
67
|
+
/** /a2a/publish 响应 → PublishReceipt. 2xx 必须包含显式成功/拒绝决议;缺失或畸形回执 fail closed. */
|
|
68
68
|
export function publishRespToReceipt(status, body, retryAfterMs) {
|
|
69
|
-
const
|
|
70
|
-
const
|
|
71
|
-
const
|
|
72
|
-
|
|
69
|
+
const bodyRecord = isRecord(body) ? body : {};
|
|
70
|
+
const rawPayload = bodyRecord['payload'];
|
|
71
|
+
const malformedPayload = rawPayload !== undefined && !isRecord(rawPayload);
|
|
72
|
+
const payload = isRecord(rawPayload) ? rawPayload : bodyRecord;
|
|
73
|
+
const rawAssetIds = payload['asset_ids'];
|
|
74
|
+
const malformedAssetIds = rawAssetIds !== undefined
|
|
75
|
+
&& (!Array.isArray(rawAssetIds) || rawAssetIds.some((value) => typeof value !== 'string'));
|
|
76
|
+
const assetIds = !malformedAssetIds && Array.isArray(rawAssetIds) ? rawAssetIds : undefined;
|
|
77
|
+
const targetAssetId = stringField(payload, 'target_asset_id') ?? stringField(bodyRecord, 'target_asset_id');
|
|
73
78
|
const assetId = (status === 409 ? targetAssetId : undefined)
|
|
74
|
-
?? payload
|
|
75
|
-
??
|
|
79
|
+
?? stringField(payload, 'asset_id')
|
|
80
|
+
?? stringField(bodyRecord, 'asset_id')
|
|
76
81
|
?? assetIds?.[0]
|
|
77
82
|
?? targetAssetId;
|
|
78
|
-
const bundleId = payload
|
|
83
|
+
const bundleId = stringField(payload, 'bundle_id');
|
|
84
|
+
const receiptId = nonBlankString(payload['receipt_id']);
|
|
85
|
+
const hasDecisionField = Object.prototype.hasOwnProperty.call(payload, 'decision');
|
|
86
|
+
const hasStatusField = Object.prototype.hasOwnProperty.call(payload, 'status');
|
|
87
|
+
const explicitDecision = explicitPublishDecision(payload['decision']);
|
|
88
|
+
const explicitStatus = explicitPublishDecision(payload['status']);
|
|
89
|
+
const decision = explicitDecision ?? explicitStatus;
|
|
90
|
+
const invalidDecisionField = (hasDecisionField && explicitDecision === undefined)
|
|
91
|
+
|| (hasStatusField && explicitStatus === undefined);
|
|
92
|
+
const accepted = decision === 'accepted';
|
|
93
|
+
const contradictory = hasDecisionField
|
|
94
|
+
&& hasStatusField
|
|
95
|
+
&& (explicitDecision === undefined || explicitStatus === undefined || explicitDecision !== explicitStatus);
|
|
96
|
+
const explicitError = hasFieldWithValue(payload, 'error') || hasFieldWithValue(bodyRecord, 'error');
|
|
97
|
+
const explicitOkFalse = payload['ok'] === false || bodyRecord['ok'] === false;
|
|
79
98
|
if (status >= 200 && status < 300) {
|
|
80
|
-
|
|
81
|
-
|
|
99
|
+
if (decision === undefined
|
|
100
|
+
|| malformedPayload
|
|
101
|
+
|| invalidDecisionField
|
|
102
|
+
|| contradictory
|
|
103
|
+
|| explicitError
|
|
104
|
+
|| explicitOkFalse
|
|
105
|
+
|| malformedAssetIds
|
|
106
|
+
|| (accepted && receiptId === undefined)) {
|
|
107
|
+
return {
|
|
108
|
+
receiptId: receiptId ?? 'malformed_receipt',
|
|
109
|
+
status: 'rejected',
|
|
110
|
+
terminal: true,
|
|
111
|
+
reason: 'malformed publish receipt',
|
|
112
|
+
rejection: { code: 'invalid_payload' },
|
|
113
|
+
};
|
|
114
|
+
}
|
|
82
115
|
return {
|
|
83
|
-
receiptId:
|
|
84
|
-
status:
|
|
116
|
+
receiptId: receiptId ?? 'rejected',
|
|
117
|
+
status: decision,
|
|
85
118
|
...(assetId ? { assetId } : {}),
|
|
86
119
|
...(bundleId ? { bundleId } : {}),
|
|
87
120
|
...(assetIds ? { assetIds } : {}),
|
|
88
|
-
...(payload['reason'] ? { reason:
|
|
89
|
-
terminal:
|
|
121
|
+
...(typeof payload['reason'] === 'string' && payload['reason'] ? { reason: payload['reason'] } : {}),
|
|
122
|
+
terminal: decision !== 'accepted', // quarantine/rejected 终态不重试
|
|
90
123
|
};
|
|
91
124
|
}
|
|
92
125
|
// M8-1: 按语义而非纯状态码区分(都终态不重试 = money-safety: 不反复打经济端点).
|
|
@@ -102,9 +135,9 @@ export function publishRespToReceipt(status, body, retryAfterMs) {
|
|
|
102
135
|
429: 'cooldown',
|
|
103
136
|
};
|
|
104
137
|
const receipt = {
|
|
105
|
-
receiptId:
|
|
138
|
+
receiptId: receiptId ?? 'rejected',
|
|
106
139
|
status: 'rejected',
|
|
107
|
-
reason:
|
|
140
|
+
reason: nonBlankString(payload['reason']) ?? reasonByStatus[status] ?? `hub ${status}`,
|
|
108
141
|
...(assetId ? { assetId } : {}),
|
|
109
142
|
...(assetIds ? { assetIds } : {}),
|
|
110
143
|
terminal: true,
|
|
@@ -122,4 +155,31 @@ export function publishRespToReceipt(status, body, retryAfterMs) {
|
|
|
122
155
|
};
|
|
123
156
|
}
|
|
124
157
|
return receipt;
|
|
158
|
+
}
|
|
159
|
+
function isRecord(value) {
|
|
160
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
161
|
+
}
|
|
162
|
+
function stringField(record, key) {
|
|
163
|
+
return typeof record[key] === 'string' ? record[key] : undefined;
|
|
164
|
+
}
|
|
165
|
+
function nonBlankString(value) {
|
|
166
|
+
if (typeof value !== 'string')
|
|
167
|
+
return undefined;
|
|
168
|
+
const valueTrimmed = value.trim();
|
|
169
|
+
return valueTrimmed.length > 0 ? valueTrimmed : undefined;
|
|
170
|
+
}
|
|
171
|
+
function hasFieldWithValue(record, key) {
|
|
172
|
+
return Object.prototype.hasOwnProperty.call(record, key) && record[key] !== undefined;
|
|
173
|
+
}
|
|
174
|
+
function explicitPublishDecision(value) {
|
|
175
|
+
if (typeof value !== 'string')
|
|
176
|
+
return undefined;
|
|
177
|
+
const normalized = value.trim();
|
|
178
|
+
if (normalized === 'accept' || normalized === 'accepted' || normalized === 'approved' || normalized === 'ok')
|
|
179
|
+
return 'accepted';
|
|
180
|
+
if (normalized === 'quarantine')
|
|
181
|
+
return 'quarantine';
|
|
182
|
+
if (normalized === 'reject' || normalized === 'rejected')
|
|
183
|
+
return 'rejected';
|
|
184
|
+
return undefined;
|
|
125
185
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@evomap/evolver-adapter-public",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.31",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"@evomap/atp-sdk": "^0.1.0",
|
|
20
|
-
"@evomap/evolver-core": "2.0.
|
|
20
|
+
"@evomap/evolver-core": "2.0.31",
|
|
21
21
|
"undici": "^6.27.0"
|
|
22
22
|
},
|
|
23
23
|
"optionalDependencies": {
|