@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,640 @@
|
|
|
1
|
+
import { t as generateId } from "./utils-SOMB4Px5.mjs";
|
|
2
|
+
import { t as safeJSONParse } from "./json-D0TBLy4q.mjs";
|
|
3
|
+
import { t as getAuthTables } from "./get-tables-BQP7YW9c.mjs";
|
|
4
|
+
import { TTY_COLORS, getColorDepth, logger } from "@gatwech/core/env";
|
|
5
|
+
import { PayvoAuthError } from "@gatwech/core/error";
|
|
6
|
+
|
|
7
|
+
//#region src/adapters/utils.ts
|
|
8
|
+
function withApplyDefault(value, field, action) {
|
|
9
|
+
if (action === "update") {
|
|
10
|
+
if (value === void 0 && field.onUpdate !== void 0) {
|
|
11
|
+
if (typeof field.onUpdate === "function") return field.onUpdate();
|
|
12
|
+
return field.onUpdate;
|
|
13
|
+
}
|
|
14
|
+
return value;
|
|
15
|
+
}
|
|
16
|
+
if (action === "create") {
|
|
17
|
+
if (value === void 0 || field.required === true && value === null) {
|
|
18
|
+
if (field.defaultValue !== void 0) {
|
|
19
|
+
if (typeof field.defaultValue === "function") return field.defaultValue();
|
|
20
|
+
return field.defaultValue;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return value;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
//#endregion
|
|
28
|
+
//#region src/adapters/adapter-factory/index.ts
|
|
29
|
+
let debugLogs = [];
|
|
30
|
+
let transactionId = -1;
|
|
31
|
+
const createAsIsTransaction = (adapter) => (fn) => fn(adapter);
|
|
32
|
+
const createAdapterFactory = ({ adapter: customAdapter, config: cfg }) => (options) => {
|
|
33
|
+
const uniqueAdapterFactoryInstanceId = Math.random().toString(36).substring(2, 15);
|
|
34
|
+
const config = {
|
|
35
|
+
...cfg,
|
|
36
|
+
supportsBooleans: cfg.supportsBooleans ?? true,
|
|
37
|
+
supportsDates: cfg.supportsDates ?? true,
|
|
38
|
+
supportsJSON: cfg.supportsJSON ?? false,
|
|
39
|
+
adapterName: cfg.adapterName ?? cfg.adapterId,
|
|
40
|
+
supportsNumericIds: cfg.supportsNumericIds ?? true,
|
|
41
|
+
transaction: cfg.transaction ?? false,
|
|
42
|
+
disableTransformInput: cfg.disableTransformInput ?? false,
|
|
43
|
+
disableTransformOutput: cfg.disableTransformOutput ?? false
|
|
44
|
+
};
|
|
45
|
+
if ((options.advanced?.database?.useNumberId === true || options.advanced?.database?.generateId === "serial") && config.supportsNumericIds === false) throw new PayvoAuthError(`[${config.adapterName}] Your database or database adapter does not support numeric ids. Please disable "useNumberId" in your config.`);
|
|
46
|
+
const schema = getAuthTables(options);
|
|
47
|
+
/**
|
|
48
|
+
* This function helps us get the default field name from the schema defined by devs.
|
|
49
|
+
* Often times, the user will be using the `fieldName` which could had been customized by the users.
|
|
50
|
+
* This function helps us get the actual field name useful to match against the schema. (eg: schema[model].fields[field])
|
|
51
|
+
*
|
|
52
|
+
* If it's still unclear what this does:
|
|
53
|
+
*
|
|
54
|
+
* 1. User can define a custom fieldName.
|
|
55
|
+
* 2. When using a custom fieldName, doing something like `schema[model].fields[field]` will not work.
|
|
56
|
+
*/
|
|
57
|
+
const getDefaultFieldName = ({ field, model: unsafe_model }) => {
|
|
58
|
+
if (field === "id" || field === "_id") return "id";
|
|
59
|
+
const model = getDefaultModelName(unsafe_model);
|
|
60
|
+
let f = schema[model]?.fields[field];
|
|
61
|
+
if (!f) {
|
|
62
|
+
const result = Object.entries(schema[model].fields).find(([_, f$1]) => f$1.fieldName === field);
|
|
63
|
+
if (result) {
|
|
64
|
+
f = result[1];
|
|
65
|
+
field = result[0];
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
if (!f) {
|
|
69
|
+
debugLog(`Field ${field} not found in model ${model}`);
|
|
70
|
+
debugLog(`Schema:`, schema);
|
|
71
|
+
throw new PayvoAuthError(`Field ${field} not found in model ${model}`);
|
|
72
|
+
}
|
|
73
|
+
return field;
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* This function helps us get the default model name from the schema defined by devs.
|
|
77
|
+
* Often times, the user will be using the `modelName` which could had been customized by the users.
|
|
78
|
+
* This function helps us get the actual model name useful to match against the schema. (eg: schema[model])
|
|
79
|
+
*
|
|
80
|
+
* If it's still unclear what this does:
|
|
81
|
+
*
|
|
82
|
+
* 1. User can define a custom modelName.
|
|
83
|
+
* 2. When using a custom modelName, doing something like `schema[model]` will not work.
|
|
84
|
+
* 3. Using this function helps us get the actual model name based on the user's defined custom modelName.
|
|
85
|
+
*/
|
|
86
|
+
const getDefaultModelName = (model) => {
|
|
87
|
+
if (config.usePlural && model.charAt(model.length - 1) === "s") {
|
|
88
|
+
let pluralessModel = model.slice(0, -1);
|
|
89
|
+
let m$1 = schema[pluralessModel] ? pluralessModel : void 0;
|
|
90
|
+
if (!m$1) m$1 = Object.entries(schema).find(([_, f]) => f.modelName === pluralessModel)?.[0];
|
|
91
|
+
if (m$1) return m$1;
|
|
92
|
+
}
|
|
93
|
+
let m = schema[model] ? model : void 0;
|
|
94
|
+
if (!m) m = Object.entries(schema).find(([_, f]) => f.modelName === model)?.[0];
|
|
95
|
+
if (!m) {
|
|
96
|
+
debugLog(`Model "${model}" not found in schema`);
|
|
97
|
+
debugLog(`Schema:`, schema);
|
|
98
|
+
throw new PayvoAuthError(`Model "${model}" not found in schema`);
|
|
99
|
+
}
|
|
100
|
+
return m;
|
|
101
|
+
};
|
|
102
|
+
/**
|
|
103
|
+
* Users can overwrite the default model of some tables. This function helps find the correct model name.
|
|
104
|
+
* Furthermore, if the user passes `usePlural` as true in their adapter config,
|
|
105
|
+
* then we should return the model name ending with an `s`.
|
|
106
|
+
*/
|
|
107
|
+
const getModelName = (model) => {
|
|
108
|
+
const defaultModelKey = getDefaultModelName(model);
|
|
109
|
+
const usePlural = config && config.usePlural;
|
|
110
|
+
if (schema && schema[defaultModelKey] && schema[defaultModelKey].modelName !== model) return usePlural ? `${schema[defaultModelKey].modelName}s` : schema[defaultModelKey].modelName;
|
|
111
|
+
return usePlural ? `${model}s` : model;
|
|
112
|
+
};
|
|
113
|
+
/**
|
|
114
|
+
* Get the field name which is expected to be saved in the database based on the user's schema.
|
|
115
|
+
*
|
|
116
|
+
* This function is useful if you need to save the field name to the database.
|
|
117
|
+
*
|
|
118
|
+
* For example, if the user has defined a custom field name for the `user` model, then you can use this function to get the actual field name from the schema.
|
|
119
|
+
*/
|
|
120
|
+
function getFieldName({ model: model_name, field: field_name }) {
|
|
121
|
+
const model = getDefaultModelName(model_name);
|
|
122
|
+
const field = getDefaultFieldName({
|
|
123
|
+
model,
|
|
124
|
+
field: field_name
|
|
125
|
+
});
|
|
126
|
+
return schema[model]?.fields[field]?.fieldName || field;
|
|
127
|
+
}
|
|
128
|
+
const debugLog = (...args) => {
|
|
129
|
+
if (config.debugLogs === true || typeof config.debugLogs === "object") {
|
|
130
|
+
if (typeof config.debugLogs === "object" && "isRunningAdapterTests" in config.debugLogs) {
|
|
131
|
+
if (config.debugLogs.isRunningAdapterTests) {
|
|
132
|
+
args.shift();
|
|
133
|
+
debugLogs.push({
|
|
134
|
+
instance: uniqueAdapterFactoryInstanceId,
|
|
135
|
+
args
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
if (typeof config.debugLogs === "object" && config.debugLogs.logCondition && !config.debugLogs.logCondition?.()) return;
|
|
141
|
+
if (typeof args[0] === "object" && "method" in args[0]) {
|
|
142
|
+
const method = args.shift().method;
|
|
143
|
+
if (typeof config.debugLogs === "object") {
|
|
144
|
+
if (method === "create" && !config.debugLogs.create) return;
|
|
145
|
+
else if (method === "update" && !config.debugLogs.update) return;
|
|
146
|
+
else if (method === "updateMany" && !config.debugLogs.updateMany) return;
|
|
147
|
+
else if (method === "findOne" && !config.debugLogs.findOne) return;
|
|
148
|
+
else if (method === "findMany" && !config.debugLogs.findMany) return;
|
|
149
|
+
else if (method === "delete" && !config.debugLogs.delete) return;
|
|
150
|
+
else if (method === "deleteMany" && !config.debugLogs.deleteMany) return;
|
|
151
|
+
else if (method === "count" && !config.debugLogs.count) return;
|
|
152
|
+
}
|
|
153
|
+
logger.info(`[${config.adapterName}]`, ...args);
|
|
154
|
+
} else logger.info(`[${config.adapterName}]`, ...args);
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
const idField = ({ customModelName, forceAllowId }) => {
|
|
158
|
+
const useNumberId = options.advanced?.database?.useNumberId || options.advanced?.database?.generateId === "serial";
|
|
159
|
+
const shouldGenerateId = !config.disableIdGeneration && !useNumberId && !forceAllowId;
|
|
160
|
+
const model = getDefaultModelName(customModelName ?? "id");
|
|
161
|
+
return {
|
|
162
|
+
type: useNumberId ? "number" : "string",
|
|
163
|
+
required: shouldGenerateId ? true : false,
|
|
164
|
+
...shouldGenerateId ? { defaultValue() {
|
|
165
|
+
if (config.disableIdGeneration) return void 0;
|
|
166
|
+
let generateId$1 = options.advanced?.database?.generateId;
|
|
167
|
+
if (options.advanced?.generateId !== void 0) {
|
|
168
|
+
logger.warn("Your Payvo Auth config includes advanced.generateId which is deprecated. Please use advanced.database.generateId instead. This will be removed in future releases.");
|
|
169
|
+
generateId$1 = options.advanced?.generateId;
|
|
170
|
+
}
|
|
171
|
+
if (generateId$1 === false || useNumberId) return void 0;
|
|
172
|
+
if (typeof generateId$1 === "function") return generateId$1({ model });
|
|
173
|
+
if (generateId$1 === "uuid") return crypto.randomUUID();
|
|
174
|
+
if (config.customIdGenerator) return config.customIdGenerator({ model });
|
|
175
|
+
return generateId();
|
|
176
|
+
} } : {}
|
|
177
|
+
};
|
|
178
|
+
};
|
|
179
|
+
const getFieldAttributes = ({ model, field }) => {
|
|
180
|
+
const defaultModelName = getDefaultModelName(model);
|
|
181
|
+
const defaultFieldName = getDefaultFieldName({
|
|
182
|
+
field,
|
|
183
|
+
model: defaultModelName
|
|
184
|
+
});
|
|
185
|
+
const fields = schema[defaultModelName].fields;
|
|
186
|
+
fields.id = idField({ customModelName: defaultModelName });
|
|
187
|
+
const fieldAttributes = fields[defaultFieldName];
|
|
188
|
+
if (!fieldAttributes) throw new PayvoAuthError(`Field ${field} not found in model ${model}`);
|
|
189
|
+
return fieldAttributes;
|
|
190
|
+
};
|
|
191
|
+
const transformInput = async (data, defaultModelName, action, forceAllowId) => {
|
|
192
|
+
const transformedData = {};
|
|
193
|
+
const fields = schema[defaultModelName].fields;
|
|
194
|
+
const newMappedKeys = config.mapKeysTransformInput ?? {};
|
|
195
|
+
if (!config.disableIdGeneration && !options.advanced?.database?.useNumberId) fields.id = idField({
|
|
196
|
+
customModelName: defaultModelName,
|
|
197
|
+
forceAllowId: forceAllowId && "id" in data
|
|
198
|
+
});
|
|
199
|
+
for (const field in fields) {
|
|
200
|
+
let value = data[field];
|
|
201
|
+
const fieldAttributes = fields[field];
|
|
202
|
+
let newFieldName = newMappedKeys[field] || fields[field].fieldName || field;
|
|
203
|
+
if (value === void 0 && (fieldAttributes.defaultValue === void 0 && !fieldAttributes.transform?.input && !(action === "update" && fieldAttributes.onUpdate) || action === "update" && !fieldAttributes.onUpdate)) continue;
|
|
204
|
+
if (fieldAttributes && fieldAttributes.type === "date" && !(value instanceof Date) && typeof value === "string") try {
|
|
205
|
+
value = new Date(value);
|
|
206
|
+
} catch {
|
|
207
|
+
logger.error("[Adapter Factory] Failed to convert string to date", {
|
|
208
|
+
value,
|
|
209
|
+
field
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
let newValue = withApplyDefault(value, fieldAttributes, action);
|
|
213
|
+
if (fieldAttributes.transform?.input) newValue = await fieldAttributes.transform.input(newValue);
|
|
214
|
+
if (fieldAttributes.references?.field === "id" && options.advanced?.database?.useNumberId) if (Array.isArray(newValue)) newValue = newValue.map((x) => x !== null ? Number(x) : null);
|
|
215
|
+
else newValue = newValue !== null ? Number(newValue) : null;
|
|
216
|
+
else if (config.supportsJSON === false && typeof newValue === "object" && fieldAttributes.type === "json") newValue = JSON.stringify(newValue);
|
|
217
|
+
else if (config.supportsDates === false && newValue instanceof Date && fieldAttributes.type === "date") newValue = newValue.toISOString();
|
|
218
|
+
else if (config.supportsBooleans === false && typeof newValue === "boolean") newValue = newValue ? 1 : 0;
|
|
219
|
+
if (config.customTransformInput) newValue = config.customTransformInput({
|
|
220
|
+
data: newValue,
|
|
221
|
+
action,
|
|
222
|
+
field: newFieldName,
|
|
223
|
+
fieldAttributes,
|
|
224
|
+
model: defaultModelName,
|
|
225
|
+
schema,
|
|
226
|
+
options
|
|
227
|
+
});
|
|
228
|
+
if (newValue !== void 0) transformedData[newFieldName] = newValue;
|
|
229
|
+
}
|
|
230
|
+
return transformedData;
|
|
231
|
+
};
|
|
232
|
+
const transformOutput = async (data, unsafe_model, select = []) => {
|
|
233
|
+
if (!data) return null;
|
|
234
|
+
const newMappedKeys = config.mapKeysTransformOutput ?? {};
|
|
235
|
+
const transformedData = {};
|
|
236
|
+
const tableSchema = schema[unsafe_model].fields;
|
|
237
|
+
const idKey = Object.entries(newMappedKeys).find(([_, v]) => v === "id")?.[0];
|
|
238
|
+
tableSchema[idKey ?? "id"] = { type: options.advanced?.database?.useNumberId ? "number" : "string" };
|
|
239
|
+
for (const key in tableSchema) {
|
|
240
|
+
if (select.length && !select.includes(key)) continue;
|
|
241
|
+
const field = tableSchema[key];
|
|
242
|
+
if (field) {
|
|
243
|
+
const originalKey = field.fieldName || key;
|
|
244
|
+
let newValue = data[Object.entries(newMappedKeys).find(([_, v]) => v === originalKey)?.[0] || originalKey];
|
|
245
|
+
if (field.transform?.output) newValue = await field.transform.output(newValue);
|
|
246
|
+
let newFieldName = newMappedKeys[key] || key;
|
|
247
|
+
if (originalKey === "id" || field.references?.field === "id") {
|
|
248
|
+
if (typeof newValue !== "undefined" && newValue !== null) newValue = String(newValue);
|
|
249
|
+
} else if (config.supportsJSON === false && typeof newValue === "string" && field.type === "json") newValue = safeJSONParse(newValue);
|
|
250
|
+
else if (config.supportsDates === false && typeof newValue === "string" && field.type === "date") newValue = new Date(newValue);
|
|
251
|
+
else if (config.supportsBooleans === false && typeof newValue === "number" && field.type === "boolean") newValue = newValue === 1;
|
|
252
|
+
if (config.customTransformOutput) newValue = config.customTransformOutput({
|
|
253
|
+
data: newValue,
|
|
254
|
+
field: newFieldName,
|
|
255
|
+
fieldAttributes: field,
|
|
256
|
+
select,
|
|
257
|
+
model: unsafe_model,
|
|
258
|
+
schema,
|
|
259
|
+
options
|
|
260
|
+
});
|
|
261
|
+
transformedData[newFieldName] = newValue;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
return transformedData;
|
|
265
|
+
};
|
|
266
|
+
const transformWhereClause = ({ model, where }) => {
|
|
267
|
+
if (!where) return void 0;
|
|
268
|
+
const newMappedKeys = config.mapKeysTransformInput ?? {};
|
|
269
|
+
return where.map((w) => {
|
|
270
|
+
const { field: unsafe_field, value, operator = "eq", connector = "AND" } = w;
|
|
271
|
+
if (operator === "in") {
|
|
272
|
+
if (!Array.isArray(value)) throw new PayvoAuthError("Value must be an array");
|
|
273
|
+
}
|
|
274
|
+
let newValue = value;
|
|
275
|
+
const defaultModelName = getDefaultModelName(model);
|
|
276
|
+
const defaultFieldName = getDefaultFieldName({
|
|
277
|
+
field: unsafe_field,
|
|
278
|
+
model
|
|
279
|
+
});
|
|
280
|
+
const fieldName = newMappedKeys[defaultFieldName] || getFieldName({
|
|
281
|
+
field: defaultFieldName,
|
|
282
|
+
model: defaultModelName
|
|
283
|
+
});
|
|
284
|
+
const fieldAttr = getFieldAttributes({
|
|
285
|
+
field: defaultFieldName,
|
|
286
|
+
model: defaultModelName
|
|
287
|
+
});
|
|
288
|
+
if (defaultFieldName === "id" || fieldAttr.references?.field === "id") {
|
|
289
|
+
if (options.advanced?.database?.useNumberId) if (Array.isArray(value)) newValue = value.map(Number);
|
|
290
|
+
else newValue = Number(value);
|
|
291
|
+
}
|
|
292
|
+
if (fieldAttr.type === "date" && value instanceof Date && !config.supportsDates) newValue = value.toISOString();
|
|
293
|
+
if (fieldAttr.type === "boolean" && typeof value === "boolean" && !config.supportsBooleans) newValue = value ? 1 : 0;
|
|
294
|
+
if (fieldAttr.type === "json" && typeof value === "object" && !config.supportsJSON) try {
|
|
295
|
+
newValue = JSON.stringify(value);
|
|
296
|
+
} catch (error) {
|
|
297
|
+
throw new Error(`Failed to stringify JSON value for field ${fieldName}`, { cause: error });
|
|
298
|
+
}
|
|
299
|
+
return {
|
|
300
|
+
operator,
|
|
301
|
+
connector,
|
|
302
|
+
field: fieldName,
|
|
303
|
+
value: newValue
|
|
304
|
+
};
|
|
305
|
+
});
|
|
306
|
+
};
|
|
307
|
+
const adapterInstance = customAdapter({
|
|
308
|
+
options,
|
|
309
|
+
schema,
|
|
310
|
+
debugLog,
|
|
311
|
+
getFieldName,
|
|
312
|
+
getModelName,
|
|
313
|
+
getDefaultModelName,
|
|
314
|
+
getDefaultFieldName,
|
|
315
|
+
getFieldAttributes,
|
|
316
|
+
transformInput,
|
|
317
|
+
transformOutput,
|
|
318
|
+
transformWhereClause
|
|
319
|
+
});
|
|
320
|
+
let lazyLoadTransaction = null;
|
|
321
|
+
const adapter = {
|
|
322
|
+
transaction: async (cb) => {
|
|
323
|
+
if (!lazyLoadTransaction) if (!config.transaction) lazyLoadTransaction = createAsIsTransaction(adapter);
|
|
324
|
+
else {
|
|
325
|
+
logger.debug(`[${config.adapterName}] - Using provided transaction implementation.`);
|
|
326
|
+
lazyLoadTransaction = config.transaction;
|
|
327
|
+
}
|
|
328
|
+
return lazyLoadTransaction(cb);
|
|
329
|
+
},
|
|
330
|
+
create: async ({ data: unsafeData, model: unsafeModel, select, forceAllowId = false }) => {
|
|
331
|
+
transactionId++;
|
|
332
|
+
let thisTransactionId = transactionId;
|
|
333
|
+
const model = getModelName(unsafeModel);
|
|
334
|
+
unsafeModel = getDefaultModelName(unsafeModel);
|
|
335
|
+
if ("id" in unsafeData && !forceAllowId) {
|
|
336
|
+
logger.warn(`[${config.adapterName}] - You are trying to create a record with an id. This is not allowed as we handle id generation for you, unless you pass in the \`forceAllowId\` parameter. The id will be ignored.`);
|
|
337
|
+
const stack = (/* @__PURE__ */ new Error()).stack?.split("\n").filter((_, i) => i !== 1).join("\n").replace("Error:", "Create method with `id` being called at:");
|
|
338
|
+
console.log(stack);
|
|
339
|
+
unsafeData.id = void 0;
|
|
340
|
+
}
|
|
341
|
+
debugLog({ method: "create" }, `${formatTransactionId(thisTransactionId)} ${formatStep(1, 4)}`, `${formatMethod("create")} ${formatAction("Unsafe Input")}:`, {
|
|
342
|
+
model,
|
|
343
|
+
data: unsafeData
|
|
344
|
+
});
|
|
345
|
+
let data = unsafeData;
|
|
346
|
+
if (!config.disableTransformInput) data = await transformInput(unsafeData, unsafeModel, "create", forceAllowId);
|
|
347
|
+
debugLog({ method: "create" }, `${formatTransactionId(thisTransactionId)} ${formatStep(2, 4)}`, `${formatMethod("create")} ${formatAction("Parsed Input")}:`, {
|
|
348
|
+
model,
|
|
349
|
+
data
|
|
350
|
+
});
|
|
351
|
+
const res = await adapterInstance.create({
|
|
352
|
+
data,
|
|
353
|
+
model
|
|
354
|
+
});
|
|
355
|
+
debugLog({ method: "create" }, `${formatTransactionId(thisTransactionId)} ${formatStep(3, 4)}`, `${formatMethod("create")} ${formatAction("DB Result")}:`, {
|
|
356
|
+
model,
|
|
357
|
+
res
|
|
358
|
+
});
|
|
359
|
+
let transformed = res;
|
|
360
|
+
if (!config.disableTransformOutput) transformed = await transformOutput(res, unsafeModel, select);
|
|
361
|
+
debugLog({ method: "create" }, `${formatTransactionId(thisTransactionId)} ${formatStep(4, 4)}`, `${formatMethod("create")} ${formatAction("Parsed Result")}:`, {
|
|
362
|
+
model,
|
|
363
|
+
data: transformed
|
|
364
|
+
});
|
|
365
|
+
return transformed;
|
|
366
|
+
},
|
|
367
|
+
update: async ({ model: unsafeModel, where: unsafeWhere, update: unsafeData }) => {
|
|
368
|
+
transactionId++;
|
|
369
|
+
let thisTransactionId = transactionId;
|
|
370
|
+
unsafeModel = getDefaultModelName(unsafeModel);
|
|
371
|
+
const model = getModelName(unsafeModel);
|
|
372
|
+
const where = transformWhereClause({
|
|
373
|
+
model: unsafeModel,
|
|
374
|
+
where: unsafeWhere
|
|
375
|
+
});
|
|
376
|
+
debugLog({ method: "update" }, `${formatTransactionId(thisTransactionId)} ${formatStep(1, 4)}`, `${formatMethod("update")} ${formatAction("Unsafe Input")}:`, {
|
|
377
|
+
model,
|
|
378
|
+
data: unsafeData
|
|
379
|
+
});
|
|
380
|
+
let data = unsafeData;
|
|
381
|
+
if (!config.disableTransformInput) data = await transformInput(unsafeData, unsafeModel, "update");
|
|
382
|
+
debugLog({ method: "update" }, `${formatTransactionId(thisTransactionId)} ${formatStep(2, 4)}`, `${formatMethod("update")} ${formatAction("Parsed Input")}:`, {
|
|
383
|
+
model,
|
|
384
|
+
data
|
|
385
|
+
});
|
|
386
|
+
const res = await adapterInstance.update({
|
|
387
|
+
model,
|
|
388
|
+
where,
|
|
389
|
+
update: data
|
|
390
|
+
});
|
|
391
|
+
debugLog({ method: "update" }, `${formatTransactionId(thisTransactionId)} ${formatStep(3, 4)}`, `${formatMethod("update")} ${formatAction("DB Result")}:`, {
|
|
392
|
+
model,
|
|
393
|
+
data: res
|
|
394
|
+
});
|
|
395
|
+
let transformed = res;
|
|
396
|
+
if (!config.disableTransformOutput) transformed = await transformOutput(res, unsafeModel);
|
|
397
|
+
debugLog({ method: "update" }, `${formatTransactionId(thisTransactionId)} ${formatStep(4, 4)}`, `${formatMethod("update")} ${formatAction("Parsed Result")}:`, {
|
|
398
|
+
model,
|
|
399
|
+
data: transformed
|
|
400
|
+
});
|
|
401
|
+
return transformed;
|
|
402
|
+
},
|
|
403
|
+
updateMany: async ({ model: unsafeModel, where: unsafeWhere, update: unsafeData }) => {
|
|
404
|
+
transactionId++;
|
|
405
|
+
let thisTransactionId = transactionId;
|
|
406
|
+
const model = getModelName(unsafeModel);
|
|
407
|
+
const where = transformWhereClause({
|
|
408
|
+
model: unsafeModel,
|
|
409
|
+
where: unsafeWhere
|
|
410
|
+
});
|
|
411
|
+
unsafeModel = getDefaultModelName(unsafeModel);
|
|
412
|
+
debugLog({ method: "updateMany" }, `${formatTransactionId(thisTransactionId)} ${formatStep(1, 4)}`, `${formatMethod("updateMany")} ${formatAction("Unsafe Input")}:`, {
|
|
413
|
+
model,
|
|
414
|
+
data: unsafeData
|
|
415
|
+
});
|
|
416
|
+
let data = unsafeData;
|
|
417
|
+
if (!config.disableTransformInput) data = await transformInput(unsafeData, unsafeModel, "update");
|
|
418
|
+
debugLog({ method: "updateMany" }, `${formatTransactionId(thisTransactionId)} ${formatStep(2, 4)}`, `${formatMethod("updateMany")} ${formatAction("Parsed Input")}:`, {
|
|
419
|
+
model,
|
|
420
|
+
data
|
|
421
|
+
});
|
|
422
|
+
const updatedCount = await adapterInstance.updateMany({
|
|
423
|
+
model,
|
|
424
|
+
where,
|
|
425
|
+
update: data
|
|
426
|
+
});
|
|
427
|
+
debugLog({ method: "updateMany" }, `${formatTransactionId(thisTransactionId)} ${formatStep(3, 4)}`, `${formatMethod("updateMany")} ${formatAction("DB Result")}:`, {
|
|
428
|
+
model,
|
|
429
|
+
data: updatedCount
|
|
430
|
+
});
|
|
431
|
+
debugLog({ method: "updateMany" }, `${formatTransactionId(thisTransactionId)} ${formatStep(4, 4)}`, `${formatMethod("updateMany")} ${formatAction("Parsed Result")}:`, {
|
|
432
|
+
model,
|
|
433
|
+
data: updatedCount
|
|
434
|
+
});
|
|
435
|
+
return updatedCount;
|
|
436
|
+
},
|
|
437
|
+
findOne: async ({ model: unsafeModel, where: unsafeWhere, select }) => {
|
|
438
|
+
transactionId++;
|
|
439
|
+
let thisTransactionId = transactionId;
|
|
440
|
+
const model = getModelName(unsafeModel);
|
|
441
|
+
const where = transformWhereClause({
|
|
442
|
+
model: unsafeModel,
|
|
443
|
+
where: unsafeWhere
|
|
444
|
+
});
|
|
445
|
+
unsafeModel = getDefaultModelName(unsafeModel);
|
|
446
|
+
debugLog({ method: "findOne" }, `${formatTransactionId(thisTransactionId)} ${formatStep(1, 3)}`, `${formatMethod("findOne")}:`, {
|
|
447
|
+
model,
|
|
448
|
+
where,
|
|
449
|
+
select
|
|
450
|
+
});
|
|
451
|
+
const res = await adapterInstance.findOne({
|
|
452
|
+
model,
|
|
453
|
+
where,
|
|
454
|
+
select
|
|
455
|
+
});
|
|
456
|
+
debugLog({ method: "findOne" }, `${formatTransactionId(thisTransactionId)} ${formatStep(2, 3)}`, `${formatMethod("findOne")} ${formatAction("DB Result")}:`, {
|
|
457
|
+
model,
|
|
458
|
+
data: res
|
|
459
|
+
});
|
|
460
|
+
let transformed = res;
|
|
461
|
+
if (!config.disableTransformOutput) transformed = await transformOutput(res, unsafeModel, select);
|
|
462
|
+
debugLog({ method: "findOne" }, `${formatTransactionId(thisTransactionId)} ${formatStep(3, 3)}`, `${formatMethod("findOne")} ${formatAction("Parsed Result")}:`, {
|
|
463
|
+
model,
|
|
464
|
+
data: transformed
|
|
465
|
+
});
|
|
466
|
+
return transformed;
|
|
467
|
+
},
|
|
468
|
+
findMany: async ({ model: unsafeModel, where: unsafeWhere, limit: unsafeLimit, sortBy, offset }) => {
|
|
469
|
+
transactionId++;
|
|
470
|
+
let thisTransactionId = transactionId;
|
|
471
|
+
const limit = unsafeLimit ?? options.advanced?.database?.defaultFindManyLimit ?? 100;
|
|
472
|
+
const model = getModelName(unsafeModel);
|
|
473
|
+
const where = transformWhereClause({
|
|
474
|
+
model: unsafeModel,
|
|
475
|
+
where: unsafeWhere
|
|
476
|
+
});
|
|
477
|
+
unsafeModel = getDefaultModelName(unsafeModel);
|
|
478
|
+
debugLog({ method: "findMany" }, `${formatTransactionId(thisTransactionId)} ${formatStep(1, 3)}`, `${formatMethod("findMany")}:`, {
|
|
479
|
+
model,
|
|
480
|
+
where,
|
|
481
|
+
limit,
|
|
482
|
+
sortBy,
|
|
483
|
+
offset
|
|
484
|
+
});
|
|
485
|
+
const res = await adapterInstance.findMany({
|
|
486
|
+
model,
|
|
487
|
+
where,
|
|
488
|
+
limit,
|
|
489
|
+
sortBy,
|
|
490
|
+
offset
|
|
491
|
+
});
|
|
492
|
+
debugLog({ method: "findMany" }, `${formatTransactionId(thisTransactionId)} ${formatStep(2, 3)}`, `${formatMethod("findMany")} ${formatAction("DB Result")}:`, {
|
|
493
|
+
model,
|
|
494
|
+
data: res
|
|
495
|
+
});
|
|
496
|
+
let transformed = res;
|
|
497
|
+
if (!config.disableTransformOutput) transformed = await Promise.all(res.map(async (r) => await transformOutput(r, unsafeModel)));
|
|
498
|
+
debugLog({ method: "findMany" }, `${formatTransactionId(thisTransactionId)} ${formatStep(3, 3)}`, `${formatMethod("findMany")} ${formatAction("Parsed Result")}:`, {
|
|
499
|
+
model,
|
|
500
|
+
data: transformed
|
|
501
|
+
});
|
|
502
|
+
return transformed;
|
|
503
|
+
},
|
|
504
|
+
delete: async ({ model: unsafeModel, where: unsafeWhere }) => {
|
|
505
|
+
transactionId++;
|
|
506
|
+
let thisTransactionId = transactionId;
|
|
507
|
+
const model = getModelName(unsafeModel);
|
|
508
|
+
const where = transformWhereClause({
|
|
509
|
+
model: unsafeModel,
|
|
510
|
+
where: unsafeWhere
|
|
511
|
+
});
|
|
512
|
+
unsafeModel = getDefaultModelName(unsafeModel);
|
|
513
|
+
debugLog({ method: "delete" }, `${formatTransactionId(thisTransactionId)} ${formatStep(1, 2)}`, `${formatMethod("delete")}:`, {
|
|
514
|
+
model,
|
|
515
|
+
where
|
|
516
|
+
});
|
|
517
|
+
await adapterInstance.delete({
|
|
518
|
+
model,
|
|
519
|
+
where
|
|
520
|
+
});
|
|
521
|
+
debugLog({ method: "delete" }, `${formatTransactionId(thisTransactionId)} ${formatStep(2, 2)}`, `${formatMethod("delete")} ${formatAction("DB Result")}:`, { model });
|
|
522
|
+
},
|
|
523
|
+
deleteMany: async ({ model: unsafeModel, where: unsafeWhere }) => {
|
|
524
|
+
transactionId++;
|
|
525
|
+
let thisTransactionId = transactionId;
|
|
526
|
+
const model = getModelName(unsafeModel);
|
|
527
|
+
const where = transformWhereClause({
|
|
528
|
+
model: unsafeModel,
|
|
529
|
+
where: unsafeWhere
|
|
530
|
+
});
|
|
531
|
+
unsafeModel = getDefaultModelName(unsafeModel);
|
|
532
|
+
debugLog({ method: "deleteMany" }, `${formatTransactionId(thisTransactionId)} ${formatStep(1, 2)}`, `${formatMethod("deleteMany")} ${formatAction("DeleteMany")}:`, {
|
|
533
|
+
model,
|
|
534
|
+
where
|
|
535
|
+
});
|
|
536
|
+
const res = await adapterInstance.deleteMany({
|
|
537
|
+
model,
|
|
538
|
+
where
|
|
539
|
+
});
|
|
540
|
+
debugLog({ method: "deleteMany" }, `${formatTransactionId(thisTransactionId)} ${formatStep(2, 2)}`, `${formatMethod("deleteMany")} ${formatAction("DB Result")}:`, {
|
|
541
|
+
model,
|
|
542
|
+
data: res
|
|
543
|
+
});
|
|
544
|
+
return res;
|
|
545
|
+
},
|
|
546
|
+
count: async ({ model: unsafeModel, where: unsafeWhere }) => {
|
|
547
|
+
transactionId++;
|
|
548
|
+
let thisTransactionId = transactionId;
|
|
549
|
+
const model = getModelName(unsafeModel);
|
|
550
|
+
const where = transformWhereClause({
|
|
551
|
+
model: unsafeModel,
|
|
552
|
+
where: unsafeWhere
|
|
553
|
+
});
|
|
554
|
+
unsafeModel = getDefaultModelName(unsafeModel);
|
|
555
|
+
debugLog({ method: "count" }, `${formatTransactionId(thisTransactionId)} ${formatStep(1, 2)}`, `${formatMethod("count")}:`, {
|
|
556
|
+
model,
|
|
557
|
+
where
|
|
558
|
+
});
|
|
559
|
+
const res = await adapterInstance.count({
|
|
560
|
+
model,
|
|
561
|
+
where
|
|
562
|
+
});
|
|
563
|
+
debugLog({ method: "count" }, `${formatTransactionId(thisTransactionId)} ${formatStep(2, 2)}`, `${formatMethod("count")}:`, {
|
|
564
|
+
model,
|
|
565
|
+
data: res
|
|
566
|
+
});
|
|
567
|
+
return res;
|
|
568
|
+
},
|
|
569
|
+
createSchema: adapterInstance.createSchema ? async (_, file) => {
|
|
570
|
+
const tables = getAuthTables(options);
|
|
571
|
+
if (options.secondaryStorage && !options.session?.storeSessionInDatabase) delete tables.session;
|
|
572
|
+
if (options.rateLimit && options.rateLimit.storage === "database" && (typeof options.rateLimit.enabled === "undefined" || options.rateLimit.enabled === true)) tables.ratelimit = {
|
|
573
|
+
modelName: options.rateLimit.modelName ?? "ratelimit",
|
|
574
|
+
fields: {
|
|
575
|
+
key: {
|
|
576
|
+
type: "string",
|
|
577
|
+
unique: true,
|
|
578
|
+
required: true,
|
|
579
|
+
fieldName: options.rateLimit.fields?.key ?? "key"
|
|
580
|
+
},
|
|
581
|
+
count: {
|
|
582
|
+
type: "number",
|
|
583
|
+
required: true,
|
|
584
|
+
fieldName: options.rateLimit.fields?.count ?? "count"
|
|
585
|
+
},
|
|
586
|
+
lastRequest: {
|
|
587
|
+
type: "number",
|
|
588
|
+
required: true,
|
|
589
|
+
bigint: true,
|
|
590
|
+
defaultValue: () => Date.now(),
|
|
591
|
+
fieldName: options.rateLimit.fields?.lastRequest ?? "lastRequest"
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
};
|
|
595
|
+
return adapterInstance.createSchema({
|
|
596
|
+
file,
|
|
597
|
+
tables
|
|
598
|
+
});
|
|
599
|
+
} : void 0,
|
|
600
|
+
options: {
|
|
601
|
+
adapterConfig: config,
|
|
602
|
+
...adapterInstance.options ?? {}
|
|
603
|
+
},
|
|
604
|
+
id: config.adapterId,
|
|
605
|
+
...config.debugLogs?.isRunningAdapterTests ? { adapterTestDebugLogs: {
|
|
606
|
+
resetDebugLogs() {
|
|
607
|
+
debugLogs = debugLogs.filter((log) => log.instance !== uniqueAdapterFactoryInstanceId);
|
|
608
|
+
},
|
|
609
|
+
printDebugLogs() {
|
|
610
|
+
const separator = `─`.repeat(80);
|
|
611
|
+
const logs = debugLogs.filter((log$1) => log$1.instance === uniqueAdapterFactoryInstanceId);
|
|
612
|
+
if (logs.length === 0) return;
|
|
613
|
+
let log = logs.reverse().map((log$1) => {
|
|
614
|
+
log$1.args[0] = `\n${log$1.args[0]}`;
|
|
615
|
+
return [...log$1.args, "\n"];
|
|
616
|
+
}).reduce((prev, curr) => {
|
|
617
|
+
return [...curr, ...prev];
|
|
618
|
+
}, [`\n${separator}`]);
|
|
619
|
+
console.log(...log);
|
|
620
|
+
}
|
|
621
|
+
} } : {}
|
|
622
|
+
};
|
|
623
|
+
return adapter;
|
|
624
|
+
};
|
|
625
|
+
function formatTransactionId(transactionId$1) {
|
|
626
|
+
if (getColorDepth() < 8) return `#${transactionId$1}`;
|
|
627
|
+
return `${TTY_COLORS.fg.magenta}#${transactionId$1}${TTY_COLORS.reset}`;
|
|
628
|
+
}
|
|
629
|
+
function formatStep(step, total) {
|
|
630
|
+
return `${TTY_COLORS.bg.black}${TTY_COLORS.fg.yellow}[${step}/${total}]${TTY_COLORS.reset}`;
|
|
631
|
+
}
|
|
632
|
+
function formatMethod(method) {
|
|
633
|
+
return `${TTY_COLORS.bright}${method}${TTY_COLORS.reset}`;
|
|
634
|
+
}
|
|
635
|
+
function formatAction(action) {
|
|
636
|
+
return `${TTY_COLORS.dim}(${action})${TTY_COLORS.reset}`;
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
//#endregion
|
|
640
|
+
export { createAdapterFactory as t };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { PayvoAuthOptions } from "@gatwech/core";
|
|
2
|
+
import { DBAdapter, DBAdapterDebugLogOption } from "@gatwech/core/db/adapter";
|
|
3
|
+
|
|
4
|
+
//#region src/adapters/drizzle-adapter/drizzle-adapter.d.ts
|
|
5
|
+
interface DB {
|
|
6
|
+
[key: string]: any;
|
|
7
|
+
}
|
|
8
|
+
interface DrizzleAdapterConfig {
|
|
9
|
+
/**
|
|
10
|
+
* The schema object that defines the tables and fields
|
|
11
|
+
*/
|
|
12
|
+
schema?: Record<string, any> | undefined;
|
|
13
|
+
/**
|
|
14
|
+
* The database provider
|
|
15
|
+
*/
|
|
16
|
+
provider: "pg" | "mysql" | "sqlite";
|
|
17
|
+
/**
|
|
18
|
+
* If the table names in the schema are plural
|
|
19
|
+
* set this to true. For example, if the schema
|
|
20
|
+
* has an object with a key "users" instead of "user"
|
|
21
|
+
*/
|
|
22
|
+
usePlural?: boolean | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* Enable debug logs for the adapter
|
|
25
|
+
*
|
|
26
|
+
* @default false
|
|
27
|
+
*/
|
|
28
|
+
debugLogs?: DBAdapterDebugLogOption | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* By default snake case is used for table and field names
|
|
31
|
+
* when the CLI is used to generate the schema. If you want
|
|
32
|
+
* to use camel case, set this to true.
|
|
33
|
+
* @default false
|
|
34
|
+
*/
|
|
35
|
+
camelCase?: boolean | undefined;
|
|
36
|
+
/**
|
|
37
|
+
* Whether to execute multiple operations in a transaction.
|
|
38
|
+
*
|
|
39
|
+
* If the database doesn't support transactions,
|
|
40
|
+
* set this to `false` and operations will be executed sequentially.
|
|
41
|
+
* @default false
|
|
42
|
+
*/
|
|
43
|
+
transaction?: boolean | undefined;
|
|
44
|
+
}
|
|
45
|
+
declare const drizzleAdapter: (db: DB, config: DrizzleAdapterConfig) => (options: PayvoAuthOptions) => DBAdapter<PayvoAuthOptions>;
|
|
46
|
+
//#endregion
|
|
47
|
+
export { DB, DrizzleAdapterConfig, drizzleAdapter };
|