@pithy-sh/auth 0.1.2 → 0.1.4

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.
Files changed (122) hide show
  1. package/dist/admin/users.d.ts +157 -0
  2. package/dist/admin/users.d.ts.map +1 -0
  3. package/dist/admin/users.js +207 -0
  4. package/dist/audit/actions.d.ts +68 -0
  5. package/dist/audit/actions.d.ts.map +1 -0
  6. package/dist/audit/actions.js +68 -0
  7. package/dist/audit/emit.d.ts +103 -0
  8. package/dist/audit/emit.d.ts.map +1 -0
  9. package/dist/audit/emit.js +172 -0
  10. package/dist/capability.d.ts +62 -0
  11. package/dist/capability.d.ts.map +1 -0
  12. package/dist/capability.js +171 -0
  13. package/dist/client/api.d.ts +301 -0
  14. package/dist/client/api.d.ts.map +1 -0
  15. package/dist/client/api.js +387 -0
  16. package/dist/client/projection.d.ts +53 -0
  17. package/dist/client/projection.d.ts.map +1 -0
  18. package/dist/client/projection.js +2 -0
  19. package/dist/data/betterAuth.d.ts +77 -0
  20. package/dist/data/betterAuth.d.ts.map +1 -0
  21. package/dist/data/betterAuth.js +94 -0
  22. package/dist/data/device.d.ts +38 -0
  23. package/dist/data/device.d.ts.map +1 -0
  24. package/dist/data/device.js +35 -0
  25. package/dist/data/kitFields.d.ts +80 -0
  26. package/dist/data/kitFields.d.ts.map +1 -0
  27. package/dist/data/kitFields.js +79 -0
  28. package/dist/data/rotatedToken.d.ts +22 -0
  29. package/dist/data/rotatedToken.d.ts.map +1 -0
  30. package/dist/data/rotatedToken.js +24 -0
  31. package/dist/data/tables.d.ts +106 -0
  32. package/dist/data/tables.d.ts.map +1 -0
  33. package/dist/data/tables.js +32 -0
  34. package/dist/device/registry.d.ts +56 -0
  35. package/dist/device/registry.d.ts.map +1 -0
  36. package/dist/device/registry.js +87 -0
  37. package/dist/email/send.d.ts +40 -0
  38. package/dist/email/send.d.ts.map +1 -0
  39. package/dist/email/send.js +50 -0
  40. package/dist/http/adminRoutes.d.ts +11 -0
  41. package/dist/http/adminRoutes.d.ts.map +1 -0
  42. package/dist/http/adminRoutes.js +276 -0
  43. package/dist/http/baseUrl.d.ts +43 -0
  44. package/dist/http/baseUrl.d.ts.map +1 -0
  45. package/dist/http/baseUrl.js +98 -0
  46. package/dist/http/csrf.d.ts +20 -0
  47. package/dist/http/csrf.d.ts.map +1 -0
  48. package/dist/http/csrf.js +83 -0
  49. package/dist/http/devLoginRoute.d.ts +44 -0
  50. package/dist/http/devLoginRoute.d.ts.map +1 -0
  51. package/dist/http/devLoginRoute.js +114 -0
  52. package/dist/http/errors.d.ts +26 -0
  53. package/dist/http/errors.d.ts.map +1 -0
  54. package/dist/http/errors.js +69 -0
  55. package/dist/http/guards.d.ts +105 -0
  56. package/dist/http/guards.d.ts.map +1 -0
  57. package/dist/http/guards.js +150 -0
  58. package/dist/http/middleware.d.ts +19 -0
  59. package/dist/http/middleware.d.ts.map +1 -0
  60. package/dist/http/middleware.js +49 -0
  61. package/dist/http/rateLimit.d.ts +19 -0
  62. package/dist/http/rateLimit.d.ts.map +1 -0
  63. package/dist/http/rateLimit.js +33 -0
  64. package/dist/http/resolve.d.ts +11 -0
  65. package/dist/http/resolve.d.ts.map +1 -0
  66. package/dist/http/resolve.js +94 -0
  67. package/dist/http/responses.d.ts +154 -0
  68. package/dist/http/responses.d.ts.map +1 -0
  69. package/dist/http/responses.js +123 -0
  70. package/dist/http/routes.d.ts +36 -0
  71. package/dist/http/routes.d.ts.map +1 -0
  72. package/dist/http/routes.js +270 -0
  73. package/dist/http/schemas.d.ts +68 -0
  74. package/dist/http/schemas.d.ts.map +1 -0
  75. package/dist/http/schemas.js +61 -0
  76. package/dist/http/views.d.ts +55 -0
  77. package/dist/http/views.d.ts.map +1 -0
  78. package/dist/http/views.js +88 -0
  79. package/dist/i18n/errorCopy.d.ts +26 -0
  80. package/dist/i18n/errorCopy.d.ts.map +1 -0
  81. package/dist/i18n/errorCopy.es.d.ts +33 -0
  82. package/dist/i18n/errorCopy.es.d.ts.map +1 -0
  83. package/dist/i18n/errorCopy.es.js +35 -0
  84. package/dist/i18n/errorCopy.js +93 -0
  85. package/dist/index.d.ts +16 -0
  86. package/dist/index.d.ts.map +1 -0
  87. package/dist/index.js +10 -0
  88. package/dist/instance/auth.d.ts +1124 -0
  89. package/dist/instance/auth.d.ts.map +1 -0
  90. package/dist/instance/auth.js +178 -0
  91. package/dist/instance/plugins.d.ts +89 -0
  92. package/dist/instance/plugins.d.ts.map +1 -0
  93. package/dist/instance/plugins.js +118 -0
  94. package/dist/instance/providers.d.ts +119 -0
  95. package/dist/instance/providers.d.ts.map +1 -0
  96. package/dist/instance/providers.js +113 -0
  97. package/dist/instance/secrets.d.ts +165 -0
  98. package/dist/instance/secrets.d.ts.map +1 -0
  99. package/dist/instance/secrets.js +171 -0
  100. package/dist/migrations/0001_init.d.ts +35 -0
  101. package/dist/migrations/0001_init.d.ts.map +1 -0
  102. package/dist/migrations/0001_init.js +79 -0
  103. package/dist/migrations/pluginTables.d.ts +128 -0
  104. package/dist/migrations/pluginTables.d.ts.map +1 -0
  105. package/dist/migrations/pluginTables.js +235 -0
  106. package/dist/seeds/devSession.d.ts +126 -0
  107. package/dist/seeds/devSession.d.ts.map +1 -0
  108. package/dist/seeds/devSession.js +213 -0
  109. package/dist/seeds/example.d.ts +14 -0
  110. package/dist/seeds/example.d.ts.map +1 -0
  111. package/dist/seeds/example.js +32 -0
  112. package/dist/test-utils/liveApp.d.ts +229 -0
  113. package/dist/test-utils/liveApp.d.ts.map +1 -0
  114. package/dist/test-utils/liveApp.js +242 -0
  115. package/dist/token/rotation.d.ts +58 -0
  116. package/dist/token/rotation.d.ts.map +1 -0
  117. package/dist/token/rotation.js +70 -0
  118. package/dist/version.generated.d.ts +7 -0
  119. package/dist/version.generated.d.ts.map +1 -0
  120. package/dist/version.generated.js +9 -0
  121. package/package.json +24 -13
  122. package/src/version.generated.ts +1 -1
