@plitzi/sdk-server 0.39.2 → 0.39.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 (66) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/README.md +49 -7
  3. package/dist/auth.d.ts +3 -2
  4. package/dist/auth.js +26 -107
  5. package/dist/cache.js +1 -1
  6. package/dist/chunks/{buildBody-W9D8ySNY.js → buildBody-BSC0UbjP.js} +352 -110
  7. package/dist/chunks/{core-TlrWmT4B.js → core-w7FIMpgv.js} +86 -4
  8. package/dist/chunks/{createServer-Bd_b7T3k.js → createServer-BQ0KE0Qu.js} +157 -34
  9. package/dist/chunks/{platform-DhdFYWm5.js → platform-C0AVlwpB.js} +2 -2
  10. package/dist/chunks/throttle-CRiZB6_A.js +330 -0
  11. package/dist/chunks/{token-B2uY9JzU.js → token-CBUubxtm.js} +1 -1
  12. package/dist/chunks/views/template.ejs +7 -0
  13. package/dist/core/auth/api/context.d.ts +4 -4
  14. package/dist/core/auth/api/values.d.ts +6 -0
  15. package/dist/core/auth/createAuth.d.ts +1 -1
  16. package/dist/core/auth/throttle.d.ts +54 -4
  17. package/dist/core/createServer.d.ts +1 -1
  18. package/dist/core/platform.d.ts +1 -1
  19. package/dist/core/services/iconFaces.d.ts +3 -0
  20. package/dist/core/services/llmsTxt.d.ts +15 -0
  21. package/dist/core/services/robotsTxt.d.ts +2 -8
  22. package/dist/core/services/securityTxt.d.ts +10 -0
  23. package/dist/handlers.js +1 -1
  24. package/dist/helpers/documentParts.d.ts +10 -0
  25. package/dist/helpers/paintedCookie.d.ts +15 -1
  26. package/dist/index.d.ts +1 -1
  27. package/dist/index.js +3 -3
  28. package/dist/modules/icons/glyphs.d.ts +21 -0
  29. package/dist/modules/icons/handler.d.ts +11 -0
  30. package/dist/modules/icons/spaceIcons.d.ts +26 -0
  31. package/dist/modules/rsc/connectorRscData.d.ts +4 -2
  32. package/dist/modules/rsc/resolveRscData.d.ts +4 -1
  33. package/dist/modules/ssr/csrfHint.d.ts +12 -0
  34. package/dist/modules/ssr/defaultFavicon.d.ts +1 -1
  35. package/dist/modules/ssr/spaceDocument.d.ts +8 -1
  36. package/dist/oauth.js +1 -1
  37. package/dist/platform.d.ts +1 -1
  38. package/dist/platform.js +1 -1
  39. package/dist/project.js +3 -3
  40. package/dist/spaces.js +1 -1
  41. package/dist/ssr.js +1 -1
  42. package/dist/types/config.d.ts +24 -0
  43. package/dist/types/index.d.ts +1 -1
  44. package/package.json +10 -8
  45. package/skills/plitzi-authoring/recipes/accordion.ts +3 -1
  46. package/skills/plitzi-authoring/recipes/carousel.ts +68 -63
  47. package/skills/plitzi-authoring/recipes/detail-page.ts +43 -33
  48. package/skills/plitzi-authoring/recipes/embed-and-svg.ts +16 -11
  49. package/skills/plitzi-authoring/recipes/every-few-seconds.ts +52 -42
  50. package/skills/plitzi-authoring/recipes/feature-flag.ts +7 -2
  51. package/skills/plitzi-authoring/recipes/filter-a-list.ts +39 -31
  52. package/skills/plitzi-authoring/recipes/forms-and-modals.ts +34 -28
  53. package/skills/plitzi-authoring/recipes/from-tailwind.ts +11 -6
  54. package/skills/plitzi-authoring/recipes/link-to-a-section.ts +11 -6
  55. package/skills/plitzi-authoring/recipes/link-with-data.ts +21 -16
  56. package/skills/plitzi-authoring/recipes/marquee.ts +17 -12
  57. package/skills/plitzi-authoring/recipes/plugin.ts +16 -10
  58. package/skills/plitzi-authoring/recipes/scroll-a-row.ts +30 -25
  59. package/skills/plitzi-authoring/recipes/server-data.ts +15 -10
  60. package/skills/plitzi-authoring/recipes/show-data.ts +32 -24
  61. package/skills/plitzi-authoring/recipes/style-a-page.ts +9 -4
  62. package/skills/plitzi-authoring/recipes/typed-data.ts +26 -21
  63. package/skills/plitzi-authoring/recipes/usable-without-sight.ts +16 -11
  64. package/skills/plitzi-authoring/reference/authoring-errors.md +3 -0
  65. package/skills/plitzi-authoring/reference/efficiency.md +2 -1
  66. package/dist/chunks/throttle-BH7JLIOF.js +0 -108
