@mastra/auth-workos 1.3.0 → 1.4.0

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
@@ -785,6 +785,9 @@ var MastraRBACWorkos = class {
785
785
  }
786
786
  };
787
787
  var FILTER_ACCESSIBLE_CHECK_CONCURRENCY = 5;
788
+ function isWorkOSResourceNotFoundError(error) {
789
+ return error?.status === 404 || error?.code === "entity_not_found";
790
+ }
788
791
  var WorkOSFGAResourceNotFoundError = class extends Error {
789
792
  status = 404;
790
793
  resourceType;
@@ -814,6 +817,10 @@ var MastraFGAWorkos = class {
814
817
  organizationId;
815
818
  resourceMapping;
816
819
  permissionMapping;
820
+ requireForProtectedRoutes;
821
+ auditProtectedRoutes;
822
+ resolveRouteFGA;
823
+ validatePermissions;
817
824
  constructor(options) {
818
825
  const apiKey = options.apiKey ?? process.env.WORKOS_API_KEY;
819
826
  const clientId = options.clientId ?? process.env.WORKOS_CLIENT_ID;
@@ -826,6 +833,10 @@ var MastraFGAWorkos = class {
826
833
  this.organizationId = options.organizationId;
827
834
  this.resourceMapping = options.resourceMapping ?? {};
828
835
  this.permissionMapping = options.permissionMapping ?? {};
836
+ this.requireForProtectedRoutes = options.requireForProtectedRoutes;
837
+ this.auditProtectedRoutes = options.auditProtectedRoutes;
838
+ this.resolveRouteFGA = options.resolveRouteFGA;
839
+ this.validatePermissions = options.validatePermissions;
829
840
  }
830
841
  // ──────────────────────────────────────────────────────────────
831
842
  // IFGAProvider — Read-only checks
@@ -843,8 +854,8 @@ var MastraFGAWorkos = class {
843
854
  const result = await this.workos.authorization.check(checkOptions);
844
855
  return result.authorized;
845
856
  } catch (error) {
846
- if (error?.status === 404 || error?.code === "entity_not_found") {
847
- throw new WorkOSFGAResourceNotFoundError(params.resource.type, params.resource.id);
857
+ if (isWorkOSResourceNotFoundError(error)) {
858
+ return false;
848
859
  }
849
860
  throw error;
850
861
  }
@@ -864,8 +875,8 @@ var MastraFGAWorkos = class {
864
875
  }
865
876
  } catch (error) {
866
877
  if (error instanceof FGADeniedError) throw error;
867
- if (error?.status === 404 || error?.code === "entity_not_found") {
868
- throw new WorkOSFGAResourceNotFoundError(params.resource.type, params.resource.id);
878
+ if (isWorkOSResourceNotFoundError(error)) {
879
+ throw new FGADeniedError(user, params.resource, params.permission);
869
880
  }
870
881
  throw error;
871
882
  }