@mccaskie-labs/workbench-settings 0.0.0-stage → 0.2.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.
@@ -0,0 +1,109 @@
1
+ /** The languages the page's words come in. A missing one falls back to English. */
2
+ export type SettingsLang = "en" | "tl" | "taglish";
3
+ /** A phrase in each language the page carries; `en` is required. */
4
+ export type Words = {
5
+ en: string;
6
+ } & Partial<Record<Exclude<SettingsLang, "en">, string>>;
7
+ /** The kind of value, which sets the field drawn and the check run. */
8
+ export type SettingType = "text" | "email" | "choice" | "whole" | "map";
9
+ /**
10
+ * How a change takes effect (§5).
11
+ * - `live`: saved and used at once.
12
+ * - `checked`: proved first. For an email address, a six-digit code is
13
+ * emailed to the new address and the owner types it in; the old value
14
+ * stays until then.
15
+ */
16
+ export type SettingKind = "live" | "checked";
17
+ /** One value an owner may change. */
18
+ export interface SettingDef {
19
+ /** Stable, `[a-z][a-z0-9_]*`. Never renamed: a rename is a new key. */
20
+ key: string;
21
+ type: SettingType;
22
+ kind: SettingKind;
23
+ label: Words;
24
+ help?: Words;
25
+ /** The value when neither the project's answers nor the owner set one. */
26
+ default?: string | number | null;
27
+ /** The answers-file key this overrides (workbench/<tool>.json), so the page can say "set when the app was built". */
28
+ answers?: string;
29
+ /** Text: the longest. Whole: the largest. */
30
+ max?: number;
31
+ /** Text: the shortest (default 1). Whole: the smallest. */
32
+ min?: number;
33
+ /** Choice: the values, in the order shown. */
34
+ choices?: readonly {
35
+ value: string;
36
+ label: Words;
37
+ }[];
38
+ /**
39
+ * True when the value decides where people's personal information goes
40
+ * (a reply-to address, where notices are sent). Such a setting can't be
41
+ * `live`: settingsProblems refuses it.
42
+ */
43
+ personal?: boolean;
44
+ /**
45
+ * An extra check run at every save, after the type's own: null to accept
46
+ * the value, or the words to show the owner ("That colour doesn't read on
47
+ * white"). Keep it quick and pure: it runs on reads too, and a stored
48
+ * value it refuses is ignored.
49
+ */
50
+ check?: (value: SettingValue) => Words | null;
51
+ }
52
+ /** Every setting one tool lets an owner change. */
53
+ export interface ToolSettings {
54
+ format: 1;
55
+ /** The tool's id, as its manifest's component: `email`, `bookings`. */
56
+ tool: string;
57
+ /** The section's heading: "Emails". */
58
+ title: Words;
59
+ /** One line under the heading. */
60
+ about?: Words;
61
+ settings: readonly SettingDef[];
62
+ /**
63
+ * The owner's values for this tool are tried on the test site and carried
64
+ * to the live one by the next release the owner approves
65
+ * (settings.exportGroup, importGroup, markCarried). Until then the page
66
+ * says "On the test site only". A carried tool can't hold a checked
67
+ * setting: a code proves an address on one site only.
68
+ */
69
+ carries?: boolean;
70
+ }
71
+ /** A map setting's value: names to names, such as { bookings: "list", "orders@/shop": "grid" }. */
72
+ export type SettingMap = Readonly<Record<string, string>>;
73
+ /** A stored value: what the JSON column holds. */
74
+ export type SettingValue = string | number | SettingMap;
75
+ /** Where the value in force came from (§2). */
76
+ export type SettingSource = "default" | "answers" | "owner";
77
+ /** One setting as the page shows it. */
78
+ export interface SettingState {
79
+ tool: string;
80
+ key: string;
81
+ def: SettingDef;
82
+ value: SettingValue | null;
83
+ from: SettingSource;
84
+ /** Who changed it and when, when `from` is `owner`. */
85
+ changedBy?: string;
86
+ changedAt?: string;
87
+ /** A checked change waiting for its code: the new value and when the code stops working. */
88
+ pending?: {
89
+ value: SettingValue;
90
+ expiresAt: string;
91
+ };
92
+ /** For a tool that carries: "test_only" when the value in force here differs from the one last carried to the live site. */
93
+ carry?: "carried" | "test_only";
94
+ }
95
+ /** One setting of a carried tool, as exportGroup gives it and importGroup takes it: null puts it back. */
96
+ export interface CarriedSetting {
97
+ key: string;
98
+ value: SettingValue | null;
99
+ }
100
+ /** One row of Recent changes. */
101
+ export interface SettingChange {
102
+ tool: string;
103
+ key: string;
104
+ action: "save" | "put_back";
105
+ before: SettingValue | null;
106
+ after: SettingValue | null;
107
+ by: string;
108
+ at: string;
109
+ }
package/dist/types.js ADDED
@@ -0,0 +1,5 @@
1
+ // What a tool declares about the settings an app's owner may change on the
2
+ // Settings page (docs/project-settings.md §3). Data only: the page draws
3
+ // from it, the save checks against it, and the tool reads the value back
4
+ // with settings.get(tool, key).
5
+ export {};
@@ -0,0 +1,13 @@
1
+ import type { SettingsLang } from "./types.ts";
2
+ export declare const SETTINGS_WORD_KEYS: readonly ["title", "intro", "from.default", "from.answers", "from.owner", "not_set", "save", "put_back", "saved", "unchanged", "put_back.done", "pending.sent", "pending.code", "pending.confirm", "pending.confirmed", "pending.cancel", "pending.cancelled", "code.wrong", "code.expired", "code.locked", "code.none", "history.title", "history.empty", "history.col.when", "history.col.who", "history.col.what", "history.col.change", "history.put_back", "history.not_set", "problem.text", "problem.required", "problem.too_long", "problem.too_short", "problem.email", "problem.choice", "problem.whole", "problem.too_small", "problem.too_big", "problem.failed", "problem.too_soon", "problem.too_many", "problem.send_failed", "problem.mailer_needed", "email.subject", "email.body", "problem.map", "problem.check", "map.empty", "carry.test_only"];
3
+ export type SettingsWordKey = (typeof SETTINGS_WORD_KEYS)[number];
4
+ /** The words by language, as `ui.wbsettings.<key>` would hold them. */
5
+ export declare const SETTINGS_WORDS: Readonly<Record<SettingsLang, Readonly<Record<SettingsWordKey, string>>>>;
6
+ /** The app's own words for a key, or undefined to use the package's. */
7
+ export type SettingsStrings = (key: `ui.wbsettings.${SettingsWordKey}`, lang: SettingsLang) => string | undefined;
8
+ /** A word, from the app's catalogue first, then the package's, with {name} filled in. */
9
+ export declare function settingsWord(key: SettingsWordKey, lang: SettingsLang, values?: Readonly<Record<string, string>>, t?: SettingsStrings): string;
10
+ /** A declared phrase in a language, falling back to English. */
11
+ export declare function phrase(words: {
12
+ en: string;
13
+ } & Partial<Record<SettingsLang, string>>, lang: SettingsLang): string;
package/dist/words.js ADDED
@@ -0,0 +1,221 @@
1
+ // The Settings page's own words and the code email's, keyed as the project's
2
+ // strings catalogue keys them (`ui.wbsettings.*`), in English, Tagalog and
3
+ // Taglish. A tool's labels come with its declarations (types.ts, Words). A
4
+ // word the catalogue lacks falls back to the English here. The Tagalog and
5
+ // Taglish are starter words: have a fluent reader check them before a client
6
+ // sees them.
7
+ export const SETTINGS_WORD_KEYS = [
8
+ "title",
9
+ "intro",
10
+ "from.default",
11
+ "from.answers",
12
+ "from.owner",
13
+ "not_set",
14
+ "save",
15
+ "put_back",
16
+ "saved",
17
+ "unchanged",
18
+ "put_back.done",
19
+ "pending.sent",
20
+ "pending.code",
21
+ "pending.confirm",
22
+ "pending.confirmed",
23
+ "pending.cancel",
24
+ "pending.cancelled",
25
+ "code.wrong",
26
+ "code.expired",
27
+ "code.locked",
28
+ "code.none",
29
+ "history.title",
30
+ "history.empty",
31
+ "history.col.when",
32
+ "history.col.who",
33
+ "history.col.what",
34
+ "history.col.change",
35
+ "history.put_back",
36
+ "history.not_set",
37
+ "problem.text",
38
+ "problem.required",
39
+ "problem.too_long",
40
+ "problem.too_short",
41
+ "problem.email",
42
+ "problem.choice",
43
+ "problem.whole",
44
+ "problem.too_small",
45
+ "problem.too_big",
46
+ "problem.failed",
47
+ "problem.too_soon",
48
+ "problem.too_many",
49
+ "problem.send_failed",
50
+ "problem.mailer_needed",
51
+ "email.subject",
52
+ "email.body",
53
+ "problem.map",
54
+ "problem.check",
55
+ "map.empty",
56
+ "carry.test_only",
57
+ ];
58
+ const en = {
59
+ title: "Settings",
60
+ intro: "Change how the app's tools work for your business, with nothing to install. A change shows within a minute; a new email address is used once you've typed the code we email to it.",
61
+ "from.default": "Workbench default",
62
+ "from.answers": "Set when the app was built",
63
+ "from.owner": "Changed by {by} on {when}",
64
+ not_set: "Not set",
65
+ save: "Save",
66
+ put_back: "Put back",
67
+ saved: "Saved. It's used from now on.",
68
+ "put_back.done": "Put back to how it was when the app was built.",
69
+ "pending.sent": "We've emailed a code to {value}. Type it here to start using that address. The code works for 24 hours, and nothing changes until then.",
70
+ "pending.code": "Code from the email",
71
+ "pending.confirm": "Use this address",
72
+ "pending.confirmed": "Done. {value} is used from now on.",
73
+ "code.wrong": "That code isn't right. Check the email and try again ({left} tries left).",
74
+ "code.expired": "That code has stopped working. Save the address again to get a new one.",
75
+ "code.locked": "Too many wrong codes. Save the address again to get a new one.",
76
+ "code.none": "There's no code waiting for this setting. Save the address to get one.",
77
+ "history.title": "Recent changes",
78
+ "history.empty": "Nothing has been changed yet.",
79
+ "history.col.when": "When",
80
+ "history.col.who": "Who",
81
+ "history.col.what": "Setting",
82
+ "history.col.change": "Change",
83
+ "history.put_back": "Put back",
84
+ "history.not_set": "not set",
85
+ "problem.text": "That can't be saved. Type it again without special characters.",
86
+ "problem.required": "This can't be empty.",
87
+ "problem.too_long": "That's too long: {max} characters at most.",
88
+ "problem.too_short": "That's too short: {min} characters at least.",
89
+ "problem.email": "That doesn't look like an email address. Check it and try again.",
90
+ "problem.choice": "Pick one of the choices.",
91
+ "problem.whole": "Type a whole number, such as 3.",
92
+ "problem.too_small": "That's too small: {min} at least.",
93
+ "problem.too_big": "That's too big: {max} at most.",
94
+ "problem.failed": "The settings can't be saved right now. Try again in a minute.",
95
+ "email.subject": "Your code for {app}",
96
+ "email.body": "Someone asked for {app} to use this address for \"{setting}\".\n\nIf that was you, type this code on the Settings page: {code}\n\nIt works for 24 hours. If it wasn't you, ignore this email: nothing changes.",
97
+ unchanged: "Nothing to change: that's already in use.",
98
+ "pending.cancel": "Cancel",
99
+ "pending.cancelled": "Cancelled. Nothing has changed.",
100
+ "problem.too_soon": "We sent a code less than a minute ago. Check that email, or wait a minute and save again.",
101
+ "problem.too_many": "We've sent five codes for this today. Try again tomorrow, or use one of the codes already sent.",
102
+ "problem.send_failed": "We couldn't send the code to that address, so nothing has changed. Check the address and try again in a few minutes.",
103
+ "problem.mailer_needed": "This app can't send the code email yet, so this setting can't be changed here. Ask whoever looks after the app to finish setting up its emails.",
104
+ "problem.map": "That isn't a list this setting can hold.",
105
+ "problem.check": "{message}",
106
+ "map.empty": "Nothing chosen yet.",
107
+ "carry.test_only": "On the test site only: it reaches the live site with the next release you approve.",
108
+ };
109
+ const tl = {
110
+ title: "Mga setting",
111
+ intro: "Baguhin kung paano gumagana ang mga tool ng app para sa negosyo mo, walang kailangang i-install. Lalabas ang pagbabago sa loob ng isang minuto; gagamitin ang bagong email address kapag na-type mo na ang code na ie-email namin dito.",
112
+ "from.default": "Default ng Workbench",
113
+ "from.answers": "Itinakda nang gawin ang app",
114
+ "from.owner": "Binago ni {by} noong {when}",
115
+ not_set: "Wala pa",
116
+ save: "I-save",
117
+ put_back: "Ibalik",
118
+ saved: "Na-save. Gagamitin na ito mula ngayon.",
119
+ "put_back.done": "Ibinalik sa dati, gaya nang gawin ang app.",
120
+ "pending.sent": "Nag-email kami ng code sa {value}. I-type ito dito para magamit ang address na iyon. Gumagana ang code nang 24 oras, at walang magbabago hanggang doon.",
121
+ "pending.code": "Code mula sa email",
122
+ "pending.confirm": "Gamitin ang address na ito",
123
+ "pending.confirmed": "Tapos na. Gagamitin na ang {value} mula ngayon.",
124
+ "code.wrong": "Mali ang code. Tingnan ang email at subukan ulit ({left} subok pa).",
125
+ "code.expired": "Hindi na gumagana ang code. I-save ulit ang address para makakuha ng bago.",
126
+ "code.locked": "Sobrang daming maling code. I-save ulit ang address para makakuha ng bago.",
127
+ "code.none": "Walang naghihintay na code para sa setting na ito. I-save ang address para makakuha.",
128
+ "history.title": "Mga huling pagbabago",
129
+ "history.empty": "Wala pang binago.",
130
+ "history.col.when": "Kailan",
131
+ "history.col.who": "Sino",
132
+ "history.col.what": "Setting",
133
+ "history.col.change": "Pagbabago",
134
+ "history.put_back": "Ibinalik",
135
+ "history.not_set": "wala",
136
+ "problem.text": "Hindi ito ma-save. I-type ulit nang walang espesyal na character.",
137
+ "problem.required": "Hindi ito puwedeng walang laman.",
138
+ "problem.too_long": "Masyadong mahaba: hanggang {max} character lang.",
139
+ "problem.too_short": "Masyadong maikli: kahit {min} character.",
140
+ "problem.email": "Mukhang hindi ito email address. Tingnan at subukan ulit.",
141
+ "problem.choice": "Pumili ng isa sa mga pagpipilian.",
142
+ "problem.whole": "Mag-type ng buong numero, gaya ng 3.",
143
+ "problem.too_small": "Masyadong maliit: kahit {min}.",
144
+ "problem.too_big": "Masyadong malaki: hanggang {max} lang.",
145
+ "problem.failed": "Hindi ma-save ang mga setting ngayon. Subukan ulit pagkalipas ng isang minuto.",
146
+ "email.subject": "Ang code mo para sa {app}",
147
+ "email.body": "May humiling na gamitin ng {app} ang address na ito para sa \"{setting}\".\n\nKung ikaw iyon, i-type ang code na ito sa page ng Mga setting: {code}\n\nGumagana ito nang 24 oras. Kung hindi ikaw, huwag pansinin ang email na ito: walang magbabago.",
148
+ unchanged: "Walang babaguhin: iyan na ang ginagamit.",
149
+ "pending.cancel": "Kanselahin",
150
+ "pending.cancelled": "Kinansela. Walang nagbago.",
151
+ "problem.too_soon": "Nagpadala kami ng code wala pang isang minuto ang nakalipas. Tingnan ang email na iyon, o maghintay ng isang minuto at i-save ulit.",
152
+ "problem.too_many": "Limang code na ang naipadala namin para dito ngayong araw. Subukan ulit bukas, o gamitin ang isa sa mga naipadalang code.",
153
+ "problem.send_failed": "Hindi namin maipadala ang code sa address na iyon, kaya walang nagbago. Tingnan ang address at subukan ulit pagkalipas ng ilang minuto.",
154
+ "problem.mailer_needed": "Hindi pa makapagpadala ng code ang app na ito, kaya hindi mababago dito ang setting na ito. Hilingin sa nag-aalaga ng app na tapusin ang pag-set up ng mga email nito.",
155
+ "problem.map": "Hindi ito listahang kayang hawakan ng setting na ito.",
156
+ "problem.check": "{message}",
157
+ "map.empty": "Wala pang napili.",
158
+ "carry.test_only": "Sa test site lang: mapupunta ito sa live site sa susunod na release na aaprubahan mo.",
159
+ };
160
+ const taglish = {
161
+ title: "Settings",
162
+ intro: "I-change kung paano gumagana ang tools ng app para sa business mo, walang kailangang i-install. Makikita ang change within a minute; magagamit ang bagong email address pag na-type mo na ang code na ie-email namin dito.",
163
+ "from.default": "Workbench default",
164
+ "from.answers": "Na-set nung ginawa ang app",
165
+ "from.owner": "Chinange ni {by} noong {when}",
166
+ not_set: "Wala pa",
167
+ save: "Save",
168
+ put_back: "Ibalik",
169
+ saved: "Na-save na. Gagamitin na ito from now on.",
170
+ "put_back.done": "Ibinalik sa dati, gaya nung ginawa ang app.",
171
+ "pending.sent": "Nag-email kami ng code sa {value}. I-type mo dito para magamit ang address na yan. Valid ang code for 24 hours, at walang magbabago hanggang doon.",
172
+ "pending.code": "Code galing sa email",
173
+ "pending.confirm": "Gamitin ang address na ito",
174
+ "pending.confirmed": "Done. Gagamitin na ang {value} from now on.",
175
+ "code.wrong": "Mali ang code. I-check ang email at try ulit ({left} tries pa).",
176
+ "code.expired": "Expired na ang code. I-save ulit ang address para sa bagong code.",
177
+ "code.locked": "Sobrang daming maling code. I-save ulit ang address para sa bagong code.",
178
+ "code.none": "Walang code na naghihintay para sa setting na ito. I-save ang address para makakuha.",
179
+ "history.title": "Recent changes",
180
+ "history.empty": "Wala pang na-change.",
181
+ "history.col.when": "Kailan",
182
+ "history.col.who": "Sino",
183
+ "history.col.what": "Setting",
184
+ "history.col.change": "Change",
185
+ "history.put_back": "Ibinalik",
186
+ "history.not_set": "wala",
187
+ "problem.text": "Hindi ma-save. I-type ulit nang walang special characters.",
188
+ "problem.required": "Hindi puwedeng empty ito.",
189
+ "problem.too_long": "Masyadong mahaba: {max} characters lang max.",
190
+ "problem.too_short": "Masyadong maikli: at least {min} characters.",
191
+ "problem.email": "Mukhang hindi email address ito. I-check at try ulit.",
192
+ "problem.choice": "Pumili ng isa sa choices.",
193
+ "problem.whole": "Mag-type ng whole number, like 3.",
194
+ "problem.too_small": "Masyadong maliit: at least {min}.",
195
+ "problem.too_big": "Masyadong malaki: {max} max.",
196
+ "problem.failed": "Hindi ma-save ang settings ngayon. Try ulit after a minute.",
197
+ "email.subject": "Ang code mo para sa {app}",
198
+ "email.body": "May nag-request na gamitin ng {app} ang address na ito para sa \"{setting}\".\n\nKung ikaw yun, i-type ang code na ito sa Settings page: {code}\n\nValid ito for 24 hours. Kung hindi ikaw, i-ignore lang ang email na ito: walang magbabago.",
199
+ unchanged: "Walang i-change: yan na ang gamit.",
200
+ "pending.cancel": "Cancel",
201
+ "pending.cancelled": "Na-cancel. Walang nagbago.",
202
+ "problem.too_soon": "Nag-send kami ng code less than a minute ago. I-check ang email na yun, o wait ng isang minute at i-save ulit.",
203
+ "problem.too_many": "Limang code na ang na-send namin para dito today. Try ulit bukas, o gamitin ang isa sa mga na-send na code.",
204
+ "problem.send_failed": "Hindi namin ma-send ang code sa address na yan, kaya walang nagbago. I-check ang address at try ulit after a few minutes.",
205
+ "problem.mailer_needed": "Hindi pa maka-send ng code email ang app na ito, kaya hindi ma-change dito ang setting na ito. Sabihan ang nag-aalaga ng app na tapusin ang setup ng emails nito.",
206
+ "problem.map": "Hindi ito list na kayang i-hold ng setting na ito.",
207
+ "problem.check": "{message}",
208
+ "map.empty": "Wala pang napili.",
209
+ "carry.test_only": "Sa test site lang: mapupunta ito sa live site sa next release na i-approve mo.",
210
+ };
211
+ /** The words by language, as `ui.wbsettings.<key>` would hold them. */
212
+ export const SETTINGS_WORDS = { en, tl, taglish };
213
+ const fill = (text, values) => text.replace(/\{(\w+)\}/g, (m, name) => (Object.hasOwn(values, name) ? values[name] : m));
214
+ /** A word, from the app's catalogue first, then the package's, with {name} filled in. */
215
+ export function settingsWord(key, lang, values = {}, t) {
216
+ return fill(t?.(`ui.wbsettings.${key}`, lang) ?? SETTINGS_WORDS[lang][key] ?? SETTINGS_WORDS.en[key], values);
217
+ }
218
+ /** A declared phrase in a language, falling back to English. */
219
+ export function phrase(words, lang) {
220
+ return words[lang] ?? words.en;
221
+ }
package/package.json CHANGED
@@ -1,6 +1,54 @@
1
1
  {
2
2
  "name": "@mccaskie-labs/workbench-settings",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.2.0",
4
+ "description": "One Settings page in a Workbench app's admin: each tool declares the settings an owner may change, the page checks and saves them in the app's own database, and the tools read them when they run, so a change needs no redeploy. A new email address is proved with an emailed code first. No Gateway call of its own.",
5
+ "license": "UNLICENSED",
6
+ "type": "module",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/mccaskie-labs/workbench.git",
10
+ "directory": "packages/settings"
11
+ },
12
+ "engines": {
13
+ "node": ">=24"
14
+ },
15
+ "sideEffects": false,
16
+ "exports": {
17
+ ".": {
18
+ "types": "./dist/index.d.ts",
19
+ "default": "./dist/index.js"
20
+ },
21
+ "./styles": {
22
+ "types": "./dist/styles.d.ts",
23
+ "default": "./dist/styles.js"
24
+ },
25
+ "./samples": {
26
+ "types": "./dist/samples.d.ts",
27
+ "default": "./dist/samples.js"
28
+ },
29
+ "./package.json": "./package.json"
30
+ },
31
+ "bin": {
32
+ "workbench-settings": "./dist/cli.js"
33
+ },
34
+ "files": [
35
+ "dist",
36
+ "README.md",
37
+ "CHANGELOG.md"
38
+ ],
39
+ "publishConfig": {
40
+ "access": "public"
41
+ },
42
+ "scripts": {
43
+ "typecheck": "tsc -p tsconfig.check.json && tsc -p test/tsconfig.json",
44
+ "test": "vitest run",
45
+ "test:store": "vitest run --config vitest.db.config.ts",
46
+ "build": "node scripts/build.mjs",
47
+ "prepack": "node scripts/build.mjs"
48
+ },
49
+ "devDependencies": {
50
+ "@types/node": "24.19.2",
51
+ "postgres": "4.1.0",
52
+ "vitest": "^5.1.0"
53
+ }
54
+ }