@internetderdinge/api 1.229.1 → 1.229.3
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.service.js +4 -4
- package/dist/src/accounts/accounts.validation.js +2 -2
- package/dist/src/accounts/auth0.service.js +12 -13
- package/dist/src/devices/devices.schemas.js +2 -2
- package/dist/src/devices/devices.validation.js +9 -9
- package/dist/src/middlewares/validateZod.js +1 -1
- package/dist/src/organizations/organizations.validation.js +1 -1
- package/dist/src/tokens/tokens.model.js +1 -2
- package/dist/src/utils/buildRouterAndDocs.js +0 -1
- package/dist/src/utils/registerOpenApi.js +62 -23
- package/dist/src/utils/zValidations.js +22 -3
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +93 -86
- package/scripts/release-and-sync-paperless.mjs +3 -1
- package/src/accounts/accounts.service.ts +4 -4
- package/src/accounts/accounts.validation.ts +2 -2
- package/src/accounts/auth0.service.ts +12 -12
- package/src/devices/devices.schemas.ts +2 -2
- package/src/devices/devices.validation.ts +9 -10
- package/src/middlewares/validateZod.ts +5 -5
- package/src/organizations/organizations.validation.ts +1 -1
- package/src/utils/buildRouterAndDocs.ts +0 -2
- package/src/utils/registerOpenApi.ts +75 -24
- package/src/utils/zValidations.ts +22 -3
|
@@ -6,7 +6,7 @@ import { auth0, mfaDisableAccount, mfaEnrollAccount } from "./auth0.service.js";
|
|
|
6
6
|
* @returns {Promise<Stock>}
|
|
7
7
|
*/
|
|
8
8
|
export const getAccountById = async (id) => {
|
|
9
|
-
return auth0.users.get(
|
|
9
|
+
return auth0.users.get(id);
|
|
10
10
|
};
|
|
11
11
|
/**
|
|
12
12
|
* Get user by email
|
|
@@ -39,20 +39,20 @@ export const mfaDisable = async (userId) => {
|
|
|
39
39
|
*/
|
|
40
40
|
export const updateMetaDataById = async (id, updateBody) => {
|
|
41
41
|
// now use the generic update and pass app_metadata
|
|
42
|
-
return auth0.users.update(
|
|
42
|
+
return auth0.users.update(id, { app_metadata: updateBody });
|
|
43
43
|
};
|
|
44
44
|
/**
|
|
45
45
|
* Update user by id
|
|
46
46
|
*/
|
|
47
47
|
export const updateUserById = async (id, updateBody) => {
|
|
48
48
|
// switch to the v3 ManagementClient users.update
|
|
49
|
-
return auth0.users.update(
|
|
49
|
+
return auth0.users.update(id, updateBody);
|
|
50
50
|
};
|
|
51
51
|
/**
|
|
52
52
|
* Delete user by id
|
|
53
53
|
*/
|
|
54
54
|
export const deleteById = async (userId) => {
|
|
55
|
-
return auth0.users.delete(
|
|
55
|
+
return auth0.users.delete(userId);
|
|
56
56
|
};
|
|
57
57
|
export default {
|
|
58
58
|
getAccountById,
|
|
@@ -12,7 +12,7 @@ export const createAccountSchema = {
|
|
|
12
12
|
organization: zObjectId.openapi({ description: "Organization ObjectId" }),
|
|
13
13
|
patient: zObjectId.openapi({ description: "Patient ObjectId" }),
|
|
14
14
|
meta: z
|
|
15
|
-
.record(z.any())
|
|
15
|
+
.record(z.string(), z.any())
|
|
16
16
|
.openapi({
|
|
17
17
|
example: { key: "value" },
|
|
18
18
|
description: "Additional metadata for the entry",
|
|
@@ -67,7 +67,7 @@ export const updateAccountSchema = {
|
|
|
67
67
|
debug: z.boolean().optional(),
|
|
68
68
|
demo: z.boolean().optional(),
|
|
69
69
|
notification: z
|
|
70
|
-
.record(z.any())
|
|
70
|
+
.record(z.string(), z.any())
|
|
71
71
|
.optional()
|
|
72
72
|
.openapi({ description: "Notification settings object" }),
|
|
73
73
|
}),
|
|
@@ -139,42 +139,41 @@ export const auth0 = new ManagementClient({
|
|
|
139
139
|
token: getAuth0ManagementToken,
|
|
140
140
|
});
|
|
141
141
|
export const getUserIdByEmail = async (email) => {
|
|
142
|
-
|
|
143
|
-
return auth0.usersByEmail.getByEmail({ email });
|
|
142
|
+
return auth0.users.listUsersByEmail({ email });
|
|
144
143
|
};
|
|
145
144
|
export const sendVerificationEmail = async (userID) => {
|
|
146
|
-
return auth0.
|
|
145
|
+
return auth0.tickets.verifyEmail({ user_id: userID });
|
|
147
146
|
};
|
|
148
147
|
export const getUserById = async (userId) => {
|
|
149
|
-
return auth0.users.get(
|
|
148
|
+
return auth0.users.get(userId);
|
|
150
149
|
};
|
|
151
150
|
export const avatar = async (userId) => {
|
|
152
|
-
return auth0.users.get(
|
|
151
|
+
return auth0.users.get(userId);
|
|
153
152
|
};
|
|
154
153
|
export const mfaEnrollAccount = async (userId, mfaToken) => {
|
|
155
|
-
const ticketResponse = await auth0.guardian.
|
|
154
|
+
const ticketResponse = await auth0.guardian.enrollments.createTicket({
|
|
156
155
|
user_id: userId,
|
|
157
156
|
send_mail: false,
|
|
158
157
|
});
|
|
159
158
|
return ticketResponse;
|
|
160
159
|
};
|
|
161
160
|
export const mfaDisableAccount = async (userId) => {
|
|
162
|
-
await auth0.users.
|
|
161
|
+
await auth0.users.authenticationMethods.deleteAll(userId);
|
|
163
162
|
return { success: true };
|
|
164
163
|
};
|
|
165
164
|
export const getUsersByIds = async (postIDs) => {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
});
|
|
165
|
+
const userIds = postIDs.filter(Boolean);
|
|
166
|
+
if (!userIds.length)
|
|
167
|
+
return [];
|
|
168
|
+
const q = userIds.map((id) => `user_id:"${id}"`).join(" OR ");
|
|
171
169
|
const params = {
|
|
172
170
|
search_engine: "v3",
|
|
173
171
|
q,
|
|
174
172
|
per_page: 100,
|
|
175
173
|
page: 0,
|
|
176
174
|
};
|
|
177
|
-
|
|
175
|
+
const page = await auth0.users.list(params);
|
|
176
|
+
return page.data || [];
|
|
178
177
|
};
|
|
179
178
|
export default {
|
|
180
179
|
auth0,
|
|
@@ -14,12 +14,12 @@ export const eventResponseSchema = z.object({
|
|
|
14
14
|
id: z.string(),
|
|
15
15
|
deviceId: z.string(),
|
|
16
16
|
type: z.string(),
|
|
17
|
-
payload: z.record(z.any()),
|
|
17
|
+
payload: z.record(z.string(), z.any()),
|
|
18
18
|
timestamp: z.string(), // ISO timestamp
|
|
19
19
|
// ...other event fields...
|
|
20
20
|
});
|
|
21
21
|
export const genericResponseSchema = z
|
|
22
|
-
.record(z.any())
|
|
22
|
+
.record(z.string(), z.any())
|
|
23
23
|
.openapi({ description: "Generic response payload" });
|
|
24
24
|
export const imageResponseSchema = z.object({
|
|
25
25
|
uuid: z.string(),
|
|
@@ -8,7 +8,7 @@ export const createEntrySchema = {
|
|
|
8
8
|
name: z.string().optional(),
|
|
9
9
|
deviceId: z.string().optional(),
|
|
10
10
|
kind: z.string().optional(),
|
|
11
|
-
meta: z.record(z.any()).optional(),
|
|
11
|
+
meta: z.record(z.string(), z.any()).optional(),
|
|
12
12
|
organization: zObjectId,
|
|
13
13
|
patient: zObjectId.optional(),
|
|
14
14
|
paper: zObjectId.optional().nullable(),
|
|
@@ -37,14 +37,14 @@ export const updateEntrySchema = {
|
|
|
37
37
|
organization: zObjectId.optional(),
|
|
38
38
|
patient: zObjectId.optional().nullable(),
|
|
39
39
|
paper: zObjectId.optional().nullable(),
|
|
40
|
-
meta: z.record(z.any()).optional(),
|
|
41
|
-
iotDevice: z.record(z.any()).optional(),
|
|
40
|
+
meta: z.record(z.string(), z.any()).optional(),
|
|
41
|
+
iotDevice: z.record(z.string(), z.any()).optional(),
|
|
42
42
|
shadow: z.union([z.string(), z.number()]).optional(),
|
|
43
43
|
alarmEnable: z.number().int().optional(),
|
|
44
44
|
takeOffsetTime: z.number().int().optional(),
|
|
45
45
|
updatedAt: z.string().datetime().optional(),
|
|
46
46
|
createdAt: z.string().datetime().optional(),
|
|
47
|
-
payment: z.record(z.any()).optional(),
|
|
47
|
+
payment: z.record(z.string(), z.any()).optional(),
|
|
48
48
|
lut: z.string().optional(),
|
|
49
49
|
sleepTime: z.string().optional(),
|
|
50
50
|
clearScreen: z.boolean().optional(),
|
|
@@ -212,8 +212,8 @@ export const uploadSingleImageFromWebsiteSchema = {};
|
|
|
212
212
|
export const updateDeviceSchema = {
|
|
213
213
|
...zUpdate("deviceId"),
|
|
214
214
|
body: zPatchBody({
|
|
215
|
-
intake: z.record(z.any()).optional(),
|
|
216
|
-
meta: z.record(z.any()).optional(),
|
|
215
|
+
intake: z.record(z.string(), z.any()).optional(),
|
|
216
|
+
meta: z.record(z.string(), z.any()).optional(),
|
|
217
217
|
organization: zObjectId.optional(),
|
|
218
218
|
patient: zObjectId.optional().nullable(),
|
|
219
219
|
paper: zObjectId.optional().nullable(),
|
|
@@ -221,8 +221,8 @@ export const updateDeviceSchema = {
|
|
|
221
221
|
deviceId: z.string().optional(),
|
|
222
222
|
alarmEnable: z.number().int().optional(),
|
|
223
223
|
takeOffsetTime: z.number().int().optional(),
|
|
224
|
-
iotDevice: z.record(z.any()).optional(),
|
|
225
|
-
payment: z.record(z.any()).optional(),
|
|
224
|
+
iotDevice: z.record(z.string(), z.any()).optional(),
|
|
225
|
+
payment: z.record(z.string(), z.any()).optional(),
|
|
226
226
|
}),
|
|
227
227
|
};
|
|
228
228
|
export const updateSingleImageMetaSchema = {
|
|
@@ -233,7 +233,7 @@ export const updateSingleImageMetaSchema = {
|
|
|
233
233
|
}),
|
|
234
234
|
body: z
|
|
235
235
|
.object({
|
|
236
|
-
meta: z.record(z.any()).optional(),
|
|
236
|
+
meta: z.record(z.string(), z.any()).optional(),
|
|
237
237
|
})
|
|
238
238
|
.openapi({ description: "Image metadata updates" }),
|
|
239
239
|
};
|
|
@@ -13,6 +13,5 @@ const tokenSchema = new mongoose.Schema({
|
|
|
13
13
|
});
|
|
14
14
|
tokenSchema.plugin(toJSON, true);
|
|
15
15
|
tokenSchema.plugin(paginate);
|
|
16
|
-
const Token = mongoose.models.Token ||
|
|
17
|
-
mongoose.model("Token", tokenSchema);
|
|
16
|
+
const Token = mongoose.models.Token || mongoose.model("Token", tokenSchema);
|
|
18
17
|
export default Token;
|
|
@@ -1,28 +1,67 @@
|
|
|
1
|
-
import { OpenAPIRegistry } from
|
|
1
|
+
import { OpenAPIRegistry } from "@asteasolutions/zod-to-openapi";
|
|
2
|
+
import { extendZodWithOpenApi } from "@asteasolutions/zod-to-openapi";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
extendZodWithOpenApi(z);
|
|
2
5
|
export const registry = new OpenAPIRegistry();
|
|
3
6
|
// add Bearer JWT auth
|
|
4
|
-
export const bearerAuth = registry.registerComponent(
|
|
5
|
-
type:
|
|
6
|
-
scheme:
|
|
7
|
-
bearerFormat:
|
|
8
|
-
description:
|
|
7
|
+
export const bearerAuth = registry.registerComponent("securitySchemes", "bearerAuth", {
|
|
8
|
+
type: "http",
|
|
9
|
+
scheme: "bearer",
|
|
10
|
+
bearerFormat: "JWT",
|
|
11
|
+
description: "JWT Bearer authentication",
|
|
9
12
|
});
|
|
10
|
-
export const xApiKey = registry.registerComponent(
|
|
11
|
-
type:
|
|
12
|
-
in:
|
|
13
|
-
name:
|
|
14
|
-
description:
|
|
13
|
+
export const xApiKey = registry.registerComponent("securitySchemes", "x-api-key", {
|
|
14
|
+
type: "apiKey",
|
|
15
|
+
in: "header",
|
|
16
|
+
name: "x-api-key",
|
|
17
|
+
description: "API key for authentication",
|
|
15
18
|
});
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
19
|
+
const UserSchema = z
|
|
20
|
+
.object({
|
|
21
|
+
id: z.string().openapi({ example: "1212121" }),
|
|
22
|
+
name: z.string().openapi({ example: "John Doe" }),
|
|
23
|
+
age: z.number().openapi({ example: 42 }),
|
|
24
|
+
})
|
|
25
|
+
.openapi("User");
|
|
26
|
+
registry.registerPath({
|
|
27
|
+
method: "get",
|
|
28
|
+
path: "/usersnnn/{id}",
|
|
29
|
+
summary: "Get a single user",
|
|
30
|
+
request: {
|
|
31
|
+
params: z.object({ id: z.string() }),
|
|
32
|
+
},
|
|
33
|
+
responses: {
|
|
34
|
+
200: {
|
|
35
|
+
description: "Object with user data.",
|
|
36
|
+
content: {
|
|
37
|
+
"application/json": {
|
|
38
|
+
schema: UserSchema,
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
registry.registerPath({
|
|
45
|
+
method: "get",
|
|
46
|
+
path: "/users/{id}",
|
|
47
|
+
description: "Get user data by its id",
|
|
48
|
+
summary: "Get a single user",
|
|
49
|
+
request: {
|
|
50
|
+
params: z.object({
|
|
51
|
+
id: z.string().openapi({ example: "1212121" }),
|
|
52
|
+
}),
|
|
53
|
+
},
|
|
54
|
+
responses: {
|
|
55
|
+
200: {
|
|
56
|
+
description: "Object with user data.",
|
|
57
|
+
content: {
|
|
58
|
+
"application/json": {
|
|
59
|
+
schema: UserSchema,
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
204: {
|
|
64
|
+
description: "No content - successful operation",
|
|
65
|
+
},
|
|
66
|
+
},
|
|
27
67
|
});
|
|
28
|
-
*/
|
|
@@ -3,20 +3,36 @@ import { z } from "zod";
|
|
|
3
3
|
import mongoose from "mongoose";
|
|
4
4
|
export const zPagination = {
|
|
5
5
|
query: z.object({
|
|
6
|
-
name: z
|
|
6
|
+
name: z
|
|
7
|
+
.string()
|
|
8
|
+
.openapi({
|
|
9
|
+
example: "John",
|
|
10
|
+
description: "Name to filter by",
|
|
11
|
+
param: { name: "name", in: "query" },
|
|
12
|
+
})
|
|
13
|
+
.optional(),
|
|
7
14
|
role: z
|
|
8
15
|
.string()
|
|
9
|
-
.openapi({
|
|
16
|
+
.openapi({
|
|
17
|
+
example: "admin",
|
|
18
|
+
description: "Role to filter by",
|
|
19
|
+
param: { name: "role", in: "query" },
|
|
20
|
+
})
|
|
10
21
|
.optional(),
|
|
11
22
|
sortBy: z
|
|
12
23
|
.string()
|
|
13
|
-
.openapi({
|
|
24
|
+
.openapi({
|
|
25
|
+
example: "createdAt",
|
|
26
|
+
description: "Field to sort by",
|
|
27
|
+
param: { name: "sortBy", in: "query" },
|
|
28
|
+
})
|
|
14
29
|
.optional(),
|
|
15
30
|
search: z
|
|
16
31
|
.string()
|
|
17
32
|
.openapi({
|
|
18
33
|
example: process.env.SCHEMA_EXAMPLE_SEARCH || "",
|
|
19
34
|
description: "Search term to filter results",
|
|
35
|
+
param: { name: "search", in: "query" },
|
|
20
36
|
})
|
|
21
37
|
.optional(),
|
|
22
38
|
limit: z.coerce
|
|
@@ -24,6 +40,7 @@ export const zPagination = {
|
|
|
24
40
|
.openapi({
|
|
25
41
|
example: 10,
|
|
26
42
|
description: "Number of items per page",
|
|
43
|
+
param: { name: "limit", in: "query" },
|
|
27
44
|
})
|
|
28
45
|
.int()
|
|
29
46
|
.min(1)
|
|
@@ -34,6 +51,7 @@ export const zPagination = {
|
|
|
34
51
|
.openapi({
|
|
35
52
|
example: 0,
|
|
36
53
|
description: "Offset for pagination, used to skip a number of items",
|
|
54
|
+
param: { name: "offset", in: "query" },
|
|
37
55
|
})
|
|
38
56
|
.int()
|
|
39
57
|
.min(0)
|
|
@@ -45,6 +63,7 @@ export const zPagination = {
|
|
|
45
63
|
.openapi({
|
|
46
64
|
example: 1,
|
|
47
65
|
description: "Page number for pagination",
|
|
66
|
+
param: { name: "page", in: "query" },
|
|
48
67
|
})
|
|
49
68
|
.min(1)
|
|
50
69
|
.max(100000)
|