diff --git a/.changeset/38372-starter-help-articles.md b/.changeset/38372-starter-help-articles.md new file mode 100644 index 00000000000..87ebf5c5688 --- /dev/null +++ b/.changeset/38372-starter-help-articles.md @@ -0,0 +1,11 @@ +--- +'@objectstack/example-starter': patch +'create-objectstack': patch +--- + +feat(example-starter, create-objectstack): help articles in the Starter app and the blank template + +Clause-②: no +Metadata-protocol: none + +The Starter app and the project `npm create objectstack` scaffolds now start with help articles: an Article object (`biz_article` in the Starter, `_article` in a new project) with a title, a Markdown body, a category (How-to, FAQ, Reference) and a status (Draft by default, Published), a grid of every article, an Articles entry in the menu between Contacts and Tasks, and four sample articles of generic office help (setting up a laptop, a Wi-Fi and printing FAQ, a meeting rooms reference, and a draft on sharing files). Each sample body opens with the article's title as a `#` heading, then one `##` section per topic. The Starter labels the articles in English and Simplified Chinese; a new project's labels are the English ones in its source. A new project also gains `src/data/`, the sample rows seeded on each boot, listed by name in `data` in `objectstack.config.ts`. Neither app declares a knowledge source. diff --git a/examples/app-starter/README.md b/examples/app-starter/README.md index 9f97e37a57b..6a7e9046dc7 100644 --- a/examples/app-starter/README.md +++ b/examples/app-starter/README.md @@ -1,23 +1,29 @@ # @objectstack/example-starter — Starter app A small, complete app an organization installs and then makes its own: -companies, the people at them, and the platform's tasks and notes in one menu. +companies, the people at them, help articles, and the platform's tasks and +notes in one menu. - `src/objects/` — `biz_company` (name, type, industry, website, phone, address) and `biz_contact` (name, company, job title, influence, email, phone). A contact is a person outside the organization, never a user. -- `src/views/` — a grid and a board for each object. The create and edit form - is each object's `fieldGroups`; the company's record page lists its contacts. -- `src/apps/` — the menu: companies, contacts, tasks (`sys_task`), notes + `biz_article` (title, Markdown body, category, status) holds help articles: + how-tos, common questions and reference pages. +- `src/views/` — a grid and a board for companies and for contacts, a grid of + articles. The create and edit form is each object's `fieldGroups`; the + company's record page lists its contacts. +- `src/apps/` — the menu: companies, contacts, articles, tasks (`sys_task`), notes (`sys_note`), and the overview dashboard. Tasks and notes are platform objects every environment carries; this package declares no copy of them. - `src/datasets/`, `src/dashboards/` — one overview dashboard. -- `src/data/` — five sample companies and six sample contacts. +- `src/data/` — five sample companies, six sample contacts, and four help + articles (setting up a laptop, a Wi-Fi and printing FAQ, a meeting rooms + reference, and a draft on sharing files). - `src/translations/` — English and Simplified Chinese. The API names carry the `biz_` namespace, so a tenant can install this starter beside a CRM package without a name clash. Uninstalling the package -removes companies and contacts; tasks and notes stay. +removes companies, contacts and articles; tasks and notes stay. ## How to run diff --git a/examples/app-starter/objectstack.config.ts b/examples/app-starter/objectstack.config.ts index a5b0560fd30..ce00c48d4ea 100644 --- a/examples/app-starter/objectstack.config.ts +++ b/examples/app-starter/objectstack.config.ts @@ -11,12 +11,13 @@ import * as translations from './src/translations/index.js'; import { StarterSeedData } from './src/data/index.js'; /** - * Starter app — companies and the people at them, with the platform's tasks - * and notes in the same menu. + * Starter app — companies and the people at them, and help articles, with the + * platform's tasks and notes in the same menu. * - * A small, complete app an organization installs and then makes its own: two - * objects (`biz_company`, `biz_contact`), a grid and a board for each, - * the company's contacts on its record page, sample rows, and one dashboard. + * A small, complete app an organization installs and then makes its own: + * companies and contacts (`biz_company`, `biz_contact`) with a grid and a + * board for each and the company's contacts on its record page, help articles + * (`biz_article`) with a grid, sample rows, and one dashboard. * Tasks and notes are not part of the package: the menu points at the * platform's `sys_task` and `sys_note`, so they stay when the package goes. */ diff --git a/examples/app-starter/src/apps/starter.app.ts b/examples/app-starter/src/apps/starter.app.ts index ce8f4ad19aa..ff8c9fbac86 100644 --- a/examples/app-starter/src/apps/starter.app.ts +++ b/examples/app-starter/src/apps/starter.app.ts @@ -3,8 +3,8 @@ import { App } from '@objectstack/spec/ui'; /** - * The starter's menu: the package's companies and contacts, then the - * platform's tasks and notes, then the overview dashboard. + * The starter's menu: the package's companies, contacts and help articles, + * then the platform's tasks and notes, then the overview dashboard. * * Tasks and notes are the platform objects `sys_task` and `sys_note`, which * every environment carries; the package declares no copy of them, so @@ -22,6 +22,7 @@ export const StarterApp = App.create({ navigation: [ { id: 'nav_companies', type: 'object', objectName: 'biz_company', icon: 'building-2' }, { id: 'nav_contacts', type: 'object', objectName: 'biz_contact', icon: 'contact' }, + { id: 'nav_articles', type: 'object', objectName: 'biz_article', icon: 'book-open' }, // `requiresObject` names the object again because `defineStack` refuses a // menu entry for an object the stack does not declare unless the entry // says the object comes from elsewhere — here, the platform. diff --git a/examples/app-starter/src/data/articles.ts b/examples/app-starter/src/data/articles.ts new file mode 100644 index 00000000000..6574e42d3ca --- /dev/null +++ b/examples/app-starter/src/data/articles.ts @@ -0,0 +1,125 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +// Sample help articles, generic office help rather than policy text. Business +// data like the companies and contacts (`index.ts`): no `mode`, so a replay +// inserts a missing article and leaves an existing one as the organization +// left it. +// +// Each `body` is Markdown in one shape, readable section by section: the +// title as a `#` heading, then 3 to 6 `##` sections, each with its own text +// and under 800 characters with its heading; the reference article carries a +// table followed by a one-line note. `test/help-articles-38372.test.ts` holds +// every article to that shape, and the blank template in create-objectstack +// carries the same seed (its parity test compares the two). + +import { defineSeed } from '@objectstack/spec/data'; +import { Article } from '../objects/article.object.js'; + +export const articles = defineSeed(Article, { + externalId: 'title', + records: [ + { + title: 'Set up your new laptop', + category: 'how_to', + status: 'published', + body: `# Set up your new laptop + +## Before you start + +Have your work email address and the temporary password from your welcome message at hand. Plug the laptop into power: the first start installs updates and can take up to half an hour. + +## Sign in for the first time + +Choose your language and keyboard, join the office Wi-Fi, then sign in with your work email and the temporary password. You are asked to choose a new password straight away; pick one you have not used anywhere else. + +## Install the apps you need + +Open the company app store from the start menu. Email, calendar, chat and the office suite install on their own; anything your team uses on top of that is listed under your department. Ask your manager if an app you need is missing. + +## Turn on backup + +Sign in to the file storage app and let it back up your Desktop and Documents folders. Files saved there follow you to a new laptop and can be restored if this one is lost. + +## Get help + +If something does not work, write to the IT help desk with the laptop's name, which is on the sticker underneath, and a screenshot of any error.`, + }, + { + title: 'Wi-Fi and printing FAQ', + category: 'faq', + status: 'published', + body: `# Wi-Fi and printing FAQ + +## How do I join the office Wi-Fi? + +Pick the network named Office and sign in with your work email and password. Guests use the Office-Guest network; its password is on the card at reception and changes every Monday. + +## Why does the Wi-Fi keep dropping? + +Most drops happen when a laptop moves between floors. Turn Wi-Fi off and on again, and forget any old office network your laptop still remembers. If it keeps happening at one desk, tell the help desk which desk it is. + +## How do I add a printer? + +Open the printer settings, choose Add printer and pick the one whose name matches the label on the machine. Printers are named by floor, so the second-floor printer starts with F2. + +## Why is my print job stuck? + +A job usually waits because the printer is out of paper or needs a release at the machine. Tap your badge on the printer to release your jobs. Jobs that are not released within a day are deleted. + +## Can I print from my phone? + +Yes. Email the file from your work account to the print address shown on the printer's screen, then release it with your badge as usual.`, + }, + { + title: 'Meeting rooms reference', + category: 'reference', + status: 'published', + body: `# Meeting rooms reference + +## Rooms at a glance + +| Room | Floor | Seats | Equipment | +| --- | --- | --- | --- | +| Harbor | 1 | 4 | Screen | +| Summit | 2 | 8 | Screen, video bar, whiteboard | +| Grove | 2 | 12 | Projector, video bar | +| Atrium | 3 | 20 | Projector, microphones | + +Seat counts are for seated meetings; a short stand-up fits a few more people. + +## Booking a room + +Book rooms from your calendar by adding the room as a guest. A booking longer than two hours, or one that repeats every week, needs a reason in the invitation so others know whether to ask for the room. + +## Video calls + +Rooms with a video bar join a call from the calendar invitation: press Join on the room's touch panel. In other rooms, connect your laptop to the screen with the cable on the table. + +## Leaving the room + +End the meeting on time, wipe the whiteboard, and take your cups with you. If you finish early, release the room from your calendar so someone else can use it.`, + }, + { + title: 'Share files with your team', + category: 'how_to', + status: 'draft', + body: `# Share files with your team + +## Pick the right place + +Keep files your whole team works on in the team's shared folder, not in your own. A file in a shared folder stays with the team when someone leaves or changes roles. + +## Share a file or folder + +Right-click the file in the file storage app, choose Share, and add people by name or add the whole team. Each person gets an email with a link. + +## Choose who can edit + +Give edit access to the people who will change the file and view access to everyone else. Links that anyone can open are turned off for files that hold customer details. + +## Stop sharing + +Open Share again and remove a person, or change their access to view only. Review who has access to a folder when a project ends.`, + }, + ], +}); diff --git a/examples/app-starter/src/data/index.ts b/examples/app-starter/src/data/index.ts index 189da3c435b..a380b985335 100644 --- a/examples/app-starter/src/data/index.ts +++ b/examples/app-starter/src/data/index.ts @@ -3,11 +3,12 @@ import { defineSeed } from '@objectstack/spec/data'; import { Company } from '../objects/company.object.js'; import { Contact } from '../objects/contact.object.js'; +import { articles } from './articles.js'; // Sample data, so the menu, the boards and the dashboard have something to -// show on first open. Business data: no `mode`, so a replay (each boot, an -// install or upgrade) inserts a missing row and leaves an existing one as the -// organization left it. Delete the rows, or the whole package, when they are +// show on first open; the help articles are in `articles.ts`. Business data: +// no `mode`, so a replay (each boot, an install or upgrade) inserts a missing +// row and leaves an existing one as the organization left it. Delete the rows, or the whole package, when they are // no longer wanted. const companies = defineSeed(Company, { @@ -33,4 +34,4 @@ const contacts = defineSeed(Contact, { ], }); -export const StarterSeedData = [companies, contacts]; +export const StarterSeedData = [companies, contacts, articles]; diff --git a/examples/app-starter/src/objects/article.object.ts b/examples/app-starter/src/objects/article.object.ts new file mode 100644 index 00000000000..b437702af27 --- /dev/null +++ b/examples/app-starter/src/objects/article.object.ts @@ -0,0 +1,57 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +import { ObjectSchema, Field } from '@objectstack/spec/data'; + +/** + * A help article — a how-to guide, an answer to a common question, or a + * reference page — written in Markdown. + * + * `body` opens with the article's title as a `#` heading, then one `##` + * section per topic, each with its own text: the seed articles in + * `src/data/articles.ts` are written that way. A draft stays a draft until + * someone sets it to Published. + */ +export const Article = ObjectSchema.create({ + name: 'biz_article', + // Shared inside the organization, as the companies and contacts are. + sharingModel: 'public_read_write', + label: 'Article', + pluralLabel: 'Articles', + icon: 'book-open', + color: 'amber', + description: 'A help article: a how-to guide, a common question, or a reference page.', + nameField: 'title', + highlightFields: ['category', 'status', 'owner_id'], + + fields: { + title: Field.text({ + label: 'Title', + required: true, + searchable: true, + maxLength: 200, + }), + body: Field.markdown({ + label: 'Body', + }), + category: Field.select({ + label: 'Category', + options: [ + { label: 'How-to', value: 'how_to', color: '#3B82F6' }, + { label: 'FAQ', value: 'faq', color: '#10B981' }, + { label: 'Reference', value: 'reference', color: '#8B5CF6' }, + ], + }), + status: Field.select({ + label: 'Status', + options: [ + { label: 'Draft', value: 'draft', color: '#6B7280', default: true }, + { label: 'Published', value: 'published', color: '#10B981' }, + ], + }), + }, + + // The one Details section of the record page and of the create and edit form. + fieldGroups: [ + { key: 'basic', label: 'Article', fields: ['title', 'category', 'status', 'body'] }, + ], +}); diff --git a/examples/app-starter/src/objects/index.ts b/examples/app-starter/src/objects/index.ts index 89a3487dfe4..a031b5d2a57 100644 --- a/examples/app-starter/src/objects/index.ts +++ b/examples/app-starter/src/objects/index.ts @@ -1,4 +1,5 @@ // Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. +export { Article } from './article.object.js'; export { Company } from './company.object.js'; export { Contact } from './contact.object.js'; diff --git a/examples/app-starter/src/translations/starter.translation.ts b/examples/app-starter/src/translations/starter.translation.ts index 72af5a4d728..d56bebc1843 100644 --- a/examples/app-starter/src/translations/starter.translation.ts +++ b/examples/app-starter/src/translations/starter.translation.ts @@ -39,6 +39,17 @@ export const StarterTranslationBundle = defineTranslationBundle({ owner_id: { label: 'Owner' }, }, }, + biz_article: { + label: 'Article', + pluralLabel: 'Articles', + fields: { + title: { label: 'Title' }, + body: { label: 'Body' }, + category: { label: 'Category' }, + status: { label: 'Status' }, + owner_id: { label: 'Owner' }, + }, + }, }, apps: { biz_app: { @@ -130,6 +141,37 @@ export const StarterTranslationBundle = defineTranslationBundle({ more: { label: '更多' }, }, }, + biz_article: { + label: '知识文章', + pluralLabel: '知识文章', + description: '帮助文章:操作指南、常见问题或参考资料。', + fields: { + title: { label: '标题' }, + body: { label: '正文' }, + category: { + label: '分类', + options: { + how_to: '操作指南', + faq: '常见问题', + reference: '参考资料', + }, + }, + status: { + label: '状态', + options: { + draft: '草稿', + published: '已发布', + }, + }, + owner_id: { label: '负责人' }, + }, + _views: { + all: { label: '全部文章' }, + }, + _sections: { + basic: { label: '文章' }, + }, + }, }, apps: { biz_app: { diff --git a/examples/app-starter/src/views/article.view.ts b/examples/app-starter/src/views/article.view.ts new file mode 100644 index 00000000000..dad86bb44ac --- /dev/null +++ b/examples/app-starter/src/views/article.view.ts @@ -0,0 +1,36 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +import { defineView } from '@objectstack/spec'; + +/** + * Article list view: a grid of every help article with its category and + * status. + * + * No `form` here: the Console's create and edit form lays a record out by the + * object's `fieldGroups` (`article.object.ts`), and a declared default form is + * not loaded there. + */ +export const ArticleViews = defineView({ + list: { + label: 'All Articles', + type: 'grid', + data: { provider: 'object', object: 'biz_article' }, + columns: [ + { field: 'title' }, + { field: 'category' }, + { field: 'status' }, + ], + }, + listViews: { + all: { + label: 'All Articles', + type: 'grid', + data: { provider: 'object', object: 'biz_article' }, + columns: [ + { field: 'title' }, + { field: 'category' }, + { field: 'status' }, + ], + }, + }, +}); diff --git a/examples/app-starter/src/views/index.ts b/examples/app-starter/src/views/index.ts index 540da647017..b037abce0db 100644 --- a/examples/app-starter/src/views/index.ts +++ b/examples/app-starter/src/views/index.ts @@ -1,4 +1,5 @@ // Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. +export { ArticleViews } from './article.view.js'; export { CompanyViews } from './company.view.js'; export { ContactViews } from './contact.view.js'; diff --git a/examples/app-starter/test/boot.test.ts b/examples/app-starter/test/boot.test.ts index 57c5872541f..258910795be 100644 --- a/examples/app-starter/test/boot.test.ts +++ b/examples/app-starter/test/boot.test.ts @@ -3,9 +3,9 @@ /** * The starter, installed for real: the package goes in through the * marketplace install door as an unmanaged copy with its sample data (the - * starter path), its menu carries the four object entries (companies, - * contacts, and the platform's tasks and notes), and uninstalling it removes - * companies and contacts while every task and note stays. + * starter path), its menu carries the five object entries (companies, + * contacts, articles, and the platform's tasks and notes), and uninstalling it + * removes companies, contacts and articles while every task and note stays. * * One boot of a host with nothing of its own, every phase in `beforeAll`; the * `it`s only read what the phases recorded. The task and the note are written @@ -78,6 +78,7 @@ describe('app-starter — installed as a starter, menu, uninstall', () => { let app: Answer; let companies: Answer; let contacts: Answer; + let articles: Answer; let task: Answer; let note: Answer; let uninstall: Answer; @@ -98,6 +99,7 @@ describe('app-starter — installed as a starter, menu, uninstall', () => { app = await call('GET', '/meta/app/biz_app'); companies = await call('GET', '/data/biz_company'); contacts = await call('GET', '/data/biz_contact'); + articles = await call('GET', '/data/biz_article'); task = await call('POST', '/data/sys_task', { title: 'Call Northwind about the renewal' }); note = await call('POST', '/data/sys_note', { title: 'Northwind visit', body: 'Met the purchasing team.' }); @@ -106,6 +108,7 @@ describe('app-starter — installed as a starter, menu, uninstall', () => { after.company = await call('GET', '/meta/object/biz_company'); after.contact = await call('GET', '/meta/object/biz_contact'); + after.article = await call('GET', '/meta/object/biz_article'); after.app = await call('GET', '/meta/app/biz_app'); after.task = await call('GET', `/data/sys_task/${unwrap(task)?.id}`); after.note = await call('GET', `/data/sys_note/${unwrap(note)?.id}`); @@ -127,13 +130,24 @@ describe('app-starter — installed as a starter, menu, uninstall', () => { expect(olivia?.company).toBe(northwind?.id); }); - it('the menu carries companies, contacts, tasks and notes — tasks and notes are the platform objects', () => { + it('installs its sample help articles, one of them a draft', () => { + expect(articles.status, JSON.stringify(articles.body)).toBe(200); + expect(rows(articles).map((a) => a.title).sort()).toEqual([ + 'Meeting rooms reference', + 'Set up your new laptop', + 'Share files with your team', + 'Wi-Fi and printing FAQ', + ]); + expect(rows(articles).filter((a) => a.status === 'draft').map((a) => a.title)).toEqual(['Share files with your team']); + }); + + it('the menu carries companies, contacts, articles, tasks and notes — tasks and notes are the platform objects', () => { expect(app.status, JSON.stringify(app.body)).toBe(200); const objectEntries = (unwrap(app)?.navigation ?? []) .filter((n: any) => n.type === 'object') .map((n: any) => n.objectName); - expect(objectEntries).toEqual(['biz_company', 'biz_contact', 'sys_task', 'sys_note']); - expect((stack.objects ?? []).map((o) => o.name).sort()).toEqual(['biz_company', 'biz_contact']); + expect(objectEntries).toEqual(['biz_company', 'biz_contact', 'biz_article', 'sys_task', 'sys_note']); + expect((stack.objects ?? []).map((o) => o.name).sort()).toEqual(['biz_article', 'biz_company', 'biz_contact']); }); it('precondition: a task and a note were written before the uninstall', () => { @@ -143,10 +157,11 @@ describe('app-starter — installed as a starter, menu, uninstall', () => { expect(unwrap(note)?.id).toBeTruthy(); }); - it('uninstall removes companies, contacts and the app', () => { + it('uninstall removes companies, contacts, articles and the app', () => { expect(uninstall.status, JSON.stringify(uninstall.body)).toBe(200); expect(after.company.status, JSON.stringify(after.company.body)).toBe(404); expect(after.contact.status, JSON.stringify(after.contact.body)).toBe(404); + expect(after.article.status, JSON.stringify(after.article.body)).toBe(404); expect(after.app.status, JSON.stringify(after.app.body)).toBe(404); }); diff --git a/examples/app-starter/test/help-articles-38372.test.ts b/examples/app-starter/test/help-articles-38372.test.ts new file mode 100644 index 00000000000..e4dcc9d9de2 --- /dev/null +++ b/examples/app-starter/test/help-articles-38372.test.ts @@ -0,0 +1,116 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * The seed help articles hold one Markdown shape, so each section reads on + * its own: the body opens with `# TITLE` (the record's own title), then 3 to 6 + * `##` sections, every section with text under its heading and, heading + * included, under 800 characters. One reference article carries a table + * followed by a one-line note, and one article is left a draft. + * + * Read off the seed definition itself, the rows the install door inserts. The + * blank template in create-objectstack carries the same seed; its parity test + * holds the two equal, so this shape holds there too. + */ + +import { describe, it, expect } from 'vitest'; +import { articles } from '../src/data/articles.js'; + +interface SeedArticle { title: string; body: string; category: string; status: string } + +const SECTION_LIMIT = 800; + +/** The body's `##` sections: each heading line with the text under it. */ +function sections(body: string): { heading: string; text: string; raw: string }[] { + const lines = body.split('\n'); + const out: { heading: string; text: string; raw: string }[] = []; + for (const line of lines) { + if (line.startsWith('## ')) out.push({ heading: line, text: '', raw: line }); + else if (out.length > 0) { + const last = out[out.length - 1]; + last.text += `${line}\n`; + last.raw += `\n${line}`; + } + } + return out.map((s) => ({ ...s, text: s.text.trim(), raw: s.raw.trimEnd() })); +} + +/** Every way an article breaks the shape, as readable sentences; empty when it holds. */ +function shapeProblems(article: SeedArticle): string[] { + const problems: string[] = []; + const lines = article.body.split('\n'); + if (lines[0] !== `# ${article.title}`) problems.push(`first line is not "# ${article.title}"`); + const firstSection = lines.findIndex((l) => l.startsWith('## ')); + const preamble = lines.slice(1, firstSection < 0 ? lines.length : firstSection).join('\n').trim(); + if (preamble) problems.push('text stands between the title and the first section'); + if (lines.slice(1).some((l) => /^# /.test(l))) problems.push('a second "# " heading'); + const found = sections(article.body); + if (found.length < 3 || found.length > 6) problems.push(`${found.length} sections, not 3 to 6`); + for (const s of found) { + if (!s.text) problems.push(`"${s.heading}" has no text`); + if (s.raw.length >= SECTION_LIMIT) problems.push(`"${s.heading}" is ${s.raw.length} characters`); + } + return problems; +} + +/** A Markdown table (header, separator, rows) followed by exactly one line of text, ending the section. */ +function hasTableThenOneLineNote(text: string): boolean { + const lines = text.split('\n'); + const start = lines.findIndex((l) => l.startsWith('|')); + if (start < 0 || !/^\|(\s*-+\s*\|)+$/.test(lines[start + 1] ?? '')) return false; + let end = start; + while (lines[end + 1]?.startsWith('|')) end++; + if (end - start < 2) return false; + const after = lines.slice(end + 1).filter((l) => l.trim() !== ''); + return after.length === 1 && !after[0].startsWith('|'); +} + +const records: SeedArticle[] = articles.records.map((r) => ({ + title: String(r.title), + body: String(r.body), + category: String(r.category), + status: String(r.status), +})); + +describe('seed help articles — one Markdown shape', () => { + it('reads the seed (vacuity guard): three to four articles, keyed by title', () => { + expect(articles.externalId).toBe('title'); + expect(records.length).toBeGreaterThanOrEqual(3); + expect(records.length).toBeLessThanOrEqual(4); + }); + + it.each(records.map((r) => [r.title, r] as const))('"%s" holds the shape', (_title, article) => { + expect(shapeProblems(article)).toEqual([]); + }); + + it('covers every category, and leaves exactly one article a draft', () => { + expect(new Set(records.map((r) => r.category))).toEqual(new Set(['how_to', 'faq', 'reference'])); + expect(records.filter((r) => r.status === 'draft')).toHaveLength(1); + expect(records.filter((r) => r.status === 'published').length).toBe(records.length - 1); + }); + + it('a reference article carries a table followed by a one-line note', () => { + const withTable = records + .filter((r) => r.category === 'reference') + .filter((r) => sections(r.body).some((s) => hasTableThenOneLineNote(s.text))); + expect(withTable.map((r) => r.title)).toHaveLength(1); + }); + + it('CONTROL: each break of the shape is caught', () => { + const good = records.find((r) => r.category === 'faq')!; + expect(shapeProblems(good)).toEqual([]); + const firstSection = good.body.indexOf('\n## '); + const cases: Record = { + 'wrong title': good.body.replace(`# ${good.title}`, '# Something else'), + 'empty section': good.body.replace('\n## ', '\n## A heading alone\n\n## '), + 'long section': `${good.body}\n\n## Long\n\n${'x'.repeat(SECTION_LIMIT)}`, + 'too few sections': good.body.slice(0, good.body.indexOf('\n## ', firstSection + 1)), + 'text before the first section': good.body.replace(`# ${good.title}\n`, `# ${good.title}\n\nIntro.\n`), + }; + for (const [name, body] of Object.entries(cases)) { + expect(shapeProblems({ ...good, body }), name).not.toEqual([]); + } + expect(hasTableThenOneLineNote('| a | b |\n| --- | --- |\n| 1 | 2 |\n\nOne note.')).toBe(true); + expect(hasTableThenOneLineNote('| a | b |\n| --- | --- |\n| 1 | 2 |\n\nOne note.\n\nA second.')).toBe(false); + expect(hasTableThenOneLineNote('| a | b |\n| --- | --- |\n| 1 | 2 |')).toBe(false); + }); +}); diff --git a/packages/cli/test/create-objectstack-stack-reach.test.ts b/packages/cli/test/create-objectstack-stack-reach.test.ts index f4da53d298d..3c41ca9c45d 100644 --- a/packages/cli/test/create-objectstack-stack-reach.test.ts +++ b/packages/cli/test/create-objectstack-stack-reach.test.ts @@ -168,8 +168,9 @@ describe('[#20333] `npm create objectstack` → `os g flow` → `os validate`', it('`os validate` exits 0 and counts the generated flow beside the control', () => { expect(validate.code, out(validate)).toBe(0); - // The starter's two objects (company, contact) plus the generated one. - expect(validate.stdout).toMatch(/\bData: 3 Objects\b/); + // The starter's three objects (article, company, contact) plus the + // generated one. + expect(validate.stdout).toMatch(/\bData: 4 Objects\b/); expect(validate.stdout).toMatch(/\bLogic: 1 Flows\b/); }); }); diff --git a/packages/cli/test/create-objectstack-wiring-parity.test.ts b/packages/cli/test/create-objectstack-wiring-parity.test.ts index 5009d65313e..64a2cd2d88a 100644 --- a/packages/cli/test/create-objectstack-wiring-parity.test.ts +++ b/packages/cli/test/create-objectstack-wiring-parity.test.ts @@ -172,6 +172,7 @@ describe('[#20333] the blank template ships every wired barrel', () => { }; expect(appendedTo('src/apps/index.ts')).toEqual(["export { default as main } from './main.app';"]); expect(appendedTo('src/views/index.ts')).toEqual([ + "export { default as article } from './article.view';", "export { default as company } from './company.view';", "export { default as contact } from './contact.view';", ]); diff --git a/packages/create-objectstack/src/blank-template-starter-parity.test.ts b/packages/create-objectstack/src/blank-template-starter-parity.test.ts index c029449c6b3..d5e34f4e250 100644 --- a/packages/create-objectstack/src/blank-template-starter-parity.test.ts +++ b/packages/create-objectstack/src/blank-template-starter-parity.test.ts @@ -1,9 +1,10 @@ // Copyright (c) 2026 ObjectStack contributors. Apache-2.0 license. // -// The blank template's companies and contacts ARE the platform's Starter app -// (`examples/app-starter`), as source a new project owns. The two must never -// drift: a project scaffolded today and an environment that installed the -// Starter hold the same objects, the same views and the same menu entries. +// The blank template's companies, contacts and help articles ARE the +// platform's Starter app (`examples/app-starter`), as source a new project +// owns. The two must never drift: a project scaffolded today and an +// environment that installed the Starter hold the same objects, the same +// views, the same menu entries and the same sample articles. // // ## Why a pin, and not a copy at build time // @@ -28,13 +29,15 @@ // newcomer reading their own project (what the org-wide default means, how to // remove the objects); the Starter's for a package author. Both files are // parsed with the TypeScript compiler and the definition (the argument of -// `ObjectSchema.create` / `defineView`, each menu entry) is printed without -// comments, so formatting and commentary are free and every key and value is -// held. +// `ObjectSchema.create` / `defineView`, each menu entry, the whole +// `defineSeed(Article, …)` call) is printed without comments, so formatting +// and commentary are free and every key and value is held. // // The template's menu is the Starter's object entries — companies, contacts, -// and the platform's tasks and notes — without the Starter's dashboard entry: -// the template ships no dashboard. +// articles, and the platform's tasks and notes — without the Starter's +// dashboard entry: the template ships no dashboard. Of the Starter's seed the +// template carries only the help articles: its companies and contacts start +// empty. import { describe, it, expect } from 'vitest'; import fs from 'node:fs'; @@ -107,14 +110,28 @@ function navigation(file: string, rename: boolean): { type: string | undefined; }); } +// Object pairs in file-name order: the object-file guard below compares them +// with the directory listing. const PAIRS = [ + { what: 'article object', file: 'objects/article.object.ts', callee: 'ObjectSchema.create' }, { what: 'company object', file: 'objects/company.object.ts', callee: 'ObjectSchema.create' }, { what: 'contact object', file: 'objects/contact.object.ts', callee: 'ObjectSchema.create' }, { what: 'company views', file: 'views/company.view.ts', callee: 'defineView' }, { what: 'contact views', file: 'views/contact.view.ts', callee: 'defineView' }, + { what: 'article views', file: 'views/article.view.ts', callee: 'defineView' }, ]; -describe('blank template — the Starter app\'s companies and contacts, as source', () => { +/** The printed `defineSeed(, …)` calls of the file — the whole call, records included. */ +function seeds(file: string, seeded: string, rename: boolean): string[] { + const sf = parse(file, rename); + return findAll( + sf, + (n): n is ts.CallExpression => + ts.isCallExpression(n) && n.expression.getText(sf) === 'defineSeed' && n.arguments[0]?.getText(sf) === seeded, + ).map((call) => print(call, sf)); +} + +describe('blank template — the Starter app\'s companies, contacts and articles, as source', () => { it('reads two real namespaces (vacuity guard)', () => { expect(BLANK_NAMESPACE).toBe('blank'); expect(STARTER_NAMESPACE).toBe('biz'); @@ -149,17 +166,42 @@ describe('blank template — the Starter app\'s companies and contacts, as sourc expect(objectFiles(BLANK_SRC)).toEqual(PAIRS.filter((p) => p.callee === 'ObjectSchema.create').map((p) => path.basename(p.file))); }); - it('the menu is the Starter\'s four object entries: companies, contacts, and the platform\'s tasks and notes', () => { + it('the sample help articles are the Starter\'s seed, modulo the namespace', () => { + const starter = seeds(path.join(STARTER_SRC, 'data', 'articles.ts'), 'Article', true); + const template = seeds(path.join(BLANK_SRC, 'data', 'articles.ts'), 'Article', false); + // Vacuity guard: one seed found on each side, carrying records. + expect(starter).toHaveLength(1); + expect(starter[0]).toMatch(/records: \[/); + expect(template).toEqual(starter); + }); + + it('CONTROL: a one-word change in a template article is caught', () => { + const file = path.join(BLANK_SRC, 'data', 'articles.ts'); + const sf = ts.createSourceFile( + file, + fs.readFileSync(file, 'utf8').replace('Plug the laptop into power', 'Plug the laptop into a socket'), + ts.ScriptTarget.Latest, + true, + ts.ScriptKind.TS, + ); + const mutated = findAll(sf, (n): n is ts.CallExpression => ts.isCallExpression(n) && n.expression.getText(sf) === 'defineSeed') + .map((call) => print(call, sf)); + expect(mutated).toHaveLength(1); + expect(mutated).not.toEqual(seeds(path.join(STARTER_SRC, 'data', 'articles.ts'), 'Article', true)); + }); + + it('the menu is the Starter\'s five object entries: companies, contacts, articles, and the platform\'s tasks and notes', () => { const starter = navigation(path.join(STARTER_SRC, 'apps', 'starter.app.ts'), true); const template = navigation(path.join(BLANK_SRC, 'apps', 'main.app.ts'), false); const starterObjects = starter.filter((e) => e.type === 'object'); // The Starter also carries a dashboard entry, which the template does not ship. expect(starter.length).toBeGreaterThan(starterObjects.length); - expect(starterObjects).toHaveLength(4); + expect(starterObjects).toHaveLength(5); expect(template.map((e) => e.text)).toEqual(starterObjects.map((e) => e.text)); + expect(template[2].text).toMatch(/objectName: 'blank_article'/); // The last two are the platform's own objects, gated as such. - expect(template[2].text).toMatch(/objectName: 'sys_task', requiresObject: 'sys_task'/); - expect(template[3].text).toMatch(/objectName: 'sys_note', requiresObject: 'sys_note'/); + expect(template[3].text).toMatch(/objectName: 'sys_task', requiresObject: 'sys_task'/); + expect(template[4].text).toMatch(/objectName: 'sys_note', requiresObject: 'sys_note'/); }); it('the scaffolder\'s closing summary names what the project starts with', () => { diff --git a/packages/create-objectstack/src/templates/blank/README.md b/packages/create-objectstack/src/templates/blank/README.md index 5dc8f2b5783..d96e9e510f8 100644 --- a/packages/create-objectstack/src/templates/blank/README.md +++ b/packages/create-objectstack/src/templates/blank/README.md @@ -1,7 +1,7 @@ # Blank Starter An ObjectStack environment that starts with companies, the people at them, -and the platform's tasks and notes in one menu — yours to change. +help articles, and the platform's tasks and notes in one menu — yours to change. ## Getting started @@ -29,8 +29,8 @@ curl -b cookies.txt "http://localhost:3000/api/v1/data/" ## What this project starts with -The same companies and contacts as the platform's Starter app, as source you -own: +The same companies, contacts and help articles as the platform's Starter app, +as source you own: - `src/objects/company.object.ts` — **Company**: a company the organization works with (a customer, a prospect, a partner, a supplier), with its type, @@ -38,9 +38,14 @@ own: - `src/objects/contact.object.ts` — **Contact**: a person at one of those companies, with a job title, an influence, an email and a phone. A contact is not a user and never signs in. +- `src/objects/article.object.ts` — **Article**: a help article (a how-to, a + common question or a reference page) with a Markdown body, a category and a + status; `src/data/articles.ts` seeds four sample articles, one a draft. - `src/views/company.view.ts`, `src/views/contact.view.ts` — a grid of every - record and a board (companies by type, contacts by influence). -- `src/apps/main.app.ts` — the menu: Companies, Contacts, Tasks and Notes. + record and a board (companies by type, contacts by influence); + `src/views/article.view.ts` — a grid of every article. +- `src/apps/main.app.ts` — the menu: Companies, Contacts, Articles, Tasks and + Notes. **Tasks and Notes are the platform's own objects** (`sys_task`, `sys_note`), which every environment carries. This project declares no copy of them: the @@ -48,7 +53,9 @@ menu points at them, so they stay when your app changes or goes, and a task or a note never changes who may see the record it is about. Change any of it freely: rename a field, add one, or replace both objects with -your own. To remove companies and contacts entirely: +your own. To remove companies and contacts entirely (help articles go the same +way: their object, view, menu entry, `src/data/articles.ts`, and its entry in +`data` in `objectstack.config.ts`): 1. Delete `src/objects/company.object.ts` and `src/objects/contact.object.ts` and their export lines in `src/objects/index.ts`. @@ -57,7 +64,8 @@ your own. To remove companies and contacts entirely: entries in `src/apps/main.app.ts` (put your own objects there instead — see [The Console](#the-console) below). 3. Point `starter.test.ts` at your own objects (rename the file to match). It - imports `Company` and `Contact`, so it stops compiling until you do. + imports `Company`, `Contact` and `Article`, so it stops compiling until you + do. 4. Run `pnpm validate` and `pnpm test`. ## The Console @@ -65,11 +73,12 @@ your own. To remove companies and contacts entirely: `pnpm dev` also serves the admin Console at `http://localhost:3000/_console/`, and prints the link on boot. Open it and you will see this project's app, **Main**, beside the platform's own apps (Setup, Account), with Companies, -Contacts, Tasks and Notes in its menu. +Contacts, Articles, Tasks and Notes in its menu. **An object appears in Console navigation only when an app lists it.** -`src/apps/main.app.ts` lists companies and contacts, and -`src/views/company.view.ts` and `src/views/contact.view.ts` draw their lists. A package whose manifest type is `app` holds at most one app, +`src/apps/main.app.ts` lists companies, contacts and articles, and +`src/views/company.view.ts`, `src/views/contact.view.ts` and +`src/views/article.view.ts` draw their lists. A package whose manifest type is `app` holds at most one app, so `main.app.ts` is the one: to show another object, add a navigation entry for it to that app's `navigation` (a `group` entry with children nests them) rather than a second app, and give it a list view. `objectstack generate view OBJECT` @@ -100,11 +109,14 @@ for OAuth, API keys, and which objects/actions become tools. - `objectstack.config.ts` — environment manifest (objects, API, plugins), and the wiring for every directory below -- `src/objects/` — object definitions (one file per object): companies and - contacts, described [above](#what-this-project-starts-with) +- `src/objects/` — object definitions (one file per object): companies, + contacts and articles, described [above](#what-this-project-starts-with) - `src/apps/` — the app, `main.app.ts`, described in - [The Console](#the-console); `src/views/` — the companies' and contacts' - list views + [The Console](#the-console); `src/views/` — the companies', contacts' and + articles' list views +- `src/data/` — sample rows, seeded on each boot. `objectstack generate` writes + no seed, so the config lists each one by name in `data`: list a new one there + too - `src/actions/`, `src/flows/`, `src/dashboards/`, `src/skills/`, `src/picklists/`, `src/security/` (permission sets), `src/datasets/` (analytics datasets) — empty to start. Each directory's `index.ts` @@ -169,8 +181,8 @@ record. See `AGENTS.md` for the full convention. `pnpm test` checks what the app *does*. `starter.test.ts` boots this app's stack in-process with `bootStack` from `@objectstack/verify` (in-memory database, no server) and asserts business facts through its handle: a company -without a name is refused, a contact belongs to a company, and the menu lists -Companies, Contacts, Tasks and Notes. Write your own the same way: `stack.hooks.run` makes a real +without a name is refused, a contact belongs to a company, the sample articles +are loaded, and the menu lists Companies, Contacts, Articles, Tasks and Notes. Write your own the same way: `stack.hooks.run` makes a real write through validation, permissions and hooks, and the same handle runs flows and actions, seeds fixtures and reads rows as a given user. diff --git a/packages/create-objectstack/src/templates/blank/objectstack.config.ts b/packages/create-objectstack/src/templates/blank/objectstack.config.ts index e277fcf8450..1675497bb7c 100644 --- a/packages/create-objectstack/src/templates/blank/objectstack.config.ts +++ b/packages/create-objectstack/src/templates/blank/objectstack.config.ts @@ -9,6 +9,7 @@ import * as skills from './src/skills'; import * as picklists from './src/picklists'; import * as permissions from './src/security'; import * as datasets from './src/datasets'; +import { articles } from './src/data'; // Every value a barrel exports, as the list a stack key takes: typed by what // the barrel exports, and an empty list while it exports nothing yet. @@ -81,4 +82,12 @@ export default defineStack({ picklists: exportsOf(picklists), permissions: exportsOf(permissions), datasets: exportsOf(datasets), + + // The sample rows are listed by name, not wired as a directory: + // `objectstack generate` writes no seed, so a seed you add is loaded once + // you list it here too. + // + // Sample rows (src/data/): each boot inserts a row that is missing and + // leaves one that exists as it is. + data: [articles], }); diff --git a/packages/create-objectstack/src/templates/blank/src/apps/main.app.ts b/packages/create-objectstack/src/templates/blank/src/apps/main.app.ts index fa241ef5c3c..7f35cee8bcd 100644 --- a/packages/create-objectstack/src/templates/blank/src/apps/main.app.ts +++ b/packages/create-objectstack/src/templates/blank/src/apps/main.app.ts @@ -11,8 +11,8 @@ import * as UI from '@objectstack/spec/ui'; // below (a 'group' entry with children nests them) rather than a second app, // and give it a list view — `objectstack generate view OBJECT` writes one. // -// The menu is the platform's Starter app's: this project's companies and -// contacts, then the platform's tasks and notes. Tasks and notes are the +// The menu is the platform's Starter app's: this project's companies, +// contacts and help articles, then the platform's tasks and notes. Tasks and notes are the // platform objects `sys_task` and `sys_note`, which every environment carries; // this project declares no copy of them, so a task or a note can be about any // record without changing who may see that record. No entry carries a label: @@ -23,6 +23,7 @@ const mainApp: UI.App = { navigation: [ { id: 'nav_companies', type: 'object', objectName: 'blank_company', icon: 'building-2' }, { id: 'nav_contacts', type: 'object', objectName: 'blank_contact', icon: 'contact' }, + { id: 'nav_articles', type: 'object', objectName: 'blank_article', icon: 'book-open' }, // `requiresObject` names the object again because `defineStack` refuses a // menu entry for an object the stack does not declare unless the entry // says the object comes from elsewhere — here, the platform. diff --git a/packages/create-objectstack/src/templates/blank/src/data/articles.ts b/packages/create-objectstack/src/templates/blank/src/data/articles.ts new file mode 100644 index 00000000000..daa670cccb9 --- /dev/null +++ b/packages/create-objectstack/src/templates/blank/src/data/articles.ts @@ -0,0 +1,124 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +// Sample help articles, so the Articles list has something to show on first +// open: the same articles as the platform's Starter app. Business data: no +// `mode`, so each boot inserts an article that is missing and leaves one that +// exists as you left it. Delete the rows, or this file, its export line in +// `src/data/index.ts` and its entry in `data` in objectstack.config.ts, when +// they are no longer wanted. +// +// Each `body` is Markdown in one shape: the article's title as a `#` heading, +// then one `##` section per topic, each with its own text and short enough to +// read on its own. Write new articles the same way. + +import { defineSeed } from '@objectstack/spec/data'; +import { Article } from '../objects/article.object.js'; + +export const articles = defineSeed(Article, { + externalId: 'title', + records: [ + { + title: 'Set up your new laptop', + category: 'how_to', + status: 'published', + body: `# Set up your new laptop + +## Before you start + +Have your work email address and the temporary password from your welcome message at hand. Plug the laptop into power: the first start installs updates and can take up to half an hour. + +## Sign in for the first time + +Choose your language and keyboard, join the office Wi-Fi, then sign in with your work email and the temporary password. You are asked to choose a new password straight away; pick one you have not used anywhere else. + +## Install the apps you need + +Open the company app store from the start menu. Email, calendar, chat and the office suite install on their own; anything your team uses on top of that is listed under your department. Ask your manager if an app you need is missing. + +## Turn on backup + +Sign in to the file storage app and let it back up your Desktop and Documents folders. Files saved there follow you to a new laptop and can be restored if this one is lost. + +## Get help + +If something does not work, write to the IT help desk with the laptop's name, which is on the sticker underneath, and a screenshot of any error.`, + }, + { + title: 'Wi-Fi and printing FAQ', + category: 'faq', + status: 'published', + body: `# Wi-Fi and printing FAQ + +## How do I join the office Wi-Fi? + +Pick the network named Office and sign in with your work email and password. Guests use the Office-Guest network; its password is on the card at reception and changes every Monday. + +## Why does the Wi-Fi keep dropping? + +Most drops happen when a laptop moves between floors. Turn Wi-Fi off and on again, and forget any old office network your laptop still remembers. If it keeps happening at one desk, tell the help desk which desk it is. + +## How do I add a printer? + +Open the printer settings, choose Add printer and pick the one whose name matches the label on the machine. Printers are named by floor, so the second-floor printer starts with F2. + +## Why is my print job stuck? + +A job usually waits because the printer is out of paper or needs a release at the machine. Tap your badge on the printer to release your jobs. Jobs that are not released within a day are deleted. + +## Can I print from my phone? + +Yes. Email the file from your work account to the print address shown on the printer's screen, then release it with your badge as usual.`, + }, + { + title: 'Meeting rooms reference', + category: 'reference', + status: 'published', + body: `# Meeting rooms reference + +## Rooms at a glance + +| Room | Floor | Seats | Equipment | +| --- | --- | --- | --- | +| Harbor | 1 | 4 | Screen | +| Summit | 2 | 8 | Screen, video bar, whiteboard | +| Grove | 2 | 12 | Projector, video bar | +| Atrium | 3 | 20 | Projector, microphones | + +Seat counts are for seated meetings; a short stand-up fits a few more people. + +## Booking a room + +Book rooms from your calendar by adding the room as a guest. A booking longer than two hours, or one that repeats every week, needs a reason in the invitation so others know whether to ask for the room. + +## Video calls + +Rooms with a video bar join a call from the calendar invitation: press Join on the room's touch panel. In other rooms, connect your laptop to the screen with the cable on the table. + +## Leaving the room + +End the meeting on time, wipe the whiteboard, and take your cups with you. If you finish early, release the room from your calendar so someone else can use it.`, + }, + { + title: 'Share files with your team', + category: 'how_to', + status: 'draft', + body: `# Share files with your team + +## Pick the right place + +Keep files your whole team works on in the team's shared folder, not in your own. A file in a shared folder stays with the team when someone leaves or changes roles. + +## Share a file or folder + +Right-click the file in the file storage app, choose Share, and add people by name or add the whole team. Each person gets an email with a link. + +## Choose who can edit + +Give edit access to the people who will change the file and view access to everyone else. Links that anyone can open are turned off for files that hold customer details. + +## Stop sharing + +Open Share again and remove a person, or change their access to view only. Review who has access to a folder when a project ends.`, + }, + ], +}); diff --git a/packages/create-objectstack/src/templates/blank/src/data/index.ts b/packages/create-objectstack/src/templates/blank/src/data/index.ts new file mode 100644 index 00000000000..779f8adc494 --- /dev/null +++ b/packages/create-objectstack/src/templates/blank/src/data/index.ts @@ -0,0 +1,5 @@ +// The sample data in this directory, as seeds: each names the object it fills +// and the field that identifies a row. objectstack.config.ts lists each seed +// by name in the stack's `data`, and each boot inserts a row that is missing +// and leaves one that exists as it is. +export { articles } from './articles.js'; diff --git a/packages/create-objectstack/src/templates/blank/src/objects/article.object.ts b/packages/create-objectstack/src/templates/blank/src/objects/article.object.ts new file mode 100644 index 00000000000..f4a791482cf --- /dev/null +++ b/packages/create-objectstack/src/templates/blank/src/objects/article.object.ts @@ -0,0 +1,72 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +// The help articles this project starts with: how-to guides, answers to +// common questions and reference pages, written in Markdown. They are the +// same definition as the platform's Starter app, so a project scaffolded +// today and an environment that installed the Starter hold the same articles. +// They are yours now: add a category, change the fields, or delete the object +// (the README's "What this project starts with" says what goes with it). +// +// The object's API name carries this project's namespace: scaffolding renamed +// every name in `src/`, references included, from the template's own. Write +// any new name the same way, `_`. + +import { ObjectSchema, Field } from '@objectstack/spec/data'; + +/** + * A help article — a how-to guide, an answer to a common question, or a + * reference page — written in Markdown. + * + * `body` opens with the article's title as a `#` heading, then one `##` + * section per topic, each with its own text: the sample articles in + * `src/data/articles.ts` are written that way. A draft stays a draft until + * someone sets it to Published. + */ +export const Article = ObjectSchema.create({ + name: 'blank_article', + // Org-wide default (OWD), as on the companies and contacts: everyone in the + // organization reads and edits every article. `private` makes them + // owner-only until a permission grant or a sharing rule widens access: + // https://objectstack.ai/docs/permissions/sharing-rules + sharingModel: 'public_read_write', + label: 'Article', + pluralLabel: 'Articles', + icon: 'book-open', + color: 'amber', + description: 'A help article: a how-to guide, a common question, or a reference page.', + nameField: 'title', + highlightFields: ['category', 'status', 'owner_id'], + + fields: { + title: Field.text({ + label: 'Title', + required: true, + searchable: true, + maxLength: 200, + }), + body: Field.markdown({ + label: 'Body', + }), + category: Field.select({ + label: 'Category', + options: [ + { label: 'How-to', value: 'how_to', color: '#3B82F6' }, + { label: 'FAQ', value: 'faq', color: '#10B981' }, + { label: 'Reference', value: 'reference', color: '#8B5CF6' }, + ], + }), + status: Field.select({ + label: 'Status', + options: [ + { label: 'Draft', value: 'draft', color: '#6B7280', default: true }, + { label: 'Published', value: 'published', color: '#10B981' }, + ], + }), + }, + + // The one Details section of the record page and of the create and edit + // form. A field shows on the form only once a section lists it. + fieldGroups: [ + { key: 'basic', label: 'Article', fields: ['title', 'category', 'status', 'body'] }, + ], +}); diff --git a/packages/create-objectstack/src/templates/blank/src/objects/index.ts b/packages/create-objectstack/src/templates/blank/src/objects/index.ts index 9be9e397a92..1c56b35ab15 100644 --- a/packages/create-objectstack/src/templates/blank/src/objects/index.ts +++ b/packages/create-objectstack/src/templates/blank/src/objects/index.ts @@ -2,5 +2,6 @@ // here and adds its export line below. objectstack.config.ts hands every // export of this file to the stack, so an object exported here is part of it, // and an object file this index does not export is never loaded. +export { Article } from './article.object.js'; export { Company } from './company.object.js'; export { Contact } from './contact.object.js'; diff --git a/packages/create-objectstack/src/templates/blank/src/views/article.view.ts b/packages/create-objectstack/src/templates/blank/src/views/article.view.ts new file mode 100644 index 00000000000..f2cfa399836 --- /dev/null +++ b/packages/create-objectstack/src/templates/blank/src/views/article.view.ts @@ -0,0 +1,39 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +import { defineView } from '@objectstack/spec'; + +/** + * Article list view: a grid of every help article with its category and + * status, the same view as the platform's Starter app. The menu's Articles + * entry (`src/apps/main.app.ts`) opens it. + * + * No `form` here: the Console's create and edit form lays a record out by the + * object's `fieldGroups` (`src/objects/article.object.ts`), and a declared + * default form is not loaded there. + */ +const ArticleViews = defineView({ + list: { + label: 'All Articles', + type: 'grid', + data: { provider: 'object', object: 'blank_article' }, + columns: [ + { field: 'title' }, + { field: 'category' }, + { field: 'status' }, + ], + }, + listViews: { + all: { + label: 'All Articles', + type: 'grid', + data: { provider: 'object', object: 'blank_article' }, + columns: [ + { field: 'title' }, + { field: 'category' }, + { field: 'status' }, + ], + }, + }, +}); + +export default ArticleViews; diff --git a/packages/create-objectstack/src/templates/blank/src/views/index.ts b/packages/create-objectstack/src/templates/blank/src/views/index.ts index 5dd16d3ef15..ce51a865459 100644 --- a/packages/create-objectstack/src/templates/blank/src/views/index.ts +++ b/packages/create-objectstack/src/templates/blank/src/views/index.ts @@ -3,5 +3,6 @@ // export of this file to the stack, so a view exported here is part of it, // and a view file this index does not export is never loaded. export {}; +export { default as article } from './article.view'; export { default as company } from './company.view'; export { default as contact } from './contact.view'; diff --git a/packages/create-objectstack/src/templates/blank/starter.test.ts b/packages/create-objectstack/src/templates/blank/starter.test.ts index e8d7cffe8ed..802276ab244 100644 --- a/packages/create-objectstack/src/templates/blank/starter.test.ts +++ b/packages/create-objectstack/src/templates/blank/starter.test.ts @@ -1,7 +1,7 @@ import { afterAll, beforeAll, describe, expect, it } from 'vitest'; import { bootStack, type VerifyStack } from '@objectstack/verify'; import config from './objectstack.config'; -import { Company, Contact } from './src/objects'; +import { Article, Company, Contact } from './src/objects'; import * as apps from './src/apps'; // Boots THIS app (its objects, its plugins, the services it requires) on the @@ -19,7 +19,7 @@ import * as apps from './src/apps'; // Objects and the app are addressed by the definitions they are imported as // (`Company.name`), never by a typed-out string: scaffolding renamed them to // carry this project's namespace, and adding your own works the same way. -describe('the starter: companies and contacts, with tasks and notes in the menu', () => { +describe('the starter: companies, contacts and help articles, with tasks and notes in the menu', () => { let stack: VerifyStack; let admin: string; @@ -65,7 +65,21 @@ describe('the starter: companies and contacts, with tasks and notes in the menu' expect(contact.company).toBe(company.id); }); - it('the menu lists companies, contacts, tasks and notes', async () => { + it('the sample help articles are loaded, one of them a draft', async () => { + // src/data/articles.ts seeds them on boot; read them the way the Console + // does, through the data route. + const res = await stack.apiAs(admin, 'GET', `/data/${Article.name}`); + expect(res.status).toBe(200); + const body = await res.json(); + const envelope = body?.data ?? body; + const rows: { title: string; status: string }[] = Array.isArray(envelope) + ? envelope + : (envelope?.records ?? envelope?.items ?? []); + expect(rows.map((r) => r.title)).toContain('Set up your new laptop'); + expect(rows.filter((r) => r.status === 'draft')).toHaveLength(1); + }); + + it('the menu lists companies, contacts, articles, tasks and notes', async () => { // Read the app the way the Console does, from the booted stack. Tasks and // notes are the platform's own objects, not this project's. const app = Object.values(apps)[0]; @@ -76,6 +90,6 @@ describe('the starter: companies and contacts, with tasks and notes in the menu' const envelope = body?.data ?? body; const served = envelope?.item ?? envelope; const entries = (served?.navigation ?? []).map((n: { objectName?: string }) => n.objectName); - expect(entries).toEqual([Company.name, Contact.name, 'sys_task', 'sys_note']); + expect(entries).toEqual([Company.name, Contact.name, Article.name, 'sys_task', 'sys_note']); }); });