@8ms/helpers 1.0.21 → 1.1.0

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 (174) hide show
  1. package/dist/api/index.d.ts +5 -4
  2. package/dist/api/index.js +7 -5
  3. package/dist/api/response.d.ts +7 -0
  4. package/dist/api/response.js +9 -0
  5. package/dist/api/states.d.ts +8 -0
  6. package/dist/api/states.js +10 -0
  7. package/dist/api/unexpectedError.d.ts +1 -0
  8. package/dist/api/unexpectedError.js +4 -0
  9. package/dist/array/tests/contains.test.d.ts +1 -0
  10. package/dist/array/tests/contains.test.js +18 -0
  11. package/dist/aws/athenaExpress/getClient.d.ts +2 -2
  12. package/dist/aws/{types.d.ts → config.d.ts} +1 -1
  13. package/dist/{api/types.js → aws/config.js} +0 -0
  14. package/dist/aws/getConfig.d.ts +2 -2
  15. package/dist/aws/glue/getClient.d.ts +2 -2
  16. package/dist/aws/index.d.ts +2 -2
  17. package/dist/aws/lambda/getClient.d.ts +2 -2
  18. package/dist/aws/s3/deleteDirectory.js +1 -1
  19. package/dist/aws/s3/getClient.d.ts +2 -2
  20. package/dist/aws/s3/getSignedUrl.d.ts +2 -2
  21. package/dist/aws/s3/getSignedUrl.js +17 -6
  22. package/dist/aws/s3/listFiles.js +1 -1
  23. package/dist/aws/s3/listFolders.js +1 -1
  24. package/dist/aws/s3/readFile.js +1 -1
  25. package/dist/aws/s3/writePresignedPost.d.ts +4 -4
  26. package/dist/aws/s3/writePresignedPost.js +14 -3
  27. package/dist/aws/s3cache/cache.d.ts +6 -0
  28. package/dist/aws/s3cache/{types.js → cache.js} +0 -0
  29. package/dist/aws/s3cache/getCache.d.ts +2 -2
  30. package/dist/aws/s3cache/getKey.d.ts +2 -2
  31. package/dist/aws/s3cache/index.d.ts +2 -2
  32. package/dist/aws/s3cache/saveCache.d.ts +2 -2
  33. package/dist/aws/s3cache/updateCache.d.ts +2 -2
  34. package/dist/aws/ses/SimpleEmail.d.ts +3 -2
  35. package/dist/aws/ses/SimpleEmail.js +23 -15
  36. package/dist/aws/ses/getClient.d.ts +2 -2
  37. package/dist/aws/ssm/getClient.d.ts +2 -2
  38. package/dist/axios/get.d.ts +6 -1
  39. package/dist/axios/get.js +1 -1
  40. package/dist/axios/index.d.ts +2 -3
  41. package/dist/axios/post.d.ts +7 -1
  42. package/dist/axios/post.js +1 -1
  43. package/dist/crud/index.d.ts +3 -4
  44. package/dist/crud/index.js +3 -3
  45. package/dist/crud/states.d.ts +7 -0
  46. package/dist/crud/{constants.js → states.js} +2 -2
  47. package/dist/date/date.d.ts +4 -0
  48. package/dist/{aws/types.js → date/date.js} +0 -0
  49. package/dist/date/duration.d.ts +5 -0
  50. package/dist/{axios/types.js → date/duration.js} +0 -0
  51. package/dist/date/durationComparisons.d.ts +4 -0
  52. package/dist/date/durationComparisons.js +7 -0
  53. package/dist/date/durations.d.ts +7 -0
  54. package/dist/date/durations.js +10 -0
  55. package/dist/date/financialYear.d.ts +4 -0
  56. package/dist/{crud/types.js → date/financialYear.js} +0 -0
  57. package/dist/date/financialYearWeek.d.ts +6 -0
  58. package/dist/date/{types.js → financialYearWeek.js} +0 -0
  59. package/dist/date/format.d.ts +1 -1
  60. package/dist/date/getDate.d.ts +1 -1
  61. package/dist/date/getFinancialYear.d.ts +1 -1
  62. package/dist/date/getFinancialYearToDate.d.ts +1 -1
  63. package/dist/date/getFinancialYearWeeks.d.ts +1 -1
  64. package/dist/date/getLastWeek.d.ts +1 -1
  65. package/dist/date/getMax.d.ts +1 -1
  66. package/dist/date/getMin.d.ts +1 -1
  67. package/dist/date/getMonday.d.ts +1 -1
  68. package/dist/date/getNumber.d.ts +1 -1
  69. package/dist/date/getPredefinedTimeframe.d.ts +3 -2
  70. package/dist/date/getPredefinedTimeframe.js +4 -4
  71. package/dist/date/getSunday.d.ts +1 -1
  72. package/dist/date/getThisWeek.d.ts +1 -1
  73. package/dist/date/getTwoWeeksAgo.d.ts +1 -1
  74. package/dist/date/getWeeksAgo.d.ts +1 -1
  75. package/dist/date/index.d.ts +11 -4
  76. package/dist/date/index.js +9 -6
  77. package/dist/date/isLastWeek.d.ts +1 -1
  78. package/dist/date/isThisWeek.d.ts +1 -1
  79. package/dist/date/predefinedTimeframes.d.ts +7 -0
  80. package/dist/date/predefinedTimeframes.js +9 -0
  81. package/dist/date/timeframe.d.ts +8 -0
  82. package/dist/{environment/types.js → date/timeframe.js} +0 -0
  83. package/dist/date/timeframes.d.ts +4 -0
  84. package/dist/date/timeframes.js +7 -0
  85. package/dist/environment/environments.d.ts +6 -0
  86. package/dist/environment/{constants.js → environments.js} +2 -6
  87. package/dist/environment/getEnvironment.d.ts +4 -3
  88. package/dist/environment/getEnvironment.js +4 -4
  89. package/dist/environment/index.d.ts +4 -4
  90. package/dist/environment/index.js +5 -4
  91. package/dist/environment/isAws.d.ts +2 -2
  92. package/dist/environment/isAws.js +2 -2
  93. package/dist/environment/isDevelopment.d.ts +2 -2
  94. package/dist/environment/isDevelopment.js +2 -2
  95. package/dist/environment/isLocalhost.d.ts +2 -2
  96. package/dist/environment/isProduction.d.ts +2 -2
  97. package/dist/environment/isProduction.js +2 -2
  98. package/dist/environment/isStaging.d.ts +2 -2
  99. package/dist/environment/isStaging.js +2 -2
  100. package/dist/environment/isVercel.d.ts +2 -2
  101. package/dist/environment/isVercel.js +2 -2
  102. package/dist/environment/platforms.d.ts +5 -0
  103. package/dist/environment/platforms.js +7 -0
  104. package/dist/eskimi/accessToken.d.ts +9 -0
  105. package/dist/eskimi/{types.js → accessToken.js} +0 -0
  106. package/dist/eskimi/ageGroups.d.ts +4 -0
  107. package/dist/eskimi/ageGroups.js +41 -0
  108. package/dist/eskimi/{types.d.ts → campaign.d.ts} +0 -0
  109. package/dist/{google/types.js → eskimi/campaign.js} +0 -0
  110. package/dist/eskimi/devices.d.ts +4 -0
  111. package/dist/eskimi/devices.js +13 -0
  112. package/dist/eskimi/{constants.d.ts → endpoints.d.ts} +1 -13
  113. package/dist/eskimi/endpoints.js +18 -0
  114. package/dist/eskimi/genders.d.ts +4 -0
  115. package/dist/eskimi/genders.js +13 -0
  116. package/dist/eskimi/getAccessToken.d.ts +1 -9
  117. package/dist/eskimi/getAgeGroup.js +2 -2
  118. package/dist/eskimi/getDevice.js +2 -2
  119. package/dist/eskimi/getGender.js +2 -2
  120. package/dist/eskimi/index.d.ts +8 -4
  121. package/dist/eskimi/index.js +9 -6
  122. package/dist/google/getCredentials.d.ts +18 -1
  123. package/dist/google/index.d.ts +2 -3
  124. package/dist/google/sheets/getAuth.d.ts +1 -1
  125. package/dist/google/sheets/getAuth.js +5 -2
  126. package/dist/googleAds/{types.d.ts → client.d.ts} +0 -0
  127. package/dist/googleAds/{types.js → client.js} +0 -0
  128. package/dist/googleAds/getClient.d.ts +3 -3
  129. package/dist/googleAds/index.d.ts +1 -1
  130. package/dist/myTarget/getAccessToken.d.ts +2 -2
  131. package/dist/nextAuth/{constants.d.ts → authStates.d.ts} +1 -1
  132. package/dist/nextAuth/{constants.js → authStates.js} +2 -2
  133. package/dist/nextAuth/index.d.ts +2 -2
  134. package/dist/nextAuth/index.js +3 -3
  135. package/dist/number/getNumber.d.ts +1 -1
  136. package/dist/number/getNumber.js +15 -4
  137. package/dist/number/tests/getNumber.test.d.ts +1 -0
  138. package/dist/number/tests/getNumber.test.js +21 -0
  139. package/dist/snapchat/getAccessToken.d.ts +2 -2
  140. package/dist/string/getCleanFolder.d.ts +3 -1
  141. package/dist/string/getCleanFolder.js +5 -2
  142. package/dist/string/getStringFromStream.d.ts +3 -1
  143. package/dist/string/getStringFromStream.js +2 -1
  144. package/dist/string/tests/getCleanFolder.test.js +1 -1
  145. package/dist/url/buildUrl.d.ts +3 -3
  146. package/dist/url/index.d.ts +1 -1
  147. package/dist/url/{types.d.ts → url.d.ts} +0 -0
  148. package/dist/url/{types.js → url.js} +0 -0
  149. package/dist/util/defaultTo.d.ts +3 -0
  150. package/dist/util/defaultTo.js +1 -1
  151. package/dist/util/tests/defaultTo.test.d.ts +1 -0
  152. package/dist/util/tests/defaultTo.test.js +27 -0
  153. package/dist/webWorker/index.d.ts +3 -4
  154. package/dist/webWorker/index.js +3 -3
  155. package/dist/webWorker/states.d.ts +6 -0
  156. package/dist/webWorker/{constant.js → states.js} +2 -2
  157. package/package.json +2 -2
  158. package/dist/api/constants.d.ts +0 -10
  159. package/dist/api/constants.js +0 -16
  160. package/dist/api/types.d.ts +0 -7
  161. package/dist/aws/s3cache/types.d.ts +0 -6
  162. package/dist/axios/types.d.ts +0 -13
  163. package/dist/crud/constants.d.ts +0 -6
  164. package/dist/crud/types.d.ts +0 -2
  165. package/dist/date/constants.d.ts +0 -21
  166. package/dist/date/constants.js +0 -24
  167. package/dist/date/types.d.ts +0 -28
  168. package/dist/environment/constants.d.ts +0 -9
  169. package/dist/environment/types.d.ts +0 -3
  170. package/dist/eskimi/constants.js +0 -76
  171. package/dist/google/types.d.ts +0 -18
  172. package/dist/webWorker/constant.d.ts +0 -5
  173. package/dist/webWorker/types.d.ts +0 -2
  174. package/dist/webWorker/types.js +0 -2
