@hichchi/nest-connector 0.0.7 → 0.0.8

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/auth.cjs.js CHANGED
@@ -33,7 +33,27 @@ var error_responses = require('./error.responses.cjs.js');
33
33
  * }
34
34
  * ```
35
35
  */
36
- const TENANT_HEADER_KEY = "x-tenant";
36
+ const HEADER_TENANT_KEY = "x-tenant";
37
+ /**
38
+ * Header key for tenant identifier propagation.
39
+ *
40
+ * This constant defines the HTTP header used to pass a stable tenant identifier
41
+ * (for example, an internal ID or UUID) in requests across services.
42
+ *
43
+ * Use this key when your auth/tenant resolution flow depends on tenant IDs
44
+ * rather than tenant names or slugs.
45
+ *
46
+ * @example
47
+ * ```typescript
48
+ * // Extract tenant ID from request headers in a guard/controller
49
+ * const tenantId = req.header(HEADER_TENANT_ID_KEY);
50
+ *
51
+ * if (!tenantId) {
52
+ * throw new UnauthorizedException("Missing tenant id header");
53
+ * }
54
+ * ```
55
+ */
56
+ const HEADER_TENANT_ID_KEY = "x-tenant-id";
37
57
 
38
58
  /**
39
59
  * Authentication Endpoints Enum
@@ -1325,5 +1345,6 @@ function isRoleObject(role) {
1325
1345
 
1326
1346
  exports.AuthErrors = AuthErrors;
1327
1347
  exports.AuthSuccessResponses = AuthSuccessResponses;
1328
- exports.TENANT_HEADER_KEY = TENANT_HEADER_KEY;
1348
+ exports.HEADER_TENANT_ID_KEY = HEADER_TENANT_ID_KEY;
1349
+ exports.HEADER_TENANT_KEY = HEADER_TENANT_KEY;
1329
1350
  exports.isRoleObject = isRoleObject;
package/auth.esm.js CHANGED
@@ -31,7 +31,27 @@ import { e as HttpServerErrorStatus, H as HttpClientErrorStatus, f as HttpSucces
31
31
  * }
32
32
  * ```
33
33
  */
34
- const TENANT_HEADER_KEY = "x-tenant";
34
+ const HEADER_TENANT_KEY = "x-tenant";
35
+ /**
36
+ * Header key for tenant identifier propagation.
37
+ *
38
+ * This constant defines the HTTP header used to pass a stable tenant identifier
39
+ * (for example, an internal ID or UUID) in requests across services.
40
+ *
41
+ * Use this key when your auth/tenant resolution flow depends on tenant IDs
42
+ * rather than tenant names or slugs.
43
+ *
44
+ * @example
45
+ * ```typescript
46
+ * // Extract tenant ID from request headers in a guard/controller
47
+ * const tenantId = req.header(HEADER_TENANT_ID_KEY);
48
+ *
49
+ * if (!tenantId) {
50
+ * throw new UnauthorizedException("Missing tenant id header");
51
+ * }
52
+ * ```
53
+ */
54
+ const HEADER_TENANT_ID_KEY = "x-tenant-id";
35
55
 
36
56
  /**
37
57
  * Authentication Endpoints Enum
@@ -1321,4 +1341,4 @@ function isRoleObject(role) {
1321
1341
  return Boolean(role) && typeof role === "object" && Boolean("name" in role);
1322
1342
  }
1323
1343
 
1324
- export { AuthEndpoint, AuthErrorResponseCode, AuthErrors, AuthField, AuthMethod, AuthProvider, AuthStrategy, AuthSuccessResponseCode, AuthSuccessResponses, TENANT_HEADER_KEY, isRoleObject };
1344
+ export { AuthEndpoint, AuthErrorResponseCode, AuthErrors, AuthField, AuthMethod, AuthProvider, AuthStrategy, AuthSuccessResponseCode, AuthSuccessResponses, HEADER_TENANT_ID_KEY, HEADER_TENANT_KEY, isRoleObject };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hichchi/nest-connector",
3
3
  "description": "Comprehensive NestJS connector library providing standardized HTTP responses, authentication interfaces, CRUD operations, and shared utilities for the Hichchi ecosystem",
4
- "version": "0.0.7",
4
+ "version": "0.0.8",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
package/readme-top.md CHANGED
@@ -112,6 +112,11 @@ npm install class-validator class-transformer
112
112
  - 📊 **Status Code Management** - Organized HTTP status code handling
113
113
  - 🔧 **Type-Safe Responses** - Full TypeScript support for response structures
114
114
 
115
+ ### 🔐 Authentication Interfaces
116
+ - 👤 **Typed Auth User Interface** - Generic `User<Role, Permission, Tenant>` typing for role/permission/tenant-aware authentication flows
117
+ - 🏢 **Tenant Interface Support** - Dedicated tenant interfaces with owner/member user relationships for multi-tenant domains
118
+ - 🧩 **Composed Auth Models** - Consistent `Role`, `User`, and `Tenant` interface exports for shared contracts across services
119
+
115
120
  ### 🎨 Developer Experience
116
121
  - 📝 **Comprehensive Documentation** - Detailed JSDoc comments for all interfaces
117
122
  - 🔍 **IntelliSense Support** - Full IDE autocomplete and type checking
@@ -120,6 +125,7 @@ npm install class-validator class-transformer
120
125
 
121
126
  ### 🔧 Advanced Features
122
127
  - 🏷️ **User Info Interfaces** - Standardized user information structures
128
+ - 🔀 **Clear Context Separation** - Base `UserInfo` for identity data, auth `User` interface for tenant-aware authentication context
123
129
  - 📦 **Modular Design** - Import only what you need
124
130
  - 🔄 **Extensible Architecture** - Easy to extend with custom response types
125
131
  - 🎪 **Framework Agnostic Types** - Core interfaces can be used beyond NestJS
@@ -29,4 +29,24 @@
29
29
  * }
30
30
  * ```
31
31
  */
