@internetderdinge/api 1.229.40 → 1.229.42

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.
Files changed (32) hide show
  1. package/dist/src/accounts/accounts.schemas.js +40 -10
  2. package/dist/src/accounts/accounts.validation.js +47 -10
  3. package/dist/src/devices/devices.route.js +6 -2
  4. package/dist/src/devices/devices.schemas.js +54 -14
  5. package/dist/src/devices/devices.validation.js +80 -13
  6. package/dist/src/index.js +1 -0
  7. package/dist/src/iotdevice/iotdevice.schemas.js +117 -33
  8. package/dist/src/iotdevice/iotdevice.validation.js +27 -5
  9. package/dist/src/middlewares/validateZod.js +3 -5
  10. package/dist/src/organizations/organizations.schemas.js +28 -5
  11. package/dist/src/organizations/organizations.validation.js +22 -11
  12. package/dist/src/tokens/tokens.schemas.js +35 -12
  13. package/dist/src/tokens/tokens.validation.js +8 -2
  14. package/dist/src/users/users.schemas.js +40 -11
  15. package/dist/src/users/users.validation.js +70 -8
  16. package/dist/tsconfig.tsbuildinfo +1 -1
  17. package/package.json +2 -2
  18. package/src/accounts/accounts.schemas.ts +40 -10
  19. package/src/accounts/accounts.validation.ts +64 -26
  20. package/src/devices/devices.route.ts +10 -2
  21. package/src/devices/devices.schemas.ts +55 -14
  22. package/src/devices/devices.validation.ts +97 -28
  23. package/src/index.ts +4 -0
  24. package/src/iotdevice/iotdevice.schemas.ts +117 -33
  25. package/src/iotdevice/iotdevice.validation.ts +38 -16
  26. package/src/middlewares/validateZod.ts +11 -13
  27. package/src/organizations/organizations.schemas.ts +28 -5
  28. package/src/organizations/organizations.validation.ts +49 -37
  29. package/src/tokens/tokens.schemas.ts +35 -12
  30. package/src/tokens/tokens.validation.ts +9 -3
  31. package/src/users/users.schemas.ts +40 -11
  32. package/src/users/users.validation.ts +88 -21
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@internetderdinge/api",
3
- "version": "1.229.40",
3
+ "version": "1.229.42",
4
4
  "description": "Shared OpenIoT API modules",
5
5
  "main": "dist/src/index.js",
6
6
  "type": "module",
@@ -14,7 +14,7 @@
14
14
  "yalc:publish": "yalc publish --push",
15
15
  "deps:versions": "node --input-type=module -e \"import { createRequire } from 'node:module'; const require = createRequire(import.meta.url); const out = (name) => { const pkgPath = require.resolve(name + '/package.json'); const version = require(pkgPath).version; console.log(name + '@' + version + ' -> ' + pkgPath); }; out('zod'); out('@asteasolutions/zod-to-openapi');\"",
16
16
  "deploy:version": "node ./scripts/release-version.mjs",
17
- "release:paperless": "node ./scripts/release-and-sync-paperless.mjs",
17
+ "release": "node ./scripts/release-and-sync-paperless.mjs",
18
18
  "lint": "eslint .",
19
19
  "lint:fix": "eslint . --fix"
20
20
  },
@@ -1,15 +1,45 @@
1
- import { z } from 'zod';
1
+ import { z } from "zod";
2
2
 
