@proulr/sdui-contract 0.1.3 → 0.1.5

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@proulr/sdui-contract",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "type": "module",
5
5
  "main": "./src/index.ts",
6
6
  "types": "./src/index.ts",
@@ -17,9 +17,12 @@
17
17
  "scripts": {
18
18
  "prepare": "husky",
19
19
  "typecheck": "tsc --noEmit",
20
+ "test": "vitest run",
21
+ "test:watch": "vitest",
20
22
  "prepublishOnly": "npm run typecheck",
21
23
  "lint": "eslint .",
22
- "lint:fix": "eslint . --fix"
24
+ "lint:fix": "eslint . --fix",
25
+ "version:sync": "node ../scripts/proulr-bump-and-sync-deps.mjs"
23
26
  },
24
27
  "publishConfig": {
25
28
  "access": "public"
@@ -32,7 +35,8 @@
32
35
  "husky": "^9.1.7",
33
36
  "lint-staged": "^16.4.0",
34
37
  "typescript": "~6.0.3",
35
- "typescript-eslint": "^8.61.1"
38
+ "typescript-eslint": "^8.61.1",
39
+ "vitest": "^3.2.7"
36
40
  },
37
41
  "engines": {
38
42
  "node": ">=22"
@@ -0,0 +1,64 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import {
3
+ createScreenWire,
4
+ decodeSduiScreenWire,
5
+ SduiCodecError,
6
+ } from './sdui-screen-codec';
7
+
8
+ describe('createScreenWire', () => {
9
+ it('builds a schema v1 wire payload', () => {
10
+ const wire = createScreenWire('demo.home', [{ id: '0', type: 'stack', props: {} }], {
11
+ data: { count: 1 },
12
+ });
13
+ expect(wire).toMatchObject({
14
+ schema_version: 1,
15
+ screen_id: 'demo.home',
16
+ blocks: [{ id: '0', type: 'stack' }],
17
+ data: { count: 1 },
18
+ });
19
+ });
20
+ });
21
+
22
+ describe('decodeSduiScreenWire', () => {
23
+ it('decodes a valid wire into camelCase domain screen', () => {
24
+ const screen = decodeSduiScreenWire({
25
+ schema_version: 1,
26
+ screen_id: 'demo.home',
27
+ blocks: [{ id: 'root', type: 'text', props: { text: 'hi' } }],
28
+ actions: {
29
+ open: { type: 'navigate', route: '/x' },
30
+ },
31
+ meta: { cache_ttl_ms: 1000, offline_policy: 'cache_only', bff: 'test' },
32
+ });
33
+
34
+ expect(screen.schemaVersion).toBe(1);
35
+ expect(screen.screenId).toBe('demo.home');
36
+ expect(screen.blocks[0]).toMatchObject({ id: 'root', type: 'text' });
37
+ expect(screen.actions.open).toMatchObject({ type: 'navigate', route: '/x' });
38
+ expect(screen.meta).toMatchObject({
39
+ cacheTtlMs: 1000,
40
+ offlinePolicy: 'cache_only',
41
+ bff: 'test',
42
+ });
43
+ });
44
+
45
+ it('throws SduiCodecError for non-object payload', () => {
46
+ expect(() => decodeSduiScreenWire(null)).toThrow(SduiCodecError);
47
+ });
48
+
49
+ it('throws when schema_version is missing', () => {
50
+ expect(() => decodeSduiScreenWire({ screen_id: 'x', blocks: [] })).toThrow(/schema_version/);
51
+ });
52
+
53
+ it('throws when screen_id is empty', () => {
54
+ expect(() =>
55
+ decodeSduiScreenWire({ schema_version: 1, screen_id: '', blocks: [] }),
56
+ ).toThrow(/screen_id/);
57
+ });
58
+
59
+ it('throws when blocks is not an array', () => {
60
+ expect(() =>
61
+ decodeSduiScreenWire({ schema_version: 1, screen_id: 'x', blocks: {} }),
62
+ ).toThrow(/blocks/);
63
+ });
64
+ });