@fui-org/fui-cli 1.3.2 → 2.1.0

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.
Files changed (115) hide show
  1. package/README.md +21 -3
  2. package/dist/fui-cx180e19.js +379 -0
  3. package/dist/fui.js +1 -1
  4. package/package.json +3 -6
  5. package/skills/fui/SKILL.md +9 -41
  6. package/skills/fui-skill/SKILL.md +95 -225
  7. package/skills/fui-skill/assets/projectdefaultstyle-3.0.css +555 -0
  8. package/skills/fui-skill/assets/projectdefaultstyle.css +207 -235
  9. package/skills/fui-skill/references/INDEX.md +105 -137
  10. package/skills/fui-skill/references/advanced-techniques.md +76 -68
  11. package/skills/fui-skill/references/coding-standards.md +56 -56
  12. package/skills/fui-skill/references/component-design.md +166 -173
  13. package/skills/fui-skill/references/component-quickref.md +61 -60
  14. package/skills/fui-skill/references/component-table.md +128 -117
  15. package/skills/fui-skill/references/components-dialog.md +55 -56
  16. package/skills/fui-skill/references/components-display.md +24 -30
  17. package/skills/fui-skill/references/components-echart.md +186 -261
  18. package/skills/fui-skill/references/components-input.md +72 -96
  19. package/skills/fui-skill/references/controls-patterns.md +196 -342
  20. package/skills/fui-skill/references/controls-styling-vocabulary.md +130 -97
  21. package/skills/fui-skill/references/db-table-design.md +24 -28
  22. package/skills/fui-skill/references/db-workflow.md +191 -390
  23. package/skills/fui-skill/references/default-function.md +169 -128
  24. package/skills/fui-skill/references/design-modes.md +35 -63
  25. package/skills/fui-skill/references/echart-templates.md +204 -196
  26. package/skills/fui-skill/references/fastproject.md +62 -60
  27. package/skills/fui-skill/references/fsheet.md +109 -124
  28. package/skills/fui-skill/references/fullstack-workflow.md +90 -128
  29. package/skills/fui-skill/references/module-data-patterns.md +31 -40
  30. package/skills/fui-skill/references/module-json-anatomy.md +47 -52
  31. package/skills/fui-skill/references/module-structure.md +80 -196
  32. package/skills/fui-skill/references/new-session.md +49 -51
  33. package/skills/fui-skill/references/pdfmake.md +17 -17
  34. package/skills/fui-skill/references/permission-system.md +89 -108
  35. package/skills/fui-skill/references/platform-architecture.md +128 -153
  36. package/skills/fui-skill/references/project-config.md +102 -134
  37. package/skills/fui-skill/references/project-provisioning.md +139 -244
  38. package/skills/fui-skill/references/script-map.md +208 -242
  39. package/skills/fui-skill/references/sql-clr-functions.md +98 -97
  40. package/skills/fui-skill/references/system-design.md +63 -88
  41. package/skills/fui-skill/references/tapi-file-api.md +46 -52
  42. package/skills/fui-skill/references/tapi-permission-patterns.md +51 -53
  43. package/skills/fui-skill/references/tapi-reference.md +132 -207
  44. package/skills/fui-skill/references/tools-registry.md +84 -460
  45. package/skills/fui-skill/references/ui-crosswindow-patterns.md +79 -75
  46. package/skills/fui-skill/references/ui-dialog-patterns.md +98 -72
  47. package/skills/fui-skill/references/ui-layout-patterns.md +26 -26
  48. package/skills/fui-skill/references/ui-patterns.md +71 -83
  49. package/skills/fui-skill/references/ui-screenshot-review.md +63 -62
  50. package/skills/fui-skill/references/ui-table-cell-patterns.md +61 -59
  51. package/skills/fui-skill/references/ui-templates.md +16 -23
  52. package/skills/fui-skill/references/verification.md +236 -246
  53. package/skills/fui-skill/references/watcher-patterns.md +30 -63
  54. package/skills/fui-skill/references/websocket-realtime.md +83 -66
  55. package/skills/fui-skill/scripts/component-3.0.js +298 -131
  56. package/skills/fui-skill/scripts/component.js +277 -271
  57. package/skills/fui-skill/scripts/componentTable-3.0.js +182 -53
  58. package/skills/fui-skill/scripts/componentTable.js +171 -49
  59. package/skills/fui-skill/scripts/defaultfunction-3.0.js +88 -3
  60. package/skills/fui-skill/scripts/defaultfunction.js +88 -3
  61. package/skills/fui-skill/scripts/fsheet.js +38 -0
  62. package/skills/fui-target/.claude-plugin/plugin.json +6 -0
  63. package/skills/fui-target/hooks/hooks.json +1 -0
  64. package/skills/fui-target/hooks/register.tsx +71 -0
  65. package/skills/fui-target/types/index.d.ts +7 -0
  66. package/dist/fui-y8an39cn.js +0 -420
  67. package/skills/fui-skill/README.md +0 -112
  68. package/skills/fui-skill/metadata.json +0 -75
  69. package/skills/fui-skill-cli/SKILL.md +0 -139
  70. package/skills/fui-skill-cli/references/INDEX.md +0 -110
  71. package/skills/fui-skill-cli/references/advanced-techniques.md +0 -168
  72. package/skills/fui-skill-cli/references/coding-standards.md +0 -112
  73. package/skills/fui-skill-cli/references/component-design.md +0 -448
  74. package/skills/fui-skill-cli/references/component-quickref.md +0 -78
  75. package/skills/fui-skill-cli/references/component-table.md +0 -248
  76. package/skills/fui-skill-cli/references/components-dialog.md +0 -191
  77. package/skills/fui-skill-cli/references/components-display.md +0 -141
  78. package/skills/fui-skill-cli/references/components-echart.md +0 -316
  79. package/skills/fui-skill-cli/references/components-input.md +0 -335
  80. package/skills/fui-skill-cli/references/controls-patterns.md +0 -701
  81. package/skills/fui-skill-cli/references/controls-styling-vocabulary.md +0 -137
  82. package/skills/fui-skill-cli/references/db-table-design.md +0 -73
  83. package/skills/fui-skill-cli/references/db-workflow.md +0 -288
  84. package/skills/fui-skill-cli/references/default-function.md +0 -425
  85. package/skills/fui-skill-cli/references/design-modes.md +0 -57
  86. package/skills/fui-skill-cli/references/echart-templates.md +0 -489
  87. package/skills/fui-skill-cli/references/fastproject.md +0 -99
  88. package/skills/fui-skill-cli/references/fsheet.md +0 -203
  89. package/skills/fui-skill-cli/references/fullstack-workflow.md +0 -313
  90. package/skills/fui-skill-cli/references/module-data-patterns.md +0 -117
  91. package/skills/fui-skill-cli/references/module-json-anatomy.md +0 -132
  92. package/skills/fui-skill-cli/references/module-structure.md +0 -141
  93. package/skills/fui-skill-cli/references/new-session.md +0 -85
  94. package/skills/fui-skill-cli/references/pdfmake.md +0 -60
  95. package/skills/fui-skill-cli/references/permission-system.md +0 -150
  96. package/skills/fui-skill-cli/references/platform-architecture.md +0 -269
  97. package/skills/fui-skill-cli/references/project-config.md +0 -303
  98. package/skills/fui-skill-cli/references/project-provisioning.md +0 -278
  99. package/skills/fui-skill-cli/references/script-map.md +0 -262
  100. package/skills/fui-skill-cli/references/sql-clr-functions.md +0 -225
  101. package/skills/fui-skill-cli/references/system-design.md +0 -89
  102. package/skills/fui-skill-cli/references/tapi-file-api.md +0 -185
  103. package/skills/fui-skill-cli/references/tapi-permission-patterns.md +0 -156
  104. package/skills/fui-skill-cli/references/tapi-reference.md +0 -474
  105. package/skills/fui-skill-cli/references/tools-registry.md +0 -84
  106. package/skills/fui-skill-cli/references/ui-crosswindow-patterns.md +0 -321
  107. package/skills/fui-skill-cli/references/ui-dialog-patterns.md +0 -255
  108. package/skills/fui-skill-cli/references/ui-layout-patterns.md +0 -176
  109. package/skills/fui-skill-cli/references/ui-patterns.md +0 -303
  110. package/skills/fui-skill-cli/references/ui-screenshot-review.md +0 -95
  111. package/skills/fui-skill-cli/references/ui-table-cell-patterns.md +0 -318
  112. package/skills/fui-skill-cli/references/ui-templates.md +0 -22
  113. package/skills/fui-skill-cli/references/verification.md +0 -236
  114. package/skills/fui-skill-cli/references/watcher-patterns.md +0 -163
  115. package/skills/fui-skill-cli/references/websocket-realtime.md +0 -271