3
3
  export const accountResponseSchema = z.object({
4
- id: z.string().uuid(),
5
- email: z.string().email(),
6
- firstName: z.string().optional(),
7
- lastName: z.string().optional(),
8
- organizationId: z.string().uuid(),
9
- roles: z.array(z.string()), // e.g. ['admin','user']
10
- isMfaEnabled: z.boolean(),
11
- createdAt: z.string(), // ISO timestamp
12
- updatedAt: z.string(), // ISO timestamp
4
+ id: z
5
+ .string()
6
+ .openapi({
7
+ example: "auth0|60452f4c0dc85b0062326",
8
+ description: "Authentication provider account ID",
9
+ }),
10
+ email: z.string().email().openapi({ example: "jane.doe@example.com" }),
11
+ firstName: z.string().optional().openapi({ example: "Jane" }),
12
+ lastName: z.string().optional().openapi({ example: "Doe" }),
13
+ organizationId: z
14
+ .string()
15
+ .openapi({
16
+ example: "682fd0d7d4a6325d9d45b86e",
17
+ description: "Organization ObjectId",
18
+ }),
19
+ roles: z
20
+ .array(z.string())
21
+ .openapi({ example: ["admin", "user"], description: "Account roles" }),
22
+ isMfaEnabled: z.boolean().openapi({ example: true }),
23
+ createdAt: z
24
+ .string()
25
+ .datetime()
26
+ .openapi({ example: "2026-05-21T09:30:00.000Z" }),
27
+ updatedAt: z
28
+ .string()
29
+ .datetime()
30
+ .openapi({ example: "2026-05-21T10:15:00.000Z" }),
31
+ }).openapi({
32
+ example: {
33
+ id: "auth0|60452f4c0dc85b0062326",
34
+ email: "jane.doe@example.com",
35
+ firstName: "Jane",
36
+ lastName: "Doe",
37
+ organizationId: "682fd0d7d4a6325d9d45b86e",
38
+ roles: ["admin", "user"],
39
+ isMfaEnabled: true,
40
+ createdAt: "2026-05-21T09:30:00.000Z",
41
+ updatedAt: "2026-05-21T10:15:00.000Z",
42
+ },
13
43
  });
14
44
 
15
45
  // If you ever need the TS type:
@@ -13,22 +13,36 @@ import {
13
13
  extendZodWithOpenApi(z);
14
14
 
15
15
  export const createAccountSchema = {
16
- body: z.object({
17
- name: z
18
- .string()
19
- .openapi({ example: "Sample Entry", description: "Name of the entry" })
20
- .optional(),
21
- medication: zObjectId.openapi({ description: "Medication ObjectId" }),
22
- organization: zObjectId.openapi({ description: "Organization ObjectId" }),
23
- patient: zObjectId.openapi({ description: "Patient ObjectId" }),
24
- meta: z
25
- .record(z.string(), z.any())
26
- .openapi({
27
- example: { key: "value" },
28
- description: "Additional metadata for the entry",
29
- })
30
- .optional(),
31
- }),
16
+ body: z
17
+ .object({
18
+ name: z
19
+ .string()
20
+ .openapi({ example: "Sample Entry", description: "Name of the entry" })
21
+ .optional(),
22
+ medication: zObjectId.openapi({ description: "Medication ObjectId" }),
23
+ organization: zObjectId.openapi({ description: "Organization ObjectId" }),
24
+ patient: zObjectId.openapi({ description: "Patient ObjectId" }),
25
+ meta: z
26
+ .record(z.string(), z.any())
27
+ .openapi({
28
+ example: { key: "value" },
29
+ description: "Additional metadata for the entry",
30
+ })
31
+ .optional(),
32
+ })
33
+ .openapi({
34
+ example: {
35
+ name: "Sample Entry",
36
+ medication: "682fd0d7d4a6325d9d45b871",
37
+ organization:
38
+ process.env.SCHEMA_EXAMPLE_ORGANIZATION_ID ||
39
+ "682fd0d7d4a6325d9d45b86e",
40
+ patient: process.env.SCHEMA_EXAMPLE_USER_ID || "682fd0d7d4a6325d9d45b86d",
41
+ meta: {
42
+ source: "manual",
43
+ },
44
+ },
45
+ }),
32
46
  };
33
47
 
34
48
  export const getUsersSchema = zPagination;
@@ -67,21 +81,38 @@ export const updateAccountSchema = {
67
81
  (value) => (value === "" ? undefined : value),
68
82
  z.string().email().optional(),
69
83
  )
70
- .openapi({ description: "User email address" }),
84
+ .openapi({
85
+ example: "jane.doe@example.com",
86
+ description: "User email address",
87
+ }),
71
88
  given_name: z
72
89
  .string()
73
90
  .optional()
74
- .openapi({ example: "John", description: "Given name" }),
91
+ .openapi({ example: "Jane", description: "Given name" }),
75
92
  family_name: z
76
93
  .string()
77
94
  .optional()
78
95
  .openapi({ example: "Doe", description: "Family name" }),
79
- debug: z.boolean().optional(),
80
- demo: z.boolean().optional(),
96
+ debug: z.boolean().optional().openapi({ example: false }),
97
+ demo: z.boolean().optional().openapi({ example: false }),
81
98
  notification: z
82
99
  .record(z.string(), z.any())
83
100
  .optional()
84
- .openapi({ description: "Notification settings object" }),
101
+ .openapi({
102
+ example: { email: true, push: false },
103
+ description: "Notification settings object",
104
+ }),
105
+ }).openapi({
106
+ example: {
107
+ language: "en",
108
+ email: "jane.doe@example.com",
109
+ given_name: "Jane",
110
+ family_name: "Doe",
111
+ notification: {
112
+ email: true,
113
+ push: false,
114
+ },
115
+ },
85
116
  }),
