@authyon/server 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.
@@ -58,7 +58,9 @@ declare function createAuthyonAbility(source?: AuthyonPermissionSource, options?
58
58
  * Whether a source holds an Authyon permission, by Authyon's own rules: the
59
59
  * values are compared segment by segment, `*` stands for any one segment, and
60
60
  * two values of different lengths never match — except an all-wildcard grant,
61
- * which is everything. OAuth scopes count as permissions.
61
+ * which is everything, and a grant ending in `**`, which stands for one or
62
+ * more segments (`manager:**` covers `manager:account:read` and
63
+ * `manager:account:credentials:write`). OAuth scopes count as permissions.
62
64
  *
63
65
  * Not the same question as {@link AuthyonAbility.can}. An ability is CASL, so
64
66
  * the action `manage` there means "every action on this subject", which is a
@@ -58,7 +58,9 @@ declare function createAuthyonAbility(source?: AuthyonPermissionSource, options?
58
58
  * Whether a source holds an Authyon permission, by Authyon's own rules: the
59
59
  * values are compared segment by segment, `*` stands for any one segment, and
60
60
  * two values of different lengths never match — except an all-wildcard grant,
61
- * which is everything. OAuth scopes count as permissions.
61
+ * which is everything, and a grant ending in `**`, which stands for one or
62
+ * more segments (`manager:**` covers `manager:account:read` and
63
+ * `manager:account:credentials:write`). OAuth scopes count as permissions.
62
64
  *
63
65
  * Not the same question as {@link AuthyonAbility.can}. An ability is CASL, so
64
66
  * the action `manage` there means "every action on this subject", which is a
@@ -238,11 +238,30 @@ function grants(granted, required) {
238
238
  if (isFullWildcard(granted)) return true;
239
239
  const grantedSegments = granted.split(":");
240
240
  const requiredSegments = required.split(":");
241
+ if (isRecursive(grantedSegments) || isRecursive(requiredSegments)) {
242
+ return grantsRecursive(grantedSegments, requiredSegments);
243
+ }
241
244
  if (grantedSegments.length !== requiredSegments.length) return false;
242
245
  return grantedSegments.every(
243
246
  (segment, index) => segment === "*" || segment === requiredSegments[index]
244
247
  );
245
248
  }
249
+ var RECURSIVE_WILDCARD = "**";
250
+ function isRecursive(segments) {
251
+ return segments[segments.length - 1] === RECURSIVE_WILDCARD;
252
+ }
253
+ function grantsRecursive(granted, required) {
254
+ if (!isRecursive(granted)) return false;
255
+ if (granted.slice(0, -1).includes(RECURSIVE_WILDCARD)) return false;
256
+ if (required.slice(0, -1).includes(RECURSIVE_WILDCARD)) return false;
257
+ const prefix = granted.length - 1;
258
+ const requiredPinned = isRecursive(required) ? required.length - 1 : required.length;
259
+ if (isRecursive(required) ? requiredPinned < prefix : requiredPinned <= prefix) return false;
260
+ for (let index = 0; index < prefix; index++) {
261
+ if (granted[index] !== "*" && granted[index] !== required[index]) return false;
262
+ }
263
+ return true;
264
+ }
246
265
  function isWellFormedPermission(permission) {
247
266
  if (!permission) return false;
248
267
  const segments = permission.split(":");
package/dist/index.cjs CHANGED
@@ -1851,11 +1851,30 @@ function grants(granted, required) {
1851
1851
  if (isFullWildcard(granted)) return true;
1852
1852
  const grantedSegments = granted.split(":");
1853
1853
  const requiredSegments = required.split(":");
1854
+ if (isRecursive(grantedSegments) || isRecursive(requiredSegments)) {
1855
+ return grantsRecursive(grantedSegments, requiredSegments);
1856
+ }
1854
1857
  if (grantedSegments.length !== requiredSegments.length) return false;
1855
1858
  return grantedSegments.every(
1856
1859
  (segment2, index) => segment2 === "*" || segment2 === requiredSegments[index]
1857
1860
  );
1858
1861
  }
1862
+ var RECURSIVE_WILDCARD = "**";
1863
+ function isRecursive(segments) {
1864
+ return segments[segments.length - 1] === RECURSIVE_WILDCARD;
1865
+ }
1866
+ function grantsRecursive(granted, required) {
1867
+ if (!isRecursive(granted)) return false;
1868
+ if (granted.slice(0, -1).includes(RECURSIVE_WILDCARD)) return false;
1869
+ if (required.slice(0, -1).includes(RECURSIVE_WILDCARD)) return false;
1870
+ const prefix = granted.length - 1;
1871
+ const requiredPinned = isRecursive(required) ? required.length - 1 : required.length;
1872
+ if (isRecursive(required) ? requiredPinned < prefix : requiredPinned <= prefix) return false;
1873
+ for (let index = 0; index < prefix; index++) {
1874
+ if (granted[index] !== "*" && granted[index] !== required[index]) return false;
1875
+ }
1876
+ return true;
1877
+ }
1859
1878
  function isWellFormedPermission(permission) {
1860
1879
  if (!permission) return false;
1861
1880
  const segments = permission.split(":");
package/dist/index.d.cts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { H as HttpAdapter, a as HttpLoggerOptions, A as AuthyonServerClient } from './authyonServerClient-6ezHxvwa.cjs';
2
2
  export { b as AcceptTenantInviteInput, c as AccessTokenSource, d as Approval, e as ApprovalAssurance, f as ApprovalPayload, g as ApprovalStatus, h as ApprovalWebAuthnOptions, i as AuditEvent, j as AuthyonJwksDiscoveryOptions, k as AuthyonJwtClaims, l as AuthyonServerClientOptions, m as AuthyonTenantClaim, C as CLIENT_IP_HEADER, n as ClientCredentials, o as ClientRequestContext, p as ConfirmApprovalInput, q as ConsumedApproval, r as CreateApprovalInput, s as CreateCredentialInput, t as CreateOrganizationInput, u as CreatePermissionInput, v as CreateTenantCredentialInput, w as CreateUserInput, x as CredentialCreator, y as CredentialDetail, z as CredentialListOptions, B as CredentialPermissionsInput, E as EnvironmentUser, F as FetchHttpAdapter, D as HttpAdapterRequest, G as HttpLogEvent, I as HttpLogger, K as IntrospectResult, L as InviteTenantMemberInput, M as IssuePasswordResetInput, N as JsonWebKeySet, J as JwksTokenVerifier, O as JwksTokenVerifierOptions, P as LoggingHttpAdapter, Q as LoginActivity, R as OpenIdConfiguration, S as Organization, T as OtpCheckResult, U as Paged, V as PaginationOptions, W as PasswordResetCompleted, X as PasswordResetIssued, Y as PasswordResetPreview, Z as Permission, _ as PermissionsByRole, $ as ReservedPermissions, a0 as Role, a1 as RoleGrant, a2 as RoleInput, a3 as RoleList, a4 as RolePermissions, a5 as SafeJwtAlgorithm, a6 as SecurityMethods, a7 as SubjectApprovals, a8 as SubjectSecurity, a9 as TENANT_FILTER_MAX_DEPTH, aa as TENANT_FILTER_MAX_VALUES, ab as TENANT_FILTER_MAX_VALUE_LENGTH, ac as TenantAncestor, ad as TenantClientValidationResult, ae as TenantCredentialIssued, af as TenantCredentialSummary, ag as TenantFilterExpression, ah as TenantFilterValue, ai as TenantInvite, aj as TenantInviteAccepted, ak as TenantInviteInput, al as TenantInviteIssued, am as TenantInvitePreview, an as TenantInviteStatus, ao as TenantListOptions, ap as TenantMember, aq as TenantMemberPage, ar as TenantMembership, as as TenantOrderField, at as TenantScopedClient, au as TokenResult, av as TokenVerificationError, aw as TokenVerificationErrorCode, ax as UpdateOrganizationInput, ay as User, az as UserScopedClient, aA as ValidateResult, aB as VerifiedAccessToken, aC as createClient, aD as normalizeClientIp, aE as tenantFilter } from './authyonServerClient-6ezHxvwa.cjs';
3
- export { b as AbilityConditions, c as AbilityEvent, d as AbilityListener, e as AbilityRequirement, f as AbilityRule, A as AbilitySubject, g as AuthorizationContext, a as AuthorizationError, h as AuthorizationOptions, i as AuthyonAbility, j as AuthyonAbilityBuilder, k as AuthyonAbilityOptions, l as AuthyonPermissionSource, E as ExpressAuthorizationMiddlewareOptions, m as ExpressNext, n as ExpressRequestLike, o as ExpressResponseLike, P as PermissionGroup, R as RequestAuthorizationOptions, p as authorizeRequest, q as authorizeToken, r as createAuthorizationErrorResponse, s as createAuthyonAbility, t as createAuthyonRules, u as createExpressAuthorizationMiddleware, v as hasPermission, w as hasPermissionGroup } from './authorization-BLVSHGQu.cjs';
3
+ export { b as AbilityConditions, c as AbilityEvent, d as AbilityListener, e as AbilityRequirement, f as AbilityRule, A as AbilitySubject, g as AuthorizationContext, a as AuthorizationError, h as AuthorizationOptions, i as AuthyonAbility, j as AuthyonAbilityBuilder, k as AuthyonAbilityOptions, l as AuthyonPermissionSource, E as ExpressAuthorizationMiddlewareOptions, m as ExpressNext, n as ExpressRequestLike, o as ExpressResponseLike, P as PermissionGroup, R as RequestAuthorizationOptions, p as authorizeRequest, q as authorizeToken, r as createAuthorizationErrorResponse, s as createAuthyonAbility, t as createAuthyonRules, u as createExpressAuthorizationMiddleware, v as hasPermission, w as hasPermissionGroup } from './authorization-CDHWMYT7.cjs';
4
4
  import 'jose';
5
5
 
6
6
  declare const ErrorCodes: {
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { H as HttpAdapter, a as HttpLoggerOptions, A as AuthyonServerClient } from './authyonServerClient-6ezHxvwa.js';
2
2
  export { b as AcceptTenantInviteInput, c as AccessTokenSource, d as Approval, e as ApprovalAssurance, f as ApprovalPayload, g as ApprovalStatus, h as ApprovalWebAuthnOptions, i as AuditEvent, j as AuthyonJwksDiscoveryOptions, k as AuthyonJwtClaims, l as AuthyonServerClientOptions, m as AuthyonTenantClaim, C as CLIENT_IP_HEADER, n as ClientCredentials, o as ClientRequestContext, p as ConfirmApprovalInput, q as ConsumedApproval, r as CreateApprovalInput, s as CreateCredentialInput, t as CreateOrganizationInput, u as CreatePermissionInput, v as CreateTenantCredentialInput, w as CreateUserInput, x as CredentialCreator, y as CredentialDetail, z as CredentialListOptions, B as CredentialPermissionsInput, E as EnvironmentUser, F as FetchHttpAdapter, D as HttpAdapterRequest, G as HttpLogEvent, I as HttpLogger, K as IntrospectResult, L as InviteTenantMemberInput, M as IssuePasswordResetInput, N as JsonWebKeySet, J as JwksTokenVerifier, O as JwksTokenVerifierOptions, P as LoggingHttpAdapter, Q as LoginActivity, R as OpenIdConfiguration, S as Organization, T as OtpCheckResult, U as Paged, V as PaginationOptions, W as PasswordResetCompleted, X as PasswordResetIssued, Y as PasswordResetPreview, Z as Permission, _ as PermissionsByRole, $ as ReservedPermissions, a0 as Role, a1 as RoleGrant, a2 as RoleInput, a3 as RoleList, a4 as RolePermissions, a5 as SafeJwtAlgorithm, a6 as SecurityMethods, a7 as SubjectApprovals, a8 as SubjectSecurity, a9 as TENANT_FILTER_MAX_DEPTH, aa as TENANT_FILTER_MAX_VALUES, ab as TENANT_FILTER_MAX_VALUE_LENGTH, ac as TenantAncestor, ad as TenantClientValidationResult, ae as TenantCredentialIssued, af as TenantCredentialSummary, ag as TenantFilterExpression, ah as TenantFilterValue, ai as TenantInvite, aj as TenantInviteAccepted, ak as TenantInviteInput, al as TenantInviteIssued, am as TenantInvitePreview, an as TenantInviteStatus, ao as TenantListOptions, ap as TenantMember, aq as TenantMemberPage, ar as TenantMembership, as as TenantOrderField, at as TenantScopedClient, au as TokenResult, av as TokenVerificationError, aw as TokenVerificationErrorCode, ax as UpdateOrganizationInput, ay as User, az as UserScopedClient, aA as ValidateResult, aB as VerifiedAccessToken, aC as createClient, aD as normalizeClientIp, aE as tenantFilter } from './authyonServerClient-6ezHxvwa.js';
3
- export { b as AbilityConditions, c as AbilityEvent, d as AbilityListener, e as AbilityRequirement, f as AbilityRule, A as AbilitySubject, g as AuthorizationContext, a as AuthorizationError, h as AuthorizationOptions, i as AuthyonAbility, j as AuthyonAbilityBuilder, k as AuthyonAbilityOptions, l as AuthyonPermissionSource, E as ExpressAuthorizationMiddlewareOptions, m as ExpressNext, n as ExpressRequestLike, o as ExpressResponseLike, P as PermissionGroup, R as RequestAuthorizationOptions, p as authorizeRequest, q as authorizeToken, r as createAuthorizationErrorResponse, s as createAuthyonAbility, t as createAuthyonRules, u as createExpressAuthorizationMiddleware, v as hasPermission, w as hasPermissionGroup } from './authorization-DPymgDb8.js';
3
+ export { b as AbilityConditions, c as AbilityEvent, d as AbilityListener, e as AbilityRequirement, f as AbilityRule, A as AbilitySubject, g as AuthorizationContext, a as AuthorizationError, h as AuthorizationOptions, i as AuthyonAbility, j as AuthyonAbilityBuilder, k as AuthyonAbilityOptions, l as AuthyonPermissionSource, E as ExpressAuthorizationMiddlewareOptions, m as ExpressNext, n as ExpressRequestLike, o as ExpressResponseLike, P as PermissionGroup, R as RequestAuthorizationOptions, p as authorizeRequest, q as authorizeToken, r as createAuthorizationErrorResponse, s as createAuthyonAbility, t as createAuthyonRules, u as createExpressAuthorizationMiddleware, v as hasPermission, w as hasPermissionGroup } from './authorization-BBwAqaR4.js';
4
4
  import 'jose';
5
5
 
6
6
  declare const ErrorCodes: {
package/dist/index.js CHANGED
@@ -25,7 +25,7 @@ import {
25
25
  hasPermission,
26
26
  hasPermissionGroup,
27
27
  normalizeClientIp
28
- } from "./chunk-WF26WYSX.js";
28
+ } from "./chunk-V6JQIOSP.js";
29
29
  import {
30
30
  __privateAdd,
31
31
  __privateGet,
package/dist/next.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { ReactNode } from 'react';
2
- import { R as RequestAuthorizationOptions, A as AbilitySubject, a as AuthorizationError } from './authorization-BLVSHGQu.cjs';
2
+ import { R as RequestAuthorizationOptions, A as AbilitySubject, a as AuthorizationError } from './authorization-CDHWMYT7.cjs';
3
3
  import { A as AuthyonServerClient } from './authyonServerClient-6ezHxvwa.cjs';
4
4
  import 'jose';
5
5
 
package/dist/next.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { ReactNode } from 'react';
2
- import { R as RequestAuthorizationOptions, A as AbilitySubject, a as AuthorizationError } from './authorization-DPymgDb8.js';
2
+ import { R as RequestAuthorizationOptions, A as AbilitySubject, a as AuthorizationError } from './authorization-BBwAqaR4.js';
3
3
  import { A as AuthyonServerClient } from './authyonServerClient-6ezHxvwa.js';
4
4
  import 'jose';
5
5
 
package/dist/next.js CHANGED
@@ -2,7 +2,7 @@ import {
2
2
  AuthorizationError,
3
3
  authorizeRequest,
4
4
  authorizeToken
5
- } from "./chunk-WF26WYSX.js";
5
+ } from "./chunk-V6JQIOSP.js";
6
6
  import "./chunk-77J4NURK.js";
7
7
 
8
8
  // src/next.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@authyon/server",
3
- "version": "0.2.0-beta.25",
3
+ "version": "0.2.0-beta.26",
4
4
  "description": "Authyon SDK for backends — server-to-server organization/member management and access-token verification.",
5
5
  "license": "MIT",
6
6
  "type": "module",