@8ms/helpers 2.0.0 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (345) hide show
  1. package/.github/workflows/deploy_npmjs.yml +7 -0
  2. package/.yarn/install-state.gz +0 -0
  3. package/_class/BaseClass.d.ts +18 -0
  4. package/_class/BaseClass.js +53 -0
  5. package/_class/BaseNamespace.d.ts +9 -0
  6. package/_class/BaseNamespace.js +27 -0
  7. package/_class/index.d.ts +2 -0
  8. package/_class/index.js +7 -0
  9. package/adverity/getJobs.d.ts +15 -0
  10. package/adverity/getJobs.js +30 -0
  11. package/adverity/index.d.ts +112 -0
  12. package/adverity/index.js +61 -0
  13. package/api/ApiResponseClass.d.ts +35 -0
  14. package/api/ApiResponseClass.js +97 -0
  15. package/api/index.d.ts +22 -0
  16. package/api/index.js +44 -0
  17. package/array/index.d.ts +8 -0
  18. package/array/index.js +17 -0
  19. package/atInternet/index.d.ts +16 -0
  20. package/atInternet/index.js +18 -0
  21. package/aws/athenaExpress/AwsAthenaNamespace.d.ts +8 -0
  22. package/aws/athenaExpress/AwsAthenaNamespace.js +82 -0
  23. package/aws/athenaExpress/index.d.ts +10 -0
  24. package/aws/athenaExpress/index.js +40 -0
  25. package/aws/ec2/AwsEc2Namespace.d.ts +10 -0
  26. package/aws/ec2/AwsEc2Namespace.js +78 -0
  27. package/aws/ec2/index.d.ts +3 -0
  28. package/aws/ec2/index.js +16 -0
  29. package/aws/ecs/AwsEcsNamespace.d.ts +53 -0
  30. package/aws/ecs/AwsEcsNamespace.js +159 -0
  31. package/aws/ecs/index.d.ts +3 -0
  32. package/aws/ecs/index.js +16 -0
  33. package/aws/glue/AwsGlueNamespace.d.ts +12 -0
  34. package/aws/glue/AwsGlueNamespace.js +70 -0
  35. package/aws/glue/index.d.ts +3 -0
  36. package/aws/glue/index.js +16 -0
  37. package/aws/index.d.ts +9 -0
  38. package/aws/index.js +34 -0
  39. package/aws/isResponse200.d.ts +4 -0
  40. package/aws/isResponse200.js +16 -0
  41. package/aws/lambda/AwsLambdaNamespace.d.ts +21 -0
  42. package/aws/lambda/AwsLambdaNamespace.js +110 -0
  43. package/aws/lambda/index.d.ts +4 -0
  44. package/aws/lambda/index.js +21 -0
  45. package/aws/s3/AwsS3Namespace.d.ts +60 -0
  46. package/aws/s3/AwsS3Namespace.js +401 -0
  47. package/aws/s3/index.d.ts +25 -0
  48. package/aws/s3/index.js +36 -0
  49. package/aws/s3/payload.d.ts +42 -0
  50. package/aws/s3/payload.js +46 -0
  51. package/aws/ses/AwsSesNamespace.d.ts +18 -0
  52. package/aws/ses/AwsSesNamespace.js +69 -0
  53. package/aws/ses/SimpleEmail.d.ts +56 -0
  54. package/aws/ses/SimpleEmail.js +106 -0
  55. package/aws/ses/index.d.ts +4 -0
  56. package/aws/ses/index.js +18 -0
  57. package/aws/sqs/AwsSqsNamespace.d.ts +34 -0
  58. package/aws/sqs/AwsSqsNamespace.js +96 -0
  59. package/aws/sqs/index.d.ts +3 -0
  60. package/aws/sqs/index.js +16 -0
  61. package/aws/ssm/AwsSsmNamespace.d.ts +11 -0
  62. package/aws/ssm/AwsSsmNamespace.js +89 -0
  63. package/aws/ssm/index.d.ts +3 -0
  64. package/aws/ssm/index.js +16 -0
  65. package/axios/deleteRequest.d.ts +6 -0
  66. package/axios/deleteRequest.js +33 -0
  67. package/axios/get.d.ts +5 -0
  68. package/axios/get.js +31 -0
  69. package/axios/index.d.ts +3 -0
  70. package/axios/index.js +9 -0
  71. package/axios/post.d.ts +5 -0
  72. package/axios/post.js +32 -0
  73. package/boolean/getBoolean.d.ts +4 -0
  74. package/boolean/getBoolean.js +23 -0
  75. package/boolean/index.d.ts +1 -0
  76. package/boolean/index.js +5 -0
  77. package/brightData/index.d.ts +15 -0
  78. package/brightData/index.js +20 -0
  79. package/brightData/serpApi/buildGoogleSerpUrl.d.ts +32 -0
  80. package/brightData/serpApi/buildGoogleSerpUrl.js +116 -0
  81. package/brightData/serpApi/buildGoogleTrendsUrl.d.ts +22 -0
  82. package/brightData/serpApi/buildGoogleTrendsUrl.js +61 -0
  83. package/brightData/serpApi/getAsyncRequestId.d.ts +8 -0
  84. package/brightData/serpApi/getAsyncRequestId.js +36 -0
  85. package/brightData/serpApi/getAsyncResults.d.ts +7 -0
  86. package/brightData/serpApi/getAsyncResults.js +35 -0
  87. package/brightData/serpApi/getRealtime.d.ts +5 -0
  88. package/brightData/serpApi/getRealtime.js +30 -0
  89. package/brightData/serpApi/index.d.ts +14 -0
  90. package/brightData/serpApi/index.js +23 -0
  91. package/brightData/webScraperIde/getBatch.d.ts +7 -0
  92. package/brightData/webScraperIde/getBatch.js +28 -0
  93. package/brightData/webScraperIde/getRealtime.d.ts +7 -0
  94. package/brightData/webScraperIde/getRealtime.js +49 -0
  95. package/brightData/webScraperIde/index.d.ts +2 -0
  96. package/brightData/webScraperIde/index.js +7 -0
  97. package/cache/index.d.ts +2 -0
  98. package/cache/index.js +48 -0
  99. package/cache/test/cache.test.d.ts +1 -0
  100. package/cache/test/cache.test.js +10 -0
  101. package/crud/index.d.ts +6 -0
  102. package/crud/index.js +10 -0
  103. package/crypto/getDecrypt.d.ts +5 -0
  104. package/crypto/getDecrypt.js +47 -0
  105. package/crypto/getEncrypt.d.ts +5 -0
  106. package/crypto/getEncrypt.js +47 -0
  107. package/crypto/getRandom.d.ts +4 -0
  108. package/crypto/getRandom.js +12 -0
  109. package/crypto/getSha256.d.ts +5 -0
  110. package/crypto/getSha256.js +48 -0
  111. package/crypto/index.d.ts +4 -0
  112. package/crypto/index.js +11 -0
  113. package/date/calculation.d.ts +75 -0
  114. package/date/calculation.js +207 -0
  115. package/date/financialYear.d.ts +19 -0
  116. package/date/financialYear.js +85 -0
  117. package/date/format.d.ts +68 -0
  118. package/date/format.js +150 -0
  119. package/date/index.d.ts +35 -0
  120. package/date/index.js +57 -0
  121. package/environment/index.d.ts +32 -0
  122. package/environment/index.js +92 -0
  123. package/eskimi/getAgeGroup.d.ts +4 -0
  124. package/eskimi/getAgeGroup.js +15 -0
  125. package/eskimi/getData.d.ts +4 -0
  126. package/eskimi/getData.js +17 -0
  127. package/eskimi/getDevice.d.ts +4 -0
  128. package/eskimi/getDevice.js +15 -0
  129. package/eskimi/getGender.d.ts +4 -0
  130. package/eskimi/getGender.js +15 -0
  131. package/eskimi/index.d.ts +49 -0
  132. package/eskimi/index.js +96 -0
  133. package/file/createDirectory.d.ts +5 -0
  134. package/file/createDirectory.js +50 -0
  135. package/file/index.d.ts +1 -0
  136. package/file/index.js +5 -0
  137. package/geo/countries.d.ts +12 -0
  138. package/geo/countries.js +222 -0
  139. package/geo/index.d.ts +2 -0
  140. package/geo/index.js +7 -0
  141. package/geo/languages.d.ts +9 -0
  142. package/geo/languages.js +58 -0
  143. package/google/bigQuery/GoogleBigQueryNamespace.d.ts +51 -0
  144. package/google/bigQuery/GoogleBigQueryNamespace.js +165 -0
  145. package/google/bigQuery/index.d.ts +5 -0
  146. package/google/bigQuery/index.js +37 -0
  147. package/google/bigQuery/loadData.d.ts +19 -0
  148. package/google/bigQuery/loadData.js +18 -0
  149. package/google/index.d.ts +27 -0
  150. package/google/index.js +24 -0
  151. package/google/sheets/GoogleSheetsNamespace.d.ts +16 -0
  152. package/google/sheets/GoogleSheetsNamespace.js +81 -0
  153. package/google/sheets/getAssociatedData.d.ts +10 -0
  154. package/google/sheets/getAssociatedData.js +43 -0
  155. package/google/sheets/index.d.ts +8 -0
  156. package/google/sheets/index.js +37 -0
  157. package/google/storage/GoogleCloudStorageNamespace.d.ts +20 -0
  158. package/google/storage/GoogleCloudStorageNamespace.js +108 -0
  159. package/google/storage/index.d.ts +3 -0
  160. package/google/storage/index.js +30 -0
  161. package/googleAds/GoogleAdsNamespace.d.ts +11 -0
  162. package/googleAds/GoogleAdsNamespace.js +73 -0
  163. package/googleAds/index.d.ts +11 -0
  164. package/googleAds/index.js +30 -0
  165. package/googleAds/keywordPlanner/index.d.ts +40 -0
  166. package/googleAds/keywordPlanner/index.js +59 -0
  167. package/googlePageSpeed/GooglePageSpeedNamespace.d.ts +11 -0
  168. package/googlePageSpeed/GooglePageSpeedNamespace.js +35 -0
  169. package/googlePageSpeed/index.d.ts +17 -0
  170. package/googlePageSpeed/index.js +44 -0
  171. package/googleSearchIncidents/index.d.ts +69 -0
  172. package/googleSearchIncidents/index.js +46 -0
  173. package/greenDomain/index.d.ts +21 -0
  174. package/greenDomain/index.js +41 -0
  175. package/inngest/index.d.ts +6 -0
  176. package/inngest/index.js +10 -0
  177. package/json/getJsonNewline.d.ts +1 -0
  178. package/json/getJsonNewline.js +13 -0
  179. package/json/index.d.ts +2 -0
  180. package/json/index.js +7 -0
  181. package/json/isJson.d.ts +1 -0
  182. package/json/isJson.js +26 -0
  183. package/littleWarden/LittleWardenNamespace.d.ts +11 -0
  184. package/littleWarden/LittleWardenNamespace.js +38 -0
  185. package/littleWarden/getUrlStatus.d.ts +4 -0
  186. package/littleWarden/getUrlStatus.js +16 -0
  187. package/littleWarden/index.d.ts +29 -0
  188. package/littleWarden/index.js +74 -0
  189. package/lumar/api/buildRequest.d.ts +13 -0
  190. package/lumar/api/buildRequest.js +80 -0
  191. package/lumar/api/getData.d.ts +5 -0
  192. package/lumar/api/getData.js +13 -0
  193. package/lumar/api/index.d.ts +36 -0
  194. package/lumar/api/index.js +33 -0
  195. package/lumar/api/initClient.d.ts +6 -0
  196. package/lumar/api/initClient.js +26 -0
  197. package/lumar/graphql/columns.d.ts +28 -0
  198. package/lumar/graphql/columns.js +31 -0
  199. package/lumar/graphql/getData.d.ts +1 -0
  200. package/lumar/graphql/getData.js +20 -0
  201. package/lumar/graphql/index.d.ts +29 -0
  202. package/lumar/graphql/index.js +39 -0
  203. package/lumar/graphql/initClient.d.ts +5 -0
  204. package/lumar/graphql/initClient.js +25 -0
  205. package/lumar/graphql/queries/crawl.d.ts +5 -0
  206. package/lumar/graphql/queries/crawl.js +2 -0
  207. package/lumar/graphql/queries/getCrawls.d.ts +18 -0
  208. package/lumar/graphql/queries/getCrawls.js +33 -0
  209. package/lumar/graphql/queries/getReportDifferences.d.ts +24 -0
  210. package/lumar/graphql/queries/getReportDifferences.js +37 -0
  211. package/lumar/graphql/queries/getRows.d.ts +38 -0
  212. package/lumar/graphql/queries/getRows.js +57 -0
  213. package/lumar/graphql/queries/getTotals.d.ts +25 -0
  214. package/lumar/graphql/queries/getTotals.js +40 -0
  215. package/lumar/graphql/queries/row.d.ts +157 -0
  216. package/lumar/graphql/queries/row.js +2 -0
  217. package/lumar/graphql/reportTemplates.d.ts +67 -0
  218. package/lumar/graphql/reportTemplates.js +70 -0
  219. package/myTarget/request.d.ts +5 -0
  220. package/myTarget/request.js +17 -0
  221. package/nextAuth/index.d.ts +6 -0
  222. package/nextAuth/index.js +11 -0
  223. package/nextAuth/isSessionReady.d.ts +1 -0
  224. package/nextAuth/isSessionReady.js +13 -0
  225. package/nextJs/getIp.d.ts +6 -0
  226. package/nextJs/getIp.js +14 -0
  227. package/nextJs/getUserAgent.d.ts +6 -0
  228. package/nextJs/getUserAgent.js +8 -0
  229. package/nextJs/index.d.ts +2 -0
  230. package/nextJs/index.js +7 -0
  231. package/number/format.d.ts +12 -0
  232. package/number/format.js +20 -0
  233. package/number/formatCurrency.d.ts +5 -0
  234. package/number/formatCurrency.js +21 -0
  235. package/number/getDecimal.d.ts +4 -0
  236. package/number/getDecimal.js +12 -0
  237. package/number/getNumber.d.ts +4 -0
  238. package/number/getNumber.js +48 -0
  239. package/number/getPercentIncrease.d.ts +4 -0
  240. package/number/getPercentIncrease.js +16 -0
  241. package/number/getSafeDivide.d.ts +11 -0
  242. package/number/getSafeDivide.js +20 -0
  243. package/number/index.d.ts +6 -0
  244. package/number/index.js +15 -0
  245. package/object/index.d.ts +1 -0
  246. package/object/index.js +5 -0
  247. package/object/replaceKeys.d.ts +5 -0
  248. package/object/replaceKeys.js +25 -0
  249. package/onePassword/OnePasswordNamespace.d.ts +13 -0
  250. package/onePassword/OnePasswordNamespace.js +81 -0
  251. package/onePassword/index.d.ts +7 -0
  252. package/onePassword/index.js +25 -0
  253. package/openAi/OpenAiNamespace.d.ts +11 -0
  254. package/openAi/OpenAiNamespace.js +44 -0
  255. package/openAi/index.d.ts +5 -0
  256. package/openAi/index.js +30 -0
  257. package/package.json +2 -2
  258. package/prisma/PrismaNamespace.d.ts +8 -0
  259. package/prisma/PrismaNamespace.js +79 -0
  260. package/prisma/getDecimal.d.ts +4 -0
  261. package/prisma/getDecimal.js +23 -0
  262. package/prisma/index.d.ts +8 -0
  263. package/prisma/index.js +29 -0
  264. package/snapchat/SnapchatNamespace.d.ts +15 -0
  265. package/snapchat/SnapchatNamespace.js +30 -0
  266. package/snapchat/index.d.ts +7 -0
  267. package/snapchat/index.js +30 -0
  268. package/sorting/byNumberAscending.d.ts +4 -0
  269. package/sorting/byNumberAscending.js +19 -0
  270. package/sorting/byNumberDescending.d.ts +4 -0
  271. package/sorting/byNumberDescending.js +22 -0
  272. package/sorting/byStringAscending.d.ts +4 -0
  273. package/sorting/byStringAscending.js +16 -0
  274. package/sorting/byStringDescending.d.ts +4 -0
  275. package/sorting/byStringDescending.js +16 -0
  276. package/sorting/index.d.ts +4 -0
  277. package/sorting/index.js +11 -0
  278. package/stream/index.d.ts +1 -0
  279. package/stream/index.js +5 -0
  280. package/stream/sort.d.ts +13 -0
  281. package/stream/sort.js +51 -0
  282. package/string/getCapitalised.d.ts +5 -0
  283. package/string/getCapitalised.js +18 -0
  284. package/string/getClean.d.ts +18 -0
  285. package/string/getClean.js +51 -0
  286. package/string/getFolder.d.ts +4 -0
  287. package/string/getFolder.js +15 -0
  288. package/string/getProperCase.d.ts +11 -0
  289. package/string/getProperCase.js +25 -0
  290. package/string/getString.d.ts +4 -0
  291. package/string/getString.js +34 -0
  292. package/string/getStringFromStream.d.ts +5 -0
  293. package/string/getStringFromStream.js +17 -0
  294. package/string/getUnescaped.d.ts +6 -0
  295. package/string/getUnescaped.js +26 -0
  296. package/string/getWithoutAccents.d.ts +5 -0
  297. package/string/getWithoutAccents.js +13 -0
  298. package/string/getWithoutHtmlTags.d.ts +5 -0
  299. package/string/getWithoutHtmlTags.js +12 -0
  300. package/string/getWithoutPunctuation.d.ts +5 -0
  301. package/string/getWithoutPunctuation.js +13 -0
  302. package/string/getWithoutUnderscores.d.ts +4 -0
  303. package/string/getWithoutUnderscores.js +11 -0
  304. package/string/getWithoutWhitespaces.d.ts +5 -0
  305. package/string/getWithoutWhitespaces.js +13 -0
  306. package/string/index.d.ts +12 -0
  307. package/string/index.js +27 -0
  308. package/swr/index.d.ts +42 -0
  309. package/swr/index.js +59 -0
  310. package/upTimeRobot/UpTimeRobotNamespace.d.ts +31 -0
  311. package/upTimeRobot/UpTimeRobotNamespace.js +52 -0
  312. package/upTimeRobot/index.d.ts +38 -0
  313. package/upTimeRobot/index.js +63 -0
  314. package/url/index.d.ts +19 -0
  315. package/url/index.js +70 -0
  316. package/url/writeUrlContents.d.ts +6 -0
  317. package/url/writeUrlContents.js +75 -0
  318. package/util/defaultTo.d.ts +4 -0
  319. package/util/defaultTo.js +44 -0
  320. package/util/getBrotliCompressed.d.ts +5 -0
  321. package/util/getBrotliCompressed.js +23 -0
  322. package/util/getBrotliDecompressed.d.ts +5 -0
  323. package/util/getBrotliDecompressed.js +24 -0
  324. package/util/getClean.d.ts +11 -0
  325. package/util/getClean.js +23 -0
  326. package/util/getGzipCompressed.d.ts +5 -0
  327. package/util/getGzipCompressed.js +23 -0
  328. package/util/getGzipDecompressed.d.ts +5 -0
  329. package/util/getGzipDecompressed.js +24 -0
  330. package/util/getWithoutHash.d.ts +4 -0
  331. package/util/getWithoutHash.js +18 -0
  332. package/util/getWithoutParameter.d.ts +4 -0
  333. package/util/getWithoutParameter.js +18 -0
  334. package/util/index.d.ts +11 -0
  335. package/util/index.js +25 -0
  336. package/util/isUndefined.d.ts +4 -0
  337. package/util/isUndefined.js +13 -0
  338. package/util/promiseChunks.d.ts +5 -0
  339. package/util/promiseChunks.js +19 -0
  340. package/util/sleep.d.ts +1 -0
  341. package/util/sleep.js +7 -0
  342. package/webWorker/index.d.ts +5 -0
  343. package/webWorker/index.js +9 -0
  344. package/xml/getXml.d.ts +1 -0
  345. package/xml/getXml.js +18 -0
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.deleteRequest = void 0;
7
+ const axios_1 = __importDefault(require("axios"));
8
+ const api_1 = require("../api");
9
+ /**
10
+ * Make a DELETE request.
11
+ * Can't use the function name delete as it's reserved
12
+ */
13
+ const deleteRequest = async (url, config = {}) => {
14
+ const response = await axios_1.default.delete(url, config)
15
+ .then(async (response) => {
16
+ // Is API response
17
+ if (undefined !== response.data.body && undefined !== response.data.error && undefined !== response.data.state) {
18
+ return new api_1.ApiResponseClass(response.data);
19
+ }
20
+ // General success - some APIs report 201
21
+ else if (response.status >= 200 && response.status <= 299) {
22
+ return (new api_1.ApiResponseClass()).setToSuccess(response.data);
23
+ }
24
+ // Error
25
+ return (new api_1.ApiResponseClass()).setToError(response.data, response.statusText);
26
+ })
27
+ .catch(error => {
28
+ // Error
29
+ return (new api_1.ApiResponseClass()).setToError(null, error.message);
30
+ });
31
+ return response;
32
+ };
33
+ exports.deleteRequest = deleteRequest;
package/axios/get.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ import { ApiResponseClass } from "../api";
2
+ /**
3
+ * Make a GET request.
4
+ */
5
+ export declare const get: (url: string, config?: {}) => Promise<ApiResponseClass>;
package/axios/get.js ADDED
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.get = void 0;
7
+ const axios_1 = __importDefault(require("axios"));
8
+ const api_1 = require("../api");
9
+ /**
10
+ * Make a GET request.
11
+ */
12
+ const get = async (url, config = {}) => {
13
+ const response = await axios_1.default.get(url, config)
14
+ .then(async (response) => {
15
+ // Is API response
16
+ if (undefined !== response.data.body && undefined !== response.data.error && undefined !== response.data.state) {
17
+ return new api_1.ApiResponseClass(response.data);
18
+ }
19
+ // General success - some APIs report 201
20
+ else if (response.status >= 200 && response.status <= 299) {
21
+ return (new api_1.ApiResponseClass()).setToSuccess(response.data);
22
+ }
23
+ // Error
24
+ return (new api_1.ApiResponseClass()).setToError(response.data, response.statusText);
25
+ })
26
+ .catch(error => {
27
+ return (new api_1.ApiResponseClass()).setToError(null, error.message);
28
+ });
29
+ return response;
30
+ };
31
+ exports.get = get;
@@ -0,0 +1,3 @@
1
+ export { get } from "./get";
2
+ export { post } from "./post";
3
+ export { deleteRequest } from "./deleteRequest";
package/axios/index.js ADDED
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.deleteRequest = exports.post = exports.get = void 0;
4
+ var get_1 = require("./get");
5
+ Object.defineProperty(exports, "get", { enumerable: true, get: function () { return get_1.get; } });
6
+ var post_1 = require("./post");
7
+ Object.defineProperty(exports, "post", { enumerable: true, get: function () { return post_1.post; } });
8
+ var deleteRequest_1 = require("./deleteRequest");
9
+ Object.defineProperty(exports, "deleteRequest", { enumerable: true, get: function () { return deleteRequest_1.deleteRequest; } });
@@ -0,0 +1,5 @@
1
+ import { ApiResponseClass } from "../api";
2
+ /**
3
+ * Make a POST request.
4
+ */
5
+ export declare const post: (url: string, data?: {}, config?: {}) => Promise<ApiResponseClass>;
package/axios/post.js ADDED
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.post = void 0;
7
+ const axios_1 = __importDefault(require("axios"));
8
+ const api_1 = require("../api");
9
+ /**
10
+ * Make a POST request.
11
+ */
12
+ const post = async (url, data = {}, config = {}) => {
13
+ const response = await axios_1.default.post(url, data, config)
14
+ .then(async (response) => {
15
+ // Is API response
16
+ if (undefined !== response.data.body && undefined !== response.data.error && undefined !== response.data.state) {
17
+ return new api_1.ApiResponseClass(response.data);
18
+ }
19
+ // General success - some APIs report 201
20
+ else if (response.status >= 200 && response.status <= 299) {
21
+ return (new api_1.ApiResponseClass()).setToSuccess(response.data);
22
+ }
23
+ // Error
24
+ return (new api_1.ApiResponseClass()).setToError(response.data, response.statusText);
25
+ })
26
+ .catch(error => {
27
+ // Error
28
+ return (new api_1.ApiResponseClass()).setToError(null, error.message);
29
+ });
30
+ return response;
31
+ };
32
+ exports.post = post;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Convert an input from a variety of forms into boolean.
3
+ */
4
+ export declare const getBoolean: (input: any, defaultValue?: boolean) => boolean;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getBoolean = void 0;
7
+ const isBoolean_1 = __importDefault(require("lodash/isBoolean"));
8
+ /**
9
+ * Convert an input from a variety of forms into boolean.
10
+ */
11
+ const getBoolean = (input, defaultValue = false) => {
12
+ if ((0, isBoolean_1.default)(input)) {
13
+ return input;
14
+ }
15
+ else if ("string" === typeof input) {
16
+ return "true" === input || "1" === input || "yes" === input || "y" === input;
17
+ }
18
+ else if ("number" === typeof input) {
19
+ return 1 === input;
20
+ }
21
+ return defaultValue;
22
+ };
23
+ exports.getBoolean = getBoolean;
@@ -0,0 +1 @@
1
+ export { getBoolean } from "./getBoolean";
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getBoolean = void 0;
4
+ var getBoolean_1 = require("./getBoolean");
5
+ Object.defineProperty(exports, "getBoolean", { enumerable: true, get: function () { return getBoolean_1.getBoolean; } });
@@ -0,0 +1,15 @@
1
+ export type Auth = {
2
+ apiKey: string;
3
+ host: string;
4
+ port: string;
5
+ username: string;
6
+ password: string;
7
+ };
8
+ /**
9
+ * Return the Zone based on the username.
10
+ */
11
+ export declare const getZone: (auth: Auth) => string;
12
+ /**
13
+ * Return the customer Id based on the username.
14
+ */
15
+ export declare const getCustomerId: (auth: Auth, prefix?: string) => string;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getCustomerId = exports.getZone = void 0;
4
+ /**
5
+ * Return the Zone based on the username.
6
+ */
7
+ const getZone = (auth) => {
8
+ const segments = auth.username.split("-");
9
+ return segments[segments.length - 1];
10
+ };
11
+ exports.getZone = getZone;
12
+ /**
13
+ * Return the customer Id based on the username.
14
+ */
15
+ const getCustomerId = (auth, prefix) => {
16
+ const segments = auth.username.split("-")[2];
17
+ const customerId = segments[2].replace("hl_", "");
18
+ return (prefix || "") + customerId;
19
+ };
20
+ exports.getCustomerId = getCustomerId;
@@ -0,0 +1,32 @@
1
+ type BuildGoogleSerpUrl = {
2
+ country?: string;
3
+ device?: "mobile" | "android" | "androidTablet" | "iphone" | "ipad";
4
+ language?: string;
5
+ geoLocation?: string;
6
+ hotel?: {
7
+ dates?: string;
8
+ occupancy?: number;
9
+ };
10
+ pagination?: {
11
+ offset?: number;
12
+ perPage?: number;
13
+ };
14
+ searchType?: "images" | "jobs" | "news" | "shopping" | "video";
15
+ query: string;
16
+ googleDomain: string;
17
+ output?: "html" | "json";
18
+ returnType: "url" | "json";
19
+ };
20
+ /**
21
+ * Construct the Google SERP url using Bright Data's API:
22
+ * https://brightdata.com/cp/serp_api/api/google/search?id=c_2cef083f
23
+ *
24
+ * For geolocation use value from:
25
+ * https://developers.google.com/google-ads/api/data/geotargets
26
+ */
27
+ export declare const buildGoogleSerpUrl: (props: BuildGoogleSerpUrl) => string | {
28
+ query: {
29
+ q: string;
30
+ };
31
+ };
32
+ export {};
@@ -0,0 +1,116 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildGoogleSerpUrl = void 0;
4
+ /**
5
+ * Construct the Google SERP url using Bright Data's API:
6
+ * https://brightdata.com/cp/serp_api/api/google/search?id=c_2cef083f
7
+ *
8
+ * For geolocation use value from:
9
+ * https://developers.google.com/google-ads/api/data/geotargets
10
+ */
11
+ const buildGoogleSerpUrl = (props) => {
12
+ let url = new URL(`https://www.${props.googleDomain}/search`);
13
+ let params = {
14
+ query: {
15
+ q: props.query,
16
+ }
17
+ };
18
+ url.searchParams.append("q", props.query);
19
+ // Two-letter country code used to define the country of search
20
+ if (props?.country) {
21
+ params.query["gl"] = props.country;
22
+ url.searchParams.append("gl", props.country);
23
+ }
24
+ // Define what device type to be represented in user-agent - Default desktop
25
+ switch (props?.device) {
26
+ case "mobile":
27
+ params.query["brd_mobile"] = "1";
28
+ url.searchParams.append("brd_mobile", "1");
29
+ break;
30
+ case "android":
31
+ params.query["brd_mobile"] = "android";
32
+ url.searchParams.append("brd_mobile", "android");
33
+ break;
34
+ case "androidTablet":
35
+ params.query["brd_mobile"] = "android_tablet";
36
+ url.searchParams.append("brd_mobile", "android_tablet");
37
+ break;
38
+ case "ipad":
39
+ params.query["brd_mobile"] = "ipad";
40
+ url.searchParams.append("brd_mobile", "ipad");
41
+ break;
42
+ case "iphone":
43
+ params.query["brd_mobile"] = "ios";
44
+ url.searchParams.append("brd_mobile", "ios");
45
+ break;
46
+ }
47
+ // Stands for the encoded location you want to use for your search
48
+ if (props?.geoLocation) {
49
+ params.query["uule"] = props.geoLocation;
50
+ url.searchParams.append("uule", props.geoLocation);
51
+ }
52
+ if (props?.hotel) {
53
+ if (props.hotel?.dates) {
54
+ params.query["hotel_dates"] = props.hotel.dates.toString();
55
+ url.searchParams.append("hotel_dates", props.hotel.dates);
56
+ }
57
+ if (props.hotel?.occupancy) {
58
+ params.query["hotel_occupancy"] = props.hotel.occupancy.toString();
59
+ url.searchParams.append("hotel_occupancy", props.hotel.occupancy.toString());
60
+ }
61
+ }
62
+ // Two-letter language code used to define the page language
63
+ if (props?.language) {
64
+ params.query["uule"] = props.language;
65
+ url.searchParams.append("hl", props.language);
66
+ }
67
+ // Define search type. For regular search
68
+ switch (props?.searchType) {
69
+ case "images":
70
+ params.query["tbm"] = "isch";
71
+ url.searchParams.append("tbm", "isch");
72
+ break;
73
+ case "jobs":
74
+ params.query["ibp"] = "htl;jobs";
75
+ url.searchParams.append("ibp", "htl;jobs");
76
+ break;
77
+ case "news":
78
+ params.query["tbm"] = "nws";
79
+ url.searchParams.append("tbm", "nws");
80
+ break;
81
+ case "shopping":
82
+ params.query["tbm"] = "shop";
83
+ url.searchParams.append("tbm", "shop");
84
+ break;
85
+ case "video":
86
+ params.query["tbm"] = "vid";
87
+ url.searchParams.append("tbm", "vid");
88
+ break;
89
+ }
90
+ if (props?.pagination) {
91
+ // Define the result offset
92
+ if (props.pagination?.offset) {
93
+ params.query["start"] = props.pagination.offset.toString();
94
+ url.searchParams.append("start", props.pagination.offset.toString());
95
+ }
96
+ // Defines the number of results to return
97
+ if (props.pagination?.perPage) {
98
+ params.query["num"] = props.pagination.offset.toString();
99
+ url.searchParams.append("num", props.pagination.perPage.toString());
100
+ }
101
+ }
102
+ // Specify the output type
103
+ if ("json" === props.output) {
104
+ params["brd_json"] = "1";
105
+ url.searchParams.append("brn_json", "1");
106
+ }
107
+ else {
108
+ params["brd_json"] = "html";
109
+ url.searchParams.append("brn_json", "html");
110
+ }
111
+ if ("json" === props.returnType) {
112
+ return params;
113
+ }
114
+ return url.toString();
115
+ };
116
+ exports.buildGoogleSerpUrl = buildGoogleSerpUrl;
@@ -0,0 +1,22 @@
1
+ type BuildGoogleTrendsUrl = {
2
+ country?: string;
3
+ language?: string;
4
+ category?: string;
5
+ date?: string;
6
+ searchType?: "images" | "news" | "shopping" | "youtube";
7
+ query: string;
8
+ returnType: "url" | "json";
9
+ };
10
+ /**
11
+ * Construct the Google Trends url using Bright Data's API:
12
+ * https://brightdata.com/cp/serp_api/api/google/trends?id=c_2cef083f
13
+ *
14
+ * For category use value from:
15
+ * https://trends.google.com/trends/api/explore/pickers/category?lang=en-US&tz=240
16
+ */
17
+ export declare const buildGoogleTrendsUrl: (props: BuildGoogleTrendsUrl) => string | {
18
+ query: {
19
+ q: string;
20
+ };
21
+ };
22
+ export {};
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildGoogleTrendsUrl = void 0;
4
+ /**
5
+ * Construct the Google Trends url using Bright Data's API:
6
+ * https://brightdata.com/cp/serp_api/api/google/trends?id=c_2cef083f
7
+ *
8
+ * For category use value from:
9
+ * https://trends.google.com/trends/api/explore/pickers/category?lang=en-US&tz=240
10
+ */
11
+ const buildGoogleTrendsUrl = (props) => {
12
+ let url = new URL(`http://trends.google.com/trends/explore`);
13
+ url.searchParams.append("q", props.query);
14
+ let params = {
15
+ query: {
16
+ q: props.query,
17
+ }
18
+ };
19
+ // Location of interest, two-letter country code
20
+ if (props?.country) {
21
+ params.query['geo'] = props.country;
22
+ url.searchParams.append("geo", props.country);
23
+ }
24
+ // Preferred language, two-letter language code
25
+ if (props?.language) {
26
+ params.query['hl'] = props.language;
27
+ url.searchParams.append("hl", props.language);
28
+ }
29
+ if (props?.category) {
30
+ params.query['cat'] = props.category;
31
+ url.searchParams.append("cat", props.category);
32
+ }
33
+ if (props?.date) {
34
+ params.query['date'] = props.date;
35
+ url.searchParams.append("date", props.date);
36
+ }
37
+ // Define search type. For regular search
38
+ switch (props?.searchType) {
39
+ case "images":
40
+ params.query['group'] = "images";
41
+ url.searchParams.append("gprop", "images");
42
+ break;
43
+ case "news":
44
+ params.query['group'] = "news";
45
+ url.searchParams.append("gprop", "news");
46
+ break;
47
+ case "shopping":
48
+ params.query['group'] = "froogle";
49
+ url.searchParams.append("gprop", "froogle");
50
+ break;
51
+ case "youtube":
52
+ params.query['group'] = "youtube";
53
+ url.searchParams.append("gprop", "youtube");
54
+ break;
55
+ }
56
+ if ("json" === props.returnType) {
57
+ return params;
58
+ }
59
+ return url.toString();
60
+ };
61
+ exports.buildGoogleTrendsUrl = buildGoogleTrendsUrl;
@@ -0,0 +1,8 @@
1
+ import { Auth } from "../";
2
+ import { BrightDataSerpApiType } from "./";
3
+ /**
4
+ * Make an async request to the SERP API using the Bright Data proxy.
5
+ * Returns a request ID used with getAsyncResults
6
+ * https://docs.brightdata.com/scraping-automation/serp-api/asynchronous-requests
7
+ */
8
+ export declare const getAsyncRequestId: (auth: Auth, data: {}, type: BrightDataSerpApiType) => Promise<string>;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getAsyncRequestId = void 0;
4
+ const axios_1 = require("../../axios");
5
+ const __1 = require("../");
6
+ const _1 = require("./");
7
+ /**
8
+ * Make an async request to the SERP API using the Bright Data proxy.
9
+ * Returns a request ID used with getAsyncResults
10
+ * https://docs.brightdata.com/scraping-automation/serp-api/asynchronous-requests
11
+ */
12
+ const getAsyncRequestId = async (auth, data = {}, type) => {
13
+ let url = "";
14
+ let response = "";
15
+ // Prevent auth requests getting blocked
16
+ process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = "0";
17
+ const customerId = (0, __1.getCustomerId)(auth);
18
+ const zone = (0, __1.getZone)(auth);
19
+ switch (type) {
20
+ case _1.BrightDataSerpApiType.GOOGLE_TRENDS:
21
+ url = `https://api.brightdata.com/serp/trends?customer=${customerId}&zone=${zone}`;
22
+ break;
23
+ default:
24
+ url = `https://api.brightdata.com/serp/req?customer=${customerId}&zone=${zone}`;
25
+ }
26
+ const requestResponse = await (0, axios_1.post)(url, data, {
27
+ headers: {
28
+ Authorization: `Bearer ${auth.apiKey}`
29
+ },
30
+ });
31
+ if (requestResponse.isSuccess()) {
32
+ response = requestResponse.getBodyDefaultTo(["response_id"], "");
33
+ }
34
+ return response;
35
+ };
36
+ exports.getAsyncRequestId = getAsyncRequestId;
@@ -0,0 +1,7 @@
1
+ import { Auth } from "../";
2
+ import { ApiResponseClass } from "../../api";
3
+ /**
4
+ * Using the request ID from getAsyncRequestId fetch to see if the data is available.
5
+ * https://docs.brightdata.com/scraping-automation/serp-api/asynchronous-requests
6
+ */
7
+ export declare const getAsyncResults: (auth: Auth, requestId: string) => Promise<ApiResponseClass<any, any>>;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getAsyncResults = void 0;
4
+ const axios_1 = require("../../axios");
5
+ const __1 = require("../");
6
+ const api_1 = require("../../api");
7
+ /**
8
+ * Using the request ID from getAsyncRequestId fetch to see if the data is available.
9
+ * https://docs.brightdata.com/scraping-automation/serp-api/asynchronous-requests
10
+ */
11
+ const getAsyncResults = async (auth, requestId) => {
12
+ let response = (new api_1.ApiResponseClass());
13
+ // Prevent auth requests getting blocked
14
+ process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = "0";
15
+ const customerId = (0, __1.getCustomerId)(auth);
16
+ const zone = (0, __1.getZone)(auth);
17
+ const requestResponse = await (0, axios_1.get)(`https://api.brightdata.com/serp/get_result?customer=${customerId}&zone=${zone}&response_id=${requestId}`, {
18
+ headers: {
19
+ Authorization: `Bearer ${auth.apiKey}`
20
+ },
21
+ });
22
+ if (requestResponse.isSuccess()) {
23
+ if ("Request is pending" === requestResponse.getBody()) {
24
+ response.setToPending();
25
+ }
26
+ else {
27
+ response.setToSuccess(requestResponse.getBody());
28
+ }
29
+ }
30
+ else {
31
+ response.setToError(null, "Error in request");
32
+ }
33
+ return response;
34
+ };
35
+ exports.getAsyncResults = getAsyncResults;
@@ -0,0 +1,5 @@
1
+ import { Auth } from "../";
2
+ /**
3
+ * Make a request to the SERP API using the Bright Data proxy
4
+ */
5
+ export declare const getRealtime: (auth: Auth, url: string) => Promise<{}>;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getRealtime = void 0;
4
+ const axios_1 = require("../../axios");
5
+ /**
6
+ * Make a request to the SERP API using the Bright Data proxy
7
+ */
8
+ const getRealtime = async (auth, url) => {
9
+ let response = {};
10
+ // Prevent auth requests getting blocked
11
+ process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = "0";
12
+ // Use fetch with the agent option to make an HTTP request through the proxy
13
+ // Replace <target_url> with the URL you want to request
14
+ const apiResponse = await (0, axios_1.get)(url, {
15
+ proxy: {
16
+ protocol: "http",
17
+ host: auth.host,
18
+ port: auth.port,
19
+ auth: {
20
+ username: auth.username,
21
+ password: auth.password,
22
+ }
23
+ },
24
+ });
25
+ if (apiResponse.isSuccess()) {
26
+ response = apiResponse.getBody();
27
+ }
28
+ return response;
29
+ };
30
+ exports.getRealtime = getRealtime;
@@ -0,0 +1,14 @@
1
+ export declare enum BrightDataSerpApiType {
2
+ GOOGLE_FLIGHTS = "GOOGLE_FLIGHTS",
3
+ GOOGLE_HOTELS = "GOOGLE_HOTELS",
4
+ GOOGLE_LENS = "GOOGLE_LENS",
5
+ GOOGLE_MAPS = "GOOGLE_MAPS",
6
+ GOOGLE_REVIEWS = "GOOGLE_REVIEWS",
7
+ GOOGLE_SEARCH = "GOOGLE_SEARCH",
8
+ GOOGLE_TRENDS = "GOOGLE_TRENDS"
9
+ }
10
+ export { buildGoogleSerpUrl } from "./buildGoogleSerpUrl";
11
+ export { buildGoogleTrendsUrl } from "./buildGoogleTrendsUrl";
12
+ export { getAsyncRequestId } from "./getAsyncRequestId";
13
+ export { getAsyncResults } from "./getAsyncResults";
14
+ export { getRealtime } from "./getRealtime";
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getRealtime = exports.getAsyncResults = exports.getAsyncRequestId = exports.buildGoogleTrendsUrl = exports.buildGoogleSerpUrl = exports.BrightDataSerpApiType = void 0;
4
+ var BrightDataSerpApiType;
5
+ (function (BrightDataSerpApiType) {
6
+ BrightDataSerpApiType["GOOGLE_FLIGHTS"] = "GOOGLE_FLIGHTS";
7
+ BrightDataSerpApiType["GOOGLE_HOTELS"] = "GOOGLE_HOTELS";
8
+ BrightDataSerpApiType["GOOGLE_LENS"] = "GOOGLE_LENS";
9
+ BrightDataSerpApiType["GOOGLE_MAPS"] = "GOOGLE_MAPS";
10
+ BrightDataSerpApiType["GOOGLE_REVIEWS"] = "GOOGLE_REVIEWS";
11
+ BrightDataSerpApiType["GOOGLE_SEARCH"] = "GOOGLE_SEARCH";
12
+ BrightDataSerpApiType["GOOGLE_TRENDS"] = "GOOGLE_TRENDS";
13
+ })(BrightDataSerpApiType || (exports.BrightDataSerpApiType = BrightDataSerpApiType = {}));
14
+ var buildGoogleSerpUrl_1 = require("./buildGoogleSerpUrl");
15
+ Object.defineProperty(exports, "buildGoogleSerpUrl", { enumerable: true, get: function () { return buildGoogleSerpUrl_1.buildGoogleSerpUrl; } });
16
+ var buildGoogleTrendsUrl_1 = require("./buildGoogleTrendsUrl");
17
+ Object.defineProperty(exports, "buildGoogleTrendsUrl", { enumerable: true, get: function () { return buildGoogleTrendsUrl_1.buildGoogleTrendsUrl; } });
18
+ var getAsyncRequestId_1 = require("./getAsyncRequestId");
19
+ Object.defineProperty(exports, "getAsyncRequestId", { enumerable: true, get: function () { return getAsyncRequestId_1.getAsyncRequestId; } });
20
+ var getAsyncResults_1 = require("./getAsyncResults");
21
+ Object.defineProperty(exports, "getAsyncResults", { enumerable: true, get: function () { return getAsyncResults_1.getAsyncResults; } });
22
+ var getRealtime_1 = require("./getRealtime");
23
+ Object.defineProperty(exports, "getRealtime", { enumerable: true, get: function () { return getRealtime_1.getRealtime; } });
@@ -0,0 +1,7 @@
1
+ import { Auth } from "../";
2
+ /**
3
+ * Depends on the Scraper setup!
4
+ *
5
+ * Make the request to trigger the scraper and let it do its job.
6
+ */
7
+ export declare const getBatch: (auth: Auth, scraperId: string, data?: {}, isDev?: boolean) => Promise<boolean>;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getBatch = void 0;
4
+ const axios_1 = require("../../axios");
5
+ /**
6
+ * Depends on the Scraper setup!
7
+ *
8
+ * Make the request to trigger the scraper and let it do its job.
9
+ */
10
+ const getBatch = async (auth, scraperId, data = {}, isDev = false) => {
11
+ let response = false;
12
+ const requestUrl = new URL("https://api.brightdata.com/dca/trigger");
13
+ requestUrl.searchParams.append("collector", scraperId);
14
+ requestUrl.searchParams.append("queue_next", "1");
15
+ if (isDev) {
16
+ requestUrl.searchParams.append("version", "dev");
17
+ }
18
+ const requestResponse = await (0, axios_1.post)(requestUrl.toString(), data, {
19
+ headers: {
20
+ Authorization: `Bearer ${auth.apiKey}`
21
+ },
22
+ });
23
+ if (requestResponse.isSuccess()) {
24
+ response = true;
25
+ }
26
+ return response;
27
+ };
28
+ exports.getBatch = getBatch;
@@ -0,0 +1,7 @@
1
+ import { Auth } from "../";
2
+ /**
3
+ * Depends on the Scraper setup!
4
+ *
5
+ * Make the request and pool the response until the data is available.
6
+ */
7
+ export declare const getRealtime: (auth: Auth, scraperId: string, data?: {}) => Promise<{}>;