nodecore-kit 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +97 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +54 -0
- package/package.json +66 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
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 src_exports = {};
|
|
32
|
+
__export(src_exports, {
|
|
33
|
+
del: () => del,
|
|
34
|
+
get: () => get,
|
|
35
|
+
makeRequest: () => makeRequest,
|
|
36
|
+
paginate: () => paginate,
|
|
37
|
+
patch: () => patch,
|
|
38
|
+
post: () => post,
|
|
39
|
+
put: () => put
|
|
40
|
+
});
|
|
41
|
+
module.exports = __toCommonJS(src_exports);
|
|
42
|
+
|
|
43
|
+
// src/utils/index.ts
|
|
44
|
+
var paginate = (totalCount, currentPage, perPage) => {
|
|
45
|
+
const previousPage = currentPage - 1;
|
|
46
|
+
return {
|
|
47
|
+
pageCount: Math.ceil(totalCount / perPage),
|
|
48
|
+
offset: currentPage > 1 ? previousPage * perPage : 0
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
// src/http/index.ts
|
|
53
|
+
var import_axios = __toESM(require("axios"), 1);
|
|
54
|
+
var makeRequest = async (options) => {
|
|
55
|
+
const { url, method = "GET", token, headers = {}, ...rest } = options;
|
|
56
|
+
const requestHeaders = {
|
|
57
|
+
"X-Requested-With": "XMLHttpRequest",
|
|
58
|
+
...headers
|
|
59
|
+
};
|
|
60
|
+
if (token) {
|
|
61
|
+
requestHeaders["Authorization"] = token;
|
|
62
|
+
}
|
|
63
|
+
try {
|
|
64
|
+
const response = await (0, import_axios.default)({
|
|
65
|
+
url,
|
|
66
|
+
method,
|
|
67
|
+
headers: requestHeaders,
|
|
68
|
+
...rest
|
|
69
|
+
});
|
|
70
|
+
return response.data;
|
|
71
|
+
} catch (error) {
|
|
72
|
+
if (error.response) {
|
|
73
|
+
const enhancedError = {
|
|
74
|
+
...error.response.data,
|
|
75
|
+
httpStatusCode: error.response.status,
|
|
76
|
+
headers: error.response.headers
|
|
77
|
+
};
|
|
78
|
+
throw enhancedError;
|
|
79
|
+
}
|
|
80
|
+
throw error;
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
var get = (url, options) => makeRequest({ ...options, url, method: "GET" });
|
|
84
|
+
var post = (url, data, options) => makeRequest({ ...options, url, method: "POST", data });
|
|
85
|
+
var put = (url, data, options) => makeRequest({ ...options, url, method: "PUT", data });
|
|
86
|
+
var patch = (url, data, options) => makeRequest({ ...options, url, method: "PATCH", data });
|
|
87
|
+
var del = (url, options) => makeRequest({ ...options, url, method: "DELETE" });
|
|
88
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
89
|
+
0 && (module.exports = {
|
|
90
|
+
del,
|
|
91
|
+
get,
|
|
92
|
+
makeRequest,
|
|
93
|
+
paginate,
|
|
94
|
+
patch,
|
|
95
|
+
post,
|
|
96
|
+
put
|
|
97
|
+
});
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { AxiosRequestConfig, Method } from 'axios';
|
|
2
|
+
|
|
3
|
+
declare const paginate: (totalCount: number, currentPage: number, perPage: number) => {
|
|
4
|
+
pageCount: number;
|
|
5
|
+
offset: number;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
interface RequestOptions extends Omit<AxiosRequestConfig, 'method' | 'url'> {
|
|
9
|
+
method?: Method;
|
|
10
|
+
url: string;
|
|
11
|
+
token?: string;
|
|
12
|
+
headers?: Record<string, string | number | boolean>;
|
|
13
|
+
}
|
|
14
|
+
declare const makeRequest: <T = any>(options: RequestOptions) => Promise<T>;
|
|
15
|
+
declare const get: <T = any>(url: string, options?: Omit<RequestOptions, "url" | "method">) => Promise<T>;
|
|
16
|
+
declare const post: <T = any>(url: string, data?: any, options?: Omit<RequestOptions, "url" | "method">) => Promise<T>;
|
|
17
|
+
declare const put: <T = any>(url: string, data?: any, options?: Omit<RequestOptions, "url" | "method">) => Promise<T>;
|
|
18
|
+
declare const patch: <T = any>(url: string, data?: any, options?: Omit<RequestOptions, "url" | "method">) => Promise<T>;
|
|
19
|
+
declare const del: <T = any>(url: string, options?: Omit<RequestOptions, "url" | "method">) => Promise<T>;
|
|
20
|
+
|
|
21
|
+
export { RequestOptions, del, get, makeRequest, paginate, patch, post, put };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// src/utils/index.ts
|
|
2
|
+
var paginate = (totalCount, currentPage, perPage) => {
|
|
3
|
+
const previousPage = currentPage - 1;
|
|
4
|
+
return {
|
|
5
|
+
pageCount: Math.ceil(totalCount / perPage),
|
|
6
|
+
offset: currentPage > 1 ? previousPage * perPage : 0
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
// src/http/index.ts
|
|
11
|
+
import axios from "axios";
|
|
12
|
+
var makeRequest = async (options) => {
|
|
13
|
+
const { url, method = "GET", token, headers = {}, ...rest } = options;
|
|
14
|
+
const requestHeaders = {
|
|
15
|
+
"X-Requested-With": "XMLHttpRequest",
|
|
16
|
+
...headers
|
|
17
|
+
};
|
|
18
|
+
if (token) {
|
|
19
|
+
requestHeaders["Authorization"] = token;
|
|
20
|
+
}
|
|
21
|
+
try {
|
|
22
|
+
const response = await axios({
|
|
23
|
+
url,
|
|
24
|
+
method,
|
|
25
|
+
headers: requestHeaders,
|
|
26
|
+
...rest
|
|
27
|
+
});
|
|
28
|
+
return response.data;
|
|
29
|
+
} catch (error) {
|
|
30
|
+
if (error.response) {
|
|
31
|
+
const enhancedError = {
|
|
32
|
+
...error.response.data,
|
|
33
|
+
httpStatusCode: error.response.status,
|
|
34
|
+
headers: error.response.headers
|
|
35
|
+
};
|
|
36
|
+
throw enhancedError;
|
|
37
|
+
}
|
|
38
|
+
throw error;
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
var get = (url, options) => makeRequest({ ...options, url, method: "GET" });
|
|
42
|
+
var post = (url, data, options) => makeRequest({ ...options, url, method: "POST", data });
|
|
43
|
+
var put = (url, data, options) => makeRequest({ ...options, url, method: "PUT", data });
|
|
44
|
+
var patch = (url, data, options) => makeRequest({ ...options, url, method: "PATCH", data });
|
|
45
|
+
var del = (url, options) => makeRequest({ ...options, url, method: "DELETE" });
|
|
46
|
+
export {
|
|
47
|
+
del,
|
|
48
|
+
get,
|
|
49
|
+
makeRequest,
|
|
50
|
+
paginate,
|
|
51
|
+
patch,
|
|
52
|
+
post,
|
|
53
|
+
put
|
|
54
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "nodecore-kit",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Backend foundation SDK for Node.js services",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"require": "./dist/index.cjs",
|
|
14
|
+
"default": "./dist/index.js"
|
|
15
|
+
},
|
|
16
|
+
"./package.json": "./package.json"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"sdk",
|
|
20
|
+
"backend",
|
|
21
|
+
"utilities",
|
|
22
|
+
"http",
|
|
23
|
+
"redis",
|
|
24
|
+
"aws"
|
|
25
|
+
],
|
|
26
|
+
"publishConfig": {
|
|
27
|
+
"access": "public"
|
|
28
|
+
},
|
|
29
|
+
"files": [
|
|
30
|
+
"dist"
|
|
31
|
+
],
|
|
32
|
+
"sideEffects": false,
|
|
33
|
+
"engines": {
|
|
34
|
+
"node": ">=18"
|
|
35
|
+
},
|
|
36
|
+
"scripts": {
|
|
37
|
+
"build": "tsup src/index.ts --format cjs,esm --dts",
|
|
38
|
+
"dev": "tsup src/index.ts --watch --format cjs,esm --dts",
|
|
39
|
+
"test": "vitest",
|
|
40
|
+
"lint": "eslint .",
|
|
41
|
+
"prepublishOnly": "npm run build"
|
|
42
|
+
},
|
|
43
|
+
"repository": {
|
|
44
|
+
"type": "git",
|
|
45
|
+
"url": "git+https://github.com/Rockhillz/nodeCore-kit.git"
|
|
46
|
+
},
|
|
47
|
+
"author": "Rockhillz",
|
|
48
|
+
"license": "MIT",
|
|
49
|
+
"bugs": {
|
|
50
|
+
"url": "https://github.com/Rockhillz/nodeCore-kit/issues"
|
|
51
|
+
},
|
|
52
|
+
"homepage": "https://github.com/Rockhillz/nodeCore-kit#readme",
|
|
53
|
+
"devDependencies": {
|
|
54
|
+
"@types/node": "^25.2.2",
|
|
55
|
+
"eslint": "^10.0.0",
|
|
56
|
+
"prettier": "^3.8.1",
|
|
57
|
+
"tsup": "^6.7.0",
|
|
58
|
+
"typescript": "^5.9.3",
|
|
59
|
+
"vitest": "^0.34.6"
|
|
60
|
+
},
|
|
61
|
+
"dependencies": {
|
|
62
|
+
"axios": "^1.13.5",
|
|
63
|
+
"ioredis": "^5.9.2",
|
|
64
|
+
"uuid": "^13.0.0"
|
|
65
|
+
}
|
|
66
|
+
}
|