@kurtbruns/kestrel 1.17.0 → 1.18.0
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/.dev.vars.example +10 -0
- package/CHANGELOG.md +30 -1
- package/bin/kestrel.mjs +1 -1
- package/cli/dev.mjs +3 -3
- package/cli/init.mjs +98 -4
- package/dist/public/dashboard/app.js +288 -286
- package/dist/public/dashboard/app.js.map +4 -4
- package/dist/public/dashboard/index.html +6 -3
- package/dist/public/dashboard/styles.css +10 -0
- package/dist/worker/index.js +5606 -5095
- package/docs/README.md +5 -3
- package/docs/get-started/02-deploy.md +24 -20
- package/docs/get-started/03-access.md +9 -5
- package/docs/get-started/04-aws-account.md +68 -0
- package/docs/get-started/{04-ses.md → 05-ses.md} +89 -92
- package/docs/get-started/06-production-access.md +64 -0
- package/docs/get-started/{05-verify.md → 07-verify.md} +16 -26
- package/docs/get-started/{06-go-live.md → 08-go-live.md} +2 -2
- package/docs/guides/01-allow-claude.md +1 -1
- package/docs/guides/02-automate.md +1 -1
- package/docs/guides/03-notifications.md +3 -3
- package/docs/guides/07-upgrade.md +4 -4
- package/docs/guides/09-as-your-list-grows.md +8 -18
- package/docs/publishing/02-sending-rules.md +2 -2
- package/docs/publishing/03-name-your-publication.md +2 -0
- package/docs/publishing/04-write-a-post.md +1 -1
- package/docs/publishing/06-troubleshooting.md +11 -7
- package/docs/publishing/09-share-your-subscribe-link.md +1 -1
- package/docs/publishing/10-check-your-setup.md +4 -2
- package/docs/reference/01-configuration.md +14 -12
- package/docs/reference/02-sending-domain-dns.md +4 -4
- package/migrations/0015_provider_account.sql +18 -0
- package/package.json +1 -1
- package/template/claude/CLAUDE.md +3 -3
- package/template/wrangler.jsonc +1 -1
|
@@ -1,277 +1,278 @@
|
|
|
1
1
|
// GENERATED by scripts/build-client.mjs from client/ — edit the source there, never this file.
|
|
2
|
-
"use strict";(()=>{function Fn(e){if(!e||typeof e!="object")return null;let t=e;return t.error!=="unauthorized"?null:t.reason==="access_not_configured"||t.reason==="access_unidentified"?t.reason:null}function so(e){let t=document.getElementById(e);if(!t)throw new Error(`the admin page has no #${e}`);return t}var fe=so("app"),oo=so("identity"),io=so("toasts"),Ci=document.getElementById("navToggle"),to=document.getElementById("navScrim");function an(e){document.body.classList.toggle("nav-open",e),Ci?.setAttribute("aria-expanded",e?"true":"false"),to&&(to.hidden=!e)}var rn=document.getElementById("navCollapse"),no=null;function Xl(){return window.innerWidth<540?"full":no==="collapsed"?"rail":no==="expanded"?"full":window.innerWidth<=1024?"rail":"full"}function Xs(){let e=Xl();if(document.documentElement.dataset.nav=e,!rn)return;let t=e!=="rail",n=t?"Collapse sidebar":"Expand sidebar";rn.setAttribute("aria-expanded",t?"true":"false"),rn.setAttribute("aria-label",n),rn.setAttribute("title",n)}var eo=0,Ri=0;function Ai(){Ci?.addEventListener("click",()=>an(!document.body.classList.contains("nav-open"))),to?.addEventListener("click",()=>an(!1)),document.querySelector(".sidebar")?.addEventListener("click",e=>{e.target instanceof Element&&e.target.closest("a")&&an(!1)}),rn?.addEventListener("click",()=>{no=document.documentElement.dataset.nav!=="rail"?"collapsed":"expanded",Xs()}),window.addEventListener("resize",()=>{document.body.classList.add("nav-resizing"),clearTimeout(Ri),Ri=setTimeout(()=>{document.body.classList.remove("nav-resizing")},200),!eo&&(eo=requestAnimationFrame(()=>{eo=0,Xs()}))}),Xs()}var qn=null,jn=null,Wn="Kestrel";function se(e,t){e.aborted||(document.title=t.trim()?`${t} - ${Wn}`:Wn)}function ee(e){qn?.abort(),jn=null;let t=new AbortController;qn=t,document.title=Wn;let n=document.createElement("div");n.className="view",fe.replaceChildren(n);let s;try{s=Promise.resolve(e(n,t.signal))}catch(i){s=Promise.reject(i)}return s.then(i=>{!t.signal.aborted&&i&&(jn=i)},i=>{if(!t.signal.aborted)throw i})}function Ht(){qn?.abort(),qn=null,jn=null,document.title=Wn,fe.replaceChildren()}function Vn(){return jn}function mt(e,t,n){if(n.aborted)return;let s=setInterval(t,e);n.addEventListener("abort",()=>clearInterval(s),{once:!0})}function ft(e,t,n){if(n.aborted)return;let s=()=>clearTimeout(i),i=setTimeout(()=>{n.removeEventListener("abort",s),t()},Math.max(0,e-Date.now()));n.addEventListener("abort",s,{once:!0})}function Hi(e,t,n){let s=()=>{if(n.aborted)return;let i=()=>clearTimeout(a),a=setTimeout(async()=>{n.removeEventListener("abort",i);let r=!0;try{r=await t()??!0}catch(l){ec(l)||reportError(l)}r!==!1&&s()},e);n.addEventListener("abort",i,{once:!0})};s()}function Pt(e,t){if(e.aborted){t();return}e.addEventListener("abort",t,{once:!0})}function ec(e){return e instanceof Error&&(e.name==="AbortError"||e.name==="ApiError")}function c(e,t=document){let n=t.querySelector(e);if(!n)throw new Error(`no element matches ${e}`);return n}function I(e,t=document){return[...t.querySelectorAll(e)]}var tc={"&":"&","<":"<",">":">",'"':""","'":"'"};function X(e){return String(e).replace(/[&<>"']/g,t=>tc[t]??t)}var ht=class{markup;constructor(t){this.markup=t,Object.freeze(this)}toString(){return this.markup}};function Mi(e){return e instanceof ht?e.markup:e==null||e===!1?"":Array.isArray(e)?e.map(Mi).join(""):X(e)}var nc=/=\s*$/;function o(e,...t){let n=Pi(e,0);for(let s=0;s<t.length;s++){let i=t[s];if(!(i instanceof ht)&&nc.test(n))throw new Error("html: an interpolation in an unquoted attribute value cannot be made safe; quote it");n+=Mi(i)+Pi(e,s+1)}return new ht(n)}function Pi(e,t){let n=e[t];if(n===void 0)throw new Error(`html: invalid escape sequence in template text near ${JSON.stringify(e.raw[t])}`);return n}function j(e){return new ht(e)}function h(e,t){if(!(t instanceof ht))throw new Error("setHtml: expected Html; build it with html`\u2026` or vouch for it with unsafeHtml()");e.innerHTML=t.markup}var sc="https://getkestrel.dev/docs/access/",oc="/cdn-cgi/access/logout";function Kn(e){if(fe.querySelector(".access-wall"))return;Ht(),document.body.classList.add("signed-out");let t=o`<p class="hint"><a href="${sc}" target="_blank" rel="noopener">Lock the dashboard with Access <span aria-hidden="true">↗</span><span class="visually-hidden"> (opens in a new tab)</span></a></p>`;e==="access_unidentified"?(h(fe,o`<div class="card auth-wall access-wall" role="alert"><h2 tabindex="-1">Access let you in, but didn’t say who you are</h2><p>Cloudflare Access sent neither an email address nor a service token, and Kestrel needs one of them to tell who is asking, so it doesn’t let this sign-in in. Some other kind of Access policy, or a login method that gives no email, let it through.</p><p>Kestrel accepts two kinds of Access policy: an Allow policy on people’s emails, and a Service Auth policy on a service token. Sign out, then sign in through one of them.</p>${t}<button id="access-signout" class="primary">Sign out</button></div>`),c("#access-signout",fe).onclick=()=>location.assign(oc)):(h(fe,o`<div class="card auth-wall access-wall"><h2 tabindex="-1">The editor is locked until you set up Access</h2><p>Until Cloudflare Access is in front of the editor, the app can’t tell who is asking, so it lets no one in. On a new deployment, that’s expected. Your public pages work as usual.</p>${t}<button id="access-reload" class="primary">Reload</button></div>`),c("#access-reload",fe).onclick=()=>location.reload()),c(".access-wall h2",fe).focus()}var Ii="Kestrel-Client",ln="editor",Gn="claude-code",zn="claude";function Yn(e){if(!e||typeof e!="object")return null;let t=e;return t.error==="schema_behind"&&typeof t.message=="string"?{message:t.message}:t.error!=="invalid_config"||typeof t.variable!="string"?null:{variable:t.variable,message:typeof t.message=="string"?t.message:`${t.variable} is refused`}}var ic="https://getkestrel.dev/docs/configuration/",rc={PROVIDER:"vars",ALLOW_FAKE_PROVIDER:"vars",APP_ORIGIN:"vars",AWS_REGION:"vars",FROM_ADDRESS:"vars",SENDING_DOMAIN:"vars",ARCHIVE_BASE_PATH:"vars",SES_MAX_SEND_RATE:"vars",SUBREQUEST_BUDGET:"vars",MIN_LEAD_SECONDS:"vars",ARCHIVE_ORIGIN:"vars",MEDIA_PUBLIC_BASE:"vars",NOTIFY_FROM:"vars",ACCESS_TEAM_DOMAIN:"secrets",ACCESS_AUD:"secrets",ACCESS_ALLOWED_EMAILS:"secrets",AWS_ACCESS_KEY_ID:"secrets",AWS_SECRET_ACCESS_KEY:"secrets",SNS_TOPIC_ARN:"secrets",SES_CONFIGURATION_SET:"secrets",SIMULATE_SENDS:"what-the-app-refuses"},ac="what-the-app-refuses";function lc(e){return`${ic}#${rc[e]??ac}`}function Zn(e){if(fe.querySelector(".config-wall"))return;Ht(),document.body.classList.add("signed-out");let{variable:t}=e,n=t?"A setting needs fixing":"The database needs updating",s=t?o`<p class="hint"><a href="${lc(t)}" target="_blank" rel="noopener">${t} in the Configuration reference <span aria-hidden="true">↗</span><span class="visually-hidden"> (opens in a new tab)</span></a></p>`:"";h(fe,o`<div class="card auth-wall config-wall" role="alert"><h2 tabindex="-1">${n}</h2><p>Kestrel won’t run until it’s fixed, and nothing is sent in the meantime.</p><p class="config-wall-problem">${e.message}</p>${s}<button id="config-reload" class="primary">Reload</button></div>`),c("#config-reload",fe).onclick=()=>location.reload(),c(".config-wall h2",fe).focus()}var Jn="kestrel_token",Q={token:localStorage.getItem(Jn)||"",session:null,appConfig:null};function Oi(e){Q.token=(e||"").trim();try{Q.token?localStorage.setItem(Jn,Q.token):localStorage.removeItem(Jn)}catch{}}function ro(){return{[Ii]:ln,...Q.token?{Authorization:`Bearer ${Q.token}`}:{}}}function Di(){let e=Q.session;if(e?.auth.mode==="access"){let t=e.principal,n=t.email||(t.kind==="service"?"Service token":"Signed in");h(oo,o`<span class="who" title="${n}">${n}</span><a class="ghost" href="/cdn-cgi/access/logout" title="Sign out"><svg class="signout-icon" aria-hidden="true"><use href="#i-signout"/></svg><span class="signout-label">Sign out</span></a>`)}else h(oo,o`<span class="who dev" title="Local dev: sign-in is skipped on localhost">Local dev</span>`)}function ao(){fe.querySelector(".reauth-wall")||(Ht(),document.body.classList.add("signed-out"),h(fe,o`<div class="card auth-wall reauth-wall"><h2 tabindex="-1">Session expired</h2><p class="hint">Your access session ended. Sign in again to continue.</p><button id="reauth" class="primary">Sign in</button></div>`),c("#reauth",fe).onclick=()=>location.reload(),c(".reauth-wall h2",fe).focus())}async function Ni(){try{let e=await fetch("/api/dev/token?kind=human");if(e.ok)return Oi((await e.json()).token),!0}catch{}return!1}async function Bi(){try{return await fetch("/api/whoami",{headers:ro(),redirect:"manual"})}catch{return null}}async function Ui(){Q.token||await Ni();let e=await Bi();if(!e?.ok&&Q.token&&(Oi(""),await Ni()&&(e=await Bi())),e?.ok)return await e.json();let t=e?await e.json().catch(()=>null):null,n=Yn(t),s=Fn(t);return n?Zn(n):s?Kn(s):ao(),null}var te=class extends Error{constructor(n,s,i=null){super(n);this.status=s;this.data=i;this.name="ApiError"}status;data;get code(){let n=this.data;return typeof n?.error=="string"?n.error:null}get field(){let n=this.data;return typeof n?.field=="string"?n.field:null}},cc="Not authorized. Sign in again.",dc=e=>/^[a-z_]+$/i.test(e.trim()),uc=/^(Failed to fetch|NetworkError when attempting to fetch resource\.?|Load failed|The network connection was lost\.?|The Internet connection appears to be offline\.?)$/;function lo(e){return e instanceof TypeError&&uc.test(e.message)}function F(e){if(e instanceof te){let t=e.data?.message;return typeof t=="string"&&!dc(t)?t:e.status===401?e.message:e.status===404?"It isn\u2019t there any more. It may have been deleted elsewhere.":e.status>=500?"Something went wrong on the server. Try again in a moment.":e.status===429?"Too many requests at once. Try again in a moment.":"The server couldn\u2019t do that. Reload the page and try again."}return lo(e)?"Couldn\u2019t reach Kestrel. Check your connection and try again.":e instanceof Error?e.message:String(e)}async function co(e,t){let n={...ro(),...t.headers??{}},s=t.body;t.json!==void 0&&(n["content-type"]="application/json",s=JSON.stringify(t.json));let i=await fetch(e,{method:t.method??"GET",headers:n,body:s,signal:t.signal});if(i.status===401){let a=await i.json().catch(()=>null),r=Fn(a);throw r?Kn(r):ao(),new te(cc,401,a)}return i}function pc(e){if(e&&typeof e=="object"){let t=e;if(typeof t.message=="string")return t.message;if(typeof t.error=="string")return t.error}}async function uo(e){let t=await e.text(),n=null;try{n=t?JSON.parse(t):null}catch{}let s=Yn(n);s&&Zn(s);let i=e.statusText||`Request failed (HTTP ${e.status})`;return new te(pc(n)??i,e.status,n)}async function R(e,t={}){let n=await co(e,t);if(!n.ok)throw await uo(n);let s=await n.text();return s?JSON.parse(s):null}async function Mt(e,t={}){let n=await co(e,t);if(!n.ok)throw await uo(n);return n.text()}async function Qn(e,t={}){let n=await co(e,t);if(!n.ok)throw await uo(n);let s=n.headers.get("content-disposition")??"",i=/filename="([^"]+)"/.exec(s)?.[1]??null;return{text:await n.text(),filename:i}}function po(e){let t=e.trim(),n=t.lastIndexOf("<");if(n<0||!t.endsWith(">"))return"";let s=t.slice(0,n).trim();return s.length>=2&&s.startsWith('"')&&s.endsWith('"')?s.slice(1,-1).replace(/\\(.)/g,"$1").trim():s}function cn(e,t){return e||po(t)}function mo(e){let t=e?.settings.publication;return{name:cn(t?.name||"",e?.deployment.from_address??"")||"Your publication",tagline:t?.tagline||"",logoUrl:t?.logo_url||null}}function Xn(){let e=mo(Q.appConfig),t=document.getElementById("brandName"),n=document.getElementById("brandTagline"),s=document.getElementById("brandLogo");t&&(t.textContent=e.name),n&&(n.textContent=e.tagline,n.hidden=!e.tagline),s&&(e.logoUrl?(h(s,o`<img src="${e.logoUrl}" alt="">`),s.classList.remove("brand-logo-placeholder")):(s.textContent=(e.name.trim()[0]||"K").toUpperCase(),s.classList.add("brand-logo-placeholder")))}function Fi(e,t,n){return`${e}${t}/${n}`}var mc=["content","invalid_request"];function fo(e){return e!==null&&mc.includes(e)}var ho={step:"Connect Amazon SES",guide:" (the setup guide walks through it)",after:", then deploy."};var qm=1800*1e3,es=300*1e3,jm=60*1e3,Wm=1440*60*1e3;function It(e){let t=Math.round(e/1e3);if(t%60===0){let n=t/60;return`${n} minute${n===1?"":"s"}`}return`${t} seconds`}function qi(e){return`Pick a time at least ${It(e)} from now, so there\u2019s time to cancel.`}var Vm=10080*60*1e3,Km=3600*1e3;function ji(){let e=Q.appConfig?.deployment.build;if(!e?.version)return null;let t=e.tag_url?o`<a class="build-link" href="${e.tag_url}" target="_blank" rel="noopener">v${e.version}</a>`:o`v${e.version}`,n=e.commit_url?o`<a class="build-link" href="${e.commit_url}" target="_blank" rel="noopener">${e.sha}</a>`:o`${e.sha}`;return{version:t,sha:n}}function ts(){return Q.appConfig?.deployment.min_lead_ms??es}function ns(){return qi(ts())}function Wi(){let e=ts();if(e%6e4===0){let t=e/6e4;return`${t} to ${t+1} minutes`}return`${It(e)} to ${It(e+6e4)}`}function ss(e,t=Date.now()){return e<t+ts()}function os(e=Date.now()){return new Date(e+ts()+6e4)}function dn(){return Q.appConfig?.deployment.provider==="fake"}function ve(){return Q.appConfig?.deployment.provider==="none"}function fc(){return Q.appConfig?.deployment.free_plan_limits===!0}function hc(){return ve()&&Q.appConfig?.deployment.not_connected_preview===!0}var bo="#/docs/ses";function Ae(e){let t=e?o` class="${e}"`:null;return o`<a${t} href="${bo}">${ho.step}</a>`}function go(){return hc()?o`Restart <code>npm run dev</code> without <code>SIMULATE_SENDS=not-connected</code> to send.`:o`${Ae()}${ho.after}`}function is(e,t){let n=t===1;return o`No email provider connected, so nothing can be sent and ${e} ${n?"is":"are"} held, with no one marked unsent; ${n?"it goes out at its":"they go out at their"} first retry once one is connected. ${go()}`}function rs(e,t){return ve()?o`<div class="health amber ${e}" role="status"><span class="health-dot">⚠️</span><div><span>${t}</span></div></div>`:null}function as(e){if(!ve())return null;let t="Will be held: no email provider is connected.";return e==="card"?o`<div class="sched-held">${t}</div>`:o`<div class="sched-note sched-note-held"><span class="sched-note-mark" aria-hidden="true">⚠️</span><span class="sched-note-msg">${t}</span></div>`}function ls(e,t){return ve()?o`<p class="hint not-connected">No email provider connected, so ${e}. ${Ae()}${t}.</p>`:null}function cs(){return ls("a test can\u2019t be sent yet"," to send one")}function Vi(){return ls("a confirmation can\u2019t be sent yet"," to add subscribers")}function vo(){return fc()&&!ve()?o`<p class="hint daily-writes" id="schDailyWrites" role="status" hidden></p>`:null}function Ki(){return ls("this can\u2019t be scheduled yet"," to schedule it")}function Gi(){return ls("this send is held when it fires, until one is"," to send it")}function Nt(e){return dn()?`${e} (local stand-in: nothing is delivered)`:e}function zi(e){let t=Q.appConfig?.deployment;return t?Fi(t.archive_origin,t.archive_base_path,e):null}var Yi=`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960" aria-hidden="true"><path d="M280-280h280v-80H280v80Zm0-160h400v-80H280v80Zm0-160h400v-80H280v80Zm-80 480q-33 0-56.5-23.5T120-200v-560q0-33 23.5-56.5T200-840h560q33 0 56.5 23.5T840-760v560q0 33-23.5 56.5T760-120H200Zm0-80h560v-560H200v560Zm0-560v560-560Z"/></svg>
|
|
3
|
-
`;var
|
|
4
|
-
`;var
|
|
5
|
-
`;var
|
|
6
|
-
`;var
|
|
7
|
-
`;var
|
|
8
|
-
`;var
|
|
9
|
-
`;var
|
|
10
|
-
`;var
|
|
11
|
-
`;var
|
|
12
|
-
`;var
|
|
13
|
-
`;var
|
|
14
|
-
`;var
|
|
15
|
-
`;var
|
|
16
|
-
`;var
|
|
17
|
-
`;var
|
|
18
|
-
`;var
|
|
19
|
-
`;var
|
|
20
|
-
`;var
|
|
21
|
-
`;var
|
|
22
|
-
`;var
|
|
23
|
-
`;var
|
|
24
|
-
`;var
|
|
25
|
-
`;var
|
|
26
|
-
`;var
|
|
27
|
-
`;var
|
|
28
|
-
`;var
|
|
29
|
-
`;var
|
|
30
|
-
`;var
|
|
31
|
-
`;var
|
|
32
|
-
`;var
|
|
33
|
-
`;var
|
|
34
|
-
`;var
|
|
35
|
-
`;var
|
|
2
|
+
"use strict";(()=>{function jn(e){if(!e||typeof e!="object")return null;let t=e;return t.error!=="unauthorized"?null:t.reason==="access_not_configured"||t.reason==="access_unidentified"?t.reason:null}function ao(e){let t=document.getElementById(e);if(!t)throw new Error(`the admin page has no #${e}`);return t}var ue=ao("app"),lo=ao("identity"),co=ao("toasts"),Ni=document.getElementById("navToggle"),io=document.getElementById("navScrim");function an(e){document.body.classList.toggle("nav-open",e),Ni?.setAttribute("aria-expanded",e?"true":"false"),io&&(io.hidden=!e)}var rn=document.getElementById("navCollapse"),ro=null;function cc(){return window.innerWidth<540?"full":ro==="collapsed"?"rail":ro==="expanded"?"full":window.innerWidth<=1024?"rail":"full"}function so(){let e=cc();if(document.documentElement.dataset.nav=e,!rn)return;let t=e!=="rail",n=t?"Collapse sidebar":"Expand sidebar";rn.setAttribute("aria-expanded",t?"true":"false"),rn.setAttribute("aria-label",n),rn.setAttribute("title",n)}var oo=0,Ii=0;function Oi(){Ni?.addEventListener("click",()=>an(!document.body.classList.contains("nav-open"))),io?.addEventListener("click",()=>an(!1)),document.querySelector(".sidebar")?.addEventListener("click",e=>{e.target instanceof Element&&e.target.closest("a")&&an(!1)}),rn?.addEventListener("click",()=>{ro=document.documentElement.dataset.nav!=="rail"?"collapsed":"expanded",so()}),window.addEventListener("resize",()=>{document.body.classList.add("nav-resizing"),clearTimeout(Ii),Ii=setTimeout(()=>{document.body.classList.remove("nav-resizing")},200),!oo&&(oo=requestAnimationFrame(()=>{oo=0,so()}))}),so()}var Wn=null,Vn=null,Kn="Kestrel";function oe(e,t){e.aborted||(document.title=t.trim()?`${t} - ${Kn}`:Kn)}function ee(e){Wn?.abort(),Vn=null;let t=new AbortController;Wn=t,document.title=Kn;let n=document.createElement("div");n.className="view",ue.replaceChildren(n);let s;try{s=Promise.resolve(e(n,t.signal))}catch(i){s=Promise.reject(i)}return s.then(i=>{!t.signal.aborted&&i&&(Vn=i)},i=>{if(!t.signal.aborted)throw i})}function Ht(){Wn?.abort(),Wn=null,Vn=null,document.title=Kn,ue.replaceChildren()}function Gn(){return Vn}function mt(e,t,n){if(n.aborted)return;let s=setInterval(t,e);n.addEventListener("abort",()=>clearInterval(s),{once:!0})}function ft(e,t,n){if(n.aborted)return;let s=()=>clearTimeout(i),i=setTimeout(()=>{n.removeEventListener("abort",s),t()},Math.max(0,e-Date.now()));n.addEventListener("abort",s,{once:!0})}function Bi(e,t,n){let s=()=>{if(n.aborted)return;let i=()=>clearTimeout(a),a=setTimeout(async()=>{n.removeEventListener("abort",i);let r=!0;try{r=await t()??!0}catch(l){dc(l)||reportError(l)}r!==!1&&s()},e);n.addEventListener("abort",i,{once:!0})};s()}function Pt(e,t){if(e.aborted){t();return}e.addEventListener("abort",t,{once:!0})}function dc(e){return e instanceof Error&&(e.name==="AbortError"||e.name==="ApiError")}function c(e,t=document){let n=t.querySelector(e);if(!n)throw new Error(`no element matches ${e}`);return n}function N(e,t=document){return[...t.querySelectorAll(e)]}var uc={"&":"&","<":"<",">":">",'"':""","'":"'"};function X(e){return String(e).replace(/[&<>"']/g,t=>uc[t]??t)}var ht=class{markup;constructor(t){this.markup=t,Object.freeze(this)}toString(){return this.markup}};function Ui(e){return e instanceof ht?e.markup:e==null||e===!1?"":Array.isArray(e)?e.map(Ui).join(""):X(e)}var pc=/=\s*$/;function o(e,...t){let n=Di(e,0);for(let s=0;s<t.length;s++){let i=t[s];if(!(i instanceof ht)&&pc.test(n))throw new Error("html: an interpolation in an unquoted attribute value cannot be made safe; quote it");n+=Ui(i)+Di(e,s+1)}return new ht(n)}function Di(e,t){let n=e[t];if(n===void 0)throw new Error(`html: invalid escape sequence in template text near ${JSON.stringify(e.raw[t])}`);return n}function V(e){return new ht(e)}function f(e,t){if(!(t instanceof ht))throw new Error("setHtml: expected Html; build it with html`\u2026` or vouch for it with unsafeHtml()");e.innerHTML=t.markup}var mc="https://getkestrel.dev/docs/access/",fc="/cdn-cgi/access/logout";function zn(e){if(ue.querySelector(".access-wall"))return;Ht(),document.body.classList.add("signed-out");let t=o`<p class="hint"><a href="${mc}" target="_blank" rel="noopener">Lock the dashboard with Access <span aria-hidden="true">↗</span><span class="visually-hidden"> (opens in a new tab)</span></a></p>`;e==="access_unidentified"?(f(ue,o`<div class="card auth-wall access-wall" role="alert"><h2 tabindex="-1">Access let you in, but didn’t say who you are</h2><p>Cloudflare Access sent neither an email address nor a service token, and Kestrel needs one of them to tell who is asking, so it doesn’t let this sign-in in. Some other kind of Access policy, or a login method that gives no email, let it through.</p><p>Kestrel accepts two kinds of Access policy: an Allow policy on people’s emails, and a Service Auth policy on a service token. Sign out, then sign in through one of them.</p>${t}<button id="access-signout" class="primary">Sign out</button></div>`),c("#access-signout",ue).onclick=()=>location.assign(fc)):(f(ue,o`<div class="card auth-wall access-wall"><h2 tabindex="-1">The editor is locked until you set up Access</h2><p>Until Cloudflare Access is in front of the editor, the app can’t tell who is asking, so it lets no one in. On a new deployment, that’s expected. Your public pages work as usual.</p>${t}<button id="access-reload" class="primary">Reload</button></div>`),c("#access-reload",ue).onclick=()=>location.reload()),c(".access-wall h2",ue).focus()}var Fi="Kestrel-Client",ln="editor",Yn="claude-code",Zn="claude";function Jn(e){if(!e||typeof e!="object")return null;let t=e;return t.error==="schema_behind"&&typeof t.message=="string"?{message:t.message}:t.error!=="invalid_config"||typeof t.variable!="string"?null:{variable:t.variable,message:typeof t.message=="string"?t.message:`${t.variable} is refused`}}var hc="https://getkestrel.dev/docs/configuration/",bc={PROVIDER:"vars",ALLOW_FAKE_PROVIDER:"vars",APP_ORIGIN:"vars",AWS_REGION:"vars",FROM_ADDRESS:"vars",SENDING_DOMAIN:"vars",ARCHIVE_BASE_PATH:"vars",SES_MAX_SEND_RATE:"vars",SUBREQUEST_BUDGET:"vars",MIN_LEAD_SECONDS:"vars",ARCHIVE_ORIGIN:"vars",MEDIA_PUBLIC_BASE:"vars",NOTIFY_FROM:"vars",ACCESS_TEAM_DOMAIN:"secrets",ACCESS_AUD:"secrets",ACCESS_ALLOWED_EMAILS:"secrets",AWS_ACCESS_KEY_ID:"secrets",AWS_SECRET_ACCESS_KEY:"secrets",SNS_TOPIC_ARN:"secrets",SES_CONFIGURATION_SET:"secrets",SIMULATE_SENDS:"what-the-app-refuses"},gc="what-the-app-refuses";function vc(e){return`${hc}#${bc[e]??gc}`}function Qn(e){if(ue.querySelector(".config-wall"))return;Ht(),document.body.classList.add("signed-out");let{variable:t}=e,n=t?"A setting needs fixing":"The database needs updating",s=t?o`<p class="hint"><a href="${vc(t)}" target="_blank" rel="noopener">${t} in the Configuration reference <span aria-hidden="true">↗</span><span class="visually-hidden"> (opens in a new tab)</span></a></p>`:"";f(ue,o`<div class="card auth-wall config-wall" role="alert"><h2 tabindex="-1">${n}</h2><p>Kestrel won’t run until it’s fixed, and nothing is sent in the meantime.</p><p class="config-wall-problem">${e.message}</p>${s}<button id="config-reload" class="primary">Reload</button></div>`),c("#config-reload",ue).onclick=()=>location.reload(),c(".config-wall h2",ue).focus()}var Xn="kestrel_token",Q={token:localStorage.getItem(Xn)||"",session:null,appConfig:null};function Wi(e){Q.token=(e||"").trim();try{Q.token?localStorage.setItem(Xn,Q.token):localStorage.removeItem(Xn)}catch{}}function uo(){return{[Fi]:ln,...Q.token?{Authorization:`Bearer ${Q.token}`}:{}}}function Vi(){let e=Q.session;if(e?.auth.mode==="access"){let t=e.principal,n=t.email||(t.kind==="service"?"Service token":"Signed in");f(lo,o`<span class="who" title="${n}">${n}</span><a class="ghost" href="/cdn-cgi/access/logout" title="Sign out"><svg class="signout-icon" aria-hidden="true"><use href="#i-signout"/></svg><span class="signout-label">Sign out</span></a>`)}else f(lo,o`<span class="who dev" title="Local dev: sign-in is skipped on localhost">Local dev</span>`)}function cn(){ue.querySelector(".reauth-wall")||(Ht(),document.body.classList.add("signed-out"),f(ue,o`<div class="card auth-wall reauth-wall"><h2 tabindex="-1">Session expired</h2><p class="hint">Your access session ended. Sign in again to continue.</p><button id="reauth" class="primary">Sign in</button></div>`),c("#reauth",ue).onclick=()=>location.reload(),c(".reauth-wall h2",ue).focus())}async function qi(){try{let e=await fetch("/api/dev/token?kind=human");if(e.ok)return Wi((await e.json()).token),!0}catch{}return!1}async function ji(){try{return await fetch("/api/whoami",{headers:uo(),redirect:"manual"})}catch{return null}}function yc(e){let t=e;return typeof t?.principal=="object"&&t.principal!==null&&typeof t.auth=="object"}async function Ki(){Q.token||await qi();let e=await ji();!e?.ok&&Q.token&&(Wi(""),await qi()&&(e=await ji()));let t=e?await e.json().catch(()=>null):null;if(e?.ok&&yc(t))return t;let n=Jn(t),s=jn(t);return n?Qn(n):s?zn(s):cn(),null}var te=class extends Error{constructor(n,s,i=null){super(n);this.status=s;this.data=i;this.name="ApiError"}status;data;get code(){let n=this.data;return typeof n?.error=="string"?n.error:null}get field(){let n=this.data;return typeof n?.field=="string"?n.field:null}},wc="Not authorized. Sign in again.",Sc=e=>/^[a-z_]+$/i.test(e.trim()),$c=/^(Failed to fetch|NetworkError when attempting to fetch resource\.?|Load failed|The network connection was lost\.?|The Internet connection appears to be offline\.?)$/;function po(e){return e instanceof TypeError&&$c.test(e.message)}function q(e){if(e instanceof te){let t=e.data?.message;return typeof t=="string"&&!Sc(t)?t:e.status===401?e.message:e.status===404?"It isn\u2019t there any more. It may have been deleted elsewhere.":e.status>=500?"Something went wrong on the server. Try again in a moment.":e.status===429?"Too many requests at once. Try again in a moment.":"The server couldn\u2019t do that. Reload the page and try again."}return po(e)?"Couldn\u2019t reach Kestrel. Check your connection and try again.":e instanceof Error?e.message:String(e)}async function mo(e,t){let n={...uo(),...t.headers??{}},s=t.body;t.json!==void 0&&(n["content-type"]="application/json",s=JSON.stringify(t.json));let i=await fetch(e,{method:t.method??"GET",headers:n,body:s,signal:t.signal});if(i.status===401){let a=await i.json().catch(()=>null),r=jn(a);throw r?zn(r):cn(),new te(wc,401,a)}return i}function Ec(e){if(e&&typeof e=="object"){let t=e;if(typeof t.message=="string")return t.message;if(typeof t.error=="string")return t.error}}async function fo(e){let t=await e.text(),n=null;try{n=t?JSON.parse(t):null}catch{}let s=Jn(n);s&&Qn(s);let i=e.statusText||`Request failed (HTTP ${e.status})`;return new te(Ec(n)??i,e.status,n)}async function T(e,t={}){let n=await mo(e,t);if(!n.ok)throw await fo(n);let s=await n.text();return s?JSON.parse(s):null}async function Mt(e,t={}){let n=await mo(e,t);if(!n.ok)throw await fo(n);return n.text()}async function es(e,t={}){let n=await mo(e,t);if(!n.ok)throw await fo(n);let s=n.headers.get("content-disposition")??"",i=/filename="([^"]+)"/.exec(s)?.[1]??null;return{text:await n.text(),filename:i}}function ho(e){let t=e.trim(),n=t.lastIndexOf("<");if(n<0||!t.endsWith(">"))return"";let s=t.slice(0,n).trim();return s.length>=2&&s.startsWith('"')&&s.endsWith('"')?s.slice(1,-1).replace(/\\(.)/g,"$1").trim():s}function dn(e,t){return e||ho(t)}function bo(e){let t=e?.settings.publication;return{name:dn(t?.name||"",e?.deployment.from_address??"")||"Your publication",tagline:t?.tagline||"",logoUrl:t?.logo_url||null}}function ts(){let e=bo(Q.appConfig),t=document.getElementById("brandName"),n=document.getElementById("brandTagline"),s=document.getElementById("brandLogo");t&&(t.textContent=e.name),n&&(n.textContent=e.tagline,n.hidden=!e.tagline),s&&(e.logoUrl?(f(s,o`<img src="${e.logoUrl}" alt="">`),s.classList.remove("brand-logo-placeholder")):(s.textContent=(e.name.trim()[0]||"K").toUpperCase(),s.classList.add("brand-logo-placeholder")))}function Gi(e,t,n){return`${e}${t}/${n}`}var xc=["content","invalid_request"];function go(e){return e!==null&&xc.includes(e)}var vo={step:"Connect Amazon SES",guide:" (the setup guide walks through it)",after:", then deploy."};var sf=1800*1e3,ns=300*1e3,of=60*1e3,rf=1440*60*1e3;function It(e){let t=Math.round(e/1e3);if(t%60===0){let n=t/60;return`${n} minute${n===1?"":"s"}`}return`${t} seconds`}function zi(e){return`Pick a time at least ${It(e)} from now, so there\u2019s time to cancel.`}var af=10080*60*1e3,lf=3600*1e3;function Yi(){let e=Q.appConfig?.deployment.build;if(!e?.version)return null;let t=e.tag_url?o`<a class="build-link" href="${e.tag_url}" target="_blank" rel="noopener">v${e.version}</a>`:o`v${e.version}`,n=e.commit_url?o`<a class="build-link" href="${e.commit_url}" target="_blank" rel="noopener">${e.sha}</a>`:o`${e.sha}`;return{version:t,sha:n}}function ss(){return Q.appConfig?.deployment.min_lead_ms??ns}function os(){return zi(ss())}function Zi(){let e=ss();if(e%6e4===0){let t=e/6e4;return`${t} to ${t+1} minutes`}return`${It(e)} to ${It(e+6e4)}`}function is(e,t=Date.now()){return e<t+ss()}function rs(e=Date.now()){return new Date(e+ss()+6e4)}function un(){return Q.appConfig?.deployment.provider==="fake"}function ve(){return Q.appConfig?.deployment.provider==="none"}function kc(){return Q.appConfig?.deployment.free_plan_limits===!0}function _c(){return ve()&&Q.appConfig?.deployment.not_connected_preview===!0}var yo="#/docs/ses";function Ae(e){let t=e?o` class="${e}"`:null;return o`<a${t} href="${yo}">${vo.step}</a>`}function wo(){return _c()?o`Restart <code>npm run dev</code> without <code>SIMULATE_SENDS=not-connected</code> to send.`:o`${Ae()}${vo.after}`}function as(e,t){let n=t===1;return o`No email provider connected, so nothing can be sent and ${e} ${n?"is":"are"} held, with no one marked unsent; ${n?"it goes out at its":"they go out at their"} first retry once one is connected. ${wo()}`}function ls(e,t){return ve()?o`<div class="health amber ${e}" role="status"><span class="health-dot">⚠️</span><div><span>${t}</span></div></div>`:null}function cs(e){if(!ve())return null;let t="Will be held: no email provider is connected.";return e==="card"?o`<div class="sched-held">${t}</div>`:o`<div class="sched-note sched-note-held"><span class="sched-note-mark" aria-hidden="true">⚠️</span><span class="sched-note-msg">${t}</span></div>`}function ds(e,t){return ve()?o`<p class="hint not-connected">No email provider connected, so ${e}. ${Ae()}${t}.</p>`:null}function us(){return ds("a test can\u2019t be sent yet"," to send one")}function Ji(){return ds("a confirmation can\u2019t be sent yet"," to add subscribers")}function So(){return kc()&&!ve()?o`<p class="hint daily-writes" id="schDailyWrites" role="status" hidden></p>`:null}function Qi(){return ds("this can\u2019t be scheduled yet"," to schedule it")}function Xi(){return ds("this send is held when it fires, until one is"," to send it")}function Nt(e){return un()?`${e} (local stand-in: nothing is delivered)`:e}function er(e){let t=Q.appConfig?.deployment;return t?Gi(t.archive_origin,t.archive_base_path,e):null}var tr=`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960" aria-hidden="true"><path d="M280-280h280v-80H280v80Zm0-160h400v-80H280v80Zm0-160h400v-80H280v80Zm-80 480q-33 0-56.5-23.5T120-200v-560q0-33 23.5-56.5T200-840h560q33 0 56.5 23.5T840-760v560q0 33-23.5 56.5T760-120H200Zm0-80h560v-560H200v560Zm0-560v560-560Z"/></svg>
|
|
3
|
+
`;var nr=`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960" aria-hidden="true"><path d="M272-200v-560h221q65 0 120 40t55 111q0 51-23 78.5T602-491q25 11 55.5 41t30.5 90q0 89-65 124.5T501-200H272Zm121-112h104q48 0 58.5-24.5T566-372q0-11-10.5-35.5T494-432H393v120Zm0-228h93q33 0 48-17t15-38q0-24-17-39t-44-15h-95v109Z"/></svg>
|
|
4
|
+
`;var sr=`<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M4 5a2 2 0 0 1 2-2h13v16H6a2 2 0 0 0-2 2z"/><path d="M4 21V5"/><path d="M9 8h6"/></svg>
|
|
5
|
+
`;var or=`<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M6 3v8a4 4 0 0 0 4 4h8"/><path d="m14 11 4 4-4 4"/></svg>
|
|
6
|
+
`;var ir=`<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"><path d="M20 6 9 17l-5-5"/></svg>
|
|
7
|
+
`;var rr=`<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="9"/><path d="m8 12 3 3 5-6"/></svg>
|
|
8
|
+
`;var ar=`<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="9"/><path d="M8 12h8"/></svg>
|
|
9
|
+
`;var lr=`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960" aria-hidden="true"><path d="M320-240 80-480l240-240 57 57-184 184 183 183-56 56Zm320 0-57-57 184-184-183-183 56-56 240 240-240 240Z"/></svg>
|
|
10
|
+
`;var cr=`<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="8" y="8" width="13" height="13" rx="2"/><path d="M16 8V5a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v9a2 2 0 0 0 2 2h3"/></svg>
|
|
11
|
+
`;var dr=`<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="4" width="18" height="12" rx="2"/><path d="M8 20h8"/><path d="M12 16v4"/></svg>
|
|
12
|
+
`;var ur=`<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 20h9"/><path d="M16.5 3.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4z"/></svg>
|
|
13
|
+
`;var pr=`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960" aria-hidden="true"><path d="M360-280v-400h80v160h160v-160h80v400h-80v-160H440v160h-80Z"/></svg>
|
|
14
|
+
`;var mr=`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960" aria-hidden="true"><path d="M120-120v-80h720v80H120Zm320-160v-80h400v80H440Zm0-160v-80h400v80H440Zm0-160v-80h400v80H440ZM120-760v-80h720v80H120Zm0 440v-320l160 160-160 160Z"/></svg>
|
|
15
|
+
`;var fr=`<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="9"/><path d="M12 16v-4M12 8h.01"/></svg>
|
|
16
|
+
`;var hr=`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960" aria-hidden="true"><path d="M440-280h80v-240h-80v240Zm68.5-331.5Q520-623 520-640t-11.5-28.5Q497-680 480-680t-28.5 11.5Q440-657 440-640t11.5 28.5Q463-600 480-600t28.5-11.5ZM480-80q-83 0-156-31.5T197-197q-54-54-85.5-127T80-480q0-83 31.5-156T197-763q54-54 127-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 83-31.5 156T763-197q-54 54-127 85.5T480-80Zm0-80q134 0 227-93t93-227q0-134-93-227t-227-93q-134 0-227 93t-93 227q0 134 93 227t227 93Zm0-320Z"/></svg>
|
|
17
|
+
`;var br=`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960" aria-hidden="true"><path d="M200-200v-100h160l120-360H320v-100h400v100H580L460-300h140v100H200Z"/></svg>
|
|
18
|
+
`;var gr=`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 360 360" aria-hidden="true"><path d="M290.028 216.064C285.698 218.264 280.838 219.394 275.978 219.344C281.268 225.044 284.128 232.924 283.708 240.694C283.278 248.844 279.388 256.514 274.268 262.874C269.148 269.244 262.808 274.494 256.608 279.814C237.148 296.474 218.248 314.404 195.328 325.854C178.568 334.224 160.148 338.864 143.458 347.374C140.148 349.064 136.898 350.904 133.418 352.224C129.938 353.544 126.178 354.324 122.498 353.794C121.718 353.684 120.938 353.504 120.228 353.184C119.508 352.864 118.848 352.374 118.408 351.734C117.918 351.024 117.708 350.154 117.718 349.304C117.728 348.454 117.948 347.614 118.268 346.824C118.567 346.054 118.967 345.339 119.371 344.618L119.418 344.534C128.788 327.894 140.118 312.454 150.358 296.344C160.598 280.224 169.848 263.174 174.428 244.634C176.258 237.264 177.328 229.644 176.738 222.074C176.138 214.504 173.808 206.964 169.308 200.854C164.588 194.434 157.728 189.874 150.538 186.434C139.628 181.204 127.768 178.284 115.858 176.154C93.9183 172.224 71.6083 170.884 49.4083 168.944C45.8483 168.634 42.2483 168.294 38.8783 167.124C34.7683 165.704 31.0683 163.004 28.7383 159.334C26.4183 155.664 25.5583 151.024 26.7483 146.844C27.6583 143.624 29.7283 140.784 32.3583 138.724C34.9883 136.654 38.1683 135.324 41.4383 134.634C44.7183 133.944 48.0983 133.874 51.4383 134.154C53.2683 134.304 55.0883 134.554 56.8983 134.824C72.2383 137.094 87.3783 140.484 102.548 143.644C115.468 146.334 128.498 148.864 141.688 149.224C154.878 149.574 168.338 147.654 180.178 141.824C196.548 133.764 208.758 118.514 215.298 101.474C224.258 78.094 223.028 52.174 220.398 27.284C219.788 21.484 219.108 15.614 220.058 9.854C220.178 9.124 220.328 8.38398 220.658 7.71398C220.988 7.05398 221.528 6.45399 222.228 6.19399C222.858 5.95399 223.568 6.01399 224.218 6.22399C224.858 6.43399 225.448 6.77399 226.028 7.12399C262.588 29.154 290.508 63.614 310.198 101.484C312.188 105.314 314.108 109.204 315.408 113.314C316.708 117.434 317.358 121.814 316.768 126.084C316.348 129.114 315.268 132.104 313.318 134.454C310.668 137.634 306.688 139.354 302.778 140.744C298.878 142.124 294.808 143.324 291.488 145.804C286.998 149.174 284.328 154.834 284.598 160.444C292.098 161.904 299.448 164.114 306.508 167.014C312.788 169.594 318.998 172.854 323.418 178.014C327.088 182.294 329.288 187.614 331.438 192.844C332.158 194.584 332.878 196.344 333.328 198.184C333.778 200.014 333.958 201.944 333.578 203.794C333.138 205.934 331.948 207.914 330.248 209.294C329.898 208.024 329.258 206.834 328.408 205.834C326.958 204.154 324.928 203.054 322.798 202.454C318.258 201.174 313.328 202.114 309.018 204.044C304.708 205.974 300.898 208.834 297.068 211.584C294.808 213.204 292.508 214.804 290.028 216.064Z"/></svg>
|
|
19
|
+
`;var vr=`<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M9 6h11M9 12h11M9 18h11M4 6h1M4 12h1M4 18h1"/></svg>
|
|
20
|
+
`;var yr=`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960" aria-hidden="true"><path d="M440-280H280q-83 0-141.5-58.5T80-480q0-83 58.5-141.5T280-680h160v80H280q-50 0-85 35t-35 85q0 50 35 85t85 35h160v80ZM320-440v-80h320v80H320Zm200 160v-80h160q50 0 85-35t35-85q0-50-35-85t-85-35H520v-80h160q83 0 141.5 58.5T880-480q0 83-58.5 141.5T680-280H520Z"/></svg>
|
|
21
|
+
`;var wr=`<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="5" width="18" height="14" rx="2"/><path d="m3 7 9 6 9-6"/></svg>
|
|
22
|
+
`;var Sr=`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960" aria-hidden="true"><path d="M120-80v-60h100v-30h-60v-60h60v-30H120v-60h120q17 0 28.5 11.5T280-280v40q0 17-11.5 28.5T240-200q17 0 28.5 11.5T280-160v40q0 17-11.5 28.5T240-80H120Zm0-280v-110q0-17 11.5-28.5T160-510h60v-30H120v-60h120q17 0 28.5 11.5T280-560v70q0 17-11.5 28.5T240-450h-60v30h100v60H120Zm60-280v-180h-60v-60h120v240h-60Zm180 440v-80h480v80H360Zm0-240v-80h480v80H360Zm0-240v-80h480v80H360Z"/></svg>
|
|
23
|
+
`;var $r=`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960" aria-hidden="true"><path d="M720-330q0 104-73 177T470-80q-104 0-177-73t-73-177v-370q0-75 52.5-127.5T400-880q75 0 127.5 52.5T580-700v350q0 46-32 78t-78 32q-46 0-78-32t-32-78v-370h80v370q0 13 8.5 21.5T470-320q13 0 21.5-8.5T500-350v-350q-1-42-29.5-71T400-800q-42 0-71 29t-29 71v370q-1 71 49 120.5T470-160q70 0 119-49.5T640-330v-390h80v390Z"/></svg>
|
|
24
|
+
`;var Er=`<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="7" y="2" width="10" height="20" rx="2"/><path d="M11 18h2"/></svg>
|
|
25
|
+
`;var xr=`<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round"><path d="M12 5v14M5 12h14"/></svg>
|
|
26
|
+
`;var kr=`<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M2 12s3.5-7 10-7 10 7 10 7-3.5 7-10 7-10-7-10-7Z"/><circle cx="12" cy="12" r="3"/></svg>
|
|
27
|
+
`;var _r=`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960" aria-hidden="true"><path d="m228-240 92-160q-66 0-113-47t-47-113q0-66 47-113t113-47q66 0 113 47t47 113q0 23-5.5 42.5T458-480L320-240h-92Zm360 0 92-160q-66 0-113-47t-47-113q0-66 47-113t113-47q66 0 113 47t47 113q0 23-5.5 42.5T818-480L680-240h-92ZM362.5-517.5Q380-535 380-560t-17.5-42.5Q345-620 320-620t-42.5 17.5Q260-585 260-560t17.5 42.5Q295-500 320-500t42.5-17.5Zm360 0Q740-535 740-560t-17.5-42.5Q705-620 680-620t-42.5 17.5Q620-585 620-560t17.5 42.5Q655-500 680-500t42.5-17.5ZM680-560Zm-360 0Z"/></svg>
|
|
28
|
+
`;var Tr=`<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="4" y="11" width="16" height="10" rx="2"/><path d="M8 11V7a4 4 0 0 1 8 0v4"/></svg>
|
|
29
|
+
`;var Lr=`<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round"><circle cx="11" cy="11" r="6.5"/><path d="m20 20-4.2-4.2"/></svg>
|
|
30
|
+
`;var Rr=`<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" aria-hidden="true" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M22 3 11 14M22 3l-7 18-4-7-7-4 18-7z"/></svg>
|
|
31
|
+
`;var Cr=`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960" aria-hidden="true"><path d="m370-80-16-128q-13-5-24.5-12T307-235l-119 50L78-375l103-78q-1-7-1-13.5v-27q0-6.5 1-13.5L78-585l110-190 119 50q11-8 23-15t24-12l16-128h220l16 128q13 5 24.5 12t22.5 15l119-50 110 190-103 78q1 7 1 13.5v27q0 6.5-2 13.5l103 78-110 190-118-50q-11 8-23 15t-24 12L590-80H370Zm70-80h79l14-106q31-8 57.5-23.5T639-327l99 41 39-68-86-65q5-14 7-29.5t2-31.5q0-16-2-31.5t-7-29.5l86-65-39-68-99 42q-22-23-48.5-38.5T533-694l-13-106h-79l-14 106q-31 8-57.5 23.5T321-633l-99-41-39 68 86 64q-5 15-7 30t-2 32q0 16 2 31t7 30l-86 65 39 68 99-42q22 23 48.5 38.5T427-266l13 106Zm42-180q58 0 99-41t41-99q0-58-41-99t-99-41q-59 0-99.5 41T342-480q0 58 40.5 99t99.5 41Zm-2-140Z"/></svg>
|
|
32
|
+
`;var Ar=`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960" aria-hidden="true"><path d="M360-200v-80h480v80H360Zm0-240v-80h480v80H360Zm0-240v-80h480v80H360ZM200-160q-33 0-56.5-23.5T120-240q0-33 23.5-56.5T200-320q33 0 56.5 23.5T280-240q0 33-23.5 56.5T200-160Zm0-240q-33 0-56.5-23.5T120-480q0-33 23.5-56.5T200-560q33 0 56.5 23.5T280-480q0 33-23.5 56.5T200-400Zm-56.5-263.5Q120-687 120-720t23.5-56.5Q167-800 200-800t56.5 23.5Q280-753 280-720t-23.5 56.5Q233-640 200-640t-56.5-23.5Z"/></svg>
|
|
33
|
+
`;var Hr=`<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 16V4M8 8l4-4 4 4"/><path d="M4 16v2a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-2"/></svg>
|
|
34
|
+
`;var Pr=`<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round"><path d="M6 6l12 12M18 6 6 18"/></svg>
|
|
35
|
+
`;var rd={article:V(tr),bold:V(nr),check:V(ir),code:V(lr),copyout:V(cr),editable:V(ur),heading:V(pr),indent:V(mr),info:V(fr),"info-filled":V(hr),italic:V(br),kestrel:V(gr),lines:V(vr),link:V(yr),ol:V(Sr),paperclip:V($r),plus:V(xr),preview:V(kr),quote:V(_r),readonly:V(Tr),search:V(Lr),send:V(Rr),settings:V(Cr),ul:V(Ar),upload:V(Hr),book:V(sr),branch:V(or),"circle-check":V(rr),"circle-minus":V(ar),desktop:V(dr),mail:V(wr),phone:V(Er),x:V(Pr)};function O(e){return rd[e]}function Ot(e,t,n){let s=(w,h)=>e===w?o`<a href="#/${w}" data-room="${w}" data-text="${h}" aria-current="page">${h}</a>`:o`<a href="#/${w}" data-room="${w}" data-text="${h}">${h}</a>`,i=Yi(),a=Q.appConfig?.deployment.build.build_time,r=a?`Built ${new Date(a).toLocaleString(void 0,{dateStyle:"medium",timeStyle:"short"})}`:null,l=i?o`${i.version} <span aria-hidden="true">·</span> ${i.sha}`:null,d=l?r?o`<div class="rail-foot" title="${r}">${l}</div>`:o`<div class="rail-foot">${l}</div>`:null,u=l?r?o`<footer class="room-foot" title="${r}">${l}</footer>`:o`<footer class="room-foot">${l}</footer>`:null,m=t==null?o`<div class="room-body norail"><div class="room-main">${n}</div></div>`:o`<div class="room-body"><nav class="room-rail" aria-label="Contents"><div class="rail-inner">${t}${d}</div></nav><div class="room-main">${n}</div></div>`;return o`<div class="room">
|
|
36
36
|
<header class="room-bar">
|
|
37
37
|
<a class="room-back" href="#/dashboard" aria-label="Back to dashboard"><span aria-hidden="true">←</span><span class="room-back-label">Dashboard</span></a>
|
|
38
38
|
<div class="room-nav">
|
|
39
|
-
<a class="room-brand" href="#/docs">${
|
|
39
|
+
<a class="room-brand" href="#/docs">${O("kestrel")}<span>Kestrel</span></a>
|
|
40
40
|
<nav class="room-switch" aria-label="Reference">${s("docs","Docs")}${s("api-reference","API")}</nav>
|
|
41
41
|
<a class="room-close" href="#/dashboard" title="Back to publication" aria-label="Back to publication"><span aria-hidden="true">✕</span></a>
|
|
42
42
|
</div>
|
|
43
43
|
</header>
|
|
44
|
-
${
|
|
44
|
+
${m}
|
|
45
45
|
${u}
|
|
46
|
-
</div>`}function
|
|
46
|
+
</div>`}function Mr(){ue.addEventListener("click",e=>{let t=e.target instanceof Element?e.target.closest(".room-bar a[href^='#/']"):null;!t||t.getAttribute("href")!==location.hash||(e.preventDefault(),window.scrollTo(0,0))})}var ad=/^(\/[A-Za-z0-9._~%-]+)+$/,ld=/\/(?:\.|%2e){1,2}(?=\/|$)/i;function $o(e){return ad.test(e)&&!ld.test(e)}function Ir(e){let t=new URLSearchParams(e).get("to");return t&&$o(t)?`#${t}`:null}var cd=/^(\d+)\.(\d+)$/;function dd(e){return`${e.seq}.${e.at}`}function Nr(e){let t=cd.exec(e);if(!t?.[1]||!t[2])return null;let n=Number(t[1]),s=Number(t[2]);return Number.isSafeInteger(n)&&Number.isSafeInteger(s)?{seq:n,at:s}:null}function ps(e,t){let n=Nr(e),s=Nr(t);return!n||!s?n?e:t:dd({seq:Math.min(n.seq,s.seq),at:Math.min(n.at,s.at)})}function nt(e){switch(e.status){case"scheduled":return e.phase==="due"?"due":"scheduled";case"sending":return"sending";case"sent":return e.phase==="complete"?"complete":"sent";default:return"canceled"}}var ud=3e3,pd=6e4,md=3e4,Ue=new Set,ms=null,bt=null,Ye,tt=null,pn=!1,Eo=!1,fs=0;function hs(e){try{e()}catch(t){reportError(t)}}function xo(e,t){return e&&t?ps(e,t):e??t}function Or(e){clearTimeout(Ye),Ye=void 0,!(!Ue.size||document.hidden)&&(Ye=setTimeout(mn,e))}function mn(){if(clearTimeout(Ye),Ye=void 0,!Ue.size)return;if(tt){pn=!0;return}let e=xo(ms,bt);bt=null;let t=[...Ue],n=new AbortController;tt=n;let s=setTimeout(()=>n.abort(),md),i=e?`?since=${encodeURIComponent(e)}`:"";T(`/api/sends/feed${i}`,{signal:n.signal}).then(a=>{if(clearTimeout(s),tt===n){tt=null,fs=0,ms=a.cursor;for(let r of t)Ue.has(r)&&r.take(a);if(pn){pn=!1,mn();return}Or(Math.max(0,a.read_again_at-a.now))}},a=>{if(clearTimeout(s),tt===n){if(tt=null,pn=!1,a instanceof te&&a.code==="cursor_ahead"){let r=[...Ue];for(let l of r)Ur(l);for(let l of r)hs(()=>l.stale());return}a instanceof te&&a.status===400?ms=null:bt=xo(bt,e),fs+=1,Or(Math.min(ud*2**(fs-1),pd))}})}function fd(){Eo||(Eo=!0,queueMicrotask(()=>{Eo=!1,mn()}))}function Br(){document.hidden?(clearTimeout(Ye),Ye=void 0):mn()}function Dr(e,t,n){n.aborted||(Ue.add(e),bt=xo(bt,t),Ue.size===1&&document.addEventListener("visibilitychange",Br),n.addEventListener("abort",()=>Ur(e),{once:!0}),fd())}function Ur(e){Ue.delete(e),!Ue.size&&(clearTimeout(Ye),Ye=void 0,tt?.abort(),tt=null,pn=!1,fs=0,ms=null,bt=null,document.removeEventListener("visibilitychange",Br))}function Bt(e,t,n){let s=new Map(e.sends.map(i=>[i.id,nt(i)]));Dr({take(i){if(!i.sends.length&&!i.removed.length)return;let a=[];for(let l of i.sends){let d=nt(l),u=s.get(l.id)??null;u!==d&&a.push({send:l,from:u,to:d}),s.set(l.id,d)}let r=i.removed.map(l=>l.id);for(let l of r)s.delete(l);hs(()=>t.update({sends:i.sends,changes:a,removed:r}))},stale:()=>t.stale()},e.cursor,n)}function fn(e,t,n){let s=e.send.id,i=nt(e.send);Dr({take(a){if(a.removed.some(u=>u.id===s)){hs(()=>t.removed());return}let r=a.sends.find(u=>u.id===s);if(!r)return;let l=nt(r),d=l!==i?{send:r,from:i,to:l}:null;i=l,hs(()=>t.update(r,d))},stale:()=>t.stale()},e.cursor,n)}function Fe(){Ue.size&&mn()}function gt(e){return e.trim().toLowerCase()}function vt(e){return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e)}function K(e){if(!e)return"\u2014";let t=new Date(e);return t.toLocaleString(void 0,{year:t.getFullYear()===new Date().getFullYear()?void 0:"numeric",month:"short",day:"numeric",hour:"numeric",minute:"2-digit"})}function bs(e){let t=new Set,n=[];for(let s of String(e||"").split(/[\n,]+/)){let i=gt(s);vt(i)?t.add(i):i&&n.push(s.trim())}return{valid:[...t],invalid:n}}function gs(e){return e.length?`Not ${e.length===1?"an email address":"email addresses"}: ${e.join(", ")}`:null}function vs(e,t,n){let s=new Map,i=[];for(let r of n)r.message?s.set(r.message,[...s.get(r.message)??[],r.email]):i.push(r.email);if(!s.size)return e?`Sent to ${e} of ${t}. Not sent to ${i.join(", ")}. Send again to try those.`:"Not sent. Send again to try.";let a=[...s].map(([r,l])=>t>1?`${l.join(", ")}: ${r}`:r);return i.length&&a.push(`Not sent to ${i.join(", ")}.`),e?`Sent to ${e} of ${t}. ${a.join(" ")} Send again goes only to those.`:a.join(" ")}function yt(e){let t=n=>String(n).padStart(2,"0");return`${e.getFullYear()}-${t(e.getMonth()+1)}-${t(e.getDate())}T${t(e.getHours())}:${t(e.getMinutes())}`}function hn(e,t=!1){let n=e-Date.now();if(t||n<=0)return"Preparing to send\u2026";let s=Math.floor(n/1e3),i=Math.floor(s/60),a=Math.floor(i/60);if(s<300)return i>0?`Sends in ${i}m ${String(s%60).padStart(2,"0")}s`:`Sends in ${s}s`;if(i<60)return`Sends in ${i}m`;if(a<24){let l=i%60;return l>0?`Sends in ${a}h ${l}m`:`Sends in ${a}h`}let r=Math.round(a/24);return`Sends in ${r} day${r===1?"":"s"}`}function ys(e){return`Missed its fire time \xB7 ${Math.max(0,Math.floor((Date.now()-e)/6e4))} min late`}var bn=e=>Math.max(0,Math.min(100,Math.round(e||0)));function ws(e){if(e==null||!Number.isFinite(e)||e<=0)return"\u2014";let t=Math.round(e/1e3);if(t<90)return`${t}s`;let n=Math.round(t/60);return n<90?`${n} min`:`${Math.round(n/60)} hr`}function wt(e,t){return t.email_only?o`<span class="title-with-label"><span class="title-text">${e}</span><span class="email-only-mark">${O("mail")}Email only</span></span>`:e}function Ss(e){return e.email_only?o` · <span class="sched-email-only">Email only</span>`:null}function $s(e){return o`<span class="countdown" data-fire="${e.fire_at}"${e.phase==="due"&&o` data-due`}${Le(e,"missed")&&o` data-missed`}></span>`}function Es(e,t){let n=0,s=()=>{let i=Date.now(),a=Number.POSITIVE_INFINITY,r=l=>{l>i&&l<a&&(a=l)};for(let l of N("[data-closes]",e)){let d=Number(l.dataset.closes);l.hidden=i>=d,r(d)}for(let l of N("[data-fire]",e)){let d=Number(l.dataset.fire),u=l.dataset.missed!==void 0;l.textContent=u?ys(d):hn(d,l.dataset.due!==void 0),l.classList.toggle("countdown-missed",u),r(d)}a-i<=1e3&&a!==n&&(n=a,ft(a,s,t))};return mt(1e3,s,t),s}var Le=(e,t)=>e.conditions.some(n=>n.kind===t);function he(e,t){return e.conditions.find(n=>n.kind===t)}var Ze=(e,t)=>e.actions.some(n=>n.name===t);function Dt(e,t){let n=new Set(e.map(s=>s.id));return[...e.map(s=>t.get(s.id)??s),...[...t.values()].filter(s=>!n.has(s.id))]}function gn(e){return Le(e,"wedged")||Le(e,"refused")}function Ut(e){let t=e.delivered||0,n=[];e.complained&&n.push(`${e.complained.toLocaleString()} complained`),e.bounced&&n.push(`${e.bounced.toLocaleString()} bounced`),e.unsent&&n.push(`${e.unsent.toLocaleString()} unsent`);let s=n.length?o`<span class="muted delivered-note">${n.map((i,a)=>o`${a?", ":""}<span class="delivered-kind">${i}</span>`)}</span>`:null;return o`<span class="n">${t.toLocaleString()}</span>${s}`}function Ft(e){if(e===null)return"it is retried on its own";let t=e-Date.now();return t>0?`next retry in ${ws(t)}`:"next retry due now"}function xs(e,{stuckNote:t=!0}={}){let n=e.counts,s=n.accepted+n.delivered+n.bounced+n.complained,i=n.delivered+n.bounced+n.complained,a=e.audience.count,r=a>0?100*s/a:0,l=e.dispatch.eta_ms?` \xB7 ~${ws(e.dispatch.eta_ms)} left`:"",d=t?he(e,"stuck"):void 0,u=e.provider.halt,m=e.phase==="backing_off"&&u?.reason==="unavailable",w=m?"Backing off":"Sending",h=m?` \xB7 provider unavailable, ${Ft(u.retry_at)}`:"";return o`<div class="card spread clickable active-card" data-watch="${e.id}">
|
|
47
47
|
<div class="active-main">
|
|
48
48
|
<a class="card-link active-subj" href="#/sent/${e.id}">${e.subject||o`<em>untitled</em>`}</a>
|
|
49
|
-
<div class="active-bar"><div class="active-fill" style="width:${
|
|
50
|
-
<div class="muted active-stat">${
|
|
49
|
+
<div class="active-bar"><div class="active-fill" style="width:${bn(r)}%"></div></div>
|
|
50
|
+
<div class="muted active-stat">${w}: ${s.toLocaleString()} of ${a.toLocaleString()} accepted${i?` \xB7 ${i.toLocaleString()} confirmed`:""}${l}${h}</div>
|
|
51
51
|
${d?o`<div class="active-stuck">${d.message}</div>`:null}
|
|
52
52
|
</div>
|
|
53
53
|
<a class="ghost-link" href="#/sent/${e.id}">Watch →</a>
|
|
54
54
|
</div>`}function qt(e){let t=new URLSearchParams;e.status&&t.set("status",e.status),e.suppressed&&t.set("suppressed",e.suppressed),e.failures&&t.set("failures",e.failures);let n=(e.search||"").trim();return n&&t.set("search",n),e.sort&&(t.set("sort",e.sort),t.set("dir",e.dir??"desc")),t.set("limit",String(e.limit)),t.set("offset",String(e.offset)),t.toString()}function jt(e){let t=e.statuses?.length?o`<select class="lt-status" aria-label="Filter by status"><option value="${e.allValue||""}">All statuses</option>${e.statuses.map(i=>o`<option value="${i.value}">${i.label}</option>`)}</select>`:null,n=e.suppressible?o`<label class="lt-toggle"><input type="checkbox" class="lt-suppressed"><span>Suppressed</span></label>`:null,s=e.failures?o`<label class="lt-toggle"><input type="checkbox" class="lt-failures"><span>With delivery failures</span></label>`:null;return o`<div class="list-toolbar">
|
|
55
55
|
<input class="lt-search" type="search" placeholder="${e.searchPlaceholder||"Search\u2026"}" aria-label="Search" autocomplete="off">
|
|
56
56
|
<div class="lt-filters">${t}${n}${s}</div>
|
|
57
|
-
</div>`}function Wt(e,t,n){let s=e.querySelector(".lt-search"),i=e.querySelector(".lt-status"),a=e.querySelector(".lt-suppressed"),r=e.querySelector(".lt-failures");if(s){s.value=t.search||"";let l;s.oninput=()=>{clearTimeout(l),l=setTimeout(()=>{t.search=s.value,t.offset=0,n()},250)}}i&&(i.value=t.status||"",i.onchange=()=>{t.status=i.value,t.offset=0,n()}),a&&(a.checked=t.suppressed==="only",a.onchange=()=>{t.suppressed=a.checked?"only":"",t.offset=0,n()}),r&&(r.checked=t.failures==="only",r.onchange=()=>{t.failures=r.checked?"only":"",t.offset=0,n()})}function $e(e,t,n,s){if(!t)return s?o`<th class="${s}">${e}</th>`:o`<th>${e}</th>`;let i=n.sort===t,a=i?n.dir==="asc"?"\u2191":"\u2193":"",r=`${s?`${s} `:""}sortable${i?" sorted":""}`;return o`<th class="${r}"><button type="button" class="th-sort" data-sort="${t}">${e}<span class="th-arrow" aria-hidden="true">${a}</span></button></th>`}function st(e,t,n){for(let s of e.querySelectorAll(".th-sort"))s.onclick=()=>{let i=s.dataset.sort;t.sort===i?t.dir=t.dir==="asc"?"desc":"asc":(t.sort=i,t.dir="desc"),t.offset=0,n()}}function ot(e,t,n,s){let i=n?.limit??t.limit;if(!n||n.total<=i){
|
|
58
|
-
${jt({statuses:
|
|
57
|
+
</div>`}function Wt(e,t,n){let s=e.querySelector(".lt-search"),i=e.querySelector(".lt-status"),a=e.querySelector(".lt-suppressed"),r=e.querySelector(".lt-failures");if(s){s.value=t.search||"";let l;s.oninput=()=>{clearTimeout(l),l=setTimeout(()=>{t.search=s.value,t.offset=0,n()},250)}}i&&(i.value=t.status||"",i.onchange=()=>{t.status=i.value,t.offset=0,n()}),a&&(a.checked=t.suppressed==="only",a.onchange=()=>{t.suppressed=a.checked?"only":"",t.offset=0,n()}),r&&(r.checked=t.failures==="only",r.onchange=()=>{t.failures=r.checked?"only":"",t.offset=0,n()})}function $e(e,t,n,s){if(!t)return s?o`<th class="${s}">${e}</th>`:o`<th>${e}</th>`;let i=n.sort===t,a=i?n.dir==="asc"?"\u2191":"\u2193":"",r=`${s?`${s} `:""}sortable${i?" sorted":""}`;return o`<th class="${r}"><button type="button" class="th-sort" data-sort="${t}">${e}<span class="th-arrow" aria-hidden="true">${a}</span></button></th>`}function st(e,t,n){for(let s of e.querySelectorAll(".th-sort"))s.onclick=()=>{let i=s.dataset.sort;t.sort===i?t.dir=t.dir==="asc"?"desc":"asc":(t.sort=i,t.dir="desc"),t.offset=0,n()}}function ot(e,t,n,s){let i=n?.limit??t.limit;if(!n||n.total<=i){f(e,o``);return}let a=n.offset+1,r=Math.min(n.offset+i,n.total),l=n.offset>0,d=n.offset+i<n.total;if(f(e,o`<div class="pager"><button type="button" class="pager-prev"${l?null:Fr}>← Prev</button><span class="pager-range muted">${a}–${r} of ${n.total}</span><button type="button" class="pager-next"${d?null:Fr}>Next →</button></div>`),l){let u=e.querySelector(".pager-prev");u&&(u.onclick=()=>{t.offset=Math.max(0,n.offset-i),s()})}if(d){let u=e.querySelector(".pager-next");u&&(u.onclick=()=>{t.offset=n.offset+i,s()})}}var Fr=o` disabled`;var hd=3600,bd=300,gd=3,_o=new WeakMap;function U(e){let t=[...co.querySelectorAll(".toast:not(.leaving)")],n=t.find(i=>i.textContent===e);if(n){qr(n);return}let s=document.createElement("div");s.className="toast",s.textContent=e,co.appendChild(s),requestAnimationFrame(()=>s.classList.add("show")),qr(s);for(let i of t.slice(0,t.length+1-gd))Wr(i)}function qr(e){clearTimeout(_o.get(e)),_o.set(e,window.setTimeout(()=>Wr(e),hd))}function Wr(e){clearTimeout(_o.get(e)),e.style.height=`${e.offsetHeight}px`,e.offsetHeight,e.classList.add("leaving"),e.style.height="0",setTimeout(()=>e.remove(),bd)}var Je=e=>o`<span class="badge ${e}">${e}</span>`,vd=0,ko=new WeakMap;function Vr(e){let t=document.createElement("div");t.className="field-error",t.id=`field-error-${++vd}`,t.setAttribute("role","alert");let n=document.createElement("span");n.className="field-error-ico",n.setAttribute("aria-hidden","true"),n.textContent="!";let s=document.createElement("span");return s.textContent=e,t.append(n,s),t}function Ne(e,t,{after:n}={}){ko.get(e)?.();let s=Vr(t),i=e.getAttribute("aria-describedby");(n??e).after(s),e.setAttribute("aria-describedby",i?`${i} ${s.id}`:s.id),e.classList.add("is-invalid");let a=!1,r=()=>{a||(a=!0,s.remove(),e.classList.remove("is-invalid"),i===null?e.removeAttribute("aria-describedby"):e.setAttribute("aria-describedby",i),e.removeEventListener("input",r),e.removeEventListener("change",r),ko.delete(e))};return e.addEventListener("input",r),e.addEventListener("change",r),ko.set(e,r),r}function me(e,t){let n=document.createElement("div");n.className="modal-backdrop",f(n,o`<div class="modal" role="dialog" aria-modal="true">${e}</div>`);let s=n.firstElementChild,i=document.activeElement instanceof HTMLElement?document.activeElement:null,a=m=>{n===[...document.querySelectorAll(".modal-backdrop")].pop()&&(m.key==="Escape"?u():m.key==="Tab"&&wd(s,m))},r=null,l=()=>{r?.(),r=null},d=(m,w)=>{if(l(),w){r=Ne(w,m),w.focus();return}let h=Vr(m);h.classList.add("dialog-error");let p=s.querySelector(".actions");p?p.before(h):s.append(h),r=()=>h.remove()},u=()=>{let m=document.activeElement,w=n.contains(m)||!m||m===document.body;n.remove(),document.removeEventListener("keydown",a),t.removeEventListener("abort",u),w&&i?.isConnected&&i.focus()};return t.aborted?{el:n,close:u,error:d,clearError:l}:(document.body.appendChild(n),n.addEventListener("click",m=>{m.target===n&&u()}),document.addEventListener("keydown",a),t.addEventListener("abort",u,{once:!0}),queueMicrotask(()=>{n.isConnected&&!s.contains(document.activeElement)&&Kr(s)[0]?.focus()}),{el:n,close:u,error:d,clearError:l})}var yd='a[href], button:not([disabled]), input:not([disabled]):not([type="hidden"]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';function Kr(e){return[...e.querySelectorAll(yd)].filter(t=>!t.closest("[hidden]"))}function wd(e,t){let n=Kr(e),s=n[0],i=n[n.length-1];if(!s||!i){t.preventDefault();return}let a=document.activeElement;e.contains(a)?t.shiftKey&&a===s?(t.preventDefault(),i.focus()):!t.shiftKey&&a===i&&(t.preventDefault(),s.focus()):(t.preventDefault(),s.focus())}var jr=8;function Sd(e){let t=getComputedStyle(e,"::after"),n=parseFloat(t.width)+parseFloat(t.paddingLeft)+parseFloat(t.paddingRight);if(!Number.isFinite(n))return;let s=e.getBoundingClientRect().left,i=document.documentElement.clientWidth,a=Math.min(0,Math.max(i-jr-n-s,jr-s));e.style.setProperty("--tip-x",`${Math.round(a)}px`)}function Gr(){for(let e of["pointerover","focusin"])document.addEventListener(e,t=>{let n=t.target instanceof Element?t.target.closest(".info"):null;n&&Sd(n)});document.addEventListener("keydown",e=>{let t=document.activeElement;e.key==="Escape"&&t instanceof HTMLElement&&t.classList.contains("info")&&t.blur()})}var ks=[],To=null,Vt=null;function St(){let e=ks.some(t=>t.contains(document.activeElement));for(let t of ks)t.remove();ks=[],To?.removeEventListener("abort",St),To=null,Vt?.setAttribute("aria-expanded","false"),e&&Vt?.isConnected&&Vt.focus(),Vt=null}function Kt(e,t,n,{align:s="end"}={}){if(St(),n.aborted)return;let i=document.createElement("div");i.className="menu-overlay",i.onclick=St;let a=document.createElement("div");a.className="menu",a.setAttribute("role","menu");for(let l of t){let d=document.createElement("button");if(d.type="button",d.setAttribute("role","menuitem"),d.tabIndex=-1,d.className=`menu-item${l.danger?" danger-item":""}`,l.description){let u=document.createElement("span");u.className="menu-item-name",u.textContent=l.label;let m=document.createElement("span");m.className="menu-item-desc",m.textContent=l.description,d.append(u,m),a.classList.add("menu-described")}else d.textContent=l.label;d.onclick=()=>{St(),l.onClick()},a.appendChild(d)}a.addEventListener("keydown",l=>$d(a,l)),document.body.appendChild(i),document.body.appendChild(a),ks=[i,a],To=n,Vt=e instanceof HTMLElement?e:null,Vt?.setAttribute("aria-expanded","true"),n.addEventListener("abort",St,{once:!0});let r=e.getBoundingClientRect();a.style.top=`${r.bottom+window.scrollY+4}px`,a.style.left=`${(s==="start"?r.left:r.right-a.offsetWidth)+window.scrollX}px`,a.querySelector(".menu-item")?.focus()}function $d(e,t){let n=[...e.querySelectorAll(".menu-item")],s=n.indexOf(document.activeElement),i=a=>{t.preventDefault(),n[(a+n.length)%n.length]?.focus()};t.key==="ArrowDown"?i(s+1):t.key==="ArrowUp"?i(s-1):t.key==="Home"?i(0):t.key==="End"?i(n.length-1):t.key==="Escape"?(t.preventDefault(),t.stopPropagation(),St()):t.key==="Tab"&&St()}async function Y(e,t,n){let s=e.textContent;e.disabled=!0,t&&(e.textContent=t);try{return await n()}finally{e.isConnected&&(e.disabled=!1,e.textContent=s)}}function ie(e,t,n){f(e,o`<div class="error"><span>${t}</span><button class="ghost" data-retry>Retry</button></div>`);let s=e.querySelector("[data-retry]");s&&(s.onclick=n)}function Gt(e,t){return e.actions.find(n=>n.name===t)}function vn(e){let t=e.send;return t&&(t.status==="scheduled"||t.status==="sending")?t:null}var Ed=[{value:"draft",label:"Draft"},{value:"scheduled",label:"Scheduled"}],Lo="draft,scheduled";function Ro(e){return Y(e,"Creating\u2026",async()=>{try{let{post:t}=await T("/api/posts",{method:"POST",json:{}});location.hash=`#/edit/${t.id}`}catch(t){U(q(t))}})}async function Co(e,t){oe(t,"Drafts");let n={status:Lo,search:"",sort:"",dir:"desc",offset:0,limit:50};f(e,o`<div class="spread page-head"><h1>Drafts</h1><button class="primary" id="newPost">New post</button></div>
|
|
58
|
+
${jt({statuses:Ed,allValue:Lo,searchPlaceholder:"Search subject\u2026"})}
|
|
59
59
|
<div id="list"><p class="muted">Loading…</p></div>
|
|
60
|
-
<div id="postsPager"></div>`);let s=c("#newPost",e);s.onclick=()=>_o(s);let i=c("#list",e),a=c("#postsPager",e),r=new Map,l=0,d=()=>u(!1);async function u(p){let v=++l;try{let x=await R(`/api/posts?${qt(n)}`,{signal:t});if(v!==l)return null;let M=x.posts;if(r=new Map(M.map(A=>[A.id,gn(A)])),!M.length){let A=n.search||n.status&&n.status!==ko;return h(i,o`<p class="muted">${A?"No drafts match.":"No drafts yet. Create your first draft."}</p>`),h(a,o``),x}h(i,o`<div class="table-wrap"><table class="list-table posts-table stacks has-actions"><colgroup><col><col class="c-status"><col class="c-date"><col class="c-date"><col class="c-act"></colgroup><thead><tr>${$e("Title","subject",n)}${$e("Status",null,n)}${$e("Scheduled","send.fire_at",n)}${$e("Updated","updated_at",n)}<th></th></tr></thead><tbody>${M.map(A=>{let H=gn(A),T=H?.status==="sending",m=H&&T?`#/sent/${H.id}`:`#/edit/${A.id}`,y=H?.fire_at??null,C=Gt(A,"delete")?"1":"";return o`<tr class="clickable" data-id="${A.id}" data-target="${m}"><td>${wt(o`<a href="${m}">${A.subject||o`<em>untitled</em>`}</a>`,A)}</td><td>${T?Je("sending"):Je(A.status)}</td><td class="muted when${y?"":" empty"}">${y?W(y):"\u2014"}</td><td class="muted updated">${W(A.updated_at)}</td><td class="act"><button class="icon" data-menu="${A.id}" data-status="${T?"sending":A.status}" data-delete="${C}" data-target="${m}" aria-label="Post actions" aria-haspopup="menu">⋯</button></td></tr>`})}</tbody></table></div>`),st(i,n,d);for(let A of I("tr[data-id]",i))A.onclick=H=>{let T=H.target;T instanceof Element&&T.tagName!=="A"&&!T.closest("[data-menu]")&&A.dataset.target&&(location.hash=A.dataset.target)};for(let A of I("[data-menu]",i))A.onclick=H=>{H.stopPropagation();let T=A.dataset.status,m=A.dataset.target??"",y=[{label:T==="sending"?"Watch send":"Open",onClick:()=>{location.hash=m}}];if(A.dataset.delete&&A.dataset.menu){let C=A.dataset.menu;y.push({label:"Delete draft",danger:!0,onClick:()=>fd(C,d,t)})}Kt(A,y,t)};return ot(a,n,x.page,d),x}catch(x){return!p&&v===l&&oe(i,F(x),()=>f?d():void b()),null}}let f=!1,S=p=>{f=!0,Ot({cursor:p.cursor,sends:[]},{update({sends:v,removed:x}){let M=new Set([...r.values()].flatMap(H=>H?.id??[]));(v.some(H=>r.has(H.post_id)&&md(r.get(H.post_id)??null,H))||x.some(H=>M.has(H)))&&u(!0)},stale:()=>ee(To)},t)},b=async()=>{let p=await u(!1);p&&!f&&S(p)};Wt(e,n,d),await b()}function md(e,t){return e?.id===t.id?t.status!==e.status||t.fire_at!==e.fire_at:t.status==="scheduled"||t.status==="sending"}function fd(e,t,n){let s=pe(o`<h3>Delete draft?</h3><p class="hint">This permanently deletes the draft and its revisions. This can’t be undone.</p><div class="actions"><button type="button" id="dCancel">Cancel</button><button type="button" class="danger" id="dGo">Delete</button></div>`,n),i=c("#dGo",s.el);c("#dCancel",s.el).onclick=s.close,i.onclick=()=>G(i,"Deleting\u2026",async()=>{s.clearError();try{await R(`/api/posts/${e}`,{method:"DELETE"}),s.close(),O("Draft deleted"),t()}catch(a){s.error(F(a))}})}var Lo={pending:"Subscribed but hasn\u2019t clicked the confirmation email.",confirmed:"Receives your posts. They confirmed here, or opted in at the service you imported them from.",unsubscribed:"Left the list. They\u2019re sent nothing until they sign up again, or, unless they left by a complaint or an erasure, you add them back and they confirm."},qr={reader:"They unsubscribed themselves, from the link or the button in your email.",publisher:"You unsubscribed them, when they asked you to.",complaint:"They reported your email as spam. Only their own sign-up brings them back, so you can\u2019t add them: ask them to subscribe through your subscribe page.",erased:"You erased them at their request. Only the address is kept, so it isn\u2019t mailed again, and only their own sign-up brings them back.",import:"The list you imported says they left, without saying why."},jr="The address isn\u2019t sent your posts, whatever its status. The status stays as it was, greyed while the suppression keeps it from taking effect.",qe={bounce:"bounced",import_bounce:"bounced",manual:"blocked"},vn={bounced:"Mail to the address failed, here or at the service it was imported from. You can clear it.",blocked:"Stopped by hand, by you or at the service it was imported from. You can unblock it."},it={unsubscribe:{label:"Unsubscribe",when:"When they ask you to take them off the list. They can rejoin by subscribing again."},block:{label:"Block",when:"When you decide yourself to stop mailing an address. Their status stays as it was, and you can unblock it."},unblock:{label:"Unblock",when:"When you decide to mail an address you blocked again. They receive your posts only if they\u2019re confirmed."},clear:{label:"Clear",when:"When you know a bounce\u2019s cause is gone, such as a reader who tells you their mailbox is fixed. Mail goes again to an address that failed."},erase:{label:"Erase",when:"When they ask you to delete their data. They\u2019re unsubscribed and only their address is kept. It can\u2019t be undone, and they come back only by subscribing themselves."}};function xs(e,t){let n=ve(),s=pe(o`<h3>Add subscriber</h3><p class="hint">Starts the normal double opt-in: they get a confirmation email and won’t receive posts until they confirm.</p>${Vi()}${n?null:o`<label for="addEmail">Email address</label><input type="email" id="addEmail" placeholder="person@example.com">`}<div class="actions"><button type="button" id="aCancel">Cancel</button><button type="button" class="primary" id="aGo">Send confirmation</button></div>`,t),i=c("#aGo",s.el);if(c("#aCancel",s.el).onclick=s.close,i.disabled=n,n){c("#aCancel",s.el).focus();return}let a=c("#addEmail",s.el);a.focus(),i.onclick=()=>G(i,"Adding\u2026",async()=>{s.clearError();let r=gt(a.value);if(!vt(r)){s.error("Enter a valid email address",a);return}try{let l=await R("/api/subscribers",{method:"POST",json:{email:r}});s.close(),O(hd(r,l.action)),e()}catch(l){s.error(F(l),l instanceof te&&l.field==="email"?a:void 0)}})}function hd(e,t){switch(t){case"already_confirmed":return`${e} is already confirmed`;case"suppressed":return`${e} is suppressed, so no confirmation was sent`;case"recently_sent":return`A confirmation went to ${e} a few minutes ago; try again later`;default:return`Confirmation sent to ${e}`}}function Wr(e,t,n){let s=pe(o`<h3>Unsubscribe this subscriber?</h3><p class="hint">Use this when <strong>${e.email}</strong> asks you to take them off the list. They stop receiving posts immediately, and can rejoin by subscribing again. To stop mailing them on your own judgment, block the address instead.</p><div class="actions"><button type="button" id="uCancel">Cancel</button><button type="button" class="danger" id="uGo">Unsubscribe</button></div>`,n),i=c("#uGo",s.el);c("#uCancel",s.el).onclick=s.close,i.onclick=()=>G(i,"Unsubscribing\u2026",async()=>{s.clearError();try{await R(`/api/subscribers/${e.id}/unsubscribe`,{method:"POST"}),s.close(),O(`Unsubscribed ${e.email}`),t()}catch(a){s.error(F(a))}})}function Vr(e,t,n){let s=pe(o`<h3>Block this address?</h3><p class="hint">Stops all mail to <strong>${e.email}</strong>, whatever their status, which stays as it is. Use this when you decide yourself to stop mailing them; if they asked to leave, unsubscribe them instead. You can unblock it later.</p><div class="actions"><button type="button" id="bCancel">Cancel</button><button type="button" class="danger" id="bGo">Block</button></div>`,n),i=c("#bGo",s.el);c("#bCancel",s.el).onclick=s.close,i.onclick=()=>G(i,"Blocking\u2026",async()=>{s.clearError();try{let a=await R("/api/suppressions",{method:"POST",json:{email:e.email}});s.close(),O(a.added?`Blocked ${e.email}`:`${e.email} was already suppressed (${qe[a.suppression.reason]})`),t()}catch(a){s.error(F(a))}})}function Kr(e,t,n){let s=e.status==="confirmed"?"They\u2019re confirmed, so they\u2019ll receive your posts again.":"They\u2019ll receive posts again only once they\u2019re confirmed.",i=pe(o`<h3>Unblock this address?</h3><p class="hint">Undoes the block on <strong>${e.email}</strong>. ${s}</p><div class="actions"><button type="button" id="ubCancel">Cancel</button><button type="button" class="primary" id="ubGo">Unblock</button></div>`,n),a=c("#ubGo",i.el);c("#ubCancel",i.el).onclick=i.close,a.onclick=()=>G(a,"Unblocking\u2026",async()=>{i.clearError();try{await Gr(e),i.close(),O(`Unblocked ${e.email}`),t()}catch(r){i.error(F(r))}})}function Gr(e){return R("/api/suppressions/lift",{method:"POST",json:{email:e.email,reason:e.suppression?.reason}})}function zr(e,t,n){let s=e.status==="confirmed"?"They\u2019re confirmed, so they\u2019ll receive your posts again.":"They\u2019ll receive posts again only once they\u2019re confirmed.",i=pe(o`<h3>Clear this bounce?</h3><p class="hint">Lets mail go again to <strong>${e.email}</strong>, an address where mail failed. Clear it only when you know the reason is gone, such as a reader who tells you their mailbox is fixed. ${s}</p><div class="actions"><button type="button" id="cCancel">Cancel</button><button type="button" class="danger" id="cGo">Clear</button></div>`,n),a=c("#cGo",i.el);c("#cCancel",i.el).onclick=i.close,a.onclick=()=>G(a,"Clearing\u2026",async()=>{i.clearError();try{await Gr(e),i.close(),O(`Cleared the bounce on ${e.email}`),t()}catch(r){i.error(F(r))}})}function Yr(e,t,n){let s=pe(o`<h3>Erase this subscriber?</h3><p class="hint">Unsubscribes <strong>${e.email}</strong> and deletes how they joined and the evidence for it, and past sends show an erased recipient in its place. Only the address is kept, so it’s never mailed again. This can’t be undone. They can still rejoin by subscribing and confirming themselves, but you can’t add them back.</p><div class="actions"><button type="button" id="eCancel">Cancel</button><button type="button" class="danger" id="eGo">Erase</button></div>`,n),i=c("#eGo",s.el);c("#eCancel",s.el).onclick=s.close,i.onclick=()=>G(i,"Erasing\u2026",async()=>{s.clearError();try{let a=await R(`/api/subscribers/${e.id}/erase`,{method:"POST"});s.close(),O(gd(a)),t()}catch(a){s.error(F(a))}})}var bd={bounce:"bounce",import_bounce:"bounce",manual:"block"};function gd({subscriber:e}){let t=e.suppression;return t?`Erased ${e.email}. Its ${bd[t.reason]??"suppression"} still stands`:`Erased ${e.email}`}var vd=1500;function Te(e=!1,t="Copy"){return o`<span>${t}</span>${N(e?"check":"copyout")}`}function yn(e,t){return o`<button type="button" class="copy-btn" data-copy="${e}" aria-label="${t}">${Te()}</button>`}function zt(e,t,n){return o`<div class="block code-block"><div class="block-head"><span class="block-label">${e}</span>${yn(n,`Copy ${e}`)}</div><pre><code>${t}</code></pre></div>`}function Zr(e,t){return o`<div class="code-bare"><pre><code>${e}</code></pre><button type="button" class="copy-btn" data-copy="${t}" data-copy-word="" aria-label="Copy" title="Copy">${Te(!1,"")}</button></div>`}var Ro=new WeakMap;async function wn(e,t){try{await navigator.clipboard.writeText(t)}catch{O("Couldn\u2019t copy to clipboard");return}let n=Ro.get(e),s=n?.label??e.getAttribute("aria-label")??"Copy",i=e.dataset.copyWord;window.clearTimeout(n?.timer),h(e,Te(!0,i)),e.setAttribute("aria-label","Copied"),e.classList.add("copied");let a=window.setTimeout(()=>{h(e,Te(!1,i)),e.setAttribute("aria-label",s),e.classList.remove("copied"),Ro.delete(e)},vd);Ro.set(e,{label:s,timer:a})}function je(e){e.addEventListener("click",t=>{let n=t.target instanceof Element?t.target.closest("[data-copy]"):null;n&&e.contains(n)&&wn(n,n.dataset.copy??"")})}function yd(e,t=!1){let n=[],s=e.filter(m=>Le(m,"missed"));s.length&&n.push({level:"red",text:`${s.length} scheduled send${s.length===1?"":"s"} passed the fire time without going out.`});let i=e.flatMap(m=>{let y=he(m,"wedged");return y?[{s:m,count:y.count}]:[]}),[a]=i;if(a){let m=i.reduce((C,U)=>C+U.count,0),y=m===1?"delivery":"deliveries";n.push({level:"red",text:i.length===1?o`<a href="#/sent/${a.s.id}">${a.s.subject}</a> has ${m} ambiguous ${y} awaiting a decision; resolve ${m===1?"it":"them"} on its page.`:o`${m} ambiguous ${y} across <a href="#/sent">${i.length} sends</a> await a decision; resolve them on the Sent page.`})}let r=ve(),l=e.flatMap(m=>{let y=he(m,"refused");return y?[{s:m,c:y}]:[]}),d=r?l.filter(m=>m.c.cause==="not_connected"):[],u=l.filter(m=>!d.includes(m)),f=m=>m.length===1&&m[0]?o`<a href="#/sent/${m[0].s.id}">${m[0].s.subject}</a>`:o`<a href="#/sent">${m.length} sends</a>`;d.length&&n.push({level:"red",text:o`<span class="dash-not-connected">${is(f(d),d.length)}</span>`});let[S]=u;S&&n.push({level:"red",text:o`${f(u)}: ${S.c.message}`});let b=e.filter(m=>Le(m,"stuck")&&!bn(m)),[p]=b;p&&n.push({level:"amber",text:b.length===1?o`<a href="#/sent/${p.id}">${p.subject}</a>: ${he(p,"stuck")?.message}`:o`<a href="#/sent">${b.length} sends</a> have handed off no one for a while, with no retry or provider problem to explain it.`});let v=e.flatMap(m=>{let y=he(m,"provider_unavailable");return y?.severity==="warn"?[{s:m,c:y}]:[]}),[x]=v;x&&n.push({level:"amber",text:o`<a href="#/sent/${x.s.id}">${x.s.subject}</a>: ${x.c.message}`});let M=e.flatMap(m=>{let y=he(m,"bounce_spike");return y?[{s:m,c:y}]:[]}),[A]=M;A&&n.push({level:"amber",text:o`<a href="#/sent/${A.s.id}">${A.s.subject}</a>: ${A.c.message}`});let H=e.flatMap(m=>{let y=he(m,"no_receipts");return y?[{s:m,c:y}]:[]}),[T]=H;return T&&n.push({level:"amber",text:H.length===1?o`<a href="#/sent/${T.s.id}">${T.s.subject}</a>: ${T.c.message}`:o`<a href="#/sent">${H.length} sends</a> have had no delivery receipt long after they went out. The provider's events may not be reaching this app, so its bounces suppress no one and its complaints unsubscribe no one.`}),r&&!d.length&&!t&&n.push({level:"amber",text:o`<span class="dash-not-connected">No email provider connected, so nothing can be sent yet. ${Ae()} to start sending.</span>`}),n}function wd(e){if(!e.length)return o``;let t=e.some(n=>n.level==="red")?"red":"amber";return o`<div class="health ${t}"><span class="health-dot">⚠️</span><div>${e.map(n=>o`<div>${n.text}</div>`)}</div></div>`}var Jr=e=>e.filter(t=>t.status==="sending"&&!bn(t));async function Co(e,t){se(t,"Dashboard");let n=()=>{t.aborted||ee(Co)};h(e,o`<div class="dash" id="dash"><p class="muted">Loading…</p></div>`);let s=c("#dash",e),i,a,r,l;try{let[_,K,D]=await Promise.all([R("/api/posts?limit=200",{signal:t}),R("/api/sends?limit=200",{signal:t}),R("/api/subscribers",{signal:t})]);i=_.posts,a=K,r=D.counts,l=D.workers_plan_advice}catch(_){oe(s,F(_),n);return}let d=a.sends,u=new Map,f=mo(Q.appConfig),S=Q.appConfig?.deployment??null,b=()=>d.some(_=>(_.status==="sending"||_.status==="sent")&&!_.email_only),p=()=>({named:!!Q.appConfig?.settings.publication?.name?.trim(),onList:r.confirmed+r.pending,archived:b()});if(!i.length){h(s,o`<div class="dash-head"><div><h1>${f.name}</h1>${f.tagline?o`<p class="muted dash-tagline">${f.tagline}</p>`:null}<p class="muted">Let’s get your first post out the door.</p></div></div>${aa(f,S,p(),"checklist")}<section class="dash-section"><h2>API access</h2>${ra(!1)}</section>`),ia(s,n,t);return}let v=()=>!b(),x=()=>v()?aa(f,S,p(),"card"):o``,M=()=>wd(yd(Dt(d,u),v()&&ve())),A=[{label:"Confirmed",emph:!0,v:r.confirmed,filter:"confirmed"},{label:"Pending",v:r.pending,filter:"pending"},{label:"Unsubscribed",v:r.unsubscribed,filter:"unsubscribed"},{label:"Suppressed",v:r.suppressed,filter:"suppressed"}],H=o`<div class="tiles">${A.map(_=>o`<a class="tile${_.emph?" tile-emph":""}" href="#/subscribers/${_.filter}"><span class="tile-n">${_.v}</span><span class="tile-label">${_.label}${_.sub?o`<span class="tile-sub">${_.sub}</span>`:null}</span></a>`)}</div>`,T=i.filter(_=>_.status==="draft").slice(0,5),m=T.length?o`<div class="table-wrap"><table class="dash-drafts"><tbody>${T.map(_=>o`<tr class="clickable" data-id="${_.id}"><td>${wt(o`<a href="#/edit/${_.id}">${_.subject||o`<em>untitled</em>`}</a>`,_)}</td><td class="muted edited">edited ${W(_.updated_at)}</td></tr>`)}</tbody></table></div>`:o`<p class="muted">No drafts in progress.</p>`,y=S?.app_origin||location.origin,C=o`<div class="card pub-card">
|
|
61
|
-
<div class="pub-row"><code class="pub-val">${
|
|
60
|
+
<div id="postsPager"></div>`);let s=c("#newPost",e);s.onclick=()=>Ro(s);let i=c("#list",e),a=c("#postsPager",e),r=new Map,l=0,d=()=>u(!1);async function u(p){let S=++l;try{let E=await T(`/api/posts?${qt(n)}`,{signal:t});if(S!==l)return null;let I=E.posts;if(r=new Map(I.map(C=>[C.id,vn(C)])),!I.length){let C=n.search||n.status&&n.status!==Lo;return f(i,o`<p class="muted">${C?"No drafts match.":"No drafts yet. Create your first draft."}</p>`),f(a,o``),E}f(i,o`<div class="table-wrap"><table class="list-table posts-table stacks has-actions"><colgroup><col><col class="c-status"><col class="c-date"><col class="c-date"><col class="c-act"></colgroup><thead><tr>${$e("Title","subject",n)}${$e("Status",null,n)}${$e("Scheduled","send.fire_at",n)}${$e("Updated","updated_at",n)}<th></th></tr></thead><tbody>${I.map(C=>{let H=vn(C),L=H?.status==="sending",v=H&&L?`#/sent/${H.id}`:`#/edit/${C.id}`,y=H?.fire_at??null,$=Gt(C,"delete")?"1":"";return o`<tr class="clickable" data-id="${C.id}" data-target="${v}"><td>${wt(o`<a href="${v}">${C.subject||o`<em>untitled</em>`}</a>`,C)}</td><td>${L?Je("sending"):Je(C.status)}</td><td class="muted when${y?"":" empty"}">${y?K(y):"\u2014"}</td><td class="muted updated">${K(C.updated_at)}</td><td class="act"><button class="icon" data-menu="${C.id}" data-status="${L?"sending":C.status}" data-delete="${$}" data-target="${v}" aria-label="Post actions" aria-haspopup="menu">⋯</button></td></tr>`})}</tbody></table></div>`),st(i,n,d);for(let C of N("tr[data-id]",i))C.onclick=H=>{let L=H.target;L instanceof Element&&L.tagName!=="A"&&!L.closest("[data-menu]")&&C.dataset.target&&(location.hash=C.dataset.target)};for(let C of N("[data-menu]",i))C.onclick=H=>{H.stopPropagation();let L=C.dataset.status,v=C.dataset.target??"",y=[{label:L==="sending"?"Watch send":"Open",onClick:()=>{location.hash=v}}];if(C.dataset.delete&&C.dataset.menu){let $=C.dataset.menu;y.push({label:"Delete draft",danger:!0,onClick:()=>kd($,d,t)})}Kt(C,y,t)};return ot(a,n,E.page,d),E}catch(E){return!p&&S===l&&ie(i,q(E),()=>m?d():void h()),null}}let m=!1,w=p=>{m=!0,Bt({cursor:p.cursor,sends:[]},{update({sends:S,removed:E}){let I=new Set([...r.values()].flatMap(H=>H?.id??[]));(S.some(H=>r.has(H.post_id)&&xd(r.get(H.post_id)??null,H))||E.some(H=>I.has(H)))&&u(!0)},stale:()=>ee(Co)},t)},h=async()=>{let p=await u(!1);p&&!m&&w(p)};Wt(e,n,d),await h()}function xd(e,t){return e?.id===t.id?t.status!==e.status||t.fire_at!==e.fire_at:t.status==="scheduled"||t.status==="sending"}function kd(e,t,n){let s=me(o`<h3>Delete draft?</h3><p class="hint">This permanently deletes the draft and its revisions. This can’t be undone.</p><div class="actions"><button type="button" id="dCancel">Cancel</button><button type="button" class="danger" id="dGo">Delete</button></div>`,n),i=c("#dGo",s.el);c("#dCancel",s.el).onclick=s.close,i.onclick=()=>Y(i,"Deleting\u2026",async()=>{s.clearError();try{await T(`/api/posts/${e}`,{method:"DELETE"}),s.close(),U("Draft deleted"),t()}catch(a){s.error(q(a))}})}var yn="#/docs/production-access",_d="#/docs/production-access/3-answer-awss-questions",Td="#/docs/ses/5-create-the-apps-aws-key";function Ho(e){return e?.provider==="ses"||!!e?.simulation?.account}async function _s(e,t){if(!Ho(e))return null;try{return await T("/api/provider",{signal:t})}catch{return null}}var Po=e=>e?.state==="sandbox";function Ao(e){let t=e.account?.max_24_hour_send;return typeof t=="number"?`, up to ${t.toLocaleString()} a day`:""}function zr(e,t=null){if(e.state==="production")return o`<span>Amazon SES <span class="set-pill ok" id="providerState">Production</span>${t}</span>`;if(e.state!=="sandbox")return e.unknown_reason==="permission"?o`<span>Amazon SES${t}</span><span class="muted" id="providerUnread">To show whether SES is in the sandbox, Kestrel’s AWS key needs permission to read your account. <a class="set-link" href="${Td}">Add the permission</a></span>`:o`Amazon SES${t}`;let n=o`<span class="set-pill warn" id="providerState">Sandbox</span>`,s=e.review==="pending"?o`AWS is reviewing your request for production access. Until then, it mails only addresses verified in SES${Ao(e)}.`:e.review==="denied"?o`<span class="set-warn">AWS denied production access.${e.review_case?` Its reply is in AWS Support, case ${e.review_case}.`:""}</span> <a class="set-link" href="${_d}">What AWS asks for</a>`:e.review==="failed"?o`<span class="set-warn">AWS didn’t receive your request for production access.</span> <a class="set-link" href="${yn}">Request it again</a>`:o`<span class="set-warn">It mails only addresses verified in SES${Ao(e)}.</span> <a class="set-link" href="${yn}">Request production access</a>`;return o`<span>Amazon SES ${n}${t}</span><span class="muted" id="providerReview">${s}</span>`}var Ld={account:"from your SES account",setting:"set by SES_MAX_SEND_RATE",default:"Kestrel\u2019s default"};function Yr(e){if(!e.send_rate)return null;let{value:t,source:n}=e.send_rate;return o`<span>${t} ${t===1?"email":"emails"} a second${Ao(e)} <span class="muted">(${Ld[n]})</span></span>`}var Rd={bounces_not_routed:"Send bounces and complaints to the app"};function Ts(e){return o`${e.message} <a href="#/docs/${e.docs.slug}/${e.docs.anchor}">${Rd[e.code]}</a>`}function Zr(){return o`Amazon SES is still in the sandbox, so it mails only addresses verified in SES. <a href="${yn}">Request production access</a>`}function Jr(e){return e?.state==="production"?"AWS granted it: SES mails anyone who signs up.":e?.state==="sandbox"&&e.review==="pending"?"AWS is reviewing your request. Until then, SES mails only addresses verified in SES.":e?.state==="sandbox"&&e.review==="denied"?e.review_case?`AWS denied it. Its reply is in AWS Support, case ${e.review_case}.`:"AWS denied it. Its reply is in AWS Support.":e?.state==="sandbox"&&e.review==="failed"?"AWS didn\u2019t receive your request. Ask again.":e?.state==="sandbox"?"SES mails only addresses verified in SES until AWS grants it. Ask once a test email has arrived.":"Ask once a test email has arrived. Kestrel can\u2019t read your SES account, so the SES console\u2019s account dashboard says whether AWS granted it."}var Mo={pending:"Subscribed but hasn\u2019t clicked the confirmation email.",confirmed:"Receives your posts. They confirmed here, or opted in at the service you imported them from.",unsubscribed:"Left the list. They\u2019re sent nothing until they sign up again, or, unless they left by a complaint or an erasure, you add them back and they confirm."},Qr={reader:"They unsubscribed themselves, from the link or the button in your email.",publisher:"You unsubscribed them, when they asked you to.",complaint:"They reported your email as spam. Only their own sign-up brings them back, so you can\u2019t add them: ask them to subscribe through your subscribe page.",erased:"You erased them at their request. Only the address is kept, so it isn\u2019t mailed again, and only their own sign-up brings them back.",import:"The list you imported says they left, without saying why."},Xr="The address isn\u2019t sent your posts, whatever its status. The status stays as it was, greyed while the suppression keeps it from taking effect.",qe={bounce:"bounced",import_bounce:"bounced",manual:"blocked"},wn={bounced:"Mail to the address failed, here or at the service it was imported from. You can clear it.",blocked:"Stopped by hand, by you or at the service it was imported from. You can unblock it."},it={unsubscribe:{label:"Unsubscribe",when:"When they ask you to take them off the list. They can rejoin by subscribing again."},block:{label:"Block",when:"When you decide yourself to stop mailing an address. Their status stays as it was, and you can unblock it."},unblock:{label:"Unblock",when:"When you decide to mail an address you blocked again. They receive your posts only if they\u2019re confirmed."},clear:{label:"Clear",when:"When you know a bounce\u2019s cause is gone, such as a reader who tells you their mailbox is fixed. Mail goes again to an address that failed."},erase:{label:"Erase",when:"When they ask you to delete their data. They\u2019re unsubscribed and only their address is kept. It can\u2019t be undone, and they come back only by subscribing themselves."}};function Ls(e,t){let n=ve(),s=me(o`<h3>Add subscriber</h3><p class="hint">Starts the normal double opt-in: they get a confirmation email and won’t receive posts until they confirm.</p>${Ji()}${n?null:o`<label for="addEmail">Email address</label><input type="email" id="addEmail" placeholder="person@example.com">`}<div class="actions"><button type="button" id="aCancel">Cancel</button><button type="button" class="primary" id="aGo">Send confirmation</button></div>`,t),i=c("#aGo",s.el);if(c("#aCancel",s.el).onclick=s.close,i.disabled=n,n){c("#aCancel",s.el).focus();return}let a=c("#addEmail",s.el);a.focus(),i.onclick=()=>Y(i,"Adding\u2026",async()=>{s.clearError();let r=gt(a.value);if(!vt(r)){s.error("Enter a valid email address",a);return}try{let l=await T("/api/subscribers",{method:"POST",json:{email:r}});s.close(),U(Cd(r,l.action)),e()}catch(l){s.error(q(l),l instanceof te&&l.field==="email"?a:void 0)}})}function Cd(e,t){switch(t){case"already_confirmed":return`${e} is already confirmed`;case"suppressed":return`${e} is suppressed, so no confirmation was sent`;case"recently_sent":return`A confirmation went to ${e} a few minutes ago; try again later`;default:return`Confirmation sent to ${e}`}}function ea(e,t,n){let s=me(o`<h3>Unsubscribe this subscriber?</h3><p class="hint">Use this when <strong>${e.email}</strong> asks you to take them off the list. They stop receiving posts immediately, and can rejoin by subscribing again. To stop mailing them on your own judgment, block the address instead.</p><div class="actions"><button type="button" id="uCancel">Cancel</button><button type="button" class="danger" id="uGo">Unsubscribe</button></div>`,n),i=c("#uGo",s.el);c("#uCancel",s.el).onclick=s.close,i.onclick=()=>Y(i,"Unsubscribing\u2026",async()=>{s.clearError();try{await T(`/api/subscribers/${e.id}/unsubscribe`,{method:"POST"}),s.close(),U(`Unsubscribed ${e.email}`),t()}catch(a){s.error(q(a))}})}function ta(e,t,n){let s=me(o`<h3>Block this address?</h3><p class="hint">Stops all mail to <strong>${e.email}</strong>, whatever their status, which stays as it is. Use this when you decide yourself to stop mailing them; if they asked to leave, unsubscribe them instead. You can unblock it later.</p><div class="actions"><button type="button" id="bCancel">Cancel</button><button type="button" class="danger" id="bGo">Block</button></div>`,n),i=c("#bGo",s.el);c("#bCancel",s.el).onclick=s.close,i.onclick=()=>Y(i,"Blocking\u2026",async()=>{s.clearError();try{let a=await T("/api/suppressions",{method:"POST",json:{email:e.email}});s.close(),U(a.added?`Blocked ${e.email}`:`${e.email} was already suppressed (${qe[a.suppression.reason]})`),t()}catch(a){s.error(q(a))}})}function na(e,t,n){let s=e.status==="confirmed"?"They\u2019re confirmed, so they\u2019ll receive your posts again.":"They\u2019ll receive posts again only once they\u2019re confirmed.",i=me(o`<h3>Unblock this address?</h3><p class="hint">Undoes the block on <strong>${e.email}</strong>. ${s}</p><div class="actions"><button type="button" id="ubCancel">Cancel</button><button type="button" class="primary" id="ubGo">Unblock</button></div>`,n),a=c("#ubGo",i.el);c("#ubCancel",i.el).onclick=i.close,a.onclick=()=>Y(a,"Unblocking\u2026",async()=>{i.clearError();try{await sa(e),i.close(),U(`Unblocked ${e.email}`),t()}catch(r){i.error(q(r))}})}function sa(e){return T("/api/suppressions/lift",{method:"POST",json:{email:e.email,reason:e.suppression?.reason}})}function oa(e,t,n){let s=e.status==="confirmed"?"They\u2019re confirmed, so they\u2019ll receive your posts again.":"They\u2019ll receive posts again only once they\u2019re confirmed.",i=me(o`<h3>Clear this bounce?</h3><p class="hint">Lets mail go again to <strong>${e.email}</strong>, an address where mail failed. Clear it only when you know the reason is gone, such as a reader who tells you their mailbox is fixed. ${s}</p><div class="actions"><button type="button" id="cCancel">Cancel</button><button type="button" class="danger" id="cGo">Clear</button></div>`,n),a=c("#cGo",i.el);c("#cCancel",i.el).onclick=i.close,a.onclick=()=>Y(a,"Clearing\u2026",async()=>{i.clearError();try{await sa(e),i.close(),U(`Cleared the bounce on ${e.email}`),t()}catch(r){i.error(q(r))}})}function ia(e,t,n){let s=me(o`<h3>Erase this subscriber?</h3><p class="hint">Unsubscribes <strong>${e.email}</strong> and deletes how they joined and the evidence for it, and past sends show an erased recipient in its place. Only the address is kept, so it’s never mailed again. This can’t be undone. They can still rejoin by subscribing and confirming themselves, but you can’t add them back.</p><div class="actions"><button type="button" id="eCancel">Cancel</button><button type="button" class="danger" id="eGo">Erase</button></div>`,n),i=c("#eGo",s.el);c("#eCancel",s.el).onclick=s.close,i.onclick=()=>Y(i,"Erasing\u2026",async()=>{s.clearError();try{let a=await T(`/api/subscribers/${e.id}/erase`,{method:"POST"});s.close(),U(Hd(a)),t()}catch(a){s.error(q(a))}})}var Ad={bounce:"bounce",import_bounce:"bounce",manual:"block"};function Hd({subscriber:e}){let t=e.suppression;return t?`Erased ${e.email}. Its ${Ad[t.reason]??"suppression"} still stands`:`Erased ${e.email}`}var Pd=1500;function Te(e=!1,t="Copy"){return o`<span>${t}</span>${O(e?"check":"copyout")}`}function Sn(e,t){return o`<button type="button" class="copy-btn" data-copy="${e}" aria-label="${t}">${Te()}</button>`}function zt(e,t,n){return o`<div class="block code-block"><div class="block-head"><span class="block-label">${e}</span>${Sn(n,`Copy ${e}`)}</div><pre><code>${t}</code></pre></div>`}function ra(e,t){return o`<div class="code-bare"><pre><code>${e}</code></pre><button type="button" class="copy-btn" data-copy="${t}" data-copy-word="" aria-label="Copy" title="Copy">${Te(!1,"")}</button></div>`}var Io=new WeakMap;async function $n(e,t){try{await navigator.clipboard.writeText(t)}catch{U("Couldn\u2019t copy to clipboard");return}let n=Io.get(e),s=n?.label??e.getAttribute("aria-label")??"Copy",i=e.dataset.copyWord;window.clearTimeout(n?.timer),f(e,Te(!0,i)),e.setAttribute("aria-label","Copied"),e.classList.add("copied");let a=window.setTimeout(()=>{f(e,Te(!1,i)),e.setAttribute("aria-label",s),e.classList.remove("copied"),Io.delete(e)},Pd);Io.set(e,{label:s,timer:a})}function je(e){e.addEventListener("click",t=>{let n=t.target instanceof Element?t.target.closest("[data-copy]"):null;n&&e.contains(n)&&$n(n,n.dataset.copy??"")})}function Md(e,t=!1,n=null,s=!1){let i=[],a=e.filter($=>Le($,"missed"));a.length&&i.push({level:"red",text:`${a.length} scheduled send${a.length===1?"":"s"} passed the fire time without going out.`});let r=e.flatMap($=>{let A=he($,"wedged");return A?[{s:$,count:A.count}]:[]}),[l]=r;if(l){let $=r.reduce((W,z)=>W+z.count,0),A=$===1?"delivery":"deliveries";i.push({level:"red",text:r.length===1?o`<a href="#/sent/${l.s.id}">${l.s.subject}</a> has ${$} ambiguous ${A} awaiting a decision; resolve ${$===1?"it":"them"} on its page.`:o`${$} ambiguous ${A} across <a href="#/sent">${r.length} sends</a> await a decision; resolve them on the Sent page.`})}let d=ve(),u=e.flatMap($=>{let A=he($,"refused");return A?[{s:$,c:A}]:[]}),m=d?u.filter($=>$.c.cause==="not_connected"):[],w=u.filter($=>!m.includes($)),h=$=>$.length===1&&$[0]?o`<a href="#/sent/${$[0].s.id}">${$[0].s.subject}</a>`:o`<a href="#/sent">${$.length} sends</a>`;m.length&&i.push({level:"red",text:o`<span class="dash-not-connected">${as(h(m),m.length)}</span>`});let[p]=w;p&&i.push({level:"red",text:o`${h(w)}: ${p.c.message}`});let S=e.filter($=>Le($,"stuck")&&!gn($)),[E]=S;E&&i.push({level:"amber",text:S.length===1?o`<a href="#/sent/${E.id}">${E.subject}</a>: ${he(E,"stuck")?.message}`:o`<a href="#/sent">${S.length} sends</a> have handed off no one for a while, with no retry or provider problem to explain it.`});let I=e.flatMap($=>{let A=he($,"provider_unavailable");return A?.severity==="warn"?[{s:$,c:A}]:[]}),[C]=I;C&&i.push({level:"amber",text:o`<a href="#/sent/${C.s.id}">${C.s.subject}</a>: ${C.c.message}`});let H=e.flatMap($=>{let A=he($,"bounce_spike");return A?[{s:$,c:A}]:[]}),[L]=H;L&&i.push({level:"amber",text:o`<a href="#/sent/${L.s.id}">${L.s.subject}</a>: ${L.c.message}`});let v=e.flatMap($=>{let A=he($,"no_receipts");return A?[{s:$,c:A}]:[]}),[y]=v;y&&i.push({level:"amber",text:v.length===1?o`<a href="#/sent/${y.s.id}">${y.s.subject}</a>: ${y.c.message}`:o`<a href="#/sent">${v.length} sends</a> have had no delivery receipt long after they went out. The provider's events may not be reaching this app, so its bounces suppress no one and its complaints unsubscribe no one.`}),d&&!m.length&&!t&&i.push({level:"amber",text:o`<span class="dash-not-connected">No email provider connected, so nothing can be sent yet. ${Ae()} to start sending.</span>`});for(let $ of n?.warnings??[])i.push({level:"amber",text:o`<span class="dash-provider-warning">${Ts($)}</span>`});return Po(n)&&!s&&i.push({level:"amber",text:o`<span class="dash-sandbox">${Zr()}</span>`}),i}function Id(e){if(!e.length)return o``;let t=e.some(n=>n.level==="red")?"red":"amber";return o`<div class="health ${t}"><span class="health-dot">⚠️</span><div>${e.map(n=>o`<div>${n.text}</div>`)}</div></div>`}var aa=e=>e.filter(t=>t.status==="sending"&&!gn(t));async function No(e,t){oe(t,"Dashboard");let n=()=>{t.aborted||ee(No)};f(e,o`<div class="dash" id="dash"><p class="muted">Loading…</p></div>`);let s=c("#dash",e),i,a,r,l,d;try{let[P,B,ne,j]=await Promise.all([T("/api/posts?limit=200",{signal:t}),T("/api/sends?limit=200",{signal:t}),T("/api/subscribers",{signal:t}),_s(Q.appConfig?.deployment,t)]);d=j,i=P.posts,a=B,r=ne.counts,l=ne.workers_plan_advice}catch(P){ie(s,q(P),n);return}let u=a.sends,m=new Map,w=bo(Q.appConfig),h=Q.appConfig?.deployment??null,p=()=>u.some(P=>(P.status==="sending"||P.status==="sent")&&!P.email_only),S=()=>({named:!!Q.appConfig?.settings.publication?.name?.trim(),onList:r.confirmed+r.pending,archived:p()});if(!i.length){f(s,o`<div class="dash-head"><div><h1>${w.name}</h1>${w.tagline?o`<p class="muted dash-tagline">${w.tagline}</p>`:null}<p class="muted">Let’s get your first post out the door.</p></div></div>${ga(w,h,S(),"checklist",d)}<section class="dash-section"><h2>API access</h2>${ba(!1)}</section>`),ha(s,n,t);return}let E=()=>!p(),I=()=>E()?ga(w,h,S(),"card",d):o``,C=()=>Id(Md(Dt(u,m),E()&&ve(),d,E())),H=[{label:"Confirmed",emph:!0,v:r.confirmed,filter:"confirmed"},{label:"Pending",v:r.pending,filter:"pending"},{label:"Unsubscribed",v:r.unsubscribed,filter:"unsubscribed"},{label:"Suppressed",v:r.suppressed,filter:"suppressed"}],L=o`<div class="tiles">${H.map(P=>o`<a class="tile${P.emph?" tile-emph":""}" href="#/subscribers/${P.filter}"><span class="tile-n">${P.v}</span><span class="tile-label">${P.label}${P.sub?o`<span class="tile-sub">${P.sub}</span>`:null}</span></a>`)}</div>`,v=i.filter(P=>P.status==="draft").slice(0,5),y=v.length?o`<div class="table-wrap"><table class="dash-drafts"><tbody>${v.map(P=>o`<tr class="clickable" data-id="${P.id}"><td>${wt(o`<a href="#/edit/${P.id}">${P.subject||o`<em>untitled</em>`}</a>`,P)}</td><td class="muted edited">edited ${K(P.updated_at)}</td></tr>`)}</tbody></table></div>`:o`<p class="muted">No drafts in progress.</p>`,$=h?.app_origin||location.origin,A=o`<div class="card pub-card">
|
|
61
|
+
<div class="pub-row"><code class="pub-val">${$}</code>${Sn($,"Copy the publication\u2019s address")}</div>
|
|
62
62
|
<div class="pub-foot"><a href="/" target="_blank" rel="noopener">View publication ↗</a></div>
|
|
63
|
-
</div>`,
|
|
63
|
+
</div>`,W=i.some(P=>P.author_client===Yn||P.author_client===Zn),z=ba(W),G=o`<div class="row quick-actions"><button data-act="new-post">New post</button><button data-act="add-sub">Add subscriber</button><button data-nav="#/settings">Edit publication</button></div>`;f(s,o`
|
|
64
64
|
<div class="dash-head">
|
|
65
|
-
<div><h1>${
|
|
65
|
+
<div><h1>${w.name}</h1>${w.tagline?o`<p class="muted dash-tagline">${w.tagline}</p>`:null}</div>
|
|
66
66
|
<button class="primary" data-act="new-post">New post</button>
|
|
67
67
|
</div>
|
|
68
|
-
<div id="dashHealth">${
|
|
69
|
-
<div id="dashSetup">${
|
|
70
|
-
<div id="dashActive">${
|
|
71
|
-
<section class="dash-section"><h2>Subscribers</h2>${
|
|
68
|
+
<div id="dashHealth">${C()}</div>
|
|
69
|
+
<div id="dashSetup">${I()}</div>
|
|
70
|
+
<div id="dashActive">${ma(aa(Dt(u,m)))}</div>
|
|
71
|
+
<section class="dash-section"><h2>Subscribers</h2>${L}${l?o`<p class="workers-plan" id="dashWorkersPlan" role="status">${l}</p>`:null}</section>
|
|
72
72
|
<div class="dash-cols">
|
|
73
|
-
<section class="dash-section"><h2>Scheduled</h2><div id="dashScheduled">${
|
|
74
|
-
<section class="dash-section"><h2>Drafts</h2>${
|
|
73
|
+
<section class="dash-section"><h2>Scheduled</h2><div id="dashScheduled">${ua(la(u))}</div></section>
|
|
74
|
+
<section class="dash-section"><h2>Drafts</h2>${y}</section>
|
|
75
75
|
</div>
|
|
76
|
-
<section class="dash-section"><h2>Sent</h2><div id="dashSent">${
|
|
77
|
-
<section class="dash-section"><h2>Quick actions</h2>${
|
|
76
|
+
<section class="dash-section"><h2>Sent</h2><div id="dashSent">${ca(u)}</div></section>
|
|
77
|
+
<section class="dash-section"><h2>Quick actions</h2>${G}</section>
|
|
78
78
|
<div class="dash-cols">
|
|
79
|
-
<section class="dash-section"><h2>Publication</h2>${
|
|
80
|
-
<section class="dash-section"><h2>API access</h2>${
|
|
81
|
-
</div>`),
|
|
79
|
+
<section class="dash-section"><h2>Publication</h2>${A}</section>
|
|
80
|
+
<section class="dash-section"><h2>API access</h2>${z}</section>
|
|
81
|
+
</div>`),ha(s,n,t);for(let P of N("tr[data-id]",s))P.onclick=B=>{let ne=B.target;ne instanceof Element&&ne.tagName!=="A"&&!ne.closest("button")&&(location.hash=`#/edit/${P.dataset.id}`)};da(s),fa(s),pa(s);let b=Es(s,t);b();let k=0,R=async()=>{let P=++k;try{let B=await T("/api/sends?limit=200",{signal:t});if(P!==k)return;u=B.sends,f(c("#dashScheduled",s),ua(la(u))),pa(s),b(),f(c("#dashSent",s),ca(u)),da(s),f(c("#dashSetup",s),I()),va(c("#dashSetup",s),n,t),x()}catch{}},x=()=>{let P=Dt(u,m);f(c("#dashHealth",s),C()),f(c("#dashActive",s),ma(aa(P))),fa(s),Nd(s,[...m.values()])},F=P=>P==="scheduled"||P==="due";Bt(a,{update:P=>{for(let B of P.sends)m.set(B.id,B);for(let B of P.removed)m.delete(B);x(),(P.changes.length||P.removed.length||P.sends.some(B=>F(nt(B))))&&R()},stale:n},t)}var la=e=>e.filter(t=>t.status==="scheduled").sort((t,n)=>t.fire_at-n.fire_at);function ca(e){let t=e.filter(n=>n.status==="sent"||n.status==="sending").slice(0,5);return t.length?o`<div class="table-wrap"><table class="dash-sent"><thead><tr><th>Subject</th><th>Status</th><th class="num">Recipients</th><th class="num">Delivered</th><th></th></tr></thead><tbody>${t.map(n=>{let s=n.email_only?n.links.unlisted:n.links.archive;return o`<tr class="clickable" data-send="${n.id}"><td>${wt(o`<a href="#/sent/${n.id}">${n.subject}</a>`,n)}</td><td>${Je(n.status)}</td><td class="num">${n.audience.count.toLocaleString()}</td><td class="num delivered">${Ut(n.counts)}</td><td class="act">${s?o`<a class="ghost-link" href="${s}" target="_blank" rel="noopener">${n.email_only?o`Web version ↗`:o`Archive ↗`}</a>`:null}</td></tr>`})}</tbody></table></div>`:o`<p class="muted">No sends yet.</p>`}function da(e){for(let t of N("tr[data-send]",e))t.onclick=n=>{let s=n.target;s instanceof Element&&s.tagName!=="A"&&(location.hash=`#/sent/${t.dataset.send}`)}}function Nd(e,t){for(let n of t){let s=N("#dashSent tr[data-send]",e).find(i=>i.dataset.send===n.id)?.querySelector("td.delivered");s&&f(s,Ut(n.counts))}}function ua(e){if(!e.length)return o`<p class="muted">Nothing scheduled.</p>`;let t=cs("card");return o`${e.map(n=>o`<div class="card spread clickable nextup sched-card" data-post="${n.post_id}"><div><a class="card-link sched-subj" href="#/edit/${n.post_id}">${n.subject}</a><div class="muted">${$s(n)} · ${K(n.fire_at)} · ${n.audience.count} recipients${Ss(n)}</div>${t}${Le(n,"remade")?o`<div class="sched-remade-mark">Look changed since your last test</div>`:null}</div></div>`)}`}function pa(e){for(let t of N("#dashScheduled .nextup",e))t.onclick=n=>{let s=n.target;s instanceof Element&&s.tagName!=="A"&&(location.hash=`#/edit/${t.dataset.post}`)}}function ma(e){return e.length?o`<section class="dash-section"><h2>Active send${e.length===1?"":"s"}</h2>${e.map(t=>xs(t,{stuckNote:!1}))}</section>`:o``}function fa(e){for(let t of N("#dashActive .active-card[data-watch]",e))t.onclick=n=>{let s=n.target;s instanceof Element&&s.tagName!=="A"&&(location.hash=`#/sent/${t.dataset.watch}`)}}function ha(e,t,n){va(e,t,n),je(e)}function va(e,t,n){for(let s of N("[data-nav]",e))s.onclick=()=>{location.hash=s.dataset.nav??""};for(let s of N("[data-act='new-post']",e))s.onclick=()=>Ro(s);for(let s of N("[data-act='add-sub']",e))s.onclick=()=>Ls(t,n)}function ba(e){return e?o`<div class="card pub-card">
|
|
82
82
|
<p class="conn-status"><span class="conn-dot" aria-hidden="true"></span>Claude is connected.</p>
|
|
83
|
-
<div class="pub-foot pub-links"><a href="#/api-reference">${
|
|
83
|
+
<div class="pub-foot pub-links"><a href="#/api-reference">${O("code")}API reference →</a><a href="#/docs/connect-claude/working-with-claude">${O("article")}Working with Claude →</a></div>
|
|
84
84
|
</div>`:o`<div class="card pub-card">
|
|
85
85
|
<p class="pub-note">Let Claude draft, proofread, and schedule your posts.</p>
|
|
86
|
-
<div class="pub-foot pub-links"><a href="#/docs/connect-claude">${
|
|
87
|
-
</div>`}function
|
|
86
|
+
<div class="pub-foot pub-links"><a href="#/docs/connect-claude">${O("article")}Connect Claude →</a><a href="#/api-reference">${O("code")}API reference →</a></div>
|
|
87
|
+
</div>`}function ga(e,t,n,s,i=null){let a=`${t?.app_origin||location.origin}/subscribe`,r=ve(),l=!r&&Ho(t),{onList:d}=n,u=m=>m?" setup-done":"";return o`<div class="card setup${s==="card"?" setup-card":""}">
|
|
88
88
|
<h2 class="setup-title">${s==="card"?"Finish setting up":"Set up your publication"}</h2>
|
|
89
89
|
<ol class="setup-steps">
|
|
90
|
-
<li class="setup-name${
|
|
91
|
-
${
|
|
92
|
-
${
|
|
93
|
-
|
|
94
|
-
|
|
90
|
+
<li class="setup-name${u(n.named)}"><div class="setup-step-main"><strong>Name your publication</strong><span class="muted">Currently “${e.name}”. Set the name, tagline, and brand in Settings.</span></div><button data-nav="#/settings">Settings</button></li>
|
|
91
|
+
${r?o`<li class="setup-connect"><div class="setup-step-main"><strong>Connect Amazon SES</strong><span class="muted">Nothing can be sent, and signups stay closed, until SES is connected.</span></div><button data-nav="${yo}">Connect Amazon SES</button></li>`:o`<li class="setup-check"><div class="setup-step-main"><strong>Check your setup</strong><span class="muted">Send yourself a test, and see how Kestrel tells you when something needs attention.</span></div><button data-nav="#/docs/check-your-setup">Docs</button></li>`}
|
|
92
|
+
${l?o`<li class="setup-access${u(i?.state==="production")}"><div class="setup-step-main"><strong>Request production access</strong><span class="muted">${Jr(i)}</span></div><button data-nav="${yn}">Docs</button></li>`:null}
|
|
93
|
+
${d?o`<li class="setup-done setup-list"><div class="setup-step-main"><strong>Bring your existing list</strong><span class="muted">${d.toLocaleString()} ${d===1?"subscriber":"subscribers"} on your list.</span></div><button data-nav="#/subscribers">Subscribers</button></li>`:o`<li class="setup-list"><div class="setup-step-main"><strong>Bring your existing list</strong><span class="muted">Import the subscribers you have on another service, with the consent they gave there. Skip this if you’re starting fresh.</span></div><button data-nav="#/subscribers/import">Import</button></li>`}
|
|
94
|
+
<li class="setup-write${u(n.archived)}"><div class="setup-step-main"><strong>Publish your first post</strong><span class="muted">Write a post, test it, and send it. It goes to your subscribers and onto your site.</span></div>${s==="card"?o`<button data-act="new-post">New post</button>`:o`<button class="primary" data-act="new-post">New post</button>`}</li>
|
|
95
|
+
${r?o`<li class="setup-subscribe"><div class="setup-step-main"><strong>Share your subscribe link</strong><span class="muted">Signups open once an email provider is connected; until then the page says they aren’t open yet.</span></div></li>`:o`<li class="setup-subscribe"><div class="setup-step-main"><strong>Share your subscribe link</strong>${Po(i)?o`<span class="muted">Share it once AWS grants production access: until then, signups from anyone not verified in SES fail.</span>`:null}<code class="setup-url">${a}</code></div><button type="button" data-copy="${a}" aria-label="Copy the subscribe link">${Te()}</button></li>`}
|
|
95
96
|
</ol>
|
|
96
|
-
</div>`}var
|
|
97
|
+
</div>`}var Oo=Math.floor(5e3);var Gb=`Workers Free suits a list of up to about ${1e3.toLocaleString("en-US")} subscribers. Past about ${Oo.toLocaleString("en-US")}, one send can use up the day\u2019s database writes and stop this newsletter until midnight UTC.`,Od="Move to Workers Paid, or, if the account is on it already, set SUBREQUEST_BUDGET to 10000.";function ya(e){return`On the Workers Free plan\u2019s limits, a send to ${e.toLocaleString("en-US")} recipients may use up the day\u2019s database writes and stop this newsletter until midnight UTC, the send included. Workers Free suits a list of up to about ${1e3.toLocaleString("en-US")} subscribers. ${Od}`}function Rs(e){return e.toLowerCase().normalize("NFKD").replace(/[̀-ͯ]/g,"").replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,80).replace(/-+$/g,"")}function En(e){return e.replace(/^https?:\/\//,"")}function wa(){let e=er("");return e?En(e):"/archive/"}function Qe(e,t){return{emailOnly:e.email_only,slug:e.slug,slugAuto:e.slug_auto,subject:e.subject,slugTaken:t,fixed:e.published_at!==null}}function Bo(e){return e.emailOnly?o`Sends by email only`:o`Sends by email and publishes at <code>${wa()}${e.slug}</code>`}function Do(e){return O(e.emailOnly?"mail":"link")}var Bd="Listed on your home page and in your public archive. Unchecked, it\u2019s sent as email only: anyone with the email can still open its web version.",Sa="Fixed once the post is sent, since people may have its link.";function $a(e,t){return e.fixed?o`<p class="pub-note">${t}</p>`:e.slugAuto&&e.slugTaken?o`<p class="pub-taken">${O("info")}<span>Another post has <code>${e.slugTaken}</code>, so a number was added. You can change it above.</span></p>`:e.slugAuto?o`<p class="pub-note">Follows the subject until you type your own.</p>`:null}function Dd(e,t,{include:n=!0,fixedNote:s=Sa}){let i=n?o`<label class="listing-check"><input type="checkbox" id="${t}Include"${e.emailOnly?null:o` checked`}><span><strong>Include in archive</strong><span class="listing-help">${Bd}</span></span></label>`:null;return e.emailOnly?o`${i}`:o`${i}<div class="pub-address"><label class="pub-label" for="${t}Slug">Archive address</label><label class="url-field${e.fixed?" readonly":""}" id="${t}Field"><span class="url-base">${wa()}</span><input type="text" id="${t}Slug" value="${e.slug}" spellcheck="false" autocomplete="off" autocapitalize="off"${e.fixed?o` readonly`:null}></label><div id="${t}Note">${$a(e,s)}</div></div>`}function Ud(e,t,n,s,{fixedNote:i=Sa,onChange:a}){let r=e.querySelector(`#${n}Include`);r&&(r.onchange=()=>{t.emailOnly=!r.checked,s(),a?.()});let l=e.querySelector(`#${n}Slug`),d=e.querySelector(`#${n}Note`);!l||!d||t.fixed||(l.onfocus=()=>l.select(),l.oninput=()=>{t.slug=l.value,t.slugAuto=!1,e.querySelector(`#${n}Field`)?.classList.remove("is-invalid"),f(d,$a(t,i)??o``)},l.onblur=()=>{l.value.trim()===""&&(t.slugAuto=!0,t.slug=Rs(t.subject)||t.slug,s())})}function xn(e,t){let n={};return t.emailOnly!==e.emailOnly&&(n.email_only=t.emailOnly),!e.fixed&&!t.emailOnly&&(t.slugAuto&&!e.slugAuto?n.slug_auto=!0:!t.slugAuto&&t.slug!==e.slug&&(n.slug=t.slug)),Object.keys(n).length?n:null}function $t(e,t,n,s={}){let i=()=>{f(e,Dd(t,n,s)),Ud(e,t,n,i,s)};i()}function kn(e,t,n){if(!(n instanceof te)||n.field!=="slug"&&n.field!=="slug_auto")return!1;let s=e.querySelector(`#${t}Note`),i=e.querySelector(`#${t}Slug`);return!s||!i?!1:(e.querySelector(`#${t}Field`)?.classList.add("is-invalid"),f(s,o`<p class="pub-error" role="alert">${n.message}</p>`),i.focus(),!0)}var Et=q;function Cs(e,t,n){let s=e.c_in_flight||0,a=me(o`<h3>Resolve ${s} ambiguous ${s===1?"delivery":"deliveries"}</h3>
|
|
97
98
|
<p class="hint">A transport error left ${s} recipient${s===1?"":"s"} in flight: the request went out but the provider never confirmed, so there’s no way to know whether it was accepted. To avoid mailing anyone twice, the send won’t retry ${s===1?"it":"them"} on its own, so it can’t finish until you decide. Neither choice re-sends this post.</p>
|
|
98
99
|
<p class="hint">Kestrel can’t tell whether ${s===1?"this email":"these emails"} went out, so unless you know, <strong>Assume not sent</strong> is the safe default.</p>
|
|
99
100
|
<p class="hint"><strong>Assume not sent</strong>: recorded as unsent. ${s===1?"That reader":"Those readers"} may miss this post but ${s===1?"gets":"get"} your next one, and no one is mailed twice.</p>
|
|
100
101
|
<p class="hint"><strong>Assume sent</strong>: recorded as accepted by your provider, with delivery still waiting on its receipt. Choose this when you know otherwise, such as a reader who says they got it.</p>
|
|
101
|
-
<div class="actions"><button type="button" id="rCancel">Cancel</button><button type="button" id="rUnsent">Assume not sent</button><button type="button" class="primary" id="rAccepted">Assume sent</button></div>`,n);c("#rCancel",a.el).onclick=a.close;let r=(u,
|
|
102
|
+
<div class="actions"><button type="button" id="rCancel">Cancel</button><button type="button" id="rUnsent">Assume not sent</button><button type="button" class="primary" id="rAccepted">Assume sent</button></div>`,n);c("#rCancel",a.el).onclick=a.close;let r=(u,m,w)=>Y(u,"Resolving\u2026",async()=>{a.clearError();try{let h=await T(`/api/sends/${e.id}/resolve`,{method:"POST",json:{resolution:m}});a.close(),U(h.completed?"Send completed":`Marked ${w}`),t()}catch(h){a.error(Et(h))}}),l=c("#rUnsent",a.el),d=c("#rAccepted",a.el);l.onclick=()=>r(l,"unsent","not sent"),d.onclick=()=>r(d,"accepted","sent")}async function As(e,t,n,s){let i=s;if(!i)try{let S=await T(`/api/posts/${e.post_id}`,{signal:n});i=Qe(S.post,S.subject_slug_held)}catch(S){n.aborted||U(Et(S));return}let a=i,r={...a},l=yt(rs()),d=new Date(yt(new Date(e.fire_at))),u=me(o`<h3 id="rsHead">Edit schedule</h3>
|
|
102
103
|
<p class="hint" id="rsHint">It sends at the time you pick, with a cancelable window until then.</p>
|
|
103
|
-
${
|
|
104
|
+
${Xi()}
|
|
104
105
|
<label for="rsWhen">Send at</label><input type="datetime-local" id="rsWhen" min="${l}" value="${yt(d)}">
|
|
105
106
|
<div class="dialog-settings" id="rsForm"></div>
|
|
106
|
-
<div class="actions"><button type="button" id="rsCancel">Cancel</button><button type="button" class="primary" id="rsGo">Save</button></div>`,n),
|
|
107
|
-
`).map(n=>{let s,i=!1,a=n.match(/^(\s*)(```+|~~~+)(.*)$/);if(a){t=!t;let r=a[3]?`<span class="cx-md-bmark">${X(a[3])}</span>`:"";s=`${a[1]}${X(a[2]??"")}${r}`}else t?(i=!0,s=X(n)):s=
|
|
108
|
-
`:l!==void 0?t+=X(l):d!==void 0?(t+=`<span class="cx-str">${X(d)}</span>`,s=!1):u!==void 0?(t+=`<span class="cx-str">${X(u).replace(
|
|
109
|
-
`,s=!0):p!==void 0?t+=`<span class="cx-punct">${X(p)}</span>`:
|
|
107
|
+
<div class="actions"><button type="button" id="rsCancel">Cancel</button><button type="button" class="primary" id="rsGo">Save</button></div>`,n),m=c(".modal",u.el);m.setAttribute("aria-labelledby","rsHead"),$t(c("#rsForm",m),r,"rs");let w=c("#rsGo",m),h=c("#rsWhen",m),p=!1;c("#rsCancel",m).onclick=()=>{u.close(),p&&t()},w.onclick=()=>Y(w,"Saving\u2026",async()=>{u.clearError();let S=h.value,E=S?new Date(S).getTime():Number.NaN;if(Number.isNaN(E)){u.error("Pick a valid date & time",h);return}let I=E===d.getTime();if(!I&&is(E)){u.error(os(),h);return}let C=xn(a,r);if(I&&!C){u.close();return}let H=L=>L instanceof te&&L.status===404?(u.close(),U("This post was deleted elsewhere."),Fe(),!0):!1;if(C)try{await T(`/api/posts/${e.post_id}/settings`,{method:"PUT",json:C})}catch(L){!H(L)&&!kn(m,"rs",L)&&u.error(Et(L));return}if(!I)try{await T(`/api/sends/${e.id}/reschedule`,{method:"POST",json:{fire_at:new Date(E).toISOString()}})}catch(L){if(H(L))return;let v=L instanceof te&&L.field==="fire_at";if(C){if(a={...r},p=!0,v){u.error(`Settings saved. ${Et(L)}`,h);return}u.close(),U(`Settings saved. The send time didn\u2019t change: ${Et(L)}`),t();return}v?u.error(Et(L),h):u.error(Et(L));return}u.close(),U(I?"Saved":"Rescheduled"),t()}),h.focus()}function Ea(e,t={}){return["default-src 'none'","script-src 'none'","object-src 'none'","frame-src 'none'","base-uri 'none'",`form-action ${e}`,t.framed?null:"frame-ancestors 'none'","img-src * data:","style-src 'unsafe-inline' https://fonts.googleapis.com","font-src https://fonts.gstatic.com"].filter(n=>n!==null).join("; ")}var xa=e=>e.preventDefault(),Yt="allow-same-origin allow-popups allow-popups-to-escape-sandbox";function Zt(e){for(let t of e.querySelectorAll("a[href], area[href]")){if(t.getAttribute("href")?.startsWith("#")){t.addEventListener("click",xa),t.addEventListener("auxclick",xa);continue}t.target="_blank",t.rel="noopener noreferrer"}}function Fd(e,t){let n=/<head(\s[^>]*)?>/i;return n.test(e)?e.replace(n,s=>s+t):t+e}function Hs(e){return Fd(e,`<meta http-equiv="Content-Security-Policy" content="${Ea("'none'",{framed:!0})}">`)}function ka(e){return e.replace(/\{\{\s*(?:if\s+)?[\w.]+\s*\}\}/g,t=>`<span class="cx-var">${t}</span>`)}function qd(e){let t=X(e);return t=t.replace(/"[^&]*?"/g,n=>`<span class="cx-str">${n}</span>`),t=t.replace(/(<\/?)([a-zA-Z][\w-]*)/g,(n,s,i)=>`<span class="cx-punct">${s}</span><span class="cx-tag">${i}</span>`),t=t.replace(/(\/?)>/g,(n,s)=>`<span class="cx-punct">${s}></span>`),ka(t)}function jd(e){let t=X(e);return t=t.replace(/"[^&]*?"/g,n=>`<span class="cx-str">${n}</span>`),t=t.replace(/#[0-9a-fA-F]{3,8}\b/g,n=>`<span class="cx-num">${n}</span>`),t=t.replace(/@[\w-]+/g,n=>`<span class="cx-at">${n}</span>`),t=t.replace(/^(\s*)(?![@\s])([^\n{}<]+?)(\s*)\{$/gm,(n,s,i,a)=>`${s}<span class="cx-sel">${i}</span>${a}{`),t=t.replace(/^(\s*)([a-z-]+)(\s*:)/gm,(n,s,i,a)=>`${s}<span class="cx-prop">${i}</span>${a}`),ka(t)}function _a(e){return V(String(e).split(/(<style>[\s\S]*?<\/style>)/).map(t=>{let n=t.match(/^<style>([\s\S]*?)<\/style>$/);return n?`<span class="cx-punct"><</span><span class="cx-tag">style</span><span class="cx-punct">></span>${jd(n[1]??"")}<span class="cx-punct"></</span><span class="cx-tag">style</span><span class="cx-punct">></span>`:qd(t)}).join(""))}function Uo(e){return X(e).replace(/(`[^`\n]+`)|(!?)(\[[^\]\n]*\])\(([^)\n]*)\)|(\*\*|__)([^\n]+?)\5|\*([^*\n]+?)\*|\b_([^_\n]+?)_\b/g,(t,n,s,i,a,r,l,d,u)=>{if(n)return`<span class="cx-md-code">${n}</span>`;if(i!==void 0)return`${s||""}${i}(<span class="cx-md-url">${a}</span>)`;if(r)return`<span class="cx-md-mark">${r}</span><span class="cx-md-strong">${l}</span><span class="cx-md-mark">${r}</span>`;let[m,w]=d!==void 0?["*",d]:["_",u];return`<span class="cx-md-mark">${m}</span><span class="cx-md-em">${w}</span><span class="cx-md-mark">${m}</span>`})}function Wd(e){let t=e.match(/^(\s{0,3}#{1,6})(\s.*)?$/);if(t)return`<span class="cx-md-hmark">${X(t[1]??"")}</span><span class="cx-md-htext">${X(t[2]||"")}</span>`;if(/^\s{0,3}([-*_])(?:\s*\1){2,}\s*$/.test(e))return`<span class="cx-md-bmark">${X(e)}</span>`;let n=e.match(/^(\s{0,3})((?:>\s?)+)(.*)$/);if(n)return`${X(n[1]??"")}<span class="cx-md-bmark">${X(n[2]??"")}</span>${Uo(n[3]??"")}`;let s=e.match(/^(\s*)([-*+]|\d{1,9}[.)])(\s+)(.*)$/);return s?`${s[1]}<span class="cx-md-bmark">${X(s[2]??"")}</span>${s[3]}${Uo(s[4]??"")}`:Uo(e)}function Ta(e){let t=!1;return V(String(e).split(`
|
|
108
|
+
`).map(n=>{let s,i=!1,a=n.match(/^(\s*)(```+|~~~+)(.*)$/);if(a){t=!t;let r=a[3]?`<span class="cx-md-bmark">${X(a[3])}</span>`:"";s=`${a[1]}${X(a[2]??"")}${r}`}else t?(i=!0,s=X(n)):s=Wd(n);return`<span class="cx-md-ln${i?" cx-md-band":""}">${s}</span>`}).join(""))}var Vd=/(\/\/[^\n]*|\/\*[\s\S]*?\*\/)|("(?:\\.|[^"\\\n])*")(\s*:)?|(?<![\w.-])(-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?)(?![\w.])|\b(true|false|null)\b|([{}[\],])/g;function Fo(e){let t="",n=0;for(let s of e.matchAll(Vd)){t+=X(e.slice(n,s.index));let[i,a,r,l,d,u]=s;a!==void 0?t+=`<span class="cx-punct">${X(a)}</span>`:r!==void 0?t+=l?`<span class="cx-prop">${X(r)}</span><span class="cx-punct">${X(l)}</span>`:`<span class="cx-str">${X(r)}</span>`:d!==void 0?t+=`<span class="cx-num">${d}</span>`:u!==void 0?t+=`<span class="cx-tag">${u}</span>`:t+=`<span class="cx-punct">${X(i)}</span>`,n=s.index+i.length}return V(t+X(e.slice(n)))}function La(e){return Fo(JSON.stringify(e,null,2)??"")}var Kd=/(\\\n)|(\\[\s\S])|('[^']*')|("(?:\\[\s\S]|[^"\\])*")|(\$\{?[A-Za-z_]\w*\}?)|(&&|\|\||[|;])|(\n)|(#[^\n]*)|([^\s'"$|&;\\]+)/g,Gd=/\$\{?[A-Za-z_]\w*\}?/g;function Ps(e){let t="",n=0,s=!0;for(let i of e.matchAll(Kd)){t+=X(e.slice(n,i.index));let[a,r,l,d,u,m,w,h,p,S]=i;r!==void 0?t+=`<span class="cx-punct">\\</span>
|
|
109
|
+
`:l!==void 0?t+=X(l):d!==void 0?(t+=`<span class="cx-str">${X(d)}</span>`,s=!1):u!==void 0?(t+=`<span class="cx-str">${X(u).replace(Gd,'<span class="cx-var">$&</span>')}</span>`,s=!1):m!==void 0?(t+=`<span class="cx-var">${m}</span>`,s=!1):w!==void 0?(t+=`<span class="cx-punct">${X(w)}</span>`,s=!0):h!==void 0?(t+=`
|
|
110
|
+
`,s=!0):p!==void 0?t+=`<span class="cx-punct">${X(p)}</span>`:S!==void 0&&(s&&/^[A-Za-z_]\w*=/.test(S)?t+=X(S):s?(t+=`<span class="cx-tag">${X(S)}</span>`,s=!1):S.startsWith("-")?t+=`<span class="cx-num">${X(S)}</span>`:t+=X(S)),n=i.index+a.length}return V(t+X(e.slice(n)))}var zd={[Yn]:"Claude Code",[Zn]:"Claude"};function Jt(e,t,n){return e?e==="service"?n?`the service token ${n}`:"a service token":t===ln?e:t===null?`${e} via the API`:`${e} via ${zd[t]??t}`:null}function Ra(e){return e.kind==="service"?Jt("service",null,e.token_id)??"a service token":Jt(e.email??null,e.client)??"a person"}var Yd=[["scheduled_by","scheduled"],["rescheduled_by","rescheduled"],["canceled_by","canceled"],["resolved_by","resolved"]];function Ca(e){let n=Yd.flatMap(([s,i])=>{let a=e[s];return a?[`${i} by ${Ra(a)}`]:[]}).join(" \xB7 ");return n?n.charAt(0).toUpperCase()+n.slice(1):null}function Zd(e,t){return e.kind==="human"&&t?.kind==="human"&&e.email===t.email&&e.client===ln}function Aa(e,t){let n=e.rescheduled_by?{verb:"Rescheduled",actor:e.rescheduled_by}:e.scheduled_by?{verb:"Scheduled",actor:e.scheduled_by}:null;return!n||Zd(n.actor,t)?null:`${n.verb} by ${Ra(n.actor)}`}var Jd={idleMs:5e3,maxMs:3e4};function Ha(e,t=Jd){let n=null,s=null,i=()=>{n!==null&&clearTimeout(n),s!==null&&clearTimeout(s),n=null,s=null},a=()=>{i(),e()};return{touch(){n!==null&&clearTimeout(n),n=setTimeout(a,t.idleMs),s===null&&(s=setTimeout(a,t.maxMs))},cancel:i,get pending(){return n!==null||s!==null}}}var Ms=class{constructor(t){this.read=t;this.#e=JSON.stringify(t())}read;#e;snapshot(){return JSON.stringify(this.read())}get dirty(){return this.snapshot()!==this.#e}markSaved(t=this.snapshot()){this.#e=t}};var Pa=Promise.resolve();function qo(e){Pa=e}function Ma(){return Pa.then(()=>{},()=>{})}function Ia(e){if(!(e instanceof te)||e.status!==409)return null;let t=e.data;return t?.error==="stale_revision"&&typeof t.current_revision=="string"?{kind:"stale",revision:t.current_revision,author:typeof t.author=="string"?t.author:null,client:typeof t.author_client=="string"?t.author_client:null}:{kind:"locked"}}var Is=class{base;warnedRevision=null;constructor(t){this.base=t}saved(t){this.base=t}noteWarned(t){t.kind==="stale"&&(this.warnedRevision=t.revision)}adoptWarned(){this.warnedRevision!==null&&(this.base=this.warnedRevision),this.warnedRevision=null}clearWarning(){this.warnedRevision=null}decide(t,n){if(n.saving||this.base!==n.baseAtRequest)return"ignore";if(t.status!=="draft")return{kind:"locked"};let s=t.revision;return s&&s!==this.base&&s!==this.warnedRevision?{kind:"stale",revision:s,author:t.author,client:t.client}:"fresh"}};function Oa(e){return`#/web/post/${encodeURIComponent(e)}`}function Ba(e,t){if(e!=="post"||!t)return null;try{return decodeURIComponent(t)}catch{return null}}function Qd(e){let t=o`<span class="web-bar-tag">Web version</span>`;return e?o`${t} <span class="web-bar-text">Not public yet</span>`:t}function Na(e){try{return new URL(e).href}catch{return null}}function Da(e,t,n){let s=t?Na(t):null;if(s)for(let i of e.querySelectorAll("a[href], area[href]")){let a=i.getAttribute("href");a&&Na(a)===s&&i.setAttribute("href",n)}}function Xd(e){location.replace(e)}async function eu(e,t){try{return await T(`/api/posts/${encodeURIComponent(e)}`,{signal:t})}catch{return null}}async function jo(e,t,n){oe(n,"Web version");try{await Ma();let[s,i]=await Promise.all([Mt(`/api/posts/${encodeURIComponent(e)}/web`,{signal:n}),eu(e,n)]);if(n.aborted)return;if(i&&i.post.published_at!==null){Xd(i.post.unlisted_url);return}let a=Qd(i!==null);f(t,o`<div class="web-page">
|
|
110
111
|
<div class="web-bar" role="note"><div class="web-bar-in">${a}</div></div>
|
|
111
112
|
<iframe class="web-frame" sandbox="${Yt}" title="Web version" scrolling="no"></iframe>
|
|
112
|
-
</div>`);let r=t.querySelector(".web-frame");if(!r)return;r.onload=()=>{let l=r.contentDocument;if(!l||n.aborted)return;Zt(l),
|
|
113
|
+
</div>`);let r=t.querySelector(".web-frame");if(!r)return;r.onload=()=>{let l=r.contentDocument;if(!l||n.aborted)return;Zt(l),oe(n,l.title?`${l.title} (web version)`:"Web version");let d=()=>{let u=l.body?.scrollHeight;u&&(r.style.height=`${u}px`)};if(d(),l.body&&typeof ResizeObserver<"u"){let u=new ResizeObserver(d);u.observe(l.body),Pt(n,()=>u.disconnect())}},r.srcdoc=Hs(s)}catch(s){if(n.aborted)return;f(t,o`<div class="web-error"></div>`);let i=t.querySelector(".web-error");if(i){let r=s instanceof te&&s.status===404?"There\u2019s no post here. It may have been deleted.":q(s);ie(i,r,()=>ee((l,d)=>jo(e,l,d)))}}}var Xe=q,tu=[[["heading","Heading"],["bold","Bold (\u2318B)"],["italic","Italic (\u2318I)"]],[["quote","Quote"],["code","Code"],["link","Link (\u2318K)"]],[["ul","Bulleted list"],["ol","Numbered list"],["indent","Indent"]]],nu=o` readonly`,su=o` hidden`,ou=o` aria-disabled="true"`;async function Wo(e,t,n){let s=()=>{n.aborted||ee((g,M)=>Wo(e,g,M))},i=!1,a=(g="This post was deleted elsewhere.")=>{i||(i=!0,U(g),n.aborted||Ns("#/drafts"))};oe(n,"Draft"),f(t,o`<p class="muted">Loading…</p>`);let r,l=null;try{if(r=await T(`/api/posts/${e}`,{signal:n}),n.aborted)return;let g=ru(r);if(g){Ns(g);return}}catch(g){if(Oe(g)){a("There\u2019s no post here. It may have been deleted.");return}ie(t,Xe(g),s);return}let d=vn(r.post);if(d){try{l=await T(`/api/sends/${d.id}`,{signal:n})}catch(g){if(n.aborted)return;if(Oe(g)){a();return}}if(n.aborted||l&&Ua(l.send,s))return}let{post:u,markdown:m}=r,w=Q.session?.principal??null,h=Qe(u,r.subject_slug_held),p=!Gt(u,"edit"),S=Gt(u,"schedule")!==void 0,E=new Is(u.current_revision),I=tu.map((g,M)=>o`${M?o`<span class="sep"></span>`:null}${g.map(([_,D])=>o`<button type="button" class="tb" data-fmt="${_}" title="${D}" aria-label="${D}"${p?ou:null}>${O(_)}</button>`)}`),C=p?nu:null,H=`${location.origin}${location.pathname}${Oa(e)}`;f(t,o`
|
|
113
114
|
<div class="editor-head">
|
|
114
115
|
<a href="#/drafts" class="back">← Drafts</a>
|
|
115
116
|
<div class="editor-head-right">
|
|
116
|
-
<span class="email-only-mark" id="headEmailOnly"${u.email_only&&!p?null:
|
|
117
|
+
<span class="email-only-mark" id="headEmailOnly"${u.email_only&&!p?null:su}>${O("mail")}Email only</span>
|
|
117
118
|
<a class="ghost btn" id="webLink" href="${H}" target="_blank" rel="noopener" aria-label="Web version (opens in a new tab)">Web version ↗</a>
|
|
118
|
-
<button type="button" class="ghost" id="settingsBtn">${
|
|
119
|
+
<button type="button" class="ghost" id="settingsBtn">${O("settings")}<span>Post settings</span></button>
|
|
119
120
|
</div>
|
|
120
121
|
</div>
|
|
121
|
-
${p&&d?o`<div class="banner banner-scheduled banner-split"><div class="banner-top"><div class="sched-main"><span id="schedWhen"></span><div class="sched-by" id="schedBy" hidden></div>${
|
|
122
|
+
${p&&d?o`<div class="banner banner-scheduled banner-split"><div class="banner-top"><div class="sched-main"><span id="schedWhen"></span><div class="sched-by" id="schedBy" hidden></div>${cs("banner")}<div class="sched-remade" id="schedRemade" hidden><span id="schedRemadeMsg"></span></div><div class="sched-note" id="schedDailyWrites" hidden><span class="sched-note-mark" aria-hidden="true">⚠️</span><span class="sched-note-msg" id="schedDailyWritesMsg"></span></div></div><span class="row" id="schedControls"><button type="button" class="ghost" id="rescheduleSchedule">Edit schedule</button><button type="button" class="ghost" id="cancelSchedule">Cancel</button></span></div><div class="banner-bottom sched-dest"><span class="sched-dest-icon" id="schedDestIcon">${Do(h)}</span><span id="schedDest">${Bo(h)}</span></div></div>`:null}
|
|
122
123
|
<div id="freshnessBanner" class="banner banner-conflict" role="alert" hidden></div>
|
|
123
124
|
<div class="editor-form">
|
|
124
125
|
<label for="f-subject">Subject</label>
|
|
125
|
-
<input id="f-subject" value="${u.subject}" placeholder="Untitled"${
|
|
126
|
+
<input id="f-subject" value="${u.subject}" placeholder="Untitled"${C}>
|
|
126
127
|
|
|
127
128
|
<label for="f-markdown">Body</label>
|
|
128
129
|
<div class="composer${p?" composer-locked":""}">
|
|
129
130
|
<div class="composer-head">
|
|
130
131
|
<div class="ctabs" role="tablist">
|
|
131
|
-
<button type="button" class="ctab active" data-tab="edit" data-text="Edit" role="tab" aria-selected="true"><span class="ctab-label">${
|
|
132
|
-
<button type="button" class="ctab" data-tab="preview" data-text="Preview" role="tab" aria-selected="false"><span class="ctab-label">${
|
|
132
|
+
<button type="button" class="ctab active" data-tab="edit" data-text="Edit" role="tab" aria-selected="true"><span class="ctab-label">${O("editable")}Edit</span></button>
|
|
133
|
+
<button type="button" class="ctab" data-tab="preview" data-text="Preview" role="tab" aria-selected="false"><span class="ctab-label">${O("preview")}Preview</span></button>
|
|
133
134
|
</div>
|
|
134
|
-
<div class="toolbar" role="toolbar" aria-label="Formatting">${
|
|
135
|
+
<div class="toolbar" role="toolbar" aria-label="Formatting">${I}</div>
|
|
135
136
|
</div>
|
|
136
137
|
<div class="composer-body${p?" locked":""}" id="composerBody">
|
|
137
138
|
<pre class="md-hl" id="mdHl" aria-hidden="true"><code></code></pre>
|
|
138
|
-
<textarea id="f-markdown" class="editor"${p?null:o` placeholder="Type your post in Markdown…"`}${
|
|
139
|
+
<textarea id="f-markdown" class="editor"${p?null:o` placeholder="Type your post in Markdown…"`}${C}>${m}</textarea>
|
|
139
140
|
<iframe id="previewFrame" class="preview" sandbox="${Yt}" title="Email preview" hidden></iframe>
|
|
140
141
|
</div>
|
|
141
|
-
${p?o`<div class="composer-foot composer-foot-lock" id="lockFoot" role="status">${
|
|
142
|
+
${p?o`<div class="composer-foot composer-foot-lock" id="lockFoot" role="status">${O("readonly")}<span>Cancel the schedule to edit</span></div>`:o`<div class="composer-foot" id="dropFoot">${O("paperclip")}<span>Paste, drop, or click to add images</span></div>`}
|
|
142
143
|
<input type="file" id="imgInput" accept="image/png,image/jpeg,image/webp,image/gif" multiple hidden>
|
|
143
144
|
</div>
|
|
144
145
|
<div id="warnings"></div>
|
|
145
|
-
${p?null:
|
|
146
|
+
${p?null:ls("editor-not-connected",o`No email provider connected: you can write and preview, not send. ${Ae()}.`)}
|
|
146
147
|
|
|
147
148
|
<div class="actions-bar">
|
|
148
|
-
${p?o`<div class="row test-row"><span class="test-hint" id="testHint" hidden>Not tested yet</span><button type="button" class="secondary" id="testBtn">${
|
|
149
|
+
${p?o`<div class="row test-row"><span class="test-hint" id="testHint" hidden>Not tested yet</span><button type="button" class="secondary" id="testBtn">${O("send")}<span>Send test email</span></button></div>`:o`<div class="row">
|
|
149
150
|
<button type="button" class="ghost" id="saveBtn">Save draft</button>
|
|
150
151
|
<span class="save-status" id="saveStatus" aria-live="polite"></span>
|
|
151
152
|
</div>
|
|
152
153
|
<div class="row">
|
|
153
|
-
<button type="button" class="secondary" id="testBtn">${
|
|
154
|
+
<button type="button" class="secondary" id="testBtn">${O("send")}<span>Send test email</span></button>
|
|
154
155
|
<button type="button" class="primary" id="scheduleBtn">Schedule</button>
|
|
155
156
|
</div>`}
|
|
156
157
|
</div>
|
|
157
|
-
</div>`);let
|
|
158
|
-
`,
|
|
159
|
-
`).map(ce=>
|
|
160
|
-
`);y.value=y.value.slice(0,
|
|
161
|
-
`)?Pe("```\n","\n```","code"):Pe("`","`","code")}
|
|
162
|
-
![${
|
|
163
|
-
`;y.value=y.value.slice(0,
|
|
164
|
-
`),
|
|
165
|
-
`),k.error(bs(Z,ce.length,Se));return}k.close(),O(Nt(`Test sent to ${Z} address${Z===1?"":"es"}`))}catch(Z){if(Be(Z)){k.close(),Rt(Z);return}k.error(Xe(Z))}})};let Li=p?null:c("#scheduleBtn");return Li&&(Li.onclick=()=>{if(!_())return;let w=yt(os()),P=yt(new Date(Date.now()+24*3600*1e3)),k=!v,B={...b,subject:T.value};B.slugAuto&&!B.slugTaken&&(B.slug=ks(B.subject)||B.slug);let ne="It sends at the time you pick, with a cancelable window until then.",ce=()=>o`<h3 id="schHead">Schedule this post</h3><p class="hint" id="schHint">${ne}</p>${Ki()}${vo()}${k?null:o`<label for="schWhen">Send at</label><input type="datetime-local" id="schWhen" min="${w}" value="${P}"><div class="dialog-settings" id="schForm"></div>`}<div class="actions"><button type="button" id="schCancel">Cancel</button><button type="button" class="primary" id="schGo">Schedule</button></div>${k?null:o`<div class="altrow"><span class="altrow-note">Or send as soon as possible.</span><button type="button" class="linkbtn" id="toSendNow">Send now →</button></div>`}`,Ee=P,ie=pe(ce(),n),Z=c(".modal",ie.el),Se=null,pt=()=>(Se??=R("/api/subscribers?status=confirmed&suppressed=hide&limit=1",{signal:n}).then(me=>me.page.total).catch(()=>null),Se),De=async()=>{if(!Z.querySelector("#schDailyWrites"))return;let me=await pt(),Ce=Z.querySelector("#schDailyWrites");Ce&&me!==null&&me>Ao&&(Ce.textContent=ca(me),Ce.hidden=!1)},xe=()=>{ie.close(),Ke.scrollIntoView({block:"nearest"})},sn=()=>$t(c("#schForm",Z),B,"sch"),Ct=()=>({email_only:B.emailOnly,...$n(b,B)}),on=me=>{En(Z,"sch",me)||ie.error(Xe(me))},be=()=>G(c("#schGo",Z),"Scheduling\u2026",async()=>{ie.clearError();let me=c("#schWhen",Z),Ce=me.value?new Date(me.value).getTime():Number.NaN;if(Number.isNaN(Ce)){ie.error("Pick a valid date & time",me);return}if(ss(Ce)){ie.error(ns(),me);return}try{if(await Oe(!0)==="refused"){xe();return}await R(`/api/posts/${e}/schedule`,{method:"POST",json:{fire_at:new Date(Ce).toISOString(),...Ct()}}),ie.close(),O(Nt(`Scheduled for ${W(Ce)}. Send yourself a test.`)),s()}catch(ze){if(Be(ze)){ie.close(),Rt(ze);return}if(ze instanceof te&&ze.field==="fire_at"){ie.error(Xe(ze),c("#schWhen",Z));return}on(ze)}}),ke=()=>G(c("#snGo",Z),"Queuing\u2026",async()=>{ie.clearError();try{if(await Oe(!0)==="refused"){xe();return}let{send:me}=await R(`/api/posts/${e}/send`,{method:"POST",json:Ct()});ie.close(),O(Nt(`Sends at ${W(me.fire_at)}, cancelable until then.`)),s()}catch(me){if(Be(me)){ie.close(),Rt(me);return}on(me)}});function _e(){if(Z.setAttribute("aria-labelledby","schHead"),c("#schCancel",Z).onclick=ie.close,c("#schGo",Z).onclick=be,c("#schGo",Z).disabled=k,k){c("#schCancel",Z).focus();return}c("#toSendNow",Z).onclick=At,c("#schWhen",Z).value=Ee,sn(),c("#schWhen",Z).focus(),De()}async function At(){let me=Z.querySelector("#schWhen");me&&(Ee=me.value),h(Z,o`<h3 id="snHead">Send now?</h3><p class="hint">Sends this draft, as it is now, to <strong id="snWho">your subscribers</strong> in ${Wi()}. The post locks until then, and you can cancel any time before it starts sending.</p><div class="dialog-settings" id="schForm"></div>${vo()}<div class="actions"><button type="button" class="linkbtn actions-back" id="toSchedule">← Back to schedule</button><button type="button" id="snCancel">Cancel</button><button type="button" class="primary" id="snGo">Send now</button></div>`),Z.setAttribute("aria-labelledby","snHead"),c("#snCancel",Z).onclick=ie.close,c("#snGo",Z).onclick=ke,sn(),c("#snGo",Z).disabled=!Gt(u,"send_now"),c("#toSchedule",Z).onclick=()=>{h(Z,ce()),_e()},c("#snGo",Z).focus(),De();let Ce=await pt(),ze=Z.querySelector("#snWho");ze&&Ce!==null&&(ze.textContent=`${Ce} recipient${Ce===1?"":"s"}`)}_e()}),Zl}function Ca(e,t){return e.status==="sending"||e.status==="sent"?(Hs(`#/sent/${e.id}`),!0):e.status==="canceled"?(t(),!0):!1}function Wd(e,t){return Le(e,"missed")?o`Scheduled for <strong>${W(e.fire_at)}</strong> · <span class="countdown countdown-missed">${gs(e.fire_at)}</span>`:t?o`Scheduled for <strong>${W(e.fire_at)}</strong> · <span class="countdown">${fn(e.fire_at,!0)}</span>`:o`Scheduled for <strong>${W(e.fire_at)}</strong> · <span class="countdown">${fn(e.fire_at)}</span>`}function Be(e){return e instanceof te&&e.status===404}function Vd(e){let t=e.post.send;return t?.status==="sending"?`#/sent/${t.id}`:e.post.status==="sent"?t?`#/sent/${t.id}`:"#/sent":null}function Hs(e){location.replace(e)}function Kd(e,t){document.addEventListener("visibilitychange",()=>{document.hidden||e()},{signal:t})}function Gd(e){return e.trim().toLowerCase().replace(/[^\p{L}\p{N}\s_-]/gu,"").replace(/\s/g,"-")}function Aa(e){let t=new Map;return e.map(n=>{let s=Gd(n),i=t.get(s)??0;return t.set(s,i+1),i?`${s}-${i}`:s})}var Do=null;function zd(e){let t=document.createElement("div");h(t,j(e.html||""));let n=(t.querySelector("p")?.textContent||"").trim().replace(/\s+/g," "),s=/[:;,]$/.test(n),i=n.replace(/[\s:;,]+$/,""),a=150;return i.length>a?`${i.slice(0,a).replace(/[\s.,;:]+\S*$/,"")}\u2026`:s?`${i}\u2026`:i}function Yd(e){let t=e.querySelector("code"),n=t?.className.match(/(?:^|\s)language-(\S+)/)?.[1]??null,s=(t??e).textContent?.replace(/\n$/,"")??"",i=n==="bash"||n==="sh"||n==="shell"?Rs(s):n==="json"||n==="jsonc"?Io(s):o`${s}`;return Zr(i,s)}async function Uo(e,t,n,s){if(se(n,"Docs"),h(t,Bt("docs",null,o`<div class="docs-index"><p class="muted">Loading…</p></div>`)),!Do)try{Do=await R("/api/docs",{signal:n})}catch(d){n.aborted||oe(c(".room-main",t),F(d),()=>ee((u,f)=>Uo(e,u,f,s)));return}let{sets:i,docs:a}=Do,r=i[0];if(!a.length||!r){h(c(".room-main"),o`<p class="muted">No documentation.</p>`);return}let l=e?i.find(d=>d.id===e):r;l?Ma(t,l,i,a,n):e&&Qd(t,i,a,e,n,s?Zd(s):void 0)}function Zd(e){try{return decodeURIComponent(e)}catch{return}}function Ma(e,t,n,s,i){se(i,`${t.name} docs`);let a=(b,p)=>{let v=zd(b);return o`<li><a class="doc-card" href="#/docs/${b.slug}">${p===null?null:o`<span class="doc-card-n">${String(p).padStart(2,"0")}</span>`}<span class="doc-card-main"><span class="doc-card-t">${b.title} <span class="doc-card-go" aria-hidden="true">→</span></span>${v?o`<span class="doc-card-d">${v}</span>`:null}</span></a></li>`},r=t.sections.map(b=>{let p=s.filter(M=>M.set===t.id&&M.section===b.id);if(!p.length)return null;let v=p.map((M,A)=>a(M,b.numbered?A+1:null)),x=b.blurb?o`<div class="doc-section-blurb">${j(b.blurb)}</div>`:null;return o`<section class="doc-section"><h2 class="doc-section-t">${b.title}</h2>${x}${b.numbered?o`<ol class="doc-cards">${v}</ol>`:o`<ul class="doc-cards">${v}</ul>`}</section>`}),l=o`<nav class="docs-tabs" aria-label="Doc sets">${n.map(b=>o`<a href="#/docs/${b.id}" title="${b.title}"${b.id===t.id?o` aria-current="page"`:null}>${b.name}</a>`)}</nav>`,d=o`<div class="docs-index"><h1>Kestrel docs</h1><p class="docs-index-intro"><strong>Publishing</strong> covers writing and sending your newsletter, from naming your publication to what happens after each send. <strong>Self-hosting</strong> covers deploying Kestrel to your own Cloudflare account and keeping it running. One person often does both.</p>${l}${r}</div>`,u=Q.appConfig?.deployment.build.repo_url||"",f=(b,p,v=p)=>o`<a class="rail-link" href="${b}" target="_blank" rel="noopener" aria-label="${p}"><span class="rail-link-full">${p}</span><span class="rail-link-short" aria-hidden="true">${v}</span> <span aria-hidden="true">↗</span></a>`,S=o`<div class="toc-label">Kestrel</div>${f("https://getkestrel.dev","Project site","Project")}${u?[f(u,"Source on GitHub","Source"),f(`${u}/blob/HEAD/LICENSE`,"License")]:null}`;h(e,Bt("docs",S,d)),window.scrollTo(0,0)}var Fo=matchMedia("(max-width: 720px)");function Ia(e){if(!e)return;let t=Fo.matches;e.open=!t,c("summary",e).tabIndex=t?0:-1}var Na=()=>document.querySelector("details#tocOnPage"),Ha=!1;function Jd(){Ha||(Ha=!0,Fo.addEventListener("change",()=>Ia(Na())))}var Pa=e=>`doc-h-${e}`;function Qd(e,t,n,s,i,a){let r=n.findIndex($=>$.slug===s),l=n[r],d=t.find($=>$.id===l?.set);if(!l||!d){let $=t[0];O(`No doc named \u201C${s}\u201D, so here\u2019s the index.`),history.replaceState(history.state,"","#/docs"),$&&Ma(e,$,t,n,i);return}se(i,l.title);let u=n.filter($=>$.set===l.set&&$.section===l.section),f=u.indexOf(l),S=u[f-1],b=u[f+1],p=($,_)=>o`<a href="#/docs/${$.slug}" aria-label="${_}: ${$.title}">${_==="Previous"?o`<span aria-hidden="true">←</span><span class="doc-topnav-word">Previous</span>`:o`<span class="doc-topnav-word">Next</span><span aria-hidden="true">→</span>`}</a>`,v=S||b?o`<nav class="doc-topnav" aria-label="Adjacent docs">${S?p(S,"Previous"):null}${b?p(b,"Next"):null}</nav>`:null;h(e,Bt("docs",o`<div id="docToc"></div>`,o`<article class="doc" id="docsMain"></article>`));let x=c("#docToc"),M=c("#docsMain");h(M,o`<section class="doc-part" id="doc-${l.slug}">${j(l.html)}</section>`);let A=c("section.doc-part",M),H=I("h1, h2, h3, h4",A),T=Aa(H.map($=>$.textContent||""));for(let[$,_]of H.entries()){let K=T[$]??"";_.dataset.anchor=K,_.id=Pa(K)}let m=A.querySelector("h1"),y=[];if(m&&y.push({id:m.id,anchor:"",title:m.textContent||l.title}),v){let $=document.createElement("div");$.className="doc-head",h($,v),m?(m.before($),$.prepend(m)):A.prepend($)}let C=document.createElement("p");C.className="eyebrow doc-set",h(C,o`<a href="#/docs/${d.id}">${d.name}</a>`),A.prepend(C);for(let $ of I("h2",A))y.push({id:$.id,anchor:$.dataset.anchor||"",title:$.textContent||""});let U=document.createElement("nav");U.className="doc-pager",h(U,o`${S?o`<a class="doc-pager-btn prev" href="#/docs/${S.slug}"><span class="doc-pager-dir">← Previous</span><span class="doc-pager-title">${S.title}</span></a>`:o`<span></span>`}${b?o`<a class="doc-pager-btn next" href="#/docs/${b.slug}"><span class="doc-pager-dir">Next →</span><span class="doc-pager-title">${b.title}</span></a>`:o`<span></span>`}`),M.appendChild(U);let J=y.map($=>o`<a class="toc-sub" href="#/docs/${l.slug}${$.anchor?`/${$.anchor}`:""}" data-target="${$.id}">${$.title}</a>`);h(x,y.length?o`<details class="toc-onpage" id="tocOnPage"><summary class="toc-label">On this page</summary>${J}</details>`:o``);let z=Na();Ia(z),Jd();let q=$=>{if(z)for(let _ of I(".toc-sub",z))_.classList.toggle("on",_.dataset.target===$)};x.addEventListener("click",$=>{let _=$.target instanceof Element?$.target.closest("a[data-target]"):null,K=_?.dataset.target;K&&($.preventDefault(),q(K),z&&Fo.matches&&(z.open=!1),history.replaceState(history.state,"",_?.getAttribute("href")??location.hash),document.getElementById(K)?.scrollIntoView({block:"start"}))});for(let $ of I("a[href^='http']",M))$.target="_blank",$.rel="noopener";for(let $ of I("pre",A)){let _=document.createElement("div");h(_,Yd($)),$.replaceWith(..._.childNodes)}je(M);let g=y.map($=>$.id),E=g[0];if(z&&E){let $=g[g.length-1]??E,K=(document.querySelector(".room-bar")?.getBoundingClientRect().height||54)+26,D=()=>{if(!document.getElementById(E)){document.onscroll=null;return}let ae=E;if(Math.ceil(window.innerHeight+window.scrollY)>=document.documentElement.scrollHeight)ae=$;else for(let V of g)if((document.getElementById(V)?.getBoundingClientRect().top??Number.POSITIVE_INFINITY)<=K)ae=V;else break;q(ae)};document.onscroll=D,D()}let L=a?document.getElementById(Pa(a)):null;L?L.scrollIntoView({block:"start"}):window.scrollTo(0,0)}function qo(e){let t=new Set(e.groups.flatMap(n=>n.routes.flatMap(s=>(s.errors??[]).map(i=>i.code))));return e.refusals.flatMap(n=>n.codes.filter(s=>!t.has(s.code)).map(s=>({...s,move:n.move})))}function xt(e){return e.replace(/\([^)]*\)/g,"").replace(/\{[^}]*\}\??/g,"")||"/"}function Qt(e){return e.title.toLowerCase().replace(/'s\b/g,"").split(/[^a-z0-9]+/).filter(t=>t!==""&&t!=="a"&&t!=="an"&&t!=="the").join("-")}var Xd=/`([^`]+)`|\*\*([^*]+)\*\*|\[([^\]]+)\]\(([^)\s]+)\)/g;function eu(e){return/^https:\/\//i.test(e)||/^\/(?![/\\])/.test(e)}function ge(e){let t=[],n=0;for(let s of e.matchAll(Xd)){let i=s.index??0;t.push(e.slice(n,i));let[,a,r,l,d]=s;a!==void 0?t.push(o`<code>${a}</code>`):r!==void 0?t.push(o`<strong>${ge(r)}</strong>`):l!==void 0&&d!==void 0&&t.push(eu(d)?o`<a href="${d}">${ge(l)}</a>`:ge(l)),n=i+s[0].length}return t.push(e.slice(n)),o`${t}`}function xn(e,t){return o`${e.split(/\n\s*\n/).filter(n=>n.trim()).map(n=>{let s=n.trim().split(`
|
|
166
|
-
`),i=s.findIndex(l=>l.startsWith("- "));if(i===-1)return o`<p class="${t}">${ge(n.trim())}</p>`;let a=s.slice(0,i).join(" ").trim(),r=s.slice(i).reduce((l,d)=>(d.startsWith("- ")||l.length===0?l.push(d.replace(/^- /,"")):l[l.length-1]=`${l[l.length-1]} ${d.trim()}`,l),[]);return o`${a?o`<p class="${t}">${ge(a)}</p>`:null}<ul class="${t} prose-list">${r.map(l=>o`<li>${ge(l)}</li>`)}</ul>`})}`}function
|
|
167
|
-
`)}function
|
|
158
|
+
</div>`);let L=c("#f-subject"),v=()=>oe(n,L.value.trim()||"Untitled");v();let y=c("#f-markdown"),$=c(".toolbar",t),A=c("#previewFrame"),W=c("#mdHl"),z=c("code",W),G=()=>{W.scrollTop=y.scrollTop,W.scrollLeft=y.scrollLeft},b=()=>{f(z,Ta(y.value)),G()};y.addEventListener("scroll",G),b();let k=()=>({subject:L.value,markdown:y.value}),R=null;function x(){R?.(),R=null}function F(){return L.value.trim()===""?(R=Ne(L,"Add a subject before you schedule."),L.focus(),!1):(x(),!0)}let P=c("#headEmailOnly"),B=()=>{P.hidden=p||!h.emailOnly;let g=t.querySelector("#schedDestIcon");g&&f(g,Do(h));let M=t.querySelector("#schedDest");M&&f(M,Bo(h))},ne=async g=>{let M=await T(`/api/posts/${e}/settings`,{method:"PUT",json:g});h=Qe(M.post,M.subject_slug_held),B(),M.changed&&Fe()},j=async()=>{try{let g=await T(`/api/posts/${e}`,{signal:n});h=Qe(g.post,g.subject_slug_held),B()}catch{}};c("#settingsBtn").onclick=()=>{let g={...h,subject:L.value},M=me(o`<h3 id="psHead">Post settings</h3><p class="hint">Neither is part of the email, so both stay open while the post is scheduled.</p><div id="psForm"></div><div class="actions"><button type="button" id="psCancel">Cancel</button><button type="button" class="primary" id="psSave">Save</button></div>`,n),_=c(".modal",M.el);_.setAttribute("aria-labelledby","psHead"),$t(c("#psForm",_),g,"ps"),c("#psCancel",_).onclick=M.close;let D=c("#psSave",_);D.onclick=()=>Y(D,"Saving\u2026",async()=>{M.clearError();let se=xn(h,g);if(!se){M.close();return}try{await ne(se),M.close(),U("Post settings saved")}catch(ce){if(n.aborted||Rt(ce)){M.close();return}kn(_,"ps",ce)||M.error(Xe(ce))}}),c("#psInclude",_).focus()},p||L.addEventListener("input",()=>{v(),L.value.trim()!==""&&x()});let ae=Ha(()=>{Be(!0).catch(()=>{})});Pt(n,()=>ae.cancel());let lt=N(".ctab",t);function Z(g){for(let M of lt){let _=M.dataset.tab===g;M.classList.toggle("active",_),M.setAttribute("aria-selected",_?"true":"false")}y.hidden=g!=="edit",W.hidden=g!=="edit",A.hidden=g!=="preview",$.classList.toggle("off",g!=="edit"),t.querySelector("#dropFoot")?.classList.toggle("off",g!=="edit"),g==="edit"&&G()}async function le(){Z("preview");try{p||await Be(!0),A.srcdoc=await Mt(`/api/posts/${e}/preview`),A.onload=()=>{try{let g=A.contentDocument;g&&(Zt(g),Da(g,u.unlisted_url,H),A.style.height=`${g.body.scrollHeight+24}px`)}catch{}}}catch(g){if(n.aborted||Rt(g))return;U(Xe(g))}}for(let g of lt)g.onclick=()=>g.dataset.tab==="preview"?le():Z("edit");p&&le();let de=p?c("#lockFoot"):null,He;function Re(){de&&(de.classList.remove("nudge"),requestAnimationFrame(()=>de.classList.add("nudge")),clearTimeout(He),He=setTimeout(()=>de.classList.remove("nudge"),900))}function Pe(g,M,_){let D=y.selectionStart,se=y.selectionEnd,ce=y.value.slice(D,se)||_;y.value=y.value.slice(0,D)+g+ce+M+y.value.slice(se),y.focus(),y.selectionStart=D+g.length,y.selectionEnd=D+g.length+ce.length}function ct(g){let M=y.selectionStart,_=y.selectionEnd,D=y.value.lastIndexOf(`
|
|
159
|
+
`,M-1)+1,se=(y.value.slice(D,_)||"").split(`
|
|
160
|
+
`).map(ce=>g+ce).join(`
|
|
161
|
+
`);y.value=y.value.slice(0,D)+se+y.value.slice(_),y.focus(),y.selectionStart=D,y.selectionEnd=D+se.length}function dt(g){if(p){Re();return}if(Z("edit"),g==="bold")Pe("**","**","bold text");else if(g==="italic")Pe("*","*","italic text");else if(g==="heading")ct("## ");else if(g==="quote")ct("> ");else if(g==="ul")ct("- ");else if(g==="ol")ct("1. ");else if(g==="indent")ct(" ");else if(g==="link")Pe("[","](https://)","link text");else if(g==="code"){let M=y.selectionStart,_=y.selectionEnd;M===_||y.value.slice(M,_).includes(`
|
|
162
|
+
`)?Pe("```\n","\n```","code"):Pe("`","`","code")}to()}for(let g of N(".tb[data-fmt]",t))g.onclick=()=>dt(g.dataset.fmt??"");y.addEventListener("keydown",g=>{if(!(g.metaKey||g.ctrlKey))return;let M=g.key.toLowerCase();M==="b"?(g.preventDefault(),dt("bold")):M==="i"?(g.preventDefault(),dt("italic")):M==="k"&&(g.preventDefault(),dt("link"))});let pe=!1,Un=!1,Ve=!1,et=null,ut=0,Fn=!1,Xs=0,Me=p?null:c("#saveBtn"),Ie=p?null:c("#saveStatus"),Tt=new Ms(k),nn=!1;function eo(){Ie&&(p?(Ie.className="save-status",Ie.textContent=""):nn?(Ie.className="save-status is-saving",Ie.textContent="Saving\u2026"):et&&pe?(Ie.className="save-status is-error",Ie.textContent=`Not saved: ${et}`):pe?(Ie.className="save-status is-dirty",Ie.textContent="Unsaved changes"):(Ie.className="save-status is-saved",Ie.textContent="Saved"))}function qn(){pe=Tt.dirty,pe||(et=null,Un=!1,ut=0),eo()}eo();function Ci(){ae.touch()}function to(){p||(b(),qn(),Ve||Ci())}let Lt=Promise.resolve();function Be(g){let M=Lt.catch(()=>{}).then(()=>oc(g));return Lt=M,qo(Lt),M}async function oc(g){if(g&&!Tt.dirty)return"unchanged";if(Ve)return"refused";ae.cancel(),nn=!0,eo();let M=k(),_=JSON.stringify(M);try{let D={...M,base_revision:E.base},{post:se,subject_slug_held:ce}=await T(`/api/posts/${e}`,{method:"PUT",json:D});return h=Qe(se,ce),B(),E.saved(se.current_revision),Tt.markSaved(_),Un=!1,et=null,ut=0,g||U("Saved"),"saved"}catch(D){let se=Ia(D);if(se)return Pi(se),"refused";if(Oe(D))return a(),"refused";Un=!0;let ce=D instanceof te&&D.field==="subject"?L:void 0;if(ce?(Ne(ce,q(D)),et="fix the field marked above."):et=q(D),!(po(D)||D instanceof te&&(D.status>=500||D.status===429)))Xs+=1,Fn=!1,ut=0;else if(!Fn){Fn=!0,ut=ut?Math.min(ut*2,6e4):5e3;let re=Xs;ft(Date.now()+ut,()=>{re===Xs&&(Fn=!1,et&&!Ve&&Be(!0).catch(()=>{}))},n)}throw D}finally{nn=!1,qn()}}Me&&(Me.onclick=()=>{if(Ve){Ke.scrollIntoView({block:"nearest"});return}Y(Me,"Saving\u2026",()=>Be(!1).catch(()=>{})).finally(qn)});function Ai(){Me&&(Ve?(Me.setAttribute("aria-disabled","true"),Me.title="Saving is paused: choose Reload or Keep editing above"):(Me.removeAttribute("aria-disabled"),Me.removeAttribute("title")))}let ic=()=>{if(ae.cancel(),p||!Tt.dirty)return;let g=k(),M=JSON.stringify(g);pe=!1,Lt=Lt.catch(()=>{}).then(async()=>{if(!Tt.dirty)return;let _={...g,base_revision:E.base},{post:D}=await T(`/api/posts/${e}`,{method:"PUT",json:_});E.saved(D.current_revision),Tt.markSaved(M)}).catch(_=>{if(Oe(_)){U("This post was deleted elsewhere, so your last edits weren\u2019t saved.");return}U(_ instanceof te&&_.status===409?"Changed elsewhere, so your edits weren\u2019t saved":`Couldn\u2019t save your changes: ${Xe(_)}`)}),qo(Lt)},rc={dirty:()=>pe,beforeLeave(){return i?"leave":pe&&(Un||Ve)?"confirm":(ic(),"leave")},manualSave(){Me&&!Me.disabled&&Me.click()}};if(!p){for(let g of[L,y])g.addEventListener("input",to);for(let g of[L])g.addEventListener("blur",()=>Be(!0).catch(()=>{})),g.addEventListener("keydown",M=>{M.key==="Enter"&&!M.isComposing&&M.keyCode!==229&&(M.preventDefault(),Be(!0).catch(()=>{}))})}let Ke=c("#freshnessBanner");function Hi(){Ve=!1,Ai(),E.clearWarning(),Ke.hidden=!0,f(Ke,o``)}function Pi(g){if(p)return;if(Ve=!0,et=null,Ai(),E.noteWarned(g),g.kind==="locked")f(Ke,o`<span><span aria-hidden="true">⚠️</span> This draft was scheduled elsewhere and can no longer be edited here.</span><span class="row"><button type="button" class="ghost" id="freshReload">Reload</button></span>`);else{let _=Jt(g.author,g.client);f(Ke,o`<span><span aria-hidden="true">⚠️</span> This draft was changed elsewhere${_?o`, last edited by <strong>${_}</strong>`:null}. Saving is paused until you choose: Reload to load that version (discards your unsaved edits), or Keep editing to keep yours, and your next save overwrites that version.</span><span class="row"><button type="button" class="ghost" id="freshReload">Reload</button><button type="button" class="ghost" id="freshKeep">Keep editing</button></span>`)}Ke.hidden=!1,c("#freshReload",Ke).onclick=()=>{Hi(),s()};let M=Ke.querySelector("#freshKeep");M&&(M.onclick=()=>{E.adoptWarned(),Hi(),qn(),pe&&Ci()})}function Rt(g){return Oe(g)?(a(),!0):!1}if(!p){let g=async()=>{if(nn||Ve||i||document.hidden)return;let M=E.base;try{let _=await T(`/api/posts/${e}`,{signal:n}),D=E.decide({status:_.post.status,revision:_.post.current_revision,author:_.post.author,client:_.post.author_client},{saving:nn,baseAtRequest:M});D!=="ignore"&&D!=="fresh"&&Pi(D)}catch(_){Oe(_)&&a()}};mt(1e4,g,n),au(g,n)}if(c("#webLink").addEventListener("click",()=>{p||Be(!0).catch(()=>{})}),p&&d){let g=l?.send??{...d,conditions:[]},M=c("#schedWhen"),_=c("#schedControls"),D="",se=0,ce=!1,Ee=c("#rescheduleSchedule"),re=c("#cancelSchedule"),J=be=>g.actions===void 0||Ze({actions:g.actions},be),Se=()=>{let be=Date.now(),ke=g.phase==="due"||be>=g.fire_at;ke?ce||(Ee.hidden=!0,re.hidden=!0):(ce=!0,Ee.hidden=!J("reschedule"),re.hidden=!J("cancel")),Ee.disabled=ke,re.disabled=ke,_.hidden=Ee.hidden&&re.hidden;let _e=iu(g,ke),At=String(_e);At!==D&&(D=At,f(M,_e)),!ke&&g.fire_at-be<=1e3&&g.fire_at!==se&&(se=g.fire_at,ft(g.fire_at,Se,n))};Se(),mt(1e3,Se,n);let pt=c("#schedRemade"),De=c("#testHint"),xe=c("#schedDailyWrites"),sn=c("#schedBy"),Ct=()=>{let be=Aa(g,w);sn.hidden=be===null,sn.textContent=be??"";let ke=he(g,"remade");pt.hidden=!ke,c("#schedRemadeMsg").textContent=ke?.message??"",De.hidden=!he(g,"untested");let _e=he(g,"daily_writes");xe.hidden=!_e,c("#schedDailyWritesMsg").textContent=_e?.message??""};Ct();let on=be=>fn(be,{update(ke,_e){let At=!_e&&ke.rev!==g.rev;if(g=ke,At&&j(),_e?.to==="sending"||_e?.to==="sent"||_e?.to==="complete"){U("Your send started, so this page switched to its live watch."),Ns(`#/sent/${ke.id}`);return}if(_e?.to==="canceled"){U("The schedule was canceled elsewhere, so this post is a draft again."),s();return}Se(),Ct()},removed:a,stale:s},n);l?on(l):Bi(5e3,async()=>{let be=await T(`/api/sends/${d.id}`,{signal:n});return Ua(be.send,s)||(g=be.send,Se(),Ct(),on(be)),!1},n),Ee.onclick=()=>{As({id:g.id,post_id:e,fire_at:g.fire_at},s,n,{...h})},re.onclick=()=>Y(re,"Canceling\u2026",async()=>{try{await T(`/api/sends/${d.id}/cancel`,{method:"POST"}),U("Schedule canceled"),s()}catch(be){Oe(be)?a():be instanceof te&&be.code==="window_closed"?(g={...g,phase:"due"},U("Too late to cancel: the send time has passed, so this email is going out."),Fe()):U(Xe(be))}}).finally(Se)}async function no(g){if(g.type.startsWith("image/"))try{let M=new FormData;M.append("file",g);let{image:_}=await T(`/api/posts/${e}/images`,{method:"POST",body:M}),D=y.selectionStart,se=`
|
|
163
|
+

|
|
164
|
+
`;y.value=y.value.slice(0,D)+se+y.value.slice(D),y.selectionStart=y.selectionEnd=D+se.length,to(),U("Image added")}catch(M){Rt(M)||U(Xe(M))}}let Ge=c("#composerBody");if(p){let g=_=>_.metaKey||_.ctrlKey?["x","z","y"].includes(_.key.toLowerCase()):_.key.length===1||_.key==="Enter"||_.key==="Backspace"||_.key==="Delete",M=[y,L];for(let _ of M)_.addEventListener("keydown",D=>{g(D)&&Re()}),_.addEventListener("paste",Re);Ge.addEventListener("dragover",_=>_.preventDefault()),Ge.addEventListener("drop",_=>{_.preventDefault(),Re()})}else{let g=c("#imgInput"),M=c("#dropFoot");Ge.addEventListener("dragover",_=>{_.preventDefault(),Ge.classList.add("dragover")}),Ge.addEventListener("dragleave",_=>{_.target===Ge&&Ge.classList.remove("dragover")}),Ge.addEventListener("drop",_=>{_.preventDefault(),Ge.classList.remove("dragover"),Z("edit");for(let D of _.dataTransfer?.files??[])no(D)}),y.addEventListener("paste",_=>{for(let D of _.clipboardData?.items||[])if(D.type.startsWith("image/")){let se=D.getAsFile();se&&(_.preventDefault(),no(se))}}),M.onclick=()=>g.click(),g.onchange=()=>{for(let _ of g.files??[])no(_);g.value=""}}let ac=c("#warnings");function lc(g){f(ac,g?.length?o`<div class="warnings"><strong>Warnings:</strong> ${g.join("; ")}</div>`:o``)}c("#testBtn").onclick=()=>{let g=p?"Delivers the frozen copy that will send, exactly as it will fire, so you can check it in a client. One address per line.":"Delivers the rendered email to real inboxes so you can check it in a client. One address per line.",M=ve(),_=me(o`<h3>Send a test</h3><p class="hint">${g}</p>${us()}${M?null:o`<label for="testTo">Recipients</label><textarea id="testTo" rows="3" placeholder="you@example.com"></textarea><p class="hint" id="testDefaultsHint" hidden></p>`}<div class="actions"><button type="button" id="tCancel">Cancel</button><button type="button" class="primary" id="tGo">Send test</button></div>`,n),D=c("#tGo",_.el);if(c("#tCancel",_.el).onclick=_.close,D.disabled=M,M){c("#tCancel",_.el).focus();return}let se=c("#testTo",_.el);se.focus(),T("/api/settings").then(ce=>{let Ee=ce.settings.test_recipients||[];if(Ee.length&&!se.value.trim()){se.value=Ee.join(`
|
|
165
|
+
`),_.clearError();let re=c("#testDefaultsHint",_.el);re.textContent="Pre-filled from your default test recipients (Settings).",re.hidden=!1}}).catch(()=>{}),D.onclick=()=>Y(D,"Sending\u2026",async()=>{_.clearError();let{valid:ce,invalid:Ee}=bs(se.value),re=gs(Ee);if(re){_.error(re,se);return}if(!ce.length){_.error("Enter at least one email address",se);return}try{p||await Be(!0);let J=0,Se=[],pt=null;for(let De of ce)try{let xe=await T(`/api/posts/${e}/test`,{method:"POST",json:{to:De}});xe.sent?J++:Se.push({email:De,message:xe.not_sent?.message??""}),pt=xe.warnings}catch(xe){if(Oe(xe)||xe instanceof te&&xe.status===401)throw xe;Se.push({email:De,message:q(xe)})}if(lc(pt),p&&J>0&&Fe(),Se.length){se.value=Se.map(De=>De.email).join(`
|
|
166
|
+
`),_.error(vs(J,ce.length,Se));return}_.close(),U(Nt(`Test sent to ${J} address${J===1?"":"es"}`))}catch(J){if(Oe(J)){_.close(),Rt(J);return}_.error(Xe(J))}})};let Mi=p?null:c("#scheduleBtn");return Mi&&(Mi.onclick=()=>{if(!F())return;let g=yt(rs()),M=yt(new Date(Date.now()+24*3600*1e3)),_=!S,D={...h,subject:L.value};D.slugAuto&&!D.slugTaken&&(D.slug=Rs(D.subject)||D.slug);let se="It sends at the time you pick, with a cancelable window until then.",ce=()=>o`<h3 id="schHead">Schedule this post</h3><p class="hint" id="schHint">${se}</p>${Qi()}${So()}${_?null:o`<label for="schWhen">Send at</label><input type="datetime-local" id="schWhen" min="${g}" value="${M}"><div class="dialog-settings" id="schForm"></div>`}<div class="actions"><button type="button" id="schCancel">Cancel</button><button type="button" class="primary" id="schGo">Schedule</button></div>${_?null:o`<div class="altrow"><span class="altrow-note">Or send as soon as possible.</span><button type="button" class="linkbtn" id="toSendNow">Send now →</button></div>`}`,Ee=M,re=me(ce(),n),J=c(".modal",re.el),Se=null,pt=()=>(Se??=T("/api/subscribers?status=confirmed&suppressed=hide&limit=1",{signal:n}).then(fe=>fe.page.total).catch(()=>null),Se),De=async()=>{if(!J.querySelector("#schDailyWrites"))return;let fe=await pt(),Ce=J.querySelector("#schDailyWrites");Ce&&fe!==null&&fe>Oo&&(Ce.textContent=ya(fe),Ce.hidden=!1)},xe=()=>{re.close(),Ke.scrollIntoView({block:"nearest"})},sn=()=>$t(c("#schForm",J),D,"sch"),Ct=()=>({email_only:D.emailOnly,...xn(h,D)}),on=fe=>{kn(J,"sch",fe)||re.error(Xe(fe))},be=()=>Y(c("#schGo",J),"Scheduling\u2026",async()=>{re.clearError();let fe=c("#schWhen",J),Ce=fe.value?new Date(fe.value).getTime():Number.NaN;if(Number.isNaN(Ce)){re.error("Pick a valid date & time",fe);return}if(is(Ce)){re.error(os(),fe);return}try{if(await Be(!0)==="refused"){xe();return}await T(`/api/posts/${e}/schedule`,{method:"POST",json:{fire_at:new Date(Ce).toISOString(),...Ct()}}),re.close(),U(Nt(`Scheduled for ${K(Ce)}. Send yourself a test.`)),s()}catch(ze){if(Oe(ze)){re.close(),Rt(ze);return}if(ze instanceof te&&ze.field==="fire_at"){re.error(Xe(ze),c("#schWhen",J));return}on(ze)}}),ke=()=>Y(c("#snGo",J),"Queuing\u2026",async()=>{re.clearError();try{if(await Be(!0)==="refused"){xe();return}let{send:fe}=await T(`/api/posts/${e}/send`,{method:"POST",json:Ct()});re.close(),U(Nt(`Sends at ${K(fe.fire_at)}, cancelable until then.`)),s()}catch(fe){if(Oe(fe)){re.close(),Rt(fe);return}on(fe)}});function _e(){if(J.setAttribute("aria-labelledby","schHead"),c("#schCancel",J).onclick=re.close,c("#schGo",J).onclick=be,c("#schGo",J).disabled=_,_){c("#schCancel",J).focus();return}c("#toSendNow",J).onclick=At,c("#schWhen",J).value=Ee,sn(),c("#schWhen",J).focus(),De()}async function At(){let fe=J.querySelector("#schWhen");fe&&(Ee=fe.value),f(J,o`<h3 id="snHead">Send now?</h3><p class="hint">Sends this draft, as it is now, to <strong id="snWho">your subscribers</strong> in ${Zi()}. The post locks until then, and you can cancel any time before it starts sending.</p><div class="dialog-settings" id="schForm"></div>${So()}<div class="actions"><button type="button" class="linkbtn actions-back" id="toSchedule">← Back to schedule</button><button type="button" id="snCancel">Cancel</button><button type="button" class="primary" id="snGo">Send now</button></div>`),J.setAttribute("aria-labelledby","snHead"),c("#snCancel",J).onclick=re.close,c("#snGo",J).onclick=ke,sn(),c("#snGo",J).disabled=!Gt(u,"send_now"),c("#toSchedule",J).onclick=()=>{f(J,ce()),_e()},c("#snGo",J).focus(),De();let Ce=await pt(),ze=J.querySelector("#snWho");ze&&Ce!==null&&(ze.textContent=`${Ce} recipient${Ce===1?"":"s"}`)}_e()}),rc}function Ua(e,t){return e.status==="sending"||e.status==="sent"?(Ns(`#/sent/${e.id}`),!0):e.status==="canceled"?(t(),!0):!1}function iu(e,t){return Le(e,"missed")?o`Scheduled for <strong>${K(e.fire_at)}</strong> · <span class="countdown countdown-missed">${ys(e.fire_at)}</span>`:t?o`Scheduled for <strong>${K(e.fire_at)}</strong> · <span class="countdown">${hn(e.fire_at,!0)}</span>`:o`Scheduled for <strong>${K(e.fire_at)}</strong> · <span class="countdown">${hn(e.fire_at)}</span>`}function Oe(e){return e instanceof te&&e.status===404}function ru(e){let t=e.post.send;return t?.status==="sending"?`#/sent/${t.id}`:e.post.status==="sent"?t?`#/sent/${t.id}`:"#/sent":null}function Ns(e){location.replace(e)}function au(e,t){document.addEventListener("visibilitychange",()=>{document.hidden||e()},{signal:t})}function lu(e){return e.trim().toLowerCase().replace(/[^\p{L}\p{N}\s_-]/gu,"").replace(/\s/g,"-")}function Fa(e){let t=new Map;return e.map(n=>{let s=lu(n),i=t.get(s)??0;return t.set(s,i+1),i?`${s}-${i}`:s})}var Vo=null;function cu(e){let t=document.createElement("div");f(t,V(e.html||""));let n=(t.querySelector("p")?.textContent||"").trim().replace(/\s+/g," "),s=/[:;,]$/.test(n),i=n.replace(/[\s:;,]+$/,""),a=150;return i.length>a?`${i.slice(0,a).replace(/[\s.,;:]+\S*$/,"")}\u2026`:s?`${i}\u2026`:i}function du(e){let t=e.querySelector("code"),n=t?.className.match(/(?:^|\s)language-(\S+)/)?.[1]??null,s=(t??e).textContent?.replace(/\n$/,"")??"",i=n==="bash"||n==="sh"||n==="shell"?Ps(s):n==="json"||n==="jsonc"?Fo(s):o`${s}`;return ra(i,s)}async function Ko(e,t,n,s){if(oe(n,"Docs"),f(t,Ot("docs",null,o`<div class="docs-index"><p class="muted">Loading…</p></div>`)),!Vo)try{Vo=await T("/api/docs",{signal:n})}catch(d){n.aborted||ie(c(".room-main",t),q(d),()=>ee((u,m)=>Ko(e,u,m,s)));return}let{sets:i,docs:a}=Vo,r=i[0];if(!a.length||!r){f(c(".room-main"),o`<p class="muted">No documentation.</p>`);return}let l=e?i.find(d=>d.id===e):r;l?Wa(t,l,i,a,n):e&&mu(t,i,a,e,n,s?uu(s):void 0)}function uu(e){try{return decodeURIComponent(e)}catch{return}}function Wa(e,t,n,s,i){oe(i,`${t.name} docs`);let a=(h,p)=>{let S=cu(h);return o`<li><a class="doc-card" href="#/docs/${h.slug}">${p===null?null:o`<span class="doc-card-n">${String(p).padStart(2,"0")}</span>`}<span class="doc-card-main"><span class="doc-card-t">${h.title} <span class="doc-card-go" aria-hidden="true">→</span></span>${S?o`<span class="doc-card-d">${S}</span>`:null}</span></a></li>`},r=t.sections.map(h=>{let p=s.filter(I=>I.set===t.id&&I.section===h.id);if(!p.length)return null;let S=p.map((I,C)=>a(I,h.numbered?C+1:null)),E=h.blurb?o`<div class="doc-section-blurb">${V(h.blurb)}</div>`:null;return o`<section class="doc-section"><h2 class="doc-section-t">${h.title}</h2>${E}${h.numbered?o`<ol class="doc-cards">${S}</ol>`:o`<ul class="doc-cards">${S}</ul>`}</section>`}),l=o`<nav class="docs-tabs" aria-label="Doc sets">${n.map(h=>o`<a href="#/docs/${h.id}" title="${h.title}"${h.id===t.id?o` aria-current="page"`:null}>${h.name}</a>`)}</nav>`,d=o`<div class="docs-index"><h1>Kestrel docs</h1><p class="docs-index-intro"><strong>Publishing</strong> covers writing and sending your newsletter, from naming your publication to what happens after each send. <strong>Self-hosting</strong> covers deploying Kestrel to your own Cloudflare account and keeping it running. One person often does both.</p>${l}${r}</div>`,u=Q.appConfig?.deployment.build.repo_url||"",m=(h,p,S=p)=>o`<a class="rail-link" href="${h}" target="_blank" rel="noopener" aria-label="${p}"><span class="rail-link-full">${p}</span><span class="rail-link-short" aria-hidden="true">${S}</span> <span aria-hidden="true">↗</span></a>`,w=o`<div class="toc-label">Kestrel</div>${m("https://getkestrel.dev","Project site","Project")}${u?[m(u,"Source on GitHub","Source"),m(`${u}/blob/HEAD/LICENSE`,"License")]:null}`;f(e,Ot("docs",w,d)),window.scrollTo(0,0)}var Go=matchMedia("(max-width: 720px)");function Va(e){if(!e)return;let t=Go.matches;e.open=!t,c("summary",e).tabIndex=t?0:-1}var Ka=()=>document.querySelector("details#tocOnPage"),qa=!1;function pu(){qa||(qa=!0,Go.addEventListener("change",()=>Va(Ka())))}var ja=e=>`doc-h-${e}`;function mu(e,t,n,s,i,a){let r=n.findIndex(x=>x.slug===s),l=n[r],d=t.find(x=>x.id===l?.set);if(!l||!d){let x=t[0];U(`No doc named \u201C${s}\u201D, so here\u2019s the index.`),history.replaceState(history.state,"","#/docs"),x&&Wa(e,x,t,n,i);return}oe(i,l.title);let u=n.filter(x=>x.set===l.set&&x.section===l.section),m=u.indexOf(l),w=u[m-1],h=u[m+1],p=(x,F)=>o`<a href="#/docs/${x.slug}" aria-label="${F}: ${x.title}">${F==="Previous"?o`<span aria-hidden="true">←</span><span class="doc-topnav-word">Previous</span>`:o`<span class="doc-topnav-word">Next</span><span aria-hidden="true">→</span>`}</a>`,S=w||h?o`<nav class="doc-topnav" aria-label="Adjacent docs">${w?p(w,"Previous"):null}${h?p(h,"Next"):null}</nav>`:null;f(e,Ot("docs",o`<div id="docToc"></div>`,o`<article class="doc" id="docsMain"></article>`));let E=c("#docToc"),I=c("#docsMain");f(I,o`<section class="doc-part" id="doc-${l.slug}">${V(l.html)}</section>`);let C=c("section.doc-part",I),H=N("h1, h2, h3, h4",C),L=Fa(H.map(x=>x.textContent||""));for(let[x,F]of H.entries()){let P=L[x]??"";F.dataset.anchor=P,F.id=ja(P)}let v=C.querySelector("h1"),y=[];if(v&&y.push({id:v.id,anchor:"",title:v.textContent||l.title}),S){let x=document.createElement("div");x.className="doc-head",f(x,S),v?(v.before(x),x.prepend(v)):C.prepend(x)}let $=document.createElement("p");$.className="eyebrow doc-set",f($,o`<a href="#/docs/${d.id}">${d.name}</a>`),C.prepend($);for(let x of N("h2",C))y.push({id:x.id,anchor:x.dataset.anchor||"",title:x.textContent||""});let A=document.createElement("nav");A.className="doc-pager",f(A,o`${w?o`<a class="doc-pager-btn prev" href="#/docs/${w.slug}"><span class="doc-pager-dir">← Previous</span><span class="doc-pager-title">${w.title}</span></a>`:o`<span></span>`}${h?o`<a class="doc-pager-btn next" href="#/docs/${h.slug}"><span class="doc-pager-dir">Next →</span><span class="doc-pager-title">${h.title}</span></a>`:o`<span></span>`}`),I.appendChild(A);let W=y.map(x=>o`<a class="toc-sub" href="#/docs/${l.slug}${x.anchor?`/${x.anchor}`:""}" data-target="${x.id}">${x.title}</a>`);f(E,y.length?o`<details class="toc-onpage" id="tocOnPage"><summary class="toc-label">On this page</summary>${W}</details>`:o``);let z=Ka();Va(z),pu();let G=x=>{if(z)for(let F of N(".toc-sub",z))F.classList.toggle("on",F.dataset.target===x)};E.addEventListener("click",x=>{let F=x.target instanceof Element?x.target.closest("a[data-target]"):null,P=F?.dataset.target;P&&(x.preventDefault(),G(P),z&&Go.matches&&(z.open=!1),history.replaceState(history.state,"",F?.getAttribute("href")??location.hash),document.getElementById(P)?.scrollIntoView({block:"start"}))});for(let x of N("a[href^='http']",I))x.target="_blank",x.rel="noopener";for(let x of N("pre",C)){let F=document.createElement("div");f(F,du(x)),x.replaceWith(...F.childNodes)}je(I);let b=y.map(x=>x.id),k=b[0];if(z&&k){let x=b[b.length-1]??k,P=(document.querySelector(".room-bar")?.getBoundingClientRect().height||54)+26,B=()=>{if(!document.getElementById(k)){document.onscroll=null;return}let ne=k;if(Math.ceil(window.innerHeight+window.scrollY)>=document.documentElement.scrollHeight)ne=x;else for(let j of b)if((document.getElementById(j)?.getBoundingClientRect().top??Number.POSITIVE_INFINITY)<=P)ne=j;else break;G(ne)};document.onscroll=B,B()}let R=a?document.getElementById(ja(a)):null;R?R.scrollIntoView({block:"start"}):window.scrollTo(0,0)}function zo(e){let t=new Set(e.groups.flatMap(n=>n.routes.flatMap(s=>(s.errors??[]).map(i=>i.code))));return e.refusals.flatMap(n=>n.codes.filter(s=>!t.has(s.code)).map(s=>({...s,move:n.move})))}function xt(e){return e.replace(/\([^)]*\)/g,"").replace(/\{[^}]*\}\??/g,"")||"/"}function Qt(e){return e.title.toLowerCase().replace(/'s\b/g,"").split(/[^a-z0-9]+/).filter(t=>t!==""&&t!=="a"&&t!=="an"&&t!=="the").join("-")}var fu=/`([^`]+)`|\*\*([^*]+)\*\*|\[([^\]]+)\]\(([^)\s]+)\)/g;function hu(e){return/^https:\/\//i.test(e)||/^\/(?![/\\])/.test(e)}function ge(e){let t=[],n=0;for(let s of e.matchAll(fu)){let i=s.index??0;t.push(e.slice(n,i));let[,a,r,l,d]=s;a!==void 0?t.push(o`<code>${a}</code>`):r!==void 0?t.push(o`<strong>${ge(r)}</strong>`):l!==void 0&&d!==void 0&&t.push(hu(d)?o`<a href="${d}">${ge(l)}</a>`:ge(l)),n=i+s[0].length}return t.push(e.slice(n)),o`${t}`}function _n(e,t){return o`${e.split(/\n\s*\n/).filter(n=>n.trim()).map(n=>{let s=n.trim().split(`
|
|
167
|
+
`),i=s.findIndex(l=>l.startsWith("- "));if(i===-1)return o`<p class="${t}">${ge(n.trim())}</p>`;let a=s.slice(0,i).join(" ").trim(),r=s.slice(i).reduce((l,d)=>(d.startsWith("- ")||l.length===0?l.push(d.replace(/^- /,"")):l[l.length-1]=`${l[l.length-1]} ${d.trim()}`,l),[]);return o`${a?o`<p class="${t}">${ge(a)}</p>`:null}<ul class="${t} prose-list">${r.map(l=>o`<li>${ge(l)}</li>`)}</ul>`})}`}function bu(e){return e==="access"?['-H "CF-Access-Client-Id: $CF_ACCESS_CLIENT_ID"','-H "CF-Access-Client-Secret: $CF_ACCESS_CLIENT_SECRET"']:['-H "Authorization: Bearer $TOKEN"']}function Ga(e,t,n){if(e.access==="webhook")return null;let s=(e.query??[]).filter(l=>l.required),i=s.length?`?${s.map(l=>`${l.name}=:${l.name}`).join("&")}`:"",a=`"${t}${xt(e.path)}${i}"`,r=[e.method==="GET"?`curl ${a}`:`curl -X ${e.method} ${a}`];if(e.access==="admin"&&r.push(...bu(n)),e.example?.request!==void 0){let l=JSON.stringify(e.example.request).replaceAll("'","'\\''");r.push('-H "Content-Type: application/json"',`-d '${l}'`)}else if(e.accepts?.includes("multipart/form-data"))for(let l of(e.body??[]).filter(d=>d.required))r.push(`-F "${l.name}=${l.type==="file"?"@":""}:${l.name}"`);return r.join(` \\
|
|
168
|
+
`)}function Zo(e,t){return t===void 0?null:zt(e,La(t),JSON.stringify(t,null,2))}function gu(e){let t=Ga(e,location.origin,Q.session?.auth.mode??"dev");return t===null?null:zt("curl",Ps(t),t)}function Os(e){return o`${e.split(/(?<=[_./])/).map((t,n)=>o`${n?o`<wbr>`:null}${t}`)}`}function rt(e,t,n,s){return o`<div class="block api-sec"><div class="block-head"><span class="block-label">${e}${n?o`<span class="api-sec-meta">${n}</span>`:null}</span></div>${s??null}${t}</div>`}function Jo(e,t,n,s){return o`<div class="api-row"><div class="api-row-head"><code class="api-row-name">${Os(e)}</code>${t?o`<span class="api-row-type">${t}</span>`:null}${n?o`<span class="api-req">Required</span>`:null}</div><div class="api-row-desc">${s}</div></div>`}function Qo(e,t,n,s){return o`<div class="api-lrow"><span class="api-st api-st-${String(e)[0]}xx">${e}</span><div><div class="api-row-head"><code class="api-row-name">${t}</code></div>${n?o`<div class="api-with">${n}</div>`:null}<div class="api-row-desc">${s}</div></div></div>`}function vu(e){if(!e?.length)return null;let t=e.map(n=>Jo(n.name,null,n.required,ge(n.description)));return rt("Query",o`<div class="api-list api-query">${t}</div>`)}function yu(e,t){if(!e?.length)return null;let n=e.map(i=>Jo(i.name,i.type,i.required,ge(i.description))),s=t?.length?o` · ${t.map((i,a)=>o`${a?", ":""}<code>${i}</code>`)}`:null;return rt("Body",o`<div class="api-list api-body">${n}</div>`,s)}function wu(e,t){if(!e?.length)return null;let n=e.map(s=>Qo(s.status,Os(s.code),s.details?.length?o`with ${s.details.map((i,a)=>o`${a?", ":""}<code>${i}</code>`)}`:null,o`${ge(s.when??t.get(s.code)??"")}<span class="api-move-next">${s.move}</span>`));return rt("Refusals",o`<div class="api-ledger api-errors">${n}</div>`)}function Su(e){let t=s=>o`<ul class="api-values">${s.map(i=>o`<li><code>${i.value}</code> ${ge(i.description)}</li>`)}</ul>`,n=[...new Set(e.map(s=>s.group).filter(s=>s!==void 0))];return n.length?o`${n.map(s=>o`<div class="api-values-group">${ge(s)}</div>${t(e.filter(i=>i.group===s))}`)}`:t(e)}function Xo(e){let t=e.map(n=>Jo(n.name,n.object?o`<a href="#/api-reference/objects-${n.object}" class="api-obj-link" data-sec="objects-${n.object}">${n.type}</a>`:n.type,!1,o`${ge(n.description)}${n.values?.length?Su(n.values):null}`));return o`<div class="api-list api-fields">${t}</div>`}function $u(e,t){if(!e)return null;let n=e.object?o`<a href="#/api-reference/objects-${e.object}" class="api-obj-link" data-sec="objects-${e.object}">${t.get(e.object)??e.object}</a>`:null,s=n?e.as?o`<p class="api-returns"><code>${e.as}</code>: ${e.list?o`a list of ${n}`:n}${e.fields?.length?", and:":null}</p>`:o`<p class="api-returns">${n}${e.fields?.length?", and:":null}</p>`:null;return rt("Returns",e.fields?.length?Xo(e.fields):null,null,s)}function Eu(e){return o`${xt(e).split(/(:[A-Za-z_]+)/).map((t,n)=>n%2?o`<span class="api-param">${t}</span>`:t)}`}function Tn(e,t){return"route"in t?o`<a class="api-self" href="#/api-reference/${t.route}" data-route="${t.route}">${O("link")}${e}</a>`:o`<a class="api-self" href="#/api-reference/${t.sec}" data-sec="${t.sec}">${O("link")}${e}</a>`}function xu(e){let t=new Map;for(let n of e.objects){let s=e.groups.find(i=>i.resources.some(a=>a.key===n.resource));if(s){let i=`${s.access}-${n.resource}`;t.set(i,[...t.get(i)??[],n])}}return t}function ku(e,t){let n=e.returns?.object;return[e.title,e.method,xt(e.path),e.summary,...(e.errors??[]).map(s=>s.code),...n?[n,t.objects.get(n)??"",e.returns?.as??""]:[]].join(" ").toLowerCase()}function _u(e,t){return o`<li data-hay="${ku(e,t)}" data-path="${xt(e.path).toLowerCase()}" id="route-${Qt(e)}" data-route="${Qt(e)}"><article class="api-op">
|
|
168
169
|
<div class="api-op-head">
|
|
169
|
-
<h4 tabindex="-1">${
|
|
170
|
+
<h4 tabindex="-1">${Tn(e.title,{route:Qt(e)})}</h4>
|
|
170
171
|
</div>
|
|
171
|
-
<p class="api-op-call"><span class="api-method m-${e.method}">${e.method}</span><code class="api-path">${
|
|
172
|
+
<p class="api-op-call"><span class="api-method m-${e.method}">${e.method}</span><code class="api-path">${Eu(e.path)}</code><button type="button" class="copy-btn api-copy-path" data-copy="${xt(e.path)}" data-copy-word="" aria-label="Copy path" title="Copy path">${Te(!1,"")}</button></p>
|
|
172
173
|
<div class="api-op-body">
|
|
173
174
|
<div class="api-op-text">
|
|
174
175
|
<p class="api-summary">${ge(e.summary)}</p>
|
|
175
|
-
${e.description?
|
|
176
|
-
${
|
|
177
|
-
${
|
|
178
|
-
${
|
|
179
|
-
${
|
|
176
|
+
${e.description?_n(e.description,"api-desc"):null}
|
|
177
|
+
${vu(e.query)}
|
|
178
|
+
${yu(e.body,e.accepts)}
|
|
179
|
+
${$u(e.returns,t.objects)}
|
|
180
|
+
${wu(e.errors,t.meanings)}
|
|
180
181
|
</div>
|
|
181
182
|
<div class="api-op-code">
|
|
182
|
-
${
|
|
183
|
-
${
|
|
184
|
-
${
|
|
183
|
+
${Zo("Request",e.example?.request)}
|
|
184
|
+
${Zo("Response",e.example?.response)}
|
|
185
|
+
${gu(e)}
|
|
185
186
|
</div>
|
|
186
187
|
</div>
|
|
187
|
-
</article></li>`}var
|
|
188
|
-
<div class="api-op-head"><h4 tabindex="-1">${
|
|
188
|
+
</article></li>`}var Ja=(e,t)=>e.routes.filter(n=>n.resource===t.key),Tu=80;function Lu(e){let t=e.columns.map((i,a)=>a>0&&e.rows.every(r=>(r[a]??"").length<=Tu)),n=e.columns.findIndex((i,a)=>a>0&&!t[a]),s=e.rows.map(i=>{let a=/^`([^`]+)`$/.exec(i[0]??"")?.[1],r=e.columns.flatMap((d,u)=>t[u]?[o`<span class="api-row-meta"><span class="api-row-key">${d}</span> ${ge(i[u]??"")}</span>`]:[]),l=e.columns.flatMap((d,u)=>u>0&&!t[u]?[o`<div class="api-row-desc">${u===n?null:o`<span class="api-row-key">${d}:</span> `}${ge(i[u]??"")}</div>`]:[]);return o`<div class="api-row"><div class="api-row-head"><code class="api-row-name">${a===void 0?ge(i[0]??""):Os(a)}</code>${r}</div>${l}</div>`});return rt(e.title,o`<div class="api-list api-value-rows">${s}</div>`,null,_n(e.description,"api-prose"))}function Ru(e){return o`<article class="api-op api-object" id="api-objects-${e.key}" data-sec="objects-${e.key}">
|
|
189
|
+
<div class="api-op-head"><h4 tabindex="-1">${Tn(e.title,{sec:`objects-${e.key}`})}</h4></div>
|
|
189
190
|
<p class="api-op-call"><span class="api-method m-OBJECT">Object</span><span class="api-path">${e.fields.length} ${e.fields.length===1?"field":"fields"}</span></p>
|
|
190
191
|
<div class="api-op-body">
|
|
191
192
|
<div class="api-op-text">
|
|
192
|
-
${
|
|
193
|
-
${
|
|
194
|
-
${(e.tables??[]).map(
|
|
193
|
+
${_n(e.description,"api-prose")}
|
|
194
|
+
${Xo(e.fields)}
|
|
195
|
+
${(e.tables??[]).map(Lu)}
|
|
195
196
|
</div>
|
|
196
|
-
<div class="api-op-code">${
|
|
197
|
+
<div class="api-op-code">${Zo("Example",e.example)}</div>
|
|
197
198
|
</div>
|
|
198
|
-
</article>`}function
|
|
199
|
-
<div class="api-res-head"><h3 tabindex="-1">${
|
|
200
|
-
${a.map(
|
|
201
|
-
<ul class="api-rows">${i.map(r=>
|
|
202
|
-
</div>`}function
|
|
203
|
-
<h2 tabindex="-1">${
|
|
199
|
+
</article>`}function Cu(e,t,n){let s=`${e.access}-${t.key}`,i=Ja(e,t),a=n.heads.get(s)??[];return o`<div class="api-res" id="api-${s}" data-sec="${s}">
|
|
200
|
+
<div class="api-res-head"><h3 tabindex="-1">${Tn(t.title,{sec:s})}</h3></div>
|
|
201
|
+
${a.map(Ru)}
|
|
202
|
+
<ul class="api-rows">${i.map(r=>_u(r,n))}</ul>
|
|
203
|
+
</div>`}function Au(e,t){return o`<section class="api-section" id="api-${e.access}" data-tier="${e.access}">
|
|
204
|
+
<h2 tabindex="-1">${Tn(e.title,{sec:e.access})}</h2>
|
|
204
205
|
<p class="api-blurb muted">${ge(e.blurb)}</p>
|
|
205
|
-
${e.resources.map(n=>
|
|
206
|
-
</section>`}function
|
|
207
|
-
<div class="api-res-head"><h3 tabindex="-1">${
|
|
208
|
-
${
|
|
209
|
-
${s.key==="errors"?
|
|
210
|
-
${s.fields?.length?rt(s.key==="errors"?"The error body":"Fields",
|
|
211
|
-
${s.key==="errors"?
|
|
206
|
+
${e.resources.map(n=>Cu(e,n,t))}
|
|
207
|
+
</section>`}function Hu(e){let t=zo(e);if(!t.length)return null;let n=t.map(s=>Qo(s.status,Os(s.code),null,ge(s.meaning)));return rt("Refusals any route can give",o`<div class="api-ledger api-refusals">${n}</div>`)}function Pu(e){let t=zo(e).map(s=>s.code),n=s=>o`<div class="api-res" id="api-overview-${s.key}" data-sec="overview-${s.key}" data-hay="${[s.title,...s.key==="errors"?t:[]].join(" ").toLowerCase()}">
|
|
208
|
+
<div class="api-res-head"><h3 tabindex="-1">${Tn(s.title,{sec:`overview-${s.key}`})}</h3></div>
|
|
209
|
+
${_n(s.text,"api-prose")}
|
|
210
|
+
${s.key==="errors"?Mu(e.statuses):null}
|
|
211
|
+
${s.fields?.length?rt(s.key==="errors"?"The error body":"Fields",Xo(s.fields)):null}
|
|
212
|
+
${s.key==="errors"?Hu(e):null}
|
|
212
213
|
</div>`;return o`<section class="api-section" id="api-overview" data-tier="overview">
|
|
213
214
|
${e.concepts.map(n)}
|
|
214
|
-
</section>`}function
|
|
215
|
-
${
|
|
216
|
-
${
|
|
215
|
+
</section>`}function Mu(e){let t=e.map(n=>Qo(n.status,o`${n.name}`,null,ge(n.meaning)));return rt("Status codes",o`<div class="api-ledger api-statuses">${t}</div>`)}function Iu(e,t){let n=(i,a)=>o`<a href="#/api-reference/${i}" class="api-nav-res" data-sec="${i}">${a}</a>`,s=(i,a)=>o`<div class="api-nav-ops" data-of="${i.access}-${a.key}">${[...(t.heads.get(`${i.access}-${a.key}`)??[]).map(r=>o`<a href="#/api-reference/objects-${r.key}" class="api-nav-op" data-sec="objects-${r.key}">${r.title}</a>`),...Ja(i,a).map(r=>o`<a href="#/api-reference/${Qt(r)}" class="api-nav-op" data-route="${Qt(r)}">${r.title}</a>`)]}</div>`;return o`<a href="#/api-reference" class="api-nav-tier" data-sec="overview" data-tier="overview">Introduction</a>${e.concepts.map(i=>n(`overview-${i.key}`,i.title))}${e.groups.map(i=>o`<a href="#/api-reference/${i.access}" class="api-nav-tier" data-sec="${i.access}" data-tier="${i.access}">${i.title}</a>${i.resources.map(a=>[i.resources.length>1?n(`${i.access}-${a.key}`,a.title):null,s(i,a)])}`)}`}function Nu(e,t){let n=e.replace(/^[a-z]+:\/\/[^/]*/,"").replace(/[?#].*$/,"");if(!n.startsWith("/"))return!1;let s=n.replace(/(.)\/+$/,"$1").split("/"),i=t.split("/");return s.length===i.length&&i.every((a,r)=>a.startsWith(":")?s[r]!=="":a===s[r])}function Ou(e,t){let n=e.dataset.path;return(e.dataset.hay??"").includes(t)||n!==void 0&&Nu(t,n)}function za(e,t,n){let s=e.trim().toLowerCase().split(/\s+/).filter(Boolean);t.classList.toggle("filtering",s.length>0);let i=0;for(let l of N(".api-section",n)){let d=0;for(let m of N(".api-res",l)){let w=m.dataset.hay!==void 0,h=0;for(let S of w?[m]:N("li[data-hay]",m)){let E=s.every(C=>Ou(S,C));S.hidden=!E,h+=E?1:0;let I=S.dataset.route?t.querySelector(`a[data-route="${S.dataset.route}"]`):null;I&&(I.hidden=!E)}m.hidden=h===0;for(let S of N(`.api-nav-ops[data-of="${m.dataset.sec}"] a[data-sec]`,t))S.hidden=s.length>0&&h===0;let p=t.querySelector(`a[data-sec="${m.dataset.sec}"]`);p&&(p.hidden=h===0),d+=h}l.hidden=d===0;let u=t.querySelector(`a[data-tier="${l.dataset.tier}"]`);u&&(u.hidden=d===0),i+=d}let a=N(".api-section",n),r=a.filter(l=>!l.hidden).at(-1);for(let l of a)l.classList.toggle("api-last",l===r);c("#apiEmpty",n).hidden=i>0}function Yo(e,t,n){let s=(c(".room-bar").getBoundingClientRect().height||54)+8,i=N(".api-section, .api-res, .api-object, li[data-route]",t).filter(S=>!S.closest("[hidden]")),a=window.scrollY>0&&Math.ceil(window.innerHeight+window.scrollY)>=document.documentElement.scrollHeight,r;for(let S of i)if(a||S.getBoundingClientRect().top<=s)r=S;else break;let l=N("a[data-sec], a[data-route]",e).filter(S=>!S.hidden&&getComputedStyle(S).display!=="none"),d=S=>S?(S.dataset.route?l.find(I=>I.dataset.route===S.dataset.route):l.find(I=>I.dataset.sec===(S.dataset.sec??S.dataset.tier)))??d(S.parentElement?.closest(".api-res, .api-section")):void 0,u=r?.closest(".api-res")?.dataset.sec;for(let S of N(".api-nav-ops",e))S.classList.toggle("open",S.dataset.of===u);let m=d(r??i[0]);for(let S of N("a[data-sec], a[data-route]",e))S.classList.toggle("active",S===m);let w=e.closest(".rail-inner");if(m&&w&&w.scrollHeight>w.clientHeight){let S=m.getBoundingClientRect(),E=w.getBoundingClientRect();(S.top<E.top+40||S.bottom>E.bottom-40)&&(w.scrollTop+=S.top-E.top-E.height/3)}let h=r?.dataset.route??r?.dataset.sec??r?.dataset.tier,p=h&&h!=="overview"&&window.scrollY>0?`#/api-reference/${h}`:"#/api-reference";n&&location.hash!==p&&history.replaceState(history.state,"",p)}function Ya(e){return document.getElementById(e==="overview"?"api-intro":`api-${e}`)}function Za(e){e.id==="api-intro"?window.scrollTo(0,0):e.scrollIntoView({block:"start"}),e.querySelector(":scope > h1, :scope > h2, :scope > .api-res-head h3, :scope > .api-op-head h4, :scope > article > .api-op-head h4")?.focus({preventScroll:!0})}async function ei(e,t,n){oe(t,"API reference"),f(e,Ot("api-reference",o`<div class="toc-label">API</div><nav class="api-nav" id="apiNav" aria-label="API sections"></nav>`,o`<div class="api-content" id="apiContent"><p class="muted">Loading…</p></div>`));let s=c("#apiNav"),i=c("#apiContent"),a=p=>{let S=p.target instanceof Element?p.target.closest("a[data-sec], a[data-route]"):null,E=S?.dataset.route?document.getElementById(`route-${S.dataset.route}`):S?.dataset.sec?Ya(S.dataset.sec):null;!E||p.button!==0||p.metaKey||p.ctrlKey||p.shiftKey||p.altKey||(p.preventDefault(),(E.closest("[hidden]")||S?.closest("#apiEmpty"))&&w(""),history.replaceState(history.state,"",S?.getAttribute("href")??location.hash),Za(E),Yo(s,i,!1))};s.addEventListener("click",a),i.addEventListener("click",a);let r;try{r=await T("/api/reference",{signal:t})}catch(p){ie(i,q(p),()=>ee((S,E)=>ei(S,E,n)));return}let l={meanings:new Map(r.refusals.flatMap(p=>p.codes.map(S=>[S.code,S.meaning]))),objects:new Map(r.objects.map(p=>[p.key,p.title])),heads:xu(r)};f(s,Iu(r,l)),f(i,o`<header class="api-head" id="api-intro"><h1 tabindex="-1">API reference</h1><p class="muted">Every endpoint this instance serves, the one API the web editor and Claude both call. It's read from the running code, so it always matches this version. Base URL <code>${location.origin}</code>.</p><div class="api-filter">${O("search")}<input type="search" id="apiFilter" placeholder="Filter by name, path, URL, or error code" autocomplete="off" aria-label="Filter routes" aria-keyshortcuts="/"><kbd aria-hidden="true">/</kbd><button type="button" class="icon api-filter-clear" id="apiFilterClear" aria-label="Clear filter" hidden>${O("x")}</button></div></header>${Pu(r)}${r.groups.map(p=>Au(p,l))}<p class="api-empty muted" id="apiEmpty" hidden>Nothing matches. Try a path segment like <code>sends</code>, a method like <code>DELETE</code>, or a code like <code>stale_revision</code>, or start from the <a href="#/api-reference" data-sec="overview">Introduction</a>.</p>`);let d=c("#apiFilter"),u=c("#apiFilterClear"),m=()=>Yo(s,i,!1),w=p=>{d.value=p,u.hidden=p==="",za(p,s,i),m()};d.addEventListener("input",()=>w(d.value)),u.addEventListener("click",()=>{w(""),d.focus()}),je(i),document.addEventListener("keydown",p=>{let S=p.target instanceof HTMLElement&&(p.target.isContentEditable||/^(INPUT|TEXTAREA|SELECT)$/.test(p.target.tagName));p.key==="/"&&!S&&!p.metaKey&&!p.ctrlKey&&!p.altKey?(p.preventDefault(),d.focus()):p.key==="Escape"&&p.target===d&&d.value&&w("")},{signal:t}),za("",s,i),window.addEventListener("scroll",()=>Yo(s,i,!0),{passive:!0,signal:t}),window.scrollTo(0,0);let h=n?document.getElementById(`route-${n}`)??Ya(n):null;h&&Za(h),m()}var Bs=q;function Bu(e){let t=[Ze(e,"reschedule")?o`<button class="ghost" data-reschedule="${e.id}">Edit schedule</button>`:null,Ze(e,"cancel")?o`<button class="ghost" data-cancel="${e.id}">Cancel</button>`:null];return t.some(Boolean)?o`<div class="row" data-closes="${e.fire_at}">${t}</div>`:null}async function ti(e,t){oe(t,"Sent");let n={status:"sent",search:"",failures:"",sort:"fire_at",dir:"desc",offset:0,limit:50};f(e,o`<h1>Sent</h1>
|
|
216
|
+
${un()?o`<p class="muted">A local stand-in sends these: they are recorded here, but nothing is delivered.</p>`:null}
|
|
217
|
+
${ls("sent-not-connected",o`No email provider connected, so nothing can be sent yet. ${Ae()} to start sending.`)}
|
|
217
218
|
<div id="stuck"></div>
|
|
218
219
|
<h2>Scheduled</h2><div id="scheduled"><p class="muted">Loading…</p></div>
|
|
219
220
|
<div id="active"></div>
|
|
220
221
|
<h2>Sent posts</h2>
|
|
221
222
|
${jt({searchPlaceholder:"Search subject\u2026",failures:!0})}
|
|
222
223
|
<div id="sendsList"><p class="muted">Loading…</p></div>
|
|
223
|
-
<div id="sendsPager"></div>`);let s=c("#stuck",e),i=c("#scheduled",e),a=c("#active",e),r=c("#sendsList",e),l=c("#sendsPager",e),d=
|
|
224
|
+
<div id="sendsPager"></div>`);let s=c("#stuck",e),i=c("#scheduled",e),a=c("#active",e),r=c("#sendsList",e),l=c("#sendsPager",e),d=Es(e,t),u=[],m=!1,w=0,h=0,p=new Map;function S(){z(),G(),Fe()}function E(b){let k=b.filter(R=>R.status==="sending"&&!gn(R));f(a,k.length?o`<h2>In progress</h2>${k.map(R=>xs(R))}`:o``);for(let R of N("[data-watch]",a))R.onclick=x=>{x.target instanceof Element&&x.target.tagName==="A"||(location.hash=`#/sent/${R.dataset.watch}`)}}function I(b){let k=b.flatMap(j=>{let ae=he(j,"refused");return ae?[{s:j,c:ae}]:[]}),R=ve()?k.filter(j=>j.c.cause==="not_connected"):[],x=k.filter(j=>!R.includes(j)),F=e.querySelector(".sent-not-connected");F&&(F.hidden=R.length>0);let P=R.map(({s:j},ae)=>o`${ae===0?"":ae===R.length-1?" and ":", "}<a href="#/sent/${j.id}">${j.subject}</a>`),B=R.length?o`<div class="card stuck-card sent-held"><div class="stuck-head"><span class="stuck-dot">⚠️</span><div>${as(o`${P}`,R.length)}</div></div></div>`:null,ne=b.flatMap(j=>{let ae=he(j,"wedged");return ae?[{s:j,c:ae}]:[]});f(s,o`${B}${x.map(({s:j,c:ae})=>o`<div class="card stuck-card"><div class="stuck-head"><span class="stuck-dot">⚠️</span><div><strong><a href="#/sent/${j.id}">${j.subject}</a></strong><div class="muted">${ae.message}</div></div></div></div>`)}${ne.map(({s:j,c:ae})=>o`<div class="card stuck-card"><div class="stuck-head"><span class="stuck-dot">⚠️</span><div><strong><a href="#/sent/${j.id}">${j.subject}</a></strong><div class="muted">${ae.message}</div></div></div>${Ze(j,"resolve")?o`<button class="primary" data-resolve="${j.id}">Resolve…</button>`:null}</div>`)}`);for(let j of N("[data-resolve]",s)){let ae=ne.find(lt=>lt.s.id===j.dataset.resolve);ae&&(j.onclick=()=>Cs({id:ae.s.id,c_in_flight:ae.c.count},S,t))}}function C(){for(let b of p.values()){let k=N("tr[data-id]",r).find(R=>R.dataset.id===b.id)?.querySelector("td.delivered");k&&f(k,Ut(b.counts))}}function H(){let b=Dt(u,p);I(b),m&&E(b),C()}let L=b=>b==="scheduled"||b==="due",v=b=>b==="sent"||b==="complete";function y(b){for(let k of b.sends)p.set(k.id,k);for(let k of b.removed)p.delete(k);H(),(b.sends.some(k=>L(nt(k)))||b.changes.some(k=>L(k.from)))&&z(),b.removed.length?(z(),G()):b.changes.some(k=>v(k.to)&&!v(k.from))&&G()}let $=!1;function A(b){let k=b.filter(R=>R!==null);$||!k.length||($=!0,Bt({cursor:k.map(R=>R.cursor).reduce(ps),sends:k.flatMap(R=>R.sends)},{update:y,stale:()=>{t.aborted||ee(ti)}},t))}async function W(){try{let b=await T("/api/sends?status=sending&limit=200",{signal:t});return u=b.sends,m=!0,H(),b}catch(b){return ie(a,Bs(b),async()=>A([await W()])),null}}async function z(){let b=++w;try{let k=await T("/api/sends?status=scheduled&sort=fire_at&dir=asc&limit=200",{signal:t});if(b!==w)return k;let{sends:R}=k,x=B=>o`<div class="card spread clickable sched-card" data-post="${B.post_id}"><div><a class="card-link sched-subj" href="#/edit/${B.post_id}">${B.subject}</a><div class="muted">${$s(B)} · ${K(B.fire_at)} · ${B.audience.count} recipients${Ss(B)}</div></div>${Bu(B)}</div>`,[F,...P]=R;if(!F)f(i,o`<p class="muted">Nothing scheduled.</p>`);else{f(i,o`${x(F)}${P.length?o`<div id="schedMore" hidden>${P.map(x)}</div><button type="button" class="ghost sched-toggle" id="schedToggle" aria-expanded="false">Show all ${R.length} scheduled</button>`:null}`);let B=i.querySelector("#schedToggle");B&&(B.onclick=()=>{let ne=c("#schedMore",i),j=ne.hidden;ne.hidden=!j,B.setAttribute("aria-expanded",String(j)),B.textContent=j?"Show fewer":`Show all ${R.length} scheduled`})}for(let B of N(".card.clickable",i))B.onclick=ne=>{let j=ne.target;j instanceof Element&&j.tagName!=="A"&&!j.closest("button")&&(location.hash=`#/edit/${B.dataset.post}`)};for(let B of N("[data-reschedule]",i)){let ne=R.find(j=>j.id===B.dataset.reschedule);ne&&(B.onclick=()=>{As(ne,S,t)})}for(let B of N("[data-cancel]",i))B.onclick=()=>Y(B,"Canceling\u2026",async()=>{try{await T(`/api/sends/${B.dataset.cancel}/cancel`,{method:"POST"}),U("Canceled"),S()}catch(ne){U(Bs(ne))}});return d(),k}catch(k){return b===w&&ie(i,Bs(k),async()=>A([await z()])),null}}async function G(){let b=++h;try{let k=await T(`/api/sends?${qt(n)}`,{signal:t});if(b!==h)return k;let R=k.sends;if(!R.length)return f(r,o`<p class="muted">${n.search?"No sent posts match.":n.failures?"Every sent post delivered cleanly.":"No sent posts yet."}</p>`),f(l,o``),k;f(r,o`<div class="table-wrap"><table class="list-table sent-table stacks"><colgroup><col><col class="c-date"><col class="c-num"><col class="c-delivered"></colgroup><thead><tr>${$e("Subject","subject",n)}${$e("When","fire_at",n)}${$e("Recipients","audience.count",n,"num")}<th class="num">Delivered</th></tr></thead><tbody>${R.map(x=>o`<tr class="clickable" data-id="${x.id}"><td class="subject">${wt(o`<a href="#/sent/${x.id}">${x.subject}</a>`,x)}</td><td class="muted">${K(x.completed_at??x.fire_at)}</td><td class="num recipients"><span class="n">${x.audience.count.toLocaleString()}</span></td><td class="num delivered">${Ut(x.counts)}</td></tr>`)}</tbody></table></div>`),st(r,n,G);for(let x of N("tr[data-id]",r))x.onclick=F=>{F.target instanceof Element&&F.target.tagName==="A"||(location.hash=`#/sent/${x.dataset.id}`)};return ot(l,n,k.page,G),C(),k}catch(k){return b===h&&ie(r,Bs(k),async()=>A([await G()])),null}}Wt(e,n,G),A(await Promise.all([z(),W(),G()]))}var Du="erased:";function Qa(e){return e.startsWith(Du)}function kt(e,t,n){let s=URL.createObjectURL(new Blob([e],{type:n})),i=document.createElement("a");i.href=s,i.download=t,i.click(),setTimeout(()=>URL.revokeObjectURL(s),1e4)}function Ds(e){if(e.event==="delivered")return{label:"Delivered",sw:"ok"};if(e.event==="bounced")return e.bounce_kind==="hard"?{label:"Hard bounce",sw:"warn"}:e.bounce_kind==="soft"?{label:"Soft bounce",sw:"warn"}:{label:"Bounce",sw:"warn"};if(e.event==="complained")return{label:"Complained",sw:"danger"};switch(e.status){case"unsent":return{label:"Unsent",sw:"neutral"};case"skipped":return{label:"Skipped",sw:"neutral"};case"accepted":return{label:"Accepted",sw:"sending"};default:return{label:"In flight",sw:"sending"}}}var Ln=q;async function ni(e,t,n){let s=()=>{n.aborted||ee((r,l)=>ni(e,r,l))};oe(n,"Sent"),f(t,o`<p class="muted">Loading…</p>`);let i;try{i=await T(`/api/sends/${e}`,{signal:n})}catch(r){ie(t,Ln(r),s);return}if(n.aborted)return;let{send:a}=i;if(oe(n,a.subject||"Untitled"),a.status==="scheduled"){location.replace(`#/edit/${a.post_id}`);return}return a.status==="sending"?Gu(i,t,n,s):Xu(e,i,t,n,s)}var Uu={scheduled:{label:"Scheduled",tone:"scheduled"},due:{label:"Due",tone:"scheduled"},progressing:{label:"Sending",tone:"sending"},retrying:{label:"Retrying",tone:"warn"},backing_off:{label:"Backing off",tone:"warn"},needs_attention:{label:"Needs attention",tone:"danger"},settling:{label:"Settling",tone:"sending"},complete:{label:"Complete",tone:"ok"},canceled:{label:"Canceled",tone:"muted"}},Fu={progressing:"Handing recipients to the provider.",retrying:"Some recipients hit a transient error and will be retried.",backing_off:"Some recipients hit a transient error. They\u2019re retried on the next sweep.",needs_attention:"Some deliveries can\u2019t be confirmed either way, and wait on your decision.",settling:"Dispatch complete, waiting on delivery receipts."};function qu(e){let t=e.provider.halt;return t&&al(e)?`${t.cause==="not_connected"?"No email provider is connected":t.reason==="account"?"The provider is refusing this account":"The provider is unavailable"}, so this post waits with the send already held and hasn\u2019t handed anyone off; ${Ft(t.retry_at)}.`:Le(e,"refused")&&t?.cause==="not_connected"?`No email provider is connected, so nothing goes out until one is; ${Ft(t.retry_at)}.`:Le(e,"refused")&&t?`The provider is refusing ${go(t.cause)?"this send":"this account"}, so nothing more goes out until it\u2019s fixed; ${Ft(t.retry_at)}.`:e.phase==="backing_off"&&t?.reason==="unavailable"?`The provider is unavailable; ${Ft(t.retry_at)}.`:Le(e,"stuck")?"Nothing is being handed off to the provider right now.":e.phase==="progressing"&&e.counts.dispatched===0&&e.counts.pending>0?"Paused between ticks. It resumes on the next sweep.":Fu[e.phase]||""}function Rn(e){let t=Uu[e]??{label:e,tone:"muted"};return o`<span class="phase-pill tone-${t.tone}">${t.label}</span>`}function ju(e,t,n,s,i){let a=s>0?bn(100*n/s):0;return o`<div class="wbar-row">
|
|
224
225
|
<div class="wbar-head"><span class="wbar-label">${t}</span><span class="wbar-count">${n.toLocaleString()} / ${s.toLocaleString()}</span></div>
|
|
225
226
|
<div class="wbar" role="progressbar" aria-valuenow="${a}" aria-valuemin="0" aria-valuemax="100"><div class="wbar-fill tone-${e}" style="width:${a}%"></div></div>
|
|
226
227
|
${i?o`<div class="wbar-sub muted">${i}</div>`:null}
|
|
227
|
-
</div>`}function
|
|
228
|
+
</div>`}function Wu(e,t,n,s,i){let a=s>0?bn(100*n/s):0,r=s>0?bn(100*t/s):0;return o`<div class="wbar-row">
|
|
228
229
|
<div class="wbar-head"><span class="wbar-label">${e}</span><span class="wbar-count">${t.toLocaleString()} of ${n.toLocaleString()} accepted</span></div>
|
|
229
230
|
<div class="wbar dual" role="progressbar" aria-valuenow="${r}" aria-valuemin="0" aria-valuemax="100">
|
|
230
231
|
<div class="wbar-fill tone-accepted" style="width:${a}%"></div>
|
|
231
232
|
<div class="wbar-fill tone-ok" style="width:${r}%"></div>
|
|
232
233
|
</div>
|
|
233
234
|
<div class="wbar-sub muted">${i}</div>
|
|
234
|
-
</div>`}var
|
|
235
|
-
${
|
|
235
|
+
</div>`}var Vu=[{key:"pending",label:"Pending",sw:"neutral"},{key:"dispatched",label:"In flight",sw:"sending"},{key:"accepted",label:"Accepted",sw:"sending"},{key:"delivered",label:"Delivered",sw:"ok"},{key:"bounced",label:"Bounced",sw:"warn"},{key:"complained",label:"Complained",sw:"danger"},{key:"unsent",label:"Unsent",sw:"neutral"},{key:"skipped",label:"Skipped",sw:"neutral"}];function Ku(e){return o`<div class="wcounts">${Vu.map(t=>o`<div class="wcount"><div class="wcount-n">${(e[t.key]||0).toLocaleString()}</div><div class="wcount-l"><span class="rec-sw sw-${t.sw}"></span>${t.label}</div></div>`)}</div>`}function rl(e){let t=e.counts,n=t.accepted+t.delivered+t.bounced+t.complained,s=e.dispatch.rate_per_min,i=e.dispatch.eta_ms,a=e.status==="sending"?`${qu(e)}${i?`${s?` \xB7 ~${s.toLocaleString()}/min`:""} \xB7 ETA ${ws(i)}`:""}`:"Dispatch complete.",r=(t.unsent||0)+(t.bounced||0)+(t.complained||0),l=un()?"Local stand-in: nothing is delivered":ve()?"No email provider connected":`Provider: ${e.provider?.name||"unknown"}`,d=he(e,"refused"),u=d?.cause==="not_connected",m=go(d?.cause??null),w=he(e,"stuck"),h=he(e,"provider_unavailable"),p=h?.severity==="warn"?h:void 0;return o`
|
|
236
|
+
${w?o`<div class="health amber" role="status"><span class="health-dot">⚠️</span><div>${w.message}</div></div>`:null}
|
|
236
237
|
${p?o`<div class="health amber" role="status"><span class="health-dot">⚠️</span><div>${p.message}</div></div>`:null}
|
|
237
|
-
${d?o`<div class="health red" role="alert"><span class="health-dot">⚠️</span><div><strong>${u?"No email provider is connected":
|
|
238
|
+
${d?o`<div class="health red" role="alert"><span class="health-dot">⚠️</span><div><strong>${u?"No email provider is connected":m?"The provider is refusing this send":"The provider is refusing this account"}</strong>${u?null:o`<div>${d.error}</div>`}<div class="refused-advice">${u?wo():d.advice}</div><div>${d.since===null?null:`Since ${K(d.since)}. `}No one has been marked unsent because of this, and once ${u?"one is connected":"this is fixed"} the send resumes at its next retry${d.retry_at===null?"":`, ${K(d.retry_at)}`}.</div></div></div>`:null}
|
|
238
239
|
<div class="wbars">
|
|
239
|
-
${
|
|
240
|
-
${
|
|
240
|
+
${ju("sending","Dispatch: provider-accepted",n,e.audience.count,a)}
|
|
241
|
+
${Wu("Delivery: webhook-confirmed",e.delivery.confirmed,n,e.audience.count,"Delivery lags acceptance: grey is accepted but unconfirmed, and green fills in as receipts arrive.")}
|
|
241
242
|
</div>
|
|
242
|
-
${
|
|
243
|
-
<div class="whealth${r?" has-failures":""}"><span class="whealth-dot"></span><span>${l} · ${r?`${r.toLocaleString()} bounced / unsent / complained`:"no delivery failures"}</span></div>`}function
|
|
243
|
+
${Ku(t)}
|
|
244
|
+
<div class="whealth${r?" has-failures":""}"><span class="whealth-dot"></span><span>${l} · ${r?`${r.toLocaleString()} bounced / unsent / complained`:"no delivery failures"}</span></div>`}function al(e){return e.status==="sending"&&e.provider.halt!==null&&!e.audience.fixed}function Us(e){let t=Ca(e);return t===null?null:o`<div class="rec-meta rec-by">${t}</div>`}function ll(e){if(al(e))return o`Due ${K(e.fire_at)} · held before handing anyone off · about ${e.audience.count.toLocaleString()} recipients`;let t=e.started_at?`Started ${K(e.started_at)}`:"Sending now";return o`${t} · ${e.audience.count.toLocaleString()} recipients`}function Xa(e){let t=e;return o`
|
|
244
245
|
<div class="editor-head">
|
|
245
246
|
<a href="#/sent" class="back">← Sent</a>
|
|
246
247
|
${Ze(t,"resolve")?o`<button type="button" class="primary" id="resolveBtn">Resolve…</button>`:null}
|
|
247
248
|
</div>
|
|
248
249
|
<div class="card rec-card watch-card">
|
|
249
250
|
<div class="rec-head">
|
|
250
|
-
<div class="watch-title"><h1>${e.subject||o`<em>untitled</em>`}</h1><span id="watchPill">${
|
|
251
|
-
<div class="rec-meta" id="watchMeta">${
|
|
252
|
-
<div id="watchBy">${
|
|
251
|
+
<div class="watch-title"><h1>${e.subject||o`<em>untitled</em>`}</h1><span id="watchPill">${Rn(t.phase)}</span></div>
|
|
252
|
+
<div class="rec-meta" id="watchMeta">${ll(e)}</div>
|
|
253
|
+
<div id="watchBy">${Us(e)}</div>
|
|
253
254
|
</div>
|
|
254
|
-
<div id="watchBody">${
|
|
255
|
+
<div id="watchBody">${rl(t)}</div>
|
|
255
256
|
<p class="rec-note muted">This view updates live while the send is in flight. Delivery receipts keep arriving after dispatch finishes, and the record stays accurate as they settle.</p>
|
|
256
|
-
</div>`}function
|
|
257
|
+
</div>`}function el(e,t,n,s){let i=e.querySelector("#resolveBtn");if(i){let a=he(t,"wedged")?.count??t.counts.dispatched;i.onclick=()=>Cs({id:t.id,c_in_flight:a},n,s)}}function tl(e,t){let n=e.querySelector("#watchPill");n&&f(n,Rn(t.phase));let s=e.querySelector("#watchMeta");s&&f(s,ll(t));let i=e.querySelector("#watchBy");i&&f(i,o`${Us(t)}`);let a=e.querySelector("#watchBody");a&&f(a,rl(t))}function Gu(e,t,n,s){f(t,Xa(e.send)),el(t,e.send,s,n);let i=e.send;mt(1e3,()=>tl(t,i),n),fn(e,{update:a=>{if(a.status!=="sending"){s();return}i=a,Ze(a,"resolve")!==!!t.querySelector("#resolveBtn")?(f(t,Xa(a)),el(t,a,s,n)):tl(t,a)},removed:s,stale:s},n)}function nl(e){let t=[{n:e.recipients,label:"Recipients",cls:"",sw:"neutral"},{n:e.delivered,label:"Delivered",cls:"ok",sw:"ok"},{n:e.bounced,label:"Bounced",cls:"warn",sw:"warn"},{n:e.complained,label:"Complained",cls:"danger",sw:"danger"},{n:e.unsent,label:"Unsent",cls:"",sw:"neutral"}];return o`${t.map(n=>o`<div class="rec-tile"><div class="rec-n ${n.cls}">${n.n.toLocaleString()}</div><div class="rec-l"><span class="rec-sw sw-${n.sw}"></span>${n.label}</div></div>`)}`}function sl(e){let t=e.recipients,n=[`${e.delivered.toLocaleString()} delivered`];e.bounced&&n.push(`${e.bounced.toLocaleString()} bounced`),e.complained&&n.push(`${e.complained.toLocaleString()} complained`),e.unsent&&n.push(`${e.unsent.toLocaleString()} unsent`),e.accepted&&n.push(`${e.accepted.toLocaleString()} accepted, awaiting a delivery receipt`),e.skipped&&n.push(`${e.skipped.toLocaleString()} skipped (unsubscribed or suppressed before hand-off, never mailed)`),e.pending&&n.push(`${e.pending.toLocaleString()} pending`),e.dispatched&&n.push(`${e.dispatched.toLocaleString()} in flight`);let s=`All ${t.toLocaleString()} accounted for: ${n.join(", ")}.`,i=e.bounced||e.complained?" Hard bounces are suppressed automatically and spam complaints unsubscribe the reader, so those addresses won\u2019t be mailed again.":"",a=e.bounced?" A soft bounce is temporary, so it\u2019s counted and the address stays on the list.":"";return`${s}${i}${a}`}function zu(e,t){return Object.keys(e).every(n=>e[n]===t[n])}var Yu=[{v:"all",label:"All"},{v:"delivered",label:"Delivered"},{v:"failures",label:"Failures"}];function Zu(e){return e.search?"No recipients match that address.":e.view==="failures"?"No delivery failures. Every recipient was accepted or delivered.":e.view==="delivered"?"No delivery receipts confirmed yet.":"No recipients on this send."}function Ju(e){let t=new URLSearchParams;t.set("view",e.view);let n=(e.search||"").trim();return n&&t.set("search",n),e.sort&&(t.set("sort",e.sort),t.set("dir",e.dir??"asc")),t.set("limit",String(e.limit)),t.set("offset",String(e.offset)),t.toString()}function Qu(e,t){let n=e.map(s=>{let i=Ds(s),a=o`<span class="rec-out"><span class="rec-sw sw-${i.sw}"></span>${i.label}</span>`,r=s.error||s.event_detail||"",l=s.event_at?K(s.event_at):"",d=Qa(s.email)?o`<span class="muted">Erased recipient</span>`:s.email;return o`<tr><td class="rec-email">${d}</td><td>${a}</td><td class="muted">${r||"\u2014"}</td><td class="muted">${l||"\u2014"}</td></tr>`});return o`<div class="table-wrap"><table class="list-table rec-people-table"><colgroup><col><col class="c-out"><col><col class="c-date"></colgroup><thead><tr>${$e("Recipient","email",t)}<th class="c-out">Outcome</th><th>Detail</th><th class="c-date">When</th></tr></thead><tbody>${n}</tbody></table></div>`}function Xu(e,t,n,s,i){let{send:a,outcomes:r}=t;if(a.status==="canceled"){tp(a,n);return}let l=r.recipients,d=a.completed_at??a.fire_at;f(n,o`
|
|
257
258
|
<div class="editor-head">
|
|
258
259
|
<a href="#/sent" class="back">← Sent</a>
|
|
259
260
|
</div>
|
|
260
261
|
<div class="rec-head rec-head-page">
|
|
261
|
-
<div class="watch-title"><h1>${a.subject||o`<em>untitled</em>`}</h1><span id="recPill">${
|
|
262
|
-
<div class="rec-meta">Sent ${
|
|
263
|
-
${
|
|
262
|
+
<div class="watch-title"><h1>${a.subject||o`<em>untitled</em>`}</h1><span id="recPill">${Rn(a.phase)}</span></div>
|
|
263
|
+
<div class="rec-meta">Sent ${K(d)} · ${l.toLocaleString()} recipients</div>
|
|
264
|
+
${Us(a)}
|
|
264
265
|
</div>
|
|
265
266
|
<section class="card rec-post" aria-labelledby="recPostTitle">
|
|
266
267
|
<h2 class="rec-part-title" id="recPostTitle">The post</h2>
|
|
267
|
-
<div class="rec-web" id="recWeb">${
|
|
268
|
+
<div class="rec-web" id="recWeb">${ol(a)}</div>
|
|
268
269
|
</section>
|
|
269
270
|
<section class="card rec-card" aria-labelledby="recDeliveryTitle">
|
|
270
271
|
<h2 class="rec-part-title" id="recDeliveryTitle">Delivery</h2>
|
|
271
|
-
<div id="recAlert">${
|
|
272
|
+
<div id="recAlert">${il(a)}</div>
|
|
272
273
|
<p class="rec-tiles-cap muted">Delivery outcomes keep updating as receipts arrive; the audience at fire and the published post are fixed.</p>
|
|
273
|
-
<div class="rec-tiles">${
|
|
274
|
-
<p class="rec-recon muted">${
|
|
274
|
+
<div class="rec-tiles">${nl(r)}</div>
|
|
275
|
+
<p class="rec-recon muted">${sl(r)}</p>
|
|
275
276
|
<div class="rec-actions">
|
|
276
277
|
<button type="button" class="ghost" id="csvBtn">Export recipients (CSV)</button>
|
|
277
278
|
</div>
|
|
@@ -279,7 +280,7 @@
|
|
|
279
280
|
<div class="rec-people-head">
|
|
280
281
|
<h3 class="rec-people-title">Recipients</h3>
|
|
281
282
|
<div class="rec-views" role="group" aria-label="Which recipients to show">
|
|
282
|
-
${
|
|
283
|
+
${Yu.map((b,k)=>o`<button type="button" class="rec-view-btn" data-view="${b.v}" aria-pressed="${k===0?"true":"false"}">${b.label}</button>`)}
|
|
283
284
|
</div>
|
|
284
285
|
</div>
|
|
285
286
|
<input class="rec-people-search" type="search" placeholder="Search email…" aria-label="Search recipients by email" autocomplete="off">
|
|
@@ -287,38 +288,38 @@
|
|
|
287
288
|
<div id="recPager"></div>
|
|
288
289
|
</div>
|
|
289
290
|
<p class="rec-note muted">This is the record of what went out: the published post is the exact frozen copy readers received, and nothing here is editable.</p>
|
|
290
|
-
</section>`);let u=c("#recWeb",n),
|
|
291
|
-
${
|
|
292
|
-
${
|
|
291
|
+
</section>`);let u=c("#recWeb",n),m=a,w=()=>{f(u,ol(m));let b=u.querySelector("#recOpen"),k=u.querySelector("#recCopy"),R=u.querySelector("#recListing"),x=cl(m);b&&x&&(b.onclick=()=>window.open(x,"_blank","noopener")),k&&x&&(k.onclick=()=>{$n(k,x)}),R&&(R.onclick=()=>m.email_only?S():p())},h=(b,k,R)=>Y(b,k.email_only?"Updating\u2026":"Adding\u2026",async()=>{R.clearError();try{let x=await T(`/api/posts/${a.post_id}/settings`,{method:"PUT",json:k});R.close();let F=x.post.archive_live?x.post.archive_url:null;m={...m,email_only:x.post.email_only,links:{...m.links,archive:F}},w(),U(x.post.email_only?"Removed from your archive":`Added to your archive at ${F?En(F):x.post.slug}`),Fe()}catch(x){R.error(Ln(x))}}),p=()=>{let b=m.links.archive,k=m.web_link==="archive",R=me(o`<h3 id="eoHead">Remove this post from your archive?</h3>
|
|
292
|
+
${k?o`<p class="hint">It comes off your home page and your public archive. Its emails link to its archive address, so that address keeps working for anyone who has them, and isn’t listed or indexed.</p>`:o`<p class="hint">It comes off your home page and your public archive, and its archive address stops working, including links people have shared. The link in the email keeps working for anyone who has it.</p>
|
|
293
|
+
${b?o`<div class="url-gone"><s>${En(b)}</s></div>`:null}
|
|
293
294
|
<p class="pub-note">The address stays this post’s. Add it back and the same address, and the links people shared, work again.</p>`}
|
|
294
|
-
<div class="actions"><button type="button" id="eoCancel">Cancel</button><button type="button" class="primary" id="eoGo">Remove from archive</button></div>`,s);c(".modal",
|
|
295
|
+
<div class="actions"><button type="button" id="eoCancel">Cancel</button><button type="button" class="primary" id="eoGo">Remove from archive</button></div>`,s);c(".modal",R.el).setAttribute("aria-labelledby","eoHead"),c("#eoCancel",R.el).onclick=R.close;let x=c("#eoGo",R.el);x.onclick=()=>h(x,{email_only:!0},R),x.focus()},S=async()=>{let b;try{b=await T(`/api/posts/${a.post_id}`,{signal:s})}catch(P){s.aborted||U(Ln(P));return}let R={...Qe(b.post,b.subject_slug_held),emailOnly:!1},x=me(o`<h3 id="addArchHead">Add this post to your archive?</h3>
|
|
295
296
|
<p class="hint">It will be listed on your home page and in your public archive, where anyone visiting can find it. The link in the email keeps working, and forwards to it.</p>
|
|
296
297
|
<div class="dialog-settings" id="addForm"></div>
|
|
297
|
-
<div class="actions"><button type="button" id="addArchCancel">Cancel</button><button type="button" class="primary" id="addArchGo">Add to archive</button></div>`,s);c(".modal"
|
|
298
|
+
<div class="actions"><button type="button" id="addArchCancel">Cancel</button><button type="button" class="primary" id="addArchGo">Add to archive</button></div>`,s);c(".modal",x.el).setAttribute("aria-labelledby","addArchHead"),c("#addArchCancel",x.el).onclick=x.close,$t(c("#addForm",x.el),R,"add",{include:!1,fixedNote:"Its address since it was sent: links people shared work again."});let F=c("#addArchGo",x.el);F.onclick=()=>h(F,{email_only:!1},x),F.focus()};w();let E={view:"all",search:"",sort:"email",dir:"asc",offset:0,limit:50},I=c("#recRows",n),C=c("#recPager",n),H=0,L=!1,v=async b=>{let k=++H;b||(L=!0);try{let R=await T(`/api/sends/${e}/deliveries?${Ju(E)}`,{signal:s});if(k!==H)return;let x=R.page.total>0?Math.floor((R.page.total-1)/R.page.limit)*R.page.limit:0;if(!R.deliveries.length&&E.offset>x)return E.offset=x,v(b);L=!1,$(()=>{if(!R.deliveries.length){f(I,o`<p class="rec-people-empty muted">${Zu(E)}</p>`),f(C,o``);return}f(I,Qu(R.deliveries,E)),st(I,E,y),ot(C,E,R.page,y)})}catch(R){k===H&&(!b||L)&&(L=!1,ie(I,Ln(R),y))}},y=()=>v(!1),$=b=>{let k=document.activeElement,R=k instanceof HTMLElement&&(I.contains(k)||C.contains(k)),x=R?k.dataset.sort:void 0,F=R?["pager-prev","pager-next"].find(B=>k.classList.contains(B)):void 0;b();let P=x?I.querySelector(`.th-sort[data-sort="${x}"]`):F?C.querySelector(`.${F}`):null;P&&!P.disabled&&P.focus()},A=N(".rec-view-btn",n);for(let b of A)b.onclick=()=>{let k=b.dataset.view;(k==="failures"||k==="delivered"||k==="all")&&(E.view=k),E.offset=0;for(let R of A)R.setAttribute("aria-pressed",String(R===b));y()};let W=n.querySelector(".rec-people-search");if(W){let b;W.oninput=()=>{clearTimeout(b),b=setTimeout(()=>{E.search=W.value,E.offset=0,y()},250)}}y();let z=c("#csvBtn");z.onclick=()=>Y(z,"Exporting\u2026",async()=>{try{let b=await es(a.links.deliveries_csv);kt(b.text,b.filename??"deliveries.csv","text/csv")}catch(b){U(b instanceof te&&b.status===404?"This send no longer exists, so there are no deliveries to export.":Ln(b))}});let G=r;fn(t,{update(b){if(b.status==="sending"){i();return}f(c("#recPill",n),Rn(b.phase)),f(c("#recAlert",n),il(b)),(b.email_only!==m.email_only||b.links.archive!==m.links.archive||b.links.unlisted!==m.links.unlisted)&&(m=b,w());let k=ep(b);zu(G,k)||(G=k,f(c(".rec-tiles",n),nl(k)),c(".rec-recon",n).textContent=sl(k),v(!0))},removed:i,stale:i},s)}function cl(e){return e.email_only&&e.web_link==="unlisted"?e.links.unlisted:e.links.archive??e.links.unlisted}function ol(e){let t=cl(e),n=t?En(t):null,s=e.web_link==="archive",i=e.email_only?s?"Its emails link here. Anyone with the link can open it; nothing lists or indexes it.":"Anyone with the link can open it. Nothing lists or indexes it.":s?"Its emails link here.":"The link in the email forwards here.",a=t&&n?o`<p class="rec-link-label">Link</p><div class="rec-link"><code title="${n}">${n}</code><button type="button" class="copy-btn" id="recCopy" data-copy-word="Copy" aria-label="Copy link">${Te(!1,"Copy")}</button><button type="button" class="rec-open" id="recOpen">Open ↗</button></div><p class="rec-link-note muted">${i}</p>`:null,r=e.email_only?o`<div class="rec-arch-what"><strong>${O("mail")}Email only</strong><span class="rec-arch-note">Not on your home page or in your public archive.</span></div><button type="button" class="secondary" id="recListing">Add to archive…</button>`:o`<div class="rec-arch-what"><strong>${O("link")}In your archive</strong><span class="rec-arch-note">Listed on your home page and in your public archive.</span></div><button type="button" class="secondary" id="recListing">Remove from archive…</button>`;return o`${a}<div class="rec-arch">${r}</div>`}function il(e){let t=he(e,"no_receipts");return t?o`<div class="health amber" role="status"><span class="health-dot">⚠️</span><div>${t.message}</div></div>`:o``}function ep(e){let t=e.counts;return{recipients:e.audience.count,delivered:t.delivered,bounced:t.bounced,complained:t.complained,unsent:t.unsent,skipped:t.skipped,accepted:t.accepted,pending:t.pending,dispatched:t.dispatched}}function tp(e,t){f(t,o`
|
|
298
299
|
<div class="editor-head">
|
|
299
300
|
<a href="#/sent" class="back">← Sent</a>
|
|
300
301
|
</div>
|
|
301
302
|
<div class="card rec-card">
|
|
302
303
|
<div class="rec-head">
|
|
303
|
-
<div class="watch-title"><h1>${e.subject||o`<em>untitled</em>`}</h1><span id="recPill">${
|
|
304
|
-
<div class="rec-meta">Canceled ${
|
|
305
|
-
${
|
|
304
|
+
<div class="watch-title"><h1>${e.subject||o`<em>untitled</em>`}</h1><span id="recPill">${Rn(e.phase)}</span></div>
|
|
305
|
+
<div class="rec-meta">Canceled ${K(e.completed_at)} · was scheduled for ${K(e.fire_at)}</div>
|
|
306
|
+
${Us(e)}
|
|
306
307
|
</div>
|
|
307
308
|
<p class="rec-note muted">This send was canceled before it fired, so no one was mailed.</p>
|
|
308
|
-
</div>`)}function
|
|
309
|
+
</div>`)}function si(e){let t=document.getElementById(e);if(!t)throw new Error(`the admin page has no #${e}`);return t}var Fs=(()=>{let e=si("savebar"),t=e.querySelector(".savebar-msg"),n=si("savebarSave"),s=si("savebarDiscard"),i=0,a=u=>{t&&f(t,o`<span class="savebar-dot"></span><span>${u}</span>`)},r=()=>{e.hidden=!1,e.offsetHeight,e.classList.add("show")};function l(){i++,e.classList.remove("show","is-error"),e.hidden=!0,n.onclick=null,s.onclick=null,document.body.classList.remove("has-savebar")}function d({onSave:u,onDiscard:m,saveLabel:w="Save changes",discardLabel:h="Discard"},p){if(p.aborted)return{setDirty(){},showError(){}};let S=++i;p.addEventListener("abort",()=>{i===S&&l()},{once:!0}),n.textContent=w,s.textContent=h,e.classList.remove("show","is-error"),a("You have unsaved changes."),e.hidden=!0,document.body.classList.add("has-savebar"),n.onclick=()=>Y(n,"Saving\u2026",()=>Promise.resolve(u())),s.onclick=()=>m();let E=()=>i===S;return{setDirty(I){E()&&(e.classList.remove("is-error"),I?(a("You have unsaved changes."),r()):e.classList.remove("show"))},showError(I){E()&&(e.classList.add("is-error"),a(I),r())}}}return{attach:d}})();var at=q,Cn=o` hidden`;function ye(e,t){return o`<span class="set-chip ${e}">${O(e)}${t}</span>`}function we(e,t,n=null){return o`<div class="set-sec-head"><h2 class="set-sec-title">${e}</h2>${t}${n}<span class="set-rule"></span></div>`}function An(e,t){return(String(e||t).trim()[0]||"K").toUpperCase()}function dl(e){let{state:t,fromName:n}=e;return o`
|
|
309
310
|
<section class="set-sec">
|
|
310
311
|
${we("Confirmation email",ye("editable","Editable"))}
|
|
311
312
|
<p class="set-lede">The email that asks a new subscriber to confirm. Edit the wording as you see fit. Kestrel adds the confirmation link.</p>
|
|
312
313
|
<div class="set-preview">
|
|
313
314
|
<div class="set-preview-bar set-ce-bar">
|
|
314
315
|
<div class="set-ce-modetog" role="group" aria-label="Confirmation email view">
|
|
315
|
-
<button type="button" class="set-ce-modebtn" id="ceTabPreview" aria-pressed="true">${
|
|
316
|
-
<button type="button" class="set-ce-modebtn" id="ceTabEdit" aria-pressed="false">${
|
|
316
|
+
<button type="button" class="set-ce-modebtn" id="ceTabPreview" aria-pressed="true">${O("preview")}Preview</button>
|
|
317
|
+
<button type="button" class="set-ce-modebtn" id="ceTabEdit" aria-pressed="false">${O("editable")}Edit</button>
|
|
317
318
|
</div>
|
|
318
319
|
</div>
|
|
319
320
|
<div id="cePreviewBody">
|
|
320
321
|
<div class="set-inbox">
|
|
321
|
-
<div class="set-inbox-avatar" id="cePvAvatar">${
|
|
322
|
+
<div class="set-inbox-avatar" id="cePvAvatar">${An(t.name,n)}</div>
|
|
322
323
|
<div class="set-inbox-body">
|
|
323
324
|
<div class="set-inbox-top"><span class="set-inbox-from" id="cePvFrom">${t.name||n}</span><span class="set-inbox-time">now</span></div>
|
|
324
325
|
<div class="set-inbox-subj" id="cePvSubject"></div>
|
|
@@ -367,69 +368,70 @@
|
|
|
367
368
|
</div>
|
|
368
369
|
</div>
|
|
369
370
|
</div>
|
|
370
|
-
</section>`}function
|
|
371
|
+
</section>`}function ul(e,t){let{state:n}=t,s=t.data.settings.confirmation_email_default,i={subject:c("#ceSubject",e),message:c("#ceMessage",e),button:c("#ceButton",e),footer:c("#ceFooter",e)},a={avatar:c("#cePvAvatar",e),from:c("#cePvFrom",e),subject:c("#cePvSubject",e),body:c("#cePvBody",e),button:c("#cePvButton",e),foot:c("#cePvFoot",e),mast:c("#cePvMast",e),mastLogo:c("#cePvMastLogo",e),mastName:c("#cePvMastName",e),mastTag:c("#cePvMastTag",e)},r=()=>{let p=n.confirmation;a.avatar.textContent=An(n.name,t.fromName),a.from.textContent=n.name||t.fromName,a.subject.textContent=p.subject.trim()||s.subject||"",a.body.textContent=p.body.trim()||s.body||"",a.button.textContent=p.button_label.trim()||s.button_label||"Confirm",a.foot.textContent=p.reassurance,a.foot.hidden=!p.reassurance.trim();let S=n.name||t.fromDisplay,E=!!n.logoUrl,I=E||!!S;a.mast.hidden=!I,I&&(a.mastLogo.hidden=!E,E&&f(a.mastLogo,o`<img src="${n.logoUrl}" alt="">`),a.mastName.textContent=S,a.mastName.hidden=!S,a.mastTag.textContent=n.tagline,a.mastTag.hidden=!n.tagline)},l=()=>{n.confirmation.subject=i.subject.value,n.confirmation.body=i.message.value,n.confirmation.button_label=i.button.value,n.confirmation.reassurance=i.footer.value,t.changed()};for(let p of Object.values(i))p.addEventListener("input",l);let d=c("#ceEditBody",e),u=c("#cePreviewBody",e),m=c("#ceTabEdit",e),w=c("#ceTabPreview",e),h=p=>{d.hidden=!p,u.hidden=p,m.setAttribute("aria-pressed",String(p)),w.setAttribute("aria-pressed",String(!p)),p&&i.subject.focus()};return w.onclick=()=>h(!1),m.onclick=()=>h(!0),c("#ceToPreview",e).onclick=()=>h(!1),c("#ceReset",e).onclick=()=>{i.subject.value=s.subject||"",i.message.value=s.body||"",i.button.value=s.button_label||"",i.footer.value=s.reassurance||"",l()},r(),{repaint:r,reset(){i.subject.value=n.confirmation.subject,i.message.value=n.confirmation.body,i.button.value=n.confirmation.button_label,i.footer.value=n.confirmation.reassurance,r()}}}var np={none:"No email provider connected",fake:"Fake (dev, dead-end)",ses:"Amazon SES"};function qs(e){return np[e]||e}function sp(e,t){if(e.provider==="none")return o`${qs(e.provider)}. ${Ae("set-link")} to start sending.`;let n=e.simulation?o`<span class="set-pill">Simulating ${op[e.simulation.profile]}${e.simulation.faults==="none"?", no failures":""}</span>`:null;return t?zr(t,n?o` ${n}`:null):o`${qs(e.provider)}${n}`}var op={generic:"a generic provider",ses:"Amazon SES"},ip="#/docs/ses/8-receive-replies-at-your-from-address";function rp(e){let t=String(e||"").match(/<([^>]+)>/);return t?.[1]?t[1]:String(e||"")}function pl(e){let t=e.data.deployment,{fromName:n}=e,s=e.provider,i=s?Yr(s):null;return o`
|
|
371
372
|
<section class="set-sec">
|
|
372
373
|
${we("Email sender",ye("readonly","Read-only \xB7 set at deploy"))}
|
|
373
374
|
<div class="set-card sunken">
|
|
374
|
-
<div class="set-ro-note">${
|
|
375
|
+
<div class="set-ro-note">${O("readonly")}<span>The sender is set at deploy in <code>wrangler.jsonc</code>, with the AWS keys stored as secrets, so it can’t be edited here. Change it in the <a class="set-link" href="#/docs/self-hosting">setup guide</a>, then redeploy. Credentials are never shown.</span></div>
|
|
375
376
|
<div class="set-preview-bar" style="background:transparent">
|
|
376
377
|
<span class="set-preview-lbl">Inbox preview</span>
|
|
377
378
|
<span class="set-preview-dot">How readers see the sender</span>
|
|
378
379
|
</div>
|
|
379
380
|
<div class="set-inbox">
|
|
380
|
-
<div class="set-inbox-avatar">${
|
|
381
|
+
<div class="set-inbox-avatar">${An(n,n)}</div>
|
|
381
382
|
<div class="set-inbox-body">
|
|
382
383
|
<div class="set-inbox-top"><span class="set-inbox-from">${n}</span><span class="set-inbox-time">9:02 AM</span></div>
|
|
383
384
|
<div class="set-inbox-subj">Your latest post: a sample subject line</div>
|
|
384
385
|
<div class="set-inbox-snip">The opening lines of your post show here as the inbox preview…</div>
|
|
385
|
-
<div class="set-inbox-addr">${
|
|
386
|
+
<div class="set-inbox-addr">${rp(t.from_address)}</div>
|
|
386
387
|
</div>
|
|
387
388
|
</div>
|
|
388
389
|
<div class="set-kv" style="border-top:1px solid var(--line)">
|
|
389
|
-
<div class="set-kv-k">From address</div><div class="set-kv-v set-kv-stack"><span class="mono">${t.from_address}</span><span class="muted" id="replyNote">Readers’ replies go to this address. <a class="set-link" href="${
|
|
390
|
+
<div class="set-kv-k">From address</div><div class="set-kv-v set-kv-stack"><span class="mono">${t.from_address}</span><span class="muted" id="replyNote">Readers’ replies go to this address. <a class="set-link" href="${ip}">Forward it to your inbox</a>.</span></div>
|
|
390
391
|
<div class="set-kv-k">Sending domain</div><div class="set-kv-v"><span class="mono">${t.sending_domain}</span></div>
|
|
391
|
-
<div class="set-kv-k">Email provider</div><div class="set-kv-v" id="providerValue">${
|
|
392
|
+
<div class="set-kv-k">Email provider</div><div class="set-kv-v set-kv-stack" id="providerValue">${sp(t,s)}${s?.warnings.map(a=>o`<span class="set-warn">${Ts(a)}</span>`)}</div>
|
|
393
|
+
${i?o`<div class="set-kv-k">Send rate</div><div class="set-kv-v" id="sendRate">${i}</div>`:null}
|
|
392
394
|
</div>
|
|
393
395
|
</div>
|
|
394
|
-
</section>`}function
|
|
396
|
+
</section>`}function ml(e){let t=e.data.deployment,n=`${t.archive_origin||""}${t.archive_base_path||""}`,s=t.archive_origin===t.app_origin;return o`
|
|
395
397
|
<section class="set-sec">
|
|
396
398
|
${we("Instance",ye("readonly","Read-only \xB7 set at deploy"))}
|
|
397
399
|
<div class="set-card sunken">
|
|
398
|
-
<div class="set-ro-note">${
|
|
400
|
+
<div class="set-ro-note">${O("info")}<span>Deploy-time infrastructure, shown for reference. These live in your Worker config and never pass through the API. See the <a class="set-link" href="#/docs/configuration">setup guide</a> to change them.</span></div>
|
|
399
401
|
<div class="set-kv">
|
|
400
402
|
<div class="set-kv-k">App origin</div><div class="set-kv-v"><span class="mono">${t.app_origin}</span></div>
|
|
401
403
|
<div class="set-kv-k">Archive URL base</div><div class="set-kv-v"><span class="mono">${n}</span>${s?o`<span class="set-pill">default: app origin</span>`:null}</div>
|
|
402
404
|
<div class="set-kv-k">Image URL base</div><div class="set-kv-v"><span class="mono">${t.media_public_base}</span></div>
|
|
403
405
|
<div class="set-kv-k">Auth mode</div><div class="set-kv-v">${t.auth_mode==="access"?"Cloudflare Access":"Local dev token"}</div>
|
|
404
|
-
<div class="set-kv-k">Cloudflare Access</div><div class="set-kv-v">${t.access_configured?o`<span class="set-pill ok">${
|
|
405
|
-
<div class="set-kv-k">Minimum lead</div><div class="set-kv-v">${It(t.min_lead_ms)}${t.min_lead_ms===
|
|
406
|
+
<div class="set-kv-k">Cloudflare Access</div><div class="set-kv-v">${t.access_configured?o`<span class="set-pill ok">${O("check")}Configured</span>`:o`<span class="set-pill">Not configured</span>`}</div>
|
|
407
|
+
<div class="set-kv-k">Minimum lead</div><div class="set-kv-v">${It(t.min_lead_ms)}${t.min_lead_ms===ns?o`<span class="set-pill">default</span>`:null}</div>
|
|
406
408
|
</div>
|
|
407
409
|
</div>
|
|
408
|
-
</section>`}function
|
|
410
|
+
</section>`}function ap(e){return e instanceof te&&e.status===409&&e.data?.error==="remake_required"?e.data:null}var lp="Not saved: the change needed your confirmation";async function _t(e,t,n){let s=null;for(;;)try{return await e(s)}catch(i){let a=ap(i);if(!a)throw i;let r=a.sends||[];if(!await cp(r,t,n))return n.aborted&&U(lp),null;s=r.map(d=>d.id)}}function cp(e,t,n){let s=e.length,i=s===1,a=`${s} scheduled email${i?"":"s"}`;return new Promise(r=>{let l=me(o`<h3>Apply this change to ${a}?</h3>
|
|
409
411
|
<p class="hint">${t.lead(s)} ${t.gerund} applies the change to ${i?"its email":"their emails"} too.</p>
|
|
410
|
-
<ul class="remake-list">${e.map(p=>o`<li><span>${p.subject||o`<em>untitled</em>`}</span><span>sends ${
|
|
412
|
+
<ul class="remake-list">${e.map(p=>o`<li><span>${p.subject||o`<em>untitled</em>`}</span><span>sends ${K(p.fire_at)}</span></li>`)}</ul>
|
|
411
413
|
<dl class="remake-facts">
|
|
412
414
|
<div><dt>Changes</dt><dd>the look of ${i?"its email":"their emails"}</dd></div>
|
|
413
415
|
<div><dt>Stays</dt><dd>${i?"its content and fire time":"their content and fire times"}</dd></div>
|
|
414
416
|
<div><dt>Next</dt><dd>send yourself a fresh test${i?"":" of each"}</dd></div>
|
|
415
417
|
</dl>
|
|
416
418
|
<p class="hint">To leave scheduled emails as they are while future posts change, you’d need a second template, which Kestrel doesn’t offer yet.</p>
|
|
417
|
-
<div class="actions"><button type="button" id="rmCancel">Cancel</button><button type="button" class="primary" id="rmGo">${t.action} and apply</button></div>`,n);if(!l.el.isConnected){r(!1);return}let d=!1,u=p=>{d||(d=!0,r(p))},
|
|
419
|
+
<div class="actions"><button type="button" id="rmCancel">Cancel</button><button type="button" class="primary" id="rmGo">${t.action} and apply</button></div>`,n);if(!l.el.isConnected){r(!1);return}let d=!1,u=p=>{d||(d=!0,r(p))},m=l.el.querySelector("#rmCancel"),w=l.el.querySelector("#rmGo");m&&(m.onclick=()=>{l.close(),u(!1)}),w&&(w.onclick=()=>{l.close(),u(!0)});let h=new MutationObserver(()=>{l.el.isConnected||(h.disconnect(),u(!1))});h.observe(document.body,{childList:!0}),w?.focus()})}var fl={action:"Save",gerund:"Saving",lead:e=>`This template is used by ${e} post${e===1?" that\u2019s":"s that are"} already scheduled.`},Hn=(e,t)=>({action:e,gerund:t,lead:n=>`Your name, tagline, address, and logo ride inside every email, including ${n} post${n===1?" that\u2019s":"s that are"} already scheduled.`});function js(e){let t=e?.sends||[];if(!t.length)return o`<span class="set-chip">${O("info")}No posts scheduled</span>`;let n=t.length;return o`<span class="set-chip inuse"><span class="set-chip-dot"></span>In use by ${n} scheduled post${n===1?"":"s"}</span>`}function dp(e,t=Date.now()){let n=e?.retry_after;if(!e||!n||t>=n)return"";let s=Math.max(1,e.sends.filter(i=>i.fire_at<=n).length);return s===1?`A scheduled post sends at ${K(n)}. You can save once it has sent.`:`${s} scheduled posts send by ${K(n)}. You can save once they have sent.`}function Xt(e){let t=dp(e);return t?o`<span data-remake-wait> ${t}</span>`:null}function Ws(e,t,n){let s=t?.retry_after;s&&ft(s,()=>{for(let i of e.querySelectorAll("[data-remake-wait]"))i.remove()},n)}function en(e,t){let n=(t||[]).length;return n?`${e} and applied to ${n} scheduled email${n===1?"":"s"}. Send yourself a test of each.`:e}var hl=e=>e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'");function bl(e,t){return e?`<img class="logo" src="${hl(e)}" alt="${hl(t)}" width="44" height="44" />`:""}var gl="You\u2019ve added a mailing address in Settings, but this template doesn\u2019t include the {{ .Publication.Address }} field. If you send promotional email, add it to the footer. If you\u2019ve written your address into the template yourself, or don\u2019t need to provide one, you can ignore this or remove the address in Settings.";function up(e,t){let n=Math.min(e,t);return{x:Math.floor((e-n)/2),y:Math.floor((t-n)/2),side:n}}var oi=class extends Error{constructor(){super("Couldn\u2019t read that image. Pick a PNG, JPEG, WebP, or GIF.")}};async function vl(e,t){let n=await createImageBitmap(e,{imageOrientation:"from-image"}).catch(()=>{throw new oi});try{let{x:s,y:i,side:a}=up(n.width,n.height),r=document.createElement("canvas");r.width=t,r.height=t;let l=r.getContext("2d");if(!l)throw new Error("This browser can\u2019t prepare the image.");return l.imageSmoothingQuality="high",l.drawImage(n,s,i,a,a,0,0,t,t),{png:await new Promise((u,m)=>r.toBlob(w=>w?u(w):m(new Error("This browser can\u2019t prepare the image.")),"image/png")),width:n.width,height:n.height}}finally{n.close()}}function pp(e){if(!(e.identity_fields||[]).length)return o`Your email template doesn’t show any of these.`;let t="Shown in every email.",n=e.sends.length;if(!n)return o`${t}`;let s=`Saving a change updates ${n} scheduled email${n===1?"":"s"} too; you\u2019ll confirm first.`;return o`${t} ${s}${Xt(e)}`}var mp="#/docs/name-your-publication/when-to-provide-a-mailing-address";function Pn(){return o`<a class="set-link" href="${mp}" target="_blank" rel="noopener">When to provide a mailing address <span aria-hidden="true">↗</span><span class="visually-hidden"> (opens in a new tab)</span></a>`}var ii=256;function yl(e){let{state:t,fromDisplay:n,fromName:s}=e,i=!!t.address;return o`
|
|
418
420
|
<section class="set-sec">
|
|
419
421
|
${we("Publication identity",ye("editable","Editable"))}
|
|
420
422
|
<div class="set-card">
|
|
421
423
|
<div class="set-id-grid">
|
|
422
424
|
<div class="set-logo-slot">
|
|
423
425
|
<div class="set-logo-tile${t.logoUrl?" has-img":""}" id="logoTile" role="button" tabindex="0" aria-label="Upload logo">
|
|
424
|
-
<span class="set-logo-ph" id="logoPh"${t.logoUrl?
|
|
426
|
+
<span class="set-logo-ph" id="logoPh"${t.logoUrl?Cn:null}>${O("upload")}Upload</span>
|
|
425
427
|
</div>
|
|
426
428
|
<input type="file" id="logoInput" accept="image/png,image/jpeg,image/webp,image/gif" hidden>
|
|
427
429
|
<div class="set-logo-actions">
|
|
428
430
|
<button type="button" id="logoReplace">${t.logoUrl?"Replace":"Upload"}</button>
|
|
429
|
-
<button type="button" class="danger-subtle" id="logoRemove"${t.logoUrl?null:
|
|
431
|
+
<button type="button" class="danger-subtle" id="logoRemove"${t.logoUrl?null:Cn}>Remove</button>
|
|
430
432
|
</div>
|
|
431
433
|
<div class="set-logo-notes">
|
|
432
|
-
<p class="field-hint">Shown as a square. Pick an image at least ${String(
|
|
434
|
+
<p class="field-hint">Shown as a square. Pick an image at least ${String(ii)} × ${String(ii)} px; a wider or taller one is cropped to its center square.</p>
|
|
433
435
|
<p class="set-field-warn" id="logoShape" hidden>Your logo isn’t square, so emails show it stretched. Replace it to have it cropped square.</p>
|
|
434
436
|
<div class="field-error" id="logoError" role="alert" hidden><span class="field-error-ico" aria-hidden="true">!</span><span></span></div>
|
|
435
437
|
</div>
|
|
@@ -445,24 +447,24 @@
|
|
|
445
447
|
<input id="setTagline" value="${t.tagline}" placeholder="A one-line description" maxlength="200" autocomplete="off">
|
|
446
448
|
<p class="field-hint">A short line under the name on your public pages.</p>
|
|
447
449
|
</div>
|
|
448
|
-
<div class="set-field set-addr-add" id="addrAdd"${i?
|
|
449
|
-
<button type="button" class="ghost" id="addrAddBtn" aria-describedby="addrAddHint">${
|
|
450
|
-
<p class="field-hint" id="addrAddHint">For promotional email, US law (CAN-SPAM) requires a postal address in the footer. A P.O. box works. ${
|
|
450
|
+
<div class="set-field set-addr-add" id="addrAdd"${i?Cn:null}>
|
|
451
|
+
<button type="button" class="ghost" id="addrAddBtn" aria-describedby="addrAddHint">${O("plus")}Add a mailing address</button>
|
|
452
|
+
<p class="field-hint" id="addrAddHint">For promotional email, US law (CAN-SPAM) requires a postal address in the footer. A P.O. box works. ${Pn()}</p>
|
|
451
453
|
</div>
|
|
452
|
-
<div class="set-field" id="addrField"${i?null:
|
|
454
|
+
<div class="set-field" id="addrField"${i?null:Cn}>
|
|
453
455
|
<div class="set-field-head">
|
|
454
456
|
<label for="setAddress">Mailing address</label>
|
|
455
457
|
<button type="button" class="danger-subtle set-field-remove" id="addrRemove">Remove</button>
|
|
456
458
|
</div>
|
|
457
459
|
<input id="setAddress" value="${t.address}" placeholder="PO Box 123, City, ST 00000" maxlength="300" autocomplete="off">
|
|
458
|
-
<p class="field-hint">${
|
|
459
|
-
<p class="set-field-warn" id="addrWarn" hidden>Your email template currently doesn’t include this field. If you send promotional email, add it to the template. ${
|
|
460
|
+
<p class="field-hint">${Pn()}</p>
|
|
461
|
+
<p class="set-field-warn" id="addrWarn" hidden>Your email template currently doesn’t include this field. If you send promotional email, add it to the template. ${Pn()}</p>
|
|
460
462
|
</div>
|
|
461
463
|
</div>
|
|
462
464
|
</div>
|
|
463
|
-
<div class="set-note">${
|
|
465
|
+
<div class="set-note">${O("info")}<span>${pp(e.data.in_use)}</span></div>
|
|
464
466
|
</div>
|
|
465
|
-
</section>`}function
|
|
467
|
+
</section>`}function wl(e,t,n){let{state:s}=t,i=c("#setName",e),a=c("#setTagline",e),r=c("#setAddress",e),l=()=>{s.name=i.value.trim(),s.tagline=a.value.trim(),s.address=r.value.trim(),t.changed()};i.addEventListener("input",l),a.addEventListener("input",l),r.addEventListener("input",l);let d=!!s.address,u=(t.data.in_use.identity_fields||[]).includes("address"),m=c("#addrAdd",e),w=c("#addrField",e),h=c("#addrWarn",e),p=()=>{m.hidden=d,w.hidden=!d,h.hidden=!(d&&s.address&&!u),h.hidden?r.removeAttribute("aria-describedby"):r.setAttribute("aria-describedby","addrWarn")};r.addEventListener("input",p),c("#addrAddBtn",e).onclick=()=>{d=!0,p(),r.focus()},c("#addrRemove",e).onclick=()=>{r.value="",d=!1,l(),p(),c("#addrAddBtn",e).focus()};let S=c("#logoInput",e),E=c("#logoTile",e),I=c("#logoPh",e),C=c("#logoReplace",e),H=c("#logoRemove",e),L=c("#logoShape",e),v=b=>{if(L.hidden=!0,!b)return;let k=new Image;k.onload=()=>{L.hidden=s.logoUrl!==b||k.naturalWidth===k.naturalHeight},k.src=b},y=()=>{let b=!!s.logoUrl;v(s.logoUrl),E.classList.toggle("has-img",b),E.style.backgroundImage=b?`url('${s.logoUrl}')`:"",I.hidden=b,H.hidden=!b,C.textContent=b?"Replace":"Upload"};C.onclick=()=>S.click(),E.addEventListener("click",()=>S.click()),E.addEventListener("keydown",b=>{(b.key==="Enter"||b.key===" ")&&(b.preventDefault(),S.click())});let $=c("#logoError",e),A=c("span:last-of-type",$),W=b=>{A.textContent=b,$.hidden=!b},z=(b,k)=>{s.logoUrl=b.settings.publication.logo_url||"",t.applySaved(b.settings),y(),t.changed(),U(en(k,b.remade))},G=b=>W(at(b));return S.onchange=async()=>{let b=S.files?.[0];if(S.value="",!!b){W("");try{let k=await vl(b,ii),R=k.width!==k.height,x=await _t(F=>{let P=new FormData;P.append("file",new File([k.png],"logo.png",{type:"image/png"}));let B=F?`?remake=${encodeURIComponent(F.join(","))}`:"";return T(`/api/settings/logo${B}`,{method:"POST",body:P})},Hn("Upload","Uploading"),n);x&&z(x,R?"Logo updated, cropped to its center square":"Logo updated")}catch(k){G(k)}}},H.onclick=()=>Y(H,"Removing\u2026",async()=>{W("");try{let b=await _t(k=>{let R=k?`?remake=${encodeURIComponent(k.join(","))}`:"";return T(`/api/settings/logo${R}`,{method:"DELETE"})},Hn("Remove","Removing"),n);b&&z(b,"Logo removed")}catch(b){G(b)}}),y(),p(),{reset(){i.value=s.name,a.value=s.tagline,r.value=s.address,d=!!s.address,p()}}}var Vs=q,fp=[{group:"Post",vars:[{token:"{{ .Post.Body }}",desc:"Your post\u2019s Markdown, rendered to HTML."},{token:"{{ .Post.Subject }}",desc:"The post\u2019s subject line."}]},{group:"Publication",vars:[{token:"{{ .Publication.Name }}",desc:"Publication name (from Identity, above)."},{token:"{{ .Publication.Tagline }}",desc:"Your tagline."},{token:"{{ .Publication.Logo }}",desc:"Your logo as an image, or nothing when no logo is set."},{token:"{{ .Publication.LogoURL }}",desc:"Absolute URL of your logo, or empty."},{token:"{{ .Publication.Address }}",desc:"Your mailing address, if you\u2019ve added one in Settings; empty otherwise. Keep it in the footer if you send promotional email."}]},{group:"Email",vars:[{token:"{{ .Email.SentTo }}",desc:"The recipient\u2019s address (filled per send)."},{token:"{{ .Email.UnsubscribeURL }}",desc:"Their one-click unsubscribe link."},{token:"{{ .Email.ViewInBrowserURL }}",desc:"The web version\u2019s permanent URL."}]},{group:"Email only",vars:[{token:"{{ if .IsEmail }} \u2026 {{ end }}",desc:"Reports whether this is the email or the web version. Put your unsubscribe link and address inside; the web version leaves them out."}]}],ri={signed:{label:"Signed",description:"Your post, then your logo, name, and tagline as a sign-off. Your mailing address sits in the footer once you add one.",html:`<style>
|
|
466
468
|
.email {
|
|
467
469
|
font: 16px/1.6 -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
|
|
468
470
|
color: #18181b;
|
|
@@ -617,7 +619,7 @@
|
|
|
617
619
|
<a href="{{ .Email.ViewInBrowserURL }}">View in browser</a>
|
|
618
620
|
<div class="address">{{ .Publication.Address }}</div>{{ end }}
|
|
619
621
|
</div>
|
|
620
|
-
</div>`}},
|
|
622
|
+
</div>`}},hp=e=>Object.hasOwn(ri,e),bp=`<div style="position:relative;border:1px dashed #93a7e6;border-radius:8px;padding:20px 14px 8px;margin:0 0 6px"><span style="position:absolute;top:-8px;left:10px;font:650 10px/1.4 -apple-system,BlinkMacSystemFont,'Segoe UI',sans-serif;letter-spacing:.04em;text-transform:uppercase;color:#3355cc;background:#fff;padding:0 6px">Your post\u2019s Markdown renders here</span><h2 style="margin:0 0 10px">Lorem ipsum,</h2><p style="margin:0">Dolor sit amet, consectetur adipiscing elit. Proin sed ex ipsum. Suspendisse vulputate nisi et odio dapibus, quis pellentesque felis sollicitudin. Proin vel cursus enim. Phasellus sollicitudin malesuada elementum. Suspendisse euismod eros turpis, ut mollis est imperdiet ut. Sed luctus accumsan erat, at eleifend purus eleifend quis.</p></div>`,gp=new Set([".Post.Body",".Publication.Logo"]);function vp(e,t){return String(e).replace(/\{\{\s*(?:if\b[^}]*|end)\s*\}\}/g,"").replace(/\{\{\s*([\w.]+)\s*\}\}/g,(s,i)=>gp.has(i)?t[i]||"":X(t[i]??""))}function yp(e){let t=e.name||"Your publication";return{".Post.Body":bp,".Post.Subject":"The starlings are back",".Publication.Name":t,".Publication.Tagline":e.tagline||"Your tagline",".Publication.LogoURL":e.logoUrl,".Publication.Logo":bl(e.logoUrl,t),".Publication.Address":e.address,".Email.SentTo":"you@example.com",".Email.UnsubscribeURL":"#unsubscribe",".Email.ViewInBrowserURL":"#view-in-browser"}}function wp(e,t){return vp(e,yp(t))}var Sp='<!doctype html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><style>html,body{margin:0}body{background:#fff}@media (prefers-color-scheme:dark){body{background:#18181b}}.kestrel-email{max-width:640px;margin:0 auto;padding:26px 20px;box-sizing:border-box}.kestrel-email img{max-width:100%}</style></head><body><div class="kestrel-email"></div></body></html>';function ai(e,t,n){e.setAttribute("sandbox",Yt);let s=!1,i=()=>{try{let r=e.contentDocument?.body?.scrollHeight;r&&(e.style.height=`${Math.max(200,r)}px`)}catch{}},a=()=>{let r=e.contentDocument,l=s&&r?r.querySelector(".kestrel-email"):null;l&&(f(l,V(wp(t(),n()))),Zt(l.ownerDocument),i())};return e.addEventListener("load",()=>{s=!0,a();try{let r=e.contentDocument;r?.body&&typeof ResizeObserver<"u"&&new ResizeObserver(i).observe(r.body)}catch{}}),e.srcdoc=Sp,{repaint:a}}function $p(){return o`${fp.map(e=>o`<div class="set-tpl-vargroup"><h4>${e.group}</h4>${e.vars.map(t=>o`<div class="set-tpl-var"><code>${t.token}</code><span class="set-tpl-var-desc">${t.desc}</span></div>`)}</div>`)}`}async function li(e,t){oe(t,"Template"),f(e,o`<div class="tpl-page"><div class="page-head"><div class="page-head-row"><h1>Email template</h1><span id="tplInUse"></span></div><p class="set-lede set-page-lede">The template controls the look and feel of the emails you send. You write it as HTML with a <code><style></code> block and <code>{{ variables }}</code> Kestrel fills in; your post’s Markdown is rendered into <code>{{ .Post.Body }}</code>.<span id="tplWait"></span></p></div><div id="tplBody" class="muted">Loading…</div></div>`);let n=c("#tplBody",e),s;try{s=await T("/api/settings",{signal:t})}catch(Z){ie(n,Vs(Z),()=>ee(li));return}let i=s.settings,a=s.deployment,r=i.publication,l={name:dn(r.name||"",a.from_address),tagline:r.tagline||"",logoUrl:r.logo_url||"",address:r.address||""},d=i.email_template||"",u=Array.isArray(i.test_recipients)?i.test_recipients:[];f(c("#tplInUse"),js(s.in_use)),f(c("#tplWait"),o`${Xt(s.in_use)}`),Ws(e,s.in_use,t),f(n,o`
|
|
621
623
|
<div class="set-preview set-tpl-sample">
|
|
622
624
|
<div class="set-preview-bar">
|
|
623
625
|
<span class="set-preview-titles">
|
|
@@ -629,7 +631,7 @@
|
|
|
629
631
|
<button type="button" class="wtog-btn" data-w="640" aria-pressed="true">640</button>
|
|
630
632
|
<button type="button" class="wtog-btn" data-w="375" aria-pressed="false">375</button>
|
|
631
633
|
</span>
|
|
632
|
-
<button type="button" class="secondary" id="tplTest">${
|
|
634
|
+
<button type="button" class="secondary" id="tplTest">${O("send")}<span id="tplTestLbl">Send test email</span></button>
|
|
633
635
|
</span>
|
|
634
636
|
</div>
|
|
635
637
|
<div class="set-email-stage" id="tplStage">
|
|
@@ -644,7 +646,7 @@
|
|
|
644
646
|
<div class="set-tpl-editor-head">
|
|
645
647
|
<div class="set-tpl-tools">
|
|
646
648
|
<button type="button" class="ghost set-menu-btn" id="tplExamplesBtn" aria-haspopup="menu" aria-expanded="false"><span>Start from example</span><span class="set-menu-caret"></span></button>
|
|
647
|
-
<button type="button" class="set-icon-btn" id="tplLineNums" aria-pressed="false" title="Show line numbers" aria-label="Show line numbers">${
|
|
649
|
+
<button type="button" class="set-icon-btn" id="tplLineNums" aria-pressed="false" title="Show line numbers" aria-label="Show line numbers">${O("lines")}</button>
|
|
648
650
|
<button type="button" class="ghost" id="tplCopyAll" title="Copy the whole template to the clipboard" aria-label="Copy the whole template">${Te()}</button>
|
|
649
651
|
</div>
|
|
650
652
|
<div class="set-tpl-required" aria-label="Required variables">
|
|
@@ -661,7 +663,7 @@
|
|
|
661
663
|
<div class="set-tpl-msgs" id="tplMsgs" hidden></div>
|
|
662
664
|
</div>
|
|
663
665
|
</div>
|
|
664
|
-
<div class="set-note">${
|
|
666
|
+
<div class="set-note">${O("info")}<span>Kestrel uses this one template for every post, starting from a sensible default. Saving a change while posts are scheduled applies it to their emails too, after you confirm, so nothing scheduled goes out on an older look; their content stays as it was. Sent emails are archived exactly as they went out and never change. Save and Discard are in the bar at the bottom of the page.</span></div>
|
|
665
667
|
</div>
|
|
666
668
|
|
|
667
669
|
<div class="set-card set-tpl-varcard">
|
|
@@ -670,15 +672,15 @@
|
|
|
670
672
|
<h3 class="set-tpl-vartitle">Variables</h3>
|
|
671
673
|
<p class="field-hint">Kestrel replaces these variables with real values when you send an email. Type a variable exactly as shown, or it renders as empty.</p>
|
|
672
674
|
</div>
|
|
673
|
-
<div class="set-tpl-vars-body">${
|
|
675
|
+
<div class="set-tpl-vars-body">${$p()}</div>
|
|
674
676
|
</div>
|
|
675
|
-
</div>`);let
|
|
677
|
+
</div>`);let m=c("#tplEditor"),w=ai(c("#tplPreview"),()=>m.value,()=>l),h=c("#tplMsgs"),p=c("#tplTest"),S=c("#tplTestLbl"),E=()=>m.value!==d,I=c("#tplHl"),C=c("code",I),H=c("#tplGutter"),L=()=>{let Z=m.value;f(C,o`${_a(Z)}\n`);let le="",de=Z.split(`
|
|
676
678
|
`).length;for(let He=1;He<=de;He++)le+=`${He}
|
|
677
|
-
`;H.textContent=le},
|
|
678
|
-
`);let Pe=c("#tplTestHint",de.el);Pe.textContent="Pre-filled from your default test recipients (Settings).",Pe.hidden=!1}He.onclick=()=>
|
|
679
|
-
`),de.error(
|
|
679
|
+
`;H.textContent=le},v=()=>{I.scrollTop=m.scrollTop,I.scrollLeft=m.scrollLeft,H.scrollTop=m.scrollTop};m.addEventListener("scroll",v);let y=c("#reqBody"),$=c("#reqUnsub"),A=()=>{y.className=`set-req-pill ${/\{\{\s*\.Post\.Body\s*\}\}/.test(m.value)?"ok":"bad"}`,$.className=`set-req-pill ${/\{\{\s*\.Email\.UnsubscribeURL\s*\}\}/.test(m.value)?"ok":"bad"}`},W=Fs.attach({onSave:R,onDiscard:b},t);function z(){L(),A(),v(),W.setDirty(E()),S.textContent=E()?"Save & send test":"Send test email",p.title=E()?"Saves your changes first, then sends: a test always reflects the saved template that will ship.":"Sends a sample post through the saved template so you can see it in a real inbox."}function G(Z){if(!Z.length){h.hidden=!0,f(h,o``);return}h.hidden=!1,h.className="set-tpl-msgs warn",f(h,o`${Z.map(le=>o`<div>${le}${le===gl?o` ${Pn()}`:null}</div>`)}`)}function b(){m.value=d,G([]),w.repaint(),z()}async function k(){let Z=m.value,le=await _t(de=>T("/api/settings",{method:"PUT",json:de?{email_template:Z,remake:de}:{email_template:Z}}),fl,t);return le?(d=le.settings.email_template,m.value=d,Q.appConfig={...s,settings:le.settings},w.repaint(),z(),{warnings:Array.isArray(le.warnings)?le.warnings:[],remade:le.remade||[]}):null}async function R(){try{let Z=await k();if(!Z)return;G(Z.warnings),U(en(Z.warnings.length?"Template saved with warnings":"Template saved",Z.remade))}catch(Z){W.showError(Vs(Z))}}let x=Z=>{let le=ri[hp(Z)?Z:"signed"];m.value=le.html,G([]),w.repaint(),z()};m.addEventListener("input",()=>{w.repaint(),z()});let F=c("#tplExamplesBtn");F.onclick=()=>Kt(F,Object.entries(ri).map(([Z,le])=>({label:le.label,description:le.description,onClick:()=>x(Z)})),t,{align:"start"});let P=c("#tplPreview");for(let Z of N(".wtog-btn",n))Z.onclick=()=>{for(let le of N(".wtog-btn",n))le.setAttribute("aria-pressed",String(le===Z));P.style.maxWidth=`${Z.dataset.w}px`,w.repaint()};let B=c("#tplEditorWrap"),ne=c("#tplLineNums"),j=Z=>{B.classList.toggle("show-lines",Z),ne.setAttribute("aria-pressed",String(Z)),v()},ae=!1;try{ae=localStorage.getItem("kestrel.tpl.lineNums")==="1"}catch{}j(ae),ne.onclick=()=>{ae=!ae,j(ae);try{localStorage.setItem("kestrel.tpl.lineNums",ae?"1":"0")}catch{}};let lt=c("#tplCopyAll");lt.onclick=()=>$n(lt,m.value),p.onclick=()=>{let Z=ve(),le=!Z&&E(),de=me(o`<h3>Send a test email</h3><p class="hint">Delivers a sample post rendered through your <strong>saved</strong> template, so you can see it in a real inbox. One address per line.</p>${us()}${le?o`<p class="hint" style="color:var(--warn-fg)"><strong>Unsaved changes:</strong> sending will save your template first, so the test reflects what will actually ship.</p>`:null}${Z?null:o`<label for="tplTestTo">Recipients</label><textarea id="tplTestTo" rows="3" placeholder="you@example.com"></textarea><p class="hint" id="tplTestHint" hidden></p>`}<div class="actions"><button type="button" id="ttCancel">Cancel</button><button type="button" class="primary" id="ttGo">${le?"Save & send test":"Send test"}</button></div>`,t),He=c("#ttGo",de.el);if(c("#ttCancel",de.el).onclick=de.close,He.disabled=Z,Z){c("#ttCancel",de.el).focus();return}let Re=c("#tplTestTo",de.el);if(Re.focus(),u.length&&!Re.value.trim()){Re.value=u.join(`
|
|
680
|
+
`);let Pe=c("#tplTestHint",de.el);Pe.textContent="Pre-filled from your default test recipients (Settings).",Pe.hidden=!1}He.onclick=()=>Y(He,E()?"Saving\u2026":"Sending\u2026",async()=>{de.clearError();let{valid:Pe,invalid:ct}=bs(Re.value),dt=gs(ct);if(dt){de.error(dt,Re);return}if(!Pe.length){de.error("Enter at least one email address",Re);return}if(E())try{let pe=await k();if(!pe){de.close();return}G(pe.warnings)}catch(pe){W.showError(Vs(pe)),de.close();return}try{let pe=await T("/api/settings/template/test",{method:"POST",json:{to:Pe}});if(pe.failed.length){Re.value=pe.failed.join(`
|
|
681
|
+
`),de.error(vs(pe.sent,pe.total,pe.not_sent));return}de.close(),U(Nt(`Test sent to ${pe.sent} address${pe.sent===1?"":"es"}`))}catch(pe){de.error(Vs(pe))}})},m.value=d,w.repaint(),z()}function Sl(e){return o`
|
|
680
682
|
<section class="set-sec">
|
|
681
|
-
${we("Email template",ye("editable","Editable"),
|
|
683
|
+
${we("Email template",ye("editable","Editable"),js(e.data.in_use))}
|
|
682
684
|
<p class="set-lede">The template controls the look and feel of the emails you send. Edit it on the Template page.${Xt(e.data.in_use)}</p>
|
|
683
685
|
<div class="set-preview set-tpl-sample">
|
|
684
686
|
<div class="set-preview-bar">
|
|
@@ -688,7 +690,7 @@
|
|
|
688
690
|
<iframe class="set-email-frame" id="tplPreview" title="Sample email preview" scrolling="no"></iframe>
|
|
689
691
|
</div>
|
|
690
692
|
<div class="row" style="margin-top:12px"><button type="button" id="tplEditLink">Edit template →</button></div>
|
|
691
|
-
</section>`}function
|
|
693
|
+
</section>`}function $l(e,t){let n=t.data.settings.email_template||"",s=ai(c("#tplPreview",e),()=>n,()=>({name:t.state.name||t.fromDisplay,tagline:t.state.tagline,logoUrl:t.state.logoUrl,address:t.state.address}));return c("#tplEditLink",e).onclick=()=>{location.hash="#/template"},{repaint:()=>s.repaint()}}function El(){return o`
|
|
692
694
|
<section class="set-sec">
|
|
693
695
|
${we("Default test recipients",ye("editable","Editable"))}
|
|
694
696
|
<div class="set-card">
|
|
@@ -701,7 +703,7 @@
|
|
|
701
703
|
</div>
|
|
702
704
|
</div>
|
|
703
705
|
</div>
|
|
704
|
-
</section>`}function
|
|
706
|
+
</section>`}function xl(e,t){let{state:n}=t,s=c("#recipChips",e),i=c("#recipInput",e),a=()=>{if(!n.recipients.length){f(s,o`<span class="set-recip-empty">No default recipients yet. Add one below.</span>`);return}f(s,o`${n.recipients.map((l,d)=>o`<span class="set-recip-chip">${l}<button type="button" data-rm="${d}" aria-label="Remove ${l}">${O("x")}</button></span>`)}`)};s.addEventListener("click",l=>{let d=l.target instanceof Element?l.target.closest("[data-rm]"):null;d&&(n.recipients.splice(Number(d.dataset.rm),1),a(),t.changed())});let r=()=>{let l=gt(i.value);if(l){if(!vt(l)){Ne(i,"That doesn\u2019t look like an email address."),i.focus();return}if(n.recipients.includes(l)){Ne(i,"That inbox is already in the list."),i.focus();return}n.recipients.push(l),i.value="",a(),t.changed()}};return c("#recipAdd",e).onclick=r,i.addEventListener("keydown",l=>{l.key==="Enter"&&(l.preventDefault(),r())}),a(),{reset:a}}function Ep(e,t){switch(e){case"cloudflare":return"Cloudflare Email, separate from your newsletter\u2019s provider";case"provider":return t==="none"?"Your email provider, once one is connected":`Your email provider (${qs(t)})`;default:return"Local stand-in: nothing is delivered"}}var kl={finished:"went out",refused:"provider refusing",stuck:"in flight too long",wedged:"waiting to be resolved",missed:"missed fire time",import:"list imported",sandbox:"signup refused by the SES sandbox",test:"test"};function _l(e){return e.kind==="test"?"test notification":e.subject?`${e.subject} (${kl[e.kind]})`:kl[e.kind]}function ci(e){let{last_sent:t,last_failure:n}=e;return n?o`<span class="set-pill danger">Not delivered</span> <span class="muted">${K(n.at)}, ${_l(n)}: ${n.error}</span>`:t?o`<span class="set-pill ok">${O("check")}Delivered</span> <span class="muted">${K(t.at)}, ${_l(t)}</span>`:o`<span class="muted">None yet</span>`}function Tl(e){let t=e.data.deployment;return o`
|
|
705
707
|
<section class="set-sec">
|
|
706
708
|
${we("Notifications",ye("editable","Editable"))}
|
|
707
709
|
<p class="set-lede">Kestrel emails you when a send goes out, and right away if a send runs into a problem.</p>
|
|
@@ -715,27 +717,27 @@
|
|
|
715
717
|
<div class="row"><button type="button" class="ghost" id="notifyTest">Send a test notification</button><span class="field-hint" id="notifyTestHint"></span></div>
|
|
716
718
|
</div>
|
|
717
719
|
<div class="set-kv" style="border-top:1px solid var(--line)">
|
|
718
|
-
<div class="set-kv-k">Sent through</div><div class="set-kv-v">${
|
|
720
|
+
<div class="set-kv-k">Sent through</div><div class="set-kv-v">${Ep(t.notify_channel,t.provider)}</div>
|
|
719
721
|
<div class="set-kv-k">From address</div><div class="set-kv-v"><span class="mono">${t.notify_from}</span></div>
|
|
720
|
-
<div class="set-kv-k">Last notification</div><div class="set-kv-v" id="notifyStatus">${
|
|
722
|
+
<div class="set-kv-k">Last notification</div><div class="set-kv-v" id="notifyStatus">${ci(e.data.notification_status)}</div>
|
|
721
723
|
</div>
|
|
722
|
-
<div class="set-note">${
|
|
724
|
+
<div class="set-note">${O("readonly")}<span>The channel and its sender are set at deploy. ${t.notify_channel==="provider"?"Notifications go through your newsletter\u2019s own provider, so one about the provider refusing your account cannot reach you; Cloudflare\u2019s email avoids that. ":""}See the <a class="set-link" href="#/docs/notifications">setup guide</a>.</span></div>
|
|
723
725
|
</div>
|
|
724
|
-
</section>`}function
|
|
725
|
-
<h3 class="set-rp-jhead" id="rpJourney-${e.id}">${
|
|
726
|
+
</section>`}function Ll(e,t){let n=c("#notifyTo",e),s=c("#notifyTest",e),i=c("#notifyTestHint",e),a=c("#notifyStatus",e);n.addEventListener("input",()=>{t.state.notifyTo=n.value.trim().toLowerCase(),t.changed()});let r=()=>{let l=t.saved().notifyTo,d=l?t.state.notifyTo!==l?"Save first: the test goes to the saved address.":"":"Save an address to send a test.";s.disabled=!!d,i.textContent=d};return s.onclick=()=>Y(s,"Sending\u2026",async()=>{try{let l=await T("/api/settings/notifications/test",{method:"POST"});U(l.channel==="fake"?`Test notification recorded for ${l.to} (local stand-in: nothing is delivered)`:`Test notification sent to ${l.to}`),f(a,ci({last_sent:{kind:"test",subject:"",at:Date.now()},last_failure:null}))}catch(l){f(a,ci({last_sent:null,last_failure:{kind:"test",subject:"",at:Date.now(),error:at(l)}}))}}),r(),{repaint:r,reset(){n.value=t.state.notifyTo,r()}}}var di={base:"app",path:"/subscribe"},Ks={base:"app",path:"/confirm?token=\u2026"},ui={base:"app",path:"/unsubscribe?token=\u2026"},Mn=[{id:"subscribe",label:"Subscribe",flow:"steps",states:[{id:"form",label:"Form",at:di},{id:"check-inbox",label:"Check your inbox",at:di},{id:"not-an-email",label:"Not an email",offPath:!0,at:di}]},{id:"confirm",label:"Confirm",flow:"steps",states:[{id:"ready",label:"Ready",at:Ks},{id:"confirmed",label:"Confirmed",at:Ks},{id:"expired",label:"Expired",offPath:!0,at:Ks},{id:"invalid",label:"Invalid link",offPath:!0,at:Ks}]},{id:"unsubscribe",label:"Unsubscribe",flow:"steps",states:[{id:"ask",label:"Ask",at:ui},{id:"done",label:"Unsubscribed",at:ui},{id:"invalid",label:"Invalid link",offPath:!0,at:ui}]},{id:"reading",label:"Reading",flow:"peers",states:[{id:"landing",label:"Landing page",at:{base:"app",path:"/"}},{id:"archive",label:"Archive",at:{base:"archive",path:""}},{id:"post",label:"Post page",at:{base:"archive",path:"/sample-post"}},{id:"landing-empty",label:"Landing, no posts yet",offPath:!0,at:{base:"app",path:"/"}},{id:"archive-empty",label:"Archive, no posts yet",offPath:!0,at:{base:"archive",path:""}},{id:"not-found",label:"Nothing here yet",offPath:!0,at:{base:"archive",path:"/\u2026"}}]}];function Rl(e,t){return`/api/reader-pages/${encodeURIComponent(e)}/${encodeURIComponent(t)}`}var xp={subscribe:o`Your name, tagline, and logo head each page; the words are Kestrel’s. The embeddable form in Ways to subscribe posts to these pages too.`,confirm:o`Your identity heads each page. You word the email that links here, under Confirmation email; these pages’ words are fixed, so what a reader agrees to can’t be edited away.`,unsubscribe:o`Your identity heads each page; the words are fixed, so leaving always reads the same. A mail client’s own Unsubscribe button leaves without a page.`,reading:o`Your identity heads each page, and a post page is your <a class="set-link" href="#/template">email template</a> around the post, as its web version shows it. Where a page lists posts, they are samples.`},kp={subscribe:"mail",confirm:"circle-check",unsubscribe:"circle-minus",reading:"book"},_p=o`<span class="set-rp-dot"></span>`;function Cl(e,t,n){return o`<li><button type="button" class="set-rp-item${t.offPath?" off":""}" data-journey="${e.id}" data-state="${t.id}" aria-current="false"><span class="set-rp-mark" aria-hidden="true">${n}</span>${t.label}</button></li>`}function Tp(){return o`${Mn.map(e=>{let t=e.states,n=e.flow==="steps";return o`<div class="set-rp-journey" data-journey="${e.id}">
|
|
727
|
+
<h3 class="set-rp-jhead" id="rpJourney-${e.id}">${O(kp[e.id])}${e.label}</h3>
|
|
726
728
|
<ul class="set-rp-list${n?" steps":""}" aria-labelledby="rpJourney-${e.id}">
|
|
727
|
-
${t.filter(s=>!s.offPath).map((s,i)=>
|
|
729
|
+
${t.filter(s=>!s.offPath).map((s,i)=>Cl(e,s,n?String(i+1):_p))}
|
|
728
730
|
</ul>
|
|
729
731
|
<ul class="set-rp-list" aria-label="${e.label}, off the main path">
|
|
730
|
-
${t.filter(s=>s.offPath).map(s=>
|
|
732
|
+
${t.filter(s=>s.offPath).map(s=>Cl(e,s,O("branch")))}
|
|
731
733
|
</ul>
|
|
732
|
-
</div>`})}`}function
|
|
734
|
+
</div>`})}`}function Lp(){return o`<select id="rpSelect" aria-label="Reader page">${Mn.map(e=>{let t=e.states,n=0;return o`<optgroup label="${e.label}">${t.map(s=>{let i=e.flow==="steps"&&!s.offPath?`${++n}. `:"";return o`<option value="${e.id}/${s.id}">${i}${s.label}</option>`})}</optgroup>`})}</select>`}function Al(e){return o`
|
|
733
735
|
<section class="set-sec set-rp-sec" id="readerPages">
|
|
734
736
|
${e}
|
|
735
737
|
<p class="set-lede">Every page a reader can land on, exactly as they see it, with your publication’s identity and sample values. Nothing here changes a page; it shows the ones that are hard to reach by hand.</p>
|
|
736
738
|
<div class="set-card set-rp">
|
|
737
|
-
<nav class="set-rp-nav" aria-label="Reader pages">${
|
|
738
|
-
<div class="set-rp-pick">${
|
|
739
|
+
<nav class="set-rp-nav" aria-label="Reader pages">${Tp()}</nav>
|
|
740
|
+
<div class="set-rp-pick">${Lp()}</div>
|
|
739
741
|
<div class="set-rp-main">
|
|
740
742
|
<div class="set-rp-top">
|
|
741
743
|
<div>
|
|
@@ -743,8 +745,8 @@
|
|
|
743
745
|
<p class="set-rp-note" id="rpNote"></p>
|
|
744
746
|
</div>
|
|
745
747
|
<span class="set-wtog" id="rpWidth" role="group" aria-label="Preview width">
|
|
746
|
-
<button type="button" class="wtog-btn" data-width="desktop" aria-pressed="true">${
|
|
747
|
-
<button type="button" class="wtog-btn" data-width="phone" aria-pressed="false">${
|
|
748
|
+
<button type="button" class="wtog-btn" data-width="desktop" aria-pressed="true">${O("desktop")}Desktop</button>
|
|
749
|
+
<button type="button" class="wtog-btn" data-width="phone" aria-pressed="false">${O("phone")}Phone</button>
|
|
748
750
|
</span>
|
|
749
751
|
</div>
|
|
750
752
|
<div class="set-rp-at"><span class="mono" id="rpAt"></span><span>Sample · links and forms do nothing</span></div>
|
|
@@ -754,7 +756,7 @@
|
|
|
754
756
|
</div>
|
|
755
757
|
</div>
|
|
756
758
|
</div>
|
|
757
|
-
</section>`}function
|
|
759
|
+
</section>`}function Rp(e,t){return`${e.base==="app"?t.app_origin:`${t.archive_origin}${t.archive_base_path}`}${e.path}`.replace(/^https?:\/\//,"")}function Hl(e,t,n){let s=c(".set-rp-nav",e),i=c("#rpSelect",e),a=c("#rpWidth",e),r=c("#rpStage",e),l=c("#rpFrame",e),d=c("#rpError",e),u=Mn[0],m=u.states[0],w="desktop",h=0,p=null;Pt(n,()=>p?.disconnect());let S=()=>{for(let H of N(".set-rp-item",s)){let L=H.dataset.journey===u.id&&H.dataset.state===m.id;H.setAttribute("aria-current",L?"true":"false")}for(let H of N(".set-rp-journey",s))H.classList.toggle("current",H.dataset.journey===u.id);i.value=`${u.id}/${m.id}`,c("#rpJourney",e).textContent=u.label,c("#rpState",e).textContent=m.label,f(c("#rpNote",e),xp[u.id]),c("#rpAt",e).textContent=Rp(m.at,t)},E=()=>{let H=l.contentDocument?.body?.scrollHeight;H&&(l.style.height=`${H}px`)},I=async()=>{let H=++h;try{let L=await Mt(Rl(u.id,m.id),{signal:n});if(H!==h||n.aborted)return;d.hidden=!0,r.hidden=!1,l.srcdoc=Hs(L)}catch(L){if(H!==h||n.aborted)return;l.srcdoc="",r.hidden=!0,d.textContent=`Couldn\u2019t load this page: ${q(L)}`,d.hidden=!1}},C=(H,L)=>{let v=Mn.find(A=>A.id===H),$=(v?.states??[]).find(A=>A.id===L);!v||!$||v===u&&$===m||(u=v,m=$,S(),I())};return l.onload=()=>{let H=l.contentDocument;!H||n.aborted||(H.addEventListener("click",L=>{L.target?.closest?.("a[href], area[href]")&&L.preventDefault()}),p?.disconnect(),E(),H.body&&typeof ResizeObserver<"u"&&(p=new ResizeObserver(E),p.observe(H.body)))},s.addEventListener("click",H=>{let L=H.target.closest(".set-rp-item");C(L?.dataset.journey,L?.dataset.state)}),i.addEventListener("change",()=>{let[H,L]=i.value.split("/");C(H,L)}),a.addEventListener("click",H=>{let v=H.target.closest("button[data-width]")?.dataset.width;if(!(v!=="desktop"&&v!=="phone"||v===w)){w=v;for(let y of N("button",a))y.setAttribute("aria-pressed",String(y.dataset.width===v));r.classList.toggle("phone",v==="phone")}}),S(),I(),{refresh:()=>{I()}}}function Ml(e){return e?`Subscribe to ${e}`:"Subscribe"}function Cp(e,t,n){let s=X(Ml(t)),i=`${X(n)}/subscribe`;return e==="styled"?`<form action="${i}" method="post" style="max-width:460px;font:16px/1.5 -apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif">
|
|
758
760
|
<div style="font:600 22px/1.2 Georgia,'Times New Roman',serif;letter-spacing:-0.01em;margin-bottom:12px">${s}</div>
|
|
759
761
|
<div style="display:flex;gap:10px;flex-wrap:wrap">
|
|
760
762
|
<input type="email" name="email" required placeholder="you@example.com" aria-label="Email address" style="flex:1 1 220px;padding:11px 13px;border:1px solid #d6d3cc;border-radius:9px;background:#fff;color:#1b1a17;font:inherit">
|
|
@@ -767,14 +769,14 @@
|
|
|
767
769
|
<input type="email" name="email" placeholder="you@example.com" required>
|
|
768
770
|
</label>
|
|
769
771
|
<button type="submit">Subscribe</button>
|
|
770
|
-
</form>`}function
|
|
772
|
+
</form>`}function Ap(e,t){let n=Ml(t);return e==="styled"?o`<form class="set-pf-styled"><span class="l">${n}</span><div class="rowf"><input type="email" placeholder="you@example.com" disabled><button type="button" class="sub-btn" tabindex="-1">Subscribe</button></div><p class="set-pf-fine">We’ll email you a link to confirm. Unsubscribe anytime.</p></form>`:o`<form class="set-pf-plain"><label>${n} <input type="email" placeholder="you@example.com" disabled></label> <button type="button" tabindex="-1">Subscribe</button></form>`}function Il(e){return e.data.deployment.app_origin||location.origin}function Hp(e){return e?"A public page with your publication\u2019s name and a sign-up form ready to go.":"A public page with a sign-up form ready to go."}function Pl(e,t,n,s,i=null){return o`<div class="set-way"><div class="set-way-head"><div class="set-way-name"><h3 class="set-way-title">${O(e)}${t}</h3><p class="set-way-line">${n}</p></div>${i}</div>${s}</div>`}function Nl(e){let t=`${Il(e)}/subscribe`;return o`
|
|
771
773
|
<section class="set-sec set-sec-subscribe">
|
|
772
774
|
${we("Ways to subscribe",ye("copyout","Copy-out"))}
|
|
773
775
|
<p class="set-lede">Two ways for readers to join your list. Either way, a reader is added only once they confirm by email.</p>
|
|
774
776
|
${e.data.deployment.provider==="none"?o`<div class="health amber set-sub-not-connected" role="status"><span class="health-dot">⚠️</span><div><span>No email provider connected, so signups aren’t open yet: the page below says so, and the form takes no address. ${Ae()} to open signups.</span></div></div>`:null}
|
|
775
777
|
<div class="set-card">
|
|
776
|
-
${
|
|
777
|
-
${
|
|
778
|
+
${Pl("link","Share the page",o`<span id="subscribePageLine"></span>`,o`<div class="set-way-body set-way-addr"><code class="set-addr">${t}</code>${Sn(t,"Copy the subscribe page\u2019s address")}<a class="ghost-link" href="${t}" target="_blank" rel="noopener">Open ↗</a></div>`)}
|
|
779
|
+
${Pl("code","Embed a form",o`Put a sign-up form on another site you own.`,o`<div class="set-embed">
|
|
778
780
|
<div class="set-embed-preview" id="embedPreview"></div>
|
|
779
781
|
<pre class="set-embed-code"><code id="embedCode"></code></pre>
|
|
780
782
|
</div>
|
|
@@ -783,23 +785,23 @@
|
|
|
783
785
|
<button type="button" class="wtog-btn" data-embed="plain" aria-pressed="false">Plain</button>
|
|
784
786
|
</span>`)}
|
|
785
787
|
</div>
|
|
786
|
-
</section>`}function
|
|
787
|
-
${
|
|
788
|
-
${
|
|
789
|
-
${
|
|
790
|
-
${
|
|
791
|
-
${
|
|
792
|
-
`),
|
|
788
|
+
</section>`}function Pp(e,t){return o`<button type="button" class="secondary set-embed-copy" data-copy="${t}" data-copy-word="Copy HTML" aria-label="Copy HTML, ${e==="styled"?"Styled":"Plain"} form">${Te(!1,"Copy HTML")}</button>`}function Ol(e,t){let n=Il(t),s=c("#embedCode",e),i=c("#embedCopy",e),a=c("#embedPreview",e),r=c("#subscribePageLine",e),l="styled",d=()=>t.state.name||t.fromDisplay,u=()=>{let h=Cp(l,d(),n);s.textContent=h,f(i,Pp(l,h)),f(a,Ap(l,d())),r.textContent=Hp(d())},m=N("[data-embed]",e);for(let h of m)h.onclick=()=>{l=h.dataset.embed==="styled"?"styled":"plain";for(let p of m)p.setAttribute("aria-pressed",String(p.dataset.embed===l));u()};je(c(".set-sec-subscribe",e)),u();let w=d();return{repaint(){d()!==w&&(w=d(),u())}}}function In(e,t){return o`<div class="set-group" data-group="${e}">${t}</div>`}function pi(e){return{name:e.name,tagline:e.tagline,address:e.address,recipients:[...e.recipients],confirmation:{...e.confirmation},notifyTo:e.notifyTo}}var Mp=(e,t)=>e.length===t.length&&e.every((n,s)=>n===t[s]),Ip=(e,t)=>e.subject===t.subject&&e.body===t.body&&e.button_label===t.button_label&&e.reassurance===t.reassurance;async function mi(e,t){oe(t,"Settings"),f(e,o`<div class="settings"><div class="page-head"><h1>Settings</h1><p class="set-lede set-page-lede">Your publication’s identity, the ways readers subscribe and the pages they land on, the email each post is sent inside, and where Kestrel tells you about your sends. Facts set when Kestrel was deployed come last, read-only.</p></div><div id="settingsBody" class="muted">Loading…</div></div>`);let n=c("#settingsBody",e),s;try{s=await T("/api/settings",{signal:t})}catch(y){ie(n,at(y),()=>ee(mi));return}let i=await _s(s.deployment,t),a=s.settings,r=a.publication,l=a.confirmation_email,d={name:r.name||"",tagline:r.tagline||"",address:r.address||"",logoUrl:r.logo_url||"",recipients:[...a.test_recipients||[]],confirmation:{subject:l.subject||"",body:l.body||"",button_label:l.button_label||"",reassurance:l.reassurance||""},notifyTo:a.notifications.to||""},u=pi(d),m=ho(s.deployment.from_address),w=()=>d.name!==u.name||d.tagline!==u.tagline||d.address!==u.address||!Mp(d.recipients,u.recipients)||!Ip(d.confirmation,u.confirmation)||d.notifyTo!==u.notifyTo,h=[],p=Fs.attach({onSave:L,onDiscard:v},t),S=()=>{},E={data:s,provider:i,state:d,saved:()=>u,fromDisplay:m,fromName:m||"Your publication",changed(){for(let y of h)y.repaint?.();p.setDirty(w())},applySaved(y){Q.appConfig={...s,settings:y},ts(),S()}};f(n,o`
|
|
789
|
+
${In("publication",[yl(E)])}
|
|
790
|
+
${In("readers",[Nl(E),dl(E),Al(we("Reader pages",ye("preview","Preview")))])}
|
|
791
|
+
${In("emails",[Sl(E),El()])}
|
|
792
|
+
${In("you",[Tl(E)])}
|
|
793
|
+
${In("deploy",[pl(E),ml(E)])}
|
|
794
|
+
`),h.push(wl(n,E,t),Ol(n,E),ul(n,E),$l(n,E),xl(n,E),Ll(n,E)),Ws(n,s.in_use,t),S=Hl(n,s.deployment,t).refresh;let C=null,H=()=>{C?.(),C=null};async function L(){H();try{let y={publication:{name:d.name,tagline:d.tagline,address:d.address},test_recipients:d.recipients,confirmation_email:d.confirmation,notifications:{to:d.notifyTo}},$=await _t(W=>T("/api/settings",{method:"PUT",json:W?{...y,remake:W}:y}),Hn("Save","Saving"),t);if(!$)return;let A=$.settings;d.name=A.publication.name,d.tagline=A.publication.tagline,d.address=A.publication.address,d.recipients=[...A.test_recipients],d.confirmation={...A.confirmation_email},d.notifyTo=A.notifications.to,u=pi(d);for(let W of h)W.reset?.();E.applySaved(A),E.changed(),U(en("Settings saved",$.remade))}catch(y){let $=y instanceof te?Op(e,y.field):null;$&&y instanceof te?(C=Ne($,at(y)),$.focus(),p.showError("Not saved: fix the field marked above.")):p.showError(at(y))}}function v(){H(),Object.assign(d,pi(u));for(let y of h)y.reset?.();E.changed()}E.changed()}var Np={"publication.name":"#setName","publication.tagline":"#setTagline","publication.address":"#setAddress",test_recipients:"#recipInput","notifications.to":"#notifyTo","confirmation_email.subject":"#ceSubject","confirmation_email.body":"#ceMessage","confirmation_email.button_label":"#ceButton","confirmation_email.reassurance":"#ceFooter"};function Op(e,t){let n=t?Np[t]:void 0,s=n?e.querySelector(n):null;return(s instanceof HTMLInputElement||s instanceof HTMLTextAreaElement)&&!s.closest("[hidden]")?s:null}var Bp="kestrel-subscribers/1",Nn="kestrel-subscribers/2",Dp=[Bp,Nn],Up=["subscribed","pending","unsubscribed","none"],fi=["double","single","unknown"],Fp=["bounce","manual"];var qp=["reader","publisher","complaint","erased"],Bl=["subscribed","unsubscribed","bounced"],jp={maxRows:1e4,maxRowsFree:1e3,maxBodyBytes:10*1024*1024,maxEvidenceBytes:500};var Dl=[{name:"email",required:!0,values:null,takes:"an email address; trimmed and lowercased before it is matched",meaning:"The address. An invalid one is still a row, counted as invalid and reported, never dropped."},{name:"status",required:!0,values:Up,takes:"one of the values",meaning:"The consent claim. `none` is a known address with no consent claim, present only to carry a suppression."},{name:"opt_in",required:!0,values:fi,takes:"one of the values",meaning:"How consent was collected. `unknown` unless the source states it."},{name:"origin",required:!0,values:null,takes:"a short lowercase name (letters, digits, `.`, `_`, `-`, up to 40): `sendy`, `mailchimp`, `kestrel`, `unknown`",meaning:"Where consent was first collected, as the file claims it."},{name:"unsubscribe_cause",required:!1,values:qp,takes:"one of the values, or empty; only on an `unsubscribed` row",meaning:"Why the person left: their own unsubscribe (`reader`), the publisher on their request (`publisher`), a complaint about the mail (`complaint`), or an erasure at their request (`erased`), which is recorded with the address alone. Empty when the source doesn\u2019t say, recorded as having left elsewhere. Version 2 only."},{name:"suppression",required:!1,values:Fp,takes:"one of the values, or empty",meaning:"A suppression on top of `status`, the sender\u2019s side: the address bounced, or was blocked by hand. In version 1 it also took `complaint`, read as an `unsubscribed` row whose cause is `complaint`, and `erased`, read as one whose cause is `erased`."},{name:"subscribed_at",required:!1,values:null,takes:"a UTC ISO-8601 instant with its zone (`2024-03-01T09:30:00Z`), or empty",meaning:"When the person subscribed, if the source states it."},{name:"confirmed_at",required:!1,values:null,takes:"an instant with its zone, or empty",meaning:"When the person confirmed, if the source states it."},{name:"unsubscribed_at",required:!1,values:null,takes:"an instant with its zone, or empty",meaning:"When the person left, if the source states it. A reader who confirmed here after it stays confirmed."},{name:"suppressed_at",required:!1,values:null,takes:"an instant with its zone, or empty",meaning:"When the address was suppressed, if the source states it."},{name:"evidence",required:!1,values:null,takes:`a JSON object of at most ${jp.maxEvidenceBytes} bytes, or empty`,meaning:"The source\u2019s consent-relevant columns, verbatim (a signup IP, a form name, a confirmation time). Nothing reads it to decide anything: it is the proof of consent and the audit trail of a conversion."},{name:"format",required:!1,values:Dp,takes:"the format\u2019s name and version, or empty",meaning:"The version the row is written in. A row without it may use either version\u2019s values, which every version reads alike; a version this release doesn\u2019t know is refused by name."}],SS=new Set(Dl.map(e=>e.name));var Wp=/^[=+\-@\t\r]/;function Vp(e){return Wp.test(e)?`'${e}`:e}function Kp(e){let t=Vp(e);return/[",\r\n]/.test(t)||t!==t.trim()?`"${t.replace(/"/g,'""')}"`:t}function hi(e){return`${e.map(t=>t.map(Kp).join(",")).join(`\r
|
|
793
795
|
`)}\r
|
|
794
|
-
`}function
|
|
796
|
+
`}function bi(e){let t=Dl.map(n=>n.name);return hi([t,...e.map(n=>t.map(s=>n[s]??""))])}var gi=[{email:"ada@example.com",status:"subscribed",opt_in:"double",origin:"sendy",unsubscribe_cause:null,suppression:null,subscribed_at:"2024-03-01T09:30:00Z",confirmed_at:"2024-03-01T09:42:00Z",unsubscribed_at:null,suppressed_at:null,evidence:'{"signup_ip":"203.0.113.7","list":"Field Notes"}',format:Nn},{email:"grace@example.com",status:"subscribed",opt_in:"single",origin:"mailchimp",unsubscribe_cause:null,suppression:null,subscribed_at:"2023-11-12T16:05:00Z",confirmed_at:null,unsubscribed_at:null,suppressed_at:null,evidence:null,format:Nn},{email:"edsger@example.com",status:"unsubscribed",opt_in:"unknown",origin:"unknown",unsubscribe_cause:"reader",suppression:null,subscribed_at:null,confirmed_at:null,unsubscribed_at:"2025-01-20T08:00:00Z",suppressed_at:null,evidence:null,format:Nn},{email:"bounced@example.com",status:"none",opt_in:"unknown",origin:"unknown",unsubscribe_cause:null,suppression:"bounce",subscribed_at:null,confirmed_at:null,unsubscribed_at:null,suppressed_at:"2025-02-02T12:00:00Z",evidence:null,format:Nn}],$S=bi(gi),vi=`ada@example.com\r
|
|
795
797
|
grace@example.com\r
|
|
796
798
|
linus@example.com\r
|
|
797
|
-
`,
|
|
799
|
+
`,Ul="kestrel-import-example.csv",yi="kestrel-import-example.txt";var Gp={buttondown:"Buttondown",convertkit:"ConvertKit",kit:"Kit",kestrel:"Kestrel",mailchimp:"Mailchimp",mailerlite:"MailerLite",sendy:"Sendy",substack:"Substack",beehiiv:"beehiiv",ghost:"Ghost"};function On(e){return e===null||e===""||e==="unknown"?null:Gp[e]??e.charAt(0).toUpperCase()+e.slice(1)}function Bn(e){return e===null||e==="unknown"?"opt-in unknown":`${e} opt-in`}function Fl(e){return e.import_id!==null?`Imported \xB7 ${[On(e.origin),Bn(e.opt_in)].filter(Boolean).join(", ")}`:e.confirmed_at!==null?"Double opt-in":null}function ql(e){if(!e)return null;try{return JSON.stringify(JSON.parse(e),null,2)}catch{return e}}function Gs(e){return e.principal.kind==="service"?"a service token":Jt(e.principal.email,e.principal.client)??"you"}var jl=(e,t,n)=>`${e.toLocaleString("en-US")} ${e===1?t:n}`,zp=[{outcome:"added_confirmed",one:"address added as a confirmed subscriber",many:"addresses added as confirmed subscribers"},{outcome:"confirmed_pending",one:"pending subscriber here confirmed",many:"pending subscribers here confirmed"},{outcome:"unsubscribed",one:"subscriber here unsubscribed",many:"subscribers here unsubscribed"},{outcome:"erased",one:"subscriber here erased, as the file says: only the address is kept, and past sends show an erased recipient",many:"subscribers here erased, as the file says: only their addresses are kept, and past sends show an erased recipient"},{outcome:"added_unsubscribed",one:"address recorded as having left (unsubscribed), so the list remembers them",many:"addresses recorded as having left (unsubscribed), so the list remembers them"},{outcome:"suppressed",one:"address suppressed as the file says (bounced or blocked), so it\u2019s never mailed",many:"addresses suppressed as the file says (bounced or blocked), so they\u2019re never mailed"},{outcome:"unchanged",one:"address already here as the file says, so it\u2019s unchanged",many:"addresses already here as the file says, so they\u2019re unchanged"},{outcome:"left_out",one:"row still pending, or with no status, left out, since an import sends no email",many:"rows still pending, or with no status, left out, since an import sends no email"},{outcome:"invalid",one:"row isn\u2019t a valid address",many:"rows aren\u2019t valid addresses"},{outcome:"merged",one:"row repeats an address earlier in the file, and is folded into it",many:"rows repeat an address earlier in the file, and are folded into it"},{outcome:"kept_suppressed",one:"address is suppressed here, so it isn\u2019t imported",many:"addresses are suppressed here, so they aren\u2019t imported",kept:!0},{outcome:"kept_unsubscribed",one:"reader unsubscribed here, and stays unsubscribed",many:"readers unsubscribed here, and stay unsubscribed",kept:!0},{outcome:"kept_confirmed_newer",one:"reader confirmed here after the file says they left, and stays confirmed",many:"readers confirmed here after the file says they left, and stay confirmed",kept:!0}];function wi(e){return zp.filter(t=>e[t.outcome]>0).map(t=>({outcome:t.outcome,count:e[t.outcome],text:jl(e[t.outcome],t.one,t.many),kept:t.kept===!0}))}function Wl(e){return e.added_confirmed+e.confirmed_pending}function Si(e,t){let n=t-e.suppressed;return n>0?`${jl(n,"of the addresses above also gains","of the addresses above also gain")} a suppression, so ${n===1?"it\u2019s":"they\u2019re"} never mailed.`:null}function Vl(e){let t=fi.filter(s=>(e.opt_in[s]??0)>0).map(s=>`${e.opt_in[s].toLocaleString("en-US")} ${Bn(s)}`).join(", "),n=Object.entries(e.origin).filter(([,s])=>s>0).sort((s,i)=>i[1]-s[1]||s[0].localeCompare(i[0])).map(([s,i])=>`${On(s)??"unknown"} ${i.toLocaleString("en-US")}`).join(", ");return{optIn:t,origin:n}}var tn={added_confirmed:"Imported as subscribed",confirmed_pending:"Imported as subscribed",unsubscribed:"Unsubscribed",erased:"Erased",added_unsubscribed:"Recorded as having left",suppressed:"Suppressed",unchanged:"Unchanged",left_out:"Left out",invalid:"Invalid",merged:"Folded into an earlier row",kept_suppressed:"Already suppressed here",kept_unsubscribed:"Kept unsubscribed",kept_confirmed_newer:"Kept confirmed"};function Kl(e,t,n){let s=new Map(e.map(r=>[r.row,r])),i=new Map(t.map(r=>[r.row,r])),a=new Map;for(let r of new Set([...s.keys(),...i.keys()])){let l=s.get(r),d=i.get(r),u=l?tn[l.outcome]:tn.added_confirmed,m=d?tn[d.outcome]:tn.added_confirmed;u!==m&&a.set(r,{row:r,email:(d??l)?.email??"",planned:u,applied:m})}for(let r of n){let l=tn[r.planned],d=tn[r.applied];!a.has(r.row)&&l!==d&&a.set(r.row,{row:r.row,email:r.email,planned:l,applied:d})}return[...a.values()].sort((r,l)=>r.row-l.row)}function Gl(e){return hi([["row","email","outcome","suppression_added"],...e.map(t=>[String(t.row),t.email,t.outcome,t.suppression_added?"yes":"no"])])}var zl="Please import my Sendy subscribers from ~/Downloads/sendy-export.csv into the newsletter.",Yp="Your list or its scheduled posts changed since this plan, so here is the plan again as things stand now. Review it, then import.",$i=["email","status","opt_in","origin","subscribed_at"],Zp={subscribed:"Subscribed",unsubscribed:"Unsubscribed",bounced:"Bounced"};async function xi(e,t){oe(t,"Import subscribers"),f(e,o`<div class="imp">
|
|
798
800
|
<div class="editor-head"><a href="#/subscribers" class="back">← Subscribers</a></div>
|
|
799
801
|
<div class="page-head"><h1>Import subscribers</h1><p class="set-lede" id="impLede">Nothing changes until you review what will happen and confirm.</p></div>
|
|
800
802
|
<div id="impBody" class="muted">Loading…</div>
|
|
801
803
|
<input type="file" id="impInput" accept=".csv,.txt,text/csv,text/plain" hidden>
|
|
802
|
-
</div>`);let n=c("#impBody",e),s=c("#impInput",e);je(n);let i;try{i=await
|
|
804
|
+
</div>`);let n=c("#impBody",e),s=c("#impInput",e);je(n);let i;try{i=await T("/api/imports/format",{signal:t})}catch(v){t.aborted||ie(n,q(v),()=>{ee(xi)});return}if(t.aborted)return;let a="full";function r(v){c("#impLede",e).hidden=!1;let y=i.limits.max_rows.toLocaleString("en-US");f(n,o`<section class="card imp-card">
|
|
803
805
|
<div class="imp-card-head"><h2>The file Kestrel reads</h2>
|
|
804
806
|
<span class="set-wtog" role="group" aria-label="Which file">
|
|
805
807
|
<button type="button" class="wtog-btn" data-sample="full" aria-pressed="${String(a==="full")}">Full list</button>
|
|
@@ -814,119 +816,119 @@ linus@example.com\r
|
|
|
814
816
|
${u()}
|
|
815
817
|
</section>
|
|
816
818
|
<div class="imp-drop" id="impDrop">
|
|
817
|
-
${
|
|
819
|
+
${O("upload")}
|
|
818
820
|
<p class="imp-drop-line">Drop your file here, or</p>
|
|
819
|
-
<button type="button" class="primary" id="impChoose" aria-describedby="impLimit${
|
|
821
|
+
<button type="button" class="primary" id="impChoose" aria-describedby="impLimit${v?" impFileError":""}">Choose file</button>
|
|
820
822
|
<p class="field-hint" id="impLimit">CSV or .txt, up to ${y} rows.${i.limits.max_rows_reason?o` ${i.limits.max_rows_reason}`:null}</p>
|
|
821
823
|
</div>
|
|
822
|
-
${
|
|
823
|
-
<p class="imp-text">Exported from another service? Claude can convert it for you. Ask Claude Code:</p>${u()}</div>`:null}`);for(let
|
|
824
|
-
<div class="table-wrap"><table class="imp-sample"><thead><tr>${
|
|
825
|
-
<tbody>${
|
|
826
|
-
<p class="field-hint">Optional columns: ${y.map((
|
|
824
|
+
${v?o`<div class="imp-file-error"><div class="field-error" id="impFileError" role="alert"><span class="field-error-ico" aria-hidden="true">!</span><span>${v}</span></div>
|
|
825
|
+
<p class="imp-text">Exported from another service? Claude can convert it for you. Ask Claude Code:</p>${u()}</div>`:null}`);for(let A of N("[data-sample]",n))A.onclick=()=>{a=A.dataset.sample==="plain"?"plain":"full";for(let W of N("[data-sample]",n))W.setAttribute("aria-pressed",String(W.dataset.sample===a));f(c("#impSample",n),a==="full"?l():d()),m()};m(),c("#impChoose",n).onclick=()=>s.click();let $=c("#impDrop",n);$.addEventListener("dragover",A=>{A.preventDefault(),$.classList.add("over")}),$.addEventListener("dragleave",()=>$.classList.remove("over")),$.addEventListener("drop",A=>{A.preventDefault(),$.classList.remove("over");let W=A.dataTransfer?.files[0];W&&w(W)})}function l(){let v=gi.slice(0,3),y=i.columns.filter($=>!$.required&&!$i.includes($.name)).map($=>$.name);return o`<p class="imp-text">A CSV with a header row, one row per address. A row says what your old service recorded about each person; Kestrel decides what that means here.</p>
|
|
826
|
+
<div class="table-wrap"><table class="imp-sample"><thead><tr>${$i.map($=>o`<th><code>${$}</code></th>`)}</tr></thead>
|
|
827
|
+
<tbody>${v.map($=>o`<tr>${$i.map(A=>o`<td>${$[A]??""}</td>`)}</tr>`)}</tbody></table></div>
|
|
828
|
+
<p class="field-hint">Optional columns: ${y.map(($,A)=>o`${A?", ":""}<code>${$}</code>`)}.</p>
|
|
827
829
|
<div class="row imp-links"><button type="button" class="ghost" data-template="csv">Download example file (CSV)</button><a class="ghost-link" href="#/docs/your-list/the-file-format">Import format reference →</a></div>`}function d(){return o`<p class="imp-text">A <code>.txt</code> file with one address per line.</p>
|
|
828
|
-
${zt(
|
|
829
|
-
`).trim()}`,
|
|
830
|
+
${zt(yi,o`${vi.replace(/\r\n/g,`
|
|
831
|
+
`).trim()}`,vi)}
|
|
830
832
|
<p class="imp-text">Next you’ll say what they are: subscribed (the default), unsubscribed, or bounced.</p>
|
|
831
|
-
<div class="row imp-links"><button type="button" class="ghost" data-template="txt">Download example file (.txt)</button></div>`}function u(){return zt("Prompt for Claude Code",o`${
|
|
833
|
+
<div class="row imp-links"><button type="button" class="ghost" data-template="txt">Download example file (.txt)</button></div>`}function u(){return zt("Prompt for Claude Code",o`${zl}`,zl)}function m(){for(let v of N("[data-template]",n))v.onclick=()=>Y(v,null,async()=>{let y=v.dataset.template==="txt"?"txt":"csv";try{let $=await es(`/api/imports/template.${y}`);kt($.text,$.filename??(y==="txt"?yi:Ul),y==="txt"?"text/plain":"text/csv")}catch($){U(q($))}})}s.onchange=()=>{let v=s.files?.[0];s.value="",v&&w(v)};async function w(v){let y=await v.text();if(t.aborted)return;let $={name:v.name,text:y},A=Jp($)?i.plain_list.default:null,W=n.querySelector("#impChoose, #impReplace"),z=await(W?Y(W,"Reading\u2026",()=>h($,A)):h($,A));z!==null&&(p(z,$),c(".imp-file",n).focus())}async function h(v,y){try{return await T("/api/imports/plan",{method:"POST",json:y===null?{file:v}:{file:v,plain_list_status:y},signal:t})}catch($){return t.aborted||(r(q($)),c("#impChoose",n).focus()),null}}function p(v,y,$){let A=Wl(v.counts),W=wi(v.counts),z=Vl(v.confirmed),G=Si(v.counts,v.suppressions_added),b=v.rows.length,k=v.file.kind==="txt"?"Plain list (.txt)":`CSV, ${i.format}`;f(n,o`<section class="card imp-card imp-file" tabindex="-1" aria-label="The file chosen and its plan">
|
|
832
834
|
<div class="imp-file-row">
|
|
833
|
-
<div><strong class="imp-file-name">${
|
|
835
|
+
<div><strong class="imp-file-name">${v.file.name}</strong><div class="muted">${k} · ${Ei(v.file.rows)} · ${Qp(v.file.addresses)}</div></div>
|
|
834
836
|
<button type="button" class="ghost" id="impReplace">Replace file</button>
|
|
835
837
|
</div>
|
|
836
|
-
${
|
|
838
|
+
${v.file.kind==="txt"?S(v.file.plain_list_status??i.plain_list.default):null}
|
|
837
839
|
</section>
|
|
838
840
|
<section class="card imp-card">
|
|
839
841
|
<h2>What will happen</h2>
|
|
840
|
-
${
|
|
841
|
-
${
|
|
842
|
-
${
|
|
843
|
-
${
|
|
842
|
+
${Zl(W,z,A)}
|
|
843
|
+
${G?o`<p class="imp-text">${G}</p>`:null}
|
|
844
|
+
${b>0?o`<div class="row imp-links"><button type="button" class="ghost" id="impNotImported">Download the ${Ei(b)} not imported as subscribed (CSV)</button></div>`:null}
|
|
845
|
+
${v.workers_plan_advice?o`<p class="workers-plan" role="status">${v.workers_plan_advice}</p>`:null}
|
|
844
846
|
</section>
|
|
845
847
|
<section class="card imp-card imp-confirm">
|
|
846
848
|
<h2>Confirm</h2>
|
|
847
|
-
${
|
|
848
|
-
${
|
|
849
|
-
${
|
|
850
|
-
<p class="field-hint imp-attest-hint">Only import people who asked to receive ${
|
|
851
|
-
${
|
|
852
|
-
${
|
|
849
|
+
${v.sends_growing.length>0?o`<p class="imp-text">A scheduled post goes to the list as it stands when it sends, so this import adds to its audience. Acknowledge each one.</p>
|
|
850
|
+
${v.sends_growing.map(B=>o`<label class="imp-check"><input type="checkbox" data-ack="${B.id}"><span>“${B.subject||"Untitled"}”, sending ${K(B.fire_at)}, goes to ${B.gains.toLocaleString("en-US")} more ${B.gains===1?"person":"people"}.</span></label>`)}`:null}
|
|
851
|
+
${v.attestation?o`<label class="imp-check"><input type="checkbox" id="impAttest"><span>${v.attestation.text}</span></label>
|
|
852
|
+
<p class="field-hint imp-attest-hint">Only import people who asked to receive ${v.attestation.publication}. If you’re unsure about some, take them out of the file before importing.</p>`:null}
|
|
853
|
+
${v.attestation===null&&v.sends_growing.length===0?o`<p class="imp-text">Nobody is imported as a subscriber, so there’s nothing to attest.</p>`:null}
|
|
854
|
+
${$?Yl($):null}
|
|
853
855
|
<div class="actions imp-actions"><a class="ghost-link" href="#/subscribers">Cancel</a><button type="button" class="primary" id="impGo">Import</button></div>
|
|
854
|
-
</section>`);let
|
|
856
|
+
</section>`);let R=c("#impReplace",n);R.onclick=()=>s.click(),b>0&&(c("#impNotImported",n).onclick=()=>E(v.file.name,v.rows));let x=c("#impGo",n),F=N("[data-plain]",n),P=B=>{R.disabled=B;for(let ne of F)ne.disabled=B};for(let B of F)B.onclick=()=>{let ne=B.dataset.plain;ne!==v.file.plain_list_status&&(x.disabled=!0,P(!0),(async()=>{let j=await h(y,ne);j&&!t.aborted&&(p(j,y),c(`[data-plain="${ne}"]`,n).focus())})())};x.onclick=()=>I(v,y,x,P)}function S(v){return o`<div class="imp-plain">
|
|
855
857
|
<span class="imp-plain-label" id="impPlainLabel">These addresses are</span>
|
|
856
|
-
<span class="set-wtog" role="group" aria-labelledby="impPlainLabel">${
|
|
858
|
+
<span class="set-wtog" role="group" aria-labelledby="impPlainLabel">${Bl.map(y=>o`<button type="button" class="wtog-btn" data-plain="${y}" aria-pressed="${String(y===v)}">${Zp[y]}</button>`)}</span>
|
|
857
859
|
<p class="field-hint">A plain list doesn’t say how each person joined, so it’s recorded as unknown.</p>
|
|
858
|
-
</div>`}function
|
|
859
|
-
<h2 id="impDoneHead" tabindex="-1">${
|
|
860
|
-
${
|
|
861
|
-
${
|
|
860
|
+
</div>`}function E(v,y){let $=v.replace(/\.(csv|txt)$/i,"");kt(Gl(y),`${$}-not-imported.csv`,"text/csv")}async function I(v,y,$,A){n.querySelector(".imp-act-error")?.remove();let W=N("[data-ack]",n),z=n.querySelector("#impAttest");for(let G of W)if(!G.checked){C(G,"Tick this to acknowledge that this post will go to the people this import adds.");return}if(z&&!z.checked){C(z,"Tick this to attest that everyone you\u2019re importing as subscribed opted in.");return}A(!0),await Y($,"Importing\u2026",async()=>{try{let G=await T("/api/imports",{method:"POST",json:{file:y,plain_list_status:v.file.plain_list_status??void 0,plan_hash:v.plan_hash,...v.attestation?{attestation:{version:v.attestation.version,accepted:!0}}:{},acknowledge_sends:v.sends_growing.map(b=>b.id)}});t.aborted||L(G,v)}catch(G){if(t.aborted)return;if(G instanceof te&&G.code==="plan_stale"){let b=await h(y,v.file.plain_list_status);b&&!t.aborted&&(p(b,y,Yp),c(".imp-act-error",n).focus());return}H(q(G)),A(!1)}})}function C(v,y){Ne(v,y,{after:v.closest("label")??v}),v.focus()}function H(v){n.querySelector(".imp-act-error")?.remove();let y=document.createElement("div");f(y,Yl(v)),c(".imp-actions",n).before(...y.childNodes)}function L(v,y){c("#impLede",e).hidden=!0;let $=v.import,A=Gs($),W=wi(v.counts),z=Si(v.counts,v.suppressions_added),G=v.replayed?[]:Kl(y.rows,v.rows,v.differed);f(n,o`<section class="card imp-card imp-done">
|
|
861
|
+
<h2 id="impDoneHead" tabindex="-1">${v.replayed?"This import was already done":"Import done"}</h2>
|
|
862
|
+
${v.replayed?o`<p class="imp-text">This plan was already imported, so nothing was written again. Here is its record.</p>`:null}
|
|
863
|
+
${Zl(W,null,0)}
|
|
862
864
|
${z?o`<p class="imp-text">${z}</p>`:null}
|
|
863
865
|
<p class="imp-text imp-nobody">Nobody was emailed. To tell your readers about the move, write a post as usual.</p>
|
|
864
866
|
</section>
|
|
865
|
-
${
|
|
867
|
+
${G.length>0?o`<section class="card imp-card imp-differed">
|
|
866
868
|
<h2>Rows that turned out differently</h2>
|
|
867
|
-
<p class="imp-text">Your list changed between the plan and the import, so ${
|
|
868
|
-
<div class="table-wrap"><table class="imp-ref"><thead><tr><th>Row</th><th>Email</th><th>Planned</th><th>Applied</th></tr></thead><tbody>${
|
|
869
|
+
<p class="imp-text">Your list changed between the plan and the import, so ${Ei(G.length)} had a different result. Each was applied to the list as it stood.</p>
|
|
870
|
+
<div class="table-wrap"><table class="imp-ref"><thead><tr><th>Row</th><th>Email</th><th>Planned</th><th>Applied</th></tr></thead><tbody>${G.map(b=>o`<tr><td>${String(b.row)}</td><td>${b.email}</td><td>${b.planned}</td><td>${b.applied}</td></tr>`)}</tbody></table></div>
|
|
869
871
|
</section>`:null}
|
|
870
872
|
<section class="card imp-card imp-record">
|
|
871
873
|
<h2>The import’s record</h2>
|
|
872
874
|
<dl class="imp-dl">
|
|
873
|
-
<dt>File</dt><dd>${
|
|
874
|
-
<dt>Fingerprint</dt><dd><code>${
|
|
875
|
-
<dt>Imported</dt><dd>${
|
|
876
|
-
<dt>Attestation</dt><dd>${
|
|
875
|
+
<dt>File</dt><dd>${$.file_name}</dd>
|
|
876
|
+
<dt>Fingerprint</dt><dd><code>${$.file_sha256.slice(0,16)}</code></dd>
|
|
877
|
+
<dt>Imported</dt><dd>${K($.created_at)} by ${A}</dd>
|
|
878
|
+
<dt>Attestation</dt><dd>${$.attestation_version===null?"None needed: nobody was imported as a subscriber.":y.attestation?o`“${y.attestation.text}” <span class="muted">(version ${String($.attestation_version)})</span>`:`Version ${$.attestation_version}`}</dd>
|
|
877
879
|
</dl>
|
|
878
880
|
<div class="actions imp-actions"><button type="button" class="ghost" id="impAnother">Import another file</button><button type="button" class="primary" id="impToList">See your subscribers</button></div>
|
|
879
|
-
</section>`),c("#impAnother",n).onclick=()=>{r(),c("#impChoose",n).focus()},c("#impToList",n).onclick=()=>{location.hash="#/subscribers"},c("#impDoneHead",n).focus()}r()}function
|
|
880
|
-
${i.length>0?o`<p class="imp-kept-head">Kept as they are here</p><ul class="imp-outcomes imp-kept">${i.map(r=>o`<li data-outcome="${r.outcome}"><span>${r.text}</span></li>`)}</ul>`:null}`}function
|
|
881
|
+
</section>`),c("#impAnother",n).onclick=()=>{r(),c("#impChoose",n).focus()},c("#impToList",n).onclick=()=>{location.hash="#/subscribers"},c("#impDoneHead",n).focus()}r()}function Yl(e){return o`<div class="field-error imp-act-error" role="alert" tabindex="-1"><span class="field-error-ico" aria-hidden="true">!</span><span>${e}</span></div>`}function Jp(e){return e.name.trim().toLowerCase().endsWith(".txt")}function Ei(e){return`${e.toLocaleString("en-US")} ${e===1?"row":"rows"}`}function Qp(e){return`${e.toLocaleString("en-US")} ${e===1?"address":"addresses"}`}function Zl(e,t,n){let s=e.filter(r=>!r.kept),i=e.filter(r=>r.kept),a=s.find(r=>r.outcome==="added_confirmed"||r.outcome==="confirmed_pending")?.outcome;return o`<ul class="imp-outcomes">${s.map(r=>o`<li data-outcome="${r.outcome}"><span>${r.text}</span>${r.outcome===a&&t&&n>0?o`<div class="field-hint imp-breakdown">Of the ${n.toLocaleString("en-US")} confirmed, by opt-in: ${t.optIn}. From: ${t.origin}.</div>`:null}</li>`)}</ul>
|
|
882
|
+
${i.length>0?o`<p class="imp-kept-head">Kept as they are here</p><ul class="imp-outcomes imp-kept">${i.map(r=>o`<li data-outcome="${r.outcome}"><span>${r.text}</span></li>`)}</ul>`:null}`}function Xp(e){return e.suppression&&qe[e.suppression.reason]||"suppressed"}function zs(e){return e.suppression?o` <span class="badge suppressed row-flag">${Xp(e)}</span>`:null}function Ys(e){return e.suppression?o`<span class="badge ${e.status} held">${e.status}</span>`:Je(e.status)}function Jl(e){let t=e.lastIndexOf("@");return t>0?o`${e.slice(0,t)}<wbr>${e.slice(t)}`:o`${e}`}function Dn(e){return e.status==="unsubscribed"&&e.unsubscribe_cause==="erased"}function Zs(e){return`#/subscribers/${e}`}function Js(e,t,n){let s=[];return e.status!=="unsubscribed"&&s.push({label:it.unsubscribe.label,danger:!0,onClick:()=>ea(e,t,n)}),e.suppression?e.suppression.reason==="manual"?s.push({label:it.unblock.label,onClick:()=>na(e,t,n)}):qe[e.suppression.reason]==="bounced"&&s.push({label:it.clear.label,danger:!0,onClick:()=>oa(e,t,n)}):s.push({label:it.block.label,danger:!0,onClick:()=>ta(e,t,n)}),Dn(e)||s.push({label:it.erase.label,danger:!0,onClick:()=>ia(e,t,n)}),s}async function em(){let e=[],t=null,n=Date.now();do{let s=t===null?"":`?after=${encodeURIComponent(t)}`,i=await T(`/api/subscribers/export${s}`);if(i.next!==null&&i.next===t)throw new Error("The export repeated a page. Try again.");e.push(...i.subscribers),n=i.exported_at,t=i.next}while(t!==null);return{rows:e,exportedAt:n}}async function Ql(){let{rows:e,exportedAt:t}=await em();return{name:`kestrel-subscribers-${new Date(t).toISOString().slice(0,10)}.csv`,text:bi(e)}}var Xl=[{value:"confirmed",label:"Confirmed"},{value:"pending",label:"Pending"},{value:"unsubscribed",label:"Unsubscribed"}],Ti=["confirmed","pending","unsubscribed","suppressed"];async function ec(e,t,n){oe(n,"Subscribers");let s={status:"",search:"",suppressed:"",sort:"created_at",dir:"desc",offset:0,limit:50};e==="suppressed"?s.suppressed="only":e&&Ti.includes(e)&&(s.status=e),f(t,o`
|
|
881
883
|
<div class="spread page-head"><h1>Subscribers</h1><span class="row"><button type="button" class="ghost" id="importSubs">Import</button><button type="button" class="ghost" id="exportSubs">Export</button><button class="primary" id="addSub">Add subscriber</button></span></div>
|
|
882
|
-
<div class="card sub-summary"><div class="sub-summary-head"><div id="subCounts" class="row muted" role="group" aria-label="Show">Loading…</div><button type="button" class="sub-legend-toggle" id="subLegendToggle" aria-expanded="false" aria-controls="subLegend">Legend</button></div><p class="workers-plan" id="subWorkersPlan" role="status" hidden></p>${
|
|
883
|
-
${jt({statuses:
|
|
884
|
+
<div class="card sub-summary"><div class="sub-summary-head"><div id="subCounts" class="row muted" role="group" aria-label="Show">Loading…</div><button type="button" class="sub-legend-toggle" id="subLegendToggle" aria-expanded="false" aria-controls="subLegend">Legend</button></div><p class="workers-plan" id="subWorkersPlan" role="status" hidden></p>${om()}</div>
|
|
885
|
+
${jt({statuses:Xl,suppressible:!0,searchPlaceholder:"Search email\u2026"})}
|
|
884
886
|
<div id="subList" class="muted">Loading…</div>
|
|
885
|
-
<div id="subPager"></div>`);let i=c("#subList"),a=c("#subPager");async function r(){try{let u=await
|
|
887
|
+
<div id="subPager"></div>`);let i=c("#subList"),a=c("#subPager");async function r(){try{let u=await T(`/api/subscribers?${qt(s)}`,{signal:n}),m=u.counts;nm(c("#subCounts"),m,s);let w=c("#subWorkersPlan");w.hidden=!u.workers_plan_advice,w.textContent=u.workers_plan_advice??"";let h=m.pending+m.confirmed+m.unsubscribed===0;im(i,u.subscribers,s,r,n,h),ot(a,s,u.page,r)}catch(u){ie(i,q(u),r)}}sm(t,s,r);let l=c("#subLegendToggle");l.onclick=()=>{let u=l.getAttribute("aria-expanded")!=="true";l.setAttribute("aria-expanded",String(u)),c("#subLegend").hidden=!u},c("#addSub").onclick=()=>Ls(r,n),c("#importSubs").onclick=()=>{location.hash="#/subscribers/import"};let d=c("#exportSubs");d.onclick=()=>Y(d,"Exporting\u2026",async()=>{try{let u=await Ql();kt(u.text,u.name,"text/csv")}catch(u){U(q(u))}}),Wt(t,s,r),r()}var tm=["confirmed","pending","unsubscribed","suppressed"];function _i(e,t){return e.search?!1:t==="suppressed"?e.suppressed==="only"&&!e.status:e.status===t&&!e.suppressed}function nm(e,t,n){e.querySelector("[data-filter]")||f(e,o`${tm.map(s=>o`<button type="button" class="sub-count" data-filter="${s}" aria-pressed="false"></button>`)}`);for(let s of N("[data-filter]",e)){let i=s.dataset.filter;f(s,o`${i==="confirmed"?o`<strong>${t[i]}</strong>`:t[i]} ${i}`),s.setAttribute("aria-pressed",String(_i(n,i)))}}function sm(e,t,n){let s=c("#subCounts",e);s.onclick=i=>{let a=i.target instanceof Element?i.target.closest("[data-filter]"):null;if(!a)return;let r=a.dataset.filter,l=!_i(t,r);t.status=l&&r!=="suppressed"?r:"",t.suppressed=l&&r==="suppressed"?"only":"",t.search="",t.offset=0,c(".lt-search",e).value="",c(".lt-status",e).value=t.status,c(".lt-suppressed",e).checked=t.suppressed==="only";for(let d of N("[data-filter]",s))d.setAttribute("aria-pressed",String(_i(t,d.dataset.filter)));n()}}function ki(e,t){return o`<dt>${e}</dt><dd>${t}</dd>`}function om(){let e=Object.keys(wn);return o`<div class="sub-legend" id="subLegend" role="region" aria-labelledby="subLegendToggle" hidden><div class="sub-legend-body">
|
|
886
888
|
<h2>Status</h2>
|
|
887
|
-
<dl>${
|
|
889
|
+
<dl>${Xl.map(({value:t})=>ki(Je(t),t==="unsubscribed"?`${Mo[t]} Why they left is on their page.`:Mo[t]))}</dl>
|
|
888
890
|
<h2>Suppressed</h2>
|
|
889
|
-
<p>${
|
|
890
|
-
<dl>${e.map(t=>
|
|
891
|
+
<p>${Xr} The red flag beside the address says why:</p>
|
|
892
|
+
<dl>${e.map(t=>ki(o`<span class="badge suppressed">${t}</span>`,wn[t]))}</dl>
|
|
891
893
|
<h2>What you can do</h2>
|
|
892
|
-
<dl>${Object.values(it).map(({label:t,when:n})=>
|
|
893
|
-
</div></div>`}function
|
|
894
|
+
<dl>${Object.values(it).map(({label:t,when:n})=>ki(o`<strong class="sub-legend-act">${t}</strong>`,n))}</dl>
|
|
895
|
+
</div></div>`}function im(e,t,n,s,i,a){if(!t.length){f(e,a?o`<p class="muted">No subscribers yet. <a href="#/subscribers/import">Import your list</a> from another service, or share your subscribe page.</p>`:o`<p class="muted">No subscribers match.</p>`);return}f(e,o`<div class="table-wrap subs-wrap"><table class="list-table subs-table stacks has-actions"><colgroup><col><col class="c-status"><col class="c-date"><col class="c-act"></colgroup><thead><tr>${$e("Email","email",n)}${$e("Status",null,n)}${$e("Joined","created_at",n)}<th></th></tr></thead><tbody>${t.map(r=>o`<tr class="clickable" data-id="${r.id}"><td><a class="sub-email" href="${Zs(r.id)}">${Jl(r.email)}</a>${zs(r)}</td><td>${Ys(r)}</td><td class="muted joined">${K(r.created_at)}</td><td class="act"><button class="icon" data-menu="${r.id}" aria-label="Subscriber actions" aria-haspopup="menu">⋯</button></td></tr>`)}</tbody></table></div>`),st(e,n,s);for(let r of N("tr[data-id]",e))r.onclick=l=>{l.target instanceof Element&&l.target.closest("a, button")||(location.hash=Zs(r.dataset.id??""))};for(let r of N("[data-menu]",e))r.onclick=l=>{l.stopPropagation();let d=t.find(m=>m.id===r.dataset.menu);if(!d)return;let u=[{label:"View subscriber",onClick:()=>{location.hash=Zs(d.id)}},...Js(d,s,i)];Kt(r,u,i)}}var Qs=o`<div class="editor-head"><a href="#/subscribers" class="back">← Subscribers</a></div>`;async function tc(e,t,n){oe(n,"Subscriber"),f(t,o`${Qs}<p class="muted">Loading…</p>`);let s=`/api/subscribers/${encodeURIComponent(e)}`;async function i(r){let l,d,u;try{let m=T(s,{signal:n}),w=m.then(({subscriber:E})=>E.import_id===null?null:T(`/api/imports/${encodeURIComponent(E.import_id)}`,{signal:n}).then(I=>I.import,()=>null)),[h,p,S]=await Promise.all([m,T(`${s}/deliveries`,{signal:n}),w]);l=h.subscriber,d=p,u=S}catch(m){let w=document.createElement("div");f(t,Qs),t.append(w),ie(w,q(m),()=>{f(t,o`${Qs}<p class="muted">Loading…</p>`),i(!1)});return}n.aborted||(a(l,d,u),r&&c("h1.sub-title",t).focus())}function a(r,l,d){let u=Js(r,()=>{i(!0)},n),m=Dn(r);f(t,o`${Qs}
|
|
894
896
|
<div class="spread page-head sub-page-head">
|
|
895
|
-
<div class="sub-page-title"><h1 class="sub-title" tabindex="-1">${r.email}</h1><span class="sub-pills">${
|
|
896
|
-
<span class="row sub-acts">${u.map((p,
|
|
897
|
+
<div class="sub-page-title"><h1 class="sub-title" tabindex="-1">${r.email}</h1><span class="sub-pills">${Ys(r)}${zs(r)}</span></div>
|
|
898
|
+
<span class="row sub-acts">${u.map((p,S)=>o`<button type="button" class="${p.danger?"danger-subtle":""}" data-act="${S}">${p.label}…</button>`)}</span>
|
|
897
899
|
</div>
|
|
898
|
-
<p class="sub-receives${r.receives_posts?" yes":""}">${
|
|
899
|
-
${
|
|
900
|
-
${
|
|
901
|
-
${r.unsubscribe_cause?
|
|
900
|
+
<p class="sub-receives${r.receives_posts?" yes":""}">${rm(r)}</p>
|
|
901
|
+
${m?null:am(r,d)}
|
|
902
|
+
${lm(r)}
|
|
903
|
+
${r.unsubscribe_cause?um(r):null}
|
|
902
904
|
<section class="sub-sec sub-sends" aria-labelledby="subSendsTitle">
|
|
903
905
|
<h2 class="rec-part-title" id="subSendsTitle">Sends</h2>
|
|
904
906
|
<div id="subSends"></div>
|
|
905
907
|
<div id="subMore"></div>
|
|
906
|
-
</section>`);for(let p of
|
|
908
|
+
</section>`);for(let p of N("[data-act]",t))p.onclick=()=>u[Number(p.dataset.act)]?.onClick();let w=t.querySelector("#subComplaint");pm(t,s,l,m,n,p=>{let S=p.find(E=>E.delivery.event==="complained");w?.hidden&&S&&(f(w,o`The report was about <a href="#/sent/${S.send.id}">${S.send.subject||"an untitled post"}</a>.`),w.hidden=!1)})}await i(!1)}function rm(e){if(e.receives_posts)return"Receives your posts.";let t=[];return e.status==="pending"?t.push("they haven\u2019t confirmed"):e.status==="unsubscribed"&&t.push(`they left the list on ${K(e.unsubscribed_at)}`),e.suppression&&t.push(qe[e.suppression.reason]==="bounced"?"the address bounced":"the address is blocked"),t.length>0?`Not sent your posts: ${t.join(", and ")}.`:"Not sent your posts."}function We(e,t){return o`<dt>${e}</dt><dd>${t}</dd>`}function am(e,t){let n=ql(e.consent_evidence),s=Fl(e)??(e.status==="pending"?"Signed up here, not confirmed yet":"Signed up here, never confirmed");return o`<section class="card sub-sec" aria-labelledby="subJoinedTitle">
|
|
907
909
|
<h2 class="rec-part-title" id="subJoinedTitle">How they joined</h2>
|
|
908
910
|
<dl class="sub-dl">
|
|
909
911
|
${We("How they joined",s)}
|
|
910
|
-
${e.import_id!==null?o`${We("Origin",
|
|
911
|
-
${We("Opt-in",
|
|
912
|
+
${e.import_id!==null?o`${We("Origin",On(e.origin)??"Unknown")}
|
|
913
|
+
${We("Opt-in",Bn(e.opt_in))}
|
|
912
914
|
${t?o`${We("Import",o`<code>${t.file_name}</code>`)}
|
|
913
|
-
${We("Imported",`${
|
|
915
|
+
${We("Imported",`${K(t.created_at)}, by ${Gs(t)}`)}
|
|
914
916
|
${We("Attestation",t.attestation_version===null?"None: the import confirmed no one":`Version ${t.attestation_version}`)}`:null}`:null}
|
|
915
|
-
${We("Joined",
|
|
916
|
-
${We("Confirmed",
|
|
917
|
+
${We("Joined",K(e.created_at))}
|
|
918
|
+
${We("Confirmed",K(e.confirmed_at))}
|
|
917
919
|
${We("Evidence",n?o`<pre class="sub-evidence">${n}</pre>`:"None recorded")}
|
|
918
920
|
</dl>
|
|
919
921
|
${e.import_id!==null?o`<p class="sub-note">The origin, opt-in, confirmation date, and evidence are what the imported file said, not something Kestrel recorded itself.</p>`:null}
|
|
920
|
-
</section>`}function
|
|
921
|
-
<p class="sub-meaning">${
|
|
922
|
+
</section>`}function lm(e){let t=e.suppression,n;if(!t)n=o`<p class="muted">None.</p>`;else{let s=qe[t.reason];n=o`<p class="sub-sup-line"><span class="badge suppressed">${s}</span> <span class="muted">since ${K(t.created_at)}</span></p>
|
|
923
|
+
<p class="sub-meaning">${dm(e,t.reason)}</p>
|
|
922
924
|
${t.detail?o`<dl class="sub-dl">${We("Detail",t.detail)}</dl>`:null}`}return o`<section class="card sub-sec" aria-labelledby="subSupTitle">
|
|
923
925
|
<h2 class="rec-part-title" id="subSupTitle">Suppression</h2>
|
|
924
926
|
${n}
|
|
925
|
-
</section>`}var
|
|
927
|
+
</section>`}var cm={reader:"They had unsubscribed themselves, from the link or the button in your email.",publisher:"You had unsubscribed them, when they asked you to.",complaint:"They had reported your email as spam.",erased:"You had erased them at their request.",import:"The list you imported said they had left."};function dm(e,t){switch(t){case"bounce":return"Your email provider reported that mail to this address failed. You can clear it.";case"import_bounce":return"Mail to this address failed at the service your list was imported from. You can clear it.";default:return e.import_id===null&&!Dn(e)?"You blocked this address. You can unblock it.":wn[qe[t]]}}function um(e){let t=e.unsubscribe_cause;if(!t)return null;let n=e.status!=="unsubscribed";return o`<section class="card sub-sec" aria-labelledby="subLeftTitle">
|
|
926
928
|
<h2 class="rec-part-title" id="subLeftTitle">${n?"Left before":"Why they left"}</h2>
|
|
927
|
-
<p class="sub-left-line"><span class="muted">Left ${
|
|
928
|
-
<p class="sub-meaning">${n?
|
|
929
|
+
<p class="sub-left-line"><span class="muted">Left ${K(e.unsubscribed_at)}</span></p>
|
|
930
|
+
<p class="sub-meaning">${n?cm[t]:Qr[t]}</p>
|
|
929
931
|
${t==="complaint"?o`<p class="sub-meaning" id="subComplaint" hidden></p>`:null}
|
|
930
932
|
${e.status==="pending"?o`<p class="sub-meaning">They signed up again, and haven’t confirmed yet.</p>`:null}
|
|
931
|
-
</section>`}function
|
|
933
|
+
</section>`}function pm(e,t,n,s,i,a){let r=c("#subSends",e),l=c("#subMore",e);if(n.deliveries.length===0){f(r,s?o`<p class="muted">Their past sends show an erased recipient in place of the address, so none is listed here.</p>`:o`<p class="muted">Not in any send yet.</p>`);return}f(r,o`<div class="table-wrap"><table class="list-table sub-sends-table"><colgroup><col><col class="c-out"><col><col class="c-date"></colgroup><thead><tr><th>Send</th><th class="c-out">Outcome</th><th>Detail</th><th class="c-date">When</th></tr></thead><tbody></tbody></table></div>`);let d=c("tbody",r),u=w=>{a(w.deliveries);let h=document.createElement("tbody");f(h,o`${w.deliveries.map(fm)}`),d.append(...h.childNodes),m(w.next)},m=w=>{if(!w){f(l,o``);return}f(l,o`<button type="button" class="sub-more">Show more</button>`);let h=c(".sub-more",l);h.onclick=()=>Y(h,"Loading\u2026",async()=>{try{u(await T(`${t}/deliveries?after=${encodeURIComponent(w)}`,{signal:i}))}catch(p){ie(l,q(p),()=>m(w))}})};u(n)}var mm="Left out: unsubscribed or suppressed before it went";function fm({send:e,delivery:t}){let n=Ds(t),s=t.error||t.event_detail||(t.event===null&&t.status==="skipped"?mm:"");return o`<tr><td class="sub-send"><a href="#/sent/${e.id}">${e.subject||o`<em>untitled</em>`}</a><div class="muted">${K(e.fire_at)}</div></td><td><span class="rec-out"><span class="rec-sw sw-${n.sw}"></span>${n.label}</span></td><td class="muted">${s||"\u2014"}</td><td class="muted">${t.event_at?K(t.event_at):"\u2014"}</td></tr>`}var hm="You have unsaved changes. Leave without saving?",Li="";function Ri(){let e=location.hash||"#/dashboard";(e==="#/reference"||e.startsWith("#/reference/"))&&(e=`#/api-reference${e.slice(11)}`,history.replaceState(history.state,"",e)),Li=e;let[,t,n,s]=($o(e.slice(1))?e:"#/dashboard").split("/");document.body.classList.toggle("editor-mode",t==="edit");let i=t==="web"?Ba(n,s):null;document.body.classList.toggle("web-mode",i!==null);let a=t==="docs"||t==="api-reference";document.body.classList.toggle("tool-mode",a);for(let r of document.querySelectorAll(".sidebar a[data-view]"))r.dataset.view===t?r.setAttribute("aria-current","page"):r.removeAttribute("aria-current");return an(!1),t==="edit"&&n?ee((r,l)=>Wo(n,r,l)):i!==null?ee((r,l)=>jo(i,r,l)):t==="drafts"?ee(Co):t==="subscribers"&&n==="import"?ee(xi):t==="subscribers"&&n&&!Ti.includes(n)?ee((r,l)=>tc(n,r,l)):t==="subscribers"?ee((r,l)=>ec(n,r,l)):t==="sent"?n?ee((r,l)=>ni(n,r,l)):ee(ti):t==="template"?ee(li):t==="settings"?ee(mi):t==="api-reference"?ee((r,l)=>ei(r,l,n)):t==="docs"?ee((r,l)=>Ko(n,r,l,s)):ee(No)}function nc(){let e=Ir(location.search);if(e){let t=new URL(location.href);t.search="",t.hash=e,history.replaceState(null,"",t)}}function sc(){window.addEventListener("hashchange",()=>{if(location.hash!==Li){if(Gn()?.beforeLeave?.()==="confirm"&&!confirm(hm)){location.hash=Li;return}Ri()}}),window.addEventListener("beforeunload",e=>{Gn()?.dirty?.()&&(e.preventDefault(),e.returnValue="")}),window.addEventListener("keydown",e=>{let t=Gn()?.manualSave;(e.metaKey||e.ctrlKey)&&e.key.toLowerCase()==="s"&&t&&(e.preventDefault(),t())})}async function bm(){Oi(),Gr(),Mr(),sc();let e=await Ki();if(e){Q.session=e,Vi();try{Q.appConfig=await T("/api/settings")}catch{}return ts(),document.body.classList.remove("signed-out"),nc(),Ri()}}bm().catch(e=>{document.body.classList.contains("signed-out")&&!ue.querySelector(".auth-wall")&&cn(),reportError(e)});})();
|
|
932
934
|
//# sourceMappingURL=app.js.map
|