Repository navigation
Expand file tree
/
Copy pathsys-email-template.object.ts
More file actions
233 lines (220 loc) · 8.73 KB
/
Copy pathsys-email-template.object.ts
File metadata and controls
233 lines (220 loc) · 8.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
import { ObjectSchema, Field } from '@objectstack/spec/data';
/**
* sys_email_template — Outbound Email Template (legacy rows)
*
* No mail is sent from this table any more (ADR-0131 D6/D10, ruling C on
* §6 Q1). Email templates are `email_template` metadata, read from the
* registry by an EXACT `(name, locale)` match: the built-in auth templates
* code-declared by `@objectstack/plugin-email`, the ones an app declares, and
* the ones authored in Studio (environment level). See plugin-email's
* `createRegistryEmailTemplateLoader` and `SendTemplateInput.locale` for the
* ladder of record.
*
* What the table still holds is the rows earlier releases wrote — the
* built-in seed, the declared-template sweep and the Studio projection —
* including rows an organization customized before its door closed. Those
* customized rows are the population the v18 migration ceremony promotes to
* environment-level Studio templates; nothing else reads, writes or deletes
* them. An organization does not create or edit a row here:
* `@objectstack/plugin-email` refuses a non-system create or update
* (ADR-0131 D6).
*
* @namespace sys
*/
export const SysEmailTemplate = ObjectSchema.create({
name: 'sys_email_template',
label: 'Email Template',
pluralLabel: 'Email Templates',
icon: 'mail',
isSystem: true,
managedBy: 'config',
description: 'Outbound email template (subject + body + variables) resolved by name+locale',
displayNameField: 'label',
nameField: 'label', // [ADR-0079] canonical primary-title pointer (mirrors deprecated displayNameField)
highlightFields: ['name', 'label', 'category', 'locale', 'active'],
fields: {
id: Field.text({
label: 'ID',
required: true,
readonly: true,
group: 'System',
}),
// ── Identity ─────────────────────────────────────────────────
name: Field.text({
label: 'Name',
required: true,
maxLength: 128,
description: 'Dotted snake_case identifier (e.g. auth.password_reset)',
group: 'Identity',
}),
// [ADR-0150 D8 row R20] The package that holds the email template `name`
// names, beside the name (ADR-0126 §4). Backfilled at boot by
// `@objectstack/plugin-email` from the template's one package holder, the
// email service's own built-in templates included (its overridable
// baseline, ADR-0150 D3 (b)); empty for a template the environment
// authored and for a name no single package holds. The v18 promotion
// ceremony is its reader-to-be; nothing reads it yet and nothing else
// writes it. Width: the package-id class (`sys_metadata.package_id`).
package_id: Field.text({
label: 'Package',
required: false,
readonly: true,
maxLength: 255,
description: 'The app the template comes from. Filled in by the platform; empty for templates created here.',
group: 'Identity',
}),
label: Field.text({
label: 'Label',
required: true,
maxLength: 200,
description: 'Human-readable name shown in App Studio',
group: 'Identity',
}),
category: Field.select(
['auth', 'notification', 'workflow', 'marketing', 'custom'],
{
label: 'Category',
required: true,
defaultValue: 'custom',
group: 'Identity',
},
),
locale: Field.text({
label: 'Locale',
required: true,
defaultValue: 'en-US',
maxLength: 16,
description: 'BCP-47 locale tag (en-US, zh-CN, …)',
group: 'Identity',
}),
description: Field.textarea({
label: 'Description',
required: false,
group: 'Identity',
}),
// ── Content ──────────────────────────────────────────────────
subject: Field.text({
label: 'Subject',
required: true,
maxLength: 500,
description: 'Subject template; supports {{var.path}} placeholders',
group: 'Content',
}),
body_html: Field.textarea({
label: 'HTML Body',
required: true,
description: 'HTML body template; supports {{var.path}} placeholders',
group: 'Content',
}),
body_text: Field.textarea({
label: 'Plain Text Body',
required: false,
description: 'Optional plain-text alternative (auto-derived from HTML when blank)',
group: 'Content',
}),
// ── Envelope overrides ───────────────────────────────────────
from_name: Field.text({
label: 'From Name',
required: false,
maxLength: 200,
group: 'Envelope',
}),
from_address: Field.text({
label: 'From Address',
required: false,
maxLength: 255,
group: 'Envelope',
}),
reply_to: Field.text({
label: 'Reply-To',
required: false,
maxLength: 255,
group: 'Envelope',
}),
// ── Lifecycle ────────────────────────────────────────────────
active: Field.boolean({
label: 'Active',
required: true,
defaultValue: true,
group: 'Lifecycle',
}),
is_system: Field.boolean({
label: 'System Template',
required: false,
defaultValue: false,
readonly: true,
description: 'Provided by a plugin / platform',
group: 'Lifecycle',
}),
/**
* Variables declared by the template author. Stored as JSON text
* (array of {name,type,required,description}). Used by the Studio
* authoring UI to render form hints and by sendTemplate() to
* validate required vars at runtime.
*/
variables_json: Field.textarea({
label: 'Variables (JSON)',
required: false,
description: 'JSON array of {name,type,required,description}',
group: 'Lifecycle',
}),
// ── Provenance (#4509 — record-authoritative seed-not-clobber) ──
// Mirrors sys_webhook (#3461) / sys_sharing_rule (#2909). Recorded on the
// rows earlier releases wrote: `is_system` was the built-in seed's axis,
// and these two tracked the DECLARED metadata door — `package` rows the
// boot sweep re-seeded, and the `customized` mark it skipped. Both are
// `readonly` — the engine strips them from non-system payloads. Nothing
// writes either any more: templates resolve from the registry, and
// ADR-0131 ruling C closed the organization door. The rows already marked
// `customized` are the population the v18 migration ceremony promotes to
// environment-level Studio templates.
managed_by: Field.select(
['platform', 'package', 'admin'],
{
label: 'Managed By',
required: false,
readonly: true,
defaultValue: 'admin',
description:
'Record provenance: platform = framework built-in / package = app/package-declared ' +
'(boot-seeded from declared email_template metadata) / admin = created in App Studio.',
group: 'System',
},
),
customized: Field.boolean({
label: 'Customized',
required: false,
readonly: true,
defaultValue: false,
description:
'Set on a package-declared template an admin edited before organization-level template ' +
'editing closed; boot seeding never overwrites such a row. Nothing sets it any more. ' +
'Meaningless on admin rows.',
group: 'System',
}),
created_at: Field.datetime({
label: 'Created At',
required: true,
defaultValue: 'NOW()',
readonly: true,
group: 'System',
}),
updated_at: Field.datetime({ label: 'Updated At', required: false, group: 'System' }),
},
indexes: [
// [#8554] Scope spelled EXPLICITLY (ADR-0120 D1). On a DECLARED index bare
// `unique: true` is the positional spelling of `'global'` — the listed
// columns VERBATIM, composite included — so `(name, locale)` was an
// installation-wide key on a tenant-scoped object. Measured live before the
// fix: org_jia creates (welcome, en-US) 201 / org_yi the SAME pair 409
// UNIQUE_VIOLATION / org_yi (other_tpl, en-US) 201 / org_yi (welcome, zh-CN)
// 201 / org_yi's own GET on the colliding pair 0 rows. The last two controls
// are what prove the key was the composite rather than `name` alone.
// Admins author and overlay templates per tenant, so two organizations both
// holding a `welcome` / `en-US` template is the normal case.
{ fields: ['name', 'locale'], unique: 'organization' },
{ fields: ['category'] },
{ fields: ['active'] },
],
});