@internetderdinge/api 1.229.39 → 1.229.41
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/src/accounts/accounts.schemas.js +40 -10
- package/dist/src/accounts/accounts.validation.js +47 -10
- package/dist/src/admin/adminSearch.route.js +4 -0
- package/dist/src/devices/devices.route.js +6 -2
- package/dist/src/devices/devices.schemas.js +54 -14
- package/dist/src/devices/devices.validation.js +80 -13
- package/dist/src/index.js +1 -0
- package/dist/src/iotdevice/iotdevice.schemas.js +117 -33
- package/dist/src/iotdevice/iotdevice.validation.js +27 -5
- package/dist/src/organizations/organizations.schemas.js +28 -5
- package/dist/src/organizations/organizations.validation.js +22 -11
- package/dist/src/tokens/tokens.schemas.js +35 -12
- package/dist/src/tokens/tokens.validation.js +8 -2
- package/dist/src/users/users.schemas.js +40 -11
- package/dist/src/users/users.validation.js +70 -8
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/accounts/accounts.schemas.ts +40 -10
- package/src/accounts/accounts.validation.ts +64 -26
- package/src/admin/adminSearch.route.ts +4 -0
- package/src/devices/devices.route.ts +10 -2
- package/src/devices/devices.schemas.ts +55 -14
- package/src/devices/devices.validation.ts +97 -28
- package/src/index.ts +4 -0
- package/src/iotdevice/iotdevice.schemas.ts +117 -33
- package/src/iotdevice/iotdevice.validation.ts +38 -16
- package/src/organizations/organizations.schemas.ts +28 -5
- package/src/organizations/organizations.validation.ts +49 -37
- package/src/tokens/tokens.schemas.ts +35 -12
- package/src/tokens/tokens.validation.ts +9 -3
- package/src/users/users.schemas.ts +40 -11
- package/src/users/users.validation.ts +88 -21
|
@@ -1,12 +1,42 @@
|
|
|
1
|
-
import { z } from
|
|
1
|
+
import { z } from "zod";
|
|
2
2
|
export const accountResponseSchema = z.object({
|
|
3
|
-
id: z
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
3
|
+
id: z
|
|
4
|
+
.string()
|
|
5
|
+
.openapi({
|
|
6
|
+
example: "auth0|60452f4c0dc85b0062326",
|
|
7
|
+
description: "Authentication provider account ID",
|
|
8
|
+
}),
|
|
9
|
+
email: z.string().email().openapi({ example: "jane.doe@example.com" }),
|
|
10
|
+
firstName: z.string().optional().openapi({ example: "Jane" }),
|
|
11
|
+
lastName: z.string().optional().openapi({ example: "Doe" }),
|
|
12
|
+
organizationId: z
|
|
13
|
+
.string()
|
|
14
|
+
.openapi({
|
|
15
|
+
example: "682fd0d7d4a6325d9d45b86e",
|
|
16
|
+
description: "Organization ObjectId",
|
|
17
|
+
}),
|
|
18
|
+
roles: z
|
|
19
|
+
.array(z.string())
|
|
20
|
+
.openapi({ example: ["admin", "user"], description: "Account roles" }),
|
|
21
|
+
isMfaEnabled: z.boolean().openapi({ example: true }),
|
|
22
|
+
createdAt: z
|
|
23
|
+
.string()
|
|
24
|
+
.datetime()
|
|
25
|
+
.openapi({ example: "2026-05-21T09:30:00.000Z" }),
|
|
26
|
+
updatedAt: z
|
|
27
|
+
.string()
|
|
28
|
+
.datetime()
|
|
29
|
+
.openapi({ example: "2026-05-21T10:15:00.000Z" }),
|
|
30
|
+
}).openapi({
|
|
31
|
+
example: {
|
|
32
|
+
id: "auth0|60452f4c0dc85b0062326",
|
|
33
|
+
email: "jane.doe@example.com",
|
|
34
|
+
firstName: "Jane",
|
|
35
|
+
lastName: "Doe",
|
|
36
|
+
organizationId: "682fd0d7d4a6325d9d45b86e",
|
|
37
|
+
roles: ["admin", "user"],
|
|
38
|
+
isMfaEnabled: true,
|
|
39
|
+
createdAt: "2026-05-21T09:30:00.000Z",
|
|
40
|
+
updatedAt: "2026-05-21T10:15:00.000Z",
|
|
41
|
+
},
|
|
12
42
|
});
|
|
@@ -3,7 +3,8 @@ import { z } from "zod";
|
|
|
3
3
|
import { zPagination, zObjectId, zPatchBody, } from "../utils/zValidations.js";
|
|
4
4
|
extendZodWithOpenApi(z);
|
|
5
5
|
export const createAccountSchema = {
|
|
6
|
-
body: z
|
|
6
|
+
body: z
|
|
7
|
+
.object({
|
|
7
8
|
name: z
|
|
8
9
|
.string()
|
|
9
10
|
.openapi({ example: "Sample Entry", description: "Name of the entry" })
|
|
@@ -18,6 +19,18 @@ export const createAccountSchema = {
|
|
|
18
19
|
description: "Additional metadata for the entry",
|
|
19
20
|
})
|
|
20
21
|
.optional(),
|
|
22
|
+
})
|
|
23
|
+
.openapi({
|
|
24
|
+
example: {
|
|
25
|
+
name: "Sample Entry",
|
|
26
|
+
medication: "682fd0d7d4a6325d9d45b871",
|
|
27
|
+
organization: process.env.SCHEMA_EXAMPLE_ORGANIZATION_ID ||
|
|
28
|
+
"682fd0d7d4a6325d9d45b86e",
|
|
29
|
+
patient: process.env.SCHEMA_EXAMPLE_USER_ID || "682fd0d7d4a6325d9d45b86d",
|
|
30
|
+
meta: {
|
|
31
|
+
source: "manual",
|
|
32
|
+
},
|
|
33
|
+
},
|
|
21
34
|
}),
|
|
22
35
|
};
|
|
23
36
|
export const getUsersSchema = zPagination;
|
|
@@ -49,21 +62,38 @@ export const updateAccountSchema = {
|
|
|
49
62
|
.openapi({ example: "female", description: "Gender" }),
|
|
50
63
|
email: z
|
|
51
64
|
.preprocess((value) => (value === "" ? undefined : value), z.string().email().optional())
|
|
52
|
-
.openapi({
|
|
65
|
+
.openapi({
|
|
66
|
+
example: "jane.doe@example.com",
|
|
67
|
+
description: "User email address",
|
|
68
|
+
}),
|
|
53
69
|
given_name: z
|
|
54
70
|
.string()
|
|
55
71
|
.optional()
|
|
56
|
-
.openapi({ example: "
|
|
72
|
+
.openapi({ example: "Jane", description: "Given name" }),
|
|
57
73
|
family_name: z
|
|
58
74
|
.string()
|
|
59
75
|
.optional()
|
|
60
76
|
.openapi({ example: "Doe", description: "Family name" }),
|
|
61
|
-
debug: z.boolean().optional(),
|
|
62
|
-
demo: z.boolean().optional(),
|
|
77
|
+
debug: z.boolean().optional().openapi({ example: false }),
|
|
78
|
+
demo: z.boolean().optional().openapi({ example: false }),
|
|
63
79
|
notification: z
|
|
64
80
|
.record(z.string(), z.any())
|
|
65
81
|
.optional()
|
|
66
|
-
.openapi({
|
|
82
|
+
.openapi({
|
|
83
|
+
example: { email: true, push: false },
|
|
84
|
+
description: "Notification settings object",
|
|
85
|
+
}),
|
|
86
|
+
}).openapi({
|
|
87
|
+
example: {
|
|
88
|
+
language: "en",
|
|
89
|
+
email: "jane.doe@example.com",
|
|
90
|
+
given_name: "Jane",
|
|
91
|
+
family_name: "Doe",
|
|
92
|
+
notification: {
|
|
93
|
+
email: true,
|
|
94
|
+
push: false,
|
|
95
|
+
},
|
|
96
|
+
},
|
|
67
97
|
}),
|
|
68
98
|
};
|
|
69
99
|
export const deleteEntrySchema = {
|
|
@@ -81,10 +111,17 @@ export const currentAccountMfaEnrollSchema = {
|
|
|
81
111
|
}), */
|
|
82
112
|
};
|
|
83
113
|
export const setDeviceTokenSchema = {
|
|
84
|
-
body: z
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
114
|
+
body: z
|
|
115
|
+
.object({
|
|
116
|
+
token: z.string().openapi({
|
|
117
|
+
example: "ExponentPushToken[xxxxxxxxxxxxxxxxxxxxxx]",
|
|
118
|
+
description: "Device token to set",
|
|
119
|
+
}),
|
|
120
|
+
})
|
|
121
|
+
.openapi({
|
|
122
|
+
example: {
|
|
123
|
+
token: "ExponentPushToken[xxxxxxxxxxxxxxxxxxxxxx]",
|
|
124
|
+
},
|
|
88
125
|
}),
|
|
89
126
|
};
|
|
90
127
|
export const getAvatarSchema = {};
|
|
@@ -13,6 +13,7 @@ export const adminSearchRouteSpecs = [
|
|
|
13
13
|
requestSchema: adminStatsSchema,
|
|
14
14
|
responseSchema: adminStatsResponseSchema,
|
|
15
15
|
handler: getStats,
|
|
16
|
+
privateDocs: true,
|
|
16
17
|
summary: "Get admin stats",
|
|
17
18
|
description: "Returns total counts for organizations, users, and devices.",
|
|
18
19
|
},
|
|
@@ -24,6 +25,7 @@ export const adminSearchRouteSpecs = [
|
|
|
24
25
|
responseSchema: adminSearchResponseSchema,
|
|
25
26
|
handler: searchAdmin,
|
|
26
27
|
summary: "Search organizations, users, and devices",
|
|
28
|
+
privateDocs: true,
|
|
27
29
|
description: "Performs an admin-only global search over organizations, users, and devices.",
|
|
28
30
|
},
|
|
29
31
|
{
|
|
@@ -33,6 +35,7 @@ export const adminSearchRouteSpecs = [
|
|
|
33
35
|
requestSchema: adminIotDevicesSchema,
|
|
34
36
|
responseSchema: adminIotDevicesResponseSchema,
|
|
35
37
|
handler: getIotDevices,
|
|
38
|
+
privateDocs: true,
|
|
36
39
|
summary: "List IoT devices",
|
|
37
40
|
description: "Returns the IoT device status list used for admin device/order sync workflows.",
|
|
38
41
|
},
|
|
@@ -43,6 +46,7 @@ export const adminSearchRouteSpecs = [
|
|
|
43
46
|
requestSchema: adminDevicesSchema,
|
|
44
47
|
responseSchema: adminDevicesResponseSchema,
|
|
45
48
|
handler: getDevices,
|
|
49
|
+
privateDocs: true,
|
|
46
50
|
summary: "List MongoDB devices",
|
|
47
51
|
description: "Returns all device documents from MongoDB for admin sync workflows.",
|
|
48
52
|
},
|
|
@@ -130,6 +130,10 @@ export const devicesRouteSpecs = [
|
|
|
130
130
|
description: "Initiate a remote reboot of the specified device.",
|
|
131
131
|
},
|
|
132
132
|
];
|
|
133
|
-
|
|
134
|
-
|
|
133
|
+
export function createDevicesRoute(options = {}) {
|
|
134
|
+
const router = Router();
|
|
135
|
+
buildRouterAndDocs(router, devicesRouteSpecs, "/devices", ["Devices"], options);
|
|
136
|
+
return router;
|
|
137
|
+
}
|
|
138
|
+
const router = createDevicesRoute();
|
|
135
139
|
export default router;
|
|
@@ -1,26 +1,61 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { zObjectId } from "../utils/zValidations.js";
|
|
3
3
|
export const deviceResponseSchema = z.object({
|
|
4
|
-
id: z.string(),
|
|
5
|
-
name: z.string(),
|
|
6
|
-
serialNumber: z.string().optional(),
|
|
7
|
-
status: z.enum(["online", "offline", "error"]),
|
|
8
|
-
createdAt: z
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
id: z.string().openapi({ example: "682fd0d7d4a6325d9d45b86f" }),
|
|
5
|
+
name: z.string().openapi({ example: "Kitchen Display" }),
|
|
6
|
+
serialNumber: z.string().optional().openapi({ example: "nrf-352656106701140" }),
|
|
7
|
+
status: z.enum(["online", "offline", "error"]).openapi({ example: "online" }),
|
|
8
|
+
createdAt: z
|
|
9
|
+
.string()
|
|
10
|
+
.datetime()
|
|
11
|
+
.openapi({ example: "2026-05-21T09:30:00.000Z" }),
|
|
12
|
+
updatedAt: z
|
|
13
|
+
.string()
|
|
14
|
+
.datetime()
|
|
15
|
+
.openapi({ example: "2026-05-21T10:15:00.000Z" }),
|
|
16
|
+
}).openapi({
|
|
17
|
+
example: {
|
|
18
|
+
id: "682fd0d7d4a6325d9d45b86f",
|
|
19
|
+
name: "Kitchen Display",
|
|
20
|
+
serialNumber: "nrf-352656106701140",
|
|
21
|
+
status: "online",
|
|
22
|
+
createdAt: "2026-05-21T09:30:00.000Z",
|
|
23
|
+
updatedAt: "2026-05-21T10:15:00.000Z",
|
|
24
|
+
},
|
|
11
25
|
});
|
|
12
26
|
export const devicesResponseSchema = deviceResponseSchema.array();
|
|
13
27
|
export const eventResponseSchema = z.object({
|
|
14
|
-
id: z.string(),
|
|
15
|
-
deviceId: z.string(),
|
|
16
|
-
type: z.string(),
|
|
17
|
-
payload: z
|
|
18
|
-
|
|
19
|
-
|
|
28
|
+
id: z.string().openapi({ example: "evt_01HX0000000000000000000000" }),
|
|
29
|
+
deviceId: z.string().openapi({ example: "682fd0d7d4a6325d9d45b86f" }),
|
|
30
|
+
type: z.string().openapi({ example: "state" }),
|
|
31
|
+
payload: z
|
|
32
|
+
.record(z.string(), z.any())
|
|
33
|
+
.openapi({ example: { battery: 87, online: true } }),
|
|
34
|
+
timestamp: z
|
|
35
|
+
.string()
|
|
36
|
+
.datetime()
|
|
37
|
+
.openapi({ example: "2026-05-21T10:15:00.000Z" }),
|
|
38
|
+
}).openapi({
|
|
39
|
+
example: {
|
|
40
|
+
id: "evt_01HX0000000000000000000000",
|
|
41
|
+
deviceId: "682fd0d7d4a6325d9d45b86f",
|
|
42
|
+
type: "state",
|
|
43
|
+
payload: {
|
|
44
|
+
battery: 87,
|
|
45
|
+
online: true,
|
|
46
|
+
},
|
|
47
|
+
timestamp: "2026-05-21T10:15:00.000Z",
|
|
48
|
+
},
|
|
20
49
|
});
|
|
21
50
|
export const genericResponseSchema = z
|
|
22
51
|
.record(z.string(), z.any())
|
|
23
|
-
.openapi({
|
|
52
|
+
.openapi({
|
|
53
|
+
description: "Generic response payload",
|
|
54
|
+
example: {
|
|
55
|
+
success: true,
|
|
56
|
+
message: "Operation completed successfully",
|
|
57
|
+
},
|
|
58
|
+
});
|
|
24
59
|
export const imageResponseSchema = z.object({
|
|
25
60
|
uuid: z.string(),
|
|
26
61
|
deviceId: z.string(),
|
|
@@ -81,4 +116,9 @@ export const resetResponseSchema = z.object({
|
|
|
81
116
|
example: true,
|
|
82
117
|
description: "Indicates if the reset operation was successful",
|
|
83
118
|
}),
|
|
119
|
+
}).openapi({
|
|
120
|
+
example: {
|
|
121
|
+
message: "Reset all Variables and Memory and reboot Device: nrf-352656106701140",
|
|
122
|
+
success: true,
|
|
123
|
+
},
|
|
84
124
|
});
|
|
@@ -14,7 +14,22 @@ export const createEntrySchema = {
|
|
|
14
14
|
paper: zObjectId.optional().nullable(),
|
|
15
15
|
date: z.string().datetime().optional(),
|
|
16
16
|
})
|
|
17
|
-
.openapi({
|
|
17
|
+
.openapi({
|
|
18
|
+
description: "Create a new device entry",
|
|
19
|
+
example: {
|
|
20
|
+
name: "Kitchen Display",
|
|
21
|
+
deviceId: "nrf-352656106701140",
|
|
22
|
+
kind: "paper-display",
|
|
23
|
+
organization: process.env.SCHEMA_EXAMPLE_ORGANIZATION_ID ||
|
|
24
|
+
"682fd0d7d4a6325d9d45b86e",
|
|
25
|
+
patient: process.env.SCHEMA_EXAMPLE_USER_ID || "682fd0d7d4a6325d9d45b86d",
|
|
26
|
+
paper: process.env.SCHEMA_EXAMPLE_PAPER_ID || null,
|
|
27
|
+
date: "2026-05-21T09:30:00.000Z",
|
|
28
|
+
meta: {
|
|
29
|
+
room: "kitchen",
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
}),
|
|
18
33
|
};
|
|
19
34
|
export const getUsersSchema = {
|
|
20
35
|
query: z
|
|
@@ -48,7 +63,19 @@ export const updateEntrySchema = {
|
|
|
48
63
|
lut: z.string().optional(),
|
|
49
64
|
sleepTime: z.string().optional(),
|
|
50
65
|
clearScreen: z.boolean().optional(),
|
|
51
|
-
}).openapi({
|
|
66
|
+
}).openapi({
|
|
67
|
+
description: "Fields to update on a device entry",
|
|
68
|
+
example: {
|
|
69
|
+
name: "Kitchen Display",
|
|
70
|
+
kind: "paper-display",
|
|
71
|
+
meta: {
|
|
72
|
+
room: "kitchen",
|
|
73
|
+
},
|
|
74
|
+
alarmEnable: 1,
|
|
75
|
+
takeOffsetTime: 15,
|
|
76
|
+
clearScreen: false,
|
|
77
|
+
},
|
|
78
|
+
}),
|
|
52
79
|
};
|
|
53
80
|
export const getEventsSchema = {
|
|
54
81
|
params: z.object({
|
|
@@ -70,16 +97,23 @@ export const createCustomerPortalSessionSchema = {
|
|
|
70
97
|
params: z.object({
|
|
71
98
|
deviceId: zObjectId.openapi({ description: "Device ObjectId" }),
|
|
72
99
|
}),
|
|
73
|
-
body: z
|
|
100
|
+
body: z
|
|
101
|
+
.object({
|
|
74
102
|
domain: z.string().url().openapi({
|
|
75
103
|
description: "Domain for return URL",
|
|
76
104
|
example: "https://web.wirewire.de",
|
|
77
105
|
}),
|
|
106
|
+
})
|
|
107
|
+
.openapi({
|
|
108
|
+
example: {
|
|
109
|
+
domain: "https://web.wirewire.de",
|
|
110
|
+
},
|
|
78
111
|
}),
|
|
79
112
|
};
|
|
80
113
|
export const createDeviceSchema = {
|
|
81
|
-
body: z
|
|
82
|
-
|
|
114
|
+
body: z
|
|
115
|
+
.object({
|
|
116
|
+
kind: z.string().optional().openapi({ example: "paper-display" }),
|
|
83
117
|
patient: zObjectIdFor("patient")
|
|
84
118
|
.optional()
|
|
85
119
|
.nullable()
|
|
@@ -91,6 +125,15 @@ export const createDeviceSchema = {
|
|
|
91
125
|
organization: zObjectIdFor("organization").openapi({
|
|
92
126
|
description: "Organization ObjectId",
|
|
93
127
|
}),
|
|
128
|
+
})
|
|
129
|
+
.openapi({
|
|
130
|
+
example: {
|
|
131
|
+
kind: "paper-display",
|
|
132
|
+
patient: process.env.SCHEMA_EXAMPLE_USER_ID || "682fd0d7d4a6325d9d45b86d",
|
|
133
|
+
paper: process.env.SCHEMA_EXAMPLE_PAPER_ID || null,
|
|
134
|
+
organization: process.env.SCHEMA_EXAMPLE_ORGANIZATION_ID ||
|
|
135
|
+
"682fd0d7d4a6325d9d45b86e",
|
|
136
|
+
},
|
|
94
137
|
}),
|
|
95
138
|
};
|
|
96
139
|
export const deleteDeviceSchema = zDelete("deviceId");
|
|
@@ -166,16 +209,40 @@ export const uploadSingleImageFromWebsiteSchema = {};
|
|
|
166
209
|
export const updateDeviceSchema = {
|
|
167
210
|
...zUpdate("deviceId"),
|
|
168
211
|
body: zPatchBody({
|
|
169
|
-
intake: z
|
|
170
|
-
|
|
212
|
+
intake: z
|
|
213
|
+
.record(z.string(), z.any())
|
|
214
|
+
.optional()
|
|
215
|
+
.openapi({ example: { morning: "08:00", evening: "20:00" } }),
|
|
216
|
+
meta: z
|
|
217
|
+
.record(z.string(), z.any())
|
|
218
|
+
.optional()
|
|
219
|
+
.openapi({ example: { room: "kitchen" } }),
|
|
171
220
|
organization: zObjectId.optional(),
|
|
172
221
|
patient: zObjectId.optional().nullable(),
|
|
173
222
|
paper: zObjectId.optional().nullable(),
|
|
174
|
-
kind: z.string().optional(),
|
|
175
|
-
deviceId: z.string().optional(),
|
|
176
|
-
alarmEnable: z.number().int().optional(),
|
|
177
|
-
takeOffsetTime: z.number().int().optional(),
|
|
178
|
-
iotDevice: z
|
|
179
|
-
|
|
223
|
+
kind: z.string().optional().openapi({ example: "paper-display" }),
|
|
224
|
+
deviceId: z.string().optional().openapi({ example: "nrf-352656106701140" }),
|
|
225
|
+
alarmEnable: z.number().int().optional().openapi({ example: 1 }),
|
|
226
|
+
takeOffsetTime: z.number().int().optional().openapi({ example: 15 }),
|
|
227
|
+
iotDevice: z
|
|
228
|
+
.record(z.string(), z.any())
|
|
229
|
+
.optional()
|
|
230
|
+
.openapi({ example: { firmwareVersion: "1.2.3" } }),
|
|
231
|
+
payment: z
|
|
232
|
+
.record(z.string(), z.any())
|
|
233
|
+
.optional()
|
|
234
|
+
.openapi({ example: { status: "active" } }),
|
|
235
|
+
}).openapi({
|
|
236
|
+
example: {
|
|
237
|
+
kind: "paper-display",
|
|
238
|
+
deviceId: "nrf-352656106701140",
|
|
239
|
+
patient: process.env.SCHEMA_EXAMPLE_USER_ID || "682fd0d7d4a6325d9d45b86d",
|
|
240
|
+
paper: process.env.SCHEMA_EXAMPLE_PAPER_ID || null,
|
|
241
|
+
meta: {
|
|
242
|
+
room: "kitchen",
|
|
243
|
+
},
|
|
244
|
+
alarmEnable: 1,
|
|
245
|
+
takeOffsetTime: 15,
|
|
246
|
+
},
|
|
180
247
|
}),
|
|
181
248
|
};
|
package/dist/src/index.js
CHANGED
|
@@ -21,6 +21,7 @@ export * from "../src/organizations/organizations.controller";
|
|
|
21
21
|
export { default as organizationsService } from "../src/organizations/organizations.service";
|
|
22
22
|
export { default as Organization } from "../src/organizations/organizations.model";
|
|
23
23
|
export { default as devicesRoute } from "../src/devices/devices.route";
|
|
24
|
+
export { createDevicesRoute, devicesRouteSpecs, } from "../src/devices/devices.route";
|
|
24
25
|
export { default as devicesService } from "../src/devices/devices.service";
|
|
25
26
|
export { default as Device } from "../src/devices/devices.model";
|
|
26
27
|
export * from "../src/devices/devices.validation";
|
|
@@ -3,58 +3,142 @@ import { z } from 'zod';
|
|
|
3
3
|
extendZodWithOpenApi(z);
|
|
4
4
|
// Represents a device in the system
|
|
5
5
|
export const iotDeviceResponseSchema = z.object({
|
|
6
|
-
deviceId: z.string(),
|
|
7
|
-
name: z.string(),
|
|
8
|
-
model: z.string().optional(),
|
|
9
|
-
firmwareVersion: z.string().optional(),
|
|
10
|
-
registeredAt: z
|
|
11
|
-
|
|
6
|
+
deviceId: z.string().openapi({ example: 'nrf-352656106701140' }),
|
|
7
|
+
name: z.string().openapi({ example: 'Kitchen Display' }),
|
|
8
|
+
model: z.string().optional().openapi({ example: 'OpenPaper 7' }),
|
|
9
|
+
firmwareVersion: z.string().optional().openapi({ example: '1.2.3' }),
|
|
10
|
+
registeredAt: z
|
|
11
|
+
.string()
|
|
12
|
+
.datetime()
|
|
13
|
+
.openapi({ example: '2026-05-21T09:30:00.000Z' }),
|
|
14
|
+
lastSeenAt: z
|
|
15
|
+
.string()
|
|
16
|
+
.datetime()
|
|
17
|
+
.optional()
|
|
18
|
+
.openapi({ example: '2026-05-21T10:15:00.000Z' }),
|
|
19
|
+
}).openapi({
|
|
20
|
+
example: {
|
|
21
|
+
deviceId: 'nrf-352656106701140',
|
|
22
|
+
name: 'Kitchen Display',
|
|
23
|
+
model: 'OpenPaper 7',
|
|
24
|
+
firmwareVersion: '1.2.3',
|
|
25
|
+
registeredAt: '2026-05-21T09:30:00.000Z',
|
|
26
|
+
lastSeenAt: '2026-05-21T10:15:00.000Z',
|
|
27
|
+
},
|
|
12
28
|
});
|
|
13
29
|
// An event generated by a device
|
|
14
30
|
export const eventResponseSchema = z.object({
|
|
15
|
-
eventId: z.string(),
|
|
16
|
-
deviceId: z.string(),
|
|
17
|
-
timestamp: z
|
|
18
|
-
|
|
19
|
-
|
|
31
|
+
eventId: z.string().openapi({ example: 'evt_01HX0000000000000000000000' }),
|
|
32
|
+
deviceId: z.string().openapi({ example: 'nrf-352656106701140' }),
|
|
33
|
+
timestamp: z
|
|
34
|
+
.string()
|
|
35
|
+
.datetime()
|
|
36
|
+
.openapi({ example: '2026-05-21T10:15:00.000Z' }),
|
|
37
|
+
type: z.string().openapi({ example: 'state' }),
|
|
38
|
+
payload: z.any().openapi({ example: { battery: 87, online: true } }),
|
|
39
|
+
}).openapi({
|
|
40
|
+
example: {
|
|
41
|
+
eventId: 'evt_01HX0000000000000000000000',
|
|
42
|
+
deviceId: 'nrf-352656106701140',
|
|
43
|
+
timestamp: '2026-05-21T10:15:00.000Z',
|
|
44
|
+
type: 'state',
|
|
45
|
+
payload: {
|
|
46
|
+
battery: 87,
|
|
47
|
+
online: true,
|
|
48
|
+
},
|
|
49
|
+
},
|
|
20
50
|
});
|
|
21
51
|
// A single device fetched by criteria
|
|
22
52
|
export const deviceResponseSchema = z.object({
|
|
23
|
-
deviceId: z.string(),
|
|
24
|
-
serialNumber: z.string(),
|
|
25
|
-
type: z.string(),
|
|
26
|
-
owner: z.string(),
|
|
27
|
-
registeredAt: z
|
|
53
|
+
deviceId: z.string().openapi({ example: 'nrf-352656106701140' }),
|
|
54
|
+
serialNumber: z.string().openapi({ example: 'nrf-352656106701140' }),
|
|
55
|
+
type: z.string().openapi({ example: 'paper-display' }),
|
|
56
|
+
owner: z.string().openapi({ example: '682fd0d7d4a6325d9d45b86e' }),
|
|
57
|
+
registeredAt: z
|
|
58
|
+
.string()
|
|
59
|
+
.datetime()
|
|
60
|
+
.openapi({ example: '2026-05-21T09:30:00.000Z' }),
|
|
61
|
+
}).openapi({
|
|
62
|
+
example: {
|
|
63
|
+
deviceId: 'nrf-352656106701140',
|
|
64
|
+
serialNumber: 'nrf-352656106701140',
|
|
65
|
+
type: 'paper-display',
|
|
66
|
+
owner: '682fd0d7d4a6325d9d45b86e',
|
|
67
|
+
registeredAt: '2026-05-21T09:30:00.000Z',
|
|
68
|
+
},
|
|
28
69
|
});
|
|
29
70
|
// Shadow alarm settings
|
|
30
71
|
export const shadowAlarmSchema = z.object({
|
|
31
|
-
enabled: z.boolean(),
|
|
32
|
-
threshold: z.number(),
|
|
33
|
-
mode: z.enum(['auto', 'manual']).optional(),
|
|
72
|
+
enabled: z.boolean().openapi({ example: true }),
|
|
73
|
+
threshold: z.number().openapi({ example: 80 }),
|
|
74
|
+
mode: z.enum(['auto', 'manual']).optional().openapi({ example: 'auto' }),
|
|
75
|
+
}).openapi({
|
|
76
|
+
example: {
|
|
77
|
+
enabled: true,
|
|
78
|
+
threshold: 80,
|
|
79
|
+
mode: 'auto',
|
|
80
|
+
},
|
|
34
81
|
});
|
|
35
82
|
// Ping / LED light response
|
|
36
83
|
export const pingResponseSchema = z.object({
|
|
37
|
-
success: z.boolean(),
|
|
38
|
-
message: z.string().optional(),
|
|
39
|
-
timestamp: z
|
|
84
|
+
success: z.boolean().openapi({ example: true }),
|
|
85
|
+
message: z.string().optional().openapi({ example: 'Device responded' }),
|
|
86
|
+
timestamp: z
|
|
87
|
+
.string()
|
|
88
|
+
.datetime()
|
|
89
|
+
.openapi({ example: '2026-05-21T10:15:00.000Z' }),
|
|
90
|
+
}).openapi({
|
|
91
|
+
example: {
|
|
92
|
+
success: true,
|
|
93
|
+
message: 'Device responded',
|
|
94
|
+
timestamp: '2026-05-21T10:15:00.000Z',
|
|
95
|
+
},
|
|
40
96
|
});
|
|
41
97
|
// Current status of a device
|
|
42
98
|
export const deviceStatusSchema = z.object({
|
|
43
|
-
deviceId: z.string(),
|
|
44
|
-
online: z.boolean(),
|
|
45
|
-
batteryLevel: z.number().min(0).max(100).optional(),
|
|
46
|
-
lastSeenAt: z
|
|
99
|
+
deviceId: z.string().openapi({ example: 'nrf-352656106701140' }),
|
|
100
|
+
online: z.boolean().openapi({ example: true }),
|
|
101
|
+
batteryLevel: z.number().min(0).max(100).optional().openapi({ example: 87 }),
|
|
102
|
+
lastSeenAt: z
|
|
103
|
+
.string()
|
|
104
|
+
.datetime()
|
|
105
|
+
.openapi({ example: '2026-05-21T10:15:00.000Z' }),
|
|
106
|
+
}).openapi({
|
|
107
|
+
example: {
|
|
108
|
+
deviceId: 'nrf-352656106701140',
|
|
109
|
+
online: true,
|
|
110
|
+
batteryLevel: 87,
|
|
111
|
+
lastSeenAt: '2026-05-21T10:15:00.000Z',
|
|
112
|
+
},
|
|
47
113
|
});
|
|
48
114
|
// API status by kind
|
|
49
115
|
export const apiStatusSchema = z.object({
|
|
50
|
-
kind: z.string(),
|
|
51
|
-
status: z.enum(['ok', 'degraded', 'down']),
|
|
52
|
-
uptimeSeconds: z.number(),
|
|
116
|
+
kind: z.string().openapi({ example: 'iot' }),
|
|
117
|
+
status: z.enum(['ok', 'degraded', 'down']).openapi({ example: 'ok' }),
|
|
118
|
+
uptimeSeconds: z.number().openapi({ example: 86400 }),
|
|
119
|
+
}).openapi({
|
|
120
|
+
example: {
|
|
121
|
+
kind: 'iot',
|
|
122
|
+
status: 'ok',
|
|
123
|
+
uptimeSeconds: 86400,
|
|
124
|
+
},
|
|
53
125
|
});
|
|
54
126
|
// Single entry for a device
|
|
55
127
|
export const entryResponseSchema = z.object({
|
|
56
|
-
entryId: z.string(),
|
|
57
|
-
deviceId: z.string(),
|
|
58
|
-
timestamp: z
|
|
59
|
-
|
|
128
|
+
entryId: z.string().openapi({ example: 'entry_01HX0000000000000000000000' }),
|
|
129
|
+
deviceId: z.string().openapi({ example: 'nrf-352656106701140' }),
|
|
130
|
+
timestamp: z
|
|
131
|
+
.string()
|
|
132
|
+
.datetime()
|
|
133
|
+
.openapi({ example: '2026-05-21T10:15:00.000Z' }),
|
|
134
|
+
data: z.any().openapi({ example: { state: 'active' } }),
|
|
135
|
+
}).openapi({
|
|
136
|
+
example: {
|
|
137
|
+
entryId: 'entry_01HX0000000000000000000000',
|
|
138
|
+
deviceId: 'nrf-352656106701140',
|
|
139
|
+
timestamp: '2026-05-21T10:15:00.000Z',
|
|
140
|
+
data: {
|
|
141
|
+
state: 'active',
|
|
142
|
+
},
|
|
143
|
+
},
|
|
60
144
|
});
|
|
@@ -6,8 +6,16 @@ export const getDevice = {
|
|
|
6
6
|
params: z.object({
|
|
7
7
|
deviceId: zObjectId.openapi({ description: 'Device ObjectId' }),
|
|
8
8
|
}),
|
|
9
|
-
body: z
|
|
10
|
-
|
|
9
|
+
body: z
|
|
10
|
+
.object({
|
|
11
|
+
deviceId: z
|
|
12
|
+
.array(zObjectId)
|
|
13
|
+
.openapi({ description: 'Array of device IDs' }),
|
|
14
|
+
})
|
|
15
|
+
.openapi({
|
|
16
|
+
example: {
|
|
17
|
+
deviceId: ['682fd0d7d4a6325d9d45b86f'],
|
|
18
|
+
},
|
|
11
19
|
}),
|
|
12
20
|
};
|
|
13
21
|
export const iotDevicesSchema = {
|
|
@@ -26,18 +34,32 @@ export const getEventsSchema = {
|
|
|
26
34
|
params: z.object({
|
|
27
35
|
deviceId: zObjectId.openapi({ description: 'Device ObjectId' }),
|
|
28
36
|
}),
|
|
29
|
-
query: z
|
|
37
|
+
query: z
|
|
38
|
+
.object({
|
|
30
39
|
DateStart: z
|
|
31
40
|
.string()
|
|
32
41
|
.datetime()
|
|
33
|
-
.openapi({
|
|
42
|
+
.openapi({
|
|
43
|
+
description: 'Start date (ISO‐string)',
|
|
44
|
+
example: '2026-05-01T00:00:00Z',
|
|
45
|
+
})
|
|
34
46
|
.optional(),
|
|
35
47
|
DateEnd: z
|
|
36
48
|
.string()
|
|
37
49
|
.datetime()
|
|
38
|
-
.openapi({
|
|
50
|
+
.openapi({
|
|
51
|
+
description: 'End date (ISO‐string)',
|
|
52
|
+
example: '2026-05-21T23:59:59Z',
|
|
53
|
+
})
|
|
39
54
|
.optional(),
|
|
40
55
|
TypeFilter: zTypeFilter.default(''),
|
|
56
|
+
})
|
|
57
|
+
.openapi({
|
|
58
|
+
example: {
|
|
59
|
+
DateStart: '2026-05-01T00:00:00Z',
|
|
60
|
+
DateEnd: '2026-05-21T23:59:59Z',
|
|
61
|
+
TypeFilter: 'state',
|
|
62
|
+
},
|
|
41
63
|
}),
|
|
42
64
|
};
|
|
43
65
|
export const updateEntrySchema = {};
|