32
- export declare const TENANT_HEADER_KEY = "x-tenant";
32
+ export declare const HEADER_TENANT_KEY = "x-tenant";
33
+ /**
34
+ * Header key for tenant identifier propagation.
35
+ *
36
+ * This constant defines the HTTP header used to pass a stable tenant identifier
37
+ * (for example, an internal ID or UUID) in requests across services.
38
+ *
39
+ * Use this key when your auth/tenant resolution flow depends on tenant IDs
40
+ * rather than tenant names or slugs.
41
+ *
42
+ * @example
43
+ * ```typescript
44
+ * // Extract tenant ID from request headers in a guard/controller
45
+ * const tenantId = req.header(HEADER_TENANT_ID_KEY);
46
+ *
47
+ * if (!tenantId) {
48
+ * throw new UnauthorizedException("Missing tenant id header");
49
+ * }
50
+ * ```
51
+ */
52
+ export declare const HEADER_TENANT_ID_KEY = "x-tenant-id";
@@ -1,6 +1,7 @@
1
1
  export * from "./dtos";
2
2
  export * from "./google-profile.interface";
3
3
  export * from "./role.interface";
4
+ export * from "./tenant.interface";
4
5
  export * from "./user.interface";
5
6
  export * from "./tokens.interface";
6
7
  export * from "./response.interfaces";
@@ -1,5 +1,6 @@
1
- import { Model } from "../../crud";
1
+ import { EntityId, Model } from "../../crud";
2
2
  import { User } from "./user.interface";
