@diviops/mcp-server 1.5.34 → 1.5.36
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.
- package/README.md +33 -12
- package/dist/capability-envelope.d.ts +12 -0
- package/dist/capability-envelope.js +29 -0
- package/dist/cross-env-preflight/cli.js +28 -9
- package/dist/cross-env-preflight/header-preflight.d.ts +4 -0
- package/dist/cross-env-preflight/layout-capability.d.ts +3 -0
- package/dist/cross-env-preflight/layout-capability.js +6 -0
- package/dist/cross-env-preflight/layout-preflight.d.ts +89 -0
- package/dist/cross-env-preflight/layout-preflight.js +202 -0
- package/dist/cross-env-preflight/source-payload-ref.d.ts +1 -1
- package/dist/cross-env-preflight/source-payload-ref.js +4 -1
- package/dist/index.js +439 -165
- package/dist/preset-cli/cli.js +5 -1
- package/dist/preset-cli/write-path.d.ts +23 -19
- package/dist/preset-cli/write-path.js +47 -39
- package/dist/validate-attrs.d.ts +15 -13
- package/dist/validate-attrs.js +91 -13
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -83,7 +83,7 @@ The skill enforces the Divi block format, the design system, and the response co
|
|
|
83
83
|
|
|
84
84
|
## Tools at a glance
|
|
85
85
|
|
|
86
|
-
The server exposes **
|
|
86
|
+
The server exposes **91 always-on tools** across the categories below. Each category links to representative tools; the full table lives in [server-reference.md](../docs/server-reference.md).
|
|
87
87
|
|
|
88
88
|
| Category | Use case | Tool prefixes |
|
|
89
89
|
|----------|----------|---------------|
|
|
@@ -108,10 +108,12 @@ Additional **conditionally-registered Pro tools** appear only on sites that have
|
|
|
108
108
|
| FluentCart simple product writes (V2) | Pro plugin + FluentCart installed + module enabled | `diviops_fc_product_create`, `diviops_fc_product_update`, `diviops_fc_product_delete` |
|
|
109
109
|
| FluentCart variation read/write (V3) | Pro plugin + FluentCart installed + module enabled | `diviops_fc_variation_list`, `diviops_fc_variation_update` |
|
|
110
110
|
| FluentCart license-settings read/write, incl. update-file pointer + readiness (V3/V3.3) | Pro plugin + FluentCart Pro installed + module enabled | `diviops_fc_license_settings_get`, `diviops_fc_license_settings_update` |
|
|
111
|
+
| FluentCart managed downloads + license changelog (V3.4) | Pro plugin + FluentCart installed + module enabled | `diviops_fc_download_list`, `diviops_fc_download_attach`, `diviops_fc_license_changelog_get`, `diviops_fc_license_changelog_update` |
|
|
111
112
|
| FluentCart order readback + guarded mark-paid (V3.1) | Pro plugin + FluentCart installed + module enabled | `diviops_fc_order_list`, `diviops_fc_order_get`, `diviops_fc_order_mark_paid` |
|
|
112
113
|
| FluentCart license readback (V3.1) | Pro plugin + FluentCart Pro installed + module enabled | `diviops_fc_license_list`, `diviops_fc_license_get`, `diviops_fc_license_activations_list` |
|
|
113
114
|
| FluentCart checkout readiness / gateway inspection (V3.2) | Pro plugin + FluentCart installed + module enabled | `diviops_fc_status`, `diviops_fc_gateway_list`, `diviops_fc_gateway_get` |
|
|
114
|
-
| Cross-env
|
|
115
|
+
| Cross-env reviewed layout rollout | Pro plugin + `cross_env` module enabled | `diviops_cross_env_header_apply`, `diviops_cross_env_layout_apply` |
|
|
116
|
+
| Managed recovery Phase 1A | Pro plugin + opt-in `managed_recovery` module enabled | `diviops_managed_recovery_policy_get`, `diviops_managed_recovery_policy_preview`, `diviops_managed_recovery_policy_update`, `diviops_managed_recovery_retention_preview`, `diviops_managed_recovery_retention_apply`, `diviops_managed_recovery_audit_list` |
|
|
115
117
|
|
|
116
118
|
When the gates are not satisfied, the tools simply don't appear on the MCP surface — no error envelope, no missing-capability hint. See the `diviops-fluentcart` skill bundle for the operator-side guide.
|
|
117
119
|
|
|
@@ -171,8 +173,13 @@ diviops-cross-env-preflight --source source.json --target target.json --dry-run
|
|
|
171
173
|
|
|
172
174
|
This command reads two secret-free JSON files and prints a report. It does not
|
|
173
175
|
connect to WordPress, does not accept credentials, and has no write/apply path.
|
|
174
|
-
The
|
|
175
|
-
existing
|
|
176
|
+
The CLI supports `tb_header_layout` and `tb_footer_layout` source payloads
|
|
177
|
+
preflighted against existing same-kind targets. Header-only inputs retain the
|
|
178
|
+
shipped header-v1 report/fingerprint; footer inputs use the generic layout-v1
|
|
179
|
+
binding by default. Pass `--contract layout-v1` to emit the generic binding for
|
|
180
|
+
a header rollout through `diviops_cross_env_layout_apply`; `--contract
|
|
181
|
+
header-v1` explicitly selects the compatibility contract and accepts header
|
|
182
|
+
inputs only. It reports source-domain upload URL
|
|
176
183
|
rewrites, attachment remap status, `gcid-*` target resolution including Divi
|
|
177
184
|
built-in customizer colors, resolved target global-color value evidence,
|
|
178
185
|
referenced `modulePreset` target-presence status, off-canvas/canvas refusal, and
|
|
@@ -182,8 +189,14 @@ target identity/current target checksum, rewrite plan, cache plan,
|
|
|
182
189
|
blocker/operator-action codes, reference-resolution summaries, target module
|
|
183
190
|
preset resolution, and the per-`gcid` value evidence for target colors
|
|
184
191
|
referenced by the source layout.
|
|
185
|
-
The fingerprint is reviewed-plan evidence for the Pro-gated
|
|
186
|
-
`diviops_cross_env_header_apply`
|
|
192
|
+
The fingerprint is reviewed-plan evidence for the Pro-gated compatibility
|
|
193
|
+
`diviops_cross_env_header_apply` or generic `diviops_cross_env_layout_apply`
|
|
194
|
+
tool. The CLI itself still has no apply path.
|
|
195
|
+
|
|
196
|
+
The Free plugin advertises `cross_env_footer_layout_evidence` when its source
|
|
197
|
+
export and target-context routes support footer kinds. The server selects those
|
|
198
|
+
two tools' public enums only after handshake: older or unproven plugins retain
|
|
199
|
+
the shipped header-only schemas instead of advertising unsupported footer input.
|
|
187
200
|
|
|
188
201
|
To collect the source JSON from the source WordPress site, call the Free/core
|
|
189
202
|
read-only MCP tool `diviops_cross_env_source_export_get` and save the returned
|
|
@@ -197,8 +210,8 @@ filesystem paths.
|
|
|
197
210
|
|
|
198
211
|
The MCP server also writes the same source payload to a bounded local artifact
|
|
199
212
|
under `.diviops-tmp/cross-env-source-payloads/` and returns
|
|
200
|
-
`data.source_payload_ref`. Use that reference for large real
|
|
201
|
-
calling
|
|
213
|
+
`data.source_payload_ref`. Use that reference for large real layouts when
|
|
214
|
+
calling a Pro layout apply tool; it avoids asking an LLM
|
|
202
215
|
to re-emit large markup byte-for-byte. The reference is a server-created handle
|
|
203
216
|
plus checksum, not an arbitrary filesystem path.
|
|
204
217
|
|
|
@@ -217,6 +230,11 @@ entries that are referenced by source markup.
|
|
|
217
230
|
It also includes target D5 module preset IDs, without preset definitions, so the
|
|
218
231
|
preflight can fail closed when source markup references a module preset the
|
|
219
232
|
target site does not have.
|
|
233
|
+
For header/footer generic preflight it also includes exact target post type and
|
|
234
|
+
a canonical template-linkage digest over the active Theme Builder master ID,
|
|
235
|
+
its exact `_et_template` order, and linked-template slot, enabled, condition,
|
|
236
|
+
and exclusion evidence. Empty linkage uses `master_template_ids: []` and
|
|
237
|
+
`links: []`; assignment state is evidence only and is never mutated by rollout.
|
|
220
238
|
|
|
221
239
|
Workflow:
|
|
222
240
|
|
|
@@ -224,12 +242,15 @@ Workflow:
|
|
|
224
242
|
returned `data` object as `source.json`.
|
|
225
243
|
2. Call `diviops_cross_env_target_context_get` on the target site and save the
|
|
226
244
|
returned `data` object as `target.json`.
|
|
227
|
-
3. Run `diviops-cross-env-preflight --source source.json --target target.json --dry-run
|
|
245
|
+
3. Run `diviops-cross-env-preflight --source source.json --target target.json --dry-run --contract layout-v1`
|
|
246
|
+
for `diviops_cross_env_layout_apply`. Omit the contract flag (or select
|
|
247
|
+
`header-v1`) only for the compatibility header apply tool.
|
|
228
248
|
|
|
229
249
|
`--apply` is intentionally refused. To mutate a target, use the separate
|
|
230
|
-
Pro-gated `
|
|
231
|
-
and either inline `source_payload` for small/disposable tests or
|
|
232
|
-
`source_payload_ref` for large
|
|
250
|
+
Pro-gated `diviops_cross_env_layout_apply` tool with the generic reviewed
|
|
251
|
+
fingerprint and either inline `source_payload` for small/disposable tests or
|
|
252
|
+
`source_payload_ref` for large layouts. The existing header tool remains the
|
|
253
|
+
header-v1 compatibility path. Both refuse media
|
|
233
254
|
upload/import, global color creation/import, off-canvas reconcile, and new
|
|
234
255
|
target layout creation.
|
|
235
256
|
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { MissingCapabilityError } from "./compatibility.js";
|
|
2
|
+
export type MissingCapabilityMcpResult = {
|
|
3
|
+
content: Array<{
|
|
4
|
+
type: "text";
|
|
5
|
+
text: string;
|
|
6
|
+
}>;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Convert a server-side capability gate failure into the canonical DiviOps
|
|
10
|
+
* response envelope carried in MCP text content.
|
|
11
|
+
*/
|
|
12
|
+
export declare function missingCapabilityEnvelope(error: MissingCapabilityError, toolName: string, hint?: string): MissingCapabilityMcpResult;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { ErrorCodes, serializeEnvelope, } from "./envelope.js";
|
|
2
|
+
const DEFAULT_HINT = "Update the diviops-agent WP plugin to the version shipped with this MCP server release.";
|
|
3
|
+
/**
|
|
4
|
+
* Convert a server-side capability gate failure into the canonical DiviOps
|
|
5
|
+
* response envelope carried in MCP text content.
|
|
6
|
+
*/
|
|
7
|
+
export function missingCapabilityEnvelope(error, toolName, hint = DEFAULT_HINT) {
|
|
8
|
+
const failure = {
|
|
9
|
+
ok: false,
|
|
10
|
+
error: {
|
|
11
|
+
code: ErrorCodes.CAPABILITY_MISSING,
|
|
12
|
+
message: error.message,
|
|
13
|
+
hint,
|
|
14
|
+
data: {
|
|
15
|
+
capability: error.capability,
|
|
16
|
+
plugin_version: error.pluginVersion,
|
|
17
|
+
tool: toolName,
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
return {
|
|
22
|
+
content: [
|
|
23
|
+
{
|
|
24
|
+
type: "text",
|
|
25
|
+
text: serializeEnvelope(failure, toolName),
|
|
26
|
+
},
|
|
27
|
+
],
|
|
28
|
+
};
|
|
29
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { readFileSync } from "node:fs";
|
|
2
2
|
import { preflightCrossEnvHeaderSync, } from "./header-preflight.js";
|
|
3
|
+
import { preflightCrossEnvThemeBuilderLayoutSync } from "./layout-preflight.js";
|
|
3
4
|
export const EXIT = {
|
|
4
5
|
OK: 0,
|
|
5
6
|
INVALID_INPUT: 1,
|
|
@@ -7,16 +8,20 @@ export const EXIT = {
|
|
|
7
8
|
const HELP = `diviops-cross-env-preflight — dry-run cross-environment layout safety reports
|
|
8
9
|
|
|
9
10
|
USAGE
|
|
10
|
-
diviops-cross-env-preflight --source source.json --target target.json --dry-run
|
|
11
|
+
diviops-cross-env-preflight --source source.json --target target.json --dry-run [--contract <auto|header-v1|layout-v1>]
|
|
11
12
|
|
|
12
13
|
OPTIONS
|
|
13
|
-
--source <path>
|
|
14
|
-
--target <path>
|
|
15
|
-
--
|
|
16
|
-
|
|
17
|
-
--
|
|
14
|
+
--source <path> Secret-free source layout payload JSON.
|
|
15
|
+
--target <path> Secret-free target context JSON.
|
|
16
|
+
--contract <version> auto (default), header-v1, or layout-v1. Use layout-v1
|
|
17
|
+
for diviops_cross_env_layout_apply, including headers.
|
|
18
|
+
--dry-run Required/default. Produce a report only; no WordPress writes.
|
|
19
|
+
--apply Refused. No write/apply path exists in this MVP.
|
|
20
|
+
--help Show this help.
|
|
18
21
|
|
|
19
|
-
|
|
22
|
+
Supported kinds are tb_header_layout and tb_footer_layout. Existing header-only
|
|
23
|
+
inputs retain the shipped header-v1 report and fingerprint contract unless
|
|
24
|
+
--contract layout-v1 is explicitly selected.`;
|
|
20
25
|
function parseArgs(argv) {
|
|
21
26
|
const parsed = { help: false };
|
|
22
27
|
for (let i = 0; i < argv.length; i++) {
|
|
@@ -30,7 +35,7 @@ function parseArgs(argv) {
|
|
|
30
35
|
if (token === "--apply") {
|
|
31
36
|
throw new Error("--apply is not supported; this MVP is preflight-only.");
|
|
32
37
|
}
|
|
33
|
-
if (token === "--source" || token === "--target") {
|
|
38
|
+
if (token === "--source" || token === "--target" || token === "--contract") {
|
|
34
39
|
const value = argv[i + 1];
|
|
35
40
|
if (value === undefined || value.startsWith("--")) {
|
|
36
41
|
throw new Error(`${token} requires a value.`);
|
|
@@ -39,6 +44,12 @@ function parseArgs(argv) {
|
|
|
39
44
|
parsed.source = value;
|
|
40
45
|
if (token === "--target")
|
|
41
46
|
parsed.target = value;
|
|
47
|
+
if (token === "--contract") {
|
|
48
|
+
if (!["auto", "header-v1", "layout-v1"].includes(value)) {
|
|
49
|
+
throw new Error("--contract must be auto, header-v1, or layout-v1.");
|
|
50
|
+
}
|
|
51
|
+
parsed.contract = value;
|
|
52
|
+
}
|
|
42
53
|
i++;
|
|
43
54
|
continue;
|
|
44
55
|
}
|
|
@@ -69,7 +80,15 @@ export async function runCli(argv, io) {
|
|
|
69
80
|
source: readJsonFile(parsed.source),
|
|
70
81
|
target: readJsonFile(parsed.target),
|
|
71
82
|
};
|
|
72
|
-
const
|
|
83
|
+
const contract = parsed.contract ?? "auto";
|
|
84
|
+
const headerPair = input.source.object_kind === "tb_header_layout" &&
|
|
85
|
+
input.target.destination_kind === "tb_header_layout";
|
|
86
|
+
if (contract === "header-v1" && !headerPair) {
|
|
87
|
+
throw new Error("--contract header-v1 requires tb_header_layout source and target inputs.");
|
|
88
|
+
}
|
|
89
|
+
const report = contract === "layout-v1" || (contract === "auto" && !headerPair)
|
|
90
|
+
? preflightCrossEnvThemeBuilderLayoutSync(input)
|
|
91
|
+
: preflightCrossEnvHeaderSync(input);
|
|
73
92
|
io.out(JSON.stringify(report, null, 2));
|
|
74
93
|
return EXIT.OK;
|
|
75
94
|
}
|
|
@@ -12,6 +12,7 @@ export interface SourceLayoutPayload {
|
|
|
12
12
|
object_kind: CrossEnvObjectKind | string;
|
|
13
13
|
object_id?: number | string;
|
|
14
14
|
object_title?: string;
|
|
15
|
+
object_post_type?: string;
|
|
15
16
|
markup: string;
|
|
16
17
|
checksum?: string;
|
|
17
18
|
attachments?: SourceAttachmentInventoryItem[];
|
|
@@ -37,7 +38,10 @@ export interface TargetLayoutContext {
|
|
|
37
38
|
destination_kind: CrossEnvObjectKind | string;
|
|
38
39
|
destination_id?: number | string;
|
|
39
40
|
destination_title?: string;
|
|
41
|
+
destination_post_type?: string;
|
|
40
42
|
destination_checksum?: string | Sha256Checksum;
|
|
43
|
+
template_linkage?: unknown;
|
|
44
|
+
template_linkage_digest?: Sha256Checksum;
|
|
41
45
|
attachment_remaps?: Record<string, unknown>;
|
|
42
46
|
attachments?: TargetAttachmentInventoryItem[];
|
|
43
47
|
global_colors?: unknown;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export declare const CROSS_ENV_FOOTER_LAYOUT_EVIDENCE_CAPABILITY: "cross_env_footer_layout_evidence";
|
|
2
|
+
export type CrossEnvEvidenceLayoutKind = "tb_header_layout" | "tb_footer_layout";
|
|
3
|
+
export declare function crossEnvEvidenceLayoutKinds(capabilities: Record<string, boolean>): ["tb_header_layout"] | ["tb_header_layout", "tb_footer_layout"];
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export const CROSS_ENV_FOOTER_LAYOUT_EVIDENCE_CAPABILITY = "cross_env_footer_layout_evidence";
|
|
2
|
+
export function crossEnvEvidenceLayoutKinds(capabilities) {
|
|
3
|
+
return capabilities[CROSS_ENV_FOOTER_LAYOUT_EVIDENCE_CAPABILITY] === true
|
|
4
|
+
? ["tb_header_layout", "tb_footer_layout"]
|
|
5
|
+
: ["tb_header_layout"];
|
|
6
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { type CrossEnvVerdict, type GcidReference, type ModulePresetReference, type OffCanvasReference, type PreflightIssue, type Sha256Checksum, type SourceLayoutPayload, type TargetLayoutContext, type AttachmentReference, type UrlOccurrence } from "./header-preflight.js";
|
|
2
|
+
export declare const THEME_BUILDER_LAYOUT_KIND_POST_TYPES: {
|
|
3
|
+
readonly tb_header_layout: "et_header_layout";
|
|
4
|
+
readonly tb_footer_layout: "et_footer_layout";
|
|
5
|
+
};
|
|
6
|
+
export type CrossEnvThemeBuilderLayoutKind = keyof typeof THEME_BUILDER_LAYOUT_KIND_POST_TYPES;
|
|
7
|
+
export declare const THEME_BUILDER_LAYOUT_VALIDATOR_VERSION: "diviops.cross_env.theme_builder_layout.validator.v1";
|
|
8
|
+
export interface CrossEnvThemeBuilderLayoutPreflightInput {
|
|
9
|
+
source: SourceLayoutPayload;
|
|
10
|
+
target: TargetLayoutContext;
|
|
11
|
+
}
|
|
12
|
+
export interface CrossEnvThemeBuilderLayoutPreflightReport {
|
|
13
|
+
type: "cross_env_theme_builder_layout_preflight";
|
|
14
|
+
dry_run: true;
|
|
15
|
+
verdict: CrossEnvVerdict;
|
|
16
|
+
validator_contract: {
|
|
17
|
+
version: typeof THEME_BUILDER_LAYOUT_VALIDATOR_VERSION;
|
|
18
|
+
serialization: "wordpress_divi_full_content.v1";
|
|
19
|
+
};
|
|
20
|
+
source: {
|
|
21
|
+
origin: string;
|
|
22
|
+
object_kind: string;
|
|
23
|
+
object_id?: number | string;
|
|
24
|
+
object_title?: string;
|
|
25
|
+
object_post_type?: string;
|
|
26
|
+
checksum: {
|
|
27
|
+
algorithm: "sha256";
|
|
28
|
+
provided?: string;
|
|
29
|
+
computed: string;
|
|
30
|
+
matches: boolean | null;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
target: {
|
|
34
|
+
origin: string;
|
|
35
|
+
destination_kind: string;
|
|
36
|
+
destination_id?: number | string;
|
|
37
|
+
destination_title?: string;
|
|
38
|
+
destination_post_type?: string;
|
|
39
|
+
cache_scope?: string;
|
|
40
|
+
destination_checksum?: Sha256Checksum;
|
|
41
|
+
template_linkage?: unknown;
|
|
42
|
+
template_linkage_digest?: Sha256Checksum;
|
|
43
|
+
};
|
|
44
|
+
findings: {
|
|
45
|
+
urls: {
|
|
46
|
+
by_host: Record<string, string[]>;
|
|
47
|
+
occurrences: UrlOccurrence[];
|
|
48
|
+
};
|
|
49
|
+
attachments: AttachmentReference[];
|
|
50
|
+
global_colors: GcidReference[];
|
|
51
|
+
module_presets: ModulePresetReference[];
|
|
52
|
+
off_canvas: OffCanvasReference[];
|
|
53
|
+
};
|
|
54
|
+
source_origin_rule: {
|
|
55
|
+
normalized_origin: string;
|
|
56
|
+
rewrite_scope: "same_origin_wp_uploads_only";
|
|
57
|
+
};
|
|
58
|
+
rewrite_plan: {
|
|
59
|
+
url_rewrites: Array<{
|
|
60
|
+
from: string;
|
|
61
|
+
to: string;
|
|
62
|
+
}>;
|
|
63
|
+
attachment_replacements: Array<{
|
|
64
|
+
from_source_id: number;
|
|
65
|
+
to_target_id: number;
|
|
66
|
+
proof?: string;
|
|
67
|
+
}>;
|
|
68
|
+
third_party_urls_kept: string[];
|
|
69
|
+
missing_attachment_remaps: number[];
|
|
70
|
+
};
|
|
71
|
+
cache_plan: {
|
|
72
|
+
scope: string;
|
|
73
|
+
steps: Array<{
|
|
74
|
+
kind: string;
|
|
75
|
+
target: string;
|
|
76
|
+
note: string;
|
|
77
|
+
}>;
|
|
78
|
+
};
|
|
79
|
+
blockers: PreflightIssue[];
|
|
80
|
+
operator_actions: PreflightIssue[];
|
|
81
|
+
notes: string[];
|
|
82
|
+
confirmation_binding: {
|
|
83
|
+
schema: "diviops.cross_env.theme_builder_layout_preflight.confirmation_binding.v1";
|
|
84
|
+
algorithm: "sha256";
|
|
85
|
+
fingerprint: string;
|
|
86
|
+
input: Record<string, unknown>;
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
export declare function preflightCrossEnvThemeBuilderLayoutSync(input: CrossEnvThemeBuilderLayoutPreflightInput): CrossEnvThemeBuilderLayoutPreflightReport;
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { preflightCrossEnvHeaderSync, } from "./header-preflight.js";
|
|
3
|
+
export const THEME_BUILDER_LAYOUT_KIND_POST_TYPES = {
|
|
4
|
+
tb_header_layout: "et_header_layout",
|
|
5
|
+
tb_footer_layout: "et_footer_layout",
|
|
6
|
+
};
|
|
7
|
+
export const THEME_BUILDER_LAYOUT_VALIDATOR_VERSION = "diviops.cross_env.theme_builder_layout.validator.v1";
|
|
8
|
+
function sha256(value) {
|
|
9
|
+
return createHash("sha256").update(value).digest("hex");
|
|
10
|
+
}
|
|
11
|
+
function canonicalize(value) {
|
|
12
|
+
if (Array.isArray(value))
|
|
13
|
+
return value.map(canonicalize);
|
|
14
|
+
if (!value || typeof value !== "object")
|
|
15
|
+
return value;
|
|
16
|
+
return Object.fromEntries(Object.entries(value)
|
|
17
|
+
.filter(([, nested]) => nested !== undefined)
|
|
18
|
+
.sort(([a], [b]) => a.localeCompare(b))
|
|
19
|
+
.map(([key, nested]) => [key, canonicalize(nested)]));
|
|
20
|
+
}
|
|
21
|
+
function canonicalJson(value) {
|
|
22
|
+
return JSON.stringify(canonicalize(value));
|
|
23
|
+
}
|
|
24
|
+
function isSha256Digest(value) {
|
|
25
|
+
if (!value || typeof value !== "object")
|
|
26
|
+
return false;
|
|
27
|
+
const record = value;
|
|
28
|
+
return (record.algorithm === "sha256" &&
|
|
29
|
+
typeof record.computed === "string" &&
|
|
30
|
+
/^[a-f0-9]{64}$/i.test(record.computed));
|
|
31
|
+
}
|
|
32
|
+
function stableIssues(issues) {
|
|
33
|
+
return issues
|
|
34
|
+
.map((issue) => ({ code: issue.code, detail: issue.detail ?? null }))
|
|
35
|
+
.sort((a, b) => canonicalJson(a).localeCompare(canonicalJson(b)));
|
|
36
|
+
}
|
|
37
|
+
function expectedPostType(kind) {
|
|
38
|
+
return THEME_BUILDER_LAYOUT_KIND_POST_TYPES[kind];
|
|
39
|
+
}
|
|
40
|
+
function replaceCacheDestinationKind(target, kind) {
|
|
41
|
+
return target.replace(/^tb_header_layout(?=#|$)/, kind);
|
|
42
|
+
}
|
|
43
|
+
export function preflightCrossEnvThemeBuilderLayoutSync(input) {
|
|
44
|
+
// The shipped header-v1 engine remains the immutable compatibility analyzer.
|
|
45
|
+
// The generic contract reuses its hazard inventory while owning a distinct
|
|
46
|
+
// report and fingerprint namespace.
|
|
47
|
+
const base = preflightCrossEnvHeaderSync({
|
|
48
|
+
source: { ...input.source, object_kind: "tb_header_layout" },
|
|
49
|
+
target: { ...input.target, destination_kind: "tb_header_layout" },
|
|
50
|
+
});
|
|
51
|
+
const blockers = [...base.blockers];
|
|
52
|
+
const operatorActions = [...base.operator_actions];
|
|
53
|
+
const sourceKind = String(input.source.object_kind ?? "");
|
|
54
|
+
const targetKind = String(input.target.destination_kind ?? "");
|
|
55
|
+
const sourceExpectedType = expectedPostType(sourceKind);
|
|
56
|
+
const targetExpectedType = expectedPostType(targetKind);
|
|
57
|
+
if (!sourceExpectedType) {
|
|
58
|
+
blockers.push({
|
|
59
|
+
code: "unsupported_source_kind",
|
|
60
|
+
message: "Only tb_header_layout and tb_footer_layout sources are supported.",
|
|
61
|
+
detail: { received: sourceKind },
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
if (!targetExpectedType) {
|
|
65
|
+
blockers.push({
|
|
66
|
+
code: "unsupported_destination_kind",
|
|
67
|
+
message: "Only tb_header_layout and tb_footer_layout destinations are supported.",
|
|
68
|
+
detail: { received: targetKind },
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
if (sourceExpectedType && targetExpectedType && sourceKind !== targetKind) {
|
|
72
|
+
blockers.push({
|
|
73
|
+
code: "layout_kind_mismatch",
|
|
74
|
+
message: "Source and target Theme Builder layout kinds must match.",
|
|
75
|
+
detail: { source_kind: sourceKind, destination_kind: targetKind },
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
if (sourceExpectedType && input.source.object_post_type !== sourceExpectedType) {
|
|
79
|
+
blockers.push({
|
|
80
|
+
code: "source_post_type_mismatch",
|
|
81
|
+
message: "Source post type does not match its declared layout kind.",
|
|
82
|
+
detail: {
|
|
83
|
+
kind: sourceKind,
|
|
84
|
+
expected: sourceExpectedType,
|
|
85
|
+
actual: input.source.object_post_type ?? null,
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
if (targetExpectedType && input.target.destination_post_type !== targetExpectedType) {
|
|
90
|
+
blockers.push({
|
|
91
|
+
code: "destination_post_type_mismatch",
|
|
92
|
+
message: "Target post type does not match its declared layout kind.",
|
|
93
|
+
detail: {
|
|
94
|
+
kind: targetKind,
|
|
95
|
+
expected: targetExpectedType,
|
|
96
|
+
actual: input.target.destination_post_type ?? null,
|
|
97
|
+
},
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
if (!isSha256Digest(input.target.template_linkage_digest)) {
|
|
101
|
+
operatorActions.push({
|
|
102
|
+
code: "missing_template_linkage_digest",
|
|
103
|
+
message: "Provide the canonical target template-linkage digest before apply confirmation.",
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
const cachePlan = {
|
|
107
|
+
...base.cache_plan,
|
|
108
|
+
steps: base.cache_plan.steps.map((step) => ({
|
|
109
|
+
...step,
|
|
110
|
+
target: replaceCacheDestinationKind(step.target, targetKind),
|
|
111
|
+
})),
|
|
112
|
+
};
|
|
113
|
+
const sourceOriginRule = {
|
|
114
|
+
normalized_origin: base.source.origin,
|
|
115
|
+
rewrite_scope: "same_origin_wp_uploads_only",
|
|
116
|
+
};
|
|
117
|
+
const validatorContract = {
|
|
118
|
+
version: THEME_BUILDER_LAYOUT_VALIDATOR_VERSION,
|
|
119
|
+
serialization: "wordpress_divi_full_content.v1",
|
|
120
|
+
};
|
|
121
|
+
const verdict = blockers.length > 0
|
|
122
|
+
? "refused"
|
|
123
|
+
: operatorActions.length > 0
|
|
124
|
+
? "operator_action_required"
|
|
125
|
+
: "safe_dry_run";
|
|
126
|
+
const reportWithoutBinding = {
|
|
127
|
+
type: "cross_env_theme_builder_layout_preflight",
|
|
128
|
+
dry_run: true,
|
|
129
|
+
verdict,
|
|
130
|
+
validator_contract: validatorContract,
|
|
131
|
+
source: {
|
|
132
|
+
...base.source,
|
|
133
|
+
object_kind: sourceKind,
|
|
134
|
+
object_post_type: input.source.object_post_type,
|
|
135
|
+
},
|
|
136
|
+
target: {
|
|
137
|
+
...base.target,
|
|
138
|
+
destination_kind: targetKind,
|
|
139
|
+
destination_post_type: input.target.destination_post_type,
|
|
140
|
+
template_linkage: input.target.template_linkage,
|
|
141
|
+
template_linkage_digest: input.target.template_linkage_digest,
|
|
142
|
+
},
|
|
143
|
+
findings: base.findings,
|
|
144
|
+
source_origin_rule: sourceOriginRule,
|
|
145
|
+
rewrite_plan: base.rewrite_plan,
|
|
146
|
+
cache_plan: cachePlan,
|
|
147
|
+
blockers,
|
|
148
|
+
operator_actions: operatorActions,
|
|
149
|
+
notes: [
|
|
150
|
+
"Preflight only: Free/core evidence and CLI do not mutate WordPress.",
|
|
151
|
+
"The generic binding is distinct from the shipped header-v1 fingerprint.",
|
|
152
|
+
"Template linkage is drift evidence only and never authorizes assignment mutation.",
|
|
153
|
+
],
|
|
154
|
+
};
|
|
155
|
+
const bindingInput = {
|
|
156
|
+
source: {
|
|
157
|
+
origin: reportWithoutBinding.source.origin,
|
|
158
|
+
object_kind: sourceKind,
|
|
159
|
+
object_id: reportWithoutBinding.source.object_id,
|
|
160
|
+
object_post_type: input.source.object_post_type,
|
|
161
|
+
checksum: {
|
|
162
|
+
algorithm: "sha256",
|
|
163
|
+
computed: reportWithoutBinding.source.checksum.computed,
|
|
164
|
+
},
|
|
165
|
+
},
|
|
166
|
+
target: {
|
|
167
|
+
origin: reportWithoutBinding.target.origin,
|
|
168
|
+
destination_kind: targetKind,
|
|
169
|
+
destination_id: reportWithoutBinding.target.destination_id,
|
|
170
|
+
destination_post_type: input.target.destination_post_type,
|
|
171
|
+
destination_checksum: reportWithoutBinding.target.destination_checksum ?? null,
|
|
172
|
+
template_linkage_digest: input.target.template_linkage_digest ?? null,
|
|
173
|
+
cache_scope: reportWithoutBinding.target.cache_scope ?? null,
|
|
174
|
+
},
|
|
175
|
+
source_origin_rule: sourceOriginRule,
|
|
176
|
+
rewrite_plan: reportWithoutBinding.rewrite_plan,
|
|
177
|
+
cache_plan: cachePlan,
|
|
178
|
+
dependency_evidence: {
|
|
179
|
+
attachment_remap_proof: reportWithoutBinding.findings.attachments,
|
|
180
|
+
global_color_resolution: reportWithoutBinding.findings.global_colors,
|
|
181
|
+
module_preset_resolution: reportWithoutBinding.findings.module_presets,
|
|
182
|
+
off_canvas: {
|
|
183
|
+
refused: reportWithoutBinding.findings.off_canvas.length > 0,
|
|
184
|
+
refs: reportWithoutBinding.findings.off_canvas,
|
|
185
|
+
},
|
|
186
|
+
},
|
|
187
|
+
blockers: stableIssues(blockers),
|
|
188
|
+
operator_actions: stableIssues(operatorActions),
|
|
189
|
+
validator_contract: validatorContract,
|
|
190
|
+
};
|
|
191
|
+
const schema = "diviops.cross_env.theme_builder_layout_preflight.confirmation_binding.v1";
|
|
192
|
+
const canonicalInput = canonicalize(bindingInput);
|
|
193
|
+
return {
|
|
194
|
+
...reportWithoutBinding,
|
|
195
|
+
confirmation_binding: {
|
|
196
|
+
schema,
|
|
197
|
+
algorithm: "sha256",
|
|
198
|
+
fingerprint: sha256(canonicalJson({ schema, input: canonicalInput })),
|
|
199
|
+
input: canonicalInput,
|
|
200
|
+
},
|
|
201
|
+
};
|
|
202
|
+
}
|
|
@@ -17,4 +17,4 @@ export interface SourcePayloadRefEnvelope {
|
|
|
17
17
|
};
|
|
18
18
|
}
|
|
19
19
|
export declare function createSourcePayloadRef(payload: SourceLayoutPayload): SourcePayloadRef;
|
|
20
|
-
export declare function loadSourcePayloadRef(ref: unknown): SourceLayoutPayload;
|
|
20
|
+
export declare function loadSourcePayloadRef(ref: unknown, expectedKind?: string): SourceLayoutPayload;
|
|
@@ -106,7 +106,7 @@ export function createSourcePayloadRef(payload) {
|
|
|
106
106
|
...(expiresAt ? { expires_at: expiresAt } : {}),
|
|
107
107
|
};
|
|
108
108
|
}
|
|
109
|
-
export function loadSourcePayloadRef(ref) {
|
|
109
|
+
export function loadSourcePayloadRef(ref, expectedKind) {
|
|
110
110
|
if (!ref || typeof ref !== "object" || Array.isArray(ref)) {
|
|
111
111
|
throw new Error("source_payload_ref must be an object.");
|
|
112
112
|
}
|
|
@@ -174,5 +174,8 @@ export function loadSourcePayloadRef(ref) {
|
|
|
174
174
|
if (computed !== expected) {
|
|
175
175
|
throw new Error("source_payload_ref checksum does not match artifact markup.");
|
|
176
176
|
}
|
|
177
|
+
if (expectedKind !== undefined && payload.object_kind !== expectedKind) {
|
|
178
|
+
throw new Error(`source_payload_ref kind does not match destination kind (${String(payload.object_kind)} != ${expectedKind}).`);
|
|
179
|
+
}
|
|
177
180
|
return { ...payload, checksum: computed };
|
|
178
181
|
}
|