@rex0220/print-craft-authoring-tools 1.1.0 → 1.3.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 (41) hide show
  1. package/README.md +9 -4
  2. package/SECURITY.md +6 -2
  3. package/dist/cli.mjs +450 -150
  4. package/dist/core.mjs +3422 -0
  5. package/dist/types/_print-craft/src/authoring/api.d.ts +3 -0
  6. package/dist/types/_print-craft/src/config/load.d.ts +4 -0
  7. package/dist/types/_print-craft/src/config/schema.d.ts +5 -0
  8. package/dist/types/commands/buttons.d.ts +19 -0
  9. package/dist/types/commands/diff.d.ts +6 -0
  10. package/dist/types/commands/fields.d.ts +54 -0
  11. package/dist/types/commands/normalize.d.ts +40 -0
  12. package/dist/types/commands/preview.d.ts +39 -0
  13. package/dist/types/commands/pull.d.ts +36 -0
  14. package/dist/types/commands/record.d.ts +63 -0
  15. package/dist/types/commands/records.d.ts +36 -0
  16. package/dist/types/commands/save.d.ts +50 -0
  17. package/dist/types/commands/take.d.ts +19 -0
  18. package/dist/types/commit-file.d.ts +38 -0
  19. package/dist/types/context.d.ts +10 -0
  20. package/dist/types/core.d.ts +32 -0
  21. package/dist/types/engine.d.ts +64 -0
  22. package/dist/types/env.d.ts +50 -0
  23. package/dist/types/kintone-rest.d.ts +65 -0
  24. package/dist/types/kintone-url.d.ts +11 -0
  25. package/dist/types/meta.d.ts +30 -0
  26. package/dist/types/normalize/checks.d.ts +58 -0
  27. package/dist/types/normalize/css-check.d.ts +53 -0
  28. package/dist/types/normalize/derive.d.ts +30 -0
  29. package/dist/types/normalize/findings.d.ts +21 -0
  30. package/dist/types/normalize/html-check.d.ts +23 -0
  31. package/dist/types/normalize/line-diff.d.ts +8 -0
  32. package/dist/types/normalize/model.d.ts +36 -0
  33. package/dist/types/normalize/policy.d.ts +29 -0
  34. package/dist/types/normalize/size.d.ts +16 -0
  35. package/dist/types/paths.d.ts +7 -0
  36. package/dist/types/permission.d.ts +21 -0
  37. package/dist/types/plugin-zip.d.ts +53 -0
  38. package/dist/types/preview/render.d.ts +82 -0
  39. package/dist/types/safe-path.d.ts +24 -0
  40. package/dist/types/workspace.d.ts +84 -0
  41. package/package.json +10 -2
