zaions-express-tool-kit
Advanced tools
Comparing version 0.0.27 to 0.0.28
@@ -1,2 +0,2 @@ | ||
'use strict';var zaionsToolKit=require('zaions-tool-kit'),X=require('cors'),express=require('express'),expressRateLimit=require('express-rate-limit'),zod=require('zod');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var X__default=/*#__PURE__*/_interopDefault(X);var N=Object.defineProperty,G=Object.defineProperties;var P=Object.getOwnPropertyDescriptors;var D=Object.getOwnPropertySymbols;var J=Object.prototype.hasOwnProperty,Q=Object.prototype.propertyIsEnumerable;var b=(e,s,n)=>s in e?N(e,s,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[s]=n,f=(e,s)=>{for(var n in s||(s={}))J.call(s,n)&&b(e,n,s[n]);if(D)for(var n of D(s))Q.call(s,n)&&b(e,n,s[n]);return e},M=(e,s)=>G(e,P(s));var L=(e,s,n)=>new Promise((r,t)=>{var o=a=>{try{u(n.next(a));}catch(d){t(d);}},l=a=>{try{u(n.throw(a));}catch(d){t(d);}},u=a=>a.done?r(a.value):Promise.resolve(a.value).then(o,l);u((n=n.apply(e,s)).next());});var F=null,E=()=>F,x=e=>{F=f({},e);};var W=e=>{let{rateLimiterOptions:s}=e;s&&x(s);};var p=(e,s)=>{let{success:n=!0,message:r=zaionsToolKit.ztkMessages.general.success,data:t=null,dataList:o=null,authToken:l=null,errors:u=null,code:a=zaionsToolKit.ResponseCodeEnum.success,status:d=zaionsToolKit.ResponseStatusEnum.success}=s||{};return e.status(d).json({success:n,message:r,result:{data:t,dataList:o,authToken:l},errors:u,code:a,status:d})},A=(e,s)=>{let{message:n=zaionsToolKit.ztkMessages.general.success,data:r=null,dataList:t=null,authToken:o=null,code:l=zaionsToolKit.ResponseCodeEnum.success,status:u=zaionsToolKit.ResponseStatusEnum.success}=s||{};return p(e,{success:!0,message:n,data:r,dataList:t,authToken:o,errors:null,code:l,status:u})},w=(e,s)=>{let{message:n=zaionsToolKit.ztkMessages.general.failed,errors:r=null,code:t=zaionsToolKit.ResponseCodeEnum.failed,status:o=zaionsToolKit.ResponseStatusEnum.failed}=s||{};return p(e,{success:!1,message:n,data:null,errors:r,code:t,status:o})},y=(e,s)=>{let{message:n=zaionsToolKit.ztkMessages.general.badRequest,errors:r=null,code:t=zaionsToolKit.ResponseCodeEnum.badRequest,status:o=zaionsToolKit.ResponseStatusEnum.badRequest}=s||{};return p(e,{success:!1,message:n,data:null,errors:r,code:t,status:o})},Z=(e,s)=>{let{message:n=zaionsToolKit.ztkMessages.general.unAuthenticated,errors:r=null,code:t=zaionsToolKit.ResponseCodeEnum.unAuthenticated,status:o=zaionsToolKit.ResponseStatusEnum.unAuthenticated}=s||{};return p(e,{success:!1,message:n,data:null,errors:r,code:t,status:o})},h=(e,s)=>{let{message:n=zaionsToolKit.ztkMessages.general.unAuthorized,errors:r=null,code:t=zaionsToolKit.ResponseCodeEnum.unAuthorized,status:o=zaionsToolKit.ResponseStatusEnum.unAuthorized}=s||{};return p(e,{success:!1,message:n,data:null,errors:r,code:t,status:o})},q=(e,s)=>{let{message:n=zaionsToolKit.ztkMessages.general.notFound,errors:r=null,code:t=zaionsToolKit.ResponseCodeEnum.notFound,status:o=zaionsToolKit.ResponseStatusEnum.notFound}=s||{};return p(e,{success:!1,message:n,data:null,errors:r,code:t,status:o})},O=(e,s)=>{let{message:n=zaionsToolKit.ztkMessages.general.tooManyRequests,errors:r=null,code:t=zaionsToolKit.ResponseCodeEnum.tooManyRequests,status:o=zaionsToolKit.ResponseStatusEnum.tooManyRequests}=s||{};return p(e,{success:!1,message:n,data:null,errors:r,code:t,status:o})},S=(e,s)=>{let{message:n=zaionsToolKit.ztkMessages.general.itemExists,errors:r=null,code:t=zaionsToolKit.ResponseCodeEnum.itemExists,status:o=zaionsToolKit.ResponseStatusEnum.itemExists}=s||{};return p(e,{success:!1,message:n,data:null,errors:r,code:t,status:o})};var i=E(),j,z,V,U,ne=expressRateLimit.rateLimit({windowMs:(j=i==null?void 0:i.windowMs)!=null?j:15*60*1e3,limit:(z=i==null?void 0:i.limit)!=null?z:100,standardHeaders:(V=i==null?void 0:i.standardHeaders)!=null?V:"draft-7",legacyHeaders:(U=i==null?void 0:i.legacyHeaders)!=null?U:!1,keyGenerator:e=>{let s=e.headers?e.headers["x-forwarded-for"]:e.socket.remoteAddress;return s?s.toString():""},handler:(e,s)=>s.status(429).json({error:"Too many requests, please try again later."})}),oe=(e,{applyCors:s,expressJson:n,expressUrlEncoded:r,applyRateLimiter:t=!0,expressRateLimiter:o})=>{t&&(o?e.use(o):e.use(ne)),s&&e.use(X__default.default({origin:"*"})),r&&e.use(express.urlencoded()),n&&e.use(express.json());},te=e=>{e.use("*",(s,n)=>{w(n,{code:zaionsToolKit.ResponseCodeEnum.invalidRequest,status:zaionsToolKit.ResponseStatusEnum.invalidRequest});});};var C=e=>e&&typeof e=="object"&&"statusCode"in e&&"statusMessage"in e;function I(e){return zod.z.number().superRefine((s,n)=>{e.includes(s)||n.addIssue({code:zod.z.ZodIssueCode.invalid_enum_value,options:[...e],received:s});})}var T=r=>L(void 0,[r],function*({req:e,res:s,validationSchema:n}){var l,u,a,d,k;let t=f({},e.body),o;try{n.parse(t);}catch(K){o=K;}return (l=o==null?void 0:o.formErrors)!=null&&l.fieldErrors?y(s,{message:'Error occurred in "validateRequestInputData" helper function.',errors:M(f({},(a=(u=o==null?void 0:o.formErrors)==null?void 0:u.fieldErrors)!=null?a:{}),{formErrors:[...(k=(d=o==null?void 0:o.formErrors)==null?void 0:d.formErrors)!=null?k:[]]})}):t});var H=zod.z.object({name:zod.z.string().trim().min(1,{message:"Name is Required."}).max(255),email:zod.z.string().email().max(255),password:zod.z.string().min(6).max(30),passwordConfirmation:zod.z.string().min(6).max(30)}).superRefine((e,s)=>{e.passwordConfirmation!==e.password&&s.addIssue({code:"custom",message:"The passwords did not match",path:["passwordConfirmation"]});}),B=zod.z.object({email:zod.z.string().email().max(255),password:zod.z.string().min(6).max(30)});exports.applyMiddlewaresOnApp=oe;exports.configureZETK=W;exports.getExpressRateLimiterOptions=E;exports.invalidRequestHandler=te;exports.isApiResponse=C;exports.loginRequestValidationSchema=B;exports.numericEnum=I;exports.registerRequestValidationSchema=H;exports.sendApiFailedResponse=w;exports.sendApiResponse=p;exports.sendApiSuccessResponse=A;exports.sendBadRequestResponse=y;exports.sendItemExistsErrorResponse=S;exports.sendNotFoundErrorResponse=q;exports.sendTooManyRequestsErrorResponse=O;exports.sendUnAuthenticatedErrorResponse=Z;exports.sendUnAuthorizedErrorResponse=h;exports.setExpressRateLimiterOptions=x;exports.validateRequestInputData=T;//# sourceMappingURL=index.js.map | ||
'use strict';var zaionsToolKit=require('zaions-tool-kit'),X=require('cors'),express=require('express'),expressRateLimit=require('express-rate-limit'),zod=require('zod');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var X__default=/*#__PURE__*/_interopDefault(X);var N=Object.defineProperty,G=Object.defineProperties;var P=Object.getOwnPropertyDescriptors;var D=Object.getOwnPropertySymbols;var J=Object.prototype.hasOwnProperty,Q=Object.prototype.propertyIsEnumerable;var b=(e,s,n)=>s in e?N(e,s,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[s]=n,f=(e,s)=>{for(var n in s||(s={}))J.call(s,n)&&b(e,n,s[n]);if(D)for(var n of D(s))Q.call(s,n)&&b(e,n,s[n]);return e},M=(e,s)=>G(e,P(s));var L=(e,s,n)=>new Promise((r,t)=>{var o=a=>{try{u(n.next(a));}catch(d){t(d);}},l=a=>{try{u(n.throw(a));}catch(d){t(d);}},u=a=>a.done?r(a.value):Promise.resolve(a.value).then(o,l);u((n=n.apply(e,s)).next());});var F=null,E=()=>F,x=e=>{F=f({},e);};var W=e=>{let{rateLimiterOptions:s}=e;s&&x(s);};var p=(e,s)=>{let{success:n=!0,message:r=zaionsToolKit.ztkMessages.general.success,data:t=null,dataList:o=null,authToken:l=null,errors:u=null,code:a=zaionsToolKit.ResponseCodeEnum.success,status:d=zaionsToolKit.ResponseStatusEnum.success}=s||{};return e.status(d).json({success:n,message:r,result:{data:t,dataList:o,authToken:l},errors:u,code:a,status:d})},A=(e,s)=>{let{message:n=zaionsToolKit.ztkMessages.general.success,data:r=null,dataList:t=null,authToken:o=null,code:l=zaionsToolKit.ResponseCodeEnum.success,status:u=zaionsToolKit.ResponseStatusEnum.success}=s||{};return p(e,{success:!0,message:n,data:r,dataList:t,authToken:o,errors:null,code:l,status:u})},w=(e,s)=>{let{message:n=zaionsToolKit.ztkMessages.general.failed,errors:r=null,code:t=zaionsToolKit.ResponseCodeEnum.failed,status:o=zaionsToolKit.ResponseStatusEnum.failed}=s||{};return p(e,{success:!1,message:n,data:null,errors:r,code:t,status:o})},y=(e,s)=>{let{message:n=zaionsToolKit.ztkMessages.general.badRequest,errors:r=null,code:t=zaionsToolKit.ResponseCodeEnum.badRequest,status:o=zaionsToolKit.ResponseStatusEnum.badRequest}=s||{};return p(e,{success:!1,message:n,data:null,errors:r,code:t,status:o})},Z=(e,s)=>{let{message:n=zaionsToolKit.ztkMessages.general.unAuthenticated,errors:r=null,code:t=zaionsToolKit.ResponseCodeEnum.unAuthenticated,status:o=zaionsToolKit.ResponseStatusEnum.unAuthenticated}=s||{};return p(e,{success:!1,message:n,data:null,errors:r,code:t,status:o})},h=(e,s)=>{let{message:n=zaionsToolKit.ztkMessages.general.unAuthorized,errors:r=null,code:t=zaionsToolKit.ResponseCodeEnum.unAuthorized,status:o=zaionsToolKit.ResponseStatusEnum.unAuthorized}=s||{};return p(e,{success:!1,message:n,data:null,errors:r,code:t,status:o})},q=(e,s)=>{let{message:n=zaionsToolKit.ztkMessages.general.notFound,errors:r=null,code:t=zaionsToolKit.ResponseCodeEnum.notFound,status:o=zaionsToolKit.ResponseStatusEnum.notFound}=s||{};return p(e,{success:!1,message:n,data:null,errors:r,code:t,status:o})},O=(e,s)=>{let{message:n=zaionsToolKit.ztkMessages.general.tooManyRequests,errors:r=null,code:t=zaionsToolKit.ResponseCodeEnum.tooManyRequests,status:o=zaionsToolKit.ResponseStatusEnum.tooManyRequests}=s||{};return p(e,{success:!1,message:n,data:null,errors:r,code:t,status:o})},S=(e,s)=>{let{message:n=zaionsToolKit.ztkMessages.general.itemExists,errors:r=null,code:t=zaionsToolKit.ResponseCodeEnum.itemExists,status:o=zaionsToolKit.ResponseStatusEnum.itemExists}=s||{};return p(e,{success:!1,message:n,data:null,errors:r,code:t,status:o})};var i=E(),j,z,V,U,ne=expressRateLimit.rateLimit({windowMs:(j=i==null?void 0:i.windowMs)!=null?j:15*60*1e3,limit:(z=i==null?void 0:i.limit)!=null?z:100,standardHeaders:(V=i==null?void 0:i.standardHeaders)!=null?V:"draft-7",legacyHeaders:(U=i==null?void 0:i.legacyHeaders)!=null?U:!1,keyGenerator:e=>{let s=e.headers?e.headers["x-forwarded-for"]:e.socket.remoteAddress;return s?s.toString():""},handler:(e,s)=>s.status(429).json({error:"Too many requests, please try again later."})}),oe=(e,{applyCors:s,expressJson:n,expressUrlEncoded:r,applyRateLimiter:t=!0,expressRateLimiter:o})=>{t&&(o?e.use(o):e.use(ne)),s&&e.use(X__default.default({origin:"*"})),r&&e.use(express.urlencoded()),n&&e.use(express.json());},te=e=>{e.use(/(.*)/,(s,n)=>{w(n,{code:zaionsToolKit.ResponseCodeEnum.invalidRequest,status:zaionsToolKit.ResponseStatusEnum.invalidRequest});});};var C=e=>e&&typeof e=="object"&&"statusCode"in e&&"statusMessage"in e;function I(e){return zod.z.number().superRefine((s,n)=>{e.includes(s)||n.addIssue({code:zod.z.ZodIssueCode.invalid_enum_value,options:[...e],received:s});})}var T=r=>L(void 0,[r],function*({req:e,res:s,validationSchema:n}){var l,u,a,d,k;let t=f({},e.body),o;try{n.parse(t);}catch(K){o=K;}return (l=o==null?void 0:o.formErrors)!=null&&l.fieldErrors?y(s,{message:'Error occurred in "validateRequestInputData" helper function.',errors:M(f({},(a=(u=o==null?void 0:o.formErrors)==null?void 0:u.fieldErrors)!=null?a:{}),{formErrors:[...(k=(d=o==null?void 0:o.formErrors)==null?void 0:d.formErrors)!=null?k:[]]})}):t});var H=zod.z.object({name:zod.z.string().trim().min(1,{message:"Name is Required."}).max(255),email:zod.z.string().email().max(255),password:zod.z.string().min(6).max(30),passwordConfirmation:zod.z.string().min(6).max(30)}).superRefine((e,s)=>{e.passwordConfirmation!==e.password&&s.addIssue({code:"custom",message:"The passwords did not match",path:["passwordConfirmation"]});}),B=zod.z.object({email:zod.z.string().email().max(255),password:zod.z.string().min(6).max(30)});exports.applyMiddlewaresOnApp=oe;exports.configureZETK=W;exports.getExpressRateLimiterOptions=E;exports.invalidRequestHandler=te;exports.isApiResponse=C;exports.loginRequestValidationSchema=B;exports.numericEnum=I;exports.registerRequestValidationSchema=H;exports.sendApiFailedResponse=w;exports.sendApiResponse=p;exports.sendApiSuccessResponse=A;exports.sendBadRequestResponse=y;exports.sendItemExistsErrorResponse=S;exports.sendNotFoundErrorResponse=q;exports.sendTooManyRequestsErrorResponse=O;exports.sendUnAuthenticatedErrorResponse=Z;exports.sendUnAuthorizedErrorResponse=h;exports.setExpressRateLimiterOptions=x;exports.validateRequestInputData=T;//# sourceMappingURL=index.js.map | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "zaions-express-tool-kit", | ||
"version": "0.0.27", | ||
"version": "0.0.28", | ||
"description": "Zaions Express Tool Kit, this is for expressJs/Typescript projects created by Zaions Dev Team (https://zaions.com), We hope you will love this and all other packages we have developed for you, please do react out if you face any issue in packages we deliver. Once again have fun while working with these packages and let us know your feedback, it keeps us motivated. Have a great day :)", | ||
@@ -72,3 +72,3 @@ "main": "./dist/index.js", | ||
"@types/express": "^5.0.0", | ||
"@types/node": "^22.8.4", | ||
"@types/node": "^22.8.5", | ||
"cors": "^2.8.5", | ||
@@ -75,0 +75,0 @@ "crypto-js": "^4.2.0", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
70701