Skip to content

Commit cfce553

Browse files
committed
refactor(messaging): name the object-label param's member object, the object's API name it holds
Claude-Session: https://claude.ai/code/session_01ADHkmQNmyLgnBbCoc2iFjL Co-authored-by: Claude <noreply@anthropic.com>
1 parent 0b91c34 commit cfce553

6 files changed

Lines changed: 29 additions & 27 deletions

File tree

‎.changeset/35384-step-label-and-notification-object-label.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Metadata-protocol: none
1212
In a deployment whose `i18n.sourceLocale` differs from its `i18n.defaultLocale` (an app authored in English that defaults its users to Chinese), an English reader was shown the Chinese approval step name, and an English approval-notification recipient read the Chinese object name inside an English sentence. Both labels were read through `II18nService.t()`, which falls back to the `defaultLocale` row; `/meta` serves the authored text. Both now resolve the way the metadata route resolves a label: the reader's negotiated locale, the declared fallback chain, and the authored language (the declared `sourceLocale`, else `defaultLocale`).
1313

1414
- **`@objectstack/spec`** adds `resolveFlowApprovalStepLabel(bundle, flowName, nodeId, literal?, opts?)` (`@objectstack/spec/system`), the one reading of `flows.<flow>.approvals.<node_id>.label`: the requested locale, then the declared fallback chain (skipped for the authored locale), then `literal`. It takes the flow's name and the node's id, so a reader holding only an approval request row needs no flow document.
15-
- **`@objectstack/service-messaging`** accepts a new `NotificationTextKeys.params` value, `{ objectLabel: '<object>', fallback }` (`NotificationObjectLabelParam`): the label of that object in the recipient's language, resolved as `GET /meta/object/:name` serves it, by `translateObject` over the object's served definition and its packaged base, so a renamed packaged object is named by its rename. It renders the same way on the inline fan-out, the dispatcher (digests included) and the inbox reader. `fallback` is delivered when nothing resolves. The `{ key, fallback }` value is still accepted and still renders through `t()`, so stored deliveries and inbox rows render as before.
15+
- **`@objectstack/service-messaging`** accepts a new `NotificationTextKeys.params` value, `{ object: '<object API name>', fallback }` (`NotificationObjectLabelParam`): the label of that object in the recipient's language, resolved as `GET /meta/object/:name` serves it, by `translateObject` over the object's served definition and its packaged base, so a renamed packaged object is named by its rename. It renders the same way on the inline fan-out, the dispatcher (digests included) and the inbox reader. `fallback` is delivered when nothing resolves. The `{ key, fallback }` value is still accepted and still renders through `t()`, so stored deliveries and inbox rows render as before.
1616
- **`@objectstack/plugin-approvals`** names a notification's object with that typed param, and reads the approval step label through `resolveFlowApprovalStepLabel`, so `t()` carries catalog sentences only.
1717

1818
Upgrade `@objectstack/plugin-approvals` and `@objectstack/service-messaging` together: an older messaging service refuses the typed param at `emit()`.