@@ -1,23 +1,19 @@
1
1
  # tAPI — File API (GET / UPLOAD)
2
2
 
3
- > File này sở hữu: **API file qua SP: `spAPIFILE_*`, `tblFileData`, alias `fileContent`, `@sys_FileContent`/`@sys_FileName`**.
4
-
5
- SP GET và UPLOAD file qua tAPI: prefix `spAPIFILE_`, cột binary alias `fileContent`, params `@sys_FileContent`/`@sys_FileName`, bảng chuẩn `tblFileData`. Load file này khi module cần upload/download/xem file. **Không tự suy từ training data** — tAPI có quy ước riêng.
6
-
7
- > Nền tảng SP (naming, params, response): xem [tapi-reference.md](tapi-reference.md).
3
+ > Owns: **file APIs via SP: `spAPIFILE_*`, `tblFileData`, alias `fileContent`, `@sys_FileContent`/`@sys_FileName`**. Load when a module needs upload/download/view of files. **Never infer from training data** — tAPI has its own conventions. SP basics (naming, params, response): [tapi-reference.md](tapi-reference.md).
8
4
 
9
5
  ---
10
6
 
11
7
  ## GET file
12
8
 
13
- SP phải SELECT **tối thiểu 3 cột bắt buộc** (có thể thêm cột metadata tùy ý):
9
+ SP must SELECT **at least 3 required columns** (extra metadata columns allowed):
14
10
 
