@authyon/server 0.2.0-beta.2 → 0.2.0-beta.3

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/dist/index.d.ts CHANGED
@@ -1,12 +1,5 @@
1
1
  import { JSONWebKeySet, JWTPayload, JWSHeaderParameters } from 'jose';
2
2
 
3
- interface ClientRequestContext {
4
- /** Real end-user IP, resolved only from infrastructure trusted by the application. */
5
- clientIp?: string;
6
- }
7
- /** Rejects header injection and values that are not a single IPv4 or IPv6 address. */
8
- declare function normalizeClientIp(value: string): string;
9
-
10
3
  interface HttpAdapterRequest {
11
4
  url: string;
12
5
  method: string;
@@ -282,6 +275,34 @@ type LoginActivity = AuditEvent;
282
275
  * live for `/env/users`, `/env/audit` and `/env/audit/login-activity`.
283
276
  * Endpoints without `skip`/`take` params return a bare array instead.
284
277
  */
278
+ /** Tenant credential metadata. Listing never returns the secret. */
279
+ interface TenantCredentialSummary {
280
+ id: string;
281
+ clientId: string;
282
+ description: string | null;
283
+ createdAt: string;
284
+ lastUsedAt: string | null;
285
+ revokedAt: string | null;
286
+ expiresAt: string | null;
287
+ isActive: boolean;
288
+ permissions: string[];
289
+ }
290
+ /** Input for a tenant machine credential. Requires at least one explicit permission. */
291
+ interface CreateTenantCredentialInput {
292
+ description: string;
293
+ /** Number of days until the tenant credential expires. Omit for no automatic expiration. */
294
+ lifetimeDays?: number | null;
295
+ permissions: string[];
296
+ }
297
+ /** The plaintext secret is returned only when the credential is issued. */
298
+ interface TenantCredentialIssued {
299
+ credentialId: string;
300
+ clientId: string;
301
+ clientSecret: string;
302
+ createdAt: string;
303
+ expiresAt: string | null;
304
+ permissions: string[];
305
+ }
285
306
  /** OAuth 2.0 client-credentials pair minted in the Authyon console. */
286
307
  interface ClientCredentials {
287
308
  clientId: string;
@@ -334,6 +355,252 @@ interface AuthyonServerClientOptions {
334
355
  fetch?: typeof fetch;
335
356
  }
336
357
 
358
+ /** A token of the requested authentication plane, or a provider called for each request. */
359
+ type AccessTokenSource = string | (() => string | Promise<string>);
360
+ interface CredentialListOptions extends PaginationOptions {
361
+ search?: string;
362
+ }
363
+ /** scopes is an alias for permissions. Always supply an explicit, nonempty set. */
364
+ type CredentialPermissionsInput = {
365
+ permissions: readonly string[];
366
+ scopes?: never;
367
+ } | {
368
+ scopes: readonly string[];
369
+ permissions?: never;
370
+ };
371
+ type CreateCredentialInput = CredentialPermissionsInput & {
372
+ description?: string;
373
+ lifetimeDays?: number | null;
374
+ };
375
+ interface CredentialScope {
376
+ workspaceId: string;
377
+ environmentId: string;
378
+ tenantId?: string;
379
+ }
380
+ interface TenantManagementScope extends CredentialScope {
381
+ tenantId: string;
382
+ }
383
+ interface CredentialCreator {
384
+ id: string | null;
385
+ type: string;
386
+ displayName: string | null;
387
+ }
388
+ interface CredentialDetail extends TenantCredentialSummary {
389
+ createdBy: CredentialCreator | null;
390
+ updatedAt: string | null;
391
+ secretRotatedAt: string | null;
392
+ expiresAt: string | null;
393
+ ageSeconds: number;
394
+ /** Null while active; elapsed lifetime at revocation otherwise. */
395
+ lifetimeSeconds: number | null;
396
+ accessTokenLifetimeSeconds: number;
397
+ }
398
+ type WorkspaceRole = "admin" | "auditor";
399
+ interface WorkspaceMember {
400
+ memberId: string | null;
401
+ userId: string;
402
+ email: string;
403
+ name: string;
404
+ role: string;
405
+ isOwner: boolean;
406
+ isSelf: boolean;
407
+ invitedByName: string | null;
408
+ joinedAt: string;
409
+ lastLoginAt: string | null;
410
+ }
411
+ interface WorkspaceInvite {
412
+ id: string;
413
+ email: string;
414
+ role: string;
415
+ invitedByName: string | null;
416
+ createdAt: string;
417
+ expiresAt: string;
418
+ }
419
+ interface WorkspaceTeam {
420
+ workspaceId: string;
421
+ workspaceName: string;
422
+ callerRole: string;
423
+ canManage: boolean;
424
+ members: WorkspaceMember[];
425
+ pendingInvites: WorkspaceInvite[];
426
+ }
427
+ interface InviteWorkspaceMemberInput {
428
+ email: string;
429
+ role: WorkspaceRole;
430
+ }
431
+ interface WorkspaceInviteIssued {
432
+ inviteId: string;
433
+ email: string;
434
+ role: string;
435
+ /** Sensitive bearer link returned at issuance. Do not log or persist in public storage. */
436
+ acceptUrl: string;
437
+ expiresAt: string;
438
+ }
439
+ interface WorkspaceInvitePreview {
440
+ workspaceName: string;
441
+ email: string;
442
+ role: string;
443
+ expiresAt: string;
444
+ requiresRegistration: boolean;
445
+ }
446
+ interface WorkspaceInviteAccepted {
447
+ workspaceId: string;
448
+ workspaceName: string;
449
+ role: string;
450
+ accountCreated: boolean;
451
+ }
452
+ interface AcceptWorkspaceInviteInput {
453
+ name?: string;
454
+ password?: string;
455
+ }
456
+ interface InviteTenantMemberInput {
457
+ email: string;
458
+ roles?: string[];
459
+ }
460
+ interface TenantMember {
461
+ userId: string;
462
+ email: string;
463
+ username: string;
464
+ roles: string[];
465
+ createdAt: string;
466
+ lastLoginAt: string | null;
467
+ }
468
+ type TenantMemberPage = Paged<TenantMember>;
469
+
470
+ type QueryParams = object;
471
+
472
+ declare const ErrorCodes: {
473
+ readonly Unknown: "unknown";
474
+ readonly NetworkError: "request.network_error";
475
+ readonly Timeout: "request.timeout";
476
+ readonly SessionMalformed: "session.malformed";
477
+ readonly NotAuthenticated: "auth.not_authenticated";
478
+ readonly InvalidToken: "auth.invalid_token";
479
+ readonly MissingToken: "auth.missing_token";
480
+ readonly EmailTaken: "user.email_taken";
481
+ readonly PasswordWeak: "user.password_weak";
482
+ readonly PasswordPwned: "user.password_pwned";
483
+ readonly RateLimited: "rate_limited";
484
+ };
485
+ type KnownErrorCode = (typeof ErrorCodes)[keyof typeof ErrorCodes];
486
+ type AuthyonErrorCategory = "network" | "timeout" | "authentication" | "authorization" | "validation" | "not_found" | "conflict" | "rate_limit" | "server" | "unknown";
487
+ type AuthyonErrorAction = "retry" | "reauthenticate" | "request_access" | "fix_input" | "not_found" | "resolve_conflict" | "contact_support";
488
+ interface AuthyonErrorInterpretation {
489
+ category: AuthyonErrorCategory;
490
+ action: AuthyonErrorAction;
491
+ retryable: boolean;
492
+ retryAfter?: number;
493
+ requestId?: string;
494
+ }
495
+ /** Shared RFC 7807 error implementation used by both public SDKs. */
496
+ declare class AuthyonError extends Error {
497
+ readonly status: number;
498
+ readonly code: string;
499
+ readonly title: string;
500
+ readonly detail?: string;
501
+ readonly requestId?: string;
502
+ readonly retryAfter?: number;
503
+ readonly cause?: unknown;
504
+ constructor(status: number, body: Partial<{
505
+ title: string;
506
+ detail: string;
507
+ code: string;
508
+ }>, options?: {
509
+ requestId?: string;
510
+ retryAfter?: number;
511
+ cause?: unknown;
512
+ });
513
+ is(code: string): boolean;
514
+ isAny(...codes: readonly string[]): boolean;
515
+ hasPrefix(prefix: string): boolean;
516
+ isStatus(...statuses: readonly number[]): boolean;
517
+ /** Stable interpretation for UI decisions, retries, telemetry and support flows. */
518
+ interpret(): AuthyonErrorInterpretation;
519
+ get category(): AuthyonErrorCategory;
520
+ get retryable(): boolean;
521
+ toJSON(): Record<string, unknown>;
522
+ }
523
+
524
+ type HttpMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
525
+ interface JsonRequestOptions {
526
+ method?: HttpMethod;
527
+ body?: unknown;
528
+ query?: QueryParams;
529
+ headers?: Record<string, string>;
530
+ }
531
+
532
+ type ManagementRequest = <T>(path: string, options?: JsonRequestOptions) => Promise<T>;
533
+
534
+ /** Platform user administration. Never falls back to an environment machine token. */
535
+ declare class PlatformScopedClient {
536
+ #private;
537
+ /** @hidden */
538
+ constructor(request: ManagementRequest, token: AccessTokenSource);
539
+ readonly credentials: {
540
+ list: (scope: CredentialScope, options?: CredentialListOptions) => Promise<Paged<TenantCredentialSummary>>;
541
+ get: (scope: CredentialScope, credentialId: string) => Promise<CredentialDetail>;
542
+ create: (scope: CredentialScope, input: CreateCredentialInput) => Promise<TenantCredentialIssued>;
543
+ updatePermissions: (scope: CredentialScope, credentialId: string, input: CredentialPermissionsInput) => Promise<void>;
544
+ updateScopes: (scope: CredentialScope, credentialId: string, scopes: readonly string[]) => Promise<void>;
545
+ /** Returns a new secret once. API may require an explicit step-up first. */
546
+ rotate: (scope: CredentialScope, credentialId: string) => Promise<TenantCredentialIssued>;
547
+ revoke: (scope: CredentialScope, credentialId: string) => Promise<void>;
548
+ };
549
+ readonly workspaces: {
550
+ team: (workspaceId: string) => Promise<WorkspaceTeam>;
551
+ members: {
552
+ invite: (workspaceId: string, input: InviteWorkspaceMemberInput) => Promise<WorkspaceInviteIssued>;
553
+ /** memberId comes from team.members; it is not the platform userId. */
554
+ remove: (workspaceId: string, memberId: string) => Promise<void>;
555
+ changeRole: (workspaceId: string, memberId: string, role: WorkspaceRole) => Promise<void>;
556
+ };
557
+ invites: {
558
+ create: (workspaceId: string, input: InviteWorkspaceMemberInput) => Promise<WorkspaceInviteIssued>;
559
+ revoke: (workspaceId: string, inviteId: string) => Promise<void>;
560
+ };
561
+ };
562
+ readonly tenants: {
563
+ members: {
564
+ list: (scope: TenantManagementScope, options?: PaginationOptions) => Promise<EnvironmentUser[]>;
565
+ add: (scope: TenantManagementScope, userId: string, roles?: string[]) => Promise<void>;
566
+ remove: (scope: TenantManagementScope, userId: string) => Promise<void>;
567
+ };
568
+ };
569
+ readonly auth: {
570
+ /** Explicitly confirms the current platform session; passwords are not retained. */
571
+ stepUp: (currentPassword: string) => Promise<void>;
572
+ };
573
+ }
574
+ /** End-user operations require a user token and the environment publishable key. */
575
+ declare class UserScopedClient {
576
+ #private;
577
+ /** @hidden */
578
+ constructor(request: ManagementRequest, token: AccessTokenSource);
579
+ readonly tenants: {
580
+ members: {
581
+ list: (tenantId: string, options?: PaginationOptions) => Promise<TenantMemberPage>;
582
+ /** Adds an existing environment user by email; does not send an invitation email. */
583
+ invite: (tenantId: string, input: InviteTenantMemberInput) => Promise<TenantMember>;
584
+ remove: (tenantId: string, userId: string) => Promise<void>;
585
+ };
586
+ };
587
+ }
588
+ /** Anonymous invite endpoints: the invitation token itself authorizes these requests. */
589
+ declare class WorkspaceInvitesClient {
590
+ #private;
591
+ /** @hidden */
592
+ constructor(request: ManagementRequest);
593
+ preview(token: string): Promise<WorkspaceInvitePreview>;
594
+ accept(token: string, input?: AcceptWorkspaceInviteInput): Promise<WorkspaceInviteAccepted>;
595
+ }
596
+
597
+ interface ClientRequestContext {
598
+ /** Real end-user IP, resolved only from infrastructure trusted by the application. */
599
+ clientIp?: string;
600
+ }
601
+ /** Rejects header injection and values that are not a single IPv4 or IPv6 address. */
602
+ declare function normalizeClientIp(value: string): string;
603
+
337
604
  type SafeJwtAlgorithm = "RS256" | "PS256" | "ES256" | "EdDSA";
338
605
  interface AuthyonJwtClaims extends JWTPayload {
339
606
  sub: string;
@@ -398,9 +665,9 @@ declare class JwksTokenVerifier {
398
665
  * server.
399
666
  */
400
667
  declare class AuthyonServerClient {
668
+ #private;
401
669
  private readonly envKey?;
402
670
  private readonly clientId?;
403
- private readonly clientSecret?;
404
671
  private readonly transport;
405
672
  private readonly http;
406
673
  private readonly environmentTokenProvider;
@@ -435,6 +702,11 @@ declare class AuthyonServerClient {
435
702
  * "the token's tenant" rather than one you pass by id.
436
703
  */
437
704
  tenant(credentials: ClientCredentials): TenantScopedClient;
705
+ /** Uses only the supplied platform-user access token. */
706
+ platform(token: AccessTokenSource): PlatformScopedClient;
707
+ /** Uses an end-user token; the configured environment key selects the environment. */
708
+ user(token: AccessTokenSource): UserScopedClient;
709
+ readonly workspaceInvites: WorkspaceInvitesClient;
438
710
  readonly environment: {
439
711
  users: {
440
712
  /** GET /env/users — paginated list of users in the environment. */
@@ -477,6 +749,20 @@ declare class AuthyonServerClient {
477
749
  removeTenant: (userId: string, tenantId: string) => Promise<void>;
478
750
  };
479
751
  tenants: {
752
+ credentials: {
753
+ /** GET /env/tenants/{tenantId}/credentials. Returns metadata only, including revoked credentials. */
754
+ list: (tenantId: string) => Promise<TenantCredentialSummary[]>;
755
+ /** Paginated searchable listing. Prefer this over loading every credential. */
756
+ listPage: (tenantId: string, options?: CredentialListOptions) => Promise<Paged<TenantCredentialSummary>>;
757
+ get: (tenantId: string, credentialId: string) => Promise<CredentialDetail>;
758
+ /** Explicit scopes/permissions; only issuance returns the client secret. */
759
+ create: (tenantId: string, input: CreateTenantCredentialInput | CreateCredentialInput) => Promise<TenantCredentialIssued>;
760
+ /** Returns a new secret once while keeping the same client id. */
761
+ rotate: (tenantId: string, credentialId: string) => Promise<TenantCredentialIssued>;
762
+ updatePermissions: (tenantId: string, credentialId: string, input: CredentialPermissionsInput) => Promise<void>;
763
+ updateScopes: (tenantId: string, credentialId: string, scopes: readonly string[]) => Promise<void>;
764
+ revoke: (tenantId: string, credentialId: string) => Promise<void>;
765
+ };
480
766
  /** GET /env/tenants — paginated, searchable list of tenants in the environment. */
481
767
  list: (params?: {
482
768
  search?: string;
@@ -627,7 +913,7 @@ declare function createClient(options?: AuthyonServerClientOptions): AuthyonServ
627
913
 
628
914
  /** Builds a server client while keeping environment credentials grouped. */
629
915
  declare class AuthyonServerClientBuilder {
630
- private readonly options;
916
+ #private;
631
917
  withEnvironmentKey(envKey: string): this;
632
918
  withEnvironmentCredentials(clientId: string, clientSecret: string): this;
633
919
  withBaseUrl(baseUrl: string, allowInsecureHttp?: boolean): this;
@@ -637,58 +923,6 @@ declare class AuthyonServerClientBuilder {
637
923
  build(): AuthyonServerClient;
638
924
  }
639
925
 
640
- declare const ErrorCodes: {
641
- readonly Unknown: "unknown";
642
- readonly NetworkError: "request.network_error";
643
- readonly Timeout: "request.timeout";
644
- readonly SessionMalformed: "session.malformed";
645
- readonly NotAuthenticated: "auth.not_authenticated";
646
- readonly InvalidToken: "auth.invalid_token";
647
- readonly MissingToken: "auth.missing_token";
648
- readonly EmailTaken: "user.email_taken";
649
- readonly PasswordWeak: "user.password_weak";
650
- readonly PasswordPwned: "user.password_pwned";
651
- readonly RateLimited: "rate_limited";
652
- };
653
- type KnownErrorCode = (typeof ErrorCodes)[keyof typeof ErrorCodes];
654
- type AuthyonErrorCategory = "network" | "timeout" | "authentication" | "authorization" | "validation" | "not_found" | "conflict" | "rate_limit" | "server" | "unknown";
655
- type AuthyonErrorAction = "retry" | "reauthenticate" | "request_access" | "fix_input" | "not_found" | "resolve_conflict" | "contact_support";
656
- interface AuthyonErrorInterpretation {
657
- category: AuthyonErrorCategory;
658
- action: AuthyonErrorAction;
659
- retryable: boolean;
660
- retryAfter?: number;
661
- requestId?: string;
662
- }
663
- /** Shared RFC 7807 error implementation used by both public SDKs. */
664
- declare class AuthyonError extends Error {
665
- readonly status: number;
666
- readonly code: string;
667
- readonly title: string;
668
- readonly detail?: string;
669
- readonly requestId?: string;
670
- readonly retryAfter?: number;
671
- readonly cause?: unknown;
672
- constructor(status: number, body: Partial<{
673
- title: string;
674
- detail: string;
675
- code: string;
676
- }>, options?: {
677
- requestId?: string;
678
- retryAfter?: number;
679
- cause?: unknown;
680
- });
681
- is(code: string): boolean;
682
- isAny(...codes: readonly string[]): boolean;
683
- hasPrefix(prefix: string): boolean;
684
- isStatus(...statuses: readonly number[]): boolean;
685
- /** Stable interpretation for UI decisions, retries, telemetry and support flows. */
686
- interpret(): AuthyonErrorInterpretation;
687
- get category(): AuthyonErrorCategory;
688
- get retryable(): boolean;
689
- toJSON(): Record<string, unknown>;
690
- }
691
-
692
926
  type AbilitySubject = string | Record<string, unknown>;
693
927
  type AbilityConditions = Record<string, unknown>;
694
928
  interface AbilityRule {
@@ -803,4 +1037,4 @@ declare function createExpressAuthorizationMiddleware(client: AuthyonServerClien
803
1037
  /** Converts an authorization error into a Fetch Response suitable for Next.js. */
804
1038
  declare function createAuthorizationErrorResponse(error: unknown): Response;
805
1039
 
806
- export { type AbilityConditions, type AbilityEvent, type AbilityListener, type AbilityRequirement, type AbilityRule, type AbilitySubject, type AuditEvent, type AuthorizationContext, AuthorizationError, type AuthorizationOptions, AuthyonAbility, AuthyonAbilityBuilder, type AuthyonAbilityOptions, AuthyonError, type AuthyonErrorAction, type AuthyonErrorCategory, type AuthyonErrorInterpretation, type AuthyonJwksDiscoveryOptions, type AuthyonJwtClaims, type AuthyonPermissionSource, AuthyonServerClient, AuthyonServerClientBuilder, type AuthyonServerClientOptions, type ClientCredentials, type ClientRequestContext, type CreateOrganizationInput, type CreatePermissionInput, type CreateUserInput, type EnvironmentUser, ErrorCodes, type ExpressAuthorizationMiddlewareOptions, type ExpressNext, type ExpressRequestLike, type ExpressResponseLike, FetchHttpAdapter, type HttpAdapter, type HttpAdapterRequest, type HttpLogEvent, type HttpLogger, type HttpLoggerOptions, type IntrospectResult, type JsonWebKeySet, JwksTokenVerifier, type JwksTokenVerifierOptions, type KnownErrorCode, LoggingHttpAdapter, type LoginActivity, type OpenIdConfiguration, type Organization, type Paged, type PaginationOptions, type Permission, type PermissionsByRole, type RequestAuthorizationOptions, type ReservedPermissions, type Role, type RoleGrant, type RoleInput, type RoleList, type RolePermissions, type SafeJwtAlgorithm, type TenantMembership, TenantScopedClient, type TokenResult, TokenVerificationError, type TokenVerificationErrorCode, type UpdateOrganizationInput, type User, type ValidateResult, type VerifiedAccessToken, authorizeRequest, authorizeToken, createAuthorizationErrorResponse, createAuthyonAbility, createAuthyonRules, createClient, createExpressAuthorizationMiddleware, hasPermission, normalizeClientIp };
1040
+ export { type AbilityConditions, type AbilityEvent, type AbilityListener, type AbilityRequirement, type AbilityRule, type AbilitySubject, type AcceptWorkspaceInviteInput, type AccessTokenSource, type AuditEvent, type AuthorizationContext, AuthorizationError, type AuthorizationOptions, AuthyonAbility, AuthyonAbilityBuilder, type AuthyonAbilityOptions, AuthyonError, type AuthyonErrorAction, type AuthyonErrorCategory, type AuthyonErrorInterpretation, type AuthyonJwksDiscoveryOptions, type AuthyonJwtClaims, type AuthyonPermissionSource, AuthyonServerClient, AuthyonServerClientBuilder, type AuthyonServerClientOptions, type ClientCredentials, type ClientRequestContext, type CreateCredentialInput, type CreateOrganizationInput, type CreatePermissionInput, type CreateTenantCredentialInput, type CreateUserInput, type CredentialCreator, type CredentialDetail, type CredentialListOptions, type CredentialPermissionsInput, type CredentialScope, type EnvironmentUser, ErrorCodes, type ExpressAuthorizationMiddlewareOptions, type ExpressNext, type ExpressRequestLike, type ExpressResponseLike, FetchHttpAdapter, type HttpAdapter, type HttpAdapterRequest, type HttpLogEvent, type HttpLogger, type HttpLoggerOptions, type IntrospectResult, type InviteTenantMemberInput, type InviteWorkspaceMemberInput, type JsonWebKeySet, JwksTokenVerifier, type JwksTokenVerifierOptions, type KnownErrorCode, LoggingHttpAdapter, type LoginActivity, type OpenIdConfiguration, type Organization, type Paged, type PaginationOptions, type Permission, type PermissionsByRole, PlatformScopedClient, type RequestAuthorizationOptions, type ReservedPermissions, type Role, type RoleGrant, type RoleInput, type RoleList, type RolePermissions, type SafeJwtAlgorithm, type TenantCredentialIssued, type TenantCredentialSummary, type TenantManagementScope, type TenantMember, type TenantMemberPage, type TenantMembership, TenantScopedClient, type TokenResult, TokenVerificationError, type TokenVerificationErrorCode, type UpdateOrganizationInput, type User, UserScopedClient, type ValidateResult, type VerifiedAccessToken, type WorkspaceInvite, type WorkspaceInviteAccepted, type WorkspaceInviteIssued, type WorkspaceInvitePreview, WorkspaceInvitesClient, type WorkspaceMember, type WorkspaceRole, type WorkspaceTeam, authorizeRequest, authorizeToken, createAuthorizationErrorResponse, createAuthyonAbility, createAuthyonRules, createClient, createExpressAuthorizationMiddleware, hasPermission, normalizeClientIp };