@dereekb/nestjs 13.10.9 → 13.11.0

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/index.cjs.js CHANGED
@@ -9,9 +9,11 @@ var querystring = require('querystring');
9
9
  var bodyParser = require('body-parser');
10
10
  var util = require('@dereekb/util');
11
11
  var config = require('@nestjs/config');
12
+ var node_fs = require('node:fs');
13
+ var promises$1 = require('node:fs/promises');
12
14
  var node_crypto = require('node:crypto');
13
15
 
14
- function asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, key, arg) {
16
+ function asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, key, arg) {
15
17
  try {
16
18
  var info = gen[key](arg);
17
19
  var value = info.value;
@@ -25,22 +27,22 @@ function asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, key, arg) {
25
27
  Promise.resolve(value).then(_next, _throw);
26
28
  }
27
29
  }
28
- function _async_to_generator$1(fn) {
30
+ function _async_to_generator$2(fn) {
29
31
  return function() {
30
32
  var self = this, args = arguments;
31
33
  return new Promise(function(resolve, reject) {
32
34
  var gen = fn.apply(self, args);
33
35
  function _next(value) {
34
- asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "next", value);
36
+ asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, "next", value);
35
37
  }
36
38
  function _throw(err) {
37
- asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "throw", err);
39
+ asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, "throw", err);
38
40
  }
39
41
  _next(undefined);
40
42
  });
41
43
  };
42
44
  }
