@mastra/auth-workos 1.4.0 → 1.5.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/CHANGELOG.md +60 -0
- package/dist/fga-provider.d.ts +6 -0
- package/dist/fga-provider.d.ts.map +1 -1
- package/dist/index.cjs +37 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +37 -21
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -846,40 +846,56 @@ var MastraFGAWorkos = class {
|
|
|
846
846
|
*
|
|
847
847
|
* Resolves the user's organization membership ID, maps the permission
|
|
848
848
|
* via `permissionMapping`, and delegates to `workos.authorization.check()`.
|
|
849
|
+
*
|
|
850
|
+
* When `params.permission` is an array, ANY-of semantics apply: returns true
|
|
851
|
+
* if any single permission in the array authorizes the user.
|
|
849
852
|
*/
|
|
850
853
|
async check(user, params) {
|
|
851
|
-
const
|
|
852
|
-
if (
|
|
853
|
-
|
|
854
|
-
const
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
return
|
|
854
|
+
const permissions = Array.isArray(params.permission) ? params.permission : [params.permission];
|
|
855
|
+
if (permissions.length === 0) return false;
|
|
856
|
+
for (const permission of permissions) {
|
|
857
|
+
const checkOptions = this.buildCheckOptions(user, { ...params, permission });
|
|
858
|
+
if (!checkOptions) continue;
|
|
859
|
+
try {
|
|
860
|
+
const result = await this.workos.authorization.check(checkOptions);
|
|
861
|
+
if (result.authorized) return true;
|
|
862
|
+
} catch (error) {
|
|
863
|
+
if (isWorkOSResourceNotFoundError(error)) continue;
|
|
864
|
+
throw error;
|
|
859
865
|
}
|
|
860
|
-
throw error;
|
|
861
866
|
}
|
|
867
|
+
return false;
|
|
862
868
|
}
|
|
863
869
|
/**
|
|
864
870
|
* Require that a user has permission, throwing FGADeniedError if not.
|
|
871
|
+
*
|
|
872
|
+
* When `params.permission` is an array, ANY-of semantics apply: passes if any
|
|
873
|
+
* single permission authorizes the user; throws if none do.
|
|
865
874
|
*/
|
|
866
875
|
async require(user, params) {
|
|
867
|
-
const
|
|
868
|
-
if (
|
|
876
|
+
const permissions = Array.isArray(params.permission) ? params.permission : [params.permission];
|
|
877
|
+
if (permissions.length === 0) {
|
|
869
878
|
throw new FGADeniedError(user, params.resource, params.permission);
|
|
870
879
|
}
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
if (
|
|
879
|
-
|
|
880
|
+
let lastError;
|
|
881
|
+
for (const permission of permissions) {
|
|
882
|
+
const checkOptions = this.buildCheckOptions(
|
|
883
|
+
user,
|
|
884
|
+
{ ...params, permission },
|
|
885
|
+
{ strictMembershipResolution: true }
|
|
886
|
+
);
|
|
887
|
+
if (!checkOptions) continue;
|
|
888
|
+
try {
|
|
889
|
+
const result = await this.workos.authorization.check(checkOptions);
|
|
890
|
+
if (result.authorized) return;
|
|
891
|
+
} catch (error) {
|
|
892
|
+
if (error instanceof FGADeniedError) throw error;
|
|
893
|
+
if (isWorkOSResourceNotFoundError(error)) continue;
|
|
894
|
+
lastError = error;
|
|
880
895
|
}
|
|
881
|
-
throw error;
|
|
882
896
|
}
|
|
897
|
+
if (lastError) throw lastError;
|
|
898
|
+
throw new FGADeniedError(user, params.resource, params.permission);
|
|
883
899
|
}
|
|
884
900
|
/**
|
|
885
901
|
* Filter resources to only those the user has permission to access.
|