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.
@@ -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,2 @@
1
+ import { ApiStatus } from "./types.js";
2
+ export declare const API_STATUS_CODES: Record<string, ApiStatus>;
@@ -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,6 @@
1
+ import type { ApiStatus } from './types.js';
2
+ import { PG_ERROR_CODES } from './pgErrorCodes.js';
3
+ import { API_STATUS_CODES } from './ApiStatus.js';
4
+ export type { ApiStatus };
5
+ export { PG_ERROR_CODES };
6
+ export { API_STATUS_CODES };
@@ -0,0 +1,4 @@
1
+ import { PG_ERROR_CODES } from './pgErrorCodes.js';
2
+ import { API_STATUS_CODES } from './ApiStatus.js';
3
+ export { PG_ERROR_CODES };
4
+ export { API_STATUS_CODES };
@@ -0,0 +1,4 @@
1
+ export declare const PG_ERROR_CODES: {
2
+ UNIQUE_VIOLATION: string;
3
+ FOREIGN_KEY_VIOLATION: string;
4
+ };
@@ -0,0 +1,4 @@
1
+ export const PG_ERROR_CODES = {
2
+ UNIQUE_VIOLATION: '23505',
3
+ FOREIGN_KEY_VIOLATION: '23503',
4
+ };
@@ -0,0 +1,5 @@
1
+ export type ApiStatus = {
2
+ success: boolean;
3
+ code: number;
4
+ defaultMessageTag: string;
5
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,4 @@
1
+ import { ApiSuccess, ApiError } from './types.js';
2
+ import type { ApiResponse } from './types.js';
3
+ export { ApiError, ApiSuccess };
4
+ export type { ApiResponse };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,9 @@
1
+ export interface ApiSuccess<T> {
2
+ success: true;
3
+ data: T;
4
+ }
5
+ export interface ApiError {
6
+ success: false;
7
+ error: string;
8
+ }
9
+ export type ApiResponse<T> = ApiSuccess<T> | ApiError;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ export * as back from './back/index.js';
2
+ export * as front from './front/index.js';
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export * as back from './back/index.js';
2
+ export * as front from './front/index.js';
@@ -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,5 @@
1
+ import { ApiStatusMessageTags } from "./apiStatusTags.js";
2
+ const prefix = 'Api';
3
+ export const Msg = {
4
+ API_STATUS: ApiStatusMessageTags(prefix),
5
+ };
@@ -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
+ }