@discover-cloud/shared 1.0.0 → 1.0.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 (61) hide show
  1. package/dist/authorization/index.d.ts +2 -0
  2. package/dist/authorization/index.js +18 -0
  3. package/dist/authorization/permission-cache.service.d.ts +12 -0
  4. package/dist/authorization/permission-cache.service.js +132 -0
  5. package/dist/authorization/permissions.d.ts +74 -0
  6. package/dist/authorization/permissions.js +171 -0
  7. package/dist/dto/auth-service.dtos.d.ts +5 -12
  8. package/dist/dto/response.dtos.d.ts +34 -27
  9. package/dist/dto/response.dtos.js +4 -0
  10. package/dist/dto/user-service.dtos.d.ts +9 -13
  11. package/dist/dtos/auth-service.dto.d.ts +44 -0
  12. package/dist/dtos/auth-service.dto.js +2 -0
  13. package/dist/dtos/index.d.ts +3 -0
  14. package/dist/dtos/index.js +19 -0
  15. package/dist/dtos/response.dto.d.ts +55 -0
  16. package/dist/dtos/response.dto.js +6 -0
  17. package/dist/dtos/user-service.dto.d.ts +50 -0
  18. package/dist/dtos/user-service.dto.js +2 -0
  19. package/dist/enums/domain.enums.d.ts +42 -0
  20. package/dist/enums/domain.enums.js +79 -0
  21. package/dist/enums/index.d.ts +2 -3
  22. package/dist/enums/index.js +2 -3
  23. package/dist/enums/permissions.enums.d.ts +124 -0
  24. package/dist/enums/permissions.enums.js +141 -0
  25. package/dist/errors/app-error.d.ts +19 -2
  26. package/dist/errors/app-error.js +17 -2
  27. package/dist/errors/http-errors.d.ts +18 -0
  28. package/dist/errors/http-errors.js +25 -1
  29. package/dist/http/index.d.ts +1 -0
  30. package/dist/http/index.js +17 -0
  31. package/dist/http/service-client.d.ts +23 -7
  32. package/dist/http/service-client.js +54 -22
  33. package/dist/index.d.ts +3 -2
  34. package/dist/index.js +3 -2
  35. package/dist/jwt/index.d.ts +1 -2
  36. package/dist/jwt/index.js +1 -2
  37. package/dist/jwt/internal-jwt-verifier.d.ts +35 -0
  38. package/dist/jwt/internal-jwt-verifier.js +162 -0
  39. package/dist/middleware/authorize.middleware.d.ts +22 -0
  40. package/dist/middleware/authorize.middleware.js +77 -0
  41. package/dist/middleware/error-handler.middleware.d.ts +16 -0
  42. package/dist/middleware/error-handler.middleware.js +42 -0
  43. package/dist/middleware/index.d.ts +4 -5
  44. package/dist/middleware/index.js +4 -5
  45. package/dist/middleware/request-id.middleware.d.ts +20 -0
  46. package/dist/middleware/request-id.middleware.js +34 -0
  47. package/dist/middleware/validate.middleware.d.ts +26 -0
  48. package/dist/middleware/validate.middleware.js +41 -0
  49. package/dist/types/express.types.d.ts +148 -0
  50. package/dist/types/express.types.js +42 -0
  51. package/dist/types/index.d.ts +1 -1
  52. package/dist/types/index.js +1 -1
  53. package/dist/utils/index.d.ts +2 -1
  54. package/dist/utils/index.js +2 -1
  55. package/dist/utils/logger.utils.d.ts +51 -0
  56. package/dist/utils/logger.utils.js +62 -0
  57. package/dist/utils/response.d.ts +2 -1
  58. package/dist/utils/response.js +6 -3
  59. package/dist/utils/response.utils.d.ts +12 -0
  60. package/dist/utils/response.utils.js +42 -0
  61. package/package.json +3 -2
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./user-service.dto"), exports);
18
+ __exportStar(require("./auth-service.dto"), exports);
19
+ __exportStar(require("./response.dto"), exports);
@@ -0,0 +1,55 @@
1
+ export interface ApiMeta {
2
+ requestId: string;
3
+ timestamp: string;
4
+ }
5
+ export interface ApiSuccessResponse<T> {
6
+ success: true;
7
+ data: T;
8
+ meta: ApiMeta;
9
+ }
10
+ export interface ApiErrorResponse {
11
+ success: false;
12
+ error: {
13
+ code: string;
14
+ message: string;
15
+ details?: unknown;
16
+ };
17
+ meta: ApiMeta;
18
+ }
19
+ /**
20
+ * Returned on login / token refresh.
21
+ * accessToken goes in the response body.
22
+ * refreshToken goes in an HttpOnly cookie — not in the body.
23
+ * Only include refreshToken here if your client explicitly needs it
24
+ * (e.g. mobile clients that can't use cookies).
25
+ */
26
+ export interface TokensResponseDto {
27
+ accessToken: string;
28
+ }
29
+ /** Generic message — use for simple confirmations */
30
+ export interface MessageResponseDto {
31
+ message: string;
32
+ }
33
+ /**
34
+ * Generic action confirmation — use when the client needs to know
35
+ * which action was performed (e.g. in a polling or event-driven context).
36
+ *
37
+ * action: machine-readable string, e.g. "account.suspended", "session.revoked"
38
+ * message: human-readable description
39
+ */
40
+ export interface ActionResponseDto {
41
+ action: string;
42
+ message: string;
43
+ }
44
+ export interface PaginationMeta {
45
+ page: number;
46
+ pageSize: number;
47
+ totalItems: number;
48
+ totalPages: number;
49
+ hasNext: boolean;
50
+ hasPrev: boolean;
51
+ }
52
+ export interface PaginatedResponseDto<T> {
53
+ items: T[];
54
+ pagination: PaginationMeta;
55
+ }
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ /* ====================================================================
3
+ RESPONSE DTOs
4
+ Shared HTTP response shapes used across all services.
5
+ ==================================================================== */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,50 @@
1
+ import { AccountStatus, OrganizationRole, MembershipStatus, OrganizationStatus, Theme, Currency } from "../enums";
2
+ export interface UserDto {
3
+ id: string;
4
+ email: string;
5
+ status: AccountStatus;
6
+ createdAt: Date;
7
+ updatedAt: Date;
8
+ }
9
+ export interface UserProfileDto {
10
+ id: string;
11
+ userId: string;
12
+ displayName: string | null;
13
+ avatarUrl: string | null;
14
+ jobTitle: string | null;
15
+ bio: string | null;
16
+ timezone: string | null;
17
+ locale: string;
18
+ country: string | null;
19
+ pronouns: string | null;
20
+ createdAt: Date;
21
+ updatedAt: Date;
22
+ }
23
+ export interface UserPreferencesDto {
24
+ id: string;
25
+ userId: string;
26
+ theme: Theme;
27
+ language: string;
28
+ currency: Currency;
29
+ emailAlerts: boolean;
30
+ createdAt: Date;
31
+ updatedAt: Date;
32
+ }
33
+ export interface OrganizationDto {
34
+ id: string;
35
+ name: string;
36
+ slug: string;
37
+ status: OrganizationStatus;
38
+ createdAt: Date;
39
+ updatedAt: Date;
40
+ deletedAt: Date | null;
41
+ }
42
+ export interface OrganizationMemberDto {
43
+ id: string;
44
+ userId: string;
45
+ organizationId: string;
46
+ role: OrganizationRole;
47
+ status: MembershipStatus;
48
+ createdAt: Date;
49
+ updatedAt: Date;
50
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,42 @@
1
+ /**
2
+ * DOMAIN STATUS & CONFIGURATION ENUMS
3
+ * ──────────────────────────────────────
4
+ * General-purpose enums for entity lifecycle, UI preferences, and
5
+ * configuration. Permission-related enums live in permissions.types.ts.
6
+ */
7
+ export declare enum AccountStatus {
8
+ ACTIVE = "ACTIVE",
9
+ SUSPENDED = "SUSPENDED",// Access revoked, data retained, reversible
10
+ DELETED = "DELETED"
11
+ }
12
+ export declare enum OrganizationStatus {
13
+ ACTIVE = "ACTIVE",
14
+ SUSPENDED = "SUSPENDED",// Platform-level suspension (non-payment, policy)
15
+ CLOSED = "CLOSED"
16
+ }
17
+ /**
18
+ * OrganizationRole lives in permissions.types.ts alongside OrgPermission
19
+ * so the role → permission map stays co-located with the role definition.
20
+ * Re-exported from enums/index.ts for convenience.
21
+ */
22
+ export declare enum MembershipStatus {
23
+ PENDING = "PENDING",
24
+ ACTIVE = "ACTIVE",
25
+ SUSPENDED = "SUSPENDED",
26
+ REMOVED = "REMOVED"
27
+ }
28
+ export declare enum Theme {
29
+ LIGHT = "LIGHT",
30
+ DARK = "DARK",
31
+ SYSTEM = "SYSTEM"
32
+ }
33
+ export declare enum Currency {
34
+ USD = "USD",// US Dollar — default, all cloud providers
35
+ EUR = "EUR",// Euro — AWS/GCP/Azure EU regions
36
+ GBP = "GBP",// British Pound — AWS/GCP/Azure UK regions
37
+ INR = "INR",// Indian Rupee — AWS/GCP/Azure AP south regions
38
+ AUD = "AUD",// Australian Dollar
39
+ CAD = "CAD",// Canadian Dollar
40
+ JPY = "JPY",// Japanese Yen
41
+ SGD = "SGD"
42
+ }
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ /**
3
+ * DOMAIN STATUS & CONFIGURATION ENUMS
4
+ * ──────────────────────────────────────
5
+ * General-purpose enums for entity lifecycle, UI preferences, and
6
+ * configuration. Permission-related enums live in permissions.types.ts.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.Currency = exports.Theme = exports.MembershipStatus = exports.OrganizationStatus = exports.AccountStatus = void 0;
10
+ /* ====================================================================
11
+ ACCOUNT
12
+ Lifecycle states for a platform account (auth domain).
13
+ Replaces the duplicate UserStatus — there is only Account in auth.
14
+ ==================================================================== */
15
+ var AccountStatus;
16
+ (function (AccountStatus) {
17
+ AccountStatus["ACTIVE"] = "ACTIVE";
18
+ AccountStatus["SUSPENDED"] = "SUSPENDED";
19
+ AccountStatus["DELETED"] = "DELETED";
20
+ })(AccountStatus || (exports.AccountStatus = AccountStatus = {}));
21
+ /* ====================================================================
22
+ ORGANIZATION (future work — defined now for type completeness)
23
+ ==================================================================== */
24
+ var OrganizationStatus;
25
+ (function (OrganizationStatus) {
26
+ OrganizationStatus["ACTIVE"] = "ACTIVE";
27
+ OrganizationStatus["SUSPENDED"] = "SUSPENDED";
28
+ OrganizationStatus["CLOSED"] = "CLOSED";
29
+ })(OrganizationStatus || (exports.OrganizationStatus = OrganizationStatus = {}));
30
+ /**
31
+ * OrganizationRole lives in permissions.types.ts alongside OrgPermission
32
+ * so the role → permission map stays co-located with the role definition.
33
+ * Re-exported from enums/index.ts for convenience.
34
+ */
35
+ /* ====================================================================
36
+ MEMBERSHIP (future work)
37
+ Tracks a user's membership state within an organization.
38
+
39
+ PENDING — invite sent, not yet accepted
40
+ ACTIVE — full org member
41
+ SUSPENDED — access revoked by org admin, invite not cancelled
42
+ REMOVED — explicitly removed by admin (different from suspended —
43
+ removed members must be re-invited to regain access)
44
+ ==================================================================== */
45
+ var MembershipStatus;
46
+ (function (MembershipStatus) {
47
+ MembershipStatus["PENDING"] = "PENDING";
48
+ MembershipStatus["ACTIVE"] = "ACTIVE";
49
+ MembershipStatus["SUSPENDED"] = "SUSPENDED";
50
+ MembershipStatus["REMOVED"] = "REMOVED";
51
+ })(MembershipStatus || (exports.MembershipStatus = MembershipStatus = {}));
52
+ /* ====================================================================
53
+ UI PREFERENCES
54
+ ==================================================================== */
55
+ var Theme;
56
+ (function (Theme) {
57
+ Theme["LIGHT"] = "LIGHT";
58
+ Theme["DARK"] = "DARK";
59
+ Theme["SYSTEM"] = "SYSTEM";
60
+ })(Theme || (exports.Theme = Theme = {}));
61
+ /* ====================================================================
62
+ CURRENCY
63
+ Cloud cost monitoring — users see costs in their preferred currency.
64
+ Amounts are stored in USD (base currency) and converted at display time.
65
+
66
+ Expand this list as you add cloud provider regions:
67
+ AUD, CAD, JPY, SGD, BRL, KRW, SEK, NOK, CHF, MXN ...
68
+ ==================================================================== */
69
+ var Currency;
70
+ (function (Currency) {
71
+ Currency["USD"] = "USD";
72
+ Currency["EUR"] = "EUR";
73
+ Currency["GBP"] = "GBP";
74
+ Currency["INR"] = "INR";
75
+ Currency["AUD"] = "AUD";
76
+ Currency["CAD"] = "CAD";
77
+ Currency["JPY"] = "JPY";
78
+ Currency["SGD"] = "SGD";
79
+ })(Currency || (exports.Currency = Currency = {}));
@@ -1,3 +1,2 @@
1
- export * from "./user-service.enums";
2
- export * from "./auth-service.enums";
3
- export * from "./permissions.types";
1
+ export * from "./permissions.enums";
2
+ export * from "./domain.enums";
@@ -14,6 +14,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./user-service.enums"), exports);
18
- __exportStar(require("./auth-service.enums"), exports);
19
- __exportStar(require("./permissions.types"), exports);
17
+ __exportStar(require("./permissions.enums"), exports);
18
+ __exportStar(require("./domain.enums"), exports);
@@ -0,0 +1,124 @@
1
+ /**
2
+ * ACCOUNT ROLES
3
+ * ──────────────
4
+ * Platform-level roles assigned to every account.
5
+ * Ordered from highest to lowest privilege.
6
+ *
7
+ * SUPERADMIN — Full platform control. Internal engineering / founders only.
8
+ * Can impersonate users, access all data, manage platform config.
9
+ *
10
+ * ADMIN — Platform operations team. Can manage users, view system health,
11
+ * handle support escalations. Cannot touch billing infrastructure.
12
+ *
13
+ * SUPPORT — Customer support agents. Read-only access to user accounts
14
+ * and cloud cost data for support purposes. Cannot modify anything.
15
+ *
16
+ * MODERATOR — Content / alert moderation (future). Included now so the
17
+ * role exists in the system before the feature ships.
18
+ *
19
+ * USER — Standard authenticated user. Accesses only their own data.
20
+ * All cloud cost features are gated at the service level.
21
+ */
22
+ export declare enum AccountRole {
23
+ SUPERADMIN = "SUPERADMIN",
24
+ ADMIN = "ADMIN",
25
+ SUPPORT = "SUPPORT",
26
+ MODERATOR = "MODERATOR",
27
+ USER = "USER"
28
+ }
29
+ /**
30
+ * GLOBAL PERMISSIONS
31
+ * ───────────────────
32
+ * Platform-wide permissions derived from AccountRole.
33
+ * These are checked at the gateway / service middleware level.
34
+ *
35
+ * Naming convention: VERB_NOUN or VERB_SCOPE_NOUN
36
+ *
37
+ * Account management
38
+ * MANAGE_ACCOUNTS — Create, update, suspend, delete any account
39
+ * VIEW_ANY_ACCOUNT — Read any account's profile and metadata
40
+ * IMPERSONATE_ACCOUNT — Act as another user (SUPERADMIN only — support tooling)
41
+ * SUSPEND_ACCOUNT — Suspend / unsuspend an account without full delete
42
+ * DELETE_ACCOUNT — Hard delete an account and all associated data
43
+ *
44
+ * Cloud cost data (platform-level, not per-org)
45
+ * VIEW_ANY_COST_DATA — Read any user's cloud cost reports (support/admin use)
46
+ * EXPORT_ANY_COST_DATA — Export cost data for any user (compliance, support)
47
+ * MANAGE_COST_ALERTS — Create/edit/delete cost alert rules platform-wide
48
+ *
49
+ * Platform operations
50
+ * VIEW_SYSTEM_LOGS — Access platform audit logs and system events
51
+ * VIEW_SYSTEM_HEALTH — Read service health, metrics dashboards
52
+ * MANAGE_PLATFORM_CONFIG — Modify platform-wide settings (limits, features)
53
+ *
54
+ * Support tooling
55
+ * SUPPORT_VIEW — Read-only access to user data for support purposes
56
+ * SUPPORT_WRITE — Ability to make support-sanctioned changes on behalf of users
57
+ *
58
+ * Future-proofing (define now, assign later)
59
+ * MANAGE_BILLING — Access to subscription and billing management
60
+ * MODERATE_CONTENT — Moderate user-generated content (alerts, comments, etc.)
61
+ * MANAGE_INTEGRATIONS — Manage platform-level cloud provider integrations
62
+ */
63
+ export declare enum GlobalPermission {
64
+ MANAGE_ACCOUNTS = "MANAGE_ACCOUNTS",
65
+ VIEW_ANY_ACCOUNT = "VIEW_ANY_ACCOUNT",
66
+ IMPERSONATE_ACCOUNT = "IMPERSONATE_ACCOUNT",
67
+ SUSPEND_ACCOUNT = "SUSPEND_ACCOUNT",
68
+ DELETE_ACCOUNT = "DELETE_ACCOUNT",
69
+ VIEW_ANY_COST_DATA = "VIEW_ANY_COST_DATA",
70
+ EXPORT_ANY_COST_DATA = "EXPORT_ANY_COST_DATA",
71
+ MANAGE_COST_ALERTS = "MANAGE_COST_ALERTS",
72
+ VIEW_SYSTEM_LOGS = "VIEW_SYSTEM_LOGS",
73
+ VIEW_SYSTEM_HEALTH = "VIEW_SYSTEM_HEALTH",
74
+ MANAGE_PLATFORM_CONFIG = "MANAGE_PLATFORM_CONFIG",
75
+ SUPPORT_VIEW = "SUPPORT_VIEW",
76
+ SUPPORT_WRITE = "SUPPORT_WRITE",
77
+ MANAGE_BILLING = "MANAGE_BILLING",
78
+ MODERATE_CONTENT = "MODERATE_CONTENT",
79
+ MANAGE_INTEGRATIONS = "MANAGE_INTEGRATIONS"
80
+ }
81
+ /**
82
+ * ORGANIZATION ROLES (future work)
83
+ * ────────────────────────────────────
84
+ * Defined now so the type system is ready when org support ships.
85
+ * No permissions are assigned yet — see orgRolePermissions below.
86
+ *
87
+ * OWNER — Created the org. Full control, including deletion and billing.
88
+ * ADMIN — Manages members and org settings. Cannot delete the org.
89
+ * EDITOR — Can create/edit cost reports and dashboards within the org.
90
+ * VIEWER — Read-only access to org cost data.
91
+ * BILLING — Dedicated billing contact. Access to invoices and payment only.
92
+ */
93
+ export declare enum OrganizationRole {
94
+ OWNER = "OWNER",
95
+ ADMIN = "ADMIN",
96
+ EDITOR = "EDITOR",
97
+ VIEWER = "VIEWER",
98
+ BILLING = "BILLING"
99
+ }
100
+ /**
101
+ * ORG PERMISSIONS (future work)
102
+ * ────────────────────────────────
103
+ * Granular org-scoped permissions. Checked by tenant middleware in each
104
+ * service via DB lookup — NOT in the JWT (org membership changes too
105
+ * frequently to embed reliably).
106
+ *
107
+ * Naming: VERB_RESOURCE
108
+ */
109
+ export declare enum OrgPermission {
110
+ DELETE_ORG = "DELETE_ORG",
111
+ MANAGE_ORG_SETTINGS = "MANAGE_ORG_SETTINGS",
112
+ INVITE_MEMBERS = "INVITE_MEMBERS",
113
+ REMOVE_MEMBERS = "REMOVE_MEMBERS",
114
+ CHANGE_MEMBER_ROLES = "CHANGE_MEMBER_ROLES",
115
+ VIEW_MEMBERS = "VIEW_MEMBERS",
116
+ VIEW_COST_DATA = "VIEW_COST_DATA",
117
+ EXPORT_COST_DATA = "EXPORT_COST_DATA",
118
+ MANAGE_COST_REPORTS = "MANAGE_COST_REPORTS",
119
+ MANAGE_ALERTS = "MANAGE_ALERTS",
120
+ MANAGE_CLOUD_ACCOUNTS = "MANAGE_CLOUD_ACCOUNTS",
121
+ VIEW_CLOUD_ACCOUNTS = "VIEW_CLOUD_ACCOUNTS",
122
+ VIEW_BILLING = "VIEW_BILLING",
123
+ MANAGE_BILLING = "MANAGE_BILLING"
124
+ }
@@ -0,0 +1,141 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OrgPermission = exports.OrganizationRole = exports.GlobalPermission = exports.AccountRole = void 0;
4
+ /**
5
+ * ACCOUNT ROLES
6
+ * ──────────────
7
+ * Platform-level roles assigned to every account.
8
+ * Ordered from highest to lowest privilege.
9
+ *
10
+ * SUPERADMIN — Full platform control. Internal engineering / founders only.
11
+ * Can impersonate users, access all data, manage platform config.
12
+ *
13
+ * ADMIN — Platform operations team. Can manage users, view system health,
14
+ * handle support escalations. Cannot touch billing infrastructure.
15
+ *
16
+ * SUPPORT — Customer support agents. Read-only access to user accounts
17
+ * and cloud cost data for support purposes. Cannot modify anything.
18
+ *
19
+ * MODERATOR — Content / alert moderation (future). Included now so the
20
+ * role exists in the system before the feature ships.
21
+ *
22
+ * USER — Standard authenticated user. Accesses only their own data.
23
+ * All cloud cost features are gated at the service level.
24
+ */
25
+ var AccountRole;
26
+ (function (AccountRole) {
27
+ AccountRole["SUPERADMIN"] = "SUPERADMIN";
28
+ AccountRole["ADMIN"] = "ADMIN";
29
+ AccountRole["SUPPORT"] = "SUPPORT";
30
+ AccountRole["MODERATOR"] = "MODERATOR";
31
+ AccountRole["USER"] = "USER";
32
+ })(AccountRole || (exports.AccountRole = AccountRole = {}));
33
+ /**
34
+ * GLOBAL PERMISSIONS
35
+ * ───────────────────
36
+ * Platform-wide permissions derived from AccountRole.
37
+ * These are checked at the gateway / service middleware level.
38
+ *
39
+ * Naming convention: VERB_NOUN or VERB_SCOPE_NOUN
40
+ *
41
+ * Account management
42
+ * MANAGE_ACCOUNTS — Create, update, suspend, delete any account
43
+ * VIEW_ANY_ACCOUNT — Read any account's profile and metadata
44
+ * IMPERSONATE_ACCOUNT — Act as another user (SUPERADMIN only — support tooling)
45
+ * SUSPEND_ACCOUNT — Suspend / unsuspend an account without full delete
46
+ * DELETE_ACCOUNT — Hard delete an account and all associated data
47
+ *
48
+ * Cloud cost data (platform-level, not per-org)
49
+ * VIEW_ANY_COST_DATA — Read any user's cloud cost reports (support/admin use)
50
+ * EXPORT_ANY_COST_DATA — Export cost data for any user (compliance, support)
51
+ * MANAGE_COST_ALERTS — Create/edit/delete cost alert rules platform-wide
52
+ *
53
+ * Platform operations
54
+ * VIEW_SYSTEM_LOGS — Access platform audit logs and system events
55
+ * VIEW_SYSTEM_HEALTH — Read service health, metrics dashboards
56
+ * MANAGE_PLATFORM_CONFIG — Modify platform-wide settings (limits, features)
57
+ *
58
+ * Support tooling
59
+ * SUPPORT_VIEW — Read-only access to user data for support purposes
60
+ * SUPPORT_WRITE — Ability to make support-sanctioned changes on behalf of users
61
+ *
62
+ * Future-proofing (define now, assign later)
63
+ * MANAGE_BILLING — Access to subscription and billing management
64
+ * MODERATE_CONTENT — Moderate user-generated content (alerts, comments, etc.)
65
+ * MANAGE_INTEGRATIONS — Manage platform-level cloud provider integrations
66
+ */
67
+ var GlobalPermission;
68
+ (function (GlobalPermission) {
69
+ // Account management
70
+ GlobalPermission["MANAGE_ACCOUNTS"] = "MANAGE_ACCOUNTS";
71
+ GlobalPermission["VIEW_ANY_ACCOUNT"] = "VIEW_ANY_ACCOUNT";
72
+ GlobalPermission["IMPERSONATE_ACCOUNT"] = "IMPERSONATE_ACCOUNT";
73
+ GlobalPermission["SUSPEND_ACCOUNT"] = "SUSPEND_ACCOUNT";
74
+ GlobalPermission["DELETE_ACCOUNT"] = "DELETE_ACCOUNT";
75
+ // Cloud cost data (platform-level)
76
+ GlobalPermission["VIEW_ANY_COST_DATA"] = "VIEW_ANY_COST_DATA";
77
+ GlobalPermission["EXPORT_ANY_COST_DATA"] = "EXPORT_ANY_COST_DATA";
78
+ GlobalPermission["MANAGE_COST_ALERTS"] = "MANAGE_COST_ALERTS";
79
+ // Platform operations
80
+ GlobalPermission["VIEW_SYSTEM_LOGS"] = "VIEW_SYSTEM_LOGS";
81
+ GlobalPermission["VIEW_SYSTEM_HEALTH"] = "VIEW_SYSTEM_HEALTH";
82
+ GlobalPermission["MANAGE_PLATFORM_CONFIG"] = "MANAGE_PLATFORM_CONFIG";
83
+ // Support tooling
84
+ GlobalPermission["SUPPORT_VIEW"] = "SUPPORT_VIEW";
85
+ GlobalPermission["SUPPORT_WRITE"] = "SUPPORT_WRITE";
86
+ // Future — define now so they exist in the type system before the features ship
87
+ GlobalPermission["MANAGE_BILLING"] = "MANAGE_BILLING";
88
+ GlobalPermission["MODERATE_CONTENT"] = "MODERATE_CONTENT";
89
+ GlobalPermission["MANAGE_INTEGRATIONS"] = "MANAGE_INTEGRATIONS";
90
+ })(GlobalPermission || (exports.GlobalPermission = GlobalPermission = {}));
91
+ /**
92
+ * ORGANIZATION ROLES (future work)
93
+ * ────────────────────────────────────
94
+ * Defined now so the type system is ready when org support ships.
95
+ * No permissions are assigned yet — see orgRolePermissions below.
96
+ *
97
+ * OWNER — Created the org. Full control, including deletion and billing.
98
+ * ADMIN — Manages members and org settings. Cannot delete the org.
99
+ * EDITOR — Can create/edit cost reports and dashboards within the org.
100
+ * VIEWER — Read-only access to org cost data.
101
+ * BILLING — Dedicated billing contact. Access to invoices and payment only.
102
+ */
103
+ var OrganizationRole;
104
+ (function (OrganizationRole) {
105
+ OrganizationRole["OWNER"] = "OWNER";
106
+ OrganizationRole["ADMIN"] = "ADMIN";
107
+ OrganizationRole["EDITOR"] = "EDITOR";
108
+ OrganizationRole["VIEWER"] = "VIEWER";
109
+ OrganizationRole["BILLING"] = "BILLING";
110
+ })(OrganizationRole || (exports.OrganizationRole = OrganizationRole = {}));
111
+ /**
112
+ * ORG PERMISSIONS (future work)
113
+ * ────────────────────────────────
114
+ * Granular org-scoped permissions. Checked by tenant middleware in each
115
+ * service via DB lookup — NOT in the JWT (org membership changes too
116
+ * frequently to embed reliably).
117
+ *
118
+ * Naming: VERB_RESOURCE
119
+ */
120
+ var OrgPermission;
121
+ (function (OrgPermission) {
122
+ // Org management
123
+ OrgPermission["DELETE_ORG"] = "DELETE_ORG";
124
+ OrgPermission["MANAGE_ORG_SETTINGS"] = "MANAGE_ORG_SETTINGS";
125
+ // Member management
126
+ OrgPermission["INVITE_MEMBERS"] = "INVITE_MEMBERS";
127
+ OrgPermission["REMOVE_MEMBERS"] = "REMOVE_MEMBERS";
128
+ OrgPermission["CHANGE_MEMBER_ROLES"] = "CHANGE_MEMBER_ROLES";
129
+ OrgPermission["VIEW_MEMBERS"] = "VIEW_MEMBERS";
130
+ // Cost data within org
131
+ OrgPermission["VIEW_COST_DATA"] = "VIEW_COST_DATA";
132
+ OrgPermission["EXPORT_COST_DATA"] = "EXPORT_COST_DATA";
133
+ OrgPermission["MANAGE_COST_REPORTS"] = "MANAGE_COST_REPORTS";
134
+ OrgPermission["MANAGE_ALERTS"] = "MANAGE_ALERTS";
135
+ // Integrations within org
136
+ OrgPermission["MANAGE_CLOUD_ACCOUNTS"] = "MANAGE_CLOUD_ACCOUNTS";
137
+ OrgPermission["VIEW_CLOUD_ACCOUNTS"] = "VIEW_CLOUD_ACCOUNTS";
138
+ // Billing within org
139
+ OrgPermission["VIEW_BILLING"] = "VIEW_BILLING";
140
+ OrgPermission["MANAGE_BILLING"] = "MANAGE_BILLING";
141
+ })(OrgPermission || (exports.OrgPermission = OrgPermission = {}));
@@ -1,6 +1,23 @@
1
+ /**
2
+ * APP ERROR
3
+ * ──────────
4
+ * Base class for all known operational errors.
5
+ * Subclasses map to specific HTTP status codes and error codes.
6
+ *
7
+ * GlobalErrorHandler catches instanceof AppError and maps it to a
8
+ * structured error response — no duck-typing, no accidental matches.
9
+ *
10
+ * Changes vs original:
11
+ * - details?: any → details?: unknown
12
+ * `any` disabled TypeScript's type checking on the most variable field.
13
+ * Callers that need a specific details shape should cast after instanceof.
14
+ * - Object.freeze(this) retained — prevents accidental mutation of thrown errors.
15
+ * Note: freeze is shallow. If details is an object, its contents are mutable.
16
+ * This is acceptable — details is for logging/response context, not program logic.
17
+ */
1
18
  export declare class AppError extends Error {
2
19
  readonly code: string;
3
20
  readonly statusCode: number;
4
- readonly details?: any;
5
- constructor(code: string, statusCode: number, message: string, details?: any);
21
+ readonly details?: unknown;
22
+ constructor(code: string, statusCode: number, message: string, details?: unknown);
6
23
  }
@@ -1,6 +1,23 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AppError = void 0;
4
+ /**
5
+ * APP ERROR
6
+ * ──────────
7
+ * Base class for all known operational errors.
8
+ * Subclasses map to specific HTTP status codes and error codes.
9
+ *
10
+ * GlobalErrorHandler catches instanceof AppError and maps it to a
11
+ * structured error response — no duck-typing, no accidental matches.
12
+ *
13
+ * Changes vs original:
14
+ * - details?: any → details?: unknown
15
+ * `any` disabled TypeScript's type checking on the most variable field.
16
+ * Callers that need a specific details shape should cast after instanceof.
17
+ * - Object.freeze(this) retained — prevents accidental mutation of thrown errors.
18
+ * Note: freeze is shallow. If details is an object, its contents are mutable.
19
+ * This is acceptable — details is for logging/response context, not program logic.
20
+ */
4
21
  class AppError extends Error {
5
22
  constructor(code, statusCode, message, details) {
6
23
  super(message);
@@ -8,8 +25,6 @@ class AppError extends Error {
8
25
  this.statusCode = statusCode;
9
26
  this.details = details;
10
27
  this.name = this.constructor.name;
11
- // A simple runtime check is all you need now.
12
- // TypeScript knows this exists because of @types/node.
13
28
  if (typeof Error.captureStackTrace === "function") {
14
29
  Error.captureStackTrace(this, this.constructor);
15
30
  }
@@ -1,4 +1,16 @@
1
1
  import { AppError } from "./app-error";
2
+ /**
3
+ * HTTP ERRORS
4
+ * ────────────
5
+ * Typed subclasses of AppError for every common HTTP error status.
6
+ * GlobalErrorHandler catches these via instanceof AppError and maps
7
+ * statusCode + code directly to the response.
8
+ *
9
+ * Usage:
10
+ * throw new NotFoundError("Account not found");
11
+ * throw new ConflictError("Email already in use");
12
+ * throw new BadRequestError("Invalid input", { field: "email" });
13
+ */
2
14
  export declare class BadRequestError extends AppError {
3
15
  constructor(message?: string, details?: unknown);
4
16
  }
@@ -17,6 +29,12 @@ export declare class ConflictError extends AppError {
17
29
  export declare class UnprocessableEntityError extends AppError {
18
30
  constructor(message?: string, details?: unknown);
19
31
  }
32
+ export declare class TooManyRequestsError extends AppError {
33
+ constructor(message?: string, details?: unknown);
34
+ }
20
35
  export declare class InternalServerError extends AppError {
21
36
  constructor(message?: string, details?: unknown);
22
37
  }
38
+ export declare class ServiceUnavailableError extends AppError {
39
+ constructor(message?: string, details?: unknown);
40
+ }