@discover-cloud/shared 1.3.0 → 1.5.0

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 (81) hide show
  1. package/dist/authorization/index.d.ts +2 -2
  2. package/dist/authorization/permission-cache.service.js +27 -11
  3. package/dist/context/index.d.ts +1 -0
  4. package/dist/context/index.js +17 -0
  5. package/dist/context/request-context.storage.d.ts +21 -0
  6. package/dist/context/request-context.storage.js +37 -0
  7. package/dist/contracts/auth-service/account.dto.d.ts +1 -1
  8. package/dist/contracts/index.d.ts +1 -0
  9. package/dist/contracts/index.js +17 -0
  10. package/dist/contracts/visibility.d.ts +63 -0
  11. package/dist/contracts/visibility.js +10 -0
  12. package/dist/dtos/audit-service.types.d.ts +42 -0
  13. package/dist/dtos/audit-service.types.js +31 -0
  14. package/dist/dtos/auth-service.dto.d.ts +16 -1
  15. package/dist/dtos/cloud-service.dto.d.ts +9 -3
  16. package/dist/dtos/index.d.ts +6 -5
  17. package/dist/dtos/index.js +1 -0
  18. package/dist/dtos/insights-service.dto.d.ts +174 -13
  19. package/dist/dtos/response.dto.d.ts +6 -0
  20. package/dist/dtos/user-service.dto.d.ts +52 -7
  21. package/dist/enums/domain.enums.d.ts +52 -26
  22. package/dist/enums/domain.enums.js +64 -40
  23. package/dist/enums/index.d.ts +2 -2
  24. package/dist/errors/app-error.js +1 -1
  25. package/dist/errors/http-errors.d.ts +1 -1
  26. package/dist/errors/http-errors.js +26 -26
  27. package/dist/errors/index.d.ts +2 -2
  28. package/dist/http/index.d.ts +2 -2
  29. package/dist/http/request-context.d.ts +2 -2
  30. package/dist/http/request-context.js +5 -5
  31. package/dist/http/service-client.d.ts +2 -2
  32. package/dist/http/service-client.js +2 -2
  33. package/dist/index.d.ts +11 -10
  34. package/dist/index.js +1 -0
  35. package/dist/jwt/index.d.ts +3 -3
  36. package/dist/jwt/machine-jwt-verifier.d.ts +1 -1
  37. package/dist/jwt/machine-jwt-verifier.js +13 -14
  38. package/dist/jwt/machine-token-client.d.ts +1 -1
  39. package/dist/jwt/machine-token-client.js +8 -8
  40. package/dist/jwt/user-jwt-verifier.d.ts +1 -1
  41. package/dist/jwt/user-jwt-verifier.js +17 -16
  42. package/dist/messaging/audit.publisher.d.ts +14 -0
  43. package/dist/messaging/audit.publisher.js +49 -0
  44. package/dist/messaging/index.d.ts +1 -0
  45. package/dist/messaging/index.js +1 -0
  46. package/dist/messaging/rabbitmq.client.d.ts +17 -5
  47. package/dist/messaging/rabbitmq.client.js +83 -36
  48. package/dist/middleware/error-handler.middleware.d.ts +2 -2
  49. package/dist/middleware/error-handler.middleware.js +10 -10
  50. package/dist/middleware/index.d.ts +10 -10
  51. package/dist/middleware/request-context.middleware.d.ts +1 -12
  52. package/dist/middleware/request-context.middleware.js +17 -42
  53. package/dist/middleware/require-auth.middleware.d.ts +3 -19
  54. package/dist/middleware/require-auth.middleware.js +17 -26
  55. package/dist/middleware/require-machine.middleware.d.ts +2 -27
  56. package/dist/middleware/require-machine.middleware.js +30 -25
  57. package/dist/middleware/require-org-permission-from-body.middleware.js +1 -2
  58. package/dist/middleware/require-org-permission.middleware.d.ts +3 -3
  59. package/dist/middleware/require-org-permission.middleware.js +28 -28
  60. package/dist/middleware/require-platform-permission.middleware.d.ts +3 -3
  61. package/dist/middleware/require-platform-permission.middleware.js +10 -10
  62. package/dist/middleware/require-user.middleware.d.ts +1 -1
  63. package/dist/middleware/require-user.middleware.js +2 -2
  64. package/dist/middleware/require-workspace-permission.middleware.d.ts +3 -3
  65. package/dist/middleware/require-workspace-permission.middleware.js +25 -25
  66. package/dist/middleware/validate.middleware.d.ts +3 -3
  67. package/dist/middleware/validate.middleware.js +1 -1
  68. package/dist/types/audit.types.d.ts +39 -0
  69. package/dist/types/audit.types.js +30 -0
  70. package/dist/types/express.types.d.ts +14 -7
  71. package/dist/types/express.types.js +10 -10
  72. package/dist/types/index.d.ts +1 -1
  73. package/dist/utils/env.util.js +1 -1
  74. package/dist/utils/index.d.ts +5 -5
  75. package/dist/utils/logger.util.d.ts +5 -0
  76. package/dist/utils/logger.util.js +46 -8
  77. package/dist/utils/request-context.als.d.ts +10 -0
  78. package/dist/utils/request-context.als.js +5 -0
  79. package/dist/utils/response.util.d.ts +1 -1
  80. package/dist/utils/url-safety.util.js +4 -1
  81. package/package.json +1 -1