86
117
  };
87
118
 
@@ -104,11 +135,18 @@ export const currentAccountMfaEnrollSchema = {
104
135
  };
105
136
 
106
137
  export const setDeviceTokenSchema = {
107
- body: z.object({
108
- token: z
109
- .string()
110
- .openapi({ example: "device-token", description: "Device token to set" }),
111
- }),
138
+ body: z
139
+ .object({
140
+ token: z.string().openapi({
141
+ example: "ExponentPushToken[xxxxxxxxxxxxxxxxxxxxxx]",
142
+ description: "Device token to set",
143
+ }),
144
+ })
145
+ .openapi({
146
+ example: {
147
+ token: "ExponentPushToken[xxxxxxxxxxxxxxxxxxxxxx]",
148
+ },
149
+ }),
112
150
  };
113
151
 
114
152
  export const getAvatarSchema = {};
@@ -34,6 +34,7 @@ import {
34
34
  validateOrganizationDelete,
35
35
  validateOrganizationUpdate,
36
36
  } from "../middlewares/validateAction.js";
37
+ import type { BuildRouterAndDocsOptions } from "../utils/buildRouterAndDocs.js";
37
38
 
38
39
  export const devicesRouteSpecs: RouteSpec[] = [
39
40
  {
@@ -166,7 +167,14 @@ export const devicesRouteSpecs: RouteSpec[] = [
166
167
  },
167
168
  ];
168
169
 
169
- const router: Router = Router();
170
- buildRouterAndDocs(router, devicesRouteSpecs, "/devices", ["Devices"]);
170
+ export function createDevicesRoute(
171
+ options: BuildRouterAndDocsOptions = {},
172
+ ): Router {
173
+ const router: Router = Router();
174
+ buildRouterAndDocs(router, devicesRouteSpecs, "/devices", ["Devices"], options);
175
+ return router;
176
+ }
177
+
178
+ const router = createDevicesRoute();
171
179
 
172
180
  export default router;
@@ -2,29 +2,64 @@ import { z } from "zod";
2
2
  import { zObjectId } from "../utils/zValidations.js";
3
3
 
4
4
  export const deviceResponseSchema = z.object({
5
- id: z.string(),
6
- name: z.string(),
7
- serialNumber: z.string().optional(),
8
- status: z.enum(["online", "offline", "error"]),
9
- createdAt: z.string(), // ISO timestamp
10
- updatedAt: z.string(), // ISO timestamp
11
- // ...other device fields...
5
+ id: z.string().openapi({ example: "682fd0d7d4a6325d9d45b86f" }),
6
+ name: z.string().openapi({ example: "Kitchen Display" }),
7
+ serialNumber: z.string().optional().openapi({ example: "nrf-352656106701140" }),
8
+ status: z.enum(["online", "offline", "error"]).openapi({ example: "online" }),
9
+ createdAt: z
10
+ .string()
11
+ .datetime()
12
+ .openapi({ example: "2026-05-21T09:30:00.000Z" }),
13
+ updatedAt: z
14
+ .string()
15
+ .datetime()
16
+ .openapi({ example: "2026-05-21T10:15:00.000Z" }),
17
+ }).openapi({
18
+ example: {
19
+ id: "682fd0d7d4a6325d9d45b86f",
20
+ name: "Kitchen Display",
21
+ serialNumber: "nrf-352656106701140",
22
+ status: "online",
23
+ createdAt: "2026-05-21T09:30:00.000Z",
24
+ updatedAt: "2026-05-21T10:15:00.000Z",
25
+ },
12
26
  });
13
27
 
14
28
  export const devicesResponseSchema = deviceResponseSchema.array();
15
29
 
16
30
  export const eventResponseSchema = z.object({
17
- id: z.string(),
18
- deviceId: z.string(),
19
- type: z.string(),
20
- payload: z.record(z.string(), z.any()),
21
- timestamp: z.string(), // ISO timestamp
22
- // ...other event fields...
31
+ id: z.string().openapi({ example: "evt_01HX0000000000000000000000" }),
32
+ deviceId: z.string().openapi({ example: "682fd0d7d4a6325d9d45b86f" }),
33
+ type: z.string().openapi({ example: "state" }),
34
+ payload: z
35
+ .record(z.string(), z.any())
36
+ .openapi({ example: { battery: 87, online: true } }),
37
+ timestamp: z
38
+ .string()
39
+ .datetime()
40
+ .openapi({ example: "2026-05-21T10:15:00.000Z" }),
41
+ }).openapi({
42
+ example: {
43
+ id: "evt_01HX0000000000000000000000",
44
+ deviceId: "682fd0d7d4a6325d9d45b86f",
45
+ type: "state",
46
+ payload: {
47
+ battery: 87,
48
+ online: true,
49
+ },
50
+ timestamp: "2026-05-21T10:15:00.000Z",
51
+ },
23
52
  });
24
53
 
25
54
  export const genericResponseSchema = z
26
55
  .record(z.string(), z.any())
27
- .openapi({ description: "Generic response payload" });
56
+ .openapi({
57
+ description: "Generic response payload",
58
+ example: {
59
+ success: true,
60
+ message: "Operation completed successfully",
61
+ },
62
+ });
28
63
 
29
64
  export const imageResponseSchema = z.object({
30
65
  uuid: z.string(),
@@ -93,4 +128,10 @@ export const resetResponseSchema = z.object({
93
128
  example: true,
94
129
  description: "Indicates if the reset operation was successful",
95
130
  }),
131
+ }).openapi({
132
+ example: {
133
+ message:
134
+ "Reset all Variables and Memory and reboot Device: nrf-352656106701140",
135
+ success: true,
136
+ },
96
137
  });
@@ -26,7 +26,23 @@ export const createEntrySchema = {
26
26
  paper: zObjectId.optional().nullable(),
27
27
  date: z.string().datetime().optional(),
28
28
  })
