@8ms/helpers 2.0.0 → 2.0.2

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 +30 -0
  315. package/url/index.js +72 -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,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getNumber = void 0;
4
+ const json_1 = require("../json");
5
+ /**
6
+ * Take an input and return a number.
7
+ */
8
+ const getNumber = (input, defaultValue = 0) => {
9
+ // Handle null/undefined inputs
10
+ if (input == null) {
11
+ return defaultValue;
12
+ }
13
+ let response = input;
14
+ // JSON - Decode the value if it's a JSON string
15
+ if (typeof input === "string" && (0, json_1.isJson)(input)) {
16
+ try {
17
+ response = JSON.parse(input);
18
+ }
19
+ catch {
20
+ // If parsing fails, continue with original input
21
+ response = input;
22
+ }
23
+ }
24
+ // Already a number
25
+ if (typeof response === "number") {
26
+ return isNaN(response) ? defaultValue : response;
27
+ }
28
+ // String input
29
+ if (typeof response === "string") {
30
+ // First, try direct conversion
31
+ const directConversion = Number(response.trim());
32
+ if (!isNaN(directConversion)) {
33
+ return directConversion;
34
+ }
35
+ // If that fails, try extracting numbers from the string
36
+ const match = response.match(/^\D*([0-9]*\.?[0-9]+)\D*$/);
37
+ if (match && match[1]) {
38
+ const extracted = Number(match[1]);
39
+ if (!isNaN(extracted)) {
40
+ return extracted;
41
+ }
42
+ }
43
+ }
44
+ // For other types, attempt direct conversion
45
+ const converted = Number(response);
46
+ return isNaN(converted) ? defaultValue : converted;
47
+ };
48
+ exports.getNumber = getNumber;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Formula to work out the percentage increase/decrease.
3
+ */
4
+ export declare const getPercentIncrease: (current: any, comparison: any, defaultValue: number) => number;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getPercentIncrease = void 0;
4
+ const getNumber_1 = require("./getNumber");
5
+ /**
6
+ * Formula to work out the percentage increase/decrease.
7
+ */
8
+ const getPercentIncrease = (current, comparison, defaultValue) => {
9
+ const currentValue = (0, getNumber_1.getNumber)(current);
10
+ const comparisonValue = (0, getNumber_1.getNumber)(comparison);
11
+ if (0 === comparisonValue) {
12
+ return defaultValue;
13
+ }
14
+ return (currentValue - comparisonValue) / comparisonValue * 100;
15
+ };
16
+ exports.getPercentIncrease = getPercentIncrease;
@@ -0,0 +1,11 @@
1
+ type GetSafeDivideProps = {
2
+ defaultValue?: number;
3
+ dp?: number;
4
+ divisor: any;
5
+ numerator: any;
6
+ };
7
+ /**
8
+ * Shorthand function to divide number, but fallback if the divisor is 0.
9
+ */
10
+ export declare const getSafeDivide: (props: GetSafeDivideProps) => number;
11
+ export {};
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getSafeDivide = void 0;
4
+ const getNumber_1 = require("./getNumber");
5
+ const getDecimal_1 = require("./getDecimal");
6
+ /**
7
+ * Shorthand function to divide number, but fallback if the divisor is 0.
8
+ */
9
+ const getSafeDivide = (props) => {
10
+ const numeratorInt = (0, getNumber_1.getNumber)(props.numerator);
11
+ if (numeratorInt === 0) {
12
+ return 0;
13
+ }
14
+ const divisorInt = (0, getNumber_1.getNumber)(props.divisor);
15
+ if (divisorInt === 0 || !Number.isFinite(divisorInt)) {
16
+ return props?.defaultValue ?? 0;
17
+ }
18
+ return (0, getDecimal_1.getDecimal)(numeratorInt / divisorInt, props?.dp);
19
+ };
20
+ exports.getSafeDivide = getSafeDivide;
@@ -0,0 +1,6 @@
1
+ export { format } from "./format";
2
+ export { formatCurrency } from "./formatCurrency";
3
+ export { getDecimal } from "./getDecimal";
4
+ export { getSafeDivide } from "./getSafeDivide";
5
+ export { getNumber } from "./getNumber";
6
+ export { getPercentIncrease } from "./getPercentIncrease";
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getPercentIncrease = exports.getNumber = exports.getSafeDivide = exports.getDecimal = exports.formatCurrency = exports.format = void 0;
4
+ var format_1 = require("./format");
5
+ Object.defineProperty(exports, "format", { enumerable: true, get: function () { return format_1.format; } });
6
+ var formatCurrency_1 = require("./formatCurrency");
7
+ Object.defineProperty(exports, "formatCurrency", { enumerable: true, get: function () { return formatCurrency_1.formatCurrency; } });
8
+ var getDecimal_1 = require("./getDecimal");
9
+ Object.defineProperty(exports, "getDecimal", { enumerable: true, get: function () { return getDecimal_1.getDecimal; } });
10
+ var getSafeDivide_1 = require("./getSafeDivide");
11
+ Object.defineProperty(exports, "getSafeDivide", { enumerable: true, get: function () { return getSafeDivide_1.getSafeDivide; } });
12
+ var getNumber_1 = require("./getNumber");
13
+ Object.defineProperty(exports, "getNumber", { enumerable: true, get: function () { return getNumber_1.getNumber; } });
14
+ var getPercentIncrease_1 = require("./getPercentIncrease");
15
+ Object.defineProperty(exports, "getPercentIncrease", { enumerable: true, get: function () { return getPercentIncrease_1.getPercentIncrease; } });
@@ -0,0 +1 @@
1
+ export { replaceKeys } from "./replaceKeys";
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.replaceKeys = void 0;
4
+ var replaceKeys_1 = require("./replaceKeys");
5
+ Object.defineProperty(exports, "replaceKeys", { enumerable: true, get: function () { return replaceKeys_1.replaceKeys; } });
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Iteratively replace all the keys in an object.
3
+ * https://www.techighness.com/post/replace-all-keys-of-deeply-nested-objects-or-array-of-objects/
4
+ */
5
+ export declare const replaceKeys: (instance: any, getNewKey: Function) => object;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.replaceKeys = void 0;
4
+ /**
5
+ * Iteratively replace all the keys in an object.
6
+ * https://www.techighness.com/post/replace-all-keys-of-deeply-nested-objects-or-array-of-objects/
7
+ */
8
+ const replaceKeys = (instance, getNewKey) => {
9
+ let response = instance;
10
+ if (Array.isArray(instance)) {
11
+ response = [];
12
+ for (let i = 0; i < instance.length; i++) {
13
+ response[i] = (0, exports.replaceKeys)(instance[i], getNewKey);
14
+ }
15
+ }
16
+ else if ("object" === typeof instance) {
17
+ response = {};
18
+ for (const key in instance) {
19
+ const newKey = getNewKey(key);
20
+ response[newKey] = (0, exports.replaceKeys)(instance[key], getNewKey);
21
+ }
22
+ }
23
+ return response;
24
+ };
25
+ exports.replaceKeys = replaceKeys;
@@ -0,0 +1,13 @@
1
+ import { OnePasswordConfig } from "./index";
2
+ import { BaseNamespace } from "../_class";
3
+ import type { Client } from "@1password/sdk";
4
+ export declare class OnePasswordNamespace extends BaseNamespace {
5
+ client: Client | null;
6
+ config: OnePasswordConfig;
7
+ constructor(key: string, config: OnePasswordConfig);
8
+ ensureInit: () => Promise<void>;
9
+ listVaults: () => Promise<import("@1password/sdk").VaultOverview[]>;
10
+ getItem: (vaultId: string, itemId: string) => Promise<import("@1password/sdk").Item>;
11
+ getJsonNote: (vaultId: string, itemId: string) => Promise<any>;
12
+ listItems: (vaultId: string) => Promise<import("@1password/sdk").ItemOverview[]>;
13
+ }
@@ -0,0 +1,81 @@
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.OnePasswordNamespace = void 0;
37
+ const _class_1 = require("../_class");
38
+ class OnePasswordNamespace extends _class_1.BaseNamespace {
39
+ constructor(key, config) {
40
+ super(key, config);
41
+ this.client = null;
42
+ // Async setup to only initialise where required
43
+ this.ensureInit = async () => {
44
+ if (!this.client) {
45
+ try {
46
+ const { createClient } = await Promise.resolve().then(() => __importStar(require("@1password/sdk")));
47
+ this.client = await createClient({
48
+ auth: this.config.serviceAccountToken,
49
+ integrationName: this.config.integrationName || "8MS Helper TS",
50
+ integrationVersion: this.config.integrationVersion || "v1.0.0",
51
+ });
52
+ }
53
+ catch (e) {
54
+ throw new Error("1Password SDK not installed");
55
+ }
56
+ }
57
+ };
58
+ this.listVaults = async () => {
59
+ await this.ensureInit();
60
+ return this.client.vaults.list();
61
+ };
62
+ this.getItem = async (vaultId, itemId) => {
63
+ await this.ensureInit();
64
+ return this.client.items.get(vaultId, itemId);
65
+ };
66
+ this.getJsonNote = async (vaultId, itemId) => {
67
+ let response = null;
68
+ const item = await this.getItem(vaultId, itemId);
69
+ if (item && "undefined" !== typeof item.notes) {
70
+ response = JSON.parse(item.notes);
71
+ }
72
+ return response;
73
+ };
74
+ this.listItems = async (vaultId) => {
75
+ await this.ensureInit();
76
+ return this.client.items.list(vaultId);
77
+ };
78
+ }
79
+ ;
80
+ }
81
+ exports.OnePasswordNamespace = OnePasswordNamespace;
@@ -0,0 +1,7 @@
1
+ import { OnePasswordNamespace } from "./OnePasswordNamespace";
2
+ export type OnePasswordConfig = {
3
+ serviceAccountToken: string;
4
+ integrationName?: string;
5
+ integrationVersion?: string;
6
+ };
7
+ export declare const onePasswordClient: (key?: string, config?: OnePasswordConfig) => Promise<OnePasswordNamespace>;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.onePasswordClient = void 0;
4
+ const OnePasswordNamespace_1 = require("./OnePasswordNamespace");
5
+ const onePasswordNamespaces = new Map();
6
+ // Main client that is used by system
7
+ const onePasswordClient = async (key = "default", config) => {
8
+ if (onePasswordNamespaces.has(key)) {
9
+ return onePasswordNamespaces.get(key);
10
+ }
11
+ if (!config) {
12
+ if (key === "default") {
13
+ config = {
14
+ serviceAccountToken: process.env.ONEPASSWORD_SERVICE_TOKEN
15
+ };
16
+ }
17
+ else {
18
+ throw new Error(`Config required for namespace '${key}'`);
19
+ }
20
+ }
21
+ const namespace = new OnePasswordNamespace_1.OnePasswordNamespace(key, config);
22
+ onePasswordNamespaces.set(key, namespace);
23
+ return namespace;
24
+ };
25
+ exports.onePasswordClient = onePasswordClient;
@@ -0,0 +1,11 @@
1
+ import { OpenAiConfig } from "./index";
2
+ import { BaseNamespace } from "../_class";
3
+ export declare class OpenAiNamespace extends BaseNamespace {
4
+ client: boolean | null;
5
+ config: OpenAiConfig | null;
6
+ /**
7
+ * Renew the access token as it expires every 3 hours.
8
+ */
9
+ ensureInit: () => Promise<void>;
10
+ completion: (prompt: string, temperature?: number, maxTokens?: number, model?: string) => Promise<any>;
11
+ }
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OpenAiNamespace = void 0;
4
+ const _class_1 = require("../_class");
5
+ const axios_1 = require("../axios");
6
+ class OpenAiNamespace extends _class_1.BaseNamespace {
7
+ constructor() {
8
+ super(...arguments);
9
+ this.client = null;
10
+ this.config = null;
11
+ /**
12
+ * Renew the access token as it expires every 3 hours.
13
+ */
14
+ this.ensureInit = async () => {
15
+ if (!this.client) {
16
+ this.client = true;
17
+ }
18
+ };
19
+ this.completion = async (prompt, temperature = 1, maxTokens = null, model = "gpt-3.5-turbo") => {
20
+ let response = null;
21
+ // Make the API request
22
+ const apiResponse = await (0, axios_1.post)(`https://api.openai.com/v1/chat/completions`, {
23
+ max_tokens: maxTokens,
24
+ model,
25
+ messages: [
26
+ {
27
+ role: "user",
28
+ content: prompt,
29
+ }
30
+ ],
31
+ temperature: 1,
32
+ }, {
33
+ headers: {
34
+ Authorization: `Bearer ${this.config.apiKey}`,
35
+ }
36
+ });
37
+ if (apiResponse.isSuccess()) {
38
+ response = apiResponse.getBody();
39
+ }
40
+ return response;
41
+ };
42
+ }
43
+ }
44
+ exports.OpenAiNamespace = OpenAiNamespace;
@@ -0,0 +1,5 @@
1
+ import { OpenAiNamespace } from "./OpenAiNamespace";
2
+ export type OpenAiConfig = {
3
+ apiKey: string;
4
+ };
5
+ export declare const openAiClient: (key?: string, config?: OpenAiConfig, vaultId?: string, itemId?: string) => Promise<OpenAiNamespace>;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.openAiClient = void 0;
4
+ const OpenAiNamespace_1 = require("./OpenAiNamespace");
5
+ const onePassword_1 = require("../onePassword");
6
+ const openAiNamespaces = new Map();
7
+ const openAiClient = async (key = "default", config, vaultId, itemId) => {
8
+ if (openAiNamespaces.has(key)) {
9
+ return openAiNamespaces.get(key);
10
+ }
11
+ let instanceConfig;
12
+ if (config) {
13
+ instanceConfig = config;
14
+ }
15
+ else if (vaultId && itemId) {
16
+ instanceConfig = await (await (0, onePassword_1.onePasswordClient)())
17
+ .getJsonNote(vaultId, itemId);
18
+ }
19
+ else if ("default" === key && process.env.OPEN_AI_VAULT_ID && process.env.OPEN_AI_ITEM_ID) {
20
+ instanceConfig = await (await (0, onePassword_1.onePasswordClient)())
21
+ .getJsonNote(process.env.OPEN_AI_VAULT_ID, process.env.OPEN_AI_ITEM_ID);
22
+ }
23
+ else {
24
+ throw new Error(`Config required for namespace '${key}'`);
25
+ }
26
+ const namespace = new OpenAiNamespace_1.OpenAiNamespace(key, instanceConfig);
27
+ openAiNamespaces.set(key, namespace);
28
+ return namespace;
29
+ };
30
+ exports.openAiClient = openAiClient;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@8ms/helpers",
3
3
  "license": "UNLICENSED",
