diff --git a/account-api.js b/account-api.js new file mode 100644 index 0000000..f78ed4e --- /dev/null +++ b/account-api.js @@ -0,0 +1,89 @@ + +module.exports.accountPayables = async (req, res) => { + console.log('===== GET accountPayables =====') + console.log('url', req.originalUrl); + console.log('headers', req.headers); + console.log('query', req.query); + console.log('params', req.params); + console.log('body', req.body); + + let response = { + "link": { + "prev": "ip:port/sgl/api/v1/accounting-management/accounting?transactionId=$transactionId&page=$page&limit=$limit&sortby=$sortby", + "next": "ip:port/sgl/api/v1/accounting-management/accounting?transactionId=$transactionId&page=$page&limit=$limit&sortby=$sortby" + }, + "meta": { + "currentPage": 1, + "totalPages": 1, + "limit": 10 + }, + "total": 4, + "results": [ + { + "_id": "ia09igfyJD3", + "vendorCode": "6100103130", + "accountName": "บริษัท เคเอสไอ โซลูชั่น จำกัด", + "partnerBank": "0001", + "tradingPartner": "", + "branch": "00000", + "taxId": "0105556143098", + "memberId": "75EzpNZ0Twt", + "createdBy": "System", + "createdDate": "2022-06-20T08:52:08.655Z", + "updatedBy": "System", + "updatedDate": "2022-06-20T08:52:08.655Z" + } + // , + // { + // "_id": "LkStgv7Pqjv", + // "vendorCode": "7100000010", + // "accountName": "บจ.แอดวานซ์ ไวร์เลส เน็ทเวอร์ค", + // "partnerBank": null, + // "tradingPartner": "1200", + // "branch": "00000", + // "memberId": "7tZlEVVBDiq", + // "createdBy": "System", + // "createdDate": "2021-06-22T09:51:37.907Z", + // "updatedBy": "System", + // "updatedDate": "2021-06-22T09:51:37.907Z", + // "taxId": "0105548115897" + // }, + // { + // "_id": "u2fc0do5gaB", + // "vendorCode": "6300000003", + // "accountName": "บจ.เกมมี่", + // "partnerBank": "0601", + // "tradingPartner": "", + // "branch": "00001", + // "memberId": "suVHEKylHuq", + // "createdBy": "System", + // "createdDate": "2021-05-21T09:51:37.907Z", + // "updatedBy": "System", + // "updatedDate": "2021-05-21T09:51:37.907Z", + // "taxId": "1234567891113" + // }, + // { + // "_id": "NEqCwA4l9Cv", + // "vendorCode": "7100000030", + // "accountName": "แอดวานซ์ ไวร์เลส เน็ทเวอร์ค", + // "partnerBank": "0001", + // "tradingPartner": "", + // "branch": "00000", + // "taxId": "0105548115897", + // "memberId": "VsIsSNY9peQ", + // "createdBy": "System", + // "createdDate": "2022-09-26T06:52:42.875Z", + // "updatedBy": "System", + // "updatedDate": "2022-09-26T06:52:42.875Z" + // } + ] + } + + + // let response = { + // "resultCode":"40109", + // "resultDescription":"Authentication failed. Invalid username or password" + // } + + res.send(response) +} \ No newline at end of file diff --git a/admd.js b/admd.js index eb5db51..d53ce49 100644 --- a/admd.js +++ b/admd.js @@ -40,10 +40,20 @@ module.exports.oauthToken = async (req, res) => { // resultDescription: 'admd something error' // } + // response = { + // resultCode: "40401", + // resultDescription: 'Data not found' + // } + // response = {error : 'invalid_grant'} } + response = { + resultCode: "40401", + resultDescription: 'Data not found' + } + res.send(response) } diff --git a/app.js b/app.js index 0ac2dd4..1cd6427 100644 --- a/app.js +++ b/app.js @@ -373,6 +373,8 @@ app.post('/auth/v3.1/oauth/token', require('./admd').oauthToken); app.post('/auth/v3.1/logout', require('./admd').logout); app.post('/validate/token', require('./admd').validateToken); +app.post('/auth/v3.2/oauth/token', require('./admd').oauthToken); + app.post('/point/v1/deleteCustomer', require('./micro_point').deleteCustomer); app.post('/privilege/v1/history/delete', require('./privilege').deleteCustomer); @@ -447,6 +449,14 @@ app.post('/api/v1/cst/wallets/checkWallet', require('./bot_gateway').checkWallet app.get('/api/v2/Account/:accountId/Destinations', require('./magellan').getAccountDestination); app.get('/api/v2/Account/:accountId/Things', require('./magellan').getAccountThings); +app.get('/api/v1/pam-js/apiList/partner/:username', require('./pam').getApiForPartner); + +app.post('/api/authen/application', require('./cmsp-authen').authen); + +app.post('/graphql', require('./cirr').graphql); + +app.get('/sgl/api/v1/accounting-management/accountpayables', require('./account-api').accountPayables); + app.get('/api/random/leader', function (req, res) { const months = ["เกมส์", "โน๊ต setup", "โน๊ต วัศรุต", "แบงค์", "มอส", "ปิ๊ค", "เต้นพอไม่ต้องตื่น", "เปา", "นัท", "kik", "new", "ann","na", "boky", "eve", "miki", "pla", "sugar"]; // const months = [ "ann"]; @@ -614,28 +624,525 @@ q.on('success', function (result, job) { app.listen(port, () => console.log('app listening on port ' + port + '!')) -//test +decryptAes256 = function (text) { + const crypto = require('crypto'); + try { + const pwd = "l;ylfu;yo/o9drkp6g-hk#ohemj;,0hk" + const iv = Buffer.alloc(16, 0); + var mykey = crypto.createDecipheriv('aes-256-cbc', pwd, iv); + var mystr = mykey.update(text, 'hex', 'utf8') + mystr += mykey.final('utf8'); + return mystr.toString() + } catch (e) { + return text + } + } + +console.log('decryptAes256', decryptAes256('54848fc27a3ecd9340da85bc201769d180721cedb4e472781920b05d09d9daf6')) +//test +const NodeRSA = require('node-rsa'); +const jwt = require('jsonwebtoken') +const crypto = require('crypto'); test = () => { - z = 0 - j = 1 - k = 0 - while (!(j > 10)) { - z = z + 1 - k = 1 - while(!(k > 10)) { - k = k + 1 - z = z + 1 + // let key = new NodeRSA() + // // key.importKey( Buffer.from(result.encryptPublicKey, 'base64') , 'pkcs8-public-der');; + // key.importKey( Buffer.from(`MIIEpAIBAAKCAQEAtENoPR+2r0O/AaPcLwHPv67du7ZHE4XIPDT59oo5pL/vdQrmfapjYDsHdt9GW1ch8xfOWX4TERkBnTqudbNkN0uGzKzGCnJ6DUDfhURelTXpfl2wPLnf4G1EHxtN4AG9Juy+NTT3QDTRriHHUaw07Ra/ExbXB2uV1yDIg+zVTuZRmFDvkIsWMCconrSp1no0C6oz1i2sF+QFQ8atObtYPOf008NusZGfwk9d/RS3G6EQD5K9dgIzvkZB27lgQ+cCg7pifF6pNLvUkTEkbF6v3Uo5lD4gs7d0LfJ94DP2PbOqXDSBO1WtZWh950QtBS71CRnhJpGXt6XBgJMB4QlfZwIDAQABAoIBAQCugO6g9VlxU2DNoqXdL6DAi/SE6hDmWkUb26D7RJZG4bNal6HHlzG6j4pLThubAr+Px8Tvp3envpBsd8k5kd77FH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qxZTliix5OQDOgGziKx2j5dEKiL3QyeVpcWgtR6H7j3FAveVfFsEZ4Z41klRFtDtlfoxRpcg==`, 'base64'), 'pkcs1-private-der' ); + // // console.log(key.isPrivate()) + // // const text = JSON.stringify(contentRSA); + // // const encrypted = key.encrypt(text, 'base64'); + // // console.log('encrypted:', encrypted); + // let encrypted = "fWPDV0Pe7aXrobnTQykCStZ1wAdLEe3jd37sNcSai9O950qza4yE1e03eiWseFYNT480oKvvV774kZOIsM05ESVhsDEKscA/EMomuFyA15By7zENXSPx3TDaTyKMJ4ebGm1riXtODz9jlEWp8RPGIAi3Md9zItH7xsg0nKBqqffbblBFbZtVYjOFVRIG1notBSzqKiMk1M97TwuuPFEKj4rbGMZeQEl5LASr157+zqA3WtQewnHHf1v+BzHgMGmBUjzNDICvfHpAerZK5Krgn8STtvajHYcqX6qIRhCaKSDHpCncol3jCGuL5I47k/OiIg6uvdM7qZDWC/jhptvLfQ==" + // const decrypted = key.decrypt(encrypted, 'utf8'); + // console.log('decrypted:', decrypted); + + rsaPrivateKey = `-----BEGIN RSA PRIVATE KEY----- +MIIEpAIBAAKCAQEAtENoPR+2r0O/AaPcLwHPv67du7ZHE4XIPDT59oo5pL/vdQrm +fapjYDsHdt9GW1ch8xfOWX4TERkBnTqudbNkN0uGzKzGCnJ6DUDfhURelTXpfl2w +PLnf4G1EHxtN4AG9Juy+NTT3QDTRriHHUaw07Ra/ExbXB2uV1yDIg+zVTuZRmFDv +kIsWMCconrSp1no0C6oz1i2sF+QFQ8atObtYPOf008NusZGfwk9d/RS3G6EQD5K9 +dgIzvkZB27lgQ+cCg7pifF6pNLvUkTEkbF6v3Uo5lD4gs7d0LfJ94DP2PbOqXDSB +O1WtZWh950QtBS71CRnhJpGXt6XBgJMB4QlfZwIDAQABAoIBAQCugO6g9VlxU2DN +oqXdL6DAi/SE6hDmWkUb26D7RJZG4bNal6HHlzG6j4pLThubAr+Px8Tvp3envpBs +d8k5kd77FHc7HipdJLL4r4tyRFxXj6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5Pb82zJwfsr2JyRcDSiGB8nKKCrQ' + jwtPublicKey = `-----BEGIN PUBLIC KEY----- +MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA84UZfRnq6v9WTTA2zKLT +pKW8Zh7p0wipwTT59e7aT2znqGFD9xB5zx8BPIRGZ86aookOtI4CYGNS8TK8PMqB +RcdBRt4xMO+bzHeHE0ichFg46eCU7Bj5NIGDb8n2rWPRTk/jmkAYPIhMuWy2Jcw+ +u3Mu7lhvlnDAzQvaL45Reg4CqbRtjuNFFcLmTkWNzJidrOmrS9lFuy6wKrLvHNmP +eQHFKVUU9qcmtODdmjsTJKekVnXO13fTE+PWQnWB0NbPpSyH8k3YlkoTDBFeZoY+ +HH8M+vaXXg6OLNS8Ry8exz8iV5ofiwthNp3Ya/YzXMzrxSrewDNr4VBj3Ckv9IYW +FQIDAQAB +-----END PUBLIC KEY-----` + let jwtDecoded = jwt.verify(token, jwtPublicKey) + + console.log('jwt decode:', jwtDecoded) + + const crypto = require('crypto'); + const decryptedData = crypto.privateDecrypt( + { + key: rsaPrivateKey, + padding: crypto.constants.RSA_PKCS1_PADDING, + }, + Buffer.from(jwtDecoded.info, 'base64') + ); + + // The decrypted data is of the Buffer type, which we can convert to a + // string to reveal the original data + console.log("decrypted info data:", decryptedData.toString()); + +} + +// test() + + +test1 = (text) => { + try { + const iv = Buffer.alloc(16, 0); + var mykey = crypto.createDecipheriv('aes-256-cbc', 'mypasswordmypasswordmypassword12', iv); + var mystr = mykey.update(text, 'hex', 'utf8') + mystr += mykey.final('utf8'); + return mystr.toString() + } catch (e) { + console.log(e) + return text + } +} + +// console.log(test1('5B346775BE1213611D4E77D63795296E')) + +const fs = require('fs'); +const { time } = require('console'); +test2 = () => { + var jwtPrivate = fs.readFileSync('./jwt.pem'); // get private key + const token = jwt.sign({ + "username": "dev@mail.com", + "ssid": "747GSS5FMkJqcU45KUiMws", + "refresh_token_expires_in": 86400 + }, Buffer.from(jwtPrivate) , { algorithm: 'RS256' }); + return token +} + +// console.log(test2()) + +test3 = (seq) => { + let most = 0; + for(i in seq){ + if((+i + 1) <= seq.length) { + let v = shum(seq[i], seq.slice((+i + 1)), seq[i]) + if(v > most) { + most = v + } } - j = j + 1 } - let a = "ABCDab" - console.log(typeof a == 'string') - if(typeof a == 'string') { - console.log(a.toLowerCase()) + console.log('result', most) +} + +shum = (value, array, shummary) => { + for(a in array) { + if(value === array[a]) { + return shummary + array[a] + } else { + return shum(value, array.slice(1), array[a] + shummary) + } + } + return 0 +} + +let arr = [1,2,1,4,5,6,1,8,9,2] + +// console.time('test3') +// test3(arr) +// console.timeEnd('test3') + +test4 = (seq) => { + let most = 0 + for(s in seq) { + let i = seq.indexOf(seq[s], +s + 1) + if(i !== -1) { + let sum = seq[s] + for(let j = s; j < i; j++) { + sum += seq[j] + } + if(sum > most) { + most = sum + } + } + } + console.log('result', most) +} + +// console.time('test4') +// test4(arr) +// console.timeEnd('test4') + + +test5 = (home) => { + console.log('input >>', home) + for(let ih in home) { + let thisHomeHasTank = false + let thisHomeHasLand = false + if(home.charAt(ih) == 'H') { + thisHomeHasTank = hasTank(home, ih) + + if(thisHomeHasTank) { + continue + } else { + thisHomeHasLand = hasLand(home, ih) + } + + if(thisHomeHasLand) { + home = addTank(home, ih) + } else { + return -1 + } + } + } + + console.log('result >>', home) + let tankCount = 0 + for(let t of home) { + if(t == 'T') { + tankCount += 1 + } + } + + return tankCount +} + +hasTank = (home, i) => { + if(home.charAt(+i-1)) { + return home.charAt(+i-1) == 'T' + } + + if(home.charAt(+i+1)) { + return home.charAt(+i+1) == 'T' + } +} + +hasLand = (home, i) => { + let hasLand = false + if(home.charAt(+i-1)) { + hasLand = home.charAt(+i-1) == '_' + } + + if(home.charAt(+i+1) && !hasLand) { + hasLand = home.charAt(+i+1) == '_' + } + + return hasLand +} + +addTank = (home, i) => { + if(home.charAt(+i+1)) { + if( home.charAt(+i+1) == '_' ){ + home = replaceChar(home, +i+1, 'T') + return home + } + } + + if(home.charAt(+i-1)) { + if( home.charAt(+i-1) == '_' ){ + home = replaceChar(home, +i-1, 'T') + return home + } + } +} + +replaceChar = (str, index, replacement) => { + return str.substring(0, index) + replacement + str.substring(index + 1); +} + +// console.time('test5') +// console.log('number of tanks:', test5('_H_H_H_H_'), '\n') +// console.timeEnd('test5') +// console.log('number of tanks:', test5('H_HHH_'), '\n') +// console.log('number of tanks:', test5('H_H_H_H_'), '\n') +// console.log('number of tanks:', test5('_HH___HH_'), '\n') +// console.log('number of tanks:', test5('_H_'), '\n') +// console.log('\n') + +let current = [150,160,170] +let future = [200,150,160] +test6 = (saving) => { + let profit = 0 + + for(let i in current) { + if(saving > current[i]) { + saving -= current[i] + } + } + + return profit +} + +// console.log(test6(310)) + +// console.log(new URLSearchParams({ +// client_id: '123clientId', +// client_secret: '123clientSecret', +// grant_type: '123authorization_code', +// code: 'body.code', +// redirect_uri: '123redirectUrl', +// }).toString()) + +test7 = (amount) => { + let tb = Math.floor(amount / 1000) + amount = amount % 1000 + let fhb = Math.floor(amount / 500) + amount = amount % 500 + let hb = Math.floor(amount / 100) + amount = amount % 100 + let twb = Math.floor(amount / 20) + amount = amount % 20 + let teb = Math.floor(amount / 10) + amount = amount % 10 + let fb = Math.floor(amount / 5) + amount = amount % 5 + let ob = Math.floor(amount) + + console.log(tb, fhb, hb, twb, teb, fb, ob) +} + +// test7(15776) + + +var jsonToGraphql = function (json) { + const serviceEnv = {} + const configField = serviceEnv['fieldGraphql'] || {} + let data = {}; + try { + data = JSON.parse(json) + } catch (e) { + console.log('condition is not json format ', e) + } + let args = {} + + for(key in data) { + if(typeof data[key] === 'object'){ + for(key2 in data[key]) { + args[key2] = data[key][key2] + } + } + } + + // console.log(args) + + let query = { + query: { apiList: Object.assign( { __args: data } , configField )} + } + + console.log(JSON.stringify(query)) + + // const graphql_query = jsonToGraphQLQuery(query); + // return graphql_query + } + +// jsonToGraphql(`{ +// "resourceName": "Resource Name", +// "systemName": "System Name", +// "status": "Approved", +// "category": "Category", +// "customParams": [ +// { +// "customKey": "Custom Parameter key", +// "customValue": "Custom Parameter value" +// }, +// { +// "customKey": "Custom Parameter key2", +// "customValue": "Custom Parameter value2" +// } +// ] +// }`) + + +// urlChecker = function (url, checkUrl) { +// // console.log(url, '--', checkUrl) +// // console.log(url.split('/').slice(3, 5)) +// let newUrl = url.split('/').slice(3, 5).map((value) => { +// return value.split('.')[0] +// }).join('/') + +// console.log(url, newUrl, checkUrl) + +// if(newUrl === checkUrl) { +// return true +// } + +// return false +// } + + +urlChecker = function (url, checkUrl) { + let newUrl = url.split('/').slice(3, 5).map((value) => { + return value.split('.')[0] + }).join('/') + + if(newUrl === checkUrl) { + return true + } + + return false + } + + +// console.log(urlChecker('/api/v1/tq/tqTest', 'tq/tq')) +// console.log(urlChecker('/admd/v3/admd/test', 'admd/test')) +// console.log(urlChecker('/admd/v3/admd/test.json', 'admd/test')) +// console.log(urlChecker('/admd/v3/xx/admd/test', 'admd/test')) +// console.log(urlChecker('/api/v3/admd/test2', 'admd/test2')) +// console.log(urlChecker('/api/v3/admd/test2', 'admd/test')) +// console.log(urlChecker('/api/v3/admd/test2.json', 'admd/test')) +// console.log(urlChecker('/api/v3/admd/test/xxx.json', 'admd/test')) + +let errorMessage = { + "success": { + "resultCode": "20000", + "developerMessage": "Success" + }, + "successWithCondition": { + "resultCode": "20001", + "developerMessage": "Some information is missing" + }, + "successWithCondition2": { + "resultCode": "20002", + "developerMessage": "Some information has not been updated" + }, + "urlNotFound": { + "resultCode": "40400", + "developerMessage": "Unknown URL" + }, + "accessDenied": { + "resultCode": "40100", + "developerMessage": "Access denied" + }, + "unauthorizedUser": { + "resultCode": "40102", + "developerMessage": "Unauthorized User" + }, + "jwtExpired": { + "resultCode": "40103", + "developerMessage": "Token Expired" + }, + "missing": { + "resultCode": "40300", + "developerMessage": "Missing or Invalid parameter {param}" + }, + "dataExisted": { + "resultCode": "40301", + "developerMessage": "Data existed" + }, + "dataNotFound": { + "resultCode": "40401", + "developerMessage": "Data not found" + }, + "systemHasAProblem": { + "resultCode": "41700", + "developerMessage": "The system has a problem" + }, + "systemError": { + "resultCode": "50000", + "developerMessage": "System Error" + }, + "dbUnknownError": { + "resultCode": "50001", + "developerMessage": "DB Error" + }, + "dbConnectionTimeout": { + "resultCode": "50002", + "developerMessage": "Connection timeout" + }, + "dbConnectionError": { + "resultCode": "50003", + "developerMessage": "Connection error" + }, + "timeout": { + "resultCode": "50002", + "developerMessage": "Connection timeout" + }, + "connectionError": { + "resultCode": "50003", + "developerMessage": "Connection error" + }, + "destNodeError": { + "resultCode": "50010", + "developerMessage": "{destnode} error: {code}:{message}" + }, + "connectionNodeTimeout": { + "resultCode": "50011", + "developerMessage": "{destnode} timeout" + }, + "connectionNodeError": { + "resultCode": "50012", + "developerMessage": "{destnode} connection error" + }, + "admdError": { + "resultCode": "50004", + "developerMessage": "ADMD Error" + } +} + +mappingDeveloperMessage = function (resultCode) { + let e; + for(key in errorMessage) { + if(errorMessage[key].resultCode == resultCode) { + e = errorMessage[key] + } + } + + return e + } + +// console.log(mappingDeveloperMessage('40403')) + +let stateStatus = 'supplier-registration|waiting,supplier-registration|reject,supplier-registration|approve,business-agreement|waiting,business-agreement|reject' + +function createAQuery(query) { + let q = {} + let stateStatusList = query.stateStatus.split(',') + let groupState = {} + for (stateStatus of stateStatusList) { + if(stateStatus.includes('|')) { + // console.log(stateStatus) + let ss = stateStatus.split('|') + let state = ss[0] + let status = ss[1] + if(groupState[state]) { + groupState[state].push(status) + } else { + groupState[state] = [status] + } + } + } + // console.log(groupState) + q.$or = [] + for(g in groupState) { + q.$or.push({ + state: g, + status: { $in: groupState[g]} + }) } - console.log(a) - console.log(z) + return q; } -test() \ No newline at end of file +console.log(JSON.stringify(createAQuery({stateStatus}))) \ No newline at end of file diff --git a/chatbot.js b/chatbot.js new file mode 100644 index 0000000..71d8bf7 --- /dev/null +++ b/chatbot.js @@ -0,0 +1,31 @@ +const { Configuration, OpenAIApi } = require("openai"); +const api_key = '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'; + +const configuration = new Configuration({ apiKey: api_key }); +const openai = new OpenAIApi(configuration); + +openai.createCompletion({ + model: "text-davinci-003", + prompt: "say hello in 3 random language", + temperature: 0.6, +}).then(response => { + console.log(response.data.choices[0].text) +}); + + +// const client = new openai(api_key); + +// const prompt = 'Once upon a time, in a far-off kingdom, there lived a beautiful princess named...'; +// const model = 'text-davinci-002'; + +// client.completions.create({ +// engine: model, +// prompt: prompt, +// max_tokens: 50, +// n: 1, +// stop: '\n' +// }).then(result => { +// console.log(result.choices[0].text); +// }).catch(err => { +// console.log(err); +// }); \ No newline at end of file diff --git a/cirr.js b/cirr.js new file mode 100644 index 0000000..0ea9ad9 --- /dev/null +++ b/cirr.js @@ -0,0 +1,245 @@ +let retryCondition = false + +module.exports.graphql = async (req, res) => { + console.log('===== POST graphql =====') + console.log('url', req.originalUrl); + console.log('headers', req.headers); + console.log('query', req.query); + console.log('params', req.params); + console.log('body', req.body); + + let response + + if(req.body.query.includes('"pam"')) { + console.log('pam') + response = { + "data": { + "apiList": [ + { + "api": { + "_id": "636c9d7916831a1e82822cb7", + "method": "GET", + "uri": "/api/v1/pam1/test", + "description": "test" + }, + "resource": { + "resourceName": "QA_PAM1", + "description": "QA_PAM1" + } + }, + { + "api": { + "_id": "636c9d7916831a6efc822cc7", + "method": "POST", + "uri": "/api/v1/pam/test2", + "description": "test" + }, + "resource": { + "resourceName": "QA_PAM1", + "description": "QA_PAM1" + } + }, + { + "api": { + "_id": "640ec27fbc5c296d3cd5f385", + "method": "GET", + "uri": "/api/v1/pam1/test", + "description": "test" + }, + "resource": { + "resourceName": "QA_PAM1", + "description": "QA_PAM1 - UPDATE RESOURCE" + } + }, + { + "api": { + "_id": "640ec27fbc5c2996b3d5f395", + "method": "POST", + "uri": "/api/v1/pam/test2", + "description": "test" + }, + "resource": { + "resourceName": "QA_PAM1", + "description": "QA_PAM1 - UPDATE RESOURCE" + } + } + ] + }, + "resultCode": "20000", + "resultDescription": "Success" + } + } else if(req.body.query.includes('"pam1"')) { + console.log('pam1') + response = { + "data": { + "apiList": [ + { + "api": { + "_id": "636c9d7916831a1e82822cb7", + "method": "GET", + "uri": "/api/v1/pam1/test", + "description": "test" + }, + "resource": { + "resourceName": "QA_PAM1", + "description": "QA_PAM1" + } + }, + { + "api": { + "_id": "640ec27fbc5c296d3cd5f385", + "method": "GET", + "uri": "/api/v1/pam1/test", + "description": "test" + }, + "resource": { + "resourceName": "QA_PAM1", + "description": "QA_PAM1 - UPDATE RESOURCE" + } + } + ] + }, + "resultCode": "20000", + "resultDescription": "Success" + } + } else if(req.body.query.includes('"resource"')) { + console.log('resource') + response = { + "data": { + "apiList": [ + { + "api": { + "_id": "640ec968bc5c2918fed5f4b0", + "method": "DELETE", + "uri": "/api/v1/resource/test", + "description": "Description test api" + }, + "resource": { + "resourceName": "TQ_Resource_Test", + "description": "Resource Description" + } + } + ] + }, + "resultCode": "20000", + "resultDescription": "Success" + } + } else { + console.log('tq') + response = { + "data": { + "apiList": [ + { + "api": { + "_id": "640823c9151674235cf1b891", + "method": "PATCH", + "uri": "/api/v1/tq/tqTest", + "description": "test00001" + }, + "resource": { + "resourceName": "TQ_Test1", + "description": "TQ_ResourceDescription1" + } + }, + { + "api": { + "_id": "640e91b0bc5c2970afd5f067", + "method": "PATCH", + "uri": "/api/v1/tq/tqTest", + "description": "test00001" + }, + "resource": { + "resourceName": "TQ_Test1", + "description": "TQ_ResourceDescription1" + } + }, + { + "api": { + "_id": "640e91b0bc5c2921c3d5f075", + "method": "GET", + "uri": "/api/v1/tq2/tqTest", + "description": "test" + }, + "resource": { + "resourceName": "TQ_Test1", + "description": "TQ_ResourceDescription1" + } + } + ] + }, + "resultCode": "20000", + "resultDescription": "Success" + } + } + + // if(req.body.query.includes('admd3')) { + // response = { + // "data": { + // "apiList": "", + // "message": "Data Not Found" + // }, + // "resultCode": "20000", + // "resultDescription": "Success" + // } + // } + + // if(req.body.query.includes('admd2')) { + // if(retryCondition) { + // retryCondition = false + // response = { + // "resultCode": "40101", + // "resultDescription": "Unauthorized" + // } + // } else { + // response = { + // "data": { + // "apiList": [{ + // "api": { + // "_id": "635a05d5bc7f8b9de2595311", + // "method": "GET", + // "uri": "/api/v1/admd2/token2.json" + // }, + // "resource": { + // "resourceName": "Resource Name GET", + // "description": "Approved" + // } + // },{ + // "api": { + // "_id": "635a05d5bc7f8b9de2595311", + // "method": "POST", + // "uri": "/api/v1/admd2/token2/xxx.json" + // }, + // "resource": { + // "resourceName": "Resource Name POST", + // "description": "Approved" + // } + // },{ + // "api": { + // "_id": "635a05d5bc7f8b9de2595311", + // "method": "POST", + // "uri": "/api/v1/admd2/token5/xxx.json" + // }, + // "resource": { + // "resourceName": "Resource Name POST", + // "description": "Approved" + // } + // },{ + // "api": { + // "_id": "635a05d5bc7f8b9de2595311", + // "method": "DELETE", + // "uri": "/api/v1/admd2/token5/xxx.json" + // }, + // "resource": { + // "resourceName": "Resource Name DELETE", + // "description": "Approved" + // } + // }] + // }, + // "resultCode": "20000", + // "resultDescription": "Success" + // } + // } + // } + + res.status(200).send(response) +} diff --git a/cmsp-authen.js b/cmsp-authen.js new file mode 100644 index 0000000..d27c62e --- /dev/null +++ b/cmsp-authen.js @@ -0,0 +1,26 @@ + +module.exports.authen = async (req, res) => { + console.log('===== POST authentication =====') + console.log('url', req.originalUrl); + console.log('headers', req.headers); + console.log('query', req.query); + console.log('params', req.params); + console.log('body', req.body); + + let response = { + "resultCode":"20000", + "resultDescription":"Success", + "data":{ + "token_type":"Bearer", + "expires_in":3600, + "application_token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhcHBsaWNhdGlvbiI6ImRldl9ndWlkZSIsImlhdCI6MTY2ODU3Njc1NCwiZXhwIjoxNjY4NjYzMTU0fQ.KTJY9xkTZx_fwSNNKMlzbcx23jF-r4efSbZOaoZLVUw" + } + } + + // let response = { + // "resultCode":"40109", + // "resultDescription":"Authentication failed. Invalid username or password" + // } + + res.send(response) +} \ No newline at end of file diff --git a/generate_insert_sql_usage.js b/generate_insert_sql_usage.js new file mode 100644 index 0000000..e3af67f --- /dev/null +++ b/generate_insert_sql_usage.js @@ -0,0 +1,135 @@ +const { v4: uuidv4 } = require('uuid'); +const crypto = require('crypto'); + + +const dayjs = require('dayjs'); + +function generateNumberUUID() { + let numberUUID = ''; + while (numberUUID.length < 19) { + const uuid = uuidv4(); + const hash = crypto.createHash('sha1').update(uuid).digest('hex'); + numberUUID += BigInt(`0x${hash}`).toString().padStart(19, '0'); + } + return numberUUID.slice(0, 19); +} + +function getRandomInteger(min, max) { + min = Math.ceil(min); + max = Math.floor(max); + return Math.floor(Math.random() * (max - min + 1)) + min; +} +function getRandomDate() { + const now = dayjs(); // Get current date and time + const randomYear = now.year(); + const randomMonth = now.month(); + const randomDay = now.date(); + const randomHour = Math.floor(Math.random() * 24); // Generate random hour (0-23) + + const randomDate = dayjs().year(randomYear).month(randomMonth).date(28).hour(randomHour).minute(0).second(0); + + return randomDate; +} + +function getTimeFromDate(date) { + const time = date.format('HH:mm'); + return time; +} + + +class SummaryDailyUsage { + constructor(ID, LogDate, LogTime, GroupName, Amount, CreatedAt) { + this.ID = ID; + this.log_date = LogDate; + this.log_time = LogTime; + this.group_name = GroupName; + this.amount = Amount; + this.created_at = CreatedAt; + } + } + + function generateInsertSQL(tableName, data) { + let insertSQL = ''; + + for (let i = 0; i < data.length; i++) { + const record = data[i]; + const columns = Object.keys(record); + const values = Object.values(record).map(formatValue); + + const columnsStr = columns.join(', '); + const valuesStr = values.join(', '); + + const sql = `INSERT INTO ${tableName} (${columnsStr}) VALUES (${valuesStr});\n`; + insertSQL += sql; + } + + return insertSQL; + } + + function formatValue(value) { + if (typeof value === 'string') { + if (value.startsWith('TO_TIMESTAMP')) { + return value + } + return `'${value}'`; + } else if (value instanceof Date) { + const formattedDate = value.toISOString().slice(0, 19).replace('T', ' '); + return `TO_TIMESTAMP('${formattedDate}', 'YYYY-MM-DD HH24:MI:SS')`; + } else { + return value; + } + } + +function generateTimeLocationData() { + const timeLocationData = {}; + const listGroup = ['ส่วนกลาง','คลินิกราชการ','สำนักงานสาธารณสุขจังหวัด','สำนักงานสาธารณสุขอำเภอ','สำนักงานป้องกันควบคุมโรค','ศูนย์บริการสาธารณสุข','โรงพยาบาล','คลินิกเอกชน','โรงพยาบาลส่งเสริมสุขภาพตำบล'] + + for (let hour = 0; hour < 24; hour++) { + const time = dayjs().hour(hour).minute(0).format('HH:mm'); + const locations = listGroup; + + timeLocationData[time] = locations; + } + + return timeLocationData; +} + +function getRandomValueFromArray(array) { + const randomIndex = Math.floor(Math.random() * array.length); + const randomValue = array[randomIndex]; + return randomValue; +} + +// Example usage: +const timeLocationData = generateTimeLocationData(); +let sdu = [] + +for (let i = 0; i <= 10; i++) { + + let checkUnique = {} + + let r = getRandomDate() + let t = getTimeFromDate(r) + + let value = getRandomValueFromArray(timeLocationData[t]) + + if(!checkUnique[t+'_'+value]) { + sdu.push(new SummaryDailyUsage( + generateNumberUUID(), + `TO_TIMESTAMP('${r.format('YYYY-MM-DD HH:mm:ss')}', 'YYYY-MM-DD HH24:MI:SS')`, // Replace with your LogDate value + t, + value, + getRandomInteger(1, 100), + new Date() // Replace with your CreatedAt value + )) + } else { + console.log('is unique') + } + + checkUnique[t+'_'+value] = true + +} + + +const insertSQL = generateInsertSQL('ddc.SUM_DAILY_USAGE_BY_GROUP', sdu); +console.log(insertSQL); \ No newline at end of file diff --git a/generate_insert_sql_usage_menu.js b/generate_insert_sql_usage_menu.js new file mode 100644 index 0000000..d992f18 --- /dev/null +++ b/generate_insert_sql_usage_menu.js @@ -0,0 +1,133 @@ +const { v4: uuidv4 } = require('uuid'); +const crypto = require('crypto'); + + +const dayjs = require('dayjs'); + +function generateNumberUUID() { + let numberUUID = ''; + while (numberUUID.length < 19) { + const uuid = uuidv4(); + const hash = crypto.createHash('sha1').update(uuid).digest('hex'); + numberUUID += BigInt(`0x${hash}`).toString().padStart(19, '0'); + } + return numberUUID.slice(0, 19); +} + +function getRandomInteger(min, max) { + min = Math.ceil(min); + max = Math.floor(max); + return Math.floor(Math.random() * (max - min + 1)) + min; +} +function getRandomDate() { + const now = dayjs(); // Get current date and time + const randomYear = now.year(); + const randomMonth = now.month(); + const randomDay = now.date(); + // const randomHour = Math.floor(Math.random() * 24); // Generate random hour (0-23) + + const randomDate = dayjs().year(randomYear).month(randomMonth).date(28).hour(0).minute(0).second(0); + + return randomDate; +} + +function getTimeFromDate(date) { + const time = date.format('HH:mm'); + return time; +} + + +class SummaryDailyUsageMenu { + constructor(ID, LogDate, Menu, SubMenu, GroupName, Amount, CreatedAt) { + this.ID = ID; + this.log_date = LogDate; + this.menu = Menu; + this.sub_menu = SubMenu; + this.group_name = GroupName; + this.amount = Amount; + this.created_at = CreatedAt; + } + } + + function generateInsertSQL(tableName, data) { + let insertSQL = ''; + + for (let i = 0; i < data.length; i++) { + const record = data[i]; + const columns = Object.keys(record); + const values = Object.values(record).map(formatValue); + + const columnsStr = columns.join(', '); + const valuesStr = values.join(', '); + + const sql = `INSERT INTO ${tableName} (${columnsStr}) VALUES (${valuesStr});\n`; + insertSQL += sql; + } + + return insertSQL; + } + + function formatValue(value) { + if (typeof value === 'string') { + if (value.startsWith('TO_TIMESTAMP')) { + return value + } + return `'${value}'`; + } else if (value instanceof Date) { + const formattedDate = value.toISOString().slice(0, 19).replace('T', ' '); + return `TO_TIMESTAMP('${formattedDate}', 'YYYY-MM-DD HH24:MI:SS')`; + } else { + return value; + } + } + +function getRandomValueFromArray(array) { + const randomIndex = Math.floor(Math.random() * array.length); + const randomValue = array[randomIndex]; + return randomValue; +} + +// Example usage: +const listGroup = ['ส่วนกลาง','คลินิกราชการ','สำนักงานสาธารณสุขจังหวัด','สำนักงานสาธารณสุขอำเภอ','สำนักงานป้องกันควบคุมโรค','ศูนย์บริการสาธารณสุข','โรงพยาบาล','คลินิกเอกชน','โรงพยาบาลส่งเสริมสุขภาพตำบล'] +const menuList = ['แดชบอร์ด', 'การร้องขอข้อมูล', 'ประกาศและการแจ้งเตือน', 'การจัดการบทความ', 'จัดการแชทบอท', 'รายงานการใช้งานระบบ', 'เครื่องมือการจัดการ'] +const menus = { + 'แดชบอร์ด': ['กลุ่มโรคติดต่อ'], + 'การร้องขอข้อมูล': ['รายงาน D506'], + 'ประกาศและการแจ้งเตือน': ['ประเภทประกาศ', 'จัดการประกาศ', 'จัดการการแจ้งเตือน'], + 'การจัดการบทความ': ['ประเภทบทความ', 'จัดการบทความสุขภาพ', 'ข้อมูลโรงพยาบาล', 'ข้อมูลผู้ใช้ (User profile)'], + 'จัดการแชทบอท': ['ประวัติสนทนา', 'หัวข้อการตอบกลับ', 'จัดการข้อความแชทบอท', 'แดชบอร์ดสถิติคำถาม', 'บันทึกการสนทนา (Chat logs)'], + 'รายงานการใช้งานระบบ': ['รายงานการใช้งานระบบ'], + 'เครื่องมือการจัดการ': ['จัดการองค์กร', 'จัดการสิทธิ์ผู้ใช้งาน', 'จัดการกลุ่มผู้ใช้งาน', 'จัดการกลุ่มผู้ใช้งาน', 'จัดการผู้ใช้งาน', 'บันทึกการใช้งาน (Logs)'] +} +let sdu = [] + +for (let i = 0; i <= 10; i++) { + + let checkUnique = {} + + let r = getRandomDate() + + let menu = getRandomValueFromArray(menuList) + let sub_menu = getRandomValueFromArray(menus[menu]) + let group = getRandomValueFromArray(listGroup) + + if(!checkUnique[menu+'_'+sub_menu+'_'+group]) { + sdu.push(new SummaryDailyUsageMenu( + generateNumberUUID(), + `TO_TIMESTAMP('${r.format('YYYY-MM-DD HH:mm:ss')}', 'YYYY-MM-DD HH24:MI:SS')`, // Replace with your LogDate value + menu, + sub_menu, + group, + getRandomInteger(1, 100), + new Date() // Replace with your CreatedAt value + )) + } else { + console.log('is unique') + } + + checkUnique[menu+'_'+sub_menu+'_'+group] = true + +} + +const insertSQL = generateInsertSQL('ddc.SUM_DAILY_USAGE_BY_GROUP', sdu); +console.log(insertSQL); \ No newline at end of file diff --git a/graphqlServer.js b/graphqlServer.js new file mode 100644 index 0000000..e98ceb2 --- /dev/null +++ b/graphqlServer.js @@ -0,0 +1,191 @@ +var express = require('express'); +var { graphqlHTTP } = require('express-graphql'); +var { buildSchema } = require('graphql'); + +// Construct a schema, using GraphQL schema language +var schema = buildSchema(` + type apiList { + api: String + } + + type Query { + apiList: [apiList] + } +`); + +// The root provides a resolver function for each API endpoint +var data = { + "apiList": [{ + "api": "hello" + }], + "resultCode": "20000", + "resultDescription": "Success" +}; + +const extensions = ({ + document, + variables, + operationName, + result, + context, + }) => { + return { + resultCode: "20000", + resultDescription: "success" + }; + }; + +var app = express(); +// app.use('/graphql', graphqlHTTP({ +// schema: schema, +// // rootValue: data, +// graphiql: true, +// extensions +// })); + +app.use('/graphql', (req, res) => { + console.log(req.body) + res.status(200).send({ + "data": { + "apiList": [{ + "api": { + "_id": "635a05d5bc7f8b9de2595311", + "method": "GET", + "uri": "/api/v1/resource", + "description": "URI Description", + "exRequest": { + "header": [{ + "paramName": "test1", + "isRequire": "1", + "dataType": "String", + "description": "test1" + }, { + "paramName": "test2", + "isRequire": "0", + "dataType": "Object", + "description": "test2.1", + "paramObj": [{ + "paramName": "test2.1", + "isRequire": "0", + "dataType": "Object", + "description": "test2.1", + "paramObjParamObj": [{ + "paramName": "test2.1.1", + "isRequire": "0", + "dataType": "Number", + "description": "test2.1.1" + } + ] + } + ] + } + ], + "exHeader": [{ + "text": "Request Header Example" + } + ], + "body": [{ + "paramName": "test1", + "isRequire": "1", + "dataType": "String", + "description": "test1" + }, { + "paramName": "test2", + "isRequire": "0", + "dataType": "String", + "description": "test2" + } + ], + "exBody": [{ + "text": "Request Body Example" + } + ] + }, + "exResponse": { + "header": [{ + "paramName": "test1", + "isRequire": "1", + "dataType": "String", + "description": "test1" + } + ], + "exHeader": [{ + "text": "Response Header Example (Success)" + } + ], + "exHeaderErr": [{ + "text": "Response Header Example (Error)" + } + ], + "body": [{ + "paramName": "test1", + "isRequire": "0", + "dataType": "String", + "description": "test1" + }, { + "paramName": "test2", + "isRequire": "1", + "dataType": "String", + "description": "test2" + }, { + "paramName": "test3", + "isRequire": "1", + "dataType": "Object", + "description": "test3", + "paramObj": [{ + "paramName": "test3.1", + "isRequire": "1", + "dataType": "Number", + "description": "test3.1" + }, { + "paramName": "test3.2", + "isRequire": "0", + "dataType": "Integer", + "description": "test3.2" + } + ] + } + ], + "exBody": [{ + "text": "Response Body Example (Success)" + } + ], + "exBodyNoData": [{ + "text": "Response Body Example (Success no data)" + } + ], + "exBodyErr": [{ + "text": "Response Body Example (Error)" + } + ] + }, + "customParams": [{ + "customKey": "Custom Parameter key", + "customValue": "Custom Parameter value" + }, { + "customKey": "Custom Parameter key 2", + "customValue": "Custom Parameter value 2" + } + ] + }, + "resource": { + "_id": "635a05d5bc7f8b51b3595310", + "resourceName": "Resource Name", + "resourceOwner": "supps305", + "systemName": "System Name", + "status": "Approved" + }, + "microservicesDomain": { + "_id": "635a05d5bc7f8bf46b59530d", + "microservicesDomainName": "Microservices Domain", + "description": "Microservices Domain Description" + } + } + ] + }, + "resultCode": "40101", + "resultDescription": "Success" + }) +}) +app.listen(4000); +console.log('Running a GraphQL API server at http://localhost:4000/graphql'); \ No newline at end of file diff --git a/jwt.pem b/jwt.pem new file mode 100644 index 0000000..021fedd --- /dev/null +++ b/jwt.pem @@ -0,0 +1,27 @@ +-----BEGIN RSA PRIVATE KEY----- +MIIEpQIBAAKCAQEAnGeADtUHNs2Nm/OCKgOB3JI9vGeCnqQ0BwQtmlzA+OKqeUnH +I5AluPqUE2D1EVnVOKXsQb1QSHiL9bf19zJ++BR2l9gGgQWqKbd4sQkSrUHM6cri +YjtvwEpXs5g/iw9cA0Svir4IV0HpMw2L4wx8m+a8MNp24SLVVfyH+tvYEuTpzl87 +9PizlGFsLWeRvJMldSn3C65Sm0ihg1zl0DRxwduszMPgghdv1glqxQTcqdmIA5bF +4OSL0Bo4LaJ+EQ2W9lxNGE3GMoqxaJQ0EW470YL0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wc8oAEXusq/IBDCSmV/QReSTEuBYF6mEuqFjoEoOVZTC0Igb4335/bMaZye+ +7h0gd+Z1AoGAAPiUICh6iirA+tdvctZL74AN4JbIHU4AJV/PNhne15Uqx173UUbx +yM2ccL5d1IWSAu6cKKyInsPGi8FKknAhbMGOgYnFCT9lT6acK20ccIq42aLRI7EA +KaNtWZXn4zaqfFFAOoKhFmG963rEwpHW/oTSkYiiWAqmeSOQ9ew1jKk= +-----END RSA PRIVATE KEY----- \ No newline at end of file diff --git a/jwt.pub b/jwt.pub new file mode 100644 index 0000000..808d214 --- /dev/null +++ b/jwt.pub @@ -0,0 +1,9 @@ +-----BEGIN PUBLIC KEY----- +MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAnGeADtUHNs2Nm/OCKgOB +3JI9vGeCnqQ0BwQtmlzA+OKqeUnHI5AluPqUE2D1EVnVOKXsQb1QSHiL9bf19zJ+ ++BR2l9gGgQWqKbd4sQkSrUHM6criYjtvwEpXs5g/iw9cA0Svir4IV0HpMw2L4wx8 +m+a8MNp24SLVVfyH+tvYEuTpzl879PizlGFsLWeRvJMldSn3C65Sm0ihg1zl0DRx +wduszMPgghdv1glqxQTcqdmIA5bF4OSL0Bo4LaJ+EQ2W9lxNGE3GMoqxaJQ0EW47 +0YL0sSAhVqJgMdABYruU8Gf3S3sbZua7bw9E8+cux2FXA8CArLshcmUSyPlZq7os +JwIDAQAB +-----END PUBLIC KEY----- \ No newline at end of file diff --git a/magellan.js b/magellan.js index 3369215..cfdc663 100644 --- a/magellan.js +++ b/magellan.js @@ -96,7 +96,23 @@ module.exports.getAccountDestination = async (req, res) => { } } - res.status(200).send(response) + let response1 = { + "DestinationInfo": [], + "@Metadata": { + "CurrentPage": 1, + "TotalPages": 18, + "Top": 10, + "TotalCount": 172, + "HasPrevious": false, + "HasNext": true + }, + "OperationStatus": { + "Code": "20000", + "DeveloperMessage": "The requested operation was successfully." + } + } + + res.status(200).send(response1) } module.exports.getAccountThings = async (req, res) => { diff --git a/package-lock.json b/package-lock.json index 95c46a1..dbedc93 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,8 +14,12 @@ "body-parser": "^1.19.0", "connect-multiparty": "^2.2.0", "cors": "^2.8.5", + "dayjs": "^1.11.7", "express": "^4.17.1", + "express-graphql": "^0.12.0", + "graphql": "^15.8.0", "http": "0.0.0", + "jsonwebtoken": "^8.5.1", "jstoxml": "^1.6.5", "loadtest": "^5.0.4", "lodash": "^4.17.15", @@ -24,6 +28,8 @@ "multiparty": "^4.2.1", "n_": "^2.0.2", "node-json-config": "0.0.5", + "node-rsa": "^1.1.1", + "openai": "^3.2.1", "queue": "^6.0.2", "run-parallel-limit": "^1.0.6", "unirest": "^0.6.0" @@ -142,6 +148,14 @@ "resolved": "https://registry.npmjs.org/aws4/-/aws4-1.9.1.tgz", "integrity": "sha512-wMHVg2EOHaMRxbzgFJ9gtjOOCrI80OHLG14rxi28XwOW8ux6IiEbRCGGGqCtdAIg4FQCbW20k9RsT4y3gJlFug==" }, + "node_modules/axios": { + "version": "0.26.1", + "resolved": "https://registry.npmjs.org/axios/-/axios-0.26.1.tgz", + "integrity": "sha512-fPwcX4EvnSHuInCMItEhAGnaSEXRBjtzh9fOtsE6E1G6p7vl7edEeZe11QHf18+6+9gR5PbKV/sGKNaD8YaMeA==", + "dependencies": { + "follow-redirects": "^1.14.8" + } + }, "node_modules/azure": { "version": "2.3.1-preview", "resolved": "https://registry.npmjs.org/azure/-/azure-2.3.1-preview.tgz", @@ -1367,6 +1381,11 @@ "node": "*" } }, + "node_modules/dayjs": { + "version": "1.11.7", + "resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.11.7.tgz", + "integrity": "sha512-+Yw9U6YO5TQohxLcIkrXBeY73WP3ejHWVvx8XCk3gxvQDCTEmS48ZrSZCKciI7Bhl/uCMyxYtE9UqRILmFphkQ==" + }, "node_modules/debug": { "version": "2.6.9", "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", @@ -1539,6 +1558,109 @@ "node": ">= 0.10.0" } }, + "node_modules/express-graphql": { + "version": "0.12.0", + "resolved": "https://registry.npmjs.org/express-graphql/-/express-graphql-0.12.0.tgz", + "integrity": "sha512-DwYaJQy0amdy3pgNtiTDuGGM2BLdj+YO2SgbKoLliCfuHv3VVTt7vNG/ZqK2hRYjtYHE2t2KB705EU94mE64zg==", + "dependencies": { + "accepts": "^1.3.7", + "content-type": "^1.0.4", + "http-errors": "1.8.0", + "raw-body": "^2.4.1" + }, + "engines": { + "node": ">= 10.x" + }, + "peerDependencies": { + "graphql": "^14.7.0 || ^15.3.0" + } + }, + "node_modules/express-graphql/node_modules/bytes": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz", + "integrity": "sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg==", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/express-graphql/node_modules/http-errors": { + "version": "1.8.0", + "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.8.0.tgz", + "integrity": "sha512-4I8r0C5JDhT5VkvI47QktDW75rNlGVsUf/8hzjCC/wkWI/jdTRmBb9aI7erSG82r1bjKY3F6k28WnsVxB1C73A==", + "dependencies": { + "depd": "~1.1.2", + "inherits": "2.0.4", + "setprototypeof": "1.2.0", + "statuses": ">= 1.5.0 < 2", + "toidentifier": "1.0.0" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/express-graphql/node_modules/inherits": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" + }, + "node_modules/express-graphql/node_modules/raw-body": { + "version": "2.5.1", + "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.5.1.tgz", + "integrity": "sha512-qqJBtEyVgS0ZmPGdCFPWJ3FreoqvG4MVQln/kCgF7Olq95IbOp0/BWyMwbdtn4VTvkM8Y7khCQ2Xgk/tcrCXig==", + "dependencies": { + "bytes": "3.1.2", + "http-errors": "2.0.0", + "iconv-lite": "0.4.24", + "unpipe": "1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/express-graphql/node_modules/raw-body/node_modules/depd": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz", + "integrity": "sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/express-graphql/node_modules/raw-body/node_modules/http-errors": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-2.0.0.tgz", + "integrity": "sha512-FtwrG/euBzaEjYeRqOgly7G0qviiXoJWnvEH2Z1plBdXgbyjv34pHTSb9zoeHMyDy33+DWy5Wt9Wo+TURtOYSQ==", + "dependencies": { + "depd": "2.0.0", + "inherits": "2.0.4", + "setprototypeof": "1.2.0", + "statuses": "2.0.1", + "toidentifier": "1.0.1" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/express-graphql/node_modules/raw-body/node_modules/statuses": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.1.tgz", + "integrity": "sha512-RwNA9Z/7PrK06rYLIzFMlaF+l73iwpzsqRIFgbMLbTcLD6cOao82TaWefPXQvB2fOC4AjuYSEndS7N/mTCbkdQ==", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/express-graphql/node_modules/raw-body/node_modules/toidentifier": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz", + "integrity": "sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==", + "engines": { + "node": ">=0.6" + } + }, + "node_modules/express-graphql/node_modules/setprototypeof": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz", + "integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==" + }, "node_modules/ext": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/ext/-/ext-1.4.0.tgz", @@ -1600,6 +1722,25 @@ "node": ">= 0.8" } }, + "node_modules/follow-redirects": { + "version": "1.15.2", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.2.tgz", + "integrity": "sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==", + "funding": [ + { + "type": "individual", + "url": "https://github.com/sponsors/RubenVerborgh" + } + ], + "engines": { + "node": ">=4.0" + }, + "peerDependenciesMeta": { + "debug": { + "optional": true + } + } + }, "node_modules/forever-agent": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/forever-agent/-/forever-agent-0.6.1.tgz", @@ -1645,6 +1786,14 @@ "assert-plus": "^1.0.0" } }, + "node_modules/graphql": { + "version": "15.8.0", + "resolved": "https://registry.npmjs.org/graphql/-/graphql-15.8.0.tgz", + "integrity": "sha512-5gghUc24tP9HRznNpV2+FIoq3xKkj5dTQqf4v0CpdPbFVwFkWoxOM+o+2OC9ZSvjEMTjfmG9QT+gcvggTwW1zw==", + "engines": { + "node": ">= 10.x" + } + }, "node_modules/har-schema": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/har-schema/-/har-schema-2.0.0.tgz", @@ -1824,6 +1973,32 @@ "node >= 0.2.0" ] }, + "node_modules/jsonwebtoken": { + "version": "8.5.1", + "resolved": "https://registry.npmjs.org/jsonwebtoken/-/jsonwebtoken-8.5.1.tgz", + "integrity": "sha512-XjwVfRS6jTMsqYs0EsuJ4LGxXV14zQybNd4L2r0UvbVnSF9Af8x7p5MzbJ90Ioz/9TI41/hTCvznF/loiSzn8w==", + "dependencies": { + "jws": "^3.2.2", + "lodash.includes": "^4.3.0", + "lodash.isboolean": "^3.0.3", + "lodash.isinteger": "^4.0.4", + "lodash.isnumber": "^3.0.3", + "lodash.isplainobject": "^4.0.6", + "lodash.isstring": "^4.0.1", + "lodash.once": "^4.0.0", + "ms": "^2.1.1", + "semver": "^5.6.0" + }, + "engines": { + "node": ">=4", + "npm": ">=1.4.28" + } + }, + "node_modules/jsonwebtoken/node_modules/ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==" + }, "node_modules/jsprim": { "version": "1.4.1", "resolved": "https://registry.npmjs.org/jsprim/-/jsprim-1.4.1.tgz", @@ -1893,6 +2068,41 @@ "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz", "integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==" }, + "node_modules/lodash.includes": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/lodash.includes/-/lodash.includes-4.3.0.tgz", + "integrity": "sha1-YLuYqHy5I8aMoeUTJUgzFISfVT8=" + }, + "node_modules/lodash.isboolean": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/lodash.isboolean/-/lodash.isboolean-3.0.3.tgz", + "integrity": "sha1-bC4XHbKiV82WgC/UOwGyDV9YcPY=" + }, + "node_modules/lodash.isinteger": { + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/lodash.isinteger/-/lodash.isinteger-4.0.4.tgz", + "integrity": "sha1-YZwK89A/iwTDH1iChAt3sRzWg0M=" + }, + "node_modules/lodash.isnumber": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/lodash.isnumber/-/lodash.isnumber-3.0.3.tgz", + "integrity": "sha1-POdoEMWSjQM1IwGsKHMX8RwLH/w=" + }, + "node_modules/lodash.isplainobject": { + "version": "4.0.6", + "resolved": "https://registry.npmjs.org/lodash.isplainobject/-/lodash.isplainobject-4.0.6.tgz", + "integrity": "sha1-fFJqUtibRcRcxpC4gWO+BJf1UMs=" + }, + "node_modules/lodash.isstring": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/lodash.isstring/-/lodash.isstring-4.0.1.tgz", + "integrity": "sha1-1SfftUVuynzJu5XV2ur4i6VKVFE=" + }, + "node_modules/lodash.once": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/lodash.once/-/lodash.once-4.1.1.tgz", + "integrity": "sha1-DdOXEhPHxW34gJd9UEyI+0cal6w=" + }, "node_modules/log": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/log/-/log-1.4.0.tgz", @@ -2148,6 +2358,14 @@ "resolved": "https://registry.npmjs.org/node-json-config/-/node-json-config-0.0.5.tgz", "integrity": "sha1-Iaaqgx7lV5djQ8ydqNgKnlSo0Oc=" }, + "node_modules/node-rsa": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/node-rsa/-/node-rsa-1.1.1.tgz", + "integrity": "sha512-Jd4cvbJMryN21r5HgxQOpMEqv+ooke/korixNNK3mGqfGJmy0M77WDDzo/05969+OkMy3XW1UuZsSmW9KQm7Fw==", + "dependencies": { + "asn1": "^0.2.4" + } + }, "node_modules/oauth-sign": { "version": "0.9.0", "resolved": "https://registry.npmjs.org/oauth-sign/-/oauth-sign-0.9.0.tgz", @@ -2175,6 +2393,28 @@ "node": ">= 0.8" } }, + "node_modules/openai": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/openai/-/openai-3.2.1.tgz", + "integrity": "sha512-762C9BNlJPbjjlWZi4WYK9iM2tAVAv0uUp1UmI34vb0CN5T2mjB/qM6RYBmNKMh/dN9fC+bxqPwWJZUTWW052A==", + "dependencies": { + "axios": "^0.26.0", + "form-data": "^4.0.0" + } + }, + "node_modules/openai/node_modules/form-data": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", + "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", + "dependencies": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/parseurl": { "version": "1.3.3", "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz", @@ -2938,6 +3178,14 @@ "resolved": "https://registry.npmjs.org/aws4/-/aws4-1.9.1.tgz", "integrity": "sha512-wMHVg2EOHaMRxbzgFJ9gtjOOCrI80OHLG14rxi28XwOW8ux6IiEbRCGGGqCtdAIg4FQCbW20k9RsT4y3gJlFug==" }, + "axios": { + "version": "0.26.1", + "resolved": "https://registry.npmjs.org/axios/-/axios-0.26.1.tgz", + "integrity": "sha512-fPwcX4EvnSHuInCMItEhAGnaSEXRBjtzh9fOtsE6E1G6p7vl7edEeZe11QHf18+6+9gR5PbKV/sGKNaD8YaMeA==", + "requires": { + "follow-redirects": "^1.14.8" + } + }, "azure": { "version": "2.3.1-preview", "resolved": "https://registry.npmjs.org/azure/-/azure-2.3.1-preview.tgz", @@ -4137,6 +4385,11 @@ "resolved": "https://registry.npmjs.org/dateformat/-/dateformat-1.0.2-1.2.3.tgz", "integrity": "sha1-sCIMAt6YYXQztyhRz0fePfLNvuk=" }, + "dayjs": { + "version": "1.11.7", + "resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.11.7.tgz", + "integrity": "sha512-+Yw9U6YO5TQohxLcIkrXBeY73WP3ejHWVvx8XCk3gxvQDCTEmS48ZrSZCKciI7Bhl/uCMyxYtE9UqRILmFphkQ==" + }, "debug": { "version": "2.6.9", "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", @@ -4291,6 +4544,86 @@ "vary": "~1.1.2" } }, + "express-graphql": { + "version": "0.12.0", + "resolved": "https://registry.npmjs.org/express-graphql/-/express-graphql-0.12.0.tgz", + "integrity": "sha512-DwYaJQy0amdy3pgNtiTDuGGM2BLdj+YO2SgbKoLliCfuHv3VVTt7vNG/ZqK2hRYjtYHE2t2KB705EU94mE64zg==", + "requires": { + "accepts": "^1.3.7", + "content-type": "^1.0.4", + "http-errors": "1.8.0", + "raw-body": "^2.4.1" + }, + "dependencies": { + "bytes": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz", + "integrity": "sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg==" + }, + "http-errors": { + "version": "1.8.0", + "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.8.0.tgz", + "integrity": "sha512-4I8r0C5JDhT5VkvI47QktDW75rNlGVsUf/8hzjCC/wkWI/jdTRmBb9aI7erSG82r1bjKY3F6k28WnsVxB1C73A==", + "requires": { + "depd": "~1.1.2", + "inherits": "2.0.4", + "setprototypeof": "1.2.0", + "statuses": ">= 1.5.0 < 2", + "toidentifier": "1.0.0" + } + }, + "inherits": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" + }, + "raw-body": { + "version": "2.5.1", + "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.5.1.tgz", + "integrity": "sha512-qqJBtEyVgS0ZmPGdCFPWJ3FreoqvG4MVQln/kCgF7Olq95IbOp0/BWyMwbdtn4VTvkM8Y7khCQ2Xgk/tcrCXig==", + "requires": { + "bytes": "3.1.2", + "http-errors": "2.0.0", + "iconv-lite": "0.4.24", + "unpipe": "1.0.0" + }, + "dependencies": { + "depd": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz", + "integrity": "sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==" + }, + "http-errors": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-2.0.0.tgz", + "integrity": "sha512-FtwrG/euBzaEjYeRqOgly7G0qviiXoJWnvEH2Z1plBdXgbyjv34pHTSb9zoeHMyDy33+DWy5Wt9Wo+TURtOYSQ==", + "requires": { + "depd": "2.0.0", + "inherits": "2.0.4", + "setprototypeof": "1.2.0", + "statuses": "2.0.1", + "toidentifier": "1.0.1" + } + }, + "statuses": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.1.tgz", + "integrity": "sha512-RwNA9Z/7PrK06rYLIzFMlaF+l73iwpzsqRIFgbMLbTcLD6cOao82TaWefPXQvB2fOC4AjuYSEndS7N/mTCbkdQ==" + }, + "toidentifier": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz", + "integrity": "sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==" + } + } + }, + "setprototypeof": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz", + "integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==" + } + } + }, "ext": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/ext/-/ext-1.4.0.tgz", @@ -4348,6 +4681,11 @@ "unpipe": "~1.0.0" } }, + "follow-redirects": { + "version": "1.15.2", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.2.tgz", + "integrity": "sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==" + }, "forever-agent": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/forever-agent/-/forever-agent-0.6.1.tgz", @@ -4381,6 +4719,11 @@ "assert-plus": "^1.0.0" } }, + "graphql": { + "version": "15.8.0", + "resolved": "https://registry.npmjs.org/graphql/-/graphql-15.8.0.tgz", + "integrity": "sha512-5gghUc24tP9HRznNpV2+FIoq3xKkj5dTQqf4v0CpdPbFVwFkWoxOM+o+2OC9ZSvjEMTjfmG9QT+gcvggTwW1zw==" + }, "har-schema": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/har-schema/-/har-schema-2.0.0.tgz", @@ -4531,6 +4874,30 @@ "resolved": "https://registry.npmjs.org/jsonparse/-/jsonparse-1.2.0.tgz", "integrity": "sha1-XAxWhRBxYOcv50ib3eoLRMK8Z70=" }, + "jsonwebtoken": { + "version": "8.5.1", + "resolved": "https://registry.npmjs.org/jsonwebtoken/-/jsonwebtoken-8.5.1.tgz", + "integrity": "sha512-XjwVfRS6jTMsqYs0EsuJ4LGxXV14zQybNd4L2r0UvbVnSF9Af8x7p5MzbJ90Ioz/9TI41/hTCvznF/loiSzn8w==", + "requires": { + "jws": "^3.2.2", + "lodash.includes": "^4.3.0", + "lodash.isboolean": "^3.0.3", + "lodash.isinteger": "^4.0.4", + "lodash.isnumber": "^3.0.3", + "lodash.isplainobject": "^4.0.6", + "lodash.isstring": "^4.0.1", + "lodash.once": "^4.0.0", + "ms": "^2.1.1", + "semver": "^5.6.0" + }, + "dependencies": { + "ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==" + } + } + }, "jsprim": { "version": "1.4.1", "resolved": "https://registry.npmjs.org/jsprim/-/jsprim-1.4.1.tgz", @@ -4590,6 +4957,41 @@ "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz", "integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==" }, + "lodash.includes": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/lodash.includes/-/lodash.includes-4.3.0.tgz", + "integrity": "sha1-YLuYqHy5I8aMoeUTJUgzFISfVT8=" + }, + "lodash.isboolean": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/lodash.isboolean/-/lodash.isboolean-3.0.3.tgz", + "integrity": "sha1-bC4XHbKiV82WgC/UOwGyDV9YcPY=" + }, + "lodash.isinteger": { + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/lodash.isinteger/-/lodash.isinteger-4.0.4.tgz", + "integrity": "sha1-YZwK89A/iwTDH1iChAt3sRzWg0M=" + }, + "lodash.isnumber": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/lodash.isnumber/-/lodash.isnumber-3.0.3.tgz", + "integrity": "sha1-POdoEMWSjQM1IwGsKHMX8RwLH/w=" + }, + "lodash.isplainobject": { + "version": "4.0.6", + "resolved": "https://registry.npmjs.org/lodash.isplainobject/-/lodash.isplainobject-4.0.6.tgz", + "integrity": "sha1-fFJqUtibRcRcxpC4gWO+BJf1UMs=" + }, + "lodash.isstring": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/lodash.isstring/-/lodash.isstring-4.0.1.tgz", + "integrity": "sha1-1SfftUVuynzJu5XV2ur4i6VKVFE=" + }, + "lodash.once": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/lodash.once/-/lodash.once-4.1.1.tgz", + "integrity": "sha1-DdOXEhPHxW34gJd9UEyI+0cal6w=" + }, "log": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/log/-/log-1.4.0.tgz", @@ -4796,6 +5198,14 @@ "resolved": "https://registry.npmjs.org/node-json-config/-/node-json-config-0.0.5.tgz", "integrity": "sha1-Iaaqgx7lV5djQ8ydqNgKnlSo0Oc=" }, + "node-rsa": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/node-rsa/-/node-rsa-1.1.1.tgz", + "integrity": "sha512-Jd4cvbJMryN21r5HgxQOpMEqv+ooke/korixNNK3mGqfGJmy0M77WDDzo/05969+OkMy3XW1UuZsSmW9KQm7Fw==", + "requires": { + "asn1": "^0.2.4" + } + }, "oauth-sign": { "version": "0.9.0", "resolved": "https://registry.npmjs.org/oauth-sign/-/oauth-sign-0.9.0.tgz", @@ -4814,6 +5224,27 @@ "ee-first": "1.1.1" } }, + "openai": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/openai/-/openai-3.2.1.tgz", + "integrity": "sha512-762C9BNlJPbjjlWZi4WYK9iM2tAVAv0uUp1UmI34vb0CN5T2mjB/qM6RYBmNKMh/dN9fC+bxqPwWJZUTWW052A==", + "requires": { + "axios": "^0.26.0", + "form-data": "^4.0.0" + }, + "dependencies": { + "form-data": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", + "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", + "requires": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + } + } + } + }, "parseurl": { "version": "1.3.3", "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz", diff --git a/package.json b/package.json index 140d829..2729427 100644 --- a/package.json +++ b/package.json @@ -14,8 +14,12 @@ "body-parser": "^1.19.0", "connect-multiparty": "^2.2.0", "cors": "^2.8.5", + "dayjs": "^1.11.7", "express": "^4.17.1", + "express-graphql": "^0.12.0", + "graphql": "^15.8.0", "http": "0.0.0", + "jsonwebtoken": "^8.5.1", "jstoxml": "^1.6.5", "loadtest": "^5.0.4", "lodash": "^4.17.15", @@ -24,6 +28,8 @@ "multiparty": "^4.2.1", "n_": "^2.0.2", "node-json-config": "0.0.5", + "node-rsa": "^1.1.1", + "openai": "^3.2.1", "queue": "^6.0.2", "run-parallel-limit": "^1.0.6", "unirest": "^0.6.0" diff --git a/pam.js b/pam.js new file mode 100644 index 0000000..03a053c --- /dev/null +++ b/pam.js @@ -0,0 +1,30 @@ +module.exports.getApiForPartner = async (req, res) => { + console.log('===== GET inquiry Api for partner =====') + console.log('url', req.originalUrl); + console.log('headers', req.headers); + console.log('query', req.query); + console.log('params', req.params); + + let response = { + "resultCode": "20000", + "developerMessage": "Success", + "result": { + "listOfApi": [ + "tq/tqTest:00001", + "pam/test2:10000", + "pam1/test:01000", + "tq/tq:11111", + "resource/test:11111" + ] + } + } + + // let response = { + // "resultCode": "40401", + // "developerMessage": "Data Not Found", + // } + + res.set('content-type', 'application/json') + + res.send(response) +} \ No newline at end of file diff --git a/script.js b/script.js new file mode 100644 index 0000000..63a0c1d --- /dev/null +++ b/script.js @@ -0,0 +1,88 @@ +conn = new Mongo('10.1.2.146:27017'); + +company = conn.getDB("iot_partner_company"); +workflow = conn.getDB("iot_partner_workflow"); + +companies = company.companies.find() +worksheets = workflow.worksheets.find().sort( { "createdDate": 1 } ) + +let movedFileList = [] +while ( worksheets.hasNext() ) { + worksheet = worksheets.next() + // print(worksheet.supplierRegistration.taxId) + + let fileList = [] + + // worksheet.files + for(file of worksheet.files) { + if(file.fileValue === 'companyFile') { + if(worksheet.businessAgreement && worksheet.businessAgreement.companyFiles + && worksheet.businessAgreement.companyFiles.companies + && !worksheet.businessAgreement.companyFiles.companies.includes(file.fileId)) { + worksheet.businessAgreement.companyFiles.companies.push(file.fileId) + } + fileList.push(file) + } + + if(file.fileValue === 'CompanyProfilePresentation0') { + if(worksheet.businessAgreement && worksheet.businessAgreement.companyFiles + && worksheet.businessAgreement.companyFiles.companies + && !worksheet.businessAgreement.companyFiles.companies.includes(file.fileId)) { + worksheet.businessAgreement.companyFiles.companies.push(file.fileId) + } + fileList.push(file) + } + + if(file.fileValue === 'vatFile') { + if(worksheet.businessAgreement && worksheet.businessAgreement.companyFiles + && worksheet.businessAgreement.companyFiles.companies + && !worksheet.businessAgreement.companyFiles.companies.includes(file.fileId)) { + worksheet.businessAgreement.companyFiles.companies.push(file.fileId) + } + fileList.push(file) + } + } + + if(worksheet.businessAgreement && worksheet.businessAgreement.companyFiles && worksheet.businessAgreement.companyFiles.companies) { + workflow.worksheets.update({_id: worksheet._id}, { + '$set': {'businessAgreement.companyFiles.companies' : worksheet.businessAgreement.companyFiles.companies} + }) + } + + + for(i = 0; i < companies.length(); i++) { + companie = companies[i] + // print(companie.taxId, worksheet.supplierRegistration.taxId, companie.taxId === worksheet.supplierRegistration.taxId) + if(companie.taxId === worksheet.supplierRegistration.taxId) { + if(companie.files && Array.isArray(companie.files) && companie.files.length > 0) { + for(j = 0; j < fileList.length; j++) { + let alreadyFileInList = false + for(k = 0; k < companie.files.length; k++) { + if(companie.files[k].fileValue === fileList[j].fileValue) { + alreadyFileInList = true + break; + } + } + if(!alreadyFileInList) { + companie.files.push(fileList[j]) + movedFileList.push(fileList[j]) + } + } + } else { + companie.files = fileList + movedFileList.concat(fileList) + } + break + } + } +} + +for(i = 0; i < companies.length(); i++) { + company.companies.update({_id: companies[i]._id}, { + '$set': {files : companies[i].files} + }) +} + +company.movedFiles.insert({ + files: movedFileList +}) diff --git a/script_v2.js b/script_v2.js new file mode 100644 index 0000000..780835a --- /dev/null +++ b/script_v2.js @@ -0,0 +1,164 @@ +conn = new Mongo('mongodb://sandmongots:Aistsmongo@10.232.155.131:25000/admin'); +// conn_iot_partner_company = new Mongo('mongodb://serveradm:mypassword@10.138.42.23:8080/iot_partner_company'); +// conn_iot_partner_workflow = new Mongo('mongodb://serveradm:mypassword@10.138.42.23:8080/iot_partner_workflow'); + +company = conn.getDB("iot_partner_company"); +workflow = conn.getDB("iot_partner_workflow"); + +companies = company.companies.find() + +// let movedFileList = [] +issueCompanies = [] + +while ( companies.hasNext() ) { + companie = companies.next() + + // print(companie.files) + let hasVatFile, hasCompanyPresentation, hasCompanyFile + for (let file of companie.files ) { + // vatFile, companyPresentaion, companyFile + // print(file) + if(file.fileValue === 'vatFile') { + hasVatFile = true + } else if(file.fileValue === 'CompanyProfilePresentation0') { + hasCompanyPresentation = true + } else if(file.fileValue === 'companyFile') { + hasCompanyFile = true + } + } + + if(!hasVatFile || !hasCompanyPresentation || !hasCompanyFile) { + issueCompanies.push(companie) + } +} + +// searchWorksheetList = [] + +for(let issueComp of issueCompanies) { + for(let file of issueComp.files) { + let searchWorksheet = { + 'files.fileId' : file.fileId, + 'supplierRegistration.taxId': issueComp.taxId + } + + worksheets = workflow.worksheets.find(searchWorksheet).sort( { "updatedDate": -1 } ) + // print(worksheets.size() > 0) + if(worksheets.size() > 0) { + // print(worksheets) + let worksheet = worksheets[0] + + let expectWorksheet = [] + let alreadyVatFile, alreadyCompanyProfilePresentation, alreadycompanyFile + let vFile, presentFile, compFile + for(let worksheetFile of worksheet.files) { + if(worksheetFile.fileValue === 'vatFile') { + if(!vFile) { + vFile = worksheetFile + } + if(worksheetFile.isPass === true) { + if(!alreadyVatFile) { + expectWorksheet.push(worksheetFile) + } + alreadyVatFile = true + } + } else if(worksheetFile.fileValue === 'CompanyProfilePresentation0') { + if(!presentFile) { + presentFile = worksheetFile + } + if(worksheetFile.isPass === true) { + if(!alreadyCompanyProfilePresentation) { + expectWorksheet.push(worksheetFile) + } + alreadyCompanyProfilePresentation = true + } + } else if(worksheetFile.fileValue === 'companyFile') { + if(!compFile) { + compFile = worksheetFile + } + if(worksheetFile.isPass === true) { + if(!alreadycompanyFile) { + expectWorksheet.push(worksheetFile) + } + alreadycompanyFile = true + } + } + } + + if(!alreadyVatFile) { + if(vFile) { + expectWorksheet.push(vFile) + } + } + + if(!alreadyCompanyProfilePresentation) { + if(presentFile) { + expectWorksheet.push(presentFile) + } + } + + if(!alreadycompanyFile) { + if(compFile) { + expectWorksheet.push(compFile) + } + } + + newFileList = issueComp.files + fileNameForMoved = [] + + for(let ws of expectWorksheet) { + hasFile = false + for(let file2 of issueComp.files) { + if(ws.fileId === file2.fileId) { + hasFile = true + break + } + } + + if(!hasFile) { + fileNameForMoved.push(ws.fileName) + newFileList.push(ws) + } + + hasCompany = false + for(let wsComp of worksheet.businessAgreement.companyFiles.companies) { + if(wsComp === ws.fileId) { + hasCompany = true + break + } + // + } + + if(!hasCompany) { + worksheet.businessAgreement.companyFiles.companies.push(ws.fileId) + } + } + + // + // update company and worksheet // + print("update company where _id " + issueComp._id) + printjson({$set: { files: newFileList }}) + + company.companies.update({_id: issueComp._id}, { + '$set': { files: newFileList } + }) + + print("update worksheet where _id " + worksheet._id) + printjson({$set: { 'businessAgreement.companyFiles.companies': worksheet.businessAgreement.companyFiles.companies }}) + + workflow.worksheets.update({_id: worksheet._id}, { + '$set': {'businessAgreement.companyFiles.companies' : worksheet.businessAgreement.companyFiles.companies} + }) + + printjson(fileNameForMoved) + + for(let fileName of fileNameForMoved) { + company.movedFiles.insert({ + src: `/workflows/worksheets/${worksheet._id}/files/${fileName}`, + dest: `/companies/${worksheet.supplierRegistration.taxId}/${fileName}` + }) + } + + break; + } + } +} -- libgit2 0.21.2