29
- .openapi({ description: "Create a new device entry" }),
29
+ .openapi({
30
+ description: "Create a new device entry",
31
+ example: {
32
+ name: "Kitchen Display",
33
+ deviceId: "nrf-352656106701140",
34
+ kind: "paper-display",
35
+ organization:
36
+ process.env.SCHEMA_EXAMPLE_ORGANIZATION_ID ||
37
+ "682fd0d7d4a6325d9d45b86e",
38
+ patient: process.env.SCHEMA_EXAMPLE_USER_ID || "682fd0d7d4a6325d9d45b86d",
39
+ paper: process.env.SCHEMA_EXAMPLE_PAPER_ID || null,
40
+ date: "2026-05-21T09:30:00.000Z",
41
+ meta: {
42
+ room: "kitchen",
43
+ },
44
+ },
45
+ }),
30
46
  };
31
47
 
32
48
  export const getUsersSchema = {
@@ -63,7 +79,19 @@ export const updateEntrySchema = {
63
79
  lut: z.string().optional(),
64
80
  sleepTime: z.string().optional(),
65
81
  clearScreen: z.boolean().optional(),
66
- }).openapi({ description: "Fields to update on a device entry" }),
82
+ }).openapi({
83
+ description: "Fields to update on a device entry",
84
+ example: {
85
+ name: "Kitchen Display",
86
+ kind: "paper-display",
87
+ meta: {
88
+ room: "kitchen",
89
+ },
90
+ alarmEnable: 1,
91
+ takeOffsetTime: 15,
92
+ clearScreen: false,
93
+ },
94
+ }),
67
95
  };
68
96
 
