@happyvertical/smrt-users 0.51.32 → 0.51.33
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/__tests__/helpers/oidc-test-server.d.ts +45 -0
- package/dist/__tests__/helpers/oidc-test-server.d.ts.map +1 -0
- package/dist/__tests__/helpers/postgres-rls-reset.d.ts +15 -0
- package/dist/__tests__/helpers/postgres-rls-reset.d.ts.map +1 -0
- package/dist/app-contract.d.ts +11 -1
- package/dist/chunks/{TerminalAuthService-Mj7kASo7.js → TerminalAuthService-CLDmxYuC.js} +2 -2
- package/dist/chunks/{TerminalAuthService-Mj7kASo7.js.map → TerminalAuthService-CLDmxYuC.js.map} +1 -1
- package/dist/collections/AccessRequestCollection.d.ts +10 -0
- package/dist/collections/CliAuthApproveLimitCollection.d.ts +5 -0
- package/dist/collections/CliAuthRequestCollection.d.ts +5 -0
- package/dist/collections/GroupCollection.d.ts +4 -0
- package/dist/collections/GroupMemberCollection.d.ts +4 -0
- package/dist/collections/GroupRoleCollection.d.ts +4 -0
- package/dist/collections/MagicLinkTokenCollection.d.ts +7 -0
- package/dist/collections/MembershipCollection.d.ts +4 -0
- package/dist/collections/MembershipOverrideCollection.d.ts +4 -0
- package/dist/collections/PermissionCollection.d.ts +4 -0
- package/dist/collections/ResourceGrantCollection.d.ts +1 -0
- package/dist/collections/RoleCollection.d.ts +5 -1
- package/dist/collections/RolePermissionCollection.d.ts +6 -2
- package/dist/collections/SessionCollection.d.ts +4 -0
- package/dist/collections/TenantCollection.d.ts +4 -0
- package/dist/collections/TenantIntegrationCollection.d.ts +6 -1
- package/dist/collections/TenantPermissionOverrideCollection.d.ts +4 -0
- package/dist/collections/UserCollection.d.ts +6 -2
- package/dist/index.d.ts +56 -0
- package/dist/index.js +3 -3
- package/dist/manifest.json +1 -1
- package/dist/migrations/backfillLegacyUserProfiles.d.ts +1 -1
- package/dist/migrations/backfillUserEmailKeys.d.ts +1 -1
- package/dist/migrations/materializeTenantHierarchy.d.ts +2 -2
- package/dist/models/AccessRequest.d.ts +22 -0
- package/dist/models/CliAuthApproveLimit.d.ts +5 -0
- package/dist/models/CliAuthRequest.d.ts +12 -0
- package/dist/models/Group.d.ts +5 -1
- package/dist/models/GroupMember.d.ts +5 -1
- package/dist/models/GroupRole.d.ts +5 -1
- package/dist/models/MagicLinkToken.d.ts +9 -1
- package/dist/models/Membership.d.ts +6 -2
- package/dist/models/MembershipOverride.d.ts +5 -1
- package/dist/models/Permission.d.ts +5 -1
- package/dist/models/ResourceGrant.d.ts +2 -1
- package/dist/models/Role.d.ts +6 -2
- package/dist/models/RolePermission.d.ts +5 -1
- package/dist/models/Session.d.ts +5 -1
- package/dist/models/Tenant.d.ts +6 -2
- package/dist/models/TenantIntegration.d.ts +10 -1
- package/dist/models/TenantPermissionOverride.d.ts +5 -1
- package/dist/models/User.d.ts +6 -2
- package/dist/models/tenant-hierarchy.d.ts +23 -0
- package/dist/services/AccessRequestService.d.ts +42 -6
- package/dist/services/MagicLinkService.d.ts +30 -1
- package/dist/services/MobileAuthService.d.ts +43 -5
- package/dist/services/OidcLoginService.d.ts +12 -2
- package/dist/services/OperationPermissionService.d.ts +7 -3
- package/dist/services/PermissionCatalogService.d.ts +5 -1
- package/dist/services/PermissionResolver.d.ts +8 -4
- package/dist/services/PostgresPermissionPolicies.d.ts +6 -2
- package/dist/services/ResourceGrantService.d.ts +4 -3
- package/dist/services/SessionPermissionContext.d.ts +8 -4
- package/dist/services/SessionService.d.ts +10 -6
- package/dist/services/TenantService.d.ts +8 -4
- package/dist/services/TerminalAuthService.d.ts +23 -4
- package/dist/services/authorization-read-options.d.ts +2 -1
- package/dist/smrt-knowledge.json +4 -4
- package/dist/sveltekit/index.d.ts +23 -5
- package/dist/sveltekit/mobile-handlers.d.ts +42 -2
- package/dist/sveltekit/resource-list-handler.d.ts +30 -4
- package/dist/sveltekit/types.d.ts +6 -2
- package/dist/sveltekit.js +1 -1
- package/dist/ui.d.ts +7 -1
- package/package.json +10 -10
|
@@ -1,10 +1,46 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* AccessRequestService — the mechanism behind the "request access / waitlist"
|
|
3
|
+
* identity primitive, plus graduation of an approved request into a `User`.
|
|
4
|
+
*
|
|
5
|
+
* ## Responsibilities
|
|
6
|
+
*
|
|
7
|
+
* - **Public-safe creation** ({@link AccessRequestService.createAccessRequest}):
|
|
8
|
+
* validates + normalizes the email and de-duplicates against any open request
|
|
9
|
+
* for the same email. Intended to be called *unauthenticated* by consuming
|
|
10
|
+
* apps from their own rate-limited endpoint (the app owns rate-limiting).
|
|
11
|
+
* - **Operator triage** (`list` / `get` / `approve` / `decline` / `cancel`):
|
|
12
|
+
* gated behind capabilities (see {@link AccessRequestAuthorizer}).
|
|
13
|
+
* - **Graduation** ({@link AccessRequestService.graduateAccessRequest}): creates
|
|
14
|
+
* or links a `User` from the request — reusing the existing user / membership
|
|
15
|
+
* / tenant collections rather than duplicating them — and (optionally)
|
|
16
|
+
* attaches the user to a brand-new tenant (requester as owner), an existing
|
|
17
|
+
* tenant, or no tenant at all. Idempotent.
|
|
18
|
+
* - **Events** ({@link AccessRequestEventHandler}): emits
|
|
19
|
+
* `access-request.created | approved | declined | canceled | graduated` so
|
|
20
|
+
* apps can react (send a magic-link/invite on `graduated`, notify ops on
|
|
21
|
+
* `created`, …). This service deliberately does **not** own email/notification
|
|
22
|
+
* delivery — bridge the event hook to your delivery channel (a function, an
|
|
23
|
+
* `EventEmitter`, the core `DispatchBus`, …).
|
|
24
|
+
*
|
|
25
|
+
* @remarks
|
|
26
|
+
* **Security.** Operator methods are gated only when an {@link AccessRequestAuthorizer}
|
|
27
|
+
* is supplied via {@link AccessRequestServiceOptions.authorize}; without one
|
|
28
|
+
* they are ungated, exactly like {@link TerminalAuthService.approveRequest}
|
|
29
|
+
* trusts its caller to authenticate first. Production apps that expose these
|
|
30
|
+
* methods MUST either provide an `authorize` hook or perform their own
|
|
31
|
+
* capability checks at the route layer. `createAccessRequest` is *always*
|
|
32
|
+
* ungated by design (public-safe). The model's generated REST/MCP/CLI surface
|
|
33
|
+
* is closed, so there is no unauthenticated network route by default.
|
|
34
|
+
*
|
|
35
|
+
* @packageDocumentation
|
|
36
|
+
*/
|
|
37
|
+
import type { SmrtClassOptions } from '@happyvertical/smrt-core';
|
|
2
38
|
import { AccessRequestCollection } from '../collections/AccessRequestCollection.js';
|
|
3
|
-
import { AccessRequest } from '../models/AccessRequest.js';
|
|
4
|
-
import { Membership } from '../models/Membership.js';
|
|
5
|
-
import { Tenant } from '../models/Tenant.js';
|
|
6
|
-
import { User } from '../models/User.js';
|
|
7
|
-
import { AccessRequestStatus, TenantStatus, UserStatus } from '../types/index.js';
|
|
39
|
+
import type { AccessRequest } from '../models/AccessRequest.js';
|
|
40
|
+
import type { Membership } from '../models/Membership.js';
|
|
41
|
+
import type { Tenant } from '../models/Tenant.js';
|
|
42
|
+
import type { User } from '../models/User.js';
|
|
43
|
+
import { AccessRequestStatus, type TenantStatus, UserStatus } from '../types/index.js';
|
|
8
44
|
/**
|
|
9
45
|
* Capabilities that gate the operator-facing methods of
|
|
10
46
|
* {@link AccessRequestService}.
|
|
@@ -1,4 +1,33 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* MagicLinkService - Passwordless email authentication via signed magic link tokens
|
|
3
|
+
*
|
|
4
|
+
* This service handles token generation and verification for magic link
|
|
5
|
+
* authentication. It is framework-agnostic: it returns tokens and verification
|
|
6
|
+
* results, leaving email delivery and cookie management to the caller.
|
|
7
|
+
*
|
|
8
|
+
* Flow:
|
|
9
|
+
* 1. User enters email → generate(email) → token + expiresAt
|
|
10
|
+
* 2. Caller sends email with link containing the token
|
|
11
|
+
* 3. User clicks link → verify(token) → { email, nonce }
|
|
12
|
+
* 4. Caller creates session (via SessionService or createSessionCookie)
|
|
13
|
+
*
|
|
14
|
+
* @packageDocumentation
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* const magicLink = await MagicLinkService.create({
|
|
19
|
+
* db: { type: 'postgres', url: process.env.DATABASE_URL },
|
|
20
|
+
* secret: process.env.AUTH_SECRET,
|
|
21
|
+
* });
|
|
22
|
+
*
|
|
23
|
+
* // Generate a magic link token
|
|
24
|
+
* const { token, expiresAt } = await magicLink.generate('user@example.com');
|
|
25
|
+
*
|
|
26
|
+
* // Verify a magic link token (single-use)
|
|
27
|
+
* const { email, nonce } = await magicLink.verify(token);
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
import type { SmrtClassOptions } from '@happyvertical/smrt-core';
|
|
2
31
|
/**
|
|
3
32
|
* Options for MagicLinkService
|
|
4
33
|
*/
|
|
@@ -1,8 +1,46 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
/**
|
|
2
|
+
* MobileAuthService — server side of the SMRT mobile `/api/mobile` contract
|
|
3
|
+
* (ADR 0001 Phase 3.5, issue #1748).
|
|
4
|
+
*
|
|
5
|
+
* Implements server-brokered OIDC/PKCE for native mobile clients on top of
|
|
6
|
+
* the existing building blocks: {@link OidcLoginService} for the protocol
|
|
7
|
+
* work, {@link SessionService} for the opaque bearer session (the session id
|
|
8
|
+
* IS the bearer token — the same convention `TerminalAuthService` ships), and
|
|
9
|
+
* the membership/role/tenant collections for the session bootstrap.
|
|
10
|
+
*
|
|
11
|
+
* Wire DTOs come from `@happyvertical/smrt-mobile-contract` — the owning
|
|
12
|
+
* package for both the Kotlin client contract and these TypeScript types.
|
|
13
|
+
*
|
|
14
|
+
* ## Stateless completion: the state token
|
|
15
|
+
*
|
|
16
|
+
* The mobile flow has no cookie jar, so the web flow's HMAC-signed
|
|
17
|
+
* transaction cookie cannot carry `state`/`nonce`/`codeVerifier` across the
|
|
18
|
+
* redirect. Instead (per the frozen contract) the CLIENT persists and echoes
|
|
19
|
+
* `state` + `codeVerifier`, and the server stays stateless by making the
|
|
20
|
+
* OAuth `state` value itself a signed token: base64url JSON carrying the
|
|
21
|
+
* nonce, provider, and creation time, plus an HMAC-SHA256 signature when a
|
|
22
|
+
* secret is available (`stateSecret` option, defaulting to the provider's
|
|
23
|
+
* `clientSecret` — the same fallback the web transaction cookie uses). The
|
|
24
|
+
* client treats `state` as opaque; `MobileSessionManager` just compares the
|
|
25
|
+
* redirect's `state` to the persisted one and echoes it back.
|
|
26
|
+
*
|
|
27
|
+
* The `codeVerifier` deliberately NEVER rides inside the state token: state
|
|
28
|
+
* appears in the authorization URL (browser history, proxy logs), and a
|
|
29
|
+
* verifier there would defeat PKCE. It stays client-held — returned once in
|
|
30
|
+
* the `auth/start` response body and echoed once in the `auth/complete`
|
|
31
|
+
* request body, both over TLS POSTs. The nonce, by contrast, is already a
|
|
32
|
+
* query parameter of the authorization URL, so embedding it in `state`
|
|
33
|
+
* leaks nothing while letting the server enforce full ID-token nonce
|
|
34
|
+
* verification without server-side pending state.
|
|
35
|
+
*
|
|
36
|
+
* @packageDocumentation
|
|
37
|
+
*/
|
|
38
|
+
import type { SmrtClassOptions } from '@happyvertical/smrt-core';
|
|
39
|
+
import type { MobileAuthCompleteRequest, MobileAuthSession, MobileAuthStartRequest, MobileAuthStartResponse, MobileSessionBootstrap, MobileTenantOption } from '@happyvertical/smrt-mobile-contract';
|
|
40
|
+
import { type OidcClaims } from '../collections/UserCollection.js';
|
|
41
|
+
import { type OidcProviderResolutionOptions, type OidcTokenSet } from './OidcLoginService.js';
|
|
42
|
+
import type { SessionContext } from './SessionService.js';
|
|
43
|
+
import { SessionService } from './SessionService.js';
|
|
6
44
|
/**
|
|
7
45
|
* Machine-readable error codes carried on {@link MobileAuthError} and in the
|
|
8
46
|
* JSON error body (`{ error, code }`) the SvelteKit handlers emit.
|
|
@@ -1,5 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* OidcLoginService - OAuth2/OIDC authorization-code login with PKCE.
|
|
3
|
+
*
|
|
4
|
+
* The service is provider-generic and works with standards-compliant IdPs such
|
|
5
|
+
* as Kanidm, Dex, Keycloak, Authentik, Google, and others. It handles provider
|
|
6
|
+
* discovery, authorization URL construction, token exchange, ID token
|
|
7
|
+
* verification, and SMRT User/Profile creation.
|
|
8
|
+
*
|
|
9
|
+
* @packageDocumentation
|
|
10
|
+
*/
|
|
11
|
+
import type { SmrtClassOptions } from '@happyvertical/smrt-core';
|
|
12
|
+
import { type OidcClaims, type OidcIdentityResult, type OidcProfileOwnerAuthorizer, type OidcProfileResolver } from '../collections/UserCollection.js';
|
|
3
13
|
export type OidcProviderKind = 'kanidm' | 'dex' | 'generic';
|
|
4
14
|
export type OidcTokenEndpointAuthMethod = 'client_secret_basic' | 'client_secret_post' | 'none';
|
|
5
15
|
export interface OidcProviderConfig {
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Reusable operation-level permission guard for hand-written server surfaces.
|
|
3
|
+
* @packageDocumentation
|
|
4
|
+
*/
|
|
5
|
+
import type { SmrtClassOptions } from '@happyvertical/smrt-core';
|
|
6
|
+
import { type OperationPermissionCollectionInput, type PermissionCatalog } from './PermissionCatalogService.js';
|
|
7
|
+
import { type PermissionResolutionOptions, PermissionResolver } from './PermissionResolver.js';
|
|
4
8
|
export type OperationPermissionDenyReason = 'invalid_operation' | 'missing_principal' | 'resolution_error' | 'unknown_permission' | 'permission_denied';
|
|
5
9
|
export type OperationPermissionAllowReason = 'permission_granted' | 'super_admin_bypass' | 'system_context_bypass';
|
|
6
10
|
export interface OperationPermissionDecision {
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Manifest-derived permission cataloging and syncing
|
|
3
|
+
* @packageDocumentation
|
|
4
|
+
*/
|
|
5
|
+
import { type SmrtClassOptions } from '@happyvertical/smrt-core';
|
|
2
6
|
export type PermissionCatalogSource = 'manifest' | 'config' | 'runtime';
|
|
3
7
|
export type PostgresPermissionAction = 'SELECT' | 'INSERT' | 'UPDATE' | 'DELETE';
|
|
4
8
|
export interface PostgresPermissionBinding {
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
/**
|
|
2
|
+
* PermissionResolver - Resolves effective permissions for a user in a tenant
|
|
3
|
+
* @packageDocumentation
|
|
4
|
+
*/
|
|
5
|
+
import { type SmrtClassOptions } from '@happyvertical/smrt-core';
|
|
6
|
+
import type { Membership } from '../models/Membership.js';
|
|
7
|
+
import { type Tenant } from '../models/Tenant.js';
|
|
8
|
+
import { type AncestorReadPolicy } from './AncestorReadPolicy.js';
|
|
5
9
|
/**
|
|
6
10
|
* Permission resolution result
|
|
7
11
|
*/
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Postgres policy generation and application for SMRT permissions
|
|
3
|
+
* @packageDocumentation
|
|
4
|
+
*/
|
|
5
|
+
import { type SmrtClassOptions } from '@happyvertical/smrt-core';
|
|
6
|
+
import { type PostgresPermissionAction, type PostgresPermissionBinding } from './PermissionCatalogService.js';
|
|
3
7
|
export interface PostgresPermissionPolicyReportItem {
|
|
4
8
|
className?: string;
|
|
5
9
|
collection?: string;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
/** Composition of tenant operation permissions with exact resource grants. @packageDocumentation */
|
|
2
|
+
import type { SmrtClassOptions } from '@happyvertical/smrt-core';
|
|
3
|
+
import type { ResourceGrant, ResourceGrantEffect } from '../models/ResourceGrant.js';
|
|
4
|
+
import { type OperationPermissionOptions } from './OperationPermissionService.js';
|
|
4
5
|
export declare const MAX_RESOURCE_GRANT_DELEGATION_DEPTH = 8;
|
|
5
6
|
export interface ResourceIdentity {
|
|
6
7
|
tenantId: string;
|
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Request-scoped session permission context helpers
|
|
3
|
+
* @packageDocumentation
|
|
4
|
+
*/
|
|
5
|
+
import type { SmrtClassOptions } from '@happyvertical/smrt-core';
|
|
6
|
+
import type { DatabaseInterface } from '@happyvertical/sql';
|
|
7
|
+
import type { Membership } from '../models/Membership.js';
|
|
4
8
|
import { PermissionResolver } from './PermissionResolver.js';
|
|
5
|
-
import { SessionContext, SessionService } from './SessionService.js';
|
|
9
|
+
import { type SessionContext, SessionService } from './SessionService.js';
|
|
6
10
|
interface QueryableDatabase extends DatabaseInterface {
|
|
7
11
|
beginTransaction?: () => Promise<TransactionDatabase>;
|
|
8
12
|
url: string;
|
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import {
|
|
1
|
+
/**
|
|
2
|
+
* SessionService - Higher-level session management combining sessions with user/permission loading
|
|
3
|
+
* @packageDocumentation
|
|
4
|
+
*/
|
|
5
|
+
import type { SmrtClassOptions } from '@happyvertical/smrt-core';
|
|
6
|
+
import { type CreateSessionOptions } from '../collections/SessionCollection.js';
|
|
7
|
+
import type { Membership } from '../models/Membership.js';
|
|
8
|
+
import { type Session } from '../models/Session.js';
|
|
9
|
+
import type { User } from '../models/User.js';
|
|
6
10
|
/**
|
|
7
11
|
* Session context with user and permissions
|
|
8
12
|
*/
|
|
@@ -118,7 +122,7 @@ export declare class SessionService {
|
|
|
118
122
|
/**
|
|
119
123
|
* Get the initialized database connection backing this session service.
|
|
120
124
|
*/
|
|
121
|
-
getDatabase(): import(
|
|
125
|
+
getDatabase(): import("@happyvertical/sql").DatabaseInterface;
|
|
122
126
|
/**
|
|
123
127
|
* Refresh session (extend expiry, update lastAccessed)
|
|
124
128
|
*/
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
/**
|
|
2
|
+
* TenantService - Manages tenant creation with configurable policies
|
|
3
|
+
* @packageDocumentation
|
|
4
|
+
*/
|
|
5
|
+
import type { SmrtClassOptions } from '@happyvertical/smrt-core';
|
|
6
|
+
import type { Membership } from '../models/Membership.js';
|
|
7
|
+
import type { Tenant } from '../models/Tenant.js';
|
|
8
|
+
import { type TenantPolicy } from '../types/index.js';
|
|
5
9
|
/**
|
|
6
10
|
* Result of tenant creation with ownership
|
|
7
11
|
*/
|
|
@@ -1,7 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
/**
|
|
2
|
+
* TerminalAuthService — device-code grant for terminal/CLI logins.
|
|
3
|
+
*
|
|
4
|
+
* Flow:
|
|
5
|
+
* 1. CLI calls `createRequest(origin)` → user code (short, displayed) + device
|
|
6
|
+
* code (long, kept secret) + verification URL.
|
|
7
|
+
* 2. User opens the verification URL in a browser, signs in normally, and
|
|
8
|
+
* POSTs the user code via `approveRequest({ user, tenantId, userCode })`.
|
|
9
|
+
* 3. CLI polls `exchangeDeviceCode(deviceCode)`; once approved, gets back the
|
|
10
|
+
* bearer session id (an opaque token usable as `Authorization: Bearer …`).
|
|
11
|
+
* 4. Server-side request handlers resolve incoming bearer tokens via
|
|
12
|
+
* `loadBearerSession(token)`, and revoke them via `destroyBearerSession`.
|
|
13
|
+
*
|
|
14
|
+
* The service is framework-agnostic: it does not set cookies, parse Request
|
|
15
|
+
* objects, or render pages. SvelteKit glue lives in the package's
|
|
16
|
+
* `./sveltekit` subpath.
|
|
17
|
+
*
|
|
18
|
+
* @packageDocumentation
|
|
19
|
+
*/
|
|
20
|
+
import { type SmrtClassOptions } from '@happyvertical/smrt-core';
|
|
21
|
+
import type { CliAuthRequestStatus, UsersCliAuthRequest } from '../models/CliAuthRequest.js';
|
|
22
|
+
import type { User } from '../models/User.js';
|
|
23
|
+
import { type SessionContext } from './SessionService.js';
|
|
5
24
|
/** Default polling interval the CLI should honour while waiting for approval. */
|
|
6
25
|
export declare const DEFAULT_CLI_AUTH_POLL_INTERVAL_SECONDS = 2;
|
|
7
26
|
/** Default lifetime of a pending request (10 minutes). */
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
/** Collection options for framework-internal authorization reads. @packageDocumentation */
|
|
2
|
+
import type { SmrtClassOptions, SmrtCollectionOptions } from '@happyvertical/smrt-core';
|
|
2
3
|
/**
|
|
3
4
|
* The caller's options with its list bounds removed.
|
|
4
5
|
*
|
package/dist/smrt-knowledge.json
CHANGED
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
"sensitiveFieldsExcluded": true,
|
|
4
4
|
"generatedAt": "1970-01-01T00:00:00.000Z",
|
|
5
5
|
"packageName": "@happyvertical/smrt-users",
|
|
6
|
-
"packageVersion": "0.51.
|
|
6
|
+
"packageVersion": "0.51.33",
|
|
7
7
|
"sourceManifestPath": "dist/manifest.json",
|
|
8
8
|
"agentDocPath": "AGENTS.md",
|
|
9
9
|
"sourceHashes": {
|
|
10
|
-
"manifest": "
|
|
11
|
-
"packageJson": "
|
|
10
|
+
"manifest": "95729b83fe3c813331a3c4ad1d1544509a4392f6c43fc87ba9289d4b266f46b6",
|
|
11
|
+
"packageJson": "1bd7002e7a0d25a1eae0b5113d091d756e8afd0420d738fc3594f5546de9c6f3",
|
|
12
12
|
"agents": "d7f1bb57f7bbbc1b750ab87c33592a53622236d17f49f8c04b15c4745b5c2ab2",
|
|
13
13
|
"moduleDoc:agents/permissions.md": "b5be3f5b84b409cb6e62080e2d7a75b67e0763266c11054045c5c401b84f8dd6",
|
|
14
14
|
"moduleDoc:agents/oidc-provisioning.md": "5efa607ff23b9a693391e0c02670324a8cea4114d4968c9718f10a763da919c6",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"fast-glob": "^3.3.3",
|
|
43
43
|
"svelte": "^5.57.1",
|
|
44
44
|
"svelte-check": "^4.7.6",
|
|
45
|
-
"typescript": "
|
|
45
|
+
"typescript": "6.0.3",
|
|
46
46
|
"vite": "8.1.4",
|
|
47
47
|
"vitest": "4.1.10"
|
|
48
48
|
},
|
|
@@ -1,7 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
/**
|
|
2
|
+
* SvelteKit integration for session management
|
|
3
|
+
* @packageDocumentation
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```typescript
|
|
7
|
+
* // hooks.server.ts
|
|
8
|
+
* import { createSessionHandler } from '@happyvertical/smrt-users/sveltekit';
|
|
9
|
+
* import { sequence } from '@sveltejs/kit/hooks';
|
|
10
|
+
*
|
|
11
|
+
* const sessionHandler = createSessionHandler({
|
|
12
|
+
* db: { type: 'postgres', url: process.env.DATABASE_URL }
|
|
13
|
+
* });
|
|
14
|
+
*
|
|
15
|
+
* export const handle = sequence(sessionHandler);
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
import '../__smrt-register__.js';
|
|
19
|
+
import type { SmrtClassOptions } from '@happyvertical/smrt-core';
|
|
20
|
+
import type { OidcProfileOwnerAuthorizer, OidcProfileResolver } from '../collections/UserCollection.js';
|
|
21
|
+
import { type OidcLoginResult, type OidcProviderResolutionOptions, type OidcTransaction } from '../services/OidcLoginService.js';
|
|
22
|
+
import { TerminalAuthError, TerminalAuthRateLimitError, TerminalAuthService, type TerminalAuthServiceOptions } from '../services/TerminalAuthService.js';
|
|
5
23
|
export { type AppResultContract, type AppResultMetadata, type CommandRequirements, canonicalizeDiscoveryArtifact, createDiscoveryConformanceArtifact, type DeclaredActionField, type DiscoveryArtifactIntegrity, DiscoveryArtifactValidationError, type DiscoveryConformanceArtifact, type DiscoveryPayload, deriveCommandRequirements, type JsonValue, SMRT_APP_RESULT_CONTRACT, SMRT_APP_RESULT_SCHEMA, SMRT_APP_RESULT_VERSION, SMRT_DISCOVERY_CONFORMANCE_ARTIFACT_SCHEMA, SMRT_DISCOVERY_CONFORMANCE_SCHEMA, SMRT_DISCOVERY_CONFORMANCE_VERSION, SMRT_MCP_RESULT_METADATA_KEY, validateDiscoveryConformanceArtifact, } from '../app-contract.js';
|
|
6
24
|
export type { NormalizedOidcClaims, OidcProfileOwnerAuthorization, OidcProfileOwnerAuthorizer, OidcProfileOwnerAuthorizerContext, OidcProfileResolver, OidcProfileResolverContext, } from '../collections/UserCollection.js';
|
|
7
25
|
export { MobileAuthError, type MobileAuthErrorCode, MobileAuthService, type MobileAuthServiceOptions, type MobileBootstrapContext, type MobileLoginContext, type MobileLogoutResult, type MobileRequestMeta, type MobileResolvedUser, type MobileTenantContext, readMobileBearerToken, validateMobileRedirectUri, } from '../services/MobileAuthService.js';
|
|
@@ -346,7 +364,7 @@ export declare function createBearerSessionDeleteHandler(options: TerminalAuthSe
|
|
|
346
364
|
* `hooks.server.ts` to resolve `Authorization: Bearer <sid>` headers
|
|
347
365
|
* alongside cookie-based sessions.
|
|
348
366
|
*/
|
|
349
|
-
export declare function loadBearerSessionContext(token: string, options: TerminalAuthServiceOptions): Promise<import(
|
|
367
|
+
export declare function loadBearerSessionContext(token: string, options: TerminalAuthServiceOptions): Promise<import("../index.js").SessionContext | null>;
|
|
350
368
|
/** Shape passed back to `+page.server.ts` `load`. */
|
|
351
369
|
export interface TerminalLoginPageData {
|
|
352
370
|
userCode: string;
|
|
@@ -1,5 +1,45 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* SvelteKit handlers for the SMRT mobile `/api/mobile` contract (issue
|
|
3
|
+
* #1748). Thin adapters over {@link MobileAuthService} — parsing, error
|
|
4
|
+
* mapping, and cache headers live here; protocol and session logic live in
|
|
5
|
+
* the service.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* // src/lib/server/mobile.ts
|
|
12
|
+
* import { createMobileAuthHandlers } from '@happyvertical/smrt-users/sveltekit';
|
|
13
|
+
*
|
|
14
|
+
* export const mobile = createMobileAuthHandlers({
|
|
15
|
+
* db: { type: 'postgres', url: process.env.DATABASE_URL! },
|
|
16
|
+
* defaultProvider: 'kanidm',
|
|
17
|
+
* providers: { kanidm: { issuer: '...', clientId: '...', clientSecret: '...' } },
|
|
18
|
+
* redirectUris: ['com.example.app://auth/callback'],
|
|
19
|
+
* });
|
|
20
|
+
*
|
|
21
|
+
* // src/routes/api/mobile/auth/start/+server.ts
|
|
22
|
+
* // export const POST = mobile.authStart;
|
|
23
|
+
* // src/routes/api/mobile/auth/complete/+server.ts
|
|
24
|
+
* // export const POST = mobile.authComplete;
|
|
25
|
+
* // src/routes/api/mobile/session/+server.ts
|
|
26
|
+
* // export const GET = mobile.session.GET;
|
|
27
|
+
* // export const DELETE = mobile.session.DELETE;
|
|
28
|
+
*
|
|
29
|
+
* // src/routes/api/mobile/captures/+server.ts — an app route behind the guard.
|
|
30
|
+
* // `db` is the app's own database config (the same one passed to
|
|
31
|
+
* // createMobileAuthHandlers); the guard resolves ctx.userId/ctx.tenantId.
|
|
32
|
+
* // export const POST = mobile.guard(async (event, ctx) => {
|
|
33
|
+
* // await assertOperationPermission({
|
|
34
|
+
* // db, collection: 'captures', action: 'create',
|
|
35
|
+
* // });
|
|
36
|
+
* // ... // domain ingestion stays app-side
|
|
37
|
+
* // });
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
import '../__smrt-register__.js';
|
|
41
|
+
import { MobileAuthService, type MobileAuthServiceOptions } from '../services/MobileAuthService.js';
|
|
42
|
+
import { type SessionPermissionRuntimeContext } from '../services/SessionPermissionContext.js';
|
|
3
43
|
/**
|
|
4
44
|
* Minimal structural slice of SvelteKit's `RequestEvent` these handlers
|
|
5
45
|
* touch (kept structural so `@sveltejs/kit` stays out of the dependency
|
|
@@ -1,7 +1,33 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Resource-list handler for `GET /api/_resources`.
|
|
3
|
+
*
|
|
4
|
+
* Returns the auth-aware list of resources and commands that an HTTP-based
|
|
5
|
+
* CLI client (e.g. `@happyvertical/smrt-app-cli`) can invoke. Walks the
|
|
6
|
+
* `ObjectRegistry` to find classes whose `@smrt({ cli: ... })` decorator
|
|
7
|
+
* exposes commands, resolves each command's URL shape (scope, http method,
|
|
8
|
+
* path segments) the same way the SvelteKit route generator does, and
|
|
9
|
+
* filters the result through a caller-supplied `commandPolicy`.
|
|
10
|
+
*
|
|
11
|
+
* @packageDocumentation
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* // apps/<app>/src/routes/api/_resources/+server.ts
|
|
16
|
+
* import { createResourceListHandler } from '@happyvertical/smrt-users/sveltekit';
|
|
17
|
+
* import './smrt-register';
|
|
18
|
+
*
|
|
19
|
+
* export const GET = createResourceListHandler({
|
|
20
|
+
* ensureRegistry: async () => { await import('./smrt-register'); },
|
|
21
|
+
* commandPolicy: ({ command, session }) => session.user != null,
|
|
22
|
+
* kebabRoutes: true, // match the vite-plugin setting
|
|
23
|
+
* });
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
import '../__smrt-register__.js';
|
|
27
|
+
import { type SmartObjectConfig } from '@happyvertical/smrt-core';
|
|
28
|
+
import { type CommandRequirements, type DiscoveryConformanceArtifact } from '../app-contract.js';
|
|
29
|
+
import type { TerminalAuthServiceOptions } from '../services/TerminalAuthService.js';
|
|
30
|
+
import type { SessionLocals } from './types.js';
|
|
5
31
|
type ApiHttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
6
32
|
export type CommandKind = 'crud' | 'custom';
|
|
7
33
|
export type CommandScope = 'item' | 'collection';
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* SvelteKit-specific type definitions for session management
|
|
3
|
+
* @packageDocumentation
|
|
4
|
+
*/
|
|
5
|
+
import type { Membership } from '../models/Membership.js';
|
|
6
|
+
import type { User } from '../models/User.js';
|
|
3
7
|
/**
|
|
4
8
|
* Extended locals interface for SvelteKit
|
|
5
9
|
*
|
package/dist/sveltekit.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as OidcLoginService, D as resolveOidcProviderConfig, E as getUsersOidcConfig, S as OidcLoginError, T as encodeOidcTransaction, _ as readMobileBearerToken, a as TerminalAuthRateLimitError, g as MobileAuthService, h as MobileAuthError, i as TerminalAuthError, m as withSessionPermissionContext, o as TerminalAuthService, s as OperationPermissionError, v as validateMobileRedirectUri, w as decodeOidcTransaction, y as SessionService } from "./chunks/TerminalAuthService-
|
|
1
|
+
import { C as OidcLoginService, D as resolveOidcProviderConfig, E as getUsersOidcConfig, S as OidcLoginError, T as encodeOidcTransaction, _ as readMobileBearerToken, a as TerminalAuthRateLimitError, g as MobileAuthService, h as MobileAuthError, i as TerminalAuthError, m as withSessionPermissionContext, o as TerminalAuthService, s as OperationPermissionError, v as validateMobileRedirectUri, w as decodeOidcTransaction, y as SessionService } from "./chunks/TerminalAuthService-CLDmxYuC.js";
|
|
2
2
|
import { DiscoveryArtifactValidationError, SMRT_APP_RESULT_CONTRACT, SMRT_APP_RESULT_SCHEMA, SMRT_APP_RESULT_VERSION, SMRT_DISCOVERY_CONFORMANCE_ARTIFACT_SCHEMA, SMRT_DISCOVERY_CONFORMANCE_SCHEMA, SMRT_DISCOVERY_CONFORMANCE_VERSION, SMRT_MCP_RESULT_METADATA_KEY, canonicalizeDiscoveryArtifact, createDiscoveryConformanceArtifact, deriveCommandRequirements, validateDiscoveryConformanceArtifact } from "./app-contract.js";
|
|
3
3
|
import { ObjectRegistry, createClassNamePredicate, resolveCustomActionMetadata, resolveEffectiveActionMetadata } from "@happyvertical/smrt-core";
|
|
4
4
|
import { createLogger } from "@happyvertical/logger";
|
package/dist/ui.d.ts
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Users Module UI Slot Declarations
|
|
3
|
+
*
|
|
4
|
+
* This file defines the UI extension points for the users module.
|
|
5
|
+
* UI components are implemented in the ./svelte subpath.
|
|
6
|
+
*/
|
|
7
|
+
import type { ModuleUISlot, SmrtModuleMeta } from '@happyvertical/smrt-types';
|
|
2
8
|
/**
|
|
3
9
|
* Users module UI slots
|
|
4
10
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@happyvertical/smrt-users",
|
|
3
|
-
"version": "0.51.
|
|
3
|
+
"version": "0.51.33",
|
|
4
4
|
"smrtJsdoc": "strict",
|
|
5
5
|
"description": "Multi-tenant user management for the SMRT framework - users, tenants, roles, permissions, groups",
|
|
6
6
|
"type": "module",
|
|
@@ -47,25 +47,25 @@
|
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
49
|
"@happyvertical/logger": "^0.94.1",
|
|
50
|
-
"@happyvertical/smrt-config": "0.51.
|
|
51
|
-
"@happyvertical/smrt-core": "0.51.
|
|
52
|
-
"@happyvertical/smrt-mobile-contract": "0.51.
|
|
53
|
-
"@happyvertical/smrt-profiles": "0.51.
|
|
54
|
-
"@happyvertical/smrt-tenancy": "0.51.
|
|
55
|
-
"@happyvertical/smrt-types": "0.51.
|
|
56
|
-
"@happyvertical/smrt-ui": "0.51.
|
|
50
|
+
"@happyvertical/smrt-config": "0.51.33",
|
|
51
|
+
"@happyvertical/smrt-core": "0.51.33",
|
|
52
|
+
"@happyvertical/smrt-mobile-contract": "0.51.33",
|
|
53
|
+
"@happyvertical/smrt-profiles": "0.51.33",
|
|
54
|
+
"@happyvertical/smrt-tenancy": "0.51.33",
|
|
55
|
+
"@happyvertical/smrt-types": "0.51.33",
|
|
56
|
+
"@happyvertical/smrt-ui": "0.51.33",
|
|
57
57
|
"@happyvertical/sql": "^0.94.1",
|
|
58
58
|
"jose": "^6.2.12"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
|
-
"@happyvertical/smrt-vitest": "0.51.
|
|
61
|
+
"@happyvertical/smrt-vitest": "0.51.33",
|
|
62
62
|
"@sveltejs/package": "^2.5.8",
|
|
63
63
|
"@sveltejs/vite-plugin-svelte": "^7.3.0",
|
|
64
64
|
"@types/node": "24.13.6",
|
|
65
65
|
"fast-glob": "^3.3.3",
|
|
66
66
|
"svelte": "^5.57.1",
|
|
67
67
|
"svelte-check": "^4.7.6",
|
|
68
|
-
"typescript": "
|
|
68
|
+
"typescript": "6.0.3",
|
|
69
69
|
"vite": "8.1.4",
|
|
70
70
|
"vitest": "4.1.10"
|
|
71
71
|
},
|