@@ -0,0 +1,3 @@
1
+ // 中核の型(dist/types/)を作るときだけ使う代わりの型。印刷屋の authoring API の型は印刷屋のリポジトリにあり、npm には出さない。
2
+ // 公開の型では any とする(中核を使う側は engine.api を直接使わず、中核の関数に渡すだけ)。tools の開発中の型の検査は本物の型で行う(tsconfig.json)
3
+ export type PrintCraftAuthoringApi = any;
@@ -0,0 +1,4 @@
1
+ // 中核の型(dist/types/)を作るときだけ使う代わりの型(api.d.ts と同じ考え)
2
+ export type FieldInfo = any;
3
+ export type FieldProp = any;
4
+ export type PrintCraftSaved = any;
@@ -0,0 +1,5 @@
1
+ // 中核の型(dist/types/)を作るときだけ使う代わりの型(api.d.ts と同じ考え)
2
+ export type MenuRow = any;
3
+ export type CssRow = any;
4
+ export type TagRow = any;
5
+ export type CalcField = any;
@@ -0,0 +1,19 @@
1
+ /**
2
+ * buttons <settings.json> [--button <名前>]
3
+ * 設定 JSON(封筒形式。normalize の前でも後でも)のボタンを 1 ボタン数行で一覧にする。--button でそのボタンの HTML 設定と更新項目の中身を出す
4
+ * (data: の URL は先頭と長さだけ。ファイルには元のまま)。通信しない・印刷屋の zip を読まない。
5
+ * 既存の設定(数十 KB。社印の data URL を含む)を AI が丸ごと読まずに済むように(2026-10-05、試用の納品書の計測で AI が node -e で同じ一覧を作っていた)
6
+ */
7
+ export declare class ButtonNotFoundError extends Error {
8
+ }
9
+ /** data: の URL を先頭と長さだけにする(社印の SVG などで数 KB〜数十 KB になる) */
10
+ export declare function shortenDataUrls(s: string, opt?: {
11
+ hash?: boolean;
12
+ }): string;
13
+ export interface ButtonsOptions {
14
+ /** 画面に出すファイル名 */
15
+ file: string;
16
+ /** この名前のボタンの中身を出す(同じ名前が複数あればすべて) */
17
+ button?: string;
18
+ }
19
+ export declare function listButtons(settings: Record<string, unknown>, opt: ButtonsOptions): string;
@@ -0,0 +1,6 @@
1
+ type Obj = Record<string, unknown>;
2
+ export declare function diffSettings(beforeEnvelope: Obj, afterEnvelope: Obj, opt?: {
3
+ derived?: boolean;
4
+ }): string;
5
+ export declare const DERIVED_KEYS: Set<string>;
6
+ export {};
@@ -0,0 +1,54 @@
1
+ /**
2
+ * fields --app N [--lang ja] [--preview] [--guest S] [--out fields/<file>]
3
+ * 項目定義(/k/v1/app/form/fields の properties)、レイアウト(/k/v1/app/form/layout)、アプリ名(/k/v1/app)を 1 つの JSON に保存する。
4
+ * 設定画面は preview の API を読む(load.ts 204 / 209 行)ので --preview で同じ API に切り替えられる(既定は運用中の形。
5
+ * preview は API トークンでは呼べないことがある)。normalize / preview はこのファイルから pp と更新項目の一覧を作る。
6
+ */
7
+ import type { RestClient } from "../kintone-rest.ts";
8
+ export interface FieldProperty {
9
+ type: string;
10
+ code: string;
11
+ label: string;
12
+ fields?: Record<string, FieldProperty>;
13
+ [key: string]: unknown;
14
+ }
15
+ export interface LayoutRow {
16
+ type?: string;
17
+ code?: string;
18
+ fields?: Array<{
19
+ type?: string;
20
+ code?: string;
21
+ [key: string]: unknown;
22
+ }>;
23
+ layout?: LayoutRow[];
24
+ [key: string]: unknown;
25
+ }
26
+ /** fields/<app>.json の形 */
27
+ export interface FieldsFile {
28
+ tool: "pcraft-authoring fields";
29
+ fetchedAt: string;
30
+ baseUrl: string;
31
+ appId: number;
32
+ appName: string;
33
+ guestSpaceId?: number;
34
+ preview: boolean;
35
+ lang: string;
36
+ revision: string;
37
+ properties: Record<string, FieldProperty>;
38
+ layout: LayoutRow[];
39
+ }
40
+ export interface FieldsOptions {
41
+ app: number;
42
+ lang?: string;
43
+ preview?: boolean;
44
+ guestSpaceId?: number;
45
+ now?: () => Date;
46
+ }
47
+ export declare function fetchFields(client: RestClient, opt: FieldsOptions): Promise<FieldsFile>;
48
+ /**
49
+ * fields --summary: 取得済みの fields/<app>.json を 1 項目 1 行で(レイアウトの順。テーブルの子は字下げ。通信しない)。
50
+ * AI が項目定義の JSON を丸ごと読まずに済むように(2026-10-05、試用の納品書の計測で AI が node -e で同じ要約を作っていた)
51
+ */
52
+ export declare function listFields(file: FieldsFile): string;
53
+ /** 画面に出す要約(項目の数と型。値は無い) */
54
+ export declare function summarizeFields(file: FieldsFile): string;
@@ -0,0 +1,40 @@
1
+ import type { Engine } from "../engine.ts";
2
+ import type { FieldsFile } from "./fields.ts";
3
+ import { Findings } from "../normalize/findings.ts";
4
+ import { loadPolicy, type Policy } from "../normalize/policy.ts";
5
+ import { type StoredSize } from "../normalize/size.ts";
6
+ export declare const PLUGIN_NAME = "\u5370\u5237\u5C4B\u30D7\u30E9\u30B0\u30A4\u30F3";
7
+ /** fields / record / 設定 JSON のファイルの上限(設定 JSON はさらに kit の 4 MB) */
8
+ export declare const MAX_INPUT_BYTES: number;
9
+ export declare class InputError extends Error {
10
+ }
11
+ export interface NormalizeInput {
12
+ settingsText: string;
13
+ settingsFile?: string;
14
+ fields: FieldsFile;
15
+ engine: Engine;
16
+ policy?: Policy;
17
+ check?: boolean;
18
+ /** .env の KINTONE_BASE_URL(検証済み)。iframe の同一オリジンの判定はこちらを使い、fields の baseUrl と違えば警告 */
19
+ baseUrl?: string;
20
+ now?: () => Date;
21
+ }
22
+ export interface NormalizeResult {
23
+ findings: Findings;
24
+ output?: Record<string, unknown>;
25
+ body?: Record<string, unknown>;
26
+ size?: StoredSize;
27
+ checkDiffs?: string[];
28
+ summary: string;
29
+ }
30
+ export declare function formatDate(d: Date): string;
31
+ /** 2 つの値の差を path 付きで集める(短く) */
32
+ export declare function jsonDiff(a: unknown, b: unknown, pathStr: string, out: string[]): void;
33
+ export declare function normalizeSettings(input: NormalizeInput): Promise<NormalizeResult>;
34
+ /** 大きさの上限を確かめてからテキストを読む */
35
+ export declare function readTextLimited(file: string, maxBytes?: number): string;
36
+ /** 大きさの上限を確かめてから JSON を読む(最上位はオブジェクト) */
37
+ export declare function readJsonLimited(file: string, maxBytes?: number): Record<string, unknown>;
38
+ export declare function readFieldsFile(file: string): Promise<FieldsFile>;
39
+ export declare function relativeSettingsPath(file: string, cwd: string): string;
40
+ export { loadPolicy };
@@ -0,0 +1,39 @@
1
+ /**
2
+ * preview <settings.json> --fields <fields.json> --record <record.json> [--button <名前>] [--out-dir <dir>] [--json]
3
+ * 正規化(normalize と同じ手順。エラーがあれば止まる)→ 有効なボタンごとに帳票 HTML(sandbox の iframe + CSP)→ out/<ボタン名>.html。
4
+ * 一覧帳票(list)は 1 レコードでは作れないので対象外(段階 2)。式の失敗は帳票に赤字で埋め、終了コード 1。
5
+ * Web フォントは配信元が承認済み(policy。Google Fonts は既定)のときだけ帳票の文書に入れる(render.ts)。
6
+ * ファイル名はボタン名から使えない文字と Windows の予約名を除き、同じ名前になるときは -2、-3 を付ける(1-10 レビュー MAJOR 4)。
7
+ */
8
+ import { type Engine } from "../engine.ts";
9
+ import type { FieldsFile } from "./fields.ts";
10
+ import { type KintoneRecord } from "./record.ts";
11
+ import { type Policy } from "../normalize/policy.ts";
12
+ import { Findings } from "../normalize/findings.ts";
13
+ import { type RenderedButton } from "../preview/render.ts";
14
+ export interface PreviewInput {
15
+ settingsText: string;
16
+ settingsFile?: string;
17
+ fields: FieldsFile;
18
+ recordFile: unknown;
19
+ engine: Engine;
20
+ policy?: Policy;
21
+ button?: string;
22
+ /** .env の KINTONE_BASE_URL(検証済み。normalize と同じ) */
23
+ baseUrl?: string;
24
+ }
25
+ export interface PreviewResult {
26
+ findings: Findings;
27
+ results: Array<RenderedButton & {
28
+ file: string;
29
+ }>;
30
+ skipped: string[];
31
+ summary: string;
32
+ }
33
+ /** レコードの形を 3 通り受ける */
34
+ export declare function extractRecord(file: unknown): KintoneRecord;
35
+ /** ボタン名 → 出力ファイル名(重複は -2、-3 …) */
36
+ export declare function previewFileNames(rows: Array<{
37
+ menu: string;
38
+ }>): string[];
39
+ export declare function runPreview(input: PreviewInput): Promise<PreviewResult>;
@@ -0,0 +1,36 @@
1
+ /**
2
+ * pull --app N [--preview] [--guest S] [--out settings/<file>] [--force] [--plugin-id <id>]
3
+ * アプリに入っている印刷屋プラグインの今の設定を kintone から取って、設定画面の「設定をダウンロード」と同じ封筒形式で settings/ に保存する
4
+ * (Takashi 2026-10-05「対象は、tools のみで GET だけ。プラグインは対象外」)。
5
+ * - API は kintone の API ラボ「アプリに追加されているプラグインの設定情報を取得する」(GET /k/v1/app/plugin/config.json、
6
+ * 動作テスト環境は /k/v1/preview/app/plugin/config.json)。使うには cybozu.com 共通管理者がアップデートオプションの「検討中の新機能」で
7
+ * 「アプリに追加されているプラグインの設定情報を取得または更新するREST API」を有効にする。変更の PUT は呼ばない(tools は GET だけ)
8
+ * - 権限: 運用中の設定はレコード閲覧(API トークンでも可。資料は「閲覧と追加」だが閲覧だけで取れた。2026-10-09 アプリ 3740 で確かめた)、
9
+ * --preview(動作テスト環境 = 設定画面で保存してまだ反映していないもの)はアプリ管理(閲覧だけのトークンでは 403 GAIA_NO01)
10
+ * - プラグイン ID は印刷屋の zip の PUBKEY から(plugin-zip.ts の pluginIdOf。5 変種とも同じ)
11
+ * - 保存値は設定画面と同じ手順で読む: kit の readConfig(圧縮形式など)→ 設定のスキーマで検証(未知のキーと共通項目の更新日時などは落ちる)
12
+ */
13
+ import type { RestClient } from "../kintone-rest.ts";
14
+ import type { Engine } from "../engine.ts";
15
+ export interface PullOptions {
16
+ app: number;
17
+ /** 動作テスト環境の設定(既定は運用中) */
18
+ preview?: boolean;
19
+ guestSpaceId?: number;
20
+ pluginId: string;
21
+ now?: () => Date;
22
+ }
23
+ export interface PullResult {
24
+ envelope: Record<string, unknown>;
25
+ appName: string;
26
+ revision: string;
27
+ /** 保存値の形式(compressed など。kit の readConfig) */
28
+ format: string;
29
+ }
30
+ export declare const PLUGIN_ID_PATTERN: RegExp;
31
+ export declare function pullSettings(client: RestClient, engine: Engine, opt: PullOptions): Promise<PullResult>;
32
+ /**
33
+ * 既定の保存先のファイル名 APP<番号>-<アプリ名>.json(ファイル名に使えない文字は _。safe-path.ts の safeFileName)。
34
+ * テンプレートの settings/ の決まり(APP3740-見積書-ご提案書.json)とそろえる(2026-10-06 Takashi「APP3740- がよいのでは?」)
35
+ */
36
+ export declare function defaultPullName(appName: string, appId: number): string;
@@ -0,0 +1,63 @@
1
+ /**
2
+ * record --app N --id R [--fields-from <settings.json>] [--guest S] [--out records/<file>]
3
+ * レコードを /k/v1/record({ type, value }、テーブルは入れ子)で取って records/<app>-<id>.json に保存する。preview の入力。
4
+ * レコードは個人情報を含むので、--fields-from で設定が使う項目だけ残し、中身は画面とログに出さない(Codex MAJOR 5)。
5
+ */
6
+ import type { RestClient } from "../kintone-rest.ts";
7
+ import type { FieldsFile } from "./fields.ts";
8
+ export type FieldValue = {
9
+ type: string;
10
+ value: unknown;
11
+ };
12
+ export type KintoneRecord = Record<string, FieldValue>;
13
+ export interface RecordFile {
14
+ tool: "pcraft-authoring record";
15
+ fetchedAt: string;
16
+ baseUrl: string;
17
+ appId: number;
18
+ id: number;
19
+ guestSpaceId?: number;
20
+ /** --fields-from で絞ったときの残した項目(絞らなければ無い) */
21
+ keptFields?: string[];
22
+ record: KintoneRecord;
23
+ }
24
+ export interface RecordOptions {
25
+ app: number;
26
+ id: number;
27
+ guestSpaceId?: number;
28
+ /** 残す項目(undefined なら全部) */
29
+ keep?: Set<string>;
30
+ now?: () => Date;
31
+ }
32
+ /**
33
+ * 式の中で項目コードになりうる語("…" の文字列の中身と数値を除く)。計算式の文字列は \ を解釈しないので "…" は次の " まで。
34
+ * 関数名やコメントの語も拾うが、絞るときはレコードにある項目しか残らないので害は無い(多めに拾う。絞りすぎるとプレビューが空欄になる)
35
+ */
36
+ export declare function identifiersOf(expr: string): string[];
37
+ /**
38
+ * 設定 JSON(封筒形式。正規化済みでなくてもよい)から、帳票と更新項目が使う項目コードを集める。
39
+ * usedFields(あれば)、HTML 欄の ${式} と計算式の本文の語、更新項目の fieldcode、filecode。何も見つからなければ null(絞らない)。
40
+ * usedFields は計算式欄だけから作られ、HTML 欄の ${式}(宛名、合計など)を含まない(2026-10-06 のリハーサルで、--fields-from が宛名などを落として
41
+ * プレビューが空欄になっていたのを見つけた)
42
+ */
43
+ export declare function usedFieldCodes(settings: unknown): Set<string> | null;
44
+ /** keep の項目だけ残す。テーブルは、テーブル自身か子のどれかが keep にあれば残し、子は keep にあるものだけ(テーブル自身が keep なら全部) */
45
+ export declare function narrowRecord(record: KintoneRecord, keep: Set<string>): {
46
+ record: KintoneRecord;
47
+ kept: string[];
48
+ };
49
+ /**
50
+ * 設定が使う項目のうち、プレビューのレコードに無いもの(fields にある項目だけを見る。テーブルの子は、テーブルが無いか行があって子が無いとき)。
51
+ * 古い records/ や絞りすぎたレコードで帳票が空欄になるのを preview の警告で知らせる(2026-10-06)
52
+ */
53
+ export declare function missingInRecord(settings: unknown, fields: Pick<FieldsFile, "properties">, record: KintoneRecord): string[];
54
+ export declare function fetchRecord(client: RestClient, opt: RecordOptions): Promise<RecordFile>;
55
+ /**
56
+ * record --summary: 取得済みの records/<app>-<id>.json を 1 項目 1 行で。**値は出さず形だけ**(文字数・行数・数値の桁・件数・添付の種類。
57
+ * SECURITY.md「レコードの値を標準出力に出さない」)。プレビューのレコードとして使えるか(備考に改行、明細が複数行、添付あり)を見るため(2026-10-05)
58
+ */
59
+ export declare function describeRecord(file: RecordFile): string;
60
+ /** レコードの形を 1 項目 1 行で(値は出さない。record --summary と kintone_list_records が使う) */
61
+ export declare function shapeLines(record: KintoneRecord): string[];
62
+ /** 画面に出す要約(項目の数だけ。値は出さない) */
63
+ export declare function summarizeRecord(file: RecordFile): string;
@@ -0,0 +1,36 @@
1
+ /**
2
+ * レコードを数件、形の要約だけで見る(段階 0-2 の段 4。print-craft MCP の kintone_list_records の本体。docs/api-table.md、実装案 5.4)。
3
+ * プレビュー用の代表の 1 件を選ぶため。値・ファイル名・ユーザー名は返さない(形だけ。record --summary と同じ shapeLines)。保存もしない。
4
+ * - query は条件と並べ替えだけ。limit / offset を含めば止める(件数は AI に決めさせない。サーバーが末尾に limit を付ける)
5
+ * - query は 500 文字まで(URL の 8 KB の上限に届かないように)
6
+ * - 返す JSON の UTF-8 のバイト数に上限を付け、超える前の件で打ち切る(truncated。項目コードの日本語・エスケープ・query を含めて測る)
7
+ */
8
+ import type { RestClient } from "../kintone-rest.ts";
9
+ export declare const LIST_LIMIT = 5;
10
+ export declare const QUERY_MAX = 500;
11
+ /** AI に返す JSON の上限(docs/api-table.md の 64 KiB。JSON.stringify した UTF-8 のバイト数。Codex レビュー MINOR 7) */
12
+ export declare const SHAPE_TEXT_MAX: number;
13
+ export declare class QueryError extends Error {
14
+ }
15
+ /** 受け取った query を検査し、末尾に limit を付けた query を返す */
16
+ export declare function listQueryOf(query: string | undefined): string;
17
+ export interface RecordShape {
18
+ /** レコード番号($id) */
19
+ id: string;
20
+ /** 1 項目 1 行の形(値は出さない) */
21
+ lines: string[];
22
+ }
23
+ export interface RecordShapes {
24
+ appId: number;
25
+ query: string;
26
+ records: RecordShape[];
27
+ /** 返す文字の上限で打ち切った */
28
+ truncated: boolean;
29
+ }
30
+ /** maxBytes は試験用(既定 SHAPE_TEXT_MAX) */
31
+ export declare function listRecordShapes(client: RestClient, opt: {
32
+ app: number;
33
+ query?: string;
34
+ guestSpaceId?: number;
35
+ maxBytes?: number;
36
+ }): Promise<RecordShapes>;
@@ -0,0 +1,50 @@
1
+ import type { Engine } from "../engine.ts";
2
+ import type { Policy } from "../normalize/policy.ts";
3
+ import type { Finding } from "../normalize/findings.ts";
4
+ export type SaveStatus = "ok" | "invalid" | "conflict" | "denied" | "failed";
5
+ export interface SaveResult {
6
+ status: SaveStatus;
7
+ /** 作業フォルダーからの相対パス(区切りは /) */
8
+ path: string;
9
+ /** 確定したファイルの digest(sha256。ok のとき) */
10
+ digest?: string;
11
+ findings: Finding[];
12
+ /** status が ok でないときの理由(決まった文) */
13
+ message?: string;
14
+ /** status が ok でないときの誤りの種類(ConflictError、PermissionError、PathError、InputError など。想定外の失敗は Error) */
15
+ code?: string;
16
+ /** ok だが、確定の後に一時ファイルかロックを消せなかった(確定はしている。利用者に伝えて消してもらう) */
17
+ cleanup?: string[];
18
+ }
19
+ export interface SaveContext {
20
+ /** 作業フォルダーの実際のパス(WorkContext.root) */
21
+ root: string;
22
+ engine: Engine;
23
+ policy: Policy;
24
+ /** iframe の同一オリジンの判定に使う接続先(検証済み) */
25
+ baseUrl?: string;
26
+ /** 試験用: 確定の直後(片付けの前)に呼ぶ。print-craft MCP と CLI は渡さない */
27
+ afterPlace?: () => void;
28
+ }
29
+ /** 入力(content / replacement)の上限(バイト) */
30
+ export declare const MAX_SAVE_INPUT_BYTES: number;
31
+ /** ファイルの digest(sha256。pcraft_buttons が返し、pcraft_update_button が照合する) */
32
+ export declare function digestOf(text: string | Buffer): string;
33
+ /** 新しい設定を保存する(expectedAbsent: true が要る。同じ名前のファイルがあれば conflict) */
34
+ export declare function saveNewSettings(ctx: SaveContext, opt: {
35
+ path: string;
36
+ content: string;
37
+ fields?: string;
38
+ expectedAbsent: true;
39
+ }): Promise<SaveResult>;
40
+ /**
41
+ * 既存の設定のボタン 1 つを差し替える(無ければ末尾に足す)。expectedDigest は pcraft_buttons(buttons --json)が返した値。
42
+ * replacement はボタン 1 つ(pluginInfos の 1 行)の JSON。その menu が button と違えば invalid
43
+ */
44
+ export declare function updateButton(ctx: SaveContext, opt: {
45
+ path: string;
46
+ button: string;
47
+ expectedDigest: string;
48
+ replacement: string;
49
+ fields?: string;
50
+ }): Promise<SaveResult>;
@@ -0,0 +1,19 @@
1
+ import { type Workspace } from "../workspace.ts";
2
+ /** 印刷屋の設定の封筒の pluginID(印刷屋の PLUGIN_ID_NAME と同じ。engine の api.pluginId で確かめている) */
3
+ export declare const PRINT_CRAFT_PLUGIN_ID = "rex0220 Print craft plugin";
4
+ export interface TakeResult {
5
+ /** leftInInbox: 行き先には置いたが inbox の元を消せなかった(消してよい。次の take でも「同じもの」として消す) */
6
+ moved: Array<{
7
+ file: string;
8
+ to: string;
9
+ same: boolean;
10
+ leftInInbox?: boolean;
11
+ }>;
12
+ skipped: Array<{
13
+ file: string;
14
+ reason: string;
15
+ }>;
16
+ /** 置いたが一時ファイルを消せなかった、など(移したことは変わらない) */
17
+ warnings: string[];
18
+ }
19
+ export declare function takeInbox(cwdIn: string, ws: Workspace, envName?: string): TakeResult;
@@ -0,0 +1,38 @@
1
+ export declare const LOCK_STALE_MS = 60000;
2
+ /** 確定先に同じ名前のファイルが既にある(確かめた後に作られた場合を含む) */
3
+ export declare class FileExistsError extends Error {
4
+ }
5
+ /** 同じファイルへの別の書き込みがロックを持っている */
6
+ export declare class LockBusyError extends Error {
7
+ }
8
+ /** EPERM / EBUSY なら短く待ってやり直す(tries 回まで)。それ以外の失敗はそのまま投げる */
9
+ export declare function withRetry<T>(fn: () => T, tries?: number): T;
10
+ /** 片付けを 1 つずつ試し、失敗の文を返す(一方の失敗で他方を飛ばさない。EPERM / EBUSY は短く待ってやり直す) */
11
+ export declare function cleanupAll(steps: Array<() => void>, tries?: number): string[];
12
+ /** 確定先と同じフォルダーの一時ファイルの名前 */
13
+ export declare function tempPathFor(target: string): string;
14
+ /** 一時ファイルを新しい名前で確定する(同じ名前があれば FileExistsError。上書きしない)。link は試験用(ハードリンクが使えない場合を作る) */
15
+ export declare function placeNew(tmp: string, target: string, link?: (from: string, to: string) => void): void;
16
+ export interface WriteNewResult {
17
+ /** 確定の後の片付けの失敗(確定はしている) */
18
+ cleanup: string[];
19
+ }
20
+ /**
21
+ * 新しいファイルとして書く。recheck は一時ファイルを書く前と確定の直前に呼ぶ(書ける場所・許可を確かめ直す。投げれば確定しない)。
22
+ * 同じ名前があれば FileExistsError(確かめた後に作られた場合も)。失敗したら一時ファイルを消す
23
+ */
24
+ export declare function writeNewFile(target: string, text: string, recheck?: () => void): WriteNewResult;
25
+ export interface Lock {
26
+ /** まだ自分のロックか(確定の直前に確かめる) */
27
+ owned(): boolean;
28
+ /** 自分のロックなら外す(他の保存が取り直したロックは消さない)。外したら true */
29
+ release(): boolean;
30
+ }
31
+ export declare function lockPathFor(target: string): string;
32
+ /** 試験用: 古いロックを付け替える直前・戻す直前に呼ぶ(その間に替わる場合を作る) */
33
+ export interface LockTestHooks {
34
+ beforeClaim?: () => void;
35
+ beforeRestore?: () => void;
36
+ }
37
+ /** 確定先のロックを取る。取れなければ LockBusyError */
38
+ export declare function acquireLock(target: string, staleMs?: number, hooks?: LockTestHooks): Lock;
@@ -0,0 +1,10 @@
1
+ export interface WorkContext {
2
+ /** 作業フォルダーの実際のパス(絶対パス) */
3
+ readonly root: string;
4
+ /** 環境変数(OS のもの、または MCP の設定項目から作ったもの)。中核は process.env を直接読まない */
5
+ readonly env: Readonly<Record<string, string | undefined>>;
6
+ }
7
+ export declare function createContext(opt: {
8
+ cwd: string;
9
+ env: Readonly<Record<string, string | undefined>>;
10
+ }): WorkContext;
@@ -0,0 +1,32 @@
1
+ /**
2
+ * 共通の中核の入口(npm の @rex0220/print-craft-authoring-tools/core。print-craft-authoring-mcp の print-craft MCP が使う)。
3
+ * 2026-10-09 Takashi「B」: 別のパッケージにせず、tools のパッケージに入口を足す(公開も版も 1 つ。CLI と同じ版)。
4
+ * - 中核は process.cwd() / process.env を読まない。作業フォルダー(実際のパス)と環境変数は呼ぶ側が引数で渡す(context.ts)
5
+ * - 印刷屋のコード(計算式エンジン、authoring API)は含まない。利用者の印刷屋の zip から loadEngine が読む
6
+ * - ここに出すものが公開の約束。CLI(cli.ts)と開発用の dev-paths.ts は出さない
7
+ * ビルド: scripts/build.mjs が dist/core.mjs(ESM。happy-dom は依存のまま外に置く)と dist/types/(型)を作る。
8
+ */
9
+ export declare const CORE_API_VERSION = 1;
10
+ export { createContext, type WorkContext } from "./context.ts";
11
+ export { PathError, WRITE_ROOTS, isInside, realResolve, resolveRead, resolveWrite } from "./safe-path.ts";
12
+ export { PermissionError, assertChangeAllowed, classOfAppPath, roleOfTarget, type ChangeOp, type TargetClass, type TargetRole } from "./permission.ts";
13
+ export { EDIT_RE, INBOX, KINTONE_ROOT, SNAPSHOT_RE, WORKSPACE_FILE, WorkspaceError, appDirFor, appFolderOfFile, editNameOf, envOfAppFolder, findAppDir, folderNameOf, listAppFolder, loadWorkspace, parseWorkspace, pickEnv, resolveApp, snapshotNameOf, type EnvRole, type EnvironmentDef, type Workspace } from "./workspace.ts";
14
+ export { MIN_PLUGIN_VERSION, PRINT_CRAFT_PLUGIN_ID, SUPPORTED_API_VERSIONS, isSupportedPluginVersion, toolsMeta, type ToolsMeta } from "./meta.ts";
15
+ export { DEFAULT_CONTEXT_BASE_URL, loadEngine, type Engine, type LoadEngineOptions } from "./engine.ts";
16
+ export { PluginZipError } from "./plugin-zip.ts";
17
+ export { AuthError, baseUrlFromEnv, describeAuth, loadAuth, loadAuthForEnv, pluginZipPath, unquote, type KintoneAuth, type LoadAuthOptions } from "./env.ts";
18
+ export { KintoneUrlError, isKintoneBaseUrl, normalizeKintoneBaseUrl } from "./kintone-url.ts";
19
+ export { ALLOWED_APIS, NotAllowedError, RECEIVE_LIMITS, RestError, createRestClient, type AllowedApi, type FetchLike, type RestClient } from "./kintone-rest.ts";
20
+ export { InputError, MAX_INPUT_BYTES, normalizeSettings, readFieldsFile, readJsonLimited, readTextLimited, relativeSettingsPath, type NormalizeInput, type NormalizeResult } from "./commands/normalize.ts";
21
+ export { loadPolicy, type Policy } from "./normalize/policy.ts";
22
+ export { type Finding } from "./normalize/findings.ts";
23
+ export { MAX_SAVE_INPUT_BYTES, digestOf, saveNewSettings, updateButton, type SaveContext, type SaveResult, type SaveStatus } from "./commands/save.ts";
24
+ export { ButtonNotFoundError, listButtons, shortenDataUrls, type ButtonsOptions } from "./commands/buttons.ts";
25
+ export { DERIVED_KEYS, diffSettings } from "./commands/diff.ts";
26
+ export { fetchFields, listFields, summarizeFields, type FieldsFile, type FieldsOptions } from "./commands/fields.ts";
27
+ export { describeRecord, fetchRecord, missingInRecord, narrowRecord, shapeLines, summarizeRecord, usedFieldCodes, type KintoneRecord, type RecordFile, type RecordOptions } from "./commands/record.ts";
28
+ export { LIST_LIMIT, QUERY_MAX, QueryError, SHAPE_TEXT_MAX, listQueryOf, listRecordShapes, type RecordShape, type RecordShapes } from "./commands/records.ts";
29
+ export { extractRecord, previewFileNames, runPreview, type PreviewInput, type PreviewResult } from "./commands/preview.ts";
30
+ export { defaultPullName, pullSettings, type PullOptions, type PullResult } from "./commands/pull.ts";
31
+ export { takeInbox, type TakeResult } from "./commands/take.ts";
32
+ export { FileExistsError, LockBusyError, writeNewFile } from "./commit-file.ts";
@@ -0,0 +1,64 @@
1
+ import type { PrintCraftAuthoringApi } from "./_print-craft/src/authoring/api.ts";
2
+ import { type PluginSources } from "./plugin-zip.ts";
3
+ /** 計算式のインスタンス(print-craft の config/libs.ts の KintoneFormula と同じ形) */
4
+ export interface FormulaInstance {
5
+ funs: Record<string, unknown>;
6
+ usedFields(init?: Record<string, unknown>): Record<string, unknown>;
7
+ dq(expression: string): unknown;
8
+ initTableInfo?(ptcode: string): void;
9
+ }
10
+ export type FormulaCtor = new (name: string, pp: unknown, record: unknown, fieldCheck: boolean, strict?: boolean) => FormulaInstance;
11
+ export interface LoginUser {
12
+ id: string;
13
+ code: string;
14
+ name: string;
15
+ email: string;
16
+ language: string;
17
+ }
18
+ export interface KintoneContext {
19
+ baseUrl: string;
20
+ appId: number;
21
+ loginUser: LoginUser;
22
+ }
23
+ export interface EngineSource {
24
+ kind: "zip" | "dev";
25
+ from: string;
26
+ pluginVersion: string;
27
+ engineSha256: string;
28
+ apiSha256?: string;
29
+ /** プラグイン ID(zip の PUBKEY から。印刷屋のものでなければ読み込まない。pull が使う。開発中の print-craft から読んだときは無い) */
30
+ pluginId?: string;
31
+ }
32
+ export interface Engine {
33
+ window: Record<string, unknown>;
34
+ Ctor: FormulaCtor;
35
+ /** 印刷屋の authoring API(設定画面・帳票のコードと kit) */
36
+ api: PrintCraftAuthoringApi;
37
+ source: EngineSource;
38
+ /** 読み込み時の注意(既知でない中身を許して続けたなど) */
39
+ warnings: string[];
40
+ setContext(ctx: Partial<KintoneContext>): void;
41
+ /** 設定画面と同じ検証用のインスタンス(createFormula) */
42
+ checker(pp: unknown, crec: unknown): FormulaInstance;
43
+ /** デスクトップと同じ実行用のインスタンス(newFormula) */
44
+ runner(pp: unknown, record: unknown): FormulaInstance;
45
+ functionNames(): string[];
46
+ }
47
+ export interface LoadEngineOptions {
48
+ /**
49
+ * 印刷屋の zip。中核は環境変数を読まない(段階 0-2。CLI は .env / OS の環境変数の PCRAFT_PLUGIN_ZIP を env.ts の pluginZipPath で
50
+ * 決めて渡す。print-craft MCP は設定項目から渡す)
51
+ */
52
+ pluginZip?: string;
53
+ /** 開発中(mode dev)の読み込み元(隣の print-craft の prod/)。CLI は環境変数 PCRAFT_ALLOW_DEV_PLUGIN=1 のときだけ dev-paths.ts の printCraftProdDir で決めて渡す */
54
+ devPluginDir?: string;
55
+ /** テスト用。省略時は toolsMeta().mode(ソースから動かすと dev、ビルドした bundle は build) */
56
+ mode?: "build" | "dev";
57
+ }
58
+ /** 接続先が分からないときの APP_URL などの元(実在しないテナント) */
59
+ export declare const DEFAULT_CONTEXT_BASE_URL = "https://example.cybozu.com";
60
+ /** 読み込み元を決める: zip(引数 → 環境変数)。開発中(mode dev + PCRAFT_ALLOW_DEV_PLUGIN=1)だけ隣の print-craft の prod/ */
61
+ export declare function resolvePluginSources(opt?: LoadEngineOptions, mode?: "build" | "dev"): PluginSources & {
62
+ kind: "zip" | "dev";
63
+ };
64
+ export declare function loadEngine(opt?: LoadEngineOptions): Promise<Engine>;
@@ -0,0 +1,50 @@
1
+ export interface KintoneAuth {
2
+ baseUrl: string;
3
+ token?: string;
4
+ username?: string;
5
+ password?: string;
6
+ }
7
+ /** 前後の空白と、対になった外側の " / ' を外す(.env の値と、OS の環境変数の場所・URL。Windows の「パスのコピー」で付く引用符。引用符の中の空白は値のうち) */
8
+ export declare function unquote(raw: string): string;
9
+ /** .env の形(KEY=VALUE。# の行と空行は無視。両端の " ' は外す。export KEY=… も可) */
10
+ export declare function parseDotEnv(text: string): Record<string, string>;
11
+ export interface LoadAuthOptions {
12
+ /** テスト用。CLI からは渡さない(.env は cwd のものだけ) */
13
+ envFile?: string;
14
+ /** 作業フォルダー(.env の場所。WorkContext.root) */
15
+ cwd: string;
16
+ /** 環境変数(WorkContext.env)。中核は process.env を直接読まない */
17
+ env: Readonly<Record<string, string | undefined>>;
18
+ }
19
+ export declare class AuthError extends Error {
20
+ }
21
+ /** 値と、その出所(OS の環境変数か .env か)。相対パスの解決の起点を出所で変えるため(段階 0-2 の段 2) */
22
+ export interface Picked {
23
+ value: string;
24
+ /** process = OS の環境変数(print-craft MCP では設定項目から作った環境変数)、file = .env */
25
+ source: "process" | "file";
26
+ /** source が file のときの .env のパス */
27
+ file?: string;
28
+ }
29
+ export declare function envFileOf(opt: LoadAuthOptions): string;
30
+ /** 接続先の URL(検証済み。無ければ undefined) */
31
+ export declare function baseUrlFromEnv(opt: LoadAuthOptions): string | undefined;
32
+ export declare function loadAuth(opt: LoadAuthOptions): KintoneAuth;
33
+ /**
34
+ * environments.json の環境の認証(workspace.ts。2026-10-05)。接続先は environments.json の baseUrl、認証はその環境の envFile(.env か env/<名前>.env。
35
+ * 場所は environments.json の値だけで、CLI から指定できない)だけから読む。OS の KINTONE_* / KSQL_* は読まない(開発と本番の取り違えを防ぐ。
36
+ * OS に本番の KINTONE_BASE_URL があっても開発の環境で使わない)。envFile に KINTONE_BASE_URL があり environments.json と違えば止まる
37
+ */
38
+ export declare function loadAuthForEnv(env: {
39
+ name: string;
40
+ baseUrl: string;
41
+ envFile: string;
42
+ }, cwd: string): KintoneAuth;
43
+ /**
44
+ * 印刷屋の zip の場所(OS の環境変数か .env の PCRAFT_PLUGIN_ZIP。無ければ undefined = 開発中の print-craft を探す)。
45
+ * .env に書いた相対パスは .env のフォルダーから解決する(今までどおり)。OS の環境変数(print-craft MCP では設定項目)の値は
46
+ * 絶対パスだけを受け付ける(相対パスの起点が起動の場所に左右されるため。Desktop の起動の場所は / や C:\Windows\System32。段階 0-2 の段 2)
47
+ */
48
+ export declare function pluginZipPath(opt: LoadAuthOptions): string | undefined;
49
+ /** 認証の種類だけを文言にする(値もユーザー名も出さない) */
50
+ export declare function describeAuth(auth: KintoneAuth): string;