ken_nogi/NodeSrv/apps/org-master-sync/scripts/push-master-site-schema.js
Kenichiro NOGI ce58cb4be4 初回コミット: dev配下(NodeSrv/Pleasanter等)をGitea管理下に統合
GitHub(nextgroup2706/ken_nogi)は今後使わず自社Gitea運用に切替え。
NodeSrvは旧リポジトリの履歴を破棄しファイルのみ統合(Dokploy用サービスアカウントは
別途mygit-admin/NodeSrv.gitに履歴あり)。notepmエクスポート(12GB)とPleasanter
インストーラzip(208MB)はサイズが大きいため.gitignoreで除外。

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-04 15:37:06 +09:00

103 lines
4.0 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"use strict";
/*
* SiteId=1記録テーブルへ、社員・組織マスタ用のフィールドラベルClassHash等
* Titleを設定する。既定はドライラン差分・送信Body・curlコマンドの表示のみ
* 実際に送信するには --execute を付ける。
*
* 実行: node scripts/push-master-site-schema.js [--execute]
*/
const { getSite: fetchSite } = require("../src/lib/pleasanterClient");
const { saveSiteSnapshot } = require("../src/lib/siteConfigStore");
const { buildHashUpdate } = require("../src/config/masterFields");
const BASE_URL = process.env.PLEASANTER_BASE_URL;
const API_KEY = process.env.PLEASANTER_API_KEY;
const SITE_ID = process.env.PLEASANTER_MASTER_SITE_ID;
const NEW_TITLE = "社員・組織マスタ管理テーブル";
if (!BASE_URL || !API_KEY || !SITE_ID) {
console.error("PLEASANTER_BASE_URL / PLEASANTER_API_KEY / PLEASANTER_MASTER_SITE_ID が未設定");
process.exit(1);
}
// サイト情報を取得するたびにconfigs/へ保存する2026-08-08、ユーザー指示
async function getSite() {
const data = await fetchSite({ baseUrl: BASE_URL, apiKey: API_KEY, siteId: SITE_ID });
saveSiteSnapshot(SITE_ID, data);
return data;
}
async function updateSite(body) {
const res = await fetch(`${BASE_URL.replace(/\/$/, "")}/api/items/${SITE_ID}/updatesite`, {
method: "POST",
headers: { "Content-Type": "application/json; charset=utf-8" },
body: JSON.stringify(body),
});
const data = await res.json();
if (!res.ok || data.StatusCode !== 200) {
throw new Error(`updatesite failed: ${res.status} ${JSON.stringify(data)}`);
}
return data;
}
async function main() {
const execute = process.argv.includes("--execute");
const current = await getSite();
const hashUpdate = buildHashUpdate();
const labelByColumnName = {
...hashUpdate.ClassHash,
...hashUpdate.NumHash,
...hashUpdate.DateHash,
...hashUpdate.DescriptionHash,
...hashUpdate.CheckHash,
};
const currentColumns = (current.SiteSettings && current.SiteSettings.Columns) || [];
// ラベル定義はトップレベルのClassHash等ではなく、SiteSettings.Columns[].LabelTextへ
// ネストして送る必要がある公式マニュアルapi-site-update準拠、実機確認済み。
// トップレベルへ送ると404になる。add-existence-flag-fields.jsと同じパターン
const mergedColumns = currentColumns.map((col) =>
labelByColumnName[col.ColumnName] !== undefined
? { ...col, LabelText: labelByColumnName[col.ColumnName] }
: col
);
const body = {
ApiVersion: "1.1",
ApiKey: API_KEY,
Title: NEW_TITLE,
ReferenceType: current.ReferenceType,
ParentId: current.ParentId,
InheritPermission: current.InheritPermission,
Permissions: current.Permissions,
SiteSettings: { ...current.SiteSettings, Columns: mergedColumns },
};
console.log("--- 現状 → 希望 ---");
console.log(`Title: "${current.Title}" -> "${NEW_TITLE}"`);
for (const col of currentColumns) {
const wantLabel = labelByColumnName[col.ColumnName];
if (wantLabel !== undefined && wantLabel !== col.LabelText) {
console.log(`${col.ColumnName}: "${col.LabelText}" -> "${wantLabel}"`);
}
}
console.log("\n--- 送信されるBodyColumnsは件数のみ表示 ---");
console.log(JSON.stringify({ ...body, ApiKey: "****", SiteSettings: { ...body.SiteSettings, Columns: `(${mergedColumns.length}件)` } }, null, 2));
if (!execute) {
console.log("\n[ドライラン] --execute を付けずに実行したため送信していません。内容を確認してから --execute を付けて再実行してください。");
return;
}
const result = await updateSite(body);
console.log("\n[OK] 送信結果:", JSON.stringify(result));
await getSite(); // 反映後の状態をconfigs/へ保存getSite内でsaveSiteSnapshot実行
console.log(`[OK] 反映後の状態をconfigs/${SITE_ID}/latest.jsonへ保存`);
}
main().catch((e) => {
console.error(e);
process.exit(1);
});