@authyon/server 0.2.0-beta.5 → 0.2.0-beta.8

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.
@@ -97,6 +97,10 @@ interface Organization {
97
97
  memberCount?: number;
98
98
  createdAt?: string;
99
99
  updatedAt?: string;
100
+ /** JSON-encoded metadata that may be exposed to tenant members. */
101
+ publicMetadata?: string;
102
+ /** JSON-encoded metadata available only through administrative APIs. */
103
+ privateMetadata?: string;
100
104
  }
101
105
  /** One of a user's tenant memberships, as embedded in `EnvironmentUser.tenantMemberships`. */
102
106
  interface TenantMembership {
@@ -234,6 +238,8 @@ interface CreateOrganizationInput {
234
238
  name: string;
235
239
  slug: string;
236
240
  description?: string;
241
+ publicMetadata?: Record<string, unknown>;
242
+ privateMetadata?: Record<string, unknown>;
237
243
  }
238
244
  interface UpdateOrganizationInput {
239
245
  name: string;
@@ -352,6 +358,12 @@ interface AuthyonServerClientOptions {
352
358
  */
353
359
  clientId?: string;
354
360
  clientSecret?: string;
361
+ /**
362
+ * Originating end-user IP to forward on every API call as `X-Forwarded-For`.
363
+ * Only set this from infrastructure you trust; the SDK rejects comma-separated
364
+ * or whitespace-containing values to avoid forwarded-header injection.
365
+ */
366
+ clientIp?: string;
355
367
  /** API origin. Defaults to `https://api.authyon.com`. */
356
368
  baseUrl?: string;
357
369
  /** Allow an HTTP `baseUrl`. Intended only for explicitly trusted local development. */
@@ -627,6 +639,7 @@ declare class AuthyonServerClient {
627
639
  #private;
628
640
  private readonly envKey?;
629
641
  private readonly clientId?;
642
+ private readonly clientIp?;
630
643
  private readonly transport;
631
644
  private readonly http;
632
645
  private readonly environmentTokenProvider;
@@ -653,6 +666,8 @@ declare class AuthyonServerClient {
653
666
  readonly tenantAuth: {
654
667
  /** POST /tenant/oauth/token — exchanges a tenant's client credentials for a scoped access token. */
655
668
  token: (credentials: ClientCredentials) => Promise<TokenResult>;
669
+ /** POST /tenant/auth/validate — validates an already-minted tenant-client bearer token. */
670
+ validate: (accessToken: string, context?: ClientRequestContext) => Promise<TenantClientValidationResult>;
656
671
  };
657
672
  /**
658
673
  * Scopes a client to a single tenant's OAuth credentials — mints and
@@ -732,7 +747,11 @@ declare class AuthyonServerClient {
732
747
  get: (tenantId: string) => Promise<Organization>;
733
748
  /** PUT /env/tenants/{tenantId} — update a tenant. */
734
749
  update: (tenantId: string, input: UpdateOrganizationInput) => Promise<Organization>;
735
- /** DELETE /env/tenants/{tenantId} — delete a tenant. */
750
+ /** PUT /env/tenants/{tenantId}/metadata - replace public and private metadata. */
751
+ updateMetadata: (tenantId: string, input: Pick<CreateOrganizationInput, "publicMetadata" | "privateMetadata">) => Promise<void>;
752
+ /** POST /env/tenants/{tenantId}/disable — disable without removing tenant data. */
753
+ disable: (tenantId: string) => Promise<void>;
754
+ /** DELETE /env/tenants/{tenantId} — logically delete (disable) a tenant. */
736
755
  delete: (tenantId: string) => Promise<void>;
737
756
  members: {
738
757
  /**
@@ -824,7 +843,7 @@ declare class TenantScopedClient {
824
843
  private getAccessToken;
825
844
  private request;
826
845
  /** POST /tenant/auth/validate — validates this tenant client's current bearer token. */
827
- validate(): Promise<TenantClientValidationResult>;
846
+ validate(context?: ClientRequestContext): Promise<TenantClientValidationResult>;
828
847
  readonly members: {
829
848
  /**
830
849
  * GET /tenant/members — members of the token's tenant.
@@ -872,118 +891,4 @@ declare class TenantScopedClient {
872
891
  /** Convenience factory: `const authyon = createClient({ clientId, clientSecret })`. */
873
892
  declare function createClient(options?: AuthyonServerClientOptions): AuthyonServerClient;
874
893
 
875
- type AbilitySubject = string | Record<string, unknown>;
876
- type AbilityConditions = Record<string, unknown>;
877
- interface AbilityRule {
878
- action: string | string[];
879
- subject: string | string[];
880
- inverted?: boolean;
881
- conditions?: AbilityConditions;
882
- fields?: string[];
883
- reason?: string;
884
- }
885
- interface AuthyonPermissionSource {
886
- permissions?: readonly string[] | null;
887
- roles?: readonly string[] | null;
888
- /** OAuth scopes are also accepted and interpreted as Authyon permissions. */
889
- scope?: string | null;
890
- }
891
- interface AuthyonAbilityOptions {
892
- rules?: readonly AbilityRule[];
893
- /** Rules added when the source contains a matching Authyon role. */
894
- roleRules?: Readonly<Record<string, readonly AbilityRule[]>>;
895
- roles?: readonly string[] | null;
896
- detectSubjectType?: (subject: Record<string, unknown>) => string;
897
- }
898
- type AbilityEvent = "updated";
899
- type AbilityListener = (rules: readonly AbilityRule[]) => void;
900
- /** Isomorphic, deny-by-default authorization engine backed by Authyon permissions. */
901
- declare class AuthyonAbility {
902
- private readonly detectSubjectType;
903
- private currentRules;
904
- private readonly listeners;
905
- constructor(rules?: readonly AbilityRule[], detectSubjectType?: (subject: Record<string, unknown>) => string);
906
- get rules(): readonly AbilityRule[];
907
- can(action: string, subject: AbilitySubject, field?: string): boolean;
908
- cannot(action: string, subject: AbilitySubject, field?: string): boolean;
909
- rulesFor(action: string, subject: string): readonly AbilityRule[];
910
- update(rules: readonly AbilityRule[]): void;
911
- on(event: AbilityEvent, listener: AbilityListener): () => void;
912
- }
913
- /** Fluent rule builder with CASL-like `can` and `cannot` methods. */
914
- declare class AuthyonAbilityBuilder {
915
- readonly rules: AbilityRule[];
916
- can(action: string | string[], subject: string | string[], conditions?: AbilityConditions, fields?: string[]): this;
917
- cannot(action: string | string[], subject: string | string[], conditions?: AbilityConditions, fields?: string[], reason?: string): this;
918
- build(options?: Pick<AuthyonAbilityOptions, "detectSubjectType">): AuthyonAbility;
919
- }
920
- /** Creates an ability from Authyon permissions, OAuth scope and optional role rules. */
921
- declare function createAuthyonAbility(source?: AuthyonPermissionSource, options?: AuthyonAbilityOptions): AuthyonAbility;
922
- /** Checks an Authyon permission string using the same wildcard rules as an ability. */
923
- declare function hasPermission(source: AuthyonPermissionSource | readonly string[], requiredPermission: string): boolean;
924
- /** Converts Authyon's `subject:action` permission strings to authorization rules. */
925
- declare function createAuthyonRules(source?: AuthyonPermissionSource, options?: AuthyonAbilityOptions): AbilityRule[];
926
-
927
- interface AbilityRequirement {
928
- action: string;
929
- subject: AbilitySubject;
930
- field?: string;
931
- }
932
- interface AuthorizationContext {
933
- token: string;
934
- userId?: string;
935
- ability: AuthyonAbility;
936
- permissions: readonly string[];
937
- roles: readonly string[];
938
- }
939
- interface AuthorizationOptions extends AuthyonAbilityOptions {
940
- requirement?: AbilityRequirement;
941
- /** Uses database-backed validation by default; introspection can be selected when desired. */
942
- verification?: "validate" | "introspect" | "jwks";
943
- /** Required for local JWKS verification. Create once and reuse its key cache. */
944
- jwksVerifier?: JwksTokenVerifier;
945
- /** Real end-user IP, obtained from trusted application infrastructure. */
946
- clientIp?: string;
947
- }
948
- declare class AuthorizationError extends Error {
949
- readonly status: 401 | 403 | 503;
950
- readonly code: "authorization.unauthenticated" | "authorization.forbidden" | "authorization.unavailable";
951
- constructor(status: 401 | 403 | 503, code: "authorization.unauthenticated" | "authorization.forbidden" | "authorization.unavailable", message: string);
952
- }
953
- /** Validates a bearer token and creates an Authyon-backed ability for server runtimes. */
954
- declare function authorizeToken(client: AuthyonServerClient, token: string, options?: AuthorizationOptions): Promise<AuthorizationContext>;
955
- /** Works with Web Request objects used by Next.js Route Handlers and other Fetch runtimes. */
956
- declare function authorizeRequest(client: AuthyonServerClient, request: Pick<Request, "headers">, options?: RequestAuthorizationOptions): Promise<AuthorizationContext>;
957
- interface RequestAuthorizationOptions extends AuthorizationOptions {
958
- /** Platform-aware resolver. Only read headers that your trusted proxy overwrites. */
959
- resolveClientIp?: (request: Pick<Request, "headers">) => string | undefined;
960
- }
961
- interface ExpressRequestLike {
962
- headers: Record<string, string | string[] | undefined>;
963
- ip?: string;
964
- socket?: {
965
- remoteAddress?: string;
966
- };
967
- authyon?: AuthorizationContext;
968
- }
969
- interface ExpressResponseLike {
970
- status(code: number): ExpressResponseLike;
971
- json(body: unknown): unknown;
972
- }
973
- type ExpressNext = (error?: unknown) => void;
974
- interface ExpressAuthorizationMiddlewareOptions extends AuthorizationOptions {
975
- /** Property assigned to the request. Defaults to `authyon`. */
976
- requestProperty?: string;
977
- /** Pass authorization errors to Express error middleware instead of writing a JSON response. */
978
- passErrorsToNext?: boolean;
979
- /** Trust Express's proxy-aware `request.ip`. Disabled by default. */
980
- trustProxy?: boolean;
981
- /** Overrides all built-in IP resolution; return only a trusted, single client IP. */
982
- resolveClientIp?: (request: ExpressRequestLike) => string | undefined;
983
- }
984
- /** Dependency-free middleware compatible with Express and similar Connect frameworks. */
985
- declare function createExpressAuthorizationMiddleware(client: AuthyonServerClient, options?: ExpressAuthorizationMiddlewareOptions): (request: ExpressRequestLike & Record<string, unknown>, response: ExpressResponseLike, next: ExpressNext) => Promise<void>;
986
- /** Converts an authorization error into a Fetch Response suitable for Next.js. */
987
- declare function createAuthorizationErrorResponse(error: unknown): Response;
988
-
989
- export { type Organization as $, AuthyonServerClient as A, type CredentialCreator as B, type ClientCredentials as C, type CredentialDetail as D, type CredentialListOptions as E, type CredentialPermissionsInput as F, type CredentialScope as G, type HttpAdapter as H, type EnvironmentUser as I, type ExpressAuthorizationMiddlewareOptions as J, type ExpressNext as K, type ExpressRequestLike as L, type ExpressResponseLike as M, FetchHttpAdapter as N, type HttpAdapterRequest as O, type HttpLogEvent as P, type HttpLogger as Q, type RequestAuthorizationOptions as R, type IntrospectResult as S, type InviteTenantMemberInput as T, type InviteWorkspaceMemberInput as U, type JsonWebKeySet as V, JwksTokenVerifier as W, type JwksTokenVerifierOptions as X, LoggingHttpAdapter as Y, type LoginActivity as Z, type OpenIdConfiguration as _, type AbilitySubject as a, type Paged as a0, type PaginationOptions as a1, type Permission as a2, type PermissionsByRole as a3, PlatformScopedClient as a4, type ReservedPermissions as a5, type Role as a6, type RoleGrant as a7, type RoleInput as a8, type RoleList as a9, authorizeRequest as aA, authorizeToken as aB, createAuthorizationErrorResponse as aC, createAuthyonAbility as aD, createAuthyonRules as aE, createClient as aF, createExpressAuthorizationMiddleware as aG, hasPermission as aH, normalizeClientIp as aI, type RolePermissions as aa, type SafeJwtAlgorithm as ab, type TenantClientValidationResult as ac, type TenantCredentialIssued as ad, type TenantCredentialSummary as ae, type TenantManagementScope as af, type TenantMember as ag, type TenantMemberPage as ah, type TenantMembership as ai, TenantScopedClient as aj, type TokenResult as ak, TokenVerificationError as al, type TokenVerificationErrorCode as am, type UpdateOrganizationInput as an, type User as ao, UserScopedClient as ap, type ValidateResult as aq, type VerifiedAccessToken as ar, type WorkspaceInvite as as, type WorkspaceInviteAccepted as at, type WorkspaceInviteIssued as au, type WorkspaceInvitePreview as av, WorkspaceInvitesClient as aw, type WorkspaceMember as ax, type WorkspaceRole as ay, type WorkspaceTeam as az, AuthorizationError as b, type HttpLoggerOptions as c, type AbilityConditions as d, type AbilityEvent as e, type AbilityListener as f, type AbilityRequirement as g, type AbilityRule as h, type AcceptWorkspaceInviteInput as i, type AccessTokenSource as j, type AuditEvent as k, type AuthorizationContext as l, type AuthorizationOptions as m, AuthyonAbility as n, AuthyonAbilityBuilder as o, type AuthyonAbilityOptions as p, type AuthyonJwksDiscoveryOptions as q, type AuthyonJwtClaims as r, type AuthyonPermissionSource as s, type AuthyonServerClientOptions as t, type ClientRequestContext as u, type CreateCredentialInput as v, type CreateOrganizationInput as w, type CreatePermissionInput as x, type CreateTenantCredentialInput as y, type CreateUserInput as z };
894
+ export { type TenantMemberPage as $, AuthyonServerClient as A, type Organization as B, type ClientCredentials as C, type PaginationOptions as D, type EnvironmentUser as E, FetchHttpAdapter as F, type Permission as G, type HttpAdapter as H, type IntrospectResult as I, type JsonWebKeySet as J, type PermissionsByRole as K, LoggingHttpAdapter as L, PlatformScopedClient as M, type Role as N, type OpenIdConfiguration as O, type Paged as P, type RoleGrant as Q, type ReservedPermissions as R, type RoleInput as S, type RoleList as T, type RolePermissions as U, type SafeJwtAlgorithm as V, type TenantClientValidationResult as W, type TenantCredentialIssued as X, type TenantCredentialSummary as Y, type TenantManagementScope as Z, type TenantMember as _, type HttpLoggerOptions as a, type TenantMembership as a0, TenantScopedClient as a1, type TokenResult as a2, TokenVerificationError as a3, type TokenVerificationErrorCode as a4, type UpdateOrganizationInput as a5, type User as a6, UserScopedClient as a7, type ValidateResult as a8, type VerifiedAccessToken as a9, type WorkspaceInvite as aa, type WorkspaceInviteAccepted as ab, type WorkspaceInviteIssued as ac, type WorkspaceInvitePreview as ad, WorkspaceInvitesClient as ae, type WorkspaceMember as af, type WorkspaceRole as ag, type WorkspaceTeam as ah, createClient as ai, normalizeClientIp as aj, type AcceptWorkspaceInviteInput as b, type AccessTokenSource as c, type AuditEvent as d, type AuthyonJwksDiscoveryOptions as e, type AuthyonJwtClaims as f, type AuthyonServerClientOptions as g, type ClientRequestContext as h, type CreateCredentialInput as i, type CreateOrganizationInput as j, type CreatePermissionInput as k, type CreateTenantCredentialInput as l, type CreateUserInput as m, type CredentialCreator as n, type CredentialDetail as o, type CredentialListOptions as p, type CredentialPermissionsInput as q, type CredentialScope as r, type HttpAdapterRequest as s, type HttpLogEvent as t, type HttpLogger as u, type InviteTenantMemberInput as v, type InviteWorkspaceMemberInput as w, JwksTokenVerifier as x, type JwksTokenVerifierOptions as y, type LoginActivity as z };