From d2552278ca304998552041903c5a647698d14ab7 Mon Sep 17 00:00:00 2001 From: ancientbag Date: Mon, 5 May 2025 17:47:13 +0500 Subject: [PATCH 01/18] feat: init --- services/http-request/.npmignore | 1 + services/http-request/README.md | 12 +++++ services/http-request/package.json | 34 +++++++++++++ services/http-request/rollup.config.js | 11 ++++ services/http-request/src/httpRequest.ts | 50 +++++++++++++++++++ .../http-request/src/httpRequest.types.ts | 0 services/http-request/src/rest.types.ts | 7 +++ services/http-request/src/restController.ts | 20 ++++++++ .../http-request/src/restController.types.ts | 4 ++ .../src/restControllerTemplates.ts | 34 +++++++++++++ services/http-request/tsconfig.json | 13 +++++ 11 files changed, 186 insertions(+) create mode 100644 services/http-request/.npmignore create mode 100644 services/http-request/README.md create mode 100644 services/http-request/package.json create mode 100644 services/http-request/rollup.config.js create mode 100644 services/http-request/src/httpRequest.ts create mode 100644 services/http-request/src/httpRequest.types.ts create mode 100644 services/http-request/src/rest.types.ts create mode 100644 services/http-request/src/restController.ts create mode 100644 services/http-request/src/restController.types.ts create mode 100644 services/http-request/src/restControllerTemplates.ts create mode 100644 services/http-request/tsconfig.json diff --git a/services/http-request/.npmignore b/services/http-request/.npmignore new file mode 100644 index 00000000..e8310385 --- /dev/null +++ b/services/http-request/.npmignore @@ -0,0 +1 @@ +src \ No newline at end of file diff --git a/services/http-request/README.md b/services/http-request/README.md new file mode 100644 index 00000000..97b21d63 --- /dev/null +++ b/services/http-request/README.md @@ -0,0 +1,12 @@ +# `@byndyusoft-ui/http-request` + +> Http request service +### Installation + +```bash +npm i @byndyusoft-ui/http-request +``` + +## Usage + +TBD \ No newline at end of file diff --git a/services/http-request/package.json b/services/http-request/package.json new file mode 100644 index 00000000..6579eacc --- /dev/null +++ b/services/http-request/package.json @@ -0,0 +1,34 @@ +{ + "name": "@byndyusoft-ui/http-request", + "version": "0.0.1", + "description": "Byndyusoft UI HTTP Service", + "keywords": [ + "byndyusoft", + "byndyusoft-ui", + "http", + "request", + "axios", + "fetch" + ], + "author": "Byndyusoft Frontend Developer ", + "homepage": "https://github.com/Byndyusoft/ui/tree/master/services/http-request#readme", + "license": "Apache-2.0", + "main": "dist/index.js", + "types": "dist/index.d.ts", + "repository": { + "type": "git", + "url": "git+https://github.com/Byndyusoft/ui.git" + }, + "scripts": { + "build": "tsc --project tsconfig.build.json", + "clean": "rimraf dist", + "lint": "eslint src --config ../../eslint.config.js", + "test": "jest --config ../../jest.config.js --roots services/pub-sub/src" + }, + "bugs": { + "url": "https://github.com/Byndyusoft/ui/issues" + }, + "publishConfig": { + "access": "public" + } + } \ No newline at end of file diff --git a/services/http-request/rollup.config.js b/services/http-request/rollup.config.js new file mode 100644 index 00000000..87cb86d1 --- /dev/null +++ b/services/http-request/rollup.config.js @@ -0,0 +1,11 @@ +import typescript from '@rollup/plugin-typescript'; +import baseConfig from '../../rollup.base.config'; + +export default { + ...baseConfig, + input: ['src/index.ts'], + plugins: [ + ...baseConfig.plugins, + typescript({ tsconfig: './tsconfig.json', exclude: ['src/**/*.stories.tsx', 'src/**/*.tests.tsx', 'node_modules'] }) + ] +}; diff --git a/services/http-request/src/httpRequest.ts b/services/http-request/src/httpRequest.ts new file mode 100644 index 00000000..886b647e --- /dev/null +++ b/services/http-request/src/httpRequest.ts @@ -0,0 +1,50 @@ +import HttpRestController from './restController'; +import { IHTTPRequestRestController } from './restController.types'; +import { fetchRestController, TFetchGetFn, TFetchPostFn } from './restControllerTemplates'; + +interface IHttpRestControllerOptions { + restController?: IHTTPRequestRestController; +} + +class HttpRequest< + GetHandler extends (...args: Parameters) => ReturnType = TFetchGetFn, + PostHandler extends (...args: Parameters) => ReturnType = TFetchPostFn +> { + private restController: + | IHTTPRequestRestController + | IHTTPRequestRestController; + + constructor(options?: IHttpRestControllerOptions) { + if (options?.restController) { + this.restController = new HttpRestController(options?.restController); + } else { + this.restController = new HttpRestController(fetchRestController); + } + } + + get(...args: Parameters) { + return Function.prototype.apply(this.restController.get, args) as GetHandler; + } + + post(...args: Parameters) { + return Function.prototype.apply(this.restController.post, args) as PostHandler; + } +} + +// type TTestGet = () => Promise; +// type TTestPost = (url: string, body: object) => Promise; + +// const TestController = new HttpRestController({ +// get() { +// return Promise.resolve() as Promise; +// }, +// post: (url, body) => { +// return new Promise(() => {}); +// } +// }); + +// const Test = new HttpRequest({ +// restController: TestController +// }); + +export default HttpRequest; diff --git a/services/http-request/src/httpRequest.types.ts b/services/http-request/src/httpRequest.types.ts new file mode 100644 index 00000000..e69de29b diff --git a/services/http-request/src/rest.types.ts b/services/http-request/src/rest.types.ts new file mode 100644 index 00000000..4a4276cb --- /dev/null +++ b/services/http-request/src/rest.types.ts @@ -0,0 +1,7 @@ +type TRequestUrlParam = string; +type TRequestParams = object; +type TRequestOptions = object; +type TRequestBody = object; + +export type TRequestGetArguments = [url: TRequestUrlParam, options?: RequestInit]; +export type TRequestPostArguments = [url: TRequestUrlParam, body?: B]; diff --git a/services/http-request/src/restController.ts b/services/http-request/src/restController.ts new file mode 100644 index 00000000..8a28e486 --- /dev/null +++ b/services/http-request/src/restController.ts @@ -0,0 +1,20 @@ +import { IHTTPRequestRestController } from './restController.types'; + +interface IHttpRestControllerOptions + extends IHTTPRequestRestController {} + +class HttpRestController implements IHTTPRequestRestController { + constructor(public options: IHttpRestControllerOptions) { + this.get = options.get; + this.post = options.post; + } + + get: GetHandler; + post: PostHandler; + + // post(args: PostArguments): Promise { + // return this.options.post(args); + // } +} + +export default HttpRestController; diff --git a/services/http-request/src/restController.types.ts b/services/http-request/src/restController.types.ts new file mode 100644 index 00000000..9330a57c --- /dev/null +++ b/services/http-request/src/restController.types.ts @@ -0,0 +1,4 @@ +export interface IHTTPRequestRestController { + get: GetHandler; + post: PostHandler; +} diff --git a/services/http-request/src/restControllerTemplates.ts b/services/http-request/src/restControllerTemplates.ts new file mode 100644 index 00000000..1e22dd1f --- /dev/null +++ b/services/http-request/src/restControllerTemplates.ts @@ -0,0 +1,34 @@ +import { IHTTPRequestRestController } from './restController.types'; + +export type TFetchGetArguments = [url: string, options?: RequestInit]; +export type TFetchPostArgumentsBody = object | string | number | boolean | undefined; +export type TFetchPostArguments = [url: string, body: TFetchPostArgumentsBody, options?: RequestInit]; + +export type TFetchGetFn = (...args: TFetchGetArguments) => Promise; +export type TFetchPostFn = (...args: TFetchPostArguments) => Promise; + +// Default rest controller with 'fetch' +export const fetchRestController: IHTTPRequestRestController = { + get: async (...args) => { + const [url, options] = args; + + try { + const response = await fetch(url, options); + return response.json(); + } catch (error) { + throw error; + } + }, + post: async (...args) => { + const [url, body] = args; + try { + const response = await fetch(url, { + method: 'POST', + body: body ? JSON.stringify(body) : undefined + }); + return response.json(); + } catch (error) { + throw error; + } + } +}; diff --git a/services/http-request/tsconfig.json b/services/http-request/tsconfig.json new file mode 100644 index 00000000..567aaea9 --- /dev/null +++ b/services/http-request/tsconfig.json @@ -0,0 +1,13 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "declaration": true, + "declarationDir": "dist", + "outDir": "dist", + "module": "commonjs" + }, + "include": [ + "../../types.d.ts", + "src" + ] +} From e7da701ac9cc0769de302de2cd02592524e1ca32 Mon Sep 17 00:00:00 2001 From: ancientbag Date: Mon, 5 May 2025 20:27:45 +0500 Subject: [PATCH 02/18] feat: rest methods --- services/http-request/src/httpRequest.ts | 73 +++++++++++++++---- .../http-request/src/httpRequest.types.ts | 0 services/http-request/src/rest.types.ts | 7 -- services/http-request/src/restController.ts | 32 ++++++-- .../http-request/src/restController.types.ts | 5 +- .../src/restControllerTemplates.ts | 44 ++++++++++- 6 files changed, 131 insertions(+), 30 deletions(-) delete mode 100644 services/http-request/src/httpRequest.types.ts delete mode 100644 services/http-request/src/rest.types.ts diff --git a/services/http-request/src/httpRequest.ts b/services/http-request/src/httpRequest.ts index 886b647e..521f60b0 100644 --- a/services/http-request/src/httpRequest.ts +++ b/services/http-request/src/httpRequest.ts @@ -2,37 +2,84 @@ import HttpRestController from './restController'; import { IHTTPRequestRestController } from './restController.types'; import { fetchRestController, TFetchGetFn, TFetchPostFn } from './restControllerTemplates'; -interface IHttpRestControllerOptions { - restController?: IHTTPRequestRestController; +interface IHttpRequestOptions { + restController?: IHTTPRequestRestController; } class HttpRequest< GetHandler extends (...args: Parameters) => ReturnType = TFetchGetFn, - PostHandler extends (...args: Parameters) => ReturnType = TFetchPostFn + PostHandler extends (...args: Parameters) => ReturnType = TFetchPostFn, + PatchHandler extends (...args: Parameters) => ReturnType = TFetchPostFn, + PutHandler extends (...args: Parameters) => ReturnType = TFetchPostFn, + DeleteHandler extends (...args: Parameters) => ReturnType = TFetchPostFn > { - private restController: - | IHTTPRequestRestController - | IHTTPRequestRestController; + private readonly restController: + | IHTTPRequestRestController + | IHTTPRequestRestController; - constructor(options?: IHttpRestControllerOptions) { + constructor(options?: IHttpRequestOptions) { if (options?.restController) { - this.restController = new HttpRestController(options?.restController); + this.restController = new HttpRestController< + GetHandler, + PostHandler, + PatchHandler, + PutHandler, + DeleteHandler + >(options?.restController); } else { - this.restController = new HttpRestController(fetchRestController); + this.restController = new HttpRestController< + TFetchGetFn, + TFetchPostFn, + TFetchPostFn, + TFetchPostFn, + TFetchPostFn + >(fetchRestController); } } get(...args: Parameters) { - return Function.prototype.apply(this.restController.get, args) as GetHandler; + try { + return Function.prototype.apply(this.restController.get, args); + } catch (exception) { + throw exception; + } } post(...args: Parameters) { - return Function.prototype.apply(this.restController.post, args) as PostHandler; + try { + return Function.prototype.apply(this.restController.post, args); + } catch (exception) { + throw exception; + } + } + + patch(...args: Parameters): PatchHandler { + try { + return Function.prototype.apply(this.restController.patch, args); + } catch (exception) { + throw exception; + } + } + + put(...args: Parameters) { + try { + return Function.prototype.apply(this.restController.put, args); + } catch (exception) { + throw exception; + } + } + + delete(...args: Parameters) { + try { + return Function.prototype.apply(this.restController.delete, args); + } catch (exception) { + throw exception; + } } } // type TTestGet = () => Promise; -// type TTestPost = (url: string, body: object) => Promise; +// type TTestPost = (url: string, ebody: object) => Promise; // const TestController = new HttpRestController({ // get() { @@ -43,7 +90,7 @@ class HttpRequest< // } // }); -// const Test = new HttpRequest({ +// const Test = new HttpRequest({ // restController: TestController // }); diff --git a/services/http-request/src/httpRequest.types.ts b/services/http-request/src/httpRequest.types.ts deleted file mode 100644 index e69de29b..00000000 diff --git a/services/http-request/src/rest.types.ts b/services/http-request/src/rest.types.ts deleted file mode 100644 index 4a4276cb..00000000 --- a/services/http-request/src/rest.types.ts +++ /dev/null @@ -1,7 +0,0 @@ -type TRequestUrlParam = string; -type TRequestParams = object; -type TRequestOptions = object; -type TRequestBody = object; - -export type TRequestGetArguments = [url: TRequestUrlParam, options?: RequestInit]; -export type TRequestPostArguments = [url: TRequestUrlParam, body?: B]; diff --git a/services/http-request/src/restController.ts b/services/http-request/src/restController.ts index 8a28e486..db9219b0 100644 --- a/services/http-request/src/restController.ts +++ b/services/http-request/src/restController.ts @@ -1,20 +1,36 @@ import { IHTTPRequestRestController } from './restController.types'; -interface IHttpRestControllerOptions - extends IHTTPRequestRestController {} +interface IHttpRestControllerOptions< + GetHandler, + PostHandler, + PatchHandler = undefined, + PutHandler = undefined, + DeleteHandler = undefined +> extends IHTTPRequestRestController {} -class HttpRestController implements IHTTPRequestRestController { - constructor(public options: IHttpRestControllerOptions) { +class HttpRestController< + GetHandler, + PostHandler, + PatchHandler = undefined, + PutHandler = undefined, + DeleteHandler = undefined +> implements IHTTPRequestRestController +{ + constructor( + public options: IHttpRestControllerOptions + ) { this.get = options.get; this.post = options.post; + this.patch = options.patch; + this.put = options.put; + this.delete = options.delete; } get: GetHandler; post: PostHandler; - - // post(args: PostArguments): Promise { - // return this.options.post(args); - // } + patch: PatchHandler | undefined; + put: PutHandler | undefined; + delete: DeleteHandler | undefined; } export default HttpRestController; diff --git a/services/http-request/src/restController.types.ts b/services/http-request/src/restController.types.ts index 9330a57c..ed8609d2 100644 --- a/services/http-request/src/restController.types.ts +++ b/services/http-request/src/restController.types.ts @@ -1,4 +1,7 @@ -export interface IHTTPRequestRestController { +export interface IHTTPRequestRestController { get: GetHandler; post: PostHandler; + patch?: PatchHandler | undefined; + put?: PutHandler | undefined; + delete?: DeleteHandler | undefined; } diff --git a/services/http-request/src/restControllerTemplates.ts b/services/http-request/src/restControllerTemplates.ts index 1e22dd1f..83b9c34a 100644 --- a/services/http-request/src/restControllerTemplates.ts +++ b/services/http-request/src/restControllerTemplates.ts @@ -8,7 +8,13 @@ export type TFetchGetFn = (...args: TFetchGetArguments) => Promise; export type TFetchPostFn = (...args: TFetchPostArguments) => Promise; // Default rest controller with 'fetch' -export const fetchRestController: IHTTPRequestRestController = { +export const fetchRestController: IHTTPRequestRestController< + TFetchGetFn, + TFetchPostFn, + TFetchPostFn, + TFetchPostFn, + TFetchPostFn +> = { get: async (...args) => { const [url, options] = args; @@ -30,5 +36,41 @@ export const fetchRestController: IHTTPRequestRestController { + const [url, body] = args; + try { + const response = await fetch(url, { + method: 'PATCH', + body: body ? JSON.stringify(body) : undefined + }); + return response.json(); + } catch (error) { + throw error; + } + }, + put: async (...args) => { + const [url, body] = args; + try { + const response = await fetch(url, { + method: 'PUT', + body: body ? JSON.stringify(body) : undefined + }); + return response.json(); + } catch (error) { + throw error; + } + }, + delete: async (...args) => { + const [url, body] = args; + try { + const response = await fetch(url, { + method: 'DELETE', + body: body ? JSON.stringify(body) : undefined + }); + return response.json(); + } catch (error) { + throw error; + } } }; From 6c4752be482e1c88b2cd490f1e9c3435a9153d92 Mon Sep 17 00:00:00 2001 From: ancientbag Date: Tue, 6 May 2025 12:53:22 +0500 Subject: [PATCH 03/18] feat: refactor --- services/http-request/src/httpRequest.ts | 60 +++++++++++++------ .../http-request/src/httpRequest.types.ts | 5 ++ services/http-request/src/restController.ts | 12 +--- .../http-request/src/restController.types.ts | 10 +++- .../src/restControllerTemplates.ts | 6 +- 5 files changed, 62 insertions(+), 31 deletions(-) create mode 100644 services/http-request/src/httpRequest.types.ts diff --git a/services/http-request/src/httpRequest.ts b/services/http-request/src/httpRequest.ts index 521f60b0..2916d821 100644 --- a/services/http-request/src/httpRequest.ts +++ b/services/http-request/src/httpRequest.ts @@ -1,21 +1,28 @@ +import { IHttpRequestOptions } from './httpRequest.types'; import HttpRestController from './restController'; -import { IHTTPRequestRestController } from './restController.types'; +import { IHTTPRestController } from './restController.types'; import { fetchRestController, TFetchGetFn, TFetchPostFn } from './restControllerTemplates'; -interface IHttpRequestOptions { - restController?: IHTTPRequestRestController; -} - class HttpRequest< - GetHandler extends (...args: Parameters) => ReturnType = TFetchGetFn, - PostHandler extends (...args: Parameters) => ReturnType = TFetchPostFn, - PatchHandler extends (...args: Parameters) => ReturnType = TFetchPostFn, - PutHandler extends (...args: Parameters) => ReturnType = TFetchPostFn, - DeleteHandler extends (...args: Parameters) => ReturnType = TFetchPostFn + GetHandler extends (...args: Parameters) => ReturnType = ( + ...args: Parameters + ) => R, + PostHandler extends (...args: Parameters) => ReturnType = ( + ...args: Parameters + ) => R, + PatchHandler extends (...args: Parameters) => ReturnType = ( + ...args: Parameters + ) => R, + PutHandler extends (...args: Parameters) => ReturnType = ( + ...args: Parameters + ) => R, + DeleteHandler extends (...args: Parameters) => ReturnType = ( + ...args: Parameters + ) => R > { private readonly restController: - | IHTTPRequestRestController - | IHTTPRequestRestController; + | IHTTPRestController + | IHTTPRestController; constructor(options?: IHttpRequestOptions) { if (options?.restController) { @@ -37,7 +44,7 @@ class HttpRequest< } } - get(...args: Parameters) { + get(...args: Parameters): Promise { try { return Function.prototype.apply(this.restController.get, args); } catch (exception) { @@ -45,7 +52,7 @@ class HttpRequest< } } - post(...args: Parameters) { + post(...args: Parameters): Promise { try { return Function.prototype.apply(this.restController.post, args); } catch (exception) { @@ -53,7 +60,7 @@ class HttpRequest< } } - patch(...args: Parameters): PatchHandler { + patch(...args: Parameters): Promise { try { return Function.prototype.apply(this.restController.patch, args); } catch (exception) { @@ -61,7 +68,7 @@ class HttpRequest< } } - put(...args: Parameters) { + put(...args: Parameters): Promise { try { return Function.prototype.apply(this.restController.put, args); } catch (exception) { @@ -69,7 +76,7 @@ class HttpRequest< } } - delete(...args: Parameters) { + delete(...args: Parameters): Promise { try { return Function.prototype.apply(this.restController.delete, args); } catch (exception) { @@ -94,4 +101,23 @@ class HttpRequest< // restController: TestController // }); +async () => { + const TestController = new HttpRestController({ + get(url: string) { + console.log(url); + return Promise.resolve(); + }, + post: (url: string, body: object) => { + console.log({ url, body }); + return new Promise(() => {}); + } + }); + + const httpRequestService = new HttpRequest({ + restController: TestController + }); + + const data = await httpRequestService.get<{ data: string }>('http://localhost:1234/api'); +}; + export default HttpRequest; diff --git a/services/http-request/src/httpRequest.types.ts b/services/http-request/src/httpRequest.types.ts new file mode 100644 index 00000000..c4db91b0 --- /dev/null +++ b/services/http-request/src/httpRequest.types.ts @@ -0,0 +1,5 @@ +import { IHTTPRestController } from './restController.types'; + +export interface IHttpRequestOptions { + restController?: IHTTPRestController; +} diff --git a/services/http-request/src/restController.ts b/services/http-request/src/restController.ts index db9219b0..1ebc4d17 100644 --- a/services/http-request/src/restController.ts +++ b/services/http-request/src/restController.ts @@ -1,12 +1,4 @@ -import { IHTTPRequestRestController } from './restController.types'; - -interface IHttpRestControllerOptions< - GetHandler, - PostHandler, - PatchHandler = undefined, - PutHandler = undefined, - DeleteHandler = undefined -> extends IHTTPRequestRestController {} +import { IHTTPRestController, IHttpRestControllerOptions } from './restController.types'; class HttpRestController< GetHandler, @@ -14,7 +6,7 @@ class HttpRestController< PatchHandler = undefined, PutHandler = undefined, DeleteHandler = undefined -> implements IHTTPRequestRestController +> implements IHTTPRestController { constructor( public options: IHttpRestControllerOptions diff --git a/services/http-request/src/restController.types.ts b/services/http-request/src/restController.types.ts index ed8609d2..222d9e6b 100644 --- a/services/http-request/src/restController.types.ts +++ b/services/http-request/src/restController.types.ts @@ -1,7 +1,15 @@ -export interface IHTTPRequestRestController { +export interface IHTTPRestController { get: GetHandler; post: PostHandler; patch?: PatchHandler | undefined; put?: PutHandler | undefined; delete?: DeleteHandler | undefined; } + +export interface IHttpRestControllerOptions< + GetHandler, + PostHandler, + PatchHandler = undefined, + PutHandler = undefined, + DeleteHandler = undefined +> extends IHTTPRestController {} diff --git a/services/http-request/src/restControllerTemplates.ts b/services/http-request/src/restControllerTemplates.ts index 83b9c34a..6c9dc16f 100644 --- a/services/http-request/src/restControllerTemplates.ts +++ b/services/http-request/src/restControllerTemplates.ts @@ -1,14 +1,14 @@ -import { IHTTPRequestRestController } from './restController.types'; +import { IHTTPRestController } from './restController.types'; export type TFetchGetArguments = [url: string, options?: RequestInit]; export type TFetchPostArgumentsBody = object | string | number | boolean | undefined; export type TFetchPostArguments = [url: string, body: TFetchPostArgumentsBody, options?: RequestInit]; -export type TFetchGetFn = (...args: TFetchGetArguments) => Promise; +export type TFetchGetFn> = (...args: TFetchGetArguments) => Promise; export type TFetchPostFn = (...args: TFetchPostArguments) => Promise; // Default rest controller with 'fetch' -export const fetchRestController: IHTTPRequestRestController< +export const fetchRestController: IHTTPRestController< TFetchGetFn, TFetchPostFn, TFetchPostFn, From 77756ca3015d47287f31104e827c3f33a633cd37 Mon Sep 17 00:00:00 2001 From: ancientbag Date: Tue, 6 May 2025 16:37:27 +0500 Subject: [PATCH 04/18] feat: refactor, reexports --- package-lock.json | 19 +++++++++++-- services/http-request/README.md | 27 +++++++++++++++++- services/http-request/package.json | 17 ++++++++---- services/http-request/src/httpRequest.ts | 35 ------------------------ services/http-request/src/index.ts | 4 +++ 5 files changed, 59 insertions(+), 43 deletions(-) create mode 100644 services/http-request/src/index.ts diff --git a/package-lock.json b/package-lock.json index c06cb0c4..a2617d2c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -691,8 +691,8 @@ "node": ">=6.9.0" } }, - "node_modules/@byndyusoft-ui/css-tools": { - "resolved": "styles/tools", + "node_modules/@byndyusoft-ui/css-utilities": { + "resolved": "styles/utilities", "link": true }, "node_modules/@byndyusoft-ui/flex": { @@ -707,6 +707,10 @@ "resolved": "components/highlighter", "link": true }, + "node_modules/@byndyusoft-ui/http-request": { + "resolved": "services/http-request", + "link": true + }, "node_modules/@byndyusoft-ui/keyframes-css": { "resolved": "styles/keyframes-css", "link": true @@ -11151,6 +11155,11 @@ "version": "0.3.0", "license": "Apache-2.0" }, + "services/http-request": { + "name": "@byndyusoft-ui/http-request", + "version": "0.0.1", + "license": "Apache-2.0" + }, "styles/keyframes-css": { "name": "@byndyusoft-ui/keyframes-css", "version": "0.0.1", @@ -11164,6 +11173,12 @@ "styles/tools": { "name": "@byndyusoft-ui/css-tools", "version": "0.0.1", + "extraneous": true, + "license": "Apache-2.0" + }, + "styles/utilities": { + "name": "@byndyusoft-ui/css-utilities", + "version": "0.0.1", "license": "Apache-2.0" } } diff --git a/services/http-request/README.md b/services/http-request/README.md index 97b21d63..b39e247b 100644 --- a/services/http-request/README.md +++ b/services/http-request/README.md @@ -9,4 +9,29 @@ npm i @byndyusoft-ui/http-request ## Usage -TBD \ No newline at end of file +### To start using this service you need to create a new class instance of HttpRequest. +By default this service is using 'fetch' for sending requests. + +```ts + const httpRequestService = new HttpRequest(); + + httpRequestService.get("http://localhost:3000/api/"); +``` + +### You can define own HttpRestController and pass it like on example below. +❗GET and POST methods must be described, others (PATCH/PUT/DELETE) are optional. + +```ts + const restController = new HttpRestController({ + get: () => {}, + post: () => {}, + /// ... + }) + + const httpRequestService = new HttpRequest({ + restController + }); + + httpRequestService.get("http://localhost:3000/api/"); + +``` \ No newline at end of file diff --git a/services/http-request/package.json b/services/http-request/package.json index 6579eacc..d2bc8622 100644 --- a/services/http-request/package.json +++ b/services/http-request/package.json @@ -20,11 +20,18 @@ "url": "git+https://github.com/Byndyusoft/ui.git" }, "scripts": { - "build": "tsc --project tsconfig.build.json", - "clean": "rimraf dist", - "lint": "eslint src --config ../../eslint.config.js", - "test": "jest --config ../../jest.config.js --roots services/pub-sub/src" - }, + "build": "rollup --config", + "clean": "rimraf dist", + "test": "jest --config ../../jest.config.js --roots services/http-request/src", + "lint:check": "npm run eslint:check && npm run prettier:check && npm run stylelint:check", + "lint:fix": "npm run eslint:fix && npm run prettier:fix && npm run stylelint:fix", + "eslint:check": "eslint src --config ../../eslint.config.js", + "eslint:fix": "eslint src --config ../../eslint.config.js --fix", + "prettier:check": "prettier --check '**/*.{ts,tsx,css,scss,json}' '!**/dist/**'", + "prettier:fix": "prettier --write '**/*.{ts,tsx,css,scss,json}' '!**/dist/**'", + "stylelint:check": "stylelint '**/*.{css,scss}' --allow-empty-input", + "stylelint:fix": "stylelint '**/*.{css,scss}' --fix --allow-empty-input" + }, "bugs": { "url": "https://github.com/Byndyusoft/ui/issues" }, diff --git a/services/http-request/src/httpRequest.ts b/services/http-request/src/httpRequest.ts index 2916d821..ae0e39a8 100644 --- a/services/http-request/src/httpRequest.ts +++ b/services/http-request/src/httpRequest.ts @@ -85,39 +85,4 @@ class HttpRequest< } } -// type TTestGet = () => Promise; -// type TTestPost = (url: string, ebody: object) => Promise; - -// const TestController = new HttpRestController({ -// get() { -// return Promise.resolve() as Promise; -// }, -// post: (url, body) => { -// return new Promise(() => {}); -// } -// }); - -// const Test = new HttpRequest({ -// restController: TestController -// }); - -async () => { - const TestController = new HttpRestController({ - get(url: string) { - console.log(url); - return Promise.resolve(); - }, - post: (url: string, body: object) => { - console.log({ url, body }); - return new Promise(() => {}); - } - }); - - const httpRequestService = new HttpRequest({ - restController: TestController - }); - - const data = await httpRequestService.get<{ data: string }>('http://localhost:1234/api'); -}; - export default HttpRequest; diff --git a/services/http-request/src/index.ts b/services/http-request/src/index.ts new file mode 100644 index 00000000..d3ae3f61 --- /dev/null +++ b/services/http-request/src/index.ts @@ -0,0 +1,4 @@ +import HttpRequest from './httpRequest'; +import HttpRestController from './restController'; + +export { HttpRequest, HttpRestController }; From 8b6d25391d4dbb2169897892c86b1569d7a35cdf Mon Sep 17 00:00:00 2001 From: ancientbag Date: Mon, 12 May 2025 14:30:36 +0500 Subject: [PATCH 05/18] feat: refactor --- .../src/constants/axiosRestController.ts | 71 ++++++++++++ .../src/constants/fetchRestController.ts | 49 ++++++++ services/http-request/src/httpRequest.ts | 109 +++++------------- .../http-request/src/httpRequest.types.ts | 6 +- services/http-request/src/index.ts | 4 +- services/http-request/src/restController.ts | 31 +---- .../http-request/src/restController.types.ts | 15 --- .../src/restControllerTemplates.ts | 76 ------------ 8 files changed, 162 insertions(+), 199 deletions(-) create mode 100644 services/http-request/src/constants/axiosRestController.ts create mode 100644 services/http-request/src/constants/fetchRestController.ts delete mode 100644 services/http-request/src/restController.types.ts delete mode 100644 services/http-request/src/restControllerTemplates.ts diff --git a/services/http-request/src/constants/axiosRestController.ts b/services/http-request/src/constants/axiosRestController.ts new file mode 100644 index 00000000..375e4491 --- /dev/null +++ b/services/http-request/src/constants/axiosRestController.ts @@ -0,0 +1,71 @@ +import axios, { AxiosInstance, AxiosResponse } from 'axios'; +import HttpRestController from '../restController'; + +const DEFAULT_REQUEST_TIMEOUT = 60000; + +export class HttpRestControllerAxios extends HttpRestController { + public axiosInstance: AxiosInstance; + + constructor() { + super(); + this.axiosInstance = axios.create({ + headers: { + 'X-Requested-With': 'XMLHttpRequest', + 'Cache-control': 'no-cache', + Pragma: 'no-cache', + 'Access-Control-Expose-Headers': 'Content-Disposition' + }, + timeout: DEFAULT_REQUEST_TIMEOUT + }); + } + + async get>(url: string, params: object = {}, options: object = {}): Promise { + return this.axiosInstance.get(url, { + params, + ...options + }); + } + + async post>( + url: string, + body?: object, + params: object = {}, + options: object = {} + ): Promise { + return this.axiosInstance.post(url, body, { + params, + ...options + }); + } + + async patch>( + url: string, + body?: object, + params: object = {}, + options: object = {} + ): Promise { + return this.axiosInstance.patch(url, body, { + params, + ...options + }); + } + + async put>( + url: string, + body?: object, + params: object = {}, + options: object = {} + ): Promise { + return this.axiosInstance.put(url, body, { + params, + ...options + }); + } + + async delete>(url: string, params: object = {}, options: object = {}): Promise { + return this.axiosInstance.delete(url, { + params, + ...options + }); + } +} diff --git a/services/http-request/src/constants/fetchRestController.ts b/services/http-request/src/constants/fetchRestController.ts new file mode 100644 index 00000000..96ce0189 --- /dev/null +++ b/services/http-request/src/constants/fetchRestController.ts @@ -0,0 +1,49 @@ +import HttpRestController from '../restController'; + +export class HttpRestControllerFetch extends HttpRestController { + constructor() { + super(); + this.headers = new Headers(); + } + + public headers: Headers; + + async get(url: string, headers?: Headers): Promise { + return fetch(url, { method: 'GET', headers: { ...this.headers, ...headers } }) as Promise; + } + + async post(url: string, body: object, headers?: Headers): Promise { + return fetch(url, { + method: 'POST', + body: JSON.stringify(body), + headers: { + ...this.headers, + ...headers + } + }) as Promise; + } + + async put(url: string, body: object, headers?: Headers): Promise { + return fetch(url, { + method: 'PUT', + body: JSON.stringify(body), + headers: { ...this.headers, ...headers } + }) as Promise; + } + + async patch(url: string, body: object, headers?: Headers): Promise { + return fetch(url, { + method: 'PATCH', + body: JSON.stringify(body), + headers: { ...this.headers, ...headers } + }) as Promise; + } + + async delete(url: string, body: object = {}, headers?: Headers): Promise { + return fetch(url, { + method: 'DELETE', + body: JSON.stringify(body), + headers: { ...this.headers, ...headers } + }) as Promise; + } +} diff --git a/services/http-request/src/httpRequest.ts b/services/http-request/src/httpRequest.ts index ae0e39a8..acffc92e 100644 --- a/services/http-request/src/httpRequest.ts +++ b/services/http-request/src/httpRequest.ts @@ -1,88 +1,39 @@ +import { HttpRestControllerAxios } from './constants/axiosRestController'; +import { HttpRestControllerFetch } from './constants/fetchRestController'; import { IHttpRequestOptions } from './httpRequest.types'; import HttpRestController from './restController'; -import { IHTTPRestController } from './restController.types'; -import { fetchRestController, TFetchGetFn, TFetchPostFn } from './restControllerTemplates'; -class HttpRequest< - GetHandler extends (...args: Parameters) => ReturnType = ( - ...args: Parameters - ) => R, - PostHandler extends (...args: Parameters) => ReturnType = ( - ...args: Parameters - ) => R, - PatchHandler extends (...args: Parameters) => ReturnType = ( - ...args: Parameters - ) => R, - PutHandler extends (...args: Parameters) => ReturnType = ( - ...args: Parameters - ) => R, - DeleteHandler extends (...args: Parameters) => ReturnType = ( - ...args: Parameters - ) => R -> { - private readonly restController: - | IHTTPRestController - | IHTTPRestController; - - constructor(options?: IHttpRequestOptions) { - if (options?.restController) { - this.restController = new HttpRestController< - GetHandler, - PostHandler, - PatchHandler, - PutHandler, - DeleteHandler - >(options?.restController); +class HttpRequest { + public restController: RestController | undefined; + + public get: RestController['get']; + public post: RestController['post']; + public patch: RestController['patch']; + public put: RestController['put']; + public delete: RestController['delete']; + + constructor(options: IHttpRequestOptions) { + if (options.restController) { + const restController = options.restController; + this.restController = restController; + + this.get = this.restController.get; + this.post = this.restController.post; + this.patch = this.restController.patch; + this.put = this.restController.put; + this.delete = this.restController.delete; } else { - this.restController = new HttpRestController< - TFetchGetFn, - TFetchPostFn, - TFetchPostFn, - TFetchPostFn, - TFetchPostFn - >(fetchRestController); - } - } - - get(...args: Parameters): Promise { - try { - return Function.prototype.apply(this.restController.get, args); - } catch (exception) { - throw exception; - } - } - - post(...args: Parameters): Promise { - try { - return Function.prototype.apply(this.restController.post, args); - } catch (exception) { - throw exception; - } - } - - patch(...args: Parameters): Promise { - try { - return Function.prototype.apply(this.restController.patch, args); - } catch (exception) { - throw exception; - } - } - - put(...args: Parameters): Promise { - try { - return Function.prototype.apply(this.restController.put, args); - } catch (exception) { - throw exception; - } - } - - delete(...args: Parameters): Promise { - try { - return Function.prototype.apply(this.restController.delete, args); - } catch (exception) { - throw exception; + this.get = () => Promise.reject('get handler was not specified'); + this.post = () => Promise.reject('post handler was not specified'); + this.patch = () => Promise.reject('patch handler was not specified'); + this.put = () => Promise.reject('put handler was not specified'); + this.delete = () => Promise.reject('delete handler was not specified'); } } } +const httpRequest = new HttpRequest({ + restController: new HttpRestControllerAxios() +}); + export default HttpRequest; diff --git a/services/http-request/src/httpRequest.types.ts b/services/http-request/src/httpRequest.types.ts index c4db91b0..c0a66241 100644 --- a/services/http-request/src/httpRequest.types.ts +++ b/services/http-request/src/httpRequest.types.ts @@ -1,5 +1,5 @@ -import { IHTTPRestController } from './restController.types'; +import HttpRestController from './restController'; -export interface IHttpRequestOptions { - restController?: IHTTPRestController; +export interface IHttpRequestOptions { + restController?: RestController; } diff --git a/services/http-request/src/index.ts b/services/http-request/src/index.ts index d3ae3f61..a473fba8 100644 --- a/services/http-request/src/index.ts +++ b/services/http-request/src/index.ts @@ -1,4 +1,6 @@ import HttpRequest from './httpRequest'; import HttpRestController from './restController'; +import { HttpRestControllerAxios } from './constants/axiosRestController'; +import { HttpRestControllerFetch } from './constants/fetchRestController'; -export { HttpRequest, HttpRestController }; +export { HttpRequest, HttpRestController, HttpRestControllerAxios, HttpRestControllerFetch }; diff --git a/services/http-request/src/restController.ts b/services/http-request/src/restController.ts index 1ebc4d17..86070ca6 100644 --- a/services/http-request/src/restController.ts +++ b/services/http-request/src/restController.ts @@ -1,28 +1,9 @@ -import { IHTTPRestController, IHttpRestControllerOptions } from './restController.types'; - -class HttpRestController< - GetHandler, - PostHandler, - PatchHandler = undefined, - PutHandler = undefined, - DeleteHandler = undefined -> implements IHTTPRestController -{ - constructor( - public options: IHttpRestControllerOptions - ) { - this.get = options.get; - this.post = options.post; - this.patch = options.patch; - this.put = options.put; - this.delete = options.delete; - } - - get: GetHandler; - post: PostHandler; - patch: PatchHandler | undefined; - put: PutHandler | undefined; - delete: DeleteHandler | undefined; +abstract class HttpRestController { + abstract get(...args: any[]): Promise; + abstract post(...args: any[]): Promise; + abstract patch(...args: any[]): Promise; + abstract put(...args: any[]): Promise; + abstract delete(...args: any[]): Promise; } export default HttpRestController; diff --git a/services/http-request/src/restController.types.ts b/services/http-request/src/restController.types.ts deleted file mode 100644 index 222d9e6b..00000000 --- a/services/http-request/src/restController.types.ts +++ /dev/null @@ -1,15 +0,0 @@ -export interface IHTTPRestController { - get: GetHandler; - post: PostHandler; - patch?: PatchHandler | undefined; - put?: PutHandler | undefined; - delete?: DeleteHandler | undefined; -} - -export interface IHttpRestControllerOptions< - GetHandler, - PostHandler, - PatchHandler = undefined, - PutHandler = undefined, - DeleteHandler = undefined -> extends IHTTPRestController {} diff --git a/services/http-request/src/restControllerTemplates.ts b/services/http-request/src/restControllerTemplates.ts deleted file mode 100644 index 6c9dc16f..00000000 --- a/services/http-request/src/restControllerTemplates.ts +++ /dev/null @@ -1,76 +0,0 @@ -import { IHTTPRestController } from './restController.types'; - -export type TFetchGetArguments = [url: string, options?: RequestInit]; -export type TFetchPostArgumentsBody = object | string | number | boolean | undefined; -export type TFetchPostArguments = [url: string, body: TFetchPostArgumentsBody, options?: RequestInit]; - -export type TFetchGetFn> = (...args: TFetchGetArguments) => Promise; -export type TFetchPostFn = (...args: TFetchPostArguments) => Promise; - -// Default rest controller with 'fetch' -export const fetchRestController: IHTTPRestController< - TFetchGetFn, - TFetchPostFn, - TFetchPostFn, - TFetchPostFn, - TFetchPostFn -> = { - get: async (...args) => { - const [url, options] = args; - - try { - const response = await fetch(url, options); - return response.json(); - } catch (error) { - throw error; - } - }, - post: async (...args) => { - const [url, body] = args; - try { - const response = await fetch(url, { - method: 'POST', - body: body ? JSON.stringify(body) : undefined - }); - return response.json(); - } catch (error) { - throw error; - } - }, - patch: async (...args) => { - const [url, body] = args; - try { - const response = await fetch(url, { - method: 'PATCH', - body: body ? JSON.stringify(body) : undefined - }); - return response.json(); - } catch (error) { - throw error; - } - }, - put: async (...args) => { - const [url, body] = args; - try { - const response = await fetch(url, { - method: 'PUT', - body: body ? JSON.stringify(body) : undefined - }); - return response.json(); - } catch (error) { - throw error; - } - }, - delete: async (...args) => { - const [url, body] = args; - try { - const response = await fetch(url, { - method: 'DELETE', - body: body ? JSON.stringify(body) : undefined - }); - return response.json(); - } catch (error) { - throw error; - } - } -}; From a899bb8809cf6a9e663c1b8cd2ab2fe7f76f4cd1 Mon Sep 17 00:00:00 2001 From: ancientbag Date: Mon, 12 May 2025 14:30:44 +0500 Subject: [PATCH 06/18] docs: readme upd --- services/http-request/README.md | 77 +++++++++++++++++++++++++++------ 1 file changed, 64 insertions(+), 13 deletions(-) diff --git a/services/http-request/README.md b/services/http-request/README.md index b39e247b..2afa69ce 100644 --- a/services/http-request/README.md +++ b/services/http-request/README.md @@ -9,29 +9,80 @@ npm i @byndyusoft-ui/http-request ## Usage -### To start using this service you need to create a new class instance of HttpRequest. -By default this service is using 'fetch' for sending requests. - +### To start using this service you need to create a new class instance of HttpRequest and provide restController option. +There are two classes ready to be used as restControllers: **HttpRestControllerFetch** and **HttpRestControllerAxios**. For fetch and axios. ```ts - const httpRequestService = new HttpRequest(); + const restController = new HttpRestControllerFetch(); + const httpRequest = new HttpRequest({ + restController +}); httpRequestService.get("http://localhost:3000/api/"); ``` -### You can define own HttpRestController and pass it like on example below. -❗GET and POST methods must be described, others (PATCH/PUT/DELETE) are optional. +### You can define own HttpRestController and pass it like this ```ts - const restController = new HttpRestController({ - get: () => {}, - post: () => {}, - /// ... - }) - + // myOwnHttpRestController.ts + import { HttpRestController } from '@byndyusoft-ui/http-request'; + + class HttpRestControllerCustom extends HttpRestController { + constructor() { + super(); + } + + async get(url: string, headers?: Headers): Promise { + return fetch(url, { method: 'GET', headers: { ...headers } }) as Promise; + } + + async post(url: string, body: object, headers?: Headers): Promise { + return fetch(url, { + method: 'POST', + body: JSON.stringify(body), + headers: { + ...this.headers, + ...headers + } + }) as Promise; + } + + async put(url: string, body: object, headers?: Headers): Promise { + return fetch(url, { + method: 'PUT', + body: JSON.stringify(body), + headers: { ...headers } + }) as Promise; + } + + async patch(url: string, body: object, headers?: Headers): Promise { + return fetch(url, { + method: 'PATCH', + body: JSON.stringify(body), + headers: { ...headers } + }) as Promise; + } + + async delete(url: string, body: object = {}, headers?: Headers): Promise { + return fetch(url, { + method: 'DELETE', + body: JSON.stringify(body), + headers: { ...headers } + }) as Promise; + } + } + + export default HttpRestControllerCustom; +``` +```ts + + // httpRequest.ts + import HttpRestControllerCustom from './myOwnHttpRestController.ts' + + const restController = new HttpRestControllerCustom(); const httpRequestService = new HttpRequest({ restController }); httpRequestService.get("http://localhost:3000/api/"); +``` -``` \ No newline at end of file From c37cc403f114060849c31198900f4c08445d43bc Mon Sep 17 00:00:00 2001 From: ancientbag Date: Mon, 12 May 2025 14:31:03 +0500 Subject: [PATCH 07/18] feat: axios added for package.json --- services/http-request/package.json | 49 ++++++++++++++++-------------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/services/http-request/package.json b/services/http-request/package.json index d2bc8622..9e821375 100644 --- a/services/http-request/package.json +++ b/services/http-request/package.json @@ -3,12 +3,12 @@ "version": "0.0.1", "description": "Byndyusoft UI HTTP Service", "keywords": [ - "byndyusoft", - "byndyusoft-ui", - "http", - "request", - "axios", - "fetch" + "byndyusoft", + "byndyusoft-ui", + "http", + "request", + "axios", + "fetch" ], "author": "Byndyusoft Frontend Developer ", "homepage": "https://github.com/Byndyusoft/ui/tree/master/services/http-request#readme", @@ -16,26 +16,29 @@ "main": "dist/index.js", "types": "dist/index.d.ts", "repository": { - "type": "git", - "url": "git+https://github.com/Byndyusoft/ui.git" + "type": "git", + "url": "git+https://github.com/Byndyusoft/ui.git" }, "scripts": { - "build": "rollup --config", - "clean": "rimraf dist", - "test": "jest --config ../../jest.config.js --roots services/http-request/src", - "lint:check": "npm run eslint:check && npm run prettier:check && npm run stylelint:check", - "lint:fix": "npm run eslint:fix && npm run prettier:fix && npm run stylelint:fix", - "eslint:check": "eslint src --config ../../eslint.config.js", - "eslint:fix": "eslint src --config ../../eslint.config.js --fix", - "prettier:check": "prettier --check '**/*.{ts,tsx,css,scss,json}' '!**/dist/**'", - "prettier:fix": "prettier --write '**/*.{ts,tsx,css,scss,json}' '!**/dist/**'", - "stylelint:check": "stylelint '**/*.{css,scss}' --allow-empty-input", - "stylelint:fix": "stylelint '**/*.{css,scss}' --fix --allow-empty-input" - }, + "build": "rollup --config", + "clean": "rimraf dist", + "test": "jest --config ../../jest.config.js --roots services/http-request/src", + "lint:check": "npm run eslint:check && npm run prettier:check && npm run stylelint:check", + "lint:fix": "npm run eslint:fix && npm run prettier:fix && npm run stylelint:fix", + "eslint:check": "eslint src --config ../../eslint.config.js", + "eslint:fix": "eslint src --config ../../eslint.config.js --fix", + "prettier:check": "prettier --check '**/*.{ts,tsx,css,scss,json}' '!**/dist/**'", + "prettier:fix": "prettier --write '**/*.{ts,tsx,css,scss,json}' '!**/dist/**'", + "stylelint:check": "stylelint '**/*.{css,scss}' --allow-empty-input", + "stylelint:fix": "stylelint '**/*.{css,scss}' --fix --allow-empty-input" + }, "bugs": { - "url": "https://github.com/Byndyusoft/ui/issues" + "url": "https://github.com/Byndyusoft/ui/issues" }, "publishConfig": { - "access": "public" + "access": "public" + }, + "dependencies": { + "axios": "^1.9.0" } - } \ No newline at end of file +} From a267aef21702aacc2305cbee3cb693a2c6781f7d Mon Sep 17 00:00:00 2001 From: ancientbag Date: Mon, 12 May 2025 16:01:50 +0500 Subject: [PATCH 08/18] feat: package lock upd --- package-lock.json | 62 +++++++++++++++++++++++++++++++---------------- 1 file changed, 41 insertions(+), 21 deletions(-) diff --git a/package-lock.json b/package-lock.json index a2617d2c..0fb55802 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3784,7 +3784,6 @@ }, "node_modules/asynckit": { "version": "0.4.0", - "dev": true, "license": "MIT" }, "node_modules/atob": { @@ -3817,6 +3816,17 @@ "node": ">=4" } }, + "node_modules/axios": { + "version": "1.9.0", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.9.0.tgz", + "integrity": "sha512-re4CqKTJaURpzbLHtIi6XpDv20/CnpXOtjRY5/CU32L8gU8ek9UIivcfvSWvmKEngmVbrUtPpdDwWDWL7DNHvg==", + "license": "MIT", + "dependencies": { + "follow-redirects": "^1.15.6", + "form-data": "^4.0.0", + "proxy-from-env": "^1.1.0" + } + }, "node_modules/axobject-query": { "version": "2.2.0", "dev": true, @@ -3989,7 +3999,6 @@ }, "node_modules/call-bind-apply-helpers": { "version": "1.0.2", - "dev": true, "license": "MIT", "dependencies": { "es-errors": "^1.3.0", @@ -4268,7 +4277,6 @@ }, "node_modules/combined-stream": { "version": "1.0.8", - "dev": true, "license": "MIT", "dependencies": { "delayed-stream": "~1.0.0" @@ -4783,7 +4791,6 @@ }, "node_modules/delayed-stream": { "version": "1.0.0", - "dev": true, "license": "MIT", "engines": { "node": ">=0.4.0" @@ -4854,7 +4861,6 @@ }, "node_modules/dunder-proto": { "version": "1.0.1", - "dev": true, "license": "MIT", "dependencies": { "call-bind-apply-helpers": "^1.0.1", @@ -4945,7 +4951,6 @@ }, "node_modules/es-define-property": { "version": "1.0.1", - "dev": true, "license": "MIT", "engines": { "node": ">= 0.4" @@ -4953,7 +4958,6 @@ }, "node_modules/es-errors": { "version": "1.3.0", - "dev": true, "license": "MIT", "engines": { "node": ">= 0.4" @@ -4966,7 +4970,6 @@ }, "node_modules/es-object-atoms": { "version": "1.1.1", - "dev": true, "license": "MIT", "dependencies": { "es-errors": "^1.3.0" @@ -4977,7 +4980,6 @@ }, "node_modules/es-set-tostringtag": { "version": "2.1.0", - "dev": true, "license": "MIT", "dependencies": { "es-errors": "^1.3.0", @@ -6131,6 +6133,26 @@ "dev": true, "license": "ISC" }, + "node_modules/follow-redirects": { + "version": "1.15.9", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.9.tgz", + "integrity": "sha512-gew4GsXizNgdoRyqmyfMHyAmXsZDk6mHkSxZFCzW9gwlbtOW44CDtYavM+y+72qD/Vq2l550kMF52DT8fOLJqQ==", + "funding": [ + { + "type": "individual", + "url": "https://github.com/sponsors/RubenVerborgh" + } + ], + "license": "MIT", + "engines": { + "node": ">=4.0" + }, + "peerDependenciesMeta": { + "debug": { + "optional": true + } + } + }, "node_modules/for-each": { "version": "0.3.3", "dev": true, @@ -6167,7 +6189,6 @@ }, "node_modules/form-data": { "version": "4.0.2", - "dev": true, "license": "MIT", "dependencies": { "asynckit": "^0.4.0", @@ -6211,7 +6232,6 @@ }, "node_modules/function-bind": { "version": "1.1.2", - "dev": true, "license": "MIT", "funding": { "url": "https://github.com/sponsors/ljharb" @@ -6265,7 +6285,6 @@ }, "node_modules/get-intrinsic": { "version": "1.3.0", - "dev": true, "license": "MIT", "dependencies": { "call-bind-apply-helpers": "^1.0.2", @@ -6288,7 +6307,6 @@ }, "node_modules/get-proto": { "version": "1.0.1", - "dev": true, "license": "MIT", "dependencies": { "dunder-proto": "^1.0.1", @@ -6730,7 +6748,6 @@ }, "node_modules/gopd": { "version": "1.2.0", - "dev": true, "license": "MIT", "engines": { "node": ">= 0.4" @@ -6814,7 +6831,6 @@ }, "node_modules/has-symbols": { "version": "1.1.0", - "dev": true, "license": "MIT", "engines": { "node": ">= 0.4" @@ -6825,7 +6841,6 @@ }, "node_modules/has-tostringtag": { "version": "1.0.2", - "dev": true, "license": "MIT", "dependencies": { "has-symbols": "^1.0.3" @@ -6839,7 +6854,6 @@ }, "node_modules/hasown": { "version": "2.0.2", - "dev": true, "license": "MIT", "dependencies": { "function-bind": "^1.1.2" @@ -8154,7 +8168,6 @@ }, "node_modules/math-intrinsics": { "version": "1.1.0", - "dev": true, "license": "MIT", "engines": { "node": ">= 0.4" @@ -8215,7 +8228,6 @@ }, "node_modules/mime-db": { "version": "1.52.0", - "dev": true, "license": "MIT", "engines": { "node": ">= 0.6" @@ -8223,7 +8235,6 @@ }, "node_modules/mime-types": { "version": "2.1.35", - "dev": true, "license": "MIT", "dependencies": { "mime-db": "1.52.0" @@ -8933,6 +8944,12 @@ "version": "16.13.1", "license": "MIT" }, + "node_modules/proxy-from-env": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", + "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==", + "license": "MIT" + }, "node_modules/punycode": { "version": "2.3.1", "dev": true, @@ -11158,7 +11175,10 @@ "services/http-request": { "name": "@byndyusoft-ui/http-request", "version": "0.0.1", - "license": "Apache-2.0" + "license": "Apache-2.0", + "dependencies": { + "axios": "^1.9.0" + } }, "styles/keyframes-css": { "name": "@byndyusoft-ui/keyframes-css", From 4cea0eaf39953df18026a547537670a13b18978d Mon Sep 17 00:00:00 2001 From: ancientbag Date: Mon, 12 May 2025 16:02:19 +0500 Subject: [PATCH 09/18] feat: refactor and setHeader method added --- services/http-request/README.md | 29 ++++++++--------- .../src/constants/axiosRestController.ts | 30 +++++++++-------- .../src/constants/fetchRestController.ts | 32 ++++++++++++------- services/http-request/src/httpRequest.ts | 9 ++---- services/http-request/src/restController.ts | 7 ++++ 5 files changed, 60 insertions(+), 47 deletions(-) diff --git a/services/http-request/README.md b/services/http-request/README.md index 2afa69ce..74462226 100644 --- a/services/http-request/README.md +++ b/services/http-request/README.md @@ -31,44 +31,41 @@ There are two classes ready to be used as restControllers: **HttpRestControllerF super(); } - async get(url: string, headers?: Headers): Promise { + get = async (url: string, headers?: Headers): Promise => { return fetch(url, { method: 'GET', headers: { ...headers } }) as Promise; - } + }; - async post(url: string, body: object, headers?: Headers): Promise { + post = async (url: string, body: object, headers?: Headers): Promise => { return fetch(url, { method: 'POST', body: JSON.stringify(body), - headers: { - ...this.headers, - ...headers - } + headers: { ...headers } }) as Promise; - } + }; - async put(url: string, body: object, headers?: Headers): Promise { + patch = async (url: string, body: object, headers?: Headers): Promise => { return fetch(url, { - method: 'PUT', + method: 'PATCH', body: JSON.stringify(body), headers: { ...headers } }) as Promise; - } + }; - async patch(url: string, body: object, headers?: Headers): Promise { + put = async (url: string, body: object, headers?: Headers): Promise => { return fetch(url, { - method: 'PATCH', + method: 'PUT', body: JSON.stringify(body), headers: { ...headers } }) as Promise; - } + }; - async delete(url: string, body: object = {}, headers?: Headers): Promise { + delete = async (url: string, body: object = {}, headers?: Headers): Promise => { return fetch(url, { method: 'DELETE', body: JSON.stringify(body), headers: { ...headers } }) as Promise; - } + }; } export default HttpRestControllerCustom; diff --git a/services/http-request/src/constants/axiosRestController.ts b/services/http-request/src/constants/axiosRestController.ts index 375e4491..dcf2e659 100644 --- a/services/http-request/src/constants/axiosRestController.ts +++ b/services/http-request/src/constants/axiosRestController.ts @@ -19,53 +19,57 @@ export class HttpRestControllerAxios extends HttpRestController { }); } - async get>(url: string, params: object = {}, options: object = {}): Promise { + setHeader = (key: string, value: string | null): void => { + this.axiosInstance.defaults.headers[key] = value; + }; + + get = async >(url: string, params: object = {}, options: object = {}): Promise => { return this.axiosInstance.get(url, { params, ...options }); - } + }; - async post>( + post = async >( url: string, body?: object, params: object = {}, options: object = {} - ): Promise { + ): Promise => { return this.axiosInstance.post(url, body, { params, ...options }); - } + }; - async patch>( + patch = async >( url: string, body?: object, params: object = {}, options: object = {} - ): Promise { + ): Promise => { return this.axiosInstance.patch(url, body, { params, ...options }); - } + }; - async put>( + put = async >( url: string, body?: object, params: object = {}, options: object = {} - ): Promise { + ): Promise => { return this.axiosInstance.put(url, body, { params, ...options }); - } + }; - async delete>(url: string, params: object = {}, options: object = {}): Promise { + delete = async >(url: string, params: object = {}, options: object = {}): Promise => { return this.axiosInstance.delete(url, { params, ...options }); - } + }; } diff --git a/services/http-request/src/constants/fetchRestController.ts b/services/http-request/src/constants/fetchRestController.ts index 96ce0189..1eb3ad47 100644 --- a/services/http-request/src/constants/fetchRestController.ts +++ b/services/http-request/src/constants/fetchRestController.ts @@ -8,11 +8,19 @@ export class HttpRestControllerFetch extends HttpRestController { public headers: Headers; - async get(url: string, headers?: Headers): Promise { + setHeader = (key: string, value: string | null): void => { + if (value) { + this.headers.set(key, value); + } else { + this.headers.delete(key); + } + }; + + get = async (url: string, headers?: Headers): Promise => { return fetch(url, { method: 'GET', headers: { ...this.headers, ...headers } }) as Promise; - } + }; - async post(url: string, body: object, headers?: Headers): Promise { + post = async (url: string, body: object, headers?: Headers): Promise => { return fetch(url, { method: 'POST', body: JSON.stringify(body), @@ -21,29 +29,29 @@ export class HttpRestControllerFetch extends HttpRestController { ...headers } }) as Promise; - } + }; - async put(url: string, body: object, headers?: Headers): Promise { + patch = async (url: string, body: object, headers?: Headers): Promise => { return fetch(url, { - method: 'PUT', + method: 'PATCH', body: JSON.stringify(body), headers: { ...this.headers, ...headers } }) as Promise; - } + }; - async patch(url: string, body: object, headers?: Headers): Promise { + put = async (url: string, body: object, headers?: Headers): Promise => { return fetch(url, { - method: 'PATCH', + method: 'PUT', body: JSON.stringify(body), headers: { ...this.headers, ...headers } }) as Promise; - } + }; - async delete(url: string, body: object = {}, headers?: Headers): Promise { + delete = async (url: string, body: object = {}, headers?: Headers): Promise => { return fetch(url, { method: 'DELETE', body: JSON.stringify(body), headers: { ...this.headers, ...headers } }) as Promise; - } + }; } diff --git a/services/http-request/src/httpRequest.ts b/services/http-request/src/httpRequest.ts index acffc92e..316dd292 100644 --- a/services/http-request/src/httpRequest.ts +++ b/services/http-request/src/httpRequest.ts @@ -1,5 +1,3 @@ -import { HttpRestControllerAxios } from './constants/axiosRestController'; -import { HttpRestControllerFetch } from './constants/fetchRestController'; import { IHttpRequestOptions } from './httpRequest.types'; import HttpRestController from './restController'; @@ -11,6 +9,7 @@ class HttpRequest { public patch: RestController['patch']; public put: RestController['put']; public delete: RestController['delete']; + public setHeader: RestController['setHeader']; constructor(options: IHttpRequestOptions) { if (options.restController) { @@ -22,18 +21,16 @@ class HttpRequest { this.patch = this.restController.patch; this.put = this.restController.put; this.delete = this.restController.delete; + this.setHeader = this.restController.setHeader; } else { this.get = () => Promise.reject('get handler was not specified'); this.post = () => Promise.reject('post handler was not specified'); this.patch = () => Promise.reject('patch handler was not specified'); this.put = () => Promise.reject('put handler was not specified'); this.delete = () => Promise.reject('delete handler was not specified'); + this.setHeader = () => undefined; } } } -const httpRequest = new HttpRequest({ - restController: new HttpRestControllerAxios() -}); - export default HttpRequest; diff --git a/services/http-request/src/restController.ts b/services/http-request/src/restController.ts index 86070ca6..c3d29746 100644 --- a/services/http-request/src/restController.ts +++ b/services/http-request/src/restController.ts @@ -4,6 +4,13 @@ abstract class HttpRestController { abstract patch(...args: any[]): Promise; abstract put(...args: any[]): Promise; abstract delete(...args: any[]): Promise; + public setHeader: (...args: any[]) => void; + + constructor() { + this.setHeader = () => { + console.error('setHeader for HttpRestController is undefined'); + }; + } } export default HttpRestController; From 5d11bb46696280f669f955fc4295777a5a285bd2 Mon Sep 17 00:00:00 2001 From: ancientbag Date: Mon, 12 May 2025 16:08:37 +0500 Subject: [PATCH 10/18] feat: fetch controller json response formatter --- .../src/constants/fetchRestController.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/services/http-request/src/constants/fetchRestController.ts b/services/http-request/src/constants/fetchRestController.ts index 1eb3ad47..ca036ac4 100644 --- a/services/http-request/src/constants/fetchRestController.ts +++ b/services/http-request/src/constants/fetchRestController.ts @@ -17,7 +17,9 @@ export class HttpRestControllerFetch extends HttpRestController { }; get = async (url: string, headers?: Headers): Promise => { - return fetch(url, { method: 'GET', headers: { ...this.headers, ...headers } }) as Promise; + return fetch(url, { method: 'GET', headers: { ...this.headers, ...headers } }).then(r => + r.json() + ) as Promise; }; post = async (url: string, body: object, headers?: Headers): Promise => { @@ -28,7 +30,7 @@ export class HttpRestControllerFetch extends HttpRestController { ...this.headers, ...headers } - }) as Promise; + }).then(r => r.json()) as Promise; }; patch = async (url: string, body: object, headers?: Headers): Promise => { @@ -36,7 +38,7 @@ export class HttpRestControllerFetch extends HttpRestController { method: 'PATCH', body: JSON.stringify(body), headers: { ...this.headers, ...headers } - }) as Promise; + }).then(r => r.json()) as Promise; }; put = async (url: string, body: object, headers?: Headers): Promise => { @@ -44,7 +46,7 @@ export class HttpRestControllerFetch extends HttpRestController { method: 'PUT', body: JSON.stringify(body), headers: { ...this.headers, ...headers } - }) as Promise; + }).then(r => r.json()) as Promise; }; delete = async (url: string, body: object = {}, headers?: Headers): Promise => { @@ -52,6 +54,6 @@ export class HttpRestControllerFetch extends HttpRestController { method: 'DELETE', body: JSON.stringify(body), headers: { ...this.headers, ...headers } - }) as Promise; + }).then(r => r.json()) as Promise; }; } From 57b93f255489b6fe401cef698fdff1ff07b2fca4 Mon Sep 17 00:00:00 2001 From: ancientbag Date: Mon, 12 May 2025 16:49:31 +0500 Subject: [PATCH 11/18] feat: workaround for Headers collection for fetch --- .../src/constants/fetchRestController.ts | 61 ++++++++++++------- 1 file changed, 38 insertions(+), 23 deletions(-) diff --git a/services/http-request/src/constants/fetchRestController.ts b/services/http-request/src/constants/fetchRestController.ts index ca036ac4..fa65eaf3 100644 --- a/services/http-request/src/constants/fetchRestController.ts +++ b/services/http-request/src/constants/fetchRestController.ts @@ -1,59 +1,74 @@ import HttpRestController from '../restController'; export class HttpRestControllerFetch extends HttpRestController { + public headers: Headers = new Headers(); + constructor() { super(); - this.headers = new Headers(); } - public headers: Headers; - setHeader = (key: string, value: string | null): void => { if (value) { - this.headers.set(key, value); + this.headers.append(key, value); } else { this.headers.delete(key); } }; - get = async (url: string, headers?: Headers): Promise => { - return fetch(url, { method: 'GET', headers: { ...this.headers, ...headers } }).then(r => - r.json() - ) as Promise; + private getCurrentHeaders() { + const currentHeaders: Record = {}; + this.headers.forEach((h, v) => { + currentHeaders[h] = v; + }); + + return currentHeaders; + } + + private mergeCurrentHeaders(headers: Headers | undefined) { + const collectedHeaders: Record = this.getCurrentHeaders(); + + if (headers) { + headers.forEach((h, v) => { + collectedHeaders[h] = v; + }); + } + + return collectedHeaders; + } + + get = async (url: string, headers?: Headers): Promise => { + return fetch(url, { method: 'GET', headers: this.mergeCurrentHeaders(headers) }) as Promise; }; - post = async (url: string, body: object, headers?: Headers): Promise => { + post = async (url: string, body: object, headers?: Headers): Promise => { return fetch(url, { method: 'POST', body: JSON.stringify(body), - headers: { - ...this.headers, - ...headers - } - }).then(r => r.json()) as Promise; + headers: this.mergeCurrentHeaders(headers) + }) as Promise; }; - patch = async (url: string, body: object, headers?: Headers): Promise => { + patch = async (url: string, body: object, headers?: Headers): Promise => { return fetch(url, { method: 'PATCH', body: JSON.stringify(body), - headers: { ...this.headers, ...headers } - }).then(r => r.json()) as Promise; + headers: this.mergeCurrentHeaders(headers) + }) as Promise; }; - put = async (url: string, body: object, headers?: Headers): Promise => { + put = async (url: string, body: object, headers?: Headers): Promise => { return fetch(url, { method: 'PUT', body: JSON.stringify(body), - headers: { ...this.headers, ...headers } - }).then(r => r.json()) as Promise; + headers: this.mergeCurrentHeaders(headers) + }) as Promise; }; - delete = async (url: string, body: object = {}, headers?: Headers): Promise => { + delete = async (url: string, body: object = {}, headers?: Headers): Promise => { return fetch(url, { method: 'DELETE', body: JSON.stringify(body), - headers: { ...this.headers, ...headers } - }).then(r => r.json()) as Promise; + headers: this.mergeCurrentHeaders(headers) + }) as Promise; }; } From 6833ccd8d2cdbc9658626224406ab9846fed95a4 Mon Sep 17 00:00:00 2001 From: ancientbag Date: Mon, 12 May 2025 16:53:53 +0500 Subject: [PATCH 12/18] docs: readme upd --- services/http-request/README.md | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/services/http-request/README.md b/services/http-request/README.md index 74462226..8a0d69e3 100644 --- a/services/http-request/README.md +++ b/services/http-request/README.md @@ -20,6 +20,38 @@ There are two classes ready to be used as restControllers: **HttpRestControllerF httpRequestService.get("http://localhost:3000/api/"); ``` +### Example of usage with HttpRestControllerFetch + +```ts + const restController = new HttpRestControllerFetch(); + const HttpService = new HttpRequest({ + restController + }); + + const handleGetProducts = async (): Promise => { + const products = await httpService + .get('http://localhost:3322/products') + .then(async r => (await r.json()) as IProduct[]); + + setProducts(products); + }; +``` + +### Example of usage with HttpRestControllerAxios + +```ts + const restController = new HttpRestControllerAxios(); + const HttpService = new HttpRequest({ + restController + }); + + const handleGetProducts = async (): Promise => { + const products = await httpService.get('http://localhost:3322/products').then(r => r.data); + + setProducts(products); + }; +``` + ### You can define own HttpRestController and pass it like this ```ts From 4b951d937d7f4e73546aae441324a73b8790ff47 Mon Sep 17 00:00:00 2001 From: ancientbag Date: Mon, 12 May 2025 16:58:17 +0500 Subject: [PATCH 13/18] feat: request => service --- services/http-request/README.md | 24 +++++++++---------- .../src/{httpRequest.ts => httpService.ts} | 8 +++---- ...pRequest.types.ts => httpService.types.ts} | 2 +- services/http-request/src/index.ts | 4 ++-- 4 files changed, 19 insertions(+), 19 deletions(-) rename services/http-request/src/{httpRequest.ts => httpService.ts} (85%) rename services/http-request/src/{httpRequest.types.ts => httpService.types.ts} (61%) diff --git a/services/http-request/README.md b/services/http-request/README.md index 8a0d69e3..e7e430ea 100644 --- a/services/http-request/README.md +++ b/services/http-request/README.md @@ -1,30 +1,30 @@ -# `@byndyusoft-ui/http-request` +# `@byndyusoft-ui/http-service` -> Http request service +> Http service service ### Installation ```bash -npm i @byndyusoft-ui/http-request +npm i @byndyusoft-ui/http-service ``` ## Usage -### To start using this service you need to create a new class instance of HttpRequest and provide restController option. +### To start using this service you need to create a new class instance of HttpService and provide restController option. There are two classes ready to be used as restControllers: **HttpRestControllerFetch** and **HttpRestControllerAxios**. For fetch and axios. ```ts const restController = new HttpRestControllerFetch(); - const httpRequest = new HttpRequest({ + const httpService = new HttpService({ restController }); - httpRequestService.get("http://localhost:3000/api/"); + httpService.get("http://localhost:3000/api/"); ``` ### Example of usage with HttpRestControllerFetch ```ts const restController = new HttpRestControllerFetch(); - const HttpService = new HttpRequest({ + const HttpService = new HttpService({ restController }); @@ -41,7 +41,7 @@ There are two classes ready to be used as restControllers: **HttpRestControllerF ```ts const restController = new HttpRestControllerAxios(); - const HttpService = new HttpRequest({ + const HttpService = new HttpService({ restController }); @@ -56,7 +56,7 @@ There are two classes ready to be used as restControllers: **HttpRestControllerF ```ts // myOwnHttpRestController.ts - import { HttpRestController } from '@byndyusoft-ui/http-request'; + import { HttpRestController } from '@byndyusoft-ui/http-service'; class HttpRestControllerCustom extends HttpRestController { constructor() { @@ -104,14 +104,14 @@ There are two classes ready to be used as restControllers: **HttpRestControllerF ``` ```ts - // httpRequest.ts + // httpService.ts import HttpRestControllerCustom from './myOwnHttpRestController.ts' const restController = new HttpRestControllerCustom(); - const httpRequestService = new HttpRequest({ + const httpService = new HttpService({ restController }); - httpRequestService.get("http://localhost:3000/api/"); + httpService.get("http://localhost:3000/api/"); ``` diff --git a/services/http-request/src/httpRequest.ts b/services/http-request/src/httpService.ts similarity index 85% rename from services/http-request/src/httpRequest.ts rename to services/http-request/src/httpService.ts index 316dd292..a68085f4 100644 --- a/services/http-request/src/httpRequest.ts +++ b/services/http-request/src/httpService.ts @@ -1,7 +1,7 @@ -import { IHttpRequestOptions } from './httpRequest.types'; +import { IHttpServiceOptions } from './httpService.types'; import HttpRestController from './restController'; -class HttpRequest { +class HttpService { public restController: RestController | undefined; public get: RestController['get']; @@ -11,7 +11,7 @@ class HttpRequest { public delete: RestController['delete']; public setHeader: RestController['setHeader']; - constructor(options: IHttpRequestOptions) { + constructor(options: IHttpServiceOptions) { if (options.restController) { const restController = options.restController; this.restController = restController; @@ -33,4 +33,4 @@ class HttpRequest { } } -export default HttpRequest; +export default HttpService; diff --git a/services/http-request/src/httpRequest.types.ts b/services/http-request/src/httpService.types.ts similarity index 61% rename from services/http-request/src/httpRequest.types.ts rename to services/http-request/src/httpService.types.ts index c0a66241..0173ddde 100644 --- a/services/http-request/src/httpRequest.types.ts +++ b/services/http-request/src/httpService.types.ts @@ -1,5 +1,5 @@ import HttpRestController from './restController'; -export interface IHttpRequestOptions { +export interface IHttpServiceOptions { restController?: RestController; } diff --git a/services/http-request/src/index.ts b/services/http-request/src/index.ts index a473fba8..5589ab56 100644 --- a/services/http-request/src/index.ts +++ b/services/http-request/src/index.ts @@ -1,6 +1,6 @@ -import HttpRequest from './httpRequest'; +import HttpService from './httpService'; import HttpRestController from './restController'; import { HttpRestControllerAxios } from './constants/axiosRestController'; import { HttpRestControllerFetch } from './constants/fetchRestController'; -export { HttpRequest, HttpRestController, HttpRestControllerAxios, HttpRestControllerFetch }; +export { HttpService, HttpRestController, HttpRestControllerAxios, HttpRestControllerFetch }; From 3654e844a66af9d11e472c9230bd76ba41682c7d Mon Sep 17 00:00:00 2001 From: ancientbag Date: Mon, 12 May 2025 16:59:10 +0500 Subject: [PATCH 14/18] feat: request => service --- services/http-request/package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/services/http-request/package.json b/services/http-request/package.json index 9e821375..183ee5f7 100644 --- a/services/http-request/package.json +++ b/services/http-request/package.json @@ -1,5 +1,5 @@ { - "name": "@byndyusoft-ui/http-request", + "name": "@byndyusoft-ui/http-service", "version": "0.0.1", "description": "Byndyusoft UI HTTP Service", "keywords": [ @@ -11,7 +11,7 @@ "fetch" ], "author": "Byndyusoft Frontend Developer ", - "homepage": "https://github.com/Byndyusoft/ui/tree/master/services/http-request#readme", + "homepage": "https://github.com/Byndyusoft/ui/tree/master/services/http-service#readme", "license": "Apache-2.0", "main": "dist/index.js", "types": "dist/index.d.ts", @@ -22,7 +22,7 @@ "scripts": { "build": "rollup --config", "clean": "rimraf dist", - "test": "jest --config ../../jest.config.js --roots services/http-request/src", + "test": "jest --config ../../jest.config.js --roots services/http-service/src", "lint:check": "npm run eslint:check && npm run prettier:check && npm run stylelint:check", "lint:fix": "npm run eslint:fix && npm run prettier:fix && npm run stylelint:fix", "eslint:check": "eslint src --config ../../eslint.config.js", From e2928135b8a22c35faade5cac36b09179126a2f8 Mon Sep 17 00:00:00 2001 From: ancientbag Date: Mon, 12 May 2025 17:00:41 +0500 Subject: [PATCH 15/18] feat: request => service --- services/http-request/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/http-request/README.md b/services/http-request/README.md index e7e430ea..1341deca 100644 --- a/services/http-request/README.md +++ b/services/http-request/README.md @@ -1,6 +1,6 @@ # `@byndyusoft-ui/http-service` -> Http service service +> Http service ### Installation ```bash From 2f791a39e70a5ed4a8d98a5aa014090fe6605928 Mon Sep 17 00:00:00 2001 From: ancientbag Date: Mon, 12 May 2025 17:01:29 +0500 Subject: [PATCH 16/18] docs: upd --- services/http-request/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/http-request/README.md b/services/http-request/README.md index 1341deca..705cf52e 100644 --- a/services/http-request/README.md +++ b/services/http-request/README.md @@ -14,8 +14,8 @@ There are two classes ready to be used as restControllers: **HttpRestControllerF ```ts const restController = new HttpRestControllerFetch(); const httpService = new HttpService({ - restController -}); + restController + }); httpService.get("http://localhost:3000/api/"); ``` From 21d70a480cfce0ff07bdfb582816f6b9bd08ff10 Mon Sep 17 00:00:00 2001 From: ancientbag Date: Mon, 12 May 2025 17:25:25 +0500 Subject: [PATCH 17/18] feat: folder rename --- services/{http-request => http-service}/.npmignore | 0 services/{http-request => http-service}/README.md | 0 services/{http-request => http-service}/package.json | 0 services/{http-request => http-service}/rollup.config.js | 0 .../src/constants/axiosRestController.ts | 0 .../src/constants/fetchRestController.ts | 0 services/{http-request => http-service}/src/httpService.ts | 0 services/{http-request => http-service}/src/httpService.types.ts | 0 services/{http-request => http-service}/src/index.ts | 0 services/{http-request => http-service}/src/restController.ts | 0 services/{http-request => http-service}/tsconfig.json | 0 11 files changed, 0 insertions(+), 0 deletions(-) rename services/{http-request => http-service}/.npmignore (100%) rename services/{http-request => http-service}/README.md (100%) rename services/{http-request => http-service}/package.json (100%) rename services/{http-request => http-service}/rollup.config.js (100%) rename services/{http-request => http-service}/src/constants/axiosRestController.ts (100%) rename services/{http-request => http-service}/src/constants/fetchRestController.ts (100%) rename services/{http-request => http-service}/src/httpService.ts (100%) rename services/{http-request => http-service}/src/httpService.types.ts (100%) rename services/{http-request => http-service}/src/index.ts (100%) rename services/{http-request => http-service}/src/restController.ts (100%) rename services/{http-request => http-service}/tsconfig.json (100%) diff --git a/services/http-request/.npmignore b/services/http-service/.npmignore similarity index 100% rename from services/http-request/.npmignore rename to services/http-service/.npmignore diff --git a/services/http-request/README.md b/services/http-service/README.md similarity index 100% rename from services/http-request/README.md rename to services/http-service/README.md diff --git a/services/http-request/package.json b/services/http-service/package.json similarity index 100% rename from services/http-request/package.json rename to services/http-service/package.json diff --git a/services/http-request/rollup.config.js b/services/http-service/rollup.config.js similarity index 100% rename from services/http-request/rollup.config.js rename to services/http-service/rollup.config.js diff --git a/services/http-request/src/constants/axiosRestController.ts b/services/http-service/src/constants/axiosRestController.ts similarity index 100% rename from services/http-request/src/constants/axiosRestController.ts rename to services/http-service/src/constants/axiosRestController.ts diff --git a/services/http-request/src/constants/fetchRestController.ts b/services/http-service/src/constants/fetchRestController.ts similarity index 100% rename from services/http-request/src/constants/fetchRestController.ts rename to services/http-service/src/constants/fetchRestController.ts diff --git a/services/http-request/src/httpService.ts b/services/http-service/src/httpService.ts similarity index 100% rename from services/http-request/src/httpService.ts rename to services/http-service/src/httpService.ts diff --git a/services/http-request/src/httpService.types.ts b/services/http-service/src/httpService.types.ts similarity index 100% rename from services/http-request/src/httpService.types.ts rename to services/http-service/src/httpService.types.ts diff --git a/services/http-request/src/index.ts b/services/http-service/src/index.ts similarity index 100% rename from services/http-request/src/index.ts rename to services/http-service/src/index.ts diff --git a/services/http-request/src/restController.ts b/services/http-service/src/restController.ts similarity index 100% rename from services/http-request/src/restController.ts rename to services/http-service/src/restController.ts diff --git a/services/http-request/tsconfig.json b/services/http-service/tsconfig.json similarity index 100% rename from services/http-request/tsconfig.json rename to services/http-service/tsconfig.json From f29ecafcbf5e21e1869ef0647c9ebe68eb437996 Mon Sep 17 00:00:00 2001 From: ancientbag Date: Mon, 12 May 2025 17:35:24 +0500 Subject: [PATCH 18/18] docs: readme upd --- services/http-service/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/http-service/README.md b/services/http-service/README.md index 705cf52e..2dad8a94 100644 --- a/services/http-service/README.md +++ b/services/http-service/README.md @@ -24,7 +24,7 @@ There are two classes ready to be used as restControllers: **HttpRestControllerF ```ts const restController = new HttpRestControllerFetch(); - const HttpService = new HttpService({ + const httpService = new HttpService({ restController }); @@ -41,7 +41,7 @@ There are two classes ready to be used as restControllers: **HttpRestControllerF ```ts const restController = new HttpRestControllerAxios(); - const HttpService = new HttpService({ + const httpService = new HttpService({ restController });