@lucaapp/service-utils 1.62.6 → 1.64.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 +47 -22
- package/dist/lib/kafka/events/operatorLocationGroup.d.ts +16 -0
- package/dist/lib/kafka/events/operatorLocationGroup.js +12 -0
- package/dist/lib/kafka/events/reservation.d.ts +5 -0
- package/dist/lib/money/sequelize/index.d.ts +1 -0
- package/dist/lib/money/sequelize/index.js +17 -0
- package/dist/lib/money/sequelize/money.d.ts +21 -0
- package/dist/lib/money/sequelize/money.js +56 -0
- package/dist/types/pino.d.ts +2 -0
- package/dist/types/pino.ded.d.ts +2 -0
- package/dist/types/pino.ded.js +2 -0
- package/dist/types/pino.js +2 -0
- package/package.json +22 -19
package/README.md
CHANGED
|
@@ -1,24 +1,31 @@
|
|
|
1
1
|
## service-utils
|
|
2
2
|
|
|
3
|
-
`service-utils`
|
|
4
|
-
|
|
3
|
+
`service-utils` is a shared package that provides functionality for backend
|
|
4
|
+
services to reduce code duplication. It includes utilities for:
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
- Logging and monitoring
|
|
7
|
+
- API validation and OpenAPI documentation
|
|
8
|
+
- Error handling
|
|
9
|
+
- Database operations
|
|
10
|
+
- Authentication and authorization
|
|
11
|
+
- Kafka messaging
|
|
12
|
+
- HTTP client operations
|
|
13
|
+
- And more
|
|
7
14
|
|
|
8
|
-
Development
|
|
9
|
-
Therefore, some adoptions and preparations are necessary.
|
|
10
|
-
Follow these steps for initial setup:
|
|
15
|
+
### Development Setup
|
|
11
16
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
17
|
+
1. Navigate to `packages/service-utils`
|
|
18
|
+
2. Run `yarn link`
|
|
19
|
+
3. Navigate to `services/backend`
|
|
20
|
+
4. Run `yarn link @lucaapp/service-utils`
|
|
16
21
|
|
|
17
|
-
This will connect your local sources for `@lucaapp/service-utils`.
|
|
18
|
-
|
|
22
|
+
This will connect your local sources for `@lucaapp/service-utils`. When making
|
|
23
|
+
changes:
|
|
19
24
|
|
|
20
|
-
|
|
21
|
-
|
|
25
|
+
1. Run `yarn build` in `packages/service-utils` to compile changes
|
|
26
|
+
2. Run `yarn package-development` in `services/backend` to test changes
|
|
27
|
+
|
|
28
|
+
Required environment variables for local development:
|
|
22
29
|
|
|
23
30
|
```shell
|
|
24
31
|
export DB_HOSTNAME=localhost
|
|
@@ -26,16 +33,34 @@ export KAFKA_BROKER=localhost:9094
|
|
|
26
33
|
export REDIS_HOSTNAME=localhost
|
|
27
34
|
```
|
|
28
35
|
|
|
29
|
-
|
|
30
|
-
|
|
36
|
+
Ensure your docker stack has `database`, `kafka`, and `redis` running (but not
|
|
37
|
+
`backend`).
|
|
38
|
+
|
|
39
|
+
### Available Scripts
|
|
40
|
+
|
|
41
|
+
- `yarn build` - Compile TypeScript to JavaScript
|
|
42
|
+
- `yarn ts:check` - Type check without emitting files
|
|
43
|
+
- `yarn lint` - Run ESLint
|
|
44
|
+
- `yarn test` - Run tests with Vitest
|
|
45
|
+
- `yarn test:coverage` - Run tests with coverage report
|
|
46
|
+
- `yarn test:ci` - Run tests in CI environment
|
|
47
|
+
- `yarn audit` - Run security audit (ignoring dev dependencies)
|
|
48
|
+
|
|
49
|
+
### Publishing
|
|
31
50
|
|
|
32
|
-
|
|
51
|
+
The package is automatically published when changes are merged to `dev`. Follow
|
|
52
|
+
[semantic-release](https://www.npmjs.com/package/semantic-release) conventions
|
|
53
|
+
in commit messages to trigger appropriate versioning.
|
|
33
54
|
|
|
34
|
-
|
|
55
|
+
### Dependencies
|
|
35
56
|
|
|
36
|
-
|
|
37
|
-
See `./gitlab-ci/publish[.template].yml` for reference.
|
|
57
|
+
The package uses modern versions of key dependencies:
|
|
38
58
|
|
|
39
|
-
|
|
59
|
+
- TypeScript 5.5.3
|
|
60
|
+
- Node.js 18
|
|
61
|
+
- Express 4.21.2
|
|
62
|
+
- Sequelize 6.32.0
|
|
63
|
+
- Zod 3.22.3
|
|
64
|
+
- Vitest 3.0.5 for testing
|
|
40
65
|
|
|
41
|
-
|
|
66
|
+
See `package.json` for a complete list of dependencies.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare enum OperatorRole {
|
|
2
|
+
Owner = "Owner",// level 6
|
|
3
|
+
Admin = "Admin",// level 5
|
|
4
|
+
Finance = "Finance",// level 4
|
|
5
|
+
Manager = "Manager",// level 3
|
|
6
|
+
Supervisor = "Supervisor",// level 2
|
|
7
|
+
Viewer = "Viewer"
|
|
8
|
+
}
|
|
9
|
+
export type OperatorLocationGroup = {
|
|
10
|
+
uuid: string;
|
|
11
|
+
operatorId: string;
|
|
12
|
+
locationGroupId: string;
|
|
13
|
+
role: OperatorRole;
|
|
14
|
+
createdAt: Date;
|
|
15
|
+
updatedAt: Date;
|
|
16
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OperatorRole = void 0;
|
|
4
|
+
var OperatorRole;
|
|
5
|
+
(function (OperatorRole) {
|
|
6
|
+
OperatorRole["Owner"] = "Owner";
|
|
7
|
+
OperatorRole["Admin"] = "Admin";
|
|
8
|
+
OperatorRole["Finance"] = "Finance";
|
|
9
|
+
OperatorRole["Manager"] = "Manager";
|
|
10
|
+
OperatorRole["Supervisor"] = "Supervisor";
|
|
11
|
+
OperatorRole["Viewer"] = "Viewer";
|
|
12
|
+
})(OperatorRole || (exports.OperatorRole = OperatorRole = {}));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './money';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./money"), exports);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { DataTypes } from 'sequelize';
|
|
2
|
+
declare class MONEY extends DataTypes.ABSTRACT.prototype.constructor {
|
|
3
|
+
static key: string;
|
|
4
|
+
static warn: () => void;
|
|
5
|
+
key: string;
|
|
6
|
+
escape: boolean;
|
|
7
|
+
types: {
|
|
8
|
+
postgres: string[];
|
|
9
|
+
sqlite: string[];
|
|
10
|
+
};
|
|
11
|
+
static toSql(): string;
|
|
12
|
+
validate(value: unknown, options: unknown): boolean;
|
|
13
|
+
_sanitize(value: unknown): number;
|
|
14
|
+
static stringify(value: unknown): string;
|
|
15
|
+
static dialectTypes: string;
|
|
16
|
+
static parse(value: unknown): number;
|
|
17
|
+
}
|
|
18
|
+
export declare const ExtendedDataTypes: {
|
|
19
|
+
MONEY: typeof MONEY & (() => typeof MONEY);
|
|
20
|
+
};
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ExtendedDataTypes = void 0;
|
|
4
|
+
const sequelize_1 = require("sequelize");
|
|
5
|
+
// Define the MONEY data type
|
|
6
|
+
class MONEY extends sequelize_1.DataTypes.ABSTRACT.prototype.constructor {
|
|
7
|
+
constructor() {
|
|
8
|
+
super(...arguments);
|
|
9
|
+
this.key = MONEY.key;
|
|
10
|
+
// Optional: disable escaping after stringifier. Do this at your own risk, since this opens opportunity for SQL injections.
|
|
11
|
+
this.escape = false;
|
|
12
|
+
// Optional: map dialect datatype names (mandatory if not creating dialect-specific datatype classes as in the example below)
|
|
13
|
+
this.types = {
|
|
14
|
+
postgres: ['pg_new_type'],
|
|
15
|
+
sqlite: ['sqlite_new_type'],
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
// Mandatory: complete definition of the new type in the database
|
|
19
|
+
static toSql() {
|
|
20
|
+
return 'INTEGER(11) UNSIGNED ZEROFILL';
|
|
21
|
+
}
|
|
22
|
+
// Optional: validator function
|
|
23
|
+
validate(value, options) {
|
|
24
|
+
return typeof value === 'number' && !Number.isNaN(value);
|
|
25
|
+
}
|
|
26
|
+
// Optional: sanitizer
|
|
27
|
+
_sanitize(value) {
|
|
28
|
+
// Force all numbers to be positive
|
|
29
|
+
return value < 0 ? 0 : Math.round(value);
|
|
30
|
+
}
|
|
31
|
+
// Optional: value stringifier before sending to database
|
|
32
|
+
static stringify(value) {
|
|
33
|
+
return value.toString();
|
|
34
|
+
}
|
|
35
|
+
// Optional: parser for values received from the database
|
|
36
|
+
static parse(value) {
|
|
37
|
+
return Number.parseInt(value);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
// Mandatory: set the type key
|
|
41
|
+
MONEY.key = 'MONEY';
|
|
42
|
+
MONEY.warn = () => { };
|
|
43
|
+
MONEY.dialectTypes = 'test';
|
|
44
|
+
// Create a new type that extends DataTypes and includes MONEY
|
|
45
|
+
exports.ExtendedDataTypes = {
|
|
46
|
+
// ...DataTypes,
|
|
47
|
+
MONEY: sequelize_1.Utils.classToInvokable(MONEY),
|
|
48
|
+
};
|
|
49
|
+
// Export the extended DataTypes
|
|
50
|
+
// export { ExtendedDataTypes as DataTypes };
|
|
51
|
+
// // Type declaration merging
|
|
52
|
+
// declare module 'sequelize' {
|
|
53
|
+
// interface DataTypes {
|
|
54
|
+
// MONEY: typeof MONEY;
|
|
55
|
+
// }
|
|
56
|
+
// }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lucaapp/service-utils",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.64.0",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"files": [
|
|
@@ -20,14 +20,14 @@
|
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"@asteasolutions/zod-to-openapi": "6.1.0",
|
|
22
22
|
"@hapi/boom": "^10.0.0",
|
|
23
|
-
"@sentry/node": "^9.
|
|
24
|
-
"@tsconfig/
|
|
23
|
+
"@sentry/node": "^9.10.1",
|
|
24
|
+
"@tsconfig/node22": "22.0.0",
|
|
25
25
|
"@types/express": "4.17.15",
|
|
26
26
|
"@types/express-serve-static-core": "^4.17.43",
|
|
27
|
-
"@types/node": "
|
|
27
|
+
"@types/node": "22.13.11",
|
|
28
28
|
"@types/response-time": "^2.3.8",
|
|
29
29
|
"@types/swagger-ui-express": "4.1.3",
|
|
30
|
-
"axios": "^1.
|
|
30
|
+
"axios": "^1.8.2",
|
|
31
31
|
"busboy": "^1.6.0",
|
|
32
32
|
"cls-rtracer": "^2.6.2",
|
|
33
33
|
"express": "4.21.2",
|
|
@@ -47,41 +47,44 @@
|
|
|
47
47
|
"swagger-ui-express": "5.0.1",
|
|
48
48
|
"url-value-parser": "^2.2.0",
|
|
49
49
|
"uuid": "^9.0.0",
|
|
50
|
-
"zod": "3.22.3"
|
|
50
|
+
"zod": "3.22.3",
|
|
51
|
+
"@apidevtools/swagger-parser": "10.0.3"
|
|
51
52
|
},
|
|
52
53
|
"devDependencies": {
|
|
53
|
-
"@types/busboy": "^1.5.
|
|
54
|
+
"@types/busboy": "^1.5.4",
|
|
54
55
|
"@types/lodash": "^4.14.187",
|
|
55
56
|
"@types/negotiator": "^0.6.1",
|
|
56
57
|
"@types/pino-http": "5.8.4",
|
|
57
|
-
"@types/supertest": "2.0.
|
|
58
|
+
"@types/supertest": "2.0.16",
|
|
58
59
|
"@types/uuid": "^8.3.4",
|
|
59
60
|
"@typescript-eslint/eslint-plugin": "^7.15.0",
|
|
60
61
|
"@typescript-eslint/parser": "^7.15.0",
|
|
61
|
-
"@vitest/coverage-v8": "3.
|
|
62
|
-
"conventional-changelog-conventionalcommits": "^
|
|
62
|
+
"@vitest/coverage-v8": "3.1.1",
|
|
63
|
+
"conventional-changelog-conventionalcommits": "^8.0.0",
|
|
63
64
|
"eslint": "8.57.0",
|
|
64
65
|
"eslint-plugin-prettier": "4.2.1",
|
|
65
66
|
"eslint-plugin-vitest": "0.4.1",
|
|
66
|
-
"improved-yarn-audit": "^3.0.
|
|
67
|
+
"improved-yarn-audit": "^3.0.3",
|
|
67
68
|
"prettier": "2.7.1",
|
|
68
|
-
"semantic-release": "^19.0.
|
|
69
|
-
"semantic-release-monorepo": "^7.0.
|
|
69
|
+
"semantic-release": "^19.0.5",
|
|
70
|
+
"semantic-release-monorepo": "^7.0.8",
|
|
70
71
|
"supertest": "^6.3.3",
|
|
71
72
|
"typescript": "5.5.3",
|
|
72
73
|
"vite-tsconfig-paths": "4.3.2",
|
|
73
|
-
"vitest": "3.
|
|
74
|
+
"vitest": "3.1.1"
|
|
74
75
|
},
|
|
75
76
|
"resolutions": {
|
|
76
77
|
"yaml": "2.2.2",
|
|
77
|
-
"semver": "7.
|
|
78
|
-
"follow-redirects": "1.15.
|
|
78
|
+
"semver": "7.7.1",
|
|
79
|
+
"follow-redirects": "1.15.9",
|
|
79
80
|
"braces": "3.0.3",
|
|
80
|
-
"send": "0.19.
|
|
81
|
+
"send": "0.19.1",
|
|
81
82
|
"rollup": "4.22.4",
|
|
82
|
-
"cookie": ">= 0.
|
|
83
|
+
"cookie": ">= 1.0.2",
|
|
83
84
|
"string-width": "4.2.3",
|
|
84
85
|
"@types/express": "4.17.15",
|
|
85
|
-
"esbuild": "^0.25.
|
|
86
|
+
"esbuild": "^0.25.5",
|
|
87
|
+
"axios": "^1.8.2",
|
|
88
|
+
"vite": "6.2.5"
|
|
86
89
|
}
|
|
87
90
|
}
|