@gatwech/auth 1.0.0-beta.18
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 +31 -0
- package/dist/access-BO2g7QVe.mjs +45 -0
- package/dist/access-C6O_osEz.mjs +79 -0
- package/dist/access-DT1f6l5k.mjs +51 -0
- package/dist/adapter-factory-BZ2Qiqpn.mjs +640 -0
- package/dist/adapters/drizzle-adapter/index.d.mts +47 -0
- package/dist/adapters/drizzle-adapter/index.mjs +208 -0
- package/dist/adapters/index.d.mts +132 -0
- package/dist/adapters/index.mjs +18 -0
- package/dist/adapters/kysely-adapter/index.d.mts +47 -0
- package/dist/adapters/kysely-adapter/index.mjs +11 -0
- package/dist/adapters/memory-adapter/index.d.mts +14 -0
- package/dist/adapters/memory-adapter/index.mjs +154 -0
- package/dist/adapters/mongodb-adapter/index.d.mts +35 -0
- package/dist/adapters/mongodb-adapter/index.mjs +315 -0
- package/dist/adapters/prisma-adapter/index.d.mts +34 -0
- package/dist/adapters/prisma-adapter/index.mjs +159 -0
- package/dist/adapters/test.d.mts +81 -0
- package/dist/adapters/test.mjs +793 -0
- package/dist/admin-Bcq53Nwj.mjs +743 -0
- package/dist/admin-DtfO1PLg.d.mts +1689 -0
- package/dist/anonymous-CRt1imBW.mjs +107 -0
- package/dist/api/index.d.mts +6 -0
- package/dist/api/index.mjs +17 -0
- package/dist/api-0pR_I-Nx.mjs +3139 -0
- package/dist/auth-CBUoBX6o.mjs +233 -0
- package/dist/bearer-Djf_awfo.mjs +63 -0
- package/dist/bun-sqlite-dialect-CeNvMaZz.mjs +155 -0
- package/dist/captcha-BqaMxlKC.mjs +178 -0
- package/dist/chunk-BK_LfMhE.mjs +40 -0
- package/dist/client/index.d.mts +186 -0
- package/dist/client/index.mjs +7 -0
- package/dist/client/plugins/index.d.mts +949 -0
- package/dist/client/plugins/index.mjs +539 -0
- package/dist/client/react/index.d.mts +179 -0
- package/dist/client/react/index.mjs +69 -0
- package/dist/client-BOX93C3d.d.mts +1250 -0
- package/dist/client-CNY0tn9g.d.mts +628 -0
- package/dist/client-CygJhqeB.mjs +29 -0
- package/dist/client-WiN43tAS.mjs +17 -0
- package/dist/client-aExCkfwm.mjs +30 -0
- package/dist/cookies/index.d.mts +7 -0
- package/dist/cookies/index.mjs +7 -0
- package/dist/cookies-cJObLwn1.mjs +597 -0
- package/dist/crypto/index.d.mts +44 -0
- package/dist/crypto/index.mjs +4 -0
- package/dist/crypto-Bb42eMrH.mjs +70 -0
- package/dist/custom-session-L3t7ecsd.mjs +67 -0
- package/dist/date-Cx2yCiC4.mjs +115 -0
- package/dist/db/index.d.mts +7 -0
- package/dist/db/index.mjs +15 -0
- package/dist/db-BrstmDhc.mjs +1124 -0
- package/dist/device-authorization-V4s3h4Mj.mjs +557 -0
- package/dist/dialect-CeddeGHf.mjs +72 -0
- package/dist/email-otp-BtDHSw14.mjs +592 -0
- package/dist/esm-C-QicDNz.mjs +4090 -0
- package/dist/generic-oauth-CL5X27ZI.mjs +445 -0
- package/dist/get-request-ip-DSjrEpGo.mjs +27 -0
- package/dist/get-tables-BQP7YW9c.mjs +249 -0
- package/dist/has-permission-BpAr7uCn.mjs +14 -0
- package/dist/haveibeenpwned-cMpJvmzI.mjs +43 -0
- package/dist/helper-tmxW3BHj.d.mts +21 -0
- package/dist/index-34ONrP8l.d.mts +503 -0
- package/dist/index-65G5U5DB-DSdjzreF.d.mts +2543 -0
- package/dist/index-B-XKqFvY.d.mts +30 -0
- package/dist/index-B3n8e37d.d.mts +165 -0
- package/dist/index-BBm8nQ9Q.d.mts +42 -0
- package/dist/index-BHoQlf7a.d.mts +7699 -0
- package/dist/index-BYMI9r_d.d.mts +257 -0
- package/dist/index-BqhKCbPH.d.mts +36 -0
- package/dist/index-Buhn3hkR.d.mts +433 -0
- package/dist/index-C-u1h_WX.d.mts +174 -0
- package/dist/index-C7fQuk-V.d.mts +41 -0
- package/dist/index-CM-CFWwr.d.mts +1919 -0
- package/dist/index-CuFzhoS6.d.mts +359 -0
- package/dist/index-Cxi7TbLE.d.mts +11347 -0
- package/dist/index-DB7t8whN.d.mts +1 -0
- package/dist/index-DKNNV1kb.d.mts +626 -0
- package/dist/index-DR0xXno9.d.mts +113 -0
- package/dist/index-D_k662QG.d.mts +833 -0
- package/dist/index-DaBcikv9.d.mts +118 -0
- package/dist/index-DlaMq1nb.d.mts +955 -0
- package/dist/index-DoXZYQpq.d.mts +290 -0
- package/dist/index-G6V0Z_Mn.d.mts +125 -0
- package/dist/index-z0KSvE5i.d.mts +246 -0
- package/dist/index-zjjNBRY2.d.mts +95 -0
- package/dist/index.d.mts +12 -0
- package/dist/index.mjs +33 -0
- package/dist/integrations/next-js.d.mts +21 -0
- package/dist/integrations/next-js.mjs +62 -0
- package/dist/integrations/node.d.mts +15 -0
- package/dist/integrations/node.mjs +15 -0
- package/dist/integrations/react-start.d.mts +15 -0
- package/dist/integrations/react-start.mjs +46 -0
- package/dist/json-D0TBLy4q.mjs +24 -0
- package/dist/jwt-CmxZAGe2.mjs +94 -0
- package/dist/jwt-lHV4QHpD.mjs +387 -0
- package/dist/kysely-adapter-DpzYO8Yf.mjs +181 -0
- package/dist/magic-link-Bk-ueorR.mjs +176 -0
- package/dist/misc-beA1w3XV.mjs +7 -0
- package/dist/multi-session-DRrLKrg9.mjs +144 -0
- package/dist/node-sqlite-dialect-BcKxBQnm.mjs +155 -0
- package/dist/oauth-proxy-D1sWh9B_.mjs +133 -0
- package/dist/oauth2/index.d.mts +60 -0
- package/dist/oauth2/index.mjs +19 -0
- package/dist/one-tap-DMswkTEc.mjs +113 -0
- package/dist/organization-BArHO_5v.mjs +3857 -0
- package/dist/parser-DcrIEuXE.mjs +73 -0
- package/dist/passkey-CcD4CnhM.mjs +558 -0
- package/dist/password-sVC4nePO.mjs +25 -0
- package/dist/permission-DLYUF3cW.mjs +15 -0
- package/dist/phone-number-rHDIlh-2.mjs +485 -0
- package/dist/plugin-helper-4L-lzsjZ.mjs +16 -0
- package/dist/plugins/access/index.d.mts +3 -0
- package/dist/plugins/access/index.mjs +3 -0
- package/dist/plugins/admin/access/index.d.mts +116 -0
- package/dist/plugins/admin/access/index.mjs +4 -0
- package/dist/plugins/admin/index.d.mts +9 -0
- package/dist/plugins/admin/index.mjs +22 -0
- package/dist/plugins/anonymous/index.d.mts +7 -0
- package/dist/plugins/anonymous/index.mjs +18 -0
- package/dist/plugins/bearer/index.d.mts +2 -0
- package/dist/plugins/bearer/index.mjs +8 -0
- package/dist/plugins/captcha/index.d.mts +2 -0
- package/dist/plugins/captcha/index.mjs +4 -0
- package/dist/plugins/custom-session/index.d.mts +7 -0
- package/dist/plugins/custom-session/index.mjs +19 -0
- package/dist/plugins/device-authorization/index.d.mts +4 -0
- package/dist/plugins/device-authorization/index.mjs +18 -0
- package/dist/plugins/email-otp/index.d.mts +3 -0
- package/dist/plugins/email-otp/index.mjs +19 -0
- package/dist/plugins/generic-oauth/index.d.mts +7 -0
- package/dist/plugins/generic-oauth/index.mjs +18 -0
- package/dist/plugins/haveibeenpwned/index.d.mts +2 -0
- package/dist/plugins/haveibeenpwned/index.mjs +18 -0
- package/dist/plugins/index.d.mts +139 -0
- package/dist/plugins/index.mjs +47 -0
- package/dist/plugins/jwt/index.d.mts +7 -0
- package/dist/plugins/jwt/index.mjs +18 -0
- package/dist/plugins/magic-link/index.d.mts +2 -0
- package/dist/plugins/magic-link/index.mjs +18 -0
- package/dist/plugins/multi-session/index.d.mts +3 -0
- package/dist/plugins/multi-session/index.mjs +18 -0
- package/dist/plugins/oauth-proxy/index.d.mts +2 -0
- package/dist/plugins/oauth-proxy/index.mjs +18 -0
- package/dist/plugins/one-tap/index.d.mts +2 -0
- package/dist/plugins/one-tap/index.mjs +18 -0
- package/dist/plugins/one-time-token/index.d.mts +7 -0
- package/dist/plugins/one-time-token/index.mjs +47 -0
- package/dist/plugins/organization/access/index.d.mts +4 -0
- package/dist/plugins/organization/access/index.mjs +4 -0
- package/dist/plugins/organization/index.d.mts +9 -0
- package/dist/plugins/organization/index.mjs +22 -0
- package/dist/plugins/passkey/index.d.mts +7 -0
- package/dist/plugins/passkey/index.mjs +18 -0
- package/dist/plugins/phone-number/index.d.mts +7 -0
- package/dist/plugins/phone-number/index.mjs +18 -0
- package/dist/plugins/two-factor/index.d.mts +7 -0
- package/dist/plugins/two-factor/index.mjs +20 -0
- package/dist/plugins/username/index.d.mts +4 -0
- package/dist/plugins/username/index.mjs +18 -0
- package/dist/plugins-3jfNste3.mjs +1544 -0
- package/dist/plugins-hFZT3hmK.d.mts +14 -0
- package/dist/promise-8rrEHRXd.mjs +23154 -0
- package/dist/proxy-CL9PZXJA.mjs +441 -0
- package/dist/session-Dgp133Yt.mjs +413 -0
- package/dist/social-providers/index.d.mts +1 -0
- package/dist/social-providers/index.mjs +3 -0
- package/dist/src/adapters/adapter-factory/index.d.ts +10 -0
- package/dist/src/adapters/adapter-factory/types.d.ts +124 -0
- package/dist/src/adapters/create-test-suite.d.ts +97 -0
- package/dist/src/adapters/drizzle-adapter/drizzle-adapter.d.ts +43 -0
- package/dist/src/adapters/drizzle-adapter/index.d.ts +1 -0
- package/dist/src/adapters/drizzle-adapter/test/generate-schema.d.ts +12 -0
- package/dist/src/adapters/index.d.ts +21 -0
- package/dist/src/adapters/kysely-adapter/bun-sqlite-dialect.d.ts +58 -0
- package/dist/src/adapters/kysely-adapter/dialect.d.ts +13 -0
- package/dist/src/adapters/kysely-adapter/index.d.ts +3 -0
- package/dist/src/adapters/kysely-adapter/kysely-adapter.d.ts +32 -0
- package/dist/src/adapters/kysely-adapter/node-sqlite-dialect.d.ts +58 -0
- package/dist/src/adapters/kysely-adapter/types.d.ts +1 -0
- package/dist/src/adapters/memory-adapter/index.d.ts +1 -0
- package/dist/src/adapters/memory-adapter/memory-adapter.d.ts +9 -0
- package/dist/src/adapters/mongodb-adapter/index.d.ts +1 -0
- package/dist/src/adapters/mongodb-adapter/mongodb-adapter.d.ts +31 -0
- package/dist/src/adapters/prisma-adapter/index.d.ts +1 -0
- package/dist/src/adapters/prisma-adapter/prisma-adapter.d.ts +32 -0
- package/dist/src/adapters/prisma-adapter/test/auth.d.ts +3 -0
- package/dist/src/adapters/prisma-adapter/test/generate-auth-config.d.ts +2 -0
- package/dist/src/adapters/prisma-adapter/test/generate-prisma-schema.d.ts +3 -0
- package/dist/src/adapters/prisma-adapter/test/get-prisma-client.d.ts +7 -0
- package/dist/src/adapters/prisma-adapter/test/push-prisma-schema.d.ts +1 -0
- package/dist/src/adapters/test-adapter.d.ts +61 -0
- package/dist/src/adapters/test.d.ts +78 -0
- package/dist/src/adapters/tests/auth-flow.d.ts +22 -0
- package/dist/src/adapters/tests/index.d.ts +5 -0
- package/dist/src/adapters/tests/normal.d.ts +87 -0
- package/dist/src/adapters/tests/number-id.d.ts +17 -0
- package/dist/src/adapters/tests/performance.d.ts +24 -0
- package/dist/src/adapters/tests/transactions.d.ts +20 -0
- package/dist/src/adapters/utils.d.ts +3 -0
- package/dist/src/api/index.d.ts +7150 -0
- package/dist/src/api/middlewares/index.d.ts +2 -0
- package/dist/src/api/middlewares/oauth.d.ts +15 -0
- package/dist/src/api/middlewares/origin-check.d.ts +8 -0
- package/dist/src/api/rate-limiter/index.d.ts +13 -0
- package/dist/src/api/routes/account.d.ts +623 -0
- package/dist/src/api/routes/callback.d.ts +68 -0
- package/dist/src/api/routes/email-verification.d.ts +266 -0
- package/dist/src/api/routes/error.d.ts +51 -0
- package/dist/src/api/routes/index.d.ts +11 -0
- package/dist/src/api/routes/ok.d.ts +61 -0
- package/dist/src/api/routes/reset-password.d.ts +203 -0
- package/dist/src/api/routes/session.d.ts +586 -0
- package/dist/src/api/routes/sign-in.d.ts +298 -0
- package/dist/src/api/routes/sign-out.d.ts +59 -0
- package/dist/src/api/routes/sign-up.d.ts +625 -0
- package/dist/src/api/routes/update-user.d.ts +862 -0
- package/dist/src/api/to-auth-endpoints.d.ts +3 -0
- package/dist/src/auth.d.ts +25 -0
- package/dist/src/client/broadcast-channel.d.ts +12 -0
- package/dist/src/client/config.d.ts +85 -0
- package/dist/src/client/fetch-plugins.d.ts +14 -0
- package/dist/src/client/index.d.ts +15 -0
- package/dist/src/client/parser.d.ts +12 -0
- package/dist/src/client/path-to-object.d.ts +63 -0
- package/dist/src/client/plugins/index.d.ts +21 -0
- package/dist/src/client/plugins/infer-plugin.d.ts +11 -0
- package/dist/src/client/proxy.d.ts +8 -0
- package/dist/src/client/query.d.ts +16 -0
- package/dist/src/client/react/index.d.ts +130 -0
- package/dist/src/client/react/react-store.d.ts +43 -0
- package/dist/src/client/session-atom.d.ts +18 -0
- package/dist/src/client/session-refresh.d.ts +17 -0
- package/dist/src/client/test-plugin.d.ts +147 -0
- package/dist/src/client/types.d.ts +49 -0
- package/dist/src/client/vanilla.d.ts +124 -0
- package/dist/src/cookies/check-cookies.d.ts +4 -0
- package/dist/src/cookies/cookie-utils.d.ts +16 -0
- package/dist/src/cookies/index.d.ts +56 -0
- package/dist/src/cookies/session-store.d.ts +43 -0
- package/dist/src/crypto/buffer.d.ts +4 -0
- package/dist/src/crypto/index.d.ts +14 -0
- package/dist/src/crypto/jwt.d.ts +4 -0
- package/dist/src/crypto/password.d.ts +5 -0
- package/dist/src/crypto/random.d.ts +1 -0
- package/dist/src/db/field.d.ts +97 -0
- package/dist/src/db/get-migration.d.ts +18 -0
- package/dist/src/db/get-schema.d.ts +6 -0
- package/dist/src/db/get-tables.d.ts +3 -0
- package/dist/src/db/index.d.ts +10 -0
- package/dist/src/db/internal-adapter.d.ts +9 -0
- package/dist/src/db/schema.d.ts +76 -0
- package/dist/src/db/to-zod.d.ts +31 -0
- package/dist/src/db/utils.d.ts +6 -0
- package/dist/src/db/with-hooks.d.ts +27 -0
- package/dist/src/index.d.ts +14 -0
- package/dist/src/init.d.ts +2 -0
- package/dist/src/integrations/next-js.d.ts +15 -0
- package/dist/src/integrations/node.d.ts +6 -0
- package/dist/src/integrations/react-start.d.ts +9 -0
- package/dist/src/oauth2/index.d.ts +4 -0
- package/dist/src/oauth2/link-account.d.ts +41 -0
- package/dist/src/oauth2/state.d.ts +21 -0
- package/dist/src/oauth2/utils.d.ts +3 -0
- package/dist/src/plugins/access/access.d.ts +25 -0
- package/dist/src/plugins/access/index.d.ts +2 -0
- package/dist/src/plugins/access/types.d.ts +14 -0
- package/dist/src/plugins/additional-fields/client.d.ts +91 -0
- package/dist/src/plugins/admin/access/index.d.ts +1 -0
- package/dist/src/plugins/admin/access/statement.d.ts +110 -0
- package/dist/src/plugins/admin/admin.d.ts +1570 -0
- package/dist/src/plugins/admin/client.d.ts +62 -0
- package/dist/src/plugins/admin/error-codes.d.ts +21 -0
- package/dist/src/plugins/admin/has-permission.d.ts +21 -0
- package/dist/src/plugins/admin/index.d.ts +2 -0
- package/dist/src/plugins/admin/schema.d.ts +36 -0
- package/dist/src/plugins/admin/types.d.ts +77 -0
- package/dist/src/plugins/anonymous/client.d.ts +8 -0
- package/dist/src/plugins/anonymous/index.d.ts +159 -0
- package/dist/src/plugins/api-key/client.d.ts +11 -0
- package/dist/src/plugins/api-key/index.d.ts +1431 -0
- package/dist/src/plugins/api-key/rate-limit.d.ts +20 -0
- package/dist/src/plugins/api-key/routes/create-api-key.d.ts +244 -0
- package/dist/src/plugins/api-key/routes/delete-all-expired-api-keys.d.ts +45 -0
- package/dist/src/plugins/api-key/routes/delete-api-key.d.ts +112 -0
- package/dist/src/plugins/api-key/routes/get-api-key.d.ts +234 -0
- package/dist/src/plugins/api-key/routes/index.d.ts +1136 -0
- package/dist/src/plugins/api-key/routes/list-api-keys.d.ts +231 -0
- package/dist/src/plugins/api-key/routes/update-api-key.d.ts +235 -0
- package/dist/src/plugins/api-key/routes/verify-api-key.d.ts +80 -0
- package/dist/src/plugins/api-key/schema.d.ts +188 -0
- package/dist/src/plugins/api-key/types.d.ts +285 -0
- package/dist/src/plugins/bearer/index.d.ts +31 -0
- package/dist/src/plugins/captcha/constants.d.ts +9 -0
- package/dist/src/plugins/captcha/error-codes.d.ts +9 -0
- package/dist/src/plugins/captcha/index.d.ts +7 -0
- package/dist/src/plugins/captcha/types.d.ts +23 -0
- package/dist/src/plugins/captcha/utils.d.ts +1 -0
- package/dist/src/plugins/captcha/verify-handlers/captchafox.d.ts +11 -0
- package/dist/src/plugins/captcha/verify-handlers/cloudflare-turnstile.d.ts +10 -0
- package/dist/src/plugins/captcha/verify-handlers/google-recaptcha.d.ts +11 -0
- package/dist/src/plugins/captcha/verify-handlers/h-captcha.d.ts +11 -0
- package/dist/src/plugins/captcha/verify-handlers/index.d.ts +4 -0
- package/dist/src/plugins/custom-session/client.d.ts +12 -0
- package/dist/src/plugins/custom-session/index.d.ts +89 -0
- package/dist/src/plugins/device-authorization/client.d.ts +12 -0
- package/dist/src/plugins/device-authorization/index.d.ts +568 -0
- package/dist/src/plugins/device-authorization/schema.d.ts +56 -0
- package/dist/src/plugins/email-otp/client.d.ts +9 -0
- package/dist/src/plugins/email-otp/index.d.ts +826 -0
- package/dist/src/plugins/email-otp/utils.d.ts +2 -0
- package/dist/src/plugins/generic-oauth/client.d.ts +5 -0
- package/dist/src/plugins/generic-oauth/index.d.ts +428 -0
- package/dist/src/plugins/haveibeenpwned/index.d.ts +25 -0
- package/dist/src/plugins/index.d.ts +28 -0
- package/dist/src/plugins/jwt/adapter.d.ts +8 -0
- package/dist/src/plugins/jwt/client.d.ts +5 -0
- package/dist/src/plugins/jwt/index.d.ts +276 -0
- package/dist/src/plugins/jwt/schema.d.ts +18 -0
- package/dist/src/plugins/jwt/sign.d.ts +8 -0
- package/dist/src/plugins/jwt/types.d.ts +175 -0
- package/dist/src/plugins/jwt/utils.d.ts +46 -0
- package/dist/src/plugins/last-login-method/client.d.ts +34 -0
- package/dist/src/plugins/last-login-method/index.d.ts +103 -0
- package/dist/src/plugins/magic-link/client.d.ts +5 -0
- package/dist/src/plugins/magic-link/index.d.ts +253 -0
- package/dist/src/plugins/magic-link/utils.d.ts +1 -0
- package/dist/src/plugins/multi-session/client.d.ts +9 -0
- package/dist/src/plugins/multi-session/index.d.ts +284 -0
- package/dist/src/plugins/oauth-proxy/index.d.ts +119 -0
- package/dist/src/plugins/one-tap/client.d.ts +81 -0
- package/dist/src/plugins/one-tap/index.d.ts +114 -0
- package/dist/src/plugins/one-time-token/client.d.ts +5 -0
- package/dist/src/plugins/one-time-token/index.d.ts +170 -0
- package/dist/src/plugins/one-time-token/utils.d.ts +1 -0
- package/dist/src/plugins/organization/access/index.d.ts +1 -0
- package/dist/src/plugins/organization/access/statement.d.ts +241 -0
- package/dist/src/plugins/organization/adapter.d.ts +685 -0
- package/dist/src/plugins/organization/call.d.ts +55 -0
- package/dist/src/plugins/organization/client.d.ts +344 -0
- package/dist/src/plugins/organization/error-codes.d.ts +58 -0
- package/dist/src/plugins/organization/has-permission.d.ts +13 -0
- package/dist/src/plugins/organization/index.d.ts +4 -0
- package/dist/src/plugins/organization/organization.d.ts +412 -0
- package/dist/src/plugins/organization/permission.d.ts +27 -0
- package/dist/src/plugins/organization/routes/crud-access-control.d.ts +701 -0
- package/dist/src/plugins/organization/routes/crud-invites.d.ts +1522 -0
- package/dist/src/plugins/organization/routes/crud-members.d.ts +1220 -0
- package/dist/src/plugins/organization/routes/crud-org.d.ts +1399 -0
- package/dist/src/plugins/organization/routes/crud-team.d.ts +1323 -0
- package/dist/src/plugins/organization/schema.d.ts +366 -0
- package/dist/src/plugins/organization/types.d.ts +737 -0
- package/dist/src/plugins/passkey/client.d.ts +190 -0
- package/dist/src/plugins/passkey/error-codes.d.ts +9 -0
- package/dist/src/plugins/passkey/index.d.ts +838 -0
- package/dist/src/plugins/passkey/schema.d.ts +50 -0
- package/dist/src/plugins/passkey/types.d.ts +69 -0
- package/dist/src/plugins/passkey/utils.d.ts +2 -0
- package/dist/src/plugins/phone-number/client.d.ts +9 -0
- package/dist/src/plugins/phone-number/index.d.ts +622 -0
- package/dist/src/plugins/phone-number/phone-number-error.d.ts +10 -0
- package/dist/src/plugins/two-factor/backup-codes/index.d.ts +387 -0
- package/dist/src/plugins/two-factor/client.d.ts +28 -0
- package/dist/src/plugins/two-factor/constant.d.ts +2 -0
- package/dist/src/plugins/two-factor/error-code.d.ts +11 -0
- package/dist/src/plugins/two-factor/index.d.ts +1014 -0
- package/dist/src/plugins/two-factor/otp/index.d.ts +282 -0
- package/dist/src/plugins/two-factor/schema.d.ts +35 -0
- package/dist/src/plugins/two-factor/totp/index.d.ts +298 -0
- package/dist/src/plugins/two-factor/types.d.ts +50 -0
- package/dist/src/plugins/two-factor/utils.d.ts +1 -0
- package/dist/src/plugins/two-factor/verify-two-factor.d.ts +59 -0
- package/dist/src/plugins/username/client.d.ts +5 -0
- package/dist/src/plugins/username/error-codes.d.ts +10 -0
- package/dist/src/plugins/username/index.d.ts +313 -0
- package/dist/src/plugins/username/schema.d.ts +27 -0
- package/dist/src/social-providers/index.d.ts +1 -0
- package/dist/src/test-utils/headers.d.ts +5 -0
- package/dist/src/test-utils/index.d.ts +2 -0
- package/dist/src/test-utils/test-instance.d.ts +17849 -0
- package/dist/src/types/adapter.d.ts +21 -0
- package/dist/src/types/api.d.ts +29 -0
- package/dist/src/types/helper.d.ts +32 -0
- package/dist/src/types/index.d.ts +7 -0
- package/dist/src/types/models.d.ts +13 -0
- package/dist/src/types/plugins.d.ts +14 -0
- package/dist/src/utils/await-object.d.ts +3 -0
- package/dist/src/utils/boolean.d.ts +1 -0
- package/dist/src/utils/clone.d.ts +1 -0
- package/dist/src/utils/constants.d.ts +1 -0
- package/dist/src/utils/date.d.ts +1 -0
- package/dist/src/utils/ensure-utc.d.ts +1 -0
- package/dist/src/utils/get-request-ip.d.ts +2 -0
- package/dist/src/utils/hashing.d.ts +6 -0
- package/dist/src/utils/hide-metadata.d.ts +3 -0
- package/dist/src/utils/id.d.ts +1 -0
- package/dist/src/utils/import-util.d.ts +1 -0
- package/dist/src/utils/index.d.ts +5 -0
- package/dist/src/utils/is-atom.d.ts +2 -0
- package/dist/src/utils/is-promise.d.ts +1 -0
- package/dist/src/utils/json.d.ts +1 -0
- package/dist/src/utils/merger.d.ts +1 -0
- package/dist/src/utils/middleware-response.d.ts +8 -0
- package/dist/src/utils/misc.d.ts +1 -0
- package/dist/src/utils/password.d.ts +6 -0
- package/dist/src/utils/plugin-helper.d.ts +5 -0
- package/dist/src/utils/shim.d.ts +3 -0
- package/dist/src/utils/time.d.ts +4 -0
- package/dist/src/utils/url.d.ts +4 -0
- package/dist/src/utils/wildcard.d.ts +45 -0
- package/dist/test-utils/index.d.mts +17870 -0
- package/dist/test-utils/index.mjs +272 -0
- package/dist/two-factor-ClUXxom2.mjs +914 -0
- package/dist/types/index.d.mts +6 -0
- package/dist/types/index.mjs +3 -0
- package/dist/types-B1OL7hyf.d.mts +4 -0
- package/dist/types-Bjn15Uy6.mjs +1 -0
- package/dist/url-VB2gAbTI.mjs +59 -0
- package/dist/username-DiGklOGl.mjs +278 -0
- package/dist/utils-SOMB4Px5.mjs +132 -0
- package/package.json +447 -0
|
@@ -0,0 +1,413 @@
|
|
|
1
|
+
import { t as safeJSONParse } from "./json-D0TBLy4q.mjs";
|
|
2
|
+
import { i as verifyJWT, n as symmetricDecodeJWT } from "./jwt-CmxZAGe2.mjs";
|
|
3
|
+
import { c as setSessionCookie, f as getChunkedCookie, n as deleteSessionCookie, p as getSessionQuerySchema, s as setCookieCache } from "./cookies-cJObLwn1.mjs";
|
|
4
|
+
import { c as parseSessionOutput, t as getDate, u as parseUserOutput } from "./date-Cx2yCiC4.mjs";
|
|
5
|
+
import { BASE_ERROR_CODES } from "@gatwech/core/error";
|
|
6
|
+
import { APIError } from "better-call";
|
|
7
|
+
import { createAuthEndpoint, createAuthMiddleware } from "@gatwech/core/api";
|
|
8
|
+
import * as z$1 from "zod";
|
|
9
|
+
import { base64Url } from "@gatwech/utils/base64";
|
|
10
|
+
import { binary } from "@gatwech/utils/binary";
|
|
11
|
+
import { createHMAC } from "@gatwech/utils/hmac";
|
|
12
|
+
|
|
13
|
+
//#region src/api/routes/session.ts
|
|
14
|
+
const getSession = () => createAuthEndpoint("/get-session", {
|
|
15
|
+
method: "GET",
|
|
16
|
+
query: getSessionQuerySchema,
|
|
17
|
+
requireHeaders: true,
|
|
18
|
+
metadata: { openapi: {
|
|
19
|
+
description: "Get the current session",
|
|
20
|
+
responses: { "200": {
|
|
21
|
+
description: "Success",
|
|
22
|
+
content: { "application/json": { schema: {
|
|
23
|
+
type: "object",
|
|
24
|
+
properties: {
|
|
25
|
+
session: { $ref: "#/components/schemas/Session" },
|
|
26
|
+
user: { $ref: "#/components/schemas/User" }
|
|
27
|
+
},
|
|
28
|
+
required: ["session", "user"]
|
|
29
|
+
} } }
|
|
30
|
+
} }
|
|
31
|
+
} }
|
|
32
|
+
}, async (ctx) => {
|
|
33
|
+
try {
|
|
34
|
+
const sessionCookieToken = await ctx.getSignedCookie(ctx.context.authCookies.sessionToken.name, ctx.context.secret);
|
|
35
|
+
if (!sessionCookieToken) return null;
|
|
36
|
+
const sessionDataCookie = getChunkedCookie(ctx, ctx.context.authCookies.sessionData.name);
|
|
37
|
+
let sessionDataPayload = null;
|
|
38
|
+
if (sessionDataCookie) {
|
|
39
|
+
const strategy = ctx.context.options.session?.cookieCache?.strategy || "compact";
|
|
40
|
+
if (strategy === "jwe") {
|
|
41
|
+
const payload = await symmetricDecodeJWT(sessionDataCookie, ctx.context.secret, "payvo-auth-session");
|
|
42
|
+
if (payload && payload.session && payload.user) sessionDataPayload = {
|
|
43
|
+
session: {
|
|
44
|
+
session: payload.session,
|
|
45
|
+
user: payload.user,
|
|
46
|
+
updatedAt: payload.updatedAt,
|
|
47
|
+
version: payload.version
|
|
48
|
+
},
|
|
49
|
+
expiresAt: payload.exp ? payload.exp * 1e3 : Date.now()
|
|
50
|
+
};
|
|
51
|
+
else {
|
|
52
|
+
const dataCookie = ctx.context.authCookies.sessionData.name;
|
|
53
|
+
ctx.setCookie(dataCookie, "", { maxAge: 0 });
|
|
54
|
+
return ctx.json(null);
|
|
55
|
+
}
|
|
56
|
+
} else if (strategy === "jwt") {
|
|
57
|
+
const payload = await verifyJWT(sessionDataCookie, ctx.context.secret);
|
|
58
|
+
if (payload && payload.session && payload.user) sessionDataPayload = {
|
|
59
|
+
session: {
|
|
60
|
+
session: payload.session,
|
|
61
|
+
user: payload.user,
|
|
62
|
+
updatedAt: payload.updatedAt,
|
|
63
|
+
version: payload.version
|
|
64
|
+
},
|
|
65
|
+
expiresAt: payload.exp ? payload.exp * 1e3 : Date.now()
|
|
66
|
+
};
|
|
67
|
+
else {
|
|
68
|
+
const dataCookie = ctx.context.authCookies.sessionData.name;
|
|
69
|
+
ctx.setCookie(dataCookie, "", { maxAge: 0 });
|
|
70
|
+
return ctx.json(null);
|
|
71
|
+
}
|
|
72
|
+
} else {
|
|
73
|
+
const parsed = safeJSONParse(binary.decode(base64Url.decode(sessionDataCookie)));
|
|
74
|
+
if (parsed) if (await createHMAC("SHA-256", "base64urlnopad").verify(ctx.context.secret, JSON.stringify({
|
|
75
|
+
...parsed.session,
|
|
76
|
+
expiresAt: parsed.expiresAt
|
|
77
|
+
}), parsed.signature)) sessionDataPayload = parsed;
|
|
78
|
+
else {
|
|
79
|
+
const dataCookie = ctx.context.authCookies.sessionData.name;
|
|
80
|
+
ctx.setCookie(dataCookie, "", { maxAge: 0 });
|
|
81
|
+
return ctx.json(null);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
const dontRememberMe = await ctx.getSignedCookie(ctx.context.authCookies.dontRememberToken.name, ctx.context.secret);
|
|
86
|
+
/**
|
|
87
|
+
* If session data is present in the cookie, check if it should be used or refreshed
|
|
88
|
+
*/
|
|
89
|
+
if (sessionDataPayload?.session && ctx.context.options.session?.cookieCache?.enabled && !ctx.query?.disableCookieCache) {
|
|
90
|
+
const session$1 = sessionDataPayload.session;
|
|
91
|
+
const versionConfig = ctx.context.options.session?.cookieCache?.version;
|
|
92
|
+
let expectedVersion = "1";
|
|
93
|
+
if (versionConfig) {
|
|
94
|
+
if (typeof versionConfig === "string") expectedVersion = versionConfig;
|
|
95
|
+
else if (typeof versionConfig === "function") {
|
|
96
|
+
const result = versionConfig(session$1.session, session$1.user);
|
|
97
|
+
expectedVersion = result instanceof Promise ? await result : result;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
if ((session$1.version || "1") !== expectedVersion) {
|
|
101
|
+
const dataCookie = ctx.context.authCookies.sessionData.name;
|
|
102
|
+
ctx.setCookie(dataCookie, "", { maxAge: 0 });
|
|
103
|
+
} else if (sessionDataPayload.expiresAt < Date.now() || session$1.session.expiresAt < /* @__PURE__ */ new Date()) {
|
|
104
|
+
const dataCookie = ctx.context.authCookies.sessionData.name;
|
|
105
|
+
ctx.setCookie(dataCookie, "", { maxAge: 0 });
|
|
106
|
+
} else {
|
|
107
|
+
const cookieRefreshCache = ctx.context.sessionConfig.cookieRefreshCache;
|
|
108
|
+
if (cookieRefreshCache === false) {
|
|
109
|
+
ctx.context.session = session$1;
|
|
110
|
+
return ctx.json({
|
|
111
|
+
session: session$1.session,
|
|
112
|
+
user: session$1.user
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
if (sessionDataPayload.expiresAt - Date.now() < cookieRefreshCache.updateAge * 1e3) {
|
|
116
|
+
const newExpiresAt = getDate(ctx.context.options.session?.cookieCache?.maxAge || 300, "sec");
|
|
117
|
+
const refreshedSession = {
|
|
118
|
+
session: {
|
|
119
|
+
...session$1.session,
|
|
120
|
+
expiresAt: newExpiresAt
|
|
121
|
+
},
|
|
122
|
+
user: session$1.user,
|
|
123
|
+
updatedAt: Date.now()
|
|
124
|
+
};
|
|
125
|
+
await setCookieCache(ctx, refreshedSession, false);
|
|
126
|
+
const parsedRefreshedSession = parseSessionOutput(ctx.context.options, {
|
|
127
|
+
...refreshedSession.session,
|
|
128
|
+
expiresAt: new Date(refreshedSession.session.expiresAt),
|
|
129
|
+
createdAt: new Date(refreshedSession.session.createdAt),
|
|
130
|
+
updatedAt: new Date(refreshedSession.session.updatedAt)
|
|
131
|
+
});
|
|
132
|
+
const parsedRefreshedUser = parseUserOutput(ctx.context.options, {
|
|
133
|
+
...refreshedSession.user,
|
|
134
|
+
createdAt: new Date(refreshedSession.user.createdAt),
|
|
135
|
+
updatedAt: new Date(refreshedSession.user.updatedAt)
|
|
136
|
+
});
|
|
137
|
+
ctx.context.session = {
|
|
138
|
+
session: parsedRefreshedSession,
|
|
139
|
+
user: parsedRefreshedUser
|
|
140
|
+
};
|
|
141
|
+
return ctx.json({
|
|
142
|
+
session: parsedRefreshedSession,
|
|
143
|
+
user: parsedRefreshedUser
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
const parsedSession = parseSessionOutput(ctx.context.options, {
|
|
147
|
+
...session$1.session,
|
|
148
|
+
expiresAt: new Date(session$1.session.expiresAt),
|
|
149
|
+
createdAt: new Date(session$1.session.createdAt),
|
|
150
|
+
updatedAt: new Date(session$1.session.updatedAt)
|
|
151
|
+
});
|
|
152
|
+
const parsedUser = parseUserOutput(ctx.context.options, {
|
|
153
|
+
...session$1.user,
|
|
154
|
+
createdAt: new Date(session$1.user.createdAt),
|
|
155
|
+
updatedAt: new Date(session$1.user.updatedAt)
|
|
156
|
+
});
|
|
157
|
+
ctx.context.session = {
|
|
158
|
+
session: parsedSession,
|
|
159
|
+
user: parsedUser
|
|
160
|
+
};
|
|
161
|
+
return ctx.json({
|
|
162
|
+
session: parsedSession,
|
|
163
|
+
user: parsedUser
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
const session = await ctx.context.internalAdapter.findSession(sessionCookieToken);
|
|
168
|
+
ctx.context.session = session;
|
|
169
|
+
if (!session || session.session.expiresAt < /* @__PURE__ */ new Date()) {
|
|
170
|
+
deleteSessionCookie(ctx);
|
|
171
|
+
if (session)
|
|
172
|
+
/**
|
|
173
|
+
* if session expired clean up the session
|
|
174
|
+
*/
|
|
175
|
+
await ctx.context.internalAdapter.deleteSession(session.session.token);
|
|
176
|
+
return ctx.json(null);
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* We don't need to update the session if the user doesn't want to be remembered
|
|
180
|
+
* or if the session refresh is disabled
|
|
181
|
+
*/
|
|
182
|
+
if (dontRememberMe || ctx.query?.disableRefresh) {
|
|
183
|
+
const parsedSession = parseSessionOutput(ctx.context.options, session.session);
|
|
184
|
+
const parsedUser = parseUserOutput(ctx.context.options, session.user);
|
|
185
|
+
return ctx.json({
|
|
186
|
+
session: parsedSession,
|
|
187
|
+
user: parsedUser
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
const expiresIn = ctx.context.sessionConfig.expiresIn;
|
|
191
|
+
const updateAge = ctx.context.sessionConfig.updateAge;
|
|
192
|
+
if (session.session.expiresAt.valueOf() - expiresIn * 1e3 + updateAge * 1e3 <= Date.now() && (!ctx.query?.disableRefresh || !ctx.context.options.session?.disableSessionRefresh)) {
|
|
193
|
+
const updatedSession = await ctx.context.internalAdapter.updateSession(session.session.token, {
|
|
194
|
+
expiresAt: getDate(ctx.context.sessionConfig.expiresIn, "sec"),
|
|
195
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
196
|
+
});
|
|
197
|
+
if (!updatedSession) {
|
|
198
|
+
/**
|
|
199
|
+
* Handle case where session update fails (e.g., concurrent deletion)
|
|
200
|
+
*/
|
|
201
|
+
deleteSessionCookie(ctx);
|
|
202
|
+
return ctx.json(null, { status: 401 });
|
|
203
|
+
}
|
|
204
|
+
const maxAge = (updatedSession.expiresAt.valueOf() - Date.now()) / 1e3;
|
|
205
|
+
await setSessionCookie(ctx, {
|
|
206
|
+
session: updatedSession,
|
|
207
|
+
user: session.user
|
|
208
|
+
}, false, { maxAge });
|
|
209
|
+
const parsedUpdatedSession = parseSessionOutput(ctx.context.options, updatedSession);
|
|
210
|
+
const parsedUser = parseUserOutput(ctx.context.options, session.user);
|
|
211
|
+
return ctx.json({
|
|
212
|
+
session: parsedUpdatedSession,
|
|
213
|
+
user: parsedUser
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
await setCookieCache(ctx, session, !!dontRememberMe);
|
|
217
|
+
return ctx.json(session);
|
|
218
|
+
} catch (error) {
|
|
219
|
+
ctx.context.logger.error("INTERNAL_SERVER_ERROR", error);
|
|
220
|
+
throw new APIError("INTERNAL_SERVER_ERROR", { message: BASE_ERROR_CODES.FAILED_TO_GET_SESSION });
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
const getSessionFromCtx = async (ctx, config) => {
|
|
224
|
+
if (ctx.context.session) return ctx.context.session;
|
|
225
|
+
const session = await getSession()({
|
|
226
|
+
...ctx,
|
|
227
|
+
asResponse: false,
|
|
228
|
+
headers: ctx.headers,
|
|
229
|
+
returnHeaders: false,
|
|
230
|
+
query: {
|
|
231
|
+
...config,
|
|
232
|
+
...ctx.query
|
|
233
|
+
}
|
|
234
|
+
}).catch((e) => {
|
|
235
|
+
return null;
|
|
236
|
+
});
|
|
237
|
+
ctx.context.session = session;
|
|
238
|
+
return session;
|
|
239
|
+
};
|
|
240
|
+
/**
|
|
241
|
+
* The middleware forces the endpoint to require a valid session.
|
|
242
|
+
*/
|
|
243
|
+
const sessionMiddleware = createAuthMiddleware(async (ctx) => {
|
|
244
|
+
const session = await getSessionFromCtx(ctx);
|
|
245
|
+
if (!session?.session) throw new APIError("UNAUTHORIZED");
|
|
246
|
+
return { session };
|
|
247
|
+
});
|
|
248
|
+
/**
|
|
249
|
+
* This middleware forces the endpoint to require a valid session and ignores cookie cache.
|
|
250
|
+
* This should be used for sensitive operations like password changes, account deletion, etc.
|
|
251
|
+
* to ensure that revoked sessions cannot be used even if they're still cached in cookies.
|
|
252
|
+
*/
|
|
253
|
+
const sensitiveSessionMiddleware = createAuthMiddleware(async (ctx) => {
|
|
254
|
+
const session = await getSessionFromCtx(ctx, { disableCookieCache: true });
|
|
255
|
+
if (!session?.session) throw new APIError("UNAUTHORIZED");
|
|
256
|
+
return { session };
|
|
257
|
+
});
|
|
258
|
+
/**
|
|
259
|
+
* This middleware allows you to call the endpoint on the client if session is valid.
|
|
260
|
+
* However, if called on the server, no session is required.
|
|
261
|
+
*/
|
|
262
|
+
const requestOnlySessionMiddleware = createAuthMiddleware(async (ctx) => {
|
|
263
|
+
const session = await getSessionFromCtx(ctx);
|
|
264
|
+
if (!session?.session && (ctx.request || ctx.headers)) throw new APIError("UNAUTHORIZED");
|
|
265
|
+
return { session };
|
|
266
|
+
});
|
|
267
|
+
/**
|
|
268
|
+
* This middleware forces the endpoint to require a valid session,
|
|
269
|
+
* as well as making sure the session is fresh before proceeding.
|
|
270
|
+
*
|
|
271
|
+
* Session freshness check will be skipped if the session config's freshAge
|
|
272
|
+
* is set to 0
|
|
273
|
+
*/
|
|
274
|
+
const freshSessionMiddleware = createAuthMiddleware(async (ctx) => {
|
|
275
|
+
const session = await getSessionFromCtx(ctx);
|
|
276
|
+
if (!session?.session) throw new APIError("UNAUTHORIZED");
|
|
277
|
+
if (ctx.context.sessionConfig.freshAge === 0) return { session };
|
|
278
|
+
const freshAge = ctx.context.sessionConfig.freshAge;
|
|
279
|
+
const lastUpdated = session.session.updatedAt?.valueOf() || session.session.createdAt.valueOf();
|
|
280
|
+
if (!(Date.now() - lastUpdated < freshAge * 1e3)) throw new APIError("FORBIDDEN", { message: "Session is not fresh" });
|
|
281
|
+
return { session };
|
|
282
|
+
});
|
|
283
|
+
/**
|
|
284
|
+
* user active sessions list
|
|
285
|
+
*/
|
|
286
|
+
const listSessions = () => createAuthEndpoint("/list-sessions", {
|
|
287
|
+
method: "GET",
|
|
288
|
+
use: [sessionMiddleware],
|
|
289
|
+
requireHeaders: true,
|
|
290
|
+
metadata: { openapi: {
|
|
291
|
+
description: "List all active sessions for the user",
|
|
292
|
+
responses: { "200": {
|
|
293
|
+
description: "Success",
|
|
294
|
+
content: { "application/json": { schema: {
|
|
295
|
+
type: "array",
|
|
296
|
+
items: { $ref: "#/components/schemas/Session" }
|
|
297
|
+
} } }
|
|
298
|
+
} }
|
|
299
|
+
} }
|
|
300
|
+
}, async (ctx) => {
|
|
301
|
+
try {
|
|
302
|
+
const activeSessions = (await ctx.context.internalAdapter.listSessions(ctx.context.session.user.id)).filter((session) => {
|
|
303
|
+
return session.expiresAt > /* @__PURE__ */ new Date();
|
|
304
|
+
});
|
|
305
|
+
return ctx.json(activeSessions);
|
|
306
|
+
} catch (e) {
|
|
307
|
+
ctx.context.logger.error(e);
|
|
308
|
+
throw ctx.error("INTERNAL_SERVER_ERROR");
|
|
309
|
+
}
|
|
310
|
+
});
|
|
311
|
+
/**
|
|
312
|
+
* revoke a single session
|
|
313
|
+
*/
|
|
314
|
+
const revokeSession = createAuthEndpoint("/revoke-session", {
|
|
315
|
+
method: "POST",
|
|
316
|
+
body: z$1.object({ token: z$1.string().meta({ description: "The token to revoke" }) }),
|
|
317
|
+
use: [sensitiveSessionMiddleware],
|
|
318
|
+
requireHeaders: true,
|
|
319
|
+
metadata: { openapi: {
|
|
320
|
+
description: "Revoke a single session",
|
|
321
|
+
requestBody: { content: { "application/json": { schema: {
|
|
322
|
+
type: "object",
|
|
323
|
+
properties: { token: {
|
|
324
|
+
type: "string",
|
|
325
|
+
description: "The token to revoke"
|
|
326
|
+
} },
|
|
327
|
+
required: ["token"]
|
|
328
|
+
} } } },
|
|
329
|
+
responses: { "200": {
|
|
330
|
+
description: "Success",
|
|
331
|
+
content: { "application/json": { schema: {
|
|
332
|
+
type: "object",
|
|
333
|
+
properties: { status: {
|
|
334
|
+
type: "boolean",
|
|
335
|
+
description: "Indicates if the session was revoked successfully"
|
|
336
|
+
} },
|
|
337
|
+
required: ["status"]
|
|
338
|
+
} } }
|
|
339
|
+
} }
|
|
340
|
+
} }
|
|
341
|
+
}, async (ctx) => {
|
|
342
|
+
const token = ctx.body.token;
|
|
343
|
+
const findSession = await ctx.context.internalAdapter.findSession(token);
|
|
344
|
+
if (!findSession) throw new APIError("BAD_REQUEST", { message: "Session not found" });
|
|
345
|
+
if (findSession.session.userId !== ctx.context.session.user.id) throw new APIError("UNAUTHORIZED");
|
|
346
|
+
try {
|
|
347
|
+
await ctx.context.internalAdapter.deleteSession(token);
|
|
348
|
+
} catch (error) {
|
|
349
|
+
ctx.context.logger.error(error && typeof error === "object" && "name" in error ? error.name : "", error);
|
|
350
|
+
throw new APIError("INTERNAL_SERVER_ERROR");
|
|
351
|
+
}
|
|
352
|
+
return ctx.json({ status: true });
|
|
353
|
+
});
|
|
354
|
+
/**
|
|
355
|
+
* revoke all user sessions
|
|
356
|
+
*/
|
|
357
|
+
const revokeSessions = createAuthEndpoint("/revoke-sessions", {
|
|
358
|
+
method: "POST",
|
|
359
|
+
use: [sensitiveSessionMiddleware],
|
|
360
|
+
requireHeaders: true,
|
|
361
|
+
metadata: { openapi: {
|
|
362
|
+
description: "Revoke all sessions for the user",
|
|
363
|
+
responses: { "200": {
|
|
364
|
+
description: "Success",
|
|
365
|
+
content: { "application/json": { schema: {
|
|
366
|
+
type: "object",
|
|
367
|
+
properties: { status: {
|
|
368
|
+
type: "boolean",
|
|
369
|
+
description: "Indicates if all sessions were revoked successfully"
|
|
370
|
+
} },
|
|
371
|
+
required: ["status"]
|
|
372
|
+
} } }
|
|
373
|
+
} }
|
|
374
|
+
} }
|
|
375
|
+
}, async (ctx) => {
|
|
376
|
+
try {
|
|
377
|
+
await ctx.context.internalAdapter.deleteSessions(ctx.context.session.user.id);
|
|
378
|
+
} catch (error) {
|
|
379
|
+
ctx.context.logger.error(error && typeof error === "object" && "name" in error ? error.name : "", error);
|
|
380
|
+
throw new APIError("INTERNAL_SERVER_ERROR");
|
|
381
|
+
}
|
|
382
|
+
return ctx.json({ status: true });
|
|
383
|
+
});
|
|
384
|
+
const revokeOtherSessions = createAuthEndpoint("/revoke-other-sessions", {
|
|
385
|
+
method: "POST",
|
|
386
|
+
requireHeaders: true,
|
|
387
|
+
use: [sensitiveSessionMiddleware],
|
|
388
|
+
metadata: { openapi: {
|
|
389
|
+
description: "Revoke all other sessions for the user except the current one",
|
|
390
|
+
responses: { "200": {
|
|
391
|
+
description: "Success",
|
|
392
|
+
content: { "application/json": { schema: {
|
|
393
|
+
type: "object",
|
|
394
|
+
properties: { status: {
|
|
395
|
+
type: "boolean",
|
|
396
|
+
description: "Indicates if all other sessions were revoked successfully"
|
|
397
|
+
} },
|
|
398
|
+
required: ["status"]
|
|
399
|
+
} } }
|
|
400
|
+
} }
|
|
401
|
+
} }
|
|
402
|
+
}, async (ctx) => {
|
|
403
|
+
const session = ctx.context.session;
|
|
404
|
+
if (!session.user) throw new APIError("UNAUTHORIZED");
|
|
405
|
+
const otherSessions = (await ctx.context.internalAdapter.listSessions(session.user.id)).filter((session$1) => {
|
|
406
|
+
return session$1.expiresAt > /* @__PURE__ */ new Date();
|
|
407
|
+
}).filter((session$1) => session$1.token !== ctx.context.session.session.token);
|
|
408
|
+
await Promise.all(otherSessions.map((session$1) => ctx.context.internalAdapter.deleteSession(session$1.token)));
|
|
409
|
+
return ctx.json({ status: true });
|
|
410
|
+
});
|
|
411
|
+
|
|
412
|
+
//#endregion
|
|
413
|
+
export { requestOnlySessionMiddleware as a, revokeSessions as c, listSessions as i, sensitiveSessionMiddleware as l, getSession as n, revokeOtherSessions as o, getSessionFromCtx as r, revokeSession as s, freshSessionMiddleware as t, sessionMiddleware as u };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@gatwech/core/social-providers";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { PayvoAuthOptions } from "@gatwech/core";
|
|
2
|
+
import type { DBAdapter } from "@gatwech/core/db/adapter";
|
|
3
|
+
import type { AdapterFactoryOptions } from "./types";
|
|
4
|
+
export * from "./types";
|
|
5
|
+
export type AdapterFactory = (options: PayvoAuthOptions) => DBAdapter<PayvoAuthOptions>;
|
|
6
|
+
export declare const createAdapterFactory: ({ adapter: customAdapter, config: cfg, }: AdapterFactoryOptions) => AdapterFactory;
|
|
7
|
+
/**
|
|
8
|
+
* @deprecated Use `createAdapterFactory` instead. This export will be removed in a future version.
|
|
9
|
+
*/
|
|
10
|
+
export declare const createAdapter: ({ adapter: customAdapter, config: cfg, }: AdapterFactoryOptions) => AdapterFactory;
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import type { PayvoAuthOptions } from "@gatwech/core";
|
|
2
|
+
import type { PayvoAuthDBSchema, DBFieldAttribute } from "@gatwech/core/db";
|
|
3
|
+
import type { CustomAdapter as CoreCustomAdapter, DBAdapterFactoryConfig, DBAdapterSchemaCreation, DBTransactionAdapter } from "@gatwech/core/db/adapter";
|
|
4
|
+
import type { Where } from "../../types";
|
|
5
|
+
import type { Prettify } from "../../types/helper";
|
|
6
|
+
export type AdapterFactoryOptions = {
|
|
7
|
+
config: DBAdapterFactoryConfig;
|
|
8
|
+
adapter: AdapterFactoryCustomizeAdapterCreator;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* @deprecated Use `DBAdapterFactoryConfig` from `@gatwech/core/db/adapter` instead.
|
|
12
|
+
*/
|
|
13
|
+
export interface AdapterFactoryConfig extends Omit<DBAdapterFactoryConfig<PayvoAuthOptions>, "transaction"> {
|
|
14
|
+
/**
|
|
15
|
+
* Execute multiple operations in a transaction.
|
|
16
|
+
*
|
|
17
|
+
* If the database doesn't support transactions, set this to `false` and operations will be executed sequentially.
|
|
18
|
+
*
|
|
19
|
+
* @default false
|
|
20
|
+
*/
|
|
21
|
+
transaction?: (false | (<R>(callback: (trx: DBTransactionAdapter) => Promise<R>) => Promise<R>)) | undefined;
|
|
22
|
+
}
|
|
23
|
+
export type AdapterFactoryCustomizeAdapterCreator = (config: {
|
|
24
|
+
options: PayvoAuthOptions;
|
|
25
|
+
/**
|
|
26
|
+
* The schema of the user's Payvo-Auth instance.
|
|
27
|
+
*/
|
|
28
|
+
schema: PayvoAuthDBSchema;
|
|
29
|
+
/**
|
|
30
|
+
* The debug log function.
|
|
31
|
+
*
|
|
32
|
+
* If the config has defined `debugLogs` as `false`, no logs will be shown.
|
|
33
|
+
*/
|
|
34
|
+
debugLog: (...args: any[]) => void;
|
|
35
|
+
/**
|
|
36
|
+
* Get the model name which is expected to be saved in the database based on the user's schema.
|
|
37
|
+
*/
|
|
38
|
+
getModelName: (model: string) => string;
|
|
39
|
+
/**
|
|
40
|
+
* Get the field name which is expected to be saved in the database based on the user's schema.
|
|
41
|
+
*/
|
|
42
|
+
getFieldName: ({ model, field }: {
|
|
43
|
+
model: string;
|
|
44
|
+
field: string;
|
|
45
|
+
}) => string;
|
|
46
|
+
/**
|
|
47
|
+
* This function helps us get the default model name from the schema defined by devs.
|
|
48
|
+
* Often times, the user will be using the `modelName` which could had been customized by the users.
|
|
49
|
+
* This function helps us get the actual model name useful to match against the schema. (eg: schema[model])
|
|
50
|
+
*
|
|
51
|
+
* If it's still unclear what this does:
|
|
52
|
+
*
|
|
53
|
+
* 1. User can define a custom modelName.
|
|
54
|
+
* 2. When using a custom modelName, doing something like `schema[model]` will not work.
|
|
55
|
+
* 3. Using this function helps us get the actual model name based on the user's defined custom modelName.
|
|
56
|
+
* 4. Thus allowing us to use `schema[model]`.
|
|
57
|
+
*/
|
|
58
|
+
getDefaultModelName: (model: string) => string;
|
|
59
|
+
/**
|
|
60
|
+
* This function helps us get the default field name from the schema defined by devs.
|
|
61
|
+
* Often times, the user will be using the `fieldName` which could had been customized by the users.
|
|
62
|
+
* This function helps us get the actual field name useful to match against the schema. (eg: schema[model].fields[field])
|
|
63
|
+
*
|
|
64
|
+
* If it's still unclear what this does:
|
|
65
|
+
*
|
|
66
|
+
* 1. User can define a custom fieldName.
|
|
67
|
+
* 2. When using a custom fieldName, doing something like `schema[model].fields[field]` will not work.
|
|
68
|
+
*
|
|
69
|
+
*/
|
|
70
|
+
getDefaultFieldName: ({ model, field, }: {
|
|
71
|
+
model: string;
|
|
72
|
+
field: string;
|
|
73
|
+
}) => string;
|
|
74
|
+
/**
|
|
75
|
+
* Get the field attributes for a given model and field.
|
|
76
|
+
*
|
|
77
|
+
* Note: any model name or field name is allowed, whether default to schema or not.
|
|
78
|
+
*/
|
|
79
|
+
getFieldAttributes: ({ model, field, }: {
|
|
80
|
+
model: string;
|
|
81
|
+
field: string;
|
|
82
|
+
}) => DBFieldAttribute;
|
|
83
|
+
transformInput: (data: Record<string, any>, defaultModelName: string, action: "create" | "update", forceAllowId?: boolean | undefined) => Promise<Record<string, any>>;
|
|
84
|
+
transformOutput: (data: Record<string, any>, defaultModelName: string, select?: string[] | undefined) => Promise<Record<string, any>>;
|
|
85
|
+
transformWhereClause: <W extends Where[] | undefined>({ model, where, }: {
|
|
86
|
+
where: W;
|
|
87
|
+
model: string;
|
|
88
|
+
}) => W extends undefined ? undefined : CleanedWhere[];
|
|
89
|
+
}) => CoreCustomAdapter;
|
|
90
|
+
/**
|
|
91
|
+
* @deprecated Use `CustomAdapter` from `@gatwech/core/db/adapter` instead.
|
|
92
|
+
*/
|
|
93
|
+
export interface CustomAdapter extends Omit<CoreCustomAdapter, "createSchema"> {
|
|
94
|
+
createSchema?: ((props: {
|
|
95
|
+
/**
|
|
96
|
+
* The file the user may have passed in to the `generate` command as the expected schema file output path.
|
|
97
|
+
*/
|
|
98
|
+
file?: string;
|
|
99
|
+
/**
|
|
100
|
+
* The tables from the user's Payvo-Auth instance schema.
|
|
101
|
+
*/
|
|
102
|
+
tables: PayvoAuthDBSchema;
|
|
103
|
+
}) => Promise<DBAdapterSchemaCreation>) | undefined;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* @deprecated Use `CleanedWhere` from `@gatwech/core/db/adapter` instead.
|
|
107
|
+
*/
|
|
108
|
+
export type CleanedWhere = Prettify<Required<Where>>;
|
|
109
|
+
export type AdapterTestDebugLogs = {
|
|
110
|
+
resetDebugLogs: () => void;
|
|
111
|
+
printDebugLogs: () => void;
|
|
112
|
+
};
|
|
113
|
+
/**
|
|
114
|
+
* @deprecated Use `AdapterFactoryOptions` instead. This export will be removed in a future version.
|
|
115
|
+
*/
|
|
116
|
+
export type CreateAdapterOptions = AdapterFactoryOptions;
|
|
117
|
+
/**
|
|
118
|
+
* @deprecated Use `AdapterFactoryConfig` instead. This export will be removed in a future version.
|
|
119
|
+
*/
|
|
120
|
+
export type AdapterConfig = DBAdapterFactoryConfig;
|
|
121
|
+
/**
|
|
122
|
+
* @deprecated Use `AdapterFactoryCustomizeAdapterCreator` instead. This export will be removed in a future version.
|
|
123
|
+
*/
|
|
124
|
+
export type CreateCustomAdapter = AdapterFactoryCustomizeAdapterCreator;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import type { PayvoAuthOptions } from "@gatwech/core";
|
|
2
|
+
import type { DBAdapter } from "@gatwech/core/db/adapter";
|
|
3
|
+
import { payvoAuth } from "../auth";
|
|
4
|
+
import type { Account, Session, User, Verification } from "../types";
|
|
5
|
+
import type { Logger } from "./test-adapter";
|
|
6
|
+
type GenerateFn = <M extends "user" | "session" | "verification" | "account">(Model: M) => Promise<M extends "user" ? User : M extends "session" ? Session : M extends "verification" ? Verification : M extends "account" ? Account : undefined>;
|
|
7
|
+
type Success<T> = {
|
|
8
|
+
data: T;
|
|
9
|
+
error: null;
|
|
10
|
+
};
|
|
11
|
+
type Failure<E> = {
|
|
12
|
+
data: null;
|
|
13
|
+
error: E;
|
|
14
|
+
};
|
|
15
|
+
type Result<T, E = Error> = Success<T> | Failure<E>;
|
|
16
|
+
export type InsertRandomFn = <M extends "user" | "session" | "verification" | "account", Count extends number = 1>(model: M, count?: Count | undefined) => Promise<Count extends 1 ? M extends "user" ? [User] : M extends "session" ? [User, Session] : M extends "verification" ? [Verification] : M extends "account" ? [User, Account] : [undefined] : Array<M extends "user" ? [User] : M extends "session" ? [User, Session] : M extends "verification" ? [Verification] : M extends "account" ? [User, Account] : [undefined]>>;
|
|
17
|
+
export declare const createTestSuite2: <Tests extends Record<string, (context: {
|
|
18
|
+
/**
|
|
19
|
+
* Mark tests as skipped. All execution after this call will be skipped.
|
|
20
|
+
* This function throws an error, so make sure you are not catching it accidentally.
|
|
21
|
+
* @see {@link https://vitest.dev/guide/test-context#skip}
|
|
22
|
+
*/
|
|
23
|
+
readonly skip: {
|
|
24
|
+
(note?: string | undefined): never;
|
|
25
|
+
(condition: boolean, note?: string | undefined): void;
|
|
26
|
+
};
|
|
27
|
+
}) => Promise<void>>, AdditionalOptions extends Record<string, any> = {}>() => void;
|
|
28
|
+
export declare const createTestSuite: <Tests extends Record<string, (context: {
|
|
29
|
+
/**
|
|
30
|
+
* Mark tests as skipped. All execution after this call will be skipped.
|
|
31
|
+
* This function throws an error, so make sure you are not catching it accidentally.
|
|
32
|
+
* @see {@link https://vitest.dev/guide/test-context#skip}
|
|
33
|
+
*/
|
|
34
|
+
readonly skip: {
|
|
35
|
+
(note?: string | undefined): never;
|
|
36
|
+
(condition: boolean, note?: string | undefined): void;
|
|
37
|
+
};
|
|
38
|
+
}) => Promise<void>>, AdditionalOptions extends Record<string, any> = {}>(suiteName: string, config: {
|
|
39
|
+
defaultPayvoAuthOptions?: PayvoAuthOptions | undefined;
|
|
40
|
+
/**
|
|
41
|
+
* Helpful if the default Payvo Auth options require migrations to be run.
|
|
42
|
+
*/
|
|
43
|
+
alwaysMigrate?: boolean | undefined;
|
|
44
|
+
prefixTests?: string | undefined;
|
|
45
|
+
}, tests: (helpers: {
|
|
46
|
+
adapter: DBAdapter<PayvoAuthOptions>;
|
|
47
|
+
log: Logger;
|
|
48
|
+
generate: GenerateFn;
|
|
49
|
+
insertRandom: InsertRandomFn;
|
|
50
|
+
/**
|
|
51
|
+
* A light cleanup function that will only delete rows it knows about.
|
|
52
|
+
*/
|
|
53
|
+
cleanup: () => Promise<void>;
|
|
54
|
+
/**
|
|
55
|
+
* A hard cleanup function that will delete all rows from the database.
|
|
56
|
+
*/
|
|
57
|
+
hardCleanup: () => Promise<void>;
|
|
58
|
+
modifyPayvoAuthOptions: (options: PayvoAuthOptions, shouldRunMigrations: boolean) => Promise<PayvoAuthOptions>;
|
|
59
|
+
getPayvoAuthOptions: () => PayvoAuthOptions;
|
|
60
|
+
sortModels: (models: Array<Record<string, any> & {
|
|
61
|
+
id: string;
|
|
62
|
+
}>, by?: ("id" | "createdAt") | undefined) => (Record<string, any> & {
|
|
63
|
+
id: string;
|
|
64
|
+
})[];
|
|
65
|
+
getAuth: () => Promise<ReturnType<typeof payvoAuth>>;
|
|
66
|
+
tryCatch<T, E = Error>(promise: Promise<T>): Promise<Result<T, E>>;
|
|
67
|
+
customIdGenerator?: () => any | Promise<any> | undefined;
|
|
68
|
+
transformIdOutput?: (id: any) => string | undefined;
|
|
69
|
+
/**
|
|
70
|
+
* Some adapters may change the ID type, this function allows you to pass the entire model
|
|
71
|
+
* data and it will return the correct payvo-auth-expected transformed data.
|
|
72
|
+
*
|
|
73
|
+
* Eg:
|
|
74
|
+
* MongoDB uses ObjectId for IDs, but it's possible the user can disable that option in the adapter config.
|
|
75
|
+
* Because of this, the expected data would be a string.
|
|
76
|
+
* These sorts of conversions will cause issues with the test when you use the `generate` function.
|
|
77
|
+
* This is because the `generate` function will return the raw data expected to be saved in DB, not the excpected BA output.
|
|
78
|
+
*/
|
|
79
|
+
transformGeneratedModel: (data: Record<string, any>) => Record<string, any>;
|
|
80
|
+
}, additionalOptions?: AdditionalOptions | undefined) => Tests) => (options?: ({
|
|
81
|
+
disableTests?: Partial<Record<keyof Tests, boolean> & {
|
|
82
|
+
ALL?: boolean;
|
|
83
|
+
}>;
|
|
84
|
+
} & AdditionalOptions) | undefined) => (helpers: {
|
|
85
|
+
adapter: () => Promise<DBAdapter<PayvoAuthOptions>>;
|
|
86
|
+
log: Logger;
|
|
87
|
+
adapterDisplayName: string;
|
|
88
|
+
getPayvoAuthOptions: () => PayvoAuthOptions;
|
|
89
|
+
modifyPayvoAuthOptions: (options: PayvoAuthOptions) => Promise<PayvoAuthOptions>;
|
|
90
|
+
cleanup: () => Promise<void>;
|
|
91
|
+
runMigrations: () => Promise<void>;
|
|
92
|
+
prefixTests?: string | undefined;
|
|
93
|
+
onTestFinish: () => Promise<void>;
|
|
94
|
+
customIdGenerator?: () => any | Promise<any> | undefined;
|
|
95
|
+
transformIdOutput?: (id: any) => string | undefined;
|
|
96
|
+
}) => Promise<void>;
|
|
97
|
+
export {};
|