kempo 4.7.0 → 4.9.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/README.md +10 -4
- package/bin/cli.js +38 -34
- package/dist/admin/components/EmailTemplates.js +25 -0
- package/dist/admin/components/EmailTemplates.js.map +1 -0
- package/dist/admin/components/Emails.js +49 -0
- package/dist/admin/components/Emails.js.map +1 -0
- package/dist/admin/components/Updates.js +117 -0
- package/dist/admin/components/Updates.js.map +1 -0
- package/dist/admin/components/settings/AdminSettings.js +7 -0
- package/dist/admin/components/settings/AdminSettings.js.map +1 -0
- package/dist/admin/components/settings/BooleanSetting.js +2 -0
- package/dist/admin/components/settings/BooleanSetting.js.map +1 -0
- package/dist/admin/components/settings/JsonSetting.js +2 -0
- package/dist/admin/components/settings/JsonSetting.js.map +1 -0
- package/dist/admin/components/settings/NumberSetting.js +2 -0
- package/dist/admin/components/settings/NumberSetting.js.map +1 -0
- package/dist/admin/components/settings/SecretSetting.js +2 -0
- package/dist/admin/components/settings/SecretSetting.js.map +1 -0
- package/dist/admin/components/settings/Setting.js +2 -0
- package/dist/admin/components/settings/Setting.js.map +1 -0
- package/dist/admin/components/settings/SettingEditor.js +2 -0
- package/dist/admin/components/settings/SettingEditor.js.map +1 -0
- package/dist/admin/components/settings/SettingsPanel.js +24 -0
- package/dist/admin/components/settings/SettingsPanel.js.map +1 -0
- package/dist/admin/components/settings/StringSetting.js +2 -0
- package/dist/admin/components/settings/StringSetting.js.map +1 -0
- package/dist/admin/components/settings/humanize.js +2 -0
- package/dist/admin/components/settings/humanize.js.map +1 -0
- package/dist/admin/emails/index.page.html +14 -0
- package/dist/admin/icons/mail.svg +1 -0
- package/dist/admin/nav.fragment.html +12 -0
- package/dist/admin/settings/[owner]/[name]/index.page.html +1 -1
- package/dist/admin/settings/index.page.html +6 -289
- package/dist/admin/updates/index.page.html +14 -0
- package/dist/kempo/api/email-templates/GET.js +2 -0
- package/dist/kempo/api/email-templates/GET.js.map +1 -0
- package/dist/kempo/api/email-templates/file/DELETE.js +2 -0
- package/dist/kempo/api/email-templates/file/DELETE.js.map +1 -0
- package/dist/kempo/api/email-templates/file/GET.js +2 -0
- package/dist/kempo/api/email-templates/file/GET.js.map +1 -0
- package/dist/kempo/api/email-templates/file/PUT.js +2 -0
- package/dist/kempo/api/email-templates/file/PUT.js.map +1 -0
- package/dist/kempo/api/email-templates/preview/GET.js +2 -0
- package/dist/kempo/api/email-templates/preview/GET.js.map +1 -0
- package/dist/kempo/api/emails/GET.js +2 -0
- package/dist/kempo/api/emails/GET.js.map +1 -0
- package/dist/kempo/api/emails/[id]/GET.js +2 -0
- package/dist/kempo/api/emails/[id]/GET.js.map +1 -0
- package/dist/kempo/api/emails/[id]/retry/POST.js +2 -0
- package/dist/kempo/api/emails/[id]/retry/POST.js.map +1 -0
- package/dist/kempo/api/emails/test/POST.js +2 -0
- package/dist/kempo/api/emails/test/POST.js.map +1 -0
- package/dist/kempo/api/settings/[owner]/[name]/POST.js +1 -1
- package/dist/kempo/api/settings/[owner]/[name]/POST.js.map +1 -1
- package/dist/kempo/api/updates/GET.js +2 -0
- package/dist/kempo/api/updates/GET.js.map +1 -0
- package/dist/kempo/api/updates/apply/POST.js +2 -0
- package/dist/kempo/api/updates/apply/POST.js.map +1 -0
- package/dist/kempo/api/updates/check/POST.js +2 -0
- package/dist/kempo/api/updates/check/POST.js.map +1 -0
- package/dist/kempo/api/updates/discard/POST.js +2 -0
- package/dist/kempo/api/updates/discard/POST.js.map +1 -0
- package/dist/kempo/api/updates/prepare/POST.js +2 -0
- package/dist/kempo/api/updates/prepare/POST.js.map +1 -0
- package/dist/kempo/api/updates/rollback/POST.js +2 -0
- package/dist/kempo/api/updates/rollback/POST.js.map +1 -0
- package/dist/kempo/fetch.js +1 -1
- package/dist/kempo/fetch.js.map +1 -1
- package/dist/kempo/sdk.js +1 -1
- package/dist/kempo/sdk.js.map +1 -1
- package/docker/.dockerignore +9 -0
- package/docker/Dockerfile +25 -0
- package/docker/docker-compose.prod.yml +39 -0
- package/docker/entrypoint.mjs +96 -0
- package/middleware/kempo.js +71 -0
- package/package.json +4 -3
- package/server/db/schema.js +44 -0
- package/server/db/upgrades/README.md +20 -0
- package/server/sdk.js +8 -0
- package/server/utils/email/defaultSender.js +2 -0
- package/server/utils/email/dispatchEmail.js +56 -0
- package/server/utils/email/emailSettings.js +21 -0
- package/server/utils/email/emailTemplatePaths.js +36 -0
- package/server/utils/email/getEmail.js +14 -0
- package/server/utils/email/getSenderEmail.js +11 -0
- package/server/utils/email/getSenderFrom.js +18 -0
- package/server/utils/email/isValidSender.js +4 -0
- package/server/utils/email/listEmailTemplates.js +23 -0
- package/server/utils/email/listEmails.js +35 -0
- package/server/utils/email/maintainEmails.js +46 -0
- package/server/utils/email/pruneEmails.js +29 -0
- package/server/utils/email/readEmailTemplate.js +28 -0
- package/server/utils/email/resetEmailTemplate.js +15 -0
- package/server/utils/email/retryEmail.js +21 -0
- package/server/utils/email/saveEmailTemplate.js +38 -0
- package/server/utils/email/sendEmail.js +22 -32
- package/server/utils/email/sendEmailFromTemplate.js +2 -2
- package/server/utils/extensions/checkExtensionUpdate.js +9 -36
- package/server/utils/extensions/reconcileExtensions.js +90 -0
- package/server/utils/extensions/updateExtension.js +14 -153
- package/server/utils/extensions/upgradeExtension.js +117 -0
- package/server/utils/extensions/writeSiteFile.js +66 -0
- package/server/utils/hooks/triggerHook.js +17 -4
- package/server/utils/settings/listSettings.js +10 -5
- package/server/utils/settings/setSetting.js +4 -0
- package/server/utils/settings/settingRules.js +21 -0
- package/server/utils/settings/systemSettings.js +41 -0
- package/server/utils/setup/runUpgrades.js +70 -0
- package/server/utils/setup/seedDatabase.js +5 -60
- package/server/utils/setup/seedIfNew.js +21 -0
- package/server/utils/setup/syncCoreSchema.js +130 -0
- package/server/utils/setup/systemPermissions.js +77 -0
- package/server/utils/updates/applyStagedUpdate.js +95 -0
- package/server/utils/updates/applyUpdate.js +76 -0
- package/server/utils/updates/backupDatabase.js +35 -0
- package/server/utils/updates/discardUpdate.js +11 -0
- package/server/utils/updates/extensionTargets.js +101 -0
- package/server/utils/updates/fetchManifest.js +26 -0
- package/server/utils/updates/getExtensionUpdates.js +70 -0
- package/server/utils/updates/getInstallInfo.js +25 -0
- package/server/utils/updates/getUpdateStatus.js +57 -0
- package/server/utils/updates/helpers.js +30 -0
- package/server/utils/updates/notifySchemaAttention.js +35 -0
- package/server/utils/updates/npm.js +41 -0
- package/server/utils/updates/prepareUpdate.js +109 -0
- package/server/utils/updates/releaseStatus.js +23 -0
- package/server/utils/updates/restart.js +64 -0
- package/server/utils/updates/rollbackUpdate.js +56 -0
- package/server/utils/updates/runUpdateCheck.js +52 -0
- package/server/utils/updates/runtime.js +15 -0
- package/server/utils/updates/siteLayout.js +200 -0
- package/server/utils/updates/starterFiles.js +118 -0
package/README.md
CHANGED
|
@@ -360,19 +360,25 @@ Extensions can push live updates to browsers: declare a channel, publish to it f
|
|
|
360
360
|
|
|
361
361
|
## Admin Dashboard
|
|
362
362
|
|
|
363
|
-
The admin home page is a grid of widgets one to four blocks wide and one to three tall. Kempo provides widgets for pages, content, users, notifications and extensions; extensions add their own with `widgets` in `kempo-config.json` or `registerDashboardWidget`. Each person chooses which are shown, their order and size, kept in their browser's localStorage, and a widget only loads its script and data once it is shown. Existing sites
|
|
363
|
+
The admin home page is a grid of widgets one to four blocks wide and one to three tall. Kempo provides widgets for pages, content, users, notifications and extensions; extensions add their own with `widgets` in `kempo-config.json` or `registerDashboardWidget`. Each person chooses which are shown, their order and size, kept in their browser's localStorage, and a widget only loads its script and data once it is shown. Existing sites get the `dashboardWidget` table when the server starts. See [docs/dashboard.md](docs/dashboard.md).
|
|
364
364
|
|
|
365
365
|
## Notifications
|
|
366
366
|
|
|
367
|
-
Core and extensions can notify users with `createNotification`: to specific users, everyone holding a permission, or a group. Each person has their own read state and history, a notification can carry buttons that link somewhere or call an API as the signed-in user, and a `dedupeKey` keeps a repeating event to one notification. The admin has a bell with an unread count and a Notifications page; a public site can use `<k-notification-bell>`. Existing sites
|
|
367
|
+
Core and extensions can notify users with `createNotification`: to specific users, everyone holding a permission, or a group. Each person has their own read state and history, a notification can carry buttons that link somewhere or call an API as the signed-in user, and a `dedupeKey` keeps a repeating event to one notification. The admin has a bell with an unread count and a Notifications page; a public site can use `<k-notification-bell>`. Existing sites get the two tables when the server starts. See [docs/notifications.md](docs/notifications.md).
|
|
368
|
+
|
|
369
|
+
## Updates
|
|
370
|
+
|
|
371
|
+
Kempo checks npm every 12 hours (`system:update_check_enabled` turns it off) for itself and for every installed extension, notifies the people who hold `system:updates:manage`, and **Admin → Updates** lists what is newer with a box each and installs what is ticked, restarts the server, waits for it to return and reloads with a success message, with nothing typed on the server. `npx kempo init` offers a `Dockerfile` and `docker-compose.prod.yml` that keep the whole site (pages, templates, uploads and the code) on a volume: there an update is downloaded beside the running site, shows what it will change (starter files you never edited update, files you edited stay, security fixes ask first), switches when you choose, and a version that does not work is put back by itself. A major extension version is treated as one that may change data (warned, backed up, confirmed), and each extension's tables and `update.js` are brought up to date when the server starts. A linked or `file:` install is shown the update but never replaced. Kempo's own database tables are brought up to date every time the server starts, additively (new tables, columns and indexes; nothing is dropped or changed), a new database sets itself up, and a release that must move data ships a migration that is backed up first, so an update needs no `drizzle-kit push`. See [docs/updates.md](docs/updates.md).
|
|
368
372
|
|
|
369
373
|
## Scheduled Jobs, Aliases and Email Templates for Extensions
|
|
370
374
|
|
|
371
|
-
Extensions can declare `jobs` in `kempo-config.json` and kempo runs them on a timer (several processes sharing a database run each once per interval), `aliases` to answer on a short address such as `/cart`, and ship their own email templates as `owner/name`. Existing sites
|
|
375
|
+
Extensions can declare `jobs` in `kempo-config.json` and kempo runs them on a timer (several processes sharing a database run each once per interval), `aliases` to answer on a short address such as `/cart`, and ship their own email templates as `owner/name`. Existing sites get the `scheduledJob` table when the server starts. See [docs/extensions/creating-extensions.md](docs/extensions/creating-extensions.md).
|
|
372
376
|
|
|
373
377
|
## Email
|
|
374
378
|
|
|
375
|
-
Kempo
|
|
379
|
+
Kempo does not send email itself. It renders the email, saves it in a log (**Admin > Emails** shows every one, with whether it was sent and why not), and hands it to an **email extension**: `kempo-resend` sends through Resend, `kempo-smtp` through any SMTP server (a Hostinger or Google mailbox, Amazon SES, a Postfix of your own). Install one from Admin > Extensions and enter its settings on the Settings screen; with none installed, emails are logged and fail with "No email extension is installed".
|
|
380
|
+
|
|
381
|
+
The address emails are sent from is the **Email from** setting (`system:email_from`); until it is set, `EMAIL_FROM` from `.env` is used, and it must be on a domain your email service allows. A failed email is tried again (`email_max_retries`, 1 by default) and the log is kept for `email_retention_days` (30 by default; `email_retention_by_type` sets it per kind of email). See [docs/extensions/creating-extensions.md](docs/extensions/creating-extensions.md) to write an email extension.
|
|
376
382
|
|
|
377
383
|
Built-in email templates (in `templates/emails/`):
|
|
378
384
|
- `verify-email.html` — Email verification link
|
package/bin/cli.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
import { existsSync, cpSync, mkdirSync, writeFileSync, rmSync } from 'fs';
|
|
3
|
+
import { existsSync, cpSync, mkdirSync, writeFileSync, readFileSync, rmSync } from 'fs';
|
|
4
4
|
import { fileURLToPath, pathToFileURL } from 'url';
|
|
5
5
|
import { join, dirname, basename } from 'path';
|
|
6
6
|
import { execSync, spawnSync } from 'child_process';
|
|
7
7
|
import crypto from 'crypto';
|
|
8
8
|
import inquirer from 'inquirer';
|
|
9
|
+
import { recordShipped } from '../server/utils/updates/starterFiles.js';
|
|
9
10
|
|
|
10
11
|
const args = process.argv.slice(2);
|
|
11
12
|
const command = args[0];
|
|
@@ -267,42 +268,33 @@ if(adminSetupChoice === 'browser'){
|
|
|
267
268
|
adminPassword = adminAnswers.adminPassword || generatedAdminPassword;
|
|
268
269
|
}
|
|
269
270
|
|
|
270
|
-
let emailApiKey = '';
|
|
271
271
|
let emailFrom = 'noreply@example.com';
|
|
272
|
-
let emailServiceSkipped = false;
|
|
273
272
|
|
|
273
|
+
/*
|
|
274
|
+
Kempo does not send email itself: an email extension (kempo-resend, kempo-smtp...) does, and is installed from the admin once the
|
|
275
|
+
site is running. Only the address emails are sent from is asked here; it can be changed later on the admin Settings screen.
|
|
276
|
+
*/
|
|
274
277
|
if(!useDefaults){
|
|
275
|
-
const {
|
|
276
|
-
type: '
|
|
277
|
-
name: '
|
|
278
|
-
message: '
|
|
279
|
-
|
|
280
|
-
{ name: 'Resend (recommended — https://resend.com)', value: 'resend' },
|
|
281
|
-
{ name: 'Skip for now', value: 'skip' }
|
|
282
|
-
]
|
|
278
|
+
const { fromEmail } = await inquirer.prompt([{
|
|
279
|
+
type: 'input',
|
|
280
|
+
name: 'fromEmail',
|
|
281
|
+
message: 'The address emails are sent from:',
|
|
282
|
+
default: 'noreply@example.com'
|
|
283
283
|
}]);
|
|
284
|
-
|
|
285
|
-
if(emailService === 'resend'){
|
|
286
|
-
const emailAnswers = await inquirer.prompt([
|
|
287
|
-
{
|
|
288
|
-
type: 'input',
|
|
289
|
-
name: 'apiKey',
|
|
290
|
-
message: 'Resend API key:'
|
|
291
|
-
},
|
|
292
|
-
{
|
|
293
|
-
type: 'input',
|
|
294
|
-
name: 'fromEmail',
|
|
295
|
-
message: 'From email address:',
|
|
296
|
-
default: 'noreply@example.com'
|
|
297
|
-
}
|
|
298
|
-
]);
|
|
299
|
-
emailApiKey = emailAnswers.apiKey;
|
|
300
|
-
emailFrom = emailAnswers.fromEmail;
|
|
301
|
-
} else {
|
|
302
|
-
emailServiceSkipped = true;
|
|
303
|
-
}
|
|
284
|
+
emailFrom = fromEmail;
|
|
304
285
|
}
|
|
305
286
|
|
|
287
|
+
/*
|
|
288
|
+
The Docker files run the site and its database on a server, with everything the admin does kept on a volume so that
|
|
289
|
+
installing and updating Kempo from the admin survives replacing the container.
|
|
290
|
+
*/
|
|
291
|
+
const addDockerFiles = useDefaults ? true : (await inquirer.prompt([{
|
|
292
|
+
type: 'confirm',
|
|
293
|
+
name: 'addDocker',
|
|
294
|
+
message: 'Add a Dockerfile and docker-compose.prod.yml for running this site on a server?',
|
|
295
|
+
default: true
|
|
296
|
+
}])).addDocker;
|
|
297
|
+
|
|
306
298
|
/*
|
|
307
299
|
Step 3: Scaffold project files
|
|
308
300
|
*/
|
|
@@ -353,6 +345,16 @@ if(!existsSync(templatesDir) && existsSync(templatesSource)){
|
|
|
353
345
|
console.log('Scaffolded templates/');
|
|
354
346
|
}
|
|
355
347
|
|
|
348
|
+
/* Remembers what was copied, so an update later can tell a starter file nobody edited from one that was. */
|
|
349
|
+
recordShipped({ cwd: projectDir, packageRoot: moduleRoot, version: JSON.parse(readFileSync(join(moduleRoot, 'package.json'), 'utf8')).version });
|
|
350
|
+
|
|
351
|
+
if(addDockerFiles){
|
|
352
|
+
for(const [source, target] of [['Dockerfile', 'Dockerfile'], ['docker-compose.prod.yml', 'docker-compose.prod.yml'], ['.dockerignore', '.dockerignore']]){
|
|
353
|
+
if(!existsSync(join(projectDir, target))) cpSync(join(moduleRoot, 'docker', source), join(projectDir, target));
|
|
354
|
+
}
|
|
355
|
+
console.log('Added Dockerfile, docker-compose.prod.yml and .dockerignore');
|
|
356
|
+
}
|
|
357
|
+
|
|
356
358
|
const drizzleConfigPath = join(projectDir, 'drizzle.config.js');
|
|
357
359
|
const scaffoldDrizzle = join(moduleRoot, 'app-drizzle.config.js');
|
|
358
360
|
if(!existsSync(drizzleConfigPath) && existsSync(scaffoldDrizzle)){
|
|
@@ -393,8 +395,7 @@ writeFileSync(join(projectDir, '.env'),
|
|
|
393
395
|
`# Database
|
|
394
396
|
DATABASE_URL=${databaseUrl}
|
|
395
397
|
|
|
396
|
-
# Email
|
|
397
|
-
RESEND_API_KEY=${emailApiKey || 'your_resend_api_key_here'}
|
|
398
|
+
# Email: the address emails are sent from (also a setting on the admin Settings screen). Sending needs an email extension such as kempo-resend or kempo-smtp.
|
|
398
399
|
EMAIL_FROM=${emailFrom}
|
|
399
400
|
|
|
400
401
|
# Encrypts the API credentials saved in the admin. Back this up with your database: if it is lost they cannot be recovered.
|
|
@@ -524,7 +525,10 @@ ${adminSetupChoice === 'browser' ? `Create your admin user in the browser:
|
|
|
524
525
|
` : `Admin credentials:
|
|
525
526
|
Email: ${adminEmail}
|
|
526
527
|
Password: ${adminPassword}
|
|
527
|
-
`}
|
|
528
|
+
`}
|
|
529
|
+
Note: Kempo does not send email itself. Install an email extension (kempo-resend or kempo-smtp)
|
|
530
|
+
from Admin > Extensions when you want the site to send email.
|
|
531
|
+
|
|
528
532
|
Next steps:
|
|
529
533
|
npm run dev
|
|
530
534
|
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import t from"/kempo-ui/components/ShadowComponent.js";import{html as e,nothing as i}from"/kempo-ui/lit-all.min.js";import"/kempo-ui/components/Spinner.js";import"/kempo-ui/components/Icon.js";import"/kempo-ui/components/Dialog.js";import"/kempo-ui/components/CodeEditor.js";import s from"/kempo-ui/components/Toast.js";import{listEmailTemplates as a,getEmailTemplate as o,saveEmailTemplate as r,resetEmailTemplate as n}from"/kempo/sdk.js";export default class l extends t{static properties={owner:{type:String},previewUrl:{type:String,attribute:"preview-url"},templates:{state:!0},error:{state:!0},editing:{state:!0},saving:{state:!0}};constructor(){super(),this.owner="",this.previewUrl="/kempo/api/email-templates/preview",this.templates=null,this.error="",this.editing=null,this.saving=!1}connectedCallback(){super.connectedCallback(),this.load()}load=async()=>{const[t,e]=await a(this.owner);t?this.error=t.msg:this.templates=e.templates};edit=async t=>{const[e,i]=await o(t);e?s.error(e.msg):(this.editing=i,await this.updateComplete,this.renderRoot.querySelector("#emailDialog").open())};confirmSave=t=>{t.keepDialogOpen=!0,this.save()};save=async()=>{this.saving=!0;const[t]=await r({template:this.editing.template,source:this.renderRoot.querySelector("#emailEditor").value});this.saving=!1,t?s.error(t.msg):(this.renderRoot.querySelector("#emailDialog").close(),s.success("Email template saved"),await this.load())};reset=async()=>{this.saving=!0;const[t]=await n(this.editing.template);this.saving=!1,t?s.error(t.msg):(this.renderRoot.querySelector("#emailDialog").close(),s.success("Email template reset to the default"),await this.load())};renderDialog(){const t=this.editing;return t?e`
|
|
2
|
+
<k-dialog id="emailDialog" style="--width: 60rem;" confirm-text=${this.saving?"Saving…":"Save"} confirm-classes="primary ml" cancel-text="Cancel" .confirmAction=${this.confirmSave}>
|
|
3
|
+
<h2 slot="title" class="h5 pyh px m0">${t.title||t.name}</h2>
|
|
4
|
+
<div class="p">
|
|
5
|
+
<p class="tc-muted mb">${t.template}. Saving keeps your copy in <strong>templates/emails</strong>, which is used from the next email and is not changed by updates. A template that does not render is not saved.</p>
|
|
6
|
+
<k-code-editor id="emailEditor" class="r b mb" language="html" .value=${t.source} style="height: 55vh; min-height: 300px;"></k-code-editor>
|
|
7
|
+
${t.overridden?e`<button type="button" class="danger" ?disabled=${this.saving} @click=${this.reset}>Reset to default</button>`:i}
|
|
8
|
+
</div>
|
|
9
|
+
</k-dialog>
|
|
10
|
+
`:i}render(){return this.error?e`<p class="tc-danger" role="alert">${this.error}</p>`:this.templates?this.templates.length?e`
|
|
11
|
+
<table class="mb">
|
|
12
|
+
<thead><tr><th>Email</th><th>Template</th><th>Status</th><th></th></tr></thead>
|
|
13
|
+
<tbody>${this.templates.map(t=>e`<tr>
|
|
14
|
+
<td>${t.title||t.name}</td>
|
|
15
|
+
<td class="tc-muted">${t.template}</td>
|
|
16
|
+
<td>${t.overridden?e`<span class="tc-warning">Customized</span>`:e`<span class="tc-muted">Default</span>`}</td>
|
|
17
|
+
<td class="ta-right">
|
|
18
|
+
<a class="btn" href=${`${this.previewUrl}?template=${encodeURIComponent(t.template)}`} target="email-preview">Preview</a>
|
|
19
|
+
<button aria-label="Edit" title="Edit" @click=${()=>this.edit(t.template)}><k-icon name="edit"></k-icon></button>
|
|
20
|
+
</td>
|
|
21
|
+
</tr>`)}</tbody>
|
|
22
|
+
</table>
|
|
23
|
+
${this.renderDialog()}
|
|
24
|
+
`:e`<p class="tc-muted">There are no email templates here.</p>`:e`<k-spinner></k-spinner>`}}customElements.define("k-email-templates",l);
|
|
25
|
+
//# sourceMappingURL=C:\Users\dusti\dev\kempo\dist\admin\components\EmailTemplates.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"src\\admin\\components\\EmailTemplates.js","names":["ShadowComponent","html","nothing","Toast","listEmailTemplates","getEmailTemplate","saveEmailTemplate","resetEmailTemplate","EmailTemplates","static","owner","type","String","previewUrl","attribute","templates","state","error","editing","saving","constructor","super","this","connectedCallback","load","async","data","msg","edit","found","template","updateComplete","renderRoot","querySelector","open","confirmSave","event","keepDialogOpen","save","source","value","close","success","reset","renderDialog","title","name","overridden","render","length","map","encodeURIComponent","customElements","define"],"sources":["0"],"sourcesContent":["import ShadowComponent from '/kempo-ui/components/ShadowComponent.js';\nimport { html, nothing } from '/kempo-ui/lit-all.min.js';\nimport '/kempo-ui/components/Spinner.js';\nimport '/kempo-ui/components/Icon.js';\nimport '/kempo-ui/components/Dialog.js';\nimport '/kempo-ui/components/CodeEditor.js';\nimport Toast from '/kempo-ui/components/Toast.js';\nimport { listEmailTemplates, getEmailTemplate, saveEmailTemplate, resetEmailTemplate } from '/kempo/sdk.js';\n\n/*\n The email templates of one extension, to edit, served at /admin/components/EmailTemplates.js:\n\n <script type=\"module\" src=\"/admin/components/EmailTemplates.js\"></script>\n <k-email-templates owner=\"kempo-commerce\"></k-email-templates>\n\n Without `owner` it lists kempo's own templates (verify-email, reset-password). Each row opens a dialog with the template in\n a code editor. Saving writes the site's own copy to `templates/emails/<owner>/<name>.page.html`, which is used from the next\n email on and survives updates of the extension; **Reset to default** removes it. The packaged template is never changed.\n\n **Preview** opens the template as it would be sent, in one named tab that each preview replaces. By default that is kempo's\n preview, which draws it with no data; an extension that can do better (its own orders as the data) serves its own and gives\n its address as `preview-url`:\n\n <k-email-templates owner=\"kempo-commerce\" preview-url=\"/commerce/api/emails/preview\"></k-email-templates>\n\n The preview is the saved template, not what is being typed in the editor.\n An extension puts this on its settings page; it needs no code of its own.\n*/\nexport default class EmailTemplates extends ShadowComponent {\n static properties = {\n owner: { type: String },\n previewUrl: { type: String, attribute: 'preview-url' },\n templates: { state: true },\n error: { state: true },\n editing: { state: true },\n saving: { state: true },\n };\n\n constructor(){\n super();\n this.owner = '';\n this.previewUrl = '/kempo/api/email-templates/preview';\n this.templates = null;\n this.error = '';\n this.editing = null;\n this.saving = false;\n }\n\n /*\n Lifecycle\n */\n connectedCallback(){\n super.connectedCallback();\n this.load();\n }\n\n /*\n Actions\n */\n load = async () => {\n const [error, data] = await listEmailTemplates(this.owner);\n if(error){\n this.error = error.msg;\n return;\n }\n this.templates = data.templates;\n };\n\n edit = async template => {\n const [error, found] = await getEmailTemplate(template);\n if(error){\n Toast.error(error.msg);\n return;\n }\n this.editing = found;\n await this.updateComplete;\n this.renderRoot.querySelector('#emailDialog').open();\n };\n\n /* The dialog's Save button: it stays open until the template is saved, so a template that does not render is not lost. */\n confirmSave = event => {\n event.keepDialogOpen = true;\n this.save();\n };\n\n save = async () => {\n this.saving = true;\n const [error] = await saveEmailTemplate({ template: this.editing.template, source: this.renderRoot.querySelector('#emailEditor').value });\n this.saving = false;\n if(error){\n Toast.error(error.msg);\n return;\n }\n this.renderRoot.querySelector('#emailDialog').close();\n Toast.success('Email template saved');\n await this.load();\n };\n\n reset = async () => {\n this.saving = true;\n const [error] = await resetEmailTemplate(this.editing.template);\n this.saving = false;\n if(error){\n Toast.error(error.msg);\n return;\n }\n this.renderRoot.querySelector('#emailDialog').close();\n Toast.success('Email template reset to the default');\n await this.load();\n };\n\n /*\n Rendering\n */\n renderDialog(){\n const template = this.editing;\n if(!template) return nothing;\n return html`\n <k-dialog id=\"emailDialog\" style=\"--width: 60rem;\" confirm-text=${this.saving ? 'Saving…' : 'Save'} confirm-classes=\"primary ml\" cancel-text=\"Cancel\" .confirmAction=${this.confirmSave}>\n <h2 slot=\"title\" class=\"h5 pyh px m0\">${template.title || template.name}</h2>\n <div class=\"p\">\n <p class=\"tc-muted mb\">${template.template}. Saving keeps your copy in <strong>templates/emails</strong>, which is used from the next email and is not changed by updates. A template that does not render is not saved.</p>\n <k-code-editor id=\"emailEditor\" class=\"r b mb\" language=\"html\" .value=${template.source} style=\"height: 55vh; min-height: 300px;\"></k-code-editor>\n ${template.overridden ? html`<button type=\"button\" class=\"danger\" ?disabled=${this.saving} @click=${this.reset}>Reset to default</button>` : nothing}\n </div>\n </k-dialog>\n `;\n }\n\n render(){\n if(this.error) return html`<p class=\"tc-danger\" role=\"alert\">${this.error}</p>`;\n if(!this.templates) return html`<k-spinner></k-spinner>`;\n if(!this.templates.length) return html`<p class=\"tc-muted\">There are no email templates here.</p>`;\n return html`\n <table class=\"mb\">\n <thead><tr><th>Email</th><th>Template</th><th>Status</th><th></th></tr></thead>\n <tbody>${this.templates.map(template => html`<tr>\n <td>${template.title || template.name}</td>\n <td class=\"tc-muted\">${template.template}</td>\n <td>${template.overridden ? html`<span class=\"tc-warning\">Customized</span>` : html`<span class=\"tc-muted\">Default</span>`}</td>\n <td class=\"ta-right\">\n <a class=\"btn\" href=${`${this.previewUrl}?template=${encodeURIComponent(template.template)}`} target=\"email-preview\">Preview</a>\n <button aria-label=\"Edit\" title=\"Edit\" @click=${() => this.edit(template.template)}><k-icon name=\"edit\"></k-icon></button>\n </td>\n </tr>`)}</tbody>\n </table>\n ${this.renderDialog()}\n `;\n }\n}\n\ncustomElements.define('k-email-templates', EmailTemplates);\n"],"mappings":"OAAOA,MAAqB,yDACnBC,aAAMC,MAAe,iCACvB,wCACA,qCACA,uCACA,4CACAC,MAAW,6DACTC,sBAAoBC,uBAAkBC,wBAAmBC,MAA0B,+BAqB7E,MAAMC,UAAuBR,EAC1CS,kBAAoB,CAClBC,MAAO,CAAEC,KAAMC,QACfC,WAAY,CAAEF,KAAMC,OAAQE,UAAW,eACvCC,UAAW,CAAEC,OAAO,GACpBC,MAAO,CAAED,OAAO,GAChBE,QAAS,CAAEF,OAAO,GAClBG,OAAQ,CAAE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AAkDqB,KAAKH,iBAAiBG,KAAKqB,kCAAoCzC;;;MAP9HA,CAWvB,CAEA,MAAA8C,GACE,OAAG1B,KAAKL,MAAchB,CAAI,qCAAqCqB,KAAKL,YAChEK,KAAKP,UACLO,KAAKP,UAAUkC,OACZhD,CAAI;;;iBAGEqB,KAAKP,UAAUmC,IAAIpB,GAAY7B,CAAI;gBACpC6B,EAASe,OAASf,EAASgB;iCACVhB,EAASA;gBAC1BA,EAASiB,WAAa9C,CAAI,6CAA+CA,CAAI;;kCAE3D,GAAGqB,KAAKT,uBAAuBsC,mBAAmBrB,EAASA;4DACjC,IAAMR,KAAKM,KAAKE,EAASA;;;;QAI7ER,KAAKsB;MAdyB3C,CAAI,6DADXA,CAAI,yBAiBjC,EAGFmD,eAAeC,OAAO,oBAAqB7C","ignoreList":[]}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import t from"/kempo-ui/components/ShadowComponent.js";import{html as s,nothing as e}from"/kempo-ui/lit-all.min.js";import"/kempo-ui/components/Spinner.js";import"/kempo-ui/components/Dialog.js";import a from"/kempo-ui/components/Toast.js";import{listEmails as i,getEmail as o,retryEmail as r,sendTestEmail as l,getAllCurrentUserPermissions as n}from"/kempo/sdk.js";const c={sent:"tc-success",failed:"tc-danger",sending:"tc-warning",queued:"tc-muted"},h=t=>t?new Date(t).toLocaleString():"";export default class d extends t{static properties={emails:{state:!0},total:{state:!0},offset:{state:!0},status:{state:!0},search:{state:!0},loading:{state:!0},error:{state:!0},canManage:{state:!0},open:{state:!0},testTo:{state:!0},busy:{state:!0}};constructor(){super(),this.emails=[],this.total=0,this.offset=0,this.status="",this.search="",this.loading=!0,this.error="",this.canManage=!1,this.open=null,this.testTo="",this.busy=!1}connectedCallback(){super.connectedCallback(),n().then(([,t])=>{this.canManage=(t?.permissions??[]).includes("system:emails:manage")}),this.load()}load=async()=>{this.loading=!0;const[t,s]=await i({status:this.status||void 0,search:this.search||void 0,limit:25,offset:this.offset});this.loading=!1,t?this.error=t.msg||"The emails could not be loaded":(this.error="",this.emails=s.emails,this.total=s.total)};filter=async t=>{Object.assign(this,t,{offset:0}),await this.load()};page=async t=>{this.offset=Math.max(0,this.offset+25*t),await this.load()};show=async t=>{const[s,e]=await o(t);s?a.error(s.msg):(this.open=e,await this.updateComplete,this.renderRoot.querySelector("#emailDialog").open())};retry=async()=>{this.busy=!0;const[t,s]=await r(this.open.id);this.busy=!1,t?a.error(t.msg):s.sent?a.success("The email was sent"):a.error(s.error||"The email could not be sent"),this.renderRoot.querySelector("#emailDialog").close(),await this.load()};openTest=()=>this.renderRoot.querySelector("#testDialog").open();confirmTest=t=>{t.keepDialogOpen=!0,this.sendTest()};sendTest=async()=>{this.busy=!0;const[t,s]=await l(this.testTo.trim());this.busy=!1,t?a.error(t.msg):(this.renderRoot.querySelector("#testDialog").close(),s.sent?a.success(`A test email was sent to ${this.testTo.trim()}`):a.error(s.error||"The test email could not be sent"),await this.load())};renderDetail(){const t=this.open;return t?s`
|
|
2
|
+
<k-dialog id="emailDialog" style="--width: 60rem;" cancel-text="Close">
|
|
3
|
+
<h2 slot="title" class="h5 pyh px m0">${t.subject}</h2>
|
|
4
|
+
<div class="p">
|
|
5
|
+
<p class="mb"><strong class=${c[t.status]??""}>${t.status}</strong>${t.attempts?s` · ${t.attempts} ${1===t.attempts?"try":"tries"}`:e}${t.provider?s` · sent by ${t.provider}`:e}</p>
|
|
6
|
+
<p class="mb">To <strong>${t.recipient}</strong>, from ${t.sender}<br><span class="tc-muted">${t.type} · created ${h(t.createdAt)}${t.sentAt?` · sent ${h(t.sentAt)}`:""}</span></p>
|
|
7
|
+
${t.lastError?s`<p class="tc-danger mb" role="alert">${t.lastError}</p>`:e}
|
|
8
|
+
${this.canManage&&["queued","failed"].includes(t.status)?s`<p class="mb"><button class="primary" ?disabled=${this.busy} @click=${this.retry}>${this.busy?"Trying…":"Try again"}</button></p>`:e}
|
|
9
|
+
<iframe title="The email" sandbox="" .srcdoc=${t.html} class="full b r" height="420"></iframe>
|
|
10
|
+
</div>
|
|
11
|
+
</k-dialog>
|
|
12
|
+
`:e}renderTest(){return s`
|
|
13
|
+
<k-dialog id="testDialog" confirm-text=${this.busy?"Sending…":"Send test email"} confirm-classes="primary ml" cancel-text="Cancel" .confirmAction=${this.confirmTest}>
|
|
14
|
+
<h2 slot="title" class="h5 pyh px m0">Send a test email</h2>
|
|
15
|
+
<div class="p">
|
|
16
|
+
<label class="mb d-b">Send it to<input type="email" .value=${this.testTo} @input=${t=>{this.testTo=t.target.value}}></label>
|
|
17
|
+
<p class="tc-muted">It goes out through the email extension that is installed, and shows in the log below.</p>
|
|
18
|
+
</div>
|
|
19
|
+
</k-dialog>
|
|
20
|
+
`}render(){const t=Math.min(this.offset+25,this.total);return s`
|
|
21
|
+
<div class="d-f mb">
|
|
22
|
+
<label class="mr">Status
|
|
23
|
+
<select @change=${t=>this.filter({status:t.target.value})}>
|
|
24
|
+
${["","queued","sending","sent","failed"].map(t=>s`<option value=${t} ?selected=${this.status===t}>${t||"All"}</option>`)}
|
|
25
|
+
</select>
|
|
26
|
+
</label>
|
|
27
|
+
<label class="mr">Search
|
|
28
|
+
<input type="search" placeholder="Address or subject" .value=${this.search} @change=${t=>this.filter({search:t.target.value})}>
|
|
29
|
+
</label>
|
|
30
|
+
${this.canManage?s`<button class="mb" @click=${this.openTest}>Send a test email</button>`:e}
|
|
31
|
+
</div>
|
|
32
|
+
${this.error?s`<p class="tc-danger" role="alert">${this.error}</p>`:e}
|
|
33
|
+
${this.loading?s`<k-spinner></k-spinner>`:this.emails.length?s`
|
|
34
|
+
<table class="mb">
|
|
35
|
+
<thead><tr><th>Status</th><th>To</th><th>Subject</th><th>Type</th><th>Created</th></tr></thead>
|
|
36
|
+
<tbody>${this.emails.map(t=>s`<tr>
|
|
37
|
+
<td><strong class=${c[t.status]??""}>${t.status}</strong></td>
|
|
38
|
+
<td>${t.recipient}</td>
|
|
39
|
+
<td><a href="#" @click=${s=>{s.preventDefault(),this.show(t.id)}}>${t.subject}</a>${t.lastError?s`<br><span class="tc-danger">${t.lastError}</span>`:e}</td>
|
|
40
|
+
<td class="tc-muted">${t.type}</td>
|
|
41
|
+
<td class="tc-muted">${h(t.createdAt)}</td>
|
|
42
|
+
</tr>`)}</tbody>
|
|
43
|
+
</table>
|
|
44
|
+
<p class="d-f mb"><button ?disabled=${0===this.offset} @click=${()=>this.page(-1)}>Newer</button><span class="tc-muted ph">${this.offset+1}–${t} of ${this.total}</span><button ?disabled=${t>=this.total} @click=${()=>this.page(1)}>Older</button></p>
|
|
45
|
+
`:s`<p class="tc-muted">No emails have been sent yet.</p>`}
|
|
46
|
+
${this.renderDetail()}
|
|
47
|
+
${this.renderTest()}
|
|
48
|
+
`}}customElements.define("k-admin-emails",d);
|
|
49
|
+
//# sourceMappingURL=C:\Users\dusti\dev\kempo\dist\admin\components\Emails.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"src\\admin\\components\\Emails.js","names":["ShadowComponent","html","nothing","Toast","listEmails","getEmail","retryEmail","sendTestEmail","getAllCurrentUserPermissions","STATUS_CLASS","sent","failed","sending","queued","when","value","Date","toLocaleString","Emails","static","emails","state","total","offset","status","search","loading","error","canManage","open","testTo","busy","constructor","super","this","connectedCallback","then","data","permissions","includes","load","async","undefined","limit","msg","filter","Object","assign","changes","page","Math","max","step","show","found","id","updateComplete","renderRoot","querySelector","retry","result","success","close","openTest","confirmTest","event","keepDialogOpen","sendTest","trim","renderDetail","mail","subject","attempts","provider","recipient","sender","type","createdAt","sentAt","lastError","renderTest","target","render","last","min","map","length","preventDefault","customElements","define"],"sources":["0"],"sourcesContent":["import ShadowComponent from '/kempo-ui/components/ShadowComponent.js';\nimport { html, nothing } from '/kempo-ui/lit-all.min.js';\nimport '/kempo-ui/components/Spinner.js';\nimport '/kempo-ui/components/Dialog.js';\nimport Toast from '/kempo-ui/components/Toast.js';\nimport { listEmails, getEmail, retryEmail, sendTestEmail, getAllCurrentUserPermissions } from '/kempo/sdk.js';\n\n/*\n The log of emails, served at /admin/components/Emails.js:\n\n <k-admin-emails></k-admin-emails>\n\n Every email kempo was asked to send is here, newest first, with how it went: `queued` (waiting for a sender or a retry), `sending`,\n `sent` or `failed`. Click one to read it, with what it said and the reason it did not go. Someone who can manage emails can try a\n waiting or failed one again and send a test email, which is the quickest way to see that an email extension is set up.\n*/\nconst PAGE_SIZE = 25;\nconst STATUS_CLASS = { sent: 'tc-success', failed: 'tc-danger', sending: 'tc-warning', queued: 'tc-muted' };\n\nconst when = value => (value ? new Date(value).toLocaleString() : '');\n\nexport default class Emails extends ShadowComponent {\n static properties = {\n emails: { state: true },\n total: { state: true },\n offset: { state: true },\n status: { state: true },\n search: { state: true },\n loading: { state: true },\n error: { state: true },\n canManage: { state: true },\n open: { state: true },\n testTo: { state: true },\n busy: { state: true },\n };\n\n constructor(){\n super();\n this.emails = [];\n this.total = 0;\n this.offset = 0;\n this.status = '';\n this.search = '';\n this.loading = true;\n this.error = '';\n this.canManage = false;\n this.open = null;\n this.testTo = '';\n this.busy = false;\n }\n\n /*\n Lifecycle\n */\n connectedCallback(){\n super.connectedCallback();\n getAllCurrentUserPermissions().then(([, data]) => { this.canManage = (data?.permissions ?? []).includes('system:emails:manage'); });\n this.load();\n }\n\n /*\n Loading\n */\n load = async () => {\n this.loading = true;\n const [error, data] = await listEmails({ status: this.status || undefined, search: this.search || undefined, limit: PAGE_SIZE, offset: this.offset });\n this.loading = false;\n if(error){\n this.error = error.msg || 'The emails could not be loaded';\n return;\n }\n this.error = '';\n this.emails = data.emails;\n this.total = data.total;\n };\n\n filter = async changes => {\n Object.assign(this, changes, { offset: 0 });\n await this.load();\n };\n\n page = async step => {\n this.offset = Math.max(0, this.offset + step * PAGE_SIZE);\n await this.load();\n };\n\n /*\n One email\n */\n show = async id => {\n const [error, found] = await getEmail(id);\n if(error){\n Toast.error(error.msg);\n return;\n }\n this.open = found;\n await this.updateComplete;\n this.renderRoot.querySelector('#emailDialog').open();\n };\n\n retry = async () => {\n this.busy = true;\n const [error, result] = await retryEmail(this.open.id);\n this.busy = false;\n if(error) Toast.error(error.msg);\n else if(result.sent) Toast.success('The email was sent');\n else Toast.error(result.error || 'The email could not be sent');\n this.renderRoot.querySelector('#emailDialog').close();\n await this.load();\n };\n\n /*\n Test email\n */\n openTest = () => this.renderRoot.querySelector('#testDialog').open();\n\n confirmTest = event => {\n event.keepDialogOpen = true;\n this.sendTest();\n };\n\n sendTest = async () => {\n this.busy = true;\n const [error, result] = await sendTestEmail(this.testTo.trim());\n this.busy = false;\n if(error){\n Toast.error(error.msg);\n return;\n }\n this.renderRoot.querySelector('#testDialog').close();\n if(result.sent) Toast.success(`A test email was sent to ${this.testTo.trim()}`);\n else Toast.error(result.error || 'The test email could not be sent');\n await this.load();\n };\n\n /*\n Rendering\n */\n renderDetail(){\n const mail = this.open;\n if(!mail) return nothing;\n return html`\n <k-dialog id=\"emailDialog\" style=\"--width: 60rem;\" cancel-text=\"Close\">\n <h2 slot=\"title\" class=\"h5 pyh px m0\">${mail.subject}</h2>\n <div class=\"p\">\n <p class=\"mb\"><strong class=${STATUS_CLASS[mail.status] ?? ''}>${mail.status}</strong>${mail.attempts ? html` · ${mail.attempts} ${mail.attempts === 1 ? 'try' : 'tries'}` : nothing}${mail.provider ? html` · sent by ${mail.provider}` : nothing}</p>\n <p class=\"mb\">To <strong>${mail.recipient}</strong>, from ${mail.sender}<br><span class=\"tc-muted\">${mail.type} · created ${when(mail.createdAt)}${mail.sentAt ? ` · sent ${when(mail.sentAt)}` : ''}</span></p>\n ${mail.lastError ? html`<p class=\"tc-danger mb\" role=\"alert\">${mail.lastError}</p>` : nothing}\n ${this.canManage && ['queued', 'failed'].includes(mail.status) ? html`<p class=\"mb\"><button class=\"primary\" ?disabled=${this.busy} @click=${this.retry}>${this.busy ? 'Trying…' : 'Try again'}</button></p>` : nothing}\n <iframe title=\"The email\" sandbox=\"\" .srcdoc=${mail.html} class=\"full b r\" height=\"420\"></iframe>\n </div>\n </k-dialog>\n `;\n }\n\n renderTest(){\n return html`\n <k-dialog id=\"testDialog\" confirm-text=${this.busy ? 'Sending…' : 'Send test email'} confirm-classes=\"primary ml\" cancel-text=\"Cancel\" .confirmAction=${this.confirmTest}>\n <h2 slot=\"title\" class=\"h5 pyh px m0\">Send a test email</h2>\n <div class=\"p\">\n <label class=\"mb d-b\">Send it to<input type=\"email\" .value=${this.testTo} @input=${event => { this.testTo = event.target.value; }}></label>\n <p class=\"tc-muted\">It goes out through the email extension that is installed, and shows in the log below.</p>\n </div>\n </k-dialog>\n `;\n }\n\n render(){\n const last = Math.min(this.offset + PAGE_SIZE, this.total);\n return html`\n <div class=\"d-f mb\">\n <label class=\"mr\">Status\n <select @change=${event => this.filter({ status: event.target.value })}>\n ${['', 'queued', 'sending', 'sent', 'failed'].map(status => html`<option value=${status} ?selected=${this.status === status}>${status || 'All'}</option>`)}\n </select>\n </label>\n <label class=\"mr\">Search\n <input type=\"search\" placeholder=\"Address or subject\" .value=${this.search} @change=${event => this.filter({ search: event.target.value })}>\n </label>\n ${this.canManage ? html`<button class=\"mb\" @click=${this.openTest}>Send a test email</button>` : nothing}\n </div>\n ${this.error ? html`<p class=\"tc-danger\" role=\"alert\">${this.error}</p>` : nothing}\n ${this.loading ? html`<k-spinner></k-spinner>` : this.emails.length ? html`\n <table class=\"mb\">\n <thead><tr><th>Status</th><th>To</th><th>Subject</th><th>Type</th><th>Created</th></tr></thead>\n <tbody>${this.emails.map(mail => html`<tr>\n <td><strong class=${STATUS_CLASS[mail.status] ?? ''}>${mail.status}</strong></td>\n <td>${mail.recipient}</td>\n <td><a href=\"#\" @click=${event => { event.preventDefault(); this.show(mail.id); }}>${mail.subject}</a>${mail.lastError ? html`<br><span class=\"tc-danger\">${mail.lastError}</span>` : nothing}</td>\n <td class=\"tc-muted\">${mail.type}</td>\n <td class=\"tc-muted\">${when(mail.createdAt)}</td>\n </tr>`)}</tbody>\n </table>\n <p class=\"d-f mb\"><button ?disabled=${this.offset === 0} @click=${() => this.page(-1)}>Newer</button><span class=\"tc-muted ph\">${this.offset + 1}–${last} of ${this.total}</span><button ?disabled=${last >= this.total} @click=${() => this.page(1)}>Older</button></p>\n ` : html`<p class=\"tc-muted\">No emails have been sent yet.</p>`}\n ${this.renderDetail()}\n ${this.renderTest()}\n `;\n }\n}\n\ncustomElements.define('k-admin-emails', Emails);\n"],"mappings":"OAAOA,MAAqB,yDACnBC,aAAMC,MAAe,iCACvB,wCACA,wCACAC,MAAW,qDACTC,cAAYC,gBAAUC,mBAAYC,kCAAeC,MAAoC,gBAW9F,MACMC,EAAe,CAAEC,KAAM,aAAcC,OAAQ,YAAaC,QAAS,aAAcC,OAAQ,YAEzFC,EAAOC,GAAUA,EAAQ,IAAIC,KAAKD,GAAOE,iBAAmB,kBAEnD,MAAMC,UAAelB,EAClCmB,kBAAoB,CAClBC,OAAQ,CAAEC,OAAO,GACjBC,MAAO,CAAED,OAAO,GAChBE,OAAQ,CAAEF,OAAO,GACjBG,OAAQ,CAAEH,OAAO,GACjBI,OAAQ,CAAEJ,OAAO,GACjBK,QAAS,CAAEL,OAAO,GAClBM,MAAO,CAAEN,OAAO,GAChBO,UAAW,CAAEP,OAAO,GACpBQ,KAAM,CAAER,OAAO,GACfS,OAAQ,CAAET,OAAO,GACjBU,KAAM,CAAEV,OAAO,IAGjB,WAAAW,GACEC,QACAC,KAAKd,OAAS,GACdc,KAAKZ,MAAQ,EACbY,KAAKX,OAAS,EACdW,KAAKV,OAAS,GACdU,KAAKT,OAAS,GACdS,KAAKR,SAAU,EACfQ,KAAKP,MAAQ,GACbO,KAAKN,WAAY,EACjBM,KAAKL,KAAO,KACZK,KAAKJ,OAAS,GACdI,KAAKH,MAAO,CACd,CAKA,iBAAAI,GACEF,MAAME,oBACN3B,IAA+B4B,KAAK,EAAE,CAAEC,MAAYH,KAAKN,WAAaS,GAAMC,aAAe,IAAIC,SAAS,0BACxGL,KAAKM,MACP,CAKAA,KAAOC,UACLP,KAAKR,SAAU,EACf,MAAOC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BwC,GAAS/B,KAAKW,OAAO,CAAEpB,OAAQwC,EAAMgB,OAAOlE;;UAElImB,KAAKN,UAAY3B,CAAI,6BAA6BiC,KAAK6B,sCAAwC7D;;QAEjGgC,KAAKP,MAAQ1B,CAAI,qCAAqCiC,KAAKP,YAAczB;QACzEgC,KAAKR,QAAUzB,CAAI,0BAA4BiC,KAAKd,OAAOkE,OAASrF,CAAI;;;mBAG7DiC,KAAKd,OAAOiE,IAAIf,GAAQrE,CAAI;gCACfQ,EAAa6D,EAAK9C,SAAW,MAAM8C,EAAK9C;kBACtD8C,EAAKI;qCACcT,IAAWA,EAAMsB,iBAAkBrD,KAAKmB,KAAKiB,EAAKf,QAAUe,EAAKC,cAAcD,EAAKS,UAAY9E,CAAI,+BAA+BqE,EAAKS,mBAAqB7E;mCAC/JoE,EAAKM;mCACL9D,EAAKwD,EAAKO;;;8CAGiB,IAAhB3C,KAAKX,iBAAuB,IAAMW,KAAKe,MAAM,8CAA8Cf,KAAKX,OAAS,KAAK4D,QAAWjD,KAAKZ,iCAAiC6D,GAAQjD,KAAKZ,gBAAgB,IAAMY,KAAKe,KAAK;QAChPhD,CAAI;QACNiC,KAAKmC;QACLnC,KAAK8C;KAEX,EAGFQ,eAAeC,OAAO,iBAAkBvE","ignoreList":[]}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import e from"/kempo-ui/components/ShadowComponent.js";import{html as t,nothing as s}from"/kempo-ui/lit-all.min.js";import"/kempo-ui/components/Spinner.js";import"/kempo-ui/components/Dialog.js";import"/kempo-ui/components/Icon.js";import a from"/kempo-ui/components/Toast.js";import{getUpdateStatus as n,checkForUpdate as i,prepareUpdate as r,applyUpdate as o,rollbackUpdate as c,discardUpdate as l}from"/kempo/sdk.js";const h="kempo-after-update",d=e=>e?new Date(e).toLocaleString():"never",p=e=>new Promise(t=>setTimeout(t,e)),m=(e,t,s)=>`${e} ${1===e?t:s}`,g=(e,t)=>e.split(".").map(Number).reduce((e,s,a)=>e||s-Number(t.split(".")[a]),0)<0;export default class u extends e{static properties={status:{state:!0},error:{state:!0},checking:{state:!0},phase:{state:!0},stalled:{state:!0},action:{state:!0},chosen:{state:!0}};constructor(){super(),this.status=null,this.error="",this.checking=!1,this.phase="idle",this.stalled=!1,this.action="update",this.chosen=null}connectedCallback(){super.connectedCallback(),this.load()}load=async()=>{const[e,t]=await n();e?this.error=e.msg||"The update status could not be loaded":(this.error="",this.status=t,this.selectNew(t),this.reportOutcome())};updatable=e=>[...e.updateAvailable?[{key:"kempo",name:"Kempo",from:e.runningVersion,to:e.latestVersion,major:e.major}]:[],...(e.extensionUpdates?.updates??[]).map(e=>({key:e.name,name:e.name,from:e.installedVersion,to:e.latestVersion,major:e.major,needs:e.kempoRequired}))];selectNew=e=>{this.seen??=new Set;const t=new Set(this.chosen??[]);for(const{key:s}of this.updatable(e))this.seen.has(s)||(this.seen.add(s),t.add(s));this.chosen=t};blocked=(e,t)=>Boolean(e.needs)&&g(t.runningVersion,e.needs)&&!(this.chosen.has("kempo")&&t.updateAvailable&&!g(t.latestVersion,e.needs));chosenItems=()=>this.updatable(this.status).filter(e=>this.chosen.has(e.key)&&!this.blocked(e,this.status));toggle=e=>{const t=new Set(this.chosen);t.has(e)?t.delete(e):t.add(e),this.chosen=t};reportOutcome=()=>{try{const e=JSON.parse(sessionStorage.getItem(h)||"null");if(!e)return;sessionStorage.removeItem(h);this.status.lastUpdate&&!this.status.lastUpdate.ok&&this.status.lastUpdate.at>e.at?a.error("The update did not work, so the site went back to how it was"):a.success(e.message)}catch{}};check=async()=>{this.checking=!0;const[e,t]=await i();if(this.checking=!1,e)return void a.error(e.msg);this.status=t,this.selectNew(t);const s=t.checkError||t.extensionUpdates?.checkError;s?a.error(s):this.updatable(t).length||t.staged||a.success("Everything is up to date")};selection=()=>{const e=this.chosenItems();return{version:e.some(e=>"kempo"===e.key)?this.status.latestVersion:null,extensions:e.filter(e=>"kempo"!==e.key).map(e=>e.key)}};prepare=async()=>{this.phase="preparing";const[e]=await r(this.selection());this.phase="idle",e?a.error(e.msg):await this.load()};discard=async()=>{const[e]=await l();e?a.error(e.msg):await this.load()};openConfirm=e=>{this.action=e,this.renderRoot.querySelector("#confirmDialog").open()};confirmed=async()=>{const{staged:e,bootId:t,mode:s,lastUpdate:n}=this.status;let i,r,l;if(this.stalled=!1,"back"===this.action)this.phase="going-back",[i,r]=await c({data:Boolean(n?.breaking)}),l="The site is back on what it ran before the last update";else if("release"===s)this.phase="switching",[i,r]=await o({confirm:{forced:e.plan.files.forced.length>0,breaking:e.plan.breaking}}),l=`Updated: ${e.packages.join(", ")}`;else{this.phase="installing";const{version:e,extensions:t}=this.selection();[i,r]=await o({version:e,extensions:t}),l=`Updated: ${this.chosenItems().map(e=>`${e.name} ${e.to}`).join(", ")}`}if(i)return this.phase="idle",void a.error(i.msg);if(this.phase="restarting",await this.waitForServer(t)){try{sessionStorage.setItem(h,JSON.stringify({message:l,at:new Date(Date.now()-5e3).toISOString(),to:r.to}))}catch{}window.location.reload()}else this.stalled=!0};waitForServer=async e=>{const t=Date.now();let s=!1;for(;Date.now()-t<6e5;){await p(2e3);try{const t=await fetch("/kempo/api/updates?offline=true",{credentials:"same-origin",cache:"no-store"});if(t.ok){if((await t.json()).bootId!==e)return!0}else if(t.status>=500)s=!0;else if(s)return!0}catch{s=!0}}return!1};renderBusy(){const[e,s]={preparing:["Downloading the updates…","Your site keeps working while this happens. It can take a few minutes."],installing:["Installing the updates…","This can take a minute."],switching:["Switching to the updates…","This can take a minute."],"going-back":["Going back…","This can take a minute."],restarting:["Restarting the server…","This page reloads by itself when the site is back, and updated extensions are brought up to date first."]}[this.phase];return t`
|
|
2
|
+
<div class="b r p mb" role="status">
|
|
3
|
+
<p class="d-f mb"><k-spinner class="mr"></k-spinner><strong>${e}</strong></p>
|
|
4
|
+
<p class="tc-muted">${s} Please keep this page open.</p>
|
|
5
|
+
</div>
|
|
6
|
+
`}renderStalled(){return t`
|
|
7
|
+
<div class="b r p mb" role="alert">
|
|
8
|
+
<p class="tc-danger mb"><strong>The server did not come back within ten minutes.</strong></p>
|
|
9
|
+
<p class="mb">Check that the server process is running; if it is managed by pm2, systemd or Docker, check that it restarts when it exits.</p>
|
|
10
|
+
<button class="primary" @click=${()=>window.location.reload()}>Reload this page</button>
|
|
11
|
+
</div>
|
|
12
|
+
`}renderRestartNote(e){return"respawn"===e.restart?t`The site is unavailable for a few seconds while the server restarts.`:t`The server restarts, which takes a few seconds, and the site is unavailable until it is back.`}renderPlan(e){const{update:a,add:n,edited:i,forced:r}=e.files,o=e.upgrades.filter(e=>e.breaking),c=e.extensions.filter(e=>e.breaking),l=!(a.length||n.length||i.length||r.length||e.upgrades.length||e.extensions.length),h={permissions:["permission","permissions"],settings:["setting","settings"],groups:["group","groups"],widgets:["dashboard widget","dashboard widgets"],jobs:["scheduled job","scheduled jobs"]},d=e=>Object.entries(e.adds).filter(([,e])=>e).map(([e,t])=>m(t,...h[e])).join(", ");return t`
|
|
13
|
+
<ul class="mb">
|
|
14
|
+
${l?t`<li>Nothing changes except the code.</li>`:s}
|
|
15
|
+
${e.extensions.map(e=>t`<li>${e.name} ${e.from} <k-icon name="arrow" direction="right"></k-icon> ${e.to}${d(e)?t` <span class="tc-muted">adds ${d(e)}</span>`:s}</li>`)}
|
|
16
|
+
${a.length?t`<li>${m(a.length,"starter file","starter files")} you have not edited will be updated.</li>`:s}
|
|
17
|
+
${n.length?t`<li>${m(n.length,"new file","new files")} will be added.</li>`:s}
|
|
18
|
+
${i.length?t`<li>${m(i.length,"file","files")} you have edited will stay as you made ${1===i.length?"it":"them"}, even though Kempo has a newer version: <span class="tc-muted">${i.join(", ")}</span></li>`:s}
|
|
19
|
+
${r.length?t`<li class="tc-warning"><k-icon name="warning"></k-icon> ${m(r.length,"file","files")} you have edited must be replaced for security reasons. Your version is saved first: <span class="tc-muted">${r.join(", ")}</span></li>`:s}
|
|
20
|
+
${o.length?t`<li class="tc-warning"><k-icon name="warning"></k-icon> Kempo changes your data${o.some(e=>e.description)?t` (${o.map(e=>e.description).filter(Boolean).join("; ")})`:s}.</li>`:s}
|
|
21
|
+
${c.length?t`<li class="tc-warning"><k-icon name="warning"></k-icon> ${c.map(e=>e.name).join(", ")} ${1===c.length?"is a breaking update that":"are breaking updates that"} may change your data.</li>`:s}
|
|
22
|
+
${e.breaking?t`<li class="tc-warning"><k-icon name="warning"></k-icon> A backup of the database is taken first. Going back later restores it, which loses anything entered after the update.</li>`:s}
|
|
23
|
+
</ul>
|
|
24
|
+
`}renderStaged(e){const{staged:s}=e;return t`
|
|
25
|
+
<div class="b r p mb">
|
|
26
|
+
<h2 class="h4 mb">${m(s.packages.length,"update is","updates are")} ready</h2>
|
|
27
|
+
<p class="tc-muted mb">${s.packages.join(", ")}. ${1===s.packages.length?"It is":"They are"} downloaded next to your running site, which has not changed. Switching will:</p>
|
|
28
|
+
${this.renderPlan(s.plan)}
|
|
29
|
+
<p class="tc-muted mb">${this.renderRestartNote(e)}</p>
|
|
30
|
+
<button class="primary mr" @click=${()=>this.openConfirm("update")}>Switch now</button>
|
|
31
|
+
<button @click=${this.discard}>Not now</button>
|
|
32
|
+
</div>
|
|
33
|
+
`}renderRow(e,a){const n=this.blocked(e,a);return t`
|
|
34
|
+
<label class="d-f mb">
|
|
35
|
+
<input type="checkbox" class="mr" ?checked=${this.chosen.has(e.key)&&!n} ?disabled=${n||"idle"!==this.phase} @change=${()=>this.toggle(e.key)}>
|
|
36
|
+
<span><strong>${e.name}</strong> ${e.from} <k-icon name="arrow" direction="right"></k-icon> ${e.to}${e.major?t` <span class="tc-warning">breaking release</span>`:s}
|
|
37
|
+
${n?t`<small class="d-b tc-muted">Needs Kempo ${e.needs} or newer: tick Kempo as well.</small>`:s}</span>
|
|
38
|
+
</label>
|
|
39
|
+
`}renderAvailable(e){const a=this.updatable(e),n=this.chosenItems(),i=n.filter(e=>e.major);return t`
|
|
40
|
+
<div class="b r p mb">
|
|
41
|
+
<h2 class="h4 mb">${m(a.length,"update is","updates are")} available</h2>
|
|
42
|
+
<div class="mb">${a.map(t=>this.renderRow(t,e))}</div>
|
|
43
|
+
${i.length?t`<p class="tc-warning mb" role="alert"><k-icon name="warning"></k-icon> ${i.map(e=>e.name).join(", ")} ${1===i.length?"is a breaking release":"are breaking releases"} and may change how things work. Read ${1===i.length?"its":"their"} release notes before updating.</p>`:s}
|
|
44
|
+
${e.canUpdate?"release"===e.mode?t`
|
|
45
|
+
<p class="tc-muted mb">Getting them ready downloads them without touching your site. You choose when to switch.</p>
|
|
46
|
+
<button class="primary" ?disabled=${!n.length} @click=${this.prepare}>Get ${m(n.length,"update","updates")} ready</button>
|
|
47
|
+
`:t`
|
|
48
|
+
<p class="tc-muted mb">${this.renderRestartNote(e)}</p>
|
|
49
|
+
<button class="primary" ?disabled=${!n.length} @click=${()=>this.openConfirm("update")}>Update ${m(n.length,"item","items")}</button>
|
|
50
|
+
`:t`<p class="mb">${e.reason} Update where it is installed, then restart the server.</p>`}
|
|
51
|
+
</div>
|
|
52
|
+
`}renderCurrent(){return t`
|
|
53
|
+
<div class="b r p mb">
|
|
54
|
+
<h2 class="h4 mb"><k-icon name="check" class="tc-success"></k-icon> Everything is up to date</h2>
|
|
55
|
+
<p class="tc-muted">This site runs Kempo ${this.status.runningVersion}${this.status.latestVersion?", the newest version":""}, and its extensions are on their newest versions.</p>
|
|
56
|
+
</div>
|
|
57
|
+
`}renderLast(e){const a=e.lastUpdate;return!a||a.ok?s:t`
|
|
58
|
+
<div class="b r p mb" role="alert">
|
|
59
|
+
<h2 class="h5 mb tc-danger">The last update did not work</h2>
|
|
60
|
+
<p>The update of ${a.packages?.length?a.packages.join(", "):"Kempo"} on ${d(a.at)} did not stay running (${a.reason}), so the site went back to how it was.${a.breaking?" Your data was restored from the backup taken before it.":""}</p>
|
|
61
|
+
</div>
|
|
62
|
+
`}renderGoBack(e){if(!e.canGoBack)return s;const a=e.lastUpdate;return t`<p class="mb"><button @click=${()=>this.openConfirm("back")}>Go back</button> <span class="tc-muted">Puts the site back on what it ran before the last update${a?.ok&&a.packages?.length?` (${a.packages.join(", ")})`:""}.</span></p>`}renderDatabase(e){const{applied:a=[],failed:n=[]}=e.database??{},{upgraded:i=[],failed:r=[]}=e.extensionsRun??{};return t`
|
|
63
|
+
${n.length?t`
|
|
64
|
+
<div class="b r p mb" role="alert">
|
|
65
|
+
<h2 class="h5 mb tc-danger">The database needs attention</h2>
|
|
66
|
+
<p class="mb">Kempo started, but these changes to its tables were not applied. Anything that depends on them may not work until they are.</p>
|
|
67
|
+
<ul class="mb">
|
|
68
|
+
${n.map(({change:e,reason:s})=>t`<li>${e}: <span class="tc-danger">${s}</span></li>`)}
|
|
69
|
+
</ul>
|
|
70
|
+
<p class="tc-muted">Kempo only ever adds to its tables on its own. It never drops or changes anything that holds data, so these need someone who can look at the database.</p>
|
|
71
|
+
</div>
|
|
72
|
+
`:s}
|
|
73
|
+
${r.length?t`
|
|
74
|
+
<div class="b r p mb" role="alert">
|
|
75
|
+
<h2 class="h5 mb tc-danger">An extension could not be brought up to date</h2>
|
|
76
|
+
<ul class="mb">${r.map(({name:e,from:s,to:a,reason:n})=>t`<li>${e} ${s} <k-icon name="arrow" direction="right"></k-icon> ${a}: <span class="tc-danger">${n}</span></li>`)}</ul>
|
|
77
|
+
<p class="tc-muted">It is tried again the next time the server starts.</p>
|
|
78
|
+
</div>
|
|
79
|
+
`:s}
|
|
80
|
+
${a.length||i.length?t`
|
|
81
|
+
<div class="b r p mb">
|
|
82
|
+
<h2 class="h5 mb">Brought up to date when the server last started</h2>
|
|
83
|
+
<ul>
|
|
84
|
+
${i.map(({name:e,from:s,to:a})=>t`<li>${e} ${s} <k-icon name="arrow" direction="right"></k-icon> ${a}</li>`)}
|
|
85
|
+
${a.map(e=>t`<li>${e}</li>`)}
|
|
86
|
+
</ul>
|
|
87
|
+
</div>
|
|
88
|
+
`:s}
|
|
89
|
+
`}renderDialog(e){const a="back"===this.action,n=e.staged?.plan.files.forced??[],i=!a&&(e.staged?.plan.breaking??!1),r="release"===e.mode?e.staged?.packages??[]:this.chosen?this.chosenItems().map(e=>`${e.name} ${e.to}`):[];return t`
|
|
90
|
+
<k-dialog id="confirmDialog" confirm-text=${a?"Go back and restart":"Update and restart"} confirm-classes="primary ml" cancel-text="Cancel" .confirmAction=${this.confirmed}>
|
|
91
|
+
<h2 slot="title" class="h5 pyh px m0">${a?"Go back":"Update"}</h2>
|
|
92
|
+
<div class="p">
|
|
93
|
+
<p class="mb">${a?"This puts the site back on what it ran before the last update.":`This updates ${r.join(", ")}.`} ${this.renderRestartNote(e)}</p>
|
|
94
|
+
${n.length?t`<p class="tc-warning mb"><k-icon name="warning"></k-icon> Your edits to ${n.join(", ")} will be replaced. Your version is saved first.</p>`:s}
|
|
95
|
+
${i?t`<p class="tc-warning mb"><k-icon name="warning"></k-icon> This update changes your data. A backup is taken first, and going back later restores it, which loses anything entered after the update.</p>`:s}
|
|
96
|
+
${a&&e.lastUpdate?.breaking?t`<p class="tc-warning mb"><k-icon name="warning"></k-icon> The update changed your data, so going back restores the database from before it. Anything entered since is lost.</p>`:s}
|
|
97
|
+
<p class="tc-muted">Anyone using the site meanwhile will not be able to reach it. This page reloads when the server is back.</p>
|
|
98
|
+
</div>
|
|
99
|
+
</k-dialog>
|
|
100
|
+
`}render(){const e=this.status;if(this.error)return t`<p class="tc-danger" role="alert">${this.error}</p>`;if(!e)return t`<k-spinner></k-spinner>`;const a=this.updatable(e);return t`
|
|
101
|
+
${"idle"!==this.phase?this.renderBusy():s}
|
|
102
|
+
${this.stalled?this.renderStalled():s}
|
|
103
|
+
${"idle"===this.phase?t`
|
|
104
|
+
${this.renderLast(e)}
|
|
105
|
+
${this.renderDatabase(e)}
|
|
106
|
+
${e.staged?this.renderStaged(e):a.length?this.renderAvailable(e):this.renderCurrent()}
|
|
107
|
+
${e.checkError||e.extensionUpdates?.checkError?t`<p class="tc-danger mb" role="alert">The last check failed: ${e.checkError||e.extensionUpdates.checkError}</p>`:s}
|
|
108
|
+
<p class="d-f mb">
|
|
109
|
+
<button ?disabled=${this.checking} @click=${this.check}>${this.checking?"Checking…":"Check now"}</button>
|
|
110
|
+
<span class="tc-muted ph">Last checked ${d(e.checkedAt)}</span>
|
|
111
|
+
</p>
|
|
112
|
+
${this.renderGoBack(e)}
|
|
113
|
+
<p class="tc-muted">Automatic checks can be turned off with <strong>update_check_enabled</strong> on the System tab of <a href="/admin/settings">Settings</a>. Installing or removing an extension is done from <a href="/admin/extensions">Extensions</a>.</p>
|
|
114
|
+
`:s}
|
|
115
|
+
${this.renderDialog(e)}
|
|
116
|
+
`}}customElements.define("k-admin-updates",u);
|
|
117
|
+
//# sourceMappingURL=C:\Users\dusti\dev\kempo\dist\admin\components\Updates.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"src\\admin\\components\\Updates.js","names":["ShadowComponent","html","nothing","Toast","getUpdateStatus","checkForUpdate","prepareUpdate","applyUpdate","rollbackUpdate","discardUpdate","AFTER_RELOAD_KEY","when","value","Date","toLocaleString","sleep","ms","Promise","resolve","setTimeout","count","n","one","many","older","a","b","split","map","Number","reduce","result","part","index","Updates","static","status","state","error","checking","phase","stalled","action","chosen","constructor","super","this","connectedCallback","load","async","msg","selectNew","reportOutcome","updatable","updateAvailable","key","name","from","runningVersion","to","latestVersion","major","extensionUpdates","updates","update","installedVersion","needs","kempoRequired","seen","Set","has","add","blocked","item","Boolean","chosenItems","filter","toggle","next","delete","expected","JSON","parse","sessionStorage","getItem","removeItem","lastUpdate","ok","at","success","message","check","problem","checkError","length","staged","selection","items","version","some","extensions","prepare","discard","openConfirm","renderRoot","querySelector","open","confirmed","bootId","mode","data","breaking","confirm","forced","plan","files","packages","join","waitForServer","setItem","stringify","now","toISOString","window","location","reload","started","wasDown","res","fetch","credentials","cache","json","oldBootId","renderBusy","title","note","preparing","installing","switching","restarting","renderStalled","renderRestartNote","restart","renderPlan","edited","breakingUpgrades","upgrades","upgrade","breakingExtensions","extension","noChanges","labels","permissions","settings","groups","widgets","jobs","adds","Object","entries","what","description","renderStaged","renderRow","renderAvailable","selected","majors","canUpdate","reason","renderCurrent","renderLast","last","renderGoBack","canGoBack","renderDatabase","applied","failed","database","upgraded","extensionFailed","extensionsRun","change","renderDialog","back","render","checkedAt","customElements","define"],"sources":["0"],"sourcesContent":["import ShadowComponent from '/kempo-ui/components/ShadowComponent.js';\nimport { html, nothing } from '/kempo-ui/lit-all.min.js';\nimport '/kempo-ui/components/Spinner.js';\nimport '/kempo-ui/components/Dialog.js';\nimport '/kempo-ui/components/Icon.js';\nimport Toast from '/kempo-ui/components/Toast.js';\nimport { getUpdateStatus, checkForUpdate, prepareUpdate, applyUpdate, rollbackUpdate, discardUpdate } from '/kempo/sdk.js';\n\n/*\n The update screen, served at /admin/components/Updates.js:\n\n <k-admin-updates></k-admin-updates>\n\n Lists what is newer on npm than what the site runs: Kempo itself and each installed extension, which the server looks up\n every 12 hours (and when \"Check now\" is pressed). Each has a box; what is ticked is updated together.\n\n A site that runs from a Docker volume updates in two steps. \"Get ready\" downloads the new versions next to the running site,\n which keeps working, and shows what switching to them would change: starter files that will update, files you edited that\n stay, files that must be replaced anyway, what each extension adds, and any change to your data. \"Switch\" asks for your word\n where that is needed, then the server restarts on the new versions. A version that does not work puts the old ones back by\n itself, and \"Go back\" does it by hand. Any other site installs the update in place and restarts.\n\n While the server is gone this screen asks it, every couple of seconds, whether it is back, then reloads the page and says how\n it went. A server that does not come back in ten minutes is reported rather than waited on forever.\n*/\nconst POLL_MS = 2000;\nconst GIVE_UP_MS = 10 * 60 * 1000;\nconst AFTER_RELOAD_KEY = 'kempo-after-update';\n\nconst when = value => (value ? new Date(value).toLocaleString() : 'never');\n\nconst sleep = ms => new Promise(resolve => setTimeout(resolve, ms));\n\nconst count = (n, one, many) => `${n} ${n === 1 ? one : many}`;\n\nconst older = (a, b) => a.split('.').map(Number).reduce((result, part, index) => result || (part - Number(b.split('.')[index])), 0) < 0;\n\nexport default class Updates extends ShadowComponent {\n static properties = {\n status: { state: true },\n error: { state: true },\n checking: { state: true },\n phase: { state: true },\n stalled: { state: true },\n action: { state: true },\n chosen: { state: true },\n };\n\n constructor(){\n super();\n this.status = null;\n this.error = '';\n this.checking = false;\n this.phase = 'idle';\n this.stalled = false;\n this.action = 'update';\n this.chosen = null;\n }\n\n /*\n Lifecycle\n */\n connectedCallback(){\n super.connectedCallback();\n this.load();\n }\n\n /*\n Loading\n */\n load = async () => {\n const [error, status] = await getUpdateStatus();\n if(error){\n this.error = error.msg || 'The update status could not be loaded';\n return;\n }\n this.error = '';\n this.status = status;\n this.selectNew(status);\n this.reportOutcome();\n };\n\n /* Everything that can be updated, as { key, name, from, to, major, needs }: Kempo first, then the extensions. */\n updatable = status => [\n ...(status.updateAvailable ? [{ key: 'kempo', name: 'Kempo', from: status.runningVersion, to: status.latestVersion, major: status.major }] : []),\n ...(status.extensionUpdates?.updates ?? []).map(update => ({ key: update.name, name: update.name, from: update.installedVersion, to: update.latestVersion, major: update.major, needs: update.kempoRequired })),\n ];\n\n /* Everything that has just become available is ticked, once; what the person unticks stays unticked. */\n selectNew = status => {\n this.seen ??= new Set();\n const chosen = new Set(this.chosen ?? []);\n for(const { key } of this.updatable(status)){\n if(!this.seen.has(key)){\n this.seen.add(key);\n chosen.add(key);\n }\n }\n this.chosen = chosen;\n };\n\n /* An extension that needs a newer Kempo than the one running can only be chosen together with the Kempo update that provides it. */\n blocked = (item, status) => Boolean(item.needs) && older(status.runningVersion, item.needs) && !(this.chosen.has('kempo') && status.updateAvailable && !older(status.latestVersion, item.needs));\n\n chosenItems = () => this.updatable(this.status).filter(item => this.chosen.has(item.key) && !this.blocked(item, this.status));\n\n toggle = key => {\n const next = new Set(this.chosen);\n if(next.has(key)) next.delete(key);\n else next.add(key);\n this.chosen = next;\n };\n\n /* After the page reloads from an update: say whether the version that was asked for is the one now running. */\n reportOutcome = () => {\n try {\n const expected = JSON.parse(sessionStorage.getItem(AFTER_RELOAD_KEY) || 'null');\n if(!expected) return;\n sessionStorage.removeItem(AFTER_RELOAD_KEY);\n const failed = this.status.lastUpdate && !this.status.lastUpdate.ok && this.status.lastUpdate.at > expected.at;\n if(failed) Toast.error(`The update did not work, so the site went back to how it was`);\n else Toast.success(expected.message);\n } catch {\n /* storage can be blocked; the page has still reloaded */\n }\n };\n\n check = async () => {\n this.checking = true;\n const [error, status] = await checkForUpdate();\n this.checking = false;\n if(error){\n Toast.error(error.msg);\n return;\n }\n this.status = status;\n this.selectNew(status);\n const problem = status.checkError || status.extensionUpdates?.checkError;\n if(problem) Toast.error(problem);\n else if(!this.updatable(status).length && !status.staged) Toast.success('Everything is up to date');\n };\n\n /*\n Getting an update ready (Docker volume sites), or throwing it away\n */\n selection = () => {\n const items = this.chosenItems();\n return { version: items.some(item => item.key === 'kempo') ? this.status.latestVersion : null, extensions: items.filter(item => item.key !== 'kempo').map(item => item.key) };\n };\n\n prepare = async () => {\n this.phase = 'preparing';\n const [error] = await prepareUpdate(this.selection());\n this.phase = 'idle';\n if(error){\n Toast.error(error.msg);\n return;\n }\n await this.load();\n };\n\n discard = async () => {\n const [error] = await discardUpdate();\n if(error){\n Toast.error(error.msg);\n return;\n }\n await this.load();\n };\n\n /*\n Switching, updating in place and going back\n */\n openConfirm = action => {\n this.action = action;\n this.renderRoot.querySelector('#confirmDialog').open();\n };\n\n confirmed = async () => {\n const { staged, bootId, mode, lastUpdate } = this.status;\n this.stalled = false;\n let error;\n let result;\n let message;\n\n if(this.action === 'back'){\n this.phase = 'going-back';\n [error, result] = await rollbackUpdate({ data: Boolean(lastUpdate?.breaking) });\n message = 'The site is back on what it ran before the last update';\n } else if(mode === 'release'){\n this.phase = 'switching';\n [error, result] = await applyUpdate({ confirm: { forced: staged.plan.files.forced.length > 0, breaking: staged.plan.breaking } });\n message = `Updated: ${staged.packages.join(', ')}`;\n } else {\n this.phase = 'installing';\n const { version, extensions } = this.selection();\n [error, result] = await applyUpdate({ version, extensions });\n message = `Updated: ${this.chosenItems().map(item => `${item.name} ${item.to}`).join(', ')}`;\n }\n\n if(error){\n this.phase = 'idle';\n Toast.error(error.msg);\n return;\n }\n this.phase = 'restarting';\n if(await this.waitForServer(bootId)){\n try {\n sessionStorage.setItem(AFTER_RELOAD_KEY, JSON.stringify({ message, at: new Date(Date.now() - 5000).toISOString(), to: result.to }));\n } catch {\n /* the reload still shows what is running */\n }\n window.location.reload();\n return;\n }\n this.stalled = true;\n };\n\n /*\n True once a server that is not the one asked about answers. The old one may still answer for a moment after\n the request that restarts it, so a reply only counts if it carries a different boot id, or if the server\n has been seen gone first (any reply short of a server error then comes from the new one, even a sign-in\n redirect that has no boot id).\n */\n waitForServer = async oldBootId => {\n const started = Date.now();\n let wasDown = false;\n while(Date.now() - started < GIVE_UP_MS){\n await sleep(POLL_MS);\n try {\n const res = await fetch('/kempo/api/updates?offline=true', { credentials: 'same-origin', cache: 'no-store' });\n if(res.ok){\n if((await res.json()).bootId !== oldBootId) return true;\n } else if(res.status >= 500){\n wasDown = true;\n } else if(wasDown){\n return true;\n }\n } catch {\n wasDown = true;\n }\n }\n return false;\n };\n\n /*\n Rendering\n */\n renderBusy(){\n const [title, note] = {\n preparing: ['Downloading the updates…', 'Your site keeps working while this happens. It can take a few minutes.'],\n installing: ['Installing the updates…', 'This can take a minute.'],\n switching: ['Switching to the updates…', 'This can take a minute.'],\n 'going-back': ['Going back…', 'This can take a minute.'],\n restarting: ['Restarting the server…', 'This page reloads by itself when the site is back, and updated extensions are brought up to date first.'],\n }[this.phase];\n return html`\n <div class=\"b r p mb\" role=\"status\">\n <p class=\"d-f mb\"><k-spinner class=\"mr\"></k-spinner><strong>${title}</strong></p>\n <p class=\"tc-muted\">${note} Please keep this page open.</p>\n </div>\n `;\n }\n\n renderStalled(){\n return html`\n <div class=\"b r p mb\" role=\"alert\">\n <p class=\"tc-danger mb\"><strong>The server did not come back within ten minutes.</strong></p>\n <p class=\"mb\">Check that the server process is running; if it is managed by pm2, systemd or Docker, check that it restarts when it exits.</p>\n <button class=\"primary\" @click=${() => window.location.reload()}>Reload this page</button>\n </div>\n `;\n }\n\n renderRestartNote(status){\n return status.restart === 'respawn'\n ? html`The site is unavailable for a few seconds while the server restarts.`\n : html`The server restarts, which takes a few seconds, and the site is unavailable until it is back.`;\n }\n\n /* What switching to the prepared versions would change. */\n renderPlan(plan){\n const { update, add, edited, forced } = plan.files;\n const breakingUpgrades = plan.upgrades.filter(upgrade => upgrade.breaking);\n const breakingExtensions = plan.extensions.filter(extension => extension.breaking);\n const noChanges = !update.length && !add.length && !edited.length && !forced.length && !plan.upgrades.length && !plan.extensions.length;\n const labels = { permissions: ['permission', 'permissions'], settings: ['setting', 'settings'], groups: ['group', 'groups'], widgets: ['dashboard widget', 'dashboard widgets'], jobs: ['scheduled job', 'scheduled jobs'] };\n const adds = extension => Object.entries(extension.adds).filter(([, n]) => n).map(([what, n]) => count(n, ...labels[what])).join(', ');\n return html`\n <ul class=\"mb\">\n ${noChanges ? html`<li>Nothing changes except the code.</li>` : nothing}\n ${plan.extensions.map(extension => html`<li>${extension.name} ${extension.from} <k-icon name=\"arrow\" direction=\"right\"></k-icon> ${extension.to}${adds(extension) ? html` <span class=\"tc-muted\">adds ${adds(extension)}</span>` : nothing}</li>`)}\n ${update.length ? html`<li>${count(update.length, 'starter file', 'starter files')} you have not edited will be updated.</li>` : nothing}\n ${add.length ? html`<li>${count(add.length, 'new file', 'new files')} will be added.</li>` : nothing}\n ${edited.length ? html`<li>${count(edited.length, 'file', 'files')} you have edited will stay as you made ${edited.length === 1 ? 'it' : 'them'}, even though Kempo has a newer version: <span class=\"tc-muted\">${edited.join(', ')}</span></li>` : nothing}\n ${forced.length ? html`<li class=\"tc-warning\"><k-icon name=\"warning\"></k-icon> ${count(forced.length, 'file', 'files')} you have edited must be replaced for security reasons. Your version is saved first: <span class=\"tc-muted\">${forced.join(', ')}</span></li>` : nothing}\n ${breakingUpgrades.length ? html`<li class=\"tc-warning\"><k-icon name=\"warning\"></k-icon> Kempo changes your data${breakingUpgrades.some(upgrade => upgrade.description) ? html` (${breakingUpgrades.map(upgrade => upgrade.description).filter(Boolean).join('; ')})` : nothing}.</li>` : nothing}\n ${breakingExtensions.length ? html`<li class=\"tc-warning\"><k-icon name=\"warning\"></k-icon> ${breakingExtensions.map(extension => extension.name).join(', ')} ${breakingExtensions.length === 1 ? 'is a breaking update that' : 'are breaking updates that'} may change your data.</li>` : nothing}\n ${plan.breaking ? html`<li class=\"tc-warning\"><k-icon name=\"warning\"></k-icon> A backup of the database is taken first. Going back later restores it, which loses anything entered after the update.</li>` : nothing}\n </ul>\n `;\n }\n\n renderStaged(status){\n const { staged } = status;\n return html`\n <div class=\"b r p mb\">\n <h2 class=\"h4 mb\">${count(staged.packages.length, 'update is', 'updates are')} ready</h2>\n <p class=\"tc-muted mb\">${staged.packages.join(', ')}. ${staged.packages.length === 1 ? 'It is' : 'They are'} downloaded next to your running site, which has not changed. Switching will:</p>\n ${this.renderPlan(staged.plan)}\n <p class=\"tc-muted mb\">${this.renderRestartNote(status)}</p>\n <button class=\"primary mr\" @click=${() => this.openConfirm('update')}>Switch now</button>\n <button @click=${this.discard}>Not now</button>\n </div>\n `;\n }\n\n renderRow(item, status){\n const blocked = this.blocked(item, status);\n return html`\n <label class=\"d-f mb\">\n <input type=\"checkbox\" class=\"mr\" ?checked=${this.chosen.has(item.key) && !blocked} ?disabled=${blocked || this.phase !== 'idle'} @change=${() => this.toggle(item.key)}>\n <span><strong>${item.name}</strong> ${item.from} <k-icon name=\"arrow\" direction=\"right\"></k-icon> ${item.to}${item.major ? html` <span class=\"tc-warning\">breaking release</span>` : nothing}\n ${blocked ? html`<small class=\"d-b tc-muted\">Needs Kempo ${item.needs} or newer: tick Kempo as well.</small>` : nothing}</span>\n </label>\n `;\n }\n\n renderAvailable(status){\n const items = this.updatable(status);\n const selected = this.chosenItems();\n const majors = selected.filter(item => item.major);\n return html`\n <div class=\"b r p mb\">\n <h2 class=\"h4 mb\">${count(items.length, 'update is', 'updates are')} available</h2>\n <div class=\"mb\">${items.map(item => this.renderRow(item, status))}</div>\n ${majors.length ? html`<p class=\"tc-warning mb\" role=\"alert\"><k-icon name=\"warning\"></k-icon> ${majors.map(item => item.name).join(', ')} ${majors.length === 1 ? 'is a breaking release' : 'are breaking releases'} and may change how things work. Read ${majors.length === 1 ? 'its' : 'their'} release notes before updating.</p>` : nothing}\n ${status.canUpdate ? (status.mode === 'release' ? html`\n <p class=\"tc-muted mb\">Getting them ready downloads them without touching your site. You choose when to switch.</p>\n <button class=\"primary\" ?disabled=${!selected.length} @click=${this.prepare}>Get ${count(selected.length, 'update', 'updates')} ready</button>\n ` : html`\n <p class=\"tc-muted mb\">${this.renderRestartNote(status)}</p>\n <button class=\"primary\" ?disabled=${!selected.length} @click=${() => this.openConfirm('update')}>Update ${count(selected.length, 'item', 'items')}</button>\n `) : html`<p class=\"mb\">${status.reason} Update where it is installed, then restart the server.</p>`}\n </div>\n `;\n }\n\n renderCurrent(){\n return html`\n <div class=\"b r p mb\">\n <h2 class=\"h4 mb\"><k-icon name=\"check\" class=\"tc-success\"></k-icon> Everything is up to date</h2>\n <p class=\"tc-muted\">This site runs Kempo ${this.status.runningVersion}${this.status.latestVersion ? ', the newest version' : ''}, and its extensions are on their newest versions.</p>\n </div>\n `;\n }\n\n renderLast(status){\n const last = status.lastUpdate;\n if(!last || last.ok) return nothing;\n return html`\n <div class=\"b r p mb\" role=\"alert\">\n <h2 class=\"h5 mb tc-danger\">The last update did not work</h2>\n <p>The update of ${last.packages?.length ? last.packages.join(', ') : 'Kempo'} on ${when(last.at)} did not stay running (${last.reason}), so the site went back to how it was.${last.breaking ? ' Your data was restored from the backup taken before it.' : ''}</p>\n </div>\n `;\n }\n\n renderGoBack(status){\n if(!status.canGoBack) return nothing;\n const last = status.lastUpdate;\n return html`<p class=\"mb\"><button @click=${() => this.openConfirm('back')}>Go back</button> <span class=\"tc-muted\">Puts the site back on what it ran before the last update${last?.ok && last.packages?.length ? ` (${last.packages.join(', ')})` : ''}.</span></p>`;\n }\n\n renderDatabase(status){\n const { applied = [], failed = [] } = status.database ?? {};\n const { upgraded = [], failed: extensionFailed = [] } = status.extensionsRun ?? {};\n return html`\n ${failed.length ? html`\n <div class=\"b r p mb\" role=\"alert\">\n <h2 class=\"h5 mb tc-danger\">The database needs attention</h2>\n <p class=\"mb\">Kempo started, but these changes to its tables were not applied. Anything that depends on them may not work until they are.</p>\n <ul class=\"mb\">\n ${failed.map(({ change, reason }) => html`<li>${change}: <span class=\"tc-danger\">${reason}</span></li>`)}\n </ul>\n <p class=\"tc-muted\">Kempo only ever adds to its tables on its own. It never drops or changes anything that holds data, so these need someone who can look at the database.</p>\n </div>\n ` : nothing}\n ${extensionFailed.length ? html`\n <div class=\"b r p mb\" role=\"alert\">\n <h2 class=\"h5 mb tc-danger\">An extension could not be brought up to date</h2>\n <ul class=\"mb\">${extensionFailed.map(({ name, from, to, reason }) => html`<li>${name} ${from} <k-icon name=\"arrow\" direction=\"right\"></k-icon> ${to}: <span class=\"tc-danger\">${reason}</span></li>`)}</ul>\n <p class=\"tc-muted\">It is tried again the next time the server starts.</p>\n </div>\n ` : nothing}\n ${applied.length || upgraded.length ? html`\n <div class=\"b r p mb\">\n <h2 class=\"h5 mb\">Brought up to date when the server last started</h2>\n <ul>\n ${upgraded.map(({ name, from, to }) => html`<li>${name} ${from} <k-icon name=\"arrow\" direction=\"right\"></k-icon> ${to}</li>`)}\n ${applied.map(change => html`<li>${change}</li>`)}\n </ul>\n </div>\n ` : nothing}\n `;\n }\n\n renderDialog(status){\n const back = this.action === 'back';\n const forced = status.staged?.plan.files.forced ?? [];\n const breaking = !back && (status.staged?.plan.breaking ?? false);\n const items = status.mode === 'release' ? (status.staged?.packages ?? []) : this.chosen ? this.chosenItems().map(item => `${item.name} ${item.to}`) : [];\n return html`\n <k-dialog id=\"confirmDialog\" confirm-text=${back ? 'Go back and restart' : 'Update and restart'} confirm-classes=\"primary ml\" cancel-text=\"Cancel\" .confirmAction=${this.confirmed}>\n <h2 slot=\"title\" class=\"h5 pyh px m0\">${back ? 'Go back' : 'Update'}</h2>\n <div class=\"p\">\n <p class=\"mb\">${back ? 'This puts the site back on what it ran before the last update.' : `This updates ${items.join(', ')}.`} ${this.renderRestartNote(status)}</p>\n ${forced.length ? html`<p class=\"tc-warning mb\"><k-icon name=\"warning\"></k-icon> Your edits to ${forced.join(', ')} will be replaced. Your version is saved first.</p>` : nothing}\n ${breaking ? html`<p class=\"tc-warning mb\"><k-icon name=\"warning\"></k-icon> This update changes your data. A backup is taken first, and going back later restores it, which loses anything entered after the update.</p>` : nothing}\n ${back && status.lastUpdate?.breaking ? html`<p class=\"tc-warning mb\"><k-icon name=\"warning\"></k-icon> The update changed your data, so going back restores the database from before it. Anything entered since is lost.</p>` : nothing}\n <p class=\"tc-muted\">Anyone using the site meanwhile will not be able to reach it. This page reloads when the server is back.</p>\n </div>\n </k-dialog>\n `;\n }\n\n render(){\n const status = this.status;\n if(this.error) return html`<p class=\"tc-danger\" role=\"alert\">${this.error}</p>`;\n if(!status) return html`<k-spinner></k-spinner>`;\n const items = this.updatable(status);\n return html`\n ${this.phase !== 'idle' ? this.renderBusy() : nothing}\n ${this.stalled ? this.renderStalled() : nothing}\n ${this.phase === 'idle' ? html`\n ${this.renderLast(status)}\n ${this.renderDatabase(status)}\n ${status.staged ? this.renderStaged(status) : (items.length ? this.renderAvailable(status) : this.renderCurrent())}\n ${status.checkError || status.extensionUpdates?.checkError ? html`<p class=\"tc-danger mb\" role=\"alert\">The last check failed: ${status.checkError || status.extensionUpdates.checkError}</p>` : nothing}\n <p class=\"d-f mb\">\n <button ?disabled=${this.checking} @click=${this.check}>${this.checking ? 'Checking…' : 'Check now'}</button>\n <span class=\"tc-muted ph\">Last checked ${when(status.checkedAt)}</span>\n </p>\n ${this.renderGoBack(status)}\n <p class=\"tc-muted\">Automatic checks can be turned off with <strong>update_check_enabled</strong> on the System tab of <a href=\"/admin/settings\">Settings</a>. Installing or removing an extension is done from <a href=\"/admin/extensions\">Extensions</a>.</p>\n ` : nothing}\n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@@
|
|
|
1
|
+
import t from"/kempo-ui/components/ShadowComponent.js";import{html as e}from"/kempo-ui/lit-all.min.js";import"/kempo-ui/components/Tabs.js";import"./SettingsPanel.js";import s from"./humanize.js";export default class n extends t{static properties={extensionTabs:{state:!0}};constructor(){super(),this.extensionTabs=[]}connectedCallback(){super.connectedCallback(),this.extensionTabs=[...this.querySelectorAll(":scope > k-settings-tab")].map((t,e)=>{const n=t.getAttribute("name")||t.getAttribute("label")||`tab-${e}`;return t.slot=`tab-${n}`,t.style.display="block",{id:n,slotName:`tab-${n}`,label:t.getAttribute("label")||s(n),position:Number(t.getAttribute("position"))||500,extension:!0}})}render(){const t=[{id:"custom",label:"Custom",position:100,content:()=>e`<k-settings-panel owner="custom"></k-settings-panel>`},{id:"system",label:"System",position:200,content:()=>e`<k-settings-panel owner="system"></k-settings-panel>`},...this.extensionTabs].sort((t,e)=>t.position-e.position);return e`
|
|
2
|
+
<k-tabs>
|
|
3
|
+
${t.map(t=>e`<k-tab for=${t.id}>${t.label}</k-tab>`)}
|
|
4
|
+
${t.map(t=>e`<k-tab-content name=${t.id} class="pt">${t.extension?e`<slot name=${t.slotName}></slot>`:t.content()}</k-tab-content>`)}
|
|
5
|
+
</k-tabs>
|
|
6
|
+
`}}customElements.define("k-admin-settings",n);
|
|
7
|
+
//# sourceMappingURL=C:\Users\dusti\dev\kempo\dist\admin\components\settings\AdminSettings.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"src\\admin\\components\\settings\\AdminSettings.js","names":["ShadowComponent","html","humanize","AdminSettings","static","extensionTabs","state","constructor","super","this","connectedCallback","querySelectorAll","map","$tab","index","name","getAttribute","slot","style","display","id","slotName","label","position","Number","extension","render","tabs","content","sort","a","b","tab","customElements","define"],"sources":["0"],"sourcesContent":["import ShadowComponent from '/kempo-ui/components/ShadowComponent.js';\nimport { html } from '/kempo-ui/lit-all.min.js';\nimport '/kempo-ui/components/Tabs.js';\nimport './SettingsPanel.js';\nimport humanize from './humanize.js';\n\n/*\n The admin Settings page, served at /admin/components/settings/AdminSettings.js. Tabs: **Custom** (the site's own settings) and **System**\n (kempo's), then a tab for each extension that chooses to add one. An extension that does not add a tab has nothing here: it manages\n its own settings wherever it likes.\n\n **An extension adds a tab** by filling the `admin-settings-tabs` location of the page with a `k-settings-tab` (and loads what the tab\n uses from the `admin-settings-scripts` location). `position` orders the tabs (Custom is 100, System 200, a tab with none 500):\n\n <k-settings-tab name=\"shipping\" label=\"Shipping\" position=\"500\">\n <k-settings-panel owner=\"kempo-shipping\"></k-settings-panel>\n </k-settings-tab>\n\n The tab holds anything: the generic panel above, a few of the extension's settings with their editors, or a screen of its own.\n*/\nconst DEFAULT_TAB_POSITION = 500;\n\nexport default class AdminSettings extends ShadowComponent {\n static properties = {\n extensionTabs: { state: true },\n };\n\n constructor(){\n super();\n this.extensionTabs = [];\n }\n\n /*\n Lifecycle\n */\n connectedCallback(){\n super.connectedCallback();\n this.extensionTabs = [...this.querySelectorAll(':scope > k-settings-tab')].map(($tab, index) => {\n const name = $tab.getAttribute('name') || $tab.getAttribute('label') || `tab-${index}`;\n $tab.slot = `tab-${name}`;\n $tab.style.display = 'block';\n return {\n id: name,\n slotName: `tab-${name}`,\n label: $tab.getAttribute('label') || humanize(name),\n position: Number($tab.getAttribute('position')) || DEFAULT_TAB_POSITION,\n extension: true,\n };\n });\n }\n\n /*\n Rendering\n */\n render(){\n const tabs = [\n { id: 'custom', label: 'Custom', position: 100, content: () => html`<k-settings-panel owner=\"custom\"></k-settings-panel>` },\n { id: 'system', label: 'System', position: 200, content: () => html`<k-settings-panel owner=\"system\"></k-settings-panel>` },\n ...this.extensionTabs,\n ].sort((a, b) => a.position - b.position);\n\n return html`\n <k-tabs>\n ${tabs.map(tab => html`<k-tab for=${tab.id}>${tab.label}</k-tab>`)}\n ${tabs.map(tab => html`<k-tab-content name=${tab.id} class=\"pt\">${tab.extension ? html`<slot name=${tab.slotName}></slot>` : tab.content()}</k-tab-content>`)}\n </k-tabs>\n `;\n }\n}\n\ncustomElements.define('k-admin-settings', AdminSettings);\n"],"mappings":"OAAOA,MAAqB,yDACnBC,MAAY,iCACd,qCACA,4BACAC,MAAc,+BAkBN,MAAMC,UAAsBH,EACzCI,kBAAoB,CAClBC,cAAe,CAAEC,OAAO,IAG1B,WAAAC,GACEC,QACAC,KAAKJ,cAAgB,EACvB,CAKA,iBAAAK,GACEF,MAAME,oBACND,KAAKJ,cAAgB,IAAII,KAAKE,iBAAiB,4BAA4BC,IAAI,CAACC,EAAMC,KACpF,MAAMC,EAAOF,EAAKG,aAAa,SAAWH,EAAKG,aAAa,UAAY,OAAOF,IAG/E,OAFAD,EAAKI,KAAO,OAAOF,IACnBF,EAAKK,MAAMC,QAAU,QACd,CACLC,GAAIL,EACJM,SAAU,OAAON,IACjBO,MAAOT,EAAKG,aAAa,UAAYd,EAASa,GAC9CQ,SAAUC,OAAOX,EAAKG,aAAa,cAzBd,IA0BrBS,WAAW,IAGjB,CAKA,MAAAC,GACE,MAAMC,EAAO,CACX,CAAEP,GAAI,SAAUE,MAAO,SAAUC,SAAU,IAAKK,QAAS,IAAM3B,CAAI,wDACnE,CAAEmB,GAAI,SAAUE,MAAO,SAAUC,SAAU,IAAKK,QAAS,IAAM3B,CAAI,2DAChEQ,KAAKJ,eACRwB,KAAK,CAACC,EAAGC,IAAMD,EAAEP,SAAWQ,EAAER,UAEhC,OAAOtB,CAAI;;UAEL0B,EAAKf,IAAIoB,GAAO/B,CAAI,cAAc+B,EAAIZ,MAAMY,EAAIV;UAChDK,EAAKf,IAAIoB,GAAO/B,CAAI,uBAAuB+B,EAAIZ,iBAAiBY,EAAIP,UAAYxB,CAAI,cAAc+B,EAAIX,mBAAqBW,EAAIJ;;KAGvI,EAGFK,eAAeC,OAAO,mBAAoB/B","ignoreList":[]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{html as e}from"/kempo-ui/lit-all.min.js";import"/kempo-ui/components/Toggle.js";import t from"./SettingEditor.js";export default class i extends t{render(){return e`<div class="mb"><k-toggle ?disabled=${this.disabled} .value=${!0===this.value||"true"===this.value} @change=${e=>this.announce(!0===e.target.value)}>${this.heading}</k-toggle>${this.renderHint()}</div>`}}customElements.define("k-setting-boolean",i);
|
|
2
|
+
//# sourceMappingURL=C:\Users\dusti\dev\kempo\dist\admin\components\settings\BooleanSetting.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"src\\admin\\components\\settings\\BooleanSetting.js","names":["html","SettingEditor","BooleanSetting","render","this","disabled","value","event","announce","target","heading","renderHint","customElements","define"],"sources":["0"],"sourcesContent":["import { html } from '/kempo-ui/lit-all.min.js';\nimport '/kempo-ui/components/Toggle.js';\nimport SettingEditor from './SettingEditor.js';\n\n/* A boolean setting: a toggle with the name beside it and the description under it. */\nexport default class BooleanSetting extends SettingEditor {\n render(){\n return html`<div class=\"mb\"><k-toggle ?disabled=${this.disabled} .value=${this.value === true || this.value === 'true'} @change=${event => this.announce(event.target.value === true)}>${this.heading}</k-toggle>${this.renderHint()}</div>`;\n }\n}\n\ncustomElements.define('k-setting-boolean', BooleanSetting);\n"],"mappings":"eAASA,MAAY,iCACd,wCACAC,MAAmB,oCAGX,MAAMC,UAAuBD,EAC1C,MAAAE,GACE,OAAOH,CAAI,uCAAuCI,KAAKC,oBAAkC,IAAfD,KAAKE,OAAiC,SAAfF,KAAKE,iBAA4BC,GAASH,KAAKI,UAAgC,IAAvBD,EAAME,OAAOH,UAAmBF,KAAKM,qBAAqBN,KAAKO,oBAC1N,EAGFC,eAAeC,OAAO,oBAAqBX","ignoreList":[]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{html as t}from"/kempo-ui/lit-all.min.js";import e from"./SettingEditor.js";export default class i extends e{text="";willUpdate(t){if(!t.has("value"))return;let e;try{e=JSON.parse(this.text)}catch{e=void 0}void 0!==e&&JSON.stringify(e)===JSON.stringify(this.value)||(this.text=JSON.stringify(this.value??null,null,2))}change=t=>{this.text=t.target.value;try{this.announce(JSON.parse(this.text))}catch{this.announce(this.value,"That is not valid JSON")}};renderControl(){return t`<textarea class="ff-mono" rows="8" ?disabled=${this.disabled} .value=${this.text} @input=${this.change}></textarea>`}}customElements.define("k-setting-json",i);
|
|
2
|
+
//# sourceMappingURL=C:\Users\dusti\dev\kempo\dist\admin\components\settings\JsonSetting.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"src\\admin\\components\\settings\\JsonSetting.js","names":["html","SettingEditor","JsonSetting","text","willUpdate","changed","has","typed","JSON","parse","this","undefined","stringify","value","change","event","target","announce","renderControl","disabled","customElements","define"],"sources":["0"],"sourcesContent":["import { html } from '/kempo-ui/lit-all.min.js';\nimport SettingEditor from './SettingEditor.js';\n\n/*\n A JSON setting: the formatted JSON in a box. Text that is not JSON is reported as a problem and is not saved. What is typed is\n kept as typed (it is only formatted again when the value is set from outside), so the cursor does not jump while editing.\n*/\nexport default class JsonSetting extends SettingEditor {\n text = '';\n\n willUpdate(changed){\n if(!changed.has('value')) return;\n let typed;\n try { typed = JSON.parse(this.text); } catch { typed = undefined; }\n if(typed === undefined || JSON.stringify(typed) !== JSON.stringify(this.value)) this.text = JSON.stringify(this.value ?? null, null, 2);\n }\n\n change = event => {\n this.text = event.target.value;\n try {\n this.announce(JSON.parse(this.text));\n } catch {\n this.announce(this.value, 'That is not valid JSON');\n }\n };\n\n renderControl(){\n return html`<textarea class=\"ff-mono\" rows=\"8\" ?disabled=${this.disabled} .value=${this.text} @input=${this.change}></textarea>`;\n }\n}\n\ncustomElements.define('k-setting-json', JsonSetting);\n"],"mappings":"eAASA,MAAY,kCACdC,MAAmB,oCAMX,MAAMC,UAAoBD,EACvCE,KAAO,GAEP,UAAAC,CAAWC,GACT,IAAIA,EAAQC,IAAI,SAAU,OAC1B,IAAIC,EACJ,IAAMA,EAAQC,KAAKC,MAAMC,KAAKP,KAAO,CAAE,MAAQI,OAAQI,CAAW,MACrDA,IAAVJ,GAAuBC,KAAKI,UAAUL,KAAWC,KAAKI,UAAUF,KAAKG,SAAQH,KAAKP,KAAOK,KAAKI,UAAUF,KAAKG,OAAS,KAAM,KAAM,GACvI,CAEAC,OAASC,IACPL,KAAKP,KAAOY,EAAMC,OAAOH,MACzB,IACEH,KAAKO,SAAST,KAAKC,MAAMC,KAAKP,MAChC,CAAE,MACAO,KAAKO,SAASP,KAAKG,MAAO,yBAC5B,GAGF,aAAAK,GACE,OAAOlB,CAAI,gDAAgDU,KAAKS,mBAAmBT,KAAKP,eAAeO,KAAKI,oBAC9G,EAGFM,eAAeC,OAAO,iBAAkBnB","ignoreList":[]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{html as e}from"/kempo-ui/lit-all.min.js";import t from"./SettingEditor.js";export default class n extends t{change=e=>{const t=e.target.value,n=Number(t);""!==t.trim()&&Number.isFinite(n)?this.announce(n):this.announce(this.value,"Enter a number")};renderControl(){return e`<input type="number" step="any" ?disabled=${this.disabled} .value=${String(this.value??0)} @input=${this.change}>`}}customElements.define("k-setting-number",n);
|
|
2
|
+
//# sourceMappingURL=C:\Users\dusti\dev\kempo\dist\admin\components\settings\NumberSetting.js.map
|