@ccci/micro-server 1.0.53 → 1.0.55

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.ts CHANGED
@@ -8,6 +8,7 @@ export { ConstructQuery, ResponseHelper, ErrorResponseHandler, } from './utils/B
8
8
  export { default as IBaseModel } from './utils/IBaseModel';
9
9
  export { default as BaseModel } from './utils/BaseModel';
10
10
  export { default as ErrorHandler } from './utils/ErrorHandler';
11
+ export { generate, verify, decode } from './utils/TokenGenerator';
11
12
  export { default as DatabaseConnector } from './utils/DatabaseConnector';
12
13
  export { default as BaseSocketHandler } from './utils/BaseSocketHandler';
13
14
  export type { WebSocketData } from './types/BaseSocketType';
package/dist/index.js CHANGED
@@ -88825,7 +88825,7 @@ var require_decode_uri_component = __commonJS((exports, module) => {
88825
88825
  var right = components.slice(split);
88826
88826
  return Array.prototype.concat.call([], decodeComponents(left), decodeComponents(right));
88827
88827
  };
88828
- var decode = function(input) {
88828
+ var decode2 = function(input) {
88829
88829
  try {
88830
88830
  return decodeURIComponent(input);
88831
88831
  } catch (err) {
@@ -88847,7 +88847,7 @@ var require_decode_uri_component = __commonJS((exports, module) => {
88847
88847
  try {
88848
88848
  replaceMap[match[0]] = decodeURIComponent(match[0]);
88849
88849
  } catch (err) {
88850
- var result = decode(match[0]);
88850
+ var result = decode2(match[0]);
88851
88851
  if (result !== match[0]) {
88852
88852
  replaceMap[match[0]] = result;
88853
88853
  }
@@ -97719,8 +97719,8 @@ var require_cookies = __commonJS((exports, module) => {
97719
97719
  if (urlparts.hostname !== cookie.domain && (cookie.domain.charAt(0) !== "." || ("." + urlparts.hostname).substr(-cookie.domain.length) !== cookie.domain)) {
97720
97720
  return false;
97721
97721
  }
97722
- let path4 = this.getPath(urlparts.pathname);
97723
- if (path4.substr(0, cookie.path.length) !== cookie.path) {
97722
+ let path3 = this.getPath(urlparts.pathname);
97723
+ if (path3.substr(0, cookie.path.length) !== cookie.path) {
97724
97724
  return false;
97725
97725
  }
97726
97726
  if (cookie.secure && urlparts.protocol !== "https:") {
@@ -97756,16 +97756,16 @@ var require_cookies = __commonJS((exports, module) => {
97756
97756
  return cookie.expires && cookie.expires < new Date || !cookie.value;
97757
97757
  }
97758
97758
  getPath(pathname) {
97759
- let path4 = (pathname || "/").split("/");
97760
- path4.pop();
97761
- path4 = path4.join("/").trim();
97762
- if (path4.charAt(0) !== "/") {
97763
- path4 = "/" + path4;
97759
+ let path3 = (pathname || "/").split("/");
97760
+ path3.pop();
97761
+ path3 = path3.join("/").trim();
97762
+ if (path3.charAt(0) !== "/") {
97763
+ path3 = "/" + path3;
97764
97764
  }
97765
- if (path4.substr(-1) !== "/") {
97766
- path4 += "/";
97765
+ if (path3.substr(-1) !== "/") {
97766
+ path3 += "/";
97767
97767
  }
97768
- return path4;
97768
+ return path3;
97769
97769
  }
97770
97770
  }
97771
97771
  module.exports = Cookies;
@@ -98129,7 +98129,7 @@ var require_shared = __commonJS((exports, module) => {
98129
98129
  };
98130
98130
  var urllib = __require("url");
98131
98131
  var util = __require("util");
98132
- var fs6 = __require("fs");
98132
+ var fs5 = __require("fs");
98133
98133
  var nmfetch = require_fetch();
98134
98134
  var dns = __require("dns");
98135
98135
  var net = __require("net");
@@ -98479,7 +98479,7 @@ var require_shared = __commonJS((exports, module) => {
98479
98479
  }
98480
98480
  return callback(null, parsedDataUri.data);
98481
98481
  } else if (content.path) {
98482
- return resolveStream(fs6.createReadStream(content.path), callback);
98482
+ return resolveStream(fs5.createReadStream(content.path), callback);
98483
98483
  }
98484
98484
  }
98485
98485
  if (typeof data[key].content === "string" && !["utf8", "usascii", "ascii"].includes(encoding)) {
@@ -98527,7 +98527,7 @@ var require_shared = __commonJS((exports, module) => {
98527
98527
 
98528
98528
  // node_modules/nodemailer/lib/mime-funcs/mime-types.js
98529
98529
  var require_mime_types2 = __commonJS((exports, module) => {
98530
- var path4 = __require("path");
98530
+ var path3 = __require("path");
98531
98531
  var defaultMimeType = "application/octet-stream";
98532
98532
  var defaultExtension = "bin";
98533
98533
  var mimeTypes = new Map([
@@ -100583,7 +100583,7 @@ var require_mime_types2 = __commonJS((exports, module) => {
100583
100583
  if (!filename) {
100584
100584
  return defaultMimeType;
100585
100585
  }
100586
- let parsed = path4.parse(filename);
100586
+ let parsed = path3.parse(filename);
100587
100587
  let extension = (parsed.ext.substr(1) || parsed.name || "").split("?").shift().trim().toLowerCase();
100588
100588
  let value = defaultMimeType;
100589
100589
  if (extensions2.has(extension)) {
@@ -100708,7 +100708,7 @@ var require_punycode = __commonJS((exports, module) => {
100708
100708
  }
100709
100709
  return floor(k + (baseMinusTMin + 1) * delta / (delta + skew));
100710
100710
  };
100711
- var decode = function(input) {
100711
+ var decode2 = function(input) {
100712
100712
  const output = [];
100713
100713
  const inputLength = input.length;
100714
100714
  let i = 0;
@@ -100818,7 +100818,7 @@ var require_punycode = __commonJS((exports, module) => {
100818
100818
  };
100819
100819
  var toUnicode = function(input) {
100820
100820
  return mapDomain(input, function(string) {
100821
- return regexPunycode.test(string) ? decode(string.slice(4).toLowerCase()) : string;
100821
+ return regexPunycode.test(string) ? decode2(string.slice(4).toLowerCase()) : string;
100822
100822
  });
100823
100823
  };
100824
100824
  var toASCII = function(input) {
@@ -100832,7 +100832,7 @@ var require_punycode = __commonJS((exports, module) => {
100832
100832
  decode: ucs2decode,
100833
100833
  encode: ucs2encode
100834
100834
  },
100835
- decode,
100835
+ decode: decode2,
100836
100836
  encode: encode2,
100837
100837
  toASCII,
100838
100838
  toUnicode
@@ -101806,7 +101806,7 @@ var require_le_unix = __commonJS((exports, module) => {
101806
101806
  // node_modules/nodemailer/lib/mime-node/index.js
101807
101807
  var require_mime_node = __commonJS((exports, module) => {
101808
101808
  var crypto4 = __require("crypto");
101809
- var fs6 = __require("fs");
101809
+ var fs5 = __require("fs");
101810
101810
  var punycode = require_punycode();
101811
101811
  var PassThrough = __require("stream").PassThrough;
101812
101812
  var shared = require_shared();
@@ -102406,7 +102406,7 @@ var require_mime_node = __commonJS((exports, module) => {
102406
102406
  setImmediate(() => contentStream.emit("error", new Error("File access rejected for " + content.path)));
102407
102407
  return contentStream;
102408
102408
  }
102409
- return fs6.createReadStream(content.path);
102409
+ return fs5.createReadStream(content.path);
102410
102410
  } else if (content && typeof content.href === "string") {
102411
102411
  if (this.disableUrlAccess) {
102412
102412
  contentStream = new PassThrough;
@@ -103270,8 +103270,8 @@ var require_dkim = __commonJS((exports, module) => {
103270
103270
  var RelaxedBody = require_relaxed_body();
103271
103271
  var sign = require_sign2();
103272
103272
  var PassThrough = __require("stream").PassThrough;
103273
- var fs6 = __require("fs");
103274
- var path4 = __require("path");
103273
+ var fs5 = __require("fs");
103274
+ var path3 = __require("path");
103275
103275
  var crypto4 = __require("crypto");
103276
103276
  var DKIM_ALGO = "sha256";
103277
103277
  var MAX_MESSAGE_SIZE = 128 * 1024;
@@ -103286,7 +103286,7 @@ var require_dkim = __commonJS((exports, module) => {
103286
103286
  this.chunks = [];
103287
103287
  this.chunklen = 0;
103288
103288
  this.readPos = 0;
103289
- this.cachePath = this.cacheDir ? path4.join(this.cacheDir, "message." + Date.now() + "-" + crypto4.randomBytes(14).toString("hex")) : false;
103289
+ this.cachePath = this.cacheDir ? path3.join(this.cacheDir, "message." + Date.now() + "-" + crypto4.randomBytes(14).toString("hex")) : false;
103290
103290
  this.cache = false;
103291
103291
  this.headers = false;
103292
103292
  this.bodyHash = false;
@@ -103306,10 +103306,10 @@ var require_dkim = __commonJS((exports, module) => {
103306
103306
  if (!this.cache || !this.cachePath) {
103307
103307
  return;
103308
103308
  }
103309
- fs6.unlink(this.cachePath, () => false);
103309
+ fs5.unlink(this.cachePath, () => false);
103310
103310
  }
103311
103311
  createReadCache() {
103312
- this.cache = fs6.createReadStream(this.cachePath);
103312
+ this.cache = fs5.createReadStream(this.cachePath);
103313
103313
  this.cache.once("error", (err) => {
103314
103314
  this.cleanup();
103315
103315
  this.output.emit("error", err);
@@ -103365,7 +103365,7 @@ var require_dkim = __commonJS((exports, module) => {
103365
103365
  }
103366
103366
  createWriteCache() {
103367
103367
  this.output.usingCache = true;
103368
- this.cache = fs6.createWriteStream(this.cachePath);
103368
+ this.cache = fs5.createWriteStream(this.cachePath);
103369
103369
  this.cache.once("error", (err) => {
103370
103370
  this.cleanup();
103371
103371
  this.relaxedBody.unpipe(this.cache);
@@ -108490,11 +108490,11 @@ var require_ast = __commonJS((exports, module) => {
108490
108490
  helperExpression: function helperExpression(node) {
108491
108491
  return node.type === "SubExpression" || (node.type === "MustacheStatement" || node.type === "BlockStatement") && !!(node.params && node.params.length || node.hash);
108492
108492
  },
108493
- scopedId: function scopedId(path4) {
108494
- return /^\.|this\b/.test(path4.original);
108493
+ scopedId: function scopedId(path3) {
108494
+ return /^\.|this\b/.test(path3.original);
108495
108495
  },
108496
- simpleId: function simpleId(path4) {
108497
- return path4.parts.length === 1 && !AST.helpers.scopedId(path4) && !path4.depth;
108496
+ simpleId: function simpleId(path3) {
108497
+ return path3.parts.length === 1 && !AST.helpers.scopedId(path3) && !path3.depth;
108498
108498
  }
108499
108499
  }
108500
108500
  };
@@ -109546,12 +109546,12 @@ var require_helpers3 = __commonJS((exports) => {
109546
109546
  loc
109547
109547
  };
109548
109548
  };
109549
- var prepareMustache = function(path4, params, hash, open, strip, locInfo) {
109549
+ var prepareMustache = function(path3, params, hash, open, strip, locInfo) {
109550
109550
  var escapeFlag = open.charAt(3) || open.charAt(2), escaped = escapeFlag !== "{" && escapeFlag !== "&";
109551
109551
  var decorator = /\*/.test(open);
109552
109552
  return {
109553
109553
  type: decorator ? "Decorator" : "MustacheStatement",
109554
- path: path4,
109554
+ path: path3,
109555
109555
  params,
109556
109556
  hash,
109557
109557
  escaped,
@@ -109907,9 +109907,9 @@ var require_compiler = __commonJS((exports) => {
109907
109907
  },
109908
109908
  DecoratorBlock: function DecoratorBlock(decorator) {
109909
109909
  var program = decorator.program && this.compileProgram(decorator.program);
109910
- var params = this.setupFullMustacheParams(decorator, program, undefined), path4 = decorator.path;
109910
+ var params = this.setupFullMustacheParams(decorator, program, undefined), path3 = decorator.path;
109911
109911
  this.useDecorators = true;
109912
- this.opcode("registerDecorator", params.length, path4.original);
109912
+ this.opcode("registerDecorator", params.length, path3.original);
109913
109913
  },
109914
109914
  PartialStatement: function PartialStatement(partial) {
109915
109915
  this.usePartial = true;
@@ -109973,46 +109973,46 @@ var require_compiler = __commonJS((exports) => {
109973
109973
  }
109974
109974
  },
109975
109975
  ambiguousSexpr: function ambiguousSexpr(sexpr, program, inverse) {
109976
- var path4 = sexpr.path, name = path4.parts[0], isBlock = program != null || inverse != null;
109977
- this.opcode("getContext", path4.depth);
109976
+ var path3 = sexpr.path, name = path3.parts[0], isBlock = program != null || inverse != null;
109977
+ this.opcode("getContext", path3.depth);
109978
109978
  this.opcode("pushProgram", program);
109979
109979
  this.opcode("pushProgram", inverse);
109980
- path4.strict = true;
109981
- this.accept(path4);
109980
+ path3.strict = true;
109981
+ this.accept(path3);
109982
109982
  this.opcode("invokeAmbiguous", name, isBlock);
109983
109983
  },
109984
109984
  simpleSexpr: function simpleSexpr(sexpr) {
109985
- var path4 = sexpr.path;
109986
- path4.strict = true;
109987
- this.accept(path4);
109985
+ var path3 = sexpr.path;
109986
+ path3.strict = true;
109987
+ this.accept(path3);
109988
109988
  this.opcode("resolvePossibleLambda");
109989
109989
  },
109990
109990
  helperSexpr: function helperSexpr(sexpr, program, inverse) {
109991
- var params = this.setupFullMustacheParams(sexpr, program, inverse), path4 = sexpr.path, name = path4.parts[0];
109991
+ var params = this.setupFullMustacheParams(sexpr, program, inverse), path3 = sexpr.path, name = path3.parts[0];
109992
109992
  if (this.options.knownHelpers[name]) {
109993
109993
  this.opcode("invokeKnownHelper", params.length, name);
109994
109994
  } else if (this.options.knownHelpersOnly) {
109995
109995
  throw new _exception2["default"]("You specified knownHelpersOnly, but used the unknown helper " + name, sexpr);
109996
109996
  } else {
109997
- path4.strict = true;
109998
- path4.falsy = true;
109999
- this.accept(path4);
110000
- this.opcode("invokeHelper", params.length, path4.original, _ast2["default"].helpers.simpleId(path4));
109997
+ path3.strict = true;
109998
+ path3.falsy = true;
109999
+ this.accept(path3);
110000
+ this.opcode("invokeHelper", params.length, path3.original, _ast2["default"].helpers.simpleId(path3));
110001
110001
  }
110002
110002
  },
110003
- PathExpression: function PathExpression(path4) {
110004
- this.addDepth(path4.depth);
110005
- this.opcode("getContext", path4.depth);
110006
- var name = path4.parts[0], scoped = _ast2["default"].helpers.scopedId(path4), blockParamId = !path4.depth && !scoped && this.blockParamIndex(name);
110003
+ PathExpression: function PathExpression(path3) {
110004
+ this.addDepth(path3.depth);
110005
+ this.opcode("getContext", path3.depth);
110006
+ var name = path3.parts[0], scoped = _ast2["default"].helpers.scopedId(path3), blockParamId = !path3.depth && !scoped && this.blockParamIndex(name);
110007
110007
  if (blockParamId) {
110008
- this.opcode("lookupBlockParam", blockParamId, path4.parts);
110008
+ this.opcode("lookupBlockParam", blockParamId, path3.parts);
110009
110009
  } else if (!name) {
110010
110010
  this.opcode("pushContext");
110011
- } else if (path4.data) {
110011
+ } else if (path3.data) {
110012
110012
  this.options.data = true;
110013
- this.opcode("lookupData", path4.depth, path4.parts, path4.strict);
110013
+ this.opcode("lookupData", path3.depth, path3.parts, path3.strict);
110014
110014
  } else {
110015
- this.opcode("lookupOnContext", path4.parts, path4.falsy, path4.strict, scoped);
110015
+ this.opcode("lookupOnContext", path3.parts, path3.falsy, path3.strict, scoped);
110016
110016
  }
110017
110017
  },
110018
110018
  StringLiteral: function StringLiteral(string) {
@@ -110273,16 +110273,16 @@ var require_util2 = __commonJS((exports) => {
110273
110273
  return url;
110274
110274
  };
110275
110275
  var normalize = function(aPath) {
110276
- var path4 = aPath;
110276
+ var path3 = aPath;
110277
110277
  var url = urlParse(aPath);
110278
110278
  if (url) {
110279
110279
  if (!url.path) {
110280
110280
  return aPath;
110281
110281
  }
110282
- path4 = url.path;
110282
+ path3 = url.path;
110283
110283
  }
110284
- var isAbsolute = exports.isAbsolute(path4);
110285
- var parts = path4.split(/\/+/);
110284
+ var isAbsolute = exports.isAbsolute(path3);
110285
+ var parts = path3.split(/\/+/);
110286
110286
  for (var part, up = 0, i = parts.length - 1;i >= 0; i--) {
110287
110287
  part = parts[i];
110288
110288
  if (part === ".") {
@@ -110299,15 +110299,15 @@ var require_util2 = __commonJS((exports) => {
110299
110299
  }
110300
110300
  }
110301
110301
  }
110302
- path4 = parts.join("/");
110303
- if (path4 === "") {
110304
- path4 = isAbsolute ? "/" : ".";
110302
+ path3 = parts.join("/");
110303
+ if (path3 === "") {
110304
+ path3 = isAbsolute ? "/" : ".";
110305
110305
  }
110306
110306
  if (url) {
110307
- url.path = path4;
110307
+ url.path = path3;
110308
110308
  return urlGenerate(url);
110309
110309
  }
110310
- return path4;
110310
+ return path3;
110311
110311
  };
110312
110312
  var join = function(aRoot, aPath) {
110313
110313
  if (aRoot === "") {
@@ -112857,8 +112857,8 @@ var require_printer = __commonJS((exports) => {
112857
112857
  return this.accept(sexpr.path) + " " + params + hash;
112858
112858
  };
112859
112859
  PrintVisitor.prototype.PathExpression = function(id) {
112860
- var path4 = id.parts.join("/");
112861
- return (id.data ? "@" : "") + "PATH:" + path4;
112860
+ var path3 = id.parts.join("/");
112861
+ return (id.data ? "@" : "") + "PATH:" + path3;
112862
112862
  };
112863
112863
  PrintVisitor.prototype.StringLiteral = function(string) {
112864
112864
  return '"' + string.value + '"';
@@ -112890,8 +112890,8 @@ var require_printer = __commonJS((exports) => {
112890
112890
  // node_modules/handlebars/lib/index.js
112891
112891
  var require_lib10 = __commonJS((exports, module) => {
112892
112892
  var extension = function(module2, filename) {
112893
- var fs6 = __require("fs");
112894
- var templateString = fs6.readFileSync(filename, "utf8");
112893
+ var fs5 = __require("fs");
112894
+ var templateString = fs5.readFileSync(filename, "utf8");
112895
112895
  module2.exports = handlebars.compile(templateString);
112896
112896
  };
112897
112897
  var handlebars = require_handlebars()["default"];
@@ -113646,6 +113646,9 @@ import path from "path";
113646
113646
 
113647
113647
  // src/utils/TokenGenerator.ts
113648
113648
  var import_jsonwebtoken = __toESM(require_jsonwebtoken(), 1);
113649
+ function generate(payload) {
113650
+ return import_jsonwebtoken.default.sign(payload, SECRET_KEY, { expiresIn: EXPIRY, issuer: ISSUER });
113651
+ }
113649
113652
  function verify(token) {
113650
113653
  let decoded = import_jsonwebtoken.default.verify(token, SECRET_KEY);
113651
113654
  if (decoded.iss !== ISSUER) {
@@ -113653,6 +113656,16 @@ function verify(token) {
113653
113656
  }
113654
113657
  return decoded;
113655
113658
  }
113659
+ function decode(val2) {
113660
+ let token = "";
113661
+ if (typeof val2 !== "string") {
113662
+ token = val2.headers["access-token"];
113663
+ } else {
113664
+ token = val2;
113665
+ }
113666
+ let decoded = import_jsonwebtoken.default.decode(token);
113667
+ return decoded;
113668
+ }
113656
113669
  var SECRET_KEY = process.env.JWT_SECRET_KEY ? process.env.JWT_SECRET_KEY : "your-secret-key-here";
113657
113670
  var EXPIRY = process.env.JWT_EXPIRY ? process.env.JWT_EXPIRY : "30 days";
113658
113671
  var ISSUER = process.env.JWT_ISSUER ? process.env.JWT_ISSUER : "*.service";
@@ -113684,6 +113697,7 @@ class RouterFactory {
113684
113697
  resolve();
113685
113698
  });
113686
113699
  } catch (error) {
113700
+ console.log("error", error);
113687
113701
  Logger.error(error);
113688
113702
  reject(error);
113689
113703
  }
@@ -113691,10 +113705,12 @@ class RouterFactory {
113691
113705
  }
113692
113706
  static authenticate(req, res, next, grantPublicAccess = false) {
113693
113707
  try {
113708
+ console.log("req.body", req.body);
113694
113709
  let bearerToken = req.headers.authorization;
113695
113710
  if (bearerToken && bearerToken != null && bearerToken != "null") {
113696
113711
  const token = bearerToken.split(" ")[1];
113697
113712
  let decoded = verify(token);
113713
+ console.log("decoded", decoded);
113698
113714
  } else if (!grantPublicAccess)
113699
113715
  return res.status(401).send({ success: false, error: 1004, errorMessage: "Unauthorized. No access token found on the request." });
113700
113716
  next();
@@ -113707,62 +113723,6 @@ class RouterFactory {
113707
113723
  }
113708
113724
  }
113709
113725
 
113710
- // src/utils/WebSocketServer.ts
113711
- import fs3 from "node:fs";
113712
- import path2 from "node:path";
113713
- class WebSocketServer {
113714
- constructor(port = 5001, dir, folder = "sockets") {
113715
- let handlers = [];
113716
- let fullDir = path2.join(dir, folder);
113717
- fs3.readdirSync(fullDir).forEach((file) => {
113718
- if (file.toLowerCase().indexOf(".ts")) {
113719
- let filePath = path2.join(fullDir, file);
113720
- import(filePath).then((handlerClass) => {
113721
- let path3 = file.replace(".ts", "");
113722
- let handler = new handlerClass.default;
113723
- handlers.push({ path: path3, handler });
113724
- });
113725
- }
113726
- });
113727
- Bun.serve({
113728
- port,
113729
- async fetch(req, server) {
113730
- const url = new URL(req.url);
113731
- let websocket = handlers.find((rec) => rec.path === url.pathname.replaceAll("/", ""));
113732
- if (websocket) {
113733
- await websocket.handler.upgrade(req, server);
113734
- return;
113735
- }
113736
- return new Response("Upgrade failed :(", { status: 500 });
113737
- },
113738
- websocket: {
113739
- async message(ws, message) {
113740
- let websocket = handlers.find((rec) => rec.path === "echo");
113741
- if (websocket) {
113742
- await websocket.handler.accept(ws, message);
113743
- return;
113744
- }
113745
- },
113746
- async open(ws) {
113747
- let websocket = handlers.find((rec) => rec.path === "echo");
113748
- if (websocket) {
113749
- await websocket.handler.connect(ws);
113750
- return;
113751
- }
113752
- },
113753
- async close(ws, code, reason) {
113754
- let websocket = handlers.find((rec) => rec.path === "echo");
113755
- if (websocket) {
113756
- websocket.handler.disconnect(ws, code, reason);
113757
- return;
113758
- }
113759
- }
113760
- }
113761
- });
113762
- Logger.info(`Web Socket Sever ready at: http://127.0.0.1:${port}\n`);
113763
- }
113764
- }
113765
-
113766
113726
  // node_modules/minio/dist/esm/minio.mjs
113767
113727
  var import_async = __toESM(require_async(), 1);
113768
113728
  var import_lodash3 = __toESM(require_lodash(), 1);
@@ -113953,14 +113913,14 @@ import * as crypto from "crypto";
113953
113913
  import * as stream2 from "stream";
113954
113914
 
113955
113915
  // node_modules/minio/dist/esm/internal/async.mjs
113956
- import * as fs4 from "fs";
113916
+ import * as fs3 from "fs";
113957
113917
  import * as stream from "stream";
113958
113918
  import {promisify} from "util";
113959
113919
  import {promises} from "node:fs";
113960
113920
  var streamPromise = {
113961
113921
  pipeline: promisify(stream.pipeline)
113962
113922
  };
113963
- var fstat2 = promisify(fs4.fstat);
113923
+ var fstat2 = promisify(fs3.fstat);
113964
113924
 
113965
113925
  // node_modules/minio/dist/esm/internal/type.mjs
113966
113926
  var ENCRYPTION_TYPES = function(ENCRYPTION_TYPES2) {
@@ -114044,8 +114004,8 @@ function isValidDomain(host) {
114044
114004
  }
114045
114005
  return true;
114046
114006
  }
114047
- function probeContentType(path3) {
114048
- let contentType = mime.lookup(path3);
114007
+ function probeContentType(path2) {
114008
+ let contentType = mime.lookup(path2);
114049
114009
  if (!contentType) {
114050
114010
  contentType = "application/octet-stream";
114051
114011
  }
@@ -114512,10 +114472,10 @@ var import_block_stream2 = __toESM(require_block_stream2(), 1);
114512
114472
  var import_browser_or_node = __toESM(require_lib9(), 1);
114513
114473
  var import_lodash2 = __toESM(require_lodash(), 1);
114514
114474
  import * as crypto3 from "crypto";
114515
- import * as fs5 from "fs";
114475
+ import * as fs4 from "fs";
114516
114476
  import * as http from "http";
114517
114477
  import * as https from "https";
114518
- import * as path3 from "path";
114478
+ import * as path2 from "path";
114519
114479
  import * as stream4 from "stream";
114520
114480
  var import_xml2js = __toESM(require_xml2js(), 1);
114521
114481
 
@@ -114598,11 +114558,11 @@ class CredentialProvider {
114598
114558
 
114599
114559
  // node_modules/minio/dist/esm/signing.mjs
114600
114560
  import * as crypto2 from "crypto";
114601
- var getCanonicalRequest = function(method, path3, headers, signedHeaders, hashedPayload) {
114561
+ var getCanonicalRequest = function(method, path2, headers, signedHeaders, hashedPayload) {
114602
114562
  if (!isString(method)) {
114603
114563
  throw new TypeError('method should be of type "string"');
114604
114564
  }
114605
- if (!isString(path3)) {
114565
+ if (!isString(path2)) {
114606
114566
  throw new TypeError('path should be of type "string"');
114607
114567
  }
114608
114568
  if (!isObject(headers)) {
@@ -114619,8 +114579,8 @@ var getCanonicalRequest = function(method, path3, headers, signedHeaders, hashed
114619
114579
  acc.push(`${i.toLowerCase()}:${val2}`);
114620
114580
  return acc;
114621
114581
  }, []);
114622
- const requestResource = path3.split("?")[0];
114623
- let requestQuery = path3.split("?")[1];
114582
+ const requestResource = path2.split("?")[0];
114583
+ let requestQuery = path2.split("?")[1];
114624
114584
  if (!requestQuery) {
114625
114585
  requestQuery = "";
114626
114586
  }
@@ -114769,12 +114729,12 @@ function presignSignatureV4(request, accessKey, secretKey, sessionToken, region,
114769
114729
  } else {
114770
114730
  query = requestQuery.join("&");
114771
114731
  }
114772
- const path3 = resource + "?" + query;
114773
- const canonicalRequest = getCanonicalRequest(request.method, path3, request.headers, signedHeaders, hashedPayload);
114732
+ const path2 = resource + "?" + query;
114733
+ const canonicalRequest = getCanonicalRequest(request.method, path2, request.headers, signedHeaders, hashedPayload);
114774
114734
  const stringToSign = getStringToSign(canonicalRequest, requestDate, region);
114775
114735
  const signingKey = getSigningKey(requestDate, region, secretKey);
114776
114736
  const signature = crypto2.createHmac("sha256", signingKey).update(stringToSign).digest("hex").toLowerCase();
114777
- return request.protocol + "//" + request.headers.host + path3 + `&X-Amz-Signature=${signature}`;
114737
+ return request.protocol + "//" + request.headers.host + path2 + `&X-Amz-Signature=${signature}`;
114778
114738
  }
114779
114739
  var signV4Algorithm = "AWS4-HMAC-SHA256";
114780
114740
 
@@ -115825,7 +115785,7 @@ class TypedClient {
115825
115785
  if (bucketName) {
115826
115786
  virtualHostStyle = isVirtualHostStyle(this.host, this.protocol, bucketName, this.pathStyle);
115827
115787
  }
115828
- let path4 = "/";
115788
+ let path3 = "/";
115829
115789
  let host = this.host;
115830
115790
  let port;
115831
115791
  if (this.port) {
@@ -115847,18 +115807,18 @@ class TypedClient {
115847
115807
  host = `${bucketName}.${host}`;
115848
115808
  }
115849
115809
  if (objectName) {
115850
- path4 = `/${objectName}`;
115810
+ path3 = `/${objectName}`;
115851
115811
  }
115852
115812
  } else {
115853
115813
  if (bucketName) {
115854
- path4 = `/${bucketName}`;
115814
+ path3 = `/${bucketName}`;
115855
115815
  }
115856
115816
  if (objectName) {
115857
- path4 = `/${bucketName}/${objectName}`;
115817
+ path3 = `/${bucketName}/${objectName}`;
115858
115818
  }
115859
115819
  }
115860
115820
  if (query) {
115861
- path4 += `?${query}`;
115821
+ path3 += `?${query}`;
115862
115822
  }
115863
115823
  reqOptions.headers.host = host;
115864
115824
  if (reqOptions.protocol === "http:" && port !== 80 || reqOptions.protocol === "https:" && port !== 443) {
@@ -115876,7 +115836,7 @@ class TypedClient {
115876
115836
  headers: import_lodash2.default.mapValues(import_lodash2.default.pickBy(reqOptions.headers, isDefined), (v) => v.toString()),
115877
115837
  host,
115878
115838
  port,
115879
- path: path4
115839
+ path: path3
115880
115840
  };
115881
115841
  }
115882
115842
  async setCredentialsProvider(credentialsProvider) {
@@ -116255,7 +116215,7 @@ class TypedClient {
116255
116215
  let partFileStream;
116256
116216
  const objStat = await this.statObject(bucketName, objectName, getOpts);
116257
116217
  const partFile2 = `${filePath}.${objStat.etag}.part.minio`;
116258
- await promises.mkdir(path3.dirname(filePath), {
116218
+ await promises.mkdir(path2.dirname(filePath), {
116259
116219
  recursive: true
116260
116220
  });
116261
116221
  let offset = 0;
@@ -116265,12 +116225,12 @@ class TypedClient {
116265
116225
  return partFile2;
116266
116226
  }
116267
116227
  offset = stats2.size;
116268
- partFileStream = fs5.createWriteStream(partFile2, {
116228
+ partFileStream = fs4.createWriteStream(partFile2, {
116269
116229
  flags: "a"
116270
116230
  });
116271
116231
  } catch (e) {
116272
116232
  if (e instanceof Error && e.code === "ENOENT") {
116273
- partFileStream = fs5.createWriteStream(partFile2, {
116233
+ partFileStream = fs4.createWriteStream(partFile2, {
116274
116234
  flags: "w"
116275
116235
  });
116276
116236
  } else {
@@ -116652,7 +116612,7 @@ class TypedClient {
116652
116612
  }
116653
116613
  metaData = insertContentType(metaData, filePath);
116654
116614
  const stat = await promises.lstat(filePath);
116655
- await this.putObject(bucketName, objectName, fs5.createReadStream(filePath), stat.size, metaData);
116615
+ await this.putObject(bucketName, objectName, fs4.createReadStream(filePath), stat.size, metaData);
116656
116616
  }
116657
116617
  async putObject(bucketName, objectName, stream5, size, metaData) {
116658
116618
  if (!isValidBucketName(bucketName)) {
@@ -119013,11 +118973,11 @@ class Uploader {
119013
118973
  const file = files[index2];
119014
118974
  let filename = file.name.replace(/ /g, "_");
119015
118975
  let newName = new Date;
119016
- let path4 = `/${bucket}/${dir}/${newName.getTime()}`;
118976
+ let path3 = `/${bucket}/${dir}/${newName.getTime()}`;
119017
118977
  let etag = await Uploader.client.putObject(bucket, `${dir}/${newName.getTime()}`, file.data, file.size, { "Content-type": file.mimetype });
119018
118978
  response4.push({
119019
118979
  etag,
119020
- path: path4,
118980
+ path: path3,
119021
118981
  bucket,
119022
118982
  directory: dir,
119023
118983
  objectName: filename,
@@ -119045,7 +119005,7 @@ class Uploader {
119045
119005
  // src/utils/Mailer.ts
119046
119006
  var import_nodemailer = __toESM(require_nodemailer(), 1);
119047
119007
  var import_handlebars = __toESM(require_lib10(), 1);
119048
- import fs6 from "fs";
119008
+ import fs5 from "fs";
119049
119009
  class Mailer {
119050
119010
  static instance;
119051
119011
  transporter;
@@ -119121,7 +119081,7 @@ class Mailer {
119121
119081
  }
119122
119082
  findTemplate(name) {
119123
119083
  return new Promise((resolve, reject) => {
119124
- fs6.readFile(`${this.LOCAL_DIR}${name}.html`, { encoding: "utf-8" }, (err, html) => {
119084
+ fs5.readFile(`${this.LOCAL_DIR}${name}.html`, { encoding: "utf-8" }, (err, html) => {
119125
119085
  if (err) {
119126
119086
  reject(err);
119127
119087
  } else {
@@ -119132,6 +119092,62 @@ class Mailer {
119132
119092
  }
119133
119093
  }
119134
119094
 
119095
+ // src/utils/WebsocketServer.ts
119096
+ import fs6 from "node:fs";
119097
+ import path3 from "node:path";
119098
+ class WebSocketServer {
119099
+ constructor(port = 5001, dir, folder = "sockets") {
119100
+ let handlers = [];
119101
+ let fullDir = path3.join(dir, folder);
119102
+ fs6.readdirSync(fullDir).forEach((file) => {
119103
+ if (file.toLowerCase().indexOf(".ts")) {
119104
+ let filePath = path3.join(fullDir, file);
119105
+ import(filePath).then((handlerClass) => {
119106
+ let path4 = file.replace(".ts", "");
119107
+ let handler = new handlerClass.default;
119108
+ handlers.push({ path: path4, handler });
119109
+ });
119110
+ }
119111
+ });
119112
+ Bun.serve({
119113
+ port,
119114
+ async fetch(req, server) {
119115
+ const url = new URL(req.url);
119116
+ let websocket = handlers.find((rec) => rec.path === url.pathname.replaceAll("/", ""));
119117
+ if (websocket) {
119118
+ await websocket.handler.upgrade(req, server);
119119
+ return;
119120
+ }
119121
+ return new Response("Upgrade failed :(", { status: 500 });
119122
+ },
119123
+ websocket: {
119124
+ async message(ws, message) {
119125
+ let websocket = handlers.find((rec) => rec.path === "echo");
119126
+ if (websocket) {
119127
+ await websocket.handler.accept(ws, message);
119128
+ return;
119129
+ }
119130
+ },
119131
+ async open(ws) {
119132
+ let websocket = handlers.find((rec) => rec.path === "echo");
119133
+ if (websocket) {
119134
+ await websocket.handler.connect(ws);
119135
+ return;
119136
+ }
119137
+ },
119138
+ async close(ws, code, reason) {
119139
+ let websocket = handlers.find((rec) => rec.path === "echo");
119140
+ if (websocket) {
119141
+ websocket.handler.disconnect(ws, code, reason);
119142
+ return;
119143
+ }
119144
+ }
119145
+ }
119146
+ });
119147
+ Logger.info(`Web Socket Sever ready at: http://127.0.0.1:${port}\n`);
119148
+ }
119149
+ }
119150
+
119135
119151
  // src/utils/ApplicationServer.ts
119136
119152
  class ApplicationServer {
119137
119153
  static app;
@@ -119518,7 +119534,6 @@ class BaseController {
119518
119534
  try {
119519
119535
  await this.beforeCreate(req);
119520
119536
  let data = req.body;
119521
- data.createdById = (req.user || {}).id || null;
119522
119537
  let response4 = await this._model?.create(data);
119523
119538
  await this.afterCreate(req, response4);
119524
119539
  return ResponseHelper(response4);
@@ -119683,7 +119698,10 @@ var PrivateAccess = (constructor) => {
119683
119698
  };
119684
119699
  };
119685
119700
  export {
119701
+ verify,
119702
+ generate,
119686
119703
  endpoint,
119704
+ decode,
119687
119705
  RouterFactory,
119688
119706
  ResponseHelper,
119689
119707
  PublicAccess,
@@ -1,4 +1,4 @@
1
1
  export default class WebSocketServer {
2
2
  constructor(port: number | undefined, dir: string, folder?: string);
3
3
  }
4
- //# sourceMappingURL=WebSocketServer.d.ts.map
4
+ //# sourceMappingURL=WebsocketServer.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ccci/micro-server",
3
- "version": "1.0.53",
3
+ "version": "1.0.55",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",