@internetderdinge/api 1.229.27 → 1.229.31

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.
@@ -0,0 +1,28 @@
1
+ import { z } from "zod";
2
+
3
+ export const adminSearchSchema = {
4
+ query: z.object({
5
+ search: z.string().max(120).optional(),
6
+ limit: z.coerce.number().min(1).max(50).optional(),
7
+ }),
8
+ };
9
+
10
+ export const adminStatsSchema = {
11
+ query: z.object({}),
12
+ };
13
+
14
+ export const adminIotDevicesSchema = {
15
+ query: z.object({
16
+ page: z.coerce.number().int().min(1).optional(),
17
+ perPage: z.coerce.number().int().min(1).max(500).optional(),
18
+ updatedSince: z.string().datetime().optional(),
19
+ }),
20
+ };
21
+
22
+ export const adminDevicesSchema = {
23
+ query: z.object({
24
+ page: z.coerce.number().int().min(1).optional(),
25
+ perPage: z.coerce.number().int().min(1).max(500).optional(),
26
+ updatedSince: z.string().datetime().optional(),
27
+ }),
28
+ };
package/src/index.ts CHANGED
@@ -15,6 +15,7 @@ export { default as i18n } from "../src/i18n/i18n";
15
15
  export { default as usersRoute } from "../src/users/users.route";
16
16
  export { default as usersService } from "../src/users/users.service";
17
17
  export { default as accountsRoute } from "../src/accounts/accounts.route";
18
+ export { default as adminSearchRoute } from "../src/admin/adminSearch.route";
18
19
  export { default as accountsService } from "../src/accounts/accounts.service";
19
20
  export { auth0 } from "../src/accounts/auth0.service";
20
21
  export { default as organizationsRoute } from "../src/organizations/organizations.route";
@@ -40,6 +40,7 @@ import {
40
40
  getApiStatus,
41
41
  getEntry,
42
42
  updateEntry,
43
+ ledLightHint,
43
44
  } from "./iotdevice.controller";
44
45
  import { request } from "https";
45
46
 