@@ -1,4 +1,5 @@
1
- import { ApiPlaceholder, ApiStatus, UnexpectedError } from './constants';
2
- import { ApiResponseType } from './types';
3
- export type { ApiResponseType, };
4
- export { ApiPlaceholder, ApiStatus, UnexpectedError, };
1
+ import { response, ResponseType } from './response';
2
+ import { states, StateType } from './states';
3
+ import { unexpectedError } from './unexpectedError';
4
+ export type { ResponseType, StateType, };
5
+ export { response, states, unexpectedError, };
package/dist/api/index.js CHANGED
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.UnexpectedError = exports.ApiStatus = exports.ApiPlaceholder = void 0;
4
- var constants_1 = require("./constants");
5
- Object.defineProperty(exports, "ApiPlaceholder", { enumerable: true, get: function () { return constants_1.ApiPlaceholder; } });
6
- Object.defineProperty(exports, "ApiStatus", { enumerable: true, get: function () { return constants_1.ApiStatus; } });
7
- Object.defineProperty(exports, "UnexpectedError", { enumerable: true, get: function () { return constants_1.UnexpectedError; } });
3
+ exports.unexpectedError = exports.states = exports.response = void 0;
4
+ var response_1 = require("./response");
5
+ Object.defineProperty(exports, "response", { enumerable: true, get: function () { return response_1.response; } });
6
+ var states_1 = require("./states");
7
+ Object.defineProperty(exports, "states", { enumerable: true, get: function () { return states_1.states; } });
8
+ var unexpectedError_1 = require("./unexpectedError");
9
+ Object.defineProperty(exports, "unexpectedError", { enumerable: true, get: function () { return unexpectedError_1.unexpectedError; } });
@@ -0,0 +1,7 @@
1
+ import { StateType } from './states';
2
+ export declare type ResponseType = {
3
+ body: any | null;
4
+ error: string | null;
5
+ status: StateType;
6
+ };
7
+ export declare const response: ResponseType;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.response = void 0;
4
+ var states_1 = require("./states");
5
+ exports.response = {
6
+ body: null,
7
+ error: null,
8
+ status: states_1.states.IDLE,
9
+ };
@@ -0,0 +1,8 @@
1
+ export declare const states: {
2
+ ERROR: string;
3
+ IDLE: string;
4
+ PENDING: string;
5
+ SUCCESS: string;
6
+ VALIDATION_ERROR: string;
7
+ };
8
+ export declare type StateType = typeof states.ERROR | typeof states.IDLE | typeof states.PENDING | typeof states.SUCCESS | typeof states.VALIDATION_ERROR;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.states = void 0;
4
+ exports.states = {
5
+ ERROR: 'error',
6
+ IDLE: 'idle',
7
+ PENDING: 'pending',
8
+ SUCCESS: 'success',
9
+ VALIDATION_ERROR: 'validationError',
10
+ };
@@ -0,0 +1 @@
1
+ export declare const unexpectedError: string;
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.unexpectedError = void 0;
4
+ exports.unexpectedError = 'An unexpected error occurred, please try again.';
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var index_1 = require("../index");
4
+ test('contains - does contain', function () {
5
+ var haystack = [1, 2, 3, 4];
6
+ expect((0, index_1.contains)({ haystack: haystack, needle: 1 }))
7
+ .toBeTruthy();
8
+ expect((0, index_1.contains)({ haystack: haystack, needle: 2 }))
9
+ .toBeTruthy();
10
+ expect((0, index_1.contains)({ haystack: haystack, needle: 3 }))
11
+ .toBeTruthy();
12
+ expect((0, index_1.contains)({ haystack: haystack, needle: 4 }))
13
+ .toBeTruthy();
14
+ });
15
+ test('contains - does not contain', function () {
16
+ expect((0, index_1.contains)({ haystack: [1, 2, 3, 4], needle: 9 }))
17
+ .toBeFalsy();
18
+ });
@@ -1,9 +1,9 @@
1
- import { AwsConfigType } from '../types';
1
+ import { ConfigType } from '../config';
2
2
  declare type GetClientType = {
3
3
  AthenaExpress: any;
4
4
  AwsSdk: any;
5
5
  athenaS3: string;
6
- config: AwsConfigType;
6
+ config: ConfigType;
7
7
  database: string;
8
8
  };
