Skip to content

Tham chiếu REST API ​

LatticeDX cung cấp hai bề mặt HTTP bổ trợ sau lớp biên kiểm soát chung (Caddy TLS và Apache APISIX): lớp API theo tài nguyên của NocoBase host tại /api/<resource>:<action> được bảo vệ bởi latticeNativeScope và PostgreSQL 16 FORCE ROW LEVEL SECURITY, cùng lớp dịch vụ lõi Fastify tại /v1/* cho tác vụ nghiệp vụ, tệp đính kèm, quy trình và đồng bộ ngữ cảnh.

Header xác thực và định tuyến qua Gateway ​

Mọi yêu cầu tới /api/* và /v1/* đi qua Apache APISIX (:9080 nội bộ, :8080 cục bộ) với header X-Request-Id tự động gắn ở lớp global và chính sách giới hạn tần suất lưu trên Valkey (limit-count).

Header HTTP chuẩn
Tham sốKiểuMặc địnhMô tả
Authorization
string—Bearer JWT từ phiên NocoBase/Keycloak OIDC hoặc khóa cá nhân định dạng Bearer ldx_pat_*.
X-Lattice-API-Key
string—Khóa truy cập cá nhân theo phạm vi (ldx_pat_<8hex>_<32hex>) thay thế cho Bearer token.
X-Role
string—Vai trò yêu cầu khi dùng phiên đa vai trò. Khi xác thực bằng ldx_pat_*, middleware ép giữ vai trò gắn với khóa.
X-Authenticator
string—Tên bộ xác thực NocoBase (mặc định basic hoặc lattice-keycloak).
X-Lattice-Edge-Token
string—Token xác thực thiết bị biên cho các route nạp dữ liệu IIoT công khai như telemetryIngest và deviceStatusIngest.
If-Match / X-Expected-Version
string—Kiểm soát đồng thời lạc quan (optimistic locking) khi cập nhật chứng từ hoặc tài sản (bắt buộc số nguyên dương).
Idempotency-Key
string—Khóa chống trùng lặp lệnh trên các endpoint tạo mới của Fastify /v1/*.
traceparent
string—Ngữ cảnh truy vết W3C Trace Context được lan truyền tới OpenTelemetry Collector.

APISIX áp dụng bốn ngưỡng limit-count theo nhóm đường dẫn (tính theo remote_addr trên cửa sổ 60 giây):

Nhóm tuyến APISIXĐường dẫn đại diệnNgưỡng (req/60s)Ghi chú
dxos-telemetry-ingest/api/dxosBlocks:telemetryIngest, /api/dxosBlocks:alarmIngest, /api/dxosBroker:deviceStatusIngest, /api/dxosBroker:orionNotify300Băng thông cao cho cảm biến biên và Orion-LD
dxos-core-api/api/*240Áp dụng cho toàn bộ tài nguyên CRUD và action nghiệp vụ
dxos-public-paas/api/dxos:openapi, /api/dxos:asyncapi, /api/dxosForms:*, /api/dxosWms:publicTrack, /.well-known/agent-card.json120Bảo vệ tài nguyên công khai khỏi quét tự động
dxos-enterprise-auth & dxos-mcp/api/enterpriseAuth:*, /api/dxos-oidc/*, /api/dxos-mcp/*120Cửa sổ 600s read/send timeout cho phiên MCP stream

Quy ước URL, Envelope và Phân trang ​

Bề mặt NocoBase (/api/<resource>:<action>) ​

Tài nguyên do NocoBase resourceManager.define đăng ký sử dụng dấu hai chấm ngăn cách tên tài nguyên và hành động, ví dụ /api/dxosWms:issueStock hoặc /api/latticeOrders:list?page=1&pageSize=20.

GET/api/latticeOrders:list?page=1&pageSize=20&sort=-id
Bearer JWT | X-Lattice-API-Keyread
Truy vấn danh sách đơn hàng đã được lọc tự động theo organizationId của tác nhân và PostgreSQL FORCE RLS.
POST/api/dxosWms:issueStock
Bearer JWT | X-Lattice-API-Keywrite | wms
Xuất kho theo lô FEFO và ghi nhận biến động tồn kho trong giao dịch RLS.

Phản hồi từ resourceManager tuân theo hai dạng envelope:

  1. Standard Data Wrapping (dataWrapping): Mặc định trả về { "data": <payload>, "meta": { "count": <n>, "page": <n>, "pageSize": <n>, "totalPage": <n> } } cho thao tác danh sách hoặc { "data": <object> } cho thao tác đơn lẻ.
  2. Raw Response (ctx.withoutDataWrapping = true): Trả trực tiếp JSON hoặc plain-text không bọc data, áp dụng trên /api/dxActions:*, /api/dxos:metrics (Prometheus exposition), /api/dxos:openapi, /api/dxos:asyncapi, /api/dxos-mcp, /api/dxos-mcp/it-ot, /api/dxos-a2a và /.well-known/agent-card.json.

Giới hạn phân trang và Bộ lọc an toàn (latticeNativeScope) ​

Middleware createNativeScopeMiddleware kiểm tra chặt mọi tham số truy vấn trước khi chuyển xuống Sequelize/PostgreSQL:

Tham số truy vấn chuẩn trên NocoBase
Tham sốKiểuMặc địnhMô tả
page
integer1Số trang trong khoảng 1..100000.
pageSize / limit
integer20Số bản ghi mỗi trang, bị kẹp cứng trong khoảng 1..200 (endpoint dxosApiKeys:list mặc định 50).
sort
string | string[]—Danh sách trường sắp xếp (tiền tố - để giảm dần). Từ chối tên chứa dấu chấm (.) hoặc từ khóa nhạy cảm.
filter
object | json—Bộ lọc Sequelize ($eq, $in, $and, $or, $startsWith). Tự động hợp nhất với { organizationId: actor.organizationId }.
expectedVersion
integer—Truyền qua body values.expectedVersion, query hoặc header If-Match. Trả 409 VERSION_CONFLICT nếu phiên bản hiện tại không khớp.

Các truy vấn vi phạm quy tắc bảo mật bị từ chối fail-closed:

Cơ chế bảo vệQuy tắc kiểm tra và mã lỗi
Chặn mở rộng quan hệ và toán tử thô (NATIVE_RELATION_EXPANSION_UNSUPPORTED)Từ chối appends, targetCollection, tên trường trong fields/sort chứa dấu chấm (ngoại trừ tự ánh xạ requester.userId và assignee.userId sang requesterId/assigneeId của chính người gọi), toán tử $where, $raw, $sql, khóa __proto__/constructor/prototype, hoặc tên trường khớp mẫu nhạy cảm (password, secret, token, apikey, privateKey, hash, salt).
Chặn ghi trực tiếp tài nguyên nhạy cảmTrừ vai trò root, các bảng latticeApiKeys, latticePkiKeys, latticeCryptoLedger, latticeConnectors, latticeWebhookSubscriptions, latticeTelemetryPoints, latticeTwinShadows, latticeIotDevices, latticeBrokerSubscriptions, latticeFrozenSnapshots, latticeDataLineage, latticeDataQuarantine và latticeOrganizations bị khóa truy cập REST trực tiếp (403 PAAS_PRIVATE_COLLECTION_FORBIDDEN hoặc mã chuyên biệt); ứng dụng bắt buộc gọi qua resource nghiệp vụ tương ứng (dxosApiKeys, dxosLedger, dxosVault, dxosEvents, dxosBlocks, dxosBroker, dxosDataGov, dxosBuilder).
Bất biến chứng từ (VOUCHER_IMMUTABLE)Với latticeRequests và latticeOrders, mọi yêu cầu cập nhật bản ghi ở trạng thái submitted, approved, completed hoặc cancelled trả về 409; thao tác xóa (destroy) bị chặn (NATIVE_DOCUMENT_DELETE_UNSUPPORTED). Quy trình điều chỉnh bắt buộc đi qua latticeVoucher:cancel và latticeVoucher:amend.

Danh mục 31 tài nguyên NocoBase (resourceManager.define) ​

Toàn bộ API nghiệp vụ được đăng ký trên 7 plugin Apache-2.0 chính thức trong plugins/nocobase/:

#Tài nguyênPlugin sở hữuHành động chính
1dxos@latticedx/plugin-lattice-foundationhealth, metrics, openapi, asyncapi, manifest, sw.js, icon-192.png, icon-512.png
2dxosApiKeys@latticedx/plugin-lattice-foundationissue, list, revoke
3dxosLedger@latticedx/plugin-lattice-foundationpublicKey, entries, status, verify, signDocument, verifySignature, rotateKey, exportProof
4dxosDataGov@latticedx/plugin-lattice-foundationtierSummary, freezeSnapshot, listSnapshots, lineage, listQuarantine, resolveQuarantine, computeMkt
5dxosVault@latticedx/plugin-lattice-foundationlist, save, rotateSecret, delete, testConnection
6dxosEvents@latticedx/plugin-lattice-foundationlistEvents, publish, listSubscriptions, saveSubscription, toggleSubscription, deleteSubscription, listDeliveries, dispatchNow, replayDlq, resetCircuit
7dxosApprovals@latticedx/plugin-lattice-foundationlistInbox, decide, request, cancel, listPolicies, savePolicy, deletePolicy, evaluateSlaNow
8dxosNotify@latticedx/plugin-lattice-foundationsend, testSend, logs, channels
9dxosForms@latticedx/plugin-lattice-foundationmeta, submit, status, list, get, save, delete, rotateToken
10latticeNative@latticedx/plugin-lattice-foundationcontext
11latticeApps@latticedx/plugin-lattice-foundationlist, get
12latticePortals@latticedx/plugin-lattice-foundationlist, save, compose
13latticeChatter@latticedx/plugin-lattice-foundationlist, post
14latticeVoucher@latticedx/plugin-lattice-foundationsubmit, cancel, amend, lineage
15latticeNotifications@latticedx/plugin-lattice-foundationlistMine, unreadCount, markRead, markAllRead
16latticeSla@latticedx/plugin-lattice-foundationsummary, policies, savePolicy, evaluateNow
17latticeContextSync@latticedx/plugin-lattice-foundationdispatch, status, retry
18latticeIntegrations@latticedx/plugin-lattice-foundationreceive, receiveAlert, propose, proposalReceipt, record, context, proposals
19latticePara@latticedx/plugin-dxos-parasummary, hybridSearch, extractAttachment, reindex
20dxosBlocks@latticedx/plugin-dxos-blocksproposals, decideProposal, contextTelemetry, telemetrySeries, telemetryIngest, alarmIngest, alarmAck, alarmClear, exportReport, globalSearch, twinShadow, twinSetDesired, twinAckCommand, bulkImportDryRun, bulkImportCommit, collectionsMeta, aggregateQuery
21dxosBroker@latticedx/plugin-dxos-blockslistDevices, provisionDevice, revokeDevice, deviceStatusIngest, orionEntities, orionListSubscriptions, orionCreateSubscription, orionToggleSubscription, orionDeleteSubscription, orionNotify
22dxosStudio@latticedx/plugin-dxos-studiolistTemplates, listEmployees, installWorkflow, composePortals, pluginStatus, readiness, outboxDlqList, outboxDlqReplay, solutionBundleExport, solutionBundleDiff, solutionBundleImport, solutionBundleRollback
23dxosWms@latticedx/plugin-dxos-studiostockSummary, receiveStock, issueStock, epodCapture, publicTrack, verifyTrackSignature
24dxosDmn@latticedx/plugin-dxos-studiolistTables, saveTable, evaluate, delegations, saveDelegation
25dxosDelegations@latticedx/plugin-dxos-studiolist, save, revoke
26dxosAutomations@latticedx/plugin-dxos-studiolistRules, saveRule, toggleRule, deleteRule, listRuns, runNow, replayRun
27dxosBuilder@latticedx/plugin-dxos-studiolistDomains, createDomain, listBusinessPacks, installBusinessPack, listTenants, provisionTenant
28dxosN8n@latticedx/plugin-dxos-studiostatus, appCatalog, workflows, getWorkflow, createWorkflow, updateWorkflow, activateWorkflow, executions, retryExecution, syncCredential
29dxosAi@latticedx/plugin-dxos-ailistProfiles, saveProfile, deleteProfile, bootstrapDefaults, portalAgents, auditLogs, quotaSummary, enterpriseTopology, pageSurfaceState, inspectPageBlocks, rollbackPageSnapshot, surfaceEvents, listApprovals, approveAction, rejectAction
30dxActions@latticedx/plugin-action-bridgeconnect, callback, status, catalog, list, run, files, workflow, studio, entity, agent, logistics, disconnect
31enterpriseAuth@latticedx/plugin-enterprise-authstart, callback, finish, backchannelLogout, configuration, link, listLinkTargets, listMappings, unlink

Ngoài 31 tài nguyên nghiệp vụ cốt lõi trên, @latticedx/plugin-lattice-foundation còn cung cấp tài nguyên latticeRequestAttachments cho quy trình tải tệp đính kèm có quét ClamAV (tối đa 1 MiB), và @latticedx/plugin-dxos-ai gắn thêm các tuyến middleware giao thức AI: POST /api/dxos-mcp, POST /api/dxos-mcp/it-ot, GET /.well-known/agent-card.json, GET /api/dxos-a2a/agent-card.json và POST /api/dxos-a2a. Các domain động latticeCustom* tạo từ dxosBuilder tự động mở đủ năm hành động list, get, create, update, destroy dưới tiền tố /api/latticeCustom<Name>:<action>.

Bề mặt Fastify Core API (/v1/*) ​

Dịch vụ Fastify (apps/api/src/app.ts, mặc định cổng 4000) chạy với giới hạn thân yêu cầu 16 KiB (bodyLimit: 16_384), bộ đếm giới hạn tốc độ nội bộ (API_RATE_LIMIT_MAX=1000 mỗi 60s, trả header X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset và Retry-After khi vượt ngưỡng 429), cùng chuẩn lỗi gọn { "error": "<message>" }.

Phân trang và Envelope trên Fastify /v1/*
Tham sốKiểuMặc địnhMô tả
limit
integer50Số lượng mục trả về trên một trang, giới hạn 1..100.
offset
integer0Vị trí bỏ qua (>= 0).
q
string—Từ khóa tìm kiếm, độ dài tối đa 200 ký tự.
items / pagebắt buộc
object—Cấu trúc phản hồi: { items: [...], page: { limit, offset, hasMore, nextOffset } }.

Các nhóm tuyến chính trên Fastify /v1/* bao gồm:

Nhóm tuyếnĐường dẫn đại diện
Kiểm tra sức khỏe và Vận hànhGET /health, /v1/operations/diagnostics, /v1/operations/metrics, /v1/operations/queues, /v1/operations/retention-preview, /v1/system-*
Hồ sơ, Thực thể và Tác vụ/v1/records, /v1/records/:id, /v1/entities*, /v1/entity-*, /v1/tasks*, /v1/files*, /v1/actions*, /v1/blocks*
Tổ chức, Quy trình và Tích hợp/v1/directory/*, /v1/organization/*, /v1/workflow-*, /v1/logistics/orders*, /v1/integrations/ngsi-ld/*, /v1/enterprise-modules*, /v1/studio/*, POST /v1/agent/demo

Ví dụ gọi API và xử lý lỗi ​

bash
# Truy vấn danh sách đơn hàng với PAT và phân trang
curl -sS -G "https://app.example.com/api/latticeOrders:list" \
  -H "X-Lattice-API-Key: ldx_pat_a1b2c3d4_0123456789abcdef0123456789abcdef" \
  --data-urlencode "page=1" \
  --data-urlencode "pageSize=20" \
  --data-urlencode "sort=-id"

# Cập nhật chứng từ ở trạng thái draft kèm If-Match tránh ghi đè
curl -sS -X POST "https://app.example.com/api/latticeOrders:update?filterByTk=42" \
  -H "Authorization: Bearer <OIDC_OR_PAT_TOKEN>" \
  -H "Content-Type: application/json" \
  -H 'If-Match: "3"' \
  -d '{"values":{"notes":"Batch verified"}}'

Định dạng lỗi và mã trạng thái phổ biến ​

Lớp NocoBase chuẩn hóa ngoại lệ thành { "errors": [{ "message": "...", "code": "..." }] }, trong khi lớp Fastify /v1/* trả { "error": "..." }.

Mã HTTPÝ nghĩaNguyên nhân điển hình
400Yêu cầu không hợp lệThiếu tham số bắt buộc, expectedVersion sai định dạng, vượt quá giới hạn q hoặc tải trọng JSON lỗi
401Chưa xác thựcThiếu token, token hết hạn (API_KEY_EXPIRED), bị thu hồi (API_KEY_REVOKED) hoặc phiên OIDC đã đăng xuất qua backchannel
403Từ chối phân quyềnThiếu scope trên ldx_pat_* (API_KEY_SCOPE_INSUFFICIENT), sai tổ chức (NATIVE_ORGANIZATION_MISMATCH) hoặc truy cập bảng riêng tư
409Xung đột trạng tháiSai expectedVersion (VERSION_CONFLICT) hoặc sửa chứng từ đã khóa (VOUCHER_IMMUTABLE)
429Vượt ngưỡng tần suấtVượt giới hạn limit-count của APISIX (120/240/300 req/60s) hoặc Fastify rateLimiter

Tài liệu liên quan ​

Apache-2.0 · LatticeDX v0.4.2 · Powered by NocoBase · v2.2.50 · Apache-2.0 (Clause 5.2)