@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.
Files changed (102) hide show
  1. package/.github/copilot-instructions.md +77 -0
  2. package/CHANGELOG.md +11 -0
  3. package/README.md +52 -0
  4. package/package.json +112 -0
  5. package/src/accounts/accounts.controller.ts +166 -0
  6. package/src/accounts/accounts.route.ts +107 -0
  7. package/src/accounts/accounts.schemas.ts +16 -0
  8. package/src/accounts/accounts.service.ts +85 -0
  9. package/src/accounts/accounts.validation.ts +118 -0
  10. package/src/accounts/auth0.service.ts +226 -0
  11. package/src/config/config.ts +49 -0
  12. package/src/config/logger.ts +33 -0
  13. package/src/config/morgan.ts +22 -0
  14. package/src/config/passport.cjs +30 -0
  15. package/src/config/roles.ts +13 -0
  16. package/src/config/tokens.cjs +10 -0
  17. package/src/devices/devices.controller.ts +276 -0
  18. package/src/devices/devices.model.ts +126 -0
  19. package/src/devices/devices.route.ts +198 -0
  20. package/src/devices/devices.schemas.ts +94 -0
  21. package/src/devices/devices.service.ts +320 -0
  22. package/src/devices/devices.validation.ts +221 -0
  23. package/src/devicesNotifications/devicesNotifications.controller.ts +72 -0
  24. package/src/devicesNotifications/devicesNotifications.model.ts +67 -0
  25. package/src/devicesNotifications/devicesNotifications.route.ts +150 -0
  26. package/src/devicesNotifications/devicesNotifications.schemas.ts +11 -0
  27. package/src/devicesNotifications/devicesNotifications.service.ts +222 -0
  28. package/src/devicesNotifications/devicesNotifications.validation.ts +56 -0
  29. package/src/email/email.service.ts +609 -0
  30. package/src/files/upload.service.ts +145 -0
  31. package/src/i18n/i18n.ts +51 -0
  32. package/src/i18n/saveMissingLocalJsonBackend.ts +92 -0
  33. package/src/index.ts +7 -0
  34. package/src/iotdevice/iotdevice.controller.ts +136 -0
  35. package/src/iotdevice/iotdevice.model.ts +32 -0
  36. package/src/iotdevice/iotdevice.route.ts +181 -0
  37. package/src/iotdevice/iotdevice.schemas.ts +79 -0
  38. package/src/iotdevice/iotdevice.service.ts +732 -0
  39. package/src/iotdevice/iotdevice.validation.ts +61 -0
  40. package/src/middlewares/auth.ts +110 -0
  41. package/src/middlewares/checkJwt.cjs +19 -0
  42. package/src/middlewares/error.js.legacy +44 -0
  43. package/src/middlewares/error.ts +41 -0
  44. package/src/middlewares/mongooseValidations/ensureSameOrganization.ts +15 -0
  45. package/src/middlewares/rateLimiter.ts +10 -0
  46. package/src/middlewares/validate.ts +25 -0
  47. package/src/middlewares/validateAction.ts +41 -0
  48. package/src/middlewares/validateAdmin.ts +21 -0
  49. package/src/middlewares/validateAi.ts +24 -0
  50. package/src/middlewares/validateCurrentAuthUser.ts +23 -0
  51. package/src/middlewares/validateCurrentUser.ts +35 -0
  52. package/src/middlewares/validateDevice.ts +191 -0
  53. package/src/middlewares/validateDeviceUserOrganization.ts +54 -0
  54. package/src/middlewares/validateOrganization.ts +109 -0
  55. package/src/middlewares/validateQuerySearchUserAndOrganization.ts +75 -0
  56. package/src/middlewares/validateTokens.ts +36 -0
  57. package/src/middlewares/validateUser.ts +75 -0
  58. package/src/middlewares/validateZod.ts +54 -0
  59. package/src/models/plugins/index.ts +7 -0
  60. package/src/models/plugins/paginate.plugin.ts +145 -0
  61. package/src/models/plugins/paginateNew.plugin.ts +206 -0
  62. package/src/models/plugins/simplePopulate.ts +12 -0
  63. package/src/models/plugins/toJSON.plugin.ts +51 -0
  64. package/src/organizations/organizations.controller.ts +101 -0
  65. package/src/organizations/organizations.model.ts +62 -0
  66. package/src/organizations/organizations.route.ts +119 -0
  67. package/src/organizations/organizations.schemas.ts +8 -0
  68. package/src/organizations/organizations.service.ts +85 -0
  69. package/src/organizations/organizations.validation.ts +76 -0
  70. package/src/pdf/pdf.controller.ts +18 -0
  71. package/src/pdf/pdf.route.ts +28 -0
  72. package/src/pdf/pdf.schemas.ts +7 -0
  73. package/src/pdf/pdf.service.ts +89 -0
  74. package/src/pdf/pdf.validation.ts +30 -0
  75. package/src/tokens/tokens.controller.ts +81 -0
  76. package/src/tokens/tokens.model.ts +24 -0
  77. package/src/tokens/tokens.route.ts +66 -0
  78. package/src/tokens/tokens.schemas.ts +15 -0
  79. package/src/tokens/tokens.service.ts +46 -0
  80. package/src/tokens/tokens.validation.ts +13 -0
  81. package/src/types/routeSpec.ts +1 -0
  82. package/src/users/users.controller.ts +234 -0
  83. package/src/users/users.model.ts +89 -0
  84. package/src/users/users.route.ts +171 -0
  85. package/src/users/users.schemas.ts +79 -0
  86. package/src/users/users.service.ts +393 -0
  87. package/src/users/users.validation.ts +166 -0
  88. package/src/utils/ApiError.ts +18 -0
  89. package/src/utils/buildRouterAndDocs.ts +85 -0
  90. package/src/utils/catchAsync.ts +9 -0
  91. package/src/utils/comparePapers.service.ts +48 -0
  92. package/src/utils/filterOptions.ts +37 -0
  93. package/src/utils/medicationName.ts +12 -0
  94. package/src/utils/pick.ts +16 -0
  95. package/src/utils/registerOpenApi.ts +32 -0
  96. package/src/utils/urlUtils.ts +14 -0
  97. package/src/utils/userName.ts +27 -0
  98. package/src/utils/zValidations.ts +89 -0
  99. package/src/validations/auth.validation.cjs +60 -0
  100. package/src/validations/custom.validation.ts +26 -0
  101. package/src/validations/index.cjs +2 -0
  102. 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>;