@hichchi/nest-connector 0.0.3 → 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 +73 -0
- package/README.md +3708 -0
- package/auth.cjs.js +35 -1
- package/auth.esm.js +35 -2
- package/crud.cjs.js +0 -23
- package/crud.esm.js +0 -23
- package/index.cjs.js +1 -0
- package/index.esm.js +1 -0
- package/package.json +1 -1
- package/readme-top.md +170 -0
- 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
|
*
|
|
@@ -1287,9 +1320,10 @@ const AuthSuccessResponses = {
|
|
|
1287
1320
|
* @see {@link Role} Interface defining the structure of role objects
|
|
1288
1321
|
*/
|
|
1289
1322
|
function isRoleObject(role) {
|
|
1290
|
-
return Boolean(role) && Boolean("name" in role);
|
|
1323
|
+
return Boolean(role) && typeof role === "object" && Boolean("name" in role);
|
|
1291
1324
|
}
|
|
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
|
*
|
|
@@ -1285,7 +1318,7 @@ const AuthSuccessResponses = {
|
|
|
1285
1318
|
* @see {@link Role} Interface defining the structure of role objects
|
|
1286
1319
|
*/
|
|
1287
1320
|
function isRoleObject(role) {
|
|
1288
|
-
return Boolean(role) && Boolean("name" in role);
|
|
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/crud.cjs.js
CHANGED
|
@@ -7,26 +7,3 @@ exports.CrudEndpoint = void 0;
|
|
|
7
7
|
CrudEndpoint["BY_IDS"] = "by-ids";
|
|
8
8
|
CrudEndpoint["DELETE_BY_IDS"] = "delete-by-ids";
|
|
9
9
|
})(exports.CrudEndpoint || (exports.CrudEndpoint = {}));
|
|
10
|
-
|
|
11
|
-
// noinspection JSUnusedGlobalSymbols
|
|
12
|
-
const x = {
|
|
13
|
-
where: {
|
|
14
|
-
id: "s",
|
|
15
|
-
company: {
|
|
16
|
-
subdomain: "subdomain"
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
const y = {
|
|
21
|
-
where: {
|
|
22
|
-
id: ["s"],
|
|
23
|
-
company: {
|
|
24
|
-
subdomain: "subdomain"
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
// eslint-disable-next-line no-console
|
|
29
|
-
console.log({
|
|
30
|
-
x,
|
|
31
|
-
y
|
|
32
|
-
});
|
package/crud.esm.js
CHANGED
|
@@ -6,27 +6,4 @@ var CrudEndpoint;
|
|
|
6
6
|
CrudEndpoint["DELETE_BY_IDS"] = "delete-by-ids";
|
|
7
7
|
})(CrudEndpoint || (CrudEndpoint = {}));
|
|
8
8
|
|
|
9
|
-
// noinspection JSUnusedGlobalSymbols
|
|
10
|
-
const x = {
|
|
11
|
-
where: {
|
|
12
|
-
id: "s",
|
|
13
|
-
company: {
|
|
14
|
-
subdomain: "subdomain"
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
const y = {
|
|
19
|
-
where: {
|
|
20
|
-
id: ["s"],
|
|
21
|
-
company: {
|
|
22
|
-
subdomain: "subdomain"
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
// eslint-disable-next-line no-console
|
|
27
|
-
console.log({
|
|
28
|
-
x,
|
|
29
|
-
y
|
|
30
|
-
});
|
|
31
|
-
|
|
32
9
|
export { CrudEndpoint };
|
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/readme-top.md
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
|
|
2
|
+
<!--suppress ALL -->
|
|
3
|
+
<div align="center">
|
|
4
|
+
|
|
5
|
+
# 🔗 @hichchi/nest-connector
|
|
6
|
+
|
|
7
|
+
## Description
|
|
8
|
+
|
|
9
|
+
**Comprehensive NestJS connector library providing standardized HTTP responses, authentication interfaces, CRUD operations, and shared utilities for the Hichchi ecosystem**
|
|
10
|
+
|
|
11
|
+
[](https://www.npmjs.com/package/@hichchi/nest-connector)
|
|
12
|
+
[](https://www.npmjs.com/package/@hichchi/nest-connector)
|
|
13
|
+
[](https://github.com/hichchidev/hichchi/blob/main/LICENSE)
|
|
14
|
+
[](https://nestjs.com/)
|
|
15
|
+
|
|
16
|
+
*Part of the [Hichchi](https://github.com/hichchidev/hichchi) ecosystem - A powerful, scalable application built with Nx workspace*
|
|
17
|
+
|
|
18
|
+
[📚 Jump to Documentation](#-api-documentation)
|
|
19
|
+
|
|
20
|
+
</div>
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## 📋 Table of Contents
|
|
25
|
+
|
|
26
|
+
- [📦 Installation](#-installation)
|
|
27
|
+
- [⚡ Quick Start](#-quick-start)
|
|
28
|
+
- [📋 Prerequisites](#-prerequisites)
|
|
29
|
+
- [🌟 Overview](#-overview)
|
|
30
|
+
- [✨ Features](#-features)
|
|
31
|
+
- [🔧 Development](#-development)
|
|
32
|
+
- [📖 API Documentation](#-api-documentation)
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
## 📦 Installation
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
npm install @hichchi/nest-connector
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## ⚡ Quick Start
|
|
43
|
+
|
|
44
|
+
Get up and running with standardized API responses in just a few minutes:
|
|
45
|
+
|
|
46
|
+
```typescript
|
|
47
|
+
// 1. Install the package
|
|
48
|
+
npm install @hichchi/nest-connector
|
|
49
|
+
|
|
50
|
+
// 2. Import response interfaces and builders
|
|
51
|
+
import {
|
|
52
|
+
HttpResponse,
|
|
53
|
+
SuccessResponse,
|
|
54
|
+
ErrorResponse,
|
|
55
|
+
SuccessResponseDto
|
|
56
|
+
} from '@hichchi/nest-connector';
|
|
57
|
+
|
|
58
|
+
// 3. Use in your NestJS controllers
|
|
59
|
+
@Controller('users')
|
|
60
|
+
export class UsersController {
|
|
61
|
+
@Get()
|
|
62
|
+
async getUsers(): Promise<SuccessResponse> {
|
|
63
|
+
const users = await this.usersService.findAll();
|
|
64
|
+
return new SuccessResponseDto(users, 'Users retrieved successfully');
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## 📋 Prerequisites
|
|
70
|
+
|
|
71
|
+
Before installing @hichchi/nest-connector, ensure you have:
|
|
72
|
+
|
|
73
|
+
### Required Dependencies
|
|
74
|
+
- **Node.js**: ^20.0.0
|
|
75
|
+
- **NestJS**: ^11.0.0
|
|
76
|
+
- **TypeScript**: ~5.9.3
|
|
77
|
+
|
|
78
|
+
### Peer Dependencies
|
|
79
|
+
```bash
|
|
80
|
+
npm install @nestjs/common @nestjs/core
|
|
81
|
+
npm install rxjs reflect-metadata
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### Internal Dependencies
|
|
85
|
+
This package depends on:
|
|
86
|
+
```bash
|
|
87
|
+
npm install @hichchi/utils
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Optional Dependencies
|
|
91
|
+
For enhanced features:
|
|
92
|
+
```bash
|
|
93
|
+
# For validation decorators
|
|
94
|
+
npm install class-validator class-transformer
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## 🌟 Overview
|
|
98
|
+
|
|
99
|
+
🎯 **Your standardized response toolkit** for NestJS applications. Ensure consistent API responses across your entire application with pre-defined interfaces, builders, and response structures that follow industry best practices.
|
|
100
|
+
|
|
101
|
+
## ✨ Features
|
|
102
|
+
|
|
103
|
+
### 🏗️ Ready-to-Use Response Structures
|
|
104
|
+
- 📋 **HttpResponse Interface** - Base interface for all API responses
|
|
105
|
+
- ✅ **SuccessResponse Interface** - Standardized success response structure
|
|
106
|
+
- ❌ **ErrorResponse Interface** - Consistent error response format
|
|
107
|
+
- 🔢 **HTTP Status Enums** - Pre-defined status code enumerations
|
|
108
|
+
|
|
109
|
+
### 🛠️ Response Builders & DTOs
|
|
110
|
+
- 🏭 **SuccessResponseDto** - Builder for success responses with data
|
|
111
|
+
- 🎯 **Response Code Types** - Application-specific response codes
|
|
112
|
+
- 📊 **Status Code Management** - Organized HTTP status code handling
|
|
113
|
+
- 🔧 **Type-Safe Responses** - Full TypeScript support for response structures
|
|
114
|
+
|
|
115
|
+
### 🎨 Developer Experience
|
|
116
|
+
- 📝 **Comprehensive Documentation** - Detailed JSDoc comments for all interfaces
|
|
117
|
+
- 🔍 **IntelliSense Support** - Full IDE autocomplete and type checking
|
|
118
|
+
- 🎯 **Consistent API Design** - Standardized response patterns across applications
|
|
119
|
+
- 🚀 **Easy Integration** - Drop-in replacement for custom response handling
|
|
120
|
+
|
|
121
|
+
### 🔧 Advanced Features
|
|
122
|
+
- 🏷️ **User Info Interfaces** - Standardized user information structures
|
|
123
|
+
- 📦 **Modular Design** - Import only what you need
|
|
124
|
+
- 🔄 **Extensible Architecture** - Easy to extend with custom response types
|
|
125
|
+
- 🎪 **Framework Agnostic Types** - Core interfaces can be used beyond NestJS
|
|
126
|
+
|
|
127
|
+
## 🔧 Development
|
|
128
|
+
|
|
129
|
+
### Building the Library
|
|
130
|
+
```bash
|
|
131
|
+
nx build nest-connector
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### Running Tests
|
|
135
|
+
```bash
|
|
136
|
+
nx test nest-connector
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### Linting
|
|
140
|
+
```bash
|
|
141
|
+
nx lint nest-connector
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
---
|
|
145
|
+
|
|
146
|
+
<div align="center">
|
|
147
|
+
|
|
148
|
+
**Made with ❤️ by [Hichchi Dev](https://github.com/hichchidev)**
|
|
149
|
+
|
|
150
|
+
[](https://github.com/hichchidev/hichchi)
|
|
151
|
+
[](https://github.com/hichchidev/hichchi/issues)
|
|
152
|
+
[](https://github.com/hichchidev/hichchi/issues)
|
|
153
|
+
|
|
154
|
+
*Standardizing API responses and connecting NestJS applications with consistent interfaces and shared utilities*
|
|
155
|
+
|
|
156
|
+
</div>
|
|
157
|
+
|
|
158
|
+
---
|
|
159
|
+
|
|
160
|
+
# 📖 API Documentation
|
|
161
|
+
|
|
162
|
+
Complete technical reference for all classes, interfaces, methods, and types in this library.
|
|
163
|
+
|
|
164
|
+
**Auto-generated by TypeDoc** - Browse through detailed API references, code examples, and implementation guides below.
|
|
165
|
+
|
|
166
|
+
<!-- TypeDoc generated documentation will be appended below this point -->
|
|
167
|
+
|
|
168
|
+
---
|
|
169
|
+
|
|
170
|
+
## 📋 API Table of Contents
|
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
|
*
|