@cossackframework/cms 0.9.3 → 0.9.5

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/app/src/auth.ts CHANGED
@@ -612,7 +612,7 @@ async function sendVerification(user: { id: string; email: string; name: string
612
612
  if (!mail || !origin) return;
613
613
  const token = await createLink('verify', user.id, VERIFICATION_TTL_MS);
614
614
  const title = await siteName().catch(() => '');
615
- await mail.send({ to: user.email, subject: `Confirm your email for ${title || 'the site'}`,
615
+ await mail.send({ kind: 'verification', to: user.email, subject: `Confirm your email for ${title || 'the site'}`,
616
616
  text: `Hello ${user.name || user.email},\n\nConfirm your email address to finish creating your account on ${title || origin}:\n${origin}/auth/verify?token=${token}\n\nThe link works for two days. If you did not register, ignore this email.` });
617
617
  }
618
618
 
@@ -1160,7 +1160,7 @@ export async function requestPasswordReset(email: string, resetBaseUrl: string):
1160
1160
  const mail = mailer();
1161
1161
  if (!mail) return; // send_email not configured: graceful no-op
1162
1162
  const resetUrl = `${resetBaseUrl.replace(/\/$/, '')}/auth/reset-password?token=${token}`;
1163
- await mail.send({ to: email, subject: 'Reset your password',
1163
+ await mail.send({ kind: 'reset', to: email, subject: 'Reset your password',
1164
1164
  text: `We received a request to reset your password. Choose a new one here; the link works for one hour:\n${resetUrl}\n\nIf you did not ask for it, ignore this email.` });
1165
1165
  }), undefined);
1166
1166
  }
@@ -1377,7 +1377,7 @@ export async function requestMagicLink(email: string, _requestOrigin?: string):
1377
1377
  if (!account || account.status !== 'active') return;
1378
1378
  const token = await createLink('magic', account.id, MAGIC_LINK_TTL_MS);
1379
1379
  const title = await siteName().catch(() => '');
1380
- await mail.send({ to: account.email, subject: `Sign in to ${title || 'the site'}`,
1380
+ await mail.send({ kind: 'magic-link', to: account.email, subject: `Sign in to ${title || 'the site'}`,
1381
1381
  text: `Open this link to sign in; it works once, for fifteen minutes:\n${origin}/auth/magic?token=${token}\n\nIf you did not ask for it, ignore this email.` });
1382
1382
  }), undefined);
1383
1383
  }