15
- | Cột | Bắt buộc | Ý nghĩa |
16
- |---|---|---|
17
- | `FileName` | ✅ | Tên file trả về — có thể là biểu thức, ví dụ `FileName + FileType` |
18
- | `ContentType` | ✅ | MIME type (vd: `application/pdf`, `image/png`) |
19
- | `fileContent` | ✅ | Binary content — alias từ cột kiểu **`image` hoặc `varbinary`**. tAPI nhận diện đây là nội dung file cần stream qua kiểu dữ liệu này |
20
- | cột khác | ❌ | Metadata tùy chọn, ví dụ `Modified`, `FileSize` — phải là kiểu thông thường (không phải binary) |
11
+ | Column | Required | Meaning |
12
+ | ------------- | -------- | ------------------------------------------------------------------------------------------------------------------------- |
13
+ | `FileName` | ✅ | Returned file name — may be an expression, e.g. `FileName + FileType` |
14
+ | `ContentType` | ✅ | MIME type (e.g. `application/pdf`, `image/png`) |
15
+ | `fileContent` | ✅ | Binary content — alias of an **`image` or `varbinary`** column. tAPI detects the file content to stream by this data type |
16
+ | other columns | ❌ | Optional metadata, e.g. `Modified`, `FileSize` — must be normal (non-binary) types |
21
17
 
22
18
  ```sql
23
19
  -- Ví dụ thực tế: FileName ghép đuôi, thêm cột Modified, binary aliased từ FileContentBIN
@@ -34,17 +30,17 @@ AS BEGIN
34
30
  END
35
31
  ```
36
32
 
37
- > `fileContent` phải alias từ cột kiểu `image` hoặc `varbinary(max)` — tAPI dùng kiểu dữ liệu này để nhận biết và stream nội dung file. Tên cột trong bảng tùy ý (`FileContentBIN`, `BinaryContent`, ...).
38
- > `FileName` nên bao gồm cả phần đuôi file (`.pdf`, `.xlsx`...) để browser nhận đúng kiểu.
33
+ > `fileContent` must alias an `image` or `varbinary(max)` column — tAPI uses the type to detect and stream the file. Table column name is free (`FileContentBIN`, `BinaryContent`, ...).
34
+ > `FileName` should include the extension (`.pdf`, `.xlsx`...) so the browser detects the type.
39
35
 
40
- **Tham số URL — `@fileID` và `@filename`:**
36
+ **URL params — `@fileID` and `@filename`:**
41
37
 
42
- | Param | Bắt buộc | Nguồn | Ý nghĩa |
43
- |---|---|---|---|
44
- | `@fileID varchar(...)` | ✅ | Segment đầu tiên sau FunctionName | ID của file cần lấy |
45
- | `@filename varchar(...)` | ❌ | Segment CUỐI cùng trong URL | Phần tên file hiển thị trong URL (browser/download manager dùng để đặt tên khi tải) |
38
+ | Param | Required | Source | Meaning |
39
+ | ------------------------ | -------- | -------------------------------- | ------------------------------------------------------------------------------------ |
40
+ | `@fileID varchar(...)` | ✅ | First segment after FunctionName | ID of the file |
41
+ | `@filename varchar(...)` | ❌ | LAST URL segment | Display file name in the URL (browser/download manager uses it to name the download) |
46
42
 
