@8ms/helpers 1.0.3 → 1.0.4

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.
@@ -6,10 +6,10 @@ var athenaClient = undefined;
6
6
  */
7
7
  var getClient = function (_a) {
8
8
  var AthenaExpress = _a.AthenaExpress, AwsSdk = _a.AwsSdk, athenaS3 = _a.athenaS3, config = _a.config, database = _a.database;
9
- if (undefined === athenaClient) {
9
+ if (!global.awsAthenaClient) {
10
10
  // Set the aws authentication
11
11
  AwsSdk.config.update(config);
12
- athenaClient = new AthenaExpress.AthenaExpress({
12
+ global.awsAthenaClient = new AthenaExpress.AthenaExpress({
13
13
  aws: AwsSdk,
14
14
  s3: athenaS3,
15
15
  db: database,
@@ -18,6 +18,7 @@ var getClient = function (_a) {
18
18
  getStats: false,
19
19
  });
20
20
  }
21
+ athenaClient = global.awsAthenaClient;
21
22
  return athenaClient;
22
23
  };
23
24
  exports.default = getClient;
@@ -7,10 +7,11 @@ var glueClient = undefined;
7
7
  */
8
8
  var getClient = function (_a) {
9
9
  var GlueLib = _a.GlueLib, config = _a.config;
10
- if (undefined === glueClient) {
10
+ if (!global.awsGlueClient) {
11
11
  var GlueClient = GlueLib.GlueClient;
12
- glueClient = new GlueClient(config);
12
+ global.awsGlueClient = new GlueClient(config);
13
13
  }
14
+ glueClient = global.awsGlueClient;
14
15
  return glueClient;
15
16
  };
16
17
  exports.default = getClient;
@@ -7,10 +7,11 @@ var lambdaClient = undefined;
7
7
  */
8
8
  var getClient = function (_a) {
9
9
  var LambdaLib = _a.LambdaLib, config = _a.config;
10
- if (undefined === lambdaClient) {
10
+ if (!global.awsLambdaClient) {
11
11
  var LambdaClient = LambdaLib.LambdaClient;
12
- lambdaClient = new LambdaClient(config);
12
+ global.awsLambdaClient = new LambdaClient(config);
13
13
  }
14
+ lambdaClient = global.awsLambdaClient;
14
15
  return lambdaClient;
15
16
  };
16
17
  exports.default = getClient;
@@ -7,10 +7,11 @@ var s3Client = undefined;
7
7
  */
8
8
  var getClient = function (_a) {
9
9
  var S3Lib = _a.S3Lib, config = _a.config;
10
- if (undefined === s3Client) {
10
+ if (!global.awsS3Client) {
11
11
  var S3Client = S3Lib.S3Client;
12
- s3Client = new S3Client(config);
12
+ global.awsS3Client = new S3Client(config);
13
13
  }
14
+ s3Client = global.awsS3Client;
14
15
  return s3Client;
15
16
  };
16
17
  exports.default = getClient;
@@ -7,10 +7,11 @@ var sesClient = undefined;
7
7
  */
8
8
  var getClient = function (_a) {
9
9
  var SesLib = _a.SesLib, config = _a.config;
10
- if (undefined === sesClient) {
10
+ if (!global.awsSesClient) {
11
11
  var SESClient = SesLib.SESClient;
12
- sesClient = new SESClient(config);
12
+ global.sesClient = new SESClient(config);
13
13
  }
14
+ sesClient = global.awsSesClient;
14
15
  return sesClient;
15
16
  };
16
17
  exports.default = getClient;
@@ -7,10 +7,11 @@ var ssmClient = undefined;
7
7
  */
8
8
  var getClient = function (_a) {
9
9
  var SsmLib = _a.SsmLib, config = _a.config;
10
- if (undefined === ssmClient) {
10
+ if (!global.awsSsmClient) {
11
11
  var SSMClient = SsmLib.SSMClient;
12
- ssmClient = new SSMClient(config);
12
+ global.awsSsmClient = new SSMClient(config);
13
13
  }
14
+ ssmClient = global.awsSsmClient;
14
15
  return ssmClient;
15
16
  };
16
17
  exports.default = getClient;
@@ -48,7 +48,11 @@ var getParameter = function (_a) {
48
48
  switch (_b.label) {
49
49
  case 0:
50
50
  response = undefined;
51
- if (!(undefined === ssmParameters[name])) return [3 /*break*/, 5];
51
+ // Ensure the global property exists
52
+ if (!global.awsSsmParameters) {
53
+ global.awsSsmParameters = {};
54
+ }
55
+ if (!!global.awsSsmParameters[name]) return [3 /*break*/, 4];
52
56
  _b.label = 1;
53
57
  case 1:
54
58
  _b.trys.push([1, 3, , 4]);
@@ -61,23 +65,26 @@ var getParameter = function (_a) {
61
65
  apiResponse = _b.sent();
62
66
  if (apiResponse.Parameter.Value) {
63
67
  response = apiResponse.Parameter.Value;
64
- ssmParameters[name] = response;
68
+ global.awsSsmParameters[name] = response;
65
69
  if (isJson && undefined !== response) {
66
70
  response = JSON.parse(response) || undefined;
67
- ssmParameters[name] = response;
71
+ global.awsSsmParameters[name] = response;
68
72
  }
69
73
  }
74
+ // Value not found (null so it can be sent from server to front end)
75
+ else {
76
+ global.awsSsmParameters[name] = null;
77
+ }
70
78
  return [3 /*break*/, 4];
71
79
  case 3:
72
80
  error_1 = _b.sent();
73
81
  // @ts-ignore
74
82
  console.log("SSM Error: ".concat(error_1.message));
75
83
  return [3 /*break*/, 4];
76
- case 4: return [3 /*break*/, 6];
77
- case 5:
78
- response = ssmParameters[name];
79
- _b.label = 6;
80
- case 6: return [2 /*return*/, response];
84
+ case 4:
85
+ // Return the loaded result
86
+ response = global.awsSsmParameters[name];
87
+ return [2 /*return*/, response];
81
88
  }
82
89
  });
83
90
  });
@@ -49,7 +49,7 @@ var getClient = function (_a) {
49
49
  return __generator(this, function (_b) {
50
50
  switch (_b.label) {
51
51
  case 0:
52
- if (!(undefined === googleAdsClient)) return [3 /*break*/, 2];
52
+ if (!!global.googleAdsClient) return [3 /*break*/, 2];
53
53
  ssmClient = (0, ssm_1.getClient)({ SsmLib: SsmLib, config: awsConfig });
54
54
  return [4 /*yield*/, (0, ssm_1.getParameter)({
55
55
  SsmLib: SsmLib,
@@ -62,7 +62,7 @@ var getClient = function (_a) {
62
62
  parameter = _b.sent();
63
63
  GoogleAdsApi = GoogleAdsLib.GoogleAdsApi;
64
64
  // Create a new client instance
65
- googleAdsClient = {
65
+ global.googleAdsClient = {
66
66
  instance: new GoogleAdsApi({
67
67
  client_id: parameter.clientId,
68
68
  client_secret: parameter.clientSecret,
@@ -72,7 +72,9 @@ var getClient = function (_a) {
72
72
  refreshToken: parameter.refreshToken,
73
73
  };
74
74
  _b.label = 2;
75
- case 2: return [2 /*return*/, googleAdsClient];
75
+ case 2:
76
+ googleAdsClient = global.googleAdsClient;
77
+ return [2 /*return*/, googleAdsClient];
76
78
  }
77
79
  });
78
80
  });
@@ -13,7 +13,7 @@ var getClient = function (_a) {
13
13
  // @ts-ignore
14
14
  if (!global.prisma) {
15
15
  // Show the full query if debugging
16
- if (debug) {
16
+ if (debug && undefined !== PrismaLogLib) {
17
17
  // @ts-ignore
18
18
  global.prisma = new PrismaClient({
19
19
  log: [
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Convert a string into Capitalised Text.
3
+ * https://stackoverflow.com/a/196991/2664955
4
+ */
5
+ declare const formatCapitalise: ({ input, split }?: {
6
+ input: string;
7
+ split: string;
8
+ }) => string;
9
+ export default formatCapitalise;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /**
4
+ * Convert a string into Capitalised Text.
5
+ * https://stackoverflow.com/a/196991/2664955
6
+ */
7
+ var formatCapitalise = function (_a) {
8
+ var _b = _a === void 0 ? { input: '', split: '_' } : _a, input = _b.input, split = _b.split;
9
+ return input
10
+ .replace("/".concat(split, "/g"), ' ')
11
+ .replace(/\w\S*/g, function (txt) {
12
+ return txt.charAt(0)
13
+ .toUpperCase() + txt.substr(1)
14
+ .toLowerCase();
15
+ });
16
+ };
17
+ exports.default = formatCapitalise;
@@ -1,4 +1,5 @@
1
+ import formatCapitalise from './formatCapitalise';
1
2
  import getCleanFolder from './getCleanFolder';
2
3
  import getStringFromStream from './getStringFromStream';
3
4
  export type {};
4
- export { getCleanFolder, getStringFromStream, };
5
+ export { formatCapitalise, getCleanFolder, getStringFromStream, };
@@ -3,7 +3,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getStringFromStream = exports.getCleanFolder = void 0;
6
+ exports.getStringFromStream = exports.getCleanFolder = exports.formatCapitalise = void 0;
7
+ var formatCapitalise_1 = __importDefault(require("./formatCapitalise"));
8
+ exports.formatCapitalise = formatCapitalise_1.default;
7
9
  var getCleanFolder_1 = __importDefault(require("./getCleanFolder"));
8
10
  exports.getCleanFolder = getCleanFolder_1.default;
9
11
  var getStringFromStream_1 = __importDefault(require("./getStringFromStream"));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@8ms/helpers",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/8millionstories-organisation/8ms-helpers-ts.git"