@internetderdinge/api 1.224.2
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/.github/copilot-instructions.md +77 -0
- package/CHANGELOG.md +11 -0
- package/README.md +52 -0
- package/package.json +112 -0
- package/src/accounts/accounts.controller.ts +166 -0
- package/src/accounts/accounts.route.ts +107 -0
- package/src/accounts/accounts.schemas.ts +16 -0
- package/src/accounts/accounts.service.ts +85 -0
- package/src/accounts/accounts.validation.ts +118 -0
- package/src/accounts/auth0.service.ts +226 -0
- package/src/config/config.ts +49 -0
- package/src/config/logger.ts +33 -0
- package/src/config/morgan.ts +22 -0
- package/src/config/passport.cjs +30 -0
- package/src/config/roles.ts +13 -0
- package/src/config/tokens.cjs +10 -0
- package/src/devices/devices.controller.ts +276 -0
- package/src/devices/devices.model.ts +126 -0
- package/src/devices/devices.route.ts +198 -0
- package/src/devices/devices.schemas.ts +94 -0
- package/src/devices/devices.service.ts +320 -0
- package/src/devices/devices.validation.ts +221 -0
- package/src/devicesNotifications/devicesNotifications.controller.ts +72 -0
- package/src/devicesNotifications/devicesNotifications.model.ts +67 -0
- package/src/devicesNotifications/devicesNotifications.route.ts +150 -0
- package/src/devicesNotifications/devicesNotifications.schemas.ts +11 -0
- package/src/devicesNotifications/devicesNotifications.service.ts +222 -0
- package/src/devicesNotifications/devicesNotifications.validation.ts +56 -0
- package/src/email/email.service.ts +609 -0
- package/src/files/upload.service.ts +145 -0
- package/src/i18n/i18n.ts +51 -0
- package/src/i18n/saveMissingLocalJsonBackend.ts +92 -0
- package/src/index.ts +7 -0
- package/src/iotdevice/iotdevice.controller.ts +136 -0
- package/src/iotdevice/iotdevice.model.ts +32 -0
- package/src/iotdevice/iotdevice.route.ts +181 -0
- package/src/iotdevice/iotdevice.schemas.ts +79 -0
- package/src/iotdevice/iotdevice.service.ts +732 -0
- package/src/iotdevice/iotdevice.validation.ts +61 -0
- package/src/middlewares/auth.ts +110 -0
- package/src/middlewares/checkJwt.cjs +19 -0
- package/src/middlewares/error.js.legacy +44 -0
- package/src/middlewares/error.ts +41 -0
- package/src/middlewares/mongooseValidations/ensureSameOrganization.ts +15 -0
- package/src/middlewares/rateLimiter.ts +10 -0
- package/src/middlewares/validate.ts +25 -0
- package/src/middlewares/validateAction.ts +41 -0
- package/src/middlewares/validateAdmin.ts +21 -0
- package/src/middlewares/validateAi.ts +24 -0
- package/src/middlewares/validateCurrentAuthUser.ts +23 -0
- package/src/middlewares/validateCurrentUser.ts +35 -0
- package/src/middlewares/validateDevice.ts +191 -0
- package/src/middlewares/validateDeviceUserOrganization.ts +54 -0
- package/src/middlewares/validateOrganization.ts +109 -0
- package/src/middlewares/validateQuerySearchUserAndOrganization.ts +75 -0
- package/src/middlewares/validateTokens.ts +36 -0
- package/src/middlewares/validateUser.ts +75 -0
- package/src/middlewares/validateZod.ts +54 -0
- package/src/models/plugins/index.ts +7 -0
- package/src/models/plugins/paginate.plugin.ts +145 -0
- package/src/models/plugins/paginateNew.plugin.ts +206 -0
- package/src/models/plugins/simplePopulate.ts +12 -0
- package/src/models/plugins/toJSON.plugin.ts +51 -0
- package/src/organizations/organizations.controller.ts +101 -0
- package/src/organizations/organizations.model.ts +62 -0
- package/src/organizations/organizations.route.ts +119 -0
- package/src/organizations/organizations.schemas.ts +8 -0
- package/src/organizations/organizations.service.ts +85 -0
- package/src/organizations/organizations.validation.ts +76 -0
- package/src/pdf/pdf.controller.ts +18 -0
- package/src/pdf/pdf.route.ts +28 -0
- package/src/pdf/pdf.schemas.ts +7 -0
- package/src/pdf/pdf.service.ts +89 -0
- package/src/pdf/pdf.validation.ts +30 -0
- package/src/tokens/tokens.controller.ts +81 -0
- package/src/tokens/tokens.model.ts +24 -0
- package/src/tokens/tokens.route.ts +66 -0
- package/src/tokens/tokens.schemas.ts +15 -0
- package/src/tokens/tokens.service.ts +46 -0
- package/src/tokens/tokens.validation.ts +13 -0
- package/src/types/routeSpec.ts +1 -0
- package/src/users/users.controller.ts +234 -0
- package/src/users/users.model.ts +89 -0
- package/src/users/users.route.ts +171 -0
- package/src/users/users.schemas.ts +79 -0
- package/src/users/users.service.ts +393 -0
- package/src/users/users.validation.ts +166 -0
- package/src/utils/ApiError.ts +18 -0
- package/src/utils/buildRouterAndDocs.ts +85 -0
- package/src/utils/catchAsync.ts +9 -0
- package/src/utils/comparePapers.service.ts +48 -0
- package/src/utils/filterOptions.ts +37 -0
- package/src/utils/medicationName.ts +12 -0
- package/src/utils/pick.ts +16 -0
- package/src/utils/registerOpenApi.ts +32 -0
- package/src/utils/urlUtils.ts +14 -0
- package/src/utils/userName.ts +27 -0
- package/src/utils/zValidations.ts +89 -0
- package/src/validations/auth.validation.cjs +60 -0
- package/src/validations/custom.validation.ts +26 -0
- package/src/validations/index.cjs +2 -0
- package/tsconfig.json +22 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { extendZodWithOpenApi } from '@asteasolutions/zod-to-openapi';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
extendZodWithOpenApi(z);
|
|
5
|
+
|
|
6
|
+
// Represents a device in the system
|
|
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
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
// An event generated by a device
|
|
17
|
+
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(),
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
// A single device fetched by criteria
|
|
26
|
+
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(),
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
// Shadow alarm settings
|
|
35
|
+
export const shadowAlarmSchema = z.object({
|
|
36
|
+
enabled: z.boolean(),
|
|
37
|
+
threshold: z.number(),
|
|
38
|
+
mode: z.enum(['auto', 'manual']).optional(),
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
// Ping / LED light response
|
|
42
|
+
export const pingResponseSchema = z.object({
|
|
43
|
+
success: z.boolean(),
|
|
44
|
+
message: z.string().optional(),
|
|
45
|
+
timestamp: z.string(),
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
// Current status of a device
|
|
49
|
+
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(),
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
// API status by kind
|
|
57
|
+
export const apiStatusSchema = z.object({
|
|
58
|
+
kind: z.string(),
|
|
59
|
+
status: z.enum(['ok', 'degraded', 'down']),
|
|
60
|
+
uptimeSeconds: z.number(),
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
// Single entry for a device
|
|
64
|
+
export const entryResponseSchema = z.object({
|
|
65
|
+
entryId: z.string(),
|
|
66
|
+
deviceId: z.string(),
|
|
67
|
+
timestamp: z.string(),
|
|
68
|
+
data: z.any(),
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
// Optionally infer TS types
|
|
72
|
+
export type IotDevice = z.infer<typeof iotDeviceResponseSchema>;
|
|
73
|
+
export type Event = z.infer<typeof eventResponseSchema>;
|
|
74
|
+
export type Device = z.infer<typeof deviceResponseSchema>;
|
|
75
|
+
export type ShadowAlarm = z.infer<typeof shadowAlarmSchema>;
|
|
76
|
+
export type PingResponse = z.infer<typeof pingResponseSchema>;
|
|
77
|
+
export type DeviceStatus = z.infer<typeof deviceStatusSchema>;
|
|
78
|
+
export type ApiStatus = z.infer<typeof apiStatusSchema>;
|
|
79
|
+
export type Entry = z.infer<typeof entryResponseSchema>;
|