av6-core 1.1.3 → 1.1.5
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 +41 -1
- package/dist/index.d.ts +41 -1
- package/dist/index.js +121 -0
- package/dist/index.mjs +118 -0
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -389,4 +389,44 @@ declare class NotificationEmitter {
|
|
|
389
389
|
notifyNow(eventName: string, body: Omit<EmitPayload, "eventName">): Promise<void>;
|
|
390
390
|
}
|
|
391
391
|
|
|
392
|
-
|
|
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
|
+
createAuditedService<T extends object>(serviceName: string, service: T): T;
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
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
|
@@ -389,4 +389,44 @@ declare class NotificationEmitter {
|
|
|
389
389
|
notifyNow(eventName: string, body: Omit<EmitPayload, "eventName">): Promise<void>;
|
|
390
390
|
}
|
|
391
391
|
|
|
392
|
-
|
|
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
|
+
createAuditedService<T extends object>(serviceName: string, service: T): T;
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
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,
|
|
@@ -1982,8 +1985,126 @@ var NotificationEmitter = class {
|
|
|
1982
1985
|
await this.service.handleEvent({ ...body, eventName });
|
|
1983
1986
|
}
|
|
1984
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
|
+
createAuditedService(serviceName, service) {
|
|
2056
|
+
const logger = this.logger;
|
|
2057
|
+
const wrappedCache = /* @__PURE__ */ new Map();
|
|
2058
|
+
return new Proxy(service, {
|
|
2059
|
+
get(target, prop, receiver) {
|
|
2060
|
+
const original = Reflect.get(target, prop, receiver);
|
|
2061
|
+
if (typeof original !== "function") {
|
|
2062
|
+
return original;
|
|
2063
|
+
}
|
|
2064
|
+
const isOwn = Object.prototype.hasOwnProperty.call(target, prop);
|
|
2065
|
+
if (!isOwn) {
|
|
2066
|
+
return original;
|
|
2067
|
+
}
|
|
2068
|
+
if (prop === "constructor") {
|
|
2069
|
+
return original;
|
|
2070
|
+
}
|
|
2071
|
+
if (wrappedCache.has(prop)) {
|
|
2072
|
+
return wrappedCache.get(prop);
|
|
2073
|
+
}
|
|
2074
|
+
const methodName = String(prop);
|
|
2075
|
+
const wrapped = async (...args) => {
|
|
2076
|
+
let result;
|
|
2077
|
+
let error = null;
|
|
2078
|
+
try {
|
|
2079
|
+
result = await original.apply(target, args);
|
|
2080
|
+
return result;
|
|
2081
|
+
} catch (err) {
|
|
2082
|
+
error = err;
|
|
2083
|
+
throw err;
|
|
2084
|
+
} finally {
|
|
2085
|
+
const hasError = !!error;
|
|
2086
|
+
const message = hasError ? `Error in ${serviceName}.${methodName}` : `Executed ${serviceName}.${methodName}`;
|
|
2087
|
+
await logger.logIfEnabled({
|
|
2088
|
+
service: serviceName,
|
|
2089
|
+
method: methodName,
|
|
2090
|
+
payload: {
|
|
2091
|
+
message,
|
|
2092
|
+
type: hasError ? "ERROR" : "INFO"
|
|
2093
|
+
}
|
|
2094
|
+
});
|
|
2095
|
+
}
|
|
2096
|
+
};
|
|
2097
|
+
wrappedCache.set(prop, wrapped);
|
|
2098
|
+
return wrapped;
|
|
2099
|
+
}
|
|
2100
|
+
});
|
|
2101
|
+
}
|
|
2102
|
+
};
|
|
1985
2103
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1986
2104
|
0 && (module.exports = {
|
|
2105
|
+
AuditCore,
|
|
2106
|
+
AuditLogger,
|
|
2107
|
+
AuditProxy,
|
|
1987
2108
|
NotificationEmitter,
|
|
1988
2109
|
commonService,
|
|
1989
2110
|
customOmit,
|
package/dist/index.mjs
CHANGED
|
@@ -1936,7 +1936,125 @@ var NotificationEmitter = class {
|
|
|
1936
1936
|
await this.service.handleEvent({ ...body, eventName });
|
|
1937
1937
|
}
|
|
1938
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
|
+
createAuditedService(serviceName, service) {
|
|
2007
|
+
const logger = this.logger;
|
|
2008
|
+
const wrappedCache = /* @__PURE__ */ new Map();
|
|
2009
|
+
return new Proxy(service, {
|
|
2010
|
+
get(target, prop, receiver) {
|
|
2011
|
+
const original = Reflect.get(target, prop, receiver);
|
|
2012
|
+
if (typeof original !== "function") {
|
|
2013
|
+
return original;
|
|
2014
|
+
}
|
|
2015
|
+
const isOwn = Object.prototype.hasOwnProperty.call(target, prop);
|
|
2016
|
+
if (!isOwn) {
|
|
2017
|
+
return original;
|
|
2018
|
+
}
|
|
2019
|
+
if (prop === "constructor") {
|
|
2020
|
+
return original;
|
|
2021
|
+
}
|
|
2022
|
+
if (wrappedCache.has(prop)) {
|
|
2023
|
+
return wrappedCache.get(prop);
|
|
2024
|
+
}
|
|
2025
|
+
const methodName = String(prop);
|
|
2026
|
+
const wrapped = async (...args) => {
|
|
2027
|
+
let result;
|
|
2028
|
+
let error = null;
|
|
2029
|
+
try {
|
|
2030
|
+
result = await original.apply(target, args);
|
|
2031
|
+
return result;
|
|
2032
|
+
} catch (err) {
|
|
2033
|
+
error = err;
|
|
2034
|
+
throw err;
|
|
2035
|
+
} finally {
|
|
2036
|
+
const hasError = !!error;
|
|
2037
|
+
const message = hasError ? `Error in ${serviceName}.${methodName}` : `Executed ${serviceName}.${methodName}`;
|
|
2038
|
+
await logger.logIfEnabled({
|
|
2039
|
+
service: serviceName,
|
|
2040
|
+
method: methodName,
|
|
2041
|
+
payload: {
|
|
2042
|
+
message,
|
|
2043
|
+
type: hasError ? "ERROR" : "INFO"
|
|
2044
|
+
}
|
|
2045
|
+
});
|
|
2046
|
+
}
|
|
2047
|
+
};
|
|
2048
|
+
wrappedCache.set(prop, wrapped);
|
|
2049
|
+
return wrapped;
|
|
2050
|
+
}
|
|
2051
|
+
});
|
|
2052
|
+
}
|
|
2053
|
+
};
|
|
1939
2054
|
export {
|
|
2055
|
+
AuditCore,
|
|
2056
|
+
AuditLogger,
|
|
2057
|
+
AuditProxy,
|
|
1940
2058
|
NotificationEmitter,
|
|
1941
2059
|
commonService,
|
|
1942
2060
|
customOmit,
|