@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
@@ -9,9 +9,17 @@ export const getDevice = {
9
9
  params: z.object({
10
10
  deviceId: zObjectId.openapi({ description: 'Device ObjectId' }),
11
11
  }),
12
- body: z.object({
13
- deviceId: z.array(zObjectId).openapi({ description: 'Array of device IDs' }),
14
- }),
12
+ body: z
13
+ .object({
14
+ deviceId: z
15
+ .array(zObjectId)
16
+ .openapi({ description: 'Array of device IDs' }),
17
+ })
18
+ .openapi({
19
+ example: {
20
+ deviceId: ['682fd0d7d4a6325d9d45b86f'],
21
+ },
22
+ }),
15
23
  };
16
24
  export const iotDevicesSchema = {
17
25
  ...zPagination,
@@ -30,19 +38,33 @@ export const getEventsSchema = {
30
38
  params: z.object({
31
39
  deviceId: zObjectId.openapi({ description: 'Device ObjectId' }),
32
40
  }),
33
- query: z.object({
34
- DateStart: z
35
- .string()
36
- .datetime()
37
- .openapi({ description: 'Start date (ISO‐string)', example: '2025-05-01T00:00:00Z' })
38
- .optional(),
39
- DateEnd: z
40
- .string()
41
- .datetime()
42
- .openapi({ description: 'End date (ISO‐string)', example: '2025-05-31T23:59:59Z' })
43
- .optional(),
44
- TypeFilter: zTypeFilter.default(''),
45
- }),
41
+ query: z
42
+ .object({
43
+ DateStart: z
44
+ .string()
45
+ .datetime()
46
+ .openapi({
47
+ description: 'Start date (ISO‐string)',
48
+ example: '2026-05-01T00:00:00Z',
49
+ })
50
+ .optional(),
51
+ DateEnd: z
52
+ .string()
53
+ .datetime()
54
+ .openapi({
55
+ description: 'End date (ISO‐string)',
56
+ example: '2026-05-21T23:59:59Z',
57
+ })
58
+ .optional(),
59
+ TypeFilter: zTypeFilter.default(''),
60
+ })
61
+ .openapi({
62
+ example: {
63
+ DateStart: '2026-05-01T00:00:00Z',
64
+ DateEnd: '2026-05-21T23:59:59Z',
65
+ TypeFilter: 'state',
66
+ },
67
+ }),
46
68
  };
47
69
  export const updateEntrySchema = {};
48
70
 
@@ -10,6 +10,15 @@ interface Schema {
10
10
  params?: ZodObject<ZodRawShape>;
11
11
  }
12
12
 
13
+ const createValidationError = (raw: unknown) =>
14
+ new ApiError(
15
+ httpStatus.BAD_REQUEST,
16
+ 'Validation error',
17
+ undefined,
18
+ undefined,
19
+ raw,
20
+ );
21
+
13
22
  export const validateZod = (schema: Schema) => (req: Request, res: Response, next: NextFunction) => {
14
23
  try {
15
24
  schema.body ||= z.object({});
@@ -25,10 +34,7 @@ export const validateZod = (schema: Schema) => (req: Request, res: Response, nex
25
34
 
26
35
  // 2) if any failure, short-circuit
27
36
  if (!result.body.success || !result.query.success || !result.params.success) {
28
- if (process.env.NODE_ENV === 'development') {
29
- return res.status(400).send(result);
30
- }
31
- return next(new ApiError(httpStatus.BAD_REQUEST, 'Validation error'));
37
+ return next(createValidationError(result));
32
38
  }
33
39
 
34
40
  // 3) merge parsed data back in
@@ -39,15 +45,7 @@ export const validateZod = (schema: Schema) => (req: Request, res: Response, nex
39
45
  return next();
40
46
  } catch (err: any) {
41
47
  console.error('Zod validation error:', err);
42
- return next(
43
- new ApiError(
44
- httpStatus.BAD_REQUEST,
45
- 'Validation error',
46
- undefined,
47
- undefined,
48
- process.env.NODE_ENV === 'development' ? err : undefined,
49
- ),
50
- );
48
+ return next(createValidationError(err));
51
49
  }
52
50
  };
53
51
 
@@ -1,8 +1,31 @@
1
- import { z } from 'zod';
1
+ import { z } from "zod";
2
2
 
3
3
  export const organizationResponseSchema = z.object({
4
- id: z.string(),
5
- name: z.string(),
6
- email: z.string().email(),
7
- kind: z.string().optional(),
4
+ id: z
5
+ .string()
6
+ .openapi({ example: "682fd0d7d4a6325d9d45b86e" }),
7
+ name: z
8
+ .string()
9
+ .openapi({ example: "Acme Inc.", description: "Organization name" }),
10
+ email: z
11
+ .string()
12
+ .email()
13
+ .openapi({
14
+ example: "contact@acme.example",
15
+ description: "Primary contact email",
16
+ }),
17
+ kind: z
18
+ .string()
19
+ .optional()
20
+ .openapi({
21
+ example: "private",
22
+ description: "The type or category of the organization",
23
+ }),
24
+ }).openapi({
25
+ example: {
26
+ id: "682fd0d7d4a6325d9d45b86e",
27
+ name: "Acme Inc.",
28
+ email: "contact@acme.example",
29
+ kind: "private",
30
+ },
8
31
  });
@@ -13,20 +13,18 @@ import {
13
13
  extendZodWithOpenApi(z);
14
14
 
15
15
  export const createOrganizationSchema = {
16
- body: z.object({
17
- /* name: z.string().openapi({
18
- example: 'Acme Inc.',
19
- description: 'The name of the organization',
20
- }),
21
- email: z.string().email().openapi({
22
- example: 'contact@acme.com',
23
- description: 'Contact email for the organization',
24
- }), */
25
- kind: z.string().openapi({
26
- example: "private",
27
- description: "The type or category of the organization",
16
+ body: z
17
+ .object({
18
+ kind: z.string().openapi({
19
+ example: "private",
20
+ description: "The type or category of the organization",
21
+ }),
22
+ })
23
+ .openapi({
24
+ example: {
25
+ kind: "private",
26
+ },
28
27
  }),
29
- }),
30
28
  };
31
29
 
32
30
  export const queryOrganizationsSchema = zPagination;
@@ -35,30 +33,44 @@ export const getOrganizationByIdSchema = zGet("organizationId");
35
33
 
36
34
  export const updateOrganizationSchema = {
37
35
  ...zUpdate("organizationId"),
38
- body: z.object({
39
- name: z
40
- .string()
41
- .openapi({
42
- example: "Acme Inc.",
43
- description: "The name of the organization",
44
- })
45
- .optional(),
46
- organization: zObjectId, // Legacy field, to be removed later
47
- kind: z
48
- .string()
49
- .openapi({
50
- example: "private",
51
- description: "The type or category of the organization",
52
- })
53
- .optional(),
54
- meta: z
55
- .record(z.string(), z.any())
56
- .openapi({
57
- example: { key: "value" },
58
- description: "Additional metadata for the entry",
59
- })
60
- .optional(),
61
- }),
36
+ body: z
37
+ .object({
38
+ name: z
39
+ .string()
40
+ .openapi({
41
+ example: "Acme Inc.",
42
+ description: "The name of the organization",
43
+ })
44
+ .optional(),
45
+ organization: zObjectId, // Legacy field, to be removed later
46
+ kind: z
47
+ .string()
48
+ .openapi({
49
+ example: "private",
50
+ description: "The type or category of the organization",
51
+ })
52
+ .optional(),
53
+ meta: z
54
+ .record(z.string(), z.any())
55
+ .openapi({
56
+ example: { billingId: "cus_123", region: "eu" },
57
+ description: "Additional metadata for the entry",
58
+ })
59
+ .optional(),
60
+ })
61
+ .openapi({
62
+ example: {
63
+ name: "Acme Inc.",
64
+ organization:
65
+ process.env.SCHEMA_EXAMPLE_ORGANIZATION_ID ||
66
+ "682fd0d7d4a6325d9d45b86d",
67
+ kind: "private",
68
+ meta: {
69
+ billingId: "cus_123",
70
+ region: "eu",
71
+ },
72
+ },
73
+ }),
62
74
  //...zUpdate('organizationId'),
63
75
  /* body: z.object({
64
76
  meta: z.any,
@@ -1,15 +1,38 @@
1
- import { z } from 'zod';
1
+ import { z } from "zod";
2
2
 
3
3
  export const tokenResponseSchema = z.object({
4
- // unique identifier of the token
5
- tokenId: z.string().uuid(),
6
- // the owning user
7
- userId: z.string().uuid(),
8
- // optional name or description
9
- name: z.string().optional(),
10
- // the token value (never returned after creation in real-world apps)
11
- token: z.string(),
12
- // timestamps
13
- createdAt: z.string().datetime(),
14
- updatedAt: z.string().datetime(),
4
+ tokenId: z
5
+ .string()
6
+ .openapi({
7
+ example: "682fd0d7d4a6325d9d45b872",
8
+ description: "Token ObjectId",
9
+ }),
10
+ userId: z
11
+ .string()
12
+ .openapi({
13
+ example: "682fd0d7d4a6325d9d45b86d",
14
+ description: "Owning user ObjectId",
15
+ }),
16
+ name: z.string().optional().openapi({ example: "Admin integration token" }),
17
+ token: z.string().openapi({
18
+ example: "idt_live_1234567890abcdef",
19
+ description: "Token secret. Usually only returned immediately after creation.",
20
+ }),
21
+ createdAt: z
22
+ .string()
23
+ .datetime()
24
+ .openapi({ example: "2026-05-21T09:30:00.000Z" }),
25
+ updatedAt: z
26
+ .string()
27
+ .datetime()
28
+ .openapi({ example: "2026-05-21T10:15:00.000Z" }),
29
+ }).openapi({
30
+ example: {
31
+ tokenId: "682fd0d7d4a6325d9d45b872",
32
+ userId: "682fd0d7d4a6325d9d45b86d",
33
+ name: "Admin integration token",
34
+ token: "idt_live_1234567890abcdef",
35
+ createdAt: "2026-05-21T09:30:00.000Z",
36
+ updatedAt: "2026-05-21T10:15:00.000Z",
37
+ },
15
38
  });
@@ -3,9 +3,15 @@ import { z } from "zod";
3
3
  import { zGet, zDelete } from "../utils/zValidations.js";
4
4
 
5
5
  export const createTokenSchema = {
6
- body: z.object({
7
- name: z.string().openapi({ example: "my sample token" }),
8
- }),
6
+ body: z
7
+ .object({
8
+ name: z.string().openapi({ example: "Admin integration token" }),
9
+ })
10
+ .openapi({
11
+ example: {
12
+ name: "Admin integration token",
13
+ },
14
+ }),
9
15
  };
10
16
 
11
17
  export const getTokenSchema = zGet("tokenId");
@@ -3,18 +3,37 @@ import { extendZodWithOpenApi } from "@asteasolutions/zod-to-openapi";
3
3
  extendZodWithOpenApi(z);
4
4
 
5
5
  export const createUserResponseSchema = z.object({
6
- id: z.string(),
7
- name: z.string(),
8
- email: z.string(),
6
+ id: z.string().openapi({ example: "682fd0d7d4a6325d9d45b86d" }),
7
+ name: z.string().openapi({ example: "Jane Doe" }),
8
+ email: z.string().email().openapi({ example: "jane.doe@example.com" }),
9
+ }).openapi({
10
+ example: {
11
+ id: "682fd0d7d4a6325d9d45b86d",
12
+ name: "Jane Doe",
13
+ email: "jane.doe@example.com",
14
+ },
9
15
  });
10
16
 
11
17
  export const getUsersResponseSchema = z.array(
12
18
  z.object({
13
- id: z.string(),
14
- name: z.string(),
15
- email: z.string(),
19
+ id: z.string().openapi({ example: "682fd0d7d4a6325d9d45b86d" }),
20
+ name: z.string().openapi({ example: "Jane Doe" }),
21
+ email: z.string().email().openapi({ example: "jane.doe@example.com" }),
16
22
  }),
17
- );
23
+ ).openapi({
24
+ example: [
25
+ {
26
+ id: "682fd0d7d4a6325d9d45b86d",
27
+ name: "Jane Doe",
28
+ email: "jane.doe@example.com",
29
+ },
30
+ {
31
+ id: "682fd0d7d4a6325d9d45b86f",
32
+ name: "John Smith",
33
+ email: "john.smith@example.com",
34
+ },
35
+ ],
36
+ });
18
37
 
19
38
  export const updateUserSchema = z.object({
20
39
  name: z.string().optional(),
@@ -22,11 +41,21 @@ export const updateUserSchema = z.object({
22
41
  });
23
42
 
24
43
  export const updateUserResponseSchema = z.object({
25
- id: z.string(),
26
- name: z.string(),
27
- email: z.string(),
44
+ id: z.string().openapi({ example: "682fd0d7d4a6325d9d45b86d" }),
45
+ name: z.string().openapi({ example: "Jane Doe" }),
46
+ email: z.string().email().openapi({ example: "jane.doe@example.com" }),
47
+ }).openapi({
48
+ example: {
49
+ id: "682fd0d7d4a6325d9d45b86d",
50
+ name: "Jane Doe",
51
+ email: "jane.doe@example.com",
52
+ },
28
53
  });
29
54
 
30
55
  export const deleteUserResponseSchema = z.object({
31
- success: z.boolean(),
56
+ success: z.boolean().openapi({ example: true }),
57
+ }).openapi({
58
+ example: {
59
+ success: true,
60
+ },
32
61
  });
@@ -36,6 +36,10 @@ export const createUserBodyShape = {
36
36
  example: "user@example.com",
37
37
  description: "User email address",
38
38
  }),
39
+ category: z.string().optional().openapi({
40
+ example: "random",
41
+ description: "LEGACY: User category",
42
+ }),
39
43
  timezone: z.string().optional().openapi({
40
44
  example: "Europe/Berlin",
41
45
  description: "IANA timezone string",
@@ -46,7 +50,19 @@ export const createUserBodyShape = {
46
50
  };
47
51
 
48
52
  export const createUserSchema = {
49
- body: z.object(createUserBodyShape),
53
+ body: z.object(createUserBodyShape).openapi({
54
+ example: {
55
+ organization:
56
+ process.env.SCHEMA_EXAMPLE_ORGANIZATION_ID ||
57
+ "682fd0d7d4a6325d9d45b86e",
58
+ email: "user@example.com",
59
+ timezone: "Europe/Berlin",
60
+ role: "user",
61
+ meta: {
62
+ externalId: "crm-123",
63
+ },
64
+ },
65
+ }),
50
66
  };
51
67
 
52
68
  export const createCurrentUserSchema = createUserSchema;
@@ -67,7 +83,10 @@ export const getUserSchema = zGet("userId");
67
83
 
68
84
  export const getCurrentUserSchema = {
69
85
  query: z.object({
70
- organization: zObjectId,
86
+ organization: zObjectId.openapi({
87
+ description: "Organization ObjectId",
88
+ param: { name: "organization", in: "query" },
89
+ }),
71
90
  }),
72
91
  };
73
92
 
@@ -75,6 +94,10 @@ export const updateUserBodyShape = {
75
94
  name: z.string().optional().openapi({ description: "User full name" }),
76
95
  timezone: z.string().optional().openapi({ description: "IANA timezone" }),
77
96
  avatar: z.string().optional().openapi({ description: "Avatar URL" }),
97
+ category: z.string().optional().openapi({
98
+ example: "random",
99
+ description: "LEGACY: User category",
100
+ }),
78
101
  meta: z
79
102
  .object({})
80
103
  .passthrough()
@@ -103,36 +126,80 @@ export const updateUserBodyShape = {
103
126
 
104
127
  export const updateUserSchema = {
105
128
  ...zUpdate("userId"),
106
- body: zPatchBody(updateUserBodyShape),
129
+ body: zPatchBody(updateUserBodyShape).openapi({
130
+ example: {
131
+ name: "Jane Doe",
132
+ timezone: "Europe/Berlin",
133
+ email: "jane.doe@example.com",
134
+ role: "patient",
135
+ meta: {
136
+ carePlan: "standard",
137
+ },
138
+ },
139
+ }),
107
140
  };
108
141
 
109
142
  export const deleteUserSchema = zDelete("userId");
110
143
 
111
144
  export const organizationInviteSchema = {
112
- body: z.object({
113
- organizationId: zObjectId.openapi({ description: "Organization ObjectId" }),
114
- action: z.string().optional().openapi({ description: "Invite action" }),
115
- role: z.string().optional().openapi({ description: "Role on invite" }),
116
- }),
145
+ body: z
146
+ .object({
147
+ organizationId: zObjectId.openapi({
148
+ description: "Organization ObjectId",
149
+ }),
150
+ action: z.string().optional().openapi({ description: "Invite action" }),
151
+ role: z.string().optional().openapi({ description: "Role on invite" }),
152
+ })
153
+ .openapi({
154
+ example: {
155
+ organizationId:
156
+ process.env.SCHEMA_EXAMPLE_ORGANIZATION_ID ||
157
+ "682fd0d7d4a6325d9d45b86e",
158
+ action: "accept",
159
+ role: "user",
160
+ },
161
+ }),
117
162
  };
118
163
 
119
164
  export const updateInviteSchema = {
120
- body: z.object({
121
- organization: zObjectId.openapi({ description: "Organization ObjectId" }),
122
- status: z.enum(["accepted"]).openapi({ description: "Invite status" }),
123
- inviteCode: z
124
- .string()
125
- .nullable()
126
- .optional()
127
- .openapi({ description: "Invite code" }),
128
- }),
165
+ body: z
166
+ .object({
167
+ organization: zObjectId.openapi({ description: "Organization ObjectId" }),
168
+ status: z.enum(["accepted"]).openapi({ description: "Invite status" }),
169
+ inviteCode: z
170
+ .string()
171
+ .nullable()
172
+ .optional()
173
+ .openapi({ description: "Invite code" }),
174
+ })
175
+ .openapi({
176
+ example: {
177
+ organization:
178
+ process.env.SCHEMA_EXAMPLE_ORGANIZATION_ID ||
179
+ "682fd0d7d4a6325d9d45b86e",
180
+ status: "accepted",
181
+ inviteCode: "INVITE-123",
182
+ },
183
+ }),
129
184
  };
130
185
 
131
186
  export const organizationRemoveSchema = {
132
- body: z.object({
133
- userId: zObjectId.openapi({ description: "User ObjectId" }),
134
- organizationId: zObjectId.openapi({ description: "Organization ObjectId" }),
135
- }),
187
+ body: z
188
+ .object({
189
+ userId: zObjectId.openapi({ description: "User ObjectId" }),
190
+ organizationId: zObjectId.openapi({
191
+ description: "Organization ObjectId",
192
+ }),
193
+ })
194
+ .openapi({
195
+ example: {
196
+ userId:
197
+ process.env.SCHEMA_EXAMPLE_USER_ID || "682fd0d7d4a6325d9d45b86d",
198
+ organizationId:
199
+ process.env.SCHEMA_EXAMPLE_ORGANIZATION_ID ||
200
+ "682fd0d7d4a6325d9d45b86e",
201
+ },
202
+ }),
136
203
  };
137
204
 
138
205
  export const updateTimesByIdSchema = {