eCourt-note/wordaddin/models/versionRecord.ts
Your Name c401f4deb7 feat(wordaddin): port Word add-in taskpane from poc
พอร์ต taskpane ของ Word add-in "e-Court Documents Versioning" จาก
D:\word-addin-poc มาเป็น sibling app ที่ route /docedit/wordaddin:

- wordaddin/ (client-only zone): services พอร์ตดิบทั้งชุด
  (authService/versioningService เป็น mock รอ backend จริง) + models + config
- components/wordaddin/: WordAddinGate ฉีด office.js self-host (singleton
  กัน StrictMode double-inject + fallback timer ครอบเคส onReady เงียบ)
  และ TaskpaneApp state machine แปลง JSX เป็น Genesis design system
- scripts/fetch-office-js.mjs (postinstall ตัวที่สาม): ดาวน์โหลด Office.js
  runtime ล่าสุดจาก CDN Microsoft ไป public/wordaddin/office-js/ (gitignore
  สร้างใหม่ได้ — npm @microsoft/office-js ตกรุ่นไม่มี Document.close)
- middleware/basePath/root page: เปิด /wordaddin เป็น public (auth แยกจาก
  แอป note), root /docedit redirect ไป taskpane ยกเว้นลิงก์ e-Court N8
  (?fileUrl=&fileId=&typeId=) ที่ยังส่งต่อ /note ตามเดิม
- docker/web.Dockerfile รัน fetch-office-js ตอน build + npm scripts
  dev:https สำหรับ sideload ตาม docs/WORDADDIN-DEV.md

Co-Authored-By: Claude Code <noreply@anthropic.com>
2026-10-16 12:07:25 +07:00

58 lines
2.1 KiB
TypeScript

/**
* Type ตรงกับ response ของ backend (`Models/VersionDtos.cs` — ASP.NET Core serialize camelCase)
* พอร์ตดิบจาก D:\word-addin-poc\addin\src\models\versionRecord.ts
*/
/** response ของ POST /api/documents/{documentId}/versions */
export interface UploadVersionResult {
hasPdf: boolean;
versionId: string;
versionNumber: number;
}
/** field เดียวใน snapshot ของ version (เอกสารที่ผูก template) */
export interface FieldSnapshotEntry {
value: string;
missing: boolean;
}
/**
* snapshot fields ต่อ version — backend เก็บ 2 รูปแบบ:
* - เอกสารผูก template: `{ [fieldKey]: { value, missing } }`
* - เอกสารไม่ผูก template (track เองจาก add-in): map ดิบ `{ [tag]: text }`
* UI ต้อง handle ได้ทั้งคู่ (ใช้ readSnapshotField ช่วยอ่าน)
*/
export type FieldsSnapshot = Record<string, FieldSnapshotEntry> | Record<string, string>;
/** item ของ GET /api/documents/{documentId}/versions */
export interface VersionRecord {
hasPdf?: boolean;
versionId: string;
versionNumber: number;
/** ISO-8601 */
createdAt: string;
createdByUserId: string;
/** SHA256 hex */
contentHash: string;
fields: FieldsSnapshot | null;
/** คำอธิบาย version แบบ commit message ที่ผู้ใช้พิมพ์ตอนสร้าง (FR-13) — null ได้ */
message: string | null;
}
/** อ่านค่า + สถานะ missing ของ field หนึ่งจาก snapshot ไม่ว่าจะเก็บรูปแบบไหน — ไม่มี field นี้คืน null */
export function readSnapshotField(
snapshot: FieldsSnapshot | null,
key: string
): FieldSnapshotEntry | null {
if (!snapshot) {
return null;
}
const raw = snapshot[key];
if (raw === undefined) {
return null;
}
if (typeof raw === "string") {
return { value: raw, missing: false };
}
return { value: raw.value, missing: raw.missing };
}