@restura/core 0.1.2 → 0.1.3

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.
package/dist/index.js CHANGED
@@ -1761,7 +1761,7 @@ var import_core_utils4 = require("@redskytech/core-utils");
1761
1761
  var SqlEngine = class {
1762
1762
  async runQueryForRoute(req, routeData, schema) {
1763
1763
  if (!this.doesRoleHavePermissionToTable(req.requesterDetails.role, schema, routeData.table))
1764
- throw new RsError("UNAUTHORIZED", "You do not have permission to access this table");
1764
+ throw new RsError("FORBIDDEN", "You do not have permission to access this table");
1765
1765
  switch (routeData.method) {
1766
1766
  case "POST":
1767
1767
  return this.executeCreateRequest(req, routeData, schema);
@@ -2254,7 +2254,7 @@ var PsqlEngine = class extends SqlEngine {
2254
2254
  if (item.subquery || this.doesRoleHavePermissionToColumn(userRole, schema, item, routeData.joins))
2255
2255
  selectColumns.push(item);
2256
2256
  });
2257
- if (!selectColumns.length) throw new RsError("UNAUTHORIZED", `You do not have permission to access this data.`);
2257
+ if (!selectColumns.length) throw new RsError("FORBIDDEN", `You do not have permission to access this data.`);
2258
2258
  let selectStatement = "SELECT \n";
2259
2259
  selectStatement += ` ${selectColumns.map((item) => {
2260
2260
  if (item.subquery) {
@@ -2362,7 +2362,7 @@ DELETE FROM "${routeData.table}" ${joinStatement} ${whereClause}`;
2362
2362
  let joinStatements = "";
2363
2363
  joins.forEach((item) => {
2364
2364
  if (!this.doesRoleHavePermissionToTable(userRole, schema, item.table))
2365
- throw new RsError("UNAUTHORIZED", "You do not have permission to access this table");
2365
+ throw new RsError("FORBIDDEN", "You do not have permission to access this table");
2366
2366
  if (item.custom) {
2367
2367
  const customReplaced = this.replaceParamKeywords(item.custom, routeData, req, sqlParams);
2368
2368
  joinStatements += ` ${item.type} JOIN ${escapeColumnName(item.table)}${item.alias ? `AS "${item.alias}"` : ""} ON ${customReplaced}
@@ -3005,8 +3005,7 @@ var ResturaEngine = class {
3005
3005
  validateAuthorization(req, routeData) {
3006
3006
  const role = req.requesterDetails.role;
3007
3007
  if (routeData.roles.length === 0 || !role) return;
3008
- if (!routeData.roles.includes(role))
3009
- throw new RsError("UNAUTHORIZED", "Not authorized to access this endpoint");
3008
+ if (!routeData.roles.includes(role)) throw new RsError("FORBIDDEN", "Not authorized to access this endpoint");
3010
3009
  }
3011
3010
  getRouteData(method, baseUrl, path5) {
3012
3011
  const endpoint = this.schema.endpoints.find((item) => {