feat(auth): add row/size caps + streaming to export-user-data
- Add per-collection row cap (default 10k, env EXPORT_ROW_CAP) via Prisma take on all findMany calls - Add total size cap (default 100MB, env EXPORT_SIZE_CAP_MB); throws PayloadTooLargeException (413) when exceeded - Convert response to Node.js Readable stream piped via NestJS StreamableFile to avoid large in-memory buffers - Export ExportUserDataResult interface (stream + truncated flag) from handler - Update controller to set Content-Type/Content-Disposition headers and return StreamableFile - Document EXPORT_ROW_CAP and EXPORT_SIZE_CAP_MB env vars in Swagger - Extend tests: row-cap assertion (take arg), size-cap 413 path, stream assertions Fixes GOO-223 (M-1 from GOO-200 audit). Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
52
libs/contracts/events/schemas/envelope.schema.json
Normal file
52
libs/contracts/events/schemas/envelope.schema.json
Normal file
@@ -0,0 +1,52 @@
|
||||
{
|
||||
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
||||
"$id": "https://goodgo.vn/schemas/events/envelope.schema.json",
|
||||
"title": "EventEnvelope",
|
||||
"description": "Cross-runtime event envelope for RFC-004 (GOO-95). Source of truth — Node and Python consumers validate against this file.",
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"required": [
|
||||
"schemaVersion",
|
||||
"eventId",
|
||||
"eventType",
|
||||
"occurredAt",
|
||||
"producer",
|
||||
"traceId",
|
||||
"payload"
|
||||
],
|
||||
"properties": {
|
||||
"schemaVersion": {
|
||||
"type": "integer",
|
||||
"const": 1,
|
||||
"description": "Envelope wire-format version. Currently 1."
|
||||
},
|
||||
"eventId": {
|
||||
"type": "string",
|
||||
"pattern": "^[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$",
|
||||
"description": "UUIDv7 — time-ordered. Used as idempotency key (30-day TTL in idempotency table)."
|
||||
},
|
||||
"eventType": {
|
||||
"type": "string",
|
||||
"pattern": "^[a-z][a-z0-9_]*(\\.[a-z][a-z0-9_]*)+$",
|
||||
"description": "Dotted event type, e.g. payment.completed."
|
||||
},
|
||||
"occurredAt": {
|
||||
"type": "string",
|
||||
"format": "date-time",
|
||||
"description": "ISO-8601 UTC timestamp of the domain event (not publish time)."
|
||||
},
|
||||
"producer": {
|
||||
"type": "string",
|
||||
"minLength": 1,
|
||||
"description": "Producing service identifier, e.g. api, ai-services."
|
||||
},
|
||||
"traceId": {
|
||||
"type": "string",
|
||||
"pattern": "^[0-9a-f]{32}$",
|
||||
"description": "OpenTelemetry-compatible 32-hex trace id. Use 32 zeros when no active span."
|
||||
},
|
||||
"payload": {
|
||||
"description": "Event-specific payload; validated separately against schemas/<eventType>.schema.json."
|
||||
}
|
||||
}
|
||||
}
|
||||
20
libs/contracts/events/schemas/kyc.verified.schema.json
Normal file
20
libs/contracts/events/schemas/kyc.verified.schema.json
Normal file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
||||
"$id": "https://goodgo.vn/schemas/events/kyc.verified.schema.json",
|
||||
"title": "kyc.verified",
|
||||
"description": "Emitted when a user's KYC review transitions to VERIFIED.",
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"required": ["userId", "verifiedByUserId", "level", "verifiedAt", "documentRefs"],
|
||||
"properties": {
|
||||
"userId": { "type": "string", "minLength": 1 },
|
||||
"verifiedByUserId": { "type": "string", "minLength": 1 },
|
||||
"level": { "type": "string", "enum": ["basic", "enhanced"] },
|
||||
"verifiedAt": { "type": "string", "format": "date-time" },
|
||||
"documentRefs": {
|
||||
"type": "array",
|
||||
"items": { "type": "string", "minLength": 1 },
|
||||
"description": "Opaque references (e.g. S3 keys) to the documents used for verification."
|
||||
}
|
||||
}
|
||||
}
|
||||
28
libs/contracts/events/schemas/listing.approved.schema.json
Normal file
28
libs/contracts/events/schemas/listing.approved.schema.json
Normal file
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
||||
"$id": "https://goodgo.vn/schemas/events/listing.approved.schema.json",
|
||||
"title": "listing.approved",
|
||||
"description": "Emitted when a Listing is approved by moderation and goes live.",
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"required": [
|
||||
"listingId",
|
||||
"propertyId",
|
||||
"agentId",
|
||||
"approvedByUserId",
|
||||
"approvedAt",
|
||||
"expiresAt"
|
||||
],
|
||||
"properties": {
|
||||
"listingId": { "type": "string", "minLength": 1 },
|
||||
"propertyId": { "type": "string", "minLength": 1 },
|
||||
"agentId": { "type": "string", "minLength": 1 },
|
||||
"approvedByUserId": { "type": "string", "minLength": 1 },
|
||||
"approvedAt": { "type": "string", "format": "date-time" },
|
||||
"expiresAt": {
|
||||
"type": ["string", "null"],
|
||||
"format": "date-time",
|
||||
"description": "Null when the listing has no scheduled expiry."
|
||||
}
|
||||
}
|
||||
}
|
||||
32
libs/contracts/events/schemas/payment.completed.schema.json
Normal file
32
libs/contracts/events/schemas/payment.completed.schema.json
Normal file
@@ -0,0 +1,32 @@
|
||||
{
|
||||
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
||||
"$id": "https://goodgo.vn/schemas/events/payment.completed.schema.json",
|
||||
"title": "payment.completed",
|
||||
"description": "Emitted when a Payment aggregate transitions to SUCCEEDED after a verified gateway IPN (VNPay / MoMo / ZaloPay).",
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"required": [
|
||||
"paymentId",
|
||||
"orderId",
|
||||
"userId",
|
||||
"amount",
|
||||
"currency",
|
||||
"gateway",
|
||||
"gatewayTransactionId",
|
||||
"paidAt"
|
||||
],
|
||||
"properties": {
|
||||
"paymentId": { "type": "string", "minLength": 1 },
|
||||
"orderId": { "type": "string", "minLength": 1 },
|
||||
"userId": { "type": "string", "minLength": 1 },
|
||||
"amount": {
|
||||
"type": "string",
|
||||
"pattern": "^-?\\d+(\\.\\d+)?$",
|
||||
"description": "Decimal as string to preserve VND precision (no float rounding)."
|
||||
},
|
||||
"currency": { "type": "string", "enum": ["VND", "USD"] },
|
||||
"gateway": { "type": "string", "enum": ["vnpay", "momo", "zalopay"] },
|
||||
"gatewayTransactionId": { "type": "string", "minLength": 1 },
|
||||
"paidAt": { "type": "string", "format": "date-time" }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user