@naman_deep_singh/http-response 3.3.3 → 3.3.4

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 (35) hide show
  1. package/README.md +1 -1
  2. package/package.json +3 -2
  3. package/dist/cjs/adapters/express/ExpressResponder.d.ts +0 -18
  4. package/dist/cjs/adapters/express/index.d.ts +0 -1
  5. package/dist/cjs/adapters/index.d.ts +0 -1
  6. package/dist/cjs/constants/httpStatus.d.ts +0 -54
  7. package/dist/cjs/constants/index.d.ts +0 -1
  8. package/dist/cjs/core/BaseResponder.d.ts +0 -31
  9. package/dist/cjs/core/config.d.ts +0 -15
  10. package/dist/cjs/core/factory.d.ts +0 -3
  11. package/dist/cjs/core/index.d.ts +0 -4
  12. package/dist/cjs/core/types.d.ts +0 -32
  13. package/dist/cjs/index.d.ts +0 -4
  14. package/dist/cjs/legacy.d.ts +0 -19
  15. package/dist/cjs/legacy.js +0 -23
  16. package/dist/cjs/middleware/express/expressMiddleware.d.ts +0 -3
  17. package/dist/cjs/middleware/express/index.d.ts +0 -1
  18. package/dist/cjs/middleware/index.d.ts +0 -1
  19. package/dist/esm/adapters/express/ExpressResponder.d.ts +0 -18
  20. package/dist/esm/adapters/express/index.d.ts +0 -1
  21. package/dist/esm/adapters/index.d.ts +0 -1
  22. package/dist/esm/constants/httpStatus.d.ts +0 -54
  23. package/dist/esm/constants/index.d.ts +0 -1
  24. package/dist/esm/core/BaseResponder.d.ts +0 -31
  25. package/dist/esm/core/config.d.ts +0 -15
  26. package/dist/esm/core/factory.d.ts +0 -3
  27. package/dist/esm/core/index.d.ts +0 -4
  28. package/dist/esm/core/types.d.ts +0 -32
  29. package/dist/esm/index.d.ts +0 -4
  30. package/dist/esm/legacy.d.ts +0 -19
  31. package/dist/esm/legacy.js +0 -18
  32. package/dist/esm/middleware/express/expressMiddleware.d.ts +0 -3
  33. package/dist/esm/middleware/express/index.d.ts +0 -1
  34. package/dist/esm/middleware/index.d.ts +0 -1
  35. package/dist/types/legacy.d.ts +0 -19
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @naman_deep_singh/http-response
2
2
 
3
- **Version:** 3.3.3
3
+ **Version:** 3.3.4
4
4
 
5
5
  A flexible, framework-agnostic **TypeScript response utility library** for building consistent, typed, and configurable API responses.
6
6
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naman_deep_singh/http-response",
3
- "version": "3.3.3",
3
+ "version": "3.3.4",
4
4
  "description": "TypeScript utilities for standardized API responses",
5
5
  "author": "Naman Deep Singh",
6
6
  "license": "MIT",
@@ -60,6 +60,7 @@
60
60
  "scripts": {
61
61
  "build": "pnpm run build:types && tsc -p tsconfig.cjs.json && tsc -p tsconfig.esm.json",
62
62
  "build:types": "tsc -p tsconfig.types.json",
63
- "clean": "rimraf dist"
63
+ "clean": "rimraf dist",
64
+ "clean:js": "find src -type f -name '*.js' -delete"
64
65
  }
65
66
  }