@@ -1691,7 +1691,7 @@ export async function sendInvitation(userId: string): Promise<boolean> {
1691
1691
  const token = await createPasswordResetToken(user.email, 7 * 24 * 60 * 60 * 1000);
1692
1692
  if (!token) return false;
1693
1693
  const title = currentTenant()?.name ?? await siteName().catch(() => '');
1694
- await mail.send({ to: user.email, subject: `You are invited to ${title || 'the site'}`,
1694
+ await mail.send({ kind: 'invitation', to: user.email, subject: `You are invited to ${title || 'the site'}`,
1695
1695
  text: `Hello ${user.name || user.email},\n\nAn account was made for you on ${title || origin}. Set your password here within seven days:\n${origin}/auth/reset-password?token=${token}\n\nIf you were not expecting this, ignore this email.` });
1696
1696
  return true;
1697
1697
  });
@@ -15,7 +15,9 @@ import { ormPeople } from './people';
15
15
  import { tenantSites } from './sites';
16
16
  import { accounts, asMainAccount, withTenant } from '../tenants';
17
17
  import { TenantMember } from '@/models/TenantMember';
18
- import registry from 'virtual:cossack-pages';
18
+ // The page files' names only. The pages registry imports every layout on the server, and the
19
+ // layouts import this module: through the registry it would import itself (requests.md C8).
20
+ import pageFiles from 'virtual:cossack-page-files';
19
21
 
20
22
  /**
21
23
  * The environment bindings the CMS application reads. The project's storage (`storage` in
@@ -156,7 +158,7 @@ export function networkFor(env: CmsBindings): CmsNetwork {
156
158
  ...(siteMail ? { mail: siteMail } : {}),
157
159
  // An entry's slug cannot take the address of a page: the CMS's routes, every page file of the
158
160
  // application (the project's, the CMS's and plugins'), and what the project names itself.
159
- reservedPaths: [...new Set([...DEFAULT_RESERVED_PATHS, ...reservedRouteSegments(Object.keys(registry.pages)), ...(project.reservedPaths ?? [])])],
161
+ reservedPaths: [...new Set([...DEFAULT_RESERVED_PATHS, ...reservedRouteSegments(pageFiles), ...(project.reservedPaths ?? [])])],
160
162
  }));
161
163
  },
162
164
  });
@@ -5,7 +5,7 @@
5
5
  */
6
6
  import {
7
7
  ENTRY_VIEW_REFUSED_BLOCKS, siteEntryView, validateBlocks, type EntryViewParts,
8
- ANONYMOUS, ARTICLE_TYPES, withContentFields, authorUrl, entryAuthors, blockDocuments, SHARE_BRAND_URLS, blockIsData, blocksPlain, editedSize, fieldGroupDeclarations, hasBlockReference, parseBlockText, PATTERN_REFERENCE, resolveBindings, resolveBlockBindings, siteBindingScope, textBlocks, usesUserBinding, type BindingScopes, type ParsedText, flattenBlocks, escapeHtml, formatSiteDate, formInputs, formSettings, imageSrcset, imageUrl, imageWidths, IMAGE_WIDTHS, isCmsError, languageFlag, languageName, mediaUrl, notificationRules, recordTitle, resolvePresets, richTextBlocks, richTextParts, richTextPlain, systemPrincipal, templateCandidates, transformable, urlList,
8
+ ANONYMOUS, ARTICLE_TYPES, slugify, withContentFields, authorUrl, entryAuthors, blockDocuments, SHARE_BRAND_URLS, blockIsData, blocksPlain, editedSize, fieldGroupDeclarations, hasBlockReference, parseBlockText, PATTERN_REFERENCE, resolveBindings, resolveBlockBindings, siteBindingScope, textBlocks, usesUserBinding, type BindingScopes, type ParsedText, flattenBlocks, escapeHtml, formatSiteDate, formInputs, formSettings, imageSrcset, imageUrl, imageWidths, IMAGE_WIDTHS, isCmsError, languageFlag, languageName, mediaUrl, notificationRules, recordTitle, resolvePresets, richTextBlocks, richTextParts, richTextPlain, systemPrincipal, templateCandidates, transformable, urlList,
9
9
  type AuthorView, type Block,
10
10
  type Principal, type TemplatePage, type ThemeData, type ThemePresets,
11
11
  type ArchiveView, type BodyPart, type BrandIcon, type CollectionDefinition, type CommentShape, type CommentView, type CommentsView, type EntryReference, type EntryView, type FieldDeclaration, type FieldFilter,
@@ -547,23 +547,34 @@ function docMediaIds(cms: CmsHost, doc: RichTextDoc, into: Set<string>): void {
547
547
  }
548
548
  }
549
549
 
550
- /** Synced patterns the blocks and documents use, by ID: their blocks. Patterns inside patterns are not expanded. */
550
+ /**
551
+ * Synced patterns the blocks and documents use: their blocks, by ID, and by the name a
552
+ * `{{ pattern … /}}` gave. Patterns have no slug field, so that name is a pattern's ID or the
553
+ * slug of its title. Patterns inside patterns are not expanded.
554
+ */
551
555
  async function usedPatterns(cms: CmsHost, docs: readonly RichTextDoc[], blocks: readonly Block[] = []): Promise<Map<string, Block[]>> {
552
556
  const all = [...docs.flatMap(doc => richTextBlocks(doc)), ...flattenBlocks(blocks)];
553
557
  const ids = [...new Set(all.filter(block => block.type === 'core/pattern').map(block => String(block.data.pattern ?? '')))].filter(Boolean);
554
- // `{{ pattern hero /}}` in text names a pattern by its slug.
555
- const slugs = [...new Set(all.flatMap(block => referencedBlocks(cms, block as { type: string; data: Record<string, unknown> })).filter(block => block.type === PATTERN_REFERENCE).map(block => String(block.data.pattern ?? '')))].filter(Boolean).slice(0, 50);
556
- if (!ids.length && !slugs.length) return new Map();
557
- try {
558
- const repository = cms.resource('cms/patterns');
559
- const patterns = ids.length ? await repository.getMany(ids, renderer) : new Map<string, RecordShape>();
560
- const named = slugs.length ? (await repository.list({ where: { slug: { in: slugs } }, limit: 50 }, renderer)).records : [];
561
- return new Map([...[...patterns].flatMap(([id, record]) => Array.isArray(record.content) ? [[id, record.content as Block[]] as const] : []),
562
- ...named.flatMap(record => Array.isArray(record.content) && typeof record.slug === 'string' ? [[record.slug, record.content as Block[]] as const] : [])]);
563
- } catch (error) {
564
- if (isCmsError(error)) return new Map();
565
- throw error;
566
- }
558
+ const names = [...new Set(all.flatMap(block => referencedBlocks(cms, block as { type: string; data: Record<string, unknown> })).filter(block => block.type === PATTERN_REFERENCE).map(block => String(block.data.pattern ?? '')))].filter(Boolean).slice(0, 50);
559
+ if (!ids.length && !names.length) return new Map();
560
+ const repository = cms.resource('cms/patterns');
561
+ const found = new Map<string, Block[]>();
562
+ const keep = (key: string, record: RecordShape) => { if (Array.isArray(record.content)) found.set(key, record.content as Block[]); };
563
+ const guarded = async (read: () => Promise<void>) => {
564
+ try { await read(); } catch (error) { if (!isCmsError(error)) throw error; }
565
+ };
566
+ await guarded(async () => {
567
+ for (const [id, record] of await repository.getMany([...new Set([...ids, ...names])], renderer)) keep(id, record);
568
+ });
569
+ const unnamed = names.filter(name => !found.has(name));
570
+ if (unnamed.length) await guarded(async () => {
571
+ const { records } = await repository.list({ limit: 100 }, renderer);
572
+ for (const record of records) {
573
+ const name = typeof record.title === 'string' ? slugify(record.title) : '';
574
+ if (unnamed.includes(name) && !found.has(name)) keep(name, record);
575
+ }
576
+ });
577
+ return found;
567
578
  }
568
579
 
569
580
  /**
package/app/src/mail.ts CHANGED
@@ -3,7 +3,7 @@
3
3
  // for `GET /api/cms/dev/mail`.
4
4
  import { currentCms } from './cms/index';
5
5
 
6
- export interface Mail { to: string; subject: string; text: string }
6
+ export interface Mail { to: string; subject: string; text: string; kind?: 'verification' | 'reset' | 'magic-link' | 'invitation' | 'other' }
7
7
 
8
8
  /** The site's mailer, or null when the site has no email sender. */
9
9
  export function mailer(): { send(mail: Mail): Promise<void> } | null {
@@ -11,5 +11,5 @@ export function mailer(): { send(mail: Mail): Promise<void> } | null {
11
11
  try { cms = currentCms(); } catch { return null; }
12
12
  const mail = cms.mail;
13
13
  if (!mail) return null;
14
- return { async send(message) { await mail.send({ to: message.to, from: cms.mailFrom, subject: message.subject, text: message.text }); } };
14
+ return { async send(message) { await mail.send({ ...(message.kind ? { kind: message.kind } : {}), to: message.to, from: cms.mailFrom, subject: message.subject, text: message.text }); } };
15
15
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cossackframework/cms",
3
- "version": "0.9.3",
3
+ "version": "0.9.5",
4
4
  "type": "module",
5
5
  "description": "Cossack CMS: resources, schema planning, repositories, auth and stores on RomeDB",
6
6
  "license": "MIT",
@@ -33,20 +33,20 @@
33
33
  "markdown-it": "15.0.3",
34
34
  "prosemirror-collab": "1.3.1",
35
35
  "uqr": "0.1.3",
36
- "@cossackframework/core": "0.9.3",
37
- "@cossackframework/renderer": "0.9.3",
38
- "@cossackframework/romedb": "0.9.3",
39
- "@cossackframework/auth": "0.9.3",
40
- "@cossackframework/database": "0.9.3"
36
+ "@cossackframework/core": "0.9.5",
37
+ "@cossackframework/auth": "0.9.5",
38
+ "@cossackframework/romedb": "0.9.5",
39
+ "@cossackframework/renderer": "0.9.5",
40
+ "@cossackframework/database": "0.9.5"
41
41
  },
42
42
  "peerDependencies": {
43
43
  "@aws-sdk/client-s3": "^3.1156.0",
44
44
  "hono": "^4.13.18",
45
45
  "sharp": "^0.35.5",
46
46
  "vite": "*",
47
- "@cossackframework/node-adapter": "0.9.3",
48
- "@cossackframework/framework": "0.9.3",
49
- "@cossackframework/ui": "0.9.3"
47
+ "@cossackframework/node-adapter": "0.9.5",
48
+ "@cossackframework/ui": "0.9.5",
49
+ "@cossackframework/framework": "0.9.5"
50
50
  },
51
51
  "devDependencies": {
52
52
  "@aws-sdk/client-s3": "^3.1156.0",
@@ -59,8 +59,8 @@
59
59
  "simple-icons": "16.36.0",
60
60
  "vite": "^8.1.6",
61
61
  "vitest": "^4.1.12",
62
- "@cossackframework/framework": "0.9.3",
63
- "@cossackframework/node-adapter": "0.9.3"
62
+ "@cossackframework/framework": "0.9.5",
63
+ "@cossackframework/node-adapter": "0.9.5"
64
64
  },
65
65
  "exports": {
66
66
  ".": "./src/index.ts",
@@ -118,7 +118,25 @@
118
118
  "models/TenantNetwork.ts",
119
119
  "models/TenantSession.ts"
120
120
  ],
121
- "hostTemplate": "0.9.0"
121
+ "hostTemplate": "0.9.3",
122
+ "hostSteps": {
123
+ "0.9.3": [
124
+ "src/bootstrap/middlewares.ts: import { ormRequestMiddleware } from '../middlewares/orm' and list ormRequestMiddleware first, before ...cmsMiddlewares.",
125
+ "package.json scripts: \"migrate\": \"cossack migration up\" and \"schema:check\": \"cossack schema check\".",
126
+ "Accounts, sessions and roles are the dashboard's, in ORM models on the CMS's RomeDB database: orm.config.ts, src/orm/, src/models/, src/migrations/, src/seeders/ and src/middlewares/orm.ts. cossack upgrade writes those the project lacks; a folder the project already has is left as it is, so compare it with a project that cossack create --features cms makes.",
127
+ "The CMS's own account tables are gone, and nothing moves their rows: make the first account again at /auth/setup."
128
+ ]
129
+ },
130
+ "hostFiles": {
131
+ "0.9.3": [
132
+ "orm.config.ts",
133
+ "src/orm/",
134
+ "src/models/",
135
+ "src/migrations/",
136
+ "src/seeders/",
137
+ "src/middlewares/orm.ts"
138
+ ]
139
+ }
122
140
  },
123
141
  "peerDependenciesMeta": {
124
142
  "@aws-sdk/client-s3": {
@@ -5,7 +5,7 @@
5
5
  * {{ block core/button label="Buy {{ $.title }}" url="/cart" /}} a block without a body
6
6
  * {{ block core/button }}Price is {{ $.price }}{{ /block }} a body fills the type's `body` field
7
7
  * {{ block core/group }} …blocks and text… {{ /block }} a container's body is its children
8
- * {{ pattern hero /}} a synced pattern by slug
8
+ * {{ pattern hero /}} a synced pattern by ID or title slug
9
9
  * \{{ … }} written as is
10
10
  *
11
11
  * Only block types that declare `inline: true` can be referenced. The parser turns text into
@@ -30,7 +30,7 @@ export function hasBlockReference(value: unknown): value is string {
30
30
  return typeof value === 'string' && /(?<!\\)\{\{\s*(?:block|pattern|\/block)\b/.test(value);
31
31
  }
32
32
 
33
- /** The pattern a `{{ pattern … }}` names, kept as a `core/pattern` block whose `pattern` is the slug until the site resolves it. */
33
+ /** The pattern a `{{ pattern … }}` names, kept as a `core/pattern` block whose `pattern` is the name until the site resolves it. */
34
34
  export const PATTERN_REFERENCE = 'core/pattern';
35
35
 
36
36
  type Tag =
@@ -142,7 +142,7 @@ function parseTag(inner: string): Tag | string | null {
142
142
  if (typeof tokens === 'string') return tokens;
143
143
  const [first, ...others] = tokens;
144
144
  if (keyword === 'pattern') {
145
- if (!first || first.value !== undefined || others.length) return '{{ pattern … /}} names one pattern by its slug.';
145
+ if (!first || first.value !== undefined || others.length) return '{{ pattern … /}} names one pattern by its ID or the slug of its title.';
146
146
  return { kind: 'pattern', ref: first.name };
147
147
  }
148
148
  if (!first || first.value !== undefined || !NAME.test(first.name)) return `{{ block ${rest.trim()} }} names no block type, such as core/button.`;
package/src/theme.ts CHANGED
@@ -991,7 +991,7 @@ export interface SiteTheme {
991
991
  }
992
992
 
993
993
  /** Template files that fill the theme's named slots; every other file is a specific template. */
994
- const TEMPLATE_FILES: { readonly [stem: string]: keyof SiteTheme } = { layout: 'layout', entry: 'entry', archive: 'archive', home: 'home', search: 'search', 'not-found': 'notFound', head: 'head', password: 'password' };
994
+ const TEMPLATE_FILES: { readonly [stem: string]: keyof SiteTheme } = { layout: 'layout', entry: 'entry', archive: 'archive', home: 'home', search: 'search', 'not-found': 'notFound', head: 'head', password: 'password', members: 'members' };
995
995
  /** Names a specific template can have. */
996
996
  export const SPECIFIC_TEMPLATE = /^(?:entry-[a-z][a-z0-9_-]*|archive-[a-z][a-z0-9_-]*|term(?:-[a-z][a-z0-9_-]*)?|author)$/;
997
997
 
@@ -1056,7 +1056,7 @@ export function siteThemeProblems(theme: unknown): string[] {
1056
1056
  const value = theme as { [name: string]: unknown };
1057
1057
  const problems: string[] = [];
1058
1058
  for (const name of ['layout', 'entry', 'archive']) if (typeof value[name] !== 'function') problems.push(`theme.${name} must be a function.`);
1059
- for (const name of ['home', 'search', 'notFound', 'head']) if (value[name] !== undefined && typeof value[name] !== 'function') problems.push(`theme.${name} must be a function.`);
1059
+ for (const name of ['home', 'search', 'notFound', 'head', 'password', 'members']) if (value[name] !== undefined && typeof value[name] !== 'function') problems.push(`theme.${name} must be a function.`);
1060
1060
  if (value.templates !== undefined) {
1061
1061
  if (typeof value.templates !== 'object' || value.templates === null) problems.push('theme.templates must map template names to functions.');
1062
1062
  else for (const [name, template] of Object.entries(value.templates)) {
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  /** The version of this package. A test keeps it equal to `package.json`. */
2
- export const CMS_VERSION = '0.9.3';
2
+ export const CMS_VERSION = '0.9.5';