@jaypie/testkit 1.1.33 → 1.1.35

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.
@@ -350,7 +350,7 @@ beforeAll(async () => {
350
350
  const cloneDeep = createMockWrappedFunction(original$1.cloneDeep, {
351
351
  throws: true,
352
352
  });
353
- const envBoolean = createMockReturnedFunction(true);
353
+ const envBoolean$1 = createMockReturnedFunction(true);
354
354
  const envsKey = createMockWrappedFunction(original$1.envsKey, `_MOCK_ENVS_KEY_[${TAG$2}]`);
355
355
  const errorFromStatusCode = createMockFunction((statusCode, message = `Mock error for status code ${statusCode}`) => {
356
356
  try {
@@ -462,7 +462,7 @@ const jaypieHandler = createMockFunction((handler, options = {}) => {
462
462
  });
463
463
  const sleep = createMockResolvedFunction(true);
464
464
  const uuid = createMockWrappedFunction(original$1.uuid, `00000000-0000-0000-0000-000000000000`);
465
- const ERROR = original$1.ERROR;
465
+ const ERROR$1 = original$1.ERROR;
466
466
  const HTTP$1 = original$1.HTTP;
467
467
  const JAYPIE = original$1.JAYPIE;
468
468
  const PROJECT = original$1.PROJECT;
@@ -473,7 +473,7 @@ var core = /*#__PURE__*/Object.freeze({
473
473
  BadGatewayError: BadGatewayError,
474
474
  BadRequestError: BadRequestError,
475
475
  ConfigurationError: ConfigurationError,
476
- ERROR: ERROR,
476
+ ERROR: ERROR$1,
477
477
  ForbiddenError: ForbiddenError,
478
478
  GatewayTimeoutError: GatewayTimeoutError,
479
479
  GoneError: GoneError,
@@ -496,7 +496,7 @@ var core = /*#__PURE__*/Object.freeze({
496
496
  UnreachableCodeError: UnreachableCodeError,
497
497
  VALIDATE: VALIDATE,
498
498
  cloneDeep: cloneDeep,
499
- envBoolean: envBoolean,
499
+ envBoolean: envBoolean$1,
500
500
  envsKey: envsKey,
501
501
  errorFromStatusCode: errorFromStatusCode,
502
502
  force: force,
@@ -580,7 +580,6 @@ const expressHandler = createMockFunction((handlerOrProps, propsOrHandler) => {
580
580
  if (!props.setup)
581
581
  props.setup = [];
582
582
  props.setup = force.array(props.setup);
583
- // @ts-expect-error TODO: cannot resolve; fix when JaypieHandler moves to TypeScript
584
583
  props.setup.unshift((req) => {
585
584
  if (!req || typeof req !== "object") {
586
585
  throw new BadRequestError$1("req must be an object");
@@ -635,9 +634,9 @@ const expressHandler = createMockFunction((handlerOrProps, propsOrHandler) => {
635
634
  // In the mock context, if status is a function we are in a "supertest"
636
635
  if (supertestMode && typeof res.status === "function") {
637
636
  // In theory jaypieFunction has handled all errors
638
- const errorStatus = error.status || HTTP.CODE.INTERNAL_ERROR;
637
+ const errorStatus = error?.status || HTTP.CODE.INTERNAL_ERROR;
639
638
  let errorResponse;
640
- if (typeof error.json === "function") {
639
+ if (typeof error?.json === "function") {
641
640
  errorResponse = error.json();
642
641
  }
643
642
  else {
@@ -703,6 +702,15 @@ var express = /*#__PURE__*/Object.freeze({
703
702
  notImplementedRoute: notImplementedRoute
704
703
  });
705
704
 
705
+ const isProductionEnv = createMockReturnedFunction(false);
706
+ const isNodeTestEnv = createMockReturnedFunction(true);
707
+
708
+ var kit = /*#__PURE__*/Object.freeze({
709
+ __proto__: null,
710
+ isNodeTestEnv: isNodeTestEnv,
711
+ isProductionEnv: isProductionEnv
712
+ });
713
+
706
714
  // Mock implementation of lambdaHandler that follows the original implementation pattern
707
715
  const lambdaHandler = createMockFunction((handler, props = {}) => {
708
716
  // If handler is an object and options is a function, swap them
@@ -798,6 +806,12 @@ const Toolkit = createMockWrappedObject(original$4.Toolkit, {
798
806
  const JaypieToolkit = createMockWrappedObject(original$4.JaypieToolkit, {
799
807
  isClass: true,
800
808
  });
809
+ const LlmMessageRole = createMockWrappedObject(original$4.LlmMessageRole, {
810
+ isClass: true,
811
+ });
812
+ const LlmMessageType = createMockWrappedObject(original$4.LlmMessageType, {
813
+ isClass: true,
814
+ });
801
815
  // Tool collections
802
816
  const toolkit = new original$4.JaypieToolkit([
803
817
  random,
@@ -812,11 +826,630 @@ var llm = /*#__PURE__*/Object.freeze({
812
826
  JaypieToolkit: JaypieToolkit,
813
827
  LLM: LLM,
814
828
  Llm: Llm,
829
+ LlmMessageRole: LlmMessageRole,
830
+ LlmMessageType: LlmMessageType,
815
831
  Toolkit: Toolkit,
816
832
  toolkit: toolkit,
817
833
  tools: tools
818
834
  });
819
835
 
836
+ const DEFAULT = {
837
+ LEVEL: "debug",
838
+ VAR_LEVEL: "debug",
839
+ };
840
+ const ERROR_PREFIX = "[logger]";
841
+ const ERROR = {
842
+ VAR: {
843
+ EMPTY_OBJECT: `${ERROR_PREFIX} Logger.var() called with empty object`,
844
+ MULTIPLE_KEYS: `${ERROR_PREFIX} Logger.var() called with multiple keys`,
845
+ NULL_OBJECT: `${ERROR_PREFIX} Logger.var() called with null`,
846
+ UNDEFINED_MESSAGE: `${ERROR_PREFIX} Logger.var() called with \`undefined\` message`,
847
+ },
848
+ };
849
+ const FORMAT = {
850
+ JSON: "json",
851
+ TEXT: "text",
852
+ };
853
+ const LEVEL = {
854
+ ALL: "all",
855
+ DEBUG: "debug",
856
+ ERROR: "error",
857
+ FATAL: "fatal",
858
+ INFO: "info",
859
+ SILENT: "silent",
860
+ TRACE: "trace",
861
+ WARN: "warn",
862
+ };
863
+ const LEVEL_VALUES = {
864
+ all: 100,
865
+ debug: 70,
866
+ error: 10,
867
+ fatal: 1,
868
+ info: 50,
869
+ none: 0,
870
+ silent: 0,
871
+ trace: 90,
872
+ warn: 30,
873
+ };
874
+
875
+ function forceString(value, defaultValue = "") {
876
+ if (value === null)
877
+ return "null";
878
+ if (value === undefined)
879
+ return String(defaultValue);
880
+ if (typeof value === "object")
881
+ return JSON.stringify(value);
882
+ return String(value);
883
+ }
884
+ function formatAsJsonString(subject) {
885
+ const SPACES = 0;
886
+ const UNUSED_PARAM = null;
887
+ switch (typeof subject) {
888
+ case "string":
889
+ if (subject === "")
890
+ return `""`;
891
+ try {
892
+ return JSON.stringify(JSON.parse(subject), UNUSED_PARAM, SPACES);
893
+ }
894
+ catch {
895
+ return subject;
896
+ }
897
+ case "object":
898
+ try {
899
+ if (subject &&
900
+ subject instanceof Object &&
901
+ !Array.isArray(subject) &&
902
+ subject.constructor &&
903
+ subject.constructor !== Object &&
904
+ "toString" in subject &&
905
+ typeof subject.toString === "function") {
906
+ return subject.toString();
907
+ }
908
+ return JSON.stringify(subject, UNUSED_PARAM, SPACES);
909
+ }
910
+ catch (error) {
911
+ if (error instanceof TypeError) {
912
+ const truncatedSubject = Object.keys(subject).reduce((newSubject, key) => {
913
+ const nextSubject = { ...newSubject };
914
+ nextSubject[key] = String(subject[key]);
915
+ return nextSubject;
916
+ }, {});
917
+ return formatAsJsonString(truncatedSubject);
918
+ }
919
+ throw error;
920
+ }
921
+ default:
922
+ return String(subject);
923
+ }
924
+ }
925
+ function stringify(...params) {
926
+ if (params.length === 0)
927
+ return "";
928
+ if (params.length === 1) {
929
+ return formatAsJsonString(params[0]);
930
+ }
931
+ const noObjects = params.reduce((previous, current) => {
932
+ if (typeof current === "object" && current !== null) {
933
+ return false;
934
+ }
935
+ return previous;
936
+ }, true);
937
+ if (noObjects) {
938
+ const formatted = params.map(formatAsJsonString);
939
+ return formatted.join(" ");
940
+ }
941
+ return formatAsJsonString(params);
942
+ }
943
+ function out(line, { level = "debug" } = {}) {
944
+ let lineStr;
945
+ if (typeof line !== "string") {
946
+ lineStr = stringify(line);
947
+ }
948
+ else {
949
+ lineStr = line;
950
+ }
951
+ let outputFunction;
952
+ switch (level) {
953
+ case LEVEL.INFO:
954
+ outputFunction = console.info;
955
+ break;
956
+ case LEVEL.WARN:
957
+ outputFunction = console.warn;
958
+ break;
959
+ case LEVEL.ERROR:
960
+ case LEVEL.FATAL:
961
+ outputFunction = console.error;
962
+ break;
963
+ case LEVEL.TRACE:
964
+ case LEVEL.DEBUG:
965
+ outputFunction = console.debug;
966
+ break;
967
+ default:
968
+ outputFunction = console.log;
969
+ break;
970
+ }
971
+ try {
972
+ outputFunction(lineStr);
973
+ }
974
+ catch (error) {
975
+ console.warn(error);
976
+ console.log(lineStr);
977
+ }
978
+ }
979
+ function parse(message) {
980
+ if (typeof message !== "string") {
981
+ return message;
982
+ }
983
+ try {
984
+ return JSON.parse(message);
985
+ }
986
+ catch {
987
+ return message;
988
+ }
989
+ }
990
+ function parsesTo(message) {
991
+ if (typeof message !== "string") {
992
+ return {
993
+ parses: false,
994
+ message,
995
+ };
996
+ }
997
+ try {
998
+ return {
999
+ parses: true,
1000
+ message: JSON.parse(message),
1001
+ };
1002
+ }
1003
+ catch {
1004
+ return {
1005
+ parses: false,
1006
+ message,
1007
+ };
1008
+ }
1009
+ }
1010
+
1011
+ class Logger {
1012
+ constructor({ format = process.env.LOG_FORMAT || DEFAULT.LEVEL, level = process.env.LOG_LEVEL || DEFAULT.LEVEL, tags = {}, varLevel = process.env.LOG_VAR_LEVEL || DEFAULT.VAR_LEVEL, } = {}) {
1013
+ this.options = {
1014
+ format,
1015
+ level,
1016
+ varLevel,
1017
+ };
1018
+ this.tags = {};
1019
+ Object.keys(tags).forEach((key) => {
1020
+ this.tags[key] = forceString(tags[key]);
1021
+ });
1022
+ this.debug = this.createLogMethod(LEVEL.DEBUG, format, level);
1023
+ this.error = this.createLogMethod(LEVEL.ERROR, format, level);
1024
+ this.fatal = this.createLogMethod(LEVEL.FATAL, format, level);
1025
+ this.info = this.createLogMethod(LEVEL.INFO, format, level);
1026
+ this.trace = this.createLogMethod(LEVEL.TRACE, format, level);
1027
+ this.warn = this.createLogMethod(LEVEL.WARN, format, level);
1028
+ const varLevelMethod = this[varLevel];
1029
+ this.var = varLevelMethod?.var || this.debug.var;
1030
+ }
1031
+ createLogMethod(logLevel, format, checkLevel) {
1032
+ const logFn = (...messages) => {
1033
+ if (LEVEL_VALUES[logLevel] <= LEVEL_VALUES[checkLevel]) {
1034
+ if (format === FORMAT.JSON) {
1035
+ const message = stringify(...messages);
1036
+ const parses = parsesTo(message);
1037
+ const json = {
1038
+ log: logLevel,
1039
+ message,
1040
+ ...this.tags,
1041
+ };
1042
+ if (parses.parses) {
1043
+ json.data = parses.message;
1044
+ }
1045
+ out(json, { level: logLevel });
1046
+ }
1047
+ else {
1048
+ const message = stringify(...messages);
1049
+ out(message, { level: logLevel });
1050
+ }
1051
+ }
1052
+ };
1053
+ logFn.var = (messageObject, messageValue) => {
1054
+ if (messageObject === undefined) {
1055
+ this.warn(ERROR.VAR.UNDEFINED_MESSAGE);
1056
+ }
1057
+ let msgObj;
1058
+ if (typeof messageObject !== "object" || messageObject === null) {
1059
+ if (typeof messageObject !== "object") {
1060
+ if (messageValue === undefined)
1061
+ messageValue = "undefined";
1062
+ msgObj = { [String(messageObject)]: messageValue };
1063
+ }
1064
+ else {
1065
+ this.warn(ERROR.VAR.NULL_OBJECT);
1066
+ return logFn(messageObject);
1067
+ }
1068
+ }
1069
+ else {
1070
+ msgObj = messageObject;
1071
+ }
1072
+ const keys = Object.keys(msgObj);
1073
+ if (keys.length === 0) {
1074
+ this.warn(ERROR.VAR.EMPTY_OBJECT);
1075
+ return logFn(msgObj);
1076
+ }
1077
+ if (keys.length > 1) {
1078
+ this.warn(ERROR.VAR.MULTIPLE_KEYS);
1079
+ return logFn(msgObj);
1080
+ }
1081
+ if (format === FORMAT.JSON) {
1082
+ const messageKey = keys[0];
1083
+ const messageVal = msgObj[messageKey];
1084
+ const json = {
1085
+ data: parse(messageVal),
1086
+ dataType: typeof messageVal,
1087
+ log: logLevel,
1088
+ message: stringify(messageVal),
1089
+ var: messageKey,
1090
+ ...this.tags,
1091
+ };
1092
+ if (LEVEL_VALUES[logLevel] <= LEVEL_VALUES[checkLevel]) {
1093
+ out(json, { level: logLevel });
1094
+ }
1095
+ }
1096
+ else {
1097
+ return logFn(msgObj);
1098
+ }
1099
+ };
1100
+ return logFn;
1101
+ }
1102
+ tag(key, value) {
1103
+ if (value) {
1104
+ this.tags[forceString(key)] = forceString(value);
1105
+ return;
1106
+ }
1107
+ if (Array.isArray(key)) {
1108
+ key.forEach((k) => {
1109
+ this.tags[forceString(k)] = "";
1110
+ });
1111
+ return;
1112
+ }
1113
+ if (key === null) {
1114
+ this.tags.null = "";
1115
+ return;
1116
+ }
1117
+ if (typeof key === "object") {
1118
+ Object.keys(key).forEach((k) => {
1119
+ this.tags[forceString(k)] = forceString(key[k]);
1120
+ });
1121
+ }
1122
+ else {
1123
+ this.tags[forceString(key)] = "";
1124
+ }
1125
+ }
1126
+ untag(key) {
1127
+ if (Array.isArray(key)) {
1128
+ key.forEach((k) => {
1129
+ delete this.tags[forceString(k)];
1130
+ });
1131
+ return;
1132
+ }
1133
+ if (key === null) {
1134
+ delete this.tags.null;
1135
+ return;
1136
+ }
1137
+ if (typeof key === "object") {
1138
+ Object.keys(key).forEach((k) => {
1139
+ delete this.tags[forceString(k)];
1140
+ });
1141
+ }
1142
+ else {
1143
+ delete this.tags[forceString(key)];
1144
+ }
1145
+ }
1146
+ with(key, value) {
1147
+ const logger = new Logger(this.options);
1148
+ logger.tag(this.tags);
1149
+ logger.tag(key, value);
1150
+ return logger;
1151
+ }
1152
+ }
1153
+
1154
+ function logTags(withTags) {
1155
+ const { PROJECT_COMMIT, PROJECT_ENV, PROJECT_KEY, PROJECT_SERVICE, PROJECT_SPONSOR, PROJECT_VERSION, } = process.env;
1156
+ const tags = {};
1157
+ if (PROJECT_COMMIT) {
1158
+ tags.commit = PROJECT_COMMIT;
1159
+ }
1160
+ if (PROJECT_ENV) {
1161
+ tags.env = PROJECT_ENV;
1162
+ }
1163
+ if (PROJECT_KEY) {
1164
+ tags.project = PROJECT_KEY;
1165
+ }
1166
+ if (PROJECT_SERVICE) {
1167
+ tags.service = PROJECT_SERVICE;
1168
+ }
1169
+ if (PROJECT_SPONSOR) {
1170
+ tags.sponsor = PROJECT_SPONSOR;
1171
+ }
1172
+ if (process.env.npm_package_version || PROJECT_VERSION) {
1173
+ tags.version = (process.env.npm_package_version ||
1174
+ PROJECT_VERSION);
1175
+ }
1176
+ return {
1177
+ ...tags,
1178
+ ...withTags,
1179
+ };
1180
+ }
1181
+
1182
+ function forceVar(key, value) {
1183
+ if (typeof key === "undefined") {
1184
+ return {};
1185
+ }
1186
+ if (typeof key === "object" && key !== null) {
1187
+ if (Object.keys(key).length === 1) {
1188
+ return key;
1189
+ }
1190
+ else {
1191
+ return { value: key };
1192
+ }
1193
+ }
1194
+ const keyStr = forceString(key);
1195
+ if (typeof value === "undefined") {
1196
+ return { [keyStr]: "" };
1197
+ }
1198
+ else {
1199
+ return { [keyStr]: value };
1200
+ }
1201
+ }
1202
+
1203
+ function isAxiosResponse(response) {
1204
+ if (typeof response !== "object" || response === null) {
1205
+ return false;
1206
+ }
1207
+ const r = response;
1208
+ return !!(r &&
1209
+ r.config &&
1210
+ r.data &&
1211
+ r.headers &&
1212
+ r.request &&
1213
+ r.status &&
1214
+ r.statusText);
1215
+ }
1216
+ function filterAxiosResponse(response) {
1217
+ if (!isAxiosResponse(response)) {
1218
+ return response;
1219
+ }
1220
+ const r = response;
1221
+ const newResponse = {
1222
+ data: r.data,
1223
+ headers: r.headers,
1224
+ status: r.status,
1225
+ statusText: r.statusText,
1226
+ };
1227
+ if (r.isAxiosError) {
1228
+ newResponse.isAxiosError = r.isAxiosError;
1229
+ }
1230
+ return newResponse;
1231
+ }
1232
+ const axiosResponseVarPipeline = {
1233
+ filter: filterAxiosResponse,
1234
+ key: "response",
1235
+ };
1236
+ function isError(item) {
1237
+ if (typeof item !== "object" || item === null) {
1238
+ return false;
1239
+ }
1240
+ if (item instanceof Error) {
1241
+ return true;
1242
+ }
1243
+ const i = item;
1244
+ if (i.isProjectError) {
1245
+ return true;
1246
+ }
1247
+ return false;
1248
+ }
1249
+ function filterErrorVar(item) {
1250
+ if (!isError(item)) {
1251
+ return item;
1252
+ }
1253
+ const e = item;
1254
+ const newItem = {
1255
+ message: e.message,
1256
+ name: e.name,
1257
+ };
1258
+ if (e.cause) {
1259
+ newItem.cause = e.cause;
1260
+ }
1261
+ if (e.stack) {
1262
+ newItem.stack = e.stack;
1263
+ }
1264
+ if (e.isProjectError) {
1265
+ newItem.isProjectError = e.isProjectError;
1266
+ newItem.title = e.title;
1267
+ newItem.detail = e.detail;
1268
+ newItem.status = e.status;
1269
+ }
1270
+ return newItem;
1271
+ }
1272
+ const errorVarPipeline = {
1273
+ filter: filterErrorVar,
1274
+ key: "error",
1275
+ };
1276
+ const pipelines = [axiosResponseVarPipeline, errorVarPipeline];
1277
+
1278
+ function keyValueToArray(keyValue) {
1279
+ const key = Object.keys(keyValue)[0];
1280
+ return [key, keyValue[key]];
1281
+ }
1282
+ function logVar(key, value) {
1283
+ let [k, v] = keyValueToArray(forceVar(key, value));
1284
+ for (const pipeline of pipelines) {
1285
+ if (k === pipeline.key) {
1286
+ v = pipeline.filter(v);
1287
+ }
1288
+ }
1289
+ return { [k]: v };
1290
+ }
1291
+
1292
+ function envBoolean(key, { defaultValue }) {
1293
+ const value = process.env[key];
1294
+ if (value === undefined)
1295
+ return defaultValue;
1296
+ const lower = value.toLowerCase();
1297
+ return !(lower === "" ||
1298
+ lower === "0" ||
1299
+ lower === "f" ||
1300
+ lower === "false" ||
1301
+ lower === "n" ||
1302
+ lower === "no");
1303
+ }
1304
+ class JaypieLogger {
1305
+ constructor({ level = process.env.LOG_LEVEL, tags = {}, } = {}) {
1306
+ this._params = { level, tags };
1307
+ this._loggers = [];
1308
+ this._tags = {};
1309
+ this._withLoggers = {};
1310
+ this.level = level || DEFAULT.LEVEL;
1311
+ this._tags = { ...logTags(), ...tags };
1312
+ this._logger = new Logger({
1313
+ format: FORMAT.JSON,
1314
+ level: this.level,
1315
+ tags: this._tags,
1316
+ });
1317
+ this._loggers = [this._logger];
1318
+ this.debug = ((...args) => this._logger.debug(...args));
1319
+ this.debug.var = (messageObject, messageValue) => this._logger.debug.var(messageObject, messageValue);
1320
+ this.error = ((...args) => this._logger.error(...args));
1321
+ this.error.var = (messageObject, messageValue) => this._logger.error.var(messageObject, messageValue);
1322
+ this.fatal = ((...args) => this._logger.fatal(...args));
1323
+ this.fatal.var = (messageObject, messageValue) => this._logger.fatal.var(messageObject, messageValue);
1324
+ this.info = ((...args) => this._logger.info(...args));
1325
+ this.info.var = (messageObject, messageValue) => this._logger.info.var(messageObject, messageValue);
1326
+ this.trace = ((...args) => this._logger.trace(...args));
1327
+ this.trace.var = (messageObject, messageValue) => this._logger.trace.var(messageObject, messageValue);
1328
+ this.warn = ((...args) => this._logger.warn(...args));
1329
+ this.warn.var = (messageObject, messageValue) => this._logger.warn.var(messageObject, messageValue);
1330
+ this.var = (messageObject, messageValue) => this._logger.var(logVar(messageObject, messageValue));
1331
+ }
1332
+ init() {
1333
+ for (const logger of this._loggers) {
1334
+ if ("init" in logger && typeof logger.init === "function") {
1335
+ logger.init();
1336
+ }
1337
+ }
1338
+ const level = this._params.level;
1339
+ const tags = this._params.tags;
1340
+ this.level = level || DEFAULT.LEVEL;
1341
+ this._tags = { ...logTags(), ...tags };
1342
+ this._logger = new Logger({
1343
+ format: FORMAT.JSON,
1344
+ level: this.level,
1345
+ tags: this._tags,
1346
+ });
1347
+ this._loggers = [this._logger];
1348
+ this._withLoggers = {};
1349
+ const levels = [
1350
+ "debug",
1351
+ "error",
1352
+ "fatal",
1353
+ "info",
1354
+ "trace",
1355
+ "warn",
1356
+ ];
1357
+ levels.forEach((lvl) => {
1358
+ this[lvl] = ((...args) => {
1359
+ this._logger[lvl](...args);
1360
+ });
1361
+ this[lvl].var = (messageObject, messageValue) => {
1362
+ this._logger[lvl].var(messageObject, messageValue);
1363
+ };
1364
+ });
1365
+ }
1366
+ lib({ level, lib, tags = {}, } = {}) {
1367
+ const newTags = Object.assign({}, this._tags, tags);
1368
+ if (lib) {
1369
+ newTags.lib = lib;
1370
+ }
1371
+ const logger = new JaypieLogger({
1372
+ level: (() => {
1373
+ if (level) {
1374
+ return level;
1375
+ }
1376
+ if (process.env.MODULE_LOG_LEVEL) {
1377
+ return process.env.MODULE_LOG_LEVEL;
1378
+ }
1379
+ if (envBoolean("MODULE_LOGGER", { defaultValue: false })) {
1380
+ return process.env.LOG_LEVEL;
1381
+ }
1382
+ return LEVEL.SILENT;
1383
+ })(),
1384
+ tags: newTags,
1385
+ });
1386
+ this._loggers.push(logger._logger);
1387
+ return logger;
1388
+ }
1389
+ tag(tags) {
1390
+ for (const logger of this._loggers) {
1391
+ logger.tag(tags);
1392
+ }
1393
+ Object.assign(this._tags, tags);
1394
+ }
1395
+ untag(key) {
1396
+ for (const logger of this._loggers) {
1397
+ logger.untag(key);
1398
+ }
1399
+ if (Array.isArray(key)) {
1400
+ key.forEach((k) => {
1401
+ delete this._tags[String(k)];
1402
+ });
1403
+ }
1404
+ else if (typeof key === "object" && key !== null) {
1405
+ Object.keys(key).forEach((k) => {
1406
+ delete this._tags[k];
1407
+ });
1408
+ }
1409
+ else {
1410
+ delete this._tags[String(key)];
1411
+ }
1412
+ }
1413
+ with(key, value) {
1414
+ if (!key || (typeof key !== "object" && value === undefined)) {
1415
+ throw new Error("ConfigurationError: with() requires an object argument or key-value pair");
1416
+ }
1417
+ const loggerKey = JSON.stringify([key, value]);
1418
+ if (Object.keys(this._withLoggers).includes(loggerKey)) {
1419
+ return this._withLoggers[loggerKey];
1420
+ }
1421
+ const logger = new JaypieLogger({
1422
+ level: this.level,
1423
+ tags: { ...this._tags },
1424
+ });
1425
+ logger._logger = this._logger.with(key, value);
1426
+ logger._loggers = [logger._logger];
1427
+ this._withLoggers[loggerKey] = logger;
1428
+ this._loggers.push(logger._logger);
1429
+ return logger;
1430
+ }
1431
+ }
1432
+ function createLogger$1(tags = {}) {
1433
+ const jaypieLogger = new JaypieLogger({
1434
+ tags,
1435
+ });
1436
+ return jaypieLogger;
1437
+ }
1438
+
1439
+ createLogger$1();
1440
+
1441
+ const mockLog = mockLogFactory();
1442
+ const createLogger = createMockWrappedFunction(createLogger$1, mockLog);
1443
+
1444
+ var logger = /*#__PURE__*/Object.freeze({
1445
+ __proto__: null,
1446
+ FORMAT: FORMAT,
1447
+ LEVEL: LEVEL,
1448
+ Logger: Logger,
1449
+ createLogger: createLogger,
1450
+ default: mockLog
1451
+ });
1452
+
820
1453
  // Mongoose mock functions
821
1454
  const connect = createMockReturnedFunction(true);
822
1455
  const connectFromSecretEnv = createMockReturnedFunction(true);
@@ -870,7 +1503,7 @@ var textract$1 = /*#__PURE__*/Object.freeze({
870
1503
 
871
1504
  // Import all mocks
872
1505
  // Export default object with all mocks
873
- var index = {
1506
+ const mock = {
874
1507
  // AWS module
875
1508
  ...aws,
876
1509
  // Core module
@@ -879,15 +1512,17 @@ var index = {
879
1512
  ...datadog,
880
1513
  // Express module
881
1514
  ...express,
1515
+ ...kit,
882
1516
  // Lambda module
883
1517
  ...lambda,
884
1518
  // LLM module
885
1519
  ...llm,
1520
+ ...logger,
886
1521
  // Mongoose module (now empty)
887
1522
  ...mongoose,
888
1523
  // Textract module
889
1524
  ...textract$1,
890
1525
  };
891
1526
 
892
- export { BadGatewayError, BadRequestError, ConfigurationError, DATADOG, ERROR, EXPRESS, ForbiddenError, GatewayTimeoutError, GoneError, HTTP$1 as HTTP, IllogicalError, InternalError, JAYPIE, JaypieToolkit, LLM, Llm, MarkdownPage, MethodNotAllowedError, MultiError, NotFoundError, NotImplementedError, PROJECT, ProjectError, ProjectMultiError, RejectedError, TeapotError, Toolkit, UnauthorizedError, UnavailableError, UnhandledError, UnreachableCodeError, VALIDATE, badRequestRoute, cloneDeep, connect, connectFromSecretEnv, cors, index as default, disconnect, echoRoute, envBoolean, envsKey, errorFromStatusCode, expressHandler, expressHttpCodeHandler, forbiddenRoute, force, formatError, getEnvSecret, getHeaderFrom, getMessages, getObjectKeyCaseInsensitive, getSecret, getSingletonMessage, getTextractJob, goneRoute, hasDatadogEnv, isClass, isJaypieError, jaypieHandler, lambdaHandler, methodNotAllowedRoute, noContentRoute, notFoundRoute, notImplementedRoute, optional, placeholders, required, resolveValue, safeParseFloat, sendBatchMessages, sendMessage, sendTextractJob, sleep, submitDistribution, submitMetric, submitMetricSet, textractJsonToMarkdown, toolkit, tools, uuid, validate };
1527
+ export { BadGatewayError, BadRequestError, ConfigurationError, DATADOG, ERROR$1 as ERROR, EXPRESS, FORMAT, ForbiddenError, GatewayTimeoutError, GoneError, HTTP$1 as HTTP, IllogicalError, InternalError, JAYPIE, JaypieToolkit, LEVEL, LLM, Llm, LlmMessageRole, LlmMessageType, Logger, MarkdownPage, MethodNotAllowedError, MultiError, NotFoundError, NotImplementedError, PROJECT, ProjectError, ProjectMultiError, RejectedError, TeapotError, Toolkit, UnauthorizedError, UnavailableError, UnhandledError, UnreachableCodeError, VALIDATE, badRequestRoute, cloneDeep, connect, connectFromSecretEnv, cors, createLogger, mock as default, disconnect, echoRoute, envBoolean$1 as envBoolean, envsKey, errorFromStatusCode, expressHandler, expressHttpCodeHandler, forbiddenRoute, force, formatError, getEnvSecret, getHeaderFrom, getMessages, getObjectKeyCaseInsensitive, getSecret, getSingletonMessage, getTextractJob, goneRoute, hasDatadogEnv, isClass, isJaypieError, isNodeTestEnv, isProductionEnv, jaypieHandler, lambdaHandler, methodNotAllowedRoute, noContentRoute, notFoundRoute, notImplementedRoute, optional, placeholders, required, resolveValue, safeParseFloat, sendBatchMessages, sendMessage, sendTextractJob, sleep, submitDistribution, submitMetric, submitMetricSet, textractJsonToMarkdown, toolkit, tools, uuid, validate };
893
1528
  //# sourceMappingURL=index.js.map