@nubisco/cms-vue 1.0.0 → 1.2.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.
@@ -1,88 +0,0 @@
1
- /**
2
- * Logic contract: visibility and variation conditions.
3
- *
4
- * A Condition gates whether a Block or Page renders. It is either a simple
5
- * predicate, a boolean tree, or a reference to a NubiscoUI Blueprint graph for
6
- * the genuinely compound cases. Most content uses a simple predicate; the graph
7
- * is the escape hatch, not the default.
8
- *
9
- * Logic inputs are a registry. Adding a new input type (e.g. campaign source)
10
- * later is one LogicInputDefinition plus one Blueprint NodeDefinition. Nothing
11
- * in the engine or the content schema changes.
12
- */
13
- export type Op = 'is' | 'not' | 'in' | 'gte' | 'lte' | 'between';
14
- export type Condition = {
15
- kind: 'always';
16
- } | {
17
- kind: 'simple';
18
- /** A registered LogicInputDefinition id. */
19
- input: string;
20
- /** Input parameters, e.g. { flag: 'stagewright' } for featureFlag. */
21
- params?: Record<string, unknown>;
22
- /** Comparison for enum/number/date inputs. Boolean inputs need none. */
23
- op?: Op;
24
- value?: unknown;
25
- } | {
26
- kind: 'all';
27
- of: Condition[];
28
- } | {
29
- kind: 'any';
30
- of: Condition[];
31
- } | {
32
- kind: 'not';
33
- of: Condition;
34
- }
35
- /** Reference to a serialized Blueprint graph stored alongside the content. */
36
- | {
37
- kind: 'graph';
38
- graphId: string;
39
- };
40
- /**
41
- * Where a logic input can be evaluated. This is load-bearing for delivery:
42
- * - `build` inputs (flag, environment, locale) let a gated block prerender.
43
- * - `request` inputs (auth, region) force the block to be resolved at the edge
44
- * (a Worker) or revealed client-side. It cannot be baked.
45
- * A block whose condition mixes both is resolved at the most dynamic site.
46
- */
47
- export type ResolveAt = 'build' | 'request';
48
- export type LogicValueType = 'boolean' | 'enum' | 'number' | 'date';
49
- /**
50
- * A logic input type, registered once. The value is resolved by a host-provided
51
- * resolver keyed by `id`; this definition only declares the shape and where it
52
- * can run, so the visual editor and the evaluator are fully data-driven.
53
- */
54
- export type LogicKind = 'featureFlag' | 'environment' | 'auth' | 'region' | 'and' | 'or' | 'not' | 'visible';
55
- export interface LogicNode {
56
- id: string;
57
- kind: LogicKind;
58
- x: number;
59
- y: number;
60
- /** Flag key / environment value / region code, for the input nodes. */
61
- param?: string;
62
- }
63
- export interface GraphConnection {
64
- fromNode: string;
65
- fromPort: string;
66
- toNode: string;
67
- toPort: string;
68
- }
69
- export interface LogicGraph {
70
- nodes: LogicNode[];
71
- connections: GraphConnection[];
72
- }
73
- export interface LogicInputDefinition {
74
- id: string;
75
- label: string;
76
- valueType: LogicValueType;
77
- /** Parameters the author fills in, e.g. featureFlag needs a `flag`. */
78
- params?: Record<string, import('./content').FieldSchema>;
79
- resolveAt: ResolveAt;
80
- /** Allowed values for enum inputs (environment, region, locale). */
81
- enumValues?: string[];
82
- }
83
- /**
84
- * The initial catalog. Extend by appending a definition (and, for the visual
85
- * editor, a matching Blueprint NodeDefinition). `campaignSource` is the worked
86
- * example of a future input: append one entry with resolveAt: 'request'.
87
- */
88
- export declare const CORE_LOGIC_INPUTS: LogicInputDefinition[];
@@ -1,63 +0,0 @@
1
- /**
2
- * Logic contract: visibility and variation conditions.
3
- *
4
- * A Condition gates whether a Block or Page renders. It is either a simple
5
- * predicate, a boolean tree, or a reference to a NubiscoUI Blueprint graph for
6
- * the genuinely compound cases. Most content uses a simple predicate; the graph
7
- * is the escape hatch, not the default.
8
- *
9
- * Logic inputs are a registry. Adding a new input type (e.g. campaign source)
10
- * later is one LogicInputDefinition plus one Blueprint NodeDefinition. Nothing
11
- * in the engine or the content schema changes.
12
- */
13
- /**
14
- * The initial catalog. Extend by appending a definition (and, for the visual
15
- * editor, a matching Blueprint NodeDefinition). `campaignSource` is the worked
16
- * example of a future input: append one entry with resolveAt: 'request'.
17
- */
18
- export const CORE_LOGIC_INPUTS = [
19
- {
20
- id: 'featureFlag',
21
- label: 'Feature flag',
22
- valueType: 'boolean',
23
- params: { flag: { type: 'text', label: 'Flag key', required: true } },
24
- resolveAt: 'build',
25
- },
26
- {
27
- id: 'environment',
28
- label: 'Environment',
29
- valueType: 'enum',
30
- enumValues: ['staging', 'production'],
31
- resolveAt: 'build',
32
- },
33
- {
34
- id: 'locale',
35
- label: 'Locale',
36
- valueType: 'enum',
37
- enumValues: ['en', 'pt', 'es', 'fr'],
38
- resolveAt: 'build',
39
- },
40
- {
41
- id: 'schedule',
42
- label: 'Schedule window',
43
- valueType: 'date',
44
- params: {
45
- from: { type: 'date', label: 'From' },
46
- to: { type: 'date', label: 'To' },
47
- },
48
- resolveAt: 'build',
49
- },
50
- {
51
- id: 'auth',
52
- label: 'Signed in',
53
- valueType: 'boolean',
54
- resolveAt: 'request',
55
- },
56
- {
57
- id: 'region',
58
- label: 'Region',
59
- valueType: 'enum',
60
- enumValues: ['EU', 'NA', 'SA', 'AS', 'AF', 'OC'],
61
- resolveAt: 'request',
62
- },
63
- ];
@@ -1,15 +0,0 @@
1
- import type { Condition, LogicGraph, Op } from './contract';
2
- /**
3
- * Resolves one logic input to a boolean, given the author's params/op/value.
4
- * The host provides one resolver per registered input id (featureFlag,
5
- * environment, auth, region, ...). This is where build-time vs request-time
6
- * resolution actually happens; the contract only declares which is which.
7
- */
8
- export type InputResolver = (params: Record<string, unknown> | undefined, op: Op | undefined, value: unknown) => boolean;
9
- export type LogicEnv = Record<string, InputResolver>;
10
- /**
11
- * Evaluates a Condition tree to a visibility boolean. `graphs` supplies the
12
- * logic graphs referenced by { kind: 'graph' } conditions (stored on the page
13
- * document); a graph condition with no matching graph defaults to visible.
14
- */
15
- export declare function evaluate(condition: Condition | undefined, env: LogicEnv, graphs?: Record<string, LogicGraph>): boolean;
package/dist/evaluate.js DELETED
@@ -1,26 +0,0 @@
1
- import { evaluateGraph } from './graph';
2
- /**
3
- * Evaluates a Condition tree to a visibility boolean. `graphs` supplies the
4
- * logic graphs referenced by { kind: 'graph' } conditions (stored on the page
5
- * document); a graph condition with no matching graph defaults to visible.
6
- */
7
- export function evaluate(condition, env, graphs) {
8
- if (!condition || condition.kind === 'always')
9
- return true;
10
- switch (condition.kind) {
11
- case 'simple': {
12
- const resolve = env[condition.input];
13
- return resolve ? resolve(condition.params, condition.op, condition.value) : false;
14
- }
15
- case 'all':
16
- return condition.of.every((c) => evaluate(c, env, graphs));
17
- case 'any':
18
- return condition.of.some((c) => evaluate(c, env, graphs));
19
- case 'not':
20
- return !evaluate(condition.of, env, graphs);
21
- case 'graph': {
22
- const graph = graphs?.[condition.graphId];
23
- return graph ? evaluateGraph(graph, env).visible : true;
24
- }
25
- }
26
- }
package/dist/graph.d.ts DELETED
@@ -1,45 +0,0 @@
1
- import type { LogicGraph, LogicKind } from './contract';
2
- import type { LogicEnv } from './evaluate';
3
- /**
4
- * App-side logic for the graph form of a Condition (the data shapes live in the
5
- * contract). The node catalog, Blueprint card mapping, and evaluator are here.
6
- * Inputs (feature flag, environment, ...) feed gates (AND/OR/NOT) that feed a
7
- * single Visible sink; graphs are referenced from a condition as
8
- * { kind: 'graph', graphId }.
9
- */
10
- interface NodePort {
11
- id: string;
12
- label: string;
13
- type: 'input' | 'output';
14
- }
15
- interface NodeSpec {
16
- label: string;
17
- color: string;
18
- category: string;
19
- ports: NodePort[];
20
- /** Which parameter this node carries, if any. */
21
- param?: 'flag' | 'environment' | 'region';
22
- }
23
- export declare const NODE_SPECS: Record<LogicKind, NodeSpec>;
24
- export interface BlueprintCard {
25
- id: string;
26
- x: number;
27
- y: number;
28
- width: number;
29
- height: number;
30
- paint: {
31
- title: string;
32
- color: string;
33
- category: string;
34
- ports: NodePort[];
35
- };
36
- }
37
- /** Maps the logic graph to Blueprint card geometry + paint. */
38
- export declare function toCards(graph: LogicGraph): BlueprintCard[];
39
- export interface GraphResult {
40
- visible: boolean;
41
- nodeOut: Record<string, boolean>;
42
- }
43
- /** Evaluates the graph to the Visible sink's value, plus each node's output. */
44
- export declare function evaluateGraph(graph: LogicGraph, env: LogicEnv): GraphResult;
45
- export {};
package/dist/graph.js DELETED
@@ -1,130 +0,0 @@
1
- export const NODE_SPECS = {
2
- featureFlag: {
3
- label: 'Feature flag',
4
- color: '#6e6bd6',
5
- category: 'input',
6
- ports: [{ id: 'out', label: 'on', type: 'output' }],
7
- param: 'flag',
8
- },
9
- environment: {
10
- label: 'Environment',
11
- color: '#b9781e',
12
- category: 'input',
13
- ports: [{ id: 'out', label: 'is', type: 'output' }],
14
- param: 'environment',
15
- },
16
- auth: {
17
- label: 'Signed in',
18
- color: '#2c9560',
19
- category: 'input',
20
- ports: [{ id: 'out', label: 'yes', type: 'output' }],
21
- },
22
- region: {
23
- label: 'Region',
24
- color: '#3a86c8',
25
- category: 'input',
26
- ports: [{ id: 'out', label: 'in', type: 'output' }],
27
- param: 'region',
28
- },
29
- and: {
30
- label: 'AND',
31
- color: '#5a5a6a',
32
- category: 'gate',
33
- ports: [
34
- { id: 'a', label: 'a', type: 'input' },
35
- { id: 'b', label: 'b', type: 'input' },
36
- { id: 'out', label: 'out', type: 'output' },
37
- ],
38
- },
39
- or: {
40
- label: 'OR',
41
- color: '#5a5a6a',
42
- category: 'gate',
43
- ports: [
44
- { id: 'a', label: 'a', type: 'input' },
45
- { id: 'b', label: 'b', type: 'input' },
46
- { id: 'out', label: 'out', type: 'output' },
47
- ],
48
- },
49
- not: {
50
- label: 'NOT',
51
- color: '#5a5a6a',
52
- category: 'gate',
53
- ports: [
54
- { id: 'in', label: 'in', type: 'input' },
55
- { id: 'out', label: 'out', type: 'output' },
56
- ],
57
- },
58
- visible: {
59
- label: 'Visible',
60
- color: '#c0392b',
61
- category: 'output',
62
- ports: [{ id: 'in', label: 'show', type: 'input' }],
63
- },
64
- };
65
- /** Maps the logic graph to Blueprint card geometry + paint. */
66
- export function toCards(graph) {
67
- return graph.nodes.map((n) => {
68
- const spec = NODE_SPECS[n.kind];
69
- const title = n.param ? `${spec.label}: ${n.param}` : spec.label;
70
- return {
71
- id: n.id,
72
- x: n.x,
73
- y: n.y,
74
- width: 160,
75
- height: 52 + spec.ports.length * 8,
76
- paint: { title, color: spec.color, category: spec.category, ports: spec.ports },
77
- };
78
- });
79
- }
80
- /** Evaluates the graph to the Visible sink's value, plus each node's output. */
81
- export function evaluateGraph(graph, env) {
82
- const memo = {};
83
- const sourceOf = (nodeId, port) => graph.connections.find((c) => c.toNode === nodeId && c.toPort === port)?.fromNode;
84
- const inVal = (nodeId, port) => {
85
- const src = sourceOf(nodeId, port);
86
- return src ? out(src) : false;
87
- };
88
- function out(nodeId) {
89
- if (nodeId in memo)
90
- return memo[nodeId];
91
- memo[nodeId] = false; // break cycles defensively
92
- const node = graph.nodes.find((n) => n.id === nodeId);
93
- if (!node)
94
- return false;
95
- let v = false;
96
- switch (node.kind) {
97
- case 'featureFlag':
98
- v = env.featureFlag?.({ flag: node.param ?? '' }, undefined, undefined) ?? false;
99
- break;
100
- case 'environment':
101
- v = env.environment?.(undefined, 'is', node.param ?? 'staging') ?? false;
102
- break;
103
- case 'auth':
104
- v = env.auth?.(undefined, undefined, undefined) ?? false;
105
- break;
106
- case 'region':
107
- v = env.region?.(undefined, 'in', [node.param ?? '']) ?? false;
108
- break;
109
- case 'and':
110
- v = inVal(nodeId, 'a') && inVal(nodeId, 'b');
111
- break;
112
- case 'or':
113
- v = inVal(nodeId, 'a') || inVal(nodeId, 'b');
114
- break;
115
- case 'not':
116
- v = !inVal(nodeId, 'in');
117
- break;
118
- case 'visible':
119
- v = inVal(nodeId, 'in');
120
- break;
121
- }
122
- memo[nodeId] = v;
123
- return v;
124
- }
125
- const sink = graph.nodes.find((n) => n.kind === 'visible');
126
- const nodeOut = {};
127
- for (const n of graph.nodes)
128
- nodeOut[n.id] = out(n.id);
129
- return { visible: sink ? out(sink.id) : false, nodeOut };
130
- }
package/dist/resolve.d.ts DELETED
@@ -1,10 +0,0 @@
1
- import type { FieldValue, ImageValue, LinkValue, TRef } from './contract';
2
- export declare function isTRef(v: unknown): v is TRef;
3
- export declare function isImage(v: unknown): v is ImageValue;
4
- export declare function isLink(v: unknown): v is LinkValue;
5
- /**
6
- * Resolves a field value to display text. String refs ({ $t }) resolve from the
7
- * provided message table (Verba / locale JSON), falling back to the key so a
8
- * missing translation is visible rather than blank.
9
- */
10
- export declare function text(value: FieldValue | undefined, messages: Record<string, string>): string;
package/dist/resolve.js DELETED
@@ -1,25 +0,0 @@
1
- export function isTRef(v) {
2
- return typeof v === 'object' && v !== null && '$t' in v;
3
- }
4
- export function isImage(v) {
5
- return typeof v === 'object' && v !== null && 'src' in v;
6
- }
7
- export function isLink(v) {
8
- return typeof v === 'object' && v !== null && 'href' in v;
9
- }
10
- /**
11
- * Resolves a field value to display text. String refs ({ $t }) resolve from the
12
- * provided message table (Verba / locale JSON), falling back to the key so a
13
- * missing translation is visible rather than blank.
14
- */
15
- export function text(value, messages) {
16
- if (value == null)
17
- return '';
18
- if (typeof value === 'string')
19
- return value;
20
- if (typeof value === 'number' || typeof value === 'boolean')
21
- return String(value);
22
- if (isTRef(value))
23
- return messages[value.$t] ?? value.$t;
24
- return '';
25
- }