Skip to content

Commit 42ea3f1

Browse files
author
Mohamed Johnson [SNT DSI/DAC/DIM/DS]
committed
feat: 🚀 Initialized Repo
1 parent 95e0bec commit 42ea3f1

8 files changed

Lines changed: 133 additions & 15 deletions

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
node_modules
2-
yarn.lock
2+
yarn.lock
3+
dist
File renamed without changes.

index.js

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,30 @@
1-
// import { BASE_HTTP_ERRORS } from './constants.js';
2-
// import { HttpError } from './http-error.js';
3-
// import { generateError } from './generateError.js';
4-
51
import { BASE_HTTP_ERRORS } from "./src/constants/index.js";
62
import { generateError } from "./utils/generateError.js";
73
import { HttpError } from "./utils/http-error.js";
4+
import statuses from 'statuses';
5+
6+
import fs from 'fs';
7+
8+
const lines = Object.entries(statuses.message)
9+
.map(([code, message]) => {
10+
const name = message.toUpperCase().replace(/[^A-Z0-9]+/g, '_');
11+
return ` * ${name}: HttpErrorConstant,`;
12+
})
13+
.join('\n');
14+
15+
const typedef = `/**
16+
* @typedef {Object} HttpErrorConstant
17+
* @property {number} status
18+
* @property {string} code
19+
* @property {string} message
20+
*/
21+
22+
/**
23+
* @typedef {{
24+
${lines}
25+
}} BaseHttpErrors
26+
*/`;
27+
28+
fs.writeFileSync('./http-error-typedef.jsdoc', typedef);
829

9-
export { HttpError, generateError, BASE_HTTP_ERRORS };
30+
export { HttpError, generateError, BASE_HTTP_ERRORS };

package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22
"name": "http-errors-plus",
33
"version": "1.0.0",
44
"description": "Next-gen HTTP error handling for modern JavaScript and TypeScript apps — structured, overrideable, and developer-focused.",
5-
"main": "./src/index.js",
5+
"main": "dist/index.cjs",
6+
"module": "dist/index.esm.js",
7+
"types": "dist/index.d.ts",
68
"exports": {
79
".": {
810
"require": "./dist/index.cjs",
911
"import": "./dist/index.esm.js",
1012
"types": "./dist/index.d.ts"
1113
}
1214
},
13-
"types": "./types/index.d.ts",
1415
"files": [
1516
"dist",
1617
"src",
@@ -19,9 +20,8 @@
1920
"LICENSE"
2021
],
2122
"scripts": {
22-
"test": "node test/basic.test.js",
23-
"lint": "echo 'linting coming soon'",
24-
"build": "echo 'no build needed — pure JS'"
23+
"dev": "NODE_TLS_REJECT_UNAUTHORIZED=0 nodemon index.js",
24+
"build": "rm -rf dist && vite build && npx tsc --emitDeclarationOnly --declaration --declarationDir dist"
2525
},
2626
"keywords": [
2727
"http",
@@ -48,8 +48,8 @@
4848
},
4949
"homepage": "https://github.com/your-username/http-errors-plus#readme",
5050
"author": {
51-
"name": "Mohamed Johnson",
52-
"email": "you@example.com",
51+
"name": "Mohamed Johnson (lpix-11)",
52+
"email": "mohamed.johnson@orange-sonatel.com",
5353
"url": "https://github.com/LPIX-11"
5454
},
5555
"license": "MIT",