47
- Ngoài hai tham số trên, có thể khai báo thêm `@sys_*` auth params nếu cần kiểm tra quyền.
43
+ Extra `@sys_*` auth params may be declared for permission checks.
48
44
 
49
45
  ```sql
50
46
  CREATE PROCEDURE spAPIFILE_Document
@@ -57,7 +53,7 @@ AS BEGIN
57
53
  END
58
54
  ```
59
55
 
60
- **4 route pattern hỗ trợ:**
56
+ **4 supported routes:**
61
57
 
62
58
  ```
63
59
  {domain}/{apiName}/{FunctionName}/{fileID}
@@ -66,25 +62,23 @@ END
66
62
  {domain}/{apiName}/viewer/{FunctionName}/{fileID}/{filename}
67
63
  ```
68
64
 
69
- `{FunctionName}` là phần tên sau prefix `spAPIFILE_`. Ví dụ SP `spAPIFILE_Document` → URL dùng `Document`.
70
-
71
- Route `/viewer/` dùng để xem trực tiếp trong browser (inline), `/download/` để tải về.
65
+ `{FunctionName}` is the name after the `spAPIFILE_` prefix: SP `spAPIFILE_Document` → URL uses `Document`. `/viewer/` = view inline in browser; `/download/` = download.
72
66
 
73
- > **Lưu ý `@filename`:** Segment này trong URL thường là tên file gốc (ví dụ `BaoCao_2024.pdf`) — browser và download manager dùng nó để đặt tên file khi tải về, không nhất thiết phải khớp với `FileName` trong bảng DB. SP không khai báo `@filename` thì tAPI vẫn nhận route có segment đó — param đơn thuần bị bỏ qua.
67
+ > **`@filename`:** usually the original name (e.g. `BaoCao_2024.pdf`) used by browser/download manager to name the file; need not match `FileName` in the DB. If the SP doesn't declare `@filename`, tAPI still accepts the route with that segment — the param is simply ignored.
74
68
 
75
69
  ## Upload file
76
70
 
77
- **Params đặc biệt do tAPI tự inject khi upload:**
71
+ **Special params injected by tAPI on upload:**
78
72
 
79
- | Param | Kiểu | Mô tả |
80
- |---|---|---|
81
- | `@sys_FileContent` | varbinary(max) | Binary content của file |
82
- | `@sys_FileName` | nvarchar(200) | Tên file gốc |
83
- | `@sys_FileContentType` | varchar(100) | MIME type |
84
- | `@sys_FileSize` | int | Kích thước file (bytes) |
85
- | `@sys_UploadData` | nvarchar(max) | JSON data bổ sung truyền qua header |
73
+ | Param | Type | Meaning |
74
+ | ---------------------- | -------------- | --------------------------------- |
75
+ | `@sys_FileContent` | varbinary(max) | File binary content |
76
+ | `@sys_FileName` | nvarchar(200) | Original file name |
77
+ | `@sys_FileContentType` | varchar(100) | MIME type |
78
+ | `@sys_FileSize` | int | File size (bytes) |
79
+ | `@sys_UploadData` | nvarchar(max) | Extra JSON data passed via header |
86
80
 
87
- Ngoài ra toàn bộ `@sys_` auth params cũng available: `@sys_UserID`, `@sys_UserName`, `@sys_SessionID`, `@sys_GroupID`, `@sys_DepartmentID`, `@sys_SystemRight`, `@sys_FunctionRight`.
81
+ All `@sys_` auth params are also available: `@sys_UserID`, `@sys_UserName`, `@sys_SessionID`, `@sys_GroupID`, `@sys_DepartmentID`, `@sys_SystemRight`, `@sys_FunctionRight`.
88
82
 
