@8ms/helpers 2.2.9 → 2.2.12

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 (178) hide show
  1. package/.github/workflows/deploy_npmjs.yml +3 -0
  2. package/_class/BaseClass.js +43 -52
  3. package/_class/BaseNamespace.js +17 -20
  4. package/_class/index.js +2 -7
  5. package/adverity/getJobs.js +7 -11
  6. package/adverity/index.js +51 -54
  7. package/adverity/server.js +1 -5
  8. package/api/ApiResponseClass.js +84 -88
  9. package/api/functions.js +13 -22
  10. package/api/index.js +3 -19
  11. package/api/types.js +5 -9
  12. package/array/index.js +3 -11
  13. package/atInternet/index.js +10 -13
  14. package/aws/ec2/AwsEc2Namespace.js +34 -74
  15. package/aws/ec2/server.js +5 -9
  16. package/aws/ecs/AwsEcsNamespace.js +110 -150
  17. package/aws/ecs/server.js +5 -9
  18. package/aws/glue/AwsGlueNamespace.js +26 -66
  19. package/aws/glue/server.js +5 -9
  20. package/aws/isResponse200.js +3 -7
  21. package/aws/lambda/AwsLambdaNamespace.js +62 -102
  22. package/aws/lambda/server.js +6 -11
  23. package/aws/s3/AwsS3Namespace.js +347 -390
  24. package/aws/s3/payload.js +29 -32
  25. package/aws/s3/server.js +9 -14
  26. package/aws/server.js +5 -10
  27. package/aws/ses/AwsSesNamespace.js +36 -76
  28. package/aws/ses/SimpleEmail.js +267 -304
  29. package/aws/ses/server.js +6 -11
  30. package/aws/sqs/AwsSqsNamespace.js +49 -89
  31. package/aws/sqs/server.js +5 -9
  32. package/aws/ssm/AwsSsmNamespace.js +43 -79
  33. package/aws/ssm/server.js +5 -9
  34. package/axios/deleteRequest.js +8 -15
  35. package/axios/get.js +8 -15
  36. package/axios/index.js +3 -9
  37. package/axios/post.js +8 -15
  38. package/boolean/index.js +3 -10
  39. package/brightData/serpApi/buildGoogleSerpUrl.js +1 -5
  40. package/brightData/serpApi/buildGoogleTrendsUrl.js +1 -5
  41. package/brightData/serpApi/getAsyncRequestId.js +8 -12
  42. package/brightData/serpApi/getAsyncResults.js +8 -12
  43. package/brightData/serpApi/getRealtime.js +3 -7
  44. package/brightData/serpApi/server.js +6 -14
  45. package/brightData/server.js +2 -7
  46. package/brightData/webScraperIde/getBatch.js +3 -7
  47. package/brightData/webScraperIde/getRealtime.js +11 -15
  48. package/brightData/webScraperIde/server.js +2 -7
  49. package/cache/server.js +2 -7
  50. package/cache/test/cache.test.js +4 -6
  51. package/crud/index.js +1 -4
  52. package/crypto/getDecrypt.js +2 -39
  53. package/crypto/getEncrypt.js +2 -39
  54. package/crypto/getRandom.js +1 -5
  55. package/crypto/getSha256.js +4 -41
  56. package/crypto/index.js +4 -11
  57. package/date/calculation.js +70 -99
  58. package/date/financialYear.js +16 -23
  59. package/date/format.js +40 -61
  60. package/date/index.js +4 -20
  61. package/date/type.js +4 -7
  62. package/environment/index.js +15 -25
  63. package/eskimi/getAgeGroup.js +3 -7
  64. package/eskimi/getData.js +3 -7
  65. package/eskimi/getDevice.js +3 -7
  66. package/eskimi/getGender.js +3 -7
  67. package/eskimi/server.js +23 -26
  68. package/file/index.js +8 -46
  69. package/geo/countries.js +1 -4
  70. package/geo/index.js +2 -7
  71. package/geo/languages.js +1 -4
  72. package/google/bigQuery/GoogleBigQueryNamespace.js +108 -148
  73. package/google/bigQuery/loadData.js +1 -5
  74. package/google/bigQuery/server.js +8 -14
  75. package/google/server.js +1 -5
  76. package/google/sheets/GoogleSheetsNamespace.js +34 -74
  77. package/google/sheets/getAssociatedData.js +1 -5
  78. package/google/sheets/server.js +8 -14
  79. package/google/storage/GoogleCloudStorageNamespace.js +62 -102
  80. package/google/storage/server.js +6 -10
  81. package/googleAds/GoogleAdsNamespace.js +28 -68
  82. package/googleAds/keywordPlanner/server.js +32 -35
  83. package/googleAds/server.js +6 -10
  84. package/googlePageSpeed/GooglePageSpeedNamespace.js +21 -28
  85. package/googlePageSpeed/server.js +8 -12
  86. package/googleSearchIncidents/server.js +28 -32
  87. package/greenDomain/server.js +17 -21
  88. package/inngest/server.js +1 -4
  89. package/json/getJsonNewline.js +3 -7
  90. package/json/index.js +2 -7
  91. package/json/isJson.js +1 -5
  92. package/littleWarden/LittleWardenNamespace.js +24 -31
  93. package/littleWarden/getUrlStatus.js +3 -7
  94. package/littleWarden/server.js +14 -22
  95. package/lumar/api/buildRequest.js +14 -18
  96. package/lumar/api/getData.js +3 -7
  97. package/lumar/api/initClient.js +3 -7
  98. package/lumar/api/server.js +6 -12
  99. package/lumar/graphql/columns.js +1 -4
  100. package/lumar/graphql/getData.js +3 -7
  101. package/lumar/graphql/initClient.js +3 -7
  102. package/lumar/graphql/queries/crawl.js +1 -2
  103. package/lumar/graphql/queries/getCrawls.js +1 -3
  104. package/lumar/graphql/queries/getReportDifferences.js +3 -5
  105. package/lumar/graphql/queries/getRows.js +1 -3
  106. package/lumar/graphql/queries/getTotals.js +1 -3
  107. package/lumar/graphql/queries/row.js +1 -2
  108. package/lumar/graphql/reportTemplates.js +1 -4
  109. package/lumar/graphql/server.js +7 -15
  110. package/myTarget/server.js +3 -7
  111. package/nextAuth/index.js +2 -6
  112. package/nextAuth/isSessionReady.js +1 -5
  113. package/nextJs/client/LazyLoad.js +5 -12
  114. package/nextJs/client.js +1 -5
  115. package/nextJs/index.js +2 -7
  116. package/number/format.js +3 -7
  117. package/number/formatCurrency.js +1 -5
  118. package/number/getDecimal.js +3 -7
  119. package/number/getNumber.js +3 -7
  120. package/number/getPercentIncrease.js +4 -8
  121. package/number/getSafeDivide.js +6 -10
  122. package/number/index.js +6 -15
  123. package/object/index.js +1 -5
  124. package/object/replaceKeys.js +3 -7
  125. package/onePassword/OnePasswordNamespace.js +36 -76
  126. package/onePassword/server.js +3 -7
  127. package/openAi/OpenAiNamespace.js +32 -39
  128. package/openAi/server.js +6 -10
  129. package/package.json +224 -122
  130. package/prisma/PrismaNamespace.js +53 -93
  131. package/prisma/getDecimal.js +5 -12
  132. package/prisma/server.js +4 -9
  133. package/scripts/generate-exports.js +50 -0
  134. package/snapchat/SnapchatNamespace.js +20 -27
  135. package/snapchat/server.js +6 -10
  136. package/sorting/byNumberAscending.js +1 -5
  137. package/sorting/byNumberDescending.js +1 -5
  138. package/sorting/byStringAscending.js +1 -5
  139. package/sorting/byStringDescending.js +1 -5
  140. package/sorting/index.js +4 -11
  141. package/stream/server.js +1 -5
  142. package/stream/sort.js +1 -5
  143. package/string/getCapitalised.js +3 -7
  144. package/string/getClean.js +17 -21
  145. package/string/getFolder.js +3 -10
  146. package/string/getProperCase.js +4 -8
  147. package/string/getString.js +8 -15
  148. package/string/getStringFromStream.js +1 -5
  149. package/string/getUnescaped.js +3 -10
  150. package/string/getWithoutAccents.js +1 -5
  151. package/string/getWithoutHtmlTags.js +1 -5
  152. package/string/getWithoutPunctuation.js +1 -5
  153. package/string/getWithoutUnderscores.js +1 -5
  154. package/string/getWithoutWhitespaces.js +1 -5
  155. package/string/index.js +12 -27
  156. package/string/reservedWords.js +5 -9
  157. package/swr/index.js +9 -18
  158. package/upTimeRobot/UpTimeRobotNamespace.js +32 -42
  159. package/upTimeRobot/server.js +11 -15
  160. package/url/index.js +12 -23
  161. package/url/server.js +1 -5
  162. package/url/writeUrlContents.js +6 -46
  163. package/util/defaultTo.js +5 -12
  164. package/util/getBrotliCompressed.js +3 -10
  165. package/util/getBrotliDecompressed.js +3 -10
  166. package/util/getClean.js +5 -9
  167. package/util/getError.js +1 -5
  168. package/util/getGzipCompressed.js +3 -10
  169. package/util/getGzipDecompressed.js +3 -10
  170. package/util/getWithoutHash.js +1 -5
  171. package/util/getWithoutParameter.js +1 -5
  172. package/util/index.js +7 -17
  173. package/util/isUndefined.js +3 -7
  174. package/util/promiseChunks.js +6 -10
  175. package/util/server.js +4 -11
  176. package/util/sleep.js +1 -5
  177. package/webWorker/index.js +1 -4
  178. package/xml/getXml.js +3 -7