src/constants/index.js

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,27 +42,68 @@ export const STATUS_NAME_MAP = Object.values(STATUS_CODE_MAP).reduce((acc, { cod
4242
* CONTINUE: HttpErrorConstant,
4343
* SWITCHING_PROTOCOLS: HttpErrorConstant,
4444
* PROCESSING: HttpErrorConstant,
45+
* EARLY_HINTS: HttpErrorConstant,
4546
* OK: HttpErrorConstant,
4647
* CREATED: HttpErrorConstant,
4748
* ACCEPTED: HttpErrorConstant,
49+
* NON_AUTHORITATIVE_INFORMATION: HttpErrorConstant,
4850
* NO_CONTENT: HttpErrorConstant,
51+
* RESET_CONTENT: HttpErrorConstant,
52+
* PARTIAL_CONTENT: HttpErrorConstant,
53+
* MULTI_STATUS: HttpErrorConstant,
54+
* ALREADY_REPORTED: HttpErrorConstant,
55+
* IM_USED: HttpErrorConstant,
56+
* MULTIPLE_CHOICES: HttpErrorConstant,
4957
* MOVED_PERMANENTLY: HttpErrorConstant,
5058
* FOUND: HttpErrorConstant,
59+
* SEE_OTHER: HttpErrorConstant,
5160
* NOT_MODIFIED: HttpErrorConstant,
61+
* USE_PROXY: HttpErrorConstant,
62+
* TEMPORARY_REDIRECT: HttpErrorConstant,
63+
* PERMANENT_REDIRECT: HttpErrorConstant,
5264
* BAD_REQUEST: HttpErrorConstant,
5365
* UNAUTHORIZED: HttpErrorConstant,
66+
* PAYMENT_REQUIRED: HttpErrorConstant,
5467
* FORBIDDEN: HttpErrorConstant,
5568
* NOT_FOUND: HttpErrorConstant,
5669
* METHOD_NOT_ALLOWED: HttpErrorConstant,
70+
* NOT_ACCEPTABLE: HttpErrorConstant,
71+
* PROXY_AUTHENTICATION_REQUIRED: HttpErrorConstant,
72+
* REQUEST_TIMEOUT: HttpErrorConstant,
5773
* CONFLICT: HttpErrorConstant,
74+
* GONE: HttpErrorConstant,
75+
* LENGTH_REQUIRED: HttpErrorConstant,
76+
* PRECONDITION_FAILED: HttpErrorConstant,
77+
* PAYLOAD_TOO_LARGE: HttpErrorConstant,
78+
* URI_TOO_LONG: HttpErrorConstant,
79+
* UNSUPPORTED_MEDIA_TYPE: HttpErrorConstant,
80+
* RANGE_NOT_SATISFIABLE: HttpErrorConstant,
81+
* EXPECTATION_FAILED: HttpErrorConstant,
82+
* I_M_A_TEAPOT: HttpErrorConstant,
83+
* MISDIRECTED_REQUEST: HttpErrorConstant,
5884
* UNPROCESSABLE_ENTITY: HttpErrorConstant,
85+
* LOCKED: HttpErrorConstant,
86+
* FAILED_DEPENDENCY: HttpErrorConstant,
87+
* TOO_EARLY: HttpErrorConstant,
88+
* UPGRADE_REQUIRED: HttpErrorConstant,
89+
* PRECONDITION_REQUIRED: HttpErrorConstant,
5990
* TOO_MANY_REQUESTS: HttpErrorConstant,
91+
* REQUEST_HEADER_FIELDS_TOO_LARGE: HttpErrorConstant,
92+
* UNAVAILABLE_FOR_LEGAL_REASONS: HttpErrorConstant,
6093
* INTERNAL_SERVER_ERROR: HttpErrorConstant,
94+
* NOT_IMPLEMENTED: HttpErrorConstant,
6195
* BAD_GATEWAY: HttpErrorConstant,
6296
* SERVICE_UNAVAILABLE: HttpErrorConstant,
63-
* GATEWAY_TIMEOUT: HttpErrorConstant
97+
* GATEWAY_TIMEOUT: HttpErrorConstant,
98+
* HTTP_VERSION_NOT_SUPPORTED: HttpErrorConstant,
99+
* VARIANT_ALSO_NEGOTIATES: HttpErrorConstant,
100+
* INSUFFICIENT_STORAGE: HttpErrorConstant,
101+
* LOOP_DETECTED: HttpErrorConstant,
102+
* BANDWIDTH_LIMIT_EXCEEDED: HttpErrorConstant,
103+
* NOT_EXTENDED: HttpErrorConstant,
104+
* NETWORK_AUTHENTICATION_REQUIRED: HttpErrorConstant,
64105
* }} BaseHttpErrors
65-
*/
106+
*/
66107

67108
/**
68109
* @type {BaseHttpErrors}

src/types/linkify-it.d.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
declare module 'linkify-it' {
2+
export = LinkifyIt;
3+
4+
namespace LinkifyIt {
5+
interface LinkifyIt { /* Define any necessary properties here */ }
6+
}
7+
}

tsconfig.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"compilerOptions": {
3+
"declaration": true,
4+
"emitDeclarationOnly": true,
5+
"declarationDir": "./dist",
6+
"module": "ESNext",
7+
"target": "ESNext",
8+
"moduleResolution": "Node",
9+
"strict": true,
10+
"esModuleInterop": true,
11+
"allowJs": true,
12+
"outDir": "./dist"
13+
},
14+
"include": ["index.js", "src/**/*.js", "src/types/**/*.d.ts"],
15+
"exclude": ["node_modules", "dist"]
16+
}

vite.config.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { defineConfig } from 'vite';
2+
3+
export default defineConfig({
4+
build: {
5+
lib: {
6+
entry: 'index.js',
7+
name: 'CCMS',
8+
fileName: (format) => `index.${format}.js`,
9+
},
10+
rollupOptions: {
11+
external: ['path', 'dotenv', 'superstruct', 'undici', '@sonatel-os/json-sculpt', 'https'],
12+
output: [
13+
{
14+
format: 'es',
15+
entryFileNames: 'index.esm.js',
16+
dir: 'dist',
17+
sourcemap: true,
18+
},
19+
{
20+
format: 'cjs',
21+
entryFileNames: 'index.cjs',
22+
dir: 'dist',
23+
sourcemap: true,
24+
},
25+
],
26+
},
27+
sourcemap: true,
28+
minify: false,
29+
},
30+
plugins: [
31+
],
32+
});

0 commit comments

Comments
 (0)