@8ms/helpers 1.0.5 → 1.0.9

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.
@@ -2,5 +2,6 @@ import { ApiStatus } from './constants';
2
2
  export declare type ApiResponseType = {
3
3
  body: any | null;
4
4
  error: string | null;
5
- status: typeof ApiStatus.ERROR | typeof ApiStatus.IDLE | typeof ApiStatus.PENDING | typeof ApiStatus.SUCCESS | typeof ApiStatus.VALIDATION_ERROR;
5
+ status: ApiStatusType;
6
6
  };
7
+ export declare type ApiStatusType = typeof ApiStatus.ERROR | typeof ApiStatus.IDLE | typeof ApiStatus.PENDING | typeof ApiStatus.SUCCESS | typeof ApiStatus.VALIDATION_ERROR;
@@ -9,7 +9,13 @@ var getClient = function (_a) {
9
9
  var GlueLib = _a.GlueLib, config = _a.config;
10
10
  if (!global.awsGlueClient) {
11
11
  var GlueClient = GlueLib.GlueClient;
12
- global.awsGlueClient = new GlueClient(config);
12
+ global.awsGlueClient = new GlueClient({
13
+ credentials: {
14
+ accessKeyId: config.accessKeyId,
15
+ secretAccessKey: config.secretAccessKey,
16
+ },
17
+ region: config.region,
18
+ });
13
19
  }
14
20
  glueClient = global.awsGlueClient;
15
21
  return glueClient;
@@ -9,7 +9,13 @@ var getClient = function (_a) {
9
9
  var LambdaLib = _a.LambdaLib, config = _a.config;
10
10
  if (!global.awsLambdaClient) {
11
11
  var LambdaClient = LambdaLib.LambdaClient;
12
- global.awsLambdaClient = new LambdaClient(config);
12
+ global.awsLambdaClient = new LambdaClient({
13
+ credentials: {
14
+ accessKeyId: config.accessKeyId,
15
+ secretAccessKey: config.secretAccessKey,
16
+ },
17
+ region: config.region,
18
+ });
13
19
  }
14
20
  lambdaClient = global.awsLambdaClient;
15
21
  return lambdaClient;
@@ -9,7 +9,13 @@ var getClient = function (_a) {
9
9
  var S3Lib = _a.S3Lib, config = _a.config;
10
10
  if (!global.awsS3Client) {
11
11
  var S3Client = S3Lib.S3Client;
12
- global.awsS3Client = new S3Client(config);
12
+ global.awsS3Client = new S3Client({
13
+ credentials: {
14
+ accessKeyId: config.accessKeyId,
15
+ secretAccessKey: config.secretAccessKey,
16
+ },
17
+ region: config.region,
18
+ });
13
19
  }
14
20
  s3Client = global.awsS3Client;
15
21
  return s3Client;
@@ -9,7 +9,13 @@ var getClient = function (_a) {
9
9
  var SesLib = _a.SesLib, config = _a.config;
10
10
  if (!global.awsSesClient) {
11
11
  var SESClient = SesLib.SESClient;
12
- global.sesClient = new SESClient(config);
12
+ global.sesClient = new SESClient({
13
+ credentials: {
14
+ accessKeyId: config.accessKeyId,
15
+ secretAccessKey: config.secretAccessKey,
16
+ },
17
+ region: config.region,
18
+ });
13
19
  }
14
20
  sesClient = global.awsSesClient;
15
21
  return sesClient;
@@ -9,7 +9,13 @@ var getClient = function (_a) {
9
9
  var SsmLib = _a.SsmLib, config = _a.config;
10
10
  if (!global.awsSsmClient) {
11
11
  var SSMClient = SsmLib.SSMClient;
12
- global.awsSsmClient = new SSMClient(config);
12
+ global.awsSsmClient = new SSMClient({
13
+ credentials: {
14
+ accessKeyId: config.accessKeyId,
15
+ secretAccessKey: config.secretAccessKey,
16
+ },
17
+ region: config.region,
18
+ });
13
19
  }
14
20
  ssmClient = global.awsSsmClient;
15
21
  return ssmClient;
package/dist/axios/get.js CHANGED
@@ -40,6 +40,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
40
40
  };
41
41
  Object.defineProperty(exports, "__esModule", { value: true });
42
42
  var axios_1 = __importDefault(require("axios"));
43
+ var api_1 = require("../api");
43
44
  var get = function (_a) {
44
45
  var _b = _a.config, config = _b === void 0 ? {} : _b, onError = _a.onError, onSuccess = _a.onSuccess, url = _a.url;
45
46
  return __awaiter(void 0, void 0, void 0, function () {
@@ -48,19 +49,39 @@ var get = function (_a) {
48
49
  switch (_c.label) {
49
50
  case 0: return [4 /*yield*/, axios_1.default.get(url, config)
50
51
  .then(function (response) { return __awaiter(void 0, void 0, void 0, function () {
51
- var _a;
52
- return __generator(this, function (_b) {
53
- switch (_b.label) {
52
+ var _a, _b;
53
+ return __generator(this, function (_c) {
54
+ switch (_c.label) {
54
55
  case 0:
56
+ if (!(200 === response.status)) return [3 /*break*/, 12];
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];
55
59
  if (!onSuccess) return [3 /*break*/, 2];
56
- return [4 /*yield*/, onSuccess(response)];
60
+ return [4 /*yield*/, onSuccess(response.data.body)];
57
61
  case 1:
58
- _a = _b.sent();
62
+ _a = _c.sent();
59
63
  return [3 /*break*/, 3];
60
64
  case 2:
61
- _a = response;
62
- _b.label = 3;
65
+ _a = response.data.body;
66
+ _c.label = 3;
63
67
  case 3: return [2 /*return*/, _a];
68
+ case 4:
69
+ if (!onError) return [3 /*break*/, 6];
70
+ return [4 /*yield*/, onError(response.data.error)];
71
+ case 5: return [2 /*return*/, _c.sent()];
72
+ case 6: throw new Error(response.data.error);
73
+ case 7: return [3 /*break*/, 12];
74
+ case 8:
75
+ if (!onSuccess) return [3 /*break*/, 10];
76
+ return [4 /*yield*/, onSuccess(response)];
77
+ case 9:
78
+ _b = _c.sent();
79
+ return [3 /*break*/, 11];
80
+ case 10:
81
+ _b = response;
82
+ _c.label = 11;
83
+ case 11: return [2 /*return*/, _b];
84
+ case 12: return [2 /*return*/];
64
85
  }
65
86
  });
66
87
  }); })
@@ -40,6 +40,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
40
40
  };
41
41
  Object.defineProperty(exports, "__esModule", { value: true });
42
42
  var axios_1 = __importDefault(require("axios"));
43
+ var api_1 = require("../api");
43
44
  /**
44
45
  * Make a POST request.
45
46
  */
@@ -51,19 +52,39 @@ var post = function (_a) {
51
52
  switch (_d.label) {
52
53
  case 0: return [4 /*yield*/, axios_1.default.post(url, data, config)
53
54
  .then(function (response) { return __awaiter(void 0, void 0, void 0, function () {
54
- var _a;
55
- return __generator(this, function (_b) {
56
- switch (_b.label) {
55
+ var _a, _b;
56
+ return __generator(this, function (_c) {
57
+ switch (_c.label) {
57
58
  case 0:
59
+ if (!(200 === response.status)) return [3 /*break*/, 12];
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];
58
62
  if (!onSuccess) return [3 /*break*/, 2];
59
- return [4 /*yield*/, onSuccess(response)];
63
+ return [4 /*yield*/, onSuccess(response.data.body)];
60
64
  case 1:
61
- _a = _b.sent();
65
+ _a = _c.sent();
62
66
  return [3 /*break*/, 3];
63
67
  case 2:
64
- _a = response;
65
- _b.label = 3;
68
+ _a = response.data.body;
69
+ _c.label = 3;
66
70
  case 3: return [2 /*return*/, _a];
71
+ case 4:
72
+ if (!onError) return [3 /*break*/, 6];
73
+ return [4 /*yield*/, onError(response.data.error)];
74
+ case 5: return [2 /*return*/, _c.sent()];
75
+ case 6: throw new Error(response.data.error);
76
+ case 7: return [3 /*break*/, 12];
77
+ case 8:
78
+ if (!onSuccess) return [3 /*break*/, 10];
79
+ return [4 /*yield*/, onSuccess(response)];
80
+ case 9:
81
+ _b = _c.sent();
82
+ return [3 /*break*/, 11];
83
+ case 10:
84
+ _b = response;
85
+ _c.label = 11;
86
+ case 11: return [2 /*return*/, _b];
87
+ case 12: return [2 /*return*/];
67
88
  }
68
89
  });
69
90
  }); })
@@ -1,3 +1,4 @@
1
1
  import { AuthState } from './constants';
2
+ import isSessionReady from './isSessionReady';
2
3
  export type {};
3
- export { AuthState, };
4
+ export { AuthState, isSessionReady, };
@@ -1,5 +1,10 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AuthState = void 0;
6
+ exports.isSessionReady = exports.AuthState = void 0;
4
7
  var constants_1 = require("./constants");
5
8
  Object.defineProperty(exports, "AuthState", { enumerable: true, get: function () { return constants_1.AuthState; } });
9
+ var isSessionReady_1 = __importDefault(require("./isSessionReady"));
10
+ exports.isSessionReady = isSessionReady_1.default;
@@ -0,0 +1,4 @@
1
+ declare const isSessionReady: ({ session }: {
2
+ session: any;
3
+ }) => boolean;
4
+ export default isSessionReady;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var isSessionReady = function (_a) {
4
+ var session = _a.session;
5
+ var response = false;
6
+ if (undefined !== session && null !== session) {
7
+ if (undefined !== session.user && null !== session.user) {
8
+ response = true;
9
+ }
10
+ }
11
+ return response;
12
+ };
13
+ exports.default = isSessionReady;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@8ms/helpers",
3
- "version": "1.0.5",
3
+ "version": "1.0.9",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/8millionstories-organisation/8ms-helpers-ts.git"