@@ -113,7 +114,7 @@ export const iotdeviceRouteSpecs: RouteSpec[] = [
113
114
  path: "/ledlight/:deviceId",
114
115
  validate: [auth("getUsers"), validateAdmin],
115
116
  responseSchema: pingResponseSchema,
116
- handler: pingDevice,
117
+ handler: ledLightHint,
117
118
  summary: "Ping device LED light",
118
119
  description:
119
120
  "Sends a ping to the device’s LED light to test its connectivity or response.",
@@ -21,6 +21,10 @@ export type RouteSpec = {
21
21
  validate?: RequestHandler<any, any, any, any, any>[];
22
22
  validateWithRequestSchema?: RequestHandler<any, any, any, any, any>[];
23
23
  requestSchema?: Partial<Record<string, ZodTypeAny>>;
24
+ requestBody?: {
25
+ required?: boolean;
26
+ content: Record<string, { schema: ZodTypeAny }>;
27
+ };
24
28
  responseSchema?: ZodTypeAny;
25
29
  handler: RequestHandler<any, any, any, any, any>;
26
30
  summary: string;
@@ -36,31 +40,22 @@ export default function buildAiRouterAndDocs(
36
40
  tags: string[] = [],
37
41
  ) {
38
42
  routeSpecs.forEach((spec) => {
39
- // mount Express
40
-
41
- if (!spec.validate) {
42
- spec.validate = [];
43
- }
44
-
45
- if (spec.requestSchema) {
46
- spec.validateWithRequestSchema = [
47
- validateZod(spec.requestSchema),
48
- ...spec.validate,
49
- ];
50
- }
51
-
52
- if (spec.validateWithRequestSchema) {
53
- router[spec.method](
54
- spec.path,
55
- ...spec.validateWithRequestSchema,
56
- spec.handler,
57
- );
58
- }
59
-
60
- var { body, ...rest } = spec.requestSchema || {};
61
-
62
- if (body) {
63
- rest.body = {
43
+ const validate = spec.validate || [];
44
+ const routeMiddleware =
45
+ spec.validateWithRequestSchema ||
46
+ (spec.requestSchema
47
+ ? [validateZod(spec.requestSchema), ...validate]
48
+ : validate);
49
+
50
+ router[spec.method](spec.path, ...routeMiddleware, spec.handler);
51
+
52
+ const { body, ...rest } = spec.requestSchema || {};
53
+ const request = { ...rest } as Record<string, unknown>;
54
+
55
+ if (spec.requestBody) {
56
+ request.body = spec.requestBody;
57
+ } else if (body) {
58
+ request.body = {
64
59
  content: {
65
60
  "application/json": {
66
61
  schema: body,
@@ -71,12 +66,12 @@ export default function buildAiRouterAndDocs(
71
66
 
72
67
  if (
73
68
  spec.responseSchema &&
74
- !hasRoleValidation(spec.validate) &&
69
+ !hasRoleValidation(spec.validateWithRequestSchema || validate) &&
75
70
  spec.privateDocs !== true &&
76
71
  spec.memoOnly !== true
77
72
  ) {
78
73
  // collect all middleware fn names (falls back to '<anonymous>' if unnamed)
79
- const middlewareNames = (spec.validate || []).map(
74
+ const middlewareNames = (spec.validateWithRequestSchema || validate).map(
80
75
  (fn) => `\`${fn.name}\`` || "<anonymous>",
81
76
  );
82
77
  const openApiPath = (basePath + spec.path).replace(
@@ -88,7 +83,7 @@ export default function buildAiRouterAndDocs(
88
83
  method: spec.method,
89
84
  path: openApiPath,
90
85
  summary: spec.summary,
91
- request: rest,
86
+ request,
92
87
 
93
88
  // append middleware names to the description
94
89
  description: [
@@ -6,6 +6,17 @@ extendZodWithOpenApi(z);
6
6
 
7
7
  export const registry = new OpenAPIRegistry();
8
8
 
9
+ export const xApiKey = registry.registerComponent(
10
+ "securitySchemes",
11
+ "x-api-key",
12
+ {
13
+ type: "apiKey",
14
+ in: "header",
15
+ name: "x-api-key",
16
+ description: "API key for authentication",
17
+ },
18
+ );
19
+
9
20
  // add Bearer JWT auth
10
21
  export const bearerAuth = registry.registerComponent(
11
22
  "securitySchemes",
@@ -18,17 +29,6 @@ export const bearerAuth = registry.registerComponent(
18
29
  },
19
30
  );
20
31
 
21
- export const xApiKey = registry.registerComponent(
22
- "securitySchemes",
23
- "x-api-key",
24
- {
25
- type: "apiKey",
26
- in: "header",
27
- name: "x-api-key",
28
- description: "API key for authentication",
29
- },
30
- );
31
-
32
32
  const UserSchema = z
33
33
  .object({
34
34
  id: z.string().openapi({ example: "1212121" }),
@@ -37,26 +37,7 @@ const UserSchema = z
37
37
  })
38
38
  .openapi("User");
39
39
 
40
- registry.registerPath({
41
- method: "get",
42
- path: "/usersnnn/{id}",
43
- summary: "Get a single user",
44
- request: {
45
- params: z.object({ id: z.string() }),
46
- },
47
-
48
- responses: {
49
- 200: {
50
- description: "Object with user data.",
51
- content: {
52
- "application/json": {
53
- schema: UserSchema,
54
- },
55
- },
56
- },
57
- },
58
- });
59
-
40
+ /*
60
41
  registry.registerPath({
61
42
  method: "get",
62
43
  path: "/users/{id}",
@@ -81,3 +62,4 @@ registry.registerPath({
81
62
  },
82
63
  },
83
64
  });
65
+ */