package/CHANGELOG.md CHANGED
@@ -1,5 +1,26 @@
1
1
  # @plitzi/sdk-server
2
2
 
3
+ ## 0.39.4
4
+
5
+ ### Patch Changes
6
+
7
+ - 35415a1: Released with every `@plitzi` package at this version. What changed in each, and what to do when you upgrade, is in
8
+ `@plitzi/cli`'s `CHANGELOG.md`: one copy of the notes, not one per package.
9
+ - Updated dependencies [35415a1]
10
+ - @plitzi/plitzi-sdk@0.39.4
11
+ - @plitzi/sdk-actions@0.39.4
12
+ - @plitzi/sdk-kernel@0.39.4
13
+ - @plitzi/sdk-shared@0.39.4
14
+
15
+ ## 0.39.3
16
+
17
+ ### Patch Changes
18
+
19
+ - @plitzi/plitzi-sdk@0.39.3
20
+ - @plitzi/sdk-actions@0.39.3
21
+ - @plitzi/sdk-kernel@0.39.3
22
+ - @plitzi/sdk-shared@0.39.3
23
+
3
24
  ## 0.39.2
4
25
 
5
26
  ### Patch Changes
package/README.md CHANGED
@@ -400,7 +400,9 @@ are built in and a fourth is `(req) => …` of your own, which is how a deployme
400
400
  its proxy sets or by a table nobody else has still gets everything below.
401
401
 
402
402
  **A space is chosen by host or credential, never by the page's path or query.** `getSpaceDeployment` is asked on every
403
- request, and what a page fetches after it — `/_plitzi/space/<hash>.json`, `/_plitzi/style/<hash>.css`, `/_action`,
403
+ request, and what a page fetches after it — `/_plitzi/space/<hash>.json`, `/_plitzi/space/part/<name>.json`,
404
+ `/_plitzi/style/<hash>.css`,
405
+ `/_plitzi/icons/…`, `/_action`,
404
406
  `/fn/…`, `/_realtime` — carries
405
407
  nothing of the page's address but its host: a space chosen by `?space=` or `/s/<id>/` renders its first page and then
406
408
  loses everything it asks for. Many spaces on one server are a sub-domain each (`wildcardSubdomain`).
@@ -669,9 +671,12 @@ some visitors may read in it: that is served by a server action whose `access` c
669
671
 
670
672
  Every space answers its own `/robots.txt` and `/sitemap.xml`, at the address it is asked on — its own domain or another:
671
673
 
672
- - `/robots.txt` is the space's `settings.robotsTxt` (`User-agent: *` / `Allow: /` when it says none), then — with
673
- `settings.blockAiCrawlers: true` — a `Disallow: /` for each crawler that trains AI models (`AI_CRAWLERS`), then
674
+ - `/robots.txt` is the space's `settings.robotsTxt` (`User-agent: *` / `Allow: /` when it says none), then a
675
+ `Disallow: /` for each AI crawler of the kinds the space keeps out — `settings.blockAiCrawlers: ['training',
676
+ 'assistants', 'search']`, any of them (`AI_CRAWLERS` in `@plitzi/sdk-shared/schema`) — then
674
677
  `Sitemap: <origin>/sitemap.xml` unless its own text names a sitemap.
