@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,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getRealtime = void 0;
4
+ const axios_1 = require("../../axios");
5
+ const api_1 = require("../../api");
6
+ const util_1 = require("../../util");
7
+ /**
8
+ * Depends on the Scraper setup!
9
+ *
10
+ * Make the request and pool the response until the data is available.
11
+ */
12
+ const getRealtime = async (auth, scraperId, data = {}) => {
13
+ let response = {};
14
+ const requestUrl = `https://api.brightdata.com/dca/trigger_immediate?collector=${scraperId}`;
15
+ const requestResponse = await (0, axios_1.post)(requestUrl, data, {
16
+ headers: {
17
+ Authorization: `Bearer ${auth.apiKey}`
18
+ },
19
+ });
20
+ if (requestResponse.isSuccess()) {
21
+ const responseId = requestResponse.getBodyDefaultTo(["response_id"], "");
22
+ if ("" !== responseId) {
23
+ let state = api_1.ApiState.PENDING;
24
+ while (api_1.ApiState.PENDING === state) {
25
+ const resultUrl = `https://api.brightdata.com/dca/get_result?response_id=${responseId}`;
26
+ // Use fetch with the agent option to make an HTTP request through the proxy
27
+ // Replace <target_url> with the URL you want to request
28
+ const resultResponse = await (0, axios_1.get)(resultUrl, {
29
+ headers: {
30
+ Authorization: `Bearer ${auth.apiKey}`
31
+ },
32
+ });
33
+ if (resultResponse.isSuccess()) {
34
+ if (undefined !== resultResponse.body.pending &&
35
+ true === resultResponse.body.pending) {
36
+ state = api_1.ApiState.PENDING;
37
+ }
38
+ else {
39
+ state = api_1.ApiState.SUCCESS;
40
+ response = resultResponse.getBody();
41
+ }
42
+ }
43
+ await (0, util_1.sleep)(1);
44
+ }
45
+ }
46
+ }
47
+ return response;
48
+ };
49
+ exports.getRealtime = getRealtime;
@@ -0,0 +1,2 @@
1
+ export { getBatch } from "./getBatch";
2
+ export { getRealtime } from "./getRealtime";
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getRealtime = exports.getBatch = void 0;
4
+ var getBatch_1 = require("./getBatch");
5
+ Object.defineProperty(exports, "getBatch", { enumerable: true, get: function () { return getBatch_1.getBatch; } });
6
+ var getRealtime_1 = require("./getRealtime");
7
+ Object.defineProperty(exports, "getRealtime", { enumerable: true, get: function () { return getRealtime_1.getRealtime; } });
@@ -0,0 +1,2 @@
1
+ export declare const getCache: (key: string) => any;
2
+ export declare const setCache: (key: string, data: any, expires?: number, force?: boolean) => any;
package/cache/index.js ADDED
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.setCache = exports.getCache = void 0;
4
+ const cache = new Map();
5
+ const getCache = (key) => {
6
+ let response = null;
7
+ if (cache.has(key)) {
8
+ const cacheItem = cache.get(key);
9
+ // Timed expiry
10
+ if (cacheItem.expires > 0) {
11
+ // https://ui.dev/get-current-timestamp-javascript
12
+ const expiresAt = Math.floor(cacheItem.insertedAt / 1000) + cacheItem.expires;
13
+ const now = Math.floor(Date.now() / 1000);
14
+ // If we are now beyond the expiry date, update the data
15
+ if (now < expiresAt) {
16
+ response = cacheItem;
17
+ }
18
+ }
19
+ // 0 - Never expires
20
+ else {
21
+ response = cacheItem;
22
+ }
23
+ }
24
+ return response;
25
+ };
26
+ exports.getCache = getCache;
27
+ const setCache = (key, data, expires = 0, force = false) => {
28
+ const now = Math.floor(Date.now() / 1000);
29
+ if (cache.has(key) && !force) {
30
+ const cacheItem = cache.get(key);
31
+ // 0 - Never expires
32
+ if (cacheItem.expires > 0) {
33
+ // https://ui.dev/get-current-timestamp-javascript
34
+ const expiresAt = Math.floor(cacheItem.insertedAt / 1000) + cacheItem.expires;
35
+ // If we are now beyond the expiry date, update the data
36
+ if (now < expiresAt) {
37
+ return cacheItem;
38
+ }
39
+ }
40
+ }
41
+ cache.set(key, {
42
+ data,
43
+ expires,
44
+ insertedAt: now,
45
+ });
46
+ return data;
47
+ };
48
+ exports.setCache = setCache;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const __1 = require("../");
4
+ test('cache', () => {
5
+ const item1 = (0, __1.getCache)('test');
6
+ // console.log('item1', item1);
7
+ (0, __1.setCache)('test', { 'this is something': 'item' });
8
+ const item2 = (0, __1.getCache)('test');
9
+ // console.log('item2', item2);
10
+ });
@@ -0,0 +1,6 @@
1
+ export declare enum CrudState {
2
+ CREATE = "CREATE",
3
+ READ = "READ",
4
+ UPDATE = "UPDATE",
5
+ DELETE = "DELETE"
6
+ }
package/crud/index.js ADDED
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CrudState = void 0;
4
+ var CrudState;
5
+ (function (CrudState) {
6
+ CrudState["CREATE"] = "CREATE";
7
+ CrudState["READ"] = "READ";
8
+ CrudState["UPDATE"] = "UPDATE";
9
+ CrudState["DELETE"] = "DELETE";
10
+ })(CrudState || (exports.CrudState = CrudState = {}));
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Decrypt an encoding string using a salt
3
+ * Library: crypto-js
4
+ */
5
+ export declare const getDecrypt: (appSalt: string, input: string, salt: string) => Promise<string>;
@@ -0,0 +1,47 @@
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.getDecrypt = void 0;
37
+ /**
38
+ * Decrypt an encoding string using a salt
39
+ * Library: crypto-js
40
+ */
41
+ const getDecrypt = async (appSalt, input, salt) => {
42
+ const { AES, enc } = await Promise.resolve().then(() => __importStar(require("crypto-js")));
43
+ const customSalt = `${appSalt}-${salt}`;
44
+ return AES.decrypt(input, customSalt)
45
+ .toString(enc.Utf8);
46
+ };
47
+ exports.getDecrypt = getDecrypt;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Encrypt an encoding string using a salt
3
+ * Library: crypto-js
4
+ */
5
+ export declare const getEncrypt: (appSalt: string, input: string, salt: string) => Promise<string>;
@@ -0,0 +1,47 @@
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.getEncrypt = void 0;
37
+ /**
38
+ * Encrypt an encoding string using a salt
39
+ * Library: crypto-js
40
+ */
41
+ const getEncrypt = async (appSalt, input, salt) => {
42
+ const { AES } = await Promise.resolve().then(() => __importStar(require("crypto-js")));
43
+ const customSalt = `${appSalt}-${salt}`;
44
+ return AES.encrypt(input, customSalt)
45
+ .toString();
46
+ };
47
+ exports.getEncrypt = getEncrypt;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Create a random string and return a number of characters from it.
3
+ */
4
+ export declare const getRandom: (length: number) => string;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getRandom = void 0;
4
+ /**
5
+ * Create a random string and return a number of characters from it.
6
+ */
7
+ const getRandom = (length) => {
8
+ return Math.random()
9
+ .toString(36)
10
+ .substr(0, length);
11
+ };
12
+ exports.getRandom = getRandom;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Encrypt a string using sha256
3
+ * Library: crypto-js
4
+ */
5
+ export declare const getSha256: (input: any) => Promise<string>;
@@ -0,0 +1,48 @@
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.getSha256 = void 0;
37
+ const string_1 = require("../string");
38
+ /**
39
+ * Encrypt a string using sha256
40
+ * Library: crypto-js
41
+ */
42
+ const getSha256 = async (input) => {
43
+ const { SHA256 } = await Promise.resolve().then(() => __importStar(require("crypto-js")));
44
+ const inputString = (0, string_1.getString)(input);
45
+ return SHA256(inputString)
46
+ .toString();
47
+ };
48
+ exports.getSha256 = getSha256;
@@ -0,0 +1,4 @@
1
+ export { getDecrypt } from "./getDecrypt";
2
+ export { getEncrypt } from "./getEncrypt";
3
+ export { getRandom } from "./getRandom";
4
+ export { getSha256 } from "./getSha256";
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getSha256 = exports.getRandom = exports.getEncrypt = exports.getDecrypt = void 0;
4
+ var getDecrypt_1 = require("./getDecrypt");
5
+ Object.defineProperty(exports, "getDecrypt", { enumerable: true, get: function () { return getDecrypt_1.getDecrypt; } });
6
+ var getEncrypt_1 = require("./getEncrypt");
7
+ Object.defineProperty(exports, "getEncrypt", { enumerable: true, get: function () { return getEncrypt_1.getEncrypt; } });
8
+ var getRandom_1 = require("./getRandom");
9
+ Object.defineProperty(exports, "getRandom", { enumerable: true, get: function () { return getRandom_1.getRandom; } });
10
+ var getSha256_1 = require("./getSha256");
11
+ Object.defineProperty(exports, "getSha256", { enumerable: true, get: function () { return getSha256_1.getSha256; } });
@@ -0,0 +1,75 @@
1
+ import { DateTime, Zone } from "luxon";
2
+ import { InputDate, Timeframe } from "./";
3
+ /**
4
+ * Convert an client's input (any time-zone) ready to be used by the server (UTC).
5
+ */
6
+ export declare const getUtcDate: (input: InputDate, inputZone?: Zone) => DateTime<boolean>;
7
+ /**
8
+ * Assume the input is always UTC.
9
+ *
10
+ * If it's not UTC, it needs to be converted to UTC before being used.
11
+ */
12
+ export declare const getDate: (input?: InputDate, setMidnight?: boolean) => DateTime<boolean>;
13
+ /**
14
+ * Similar to date-fns' eachDayOfInterval, however the timezone messes this function up.
15
+ * https://date-fns.org/v2.28.0/docs/eachDayOfInterval
16
+ * https://www.gov.uk/when-do-the-clocks-change
17
+ */
18
+ export declare const getDatesBetween: (start: InputDate, end: InputDate) => DateTime<true>[];
19
+ /**
20
+ * If a given date is beyond the maximum, return the maximum.
21
+ */
22
+ export declare const getMax: (input: DateTime, max: DateTime) => DateTime<boolean>;
23
+ /**
24
+ * If a given date is before the minimum, return the minimum.
25
+ */
26
+ export declare const getMin: (input: DateTime, min: DateTime) => DateTime<boolean>;
27
+ /**
28
+ * Retrieve the closest last Monday relative to the input or today.
29
+ * 0 weeksAgo - Tuesday (10th), return Monday (8th)
30
+ * 1 weeksAgo - Tuesday (10th), return Monday (1st)
31
+ */
32
+ export declare const getMonday: (input?: InputDate, weeksAgo?: number) => DateTime<boolean>;
33
+ /**
34
+ * Retrieve the closest last Sunday relative to the input or today.
35
+ * 0 weeksAgo - Tuesday (17th), return Sunday (14th)
36
+ * 1 weeksAgo - Tuesday (17th), return Monday (7th)
37
+ */
38
+ export declare const getSunday: (input?: InputDate, weeksAgo?: number) => DateTime<boolean>;
39
+ /**
40
+ * Return an object of start/end predefined date of Last Week.
41
+ * Creating a date from scratch (no user input), thus needs to be London time.
42
+ */
43
+ export declare const getLastWeek: () => Timeframe;
44
+ /**
45
+ * Return an object of start/end predefined date of This Week.
46
+ * Creating a date from scratch (no user input), thus needs to be London time.
47
+ */
48
+ export declare const getThisWeek: () => Timeframe;
49
+ /**
50
+ * Return an object of start/end predefined date of Two Weeks Ago.
51
+ * Creating a date from scratch (no user input), thus needs to be London time.
52
+ */
53
+ export declare const getTwoWeeksAgo: () => Timeframe;
54
+ /**
55
+ * Shortcut to get today's date.
56
+ * Creating a date from scratch (no user input), thus needs to be London time.
57
+ */
58
+ export declare const getToday: (setMidnight?: boolean) => DateTime<boolean>;
59
+ /**
60
+ * From a given input, move the date back X weeksAgo
61
+ */
62
+ export declare const getWeeksAgo: (input?: InputDate, weeksAgo?: number) => DateTime<boolean>;
63
+ /**
64
+ * Shortcut to get yesterday's date.
65
+ * Creating a date from scratch (no user input), thus needs to be London time.
66
+ */
67
+ export declare const getYesterday: (input?: InputDate) => DateTime<boolean>;
68
+ /**
69
+ * Check to see if a given timeframe is This Week.
70
+ */
71
+ export declare const isThisWeek: (start: InputDate, end: InputDate) => boolean;
72
+ /**
73
+ * Check to see if a given timeframe is Last Week.
74
+ */
75
+ export declare const isLastWeek: (start: InputDate, end: InputDate) => boolean;
@@ -0,0 +1,207 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isLastWeek = exports.isThisWeek = exports.getYesterday = exports.getWeeksAgo = exports.getToday = exports.getTwoWeeksAgo = exports.getThisWeek = exports.getLastWeek = exports.getSunday = exports.getMonday = exports.getMin = exports.getMax = exports.getDatesBetween = exports.getDate = exports.getUtcDate = void 0;
4
+ const luxon_1 = require("luxon");
5
+ /**
6
+ * Convert an client's input (any time-zone) ready to be used by the server (UTC).
7
+ */
8
+ const getUtcDate = (input, inputZone) => {
9
+ let instance = luxon_1.DateTime.now();
10
+ if (input) {
11
+ if (input instanceof Date) {
12
+ instance = luxon_1.DateTime.fromJSDate(input);
13
+ }
14
+ else if (input instanceof luxon_1.DateTime) {
15
+ instance = input;
16
+ }
17
+ else {
18
+ instance = luxon_1.DateTime.fromISO(input.toString(), { zone: inputZone });
19
+ if (!instance.isValid) {
20
+ instance = luxon_1.DateTime.fromFormat(input.toString(), "yyyy-MM-dd HH:mm:ss", { zone: inputZone });
21
+ }
22
+ }
23
+ }
24
+ return instance.toUTC();
25
+ };
26
+ exports.getUtcDate = getUtcDate;
27
+ /**
28
+ * Assume the input is always UTC.
29
+ *
30
+ * If it's not UTC, it needs to be converted to UTC before being used.
31
+ */
32
+ const getDate = (input, setMidnight) => {
33
+ let instance = luxon_1.DateTime.now();
34
+ if (input) {
35
+ if (input instanceof Date) {
36
+ instance = luxon_1.DateTime.fromJSDate(input).toUTC();
37
+ }
38
+ else if (input instanceof luxon_1.DateTime) {
39
+ instance = input.toUTC();
40
+ }
41
+ else {
42
+ instance = luxon_1.DateTime.fromISO(input.toString(), { zone: "utc" });
43
+ if (!instance.isValid) {
44
+ instance = luxon_1.DateTime.fromFormat(input.toString(), "yyyy-MM-dd HH:mm:ss", { zone: "utc" });
45
+ }
46
+ }
47
+ }
48
+ // instance = instance.setZone("utc");
49
+ if (setMidnight) {
50
+ instance = instance.set({
51
+ hour: 0,
52
+ minute: 0,
53
+ second: 0,
54
+ millisecond: 0,
55
+ });
56
+ }
57
+ return instance;
58
+ };
59
+ exports.getDate = getDate;
60
+ /**
61
+ * Similar to date-fns' eachDayOfInterval, however the timezone messes this function up.
62
+ * https://date-fns.org/v2.28.0/docs/eachDayOfInterval
63
+ * https://www.gov.uk/when-do-the-clocks-change
64
+ */
65
+ const getDatesBetween = (start, end) => {
66
+ const startInstance = (0, exports.getDate)(start);
67
+ const endInstance = (0, exports.getDate)(end);
68
+ const response = luxon_1.Interval.fromDateTimes(startInstance.startOf("day"), endInstance.endOf("day"))
69
+ .splitBy({ day: 1 })
70
+ .map(d => d.start);
71
+ return response;
72
+ };
73
+ exports.getDatesBetween = getDatesBetween;
74
+ /**
75
+ * If a given date is beyond the maximum, return the maximum.
76
+ */
77
+ const getMax = (input, max) => {
78
+ return input > max ? max : input;
79
+ };
80
+ exports.getMax = getMax;
81
+ /**
82
+ * If a given date is before the minimum, return the minimum.
83
+ */
84
+ const getMin = (input, min) => {
85
+ return input < min ? min : input;
86
+ };
87
+ exports.getMin = getMin;
88
+ /**
89
+ * Retrieve the closest last Monday relative to the input or today.
90
+ * 0 weeksAgo - Tuesday (10th), return Monday (8th)
91
+ * 1 weeksAgo - Tuesday (10th), return Monday (1st)
92
+ */
93
+ const getMonday = (input, weeksAgo) => {
94
+ let instance = (0, exports.getDate)(input);
95
+ if ("Mon" !== instance.toFormat("EEE")) {
96
+ // Get the ISO Day of week (Monday - 1 to Sunday - 7)
97
+ const isoDay = Number(instance.toFormat("E")) - 1;
98
+ instance = instance.minus({ days: isoDay });
99
+ }
100
+ // Move it back weeks
101
+ instance = instance.minus({ weeks: weeksAgo ?? 0 });
102
+ return instance;
103
+ };
104
+ exports.getMonday = getMonday;
105
+ /**
106
+ * Retrieve the closest last Sunday relative to the input or today.
107
+ * 0 weeksAgo - Tuesday (17th), return Sunday (14th)
108
+ * 1 weeksAgo - Tuesday (17th), return Monday (7th)
109
+ */
110
+ const getSunday = (input, weeksAgo) => {
111
+ let instance = (0, exports.getDate)(input);
112
+ if ("Sun" !== instance.toFormat("EEE")) {
113
+ // Get the ISO Day of week (Monday - 1 to Sunday - 7)
114
+ const isoDay = Number(instance.toFormat("E"));
115
+ instance = instance.minus({ days: isoDay });
116
+ }
117
+ // Move it back weeks
118
+ instance = instance.minus({ weeks: weeksAgo ?? 0 });
119
+ return instance;
120
+ };
121
+ exports.getSunday = getSunday;
122
+ /**
123
+ * Return an object of start/end predefined date of Last Week.
124
+ * Creating a date from scratch (no user input), thus needs to be London time.
125
+ */
126
+ const getLastWeek = () => {
127
+ return {
128
+ end: (0, exports.getMonday)(undefined, 0),
129
+ start: (0, exports.getSunday)(undefined, 1),
130
+ };
131
+ };
132
+ exports.getLastWeek = getLastWeek;
133
+ /**
134
+ * Return an object of start/end predefined date of This Week.
135
+ * Creating a date from scratch (no user input), thus needs to be London time.
136
+ */
137
+ const getThisWeek = () => {
138
+ return {
139
+ end: (0, exports.getMonday)(undefined, 0),
140
+ start: (0, exports.getSunday)(undefined, -1),
141
+ };
142
+ };
143
+ exports.getThisWeek = getThisWeek;
144
+ /**
145
+ * Return an object of start/end predefined date of Two Weeks Ago.
146
+ * Creating a date from scratch (no user input), thus needs to be London time.
147
+ */
148
+ const getTwoWeeksAgo = () => {
149
+ return {
150
+ end: (0, exports.getMonday)(undefined, 1),
151
+ start: (0, exports.getSunday)(undefined, 2),
152
+ };
153
+ };
154
+ exports.getTwoWeeksAgo = getTwoWeeksAgo;
155
+ /**
156
+ * Shortcut to get today's date.
157
+ * Creating a date from scratch (no user input), thus needs to be London time.
158
+ */
159
+ const getToday = (setMidnight) => {
160
+ return (0, exports.getDate)(undefined, setMidnight);
161
+ };
162
+ exports.getToday = getToday;
163
+ /**
164
+ * From a given input, move the date back X weeksAgo
165
+ */
166
+ const getWeeksAgo = (input, weeksAgo) => {
167
+ let instance = (0, exports.getDate)(input);
168
+ instance = instance.plus({ weeks: weeksAgo });
169
+ return instance;
170
+ };
171
+ exports.getWeeksAgo = getWeeksAgo;
172
+ /**
173
+ * Shortcut to get yesterday's date.
174
+ * Creating a date from scratch (no user input), thus needs to be London time.
175
+ */
176
+ const getYesterday = (input) => {
177
+ let instance = (0, exports.getDate)(input);
178
+ instance = instance.minus({ days: 1 });
179
+ return instance;
180
+ };
181
+ exports.getYesterday = getYesterday;
182
+ /**
183
+ * Check to see if a given timeframe is This Week.
184
+ */
185
+ const isThisWeek = (start, end) => {
186
+ const inputWeek = {
187
+ start: (0, exports.getDate)(start),
188
+ end: (0, exports.getDate)(end),
189
+ };
190
+ const thisWeek = (0, exports.getThisWeek)();
191
+ // Day confirms same year and month and day
192
+ return inputWeek.start.hasSame(thisWeek.start, "day") && inputWeek.end.hasSame(thisWeek.end, "day");
193
+ };
194
+ exports.isThisWeek = isThisWeek;
195
+ /**
196
+ * Check to see if a given timeframe is Last Week.
197
+ */
198
+ const isLastWeek = (start, end) => {
199
+ const inputWeek = {
200
+ start: (0, exports.getDate)(start),
201
+ end: (0, exports.getDate)(end),
202
+ };
203
+ const lastWeek = (0, exports.getLastWeek)();
204
+ // Day confirms same year and month and day
205
+ return inputWeek.start.hasSame(lastWeek.start, "day") && inputWeek.end.hasSame(lastWeek.end, "day");
206
+ };
207
+ exports.isLastWeek = isLastWeek;
@@ -0,0 +1,19 @@
1
+ import { Timeframe } from "./";
2
+ import { Interval } from "luxon";
3
+ /**
4
+ * Get the current financial year.
5
+ */
6
+ export declare const getFinancialYear: (year?: number) => Timeframe;
7
+ /**
8
+ * Return the current financial year up to today.
9
+ */
10
+ export declare const getFinancialYearToDate: () => Timeframe;
11
+ /**
12
+ * Return the current financial year up to yesterday.
13
+ * Timezone should always be London based
14
+ */
15
+ export declare const getFinancialYearToYesterday: () => Timeframe;
16
+ /**
17
+ * Get the current financial year.
18
+ */
19
+ export declare const getFinancialYearWeeks: (year?: number) => Interval<boolean>[];