diff --git a/package-lock.json b/package-lock.json index 3060a49..ee42d37 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,8 @@ "version": "2.0.1", "license": "MIT", "dependencies": { - "undici": "^5.4.0" + "socks-proxy-agent": "^8.0.5", + "undici": "^5.28.4" }, "devDependencies": { "clean-jsdoc-theme": "^4.1.6", @@ -177,6 +178,14 @@ "node": "^12.22.0 || ^14.17.0 || >=16.0.0" } }, + "node_modules/@fastify/busboy": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/@fastify/busboy/-/busboy-2.1.1.tgz", + "integrity": "sha512-vBZP4NlzfOlerQTnba4aqZoMhE/a9HY7HRqoOPaETQcSQuWEIyZMHGfVu6w9wGtGK5fED5qRs2DteVCjOH60sA==", + "engines": { + "node": ">=14" + } + }, "node_modules/@humanwhocodes/config-array": { "version": "0.9.5", "resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.9.5.tgz", @@ -268,6 +277,7 @@ "resolved": "https://registry.npmjs.org/@types/markdown-it/-/markdown-it-12.2.3.tgz", "integrity": "sha512-GKMHFfv3458yYy+v/N8gjufHO6MSZKCOXpZc5GXIWWy8uldwfmPn98vp81gZ5f9SVw8YYBctgfJ22a2d7AOMeQ==", "dev": true, + "peer": true, "dependencies": { "@types/linkify-it": "*", "@types/mdurl": "*" @@ -323,6 +333,7 @@ "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.7.1.tgz", "integrity": "sha512-Xx54uLJQZ19lKygFXOWsscKUbsBZW0CPykPhVQdhIeIwrbPmJzqeASDInc8nKBnp/JT6igTs82qPXz069H8I/A==", "dev": true, + "peer": true, "bin": { "acorn": "bin/acorn" }, @@ -339,6 +350,15 @@ "acorn": "^6.0.0 || ^7.0.0 || ^8.0.0" } }, + "node_modules/agent-base": { + "version": "7.1.4", + "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-7.1.4.tgz", + "integrity": "sha512-MnA+YT8fwfJPgBx3m60MNqakm30XOkyIoH1y6huTQvC0PwZG7ki8NacLBcrPbNoo8vEZy7Jpuk7+jMO+CUovTQ==", + "license": "MIT", + "engines": { + "node": ">= 14" + } + }, "node_modules/ajv": { "version": "6.12.6", "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", @@ -722,7 +742,6 @@ "version": "4.3.4", "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==", - "dev": true, "dependencies": { "ms": "2.1.2" }, @@ -910,6 +929,7 @@ "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.17.0.tgz", "integrity": "sha512-gq0m0BTJfci60Fz4nczYxNAlED+sMcihltndR8t9t1evnU/azx53x3t2UHXC/uRjcbvRw/XctpaNygSTcQD+Iw==", "dev": true, + "peer": true, "dependencies": { "@eslint/eslintrc": "^1.3.0", "@humanwhocodes/config-array": "^0.9.2", @@ -1072,6 +1092,7 @@ "resolved": "https://registry.npmjs.org/eslint-plugin-import/-/eslint-plugin-import-2.26.0.tgz", "integrity": "sha512-hYfi3FXaM8WPLf4S1cikh/r4IxnO6zrhZbEGz2b660EJRbuxgpDS5gkCuYgGWg2xxh2rBuIr4Pvhve/7c31koA==", "dev": true, + "peer": true, "dependencies": { "array-includes": "^3.1.4", "array.prototype.flat": "^1.2.5", @@ -1148,6 +1169,7 @@ "resolved": "https://registry.npmjs.org/eslint-plugin-n/-/eslint-plugin-n-15.2.1.tgz", "integrity": "sha512-uMG50pvKqXK9ab163bSI5OpyZR0F5yIB0pEC4ciGpBLrXVjVDOlx5oTq8GQULWzbelJt7wL5Rw4T+FfAff5Cxg==", "dev": true, + "peer": true, "dependencies": { "builtins": "^5.0.1", "eslint-plugin-es": "^4.1.0", @@ -1173,6 +1195,7 @@ "resolved": "https://registry.npmjs.org/eslint-plugin-promise/-/eslint-plugin-promise-6.0.0.tgz", "integrity": "sha512-7GPezalm5Bfi/E22PnQxDWH2iW9GTvAlUNTztemeHb6c1BniSyoeTrM87JkC0wYdi6aQrZX9p2qEiAno8aTcbw==", "dev": true, + "peer": true, "engines": { "node": "^12.22.0 || ^14.17.0 || >=16.0.0" }, @@ -1739,6 +1762,15 @@ "node": ">= 0.4" } }, + "node_modules/ip-address": { + "version": "10.1.0", + "resolved": "https://registry.npmjs.org/ip-address/-/ip-address-10.1.0.tgz", + "integrity": "sha512-XXADHxXmvT9+CRxhXg56LJovE+bmWnEWB78LB83VZTprKTmaC5QfruXocxzTZ2Kl0DNwKuBdlIhjL8LeY8Sf8Q==", + "license": "MIT", + "engines": { + "node": ">= 12" + } + }, "node_modules/is-arrayish": { "version": "0.2.1", "resolved": "https://registry.npmjs.org/is-arrayish/-/is-arrayish-0.2.1.tgz", @@ -2030,6 +2062,7 @@ "resolved": "https://registry.npmjs.org/jsdoc/-/jsdoc-3.6.10.tgz", "integrity": "sha512-IdQ8ppSo5LKZ9o3M+LKIIK8i00DIe5msDvG3G81Km+1dhy0XrOWD0Ji8H61ElgyEj/O9KRLokgKbAM9XX9CJAg==", "dev": true, + "peer": true, "dependencies": { "@babel/parser": "^7.9.4", "@types/markdown-it": "^12.2.3", @@ -2308,6 +2341,7 @@ "resolved": "https://registry.npmjs.org/markdown-it/-/markdown-it-12.3.2.tgz", "integrity": "sha512-TchMembfxfNVpHkbtriWltGWc+m3xszaRD0CZup7GFFhzIgQqxIfn3eGj1yZpfuflzPvfkt611B2Q/Bsk1YnGg==", "dev": true, + "peer": true, "dependencies": { "argparse": "^2.0.1", "entities": "~2.1.0", @@ -2928,8 +2962,7 @@ "node_modules/ms": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", - "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", - "dev": true + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" }, "node_modules/nanoid": { "version": "3.3.4", @@ -3993,6 +4026,44 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/smart-buffer": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/smart-buffer/-/smart-buffer-4.2.0.tgz", + "integrity": "sha512-94hK0Hh8rPqQl2xXc3HsaBoOXKV20MToPkcXvwbISWLEs+64sBq5kFgn2kJDHb1Pry9yrP0dxrCI9RRci7RXKg==", + "license": "MIT", + "engines": { + "node": ">= 6.0.0", + "npm": ">= 3.0.0" + } + }, + "node_modules/socks": { + "version": "2.8.7", + "resolved": "https://registry.npmjs.org/socks/-/socks-2.8.7.tgz", + "integrity": "sha512-HLpt+uLy/pxB+bum/9DzAgiKS8CX1EvbWxI4zlmgGCExImLdiad2iCwXT5Z4c9c3Eq8rP2318mPW2c+QbtjK8A==", + "license": "MIT", + "dependencies": { + "ip-address": "^10.0.1", + "smart-buffer": "^4.2.0" + }, + "engines": { + "node": ">= 10.0.0", + "npm": ">= 3.0.0" + } + }, + "node_modules/socks-proxy-agent": { + "version": "8.0.5", + "resolved": "https://registry.npmjs.org/socks-proxy-agent/-/socks-proxy-agent-8.0.5.tgz", + "integrity": "sha512-HehCEsotFqbPW9sJ8WVYB6UbmIMv7kUUORIF2Nncq4VQvBfNBLibW9YZR5dlYCSUhwcD628pRllm7n+E+YTzJw==", + "license": "MIT", + "dependencies": { + "agent-base": "^7.1.2", + "debug": "^4.3.4", + "socks": "^2.8.3" + }, + "engines": { + "node": ">= 14" + } + }, "node_modules/source-map": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", @@ -4292,11 +4363,14 @@ "dev": true }, "node_modules/undici": { - "version": "5.4.0", - "resolved": "https://registry.npmjs.org/undici/-/undici-5.4.0.tgz", - "integrity": "sha512-A1SRXysDg7J+mVP46jF+9cKANw0kptqSFZ8tGyL+HBiv0K1spjxPX8Z4EGu+Eu6pjClJUBdnUPlxrOafR668/g==", + "version": "5.28.4", + "resolved": "https://registry.npmjs.org/undici/-/undici-5.28.4.tgz", + "integrity": "sha512-72RFADWFqKmUb2hmmvNODKL3p9hcB6Gt2DOQMis1SEBaV6a4MH8soBvzg+95CYhCKPFedut2JY9bMfrDl9D23g==", + "dependencies": { + "@fastify/busboy": "^2.0.0" + }, "engines": { - "node": ">=12.18" + "node": ">=14.0" } }, "node_modules/unified": { @@ -4879,6 +4953,11 @@ "strip-json-comments": "^3.1.1" } }, + "@fastify/busboy": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/@fastify/busboy/-/busboy-2.1.1.tgz", + "integrity": "sha512-vBZP4NlzfOlerQTnba4aqZoMhE/a9HY7HRqoOPaETQcSQuWEIyZMHGfVu6w9wGtGK5fED5qRs2DteVCjOH60sA==" + }, "@humanwhocodes/config-array": { "version": "0.9.5", "resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.9.5.tgz", @@ -4967,6 +5046,7 @@ "resolved": "https://registry.npmjs.org/@types/markdown-it/-/markdown-it-12.2.3.tgz", "integrity": "sha512-GKMHFfv3458yYy+v/N8gjufHO6MSZKCOXpZc5GXIWWy8uldwfmPn98vp81gZ5f9SVw8YYBctgfJ22a2d7AOMeQ==", "dev": true, + "peer": true, "requires": { "@types/linkify-it": "*", "@types/mdurl": "*" @@ -5021,7 +5101,8 @@ "version": "8.7.1", "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.7.1.tgz", "integrity": "sha512-Xx54uLJQZ19lKygFXOWsscKUbsBZW0CPykPhVQdhIeIwrbPmJzqeASDInc8nKBnp/JT6igTs82qPXz069H8I/A==", - "dev": true + "dev": true, + "peer": true }, "acorn-jsx": { "version": "5.3.2", @@ -5030,6 +5111,11 @@ "dev": true, "requires": {} }, + "agent-base": { + "version": "7.1.4", + "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-7.1.4.tgz", + "integrity": "sha512-MnA+YT8fwfJPgBx3m60MNqakm30XOkyIoH1y6huTQvC0PwZG7ki8NacLBcrPbNoo8vEZy7Jpuk7+jMO+CUovTQ==" + }, "ajv": { "version": "6.12.6", "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", @@ -5320,7 +5406,6 @@ "version": "4.3.4", "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==", - "dev": true, "requires": { "ms": "2.1.2" } @@ -5460,6 +5545,7 @@ "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.17.0.tgz", "integrity": "sha512-gq0m0BTJfci60Fz4nczYxNAlED+sMcihltndR8t9t1evnU/azx53x3t2UHXC/uRjcbvRw/XctpaNygSTcQD+Iw==", "dev": true, + "peer": true, "requires": { "@eslint/eslintrc": "^1.3.0", "@humanwhocodes/config-array": "^0.9.2", @@ -5579,6 +5665,7 @@ "resolved": "https://registry.npmjs.org/eslint-plugin-import/-/eslint-plugin-import-2.26.0.tgz", "integrity": "sha512-hYfi3FXaM8WPLf4S1cikh/r4IxnO6zrhZbEGz2b660EJRbuxgpDS5gkCuYgGWg2xxh2rBuIr4Pvhve/7c31koA==", "dev": true, + "peer": true, "requires": { "array-includes": "^3.1.4", "array.prototype.flat": "^1.2.5", @@ -5642,6 +5729,7 @@ "resolved": "https://registry.npmjs.org/eslint-plugin-n/-/eslint-plugin-n-15.2.1.tgz", "integrity": "sha512-uMG50pvKqXK9ab163bSI5OpyZR0F5yIB0pEC4ciGpBLrXVjVDOlx5oTq8GQULWzbelJt7wL5Rw4T+FfAff5Cxg==", "dev": true, + "peer": true, "requires": { "builtins": "^5.0.1", "eslint-plugin-es": "^4.1.0", @@ -5658,6 +5746,7 @@ "resolved": "https://registry.npmjs.org/eslint-plugin-promise/-/eslint-plugin-promise-6.0.0.tgz", "integrity": "sha512-7GPezalm5Bfi/E22PnQxDWH2iW9GTvAlUNTztemeHb6c1BniSyoeTrM87JkC0wYdi6aQrZX9p2qEiAno8aTcbw==", "dev": true, + "peer": true, "requires": {} }, "eslint-scope": { @@ -6076,6 +6165,11 @@ "side-channel": "^1.0.4" } }, + "ip-address": { + "version": "10.1.0", + "resolved": "https://registry.npmjs.org/ip-address/-/ip-address-10.1.0.tgz", + "integrity": "sha512-XXADHxXmvT9+CRxhXg56LJovE+bmWnEWB78LB83VZTprKTmaC5QfruXocxzTZ2Kl0DNwKuBdlIhjL8LeY8Sf8Q==" + }, "is-arrayish": { "version": "0.2.1", "resolved": "https://registry.npmjs.org/is-arrayish/-/is-arrayish-0.2.1.tgz", @@ -6269,6 +6363,7 @@ "resolved": "https://registry.npmjs.org/jsdoc/-/jsdoc-3.6.10.tgz", "integrity": "sha512-IdQ8ppSo5LKZ9o3M+LKIIK8i00DIe5msDvG3G81Km+1dhy0XrOWD0Ji8H61ElgyEj/O9KRLokgKbAM9XX9CJAg==", "dev": true, + "peer": true, "requires": { "@babel/parser": "^7.9.4", "@types/markdown-it": "^12.2.3", @@ -6489,6 +6584,7 @@ "resolved": "https://registry.npmjs.org/markdown-it/-/markdown-it-12.3.2.tgz", "integrity": "sha512-TchMembfxfNVpHkbtriWltGWc+m3xszaRD0CZup7GFFhzIgQqxIfn3eGj1yZpfuflzPvfkt611B2Q/Bsk1YnGg==", "dev": true, + "peer": true, "requires": { "argparse": "^2.0.1", "entities": "~2.1.0", @@ -6851,8 +6947,7 @@ "ms": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", - "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", - "dev": true + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" }, "nanoid": { "version": "3.3.4", @@ -7638,6 +7733,30 @@ "object-inspect": "^1.9.0" } }, + "smart-buffer": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/smart-buffer/-/smart-buffer-4.2.0.tgz", + "integrity": "sha512-94hK0Hh8rPqQl2xXc3HsaBoOXKV20MToPkcXvwbISWLEs+64sBq5kFgn2kJDHb1Pry9yrP0dxrCI9RRci7RXKg==" + }, + "socks": { + "version": "2.8.7", + "resolved": "https://registry.npmjs.org/socks/-/socks-2.8.7.tgz", + "integrity": "sha512-HLpt+uLy/pxB+bum/9DzAgiKS8CX1EvbWxI4zlmgGCExImLdiad2iCwXT5Z4c9c3Eq8rP2318mPW2c+QbtjK8A==", + "requires": { + "ip-address": "^10.0.1", + "smart-buffer": "^4.2.0" + } + }, + "socks-proxy-agent": { + "version": "8.0.5", + "resolved": "https://registry.npmjs.org/socks-proxy-agent/-/socks-proxy-agent-8.0.5.tgz", + "integrity": "sha512-HehCEsotFqbPW9sJ8WVYB6UbmIMv7kUUORIF2Nncq4VQvBfNBLibW9YZR5dlYCSUhwcD628pRllm7n+E+YTzJw==", + "requires": { + "agent-base": "^7.1.2", + "debug": "^4.3.4", + "socks": "^2.8.3" + } + }, "source-map": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", @@ -7862,9 +7981,12 @@ "dev": true }, "undici": { - "version": "5.4.0", - "resolved": "https://registry.npmjs.org/undici/-/undici-5.4.0.tgz", - "integrity": "sha512-A1SRXysDg7J+mVP46jF+9cKANw0kptqSFZ8tGyL+HBiv0K1spjxPX8Z4EGu+Eu6pjClJUBdnUPlxrOafR668/g==" + "version": "5.28.4", + "resolved": "https://registry.npmjs.org/undici/-/undici-5.28.4.tgz", + "integrity": "sha512-72RFADWFqKmUb2hmmvNODKL3p9hcB6Gt2DOQMis1SEBaV6a4MH8soBvzg+95CYhCKPFedut2JY9bMfrDl9D23g==", + "requires": { + "@fastify/busboy": "^2.0.0" + } }, "unified": { "version": "10.1.2", diff --git a/package.json b/package.json index 0fc75ab..3fbeef7 100644 --- a/package.json +++ b/package.json @@ -10,17 +10,18 @@ "remark": "npx remark README.md --use remark-preset-lint-consistent --use remark-preset-lint-recommended" }, "dependencies": { - "undici": "^5.4.0" + "socks-proxy-agent": "^8.0.5", + "undici": "^5.28.4" }, "devDependencies": { + "clean-jsdoc-theme": "^4.1.6", "eslint": "^8.17.0", "eslint-config-standard": "^17.0.0", "eslint-plugin-import": "^2.26.0", + "eslint-plugin-jsdoc": "^37.7.0", "eslint-plugin-n": "^15.2.1", "eslint-plugin-promise": "^6.0.0", "jsdoc": "^3.6.10", - "eslint-plugin-jsdoc": "^37.7.0", - "clean-jsdoc-theme": "^4.1.6", "remark-cli": "^10.0.1", "remark-preset-lint-consistent": "^5.1.1", "remark-preset-lint-recommended": "^6.1.2" diff --git a/src/countries.json b/src/countries.json new file mode 100644 index 0000000..8d15cfa --- /dev/null +++ b/src/countries.json @@ -0,0 +1,660 @@ +[ + { + "code": "RU", + "country": "Russia", + "phoneCode": 7, + "smsHubId": 0, + "smsBowerId": 0 + }, + { + "code": "UA", + "country": "Ukraine", + "phoneCode": 380, + "smsHubId": 1, + "smsBowerId": 1 + }, + { + "code": "KZ", + "country": "Kazakhstan", + "phoneCode": 7, + "smsHubId": 2, + "smsBowerId": 2 + }, + { + "code": "CN", + "country": "China", + "phoneCode": 86, + "smsHubId": 3, + "smsBowerId": 3 + }, + { + "code": "PH", + "country": "Philippines", + "phoneCode": 63, + "smsHubId": 4, + "smsBowerId": 4 + }, + { + "code": "MM", + "country": "Myanmar", + "phoneCode": 95, + "smsHubId": 5, + "smsBowerId": 5 + }, + { + "code": "ID", + "country": "Indonesia", + "phoneCode": 62, + "smsHubId": 6, + "smsBowerId": 6 + }, + { + "code": "MY", + "country": "Malaysia", + "phoneCode": 60, + "smsHubId": 7, + "smsBowerId": 7 + }, + { + "code": "KE", + "country": "Kenya", + "phoneCode": 254, + "smsHubId": 8, + "smsBowerId": 8 + }, + { + "code": "TZ", + "country": "Tanzania", + "phoneCode": 255, + "smsHubId": 9, + "smsBowerId": 9 + }, + { + "code": "VN", + "country": "Vietnam", + "phoneCode": 84, + "smsHubId": 10, + "smsBowerId": 10 + }, + { + "code": "KG", + "country": "Kyrgyzstan", + "phoneCode": 996, + "smsHubId": 11, + "smsBowerId": 11 + }, + { + "code": "US", + "country": "USA (Virtual)", + "phoneCode": 1, + "smsHubId": 12, + "smsBowerId": 12 + }, + { + "code": "US_nonvirt", + "country": "USA", + "phoneCode": 1, + "smsHubId": 187, + "smsBowerId": 187 + }, + { + "code": "IL", + "country": "Israel", + "phoneCode": 972, + "smsHubId": 13, + "smsBowerId": 13 + }, + { + "code": "HK", + "country": "Hong Kong", + "phoneCode": 852, + "smsHubId": 14, + "smsBowerId": 14 + }, + { + "code": "PL", + "country": "Poland", + "phoneCode": 48, + "smsHubId": 15, + "smsBowerId": 15 + }, + { + "code": "GB", + "country": "United Kingdom", + "phoneCode": 44, + "smsHubId": 16, + "smsBowerId": 16 + }, + { + "code": "MG", + "country": "Madagascar", + "phoneCode": 261, + "smsHubId": 17, + "smsBowerId": 17 + }, + { + "code": "CD", + "country": "Democratic Republic of the Congo", + "phoneCode": 243, + "smsHubId": 18, + "smsBowerId": 18 + }, + { + "code": "NG", + "country": "Nigeria", + "phoneCode": 234, + "smsHubId": 19, + "smsBowerId": 19 + }, + { + "code": "MO", + "country": "Macao", + "phoneCode": 853, + "smsHubId": 20, + "smsBowerId": 20 + }, + { + "code": "EG", + "country": "Egypt", + "phoneCode": 20, + "smsHubId": 21, + "smsBowerId": 21 + }, + { + "code": "IN", + "country": "India", + "phoneCode": 91, + "smsHubId": 22, + "smsBowerId": 22 + }, + { + "code": "IE", + "country": "Ireland", + "phoneCode": 353, + "smsHubId": 23, + "smsBowerId": 23 + }, + { + "code": "KH", + "country": "Cambodia", + "phoneCode": 855, + "smsHubId": 24, + "smsBowerId": 24 + }, + { + "code": "LA", + "country": "Laos", + "phoneCode": 856, + "smsHubId": 25, + "smsBowerId": 25 + }, + { + "code": "HT", + "country": "Haiti", + "phoneCode": 509, + "smsHubId": 26, + "smsBowerId": 26 + }, + { + "code": "CI", + "country": "Côte d'Ivoire", + "phoneCode": 225, + "smsHubId": 27, + "smsBowerId": 27 + }, + { + "code": "GM", + "country": "Gambia", + "phoneCode": 220, + "smsHubId": 28, + "smsBowerId": 28 + }, + { + "code": "RS", + "country": "Serbia", + "phoneCode": 381, + "smsHubId": 29, + "smsBowerId": 29 + }, + { + "code": "YE", + "country": "Yemen", + "phoneCode": 967, + "smsHubId": 30, + "smsBowerId": 30 + }, + { + "code": "ZA", + "country": "South Africa", + "phoneCode": 27, + "smsHubId": 31, + "smsBowerId": 31 + }, + { + "code": "RO", + "country": "Romania", + "phoneCode": 40, + "smsHubId": 32, + "smsBowerId": 32 + }, + { + "code": "CO", + "country": "Colombia", + "phoneCode": 57, + "smsHubId": 33, + "smsBowerId": 33 + }, + { + "code": "EE", + "country": "Estonia", + "phoneCode": 372, + "smsHubId": 34, + "smsBowerId": 34 + }, + { + "code": "AZ", + "country": "Azerbaijan", + "phoneCode": 994, + "smsHubId": 35, + "smsBowerId": 35 + }, + { + "code": "CA", + "country": "Canada", + "phoneCode": 1, + "smsHubId": 36, + "smsBowerId": 36 + }, + { + "code": "MA", + "country": "Morocco", + "phoneCode": 212, + "smsHubId": 37, + "smsBowerId": 37 + }, + { + "code": "GH", + "country": "Ghana", + "phoneCode": 233, + "smsHubId": 38, + "smsBowerId": 38 + }, + { + "code": "AR", + "country": "Argentina", + "phoneCode": 54, + "smsHubId": 39, + "smsBowerId": 39 + }, + { + "code": "UZ", + "country": "Uzbekistan", + "phoneCode": 998, + "smsHubId": 40, + "smsBowerId": 40 + }, + { + "code": "CM", + "country": "Cameroon", + "phoneCode": 237, + "smsHubId": 41, + "smsBowerId": 41 + }, + { + "code": "TD", + "country": "Chad", + "phoneCode": 235, + "smsHubId": 42, + "smsBowerId": 42 + }, + { + "code": "DE", + "country": "Germany", + "phoneCode": 49, + "smsHubId": 43, + "smsBowerId": 43 + }, + { + "code": "LT", + "country": "Lithuania", + "phoneCode": 370, + "smsHubId": 44, + "smsBowerId": 44 + }, + { + "code": "HR", + "country": "Croatia", + "phoneCode": 385, + "smsHubId": 45, + "smsBowerId": 45 + }, + { + "code": "SE", + "country": "Sweden", + "phoneCode": 46, + "smsHubId": 46, + "smsBowerId": 174 + }, + { + "code": "IQ", + "country": "Iraq", + "phoneCode": 964, + "smsHubId": 47, + "smsBowerId": 47 + }, + { + "code": "NL", + "country": "Netherlands", + "phoneCode": 31, + "smsHubId": 48, + "smsBowerId": 48 + }, + { + "code": "LV", + "country": "Latvia", + "phoneCode": 371, + "smsHubId": 49, + "smsBowerId": 49 + }, + { + "code": "AT", + "country": "Austria", + "phoneCode": 43, + "smsHubId": 50, + "smsBowerId": 50 + }, + { + "code": "BY", + "country": "Belarus", + "phoneCode": 375, + "smsHubId": 51, + "smsBowerId": 51 + }, + { + "code": "TH", + "country": "Thailand", + "phoneCode": 66, + "smsHubId": 52, + "smsBowerId": 52 + }, + { + "code": "SA", + "country": "Saudi Arabia", + "phoneCode": 966, + "smsHubId": 53, + "smsBowerId": 53 + }, + { + "code": "MX", + "country": "Mexico", + "phoneCode": 52, + "smsHubId": 54, + "smsBowerId": 54 + }, + { + "code": "TW", + "country": "Taiwan", + "phoneCode": 886, + "smsHubId": 55, + "smsBowerId": 55 + }, + { + "code": "ES", + "country": "Spain", + "phoneCode": 34, + "smsHubId": 56, + "smsBowerId": 56 + }, + { + "code": "IR", + "country": "Iran", + "phoneCode": 98, + "smsHubId": 57, + "smsBowerId": 57 + }, + { + "code": "DZ", + "country": "Algeria", + "phoneCode": 213, + "smsHubId": 58, + "smsBowerId": 58 + }, + { + "code": "SI", + "country": "Slovenia", + "phoneCode": 386, + "smsHubId": 59, + "smsBowerId": 59 + }, + { + "code": "BD", + "country": "Bangladesh", + "phoneCode": 880, + "smsHubId": 60, + "smsBowerId": 60 + }, + { + "code": "SN", + "country": "Senegal", + "phoneCode": 221, + "smsHubId": 61, + "smsBowerId": 61 + }, + { + "code": "TR", + "country": "Turkey", + "phoneCode": 90, + "smsHubId": 62, + "smsBowerId": 62 + }, + { + "code": "CZ", + "country": "Czech Republic", + "phoneCode": 420, + "smsHubId": 63, + "smsBowerId": 63 + }, + { + "code": "LK", + "country": "Sri Lanka", + "phoneCode": 94, + "smsHubId": 64, + "smsBowerId": 64 + }, + { + "code": "PE", + "country": "Peru", + "phoneCode": 51, + "smsHubId": 65, + "smsBowerId": 65 + }, + { + "code": "PK", + "country": "Pakistan", + "phoneCode": 92, + "smsHubId": 66, + "smsBowerId": 66 + }, + { + "code": "NZ", + "country": "New Zealand", + "phoneCode": 64, + "smsHubId": 67, + "smsBowerId": 175 + }, + { + "code": "GN", + "country": "Guinea", + "phoneCode": 224, + "smsHubId": 68, + "smsBowerId": 68 + }, + { + "code": "ML", + "country": "Mali", + "phoneCode": 223, + "smsHubId": 69, + "smsBowerId": 69 + }, + { + "code": "VE", + "country": "Venezuela", + "phoneCode": 58, + "smsHubId": 70, + "smsBowerId": 70 + }, + { + "code": "ET", + "country": "Ethiopia", + "phoneCode": 251, + "smsHubId": 71, + "smsBowerId": 71 + }, + { + "code": "MN", + "country": "Mongolia", + "phoneCode": 976, + "smsHubId": 72, + "smsBowerId": 72 + }, + { + "code": "BR", + "country": "Brazil", + "phoneCode": 55, + "smsHubId": 73, + "smsBowerId": 73 + }, + { + "code": "AF", + "country": "Afghanistan", + "phoneCode": 93, + "smsHubId": 74, + "smsBowerId": 74 + }, + { + "code": "UG", + "country": "Uganda", + "phoneCode": 256, + "smsHubId": 75, + "smsBowerId": 75 + }, + { + "code": "AO", + "country": "Angola", + "phoneCode": 244, + "smsHubId": 76, + "smsBowerId": 76 + }, + { + "code": "CY", + "country": "Cyprus", + "phoneCode": 357, + "smsHubId": 77, + "smsBowerId": 77 + }, + { + "code": "FR", + "country": "France", + "phoneCode": 33, + "smsHubId": 78, + "smsBowerId": 78 + }, + { + "code": "PG", + "country": "Papua New Guinea", + "phoneCode": 675, + "smsHubId": 79, + "smsBowerId": 79 + }, + { + "code": "MZ", + "country": "Mozambique", + "phoneCode": 258, + "smsHubId": 80, + "smsBowerId": 80 + }, + { + "code": "NP", + "country": "Nepal", + "phoneCode": 977, + "smsHubId": 81, + "smsBowerId": 81 + }, + { + "code": "BE", + "country": "Belgium", + "phoneCode": 32, + "smsHubId": 82, + "smsBowerId": 82 + }, + { + "code": "BG", + "country": "Bulgaria", + "phoneCode": 359, + "smsHubId": 83, + "smsBowerId": 83 + }, + { + "code": "HU", + "country": "Hungary", + "phoneCode": 36, + "smsHubId": 84, + "smsBowerId": 84 + }, + { + "code": "DK", + "country": "Denmark", + "phoneCode": 45, + "smsHubId": 85, + "smsBowerId": 172 + }, + { + "code": "FI", + "country": "Finland", + "phoneCode": 358, + "smsHubId": 86, + "smsBowerId": 163 + }, + { + "code": "NO", + "country": "Norway", + "phoneCode": 47, + "smsHubId": 87, + "smsBowerId": 174 + }, + { + "code": "IS", + "country": "Iceland", + "phoneCode": 354, + "smsHubId": 88, + "smsBowerId": 132 + }, + { + "code": "ZW", + "country": "Zimbabwe", + "phoneCode": 263, + "smsHubId": 89, + "smsBowerId": 89 + }, + { + "code": "PY", + "country": "Paraguay", + "phoneCode": 595, + "smsHubId": 90, + "smsBowerId": 87 + }, + { + "code": "SY", + "country": "Syria", + "phoneCode": 963, + "smsHubId": 91, + "smsBowerId": 91 + }, + { + "code": "UG", + "country": "Uganda", + "phoneCode": 256, + "smsHubId": 92, + "smsBowerId": 75 + } +] \ No newline at end of file diff --git a/src/index.js b/src/index.js index d8a2b7f..f9ab48a 100644 --- a/src/index.js +++ b/src/index.js @@ -1,4 +1,8 @@ -const { request } = require('undici') +const { request, ProxyAgent } = require('undici') +const { SocksProxyAgent } = require('socks-proxy-agent') +const https = require('https') +const http = require('http') +const countries = require('./countries.json'); const errorsList = { BANNED: 'Account banned', @@ -31,6 +35,9 @@ const supportedMethods = { smsactivate: [ 'getNumbersStatus', 'getBalance', 'getNumber', 'setStatus', 'getStatus', 'getPrices', 'getFullSms', 'getAdditionalService', 'getCountries', 'getQiwiRequisites', 'getCode' + ], + smsbower: [ + 'getBalance', 'getNumber', 'setStatus', 'getStatus', 'getPrices', 'getCode', 'setMaxPrice' ] } @@ -90,6 +97,7 @@ class GetSMS { * @property {(en|ru)} [lang=ru] - Lang code, smshub can returns results with russian or english (Only smshub) * @property {(smshub|smsactivate)} service - Service name * @property {interval} [interval=2000] - Polling interval of getCode method + * @property {boolean} [withoutCountryCode=false] - Return numbers without country code */ /** @@ -99,11 +107,11 @@ class GetSMS { * @param {InitProperties} - Options object * @throws Error */ - constructor ({ key, url, secondUrl = 'https://smshub.org/api.php', service, lang = 'ru', interval = 2000 }) { + constructor ({ key, url, secondUrl = 'https://smshub.org/api.php', service, lang = 'ru', interval = 2000, withoutCountryCode = false, proxyUrl = null }) { if (!key || !url || !service) { throw new Error('Missing argument(s)') } - if (!['smshub', 'smsactivate'].includes(service)) { + if (!['smshub', 'smsactivate', 'smsbower'].includes(service)) { throw new Error('Invalid service name') } this._key = key @@ -112,6 +120,9 @@ class GetSMS { this._secondUrl = secondUrl this._service = service this._interval = interval + this._withoutCountryCode = withoutCountryCode + this._proxyUrl = proxyUrl + this._maxPrice = null; return new Proxy(this, { get (target, prop) { @@ -150,12 +161,86 @@ class GetSMS { Object.assign(qs, { api_key: this._key }) ).toString() + let useSocksProxy = false; + let socksAgent = null; + let dispatcher = {}; + + if (this._proxyUrl) { + const uri = new URL(this._proxyUrl); + + // Check if it's a SOCKS proxy + if (uri.protocol === 'socks:' || uri.protocol === 'socks4:' || uri.protocol === 'socks5:') { + // Use Node.js native request with SocksProxyAgent + useSocksProxy = true; + socksAgent = new SocksProxyAgent(this._proxyUrl); + } else { + // Use ProxyAgent for HTTP/HTTPS proxies with undici + const token = + "Basic " + + Buffer.from(`${uri.username}:${uri.password}`).toString("base64"); + + dispatcher = { + dispatcher : new ProxyAgent({ + uri: uri, + token: token, + }), + } + } + } + + // Use SOCKS proxy with Node.js native request + if (useSocksProxy) { + return new Promise((resolve, reject) => { + const requestModule = url.protocol === 'https:' ? https : http; + const options = { + method, + headers: { + Cookie: 'lang=' + this._lang + }, + agent: socksAgent + }; + + if (form) { + const formData = new URLSearchParams(form).toString(); + options.headers['Content-Type'] = 'application/x-www-form-urlencoded'; + options.headers['Content-Length'] = Buffer.byteLength(formData); + } + + const req = requestModule.request(url, options, (res) => { + let data = ''; + res.on('data', (chunk) => { data += chunk; }); + res.on('end', () => { + try { + const parsed = JSON.parse(data); + resolve(parsed); + } catch (e) { + if (!ServiceApiError._check(data)) { + resolve(data); + } else { + reject(new ServiceApiError(data)); + } + } + }); + }); + + req.on('error', reject); + + if (form) { + req.write(new URLSearchParams(form).toString()); + } + + req.end(); + }); + } + + // Use undici for non-SOCKS proxies or no proxy return request(url, { method, form: form ? new URLSearchParams(form).toString() : undefined, headers: { Cookie: 'lang=' + this._lang - } + }, + ...dispatcher }) .then(data => data.body.text()) .then(data => { @@ -237,6 +322,7 @@ class GetSMS { * .getMultiServiceNumber(['ok','vk','vi','av'], 'mts', 0, [0, 1, 0, 0]) */ getMultiServiceNumber (service, operator, country, forward, ref) { + country = this._getCountryId(country) if (Array.isArray(service)) service = service.toString() if (Array.isArray(forward)) forward = forward.toString() if (Array.isArray(operator)) operator = operator.toString() @@ -376,15 +462,22 @@ class GetSMS { * @method * @public * @async - * @param {string} service - Service code name - * @param {string|number} maxPrice - Max buy price + * @param {string|number} maxPrice - Max buy price (for SmsHub in USD, no need to add country) * @param {boolean} random - Enable random number - * @param {string|number} country - Country ID + * @param {string|number|null} country - Country ID * @returns {Promise} * @throws Error * @throws ServiceApiError */ - setMaxPrice (service, maxPrice, random = true, country) { + setMaxPrice (maxPrice, random = true, country = null) { + + // For smshub it will be used during getNumber request + if ('smshub' === this._service || 'smsbower' === this._service) { + this._maxPrice = maxPrice; + return; + } + country = this._getCountryId(country) + return this._request({ action: 'setMaxPrice', service, maxPrice, country, random }) } @@ -443,7 +536,7 @@ class GetSMS { * @public * @async * @param {string} service - Service code name - * @param {string} [operator] - Mobile operator code name + * @param {string|array} [operators] - Mobile operator code name or multiple operators in array (will be choosen random + will be changed if no numbers) * @param {string|number} [country] - Country ID * @param {(string|number)} [forward] - Number forward, must be 1 or 0 * * @param {string} [phoneException] - Prefixes for excepting mobile numbers separated by comma * @@ -452,15 +545,36 @@ class GetSMS { * @throws Error * @throws ServiceApiError */ - getNumber (service, operator, country, forward, phoneException, ref) { - return this._request({ action: 'getNumber', service, operator, country, forward, phoneException, ref }) - .then((response) => { - const [, id, number] = response.split(':') - return { - id, - number - } - }) + getNumber (service, operators, country, forward, phoneException = '', ref = '') { + country = this._getCountryId(country); + const operator = Array.isArray(operators) ? operators[Math.floor(Math.random() * operators.length)] : operators; + + return this._request({ action: 'getNumber', service, operator, country, forward, phoneException, ref, ...(('smshub' === this._service || 'smsbower' === this._service) && this._maxPrice !== null && { maxPrice: this._maxPrice, currency: 840 }) }) + .then((response) => { + let [, id, number] = response.split(':') + + // Removing country code if needed + if (this._withoutCountryCode) { + const countryObj = countries.find((el) => { + return el.smsHubId === country + }) + // removing country number, but only if it is in the beginning of the string + number = number.replace(new RegExp('^' + countryObj.phoneCode), '') + } + + return { + id, + number + } + }) + .catch((e) => { + // If operators are array, trying again but excluding failed operator + if ('NO_NUMBERS' === e.code && 'string' !== typeof operators && 0 !== operators.length) { + return this.getNumber(service, operators.filter(value => value !== operator), country, forward, phoneException, ref); + } else { + throw e; + } + }) } /** @@ -579,10 +693,37 @@ class GetSMS { * @throws ServiceApiError */ getPrices (service, country) { + country = this._getCountryId(country) return this._request({ action: 'getPrices', country, service }) } + + /** + * Method for getting ID of the country by 2 letter code + * @method + * @private + * @param {string|number} [country] - Country ID or 2 letter symbol code + * @returns number + * @throws Error + */ + _getCountryId(country) { + if (!/^-?\d+$/.test(country) && 'number' !== typeof country && (2 === country.length || 'US_nonvirt' === country)) { + const res = countries.find((el) => el.code === country) + if (res) { + console.log(`res`, JSON.stringify(res), this._service); + if ('smshub' === this._service) { + return res.smsHubId; + } else if ('smsbower' === this._service) { + return res.smsBowerId; + } + } else { + throw new Error('Country ID is not found by 2 letter symbol code') + } + } + return country; + } } + module.exports = { GetSMS, ServiceApiError,