2024-11-05 11:12:42 +00:00
"use strict" ;
( ( ) => {
var exports = { } ;
exports . id = 7072 ;
exports . ids = [ 7072 ] ;
exports . modules = {
/***/ 6517 :
/***/ ( ( module ) => {
module . exports = require ( "lodash" ) ;
/***/ } ) ,
/***/ 2261 :
/***/ ( ( module ) => {
module . exports = require ( "serverless-mysql" ) ;
/***/ } ) ,
/***/ 4300 :
/***/ ( ( module ) => {
module . exports = require ( "buffer" ) ;
/***/ } ) ,
/***/ 2081 :
/***/ ( ( module ) => {
module . exports = require ( "child_process" ) ;
/***/ } ) ,
/***/ 6113 :
/***/ ( ( module ) => {
module . exports = require ( "crypto" ) ;
/***/ } ) ,
/***/ 7147 :
/***/ ( ( module ) => {
module . exports = require ( "fs" ) ;
/***/ } ) ,
/***/ 3685 :
/***/ ( ( module ) => {
module . exports = require ( "http" ) ;
/***/ } ) ,
/***/ 1017 :
/***/ ( ( module ) => {
module . exports = require ( "path" ) ;
/***/ } ) ,
/***/ 7840 :
/***/ ( ( _ _unused _webpack _module , _ _webpack _exports _ _ , _ _webpack _require _ _ ) => {
_ _webpack _require _ _ . r ( _ _webpack _exports _ _ ) ;
/* harmony export */ _ _webpack _require _ _ . d ( _ _webpack _exports _ _ , {
/* harmony export */ "default" : ( ) => ( /* binding */ handler )
/* harmony export */ } ) ;
/* harmony import */ var _functions _backend _grabUserSchemaData _ _WEBPACK _IMPORTED _MODULE _0 _ _ = _ _webpack _require _ _ ( 8164 ) ;
/* harmony import */ var _functions _backend _serverError _ _WEBPACK _IMPORTED _MODULE _1 _ _ = _ _webpack _require _ _ ( 2163 ) ;
/* harmony import */ var _functions _backend _serverError _ _WEBPACK _IMPORTED _MODULE _1 _ _ _default = /*#__PURE__*/ _ _webpack _require _ _ . n ( _functions _backend _serverError _ _WEBPACK _IMPORTED _MODULE _1 _ _ ) ;
/* harmony import */ var _functions _backend _userAuth _ _WEBPACK _IMPORTED _MODULE _2 _ _ = _ _webpack _require _ _ ( 6825 ) ;
/* harmony import */ var _functions _backend _userAuth _ _WEBPACK _IMPORTED _MODULE _2 _ _ _default = /*#__PURE__*/ _ _webpack _require _ _ . n ( _functions _backend _userAuth _ _WEBPACK _IMPORTED _MODULE _2 _ _ ) ;
/* harmony import */ var lodash _ _WEBPACK _IMPORTED _MODULE _3 _ _ = _ _webpack _require _ _ ( 6517 ) ;
/* harmony import */ var lodash _ _WEBPACK _IMPORTED _MODULE _3 _ _ _default = /*#__PURE__*/ _ _webpack _require _ _ . n ( lodash _ _WEBPACK _IMPORTED _MODULE _3 _ _ ) ;
/* harmony import */ var _package _shared _utils _backend _global _db _DB _HANDLER _ _WEBPACK _IMPORTED _MODULE _4 _ _ = _ _webpack _require _ _ ( 2224 ) ;
/* harmony import */ var _package _shared _utils _backend _global _db _DB _HANDLER _ _WEBPACK _IMPORTED _MODULE _4 _ _ _default = /*#__PURE__*/ _ _webpack _require _ _ . n ( _package _shared _utils _backend _global _db _DB _HANDLER _ _WEBPACK _IMPORTED _MODULE _4 _ _ ) ;
// @ts-check
/ * *
* === === === === === === === === === === === === === === === === === === === === === === === === === ===
* Imports
* === === === === === === === === === === === === === === === === === === === === === === === === === ===
* / c o n s t f s = _ _ w e b p a c k _ r e q u i r e _ _ ( 7 1 4 7 ) ;
const path = _ _webpack _require _ _ ( 1017 ) ;
const { execSync } = _ _webpack _require _ _ ( 2081 ) ;
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ / * *
* @ typedef { object } SyncTableBodySrcDstObject
* @ property { string } db
* @ property { string } table
* / / * *
* @ typedef { object } SyncTableBody
* @ property { "Pull" | "Push" } paradigm
* @ property { SyncTableBodySrcDstObject } src
* @ property { SyncTableBodySrcDstObject } dst
* @ property { any } [ delegated ]
* / / * *
* API handler
* === === === === === === === === === === === === === === === === === === === === === === === === === ===
* @ type { import ( "next" ) . NextApiHandler }
* / a s y n c f u n c t i o n h a n d l e r ( r e q , r e s ) {
/ * *
* Check method
*
* @ description Check request method and return if invalid
* / i f ( r e q . m e t h o d ! = = " G E T " ) r e t u r n r e s . j s o n ( {
msg : "Failed!"
} ) ;
/ * *
* User auth
*
* @ description Authenticate user
* / c o n s t u s e r = a w a i t _ f u n c t i o n s _ b a c k e n d _ u s e r A u t h _ _ W E B P A C K _ I M P O R T E D _ M O D U L E _ 2 _ _ _ d e f a u l t ( ) ( r e q , r e s ) ;
if ( ! user ) {
return res . json ( {
success : false ,
msg : "Unauthorized"
} ) ;
}
const dbUserId = req . query . dbUserId ;
const delegated = req . query . delegated ;
/ * *
* Send Response
*
* @ description Send a boolean response
* / t r y {
if ( ! dbUserId ) {
throw new Error ( "No Root user Id Found!" ) ;
}
/** @type {import("@/package-shared/types").MYSQL_delegated_user_tables_table_def[]} */ const delegatedTables = await _package _shared _utils _backend _global _db _DB _HANDLER _ _WEBPACK _IMPORTED _MODULE _4 _ _ _default ( ) ( ` SELECT * FROM datasquirel.delegated_user_tables WHERE delegated_user_id=? AND root_user_id=? ` , [
String ( user . id ) ,
String ( dbUserId )
] ) ;
const rootUserDbSchema = ( 0 , _functions _backend _grabUserSchemaData _ _WEBPACK _IMPORTED _MODULE _0 _ _ [ "default" ] ) ( {
userId : String ( dbUserId )
} ) ;
if ( ! rootUserDbSchema ) {
throw new Error ( "Root user schema not found!" ) ;
}
/** @type {import("@/package-shared/types").DSQL_DatabaseSchemaType[]} */ const filteredDbSchema = [ ] ;
delegatedTables . forEach ( ( tblObj ) => {
const existingDbIndex = filteredDbSchema . findIndex ( ( db ) => db . dbSlug === tblObj . database ) ;
/** @type {import("@/package-shared/types").DSQL_DatabaseSchemaType | undefined} */ const targetDb = rootUserDbSchema . find ( ( db ) => db . dbSlug === tblObj . database ) ;
if ( targetDb ) {
/** @type {import("@/package-shared/types").DSQL_DatabaseSchemaType} */ const finalDb = filteredDbSchema [ existingDbIndex ] ? filteredDbSchema [ existingDbIndex ] : {
... targetDb ,
tables : [ ]
} ;
const targetDbTbls = lodash _ _WEBPACK _IMPORTED _MODULE _3 _ _ _default ( ) . cloneDeep ( targetDb . tables ) ;
const targetTable = targetDbTbls . find ( ( tbl ) => tbl . tableName === tblObj . table ) ;
if ( targetTable && filteredDbSchema [ existingDbIndex ] ) {
filteredDbSchema [ existingDbIndex ] = {
... finalDb ,
tables : [
... filteredDbSchema [ existingDbIndex ] . tables ,
targetTable ,
]
} ;
} else if ( targetTable && ! filteredDbSchema [ existingDbIndex ] ) {
filteredDbSchema . push ( {
... targetDb ,
tables : [
targetTable
]
} ) ;
}
}
} ) ;
////////////////////////////////////////
res . json ( {
success : true ,
payload : filteredDbSchema
} ) ;
} catch ( /** @type {any} */ error ) {
console . log ( "ERROR:" , error . message ) ;
////////////////////////////////////////
_functions _backend _serverError _ _WEBPACK _IMPORTED _MODULE _1 _ _ _default ( ) ( {
component : "/api/get-authorized-databases" ,
message : error . message ,
user : user
} ) ;
res . json ( {
success : false ,
msg : error . message
} ) ;
////////////////////////////////////////
}
}
/***/ } )
} ;
;
// load runtime
var _ _webpack _require _ _ = require ( "../../webpack-api-runtime.js" ) ;
_ _webpack _require _ _ . C ( exports ) ;
var _ _webpack _exec _ _ = ( moduleId ) => ( _ _webpack _require _ _ ( _ _webpack _require _ _ . s = moduleId ) )
2024-11-05 14:18:40 +00:00
var _ _webpack _exports _ _ = _ _webpack _require _ _ . X ( 0 , [ 2224 , 2163 , 6825 , 8164 ] , ( ) => ( _ _webpack _exec _ _ ( 7840 ) ) ) ;
2024-11-05 11:12:42 +00:00
module . exports = _ _webpack _exports _ _ ;
} ) ( ) ;