4
- "version": "2.0.0",
4
+ "version": "2.0.2",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/8millionstories-organisation/8ms-helpers-ts.git"
@@ -160,7 +160,7 @@
160
160
  "@types/jest": "29.5.14",
161
161
  "@types/lodash": "4.17.17",
162
162
  "@types/luxon": "3.6.2",
163
- "@types/node": "22.15.31",
163
+ "@types/node": "22.15.32",
164
164
  "@types/react": "19",
165
165
  "athena-express": "7.1.5",
166
166
  "aws-sdk": "2.1692.0",
@@ -0,0 +1,8 @@
1
+ import { PrismaConfig } from "./index";
2
+ import { BaseNamespace } from "../_class";
3
+ import type { PrismaClient } from "@prisma/client";
4
+ export declare class PrismaNamespace extends BaseNamespace {
5
+ client: PrismaClient | null;
6
+ config: PrismaConfig | null;
7
+ ensureInit: () => Promise<void>;
8
+ }
@@ -0,0 +1,79 @@
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.PrismaNamespace = void 0;
37
+ const _class_1 = require("../_class");
38
+ class PrismaNamespace extends _class_1.BaseNamespace {
39
+ constructor() {
40
+ super(...arguments);
41
+ this.client = null;
42
+ this.config = null;
43
+ // Async setup to only initialise where required
44
+ this.ensureInit = async () => {
45
+ if (!this.client) {
46
+ try {
47
+ const { PrismaClient } = await Promise.resolve().then(() => __importStar(require("@prisma/client")));
48
+ let adapter;
49
+ if (this.config.isPlanetScale) {
50
+ const { PrismaPlanetScale } = await Promise.resolve().then(() => __importStar(require("@prisma/adapter-planetscale")));
51
+ adapter = new PrismaPlanetScale({
52
+ url: this.config.url,
53
+ });
54
+ }
55
+ // Show the full query if debugging
56
+ if (this.config.isDebug) {
57
+ this.client = new PrismaClient({
58
+ adapter,
59
+ log: [
60
+ {
61
+ emit: "event",
62
+ level: "query",
63
+ },
64
+ ],
65
+ });
66
+ }
67
+ // Standard prisma
68
+ else {
69
+ this.client = new PrismaClient({ adapter });
70
+ }
71
+ }
72
+ catch (e) {
73
+ throw new Error("Prisma / PlanetScale Client not installed");
74
+ }
75
+ }
76
+ };
77
+ }
78
+ }
79
+ exports.PrismaNamespace = PrismaNamespace;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Fetch the number from a prisma decimal (comes through as an object).
3
+ */
4
+ export declare const getDecimal: (input: any, dp?: number) => number;
@@ -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.getDecimal = void 0;
7
+ const getDecimal_1 = require("../number/getDecimal");
8
+ const isArray_1 = __importDefault(require("lodash/isArray"));
9
+ /**
10
+ * Fetch the number from a prisma decimal (comes through as an object).
11
+ */
12
+ const getDecimal = (input, dp = 2) => {
13
+ let numberString = "";
14
+ // Prisma value
15
+ if ((0, isArray_1.default)(input?.d)) {
16
+ numberString = input.absoluteValue();
17
+ }
18
+ else {
19
+ numberString = input.toString();
20
+ }
21
+ return (0, getDecimal_1.getDecimal)(numberString, dp);
22
+ };
23
+ exports.getDecimal = getDecimal;
@@ -0,0 +1,8 @@
1
+ import { PrismaNamespace } from "./PrismaNamespace";
2
+ export type PrismaConfig = {
3
+ url: string;
4
+ isDebug: boolean;
5
+ isPlanetScale: boolean;
6
+ };
7
+ export declare const prismaClient: (key: string, config: PrismaConfig) => Promise<PrismaNamespace>;
8
+ export { getDecimal } from "./getDecimal";
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getDecimal = exports.prismaClient = void 0;
4
+ const PrismaNamespace_1 = require("./PrismaNamespace");
5
+ const prismaNamespaces = new Map();
6
+ // Main client that is used by system
7
+ const prismaClient = async (key = "default", config) => {
8
+ if (prismaNamespaces.has(key)) {
9
+ return prismaNamespaces.get(key);
10
+ }
11
+ if (!config) {
12
+ if (key === "default") {
13
+ config = {
14
+ url: process.env.DATABASE_URL,
15
+ isDebug: 'true' === process.env.DATABASE_IS_DEBUG,
16
+ isPlanetScale: 'true' === process.env.DATABASE_IS_PLANETSCALE,
17
+ };
18
+ }
19
+ else {
20
+ throw new Error(`Config required for namespace '${key}'`);
21
+ }
22
+ }
23
+ const namespace = new PrismaNamespace_1.PrismaNamespace(key, config);
24
+ prismaNamespaces.set(key, namespace);
25
+ return namespace;
26
+ };
27
+ exports.prismaClient = prismaClient;
28
+ var getDecimal_1 = require("./getDecimal");
29
+ Object.defineProperty(exports, "getDecimal", { enumerable: true, get: function () { return getDecimal_1.getDecimal; } });
@@ -0,0 +1,15 @@
1
+ import type { SnapchatConfig } from "./index";
2
+ import { BaseNamespace } from "../_class";
3
+ type Client = {
4
+ expires: number;
5
+ refreshToken: string;
6
+ };
7
+ export declare class SnapchatNamespace extends BaseNamespace {
8
+ client: Client | null;
9
+ config: SnapchatConfig | null;
10
+ /**
11
+ * Renew the access token as it expires every 3 hours.
12
+ */
13
+ ensureInit: () => Promise<void>;
14
+ }
15
+ export {};
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SnapchatNamespace = void 0;
4
+ const _class_1 = require("../_class");
5
+ const axios_1 = require("../axios");
6
+ const luxon_1 = require("luxon");
7
+ class SnapchatNamespace extends _class_1.BaseNamespace {
8
+ constructor() {
9
+ super(...arguments);
10
+ this.client = null;
11
+ this.config = null;
12
+ /**
13
+ * Renew the access token as it expires every 3 hours.
14
+ */
15
+ this.ensureInit = async () => {
16
+ if (!this.client) {
17
+ // Build the token request for Snapchat
18
+ const url = `https://accounts.snapchat.com/login/oauth2/access_token?client_id=${this.config.clientId}&client_secret=${this.config.clientSecret}&grant_type=refresh_token&refresh_token=${this.config.refreshToken}`;
19
+ const apiResponse = await (0, axios_1.post)(url);
20
+ if (apiResponse.isSuccess()) {
21
+ this.client = {
22
+ expires: luxon_1.DateTime.now().toUnixInteger() + (3 * 60 * 60 * 1000),
23
+ refreshToken: apiResponse.getBodyDefaultTo(["data", "access_token"], null)
24
+ };
25
+ }
26
+ }
27
+ };
28
+ }
29
+ }
30
+ exports.SnapchatNamespace = SnapchatNamespace;
@@ -0,0 +1,7 @@
1
+ import { SnapchatNamespace } from "./SnapchatNamespace";
2
+ export type SnapchatConfig = {
3
+ clientId: string;
4
+ clientSecret: string;
5
+ refreshToken: string;
6
+ };
7
+ export declare const snapchatClient: (key?: string, config?: SnapchatConfig, vaultId?: string, itemId?: string) => Promise<SnapchatNamespace>;