zaions-express-tool-kit
Advanced tools
Comparing version 0.0.26 to 0.0.27
@@ -118,3 +118,3 @@ import { Response, Express, Request } from 'express'; | ||
passwordConfirmation: z.ZodString; | ||
}, "strip", z.ZodTypeAny, { | ||
}, 'strip', z.ZodTypeAny, { | ||
name: string; | ||
@@ -143,3 +143,3 @@ email: string; | ||
password: z.ZodString; | ||
}, "strip", z.ZodTypeAny, { | ||
}, 'strip', z.ZodTypeAny, { | ||
email: string; | ||
@@ -146,0 +146,0 @@ password: string; |
@@ -1,35 +0,2 @@ | ||
'use strict'; | ||
var X = require('cors'); | ||
var express = require('express'); | ||
var zaionsToolKit = require('zaions-tool-kit'); | ||
var expressRateLimit = require('express-rate-limit'); | ||
var zod = require('zod'); | ||
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; } | ||
var X__default = /*#__PURE__*/_interopDefault(X); | ||
var v=Object.defineProperty,G=Object.defineProperties;var P=Object.getOwnPropertyDescriptors;var Z=Object.getOwnPropertySymbols;var J=Object.prototype.hasOwnProperty,Q=Object.prototype.propertyIsEnumerable;var b=(e,s,o)=>s in e?v(e,s,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[s]=o,E=(e,s)=>{for(var o in s||(s={}))J.call(s,o)&&b(e,o,s[o]);if(Z)for(var o of Z(s))Q.call(s,o)&&b(e,o,s[o]);return e},L=(e,s)=>G(e,P(s));var F=(e,s,o)=>new Promise((r,t)=>{var n=a=>{try{i(o.next(a));}catch(d){t(d);}},l=a=>{try{i(o.throw(a));}catch(d){t(d);}},i=a=>a.done?r(a.value):Promise.resolve(a.value).then(n,l);i((o=o.apply(e,s)).next());});var z=null,g=()=>z,x=e=>{z=E({},e);};var W=e=>{let{rateLimiterOptions:s}=e;s&&x(s);};var p=(e,s)=>{let{success:o=!0,message:r=zaionsToolKit.ztkMessages.general.success,data:t=null,dataList:n=null,authToken:l=null,errors:i=null,code:a=zaionsToolKit.ResponseCodeEnum.success,status:d=zaionsToolKit.ResponseStatusEnum.success}=s||{};return e.status(d).json({success:o,message:r,result:{data:t,dataList:n,authToken:l},errors:i,code:a,status:d})},q=(e,s)=>{let{message:o=zaionsToolKit.ztkMessages.general.success,data:r=null,dataList:t=null,authToken:n=null,code:l=zaionsToolKit.ResponseCodeEnum.success,status:i=zaionsToolKit.ResponseStatusEnum.success}=s||{};return p(e,{success:!0,message:o,data:r,dataList:t,authToken:n,errors:null,code:l,status:i})},A=(e,s)=>{let{message:o=zaionsToolKit.ztkMessages.general.failed,errors:r=null,code:t=zaionsToolKit.ResponseCodeEnum.failed,status:n=zaionsToolKit.ResponseStatusEnum.failed}=s||{};return p(e,{success:!1,message:o,data:null,errors:r,code:t,status:n})},h=(e,s)=>{let{message:o=zaionsToolKit.ztkMessages.general.badRequest,errors:r=null,code:t=zaionsToolKit.ResponseCodeEnum.badRequest,status:n=zaionsToolKit.ResponseStatusEnum.badRequest}=s||{};return p(e,{success:!1,message:o,data:null,errors:r,code:t,status:n})},w=(e,s)=>{let{message:o=zaionsToolKit.ztkMessages.general.unAuthenticated,errors:r=null,code:t=zaionsToolKit.ResponseCodeEnum.unAuthenticated,status:n=zaionsToolKit.ResponseStatusEnum.unAuthenticated}=s||{};return p(e,{success:!1,message:o,data:null,errors:r,code:t,status:n})},y=(e,s)=>{let{message:o=zaionsToolKit.ztkMessages.general.unAuthorized,errors:r=null,code:t=zaionsToolKit.ResponseCodeEnum.unAuthorized,status:n=zaionsToolKit.ResponseStatusEnum.unAuthorized}=s||{};return p(e,{success:!1,message:o,data:null,errors:r,code:t,status:n})},I=(e,s)=>{let{message:o=zaionsToolKit.ztkMessages.general.notFound,errors:r=null,code:t=zaionsToolKit.ResponseCodeEnum.notFound,status:n=zaionsToolKit.ResponseStatusEnum.notFound}=s||{};return p(e,{success:!1,message:o,data:null,errors:r,code:t,status:n})},T=(e,s)=>{let{message:o=zaionsToolKit.ztkMessages.general.tooManyRequests,errors:r=null,code:t=zaionsToolKit.ResponseCodeEnum.tooManyRequests,status:n=zaionsToolKit.ResponseStatusEnum.tooManyRequests}=s||{};return p(e,{success:!1,message:o,data:null,errors:r,code:t,status:n})},k=(e,s)=>{let{message:o=zaionsToolKit.ztkMessages.general.itemExists,errors:r=null,code:t=zaionsToolKit.ResponseCodeEnum.itemExists,status:n=zaionsToolKit.ResponseStatusEnum.itemExists}=s||{};return p(e,{success:!1,message:o,data:null,errors:r,code:t,status:n})};var u=g(),j,V,U,D,oe=expressRateLimit.rateLimit({windowMs:(j=u==null?void 0:u.windowMs)!=null?j:15*60*1e3,limit:(V=u==null?void 0:u.limit)!=null?V:100,standardHeaders:(U=u==null?void 0:u.standardHeaders)!=null?U:"draft-7",legacyHeaders:(D=u==null?void 0:u.legacyHeaders)!=null?D:!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."})}),ne=(e,{applyCors:s,expressJson:o,expressUrlEncoded:r,applyRateLimiter:t=!0,expressRateLimiter:n})=>{t&&(n?e.use(n):e.use(oe)),s&&e.use(X__default.default({origin:"*"})),r&&e.use(express.urlencoded()),o&&e.use(express.json());},te=e=>{e.use("*",(s,o)=>{A(o,{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,o)=>{e.includes(s)||o.addIssue({code:zod.z.ZodIssueCode.invalid_enum_value,options:[...e],received:s});})}var C=r=>F(void 0,[r],function*({req:e,res:s,validationSchema:o}){var l,i,a,d,M;let t=E({},e.body),n;try{o.parse(t);}catch(N){n=N;}return (l=n==null?void 0:n.formErrors)!=null&&l.fieldErrors?h(s,{message:'Error occurred in "validateRequestInputData" helper function.',errors:L(E({},(a=(i=n==null?void 0:n.formErrors)==null?void 0:i.fieldErrors)!=null?a:{}),{formErrors:[...(M=(d=n==null?void 0:n.formErrors)==null?void 0:d.formErrors)!=null?M:[]]})}):t});var K=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 = ne; | ||
exports.configureZETK = W; | ||
exports.getExpressRateLimiterOptions = g; | ||
exports.invalidRequestHandler = te; | ||
exports.isApiResponse = O; | ||
exports.loginRequestValidationSchema = B; | ||
exports.numericEnum = S; | ||
exports.registerRequestValidationSchema = K; | ||
exports.sendApiFailedResponse = A; | ||
exports.sendApiResponse = p; | ||
exports.sendApiSuccessResponse = q; | ||
exports.sendBadRequestResponse = h; | ||
exports.sendItemExistsErrorResponse = k; | ||
exports.sendNotFoundErrorResponse = I; | ||
exports.sendTooManyRequestsErrorResponse = T; | ||
exports.sendUnAuthenticatedErrorResponse = w; | ||
exports.sendUnAuthorizedErrorResponse = y; | ||
exports.setExpressRateLimiterOptions = x; | ||
exports.validateRequestInputData = C; | ||
//# 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.26", | ||
"version": "0.0.27", | ||
"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 :)", | ||
@@ -65,3 +65,3 @@ "main": "./dist/index.js", | ||
"express-rate-limit": "^7.4.1", | ||
"zaions-tool-kit": "^0.0.79", | ||
"zaions-tool-kit": "^0.0.86", | ||
"zod": "^3.23.8" | ||
@@ -73,3 +73,3 @@ }, | ||
"@types/express": "^5.0.0", | ||
"@types/node": "^22.7.5", | ||
"@types/node": "^22.8.4", | ||
"cors": "^2.8.5", | ||
@@ -81,6 +81,6 @@ "crypto-js": "^4.2.0", | ||
"ts-node": "^10.9.2", | ||
"tsup": "^8.3.0", | ||
"tsup": "^8.3.5", | ||
"typescript": "^5.6.3", | ||
"vitest": "^2.1.2", | ||
"zaions-tool-kit": "^0.0.79", | ||
"vitest": "^2.1.4", | ||
"zaions-tool-kit": "^0.0.86", | ||
"zod": "^3.23.8" | ||
@@ -87,0 +87,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
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
70689
188