69
97
  export const getEventsSchema = {
@@ -88,28 +116,45 @@ export const createCustomerPortalSessionSchema = {
88
116
  params: z.object({
89
117
  deviceId: zObjectId.openapi({ description: "Device ObjectId" }),
90
118
  }),
91
- body: z.object({
92
- domain: z.string().url().openapi({
93
- description: "Domain for return URL",
94
- example: "https://web.wirewire.de",
119
+ body: z
120
+ .object({
121
+ domain: z.string().url().openapi({
122
+ description: "Domain for return URL",
123
+ example: "https://web.wirewire.de",
124
+ }),
125
+ })
126
+ .openapi({
127
+ example: {
128
+ domain: "https://web.wirewire.de",
129
+ },
95
130
  }),
96
- }),
97
131
  };
98
132
  export const createDeviceSchema = {
99
- body: z.object({
100
- kind: z.string().optional(),
101
- patient: zObjectIdFor("patient")
102
- .optional()
103
- .nullable()
104
- .openapi({ description: "Patient ObjectId", example: null }),
105
- paper: zObjectIdFor("paper")
106
- .optional()
107
- .nullable()
108
- .openapi({ description: "Paper ObjectId", example: null }),
109
- organization: zObjectIdFor("organization").openapi({
110
- description: "Organization ObjectId",
133
+ body: z
134
+ .object({
135
+ kind: z.string().optional().openapi({ example: "paper-display" }),
136
+ patient: zObjectIdFor("patient")
137
+ .optional()
138
+ .nullable()
139
+ .openapi({ description: "Patient ObjectId", example: null }),
140
+ paper: zObjectIdFor("paper")
141
+ .optional()
142
+ .nullable()
143
+ .openapi({ description: "Paper ObjectId", example: null }),
144
+ organization: zObjectIdFor("organization").openapi({
145
+ description: "Organization ObjectId",
146
+ }),
147
+ })
148
+ .openapi({
149
+ example: {
150
+ kind: "paper-display",
151
+ patient: process.env.SCHEMA_EXAMPLE_USER_ID || "682fd0d7d4a6325d9d45b86d",
152
+ paper: process.env.SCHEMA_EXAMPLE_PAPER_ID || null,
153
+ organization:
154
+ process.env.SCHEMA_EXAMPLE_ORGANIZATION_ID ||
155
+ "682fd0d7d4a6325d9d45b86e",
156
+ },
111
157
  }),
112
- }),
113
158
  };
114
159
  export const deleteDeviceSchema = zDelete("deviceId");
115
160
  export const getDeviceSchema = zGet("deviceId");
@@ -195,16 +240,40 @@ export const uploadSingleImageFromWebsiteSchema = {};
195
240
  export const updateDeviceSchema = {
196
241
  ...zUpdate("deviceId"),
197
242
  body: zPatchBody({
198
- intake: z.record(z.string(), z.any()).optional(),
199
- meta: z.record(z.string(), z.any()).optional(),
243
+ intake: z
244
+ .record(z.string(), z.any())
245
+ .optional()
246
+ .openapi({ example: { morning: "08:00", evening: "20:00" } }),
247
+ meta: z
248
+ .record(z.string(), z.any())
249
+ .optional()
250
+ .openapi({ example: { room: "kitchen" } }),
200
251
  organization: zObjectId.optional(),
201
252
  patient: zObjectId.optional().nullable(),
202
253
  paper: zObjectId.optional().nullable(),
203
- kind: z.string().optional(),
204
- deviceId: z.string().optional(),
205
- alarmEnable: z.number().int().optional(),
206
- takeOffsetTime: z.number().int().optional(),
207
- iotDevice: z.record(z.string(), z.any()).optional(),
208
- payment: z.record(z.string(), z.any()).optional(),
254
+ kind: z.string().optional().openapi({ example: "paper-display" }),
255
+ deviceId: z.string().optional().openapi({ example: "nrf-352656106701140" }),
256
+ alarmEnable: z.number().int().optional().openapi({ example: 1 }),
257
+ takeOffsetTime: z.number().int().optional().openapi({ example: 15 }),
258
+ iotDevice: z
259
+ .record(z.string(), z.any())
260
+ .optional()
261
+ .openapi({ example: { firmwareVersion: "1.2.3" } }),
262
+ payment: z
263
+ .record(z.string(), z.any())
264
+ .optional()
265
+ .openapi({ example: { status: "active" } }),
266
+ }).openapi({
267
+ example: {
268
+ kind: "paper-display",
269
+ deviceId: "nrf-352656106701140",
270
+ patient: process.env.SCHEMA_EXAMPLE_USER_ID || "682fd0d7d4a6325d9d45b86d",
271
+ paper: process.env.SCHEMA_EXAMPLE_PAPER_ID || null,
272
+ meta: {
273
+ room: "kitchen",
274
+ },
275
+ alarmEnable: 1,
276
+ takeOffsetTime: 15,
277
+ },
209
278
  }),
210
279
  };
package/src/index.ts CHANGED
@@ -26,6 +26,10 @@ export * from "../src/organizations/organizations.controller";
26
26
  export { default as organizationsService } from "../src/organizations/organizations.service";
27
27
  export { default as Organization } from "../src/organizations/organizations.model";
28
28
  export { default as devicesRoute } from "../src/devices/devices.route";
29
+ export {
30
+ createDevicesRoute,
31
+ devicesRouteSpecs,
32
+ } from "../src/devices/devices.route";
29
33
  export { default as devicesService } from "../src/devices/devices.service";
30
34
  export { default as Device } from "../src/devices/devices.model";
31
35
  export * from "../src/devices/devices.validation";
@@ -5,67 +5,151 @@ extendZodWithOpenApi(z);
5
5
 
6
6
  // Represents a device in the system
7
7
  export const iotDeviceResponseSchema = z.object({
8
- deviceId: z.string(),
9
- name: z.string(),
10
- model: z.string().optional(),
11
- firmwareVersion: z.string().optional(),
12
- registeredAt: z.string(), // ISO timestamp
13
- lastSeenAt: z.string().optional(), // ISO timestamp
8
+ deviceId: z.string().openapi({ example: 'nrf-352656106701140' }),
9
+ name: z.string().openapi({ example: 'Kitchen Display' }),
10
+ model: z.string().optional().openapi({ example: 'OpenPaper 7' }),
11
+ firmwareVersion: z.string().optional().openapi({ example: '1.2.3' }),
12
+ registeredAt: z
13
+ .string()
14
+ .datetime()
15
+ .openapi({ example: '2026-05-21T09:30:00.000Z' }),
16
+ lastSeenAt: z
17
+ .string()
18
+ .datetime()
19
+ .optional()
20
+ .openapi({ example: '2026-05-21T10:15:00.000Z' }),
21
+ }).openapi({
22
+ example: {
23
+ deviceId: 'nrf-352656106701140',
24
+ name: 'Kitchen Display',
25
+ model: 'OpenPaper 7',
26
+ firmwareVersion: '1.2.3',
27
+ registeredAt: '2026-05-21T09:30:00.000Z',
28
+ lastSeenAt: '2026-05-21T10:15:00.000Z',
29
+ },
14
30
  });
15
31
 
16
32
  // An event generated by a device
17
33
  export const eventResponseSchema = z.object({
18
- eventId: z.string(),
19
- deviceId: z.string(),
20
- timestamp: z.string(), // ISO timestamp
21
- type: z.string(),
22
- payload: z.any(),
34
+ eventId: z.string().openapi({ example: 'evt_01HX0000000000000000000000' }),
35
+ deviceId: z.string().openapi({ example: 'nrf-352656106701140' }),
36
+ timestamp: z
37
+ .string()
38
+ .datetime()
39
+ .openapi({ example: '2026-05-21T10:15:00.000Z' }),
40
+ type: z.string().openapi({ example: 'state' }),
41
+ payload: z.any().openapi({ example: { battery: 87, online: true } }),
42
+ }).openapi({
43
+ example: {
44
+ eventId: 'evt_01HX0000000000000000000000',
45
+ deviceId: 'nrf-352656106701140',
46
+ timestamp: '2026-05-21T10:15:00.000Z',
47
+ type: 'state',
48
+ payload: {
49
+ battery: 87,
50
+ online: true,
51
+ },
52
+ },
23
53
  });
24
54
 
25
55
  // A single device fetched by criteria
26
56
  export const deviceResponseSchema = z.object({
27
- deviceId: z.string(),
28
- serialNumber: z.string(),
29
- type: z.string(),
30
- owner: z.string(),
31
- registeredAt: z.string(),
57
+ deviceId: z.string().openapi({ example: 'nrf-352656106701140' }),
58
+ serialNumber: z.string().openapi({ example: 'nrf-352656106701140' }),
59
+ type: z.string().openapi({ example: 'paper-display' }),
60
+ owner: z.string().openapi({ example: '682fd0d7d4a6325d9d45b86e' }),
61
+ registeredAt: z
62
+ .string()
63
+ .datetime()
64
+ .openapi({ example: '2026-05-21T09:30:00.000Z' }),
65
+ }).openapi({
66
+ example: {
67
+ deviceId: 'nrf-352656106701140',
68
+ serialNumber: 'nrf-352656106701140',
69
+ type: 'paper-display',
70
+ owner: '682fd0d7d4a6325d9d45b86e',
71
+ registeredAt: '2026-05-21T09:30:00.000Z',
72
+ },
32
73
  });
33
74
 
34
75
  // Shadow alarm settings
35
76
  export const shadowAlarmSchema = z.object({
36
- enabled: z.boolean(),
37
- threshold: z.number(),
38
- mode: z.enum(['auto', 'manual']).optional(),
77
+ enabled: z.boolean().openapi({ example: true }),
78
+ threshold: z.number().openapi({ example: 80 }),
79
+ mode: z.enum(['auto', 'manual']).optional().openapi({ example: 'auto' }),
80
+ }).openapi({
81
+ example: {
82
+ enabled: true,
83
+ threshold: 80,
84
+ mode: 'auto',
85
+ },
39
86
  });
40
87
 
41
88
  // Ping / LED light response
42
89
  export const pingResponseSchema = z.object({
43
- success: z.boolean(),
44
- message: z.string().optional(),
45
- timestamp: z.string(),
90
+ success: z.boolean().openapi({ example: true }),
91
+ message: z.string().optional().openapi({ example: 'Device responded' }),
92
+ timestamp: z
93
+ .string()
94
+ .datetime()
95
+ .openapi({ example: '2026-05-21T10:15:00.000Z' }),
96
+ }).openapi({
97
+ example: {
98
+ success: true,
99
+ message: 'Device responded',
100
+ timestamp: '2026-05-21T10:15:00.000Z',
101
+ },
46
102
  });
47
103
 
48
104
  // Current status of a device
49
105
  export const deviceStatusSchema = z.object({
50
- deviceId: z.string(),
51
- online: z.boolean(),
52
- batteryLevel: z.number().min(0).max(100).optional(),
53
- lastSeenAt: z.string(),
106
+ deviceId: z.string().openapi({ example: 'nrf-352656106701140' }),
107
+ online: z.boolean().openapi({ example: true }),
108
+ batteryLevel: z.number().min(0).max(100).optional().openapi({ example: 87 }),
109
+ lastSeenAt: z
110
+ .string()
111
+ .datetime()
112
+ .openapi({ example: '2026-05-21T10:15:00.000Z' }),
113
+ }).openapi({
114
+ example: {
115
+ deviceId: 'nrf-352656106701140',
116
+ online: true,
117
+ batteryLevel: 87,
118
+ lastSeenAt: '2026-05-21T10:15:00.000Z',
119
+ },
54
120
  });
55
121
 
56
122
  // API status by kind
57
123
  export const apiStatusSchema = z.object({
58
- kind: z.string(),
59
- status: z.enum(['ok', 'degraded', 'down']),
60
- uptimeSeconds: z.number(),
124
+ kind: z.string().openapi({ example: 'iot' }),
125
+ status: z.enum(['ok', 'degraded', 'down']).openapi({ example: 'ok' }),
126
+ uptimeSeconds: z.number().openapi({ example: 86400 }),
127
+ }).openapi({
128
+ example: {
129
+ kind: 'iot',
130
+ status: 'ok',
131
+ uptimeSeconds: 86400,
132
+ },
61
133
  });
62
134
 
63
135
  // Single entry for a device
64
136
  export const entryResponseSchema = z.object({
65
- entryId: z.string(),
66
- deviceId: z.string(),
67
- timestamp: z.string(),
68
- data: z.any(),
137
+ entryId: z.string().openapi({ example: 'entry_01HX0000000000000000000000' }),
138
+ deviceId: z.string().openapi({ example: 'nrf-352656106701140' }),
139
+ timestamp: z
140
+ .string()
141
+ .datetime()
142
+ .openapi({ example: '2026-05-21T10:15:00.000Z' }),
143
+ data: z.any().openapi({ example: { state: 'active' } }),
144
+ }).openapi({
145
+ example: {
146
+ entryId: 'entry_01HX0000000000000000000000',
147
+ deviceId: 'nrf-352656106701140',
148
+ timestamp: '2026-05-21T10:15:00.000Z',
149
+ data: {
150
+ state: 'active',
151
+ },
152
+ },
69
153
  });
70
154
 
71
155
  // Optionally infer TS types