@qelos/api-kit 3.11.8 → 3.11.10

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/app.d.ts CHANGED
@@ -1,7 +1,9 @@
1
1
  import type { ApiConfig } from './types';
2
2
  export declare const config: (updatedConfig?: any) => ApiConfig;
3
3
  export declare const app: () => any;
4
- export declare const start: typeof startApp;
5
- export declare function getBodyParser(): any;
4
+ export declare function getBodyParser(options?: {
5
+ limit?: string;
6
+ }): any;
6
7
  declare function startApp(serviceName?: string, port?: string | number, ip?: string): Promise<void>;
8
+ export declare const start: typeof startApp;
7
9
  export {};
package/dist/app.js CHANGED
@@ -7,14 +7,6 @@ exports.start = exports.app = exports.config = void 0;
7
7
  exports.getBodyParser = getBodyParser;
8
8
  const express_1 = __importDefault(require("express"));
9
9
  const shutdown_1 = __importDefault(require("./shutdown"));
10
- const config = (updatedConfig = _config) => {
11
- _config = { ..._config, ...updatedConfig };
12
- return _config;
13
- };
14
- exports.config = config;
15
- const app = () => _app || createApp();
16
- exports.app = app;
17
- exports.start = startApp;
18
10
  let _app;
19
11
  let _config = {
20
12
  cors: !!process.env.API_CORS || false,
@@ -23,11 +15,18 @@ let _config = {
23
15
  port: process.env?.PORT || '3000',
24
16
  ip: process.env.IP || '127.0.0.1'
25
17
  };
18
+ const config = (updatedConfig = _config) => {
19
+ _config = { ..._config, ...updatedConfig };
20
+ return _config;
21
+ };
22
+ exports.config = config;
26
23
  function createApp() {
27
24
  _app = (0, express_1.default)();
28
25
  configureApp(_app);
29
26
  return _app;
30
27
  }
28
+ const app = () => _app || createApp();
29
+ exports.app = app;
31
30
  const HEALTH_PATH = '/internal-api/health';
32
31
  function configureApp(app) {
33
32
  const morganSkip = (req) => req.path === HEALTH_PATH;
@@ -51,8 +50,8 @@ function configureApp(app) {
51
50
  res.status(200).send('ok');
52
51
  });
53
52
  }
54
- function getBodyParser() {
55
- return express_1.default.json();
53
+ function getBodyParser(options = _config.bodyParserOptions || {}) {
54
+ return express_1.default.json(options);
56
55
  }
57
56
  function startApp(serviceName = 'APP', port = _config.port, ip = _config.ip) {
58
57
  return new Promise((resolve) => {
@@ -65,4 +64,5 @@ function startApp(serviceName = 'APP', port = _config.port, ip = _config.ip) {
65
64
  });
66
65
  });
67
66
  }
67
+ exports.start = startApp;
68
68
  //# sourceMappingURL=app.js.map