9
9
  /**
@@ -1,4 +1,4 @@
1
- export declare type AwsConfigType = {
1
+ export declare type ConfigType = {
2
2
  accessKeyId: string;
3
3
  region: string;
4
4
  secretAccessKey: string;
File without changes
@@ -1,9 +1,9 @@
1
- import { AwsConfigType } from './types';
1
+ import { ConfigType } from './config';
2
2
  /**
3
3
  * The config must be in a specific structure, if the properties aren't defined don't specify them as they could be inferred (e.g. Lambda).
4
4
  */
5
5
  declare const getConfig: ({ config, isAthenaExpress }: {
6
- config: AwsConfigType;
6
+ config: ConfigType;
7
7
  isAthenaExpress: boolean;
8
8
  }) => object;
9
9
  export default getConfig;
@@ -1,10 +1,10 @@
1
- import { AwsConfigType } from '../types';
1
+ import { ConfigType } from '../config';
2
2
  /**
3
3
  * Shorthand function to get the Glue Client.
4
4
  * Library: @aws-sdk/client-glue
5
5
  */
6
6
  declare const getClient: ({ GlueLib, config }: {
7
7
  GlueLib: any;
8
- config: AwsConfigType;
8
+ config: ConfigType;
9
9
  }) => any;
10
10
  export default getClient;
