@adobe/design-data 3.0.9 → 3.1.0-beta.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.
- package/package.json +3 -2
- package/src/guideline.js +46 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adobe/design-data",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.1.0-beta.0",
|
|
4
4
|
"description": "Node.js helpers for @adobe/design-data-wasm: filesystem dataset loading, token write operations, and authoring-session management",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
"./load": "./src/load.js",
|
|
10
10
|
"./write": "./src/write.js",
|
|
11
11
|
"./session": "./src/session.js",
|
|
12
|
-
"./validate": "./src/validate.js"
|
|
12
|
+
"./validate": "./src/validate.js",
|
|
13
|
+
"./guideline": "./src/guideline.js"
|
|
13
14
|
},
|
|
14
15
|
"files": [
|
|
15
16
|
"src/",
|
package/src/guideline.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// Copyright 2026 Adobe. All rights reserved.
|
|
2
|
+
// This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License. You may obtain a copy
|
|
4
|
+
// of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
5
|
+
//
|
|
6
|
+
// Unless required by applicable law or agreed to in writing, software distributed under
|
|
7
|
+
// the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
8
|
+
// OF ANY KIND, either express or implied. See the License for the specific language
|
|
9
|
+
// governing permissions and limitations under the License.
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Shared guideline-document loader, used by both @adobe/design-data-mcp's
|
|
13
|
+
* `design-data-guideline` tool and @adobe/design-data-agent-mcp's
|
|
14
|
+
* `describe_guideline` tool, so the read-back logic (and its path-traversal
|
|
15
|
+
* guard) lives in exactly one place instead of being duplicated per server.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { readFileSync, existsSync } from "node:fs";
|
|
19
|
+
import { resolve, sep } from "node:path";
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Load a single guideline document (`<guidelinesDir>/<id>.json`) by slug id.
|
|
23
|
+
*
|
|
24
|
+
* Path safety: the resolved absolute path is asserted to stay within
|
|
25
|
+
* `guidelinesDir` so a crafted `id` (e.g. `../../etc/passwd`) cannot read
|
|
26
|
+
* files outside the intended data directory.
|
|
27
|
+
*
|
|
28
|
+
* @param {string} guidelinesDir - absolute path to the guidelines directory,
|
|
29
|
+
* e.g. `<spectrum-design-data package root>/guidelines`.
|
|
30
|
+
* @param {string} id - kebab-case slug, e.g. "colors" or "motion".
|
|
31
|
+
* @returns {object} the parsed guideline JSON document.
|
|
32
|
+
*/
|
|
33
|
+
export function loadGuideline(guidelinesDir, id) {
|
|
34
|
+
if (id === "manifest") {
|
|
35
|
+
throw new Error(`Not found: "${id}" in guidelines/.`);
|
|
36
|
+
}
|
|
37
|
+
const baseDir = resolve(guidelinesDir);
|
|
38
|
+
const filePath = resolve(baseDir, `${id}.json`);
|
|
39
|
+
if (!filePath.startsWith(baseDir + sep)) {
|
|
40
|
+
throw new Error(`Invalid guideline id: "${id}"`);
|
|
41
|
+
}
|
|
42
|
+
if (!existsSync(filePath)) {
|
|
43
|
+
throw new Error(`Not found: "${id}" in guidelines/.`);
|
|
44
|
+
}
|
|
45
|
+
return JSON.parse(readFileSync(filePath, "utf-8"));
|
|
46
|
+
}
|