@hichchi/nest-connector 0.0.4 → 0.0.5
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/CHANGELOG.md +6 -0
- package/README.md +169 -141
- package/auth.cjs.js +34 -0
- package/auth.esm.js +34 -1
- package/index.cjs.js +1 -0
- package/index.esm.js +1 -0
- package/package.json +1 -1
- package/src/auth/auth.d.ts +1 -0
- package/src/auth/constants/constants.d.ts +32 -0
- package/src/auth/constants/index.d.ts +1 -0
- package/src/auth/types/types.d.ts +10 -0
- package/src/common/interfaces/user-info.interface.d.ts +11 -0
package/auth.cjs.js
CHANGED
|
@@ -2,6 +2,39 @@
|
|
|
2
2
|
|
|
3
3
|
var error_responses = require('./error.responses.cjs.js');
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Header key for tenant identification
|
|
7
|
+
*
|
|
8
|
+
* This constant defines the HTTP header used to indicate the tenant in a request,
|
|
9
|
+
* typically in multi-tenant applications. The value should be sent by the client
|
|
10
|
+
* (or upstream gateway) in each request, for example as "x-tenant".
|
|
11
|
+
*
|
|
12
|
+
* Controllers and services can read this header directly from the request object
|
|
13
|
+
* to perform tenant-specific logic.
|
|
14
|
+
*
|
|
15
|
+
* Using a constant prevents magic strings and ensures consistency across the app.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* // Controller accessing the tenant directly from the header
|
|
20
|
+
* @Controller()
|
|
21
|
+
* export class SomeController {
|
|
22
|
+
* @Get()
|
|
23
|
+
* findAll(@Req() req: Request) {
|
|
24
|
+
* const tenant = req.header(TENANT_HEADER_KEY);
|
|
25
|
+
*
|
|
26
|
+
* if (tenant) {
|
|
27
|
+
* // Perform tenant-specific operations
|
|
28
|
+
* return this.service.findAllForTenant(tenant);
|
|
29
|
+
* }
|
|
30
|
+
*
|
|
31
|
+
* return this.service.findAll();
|
|
32
|
+
* }
|
|
33
|
+
* }
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
const TENANT_HEADER_KEY = "x-tenant";
|
|
37
|
+
|
|
5
38
|
/**
|
|
6
39
|
* Authentication Endpoints Enum
|
|
7
40
|
*
|
|
@@ -1292,4 +1325,5 @@ function isRoleObject(role) {
|
|
|
1292
1325
|
|
|
1293
1326
|
exports.AuthErrors = AuthErrors;
|
|
1294
1327
|
exports.AuthSuccessResponses = AuthSuccessResponses;
|
|
1328
|
+
exports.TENANT_HEADER_KEY = TENANT_HEADER_KEY;
|
|
1295
1329
|
exports.isRoleObject = isRoleObject;
|
package/auth.esm.js
CHANGED
|
@@ -1,5 +1,38 @@
|
|
|
1
1
|
import { e as HttpServerErrorStatus, H as HttpClientErrorStatus, f as HttpSuccessStatus } from './error.responses.esm.js';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Header key for tenant identification
|
|
5
|
+
*
|
|
6
|
+
* This constant defines the HTTP header used to indicate the tenant in a request,
|
|
7
|
+
* typically in multi-tenant applications. The value should be sent by the client
|
|
8
|
+
* (or upstream gateway) in each request, for example as "x-tenant".
|
|
9
|
+
*
|
|
10
|
+
* Controllers and services can read this header directly from the request object
|
|
11
|
+
* to perform tenant-specific logic.
|
|
12
|
+
*
|
|
13
|
+
* Using a constant prevents magic strings and ensures consistency across the app.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* // Controller accessing the tenant directly from the header
|
|
18
|
+
* @Controller()
|
|
19
|
+
* export class SomeController {
|
|
20
|
+
* @Get()
|
|
21
|
+
* findAll(@Req() req: Request) {
|
|
22
|
+
* const tenant = req.header(TENANT_HEADER_KEY);
|
|
23
|
+
*
|
|
24
|
+
* if (tenant) {
|
|
25
|
+
* // Perform tenant-specific operations
|
|
26
|
+
* return this.service.findAllForTenant(tenant);
|
|
27
|
+
* }
|
|
28
|
+
*
|
|
29
|
+
* return this.service.findAll();
|
|
30
|
+
* }
|
|
31
|
+
* }
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
const TENANT_HEADER_KEY = "x-tenant";
|
|
35
|
+
|
|
3
36
|
/**
|
|
4
37
|
* Authentication Endpoints Enum
|
|
5
38
|
*
|
|
@@ -1288,4 +1321,4 @@ function isRoleObject(role) {
|
|
|
1288
1321
|
return Boolean(role) && typeof role === "object" && Boolean("name" in role);
|
|
1289
1322
|
}
|
|
1290
1323
|
|
|
1291
|
-
export { AuthEndpoint, AuthErrorResponseCode, AuthErrors, AuthField, AuthMethod, AuthProvider, AuthStrategy, AuthSuccessResponseCode, AuthSuccessResponses, isRoleObject };
|
|
1324
|
+
export { AuthEndpoint, AuthErrorResponseCode, AuthErrors, AuthField, AuthMethod, AuthProvider, AuthStrategy, AuthSuccessResponseCode, AuthSuccessResponses, TENANT_HEADER_KEY, isRoleObject };
|
package/index.cjs.js
CHANGED
package/index.esm.js
CHANGED
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.
|
|
4
|
+
"version": "0.0.5",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
package/src/auth/auth.d.ts
CHANGED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Header key for tenant identification
|
|
3
|
+
*
|
|
4
|
+
* This constant defines the HTTP header used to indicate the tenant in a request,
|
|
5
|
+
* typically in multi-tenant applications. The value should be sent by the client
|
|
6
|
+
* (or upstream gateway) in each request, for example as "x-tenant".
|
|
7
|
+
*
|
|
8
|
+
* Controllers and services can read this header directly from the request object
|
|
9
|
+
* to perform tenant-specific logic.
|
|
10
|
+
*
|
|
11
|
+
* Using a constant prevents magic strings and ensures consistency across the app.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* // Controller accessing the tenant directly from the header
|
|
16
|
+
* @Controller()
|
|
17
|
+
* export class SomeController {
|
|
18
|
+
* @Get()
|
|
19
|
+
* findAll(@Req() req: Request) {
|
|
20
|
+
* const tenant = req.header(TENANT_HEADER_KEY);
|
|
21
|
+
*
|
|
22
|
+
* if (tenant) {
|
|
23
|
+
* // Perform tenant-specific operations
|
|
24
|
+
* return this.service.findAllForTenant(tenant);
|
|
25
|
+
* }
|
|
26
|
+
*
|
|
27
|
+
* return this.service.findAll();
|
|
28
|
+
* }
|
|
29
|
+
* }
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export declare const TENANT_HEADER_KEY = "x-tenant";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./constants";
|
|
@@ -169,3 +169,13 @@ export type RefreshToken = string & {
|
|
|
169
169
|
export type VerifyToken = string & {
|
|
170
170
|
readonly __brand: unique symbol;
|
|
171
171
|
};
|
|
172
|
+
/**
|
|
173
|
+
* A type representing a tenant-specific slug with a unique branding.
|
|
174
|
+
* This type is used to distinguish tenant slugs from regular strings at the type level.
|
|
175
|
+
* The `__brand` symbol ensures that type operations preserve the distinction.
|
|
176
|
+
*
|
|
177
|
+
* Usage of this type prevents accidental misuse of strings in contexts where a tenant slug is required.
|
|
178
|
+
*/
|
|
179
|
+
export type TenantSlug = string & {
|
|
180
|
+
readonly __brand: unique symbol;
|
|
181
|
+
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { TenantSlug } from "../../auth";
|
|
1
2
|
import { EntityId } from "../../crud";
|
|
2
3
|
/**
|
|
3
4
|
* Interface representing essential user information.
|
|
@@ -40,6 +41,16 @@ export interface UserInfo {
|
|
|
40
41
|
* and uniquely identifies the user across the entire system.
|
|
41
42
|
*/
|
|
42
43
|
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;
|
|
43
54
|
/**
|
|
44
55
|
* The user's first name or given name.
|
|
45
56
|
*
|