@lucaapp/service-utils 1.64.1 → 1.65.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/lib/api/api.js +8 -2
- package/dist/lib/api/endpoint.js +6 -0
- package/dist/lib/api/types/middleware.d.ts +2 -0
- package/dist/lib/kafka/events/operatorLocationGroup.d.ts +16 -0
- package/dist/lib/kafka/events/operatorLocationGroup.js +12 -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 +4 -3
package/dist/lib/api/api.js
CHANGED
|
@@ -10,6 +10,13 @@ const swagger_ui_express_1 = __importDefault(require("swagger-ui-express"));
|
|
|
10
10
|
const zod_to_openapi_1 = require("@asteasolutions/zod-to-openapi");
|
|
11
11
|
const endpoint_1 = require("./endpoint");
|
|
12
12
|
const openapi_1 = require("./openapi");
|
|
13
|
+
const body_parser_1 = __importDefault(require("body-parser"));
|
|
14
|
+
const rawBodySaver = function (req, res, buf, encoding) {
|
|
15
|
+
if (buf && buf.length) {
|
|
16
|
+
// @ts-expect-error - rawBody is an extension
|
|
17
|
+
req.rawBody = buf.toString(encoding || 'utf8');
|
|
18
|
+
}
|
|
19
|
+
};
|
|
13
20
|
class Api {
|
|
14
21
|
constructor(options = {}) {
|
|
15
22
|
this.router = options.router || (0, express_1.Router)();
|
|
@@ -21,8 +28,7 @@ class Api {
|
|
|
21
28
|
this.apiDescription = options.apiDescription || '';
|
|
22
29
|
this.debug = options.debug || false;
|
|
23
30
|
this.tags = options.tags || [];
|
|
24
|
-
|
|
25
|
-
this.router.use((0, express_1.json)());
|
|
31
|
+
this.router.use(body_parser_1.default.json({ verify: rawBodySaver }));
|
|
26
32
|
}
|
|
27
33
|
child(options) {
|
|
28
34
|
return new Api({
|
package/dist/lib/api/endpoint.js
CHANGED
|
@@ -281,9 +281,15 @@ new Promise(async (resolve) => {
|
|
|
281
281
|
request.headers['content-type']?.includes('multipart/form-data')) {
|
|
282
282
|
files = await handleMultipleFileUpload(request);
|
|
283
283
|
}
|
|
284
|
+
let rawBody;
|
|
285
|
+
if (middleware.options.config?.returnRawBody) {
|
|
286
|
+
// @ts-expect-error - rawBody is an extension
|
|
287
|
+
rawBody = request.rawBody;
|
|
288
|
+
}
|
|
284
289
|
// if the header is multipart we should return a buffer with the content
|
|
285
290
|
const handlerRequest = {
|
|
286
291
|
body: handlerRequestBody,
|
|
292
|
+
...(rawBody && { rawBody }),
|
|
287
293
|
...(file && { file }),
|
|
288
294
|
...(files && { files }),
|
|
289
295
|
params: handlerRequestParams,
|
|
@@ -18,6 +18,7 @@ export type FileUpload = {
|
|
|
18
18
|
};
|
|
19
19
|
export type MiddlewareHandler<TResponseSchema, TRequestBodySchema, TRequestParamsSchema, TRequestQuerySchema, TRequestHeadersSchema, TContextSchema> = (request: {
|
|
20
20
|
body: ZodSchemaOuput<TRequestBodySchema>;
|
|
21
|
+
rawBody?: string | Buffer | object;
|
|
21
22
|
params: ZodSchemaOuput<TRequestParamsSchema>;
|
|
22
23
|
query: ZodSchemaOuput<TRequestQuerySchema>;
|
|
23
24
|
headers: ZodSchemaOuput<TRequestHeadersSchema>;
|
|
@@ -41,6 +42,7 @@ export type MiddlewareOptions<TResponseSchemas extends ReadonlyArray<EndpointRes
|
|
|
41
42
|
config?: {
|
|
42
43
|
isFileUpload?: boolean;
|
|
43
44
|
isFilesUpload?: boolean;
|
|
45
|
+
returnRawBody?: boolean;
|
|
44
46
|
};
|
|
45
47
|
errors?: Record<string, number>;
|
|
46
48
|
};
|
|
@@ -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.65.0",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"files": [
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
"audit": "improved-yarn-audit --ignore-dev-deps"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
+
"@apidevtools/swagger-parser": "10.0.3",
|
|
21
22
|
"@asteasolutions/zod-to-openapi": "6.1.0",
|
|
22
23
|
"@hapi/boom": "^10.0.1",
|
|
23
24
|
"@sentry/node": "^9.10.1",
|
|
@@ -28,6 +29,7 @@
|
|
|
28
29
|
"@types/response-time": "^2.3.8",
|
|
29
30
|
"@types/swagger-ui-express": "4.1.3",
|
|
30
31
|
"axios": "^1.8.2",
|
|
32
|
+
"body-parser": "^2.2.0",
|
|
31
33
|
"busboy": "^1.6.0",
|
|
32
34
|
"cls-rtracer": "^2.6.2",
|
|
33
35
|
"express": "4.21.2",
|
|
@@ -47,8 +49,7 @@
|
|
|
47
49
|
"swagger-ui-express": "5.0.1",
|
|
48
50
|
"url-value-parser": "^2.2.0",
|
|
49
51
|
"uuid": "^9.0.0",
|
|
50
|
-
"zod": "3.22.3"
|
|
51
|
-
"@apidevtools/swagger-parser": "10.0.3"
|
|
52
|
+
"zod": "3.22.3"
|
|
52
53
|
},
|
|
53
54
|
"devDependencies": {
|
|
54
55
|
"@types/busboy": "^1.5.4",
|