@ooneex/http-response 0.0.1 → 0.3.0
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/dist/index.d.ts +5 -4
- package/dist/index.js +2 -2
- package/dist/index.js.map +3 -3
- package/package.json +15 -6
- package/dist/ooneex-http-response-0.0.1.tgz +0 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Environment as Environment2 } from "@ooneex/app-env";
|
|
1
2
|
import { IHeader as IHeader2 } from "@ooneex/http-header";
|
|
2
3
|
import { StatusCodeType as StatusCodeType2 } from "@ooneex/http-status";
|
|
3
4
|
import { Environment } from "@ooneex/app-env";
|
|
@@ -16,7 +17,8 @@ interface IResponse<DataType extends Record<string, unknown> = Record<string, un
|
|
|
16
17
|
status?: StatusCodeType;
|
|
17
18
|
}) => IResponse<DataType>;
|
|
18
19
|
redirect: (url: string | URL, status?: StatusCodeType) => IResponse<DataType>;
|
|
19
|
-
get: () => Response;
|
|
20
|
+
get: (env?: Environment) => Response;
|
|
21
|
+
getData: () => DataType | null;
|
|
20
22
|
}
|
|
21
23
|
type ResponseDataType<Data extends Record<string, unknown>> = {
|
|
22
24
|
data: Data;
|
|
@@ -29,9 +31,7 @@ type ResponseDataType<Data extends Record<string, unknown>> = {
|
|
|
29
31
|
isNotFound: boolean;
|
|
30
32
|
isUnauthorized: boolean;
|
|
31
33
|
isForbidden: boolean;
|
|
32
|
-
debug: boolean;
|
|
33
34
|
app: {
|
|
34
|
-
url: string;
|
|
35
35
|
env: Environment;
|
|
36
36
|
};
|
|
37
37
|
};
|
|
@@ -53,6 +53,7 @@ declare class HttpResponse<Data extends Record<string, unknown> = Record<string,
|
|
|
53
53
|
status?: StatusCodeType2;
|
|
54
54
|
}): IResponse<Data>;
|
|
55
55
|
redirect(url: string | URL, status?: StatusCodeType2): IResponse<Data>;
|
|
56
|
-
|
|
56
|
+
getData(): Data | null;
|
|
57
|
+
get(env?: Environment2): Response;
|
|
57
58
|
}
|
|
58
59
|
export { ResponseDataType, IResponse, HttpResponse };
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{Environment as
|
|
1
|
+
import{Environment as r}from"@ooneex/app-env";import{Header as o}from"@ooneex/http-header";import{HttpStatus as s}from"@ooneex/http-status";class n{header;data=null;status=s.Code.OK;redirectUrl=null;message=null;done=!1;constructor(t){this.header=t||new o}json(t,e=s.Code.OK){return this.data=t,this.status=e,this.header.setJson(),this.header.remove("Location"),this.redirectUrl=null,this.message=null,this}exception(t,e){return this.message=t,this.status=e?.status??s.Code.InternalServerError,this.data=e?.data||null,this.redirectUrl=null,this.header.setJson(),this.header.remove("Location"),this}notFound(t,e){return this.message=t,this.status=e?.status||s.Code.NotFound,this.data=e?.data||null,this.redirectUrl=null,this.header.setJson(),this.header.remove("Location"),this}redirect(t,e=s.Code.Found){return this.redirectUrl=t,this.status=e,this.header.setLocation(t.toString()),this.data=null,this.message=null,this}getData(){return this.data}get(t){if(this.redirectUrl)return new Response(null,{status:this.status,headers:this.header.native});let e=new s,a={data:this.data||{},message:this.message,success:e.isSuccessful(this.status),done:this.done,status:this.status,isClientError:e.isClientError(this.status),isServerError:e.isServerError(this.status),isNotFound:!1,isUnauthorized:!1,isForbidden:!1,app:{env:t||r.PRODUCTION}};return new Response(JSON.stringify(a),{status:a.status,headers:this.header.native})}}export{n as HttpResponse};
|
|
2
2
|
|
|
3
|
-
//# debugId=
|
|
3
|
+
//# debugId=A1CEA356DBFBE4D664756E2164756E21
|
package/dist/index.js.map
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["src/HttpResponse.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"import { Environment } from \"@ooneex/app-env\";\nimport { Header, type IHeader } from \"@ooneex/http-header\";\nimport { HttpStatus, type StatusCodeType } from \"@ooneex/http-status\";\nimport type { IResponse, ResponseDataType } from \"./types\";\n\nexport class HttpResponse<Data extends Record<string, unknown> = Record<string, unknown>> implements IResponse<Data> {\n public readonly header: IHeader;\n private data: Data | null = null;\n private status: StatusCodeType = HttpStatus.Code.OK;\n private redirectUrl: string | URL | null = null;\n private message: string | null = null;\n public done = false; // For socket\n\n constructor(header?: IHeader) {\n this.header = header || new Header();\n }\n\n public json(data: Data, status: StatusCodeType = HttpStatus.Code.OK): IResponse<Data> {\n this.data = data;\n this.status = status;\n this.header.setJson();\n this.header.remove(\"Location\");\n this.redirectUrl = null;\n this.message = null;\n\n return this;\n }\n\n public exception(\n message: string,\n config?: {\n data?: Data;\n status?: StatusCodeType;\n },\n ): IResponse<Data> {\n this.message = message;\n this.status = config?.status ?? HttpStatus.Code.InternalServerError;\n this.data = config?.data || null;\n this.redirectUrl = null;\n this.header.setJson();\n this.header.remove(\"Location\");\n\n return this;\n }\n\n public notFound(\n message: string,\n config?: {\n data?: Data;\n status?: StatusCodeType;\n },\n ): IResponse<Data> {\n this.message = message;\n this.status = config?.status || HttpStatus.Code.NotFound;\n this.data = config?.data || null;\n this.redirectUrl = null;\n this.header.setJson();\n this.header.remove(\"Location\");\n\n return this;\n }\n\n public redirect(url: string | URL, status: StatusCodeType = HttpStatus.Code.Found): IResponse<Data> {\n this.redirectUrl = url;\n this.status = status;\n this.header.setLocation(url.toString());\n this.data = null;\n this.message = null;\n\n return this;\n }\n\n public get(): Response {\n if (this.redirectUrl) {\n return new Response(null, {\n status: this.status,\n headers: this.header.native,\n });\n }\n\n const status = new HttpStatus();\n\n const responseData: ResponseDataType<Data> = {\n data: this.data || ({} as Data),\n message: this.message,\n success: status.isSuccessful(this.status),\n done: this.done,\n status: this.status,\n isClientError: status.isClientError(this.status),\n isServerError: status.isServerError(this.status),\n isNotFound: false,\n isUnauthorized: false,\n isForbidden: false,\n
|
|
5
|
+
"import { Environment } from \"@ooneex/app-env\";\nimport { Header, type IHeader } from \"@ooneex/http-header\";\nimport { HttpStatus, type StatusCodeType } from \"@ooneex/http-status\";\nimport type { IResponse, ResponseDataType } from \"./types\";\n\nexport class HttpResponse<Data extends Record<string, unknown> = Record<string, unknown>> implements IResponse<Data> {\n public readonly header: IHeader;\n private data: Data | null = null;\n private status: StatusCodeType = HttpStatus.Code.OK;\n private redirectUrl: string | URL | null = null;\n private message: string | null = null;\n public done = false; // For socket\n\n constructor(header?: IHeader) {\n this.header = header || new Header();\n }\n\n public json(data: Data, status: StatusCodeType = HttpStatus.Code.OK): IResponse<Data> {\n this.data = data;\n this.status = status;\n this.header.setJson();\n this.header.remove(\"Location\");\n this.redirectUrl = null;\n this.message = null;\n\n return this;\n }\n\n public exception(\n message: string,\n config?: {\n data?: Data;\n status?: StatusCodeType;\n },\n ): IResponse<Data> {\n this.message = message;\n this.status = config?.status ?? HttpStatus.Code.InternalServerError;\n this.data = config?.data || null;\n this.redirectUrl = null;\n this.header.setJson();\n this.header.remove(\"Location\");\n\n return this;\n }\n\n public notFound(\n message: string,\n config?: {\n data?: Data;\n status?: StatusCodeType;\n },\n ): IResponse<Data> {\n this.message = message;\n this.status = config?.status || HttpStatus.Code.NotFound;\n this.data = config?.data || null;\n this.redirectUrl = null;\n this.header.setJson();\n this.header.remove(\"Location\");\n\n return this;\n }\n\n public redirect(url: string | URL, status: StatusCodeType = HttpStatus.Code.Found): IResponse<Data> {\n this.redirectUrl = url;\n this.status = status;\n this.header.setLocation(url.toString());\n this.data = null;\n this.message = null;\n\n return this;\n }\n\n public getData(): Data | null {\n return this.data;\n }\n\n public get(env?: Environment): Response {\n if (this.redirectUrl) {\n return new Response(null, {\n status: this.status,\n headers: this.header.native,\n });\n }\n\n const status = new HttpStatus();\n\n const responseData: ResponseDataType<Data> = {\n data: this.data || ({} as Data),\n message: this.message,\n success: status.isSuccessful(this.status),\n done: this.done,\n status: this.status,\n isClientError: status.isClientError(this.status),\n isServerError: status.isServerError(this.status),\n isNotFound: false,\n isUnauthorized: false,\n isForbidden: false,\n app: {\n env: env || Environment.PRODUCTION,\n },\n };\n\n return new Response(JSON.stringify(responseData), {\n status: responseData.status,\n headers: this.header.native,\n });\n }\n}\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": "AAAA,sBAAS,wBACT,iBAAS,4BACT,qBAAS,4BAGF,MAAM,CAAwG,CACnG,OACR,KAAoB,KACpB,OAAyB,EAAW,KAAK,GACzC,YAAmC,KACnC,QAAyB,KAC1B,KAAO,GAEd,WAAW,CAAC,EAAkB,CAC5B,KAAK,OAAS,GAAU,IAAI,EAGvB,IAAI,CAAC,EAAY,EAAyB,EAAW,KAAK,GAAqB,CAQpF,OAPA,KAAK,KAAO,EACZ,KAAK,OAAS,EACd,KAAK,OAAO,QAAQ,EACpB,KAAK,OAAO,OAAO,UAAU,EAC7B,KAAK,YAAc,KACnB,KAAK,QAAU,KAER,KAGF,SAAS,CACd,EACA,EAIiB,CAQjB,OAPA,KAAK,QAAU,EACf,KAAK,OAAS,GAAQ,QAAU,EAAW,KAAK,oBAChD,KAAK,KAAO,GAAQ,MAAQ,KAC5B,KAAK,YAAc,KACnB,KAAK,OAAO,QAAQ,EACpB,KAAK,OAAO,OAAO,UAAU,EAEtB,KAGF,QAAQ,CACb,EACA,EAIiB,CAQjB,OAPA,KAAK,QAAU,EACf,KAAK,OAAS,GAAQ,QAAU,EAAW,KAAK,SAChD,KAAK,KAAO,GAAQ,MAAQ,KAC5B,KAAK,YAAc,KACnB,KAAK,OAAO,QAAQ,EACpB,KAAK,OAAO,OAAO,UAAU,EAEtB,KAGF,QAAQ,CAAC,EAAmB,EAAyB,EAAW,KAAK,MAAwB,CAOlG,OANA,KAAK,YAAc,EACnB,KAAK,OAAS,EACd,KAAK,OAAO,YAAY,EAAI,SAAS,CAAC,EACtC,KAAK,KAAO,KACZ,KAAK,QAAU,KAER,KAGF,GAAG,
|
|
8
|
-
"debugId": "
|
|
7
|
+
"mappings": "AAAA,sBAAS,wBACT,iBAAS,4BACT,qBAAS,4BAGF,MAAM,CAAwG,CACnG,OACR,KAAoB,KACpB,OAA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AAe,EAAO,cAAc,KAAK,MAAM,EAC/C,cAAe,EAAO,cAAc,KAAK,MAAM,EAC/C,WAAY,GACZ,eAAgB,GAChB,YAAa,GACb,IAAK,CACH,IAAK,GAAO,EAAY,UAC1B,CACF,EAEA,OAAO,IAAI,SAAS,KAAK,UAAU,CAAY,EAAG,CAChD,OAAQ,EAAa,OACrB,QAAS,KAAK,OAAO,MACvB,CAAC,EAEL",
|
|
8
|
+
"debugId": "A1CEA356DBFBE4D664756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ooneex/http-response",
|
|
3
|
-
"description": "",
|
|
4
|
-
"version": "0.0
|
|
3
|
+
"description": "HTTP response builder with status codes, headers, cookies, and content formatting support",
|
|
4
|
+
"version": "0.3.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
7
7
|
"dist",
|
|
@@ -25,9 +25,8 @@
|
|
|
25
25
|
"compile": "tsc ./src/index.ts --declaration --emitDeclarationOnly --target ES2022 --moduleResolution bundler --outfile dist/index.d.ts",
|
|
26
26
|
"build": "bunup",
|
|
27
27
|
"lint": "tsgo --noEmit && bunx biome lint",
|
|
28
|
-
"publish
|
|
29
|
-
"
|
|
30
|
-
"publish:dry": "bun publish --dry-run"
|
|
28
|
+
"publish": "bun publish --access public || true",
|
|
29
|
+
"test": "bun test tests"
|
|
31
30
|
},
|
|
32
31
|
"dependencies": {
|
|
33
32
|
"@ooneex/app-env": "0.0.1",
|
|
@@ -35,5 +34,15 @@
|
|
|
35
34
|
"@ooneex/http-status": "0.0.1"
|
|
36
35
|
},
|
|
37
36
|
"devDependencies": {},
|
|
38
|
-
"
|
|
37
|
+
"keywords": [
|
|
38
|
+
"bun",
|
|
39
|
+
"cookies",
|
|
40
|
+
"headers",
|
|
41
|
+
"http",
|
|
42
|
+
"http-response",
|
|
43
|
+
"ooneex",
|
|
44
|
+
"response",
|
|
45
|
+
"typescript",
|
|
46
|
+
"web"
|
|
47
|
+
]
|
|
39
48
|
}
|
|
Binary file
|