@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,557 @@
|
|
|
1
|
+
import { r as generateRandomString } from "./crypto-Bb42eMrH.mjs";
|
|
2
|
+
import { m as ms } from "./cookies-cJObLwn1.mjs";
|
|
3
|
+
import { n as mergeSchema } from "./date-Cx2yCiC4.mjs";
|
|
4
|
+
import { r as getSessionFromCtx } from "./session-Dgp133Yt.mjs";
|
|
5
|
+
import { defineErrorCodes } from "@gatwech/core/utils";
|
|
6
|
+
import { APIError } from "better-call";
|
|
7
|
+
import { createAuthEndpoint } from "@gatwech/core/api";
|
|
8
|
+
import * as z$1 from "zod";
|
|
9
|
+
|
|
10
|
+
//#region src/plugins/device-authorization/schema.ts
|
|
11
|
+
const schema = { deviceCode: { fields: {
|
|
12
|
+
deviceCode: {
|
|
13
|
+
type: "string",
|
|
14
|
+
required: true
|
|
15
|
+
},
|
|
16
|
+
userCode: {
|
|
17
|
+
type: "string",
|
|
18
|
+
required: true
|
|
19
|
+
},
|
|
20
|
+
userId: {
|
|
21
|
+
type: "string",
|
|
22
|
+
required: false
|
|
23
|
+
},
|
|
24
|
+
expiresAt: {
|
|
25
|
+
type: "date",
|
|
26
|
+
required: true
|
|
27
|
+
},
|
|
28
|
+
status: {
|
|
29
|
+
type: "string",
|
|
30
|
+
required: true
|
|
31
|
+
},
|
|
32
|
+
lastPolledAt: {
|
|
33
|
+
type: "date",
|
|
34
|
+
required: false
|
|
35
|
+
},
|
|
36
|
+
pollingInterval: {
|
|
37
|
+
type: "number",
|
|
38
|
+
required: false
|
|
39
|
+
},
|
|
40
|
+
clientId: {
|
|
41
|
+
type: "string",
|
|
42
|
+
required: false
|
|
43
|
+
},
|
|
44
|
+
scope: {
|
|
45
|
+
type: "string",
|
|
46
|
+
required: false
|
|
47
|
+
}
|
|
48
|
+
} } };
|
|
49
|
+
const deviceCode = z$1.object({
|
|
50
|
+
id: z$1.string(),
|
|
51
|
+
deviceCode: z$1.string(),
|
|
52
|
+
userCode: z$1.string(),
|
|
53
|
+
userId: z$1.string().optional(),
|
|
54
|
+
expiresAt: z$1.date(),
|
|
55
|
+
status: z$1.string(),
|
|
56
|
+
lastPolledAt: z$1.date().optional(),
|
|
57
|
+
pollingInterval: z$1.number().optional(),
|
|
58
|
+
clientId: z$1.string().optional(),
|
|
59
|
+
scope: z$1.string().optional()
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
//#endregion
|
|
63
|
+
//#region src/plugins/device-authorization/index.ts
|
|
64
|
+
const msStringValueSchema = z$1.custom((val) => {
|
|
65
|
+
try {
|
|
66
|
+
ms(val);
|
|
67
|
+
} catch (e) {
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
return true;
|
|
71
|
+
}, { message: "Invalid time string format. Use formats like '30m', '5s', '1h', etc." });
|
|
72
|
+
const $deviceAuthorizationOptionsSchema = z$1.object({
|
|
73
|
+
expiresIn: msStringValueSchema.default("30m").describe("Time in seconds until the device code expires. Use formats like '30m', '5s', '1h', etc."),
|
|
74
|
+
interval: msStringValueSchema.default("5s").describe("Time in seconds between polling attempts. Use formats like '30m', '5s', '1h', etc."),
|
|
75
|
+
deviceCodeLength: z$1.number().int().positive().default(40).describe("Length of the device code to be generated. Default is 40 characters."),
|
|
76
|
+
userCodeLength: z$1.number().int().positive().default(8).describe("Length of the user code to be generated. Default is 8 characters."),
|
|
77
|
+
generateDeviceCode: z$1.custom((val) => typeof val === "function", { message: "generateDeviceCode must be a function that returns a string or a promise that resolves to a string." }).optional().describe("Function to generate a device code. If not provided, a default random string generator will be used."),
|
|
78
|
+
generateUserCode: z$1.custom((val) => typeof val === "function", { message: "generateUserCode must be a function that returns a string or a promise that resolves to a string." }).optional().describe("Function to generate a user code. If not provided, a default random string generator will be used."),
|
|
79
|
+
validateClient: z$1.custom((val) => typeof val === "function", { message: "validateClient must be a function that returns a boolean or a promise that resolves to a boolean." }).optional().describe("Function to validate the client ID. If not provided, no validation will be performed."),
|
|
80
|
+
onDeviceAuthRequest: z$1.custom((val) => typeof val === "function", { message: "onDeviceAuthRequest must be a function that returns void or a promise that resolves to void." }).optional().describe("Function to handle device authorization requests. If not provided, no additional actions will be taken."),
|
|
81
|
+
schema: z$1.custom(() => true)
|
|
82
|
+
});
|
|
83
|
+
const DEVICE_AUTHORIZATION_ERROR_CODES = defineErrorCodes({
|
|
84
|
+
INVALID_DEVICE_CODE: "Invalid device code",
|
|
85
|
+
EXPIRED_DEVICE_CODE: "Device code has expired",
|
|
86
|
+
EXPIRED_USER_CODE: "User code has expired",
|
|
87
|
+
AUTHORIZATION_PENDING: "Authorization pending",
|
|
88
|
+
ACCESS_DENIED: "Access denied",
|
|
89
|
+
INVALID_USER_CODE: "Invalid user code",
|
|
90
|
+
DEVICE_CODE_ALREADY_PROCESSED: "Device code already processed",
|
|
91
|
+
POLLING_TOO_FREQUENTLY: "Polling too frequently",
|
|
92
|
+
USER_NOT_FOUND: "User not found",
|
|
93
|
+
FAILED_TO_CREATE_SESSION: "Failed to create session",
|
|
94
|
+
INVALID_DEVICE_CODE_STATUS: "Invalid device code status",
|
|
95
|
+
AUTHENTICATION_REQUIRED: "Authentication required"
|
|
96
|
+
});
|
|
97
|
+
const defaultCharset = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789";
|
|
98
|
+
/**
|
|
99
|
+
* @internal
|
|
100
|
+
*/
|
|
101
|
+
const defaultGenerateDeviceCode = (length) => {
|
|
102
|
+
return generateRandomString(length, "a-z", "A-Z", "0-9");
|
|
103
|
+
};
|
|
104
|
+
/**
|
|
105
|
+
* @internal
|
|
106
|
+
*/
|
|
107
|
+
const defaultGenerateUserCode = (length) => {
|
|
108
|
+
const chars = new Uint8Array(length);
|
|
109
|
+
return Array.from(crypto.getRandomValues(chars)).map((byte) => defaultCharset[byte % 32]).join("");
|
|
110
|
+
};
|
|
111
|
+
const deviceAuthorization = (options = {}) => {
|
|
112
|
+
const opts = $deviceAuthorizationOptionsSchema.parse(options);
|
|
113
|
+
const generateDeviceCode = async () => {
|
|
114
|
+
if (opts.generateDeviceCode) return opts.generateDeviceCode();
|
|
115
|
+
return defaultGenerateDeviceCode(opts.deviceCodeLength);
|
|
116
|
+
};
|
|
117
|
+
const generateUserCode = async () => {
|
|
118
|
+
if (opts.generateUserCode) return opts.generateUserCode();
|
|
119
|
+
return defaultGenerateUserCode(opts.userCodeLength);
|
|
120
|
+
};
|
|
121
|
+
return {
|
|
122
|
+
id: "device-authorization",
|
|
123
|
+
schema: mergeSchema(schema, options?.schema),
|
|
124
|
+
endpoints: {
|
|
125
|
+
deviceCode: createAuthEndpoint("/device/code", {
|
|
126
|
+
method: "POST",
|
|
127
|
+
body: z$1.object({
|
|
128
|
+
client_id: z$1.string().meta({ description: "The client ID of the application" }),
|
|
129
|
+
scope: z$1.string().meta({ description: "Space-separated list of scopes" }).optional()
|
|
130
|
+
}),
|
|
131
|
+
error: z$1.object({
|
|
132
|
+
error: z$1.enum(["invalid_request", "invalid_client"]).meta({ description: "Error code" }),
|
|
133
|
+
error_description: z$1.string().meta({ description: "Detailed error description" })
|
|
134
|
+
}),
|
|
135
|
+
metadata: { openapi: {
|
|
136
|
+
description: `Request a device and user code
|
|
137
|
+
|
|
138
|
+
Follow [rfc8628#section-3.2](https://datatracker.ietf.org/doc/html/rfc8628#section-3.2)`,
|
|
139
|
+
responses: {
|
|
140
|
+
200: {
|
|
141
|
+
description: "Success",
|
|
142
|
+
content: { "application/json": { schema: {
|
|
143
|
+
type: "object",
|
|
144
|
+
properties: {
|
|
145
|
+
device_code: {
|
|
146
|
+
type: "string",
|
|
147
|
+
description: "The device verification code"
|
|
148
|
+
},
|
|
149
|
+
user_code: {
|
|
150
|
+
type: "string",
|
|
151
|
+
description: "The user code to display"
|
|
152
|
+
},
|
|
153
|
+
verification_uri: {
|
|
154
|
+
type: "string",
|
|
155
|
+
description: "The URL for user verification"
|
|
156
|
+
},
|
|
157
|
+
verification_uri_complete: {
|
|
158
|
+
type: "string",
|
|
159
|
+
description: "The complete URL with user code"
|
|
160
|
+
},
|
|
161
|
+
expires_in: {
|
|
162
|
+
type: "number",
|
|
163
|
+
description: "Lifetime in seconds of the device code"
|
|
164
|
+
},
|
|
165
|
+
interval: {
|
|
166
|
+
type: "number",
|
|
167
|
+
description: "Minimum polling interval in seconds"
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
} } }
|
|
171
|
+
},
|
|
172
|
+
400: {
|
|
173
|
+
description: "Error response",
|
|
174
|
+
content: { "application/json": { schema: {
|
|
175
|
+
type: "object",
|
|
176
|
+
properties: {
|
|
177
|
+
error: {
|
|
178
|
+
type: "string",
|
|
179
|
+
enum: ["invalid_request", "invalid_client"]
|
|
180
|
+
},
|
|
181
|
+
error_description: { type: "string" }
|
|
182
|
+
}
|
|
183
|
+
} } }
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
} }
|
|
187
|
+
}, async (ctx) => {
|
|
188
|
+
if (opts.validateClient) {
|
|
189
|
+
if (!await opts.validateClient(ctx.body.client_id)) throw new APIError("BAD_REQUEST", {
|
|
190
|
+
error: "invalid_client",
|
|
191
|
+
error_description: "Invalid client ID"
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
if (opts.onDeviceAuthRequest) await opts.onDeviceAuthRequest(ctx.body.client_id, ctx.body.scope);
|
|
195
|
+
const deviceCode$1 = await generateDeviceCode();
|
|
196
|
+
const userCode = await generateUserCode();
|
|
197
|
+
const expiresIn = ms(opts.expiresIn);
|
|
198
|
+
const expiresAt = new Date(Date.now() + expiresIn);
|
|
199
|
+
await ctx.context.adapter.create({
|
|
200
|
+
model: "deviceCode",
|
|
201
|
+
data: {
|
|
202
|
+
deviceCode: deviceCode$1,
|
|
203
|
+
userCode,
|
|
204
|
+
expiresAt,
|
|
205
|
+
status: "pending",
|
|
206
|
+
pollingInterval: ms(opts.interval),
|
|
207
|
+
clientId: ctx.body.client_id,
|
|
208
|
+
scope: ctx.body.scope
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
const baseURL = new URL(ctx.context.baseURL);
|
|
212
|
+
const verification_uri = new URL("/device", baseURL);
|
|
213
|
+
const verification_uri_complete = new URL(verification_uri);
|
|
214
|
+
verification_uri_complete.searchParams.set("user_code", encodeURIComponent(userCode));
|
|
215
|
+
return ctx.json({
|
|
216
|
+
device_code: deviceCode$1,
|
|
217
|
+
user_code: userCode,
|
|
218
|
+
verification_uri: verification_uri.toString(),
|
|
219
|
+
verification_uri_complete: verification_uri_complete.toString(),
|
|
220
|
+
expires_in: Math.floor(expiresIn / 1e3),
|
|
221
|
+
interval: Math.floor(ms(opts.interval) / 1e3)
|
|
222
|
+
}, { headers: { "Cache-Control": "no-store" } });
|
|
223
|
+
}),
|
|
224
|
+
deviceToken: createAuthEndpoint("/device/token", {
|
|
225
|
+
method: "POST",
|
|
226
|
+
body: z$1.object({
|
|
227
|
+
grant_type: z$1.literal("urn:ietf:params:oauth:grant-type:device_code").meta({ description: "The grant type for device flow" }),
|
|
228
|
+
device_code: z$1.string().meta({ description: "The device verification code" }),
|
|
229
|
+
client_id: z$1.string().meta({ description: "The client ID of the application" })
|
|
230
|
+
}),
|
|
231
|
+
error: z$1.object({
|
|
232
|
+
error: z$1.enum([
|
|
233
|
+
"authorization_pending",
|
|
234
|
+
"slow_down",
|
|
235
|
+
"expired_token",
|
|
236
|
+
"access_denied",
|
|
237
|
+
"invalid_request",
|
|
238
|
+
"invalid_grant"
|
|
239
|
+
]).meta({ description: "Error code" }),
|
|
240
|
+
error_description: z$1.string().meta({ description: "Detailed error description" })
|
|
241
|
+
}),
|
|
242
|
+
metadata: { openapi: {
|
|
243
|
+
description: `Exchange device code for access token
|
|
244
|
+
|
|
245
|
+
Follow [rfc8628#section-3.4](https://datatracker.ietf.org/doc/html/rfc8628#section-3.4)`,
|
|
246
|
+
responses: {
|
|
247
|
+
200: {
|
|
248
|
+
description: "Success",
|
|
249
|
+
content: { "application/json": { schema: {
|
|
250
|
+
type: "object",
|
|
251
|
+
properties: {
|
|
252
|
+
session: { $ref: "#/components/schemas/Session" },
|
|
253
|
+
user: { $ref: "#/components/schemas/User" }
|
|
254
|
+
}
|
|
255
|
+
} } }
|
|
256
|
+
},
|
|
257
|
+
400: {
|
|
258
|
+
description: "Error response",
|
|
259
|
+
content: { "application/json": { schema: {
|
|
260
|
+
type: "object",
|
|
261
|
+
properties: {
|
|
262
|
+
error: {
|
|
263
|
+
type: "string",
|
|
264
|
+
enum: [
|
|
265
|
+
"authorization_pending",
|
|
266
|
+
"slow_down",
|
|
267
|
+
"expired_token",
|
|
268
|
+
"access_denied",
|
|
269
|
+
"invalid_request",
|
|
270
|
+
"invalid_grant"
|
|
271
|
+
]
|
|
272
|
+
},
|
|
273
|
+
error_description: { type: "string" }
|
|
274
|
+
}
|
|
275
|
+
} } }
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
} }
|
|
279
|
+
}, async (ctx) => {
|
|
280
|
+
const { device_code, client_id } = ctx.body;
|
|
281
|
+
if (opts.validateClient) {
|
|
282
|
+
if (!await opts.validateClient(client_id)) throw new APIError("BAD_REQUEST", {
|
|
283
|
+
error: "invalid_grant",
|
|
284
|
+
error_description: "Invalid client ID"
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
const deviceCodeRecord = await ctx.context.adapter.findOne({
|
|
288
|
+
model: "deviceCode",
|
|
289
|
+
where: [{
|
|
290
|
+
field: "deviceCode",
|
|
291
|
+
value: device_code
|
|
292
|
+
}]
|
|
293
|
+
});
|
|
294
|
+
if (!deviceCodeRecord) throw new APIError("BAD_REQUEST", {
|
|
295
|
+
error: "invalid_grant",
|
|
296
|
+
error_description: DEVICE_AUTHORIZATION_ERROR_CODES.INVALID_DEVICE_CODE
|
|
297
|
+
});
|
|
298
|
+
if (deviceCodeRecord.clientId && deviceCodeRecord.clientId !== client_id) throw new APIError("BAD_REQUEST", {
|
|
299
|
+
error: "invalid_grant",
|
|
300
|
+
error_description: "Client ID mismatch"
|
|
301
|
+
});
|
|
302
|
+
if (deviceCodeRecord.lastPolledAt && deviceCodeRecord.pollingInterval) {
|
|
303
|
+
if (Date.now() - new Date(deviceCodeRecord.lastPolledAt).getTime() < deviceCodeRecord.pollingInterval) throw new APIError("BAD_REQUEST", {
|
|
304
|
+
error: "slow_down",
|
|
305
|
+
error_description: DEVICE_AUTHORIZATION_ERROR_CODES.POLLING_TOO_FREQUENTLY
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
await ctx.context.adapter.update({
|
|
309
|
+
model: "deviceCode",
|
|
310
|
+
where: [{
|
|
311
|
+
field: "id",
|
|
312
|
+
value: deviceCodeRecord.id
|
|
313
|
+
}],
|
|
314
|
+
update: { lastPolledAt: /* @__PURE__ */ new Date() }
|
|
315
|
+
});
|
|
316
|
+
if (deviceCodeRecord.expiresAt < /* @__PURE__ */ new Date()) {
|
|
317
|
+
await ctx.context.adapter.delete({
|
|
318
|
+
model: "deviceCode",
|
|
319
|
+
where: [{
|
|
320
|
+
field: "id",
|
|
321
|
+
value: deviceCodeRecord.id
|
|
322
|
+
}]
|
|
323
|
+
});
|
|
324
|
+
throw new APIError("BAD_REQUEST", {
|
|
325
|
+
error: "expired_token",
|
|
326
|
+
error_description: DEVICE_AUTHORIZATION_ERROR_CODES.EXPIRED_DEVICE_CODE
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
if (deviceCodeRecord.status === "pending") throw new APIError("BAD_REQUEST", {
|
|
330
|
+
error: "authorization_pending",
|
|
331
|
+
error_description: DEVICE_AUTHORIZATION_ERROR_CODES.AUTHORIZATION_PENDING
|
|
332
|
+
});
|
|
333
|
+
if (deviceCodeRecord.status === "denied") {
|
|
334
|
+
await ctx.context.adapter.delete({
|
|
335
|
+
model: "deviceCode",
|
|
336
|
+
where: [{
|
|
337
|
+
field: "id",
|
|
338
|
+
value: deviceCodeRecord.id
|
|
339
|
+
}]
|
|
340
|
+
});
|
|
341
|
+
throw new APIError("BAD_REQUEST", {
|
|
342
|
+
error: "access_denied",
|
|
343
|
+
error_description: DEVICE_AUTHORIZATION_ERROR_CODES.ACCESS_DENIED
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
if (deviceCodeRecord.status === "approved" && deviceCodeRecord.userId) {
|
|
347
|
+
await ctx.context.adapter.delete({
|
|
348
|
+
model: "deviceCode",
|
|
349
|
+
where: [{
|
|
350
|
+
field: "id",
|
|
351
|
+
value: deviceCodeRecord.id
|
|
352
|
+
}]
|
|
353
|
+
});
|
|
354
|
+
const user = await ctx.context.internalAdapter.findUserById(deviceCodeRecord.userId);
|
|
355
|
+
if (!user) throw new APIError("INTERNAL_SERVER_ERROR", {
|
|
356
|
+
error: "server_error",
|
|
357
|
+
error_description: DEVICE_AUTHORIZATION_ERROR_CODES.USER_NOT_FOUND
|
|
358
|
+
});
|
|
359
|
+
const session = await ctx.context.internalAdapter.createSession(user.id);
|
|
360
|
+
if (!session) throw new APIError("INTERNAL_SERVER_ERROR", {
|
|
361
|
+
error: "server_error",
|
|
362
|
+
error_description: DEVICE_AUTHORIZATION_ERROR_CODES.FAILED_TO_CREATE_SESSION
|
|
363
|
+
});
|
|
364
|
+
ctx.context.setNewSession({
|
|
365
|
+
session,
|
|
366
|
+
user
|
|
367
|
+
});
|
|
368
|
+
if (ctx.context.options.secondaryStorage) await ctx.context.secondaryStorage?.set(session.token, JSON.stringify({
|
|
369
|
+
user,
|
|
370
|
+
session
|
|
371
|
+
}), Math.floor((new Date(session.expiresAt).getTime() - Date.now()) / 1e3));
|
|
372
|
+
return ctx.json({
|
|
373
|
+
access_token: session.token,
|
|
374
|
+
token_type: "Bearer",
|
|
375
|
+
expires_in: Math.floor((new Date(session.expiresAt).getTime() - Date.now()) / 1e3),
|
|
376
|
+
scope: deviceCodeRecord.scope || ""
|
|
377
|
+
}, { headers: {
|
|
378
|
+
"Cache-Control": "no-store",
|
|
379
|
+
Pragma: "no-cache"
|
|
380
|
+
} });
|
|
381
|
+
}
|
|
382
|
+
throw new APIError("INTERNAL_SERVER_ERROR", {
|
|
383
|
+
error: "server_error",
|
|
384
|
+
error_description: DEVICE_AUTHORIZATION_ERROR_CODES.INVALID_DEVICE_CODE_STATUS
|
|
385
|
+
});
|
|
386
|
+
}),
|
|
387
|
+
deviceVerify: createAuthEndpoint("/device", {
|
|
388
|
+
method: "GET",
|
|
389
|
+
query: z$1.object({ user_code: z$1.string().meta({ description: "The user code to verify" }) }),
|
|
390
|
+
error: z$1.object({
|
|
391
|
+
error: z$1.enum(["invalid_request"]).meta({ description: "Error code" }),
|
|
392
|
+
error_description: z$1.string().meta({ description: "Detailed error description" })
|
|
393
|
+
}),
|
|
394
|
+
metadata: { openapi: {
|
|
395
|
+
description: "Display device verification page",
|
|
396
|
+
responses: { 200: {
|
|
397
|
+
description: "Verification page HTML",
|
|
398
|
+
content: { "application/json": { schema: {
|
|
399
|
+
type: "object",
|
|
400
|
+
properties: {
|
|
401
|
+
user_code: {
|
|
402
|
+
type: "string",
|
|
403
|
+
description: "The user code to verify"
|
|
404
|
+
},
|
|
405
|
+
status: {
|
|
406
|
+
type: "string",
|
|
407
|
+
enum: [
|
|
408
|
+
"pending",
|
|
409
|
+
"approved",
|
|
410
|
+
"denied"
|
|
411
|
+
],
|
|
412
|
+
description: "Current status of the device authorization"
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
} } }
|
|
416
|
+
} }
|
|
417
|
+
} }
|
|
418
|
+
}, async (ctx) => {
|
|
419
|
+
const { user_code } = ctx.query;
|
|
420
|
+
const cleanUserCode = user_code.replace(/-/g, "");
|
|
421
|
+
const deviceCodeRecord = await ctx.context.adapter.findOne({
|
|
422
|
+
model: "deviceCode",
|
|
423
|
+
where: [{
|
|
424
|
+
field: "userCode",
|
|
425
|
+
value: cleanUserCode
|
|
426
|
+
}]
|
|
427
|
+
});
|
|
428
|
+
if (!deviceCodeRecord) throw new APIError("BAD_REQUEST", {
|
|
429
|
+
error: "invalid_request",
|
|
430
|
+
error_description: DEVICE_AUTHORIZATION_ERROR_CODES.INVALID_USER_CODE
|
|
431
|
+
});
|
|
432
|
+
if (deviceCodeRecord.expiresAt < /* @__PURE__ */ new Date()) throw new APIError("BAD_REQUEST", {
|
|
433
|
+
error: "expired_token",
|
|
434
|
+
error_description: DEVICE_AUTHORIZATION_ERROR_CODES.EXPIRED_USER_CODE
|
|
435
|
+
});
|
|
436
|
+
return ctx.json({
|
|
437
|
+
user_code,
|
|
438
|
+
status: deviceCodeRecord.status
|
|
439
|
+
});
|
|
440
|
+
}),
|
|
441
|
+
deviceApprove: createAuthEndpoint("/device/approve", {
|
|
442
|
+
method: "POST",
|
|
443
|
+
body: z$1.object({ userCode: z$1.string().meta({ description: "The user code to approve" }) }),
|
|
444
|
+
error: z$1.object({
|
|
445
|
+
error: z$1.enum([
|
|
446
|
+
"invalid_request",
|
|
447
|
+
"expired_token",
|
|
448
|
+
"device_code_already_processed"
|
|
449
|
+
]).meta({ description: "Error code" }),
|
|
450
|
+
error_description: z$1.string().meta({ description: "Detailed error description" })
|
|
451
|
+
}),
|
|
452
|
+
requireHeaders: true,
|
|
453
|
+
metadata: { openapi: {
|
|
454
|
+
description: "Approve device authorization",
|
|
455
|
+
responses: { 200: {
|
|
456
|
+
description: "Success",
|
|
457
|
+
content: { "application/json": { schema: {
|
|
458
|
+
type: "object",
|
|
459
|
+
properties: { success: { type: "boolean" } }
|
|
460
|
+
} } }
|
|
461
|
+
} }
|
|
462
|
+
} }
|
|
463
|
+
}, async (ctx) => {
|
|
464
|
+
const session = await getSessionFromCtx(ctx);
|
|
465
|
+
if (!session) throw new APIError("UNAUTHORIZED", {
|
|
466
|
+
error: "unauthorized",
|
|
467
|
+
error_description: DEVICE_AUTHORIZATION_ERROR_CODES.AUTHENTICATION_REQUIRED
|
|
468
|
+
});
|
|
469
|
+
const { userCode } = ctx.body;
|
|
470
|
+
const deviceCodeRecord = await ctx.context.adapter.findOne({
|
|
471
|
+
model: "deviceCode",
|
|
472
|
+
where: [{
|
|
473
|
+
field: "userCode",
|
|
474
|
+
value: userCode
|
|
475
|
+
}]
|
|
476
|
+
});
|
|
477
|
+
if (!deviceCodeRecord) throw new APIError("BAD_REQUEST", {
|
|
478
|
+
error: "invalid_request",
|
|
479
|
+
error_description: DEVICE_AUTHORIZATION_ERROR_CODES.INVALID_USER_CODE
|
|
480
|
+
});
|
|
481
|
+
if (deviceCodeRecord.expiresAt < /* @__PURE__ */ new Date()) throw new APIError("BAD_REQUEST", {
|
|
482
|
+
error: "expired_token",
|
|
483
|
+
error_description: DEVICE_AUTHORIZATION_ERROR_CODES.EXPIRED_USER_CODE
|
|
484
|
+
});
|
|
485
|
+
if (deviceCodeRecord.status !== "pending") throw new APIError("BAD_REQUEST", {
|
|
486
|
+
error: "invalid_request",
|
|
487
|
+
error_description: DEVICE_AUTHORIZATION_ERROR_CODES.DEVICE_CODE_ALREADY_PROCESSED
|
|
488
|
+
});
|
|
489
|
+
await ctx.context.adapter.update({
|
|
490
|
+
model: "deviceCode",
|
|
491
|
+
where: [{
|
|
492
|
+
field: "id",
|
|
493
|
+
value: deviceCodeRecord.id
|
|
494
|
+
}],
|
|
495
|
+
update: {
|
|
496
|
+
status: "approved",
|
|
497
|
+
userId: session.user.id
|
|
498
|
+
}
|
|
499
|
+
});
|
|
500
|
+
return ctx.json({ success: true });
|
|
501
|
+
}),
|
|
502
|
+
deviceDeny: createAuthEndpoint("/device/deny", {
|
|
503
|
+
method: "POST",
|
|
504
|
+
body: z$1.object({ userCode: z$1.string().meta({ description: "The user code to deny" }) }),
|
|
505
|
+
error: z$1.object({
|
|
506
|
+
error: z$1.enum(["invalid_request", "expired_token"]).meta({ description: "Error code" }),
|
|
507
|
+
error_description: z$1.string().meta({ description: "Detailed error description" })
|
|
508
|
+
}),
|
|
509
|
+
metadata: { openapi: {
|
|
510
|
+
description: "Deny device authorization",
|
|
511
|
+
responses: { 200: {
|
|
512
|
+
description: "Success",
|
|
513
|
+
content: { "application/json": { schema: {
|
|
514
|
+
type: "object",
|
|
515
|
+
properties: { success: { type: "boolean" } }
|
|
516
|
+
} } }
|
|
517
|
+
} }
|
|
518
|
+
} }
|
|
519
|
+
}, async (ctx) => {
|
|
520
|
+
const { userCode } = ctx.body;
|
|
521
|
+
const cleanUserCode = userCode.replace(/-/g, "");
|
|
522
|
+
const deviceCodeRecord = await ctx.context.adapter.findOne({
|
|
523
|
+
model: "deviceCode",
|
|
524
|
+
where: [{
|
|
525
|
+
field: "userCode",
|
|
526
|
+
value: cleanUserCode
|
|
527
|
+
}]
|
|
528
|
+
});
|
|
529
|
+
if (!deviceCodeRecord) throw new APIError("BAD_REQUEST", {
|
|
530
|
+
error: "invalid_request",
|
|
531
|
+
error_description: DEVICE_AUTHORIZATION_ERROR_CODES.INVALID_USER_CODE
|
|
532
|
+
});
|
|
533
|
+
if (deviceCodeRecord.expiresAt < /* @__PURE__ */ new Date()) throw new APIError("BAD_REQUEST", {
|
|
534
|
+
error: "expired_token",
|
|
535
|
+
error_description: DEVICE_AUTHORIZATION_ERROR_CODES.EXPIRED_USER_CODE
|
|
536
|
+
});
|
|
537
|
+
if (deviceCodeRecord.status !== "pending") throw new APIError("BAD_REQUEST", {
|
|
538
|
+
error: "invalid_request",
|
|
539
|
+
error_description: DEVICE_AUTHORIZATION_ERROR_CODES.DEVICE_CODE_ALREADY_PROCESSED
|
|
540
|
+
});
|
|
541
|
+
await ctx.context.adapter.update({
|
|
542
|
+
model: "deviceCode",
|
|
543
|
+
where: [{
|
|
544
|
+
field: "id",
|
|
545
|
+
value: deviceCodeRecord.id
|
|
546
|
+
}],
|
|
547
|
+
update: { status: "denied" }
|
|
548
|
+
});
|
|
549
|
+
return ctx.json({ success: true });
|
|
550
|
+
})
|
|
551
|
+
},
|
|
552
|
+
$ERROR_CODES: DEVICE_AUTHORIZATION_ERROR_CODES
|
|
553
|
+
};
|
|
554
|
+
};
|
|
555
|
+
|
|
556
|
+
//#endregion
|
|
557
|
+
export { deviceAuthorization as n, $deviceAuthorizationOptionsSchema as t };
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { Kysely, MssqlDialect, MysqlDialect, PostgresDialect, SqliteDialect } from "kysely";
|
|
2
|
+
|
|
3
|
+
//#region src/adapters/kysely-adapter/dialect.ts
|
|
4
|
+
function getKyselyDatabaseType(db) {
|
|
5
|
+
if (!db) return null;
|
|
6
|
+
if ("dialect" in db) return getKyselyDatabaseType(db.dialect);
|
|
7
|
+
if ("createDriver" in db) {
|
|
8
|
+
if (db instanceof SqliteDialect) return "sqlite";
|
|
9
|
+
if (db instanceof MysqlDialect) return "mysql";
|
|
10
|
+
if (db instanceof PostgresDialect) return "postgres";
|
|
11
|
+
if (db instanceof MssqlDialect) return "mssql";
|
|
12
|
+
}
|
|
13
|
+
if ("aggregate" in db) return "sqlite";
|
|
14
|
+
if ("getConnection" in db) return "mysql";
|
|
15
|
+
if ("connect" in db) return "postgres";
|
|
16
|
+
if ("fileControl" in db) return "sqlite";
|
|
17
|
+
if ("open" in db && "close" in db && "prepare" in db) return "sqlite";
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
const createKyselyAdapter = async (config) => {
|
|
21
|
+
const db = config.database;
|
|
22
|
+
if (!db) return {
|
|
23
|
+
kysely: null,
|
|
24
|
+
databaseType: null,
|
|
25
|
+
transaction: void 0
|
|
26
|
+
};
|
|
27
|
+
if ("db" in db) return {
|
|
28
|
+
kysely: db.db,
|
|
29
|
+
databaseType: db.type,
|
|
30
|
+
transaction: db.transaction
|
|
31
|
+
};
|
|
32
|
+
if ("dialect" in db) return {
|
|
33
|
+
kysely: new Kysely({ dialect: db.dialect }),
|
|
34
|
+
databaseType: db.type,
|
|
35
|
+
transaction: db.transaction
|
|
36
|
+
};
|
|
37
|
+
let dialect = void 0;
|
|
38
|
+
const databaseType = getKyselyDatabaseType(db);
|
|
39
|
+
if ("createDriver" in db) dialect = db;
|
|
40
|
+
if ("aggregate" in db && !("createSession" in db)) dialect = new SqliteDialect({ database: db });
|
|
41
|
+
if ("getConnection" in db) dialect = new MysqlDialect(db);
|
|
42
|
+
if ("connect" in db) dialect = new PostgresDialect({ pool: db });
|
|
43
|
+
if ("fileControl" in db) {
|
|
44
|
+
const { BunSqliteDialect } = await import("./bun-sqlite-dialect-CeNvMaZz.mjs");
|
|
45
|
+
dialect = new BunSqliteDialect({ database: db });
|
|
46
|
+
}
|
|
47
|
+
if ("createSession" in db && typeof window === "undefined") {
|
|
48
|
+
let DatabaseSync = void 0;
|
|
49
|
+
try {
|
|
50
|
+
let nodeSqlite = "node:sqlite";
|
|
51
|
+
({DatabaseSync} = await import(
|
|
52
|
+
/* @vite-ignore */
|
|
53
|
+
/* webpackIgnore: true */
|
|
54
|
+
nodeSqlite
|
|
55
|
+
));
|
|
56
|
+
} catch (error) {
|
|
57
|
+
if (error !== null && typeof error === "object" && "code" in error && error.code !== "ERR_UNKNOWN_BUILTIN_MODULE") throw error;
|
|
58
|
+
}
|
|
59
|
+
if (DatabaseSync && db instanceof DatabaseSync) {
|
|
60
|
+
const { NodeSqliteDialect } = await import("./node-sqlite-dialect-BcKxBQnm.mjs");
|
|
61
|
+
dialect = new NodeSqliteDialect({ database: db });
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return {
|
|
65
|
+
kysely: dialect ? new Kysely({ dialect }) : null,
|
|
66
|
+
databaseType,
|
|
67
|
+
transaction: void 0
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
//#endregion
|
|
72
|
+
export { getKyselyDatabaseType as n, createKyselyAdapter as t };
|