@8ms/helpers 1.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 (251) hide show
  1. package/dist/Class/BaseClass.d.ts +19 -0
  2. package/dist/Class/BaseClass.js +78 -0
  3. package/dist/Class/index.d.ts +3 -0
  4. package/dist/Class/index.js +8 -0
  5. package/dist/api/constants.d.ts +13 -0
  6. package/dist/api/constants.js +16 -0
  7. package/dist/api/index.d.ts +4 -0
  8. package/dist/api/index.js +7 -0
  9. package/dist/api/types.d.ts +6 -0
  10. package/dist/api/types.js +2 -0
  11. package/dist/array/getArray.d.ts +7 -0
  12. package/dist/array/getArray.js +14 -0
  13. package/dist/array/index.d.ts +3 -0
  14. package/dist/array/index.js +8 -0
  15. package/dist/atInternet/index.d.ts +3 -0
  16. package/dist/atInternet/index.js +2 -0
  17. package/dist/atInternet/types.d.ts +30 -0
  18. package/dist/atInternet/types.js +2 -0
  19. package/dist/aws/athenaExpress/getClient.d.ts +13 -0
  20. package/dist/aws/athenaExpress/getClient.js +23 -0
  21. package/dist/aws/athenaExpress/index.d.ts +4 -0
  22. package/dist/aws/athenaExpress/index.js +10 -0
  23. package/dist/aws/athenaExpress/request.d.ts +8 -0
  24. package/dist/aws/athenaExpress/request.js +54 -0
  25. package/dist/aws/glue/getClient.d.ts +10 -0
  26. package/dist/aws/glue/getClient.js +16 -0
  27. package/dist/aws/glue/index.d.ts +4 -0
  28. package/dist/aws/glue/index.js +10 -0
  29. package/dist/aws/glue/invoke.d.ts +10 -0
  30. package/dist/aws/glue/invoke.js +71 -0
  31. package/dist/aws/index.d.ts +4 -0
  32. package/dist/aws/index.js +8 -0
  33. package/dist/aws/isResponse200.d.ts +7 -0
  34. package/dist/aws/isResponse200.js +16 -0
  35. package/dist/aws/lambda/getClient.d.ts +10 -0
  36. package/dist/aws/lambda/getClient.js +16 -0
  37. package/dist/aws/lambda/index.d.ts +4 -0
  38. package/dist/aws/lambda/index.js +10 -0
  39. package/dist/aws/lambda/invoke.d.ts +20 -0
  40. package/dist/aws/lambda/invoke.js +91 -0
  41. package/dist/aws/s3/deleteDirectory.d.ts +10 -0
  42. package/dist/aws/s3/deleteDirectory.js +83 -0
  43. package/dist/aws/s3/deleteFile.d.ts +10 -0
  44. package/dist/aws/s3/deleteFile.js +61 -0
  45. package/dist/aws/s3/deleteFiles.d.ts +10 -0
  46. package/dist/aws/s3/deleteFiles.js +65 -0
  47. package/dist/aws/s3/getClient.d.ts +10 -0
  48. package/dist/aws/s3/getClient.js +16 -0
  49. package/dist/aws/s3/getPresignedPost.d.ts +21 -0
  50. package/dist/aws/s3/getPresignedPost.js +66 -0
  51. package/dist/aws/s3/getSignedUrl.d.ts +15 -0
  52. package/dist/aws/s3/getSignedUrl.js +70 -0
  53. package/dist/aws/s3/index.d.ts +15 -0
  54. package/dist/aws/s3/index.js +30 -0
  55. package/dist/aws/s3/listFiles.d.ts +10 -0
  56. package/dist/aws/s3/listFiles.js +77 -0
  57. package/dist/aws/s3/listFolders.d.ts +10 -0
  58. package/dist/aws/s3/listFolders.js +76 -0
  59. package/dist/aws/s3/readBuffer.d.ts +11 -0
  60. package/dist/aws/s3/readBuffer.js +100 -0
  61. package/dist/aws/s3/readFile.d.ts +12 -0
  62. package/dist/aws/s3/readFile.js +114 -0
  63. package/dist/aws/s3/types.d.ts +22 -0
  64. package/dist/aws/s3/types.js +2 -0
  65. package/dist/aws/s3/writeFile.d.ts +11 -0
  66. package/dist/aws/s3/writeFile.js +64 -0
  67. package/dist/aws/s3/writeGlueJsonFile.d.ts +13 -0
  68. package/dist/aws/s3/writeGlueJsonFile.js +64 -0
  69. package/dist/aws/s3/writePresignedPost.d.ts +15 -0
  70. package/dist/aws/s3/writePresignedPost.js +87 -0
  71. package/dist/aws/s3cache/getCache.d.ts +17 -0
  72. package/dist/aws/s3cache/getCache.js +62 -0
  73. package/dist/aws/s3cache/getKey.d.ts +12 -0
  74. package/dist/aws/s3cache/getKey.js +19 -0
  75. package/dist/aws/s3cache/index.d.ts +7 -0
  76. package/dist/aws/s3cache/index.js +14 -0
  77. package/dist/aws/s3cache/saveCache.d.ts +12 -0
  78. package/dist/aws/s3cache/saveCache.js +59 -0
  79. package/dist/aws/s3cache/types.d.ts +6 -0
  80. package/dist/aws/s3cache/types.js +2 -0
  81. package/dist/aws/s3cache/updateCache.d.ts +12 -0
  82. package/dist/aws/s3cache/updateCache.js +66 -0
  83. package/dist/aws/ses/SimpleEmail.d.ts +53 -0
  84. package/dist/aws/ses/SimpleEmail.js +209 -0
  85. package/dist/aws/ses/getClient.d.ts +10 -0
  86. package/dist/aws/ses/getClient.js +16 -0
  87. package/dist/aws/ses/index.d.ts +4 -0
  88. package/dist/aws/ses/index.js +10 -0
  89. package/dist/aws/ssm/getClient.d.ts +10 -0
  90. package/dist/aws/ssm/getClient.js +16 -0
  91. package/dist/aws/ssm/getParameter.d.ts +12 -0
  92. package/dist/aws/ssm/getParameter.js +85 -0
  93. package/dist/aws/ssm/index.d.ts +4 -0
  94. package/dist/aws/ssm/index.js +10 -0
  95. package/dist/aws/types.d.ts +5 -0
  96. package/dist/aws/types.js +2 -0
  97. package/dist/boolean/getBoolean.d.ts +5 -0
  98. package/dist/boolean/getBoolean.js +16 -0
  99. package/dist/boolean/index.d.ts +3 -0
  100. package/dist/boolean/index.js +8 -0
  101. package/dist/crud/constants.d.ts +6 -0
  102. package/dist/crud/constants.js +9 -0
  103. package/dist/crud/index.d.ts +4 -0
  104. package/dist/crud/index.js +5 -0
  105. package/dist/crud/types.d.ts +2 -0
  106. package/dist/crud/types.js +2 -0
  107. package/dist/crypto/getDecrypt.d.ts +11 -0
  108. package/dist/crypto/getDecrypt.js +13 -0
  109. package/dist/crypto/getEncrypt.d.ts +11 -0
  110. package/dist/crypto/getEncrypt.js +13 -0
  111. package/dist/crypto/getRandom.d.ts +7 -0
  112. package/dist/crypto/getRandom.js +12 -0
  113. package/dist/crypto/getSha256.d.ts +8 -0
  114. package/dist/crypto/getSha256.js +12 -0
  115. package/dist/crypto/index.d.ts +6 -0
  116. package/dist/crypto/index.js +14 -0
  117. package/dist/date/constants.d.ts +21 -0
  118. package/dist/date/constants.js +24 -0
  119. package/dist/date/format.d.ts +9 -0
  120. package/dist/date/format.js +15 -0
  121. package/dist/date/getDate.d.ts +8 -0
  122. package/dist/date/getDate.js +40 -0
  123. package/dist/date/getDurationHours.d.ts +8 -0
  124. package/dist/date/getDurationHours.js +28 -0
  125. package/dist/date/getDurationMinutes.d.ts +8 -0
  126. package/dist/date/getDurationMinutes.js +27 -0
  127. package/dist/date/getFinancialYear.d.ts +8 -0
  128. package/dist/date/getFinancialYear.js +48 -0
  129. package/dist/date/getFinancialYearToDate.d.ts +6 -0
  130. package/dist/date/getFinancialYearToDate.js +15 -0
  131. package/dist/date/getFinancialYearWeeks.d.ts +8 -0
  132. package/dist/date/getFinancialYearWeeks.js +26 -0
  133. package/dist/date/getLastWeek.d.ts +6 -0
  134. package/dist/date/getLastWeek.js +16 -0
  135. package/dist/date/getMax.d.ts +8 -0
  136. package/dist/date/getMax.js +19 -0
  137. package/dist/date/getMonday.d.ts +11 -0
  138. package/dist/date/getMonday.js +29 -0
  139. package/dist/date/getNumber.d.ts +8 -0
  140. package/dist/date/getNumber.js +16 -0
  141. package/dist/date/getPredefinedTimeframe.d.ts +8 -0
  142. package/dist/date/getPredefinedTimeframe.js +25 -0
  143. package/dist/date/getSunday.d.ts +11 -0
  144. package/dist/date/getSunday.js +29 -0
  145. package/dist/date/getThisWeek.d.ts +6 -0
  146. package/dist/date/getThisWeek.js +16 -0
  147. package/dist/date/getToday.d.ts +6 -0
  148. package/dist/date/getToday.js +12 -0
  149. package/dist/date/getTwoWeeksAgo.d.ts +6 -0
  150. package/dist/date/getTwoWeeksAgo.js +16 -0
  151. package/dist/date/getWeeksAgo.d.ts +6 -0
  152. package/dist/date/getWeeksAgo.js +17 -0
  153. package/dist/date/getYesterday.d.ts +5 -0
  154. package/dist/date/getYesterday.js +12 -0
  155. package/dist/date/index.d.ts +24 -0
  156. package/dist/date/index.js +51 -0
  157. package/dist/date/isDateValid.d.ts +7 -0
  158. package/dist/date/isDateValid.js +24 -0
  159. package/dist/date/isLastWeek.d.ts +6 -0
  160. package/dist/date/isLastWeek.js +15 -0
  161. package/dist/date/isThisWeek.d.ts +6 -0
  162. package/dist/date/isThisWeek.js +15 -0
  163. package/dist/date/parseExcelDate.d.ts +8 -0
  164. package/dist/date/parseExcelDate.js +20 -0
  165. package/dist/date/types.d.ts +28 -0
  166. package/dist/date/types.js +2 -0
  167. package/dist/environment/constants.d.ts +9 -0
  168. package/dist/environment/constants.js +12 -0
  169. package/dist/environment/getEnvironment.d.ts +8 -0
  170. package/dist/environment/getEnvironment.js +31 -0
  171. package/dist/environment/index.d.ts +11 -0
  172. package/dist/environment/index.js +23 -0
  173. package/dist/environment/isAws.d.ts +8 -0
  174. package/dist/environment/isAws.js +11 -0
  175. package/dist/environment/isDevelopment.d.ts +5 -0
  176. package/dist/environment/isDevelopment.js +12 -0
  177. package/dist/environment/isLocalhost.d.ts +8 -0
  178. package/dist/environment/isLocalhost.js +23 -0
  179. package/dist/environment/isProduction.d.ts +5 -0
  180. package/dist/environment/isProduction.js +12 -0
  181. package/dist/environment/isStaging.d.ts +5 -0
  182. package/dist/environment/isStaging.js +12 -0
  183. package/dist/environment/isVercel.d.ts +8 -0
  184. package/dist/environment/isVercel.js +11 -0
  185. package/dist/environment/types.d.ts +3 -0
  186. package/dist/environment/types.js +2 -0
  187. package/dist/google/getCredentials.d.ts +11 -0
  188. package/dist/google/getCredentials.js +77 -0
  189. package/dist/google/index.d.ts +4 -0
  190. package/dist/google/index.js +8 -0
  191. package/dist/google/types.d.ts +12 -0
  192. package/dist/google/types.js +2 -0
  193. package/dist/googleAds/getClient.d.ts +14 -0
  194. package/dist/googleAds/getClient.js +80 -0
  195. package/dist/googleAds/getCustomer.d.ts +8 -0
  196. package/dist/googleAds/getCustomer.js +56 -0
  197. package/dist/googleAds/index.d.ts +5 -0
  198. package/dist/googleAds/index.js +10 -0
  199. package/dist/googleAds/types.d.ts +5 -0
  200. package/dist/googleAds/types.js +2 -0
  201. package/dist/index.d.ts +26 -0
  202. package/dist/index.js +72 -0
  203. package/dist/nextAuth/constants.d.ts +5 -0
  204. package/dist/nextAuth/constants.js +8 -0
  205. package/dist/nextAuth/index.d.ts +3 -0
  206. package/dist/nextAuth/index.js +5 -0
  207. package/dist/prisma/getClient.d.ts +6 -0
  208. package/dist/prisma/getClient.js +41 -0
  209. package/dist/prisma/index.d.ts +3 -0
  210. package/dist/prisma/index.js +8 -0
  211. package/dist/string/getCleanFolder.d.ts +5 -0
  212. package/dist/string/getCleanFolder.js +12 -0
  213. package/dist/string/getStringFromStream.d.ts +6 -0
  214. package/dist/string/getStringFromStream.js +16 -0
  215. package/dist/string/index.d.ts +4 -0
  216. package/dist/string/index.js +10 -0
  217. package/dist/swr/index.d.ts +8 -0
  218. package/dist/swr/index.js +18 -0
  219. package/dist/swr/isAllData.d.ts +5 -0
  220. package/dist/swr/isAllData.js +19 -0
  221. package/dist/swr/isAnyError.d.ts +5 -0
  222. package/dist/swr/isAnyError.js +19 -0
  223. package/dist/swr/isAnyLoading.d.ts +5 -0
  224. package/dist/swr/isAnyLoading.js +21 -0
  225. package/dist/swr/isData.d.ts +5 -0
  226. package/dist/swr/isData.js +7 -0
  227. package/dist/swr/isError.d.ts +5 -0
  228. package/dist/swr/isError.js +7 -0
  229. package/dist/swr/isLoading.d.ts +5 -0
  230. package/dist/swr/isLoading.js +12 -0
  231. package/dist/url/buildParameters.d.ts +8 -0
  232. package/dist/url/buildParameters.js +23 -0
  233. package/dist/url/buildRelative.d.ts +8 -0
  234. package/dist/url/buildRelative.js +14 -0
  235. package/dist/url/buildUrl.d.ts +12 -0
  236. package/dist/url/buildUrl.js +30 -0
  237. package/dist/url/index.d.ts +8 -0
  238. package/dist/url/index.js +16 -0
  239. package/dist/url/isAbsolute.d.ts +7 -0
  240. package/dist/url/isAbsolute.js +16 -0
  241. package/dist/url/isRelative.d.ts +7 -0
  242. package/dist/url/isRelative.js +11 -0
  243. package/dist/url/types.d.ts +6 -0
  244. package/dist/url/types.js +2 -0
  245. package/dist/util/defaultTo.d.ts +5 -0
  246. package/dist/util/defaultTo.js +34 -0
  247. package/dist/util/index.d.ts +4 -0
  248. package/dist/util/index.js +10 -0
  249. package/dist/util/sleep.d.ts +4 -0
  250. package/dist/util/sleep.js +7 -0
  251. package/package.json +27 -0
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ var api_1 = require("../../api");
40
+ /**
41
+ * Get a presigned post URL so we can upload directly to S3 via frontend.
42
+ */
43
+ var writePresignedPost = function (_a) {
44
+ var bucket = _a.bucket, config = _a.config, fields = _a.fields, file = _a.file, fileName = _a.fileName, url = _a.url;
45
+ return __awaiter(void 0, void 0, void 0, function () {
46
+ return __generator(this, function (_b) {
47
+ return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(void 0, void 0, void 0, function () {
48
+ var response, formData, upload;
49
+ return __generator(this, function (_a) {
50
+ switch (_a.label) {
51
+ case 0:
52
+ response = api_1.ApiPlaceholder;
53
+ formData = new FormData();
54
+ Object.entries({ fields: fields, file: file })
55
+ .forEach(function (_a) {
56
+ var key = _a[0], value = _a[1];
57
+ // @ts-ignore
58
+ formData.append(key, value);
59
+ });
60
+ return [4 /*yield*/, fetch(url, {
61
+ method: 'POST',
62
+ body: formData,
63
+ })];
64
+ case 1:
65
+ upload = _a.sent();
66
+ // Uploaded to S3
67
+ if (upload.ok) {
68
+ response.status = api_1.ApiStatus.SUCCESS;
69
+ response.data = {
70
+ url: "https://".concat(bucket, ".s3.").concat(config.region, ".amazonaws.com/").concat(fileName),
71
+ };
72
+ resolve(response);
73
+ }
74
+ // Failed to upload to S3
75
+ else {
76
+ response.status = api_1.ApiStatus.ERROR;
77
+ response.error = 'Failed to upload file, please try again.';
78
+ reject(response);
79
+ }
80
+ return [2 /*return*/];
81
+ }
82
+ });
83
+ }); })];
84
+ });
85
+ });
86
+ };
87
+ exports.default = writePresignedPost;
@@ -0,0 +1,17 @@
1
+ import { AwsConfigType } from '../types';
2
+ /**
3
+ * Get the stored cache if it exists.
4
+ */
5
+ declare const getCache: {
6
+ ({ S3Lib, bucket, config, key, isJson }: {
7
+ S3Lib: any;
8
+ bucket: string;
9
+ config: AwsConfigType;
10
+ key: string;
11
+ isJson: boolean;
12
+ }): Promise<any>;
13
+ defaultProps: {
14
+ isJson: boolean;
15
+ };
16
+ };
17
+ export default getCache;
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ var s3_1 = require("../s3");
40
+ /**
41
+ * Get the stored cache if it exists.
42
+ */
43
+ var getCache = function (_a) {
44
+ var S3Lib = _a.S3Lib, bucket = _a.bucket, config = _a.config, key = _a.key, isJson = _a.isJson;
45
+ return __awaiter(void 0, void 0, void 0, function () {
46
+ var client;
47
+ return __generator(this, function (_b) {
48
+ switch (_b.label) {
49
+ case 0:
50
+ client = (0, s3_1.getClient)({ S3Lib: S3Lib, config: config });
51
+ return [4 /*yield*/, (0, s3_1.readFile)({ S3Lib: S3Lib, bucket: bucket, client: client, file: key, isJson: isJson })];
52
+ case 1:
53
+ _b.sent();
54
+ return [2 /*return*/];
55
+ }
56
+ });
57
+ });
58
+ };
59
+ getCache.defaultProps = {
60
+ isJson: true,
61
+ };
62
+ exports.default = getCache;
@@ -0,0 +1,12 @@
1
+ import { PlatformType } from '../../environment/types';
2
+ /**
3
+ * Take an input and return the key.
4
+ * Always in the "_cache" folder with the "environment" followed by the optional folder then the key.
5
+ */
6
+ declare const getKey: ({ CryptoLib, fileName, folder, platform }: {
7
+ CryptoLib: any;
8
+ fileName: any;
9
+ folder: string;
10
+ platform: PlatformType;
11
+ }) => string;
12
+ export default getKey;
@@ -0,0 +1,19 @@
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
+ var trimStart_1 = __importDefault(require("lodash/trimStart"));
7
+ var getSha256_1 = __importDefault(require("../../crypto/getSha256"));
8
+ var environment_1 = require("../../environment");
9
+ /**
10
+ * Take an input and return the key.
11
+ * Always in the "_cache" folder with the "environment" followed by the optional folder then the key.
12
+ */
13
+ var getKey = function (_a) {
14
+ var CryptoLib = _a.CryptoLib, fileName = _a.fileName, folder = _a.folder, platform = _a.platform;
15
+ var fileNameString = (0, getSha256_1.default)({ CryptoLib: CryptoLib, input: fileName });
16
+ var folderPath = (0, trimStart_1.default)('' === folder ? '' : "".concat(folder, "/"), '/');
17
+ return "cache/".concat((0, environment_1.getEnvironment)({ platform: platform }), "/").concat(folderPath).concat(fileNameString, ".json");
18
+ };
19
+ exports.default = getKey;
@@ -0,0 +1,7 @@
1
+ import getCache from './getCache';
2
+ import getKey from './getKey';
3
+ import saveCache from './saveCache';
4
+ import { CacheExpiresType } from './types';
5
+ import updateCache from './updateCache';
6
+ export type { CacheExpiresType, };
7
+ export { getCache, getKey, saveCache, updateCache, };
@@ -0,0 +1,14 @@
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.updateCache = exports.saveCache = exports.getKey = exports.getCache = void 0;
7
+ var getCache_1 = __importDefault(require("./getCache"));
8
+ exports.getCache = getCache_1.default;
9
+ var getKey_1 = __importDefault(require("./getKey"));
10
+ exports.getKey = getKey_1.default;
11
+ var saveCache_1 = __importDefault(require("./saveCache"));
12
+ exports.saveCache = saveCache_1.default;
13
+ var updateCache_1 = __importDefault(require("./updateCache"));
14
+ exports.updateCache = updateCache_1.default;
@@ -0,0 +1,12 @@
1
+ import { AwsConfigType } from '../types';
2
+ /**
3
+ * Save the cache.
4
+ */
5
+ declare const saveCache: ({ S3Lib, bucket, config, data, key }: {
6
+ S3Lib: any;
7
+ bucket: string;
8
+ config: AwsConfigType;
9
+ key: string;
10
+ data: any;
11
+ }) => Promise<void>;
12
+ export default saveCache;
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ var s3_1 = require("../s3");
40
+ /**
41
+ * Save the cache.
42
+ */
43
+ var saveCache = function (_a) {
44
+ var S3Lib = _a.S3Lib, bucket = _a.bucket, config = _a.config, data = _a.data, key = _a.key;
45
+ return __awaiter(void 0, void 0, void 0, function () {
46
+ var client;
47
+ return __generator(this, function (_b) {
48
+ switch (_b.label) {
49
+ case 0:
50
+ client = (0, s3_1.getClient)({ S3Lib: S3Lib, config: config });
51
+ return [4 /*yield*/, (0, s3_1.writeFile)({ S3Lib: S3Lib, bucket: bucket, client: client, file: key, content: data })];
52
+ case 1:
53
+ _b.sent();
54
+ return [2 /*return*/];
55
+ }
56
+ });
57
+ });
58
+ };
59
+ exports.default = saveCache;
@@ -0,0 +1,6 @@
1
+ import { Duration, DurationComparison } from '../../date';
2
+ export declare type CacheExpiresType = {
3
+ duration: number;
4
+ from: typeof DurationComparison.VS_MIDNIGHT | typeof DurationComparison.VS_NOW;
5
+ timeframe: typeof Duration.FOREVER | typeof Duration.MONTHS | typeof Duration.DAYS | typeof Duration.HOURS | typeof Duration.MINUTES;
6
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,12 @@
1
+ import { AwsConfigType } from '../types';
2
+ /**
3
+ * Delete other caches if present, then save the new file.
4
+ */
5
+ declare const updateCache: ({ S3Lib, bucket, config, data, key }: {
6
+ S3Lib: any;
7
+ bucket: string;
8
+ config: AwsConfigType;
9
+ data: any;
10
+ key: string;
11
+ }) => Promise<void>;
12
+ export default updateCache;
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ var __importDefault = (this && this.__importDefault) || function (mod) {
39
+ return (mod && mod.__esModule) ? mod : { "default": mod };
40
+ };
41
+ Object.defineProperty(exports, "__esModule", { value: true });
42
+ var s3_1 = require("../s3");
43
+ var saveCache_1 = __importDefault(require("./saveCache"));
44
+ /**
45
+ * Delete other caches if present, then save the new file.
46
+ */
47
+ var updateCache = function (_a) {
48
+ var S3Lib = _a.S3Lib, bucket = _a.bucket, config = _a.config, data = _a.data, key = _a.key;
49
+ return __awaiter(void 0, void 0, void 0, function () {
50
+ var client;
51
+ return __generator(this, function (_b) {
52
+ switch (_b.label) {
53
+ case 0:
54
+ client = (0, s3_1.getClient)({ S3Lib: S3Lib, config: config });
55
+ return [4 /*yield*/, (0, s3_1.deleteFile)({ S3Lib: S3Lib, bucket: bucket, client: client, file: key })];
56
+ case 1:
57
+ _b.sent();
58
+ return [4 /*yield*/, (0, saveCache_1.default)({ S3Lib: S3Lib, bucket: bucket, config: config, data: data, key: key })];
59
+ case 2:
60
+ _b.sent();
61
+ return [2 /*return*/];
62
+ }
63
+ });
64
+ });
65
+ };
66
+ exports.default = updateCache;
@@ -0,0 +1,53 @@
1
+ import { ApiResponseType } from '../../api';
2
+ import { BaseClass } from '../../Class';
3
+ /**
4
+ * Class to build and send an AWS SES email.
5
+ */
6
+ declare class SimpleEmail extends BaseClass {
7
+ from?: string;
8
+ to: string[];
9
+ cc: string[];
10
+ bcc: string[];
11
+ html?: string;
12
+ subject?: string;
13
+ constructor({ bcc, cc, from, html, subject, to }: {
14
+ bcc?: string[];
15
+ cc?: string[];
16
+ from?: string;
17
+ html?: string;
18
+ subject?: string;
19
+ to?: string | string[];
20
+ });
21
+ setFrom({ from }: {
22
+ from: string;
23
+ }): this;
24
+ setHtml({ html }: {
25
+ html: string;
26
+ }): this;
27
+ setSubject({ subject }: {
28
+ subject: string;
29
+ }): this;
30
+ pushBcc({ recipient }: {
31
+ recipient: string | string[];
32
+ }): this;
33
+ pushCc({ recipient }: {
34
+ recipient: string | string[];
35
+ }): this;
36
+ pushTo({ recipient }: {
37
+ recipient: string | string[];
38
+ }): this;
39
+ setBcc({ recipient }: {
40
+ recipient: string | string[];
41
+ }): this;
42
+ setCc({ recipient }: {
43
+ recipient: string | string[];
44
+ }): this;
45
+ setTo({ recipient }: {
46
+ recipient: string | string[];
47
+ }): this;
48
+ send({ SesLib, client }: {
49
+ SesLib: any;
50
+ client: any;
51
+ }): Promise<ApiResponseType>;
52
+ }
53
+ export default SimpleEmail;
@@ -0,0 +1,209 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __assign = (this && this.__assign) || function () {
18
+ __assign = Object.assign || function(t) {
19
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
20
+ s = arguments[i];
21
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
22
+ t[p] = s[p];
23
+ }
24
+ return t;
25
+ };
26
+ return __assign.apply(this, arguments);
27
+ };
28
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
29
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
30
+ return new (P || (P = Promise))(function (resolve, reject) {
31
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
32
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
33
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
34
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
35
+ });
36
+ };
37
+ var __generator = (this && this.__generator) || function (thisArg, body) {
38
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
39
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
40
+ function verb(n) { return function (v) { return step([n, v]); }; }
41
+ function step(op) {
42
+ if (f) throw new TypeError("Generator is already executing.");
43
+ while (_) try {
44
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
45
+ if (y = 0, t) op = [op[0] & 2, t.value];
46
+ switch (op[0]) {
47
+ case 0: case 1: t = op; break;
48
+ case 4: _.label++; return { value: op[1], done: false };
49
+ case 5: _.label++; y = op[1]; op = [0]; continue;
50
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
51
+ default:
52
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
53
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
54
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
55
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
56
+ if (t[2]) _.ops.pop();
57
+ _.trys.pop(); continue;
58
+ }
59
+ op = body.call(thisArg, _);
60
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
61
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
62
+ }
63
+ };
64
+ var __importDefault = (this && this.__importDefault) || function (mod) {
65
+ return (mod && mod.__esModule) ? mod : { "default": mod };
66
+ };
67
+ Object.defineProperty(exports, "__esModule", { value: true });
68
+ var uniq_1 = __importDefault(require("lodash/uniq"));
69
+ var api_1 = require("../../api");
70
+ var Class_1 = require("../../Class");
71
+ var isResponse200_1 = __importDefault(require("../isResponse200"));
72
+ /**
73
+ * Class to build and send an AWS SES email.
74
+ */
75
+ var SimpleEmail = /** @class */ (function (_super) {
76
+ __extends(SimpleEmail, _super);
77
+ function SimpleEmail(_a) {
78
+ var _b = _a.bcc, bcc = _b === void 0 ? undefined : _b, _c = _a.cc, cc = _c === void 0 ? undefined : _c, _d = _a.from, from = _d === void 0 ? undefined : _d, _e = _a.html, html = _e === void 0 ? undefined : _e, _f = _a.subject, subject = _f === void 0 ? undefined : _f, _g = _a.to, to = _g === void 0 ? undefined : _g;
79
+ var _this = _super.call(this) || this;
80
+ _this.from = undefined;
81
+ _this.to = [];
82
+ _this.cc = [];
83
+ _this.bcc = [];
84
+ _this.html = undefined;
85
+ _this.subject = undefined;
86
+ if (undefined !== bcc) {
87
+ _this.setBcc({ recipient: bcc });
88
+ }
89
+ if (undefined !== cc) {
90
+ _this.setCc({ recipient: cc });
91
+ }
92
+ if (undefined !== from) {
93
+ _this.setFrom({ from: from });
94
+ }
95
+ if (undefined !== html) {
96
+ _this.setHtml({ html: html });
97
+ }
98
+ if (undefined !== subject) {
99
+ _this.setSubject({ subject: subject });
100
+ }
101
+ if (undefined !== to) {
102
+ _this.setTo({ recipient: to });
103
+ }
104
+ return _this;
105
+ }
106
+ SimpleEmail.prototype.setFrom = function (_a) {
107
+ var from = _a.from;
108
+ return this._setValue(from, 'from');
109
+ };
110
+ SimpleEmail.prototype.setHtml = function (_a) {
111
+ var html = _a.html;
112
+ return this._setValue(html, 'html');
113
+ };
114
+ SimpleEmail.prototype.setSubject = function (_a) {
115
+ var subject = _a.subject;
116
+ return this._setValue(subject, 'subject');
117
+ };
118
+ SimpleEmail.prototype.pushBcc = function (_a) {
119
+ var recipient = _a.recipient;
120
+ return this._push(recipient, 'bcc');
121
+ };
122
+ SimpleEmail.prototype.pushCc = function (_a) {
123
+ var recipient = _a.recipient;
124
+ return this._push(recipient, 'cc');
125
+ };
126
+ SimpleEmail.prototype.pushTo = function (_a) {
127
+ var recipient = _a.recipient;
128
+ return this._push(recipient, 'to');
129
+ };
130
+ SimpleEmail.prototype.setBcc = function (_a) {
131
+ var recipient = _a.recipient;
132
+ return this._setArray(recipient, 'bcc');
133
+ };
134
+ SimpleEmail.prototype.setCc = function (_a) {
135
+ var recipient = _a.recipient;
136
+ return this._setArray(recipient, 'cc');
137
+ };
138
+ SimpleEmail.prototype.setTo = function (_a) {
139
+ var recipient = _a.recipient;
140
+ return this._setArray(recipient, 'to');
141
+ };
142
+ SimpleEmail.prototype.send = function (_a) {
143
+ var SesLib = _a.SesLib, client = _a.client;
144
+ return __awaiter(this, void 0, void 0, function () {
145
+ var SendEmailCommand, response, clean, params, command, apiResponse, error_1;
146
+ return __generator(this, function (_b) {
147
+ switch (_b.label) {
148
+ case 0:
149
+ SendEmailCommand = SesLib.SendEmailCommand;
150
+ response = __assign({}, api_1.ApiPlaceholder);
151
+ clean = {
152
+ bcc: (0, uniq_1.default)(this.bcc.filter(function (value) { return value !== undefined && value !== null; })),
153
+ cc: (0, uniq_1.default)(this.cc.filter(function (value) { return value !== undefined && value !== null; })),
154
+ to: (0, uniq_1.default)(this.to.filter(function (value) { return value !== undefined && value !== null; })),
155
+ };
156
+ params = {
157
+ Destination: {
158
+ BccAddresses: clean.bcc,
159
+ CcAddresses: clean.cc,
160
+ ToAddresses: clean.to,
161
+ },
162
+ Message: {
163
+ Body: {
164
+ Html: {
165
+ Charset: "UTF-8",
166
+ Data: this.html,
167
+ },
168
+ Text: {
169
+ Charset: "UTF-8",
170
+ Data: this.html,
171
+ },
172
+ },
173
+ Subject: {
174
+ Charset: "UTF-8",
175
+ Data: this.subject,
176
+ },
177
+ },
178
+ Source: this.from,
179
+ };
180
+ _b.label = 1;
181
+ case 1:
182
+ _b.trys.push([1, 3, , 4]);
183
+ command = new SendEmailCommand(params);
184
+ return [4 /*yield*/, client.send(command)];
185
+ case 2:
186
+ apiResponse = _b.sent();
187
+ if ((0, isResponse200_1.default)({ apiResponse: apiResponse })) {
188
+ response.status = api_1.ApiStatus.SUCCESS;
189
+ }
190
+ else {
191
+ response.status = api_1.ApiStatus.ERROR;
192
+ // @ts-ignore
193
+ response.error = "An unexpected error occurred.";
194
+ }
195
+ return [3 /*break*/, 4];
196
+ case 3:
197
+ error_1 = _b.sent();
198
+ response.status = api_1.ApiStatus.ERROR;
199
+ // @ts-ignore
200
+ response.error = error_1.message;
201
+ return [3 /*break*/, 4];
202
+ case 4: return [2 /*return*/, response];
203
+ }
204
+ });
205
+ });
206
+ };
207
+ return SimpleEmail;
208
+ }(Class_1.BaseClass));
209
+ exports.default = SimpleEmail;