@heliyos/heliyos-api-core 1.0.22 → 1.0.23

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.
@@ -10,11 +10,11 @@ export declare const authentication: (req: Request, res: Response, next: NextFun
10
10
  export interface IAuthResponseApiKey {
11
11
  id: number;
12
12
  name?: string;
13
- customer_id?: string;
14
- location_ids: string[] | undefined;
13
+ customerId?: string;
14
+ locationIds: string[] | undefined;
15
15
  policy: IAuthResponseApiKeyPolicy[] | undefined;
16
- user_id: string;
17
- organization_id: string;
16
+ userId: string;
17
+ organizationId: string;
18
18
  }
19
19
  interface IAuthResponseApiKeyPolicy {
20
20
  resource: string;
@@ -41,8 +41,8 @@ const authentication = (req, res, next) => __awaiter(void 0, void 0, void 0, fun
41
41
  auth_type: undefined,
42
42
  },
43
43
  output: {
44
- is_basic_auth: false,
45
- is_api_key_auth: false,
44
+ isBasicAuth: false,
45
+ isApiKeyAuth: false,
46
46
  },
47
47
  };
48
48
  // Check for the type of authentication
@@ -51,7 +51,7 @@ const authentication = (req, res, next) => __awaiter(void 0, void 0, void 0, fun
51
51
  // Either of BASIC / COOKIE / BEARER
52
52
  const authenticationResponse = yield authenticate_request(container);
53
53
  if (authenticationResponse) {
54
- container.output.logged_in_user = authenticationResponse;
54
+ container.output.loggedInUser = authenticationResponse;
55
55
  }
56
56
  else {
57
57
  return res.status(401).json({
@@ -173,9 +173,9 @@ const authenticate_request = (container) => __awaiter(void 0, void 0, void 0, fu
173
173
  case "API_KEY":
174
174
  // Call API authorization server with api key
175
175
  result = yield verify_api_key(authentication_header.replace(/Bearer /, ""));
176
- // Set is_api_key_auth if there is a api key id
176
+ // Set isApiKeyAuth if there is a api key id
177
177
  if (result === null || result === void 0 ? void 0 : result.id) {
178
- container.output.is_api_key_auth = true;
178
+ container.output.isApiKeyAuth = true;
179
179
  }
180
180
  break;
181
181
  default:
@@ -203,8 +203,8 @@ const do_basic_auth = (container) => {
203
203
  error.status = "401";
204
204
  throw error;
205
205
  }
206
- // Set is_basic_auth
207
- container.output.is_basic_auth = true;
206
+ // Set isBasicAuth
207
+ container.output.isBasicAuth = true;
208
208
  // An empty object is returned because returning a falsy
209
209
  // object will means unauthorized.
210
210
  return {};
@@ -216,29 +216,29 @@ const do_basic_auth = (container) => {
216
216
  * @returns
217
217
  */
218
218
  const set_logged_in_user = function (container, req) {
219
- // If is_basic_auth, set it and return
220
- const { output: { is_basic_auth, is_api_key_auth }, input: { auth_type }, } = container;
221
- if (is_basic_auth) {
222
- req.is_basic_auth = is_basic_auth;
219
+ // If isBasicAuth, set it and return
220
+ const { output: { isBasicAuth, isApiKeyAuth }, input: { auth_type }, } = container;
221
+ if (isBasicAuth) {
222
+ req.isBasicAuth = isBasicAuth;
223
223
  return undefined;
224
224
  }
225
- // Set is_api_key_auth
226
- if (is_api_key_auth) {
227
- req.is_api_key_auth = is_api_key_auth;
228
- const { output: { logged_in_user }, } = container;
225
+ // Set isApiKeyAuth
226
+ if (isApiKeyAuth) {
227
+ req.isApiKeyAuth = isApiKeyAuth;
228
+ const { output: { loggedInUser }, } = container;
229
229
  // Modify req object with logged in user data
230
- req.logged_in_user = logged_in_user;
230
+ req.loggedInUser = loggedInUser;
231
231
  return undefined;
232
232
  }
233
233
  //
234
234
  // Handle Cookie and Bearer token
235
- const { output: { logged_in_user }, } = container;
236
- const { token, user_id, organization_id } = logged_in_user;
235
+ const { output: { loggedInUser }, } = container;
236
+ const { token, userId, organizationId } = loggedInUser;
237
237
  // Modify req object with logged in user data
238
- req.logged_in_user = {
238
+ req.loggedInUser = {
239
239
  token,
240
- user_id,
241
- organization_id,
240
+ userId,
241
+ organizationId,
242
242
  auth_type,
243
243
  };
244
244
  return undefined;
@@ -256,12 +256,12 @@ const call_auth_api_server = (token) => __awaiter(void 0, void 0, void 0, functi
256
256
  const auth_result = yield _1.axios.auth_server.post("/v1/auth/verify_token_v2", {
257
257
  token: token,
258
258
  });
259
- if ((_b = (_a = auth_result.data) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.is_valid) {
259
+ if ((_b = (_a = auth_result.data) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.isValid) {
260
260
  // Resolve request with received data
261
261
  return {
262
262
  token,
263
- user_id: auth_result.data.data.payload.user_id,
264
- organization_id: auth_result.data.data.payload.organization_id,
263
+ userId: auth_result.data.data.payload.userId,
264
+ organizationId: auth_result.data.data.payload.organizationId,
265
265
  };
266
266
  }
267
267
  else {
@@ -1,11 +1,11 @@
1
1
  /**
2
2
  * Authorize the user with the resource action
3
- * @param organization_id
4
- * @param user_id
5
- * @param resource_action
3
+ * @param organizationId
4
+ * @param userId
5
+ * @param resourceAction
6
6
  * @returns
7
7
  */
8
- export declare const authorize_user: <T = string, U = string>(organization_id: T, user_id: U, resource_action: string) => Promise<{
8
+ export declare const authorize_user: <T = string, U = string>(organizationId: T, userId: U, resourceAction: string) => Promise<{
9
9
  isAllowed: string;
10
10
  userRole: string;
11
11
  }>;
@@ -14,15 +14,15 @@ const customError_1 = require("./@types/globals/customError");
14
14
  const axios_1 = require("./axios");
15
15
  /**
16
16
  * Authorize the user with the resource action
17
- * @param organization_id
18
- * @param user_id
19
- * @param resource_action
17
+ * @param organizationId
18
+ * @param userId
19
+ * @param resourceAction
20
20
  * @returns
21
21
  */
22
22
  // eslint-disable-next-line import/prefer-default-export, @typescript-eslint/naming-convention
23
- const authorize_user = (organization_id, user_id, resource_action) => __awaiter(void 0, void 0, void 0, function* () {
23
+ const authorize_user = (organizationId, userId, resourceAction) => __awaiter(void 0, void 0, void 0, function* () {
24
24
  try {
25
- const authenticationResponse = yield axios_1.core_axios.auth_server.post(`v1/auth/user/${user_id}`, { resource_action: resource_action, organization_uuid: organization_id });
25
+ const authenticationResponse = yield axios_1.core_axios.auth_server.post(`v1/auth/user/${userId}`, { resourceAction, organizationId });
26
26
  return authenticationResponse.data.data;
27
27
  // eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-member-access
28
28
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@heliyos/heliyos-api-core",
3
- "version": "1.0.22",
3
+ "version": "1.0.23",
4
4
  "description": "Heliyos's core api functions and middlewares. Its a private package hosted on npm.",
5
5
  "main": "./dist/index.js",
6
6
  "scripts": {