@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.mjs CHANGED
@@ -1714,7 +1714,7 @@ import { ObjectUtils as ObjectUtils3 } from "@redskytech/core-utils";
1714
1714
  var SqlEngine = class {
1715
1715
  async runQueryForRoute(req, routeData, schema) {
1716
1716
  if (!this.doesRoleHavePermissionToTable(req.requesterDetails.role, schema, routeData.table))
1717
- throw new RsError("UNAUTHORIZED", "You do not have permission to access this table");
1717
+ throw new RsError("FORBIDDEN", "You do not have permission to access this table");
1718
1718
  switch (routeData.method) {
1719
1719
  case "POST":
1720
1720
  return this.executeCreateRequest(req, routeData, schema);
@@ -2207,7 +2207,7 @@ var PsqlEngine = class extends SqlEngine {
2207
2207
  if (item.subquery || this.doesRoleHavePermissionToColumn(userRole, schema, item, routeData.joins))
2208
2208
  selectColumns.push(item);
2209
2209
  });
2210
- if (!selectColumns.length) throw new RsError("UNAUTHORIZED", `You do not have permission to access this data.`);
2210
+ if (!selectColumns.length) throw new RsError("FORBIDDEN", `You do not have permission to access this data.`);
2211
2211
  let selectStatement = "SELECT \n";
2212
2212
  selectStatement += ` ${selectColumns.map((item) => {
2213
2213
  if (item.subquery) {
@@ -2315,7 +2315,7 @@ DELETE FROM "${routeData.table}" ${joinStatement} ${whereClause}`;
2315
2315
  let joinStatements = "";
2316
2316
  joins.forEach((item) => {
2317
2317
  if (!this.doesRoleHavePermissionToTable(userRole, schema, item.table))
2318
- throw new RsError("UNAUTHORIZED", "You do not have permission to access this table");
2318
+ throw new RsError("FORBIDDEN", "You do not have permission to access this table");
2319
2319
  if (item.custom) {
2320
2320
  const customReplaced = this.replaceParamKeywords(item.custom, routeData, req, sqlParams);
2321
2321
  joinStatements += ` ${item.type} JOIN ${escapeColumnName(item.table)}${item.alias ? `AS "${item.alias}"` : ""} ON ${customReplaced}
@@ -2958,8 +2958,7 @@ var ResturaEngine = class {
2958
2958
  validateAuthorization(req, routeData) {
2959
2959
  const role = req.requesterDetails.role;
2960
2960
  if (routeData.roles.length === 0 || !role) return;
2961
- if (!routeData.roles.includes(role))
2962
- throw new RsError("UNAUTHORIZED", "Not authorized to access this endpoint");
2961
+ if (!routeData.roles.includes(role)) throw new RsError("FORBIDDEN", "Not authorized to access this endpoint");
2963
2962
  }
2964
2963
  getRouteData(method, baseUrl, path5) {
2965
2964
  const endpoint = this.schema.endpoints.find((item) => {