@@ -18,16 +18,16 @@ const createRequireOrgPermission = (permissionCache, resolveFn) => {
18
18
  const requireOrgPermission = (permission) => {
19
19
  return async (req, res, next) => {
20
20
  const ctx = req.authContext;
21
- if (!ctx || ctx.type !== "user") {
22
- (0, utils_1.failure)(res, req, "Unauthorized: No auth context", "UNAUTHORIZED", 401);
21
+ if (!ctx || ctx.type !== 'user') {
22
+ (0, utils_1.failure)(res, req, 'Unauthorized: No auth context', 'UNAUTHORIZED', 401);
23
23
  return;
24
24
  }
25
- const organizationId = req.params["organizationId"] ??
26
- req.params["orgId"] ??
27
- req.validated?.params?.["organizationId"] ??
28
- req.validated?.body?.["organizationId"];
29
- if (!organizationId || typeof organizationId !== "string") {
30
- (0, utils_1.failure)(res, req, "Bad Request: Missing organization context", "BAD_REQUEST", 400);
25
+ const organizationId = req.params['organizationId'] ??
26
+ req.params['orgId'] ??
27
+ req.validated?.params?.['organizationId'] ??
28
+ req.validated?.body?.['organizationId'];
29
+ if (!organizationId || typeof organizationId !== 'string') {
30
+ (0, utils_1.failure)(res, req, 'Bad Request: Missing organization context', 'BAD_REQUEST', 400);
31
31
  return;
32
32
  }
33
33
  try {
@@ -35,7 +35,7 @@ const createRequireOrgPermission = (permissionCache, resolveFn) => {
35
35
  return resolveFn(ctx.accountId, organizationId);
36
36
  });
37
37
  if (!permission_checker_1.PermissionChecker.has(perms, permission)) {
38
- (0, utils_1.failure)(res, req, `Forbidden: Missing required organization permission: ${permission}`, "FORBIDDEN", 403);
38
+ (0, utils_1.failure)(res, req, `Forbidden: Missing required organization permission: ${permission}`, 'FORBIDDEN', 403);
39
39
  return;
40
40
  }
41
41
  next();
@@ -48,16 +48,16 @@ const createRequireOrgPermission = (permissionCache, resolveFn) => {
48
48
  const requireAnyOrgPermission = (...permissions) => {
49
49
  return async (req, res, next) => {
50
50
  const ctx = req.authContext;
51
- if (!ctx || ctx.type !== "user") {
52
- (0, utils_1.failure)(res, req, "Unauthorized: No auth context", "UNAUTHORIZED", 401);
51
+ if (!ctx || ctx.type !== 'user') {
52
+ (0, utils_1.failure)(res, req, 'Unauthorized: No auth context', 'UNAUTHORIZED', 401);
53
53
  return;
54
54
  }
55
- const organizationId = req.params["organizationId"] ??
56
- req.params["orgId"] ??
57
- req.validated?.params?.["organizationId"] ??
58
- req.validated?.body?.["organizationId"];
59
- if (!organizationId || typeof organizationId !== "string") {
60
- (0, utils_1.failure)(res, req, "Bad Request: Missing organization context", "BAD_REQUEST", 400);
55
+ const organizationId = req.params['organizationId'] ??
56
+ req.params['orgId'] ??
57
+ req.validated?.params?.['organizationId'] ??
58
+ req.validated?.body?.['organizationId'];
59
+ if (!organizationId || typeof organizationId !== 'string') {
60
+ (0, utils_1.failure)(res, req, 'Bad Request: Missing organization context', 'BAD_REQUEST', 400);
61
61
  return;
62
62
  }
63
63
  try {
@@ -65,7 +65,7 @@ const createRequireOrgPermission = (permissionCache, resolveFn) => {
65
65
  return resolveFn(ctx.accountId, organizationId);
66
66
  });
67
67
  if (!permission_checker_1.PermissionChecker.hasAny(perms, permissions)) {
68
- (0, utils_1.failure)(res, req, `Forbidden: Missing one of required organization permissions: [${permissions.join(", ")}]`, "FORBIDDEN", 403);
68
+ (0, utils_1.failure)(res, req, `Forbidden: Missing one of required organization permissions: [${permissions.join(', ')}]`, 'FORBIDDEN', 403);
69
69
  return;
70
70
  }
71
71
  next();
@@ -78,16 +78,16 @@ const createRequireOrgPermission = (permissionCache, resolveFn) => {
78
78
  const requireAllOrgPermissions = (...permissions) => {
79
79
  return async (req, res, next) => {
80
80
  const ctx = req.authContext;
81
- if (!ctx || ctx.type !== "user") {
82
- (0, utils_1.failure)(res, req, "Unauthorized: No auth context", "UNAUTHORIZED", 401);
81
+ if (!ctx || ctx.type !== 'user') {
82
+ (0, utils_1.failure)(res, req, 'Unauthorized: No auth context', 'UNAUTHORIZED', 401);
83
83
  return;
84
84
  }
85
- const organizationId = req.params["organizationId"] ??
86
- req.params["orgId"] ??
87
- req.validated?.params?.["organizationId"] ??
88
- req.validated?.body?.["organizationId"];
89
- if (!organizationId || typeof organizationId !== "string") {
90
- (0, utils_1.failure)(res, req, "Bad Request: Missing organization context", "BAD_REQUEST", 400);
85
+ const organizationId = req.params['organizationId'] ??
86
+ req.params['orgId'] ??
87
+ req.validated?.params?.['organizationId'] ??
88
+ req.validated?.body?.['organizationId'];
89
+ if (!organizationId || typeof organizationId !== 'string') {
90
+ (0, utils_1.failure)(res, req, 'Bad Request: Missing organization context', 'BAD_REQUEST', 400);
91
91
  return;
92
92
  }
93
93
  try {
@@ -95,8 +95,8 @@ const createRequireOrgPermission = (permissionCache, resolveFn) => {
95
95
  return resolveFn(ctx.accountId, organizationId);
96
96
  });
97
97
  if (!permission_checker_1.PermissionChecker.hasAll(perms, permissions)) {
98
- const missing = permissions.filter(p => !permission_checker_1.PermissionChecker.has(perms, p));
99
- (0, utils_1.failure)(res, req, `Forbidden: Missing required organization permissions: [${missing.join(", ")}]`, "FORBIDDEN", 403);
98
+ const missing = permissions.filter((p) => !permission_checker_1.PermissionChecker.has(perms, p));
99
+ (0, utils_1.failure)(res, req, `Forbidden: Missing required organization permissions: [${missing.join(', ')}]`, 'FORBIDDEN', 403);
100
100
  return;
101
101
  }
102
102
  next();
@@ -2,9 +2,9 @@
2
2
  * @file require-platform-permission.middleware.ts
3
3
  * @description Express middleware generator to enforce platform-scoped permission checks.
4
4
  */
5
- import { RequestHandler } from "express";
6
- import { PlatformPermission } from "../enums";
7
- import { PermissionCacheService } from "../authorization/permission-cache.service";
5
+ import { RequestHandler } from 'express';
6
+ import { PlatformPermission } from '../enums';
7
+ import { PermissionCacheService } from '../authorization/permission-cache.service';
8
8
  /**
9
9
  * Creates requirePlatformPermission middleware.
10
10
  *
@@ -18,8 +18,8 @@ const createRequirePlatformPermission = (permissionCache, resolveFn) => {
18
18
  const requirePlatformPermission = (permission) => {
19
19
  return async (req, res, next) => {
20
20
  const ctx = req.authContext;
21
- if (!ctx || ctx.type !== "user") {
22
- (0, utils_1.failure)(res, req, "Unauthorized: No access context", "UNAUTHORIZED", 401);
21
+ if (!ctx || ctx.type !== 'user') {
22
+ (0, utils_1.failure)(res, req, 'Unauthorized: No access context', 'UNAUTHORIZED', 401);
23
23
  return;
24
24
  }
25
25
  try {
@@ -27,7 +27,7 @@ const createRequirePlatformPermission = (permissionCache, resolveFn) => {
27
27
  return resolveFn(ctx.accountId);
28
28
  });
29
29
  if (!permission_checker_1.PermissionChecker.has(perms, permission)) {
30
- (0, utils_1.failure)(res, req, `Forbidden: Missing required platform permission: ${permission}`, "FORBIDDEN", 403);
30
+ (0, utils_1.failure)(res, req, `Forbidden: Missing required platform permission: ${permission}`, 'FORBIDDEN', 403);
31
31
  return;
32
32
  }
33
33
  next();
@@ -40,8 +40,8 @@ const createRequirePlatformPermission = (permissionCache, resolveFn) => {
40
40
  const requireAnyPlatformPermission = (...permissions) => {
41
41
  return async (req, res, next) => {
42
42
  const ctx = req.authContext;
43
- if (!ctx || ctx.type !== "user") {
44
- (0, utils_1.failure)(res, req, "Unauthorized: No access context", "UNAUTHORIZED", 401);
43
+ if (!ctx || ctx.type !== 'user') {
44
+ (0, utils_1.failure)(res, req, 'Unauthorized: No access context', 'UNAUTHORIZED', 401);
45
45
  return;
46
46
  }
47
47
  try {
@@ -49,7 +49,7 @@ const createRequirePlatformPermission = (permissionCache, resolveFn) => {
49
49
  return resolveFn(ctx.accountId);
50
50
  });
51
51
  if (!permission_checker_1.PermissionChecker.hasAny(perms, permissions)) {
52
- (0, utils_1.failure)(res, req, `Forbidden: Missing one of required platform permissions: [${permissions.join(", ")}]`, "FORBIDDEN", 403);
52
+ (0, utils_1.failure)(res, req, `Forbidden: Missing one of required platform permissions: [${permissions.join(', ')}]`, 'FORBIDDEN', 403);
53
53
  return;
54
54
  }
55
55
  next();
@@ -62,8 +62,8 @@ const createRequirePlatformPermission = (permissionCache, resolveFn) => {
62
62
  const requireAllPlatformPermissions = (...permissions) => {
63
63
  return async (req, res, next) => {
64
64
  const ctx = req.authContext;
65
- if (!ctx || ctx.type !== "user") {
66
- (0, utils_1.failure)(res, req, "Unauthorized: No access context", "UNAUTHORIZED", 401);
65
+ if (!ctx || ctx.type !== 'user') {
66
+ (0, utils_1.failure)(res, req, 'Unauthorized: No access context', 'UNAUTHORIZED', 401);
67
67
  return;
68
68
  }
69
69
  try {
@@ -71,8 +71,8 @@ const createRequirePlatformPermission = (permissionCache, resolveFn) => {
71
71
  return resolveFn(ctx.accountId);
72
72
  });
73
73
  if (!permission_checker_1.PermissionChecker.hasAll(perms, permissions)) {
74
- const missing = permissions.filter(p => !permission_checker_1.PermissionChecker.has(perms, p));
75
- (0, utils_1.failure)(res, req, `Forbidden: Missing required platform permissions: [${missing.join(", ")}]`, "FORBIDDEN", 403);
74
+ const missing = permissions.filter((p) => !permission_checker_1.PermissionChecker.has(perms, p));
75
+ (0, utils_1.failure)(res, req, `Forbidden: Missing required platform permissions: [${missing.join(', ')}]`, 'FORBIDDEN', 403);
76
76
  return;
77
77
  }
78
78
  next();
@@ -2,7 +2,7 @@
2
2
  * @file require-user.middleware.ts
3
3
  * @description Express middleware to assert that the request auth context belongs to a user (not a machine).
4
4
  */
5
- import { Request, Response, NextFunction } from "express";
5
+ import { Request, Response, NextFunction } from 'express';
6
6
  /**
7
7
  * Asserts that the current request has a valid user context, returning 401/403 otherwise.
8
8
  *
@@ -18,11 +18,11 @@ const types_1 = require("../types");
18
18
  const requireUser = (req, res, next) => {
19
19
  const ctx = req.authContext;
20
20
  if (!ctx) {
21
- (0, utils_1.failure)(res, req, "Unauthorized: No auth context", "UNAUTHORIZED", 401);
21
+ (0, utils_1.failure)(res, req, 'Unauthorized: No auth context', 'UNAUTHORIZED', 401);
22
22
  return;
23
23
  }
24
24
  if (!(0, types_1.isUserContext)(ctx)) {
25
- (0, utils_1.failure)(res, req, "User token required", "FORBIDDEN", 401);
25
+ (0, utils_1.failure)(res, req, 'User token required', 'FORBIDDEN', 401);
26
26
  return;
27
27
  }
28
28
  next();
@@ -2,9 +2,9 @@
2
2
  * @file require-workspace-permission.middleware.ts
3
3
  * @description Express middleware factory to enforce workspace-scoped permission checks.
4
4
  */
5
- import { RequestHandler } from "express";
6
- import { Permission } from "../enums";
7
- import { PermissionCacheService } from "../authorization/permission-cache.service";
5
+ import { RequestHandler } from 'express';
6
+ import { Permission } from '../enums';
7
+ import { PermissionCacheService } from '../authorization/permission-cache.service';
8
8
  /**
9
9
  * Creates requireWorkspacePermission middleware factory.
10
10
  *
@@ -19,16 +19,16 @@ const createRequireWorkspacePermission = (permissionCache, resolveFn) => {
19
19
  const requireWorkspacePermission = (permission) => {
20
20
  return async (req, res, next) => {
21
21
  const ctx = req.authContext;
22
- if (!ctx || ctx.type !== "user") {
23
- (0, utils_1.failure)(res, req, "Unauthorized: No access context", "UNAUTHORIZED", 401);
22
+ if (!ctx || ctx.type !== 'user') {
23
+ (0, utils_1.failure)(res, req, 'Unauthorized: No access context', 'UNAUTHORIZED', 401);
24
24
  return;
25
25
  }
26
26
  // Resolve workspaceId from request locations
27
- const workspaceId = req.params["workspaceId"] ??
28
- req.validated?.params?.["workspaceId"] ??
29
- req.validated?.body?.["workspaceId"];
30
- if (!workspaceId || typeof workspaceId !== "string") {
31
- (0, utils_1.failure)(res, req, "Bad Request: Missing workspaceId", "BAD_REQUEST", 400);
27
+ const workspaceId = req.params['workspaceId'] ??
28
+ req.validated?.params?.['workspaceId'] ??
29
+ req.validated?.body?.['workspaceId'];
30
+ if (!workspaceId || typeof workspaceId !== 'string') {
31
+ (0, utils_1.failure)(res, req, 'Bad Request: Missing workspaceId', 'BAD_REQUEST', 400);
32
32
  return;
33
33
  }
34
34
  try {
@@ -36,7 +36,7 @@ const createRequireWorkspacePermission = (permissionCache, resolveFn) => {
36
36
  return resolveFn(ctx.accountId, workspaceId);
37
37
  });
38
38
  if (!permission_checker_1.PermissionChecker.has(perms, permission)) {
39
- (0, utils_1.failure)(res, req, `Forbidden: Missing required workspace permission: ${permission}`, "FORBIDDEN", 403);
39
+ (0, utils_1.failure)(res, req, `Forbidden: Missing required workspace permission: ${permission}`, 'FORBIDDEN', 403);
40
40
  return;
41
41
  }
42
42
  next();
@@ -49,15 +49,15 @@ const createRequireWorkspacePermission = (permissionCache, resolveFn) => {
49
49
  const requireAnyWorkspacePermission = (...permissions) => {
50
50
  return async (req, res, next) => {
51
51
  const ctx = req.authContext;
52
- if (!ctx || ctx.type !== "user") {
53
- (0, utils_1.failure)(res, req, "Unauthorized: No access context", "UNAUTHORIZED", 401);
52
+ if (!ctx || ctx.type !== 'user') {
53
+ (0, utils_1.failure)(res, req, 'Unauthorized: No access context', 'UNAUTHORIZED', 401);
54
54
  return;
55
55
  }
56
- const workspaceId = req.params["workspaceId"] ??
57
- req.validated?.params?.["workspaceId"] ??
58
- req.validated?.body?.["workspaceId"];
59
- if (!workspaceId || typeof workspaceId !== "string") {
60
- (0, utils_1.failure)(res, req, "Bad Request: Missing workspaceId", "BAD_REQUEST", 400);
56
+ const workspaceId = req.params['workspaceId'] ??
57
+ req.validated?.params?.['workspaceId'] ??
58
+ req.validated?.body?.['workspaceId'];
59
+ if (!workspaceId || typeof workspaceId !== 'string') {
60
+ (0, utils_1.failure)(res, req, 'Bad Request: Missing workspaceId', 'BAD_REQUEST', 400);
61
61
  return;
62
62
  }
63
63
  try {
@@ -65,7 +65,7 @@ const createRequireWorkspacePermission = (permissionCache, resolveFn) => {
65
65
  return resolveFn(ctx.accountId, workspaceId);
66
66
  });
67
67
  if (!permission_checker_1.PermissionChecker.hasAny(perms, permissions)) {
68
- (0, utils_1.failure)(res, req, `Forbidden: Missing one of required workspace permissions: [${permissions.join(", ")}]`, "FORBIDDEN", 403);
68
+ (0, utils_1.failure)(res, req, `Forbidden: Missing one of required workspace permissions: [${permissions.join(', ')}]`, 'FORBIDDEN', 403);
69
69
  return;
70
70
  }
71
71
  next();
@@ -78,15 +78,15 @@ const createRequireWorkspacePermission = (permissionCache, resolveFn) => {
78
78
  const requireAllWorkspacePermissions = (...permissions) => {
79
79
  return async (req, res, next) => {
80
80
  const ctx = req.authContext;
81
- if (!ctx || ctx.type !== "user") {
82
- (0, utils_1.failure)(res, req, "Unauthorized: No access context", "UNAUTHORIZED", 401);
81
+ if (!ctx || ctx.type !== 'user') {
82
+ (0, utils_1.failure)(res, req, 'Unauthorized: No access context', 'UNAUTHORIZED', 401);
83
83
  return;
84
84
  }
85
- const workspaceId = req.params["workspaceId"] ??
86
- req.validated?.params?.["workspaceId"] ??
87
- req.validated?.body?.["workspaceId"];
88
- if (!workspaceId || typeof workspaceId !== "string") {
89
- (0, utils_1.failure)(res, req, "Bad Request: Missing workspaceId", "BAD_REQUEST", 400);
85
+ const workspaceId = req.params['workspaceId'] ??
86
+ req.validated?.params?.['workspaceId'] ??
87
+ req.validated?.body?.['workspaceId'];
88
+ if (!workspaceId || typeof workspaceId !== 'string') {
89
+ (0, utils_1.failure)(res, req, 'Bad Request: Missing workspaceId', 'BAD_REQUEST', 400);
90
90
  return;
91
91
  }
92
92
  try {
@@ -94,8 +94,8 @@ const createRequireWorkspacePermission = (permissionCache, resolveFn) => {
94
94
  return resolveFn(ctx.accountId, workspaceId);
95
95
  });
96
96
  if (!permission_checker_1.PermissionChecker.hasAll(perms, permissions)) {
97
- const missing = permissions.filter(p => !permission_checker_1.PermissionChecker.has(perms, p));
98
- (0, utils_1.failure)(res, req, `Forbidden: Missing required workspace permissions: [${missing.join(", ")}]`, "FORBIDDEN", 403);
97
+ const missing = permissions.filter((p) => !permission_checker_1.PermissionChecker.has(perms, p));
98
+ (0, utils_1.failure)(res, req, `Forbidden: Missing required workspace permissions: [${missing.join(', ')}]`, 'FORBIDDEN', 403);
99
99
  return;
100
100
  }
101
101
  next();
@@ -3,12 +3,12 @@
3
3
  * @description Request validation middleware leveraging Zod schema definitions.
4
4
  * Supports validating multiple request sources without overwriting previous results.
5
5
  */
6
- import { Request, Response, NextFunction } from "express";
7
- import { ZodType } from "zod";
6
+ import { Request, Response, NextFunction } from 'express';
7
+ import { ZodType } from 'zod';
8
8
  /**
9
9
  * Supported Express request validation sources.
10
10
  */
11
- type ValidationSource = "body" | "params" | "query" | "headers";
11
+ type ValidationSource = 'body' | 'params' | 'query' | 'headers';
12
12
  /**
13
13
  * Validator utility class containing Express middleware generation methods.
14
14
  */
@@ -27,7 +27,7 @@ class Validator {
27
27
  * @param {ZodType<T>} schema - Zod validation schema.
28
28
  * @param {ValidationSource} source - Request source.
29
29
  */
30
- static validate(schema, source = "body") {
30
+ static validate(schema, source = 'body') {
31
31
  return (req, _res, next) => {
32
32
  const result = schema.safeParse(req[source]);
33
33
  if (!result.success) {
@@ -0,0 +1,39 @@
1
+ export declare enum AuditActorType {
2
+ USER = "USER",
3
+ SERVICE = "SERVICE",
4
+ SYSTEM = "SYSTEM",
5
+ ANONYMOUS = "ANONYMOUS",
6
+ SUPPORT = "SUPPORT",
7
+ INTEGRATION = "INTEGRATION",
8
+ API_KEY = "API_KEY"
9
+ }
10
+ export declare enum AuditResourceType {
11
+ ACCOUNT = "ACCOUNT",
12
+ USER = "USER",
13
+ ORGANIZATION = "ORGANIZATION",
14
+ WORKSPACE = "WORKSPACE",
15
+ ROLE = "ROLE",
16
+ PERMISSION = "PERMISSION",
17
+ PLATFORM_ROLE = "PLATFORM_ROLE",
18
+ PLATFORM_PERMISSION = "PLATFORM_PERMISSION",
19
+ SESSION = "SESSION",
20
+ SERVICE_CLIENT = "SERVICE_CLIENT",
21
+ MFA = "MFA",
22
+ SYSTEM = "SYSTEM",// e.g. for system cron jobs
23
+ INVITE = "INVITE"
24
+ }
25
+ export declare const AUDIT_SEVERITIES: readonly ["info", "warning", "error", "critical"];
26
+ export type AuditSeverity = (typeof AUDIT_SEVERITIES)[number];
27
+ export interface RecordAuditActionInput {
28
+ actorId?: string | null;
29
+ actorType?: AuditActorType;
30
+ action: string;
31
+ severity?: AuditSeverity;
32
+ resourceType: AuditResourceType;
33
+ resourceId?: string | null;
34
+ organizationId?: string | null;
35
+ workspaceId?: string | null;
36
+ metadata?: Record<string, any>;
37
+ requestId?: string | null;
38
+ traceId?: string | null;
39
+ }
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AUDIT_SEVERITIES = exports.AuditResourceType = exports.AuditActorType = void 0;
4
+ var AuditActorType;
5
+ (function (AuditActorType) {
6
+ AuditActorType["USER"] = "USER";
7
+ AuditActorType["SERVICE"] = "SERVICE";
8
+ AuditActorType["SYSTEM"] = "SYSTEM";
9
+ AuditActorType["ANONYMOUS"] = "ANONYMOUS";
10
+ AuditActorType["SUPPORT"] = "SUPPORT";
11
+ AuditActorType["INTEGRATION"] = "INTEGRATION";
12
+ AuditActorType["API_KEY"] = "API_KEY";
13
+ })(AuditActorType || (exports.AuditActorType = AuditActorType = {}));
14
+ var AuditResourceType;
15
+ (function (AuditResourceType) {
16
+ AuditResourceType["ACCOUNT"] = "ACCOUNT";
17
+ AuditResourceType["USER"] = "USER";
18
+ AuditResourceType["ORGANIZATION"] = "ORGANIZATION";
19
+ AuditResourceType["WORKSPACE"] = "WORKSPACE";
20
+ AuditResourceType["ROLE"] = "ROLE";
21
+ AuditResourceType["PERMISSION"] = "PERMISSION";
22
+ AuditResourceType["PLATFORM_ROLE"] = "PLATFORM_ROLE";
23
+ AuditResourceType["PLATFORM_PERMISSION"] = "PLATFORM_PERMISSION";
24
+ AuditResourceType["SESSION"] = "SESSION";
25
+ AuditResourceType["SERVICE_CLIENT"] = "SERVICE_CLIENT";
26
+ AuditResourceType["MFA"] = "MFA";
27
+ AuditResourceType["SYSTEM"] = "SYSTEM";
28
+ AuditResourceType["INVITE"] = "INVITE";
29
+ })(AuditResourceType || (exports.AuditResourceType = AuditResourceType = {}));
30
+ exports.AUDIT_SEVERITIES = ["info", "warning", "error", "critical"];
@@ -2,7 +2,8 @@
2
2
  * @file express.types.ts
3
3
  * @description Express Request type augmentations and authentication context definitions.
4
4
  */
5
- import { JWTPayload } from "jose";
5
+ import { JWTPayload } from 'jose';
6
+ import { ResourceQueryScope } from '../contracts';
6
7
  interface BaseTokenPayload extends JWTPayload {
7
8
  jti: string;
8
9
  iss: string;
@@ -18,13 +19,15 @@ interface BaseTokenPayload extends JWTPayload {
18
19
  * Authorization is resolved dynamically using RBAC.
19
20
  */
20
21
  export interface AccessTokenPayload extends BaseTokenPayload {
21
- typ: "access";
22
+ typ: 'access';
22
23
  /** Account identifier. */
23
24
  accountId: string;
24
25
  /** Active session identifier. */
25
26
  sessionId: string;
26
27
  /** Token/version invalidation marker. */
27
28
  ver: number;
29
+ /** Whether the session was generated via impersonation. */
30
+ impersonated?: boolean;
28
31
  }
29
32
  /**
30
33
  * Long-lived refresh token payload.
@@ -32,14 +35,14 @@ export interface AccessTokenPayload extends BaseTokenPayload {
32
35
  * Refresh tokens are only used for rotation.
33
36
  */
34
37
  export interface RefreshTokenPayload extends BaseTokenPayload {
35
- typ: "refresh";
38
+ typ: 'refresh';
36
39
  accountId: string;
37
40
  }
38
41
  /**
39
42
  * Service-to-service authentication token.
40
43
  */
41
44
  export interface MachineTokenPayload extends BaseTokenPayload {
42
- typ: "machine";
45
+ typ: 'machine';
43
46
  serviceId: string;
44
47
  scopes: string[];
45
48
  requestId?: string;
@@ -61,7 +64,7 @@ export interface TokenRevocationContext {
61
64
  * Created from access tokens only.
62
65
  */
63
66
  export interface UserContext {
64
- type: "user";
67
+ type: 'user';
65
68
  accountId: string;
66
69
  sessionId: string;
67
70
  }
@@ -69,7 +72,7 @@ export interface UserContext {
69
72
  * Authenticated internal service context.
70
73
  */
71
74
  export interface MachineContext {
72
- type: "machine";
75
+ type: 'machine';
73
76
  serviceId: string;
74
77
  scopes: string[];
75
78
  }
@@ -100,7 +103,7 @@ export interface ValidatedRequestData {
100
103
  body?: Record<string, unknown>;
101
104
  headers?: Record<string, unknown>;
102
105
  }
103
- declare module "express-serve-static-core" {
106
+ declare module 'express-serve-static-core' {
104
107
  interface Request {
105
108
  /**
106
109
  * Request correlation ID.
@@ -122,6 +125,10 @@ declare module "express-serve-static-core" {
122
125
  * Runtime authenticated identity.
123
126
  */
124
127
  authContext?: AuthContext;
128
+ /**
129
+ * Resolved resource query scope for insights queries.
130
+ */
131
+ visibilityScope?: ResourceQueryScope;
125
132
  }
126
133
  }
127
134
  export {};
@@ -14,28 +14,28 @@ exports.assertMachineToken = assertMachineToken;
14
14
  Type Guards
15
15
  --------------------------------------------------------------------------- */
16
16
  function isAccessToken(payload) {
17
- return payload.typ === "access";
17
+ return payload.typ === 'access';
18
18
  }
19
19
  function isRefreshToken(payload) {
20
- return payload.typ === "refresh";
20
+ return payload.typ === 'refresh';
21
21
  }
22
22
  function isMachineToken(payload) {
23
- return payload.typ === "machine";
23
+ return payload.typ === 'machine';
24
24
  }
25
25
  function isUserContext(ctx) {
26
- return ctx.type === "user";
26
+ return ctx.type === 'user';
27
27
  }
28
28
  function isMachineContext(ctx) {
29
- return ctx.type === "machine";
29
+ return ctx.type === 'machine';
30
30
  }
31
31
  /**
32
32
  * Runtime assertion for service tokens.
33
33
  */
34
34
  function assertMachineToken(payload) {
35
- if (payload["typ"] !== "machine" ||
36
- typeof payload["serviceId"] !== "string" ||
37
- typeof payload["jti"] !== "string" ||
38
- !Array.isArray(payload["scopes"])) {
39
- throw new Error("Invalid machine token payload");
35
+ if (payload['typ'] !== 'machine' ||
36
+ typeof payload['serviceId'] !== 'string' ||
37
+ typeof payload['jti'] !== 'string' ||
38
+ !Array.isArray(payload['scopes'])) {
39
+ throw new Error('Invalid machine token payload');
40
40
  }
41
41
  }
@@ -1 +1 @@
1
- export * from "./express.types";
1
+ export * from './express.types';
@@ -15,5 +15,5 @@ function getEnv(name) {
15
15
  }
16
16
  function getEnvOptional(name) {
17
17
  const value = process.env[name];
18
- return value === "" ? undefined : value;
18
+ return value === '' ? undefined : value;
19
19
  }
@@ -1,5 +1,5 @@
1
- export * from "./response.util";
2
- export * from "./logger.util";
3
- export * from "./date.util";
4
- export * from "./env.util";
5
- export * from "./pagination.util";
1
+ export * from './response.util';
2
+ export * from './logger.util';
3
+ export * from './date.util';
4
+ export * from './env.util';
5
+ export * from './pagination.util';
@@ -24,3 +24,8 @@ export declare const noopLogger: ILogger;
24
24
  * Console logger implementing the ILogger interface mapping to native console output.
25
25
  */
26
26
  export declare const consoleLogger: ILogger;
27
+ /**
28
+ * Creates an ILogger adapter for a given Pino logger instance.
29
+ * @param pinoLogger Any Pino logger instance.
30
+ */
31
+ export declare function createPinoAdapter(pinoLogger: any): ILogger;