@glinr/theauth 0.5.0 → 0.6.0

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.
@@ -1,7 +1,7 @@
1
1
  import { z } from 'zod';
2
- import { a6 as AuthAdapter, o as ResolvedUser, aj as KavachPlugin, D as Database, $ as AdminConfig, p as SessionManager, a3 as ApiKeyManagerConfig, af as EmailOtpConfig, P as Permission, ak as MagicLinkConfig, ap as OrgConfig, au as PasskeyConfig, Q as PluginEndpoint, aN as TotpConfig } from '../types-D1dTo8-m.js';
3
- export { v as AdminModule, a0 as AdminUser, a2 as ApiKey, w as ApiKeyManagerModule, ab as CaptchaConfig, H as CaptchaModule, ac as CaptchaVerifyResult, ad as CreateTokenInput, E as EmailOtpModule, ag as EmailVerificationConfig, z as EmailVerificationModule, r as MagicLinkModule, am as OidcProvider, an as OneTimeTokenConfig, B as OneTimeTokenModule, ao as OneTimeTokenPurpose, aq as OrgInvitation, ar as OrgMember, O as OrgModule, as as OrgRole, at as Organization, av as PasskeyCredential, t as PasskeyModule, aw as PasswordResetConfig, y as PasswordResetModule, ay as PhoneAuthConfig, G as PhoneAuthModule, aB as RevokeTokensResult, aC as SSO_ERROR, aD as SamlProvider, aG as SsoAuditEvent, aH as SsoConfig, aI as SsoConnection, aJ as SsoError, u as SsoModule, s as TotpModule, aO as TotpSetup, aP as UsernameAuthConfig, x as UsernameAuthModule, aQ as ValidateTokenResult, bC as WebhookConfig, bD as WebhookEvent, W as WebhookModule, a_ as createAdminModule, a$ as createApiKeyManagerModule, b1 as createCaptchaModule, b4 as createEmailOtpModule, b5 as createEmailVerificationModule, b6 as createMagicLinkModule, b7 as createOneTimeTokenModule, b8 as createOrgModule, b9 as createPasskeyModule, ba as createPasswordResetModule, bb as createPhoneAuthModule, be as createSsoModule, bf as createTotpModule, bg as createUsernameAuthModule, bE as createWebhookModule } from '../types-D1dTo8-m.js';
4
- import { R as Result } from '../types-IkWVkOVv.js';
2
+ import { a5 as AuthAdapter, t as ResolvedUser, i as TheAuthPlugin, D as Database, _ as AdminConfig, j as SessionManager, a2 as ApiKeyManagerConfig, ae as EmailOtpConfig, P as Permission, ag as MagicLinkConfig, al as OrgConfig, aq as PasskeyConfig, h as PluginEndpoint, aJ as TotpConfig } from '../types-JOx1R8-Q.js';
3
+ export { B as AdminModule, $ as AdminUser, a1 as ApiKey, F as ApiKeyManagerModule, aa as CaptchaConfig, N as CaptchaModule, ab as CaptchaVerifyResult, ac as CreateTokenInput, w as EmailOtpModule, af as EmailVerificationConfig, I as EmailVerificationModule, v as MagicLinkModule, ai as OidcProvider, aj as OneTimeTokenConfig, J as OneTimeTokenModule, ak as OneTimeTokenPurpose, am as OrgInvitation, an as OrgMember, O as OrgModule, ao as OrgRole, ap as Organization, ar as PasskeyCredential, y as PasskeyModule, as as PasswordResetConfig, H as PasswordResetModule, au as PhoneAuthConfig, L as PhoneAuthModule, ax as RevokeTokensResult, ay as SSO_ERROR, az as SamlProvider, aC as SsoAuditEvent, aD as SsoConfig, aE as SsoConnection, aF as SsoError, z as SsoModule, x as TotpModule, aK as TotpSetup, aL as UsernameAuthConfig, G as UsernameAuthModule, aM as ValidateTokenResult, by as WebhookConfig, bz as WebhookEvent, W as WebhookModule, aW as createAdminModule, aX as createApiKeyManagerModule, aZ as createCaptchaModule, b0 as createEmailOtpModule, b1 as createEmailVerificationModule, b2 as createMagicLinkModule, b3 as createOneTimeTokenModule, b4 as createOrgModule, b5 as createPasskeyModule, b6 as createPasswordResetModule, b7 as createPhoneAuthModule, ba as createSsoModule, bb as createTotpModule, bc as createUsernameAuthModule, bA as createWebhookModule } from '../types-JOx1R8-Q.js';
4
+ import { R as Result } from '../types-XoCxTUZj.js';
5
5
  import { AgentType, TrustTier } from '../standards/index.js';
