@robelest/convex-auth 0.0.4-preview.25 → 0.0.4-preview.28
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 +43 -36
- package/dist/bin.js +5765 -4880
- package/dist/browser/index.d.ts +30 -0
- package/dist/browser/index.js +93 -0
- package/dist/browser/locks.js +11 -0
- package/dist/browser/navigation.js +14 -0
- package/dist/{factors → browser}/passkey.js +23 -32
- package/dist/browser/runtime.js +92 -0
- package/dist/client/core/types.d.ts +452 -5
- package/dist/client/core/types.js +17 -0
- package/dist/client/errors.js +19 -0
- package/dist/client/factors/device.js +94 -0
- package/dist/{factors → client/factors}/totp.js +12 -4
- package/dist/client/index.d.ts +47 -1
- package/dist/client/index.js +269 -232
- package/dist/client/runtime/mutex.js +24 -0
- package/dist/client/runtime/proxy.js +30 -0
- package/dist/client/runtime/storage.js +45 -0
- package/dist/client/services/adapters.js +7 -0
- package/dist/client/services/http.js +6 -0
- package/dist/client/services/resolve.js +13 -0
- package/dist/client/services/runtime.js +6 -0
- package/dist/component/_generated/component.d.ts +1355 -1399
- package/dist/component/convex.config.d.ts +2 -2
- package/dist/component/index.d.ts +4 -26
- package/dist/component/index.js +1 -1
- package/dist/component/model.d.ts +26 -112
- package/dist/component/model.js +76 -54
- package/dist/component/modules.js +38 -0
- package/dist/component/public/factors/devices.js +1 -1
- package/dist/component/public/factors/passkeys.js +1 -1
- package/dist/component/public/factors/totp.js +1 -1
- package/dist/component/public/groups/core.js +2 -2
- package/dist/component/public/groups/invites.js +1 -1
- package/dist/component/public/groups/members.js +1 -1
- package/dist/component/public/identity/accounts.js +1 -1
- package/dist/component/public/identity/codes.js +1 -1
- package/dist/component/public/identity/sessions.js +39 -2
- package/dist/component/public/identity/tokens.js +82 -4
- package/dist/component/public/identity/users.js +1 -1
- package/dist/component/public/identity/verifiers.js +10 -4
- package/dist/component/public/security/keys.js +1 -1
- package/dist/component/public/security/limits.js +1 -1
- package/dist/component/public/{enterprise → sso}/audit.js +26 -26
- package/dist/component/public/sso/core.js +263 -0
- package/dist/component/public/sso/domains.js +280 -0
- package/dist/component/public/{enterprise → sso}/scim.js +87 -87
- package/dist/component/public/sso/secrets.js +125 -0
- package/dist/component/public/{enterprise → sso}/webhooks.js +59 -59
- package/dist/component/public.js +9 -9
- package/dist/component/schema.d.ts +472 -393
- package/dist/component/schema.js +36 -35
- package/dist/core/index.d.ts +380 -0
- package/dist/core/index.js +83 -0
- package/dist/otel.d.ts +69 -0
- package/dist/otel.js +82 -0
- package/dist/providers/anonymous.d.ts +15 -34
- package/dist/providers/anonymous.js +27 -35
- package/dist/providers/apple.d.ts +59 -0
- package/dist/providers/apple.js +58 -0
- package/dist/providers/credentials.d.ts +18 -34
- package/dist/providers/credentials.js +16 -27
- package/dist/providers/custom.d.ts +94 -0
- package/dist/providers/custom.js +119 -0
- package/dist/providers/device.d.ts +15 -49
- package/dist/providers/device.js +17 -34
- package/dist/providers/email.d.ts +21 -38
- package/dist/providers/email.js +36 -55
- package/dist/providers/github.d.ts +54 -0
- package/dist/providers/github.js +75 -0
- package/dist/providers/google.d.ts +54 -0
- package/dist/providers/google.js +61 -0
- package/dist/providers/index.d.ts +16 -12
- package/dist/providers/index.js +15 -11
- package/dist/providers/microsoft.d.ts +57 -0
- package/dist/providers/microsoft.js +101 -0
- package/dist/providers/passkey.d.ts +19 -35
- package/dist/providers/passkey.js +20 -30
- package/dist/providers/password.d.ts +17 -18
- package/dist/providers/password.js +121 -143
- package/dist/providers/phone.d.ts +13 -28
- package/dist/providers/phone.js +21 -46
- package/dist/providers/sso.d.ts +16 -36
- package/dist/providers/sso.js +21 -22
- package/dist/providers/totp.d.ts +13 -29
- package/dist/providers/totp.js +17 -27
- package/dist/server/auth-context.d.ts +204 -0
- package/dist/server/auth-context.js +76 -0
- package/dist/server/auth.d.ts +99 -244
- package/dist/server/auth.js +56 -152
- package/dist/server/componentContext.d.ts +12 -0
- package/dist/server/componentContext.js +1 -0
- package/dist/server/config.js +6 -67
- package/dist/server/constants.js +6 -0
- package/dist/server/contract.d.ts +105 -0
- package/dist/server/contract.js +43 -0
- package/dist/server/cookies.js +3 -2
- package/dist/server/core.js +31 -36
- package/dist/server/crypto.js +34 -44
- package/dist/server/db.js +6 -1
- package/dist/server/device.js +96 -130
- package/dist/server/env.js +48 -0
- package/dist/server/errors.js +20 -0
- package/dist/server/http.d.ts +15 -59
- package/dist/server/http.js +136 -120
- package/dist/server/identity.js +2 -2
- package/dist/server/index.d.ts +5 -4
- package/dist/server/index.js +3 -3
- package/dist/server/keys.js +10 -1
- package/dist/server/limits.js +26 -26
- package/dist/server/log.js +28 -0
- package/dist/server/mounts.d.ts +1107 -296
- package/dist/server/mounts.js +315 -196
- package/dist/server/mutations/account.js +11 -14
- package/dist/server/mutations/code.js +6 -5
- package/dist/server/mutations/invalidate.js +9 -11
- package/dist/server/mutations/oauth.js +112 -73
- package/dist/server/mutations/refresh.js +47 -97
- package/dist/server/mutations/register.js +37 -35
- package/dist/server/mutations/retrieve.js +16 -16
- package/dist/server/mutations/signature.js +15 -18
- package/dist/server/mutations/signin.js +10 -5
- package/dist/server/mutations/signout.js +11 -14
- package/dist/server/mutations/store.js +25 -18
- package/dist/server/mutations/verifier.js +11 -8
- package/dist/server/mutations/verify.js +53 -41
- package/dist/server/oauth/factory.js +44 -0
- package/dist/server/oauth/index.js +12 -0
- package/dist/server/oauth/runtime.js +248 -0
- package/dist/server/passkey.js +331 -365
- package/dist/server/payloads.d.ts +16 -0
- package/dist/server/payloads.js +30 -0
- package/dist/server/{ssr.d.ts → prefetch.d.ts} +2 -2
- package/dist/server/prefetch.js +635 -0
- package/dist/server/random.js +19 -0
- package/dist/server/redirects.js +10 -5
- package/dist/server/refresh.js +14 -86
- package/dist/server/runtime.d.ts +531 -31
- package/dist/server/runtime.js +106 -267
- package/dist/server/secret.js +44 -0
- package/dist/server/services/config.js +10 -0
- package/dist/server/services/group.js +211 -0
- package/dist/server/services/logger.js +8 -0
- package/dist/server/services/providers.js +22 -0
- package/dist/server/services/refresh.js +8 -0
- package/dist/server/services/resolve.js +27 -0
- package/dist/server/services/signin.js +8 -0
- package/dist/server/sessions.js +35 -34
- package/dist/server/signin.js +229 -140
- package/dist/server/{enterprise → sso}/config.js +10 -3
- package/dist/server/sso/domain.d.ts +614 -0
- package/dist/server/sso/domain.js +1175 -0
- package/dist/server/sso/http.js +1060 -0
- package/dist/server/sso/oidc.js +324 -0
- package/dist/server/sso/policies.js +59 -0
- package/dist/server/sso/policy.js +139 -0
- package/dist/server/sso/profile.js +22 -0
- package/dist/server/sso/provision.js +179 -0
- package/dist/{component/server/enterprise → server/sso}/saml.js +142 -56
- package/dist/{component/server/enterprise → server/sso}/scim.js +13 -7
- package/dist/server/sso/shared.js +74 -0
- package/dist/server/sso/validators.js +88 -0
- package/dist/server/sso/webhook.js +94 -0
- package/dist/server/tokens.js +16 -4
- package/dist/server/totp.js +155 -164
- package/dist/server/types.d.ts +306 -296
- package/dist/server/types.js +1 -30
- package/dist/server/url.js +32 -0
- package/dist/server/users.js +74 -40
- package/dist/server/utils/cache.js +51 -0
- package/dist/server/utils/dispatch.js +36 -0
- package/dist/server/utils/retry.js +24 -0
- package/dist/server/utils/span.js +32 -0
- package/dist/shared/errors.js +19 -0
- package/dist/shared/log.js +45 -0
- package/{src/test.ts → dist/test.d.ts} +21 -22
- package/dist/test.js +51 -0
- package/package.json +70 -42
- package/dist/authorization/index.d.ts.map +0 -1
- package/dist/authorization/index.js.map +0 -1
- package/dist/client/core/types.d.ts.map +0 -1
- package/dist/client/index.d.ts.map +0 -1
- package/dist/client/index.js.map +0 -1
- package/dist/component/_generated/api.d.ts +0 -75
- package/dist/component/_generated/api.d.ts.map +0 -1
- package/dist/component/_generated/api.js.map +0 -1
- package/dist/component/_generated/component.d.ts.map +0 -1
- package/dist/component/_generated/dataModel.d.ts +0 -42
- package/dist/component/_generated/dataModel.d.ts.map +0 -1
- package/dist/component/_generated/server.d.ts +0 -117
- package/dist/component/_generated/server.d.ts.map +0 -1
- package/dist/component/_generated/server.js.map +0 -1
- package/dist/component/_virtual/rolldown_runtime.js +0 -18
- package/dist/component/client/core/types.d.ts +0 -2
- package/dist/component/client/index.d.ts +0 -1
- package/dist/component/convex.config.d.ts.map +0 -1
- package/dist/component/convex.config.js.map +0 -1
- package/dist/component/functions.d.ts +0 -25
- package/dist/component/functions.d.ts.map +0 -1
- package/dist/component/functions.js.map +0 -1
- package/dist/component/index.d.ts.map +0 -1
- package/dist/component/model.d.ts.map +0 -1
- package/dist/component/model.js.map +0 -1
- package/dist/component/providers/anonymous.d.ts +0 -54
- package/dist/component/providers/anonymous.d.ts.map +0 -1
- package/dist/component/providers/credentials.d.ts +0 -38
- package/dist/component/providers/credentials.d.ts.map +0 -1
- package/dist/component/providers/device.d.ts +0 -67
- package/dist/component/providers/device.d.ts.map +0 -1
- package/dist/component/providers/email.d.ts +0 -62
- package/dist/component/providers/email.d.ts.map +0 -1
- package/dist/component/providers/oauth.d.ts +0 -25
- package/dist/component/providers/oauth.d.ts.map +0 -1
- package/dist/component/providers/oauth.js +0 -13
- package/dist/component/providers/oauth.js.map +0 -1
- package/dist/component/providers/passkey.d.ts +0 -57
- package/dist/component/providers/passkey.d.ts.map +0 -1
- package/dist/component/providers/password.d.ts +0 -88
- package/dist/component/providers/password.d.ts.map +0 -1
- package/dist/component/providers/phone.d.ts +0 -48
- package/dist/component/providers/phone.d.ts.map +0 -1
- package/dist/component/providers/sso.d.ts +0 -50
- package/dist/component/providers/sso.d.ts.map +0 -1
- package/dist/component/providers/totp.d.ts +0 -45
- package/dist/component/providers/totp.d.ts.map +0 -1
- package/dist/component/public/enterprise/audit.d.ts +0 -73
- package/dist/component/public/enterprise/audit.d.ts.map +0 -1
- package/dist/component/public/enterprise/audit.js.map +0 -1
- package/dist/component/public/enterprise/core.d.ts +0 -176
- package/dist/component/public/enterprise/core.d.ts.map +0 -1
- package/dist/component/public/enterprise/core.js +0 -292
- package/dist/component/public/enterprise/core.js.map +0 -1
- package/dist/component/public/enterprise/domains.d.ts +0 -174
- package/dist/component/public/enterprise/domains.d.ts.map +0 -1
- package/dist/component/public/enterprise/domains.js +0 -271
- package/dist/component/public/enterprise/domains.js.map +0 -1
- package/dist/component/public/enterprise/scim.d.ts +0 -245
- package/dist/component/public/enterprise/scim.d.ts.map +0 -1
- package/dist/component/public/enterprise/scim.js.map +0 -1
- package/dist/component/public/enterprise/secrets.d.ts +0 -78
- package/dist/component/public/enterprise/secrets.d.ts.map +0 -1
- package/dist/component/public/enterprise/secrets.js +0 -118
- package/dist/component/public/enterprise/secrets.js.map +0 -1
- package/dist/component/public/enterprise/webhooks.d.ts +0 -211
- package/dist/component/public/enterprise/webhooks.d.ts.map +0 -1
- package/dist/component/public/enterprise/webhooks.js.map +0 -1
- package/dist/component/public/factors/devices.d.ts +0 -157
- package/dist/component/public/factors/devices.d.ts.map +0 -1
- package/dist/component/public/factors/devices.js.map +0 -1
- package/dist/component/public/factors/passkeys.d.ts +0 -175
- package/dist/component/public/factors/passkeys.d.ts.map +0 -1
- package/dist/component/public/factors/passkeys.js.map +0 -1
- package/dist/component/public/factors/totp.d.ts +0 -189
- package/dist/component/public/factors/totp.d.ts.map +0 -1
- package/dist/component/public/factors/totp.js.map +0 -1
- package/dist/component/public/groups/core.d.ts +0 -137
- package/dist/component/public/groups/core.d.ts.map +0 -1
- package/dist/component/public/groups/core.js.map +0 -1
- package/dist/component/public/groups/invites.d.ts +0 -217
- package/dist/component/public/groups/invites.d.ts.map +0 -1
- package/dist/component/public/groups/invites.js.map +0 -1
- package/dist/component/public/groups/members.d.ts +0 -204
- package/dist/component/public/groups/members.d.ts.map +0 -1
- package/dist/component/public/groups/members.js.map +0 -1
- package/dist/component/public/identity/accounts.d.ts +0 -147
- package/dist/component/public/identity/accounts.d.ts.map +0 -1
- package/dist/component/public/identity/accounts.js.map +0 -1
- package/dist/component/public/identity/codes.d.ts +0 -104
- package/dist/component/public/identity/codes.d.ts.map +0 -1
- package/dist/component/public/identity/codes.js.map +0 -1
- package/dist/component/public/identity/sessions.d.ts +0 -128
- package/dist/component/public/identity/sessions.d.ts.map +0 -1
- package/dist/component/public/identity/sessions.js.map +0 -1
- package/dist/component/public/identity/tokens.d.ts +0 -169
- package/dist/component/public/identity/tokens.d.ts.map +0 -1
- package/dist/component/public/identity/tokens.js.map +0 -1
- package/dist/component/public/identity/users.d.ts +0 -212
- package/dist/component/public/identity/users.d.ts.map +0 -1
- package/dist/component/public/identity/users.js.map +0 -1
- package/dist/component/public/identity/verifiers.d.ts +0 -116
- package/dist/component/public/identity/verifiers.d.ts.map +0 -1
- package/dist/component/public/identity/verifiers.js.map +0 -1
- package/dist/component/public/security/keys.d.ts +0 -209
- package/dist/component/public/security/keys.d.ts.map +0 -1
- package/dist/component/public/security/keys.js.map +0 -1
- package/dist/component/public/security/limits.d.ts +0 -114
- package/dist/component/public/security/limits.d.ts.map +0 -1
- package/dist/component/public/security/limits.js.map +0 -1
- package/dist/component/public.d.ts +0 -28
- package/dist/component/public.d.ts.map +0 -1
- package/dist/component/schema.d.ts.map +0 -1
- package/dist/component/schema.js.map +0 -1
- package/dist/component/server/auth.d.ts +0 -447
- package/dist/component/server/auth.d.ts.map +0 -1
- package/dist/component/server/auth.js +0 -254
- package/dist/component/server/auth.js.map +0 -1
- package/dist/component/server/config.js +0 -121
- package/dist/component/server/config.js.map +0 -1
- package/dist/component/server/context.js +0 -53
- package/dist/component/server/context.js.map +0 -1
- package/dist/component/server/cookies.js +0 -47
- package/dist/component/server/cookies.js.map +0 -1
- package/dist/component/server/core.js +0 -576
- package/dist/component/server/core.js.map +0 -1
- package/dist/component/server/crypto.js +0 -56
- package/dist/component/server/crypto.js.map +0 -1
- package/dist/component/server/db.js +0 -87
- package/dist/component/server/db.js.map +0 -1
- package/dist/component/server/device.js +0 -152
- package/dist/component/server/device.js.map +0 -1
- package/dist/component/server/enterprise/config.js +0 -46
- package/dist/component/server/enterprise/config.js.map +0 -1
- package/dist/component/server/enterprise/domain.js +0 -974
- package/dist/component/server/enterprise/domain.js.map +0 -1
- package/dist/component/server/enterprise/http.js +0 -787
- package/dist/component/server/enterprise/http.js.map +0 -1
- package/dist/component/server/enterprise/oidc.js +0 -248
- package/dist/component/server/enterprise/oidc.js.map +0 -1
- package/dist/component/server/enterprise/policy.js +0 -85
- package/dist/component/server/enterprise/policy.js.map +0 -1
- package/dist/component/server/enterprise/saml.js.map +0 -1
- package/dist/component/server/enterprise/scim.js.map +0 -1
- package/dist/component/server/enterprise/shared.js +0 -51
- package/dist/component/server/enterprise/shared.js.map +0 -1
- package/dist/component/server/http.d.ts +0 -85
- package/dist/component/server/http.d.ts.map +0 -1
- package/dist/component/server/http.js +0 -351
- package/dist/component/server/http.js.map +0 -1
- package/dist/component/server/identity.js +0 -16
- package/dist/component/server/identity.js.map +0 -1
- package/dist/component/server/keys.js +0 -96
- package/dist/component/server/keys.js.map +0 -1
- package/dist/component/server/limits.js +0 -52
- package/dist/component/server/limits.js.map +0 -1
- package/dist/component/server/mutations/account.js +0 -46
- package/dist/component/server/mutations/account.js.map +0 -1
- package/dist/component/server/mutations/code.js +0 -68
- package/dist/component/server/mutations/code.js.map +0 -1
- package/dist/component/server/mutations/invalidate.js +0 -32
- package/dist/component/server/mutations/invalidate.js.map +0 -1
- package/dist/component/server/mutations/oauth.js +0 -116
- package/dist/component/server/mutations/oauth.js.map +0 -1
- package/dist/component/server/mutations/refresh.js +0 -119
- package/dist/component/server/mutations/refresh.js.map +0 -1
- package/dist/component/server/mutations/register.js +0 -87
- package/dist/component/server/mutations/register.js.map +0 -1
- package/dist/component/server/mutations/retrieve.js +0 -61
- package/dist/component/server/mutations/retrieve.js.map +0 -1
- package/dist/component/server/mutations/signature.js +0 -38
- package/dist/component/server/mutations/signature.js.map +0 -1
- package/dist/component/server/mutations/signin.js +0 -27
- package/dist/component/server/mutations/signin.js.map +0 -1
- package/dist/component/server/mutations/signout.js +0 -27
- package/dist/component/server/mutations/signout.js.map +0 -1
- package/dist/component/server/mutations/store/refs.js +0 -15
- package/dist/component/server/mutations/store/refs.js.map +0 -1
- package/dist/component/server/mutations/store.js +0 -70
- package/dist/component/server/mutations/store.js.map +0 -1
- package/dist/component/server/mutations/verifier.js +0 -18
- package/dist/component/server/mutations/verifier.js.map +0 -1
- package/dist/component/server/mutations/verify.js +0 -98
- package/dist/component/server/mutations/verify.js.map +0 -1
- package/dist/component/server/oauth.js +0 -242
- package/dist/component/server/oauth.js.map +0 -1
- package/dist/component/server/passkey.js +0 -415
- package/dist/component/server/passkey.js.map +0 -1
- package/dist/component/server/redirects.js +0 -40
- package/dist/component/server/redirects.js.map +0 -1
- package/dist/component/server/refresh.js +0 -99
- package/dist/component/server/refresh.js.map +0 -1
- package/dist/component/server/runtime.d.ts +0 -136
- package/dist/component/server/runtime.d.ts.map +0 -1
- package/dist/component/server/runtime.js +0 -456
- package/dist/component/server/runtime.js.map +0 -1
- package/dist/component/server/sessions.js +0 -71
- package/dist/component/server/sessions.js.map +0 -1
- package/dist/component/server/signin.js +0 -225
- package/dist/component/server/signin.js.map +0 -1
- package/dist/component/server/tokens.js +0 -17
- package/dist/component/server/tokens.js.map +0 -1
- package/dist/component/server/totp.js +0 -208
- package/dist/component/server/totp.js.map +0 -1
- package/dist/component/server/types.d.ts +0 -949
- package/dist/component/server/types.d.ts.map +0 -1
- package/dist/component/server/types.js +0 -79
- package/dist/component/server/types.js.map +0 -1
- package/dist/component/server/users.js +0 -123
- package/dist/component/server/users.js.map +0 -1
- package/dist/component/server/utils.js +0 -140
- package/dist/component/server/utils.js.map +0 -1
- package/dist/core/types.d.ts +0 -361
- package/dist/core/types.d.ts.map +0 -1
- package/dist/factors/device.js +0 -104
- package/dist/factors/device.js.map +0 -1
- package/dist/factors/passkey.js.map +0 -1
- package/dist/factors/totp.js.map +0 -1
- package/dist/providers/anonymous.d.ts.map +0 -1
- package/dist/providers/anonymous.js.map +0 -1
- package/dist/providers/credentials.d.ts.map +0 -1
- package/dist/providers/credentials.js.map +0 -1
- package/dist/providers/device.d.ts.map +0 -1
- package/dist/providers/device.js.map +0 -1
- package/dist/providers/email.d.ts.map +0 -1
- package/dist/providers/email.js.map +0 -1
- package/dist/providers/oauth.d.ts +0 -69
- package/dist/providers/oauth.d.ts.map +0 -1
- package/dist/providers/oauth.js +0 -43
- package/dist/providers/oauth.js.map +0 -1
- package/dist/providers/passkey.d.ts.map +0 -1
- package/dist/providers/passkey.js.map +0 -1
- package/dist/providers/password.d.ts.map +0 -1
- package/dist/providers/password.js.map +0 -1
- package/dist/providers/phone.d.ts.map +0 -1
- package/dist/providers/phone.js.map +0 -1
- package/dist/providers/sso.d.ts.map +0 -1
- package/dist/providers/sso.js.map +0 -1
- package/dist/providers/totp.d.ts.map +0 -1
- package/dist/providers/totp.js.map +0 -1
- package/dist/runtime/browser.js +0 -68
- package/dist/runtime/browser.js.map +0 -1
- package/dist/runtime/invite.js.map +0 -1
- package/dist/runtime/proxy.js +0 -70
- package/dist/runtime/proxy.js.map +0 -1
- package/dist/runtime/storage.js +0 -37
- package/dist/runtime/storage.js.map +0 -1
- package/dist/server/auth.d.ts.map +0 -1
- package/dist/server/auth.js.map +0 -1
- package/dist/server/config.d.ts +0 -1
- package/dist/server/config.js.map +0 -1
- package/dist/server/context.d.ts +0 -1
- package/dist/server/context.js.map +0 -1
- package/dist/server/cookies.d.ts +0 -1
- package/dist/server/cookies.js.map +0 -1
- package/dist/server/core.d.ts +0 -1315
- package/dist/server/core.d.ts.map +0 -1
- package/dist/server/core.js.map +0 -1
- package/dist/server/crypto.d.ts +0 -8
- package/dist/server/crypto.d.ts.map +0 -1
- package/dist/server/crypto.js.map +0 -1
- package/dist/server/db.d.ts +0 -1
- package/dist/server/db.js.map +0 -1
- package/dist/server/device.d.ts +0 -1
- package/dist/server/device.js.map +0 -1
- package/dist/server/enterprise/config.d.ts +0 -1
- package/dist/server/enterprise/config.js.map +0 -1
- package/dist/server/enterprise/domain.d.ts +0 -401
- package/dist/server/enterprise/domain.d.ts.map +0 -1
- package/dist/server/enterprise/domain.js +0 -974
- package/dist/server/enterprise/domain.js.map +0 -1
- package/dist/server/enterprise/http.d.ts +0 -26
- package/dist/server/enterprise/http.d.ts.map +0 -1
- package/dist/server/enterprise/http.js +0 -787
- package/dist/server/enterprise/http.js.map +0 -1
- package/dist/server/enterprise/oidc.d.ts +0 -1
- package/dist/server/enterprise/oidc.js +0 -248
- package/dist/server/enterprise/oidc.js.map +0 -1
- package/dist/server/enterprise/policy.d.ts +0 -1
- package/dist/server/enterprise/policy.js +0 -85
- package/dist/server/enterprise/policy.js.map +0 -1
- package/dist/server/enterprise/saml.d.ts +0 -1
- package/dist/server/enterprise/saml.js +0 -338
- package/dist/server/enterprise/saml.js.map +0 -1
- package/dist/server/enterprise/scim.d.ts +0 -1
- package/dist/server/enterprise/scim.js +0 -97
- package/dist/server/enterprise/scim.js.map +0 -1
- package/dist/server/enterprise/shared.d.ts +0 -5
- package/dist/server/enterprise/shared.d.ts.map +0 -1
- package/dist/server/enterprise/shared.js +0 -51
- package/dist/server/enterprise/shared.js.map +0 -1
- package/dist/server/enterprise/validators.d.ts +0 -1
- package/dist/server/enterprise/validators.js +0 -60
- package/dist/server/enterprise/validators.js.map +0 -1
- package/dist/server/http.d.ts.map +0 -1
- package/dist/server/http.js.map +0 -1
- package/dist/server/identity.d.ts +0 -1
- package/dist/server/identity.js.map +0 -1
- package/dist/server/keys.d.ts +0 -1
- package/dist/server/keys.js.map +0 -1
- package/dist/server/limits.d.ts +0 -1
- package/dist/server/limits.js.map +0 -1
- package/dist/server/mounts.d.ts.map +0 -1
- package/dist/server/mounts.js.map +0 -1
- package/dist/server/mutations/account.d.ts +0 -29
- package/dist/server/mutations/account.d.ts.map +0 -1
- package/dist/server/mutations/account.js.map +0 -1
- package/dist/server/mutations/code.d.ts +0 -30
- package/dist/server/mutations/code.d.ts.map +0 -1
- package/dist/server/mutations/code.js.map +0 -1
- package/dist/server/mutations/index.d.ts +0 -14
- package/dist/server/mutations/invalidate.d.ts +0 -20
- package/dist/server/mutations/invalidate.d.ts.map +0 -1
- package/dist/server/mutations/invalidate.js.map +0 -1
- package/dist/server/mutations/oauth.d.ts +0 -30
- package/dist/server/mutations/oauth.d.ts.map +0 -1
- package/dist/server/mutations/oauth.js.map +0 -1
- package/dist/server/mutations/refresh.d.ts +0 -21
- package/dist/server/mutations/refresh.d.ts.map +0 -1
- package/dist/server/mutations/refresh.js.map +0 -1
- package/dist/server/mutations/register.d.ts +0 -38
- package/dist/server/mutations/register.d.ts.map +0 -1
- package/dist/server/mutations/register.js.map +0 -1
- package/dist/server/mutations/retrieve.d.ts +0 -33
- package/dist/server/mutations/retrieve.d.ts.map +0 -1
- package/dist/server/mutations/retrieve.js.map +0 -1
- package/dist/server/mutations/signature.d.ts +0 -21
- package/dist/server/mutations/signature.d.ts.map +0 -1
- package/dist/server/mutations/signature.js.map +0 -1
- package/dist/server/mutations/signin.d.ts +0 -22
- package/dist/server/mutations/signin.d.ts.map +0 -1
- package/dist/server/mutations/signin.js.map +0 -1
- package/dist/server/mutations/signout.d.ts +0 -16
- package/dist/server/mutations/signout.d.ts.map +0 -1
- package/dist/server/mutations/signout.js.map +0 -1
- package/dist/server/mutations/store/refs.d.ts +0 -12
- package/dist/server/mutations/store/refs.d.ts.map +0 -1
- package/dist/server/mutations/store/refs.js.map +0 -1
- package/dist/server/mutations/store.d.ts +0 -306
- package/dist/server/mutations/store.d.ts.map +0 -1
- package/dist/server/mutations/store.js.map +0 -1
- package/dist/server/mutations/verifier.d.ts +0 -13
- package/dist/server/mutations/verifier.d.ts.map +0 -1
- package/dist/server/mutations/verifier.js.map +0 -1
- package/dist/server/mutations/verify.d.ts +0 -26
- package/dist/server/mutations/verify.d.ts.map +0 -1
- package/dist/server/mutations/verify.js.map +0 -1
- package/dist/server/oauth.d.ts +0 -1
- package/dist/server/oauth.js +0 -242
- package/dist/server/oauth.js.map +0 -1
- package/dist/server/passkey.d.ts +0 -27
- package/dist/server/passkey.d.ts.map +0 -1
- package/dist/server/passkey.js.map +0 -1
- package/dist/server/redirects.d.ts +0 -1
- package/dist/server/redirects.js.map +0 -1
- package/dist/server/refresh.d.ts +0 -1
- package/dist/server/refresh.js.map +0 -1
- package/dist/server/runtime.d.ts.map +0 -1
- package/dist/server/runtime.js.map +0 -1
- package/dist/server/sessions.d.ts +0 -1
- package/dist/server/sessions.js.map +0 -1
- package/dist/server/signin.d.ts +0 -1
- package/dist/server/signin.js.map +0 -1
- package/dist/server/ssr.d.ts.map +0 -1
- package/dist/server/ssr.js +0 -777
- package/dist/server/ssr.js.map +0 -1
- package/dist/server/templates.d.ts +0 -1
- package/dist/server/templates.js.map +0 -1
- package/dist/server/tokens.d.ts +0 -1
- package/dist/server/tokens.js.map +0 -1
- package/dist/server/totp.d.ts +0 -1
- package/dist/server/totp.js.map +0 -1
- package/dist/server/types.d.ts.map +0 -1
- package/dist/server/types.js.map +0 -1
- package/dist/server/users.d.ts +0 -1
- package/dist/server/users.js.map +0 -1
- package/dist/server/utils.d.ts +0 -1
- package/dist/server/utils.js +0 -140
- package/dist/server/utils.js.map +0 -1
- package/src/authorization/index.ts +0 -83
- package/src/cli/bin.ts +0 -5
- package/src/cli/command.ts +0 -70
- package/src/cli/index.ts +0 -1112
- package/src/cli/keys.ts +0 -23
- package/src/client/core/types.ts +0 -437
- package/src/client/factors/device.ts +0 -158
- package/src/client/factors/passkey.ts +0 -279
- package/src/client/factors/totp.ts +0 -150
- package/src/client/index.ts +0 -1124
- package/src/client/runtime/browser.ts +0 -112
- package/src/client/runtime/invite.ts +0 -63
- package/src/client/runtime/proxy.ts +0 -111
- package/src/client/runtime/storage.ts +0 -79
- package/src/component/_generated/api.ts +0 -96
- package/src/component/_generated/component.ts +0 -3774
- package/src/component/_generated/dataModel.ts +0 -60
- package/src/component/_generated/server.ts +0 -156
- package/src/component/convex.config.ts +0 -5
- package/src/component/functions.ts +0 -104
- package/src/component/index.ts +0 -42
- package/src/component/model.ts +0 -449
- package/src/component/public/enterprise/audit.ts +0 -125
- package/src/component/public/enterprise/core.ts +0 -355
- package/src/component/public/enterprise/domains.ts +0 -327
- package/src/component/public/enterprise/scim.ts +0 -397
- package/src/component/public/enterprise/secrets.ts +0 -133
- package/src/component/public/enterprise/webhooks.ts +0 -307
- package/src/component/public/factors/devices.ts +0 -224
- package/src/component/public/factors/passkeys.ts +0 -243
- package/src/component/public/factors/totp.ts +0 -259
- package/src/component/public/groups/core.ts +0 -481
- package/src/component/public/groups/invites.ts +0 -608
- package/src/component/public/groups/members.ts +0 -410
- package/src/component/public/identity/accounts.ts +0 -207
- package/src/component/public/identity/codes.ts +0 -149
- package/src/component/public/identity/sessions.ts +0 -210
- package/src/component/public/identity/tokens.ts +0 -251
- package/src/component/public/identity/users.ts +0 -355
- package/src/component/public/identity/verifiers.ts +0 -158
- package/src/component/public/security/keys.ts +0 -366
- package/src/component/public/security/limits.ts +0 -174
- package/src/component/public.ts +0 -27
- package/src/component/schema.ts +0 -505
- package/src/providers/anonymous.ts +0 -99
- package/src/providers/credentials.ts +0 -102
- package/src/providers/device.ts +0 -87
- package/src/providers/email.ts +0 -99
- package/src/providers/index.ts +0 -31
- package/src/providers/oauth.ts +0 -117
- package/src/providers/passkey.ts +0 -77
- package/src/providers/password.ts +0 -441
- package/src/providers/phone.ts +0 -93
- package/src/providers/sso.ts +0 -54
- package/src/providers/totp.ts +0 -62
- package/src/samlify.d.ts +0 -53
- package/src/server/auth.ts +0 -949
- package/src/server/config.ts +0 -200
- package/src/server/context.ts +0 -90
- package/src/server/cookies.ts +0 -49
- package/src/server/core.ts +0 -2004
- package/src/server/crypto.ts +0 -90
- package/src/server/db.ts +0 -203
- package/src/server/device.ts +0 -254
- package/src/server/enterprise/config.ts +0 -51
- package/src/server/enterprise/domain.ts +0 -1739
- package/src/server/enterprise/http.ts +0 -1331
- package/src/server/enterprise/oidc.ts +0 -500
- package/src/server/enterprise/policy.ts +0 -128
- package/src/server/enterprise/saml.ts +0 -578
- package/src/server/enterprise/scim.ts +0 -135
- package/src/server/enterprise/shared.ts +0 -134
- package/src/server/enterprise/validators.ts +0 -93
- package/src/server/http.ts +0 -790
- package/src/server/identity.ts +0 -18
- package/src/server/index.ts +0 -40
- package/src/server/keys.ts +0 -158
- package/src/server/limits.ts +0 -107
- package/src/server/mounts.ts +0 -924
- package/src/server/mutations/account.ts +0 -62
- package/src/server/mutations/code.ts +0 -119
- package/src/server/mutations/index.ts +0 -13
- package/src/server/mutations/invalidate.ts +0 -50
- package/src/server/mutations/oauth.ts +0 -243
- package/src/server/mutations/refresh.ts +0 -299
- package/src/server/mutations/register.ts +0 -155
- package/src/server/mutations/retrieve.ts +0 -109
- package/src/server/mutations/signature.ts +0 -57
- package/src/server/mutations/signin.ts +0 -54
- package/src/server/mutations/signout.ts +0 -43
- package/src/server/mutations/store/refs.ts +0 -10
- package/src/server/mutations/store.ts +0 -123
- package/src/server/mutations/verifier.ts +0 -34
- package/src/server/mutations/verify.ts +0 -200
- package/src/server/oauth.ts +0 -418
- package/src/server/passkey.ts +0 -838
- package/src/server/redirects.ts +0 -59
- package/src/server/refresh.ts +0 -218
- package/src/server/runtime.ts +0 -918
- package/src/server/sessions.ts +0 -132
- package/src/server/signin.ts +0 -445
- package/src/server/ssr.ts +0 -1747
- package/src/server/templates.ts +0 -82
- package/src/server/tokens.ts +0 -35
- package/src/server/totp.ts +0 -399
- package/src/server/types.ts +0 -1942
- package/src/server/users.ts +0 -291
- package/src/server/utils.ts +0 -220
- /package/dist/{runtime → client/runtime}/invite.js +0 -0
package/src/server/types.ts
DELETED
|
@@ -1,1942 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
AnyDataModel,
|
|
3
|
-
DataModelFromSchemaDefinition,
|
|
4
|
-
DocumentByName,
|
|
5
|
-
FunctionReference,
|
|
6
|
-
GenericActionCtx,
|
|
7
|
-
GenericDataModel,
|
|
8
|
-
GenericMutationCtx,
|
|
9
|
-
GenericQueryCtx,
|
|
10
|
-
RegisteredAction,
|
|
11
|
-
RegisteredMutation,
|
|
12
|
-
RegisteredQuery,
|
|
13
|
-
TableNamesInDataModel,
|
|
14
|
-
} from "convex/server";
|
|
15
|
-
import type { Infer } from "convex/values";
|
|
16
|
-
import { GenericId, Value } from "convex/values";
|
|
17
|
-
|
|
18
|
-
import {
|
|
19
|
-
vApiKeyDoc,
|
|
20
|
-
vAuthVerifierDoc,
|
|
21
|
-
vDeviceCodeDoc,
|
|
22
|
-
vPasskeyDoc,
|
|
23
|
-
vTotpFactorDoc,
|
|
24
|
-
vUserDoc,
|
|
25
|
-
} from "../component/model";
|
|
26
|
-
import schema from "../component/schema";
|
|
27
|
-
import type { CredentialsConfig } from "../providers/credentials";
|
|
28
|
-
|
|
29
|
-
// ============================================================================
|
|
30
|
-
// Utility types
|
|
31
|
-
// ============================================================================
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* A value that is either `T` or a `PromiseLike<T>`.
|
|
35
|
-
*
|
|
36
|
-
* @typeParam T - The underlying value type.
|
|
37
|
-
*/
|
|
38
|
-
export type Awaitable<T> = T | PromiseLike<T>;
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* A single role definition within the authorization config.
|
|
42
|
-
*
|
|
43
|
-
* Each role has an optional human-readable label and a list of grant strings
|
|
44
|
-
* that members with this role receive.
|
|
45
|
-
*
|
|
46
|
-
* @see {@link AuthAuthorizationConfig}
|
|
47
|
-
*/
|
|
48
|
-
export type AuthRoleDefinition = {
|
|
49
|
-
/** Optional stable identifier (defaults to the record key). */
|
|
50
|
-
id?: string;
|
|
51
|
-
/** Human-readable label for admin UIs. */
|
|
52
|
-
label?: string;
|
|
53
|
-
/** Permission grant strings conferred by this role. */
|
|
54
|
-
grants: string[];
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Authorization configuration mapping role IDs to {@link AuthRoleDefinition}s.
|
|
59
|
-
*
|
|
60
|
-
* Passed as `authorization.roles` in {@link ConvexAuthConfig}.
|
|
61
|
-
*
|
|
62
|
-
* @see {@link AuthRoleDefinition}
|
|
63
|
-
* @see {@link ConvexAuthConfig}
|
|
64
|
-
*/
|
|
65
|
-
export type AuthAuthorizationConfig = {
|
|
66
|
-
roles: Record<string, AuthRoleDefinition>;
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Extracts the union of role ID strings from an authorization config.
|
|
71
|
-
*
|
|
72
|
-
* When `TAuthorization` is defined, this resolves to the literal key union
|
|
73
|
-
* of the `roles` record. Otherwise falls back to `string`.
|
|
74
|
-
*
|
|
75
|
-
* @typeParam TAuthorization - The authorization config type, or `undefined`.
|
|
76
|
-
*
|
|
77
|
-
* @see {@link AuthGrant}
|
|
78
|
-
*/
|
|
79
|
-
export type AuthRoleId<
|
|
80
|
-
TAuthorization extends AuthAuthorizationConfig | undefined,
|
|
81
|
-
> = TAuthorization extends { roles: infer TRoles extends Record<string, any> }
|
|
82
|
-
? keyof TRoles & string
|
|
83
|
-
: string;
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Extracts the union of grant strings from all roles in an authorization config.
|
|
87
|
-
*
|
|
88
|
-
* When `TAuthorization` is defined, this resolves to the literal union
|
|
89
|
-
* of all `grants` array elements across every role. Otherwise falls back to `string`.
|
|
90
|
-
*
|
|
91
|
-
* @typeParam TAuthorization - The authorization config type, or `undefined`.
|
|
92
|
-
*
|
|
93
|
-
* @see {@link AuthRoleId}
|
|
94
|
-
*/
|
|
95
|
-
export type AuthGrant<
|
|
96
|
-
TAuthorization extends AuthAuthorizationConfig | undefined,
|
|
97
|
-
> = TAuthorization extends {
|
|
98
|
-
roles: infer TRoles extends Record<string, { grants: readonly any[] }>;
|
|
99
|
-
}
|
|
100
|
-
? TRoles[keyof TRoles]["grants"][number] & string
|
|
101
|
-
: string;
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* The config for the Convex Auth library, passed to `createAuth`.
|
|
105
|
-
*/
|
|
106
|
-
export type ConvexAuthConfig = {
|
|
107
|
-
/**
|
|
108
|
-
* A list of authentication provider configs.
|
|
109
|
-
*
|
|
110
|
-
* You can import existing configs from
|
|
111
|
-
* `@robelest/convex-auth/providers/<provider-name>`
|
|
112
|
-
*/
|
|
113
|
-
providers: AuthProviderConfig[];
|
|
114
|
-
/**
|
|
115
|
-
* Auth component reference from `components.auth`.
|
|
116
|
-
*
|
|
117
|
-
* Core auth storage operations are executed through
|
|
118
|
-
* the component API boundary.
|
|
119
|
-
*/
|
|
120
|
-
component: AuthComponentApi;
|
|
121
|
-
/**
|
|
122
|
-
* Session configuration.
|
|
123
|
-
*/
|
|
124
|
-
session?: {
|
|
125
|
-
/**
|
|
126
|
-
* How long can a user session last without the user reauthenticating.
|
|
127
|
-
*
|
|
128
|
-
* Defaults to 30 days.
|
|
129
|
-
*
|
|
130
|
-
* @defaultValue 2_592_000_000
|
|
131
|
-
*/
|
|
132
|
-
totalDurationMs?: number;
|
|
133
|
-
/**
|
|
134
|
-
* How long can a user session last without the user being active.
|
|
135
|
-
*
|
|
136
|
-
* Defaults to 30 days.
|
|
137
|
-
*
|
|
138
|
-
* @defaultValue 2_592_000_000
|
|
139
|
-
*/
|
|
140
|
-
inactiveDurationMs?: number;
|
|
141
|
-
};
|
|
142
|
-
/**
|
|
143
|
-
* JWT configuration.
|
|
144
|
-
*/
|
|
145
|
-
jwt?: {
|
|
146
|
-
/**
|
|
147
|
-
* How long is the JWT valid for after it is signed initially.
|
|
148
|
-
*
|
|
149
|
-
* Defaults to 1 hour.
|
|
150
|
-
*
|
|
151
|
-
* @defaultValue 3_600_000
|
|
152
|
-
*/
|
|
153
|
-
durationMs?: number;
|
|
154
|
-
};
|
|
155
|
-
/**
|
|
156
|
-
* Sign-in configuration.
|
|
157
|
-
*/
|
|
158
|
-
signIn?: {
|
|
159
|
-
/**
|
|
160
|
-
* How many times can the user fail to provide the correct credentials
|
|
161
|
-
* (password, OTP) per hour.
|
|
162
|
-
*
|
|
163
|
-
* Defaults to 10 times per hour (that is 10 failed attempts, and then
|
|
164
|
-
* allow another one every 6 minutes).
|
|
165
|
-
*
|
|
166
|
-
* @defaultValue 10
|
|
167
|
-
*/
|
|
168
|
-
maxFailedAttemptsPerHour?: number;
|
|
169
|
-
};
|
|
170
|
-
/**
|
|
171
|
-
* Lifecycle callbacks for customizing sign-in behavior.
|
|
172
|
-
*
|
|
173
|
-
* Use `redirect` to control post-OAuth redirect URLs, and
|
|
174
|
-
* `createOrUpdateUser` or `afterUserCreatedOrUpdated` to
|
|
175
|
-
* customize account linking and user document creation.
|
|
176
|
-
*/
|
|
177
|
-
callbacks?: {
|
|
178
|
-
/**
|
|
179
|
-
* Control which URLs are allowed as a destination after OAuth sign-in
|
|
180
|
-
* and for magic links:
|
|
181
|
-
*
|
|
182
|
-
* ```ts
|
|
183
|
-
* import { createAuth } from "@robelest/convex-auth/component";
|
|
184
|
-
* import { components } from "./_generated/api";
|
|
185
|
-
*
|
|
186
|
-
* const auth = createAuth(components.auth, {
|
|
187
|
-
* providers: [google],
|
|
188
|
-
* callbacks: {
|
|
189
|
-
* async redirect({ redirectTo }) {
|
|
190
|
-
* // Check that redirectTo is valid
|
|
191
|
-
* // and return the relative or absolute URL
|
|
192
|
-
* // to redirect to.
|
|
193
|
-
* },
|
|
194
|
-
* },
|
|
195
|
-
* });
|
|
196
|
-
* ```
|
|
197
|
-
*
|
|
198
|
-
* Convex Auth performs redirect only during OAuth sign-in. By default,
|
|
199
|
-
* it redirects back to the URL specified via the `SITE_URL` environment
|
|
200
|
-
* variable. Similarly magic links link to `SITE_URL`. Additional frontend
|
|
201
|
-
* origins can be listed in `SECONDARY_URL` for flows like passkeys.
|
|
202
|
-
*
|
|
203
|
-
* You can customize that behavior by providing a `redirectTo` param
|
|
204
|
-
* to the `signIn` function:
|
|
205
|
-
*
|
|
206
|
-
* ```ts
|
|
207
|
-
* signIn("google", { redirectTo: "/dashboard" })
|
|
208
|
-
* ```
|
|
209
|
-
*
|
|
210
|
-
* You can even redirect to a different site.
|
|
211
|
-
*
|
|
212
|
-
* This callback, if specified, is then called with the provided
|
|
213
|
-
* `redirectTo` param. Otherwise, only query params, relative paths
|
|
214
|
-
* and URLs starting with `SITE_URL` are allowed.
|
|
215
|
-
*/
|
|
216
|
-
redirect?: (params: {
|
|
217
|
-
/**
|
|
218
|
-
* The param value passed to the `signIn` function.
|
|
219
|
-
*/
|
|
220
|
-
redirectTo: string;
|
|
221
|
-
}) => Promise<string>;
|
|
222
|
-
/**
|
|
223
|
-
* Completely control account linking via this callback.
|
|
224
|
-
*
|
|
225
|
-
* This callback is called during the sign-in process,
|
|
226
|
-
* before account creation and token generation.
|
|
227
|
-
* If specified, this callback is responsible for creating
|
|
228
|
-
* or updating the user document.
|
|
229
|
-
*
|
|
230
|
-
* For "credentials" providers, the callback is only called
|
|
231
|
-
* when `createAccount` is called.
|
|
232
|
-
*/
|
|
233
|
-
createOrUpdateUser?: (
|
|
234
|
-
ctx: GenericMutationCtx<AnyDataModel>,
|
|
235
|
-
args: {
|
|
236
|
-
/**
|
|
237
|
-
* If this is a sign-in to an existing account,
|
|
238
|
-
* this is the existing user ID linked to that account.
|
|
239
|
-
*/
|
|
240
|
-
existingUserId: GenericId<"User"> | null;
|
|
241
|
-
/**
|
|
242
|
-
* The provider type or "verification" if this callback is called
|
|
243
|
-
* after an email or phone token verification.
|
|
244
|
-
*/
|
|
245
|
-
type: "oauth" | "credentials" | "email" | "phone" | "verification";
|
|
246
|
-
/**
|
|
247
|
-
* The provider used for the sign-in, or the provider
|
|
248
|
-
* tied to the account which is having the email or phone verified.
|
|
249
|
-
*/
|
|
250
|
-
provider: AuthProviderMaterializedConfig;
|
|
251
|
-
/**
|
|
252
|
-
* - The profile returned by the OAuth provider's `profile` method.
|
|
253
|
-
* - The profile passed to `createAccount` from a ConvexCredentials
|
|
254
|
-
* config.
|
|
255
|
-
* - The email address to which an email will be sent.
|
|
256
|
-
* - The phone number to which a text will be sent.
|
|
257
|
-
*/
|
|
258
|
-
profile: Record<string, unknown> & {
|
|
259
|
-
email?: string;
|
|
260
|
-
phone?: string;
|
|
261
|
-
emailVerified?: boolean;
|
|
262
|
-
phoneVerified?: boolean;
|
|
263
|
-
};
|
|
264
|
-
/**
|
|
265
|
-
* The `shouldLink` argument passed to `createAccount`.
|
|
266
|
-
*/
|
|
267
|
-
shouldLink?: boolean;
|
|
268
|
-
},
|
|
269
|
-
) => Promise<GenericId<"User">>;
|
|
270
|
-
/**
|
|
271
|
-
* Perform additional writes after a user is created.
|
|
272
|
-
*
|
|
273
|
-
* This callback is called during the sign-in process,
|
|
274
|
-
* after the user is created or updated,
|
|
275
|
-
* before account creation and token generation.
|
|
276
|
-
*
|
|
277
|
-
* **This callback is only called if `createOrUpdateUser`
|
|
278
|
-
* is not specified.** If `createOrUpdateUser` is specified,
|
|
279
|
-
* you can perform any additional writes in that callback.
|
|
280
|
-
*
|
|
281
|
-
* For "credentials" providers, the callback is only called
|
|
282
|
-
* when `createAccount` is called.
|
|
283
|
-
*/
|
|
284
|
-
afterUserCreatedOrUpdated?: (
|
|
285
|
-
ctx: GenericMutationCtx<AnyDataModel>,
|
|
286
|
-
args: {
|
|
287
|
-
/**
|
|
288
|
-
* The ID of the user that is being signed in.
|
|
289
|
-
*/
|
|
290
|
-
userId: GenericId<"User">;
|
|
291
|
-
/**
|
|
292
|
-
* If this is a sign-in to an existing account,
|
|
293
|
-
* this is the existing user ID linked to that account.
|
|
294
|
-
*/
|
|
295
|
-
existingUserId: GenericId<"User"> | null;
|
|
296
|
-
/**
|
|
297
|
-
* The provider type or "verification" if this callback is called
|
|
298
|
-
* after an email or phone token verification.
|
|
299
|
-
*/
|
|
300
|
-
type: "oauth" | "credentials" | "email" | "phone" | "verification";
|
|
301
|
-
/**
|
|
302
|
-
* The provider used for the sign-in, or the provider
|
|
303
|
-
* tied to the account which is having the email or phone verified.
|
|
304
|
-
*/
|
|
305
|
-
provider: AuthProviderMaterializedConfig;
|
|
306
|
-
/**
|
|
307
|
-
* - The profile returned by the OAuth provider's `profile` method.
|
|
308
|
-
* - The profile passed to `createAccount` from a ConvexCredentials
|
|
309
|
-
* config.
|
|
310
|
-
* - The email address to which an email will be sent.
|
|
311
|
-
* - The phone number to which a text will be sent.
|
|
312
|
-
*/
|
|
313
|
-
profile: Record<string, unknown> & {
|
|
314
|
-
email?: string;
|
|
315
|
-
phone?: string;
|
|
316
|
-
emailVerified?: boolean;
|
|
317
|
-
phoneVerified?: boolean;
|
|
318
|
-
};
|
|
319
|
-
/**
|
|
320
|
-
* The `shouldLink` argument passed to `createAccount`.
|
|
321
|
-
*/
|
|
322
|
-
shouldLink?: boolean;
|
|
323
|
-
},
|
|
324
|
-
) => Promise<void>;
|
|
325
|
-
};
|
|
326
|
-
/**
|
|
327
|
-
* Application-defined role and grant model used by membership access checks.
|
|
328
|
-
*/
|
|
329
|
-
authorization?: {
|
|
330
|
-
roles: Record<
|
|
331
|
-
string,
|
|
332
|
-
{
|
|
333
|
-
label?: string;
|
|
334
|
-
grants: string[];
|
|
335
|
-
}
|
|
336
|
-
>;
|
|
337
|
-
};
|
|
338
|
-
};
|
|
339
|
-
|
|
340
|
-
/**
|
|
341
|
-
* Union of all supported auth provider config types.
|
|
342
|
-
*
|
|
343
|
-
* Includes Arctic-based OAuth providers (via the `OAuth()` factory),
|
|
344
|
-
* plus library-native providers: credentials, email, phone, passkey
|
|
345
|
-
* (WebAuthn), and TOTP (2FA). Each can be passed as a config object
|
|
346
|
-
* or a factory function.
|
|
347
|
-
*/
|
|
348
|
-
export type AuthProviderConfig =
|
|
349
|
-
| import("../providers/oauth").OAuthProviderInstance
|
|
350
|
-
| import("../providers/password").Password
|
|
351
|
-
| import("../providers/passkey").Passkey
|
|
352
|
-
| import("../providers/totp").Totp
|
|
353
|
-
| import("../providers/anonymous").Anonymous
|
|
354
|
-
| import("../providers/device").Device
|
|
355
|
-
| import("../providers/sso").SSO
|
|
356
|
-
| import("../providers/email").Email
|
|
357
|
-
| import("../providers/phone").Phone
|
|
358
|
-
| OAuthMaterializedConfig
|
|
359
|
-
| ConvexCredentialsConfig
|
|
360
|
-
| ((...args: any) => ConvexCredentialsConfig)
|
|
361
|
-
| EmailConfig
|
|
362
|
-
| ((...args: any) => EmailConfig)
|
|
363
|
-
| PhoneConfig
|
|
364
|
-
| ((...args: any) => PhoneConfig)
|
|
365
|
-
| PasskeyProviderConfig
|
|
366
|
-
| ((...args: any) => PasskeyProviderConfig)
|
|
367
|
-
| TotpProviderConfig
|
|
368
|
-
| ((...args: any) => TotpProviderConfig)
|
|
369
|
-
| DeviceProviderConfig
|
|
370
|
-
| ((...args: any) => DeviceProviderConfig)
|
|
371
|
-
| SSOProviderConfig;
|
|
372
|
-
|
|
373
|
-
/**
|
|
374
|
-
* Minimal config stored for the SSO provider at runtime.
|
|
375
|
-
* No options — enterprise configuration is entirely per-tenant runtime state.
|
|
376
|
-
*/
|
|
377
|
-
export interface SSOProviderConfig {
|
|
378
|
-
id: string;
|
|
379
|
-
type: "sso";
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
/**
|
|
383
|
-
* Account linking strategy for enterprise SSO sign-in.
|
|
384
|
-
*
|
|
385
|
-
* - `"verifiedEmail"` — link accounts when the IdP-provided email matches a verified email on an existing user.
|
|
386
|
-
* - `"none"` — never auto-link; always create a new account.
|
|
387
|
-
*/
|
|
388
|
-
export type EnterpriseAccountLinkingPolicy = "verifiedEmail" | "none";
|
|
389
|
-
|
|
390
|
-
/**
|
|
391
|
-
* Policy for reusing existing users during SCIM provisioning.
|
|
392
|
-
*
|
|
393
|
-
* - `"externalId"` — match by the SCIM `externalId` to reuse a previously provisioned user.
|
|
394
|
-
* - `"none"` — always create a new user for each SCIM provision request.
|
|
395
|
-
*/
|
|
396
|
-
export type EnterpriseScimReuseUserPolicy = "externalId" | "none";
|
|
397
|
-
|
|
398
|
-
/**
|
|
399
|
-
* Just-in-time provisioning mode for enterprise SSO.
|
|
400
|
-
*
|
|
401
|
-
* - `"off"` — no JIT provisioning; users must be pre-provisioned.
|
|
402
|
-
* - `"createUser"` — create a user record on first SSO sign-in.
|
|
403
|
-
* - `"createUserAndMembership"` — create a user and add them to the enterprise group on first SSO sign-in.
|
|
404
|
-
*/
|
|
405
|
-
export type EnterpriseJitProvisioningMode =
|
|
406
|
-
| "off"
|
|
407
|
-
| "createUser"
|
|
408
|
-
| "createUserAndMembership";
|
|
409
|
-
|
|
410
|
-
/**
|
|
411
|
-
* Deprovisioning strategy when a SCIM user is deleted.
|
|
412
|
-
*
|
|
413
|
-
* - `"soft"` — mark the user as inactive but preserve the record.
|
|
414
|
-
* - `"hard"` — permanently delete the user and associated data.
|
|
415
|
-
*/
|
|
416
|
-
export type EnterpriseDeprovisionMode = "soft" | "hard";
|
|
417
|
-
|
|
418
|
-
/**
|
|
419
|
-
* Effective enterprise policy document stored for an SSO/SCIM tenant.
|
|
420
|
-
*
|
|
421
|
-
* Controls account linking, JIT provisioning, SCIM reuse behavior,
|
|
422
|
-
* deprovisioning, and any app-defined extension metadata.
|
|
423
|
-
*
|
|
424
|
-
* @see {@link EnterprisePolicyPatch}
|
|
425
|
-
*/
|
|
426
|
-
export interface EnterprisePolicy {
|
|
427
|
-
version: 1;
|
|
428
|
-
identity: {
|
|
429
|
-
accountLinking: {
|
|
430
|
-
oidc: EnterpriseAccountLinkingPolicy;
|
|
431
|
-
saml: EnterpriseAccountLinkingPolicy;
|
|
432
|
-
};
|
|
433
|
-
};
|
|
434
|
-
provisioning: {
|
|
435
|
-
scimReuse: {
|
|
436
|
-
user: EnterpriseScimReuseUserPolicy;
|
|
437
|
-
};
|
|
438
|
-
jit: {
|
|
439
|
-
mode: EnterpriseJitProvisioningMode;
|
|
440
|
-
defaultRoleIds: string[];
|
|
441
|
-
};
|
|
442
|
-
deprovision: {
|
|
443
|
-
mode: EnterpriseDeprovisionMode;
|
|
444
|
-
};
|
|
445
|
-
};
|
|
446
|
-
extend?: Record<string, unknown>;
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
/**
|
|
450
|
-
* Partial update payload for {@link EnterprisePolicy}.
|
|
451
|
-
*
|
|
452
|
-
* Use this when patching only selected enterprise policy sections without
|
|
453
|
-
* replacing the entire stored policy document.
|
|
454
|
-
*/
|
|
455
|
-
export interface EnterprisePolicyPatch {
|
|
456
|
-
identity?: {
|
|
457
|
-
accountLinking?: {
|
|
458
|
-
oidc?: EnterpriseAccountLinkingPolicy;
|
|
459
|
-
saml?: EnterpriseAccountLinkingPolicy;
|
|
460
|
-
};
|
|
461
|
-
};
|
|
462
|
-
provisioning?: {
|
|
463
|
-
scimReuse?: {
|
|
464
|
-
user?: EnterpriseScimReuseUserPolicy;
|
|
465
|
-
};
|
|
466
|
-
jit?: {
|
|
467
|
-
mode?: EnterpriseJitProvisioningMode;
|
|
468
|
-
defaultRoleIds?: string[];
|
|
469
|
-
};
|
|
470
|
-
deprovision?: {
|
|
471
|
-
mode?: EnterpriseDeprovisionMode;
|
|
472
|
-
};
|
|
473
|
-
};
|
|
474
|
-
extend?: Record<string, unknown>;
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
/**
|
|
478
|
-
* Email provider config for magic link / OTP sign-in.
|
|
479
|
-
*
|
|
480
|
-
* @typeParam DataModel - The Convex data model for typed action contexts.
|
|
481
|
-
*/
|
|
482
|
-
export interface EmailConfig<
|
|
483
|
-
DataModel extends GenericDataModel = GenericDataModel,
|
|
484
|
-
> {
|
|
485
|
-
/** Provider identifier (e.g. `"email"`, `"resend"`). */
|
|
486
|
-
id: string;
|
|
487
|
-
/** Discriminant for provider type routing. */
|
|
488
|
-
type: "email";
|
|
489
|
-
/** Display name for this provider. */
|
|
490
|
-
name?: string;
|
|
491
|
-
/** Sender address (e.g. `"My App <noreply@example.com>"`). */
|
|
492
|
-
from?: string;
|
|
493
|
-
/**
|
|
494
|
-
* Token expiration in seconds. Defaults to 86 400 (24 hours).
|
|
495
|
-
*
|
|
496
|
-
* @defaultValue 86400
|
|
497
|
-
*/
|
|
498
|
-
maxAge?: number;
|
|
499
|
-
/**
|
|
500
|
-
* Send the verification token to the user.
|
|
501
|
-
*
|
|
502
|
-
* Accepts an optional Convex action context as the second argument,
|
|
503
|
-
* enabling use with Convex components like `@convex-dev/resend`.
|
|
504
|
-
*/
|
|
505
|
-
sendVerificationRequest: (
|
|
506
|
-
params: {
|
|
507
|
-
identifier: string;
|
|
508
|
-
url: string;
|
|
509
|
-
expires: Date;
|
|
510
|
-
provider: EmailConfig;
|
|
511
|
-
token: string;
|
|
512
|
-
request: Request;
|
|
513
|
-
},
|
|
514
|
-
ctx?: GenericActionCtx<AnyDataModel>,
|
|
515
|
-
) => Awaitable<void>;
|
|
516
|
-
/**
|
|
517
|
-
* Override to generate a custom verification token.
|
|
518
|
-
* Tokens shorter than 24 characters are treated as OTPs and
|
|
519
|
-
* require the original email to be re-submitted for verification.
|
|
520
|
-
*/
|
|
521
|
-
generateVerificationToken?: () => Awaitable<string>;
|
|
522
|
-
/**
|
|
523
|
-
* Normalize the email address before storage / lookup.
|
|
524
|
-
* Defaults to lowercasing and trimming whitespace.
|
|
525
|
-
*/
|
|
526
|
-
normalizeIdentifier?: (identifier: string) => string;
|
|
527
|
-
/**
|
|
528
|
-
* Before the token is verified, check other
|
|
529
|
-
* provided parameters.
|
|
530
|
-
*
|
|
531
|
-
* Used to make sure that OTPs are accompanied
|
|
532
|
-
* with the correct email address.
|
|
533
|
-
*/
|
|
534
|
-
authorize?: (
|
|
535
|
-
/**
|
|
536
|
-
* The values passed to the `signIn` function.
|
|
537
|
-
*/
|
|
538
|
-
params: Record<string, Value | undefined>,
|
|
539
|
-
account: GenericDoc<DataModel, "Account">,
|
|
540
|
-
) => Promise<void>;
|
|
541
|
-
/** Raw user options before merging with defaults. */
|
|
542
|
-
options: EmailUserConfig<DataModel>;
|
|
543
|
-
}
|
|
544
|
-
|
|
545
|
-
/**
|
|
546
|
-
* User-facing configuration shape accepted by the email provider.
|
|
547
|
-
*
|
|
548
|
-
* Equivalent to `Partial<EmailConfig>` without internal runtime-only fields.
|
|
549
|
-
*
|
|
550
|
-
* @typeParam DataModel - The Convex data model.
|
|
551
|
-
*/
|
|
552
|
-
export type EmailUserConfig<
|
|
553
|
-
DataModel extends GenericDataModel = GenericDataModel,
|
|
554
|
-
> = Omit<Partial<EmailConfig<DataModel>>, "options" | "type">;
|
|
555
|
-
|
|
556
|
-
/**
|
|
557
|
-
* Same as email provider config, but verifies
|
|
558
|
-
* phone number instead of the email address.
|
|
559
|
-
*
|
|
560
|
-
* @typeParam DataModel - The Convex data model for typed action contexts.
|
|
561
|
-
*/
|
|
562
|
-
export interface PhoneConfig<
|
|
563
|
-
DataModel extends GenericDataModel = GenericDataModel,
|
|
564
|
-
> {
|
|
565
|
-
id: string;
|
|
566
|
-
type: "phone";
|
|
567
|
-
/**
|
|
568
|
-
* Token expiration in seconds.
|
|
569
|
-
*/
|
|
570
|
-
maxAge: number;
|
|
571
|
-
/**
|
|
572
|
-
* Send the phone number verification request.
|
|
573
|
-
*/
|
|
574
|
-
sendVerificationRequest: (
|
|
575
|
-
params: {
|
|
576
|
-
identifier: string;
|
|
577
|
-
url: string;
|
|
578
|
-
expires: Date;
|
|
579
|
-
provider: PhoneConfig;
|
|
580
|
-
token: string;
|
|
581
|
-
},
|
|
582
|
-
ctx: GenericActionCtxWithAuthConfig<DataModel>,
|
|
583
|
-
) => Promise<void>;
|
|
584
|
-
/**
|
|
585
|
-
* Defaults to `process.env.AUTH_<PROVIDER_ID>_KEY`.
|
|
586
|
-
*/
|
|
587
|
-
apiKey?: string;
|
|
588
|
-
/**
|
|
589
|
-
* Override this to generate a custom token.
|
|
590
|
-
* Note that the tokens are assumed to be cryptographically secure.
|
|
591
|
-
* Any tokens shorter than 24 characters are assumed to not
|
|
592
|
-
* be secure enough on their own, and require providing
|
|
593
|
-
* the original `phone` used in the initial `signIn` call.
|
|
594
|
-
* @returns
|
|
595
|
-
*/
|
|
596
|
-
generateVerificationToken?: () => Promise<string>;
|
|
597
|
-
/**
|
|
598
|
-
* Normalize the phone number.
|
|
599
|
-
* @param identifier Passed as `phone` in params of `signIn`.
|
|
600
|
-
* @returns The phone number used in `sendVerificationRequest`.
|
|
601
|
-
*/
|
|
602
|
-
normalizeIdentifier?: (identifier: string) => string;
|
|
603
|
-
/**
|
|
604
|
-
* Before the token is verified, check other
|
|
605
|
-
* provided parameters.
|
|
606
|
-
*
|
|
607
|
-
* Used to make sure tha OTPs are accompanied
|
|
608
|
-
* with the correct phone number.
|
|
609
|
-
*/
|
|
610
|
-
authorize?: (
|
|
611
|
-
/**
|
|
612
|
-
* The values passed to the `signIn` function.
|
|
613
|
-
*/
|
|
614
|
-
params: Record<string, Value | undefined>,
|
|
615
|
-
account: GenericDoc<DataModel, "Account">,
|
|
616
|
-
) => Promise<void>;
|
|
617
|
-
options: PhoneUserConfig<DataModel>;
|
|
618
|
-
}
|
|
619
|
-
|
|
620
|
-
/**
|
|
621
|
-
* User-facing configuration shape accepted by the phone provider.
|
|
622
|
-
*
|
|
623
|
-
* Equivalent to `Partial<PhoneConfig>` without internal runtime-only fields.
|
|
624
|
-
*
|
|
625
|
-
* @typeParam DataModel - The Convex data model.
|
|
626
|
-
*/
|
|
627
|
-
export type PhoneUserConfig<
|
|
628
|
-
DataModel extends GenericDataModel = GenericDataModel,
|
|
629
|
-
> = Omit<Partial<PhoneConfig<DataModel>>, "options" | "type">;
|
|
630
|
-
|
|
631
|
-
/**
|
|
632
|
-
* Credentials provider config used by Convex Auth.
|
|
633
|
-
*/
|
|
634
|
-
export type ConvexCredentialsConfig = CredentialsConfig<any> & {
|
|
635
|
-
type: "credentials";
|
|
636
|
-
id: string;
|
|
637
|
-
};
|
|
638
|
-
|
|
639
|
-
/**
|
|
640
|
-
* Configuration for the passkey (WebAuthn) provider.
|
|
641
|
-
*/
|
|
642
|
-
export interface PasskeyProviderConfig {
|
|
643
|
-
id: string;
|
|
644
|
-
type: "passkey";
|
|
645
|
-
options: {
|
|
646
|
-
/** Relying Party display name. Defaults to SITE_URL hostname. */
|
|
647
|
-
rpName?: string;
|
|
648
|
-
/** Relying Party ID (hostname). Defaults to SITE_URL hostname. */
|
|
649
|
-
rpId?: string;
|
|
650
|
-
/** Allowed origins for credential verification. Defaults to SITE_URL plus SECONDARY_URL. */
|
|
651
|
-
origin?: string | string[];
|
|
652
|
-
/**
|
|
653
|
-
* Attestation conveyance preference. Defaults to "none".
|
|
654
|
-
*
|
|
655
|
-
* @defaultValue "none"
|
|
656
|
-
*/
|
|
657
|
-
attestation?: "none" | "direct";
|
|
658
|
-
/**
|
|
659
|
-
* User verification requirement. Defaults to "required".
|
|
660
|
-
*
|
|
661
|
-
* @defaultValue "required"
|
|
662
|
-
*/
|
|
663
|
-
userVerification?: "required" | "preferred" | "discouraged";
|
|
664
|
-
/**
|
|
665
|
-
* Resident key (discoverable credential) preference. Defaults to "preferred".
|
|
666
|
-
*
|
|
667
|
-
* @defaultValue "preferred"
|
|
668
|
-
*/
|
|
669
|
-
residentKey?: "required" | "preferred" | "discouraged";
|
|
670
|
-
/** Restrict to platform or cross-platform authenticators. */
|
|
671
|
-
authenticatorAttachment?: "platform" | "cross-platform";
|
|
672
|
-
/**
|
|
673
|
-
* Supported COSE algorithms. Defaults to [-7 (ES256), -257 (RS256)].
|
|
674
|
-
*
|
|
675
|
-
* @defaultValue [-7, -257]
|
|
676
|
-
*/
|
|
677
|
-
algorithms?: number[];
|
|
678
|
-
/**
|
|
679
|
-
* Challenge expiration in ms. Defaults to 300_000 (5 minutes).
|
|
680
|
-
*
|
|
681
|
-
* @defaultValue 300_000
|
|
682
|
-
*/
|
|
683
|
-
challengeExpirationMs?: number;
|
|
684
|
-
};
|
|
685
|
-
}
|
|
686
|
-
|
|
687
|
-
/**
|
|
688
|
-
* Configuration for the TOTP two-factor authentication provider.
|
|
689
|
-
*/
|
|
690
|
-
export interface TotpProviderConfig {
|
|
691
|
-
id: string;
|
|
692
|
-
type: "totp";
|
|
693
|
-
options: {
|
|
694
|
-
/** Issuer name shown in authenticator apps (e.g. "My App"). */
|
|
695
|
-
issuer: string;
|
|
696
|
-
/**
|
|
697
|
-
* Number of digits in each code (default: 6).
|
|
698
|
-
*
|
|
699
|
-
* @defaultValue 6
|
|
700
|
-
*/
|
|
701
|
-
digits: number;
|
|
702
|
-
/**
|
|
703
|
-
* Time period in seconds for code rotation (default: 30).
|
|
704
|
-
*
|
|
705
|
-
* @defaultValue 30
|
|
706
|
-
*/
|
|
707
|
-
period: number;
|
|
708
|
-
};
|
|
709
|
-
}
|
|
710
|
-
|
|
711
|
-
// ============================================================================
|
|
712
|
-
// OAuth types (Arctic-based)
|
|
713
|
-
// ============================================================================
|
|
714
|
-
|
|
715
|
-
/**
|
|
716
|
-
* Normalized user profile returned by an OAuth provider.
|
|
717
|
-
*
|
|
718
|
-
* `id` is the provider-specific account identifier (e.g. GitHub user ID).
|
|
719
|
-
*/
|
|
720
|
-
export interface OAuthProfile {
|
|
721
|
-
id: string;
|
|
722
|
-
name?: string;
|
|
723
|
-
email?: string;
|
|
724
|
-
image?: string;
|
|
725
|
-
/** Additional claims from the ID token or userinfo endpoint. */
|
|
726
|
-
[key: string]: unknown;
|
|
727
|
-
}
|
|
728
|
-
|
|
729
|
-
/**
|
|
730
|
-
* Internal config shape for an OAuth provider after normalization.
|
|
731
|
-
*
|
|
732
|
-
* This is what the OAuth flow code receives — it maps to the user-facing
|
|
733
|
-
* `OAuthConfig` from `@robelest/convex-auth/providers`.
|
|
734
|
-
*
|
|
735
|
-
* @internal
|
|
736
|
-
*/
|
|
737
|
-
export interface OAuthProviderConfig {
|
|
738
|
-
/** OAuth scopes to request. */
|
|
739
|
-
scopes?: string[];
|
|
740
|
-
/** User-provided profile extraction callback. */
|
|
741
|
-
profile?: (tokens: import("arctic").OAuth2Tokens) => Promise<OAuthProfile>;
|
|
742
|
-
}
|
|
743
|
-
|
|
744
|
-
/** Credentials identifying a provider account (e.g. email + hashed password). */
|
|
745
|
-
export type AuthAccountCredentials = {
|
|
746
|
-
/** Provider-specific account identifier (e.g. email address). */
|
|
747
|
-
id: string;
|
|
748
|
-
/** Optional secret (e.g. hashed password). */
|
|
749
|
-
secret?: string;
|
|
750
|
-
};
|
|
751
|
-
|
|
752
|
-
/** Arguments for `auth.account.create()`. */
|
|
753
|
-
export type AuthCreateAccountArgs = {
|
|
754
|
-
provider: string;
|
|
755
|
-
account: AuthAccountCredentials;
|
|
756
|
-
profile: Record<string, unknown> & {
|
|
757
|
-
email?: string;
|
|
758
|
-
phone?: string;
|
|
759
|
-
emailVerified?: boolean;
|
|
760
|
-
phoneVerified?: boolean;
|
|
761
|
-
};
|
|
762
|
-
shouldLinkViaEmail?: boolean;
|
|
763
|
-
shouldLinkViaPhone?: boolean;
|
|
764
|
-
};
|
|
765
|
-
|
|
766
|
-
/** Arguments for `auth.account.get()`. */
|
|
767
|
-
export type AuthRetrieveAccountArgs = {
|
|
768
|
-
provider: string;
|
|
769
|
-
account: AuthAccountCredentials;
|
|
770
|
-
};
|
|
771
|
-
|
|
772
|
-
/** Arguments for `auth.account.update()`. */
|
|
773
|
-
export type AuthUpdateAccountArgs = {
|
|
774
|
-
provider: string;
|
|
775
|
-
account: {
|
|
776
|
-
id: string;
|
|
777
|
-
secret: string;
|
|
778
|
-
};
|
|
779
|
-
};
|
|
780
|
-
|
|
781
|
-
/** Arguments for `auth.session.invalidate()`. */
|
|
782
|
-
export type AuthInvalidateSessionsArgs = {
|
|
783
|
-
userId: GenericId<"User">;
|
|
784
|
-
except?: GenericId<"Session">[];
|
|
785
|
-
};
|
|
786
|
-
|
|
787
|
-
/** Arguments for `auth.provider.signIn()`. */
|
|
788
|
-
export type AuthProviderSignInArgs = {
|
|
789
|
-
accountId?: GenericId<"Account">;
|
|
790
|
-
params?: Record<string, Value | undefined>;
|
|
791
|
-
};
|
|
792
|
-
|
|
793
|
-
/** Return type of `auth.provider.signIn()` — user and session IDs, or `null` on failure. */
|
|
794
|
-
export type AuthProviderSignInResult = {
|
|
795
|
-
userId: GenericId<"User">;
|
|
796
|
-
sessionId: GenericId<"Session">;
|
|
797
|
-
} | null;
|
|
798
|
-
|
|
799
|
-
/** Arguments for `auth.member.inspect()`. */
|
|
800
|
-
export type AuthMemberInspectArgs = {
|
|
801
|
-
userId: GenericId<"User">;
|
|
802
|
-
groupId: GenericId<"Group">;
|
|
803
|
-
ancestry?: boolean;
|
|
804
|
-
maxDepth?: number;
|
|
805
|
-
};
|
|
806
|
-
|
|
807
|
-
/** Result of `auth.member.inspect()` — membership state and derived access details. */
|
|
808
|
-
export type AuthMemberInspectResult = {
|
|
809
|
-
membership: GenericDoc<GenericDataModel, "GroupMember"> | null;
|
|
810
|
-
roleIds: string[];
|
|
811
|
-
grants: string[];
|
|
812
|
-
};
|
|
813
|
-
|
|
814
|
-
/** Arguments for `auth.member.require()`. */
|
|
815
|
-
export type AuthMemberRequireArgs = AuthMemberInspectArgs & {
|
|
816
|
-
roleIds?: string[];
|
|
817
|
-
grants?: string[];
|
|
818
|
-
};
|
|
819
|
-
|
|
820
|
-
/**
|
|
821
|
-
* Server-side auth helper methods injected into `ctx.auth` within provider actions.
|
|
822
|
-
*
|
|
823
|
-
* Provides programmatic access to account management, session lifecycle,
|
|
824
|
-
* membership resolution, and provider sign-in from within Convex actions
|
|
825
|
-
* that use {@link GenericActionCtxWithAuthConfig}.
|
|
826
|
-
*
|
|
827
|
-
* @see {@link GenericActionCtxWithAuthConfig}
|
|
828
|
-
*
|
|
829
|
-
* @example
|
|
830
|
-
* ```ts
|
|
831
|
-
* // Inside a credentials provider's authorize callback:
|
|
832
|
-
* const { account, user } = await ctx.auth.account.get(ctx, {
|
|
833
|
-
* provider: "password",
|
|
834
|
-
* account: { id: email },
|
|
835
|
-
* });
|
|
836
|
-
* ```
|
|
837
|
-
*/
|
|
838
|
-
export type AuthServerHelpers = {
|
|
839
|
-
/** Account management: create, retrieve, and update provider-linked accounts. */
|
|
840
|
-
account: {
|
|
841
|
-
create: (
|
|
842
|
-
ctx: GenericActionCtx<any>,
|
|
843
|
-
args: AuthCreateAccountArgs,
|
|
844
|
-
) => Promise<{
|
|
845
|
-
account: GenericDoc<GenericDataModel, "Account">;
|
|
846
|
-
user: GenericDoc<GenericDataModel, "User">;
|
|
847
|
-
}>;
|
|
848
|
-
get: (
|
|
849
|
-
ctx: GenericActionCtx<any>,
|
|
850
|
-
args: AuthRetrieveAccountArgs,
|
|
851
|
-
) => Promise<{
|
|
852
|
-
account: GenericDoc<GenericDataModel, "Account">;
|
|
853
|
-
user: GenericDoc<GenericDataModel, "User">;
|
|
854
|
-
}>;
|
|
855
|
-
update: (
|
|
856
|
-
ctx: GenericActionCtx<any>,
|
|
857
|
-
args: AuthUpdateAccountArgs,
|
|
858
|
-
) => Promise<{ accountId: GenericId<"Account"> }>;
|
|
859
|
-
};
|
|
860
|
-
session: {
|
|
861
|
-
current: (ctx: {
|
|
862
|
-
auth: GenericActionCtx<GenericDataModel>["auth"];
|
|
863
|
-
}) => Promise<GenericId<"Session"> | null>;
|
|
864
|
-
invalidate: (
|
|
865
|
-
ctx: GenericActionCtx<any>,
|
|
866
|
-
args: AuthInvalidateSessionsArgs,
|
|
867
|
-
) => Promise<{
|
|
868
|
-
userId: GenericId<"User">;
|
|
869
|
-
except: GenericId<"Session">[];
|
|
870
|
-
}>;
|
|
871
|
-
};
|
|
872
|
-
member: {
|
|
873
|
-
inspect: (
|
|
874
|
-
ctx: GenericActionCtx<any>,
|
|
875
|
-
args: AuthMemberInspectArgs,
|
|
876
|
-
) => Promise<AuthMemberInspectResult>;
|
|
877
|
-
require: (
|
|
878
|
-
ctx: GenericActionCtx<any>,
|
|
879
|
-
args: AuthMemberRequireArgs,
|
|
880
|
-
) => Promise<AuthMemberInspectResult>;
|
|
881
|
-
};
|
|
882
|
-
provider: {
|
|
883
|
-
signIn: (
|
|
884
|
-
ctx: GenericActionCtx<any>,
|
|
885
|
-
provider: AuthProviderConfig,
|
|
886
|
-
args: AuthProviderSignInArgs,
|
|
887
|
-
) => Promise<AuthProviderSignInResult>;
|
|
888
|
-
};
|
|
889
|
-
};
|
|
890
|
-
|
|
891
|
-
/**
|
|
892
|
-
* Your `ActionCtx` enriched with `ctx.auth.config` field with
|
|
893
|
-
* the config passed to `createAuth`.
|
|
894
|
-
*
|
|
895
|
-
* @typeParam DataModel - The Convex data model.
|
|
896
|
-
*/
|
|
897
|
-
export type GenericActionCtxWithAuthConfig<DataModel extends GenericDataModel> =
|
|
898
|
-
GenericActionCtx<DataModel> & {
|
|
899
|
-
auth: GenericActionCtx<DataModel>["auth"] & {
|
|
900
|
-
config: ConvexAuthMaterializedConfig;
|
|
901
|
-
} & AuthServerHelpers;
|
|
902
|
-
};
|
|
903
|
-
|
|
904
|
-
/**
|
|
905
|
-
* The config for the Convex Auth library, passed to `createAuth`,
|
|
906
|
-
* with defaults and initialized providers.
|
|
907
|
-
*
|
|
908
|
-
* See {@link ConvexAuthConfig}
|
|
909
|
-
*/
|
|
910
|
-
export type ConvexAuthMaterializedConfig = {
|
|
911
|
-
providers: AuthProviderMaterializedConfig[];
|
|
912
|
-
} & Pick<
|
|
913
|
-
ConvexAuthConfig,
|
|
914
|
-
"component" | "session" | "jwt" | "signIn" | "callbacks" | "authorization"
|
|
915
|
-
>;
|
|
916
|
-
|
|
917
|
-
/**
|
|
918
|
-
* Maps SAML assertion attribute names to user profile fields.
|
|
919
|
-
*
|
|
920
|
-
* Use this to tell the SSO flow which SAML attributes correspond to
|
|
921
|
-
* the user's subject identifier, email, and display name fields.
|
|
922
|
-
*/
|
|
923
|
-
export interface SAMLAttributeMapping {
|
|
924
|
-
/** SAML attribute for the unique subject identifier (NameID). */
|
|
925
|
-
subject?: string;
|
|
926
|
-
/** SAML attribute for the user's email address. */
|
|
927
|
-
email?: string;
|
|
928
|
-
/** SAML attribute for the user's full display name. */
|
|
929
|
-
name?: string;
|
|
930
|
-
/** SAML attribute for the user's first / given name. */
|
|
931
|
-
firstName?: string;
|
|
932
|
-
/** SAML attribute for the user's last / family name. */
|
|
933
|
-
lastName?: string;
|
|
934
|
-
}
|
|
935
|
-
|
|
936
|
-
/**
|
|
937
|
-
* Materialized OAuth provider config (Arctic-based).
|
|
938
|
-
*
|
|
939
|
-
* Carries the Arctic provider instance along with scopes and profile config.
|
|
940
|
-
* Produced by materializing an `OAuthProviderInstance` during `configDefaults`.
|
|
941
|
-
*/
|
|
942
|
-
export interface OAuthMaterializedConfig {
|
|
943
|
-
/**
|
|
944
|
-
* Provider identifier (e.g. `"google"`, `"github"`).
|
|
945
|
-
* @readonly
|
|
946
|
-
*/
|
|
947
|
-
readonly id: string;
|
|
948
|
-
/**
|
|
949
|
-
* Discriminant for provider type routing.
|
|
950
|
-
* @readonly
|
|
951
|
-
*/
|
|
952
|
-
readonly type: "oauth";
|
|
953
|
-
/**
|
|
954
|
-
* The Arctic provider instance.
|
|
955
|
-
* @readonly
|
|
956
|
-
*/
|
|
957
|
-
readonly provider: any;
|
|
958
|
-
/**
|
|
959
|
-
* OAuth scopes to request.
|
|
960
|
-
* @readonly
|
|
961
|
-
*/
|
|
962
|
-
readonly scopes: string[];
|
|
963
|
-
/**
|
|
964
|
-
* User-provided profile extraction callback.
|
|
965
|
-
* @readonly
|
|
966
|
-
*/
|
|
967
|
-
readonly profile?: (
|
|
968
|
-
tokens: import("arctic").OAuth2Tokens,
|
|
969
|
-
) => Promise<OAuthProfile>;
|
|
970
|
-
/**
|
|
971
|
-
* Account-linking policy for OAuth identities. Defaults to verified email linking.
|
|
972
|
-
* @readonly
|
|
973
|
-
*/
|
|
974
|
-
readonly accountLinking?: "verifiedEmail" | "none";
|
|
975
|
-
}
|
|
976
|
-
|
|
977
|
-
/**
|
|
978
|
-
* Device authorization provider config (RFC 8628).
|
|
979
|
-
*
|
|
980
|
-
* Enables input-constrained devices (CLIs, TVs, IoT) to authenticate
|
|
981
|
-
* by displaying a short code that the user enters on a secondary device.
|
|
982
|
-
*/
|
|
983
|
-
export interface DeviceProviderConfig {
|
|
984
|
-
id: string;
|
|
985
|
-
type: "device";
|
|
986
|
-
/** User code character set. Default: `"BCDFGHJKLMNPQRSTVWXZ"` (base-20, no vowels). */
|
|
987
|
-
charset: string;
|
|
988
|
-
/** User code length. Default: 8. */
|
|
989
|
-
userCodeLength: number;
|
|
990
|
-
/** Device code + user code lifetime in seconds. Default: 900 (15 min). */
|
|
991
|
-
expiresIn: number;
|
|
992
|
-
/** Minimum polling interval in seconds. Default: 5. */
|
|
993
|
-
interval: number;
|
|
994
|
-
/**
|
|
995
|
-
* Base URL for the verification page (e.g. `"http://localhost:3000/device"`).
|
|
996
|
-
*
|
|
997
|
-
* This is where users go to enter the device code. If not provided,
|
|
998
|
-
* falls back to `SITE_URL + "/device"`.
|
|
999
|
-
*/
|
|
1000
|
-
verificationUri?: string;
|
|
1001
|
-
}
|
|
1002
|
-
|
|
1003
|
-
/**
|
|
1004
|
-
* Materialized auth provider config — the fully resolved form stored at runtime.
|
|
1005
|
-
*/
|
|
1006
|
-
export type AuthProviderMaterializedConfig =
|
|
1007
|
-
| OAuthMaterializedConfig
|
|
1008
|
-
| EmailConfig
|
|
1009
|
-
| PhoneConfig
|
|
1010
|
-
| ConvexCredentialsConfig
|
|
1011
|
-
| PasskeyProviderConfig
|
|
1012
|
-
| TotpProviderConfig
|
|
1013
|
-
| DeviceProviderConfig
|
|
1014
|
-
| SSOProviderConfig;
|
|
1015
|
-
|
|
1016
|
-
/**
|
|
1017
|
-
* Resolves to `true` when the providers list includes `SSO`, otherwise `false`.
|
|
1018
|
-
*
|
|
1019
|
-
* Used to make `auth.sso` conditionally present on the `createAuth`
|
|
1020
|
-
* return type — it only appears when `new SSO()` is in the providers array.
|
|
1021
|
-
*/
|
|
1022
|
-
export type HasSSO<P extends AuthProviderConfig[]> =
|
|
1023
|
-
import("../providers/sso").SSO extends P[number] ? true : false;
|
|
1024
|
-
|
|
1025
|
-
export type HasPasskeyProvider<P extends AuthProviderConfig[]> =
|
|
1026
|
-
import("../providers/passkey").Passkey extends P[number] ? true : false;
|
|
1027
|
-
|
|
1028
|
-
export type HasTotpProvider<P extends AuthProviderConfig[]> =
|
|
1029
|
-
import("../providers/totp").Totp extends P[number] ? true : false;
|
|
1030
|
-
|
|
1031
|
-
export type HasDeviceProvider<P extends AuthProviderConfig[]> =
|
|
1032
|
-
import("../providers/device").Device extends P[number] ? true : false;
|
|
1033
|
-
|
|
1034
|
-
// ============================================================================
|
|
1035
|
-
// API Key types
|
|
1036
|
-
// ============================================================================
|
|
1037
|
-
|
|
1038
|
-
/**
|
|
1039
|
-
* A single scope entry stored per API key.
|
|
1040
|
-
* Uses a resource:action pattern for structured permissions.
|
|
1041
|
-
*
|
|
1042
|
-
* ```ts
|
|
1043
|
-
* { resource: "users", actions: ["read", "list"] }
|
|
1044
|
-
* ```
|
|
1045
|
-
*/
|
|
1046
|
-
export interface KeyScope {
|
|
1047
|
-
resource: string;
|
|
1048
|
-
actions: string[];
|
|
1049
|
-
}
|
|
1050
|
-
|
|
1051
|
-
/**
|
|
1052
|
-
* Result of scope verification. Provides a `.can()` helper
|
|
1053
|
-
* for checking if a key has a specific permission.
|
|
1054
|
-
*
|
|
1055
|
-
* ```ts
|
|
1056
|
-
* const result = await auth.key.verify(ctx, rawKey);
|
|
1057
|
-
* if (result.scopes.can("users", "read")) {
|
|
1058
|
-
* // authorized
|
|
1059
|
-
* }
|
|
1060
|
-
* ```
|
|
1061
|
-
*/
|
|
1062
|
-
export interface ScopeChecker {
|
|
1063
|
-
/** Check if the key has permission for a given resource:action. */
|
|
1064
|
-
can(resource: string, action: string): boolean;
|
|
1065
|
-
/** The raw scope entries from the key. */
|
|
1066
|
-
scopes: KeyScope[];
|
|
1067
|
-
}
|
|
1068
|
-
|
|
1069
|
-
/**
|
|
1070
|
-
* An API key record as returned by `auth.key.list()` and `auth.key.get()`.
|
|
1071
|
-
* Never includes the raw key material — only the display prefix.
|
|
1072
|
-
*/
|
|
1073
|
-
export interface KeyRecord {
|
|
1074
|
-
/** Document ID. */
|
|
1075
|
-
_id: string;
|
|
1076
|
-
/** Owner user ID. */
|
|
1077
|
-
userId: string;
|
|
1078
|
-
/** Display prefix (e.g. `"sk_abc1"`). Safe to show in UIs. */
|
|
1079
|
-
prefix: string;
|
|
1080
|
-
/** Human-readable name (e.g. "CI Pipeline"). */
|
|
1081
|
-
name: string;
|
|
1082
|
-
/** Resource:action permissions granted to this key. */
|
|
1083
|
-
scopes: KeyScope[];
|
|
1084
|
-
/** Per-key rate limit, if configured. */
|
|
1085
|
-
rateLimit?: { maxRequests: number; windowMs: number };
|
|
1086
|
-
/** Expiration timestamp (ms since epoch), or `undefined` for no expiry. */
|
|
1087
|
-
expiresAt?: number;
|
|
1088
|
-
/** Timestamp of last successful verification, or `undefined` if never used. */
|
|
1089
|
-
lastUsedAt?: number;
|
|
1090
|
-
/** Creation timestamp (ms since epoch). */
|
|
1091
|
-
createdAt: number;
|
|
1092
|
-
/** `true` when the key has been revoked (soft-deleted). */
|
|
1093
|
-
revoked: boolean;
|
|
1094
|
-
/** Arbitrary app-specific metadata attached to the key. */
|
|
1095
|
-
metadata?: Record<string, unknown>;
|
|
1096
|
-
}
|
|
1097
|
-
|
|
1098
|
-
// ============================================================================
|
|
1099
|
-
// Unified List API types
|
|
1100
|
-
// ============================================================================
|
|
1101
|
-
|
|
1102
|
-
/**
|
|
1103
|
-
* Options for paginated list queries. Every entity list method uses this
|
|
1104
|
-
* same shape with entity-specific `TWhere` and `TOrderBy` type parameters.
|
|
1105
|
-
*
|
|
1106
|
-
* @typeParam TWhere - The type of the optional filter object.
|
|
1107
|
-
* @typeParam TOrderBy - The union of sortable field names.
|
|
1108
|
-
*
|
|
1109
|
-
* ```ts
|
|
1110
|
-
* const result = await auth.group.list(ctx, {
|
|
1111
|
-
* where: { type: "team" },
|
|
1112
|
-
* limit: 20,
|
|
1113
|
-
* orderBy: "name",
|
|
1114
|
-
* order: "asc",
|
|
1115
|
-
* });
|
|
1116
|
-
* ```
|
|
1117
|
-
*/
|
|
1118
|
-
export type ListOptions<
|
|
1119
|
-
TWhere extends Record<string, unknown>,
|
|
1120
|
-
TOrderBy extends string,
|
|
1121
|
-
> = {
|
|
1122
|
-
/** Serializable filter — only known fields for the entity. */
|
|
1123
|
-
where?: TWhere;
|
|
1124
|
-
/** Maximum number of items to return. Defaults to 50, max 100. */
|
|
1125
|
-
limit?: number;
|
|
1126
|
-
/** Opaque cursor from a previous `ListResult.nextCursor`. */
|
|
1127
|
-
cursor?: string | null;
|
|
1128
|
-
/** Field to sort by. Defaults to `"_creationTime"`. */
|
|
1129
|
-
orderBy?: TOrderBy;
|
|
1130
|
-
/** Sort direction. Defaults to `"desc"`. */
|
|
1131
|
-
order?: "asc" | "desc";
|
|
1132
|
-
};
|
|
1133
|
-
|
|
1134
|
-
/**
|
|
1135
|
-
* Paginated list result returned by every entity list method.
|
|
1136
|
-
*
|
|
1137
|
-
* @typeParam T - The type of items in the result array.
|
|
1138
|
-
*/
|
|
1139
|
-
export type ListResult<T> = {
|
|
1140
|
-
/** The page of items. */
|
|
1141
|
-
items: T[];
|
|
1142
|
-
/** Opaque cursor for the next page, or `null` when exhausted. */
|
|
1143
|
-
nextCursor: string | null;
|
|
1144
|
-
};
|
|
1145
|
-
|
|
1146
|
-
// -- Per-entity Where / OrderBy types --
|
|
1147
|
-
|
|
1148
|
-
/**
|
|
1149
|
-
* A single key/value tag for group classification.
|
|
1150
|
-
*
|
|
1151
|
-
* Tags are normalized at write time: both `key` and `value` are
|
|
1152
|
-
* trimmed and lowercased. Filtering is strict exact-match only.
|
|
1153
|
-
*/
|
|
1154
|
-
export type GroupTag = {
|
|
1155
|
-
key: string;
|
|
1156
|
-
value: string;
|
|
1157
|
-
};
|
|
1158
|
-
|
|
1159
|
-
/** Filter fields for `auth.group.list()`. All optional. */
|
|
1160
|
-
export type GroupWhere = {
|
|
1161
|
-
slug?: string;
|
|
1162
|
-
type?: string;
|
|
1163
|
-
parentGroupId?: string;
|
|
1164
|
-
name?: string;
|
|
1165
|
-
/** When `true`, return only root groups (no parent). When `false`, only non-root. */
|
|
1166
|
-
isRoot?: boolean;
|
|
1167
|
-
/**
|
|
1168
|
-
* Return only groups that have **all** of the specified tags.
|
|
1169
|
-
* Each tag is matched exactly on normalized `(key, value)`.
|
|
1170
|
-
*/
|
|
1171
|
-
tagsAll?: GroupTag[];
|
|
1172
|
-
/**
|
|
1173
|
-
* Return only groups that have **at least one** of the specified tags.
|
|
1174
|
-
* Each tag is matched exactly on normalized `(key, value)`.
|
|
1175
|
-
*/
|
|
1176
|
-
tagsAny?: GroupTag[];
|
|
1177
|
-
};
|
|
1178
|
-
|
|
1179
|
-
/** Sortable fields for `auth.group.list()`. */
|
|
1180
|
-
export type GroupOrderBy = "_creationTime" | "name" | "slug" | "type";
|
|
1181
|
-
|
|
1182
|
-
/** Filter fields for `auth.member.list()`. All optional. */
|
|
1183
|
-
export type MemberWhere = {
|
|
1184
|
-
groupId?: string;
|
|
1185
|
-
userId?: string;
|
|
1186
|
-
roleId?: string;
|
|
1187
|
-
status?: string;
|
|
1188
|
-
};
|
|
1189
|
-
|
|
1190
|
-
/** Sortable fields for `auth.member.list()`. */
|
|
1191
|
-
export type MemberOrderBy = "_creationTime" | "status";
|
|
1192
|
-
|
|
1193
|
-
/** Filter fields for `auth.invite.list()`. All optional. */
|
|
1194
|
-
export type InviteWhere = {
|
|
1195
|
-
tokenHash?: string;
|
|
1196
|
-
groupId?: string;
|
|
1197
|
-
status?: "pending" | "accepted" | "revoked" | "expired";
|
|
1198
|
-
email?: string;
|
|
1199
|
-
invitedByUserId?: string;
|
|
1200
|
-
roleId?: string;
|
|
1201
|
-
acceptedByUserId?: string;
|
|
1202
|
-
};
|
|
1203
|
-
|
|
1204
|
-
/** Sortable fields for `auth.invite.list()`. */
|
|
1205
|
-
export type InviteOrderBy =
|
|
1206
|
-
| "_creationTime"
|
|
1207
|
-
| "status"
|
|
1208
|
-
| "email"
|
|
1209
|
-
| "expiresTime"
|
|
1210
|
-
| "acceptedTime";
|
|
1211
|
-
|
|
1212
|
-
/** Filter fields for `auth.key.list()`. All optional. */
|
|
1213
|
-
export type KeyWhere = {
|
|
1214
|
-
userId?: string;
|
|
1215
|
-
revoked?: boolean;
|
|
1216
|
-
name?: string;
|
|
1217
|
-
prefix?: string;
|
|
1218
|
-
};
|
|
1219
|
-
|
|
1220
|
-
/** Sortable fields for `auth.key.list()`. */
|
|
1221
|
-
export type KeyOrderBy =
|
|
1222
|
-
| "_creationTime"
|
|
1223
|
-
| "name"
|
|
1224
|
-
| "lastUsedAt"
|
|
1225
|
-
| "expiresAt"
|
|
1226
|
-
| "revoked";
|
|
1227
|
-
|
|
1228
|
-
/** Filter fields for `auth.user.list()`. All optional. */
|
|
1229
|
-
export type UserWhere = {
|
|
1230
|
-
email?: string;
|
|
1231
|
-
phone?: string;
|
|
1232
|
-
isAnonymous?: boolean;
|
|
1233
|
-
name?: string;
|
|
1234
|
-
};
|
|
1235
|
-
|
|
1236
|
-
/** Sortable fields for `auth.user.list()`. */
|
|
1237
|
-
export type UserOrderBy = "_creationTime" | "name" | "email" | "phone";
|
|
1238
|
-
|
|
1239
|
-
// ============================================================================
|
|
1240
|
-
// HTTP Bearer Auth types
|
|
1241
|
-
// ============================================================================
|
|
1242
|
-
|
|
1243
|
-
/**
|
|
1244
|
-
* Context injected into `auth.http.action()` and `auth.http.route()` handlers.
|
|
1245
|
-
*
|
|
1246
|
-
* The handler's `ctx` receives these fields after Bearer token verification:
|
|
1247
|
-
*
|
|
1248
|
-
* ```ts
|
|
1249
|
-
* auth.http.route(http, {
|
|
1250
|
-
* path: "/api/data",
|
|
1251
|
-
* method: "GET",
|
|
1252
|
-
* handler: async (ctx, request) => {
|
|
1253
|
-
* ctx.key.userId; // owner of the API key
|
|
1254
|
-
* ctx.key.keyId; // the key document ID
|
|
1255
|
-
* ctx.key.scopes.can("data", "read"); // scope check
|
|
1256
|
-
* },
|
|
1257
|
-
* });
|
|
1258
|
-
* ```
|
|
1259
|
-
*/
|
|
1260
|
-
export interface HttpKeyContext {
|
|
1261
|
-
key: {
|
|
1262
|
-
/** The user ID that owns the verified API key. */
|
|
1263
|
-
userId: string;
|
|
1264
|
-
/** The API key document ID. */
|
|
1265
|
-
keyId: string;
|
|
1266
|
-
/** Scope checker for the verified key's permissions. */
|
|
1267
|
-
scopes: ScopeChecker;
|
|
1268
|
-
};
|
|
1269
|
-
}
|
|
1270
|
-
|
|
1271
|
-
/**
|
|
1272
|
-
* CORS configuration for Bearer-authenticated HTTP endpoints.
|
|
1273
|
-
*/
|
|
1274
|
-
export interface CorsConfig {
|
|
1275
|
-
/** Allowed origin(s). Defaults to `"*"`. */
|
|
1276
|
-
origin?: string;
|
|
1277
|
-
/** Allowed HTTP methods. Defaults to `"GET,POST,PUT,PATCH,DELETE,OPTIONS"`. */
|
|
1278
|
-
methods?: string;
|
|
1279
|
-
/** Allowed request headers. Defaults to `"Content-Type,Authorization"`. */
|
|
1280
|
-
headers?: string;
|
|
1281
|
-
}
|
|
1282
|
-
|
|
1283
|
-
/**
|
|
1284
|
-
* Component function references required by core auth runtime.
|
|
1285
|
-
*
|
|
1286
|
-
* @internal Consumers should not depend on this shape — it may change
|
|
1287
|
-
* between minor versions. Pass `components.auth` directly to `createAuth`.
|
|
1288
|
-
*/
|
|
1289
|
-
export type AuthComponentApi = {
|
|
1290
|
-
public: {
|
|
1291
|
-
userGetById: FunctionReference<"query", "internal">;
|
|
1292
|
-
userList: FunctionReference<"query", "internal">;
|
|
1293
|
-
userFindByVerifiedEmail: FunctionReference<"query", "internal">;
|
|
1294
|
-
userFindByVerifiedPhone: FunctionReference<"query", "internal">;
|
|
1295
|
-
userInsert: FunctionReference<"mutation", "internal">;
|
|
1296
|
-
userUpsert: FunctionReference<"mutation", "internal">;
|
|
1297
|
-
userPatch: FunctionReference<"mutation", "internal">;
|
|
1298
|
-
userDelete: FunctionReference<"mutation", "internal">;
|
|
1299
|
-
accountGet: FunctionReference<"query", "internal">;
|
|
1300
|
-
accountGetById: FunctionReference<"query", "internal">;
|
|
1301
|
-
accountInsert: FunctionReference<"mutation", "internal">;
|
|
1302
|
-
accountListByUser: FunctionReference<"query", "internal">;
|
|
1303
|
-
accountPatch: FunctionReference<"mutation", "internal">;
|
|
1304
|
-
accountDelete: FunctionReference<"mutation", "internal">;
|
|
1305
|
-
sessionCreate: FunctionReference<"mutation", "internal">;
|
|
1306
|
-
sessionGetById: FunctionReference<"query", "internal">;
|
|
1307
|
-
sessionDelete: FunctionReference<"mutation", "internal">;
|
|
1308
|
-
sessionListByUser: FunctionReference<"query", "internal">;
|
|
1309
|
-
verifierCreate: FunctionReference<"mutation", "internal">;
|
|
1310
|
-
verifierGetById: FunctionReference<"query", "internal">;
|
|
1311
|
-
verifierGetBySignature: FunctionReference<"query", "internal">;
|
|
1312
|
-
verifierPatch: FunctionReference<"mutation", "internal">;
|
|
1313
|
-
verifierDelete: FunctionReference<"mutation", "internal">;
|
|
1314
|
-
verificationCodeGetByAccountId: FunctionReference<"query", "internal">;
|
|
1315
|
-
verificationCodeGetByCode: FunctionReference<"query", "internal">;
|
|
1316
|
-
verificationCodeCreate: FunctionReference<"mutation", "internal">;
|
|
1317
|
-
verificationCodeDelete: FunctionReference<"mutation", "internal">;
|
|
1318
|
-
refreshTokenCreate: FunctionReference<"mutation", "internal">;
|
|
1319
|
-
refreshTokenGetById: FunctionReference<"query", "internal">;
|
|
1320
|
-
refreshTokenPatch: FunctionReference<"mutation", "internal">;
|
|
1321
|
-
refreshTokenGetChildren: FunctionReference<"query", "internal">;
|
|
1322
|
-
refreshTokenListBySession: FunctionReference<"query", "internal">;
|
|
1323
|
-
refreshTokenDeleteAll: FunctionReference<"mutation", "internal">;
|
|
1324
|
-
refreshTokenGetActive: FunctionReference<"query", "internal">;
|
|
1325
|
-
rateLimitGet: FunctionReference<"query", "internal">;
|
|
1326
|
-
rateLimitCreate: FunctionReference<"mutation", "internal">;
|
|
1327
|
-
rateLimitPatch: FunctionReference<"mutation", "internal">;
|
|
1328
|
-
rateLimitDelete: FunctionReference<"mutation", "internal">;
|
|
1329
|
-
groupCreate: FunctionReference<"mutation", "internal">;
|
|
1330
|
-
groupGet: FunctionReference<"query", "internal">;
|
|
1331
|
-
groupList: FunctionReference<"query", "internal">;
|
|
1332
|
-
groupUpdate: FunctionReference<"mutation", "internal">;
|
|
1333
|
-
groupDelete: FunctionReference<"mutation", "internal">;
|
|
1334
|
-
memberAdd: FunctionReference<"mutation", "internal">;
|
|
1335
|
-
memberGet: FunctionReference<"query", "internal">;
|
|
1336
|
-
memberList: FunctionReference<"query", "internal">;
|
|
1337
|
-
memberGetByGroupAndUser: FunctionReference<"query", "internal">;
|
|
1338
|
-
memberRemove: FunctionReference<"mutation", "internal">;
|
|
1339
|
-
memberUpdate: FunctionReference<"mutation", "internal">;
|
|
1340
|
-
inviteCreate: FunctionReference<"mutation", "internal">;
|
|
1341
|
-
inviteGet: FunctionReference<"query", "internal">;
|
|
1342
|
-
inviteGetByTokenHash: FunctionReference<"query", "internal">;
|
|
1343
|
-
inviteList: FunctionReference<"query", "internal">;
|
|
1344
|
-
inviteAccept: FunctionReference<"mutation", "internal">;
|
|
1345
|
-
inviteAcceptByToken: FunctionReference<"mutation", "internal">;
|
|
1346
|
-
inviteRevoke: FunctionReference<"mutation", "internal">;
|
|
1347
|
-
keyInsert: FunctionReference<"mutation", "internal">;
|
|
1348
|
-
keyGetByHashedKey: FunctionReference<"query", "internal">;
|
|
1349
|
-
keyGetById: FunctionReference<"query", "internal">;
|
|
1350
|
-
keyList: FunctionReference<"query", "internal">;
|
|
1351
|
-
keyPatch: FunctionReference<"mutation", "internal">;
|
|
1352
|
-
keyDelete: FunctionReference<"mutation", "internal">;
|
|
1353
|
-
passkeyInsert: FunctionReference<"mutation", "internal">;
|
|
1354
|
-
passkeyGetByCredentialId: FunctionReference<"query", "internal">;
|
|
1355
|
-
passkeyListByUserId: FunctionReference<"query", "internal">;
|
|
1356
|
-
passkeyUpdateCounter: FunctionReference<"mutation", "internal">;
|
|
1357
|
-
passkeyUpdateMeta: FunctionReference<"mutation", "internal">;
|
|
1358
|
-
passkeyDelete: FunctionReference<"mutation", "internal">;
|
|
1359
|
-
totpInsert: FunctionReference<"mutation", "internal", any, any>;
|
|
1360
|
-
totpGetVerifiedByUserId: FunctionReference<"query", "internal", any, any>;
|
|
1361
|
-
totpListByUserId: FunctionReference<"query", "internal", any, any>;
|
|
1362
|
-
totpGetById: FunctionReference<"query", "internal", any, any>;
|
|
1363
|
-
totpMarkVerified: FunctionReference<"mutation", "internal", any, any>;
|
|
1364
|
-
totpUpdateLastUsed: FunctionReference<"mutation", "internal", any, any>;
|
|
1365
|
-
totpDelete: FunctionReference<"mutation", "internal", any, any>;
|
|
1366
|
-
deviceInsert: FunctionReference<"mutation", "internal", any, any>;
|
|
1367
|
-
deviceGetByCodeHash: FunctionReference<"query", "internal", any, any>;
|
|
1368
|
-
deviceGetByUserCode: FunctionReference<"query", "internal", any, any>;
|
|
1369
|
-
deviceAuthorize: FunctionReference<"mutation", "internal", any, any>;
|
|
1370
|
-
deviceUpdateLastPolled: FunctionReference<"mutation", "internal", any, any>;
|
|
1371
|
-
deviceDelete: FunctionReference<"mutation", "internal", any, any>;
|
|
1372
|
-
enterpriseCreate: FunctionReference<"mutation", "internal", any, any>;
|
|
1373
|
-
enterpriseGet: FunctionReference<"query", "internal", any, any>;
|
|
1374
|
-
enterpriseGetByGroup: FunctionReference<"query", "internal", any, any>;
|
|
1375
|
-
enterpriseGetByDomain: FunctionReference<"query", "internal", any, any>;
|
|
1376
|
-
enterpriseList: FunctionReference<"query", "internal", any, any>;
|
|
1377
|
-
enterpriseUpdate: FunctionReference<"mutation", "internal", any, any>;
|
|
1378
|
-
enterpriseDelete: FunctionReference<"mutation", "internal", any, any>;
|
|
1379
|
-
enterpriseDomainAdd: FunctionReference<"mutation", "internal", any, any>;
|
|
1380
|
-
enterpriseDomainList: FunctionReference<"query", "internal", any, any>;
|
|
1381
|
-
enterpriseDomainDelete: FunctionReference<"mutation", "internal", any, any>;
|
|
1382
|
-
enterpriseDomainVerificationGet: FunctionReference<
|
|
1383
|
-
"query",
|
|
1384
|
-
"internal",
|
|
1385
|
-
any,
|
|
1386
|
-
any
|
|
1387
|
-
>;
|
|
1388
|
-
enterpriseDomainVerificationUpsert: FunctionReference<
|
|
1389
|
-
"mutation",
|
|
1390
|
-
"internal",
|
|
1391
|
-
any,
|
|
1392
|
-
any
|
|
1393
|
-
>;
|
|
1394
|
-
enterpriseDomainVerificationDelete: FunctionReference<
|
|
1395
|
-
"mutation",
|
|
1396
|
-
"internal",
|
|
1397
|
-
any,
|
|
1398
|
-
any
|
|
1399
|
-
>;
|
|
1400
|
-
enterpriseDomainVerify: FunctionReference<"mutation", "internal", any, any>;
|
|
1401
|
-
enterpriseSecretUpsert: FunctionReference<"mutation", "internal", any, any>;
|
|
1402
|
-
enterpriseSecretGet: FunctionReference<"query", "internal", any, any>;
|
|
1403
|
-
enterpriseSecretDelete: FunctionReference<"mutation", "internal", any, any>;
|
|
1404
|
-
enterpriseScimConfigUpsert: FunctionReference<
|
|
1405
|
-
"mutation",
|
|
1406
|
-
"internal",
|
|
1407
|
-
any,
|
|
1408
|
-
any
|
|
1409
|
-
>;
|
|
1410
|
-
enterpriseScimConfigGetByEnterprise: FunctionReference<
|
|
1411
|
-
"query",
|
|
1412
|
-
"internal",
|
|
1413
|
-
any,
|
|
1414
|
-
any
|
|
1415
|
-
>;
|
|
1416
|
-
enterpriseScimConfigGetByTokenHash: FunctionReference<
|
|
1417
|
-
"query",
|
|
1418
|
-
"internal",
|
|
1419
|
-
any,
|
|
1420
|
-
any
|
|
1421
|
-
>;
|
|
1422
|
-
enterpriseScimIdentityGet: FunctionReference<"query", "internal", any, any>;
|
|
1423
|
-
enterpriseScimIdentityGetByUser: FunctionReference<
|
|
1424
|
-
"query",
|
|
1425
|
-
"internal",
|
|
1426
|
-
any,
|
|
1427
|
-
any
|
|
1428
|
-
>;
|
|
1429
|
-
enterpriseScimIdentityGetByEnterpriseAndUser: FunctionReference<
|
|
1430
|
-
"query",
|
|
1431
|
-
"internal",
|
|
1432
|
-
any,
|
|
1433
|
-
any
|
|
1434
|
-
>;
|
|
1435
|
-
enterpriseScimIdentityGetByMappedGroup: FunctionReference<
|
|
1436
|
-
"query",
|
|
1437
|
-
"internal",
|
|
1438
|
-
any,
|
|
1439
|
-
any
|
|
1440
|
-
>;
|
|
1441
|
-
enterpriseScimIdentityListByEnterprise: FunctionReference<
|
|
1442
|
-
"query",
|
|
1443
|
-
"internal",
|
|
1444
|
-
any,
|
|
1445
|
-
any
|
|
1446
|
-
>;
|
|
1447
|
-
enterpriseScimIdentityUpsert: FunctionReference<
|
|
1448
|
-
"mutation",
|
|
1449
|
-
"internal",
|
|
1450
|
-
any,
|
|
1451
|
-
any
|
|
1452
|
-
>;
|
|
1453
|
-
enterpriseScimIdentityDelete: FunctionReference<
|
|
1454
|
-
"mutation",
|
|
1455
|
-
"internal",
|
|
1456
|
-
any,
|
|
1457
|
-
any
|
|
1458
|
-
>;
|
|
1459
|
-
enterpriseAuditEventCreate: FunctionReference<
|
|
1460
|
-
"mutation",
|
|
1461
|
-
"internal",
|
|
1462
|
-
any,
|
|
1463
|
-
any
|
|
1464
|
-
>;
|
|
1465
|
-
enterpriseAuditEventList: FunctionReference<"query", "internal", any, any>;
|
|
1466
|
-
enterpriseWebhookEndpointCreate: FunctionReference<
|
|
1467
|
-
"mutation",
|
|
1468
|
-
"internal",
|
|
1469
|
-
any,
|
|
1470
|
-
any
|
|
1471
|
-
>;
|
|
1472
|
-
enterpriseWebhookEndpointList: FunctionReference<
|
|
1473
|
-
"query",
|
|
1474
|
-
"internal",
|
|
1475
|
-
any,
|
|
1476
|
-
any
|
|
1477
|
-
>;
|
|
1478
|
-
enterpriseWebhookEndpointGet: FunctionReference<
|
|
1479
|
-
"query",
|
|
1480
|
-
"internal",
|
|
1481
|
-
any,
|
|
1482
|
-
any
|
|
1483
|
-
>;
|
|
1484
|
-
enterpriseWebhookEndpointUpdate: FunctionReference<
|
|
1485
|
-
"mutation",
|
|
1486
|
-
"internal",
|
|
1487
|
-
any,
|
|
1488
|
-
any
|
|
1489
|
-
>;
|
|
1490
|
-
enterpriseWebhookDeliveryEnqueue: FunctionReference<
|
|
1491
|
-
"mutation",
|
|
1492
|
-
"internal",
|
|
1493
|
-
any,
|
|
1494
|
-
any
|
|
1495
|
-
>;
|
|
1496
|
-
enterpriseWebhookDeliveryListReady: FunctionReference<
|
|
1497
|
-
"query",
|
|
1498
|
-
"internal",
|
|
1499
|
-
any,
|
|
1500
|
-
any
|
|
1501
|
-
>;
|
|
1502
|
-
enterpriseWebhookDeliveryPatch: FunctionReference<
|
|
1503
|
-
"mutation",
|
|
1504
|
-
"internal",
|
|
1505
|
-
any,
|
|
1506
|
-
any
|
|
1507
|
-
>;
|
|
1508
|
-
};
|
|
1509
|
-
};
|
|
1510
|
-
|
|
1511
|
-
// ============================================================================
|
|
1512
|
-
// Convex document types (merged from convex_types)
|
|
1513
|
-
// ============================================================================
|
|
1514
|
-
|
|
1515
|
-
/**
|
|
1516
|
-
* Convex document from a given table.
|
|
1517
|
-
*/
|
|
1518
|
-
export type GenericDoc<
|
|
1519
|
-
DataModel extends GenericDataModel,
|
|
1520
|
-
TableName extends TableNamesInDataModel<DataModel>,
|
|
1521
|
-
> = DocumentByName<DataModel, TableName> & {
|
|
1522
|
-
_id: GenericId<TableName>;
|
|
1523
|
-
_creationTime: number;
|
|
1524
|
-
};
|
|
1525
|
-
|
|
1526
|
-
/**
|
|
1527
|
-
* @internal
|
|
1528
|
-
*/
|
|
1529
|
-
export type FunctionReferenceFromExport<Export> =
|
|
1530
|
-
Export extends RegisteredQuery<infer Visibility, infer Args, infer Output>
|
|
1531
|
-
? FunctionReference<"query", Visibility, Args, ConvertReturnType<Output>>
|
|
1532
|
-
: Export extends RegisteredMutation<
|
|
1533
|
-
infer Visibility,
|
|
1534
|
-
infer Args,
|
|
1535
|
-
infer Output
|
|
1536
|
-
>
|
|
1537
|
-
? FunctionReference<
|
|
1538
|
-
"mutation",
|
|
1539
|
-
Visibility,
|
|
1540
|
-
Args,
|
|
1541
|
-
ConvertReturnType<Output>
|
|
1542
|
-
>
|
|
1543
|
-
: Export extends RegisteredAction<
|
|
1544
|
-
infer Visibility,
|
|
1545
|
-
infer Args,
|
|
1546
|
-
infer Output
|
|
1547
|
-
>
|
|
1548
|
-
? FunctionReference<
|
|
1549
|
-
"action",
|
|
1550
|
-
Visibility,
|
|
1551
|
-
Args,
|
|
1552
|
-
ConvertReturnType<Output>
|
|
1553
|
-
>
|
|
1554
|
-
: never;
|
|
1555
|
-
|
|
1556
|
-
type ConvertReturnType<T> = UndefinedToNull<Awaited<T>>;
|
|
1557
|
-
|
|
1558
|
-
type UndefinedToNull<T> = T extends void ? null : T;
|
|
1559
|
-
|
|
1560
|
-
// Internal server data-model types (merged from former internalTypes.ts)
|
|
1561
|
-
|
|
1562
|
-
/** Data model derived from the component schema. */
|
|
1563
|
-
export type AuthDataModel = DataModelFromSchemaDefinition<typeof schema>;
|
|
1564
|
-
|
|
1565
|
-
/** Action context typed to the auth component's data model. */
|
|
1566
|
-
export type ActionCtx = GenericActionCtx<AuthDataModel>;
|
|
1567
|
-
|
|
1568
|
-
/** Mutation context typed to the auth component's data model. */
|
|
1569
|
-
export type MutationCtx = GenericMutationCtx<AuthDataModel>;
|
|
1570
|
-
|
|
1571
|
-
/** Query context typed to the auth component's data model. */
|
|
1572
|
-
export type QueryCtx = GenericQueryCtx<AuthDataModel>;
|
|
1573
|
-
|
|
1574
|
-
/** A document from any table in the auth component schema. */
|
|
1575
|
-
export type Doc<T extends TableNamesInDataModel<AuthDataModel>> = GenericDoc<
|
|
1576
|
-
AuthDataModel,
|
|
1577
|
-
T
|
|
1578
|
-
>;
|
|
1579
|
-
|
|
1580
|
-
/** A pair of JWT access token and refresh token. */
|
|
1581
|
-
export type Tokens = { token: string; refreshToken: string };
|
|
1582
|
-
|
|
1583
|
-
/** Session information returned after authentication. */
|
|
1584
|
-
export type SessionInfo = {
|
|
1585
|
-
userId: GenericId<"User">;
|
|
1586
|
-
sessionId: GenericId<"Session">;
|
|
1587
|
-
tokens: Tokens | null;
|
|
1588
|
-
};
|
|
1589
|
-
|
|
1590
|
-
/** Session information with guaranteed non-null tokens. */
|
|
1591
|
-
export type SessionInfoWithTokens = {
|
|
1592
|
-
userId: GenericId<"User">;
|
|
1593
|
-
sessionId: GenericId<"Session">;
|
|
1594
|
-
tokens: Tokens;
|
|
1595
|
-
};
|
|
1596
|
-
|
|
1597
|
-
// ---------------------------------------------------------------------------
|
|
1598
|
-
// Cross-component document shapes
|
|
1599
|
-
// ---------------------------------------------------------------------------
|
|
1600
|
-
// These mirror the component schema tables. They exist so that server-side
|
|
1601
|
-
// code can work with typed results from cross-component queries/mutations
|
|
1602
|
-
// instead of casting to `any` at every field access.
|
|
1603
|
-
|
|
1604
|
-
export type TotpDoc = Infer<typeof vTotpFactorDoc>;
|
|
1605
|
-
|
|
1606
|
-
export type PasskeyDoc = Infer<typeof vPasskeyDoc>;
|
|
1607
|
-
|
|
1608
|
-
export type VerifierDoc = Infer<typeof vAuthVerifierDoc>;
|
|
1609
|
-
|
|
1610
|
-
/**
|
|
1611
|
-
* Cross-component user document shape inferred from the component validator.
|
|
1612
|
-
*
|
|
1613
|
-
* Used by internal typed wrappers (`queryUserById`, etc.) so server code stays
|
|
1614
|
-
* aligned with the component runtime contract. Not intended for consumer use —
|
|
1615
|
-
* consumers should use `UserDoc` (exported from
|
|
1616
|
-
* `@robelest/convex-auth/component`).
|
|
1617
|
-
*
|
|
1618
|
-
* @internal
|
|
1619
|
-
*/
|
|
1620
|
-
export type CrossComponentUserDoc = Infer<typeof vUserDoc>;
|
|
1621
|
-
|
|
1622
|
-
export type KeyDoc = Infer<typeof vApiKeyDoc>;
|
|
1623
|
-
|
|
1624
|
-
// ---------------------------------------------------------------------------
|
|
1625
|
-
// Cross-component wrapper context
|
|
1626
|
-
// ---------------------------------------------------------------------------
|
|
1627
|
-
// Structural type accepted by all wrappers below. Works for both action and
|
|
1628
|
-
// mutation contexts — the only capabilities we need are runQuery / runMutation
|
|
1629
|
-
// and access to the component API via `auth.config.component`.
|
|
1630
|
-
|
|
1631
|
-
/** @internal */
|
|
1632
|
-
export type ComponentCallCtx = {
|
|
1633
|
-
runQuery: GenericActionCtx<AuthDataModel>["runQuery"];
|
|
1634
|
-
runMutation: GenericActionCtx<AuthDataModel>["runMutation"];
|
|
1635
|
-
auth: { config: { component: AuthComponentApi } };
|
|
1636
|
-
};
|
|
1637
|
-
|
|
1638
|
-
// ---------------------------------------------------------------------------
|
|
1639
|
-
// Typed wrappers for cross-component calls
|
|
1640
|
-
// ---------------------------------------------------------------------------
|
|
1641
|
-
// Each wrapper encapsulates the single `as any` cast at the component
|
|
1642
|
-
// boundary so that callers get full type safety on both args and return
|
|
1643
|
-
// values.
|
|
1644
|
-
|
|
1645
|
-
// -- User queries --
|
|
1646
|
-
|
|
1647
|
-
export async function queryUserById(
|
|
1648
|
-
ctx: ComponentCallCtx,
|
|
1649
|
-
userId: string,
|
|
1650
|
-
): Promise<CrossComponentUserDoc | null> {
|
|
1651
|
-
return (await ctx.runQuery(ctx.auth.config.component.public.userGetById, {
|
|
1652
|
-
userId,
|
|
1653
|
-
})) as CrossComponentUserDoc | null;
|
|
1654
|
-
}
|
|
1655
|
-
|
|
1656
|
-
export async function queryUserByVerifiedEmail(
|
|
1657
|
-
ctx: ComponentCallCtx,
|
|
1658
|
-
email: string,
|
|
1659
|
-
): Promise<CrossComponentUserDoc | null> {
|
|
1660
|
-
return (await ctx.runQuery(
|
|
1661
|
-
ctx.auth.config.component.public.userFindByVerifiedEmail,
|
|
1662
|
-
{ email },
|
|
1663
|
-
)) as CrossComponentUserDoc | null;
|
|
1664
|
-
}
|
|
1665
|
-
|
|
1666
|
-
// -- Verifier queries / mutations --
|
|
1667
|
-
|
|
1668
|
-
export async function queryVerifierById(
|
|
1669
|
-
ctx: ComponentCallCtx,
|
|
1670
|
-
verifierId: string,
|
|
1671
|
-
): Promise<VerifierDoc | null> {
|
|
1672
|
-
return (await ctx.runQuery(ctx.auth.config.component.public.verifierGetById, {
|
|
1673
|
-
verifierId,
|
|
1674
|
-
})) as VerifierDoc | null;
|
|
1675
|
-
}
|
|
1676
|
-
|
|
1677
|
-
export async function mutateVerifierDelete(
|
|
1678
|
-
ctx: ComponentCallCtx,
|
|
1679
|
-
verifierId: string,
|
|
1680
|
-
): Promise<void> {
|
|
1681
|
-
await ctx.runMutation(ctx.auth.config.component.public.verifierDelete, {
|
|
1682
|
-
verifierId,
|
|
1683
|
-
});
|
|
1684
|
-
}
|
|
1685
|
-
|
|
1686
|
-
// -- TOTP queries / mutations --
|
|
1687
|
-
|
|
1688
|
-
export async function queryTotpById(
|
|
1689
|
-
ctx: ComponentCallCtx,
|
|
1690
|
-
totpId: string,
|
|
1691
|
-
): Promise<TotpDoc | null> {
|
|
1692
|
-
return (await ctx.runQuery(ctx.auth.config.component.public.totpGetById, {
|
|
1693
|
-
totpId,
|
|
1694
|
-
})) as TotpDoc | null;
|
|
1695
|
-
}
|
|
1696
|
-
|
|
1697
|
-
export async function queryTotpVerifiedByUserId(
|
|
1698
|
-
ctx: ComponentCallCtx,
|
|
1699
|
-
userId: string,
|
|
1700
|
-
): Promise<TotpDoc | null> {
|
|
1701
|
-
return (await ctx.runQuery(
|
|
1702
|
-
ctx.auth.config.component.public.totpGetVerifiedByUserId,
|
|
1703
|
-
{ userId },
|
|
1704
|
-
)) as TotpDoc | null;
|
|
1705
|
-
}
|
|
1706
|
-
|
|
1707
|
-
export async function mutateTotpInsert(
|
|
1708
|
-
ctx: ComponentCallCtx,
|
|
1709
|
-
args: {
|
|
1710
|
-
userId: string;
|
|
1711
|
-
secret: ArrayBuffer;
|
|
1712
|
-
digits: number;
|
|
1713
|
-
period: number;
|
|
1714
|
-
verified: boolean;
|
|
1715
|
-
name?: string;
|
|
1716
|
-
createdAt: number;
|
|
1717
|
-
},
|
|
1718
|
-
): Promise<string> {
|
|
1719
|
-
return (await ctx.runMutation(
|
|
1720
|
-
ctx.auth.config.component.public.totpInsert,
|
|
1721
|
-
args,
|
|
1722
|
-
)) as string;
|
|
1723
|
-
}
|
|
1724
|
-
|
|
1725
|
-
export async function mutateTotpMarkVerified(
|
|
1726
|
-
ctx: ComponentCallCtx,
|
|
1727
|
-
totpId: string,
|
|
1728
|
-
lastUsedAt: number,
|
|
1729
|
-
): Promise<void> {
|
|
1730
|
-
await ctx.runMutation(ctx.auth.config.component.public.totpMarkVerified, {
|
|
1731
|
-
totpId,
|
|
1732
|
-
lastUsedAt,
|
|
1733
|
-
});
|
|
1734
|
-
}
|
|
1735
|
-
|
|
1736
|
-
export async function mutateTotpUpdateLastUsed(
|
|
1737
|
-
ctx: ComponentCallCtx,
|
|
1738
|
-
totpId: string,
|
|
1739
|
-
lastUsedAt: number,
|
|
1740
|
-
): Promise<void> {
|
|
1741
|
-
await ctx.runMutation(ctx.auth.config.component.public.totpUpdateLastUsed, {
|
|
1742
|
-
totpId,
|
|
1743
|
-
lastUsedAt,
|
|
1744
|
-
});
|
|
1745
|
-
}
|
|
1746
|
-
|
|
1747
|
-
// -- Passkey queries / mutations --
|
|
1748
|
-
|
|
1749
|
-
export async function queryPasskeysByUserId(
|
|
1750
|
-
ctx: ComponentCallCtx,
|
|
1751
|
-
userId: string,
|
|
1752
|
-
): Promise<PasskeyDoc[]> {
|
|
1753
|
-
return (await ctx.runQuery(
|
|
1754
|
-
ctx.auth.config.component.public.passkeyListByUserId,
|
|
1755
|
-
{ userId },
|
|
1756
|
-
)) as PasskeyDoc[];
|
|
1757
|
-
}
|
|
1758
|
-
|
|
1759
|
-
export async function queryPasskeyByCredentialId(
|
|
1760
|
-
ctx: ComponentCallCtx,
|
|
1761
|
-
credentialId: string,
|
|
1762
|
-
): Promise<PasskeyDoc | null> {
|
|
1763
|
-
return (await ctx.runQuery(
|
|
1764
|
-
ctx.auth.config.component.public.passkeyGetByCredentialId,
|
|
1765
|
-
{ credentialId },
|
|
1766
|
-
)) as PasskeyDoc | null;
|
|
1767
|
-
}
|
|
1768
|
-
|
|
1769
|
-
export async function mutatePasskeyInsert(
|
|
1770
|
-
ctx: ComponentCallCtx,
|
|
1771
|
-
args: {
|
|
1772
|
-
userId: string;
|
|
1773
|
-
credentialId: string;
|
|
1774
|
-
publicKey: ArrayBuffer | ArrayBufferLike;
|
|
1775
|
-
algorithm: number;
|
|
1776
|
-
counter: number;
|
|
1777
|
-
transports?: string[];
|
|
1778
|
-
deviceType: string;
|
|
1779
|
-
backedUp: boolean;
|
|
1780
|
-
name?: string;
|
|
1781
|
-
createdAt: number;
|
|
1782
|
-
},
|
|
1783
|
-
): Promise<string> {
|
|
1784
|
-
return (await ctx.runMutation(
|
|
1785
|
-
ctx.auth.config.component.public.passkeyInsert,
|
|
1786
|
-
args,
|
|
1787
|
-
)) as string;
|
|
1788
|
-
}
|
|
1789
|
-
|
|
1790
|
-
export async function mutatePasskeyUpdateCounter(
|
|
1791
|
-
ctx: ComponentCallCtx,
|
|
1792
|
-
passkeyId: string,
|
|
1793
|
-
counter: number,
|
|
1794
|
-
lastUsedAt: number,
|
|
1795
|
-
): Promise<void> {
|
|
1796
|
-
await ctx.runMutation(ctx.auth.config.component.public.passkeyUpdateCounter, {
|
|
1797
|
-
passkeyId,
|
|
1798
|
-
counter,
|
|
1799
|
-
lastUsedAt,
|
|
1800
|
-
});
|
|
1801
|
-
}
|
|
1802
|
-
|
|
1803
|
-
// -- Key queries / mutations --
|
|
1804
|
-
|
|
1805
|
-
export async function mutateKeyInsert(
|
|
1806
|
-
ctx: ComponentCallCtx,
|
|
1807
|
-
args: {
|
|
1808
|
-
userId: string;
|
|
1809
|
-
prefix: string;
|
|
1810
|
-
hashedKey: string;
|
|
1811
|
-
name: string;
|
|
1812
|
-
scopes: Array<{ resource: string; actions: string[] }>;
|
|
1813
|
-
rateLimit?: { maxRequests: number; windowMs: number };
|
|
1814
|
-
expiresAt?: number;
|
|
1815
|
-
},
|
|
1816
|
-
): Promise<string> {
|
|
1817
|
-
return (await ctx.runMutation(
|
|
1818
|
-
ctx.auth.config.component.public.keyInsert,
|
|
1819
|
-
args,
|
|
1820
|
-
)) as string;
|
|
1821
|
-
}
|
|
1822
|
-
|
|
1823
|
-
export async function queryKeysByUserId(
|
|
1824
|
-
ctx: ComponentCallCtx,
|
|
1825
|
-
userId: string,
|
|
1826
|
-
): Promise<KeyDoc[]> {
|
|
1827
|
-
const items: KeyDoc[] = [];
|
|
1828
|
-
let cursor: string | null = null;
|
|
1829
|
-
do {
|
|
1830
|
-
const page = (await ctx.runQuery(ctx.auth.config.component.public.keyList, {
|
|
1831
|
-
where: { userId },
|
|
1832
|
-
limit: 100,
|
|
1833
|
-
cursor,
|
|
1834
|
-
})) as {
|
|
1835
|
-
items: KeyDoc[];
|
|
1836
|
-
nextCursor: string | null;
|
|
1837
|
-
};
|
|
1838
|
-
items.push(...page.items);
|
|
1839
|
-
cursor = page.nextCursor;
|
|
1840
|
-
} while (cursor !== null);
|
|
1841
|
-
return items;
|
|
1842
|
-
}
|
|
1843
|
-
|
|
1844
|
-
export async function queryKeyById(
|
|
1845
|
-
ctx: ComponentCallCtx,
|
|
1846
|
-
keyId: string,
|
|
1847
|
-
): Promise<KeyDoc | null> {
|
|
1848
|
-
return (await ctx.runQuery(ctx.auth.config.component.public.keyGetById, {
|
|
1849
|
-
keyId,
|
|
1850
|
-
})) as KeyDoc | null;
|
|
1851
|
-
}
|
|
1852
|
-
|
|
1853
|
-
export async function mutateKeyPatch(
|
|
1854
|
-
ctx: ComponentCallCtx,
|
|
1855
|
-
keyId: string,
|
|
1856
|
-
data: Record<string, unknown>,
|
|
1857
|
-
): Promise<void> {
|
|
1858
|
-
await ctx.runMutation(ctx.auth.config.component.public.keyPatch, {
|
|
1859
|
-
keyId,
|
|
1860
|
-
data,
|
|
1861
|
-
});
|
|
1862
|
-
}
|
|
1863
|
-
|
|
1864
|
-
export async function mutateKeyDelete(
|
|
1865
|
-
ctx: ComponentCallCtx,
|
|
1866
|
-
keyId: string,
|
|
1867
|
-
): Promise<void> {
|
|
1868
|
-
await ctx.runMutation(ctx.auth.config.component.public.keyDelete, { keyId });
|
|
1869
|
-
}
|
|
1870
|
-
|
|
1871
|
-
// -- Device authorization queries / mutations --
|
|
1872
|
-
|
|
1873
|
-
export type DeviceDoc = Infer<typeof vDeviceCodeDoc>;
|
|
1874
|
-
|
|
1875
|
-
export async function mutateDeviceInsert(
|
|
1876
|
-
ctx: ComponentCallCtx,
|
|
1877
|
-
args: {
|
|
1878
|
-
deviceCodeHash: string;
|
|
1879
|
-
userCode: string;
|
|
1880
|
-
expiresAt: number;
|
|
1881
|
-
interval: number;
|
|
1882
|
-
status: "pending" | "authorized" | "denied";
|
|
1883
|
-
},
|
|
1884
|
-
): Promise<string> {
|
|
1885
|
-
return (await ctx.runMutation(
|
|
1886
|
-
ctx.auth.config.component.public.deviceInsert,
|
|
1887
|
-
args,
|
|
1888
|
-
)) as string;
|
|
1889
|
-
}
|
|
1890
|
-
|
|
1891
|
-
export async function queryDeviceByCodeHash(
|
|
1892
|
-
ctx: ComponentCallCtx,
|
|
1893
|
-
deviceCodeHash: string,
|
|
1894
|
-
): Promise<DeviceDoc | null> {
|
|
1895
|
-
return (await ctx.runQuery(
|
|
1896
|
-
ctx.auth.config.component.public.deviceGetByCodeHash,
|
|
1897
|
-
{ deviceCodeHash },
|
|
1898
|
-
)) as DeviceDoc | null;
|
|
1899
|
-
}
|
|
1900
|
-
|
|
1901
|
-
export async function queryDeviceByUserCode(
|
|
1902
|
-
ctx: ComponentCallCtx,
|
|
1903
|
-
userCode: string,
|
|
1904
|
-
): Promise<DeviceDoc | null> {
|
|
1905
|
-
return (await ctx.runQuery(
|
|
1906
|
-
ctx.auth.config.component.public.deviceGetByUserCode,
|
|
1907
|
-
{ userCode },
|
|
1908
|
-
)) as DeviceDoc | null;
|
|
1909
|
-
}
|
|
1910
|
-
|
|
1911
|
-
export async function mutateDeviceAuthorize(
|
|
1912
|
-
ctx: ComponentCallCtx,
|
|
1913
|
-
deviceId: string,
|
|
1914
|
-
userId: string,
|
|
1915
|
-
sessionId: string,
|
|
1916
|
-
): Promise<void> {
|
|
1917
|
-
await ctx.runMutation(ctx.auth.config.component.public.deviceAuthorize, {
|
|
1918
|
-
deviceId,
|
|
1919
|
-
userId,
|
|
1920
|
-
sessionId,
|
|
1921
|
-
});
|
|
1922
|
-
}
|
|
1923
|
-
|
|
1924
|
-
export async function mutateDeviceUpdateLastPolled(
|
|
1925
|
-
ctx: ComponentCallCtx,
|
|
1926
|
-
deviceId: string,
|
|
1927
|
-
lastPolledAt: number,
|
|
1928
|
-
): Promise<void> {
|
|
1929
|
-
await ctx.runMutation(
|
|
1930
|
-
ctx.auth.config.component.public.deviceUpdateLastPolled,
|
|
1931
|
-
{ deviceId, lastPolledAt },
|
|
1932
|
-
);
|
|
1933
|
-
}
|
|
1934
|
-
|
|
1935
|
-
export async function mutateDeviceDelete(
|
|
1936
|
-
ctx: ComponentCallCtx,
|
|
1937
|
-
deviceId: string,
|
|
1938
|
-
): Promise<void> {
|
|
1939
|
-
await ctx.runMutation(ctx.auth.config.component.public.deviceDelete, {
|
|
1940
|
-
deviceId,
|
|
1941
|
-
});
|
|
1942
|
-
}
|