package/dist/app.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"app.js","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":";;;;;;AAqDA,sCAEC;AAvDD,sDAA2C;AAG3C,0DAAkC;AAE3B,MAAM,MAAM,GAAG,CAAC,gBAAqB,OAAO,EAAa,EAAE;IAChE,OAAO,GAAG,EAAE,GAAG,OAAO,EAAE,GAAG,aAAa,EAAE,CAAC;IAC3C,OAAO,OAAO,CAAC;AACjB,CAAC,CAAA;AAHY,QAAA,MAAM,UAGlB;AACM,MAAM,GAAG,GAAG,GAAG,EAAE,CAAC,IAAI,IAAI,SAAS,EAAE,CAAC;AAAhC,QAAA,GAAG,OAA6B;AAChC,QAAA,KAAK,GAAG,QAAQ,CAAC;AAE9B,IAAI,IAAa,CAAC;AAClB,IAAI,OAAO,GAAc;IACvB,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,IAAI,KAAK;IACrC,UAAU,EAAG,OAAO,CAAC,GAAG,CAAC,eAAkC,IAAI,MAAM;IACrE,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,SAAS;IACjC,IAAI,EAAE,OAAO,CAAC,GAAG,EAAE,IAAI,IAAI,MAAM;IACjC,EAAE,EAAE,OAAO,CAAC,GAAG,CAAC,EAAE,IAAI,WAAW;CAClC,CAAC;AAEF,SAAS,SAAS;IAChB,IAAI,GAAG,IAAA,iBAAO,GAAE,CAAA;IAEhB,YAAY,CAAC,IAAI,CAAC,CAAC;IAEnB,OAAO,IAAI,CAAC;AACd,CAAC;AAED,MAAM,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,EAAE,EAAE;QAC9B,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC7B,CAAC,CAAC,CAAA;AACJ,CAAC;AAED,SAAgB,aAAa,CAAC,OAAO,GAAG,OAAO,CAAC,iBAAiB,IAAI,EAAE;IACrE,OAAO,iBAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AAC/B,CAAC;AAED,SAAS,QAAQ,CAAC,WAAW,GAAG,KAAK,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,EAAE,EAAE,GAAG,OAAO,CAAC,EAAE;IACzE,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC7B,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAc,CAAC,EAAE,EAAE,EAAE,GAAG,EAAE;YAC7C,OAAO,CAAC,GAAG,CAAC,GAAG,WAAW,uBAAuB,IAAI,EAAE,CAAC,CAAC;YACzD,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;gBACrB,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAC;YACpC,CAAC;YACD,OAAO,EAAE,CAAC;QACZ,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAA;AACJ,CAAC;AAEY,QAAA,KAAK,GAAG,QAAQ,CAAC"}
package/dist/index.d.ts CHANGED
@@ -5,3 +5,4 @@ export * from './internal-service';
5
5
  export * from './user-middlewares';
6
6
  export * from './emit-internal-event';
7
7
  export * from './response-error';
8
+ export * from './request-utils';
package/dist/index.js CHANGED
@@ -21,4 +21,5 @@ __exportStar(require("./internal-service"), exports);
21
21
  __exportStar(require("./user-middlewares"), exports);
22
22
  __exportStar(require("./emit-internal-event"), exports);
23
23
  __exportStar(require("./response-error"), exports);
24
+ __exportStar(require("./request-utils"), exports);
24
25
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,6CAA0B;AAC1B,wCAAqB;AACrB,2CAAwB;AACxB,qDAAkC;AAClC,qDAAkC;AAClC,wDAAqC;AACrC,mDAAiC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,6CAA0B;AAC1B,wCAAqB;AACrB,2CAAwB;AACxB,qDAAkC;AAClC,qDAAkC;AAClC,wDAAqC;AACrC,mDAAiC;AACjC,kDAAgC"}
@@ -0,0 +1,6 @@
1
+ import type { Request } from 'express';
2
+ /**
3
+ * Reads bypassAdmin from request body, query, or header (x-bypass-admin).
4
+ * When true, privileged users (e.g. admin) are treated as regular users for scope filtering.
5
+ */
6
+ export declare function getBypassAdmin(req: Request): boolean;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getBypassAdmin = getBypassAdmin;
4
+ /**
5
+ * Reads bypassAdmin from request body, query, or header (x-bypass-admin).
6
+ * When true, privileged users (e.g. admin) are treated as regular users for scope filtering.
7
+ */
8
+ function getBypassAdmin(req) {
9
+ if (typeof req.body?.bypassAdmin !== 'undefined') {
10
+ return !!req.body.bypassAdmin;
11
+ }
12
+ if (req.query?.bypassAdmin === 'true') {
13
+ return true;
14
+ }
15
+ const h = req.headers?.['x-bypass-admin'];
16
+ return h === 'true' || h === '1';
17
+ }
18
+ //# sourceMappingURL=request-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request-utils.js","sourceRoot":"","sources":["../src/request-utils.ts"],"names":[],"mappings":";;AAMA,wCASC;AAbD;;;GAGG;AACH,SAAgB,cAAc,CAAC,GAAY;IACzC,IAAI,OAAQ,GAAW,CAAC,IAAI,EAAE,WAAW,KAAK,WAAW,EAAE,CAAC;QAC1D,OAAO,CAAC,CAAE,GAAW,CAAC,IAAI,CAAC,WAAW,CAAC;IACzC,CAAC;IACD,IAAK,GAAW,CAAC,KAAK,EAAE,WAAW,KAAK,MAAM,EAAE,CAAC;QAC/C,OAAO,IAAI,CAAC;IACd,CAAC;IACD,MAAM,CAAC,GAAG,GAAG,CAAC,OAAO,EAAE,CAAC,gBAAgB,CAAC,CAAC;IAC1C,OAAO,CAAC,KAAK,MAAM,IAAI,CAAC,KAAK,GAAG,CAAC;AACnC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qelos/api-kit",
3
- "version": "3.11.8",
3
+ "version": "3.11.10",
4
4
  "description": "API-Kit package to help with qelos infrastructure and reuse capabilities across services",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/app.ts CHANGED
