@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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,65 @@
|
|
|
1
1
|
# @mastra/auth-workos
|
|
2
2
|
|
|
3
|
+
## 1.5.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- FGA `check()` and `require()` now accept an array of permissions and short-circuit on the first one that resolves to allow (ANY-of semantics). Single-permission usage continues to work unchanged. ([#16605](https://github.com/mastra-ai/mastra/pull/16605))
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
// Before — one permission per call
|
|
11
|
+
await fgaProvider.check({
|
|
12
|
+
user,
|
|
13
|
+
resource: { type: 'agent', id: 'abc' },
|
|
14
|
+
permission: 'agents:read',
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
// After — single permission or ANY-of array
|
|
18
|
+
await fgaProvider.check({
|
|
19
|
+
user,
|
|
20
|
+
resource: { type: 'agent', id: 'abc' },
|
|
21
|
+
permission: ['agents:read', 'agents:execute'],
|
|
22
|
+
});
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
When all permissions in the array are denied, the thrown `FGADeniedError` lists them as `any of [a, b, c]` in its message.
|
|
26
|
+
|
|
27
|
+
### Patch Changes
|
|
28
|
+
|
|
29
|
+
- Updated dependencies [[`452036a`](https://github.com/mastra-ai/mastra/commit/452036a0d965b4f4c1efd93606e4f03b50b807a5), [`c272d50`](https://github.com/mastra-ai/mastra/commit/c272d50610a54496b6b6d92ccd4d37b333a2613a), [`27fd1b7`](https://github.com/mastra-ai/mastra/commit/27fd1b79ac62eb7694f92587eb7d1be05b59be01), [`5ba7253`](https://github.com/mastra-ai/mastra/commit/5ba7253745c85e8df8012a76d954c640ffa336f7), [`5556cc1`](https://github.com/mastra-ai/mastra/commit/5556cc1befec71518d84f826b3bfe3a079a9daf7), [`f73980d`](https://github.com/mastra-ai/mastra/commit/f73980d651eb5f7f1ab20582de4615a1b6f10fce), [`5499303`](https://github.com/mastra-ai/mastra/commit/54993032c1ebc09642625b78d2014e0cf84a3cae), [`a702009`](https://github.com/mastra-ai/mastra/commit/a702009d3cfaa745120f501e21c783ed4d6a3072), [`9aee493`](https://github.com/mastra-ai/mastra/commit/9aee493ed6089b5133472623dcce49934bf2d509), [`d8692af`](https://github.com/mastra-ai/mastra/commit/d8692afa253028e39cdce2aafa0ac414071a762e), [`1a9cc60`](https://github.com/mastra-ai/mastra/commit/1a9cc6069f9910fc3d59e4953ac8cd95d89ad6f5), [`8cdb86c`](https://github.com/mastra-ai/mastra/commit/8cdb86ceed1137bc2768e147dce85a0692b9fb26), [`8534d79`](https://github.com/mastra-ai/mastra/commit/8534d791fa1cb70fe1c19e2604c4b63cc10dd051), [`eda90c5`](https://github.com/mastra-ai/mastra/commit/eda90c5bfd7de11805ecc9f4552716c895fbaf78), [`a935b0a`](https://github.com/mastra-ai/mastra/commit/a935b0a0977ae3f196b33ec7621f528069c82db0), [`9c88701`](https://github.com/mastra-ai/mastra/commit/9c8870195b41a38dc40b6ba2aa55eda04df8fa69), [`c78f8cd`](https://github.com/mastra-ai/mastra/commit/c78f8cd6222a86e6c60ae5210b6929ad5221b6fb), [`e146aad`](https://github.com/mastra-ai/mastra/commit/e146aadbba66c410ba0e74bac4c50135495cb8dd), [`ac79462`](https://github.com/mastra-ai/mastra/commit/ac79462b98f1062394c45093aa515b0766f27ee2), [`1a0ec78`](https://github.com/mastra-ai/mastra/commit/1a0ec789a26cae443744e9abbd62ed6ee676af39), [`e47bca7`](https://github.com/mastra-ai/mastra/commit/e47bca7b72866d3abd173b9f530ac4318113a8ff), [`afc004f`](https://github.com/mastra-ai/mastra/commit/afc004f5cc7e30697809e7021820b9f5881e6719), [`0031d0f`](https://github.com/mastra-ai/mastra/commit/0031d0f13831d7843ac5d498734a7d92862e2ce3), [`841a222`](https://github.com/mastra-ai/mastra/commit/841a222560d8c19238f8213713f30535cdd82284), [`64c1e0b`](https://github.com/mastra-ai/mastra/commit/64c1e0b35165c96b659818bd0177aa18794ef11f), [`40d83a9`](https://github.com/mastra-ai/mastra/commit/40d83a90d9be31a1b83e04649edb703eb7753e33), [`4e88dc6`](https://github.com/mastra-ai/mastra/commit/4e88dc6b89f154c0eae37221c8126be0c23c569f), [`19018f0`](https://github.com/mastra-ai/mastra/commit/19018f05722af74a5978781a7731a654b26f7f2a), [`19281c7`](https://github.com/mastra-ai/mastra/commit/19281c70424f757219782de16c2699743c5e04d0), [`3498b49`](https://github.com/mastra-ai/mastra/commit/3498b4946be94f4313cd817733589680dcda5278), [`d52b6fe`](https://github.com/mastra-ai/mastra/commit/d52b6fe1c56853eb38864baae0bbfa75cc739ccb), [`408be73`](https://github.com/mastra-ai/mastra/commit/408be73449dfab92b51eab8c6623b6c443debc25), [`359439b`](https://github.com/mastra-ai/mastra/commit/359439bb8c635e048176306828195f8297f50021), [`71a820b`](https://github.com/mastra-ai/mastra/commit/71a820b2353fa1406772c50760a3732058a8b337), [`1698f5e`](https://github.com/mastra-ai/mastra/commit/1698f5ec141d34f22a873efdb145ce3cdf848a5e)]:
|
|
30
|
+
- @mastra/core@1.36.0
|
|
31
|
+
- @mastra/auth@1.0.2
|
|
32
|
+
|
|
33
|
+
## 1.5.0-alpha.0
|
|
34
|
+
|
|
35
|
+
### Minor Changes
|
|
36
|
+
|
|
37
|
+
- FGA `check()` and `require()` now accept an array of permissions and short-circuit on the first one that resolves to allow (ANY-of semantics). Single-permission usage continues to work unchanged. ([#16605](https://github.com/mastra-ai/mastra/pull/16605))
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
// Before — one permission per call
|
|
41
|
+
await fgaProvider.check({
|
|
42
|
+
user,
|
|
43
|
+
resource: { type: 'agent', id: 'abc' },
|
|
44
|
+
permission: 'agents:read',
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
// After — single permission or ANY-of array
|
|
48
|
+
await fgaProvider.check({
|
|
49
|
+
user,
|
|
50
|
+
resource: { type: 'agent', id: 'abc' },
|
|
51
|
+
permission: ['agents:read', 'agents:execute'],
|
|
52
|
+
});
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
When all permissions in the array are denied, the thrown `FGADeniedError` lists them as `any of [a, b, c]` in its message.
|
|
56
|
+
|
|
57
|
+
### Patch Changes
|
|
58
|
+
|
|
59
|
+
- Updated dependencies [[`5ba7253`](https://github.com/mastra-ai/mastra/commit/5ba7253745c85e8df8012a76d954c640ffa336f7), [`f73980d`](https://github.com/mastra-ai/mastra/commit/f73980d651eb5f7f1ab20582de4615a1b6f10fce), [`9c88701`](https://github.com/mastra-ai/mastra/commit/9c8870195b41a38dc40b6ba2aa55eda04df8fa69), [`4e88dc6`](https://github.com/mastra-ai/mastra/commit/4e88dc6b89f154c0eae37221c8126be0c23c569f), [`19018f0`](https://github.com/mastra-ai/mastra/commit/19018f05722af74a5978781a7731a654b26f7f2a)]:
|
|
60
|
+
- @mastra/core@1.36.0-alpha.2
|
|
61
|
+
- @mastra/auth@1.0.2
|
|
62
|
+
|
|
3
63
|
## 1.4.0
|
|
4
64
|
|
|
5
65
|
### Minor Changes
|
package/dist/fga-provider.d.ts
CHANGED
|
@@ -73,10 +73,16 @@ export declare class MastraFGAWorkos implements IFGAManager<WorkOSUser> {
|
|
|
73
73
|
*
|
|
74
74
|
* Resolves the user's organization membership ID, maps the permission
|
|
75
75
|
* via `permissionMapping`, and delegates to `workos.authorization.check()`.
|
|
76
|
+
*
|
|
77
|
+
* When `params.permission` is an array, ANY-of semantics apply: returns true
|
|
78
|
+
* if any single permission in the array authorizes the user.
|
|
76
79
|
*/
|
|
77
80
|
check(user: WorkOSUser, params: FGACheckParams): Promise<boolean>;
|
|
78
81
|
/**
|
|
79
82
|
* Require that a user has permission, throwing FGADeniedError if not.
|
|
83
|
+
*
|
|
84
|
+
* When `params.permission` is an array, ANY-of semantics apply: passes if any
|
|
85
|
+
* single permission authorizes the user; throws if none do.
|
|
80
86
|
*/
|
|
81
87
|
require(user: WorkOSUser, params: FGACheckParams): Promise<void>;
|
|
82
88
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fga-provider.d.ts","sourceRoot":"","sources":["../src/fga-provider.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EACV,WAAW,EACX,cAAc,EACd,WAAW,EACX,uBAAuB,EACvB,uBAAuB,EACvB,uBAAuB,EACvB,uBAAuB,EACvB,iBAAiB,EACjB,aAAa,EACb,6BAA6B,EAC7B,wBAAwB,EACzB,MAAM,sBAAsB,CAAC;AAI9B,OAAO,KAAK,EAAE,sBAAsB,EAA2B,UAAU,EAAE,MAAM,SAAS,CAAC;AAQ3F,qBAAa,8BAA+B,SAAQ,KAAK;IACvD,QAAQ,CAAC,MAAM,OAAO;IACtB,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;gBAEhB,YAAY,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM;CAWrD;AAED,qBAAa,kCAAmC,SAAQ,KAAK;IAC3D,QAAQ,CAAC,MAAM,OAAO;IACtB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;gBAEb,IAAI,EAAE,UAAU;CAQ7B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,qBAAa,eAAgB,YAAW,WAAW,CAAC,UAAU,CAAC;IAC7D,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,cAAc,CAAC,CAAS;IAChC,OAAO,CAAC,eAAe,CAA0C;IACjE,OAAO,CAAC,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AAC;IAYpE;;OAEG;IACG,UAAU,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAuBnE;;OAEG;IACG,UAAU,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;IActD;;OAEG;IACG,mBAAmB,CAAC,OAAO,EAAE,6BAA6B,GAAG,OAAO,CAAC,iBAAiB,EAAE,CAAC;IAsB/F;;;;;;;;OAQG;IACH,OAAO,CAAC,+BAA+B;IAgCvC;;;OAGG;IACH,OAAO,CAAC,iBAAiB;IAIzB;;OAEG;IACH,OAAO,CAAC,qBAAqB;IAiB7B;;;OAGG;IACH,OAAO,CAAC,iBAAiB;IAezB,OAAO,CAAC,iBAAiB;IAgCzB,OAAO,CAAC,kBAAkB;IAsB1B;;OAEG;YACW,iCAAiC;IAgC/C;;OAEG;IACH,OAAO,CAAC,wBAAwB;CAWjC"}
|
package/dist/index.cjs
CHANGED
|
@@ -848,40 +848,56 @@ var MastraFGAWorkos = class {
|
|
|
848
848
|
*
|
|
849
849
|
* Resolves the user's organization membership ID, maps the permission
|
|
850
850
|
* via `permissionMapping`, and delegates to `workos.authorization.check()`.
|
|
851
|
+
*
|
|
852
|
+
* When `params.permission` is an array, ANY-of semantics apply: returns true
|
|
853
|
+
* if any single permission in the array authorizes the user.
|
|
851
854
|
*/
|
|
852
855
|
async check(user, params) {
|
|
853
|
-
const
|
|
854
|
-
if (
|
|
855
|
-
|
|
856
|
-
const
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
return
|
|
856
|
+
const permissions = Array.isArray(params.permission) ? params.permission : [params.permission];
|
|
857
|
+
if (permissions.length === 0) return false;
|
|
858
|
+
for (const permission of permissions) {
|
|
859
|
+
const checkOptions = this.buildCheckOptions(user, { ...params, permission });
|
|
860
|
+
if (!checkOptions) continue;
|
|
861
|
+
try {
|
|
862
|
+
const result = await this.workos.authorization.check(checkOptions);
|
|
863
|
+
if (result.authorized) return true;
|
|
864
|
+
} catch (error) {
|
|
865
|
+
if (isWorkOSResourceNotFoundError(error)) continue;
|
|
866
|
+
throw error;
|
|
861
867
|
}
|
|
862
|
-
throw error;
|
|
863
868
|
}
|
|
869
|
+
return false;
|
|
864
870
|
}
|
|
865
871
|
/**
|
|
866
872
|
* Require that a user has permission, throwing FGADeniedError if not.
|
|
873
|
+
*
|
|
874
|
+
* When `params.permission` is an array, ANY-of semantics apply: passes if any
|
|
875
|
+
* single permission authorizes the user; throws if none do.
|
|
867
876
|
*/
|
|
868
877
|
async require(user, params) {
|
|
869
|
-
const
|
|
870
|
-
if (
|
|
878
|
+
const permissions = Array.isArray(params.permission) ? params.permission : [params.permission];
|
|
879
|
+
if (permissions.length === 0) {
|
|
871
880
|
throw new ee.FGADeniedError(user, params.resource, params.permission);
|
|
872
881
|
}
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
if (
|
|
881
|
-
|
|
882
|
+
let lastError;
|
|
883
|
+
for (const permission of permissions) {
|
|
884
|
+
const checkOptions = this.buildCheckOptions(
|
|
885
|
+
user,
|
|
886
|
+
{ ...params, permission },
|
|
887
|
+
{ strictMembershipResolution: true }
|
|
888
|
+
);
|
|
889
|
+
if (!checkOptions) continue;
|
|
890
|
+
try {
|
|
891
|
+
const result = await this.workos.authorization.check(checkOptions);
|
|
892
|
+
if (result.authorized) return;
|
|
893
|
+
} catch (error) {
|
|
894
|
+
if (error instanceof ee.FGADeniedError) throw error;
|
|
895
|
+
if (isWorkOSResourceNotFoundError(error)) continue;
|
|
896
|
+
lastError = error;
|
|
882
897
|
}
|
|
883
|
-
throw error;
|
|
884
898
|
}
|
|
899
|
+
if (lastError) throw lastError;
|
|
900
|
+
throw new ee.FGADeniedError(user, params.resource, params.permission);
|
|
885
901
|
}
|
|
886
902
|
/**
|
|
887
903
|
* Filter resources to only those the user has permission to access.
|