mielk-api 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Config.d.ts +1 -0
- package/dist/Config.js +1 -0
- package/dist/back/ApiResponse.d.ts +1 -0
- package/dist/back/ApiResponse.js +30 -0
- package/dist/back/ApiStatus.d.ts +2 -0
- package/dist/back/ApiStatus.js +11 -0
- package/dist/back/index.d.ts +6 -0
- package/dist/back/index.js +4 -0
- package/dist/back/pgErrorCodes.d.ts +4 -0
- package/dist/back/pgErrorCodes.js +4 -0
- package/dist/back/types.d.ts +5 -0
- package/dist/back/types.js +1 -0
- package/dist/front/index.d.ts +4 -0
- package/dist/front/index.js +1 -0
- package/dist/front/types.d.ts +9 -0
- package/dist/front/types.js +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/internal/messaging/Msg.d.ts +10 -0
- package/dist/internal/messaging/Msg.js +5 -0
- package/dist/internal/messaging/apiStatusTags.d.ts +8 -0
- package/dist/internal/messaging/apiStatusTags.js +10 -0
- package/dist/utils/Post.d.ts +1 -0
- package/dist/utils/Post.js +21 -0
- package/package.json +61 -0
package/dist/Config.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const ApiUrl = "http://localhost:4000";
|
package/dist/Config.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const ApiUrl = 'http://localhost:4000';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// import { ApiSuccess, ApiError } from '../front/types.js';
|
|
2
|
+
export {};
|
|
3
|
+
// export function ok<T>(res: Response, data: T): void {
|
|
4
|
+
// const apiResponse: ApiSuccess<T> = {
|
|
5
|
+
// success: true,
|
|
6
|
+
// data,
|
|
7
|
+
// }
|
|
8
|
+
// res.status(200).json(apiResponse);
|
|
9
|
+
// }
|
|
10
|
+
// export function notFound(res: Response, message = 'Resource not found'): void {
|
|
11
|
+
// const apiError: ApiError = {
|
|
12
|
+
// success: false,
|
|
13
|
+
// error: message,
|
|
14
|
+
// };
|
|
15
|
+
// res.status(404).json(apiError);
|
|
16
|
+
// }
|
|
17
|
+
// export function badRequest(res: Response, message: string): void {
|
|
18
|
+
// const apiError: ApiError = {
|
|
19
|
+
// success: false,
|
|
20
|
+
// error: message,
|
|
21
|
+
// };
|
|
22
|
+
// res.status(400).json(apiError);
|
|
23
|
+
// }
|
|
24
|
+
// export function serverError(res: Response, err: unknown): void {
|
|
25
|
+
// const apiError: ApiError = {
|
|
26
|
+
// success: false,
|
|
27
|
+
// error: `Internal server error [details: ${err}]`,
|
|
28
|
+
// };
|
|
29
|
+
// res.status(500).json(apiError);
|
|
30
|
+
// }
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { msgTag } from "mielk-fn/tags";
|
|
2
|
+
import { Msg } from "../internal/messaging/Msg.js";
|
|
3
|
+
const createApiStatus = (success, code, defaultMessageTag) => ({ success, code, defaultMessageTag });
|
|
4
|
+
export const API_STATUS_CODES = {
|
|
5
|
+
OK: createApiStatus(true, 200, msgTag(Msg.API_STATUS.OK)),
|
|
6
|
+
CREATED: createApiStatus(true, 200, msgTag(Msg.API_STATUS.CREATED)),
|
|
7
|
+
BAD_REQUEST: createApiStatus(false, 400, msgTag(Msg.API_STATUS.BAD_REQUEST)),
|
|
8
|
+
NOT_FOUND: createApiStatus(false, 404, msgTag(Msg.API_STATUS.NOT_FOUND)),
|
|
9
|
+
CONFLICT: createApiStatus(false, 409, msgTag(Msg.API_STATUS.CONFLICT)),
|
|
10
|
+
SERVER_ERROR: createApiStatus(false, 500, msgTag(Msg.API_STATUS.SERVER_ERROR)),
|
|
11
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare const Msg: {
|
|
2
|
+
API_STATUS: {
|
|
3
|
+
OK: import("mielk-fn/tags").Tag;
|
|
4
|
+
CREATED: import("mielk-fn/tags").Tag;
|
|
5
|
+
BAD_REQUEST: import("mielk-fn/tags").Tag;
|
|
6
|
+
NOT_FOUND: import("mielk-fn/tags").Tag;
|
|
7
|
+
CONFLICT: import("mielk-fn/tags").Tag;
|
|
8
|
+
SERVER_ERROR: import("mielk-fn/tags").Tag;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare const ApiStatusMessageTags: (parentPrefix: string) => {
|
|
2
|
+
OK: import("mielk-fn/tags").Tag;
|
|
3
|
+
CREATED: import("mielk-fn/tags").Tag;
|
|
4
|
+
BAD_REQUEST: import("mielk-fn/tags").Tag;
|
|
5
|
+
NOT_FOUND: import("mielk-fn/tags").Tag;
|
|
6
|
+
CONFLICT: import("mielk-fn/tags").Tag;
|
|
7
|
+
SERVER_ERROR: import("mielk-fn/tags").Tag;
|
|
8
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { createTag } from 'mielk-fn/tags';
|
|
2
|
+
const prefix = 'ApiStatus';
|
|
3
|
+
export const ApiStatusMessageTags = (parentPrefix) => ({
|
|
4
|
+
OK: createTag(parentPrefix, prefix, 'ok'),
|
|
5
|
+
CREATED: createTag(parentPrefix, prefix, 'created'),
|
|
6
|
+
BAD_REQUEST: createTag(parentPrefix, prefix, 'badRequest'),
|
|
7
|
+
NOT_FOUND: createTag(parentPrefix, prefix, 'notFound'),
|
|
8
|
+
CONFLICT: createTag(parentPrefix, prefix, 'conflict'),
|
|
9
|
+
SERVER_ERROR: createTag(parentPrefix, prefix, 'serverError'),
|
|
10
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getPostResponse(url: string, params: Record<string, any>): Promise<Response>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
export function getPostResponse(url, params) {
|
|
12
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
13
|
+
return yield fetch(url, {
|
|
14
|
+
method: 'POST',
|
|
15
|
+
headers: {
|
|
16
|
+
'Content-Type': 'application/json',
|
|
17
|
+
},
|
|
18
|
+
body: JSON.stringify(params),
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "mielk-api",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"keywords": [],
|
|
5
|
+
"author": "mielk",
|
|
6
|
+
"description": "Wrapper for API operations",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"import": "./dist/index.js",
|
|
14
|
+
"default": "./dist/index.js"
|
|
15
|
+
},
|
|
16
|
+
"./back": {
|
|
17
|
+
"types": "./dist/back/index.d.ts",
|
|
18
|
+
"import": "./dist/back/index.js",
|
|
19
|
+
"default": "./dist/back/index.js"
|
|
20
|
+
},
|
|
21
|
+
"./front": {
|
|
22
|
+
"types": "./dist/front/index.d.ts",
|
|
23
|
+
"import": "./dist/front/index.js",
|
|
24
|
+
"default": "./dist/front/index.js"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"test": "jest --detectOpenHandles",
|
|
29
|
+
"build": "tsc",
|
|
30
|
+
"prepublishOnly": "npm test && npm run build",
|
|
31
|
+
"dev": "tsc -w",
|
|
32
|
+
"release": "standard-version"
|
|
33
|
+
},
|
|
34
|
+
"license": "MIT",
|
|
35
|
+
"repository": {
|
|
36
|
+
"type": "git",
|
|
37
|
+
"url": "git+https://github.com/mielk/mielk-api-client.git"
|
|
38
|
+
},
|
|
39
|
+
"homepage": "https://mielk.github.io/mielk-api-client/",
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@babel/cli": "^7.25.7",
|
|
42
|
+
"@babel/core": "^7.25.8",
|
|
43
|
+
"@babel/node": "^7.25.7",
|
|
44
|
+
"@babel/preset-env": "^7.25.8",
|
|
45
|
+
"@types/jest": "^30.0.0",
|
|
46
|
+
"@types/node": "^22.7.5",
|
|
47
|
+
"babel-jest": "^29.7.0",
|
|
48
|
+
"jest": "^30.3.0",
|
|
49
|
+
"jest-html-reporters": "^3.1.7",
|
|
50
|
+
"standard-version": "^9.5.0",
|
|
51
|
+
"ts-jest": "^29.4.6",
|
|
52
|
+
"tslib": "^2.3.0",
|
|
53
|
+
"typescript": "^5.9.2"
|
|
54
|
+
},
|
|
55
|
+
"files": [
|
|
56
|
+
"dist"
|
|
57
|
+
],
|
|
58
|
+
"dependencies": {
|
|
59
|
+
"mielk-fn": "^1.1.0"
|
|
60
|
+
}
|
|
61
|
+
}
|