@authyon/auth 0.2.0-beta.25 → 0.2.0-beta.26

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.
@@ -996,7 +996,9 @@ declare function createAuthyonAbility(source?: AuthyonPermissionSource, options?
996
996
  * Whether a source holds an Authyon permission, by Authyon's own rules: the
997
997
  * values are compared segment by segment, `*` stands for any one segment, and
998
998
  * two values of different lengths never match — except an all-wildcard grant,
999
- * which is everything. OAuth scopes count as permissions.
999
+ * which is everything, and a grant ending in `**`, which stands for one or
1000
+ * more segments (`manager:**` covers `manager:account:read` and
1001
+ * `manager:account:credentials:write`). OAuth scopes count as permissions.
1000
1002
  *
1001
1003
  * Not the same question as {@link AuthyonAbility.can}. An ability is CASL, so
1002
1004
  * the action `manage` there means "every action on this subject", which is a
@@ -996,7 +996,9 @@ declare function createAuthyonAbility(source?: AuthyonPermissionSource, options?
996
996
  * Whether a source holds an Authyon permission, by Authyon's own rules: the
997
997
  * values are compared segment by segment, `*` stands for any one segment, and
998
998
  * two values of different lengths never match — except an all-wildcard grant,
999
- * which is everything. OAuth scopes count as permissions.
999
+ * which is everything, and a grant ending in `**`, which stands for one or
1000
+ * more segments (`manager:**` covers `manager:account:read` and
1001
+ * `manager:account:credentials:write`). OAuth scopes count as permissions.
1000
1002
  *
1001
1003
  * Not the same question as {@link AuthyonAbility.can}. An ability is CASL, so
1002
1004
  * the action `manage` there means "every action on this subject", which is a
@@ -208,11 +208,30 @@ function grants(granted, required) {
208
208
  if (isFullWildcard(granted)) return true;
209
209
  const grantedSegments = granted.split(":");
210
210
  const requiredSegments = required.split(":");
211
+ if (isRecursive(grantedSegments) || isRecursive(requiredSegments)) {
212
+ return grantsRecursive(grantedSegments, requiredSegments);
213
+ }
211
214
  if (grantedSegments.length !== requiredSegments.length) return false;
212
215
  return grantedSegments.every(
213
216
  (segment, index) => segment === "*" || segment === requiredSegments[index]
214
217
  );
215
218
  }
219
+ var RECURSIVE_WILDCARD = "**";
220
+ function isRecursive(segments) {
221
+ return segments[segments.length - 1] === RECURSIVE_WILDCARD;
222
+ }
223
+ function grantsRecursive(granted, required) {
224
+ if (!isRecursive(granted)) return false;
225
+ if (granted.slice(0, -1).includes(RECURSIVE_WILDCARD)) return false;
226
+ if (required.slice(0, -1).includes(RECURSIVE_WILDCARD)) return false;
227
+ const prefix = granted.length - 1;
228
+ const requiredPinned = isRecursive(required) ? required.length - 1 : required.length;
229
+ if (isRecursive(required) ? requiredPinned < prefix : requiredPinned <= prefix) return false;
230
+ for (let index = 0; index < prefix; index++) {
231
+ if (granted[index] !== "*" && granted[index] !== required[index]) return false;
232
+ }
233
+ return true;
234
+ }
216
235
  function isWellFormedPermission(permission) {
217
236
  if (!permission) return false;
218
237
  const segments = permission.split(":");
package/dist/index.cjs CHANGED
@@ -1360,11 +1360,30 @@ function grants(granted, required) {
1360
1360
  if (isFullWildcard(granted)) return true;
1361
1361
  const grantedSegments = granted.split(":");
1362
1362
  const requiredSegments = required.split(":");
1363
+ if (isRecursive(grantedSegments) || isRecursive(requiredSegments)) {
1364
+ return grantsRecursive(grantedSegments, requiredSegments);
1365
+ }
1363
1366
  if (grantedSegments.length !== requiredSegments.length) return false;
1364
1367
  return grantedSegments.every(
1365
1368
  (segment, index) => segment === "*" || segment === requiredSegments[index]
1366
1369
  );
1367
1370
  }
1371
+ var RECURSIVE_WILDCARD = "**";
1372
+ function isRecursive(segments) {
1373
+ return segments[segments.length - 1] === RECURSIVE_WILDCARD;
1374
+ }
1375
+ function grantsRecursive(granted, required) {
1376
+ if (!isRecursive(granted)) return false;
1377
+ if (granted.slice(0, -1).includes(RECURSIVE_WILDCARD)) return false;
1378
+ if (required.slice(0, -1).includes(RECURSIVE_WILDCARD)) return false;
1379
+ const prefix = granted.length - 1;
1380
+ const requiredPinned = isRecursive(required) ? required.length - 1 : required.length;
1381
+ if (isRecursive(required) ? requiredPinned < prefix : requiredPinned <= prefix) return false;
1382
+ for (let index = 0; index < prefix; index++) {
1383
+ if (granted[index] !== "*" && granted[index] !== required[index]) return false;
1384
+ }
1385
+ return true;
1386
+ }
1368
1387
  function isWellFormedPermission(permission) {
1369
1388
  if (!permission) return false;
1370
1389
  const segments = permission.split(":");
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { T as TokenStorage, H as HttpAdapter, a as HttpLoggerOptions, A as AuthyonClient } from './ability-DjEMCVjx.cjs';
2
- export { b as AbilityConditions, c as AbilityEvent, d as AbilityListener, e as AbilityRule, f as AbilitySubject, g as AcceptOrganizationInviteInput, h as Activity, i as Approval, j as ApprovalAssurance, k as ApprovalPayload, l as ApprovalStatus, m as ApprovalWebAuthnOptions, n as AuthEvent, o as AuthState, p as AuthStateListener, q as AuthenticatorSetup, r as AuthyonAbility, s as AuthyonAbilityBuilder, t as AuthyonAbilityOptions, u as AuthyonClientOptions, v as AuthyonPermissionSource, w as AuthyonSessionController, C as ConfirmApprovalInput, x as CreateOrganizationInput, F as FetchHttpAdapter, y as HttpAdapterRequest, z as HttpLogEvent, B as HttpLogger, I as IntrospectResult, D as InviteMemberInput, L as LoggingHttpAdapter, E as LoginInput, G as LoginResult, O as Organization, J as OrganizationInvite, K as OrganizationInviteAccepted, M as OrganizationInviteInput, N as OrganizationInviteIssued, P as OrganizationInvitePreview, Q as OrganizationInviteStatus, R as OrganizationMember, S as Paged, U as PaginationOptions, V as PasswordResetCompleted, W as PasswordResetPreview, X as PasswordResetRequestOptions, Y as PermissionGroup, Z as RegisterInput, _ as Role, $ as SecurityMethods, a0 as Session, a1 as SessionControllerOptions, a2 as SessionInfo, a3 as SessionSnapshot, a4 as SessionSnapshotListener, a5 as SessionStatus, a6 as SsoProvider, a7 as SubjectApprovals, a8 as SubjectSecurity, a9 as TwoFactorChallenge, aa as TwoFactorMethod, ab as TwoFactorStatus, ac as User, ad as ValidateResult, ae as VerifyTwoFactorInput, af as WebAuthnAssertion, ag as WebAuthnCeremonyStart, ah as WebAuthnCredential, ai as createAuthyonAbility, aj as createAuthyonRules, ak as createClient, al as hasPermission, am as hasPermissionGroup } from './ability-DjEMCVjx.cjs';
1
+ import { T as TokenStorage, H as HttpAdapter, a as HttpLoggerOptions, A as AuthyonClient } from './ability-BE38_bgr.cjs';
2
+ export { b as AbilityConditions, c as AbilityEvent, d as AbilityListener, e as AbilityRule, f as AbilitySubject, g as AcceptOrganizationInviteInput, h as Activity, i as Approval, j as ApprovalAssurance, k as ApprovalPayload, l as ApprovalStatus, m as ApprovalWebAuthnOptions, n as AuthEvent, o as AuthState, p as AuthStateListener, q as AuthenticatorSetup, r as AuthyonAbility, s as AuthyonAbilityBuilder, t as AuthyonAbilityOptions, u as AuthyonClientOptions, v as AuthyonPermissionSource, w as AuthyonSessionController, C as ConfirmApprovalInput, x as CreateOrganizationInput, F as FetchHttpAdapter, y as HttpAdapterRequest, z as HttpLogEvent, B as HttpLogger, I as IntrospectResult, D as InviteMemberInput, L as LoggingHttpAdapter, E as LoginInput, G as LoginResult, O as Organization, J as OrganizationInvite, K as OrganizationInviteAccepted, M as OrganizationInviteInput, N as OrganizationInviteIssued, P as OrganizationInvitePreview, Q as OrganizationInviteStatus, R as OrganizationMember, S as Paged, U as PaginationOptions, V as PasswordResetCompleted, W as PasswordResetPreview, X as PasswordResetRequestOptions, Y as PermissionGroup, Z as RegisterInput, _ as Role, $ as SecurityMethods, a0 as Session, a1 as SessionControllerOptions, a2 as SessionInfo, a3 as SessionSnapshot, a4 as SessionSnapshotListener, a5 as SessionStatus, a6 as SsoProvider, a7 as SubjectApprovals, a8 as SubjectSecurity, a9 as TwoFactorChallenge, aa as TwoFactorMethod, ab as TwoFactorStatus, ac as User, ad as ValidateResult, ae as VerifyTwoFactorInput, af as WebAuthnAssertion, ag as WebAuthnCeremonyStart, ah as WebAuthnCredential, ai as createAuthyonAbility, aj as createAuthyonRules, ak as createClient, al as hasPermission, am as hasPermissionGroup } from './ability-BE38_bgr.cjs';
3
3
 
4
4
  declare const ErrorCodes: {
5
5
  readonly Unknown: "unknown";
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { T as TokenStorage, H as HttpAdapter, a as HttpLoggerOptions, A as AuthyonClient } from './ability-DjEMCVjx.js';
2
- export { b as AbilityConditions, c as AbilityEvent, d as AbilityListener, e as AbilityRule, f as AbilitySubject, g as AcceptOrganizationInviteInput, h as Activity, i as Approval, j as ApprovalAssurance, k as ApprovalPayload, l as ApprovalStatus, m as ApprovalWebAuthnOptions, n as AuthEvent, o as AuthState, p as AuthStateListener, q as AuthenticatorSetup, r as AuthyonAbility, s as AuthyonAbilityBuilder, t as AuthyonAbilityOptions, u as AuthyonClientOptions, v as AuthyonPermissionSource, w as AuthyonSessionController, C as ConfirmApprovalInput, x as CreateOrganizationInput, F as FetchHttpAdapter, y as HttpAdapterRequest, z as HttpLogEvent, B as HttpLogger, I as IntrospectResult, D as InviteMemberInput, L as LoggingHttpAdapter, E as LoginInput, G as LoginResult, O as Organization, J as OrganizationInvite, K as OrganizationInviteAccepted, M as OrganizationInviteInput, N as OrganizationInviteIssued, P as OrganizationInvitePreview, Q as OrganizationInviteStatus, R as OrganizationMember, S as Paged, U as PaginationOptions, V as PasswordResetCompleted, W as PasswordResetPreview, X as PasswordResetRequestOptions, Y as PermissionGroup, Z as RegisterInput, _ as Role, $ as SecurityMethods, a0 as Session, a1 as SessionControllerOptions, a2 as SessionInfo, a3 as SessionSnapshot, a4 as SessionSnapshotListener, a5 as SessionStatus, a6 as SsoProvider, a7 as SubjectApprovals, a8 as SubjectSecurity, a9 as TwoFactorChallenge, aa as TwoFactorMethod, ab as TwoFactorStatus, ac as User, ad as ValidateResult, ae as VerifyTwoFactorInput, af as WebAuthnAssertion, ag as WebAuthnCeremonyStart, ah as WebAuthnCredential, ai as createAuthyonAbility, aj as createAuthyonRules, ak as createClient, al as hasPermission, am as hasPermissionGroup } from './ability-DjEMCVjx.js';
1
+ import { T as TokenStorage, H as HttpAdapter, a as HttpLoggerOptions, A as AuthyonClient } from './ability-BE38_bgr.js';
2
+ export { b as AbilityConditions, c as AbilityEvent, d as AbilityListener, e as AbilityRule, f as AbilitySubject, g as AcceptOrganizationInviteInput, h as Activity, i as Approval, j as ApprovalAssurance, k as ApprovalPayload, l as ApprovalStatus, m as ApprovalWebAuthnOptions, n as AuthEvent, o as AuthState, p as AuthStateListener, q as AuthenticatorSetup, r as AuthyonAbility, s as AuthyonAbilityBuilder, t as AuthyonAbilityOptions, u as AuthyonClientOptions, v as AuthyonPermissionSource, w as AuthyonSessionController, C as ConfirmApprovalInput, x as CreateOrganizationInput, F as FetchHttpAdapter, y as HttpAdapterRequest, z as HttpLogEvent, B as HttpLogger, I as IntrospectResult, D as InviteMemberInput, L as LoggingHttpAdapter, E as LoginInput, G as LoginResult, O as Organization, J as OrganizationInvite, K as OrganizationInviteAccepted, M as OrganizationInviteInput, N as OrganizationInviteIssued, P as OrganizationInvitePreview, Q as OrganizationInviteStatus, R as OrganizationMember, S as Paged, U as PaginationOptions, V as PasswordResetCompleted, W as PasswordResetPreview, X as PasswordResetRequestOptions, Y as PermissionGroup, Z as RegisterInput, _ as Role, $ as SecurityMethods, a0 as Session, a1 as SessionControllerOptions, a2 as SessionInfo, a3 as SessionSnapshot, a4 as SessionSnapshotListener, a5 as SessionStatus, a6 as SsoProvider, a7 as SubjectApprovals, a8 as SubjectSecurity, a9 as TwoFactorChallenge, aa as TwoFactorMethod, ab as TwoFactorStatus, ac as User, ad as ValidateResult, ae as VerifyTwoFactorInput, af as WebAuthnAssertion, ag as WebAuthnCeremonyStart, ah as WebAuthnCredential, ai as createAuthyonAbility, aj as createAuthyonRules, ak as createClient, al as hasPermission, am as hasPermissionGroup } from './ability-BE38_bgr.js';
3
3
 
4
4
  declare const ErrorCodes: {
5
5
  readonly Unknown: "unknown";
package/dist/index.js CHANGED
@@ -6,7 +6,7 @@ import {
6
6
  createAuthyonRules,
7
7
  hasPermission,
8
8
  hasPermissionGroup
9
- } from "./chunk-IX6U6A72.js";
9
+ } from "./chunk-3MOFQ3S4.js";
10
10
 
11
11
  // ../../internal/core/security/approvals.ts
12
12
  function path(id, suffix = "") {
@@ -1,7 +1,7 @@
1
1
  import * as react from 'react';
2
2
  import { ReactNode } from 'react';
3
- import { ac as User, a1 as SessionControllerOptions, A as AuthyonClient, a3 as SessionSnapshot, a0 as Session, f as AbilitySubject, t as AuthyonAbilityOptions, r as AuthyonAbility } from '../ability-DjEMCVjx.cjs';
4
- export { w as AuthyonSessionController, a4 as SessionSnapshotListener, a5 as SessionStatus } from '../ability-DjEMCVjx.cjs';
3
+ import { ac as User, a1 as SessionControllerOptions, A as AuthyonClient, a3 as SessionSnapshot, a0 as Session, f as AbilitySubject, t as AuthyonAbilityOptions, r as AuthyonAbility } from '../ability-BE38_bgr.cjs';
4
+ export { w as AuthyonSessionController, a4 as SessionSnapshotListener, a5 as SessionStatus } from '../ability-BE38_bgr.cjs';
5
5
 
6
6
  interface AuthyonProviderProps<TUser extends User = User> extends SessionControllerOptions {
7
7
  client: AuthyonClient;
@@ -1,7 +1,7 @@
1
1
  import * as react from 'react';
2
2
  import { ReactNode } from 'react';
3
- import { ac as User, a1 as SessionControllerOptions, A as AuthyonClient, a3 as SessionSnapshot, a0 as Session, f as AbilitySubject, t as AuthyonAbilityOptions, r as AuthyonAbility } from '../ability-DjEMCVjx.js';
4
- export { w as AuthyonSessionController, a4 as SessionSnapshotListener, a5 as SessionStatus } from '../ability-DjEMCVjx.js';
3
+ import { ac as User, a1 as SessionControllerOptions, A as AuthyonClient, a3 as SessionSnapshot, a0 as Session, f as AbilitySubject, t as AuthyonAbilityOptions, r as AuthyonAbility } from '../ability-BE38_bgr.js';
4
+ export { w as AuthyonSessionController, a4 as SessionSnapshotListener, a5 as SessionStatus } from '../ability-BE38_bgr.js';
5
5
 
6
6
  interface AuthyonProviderProps<TUser extends User = User> extends SessionControllerOptions {
7
7
  client: AuthyonClient;
@@ -2,7 +2,7 @@
2
2
  import {
3
3
  AuthyonSessionController,
4
4
  createAuthyonAbility
5
- } from "../chunk-IX6U6A72.js";
5
+ } from "../chunk-3MOFQ3S4.js";
6
6
 
7
7
  // src/react/index.tsx
8
8
  import {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@authyon/auth",
3
- "version": "0.2.0-beta.25",
3
+ "version": "0.2.0-beta.26",
4
4
  "description": "Authyon SDK for browsers — auth, sessions, multi-tenant and 2FA for vanilla JS/TS.",
5
5
  "license": "MIT",
6
6
  "type": "module",