6
6
  import * as jose from 'jose';
7
7
  import 'drizzle-orm/sqlite-core';
@@ -159,11 +159,11 @@ declare function headerAuth(options?: HeaderAuthOptions): AuthAdapter;
159
159
  *
160
160
  * @example
161
161
  * ```typescript
162
- * import { createKavach } from '@glinr/theauth';
162
+ * import { createTheAuth } from '@glinr/theauth';
163
163
  * import { additionalFields } from '@glinr/theauth/auth';
164
164
  *
165
- * const kavach = await createKavach({
166
- * database: { provider: 'sqlite', url: 'kavach.db' },
165
+ * const theauth = await createTheAuth({
166
+ * database: { provider: 'sqlite', url: 'theauth.db' },
167
167
  * plugins: [
168
168
  * additionalFields({
169
169
  * user: {
@@ -174,7 +174,7 @@ declare function headerAuth(options?: HeaderAuthOptions): AuthAdapter;
174
174
  * ],
175
175
  * });
176
176
  *
177
- * const mod = kavach.plugins.getContext().additionalFields as AdditionalFieldsModule;
177
+ * const mod = theauth.plugins.getContext().additionalFields as AdditionalFieldsModule;
178
178
  * await mod.setUserFields(userId, { plan: 'pro', credits: 100 });
179
179
  * const fields = await mod.getUserFields(userId);
180
180
  * // => { plan: 'pro', credits: 100 }
@@ -231,9 +231,9 @@ interface AdditionalFieldsModule {
231
231
  validate(fields: Record<string, unknown>, schema: "user" | "session"): ValidationResult;
232
232
  }
233
233
  declare function createAdditionalFieldsModule(config: AdditionalFieldsConfig, db: Database): AdditionalFieldsModule;
234
- declare function additionalFields(config?: AdditionalFieldsConfig): KavachPlugin;
234
+ declare function additionalFields(config?: AdditionalFieldsConfig): TheAuthPlugin;
235
235
 
236
- declare function admin(config?: AdminConfig): KavachPlugin;
236
+ declare function admin(config?: AdminConfig): TheAuthPlugin;
237
237
 
238
238
  /**
239
239
  * Anonymous authentication for TheAuth.
@@ -241,7 +241,7 @@ declare function admin(config?: AdminConfig): KavachPlugin;
241
241
  * Lets users start as guests without providing credentials. The anonymous
242
242
  * user can later be upgraded to a real account by supplying an email.
243
243
  *
244
- * Anonymous users are stored in `kavach_users` with a synthetic placeholder
244
+ * Anonymous users are stored in `theauth_users` with a synthetic placeholder
245
245
  * email (`anon_<uuid>@theauth.anonymous`) and a metadata flag
246
246
  * `{ anonymous: true }`. This satisfies the NOT NULL UNIQUE constraint on
247
247
  * the email column while keeping them easily identifiable.
@@ -285,9 +285,9 @@ interface AnonymousAuthModule {
285
285
  }
286
286
  declare function createAnonymousAuthModule(config: AnonymousAuthConfig, db: Database, sessionManager: SessionManager): AnonymousAuthModule;
287
287
 
288
- declare function anonymousAuth(config?: AnonymousAuthConfig): KavachPlugin;
288
+ declare function anonymousAuth(config?: AnonymousAuthConfig): TheAuthPlugin;
289
289
 
290
- declare function apiKeys(config?: ApiKeyManagerConfig): KavachPlugin;
290
+ declare function apiKeys(config?: ApiKeyManagerConfig): TheAuthPlugin;
291
291
 
292
292
  interface CostAttributionConfig {
293
293
  /** ISO 4217 currency code, default 'USD' */
@@ -386,11 +386,11 @@ declare function createCostAttributionModule(db: Database, config?: CostAttribut
386
386
  *
387
387
  * @example
388
388
  * ```typescript
