@envarai/envarpay 0.2.0-alpha.2 → 0.2.0-alpha.3

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.
@@ -1,7 +1,7 @@
1
1
  import { timingSafeEqual } from 'node:crypto';
2
2
  import { AgentCard, Role, Task, TaskState, SendMessageRequest } from '@a2a-js/sdk';
3
3
  import { DefaultRequestHandler, JsonRpcTransportHandler, ServerCallContext } from '@a2a-js/sdk/server';
4
- import { RequestMalformedError, TaskNotFoundError, UnsupportedOperationError } from '@a2a-js/sdk/errors';
4
+ import { ContentTypeNotSupportedError, RequestMalformedError, TaskNotFoundError, UnsupportedOperationError, VersionNotSupportedError } from '@a2a-js/sdk/errors';
5
5
  import { Ajv2020 } from 'ajv/dist/2020.js';
6
6
  import addFormatsImport from 'ajv-formats';
7
7
  import { createOfferCard, offerPath } from './card.js';
@@ -267,8 +267,6 @@ export class CommerceServer {
267
267
  const caller = await this.options.authenticate(request);
268
268
  if (!caller)
269
269
  return Response.json({ error: 'authentication_required' }, { status: 401, headers: { 'WWW-Authenticate': 'Bearer', 'Cache-Control': 'no-store' } });
270
- if (request.headers.get('A2A-Version') !== '1.0')
271
- return Response.json({ error: 'A2A-Version 1.0 required' }, { status: 400 });
272
270
  if (Number(request.headers.get('Content-Length') ?? 0) > 1024 * 1024)
273
271
  return Response.json({ error: 'request_too_large' }, { status: 413 });
274
272
  let size = 0;
@@ -291,12 +289,18 @@ export class CommerceServer {
291
289
  let requestId = null;
292
290
  try {
293
291
  const raw = JSON.parse(body);
294
- if (raw.method === 'SendMessage' && this.workerFailed)
295
- return Response.json({ error: 'worker_unavailable' }, { status: 503, headers: { 'Cache-Control': 'no-store' } });
296
292
  if (!raw || Array.isArray(raw) || typeof raw !== 'object')
297
293
  throw new RequestMalformedError('A single JSONRPC object is required');
298
294
  requestId = raw.id ?? null;
299
295
  const params = raw.params;
296
+ // Parse only the bounded envelope to preserve its request ID. Reject these
297
+ // transport conditions before any quote, payment gate or Task dispatch.
298
+ if (request.headers.get('A2A-Version') !== '1.0')
299
+ throw new VersionNotSupportedError('This service supports A2A-Version 1.0');
300
+ if (request.headers.get('Content-Type')?.split(';', 1)[0]?.trim().toLowerCase() !== 'application/json')
301
+ throw new ContentTypeNotSupportedError('Send application/json to this JSON-RPC endpoint');
302
+ if (raw.method === 'SendMessage' && this.workerFailed)
303
+ return Response.json({ error: 'worker_unavailable' }, { status: 503, headers: { 'Cache-Control': 'no-store' } });
300
304
  if (params && typeof params === 'object' && 'tenant' in params && params.tenant !== route.tenant)
301
305
  return Response.json({ jsonrpc: '2.0', id: raw.id ?? null, error: { code: -32602, message: 'Invalid tenant' } }, { status: 200 });
302
306
  let paymentHeaders = {};
@@ -329,7 +333,7 @@ export class CommerceServer {
329
333
  }
330
334
  catch (error) {
331
335
  const mapped = error instanceof CommerceError ? { code: -32000, message: error.message, data: { code: error.code } } : JsonRpcTransportHandler.mapToJSONRPCError(error);
332
- return Response.json({ jsonrpc: '2.0', id: requestId, error: mapped }, { headers: { 'Cache-Control': 'no-store' } });
336
+ return Response.json({ jsonrpc: '2.0', id: requestId, error: mapped }, { headers: { 'A2A-Version': '1.0', 'Cache-Control': 'no-store' } });
333
337
  }
334
338
  }
335
339
  async continueTask(params, input, service, offerId, context) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@envarai/envarpay",
3
- "version": "0.2.0-alpha.2",
3
+ "version": "0.2.0-alpha.3",
4
4
  "description": "Independent A2A service commerce, budgeted buyers and x402/MPP payments",
5
5
  "type": "module",
6
6
  "license": "MIT",