zaions-express-tool-kit
Advanced tools
Comparing version 0.0.15 to 0.0.16
'use strict'; | ||
var j = require('cors'); | ||
var G = require('cors'); | ||
var express = require('express'); | ||
@@ -11,26 +11,26 @@ var zaionsToolKit = require('zaions-tool-kit'); | ||
var j__default = /*#__PURE__*/_interopDefault(j); | ||
var G__default = /*#__PURE__*/_interopDefault(G); | ||
var I=Object.defineProperty;var x=Object.getOwnPropertySymbols;var M=Object.prototype.hasOwnProperty,O=Object.prototype.propertyIsEnumerable;var E=(e,s,o)=>s in e?I(e,s,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[s]=o,g=(e,s)=>{for(var o in s||(s={}))M.call(s,o)&&E(e,o,s[o]);if(x)for(var o of x(s))O.call(s,o)&&E(e,o,s[o]);return e};var w=(e,s,o)=>new Promise((r,n)=>{var t=u=>{try{p(o.next(u));}catch(f){n(f);}},c=u=>{try{p(o.throw(u));}catch(f){n(f);}},p=u=>u.done?r(u.value):Promise.resolve(u.value).then(t,c);p((o=o.apply(e,s)).next());});var y=null,h=()=>y,k=e=>{y=g({},e);};var G=e=>{let{rateLimiterOptions:s}=e;s&&k(s);};var l=(e,s)=>{let{success:o=!0,message:r=zaionsToolKit.ztkMessages.general.success,data:n=null,dataList:t=null,authToken:c=null,errors:p=null,code:u=zaionsToolKit.ResponseCodeEnum.success,status:f=zaionsToolKit.ResponseStatusEnum.success}=s||{};return e.status(f).json({success:o,message:r,result:{data:n,dataList:t,authToken:c},errors:p,code:u,status:f})},J=(e,s)=>{let{message:o=zaionsToolKit.ztkMessages.general.success,data:r=null,dataList:n=null,authToken:t=null,code:c=zaionsToolKit.ResponseCodeEnum.success,status:p=zaionsToolKit.ResponseStatusEnum.success}=s||{};return l(e,{success:!0,message:o,data:r,dataList:n,authToken:t,errors:null,code:c,status:p})},q=(e,s)=>{let{message:o=zaionsToolKit.ztkMessages.general.failed,errors:r=null,code:n=zaionsToolKit.ResponseCodeEnum.failed,status:t=zaionsToolKit.ResponseStatusEnum.failed}=s||{};return l(e,{success:!1,message:o,data:null,errors:r,code:n,status:t})},C=(e,s)=>{let{message:o=zaionsToolKit.ztkMessages.general.badRequest,errors:r=null,code:n=zaionsToolKit.ResponseCodeEnum.badRequest,status:t=zaionsToolKit.ResponseStatusEnum.badRequest}=s||{};return l(e,{success:!1,message:o,data:null,errors:r,code:n,status:t})},Q=(e,s)=>{let{message:o=zaionsToolKit.ztkMessages.general.unAuthenticated,errors:r=null,code:n=zaionsToolKit.ResponseCodeEnum.unAuthenticated,status:t=zaionsToolKit.ResponseStatusEnum.unAuthenticated}=s||{};return l(e,{success:!1,message:o,data:null,errors:r,code:n,status:t})},W=(e,s)=>{let{message:o=zaionsToolKit.ztkMessages.general.unAuthorized,errors:r=null,code:n=zaionsToolKit.ResponseCodeEnum.unAuthorized,status:t=zaionsToolKit.ResponseStatusEnum.unAuthorized}=s||{};return l(e,{success:!1,message:o,data:null,errors:r,code:n,status:t})},X=(e,s)=>{let{message:o=zaionsToolKit.ztkMessages.general.notFound,errors:r=null,code:n=zaionsToolKit.ResponseCodeEnum.notFound,status:t=zaionsToolKit.ResponseStatusEnum.notFound}=s||{};return l(e,{success:!1,message:o,data:null,errors:r,code:n,status:t})},Y=(e,s)=>{let{message:o=zaionsToolKit.ztkMessages.general.tooManyRequests,errors:r=null,code:n=zaionsToolKit.ResponseCodeEnum.tooManyRequests,status:t=zaionsToolKit.ResponseStatusEnum.tooManyRequests}=s||{};return l(e,{success:!1,message:o,data:null,errors:r,code:n,status:t})},$=(e,s)=>{let{message:o=zaionsToolKit.ztkMessages.general.itemExists,errors:r=null,code:n=zaionsToolKit.ResponseCodeEnum.itemExists,status:t=zaionsToolKit.ResponseStatusEnum.itemExists}=s||{};return l(e,{success:!1,message:o,data:null,errors:r,code:n,status:t})};var a=h(),T,S,b,A,K=expressRateLimit.rateLimit({windowMs:(T=a==null?void 0:a.windowMs)!=null?T:15*60*1e3,limit:(S=a==null?void 0:a.limit)!=null?S:100,standardHeaders:(b=a==null?void 0:a.standardHeaders)!=null?b:"draft-7",legacyHeaders:(A=a==null?void 0:a.legacyHeaders)!=null?A:!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."})}),ae=(e,{applyCors:s,expressJson:o,expressUrlEncoded:r,applyRateLimiter:n=!0,expressRateLimiter:t})=>{n&&(t?e.use(t):e.use(K)),s&&e.use(j__default.default({origin:"*"})),r&&e.use(express.urlencoded()),o&&e.use(express.json());},ue=e=>{e.use("*",(s,o)=>{q(o,{code:zaionsToolKit.ResponseCodeEnum.invalidRequest,status:zaionsToolKit.ResponseStatusEnum.invalidRequest});});};var me=e=>e&&typeof e=="object"&&"statusCode"in e&&"statusMessage"in e;function Re(e){return zod.z.number().superRefine((s,o)=>{e.includes(s)||o.addIssue({code:zod.z.ZodIssueCode.invalid_enum_value,options:[...e],received:s});})}var xe=r=>w(void 0,[r],function*({req:e,res:s,validationSchema:o}){var c,p;let n=g({},e.body),t;try{o.parse(n);}catch(u){t=u;}return (c=t==null?void 0:t.formErrors)!=null&&c.fieldErrors?C(s,{errors:(p=t==null?void 0:t.formErrors)==null?void 0:p.fieldErrors}):n});var Ze=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"]});}),Ie=zod.z.object({email:zod.z.string().email().max(255),password:zod.z.string().min(6).max(30)}); | ||
var B=Object.defineProperty;var M=Object.getOwnPropertySymbols;var D=Object.prototype.hasOwnProperty,N=Object.prototype.propertyIsEnumerable;var Z=(e,s,n)=>s in e?B(e,s,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[s]=n,h=(e,s)=>{for(var n in s||(s={}))D.call(s,n)&&Z(e,n,s[n]);if(M)for(var n of M(s))N.call(s,n)&&Z(e,n,s[n]);return e};var b=(e,s,n)=>new Promise((r,t)=>{var o=u=>{try{i(n.next(u));}catch(E){t(E);}},c=u=>{try{i(n.throw(u));}catch(E){t(E);}},i=u=>u.done?r(u.value):Promise.resolve(u.value).then(o,c);i((n=n.apply(e,s)).next());});var L=null,f=()=>L,g=e=>{L=h({},e);};var v=e=>{let{rateLimiterOptions:s}=e;s&&g(s);};var p=(e,s)=>{let{success:n=!0,message:r=zaionsToolKit.ztkMessages.general.success,data:t=null,dataList:o=null,authToken:c=null,errors:i=null,code:u=zaionsToolKit.ResponseCodeEnum.success,status:E=zaionsToolKit.ResponseStatusEnum.success}=s||{};return e.status(E).json({success:n,message:r,result:{data:t,dataList:o,authToken:c},errors:i,code:u,status:E})},q=(e,s)=>{let{message:n=zaionsToolKit.ztkMessages.general.success,data:r=null,dataList:t=null,authToken:o=null,code:c=zaionsToolKit.ResponseCodeEnum.success,status:i=zaionsToolKit.ResponseStatusEnum.success}=s||{};return p(e,{success:!0,message:n,data:r,dataList:t,authToken:o,errors:null,code:c,status:i})},x=(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})},A=(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})},w=(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})},y=(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})},I=(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})},T=(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})},k=(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 a=f(),F,z,j,V,Y=expressRateLimit.rateLimit({windowMs:(F=a==null?void 0:a.windowMs)!=null?F:15*60*1e3,limit:(z=a==null?void 0:a.limit)!=null?z:100,standardHeaders:(j=a==null?void 0:a.standardHeaders)!=null?j:"draft-7",legacyHeaders:(V=a==null?void 0:a.legacyHeaders)!=null?V:!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."})}),$=(e,{applyCors:s,expressJson:n,expressUrlEncoded:r,applyRateLimiter:t=!0,expressRateLimiter:o})=>{t&&(o?e.use(o):e.use(Y)),s&&e.use(G__default.default({origin:"*"})),r&&e.use(express.urlencoded()),n&&e.use(express.json());},_=e=>{e.use("*",(s,n)=>{x(n,{code:zaionsToolKit.ResponseCodeEnum.invalidRequest,status:zaionsToolKit.ResponseStatusEnum.invalidRequest});});};var O=e=>e&&typeof e=="object"&&"statusCode"in e&&"statusMessage"in e;function S(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 C=r=>b(void 0,[r],function*({req:e,res:s,validationSchema:n}){var c,i;let t=h({},e.body),o;try{n.parse(t);}catch(u){o=u;}return (c=o==null?void 0:o.formErrors)!=null&&c.fieldErrors?A(s,{errors:(i=o==null?void 0:o.formErrors)==null?void 0:i.fieldErrors}):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"]});}),K=zod.z.object({email:zod.z.string().email().max(255),password:zod.z.string().min(6).max(30)}); | ||
exports.applyMiddlewaresOnApp = ae; | ||
exports.configureZETK = G; | ||
exports.getExpressRateLimiterOptions = h; | ||
exports.invalidRequestHandler = ue; | ||
exports.isApiResponse = me; | ||
exports.loginRequestValidationSchema = Ie; | ||
exports.numericEnum = Re; | ||
exports.registerRequestValidationSchema = Ze; | ||
exports.sendApiFailedResponse = q; | ||
exports.sendApiResponse = l; | ||
exports.sendApiSuccessResponse = J; | ||
exports.sendBadRequestResponse = C; | ||
exports.sendItemExistsErrorResponse = $; | ||
exports.sendNotFoundErrorResponse = X; | ||
exports.sendTooManyRequestsErrorResponse = Y; | ||
exports.sendUnAuthenticatedErrorResponse = Q; | ||
exports.sendUnAuthorizedErrorResponse = W; | ||
exports.setExpressRateLimiterOptions = k; | ||
exports.validateRequestInputData = xe; | ||
exports.applyMiddlewaresOnApp = $; | ||
exports.configureZETK = v; | ||
exports.getExpressRateLimiterOptions = f; | ||
exports.invalidRequestHandler = _; | ||
exports.isApiResponse = O; | ||
exports.loginRequestValidationSchema = K; | ||
exports.numericEnum = S; | ||
exports.registerRequestValidationSchema = H; | ||
exports.sendApiFailedResponse = x; | ||
exports.sendApiResponse = p; | ||
exports.sendApiSuccessResponse = q; | ||
exports.sendBadRequestResponse = A; | ||
exports.sendItemExistsErrorResponse = k; | ||
exports.sendNotFoundErrorResponse = I; | ||
exports.sendTooManyRequestsErrorResponse = T; | ||
exports.sendUnAuthenticatedErrorResponse = w; | ||
exports.sendUnAuthorizedErrorResponse = y; | ||
exports.setExpressRateLimiterOptions = g; | ||
exports.validateRequestInputData = C; | ||
//# sourceMappingURL=index.js.map | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "zaions-express-tool-kit", | ||
"version": "0.0.15", | ||
"version": "0.0.16", | ||
"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 :)", | ||
@@ -76,3 +76,3 @@ "main": "./dist/index.js", | ||
"vitest": "^2.0.5", | ||
"zaions-tool-kit": "0.0.13", | ||
"zaions-tool-kit": "0.0.15", | ||
"zod": "^3.23.8" | ||
@@ -79,0 +79,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
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
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
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
66284