@ramme-io/shared 2.0.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/dist/index.js ADDED
@@ -0,0 +1,190 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __export = (target, all) => {
3
+ for (var name in all)
4
+ __defProp(target, name, { get: all[name], enumerable: true });
5
+ };
6
+
7
+ // src/schema.ts
8
+ import { z } from "zod";
9
+ var FieldSchema = z.object({
10
+ key: z.string(),
11
+ label: z.string(),
12
+ type: z.enum(["text", "number", "currency", "date", "boolean", "status", "email", "image", "textarea"]),
13
+ required: z.boolean().optional(),
14
+ description: z.string().optional(),
15
+ defaultValue: z.any().optional()
16
+ });
17
+ var ResourceSchema = z.object({
18
+ id: z.string(),
19
+ name: z.string(),
20
+ fields: z.array(FieldSchema),
21
+ defaultView: z.enum(["table", "grid", "list"]).optional(),
22
+ features: z.object({
23
+ searchable: z.boolean().optional(),
24
+ creatable: z.boolean().optional(),
25
+ editable: z.boolean().optional(),
26
+ deletable: z.boolean().optional(),
27
+ exportable: z.boolean().optional()
28
+ }).optional()
29
+ });
30
+ var SignalSchema = z.object({
31
+ id: z.string().min(1, "Signal ID is required"),
32
+ label: z.string(),
33
+ description: z.string().optional(),
34
+ kind: z.enum(["sensor", "actuator", "setpoint", "metric", "status", "kpi"]),
35
+ source: z.enum(["mock", "mqtt", "http", "derived", "local"]),
36
+ // Connectivity
37
+ topic: z.string().optional(),
38
+ endpoint: z.string().optional(),
39
+ jsonPath: z.string().optional(),
40
+ refreshRate: z.number().optional().default(1e3),
41
+ // Values
42
+ defaultValue: z.any().optional(),
43
+ unit: z.string().optional(),
44
+ min: z.number().optional(),
45
+ max: z.number().optional()
46
+ });
47
+ var EntitySchema = z.object({
48
+ id: z.string(),
49
+ name: z.string(),
50
+ description: z.string().optional(),
51
+ type: z.string(),
52
+ category: z.string().default("logical"),
53
+ signals: z.array(z.string()),
54
+ ui: z.object({
55
+ icon: z.string().optional(),
56
+ color: z.string().optional(),
57
+ dashboardComponent: z.string().optional()
58
+ }).optional()
59
+ });
60
+ var TriggerSchema = z.object({
61
+ id: z.string(),
62
+ type: z.enum(["signal_change", "manual_action", "schedule", "webhook"]),
63
+ config: z.record(z.string(), z.any())
64
+ });
65
+ var ActionSchema = z.object({
66
+ id: z.string(),
67
+ type: z.enum([
68
+ "update_resource",
69
+ "send_notification",
70
+ "mqtt_publish",
71
+ "api_call",
72
+ "navigate",
73
+ "agent_task"
74
+ ]),
75
+ config: z.record(z.string(), z.any())
76
+ });
77
+ var WorkflowSchema = z.object({
78
+ id: z.string(),
79
+ name: z.string(),
80
+ active: z.boolean().default(true),
81
+ trigger: TriggerSchema,
82
+ actions: z.array(ActionSchema)
83
+ });
84
+ var BlockSchema = z.object({
85
+ id: z.string(),
86
+ type: z.string(),
87
+ props: z.record(z.string(), z.any()),
88
+ layout: z.object({
89
+ colSpan: z.number().optional(),
90
+ rowSpan: z.number().optional()
91
+ }).optional()
92
+ });
93
+ var PageSectionSchema = z.object({
94
+ id: z.string(),
95
+ title: z.string().optional(),
96
+ description: z.string().optional(),
97
+ layout: z.object({
98
+ columns: z.number().optional(),
99
+ variant: z.enum(["grid", "stack", "split"]).optional()
100
+ }).optional(),
101
+ blocks: z.array(BlockSchema)
102
+ });
103
+ var PageSchema = z.object({
104
+ id: z.string(),
105
+ slug: z.string(),
106
+ title: z.string(),
107
+ description: z.string().optional(),
108
+ icon: z.string().optional(),
109
+ sections: z.array(PageSectionSchema)
110
+ });
111
+ var AppSpecificationSchema = z.object({
112
+ meta: z.object({
113
+ name: z.string(),
114
+ version: z.string(),
115
+ description: z.string().optional(),
116
+ author: z.string().optional(),
117
+ createdAt: z.string().optional()
118
+ }),
119
+ config: z.object({
120
+ theme: z.enum(["light", "dark", "system", "corporate", "midnight", "blueprint"]).default("system"),
121
+ mockMode: z.boolean().default(true),
122
+ brokerUrl: z.string().optional()
123
+ }),
124
+ modules: z.array(z.string()).optional(),
125
+ resources: z.array(ResourceSchema).optional(),
126
+ domain: z.object({
127
+ signals: z.array(SignalSchema),
128
+ entities: z.array(EntitySchema),
129
+ workflows: z.array(WorkflowSchema).optional()
130
+ }),
131
+ pages: z.array(PageSchema).optional()
132
+ });
133
+ var FloraTelemetrySchema = z.object({
134
+ timestamp: z.number(),
135
+ soilMoisture: z.number().min(0).max(100),
136
+ ambientLight: z.number().min(0).max(1e5),
137
+ temperature: z.number().min(-40).max(125)
138
+ });
139
+
140
+ // src/bodewell/schema.ts
141
+ var schema_exports = {};
142
+ __export(schema_exports, {
143
+ BodewellCommandSchema: () => BodewellCommandSchema,
144
+ BodewellDeviceID: () => BodewellDeviceID,
145
+ BodewellTelemetrySchema: () => BodewellTelemetrySchema
146
+ });
147
+ import { z as z2 } from "zod";
148
+ var BodewellDeviceID = z2.enum([
149
+ "STK-V1-001",
150
+ "STK-V1-002",
151
+ "STK-V1-003",
152
+ "STK-PRO-001",
153
+ "STK-VIS-001"
154
+ ]);
155
+ var BodewellTelemetrySchema = z2.object({
156
+ device_id: BodewellDeviceID,
157
+ stick_id: z2.string().optional().describe("Firmware alias for device_id"),
158
+ timestamp: z2.number().optional().describe("Epoch timestamp from NTP"),
159
+ air_temp: z2.number().optional().describe("Celsius"),
160
+ air_humid: z2.number().optional().describe("Relative Humidity %"),
161
+ humidity: z2.number().optional().describe("Firmware alias for air_humid"),
162
+ air_pressure: z2.number().optional().describe("hPa"),
163
+ pressure: z2.number().optional().describe("Firmware alias for air_pressure"),
164
+ light_lux: z2.number().optional().describe("Lux level"),
165
+ soil_temp_stemma: z2.number().optional().describe("Celsius"),
166
+ soil_vwc: z2.number().describe("Volumetric Water Content / Raw Capacitance"),
167
+ soil_moisture: z2.number().optional().describe("Firmware alias for raw capacitance"),
168
+ soil_moisture_raw: z2.number().optional().describe("Unscaled capacitance (300-1100)")
169
+ }).passthrough();
170
+ var BodewellCommandSchema = z2.object({
171
+ stick_id: BodewellDeviceID,
172
+ // Note: Your API uses stick_id here, not device_id
173
+ type: z2.enum(["dry", "wet"]),
174
+ value: z2.number()
175
+ });
176
+ export {
177
+ ActionSchema,
178
+ AppSpecificationSchema,
179
+ BlockSchema,
180
+ schema_exports as Bodewell,
181
+ EntitySchema,
182
+ FieldSchema,
183
+ FloraTelemetrySchema,
184
+ PageSchema,
185
+ PageSectionSchema,
186
+ ResourceSchema,
187
+ SignalSchema,
188
+ TriggerSchema,
189
+ WorkflowSchema
190
+ };
package/index.ts ADDED
@@ -0,0 +1,4 @@
1
+ export * from './src/schema';
2
+
3
+ // NEW: Bodewell Tenant Exports
4
+ export * as Bodewell from './src/bodewell/schema';
package/package.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "name": "@ramme-io/shared",
3
+ "version": "2.0.0",
4
+ "private": false,
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
+ "scripts": {
17
+ "build": "tsup index.ts --format esm,cjs --dts --clean"
18
+ },
19
+ "dependencies": {
20
+ "zod": "^3.23.8"
21
+ },
22
+ "devDependencies": {
23
+ "tsup": "^8.5.1"
24
+ }
25
+ }
@@ -0,0 +1,35 @@
1
+ import { z } from 'zod';
2
+
3
+ export const BodewellDeviceID = z.enum([
4
+ 'STK-V1-001', 'STK-V1-002', 'STK-V1-003',
5
+ 'STK-PRO-001', 'STK-VIS-001'
6
+ ]);
7
+
8
+ // 1. The Telemetry Payload
9
+ // Hardware may send partial packets or use stick_id alias.
10
+ // Only device_id and soil_vwc are guaranteed per transmission.
11
+ export const BodewellTelemetrySchema = z.object({
12
+ device_id: BodewellDeviceID,
13
+ stick_id: z.string().optional().describe("Firmware alias for device_id"),
14
+ timestamp: z.number().optional().describe("Epoch timestamp from NTP"),
15
+ air_temp: z.number().optional().describe("Celsius"),
16
+ air_humid: z.number().optional().describe("Relative Humidity %"),
17
+ humidity: z.number().optional().describe("Firmware alias for air_humid"),
18
+ air_pressure: z.number().optional().describe("hPa"),
19
+ pressure: z.number().optional().describe("Firmware alias for air_pressure"),
20
+ light_lux: z.number().optional().describe("Lux level"),
21
+ soil_temp_stemma: z.number().optional().describe("Celsius"),
22
+ soil_vwc: z.number().describe("Volumetric Water Content / Raw Capacitance"),
23
+ soil_moisture: z.number().optional().describe("Firmware alias for raw capacitance"),
24
+ soil_moisture_raw: z.number().optional().describe("Unscaled capacitance (300-1100)"),
25
+ }).passthrough();
26
+
27
+ // 2. The Command Payload (Updated for your actual API route)
28
+ export const BodewellCommandSchema = z.object({
29
+ stick_id: BodewellDeviceID, // Note: Your API uses stick_id here, not device_id
30
+ type: z.enum(['dry', 'wet']),
31
+ value: z.number(),
32
+ });
33
+
34
+ export type BodewellTelemetry = z.infer<typeof BodewellTelemetrySchema>;
35
+ export type BodewellCommand = z.infer<typeof BodewellCommandSchema>;
package/src/schema.ts ADDED
@@ -0,0 +1,209 @@
1
+ import { z } from 'zod';
2
+
3
+ /**
4
+ * @file schema.ts
5
+ * @description The "Application Constitution".
6
+ *
7
+ * ARCHITECTURAL ROLE:
8
+ * This file uses Zod to define the strict runtime validation rules for the
9
+ * App Manifest. While `manifest-types.ts` handles compile-time TypeScript checks,
10
+ * this file handles runtime validation, ensuring that any JSON loaded into the
11
+ * engine (whether from a file, API, or user input) is structurally sound.
12
+ *
13
+ * LAYERS DEFINED:
14
+ * 1. **SaaS Layer:** Data resources, fields, and tables.
15
+ * 2. **Physical Layer:** IoT signals, sensors, and entities.
16
+ * 3. **Logic Layer:** Workflows, triggers, and automated actions.
17
+ * 4. **Presentation Layer:** Pages, sections, and UI blocks.
18
+ */
19
+
20
+ // ------------------------------------------------------------------
21
+ // 1. DATA RESOURCE DEFINITIONS (SaaS Layer)
22
+ // ------------------------------------------------------------------
23
+
24
+ export const FieldSchema = z.object({
25
+ key: z.string(),
26
+ label: z.string(),
27
+ type: z.enum(['text', 'number', 'currency', 'date', 'boolean', 'status', 'email', 'image', 'textarea']),
28
+ required: z.boolean().optional(),
29
+ description: z.string().optional(),
30
+ defaultValue: z.any().optional(),
31
+ });
32
+ export type FieldDefinition = z.infer<typeof FieldSchema>;
33
+
34
+ export const ResourceSchema = z.object({
35
+ id: z.string(),
36
+ name: z.string(),
37
+ fields: z.array(FieldSchema),
38
+ defaultView: z.enum(['table', 'grid', 'list']).optional(),
39
+ features: z.object({
40
+ searchable: z.boolean().optional(),
41
+ creatable: z.boolean().optional(),
42
+ editable: z.boolean().optional(),
43
+ deletable: z.boolean().optional(),
44
+ exportable: z.boolean().optional(),
45
+ }).optional(),
46
+ });
47
+ export type ResourceDefinition = z.infer<typeof ResourceSchema>;
48
+
49
+
50
+ // ------------------------------------------------------------------
51
+ // 2. SIGNAL & IOT DEFINITIONS (Physical Layer)
52
+ // ------------------------------------------------------------------
53
+
54
+ export const SignalSchema = z.object({
55
+ id: z.string().min(1, "Signal ID is required"),
56
+ label: z.string(),
57
+ description: z.string().optional(),
58
+ kind: z.enum(['sensor', 'actuator', 'setpoint', 'metric', 'status', 'kpi']),
59
+ source: z.enum(['mock', 'mqtt', 'http', 'derived', 'local']),
60
+
61
+ // Connectivity
62
+ topic: z.string().optional(),
63
+ endpoint: z.string().optional(),
64
+ jsonPath: z.string().optional(),
65
+ refreshRate: z.number().optional().default(1000),
66
+
67
+ // Values
68
+ defaultValue: z.any().optional(),
69
+ unit: z.string().optional(),
70
+ min: z.number().optional(),
71
+ max: z.number().optional(),
72
+ });
73
+ export type SignalDefinition = z.infer<typeof SignalSchema>;
74
+
75
+ export const EntitySchema = z.object({
76
+ id: z.string(),
77
+ name: z.string(),
78
+ description: z.string().optional(),
79
+ type: z.string(),
80
+ category: z.string().default('logical'),
81
+ signals: z.array(z.string()),
82
+ ui: z.object({
83
+ icon: z.string().optional(),
84
+ color: z.string().optional(),
85
+ dashboardComponent: z.string().optional(),
86
+ }).optional(),
87
+ });
88
+ export type EntityDefinition = z.infer<typeof EntitySchema>;
89
+
90
+ // ------------------------------------------------------------------
91
+ // 3. LOGIC & WORKFLOW DEFINITIONS (Logic Layer)
92
+ // ------------------------------------------------------------------
93
+
94
+ export const TriggerSchema = z.object({
95
+ id: z.string(),
96
+ type: z.enum(['signal_change', 'manual_action', 'schedule', 'webhook']),
97
+ config: z.record(z.string(), z.any()),
98
+ });
99
+
100
+ export const ActionSchema = z.object({
101
+ id: z.string(),
102
+ type: z.enum([
103
+ 'update_resource',
104
+ 'send_notification',
105
+ 'mqtt_publish',
106
+ 'api_call',
107
+ 'navigate',
108
+ 'agent_task'
109
+ ]),
110
+ config: z.record(z.string(), z.any()),
111
+ });
112
+
113
+ export const WorkflowSchema = z.object({
114
+ id: z.string(),
115
+ name: z.string(),
116
+ active: z.boolean().default(true),
117
+ trigger: TriggerSchema,
118
+ actions: z.array(ActionSchema),
119
+ });
120
+ export type WorkflowDefinition = z.infer<typeof WorkflowSchema>;
121
+ export type ActionDefinition = z.infer<typeof ActionSchema>;
122
+
123
+
124
+ // ------------------------------------------------------------------
125
+ // 4. UI LAYOUT DEFINITIONS (Presentation Layer)
126
+ // ------------------------------------------------------------------
127
+
128
+ export const BlockSchema = z.object({
129
+ id: z.string(),
130
+ type: z.string(),
131
+ props: z.record(z.string(), z.any()),
132
+ layout: z.object({
133
+ colSpan: z.number().optional(),
134
+ rowSpan: z.number().optional(),
135
+ }).optional(),
136
+ });
137
+ // Explicitly export the Block type
138
+ export type Block = z.infer<typeof BlockSchema>;
139
+
140
+ export const PageSectionSchema = z.object({
141
+ id: z.string(),
142
+ title: z.string().optional(),
143
+ description: z.string().optional(),
144
+ layout: z.object({
145
+ columns: z.number().optional(),
146
+ variant: z.enum(['grid', 'stack', 'split']).optional()
147
+ }).optional(),
148
+ blocks: z.array(BlockSchema),
149
+ });
150
+ // Explicitly export the PageSection type
151
+ export type PageSection = z.infer<typeof PageSectionSchema>;
152
+
153
+ export const PageSchema = z.object({
154
+ id: z.string(),
155
+ slug: z.string(),
156
+ title: z.string(),
157
+ description: z.string().optional(),
158
+ icon: z.string().optional(),
159
+ sections: z.array(PageSectionSchema),
160
+ });
161
+ export type PageDefinition = z.infer<typeof PageSchema>;
162
+
163
+
164
+ // ------------------------------------------------------------------
165
+ // 5. MASTER APP SPECIFICATION (Root)
166
+ // ------------------------------------------------------------------
167
+
168
+ export const AppSpecificationSchema = z.object({
169
+ meta: z.object({
170
+ name: z.string(),
171
+ version: z.string(),
172
+ description: z.string().optional(),
173
+ author: z.string().optional(),
174
+ createdAt: z.string().optional(),
175
+ }),
176
+
177
+ config: z.object({
178
+ theme: z.enum(['light', 'dark', 'system', 'corporate', 'midnight', 'blueprint']).default('system'),
179
+ mockMode: z.boolean().default(true),
180
+ brokerUrl: z.string().optional(),
181
+ }),
182
+
183
+ modules: z.array(z.string()).optional(),
184
+ resources: z.array(ResourceSchema).optional(),
185
+
186
+ domain: z.object({
187
+ signals: z.array(SignalSchema),
188
+ entities: z.array(EntitySchema),
189
+ workflows: z.array(WorkflowSchema).optional(),
190
+ }),
191
+
192
+ pages: z.array(PageSchema).optional(),
193
+ });
194
+
195
+ export type AppSpecification = z.infer<typeof AppSpecificationSchema>;
196
+
197
+
198
+ // ------------------------------------------------------------------
199
+ // 6. FLORA TELEMETRY (Legacy)
200
+ // ------------------------------------------------------------------
201
+
202
+ export const FloraTelemetrySchema = z.object({
203
+ timestamp: z.number(),
204
+ soilMoisture: z.number().min(0).max(100),
205
+ ambientLight: z.number().min(0).max(100000),
206
+ temperature: z.number().min(-40).max(125),
207
+ });
208
+
209
+ export type FloraTelemetry = z.infer<typeof FloraTelemetrySchema>;
package/tsconfig.json ADDED
@@ -0,0 +1,16 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "module": "ESNext",
5
+ "moduleResolution": "bundler",
6
+ "strict": true,
7
+ "esModuleInterop": true,
8
+ "declaration": true,
9
+ "declarationMap": true,
10
+ "sourceMap": true,
11
+ "outDir": "./dist",
12
+ "rootDir": "."
13
+ },
14
+ "include": ["index.ts", "src/**/*.ts"],
15
+ "exclude": ["dist", "node_modules"]
16
+ }