@@ -1,18 +0,0 @@
1
- import type { Response } from 'express';
2
- import { BaseResponder } from '../../core/BaseResponder.js';
3
- import type { ResponderConfig } from '../../core/config.js';
4
- export declare class ExpressResponder<P = unknown> extends BaseResponder<P> {
5
- private readonly res;
6
- constructor(cfg: Partial<ResponderConfig> | undefined, res: Response);
7
- okAndSend(data?: P, message?: string): void;
8
- createdAndSend(data?: P, message?: string): void;
9
- badRequestAndSend(message?: string, error?: unknown): void;
10
- unauthorizedAndSend(message?: string): void;
11
- forbiddenAndSend(message?: string): void;
12
- notFoundAndSend(message?: string): void;
13
- conflictAndSend(message?: string): void;
14
- unprocessableEntityAndSend(message?: string, error?: unknown): void;
15
- tooManyRequestsAndSend(message?: string): void;
16
- serverErrorAndSend(message?: string, error?: unknown): void;
17
- paginateAndSend(data: P[], page: number, limit: number, total: number, message?: string): void;
18
- }
@@ -1 +0,0 @@
1
- export * from './ExpressResponder.js';
@@ -1 +0,0 @@
1
- export * from './express/index.js';
@@ -1,54 +0,0 @@
1
- declare const SUCCESS: Readonly<{
2
- readonly OK: 200;
3
- readonly CREATED: 201;
4
- readonly ACCEPTED: 202;
5
- readonly NO_CONTENT: 204;
6
- }>;
7
- declare const REDIRECTION: Readonly<{
8
- readonly NOT_MODIFIED: 304;
9
- }>;
10
- declare const CLIENT_ERROR: Readonly<{
11
- readonly BAD_REQUEST: 400;
12
- readonly UNAUTHORIZED: 401;
13
- readonly FORBIDDEN: 403;
14
- readonly NOT_FOUND: 404;
15
- readonly METHOD_NOT_ALLOWED: 405;
16
- readonly CONFLICT: 409;
17
- readonly UNPROCESSABLE_ENTITY: 422;
18
- readonly TOO_MANY_REQUESTS: 429;
19
- }>;
20
- declare const SERVER_ERROR: Readonly<{
21
- readonly INTERNAL_SERVER_ERROR: 500;
22
- readonly NOT_IMPLEMENTED: 501;
23
- readonly BAD_GATEWAY: 502;
24
- readonly SERVICE_UNAVAILABLE: 503;
25
- }>;
26
- export declare const HTTP_STATUS: Readonly<{
27
- readonly SUCCESS: Readonly<{
28
- readonly OK: 200;
29
- readonly CREATED: 201;
30
- readonly ACCEPTED: 202;
31
- readonly NO_CONTENT: 204;
32
- }>;
33
- readonly REDIRECTION: Readonly<{
34
- readonly NOT_MODIFIED: 304;
35
- }>;
36
- readonly CLIENT_ERROR: Readonly<{
37
- readonly BAD_REQUEST: 400;
38
- readonly UNAUTHORIZED: 401;
39
- readonly FORBIDDEN: 403;
40
- readonly NOT_FOUND: 404;
41
- readonly METHOD_NOT_ALLOWED: 405;
42
- readonly CONFLICT: 409;
43
- readonly UNPROCESSABLE_ENTITY: 422;
44
- readonly TOO_MANY_REQUESTS: 429;
45
- }>;
46
- readonly SERVER_ERROR: Readonly<{
47
- readonly INTERNAL_SERVER_ERROR: 500;
48
- readonly NOT_IMPLEMENTED: 501;
49
- readonly BAD_GATEWAY: 502;
50
- readonly SERVICE_UNAVAILABLE: 503;
51
- }>;
52
- }>;
53
- export type HttpStatusCode = (typeof SUCCESS)[keyof typeof SUCCESS] | (typeof REDIRECTION)[keyof typeof REDIRECTION] | (typeof CLIENT_ERROR)[keyof typeof CLIENT_ERROR] | (typeof SERVER_ERROR)[keyof typeof SERVER_ERROR];
54
- export {};
@@ -1 +0,0 @@
1
- export * from './httpStatus.js';
@@ -1,31 +0,0 @@
1
- import { type ResponderConfig } from './config.js';
2
- import type { PaginationMeta, ResponseEnvelope, Sender } from './types.js';
3
- export declare class BaseResponder<P = unknown, M = PaginationMeta> {
4
- protected readonly cfg: ResponderConfig;
5
- protected sender?: Sender;
6
- constructor(cfg?: Partial<ResponderConfig>, sender?: Sender);
7
- attachSender(sender: Sender): void;
8
- protected normalizeError(err: unknown): {
9
- message: string;
10
- code?: string;
11
- details?: unknown;
12
- };
13
- protected buildEnvelope(data?: P, message?: string, error?: unknown, meta?: M): ResponseEnvelope<P, M>;
14
- protected send(status: number, envelope: ResponseEnvelope<P, M>): any;
15
- /** -----------------------------
16
- * Standard REST Response Helpers
17
- * ----------------------------- */
18
- ok(data?: P, message?: string): any;
19
- created(data?: P, message?: string): any;
20
- noContent(message?: string): any;
21
- badRequest(message?: string, error?: unknown): any;
22
- unauthorized(message?: string): any;
23
- forbidden(message?: string): any;
24
- notFound(message?: string): any;
25
- conflict(message?: string): any;
26
- unprocessableEntity(message?: string, error?: unknown): any;
27
- tooManyRequests(message?: string): any;
28
- serverError(message?: string, error?: unknown): any;
29
- paginate(data: P[], page: number, limit: number, total: number, message?: string): any;
30
- paginateOffset(data: P[], offset: number, limit: number, total: number, message?: string): any;
31
- }
@@ -1,15 +0,0 @@
1
- import type { PlainObject } from './types.js';
2
- export type EnvelopeKeys = {
3
- success?: string;
4
- message?: string;
5
- data?: string;
6
- error?: string;
7
- meta?: string;
8
- };
9
- export type ResponderConfig = {
10
- envelopeKeys?: EnvelopeKeys;
11
- defaultStatus?: number;
12
- timestamp?: boolean;
13
- extra?: PlainObject | null;
14
- };
15
- export declare const defaultConfig: ResponderConfig;
@@ -1,3 +0,0 @@
1
- import { ExpressResponder } from '../adapters/index.js';
2
- import type { ResponderConfig } from './config.js';
3
- export declare const createResponderFactory: (cfg?: Partial<ResponderConfig>) => <P = unknown, _M = Record<string, unknown>>(res: import("express").Response) => ExpressResponder<P>;
@@ -1,4 +0,0 @@
1
- export * from './BaseResponder.js';
2
- export * from './config.js';
3
- export * from './factory.js';
4
- export * from './types.js';
@@ -1,32 +0,0 @@
1
- export type PlainObject = Record<string, unknown>;
2
- export type ErrorShape = {
3
- code?: string;
4
- message: string;
5
- details?: unknown;
6
- };
7
- export type ResponseEnvelope<T = unknown, M = PlainObject> = {
8
- success: boolean;
9
- message?: string;
10
- data?: T;
11
- error?: ErrorShape | null;
12
- meta?: M | null;
13
- };
14
- export type TransportResult = {
15
- status: number;
16
- body: unknown;
17
- };
18
- export type Sender = (status: number, body: unknown) => Promise<any> | any;
19
- export interface PaginationMeta {
20
- page: number;
21
- limit: number;
22
- total: number;
23
- totalPages: number;
24
- hasNext?: boolean;
25
- hasPrev?: boolean;
26
- offset?: number;
27
- links?: {
28
- next?: string;
29
- prev?: string;
30
- self: string;
31
- };
32
- }
@@ -1,4 +0,0 @@
1
- export * from './core/index.js';
2
- export * from './constants/index.js';
3
- export * from './adapters/index.js';
4
- export * from './middleware/index.js';
@@ -1,19 +0,0 @@
1
- export declare const success: <T>(data: T, message?: string, status?: number, res?: {
2
- status: (code: number) => any;
3
- json: (body: unknown) => any;
4
- }) => any;
5
- export declare const error: (message: string, status?: number, err?: string, res?: {
6
- status: (code: number) => any;
7
- json: (body: unknown) => any;
8
- }) => any;
9
- declare const _default: {
10
- success: <T>(data: T, message?: string, status?: number, res?: {
11
- status: (code: number) => any;
12
- json: (body: unknown) => any;
13
- }) => any;
14
- error: (message: string, status?: number, err?: string, res?: {
15
- status: (code: number) => any;
16
- json: (body: unknown) => any;
17
- }) => any;
18
- };
19
- export default _default;
@@ -1,23 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.error = exports.success = void 0;
4
- const success = (data, message = 'Success', status = 200, res) => {
5
- if (res)
6
- return res
7
- .status(status)
8
- .json({ success: true, message, data, statusCode: status });
9
- return { success: true, message, data, statusCode: status };
10
- };
11
- exports.success = success;
12
- const error = (message, status = 500, err, res) => {
13
- if (res)
14
- return res
15
- .status(status)
16
- .json({ success: false, message, error: err, statusCode: status });
17
- return { success: false, message, error: err, statusCode: status };
18
- };
19
- exports.error = error;
20
- exports.default = {
21
- success: exports.success,
22
- error: exports.error,
23
- };
@@ -1,3 +0,0 @@
1
- import type { RequestHandler } from 'express';
2
- import type { ResponderConfig } from '../../core/config.js';
3
- export declare const responderMiddleware: (cfg?: Partial<ResponderConfig>) => RequestHandler;
@@ -1 +0,0 @@
1
- export * from './expressMiddleware.js';
@@ -1 +0,0 @@
1
- export * from './express/index.js';
@@ -1,18 +0,0 @@
1
- import type { Response } from 'express';
2
- import { BaseResponder } from '../../core/BaseResponder.js';
3
- import type { ResponderConfig } from '../../core/config.js';
4
- export declare class ExpressResponder<P = unknown> extends BaseResponder<P> {
5
- private readonly res;
6
- constructor(cfg: Partial<ResponderConfig> | undefined, res: Response);
7
- okAndSend(data?: P, message?: string): void;
8
- createdAndSend(data?: P, message?: string): void;
9
- badRequestAndSend(message?: string, error?: unknown): void;
10
- unauthorizedAndSend(message?: string): void;
11
- forbiddenAndSend(message?: string): void;
12
- notFoundAndSend(message?: string): void;
13
- conflictAndSend(message?: string): void;
14
- unprocessableEntityAndSend(message?: string, error?: unknown): void;
15
- tooManyRequestsAndSend(message?: string): void;
16
- serverErrorAndSend(message?: string, error?: unknown): void;
17
- paginateAndSend(data: P[], page: number, limit: number, total: number, message?: string): void;
18
- }
@@ -1 +0,0 @@
1
- export * from './ExpressResponder.js';
@@ -1 +0,0 @@
1
- export * from './express/index.js';
@@ -1,54 +0,0 @@
1
- declare const SUCCESS: Readonly<{
2
- readonly OK: 200;
3
- readonly CREATED: 201;
4
- readonly ACCEPTED: 202;
5
- readonly NO_CONTENT: 204;
6
- }>;
7
- declare const REDIRECTION: Readonly<{
8
- readonly NOT_MODIFIED: 304;
9
- }>;
10
- declare const CLIENT_ERROR: Readonly<{
11
- readonly BAD_REQUEST: 400;
12
- readonly UNAUTHORIZED: 401;
13
- readonly FORBIDDEN: 403;
14
- readonly NOT_FOUND: 404;
15
- readonly METHOD_NOT_ALLOWED: 405;
16
- readonly CONFLICT: 409;
17
- readonly UNPROCESSABLE_ENTITY: 422;
18
- readonly TOO_MANY_REQUESTS: 429;
19
- }>;
20
- declare const SERVER_ERROR: Readonly<{
21
- readonly INTERNAL_SERVER_ERROR: 500;
22
- readonly NOT_IMPLEMENTED: 501;
23
- readonly BAD_GATEWAY: 502;
24
- readonly SERVICE_UNAVAILABLE: 503;
25
- }>;
26
- export declare const HTTP_STATUS: Readonly<{
27
- readonly SUCCESS: Readonly<{
28
- readonly OK: 200;
29
- readonly CREATED: 201;
30
- readonly ACCEPTED: 202;
31
- readonly NO_CONTENT: 204;
32
- }>;
33
- readonly REDIRECTION: Readonly<{
34
- readonly NOT_MODIFIED: 304;
35
- }>;
36
- readonly CLIENT_ERROR: Readonly<{
37
- readonly BAD_REQUEST: 400;
38
- readonly UNAUTHORIZED: 401;
39
- readonly FORBIDDEN: 403;
40
- readonly NOT_FOUND: 404;
41
- readonly METHOD_NOT_ALLOWED: 405;
42
- readonly CONFLICT: 409;
43
- readonly UNPROCESSABLE_ENTITY: 422;
44
- readonly TOO_MANY_REQUESTS: 429;
45
- }>;
46
- readonly SERVER_ERROR: Readonly<{
47
- readonly INTERNAL_SERVER_ERROR: 500;
48
- readonly NOT_IMPLEMENTED: 501;
49
- readonly BAD_GATEWAY: 502;
50
- readonly SERVICE_UNAVAILABLE: 503;
51
- }>;
52
- }>;
53
- export type HttpStatusCode = (typeof SUCCESS)[keyof typeof SUCCESS] | (typeof REDIRECTION)[keyof typeof REDIRECTION] | (typeof CLIENT_ERROR)[keyof typeof CLIENT_ERROR] | (typeof SERVER_ERROR)[keyof typeof SERVER_ERROR];
54
- export {};
@@ -1 +0,0 @@
1
- export * from './httpStatus.js';
@@ -1,31 +0,0 @@
1
- import { type ResponderConfig } from './config.js';
2
- import type { PaginationMeta, ResponseEnvelope, Sender } from './types.js';
3
- export declare class BaseResponder<P = unknown, M = PaginationMeta> {
4
- protected readonly cfg: ResponderConfig;
5
- protected sender?: Sender;
6
- constructor(cfg?: Partial<ResponderConfig>, sender?: Sender);
7
- attachSender(sender: Sender): void;
8
- protected normalizeError(err: unknown): {
9
- message: string;
10
- code?: string;
11
- details?: unknown;
12
- };
13
- protected buildEnvelope(data?: P, message?: string, error?: unknown, meta?: M): ResponseEnvelope<P, M>;
14
- protected send(status: number, envelope: ResponseEnvelope<P, M>): any;
15
- /** -----------------------------
16
- * Standard REST Response Helpers
17
- * ----------------------------- */
18
- ok(data?: P, message?: string): any;
19
- created(data?: P, message?: string): any;
20
- noContent(message?: string): any;
21
- badRequest(message?: string, error?: unknown): any;
22
- unauthorized(message?: string): any;
23
- forbidden(message?: string): any;
24
- notFound(message?: string): any;
25
- conflict(message?: string): any;
26
- unprocessableEntity(message?: string, error?: unknown): any;
27
- tooManyRequests(message?: string): any;
28
- serverError(message?: string, error?: unknown): any;
29
- paginate(data: P[], page: number, limit: number, total: number, message?: string): any;
30
- paginateOffset(data: P[], offset: number, limit: number, total: number, message?: string): any;
31
- }
@@ -1,15 +0,0 @@
1
- import type { PlainObject } from './types.js';
2
- export type EnvelopeKeys = {
3
- success?: string;
4
- message?: string;
5
- data?: string;
6
- error?: string;
7
- meta?: string;
8
- };
9
- export type ResponderConfig = {
10
- envelopeKeys?: EnvelopeKeys;
11
- defaultStatus?: number;
12
- timestamp?: boolean;
13
- extra?: PlainObject | null;
14
- };
15
- export declare const defaultConfig: ResponderConfig;
@@ -1,3 +0,0 @@
1
- import { ExpressResponder } from '../adapters/index.js';
2
- import type { ResponderConfig } from './config.js';
3
- export declare const createResponderFactory: (cfg?: Partial<ResponderConfig>) => <P = unknown, _M = Record<string, unknown>>(res: import("express").Response) => ExpressResponder<P>;
@@ -1,4 +0,0 @@
1
- export * from './BaseResponder.js';
2
- export * from './config.js';
3
- export * from './factory.js';
4
- export * from './types.js';
@@ -1,32 +0,0 @@
1
- export type PlainObject = Record<string, unknown>;
2
- export type ErrorShape = {
3
- code?: string;
4
- message: string;
5
- details?: unknown;
6
- };
7
- export type ResponseEnvelope<T = unknown, M = PlainObject> = {
8
- success: boolean;
9
- message?: string;
10
- data?: T;
11
- error?: ErrorShape | null;
12
- meta?: M | null;
13
- };
14
- export type TransportResult = {
15
- status: number;
16
- body: unknown;
17
- };
18
- export type Sender = (status: number, body: unknown) => Promise<any> | any;
19
- export interface PaginationMeta {
20
- page: number;
21
- limit: number;
22
- total: number;
23
- totalPages: number;
24
- hasNext?: boolean;
25
- hasPrev?: boolean;
26
- offset?: number;
27
- links?: {
28
- next?: string;
29
- prev?: string;
30
- self: string;
31
- };
32
- }
@@ -1,4 +0,0 @@
1
- export * from './core/index.js';
2
- export * from './constants/index.js';
3
- export * from './adapters/index.js';
4
- export * from './middleware/index.js';
@@ -1,19 +0,0 @@
1
- export declare const success: <T>(data: T, message?: string, status?: number, res?: {
2
- status: (code: number) => any;
3
- json: (body: unknown) => any;
4
- }) => any;
5
- export declare const error: (message: string, status?: number, err?: string, res?: {
6
- status: (code: number) => any;
7
- json: (body: unknown) => any;
8
- }) => any;
9
- declare const _default: {
10
- success: <T>(data: T, message?: string, status?: number, res?: {
11
- status: (code: number) => any;
12
- json: (body: unknown) => any;
13
- }) => any;
14
- error: (message: string, status?: number, err?: string, res?: {
15
- status: (code: number) => any;
16
- json: (body: unknown) => any;
17
- }) => any;
18
- };
19
- export default _default;
@@ -1,18 +0,0 @@
1
- export const success = (data, message = 'Success', status = 200, res) => {
2
- if (res)
3
- return res
4
- .status(status)
5
- .json({ success: true, message, data, statusCode: status });
6
- return { success: true, message, data, statusCode: status };
7
- };
8
- export const error = (message, status = 500, err, res) => {
9
- if (res)
10
- return res
11
- .status(status)
12
- .json({ success: false, message, error: err, statusCode: status });
13
- return { success: false, message, error: err, statusCode: status };
14
- };
15
- export default {
16
- success,
17
- error,
18
- };
@@ -1,3 +0,0 @@
1
- import type { RequestHandler } from 'express';
2
- import type { ResponderConfig } from '../../core/config.js';
3
- export declare const responderMiddleware: (cfg?: Partial<ResponderConfig>) => RequestHandler;
@@ -1 +0,0 @@
1
- export * from './expressMiddleware.js';
@@ -1 +0,0 @@
1
- export * from './express/index.js';
@@ -1,19 +0,0 @@
1
- export declare const success: <T>(data: T, message?: string, status?: number, res?: {
2
- status: (code: number) => any;
3
- json: (body: unknown) => any;
4
- }) => any;
5
- export declare const error: (message: string, status?: number, err?: string, res?: {
6
- status: (code: number) => any;
7
- json: (body: unknown) => any;
8
- }) => any;
9
- declare const _default: {
10
- success: <T>(data: T, message?: string, status?: number, res?: {
11
- status: (code: number) => any;
12
- json: (body: unknown) => any;
13
- }) => any;
14
- error: (message: string, status?: number, err?: string, res?: {
15
- status: (code: number) => any;
16
- json: (body: unknown) => any;
17
- }) => any;
18
- };
19
- export default _default;