├── .editorconfig ├── .gitignore ├── .jscsrc ├── README.md ├── companies ├── Aras.js ├── Yurtici.js └── index.js ├── index.js ├── package.json └── sample.js /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | end_of_line = lf 6 | insert_final_newline = true 7 | indent_style = space 8 | indent_size = 4 9 | 10 | [*.json] 11 | indent_size = 2 12 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | 5 | # Runtime data 6 | pids 7 | *.pid 8 | *.seed 9 | 10 | # Directory for instrumented libs generated by jscoverage/JSCover 11 | lib-cov 12 | 13 | # Coverage directory used by tools like istanbul 14 | coverage 15 | 16 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 17 | .grunt 18 | 19 | # Compiled binary addons (http://nodejs.org/api/addons.html) 20 | build/Release 21 | 22 | # Dependency directory 23 | # Commenting this out is preferred by some people, see 24 | # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git- 25 | node_modules 26 | 27 | # Users Environment Variables 28 | .lock-wscript 29 | 30 | # ========================= 31 | # Operating System Files 32 | # ========================= 33 | 34 | # OSX 35 | # ========================= 36 | 37 | .DS_Store 38 | .AppleDouble 39 | .LSOverride 40 | 41 | # Thumbnails 42 | ._* 43 | 44 | # Files that might appear on external disk 45 | .Spotlight-V100 46 | .Trashes 47 | 48 | # Directories potentially created on remote AFP share 49 | .AppleDB 50 | .AppleDesktop 51 | Network Trash Folder 52 | Temporary Items 53 | .apdisk 54 | 55 | # Windows 56 | # ========================= 57 | 58 | # Windows image file caches 59 | Thumbs.db 60 | ehthumbs.db 61 | 62 | # Folder config file 63 | Desktop.ini 64 | 65 | # Recycle Bin used on file shares 66 | $RECYCLE.BIN/ 67 | 68 | # Windows Installer files 69 | *.cab 70 | *.msi 71 | *.msm 72 | *.msp 73 | 74 | # Windows shortcuts 75 | *.lnk 76 | -------------------------------------------------------------------------------- /.jscsrc: -------------------------------------------------------------------------------- 1 | { 2 | "preset": "google", 3 | "disallowKeywords": ["with"], 4 | "disallowMultipleLineBreaks": null, 5 | "disallowMultipleVarDecl": null, 6 | "disallowSpacesInsideObjectBrackets": null, 7 | "requireCamelCaseOrUpperCaseIdentifiers": null, 8 | "requireCurlyBraces": null, 9 | "validateIndentation": 4 10 | } 11 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # kargojs 2 | 3 | Türkiye Kargo firmalarından rahatça sorgulama yapabilmek için geliştirilen npm modülü. 4 | 5 | ## Kullanım 6 | 7 | ```js 8 | 9 | var kargojs = require('./index'); 10 | 11 | 12 | kargojs.Yurtici.query("107683143283",function(err,data){ 13 | console.log(err ? err : data); 14 | }) 15 | 16 | 17 | kargojs.Yurtici.getMovements("107683143283",function(err,data){ 18 | console.log(err ? err : data); 19 | }) 20 | 21 | 22 | kargojs.Aras.query("5560228801279",function(err,data){ 23 | console.log(err ? err : data); 24 | }) 25 | 26 | 27 | kargojs.Aras.getMovements("5560228801279",function(err,data){ 28 | console.log(err ? err : data); 29 | }) 30 | 31 | ``` 32 | 33 | ## Aktif kargo firmaları 34 | Şuan için aktif olan firmalar Aras ve Yurtiçi kargo firmalarıdır. Diğer firmaları da yavaş yavaş ekleyeceğim. 35 | 36 | ## Testler 37 | Henüz test yazmadım, bazı yerlerde de saçma sapan hackler kullanarak sonuca ulaşmaya çalıştım. Lütfen ürün ortamında kullanmadan önce inceleyin, saçma bulduğunuz yerler için issue oluşturabilirseniz sevinirim. 38 | -------------------------------------------------------------------------------- /companies/Aras.js: -------------------------------------------------------------------------------- 1 | var Aras = {}, 2 | request = require('request'), 3 | async = require('async'); 4 | 5 | 6 | 7 | /** 8 | * @private 9 | */ 10 | Aras._delete_null_properties = function(test, recurse) { 11 | for (var i in test) { 12 | if (test[i] === null) { 13 | delete test[i]; 14 | } else if (recurse && typeof test[i] === 'object') { 15 | Aras._delete_null_properties(test[i], recurse); 16 | } 17 | } 18 | } 19 | 20 | 21 | /** 22 | * @private 23 | */ 24 | Aras._stripTags = function(str){ 25 | return str.replace(/<(?:.|\n)*?>/gm, ''); 26 | } 27 | 28 | 29 | /** 30 | * @private 31 | */ 32 | Aras._findAndGetRegex = function(regexPattern,subject){ 33 | var findings = regexPattern.exec(subject); 34 | 35 | return !findings ? null : Aras._stripTags(findings[1]); 36 | } 37 | 38 | 39 | /** 40 | * @private 41 | */ 42 | Aras._getShipmentId = function(query,callback){ 43 | request("http://kargotakip.araskargo.com.tr/CargoInfoV3.aspx?code=" + String(query), function(err,response,body){ 44 | if (err) return callback(err); 45 | 46 | var shipmentIdRegex = /shipmentid=(.*)&/g, 47 | shipmentId = Aras._findAndGetRegex(shipmentIdRegex,body), 48 | barcodeRegex = /barcode=(.*)&/g, 49 | barcode = Aras._findAndGetRegex(barcodeRegex,body); 50 | 51 | if(shipmentId && barcode){ 52 | var idsObject = { 53 | shipmentId: shipmentId, 54 | barcode: barcode 55 | } 56 | return callback(null,idsObject); 57 | } else { 58 | return callback(new Error('Hatalı kargo takip numarası')); 59 | } 60 | }) 61 | } 62 | 63 | 64 | /** 65 | * @private 66 | */ 67 | Aras._getCargoDetails = function(shipmentId,callback){ 68 | request("http://kargotakip.araskargo.com.tr/CargoInfoWaybillAndDelivered.aspx?shipmentid=" + String(shipmentId), function(err,response,body){ 69 | if (err) return callback(err); 70 | 71 | var kayitKontrolRegex = /(.*)<\/font>/g, 72 | kayitKontrol = Aras._findAndGetRegex(kayitKontrolRegex,body); 73 | 74 | if(kayitKontrol != null) 75 | return callback(new Error('Kayıt bulunamadı')); 76 | 77 | 78 | var ilkCikisRegex = /(.*)<\/span>/g; 79 | var ilkCikis = Aras._findAndGetRegex(ilkCikisRegex,body); 80 | 81 | var cikisRegex = /(.*)<\/span>/g; 82 | var cikis = Aras._findAndGetRegex(cikisRegex,body); 83 | 84 | var varisRegex = /(.*)<\/span>/g; 85 | var varis = Aras._findAndGetRegex(varisRegex,body); 86 | 87 | var odemeTuruRegex = /(.*)<\/span>/g; 88 | var odemeTuru = Aras._findAndGetRegex(odemeTuruRegex,body); 89 | 90 | var aliciRegex = /(.*)<\/span>/g; 91 | var alici = Aras._findAndGetRegex(aliciRegex,body); 92 | 93 | var kargoCinsRegex = /(.*)<\/span>/g; 94 | var kargoCins = Aras._findAndGetRegex(kargoCinsRegex,body); 95 | 96 | var paketSayiRegex = /(.*)<\/span>/g; 97 | var paketSayi = Aras._findAndGetRegex(paketSayiRegex,body); 98 | 99 | var gonderiTipiRegex = /(.*)<\/span>/g; 100 | var gonderiTipi = Aras._findAndGetRegex(gonderiTipiRegex,body); 101 | 102 | var cikisTarihiRegex = /(.*)<\/span>/g; 103 | var cikisTarihi = Aras._findAndGetRegex(cikisTarihiRegex,body); 104 | 105 | var tasimaIrsaliyeRegex = /(.*)<\/span>/g; 106 | var tasimaIrsaliye = Aras._findAndGetRegex(tasimaIrsaliyeRegex,body); 107 | 108 | var gonderiNoRegex = /(.*)<\/span>/g; 109 | var gonderiNo = Aras._findAndGetRegex(gonderiNoRegex,body); 110 | 111 | var gondericiRegex = /(.*)<\/span>/g; 112 | var gonderici = Aras._findAndGetRegex(gondericiRegex,body); 113 | 114 | var sevkIrsaliyeRegex = /(.*)<\/span>/g; 115 | var sevkIrsaliye = Aras._findAndGetRegex(sevkIrsaliyeRegex,body); 116 | 117 | var durumRegex = /(.*)<\/span>/g; 118 | var durum = Aras._findAndGetRegex(durumRegex,body); 119 | 120 | var teslimAlanRegex = /(.*)<\/span>/g; 121 | var teslimAlan = Aras._findAndGetRegex(teslimAlanRegex,body); 122 | 123 | var teslimTarihiRegex = /(.*)<\/span>/g; 124 | var teslimTarihi = Aras._findAndGetRegex(teslimTarihiRegex,body); 125 | 126 | var arasObj = { 127 | bilgiler: { 128 | 'ilk_cikis_sube': ilkCikis, 129 | 'cikis_sube': cikis, 130 | 'varis_sube': varis, 131 | 'odeme_turu': odemeTuru, 132 | 'alici': alici, 133 | 'kargo_cinsi': kargoCins, 134 | 'paket_sayi': paketSayi, 135 | 'gonderi_tipi': gonderiTipi, 136 | 'cikis_tarihi': cikisTarihi, 137 | 'tasima_irsaliye_no': tasimaIrsaliye, 138 | 'gonderi_no': gonderiNo, 139 | 'gonderici': gonderici, 140 | 'sevk_irsaliye_no': sevkIrsaliye, 141 | }, 142 | durum: { 143 | 'son_durum': durum, 144 | 'teslim_alan': teslimAlan, 145 | 'teslim_tarihi': teslimTarihi 146 | } 147 | } 148 | 149 | return callback(null,arasObj); 150 | 151 | }) 152 | } 153 | 154 | 155 | /** 156 | * @private 157 | */ 158 | Aras._getMovementDetails = function(barcode,callback){ 159 | request("http://kargotakip.araskargo.com.tr/CargoInfoTransactionAndRedirection.aspx?barcode=" + String(barcode), function(err,response,body){ 160 | if (err) return callback(err); 161 | 162 | body = body.replace(//g, ''); 163 | 164 | var tableRegex = /(.{19})<\/td>(.*)<\/td>(.*)<\/td>(.*)<\/td>/g, 165 | tableResults = body.match(tableRegex); 166 | 167 | if(!tableResults) return new Error('Taşıma bilgisi bulunamadı'); 168 | 169 | var parseDetailsRegex = /(.*)<\/td>/g, 170 | movementDetails = []; 171 | 172 | for(var i=0; i(.*?)<\/td>/g).map(function(val){ 174 | return val.replace(/<\/?td>/g,''); 175 | }); 176 | 177 | movementDetails.push({ 178 | 'tarih': detailsRaw[0], 179 | 'il': detailsRaw[1], 180 | 'birim': detailsRaw[2], 181 | 'islem': detailsRaw[3] 182 | }); 183 | } 184 | return callback(null,movementDetails); 185 | }); 186 | } 187 | 188 | 189 | Aras.query = function(query, callback){ 190 | async.waterfall([ 191 | function(cb){ 192 | Aras._getShipmentId(query,cb); 193 | }, 194 | function(idsObject,cb){ 195 | Aras._getCargoDetails(idsObject.shipmentId,cb); 196 | } 197 | ], function(err,results){ 198 | if (err) return callback(err); 199 | 200 | callback(null,results); 201 | }) 202 | } 203 | 204 | 205 | Aras.getMovements = function(query,callback){ 206 | async.waterfall([ 207 | function (cb){ 208 | Aras._getShipmentId(query,cb); 209 | }, 210 | function (idsObject,cb){ 211 | Aras._getMovementDetails(idsObject.barcode,cb); 212 | } 213 | ], function (err, results){ 214 | if (err) return callback(err); 215 | 216 | callback(null, results); 217 | }) 218 | } 219 | 220 | 221 | 222 | module.exports = Aras; 223 | -------------------------------------------------------------------------------- /companies/Yurtici.js: -------------------------------------------------------------------------------- 1 | var Yurtici = {}, 2 | request = require('request'); 3 | 4 | 5 | 6 | /** 7 | * @private 8 | */ 9 | Yurtici._queryFormatter = function(query){ 10 | var postingRefIds; 11 | 12 | if (typeof query === "string") { 13 | postingRefIds = query.split(); 14 | } else if (typeof query === "number") { 15 | postingRefIds = String(query).split(); 16 | } else { 17 | query = query.map(function(item) { 18 | return String(item); 19 | }); 20 | 21 | return query; 22 | } 23 | 24 | return postingRefIds; 25 | } 26 | 27 | 28 | /** 29 | * @private 30 | */ 31 | Yurtici._prepareQuery = function(query){ 32 | var postingRefIds = Yurtici._queryFormatter(query), 33 | innerQuery = { 34 | "postingRefIds": postingRefIds, 35 | "ticketId": "8a81a3194f830a88014f88343d881642", 36 | "SERVICE_NAME": "getLastPostings" 37 | }; 38 | 39 | return { 40 | "NO_ENC": true, 41 | "INPUT_BLOCK": JSON.stringify(innerQuery) 42 | }; 43 | } 44 | 45 | Yurtici.replace_tr = function(input) 46 | { 47 | input = input.replace('@s', 'ş'); 48 | input = input.replace('@i', 'ı'); 49 | input = input.replace('@g', 'ğ'); 50 | input = input.replace('@u', 'ü'); 51 | input = input.replace('@c', 'ç'); 52 | input = input.replace('@o', 'ö'); 53 | return input; 54 | } 55 | Yurtici.query = function(query,callback){ 56 | request({ 57 | uri: "http://mapp.yurticikargo.com/ListenerServlet", 58 | method: "POST", 59 | form: Yurtici._prepareQuery(query), 60 | json: false 61 | }, function(error,response,body){ 62 | if (error) return callback(error); 63 | 64 | var responseObj = JSON.parse(Yurtici.replace_tr(body)); 65 | 66 | if (responseObj.message) 67 | return callback(new Error(responseObj.message)); 68 | 69 | return callback(null,responseObj.result); 70 | }) 71 | } 72 | 73 | 74 | /** 75 | * @private 76 | */ 77 | Yurtici._prepareMovementsQuery = function(singleId){ 78 | var innerQuery = { 79 | "postingRefId": singleId, 80 | "ticketId": "8a81a3194f830a88014f88343d881642", 81 | "SERVICE_NAME": "getCargoMovements" 82 | }; 83 | 84 | return { 85 | "NO_ENC": true, 86 | "INPUT_BLOCK": JSON.stringify(innerQuery) 87 | }; 88 | } 89 | 90 | 91 | Yurtici.getMovements = function(query,callback){ 92 | request({ 93 | uri: "http://mapp.yurticikargo.com/ListenerServlet", 94 | method: "POST", 95 | form: Yurtici._prepareMovementsQuery(query), 96 | json: false 97 | }, function(error,response,body){ 98 | if (error) return callback(error); 99 | 100 | var responseObj = JSON.parse(Yurtici.replace_tr(body)); 101 | 102 | if (responseObj.message) 103 | return callback(new Error(responseObj.message)); 104 | 105 | return callback(null,responseObj.result); 106 | }) 107 | } 108 | 109 | 110 | 111 | module.exports = Yurtici; 112 | -------------------------------------------------------------------------------- /companies/index.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | 'Aras': require('./Aras'), 3 | 'Yurtici': require('./Yurtici') 4 | }; 5 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | module.exports = require('./companies') 2 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "kargojs", 3 | "version": "0.1.0", 4 | "description": "Türkiye Kargo firmalarından rahatça sorgulama yapabilmek için geliştirilen npm modülü.", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "https://github.com/BatuhanK/kargojs.git" 12 | }, 13 | "keywords": [ 14 | "kargo", 15 | "aras", 16 | "kargo", 17 | "yurtiçi", 18 | "kargo", 19 | "ups", 20 | "kargo" 21 | ], 22 | "author": "Batuhan KATIRCI (http://batuhan.org)", 23 | "contributors": [{ 24 | "name": "Yagiz Nizipli", 25 | "email": "yagiznizipli@gmail.com" 26 | }], 27 | "license": "ISC", 28 | "bugs": { 29 | "url": "https://github.com/BatuhanK/kargo/issues" 30 | }, 31 | "homepage": "https://github.com/BatuhanK/kargo#readme", 32 | "dependencies": { 33 | "async": "^1.4.2", 34 | "request": "^2.61.0" 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /sample.js: -------------------------------------------------------------------------------- 1 | var kargojs = require('./index'); 2 | 3 | 4 | kargojs.Yurtici.query("107683143283",function(err,data){ 5 | console.log(err ? err : data); 6 | }) 7 | 8 | 9 | kargojs.Yurtici.getMovements("107683143283",function(err,data){ 10 | console.log(err ? err : data); 11 | }) 12 | 13 | 14 | kargojs.Aras.query("5560228801279",function(err,data){ 15 | console.log(err ? err : data); 16 | }) 17 | 18 | 19 | kargojs.Aras.getMovements("5560228801279",function(err,data){ 20 | console.log(err ? err : data); 21 | }) 22 | --------------------------------------------------------------------------------