389
- * import { createKavach } from '@glinr/theauth';
389
+ * import { createTheAuth } from '@glinr/theauth';
390
390
  * import { customSession } from '@glinr/theauth/auth';
391
391
  *
392
- * const kavach = await createKavach({
393
- * database: { provider: 'sqlite', url: 'kavach.db' },
392
+ * const theauth = await createTheAuth({
393
+ * database: { provider: 'sqlite', url: 'theauth.db' },
394
394
  * auth: { session: { secret: process.env.SESSION_SECRET } },
395
395
  * plugins: [
396
396
  * customSession({
@@ -400,8 +400,8 @@ declare function createCostAttributionModule(db: Database, config?: CostAttribut
400
400
  * ],
401
401
  * });
402
402
  *
403
- * // After a session is created via kavach.auth.session.create(...)
404
- * const mod = kavach.plugins.getContext().customSession as CustomSessionModule;
403
+ * // After a session is created via theauth.auth.session.create(...)
404
+ * const mod = theauth.plugins.getContext().customSession as CustomSessionModule;
405
405
  * const fields = await mod.getSessionFields(session.id);
406
406
  * // => { theme: 'dark', lastSeen: 1234567890 }
407
407
  * ```
@@ -432,7 +432,7 @@ interface CustomSessionModule {
432
432
  updateSessionFields(sessionId: string, fields: Record<string, unknown>): Promise<void>;
433
433
  }
434
434
  declare function createCustomSessionModule(_config: CustomSessionConfig, db: Database): CustomSessionModule;
435
- declare function customSession(config?: CustomSessionConfig): KavachPlugin;
435
+ declare function customSession(config?: CustomSessionConfig): TheAuthPlugin;
436
436
 
437
437
  /**
438
438
  * OAuth Device Authorization Grant (RFC 8628) for TheAuth.
@@ -501,9 +501,9 @@ interface DeviceAuthModule {
501
501
  }
502
502
  declare function createDeviceAuthModule(config: DeviceAuthConfig): DeviceAuthModule;
503
503
 
504
- declare function deviceAuth(config: DeviceAuthConfig): KavachPlugin;
504
+ declare function deviceAuth(config: DeviceAuthConfig): TheAuthPlugin;
505
505
 
506
- declare function emailOtp(config: EmailOtpConfig): KavachPlugin;
506
+ declare function emailOtp(config: EmailOtpConfig): TheAuthPlugin;
507
507
 
508
508
  /**
509
509
  * Ephemeral agent sessions for TheAuth.
@@ -601,7 +601,7 @@ declare function createEphemeralSessionModule(config: EphemeralSessionConfig): E
601
601
  * changes, auth events, and anomalies. SOC teams and monitoring systems can
602
602
  * subscribe instead of polling the audit API or relying solely on webhooks.
603
603
  *
604
- * Endpoint: GET /api/kavach/events/stream
604
+ * Endpoint: GET /api/theauth/events/stream
605
605
  * Auth: Bearer token via Authorization header or `?token=` query param
606
606
  * Filtering: `?types=audit,agent.created`
607
607
  * Replay: `?since=2026-01-01T00:00:00Z` or Last-Event-ID header
@@ -677,7 +677,7 @@ declare function createEventStreamModule(config: EventStreamConfig): EventStream
677
677
  *
678
678
  * Federation tokens are short-lived JWTs signed by the source instance.
679
679
  * The target instance verifies them by fetching the source's public key
680
- * from `/.well-known/kavach-federation.json`. Optionally, a Verifiable
680
+ * from `/.well-known/theauth-federation.json`. Optionally, a Verifiable
681
681
  * Credential can be embedded for offline verification.
682
682
  *
683
683
  * @example
@@ -774,7 +774,7 @@ interface IssueFederationTokenInput {
774
774
  /** Optional VC JWT to embed */
775
775
  credential?: string;
776
776
  }
777
- /** The well-known document served at /.well-known/kavach-federation.json */
777
+ /** The well-known document served at /.well-known/theauth-federation.json */
778
778
  interface FederationWellKnown {
779
779
  instanceId: string;
780
780
  instanceUrl: string;
@@ -925,17 +925,17 @@ declare function createGdprModule(db: Database): GdprModule;
925
925
  *
926
926
  * @example
927
927
  * ```typescript
928
- * import { createKavach } from '@glinr/theauth';
928
+ * import { createTheAuth } from '@glinr/theauth';
929
929
  * import { gdpr } from '@glinr/theauth/auth';
930
930
  *
931
- * const kavach = await createKavach({
932
- * database: { provider: 'sqlite', url: 'kavach.db' },
931
+ * const theauth = await createTheAuth({
932
+ * database: { provider: 'sqlite', url: 'theauth.db' },
933
933
  * plugins: [gdpr()],
934
934
  * });
935
935
  * ```
936
936
  */
937
937
 
938
- declare function gdpr(): KavachPlugin;
938
+ declare function gdpr(): TheAuthPlugin;
939
939
 
940
940
  /**
941
941
  * Have I Been Pwned password checking for TheAuth.
@@ -1218,7 +1218,7 @@ interface LastLoginModule {
1218
1218
  */
1219
1219
  declare function createLastLoginModule(config: LastLoginConfig, db: Database): LastLoginModule;
1220
1220
 
1221
- declare function magicLink(config: MagicLinkConfig): KavachPlugin;
1221
+ declare function magicLink(config: MagicLinkConfig): TheAuthPlugin;
1222
1222
 
1223
1223
  /**
1224
1224
  * Types for the OAuth 2.0 / OIDC provider system.
@@ -1401,8 +1401,8 @@ interface OAuthAccount {
1401
1401
  * 3. `linkAccount` — manually link provider tokens to an existing user.
1402
1402
  * 4. `findLinkedUser` — look up which user owns a provider account.
1403
1403
  *
1404
- * All state operations use the `kavach_oauth_states` table; all account links
1405
- * use the `kavach_oauth_accounts` table — both defined in `./schema.ts`.
1404
+ * All state operations use the `theauth_oauth_states` table; all account links
1405
+ * use the `theauth_oauth_accounts` table — both defined in `./schema.ts`.
1406
1406
  */
1407
1407
 
1408
1408
  /**
@@ -1440,7 +1440,7 @@ interface OAuthPluginConfig extends OAuthModuleConfig {
1440
1440
  */
1441
1441
  buildRedirectUri?: (provider: string, baseUrl: string) => string;
1442
1442
  }
1443
- declare function oauth(config: OAuthPluginConfig): KavachPlugin;
1443
+ declare function oauth(config: OAuthPluginConfig): TheAuthPlugin;
1444
1444
 
1445
1445
  /**
1446
1446
  * Apple Sign In provider (OAuth 2.0 / OIDC).
@@ -2437,7 +2437,7 @@ interface OAuthProxyPluginConfig extends OAuthProxyConfig {
2437
2437
  */
2438
2438
  providers: Record<string, OAuthProvider>;
2439
2439
  }
2440
- declare function oauthProxy(config: OAuthProxyPluginConfig): KavachPlugin;
2440
+ declare function oauthProxy(config: OAuthProxyPluginConfig): TheAuthPlugin;
2441
2441
 
2442
2442
  /**
2443
2443
  * OIDC Provider module for TheAuth.
@@ -2620,8 +2620,8 @@ declare function createOidcProviderModule(config: OidcProviderConfig, db: Databa
2620
2620
  *
2621
2621
  * @example
2622
2622
  * ```typescript
2623
- * const kavach = await createKavach({
2624
- * database: { provider: 'sqlite', url: 'kavach.db' },
2623
+ * const theauth = await createTheAuth({
2624
+ * database: { provider: 'sqlite', url: 'theauth.db' },
2625
2625
  * auth: { session: { secret: process.env.SESSION_SECRET } },
2626
2626
  * });
2627
2627
  *
@@ -2675,13 +2675,13 @@ declare class OneTapVerifyError extends Error {
2675
2675
  }
2676
2676
  declare function createOneTapModule(config: OneTapConfig, db: Database, sessionManager: SessionManager): OneTapModule;
2677
2677
 
2678
- declare function oneTap(config: OneTapConfig): KavachPlugin;
2678
+ declare function oneTap(config: OneTapConfig): TheAuthPlugin;
2679
2679
 
2680
2680
  /**
2681
2681
  * OpenAPI 3.1 spec generation plugin for TheAuth.
2682
2682
  *
2683
2683
  * Generates a complete OpenAPI document from TheAuth's registered auth
2684
- * endpoints. Useful for serving at `/api/kavach/openapi.json` or wiring
2684
+ * endpoints. Useful for serving at `/api/theauth/openapi.json` or wiring
2685
2685
  * into Swagger UI / Scalar.
2686
2686
  *
2687
2687
  * @example
@@ -2710,7 +2710,7 @@ interface OpenApiConfig {
2710
2710
  description?: string;
2711
2711
  /** Server base URL. Default: "/" */
2712
2712
  serverUrl?: string;
2713
- /** Path prefix for all TheAuth endpoints. Default: "/api/kavach" */
2713
+ /** Path prefix for all TheAuth endpoints. Default: "/api/theauth" */
2714
2714
  basePath?: string;
2715
2715
  /**
2716
2716
  * Limit which endpoint groups are included in the spec.
@@ -2819,9 +2819,9 @@ interface OpenApiModule {
2819
2819
  */
2820
2820
  declare function createOpenApiModule(): OpenApiModule;
2821
2821
 
2822
- declare function organization(config?: OrgConfig): KavachPlugin;
2822
+ declare function organization(config?: OrgConfig): TheAuthPlugin;
2823
2823
 
2824
- declare function passkey(config: PasskeyConfig): KavachPlugin;
2824
+ declare function passkey(config: PasskeyConfig): TheAuthPlugin;
2825
2825
 
2826
2826
  /**
2827
2827
  * Polar payment integration for TheAuth.
@@ -2886,7 +2886,7 @@ interface PolarModule {
2886
2886
  }
2887
2887
  declare function createPolarModule(config: PolarConfig, db: Database): PolarModule;
2888
2888
 
2889
- declare function polar(config: PolarConfig): KavachPlugin;
2889
+ declare function polar(config: PolarConfig): TheAuthPlugin;
2890
2890
 
2891
2891
  /**
2892
2892
  * Shared store interface for the rateLimit() plugin.
@@ -2916,11 +2916,11 @@ interface RateLimitStore {
2916
2916
  *
2917
2917
  * @example
2918
2918
  * ```typescript
2919
- * import { createKavach } from '@glinr/theauth';
2919
+ * import { createTheAuth } from '@glinr/theauth';
2920
2920
  * import { rateLimit } from '@glinr/theauth/auth';
2921
2921
  * import { kvStore } from '@glinr/theauth/auth/stores/kv';
2922
2922
  *
2923
- * const kavach = createKavach({
2923
+ * const theauth = createTheAuth({
2924
2924
  * plugins: [
2925
2925
  * rateLimit({
2926
2926
  * signIn: { window: '15m', max: 10 },
@@ -2970,7 +2970,7 @@ interface RateLimitConfig$1 {
2970
2970
  */
2971
2971
  onLimit?: (request: Request, retryAfter: number) => Response;
2972
2972
  }
2973
- declare function rateLimit(config?: RateLimitConfig$1): KavachPlugin;
2973
+ declare function rateLimit(config?: RateLimitConfig$1): TheAuthPlugin;
2974
2974
 
2975
2975
  /**
2976
2976
  * In-memory sliding window rate limiter for auth endpoints.
@@ -3128,7 +3128,7 @@ declare function createReBACModule(config: ReBACConfig, db: Database): ReBACModu
3128
3128
  * providers (Okta, Azure AD, Google Workspace) to provision and deprovision
3129
3129
  * users and groups automatically.
3130
3130
  *
3131
- * Users map to kavach_users. Groups map to kavach_organizations.
3131
+ * Users map to theauth_users. Groups map to theauth_organizations.
3132
3132
  *
3133
3133
  * @example
3134
3134
  * ```typescript
@@ -3157,6 +3157,26 @@ interface ScimConfig {
3157
3157
  onProvision?: (user: ScimUser) => Promise<void>;
3158
3158
  /** Callback when user is deprovisioned */
3159
3159
  onDeprovision?: (userId: string) => Promise<void>;
3160
+ /**
3161
+ * Resolves the user id the current request speaks for. Required to enable
3162
+ * `GET /scim/v2/Me`. If omitted, `/Me` returns 501 with a clear detail.
3163
+ * The resolver should derive the id from the bearer token or associated
3164
+ * session and return `null` when the caller is not tied to a user.
3165
+ */
3166
+ resolveSelf?: (request: Request) => Promise<string | null>;
3167
+ /**
3168
+ * Audit every SCIM provisioning write. When configured, each
3169
+ * POST/PUT/PATCH/DELETE on /Users or /Groups writes an `auditLogs` row
3170
+ * attributed to `agentId`. The caller is responsible for pre-creating a
3171
+ * system agent and passing its id. Set `enabled: false` to turn off
3172
+ * writes without deleting the agent (useful in tests).
3173
+ */
3174
+ audit?: {
3175
+ /** FK to kavach_agents.id — typically a dedicated "scim-provisioner" system agent. */
3176
+ agentId: string;
3177
+ /** Defaults to true when `audit` is set. */
3178
+ enabled?: boolean;
3179
+ };
3160
3180
  }
3161
3181
  interface ScimUser {
3162
3182
  id: string;
@@ -3196,11 +3216,11 @@ declare function createScimModule(config: ScimConfig, db: Database): ScimModule;
3196
3216
  *
3197
3217
  * @example
3198
3218
  * ```typescript
3199
- * import { createKavach } from '@glinr/theauth';
3219
+ * import { createTheAuth } from '@glinr/theauth';
3200
3220
  * import { scim } from '@glinr/theauth/auth';
3201
3221
  *
3202
- * const kavach = await createKavach({
3203
- * database: { provider: 'sqlite', url: 'kavach.db' },
3222
+ * const theauth = await createTheAuth({
3223
+ * database: { provider: 'sqlite', url: 'theauth.db' },
3204
3224
  * plugins: [
3205
3225
  * scim({
3206
3226
  * bearerToken: process.env.SCIM_TOKEN,
@@ -3212,7 +3232,7 @@ declare function createScimModule(config: ScimConfig, db: Database): ScimModule;
3212
3232
  * });
3213
3233
  * ```
3214
3234
  */
3215
- declare function scim(config: ScimConfig): KavachPlugin;
3235
+ declare function scim(config: ScimConfig): TheAuthPlugin;
3216
3236
 
3217
3237
  /**
3218
3238
  * Sign In With Ethereum (SIWE) for TheAuth.
@@ -3276,7 +3296,7 @@ interface SiweVerifyResult {
3276
3296
  }
3277
3297
  declare function createSiweModule(config: SiweConfig): SiweModule;
3278
3298
 
3279
- declare function siwe(config: SiweConfig): KavachPlugin;
3299
+ declare function siwe(config: SiweConfig): TheAuthPlugin;
3280
3300
 
3281
3301
  /**
3282
3302
  * Cloudflare KV rate limit store.
@@ -3400,10 +3420,10 @@ interface StripeModule {
3400
3420
  }
3401
3421
  declare function createStripeModule(config: StripeConfig, db: Database): StripeModule;
3402
3422
 
3403
- declare function stripe(config: StripeConfig): KavachPlugin;
3423
+ declare function stripe(config: StripeConfig): TheAuthPlugin;
3404
3424
 
3405
3425
  type TwoFactorConfig = TotpConfig;
3406
- declare function twoFactor(config?: TwoFactorConfig): KavachPlugin;
3426
+ declare function twoFactor(config?: TwoFactorConfig): TheAuthPlugin;
3407
3427
 
3408
3428
  /**
3409
3429
  * Trusted device windows for 2FA in TheAuth.