678
+ - `/.well-known/security.txt` is the space's `settings.securityTxt` as written (RFC 9116: `Contact:`, `Expires:`), and
679
+ 404 when it says none — the rest of `/.well-known/` stays reserved.
675
680
  - `/sitemap.xml` lists every page a search engine may read (`sitemapPaths` in `@plitzi/sdk-shared/navigation`): not a
676
681
  page only signed-in visitors or a role may open, one whose slug takes a parameter or is `*`, one that says `noindex` or
677
682
  one behind a feature flag.
@@ -774,8 +779,8 @@ sweep timer is stopped when `server.close()` is called.
774
779
 
775
780
  A space's compiled stylesheet (`style.cache`) holds every page's rules — on a large space most of the page: the
776
781
  Plitzi dashboard's was 429 KB of a 496 KB document, compressed again on every response. A server-rendered page links it
777
- instead, as `/_plitzi/style/<hash>.css`, and carries only what is this request's — the variables, the custom CSS — in
778
- the page. The file is compressed once, kept by the browser for good under its name, and answered by any replica from
782
+ instead, as `/_plitzi/style/<hash>.css` — the compiled rules and the space's custom CSS after them — and carries only
783
+ what is this request's, the variables, in the page. The file is compressed once, kept by the browser for good under its name, and answered by any replica from
779
784
  the space as the request resolves it, as the space document is: a name that is no longer the stylesheet's (the space
780
785
  changed since the page was drawn) answers the current one, `no-store`. Taking it out of the page made the dashboard's
781
786
  render ~60% cheaper in requests a second.
@@ -788,6 +793,43 @@ deployment's own `templateFn`, which does not know to link it, and when a `{{ to
788
793
  variables as each request resolves them. A client-side render (no SSR) receives the stylesheet as it always did, and
789
794
  draws it; a page whose stylesheet the browser comes to draw itself (new documents in place) drops the linked copy.
790
795
 
