@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,233 @@
|
|
|
1
|
+
import { t as generateId } from "./utils-SOMB4Px5.mjs";
|
|
2
|
+
import { r as getOrigin, t as getBaseURL } from "./url-VB2gAbTI.mjs";
|
|
3
|
+
import { a as getEndpoints, n as checkEndpointConflicts, s as router } from "./api-0pR_I-Nx.mjs";
|
|
4
|
+
import { a as verifyPassword, i as hashPassword } from "./crypto-Bb42eMrH.mjs";
|
|
5
|
+
import { i as getCookies, t as createCookieGetter } from "./cookies-cJObLwn1.mjs";
|
|
6
|
+
import { a as createInternalAdapter, r as getAdapter, s as getMigrations } from "./db-BrstmDhc.mjs";
|
|
7
|
+
import { n as getKyselyDatabaseType } from "./dialect-CeddeGHf.mjs";
|
|
8
|
+
import { t as getAuthTables } from "./get-tables-BQP7YW9c.mjs";
|
|
9
|
+
import { t as checkPassword } from "./password-sVC4nePO.mjs";
|
|
10
|
+
import { runWithAdapter } from "@gatwech/core/context";
|
|
11
|
+
import { createLogger, env, isProduction, isTest } from "@gatwech/core/env";
|
|
12
|
+
import { BASE_ERROR_CODES, PayvoAuthError } from "@gatwech/core/error";
|
|
13
|
+
import { socialProviders } from "@gatwech/core/social-providers";
|
|
14
|
+
import { defu } from "defu";
|
|
15
|
+
import { createTelemetry } from "@gatwech/telemetry";
|
|
16
|
+
|
|
17
|
+
//#region src/utils/constants.ts
|
|
18
|
+
const DEFAULT_SECRET = "payvo-auth-secret-123456789";
|
|
19
|
+
|
|
20
|
+
//#endregion
|
|
21
|
+
//#region src/utils/is-promise.ts
|
|
22
|
+
function isPromise(obj) {
|
|
23
|
+
return !!obj && (typeof obj === "object" || typeof obj === "function") && typeof obj.then === "function";
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
//#endregion
|
|
27
|
+
//#region src/init.ts
|
|
28
|
+
const init = async (options) => {
|
|
29
|
+
const adapter = await getAdapter(options);
|
|
30
|
+
const plugins = options.plugins || [];
|
|
31
|
+
const internalPlugins = getInternalPlugins(options);
|
|
32
|
+
const logger$1 = createLogger(options.logger);
|
|
33
|
+
const baseURL = getBaseURL(options.baseURL, options.basePath);
|
|
34
|
+
const secret = options.secret || env.PAYVO_AUTH_SECRET || env.AUTH_SECRET || DEFAULT_SECRET;
|
|
35
|
+
if (secret === DEFAULT_SECRET) {
|
|
36
|
+
if (isProduction) logger$1.error("You are using the default secret. Please set `PAYVO_AUTH_SECRET` in your environment variables or pass `secret` in your auth config.");
|
|
37
|
+
}
|
|
38
|
+
options = {
|
|
39
|
+
...options,
|
|
40
|
+
secret,
|
|
41
|
+
baseURL: baseURL ? new URL(baseURL).origin : "",
|
|
42
|
+
basePath: options.basePath || "/api/auth",
|
|
43
|
+
plugins: plugins.concat(internalPlugins)
|
|
44
|
+
};
|
|
45
|
+
checkEndpointConflicts(options, logger$1);
|
|
46
|
+
const cookies = getCookies(options);
|
|
47
|
+
const tables = getAuthTables(options);
|
|
48
|
+
const providers = Object.entries(options.socialProviders || {}).map(([key, config]) => {
|
|
49
|
+
if (config == null) return null;
|
|
50
|
+
if (config.enabled === false) return null;
|
|
51
|
+
if (!config.clientId) logger$1.warn(`Social provider ${key} is missing clientId or clientSecret`);
|
|
52
|
+
const provider = socialProviders[key](config);
|
|
53
|
+
provider.disableImplicitSignUp = config.disableImplicitSignUp;
|
|
54
|
+
return provider;
|
|
55
|
+
}).filter((x) => x !== null);
|
|
56
|
+
const generateIdFunc = ({ model, size }) => {
|
|
57
|
+
if (typeof options.advanced?.generateId === "function") return options.advanced.generateId({
|
|
58
|
+
model,
|
|
59
|
+
size
|
|
60
|
+
});
|
|
61
|
+
if (typeof options?.advanced?.database?.generateId === "function") return options.advanced.database.generateId({
|
|
62
|
+
model,
|
|
63
|
+
size
|
|
64
|
+
});
|
|
65
|
+
return generateId(size);
|
|
66
|
+
};
|
|
67
|
+
const { publish } = await createTelemetry(options, {
|
|
68
|
+
adapter: adapter.id,
|
|
69
|
+
database: typeof options.database === "function" ? "adapter" : getKyselyDatabaseType(options.database) || "unknown"
|
|
70
|
+
});
|
|
71
|
+
const initOrPromise = runPluginInit({
|
|
72
|
+
appName: options.appName || "Payvo Auth",
|
|
73
|
+
socialProviders: providers,
|
|
74
|
+
options,
|
|
75
|
+
oauthConfig: {
|
|
76
|
+
storeStateStrategy: options.advanced?.oauthConfig?.storeStateStrategy || "database",
|
|
77
|
+
skipStateCookieCheck: !!options.advanced?.oauthConfig?.skipStateCookieCheck
|
|
78
|
+
},
|
|
79
|
+
tables,
|
|
80
|
+
trustedOrigins: getTrustedOrigins(options),
|
|
81
|
+
baseURL: baseURL || "",
|
|
82
|
+
sessionConfig: {
|
|
83
|
+
updateAge: options.session?.updateAge !== void 0 ? options.session.updateAge : 1440 * 60,
|
|
84
|
+
expiresIn: options.session?.expiresIn || 3600 * 24 * 7,
|
|
85
|
+
freshAge: options.session?.freshAge === void 0 ? 3600 * 24 : options.session.freshAge,
|
|
86
|
+
cookieRefreshCache: (() => {
|
|
87
|
+
const refreshCache = options.session?.cookieCache?.refreshCache;
|
|
88
|
+
const maxAge = options.session?.cookieCache?.maxAge || 300;
|
|
89
|
+
if (refreshCache === false || refreshCache === void 0) return false;
|
|
90
|
+
if (refreshCache === true) return {
|
|
91
|
+
enabled: true,
|
|
92
|
+
updateAge: Math.floor(maxAge * .2)
|
|
93
|
+
};
|
|
94
|
+
return {
|
|
95
|
+
enabled: true,
|
|
96
|
+
updateAge: refreshCache.updateAge !== void 0 ? refreshCache.updateAge : Math.floor(maxAge * .2)
|
|
97
|
+
};
|
|
98
|
+
})()
|
|
99
|
+
},
|
|
100
|
+
secret,
|
|
101
|
+
rateLimit: {
|
|
102
|
+
...options.rateLimit,
|
|
103
|
+
enabled: options.rateLimit?.enabled ?? isProduction,
|
|
104
|
+
window: options.rateLimit?.window || 10,
|
|
105
|
+
max: options.rateLimit?.max || 100,
|
|
106
|
+
storage: options.rateLimit?.storage || (options.secondaryStorage ? "secondary-storage" : "memory")
|
|
107
|
+
},
|
|
108
|
+
authCookies: cookies,
|
|
109
|
+
logger: logger$1,
|
|
110
|
+
generateId: generateIdFunc,
|
|
111
|
+
session: null,
|
|
112
|
+
secondaryStorage: options.secondaryStorage,
|
|
113
|
+
password: {
|
|
114
|
+
hash: options.emailAndPassword?.password?.hash || hashPassword,
|
|
115
|
+
verify: options.emailAndPassword?.password?.verify || verifyPassword,
|
|
116
|
+
config: {
|
|
117
|
+
minPasswordLength: options.emailAndPassword?.minPasswordLength || 8,
|
|
118
|
+
maxPasswordLength: options.emailAndPassword?.maxPasswordLength || 128
|
|
119
|
+
},
|
|
120
|
+
checkPassword
|
|
121
|
+
},
|
|
122
|
+
setNewSession(session) {
|
|
123
|
+
this.newSession = session;
|
|
124
|
+
},
|
|
125
|
+
newSession: null,
|
|
126
|
+
adapter,
|
|
127
|
+
internalAdapter: createInternalAdapter(adapter, {
|
|
128
|
+
options,
|
|
129
|
+
logger: logger$1,
|
|
130
|
+
hooks: options.databaseHooks ? [options.databaseHooks] : [],
|
|
131
|
+
generateId: generateIdFunc
|
|
132
|
+
}),
|
|
133
|
+
createAuthCookie: createCookieGetter(options),
|
|
134
|
+
async runMigrations() {
|
|
135
|
+
if (!options.database || "updateMany" in options.database) throw new PayvoAuthError("Database is not provided or it's an adapter. Migrations are only supported with a database instance.");
|
|
136
|
+
const { runMigrations } = await getMigrations(options);
|
|
137
|
+
await runMigrations();
|
|
138
|
+
},
|
|
139
|
+
publishTelemetry: publish,
|
|
140
|
+
skipCSRFCheck: !!options.advanced?.disableCSRFCheck,
|
|
141
|
+
skipOriginCheck: options.advanced?.disableOriginCheck !== void 0 ? options.advanced.disableOriginCheck : isTest() ? true : false
|
|
142
|
+
});
|
|
143
|
+
let context;
|
|
144
|
+
if (isPromise(initOrPromise)) ({context} = await initOrPromise);
|
|
145
|
+
else ({context} = initOrPromise);
|
|
146
|
+
return context;
|
|
147
|
+
};
|
|
148
|
+
async function runPluginInit(ctx) {
|
|
149
|
+
let options = ctx.options;
|
|
150
|
+
const plugins = options.plugins || [];
|
|
151
|
+
let context = ctx;
|
|
152
|
+
const dbHooks = [];
|
|
153
|
+
for (const plugin of plugins) if (plugin.init) {
|
|
154
|
+
let initPromise = plugin.init(context);
|
|
155
|
+
let result;
|
|
156
|
+
if (isPromise(initPromise)) result = await initPromise;
|
|
157
|
+
else result = initPromise;
|
|
158
|
+
if (typeof result === "object") {
|
|
159
|
+
if (result.options) {
|
|
160
|
+
const { databaseHooks,...restOpts } = result.options;
|
|
161
|
+
if (databaseHooks) dbHooks.push(databaseHooks);
|
|
162
|
+
options = defu(options, restOpts);
|
|
163
|
+
}
|
|
164
|
+
if (result.context) context = {
|
|
165
|
+
...context,
|
|
166
|
+
...result.context
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
dbHooks.push(options.databaseHooks);
|
|
171
|
+
context.internalAdapter = createInternalAdapter(ctx.adapter, {
|
|
172
|
+
options,
|
|
173
|
+
logger: ctx.logger,
|
|
174
|
+
hooks: dbHooks.filter((u) => u !== void 0),
|
|
175
|
+
generateId: ctx.generateId
|
|
176
|
+
});
|
|
177
|
+
context.options = options;
|
|
178
|
+
return { context };
|
|
179
|
+
}
|
|
180
|
+
function getInternalPlugins(options) {
|
|
181
|
+
const plugins = [];
|
|
182
|
+
if (options.advanced?.crossSubDomainCookies?.enabled) {}
|
|
183
|
+
return plugins;
|
|
184
|
+
}
|
|
185
|
+
function getTrustedOrigins(options) {
|
|
186
|
+
const baseURL = getBaseURL(options.baseURL, options.basePath);
|
|
187
|
+
if (!baseURL) return [];
|
|
188
|
+
const trustedOrigins = [new URL(baseURL).origin];
|
|
189
|
+
if (options.trustedOrigins && Array.isArray(options.trustedOrigins)) trustedOrigins.push(...options.trustedOrigins);
|
|
190
|
+
const envTrustedOrigins = env.PAYVO_AUTH_TRUSTED_ORIGINS;
|
|
191
|
+
if (envTrustedOrigins) trustedOrigins.push(...envTrustedOrigins.split(","));
|
|
192
|
+
if (trustedOrigins.filter((x) => !x).length) throw new PayvoAuthError("A provided trusted origin is invalid, make sure your trusted origins list is properly defined.");
|
|
193
|
+
return trustedOrigins;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
//#endregion
|
|
197
|
+
//#region src/auth.ts
|
|
198
|
+
const payvoAuth = (options) => {
|
|
199
|
+
const authContext = init(options);
|
|
200
|
+
const { api } = getEndpoints(authContext, options);
|
|
201
|
+
return {
|
|
202
|
+
handler: async (request) => {
|
|
203
|
+
const ctx = await authContext;
|
|
204
|
+
const basePath = ctx.options.basePath || "/api/auth";
|
|
205
|
+
if (!ctx.options.baseURL) {
|
|
206
|
+
const baseURL = getBaseURL(void 0, basePath, request);
|
|
207
|
+
if (baseURL) {
|
|
208
|
+
ctx.baseURL = baseURL;
|
|
209
|
+
ctx.options.baseURL = getOrigin(ctx.baseURL) || void 0;
|
|
210
|
+
} else throw new PayvoAuthError("Could not get base URL from request. Please provide a valid base URL.");
|
|
211
|
+
}
|
|
212
|
+
ctx.trustedOrigins = [...options.trustedOrigins ? Array.isArray(options.trustedOrigins) ? options.trustedOrigins : await options.trustedOrigins(request) : [], ctx.options.baseURL];
|
|
213
|
+
const { handler } = router(ctx, options);
|
|
214
|
+
return runWithAdapter(ctx.adapter, () => handler(request));
|
|
215
|
+
},
|
|
216
|
+
api,
|
|
217
|
+
options,
|
|
218
|
+
$context: authContext,
|
|
219
|
+
$ERROR_CODES: {
|
|
220
|
+
...options.plugins?.reduce((acc, plugin) => {
|
|
221
|
+
if (plugin.$ERROR_CODES) return {
|
|
222
|
+
...acc,
|
|
223
|
+
...plugin.$ERROR_CODES
|
|
224
|
+
};
|
|
225
|
+
return acc;
|
|
226
|
+
}, {}),
|
|
227
|
+
...BASE_ERROR_CODES
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
//#endregion
|
|
233
|
+
export { payvoAuth as t };
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { l as parseSetCookieHeader } from "./cookies-cJObLwn1.mjs";
|
|
2
|
+
import { serializeSignedCookie } from "better-call";
|
|
3
|
+
import { createAuthMiddleware } from "@gatwech/core/api";
|
|
4
|
+
import { createHMAC } from "@gatwech/utils/hmac";
|
|
5
|
+
|
|
6
|
+
//#region src/plugins/bearer/index.ts
|
|
7
|
+
/**
|
|
8
|
+
* Converts bearer token to session cookie
|
|
9
|
+
*/
|
|
10
|
+
const bearer = (options) => {
|
|
11
|
+
return {
|
|
12
|
+
id: "bearer",
|
|
13
|
+
hooks: {
|
|
14
|
+
before: [{
|
|
15
|
+
matcher(context) {
|
|
16
|
+
return Boolean(context.request?.headers.get("authorization") || context.headers?.get("authorization"));
|
|
17
|
+
},
|
|
18
|
+
handler: createAuthMiddleware(async (c) => {
|
|
19
|
+
const token = c.request?.headers.get("authorization")?.replace("Bearer ", "") || c.headers?.get("Authorization")?.replace("Bearer ", "");
|
|
20
|
+
if (!token) return;
|
|
21
|
+
let signedToken = "";
|
|
22
|
+
if (token.includes(".")) signedToken = token.replace("=", "");
|
|
23
|
+
else {
|
|
24
|
+
if (options?.requireSignature) return;
|
|
25
|
+
signedToken = (await serializeSignedCookie("", token, c.context.secret)).replace("=", "");
|
|
26
|
+
}
|
|
27
|
+
try {
|
|
28
|
+
const decodedToken = decodeURIComponent(signedToken);
|
|
29
|
+
if (!await createHMAC("SHA-256", "base64urlnopad").verify(c.context.secret, decodedToken.split(".")[0], decodedToken.split(".")[1])) return;
|
|
30
|
+
} catch (e) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const existingHeaders = c.request?.headers || c.headers;
|
|
34
|
+
const headers = new Headers({ ...Object.fromEntries(existingHeaders?.entries()) });
|
|
35
|
+
headers.append("cookie", `${c.context.authCookies.sessionToken.name}=${signedToken}`);
|
|
36
|
+
return { context: { headers } };
|
|
37
|
+
})
|
|
38
|
+
}],
|
|
39
|
+
after: [{
|
|
40
|
+
matcher(context) {
|
|
41
|
+
return true;
|
|
42
|
+
},
|
|
43
|
+
handler: createAuthMiddleware(async (ctx) => {
|
|
44
|
+
const setCookie = ctx.context.responseHeaders?.get("set-cookie");
|
|
45
|
+
if (!setCookie) return;
|
|
46
|
+
const parsedCookies = parseSetCookieHeader(setCookie);
|
|
47
|
+
const cookieName = ctx.context.authCookies.sessionToken.name;
|
|
48
|
+
const sessionCookie = parsedCookies.get(cookieName);
|
|
49
|
+
if (!sessionCookie || !sessionCookie.value || sessionCookie["max-age"] === 0) return;
|
|
50
|
+
const token = sessionCookie.value;
|
|
51
|
+
const exposedHeaders = ctx.context.responseHeaders?.get("access-control-expose-headers") || "";
|
|
52
|
+
const headersSet = new Set(exposedHeaders.split(",").map((header) => header.trim()).filter(Boolean));
|
|
53
|
+
headersSet.add("set-auth-token");
|
|
54
|
+
ctx.setHeader("set-auth-token", token);
|
|
55
|
+
ctx.setHeader("Access-Control-Expose-Headers", Array.from(headersSet).join(", "));
|
|
56
|
+
})
|
|
57
|
+
}]
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
//#endregion
|
|
63
|
+
export { bearer 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/bun-sqlite-dialect.ts
|
|
4
|
+
var BunSqliteAdapter = 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 BunSqliteDriver = 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 BunSqliteConnection(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 BunSqliteConnection = class {
|
|
54
|
+
#db;
|
|
55
|
+
constructor(db) {
|
|
56
|
+
this.#db = db;
|
|
57
|
+
}
|
|
58
|
+
executeQuery(compiledQuery) {
|
|
59
|
+
const { sql: sql$1, parameters } = compiledQuery;
|
|
60
|
+
const stmt = this.#db.prepare(sql$1);
|
|
61
|
+
return Promise.resolve({ rows: stmt.all(parameters) });
|
|
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 BunSqliteIntrospector = 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 BunSqliteQueryCompiler = 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 BunSqliteDialect = class {
|
|
136
|
+
#config;
|
|
137
|
+
constructor(config) {
|
|
138
|
+
this.#config = { ...config };
|
|
139
|
+
}
|
|
140
|
+
createDriver() {
|
|
141
|
+
return new BunSqliteDriver(this.#config);
|
|
142
|
+
}
|
|
143
|
+
createQueryCompiler() {
|
|
144
|
+
return new BunSqliteQueryCompiler();
|
|
145
|
+
}
|
|
146
|
+
createAdapter() {
|
|
147
|
+
return new BunSqliteAdapter();
|
|
148
|
+
}
|
|
149
|
+
createIntrospector(db) {
|
|
150
|
+
return new BunSqliteIntrospector(db);
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
//#endregion
|
|
155
|
+
export { BunSqliteAdapter, BunSqliteDialect, BunSqliteDriver, BunSqliteIntrospector, BunSqliteQueryCompiler };
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { t as getIp } from "./get-request-ip-DSjrEpGo.mjs";
|
|
2
|
+
import { defineErrorCodes } from "@gatwech/core/utils";
|
|
3
|
+
import { betterFetch } from "@better-fetch/fetch";
|
|
4
|
+
|
|
5
|
+
//#region src/utils/middleware-response.ts
|
|
6
|
+
const middlewareResponse = ({ message, status }) => ({ response: new Response(JSON.stringify({ message }), { status }) });
|
|
7
|
+
|
|
8
|
+
//#endregion
|
|
9
|
+
//#region src/plugins/captcha/constants.ts
|
|
10
|
+
const defaultEndpoints = [
|
|
11
|
+
"/sign-up/email",
|
|
12
|
+
"/sign-in/email",
|
|
13
|
+
"/request-password-reset"
|
|
14
|
+
];
|
|
15
|
+
const Providers = {
|
|
16
|
+
CLOUDFLARE_TURNSTILE: "cloudflare-turnstile",
|
|
17
|
+
GOOGLE_RECAPTCHA: "google-recaptcha",
|
|
18
|
+
HCAPTCHA: "hcaptcha",
|
|
19
|
+
CAPTCHAFOX: "captchafox"
|
|
20
|
+
};
|
|
21
|
+
const siteVerifyMap = {
|
|
22
|
+
[Providers.CLOUDFLARE_TURNSTILE]: "https://challenges.cloudflare.com/turnstile/v0/siteverify",
|
|
23
|
+
[Providers.GOOGLE_RECAPTCHA]: "https://www.google.com/recaptcha/api/siteverify",
|
|
24
|
+
[Providers.HCAPTCHA]: "https://api.hcaptcha.com/siteverify",
|
|
25
|
+
[Providers.CAPTCHAFOX]: "https://api.captchafox.com/siteverify"
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
//#endregion
|
|
29
|
+
//#region src/plugins/captcha/error-codes.ts
|
|
30
|
+
const EXTERNAL_ERROR_CODES = defineErrorCodes({
|
|
31
|
+
VERIFICATION_FAILED: "Captcha verification failed",
|
|
32
|
+
MISSING_RESPONSE: "Missing CAPTCHA response",
|
|
33
|
+
UNKNOWN_ERROR: "Something went wrong"
|
|
34
|
+
});
|
|
35
|
+
const INTERNAL_ERROR_CODES = defineErrorCodes({
|
|
36
|
+
MISSING_SECRET_KEY: "Missing secret key",
|
|
37
|
+
SERVICE_UNAVAILABLE: "CAPTCHA service unavailable"
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
//#endregion
|
|
41
|
+
//#region src/plugins/captcha/utils.ts
|
|
42
|
+
const encodeToURLParams = (obj) => {
|
|
43
|
+
if (typeof obj !== "object" || obj === null || Array.isArray(obj)) throw new Error("Input must be a non-null object.");
|
|
44
|
+
const params = new URLSearchParams();
|
|
45
|
+
for (const [key, value] of Object.entries(obj)) if (value !== void 0 && value !== null) params.append(key, String(value));
|
|
46
|
+
return params.toString();
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
//#endregion
|
|
50
|
+
//#region src/plugins/captcha/verify-handlers/captchafox.ts
|
|
51
|
+
const captchaFox = async ({ siteVerifyURL, captchaResponse, secretKey, siteKey, remoteIP }) => {
|
|
52
|
+
const response = await betterFetch(siteVerifyURL, {
|
|
53
|
+
method: "POST",
|
|
54
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
55
|
+
body: encodeToURLParams({
|
|
56
|
+
secret: secretKey,
|
|
57
|
+
response: captchaResponse,
|
|
58
|
+
...siteKey && { sitekey: siteKey },
|
|
59
|
+
...remoteIP && { remoteIp: remoteIP }
|
|
60
|
+
})
|
|
61
|
+
});
|
|
62
|
+
if (!response.data || response.error) throw new Error(INTERNAL_ERROR_CODES.SERVICE_UNAVAILABLE);
|
|
63
|
+
if (!response.data.success) return middlewareResponse({
|
|
64
|
+
message: EXTERNAL_ERROR_CODES.VERIFICATION_FAILED,
|
|
65
|
+
status: 403
|
|
66
|
+
});
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
//#endregion
|
|
70
|
+
//#region src/plugins/captcha/verify-handlers/cloudflare-turnstile.ts
|
|
71
|
+
const cloudflareTurnstile = async ({ siteVerifyURL, captchaResponse, secretKey, remoteIP }) => {
|
|
72
|
+
const response = await betterFetch(siteVerifyURL, {
|
|
73
|
+
method: "POST",
|
|
74
|
+
headers: { "Content-Type": "application/json" },
|
|
75
|
+
body: JSON.stringify({
|
|
76
|
+
secret: secretKey,
|
|
77
|
+
response: captchaResponse,
|
|
78
|
+
...remoteIP && { remoteip: remoteIP }
|
|
79
|
+
})
|
|
80
|
+
});
|
|
81
|
+
if (!response.data || response.error) throw new Error(INTERNAL_ERROR_CODES.SERVICE_UNAVAILABLE);
|
|
82
|
+
if (!response.data.success) return middlewareResponse({
|
|
83
|
+
message: EXTERNAL_ERROR_CODES.VERIFICATION_FAILED,
|
|
84
|
+
status: 403
|
|
85
|
+
});
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
//#endregion
|
|
89
|
+
//#region src/plugins/captcha/verify-handlers/google-recaptcha.ts
|
|
90
|
+
const isV3 = (response) => {
|
|
91
|
+
return "score" in response && typeof response.score === "number";
|
|
92
|
+
};
|
|
93
|
+
const googleRecaptcha = async ({ siteVerifyURL, captchaResponse, secretKey, minScore = .5, remoteIP }) => {
|
|
94
|
+
const response = await betterFetch(siteVerifyURL, {
|
|
95
|
+
method: "POST",
|
|
96
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
97
|
+
body: encodeToURLParams({
|
|
98
|
+
secret: secretKey,
|
|
99
|
+
response: captchaResponse,
|
|
100
|
+
...remoteIP && { remoteip: remoteIP }
|
|
101
|
+
})
|
|
102
|
+
});
|
|
103
|
+
if (!response.data || response.error) throw new Error(INTERNAL_ERROR_CODES.SERVICE_UNAVAILABLE);
|
|
104
|
+
if (!response.data.success || isV3(response.data) && response.data.score < minScore) return middlewareResponse({
|
|
105
|
+
message: EXTERNAL_ERROR_CODES.VERIFICATION_FAILED,
|
|
106
|
+
status: 403
|
|
107
|
+
});
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
//#endregion
|
|
111
|
+
//#region src/plugins/captcha/verify-handlers/h-captcha.ts
|
|
112
|
+
const hCaptcha = async ({ siteVerifyURL, captchaResponse, secretKey, siteKey, remoteIP }) => {
|
|
113
|
+
const response = await betterFetch(siteVerifyURL, {
|
|
114
|
+
method: "POST",
|
|
115
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
116
|
+
body: encodeToURLParams({
|
|
117
|
+
secret: secretKey,
|
|
118
|
+
response: captchaResponse,
|
|
119
|
+
...siteKey && { sitekey: siteKey },
|
|
120
|
+
...remoteIP && { remoteip: remoteIP }
|
|
121
|
+
})
|
|
122
|
+
});
|
|
123
|
+
if (!response.data || response.error) throw new Error(INTERNAL_ERROR_CODES.SERVICE_UNAVAILABLE);
|
|
124
|
+
if (!response.data.success) return middlewareResponse({
|
|
125
|
+
message: EXTERNAL_ERROR_CODES.VERIFICATION_FAILED,
|
|
126
|
+
status: 403
|
|
127
|
+
});
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
//#endregion
|
|
131
|
+
//#region src/plugins/captcha/index.ts
|
|
132
|
+
const captcha = (options) => ({
|
|
133
|
+
id: "captcha",
|
|
134
|
+
onRequest: async (request, ctx) => {
|
|
135
|
+
try {
|
|
136
|
+
if (!(options.endpoints?.length ? options.endpoints : defaultEndpoints).some((endpoint) => request.url.includes(endpoint))) return void 0;
|
|
137
|
+
if (!options.secretKey) throw new Error(INTERNAL_ERROR_CODES.MISSING_SECRET_KEY);
|
|
138
|
+
const captchaResponse = request.headers.get("x-captcha-response");
|
|
139
|
+
const remoteUserIP = getIp(request, ctx.options) ?? void 0;
|
|
140
|
+
if (!captchaResponse) return middlewareResponse({
|
|
141
|
+
message: EXTERNAL_ERROR_CODES.MISSING_RESPONSE,
|
|
142
|
+
status: 400
|
|
143
|
+
});
|
|
144
|
+
const handlerParams = {
|
|
145
|
+
siteVerifyURL: options.siteVerifyURLOverride || siteVerifyMap[options.provider],
|
|
146
|
+
captchaResponse,
|
|
147
|
+
secretKey: options.secretKey,
|
|
148
|
+
remoteIP: remoteUserIP
|
|
149
|
+
};
|
|
150
|
+
if (options.provider === Providers.CLOUDFLARE_TURNSTILE) return await cloudflareTurnstile(handlerParams);
|
|
151
|
+
if (options.provider === Providers.GOOGLE_RECAPTCHA) return await googleRecaptcha({
|
|
152
|
+
...handlerParams,
|
|
153
|
+
minScore: options.minScore
|
|
154
|
+
});
|
|
155
|
+
if (options.provider === Providers.HCAPTCHA) return await hCaptcha({
|
|
156
|
+
...handlerParams,
|
|
157
|
+
siteKey: options.siteKey
|
|
158
|
+
});
|
|
159
|
+
if (options.provider === Providers.CAPTCHAFOX) return await captchaFox({
|
|
160
|
+
...handlerParams,
|
|
161
|
+
siteKey: options.siteKey
|
|
162
|
+
});
|
|
163
|
+
} catch (_error) {
|
|
164
|
+
const errorMessage = _error instanceof Error ? _error.message : void 0;
|
|
165
|
+
ctx.logger.error(errorMessage ?? "Unknown error", {
|
|
166
|
+
endpoint: request.url,
|
|
167
|
+
message: _error
|
|
168
|
+
});
|
|
169
|
+
return middlewareResponse({
|
|
170
|
+
message: EXTERNAL_ERROR_CODES.UNKNOWN_ERROR,
|
|
171
|
+
status: 500
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
//#endregion
|
|
178
|
+
export { captcha as t };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
|
|
3
|
+
//#region rolldown:runtime
|
|
4
|
+
var __create = Object.create;
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
9
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __commonJS = (cb, mod) => function() {
|
|
11
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
12
|
+
};
|
|
13
|
+
var __export = (all) => {
|
|
14
|
+
let target = {};
|
|
15
|
+
for (var name in all) __defProp(target, name, {
|
|
16
|
+
get: all[name],
|
|
17
|
+
enumerable: true
|
|
18
|
+
});
|
|
19
|
+
return target;
|
|
20
|
+
};
|
|
21
|
+
var __copyProps = (to, from, except, desc) => {
|
|
22
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
23
|
+
key = keys[i];
|
|
24
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
25
|
+
get: ((k) => from[k]).bind(null, key),
|
|
26
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
return to;
|
|
30
|
+
};
|
|
31
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
32
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
33
|
+
value: mod,
|
|
34
|
+
enumerable: true
|
|
35
|
+
}) : target, mod));
|
|
36
|
+
var __toDynamicImportESM = (isNodeMode) => (mod) => __toESM(mod.default, isNodeMode);
|
|
37
|
+
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
38
|
+
|
|
39
|
+
//#endregion
|
|
40
|
+
export { __toDynamicImportESM as a, __require as i, __export as n, __toESM as o, __reExport as r, __commonJS as t };
|