"use strict";(()=>{var e={};e.id=460,e.ids=[460],e.modules={76102:e=>{e.exports=require("@moduletrace/datasquirel/dist/client")},39383:e=>{e.exports=require("@moduletrace/datasquirel/dist/package-shared/actions/users/user-auth")},65967:e=>{e.exports=require("@moduletrace/datasquirel/dist/package-shared/utils/ejson")},93726:e=>{e.exports=require("@moduletrace/datasquirel/dist/package-shared/utils/numberfy")},30889:e=>{e.exports=require("@moduletrace/datasquirel/dist/package-shared/utils/slugify")},75600:e=>{e.exports=require("next/dist/compiled/next-server/pages-api.runtime.prod.js")},72583:e=>{e.exports=require("sanitize-html")},9973:e=>{e.exports=require("serverless-mysql")},79428:e=>{e.exports=require("buffer")},55511:e=>{e.exports=require("crypto")},29021:e=>{e.exports=require("fs")},66912:(e,t,a)=>{a.r(t),a.d(t,{config:()=>g,default:()=>m,routeModule:()=>f});var r={};a.r(r),a.d(r,{default:()=>_});var d=a(89947),s=a(2706),i=a(96762),l=a(41520),u=a(98e3),o=a(31495),n=a(60125),c=a(67619),p=a(69842);async function _(e,t){if("POST"!==e.method)return t.json({msg:"Failed!"});let{user:a,appData:r}=await (0,p.A)(e,t,!0);if(!a)return t.json({success:!1,msg:"User Auth Failed"});let{tableName:d,payload:s,tableSchema:i,dbSlug:_,dbId:m,delegated:g}=e.body;try{let r=await (0,n.A)({databaseSlug:_,request:e,user:a,query:e.query});if(!await (0,o.A)({user:a,confirmedDelegetedUser:r,database:_,table:d,dbId:m,priviledgeRegex:/Update Entries/i}))return t.json({success:!1,msg:"Unauthorized"});let c=r?.rootUserId?`datasquirel_user_${r.rootUserId}_${_}`:`datasquirel_user_${a.id}_${_}`,p=await (0,u.A)({dbContext:"Dsql User",paradigm:"Full Access",dbFullName:c,tableName:d,data:s,tableSchema:i});if(!p.insertId)throw console.log("Table Insertion Failed =>",p),Error(p?.error||"Table Insertion Failed");await (0,l.A)({dbName:c,entryId:p.insertId,entryOrder:s.order,tableName:d,tableSchema:i}),t.json({success:!0})}catch(e){(0,c.A)({component:"/api/addTableEntry/catch-error",message:e.message,user:a}),t.json({success:!1,msg:"Database Files could not be written!",err:e.message})}}let m=(0,i.M)(r,"default"),g=(0,i.M)(r,"config"),f=new d.PagesAPIRouteModule({definition:{kind:s.A.PAGES_API,page:"/api/addTableEntry",pathname:"/api/addTableEntry",bundlePath:"",filename:""},userland:r})},98e3:(e,t,a)=>{a.d(t,{A:()=>n});var r=a(72583),d=a.n(r),s=a(92652),i=a(30802),l=a(68829),u=a(64292),o=a(52939);async function n({dbContext:e,paradigm:t,dbFullName:a,tableName:r,data:n,tableSchema:c,duplicateColumnName:p,duplicateColumnValue:_,update:m,encryptionKey:g,encryptionSalt:f,forceLocal:h}){let b=!!h||(0,o.A)({dbContext:e,dbFullName:a}),y=b?global.DSQL_DB_CONN:global.DSQL_FULL_ACCESS_DB_CONN||global.DSQL_DB_CONN,q=b?global.DSQL_DB_CONN:global.DSQL_READ_ONLY_DB_CONN||global.DSQL_DB_CONN;if(n?.date_created_timestamp&&delete n.date_created_timestamp,n?.date_updated_timestamp&&delete n.date_updated_timestamp,n?.date_updated&&delete n.date_updated,n?.date_updated_code&&delete n.date_updated_code,n?.date_created&&delete n.date_created,n?.date_created_code&&delete n.date_created_code,p&&"string"==typeof p){let t=`SELECT * FROM ${b?"":`\`${a}\`.`}\`${r}\` WHERE \`${p}\`=?`,d=await (0,u.A)(q,t,[_]);if(d?.[0]&&!m)return null;if(d&&d[0]&&m)return await (0,i.A)({dbContext:e,dbFullName:a,tableName:r,data:n,tableSchema:c,encryptionKey:g,encryptionSalt:f,identifierColumnName:p,identifierValue:_||""})}let D=Object.keys(n),A=[],N=[];for(let e=0;e<D.length;e++)try{let t=D[e],a=n?.[t],r=c?c?.fields?.filter(e=>e.fieldName==t):null,i=r&&r[0]?r[0]:null;if(null==a||void 0==a||i?.dataType?.match(/int$/i)&&"string"==typeof a&&!a?.match(/./))continue;i?.encrypted&&(a=(0,l.A)({data:a,encryptionKey:g,encryptionSalt:f}),console.log("DSQL: Encrypted value =>",a));let u=/<[^>]+>/g;(i?.richText||String(a).match(u))&&(a=d()(a,s.A)),i?.pattern&&!new RegExp(i.pattern,i.patternFlags||"").test(a)&&(console.log("DSQL: Pattern not matched =>",a),a=""),A.push("`"+t+"`"),"object"==typeof a&&(a=JSON.stringify(a)),"number"==typeof a?N.push(String(a)):N.push(a)}catch(e){console.log("DSQL: Error in parsing data keys =>",e.message);continue}n?.date_created||(A.push("`date_created`"),N.push(Date())),n?.date_created_code||(A.push("`date_created_code`"),N.push(Date.now())),n?.date_updated||(A.push("`date_updated`"),N.push(Date())),n?.date_updated_code||(A.push("`date_updated_code`"),N.push(Date.now()));let S=`INSERT INTO ${b?"":`\`${a}\`.`}\`${r}\` (${A.join(",")}) VALUES (${N.map(()=>"?").join(",")})`;return await (0,u.A)(y,S,N)}}};var t=require("../../webpack-api-runtime.js");t.C(e);var a=e=>t(t.s=e),r=t.X(0,[2984],()=>a(66912));module.exports=r})();