796
+ ### The space's icons, cut from the font
797
+
798
+ A page draws its icons from Font Awesome's faces (`plitzi-sdk-icons.css`, its fonts beside it), whose solid face alone
799
+ is 119 KB. Where the stylesheet is linked, the head also declares the glyphs the space names as faces of their own,
800
+ after the whole font's — `@font-face { …; src: url(/_plitzi/icons/<hash>-solid.woff2); unicode-range: … }` — so the
801
+ browser fetches those few glyphs and nothing else: Plitzi's website names 110, 9 KB. A glyph is named wherever the
802
+ document says it (an attribute, a component's props, both sides of a binding's template); one named only by data the
803
+ space reads at run time is drawn from the whole font, which stays declared before them. The faces are cut on the first
804
+ request for them (`subset-font`, loaded only then), answered by any replica from the space as the request resolves it,
805
+ kept for good under their name; an older name answers the space's glyphs as they are, `no-store`. A bundler that
806
+ leaves out what loads its own files keeps `subset-font` out too: it reads its WebAssembly beside itself.
807
+
808
+ ### A proxy in front of it
809
+
810
+ A page is hydrated over the HTML the server sent: a proxy or CDN in front of the page server that rewrites it — an
811
+ edge's email obfuscation (Cloudflare's *Email Address Obfuscation*), a minifier, an injected script — has React find
812
+ HTML it did not render (error #418 in production) and the page's script policy refuse what was added. Leave the HTML
813
+ alone at the edge: turn those features off for the hosts the server answers.
814
+
815
+ ### The space in parts
816
+
817
+ A page the server draws is sent the space it hydrates with beside it, at `/_plitzi/space/<hash>.json` — and not the
818
+ whole of it: a shell (the definition, the settings, the variables, every page and layout element itself, so the space
819
+ routes as the whole did) with that page's own elements and its layouts' in it. `schema.parts` names the rest, a part per
820
+ page and per layout, each at `/_plitzi/space/part/<name>.json`, named by its content and kept by the browser for good
821
+ (`immutable`, `public` unless a session asked). A navigation fetches what its page needs before it goes, a link fetches
822
+ it ahead once it is on screen, and a part that does not come loads the address from the server instead — the page is
823
+ never drawn without its elements. The pages at the same address (one per access level), and the page drawn in place of
824
+ a withheld one (`settings.withheldPage`), travel together.
825
+
826
+ A part is answered from the space as this visitor may be sent it (`withholdPages`): a page they may not see has none,
827
+ and a layout only such pages are drawn in is named `''` — the server's to draw, so a link to one of those pages loads
828
+ it from there. When somebody signs in or out on the page, what its document kept from the visitor it was sent for is
829
+ loaded from the server again. Whole for a draft, a page named by a token, a deployment's own `templateFn`, a URL that is
830
+ no page, a space with one page, and one that says `settings.wholeDocument` — for pages that read each other's elements.
831
+ The SDK alone, the builder and the MCP read the whole document, which has no `parts`.
832
+
791
833
  ### A page that renders the space itself
792
834
 
793
835
  `GET /_plitzi/space.json` answers the space as it is now to a page the server did not draw — a site published as
@@ -1323,7 +1365,7 @@ There is no third argument for the security-relevant parts, on purpose: password
1323
1365
  is rate-limited in memory, mailed links expire, and CSRF is on. Each of those used to be an option with no default —
1324
1366
  which meant the ordinary deployment went without, because nobody configures what they have not read about. Supply
1325
1367
  `api.hashPassword`/`verifyPassword` to keep an existing algorithm (a store of bcrypt hashes needs bcrypt), and
1326
- `api.rateLimit` to put one counter behind a fleet. Name the terms accounts are opened under — `api.terms: { version }`
1368
+ `api.rateLimit: createRateLimit({ counts: redisThrottleCounts(redis) })` to give several replicas one count. Name the terms accounts are opened under — `api.terms: { version }`
1327
1369
  — and `/auth/signup` refuses a sign-up without `acceptedTerms: true` (400, `field: 'acceptedTerms'`) and hands
1328
1370
  `createAccount` the version accepted and when (`termsAccepted`), for the account store to keep; named none, sign-up asks
1329
1371
  for nothing more.
@@ -1481,7 +1523,7 @@ and every refusal names a machine-readable `reason`, so a client can tell "renew
1481
1523
  |---|---|
1482
1524
  | `cookie` | Name, domain, `SameSite`, `Secure`, the refresh path, the hint suffix. Defaults derive from the request host: this machine — loopback, a `.localhost` name, a private network address, its mDNS name (`studio.local`), as a phone on the Wi-Fi opens it over http — gets `SameSite=Lax` with no `Secure` and no `Domain`; any other host `SameSite=Lax; Secure`, shared across its sub-domains — which are one site, so `Lax` reaches them all. `sameSite: 'none'` for a deployment whose pages need the session inside another site's page (a space in an iframe there); a domain that lets other sites frame it (`security.frameAncestors` of its deployment) gets it on that host alone, over https. A deployment that serves spaces of different people on sub-domains of one domain (`*.plitzi.app`) answers `domain` per host — its own hosts `registrableDomain(hostname)`, a space's host `undefined` — or one space's visitor session reaches every other's |
1483
1525
  | `api.password` | What a password has to be. `minLength` defaults to 8 (NIST SP 800-63B's floor); `validate` is where a breach-list lookup or a strength estimator goes. Applied wherever one is set — signing up, resetting, changing |
1484
- | `api.rateLimit` | May this attempt proceed? **Defaults to an in-memory sliding window**, so no deployment is unthrottled by omission; supply one to put a single counter behind a whole fleet. Called before the password is checked, so a throttled attempt costs no hash |
1526
+ | `api.rateLimit` | May this attempt proceed? **Defaults to an in-memory sliding window**, so no deployment is unthrottled by omission. Sign-in is counted three ways — the account from one address (10 in 5 min), the address over any accounts (30), the account from anywhere (100) — so a stranger cannot lock an owner out and a sprayed password is still slowed. Several replicas share one count with `createRateLimit({ counts: redisThrottleCounts(redis, { prefix }) })` (`@plitzi/sdk-server/auth`): `redis` is anything with ioredis's `eval`, each attempt one script over its counts — atomic, so a burst sent at once cannot read an empty window together — and `prefix` keeps a `{hash tag}` on a Redis Cluster. Called before the password is checked, so a throttled attempt costs no hash |
1485
1527
  | `api.adminPermission` | The global capability the `/auth/admin/*` routes require. Default `userManage` |
1486
1528
  | `api.impersonationPermission` | The capability it takes to obtain a session **as** another account, and the switch that offers the flow at all — **absent, there is no impersonation**. Its own permission on purpose: suspending an account and becoming one are not the same grant |
1487
1529
  | `api.onEvent` | Every act worth recording — sign-ins, failures, password changes, admin actions — as a `SecurityEvent`. An audit trail, a webhook and an alert are the same feed. Never awaited and never able to fail a request |
package/dist/auth.d.ts CHANGED
@@ -4,7 +4,7 @@
4
4
  * `createAuth`, which assembles them over the kernel's checks and is what almost every deployment wants.
5
5
  *
6
6
  * Checking who a request is — the tokens (`@plitzi/sdk-kernel/tokens`), the session cookies, the identity resolver,
7
- * CSRF, the RBAC checks (`@plitzi/sdk-kernel/identity`) — is the kernel's (RFC 0032, D3): a worker checks credentials
7
+ * CSRF, the RBAC checks (`@plitzi/sdk-kernel/identity`) — is the kernel's (docs/en/server-packages.md, D3): a worker checks credentials
8
8
  * and signs nobody in, so it runs that half without this one.
9
9
  *
10
10
  * ```ts
@@ -25,7 +25,8 @@ export { isDocumentNavigation, renewForNavigation } from './core/auth/renewal';
25
25
  export type { RenewalOptions } from './core/auth/renewal';
26
26
  export type { RedirectPolicyConfig } from './core/auth/redirects';
27
27
  export { applySessionOutcome, authPolicyRules, authRoutes } from './core/auth/routes';
28
- export { createMemoryRateLimit } from './core/auth/throttle';
28
+ export { createRateLimit, memoryThrottleCounts, redisThrottleCounts } from './core/auth/throttle';
29
+ export type { ThrottleCounter, ThrottleCounts, ThrottleRedis, ThrottleVerdict } from './core/auth/throttle';
29
30
  export { generateRecoveryCodes, generateTotpSecret, normalizeRecoveryCode, randomCode, totpCode, totpStep, totpUri, verifyTotp } from './core/auth/totp';
30
31
  export type { Auth, AuthConfig } from './core/auth/createAuth';
31
32
  export type { AuthApi, AuthApiConfig, AuthOutcome, ExchangeResult, PasswordPolicy, ThrottleAttempt, ThrottledAction } from './core/auth/api';
package/dist/auth.js CHANGED
@@ -1,98 +1,10 @@
1
- import { n as createMemoryRateLimit, r as fleetRateLimit } from "./chunks/throttle-BH7JLIOF.js";
1
+ import { a as redisThrottleCounts, c as STATUSES, d as clientOf, f as deniedReason, g as refuse, h as profileOf, i as memoryThrottleCounts, l as asString, m as now, n as createRateLimit, o as LIFETIME, p as destinationOf, r as fleetRateLimit, s as NOT_OFFERED, u as asText } from "./chunks/throttle-CRiZB6_A.js";
2
2
  import { a as authRoutes, i as authPolicyRules, n as renewForNavigation, r as applySessionOutcome, t as isDocumentNavigation } from "./chunks/renewal-D98v6-Jd.js";
3
- import { forwardedIp } from "@plitzi/sdk-kernel/http";
4
3
  import { serverLog } from "@plitzi/sdk-kernel/log";
5
4
  import { authFailureMessage, checkPermission, createAuthorizer, createCarriers, createCsrf, createIdentity, createSessionCookies, generateToken, hashPassword, presentedOrigin, sessionCookieParams, verifyPassword } from "@plitzi/sdk-kernel/identity";
6
5
  import { createHash, createHmac, createPublicKey, randomBytes, randomInt, timingSafeEqual } from "node:crypto";
7
6
  import { createTokens, userIdOf } from "@plitzi/sdk-kernel/tokens";
8
7
  import jwt from "jsonwebtoken";
9
- // src/core/auth/api/values.ts
10
- var clientOf = (carrier) => {
11
- if (!carrier) return;
12
- const userAgent = carrier.headers["user-agent"];
13
- const ip = carrier.ip || forwardedIp(carrier.headers);
14
- const client = {
15
- ...typeof userAgent === "string" && userAgent ? { userAgent } : {},
16
- ...ip ? { ip } : {},
17
- ...carrier.hostname ? { host: carrier.hostname.toLowerCase() } : {}
18
- };
19
- return client.userAgent || client.ip || client.host ? client : void 0;
20
- };
21
- /**
22
- * The account store, as auth needs to see it. Every method is optional except the three the session cycle cannot do
23
- * without, and **what is absent decides what this server offers**: a deployment with no `createAccount` has no
24
- * signup, and its route answers 404 rather than failing at runtime. That rule is what lets one server serve a
25
- * deployment with its own user table and one that signs everybody in through an external provider.
26
- */
27
- var refuse = (status, error, reason) => ({
28
- ok: false,
29
- status,
30
- body: reason ? {
31
- error,
32
- reason
33
- } : { error }
34
- });
35
- var NOT_OFFERED = refuse(404, "Not found");
36
- /**
37
- * A field from a request body, as a string. Numbers count: JSON carries an all-digits password as a number, and a
38
- * client that sends one has supplied a password — refusing it as "credentials are required" is a lie about what
39
- * arrived. Objects and arrays do not, since `[object Object]` is not a value anybody sent.
40
- */
41
- var asText = (value) => {
42
- if (typeof value === "string") return value;
43
- return typeof value === "number" && Number.isFinite(value) ? String(value) : "";
44
- };
45
- var asString = (value) => asText(value).trim();
46
- /**
47
- * The destination a caller named, for a mail to carry — or nothing at all.
48
- *
49
- * Carried, not judged: the kernel has no redirect policy, and the link it ends up in is composed by the deployment,
50
- * which vets it there (`createRedirectPolicy`). Absent rather than empty when there is none, so a mail template never
51
- * has to know that `''` means "nowhere".
52
- */
53
- var destinationOf = (value) => {
54
- const redirect = asString(value);
55
- return redirect ? { redirect } : {};
56
- };
57
- var now = () => Math.floor(Date.now() / 1e3);
58
- var HOUR = 3600;
59
- /**
60
- * How long the things this server mails or hands out stay good for. Constants rather than configuration: each is a
61
- * security answer with one sensible value, and an option here is a question every deployment has to work out an
62
- * answer to before it can start.
63
- */
64
- var LIFETIME = {
65
- /** A code from an email. Long enough to go and find it, short enough that a stolen one is worthless. */
66
- signInCode: 600,
67
- /** A reset link IS a password, and it sits in an inbox, a mail archive, a forwarded ticket. */
68
- resetLink: HOUR,
69
- /** Confirming an address is not a credential in the same way, and people read their mail tomorrow. */
70
- confirmLink: 24 * HOUR,
71
- /** A borrowed session — see `admin.impersonate`. Short, and it cannot renew. */
72
- impersonation: 900
73
- };
74
- var STATUSES = [
75
- "active",
76
- "inactive",
77
- "blocked"
78
- ];
79
- /**
80
- * Why an account may not hold a session, when it may not.
81
- *
82
- * `active` answers whether it may sign in at all; `verified` answers whether its owner can do anything about that.
83
- * A deployment where confirming an address is what makes an account active — Plitzi is one — refuses both through
84
- * the same flag, so a screen told only `inactive` has to tell somebody whose address has simply never answered that
85
- * their password was wrong. It was, in fact, right.
86
- */
87
- var deniedReason = (account) => account && !account.verified ? "unverified" : "inactive";
88
- /** An account as it may be shown. Never the password hash, and never the credentials — not even to an admin. */
89
- var profileOf = (account) => ({
90
- id: account.id,
91
- username: account.username,
92
- email: account.email,
93
- active: account.active,
94
- verified: account.verified
95
- });
96
8
  // src/core/auth/api/accounts.ts
97
9
  /** An account made and recovered: signing up, verifying the address, forgetting and resetting the password. */
98
10
  var accountsFlows = ({ adapters, hashPassword, generateToken, verifyOnSignup, terms, record, mintLink, linkExpired, deliver, throttled, rejectPassword, capabilities }) => ({
@@ -156,7 +68,7 @@ var accountsFlows = ({ adapters, hashPassword, generateToken, verifyOnSignup, te
156
68
  if (!verifyOnSignup && capabilities.emailVerification && adapters.setValidationToken) {
157
69
  const validationToken = mintLink(generateToken(), LIFETIME.confirmLink);
158
70
  await adapters.setValidationToken(account.id, validationToken);
159
- await deliver({
71
+ deliver({
160
72
  to: email,
161
73
  template: "validation",
162
74
  data: {
@@ -191,7 +103,7 @@ var accountsFlows = ({ adapters, hashPassword, generateToken, verifyOnSignup, te
191
103
  if (account) {
192
104
  const resetToken = mintLink(generateToken(), LIFETIME.resetLink);
193
105
  await adapters.setResetToken?.(account.id, resetToken);
194
- await deliver({
106
+ deliver({
195
107
  to: account.email,
196
108
  template: "password-reset",
197
109
  data: {
@@ -249,7 +161,7 @@ var accountsFlows = ({ adapters, hashPassword, generateToken, verifyOnSignup, te
249
161
  if (account && !account.verified) {
250
162
  const validationToken = mintLink(generateToken(), LIFETIME.confirmLink);
251
163
  await adapters.setValidationToken?.(account.id, validationToken);
252
- await deliver({
164
+ deliver({
253
165
  to: account.email,
254
166
  template: "validation",
255
167
  data: {
@@ -530,7 +442,7 @@ var normalizeRecoveryCode = (code) => code.trim().toUpperCase().replace(/[^A-Z0-
530
442
  // src/core/auth/api/context.ts
531
443
  /** What every flow of the auth API shares: the adapters and the settings, read once, and the steps they take alike. */
532
444
  var createAuthContext = ({ tokens, identity, adapters, config = {} }) => {
533
- const { verifyPassword: verifyPassword$1 = verifyPassword, hashPassword: hashPassword$1 = hashPassword, generateToken: generateToken$1 = generateToken, verifyOnSignup = false, terms, adminPermission = "userManage", impersonationPermission, password: policy = {}, rateLimit = fleetRateLimit() ?? createMemoryRateLimit(), onMailError, onEvent, mfaIssuer, csrf } = config;
445
+ const { verifyPassword: verifyPassword$1 = verifyPassword, hashPassword: hashPassword$1 = hashPassword, generateToken: generateToken$1 = generateToken, verifyOnSignup = false, terms, adminPermission = "userManage", impersonationPermission, password: policy = {}, rateLimit = fleetRateLimit() ?? createRateLimit(), onMailError, onEvent, mfaIssuer, csrf } = config;
534
446
  /** Never awaited, never able to throw: a logging outage must not become an authentication outage. */
535
447
  const record = (event) => {
536
448
  if (!onEvent) return;
@@ -563,22 +475,29 @@ var createAuthContext = ({ tokens, identity, adapters, config = {} }) => {
563
475
  /** Recovery codes are high-entropy, so a fast digest is right — scrypt ten times per sign-in would not be. */
564
476
  const digestRecoveryCode = (code) => createHash("sha256").update(normalizeRecoveryCode(code)).digest("hex");
565
477
  /**
566
- * Sends, and never fails the flow if it cannot.
478
+ * Sends, and never fails the flow if it cannot — nor holds it while it does.
567
479
  *
568
480
  * Every one of these goes out AFTER something has already been committed — an account created, an address
569
481
  * changed, a reset token stored. Letting the mail provider decide whether that request succeeded turns an
570
482
  * outage at Brevo into a 500 on a change that did happen, which is the worst of both: the caller is told it
571
483
  * failed and retries against the new state. Reported instead, and the person can ask for another.
484
+ *
485
+ * Started, not awaited: the answer never depended on it, and waiting for it was the provider's round trip on every
486
+ * sign-up — and on a password reset, a slower answer for an address that has an account than for
487
+ * one that has not, which is how a stranger tells them apart.
572
488
  */
573
- const deliver = async (message) => {
574
- try {
575
- await adapters.sendMail?.(message);
576
- } catch (error) {
577
- (onMailError ?? ((cause) => serverLog.error("auth", "could not send mail", cause)))(error, {
578
- to: message.to,
579
- template: message.template
580
- });
581
- }
489
+ const deliver = (message) => {
490
+ const report = onMailError ?? ((cause) => serverLog.error("auth", "could not send mail", cause));
491
+ Promise.resolve().then(() => adapters.sendMail?.(message)).catch((error) => {
492
+ try {
493
+ report(error, {
494
+ to: message.to,
495
+ template: message.template
496
+ });
497
+ } catch (reporting) {
498
+ serverLog.error("auth", "could not send mail, nor report it", reporting);
499
+ }
500
+ });
582
501
  };
583
502
  /**
584
503
  * Checked before the password is, so a throttled attempt costs no hash — which is the difference between a rate
@@ -818,7 +737,7 @@ var factorsFlows = ({ tokens, adapters, verifyPassword, mfaIssuer, record, diges
818
737
  expiresAt: now() + LIFETIME.signInCode,
819
738
  userId: account.id
820
739
  });
821
- await deliver({
740
+ deliver({
822
741
  to: account.email,
823
742
  template: "signin-code",
824
743
  data: {
@@ -1027,7 +946,7 @@ var profileFlows = ({ adapters, verifyPassword, hashPassword, generateToken, rec
1027
946
  if (parking && adapters.setPendingEmail) {
1028
947
  const confirmationToken = mintLink(generateToken(), LIFETIME.confirmLink);
1029
948
  await adapters.setPendingEmail(actor.id, email, confirmationToken);
1030
- await deliver({
949
+ deliver({
1031
950
  to: email,
1032
951
  template: "email-change",
1033
952
  data: {
@@ -1049,7 +968,7 @@ var profileFlows = ({ adapters, verifyPassword, hashPassword, generateToken, rec
1049
968
  if (changingEmail && capabilities.emailVerification && adapters.setValidationToken) {
1050
969
  const validationToken = mintLink(generateToken(), LIFETIME.confirmLink);
1051
970
  await adapters.setValidationToken(actor.id, validationToken);
1052
- await deliver({
971
+ deliver({
1053
972
  to: account.email,
1054
973
  template: "validation",
1055
974
  data: {
@@ -2320,4 +2239,4 @@ var createSocialAuth = ({ config, adapters, providers: configured, customProvide
2320
2239
  }
2321
2240
  };
2322
2241
  };
2323
- export { BUILT_IN_PROVIDERS, OAuthFailure, applySessionOutcome, authPolicyRules, authRoutes, createAuth, createAuthApi, createMemoryRateLimit, createOidcProvider, createRedirectPolicy, createSocialAuth, discoverOidc, generateRecoveryCodes, generateTotpSecret, isDocumentNavigation, normalizeRecoveryCode, randomCode, renewForNavigation, requestProfileJson, totpCode, totpStep, totpUri, verifyTotp };
2242
+ export { BUILT_IN_PROVIDERS, OAuthFailure, applySessionOutcome, authPolicyRules, authRoutes, createAuth, createAuthApi, createOidcProvider, createRateLimit, createRedirectPolicy, createSocialAuth, discoverOidc, generateRecoveryCodes, generateTotpSecret, isDocumentNavigation, memoryThrottleCounts, normalizeRecoveryCode, randomCode, redisThrottleCounts, renewForNavigation, requestProfileJson, totpCode, totpStep, totpUri, verifyTotp };
package/dist/cache.js CHANGED
@@ -1 +1 @@
1
- export { nt as DEFAULT_IGNORED_QUERY_PARAMS, k as createCacheInvalidator, t as createRedisPageStore } from "./chunks/core-TlrWmT4B.js";
1
+ export { at as DEFAULT_IGNORED_QUERY_PARAMS, M as createCacheInvalidator, t as createRedisPageStore } from "./chunks/core-w7FIMpgv.js";