elseware-nodejs 1.11.4 → 1.11.6

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.cjs CHANGED
@@ -27,8 +27,7 @@ var juice__default = /*#__PURE__*/_interopDefault(juice);
27
27
  var jwt__default = /*#__PURE__*/_interopDefault(jwt);
28
28
  var multer__default = /*#__PURE__*/_interopDefault(multer);
29
29
 
30
- // src/core/constants/defaultOrigins.ts
31
- var DEFAULT_ALLOWED_ORIGINS = ["http://localhost:3000"];
30
+ // src/core/environment/loadEnv.ts
32
31
 
33
32
  // src/utils/errorToString.ts
34
33
  function errorToString(error) {
@@ -4863,41 +4862,52 @@ var SegmentTree = class {
4863
4862
  }
4864
4863
  };
4865
4864
 
4866
- // src/infrastructure/cors/createAllowedOrigins.ts
4867
- function createAllowedOrigins(options = {}) {
4868
- const { origins, defaults = DEFAULT_ALLOWED_ORIGINS } = options;
4869
- let allowedOrigins = [];
4870
- if (typeof origins === "string") {
4871
- allowedOrigins = origins.split(",").map((origin) => origin.trim()).filter(Boolean);
4872
- }
4873
- if (Array.isArray(origins)) {
4874
- allowedOrigins = origins.map((origin) => origin.trim()).filter(Boolean);
4875
- }
4876
- if (allowedOrigins.length === 0) {
4877
- allowedOrigins = [...defaults];
4878
- }
4879
- return allowedOrigins;
4865
+ // src/infrastructure/cors/isAllowedOrigin.ts
4866
+ function isAllowedOrigin(origin, allowedOrigins) {
4867
+ return allowedOrigins.some((allowedOrigin) => {
4868
+ if (allowedOrigin === "*") {
4869
+ return true;
4870
+ }
4871
+ if (allowedOrigin === origin) {
4872
+ return true;
4873
+ }
4874
+ if (allowedOrigin.startsWith("*.") && origin.endsWith(allowedOrigin.slice(1))) {
4875
+ return true;
4876
+ }
4877
+ return false;
4878
+ });
4880
4879
  }
4881
4880
 
4882
4881
  // src/infrastructure/cors/createCorsOptions.ts
4883
- function createCorsOptions(allowedOrigins) {
4882
+ function createCorsOptions(config) {
4883
+ const {
4884
+ allowedOrigins,
4885
+ allowCredentials = true,
4886
+ allowedMethods = ["GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"],
4887
+ allowedHeaders = [
4888
+ "Content-Type",
4889
+ "Authorization",
4890
+ "X-Requested-With",
4891
+ "Accept"
4892
+ ],
4893
+ exposedHeaders = ["Set-Cookie"],
4894
+ optionsSuccessStatus = 204
4895
+ } = config;
4884
4896
  return {
4885
4897
  origin(origin, callback) {
4886
- if (!origin || allowedOrigins.includes(origin)) {
4898
+ if (!origin) {
4899
+ return callback(null, true);
4900
+ }
4901
+ if (isAllowedOrigin(origin, allowedOrigins)) {
4887
4902
  return callback(null, true);
4888
4903
  }
4889
4904
  return callback(new Error(`CORS blocked: ${origin} is not allowed`));
4890
4905
  },
4891
- credentials: true,
4892
- methods: ["GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"],
4893
- allowedHeaders: [
4894
- "Content-Type",
4895
- "Authorization",
4896
- "X-Requested-With",
4897
- "Accept"
4898
- ],
4899
- exposedHeaders: ["Set-Cookie"],
4900
- optionsSuccessStatus: 204
4906
+ credentials: allowCredentials,
4907
+ methods: allowedMethods,
4908
+ allowedHeaders,
4909
+ exposedHeaders,
4910
+ optionsSuccessStatus
4901
4911
  };
4902
4912
  }
4903
4913
 
@@ -6358,7 +6368,6 @@ exports.ConsistentHash = ConsistentHash;
6358
6368
  exports.CorrelationId = CorrelationId;
6359
6369
  exports.CountMinSketch = CountMinSketch;
6360
6370
  exports.CrudControllerFactory = CrudControllerFactory;
6361
- exports.DEFAULT_ALLOWED_ORIGINS = DEFAULT_ALLOWED_ORIGINS;
6362
6371
  exports.DEFAULT_LIMIT = DEFAULT_LIMIT;
6363
6372
  exports.DEFAULT_PAGE = DEFAULT_PAGE;
6364
6373
  exports.DEFAULT_SORT_DIRECTION = DEFAULT_SORT_DIRECTION;
@@ -6427,12 +6436,12 @@ exports.TreeNode = TreeNode;
6427
6436
  exports.Trie = Trie;
6428
6437
  exports.ZodValidator = ZodValidator;
6429
6438
  exports.authMiddleware = authMiddleware;
6430
- exports.createAllowedOrigins = createAllowedOrigins;
6431
6439
  exports.createCorsOptions = createCorsOptions;
6432
6440
  exports.createRequestContextMiddleware = createRequestContextMiddleware;
6433
6441
  exports.days = days;
6434
6442
  exports.errorToString = errorToString;
6435
6443
  exports.hours = hours;
6444
+ exports.isAllowedOrigin = isAllowedOrigin;
6436
6445
  exports.isJoiSchema = isJoiSchema;
6437
6446
  exports.isZodSchema = isZodSchema;
6438
6447
  exports.loadEnv = loadEnv;