43
- function _ts_generator$1(thisArg, body) {
45
+ function _ts_generator$2(thisArg, body) {
44
46
  var f, y, t, _ = {
45
47
  label: 0,
46
48
  sent: function() {
@@ -159,9 +161,9 @@ function _ts_generator$1(thisArg, body) {
159
161
  */ function nodeJsLocalAssetLoader(config) {
160
162
  var basePath = config.basePath;
161
163
  var getFn = function getFn(ref) {
162
- return _async_to_generator$1(function() {
164
+ return _async_to_generator$2(function() {
163
165
  var localRef, fullPath, buffer;
164
- return _ts_generator$1(this, function(_state) {
166
+ return _ts_generator$2(this, function(_state) {
165
167
  switch(_state.label){
166
168
  case 0:
167
169
  localRef = ref;
@@ -240,7 +242,7 @@ function _ts_generator$1(thisArg, body) {
240
242
  return origin.startsWith('http://localhost') || origin.startsWith('https://localhost');
241
243
  }
242
244
 
243
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
245
+ function asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, key, arg) {
244
246
  try {
245
247
  var info = gen[key](arg);
246
248
  var value = info.value;
@@ -254,22 +256,22 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
254
256
  Promise.resolve(value).then(_next, _throw);
255
257
  }
256
258
  }
257
- function _async_to_generator(fn) {
259
+ function _async_to_generator$1(fn) {
258
260
  return function() {
259
261
  var self = this, args = arguments;
260
262
  return new Promise(function(resolve, reject) {
261
263
  var gen = fn.apply(self, args);
262
264
  function _next(value) {
263
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
265
+ asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "next", value);
264
266
  }
265
267
  function _throw(err) {
266
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
268
+ asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "throw", err);
267
269
  }
268
270
  _next(undefined);
269
271
  });
270
272
  };
271
273
  }
272
- function _ts_generator(thisArg, body) {
274
+ function _ts_generator$1(thisArg, body) {
273
275
  var f, y, t, _ = {
274
276
  label: 0,
275
277
  sent: function() {
@@ -382,9 +384,9 @@ function _ts_generator(thisArg, body) {
382
384
  * ```
383
385
  */ var rawBodyLogger = new common.Logger('RawBody');
384
386
  var ParseRawBody = common.createParamDecorator(function(_, context) {
385
- return _async_to_generator(function() {
387
+ return _async_to_generator$1(function() {
386
388
  var req, body;
387
- return _ts_generator(this, function(_state) {
389
+ return _ts_generator$1(this, function(_state) {
388
390
  switch(_state.label){
389
391
  case 0:
390
392
  req = context.switchToHttp().getRequest();
@@ -419,9 +421,9 @@ var ParseRawBody = common.createParamDecorator(function(_, context) {
419
421
  * handleWebhook(@RawBody() body: RawBodyBuffer) { ... }
420
422
  * ```
421
423
  */ var RawBody = common.createParamDecorator(function(_, context) {
422
- return _async_to_generator(function() {
424
+ return _async_to_generator$1(function() {
423
425
  var req, body;
424
- return _ts_generator(this, function(_state) {
426
+ return _ts_generator$1(this, function(_state) {
425
427
  req = context.switchToHttp().getRequest();
426
428
  body = req.body;
427
429
  if (!Buffer.isBuffer(body)) {
@@ -445,9 +447,9 @@ var ParseRawBody = common.createParamDecorator(function(_, context) {
445
447
  * handleForm(@ParsedQueryRawBody() body: ParsedUrlQuery) { ... }
446
448
  * ```
447
449
  */ var ParsedQueryRawBody = common.createParamDecorator(function(_, context) {
448
- return _async_to_generator(function() {
450
+ return _async_to_generator$1(function() {
449
451
  var req;
450
- return _ts_generator(this, function(_state) {
452
+ return _ts_generator$1(this, function(_state) {
451
453
  req = context.switchToHttp().getRequest();
452
454
  req.body = RawBodyToParsedQueryString(req.body);
453
455
  return [
@@ -631,7 +633,7 @@ function _create_class$3(Constructor, protoProps, staticProps) {
631
633
  if (protoProps) _defineProperties$3(Constructor.prototype, protoProps);
632
634
  return Constructor;
633
635
  }
634
- function _define_property$3(obj, key, value) {
636
+ function _define_property$4(obj, key, value) {
635
637
  if (key in obj) {
636
638
  Object.defineProperty(obj, key, {
637
639
  value: value,
@@ -739,7 +741,7 @@ var DEFAULT_WEBHOOK_MIDDLEWARE_ROUTE_INFO = {
739
741
  function ConfigureWebhookMiddlewareModule() {
740
742
  _class_call_check$5(this, ConfigureWebhookMiddlewareModule);
741
743
  var _this;
742
- _this = _call_super(this, ConfigureWebhookMiddlewareModule, arguments), _define_property$3(_this, "logger", new common.Logger('ConfigureWebhookMiddlewareModule'));
744
+ _this = _call_super(this, ConfigureWebhookMiddlewareModule, arguments), _define_property$4(_this, "logger", new common.Logger('ConfigureWebhookMiddlewareModule'));
743
745
  return _this;
744
746
  }
745
747
  _create_class$3(ConfigureWebhookMiddlewareModule, [
@@ -836,7 +838,7 @@ function _create_class$2(Constructor, protoProps, staticProps) {
836
838
  if (staticProps) _defineProperties$2(Constructor, staticProps);
837
839
  return Constructor;
838
840
  }
839
- function _define_property$2(obj, key, value) {
841
+ function _define_property$3(obj, key, value) {
840
842
  if (key in obj) {
841
843
  Object.defineProperty(obj, key, {
842
844
  value: value,
@@ -856,7 +858,7 @@ function _define_property$2(obj, key, value) {
856
858
  */ var ClientAppServiceConfig = /*#__PURE__*/ function() {
857
859
  function ClientAppServiceConfig() {
858
860
  _class_call_check$4(this, ClientAppServiceConfig);
859
- _define_property$2(this, "client", void 0);
861
+ _define_property$3(this, "client", void 0);
860
862
  }
861
863
  _create_class$2(ClientAppServiceConfig, null, [
862
864
  {
@@ -895,7 +897,7 @@ function _create_class$1(Constructor, protoProps, staticProps) {
895
897
  if (protoProps) _defineProperties$1(Constructor.prototype, protoProps);
896
898
  return Constructor;
897
899
  }
898
- function _define_property$1(obj, key, value) {
900
+ function _define_property$2(obj, key, value) {
899
901
  if (key in obj) {
900
902
  Object.defineProperty(obj, key, {
901
903
  value: value,
@@ -913,7 +915,7 @@ function _define_property$1(obj, key, value) {
913
915
  */ exports.ClientAppService = /*#__PURE__*/ function() {
914
916
  function ClientAppService(config) {
915
917
  _class_call_check$3(this, ClientAppService);
916
- _define_property$1(this, "_config", void 0);
918
+ _define_property$2(this, "_config", void 0);
917
919
  this._config = config;
918
920
  }
919
921
  _create_class$1(ClientAppService, [
@@ -1052,7 +1054,7 @@ function _create_class(Constructor, protoProps, staticProps) {
1052
1054
  if (protoProps) _defineProperties(Constructor.prototype, protoProps);
1053
1055
  return Constructor;
1054
1056
  }
1055
- function _define_property(obj, key, value) {
1057
+ function _define_property$1(obj, key, value) {
1056
1058
  if (key in obj) {
1057
1059
  Object.defineProperty(obj, key, {
1058
1060
  value: value,
@@ -1068,7 +1070,7 @@ function _define_property(obj, key, value) {
1068
1070
  exports.ServerEnvironmentService = /*#__PURE__*/ function() {
1069
1071
  function ServerEnvironmentService(env) {
1070
1072
  _class_call_check(this, ServerEnvironmentService);
1071
- _define_property(this, "env", void 0);
1073
+ _define_property$1(this, "env", void 0);
1072
1074
  this.env = env;
1073
1075
  }
1074
1076
  _create_class(ServerEnvironmentService, [
@@ -1116,6 +1118,639 @@ exports.ServerEnvironmentService = __decorate([
1116
1118
  __param(0, common.Inject(SERVER_ENV_TOKEN))
1117
1119
  ], exports.ServerEnvironmentService);
1118
1120
 
1121
+ /**
1122
+ * Reads JSON from disk, resolving `undefined` when the file is missing (ENOENT) or its
1123
+ * contents fail to parse as JSON. Other I/O errors (permission denied, busy handles) are
1124
+ * forwarded to the caller — silently swallowing them masks real failures.
1125
+ *
1126
+ * @param filePath - Absolute path to the JSON file to read.
1127
+ * @returns The parsed JSON cast to `T`, or `undefined` when the file does not exist or its contents are not valid JSON.
1128
+ */ function readJsonFile(filePath) {
1129
+ return new Promise(function(resolve, reject) {
1130
+ node_fs.readFile(filePath, {
1131
+ encoding: 'utf-8'
1132
+ }, function(err, data) {
1133
+ if (err) {
1134
+ if (err.code === 'ENOENT') {
1135
+ resolve(undefined);
1136
+ } else {
1137
+ reject(err);
1138
+ }
1139
+ return;
1140
+ }
1141
+ try {
1142
+ resolve(JSON.parse(data));
1143
+ } catch (unused) {
1144
+ resolve(undefined);
1145
+ }
1146
+ });
1147
+ });
1148
+ }
1149
+ /**
1150
+ * Writes a value to disk as JSON. Creates the parent directory if it does not exist.
1151
+ *
1152
+ * The `mode` option is enforced via an explicit `chmod` after the write — `writeFile`'s `mode`
1153
+ * parameter is ignored when the file already exists, which would otherwise leave a
1154
+ * pre-existing file at its original (potentially world-readable) permissions.
1155
+ *
1156
+ * @param input - Configuration describing the destination, payload, and optional file mode.
1157
+ * @param input.filePath - Absolute path to the file to write.
1158
+ * @param input.dirPath - Absolute path to the parent directory; created (recursively) when missing.
1159
+ * @param input.data - Value to serialize as JSON (pretty-printed with two-space indentation).
1160
+ * @param input.mode - Optional numeric file mode (e.g. `0o600`) applied via `chmod` after the write.
1161
+ * @returns A promise that resolves once the JSON has been written and the optional `chmod` has completed.
1162
+ */ function writeJsonFile(input) {
1163
+ node_fs.mkdirSync(input.dirPath, {
1164
+ recursive: true
1165
+ });
1166
+ return new Promise(function(resolve, reject) {
1167
+ node_fs.writeFile(input.filePath, JSON.stringify(input.data, null, 2), {
1168
+ mode: input.mode
1169
+ }, function(err) {
1170
+ if (err) {
1171
+ reject(err);
1172
+ return;
1173
+ }
1174
+ if (input.mode == null) {
1175
+ resolve();
1176
+ return;
1177
+ }
1178
+ node_fs.chmod(input.filePath, input.mode, function(chmodErr) {
1179
+ if (chmodErr) reject(chmodErr);
1180
+ else resolve();
1181
+ });
1182
+ });
1183
+ });
1184
+ }
1185
+ /**
1186
+ * Removes the file at the given path.
1187
+ *
1188
+ * Resolves silently when the file does not exist (`force: true`); other errors
1189
+ * (permission denied, busy file handles) are forwarded to the caller — silently
1190
+ * swallowing them masks real failures and makes operations appear to have succeeded.
1191
+ *
1192
+ * @param filePath - Absolute path to the file to remove.
1193
+ * @returns A promise that resolves once the file is removed (or was already absent).
1194
+ */ function removeFile(filePath) {
1195
+ return promises$1.rm(filePath, {
1196
+ force: true
1197
+ });
1198
+ }
1199
+
1200
+ function _array_like_to_array$1(arr, len) {
1201
+ if (len == null || len > arr.length) len = arr.length;
1202
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
1203
+ return arr2;
1204
+ }
1205
+ function _array_with_holes$1(arr) {
1206
+ if (Array.isArray(arr)) return arr;
1207
+ }
1208
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
1209
+ try {
1210
+ var info = gen[key](arg);
1211
+ var value = info.value;
1212
+ } catch (error) {
1213
+ reject(error);
1214
+ return;
1215
+ }
1216
+ if (info.done) {
1217
+ resolve(value);
1218
+ } else {
1219
+ Promise.resolve(value).then(_next, _throw);
1220
+ }
1221
+ }
1222
+ function _async_to_generator(fn) {
1223
+ return function() {
1224
+ var self = this, args = arguments;
1225
+ return new Promise(function(resolve, reject) {
1226
+ var gen = fn.apply(self, args);
1227
+ function _next(value) {
1228
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
1229
+ }
1230
+ function _throw(err) {
1231
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
1232
+ }
1233
+ _next(undefined);
1234
+ });
1235
+ };
1236
+ }
1237
+ function _define_property(obj, key, value) {
1238
+ if (key in obj) {
1239
+ Object.defineProperty(obj, key, {
1240
+ value: value,
1241
+ enumerable: true,
1242
+ configurable: true,
1243
+ writable: true
1244
+ });
1245
+ } else {
1246
+ obj[key] = value;
1247
+ }
1248
+ return obj;
1249
+ }
1250
+ function _iterable_to_array_limit$1(arr, i) {
1251
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
1252
+ if (_i == null) return;
1253
+ var _arr = [];
1254
+ var _n = true;
1255
+ var _d = false;
1256
+ var _s, _e;
1257
+ try {
1258
+ for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
1259
+ _arr.push(_s.value);
1260
+ if (i && _arr.length === i) break;
1261
+ }
1262
+ } catch (err) {
1263
+ _d = true;
1264
+ _e = err;
1265
+ } finally{
1266
+ try {
1267
+ if (!_n && _i["return"] != null) _i["return"]();
1268
+ } finally{
1269
+ if (_d) throw _e;
1270
+ }
1271
+ }
1272
+ return _arr;
1273
+ }
1274
+ function _non_iterable_rest$1() {
1275
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
1276
+ }
1277
+ function _object_spread(target) {
1278
+ for(var i = 1; i < arguments.length; i++){
1279
+ var source = arguments[i] != null ? arguments[i] : {};
1280
+ var ownKeys = Object.keys(source);
1281
+ if (typeof Object.getOwnPropertySymbols === "function") {
1282
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
1283
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
1284
+ }));
1285
+ }
1286
+ ownKeys.forEach(function(key) {
1287
+ _define_property(target, key, source[key]);
1288
+ });
1289
+ }
1290
+ return target;
1291
+ }
1292
+ function ownKeys(object, enumerableOnly) {
1293
+ var keys = Object.keys(object);
1294
+ if (Object.getOwnPropertySymbols) {
1295
+ var symbols = Object.getOwnPropertySymbols(object);
1296
+ keys.push.apply(keys, symbols);
1297
+ }
1298
+ return keys;
1299
+ }
1300
+ function _object_spread_props(target, source) {
1301
+ source = source != null ? source : {};
1302
+ if (Object.getOwnPropertyDescriptors) {
1303
+ Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
1304
+ } else {
1305
+ ownKeys(Object(source)).forEach(function(key) {
1306
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
1307
+ });
1308
+ }
1309
+ return target;
1310
+ }
1311
+ function _sliced_to_array$1(arr, i) {
1312
+ return _array_with_holes$1(arr) || _iterable_to_array_limit$1(arr, i) || _unsupported_iterable_to_array$1(arr, i) || _non_iterable_rest$1();
1313
+ }
1314
+ function _unsupported_iterable_to_array$1(o, minLen) {
1315
+ if (!o) return;
1316
+ if (typeof o === "string") return _array_like_to_array$1(o, minLen);
1317
+ var n = Object.prototype.toString.call(o).slice(8, -1);
1318
+ if (n === "Object" && o.constructor) n = o.constructor.name;
1319
+ if (n === "Map" || n === "Set") return Array.from(n);
1320
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array$1(o, minLen);
1321
+ }
1322
+ function _ts_generator(thisArg, body) {
1323
+ var f, y, t, _ = {
1324
+ label: 0,
1325
+ sent: function() {
1326
+ if (t[0] & 1) throw t[1];
1327
+ return t[1];
1328
+ },
1329
+ trys: [],
1330
+ ops: []
1331
+ }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
1332
+ return d(g, "next", {
1333
+ value: verb(0)
1334
+ }), d(g, "throw", {
1335
+ value: verb(1)
1336
+ }), d(g, "return", {
1337
+ value: verb(2)
1338
+ }), typeof Symbol === "function" && d(g, Symbol.iterator, {
1339
+ value: function() {
1340
+ return this;
1341
+ }
1342
+ }), g;
1343
+ function verb(n) {
1344
+ return function(v) {
1345
+ return step([
1346
+ n,
1347
+ v
1348
+ ]);
1349
+ };
1350
+ }
1351
+ function step(op) {
1352
+ if (f) throw new TypeError("Generator is already executing.");
1353
+ while(g && (g = 0, op[0] && (_ = 0)), _)try {
1354
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
1355
+ if (y = 0, t) op = [
1356
+ op[0] & 2,
1357
+ t.value
1358
+ ];
1359
+ switch(op[0]){
1360
+ case 0:
1361
+ case 1:
1362
+ t = op;
1363
+ break;
1364
+ case 4:
1365
+ _.label++;
1366
+ return {
1367
+ value: op[1],
1368
+ done: false
1369
+ };
1370
+ case 5:
1371
+ _.label++;
1372
+ y = op[1];
1373
+ op = [
1374
+ 0
1375
+ ];
1376
+ continue;
1377
+ case 7:
1378
+ op = _.ops.pop();
1379
+ _.trys.pop();
1380
+ continue;
1381
+ default:
1382
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
1383
+ _ = 0;
1384
+ continue;
1385
+ }
1386
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
1387
+ _.label = op[1];
1388
+ break;
1389
+ }
1390
+ if (op[0] === 6 && _.label < t[1]) {
1391
+ _.label = t[1];
1392
+ t = op;
1393
+ break;
1394
+ }
1395
+ if (t && _.label < t[2]) {
1396
+ _.label = t[2];
1397
+ _.ops.push(op);
1398
+ break;
1399
+ }
1400
+ if (t[2]) _.ops.pop();
1401
+ _.trys.pop();
1402
+ continue;
1403
+ }
1404
+ op = body.call(thisArg, _);
1405
+ } catch (e) {
1406
+ op = [
1407
+ 6,
1408
+ e
1409
+ ];
1410
+ y = 0;
1411
+ } finally{
1412
+ f = t = 0;
1413
+ }
1414
+ if (op[0] & 5) throw op[1];
1415
+ return {
1416
+ value: op[0] ? op[1] : void 0,
1417
+ done: true
1418
+ };
1419
+ }
1420
+ }
1421
+ /**
1422
+ * Default file mode used by the JSON-file caches when none is provided.
1423
+ *
1424
+ * 0o600 restricts the file to read/write for the owning user only — appropriate for
1425
+ * secrets like cached access/refresh tokens.
1426
+ */ var DEFAULT_JSON_FILE_CACHE_MODE = 384;
1427
+ /**
1428
+ * Creates an {@link AsyncValueCache} backed by a single JSON file on disk.
1429
+ *
1430
+ * Reads always touch disk; wrap with {@link memoizeAsyncValueCache} (or use
1431
+ * {@link createMemoizedJsonFileAsyncValueCache}) to add per-process memoization.
1432
+ *
1433
+ * Multi-process invalidation is not provided. Two processes writing to the same file
1434
+ * will last-writer-wins; once memoized, a long-running process will not observe writes
1435
+ * from another process.
1436
+ *
1437
+ * @param input - Configuration bag describing the backing file and optional JSON revive/replace hooks.
1438
+ * @param input.filePath - Absolute path to the JSON file that backs the cache.
1439
+ * @param input.mode - Optional file mode applied on write; defaults to {@link DEFAULT_JSON_FILE_CACHE_MODE} (0o600).
1440
+ * @param input.reviver - Optional transform applied to the raw JSON-parsed payload before it is returned from `load()` (e.g. revive `Date` fields).
1441
+ * @param input.replacer - Optional transform applied to the value before it is stringified to JSON on `update()`.
1442
+ * @returns An {@link AsyncValueCache} that persists the value to the configured JSON file.
1443
+ */ function createJsonFileAsyncValueCache(input) {
1444
+ var filePath = input.filePath, mode = input.mode, reviver = input.reviver, replacer = input.replacer;
1445
+ var fileMode = mode !== null && mode !== void 0 ? mode : DEFAULT_JSON_FILE_CACHE_MODE;
1446
+ return {
1447
+ load: function load() {
1448
+ return _async_to_generator(function() {
1449
+ var raw;
1450
+ return _ts_generator(this, function(_state) {
1451
+ switch(_state.label){
1452
+ case 0:
1453
+ return [
1454
+ 4,
1455
+ readJsonFile(filePath)
1456
+ ];
1457
+ case 1:
1458
+ raw = _state.sent();
1459
+ if (raw == null) {
1460
+ return [
1461
+ 2,
1462
+ undefined
1463
+ ];
1464
+ }
1465
+ return [
1466
+ 2,
1467
+ reviver == null ? raw : reviver(raw)
1468
+ ];
1469
+ }
1470
+ });
1471
+ })();
1472
+ },
1473
+ update: function update(value) {
1474
+ return _async_to_generator(function() {
1475
+ var data;
1476
+ return _ts_generator(this, function(_state) {
1477
+ switch(_state.label){
1478
+ case 0:
1479
+ data = replacer == null ? value : replacer(value);
1480
+ return [
1481
+ 4,
1482
+ writeJsonFile({
1483
+ filePath: filePath,
1484
+ dirPath: node_path.dirname(filePath),
1485
+ data: data,
1486
+ mode: fileMode
1487
+ })
1488
+ ];
1489
+ case 1:
1490
+ _state.sent();
1491
+ return [
1492
+ 2
1493
+ ];
1494
+ }
1495
+ });
1496
+ })();
1497
+ },
1498
+ clear: function clear() {
1499
+ return _async_to_generator(function() {
1500
+ return _ts_generator(this, function(_state) {
1501
+ switch(_state.label){
1502
+ case 0:
1503
+ return [
1504
+ 4,
1505
+ removeFile(filePath)
1506
+ ];
1507
+ case 1:
1508
+ _state.sent();
1509
+ return [
1510
+ 2
1511
+ ];
1512
+ }
1513
+ });
1514
+ })();
1515
+ }
1516
+ };
1517
+ }
1518
+ /**
1519
+ * Convenience wrapper around {@link createJsonFileAsyncValueCache} composed with
1520
+ * {@link memoizeAsyncValueCache}.
1521
+ *
1522
+ * @param input - Same configuration accepted by {@link createJsonFileAsyncValueCache}; see {@link CreateJsonFileAsyncValueCacheInput}.
1523
+ * @returns An {@link AsyncValueCache} backed by the JSON file with a per-process single-load memoization layer in front.
1524
+ */ function createMemoizedJsonFileAsyncValueCache(input) {
1525
+ return util.memoizeAsyncValueCache(createJsonFileAsyncValueCache(input));
1526
+ }
1527
+ /**
1528
+ * Creates an {@link AsyncKeyedValueCache} backed by a single JSON file holding a `Record<string, T>`.
1529
+ *
1530
+ * Reads/writes always touch disk; wrap with {@link memoizeAsyncKeyedValueCache} (or use
1531
+ * {@link createMemoizedJsonFileAsyncKeyedValueCache}) to add per-process memoization of the
1532
+ * entire record.
1533
+ *
1534
+ * Multi-process invalidation is not provided; see {@link createJsonFileAsyncValueCache} for caveats.
1535
+ *
1536
+ * Concurrent `set`/`remove`/`clear` calls are serialized through a per-instance promise chain so
1537
+ * the read-modify-write of the entire record file does not race within the same process.
1538
+ *
1539
+ * @param input - Configuration bag describing the backing file and optional per-entry revive/replace hooks.
1540
+ * @param input.filePath - Absolute path to the JSON file that holds the entire `Record<string, T>`.
1541
+ * @param input.mode - Optional file mode applied on write; defaults to {@link DEFAULT_JSON_FILE_CACHE_MODE} (0o600).
1542
+ * @param input.reviver - Optional transform applied to each entry after it is JSON-parsed on `load()`/`get()`. Returning null/undefined drops the entry.
1543
+ * @param input.replacer - Optional transform applied to each entry before it is stringified on `set()`.
1544
+ * @returns An {@link AsyncKeyedValueCache} that persists all entries in the configured JSON file.
1545
+ */ function createJsonFileAsyncKeyedValueCache(input) {
1546
+ var filePath = input.filePath, mode = input.mode, reviver = input.reviver, replacer = input.replacer;
1547
+ var fileMode = mode !== null && mode !== void 0 ? mode : DEFAULT_JSON_FILE_CACHE_MODE;
1548
+ function readEntries() {
1549
+ return _async_to_generator(function() {
1550
+ var raw, result, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, key, revived;
1551
+ return _ts_generator(this, function(_state) {
1552
+ switch(_state.label){
1553
+ case 0:
1554
+ return [
1555
+ 4,
1556
+ readJsonFile(filePath)
1557
+ ];
1558
+ case 1:
1559
+ raw = _state.sent();
1560
+ if (raw == null) {
1561
+ return [
1562
+ 2,
1563
+ {}
1564
+ ];
1565
+ }
1566
+ if (reviver == null) {
1567
+ return [
1568
+ 2,
1569
+ raw
1570
+ ];
1571
+ }
1572
+ result = {};
1573
+ _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
1574
+ try {
1575
+ for(_iterator = Object.keys(raw)[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
1576
+ key = _step.value;
1577
+ revived = reviver(raw[key]);
1578
+ if (revived != null) {
1579
+ result[key] = revived;
1580
+ }
1581
+ }
1582
+ } catch (err) {
1583
+ _didIteratorError = true;
1584
+ _iteratorError = err;
1585
+ } finally{
1586
+ try {
1587
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
1588
+ _iterator.return();
1589
+ }
1590
+ } finally{
1591
+ if (_didIteratorError) {
1592
+ throw _iteratorError;
1593
+ }
1594
+ }
1595
+ }
1596
+ return [
1597
+ 2,
1598
+ result
1599
+ ];
1600
+ }
1601
+ });
1602
+ })();
1603
+ }
1604
+ function writeEntries(entries) {
1605
+ return _async_to_generator(function() {
1606
+ var data;
1607
+ return _ts_generator(this, function(_state) {
1608
+ switch(_state.label){
1609
+ case 0:
1610
+ data = replacer == null ? entries : Object.fromEntries(Object.entries(entries).map(function(param) {
1611
+ var _param = _sliced_to_array$1(param, 2), key = _param[0], value = _param[1];
1612
+ return [
1613
+ key,
1614
+ replacer(value)
1615
+ ];
1616
+ }));
1617
+ return [
1618
+ 4,
1619
+ writeJsonFile({
1620
+ filePath: filePath,
1621
+ dirPath: node_path.dirname(filePath),
1622
+ data: data,
1623
+ mode: fileMode
1624
+ })
1625
+ ];
1626
+ case 1:
1627
+ _state.sent();
1628
+ return [
1629
+ 2
1630
+ ];
1631
+ }
1632
+ });
1633
+ })();
1634
+ }
1635
+ // Serialize set/remove through a per-instance promise chain. Without this, two concurrent
1636
+ // mutations would race on the read-modify-write of the entire record file and the second
1637
+ // writer's snapshot of the entries would clobber the first.
1638
+ var mutationQueue = Promise.resolve();
1639
+ function enqueueMutation(fn) {
1640
+ var next = mutationQueue.then(fn, fn);
1641
+ mutationQueue = next.catch(function() {
1642
+ return undefined;
1643
+ });
1644
+ return next;
1645
+ }
1646
+ return {
1647
+ load: readEntries,
1648
+ get: function get(key) {
1649
+ return _async_to_generator(function() {
1650
+ return _ts_generator(this, function(_state) {
1651
+ switch(_state.label){
1652
+ case 0:
1653
+ return [
1654
+ 4,
1655
+ readEntries()
1656
+ ];
1657
+ case 1:
1658
+ return [
1659
+ 2,
1660
+ _state.sent()[key]
1661
+ ];
1662
+ }
1663
+ });
1664
+ })();
1665
+ },
1666
+ set: function set(key, value) {
1667
+ return enqueueMutation(function() {
1668
+ return _async_to_generator(function() {
1669
+ var current;
1670
+ return _ts_generator(this, function(_state) {
1671
+ switch(_state.label){
1672
+ case 0:
1673
+ return [
1674
+ 4,
1675
+ readEntries()
1676
+ ];
1677
+ case 1:
1678
+ current = _state.sent();
1679
+ return [
1680
+ 4,
1681
+ writeEntries(_object_spread_props(_object_spread({}, current), _define_property({}, key, value)))
1682
+ ];
1683
+ case 2:
1684
+ _state.sent();
1685
+ return [
1686
+ 2
1687
+ ];
1688
+ }
1689
+ });
1690
+ })();
1691
+ });
1692
+ },
1693
+ remove: function remove(key) {
1694
+ return enqueueMutation(function() {
1695
+ return _async_to_generator(function() {
1696
+ var current, next;
1697
+ return _ts_generator(this, function(_state) {
1698
+ switch(_state.label){
1699
+ case 0:
1700
+ return [
1701
+ 4,
1702
+ readEntries()
1703
+ ];
1704
+ case 1:
1705
+ current = _state.sent();
1706
+ next = _object_spread({}, current);
1707
+ delete next[key];
1708
+ return [
1709
+ 4,
1710
+ writeEntries(next)
1711
+ ];
1712
+ case 2:
1713
+ _state.sent();
1714
+ return [
1715
+ 2
1716
+ ];
1717
+ }
1718
+ });
1719
+ })();
1720
+ });
1721
+ },
1722
+ clear: function clear() {
1723
+ return enqueueMutation(function() {
1724
+ return _async_to_generator(function() {
1725
+ return _ts_generator(this, function(_state) {
1726
+ switch(_state.label){
1727
+ case 0:
1728
+ return [
1729
+ 4,
1730
+ removeFile(filePath)
1731
+ ];
1732
+ case 1:
1733
+ _state.sent();
1734
+ return [
1735
+ 2
1736
+ ];
1737
+ }
1738
+ });
1739
+ })();
1740
+ });
1741
+ }
1742
+ };
1743
+ }
1744
+ /**
1745
+ * Convenience wrapper around {@link createJsonFileAsyncKeyedValueCache} composed with
1746
+ * {@link memoizeAsyncKeyedValueCache}.
1747
+ *
1748
+ * @param input - Same configuration accepted by {@link createJsonFileAsyncKeyedValueCache}; see {@link CreateJsonFileAsyncKeyedValueCacheInput}.
1749
+ * @returns An {@link AsyncKeyedValueCache} backed by the JSON file with a per-process record-level memoization layer in front.
1750
+ */ function createMemoizedJsonFileAsyncKeyedValueCache(input) {
1751
+ return util.memoizeAsyncKeyedValueCache(createJsonFileAsyncKeyedValueCache(input));
1752
+ }
1753
+
1119
1754
  // MARK: Constants
1120
1755
  /**
1121
1756
  * AES-256-GCM encryption constants.
@@ -2099,6 +2734,7 @@ exports.AppModuleWithWebhooksEnabled = AppModuleWithWebhooksEnabled;
2099
2734
  exports.CLIENT_WEB_APP_URL_ENV_VAR = CLIENT_WEB_APP_URL_ENV_VAR;
2100
2735
  exports.ClientAppServiceConfig = ClientAppServiceConfig;
2101
2736
  exports.DEFAULT_BASE_WEBHOOK_PATH = DEFAULT_BASE_WEBHOOK_PATH;
2737
+ exports.DEFAULT_JSON_FILE_CACHE_MODE = DEFAULT_JSON_FILE_CACHE_MODE;
2102
2738
  exports.DEFAULT_WEBHOOK_MIDDLEWARE_ROUTE_INFO = DEFAULT_WEBHOOK_MIDDLEWARE_ROUTE_INFO;
2103
2739
  exports.IsRequestFromLocalHost = IsRequestFromLocalHost;
2104
2740
  exports.ParseRawBody = ParseRawBody;
@@ -2114,6 +2750,10 @@ exports.clientAppConfigFactory = clientAppConfigFactory;
2114
2750
  exports.consumeWebhooksWithRawBodyMiddleware = consumeWebhooksWithRawBodyMiddleware;
2115
2751
  exports.createAES256GCMEncryption = createAES256GCMEncryption;
2116
2752
  exports.createAesStringEncryptionProvider = createAesStringEncryptionProvider;
2753
+ exports.createJsonFileAsyncKeyedValueCache = createJsonFileAsyncKeyedValueCache;
2754
+ exports.createJsonFileAsyncValueCache = createJsonFileAsyncValueCache;
2755
+ exports.createMemoizedJsonFileAsyncKeyedValueCache = createMemoizedJsonFileAsyncKeyedValueCache;
2756
+ exports.createMemoizedJsonFileAsyncValueCache = createMemoizedJsonFileAsyncValueCache;
2117
2757
  exports.decryptValue = decryptValue;
2118
2758
  exports.detectPdfEncryption = detectPdfEncryption;
2119
2759
  exports.encryptValue = encryptValue;
@@ -2123,5 +2763,8 @@ exports.isTestNodeEnv = isTestNodeEnv;
2123
2763
  exports.isValidAES256GCMEncryptionSecret = isValidAES256GCMEncryptionSecret;
2124
2764
  exports.mergeModuleMetadata = mergeModuleMetadata;
2125
2765
  exports.nodeJsLocalAssetLoader = nodeJsLocalAssetLoader;
2766
+ exports.readJsonFile = readJsonFile;
2767
+ exports.removeFile = removeFile;
2126
2768
  exports.resolveEncryptionKey = resolveEncryptionKey;
2127
2769
  exports.serverEnvTokenProvider = serverEnvTokenProvider;
2770
+ exports.writeJsonFile = writeJsonFile;