@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,176 @@
|
|
|
1
|
+
import { R as originCheck } from "./api-0pR_I-Nx.mjs";
|
|
2
|
+
import { r as generateRandomString } from "./crypto-Bb42eMrH.mjs";
|
|
3
|
+
import { c as setSessionCookie } from "./cookies-cJObLwn1.mjs";
|
|
4
|
+
import { BASE_ERROR_CODES } from "@gatwech/core/error";
|
|
5
|
+
import { APIError } from "better-call";
|
|
6
|
+
import { createAuthEndpoint } from "@gatwech/core/api";
|
|
7
|
+
import * as z$1 from "zod";
|
|
8
|
+
import { createHash } from "@gatwech/utils/hash";
|
|
9
|
+
import { base64Url } from "@gatwech/utils/base64";
|
|
10
|
+
|
|
11
|
+
//#region src/plugins/magic-link/utils.ts
|
|
12
|
+
const defaultKeyHasher = async (otp) => {
|
|
13
|
+
const hash = await createHash("SHA-256", "none").digest(new TextEncoder().encode(otp));
|
|
14
|
+
return base64Url.encode(new Uint8Array(hash), { padding: false });
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
//#endregion
|
|
18
|
+
//#region src/plugins/magic-link/index.ts
|
|
19
|
+
const magicLink = (options) => {
|
|
20
|
+
const opts = {
|
|
21
|
+
storeToken: "plain",
|
|
22
|
+
...options
|
|
23
|
+
};
|
|
24
|
+
async function storeToken(ctx, token) {
|
|
25
|
+
if (opts.storeToken === "hashed") return await defaultKeyHasher(token);
|
|
26
|
+
if (typeof opts.storeToken === "object" && "type" in opts.storeToken && opts.storeToken.type === "custom-hasher") return await opts.storeToken.hash(token);
|
|
27
|
+
return token;
|
|
28
|
+
}
|
|
29
|
+
return {
|
|
30
|
+
id: "magic-link",
|
|
31
|
+
endpoints: {
|
|
32
|
+
signInMagicLink: createAuthEndpoint("/sign-in/magic-link", {
|
|
33
|
+
method: "POST",
|
|
34
|
+
requireHeaders: true,
|
|
35
|
+
body: z$1.object({
|
|
36
|
+
email: z$1.string().meta({ description: "Email address to send the magic link" }).email(),
|
|
37
|
+
name: z$1.string().meta({ description: "User display name. Only used if the user is registering for the first time. Eg: \"my-name\"" }).optional(),
|
|
38
|
+
callbackURL: z$1.string().meta({ description: "URL to redirect after magic link verification" }).optional(),
|
|
39
|
+
newUserCallbackURL: z$1.string().meta({ description: "URL to redirect after new user signup. Only used if the user is registering for the first time." }).optional(),
|
|
40
|
+
errorCallbackURL: z$1.string().meta({ description: "URL to redirect after error." }).optional()
|
|
41
|
+
}),
|
|
42
|
+
metadata: { openapi: {
|
|
43
|
+
description: "Sign in with magic link",
|
|
44
|
+
responses: { 200: {
|
|
45
|
+
description: "Success",
|
|
46
|
+
content: { "application/json": { schema: {
|
|
47
|
+
type: "object",
|
|
48
|
+
properties: { status: { type: "boolean" } }
|
|
49
|
+
} } }
|
|
50
|
+
} }
|
|
51
|
+
} }
|
|
52
|
+
}, async (ctx) => {
|
|
53
|
+
const { email } = ctx.body;
|
|
54
|
+
if (opts.disableSignUp) {
|
|
55
|
+
if (!await ctx.context.internalAdapter.findUserByEmail(email)) throw new APIError("BAD_REQUEST", { message: BASE_ERROR_CODES.USER_NOT_FOUND });
|
|
56
|
+
}
|
|
57
|
+
const verificationToken = opts?.generateToken ? await opts.generateToken(email) : generateRandomString(32, "a-z", "A-Z");
|
|
58
|
+
const storedToken = await storeToken(ctx, verificationToken);
|
|
59
|
+
await ctx.context.internalAdapter.createVerificationValue({
|
|
60
|
+
identifier: storedToken,
|
|
61
|
+
value: JSON.stringify({
|
|
62
|
+
email,
|
|
63
|
+
name: ctx.body.name
|
|
64
|
+
}),
|
|
65
|
+
expiresAt: new Date(Date.now() + (opts.expiresIn || 300) * 1e3)
|
|
66
|
+
});
|
|
67
|
+
const realBaseURL = new URL(ctx.context.baseURL);
|
|
68
|
+
const pathname = realBaseURL.pathname === "/" ? "" : realBaseURL.pathname;
|
|
69
|
+
const basePath = pathname ? "" : ctx.context.options.basePath || "";
|
|
70
|
+
const url = new URL(`${pathname}${basePath}/magic-link/verify`, realBaseURL.origin);
|
|
71
|
+
url.searchParams.set("token", verificationToken);
|
|
72
|
+
url.searchParams.set("callbackURL", ctx.body.callbackURL || "/");
|
|
73
|
+
if (ctx.body.newUserCallbackURL) url.searchParams.set("newUserCallbackURL", ctx.body.newUserCallbackURL);
|
|
74
|
+
if (ctx.body.errorCallbackURL) url.searchParams.set("errorCallbackURL", ctx.body.errorCallbackURL);
|
|
75
|
+
await options.sendMagicLink({
|
|
76
|
+
email,
|
|
77
|
+
url: url.toString(),
|
|
78
|
+
token: verificationToken
|
|
79
|
+
}, ctx.request);
|
|
80
|
+
return ctx.json({ status: true });
|
|
81
|
+
}),
|
|
82
|
+
magicLinkVerify: createAuthEndpoint("/magic-link/verify", {
|
|
83
|
+
method: "GET",
|
|
84
|
+
query: z$1.object({
|
|
85
|
+
token: z$1.string().meta({ description: "Verification token" }),
|
|
86
|
+
callbackURL: z$1.string().meta({ description: "URL to redirect after magic link verification, if not provided the user will be redirected to the root URL. Eg: \"/dashboard\"" }).optional(),
|
|
87
|
+
errorCallbackURL: z$1.string().meta({ description: "URL to redirect after error." }).optional(),
|
|
88
|
+
newUserCallbackURL: z$1.string().meta({ description: "URL to redirect after new user signup. Only used if the user is registering for the first time." }).optional()
|
|
89
|
+
}),
|
|
90
|
+
use: [
|
|
91
|
+
originCheck((ctx) => {
|
|
92
|
+
return ctx.query.callbackURL ? decodeURIComponent(ctx.query.callbackURL) : "/";
|
|
93
|
+
}),
|
|
94
|
+
originCheck((ctx) => {
|
|
95
|
+
return ctx.query.newUserCallbackURL ? decodeURIComponent(ctx.query.newUserCallbackURL) : "/";
|
|
96
|
+
}),
|
|
97
|
+
originCheck((ctx) => {
|
|
98
|
+
return ctx.query.errorCallbackURL ? decodeURIComponent(ctx.query.errorCallbackURL) : "/";
|
|
99
|
+
})
|
|
100
|
+
],
|
|
101
|
+
requireHeaders: true,
|
|
102
|
+
metadata: { openapi: {
|
|
103
|
+
description: "Verify magic link",
|
|
104
|
+
responses: { 200: {
|
|
105
|
+
description: "Success",
|
|
106
|
+
content: { "application/json": { schema: {
|
|
107
|
+
type: "object",
|
|
108
|
+
properties: {
|
|
109
|
+
session: { $ref: "#/components/schemas/Session" },
|
|
110
|
+
user: { $ref: "#/components/schemas/User" }
|
|
111
|
+
}
|
|
112
|
+
} } }
|
|
113
|
+
} }
|
|
114
|
+
} }
|
|
115
|
+
}, async (ctx) => {
|
|
116
|
+
const token = ctx.query.token;
|
|
117
|
+
const callbackURL = new URL(ctx.query.callbackURL ? decodeURIComponent(ctx.query.callbackURL) : "/", ctx.context.baseURL).toString();
|
|
118
|
+
const errorCallbackURL = new URL(ctx.query.errorCallbackURL ? decodeURIComponent(ctx.query.errorCallbackURL) : callbackURL, ctx.context.baseURL).toString();
|
|
119
|
+
const newUserCallbackURL = new URL(ctx.query.newUserCallbackURL ? decodeURIComponent(ctx.query.newUserCallbackURL) : callbackURL, ctx.context.baseURL).toString();
|
|
120
|
+
callbackURL?.startsWith("http") || (callbackURL ? `${ctx.context.options.baseURL}${callbackURL}` : ctx.context.options.baseURL);
|
|
121
|
+
const storedToken = await storeToken(ctx, token);
|
|
122
|
+
const tokenValue = await ctx.context.internalAdapter.findVerificationValue(storedToken);
|
|
123
|
+
if (!tokenValue) throw ctx.redirect(`${errorCallbackURL}?error=INVALID_TOKEN`);
|
|
124
|
+
if (tokenValue.expiresAt < /* @__PURE__ */ new Date()) {
|
|
125
|
+
await ctx.context.internalAdapter.deleteVerificationValue(tokenValue.id);
|
|
126
|
+
throw ctx.redirect(`${errorCallbackURL}?error=EXPIRED_TOKEN`);
|
|
127
|
+
}
|
|
128
|
+
await ctx.context.internalAdapter.deleteVerificationValue(tokenValue.id);
|
|
129
|
+
const { email, name } = JSON.parse(tokenValue.value);
|
|
130
|
+
let isNewUser = false;
|
|
131
|
+
let user = await ctx.context.internalAdapter.findUserByEmail(email).then((res) => res?.user);
|
|
132
|
+
if (!user) if (!opts.disableSignUp) {
|
|
133
|
+
const newUser = await ctx.context.internalAdapter.createUser({
|
|
134
|
+
email,
|
|
135
|
+
emailVerified: true,
|
|
136
|
+
name: name || ""
|
|
137
|
+
});
|
|
138
|
+
isNewUser = true;
|
|
139
|
+
user = newUser;
|
|
140
|
+
if (!user) throw ctx.redirect(`${errorCallbackURL}?error=failed_to_create_user`);
|
|
141
|
+
} else throw ctx.redirect(`${errorCallbackURL}?error=new_user_signup_disabled`);
|
|
142
|
+
if (!user.emailVerified) await ctx.context.internalAdapter.updateUser(user.id, { emailVerified: true });
|
|
143
|
+
const session = await ctx.context.internalAdapter.createSession(user.id);
|
|
144
|
+
if (!session) throw ctx.redirect(`${errorCallbackURL}?error=failed_to_create_session`);
|
|
145
|
+
await setSessionCookie(ctx, {
|
|
146
|
+
session,
|
|
147
|
+
user
|
|
148
|
+
});
|
|
149
|
+
if (!ctx.query.callbackURL) return ctx.json({
|
|
150
|
+
token: session.token,
|
|
151
|
+
user: {
|
|
152
|
+
id: user.id,
|
|
153
|
+
email: user.email,
|
|
154
|
+
emailVerified: user.emailVerified,
|
|
155
|
+
name: user.name,
|
|
156
|
+
image: user.image,
|
|
157
|
+
createdAt: user.createdAt,
|
|
158
|
+
updatedAt: user.updatedAt
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
if (isNewUser) throw ctx.redirect(newUserCallbackURL);
|
|
162
|
+
throw ctx.redirect(callbackURL);
|
|
163
|
+
})
|
|
164
|
+
},
|
|
165
|
+
rateLimit: [{
|
|
166
|
+
pathMatcher(path) {
|
|
167
|
+
return path.startsWith("/sign-in/magic-link") || path.startsWith("/magic-link/verify");
|
|
168
|
+
},
|
|
169
|
+
window: opts.rateLimit?.window || 60,
|
|
170
|
+
max: opts.rateLimit?.max || 5
|
|
171
|
+
}]
|
|
172
|
+
};
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
//#endregion
|
|
176
|
+
export { magicLink as t };
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { t as APIError } from "./api-0pR_I-Nx.mjs";
|
|
2
|
+
import { c as setSessionCookie, l as parseSetCookieHeader, n as deleteSessionCookie, o as parseCookies } from "./cookies-cJObLwn1.mjs";
|
|
3
|
+
import { u as sessionMiddleware } from "./session-Dgp133Yt.mjs";
|
|
4
|
+
import { defineErrorCodes } from "@gatwech/core/utils";
|
|
5
|
+
import { createAuthEndpoint, createAuthMiddleware } from "@gatwech/core/api";
|
|
6
|
+
import * as z$1 from "zod";
|
|
7
|
+
|
|
8
|
+
//#region src/plugins/multi-session/index.ts
|
|
9
|
+
const ERROR_CODES = defineErrorCodes({ INVALID_SESSION_TOKEN: "Invalid session token" });
|
|
10
|
+
const multiSession = (options) => {
|
|
11
|
+
const opts = {
|
|
12
|
+
maximumSessions: 5,
|
|
13
|
+
...options
|
|
14
|
+
};
|
|
15
|
+
const isMultiSessionCookie = (key) => key.includes("_multi-");
|
|
16
|
+
return {
|
|
17
|
+
id: "multi-session",
|
|
18
|
+
endpoints: {
|
|
19
|
+
listDeviceSessions: createAuthEndpoint("/multi-session/list-device-sessions", {
|
|
20
|
+
method: "GET",
|
|
21
|
+
requireHeaders: true
|
|
22
|
+
}, async (ctx) => {
|
|
23
|
+
const cookieHeader = ctx.headers?.get("cookie");
|
|
24
|
+
if (!cookieHeader) return ctx.json([]);
|
|
25
|
+
const cookies = Object.fromEntries(parseCookies(cookieHeader));
|
|
26
|
+
const sessionTokens = (await Promise.all(Object.entries(cookies).filter(([key]) => isMultiSessionCookie(key)).map(async ([key]) => await ctx.getSignedCookie(key, ctx.context.secret)))).filter((v) => v !== null);
|
|
27
|
+
if (!sessionTokens.length) return ctx.json([]);
|
|
28
|
+
const uniqueUserSessions = (await ctx.context.internalAdapter.findSessions(sessionTokens)).filter((session) => session && session.session.expiresAt > /* @__PURE__ */ new Date()).reduce((acc, session) => {
|
|
29
|
+
if (!acc.find((s) => s.user.id === session.user.id)) acc.push(session);
|
|
30
|
+
return acc;
|
|
31
|
+
}, []);
|
|
32
|
+
return ctx.json(uniqueUserSessions);
|
|
33
|
+
}),
|
|
34
|
+
setActiveSession: createAuthEndpoint("/multi-session/set-active", {
|
|
35
|
+
method: "POST",
|
|
36
|
+
body: z$1.object({ sessionToken: z$1.string().meta({ description: "The session token to set as active" }) }),
|
|
37
|
+
requireHeaders: true,
|
|
38
|
+
use: [sessionMiddleware],
|
|
39
|
+
metadata: { openapi: {
|
|
40
|
+
description: "Set the active session",
|
|
41
|
+
responses: { 200: {
|
|
42
|
+
description: "Success",
|
|
43
|
+
content: { "application/json": { schema: {
|
|
44
|
+
type: "object",
|
|
45
|
+
properties: { session: { $ref: "#/components/schemas/Session" } }
|
|
46
|
+
} } }
|
|
47
|
+
} }
|
|
48
|
+
} }
|
|
49
|
+
}, async (ctx) => {
|
|
50
|
+
const sessionToken = ctx.body.sessionToken;
|
|
51
|
+
const multiSessionCookieName = `${ctx.context.authCookies.sessionToken.name}_multi-${sessionToken.toLowerCase()}`;
|
|
52
|
+
if (!await ctx.getSignedCookie(multiSessionCookieName, ctx.context.secret)) throw new APIError("UNAUTHORIZED", { message: ERROR_CODES.INVALID_SESSION_TOKEN });
|
|
53
|
+
const session = await ctx.context.internalAdapter.findSession(sessionToken);
|
|
54
|
+
if (!session || session.session.expiresAt < /* @__PURE__ */ new Date()) {
|
|
55
|
+
ctx.setCookie(multiSessionCookieName, "", {
|
|
56
|
+
...ctx.context.authCookies.sessionToken.options,
|
|
57
|
+
maxAge: 0
|
|
58
|
+
});
|
|
59
|
+
throw new APIError("UNAUTHORIZED", { message: ERROR_CODES.INVALID_SESSION_TOKEN });
|
|
60
|
+
}
|
|
61
|
+
await setSessionCookie(ctx, session);
|
|
62
|
+
return ctx.json(session);
|
|
63
|
+
}),
|
|
64
|
+
revokeDeviceSession: createAuthEndpoint("/multi-session/revoke", {
|
|
65
|
+
method: "POST",
|
|
66
|
+
body: z$1.object({ sessionToken: z$1.string().meta({ description: "The session token to revoke" }) }),
|
|
67
|
+
requireHeaders: true,
|
|
68
|
+
use: [sessionMiddleware],
|
|
69
|
+
metadata: { openapi: {
|
|
70
|
+
description: "Revoke a device session",
|
|
71
|
+
responses: { 200: {
|
|
72
|
+
description: "Success",
|
|
73
|
+
content: { "application/json": { schema: {
|
|
74
|
+
type: "object",
|
|
75
|
+
properties: { status: { type: "boolean" } }
|
|
76
|
+
} } }
|
|
77
|
+
} }
|
|
78
|
+
} }
|
|
79
|
+
}, async (ctx) => {
|
|
80
|
+
const sessionToken = ctx.body.sessionToken;
|
|
81
|
+
const multiSessionCookieName = `${ctx.context.authCookies.sessionToken.name}_multi-${sessionToken.toLowerCase()}`;
|
|
82
|
+
if (!await ctx.getSignedCookie(multiSessionCookieName, ctx.context.secret)) throw new APIError("UNAUTHORIZED", { message: ERROR_CODES.INVALID_SESSION_TOKEN });
|
|
83
|
+
await ctx.context.internalAdapter.deleteSession(sessionToken);
|
|
84
|
+
ctx.setCookie(multiSessionCookieName, "", {
|
|
85
|
+
...ctx.context.authCookies.sessionToken.options,
|
|
86
|
+
maxAge: 0
|
|
87
|
+
});
|
|
88
|
+
if (!(ctx.context.session?.session.token === sessionToken)) return ctx.json({ status: true });
|
|
89
|
+
const cookieHeader = ctx.headers?.get("cookie");
|
|
90
|
+
if (cookieHeader) {
|
|
91
|
+
const cookies = Object.fromEntries(parseCookies(cookieHeader));
|
|
92
|
+
const sessionTokens = (await Promise.all(Object.entries(cookies).filter(([key]) => isMultiSessionCookie(key)).map(async ([key]) => await ctx.getSignedCookie(key, ctx.context.secret)))).filter((v) => v !== void 0);
|
|
93
|
+
const internalAdapter = ctx.context.internalAdapter;
|
|
94
|
+
if (sessionTokens.length > 0) {
|
|
95
|
+
const validSessions = (await internalAdapter.findSessions(sessionTokens)).filter((session) => session && session.session.expiresAt > /* @__PURE__ */ new Date());
|
|
96
|
+
if (validSessions.length > 0) {
|
|
97
|
+
const nextSession = validSessions[0];
|
|
98
|
+
await setSessionCookie(ctx, nextSession);
|
|
99
|
+
} else deleteSessionCookie(ctx);
|
|
100
|
+
} else deleteSessionCookie(ctx);
|
|
101
|
+
} else deleteSessionCookie(ctx);
|
|
102
|
+
return ctx.json({ status: true });
|
|
103
|
+
})
|
|
104
|
+
},
|
|
105
|
+
hooks: { after: [{
|
|
106
|
+
matcher: () => true,
|
|
107
|
+
handler: createAuthMiddleware(async (ctx) => {
|
|
108
|
+
const cookieString = ctx.context.responseHeaders?.get("set-cookie");
|
|
109
|
+
if (!cookieString) return;
|
|
110
|
+
const setCookies = parseSetCookieHeader(cookieString);
|
|
111
|
+
const sessionCookieConfig = ctx.context.authCookies.sessionToken;
|
|
112
|
+
const sessionToken = ctx.context.newSession?.session.token;
|
|
113
|
+
if (!sessionToken) return;
|
|
114
|
+
const cookies = parseCookies(ctx.headers?.get("cookie") || "");
|
|
115
|
+
const cookieName = `${sessionCookieConfig.name}_multi-${sessionToken.toLowerCase()}`;
|
|
116
|
+
if (setCookies.get(cookieName) || cookies.get(cookieName)) return;
|
|
117
|
+
if (Object.keys(Object.fromEntries(cookies)).filter(isMultiSessionCookie).length + (cookieString.includes("session_token") ? 1 : 0) >= opts.maximumSessions) return;
|
|
118
|
+
await ctx.setSignedCookie(cookieName, sessionToken, ctx.context.secret, sessionCookieConfig.options);
|
|
119
|
+
})
|
|
120
|
+
}, {
|
|
121
|
+
matcher: (context) => context.path === "/sign-out",
|
|
122
|
+
handler: createAuthMiddleware(async (ctx) => {
|
|
123
|
+
const cookieHeader = ctx.headers?.get("cookie");
|
|
124
|
+
if (!cookieHeader) return;
|
|
125
|
+
const cookies = Object.fromEntries(parseCookies(cookieHeader));
|
|
126
|
+
const ids = Object.keys(cookies).map((key) => {
|
|
127
|
+
if (isMultiSessionCookie(key)) {
|
|
128
|
+
ctx.setCookie(key.toLowerCase().replace("__secure-", "__Secure-"), "", {
|
|
129
|
+
...ctx.context.authCookies.sessionToken.options,
|
|
130
|
+
maxAge: 0
|
|
131
|
+
});
|
|
132
|
+
return cookies[key].split(".")[0];
|
|
133
|
+
}
|
|
134
|
+
return null;
|
|
135
|
+
}).filter((v) => v !== null);
|
|
136
|
+
await ctx.context.internalAdapter.deleteSessions(ids);
|
|
137
|
+
})
|
|
138
|
+
}] },
|
|
139
|
+
$ERROR_CODES: ERROR_CODES
|
|
140
|
+
};
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
//#endregion
|
|
144
|
+
export { multiSession as t };
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { CompiledQuery, DEFAULT_MIGRATION_LOCK_TABLE, DEFAULT_MIGRATION_TABLE, DefaultQueryCompiler, Kysely, sql } from "kysely";
|
|
2
|
+
|
|
3
|
+
//#region src/adapters/kysely-adapter/node-sqlite-dialect.ts
|
|
4
|
+
var NodeSqliteAdapter = class {
|
|
5
|
+
get supportsCreateIfNotExists() {
|
|
6
|
+
return true;
|
|
7
|
+
}
|
|
8
|
+
get supportsTransactionalDdl() {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
get supportsReturning() {
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
async acquireMigrationLock() {}
|
|
15
|
+
async releaseMigrationLock() {}
|
|
16
|
+
get supportsOutput() {
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
var NodeSqliteDriver = class {
|
|
21
|
+
#config;
|
|
22
|
+
#connectionMutex = new ConnectionMutex();
|
|
23
|
+
#db;
|
|
24
|
+
#connection;
|
|
25
|
+
constructor(config) {
|
|
26
|
+
this.#config = { ...config };
|
|
27
|
+
}
|
|
28
|
+
async init() {
|
|
29
|
+
this.#db = this.#config.database;
|
|
30
|
+
this.#connection = new NodeSqliteConnection(this.#db);
|
|
31
|
+
if (this.#config.onCreateConnection) await this.#config.onCreateConnection(this.#connection);
|
|
32
|
+
}
|
|
33
|
+
async acquireConnection() {
|
|
34
|
+
await this.#connectionMutex.lock();
|
|
35
|
+
return this.#connection;
|
|
36
|
+
}
|
|
37
|
+
async beginTransaction(connection) {
|
|
38
|
+
await connection.executeQuery(CompiledQuery.raw("begin"));
|
|
39
|
+
}
|
|
40
|
+
async commitTransaction(connection) {
|
|
41
|
+
await connection.executeQuery(CompiledQuery.raw("commit"));
|
|
42
|
+
}
|
|
43
|
+
async rollbackTransaction(connection) {
|
|
44
|
+
await connection.executeQuery(CompiledQuery.raw("rollback"));
|
|
45
|
+
}
|
|
46
|
+
async releaseConnection() {
|
|
47
|
+
this.#connectionMutex.unlock();
|
|
48
|
+
}
|
|
49
|
+
async destroy() {
|
|
50
|
+
this.#db?.close();
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
var NodeSqliteConnection = class {
|
|
54
|
+
#db;
|
|
55
|
+
constructor(db) {
|
|
56
|
+
this.#db = db;
|
|
57
|
+
}
|
|
58
|
+
executeQuery(compiledQuery) {
|
|
59
|
+
const { sql: sql$1, parameters } = compiledQuery;
|
|
60
|
+
const rows = this.#db.prepare(sql$1).all(...parameters);
|
|
61
|
+
return Promise.resolve({ rows });
|
|
62
|
+
}
|
|
63
|
+
async *streamQuery() {
|
|
64
|
+
throw new Error("Streaming query is not supported by SQLite driver.");
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
var ConnectionMutex = class {
|
|
68
|
+
#promise;
|
|
69
|
+
#resolve;
|
|
70
|
+
async lock() {
|
|
71
|
+
while (this.#promise) await this.#promise;
|
|
72
|
+
this.#promise = new Promise((resolve) => {
|
|
73
|
+
this.#resolve = resolve;
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
unlock() {
|
|
77
|
+
const resolve = this.#resolve;
|
|
78
|
+
this.#promise = void 0;
|
|
79
|
+
this.#resolve = void 0;
|
|
80
|
+
resolve?.();
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
var NodeSqliteIntrospector = class {
|
|
84
|
+
#db;
|
|
85
|
+
constructor(db) {
|
|
86
|
+
this.#db = db;
|
|
87
|
+
}
|
|
88
|
+
async getSchemas() {
|
|
89
|
+
return [];
|
|
90
|
+
}
|
|
91
|
+
async getTables(options = { withInternalKyselyTables: false }) {
|
|
92
|
+
let query = this.#db.selectFrom("sqlite_schema").where("type", "=", "table").where("name", "not like", "sqlite_%").select("name").$castTo();
|
|
93
|
+
if (!options.withInternalKyselyTables) query = query.where("name", "!=", DEFAULT_MIGRATION_TABLE).where("name", "!=", DEFAULT_MIGRATION_LOCK_TABLE);
|
|
94
|
+
const tables = await query.execute();
|
|
95
|
+
return Promise.all(tables.map(({ name }) => this.#getTableMetadata(name)));
|
|
96
|
+
}
|
|
97
|
+
async getMetadata(options) {
|
|
98
|
+
return { tables: await this.getTables(options) };
|
|
99
|
+
}
|
|
100
|
+
async #getTableMetadata(table) {
|
|
101
|
+
const db = this.#db;
|
|
102
|
+
const autoIncrementCol = (await db.selectFrom("sqlite_master").where("name", "=", table).select("sql").$castTo().execute())[0]?.sql?.split(/[\(\),]/)?.find((it) => it.toLowerCase().includes("autoincrement"))?.split(/\s+/)?.[0]?.replace(/["`]/g, "");
|
|
103
|
+
return {
|
|
104
|
+
name: table,
|
|
105
|
+
columns: (await db.selectFrom(sql`pragma_table_info(${table})`.as("table_info")).select([
|
|
106
|
+
"name",
|
|
107
|
+
"type",
|
|
108
|
+
"notnull",
|
|
109
|
+
"dflt_value"
|
|
110
|
+
]).execute()).map((col) => ({
|
|
111
|
+
name: col.name,
|
|
112
|
+
dataType: col.type,
|
|
113
|
+
isNullable: !col.notnull,
|
|
114
|
+
isAutoIncrementing: col.name === autoIncrementCol,
|
|
115
|
+
hasDefaultValue: col.dflt_value != null
|
|
116
|
+
})),
|
|
117
|
+
isView: true
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
var NodeSqliteQueryCompiler = class extends DefaultQueryCompiler {
|
|
122
|
+
getCurrentParameterPlaceholder() {
|
|
123
|
+
return "?";
|
|
124
|
+
}
|
|
125
|
+
getLeftIdentifierWrapper() {
|
|
126
|
+
return "\"";
|
|
127
|
+
}
|
|
128
|
+
getRightIdentifierWrapper() {
|
|
129
|
+
return "\"";
|
|
130
|
+
}
|
|
131
|
+
getAutoIncrement() {
|
|
132
|
+
return "autoincrement";
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
var NodeSqliteDialect = class {
|
|
136
|
+
#config;
|
|
137
|
+
constructor(config) {
|
|
138
|
+
this.#config = { ...config };
|
|
139
|
+
}
|
|
140
|
+
createDriver() {
|
|
141
|
+
return new NodeSqliteDriver(this.#config);
|
|
142
|
+
}
|
|
143
|
+
createQueryCompiler() {
|
|
144
|
+
return new NodeSqliteQueryCompiler();
|
|
145
|
+
}
|
|
146
|
+
createAdapter() {
|
|
147
|
+
return new NodeSqliteAdapter();
|
|
148
|
+
}
|
|
149
|
+
createIntrospector(db) {
|
|
150
|
+
return new NodeSqliteIntrospector(db);
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
//#endregion
|
|
155
|
+
export { NodeSqliteAdapter, NodeSqliteDialect, NodeSqliteDriver, NodeSqliteIntrospector, NodeSqliteQueryCompiler };
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { r as getOrigin } from "./url-VB2gAbTI.mjs";
|
|
2
|
+
import { R as originCheck } from "./api-0pR_I-Nx.mjs";
|
|
3
|
+
import { n as symmetricEncrypt, t as symmetricDecrypt } from "./crypto-Bb42eMrH.mjs";
|
|
4
|
+
import { env } from "@gatwech/core/env";
|
|
5
|
+
import { createAuthEndpoint, createAuthMiddleware } from "@gatwech/core/api";
|
|
6
|
+
import * as z$1 from "zod";
|
|
7
|
+
|
|
8
|
+
//#region src/plugins/oauth-proxy/index.ts
|
|
9
|
+
function getVenderBaseURL() {
|
|
10
|
+
const vercel = env.VERCEL_URL ? `https://${env.VERCEL_URL}` : void 0;
|
|
11
|
+
const netlify = env.NETLIFY_URL;
|
|
12
|
+
const render = env.RENDER_URL;
|
|
13
|
+
const aws = env.AWS_LAMBDA_FUNCTION_NAME;
|
|
14
|
+
const google = env.GOOGLE_CLOUD_FUNCTION_NAME;
|
|
15
|
+
const azure = env.AZURE_FUNCTION_NAME;
|
|
16
|
+
return vercel || netlify || render || aws || google || azure;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* A proxy plugin, that allows you to proxy OAuth requests.
|
|
20
|
+
* Useful for development and preview deployments where
|
|
21
|
+
* the redirect URL can't be known in advance to add to the OAuth provider.
|
|
22
|
+
*/
|
|
23
|
+
const oAuthProxy = (opts) => {
|
|
24
|
+
const resolveCurrentURL = (ctx) => {
|
|
25
|
+
return new URL(opts?.currentURL || ctx.request?.url || getVenderBaseURL() || ctx.context.baseURL);
|
|
26
|
+
};
|
|
27
|
+
const checkSkipProxy = (ctx) => {
|
|
28
|
+
if (ctx.request?.headers.get("x-skip-oauth-proxy")) return true;
|
|
29
|
+
if ((opts?.productionURL || env.PAYVO_AUTH_URL) === ctx.context.options.baseURL) return true;
|
|
30
|
+
return false;
|
|
31
|
+
};
|
|
32
|
+
return {
|
|
33
|
+
id: "oauth-proxy",
|
|
34
|
+
options: opts,
|
|
35
|
+
endpoints: { oAuthProxy: createAuthEndpoint("/oauth-proxy-callback", {
|
|
36
|
+
method: "GET",
|
|
37
|
+
query: z$1.object({
|
|
38
|
+
callbackURL: z$1.string().meta({ description: "The URL to redirect to after the proxy" }),
|
|
39
|
+
cookies: z$1.string().meta({ description: "The cookies to set after the proxy" })
|
|
40
|
+
}),
|
|
41
|
+
use: [originCheck((ctx) => ctx.query.callbackURL)],
|
|
42
|
+
metadata: { openapi: {
|
|
43
|
+
description: "OAuth Proxy Callback",
|
|
44
|
+
parameters: [{
|
|
45
|
+
in: "query",
|
|
46
|
+
name: "callbackURL",
|
|
47
|
+
required: true,
|
|
48
|
+
description: "The URL to redirect to after the proxy"
|
|
49
|
+
}, {
|
|
50
|
+
in: "query",
|
|
51
|
+
name: "cookies",
|
|
52
|
+
required: true,
|
|
53
|
+
description: "The cookies to set after the proxy"
|
|
54
|
+
}],
|
|
55
|
+
responses: { 302: {
|
|
56
|
+
description: "Redirect",
|
|
57
|
+
headers: { Location: {
|
|
58
|
+
description: "The URL to redirect to",
|
|
59
|
+
schema: { type: "string" }
|
|
60
|
+
} }
|
|
61
|
+
} }
|
|
62
|
+
} }
|
|
63
|
+
}, async (ctx) => {
|
|
64
|
+
const cookies = ctx.query.cookies;
|
|
65
|
+
const decryptedCookies = await symmetricDecrypt({
|
|
66
|
+
key: ctx.context.secret,
|
|
67
|
+
data: cookies
|
|
68
|
+
}).catch((e) => {
|
|
69
|
+
ctx.context.logger.error(e);
|
|
70
|
+
return null;
|
|
71
|
+
});
|
|
72
|
+
const error = ctx.context.options.onAPIError?.errorURL || `${ctx.context.options.baseURL}/api/auth/error`;
|
|
73
|
+
if (!decryptedCookies) throw ctx.redirect(`${error}?error=OAuthProxy - Invalid cookies or secret`);
|
|
74
|
+
const isSecureContext = resolveCurrentURL(ctx).protocol === "https:";
|
|
75
|
+
const prefix = ctx.context.options.advanced?.cookiePrefix || "payvo-auth";
|
|
76
|
+
const cookieToSet = isSecureContext ? decryptedCookies : decryptedCookies.replace("Secure;", "").replace(`__Secure-${prefix}`, prefix);
|
|
77
|
+
ctx.setHeader("set-cookie", cookieToSet);
|
|
78
|
+
throw ctx.redirect(ctx.query.callbackURL);
|
|
79
|
+
}) },
|
|
80
|
+
hooks: {
|
|
81
|
+
after: [{
|
|
82
|
+
matcher(context) {
|
|
83
|
+
return !!(context.path?.startsWith("/callback") || context.path?.startsWith("/oauth2/callback"));
|
|
84
|
+
},
|
|
85
|
+
handler: createAuthMiddleware(async (ctx) => {
|
|
86
|
+
const headers = ctx.context.responseHeaders;
|
|
87
|
+
const location = headers?.get("location");
|
|
88
|
+
if (location?.includes("/oauth-proxy-callback?callbackURL")) {
|
|
89
|
+
if (!location.startsWith("http")) return;
|
|
90
|
+
const locationURL = new URL(location);
|
|
91
|
+
if (locationURL.origin === getOrigin(opts?.productionURL || ctx.context.options.baseURL || ctx.context.baseURL)) {
|
|
92
|
+
const newLocation = locationURL.searchParams.get("callbackURL");
|
|
93
|
+
if (!newLocation) return;
|
|
94
|
+
ctx.setHeader("location", newLocation);
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
const setCookies = headers?.get("set-cookie");
|
|
98
|
+
if (!setCookies) return;
|
|
99
|
+
const encryptedCookies = await symmetricEncrypt({
|
|
100
|
+
key: ctx.context.secret,
|
|
101
|
+
data: setCookies
|
|
102
|
+
});
|
|
103
|
+
const locationWithCookies = `${location}&cookies=${encodeURIComponent(encryptedCookies)}`;
|
|
104
|
+
ctx.setHeader("location", locationWithCookies);
|
|
105
|
+
}
|
|
106
|
+
})
|
|
107
|
+
}],
|
|
108
|
+
before: [{
|
|
109
|
+
matcher() {
|
|
110
|
+
return true;
|
|
111
|
+
},
|
|
112
|
+
handler: createAuthMiddleware(async (ctx) => {
|
|
113
|
+
if (checkSkipProxy(ctx) || ctx.path !== "/callback/:id") return;
|
|
114
|
+
return { context: { context: { oauthConfig: { skipStateCookieCheck: true } } } };
|
|
115
|
+
})
|
|
116
|
+
}, {
|
|
117
|
+
matcher(context) {
|
|
118
|
+
return !!(context.path?.startsWith("/sign-in/social") || context.path?.startsWith("/sign-in/oauth2"));
|
|
119
|
+
},
|
|
120
|
+
handler: createAuthMiddleware(async (ctx) => {
|
|
121
|
+
if (checkSkipProxy(ctx)) return;
|
|
122
|
+
const url = resolveCurrentURL(ctx);
|
|
123
|
+
if (!ctx.body) return;
|
|
124
|
+
ctx.body.callbackURL = `${url.origin}${ctx.context.options.basePath || "/api/auth"}/oauth-proxy-callback?callbackURL=${encodeURIComponent(ctx.body.callbackURL || ctx.context.baseURL)}`;
|
|
125
|
+
return { context: ctx };
|
|
126
|
+
})
|
|
127
|
+
}]
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
//#endregion
|
|
133
|
+
export { oAuthProxy as t };
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import "../helper-tmxW3BHj.mjs";
|
|
2
|
+
import { Mn as generateState, Nn as parseState, g as User, o as Account } from "../index-Cxi7TbLE.mjs";
|
|
3
|
+
import "../types-B1OL7hyf.mjs";
|
|
4
|
+
import "../index-65G5U5DB-DSdjzreF.mjs";
|
|
5
|
+
import "../plugins-hFZT3hmK.mjs";
|
|
6
|
+
import { AuthContext, GenericEndpointContext } from "@gatwech/core";
|
|
7
|
+
export * from "@gatwech/core/oauth2";
|
|
8
|
+
|
|
9
|
+
//#region src/oauth2/link-account.d.ts
|
|
10
|
+
declare function handleOAuthUserInfo(c: GenericEndpointContext, {
|
|
11
|
+
userInfo,
|
|
12
|
+
account,
|
|
13
|
+
callbackURL,
|
|
14
|
+
disableSignUp,
|
|
15
|
+
overrideUserInfo
|
|
16
|
+
}: {
|
|
17
|
+
userInfo: Omit<User, "createdAt" | "updatedAt">;
|
|
18
|
+
account: Omit<Account, "id" | "userId" | "createdAt" | "updatedAt">;
|
|
19
|
+
callbackURL?: string | undefined;
|
|
20
|
+
disableSignUp?: boolean | undefined;
|
|
21
|
+
overrideUserInfo?: boolean | undefined;
|
|
22
|
+
}): Promise<{
|
|
23
|
+
error: string;
|
|
24
|
+
data: null;
|
|
25
|
+
isRegister?: undefined;
|
|
26
|
+
} | {
|
|
27
|
+
error: string;
|
|
28
|
+
data: null;
|
|
29
|
+
isRegister: boolean;
|
|
30
|
+
} | {
|
|
31
|
+
data: {
|
|
32
|
+
session: {
|
|
33
|
+
id: string;
|
|
34
|
+
createdAt: Date;
|
|
35
|
+
updatedAt: Date;
|
|
36
|
+
userId: string;
|
|
37
|
+
expiresAt: Date;
|
|
38
|
+
token: string;
|
|
39
|
+
ipAddress?: string | null | undefined;
|
|
40
|
+
userAgent?: string | null | undefined;
|
|
41
|
+
};
|
|
42
|
+
user: {
|
|
43
|
+
id: string;
|
|
44
|
+
createdAt: Date;
|
|
45
|
+
updatedAt: Date;
|
|
46
|
+
email: string;
|
|
47
|
+
emailVerified: boolean;
|
|
48
|
+
name: string;
|
|
49
|
+
image?: string | null | undefined;
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
error: null;
|
|
53
|
+
isRegister: boolean;
|
|
54
|
+
}>;
|
|
55
|
+
//#endregion
|
|
56
|
+
//#region src/oauth2/utils.d.ts
|
|
57
|
+
declare function decryptOAuthToken(token: string, ctx: AuthContext): string | Promise<string>;
|
|
58
|
+
declare function setTokenUtil(token: string | null | undefined, ctx: AuthContext): string | Promise<string> | null | undefined;
|
|
59
|
+
//#endregion
|
|
60
|
+
export { decryptOAuthToken, generateState, handleOAuthUserInfo, parseState, setTokenUtil };
|