@robelest/convex-auth 0.0.4-preview.2 → 0.0.4-preview.21
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/README.md +67 -26
- package/dist/authorization/index.d.ts +63 -0
- package/dist/authorization/index.d.ts.map +1 -0
- package/dist/authorization/index.js +63 -0
- package/dist/authorization/index.js.map +1 -0
- package/dist/bin.js +6185 -0
- package/dist/client/core/types.d.ts +20 -0
- package/dist/client/core/types.d.ts.map +1 -0
- package/dist/client/index.d.ts +2 -299
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +407 -534
- package/dist/client/index.js.map +1 -1
- package/dist/component/_generated/api.d.ts +42 -0
- package/dist/component/_generated/api.d.ts.map +1 -1
- package/dist/component/_generated/api.js.map +1 -1
- package/dist/component/_generated/component.d.ts +2546 -90
- package/dist/component/_generated/component.d.ts.map +1 -1
- package/dist/component/client/core/types.d.ts +2 -0
- package/dist/component/client/index.d.ts +2 -0
- package/dist/component/convex.config.d.ts +2 -2
- package/dist/component/functions.d.ts +11 -9
- package/dist/component/functions.d.ts.map +1 -1
- package/dist/component/functions.js.map +1 -1
- package/dist/component/index.d.ts +7 -11
- package/dist/component/index.js +2 -3
- package/dist/component/model.d.ts +153 -0
- package/dist/component/model.d.ts.map +1 -0
- package/dist/component/model.js +349 -0
- package/dist/component/model.js.map +1 -0
- package/dist/component/providers/anonymous.d.ts +54 -0
- package/dist/component/providers/anonymous.d.ts.map +1 -0
- package/dist/component/providers/credentials.d.ts +5 -5
- package/dist/component/providers/credentials.d.ts.map +1 -1
- package/dist/component/providers/device.d.ts +67 -0
- package/dist/component/providers/device.d.ts.map +1 -0
- package/dist/component/providers/email.d.ts +62 -0
- package/dist/component/providers/email.d.ts.map +1 -0
- package/dist/component/providers/oauth.d.ts.map +1 -1
- package/dist/component/providers/oauth.js.map +1 -1
- package/dist/component/providers/passkey.d.ts +57 -0
- package/dist/component/providers/passkey.d.ts.map +1 -0
- package/dist/component/providers/password.d.ts +88 -0
- package/dist/component/providers/password.d.ts.map +1 -0
- package/dist/component/providers/phone.d.ts +48 -0
- package/dist/component/providers/phone.d.ts.map +1 -0
- package/dist/component/providers/sso.d.ts +50 -0
- package/dist/component/providers/sso.d.ts.map +1 -0
- package/dist/component/providers/totp.d.ts +45 -0
- package/dist/component/providers/totp.d.ts.map +1 -0
- package/dist/component/public/enterprise/audit.d.ts +73 -0
- package/dist/component/public/enterprise/audit.d.ts.map +1 -0
- package/dist/component/public/enterprise/audit.js +108 -0
- package/dist/component/public/enterprise/audit.js.map +1 -0
- package/dist/component/public/enterprise/core.d.ts +176 -0
- package/dist/component/public/enterprise/core.d.ts.map +1 -0
- package/dist/component/public/enterprise/core.js +292 -0
- package/dist/component/public/enterprise/core.js.map +1 -0
- package/dist/component/public/enterprise/domains.d.ts +174 -0
- package/dist/component/public/enterprise/domains.d.ts.map +1 -0
- package/dist/component/public/enterprise/domains.js +271 -0
- package/dist/component/public/enterprise/domains.js.map +1 -0
- package/dist/component/public/enterprise/scim.d.ts +245 -0
- package/dist/component/public/enterprise/scim.d.ts.map +1 -0
- package/dist/component/public/enterprise/scim.js +344 -0
- package/dist/component/public/enterprise/scim.js.map +1 -0
- package/dist/component/public/enterprise/secrets.d.ts +78 -0
- package/dist/component/public/enterprise/secrets.d.ts.map +1 -0
- package/dist/component/public/enterprise/secrets.js +118 -0
- package/dist/component/public/enterprise/secrets.js.map +1 -0
- package/dist/component/public/enterprise/webhooks.d.ts +211 -0
- package/dist/component/public/enterprise/webhooks.d.ts.map +1 -0
- package/dist/component/public/enterprise/webhooks.js +300 -0
- package/dist/component/public/enterprise/webhooks.js.map +1 -0
- package/dist/component/public/factors/devices.d.ts +157 -0
- package/dist/component/public/factors/devices.d.ts.map +1 -0
- package/dist/component/public/factors/devices.js +216 -0
- package/dist/component/public/factors/devices.js.map +1 -0
- package/dist/component/public/factors/passkeys.d.ts +175 -0
- package/dist/component/public/factors/passkeys.d.ts.map +1 -0
- package/dist/component/public/factors/passkeys.js +238 -0
- package/dist/component/public/factors/passkeys.js.map +1 -0
- package/dist/component/public/factors/totp.d.ts +189 -0
- package/dist/component/public/factors/totp.d.ts.map +1 -0
- package/dist/component/public/factors/totp.js +254 -0
- package/dist/component/public/factors/totp.js.map +1 -0
- package/dist/component/public/groups/core.d.ts +137 -0
- package/dist/component/public/groups/core.d.ts.map +1 -0
- package/dist/component/public/groups/core.js +321 -0
- package/dist/component/public/groups/core.js.map +1 -0
- package/dist/component/public/groups/invites.d.ts +217 -0
- package/dist/component/public/groups/invites.d.ts.map +1 -0
- package/dist/component/public/groups/invites.js +457 -0
- package/dist/component/public/groups/invites.js.map +1 -0
- package/dist/component/public/groups/members.d.ts +204 -0
- package/dist/component/public/groups/members.d.ts.map +1 -0
- package/dist/component/public/groups/members.js +355 -0
- package/dist/component/public/groups/members.js.map +1 -0
- package/dist/component/public/identity/accounts.d.ts +147 -0
- package/dist/component/public/identity/accounts.d.ts.map +1 -0
- package/dist/component/public/identity/accounts.js +200 -0
- package/dist/component/public/identity/accounts.js.map +1 -0
- package/dist/component/public/identity/codes.d.ts +104 -0
- package/dist/component/public/identity/codes.d.ts.map +1 -0
- package/dist/component/public/identity/codes.js +140 -0
- package/dist/component/public/identity/codes.js.map +1 -0
- package/dist/component/public/identity/sessions.d.ts +128 -0
- package/dist/component/public/identity/sessions.d.ts.map +1 -0
- package/dist/component/public/identity/sessions.js +192 -0
- package/dist/component/public/identity/sessions.js.map +1 -0
- package/dist/component/public/identity/tokens.d.ts +169 -0
- package/dist/component/public/identity/tokens.d.ts.map +1 -0
- package/dist/component/public/identity/tokens.js +227 -0
- package/dist/component/public/identity/tokens.js.map +1 -0
- package/dist/component/public/identity/users.d.ts +212 -0
- package/dist/component/public/identity/users.d.ts.map +1 -0
- package/dist/component/public/identity/users.js +311 -0
- package/dist/component/public/identity/users.js.map +1 -0
- package/dist/component/public/identity/verifiers.d.ts +116 -0
- package/dist/component/public/identity/verifiers.d.ts.map +1 -0
- package/dist/component/public/identity/verifiers.js +154 -0
- package/dist/component/public/identity/verifiers.js.map +1 -0
- package/dist/component/public/security/keys.d.ts +209 -0
- package/dist/component/public/security/keys.d.ts.map +1 -0
- package/dist/component/public/security/keys.js +319 -0
- package/dist/component/public/security/keys.js.map +1 -0
- package/dist/component/public/security/limits.d.ts +114 -0
- package/dist/component/public/security/limits.d.ts.map +1 -0
- package/dist/component/public/security/limits.js +169 -0
- package/dist/component/public/security/limits.js.map +1 -0
- package/dist/component/public.d.ts +24 -271
- package/dist/component/public.d.ts.map +1 -1
- package/dist/component/public.js +21 -1229
- package/dist/component/schema.d.ts +473 -110
- package/dist/component/schema.js +162 -73
- package/dist/component/schema.js.map +1 -1
- package/dist/component/server/auth.d.ts +318 -373
- package/dist/component/server/auth.d.ts.map +1 -1
- package/dist/component/server/auth.js +204 -123
- package/dist/component/server/auth.js.map +1 -1
- package/dist/component/server/authError.js +34 -0
- package/dist/component/server/authError.js.map +1 -0
- package/dist/component/server/{providers.js → config.js} +43 -12
- package/dist/component/server/config.js.map +1 -0
- package/dist/component/server/cookies.js +3 -0
- package/dist/component/server/cookies.js.map +1 -1
- package/dist/component/server/core.js +713 -0
- package/dist/component/server/core.js.map +1 -0
- package/dist/component/server/crypto.js +38 -0
- package/dist/component/server/crypto.js.map +1 -0
- package/dist/component/server/{implementation/db.js → db.js} +2 -1
- package/dist/component/server/db.js.map +1 -0
- package/dist/component/server/device.js +109 -0
- package/dist/component/server/device.js.map +1 -0
- package/dist/component/server/enterprise/config.js +46 -0
- package/dist/component/server/enterprise/config.js.map +1 -0
- package/dist/component/server/enterprise/domain.js +885 -0
- package/dist/component/server/enterprise/domain.js.map +1 -0
- package/dist/component/server/enterprise/http.js +766 -0
- package/dist/component/server/enterprise/http.js.map +1 -0
- package/dist/component/server/enterprise/oidc.js +248 -0
- package/dist/component/server/enterprise/oidc.js.map +1 -0
- package/dist/component/server/enterprise/policy.js +85 -0
- package/dist/component/server/enterprise/policy.js.map +1 -0
- package/dist/component/server/enterprise/saml.js +338 -0
- package/dist/component/server/enterprise/saml.js.map +1 -0
- package/dist/component/server/enterprise/scim.js +97 -0
- package/dist/component/server/enterprise/scim.js.map +1 -0
- package/dist/component/server/enterprise/shared.js +51 -0
- package/dist/component/server/enterprise/shared.js.map +1 -0
- package/dist/component/server/errors.d.ts +1 -0
- package/dist/component/server/errors.js +24 -16
- package/dist/component/server/errors.js.map +1 -1
- package/dist/component/server/http.js +288 -0
- package/dist/component/server/http.js.map +1 -0
- package/dist/component/server/identity.js +13 -0
- package/dist/component/server/identity.js.map +1 -0
- package/dist/{server/implementation → component/server}/keys.js +9 -31
- package/dist/component/server/keys.js.map +1 -0
- package/dist/component/server/limits.js +61 -0
- package/dist/component/server/limits.js.map +1 -0
- package/dist/component/server/mutations/account.js +44 -0
- package/dist/component/server/mutations/account.js.map +1 -0
- package/dist/component/server/{implementation/mutations → mutations}/code.js +7 -4
- package/dist/component/server/mutations/code.js.map +1 -0
- package/dist/component/server/mutations/invalidate.js +32 -0
- package/dist/component/server/mutations/invalidate.js.map +1 -0
- package/dist/component/server/mutations/oauth.js +110 -0
- package/dist/component/server/mutations/oauth.js.map +1 -0
- package/dist/component/server/mutations/refresh.js +119 -0
- package/dist/component/server/mutations/refresh.js.map +1 -0
- package/dist/component/server/mutations/register.js +83 -0
- package/dist/component/server/mutations/register.js.map +1 -0
- package/dist/component/server/mutations/retrieve.js +65 -0
- package/dist/component/server/mutations/retrieve.js.map +1 -0
- package/dist/component/server/mutations/signature.js +32 -0
- package/dist/component/server/mutations/signature.js.map +1 -0
- package/dist/component/server/{implementation/mutations → mutations}/signin.js +2 -2
- package/dist/component/server/mutations/signin.js.map +1 -0
- package/dist/component/server/mutations/signout.js +27 -0
- package/dist/component/server/mutations/signout.js.map +1 -0
- package/dist/component/server/mutations/store/refs.js +15 -0
- package/dist/component/server/mutations/store/refs.js.map +1 -0
- package/dist/component/server/mutations/store.js +85 -0
- package/dist/component/server/mutations/store.js.map +1 -0
- package/dist/component/server/mutations/verifier.js +18 -0
- package/dist/component/server/mutations/verifier.js.map +1 -0
- package/dist/component/server/mutations/verify.js +98 -0
- package/dist/component/server/mutations/verify.js.map +1 -0
- package/dist/component/server/oauth.js +106 -60
- package/dist/component/server/oauth.js.map +1 -1
- package/dist/component/server/passkey.js +328 -0
- package/dist/component/server/passkey.js.map +1 -0
- package/dist/{server/implementation → component/server}/redirects.js +13 -11
- package/dist/component/server/redirects.js.map +1 -0
- package/dist/component/server/refresh.js +96 -0
- package/dist/component/server/refresh.js.map +1 -0
- package/dist/component/server/runtime.d.ts +136 -0
- package/dist/component/server/runtime.d.ts.map +1 -0
- package/dist/component/server/runtime.js +413 -0
- package/dist/component/server/runtime.js.map +1 -0
- package/dist/{server/implementation → component/server}/sessions.js +14 -8
- package/dist/component/server/sessions.js.map +1 -0
- package/dist/component/server/signin.js +201 -0
- package/dist/component/server/signin.js.map +1 -0
- package/dist/component/server/tokens.js +17 -0
- package/dist/component/server/tokens.js.map +1 -0
- package/dist/component/server/totp.js +148 -0
- package/dist/component/server/totp.js.map +1 -0
- package/dist/component/server/types.d.ts +387 -298
- package/dist/component/server/types.d.ts.map +1 -1
- package/dist/component/server/{implementation/types.js → types.js} +1 -1
- package/dist/component/server/types.js.map +1 -0
- package/dist/component/server/{implementation/users.js → users.js} +54 -35
- package/dist/component/server/users.js.map +1 -0
- package/dist/component/server/utils.js +110 -4
- package/dist/component/server/utils.js.map +1 -1
- package/dist/core/types.d.ts +369 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/factors/device.js +105 -0
- package/dist/factors/device.js.map +1 -0
- package/dist/factors/passkey.js +181 -0
- package/dist/factors/passkey.js.map +1 -0
- package/dist/factors/totp.js +122 -0
- package/dist/factors/totp.js.map +1 -0
- package/dist/providers/anonymous.d.ts +3 -9
- package/dist/providers/anonymous.d.ts.map +1 -1
- package/dist/providers/anonymous.js +1 -18
- package/dist/providers/anonymous.js.map +1 -1
- package/dist/providers/credentials.d.ts +8 -10
- package/dist/providers/credentials.d.ts.map +1 -1
- package/dist/providers/credentials.js +3 -5
- package/dist/providers/credentials.js.map +1 -1
- package/dist/providers/device.d.ts +18 -10
- package/dist/providers/device.d.ts.map +1 -1
- package/dist/providers/device.js +4 -8
- package/dist/providers/device.js.map +1 -1
- package/dist/providers/email.d.ts +50 -23
- package/dist/providers/email.d.ts.map +1 -1
- package/dist/providers/email.js +58 -34
- package/dist/providers/email.js.map +1 -1
- package/dist/providers/index.d.ts +7 -3
- package/dist/providers/index.js +4 -1
- package/dist/providers/oauth.d.ts.map +1 -1
- package/dist/providers/oauth.js.map +1 -1
- package/dist/providers/passkey.d.ts +12 -9
- package/dist/providers/passkey.d.ts.map +1 -1
- package/dist/providers/passkey.js +1 -7
- package/dist/providers/passkey.js.map +1 -1
- package/dist/providers/password.d.ts +6 -12
- package/dist/providers/password.d.ts.map +1 -1
- package/dist/providers/password.js +189 -89
- package/dist/providers/password.js.map +1 -1
- package/dist/providers/phone.d.ts +40 -11
- package/dist/providers/phone.d.ts.map +1 -1
- package/dist/providers/phone.js +52 -21
- package/dist/providers/phone.js.map +1 -1
- package/dist/providers/sso.d.ts +50 -0
- package/dist/providers/sso.d.ts.map +1 -0
- package/dist/providers/sso.js +34 -0
- package/dist/providers/sso.js.map +1 -0
- package/dist/providers/totp.d.ts +12 -9
- package/dist/providers/totp.d.ts.map +1 -1
- package/dist/providers/totp.js +1 -7
- package/dist/providers/totp.js.map +1 -1
- package/dist/runtime/browser.js +68 -0
- package/dist/runtime/browser.js.map +1 -0
- package/dist/runtime/invite.js +51 -0
- package/dist/runtime/invite.js.map +1 -0
- package/dist/runtime/proxy.js +70 -0
- package/dist/runtime/proxy.js.map +1 -0
- package/dist/runtime/storage.js +37 -0
- package/dist/runtime/storage.js.map +1 -0
- package/dist/server/auth.d.ts +335 -370
- package/dist/server/auth.d.ts.map +1 -1
- package/dist/server/auth.js +204 -123
- package/dist/server/auth.js.map +1 -1
- package/dist/server/authError.d.ts +46 -0
- package/dist/server/authError.d.ts.map +1 -0
- package/dist/server/authError.js +34 -0
- package/dist/server/authError.js.map +1 -0
- package/dist/server/config.d.ts +1 -0
- package/dist/server/{providers.js → config.js} +43 -12
- package/dist/server/config.js.map +1 -0
- package/dist/server/cookies.d.ts +1 -38
- package/dist/server/cookies.js +3 -0
- package/dist/server/cookies.js.map +1 -1
- package/dist/server/core.d.ts +1436 -0
- package/dist/server/core.d.ts.map +1 -0
- package/dist/server/core.js +713 -0
- package/dist/server/core.js.map +1 -0
- package/dist/server/crypto.d.ts +8 -0
- package/dist/server/crypto.d.ts.map +1 -0
- package/dist/server/crypto.js +38 -0
- package/dist/server/crypto.js.map +1 -0
- package/dist/server/db.d.ts +1 -0
- package/dist/server/{implementation/db.js → db.js} +2 -1
- package/dist/server/db.js.map +1 -0
- package/dist/server/device.d.ts +1 -0
- package/dist/server/device.js +109 -0
- package/dist/server/device.js.map +1 -0
- package/dist/server/enterprise/config.d.ts +1 -0
- package/dist/server/enterprise/config.js +46 -0
- package/dist/server/enterprise/config.js.map +1 -0
- package/dist/server/enterprise/domain.d.ts +409 -0
- package/dist/server/enterprise/domain.d.ts.map +1 -0
- package/dist/server/enterprise/domain.js +885 -0
- package/dist/server/enterprise/domain.js.map +1 -0
- package/dist/server/enterprise/http.d.ts +26 -0
- package/dist/server/enterprise/http.d.ts.map +1 -0
- package/dist/server/enterprise/http.js +766 -0
- package/dist/server/enterprise/http.js.map +1 -0
- package/dist/server/enterprise/oidc.d.ts +1 -0
- package/dist/server/enterprise/oidc.js +248 -0
- package/dist/server/enterprise/oidc.js.map +1 -0
- package/dist/server/enterprise/policy.d.ts +1 -0
- package/dist/server/enterprise/policy.js +85 -0
- package/dist/server/enterprise/policy.js.map +1 -0
- package/dist/server/enterprise/saml.d.ts +1 -0
- package/dist/server/enterprise/saml.js +338 -0
- package/dist/server/enterprise/saml.js.map +1 -0
- package/dist/server/enterprise/scim.d.ts +1 -0
- package/dist/server/enterprise/scim.js +97 -0
- package/dist/server/enterprise/scim.js.map +1 -0
- package/dist/server/enterprise/shared.d.ts +5 -0
- package/dist/server/enterprise/shared.d.ts.map +1 -0
- package/dist/server/enterprise/shared.js +51 -0
- package/dist/server/enterprise/shared.js.map +1 -0
- package/dist/server/enterprise/validators.d.ts +1 -0
- package/dist/server/enterprise/validators.js +60 -0
- package/dist/server/enterprise/validators.js.map +1 -0
- package/dist/server/errors.d.ts +33 -1
- package/dist/server/errors.d.ts.map +1 -1
- package/dist/server/errors.js +44 -1
- package/dist/server/errors.js.map +1 -1
- package/dist/server/http.d.ts +59 -0
- package/dist/server/http.d.ts.map +1 -0
- package/dist/server/http.js +288 -0
- package/dist/server/http.js.map +1 -0
- package/dist/server/identity.d.ts +1 -0
- package/dist/server/identity.js +13 -0
- package/dist/server/identity.js.map +1 -0
- package/dist/server/index.d.ts +4 -182
- package/dist/server/index.js +4 -376
- package/dist/server/keys.d.ts +1 -0
- package/dist/{component/server/implementation → server}/keys.js +9 -31
- package/dist/server/keys.js.map +1 -0
- package/dist/server/limits.d.ts +1 -0
- package/dist/server/limits.js +61 -0
- package/dist/server/limits.js.map +1 -0
- package/dist/server/mounts.d.ts +647 -0
- package/dist/server/mounts.d.ts.map +1 -0
- package/dist/server/mounts.js +643 -0
- package/dist/server/mounts.js.map +1 -0
- package/dist/server/mutations/account.d.ts +30 -0
- package/dist/server/mutations/account.d.ts.map +1 -0
- package/dist/server/mutations/account.js +44 -0
- package/dist/server/mutations/account.js.map +1 -0
- package/dist/server/mutations/code.d.ts +30 -0
- package/dist/server/mutations/code.d.ts.map +1 -0
- package/dist/server/{implementation/mutations → mutations}/code.js +7 -4
- package/dist/server/mutations/code.js.map +1 -0
- package/dist/server/mutations/index.d.ts +14 -0
- package/dist/server/mutations/index.js +15 -0
- package/dist/server/mutations/invalidate.d.ts +20 -0
- package/dist/server/mutations/invalidate.d.ts.map +1 -0
- package/dist/server/mutations/invalidate.js +32 -0
- package/dist/server/mutations/invalidate.js.map +1 -0
- package/dist/server/mutations/oauth.d.ts +28 -0
- package/dist/server/mutations/oauth.d.ts.map +1 -0
- package/dist/server/mutations/oauth.js +110 -0
- package/dist/server/mutations/oauth.js.map +1 -0
- package/dist/server/mutations/refresh.d.ts +21 -0
- package/dist/server/mutations/refresh.d.ts.map +1 -0
- package/dist/server/mutations/refresh.js +119 -0
- package/dist/server/mutations/refresh.js.map +1 -0
- package/dist/server/mutations/register.d.ts +38 -0
- package/dist/server/mutations/register.d.ts.map +1 -0
- package/dist/server/mutations/register.js +83 -0
- package/dist/server/mutations/register.js.map +1 -0
- package/dist/server/mutations/retrieve.d.ts +33 -0
- package/dist/server/mutations/retrieve.d.ts.map +1 -0
- package/dist/server/mutations/retrieve.js +65 -0
- package/dist/server/mutations/retrieve.js.map +1 -0
- package/dist/server/mutations/signature.d.ts +22 -0
- package/dist/server/mutations/signature.d.ts.map +1 -0
- package/dist/server/mutations/signature.js +32 -0
- package/dist/server/mutations/signature.js.map +1 -0
- package/dist/server/mutations/signin.d.ts +22 -0
- package/dist/server/mutations/signin.d.ts.map +1 -0
- package/dist/server/{implementation/mutations → mutations}/signin.js +2 -2
- package/dist/server/mutations/signin.js.map +1 -0
- package/dist/server/mutations/signout.d.ts +16 -0
- package/dist/server/mutations/signout.d.ts.map +1 -0
- package/dist/server/mutations/signout.js +27 -0
- package/dist/server/mutations/signout.js.map +1 -0
- package/dist/server/mutations/store/refs.d.ts +12 -0
- package/dist/server/mutations/store/refs.d.ts.map +1 -0
- package/dist/server/mutations/store/refs.js +15 -0
- package/dist/server/mutations/store/refs.js.map +1 -0
- package/dist/server/mutations/store.d.ts +306 -0
- package/dist/server/mutations/store.d.ts.map +1 -0
- package/dist/server/mutations/store.js +85 -0
- package/dist/server/mutations/store.js.map +1 -0
- package/dist/server/mutations/verifier.d.ts +13 -0
- package/dist/server/mutations/verifier.d.ts.map +1 -0
- package/dist/server/mutations/verifier.js +18 -0
- package/dist/server/mutations/verifier.js.map +1 -0
- package/dist/server/mutations/verify.d.ts +26 -0
- package/dist/server/mutations/verify.d.ts.map +1 -0
- package/dist/server/mutations/verify.js +98 -0
- package/dist/server/mutations/verify.js.map +1 -0
- package/dist/server/oauth.d.ts +1 -48
- package/dist/server/oauth.js +107 -64
- package/dist/server/oauth.js.map +1 -1
- package/dist/server/passkey.d.ts +27 -0
- package/dist/server/passkey.d.ts.map +1 -0
- package/dist/server/passkey.js +328 -0
- package/dist/server/passkey.js.map +1 -0
- package/dist/server/redirects.d.ts +1 -0
- package/dist/{component/server/implementation → server}/redirects.js +13 -11
- package/dist/server/redirects.js.map +1 -0
- package/dist/server/refresh.d.ts +1 -0
- package/dist/server/refresh.js +96 -0
- package/dist/server/refresh.js.map +1 -0
- package/dist/server/runtime.d.ts +136 -0
- package/dist/server/runtime.d.ts.map +1 -0
- package/dist/server/runtime.js +413 -0
- package/dist/server/runtime.js.map +1 -0
- package/dist/server/sessions.d.ts +1 -0
- package/dist/{component/server/implementation → server}/sessions.js +14 -8
- package/dist/server/sessions.js.map +1 -0
- package/dist/server/signin.d.ts +1 -0
- package/dist/server/signin.js +201 -0
- package/dist/server/signin.js.map +1 -0
- package/dist/server/ssr.d.ts +226 -0
- package/dist/server/ssr.d.ts.map +1 -0
- package/dist/server/ssr.js +786 -0
- package/dist/server/ssr.js.map +1 -0
- package/dist/server/templates.d.ts +1 -21
- package/dist/server/templates.js +2 -1
- package/dist/server/templates.js.map +1 -1
- package/dist/server/tokens.d.ts +1 -0
- package/dist/server/tokens.js +17 -0
- package/dist/server/tokens.js.map +1 -0
- package/dist/server/totp.d.ts +1 -0
- package/dist/server/totp.js +148 -0
- package/dist/server/totp.js.map +1 -0
- package/dist/server/types.d.ts +498 -306
- package/dist/server/types.d.ts.map +1 -1
- package/dist/server/types.js +108 -1
- package/dist/server/types.js.map +1 -0
- package/dist/server/users.d.ts +1 -0
- package/dist/server/{implementation/users.js → users.js} +54 -35
- package/dist/server/users.js.map +1 -0
- package/dist/server/utils.d.ts +1 -6
- package/dist/server/utils.js +110 -4
- package/dist/server/utils.js.map +1 -1
- package/package.json +49 -46
- package/src/authorization/index.ts +83 -0
- package/src/cli/bin.ts +5 -0
- package/src/cli/command.ts +6 -5
- package/src/cli/index.ts +456 -248
- package/src/cli/keys.ts +3 -0
- package/src/client/core/types.ts +437 -0
- package/src/client/factors/device.ts +160 -0
- package/src/client/factors/passkey.ts +282 -0
- package/src/client/factors/totp.ts +150 -0
- package/src/client/index.ts +745 -989
- package/src/client/runtime/browser.ts +112 -0
- package/src/client/runtime/invite.ts +65 -0
- package/src/client/runtime/proxy.ts +111 -0
- package/src/client/runtime/storage.ts +79 -0
- package/src/component/_generated/api.ts +42 -0
- package/src/component/_generated/component.ts +3123 -102
- package/src/component/functions.ts +38 -22
- package/src/component/index.ts +10 -20
- package/src/component/model.ts +449 -0
- package/src/component/public/enterprise/audit.ts +120 -0
- package/src/component/public/enterprise/core.ts +354 -0
- package/src/component/public/enterprise/domains.ts +323 -0
- package/src/component/public/enterprise/scim.ts +396 -0
- package/src/component/public/enterprise/secrets.ts +132 -0
- package/src/component/public/enterprise/webhooks.ts +306 -0
- package/src/component/public/factors/devices.ts +223 -0
- package/src/component/public/factors/passkeys.ts +242 -0
- package/src/component/public/factors/totp.ts +258 -0
- package/src/component/public/groups/core.ts +481 -0
- package/src/component/public/groups/invites.ts +602 -0
- package/src/component/public/groups/members.ts +409 -0
- package/src/component/public/identity/accounts.ts +206 -0
- package/src/component/public/identity/codes.ts +148 -0
- package/src/component/public/identity/sessions.ts +209 -0
- package/src/component/public/identity/tokens.ts +250 -0
- package/src/component/public/identity/users.ts +354 -0
- package/src/component/public/identity/verifiers.ts +157 -0
- package/src/component/public/security/keys.ts +365 -0
- package/src/component/public/security/limits.ts +173 -0
- package/src/component/public.ts +26 -1766
- package/src/component/schema.ts +273 -100
- package/src/providers/anonymous.ts +10 -20
- package/src/providers/credentials.ts +14 -22
- package/src/providers/device.ts +3 -14
- package/src/providers/email.ts +83 -47
- package/src/providers/index.ts +7 -0
- package/src/providers/oauth.ts +5 -3
- package/src/providers/passkey.ts +0 -13
- package/src/providers/password.ts +307 -130
- package/src/providers/phone.ts +81 -37
- package/src/providers/sso.ts +54 -0
- package/src/providers/totp.ts +0 -13
- package/src/samlify.d.ts +53 -0
- package/src/server/auth.ts +701 -247
- package/src/server/authError.ts +44 -0
- package/src/server/{providers.ts → config.ts} +84 -15
- package/src/server/cookies.ts +8 -1
- package/src/server/core.ts +2095 -0
- package/src/server/crypto.ts +88 -0
- package/src/server/{implementation/db.ts → db.ts} +90 -15
- package/src/server/device.ts +221 -0
- package/src/server/enterprise/config.ts +51 -0
- package/src/server/enterprise/domain.ts +1751 -0
- package/src/server/enterprise/http.ts +1324 -0
- package/src/server/enterprise/oidc.ts +500 -0
- package/src/server/enterprise/policy.ts +128 -0
- package/src/server/enterprise/saml.ts +578 -0
- package/src/server/enterprise/scim.ts +135 -0
- package/src/server/enterprise/shared.ts +134 -0
- package/src/server/enterprise/validators.ts +93 -0
- package/src/server/errors.ts +130 -119
- package/src/server/http.ts +531 -0
- package/src/server/identity.ts +18 -0
- package/src/server/index.ts +32 -650
- package/src/server/{implementation/keys.ts → keys.ts} +16 -44
- package/src/server/limits.ts +134 -0
- package/src/server/mounts.ts +948 -0
- package/src/server/mutations/account.ts +76 -0
- package/src/server/{implementation/mutations → mutations}/code.ts +22 -11
- package/src/server/mutations/index.ts +13 -0
- package/src/server/mutations/invalidate.ts +50 -0
- package/src/server/mutations/oauth.ts +237 -0
- package/src/server/mutations/refresh.ts +298 -0
- package/src/server/mutations/register.ts +200 -0
- package/src/server/mutations/retrieve.ts +109 -0
- package/src/server/mutations/signature.ts +50 -0
- package/src/server/{implementation/mutations → mutations}/signin.ts +9 -7
- package/src/server/mutations/signout.ts +43 -0
- package/src/server/mutations/store/refs.ts +10 -0
- package/src/server/mutations/store.ts +138 -0
- package/src/server/mutations/verifier.ts +34 -0
- package/src/server/mutations/verify.ts +202 -0
- package/src/server/oauth.ts +243 -131
- package/src/server/passkey.ts +784 -0
- package/src/server/{implementation/redirects.ts → redirects.ts} +21 -16
- package/src/server/refresh.ts +222 -0
- package/src/server/runtime.ts +880 -0
- package/src/server/{implementation/sessions.ts → sessions.ts} +33 -25
- package/src/server/signin.ts +438 -0
- package/src/server/ssr.ts +1764 -0
- package/src/server/templates.ts +8 -3
- package/src/server/{implementation/tokens.ts → tokens.ts} +11 -5
- package/src/server/totp.ts +349 -0
- package/src/server/types.ts +972 -207
- package/src/server/{implementation/users.ts → users.ts} +129 -75
- package/src/server/utils.ts +192 -5
- package/src/test.ts +28 -4
- package/dist/bin.cjs +0 -27757
- package/dist/component/providers/email.js +0 -47
- package/dist/component/providers/email.js.map +0 -1
- package/dist/component/public.js.map +0 -1
- package/dist/component/server/implementation/db.js.map +0 -1
- package/dist/component/server/implementation/device.js +0 -135
- package/dist/component/server/implementation/device.js.map +0 -1
- package/dist/component/server/implementation/index.d.ts +0 -870
- package/dist/component/server/implementation/index.d.ts.map +0 -1
- package/dist/component/server/implementation/index.js +0 -610
- package/dist/component/server/implementation/index.js.map +0 -1
- package/dist/component/server/implementation/keys.js.map +0 -1
- package/dist/component/server/implementation/mutations/account.js +0 -39
- package/dist/component/server/implementation/mutations/account.js.map +0 -1
- package/dist/component/server/implementation/mutations/code.js.map +0 -1
- package/dist/component/server/implementation/mutations/index.js +0 -70
- package/dist/component/server/implementation/mutations/index.js.map +0 -1
- package/dist/component/server/implementation/mutations/invalidate.js +0 -29
- package/dist/component/server/implementation/mutations/invalidate.js.map +0 -1
- package/dist/component/server/implementation/mutations/oauth.js +0 -51
- package/dist/component/server/implementation/mutations/oauth.js.map +0 -1
- package/dist/component/server/implementation/mutations/refresh.js +0 -85
- package/dist/component/server/implementation/mutations/refresh.js.map +0 -1
- package/dist/component/server/implementation/mutations/register.js +0 -65
- package/dist/component/server/implementation/mutations/register.js.map +0 -1
- package/dist/component/server/implementation/mutations/retrieve.js +0 -50
- package/dist/component/server/implementation/mutations/retrieve.js.map +0 -1
- package/dist/component/server/implementation/mutations/signature.js +0 -27
- package/dist/component/server/implementation/mutations/signature.js.map +0 -1
- package/dist/component/server/implementation/mutations/signin.js.map +0 -1
- package/dist/component/server/implementation/mutations/signout.js +0 -27
- package/dist/component/server/implementation/mutations/signout.js.map +0 -1
- package/dist/component/server/implementation/mutations/store.js +0 -12
- package/dist/component/server/implementation/mutations/store.js.map +0 -1
- package/dist/component/server/implementation/mutations/verifier.js +0 -16
- package/dist/component/server/implementation/mutations/verifier.js.map +0 -1
- package/dist/component/server/implementation/mutations/verify.js +0 -105
- package/dist/component/server/implementation/mutations/verify.js.map +0 -1
- package/dist/component/server/implementation/passkey.js +0 -307
- package/dist/component/server/implementation/passkey.js.map +0 -1
- package/dist/component/server/implementation/provider.js +0 -19
- package/dist/component/server/implementation/provider.js.map +0 -1
- package/dist/component/server/implementation/ratelimit.js +0 -48
- package/dist/component/server/implementation/ratelimit.js.map +0 -1
- package/dist/component/server/implementation/redirects.js.map +0 -1
- package/dist/component/server/implementation/refresh.js +0 -109
- package/dist/component/server/implementation/refresh.js.map +0 -1
- package/dist/component/server/implementation/sessions.js.map +0 -1
- package/dist/component/server/implementation/signin.js +0 -148
- package/dist/component/server/implementation/signin.js.map +0 -1
- package/dist/component/server/implementation/tokens.js +0 -15
- package/dist/component/server/implementation/tokens.js.map +0 -1
- package/dist/component/server/implementation/totp.js +0 -142
- package/dist/component/server/implementation/totp.js.map +0 -1
- package/dist/component/server/implementation/types.d.ts +0 -42
- package/dist/component/server/implementation/types.d.ts.map +0 -1
- package/dist/component/server/implementation/types.js.map +0 -1
- package/dist/component/server/implementation/users.js.map +0 -1
- package/dist/component/server/implementation/utils.js +0 -56
- package/dist/component/server/implementation/utils.js.map +0 -1
- package/dist/component/server/providers.js.map +0 -1
- package/dist/component/server/templates.js +0 -84
- package/dist/component/server/templates.js.map +0 -1
- package/dist/server/cookies.d.ts.map +0 -1
- package/dist/server/implementation/db.d.ts +0 -86
- package/dist/server/implementation/db.d.ts.map +0 -1
- package/dist/server/implementation/db.js.map +0 -1
- package/dist/server/implementation/device.d.ts +0 -30
- package/dist/server/implementation/device.d.ts.map +0 -1
- package/dist/server/implementation/device.js +0 -135
- package/dist/server/implementation/device.js.map +0 -1
- package/dist/server/implementation/index.d.ts +0 -870
- package/dist/server/implementation/index.d.ts.map +0 -1
- package/dist/server/implementation/index.js +0 -610
- package/dist/server/implementation/index.js.map +0 -1
- package/dist/server/implementation/keys.d.ts +0 -66
- package/dist/server/implementation/keys.d.ts.map +0 -1
- package/dist/server/implementation/keys.js.map +0 -1
- package/dist/server/implementation/mutations/account.d.ts +0 -27
- package/dist/server/implementation/mutations/account.d.ts.map +0 -1
- package/dist/server/implementation/mutations/account.js +0 -39
- package/dist/server/implementation/mutations/account.js.map +0 -1
- package/dist/server/implementation/mutations/code.d.ts +0 -29
- package/dist/server/implementation/mutations/code.d.ts.map +0 -1
- package/dist/server/implementation/mutations/code.js.map +0 -1
- package/dist/server/implementation/mutations/index.d.ts +0 -310
- package/dist/server/implementation/mutations/index.d.ts.map +0 -1
- package/dist/server/implementation/mutations/index.js +0 -70
- package/dist/server/implementation/mutations/index.js.map +0 -1
- package/dist/server/implementation/mutations/invalidate.d.ts +0 -18
- package/dist/server/implementation/mutations/invalidate.d.ts.map +0 -1
- package/dist/server/implementation/mutations/invalidate.js +0 -29
- package/dist/server/implementation/mutations/invalidate.js.map +0 -1
- package/dist/server/implementation/mutations/oauth.d.ts +0 -23
- package/dist/server/implementation/mutations/oauth.d.ts.map +0 -1
- package/dist/server/implementation/mutations/oauth.js +0 -51
- package/dist/server/implementation/mutations/oauth.js.map +0 -1
- package/dist/server/implementation/mutations/refresh.d.ts +0 -20
- package/dist/server/implementation/mutations/refresh.d.ts.map +0 -1
- package/dist/server/implementation/mutations/refresh.js +0 -85
- package/dist/server/implementation/mutations/refresh.js.map +0 -1
- package/dist/server/implementation/mutations/register.d.ts +0 -37
- package/dist/server/implementation/mutations/register.d.ts.map +0 -1
- package/dist/server/implementation/mutations/register.js +0 -65
- package/dist/server/implementation/mutations/register.js.map +0 -1
- package/dist/server/implementation/mutations/retrieve.d.ts +0 -31
- package/dist/server/implementation/mutations/retrieve.d.ts.map +0 -1
- package/dist/server/implementation/mutations/retrieve.js +0 -50
- package/dist/server/implementation/mutations/retrieve.js.map +0 -1
- package/dist/server/implementation/mutations/signature.d.ts +0 -19
- package/dist/server/implementation/mutations/signature.d.ts.map +0 -1
- package/dist/server/implementation/mutations/signature.js +0 -27
- package/dist/server/implementation/mutations/signature.js.map +0 -1
- package/dist/server/implementation/mutations/signin.d.ts +0 -21
- package/dist/server/implementation/mutations/signin.d.ts.map +0 -1
- package/dist/server/implementation/mutations/signin.js.map +0 -1
- package/dist/server/implementation/mutations/signout.d.ts +0 -14
- package/dist/server/implementation/mutations/signout.d.ts.map +0 -1
- package/dist/server/implementation/mutations/signout.js +0 -27
- package/dist/server/implementation/mutations/signout.js.map +0 -1
- package/dist/server/implementation/mutations/store.d.ts +0 -11
- package/dist/server/implementation/mutations/store.d.ts.map +0 -1
- package/dist/server/implementation/mutations/store.js +0 -12
- package/dist/server/implementation/mutations/store.js.map +0 -1
- package/dist/server/implementation/mutations/verifier.d.ts +0 -11
- package/dist/server/implementation/mutations/verifier.d.ts.map +0 -1
- package/dist/server/implementation/mutations/verifier.js +0 -16
- package/dist/server/implementation/mutations/verifier.js.map +0 -1
- package/dist/server/implementation/mutations/verify.d.ts +0 -25
- package/dist/server/implementation/mutations/verify.d.ts.map +0 -1
- package/dist/server/implementation/mutations/verify.js +0 -105
- package/dist/server/implementation/mutations/verify.js.map +0 -1
- package/dist/server/implementation/passkey.d.ts +0 -24
- package/dist/server/implementation/passkey.d.ts.map +0 -1
- package/dist/server/implementation/passkey.js +0 -307
- package/dist/server/implementation/passkey.js.map +0 -1
- package/dist/server/implementation/provider.d.ts +0 -10
- package/dist/server/implementation/provider.d.ts.map +0 -1
- package/dist/server/implementation/provider.js +0 -19
- package/dist/server/implementation/provider.js.map +0 -1
- package/dist/server/implementation/ratelimit.d.ts +0 -10
- package/dist/server/implementation/ratelimit.d.ts.map +0 -1
- package/dist/server/implementation/ratelimit.js +0 -48
- package/dist/server/implementation/ratelimit.js.map +0 -1
- package/dist/server/implementation/redirects.d.ts +0 -10
- package/dist/server/implementation/redirects.d.ts.map +0 -1
- package/dist/server/implementation/redirects.js.map +0 -1
- package/dist/server/implementation/refresh.d.ts +0 -37
- package/dist/server/implementation/refresh.d.ts.map +0 -1
- package/dist/server/implementation/refresh.js +0 -109
- package/dist/server/implementation/refresh.js.map +0 -1
- package/dist/server/implementation/sessions.d.ts +0 -29
- package/dist/server/implementation/sessions.d.ts.map +0 -1
- package/dist/server/implementation/sessions.js.map +0 -1
- package/dist/server/implementation/signin.d.ts +0 -55
- package/dist/server/implementation/signin.d.ts.map +0 -1
- package/dist/server/implementation/signin.js +0 -148
- package/dist/server/implementation/signin.js.map +0 -1
- package/dist/server/implementation/tokens.d.ts +0 -11
- package/dist/server/implementation/tokens.d.ts.map +0 -1
- package/dist/server/implementation/tokens.js +0 -15
- package/dist/server/implementation/tokens.js.map +0 -1
- package/dist/server/implementation/totp.d.ts +0 -31
- package/dist/server/implementation/totp.d.ts.map +0 -1
- package/dist/server/implementation/totp.js +0 -142
- package/dist/server/implementation/totp.js.map +0 -1
- package/dist/server/implementation/types.d.ts +0 -189
- package/dist/server/implementation/types.d.ts.map +0 -1
- package/dist/server/implementation/types.js +0 -97
- package/dist/server/implementation/types.js.map +0 -1
- package/dist/server/implementation/users.d.ts +0 -30
- package/dist/server/implementation/users.d.ts.map +0 -1
- package/dist/server/implementation/users.js.map +0 -1
- package/dist/server/implementation/utils.d.ts +0 -19
- package/dist/server/implementation/utils.d.ts.map +0 -1
- package/dist/server/implementation/utils.js +0 -56
- package/dist/server/implementation/utils.js.map +0 -1
- package/dist/server/index.d.ts.map +0 -1
- package/dist/server/index.js.map +0 -1
- package/dist/server/oauth.d.ts.map +0 -1
- package/dist/server/providers.d.ts +0 -72
- package/dist/server/providers.d.ts.map +0 -1
- package/dist/server/providers.js.map +0 -1
- package/dist/server/templates.d.ts.map +0 -1
- package/dist/server/utils.d.ts.map +0 -1
- package/dist/server/version.d.ts +0 -5
- package/dist/server/version.d.ts.map +0 -1
- package/dist/server/version.js +0 -6
- package/dist/server/version.js.map +0 -1
- package/src/cli/utils.ts +0 -248
- package/src/server/implementation/device.ts +0 -307
- package/src/server/implementation/index.ts +0 -1583
- package/src/server/implementation/mutations/account.ts +0 -50
- package/src/server/implementation/mutations/index.ts +0 -157
- package/src/server/implementation/mutations/invalidate.ts +0 -42
- package/src/server/implementation/mutations/oauth.ts +0 -73
- package/src/server/implementation/mutations/refresh.ts +0 -175
- package/src/server/implementation/mutations/register.ts +0 -100
- package/src/server/implementation/mutations/retrieve.ts +0 -79
- package/src/server/implementation/mutations/signature.ts +0 -39
- package/src/server/implementation/mutations/signout.ts +0 -35
- package/src/server/implementation/mutations/store.ts +0 -7
- package/src/server/implementation/mutations/verifier.ts +0 -24
- package/src/server/implementation/mutations/verify.ts +0 -194
- package/src/server/implementation/passkey.ts +0 -620
- package/src/server/implementation/provider.ts +0 -36
- package/src/server/implementation/ratelimit.ts +0 -79
- package/src/server/implementation/refresh.ts +0 -172
- package/src/server/implementation/signin.ts +0 -296
- package/src/server/implementation/totp.ts +0 -342
- package/src/server/implementation/types.ts +0 -444
- package/src/server/implementation/utils.ts +0 -91
- package/src/server/version.ts +0 -2
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
declare namespace keys_d_exports {
|
|
2
|
+
export { keyDelete, keyGetByHashedKey, keyGetById, keyInsert, keyList, keyPatch };
|
|
3
|
+
}
|
|
4
|
+
/**
|
|
5
|
+
* Insert a new API key record into the `ApiKey` table.
|
|
6
|
+
*
|
|
7
|
+
* Creates an API key entry with the given metadata and scopes. The caller
|
|
8
|
+
* is responsible for generating and hashing the raw key before passing it
|
|
9
|
+
* here -- this function only stores the hash, never the plaintext key.
|
|
10
|
+
* The `createdAt` timestamp and `revoked: false` flag are set automatically.
|
|
11
|
+
*
|
|
12
|
+
* @param userId - The `_id` of the `User` who owns this API key.
|
|
13
|
+
* @param prefix - A short, visible prefix for the key (e.g. `"sk_live_"`)
|
|
14
|
+
* that helps users identify which key was used without exposing the secret.
|
|
15
|
+
* @param hashedKey - SHA-256 hash of the full API key string. Used for
|
|
16
|
+
* constant-time lookup during Bearer token verification.
|
|
17
|
+
* @param name - Human-readable name for the key (e.g. `"Production Backend"`).
|
|
18
|
+
* @param scopes - Array of permission scopes, each containing a `resource`
|
|
19
|
+
* name and an array of allowed `actions` (e.g.
|
|
20
|
+
* `[{ resource: "messages", actions: ["read", "write"] }]`).
|
|
21
|
+
* @param rateLimit - Optional rate limit configuration to apply per-key
|
|
22
|
+
* (e.g. max requests per window).
|
|
23
|
+
* @param expiresAt - Optional Unix timestamp (in milliseconds) after which
|
|
24
|
+
* the key is no longer valid. Omit for non-expiring keys.
|
|
25
|
+
* @param metadata - Optional arbitrary metadata to attach to the key record.
|
|
26
|
+
* @returns The `_id` of the newly created `ApiKey` document.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* const keyId = await ctx.runMutation(
|
|
31
|
+
* components.auth.security.keys.keyInsert,
|
|
32
|
+
* {
|
|
33
|
+
* userId: user._id,
|
|
34
|
+
* prefix: "sk_live_",
|
|
35
|
+
* hashedKey: await sha256(rawKey),
|
|
36
|
+
* name: "Production Backend",
|
|
37
|
+
* scopes: [{ resource: "messages", actions: ["read", "write"] }],
|
|
38
|
+
* expiresAt: Date.now() + 90 * 24 * 60 * 60 * 1000,
|
|
39
|
+
* },
|
|
40
|
+
* );
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
declare const keyInsert: any;
|
|
44
|
+
/**
|
|
45
|
+
* Look up an API key by its SHA-256 hash.
|
|
46
|
+
*
|
|
47
|
+
* Queries the `ApiKey` table using the `hashed_key` index. This is the
|
|
48
|
+
* primary lookup path during Bearer token verification: the incoming
|
|
49
|
+
* token is hashed and matched against stored hashes in constant time.
|
|
50
|
+
* Returns the full key record including scopes, rate limit state, and
|
|
51
|
+
* revocation status so the caller can perform authorization checks.
|
|
52
|
+
*
|
|
53
|
+
* @param hashedKey - SHA-256 hash of the API key string extracted from
|
|
54
|
+
* the `Authorization: Bearer <token>` header.
|
|
55
|
+
* @returns The matching `ApiKey` document (including rate limit state),
|
|
56
|
+
* or `null` if no key matches the given hash.
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```ts
|
|
60
|
+
* const apiKey = await ctx.runQuery(
|
|
61
|
+
* components.auth.security.keys.keyGetByHashedKey,
|
|
62
|
+
* { hashedKey: await sha256(bearerToken) },
|
|
63
|
+
* );
|
|
64
|
+
* if (apiKey === null || apiKey.revoked) {
|
|
65
|
+
* throw new Error("Invalid or revoked API key");
|
|
66
|
+
* }
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
declare const keyGetByHashedKey: any;
|
|
70
|
+
/**
|
|
71
|
+
* List API keys with optional filtering, sorting, and cursor-based pagination.
|
|
72
|
+
*
|
|
73
|
+
* Returns a paginated result `{ items, nextCursor }` from the `ApiKey`
|
|
74
|
+
* table. Supports filtering by `userId`, `revoked` status, `name`, and
|
|
75
|
+
* `prefix`. The page size is clamped between 1 and 100 (default 50).
|
|
76
|
+
* Pass the returned `nextCursor` as `cursor` in a subsequent call to
|
|
77
|
+
* fetch the next page.
|
|
78
|
+
*
|
|
79
|
+
* @param where - Optional filter object. All specified fields are
|
|
80
|
+
* combined with AND logic:
|
|
81
|
+
* - `userId` -- restrict to keys owned by this user.
|
|
82
|
+
* - `revoked` -- `true` for revoked keys, `false` for active keys.
|
|
83
|
+
* - `name` -- exact match on the key's human-readable name.
|
|
84
|
+
* - `prefix` -- exact match on the key prefix string.
|
|
85
|
+
* @param limit - Maximum number of items to return per page (1--100,
|
|
86
|
+
* default `50`).
|
|
87
|
+
* @param cursor - Opaque cursor string (an `ApiKey` document `_id`)
|
|
88
|
+
* returned from a previous call. Pass `null` or omit for the first page.
|
|
89
|
+
* @param orderBy - Field to sort by. One of `"_creationTime"`, `"name"`,
|
|
90
|
+
* `"lastUsedAt"`, `"expiresAt"`, or `"revoked"`. Defaults to
|
|
91
|
+
* `"_creationTime"`.
|
|
92
|
+
* @param order - Sort direction, `"asc"` or `"desc"` (default `"desc"`).
|
|
93
|
+
* @returns An object with `items` (array of `ApiKey` documents) and
|
|
94
|
+
* `nextCursor` (string ID of the last item, or `null` if no more pages).
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* ```ts
|
|
98
|
+
* // Fetch the first page of active keys for a user
|
|
99
|
+
* const page = await ctx.runQuery(
|
|
100
|
+
* components.auth.security.keys.keyList,
|
|
101
|
+
* {
|
|
102
|
+
* where: { userId: user._id, revoked: false },
|
|
103
|
+
* limit: 20,
|
|
104
|
+
* order: "desc",
|
|
105
|
+
* },
|
|
106
|
+
* );
|
|
107
|
+
* // Fetch the next page
|
|
108
|
+
* if (page.nextCursor) {
|
|
109
|
+
* const page2 = await ctx.runQuery(
|
|
110
|
+
* components.auth.security.keys.keyList,
|
|
111
|
+
* { where: { userId: user._id, revoked: false }, cursor: page.nextCursor },
|
|
112
|
+
* );
|
|
113
|
+
* }
|
|
114
|
+
* ```
|
|
115
|
+
*/
|
|
116
|
+
declare const keyList: any;
|
|
117
|
+
/**
|
|
118
|
+
* Get a single API key by its document ID.
|
|
119
|
+
*
|
|
120
|
+
* Performs a direct document lookup on the `ApiKey` table. Useful when
|
|
121
|
+
* you already have the key's `_id` (e.g. from a list query or a stored
|
|
122
|
+
* reference) and need to retrieve its full details.
|
|
123
|
+
*
|
|
124
|
+
* @param keyId - The `_id` of the `ApiKey` document to retrieve.
|
|
125
|
+
* @returns The `ApiKey` document, or `null` if no key exists with the
|
|
126
|
+
* given ID.
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* ```ts
|
|
130
|
+
* const apiKey = await ctx.runQuery(
|
|
131
|
+
* components.auth.security.keys.keyGetById,
|
|
132
|
+
* { keyId: storedKeyId },
|
|
133
|
+
* );
|
|
134
|
+
* if (apiKey !== null) {
|
|
135
|
+
* console.log(apiKey.name, apiKey.scopes);
|
|
136
|
+
* }
|
|
137
|
+
* ```
|
|
138
|
+
*/
|
|
139
|
+
declare const keyGetById: any;
|
|
140
|
+
/**
|
|
141
|
+
* Patch an API key record with partial updates.
|
|
142
|
+
*
|
|
143
|
+
* Performs a partial update on the `ApiKey` document. Supports modifying
|
|
144
|
+
* the key's name, scopes, rate limit configuration, rate limit state,
|
|
145
|
+
* revocation flag, and last-used timestamp. Throws a `ConvexError` with
|
|
146
|
+
* code `"KEY_NOT_FOUND"` if the key does not exist.
|
|
147
|
+
*
|
|
148
|
+
* @param keyId - The `_id` of the `ApiKey` document to update.
|
|
149
|
+
* @param data - An object containing the fields to patch. All fields are
|
|
150
|
+
* optional:
|
|
151
|
+
* - `name` -- Updated human-readable name.
|
|
152
|
+
* - `scopes` -- Replacement array of permission scopes.
|
|
153
|
+
* - `rateLimit` -- Updated rate limit configuration.
|
|
154
|
+
* - `rateLimitState` -- Updated rate limit tracking state (token
|
|
155
|
+
* count, last refill time).
|
|
156
|
+
* - `revoked` -- Set to `true` to revoke the key, `false` to
|
|
157
|
+
* reinstate it.
|
|
158
|
+
* - `lastUsedAt` -- Unix timestamp (in milliseconds) of the most
|
|
159
|
+
* recent API call using this key.
|
|
160
|
+
* @returns `null` on success.
|
|
161
|
+
*
|
|
162
|
+
* @example
|
|
163
|
+
* ```ts
|
|
164
|
+
* // Revoke an API key
|
|
165
|
+
* await ctx.runMutation(
|
|
166
|
+
* components.auth.security.keys.keyPatch,
|
|
167
|
+
* {
|
|
168
|
+
* keyId: apiKey._id,
|
|
169
|
+
* data: { revoked: true },
|
|
170
|
+
* },
|
|
171
|
+
* );
|
|
172
|
+
*
|
|
173
|
+
* // Rename and update scopes
|
|
174
|
+
* await ctx.runMutation(
|
|
175
|
+
* components.auth.security.keys.keyPatch,
|
|
176
|
+
* {
|
|
177
|
+
* keyId: apiKey._id,
|
|
178
|
+
* data: {
|
|
179
|
+
* name: "Read-Only Key",
|
|
180
|
+
* scopes: [{ resource: "messages", actions: ["read"] }],
|
|
181
|
+
* },
|
|
182
|
+
* },
|
|
183
|
+
* );
|
|
184
|
+
* ```
|
|
185
|
+
*/
|
|
186
|
+
declare const keyPatch: any;
|
|
187
|
+
/**
|
|
188
|
+
* Hard-delete an API key record from the `ApiKey` table.
|
|
189
|
+
*
|
|
190
|
+
* Permanently removes the API key document. Unlike revocation (which
|
|
191
|
+
* keeps the record for audit purposes), this is an irreversible
|
|
192
|
+
* deletion. Throws a `ConvexError` with code `"KEY_NOT_FOUND"` if the
|
|
193
|
+
* key does not exist.
|
|
194
|
+
*
|
|
195
|
+
* @param keyId - The `_id` of the `ApiKey` document to delete.
|
|
196
|
+
* @returns `null` on success.
|
|
197
|
+
*
|
|
198
|
+
* @example
|
|
199
|
+
* ```ts
|
|
200
|
+
* await ctx.runMutation(
|
|
201
|
+
* components.auth.security.keys.keyDelete,
|
|
202
|
+
* { keyId: apiKey._id },
|
|
203
|
+
* );
|
|
204
|
+
* ```
|
|
205
|
+
*/
|
|
206
|
+
declare const keyDelete: any;
|
|
207
|
+
//#endregion
|
|
208
|
+
export { keyDelete, keyGetByHashedKey, keyGetById, keyInsert, keyList, keyPatch, keys_d_exports };
|
|
209
|
+
//# sourceMappingURL=keys.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keys.d.ts","names":[],"sources":["../../../../src/component/public/security/keys.ts"],"mappings":";;;;;;;;;;;;;;AAqDA;;;;;AAmDA;;;;;AAyDA;;;;;AAwFA;;;;;AAsDA;;;;;AA8CA;;;cAxSa,SAAA;;;;;;;;;;;;;;;;;;;;;;;;;;cAmDA,iBAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAyDA,OAAA;;;;;;;;;;;;;;;;;;;;;;;cAwFA,UAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAsDA,QAAA;;;;;;;;;;;;;;;;;;;;cA8CA,SAAA"}
|
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
import { mutation, query } from "../../functions.js";
|
|
2
|
+
import { vApiKeyDoc, vApiKeyRateLimit, vApiKeyRateLimitState, vApiKeyScope, vPaginated } from "../../model.js";
|
|
3
|
+
import { ConvexError, v } from "convex/values";
|
|
4
|
+
|
|
5
|
+
//#region src/component/public/security/keys.ts
|
|
6
|
+
/**
|
|
7
|
+
* Insert a new API key record into the `ApiKey` table.
|
|
8
|
+
*
|
|
9
|
+
* Creates an API key entry with the given metadata and scopes. The caller
|
|
10
|
+
* is responsible for generating and hashing the raw key before passing it
|
|
11
|
+
* here -- this function only stores the hash, never the plaintext key.
|
|
12
|
+
* The `createdAt` timestamp and `revoked: false` flag are set automatically.
|
|
13
|
+
*
|
|
14
|
+
* @param userId - The `_id` of the `User` who owns this API key.
|
|
15
|
+
* @param prefix - A short, visible prefix for the key (e.g. `"sk_live_"`)
|
|
16
|
+
* that helps users identify which key was used without exposing the secret.
|
|
17
|
+
* @param hashedKey - SHA-256 hash of the full API key string. Used for
|
|
18
|
+
* constant-time lookup during Bearer token verification.
|
|
19
|
+
* @param name - Human-readable name for the key (e.g. `"Production Backend"`).
|
|
20
|
+
* @param scopes - Array of permission scopes, each containing a `resource`
|
|
21
|
+
* name and an array of allowed `actions` (e.g.
|
|
22
|
+
* `[{ resource: "messages", actions: ["read", "write"] }]`).
|
|
23
|
+
* @param rateLimit - Optional rate limit configuration to apply per-key
|
|
24
|
+
* (e.g. max requests per window).
|
|
25
|
+
* @param expiresAt - Optional Unix timestamp (in milliseconds) after which
|
|
26
|
+
* the key is no longer valid. Omit for non-expiring keys.
|
|
27
|
+
* @param metadata - Optional arbitrary metadata to attach to the key record.
|
|
28
|
+
* @returns The `_id` of the newly created `ApiKey` document.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* const keyId = await ctx.runMutation(
|
|
33
|
+
* components.auth.security.keys.keyInsert,
|
|
34
|
+
* {
|
|
35
|
+
* userId: user._id,
|
|
36
|
+
* prefix: "sk_live_",
|
|
37
|
+
* hashedKey: await sha256(rawKey),
|
|
38
|
+
* name: "Production Backend",
|
|
39
|
+
* scopes: [{ resource: "messages", actions: ["read", "write"] }],
|
|
40
|
+
* expiresAt: Date.now() + 90 * 24 * 60 * 60 * 1000,
|
|
41
|
+
* },
|
|
42
|
+
* );
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
const keyInsert = mutation({
|
|
46
|
+
args: {
|
|
47
|
+
userId: v.id("User"),
|
|
48
|
+
prefix: v.string(),
|
|
49
|
+
hashedKey: v.string(),
|
|
50
|
+
name: v.string(),
|
|
51
|
+
scopes: v.array(v.object({
|
|
52
|
+
resource: v.string(),
|
|
53
|
+
actions: v.array(v.string())
|
|
54
|
+
})),
|
|
55
|
+
rateLimit: v.optional(vApiKeyRateLimit),
|
|
56
|
+
expiresAt: v.optional(v.number()),
|
|
57
|
+
metadata: v.optional(v.any())
|
|
58
|
+
},
|
|
59
|
+
returns: v.id("ApiKey"),
|
|
60
|
+
handler: async (ctx, args) => {
|
|
61
|
+
return await ctx.db.insert("ApiKey", {
|
|
62
|
+
...args,
|
|
63
|
+
createdAt: Date.now(),
|
|
64
|
+
revoked: false
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
/**
|
|
69
|
+
* Look up an API key by its SHA-256 hash.
|
|
70
|
+
*
|
|
71
|
+
* Queries the `ApiKey` table using the `hashed_key` index. This is the
|
|
72
|
+
* primary lookup path during Bearer token verification: the incoming
|
|
73
|
+
* token is hashed and matched against stored hashes in constant time.
|
|
74
|
+
* Returns the full key record including scopes, rate limit state, and
|
|
75
|
+
* revocation status so the caller can perform authorization checks.
|
|
76
|
+
*
|
|
77
|
+
* @param hashedKey - SHA-256 hash of the API key string extracted from
|
|
78
|
+
* the `Authorization: Bearer <token>` header.
|
|
79
|
+
* @returns The matching `ApiKey` document (including rate limit state),
|
|
80
|
+
* or `null` if no key matches the given hash.
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```ts
|
|
84
|
+
* const apiKey = await ctx.runQuery(
|
|
85
|
+
* components.auth.security.keys.keyGetByHashedKey,
|
|
86
|
+
* { hashedKey: await sha256(bearerToken) },
|
|
87
|
+
* );
|
|
88
|
+
* if (apiKey === null || apiKey.revoked) {
|
|
89
|
+
* throw new Error("Invalid or revoked API key");
|
|
90
|
+
* }
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
const keyGetByHashedKey = query({
|
|
94
|
+
args: { hashedKey: v.string() },
|
|
95
|
+
returns: v.union(vApiKeyDoc, v.null()),
|
|
96
|
+
handler: async (ctx, { hashedKey }) => {
|
|
97
|
+
return await ctx.db.query("ApiKey").withIndex("hashed_key", (q) => q.eq("hashedKey", hashedKey)).first();
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
/**
|
|
101
|
+
* List API keys with optional filtering, sorting, and cursor-based pagination.
|
|
102
|
+
*
|
|
103
|
+
* Returns a paginated result `{ items, nextCursor }` from the `ApiKey`
|
|
104
|
+
* table. Supports filtering by `userId`, `revoked` status, `name`, and
|
|
105
|
+
* `prefix`. The page size is clamped between 1 and 100 (default 50).
|
|
106
|
+
* Pass the returned `nextCursor` as `cursor` in a subsequent call to
|
|
107
|
+
* fetch the next page.
|
|
108
|
+
*
|
|
109
|
+
* @param where - Optional filter object. All specified fields are
|
|
110
|
+
* combined with AND logic:
|
|
111
|
+
* - `userId` -- restrict to keys owned by this user.
|
|
112
|
+
* - `revoked` -- `true` for revoked keys, `false` for active keys.
|
|
113
|
+
* - `name` -- exact match on the key's human-readable name.
|
|
114
|
+
* - `prefix` -- exact match on the key prefix string.
|
|
115
|
+
* @param limit - Maximum number of items to return per page (1--100,
|
|
116
|
+
* default `50`).
|
|
117
|
+
* @param cursor - Opaque cursor string (an `ApiKey` document `_id`)
|
|
118
|
+
* returned from a previous call. Pass `null` or omit for the first page.
|
|
119
|
+
* @param orderBy - Field to sort by. One of `"_creationTime"`, `"name"`,
|
|
120
|
+
* `"lastUsedAt"`, `"expiresAt"`, or `"revoked"`. Defaults to
|
|
121
|
+
* `"_creationTime"`.
|
|
122
|
+
* @param order - Sort direction, `"asc"` or `"desc"` (default `"desc"`).
|
|
123
|
+
* @returns An object with `items` (array of `ApiKey` documents) and
|
|
124
|
+
* `nextCursor` (string ID of the last item, or `null` if no more pages).
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* ```ts
|
|
128
|
+
* // Fetch the first page of active keys for a user
|
|
129
|
+
* const page = await ctx.runQuery(
|
|
130
|
+
* components.auth.security.keys.keyList,
|
|
131
|
+
* {
|
|
132
|
+
* where: { userId: user._id, revoked: false },
|
|
133
|
+
* limit: 20,
|
|
134
|
+
* order: "desc",
|
|
135
|
+
* },
|
|
136
|
+
* );
|
|
137
|
+
* // Fetch the next page
|
|
138
|
+
* if (page.nextCursor) {
|
|
139
|
+
* const page2 = await ctx.runQuery(
|
|
140
|
+
* components.auth.security.keys.keyList,
|
|
141
|
+
* { where: { userId: user._id, revoked: false }, cursor: page.nextCursor },
|
|
142
|
+
* );
|
|
143
|
+
* }
|
|
144
|
+
* ```
|
|
145
|
+
*/
|
|
146
|
+
const keyList = query({
|
|
147
|
+
args: {
|
|
148
|
+
where: v.optional(v.object({
|
|
149
|
+
userId: v.optional(v.id("User")),
|
|
150
|
+
revoked: v.optional(v.boolean()),
|
|
151
|
+
name: v.optional(v.string()),
|
|
152
|
+
prefix: v.optional(v.string())
|
|
153
|
+
})),
|
|
154
|
+
limit: v.optional(v.number()),
|
|
155
|
+
cursor: v.optional(v.union(v.string(), v.null())),
|
|
156
|
+
orderBy: v.optional(v.union(v.literal("_creationTime"), v.literal("name"), v.literal("lastUsedAt"), v.literal("expiresAt"), v.literal("revoked"))),
|
|
157
|
+
order: v.optional(v.union(v.literal("asc"), v.literal("desc")))
|
|
158
|
+
},
|
|
159
|
+
returns: vPaginated(vApiKeyDoc),
|
|
160
|
+
handler: async (ctx, args) => {
|
|
161
|
+
const where = args.where ?? {};
|
|
162
|
+
const limit = Math.min(Math.max(args.limit ?? 50, 1), 100);
|
|
163
|
+
const order = args.order ?? "desc";
|
|
164
|
+
let q;
|
|
165
|
+
if (where.userId !== void 0) q = ctx.db.query("ApiKey").withIndex("user_id", (idx) => idx.eq("userId", where.userId));
|
|
166
|
+
else q = ctx.db.query("ApiKey");
|
|
167
|
+
if (where.revoked !== void 0) q = q.filter((f) => f.eq(f.field("revoked"), where.revoked));
|
|
168
|
+
if (where.name !== void 0) q = q.filter((f) => f.eq(f.field("name"), where.name));
|
|
169
|
+
if (where.prefix !== void 0) q = q.filter((f) => f.eq(f.field("prefix"), where.prefix));
|
|
170
|
+
q = q.order(order);
|
|
171
|
+
const all = await q.collect();
|
|
172
|
+
let startIdx = 0;
|
|
173
|
+
if (args.cursor) {
|
|
174
|
+
const cursorIdx = all.findIndex((doc) => doc._id === args.cursor);
|
|
175
|
+
if (cursorIdx !== -1) startIdx = cursorIdx + 1;
|
|
176
|
+
}
|
|
177
|
+
const page = all.slice(startIdx, startIdx + limit + 1);
|
|
178
|
+
const hasMore = page.length > limit;
|
|
179
|
+
const items = hasMore ? page.slice(0, limit) : page;
|
|
180
|
+
return {
|
|
181
|
+
items,
|
|
182
|
+
nextCursor: hasMore ? items[items.length - 1]._id : null
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
/**
|
|
187
|
+
* Get a single API key by its document ID.
|
|
188
|
+
*
|
|
189
|
+
* Performs a direct document lookup on the `ApiKey` table. Useful when
|
|
190
|
+
* you already have the key's `_id` (e.g. from a list query or a stored
|
|
191
|
+
* reference) and need to retrieve its full details.
|
|
192
|
+
*
|
|
193
|
+
* @param keyId - The `_id` of the `ApiKey` document to retrieve.
|
|
194
|
+
* @returns The `ApiKey` document, or `null` if no key exists with the
|
|
195
|
+
* given ID.
|
|
196
|
+
*
|
|
197
|
+
* @example
|
|
198
|
+
* ```ts
|
|
199
|
+
* const apiKey = await ctx.runQuery(
|
|
200
|
+
* components.auth.security.keys.keyGetById,
|
|
201
|
+
* { keyId: storedKeyId },
|
|
202
|
+
* );
|
|
203
|
+
* if (apiKey !== null) {
|
|
204
|
+
* console.log(apiKey.name, apiKey.scopes);
|
|
205
|
+
* }
|
|
206
|
+
* ```
|
|
207
|
+
*/
|
|
208
|
+
const keyGetById = query({
|
|
209
|
+
args: { keyId: v.id("ApiKey") },
|
|
210
|
+
returns: v.union(vApiKeyDoc, v.null()),
|
|
211
|
+
handler: async (ctx, { keyId }) => {
|
|
212
|
+
return await ctx.db.get("ApiKey", keyId);
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
/**
|
|
216
|
+
* Patch an API key record with partial updates.
|
|
217
|
+
*
|
|
218
|
+
* Performs a partial update on the `ApiKey` document. Supports modifying
|
|
219
|
+
* the key's name, scopes, rate limit configuration, rate limit state,
|
|
220
|
+
* revocation flag, and last-used timestamp. Throws a `ConvexError` with
|
|
221
|
+
* code `"KEY_NOT_FOUND"` if the key does not exist.
|
|
222
|
+
*
|
|
223
|
+
* @param keyId - The `_id` of the `ApiKey` document to update.
|
|
224
|
+
* @param data - An object containing the fields to patch. All fields are
|
|
225
|
+
* optional:
|
|
226
|
+
* - `name` -- Updated human-readable name.
|
|
227
|
+
* - `scopes` -- Replacement array of permission scopes.
|
|
228
|
+
* - `rateLimit` -- Updated rate limit configuration.
|
|
229
|
+
* - `rateLimitState` -- Updated rate limit tracking state (token
|
|
230
|
+
* count, last refill time).
|
|
231
|
+
* - `revoked` -- Set to `true` to revoke the key, `false` to
|
|
232
|
+
* reinstate it.
|
|
233
|
+
* - `lastUsedAt` -- Unix timestamp (in milliseconds) of the most
|
|
234
|
+
* recent API call using this key.
|
|
235
|
+
* @returns `null` on success.
|
|
236
|
+
*
|
|
237
|
+
* @example
|
|
238
|
+
* ```ts
|
|
239
|
+
* // Revoke an API key
|
|
240
|
+
* await ctx.runMutation(
|
|
241
|
+
* components.auth.security.keys.keyPatch,
|
|
242
|
+
* {
|
|
243
|
+
* keyId: apiKey._id,
|
|
244
|
+
* data: { revoked: true },
|
|
245
|
+
* },
|
|
246
|
+
* );
|
|
247
|
+
*
|
|
248
|
+
* // Rename and update scopes
|
|
249
|
+
* await ctx.runMutation(
|
|
250
|
+
* components.auth.security.keys.keyPatch,
|
|
251
|
+
* {
|
|
252
|
+
* keyId: apiKey._id,
|
|
253
|
+
* data: {
|
|
254
|
+
* name: "Read-Only Key",
|
|
255
|
+
* scopes: [{ resource: "messages", actions: ["read"] }],
|
|
256
|
+
* },
|
|
257
|
+
* },
|
|
258
|
+
* );
|
|
259
|
+
* ```
|
|
260
|
+
*/
|
|
261
|
+
const keyPatch = mutation({
|
|
262
|
+
args: {
|
|
263
|
+
keyId: v.id("ApiKey"),
|
|
264
|
+
data: v.object({
|
|
265
|
+
name: v.optional(v.string()),
|
|
266
|
+
scopes: v.optional(v.array(vApiKeyScope)),
|
|
267
|
+
rateLimit: v.optional(vApiKeyRateLimit),
|
|
268
|
+
rateLimitState: v.optional(vApiKeyRateLimitState),
|
|
269
|
+
revoked: v.optional(v.boolean()),
|
|
270
|
+
lastUsedAt: v.optional(v.number())
|
|
271
|
+
})
|
|
272
|
+
},
|
|
273
|
+
returns: v.null(),
|
|
274
|
+
handler: async (ctx, { keyId, data }) => {
|
|
275
|
+
if (await ctx.db.get("ApiKey", keyId) === null) throw new ConvexError({
|
|
276
|
+
code: "KEY_NOT_FOUND",
|
|
277
|
+
message: "API key not found",
|
|
278
|
+
keyId
|
|
279
|
+
});
|
|
280
|
+
await ctx.db.patch("ApiKey", keyId, data);
|
|
281
|
+
return null;
|
|
282
|
+
}
|
|
283
|
+
});
|
|
284
|
+
/**
|
|
285
|
+
* Hard-delete an API key record from the `ApiKey` table.
|
|
286
|
+
*
|
|
287
|
+
* Permanently removes the API key document. Unlike revocation (which
|
|
288
|
+
* keeps the record for audit purposes), this is an irreversible
|
|
289
|
+
* deletion. Throws a `ConvexError` with code `"KEY_NOT_FOUND"` if the
|
|
290
|
+
* key does not exist.
|
|
291
|
+
*
|
|
292
|
+
* @param keyId - The `_id` of the `ApiKey` document to delete.
|
|
293
|
+
* @returns `null` on success.
|
|
294
|
+
*
|
|
295
|
+
* @example
|
|
296
|
+
* ```ts
|
|
297
|
+
* await ctx.runMutation(
|
|
298
|
+
* components.auth.security.keys.keyDelete,
|
|
299
|
+
* { keyId: apiKey._id },
|
|
300
|
+
* );
|
|
301
|
+
* ```
|
|
302
|
+
*/
|
|
303
|
+
const keyDelete = mutation({
|
|
304
|
+
args: { keyId: v.id("ApiKey") },
|
|
305
|
+
returns: v.null(),
|
|
306
|
+
handler: async (ctx, { keyId }) => {
|
|
307
|
+
if (await ctx.db.get("ApiKey", keyId) === null) throw new ConvexError({
|
|
308
|
+
code: "KEY_NOT_FOUND",
|
|
309
|
+
message: "API key not found",
|
|
310
|
+
keyId
|
|
311
|
+
});
|
|
312
|
+
await ctx.db.delete("ApiKey", keyId);
|
|
313
|
+
return null;
|
|
314
|
+
}
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
//#endregion
|
|
318
|
+
export { keyDelete, keyGetByHashedKey, keyGetById, keyInsert, keyList, keyPatch };
|
|
319
|
+
//# sourceMappingURL=keys.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keys.js","names":[],"sources":["../../../../src/component/public/security/keys.ts"],"sourcesContent":["import { ConvexError, v } from \"convex/values\";\nimport { mutation, query } from \"../../functions\";\nimport {\n vApiKeyDoc,\n vApiKeyRateLimit,\n vApiKeyRateLimitState,\n vApiKeyScope,\n vPaginated,\n} from \"../../model\";\n\n// ============================================================================\n// API Keys\n// ============================================================================\n\n/**\n * Insert a new API key record into the `ApiKey` table.\n *\n * Creates an API key entry with the given metadata and scopes. The caller\n * is responsible for generating and hashing the raw key before passing it\n * here -- this function only stores the hash, never the plaintext key.\n * The `createdAt` timestamp and `revoked: false` flag are set automatically.\n *\n * @param userId - The `_id` of the `User` who owns this API key.\n * @param prefix - A short, visible prefix for the key (e.g. `\"sk_live_\"`)\n * that helps users identify which key was used without exposing the secret.\n * @param hashedKey - SHA-256 hash of the full API key string. Used for\n * constant-time lookup during Bearer token verification.\n * @param name - Human-readable name for the key (e.g. `\"Production Backend\"`).\n * @param scopes - Array of permission scopes, each containing a `resource`\n * name and an array of allowed `actions` (e.g.\n * `[{ resource: \"messages\", actions: [\"read\", \"write\"] }]`).\n * @param rateLimit - Optional rate limit configuration to apply per-key\n * (e.g. max requests per window).\n * @param expiresAt - Optional Unix timestamp (in milliseconds) after which\n * the key is no longer valid. Omit for non-expiring keys.\n * @param metadata - Optional arbitrary metadata to attach to the key record.\n * @returns The `_id` of the newly created `ApiKey` document.\n *\n * @example\n * ```ts\n * const keyId = await ctx.runMutation(\n * components.auth.security.keys.keyInsert,\n * {\n * userId: user._id,\n * prefix: \"sk_live_\",\n * hashedKey: await sha256(rawKey),\n * name: \"Production Backend\",\n * scopes: [{ resource: \"messages\", actions: [\"read\", \"write\"] }],\n * expiresAt: Date.now() + 90 * 24 * 60 * 60 * 1000,\n * },\n * );\n * ```\n */\nexport const keyInsert = mutation({\n args: {\n userId: v.id(\"User\"),\n prefix: v.string(),\n hashedKey: v.string(),\n name: v.string(),\n scopes: v.array(\n v.object({\n resource: v.string(),\n actions: v.array(v.string()),\n }),\n ),\n rateLimit: v.optional(vApiKeyRateLimit),\n expiresAt: v.optional(v.number()),\n metadata: v.optional(v.any()),\n },\n returns: v.id(\"ApiKey\"),\n handler: async (ctx, args) => {\n return await ctx.db.insert(\"ApiKey\", {\n ...args,\n createdAt: Date.now(),\n revoked: false,\n });\n },\n});\n\n/**\n * Look up an API key by its SHA-256 hash.\n *\n * Queries the `ApiKey` table using the `hashed_key` index. This is the\n * primary lookup path during Bearer token verification: the incoming\n * token is hashed and matched against stored hashes in constant time.\n * Returns the full key record including scopes, rate limit state, and\n * revocation status so the caller can perform authorization checks.\n *\n * @param hashedKey - SHA-256 hash of the API key string extracted from\n * the `Authorization: Bearer <token>` header.\n * @returns The matching `ApiKey` document (including rate limit state),\n * or `null` if no key matches the given hash.\n *\n * @example\n * ```ts\n * const apiKey = await ctx.runQuery(\n * components.auth.security.keys.keyGetByHashedKey,\n * { hashedKey: await sha256(bearerToken) },\n * );\n * if (apiKey === null || apiKey.revoked) {\n * throw new Error(\"Invalid or revoked API key\");\n * }\n * ```\n */\nexport const keyGetByHashedKey = query({\n args: { hashedKey: v.string() },\n returns: v.union(vApiKeyDoc, v.null()),\n handler: async (ctx, { hashedKey }) => {\n return await ctx.db\n .query(\"ApiKey\")\n .withIndex(\"hashed_key\", (q) => q.eq(\"hashedKey\", hashedKey))\n .first();\n },\n});\n\n/**\n * List API keys with optional filtering, sorting, and cursor-based pagination.\n *\n * Returns a paginated result `{ items, nextCursor }` from the `ApiKey`\n * table. Supports filtering by `userId`, `revoked` status, `name`, and\n * `prefix`. The page size is clamped between 1 and 100 (default 50).\n * Pass the returned `nextCursor` as `cursor` in a subsequent call to\n * fetch the next page.\n *\n * @param where - Optional filter object. All specified fields are\n * combined with AND logic:\n * - `userId` -- restrict to keys owned by this user.\n * - `revoked` -- `true` for revoked keys, `false` for active keys.\n * - `name` -- exact match on the key's human-readable name.\n * - `prefix` -- exact match on the key prefix string.\n * @param limit - Maximum number of items to return per page (1--100,\n * default `50`).\n * @param cursor - Opaque cursor string (an `ApiKey` document `_id`)\n * returned from a previous call. Pass `null` or omit for the first page.\n * @param orderBy - Field to sort by. One of `\"_creationTime\"`, `\"name\"`,\n * `\"lastUsedAt\"`, `\"expiresAt\"`, or `\"revoked\"`. Defaults to\n * `\"_creationTime\"`.\n * @param order - Sort direction, `\"asc\"` or `\"desc\"` (default `\"desc\"`).\n * @returns An object with `items` (array of `ApiKey` documents) and\n * `nextCursor` (string ID of the last item, or `null` if no more pages).\n *\n * @example\n * ```ts\n * // Fetch the first page of active keys for a user\n * const page = await ctx.runQuery(\n * components.auth.security.keys.keyList,\n * {\n * where: { userId: user._id, revoked: false },\n * limit: 20,\n * order: \"desc\",\n * },\n * );\n * // Fetch the next page\n * if (page.nextCursor) {\n * const page2 = await ctx.runQuery(\n * components.auth.security.keys.keyList,\n * { where: { userId: user._id, revoked: false }, cursor: page.nextCursor },\n * );\n * }\n * ```\n */\nexport const keyList = query({\n args: {\n where: v.optional(\n v.object({\n userId: v.optional(v.id(\"User\")),\n revoked: v.optional(v.boolean()),\n name: v.optional(v.string()),\n prefix: v.optional(v.string()),\n }),\n ),\n limit: v.optional(v.number()),\n cursor: v.optional(v.union(v.string(), v.null())),\n orderBy: v.optional(\n v.union(\n v.literal(\"_creationTime\"),\n v.literal(\"name\"),\n v.literal(\"lastUsedAt\"),\n v.literal(\"expiresAt\"),\n v.literal(\"revoked\"),\n ),\n ),\n order: v.optional(v.union(v.literal(\"asc\"), v.literal(\"desc\"))),\n },\n returns: vPaginated(vApiKeyDoc),\n handler: async (ctx, args) => {\n const where = args.where ?? {};\n const limit = Math.min(Math.max(args.limit ?? 50, 1), 100);\n const order = args.order ?? \"desc\";\n\n let q;\n if (where.userId !== undefined) {\n q = ctx.db\n .query(\"ApiKey\")\n .withIndex(\"user_id\", (idx) => idx.eq(\"userId\", where.userId!));\n } else {\n q = ctx.db.query(\"ApiKey\");\n }\n\n if (where.revoked !== undefined) {\n q = q.filter((f) => f.eq(f.field(\"revoked\"), where.revoked!));\n }\n if (where.name !== undefined) {\n q = q.filter((f) => f.eq(f.field(\"name\"), where.name!));\n }\n if (where.prefix !== undefined) {\n q = q.filter((f) => f.eq(f.field(\"prefix\"), where.prefix!));\n }\n\n q = q.order(order);\n\n const all = await q.collect();\n let startIdx = 0;\n if (args.cursor) {\n const cursorIdx = all.findIndex((doc) => doc._id === args.cursor);\n if (cursorIdx !== -1) {\n startIdx = cursorIdx + 1;\n }\n }\n const page = all.slice(startIdx, startIdx + limit + 1);\n const hasMore = page.length > limit;\n const items = hasMore ? page.slice(0, limit) : page;\n const nextCursor = hasMore ? items[items.length - 1]._id : null;\n return { items, nextCursor };\n },\n});\n\n/**\n * Get a single API key by its document ID.\n *\n * Performs a direct document lookup on the `ApiKey` table. Useful when\n * you already have the key's `_id` (e.g. from a list query or a stored\n * reference) and need to retrieve its full details.\n *\n * @param keyId - The `_id` of the `ApiKey` document to retrieve.\n * @returns The `ApiKey` document, or `null` if no key exists with the\n * given ID.\n *\n * @example\n * ```ts\n * const apiKey = await ctx.runQuery(\n * components.auth.security.keys.keyGetById,\n * { keyId: storedKeyId },\n * );\n * if (apiKey !== null) {\n * console.log(apiKey.name, apiKey.scopes);\n * }\n * ```\n */\nexport const keyGetById = query({\n args: { keyId: v.id(\"ApiKey\") },\n returns: v.union(vApiKeyDoc, v.null()),\n handler: async (ctx, { keyId }) => {\n return await ctx.db.get(\"ApiKey\", keyId);\n },\n});\n\n/**\n * Patch an API key record with partial updates.\n *\n * Performs a partial update on the `ApiKey` document. Supports modifying\n * the key's name, scopes, rate limit configuration, rate limit state,\n * revocation flag, and last-used timestamp. Throws a `ConvexError` with\n * code `\"KEY_NOT_FOUND\"` if the key does not exist.\n *\n * @param keyId - The `_id` of the `ApiKey` document to update.\n * @param data - An object containing the fields to patch. All fields are\n * optional:\n * - `name` -- Updated human-readable name.\n * - `scopes` -- Replacement array of permission scopes.\n * - `rateLimit` -- Updated rate limit configuration.\n * - `rateLimitState` -- Updated rate limit tracking state (token\n * count, last refill time).\n * - `revoked` -- Set to `true` to revoke the key, `false` to\n * reinstate it.\n * - `lastUsedAt` -- Unix timestamp (in milliseconds) of the most\n * recent API call using this key.\n * @returns `null` on success.\n *\n * @example\n * ```ts\n * // Revoke an API key\n * await ctx.runMutation(\n * components.auth.security.keys.keyPatch,\n * {\n * keyId: apiKey._id,\n * data: { revoked: true },\n * },\n * );\n *\n * // Rename and update scopes\n * await ctx.runMutation(\n * components.auth.security.keys.keyPatch,\n * {\n * keyId: apiKey._id,\n * data: {\n * name: \"Read-Only Key\",\n * scopes: [{ resource: \"messages\", actions: [\"read\"] }],\n * },\n * },\n * );\n * ```\n */\nexport const keyPatch = mutation({\n args: {\n keyId: v.id(\"ApiKey\"),\n data: v.object({\n name: v.optional(v.string()),\n scopes: v.optional(v.array(vApiKeyScope)),\n rateLimit: v.optional(vApiKeyRateLimit),\n rateLimitState: v.optional(vApiKeyRateLimitState),\n revoked: v.optional(v.boolean()),\n lastUsedAt: v.optional(v.number()),\n }),\n },\n returns: v.null(),\n handler: async (ctx, { keyId, data }) => {\n const key = await ctx.db.get(\"ApiKey\", keyId);\n if (key === null) {\n throw new ConvexError({\n code: \"KEY_NOT_FOUND\",\n message: \"API key not found\",\n keyId,\n });\n }\n await ctx.db.patch(\"ApiKey\", keyId, data);\n return null;\n },\n});\n\n/**\n * Hard-delete an API key record from the `ApiKey` table.\n *\n * Permanently removes the API key document. Unlike revocation (which\n * keeps the record for audit purposes), this is an irreversible\n * deletion. Throws a `ConvexError` with code `\"KEY_NOT_FOUND\"` if the\n * key does not exist.\n *\n * @param keyId - The `_id` of the `ApiKey` document to delete.\n * @returns `null` on success.\n *\n * @example\n * ```ts\n * await ctx.runMutation(\n * components.auth.security.keys.keyDelete,\n * { keyId: apiKey._id },\n * );\n * ```\n */\nexport const keyDelete = mutation({\n args: { keyId: v.id(\"ApiKey\") },\n returns: v.null(),\n handler: async (ctx, { keyId }) => {\n const key = await ctx.db.get(\"ApiKey\", keyId);\n if (key === null) {\n throw new ConvexError({\n code: \"KEY_NOT_FOUND\",\n message: \"API key not found\",\n keyId,\n });\n }\n await ctx.db.delete(\"ApiKey\", keyId);\n return null;\n },\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqDA,MAAa,YAAY,SAAS;CAChC,MAAM;EACJ,QAAQ,EAAE,GAAG,OAAO;EACpB,QAAQ,EAAE,QAAQ;EAClB,WAAW,EAAE,QAAQ;EACrB,MAAM,EAAE,QAAQ;EAChB,QAAQ,EAAE,MACR,EAAE,OAAO;GACP,UAAU,EAAE,QAAQ;GACpB,SAAS,EAAE,MAAM,EAAE,QAAQ,CAAC;GAC7B,CAAC,CACH;EACD,WAAW,EAAE,SAAS,iBAAiB;EACvC,WAAW,EAAE,SAAS,EAAE,QAAQ,CAAC;EACjC,UAAU,EAAE,SAAS,EAAE,KAAK,CAAC;EAC9B;CACD,SAAS,EAAE,GAAG,SAAS;CACvB,SAAS,OAAO,KAAK,SAAS;AAC5B,SAAO,MAAM,IAAI,GAAG,OAAO,UAAU;GACnC,GAAG;GACH,WAAW,KAAK,KAAK;GACrB,SAAS;GACV,CAAC;;CAEL,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BF,MAAa,oBAAoB,MAAM;CACrC,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE;CAC/B,SAAS,EAAE,MAAM,YAAY,EAAE,MAAM,CAAC;CACtC,SAAS,OAAO,KAAK,EAAE,gBAAgB;AACrC,SAAO,MAAM,IAAI,GACd,MAAM,SAAS,CACf,UAAU,eAAe,MAAM,EAAE,GAAG,aAAa,UAAU,CAAC,CAC5D,OAAO;;CAEb,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgDF,MAAa,UAAU,MAAM;CAC3B,MAAM;EACJ,OAAO,EAAE,SACP,EAAE,OAAO;GACP,QAAQ,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC;GAChC,SAAS,EAAE,SAAS,EAAE,SAAS,CAAC;GAChC,MAAM,EAAE,SAAS,EAAE,QAAQ,CAAC;GAC5B,QAAQ,EAAE,SAAS,EAAE,QAAQ,CAAC;GAC/B,CAAC,CACH;EACD,OAAO,EAAE,SAAS,EAAE,QAAQ,CAAC;EAC7B,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,MAAM,CAAC,CAAC;EACjD,SAAS,EAAE,SACT,EAAE,MACA,EAAE,QAAQ,gBAAgB,EAC1B,EAAE,QAAQ,OAAO,EACjB,EAAE,QAAQ,aAAa,EACvB,EAAE,QAAQ,YAAY,EACtB,EAAE,QAAQ,UAAU,CACrB,CACF;EACD,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,MAAM,EAAE,EAAE,QAAQ,OAAO,CAAC,CAAC;EAChE;CACD,SAAS,WAAW,WAAW;CAC/B,SAAS,OAAO,KAAK,SAAS;EAC5B,MAAM,QAAQ,KAAK,SAAS,EAAE;EAC9B,MAAM,QAAQ,KAAK,IAAI,KAAK,IAAI,KAAK,SAAS,IAAI,EAAE,EAAE,IAAI;EAC1D,MAAM,QAAQ,KAAK,SAAS;EAE5B,IAAI;AACJ,MAAI,MAAM,WAAW,OACnB,KAAI,IAAI,GACL,MAAM,SAAS,CACf,UAAU,YAAY,QAAQ,IAAI,GAAG,UAAU,MAAM,OAAQ,CAAC;MAEjE,KAAI,IAAI,GAAG,MAAM,SAAS;AAG5B,MAAI,MAAM,YAAY,OACpB,KAAI,EAAE,QAAQ,MAAM,EAAE,GAAG,EAAE,MAAM,UAAU,EAAE,MAAM,QAAS,CAAC;AAE/D,MAAI,MAAM,SAAS,OACjB,KAAI,EAAE,QAAQ,MAAM,EAAE,GAAG,EAAE,MAAM,OAAO,EAAE,MAAM,KAAM,CAAC;AAEzD,MAAI,MAAM,WAAW,OACnB,KAAI,EAAE,QAAQ,MAAM,EAAE,GAAG,EAAE,MAAM,SAAS,EAAE,MAAM,OAAQ,CAAC;AAG7D,MAAI,EAAE,MAAM,MAAM;EAElB,MAAM,MAAM,MAAM,EAAE,SAAS;EAC7B,IAAI,WAAW;AACf,MAAI,KAAK,QAAQ;GACf,MAAM,YAAY,IAAI,WAAW,QAAQ,IAAI,QAAQ,KAAK,OAAO;AACjE,OAAI,cAAc,GAChB,YAAW,YAAY;;EAG3B,MAAM,OAAO,IAAI,MAAM,UAAU,WAAW,QAAQ,EAAE;EACtD,MAAM,UAAU,KAAK,SAAS;EAC9B,MAAM,QAAQ,UAAU,KAAK,MAAM,GAAG,MAAM,GAAG;AAE/C,SAAO;GAAE;GAAO,YADG,UAAU,MAAM,MAAM,SAAS,GAAG,MAAM;GAC/B;;CAE/B,CAAC;;;;;;;;;;;;;;;;;;;;;;;AAwBF,MAAa,aAAa,MAAM;CAC9B,MAAM,EAAE,OAAO,EAAE,GAAG,SAAS,EAAE;CAC/B,SAAS,EAAE,MAAM,YAAY,EAAE,MAAM,CAAC;CACtC,SAAS,OAAO,KAAK,EAAE,YAAY;AACjC,SAAO,MAAM,IAAI,GAAG,IAAI,UAAU,MAAM;;CAE3C,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgDF,MAAa,WAAW,SAAS;CAC/B,MAAM;EACJ,OAAO,EAAE,GAAG,SAAS;EACrB,MAAM,EAAE,OAAO;GACb,MAAM,EAAE,SAAS,EAAE,QAAQ,CAAC;GAC5B,QAAQ,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;GACzC,WAAW,EAAE,SAAS,iBAAiB;GACvC,gBAAgB,EAAE,SAAS,sBAAsB;GACjD,SAAS,EAAE,SAAS,EAAE,SAAS,CAAC;GAChC,YAAY,EAAE,SAAS,EAAE,QAAQ,CAAC;GACnC,CAAC;EACH;CACD,SAAS,EAAE,MAAM;CACjB,SAAS,OAAO,KAAK,EAAE,OAAO,WAAW;AAEvC,MADY,MAAM,IAAI,GAAG,IAAI,UAAU,MAAM,KACjC,KACV,OAAM,IAAI,YAAY;GACpB,MAAM;GACN,SAAS;GACT;GACD,CAAC;AAEJ,QAAM,IAAI,GAAG,MAAM,UAAU,OAAO,KAAK;AACzC,SAAO;;CAEV,CAAC;;;;;;;;;;;;;;;;;;;;AAqBF,MAAa,YAAY,SAAS;CAChC,MAAM,EAAE,OAAO,EAAE,GAAG,SAAS,EAAE;CAC/B,SAAS,EAAE,MAAM;CACjB,SAAS,OAAO,KAAK,EAAE,YAAY;AAEjC,MADY,MAAM,IAAI,GAAG,IAAI,UAAU,MAAM,KACjC,KACV,OAAM,IAAI,YAAY;GACpB,MAAM;GACN,SAAS;GACT;GACD,CAAC;AAEJ,QAAM,IAAI,GAAG,OAAO,UAAU,MAAM;AACpC,SAAO;;CAEV,CAAC"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
declare namespace limits_d_exports {
|
|
2
|
+
export { rateLimitCreate, rateLimitDelete, rateLimitGet, rateLimitPatch };
|
|
3
|
+
}
|
|
4
|
+
/**
|
|
5
|
+
* Look up a rate limit entry by its string identifier.
|
|
6
|
+
*
|
|
7
|
+
* Queries the `RateLimit` table using the `by_identifier` unique index.
|
|
8
|
+
* Returns the rate limit state with camelCase field names (`attemptsLeft`,
|
|
9
|
+
* `lastAttemptTime`) mapped from the snake_case storage format. Used to
|
|
10
|
+
* check whether an action should be allowed or throttled.
|
|
11
|
+
*
|
|
12
|
+
* @param identifier - Unique string identifying the rate limit bucket
|
|
13
|
+
* (e.g. `"login:user@example.com"` or `"api:sk_live_abc123"`).
|
|
14
|
+
* @returns The rate limit state object (including `attemptsLeft` and
|
|
15
|
+
* `lastAttemptTime`), or `null` if no entry exists for the identifier.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* const limit = await ctx.runQuery(
|
|
20
|
+
* components.auth.security.limits.rateLimitGet,
|
|
21
|
+
* { identifier: `login:${email}` },
|
|
22
|
+
* );
|
|
23
|
+
* if (limit !== null && limit.attemptsLeft <= 0) {
|
|
24
|
+
* throw new Error("Too many login attempts. Please try again later.");
|
|
25
|
+
* }
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
declare const rateLimitGet: any;
|
|
29
|
+
/**
|
|
30
|
+
* Create a new rate limit entry in the `RateLimit` table.
|
|
31
|
+
*
|
|
32
|
+
* Initializes a rate limit bucket for a given identifier. The entry
|
|
33
|
+
* tracks remaining attempts and the timestamp of the last attempt,
|
|
34
|
+
* storing them in snake_case format internally. Call this when the
|
|
35
|
+
* first rate-limited action occurs for an identifier that does not
|
|
36
|
+
* yet have an entry.
|
|
37
|
+
*
|
|
38
|
+
* @param identifier - Unique string identifying the rate limit bucket
|
|
39
|
+
* (e.g. `"login:user@example.com"` or `"otp:+15551234567"`).
|
|
40
|
+
* @param attemptsLeft - Number of remaining attempts before the action
|
|
41
|
+
* is throttled.
|
|
42
|
+
* @param lastAttemptTime - Unix timestamp (in milliseconds) of the
|
|
43
|
+
* initial attempt.
|
|
44
|
+
* @returns The `_id` of the newly created `RateLimit` document.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```ts
|
|
48
|
+
* const rateLimitId = await ctx.runMutation(
|
|
49
|
+
* components.auth.security.limits.rateLimitCreate,
|
|
50
|
+
* {
|
|
51
|
+
* identifier: `login:${email}`,
|
|
52
|
+
* attemptsLeft: 4, // 5 max minus this attempt
|
|
53
|
+
* lastAttemptTime: Date.now(),
|
|
54
|
+
* },
|
|
55
|
+
* );
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
declare const rateLimitCreate: any;
|
|
59
|
+
/**
|
|
60
|
+
* Patch a rate limit entry with partial data.
|
|
61
|
+
*
|
|
62
|
+
* Updates an existing `RateLimit` document with the provided fields.
|
|
63
|
+
* Automatically maps camelCase field names (`attemptsLeft`,
|
|
64
|
+
* `lastAttemptTime`) to the snake_case storage format before writing.
|
|
65
|
+
* Typically called to decrement remaining attempts or to reset the
|
|
66
|
+
* bucket after a cooldown window has elapsed.
|
|
67
|
+
*
|
|
68
|
+
* @param rateLimitId - The `_id` of the `RateLimit` document to update.
|
|
69
|
+
* @param data - An object containing the fields to patch. Supports
|
|
70
|
+
* camelCase names which are transparently converted:
|
|
71
|
+
* - `attemptsLeft` -- Updated number of remaining attempts.
|
|
72
|
+
* - `lastAttemptTime` -- Updated timestamp of the most recent attempt.
|
|
73
|
+
* @returns `null` on success.
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```ts
|
|
77
|
+
* // Decrement attempts after a failed login
|
|
78
|
+
* await ctx.runMutation(
|
|
79
|
+
* components.auth.security.limits.rateLimitPatch,
|
|
80
|
+
* {
|
|
81
|
+
* rateLimitId: limit._id,
|
|
82
|
+
* data: {
|
|
83
|
+
* attemptsLeft: limit.attemptsLeft - 1,
|
|
84
|
+
* lastAttemptTime: Date.now(),
|
|
85
|
+
* },
|
|
86
|
+
* },
|
|
87
|
+
* );
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
declare const rateLimitPatch: any;
|
|
91
|
+
/**
|
|
92
|
+
* Delete a rate limit entry from the `RateLimit` table.
|
|
93
|
+
*
|
|
94
|
+
* Permanently removes the rate limit bucket. This effectively resets
|
|
95
|
+
* rate limiting for the associated identifier, allowing the next
|
|
96
|
+
* action to proceed without throttling. Useful for administrative
|
|
97
|
+
* resets or cleanup of expired buckets.
|
|
98
|
+
*
|
|
99
|
+
* @param rateLimitId - The `_id` of the `RateLimit` document to delete.
|
|
100
|
+
* @returns `null` on success.
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```ts
|
|
104
|
+
* // Admin resets a user's login rate limit
|
|
105
|
+
* await ctx.runMutation(
|
|
106
|
+
* components.auth.security.limits.rateLimitDelete,
|
|
107
|
+
* { rateLimitId: limit._id },
|
|
108
|
+
* );
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
111
|
+
declare const rateLimitDelete: any;
|
|
112
|
+
//#endregion
|
|
113
|
+
export { limits_d_exports, rateLimitCreate, rateLimitDelete, rateLimitGet, rateLimitPatch };
|
|
114
|
+
//# sourceMappingURL=limits.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"limits.d.ts","names":[],"sources":["../../../../src/component/public/security/limits.ts"],"mappings":";;;;;;;;;;;;AA4BA;;;;;AAgDA;;;;;AA+CA;;;;;cA/Fa,YAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAgDA,eAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA+CA,cAAA;;;;;;;;;;;;;;;;;;;;;cAsCA,eAAA"}
|