@@ -1,4 +1,4 @@
1
1
  import isResponse200 from './isResponse200';
2
- import { AwsConfigType } from './types';
3
- export type { AwsConfigType, };
2
+ import { ConfigType } from './config';
3
+ export type { ConfigType, };
4
4
  export { isResponse200, };
@@ -1,10 +1,10 @@
1
- import { AwsConfigType } from '../types';
1
+ import { ConfigType } from '../config';
2
2
  /**
3
3
  * Shorthand function to get the Lambda Client.
4
4
  * Library: @aws-sdk/client-lambda
5
5
  */
6
6
  declare const getClient: ({ LambdaLib, config }: {
7
7
  LambdaLib: any;
8
- config: AwsConfigType;
8
+ config: ConfigType;
9
9
  }) => any;
10
10
  export default getClient;
@@ -47,7 +47,7 @@ var deleteDirectory = function (_a) {
47
47
  return __generator(this, function (_b) {
48
48
  switch (_b.label) {
49
49
  case 0:
50
- cleanFolder = (0, string_1.getCleanFolder)(folder);
50
+ cleanFolder = (0, string_1.getCleanFolder)({ input: folder });
51
51
  ListObjectsV2Command = S3Lib.ListObjectsV2Command, DeleteObjectsCommand = S3Lib.DeleteObjectsCommand;
52
52
  return [4 /*yield*/, client.send(new ListObjectsV2Command({
53
53
  Bucket: bucket,
@@ -1,10 +1,10 @@
1
- import { AwsConfigType } from '../types';
1
+ import { ConfigType } from '../config';
2
2
  /**
3
3
  * Shorthand function to get the S3 Client.
4
4
  * Library: @aws-sdk/client-s3
5
5
  */
6
6
  declare const getClient: ({ S3Lib, config }: {
7
7
  S3Lib: any;
8
- config: AwsConfigType;
8
+ config: ConfigType;
9
9
  }) => any;
10
10
  export default getClient;
@@ -1,4 +1,4 @@
1
- import { ApiResponseType } from '../../api';
1
+ import { ResponseType } from '../../api';
2
2
  declare type GetSignedUrlType = {
3
3
  S3Lib: any;
4
4
  S3PresignerLib: any;
@@ -11,5 +11,5 @@ declare type GetSignedUrlType = {
11
11
  * Returns a signed for URL to allow download of private buckets for a given duration.
12
12
  * Library: @aws-sdk/s3-request-presigner
13
13
  */
14
- declare const getSignedUrl: ({ S3Lib, S3PresignerLib, bucket, client, expires, file }: GetSignedUrlType) => Promise<ApiResponseType>;
14
+ declare const getSignedUrl: ({ S3Lib, S3PresignerLib, bucket, client, expires, file }: GetSignedUrlType) => Promise<ResponseType>;
15
15
  export default getSignedUrl;
@@ -1,4 +1,15 @@
1
1
  "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
2
13
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
14
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
15
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -44,11 +55,11 @@ var api_1 = require("../../api");
44
55
  var getSignedUrl = function (_a) {
45
56
  var S3Lib = _a.S3Lib, S3PresignerLib = _a.S3PresignerLib, bucket = _a.bucket, client = _a.client, expires = _a.expires, file = _a.file;
46
57
  return __awaiter(void 0, void 0, void 0, function () {
47
- var response, GetObjectCommand, getSignedUrl, command, apiResponse;
58
+ var response, GetObjectCommand, getSignedUrl, command, awsResponse;
48
59
  return __generator(this, function (_b) {
49
60
  switch (_b.label) {
50
61
  case 0:
51
- response = api_1.ApiPlaceholder;
62
+ response = __assign({}, api_1.response);
52
63
  GetObjectCommand = S3Lib.GetObjectCommand;
53
64
  getSignedUrl = S3PresignerLib.getSignedUrl;
54
65
  command = new GetObjectCommand({
@@ -57,10 +68,10 @@ var getSignedUrl = function (_a) {
57
68
  });
58
69
  return [4 /*yield*/, getSignedUrl(client, command, { expiresIn: expires })];
59
70
  case 1:
60
- apiResponse = _b.sent();
61
- if (apiResponse && 'string' === typeof apiResponse) {
62
- response.status = api_1.ApiStatus.SUCCESS;
63
- response.body = apiResponse;
71
+ awsResponse = _b.sent();
72
+ if (awsResponse && 'string' === typeof awsResponse) {
73
+ response.status = api_1.states.SUCCESS;
74
+ response.body = awsResponse;
64
75
  }
65
76
  return [2 /*return*/, response];
66
77
  }
@@ -47,7 +47,7 @@ var listFiles = function (_a) {
47
47
  return __generator(this, function (_c) {
48
48
  switch (_c.label) {
49
49
  case 0:
50
- cleanFolder = (0, string_1.getCleanFolder)(folder);
50
+ cleanFolder = (0, string_1.getCleanFolder)({ input: folder });
51
51
  response = [];
52
52
  valid = [];
53
53
  ListObjectsV2Command = S3Lib.ListObjectsV2Command;
@@ -47,7 +47,7 @@ var listFolders = function (_a) {
47
47
  return __generator(this, function (_c) {
48
48
  switch (_c.label) {
49
49
  case 0:
50
- cleanFolder = (0, string_1.getCleanFolder)(folder);
50
+ cleanFolder = (0, string_1.getCleanFolder)({ input: folder });
51
51
  response = [];
52
52
  ListObjectsV2Command = S3Lib.ListObjectsV2Command;
53
53
  return [4 /*yield*/, client.send(new ListObjectsV2Command({
@@ -97,7 +97,7 @@ var readFile = function (_a) {
97
97
  response.modified.vsMidnight.minutes = (0, getMinutes_1.default)(now);
98
98
  // Convert stream into a string
99
99
  _b = response;
100
- return [4 /*yield*/, (0, string_1.getStringFromStream)(apiResponse.Body)];
100
+ return [4 /*yield*/, (0, string_1.getStringFromStream)({ stream: apiResponse.Body })];
101
101
  case 2:
102
102
  // Convert stream into a string
103
103
  _b.body = _c.sent();
@@ -1,8 +1,8 @@
1
- import { ApiResponseType } from '../../api';
2
- import { AwsConfigType } from '../types';
1
+ import { ResponseType } from '../../api';
2
+ import { ConfigType } from '../config';
3
3
  declare type WritePresignedPostType = {
4
4
  bucket: string;
5
- config: AwsConfigType;
5
+ config: ConfigType;
6
6
  fields: any;
7
7
  file: any;
8
8
  fileName: string;
@@ -11,5 +11,5 @@ declare type WritePresignedPostType = {
11
11
  /**
12
12
  * Get a presigned post URL so we can upload directly to S3 via frontend.
13
13
  */
14
- declare const writePresignedPost: ({ bucket, config, fields, file, fileName, url }: WritePresignedPostType) => Promise<ApiResponseType>;
14
+ declare const writePresignedPost: ({ bucket, config, fields, file, fileName, url }: WritePresignedPostType) => Promise<ResponseType>;
15
15
  export default writePresignedPost;
@@ -1,4 +1,15 @@
1
1
  "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
2
13
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
14
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
15
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -49,7 +60,7 @@ var writePresignedPost = function (_a) {
49
60
  return __generator(this, function (_a) {
50
61
  switch (_a.label) {
51
62
  case 0:
52
- response = api_1.ApiPlaceholder;
63
+ response = __assign({}, api_1.response);
53
64
  formData = new FormData();
54
65
  Object.entries({ fields: fields, file: file })
55
66
  .forEach(function (_a) {
@@ -65,7 +76,7 @@ var writePresignedPost = function (_a) {
65
76
  upload = _a.sent();
66
77
  // Uploaded to S3
67
78
  if (upload.ok) {
68
- response.status = api_1.ApiStatus.SUCCESS;
79
+ response.status = api_1.states.SUCCESS;
69
80
  response.body = {
70
81
  url: "https://".concat(bucket, ".s3.").concat(config.region, ".amazonaws.com/").concat(fileName),
71
82
  };
@@ -73,7 +84,7 @@ var writePresignedPost = function (_a) {
73
84
  }
74
85
  // Failed to upload to S3
75
86
  else {
76
- response.status = api_1.ApiStatus.ERROR;
87
+ response.status = api_1.states.ERROR;
77
88
  response.error = 'Failed to upload file, please try again.';
78
89
  reject(response);
79
90
  }
@@ -0,0 +1,6 @@
1
+ import { durationComparisons, durations } from '../../date';
2
+ export declare type CacheType = {
3
+ duration: number;
4
+ from: typeof durationComparisons.VS_MIDNIGHT | typeof durationComparisons.VS_NOW;
5
+ timeframe: typeof durations.FOREVER | typeof durations.MONTHS | typeof durations.DAYS | typeof durations.HOURS | typeof durations.MINUTES;
6
+ };
File without changes
@@ -1,4 +1,4 @@
1
- import { AwsConfigType } from '../types';
1
+ import { ConfigType } from '../config';
2
2
  /**
3
3
  * Get the stored cache if it exists.
4
4
  */
@@ -6,7 +6,7 @@ declare const getCache: {
6
6
  ({ S3Lib, bucket, config, key, isJson }: {
7
7
  S3Lib: any;
8
8
  bucket: string;
9
- config: AwsConfigType;
9
+ config: ConfigType;
10
10
  key: string;
11
11
  isJson: boolean;
12
12
  }): Promise<any>;
@@ -1,4 +1,4 @@
1
- import { PlatformType } from '../../environment/types';
1
+ import { PlatformsType } from '../../environment/platforms';
2
2
  /**
3
3
  * Take an input and return the key.
4
4
  * Always in the "_cache" folder with the "environment" followed by the optional folder then the key.
@@ -7,6 +7,6 @@ declare const getKey: ({ CryptoLib, fileName, folder, platform }: {
7
7
  CryptoLib: any;
8
8
  fileName: any;
9
9
  folder: string;
10
- platform: PlatformType;
10
+ platform: PlatformsType;
11
11
  }) => string;
12
12
  export default getKey;
@@ -1,7 +1,7 @@
1
1
  import getCache from './getCache';
2
2
  import getKey from './getKey';
3
3
  import saveCache from './saveCache';
4
- import { CacheExpiresType } from './types';
4
+ import { CacheType } from './cache';
5
5
  import updateCache from './updateCache';
6
- export type { CacheExpiresType, };
6
+ export type { CacheType, };
7
7
  export { getCache, getKey, saveCache, updateCache, };
@@ -1,11 +1,11 @@
1
- import { AwsConfigType } from '../types';
1
+ import { ConfigType } from '../config';
2
2
  /**
3
3
  * Save the cache.
4
4
  */
5
5
  declare const saveCache: ({ S3Lib, bucket, config, data, key }: {
6
6
  S3Lib: any;
7
7
  bucket: string;
8
- config: AwsConfigType;
8
+ config: ConfigType;
9
9
  key: string;
10
10
  data: any;
11
11
  }) => Promise<void>;
@@ -1,11 +1,11 @@
1
- import { AwsConfigType } from '../types';
1
+ import { ConfigType } from '../config';
2
2
  /**
3
3
  * Delete other caches if present, then save the new file.
4
4
  */
5
5
  declare const updateCache: ({ S3Lib, bucket, config, data, key }: {
6
6
  S3Lib: any;
7
7
  bucket: string;
8
- config: AwsConfigType;
8
+ config: ConfigType;
9
9
  data: any;
10
10
  key: string;
11
11
  }) => Promise<void>;
@@ -1,4 +1,4 @@
1
- import { ApiResponseType } from '../../api';
1
+ import { ResponseType } from '../../api';
2
2
  import { BaseClass } from '../../Class';
3
3
  /**
4
4
  * Class to build and send an AWS SES email.
@@ -48,6 +48,7 @@ declare class SimpleEmail extends BaseClass {
48
48
  send({ SesLib, client }: {
49
49
  SesLib: any;
50
50
  client: any;
51
- }): Promise<ApiResponseType>;
51
+ }): Promise<ResponseType>;
52
+ private _filterRecipients;
52
53
  }
53
54
  export default SimpleEmail;
@@ -142,22 +142,17 @@ var SimpleEmail = /** @class */ (function (_super) {
142
142
  SimpleEmail.prototype.send = function (_a) {
143
143
  var SesLib = _a.SesLib, client = _a.client;
144
144
  return __awaiter(this, void 0, void 0, function () {
145
- var SendEmailCommand, response, clean, params, command, apiResponse, error_1;
145
+ var SendEmailCommand, response, params, command, apiResponse_1, error_1;
146
146
  return __generator(this, function (_b) {
147
147
  switch (_b.label) {
148
148
  case 0:
149
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
- };
150
+ response = __assign({}, api_1.response);
156
151
  params = {
157
152
  Destination: {
158
- BccAddresses: clean.bcc,
159
- CcAddresses: clean.cc,
160
- ToAddresses: clean.to,
153
+ BccAddresses: this._filterRecipients({ field: 'bcc' }),
154
+ CcAddresses: this._filterRecipients({ field: 'cc' }),
155
+ ToAddresses: this._filterRecipients({ field: 'to' }),
161
156
  },
162
157
  Message: {
163
158
  Body: {
@@ -183,19 +178,19 @@ var SimpleEmail = /** @class */ (function (_super) {
183
178
  command = new SendEmailCommand(params);
184
179
  return [4 /*yield*/, client.send(command)];
185
180
  case 2:
186
- apiResponse = _b.sent();
187
- if ((0, isResponse200_1.default)({ apiResponse: apiResponse })) {
188
- response.status = api_1.ApiStatus.SUCCESS;
181
+ apiResponse_1 = _b.sent();
182
+ if ((0, isResponse200_1.default)({ apiResponse: apiResponse_1 })) {
183
+ response.status = api_1.states.SUCCESS;
189
184
  }
190
185
  else {
191
- response.status = api_1.ApiStatus.ERROR;
186
+ response.status = api_1.states.ERROR;
192
187
  // @ts-ignore
193
188
  response.error = "An unexpected error occurred.";
194
189
  }
195
190
  return [3 /*break*/, 4];
196
191
  case 3:
197
192
  error_1 = _b.sent();
198
- response.status = api_1.ApiStatus.ERROR;
193
+ response.status = api_1.states.ERROR;
199
194
  // @ts-ignore
200
195
  response.error = error_1.message;
201
196
  return [3 /*break*/, 4];
@@ -204,6 +199,19 @@ var SimpleEmail = /** @class */ (function (_super) {
204
199
  });
205
200
  });
206
201
  };
202
+ SimpleEmail.prototype._filterRecipients = function (_a) {
203
+ var field = _a.field;
204
+ // Remove all undefined and null values
205
+ var response = this[field].filter(function (recipient) { return undefined !== recipient && null !== recipient; });
206
+ // Clean all the values
207
+ response = response.map(function (recipient) { return recipient.toLowerCase()
208
+ .trim(); });
209
+ // Remove all empty values
210
+ response = response.filter(function (recipient) { return '' !== recipient; });
211
+ // Return only unique values
212
+ response = (0, uniq_1.default)(response);
213
+ return response;
214
+ };
207
215
  return SimpleEmail;
208
216
  }(Class_1.BaseClass));
209
217
  exports.default = SimpleEmail;
@@ -1,10 +1,10 @@
1
- import { AwsConfigType } from '../types';
1
+ import { ConfigType } from '../config';
2
2
  /**
3
3
  * Shorthand function to get the SES Client.
4
4
  * Library: @aws-sdk/client-ses
5
5
  */
6
6
  declare const getClient: ({ SesLib, config }: {
7
7
  SesLib: any;
8
- config: AwsConfigType;
8
+ config: ConfigType;
9
9
  }) => any;
10
10
  export default getClient;
@@ -1,10 +1,10 @@
1
- import { AwsConfigType } from '../types';
1
+ import { ConfigType } from '../config';
2
2
  /**
3
3
  * Shorthand function to get the Lambda Client.
4
4
  * Library: @aws-sdk/client-ssm
5
5
  */
6
6
  declare const getClient: ({ SsmLib, config }: {
7
7
  SsmLib: any;
8
- config: AwsConfigType;
8
+ config: ConfigType;
9
9
  }) => any;
10
10
  export default getClient;
@@ -1,3 +1,8 @@
1
- import { GetType } from './types';
1
+ export declare type GetType = {
2
+ config?: object;
3
+ onError?: Function;
4
+ onSuccess?: Function;
5
+ url: string;
6
+ };
2
7
  declare const get: ({ config, onError, onSuccess, url }: GetType) => Promise<any>;
3
8
  export default get;
package/dist/axios/get.js CHANGED
@@ -55,7 +55,7 @@ var get = function (_a) {
55
55
  case 0:
56
56
  if (!(200 === response.status)) return [3 /*break*/, 12];
57
57
  if (!(undefined !== response.data.body && undefined !== response.data.error && undefined !== response.data.status)) return [3 /*break*/, 8];
58
- if (!(api_1.ApiStatus.SUCCESS === response.data.status)) return [3 /*break*/, 4];
58
+ if (!(api_1.states.SUCCESS === response.data.status)) return [3 /*break*/, 4];
59
59
  if (!onSuccess) return [3 /*break*/, 2];
60
60
  return [4 /*yield*/, onSuccess(response.data.body)];
61
61
  case 1:
@@ -1,5 +1,4 @@
1
- import { GetType, PostType } from './types';
2
- import get from './get';
3
- import post from './post';
1
+ import get, { GetType } from './get';
2
+ import post, { PostType } from './post';
4
3
  export type { GetType, PostType, };
5
4
  export { get, post, };
@@ -1,4 +1,10 @@
1
- import { PostType } from './types';
1
+ export declare type PostType = {
2
+ config?: object;
3
+ data?: object;
4
+ onError?: Function;
5
+ onSuccess?: Function;
6
+ url: string;
7
+ };
2
8
  /**
3
9
  * Make a POST request.
4
10
  */
@@ -58,7 +58,7 @@ var post = function (_a) {
58
58
  case 0:
59
59
  if (!(200 === response.status)) return [3 /*break*/, 12];
60
60
  if (!(undefined !== response.data.body && undefined !== response.data.error && undefined !== response.data.status)) return [3 /*break*/, 8];
61
- if (!(api_1.ApiStatus.SUCCESS === response.data.status)) return [3 /*break*/, 4];
61
+ if (!(api_1.states.SUCCESS === response.data.status)) return [3 /*break*/, 4];
62
62
  if (!onSuccess) return [3 /*break*/, 2];
63
63
  return [4 /*yield*/, onSuccess(response.data.body)];
64
64
  case 1:
@@ -1,4 +1,3 @@
1
- import { CrudStatus } from './constants';
2
- import { CrudType } from './types';
3
- export type { CrudType, };
4
- export { CrudStatus, };
1
+ import { states, StateType } from './states';
2
+ export type { StateType, };
3
+ export { states, };
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CrudStatus = void 0;
4
- var constants_1 = require("./constants");
5
- Object.defineProperty(exports, "CrudStatus", { enumerable: true, get: function () { return constants_1.CrudStatus; } });
3
+ exports.states = void 0;
4
+ var states_1 = require("./states");
5
+ Object.defineProperty(exports, "states", { enumerable: true, get: function () { return states_1.states; } });
@@ -0,0 +1,7 @@
1
+ export declare const states: {
2
+ CREATE: string;
3
+ READ: string;
4
+ UPDATE: string;
5
+ DELETE: string;
6
+ };
7
+ export declare type StateType = typeof states.CREATE | typeof states.READ | typeof states.UPDATE | typeof states.DELETE;