@@ -1,95 +1,55 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.AwsSqsNamespace = void 0;
37
- const _class_1 = require("../../_class");
38
- class AwsSqsNamespace extends _class_1.BaseNamespace {
39
- constructor() {
40
- super(...arguments);
41
- this.ensureInit = async () => {
42
- if (!this.client) {
43
- try {
44
- const { SQSClient } = await Promise.resolve().then(() => __importStar(require("@aws-sdk/client-sqs")));
45
- this.client = new SQSClient(this.config);
46
- }
47
- catch (e) {
48
- throw new Error("AWS SQS Client not installed");
49
- }
50
- }
51
- };
52
- this.addToQueue = async (props) => {
53
- await this.ensureInit();
54
- const { SendMessageCommand } = await Promise.resolve().then(() => __importStar(require("@aws-sdk/client-sqs")));
55
- let params = {
56
- MessageBody: JSON.stringify({
57
- queueId: props.queueId,
58
- data: props.data,
59
- }),
60
- QueueUrl: props.queueUrl,
61
- };
62
- // Required for FIFO
63
- if (undefined !== props?.dedupeId) {
64
- params["MessageDeduplicationId"] = props.dedupeId;
1
+ import { BaseNamespace } from "../../_class";
2
+ export class AwsSqsNamespace extends BaseNamespace {
3
+ ensureInit = async () => {
4
+ if (!this.client) {
5
+ try {
6
+ const { SQSClient } = await import("@aws-sdk/client-sqs");
7
+ this.client = new SQSClient(this.config);
65
8
  }
66
- // Required for FIFO
67
- if (undefined !== props?.groupId) {
68
- params["MessageGroupId"] = props.dedupeId;
9
+ catch (e) {
10
+ throw new Error("AWS SQS Client not installed");
69
11
  }
70
- const sendData = await this.client.send(new SendMessageCommand(params));
71
- return sendData;
12
+ }
13
+ };
14
+ addToQueue = async (props) => {
15
+ await this.ensureInit();
16
+ const { SendMessageCommand } = await import("@aws-sdk/client-sqs");
17
+ let params = {
18
+ MessageBody: JSON.stringify({
19
+ queueId: props.queueId,
20
+ data: props.data,
21
+ }),
22
+ QueueUrl: props.queueUrl,
72
23
  };
73
- this.deleteFromQueue = async (queueUrl, recipientHandle) => {
74
- await this.ensureInit();
75
- const { DeleteMessageCommand } = await Promise.resolve().then(() => __importStar(require("@aws-sdk/client-sqs")));
76
- const params = {
77
- QueueUrl: queueUrl,
78
- ReceiptHandle: recipientHandle,
79
- };
80
- const sendData = await this.client.send(new DeleteMessageCommand(params));
81
- return sendData;
24
+ // Required for FIFO
25
+ if (undefined !== props?.dedupeId) {
26
+ params["MessageDeduplicationId"] = props.dedupeId;
27
+ }
28
+ // Required for FIFO
29
+ if (undefined !== props?.groupId) {
30
+ params["MessageGroupId"] = props.dedupeId;
31
+ }
32
+ const sendData = await this.client.send(new SendMessageCommand(params));
33
+ return sendData;
34
+ };
35
+ deleteFromQueue = async (queueUrl, recipientHandle) => {
36
+ await this.ensureInit();
37
+ const { DeleteMessageCommand } = await import("@aws-sdk/client-sqs");
38
+ const params = {
39
+ QueueUrl: queueUrl,
40
+ ReceiptHandle: recipientHandle,
82
41
  };
83
- this.isEventSqs = async (event) => {
84
- await this.ensureInit();
85
- let response = false;
86
- if (undefined !== event["Records"]) {
87
- for (let i = 0; i < event['Records'].length; i++) {
88
- // todo: Complete
89
- }
42
+ const sendData = await this.client.send(new DeleteMessageCommand(params));
43
+ return sendData;
44
+ };
45
+ isEventSqs = async (event) => {
46
+ await this.ensureInit();
47
+ let response = false;
48
+ if (undefined !== event["Records"]) {
49
+ for (let i = 0; i < event['Records'].length; i++) {
50
+ // todo: Complete
90
51
  }
91
- return response;
92
- };
93
- }
52
+ }
53
+ return response;
54
+ };
94
55
  }
95
- exports.AwsSqsNamespace = AwsSqsNamespace;
package/aws/sqs/server.js CHANGED
@@ -1,16 +1,12 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.awsSqsClient = void 0;
4
- const AwsSqsNamespace_1 = require("./AwsSqsNamespace");
5
- const server_1 = require("../server");
1
+ import { AwsSqsNamespace } from "./AwsSqsNamespace";
2
+ import { getConfig } from "../server";
6
3
  const awsSqsNamespaces = new Map();
7
- const awsSqsClient = async (key = "default", config, vaultId, itemId) => {
4
+ export const awsSqsClient = async (key = "default", config, vaultId, itemId) => {
8
5
  if (awsSqsNamespaces.has(key)) {
9
6
  return awsSqsNamespaces.get(key);
10
7
  }
11
- const instanceConfig = await (0, server_1.getConfig)(key, config, vaultId, itemId);
12
- const namespace = new AwsSqsNamespace_1.AwsSqsNamespace(key, instanceConfig);
8
+ const instanceConfig = await getConfig(key, config, vaultId, itemId);
9
+ const namespace = new AwsSqsNamespace(key, instanceConfig);
13
10
  awsSqsNamespaces.set(key, namespace);
14
11
  return namespace;
15
12
  };
16
- exports.awsSqsClient = awsSqsClient;
@@ -1,88 +1,52 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.AwsSsmNamespace = void 0;
37
- const _class_1 = require("../../_class");
38
- class AwsSsmNamespace extends _class_1.BaseNamespace {
1
+ import { BaseNamespace } from "../../_class";
2
+ export class AwsSsmNamespace extends BaseNamespace {
3
+ parameters;
39
4
  constructor(key, config) {
40
5
  super(key, config);
41
- this.ensureInit = async () => {
42
- if (!this.client) {
43
- try {
44
- const { SSMClient } = await Promise.resolve().then(() => __importStar(require("@aws-sdk/client-ssm")));
45
- this.client = new SSMClient(this.config);
46
- }
47
- catch (e) {
48
- throw new Error("AWS SSM Client not installed");
49
- }
6
+ this.parameters = new Map();
7
+ }
8
+ ensureInit = async () => {
9
+ if (!this.client) {
10
+ try {
11
+ const { SSMClient } = await import("@aws-sdk/client-ssm");
12
+ this.client = new SSMClient(this.config);
13
+ }
14
+ catch (e) {
15
+ throw new Error("AWS SSM Client not installed");
50
16
  }
51
- };
52
- this.getParameter = async (name, withDecryption = false, isJson = true) => {
53
- await this.ensureInit();
54
- if (!this.parameters.has(name)) {
55
- const { GetParameterCommand } = await Promise.resolve().then(() => __importStar(require("@aws-sdk/client-ssm")));
56
- const apiResponse = await this.client.send(new GetParameterCommand({
57
- Name: name,
58
- WithDecryption: undefined === withDecryption ? true : withDecryption,
59
- }));
60
- if (apiResponse.Parameter.Value) {
61
- // Value is undefined
62
- if (undefined === apiResponse.Parameter.Value) {
63
- this.parameters.set(name, null);
17
+ }
18
+ };
19
+ getParameter = async (name, withDecryption = false, isJson = true) => {
20
+ await this.ensureInit();
21
+ if (!this.parameters.has(name)) {
22
+ const { GetParameterCommand } = await import("@aws-sdk/client-ssm");
23
+ const apiResponse = await this.client.send(new GetParameterCommand({
24
+ Name: name,
25
+ WithDecryption: undefined === withDecryption ? true : withDecryption,
26
+ }));
27
+ if (apiResponse.Parameter.Value) {
28
+ // Value is undefined
29
+ if (undefined === apiResponse.Parameter.Value) {
30
+ this.parameters.set(name, null);
31
+ }
32
+ // Value is defined
33
+ else {
34
+ // isJson is default - decode
35
+ if (undefined === isJson || true === isJson) {
36
+ this.parameters.set(name, JSON.parse(apiResponse.Parameter.Value) || null);
64
37
  }
65
- // Value is defined
38
+ // Not JSON don't decode
66
39
  else {
67
- // isJson is default - decode
68
- if (undefined === isJson || true === isJson) {
69
- this.parameters.set(name, JSON.parse(apiResponse.Parameter.Value) || null);
70
- }
71
- // Not JSON don't decode
72
- else {
73
- this.parameters.set(name, apiResponse.Parameter.Value);
74
- }
40
+ this.parameters.set(name, apiResponse.Parameter.Value);
75
41
  }
76
42
  }
77
- // Value not found (null so it can be sent from server to front end)
78
- else {
79
- this.parameters.set(name, null);
80
- }
81
43
  }
82
- // Return the loaded result
83
- return this.parameters.get(name);
84
- };
85
- this.parameters = new Map();
86
- }
44
+ // Value not found (null so it can be sent from server to front end)
45
+ else {
46
+ this.parameters.set(name, null);
47
+ }
48
+ }
49
+ // Return the loaded result
50
+ return this.parameters.get(name);
51
+ };
87
52
  }
88
- exports.AwsSsmNamespace = AwsSsmNamespace;
package/aws/ssm/server.js CHANGED
@@ -1,16 +1,12 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.awsSsmClient = void 0;
4
- const AwsSsmNamespace_1 = require("./AwsSsmNamespace");
5
- const server_1 = require("../server");
1
+ import { AwsSsmNamespace } from "./AwsSsmNamespace";
2
+ import { getConfig } from "../server";
6
3
  const awsSsmNamespaces = new Map();
7
- const awsSsmClient = async (key = "default", config, vaultId, itemId) => {
4
+ export const awsSsmClient = async (key = "default", config, vaultId, itemId) => {
8
5
  if (awsSsmNamespaces.has(key)) {
9
6
  return awsSsmNamespaces.get(key);
10
7
  }
11
- const instanceConfig = await (0, server_1.getConfig)(key, config, vaultId, itemId);
12
- const namespace = new AwsSsmNamespace_1.AwsSsmNamespace(key, instanceConfig);
8
+ const instanceConfig = await getConfig(key, config, vaultId, itemId);
9
+ const namespace = new AwsSsmNamespace(key, instanceConfig);
13
10
  awsSsmNamespaces.set(key, namespace);
14
11
  return namespace;
15
12
  };
16
- exports.awsSsmClient = awsSsmClient;
@@ -1,33 +1,26 @@
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");
1
+ import axios from "axios";
2
+ import { ApiResponseClass } from "../api";
9
3
  /**
10
4
  * Make a DELETE request.
11
5
  * Can't use the function name delete as it's reserved
12
6
  */
13
- const deleteRequest = async (url, config = {}) => {
14
- const response = await axios_1.default.delete(url, config)
7
+ export const deleteRequest = async (url, config = {}) => {
8
+ const response = await axios.delete(url, config)
15
9
  .then(async (response) => {
16
10
  // Is API response
17
11
  if (undefined !== response.data.body && undefined !== response.data.error && undefined !== response.data.state) {
18
- return new api_1.ApiResponseClass(response.data);
12
+ return new ApiResponseClass(response.data);
19
13
  }
20
14
  // General success - some APIs report 201
21
15
  else if (response.status >= 200 && response.status <= 299) {
22
- return (new api_1.ApiResponseClass()).setToSuccess(response.data);
16
+ return (new ApiResponseClass()).setToSuccess(response.data);
23
17
  }
24
18
  // Error
25
- return (new api_1.ApiResponseClass()).setToError(response.data, response.statusText);
19
+ return (new ApiResponseClass()).setToError(response.data, response.statusText);
26
20
  })
27
21
  .catch(error => {
28
22
  // Error
29
- return (new api_1.ApiResponseClass()).setToError(null, error.message);
23
+ return (new ApiResponseClass()).setToError(null, error.message);
30
24
  });
31
25
  return response;
32
26
  };
33
- exports.deleteRequest = deleteRequest;
package/axios/get.js CHANGED
@@ -1,31 +1,24 @@
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");
1
+ import axios from "axios";
2
+ import { ApiResponseClass } from "../api";
9
3
  /**
10
4
  * Make a GET request.
11
5
  */
12
- const get = async (url, config = {}) => {
13
- const response = await axios_1.default.get(url, config)
6
+ export const get = async (url, config = {}) => {
7
+ const response = await axios.get(url, config)
14
8
  .then(async (response) => {
15
9
  // Is API response
16
10
  if (undefined !== response.data.body && undefined !== response.data.error && undefined !== response.data.state) {
17
- return new api_1.ApiResponseClass(response.data);
11
+ return new ApiResponseClass(response.data);
18
12
  }
19
13
  // General success - some APIs report 201
20
14
  else if (response.status >= 200 && response.status <= 299) {
21
- return (new api_1.ApiResponseClass()).setToSuccess(response.data);
15
+ return (new ApiResponseClass()).setToSuccess(response.data);
22
16
  }
23
17
  // Error
24
- return (new api_1.ApiResponseClass()).setToError(response.data, response.statusText);
18
+ return (new ApiResponseClass()).setToError(response.data, response.statusText);
25
19
  })
26
20
  .catch(error => {
27
- return (new api_1.ApiResponseClass()).setToError(null, error.message);
21
+ return (new ApiResponseClass()).setToError(null, error.message);
28
22
  });
29
23
  return response;
30
24
  };
31
- exports.get = get;
package/axios/index.js CHANGED
@@ -1,9 +1,3 @@
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; } });
1
+ export { get } from "./get";
2
+ export { post } from "./post";
3
+ export { deleteRequest } from "./deleteRequest";
package/axios/post.js CHANGED
@@ -1,32 +1,25 @@
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");
1
+ import axios from "axios";
2
+ import { ApiResponseClass } from "../api";
9
3
  /**
10
4
  * Make a POST request.
11
5
  */
12
- const post = async (url, data = {}, config = {}) => {
13
- const response = await axios_1.default.post(url, data, config)
6
+ export const post = async (url, data = {}, config = {}) => {
7
+ const response = await axios.post(url, data, config)
14
8
  .then(async (response) => {
15
9
  // Is API response
16
10
  if (undefined !== response.data.body && undefined !== response.data.error && undefined !== response.data.state) {
17
- return new api_1.ApiResponseClass(response.data);
11
+ return new ApiResponseClass(response.data);
18
12
  }
19
13
  // General success - some APIs report 201
20
14
  else if (response.status >= 200 && response.status <= 299) {
21
- return (new api_1.ApiResponseClass()).setToSuccess(response.data);
15
+ return (new ApiResponseClass()).setToSuccess(response.data);
22
16
  }
23
17
  // Error
24
- return (new api_1.ApiResponseClass()).setToError(response.data, response.statusText);
18
+ return (new ApiResponseClass()).setToError(response.data, response.statusText);
25
19
  })
26
20
  .catch(error => {
27
21
  // Error
28
- return (new api_1.ApiResponseClass()).setToError(null, error.message);
22
+ return (new ApiResponseClass()).setToError(null, error.message);
29
23
  });
30
24
  return response;
31
25
  };
32
- exports.post = post;
package/boolean/index.js CHANGED
@@ -1,15 +1,9 @@
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"));
1
+ import isBoolean from "lodash/isBoolean";
8
2
  /**
9
3
  * Convert an input from a variety of forms into boolean.
10
4
  */
11
- const getBoolean = (input, defaultValue = false) => {
12
- if ((0, isBoolean_1.default)(input)) {
5
+ export const getBoolean = (input, defaultValue = false) => {
6
+ if (isBoolean(input)) {
13
7
  return input;
14
8
  }
15
9
  else if ("string" === typeof input) {
@@ -20,4 +14,3 @@ const getBoolean = (input, defaultValue = false) => {
20
14
  }
21
15
  return defaultValue;
22
16
  };
23
- exports.getBoolean = getBoolean;
@@ -1,6 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.buildGoogleSerpUrl = void 0;
4
1
  /**
5
2
  * Construct the Google SERP url using Bright Data's API:
6
3
  * https://brightdata.com/cp/serp_api/api/google/search?id=c_2cef083f
@@ -8,7 +5,7 @@ exports.buildGoogleSerpUrl = void 0;
8
5
  * For geolocation use value from:
9
6
  * https://developers.google.com/google-ads/api/data/geotargets
10
7
  */
11
- const buildGoogleSerpUrl = (props) => {
8
+ export const buildGoogleSerpUrl = (props) => {
12
9
  let url = new URL(`https://www.${props.googleDomain}/search`);
13
10
  let params = {
14
11
  query: {
@@ -113,4 +110,3 @@ const buildGoogleSerpUrl = (props) => {
113
110
  }
114
111
  return url.toString();
115
112
  };
116
- exports.buildGoogleSerpUrl = buildGoogleSerpUrl;
@@ -1,6 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.buildGoogleTrendsUrl = void 0;
4
1
  /**
5
2
  * Construct the Google Trends url using Bright Data's API:
6
3
  * https://brightdata.com/cp/serp_api/api/google/trends?id=c_2cef083f
@@ -8,7 +5,7 @@ exports.buildGoogleTrendsUrl = void 0;
8
5
  * For category use value from:
9
6
  * https://trends.google.com/trends/api/explore/pickers/category?lang=en-US&tz=240
10
7
  */
11
- const buildGoogleTrendsUrl = (props) => {
8
+ export const buildGoogleTrendsUrl = (props) => {
12
9
  let url = new URL(`http://trends.google.com/trends/explore`);
13
10
  url.searchParams.append("q", props.query);
14
11
  let params = {
@@ -58,4 +55,3 @@ const buildGoogleTrendsUrl = (props) => {
58
55
  }
59
56
  return url.toString();
60
57
  };
61
- exports.buildGoogleTrendsUrl = buildGoogleTrendsUrl;
@@ -1,29 +1,26 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getAsyncRequestId = void 0;
4
- const axios_1 = require("../../axios");
5
- const server_1 = require("../server");
6
- const server_2 = require("./server");
1
+ import { post } from "../../axios";
2
+ import { getCustomerId, getZone } from "../server";
3
+ import { BrightDataSerpApiType } from "./server";
7
4
  /**
8
5
  * Make an async request to the SERP API using the Bright Data proxy.
9
6
  * Returns a request ID used with getAsyncResults
10
7
  * https://docs.brightdata.com/scraping-automation/serp-api/asynchronous-requests
11
8
  */
12
- const getAsyncRequestId = async (auth, data = {}, type) => {
9
+ export const getAsyncRequestId = async (auth, data = {}, type) => {
13
10
  let url = "";
14
11
  let response = "";
15
12
  // Prevent auth requests getting blocked
16
13
  process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = "0";
17
- const customerId = (0, server_1.getCustomerId)(auth);
18
- const zone = (0, server_1.getZone)(auth);
14
+ const customerId = getCustomerId(auth);
15
+ const zone = getZone(auth);
19
16
  switch (type) {
20
- case server_2.BrightDataSerpApiType.GOOGLE_TRENDS:
17
+ case BrightDataSerpApiType.GOOGLE_TRENDS:
21
18
  url = `https://api.brightdata.com/serp/trends?customer=${customerId}&zone=${zone}`;
22
19
  break;
23
20
  default:
24
21
  url = `https://api.brightdata.com/serp/req?customer=${customerId}&zone=${zone}`;
25
22
  }
26
- const requestResponse = await (0, axios_1.post)(url, data, {
23
+ const requestResponse = await post(url, data, {
27
24
  headers: {
28
25
  Authorization: `Bearer ${auth.apiKey}`
29
26
  },
@@ -33,4 +30,3 @@ const getAsyncRequestId = async (auth, data = {}, type) => {
33
30
  }
34
31
  return response;
35
32
  };
36
- exports.getAsyncRequestId = getAsyncRequestId;
@@ -1,20 +1,17 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getAsyncResults = void 0;
4
- const axios_1 = require("../../axios");
5
- const server_1 = require("../server");
6
- const api_1 = require("../../api");
1
+ import { get } from "../../axios";
2
+ import { getCustomerId, getZone } from "../server";
3
+ import { ApiResponseClass } from "../../api";
7
4
  /**
8
5
  * Using the request ID from getAsyncRequestId fetch to see if the data is available.
9
6
  * https://docs.brightdata.com/scraping-automation/serp-api/asynchronous-requests
10
7
  */
11
- const getAsyncResults = async (auth, requestId) => {
12
- let response = (new api_1.ApiResponseClass());
8
+ export const getAsyncResults = async (auth, requestId) => {
9
+ let response = (new ApiResponseClass());
13
10
  // Prevent auth requests getting blocked
14
11
  process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = "0";
15
- const customerId = (0, server_1.getCustomerId)(auth);
16
- const zone = (0, server_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}`, {
12
+ const customerId = getCustomerId(auth);
13
+ const zone = getZone(auth);
14
+ const requestResponse = await get(`https://api.brightdata.com/serp/get_result?customer=${customerId}&zone=${zone}&response_id=${requestId}`, {
18
15
  headers: {
19
16
  Authorization: `Bearer ${auth.apiKey}`
20
17
  },
@@ -32,4 +29,3 @@ const getAsyncResults = async (auth, requestId) => {
32
29
  }
33
30
  return response;
34
31
  };
35
- exports.getAsyncResults = getAsyncResults;
@@ -1,17 +1,14 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getRealtime = void 0;
4
- const axios_1 = require("../../axios");
1
+ import { get } from "../../axios";
5
2
  /**
6
3
  * Make a request to the SERP API using the Bright Data proxy
7
4
  */
8
- const getRealtime = async (auth, url) => {
5
+ export const getRealtime = async (auth, url) => {
9
6
  let response = {};
10
7
  // Prevent auth requests getting blocked
11
8
  process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = "0";
12
9
  // Use fetch with the agent option to make an HTTP request through the proxy
13
10
  // Replace <target_url> with the URL you want to request
14
- const apiResponse = await (0, axios_1.get)(url, {
11
+ const apiResponse = await get(url, {
15
12
  proxy: {
16
13
  protocol: "http",
17
14
  host: auth.host,
@@ -27,4 +24,3 @@ const getRealtime = async (auth, url) => {
27
24
  }
28
25
  return response;
29
26
  };
30
- exports.getRealtime = getRealtime;