@ooneex/http-request 0.0.1
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/LICENSE +21 -0
- package/README.md +1 -0
- package/dist/index.d.ts +54 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +10 -0
- package/dist/ooneex-http-request-0.0.1.tgz +0 -0
- package/package.json +42 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Ooneex
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# @ooneex/router
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Header as Header2, IUserAgent as IUserAgent2 } from "@ooneex/http-header";
|
|
2
|
+
import { IRequestFile as IRequestFile2 } from "@ooneex/http-request-file";
|
|
3
|
+
import { LocaleInfoType as LocaleInfoType2 } from "@ooneex/translation";
|
|
4
|
+
import { HttpMethodType as HttpMethodType2, ScalarType as ScalarType2 } from "@ooneex/types";
|
|
5
|
+
import { IUrl as IUrl2 } from "@ooneex/url";
|
|
6
|
+
import { Header, IUserAgent } from "@ooneex/http-header";
|
|
7
|
+
import { IRequestFile } from "@ooneex/http-request-file";
|
|
8
|
+
import { LocaleInfoType } from "@ooneex/translation";
|
|
9
|
+
import { HttpMethodType, ScalarType } from "@ooneex/types";
|
|
10
|
+
import { IUrl } from "@ooneex/url";
|
|
11
|
+
type RequestConfigType = {
|
|
12
|
+
params: Record<string, ScalarType>;
|
|
13
|
+
payload: Record<string, unknown>;
|
|
14
|
+
queries: Record<string, ScalarType>;
|
|
15
|
+
};
|
|
16
|
+
interface IRequest<Config extends RequestConfigType = RequestConfigType> {
|
|
17
|
+
readonly native: Readonly<Request>;
|
|
18
|
+
readonly path: string;
|
|
19
|
+
readonly url: IUrl;
|
|
20
|
+
readonly method: HttpMethodType;
|
|
21
|
+
readonly header: Header;
|
|
22
|
+
readonly userAgent: IUserAgent | null;
|
|
23
|
+
readonly params: Config["params"];
|
|
24
|
+
readonly payload: Config["payload"];
|
|
25
|
+
readonly queries: Config["queries"];
|
|
26
|
+
readonly form: FormData | null;
|
|
27
|
+
readonly files: Record<string, IRequestFile>;
|
|
28
|
+
readonly ip: string | null;
|
|
29
|
+
readonly host: string;
|
|
30
|
+
readonly language: LocaleInfoType;
|
|
31
|
+
}
|
|
32
|
+
declare class HttpRequest<Config extends RequestConfigType = RequestConfigType> implements IRequest<Config> {
|
|
33
|
+
readonly native: Readonly<Request>;
|
|
34
|
+
readonly path: string;
|
|
35
|
+
readonly url: IUrl2;
|
|
36
|
+
readonly method: HttpMethodType2;
|
|
37
|
+
readonly header: Header2;
|
|
38
|
+
readonly userAgent: IUserAgent2 | null;
|
|
39
|
+
readonly params: Config["params"];
|
|
40
|
+
readonly payload: Config["payload"];
|
|
41
|
+
readonly queries: Config["queries"];
|
|
42
|
+
readonly form: FormData | null;
|
|
43
|
+
readonly files: Record<string, IRequestFile2>;
|
|
44
|
+
readonly ip: string | null;
|
|
45
|
+
readonly host: string;
|
|
46
|
+
readonly language: LocaleInfoType2;
|
|
47
|
+
constructor(native: Readonly<Request>, config?: {
|
|
48
|
+
params?: Record<string, ScalarType2>;
|
|
49
|
+
form?: FormData | null;
|
|
50
|
+
payload?: Record<string, unknown>;
|
|
51
|
+
ip?: string | null;
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
export { RequestConfigType, IRequest, HttpRequest };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import{Header as n}from"@ooneex/http-header";import{RequestFile as s}from"@ooneex/http-request-file";import{Url as i}from"@ooneex/url";import p from"accept-language-parser";class a{native;path;url;method;header;userAgent;params={};payload={};queries={};form;files={};ip;host;language;constructor(l,e){this.native=l;if(this.url=new i(this.native.url),this.path=this.url.getPath(),this.method=this.native.method.toUpperCase(),this.header=new n(l.headers),this.queries=this.url.getQueries(),this.payload=e?.payload||{},this.params=e?.params||{},this.form=e?.form||null,this.userAgent=this.header.getUserAgent(),e?.form)e.form.forEach((r,t)=>{if(r instanceof File)this.files[t]=new s(r)});this.ip=e?.ip||null,this.host=this.header.getHost()||"";let o=this.url.getQuery("lang")||this.url.getQuery("locale")||this.header.get("X-Custom-Lang");if(o)this.language={code:o,region:null};else{let t=p.parse(this.header.get("Accept-Language")??"en-US")[0];this.language={code:t?.code,region:t?.region??null}}}}export{a as HttpRequest};
|
|
2
|
+
|
|
3
|
+
//# debugId=0A38759E9735862264756E2164756E21
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["src/HttpRequest.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"import { Header, type IUserAgent } from \"@ooneex/http-header\";\nimport { type IRequestFile, RequestFile } from \"@ooneex/http-request-file\";\nimport type { LocaleInfoType, LocaleType } from \"@ooneex/translation\";\nimport type { HttpMethodType, ScalarType } from \"@ooneex/types\";\nimport { type IUrl, Url } from \"@ooneex/url\";\nimport parser from \"accept-language-parser\";\nimport type { IRequest, RequestConfigType } from \"./types\";\n\nexport class HttpRequest<Config extends RequestConfigType = RequestConfigType> implements IRequest<Config> {\n public readonly path: string;\n public readonly url: IUrl;\n public readonly method: HttpMethodType;\n public readonly header: Header;\n public readonly userAgent: IUserAgent | null;\n public readonly params: Config[\"params\"] = {};\n public readonly payload: Config[\"payload\"] = {};\n public readonly queries: Config[\"queries\"] = {};\n public readonly form: FormData | null;\n public readonly files: Record<string, IRequestFile> = {};\n public readonly ip: string | null;\n public readonly host: string;\n public readonly language: LocaleInfoType;\n\n constructor(\n public readonly native: Readonly<Request>,\n config?: {\n params?: Record<string, ScalarType>;\n form?: FormData | null;\n payload?: Record<string, unknown>;\n ip?: string | null;\n },\n ) {\n this.url = new Url(this.native.url);\n this.path = this.url.getPath();\n this.method = this.native.method.toUpperCase() as HttpMethodType;\n this.header = new Header(native.headers);\n this.queries = this.url.getQueries();\n this.payload = config?.payload || {};\n this.params = config?.params || {};\n this.form = config?.form || null;\n this.userAgent = this.header.getUserAgent();\n\n if (config?.form) {\n config.form.forEach((value, key) => {\n if (value instanceof File) {\n this.files[key] = new RequestFile(value);\n }\n });\n }\n\n this.ip = config?.ip || null;\n this.host = this.header.getHost() || \"\";\n\n const customLang = this.url.getQuery(\"lang\") || this.url.getQuery(\"locale\") || this.header.get(\"X-Custom-Lang\");\n if (customLang) {\n this.language = {\n code: customLang as LocaleType,\n region: null,\n };\n } else {\n const languages = parser.parse(this.header.get(\"Accept-Language\") ?? \"en-US\");\n const language = languages[0];\n this.language = {\n code: language?.code as LocaleType,\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9
|
+
"names": []
|
|
10
|
+
}
|
|
Binary file
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ooneex/http-request",
|
|
3
|
+
"description": "",
|
|
4
|
+
"version": "0.0.1",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist",
|
|
8
|
+
"LICENSE",
|
|
9
|
+
"README.md",
|
|
10
|
+
"package.json"
|
|
11
|
+
],
|
|
12
|
+
"module": "./dist/index.js",
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"import": {
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"default": "./dist/index.js"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"./package.json": "./package.json"
|
|
22
|
+
},
|
|
23
|
+
"license": "MIT",
|
|
24
|
+
"scripts": {
|
|
25
|
+
"test": "bun test tests",
|
|
26
|
+
"build": "bunup",
|
|
27
|
+
"lint": "tsgo --noEmit && bunx biome lint",
|
|
28
|
+
"publish:prod": "bun publish --tolerate-republish --access public",
|
|
29
|
+
"publish:pack": "bun pm pack --destination ./dist",
|
|
30
|
+
"publish:dry": "bun publish --dry-run"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@ooneex/http-header": "0.0.1",
|
|
34
|
+
"@ooneex/http-request-file": "0.0.1",
|
|
35
|
+
"@ooneex/url": "0.0.1",
|
|
36
|
+
"accept-language-parser": "^1.5.0"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@ooneex/translation": "0.0.1",
|
|
40
|
+
"@ooneex/types": "0.0.1"
|
|
41
|
+
}
|
|
42
|
+
}
|