3
+ import { Tenant } from "./tenant.interface";
3
4
  export interface RoleBase<R extends string = string, P extends string = string> {
4
5
  /**
5
6
  * Human-readable name of the role.
@@ -42,5 +43,7 @@ export interface RoleBase<R extends string = string, P extends string = string>
42
43
  * @see {@link User} Interface for user information which references roles
43
44
  */
44
45
  export interface Role<R extends string = string, P extends string = string> extends RoleBase<R, P>, Model {
46
+ tenant?: Tenant | null;
47
+ tenantId?: EntityId | null;
45
48
  users: User<R, P>[] | null;
46
49
  }
@@ -0,0 +1,60 @@
1
+ import { EntityId, Model } from "../../crud";
2
+ import { Role, TenantSlug } from "../auth";
3
+ import { User } from "./user.interface";
4
+ /**
5
+ * Base interface defining core tenant identity properties.
6
+ *
7
+ * This interface contains the minimum identifying information needed to
8
+ * represent a tenant in a multi-tenant system.
9
+ */
10
+ export interface TenantBase {
11
+ /**
12
+ * Human-readable tenant name.
13
+ *
14
+ * This value is typically displayed in administrative interfaces and
15
+ * organization selectors.
16
+ */
17
+ name: string;
18
+ /**
19
+ * Unique slug used to identify the tenant in routes and context resolution.
20
+ *
21
+ * The slug should be stable and URL-friendly to support tenant-specific
22
+ * API and frontend paths.
23
+ */
24
+ slug: TenantSlug;
25
+ }
26
+ /**
27
+ * Interface representing a tenant entity in the authentication domain.
28
+ *
29
+ * Extends {@link TenantBase} with persistence fields from {@link Model} and
30
+ * ownership/member relationships to users.
31
+ *
32
+ * @interface Tenant
33
+ *
34
+ * @see {@link User} Interface for user information linked to tenants
35
+ */
36
+ export interface Tenant extends TenantBase, Model {
37
+ /**
38
+ * User who owns and manages the tenant.
39
+ *
40
+ * This value may be null when ownership has not been assigned yet.
41
+ */
42
+ owner: User | null;
43
+ /**
44
+ * ID of the user who owns and manages the tenant.
45
+ */
46
+ ownerId: EntityId | null;
47
+ /**
48
+ * Represents the roles associated with a user or entity.
49
+ * This can either be an array of Role objects or null if no roles are assigned.
50
+ *
51
+ * @type {Role[] | null}
52
+ */
53
+ roles: Role[] | null;
54
+ /**
55
+ * Users associated with this tenant.
56
+ *
57
+ * Contains the members that belong to the tenant context.
58
+ */
59
+ users: User[] | null;
60
+ }
@@ -3,6 +3,8 @@ import { Role } from "./role.interface";
3
3
  import { AuthProvider } from "../enums";
4
4
  import { EntityId, Model } from "../../crud";
5
5
  import { GoogleProfile } from "./google-profile.interface";
6
+ import { TenantSlug } from "../types";
7
+ import { Tenant } from "./tenant.interface";
6
8
  /**
7
9
  * Interface representing a user account in the authentication system.
8
10
  *
@@ -23,7 +25,7 @@ import { GoogleProfile } from "./google-profile.interface";
23
25
  * @see {@link Role} Interface defining user authorization roles
24
26
  * @see {@link AuthResponse} Authentication response containing user information
25
27
  */
26
- export interface User<R extends string = string, P extends string = string> extends UserInfo, Model {
28
+ export interface User<R extends string = string, P extends string = string, T extends string = TenantSlug> extends UserInfo, Model {
27
29
  /**
28
30
  * The user's email address.
29
31
  *
@@ -80,6 +82,22 @@ export interface User<R extends string = string, P extends string = string> exte
80
82
  * @see {@link Role} Interface defining user authorization roles
81
83
  */
82
84
  roleId?: EntityId | null;
85
+ /**
86
+ * Tenant associated with the user account.
87
+ *
88
+ * Supports either a full tenant object or a tenant slug identifier,
89
+ * depending on whether tenant relations are loaded.
90
+ *
91
+ * @see {@link Tenant} Interface defining tenant details
92
+ */
93
+ tenant: Tenant | T | null;
94
+ /**
95
+ * The unique identifier of the user's tenant.
96
+ *
97
+ * Optional foreign key reference to the tenant entity. This can be used
98
+ * for efficient tenant scoping without loading the full tenant object.
99
+ */
100
+ tenantId?: EntityId | null;
83
101
  /**
84
102
  * Indicates whether the user's email address has been verified.
85
103
  *
@@ -1,4 +1,3 @@
1
- import { TenantSlug } from "../../auth";
2
1
  import { EntityId } from "../../crud";
3
2
  /**
4
3
  * Interface representing essential user information.
@@ -41,16 +40,6 @@ export interface UserInfo {
41
40
  * and uniquely identifies the user across the entire system.
42
41
  */
43
42
  id: EntityId;
44
- /**
45
- * Represents the tenant associated with the current context.
46
- * The value can either be a tenant-specific identifier (TenantSlug) or null if no tenant is assigned.
47
- *
48
- * A TenantSlug is typically a unique string or slug representing a tenant in multi-tenant applications.
49
- * Null indicates the absence of a tenant in the current context.
50
- *
51
- * This variable is often used to scope application logic and data to a specific tenant.
52
- */
53
- tenant: TenantSlug | null;
54
43
  /**
55
44
  * The user's first name or given name.
56
45
  *
@@ -1,3 +1,7 @@
1
+ /**
2
+ * Primitive type
3
+ */
4
+ type Primitive = string | number | boolean | bigint | symbol | null | undefined;
1
5
  /**
2
6
  * Entity ID type
3
7
  *
@@ -31,5 +35,6 @@ export type EntityDeepPartial<T> = T extends Array<infer _U> ? never : T extends
31
35
  export type QueryDeepPartial<T extends {
32
36
  [P in keyof T]: unknown;
33
37
  } = object> = {
34
- [P in keyof T]?: T[P] extends Date ? never : T[P] extends (infer U)[] ? U extends object ? never : T[P] : T[P] extends object ? T[P] | T[P][] : QueryDeepPartial<T[P]>;
38
+ [P in keyof T]?: T[P] extends Date ? never : T[P] extends (infer U)[] ? U extends object ? never : T[P] : T[P] extends Primitive ? T[P] | T[P][] : QueryDeepPartial<T[P]>;
35
39
  };
40
+ export {};