av6-core 1.1.4 → 1.1.6

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/index.d.mts CHANGED
@@ -393,6 +393,7 @@ interface AuditContext {
393
393
  userId: number | null;
394
394
  traceId: string | null;
395
395
  ccId: number | null;
396
+ module: "OPD" | "PROCEDURE" | "GENERAL_BILL" | "PHARMACY" | "LAB" | "IPD";
396
397
  }
397
398
  type AuditContextProvider = () => AuditContext;
398
399
  interface AuditLogPayload {
@@ -426,12 +427,6 @@ declare class AuditLogger {
426
427
  declare class AuditProxy {
427
428
  private logger;
428
429
  constructor(logger: AuditLogger);
429
- /**
430
- * Wraps a service object so that all its methods are auto-audited.
431
- *
432
- * Usage:
433
- * const audited = auditProxy.createAuditedService("SellService", sellServiceRaw);
434
- */
435
430
  createAuditedService<T extends object>(serviceName: string, service: T): T;
436
431
  }
437
432
 
package/dist/index.d.ts CHANGED
@@ -393,6 +393,7 @@ interface AuditContext {
393
393
  userId: number | null;
394
394
  traceId: string | null;
395
395
  ccId: number | null;
396
+ module: "OPD" | "PROCEDURE" | "GENERAL_BILL" | "PHARMACY" | "LAB" | "IPD";
396
397
  }
397
398
  type AuditContextProvider = () => AuditContext;
398
399
  interface AuditLogPayload {
@@ -426,12 +427,6 @@ declare class AuditLogger {
426
427
  declare class AuditProxy {
427
428
  private logger;
428
429
  constructor(logger: AuditLogger);
429
- /**
430
- * Wraps a service object so that all its methods are auto-audited.
431
- *
432
- * Usage:
433
- * const audited = auditProxy.createAuditedService("SellService", sellServiceRaw);
434
- */
435
430
  createAuditedService<T extends object>(serviceName: string, service: T): T;
436
431
  }
437
432
 
package/dist/index.js CHANGED
@@ -2014,11 +2014,12 @@ var AuditLogger = class {
2014
2014
  async logIfEnabled(params) {
2015
2015
  const { service, method, payload } = params;
2016
2016
  const prisma = this.core.getPrisma();
2017
- const { userId, traceId, ccId: ctxCcId } = this.core.getContext();
2017
+ const { userId, traceId, ccId: ctxCcId, module: module2 } = this.core.getContext();
2018
2018
  try {
2019
2019
  const config = await prisma.auditConfig.findFirst({
2020
2020
  where: {
2021
2021
  service,
2022
+ module: module2,
2022
2023
  method,
2023
2024
  isActive: true
2024
2025
  }
@@ -2026,12 +2027,13 @@ var AuditLogger = class {
2026
2027
  if (!config || !config.isAuditable) {
2027
2028
  return;
2028
2029
  }
2029
- const message = payload.message;
2030
+ const message = config.message;
2030
2031
  const type = payload.type ?? "INFO";
2031
2032
  const ccId = payload.ccId ?? ctxCcId ?? 0;
2032
2033
  await prisma.commonAudit.create({
2033
2034
  data: {
2034
2035
  service,
2036
+ module: module2,
2035
2037
  type,
2036
2038
  message,
2037
2039
  ccId,
@@ -2052,20 +2054,25 @@ var AuditProxy = class {
2052
2054
  constructor(logger) {
2053
2055
  this.logger = logger;
2054
2056
  }
2055
- /**
2056
- * Wraps a service object so that all its methods are auto-audited.
2057
- *
2058
- * Usage:
2059
- * const audited = auditProxy.createAuditedService("SellService", sellServiceRaw);
2060
- */
2061
2057
  createAuditedService(serviceName, service) {
2062
2058
  const logger = this.logger;
2059
+ const wrappedCache = /* @__PURE__ */ new Map();
2063
2060
  return new Proxy(service, {
2064
2061
  get(target, prop, receiver) {
2065
2062
  const original = Reflect.get(target, prop, receiver);
2066
2063
  if (typeof original !== "function") {
2067
2064
  return original;
2068
2065
  }
2066
+ const isOwn = Object.prototype.hasOwnProperty.call(target, prop);
2067
+ if (!isOwn) {
2068
+ return original;
2069
+ }
2070
+ if (prop === "constructor") {
2071
+ return original;
2072
+ }
2073
+ if (wrappedCache.has(prop)) {
2074
+ return wrappedCache.get(prop);
2075
+ }
2069
2076
  const methodName = String(prop);
2070
2077
  const wrapped = async (...args) => {
2071
2078
  let result;
@@ -2089,6 +2096,7 @@ var AuditProxy = class {
2089
2096
  });
2090
2097
  }
2091
2098
  };
2099
+ wrappedCache.set(prop, wrapped);
2092
2100
  return wrapped;
2093
2101
  }
2094
2102
  });
package/dist/index.mjs CHANGED
@@ -1965,11 +1965,12 @@ var AuditLogger = class {
1965
1965
  async logIfEnabled(params) {
1966
1966
  const { service, method, payload } = params;
1967
1967
  const prisma = this.core.getPrisma();
1968
- const { userId, traceId, ccId: ctxCcId } = this.core.getContext();
1968
+ const { userId, traceId, ccId: ctxCcId, module } = this.core.getContext();
1969
1969
  try {
1970
1970
  const config = await prisma.auditConfig.findFirst({
1971
1971
  where: {
1972
1972
  service,
1973
+ module,
1973
1974
  method,
1974
1975
  isActive: true
1975
1976
  }
@@ -1977,12 +1978,13 @@ var AuditLogger = class {
1977
1978
  if (!config || !config.isAuditable) {
1978
1979
  return;
1979
1980
  }
1980
- const message = payload.message;
1981
+ const message = config.message;
1981
1982
  const type = payload.type ?? "INFO";
1982
1983
  const ccId = payload.ccId ?? ctxCcId ?? 0;
1983
1984
  await prisma.commonAudit.create({
1984
1985
  data: {
1985
1986
  service,
1987
+ module,
1986
1988
  type,
1987
1989
  message,
1988
1990
  ccId,
@@ -2003,20 +2005,25 @@ var AuditProxy = class {
2003
2005
  constructor(logger) {
2004
2006
  this.logger = logger;
2005
2007
  }
2006
- /**
2007
- * Wraps a service object so that all its methods are auto-audited.
2008
- *
2009
- * Usage:
2010
- * const audited = auditProxy.createAuditedService("SellService", sellServiceRaw);
2011
- */
2012
2008
  createAuditedService(serviceName, service) {
2013
2009
  const logger = this.logger;
2010
+ const wrappedCache = /* @__PURE__ */ new Map();
2014
2011
  return new Proxy(service, {
2015
2012
  get(target, prop, receiver) {
2016
2013
  const original = Reflect.get(target, prop, receiver);
2017
2014
  if (typeof original !== "function") {
2018
2015
  return original;
2019
2016
  }
2017
+ const isOwn = Object.prototype.hasOwnProperty.call(target, prop);
2018
+ if (!isOwn) {
2019
+ return original;
2020
+ }
2021
+ if (prop === "constructor") {
2022
+ return original;
2023
+ }
2024
+ if (wrappedCache.has(prop)) {
2025
+ return wrappedCache.get(prop);
2026
+ }
2020
2027
  const methodName = String(prop);
2021
2028
  const wrapped = async (...args) => {
2022
2029
  let result;
@@ -2040,6 +2047,7 @@ var AuditProxy = class {
2040
2047
  });
2041
2048
  }
2042
2049
  };
2050
+ wrappedCache.set(prop, wrapped);
2043
2051
  return wrapped;
2044
2052
  }
2045
2053
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "av6-core",
3
- "version": "1.1.4",
3
+ "version": "1.1.6",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.mjs",
6
6
  "types": "dist/index.d.ts",