89
83
  ```sql
90
84
  CREATE PROCEDURE spAPIFILE_UPLOAD_Attachment
@@ -103,9 +97,9 @@ END
103
97
 
104
98
  Route: `POST {domain}/{apiName}/upload/{spName}/{url1}/{url2}...`
105
99
 
106
- ## Bảng lưu trữ file chuẩn — `tblFileData`
100
+ ## Standard file table — `tblFileData`
107
101
 
108
- Đây là cấu trúc bảng chuẩn để dùng chung với cả `spAPIFILE_` (GET) và `spAPIFILE_UPLOAD_` (POST). Khi thiết kế module có file, tạo bảng này (hoặc bảng tương tự) trước khi viết SP.
102
+ Standard structure shared by `spAPIFILE_` (GET) and `spAPIFILE_UPLOAD_` (POST). For modules with files, create this table (or similar) before writing SPs.
109
103
 
110
104
  ```sql
111
105
  CREATE TABLE [dbo].[tblFileData](
@@ -129,23 +123,23 @@ ALTER TABLE [dbo].[tblFileData] ADD CONSTRAINT [DF_tblFileData_CreateTime]
129
123
  ALTER TABLE [dbo].[tblFileData] ADD CONSTRAINT [DF_tblFileData_ContentType] DEFAULT ('') FOR [ContentType]
130
124
  ```
131
125
 
132
- > **Lưu ý về DDL:** các câu `ALTER TABLE ... ADD CONSTRAINT` ở trên **chạy được qua tool** (ADD là thao tác cộng thêm). Riêng `CREATE TABLE` thì không — MCP chặn, phải do lập trình viên tự chạy. Đây là tài liệu tham chiếu cấu trúc.
126
+ > **DDL:** the `ALTER TABLE ... ADD CONSTRAINT` statements **can run via fui** (ADD is additive). `CREATE TABLE` cannot — fui blocks it; the developer must run it. This is a structure reference.
133
127
 
134
- **Giải thích từng field:**
128
+ **Fields:**
135
129
 
136
- | Field | Kiểu | Mô tả |
137
- |---|---|---|
138
- | `FileID` | char(36) PK | UUID tự sinh bằng `newid()` — dùng làm key trong URL |
139
- | `FileName` | nvarchar(200) | Tên file gốc khi upload |
140
- | `PhysicalName` | char(36) | UUID tự sinh — tên file thực tế lưu trên disk (tránh trùng tên) |
141
- | `PhysicalSegment` | char(10) | Subfolder phân tán theo ngày từ hàm `getPhysicalSegment(date)` |
142
- | `CreateTime` | datetime | Thời điểm tạo record, DEFAULT getdate() |
143
- | `WriteToDisk` | datetime NULL | Khi nào binary được ghi ra disk; `NULL` = chỉ lưu DB, chưa ra file system |
144
- | `BinaryContent` | image NULL | Nội dung binary của file — SP GET phải alias là `fileContent` |
145
- | `ContentType` | varchar(100) | MIME type, ví dụ `application/pdf`, `image/png` |
146
- | `Size` | int NULL | Kích thước bytes |
130
+ | Field | Type | Meaning |
131
+ | ----------------- | ------------- | ----------------------------------------------------------------------------- |
132
+ | `FileID` | char(36) PK | Auto UUID via `newid()` — used as the URL key |
133
+ | `FileName` | nvarchar(200) | Original upload name |
134
+ | `PhysicalName` | char(36) | Auto UUID — actual file name on disk (avoids collisions) |
135
+ | `PhysicalSegment` | char(10) | Date-based subfolder from `getPhysicalSegment(date)` |
136
+ | `CreateTime` | datetime | Record creation time, DEFAULT getdate() |
137
+ | `WriteToDisk` | datetime NULL | When the binary was written to disk; `NULL` = DB only, not on file system yet |
138
+ | `BinaryContent` | image NULL | File binary — GET SP must alias it `fileContent` |
139
+ | `ContentType` | varchar(100) | MIME type, e.g. `application/pdf`, `image/png` |
140
+ | `Size` | int NULL | Size in bytes |
147
141
 
148
- **SP GET file — map tới bảng:**
142
+ **GET SP on the table:**
149
143
 
150
144
  ```sql
151
145
  CREATE PROCEDURE spAPIFILE_Document
@@ -162,7 +156,7 @@ AS BEGIN
162
156
  END
163
157
  ```
164
158
 
165
- **SP UPLOAD — lưu vào bảng:**
159
+ **UPLOAD SP into the table:**
166
160
 
167
161
  ```sql
168
162
  CREATE PROCEDURE spAPIFILE_UPLOAD_Document
@@ -188,4 +182,4 @@ AS BEGIN
188
182
  END
189
183
  ```
190
184
 
191
- > **Lưu ý `BinaryContent [image]`**: Kiểu `image` là legacy của SQL Server nhưng vẫn hoạt động tốt với tAPI. Nếu muốn dùng kiểu mới hơn có thể dùng `varbinary(max)` — cả hai đều map được vào `fileContent` alias.
185
+ > **`BinaryContent [image]`**: `image` is legacy SQL Server but works fine with tAPI. `varbinary(max)` also works — both map to the `fileContent` alias.
@@ -1,25 +1,20 @@
1
- # tAPI — Kiểm tra quyền người dùng (Permission Check Patterns)
1
+ # tAPI — Permission Check Patterns
2
2
 
3
- > File này sở hữu: **5 pattern kiểm tra quyền trong thân SP (`@sys_SystemRight`, `getSystemRight`, RAISERROR)**. Khái niệm quyền xem [permission-system.md](permission-system.md).
4
-
5
- Các pattern kiểm tra quyền trong thân Stored Procedure tAPI. Load file này khi SP cần phân quyền.
6
-
7
- > Nền tảng SP (naming, params, response, RAISERROR): xem [tapi-reference.md](tapi-reference.md).
8
- > Khái niệm `SystemRight`/`FunctionRight`, cấu trúc `tblSysRight`/`tblFunction`, và 4 tool quản lý định nghĩa quyền: xem [permission-system.md](permission-system.md).
3
+ > Owns: **5 permission-check patterns in SP bodies (`@sys_SystemRight`, `getSystemRight`, RAISERROR)**. Load when an SP needs authorization. SP basics (naming, params, response, RAISERROR): [tapi-reference.md](tapi-reference.md). `SystemRight`/`FunctionRight` concepts, `tblSysRight`/`tblFunction`, right-definition commands: [permission-system.md](permission-system.md).
9
4
 
10
5
  ---
11
6
 
12
- ## Tham số hệ thống liên quan đến quyền
7
+ ## Permission-related system params
13
8
 
14
- tAPI tự inject các tham số sau — không cần client truyền lên:
9
+ Injected by tAPI — the client never sends them:
15
10
 
16
- | Tham số | Kiểu | Mô tả |
17
- |---|---|---|
18
- | `@sys_UserID` | varchar(9) | Mã người dùng đang đăng nhập |
19
- | `@sys_SystemRight` | int | Mức quyền của user trên module hiện tại |
20
- | `@sys_FunctionRight` | varchar(2000) | Quyền chức năng dạng `[AD][RPT][MGR]` |
11
+ | Param | Type | Meaning |
12
+ | -------------------- | ------------- | ------------------------------------- |
13
+ | `@sys_UserID` | varchar(9) | Logged-in user ID |
14
+ | `@sys_SystemRight` | int | User's level on the current module |
15
+ | `@sys_FunctionRight` | varchar(2000) | Function rights like `[AD][RPT][MGR]` |
21
16
 
22
- **Khai báo trong SP** — luôn đặt cuối danh sách tham số, **không được gán default cho bất kỳ tham số nào, kể cả `@sys_*`** (xem [tapi-reference.md](tapi-reference.md) §2 — tAPI luôn truyền đủ mọi tham số, thiếu thì truyền `NULL`, nên `DEFAULT` không bao giờ được dùng tới; `db_sp_deploy` chặn cứng nếu có):
17
+ **Declare** at the end of the param list. **No default on any param, including `@sys_*`** ([tapi-reference.md](tapi-reference.md) §2 — tAPI always passes every param, `NULL` when missing, so `DEFAULT` is never used; `fui sp deploy` hard-blocks it):
23
18
 
24
19
  ```sql
25
20
  CREATE PROCEDURE spAPI_EntityAction
@@ -30,31 +25,31 @@ CREATE PROCEDURE spAPI_EntityAction
30
25
  AS
31
26
  ```
32
27
 
33
- ## Các mức `@sys_SystemRight`
28
+ ## `@sys_SystemRight` levels
34
29
 
35
- Ý nghĩa từng mức **do mỗi project tự định nghĩa** (`tblSysRight.Note`, quản lý qua `right_system_list`/`right_system_update` — xem [permission-system.md](permission-system.md)). Bảng dưới là quy ước phổ biến dùng khi viết pattern kiểm tra trong SP — không phải giá trị cố định của platform, ngoại trừ `9` luôn là Project Admin:
30
+ Meaning is **defined per project** (`tblSysRight.Note`, managed via `fui right system list`/`update` — [permission-system.md](permission-system.md)). Common convention for SP checks — not platform-fixed, except `9` is always Project Admin:
36
31
 
37
- | Giá trị | Ý nghĩa thực tế (quy ước phổ biến) |
38
- |---|---|
39
- | `0` | Không có quyền / chưa được cấp quyền trên module |
40
- | `1` | Quyền xem cơ bản |
41
- | `2` | Quyền thao tác chuẩn (đọc, thêm, sửa thông thường) |
42
- | `3` | Quyền nâng cao (quản lý nội bộ, thao tác nhạy cảm) |
43
- | `9` | Module Admin / Project Admin (cố định trên toàn platform) |
32
+ | Value | Common meaning |
33
+ | ----- | -------------------------------------------------- |
34
+ | `0` | No right / not granted on the module |
35
+ | `1` | Basic view |
36
+ | `2` | Standard operations (read, add, normal edit) |
37
+ | `3` | Advanced (internal management, sensitive ops) |
38
+ | `9` | Module Admin / Project Admin (fixed platform-wide) |
44
39
 
45
- ## Helper function kiểm tra quyền theo module cụ thể
40
+ ## Helper: rights on a specific module
46
41
 
47
42
  ```sql
48
43
  dbo.getSystemRight(@ModuleID, @sys_UserID)
49
44
  ```
50
45
 
51
- Trả về mức `SysRight` mà user được assign cho một module xác định — dùng khi cần kiểm tra quyền trên module **khác** với module hiện tại.
46
+ Returns the user's `SysRight` on a given module — use to check rights on a module **other than** the current one.
52
47
 
53
48
  ---
54
49
 
55
- ## Pattern 1 — Chặn truy cập cơ bản (READ operations)
50
+ ## Pattern 1 — Basic access block (READ)
56
51
 
57
- Dùng cho mọi SP đọc dữ liệu cần đăng nhập. Yêu cầu ít nhất `SysRight = 2`.
52
+ Every read SP that needs login. Requires `SysRight >= 2`.
58
53
 
59
54
  ```sql
60
55
  If @sys_SystemRight < 2
@@ -64,9 +59,9 @@ Begin
64
59
  End
65
60
  ```
66
61
 
67
- ## Pattern 2 — Chặn user hoàn toàn không có quyền (minimal check)
62
+ ## Pattern 2 — Block only users with no right (minimal)
68
63
 
69
- Dùng khi muốn cho phép cả `SysRight = 1` thao tác, chỉ chặn `SysRight = 0`.
64
+ Allows `SysRight = 1`; blocks only `SysRight = 0`.
70
65
 
71
66
  ```sql
72
67
  If @sys_SystemRight = 0
@@ -76,11 +71,12 @@ Begin
76
71
  End
77
72
  ```
78
73
 
79
- ## Pattern 3 — Kiểm tra 2 tầng: global + module admin (WRITE operations)
74
+ ## Pattern 3 — 2-tier: global + module admin (WRITE)
75
+
76
+ Writes affecting module config or other users' data. User must meet **either**:
80
77
 
81
- Dùng cho các thao tác ghi có tác động đến cấu hình module hoặc dữ liệu người dùng khác. User phải đạt **một trong hai điều kiện**:
82
- - `@sys_SystemRight >= 3` (quyền cao toàn hệ thống), **hoặc**
83
- - Là Module Admin (`getSystemRight >= 9`) của module đó.
78
+ - `@sys_SystemRight >= 3` (high global right), **or**
79
+ - Module Admin (`getSystemRight >= 9`) of that module.
84
80
 
85
81
  ```sql
86
82
  -- Tầng 1: phải có quyền cơ bản
@@ -98,9 +94,9 @@ Begin
98
94
  End
99
95
  ```
100
96
 
101
- ## Pattern 4 — Kiểm tra logic nghiệp vụ trước khi thực thi
97
+ ## Pattern 4 — Business-rule check before executing
102
98
 
103
- Dùng khi thao tác hợp lệ về quyền nhưng vi phạm ràng buộc dữ liệu (ví dụ: xóa cha khi còn con).
99
+ Authorized but violates a data constraint (e.g. deleting a parent that still has children).
104
100
 
105
101
  ```sql
106
102
  -- Kiểm tra ràng buộc trước khi xóa
@@ -113,9 +109,9 @@ End
113
109
  DELETE tblParent WHERE ParentID = @ParentID
114
110
  ```
115
111
 
116
- ## Pattern 5 — Kiểm tra `@sys_FunctionRight`
112
+ ## Pattern 5 — `@sys_FunctionRight` check
117
113
 
118
- Dùng khi phân quyền theo chức năng cụ thể (không chỉ theo mức số).
114
+ Authorization by specific function (not just numeric level).
119
115
 
120
116
  ```sql
121
117
  If CHARINDEX('[ADMIN]', @sys_FunctionRight) = 0
@@ -127,7 +123,7 @@ End
127
123
 
128
124
  ---
129
125
 
130
- ## Quy tắc đặt thứ tự kiểm tra
126
+ ## Check order
131
127
 
132
128
  ```
133
129
  1. Kiểm tra quyền hệ thống (@sys_SystemRight) ← luôn đầu tiên
@@ -136,23 +132,25 @@ End
136
132
  4. Kiểm tra ràng buộc nghiệp vụ ← sau cùng, trước khi ghi
137
133
  ```
138
134
 
139
- ## Quy ước thông báo lỗi
135
+ ## Error message conventions
140
136
 
141
- | Tình huống | Message chuẩn |
142
- |---|---|
143
- | Thiếu quyền global | `N'[Unauthorized]Bạn không có quyền trên chức năng này.'` |
144
- | Thiếu quyền module | `N'[Unauthorized]Bạn không có quyền trên Module này.'` |
145
- | Thiếu quyền chức năng (`FunctionRight`) | `N'[Unauthorized]Bạn không có quyền thực hiện chức năng này.'` |
146
- | Vi phạm ràng buộc | Mô tả cụ thể, **không** có prefix: `N'Phải xóa X trước khi xóa Y.'` |
147
- | Dữ liệu không hợp lệ | `N'Dữ liệu không hợp lệ.'` hoặc mô tả cụ thể, **không** có prefix |
137
+ | Case | Standard message |
138
+ | ---------------------------------------- | --------------------------------------------------------------------- |
139
+ | Missing global right | `N'[Unauthorized]Bạn không có quyền trên chức năng này.'` |
140
+ | Missing module right | `N'[Unauthorized]Bạn không có quyền trên Module này.'` |
141
+ | Missing function right (`FunctionRight`) | `N'[Unauthorized]Bạn không có quyền thực hiện chức năng này.'` |
142
+ | Constraint violation | Specific description, **no** prefix: `N'Phải xóa X trước khi xóa Y.'` |
143
+ | Invalid data | `N'Dữ liệu không hợp lệ.'` or specific description, **no** prefix |
144
+
145
+ **Mandatory `RAISERROR` format:**
148
146
 
149
- **Format `RAISERROR` bắt buộc:**
150
147
  ```sql
151
148
  RAISERROR(N'Thông báo lỗi tiếng Việt.', 16, 1)
152
149
  RETURN
153
150
  ```
154
- - **Severity luôn là `16`** — áp dụng cho mọi loại lỗi (validation, unauthorized, business logic)
155
- - Prefix `N` bắt buộc cho Unicode tiếng Việt
156
- - `RETURN` bắt buộc ngay sau `RAISERROR` — thiếu `RETURN` SP tiếp tục chạy dù đã báo lỗi
157
- - Client nhận `{ "Message": "..." }` với nội dung thông báo
158
- - **Mọi lỗi thiếu quyền ở 5 pattern trên phải mở message bằng `[Unauthorized]`** (vd `N'[Unauthorized]Bạn không có quyền...'`) — tAPI dựa vào tiền tố này để trả HTTP status `401` thay vì mặc định, và tự cắt `[Unauthorized]` khỏi `Message` trước khi trả về client. Lỗi ràng buộc/nghiệp vụ (Pattern 4) **không** dùng prefix này — chi tiết cơ chế + cách client xử lý status 401 xem [tapi-reference.md](tapi-reference.md) §5.
151
+
152
+ - **Severity always `16`** — every error kind (validation, unauthorized, business logic)
153
+ - `N` prefix required for Vietnamese Unicode
154
+ - `RETURN` required right after `RAISERROR` — without it the SP keeps running after the error
155
+ - Client receives `{ "Message": "..." }`
156
+ - **Every missing-right error in the 5 patterns must start with `[Unauthorized]`** (e.g. `N'[Unauthorized]Bạn không có quyền...'`) — tAPI uses this prefix to return HTTP `401` instead of the default, and strips `[Unauthorized]` from `Message` before returning. Constraint/business errors (Pattern 4) do **not** use it — mechanism + client 401 handling: [tapi-reference.md](tapi-reference.md) §5.