@@ -3,13 +3,6 @@ import express, { Express } from 'express';
3
3
  import type { ApiConfig, BodyParserType } from './types';
4
4
  import shutdown from './shutdown';
5
5
 
6
- export const config = (updatedConfig: any = _config): ApiConfig => {
7
- _config = { ..._config, ...updatedConfig };
8
- return _config;
9
- }
10
- export const app = () => _app || createApp();
11
- export const start = startApp;
12
-
13
6
  let _app: Express;
14
7
  let _config: ApiConfig = {
15
8
  cors: !!process.env.API_CORS || false,
@@ -19,6 +12,11 @@ let _config: ApiConfig = {
19
12
  ip: process.env.IP || '127.0.0.1'
20
13
  };
21
14
 
15
+ export const config = (updatedConfig: any = _config): ApiConfig => {
16
+ _config = { ..._config, ...updatedConfig };
17
+ return _config;
18
+ }
19
+
22
20
  function createApp() {
23
21
  _app = express()
24
22
 
@@ -27,6 +25,8 @@ function createApp() {
27
25
  return _app;
28
26
  }
29
27
 
28
+ export const app = () => _app || createApp();
29
+
30
30
  const HEALTH_PATH = '/internal-api/health';
31
31
 
32
32
  function configureApp(app: Express) {
@@ -51,8 +51,8 @@ function configureApp(app: Express) {
51
51
  })
52
52
  }
53
53
 
54
- export function getBodyParser() {
55
- return express.json();
54
+ export function getBodyParser(options = _config.bodyParserOptions || {}) {
55
+ return express.json(options);
56
56
  }
57
57
 
58
58
  function startApp(serviceName = 'APP', port = _config.port, ip = _config.ip): Promise<void> {
@@ -67,3 +67,6 @@ function startApp(serviceName = 'APP', port = _config.port, ip = _config.ip): Pr
67
67
  })
68
68
  }
69
69
 
70
+ export const start = startApp;
71
+
72
+
package/src/index.ts CHANGED
@@ -4,4 +4,5 @@ export * from './router'
4
4
  export * from './internal-service'
5
5
  export * from './user-middlewares'
6
6
  export * from './emit-internal-event'
7
- export * from './response-error';
7
+ export * from './response-error';
8
+ export * from './request-utils';
@@ -0,0 +1,16 @@
1
+ import type { Request } from 'express';
2
+
3
+ /**
4
+ * Reads bypassAdmin from request body, query, or header (x-bypass-admin).
5
+ * When true, privileged users (e.g. admin) are treated as regular users for scope filtering.
6
+ */
7
+ export function getBypassAdmin(req: Request): boolean {
8
+ if (typeof (req as any).body?.bypassAdmin !== 'undefined') {
9
+ return !!(req as any).body.bypassAdmin;
10
+ }
11
+ if ((req as any).query?.bypassAdmin === 'true') {
12
+ return true;
13
+ }
14
+ const h = req.headers?.['x-bypass-admin'];
15
+ return h === 'true' || h === '1';
16
+ }