@@ -0,0 +1,93 @@
1
+ // SPDX-FileCopyrightText: 2026 Pithy
2
+ // SPDX-License-Identifier: MIT
3
+ import { AUTH_ERRORS_ES } from "./errorCopy.es.js";
4
+ import { BASE_ERROR_CODES } from "better-auth";
5
+ import { locales } from "@better-auth/i18n";
6
+ //#region src/i18n/errorCopy.ts
7
+ /**
8
+ * The words Better Auth's own refusals are said in.
9
+ *
10
+ * ## Why this is server-side, when every other translation in the kit is not
11
+ *
12
+ * `docs/I18N.md` holds that the server never localizes an error: a `PithyError`'s `message` stays
13
+ * English permanently, because it is at once the operator's diagnostic and the fallback for a client
14
+ * that cannot translate, and a translating client renders `t.maybe(code, params) ?? message`.
15
+ *
16
+ * These are not `PithyError`s. Better Auth owns these routes and answers them in its own flat
17
+ * `{ message, code }` before anything of ours sees the failure — better-call renders an endpoint's
18
+ * `APIError` into a Response inside `instance.handler` (#449). So the choice is not *where* to
19
+ * translate them but *whether*, and leaving them was leaving the last English sentences on an otherwise
20
+ * translated screen — met by the most ordinary mistake there is, mistyping a one-time code.
21
+ *
22
+ * Translating them at the server also reaches a caller the client seam cannot: a mobile app holding a
23
+ * bearer token, or a second-party integration, gets the reader's language without shipping
24
+ * `@pithy-sh/i18n`. And nothing is lost to the operator, because the plugin keeps the English on
25
+ * `originalMessage` rather than replacing it.
26
+ *
27
+ * ## Where the words come from
28
+ *
29
+ * `@better-auth/i18n` (MIT) ships 22 languages of its own, maintained upstream. This layers over them
30
+ * rather than restating them: copying a locale here would fork it on the day it landed, and the kit's
31
+ * own rule for catalogs is that they ship in the package and are never copied. {@link AUTH_ERRORS_ES}
32
+ * carries only what its `es` is missing.
33
+ *
34
+ * **The layering is per key, never per locale**, for the same reason `composeMessages` merges that way:
35
+ * a locale object replacing another is a fork wearing the shape of an override.
36
+ */
37
+ /** Every locale this kit writes Better Auth's refusals in. English is the source and is not listed. */
38
+ const KIT_OVERRIDES = { es: AUTH_ERRORS_ES };
39
+ /**
40
+ * Codes that stay English on purpose, and why.
41
+ *
42
+ * **A declared list rather than a silent remainder.** The gate in `./errorCopy.test.ts` requires every
43
+ * code the composed plugin set can raise to be either translated or named here, so a code Better Auth
44
+ * adds in a later release fails the build instead of quietly reaching somebody in English. That is the
45
+ * same shape the migration-order table uses, and for the same reason: the property is only true as a
46
+ * set.
47
+ *
48
+ * Every entry is a fault an **adopter** caused in their own configuration or their own request, not
49
+ * anything a reader can act on. Translating those makes them harder to search for and no easier to fix.
50
+ */
51
+ const ENGLISH_ON_PURPOSE = {
52
+ ASYNC_VALIDATION_NOT_SUPPORTED: "A field validator returned a promise where the adapter takes none.",
53
+ BODY_MUST_BE_AN_OBJECT: "The caller sent something that is not a JSON object.",
54
+ CALLBACK_URL_REQUIRED: "The adopter's own call omitted the URL it wants a reader returned to.",
55
+ CHANGE_EMAIL_DISABLED: "The adopter switched the feature off in their own config.",
56
+ FAILED_TO_CREATE_VERIFICATION: "A write this Worker owns failed; the operator reads our logs, not a reader.",
57
+ FIELD_NOT_ALLOWED: "The caller sent a field the adopter's own schema does not declare.",
58
+ ID_TOKEN_NOT_SUPPORTED: "The configured provider does not do id-token sign-in.",
59
+ INVALID_CALLBACK_URL: "The adopter's configured callback is not a URL this Worker trusts.",
60
+ INVALID_ERROR_CALLBACK_URL: "As above, for the error return.",
61
+ INVALID_NEW_USER_CALLBACK_URL: "As above, for the first-sign-in return.",
62
+ INVALID_ORIGIN: "The CSRF origin gate. An operator reads this while checking `trustedOrigins`.",
63
+ INVALID_REDIRECT_URL: "A redirect target outside the configured set.",
64
+ METHOD_NOT_ALLOWED_DEFER_SESSION_REQUIRED: "A caller used the wrong verb on the session route.",
65
+ MISSING_OR_NULL_ORIGIN: "The other half of the origin gate, and the same audience."
66
+ };
67
+ /** Every error code the given plugin set can raise, plus Better Auth's own base vocabulary. */
68
+ function composedErrorCodes(plugins) {
69
+ const codes = new Set(Object.keys(BASE_ERROR_CODES));
70
+ for (const plugin of plugins) {
71
+ const own = plugin.$ERROR_CODES;
72
+ for (const code of Object.keys(own ?? {})) codes.add(code);
73
+ }
74
+ return [...codes].sort();
75
+ }
76
+ /**
77
+ * The dictionary the plugin is configured with: what it ships, with this kit's own words over the top.
78
+ *
79
+ * `en` is included and is the plugin's own, so a reader whose negotiated locale is English gets exactly
80
+ * the sentences Better Auth already wrote — this changes nothing for a project that serves one language.
81
+ */
82
+ function authErrorTranslations() {
83
+ const bundled = locales;
84
+ const merged = {};
85
+ for (const [locale, dictionary] of Object.entries(bundled)) merged[locale] = {
86
+ ...dictionary,
87
+ ...KIT_OVERRIDES[locale] ?? {}
88
+ };
89
+ for (const [locale, dictionary] of Object.entries(KIT_OVERRIDES)) if (!merged[locale]) merged[locale] = { ...dictionary };
90
+ return merged;
91
+ }
92
+ //#endregion
93
+ export { ENGLISH_ON_PURPOSE, authErrorTranslations, composedErrorCodes };
@@ -0,0 +1,16 @@
1
+ // SPDX-FileCopyrightText: 2026 Pithy
2
+ // SPDX-License-Identifier: MIT
3
+ /**
4
+ * The package entrypoint — the surface `pithy add auth` wires into `pithy.config.ts`. Deliberately
5
+ * narrow: the capability factory, the `requireAuth()` gate other capabilities stack, and the data /
6
+ * secret types an app or tool needs. Every other module is imported by deep path
7
+ * (`@pithy-sh/auth/src/...`) — this is the documented contract, not a barrel over the package.
8
+ */
9
+ export { AuthAuditActions } from "./audit/actions";
10
+ export { type AuthCapability, AuthConfig, type AuthConfigInput, auth, isAuthCapability } from "./capability";
11
+ export { type Device, DevicePlatform } from "./data/device";
12
+ export { type AuthDatabase, authDatabase } from "./data/tables";
13
+ export { DEVICE_HEADERS, type DeviceMeta } from "./device/registry";
14
+ export { requireAuth } from "./http/middleware";
15
+ export { AppleOAuthCredentials, AUTH_APPLE_CREDENTIALS, AUTH_GOOGLE_CREDENTIALS, AUTH_SESSION_SECRET, authSecretsRegistry, GoogleOAuthCredentials, } from "./instance/secrets";
16
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,KAAK,cAAc,EAAE,UAAU,EAAE,KAAK,eAAe,EAAE,IAAI,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAC7G,OAAO,EAAE,KAAK,MAAM,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC5D,OAAO,EAAE,KAAK,YAAY,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAChE,OAAO,EAAE,cAAc,EAAE,KAAK,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EACL,qBAAqB,EACrB,sBAAsB,EACtB,uBAAuB,EACvB,mBAAmB,EACnB,mBAAmB,EACnB,sBAAsB,GACvB,MAAM,oBAAoB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,10 @@
1
+ // SPDX-FileCopyrightText: 2026 Pithy
2
+ // SPDX-License-Identifier: MIT
3
+ import { DevicePlatform } from "./data/device.js";
4
+ import { authDatabase } from "./data/tables.js";
5
+ import { AUTH_APPLE_CREDENTIALS, AUTH_GOOGLE_CREDENTIALS, AUTH_SESSION_SECRET, AppleOAuthCredentials, GoogleOAuthCredentials, authSecretsRegistry } from "./instance/secrets.js";
6
+ import { AuthAuditActions } from "./audit/actions.js";
7
+ import { DEVICE_HEADERS } from "./device/registry.js";
8
+ import { requireAuth } from "./http/middleware.js";
9
+ import { AuthConfig, auth, isAuthCapability } from "./capability.js";
10
+ export { AUTH_APPLE_CREDENTIALS, AUTH_GOOGLE_CREDENTIALS, AUTH_SESSION_SECRET, AppleOAuthCredentials, AuthAuditActions, AuthConfig, DEVICE_HEADERS, DevicePlatform, GoogleOAuthCredentials, auth, authDatabase, authSecretsRegistry, isAuthCapability, requireAuth };