@robelest/convex-auth 0.0.4-preview.18 → 0.0.4-preview.19
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 +6 -3
- package/dist/authorization/index.d.ts +46 -0
- package/dist/authorization/index.d.ts.map +1 -1
- package/dist/authorization/index.js +46 -0
- package/dist/authorization/index.js.map +1 -1
- package/dist/bin.cjs +21 -13
- package/dist/client/core/types.d.ts +20 -0
- package/dist/client/core/types.d.ts.map +1 -0
- package/dist/client/index.d.ts +2 -16
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +67 -565
- package/dist/client/index.js.map +1 -1
- package/dist/component/_generated/api.d.ts +40 -12
- package/dist/component/_generated/api.d.ts.map +1 -1
- package/dist/component/_generated/api.js.map +1 -1
- package/dist/component/_generated/component.d.ts +1306 -1344
- package/dist/component/_generated/component.d.ts.map +1 -1
- package/dist/component/client/core/types.d.ts +2 -0
- package/dist/component/client/index.d.ts +2 -2
- package/dist/component/model.d.ts +80 -80
- package/dist/component/model.d.ts.map +1 -1
- package/dist/component/model.js +5 -1
- package/dist/component/model.js.map +1 -1
- package/dist/component/providers/credentials.d.ts +3 -2
- package/dist/component/providers/credentials.d.ts.map +1 -1
- package/dist/component/providers/email.d.ts +30 -0
- package/dist/component/providers/email.d.ts.map +1 -1
- package/dist/component/providers/phone.d.ts +28 -0
- package/dist/component/providers/phone.d.ts.map +1 -1
- package/dist/component/public/enterprise/audit.d.ts +73 -0
- package/dist/component/public/enterprise/audit.d.ts.map +1 -0
- package/dist/component/public/enterprise/audit.js +108 -0
- package/dist/component/public/enterprise/audit.js.map +1 -0
- package/dist/component/public/enterprise/core.d.ts +176 -0
- package/dist/component/public/enterprise/core.d.ts.map +1 -0
- package/dist/component/public/enterprise/core.js +292 -0
- package/dist/component/public/enterprise/core.js.map +1 -0
- package/dist/component/public/enterprise/domains.d.ts +174 -0
- package/dist/component/public/enterprise/domains.d.ts.map +1 -0
- package/dist/component/public/enterprise/domains.js +271 -0
- package/dist/component/public/enterprise/domains.js.map +1 -0
- package/dist/component/public/enterprise/scim.d.ts +245 -0
- package/dist/component/public/enterprise/scim.d.ts.map +1 -0
- package/dist/component/public/enterprise/scim.js +344 -0
- package/dist/component/public/enterprise/scim.js.map +1 -0
- package/dist/component/public/enterprise/secrets.d.ts +78 -0
- package/dist/component/public/enterprise/secrets.d.ts.map +1 -0
- package/dist/component/public/enterprise/secrets.js +118 -0
- package/dist/component/public/enterprise/secrets.js.map +1 -0
- package/dist/component/public/enterprise/webhooks.d.ts +211 -0
- package/dist/component/public/enterprise/webhooks.d.ts.map +1 -0
- package/dist/component/public/enterprise/webhooks.js +300 -0
- package/dist/component/public/enterprise/webhooks.js.map +1 -0
- package/dist/component/public/factors/devices.d.ts +157 -0
- package/dist/component/public/factors/devices.d.ts.map +1 -0
- package/dist/component/public/factors/devices.js +216 -0
- package/dist/component/public/factors/devices.js.map +1 -0
- package/dist/component/public/factors/passkeys.d.ts +175 -0
- package/dist/component/public/factors/passkeys.d.ts.map +1 -0
- package/dist/component/public/factors/passkeys.js +238 -0
- package/dist/component/public/factors/passkeys.js.map +1 -0
- package/dist/component/public/factors/totp.d.ts +189 -0
- package/dist/component/public/factors/totp.d.ts.map +1 -0
- package/dist/component/public/factors/totp.js +254 -0
- package/dist/component/public/factors/totp.js.map +1 -0
- package/dist/component/public/groups/core.d.ts +137 -0
- package/dist/component/public/groups/core.d.ts.map +1 -0
- package/dist/component/public/groups/core.js +321 -0
- package/dist/component/public/groups/core.js.map +1 -0
- package/dist/component/public/groups/invites.d.ts +217 -0
- package/dist/component/public/groups/invites.d.ts.map +1 -0
- package/dist/component/public/groups/invites.js +457 -0
- package/dist/component/public/groups/invites.js.map +1 -0
- package/dist/component/public/groups/members.d.ts +204 -0
- package/dist/component/public/groups/members.d.ts.map +1 -0
- package/dist/component/public/groups/members.js +355 -0
- package/dist/component/public/groups/members.js.map +1 -0
- package/dist/component/public/identity/accounts.d.ts +147 -0
- package/dist/component/public/identity/accounts.d.ts.map +1 -0
- package/dist/component/public/identity/accounts.js +200 -0
- package/dist/component/public/identity/accounts.js.map +1 -0
- package/dist/component/public/identity/codes.d.ts +104 -0
- package/dist/component/public/identity/codes.d.ts.map +1 -0
- package/dist/component/public/identity/codes.js +140 -0
- package/dist/component/public/identity/codes.js.map +1 -0
- package/dist/component/public/identity/sessions.d.ts +128 -0
- package/dist/component/public/identity/sessions.d.ts.map +1 -0
- package/dist/component/public/identity/sessions.js +192 -0
- package/dist/component/public/identity/sessions.js.map +1 -0
- package/dist/component/public/identity/tokens.d.ts +169 -0
- package/dist/component/public/identity/tokens.d.ts.map +1 -0
- package/dist/component/public/identity/tokens.js +227 -0
- package/dist/component/public/identity/tokens.js.map +1 -0
- package/dist/component/public/identity/users.d.ts +212 -0
- package/dist/component/public/identity/users.d.ts.map +1 -0
- package/dist/component/public/identity/users.js +311 -0
- package/dist/component/public/identity/users.js.map +1 -0
- package/dist/component/public/identity/verifiers.d.ts +116 -0
- package/dist/component/public/identity/verifiers.d.ts.map +1 -0
- package/dist/component/public/identity/verifiers.js +154 -0
- package/dist/component/public/identity/verifiers.js.map +1 -0
- package/dist/component/public/security/keys.d.ts +209 -0
- package/dist/component/public/security/keys.d.ts.map +1 -0
- package/dist/component/public/security/keys.js +319 -0
- package/dist/component/public/security/keys.js.map +1 -0
- package/dist/component/public/security/limits.d.ts +114 -0
- package/dist/component/public/security/limits.d.ts.map +1 -0
- package/dist/component/public/security/limits.js +169 -0
- package/dist/component/public/security/limits.js.map +1 -0
- package/dist/component/public.d.ts +22 -7
- package/dist/component/public.js +21 -6
- package/dist/component/schema.d.ts +288 -288
- package/dist/component/server/auth.d.ts +212 -25
- package/dist/component/server/auth.d.ts.map +1 -1
- package/dist/component/server/auth.js +68 -4
- package/dist/component/server/auth.js.map +1 -1
- package/dist/component/server/authError.js +34 -0
- package/dist/component/server/authError.js.map +1 -0
- package/dist/component/server/{providers.js → config.js} +2 -2
- package/dist/component/server/config.js.map +1 -0
- package/dist/component/server/{domains/core.js → core.js} +107 -88
- package/dist/component/server/core.js.map +1 -0
- package/dist/component/server/{provider.js → crypto.js} +3 -3
- package/dist/component/server/crypto.js.map +1 -0
- package/dist/component/server/device.js +1 -1
- package/dist/component/server/device.js.map +1 -1
- package/dist/component/server/enterprise/config.js +46 -0
- package/dist/component/server/enterprise/config.js.map +1 -0
- package/dist/component/server/{domains/sso.js → enterprise/domain.js} +6 -5
- package/dist/component/server/enterprise/domain.js.map +1 -0
- package/dist/component/server/enterprise/http.js +766 -0
- package/dist/component/server/enterprise/http.js.map +1 -0
- package/dist/component/server/enterprise/oidc.js +248 -0
- package/dist/component/server/enterprise/oidc.js.map +1 -0
- package/dist/component/server/enterprise/policy.js +85 -0
- package/dist/component/server/enterprise/policy.js.map +1 -0
- package/dist/component/server/enterprise/saml.js +338 -0
- package/dist/component/server/enterprise/saml.js.map +1 -0
- package/dist/component/server/enterprise/scim.js +97 -0
- package/dist/component/server/enterprise/scim.js.map +1 -0
- package/dist/component/server/enterprise/shared.js +51 -0
- package/dist/component/server/enterprise/shared.js.map +1 -0
- package/dist/component/server/errors.js.map +1 -1
- package/dist/component/server/http.js +2 -1
- package/dist/component/server/http.js.map +1 -1
- package/dist/component/server/identity.js +1 -1
- package/dist/component/server/identity.js.map +1 -1
- package/dist/component/server/{ratelimit.js → limits.js} +3 -3
- package/dist/component/server/limits.js.map +1 -0
- package/dist/component/server/mutations/account.js +3 -3
- package/dist/component/server/mutations/account.js.map +1 -1
- package/dist/component/server/mutations/code.js +2 -2
- package/dist/component/server/mutations/code.js.map +1 -1
- package/dist/component/server/mutations/invalidate.js +1 -1
- package/dist/component/server/mutations/invalidate.js.map +1 -1
- package/dist/component/server/mutations/oauth.js +5 -3
- package/dist/component/server/mutations/oauth.js.map +1 -1
- package/dist/component/server/mutations/refresh.js +1 -1
- package/dist/component/server/mutations/refresh.js.map +1 -1
- package/dist/component/server/mutations/register.js +3 -3
- package/dist/component/server/mutations/register.js.map +1 -1
- package/dist/component/server/mutations/retrieve.js +4 -4
- package/dist/component/server/mutations/retrieve.js.map +1 -1
- package/dist/component/server/mutations/signature.js +2 -2
- package/dist/component/server/mutations/signature.js.map +1 -1
- package/dist/component/server/mutations/signin.js +1 -1
- package/dist/component/server/mutations/signin.js.map +1 -1
- package/dist/component/server/mutations/signout.js +1 -1
- package/dist/component/server/mutations/signout.js.map +1 -1
- package/dist/component/server/mutations/store/refs.js +15 -0
- package/dist/component/server/mutations/store/refs.js.map +1 -0
- package/dist/component/server/mutations/store.js +80 -10
- package/dist/component/server/mutations/store.js.map +1 -1
- package/dist/component/server/mutations/verifier.js +1 -1
- package/dist/component/server/mutations/verifier.js.map +1 -1
- package/dist/component/server/mutations/verify.js +4 -3
- package/dist/component/server/mutations/verify.js.map +1 -1
- package/dist/component/server/oauth.js +1 -1
- package/dist/component/server/oauth.js.map +1 -1
- package/dist/component/server/passkey.js +2 -1
- package/dist/component/server/passkey.js.map +1 -1
- package/dist/component/server/redirects.js +1 -1
- package/dist/component/server/redirects.js.map +1 -1
- package/dist/component/server/refresh.js +1 -1
- package/dist/component/server/refresh.js.map +1 -1
- package/dist/component/server/{factory.d.ts → runtime.d.ts} +2 -2
- package/dist/component/server/runtime.d.ts.map +1 -0
- package/dist/component/server/runtime.js +413 -0
- package/dist/component/server/runtime.js.map +1 -0
- package/dist/component/server/signin.js +2 -1
- package/dist/component/server/signin.js.map +1 -1
- package/dist/component/server/totp.js +2 -1
- package/dist/component/server/totp.js.map +1 -1
- package/dist/component/server/types.d.ts +225 -41
- package/dist/component/server/types.d.ts.map +1 -1
- package/dist/component/server/types.js.map +1 -1
- package/dist/component/server/users.js +1 -1
- package/dist/component/server/users.js.map +1 -1
- package/dist/component/server/utils.js +1 -1
- package/dist/component/server/utils.js.map +1 -1
- package/dist/core/types.d.ts +369 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/factors/device.js +105 -0
- package/dist/factors/device.js.map +1 -0
- package/dist/factors/passkey.js +181 -0
- package/dist/factors/passkey.js.map +1 -0
- package/dist/factors/totp.js +122 -0
- package/dist/factors/totp.js.map +1 -0
- package/dist/providers/credentials.d.ts +5 -2
- package/dist/providers/credentials.d.ts.map +1 -1
- package/dist/providers/credentials.js +2 -0
- package/dist/providers/credentials.js.map +1 -1
- package/dist/providers/email.d.ts +30 -0
- package/dist/providers/email.d.ts.map +1 -1
- package/dist/providers/email.js +24 -0
- package/dist/providers/email.js.map +1 -1
- package/dist/providers/phone.d.ts +28 -0
- package/dist/providers/phone.d.ts.map +1 -1
- package/dist/providers/phone.js +22 -0
- package/dist/providers/phone.js.map +1 -1
- package/dist/runtime/browser.js +68 -0
- package/dist/runtime/browser.js.map +1 -0
- package/dist/runtime/invite.js +51 -0
- package/dist/runtime/invite.js.map +1 -0
- package/dist/runtime/proxy.js +70 -0
- package/dist/runtime/proxy.js.map +1 -0
- package/dist/runtime/storage.js +37 -0
- package/dist/runtime/storage.js.map +1 -0
- package/dist/server/auth.d.ts +218 -28
- package/dist/server/auth.d.ts.map +1 -1
- package/dist/server/auth.js +68 -4
- package/dist/server/auth.js.map +1 -1
- package/dist/server/{fx.d.ts → authError.d.ts} +25 -15
- package/dist/server/authError.d.ts.map +1 -0
- package/dist/server/authError.js +34 -0
- package/dist/server/authError.js.map +1 -0
- package/dist/server/{providers.js → config.js} +2 -2
- package/dist/server/config.js.map +1 -0
- package/dist/server/core.d.ts +1436 -0
- package/dist/server/core.d.ts.map +1 -0
- package/dist/server/{domains/core.js → core.js} +107 -88
- package/dist/server/core.js.map +1 -0
- package/dist/server/{provider.d.ts → crypto.d.ts} +2 -2
- package/dist/server/crypto.d.ts.map +1 -0
- package/dist/server/{provider.js → crypto.js} +3 -3
- package/dist/{component/server/provider.js.map → server/crypto.js.map} +1 -1
- package/dist/server/device.js +1 -1
- package/dist/server/device.js.map +1 -1
- package/dist/server/enterprise/config.js +46 -0
- package/dist/server/enterprise/config.js.map +1 -0
- package/dist/server/{domains/sso.d.ts → enterprise/domain.d.ts} +4 -4
- package/dist/server/enterprise/domain.d.ts.map +1 -0
- package/dist/server/{domains/sso.js → enterprise/domain.js} +6 -5
- package/dist/server/enterprise/domain.js.map +1 -0
- package/dist/server/enterprise/http.d.ts +26 -0
- package/dist/server/enterprise/http.d.ts.map +1 -0
- package/dist/server/enterprise/http.js +766 -0
- package/dist/server/enterprise/http.js.map +1 -0
- package/dist/server/enterprise/oidc.js +248 -0
- package/dist/server/enterprise/oidc.js.map +1 -0
- package/dist/server/enterprise/policy.js +85 -0
- package/dist/server/enterprise/policy.js.map +1 -0
- package/dist/server/enterprise/saml.d.ts +1 -0
- package/dist/server/enterprise/saml.js +338 -0
- package/dist/server/enterprise/saml.js.map +1 -0
- package/dist/server/enterprise/scim.d.ts +1 -0
- package/dist/server/enterprise/scim.js +97 -0
- package/dist/server/enterprise/scim.js.map +1 -0
- package/dist/server/enterprise/shared.d.ts +5 -0
- package/dist/server/enterprise/shared.d.ts.map +1 -0
- package/dist/server/enterprise/shared.js +51 -0
- package/dist/server/enterprise/shared.js.map +1 -0
- package/dist/server/enterprise/validators.d.ts +1 -0
- package/dist/server/{enterpriseValidators.js → enterprise/validators.js} +2 -2
- package/dist/server/enterprise/validators.js.map +1 -0
- package/dist/server/errors.d.ts +2 -0
- package/dist/server/errors.d.ts.map +1 -1
- package/dist/server/errors.js +2 -0
- package/dist/server/errors.js.map +1 -1
- package/dist/server/http.d.ts +2 -2
- package/dist/server/http.d.ts.map +1 -1
- package/dist/server/http.js +2 -1
- package/dist/server/http.js.map +1 -1
- package/dist/server/identity.js +1 -1
- package/dist/server/identity.js.map +1 -1
- package/dist/server/index.d.ts +4 -705
- package/dist/server/index.js +4 -1367
- package/dist/server/limits.d.ts +1 -0
- package/dist/server/{ratelimit.js → limits.js} +3 -3
- package/dist/server/limits.js.map +1 -0
- package/dist/server/mounts.d.ts +647 -0
- package/dist/server/mounts.d.ts.map +1 -0
- package/dist/server/mounts.js +643 -0
- package/dist/server/mounts.js.map +1 -0
- package/dist/server/mutations/account.d.ts +8 -8
- package/dist/server/mutations/account.js +3 -3
- package/dist/server/mutations/account.js.map +1 -1
- package/dist/server/mutations/code.d.ts +13 -13
- package/dist/server/mutations/code.js +2 -2
- package/dist/server/mutations/code.js.map +1 -1
- package/dist/server/mutations/index.d.ts +8 -312
- package/dist/server/mutations/index.js +14 -84
- package/dist/server/mutations/invalidate.d.ts +5 -5
- package/dist/server/mutations/invalidate.d.ts.map +1 -1
- package/dist/server/mutations/invalidate.js +1 -1
- package/dist/server/mutations/invalidate.js.map +1 -1
- package/dist/server/mutations/oauth.d.ts +9 -9
- package/dist/server/mutations/oauth.d.ts.map +1 -1
- package/dist/server/mutations/oauth.js +5 -3
- package/dist/server/mutations/oauth.js.map +1 -1
- package/dist/server/mutations/refresh.d.ts +4 -4
- package/dist/server/mutations/refresh.js +1 -1
- package/dist/server/mutations/refresh.js.map +1 -1
- package/dist/server/mutations/register.d.ts +10 -10
- package/dist/server/mutations/register.d.ts.map +1 -1
- package/dist/server/mutations/register.js +3 -3
- package/dist/server/mutations/register.js.map +1 -1
- package/dist/server/mutations/retrieve.d.ts +8 -10
- package/dist/server/mutations/retrieve.d.ts.map +1 -1
- package/dist/server/mutations/retrieve.js +5 -7
- package/dist/server/mutations/retrieve.js.map +1 -1
- package/dist/server/mutations/signature.d.ts +6 -6
- package/dist/server/mutations/signature.d.ts.map +1 -1
- package/dist/server/mutations/signature.js +2 -2
- package/dist/server/mutations/signature.js.map +1 -1
- package/dist/server/mutations/signin.d.ts +1 -1
- package/dist/server/mutations/signin.js +1 -1
- package/dist/server/mutations/signin.js.map +1 -1
- package/dist/server/mutations/signout.d.ts +1 -1
- package/dist/server/mutations/signout.js +1 -1
- package/dist/server/mutations/signout.js.map +1 -1
- package/dist/server/mutations/store/refs.d.ts +12 -0
- package/dist/server/mutations/store/refs.d.ts.map +1 -0
- package/dist/server/mutations/store/refs.js +15 -0
- package/dist/server/mutations/store/refs.js.map +1 -0
- package/dist/server/mutations/store.d.ts +303 -9
- package/dist/server/mutations/store.d.ts.map +1 -1
- package/dist/server/mutations/store.js +80 -10
- package/dist/server/mutations/store.js.map +1 -1
- package/dist/server/mutations/verifier.d.ts +1 -1
- package/dist/server/mutations/verifier.js +1 -1
- package/dist/server/mutations/verifier.js.map +1 -1
- package/dist/server/mutations/verify.d.ts +8 -8
- package/dist/server/mutations/verify.d.ts.map +1 -1
- package/dist/server/mutations/verify.js +4 -3
- package/dist/server/mutations/verify.js.map +1 -1
- package/dist/server/oauth.js +1 -1
- package/dist/server/oauth.js.map +1 -1
- package/dist/server/passkey.d.ts +2 -2
- package/dist/server/passkey.d.ts.map +1 -1
- package/dist/server/passkey.js +3 -2
- package/dist/server/passkey.js.map +1 -1
- package/dist/server/redirects.js +1 -1
- package/dist/server/redirects.js.map +1 -1
- package/dist/server/refresh.js +1 -1
- package/dist/server/refresh.js.map +1 -1
- package/dist/server/{factory.d.ts → runtime.d.ts} +16 -16
- package/dist/server/runtime.d.ts.map +1 -0
- package/dist/server/runtime.js +413 -0
- package/dist/server/runtime.js.map +1 -0
- package/dist/server/signin.js +3 -2
- package/dist/server/signin.js.map +1 -1
- package/dist/server/ssr.d.ts +226 -0
- package/dist/server/ssr.d.ts.map +1 -0
- package/dist/server/ssr.js +786 -0
- package/dist/server/ssr.js.map +1 -0
- package/dist/server/totp.js +2 -1
- package/dist/server/totp.js.map +1 -1
- package/dist/server/types.d.ts +242 -42
- package/dist/server/types.d.ts.map +1 -1
- package/dist/server/types.js +12 -1
- package/dist/server/types.js.map +1 -1
- package/dist/server/users.js +1 -1
- package/dist/server/users.js.map +1 -1
- package/dist/server/utils.js +1 -1
- package/dist/server/utils.js.map +1 -1
- package/package.json +3 -4
- package/src/authorization/index.ts +46 -0
- package/src/cli/index.ts +38 -20
- package/src/client/core/types.ts +437 -0
- package/src/client/factors/device.ts +160 -0
- package/src/client/factors/passkey.ts +282 -0
- package/src/client/factors/totp.ts +150 -0
- package/src/client/index.ts +133 -1267
- package/src/client/runtime/browser.ts +112 -0
- package/src/client/runtime/invite.ts +65 -0
- package/src/client/runtime/proxy.ts +111 -0
- package/src/client/runtime/storage.ts +79 -0
- package/src/component/_generated/api.ts +40 -12
- package/src/component/_generated/component.ts +1772 -1798
- package/src/component/model.ts +6 -0
- package/src/component/public/enterprise/audit.ts +120 -0
- package/src/component/public/enterprise/core.ts +354 -0
- package/src/component/public/enterprise/domains.ts +323 -0
- package/src/component/public/enterprise/scim.ts +396 -0
- package/src/component/public/enterprise/secrets.ts +132 -0
- package/src/component/public/enterprise/webhooks.ts +306 -0
- package/src/component/public/factors/devices.ts +223 -0
- package/src/component/public/factors/passkeys.ts +242 -0
- package/src/component/public/factors/totp.ts +258 -0
- package/src/component/public/groups/core.ts +481 -0
- package/src/component/public/groups/invites.ts +602 -0
- package/src/component/public/groups/members.ts +409 -0
- package/src/component/public/identity/accounts.ts +206 -0
- package/src/component/public/identity/codes.ts +148 -0
- package/src/component/public/identity/sessions.ts +209 -0
- package/src/component/public/identity/tokens.ts +250 -0
- package/src/component/public/identity/users.ts +354 -0
- package/src/component/public/identity/verifiers.ts +157 -0
- package/src/component/public/security/keys.ts +365 -0
- package/src/component/public/security/limits.ts +173 -0
- package/src/component/public.ts +27 -5
- package/src/providers/credentials.ts +4 -5
- package/src/providers/email.ts +30 -0
- package/src/providers/phone.ts +28 -0
- package/src/server/auth.ts +282 -28
- package/src/server/authError.ts +44 -0
- package/src/server/core.ts +2095 -0
- package/src/server/{provider.ts → crypto.ts} +1 -1
- package/src/server/device.ts +1 -1
- package/src/server/enterprise/config.ts +51 -0
- package/src/server/{domains/sso.ts → enterprise/domain.ts} +4 -2
- package/src/server/enterprise/http.ts +1324 -0
- package/src/server/enterprise/oidc.ts +500 -0
- package/src/server/enterprise/policy.ts +128 -0
- package/src/server/enterprise/saml.ts +578 -0
- package/src/server/enterprise/scim.ts +135 -0
- package/src/server/enterprise/shared.ts +134 -0
- package/src/server/errors.ts +2 -0
- package/src/server/http.ts +3 -1
- package/src/server/identity.ts +1 -1
- package/src/server/index.ts +32 -2605
- package/src/server/{ratelimit.ts → limits.ts} +1 -1
- package/src/server/mounts.ts +948 -0
- package/src/server/mutations/account.ts +4 -4
- package/src/server/mutations/code.ts +3 -3
- package/src/server/mutations/index.ts +8 -148
- package/src/server/mutations/invalidate.ts +2 -2
- package/src/server/mutations/oauth.ts +8 -6
- package/src/server/mutations/refresh.ts +3 -3
- package/src/server/mutations/register.ts +3 -3
- package/src/server/mutations/retrieve.ts +4 -8
- package/src/server/mutations/signature.ts +3 -3
- package/src/server/mutations/signin.ts +2 -2
- package/src/server/mutations/signout.ts +2 -2
- package/src/server/mutations/store/refs.ts +10 -0
- package/src/server/mutations/store.ts +137 -9
- package/src/server/mutations/verifier.ts +2 -2
- package/src/server/mutations/verify.ts +5 -5
- package/src/server/oauth.ts +1 -1
- package/src/server/passkey.ts +3 -4
- package/src/server/redirects.ts +1 -1
- package/src/server/refresh.ts +1 -1
- package/src/server/runtime.ts +880 -0
- package/src/server/signin.ts +3 -1
- package/src/server/ssr.ts +1764 -0
- package/src/server/totp.ts +3 -1
- package/src/server/types.ts +254 -43
- package/src/server/users.ts +1 -1
- package/src/server/utils.ts +1 -1
- package/src/test.ts +25 -0
- package/dist/component/public/enterprise.d.ts +0 -54
- package/dist/component/public/enterprise.d.ts.map +0 -1
- package/dist/component/public/enterprise.js +0 -515
- package/dist/component/public/enterprise.js.map +0 -1
- package/dist/component/public/factors.d.ts +0 -52
- package/dist/component/public/factors.d.ts.map +0 -1
- package/dist/component/public/factors.js +0 -285
- package/dist/component/public/factors.js.map +0 -1
- package/dist/component/public/groups.d.ts +0 -124
- package/dist/component/public/groups.d.ts.map +0 -1
- package/dist/component/public/groups.js +0 -680
- package/dist/component/public/groups.js.map +0 -1
- package/dist/component/public/identity.d.ts +0 -93
- package/dist/component/public/identity.d.ts.map +0 -1
- package/dist/component/public/identity.js +0 -426
- package/dist/component/public/identity.js.map +0 -1
- package/dist/component/public/keys.d.ts +0 -41
- package/dist/component/public/keys.d.ts.map +0 -1
- package/dist/component/public/keys.js +0 -157
- package/dist/component/public/keys.js.map +0 -1
- package/dist/component/public/shared.d.ts +0 -26
- package/dist/component/public/shared.d.ts.map +0 -1
- package/dist/component/public/shared.js +0 -32
- package/dist/component/public/shared.js.map +0 -1
- package/dist/component/server/domains/core.js.map +0 -1
- package/dist/component/server/domains/sso.js.map +0 -1
- package/dist/component/server/factory.d.ts.map +0 -1
- package/dist/component/server/factory.js +0 -1134
- package/dist/component/server/factory.js.map +0 -1
- package/dist/component/server/fx.js +0 -66
- package/dist/component/server/fx.js.map +0 -1
- package/dist/component/server/mutations/index.js +0 -85
- package/dist/component/server/mutations/index.js.map +0 -1
- package/dist/component/server/providers.js.map +0 -1
- package/dist/component/server/ratelimit.js.map +0 -1
- package/dist/component/server/sso.js +0 -830
- package/dist/component/server/sso.js.map +0 -1
- package/dist/server/domains/core.d.ts +0 -449
- package/dist/server/domains/core.d.ts.map +0 -1
- package/dist/server/domains/core.js.map +0 -1
- package/dist/server/domains/sso.d.ts.map +0 -1
- package/dist/server/domains/sso.js.map +0 -1
- package/dist/server/enterpriseValidators.js.map +0 -1
- package/dist/server/factory.d.ts.map +0 -1
- package/dist/server/factory.js +0 -1134
- package/dist/server/factory.js.map +0 -1
- package/dist/server/fx.d.ts.map +0 -1
- package/dist/server/fx.js +0 -66
- package/dist/server/fx.js.map +0 -1
- package/dist/server/index.d.ts.map +0 -1
- package/dist/server/index.js.map +0 -1
- package/dist/server/mutations/index.d.ts.map +0 -1
- package/dist/server/mutations/index.js.map +0 -1
- package/dist/server/provider.d.ts.map +0 -1
- package/dist/server/provider.js.map +0 -1
- package/dist/server/providers.js.map +0 -1
- package/dist/server/ratelimit.js.map +0 -1
- package/dist/server/sso.js +0 -830
- package/dist/server/sso.js.map +0 -1
- package/dist/server/version.d.ts +0 -5
- package/dist/server/version.d.ts.map +0 -1
- package/dist/server/version.js +0 -6
- package/dist/server/version.js.map +0 -1
- package/src/component/public/enterprise.ts +0 -753
- package/src/component/public/factors.ts +0 -333
- package/src/component/public/groups.ts +0 -1066
- package/src/component/public/identity.ts +0 -569
- package/src/component/public/keys.ts +0 -209
- package/src/component/public/shared.ts +0 -119
- package/src/server/domains/core.ts +0 -1096
- package/src/server/factory.ts +0 -2181
- package/src/server/fx.ts +0 -152
- package/src/server/sso.ts +0 -1516
- package/src/server/version.ts +0 -2
- /package/dist/server/{enterpriseValidators.d.ts → config.d.ts} +0 -0
- /package/dist/server/{providers.d.ts → enterprise/config.d.ts} +0 -0
- /package/dist/server/{ratelimit.d.ts → enterprise/oidc.d.ts} +0 -0
- /package/dist/server/{sso.d.ts → enterprise/policy.d.ts} +0 -0
- /package/src/server/{providers.ts → config.ts} +0 -0
- /package/src/server/{enterpriseValidators.ts → enterprise/validators.ts} +0 -0
|
@@ -1,1096 +0,0 @@
|
|
|
1
|
-
import { Auth, GenericActionCtx, GenericDataModel } from "convex/server";
|
|
2
|
-
import { GenericId } from "convex/values";
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
buildScopeChecker,
|
|
6
|
-
checkKeyRateLimit,
|
|
7
|
-
generateApiKey,
|
|
8
|
-
hashApiKey,
|
|
9
|
-
} from "../keys";
|
|
10
|
-
import { materializeProvider } from "../providers";
|
|
11
|
-
import { signInImpl } from "../signin";
|
|
12
|
-
import type {
|
|
13
|
-
AuthProviderConfig,
|
|
14
|
-
KeyDoc,
|
|
15
|
-
KeyScope,
|
|
16
|
-
ScopeChecker,
|
|
17
|
-
UserOrderBy,
|
|
18
|
-
UserWhere,
|
|
19
|
-
} from "../types";
|
|
20
|
-
import {
|
|
21
|
-
generateRandomString,
|
|
22
|
-
sha256,
|
|
23
|
-
TOKEN_SUB_CLAIM_DIVIDER,
|
|
24
|
-
} from "../utils";
|
|
25
|
-
|
|
26
|
-
type ComponentCtx = Pick<
|
|
27
|
-
GenericActionCtx<GenericDataModel>,
|
|
28
|
-
"runQuery" | "runMutation"
|
|
29
|
-
>;
|
|
30
|
-
type ComponentReadCtx = Pick<GenericActionCtx<GenericDataModel>, "runQuery">;
|
|
31
|
-
type ComponentAuthReadCtx = ComponentReadCtx & { auth: Auth };
|
|
32
|
-
type AccountCredentials = { id: string; secret?: string };
|
|
33
|
-
type CreateAccountArgs = {
|
|
34
|
-
provider: string;
|
|
35
|
-
account: AccountCredentials;
|
|
36
|
-
profile: Record<string, unknown>;
|
|
37
|
-
shouldLinkViaEmail?: boolean;
|
|
38
|
-
shouldLinkViaPhone?: boolean;
|
|
39
|
-
};
|
|
40
|
-
type RetrieveAccountArgs = { provider: string; account: AccountCredentials };
|
|
41
|
-
type UpdateAccountCredentialsArgs = {
|
|
42
|
-
provider: string;
|
|
43
|
-
account: { id: string; secret: string };
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
type CoreDeps = {
|
|
47
|
-
config: any;
|
|
48
|
-
getAuth: () => any;
|
|
49
|
-
callInvalidateSessions: <DataModel extends GenericDataModel>(
|
|
50
|
-
ctx: GenericActionCtx<DataModel>,
|
|
51
|
-
args: { userId: GenericId<"User">; except?: GenericId<"Session">[] },
|
|
52
|
-
) => Promise<void>;
|
|
53
|
-
callCreateAccountFromCredentials: <DataModel extends GenericDataModel>(
|
|
54
|
-
ctx: GenericActionCtx<DataModel>,
|
|
55
|
-
args: CreateAccountArgs,
|
|
56
|
-
) => Promise<any>;
|
|
57
|
-
callRetrieveAccountWithCredentials: <DataModel extends GenericDataModel>(
|
|
58
|
-
ctx: GenericActionCtx<DataModel>,
|
|
59
|
-
args: RetrieveAccountArgs,
|
|
60
|
-
) => Promise<any>;
|
|
61
|
-
callModifyAccount: <DataModel extends GenericDataModel>(
|
|
62
|
-
ctx: GenericActionCtx<DataModel>,
|
|
63
|
-
args: UpdateAccountCredentialsArgs,
|
|
64
|
-
) => Promise<void>;
|
|
65
|
-
getEnrichCtx: () => <DataModel extends GenericDataModel>(
|
|
66
|
-
ctx: GenericActionCtx<DataModel>,
|
|
67
|
-
) => any;
|
|
68
|
-
inviteTokenAlphabet: string;
|
|
69
|
-
inviteTokenLength: number;
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Build the core auth domains that back the canonical app API surface.
|
|
74
|
-
*/
|
|
75
|
-
export function createCoreDomains(deps: CoreDeps) {
|
|
76
|
-
const {
|
|
77
|
-
config,
|
|
78
|
-
getAuth,
|
|
79
|
-
callInvalidateSessions,
|
|
80
|
-
callCreateAccountFromCredentials,
|
|
81
|
-
callRetrieveAccountWithCredentials,
|
|
82
|
-
callModifyAccount,
|
|
83
|
-
getEnrichCtx,
|
|
84
|
-
inviteTokenAlphabet,
|
|
85
|
-
inviteTokenLength,
|
|
86
|
-
} = deps;
|
|
87
|
-
|
|
88
|
-
const roleDefinitions = config.authorization.roles as Record<
|
|
89
|
-
string,
|
|
90
|
-
{ label?: string; grants: string[] }
|
|
91
|
-
>;
|
|
92
|
-
|
|
93
|
-
const getRoleDefinition = (roleId: string) => {
|
|
94
|
-
return roleDefinitions[roleId] ?? null;
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
const normalizeRoleIds = (
|
|
98
|
-
roleIds?: string[],
|
|
99
|
-
):
|
|
100
|
-
| { ok: true; roleIds: string[] }
|
|
101
|
-
| { ok: false; invalidRoleIds: string[] } => {
|
|
102
|
-
const normalized = Array.from(new Set(roleIds ?? []));
|
|
103
|
-
const invalid = normalized.filter((id) => getRoleDefinition(id) === null);
|
|
104
|
-
if (invalid.length > 0) {
|
|
105
|
-
return { ok: false, invalidRoleIds: invalid };
|
|
106
|
-
}
|
|
107
|
-
return { ok: true, roleIds: normalized };
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
const resolveGrantedPermissions = (roleIds?: string[]) => {
|
|
111
|
-
const grants = new Set<string>();
|
|
112
|
-
for (const roleId of roleIds ?? []) {
|
|
113
|
-
const role = getRoleDefinition(roleId);
|
|
114
|
-
if (role === null) continue;
|
|
115
|
-
for (const grant of role.grants) {
|
|
116
|
-
grants.add(grant);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
return Array.from(grants).sort();
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
// Per-execution cache — attached to ctx so each function invocation has its own.
|
|
123
|
-
// Eliminates redundant cross-component RPCs for the same entity within a handler.
|
|
124
|
-
type CtxCache = {
|
|
125
|
-
users: Map<string, any>;
|
|
126
|
-
groups: Map<string, any>;
|
|
127
|
-
};
|
|
128
|
-
const AUTH_CACHE = Symbol("__convexAuthCache");
|
|
129
|
-
function cache(ctx: any): CtxCache {
|
|
130
|
-
if (!ctx[AUTH_CACHE]) {
|
|
131
|
-
ctx[AUTH_CACHE] = {
|
|
132
|
-
users: new Map(),
|
|
133
|
-
groups: new Map(),
|
|
134
|
-
} satisfies CtxCache;
|
|
135
|
-
}
|
|
136
|
-
return ctx[AUTH_CACHE];
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
const user = {
|
|
140
|
-
id: async (
|
|
141
|
-
ctx: { auth: Auth } & Partial<ComponentCtx>,
|
|
142
|
-
request?: Request,
|
|
143
|
-
): Promise<string | null> => {
|
|
144
|
-
const identity = await ctx.auth.getUserIdentity();
|
|
145
|
-
if (identity !== null) {
|
|
146
|
-
const [userId] = identity.subject.split(TOKEN_SUB_CLAIM_DIVIDER);
|
|
147
|
-
return userId;
|
|
148
|
-
}
|
|
149
|
-
if (request !== undefined && "runMutation" in ctx && ctx.runMutation) {
|
|
150
|
-
const authHeader = request.headers.get("Authorization");
|
|
151
|
-
if (authHeader?.startsWith("Bearer sk_")) {
|
|
152
|
-
const rawKey = authHeader.slice(7);
|
|
153
|
-
const result = await getAuth().key.verify(
|
|
154
|
-
ctx as ComponentCtx,
|
|
155
|
-
rawKey,
|
|
156
|
-
);
|
|
157
|
-
if (result.ok) {
|
|
158
|
-
return result.userId;
|
|
159
|
-
}
|
|
160
|
-
return null;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
return null;
|
|
164
|
-
},
|
|
165
|
-
get: async (ctx: ComponentReadCtx, userId: string) => {
|
|
166
|
-
const c = cache(ctx);
|
|
167
|
-
if (c.users.has(userId)) return c.users.get(userId);
|
|
168
|
-
const result = await ctx.runQuery(config.component.public.userGetById, {
|
|
169
|
-
userId,
|
|
170
|
-
});
|
|
171
|
-
c.users.set(userId, result);
|
|
172
|
-
return result;
|
|
173
|
-
},
|
|
174
|
-
list: async (
|
|
175
|
-
ctx: ComponentReadCtx,
|
|
176
|
-
opts: {
|
|
177
|
-
where?: UserWhere;
|
|
178
|
-
limit?: number;
|
|
179
|
-
cursor?: string | null;
|
|
180
|
-
orderBy?: UserOrderBy;
|
|
181
|
-
order?: "asc" | "desc";
|
|
182
|
-
} = {},
|
|
183
|
-
) => {
|
|
184
|
-
return await ctx.runQuery(config.component.public.userList, opts);
|
|
185
|
-
},
|
|
186
|
-
viewer: async (ctx: ComponentAuthReadCtx) => {
|
|
187
|
-
const userId = await user.id(ctx);
|
|
188
|
-
if (userId === null) return null;
|
|
189
|
-
return await user.get(ctx, userId);
|
|
190
|
-
},
|
|
191
|
-
update: async (
|
|
192
|
-
ctx: ComponentCtx,
|
|
193
|
-
userId: string,
|
|
194
|
-
data: Record<string, unknown>,
|
|
195
|
-
) => {
|
|
196
|
-
await ctx.runMutation(config.component.public.userPatch, {
|
|
197
|
-
userId,
|
|
198
|
-
data,
|
|
199
|
-
});
|
|
200
|
-
return { ok: true as const, userId };
|
|
201
|
-
},
|
|
202
|
-
setActiveGroup: async (
|
|
203
|
-
ctx: ComponentCtx,
|
|
204
|
-
opts: { userId: string; groupId: string | null },
|
|
205
|
-
) => {
|
|
206
|
-
const doc = await user.get(ctx, opts.userId);
|
|
207
|
-
const existingExtend =
|
|
208
|
-
doc !== null &&
|
|
209
|
-
doc.extend !== null &&
|
|
210
|
-
typeof doc.extend === "object" &&
|
|
211
|
-
!Array.isArray(doc.extend)
|
|
212
|
-
? { ...(doc.extend as Record<string, unknown>) }
|
|
213
|
-
: {};
|
|
214
|
-
if (opts.groupId === null) {
|
|
215
|
-
const { lastActiveGroup: _omit, ...rest } = existingExtend;
|
|
216
|
-
await user.update(ctx, opts.userId, { extend: rest });
|
|
217
|
-
return { ok: true as const, userId: opts.userId, groupId: null };
|
|
218
|
-
}
|
|
219
|
-
await user.update(ctx, opts.userId, {
|
|
220
|
-
extend: { ...existingExtend, lastActiveGroup: opts.groupId },
|
|
221
|
-
});
|
|
222
|
-
return { ok: true as const, userId: opts.userId, groupId: opts.groupId };
|
|
223
|
-
},
|
|
224
|
-
getActiveGroup: async (
|
|
225
|
-
ctx: ComponentReadCtx,
|
|
226
|
-
opts: { userId: string },
|
|
227
|
-
): Promise<string | null> => {
|
|
228
|
-
const doc = await user.get(ctx, opts.userId);
|
|
229
|
-
if (
|
|
230
|
-
doc !== null &&
|
|
231
|
-
doc.extend !== null &&
|
|
232
|
-
typeof doc.extend === "object" &&
|
|
233
|
-
!Array.isArray(doc.extend)
|
|
234
|
-
) {
|
|
235
|
-
const val = (doc.extend as Record<string, unknown>).lastActiveGroup;
|
|
236
|
-
if (typeof val === "string") return val;
|
|
237
|
-
}
|
|
238
|
-
return null;
|
|
239
|
-
},
|
|
240
|
-
delete: async (
|
|
241
|
-
ctx: ComponentCtx,
|
|
242
|
-
userId: string,
|
|
243
|
-
opts?: { cascade?: boolean },
|
|
244
|
-
) => {
|
|
245
|
-
const cascade = opts?.cascade !== false;
|
|
246
|
-
const [sessions, accounts, keys, members, passkeys, totps] =
|
|
247
|
-
await Promise.all([
|
|
248
|
-
ctx.runQuery(config.component.public.sessionListByUser, {
|
|
249
|
-
userId,
|
|
250
|
-
}) as Promise<Array<{ _id: string }>>,
|
|
251
|
-
ctx.runQuery(config.component.public.accountListByUser, {
|
|
252
|
-
userId,
|
|
253
|
-
}) as Promise<Array<{ _id: string }>>,
|
|
254
|
-
ctx.runQuery(config.component.public.keyListByUserId, {
|
|
255
|
-
userId,
|
|
256
|
-
}) as Promise<Array<{ _id: string }>>,
|
|
257
|
-
ctx.runQuery(config.component.public.memberListByUser, {
|
|
258
|
-
userId,
|
|
259
|
-
}) as Promise<Array<{ _id: string }>>,
|
|
260
|
-
ctx.runQuery(config.component.public.passkeyListByUserId, {
|
|
261
|
-
userId,
|
|
262
|
-
}) as Promise<Array<{ _id: string }>>,
|
|
263
|
-
ctx.runQuery(config.component.public.totpListByUserId, {
|
|
264
|
-
userId,
|
|
265
|
-
}) as Promise<Array<{ _id: string }>>,
|
|
266
|
-
]);
|
|
267
|
-
const totalLinked =
|
|
268
|
-
sessions.length +
|
|
269
|
-
accounts.length +
|
|
270
|
-
keys.length +
|
|
271
|
-
members.length +
|
|
272
|
-
passkeys.length +
|
|
273
|
-
totps.length;
|
|
274
|
-
if (!cascade && totalLinked > 0) {
|
|
275
|
-
return { ok: false as const, code: "INVALID_PARAMETERS" as const };
|
|
276
|
-
}
|
|
277
|
-
const deletions: Promise<unknown>[] = [];
|
|
278
|
-
for (const s of sessions)
|
|
279
|
-
deletions.push(
|
|
280
|
-
ctx.runMutation(config.component.public.sessionDelete, {
|
|
281
|
-
sessionId: s._id,
|
|
282
|
-
}),
|
|
283
|
-
);
|
|
284
|
-
for (const a of accounts)
|
|
285
|
-
deletions.push(
|
|
286
|
-
ctx.runMutation(config.component.public.accountDelete, {
|
|
287
|
-
accountId: a._id,
|
|
288
|
-
}),
|
|
289
|
-
);
|
|
290
|
-
for (const k of keys)
|
|
291
|
-
deletions.push(
|
|
292
|
-
ctx.runMutation(config.component.public.keyDelete, { keyId: k._id }),
|
|
293
|
-
);
|
|
294
|
-
for (const m of members)
|
|
295
|
-
deletions.push(
|
|
296
|
-
ctx.runMutation(config.component.public.memberRemove, {
|
|
297
|
-
memberId: m._id,
|
|
298
|
-
}),
|
|
299
|
-
);
|
|
300
|
-
for (const p of passkeys)
|
|
301
|
-
deletions.push(
|
|
302
|
-
ctx.runMutation(config.component.public.passkeyDelete, {
|
|
303
|
-
passkeyId: p._id,
|
|
304
|
-
}),
|
|
305
|
-
);
|
|
306
|
-
for (const t of totps)
|
|
307
|
-
deletions.push(
|
|
308
|
-
ctx.runMutation(config.component.public.totpDelete, {
|
|
309
|
-
totpId: t._id,
|
|
310
|
-
}),
|
|
311
|
-
);
|
|
312
|
-
await Promise.all(deletions);
|
|
313
|
-
await ctx.runMutation(config.component.public.userDelete, { userId });
|
|
314
|
-
return { ok: true as const, userId };
|
|
315
|
-
},
|
|
316
|
-
};
|
|
317
|
-
|
|
318
|
-
const session = {
|
|
319
|
-
current: async (ctx: { auth: Auth }) => {
|
|
320
|
-
const identity = await ctx.auth.getUserIdentity();
|
|
321
|
-
if (identity === null) return null;
|
|
322
|
-
const [, sessionId] = identity.subject.split(TOKEN_SUB_CLAIM_DIVIDER);
|
|
323
|
-
return sessionId as GenericId<"Session">;
|
|
324
|
-
},
|
|
325
|
-
invalidate: async <DataModel extends GenericDataModel>(
|
|
326
|
-
ctx: GenericActionCtx<DataModel>,
|
|
327
|
-
args: { userId: GenericId<"User">; except?: GenericId<"Session">[] },
|
|
328
|
-
) => {
|
|
329
|
-
await callInvalidateSessions(ctx, args);
|
|
330
|
-
return {
|
|
331
|
-
ok: true as const,
|
|
332
|
-
userId: args.userId,
|
|
333
|
-
except: args.except ?? [],
|
|
334
|
-
};
|
|
335
|
-
},
|
|
336
|
-
get: async (ctx: ComponentReadCtx, sessionId: string) => {
|
|
337
|
-
return await ctx.runQuery(config.component.public.sessionGetById, {
|
|
338
|
-
sessionId,
|
|
339
|
-
});
|
|
340
|
-
},
|
|
341
|
-
list: async (ctx: ComponentReadCtx, opts: { userId: string }) => {
|
|
342
|
-
return await ctx.runQuery(config.component.public.sessionListByUser, {
|
|
343
|
-
userId: opts.userId,
|
|
344
|
-
});
|
|
345
|
-
},
|
|
346
|
-
};
|
|
347
|
-
|
|
348
|
-
const account = {
|
|
349
|
-
create: async <DataModel extends GenericDataModel>(
|
|
350
|
-
ctx: GenericActionCtx<DataModel>,
|
|
351
|
-
args: CreateAccountArgs,
|
|
352
|
-
) => {
|
|
353
|
-
const created = await callCreateAccountFromCredentials(ctx, args);
|
|
354
|
-
return { ok: true as const, ...created };
|
|
355
|
-
},
|
|
356
|
-
get: async <DataModel extends GenericDataModel>(
|
|
357
|
-
ctx: GenericActionCtx<DataModel>,
|
|
358
|
-
args: RetrieveAccountArgs,
|
|
359
|
-
) => {
|
|
360
|
-
const result = await callRetrieveAccountWithCredentials(ctx, args);
|
|
361
|
-
if (typeof result === "string") {
|
|
362
|
-
return null;
|
|
363
|
-
}
|
|
364
|
-
return result;
|
|
365
|
-
},
|
|
366
|
-
update: async <DataModel extends GenericDataModel>(
|
|
367
|
-
ctx: GenericActionCtx<DataModel>,
|
|
368
|
-
args: UpdateAccountCredentialsArgs,
|
|
369
|
-
) => {
|
|
370
|
-
await callModifyAccount(ctx, args);
|
|
371
|
-
return { ok: true as const, accountId: args.account.id };
|
|
372
|
-
},
|
|
373
|
-
delete: async (ctx: ComponentCtx, accountId: string) => {
|
|
374
|
-
const doc = await ctx.runQuery(config.component.public.accountGetById, {
|
|
375
|
-
accountId,
|
|
376
|
-
});
|
|
377
|
-
if (doc === null) {
|
|
378
|
-
return { ok: false as const, code: "ACCOUNT_NOT_FOUND" as const };
|
|
379
|
-
}
|
|
380
|
-
const allAccounts = (await ctx.runQuery(
|
|
381
|
-
config.component.public.accountListByUser,
|
|
382
|
-
{ userId: (doc as any).userId },
|
|
383
|
-
)) as Array<{ _id: string }>;
|
|
384
|
-
if (allAccounts.length <= 1) {
|
|
385
|
-
return { ok: false as const, code: "INVALID_PARAMETERS" as const };
|
|
386
|
-
}
|
|
387
|
-
await ctx.runMutation(config.component.public.accountDelete, {
|
|
388
|
-
accountId,
|
|
389
|
-
});
|
|
390
|
-
return { ok: true as const, accountId };
|
|
391
|
-
},
|
|
392
|
-
listPasskeys: async (ctx: ComponentReadCtx, opts: { userId: string }) => {
|
|
393
|
-
return await ctx.runQuery(
|
|
394
|
-
config.component.public.passkeyListByUserId,
|
|
395
|
-
opts,
|
|
396
|
-
);
|
|
397
|
-
},
|
|
398
|
-
renamePasskey: async (
|
|
399
|
-
ctx: ComponentCtx,
|
|
400
|
-
passkeyId: string,
|
|
401
|
-
name: string,
|
|
402
|
-
) => {
|
|
403
|
-
await ctx.runMutation(config.component.public.passkeyUpdateMeta, {
|
|
404
|
-
passkeyId,
|
|
405
|
-
data: { name },
|
|
406
|
-
});
|
|
407
|
-
return { ok: true as const, passkeyId };
|
|
408
|
-
},
|
|
409
|
-
deletePasskey: async (ctx: ComponentCtx, passkeyId: string) => {
|
|
410
|
-
await ctx.runMutation(config.component.public.passkeyDelete, {
|
|
411
|
-
passkeyId,
|
|
412
|
-
});
|
|
413
|
-
return { ok: true as const, passkeyId };
|
|
414
|
-
},
|
|
415
|
-
listTotps: async (ctx: ComponentReadCtx, opts: { userId: string }) => {
|
|
416
|
-
return await ctx.runQuery(config.component.public.totpListByUserId, opts);
|
|
417
|
-
},
|
|
418
|
-
deleteTotp: async (ctx: ComponentCtx, totpId: string) => {
|
|
419
|
-
await ctx.runMutation(config.component.public.totpDelete, { totpId });
|
|
420
|
-
return { ok: true as const, totpId };
|
|
421
|
-
},
|
|
422
|
-
};
|
|
423
|
-
|
|
424
|
-
const provider = {
|
|
425
|
-
signIn: async <DataModel extends GenericDataModel>(
|
|
426
|
-
ctx: GenericActionCtx<DataModel>,
|
|
427
|
-
providerConfig: AuthProviderConfig,
|
|
428
|
-
args: {
|
|
429
|
-
accountId?: GenericId<"Account">;
|
|
430
|
-
params?: Record<string, unknown>;
|
|
431
|
-
},
|
|
432
|
-
) => {
|
|
433
|
-
const result = await signInImpl(
|
|
434
|
-
getEnrichCtx()(ctx),
|
|
435
|
-
materializeProvider(providerConfig),
|
|
436
|
-
args as {
|
|
437
|
-
accountId?: GenericId<"Account">;
|
|
438
|
-
params?: Record<string, any>;
|
|
439
|
-
},
|
|
440
|
-
{ generateTokens: false, allowExtraProviders: true },
|
|
441
|
-
);
|
|
442
|
-
return result.kind === "signedIn"
|
|
443
|
-
? result.signedIn !== null
|
|
444
|
-
? {
|
|
445
|
-
userId: result.signedIn.userId,
|
|
446
|
-
sessionId: result.signedIn.sessionId,
|
|
447
|
-
}
|
|
448
|
-
: null
|
|
449
|
-
: null;
|
|
450
|
-
},
|
|
451
|
-
};
|
|
452
|
-
|
|
453
|
-
const group = {
|
|
454
|
-
create: async (
|
|
455
|
-
ctx: ComponentCtx,
|
|
456
|
-
data: {
|
|
457
|
-
name: string;
|
|
458
|
-
slug?: string;
|
|
459
|
-
type?: string;
|
|
460
|
-
parentGroupId?: string;
|
|
461
|
-
tags?: Array<{ key: string; value: string }>;
|
|
462
|
-
extend?: Record<string, unknown>;
|
|
463
|
-
},
|
|
464
|
-
): Promise<{ ok: true; groupId: string }> => {
|
|
465
|
-
const groupId = (await ctx.runMutation(
|
|
466
|
-
config.component.public.groupCreate,
|
|
467
|
-
data,
|
|
468
|
-
)) as string;
|
|
469
|
-
return { ok: true, groupId };
|
|
470
|
-
},
|
|
471
|
-
get: async (ctx: ComponentReadCtx, groupId: string) => {
|
|
472
|
-
const c = cache(ctx);
|
|
473
|
-
if (c.groups.has(groupId)) return c.groups.get(groupId);
|
|
474
|
-
const result = await ctx.runQuery(config.component.public.groupGet, {
|
|
475
|
-
groupId,
|
|
476
|
-
});
|
|
477
|
-
c.groups.set(groupId, result);
|
|
478
|
-
return result;
|
|
479
|
-
},
|
|
480
|
-
list: async (
|
|
481
|
-
ctx: ComponentReadCtx,
|
|
482
|
-
opts?: {
|
|
483
|
-
where?: {
|
|
484
|
-
slug?: string;
|
|
485
|
-
type?: string;
|
|
486
|
-
parentGroupId?: string;
|
|
487
|
-
name?: string;
|
|
488
|
-
isRoot?: boolean;
|
|
489
|
-
tagsAll?: Array<{ key: string; value: string }>;
|
|
490
|
-
tagsAny?: Array<{ key: string; value: string }>;
|
|
491
|
-
};
|
|
492
|
-
limit?: number;
|
|
493
|
-
cursor?: string | null;
|
|
494
|
-
orderBy?: "_creationTime" | "name" | "slug" | "type";
|
|
495
|
-
order?: "asc" | "desc";
|
|
496
|
-
},
|
|
497
|
-
) => {
|
|
498
|
-
return await ctx.runQuery(config.component.public.groupList, {
|
|
499
|
-
where: opts?.where,
|
|
500
|
-
limit: opts?.limit,
|
|
501
|
-
cursor: opts?.cursor,
|
|
502
|
-
orderBy: opts?.orderBy,
|
|
503
|
-
order: opts?.order,
|
|
504
|
-
});
|
|
505
|
-
},
|
|
506
|
-
update: async (
|
|
507
|
-
ctx: ComponentCtx,
|
|
508
|
-
groupId: string,
|
|
509
|
-
data: Record<string, unknown>,
|
|
510
|
-
) => {
|
|
511
|
-
await ctx.runMutation(config.component.public.groupUpdate, {
|
|
512
|
-
groupId,
|
|
513
|
-
data,
|
|
514
|
-
});
|
|
515
|
-
return { ok: true as const, groupId };
|
|
516
|
-
},
|
|
517
|
-
delete: async (ctx: ComponentCtx, groupId: string) => {
|
|
518
|
-
await ctx.runMutation(config.component.public.groupDelete, { groupId });
|
|
519
|
-
return { ok: true as const, groupId };
|
|
520
|
-
},
|
|
521
|
-
ancestors: async (
|
|
522
|
-
ctx: ComponentReadCtx,
|
|
523
|
-
opts: { groupId: string; maxDepth?: number; includeSelf?: boolean },
|
|
524
|
-
) => {
|
|
525
|
-
const maxDepth = Math.max(0, Math.floor(opts.maxDepth ?? 32));
|
|
526
|
-
const visited = new Set<string>();
|
|
527
|
-
const ancestors: any[] = [];
|
|
528
|
-
let cycleDetected = false;
|
|
529
|
-
let maxDepthReached = false;
|
|
530
|
-
let currentGroupId: string | undefined = opts.groupId;
|
|
531
|
-
let depth = 0;
|
|
532
|
-
let isFirst = true;
|
|
533
|
-
while (currentGroupId !== undefined) {
|
|
534
|
-
if (depth > maxDepth) {
|
|
535
|
-
maxDepthReached = true;
|
|
536
|
-
break;
|
|
537
|
-
}
|
|
538
|
-
if (visited.has(currentGroupId)) {
|
|
539
|
-
cycleDetected = true;
|
|
540
|
-
break;
|
|
541
|
-
}
|
|
542
|
-
visited.add(currentGroupId);
|
|
543
|
-
const doc = await group.get(ctx, currentGroupId);
|
|
544
|
-
if (doc === null) break;
|
|
545
|
-
if (isFirst) {
|
|
546
|
-
isFirst = false;
|
|
547
|
-
if (opts.includeSelf) ancestors.push(doc);
|
|
548
|
-
currentGroupId = doc.parentGroupId;
|
|
549
|
-
depth += 1;
|
|
550
|
-
continue;
|
|
551
|
-
}
|
|
552
|
-
ancestors.push(doc);
|
|
553
|
-
currentGroupId = doc.parentGroupId;
|
|
554
|
-
depth += 1;
|
|
555
|
-
}
|
|
556
|
-
return { ancestors, cycleDetected, maxDepthReached };
|
|
557
|
-
},
|
|
558
|
-
};
|
|
559
|
-
|
|
560
|
-
const member = {
|
|
561
|
-
create: async (
|
|
562
|
-
ctx: ComponentCtx,
|
|
563
|
-
data: {
|
|
564
|
-
groupId: string;
|
|
565
|
-
userId: string;
|
|
566
|
-
roleIds?: string[];
|
|
567
|
-
status?: string;
|
|
568
|
-
extend?: Record<string, unknown>;
|
|
569
|
-
},
|
|
570
|
-
) => {
|
|
571
|
-
const normalized = normalizeRoleIds(data.roleIds);
|
|
572
|
-
if (!normalized.ok)
|
|
573
|
-
return {
|
|
574
|
-
ok: false as const,
|
|
575
|
-
code: "INVALID_ROLE_IDS" as const,
|
|
576
|
-
invalidRoleIds: normalized.invalidRoleIds,
|
|
577
|
-
};
|
|
578
|
-
const memberId = (await ctx.runMutation(
|
|
579
|
-
config.component.public.memberAdd,
|
|
580
|
-
{ ...data, roleIds: normalized.roleIds },
|
|
581
|
-
)) as string;
|
|
582
|
-
return { ok: true as const, memberId };
|
|
583
|
-
},
|
|
584
|
-
get: async (ctx: ComponentReadCtx, memberId: string) => {
|
|
585
|
-
return await ctx.runQuery(config.component.public.memberGet, {
|
|
586
|
-
memberId,
|
|
587
|
-
});
|
|
588
|
-
},
|
|
589
|
-
getByUserAndGroup: async (
|
|
590
|
-
ctx: ComponentReadCtx,
|
|
591
|
-
opts: { userId: string; groupId: string },
|
|
592
|
-
) => {
|
|
593
|
-
return await ctx.runQuery(
|
|
594
|
-
config.component.public.memberGetByGroupAndUser,
|
|
595
|
-
opts,
|
|
596
|
-
);
|
|
597
|
-
},
|
|
598
|
-
list: async (
|
|
599
|
-
ctx: ComponentReadCtx,
|
|
600
|
-
opts?: {
|
|
601
|
-
where?: {
|
|
602
|
-
groupId?: string;
|
|
603
|
-
userId?: string;
|
|
604
|
-
roleId?: string;
|
|
605
|
-
status?: string;
|
|
606
|
-
};
|
|
607
|
-
limit?: number;
|
|
608
|
-
cursor?: string | null;
|
|
609
|
-
orderBy?: "_creationTime" | "status";
|
|
610
|
-
order?: "asc" | "desc";
|
|
611
|
-
},
|
|
612
|
-
) => {
|
|
613
|
-
return await ctx.runQuery(config.component.public.memberList, {
|
|
614
|
-
where: opts?.where,
|
|
615
|
-
limit: opts?.limit,
|
|
616
|
-
cursor: opts?.cursor,
|
|
617
|
-
orderBy: opts?.orderBy,
|
|
618
|
-
order: opts?.order,
|
|
619
|
-
});
|
|
620
|
-
},
|
|
621
|
-
delete: async (ctx: ComponentCtx, memberId: string) => {
|
|
622
|
-
await ctx.runMutation(config.component.public.memberRemove, { memberId });
|
|
623
|
-
return { ok: true as const, memberId };
|
|
624
|
-
},
|
|
625
|
-
update: async (
|
|
626
|
-
ctx: ComponentCtx,
|
|
627
|
-
memberId: string,
|
|
628
|
-
data: Record<string, unknown>,
|
|
629
|
-
) => {
|
|
630
|
-
const nextData = { ...data };
|
|
631
|
-
if ("roleIds" in nextData) {
|
|
632
|
-
const normalized = normalizeRoleIds(
|
|
633
|
-
Array.isArray(nextData.roleIds)
|
|
634
|
-
? (nextData.roleIds as string[])
|
|
635
|
-
: undefined,
|
|
636
|
-
);
|
|
637
|
-
if (!normalized.ok)
|
|
638
|
-
return {
|
|
639
|
-
ok: false as const,
|
|
640
|
-
code: "INVALID_ROLE_IDS" as const,
|
|
641
|
-
invalidRoleIds: normalized.invalidRoleIds,
|
|
642
|
-
};
|
|
643
|
-
nextData.roleIds = normalized.roleIds;
|
|
644
|
-
}
|
|
645
|
-
await ctx.runMutation(config.component.public.memberUpdate, {
|
|
646
|
-
memberId,
|
|
647
|
-
data: nextData,
|
|
648
|
-
});
|
|
649
|
-
return { ok: true as const, memberId };
|
|
650
|
-
},
|
|
651
|
-
resolve: async (
|
|
652
|
-
ctx: ComponentReadCtx,
|
|
653
|
-
opts: {
|
|
654
|
-
userId: string;
|
|
655
|
-
groupId: string;
|
|
656
|
-
roleIds?: string[];
|
|
657
|
-
grants?: string[];
|
|
658
|
-
maxDepth?: number;
|
|
659
|
-
},
|
|
660
|
-
) => {
|
|
661
|
-
const normalized = normalizeRoleIds(opts.roleIds);
|
|
662
|
-
if (!normalized.ok)
|
|
663
|
-
return {
|
|
664
|
-
ok: false as const,
|
|
665
|
-
code: "INVALID_ROLE_IDS" as const,
|
|
666
|
-
invalidRoleIds: normalized.invalidRoleIds,
|
|
667
|
-
};
|
|
668
|
-
const requestedRoleIds = normalized.roleIds;
|
|
669
|
-
const roleFilter =
|
|
670
|
-
requestedRoleIds.length > 0 ? new Set(requestedRoleIds) : null;
|
|
671
|
-
const requiredGrants = Array.from(new Set(opts.grants ?? []));
|
|
672
|
-
const maxDepth = Math.max(0, Math.floor(opts.maxDepth ?? 32));
|
|
673
|
-
|
|
674
|
-
// Single cross-component RPC — hierarchy walk happens inside the component
|
|
675
|
-
const result = await ctx.runQuery(config.component.public.memberResolve, {
|
|
676
|
-
userId: opts.userId,
|
|
677
|
-
groupId: opts.groupId,
|
|
678
|
-
maxDepth,
|
|
679
|
-
ancestry: true,
|
|
680
|
-
});
|
|
681
|
-
|
|
682
|
-
const traversedGroupIds = result.traversedGroupIds ?? [];
|
|
683
|
-
|
|
684
|
-
if (result.membership === null) {
|
|
685
|
-
return {
|
|
686
|
-
requestedGroupId: opts.groupId,
|
|
687
|
-
matchedGroupId: null,
|
|
688
|
-
membership: null,
|
|
689
|
-
roleIds: [] as string[],
|
|
690
|
-
grants: [] as string[],
|
|
691
|
-
missingGrants: requiredGrants,
|
|
692
|
-
depth: null,
|
|
693
|
-
isDirect: false,
|
|
694
|
-
isInherited: false,
|
|
695
|
-
traversedGroupIds,
|
|
696
|
-
cycleDetected: false,
|
|
697
|
-
maxDepthReached: false,
|
|
698
|
-
};
|
|
699
|
-
}
|
|
700
|
-
|
|
701
|
-
// Grant resolution uses app-defined roles — stays server-side
|
|
702
|
-
const membershipRoleIds = (result.membership as any).roleIds ?? [];
|
|
703
|
-
const membershipGrants = resolveGrantedPermissions(membershipRoleIds);
|
|
704
|
-
|
|
705
|
-
// Check role filter
|
|
706
|
-
if (
|
|
707
|
-
roleFilter !== null &&
|
|
708
|
-
!membershipRoleIds.some((roleId: string) => roleFilter.has(roleId))
|
|
709
|
-
) {
|
|
710
|
-
return {
|
|
711
|
-
requestedGroupId: opts.groupId,
|
|
712
|
-
matchedGroupId: null,
|
|
713
|
-
membership: null,
|
|
714
|
-
roleIds: [] as string[],
|
|
715
|
-
grants: [] as string[],
|
|
716
|
-
missingGrants: requiredGrants,
|
|
717
|
-
depth: null,
|
|
718
|
-
isDirect: false,
|
|
719
|
-
isInherited: false,
|
|
720
|
-
traversedGroupIds,
|
|
721
|
-
cycleDetected: false,
|
|
722
|
-
maxDepthReached: false,
|
|
723
|
-
};
|
|
724
|
-
}
|
|
725
|
-
|
|
726
|
-
// Check required grants
|
|
727
|
-
const missingGrants = requiredGrants.filter(
|
|
728
|
-
(grant) => !membershipGrants.includes(grant),
|
|
729
|
-
);
|
|
730
|
-
if (missingGrants.length > 0) {
|
|
731
|
-
return {
|
|
732
|
-
requestedGroupId: opts.groupId,
|
|
733
|
-
matchedGroupId: result.matchedGroupId,
|
|
734
|
-
membership: result.membership,
|
|
735
|
-
roleIds: membershipRoleIds,
|
|
736
|
-
grants: membershipGrants,
|
|
737
|
-
missingGrants,
|
|
738
|
-
depth: result.depth,
|
|
739
|
-
isDirect: result.isDirect,
|
|
740
|
-
isInherited: result.isInherited,
|
|
741
|
-
traversedGroupIds,
|
|
742
|
-
cycleDetected: false,
|
|
743
|
-
maxDepthReached: false,
|
|
744
|
-
};
|
|
745
|
-
}
|
|
746
|
-
|
|
747
|
-
return {
|
|
748
|
-
requestedGroupId: opts.groupId,
|
|
749
|
-
matchedGroupId: result.matchedGroupId,
|
|
750
|
-
membership: result.membership,
|
|
751
|
-
roleIds: membershipRoleIds,
|
|
752
|
-
grants: membershipGrants,
|
|
753
|
-
missingGrants: [] as string[],
|
|
754
|
-
depth: result.depth,
|
|
755
|
-
isDirect: result.isDirect,
|
|
756
|
-
isInherited: result.isInherited,
|
|
757
|
-
traversedGroupIds,
|
|
758
|
-
cycleDetected: false,
|
|
759
|
-
maxDepthReached: false,
|
|
760
|
-
};
|
|
761
|
-
},
|
|
762
|
-
};
|
|
763
|
-
|
|
764
|
-
const access = {
|
|
765
|
-
check: async (
|
|
766
|
-
ctx: ComponentReadCtx,
|
|
767
|
-
opts: {
|
|
768
|
-
userId: string;
|
|
769
|
-
groupId: string;
|
|
770
|
-
grants: string[];
|
|
771
|
-
maxDepth?: number;
|
|
772
|
-
},
|
|
773
|
-
) => {
|
|
774
|
-
const requiredGrants = Array.from(new Set(opts.grants));
|
|
775
|
-
const result = await member.resolve(ctx, {
|
|
776
|
-
userId: opts.userId,
|
|
777
|
-
groupId: opts.groupId,
|
|
778
|
-
grants: requiredGrants,
|
|
779
|
-
maxDepth: opts.maxDepth,
|
|
780
|
-
});
|
|
781
|
-
if ("code" in result && result.code === "INVALID_ROLE_IDS") {
|
|
782
|
-
return {
|
|
783
|
-
ok: false,
|
|
784
|
-
membership: null,
|
|
785
|
-
matchedGroupId: null,
|
|
786
|
-
roleIds: [] as string[],
|
|
787
|
-
grants: [] as string[],
|
|
788
|
-
missingGrants: requiredGrants,
|
|
789
|
-
isDirect: false,
|
|
790
|
-
isInherited: false,
|
|
791
|
-
depth: null,
|
|
792
|
-
};
|
|
793
|
-
}
|
|
794
|
-
const missingGrants = requiredGrants.filter(
|
|
795
|
-
(grant) => !result.grants.includes(grant),
|
|
796
|
-
);
|
|
797
|
-
return {
|
|
798
|
-
ok: result.membership !== null && missingGrants.length === 0,
|
|
799
|
-
membership: result.membership,
|
|
800
|
-
matchedGroupId: result.matchedGroupId,
|
|
801
|
-
roleIds: result.roleIds,
|
|
802
|
-
grants: result.grants,
|
|
803
|
-
missingGrants,
|
|
804
|
-
isDirect: result.isDirect,
|
|
805
|
-
isInherited: result.isInherited,
|
|
806
|
-
depth: result.depth,
|
|
807
|
-
};
|
|
808
|
-
},
|
|
809
|
-
};
|
|
810
|
-
|
|
811
|
-
const invite = {
|
|
812
|
-
create: async (
|
|
813
|
-
ctx: ComponentCtx,
|
|
814
|
-
data: {
|
|
815
|
-
groupId?: string;
|
|
816
|
-
invitedByUserId?: string;
|
|
817
|
-
email?: string;
|
|
818
|
-
roleIds?: string[];
|
|
819
|
-
expiresTime?: number;
|
|
820
|
-
extend?: Record<string, unknown>;
|
|
821
|
-
},
|
|
822
|
-
) => {
|
|
823
|
-
const normalized = normalizeRoleIds(data.roleIds);
|
|
824
|
-
if (!normalized.ok)
|
|
825
|
-
return {
|
|
826
|
-
ok: false as const,
|
|
827
|
-
code: "INVALID_ROLE_IDS" as const,
|
|
828
|
-
invalidRoleIds: normalized.invalidRoleIds,
|
|
829
|
-
};
|
|
830
|
-
const token = generateRandomString(
|
|
831
|
-
inviteTokenLength,
|
|
832
|
-
inviteTokenAlphabet,
|
|
833
|
-
);
|
|
834
|
-
const tokenHash = await sha256(token);
|
|
835
|
-
const inviteId = (await ctx.runMutation(
|
|
836
|
-
config.component.public.inviteCreate,
|
|
837
|
-
{ ...data, roleIds: normalized.roleIds, tokenHash, status: "pending" },
|
|
838
|
-
)) as string;
|
|
839
|
-
return { ok: true as const, inviteId, token };
|
|
840
|
-
},
|
|
841
|
-
get: async (ctx: ComponentReadCtx, inviteId: string) => {
|
|
842
|
-
return await ctx.runQuery(config.component.public.inviteGet, {
|
|
843
|
-
inviteId,
|
|
844
|
-
});
|
|
845
|
-
},
|
|
846
|
-
token: {
|
|
847
|
-
get: async (ctx: ComponentReadCtx, token: string) => {
|
|
848
|
-
const tokenHash = await sha256(token);
|
|
849
|
-
return await ctx.runQuery(
|
|
850
|
-
config.component.public.inviteGetByTokenHash,
|
|
851
|
-
{ tokenHash },
|
|
852
|
-
);
|
|
853
|
-
},
|
|
854
|
-
accept: async (
|
|
855
|
-
ctx: ComponentCtx,
|
|
856
|
-
args: { token: string; acceptedByUserId: string },
|
|
857
|
-
) => {
|
|
858
|
-
const tokenHash = await sha256(args.token);
|
|
859
|
-
const result = await ctx.runMutation(
|
|
860
|
-
config.component.public.inviteAcceptByToken,
|
|
861
|
-
{ tokenHash, acceptedByUserId: args.acceptedByUserId },
|
|
862
|
-
);
|
|
863
|
-
return { ok: true as const, ...result };
|
|
864
|
-
},
|
|
865
|
-
},
|
|
866
|
-
list: async (
|
|
867
|
-
ctx: ComponentReadCtx,
|
|
868
|
-
opts?: {
|
|
869
|
-
where?: {
|
|
870
|
-
tokenHash?: string;
|
|
871
|
-
groupId?: string;
|
|
872
|
-
status?: "pending" | "accepted" | "revoked" | "expired";
|
|
873
|
-
email?: string;
|
|
874
|
-
invitedByUserId?: string;
|
|
875
|
-
roleId?: string;
|
|
876
|
-
acceptedByUserId?: string;
|
|
877
|
-
};
|
|
878
|
-
limit?: number;
|
|
879
|
-
cursor?: string | null;
|
|
880
|
-
orderBy?:
|
|
881
|
-
| "_creationTime"
|
|
882
|
-
| "status"
|
|
883
|
-
| "email"
|
|
884
|
-
| "expiresTime"
|
|
885
|
-
| "acceptedTime";
|
|
886
|
-
order?: "asc" | "desc";
|
|
887
|
-
},
|
|
888
|
-
) => {
|
|
889
|
-
return await ctx.runQuery(config.component.public.inviteList, {
|
|
890
|
-
where: opts?.where,
|
|
891
|
-
limit: opts?.limit,
|
|
892
|
-
cursor: opts?.cursor,
|
|
893
|
-
orderBy: opts?.orderBy,
|
|
894
|
-
order: opts?.order,
|
|
895
|
-
});
|
|
896
|
-
},
|
|
897
|
-
accept: async (
|
|
898
|
-
ctx: ComponentCtx,
|
|
899
|
-
inviteId: string,
|
|
900
|
-
acceptedByUserId?: string,
|
|
901
|
-
) => {
|
|
902
|
-
await ctx.runMutation(config.component.public.inviteAccept, {
|
|
903
|
-
inviteId,
|
|
904
|
-
...(acceptedByUserId ? { acceptedByUserId } : {}),
|
|
905
|
-
});
|
|
906
|
-
return {
|
|
907
|
-
ok: true as const,
|
|
908
|
-
inviteId,
|
|
909
|
-
acceptedByUserId: acceptedByUserId ?? null,
|
|
910
|
-
};
|
|
911
|
-
},
|
|
912
|
-
revoke: async (ctx: ComponentCtx, inviteId: string) => {
|
|
913
|
-
await ctx.runMutation(config.component.public.inviteRevoke, { inviteId });
|
|
914
|
-
return { ok: true as const, inviteId };
|
|
915
|
-
},
|
|
916
|
-
};
|
|
917
|
-
|
|
918
|
-
const key = {
|
|
919
|
-
create: async (
|
|
920
|
-
ctx: ComponentCtx,
|
|
921
|
-
opts: {
|
|
922
|
-
userId: string;
|
|
923
|
-
name: string;
|
|
924
|
-
scopes: KeyScope[];
|
|
925
|
-
rateLimit?: { maxRequests: number; windowMs: number };
|
|
926
|
-
expiresAt?: number;
|
|
927
|
-
metadata?: Record<string, unknown>;
|
|
928
|
-
},
|
|
929
|
-
): Promise<{ ok: true; keyId: string; secret: string }> => {
|
|
930
|
-
const { raw, hashedKey, displayPrefix } = await generateApiKey("sk_");
|
|
931
|
-
const keyId = (await ctx.runMutation(config.component.public.keyInsert, {
|
|
932
|
-
userId: opts.userId,
|
|
933
|
-
prefix: displayPrefix,
|
|
934
|
-
hashedKey,
|
|
935
|
-
name: opts.name,
|
|
936
|
-
scopes: opts.scopes,
|
|
937
|
-
rateLimit: opts.rateLimit,
|
|
938
|
-
expiresAt: opts.expiresAt,
|
|
939
|
-
metadata: opts.metadata,
|
|
940
|
-
})) as string;
|
|
941
|
-
return { ok: true, keyId, secret: raw };
|
|
942
|
-
},
|
|
943
|
-
verify: async (
|
|
944
|
-
ctx: ComponentCtx,
|
|
945
|
-
rawKey: string,
|
|
946
|
-
): Promise<
|
|
947
|
-
| { ok: true; userId: string; keyId: string; scopes: ScopeChecker }
|
|
948
|
-
| {
|
|
949
|
-
ok: false;
|
|
950
|
-
code:
|
|
951
|
-
| "INVALID_API_KEY"
|
|
952
|
-
| "API_KEY_REVOKED"
|
|
953
|
-
| "API_KEY_EXPIRED"
|
|
954
|
-
| "API_KEY_RATE_LIMITED";
|
|
955
|
-
}
|
|
956
|
-
> => {
|
|
957
|
-
const hashedKey = await hashApiKey(rawKey);
|
|
958
|
-
const doc = (await ctx.runQuery(
|
|
959
|
-
config.component.public.keyGetByHashedKey,
|
|
960
|
-
{ hashedKey },
|
|
961
|
-
)) as KeyDoc | null;
|
|
962
|
-
if (!doc) {
|
|
963
|
-
return { ok: false as const, code: "INVALID_API_KEY" as const };
|
|
964
|
-
}
|
|
965
|
-
const k = doc;
|
|
966
|
-
if (k.revoked) {
|
|
967
|
-
return { ok: false as const, code: "API_KEY_REVOKED" as const };
|
|
968
|
-
}
|
|
969
|
-
if (k.expiresAt && k.expiresAt < Date.now()) {
|
|
970
|
-
return { ok: false as const, code: "API_KEY_EXPIRED" as const };
|
|
971
|
-
}
|
|
972
|
-
const patchData: Record<string, unknown> = { lastUsedAt: Date.now() };
|
|
973
|
-
if (k.rateLimit) {
|
|
974
|
-
const { limited, newState } = checkKeyRateLimit(
|
|
975
|
-
k.rateLimit,
|
|
976
|
-
k.rateLimitState ?? undefined,
|
|
977
|
-
);
|
|
978
|
-
if (limited) {
|
|
979
|
-
return { ok: false as const, code: "API_KEY_RATE_LIMITED" as const };
|
|
980
|
-
}
|
|
981
|
-
patchData.rateLimitState = newState;
|
|
982
|
-
}
|
|
983
|
-
await ctx.runMutation(config.component.public.keyPatch, {
|
|
984
|
-
keyId: k._id,
|
|
985
|
-
data: patchData,
|
|
986
|
-
});
|
|
987
|
-
return {
|
|
988
|
-
ok: true as const,
|
|
989
|
-
userId: k.userId,
|
|
990
|
-
keyId: k._id,
|
|
991
|
-
scopes: buildScopeChecker(k.scopes),
|
|
992
|
-
};
|
|
993
|
-
},
|
|
994
|
-
list: async (
|
|
995
|
-
ctx: ComponentReadCtx,
|
|
996
|
-
opts?: {
|
|
997
|
-
where?: {
|
|
998
|
-
userId?: string;
|
|
999
|
-
revoked?: boolean;
|
|
1000
|
-
name?: string;
|
|
1001
|
-
prefix?: string;
|
|
1002
|
-
};
|
|
1003
|
-
limit?: number;
|
|
1004
|
-
cursor?: string | null;
|
|
1005
|
-
orderBy?:
|
|
1006
|
-
| "_creationTime"
|
|
1007
|
-
| "name"
|
|
1008
|
-
| "lastUsedAt"
|
|
1009
|
-
| "expiresAt"
|
|
1010
|
-
| "revoked";
|
|
1011
|
-
order?: "asc" | "desc";
|
|
1012
|
-
},
|
|
1013
|
-
) => {
|
|
1014
|
-
return await ctx.runQuery(config.component.public.keyList, {
|
|
1015
|
-
where: opts?.where,
|
|
1016
|
-
limit: opts?.limit,
|
|
1017
|
-
cursor: opts?.cursor,
|
|
1018
|
-
orderBy: opts?.orderBy,
|
|
1019
|
-
order: opts?.order,
|
|
1020
|
-
});
|
|
1021
|
-
},
|
|
1022
|
-
get: async (
|
|
1023
|
-
ctx: ComponentReadCtx,
|
|
1024
|
-
keyId: string,
|
|
1025
|
-
): Promise<KeyDoc | null> => {
|
|
1026
|
-
return (await ctx.runQuery(config.component.public.keyGetById, {
|
|
1027
|
-
keyId,
|
|
1028
|
-
})) as KeyDoc | null;
|
|
1029
|
-
},
|
|
1030
|
-
update: async (
|
|
1031
|
-
ctx: ComponentCtx,
|
|
1032
|
-
keyId: string,
|
|
1033
|
-
data: {
|
|
1034
|
-
name?: string;
|
|
1035
|
-
scopes?: KeyScope[];
|
|
1036
|
-
rateLimit?: { maxRequests: number; windowMs: number };
|
|
1037
|
-
},
|
|
1038
|
-
) => {
|
|
1039
|
-
await ctx.runMutation(config.component.public.keyPatch, { keyId, data });
|
|
1040
|
-
return { ok: true as const, keyId };
|
|
1041
|
-
},
|
|
1042
|
-
revoke: async (ctx: ComponentCtx, keyId: string) => {
|
|
1043
|
-
await ctx.runMutation(config.component.public.keyPatch, {
|
|
1044
|
-
keyId,
|
|
1045
|
-
data: { revoked: true },
|
|
1046
|
-
});
|
|
1047
|
-
return { ok: true as const, keyId };
|
|
1048
|
-
},
|
|
1049
|
-
delete: async (ctx: ComponentCtx, keyId: string) => {
|
|
1050
|
-
await ctx.runMutation(config.component.public.keyDelete, { keyId });
|
|
1051
|
-
return { ok: true as const, keyId };
|
|
1052
|
-
},
|
|
1053
|
-
rotate: async (
|
|
1054
|
-
ctx: ComponentCtx,
|
|
1055
|
-
keyId: string,
|
|
1056
|
-
opts?: { name?: string; expiresAt?: number },
|
|
1057
|
-
): Promise<
|
|
1058
|
-
| { ok: true; keyId: string; secret: string }
|
|
1059
|
-
| { ok: false; code: "INVALID_PARAMETERS" | "API_KEY_REVOKED" }
|
|
1060
|
-
> => {
|
|
1061
|
-
const existing = await ctx.runQuery(config.component.public.keyGetById, {
|
|
1062
|
-
keyId,
|
|
1063
|
-
});
|
|
1064
|
-
if (!existing) {
|
|
1065
|
-
return { ok: false as const, code: "INVALID_PARAMETERS" as const };
|
|
1066
|
-
}
|
|
1067
|
-
if ((existing as any).revoked === true) {
|
|
1068
|
-
return { ok: false as const, code: "API_KEY_REVOKED" as const };
|
|
1069
|
-
}
|
|
1070
|
-
await ctx.runMutation(config.component.public.keyPatch, {
|
|
1071
|
-
keyId,
|
|
1072
|
-
data: { revoked: true },
|
|
1073
|
-
});
|
|
1074
|
-
return await key.create(ctx, {
|
|
1075
|
-
userId: (existing as any).userId,
|
|
1076
|
-
name: opts?.name ?? (existing as any).name,
|
|
1077
|
-
scopes: (existing as any).scopes ?? [],
|
|
1078
|
-
rateLimit: (existing as any).rateLimit,
|
|
1079
|
-
expiresAt: opts?.expiresAt,
|
|
1080
|
-
metadata: (existing as any).metadata,
|
|
1081
|
-
});
|
|
1082
|
-
},
|
|
1083
|
-
};
|
|
1084
|
-
|
|
1085
|
-
return {
|
|
1086
|
-
user,
|
|
1087
|
-
session,
|
|
1088
|
-
account,
|
|
1089
|
-
provider,
|
|
1090
|
-
group,
|
|
1091
|
-
member,
|
|
1092
|
-
access,
|
|
1093
|
-
invite,
|
|
1094
|
-
key,
|
|
1095
|
-
};
|
|
1096
|
-
}
|