@kubuild/core 0.0.1
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/dist/binding-resolver.d.ts +16 -0
- package/dist/binding-resolver.d.ts.map +1 -0
- package/dist/command-tree-utils.d.ts +60 -0
- package/dist/command-tree-utils.d.ts.map +1 -0
- package/dist/commands.d.ts +99 -0
- package/dist/commands.d.ts.map +1 -0
- package/dist/document-utils.d.ts +51 -0
- package/dist/document-utils.d.ts.map +1 -0
- package/dist/exporter.d.ts +89 -0
- package/dist/exporter.d.ts.map +1 -0
- package/dist/history.d.ts +107 -0
- package/dist/history.d.ts.map +1 -0
- package/dist/importer.d.ts +243 -0
- package/dist/importer.d.ts.map +1 -0
- package/dist/index.cjs +3686 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3614 -0
- package/dist/index.js.map +1 -0
- package/dist/interfaces.d.ts +71 -0
- package/dist/interfaces.d.ts.map +1 -0
- package/dist/migration.d.ts +86 -0
- package/dist/migration.d.ts.map +1 -0
- package/dist/round-trip-comparator.d.ts +38 -0
- package/dist/round-trip-comparator.d.ts.map +1 -0
- package/dist/security.d.ts +99 -0
- package/dist/security.d.ts.map +1 -0
- package/dist/template-utils.d.ts +124 -0
- package/dist/template-utils.d.ts.map +1 -0
- package/dist/validator.d.ts +43 -0
- package/dist/validator.d.ts.map +1 -0
- package/dist/variable-catalog.d.ts +9 -0
- package/dist/variable-catalog.d.ts.map +1 -0
- package/package.json +58 -0
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { PageDocument } from '@kubuild/schema';
|
|
2
|
+
export interface AssetInfo {
|
|
3
|
+
id: string;
|
|
4
|
+
url: string;
|
|
5
|
+
mimeType: string;
|
|
6
|
+
size?: number;
|
|
7
|
+
alt?: string;
|
|
8
|
+
}
|
|
9
|
+
export interface AssetProvider {
|
|
10
|
+
resolve(assetIdOrUri: string): Promise<string> | string;
|
|
11
|
+
upload?(file: File | Blob, metadata?: Record<string, unknown>): Promise<AssetInfo>;
|
|
12
|
+
delete?(assetId: string): Promise<boolean>;
|
|
13
|
+
list?(): Promise<AssetInfo[]>;
|
|
14
|
+
}
|
|
15
|
+
export interface ActionExecutionContext {
|
|
16
|
+
nodeId?: string;
|
|
17
|
+
document: PageDocument;
|
|
18
|
+
variables?: Record<string, unknown>;
|
|
19
|
+
[key: string]: unknown;
|
|
20
|
+
}
|
|
21
|
+
export type ActionHandler = (payload: Record<string, unknown> | undefined, context: ActionExecutionContext) => Promise<void> | void;
|
|
22
|
+
export interface ActionRegistry {
|
|
23
|
+
get(actionType: string): ActionHandler | undefined;
|
|
24
|
+
register(actionType: string, handler: ActionHandler): void;
|
|
25
|
+
unregister(actionType: string): void;
|
|
26
|
+
}
|
|
27
|
+
export interface ActionDiagnostic {
|
|
28
|
+
code: 'UNKNOWN_ACTION' | 'ACTION_EXECUTION_ERROR' | 'INVALID_ACTION_PAYLOAD' | 'INVALID_ACTION_BINDING';
|
|
29
|
+
actionType: string;
|
|
30
|
+
nodeId?: string;
|
|
31
|
+
message: string;
|
|
32
|
+
error?: unknown;
|
|
33
|
+
invalidPaths?: string[];
|
|
34
|
+
}
|
|
35
|
+
export interface PropBindingDiagnostic {
|
|
36
|
+
code: 'INCOMPATIBLE_BINDING_TYPE';
|
|
37
|
+
nodeId?: string;
|
|
38
|
+
propName: string;
|
|
39
|
+
expectedType: string;
|
|
40
|
+
actualType: string;
|
|
41
|
+
message: string;
|
|
42
|
+
}
|
|
43
|
+
export interface CollectionDiagnostic {
|
|
44
|
+
code: 'INVALID_COLLECTION_SOURCE';
|
|
45
|
+
nodeId?: string;
|
|
46
|
+
propName: string;
|
|
47
|
+
message: string;
|
|
48
|
+
}
|
|
49
|
+
export type Diagnostic = ActionDiagnostic | PropBindingDiagnostic | CollectionDiagnostic;
|
|
50
|
+
export type RenderContext = Readonly<{
|
|
51
|
+
variables?: Readonly<Record<string, unknown>>;
|
|
52
|
+
assetProvider?: AssetProvider;
|
|
53
|
+
actionRegistry?: ActionRegistry;
|
|
54
|
+
onDiagnostic?: (diagnostic: Diagnostic) => void;
|
|
55
|
+
}>;
|
|
56
|
+
export type RuntimeContext = RenderContext;
|
|
57
|
+
export type VariableValueType = 'string' | 'number' | 'boolean' | 'array' | 'object';
|
|
58
|
+
/**
|
|
59
|
+
* Host-declared catalog entry describing a bindable variable and an editor/preview-only
|
|
60
|
+
* sample value. `sampleValue` must never be written into a `PageDocument` — it exists so
|
|
61
|
+
* the builder can preview bindings without persisting host data into the portable document.
|
|
62
|
+
*/
|
|
63
|
+
export interface VariableDefinition {
|
|
64
|
+
key: string;
|
|
65
|
+
label: string;
|
|
66
|
+
type: VariableValueType;
|
|
67
|
+
sampleValue: unknown;
|
|
68
|
+
description?: string;
|
|
69
|
+
}
|
|
70
|
+
export type VariableCatalog = VariableDefinition[];
|
|
71
|
+
//# sourceMappingURL=interfaces.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,MAAM,WAAW,SAAS;IACxB,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,aAAa;IAC5B,OAAO,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC;IACxD,MAAM,CAAC,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,EAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;IACnF,MAAM,CAAC,CAA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AAM,CAAC;CACjB;AAED,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,2BAA2B,CAAC;IAClC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,MAAM,UAAU,GAAG,gBAAgB,GAAG,qBAAqB,GAAG,oBAAoB,CAAC;AAEzF,MAAM,MAAM,aAAa,GAAG,QAAQ,CAAC;IACnC,SAAS,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IAC9C,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B,cAAc,CAAC,EAAE,cAAc,CAAC;IAChC,YAAY,CAAC,EAAE,CAAC,UAAU,EAAE,UAAU,KAAK,IAAI,CAAC;CACjD,CAAC,CAAC;AAEH,MAAM,MAAM,cAAc,GAAG,aAAa,CAAC;AAE3C,MAAM,MAAM,iBAAiB,GAAG,QAAQ,GAAG,QAAQ,GAAG,SAAS,GAAG,OAAO,GAAG,QAAQ,CAAC;AAErF;;;;GAIG;AACH,MAAM,WAAW,kBAAkB;IACjC,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,iBAAiB,CAAC;IACxB,WAAW,EAAE,OAAO,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,MAAM,eAAe,GAAG,kBAAkB,EAAE,CAAC"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { PageDocument } from '@kubuild/schema';
|
|
2
|
+
export type MigrationErrorCode = 'NO_MIGRATION_PATH' | 'UNSUPPORTED_SCHEMA_VERSION' | 'INVALID_SOURCE_DOCUMENT' | 'MIGRATION_EXECUTION_FAILED';
|
|
3
|
+
export interface MigrationError {
|
|
4
|
+
code: MigrationErrorCode;
|
|
5
|
+
message: string;
|
|
6
|
+
sourceVersion: string;
|
|
7
|
+
targetVersion: string;
|
|
8
|
+
details?: Record<string, unknown>;
|
|
9
|
+
}
|
|
10
|
+
export interface MigrationDiagnostic {
|
|
11
|
+
success: boolean;
|
|
12
|
+
sourceVersion: string;
|
|
13
|
+
targetVersion: string;
|
|
14
|
+
migrationPath: string[];
|
|
15
|
+
stepsApplied: number;
|
|
16
|
+
dryRun: boolean;
|
|
17
|
+
errors?: MigrationError[];
|
|
18
|
+
}
|
|
19
|
+
export interface MigrationResult {
|
|
20
|
+
success: boolean;
|
|
21
|
+
document?: PageDocument;
|
|
22
|
+
diagnostic: MigrationDiagnostic;
|
|
23
|
+
}
|
|
24
|
+
export interface MigrateOptions {
|
|
25
|
+
/**
|
|
26
|
+
* Target schema version (defaults to CURRENT_SCHEMA_VERSION = "1.0.0").
|
|
27
|
+
*/
|
|
28
|
+
targetVersion?: string;
|
|
29
|
+
/**
|
|
30
|
+
* If true, validates path and simulates migration without modifying production data.
|
|
31
|
+
*/
|
|
32
|
+
dryRun?: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Custom migration registry (defaults to defaultMigrationRegistry).
|
|
35
|
+
*/
|
|
36
|
+
registry?: MigrationRegistry;
|
|
37
|
+
/**
|
|
38
|
+
* Validate document with schema validator after migration (default: true).
|
|
39
|
+
*/
|
|
40
|
+
validate?: boolean;
|
|
41
|
+
}
|
|
42
|
+
export type MigrationFunction = (rawDoc: Record<string, unknown>) => Record<string, unknown>;
|
|
43
|
+
export interface MigrationStep {
|
|
44
|
+
fromVersion: string;
|
|
45
|
+
toVersion: string;
|
|
46
|
+
migrate: MigrationFunction;
|
|
47
|
+
description?: string;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Migration Registry to manage version transition steps.
|
|
51
|
+
*/
|
|
52
|
+
export declare class MigrationRegistry {
|
|
53
|
+
private steps;
|
|
54
|
+
/**
|
|
55
|
+
* Register a migration step from one version to another.
|
|
56
|
+
*/
|
|
57
|
+
register(step: MigrationStep): void;
|
|
58
|
+
private getKey;
|
|
59
|
+
/**
|
|
60
|
+
* Find shortest path of versions to migrate from source to target using BFS.
|
|
61
|
+
*/
|
|
62
|
+
findPath(sourceVersion: string, targetVersion: string): string[] | null;
|
|
63
|
+
/**
|
|
64
|
+
* Check if a valid migration path exists between source and target versions.
|
|
65
|
+
*/
|
|
66
|
+
hasPath(sourceVersion: string, targetVersion: string): boolean;
|
|
67
|
+
/**
|
|
68
|
+
* Get the migration step handler for a direct version step.
|
|
69
|
+
*/
|
|
70
|
+
getStep(fromVersion: string, toVersion: string): MigrationStep | undefined;
|
|
71
|
+
}
|
|
72
|
+
export declare const defaultMigrationRegistry: MigrationRegistry;
|
|
73
|
+
/**
|
|
74
|
+
* Check whether a migration path exists between source and target versions.
|
|
75
|
+
*/
|
|
76
|
+
export declare function canMigrate(sourceVersion: string, targetVersion?: string, registry?: MigrationRegistry): boolean;
|
|
77
|
+
/**
|
|
78
|
+
* Get the sequence of versions forming the migration path.
|
|
79
|
+
*/
|
|
80
|
+
export declare function getMigrationPath(sourceVersion: string, targetVersion?: string, registry?: MigrationRegistry): string[] | null;
|
|
81
|
+
/**
|
|
82
|
+
* Migrate a page document from an older schema version to current (or specified) schema version.
|
|
83
|
+
* Supports dry-run execution, step diagnostics, and structured error reporting.
|
|
84
|
+
*/
|
|
85
|
+
export declare function migrateDocument(rawDocument: unknown, options?: MigrateOptions): MigrationResult;
|
|
86
|
+
//# sourceMappingURL=migration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migration.d.ts","sourceRoot":"","sources":["../src/migration.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EAKb,MAAM,iBAAiB,CAAC;AAIzB,MAAM,MAAM,kBAAkB,GAC1B,mBAAmB,GACnB,4BAA4B,GAC5B,yBAAyB,GACzB,4BAA4B,CAAC;AAEjC,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,kBAAkB,CAAC;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,E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AM,EAAE,aAAa,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,IAAI;IA+BvE;;OAEG;IACH,OAAO,CAAC,aAAa,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,OAAO;IAI9D;;OAEG;IACH,OAAO,CAAC,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,aAAa,GAAG,SAAS;CAG3E;AA0BD,eAAO,MAAM,wBAAwB,mBAA0B,CAAC;AAqGhE;;GAEG;AACH,wBAAgB,UAAU,CACxB,aAAa,EAAE,MAAM,EACrB,aAAa,GAAE,MAA+B,EAC9C,QAAQ,GAAE,iBAA4C,GACrD,OAAO,CAIT;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAC9B,aAAa,EAAE,MAAM,EACrB,aAAa,GAAE,MAA+B,EAC9C,QAAQ,GAAE,iBAA4C,GACrD,MAAM,EAAE,GAAG,IAAI,CAGjB;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAC7B,WAAW,EAAE,OAAO,EACpB,OAAO,GAAE,cAAmB,GAC3B,eAAe,CA0MjB"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { PageDocument, Manifest } from '@kubuild/schema';
|
|
2
|
+
export type SemanticDifferenceKind = 'METADATA_MISMATCH' | 'NODE_MISSING' | 'NODE_EXTRA' | 'NODE_ORDER' | 'NODE_TYPE' | 'PROP_MISMATCH' | 'STYLE_MISMATCH' | 'BINDING_MISMATCH' | 'ACTION_MISMATCH' | 'ASSET_MISMATCH' | 'DEPENDENCY_MISMATCH';
|
|
3
|
+
export interface SemanticDifference {
|
|
4
|
+
path: string;
|
|
5
|
+
kind: SemanticDifferenceKind;
|
|
6
|
+
message: string;
|
|
7
|
+
expected?: unknown;
|
|
8
|
+
actual?: unknown;
|
|
9
|
+
}
|
|
10
|
+
export interface SemanticCompareOptions {
|
|
11
|
+
/**
|
|
12
|
+
* Optional map of original asset IDs to host-remapped asset IDs.
|
|
13
|
+
* Used when host renamed colliding assets during import.
|
|
14
|
+
*/
|
|
15
|
+
assetIdMap?: Record<string, string> | Map<string, string>;
|
|
16
|
+
/**
|
|
17
|
+
* Whether to ignore transient timestamp fields (e.g. createdAt/updatedAt).
|
|
18
|
+
* Default: true.
|
|
19
|
+
*/
|
|
20
|
+
ignoreTimestamps?: boolean;
|
|
21
|
+
}
|
|
22
|
+
export interface SemanticComparisonResult {
|
|
23
|
+
equivalent: boolean;
|
|
24
|
+
differences: SemanticDifference[];
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Semantically compares two PageDocuments, checking metadata, tree structure,
|
|
28
|
+
* node order, props, responsive styles, bindings, action references, and asset mappings.
|
|
29
|
+
*
|
|
30
|
+
* Only documented transient fields (e.g. transient timestamps, host-generated asset IDs)
|
|
31
|
+
* are ignored or normalized per options.
|
|
32
|
+
*/
|
|
33
|
+
export declare function compareDocumentsSemantically(expected: PageDocument, actual: PageDocument, options?: SemanticCompareOptions): SemanticComparisonResult;
|
|
34
|
+
/**
|
|
35
|
+
* Semantically compares exported and imported package manifests.
|
|
36
|
+
*/
|
|
37
|
+
export declare function compareManifestsSemantically(expected: Manifest, actual: Manifest, options?: SemanticCompareOptions): SemanticComparisonResult;
|
|
38
|
+
//# sourceMappingURL=round-trip-comparator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"round-trip-comparator.d.ts","sourceRoot":"","sources":["../src/round-trip-comparator.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EAIZ,QAAQ,EAIT,MAAM,iBAAiB,CAAC;AAEzB,MAAM,MAAM,sBAAsB,GAC9B,mBAAmB,GACnB,cAAc,GACd,YAAY,GACZ,YAAY,GACZ,WAAW,GACX,eAAe,GACf,gBAAgB,GAChB,kBAAkB,GAClB,iBAAiB,GACjB,gBAAgB,GAChB,qBAAqB,CAAC;AAE1B,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,sBAAsB,CAAC;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,sBAAsB;IACrC;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAE1D;;;OAGG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED,MAAM,WAAW,wBAAwB;IACvC,UAAU,EAAE,OAAO,CAAC;IACpB,WAAW,EAAE,kBAAkB,EAAE,CAAC;CACnC;AAiYD;;;;;;GAMG;AACH,wBAAgB,4BAA4B,CAC1C,QAAQ,EAAE,YAAY,EACtB,MAAM,EAAE,YAAY,EACpB,OAAO,GAAE,sBAA2B,GACnC,wBAAwB,CA2D1B;AAED;;GAEG;AACH,wBAAgB,4BAA4B,CAC1C,QAAQ,EAAE,QAAQ,EAClB,MAAM,EAAE,QAAQ,EAChB,OAAO,GAAE,sBAA2B,GACnC,wBAAwB,CAuF1B"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Security Limits and Sanitization Utilities for KUBUILD documents, assets, and actions.
|
|
3
|
+
*/
|
|
4
|
+
export interface DocumentSecurityLimits {
|
|
5
|
+
/**
|
|
6
|
+
* Maximum allowed total nodes in the document tree (default: 5000).
|
|
7
|
+
*/
|
|
8
|
+
maxNodeCount?: number;
|
|
9
|
+
/**
|
|
10
|
+
* Maximum allowed nesting depth of nodes (default: 32).
|
|
11
|
+
*/
|
|
12
|
+
maxTreeDepth?: number;
|
|
13
|
+
/**
|
|
14
|
+
* Maximum number of direct properties per node (default: 200).
|
|
15
|
+
*/
|
|
16
|
+
maxPropsCount?: number;
|
|
17
|
+
/**
|
|
18
|
+
* Maximum character length for any individual string property (default: 100,000).
|
|
19
|
+
*/
|
|
20
|
+
maxStringLength?: number;
|
|
21
|
+
/**
|
|
22
|
+
* Maximum number of direct children per node (default: 1000).
|
|
23
|
+
*/
|
|
24
|
+
maxChildrenPerNode?: number;
|
|
25
|
+
/**
|
|
26
|
+
* Maximum allowed JSON serialized size in bytes (default: 10MB).
|
|
27
|
+
*/
|
|
28
|
+
maxDocumentSizeBytes?: number;
|
|
29
|
+
/**
|
|
30
|
+
* Allowed URL schemes for links and media.
|
|
31
|
+
* Default: ['http:', 'https:', 'mailto:', 'tel:', '#', 'relative', 'data:image/']
|
|
32
|
+
*/
|
|
33
|
+
allowedUrlSchemes?: string[];
|
|
34
|
+
/**
|
|
35
|
+
* Prohibited property keys to defend against Prototype Pollution.
|
|
36
|
+
* Default: ['__proto__', 'constructor', 'prototype', '__defineGetter__', '__defineSetter__', '__lookupGetter__', '__lookupSetter__']
|
|
37
|
+
*/
|
|
38
|
+
prohibitedPropertyKeys?: string[];
|
|
39
|
+
/**
|
|
40
|
+
* Prohibited asset file extensions to prevent executable uploads.
|
|
41
|
+
* Default: ['.exe', '.dll', '.so', '.sh', '.bat', '.cmd', '.js', '.mjs', '.cjs', '.php', '.py', '.vbs', '.wasm', '.bin', '.com', '.scr', '.pif']
|
|
42
|
+
*/
|
|
43
|
+
prohibitedAssetExtensions?: string[];
|
|
44
|
+
/**
|
|
45
|
+
* Maximum compression expansion ratio before flagging potential zip bomb (default: 100).
|
|
46
|
+
*/
|
|
47
|
+
maxZipExpansionRatio?: number;
|
|
48
|
+
}
|
|
49
|
+
export declare const DEFAULT_DOCUMENT_SECURITY_LIMITS: Required<DocumentSecurityLimits>;
|
|
50
|
+
export interface SecurityViolation {
|
|
51
|
+
code: 'PROTOTYPE_POLLUTION_DETECTED' | 'MAX_NODE_COUNT_EXCEEDED' | 'MAX_TREE_DEPTH_EXCEEDED' | 'MAX_PROPS_COUNT_EXCEEDED' | 'MAX_STRING_LENGTH_EXCEEDED' | 'MAX_CHILDREN_COUNT_EXCEEDED' | 'MAX_DOCUMENT_SIZE_EXCEEDED' | 'UNSAFE_URL_DETECTED' | 'EXECUTABLE_ASSET_DETECTED' | 'ZIP_BOMB_DETECTED';
|
|
52
|
+
message: string;
|
|
53
|
+
path?: string;
|
|
54
|
+
details?: Record<string, unknown>;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Checks whether a URL is safe according to the allowed URL schemes.
|
|
58
|
+
* Rejects dangerous schemes such as javascript:, vbscript:, data:text/html, etc.
|
|
59
|
+
*/
|
|
60
|
+
export declare function isSafeUrl(url: unknown, options?: {
|
|
61
|
+
allowedSchemes?: string[];
|
|
62
|
+
allowDataImage?: boolean;
|
|
63
|
+
/** Allow `blob:` URLs (runtime-only, e.g. in-memory uploaded media previews). */
|
|
64
|
+
allowBlobMedia?: boolean;
|
|
65
|
+
}): boolean;
|
|
66
|
+
/**
|
|
67
|
+
* Sanitizes a URL, returning a safe URL or a fallback (default empty string or '#').
|
|
68
|
+
*/
|
|
69
|
+
export declare function sanitizeUrl(url: unknown, fallback?: string, options?: Parameters<typeof isSafeUrl>[1]): string;
|
|
70
|
+
/**
|
|
71
|
+
* Checks an object recursively for prohibited prototype pollution keys.
|
|
72
|
+
*/
|
|
73
|
+
export declare function containsProhibitedKeys(obj: unknown, prohibitedKeys?: string[]): {
|
|
74
|
+
found: boolean;
|
|
75
|
+
path: string;
|
|
76
|
+
key: string;
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* Validates a document against security limits (node count, tree depth, props count, string length, prototype pollution).
|
|
80
|
+
*/
|
|
81
|
+
export declare function validateDocumentSecurity(doc: unknown, customLimits?: DocumentSecurityLimits): {
|
|
82
|
+
safe: boolean;
|
|
83
|
+
errors: SecurityViolation[];
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* Checks if an asset filename has a dangerous or executable extension.
|
|
87
|
+
*/
|
|
88
|
+
export declare function isDangerousAssetFilename(filename: string, prohibitedExtensions?: string[]): boolean;
|
|
89
|
+
/**
|
|
90
|
+
* Checks whether an archive expansion ratio indicates a zip bomb attack.
|
|
91
|
+
*/
|
|
92
|
+
export declare function checkZipBomb(compressedSize: number, uncompressedSize: number, maxRatio?: number): boolean;
|
|
93
|
+
/**
|
|
94
|
+
* Sanitizes an HTML string by stripping unsafe tags (<script>, <object>, <embed>, <applet>, <base>, <link rel="import">),
|
|
95
|
+
* removing inline event handlers (on* attributes like onclick, onerror, onload, etc.),
|
|
96
|
+
* and disarming javascript:/vbscript:/data:text/html URLs in attributes.
|
|
97
|
+
*/
|
|
98
|
+
export declare function sanitizeHtml(rawHtml: unknown): string;
|
|
99
|
+
//# sourceMappingURL=security.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"security.d.ts","sourceRoot":"","sources":["../src/security.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,WAAW,sBAAsB;IACrC;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB;;OAEG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IAEvB;;OAEG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IAEzB;;OAEG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAE5B;;OAEG;IACH,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAE9B;;;OAGG;IACH,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC;IAE7B;;;OAGG;IACH,sBAAsB,CAAC,EAAE,MAAM,EAAE,CAAC;IAElC;;;OAGG;IACH,yBAAyB,CAAC,EAAE,MAAM,EAAE,CAAC;IAErC;;OAEG;IACH,oBAAoB,CAAC,EAAE,MAAM,CAAC;CAC/B;AAED,eAAO,MAAM,gCAAgC,EAAE,QAAQ,CAAC,sBAAsB,CAuC7E,CAAC;AAEF,MAAM,WAAW,iBAAiB;IAChC,IAAI,EACA,8BAA8B,GAC9B,yBAAyB,GACzB,yBAAyB,GACzB,0BAA0B,GAC1B,4B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ACvE,OAAO,CAQT;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,CAwBrD"}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { type TemplateRecord, type TemplateRequirements, type PageDocument, type Node } from '@kubuild/schema';
|
|
2
|
+
/**
|
|
3
|
+
* Standard core built-in component types
|
|
4
|
+
*/
|
|
5
|
+
export declare const CORE_BUILTIN_COMPONENTS: Set<string>;
|
|
6
|
+
/**
|
|
7
|
+
* Structured validation error entry
|
|
8
|
+
*/
|
|
9
|
+
export interface TemplateValidationError {
|
|
10
|
+
code: string;
|
|
11
|
+
message: string;
|
|
12
|
+
path: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Result of template record validation
|
|
16
|
+
*/
|
|
17
|
+
export interface TemplateValidationResult {
|
|
18
|
+
valid: boolean;
|
|
19
|
+
data?: TemplateRecord;
|
|
20
|
+
errors?: TemplateValidationError[];
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Validates a template record value against TemplateRecordSchema and returns structured errors.
|
|
24
|
+
*/
|
|
25
|
+
export declare function validateTemplate(value: unknown): TemplateValidationResult;
|
|
26
|
+
/**
|
|
27
|
+
* Extracts required components and capabilities from a PageDocument.
|
|
28
|
+
* Detects any custom/non-core component types used in the document tree.
|
|
29
|
+
*/
|
|
30
|
+
export declare function extractTemplateRequirements(doc: PageDocument, builtinComponents?: Set<string>): TemplateRequirements;
|
|
31
|
+
/**
|
|
32
|
+
* Parameters for creating a TemplateRecord
|
|
33
|
+
*/
|
|
34
|
+
export interface CreateTemplateParams {
|
|
35
|
+
id: string;
|
|
36
|
+
name: string;
|
|
37
|
+
description?: string;
|
|
38
|
+
category?: string;
|
|
39
|
+
tags?: string[];
|
|
40
|
+
thumbnail?: TemplateRecord['thumbnail'];
|
|
41
|
+
author?: string;
|
|
42
|
+
version?: string;
|
|
43
|
+
document?: PageDocument;
|
|
44
|
+
packageReference?: TemplateRecord['packageReference'];
|
|
45
|
+
requirements?: TemplateRequirements;
|
|
46
|
+
createdAt?: string;
|
|
47
|
+
updatedAt?: string;
|
|
48
|
+
custom?: Record<string, unknown>;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Creates and validates a TemplateRecord.
|
|
52
|
+
* Automatically extracts requirements from the embedded document if requirements are not explicitly supplied.
|
|
53
|
+
*/
|
|
54
|
+
export declare function createTemplateRecord(params: CreateTemplateParams): TemplateRecord;
|
|
55
|
+
/**
|
|
56
|
+
* Required metadata parameters for saving a draft as a template.
|
|
57
|
+
* id and name are strictly required and non-empty.
|
|
58
|
+
*/
|
|
59
|
+
export interface SaveTemplateMetadata {
|
|
60
|
+
id: string;
|
|
61
|
+
name: string;
|
|
62
|
+
description?: string;
|
|
63
|
+
category?: string;
|
|
64
|
+
tags?: string[];
|
|
65
|
+
thumbnail?: TemplateRecord['thumbnail'];
|
|
66
|
+
author?: string;
|
|
67
|
+
version?: string;
|
|
68
|
+
custom?: Record<string, unknown>;
|
|
69
|
+
}
|
|
70
|
+
export interface SaveDraftAsTemplateOptions {
|
|
71
|
+
validateDraft?: boolean;
|
|
72
|
+
requirements?: TemplateRequirements;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Exports a draft document snapshot as an immutable reusable TemplateRecord.
|
|
76
|
+
* - Requires mandatory metadata (id, name).
|
|
77
|
+
* - Validates draft document structure.
|
|
78
|
+
* - Extracts component/capability requirements.
|
|
79
|
+
* - Creates a deep-cloned immutable snapshot completely decoupled from the active draft.
|
|
80
|
+
*/
|
|
81
|
+
export declare function saveDraftAsTemplate(draft: PageDocument, metadata: SaveTemplateMetadata, options?: SaveDraftAsTemplateOptions): TemplateRecord;
|
|
82
|
+
/**
|
|
83
|
+
* Options for cloning/instantiating a template into a new page document.
|
|
84
|
+
*/
|
|
85
|
+
export interface CloneTemplateOptions {
|
|
86
|
+
/**
|
|
87
|
+
* Title for the newly created page document. Defaults to template name or document title.
|
|
88
|
+
*/
|
|
89
|
+
title?: string;
|
|
90
|
+
/**
|
|
91
|
+
* Author for the newly created page document.
|
|
92
|
+
*/
|
|
93
|
+
author?: string;
|
|
94
|
+
/**
|
|
95
|
+
* Optional custom ID generator function for node duplication.
|
|
96
|
+
*/
|
|
97
|
+
idGenerator?: (oldId: string, node: Node) => string;
|
|
98
|
+
/**
|
|
99
|
+
* Custom ID prefix for freshly generated node IDs. Defaults to random string / timestamp.
|
|
100
|
+
*/
|
|
101
|
+
idPrefix?: string;
|
|
102
|
+
/**
|
|
103
|
+
* Whether to record origin template metadata in metadata.custom.originTemplate (defaults to true).
|
|
104
|
+
*/
|
|
105
|
+
recordOrigin?: boolean;
|
|
106
|
+
/**
|
|
107
|
+
* Additional custom metadata for the new document.
|
|
108
|
+
*/
|
|
109
|
+
customMetadata?: Record<string, unknown>;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Clones a template (or existing document) into a brand new PageDocument.
|
|
113
|
+
* - Generates ALL NEW node IDs across the entire tree (root page node and all children).
|
|
114
|
+
* - Ensures 100% ID difference from the source template.
|
|
115
|
+
* - Sets fresh creation/update timestamps.
|
|
116
|
+
* - Preserves origin template version/id in custom metadata.
|
|
117
|
+
* - Guarantees full memory and reference isolation from the template source.
|
|
118
|
+
*/
|
|
119
|
+
export declare function cloneTemplateAsPage(templateOrDoc: TemplateRecord | PageDocument, options?: CloneTemplateOptions): PageDocument;
|
|
120
|
+
/**
|
|
121
|
+
* Helper to verify that two PageDocuments share ZERO overlapping node IDs.
|
|
122
|
+
*/
|
|
123
|
+
export declare function areNodeIdsCompletelyDistinct(docA: PageDocument, docB: PageDocument): boolean;
|
|
124
|
+
//# sourceMappingURL=template-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"template-utils.d.ts","sourceRoot":"","sources":["../src/template-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,cAAc,EACnB,KAAK,oBAAoB,EACzB,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,GAAE,oBAAyB,GACjC,YAAY,CAmFd;AAED;;GAEG;AACH,wBAAgB,4BAA4B,CAAC,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,YAAY,GAAG,OAAO,CAW5F"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { PageDocument } from '@kubuild/schema';
|
|
2
|
+
import { DocumentSecurityLimits } from './security';
|
|
3
|
+
export type DocumentValidationErrorCode = 'GLOBAL_SCHEMA_INVALID' | 'ROOT_NODE_INVALID' | 'NODE_SHAPE_INVALID' | 'DUPLICATE_NODE_ID' | 'TREE_CYCLE_DETECTED' | 'UNKNOWN_COMPONENT_TYPE' | 'CHILD_POLICY_VIOLATION' | 'INVALID_ASSET_REFERENCE' | 'INVALID_VARIABLE_BINDING' | 'INVALID_ACTION_BINDING' | 'INVALID_METADATA' | 'PROTOTYPE_POLLUTION_DETECTED' | 'SECURITY_LIMIT_EXCEEDED';
|
|
4
|
+
export interface DocumentValidationError {
|
|
5
|
+
code: DocumentValidationErrorCode;
|
|
6
|
+
message: string;
|
|
7
|
+
path: string;
|
|
8
|
+
nodeId?: string;
|
|
9
|
+
details?: Record<string, unknown>;
|
|
10
|
+
}
|
|
11
|
+
export interface ComponentDefinitionLike {
|
|
12
|
+
type: string;
|
|
13
|
+
category?: string;
|
|
14
|
+
capabilities?: string[];
|
|
15
|
+
acceptsChildren?: boolean;
|
|
16
|
+
allowedChildren?: string[];
|
|
17
|
+
disallowedParents?: string[];
|
|
18
|
+
}
|
|
19
|
+
export interface ComponentRegistryLike {
|
|
20
|
+
get(type: string): ComponentDefinitionLike | undefined;
|
|
21
|
+
has(type: string): boolean;
|
|
22
|
+
}
|
|
23
|
+
export interface ValidationOptions {
|
|
24
|
+
componentRegistry?: ComponentRegistryLike;
|
|
25
|
+
knownComponentTypes?: string[] | Set<string>;
|
|
26
|
+
strictComponentTypes?: boolean;
|
|
27
|
+
checkAssetReferences?: boolean;
|
|
28
|
+
checkVariableBindings?: boolean;
|
|
29
|
+
checkActionBindings?: boolean;
|
|
30
|
+
securityLimits?: DocumentSecurityLimits;
|
|
31
|
+
}
|
|
32
|
+
export interface DocumentValidationResult {
|
|
33
|
+
valid: boolean;
|
|
34
|
+
success: boolean;
|
|
35
|
+
errors: DocumentValidationError[];
|
|
36
|
+
data?: PageDocument;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Validate a page document against global schema, node shape, child policy,
|
|
40
|
+
* ID uniqueness, cycles, unknown component types, and structural bindings.
|
|
41
|
+
*/
|
|
42
|
+
export declare function validateDocument(input: unknown, options?: ValidationOptions): DocumentValidationResult;
|
|
43
|
+
//# sourceMappingURL=validator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validator.d.ts","sourceRoot":"","sources":["../src/validator.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EAGb,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,sBAAsB,EAEvB,MAAM,YAAY,CAAC;AAEpB,MAAM,MAAM,2BAA2B,GACnC,uBAAuB,GACvB,mBAAmB,GACnB,oBAAoB,GACpB,mBAAmB,GACnB,qBAAqB,GACrB,wBAAwB,GACxB,wBAAwB,GACxB,yBAAyB,GACzB,0BAA0B,GAC1B,wBAAwB,GACxB,kBAAkB,GAClB,8BAA8B,GAC9B,yBAAyB,CAAC;AAE9B,MAAM,WAAW,uBAAuB;IACtC,IAAI,EAAE,2BAA2B,CAAC;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnC;AAED,MAAM,WAAW,uBAAuB;IACtC,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAC3B,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC;CAC9B;AAED,MAAM,WAAW,qBAAqB;IACpC,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,uBAAuB,GAAG,SAAS,CAAC;IACvD,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;CAC5B;AAED,MAAM,WAAW,iBAAiB;IAChC,iBAAiB,CAAC,EAAE,qBAAqB,CAAC;IAC1C,mBAAmB,CAAC,EAAE,MAAM,EAAE,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC;IAC7C,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,cAAc,CAAC,EAAE,sBAAsB,CAAC;CACzC;AAED,MAAM,WAAW,wBAAwB;IACvC,KAAK,EAAE,OAAO,CAAC;IACf,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,uBAAuB,EAAE,CAAC;IAClC,IAAI,CAAC,EAAE,YAAY,CAAC;CACrB;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,OAAO,EACd,OAAO,GAAE,iBAAsB,GAC9B,wBAAwB,CAiJ1B"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { VariableCatalog } from './interfaces';
|
|
2
|
+
/**
|
|
3
|
+
* Expands a host `VariableCatalog`'s dotted `sampleValue` keys (e.g. `'site.name'`,
|
|
4
|
+
* `'products'`) into a nested object shaped the same way `resolveBinding` expects
|
|
5
|
+
* `context.variables` to be shaped. Editor/preview-only: the result should be merged
|
|
6
|
+
* into a `RuntimeContext.variables` for canvas preview, never written to a document.
|
|
7
|
+
*/
|
|
8
|
+
export declare function buildSampleVariablesFromCatalog(catalog?: VariableCatalog): Record<string, unknown>;
|
|
9
|
+
//# sourceMappingURL=variable-catalog.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"variable-catalog.d.ts","sourceRoot":"","sources":["../src/variable-catalog.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAQpD;;;;;GAKG;AACH,wBAAgB,+BAA+B,CAAC,OAAO,CAAC,EAAE,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAyBlG"}
|
package/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@kubuild/core",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Framework-agnostic engine for KUBUILD: document utilities, command engine, history, migration, and validation",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"require": "./dist/index.cjs"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist"
|
|
18
|
+
],
|
|
19
|
+
"sideEffects": false,
|
|
20
|
+
"publishConfig": {
|
|
21
|
+
"access": "public"
|
|
22
|
+
},
|
|
23
|
+
"scripts": {
|
|
24
|
+
"build": "tsup && tsc --emitDeclarationOnly",
|
|
25
|
+
"dev": "tsup --watch",
|
|
26
|
+
"typecheck": "tsc --noEmit",
|
|
27
|
+
"lint": "eslint src",
|
|
28
|
+
"test": "vitest run",
|
|
29
|
+
"prepublishOnly": "pnpm run build"
|
|
30
|
+
},
|
|
31
|
+
"repository": {
|
|
32
|
+
"type": "git",
|
|
33
|
+
"url": "git+https://github.com/kustora/kubuild.git"
|
|
34
|
+
},
|
|
35
|
+
"keywords": [
|
|
36
|
+
"page-builder",
|
|
37
|
+
"visual-editor",
|
|
38
|
+
"low-code",
|
|
39
|
+
"website-builder",
|
|
40
|
+
"stora",
|
|
41
|
+
"kubuild"
|
|
42
|
+
],
|
|
43
|
+
"author": "KUBUILD",
|
|
44
|
+
"license": "MIT",
|
|
45
|
+
"bugs": {
|
|
46
|
+
"url": "https://github.com/kustora/kubuild/issues"
|
|
47
|
+
},
|
|
48
|
+
"homepage": "https://github.com/kustora/kubuild#readme",
|
|
49
|
+
"dependencies": {
|
|
50
|
+
"@kubuild/schema": "workspace:*",
|
|
51
|
+
"fflate": "^0.8.3"
|
|
52
|
+
},
|
|
53
|
+
"devDependencies": {
|
|
54
|
+
"tsup": "^8.3.6",
|
|
55
|
+
"typescript": "^6.0.0",
|
|
56
|
+
"vitest": "^3.0.5"
|
|
57
|
+
}
|
|
58
|
+
}
|