@agranom/boykom-common 1.0.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/README.md +46 -0
- package/dist/constants/api.constants.d.ts +25 -0
- package/dist/constants/api.constants.js +28 -0
- package/dist/constants/index.d.ts +4 -0
- package/dist/constants/index.js +20 -0
- package/dist/enums/app-routes.enum.d.ts +12 -0
- package/dist/enums/app-routes.enum.js +16 -0
- package/dist/enums/grocery-event-types.enum.d.ts +5 -0
- package/dist/enums/grocery-event-types.enum.js +9 -0
- package/dist/enums/index.d.ts +4 -0
- package/dist/enums/index.js +20 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +25 -0
- package/dist/models/index.d.ts +4 -0
- package/dist/models/index.js +20 -0
- package/dist/models/user.model.d.ts +23 -0
- package/dist/models/user.model.js +5 -0
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/index.js +20 -0
- package/dist/utils/retry.util.d.ts +22 -0
- package/dist/utils/retry.util.js +31 -0
- package/dist/utils/string.util.d.ts +16 -0
- package/dist/utils/string.util.js +30 -0
- package/package.json +43 -0
package/README.md
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# Boykom Common Library
|
|
2
|
+
|
|
3
|
+
A shared library containing reusable utilities, enums, models, and constants for Boykom projects.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @agranom/boykom-common
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
// Import specific utilities, enums, models, or constants
|
|
15
|
+
import { capitalizeFirstLetter, truncateString } from '@agranom/boykom-common';
|
|
16
|
+
|
|
17
|
+
// Use imported items
|
|
18
|
+
const capitalized = capitalizeFirstLetter('hello');
|
|
19
|
+
const truncated = truncateString('This is a long text', 10);
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Development
|
|
23
|
+
|
|
24
|
+
### Setup
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
# Install dependencies
|
|
28
|
+
npm install
|
|
29
|
+
|
|
30
|
+
# Build the library
|
|
31
|
+
npm run build
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### Publishing
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
# Login to npm (if not already logged in)
|
|
38
|
+
npm login
|
|
39
|
+
|
|
40
|
+
# Publish the package
|
|
41
|
+
npm publish
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## License
|
|
45
|
+
|
|
46
|
+
MIT
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* API constants
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* API endpoints
|
|
6
|
+
*/
|
|
7
|
+
export declare const API_ENDPOINTS: {
|
|
8
|
+
readonly AUTH: {
|
|
9
|
+
readonly LOGIN: "/auth/login";
|
|
10
|
+
readonly REGISTER: "/auth/register";
|
|
11
|
+
readonly LOGOUT: "/auth/logout";
|
|
12
|
+
};
|
|
13
|
+
readonly USER: {
|
|
14
|
+
readonly PROFILE: "/user/profile";
|
|
15
|
+
readonly UPDATE: "/user/update";
|
|
16
|
+
};
|
|
17
|
+
readonly GROCERY: {
|
|
18
|
+
readonly LIST: "/grocery/list";
|
|
19
|
+
readonly ITEM: "/grocery/item";
|
|
20
|
+
};
|
|
21
|
+
readonly RECIPE: {
|
|
22
|
+
readonly LIST: "/recipe/list";
|
|
23
|
+
readonly ITEM: "/recipe/item";
|
|
24
|
+
};
|
|
25
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* API constants
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.API_ENDPOINTS = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* API endpoints
|
|
9
|
+
*/
|
|
10
|
+
exports.API_ENDPOINTS = {
|
|
11
|
+
AUTH: {
|
|
12
|
+
LOGIN: '/auth/login',
|
|
13
|
+
REGISTER: '/auth/register',
|
|
14
|
+
LOGOUT: '/auth/logout',
|
|
15
|
+
},
|
|
16
|
+
USER: {
|
|
17
|
+
PROFILE: '/user/profile',
|
|
18
|
+
UPDATE: '/user/update',
|
|
19
|
+
},
|
|
20
|
+
GROCERY: {
|
|
21
|
+
LIST: '/grocery/list',
|
|
22
|
+
ITEM: '/grocery/item',
|
|
23
|
+
},
|
|
24
|
+
RECIPE: {
|
|
25
|
+
LIST: '/recipe/list',
|
|
26
|
+
ITEM: '/recipe/item',
|
|
27
|
+
},
|
|
28
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Constants for Boykom projects
|
|
4
|
+
*/
|
|
5
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
10
|
+
}
|
|
11
|
+
Object.defineProperty(o, k2, desc);
|
|
12
|
+
}) : (function(o, m, k, k2) {
|
|
13
|
+
if (k2 === undefined) k2 = k;
|
|
14
|
+
o[k2] = m[k];
|
|
15
|
+
}));
|
|
16
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
17
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
__exportStar(require("./api.constants"), exports);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AppRoutes = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Application routes enum
|
|
6
|
+
*/
|
|
7
|
+
var AppRoutes;
|
|
8
|
+
(function (AppRoutes) {
|
|
9
|
+
AppRoutes["HOME"] = "/";
|
|
10
|
+
AppRoutes["LOGIN"] = "/login";
|
|
11
|
+
AppRoutes["REGISTER"] = "/register";
|
|
12
|
+
AppRoutes["PROFILE"] = "/profile";
|
|
13
|
+
AppRoutes["SETTINGS"] = "/settings";
|
|
14
|
+
AppRoutes["GROCERY"] = "/grocery";
|
|
15
|
+
AppRoutes["RECIPE"] = "/recipe";
|
|
16
|
+
})(AppRoutes || (exports.AppRoutes = AppRoutes = {}));
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GroceryEventTypes = void 0;
|
|
4
|
+
var GroceryEventTypes;
|
|
5
|
+
(function (GroceryEventTypes) {
|
|
6
|
+
GroceryEventTypes[GroceryEventTypes["Add"] = 1] = "Add";
|
|
7
|
+
GroceryEventTypes[GroceryEventTypes["Move"] = 2] = "Move";
|
|
8
|
+
GroceryEventTypes[GroceryEventTypes["Delete"] = 3] = "Delete";
|
|
9
|
+
})(GroceryEventTypes || (exports.GroceryEventTypes = GroceryEventTypes = {}));
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Enums for Boykom projects
|
|
4
|
+
*/
|
|
5
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
10
|
+
}
|
|
11
|
+
Object.defineProperty(o, k2, desc);
|
|
12
|
+
}) : (function(o, m, k, k2) {
|
|
13
|
+
if (k2 === undefined) k2 = k;
|
|
14
|
+
o[k2] = m[k];
|
|
15
|
+
}));
|
|
16
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
17
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
__exportStar(require("./grocery-event-types.enum"), exports);
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Boykom Common Library
|
|
4
|
+
*
|
|
5
|
+
* This library contains reusable utilities, enums, models, and constants
|
|
6
|
+
* for Boykom projects.
|
|
7
|
+
*/
|
|
8
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
9
|
+
if (k2 === undefined) k2 = k;
|
|
10
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
11
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
12
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
13
|
+
}
|
|
14
|
+
Object.defineProperty(o, k2, desc);
|
|
15
|
+
}) : (function(o, m, k, k2) {
|
|
16
|
+
if (k2 === undefined) k2 = k;
|
|
17
|
+
o[k2] = m[k];
|
|
18
|
+
}));
|
|
19
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
20
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
21
|
+
};
|
|
22
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
+
// Re-export all modules
|
|
24
|
+
__exportStar(require("./utils"), exports);
|
|
25
|
+
__exportStar(require("./enums"), exports);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Models for Boykom projects
|
|
4
|
+
*/
|
|
5
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
10
|
+
}
|
|
11
|
+
Object.defineProperty(o, k2, desc);
|
|
12
|
+
}) : (function(o, m, k, k2) {
|
|
13
|
+
if (k2 === undefined) k2 = k;
|
|
14
|
+
o[k2] = m[k];
|
|
15
|
+
}));
|
|
16
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
17
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
__exportStar(require("./user.model"), exports);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* User model
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* User interface representing a user in the system
|
|
6
|
+
*/
|
|
7
|
+
export interface User {
|
|
8
|
+
id: string;
|
|
9
|
+
email: string;
|
|
10
|
+
firstName: string;
|
|
11
|
+
lastName: string;
|
|
12
|
+
createdAt: Date;
|
|
13
|
+
updatedAt: Date;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* User creation data interface
|
|
17
|
+
*/
|
|
18
|
+
export interface CreateUserData {
|
|
19
|
+
email: string;
|
|
20
|
+
firstName: string;
|
|
21
|
+
lastName: string;
|
|
22
|
+
password: string;
|
|
23
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Utility functions for Boykom projects
|
|
4
|
+
*/
|
|
5
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
10
|
+
}
|
|
11
|
+
Object.defineProperty(o, k2, desc);
|
|
12
|
+
}) : (function(o, m, k, k2) {
|
|
13
|
+
if (k2 === undefined) k2 = k;
|
|
14
|
+
o[k2] = m[k];
|
|
15
|
+
}));
|
|
16
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
17
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
__exportStar(require("./retry.util"), exports);
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Options for configuring the retry behavior
|
|
3
|
+
*/
|
|
4
|
+
export interface RetryOptions {
|
|
5
|
+
/** Maximum number of retry attempts */
|
|
6
|
+
maxAttempts?: number;
|
|
7
|
+
/** Delay between retries in milliseconds */
|
|
8
|
+
delayMs?: number;
|
|
9
|
+
/** Whether to use exponential backoff for delays (doubles delay each retry) */
|
|
10
|
+
useExponentialBackoff?: boolean;
|
|
11
|
+
/** Function to call on each retry attempt */
|
|
12
|
+
onRetry?: (error: any, attempt: number) => void;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Executes an async function and retries it up to N times until it succeeds
|
|
16
|
+
*
|
|
17
|
+
* @param fn - Async function to execute
|
|
18
|
+
* @param options - Retry options
|
|
19
|
+
* @returns Promise with the result of the function
|
|
20
|
+
* @throws The last error encountered if all retry attempts fail
|
|
21
|
+
*/
|
|
22
|
+
export declare function retry<T>(fn: () => Promise<T>, options: RetryOptions): Promise<T>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.retry = retry;
|
|
4
|
+
/**
|
|
5
|
+
* Executes an async function and retries it up to N times until it succeeds
|
|
6
|
+
*
|
|
7
|
+
* @param fn - Async function to execute
|
|
8
|
+
* @param options - Retry options
|
|
9
|
+
* @returns Promise with the result of the function
|
|
10
|
+
* @throws The last error encountered if all retry attempts fail
|
|
11
|
+
*/
|
|
12
|
+
async function retry(fn, options) {
|
|
13
|
+
const { maxAttempts = 3, delayMs = 1000, useExponentialBackoff = false, onRetry } = options;
|
|
14
|
+
let lastError;
|
|
15
|
+
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
|
16
|
+
try {
|
|
17
|
+
return await fn();
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
lastError = error;
|
|
21
|
+
if (attempt < maxAttempts) {
|
|
22
|
+
if (onRetry) {
|
|
23
|
+
onRetry(error, attempt);
|
|
24
|
+
}
|
|
25
|
+
const currentDelay = useExponentialBackoff ? delayMs * Math.pow(2, attempt - 1) : delayMs;
|
|
26
|
+
await new Promise((resolve) => setTimeout(resolve, currentDelay));
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
throw lastError;
|
|
31
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* String utility functions
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Capitalizes the first letter of a string
|
|
6
|
+
* @param str - The string to capitalize
|
|
7
|
+
* @returns The capitalized string
|
|
8
|
+
*/
|
|
9
|
+
export declare function capitalizeFirstLetter(str: string): string;
|
|
10
|
+
/**
|
|
11
|
+
* Truncates a string to a specified length and adds an ellipsis if truncated
|
|
12
|
+
* @param str - The string to truncate
|
|
13
|
+
* @param maxLength - The maximum length of the string
|
|
14
|
+
* @returns The truncated string
|
|
15
|
+
*/
|
|
16
|
+
export declare function truncateString(str: string, maxLength: number): string;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* String utility functions
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.capitalizeFirstLetter = capitalizeFirstLetter;
|
|
7
|
+
exports.truncateString = truncateString;
|
|
8
|
+
/**
|
|
9
|
+
* Capitalizes the first letter of a string
|
|
10
|
+
* @param str - The string to capitalize
|
|
11
|
+
* @returns The capitalized string
|
|
12
|
+
*/
|
|
13
|
+
function capitalizeFirstLetter(str) {
|
|
14
|
+
if (!str || str.length === 0) {
|
|
15
|
+
return str;
|
|
16
|
+
}
|
|
17
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Truncates a string to a specified length and adds an ellipsis if truncated
|
|
21
|
+
* @param str - The string to truncate
|
|
22
|
+
* @param maxLength - The maximum length of the string
|
|
23
|
+
* @returns The truncated string
|
|
24
|
+
*/
|
|
25
|
+
function truncateString(str, maxLength) {
|
|
26
|
+
if (!str || str.length <= maxLength) {
|
|
27
|
+
return str;
|
|
28
|
+
}
|
|
29
|
+
return str.slice(0, maxLength) + '...';
|
|
30
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@agranom/boykom-common",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Boykom Common Library",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "tsc",
|
|
12
|
+
"prepublishOnly": "npm run build",
|
|
13
|
+
"test": "jest",
|
|
14
|
+
"lint": "eslint --ext .ts src",
|
|
15
|
+
"clean": "rimraf dist",
|
|
16
|
+
"setup": "node install.js"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"boykom",
|
|
20
|
+
"utils",
|
|
21
|
+
"common"
|
|
22
|
+
],
|
|
23
|
+
"author": "",
|
|
24
|
+
"license": "MIT",
|
|
25
|
+
"repository": {
|
|
26
|
+
"type": "git",
|
|
27
|
+
"url": "https://github.com/agranom/boykom-common"
|
|
28
|
+
},
|
|
29
|
+
"publishConfig": {
|
|
30
|
+
"access": "public"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@types/jest": "^29.5.0",
|
|
34
|
+
"@types/node": "^18.15.11",
|
|
35
|
+
"@typescript-eslint/eslint-plugin": "^5.57.1",
|
|
36
|
+
"@typescript-eslint/parser": "^5.57.1",
|
|
37
|
+
"eslint": "^8.38.0",
|
|
38
|
+
"jest": "^29.5.0",
|
|
39
|
+
"rimraf": "^5.0.0",
|
|
40
|
+
"ts-jest": "^29.1.0",
|
|
41
|
+
"typescript": "^5.0.4"
|
|
42
|
+
}
|
|
43
|
+
}
|