@dbx-tools/shared-core 0.1.22 → 0.1.23

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/.projen/deps.json CHANGED
@@ -23,6 +23,11 @@
23
23
  "name": "consola",
24
24
  "version": "catalog:",
25
25
  "type": "peer"
26
+ },
27
+ {
28
+ "name": "zod",
29
+ "version": "catalog:",
30
+ "type": "runtime"
26
31
  }
27
32
  ],
28
33
  "//": "~~ Generated by projen. To modify, edit .projenrc.js and run \"pnpm exec projen\"."
package/README.md CHANGED
@@ -15,6 +15,7 @@ import {
15
15
  log,
16
16
  net,
17
17
  object,
18
+ brand,
18
19
  string,
19
20
  } from "@dbx-tools/shared-core";
20
21
  ```
@@ -36,6 +37,24 @@ Key features:
36
37
  logging helpers that avoid Node-only dependencies.
37
38
  - Namespace exports that make utility call sites explicit without creating a
38
39
  grab-bag default import.
40
+ - A Zod-backed `BrandContext` contract with dbx tools defaults, JSON Schema
41
+ output, and prompt serialization for browser, library, and LLM consumers.
42
+
43
+ ## Brand Context
44
+
45
+ ```ts
46
+ import { brand } from "@dbx-tools/shared-core";
47
+
48
+ const context = brand.parseBrandContext({ name: "Acme Data" });
49
+ const jsonSchema = brand.brandContextJsonSchema();
50
+ const instructions = brand.brandContextPrompt(context);
51
+ ```
52
+
53
+ `BrandContextSchema` validates identity, theme-aware assets, colors,
54
+ typography, links, audience, and voice. Every field has a dbx tools default, so
55
+ an empty object is a complete context. Use [`@dbx-tools/core`](../../node/core)
56
+ to discover and read YAML/JSON files, and
57
+ [`@dbx-tools/ui-branding`](../../ui/branding) to apply the same context to a UI.
39
58
 
40
59
  ## Async Control
41
60
 
@@ -217,3 +236,4 @@ without paying formatting cost when disabled.
217
236
  - `token` - JWT payload and scope readers.
218
237
  - `functionModule` - memoization.
219
238
  - `log` - tagged leveled logging.
239
+ - `brand` - Zod schema, defaults, JSON Schema, and LLM prompt serialization.
package/index.ts CHANGED
@@ -3,6 +3,7 @@
3
3
  // Hand edits are overwritten on the next watch; this file is read-only.
4
4
 
5
5
  export * as async from "./src/async";
6
+ export * as brand from "./src/brand";
6
7
  export * as error from "./src/error";
7
8
  export * as functionModule from "./src/function";
8
9
  export * as hash from "./src/hash";
@@ -14,6 +15,7 @@ export * as predicate from "./src/predicate";
14
15
  export * as string from "./src/string";
15
16
  export * as token from "./src/token";
16
17
  export type { PollContext, PollProducer, PollOptions } from "./src/async";
18
+ export type { BrandContext, BrandContextInput, BrandAssetSet } from "./src/brand";
17
19
  export type { ErrorContext } from "./src/error";
18
20
  export type { MemoizeOptions } from "./src/function";
19
21
  export type { HeaderLike } from "./src/http";
package/package.json CHANGED
@@ -14,12 +14,15 @@
14
14
  "peerDependencies": {
15
15
  "consola": "^3.4.2"
16
16
  },
17
+ "dependencies": {
18
+ "zod": "^4.3.6"
19
+ },
17
20
  "main": "index.ts",
18
21
  "license": "UNLICENSED",
19
22
  "publishConfig": {
20
23
  "access": "public"
21
24
  },
22
- "version": "0.1.22",
25
+ "version": "0.1.23",
23
26
  "types": "index.ts",
24
27
  "type": "module",
25
28
  "exports": {
package/src/brand.ts ADDED
@@ -0,0 +1,136 @@
1
+ /**
2
+ * Browser-safe brand contract, defaults, and LLM serialization helpers.
3
+ *
4
+ * Asset values are intentionally strings: they may be relative file paths,
5
+ * package exports, data URLs, or network URLs depending on the consumer.
6
+ */
7
+ import { z } from "zod";
8
+
9
+ const nonBlankString = z.string().trim().min(1);
10
+ const color = z.string().regex(/^#(?:[\da-f]{3}|[\da-f]{6}|[\da-f]{8})$/i, "Expected a hex color.");
11
+
12
+ export const DEFAULT_BRAND_ASSETS = {
13
+ icon: {
14
+ light: "@dbx-tools/ui-branding/assets/icon-light.svg",
15
+ dark: "@dbx-tools/ui-branding/assets/icon-dark.svg",
16
+ },
17
+ logo: {
18
+ light: "@dbx-tools/ui-branding/assets/logo-light.svg",
19
+ dark: "@dbx-tools/ui-branding/assets/logo-dark.svg",
20
+ },
21
+ favicon: "@dbx-tools/ui-branding/assets/icon-light.svg",
22
+ } as const;
23
+
24
+ export const BrandAssetSetSchema = z
25
+ .object({
26
+ light: nonBlankString.describe("Asset for light surfaces."),
27
+ dark: nonBlankString.optional().describe("Asset for dark surfaces; light is the fallback."),
28
+ })
29
+ .strict()
30
+ .describe("Theme-aware references to one visual asset.");
31
+
32
+ export const BrandColorsSchema = z
33
+ .object({
34
+ primary: color.default("#FF3621").describe("Primary action and identity color."),
35
+ primaryHover: color.default("#D92D18").describe("Primary hover or pressed color."),
36
+ accent: color.default("#00A972").describe("Secondary accent color."),
37
+ foreground: color.default("#0B2026").describe("Default text and mark color."),
38
+ background: color.default("#FFFFFF").describe("Default page background."),
39
+ surface: color.default("#F6F7F8").describe("Secondary surface background."),
40
+ muted: color.default("#5F6B70").describe("Muted text color."),
41
+ border: color.default("#DCE2E5").describe("Default border color."),
42
+ })
43
+ .strict()
44
+ .prefault({});
45
+
46
+ export const BrandVoiceSchema = z
47
+ .object({
48
+ audience: z
49
+ .array(nonBlankString)
50
+ .default(["Databricks developers", "application engineers", "AI agents"]),
51
+ tone: z.array(nonBlankString).default(["direct", "practical", "technical", "approachable"]),
52
+ principles: z
53
+ .array(nonBlankString)
54
+ .default([
55
+ "Lead with the useful outcome.",
56
+ "Prefer concrete examples and accurate technical language.",
57
+ "Keep product claims specific and defensible.",
58
+ ]),
59
+ avoid: z
60
+ .array(nonBlankString)
61
+ .default(["unsupported superlatives", "vague AI claims", "unnecessary jargon"]),
62
+ })
63
+ .strict()
64
+ .prefault({});
65
+
66
+ export const BrandContextSchema = z
67
+ .object({
68
+ schemaVersion: z.literal("1").default("1"),
69
+ name: nonBlankString.default("dbx tools").describe("Canonical display name."),
70
+ shortName: nonBlankString.default("dbx").describe("Compact name for constrained UI."),
71
+ tagline: nonBlankString
72
+ .default("Practical tools for Databricks builders.")
73
+ .describe("Short product line suitable for a header or metadata."),
74
+ description: nonBlankString
75
+ .default(
76
+ "Companion packages for Databricks developers building apps, agents, data workflows, and reusable UI.",
77
+ )
78
+ .describe("Plain-language product description."),
79
+ assets: z
80
+ .object({
81
+ icon: BrandAssetSetSchema.default(DEFAULT_BRAND_ASSETS.icon),
82
+ logo: BrandAssetSetSchema.default(DEFAULT_BRAND_ASSETS.logo),
83
+ favicon: nonBlankString.default(DEFAULT_BRAND_ASSETS.favicon),
84
+ })
85
+ .strict()
86
+ .default(DEFAULT_BRAND_ASSETS),
87
+ colors: BrandColorsSchema,
88
+ typography: z
89
+ .object({
90
+ sans: nonBlankString.default("Inter, ui-sans-serif, system-ui, sans-serif"),
91
+ mono: nonBlankString.default("ui-monospace, SFMono-Regular, Menlo, monospace"),
92
+ })
93
+ .strict()
94
+ .prefault({}),
95
+ voice: BrandVoiceSchema,
96
+ links: z
97
+ .object({
98
+ website: z.string().url().optional(),
99
+ repository: z.string().url().optional(),
100
+ documentation: z.string().url().optional(),
101
+ })
102
+ .strict()
103
+ .default({}),
104
+ extensions: z
105
+ .record(nonBlankString, z.unknown())
106
+ .default({})
107
+ .describe("Namespaced consumer-specific values that do not belong in the portable core."),
108
+ })
109
+ .strict()
110
+ .describe("Portable identity, visual, and voice context for UI, libraries, and LLMs.");
111
+
112
+ export type BrandContext = z.output<typeof BrandContextSchema>;
113
+ export type BrandContextInput = z.input<typeof BrandContextSchema>;
114
+ export type BrandAssetSet = z.output<typeof BrandAssetSetSchema>;
115
+
116
+ /** Validate input and fill every dbx tools default. */
117
+ export function parseBrandContext(input: unknown = {}): BrandContext {
118
+ return BrandContextSchema.parse(input);
119
+ }
120
+
121
+ export const defaultBrandContext: BrandContext = parseBrandContext();
122
+
123
+ /** JSON Schema representation suitable for structured-output and tool definitions. */
124
+ export function brandContextJsonSchema(): Record<string, unknown> {
125
+ return z.toJSONSchema(BrandContextSchema) as Record<string, unknown>;
126
+ }
127
+
128
+ /** Stable prompt block for an LLM that needs to write or design in this brand. */
129
+ export function brandContextPrompt(context: BrandContext = defaultBrandContext): string {
130
+ return [
131
+ `Use the following ${context.name} brand context for names, visual choices, and writing voice.`,
132
+ "Treat explicit task instructions as higher priority than this context.",
133
+ "",
134
+ JSON.stringify(context, null, 2),
135
+ ].join("\n");
136
+ }
@@ -0,0 +1,33 @@
1
+ import assert from "node:assert/strict";
2
+ import { describe, it } from "node:test";
3
+ import { brand } from "../index";
4
+
5
+ describe("brand context", () => {
6
+ it("fills dbx tools defaults", () => {
7
+ const context = brand.parseBrandContext();
8
+
9
+ assert.equal(context.name, "dbx tools");
10
+ assert.equal(context.assets.icon.light, brand.DEFAULT_BRAND_ASSETS.icon.light);
11
+ assert.equal(context.colors.primary, "#FF3621");
12
+ });
13
+
14
+ it("validates nested overrides and preserves defaults", () => {
15
+ const context = brand.parseBrandContext({
16
+ name: "Example",
17
+ colors: { primary: "#123456" },
18
+ });
19
+
20
+ assert.equal(context.name, "Example");
21
+ assert.equal(context.colors.primary, "#123456");
22
+ assert.equal(context.colors.background, "#FFFFFF");
23
+ });
24
+
25
+ it("exports schema and prompt forms for LLM consumers", () => {
26
+ const schema = brand.brandContextJsonSchema();
27
+ const prompt = brand.brandContextPrompt();
28
+
29
+ assert.equal(schema.type, "object");
30
+ assert.match(prompt, /dbx tools brand context/);
31
+ assert.match(prompt, /"schemaVersion": "1"/);
32
+ });
33
+ });