‎packages/plugins/plugin-approvals/src/approval-notification-keyed-text.integration.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ describe('#24978 — end to end: a real messaging service renders each approver\
365365
/**
366366
* [#35384] The object an approval notification names is labelled as
367367
* `GET /meta/object/:name` serves it: the subject param is the messaging
368-
* service's typed object-label param (`{ objectLabel, fallback }`), resolved
368+
* service's typed object-label param (`{ object, fallback }`), resolved
369369
* per recipient by `translateObject` with the metadata route's resolve options
370370
* and the object's packaged base, never through `t()`.
371371
*

‎packages/plugins/plugin-approvals/src/approval-notification-text.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
* (`ApprovalService.notify` resolves it per recipient); the #23556 / #23594
3333
* ruling B form, label and id for every reader, stands only on the
3434
* reader-less action-link pages. [#35384] The label rides as the messaging
35-
* service's typed object-label param, `{ objectLabel: <object>, fallback }`,
35+
* service's typed object-label param, `{ object: <object API name>, fallback }`,
3636
* which it resolves per recipient as `GET /meta/object/:name` serves the
3737
* object (`translateObject` with the metadata route's resolve options and the
3838
* packaged base), the way the reader-language labels (`reader-locale-labels.ts`)
@@ -55,7 +55,8 @@ export type ApprovalTextParam =
5555

5656
/** [#35384] The structural mirror of the messaging service's `NotificationObjectLabelParam`. */
5757
export interface ApprovalObjectLabelParam {
58-
readonly objectLabel: string;
58+
/** The object's API name, never its label. */
59+
readonly object: string;
5960
readonly fallback: string;
6061
}
6162

@@ -105,7 +106,7 @@ export function subjectParams(
105106
record: string,
106107
): ApprovalSubjectParams {
107108
return {
108-
object: { objectLabel: objectName, fallback: objectLabel ?? objectName },
109+
object: { object: objectName, fallback: objectLabel ?? objectName },
109110
record,
110111
};
111112
}

‎packages/plugins/plugin-approvals/src/no-approver-note.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const deliveredIn = (
4343
for (const [name, param] of Object.entries(notice.params)) {
4444
if (typeof param === 'string') { params[name] = param; continue; }
4545
// [#35384] An object-label param is resolved off the object's metadata, which no notice here names.
46-
if ('objectLabel' in param) { params[name] = param.fallback; continue; }
46+
if ('object' in param) { params[name] = param.fallback; continue; }
4747
const looked = param.key.startsWith('messages.') ? catalog[param.key.slice('messages.'.length)] : pack[param.key];
4848
params[name] = looked ?? param.fallback;
4949
}

‎packages/services/service-messaging/src/keyed-notification-text.integration.test.ts‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,7 @@ describe("#32240 — an inbox row reads in the READER's language", () => {
725725
});
726726

727727
/**
728-
* [#35384] The typed object-label param, `{ objectLabel, fallback }`: an
728+
* [#35384] The typed object-label param, `{ object, fallback }`: an
729729
* object's label is METADATA, so it is resolved as `GET /meta/object/:name`
730730
* serves it — `translateObject` over the object's served definition and its
731731
* packaged base, with the metadata route's resolve options (the recipient's
@@ -751,7 +751,7 @@ describe('#35384 — an object label param reads as /meta serves the object', ()
751751
const TYPED: NotificationTextKeys = {
752752
titleKey: 'messages.dealTitle',
753753
bodyKey: 'messages.dealBody',
754-
params: { object: { objectLabel: 'crm_deal', fallback: 'Opportunity' }, record: 'D_1' },
754+
params: { object: { object: 'crm_deal', fallback: 'Opportunity' }, record: 'D_1' },
755755
};
756756
const LEGACY: NotificationTextKeys = {
757757
...TYPED,
@@ -866,11 +866,11 @@ describe('#35384 — an object label param reads as /meta serves the object', ()
866866
const ql = await bootDeal();
867867
const { messaging } = compose(ql, { i18n: sourceLocaleI18n() });
868868
const bad: unknown[] = [
869-
{ objectLabel: 'crm_deal' }, // no fallback
870-
{ objectLabel: 'crm deal', fallback: 'Deal' }, // not an object's API name
871-
{ objectLabel: 'objects.crm_deal.label', fallback: 'Deal' }, // a catalog key is not a name
872-
{ objectLabel: 'crm_deal', fallback: 'Deal', key: 'objects.crm_deal.label' }, // both shapes at once
873-
{ objectLabel: 7, fallback: 'Deal' },
869+
{ object: 'crm_deal' }, // no fallback
870+
{ object: 'crm deal', fallback: 'Deal' }, // not an object's API name
871+
{ object: 'objects.crm_deal.label', fallback: 'Deal' }, // a catalog key is not a name
872+
{ object: 'crm_deal', fallback: 'Deal', key: 'objects.crm_deal.label' }, // both shapes at once
873+
{ object: 7, fallback: 'Deal' },
874874
];
875875
for (const object of bad) {
876876
const keyedText = { ...TYPED, params: { object, record: 'D_1' } };

‎packages/services/service-messaging/src/notification-text.ts‎

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@
2727
* - `params` fills the entries' `{{name}}` holes. A value is used as given,
2828
* or, spelled `{ key, fallback }`, is itself the recipient-language text of
2929
* the catalog entry `key`, else `fallback`; or, spelled
30-
* `{ objectLabel, fallback }`, is the label of the object named
31-
* `objectLabel` in the recipient's language, else `fallback`.
30+
* `{ object, fallback }`, is the label of the object whose API name is
31+
* `object`, in the recipient's language, else `fallback`.
3232
* - [#35384] An object's label is METADATA, not a catalog sentence, so the
33-
* `{ objectLabel }` param is resolved as `GET /meta/object/:name` serves it:
33+
* `{ object }` param is resolved as `GET /meta/object/:name` serves it:
3434
* by `translateObject` (`@objectstack/spec/system`) over the object's
3535
* served definition and its packaged base, with the metadata route's
3636
* `ResolveOptions` (the recipient's negotiated locale, the DECLARED
@@ -98,15 +98,16 @@ export type NotificationTextParam =
9898
| NotificationObjectLabelParam;
9999

100100
/**
101-
* [#35384] A `{{name}}` value that is the label of the object `objectLabel`
102-
* names (its API name, `crm_deal`), in the recipient's language, as
101+
* [#35384] A `{{name}}` value that is the label of the object whose API name
102+
* `object` holds (`crm_deal`), in the recipient's language, as
103103
* `GET /meta/object/:name` serves it: `translateObject` over the object's
104104
* served definition and packaged base, with the metadata route's resolve
105105
* options. `fallback` is the text when nothing resolves (no `i18n` service
106106
* that can hand its translations over, no data engine that knows the object).
107107
*/
108108
export interface NotificationObjectLabelParam {
109-
readonly objectLabel: string;
109+
/** The object's API name (`ObjectSchema.name`), never its label: the param names the object, the render picks its label. */
110+
readonly object: string;
110111
readonly fallback: string;
111112
}
112113

@@ -158,7 +159,7 @@ const PARAM_NAME_SHAPE = /^\w+$/;
158159

159160
const TEXT_MEMBERS: ReadonlySet<string> = new Set(['titleKey', 'bodyKey', 'params']);
160161
const KEYED_PARAM_MEMBERS: ReadonlySet<string> = new Set(['key', 'fallback']);
161-
const OBJECT_LABEL_PARAM_MEMBERS: ReadonlySet<string> = new Set(['objectLabel', 'fallback']);
162+
const OBJECT_LABEL_PARAM_MEMBERS: ReadonlySet<string> = new Set(['object', 'fallback']);
162163

163164
/**
164165
* An object's API name: one segment of {@link CATALOG_KEY_SHAPE}, so every
@@ -194,15 +195,15 @@ function problemOf(value: unknown): string | undefined {
194195
for (const [name, param] of Object.entries(params)) {
195196
if (!PARAM_NAME_SHAPE.test(name)) return `.params has a name '${name}' no {{hole}} can spell`;
196197
if (typeof param === 'string') continue;
197-
if (!isPlainObject(param)) return `.params.${name} must be a string, { key, fallback } or { objectLabel, fallback }`;
198-
if ('objectLabel' in param) {
198+
if (!isPlainObject(param)) return `.params.${name} must be a string, { key, fallback } or { object, fallback }`;
199+
if ('object' in param) {
199200
for (const member of Object.keys(param)) {
200201
if (!OBJECT_LABEL_PARAM_MEMBERS.has(member)) {
201-
return `.params.${name} has an undeclared member '${member}' (declared: objectLabel, fallback)`;
202+
return `.params.${name} has an undeclared member '${member}' (declared: object, fallback)`;
202203
}
203204
}
204-
if (typeof param.objectLabel !== 'string' || !OBJECT_NAME_SHAPE.test(param.objectLabel)) {
205-
return `.params.${name}.objectLabel must be an object's API name such as 'crm_deal' (got ${JSON.stringify(param.objectLabel)})`;
205+
if (typeof param.object !== 'string' || !OBJECT_NAME_SHAPE.test(param.object)) {
206+
return `.params.${name}.object must be an object's API name such as 'crm_deal' (got ${JSON.stringify(param.object)})`;
206207
}
207208
if (typeof param.fallback !== 'string') return `.params.${name}.fallback must be a string`;
208209
continue;
@@ -375,9 +376,9 @@ export class NotificationTextRenderer {
375376
for (const [name, param] of Object.entries(keys.params ?? {})) {
376377
if (typeof param === 'string') {
377378
params[name] = param;
378-
} else if ('objectLabel' in param) {
379+
} else if ('object' in param) {
379380
translation ??= { value: metaLabelTranslation(i18n, locale) };
380-
params[name] = this.objectLabel(translation.value, param.objectLabel) ?? param.fallback;
381+
params[name] = this.objectLabel(translation.value, param.object) ?? param.fallback;
381382
} else {
382383
params[name] = lookup(i18n, param.key, locale) ?? param.fallback;
383384
}

0 commit comments

Comments
 (0)