hia-frontend-api 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,32 @@
1
+ interface HttpClientConfig {
2
+ baseURL: string;
3
+ timeout?: number;
4
+ headers?: Record<string, string>;
5
+ }
6
+ interface RequestConfig {
7
+ headers?: Record<string, string>;
8
+ params?: Record<string, unknown>;
9
+ signal?: AbortSignal;
10
+ }
11
+ interface HttpClient {
12
+ get<T>(url: string, config?: RequestConfig): Promise<T>;
13
+ post<T>(url: string, data?: unknown, config?: RequestConfig): Promise<T>;
14
+ put<T>(url: string, data?: unknown, config?: RequestConfig): Promise<T>;
15
+ patch<T>(url: string, data?: unknown, config?: RequestConfig): Promise<T>;
16
+ delete<T>(url: string, config?: RequestConfig): Promise<T>;
17
+ }
18
+
19
+ declare class AxiosHttpClient implements HttpClient {
20
+ private instance;
21
+ constructor(config: HttpClientConfig);
22
+ private setupInterceptors;
23
+ private toAxiosConfig;
24
+ get<T>(url: string, config?: RequestConfig): Promise<T>;
25
+ post<T>(url: string, data?: unknown, config?: RequestConfig): Promise<T>;
26
+ put<T>(url: string, data?: unknown, config?: RequestConfig): Promise<T>;
27
+ patch<T>(url: string, data?: unknown, config?: RequestConfig): Promise<T>;
28
+ delete<T>(url: string, config?: RequestConfig): Promise<T>;
29
+ }
30
+ declare function createHttpClient(config: HttpClientConfig): HttpClient;
31
+
32
+ export { AxiosHttpClient, type HttpClient, type HttpClientConfig, type RequestConfig, createHttpClient };
@@ -0,0 +1,32 @@
1
+ interface HttpClientConfig {
2
+ baseURL: string;
3
+ timeout?: number;
4
+ headers?: Record<string, string>;
5
+ }
6
+ interface RequestConfig {
7
+ headers?: Record<string, string>;
8
+ params?: Record<string, unknown>;
9
+ signal?: AbortSignal;
10
+ }
11
+ interface HttpClient {
12
+ get<T>(url: string, config?: RequestConfig): Promise<T>;
13
+ post<T>(url: string, data?: unknown, config?: RequestConfig): Promise<T>;
14
+ put<T>(url: string, data?: unknown, config?: RequestConfig): Promise<T>;
15
+ patch<T>(url: string, data?: unknown, config?: RequestConfig): Promise<T>;
16
+ delete<T>(url: string, config?: RequestConfig): Promise<T>;
17
+ }
18
+
19
+ declare class AxiosHttpClient implements HttpClient {
20
+ private instance;
21
+ constructor(config: HttpClientConfig);
22
+ private setupInterceptors;
23
+ private toAxiosConfig;
24
+ get<T>(url: string, config?: RequestConfig): Promise<T>;
25
+ post<T>(url: string, data?: unknown, config?: RequestConfig): Promise<T>;
26
+ put<T>(url: string, data?: unknown, config?: RequestConfig): Promise<T>;
27
+ patch<T>(url: string, data?: unknown, config?: RequestConfig): Promise<T>;
28
+ delete<T>(url: string, config?: RequestConfig): Promise<T>;
29
+ }
30
+ declare function createHttpClient(config: HttpClientConfig): HttpClient;
31
+
32
+ export { AxiosHttpClient, type HttpClient, type HttpClientConfig, type RequestConfig, createHttpClient };
package/dist/index.js ADDED
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ AxiosHttpClient: () => AxiosHttpClient,
34
+ createHttpClient: () => createHttpClient
35
+ });
36
+ module.exports = __toCommonJS(index_exports);
37
+
38
+ // src/http-client/http-client-axios.ts
39
+ var import_axios = __toESM(require("axios"));
40
+ var AxiosHttpClient = class {
41
+ instance;
42
+ constructor(config) {
43
+ this.instance = import_axios.default.create({
44
+ baseURL: config.baseURL,
45
+ timeout: config.timeout ?? 1e4,
46
+ headers: {
47
+ "Content-Type": "application/json",
48
+ ...config.headers
49
+ }
50
+ });
51
+ this.setupInterceptors();
52
+ }
53
+ setupInterceptors() {
54
+ this.instance.interceptors.request.use(
55
+ (config) => config,
56
+ (error) => Promise.reject(error)
57
+ );
58
+ this.instance.interceptors.response.use(
59
+ (response) => response.data,
60
+ (error) => Promise.reject(error)
61
+ );
62
+ }
63
+ toAxiosConfig(config) {
64
+ return {
65
+ headers: config?.headers,
66
+ params: config?.params,
67
+ signal: config?.signal
68
+ };
69
+ }
70
+ get(url, config) {
71
+ return this.instance.get(url, this.toAxiosConfig(config));
72
+ }
73
+ post(url, data, config) {
74
+ return this.instance.post(url, data, this.toAxiosConfig(config));
75
+ }
76
+ put(url, data, config) {
77
+ return this.instance.put(url, data, this.toAxiosConfig(config));
78
+ }
79
+ patch(url, data, config) {
80
+ return this.instance.patch(url, data, this.toAxiosConfig(config));
81
+ }
82
+ delete(url, config) {
83
+ return this.instance.delete(url, this.toAxiosConfig(config));
84
+ }
85
+ };
86
+ function createHttpClient(config) {
87
+ return new AxiosHttpClient(config);
88
+ }
89
+ // Annotate the CommonJS export names for ESM import in node:
90
+ 0 && (module.exports = {
91
+ AxiosHttpClient,
92
+ createHttpClient
93
+ });
94
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/http-client/http-client-axios.ts"],"sourcesContent":["export * from './http-client';\n","import axios, { AxiosInstance, AxiosRequestConfig } from 'axios';\n\nimport type { HttpClient, HttpClientConfig, RequestConfig } from './http-client.types';\n\nexport class AxiosHttpClient implements HttpClient {\n private instance: AxiosInstance;\n\n constructor(config: HttpClientConfig) {\n this.instance = axios.create({\n baseURL: config.baseURL,\n timeout: config.timeout ?? 10_000,\n headers: {\n 'Content-Type': 'application/json',\n ...config.headers\n }\n });\n\n this.setupInterceptors();\n }\n\n private setupInterceptors() {\n this.instance.interceptors.request.use(\n (config) => config,\n (error) => Promise.reject(error)\n );\n\n this.instance.interceptors.response.use(\n (response) => response.data,\n (error) => Promise.reject(error)\n );\n }\n\n private toAxiosConfig(config?: RequestConfig): AxiosRequestConfig {\n return {\n headers: config?.headers,\n params: config?.params,\n signal: config?.signal\n };\n }\n\n get<T>(url: string, config?: RequestConfig): Promise<T> {\n return this.instance.get<T, T>(url, this.toAxiosConfig(config));\n }\n\n post<T>(url: string, data?: unknown, config?: RequestConfig): Promise<T> {\n return this.instance.post<T, T>(url, data, this.toAxiosConfig(config));\n }\n\n put<T>(url: string, data?: unknown, config?: RequestConfig): Promise<T> {\n return this.instance.put<T, T>(url, data, this.toAxiosConfig(config));\n }\n\n patch<T>(url: string, data?: unknown, config?: RequestConfig): Promise<T> {\n return this.instance.patch<T, T>(url, data, this.toAxiosConfig(config));\n }\n\n delete<T>(url: string, config?: RequestConfig): Promise<T> {\n return this.instance.delete<T, T>(url, this.toAxiosConfig(config));\n }\n}\n\nexport function createHttpClient(config: HttpClientConfig): HttpClient {\n return new AxiosHttpClient(config);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAAyD;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nE;AACF;AAEO,SAAS,iBAAiB,QAAsC;AACrE,SAAO,IAAI,gBAAgB,MAAM;AACnC;","names":["axios"]}
package/dist/index.mjs ADDED
@@ -0,0 +1,56 @@
1
+ // src/http-client/http-client-axios.ts
2
+ import axios from "axios";
3
+ var AxiosHttpClient = class {
4
+ instance;
5
+ constructor(config) {
6
+ this.instance = axios.create({
7
+ baseURL: config.baseURL,
8
+ timeout: config.timeout ?? 1e4,
9
+ headers: {
10
+ "Content-Type": "application/json",
11
+ ...config.headers
12
+ }
13
+ });
14
+ this.setupInterceptors();
15
+ }
16
+ setupInterceptors() {
17
+ this.instance.interceptors.request.use(
18
+ (config) => config,
19
+ (error) => Promise.reject(error)
20
+ );
21
+ this.instance.interceptors.response.use(
22
+ (response) => response.data,
23
+ (error) => Promise.reject(error)
24
+ );
25
+ }
26
+ toAxiosConfig(config) {
27
+ return {
28
+ headers: config?.headers,
29
+ params: config?.params,
30
+ signal: config?.signal
31
+ };
32
+ }
33
+ get(url, config) {
34
+ return this.instance.get(url, this.toAxiosConfig(config));
35
+ }
36
+ post(url, data, config) {
37
+ return this.instance.post(url, data, this.toAxiosConfig(config));
38
+ }
39
+ put(url, data, config) {
40
+ return this.instance.put(url, data, this.toAxiosConfig(config));
41
+ }
42
+ patch(url, data, config) {
43
+ return this.instance.patch(url, data, this.toAxiosConfig(config));
44
+ }
45
+ delete(url, config) {
46
+ return this.instance.delete(url, this.toAxiosConfig(config));
47
+ }
48
+ };
49
+ function createHttpClient(config) {
50
+ return new AxiosHttpClient(config);
51
+ }
52
+ export {
53
+ AxiosHttpClient,
54
+ createHttpClient
55
+ };
56
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/http-client/http-client-axios.ts"],"sourcesContent":["import axios, { AxiosInstance, AxiosRequestConfig } from 'axios';\n\nimport type { HttpClient, HttpClientConfig, RequestConfig } from './http-client.types';\n\nexport class AxiosHttpClient implements HttpClient {\n private instance: AxiosInstance;\n\n constructor(config: HttpClientConfig) {\n this.instance = axios.create({\n baseURL: config.baseURL,\n timeout: config.timeout ?? 10_000,\n headers: {\n 'Content-Type': 'application/json',\n ...config.headers\n }\n });\n\n this.setupInterceptors();\n }\n\n private setupInterceptors() {\n this.instance.interceptors.request.use(\n (config) => config,\n (error) => Promise.reject(error)\n );\n\n this.instance.interceptors.response.use(\n (response) => response.data,\n (error) => Promise.reject(error)\n );\n }\n\n private toAxiosConfig(config?: RequestConfig): AxiosRequestConfig {\n return {\n headers: config?.headers,\n params: config?.params,\n signal: config?.signal\n };\n }\n\n get<T>(url: string, config?: RequestConfig): Promise<T> {\n return this.instance.get<T, T>(url, this.toAxiosConfig(config));\n }\n\n post<T>(url: string, data?: unknown, config?: RequestConfig): Promise<T> {\n return this.instance.post<T, T>(url, data, this.toAxiosConfig(config));\n }\n\n put<T>(url: string, data?: unknown, config?: RequestConfig): Promise<T> {\n return this.instance.put<T, T>(url, data, this.toAxiosConfig(config));\n }\n\n patch<T>(url: string, data?: unknown, config?: RequestConfig): Promise<T> {\n return this.instance.patch<T, T>(url, data, this.toAxiosConfig(config));\n }\n\n delete<T>(url: string, config?: RequestConfig): Promise<T> {\n return this.instance.delete<T, T>(url, this.toAxiosConfig(config));\n }\n}\n\nexport function createHttpClient(config: HttpClientConfig): HttpClient {\n return new AxiosHttpClient(config);\n}\n"],"mappings":";AAAA,OAAO,WAAkD;AAIlD,IAAM,kBAAN,MAA4C;AAAA,EACzC;AAAA,EAER,YAAY,QAA0B;AACpC,SAAK,WAAW,MAAM,OAAO;AAAA,MAC3B,SAAS,OAAO;AAAA,MAChB,SAAS,OAAO,WAAW;AAAA,MAC3B,SAAS;AAAA,QACP,gBAAgB;AAAA,QAChB,GAAG,OAAO;AAAA,MACZ;AAAA,IACF,CAAC;AAED,SAAK,kBAAkB;AAAA,EACzB;AAAA,EAEQ,oBAAoB;AAC1B,SAAK,SAAS,aAAa,QAAQ;AAAA,MACjC,CAAC,WAAW;AAAA,MACZ,CAAC,UAAU,QAAQ,OAAO,KAAK;AAAA,IACjC;AAEA,SAAK,SAAS,aAAa,SAAS;AAAA,MAClC,CAAC,aAAa,SAAS;AAAA,MACvB,CAAC,UAAU,QAAQ,OAAO,KAAK;AAAA,IACjC;AAAA,EACF;AAAA,EAEQ,cAAc,QAA4C;AAChE,WAAO;AAAA,MACL,SAAS,QAAQ;AAAA,MACjB,QAAQ,QAAQ;AAAA,MAChB,QAAQ,QAAQ;AAAA,IAClB;AAAA,EACF;AAAA,EAEA,IAAO,KAAa,QAAoC;AACtD,WAAO,KAAK,SAAS,IAAU,KAAK,KAAK,cAAc,MAAM,CAAC;AAAA,EAChE;AAAA,EAEA,KAAQ,KAAa,MAAgB,QAAoC;AACvE,WAAO,KAAK,SAAS,KAAW,KAAK,MAAM,KAAK,cAAc,MAAM,CAAC;AAAA,EACvE;AAAA,EAEA,IAAO,KAAa,MAAgB,QAAoC;AACtE,WAAO,KAAK,SAAS,IAAU,KAAK,MAAM,KAAK,cAAc,MAAM,CAAC;AAAA,EACtE;AAAA,EAEA,MAAS,KAAa,MAAgB,QAAoC;AACxE,WAAO,KAAK,SAAS,MAAY,KAAK,MAAM,KAAK,cAAc,MAAM,CAAC;AAAA,EACxE;AAAA,EAEA,OAAU,KAAa,QAAoC;AACzD,WAAO,KAAK,SAAS,OAAa,KAAK,KAAK,cAAc,MAAM,CAAC;AAAA,EACnE;AACF;AAEO,SAAS,iBAAiB,QAAsC;AACrE,SAAO,IAAI,gBAAgB,MAAM;AACnC;","names":[]}
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "hia-frontend-api",
3
+ "version": "0.0.1",
4
+ "description": "HIA 공통 HTTP 클라이언트 및 API 유틸리티",
5
+ "main": "./dist/index.js",
6
+ "module": "./dist/index.mjs",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.mjs",
12
+ "require": "./dist/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "dependencies": {
19
+ "axios": "^1.7.2"
20
+ },
21
+ "devDependencies": {
22
+ "tsup": "^8.0.0",
23
+ "typescript": "^5.8.3",
24
+ "hia-frontend-typescript-config": "0.0.1"
25
+ },
26
+ "publishConfig": {
27
+ "access": "public"
28
+ },
29
+ "scripts": {
30
+ "build": "tsup",
31
+ "dev": "tsup --watch",
32
+ "lint": "eslint src --ext .ts",
33
+ "clean": "rm -rf dist",
34
+ "check-types": "tsc --noEmit"
35
+ }
36
+ }