av6-core 1.1.2 → 1.1.4

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
@@ -347,6 +347,7 @@ declare const uinConfigService: (uinDeps: UinDeps) => {
347
347
 
348
348
  declare const toUINConfigDTO: (model: any) => UINConfigDTO;
349
349
 
350
+ type Priority = "high" | "normal" | "low";
350
351
  type Recipient = {
351
352
  email?: string;
352
353
  phone?: string;
@@ -359,6 +360,7 @@ type EmitPayload = {
359
360
  recipient: Recipient;
360
361
  data?: Record<string, any>;
361
362
  dataWp?: any[];
363
+ priority?: Priority;
362
364
  };
363
365
  type ILogger = winston.Logger | Console;
364
366
  type NotificationEmitterDeps = {
@@ -387,4 +389,50 @@ declare class NotificationEmitter {
387
389
  notifyNow(eventName: string, body: Omit<EmitPayload, "eventName">): Promise<void>;
388
390
  }
389
391
 
390
- export { type CacheAdapter, type CalculationRes, type ColValue, type CommonExcelRequest, type CommonFilterRequest, type CommonServiceResponse, type Config, type Context, type CreateUINConfigRequest, type DataType, type DeleteParams, type DeleteRequestRepository, type Deps, type DropdownRequest, type DropdownRequestService, type DynamicShortCode, type EmitPayload, type ExcelConfig, type ExportExcel, type ExportExcelRequestService, type FetchRequest, type FetchRequestRepository, type FixedSearchRequest, type FixedSearchRequestService, type Helpers, type ImportExcel, type ImportExcelRequestService, type Mapper, type NewFixedSearchRequest, type NewFixedSearchRequestService, type NewSearchRequest, NotificationEmitter, type PaginatedResponse, type Recipient, type SearchRequest, type SearchRequestService, type ServiceCacheAdapter, type Store, type ToggleActive, type UINConfigDTO, type UINPreviewRequest, type UINSegment, type UINSegmentType, type UIN_RESET_POLICY, type UinDeps, type UpdateStatusRequestRepository, type UpdateUINConfigRequest, type ValidationErrorItem, commonService, customOmit, findDifferences, getDynamicValue, getPattern, interpolate, objectTo2DArray, toNumberOrNull, toUINConfigDTO, uinConfigService, type updateStatusParams };
392
+ interface AuditContext {
393
+ userId: number | null;
394
+ traceId: string | null;
395
+ ccId: number | null;
396
+ }
397
+ type AuditContextProvider = () => AuditContext;
398
+ interface AuditLogPayload {
399
+ message: string;
400
+ type?: "INFO" | "CREATE" | "UPDATE" | "DELETE" | "ERROR";
401
+ ccId?: number | null;
402
+ extra?: Record<string, any>;
403
+ }
404
+
405
+ declare class AuditCore {
406
+ private prisma;
407
+ private contextProvider;
408
+ constructor(prisma: PrismaClient, contextProvider: AuditContextProvider);
409
+ getPrisma(): PrismaClient;
410
+ getContext(): AuditContext;
411
+ }
412
+
413
+ declare class AuditLogger {
414
+ private core;
415
+ constructor(core: AuditCore);
416
+ /**
417
+ * Check core_audit_config and, if auditable, insert into core_common_audit
418
+ */
419
+ logIfEnabled(params: {
420
+ service: string;
421
+ method: string;
422
+ payload: AuditLogPayload;
423
+ }): Promise<void>;
424
+ }
425
+
426
+ declare class AuditProxy {
427
+ private logger;
428
+ 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
+ createAuditedService<T extends object>(serviceName: string, service: T): T;
436
+ }
437
+
438
+ export { type AuditContext, type AuditContextProvider, AuditCore, type AuditLogPayload, AuditLogger, AuditProxy, type CacheAdapter, type CalculationRes, type ColValue, type CommonExcelRequest, type CommonFilterRequest, type CommonServiceResponse, type Config, type Context, type CreateUINConfigRequest, type DataType, type DeleteParams, type DeleteRequestRepository, type Deps, type DropdownRequest, type DropdownRequestService, type DynamicShortCode, type EmitPayload, type ExcelConfig, type ExportExcel, type ExportExcelRequestService, type FetchRequest, type FetchRequestRepository, type FixedSearchRequest, type FixedSearchRequestService, type Helpers, type ImportExcel, type ImportExcelRequestService, type Mapper, type NewFixedSearchRequest, type NewFixedSearchRequestService, type NewSearchRequest, NotificationEmitter, type PaginatedResponse, type Recipient, type SearchRequest, type SearchRequestService, type ServiceCacheAdapter, type Store, type ToggleActive, type UINConfigDTO, type UINPreviewRequest, type UINSegment, type UINSegmentType, type UIN_RESET_POLICY, type UinDeps, type UpdateStatusRequestRepository, type UpdateUINConfigRequest, type ValidationErrorItem, commonService, customOmit, findDifferences, getDynamicValue, getPattern, interpolate, objectTo2DArray, toNumberOrNull, toUINConfigDTO, uinConfigService, type updateStatusParams };
package/dist/index.d.ts CHANGED
@@ -347,6 +347,7 @@ declare const uinConfigService: (uinDeps: UinDeps) => {
347
347
 
348
348
  declare const toUINConfigDTO: (model: any) => UINConfigDTO;
349
349
 
350
+ type Priority = "high" | "normal" | "low";
350
351
  type Recipient = {
351
352
  email?: string;
352
353
  phone?: string;
@@ -359,6 +360,7 @@ type EmitPayload = {
359
360
  recipient: Recipient;
360
361
  data?: Record<string, any>;
361
362
  dataWp?: any[];
363
+ priority?: Priority;
362
364
  };
363
365
  type ILogger = winston.Logger | Console;
364
366
  type NotificationEmitterDeps = {
@@ -387,4 +389,50 @@ declare class NotificationEmitter {
387
389
  notifyNow(eventName: string, body: Omit<EmitPayload, "eventName">): Promise<void>;
388
390
  }
389
391
 
390
- export { type CacheAdapter, type CalculationRes, type ColValue, type CommonExcelRequest, type CommonFilterRequest, type CommonServiceResponse, type Config, type Context, type CreateUINConfigRequest, type DataType, type DeleteParams, type DeleteRequestRepository, type Deps, type DropdownRequest, type DropdownRequestService, type DynamicShortCode, type EmitPayload, type ExcelConfig, type ExportExcel, type ExportExcelRequestService, type FetchRequest, type FetchRequestRepository, type FixedSearchRequest, type FixedSearchRequestService, type Helpers, type ImportExcel, type ImportExcelRequestService, type Mapper, type NewFixedSearchRequest, type NewFixedSearchRequestService, type NewSearchRequest, NotificationEmitter, type PaginatedResponse, type Recipient, type SearchRequest, type SearchRequestService, type ServiceCacheAdapter, type Store, type ToggleActive, type UINConfigDTO, type UINPreviewRequest, type UINSegment, type UINSegmentType, type UIN_RESET_POLICY, type UinDeps, type UpdateStatusRequestRepository, type UpdateUINConfigRequest, type ValidationErrorItem, commonService, customOmit, findDifferences, getDynamicValue, getPattern, interpolate, objectTo2DArray, toNumberOrNull, toUINConfigDTO, uinConfigService, type updateStatusParams };
392
+ interface AuditContext {
393
+ userId: number | null;
394
+ traceId: string | null;
395
+ ccId: number | null;
396
+ }
397
+ type AuditContextProvider = () => AuditContext;
398
+ interface AuditLogPayload {
399
+ message: string;
400
+ type?: "INFO" | "CREATE" | "UPDATE" | "DELETE" | "ERROR";
401
+ ccId?: number | null;
402
+ extra?: Record<string, any>;
403
+ }
404
+
405
+ declare class AuditCore {
406
+ private prisma;
407
+ private contextProvider;
408
+ constructor(prisma: PrismaClient, contextProvider: AuditContextProvider);
409
+ getPrisma(): PrismaClient;
410
+ getContext(): AuditContext;
411
+ }
412
+
413
+ declare class AuditLogger {
414
+ private core;
415
+ constructor(core: AuditCore);
416
+ /**
417
+ * Check core_audit_config and, if auditable, insert into core_common_audit
418
+ */
419
+ logIfEnabled(params: {
420
+ service: string;
421
+ method: string;
422
+ payload: AuditLogPayload;
423
+ }): Promise<void>;
424
+ }
425
+
426
+ declare class AuditProxy {
427
+ private logger;
428
+ 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
+ createAuditedService<T extends object>(serviceName: string, service: T): T;
436
+ }
437
+
438
+ export { type AuditContext, type AuditContextProvider, AuditCore, type AuditLogPayload, AuditLogger, AuditProxy, type CacheAdapter, type CalculationRes, type ColValue, type CommonExcelRequest, type CommonFilterRequest, type CommonServiceResponse, type Config, type Context, type CreateUINConfigRequest, type DataType, type DeleteParams, type DeleteRequestRepository, type Deps, type DropdownRequest, type DropdownRequestService, type DynamicShortCode, type EmitPayload, type ExcelConfig, type ExportExcel, type ExportExcelRequestService, type FetchRequest, type FetchRequestRepository, type FixedSearchRequest, type FixedSearchRequestService, type Helpers, type ImportExcel, type ImportExcelRequestService, type Mapper, type NewFixedSearchRequest, type NewFixedSearchRequestService, type NewSearchRequest, NotificationEmitter, type PaginatedResponse, type Recipient, type SearchRequest, type SearchRequestService, type ServiceCacheAdapter, type Store, type ToggleActive, type UINConfigDTO, type UINPreviewRequest, type UINSegment, type UINSegmentType, type UIN_RESET_POLICY, type UinDeps, type UpdateStatusRequestRepository, type UpdateUINConfigRequest, type ValidationErrorItem, commonService, customOmit, findDifferences, getDynamicValue, getPattern, interpolate, objectTo2DArray, toNumberOrNull, toUINConfigDTO, uinConfigService, type updateStatusParams };
package/dist/index.js CHANGED
@@ -30,6 +30,9 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/index.ts
31
31
  var index_exports = {};
32
32
  __export(index_exports, {
33
+ AuditCore: () => AuditCore,
34
+ AuditLogger: () => AuditLogger,
35
+ AuditProxy: () => AuditProxy,
33
36
  NotificationEmitter: () => NotificationEmitter,
34
37
  commonService: () => commonService,
35
38
  customOmit: () => customOmit,
@@ -1507,7 +1510,8 @@ var EmailProvider = class {
1507
1510
  body,
1508
1511
  recipient,
1509
1512
  subject,
1510
- attachments = []
1513
+ attachments = [],
1514
+ priority = "normal"
1511
1515
  }) {
1512
1516
  if (!recipient.email) {
1513
1517
  return {
@@ -1546,8 +1550,9 @@ var EmailProvider = class {
1546
1550
  subject,
1547
1551
  html: body,
1548
1552
  // The interpolated HTML body
1549
- attachments
1553
+ attachments,
1550
1554
  // Optional attachments
1555
+ priority
1551
1556
  });
1552
1557
  this.logger.info(`Email sent to ${recipient.email} with subject: ${subject}`);
1553
1558
  return {
@@ -1829,7 +1834,8 @@ var NotificationService = class {
1829
1834
  eventConfigId: cfg.id,
1830
1835
  evt,
1831
1836
  subject: msg.subject,
1832
- body: msg.body
1837
+ body: msg.body,
1838
+ priority: evt.priority
1833
1839
  })
1834
1840
  );
1835
1841
  }
@@ -1882,7 +1888,8 @@ var NotificationService = class {
1882
1888
  const result = await args.provider.send({
1883
1889
  subject: args.subject,
1884
1890
  body: args.body,
1885
- recipient: args.evt.recipient
1891
+ recipient: args.evt.recipient,
1892
+ priority: args.priority
1886
1893
  });
1887
1894
  await this.prisma.eventNotificationAudit.create({
1888
1895
  data: {
@@ -1978,8 +1985,120 @@ var NotificationEmitter = class {
1978
1985
  await this.service.handleEvent({ ...body, eventName });
1979
1986
  }
1980
1987
  };
1988
+
1989
+ // src/audit/audit.core.ts
1990
+ var AuditCore = class {
1991
+ prisma;
1992
+ contextProvider;
1993
+ constructor(prisma, contextProvider) {
1994
+ this.prisma = prisma;
1995
+ this.contextProvider = contextProvider;
1996
+ }
1997
+ getPrisma() {
1998
+ return this.prisma;
1999
+ }
2000
+ getContext() {
2001
+ return this.contextProvider();
2002
+ }
2003
+ };
2004
+
2005
+ // src/audit/audit.logger.ts
2006
+ var AuditLogger = class {
2007
+ core;
2008
+ constructor(core) {
2009
+ this.core = core;
2010
+ }
2011
+ /**
2012
+ * Check core_audit_config and, if auditable, insert into core_common_audit
2013
+ */
2014
+ async logIfEnabled(params) {
2015
+ const { service, method, payload } = params;
2016
+ const prisma = this.core.getPrisma();
2017
+ const { userId, traceId, ccId: ctxCcId } = this.core.getContext();
2018
+ try {
2019
+ const config = await prisma.auditConfig.findFirst({
2020
+ where: {
2021
+ service,
2022
+ method,
2023
+ isActive: true
2024
+ }
2025
+ });
2026
+ if (!config || !config.isAuditable) {
2027
+ return;
2028
+ }
2029
+ const message = payload.message;
2030
+ const type = payload.type ?? "INFO";
2031
+ const ccId = payload.ccId ?? ctxCcId ?? 0;
2032
+ await prisma.commonAudit.create({
2033
+ data: {
2034
+ service,
2035
+ type,
2036
+ message,
2037
+ ccId,
2038
+ methodName: method,
2039
+ traceId,
2040
+ createdBy: userId ?? void 0
2041
+ }
2042
+ });
2043
+ } catch (err) {
2044
+ console.error("[AuditLogger] Failed to write audit:", err);
2045
+ }
2046
+ }
2047
+ };
2048
+
2049
+ // src/audit/audit.proxy.ts
2050
+ var AuditProxy = class {
2051
+ logger;
2052
+ constructor(logger) {
2053
+ this.logger = logger;
2054
+ }
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
+ createAuditedService(serviceName, service) {
2062
+ const logger = this.logger;
2063
+ return new Proxy(service, {
2064
+ get(target, prop, receiver) {
2065
+ const original = Reflect.get(target, prop, receiver);
2066
+ if (typeof original !== "function") {
2067
+ return original;
2068
+ }
2069
+ const methodName = String(prop);
2070
+ const wrapped = async (...args) => {
2071
+ let result;
2072
+ let error = null;
2073
+ try {
2074
+ result = await original.apply(target, args);
2075
+ return result;
2076
+ } catch (err) {
2077
+ error = err;
2078
+ throw err;
2079
+ } finally {
2080
+ const hasError = !!error;
2081
+ const message = hasError ? `Error in ${serviceName}.${methodName}` : `Executed ${serviceName}.${methodName}`;
2082
+ await logger.logIfEnabled({
2083
+ service: serviceName,
2084
+ method: methodName,
2085
+ payload: {
2086
+ message,
2087
+ type: hasError ? "ERROR" : "INFO"
2088
+ }
2089
+ });
2090
+ }
2091
+ };
2092
+ return wrapped;
2093
+ }
2094
+ });
2095
+ }
2096
+ };
1981
2097
  // Annotate the CommonJS export names for ESM import in node:
1982
2098
  0 && (module.exports = {
2099
+ AuditCore,
2100
+ AuditLogger,
2101
+ AuditProxy,
1983
2102
  NotificationEmitter,
1984
2103
  commonService,
1985
2104
  customOmit,
package/dist/index.mjs CHANGED
@@ -1461,7 +1461,8 @@ var EmailProvider = class {
1461
1461
  body,
1462
1462
  recipient,
1463
1463
  subject,
1464
- attachments = []
1464
+ attachments = [],
1465
+ priority = "normal"
1465
1466
  }) {
1466
1467
  if (!recipient.email) {
1467
1468
  return {
@@ -1500,8 +1501,9 @@ var EmailProvider = class {
1500
1501
  subject,
1501
1502
  html: body,
1502
1503
  // The interpolated HTML body
1503
- attachments
1504
+ attachments,
1504
1505
  // Optional attachments
1506
+ priority
1505
1507
  });
1506
1508
  this.logger.info(`Email sent to ${recipient.email} with subject: ${subject}`);
1507
1509
  return {
@@ -1783,7 +1785,8 @@ var NotificationService = class {
1783
1785
  eventConfigId: cfg.id,
1784
1786
  evt,
1785
1787
  subject: msg.subject,
1786
- body: msg.body
1788
+ body: msg.body,
1789
+ priority: evt.priority
1787
1790
  })
1788
1791
  );
1789
1792
  }
@@ -1836,7 +1839,8 @@ var NotificationService = class {
1836
1839
  const result = await args.provider.send({
1837
1840
  subject: args.subject,
1838
1841
  body: args.body,
1839
- recipient: args.evt.recipient
1842
+ recipient: args.evt.recipient,
1843
+ priority: args.priority
1840
1844
  });
1841
1845
  await this.prisma.eventNotificationAudit.create({
1842
1846
  data: {
@@ -1932,7 +1936,119 @@ var NotificationEmitter = class {
1932
1936
  await this.service.handleEvent({ ...body, eventName });
1933
1937
  }
1934
1938
  };
1939
+
1940
+ // src/audit/audit.core.ts
1941
+ var AuditCore = class {
1942
+ prisma;
1943
+ contextProvider;
1944
+ constructor(prisma, contextProvider) {
1945
+ this.prisma = prisma;
1946
+ this.contextProvider = contextProvider;
1947
+ }
1948
+ getPrisma() {
1949
+ return this.prisma;
1950
+ }
1951
+ getContext() {
1952
+ return this.contextProvider();
1953
+ }
1954
+ };
1955
+
1956
+ // src/audit/audit.logger.ts
1957
+ var AuditLogger = class {
1958
+ core;
1959
+ constructor(core) {
1960
+ this.core = core;
1961
+ }
1962
+ /**
1963
+ * Check core_audit_config and, if auditable, insert into core_common_audit
1964
+ */
1965
+ async logIfEnabled(params) {
1966
+ const { service, method, payload } = params;
1967
+ const prisma = this.core.getPrisma();
1968
+ const { userId, traceId, ccId: ctxCcId } = this.core.getContext();
1969
+ try {
1970
+ const config = await prisma.auditConfig.findFirst({
1971
+ where: {
1972
+ service,
1973
+ method,
1974
+ isActive: true
1975
+ }
1976
+ });
1977
+ if (!config || !config.isAuditable) {
1978
+ return;
1979
+ }
1980
+ const message = payload.message;
1981
+ const type = payload.type ?? "INFO";
1982
+ const ccId = payload.ccId ?? ctxCcId ?? 0;
1983
+ await prisma.commonAudit.create({
1984
+ data: {
1985
+ service,
1986
+ type,
1987
+ message,
1988
+ ccId,
1989
+ methodName: method,
1990
+ traceId,
1991
+ createdBy: userId ?? void 0
1992
+ }
1993
+ });
1994
+ } catch (err) {
1995
+ console.error("[AuditLogger] Failed to write audit:", err);
1996
+ }
1997
+ }
1998
+ };
1999
+
2000
+ // src/audit/audit.proxy.ts
2001
+ var AuditProxy = class {
2002
+ logger;
2003
+ constructor(logger) {
2004
+ this.logger = logger;
2005
+ }
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
+ createAuditedService(serviceName, service) {
2013
+ const logger = this.logger;
2014
+ return new Proxy(service, {
2015
+ get(target, prop, receiver) {
2016
+ const original = Reflect.get(target, prop, receiver);
2017
+ if (typeof original !== "function") {
2018
+ return original;
2019
+ }
2020
+ const methodName = String(prop);
2021
+ const wrapped = async (...args) => {
2022
+ let result;
2023
+ let error = null;
2024
+ try {
2025
+ result = await original.apply(target, args);
2026
+ return result;
2027
+ } catch (err) {
2028
+ error = err;
2029
+ throw err;
2030
+ } finally {
2031
+ const hasError = !!error;
2032
+ const message = hasError ? `Error in ${serviceName}.${methodName}` : `Executed ${serviceName}.${methodName}`;
2033
+ await logger.logIfEnabled({
2034
+ service: serviceName,
2035
+ method: methodName,
2036
+ payload: {
2037
+ message,
2038
+ type: hasError ? "ERROR" : "INFO"
2039
+ }
2040
+ });
2041
+ }
2042
+ };
2043
+ return wrapped;
2044
+ }
2045
+ });
2046
+ }
2047
+ };
1935
2048
  export {
2049
+ AuditCore,
2050
+ AuditLogger,
2051
+ AuditProxy,
1936
2052
  NotificationEmitter,
1937
2053
  commonService,
1938
2054
  customOmit,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "av6-core",
3
- "version": "1.1.2",
3
+ "version": "1.1.4",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.mjs",
6
6
  "types": "dist/index.d.ts",