@agent-native/core 0.138.0 → 0.140.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.
Files changed (100) hide show
  1. package/corpus/README.md +1 -1
  2. package/corpus/templates/analytics/server/lib/dashboard-report.ts +2 -0
  3. package/corpus/templates/analytics/server/lib/emails.ts +51 -0
  4. package/corpus/templates/analytics/server/plugins/transactional-emails.ts +5 -0
  5. package/corpus/templates/calendar/server/lib/booking-emails.ts +154 -70
  6. package/corpus/templates/calendar/server/lib/emails.ts +167 -0
  7. package/corpus/templates/calendar/server/lib/event-guest-notifications.ts +64 -28
  8. package/corpus/templates/calendar/server/plugins/transactional-emails.ts +5 -0
  9. package/corpus/templates/clips/actions/invite-member.ts +39 -15
  10. package/corpus/templates/clips/server/lib/emails.ts +256 -0
  11. package/corpus/templates/clips/server/lib/transactional-email-templates.ts +24 -0
  12. package/corpus/templates/clips/server/plugins/transactional-email-catalog.ts +5 -0
  13. package/corpus/templates/content/server/lib/comment-notifications.ts +57 -26
  14. package/corpus/templates/content/server/lib/emails.ts +70 -0
  15. package/corpus/templates/content/server/plugins/transactional-emails.ts +5 -0
  16. package/corpus/templates/design/.agents/skills/design-systems/SKILL.md +44 -1
  17. package/corpus/templates/design/.generated/bridge/editor-chrome.generated.ts +265 -1
  18. package/corpus/templates/design/actions/create-design-system.ts +9 -10
  19. package/corpus/templates/design/actions/get-design-system.ts +53 -0
  20. package/corpus/templates/design/actions/import-design-tokens.ts +5 -71
  21. package/corpus/templates/design/actions/index-design-tokens.ts +61 -80
  22. package/corpus/templates/design/actions/update-design-system.ts +7 -10
  23. package/corpus/templates/design/app/components/design/EditPanel.tsx +45 -2
  24. package/corpus/templates/design/app/components/design/bridge/editor-chrome.bridge.ts +12 -0
  25. package/corpus/templates/design/app/components/design/edit-panel/design-system-swatches.ts +215 -0
  26. package/corpus/templates/design/app/components/design/edit-panel/document-colors.ts +10 -6
  27. package/corpus/templates/design/app/components/design/edit-panel/effects-properties.tsx +19 -3
  28. package/corpus/templates/design/app/components/design/edit-panel/fill-properties.tsx +36 -10
  29. package/corpus/templates/design/app/components/design/edit-panel/interaction-state-helpers.ts +15 -0
  30. package/corpus/templates/design/app/components/design/edit-panel/panel-primitives.tsx +19 -1
  31. package/corpus/templates/design/app/components/design/edit-panel/position-helpers.ts +6 -0
  32. package/corpus/templates/design/app/components/design/edit-panel/stroke-properties.tsx +53 -10
  33. package/corpus/templates/design/app/components/design/inspector/DesignColorPicker.tsx +142 -4
  34. package/corpus/templates/design/app/components/design/types.ts +6 -0
  35. package/corpus/templates/design/app/i18n-data.ts +20 -0
  36. package/corpus/templates/design/app/pages/DesignSystemSetup.tsx +1 -1
  37. package/corpus/templates/design/app/pages/DesignSystems.tsx +78 -1
  38. package/corpus/templates/design/app/pages/design-editor/html-layer-positioning.ts +6 -1
  39. package/corpus/templates/design/changelog/2026-08-04-design-system-tokens-show-by-name-in-the-editor.md +6 -0
  40. package/corpus/templates/design/e2e/helpers.ts +17 -0
  41. package/corpus/templates/design/server/lib/design-system-tokens.ts +35 -0
  42. package/corpus/templates/design/shared/authored-color-styles.ts +401 -0
  43. package/corpus/templates/design/shared/resolve-tweaks.ts +10 -18
  44. package/corpus/templates/dispatch/app/routes/transactional-email.$appId.$id.tsx +4 -0
  45. package/corpus/templates/dispatch/app/routes/transactional-email.tsx +4 -0
  46. package/corpus/templates/forms/server/lib/emails.ts +52 -0
  47. package/corpus/templates/forms/server/lib/response-email.ts +2 -0
  48. package/corpus/templates/forms/server/plugins/transactional-emails.ts +5 -0
  49. package/corpus/templates/plan/actions/request-plan-access.ts +33 -12
  50. package/corpus/templates/plan/server/lib/comment-notifications.ts +53 -27
  51. package/corpus/templates/plan/server/lib/emails.ts +67 -0
  52. package/corpus/templates/plan/server/plugins/transactional-emails.ts +5 -0
  53. package/corpus/templates/slides/server/lib/comment-notifications.ts +44 -21
  54. package/corpus/templates/slides/server/lib/emails.ts +40 -0
  55. package/corpus/templates/slides/server/plugins/transactional-emails.ts +5 -0
  56. package/dist/brand-kit/index.d.ts +1 -0
  57. package/dist/brand-kit/index.js +1 -0
  58. package/dist/brand-kit/tokens.d.ts +92 -0
  59. package/dist/brand-kit/tokens.js +280 -0
  60. package/dist/brand-kit/types.d.ts +25 -0
  61. package/dist/collab/awareness.d.ts +2 -2
  62. package/dist/collab/routes.d.ts +2 -2
  63. package/dist/email-catalog/actions/list-email-activity.d.ts +6 -0
  64. package/dist/email-catalog/actions/list-email-activity.js +15 -0
  65. package/dist/email-catalog/actions/list-email-engagement.d.ts +6 -0
  66. package/dist/email-catalog/actions/list-email-engagement.js +15 -0
  67. package/dist/email-catalog/actions/list-email-log.d.ts +8 -0
  68. package/dist/email-catalog/actions/list-email-log.js +22 -0
  69. package/dist/email-catalog/actions/list-transactional-emails.d.ts +23 -0
  70. package/dist/email-catalog/actions/list-transactional-emails.js +61 -0
  71. package/dist/email-catalog/actions/render-transactional-email-preview.d.ts +10 -0
  72. package/dist/email-catalog/actions/render-transactional-email-preview.js +24 -0
  73. package/dist/email-catalog/authorize.d.ts +2 -0
  74. package/dist/email-catalog/authorize.js +10 -0
  75. package/dist/email-catalog/log.d.ts +57 -0
  76. package/dist/email-catalog/log.js +117 -0
  77. package/dist/email-catalog/provider-metrics.d.ts +34 -0
  78. package/dist/email-catalog/provider-metrics.js +165 -0
  79. package/dist/email-catalog/registry.d.ts +79 -0
  80. package/dist/email-catalog/registry.js +71 -0
  81. package/dist/email-catalog/schema.d.ts +212 -0
  82. package/dist/email-catalog/schema.js +49 -0
  83. package/dist/email-catalog/system-emails.d.ts +14 -0
  84. package/dist/email-catalog/system-emails.js +68 -0
  85. package/dist/localization/default-messages.d.ts +45 -0
  86. package/dist/localization/default-messages.js +45 -0
  87. package/dist/notifications/routes.d.ts +6 -6
  88. package/dist/org/handlers.js +8 -1
  89. package/dist/progress/routes.d.ts +1 -1
  90. package/dist/provider-api/actions/custom-provider-registration.d.ts +7 -7
  91. package/dist/provider-api/actions/provider-api.d.ts +7 -7
  92. package/dist/provider-api/corpus-jobs.d.ts +2 -2
  93. package/dist/resources/handlers.d.ts +1 -1
  94. package/dist/server/action-discovery.js +22 -0
  95. package/dist/server/better-auth-instance.js +17 -2
  96. package/dist/server/email.d.ts +9 -0
  97. package/dist/server/email.js +44 -3
  98. package/dist/server/index.d.ts +1 -0
  99. package/dist/server/index.js +1 -0
  100. package/package.json +3 -1
@@ -0,0 +1,280 @@
1
+ /**
2
+ * `@agent-native/core/brand-kit/tokens`
3
+ *
4
+ * Pure helpers for the named-token vocabulary a Brand Kit stores alongside its
5
+ * seven color roles. Kept on its own subpath (no `design-token-utils` re-export)
6
+ * so browser code can import the CSS-safety predicates without pulling the
7
+ * server-side extraction stack into the bundle.
8
+ */
9
+ const BRAND_KIT_TOKEN_TYPES = [
10
+ "color",
11
+ "typography",
12
+ "spacing",
13
+ "radius",
14
+ "shadow",
15
+ "other",
16
+ ];
17
+ /**
18
+ * Upper bound on a single kit's stored vocabulary. Large systems legitimately
19
+ * define hundreds of tokens; this only stops an unbounded scrape landing in SQL.
20
+ */
21
+ export const MAX_BRAND_KIT_TOKENS = 500;
22
+ const CSS_CUSTOM_PROPERTY_NAME = /^--[-_a-zA-Z0-9]+$/;
23
+ const COLOR_FUNCTION_OR_HEX = /^(#[0-9a-fA-F]{3,8}|rgba?\(|hsla?\(|oklch\(|color\()/i;
24
+ const NAMED_CSS_COLORS = new Set([
25
+ "red",
26
+ "blue",
27
+ "green",
28
+ "yellow",
29
+ "orange",
30
+ "purple",
31
+ "pink",
32
+ "cyan",
33
+ "magenta",
34
+ "teal",
35
+ "navy",
36
+ "maroon",
37
+ "coral",
38
+ "salmon",
39
+ "gold",
40
+ "silver",
41
+ "gray",
42
+ "grey",
43
+ "indigo",
44
+ "violet",
45
+ "lime",
46
+ "olive",
47
+ "aqua",
48
+ "fuchsia",
49
+ "crimson",
50
+ "turquoise",
51
+ "ivory",
52
+ "beige",
53
+ "lavender",
54
+ "tan",
55
+ "khaki",
56
+ "plum",
57
+ "orchid",
58
+ "sienna",
59
+ ]);
60
+ export function isSafeCssVarName(value) {
61
+ return CSS_CUSTOM_PROPERTY_NAME.test(value);
62
+ }
63
+ /**
64
+ * Token values are spliced raw into `:root { … }` declarations, so anything that
65
+ * could terminate a declaration or break out of a `<style>` element is unsafe.
66
+ */
67
+ export function isSafeCssTokenValue(value) {
68
+ return (value.length > 0 &&
69
+ value.length <= 300 &&
70
+ !/[;{}<>]/.test(value) &&
71
+ !/\/\*/.test(value) &&
72
+ !/[\u0000-\u001f\u007f]/.test(value));
73
+ }
74
+ export function isColorTokenValue(value) {
75
+ const normalized = value.trim().toLowerCase();
76
+ return (COLOR_FUNCTION_OR_HEX.test(normalized) || NAMED_CSS_COLORS.has(normalized));
77
+ }
78
+ const COLOR_NAME_HINT = /color|bg|background|text|border|accent|primary|secondary|surface|muted|foreground|fill|stroke/i;
79
+ const DIMENSION_VALUE = /^-?\d*\.?\d+(px|rem|em|ex|ch|%|vh|vw|vmin|vmax|pt|pc|cm|mm|in|s|ms|deg|fr)?$/i;
80
+ /**
81
+ * Bucket a token, trusting the value's shape over the name's keywords.
82
+ *
83
+ * Name-first classification called Primer's `--text-body-size-medium: 1rem` a
84
+ * color because the name contains "text", which then rendered a swatch with
85
+ * `background: 1rem`. A dimension is never a color however the token is named.
86
+ */
87
+ export function classifyBrandKitToken(name, value) {
88
+ const n = name.toLowerCase();
89
+ if (isColorTokenValue(value))
90
+ return "color";
91
+ if (/radius|rounded/i.test(n))
92
+ return "radius";
93
+ // `line-?height` and `letter` run before the spacing check so
94
+ // `letter-spacing` is type metrics, not layout spacing.
95
+ if (/font|size|leading|line-?height|letter|tracking|weight|heading|body|type/i.test(n)) {
96
+ return "typography";
97
+ }
98
+ if (/spacing|gap|padding|margin|space/i.test(n))
99
+ return "spacing";
100
+ if (/shadow|blur|drop/i.test(n))
101
+ return "shadow";
102
+ if (COLOR_NAME_HINT.test(n) && !DIMENSION_VALUE.test(value.trim())) {
103
+ return "color";
104
+ }
105
+ return "other";
106
+ }
107
+ /** Title-case display name derived from a CSS var, e.g. `--primary-color`. */
108
+ export function friendlyTokenName(cssVar) {
109
+ return cssVar
110
+ .replace(/^--/, "")
111
+ .replace(/[-_]/g, " ")
112
+ .replace(/\b\w/g, (c) => c.toUpperCase());
113
+ }
114
+ function readString(source, key) {
115
+ const value = source[key];
116
+ return typeof value === "string" ? value.trim() : "";
117
+ }
118
+ /**
119
+ * Coerce untrusted token JSON into storable tokens, reporting every entry it
120
+ * could not accept. Later duplicates of a `cssVar` win, matching the overlay
121
+ * order importers use.
122
+ */
123
+ export function normalizeBrandKitTokens(input) {
124
+ if (input === undefined || input === null) {
125
+ return { tokens: [], rejected: [] };
126
+ }
127
+ if (!Array.isArray(input)) {
128
+ return { tokens: [], rejected: [{ reason: "malformed", label: "tokens" }] };
129
+ }
130
+ const byCssVar = new Map();
131
+ const rejected = [];
132
+ for (const entry of input) {
133
+ if (!entry || typeof entry !== "object" || Array.isArray(entry)) {
134
+ rejected.push({ reason: "malformed", label: String(entry) });
135
+ continue;
136
+ }
137
+ const record = entry;
138
+ const cssVar = readString(record, "cssVar");
139
+ const value = readString(record, "value");
140
+ const name = readString(record, "name") || friendlyTokenName(cssVar);
141
+ if (!cssVar || !isSafeCssVarName(cssVar)) {
142
+ rejected.push({ reason: "unsafe-css-var", label: cssVar || name });
143
+ continue;
144
+ }
145
+ if (!isSafeCssTokenValue(value)) {
146
+ rejected.push({ reason: "unsafe-value", label: cssVar });
147
+ continue;
148
+ }
149
+ const declaredType = readString(record, "type");
150
+ const group = readString(record, "group");
151
+ const source = readString(record, "source");
152
+ byCssVar.set(cssVar, {
153
+ name,
154
+ cssVar,
155
+ value,
156
+ type: BRAND_KIT_TOKEN_TYPES.includes(declaredType)
157
+ ? declaredType
158
+ : classifyBrandKitToken(cssVar, value),
159
+ ...(group ? { group } : {}),
160
+ ...(source ? { source } : {}),
161
+ });
162
+ }
163
+ const tokens = [...byCssVar.values()];
164
+ if (tokens.length > MAX_BRAND_KIT_TOKENS) {
165
+ for (const token of tokens.slice(MAX_BRAND_KIT_TOKENS)) {
166
+ rejected.push({ reason: "over-limit", label: token.cssVar });
167
+ }
168
+ }
169
+ return { tokens: tokens.slice(0, MAX_BRAND_KIT_TOKENS), rejected };
170
+ }
171
+ /** Human-readable summary of why tokens were refused, for thrown errors. */
172
+ export function describeBrandKitTokenRejections(rejected) {
173
+ return rejected
174
+ .slice(0, 10)
175
+ .map((entry) => `${entry.label} (${entry.reason})`)
176
+ .join(", ");
177
+ }
178
+ /** The CSS variable each colour role is published under. */
179
+ const BRAND_KIT_COLOR_ROLE_VARS = {
180
+ primary: "--color-primary",
181
+ secondary: "--color-secondary",
182
+ accent: "--color-accent",
183
+ background: "--color-background",
184
+ surface: "--color-surface",
185
+ text: "--color-text",
186
+ textMuted: "--color-text-muted",
187
+ };
188
+ /**
189
+ * The seven colour roles plus radius/spacing, as tokens. Derived from a kit's
190
+ * summary fields rather than named by the source system, so they carry no
191
+ * `group`.
192
+ */
193
+ export function brandKitRoleTokens(data, source = "Brand Kit") {
194
+ if (!data)
195
+ return [];
196
+ const out = [];
197
+ const push = (cssVar, value) => {
198
+ if (typeof value !== "string" || !value.trim())
199
+ return;
200
+ if (!isSafeCssVarName(cssVar) || !isSafeCssTokenValue(value.trim()))
201
+ return;
202
+ out.push({
203
+ name: friendlyTokenName(cssVar),
204
+ cssVar,
205
+ value: value.trim(),
206
+ type: classifyBrandKitToken(cssVar, value.trim()),
207
+ source,
208
+ });
209
+ };
210
+ const colors = (data.colors ?? {});
211
+ const spacing = (data.spacing ?? {});
212
+ for (const [role, cssVar] of Object.entries(BRAND_KIT_COLOR_ROLE_VARS)) {
213
+ push(cssVar, colors[role]);
214
+ }
215
+ push("--radius", data.borders?.radius);
216
+ push("--spacing-element-gap", spacing.elementGap);
217
+ push("--spacing-page-padding", spacing.pagePadding);
218
+ return out;
219
+ }
220
+ const CSS_CUSTOM_PROPERTY_DECLARATION = /(--[-_a-zA-Z0-9]+)\s*:\s*([^;{}]+)[;}]/g;
221
+ /**
222
+ * Read a kit's named tokens out of a raw CSS block. A kit's `customCSS` already
223
+ * spells out the source system's real token names. Declaration order wins on
224
+ * duplicates, matching the cascade.
225
+ */
226
+ export function parseBrandKitTokensFromCss(css, source) {
227
+ const byCssVar = new Map();
228
+ for (const match of css.matchAll(CSS_CUSTOM_PROPERTY_DECLARATION)) {
229
+ const cssVar = match[1];
230
+ const value = match[2].trim();
231
+ if (!isSafeCssVarName(cssVar) || !isSafeCssTokenValue(value))
232
+ continue;
233
+ byCssVar.set(cssVar, {
234
+ name: cssVar.replace(/^--/, ""),
235
+ cssVar,
236
+ value,
237
+ type: classifyBrandKitToken(cssVar, value),
238
+ ...(source ? { source } : {}),
239
+ });
240
+ }
241
+ return [...byCssVar.values()].slice(0, MAX_BRAND_KIT_TOKENS);
242
+ }
243
+ /**
244
+ * The kit's named vocabulary: its stored `tokens` when it has them, else the
245
+ * names its `customCSS` declares. Kits predating `tokens` still carry real names
246
+ * in CSS, so reading only `tokens` would report them as having none.
247
+ */
248
+ export function resolveBrandKitTokens(data, cssSource) {
249
+ if (!data)
250
+ return [];
251
+ const stored = normalizeBrandKitTokens(data.tokens).tokens;
252
+ if (stored.length > 0)
253
+ return stored;
254
+ return typeof data.customCSS === "string"
255
+ ? parseBrandKitTokensFromCss(data.customCSS, cssSource)
256
+ : [];
257
+ }
258
+ /**
259
+ * Group tokens for display, preserving the source's collection paths. Groups sort
260
+ * by token type so colors lead, then alphabetically within a type.
261
+ */
262
+ export function groupBrandKitTokens(tokens) {
263
+ const groups = new Map();
264
+ for (const token of tokens) {
265
+ const label = token.group?.trim() || token.type;
266
+ const key = `${token.type}::${label}`;
267
+ const existing = groups.get(key);
268
+ if (existing) {
269
+ existing.tokens.push(token);
270
+ continue;
271
+ }
272
+ groups.set(key, { label, type: token.type, tokens: [token] });
273
+ }
274
+ return [...groups.values()].sort((a, b) => {
275
+ const byType = BRAND_KIT_TOKEN_TYPES.indexOf(a.type) -
276
+ BRAND_KIT_TOKEN_TYPES.indexOf(b.type);
277
+ return byType !== 0 ? byType : a.label.localeCompare(b.label);
278
+ });
279
+ }
280
+ //# sourceMappingURL=tokens.js.map
@@ -23,6 +23,25 @@ export interface BrandKitColors {
23
23
  text: string;
24
24
  textMuted: string;
25
25
  }
26
+ /** Semantic category a {@link BrandKitToken} belongs to. */
27
+ export type BrandKitTokenType = "color" | "typography" | "spacing" | "radius" | "shadow" | "other";
28
+ /**
29
+ * One token under the name its source design system uses. The seven
30
+ * {@link BrandKitColors} roles are a summary view, not a substitute: collapsing
31
+ * `interactive-01` into `secondary` discards the only name the design team has.
32
+ */
33
+ export interface BrandKitToken {
34
+ name: string;
35
+ /** e.g. `--cds-interactive-01`. */
36
+ cssVar: string;
37
+ /** Resolved value, e.g. a hex color or `0.5rem`. */
38
+ value: string;
39
+ type: BrandKitTokenType;
40
+ /** Collection path as the source organises it, e.g. `Colors/Interactive`. */
41
+ group?: string;
42
+ /** e.g. `Carbon v11` or `globals.css`. */
43
+ source?: string;
44
+ }
26
45
  /** Brand typography system. */
27
46
  export interface BrandKitTypography {
28
47
  headingFont: string;
@@ -76,6 +95,12 @@ export interface BrandKitData {
76
95
  spacing: BrandKitSpacing;
77
96
  borders: BrandKitBorders;
78
97
  logos: BrandKitLogo[];
98
+ /**
99
+ * The source system's full named vocabulary. Optional because kits predating
100
+ * it store only the role summary — absent means "never extracted", not "the
101
+ * system has none".
102
+ */
103
+ tokens?: BrandKitToken[];
79
104
  imageStyle?: BrandKitImageStyle;
80
105
  customCSS?: string;
81
106
  notes?: string;
@@ -62,11 +62,11 @@ export declare const postAwareness: import("h3").EventHandlerWithFetch<import("h
62
62
  error: string;
63
63
  states?: undefined;
64
64
  } | {
65
+ error?: undefined;
65
66
  states: {
66
67
  clientId: number;
67
68
  state: string;
68
69
  }[];
69
- error?: undefined;
70
70
  }>>;
71
71
  /**
72
72
  * GET /_agent-native/collab/:docId/users
@@ -77,10 +77,10 @@ export declare const getActiveUsers: import("h3").EventHandlerWithFetch<import("
77
77
  error: string;
78
78
  users?: undefined;
79
79
  } | {
80
+ error?: undefined;
80
81
  users: {
81
82
  clientId: number;
82
83
  lastSeen: number;
83
84
  }[];
84
- error?: undefined;
85
85
  }>>;
86
86
  //# sourceMappingURL=awareness.d.ts.map
@@ -26,8 +26,8 @@ export declare const getCollabState: import("h3").EventHandlerWithFetch<import("
26
26
  * Body: { update: string (base64), requestSource?: string }
27
27
  */
28
28
  export declare const postCollabUpdate: import("h3").EventHandlerWithFetch<import("h3").EventHandlerRequest, Promise<{
29
- error: string;
30
29
  ok?: undefined;
30
+ error: string;
31
31
  } | {
32
32
  error?: undefined;
33
33
  ok: boolean;
@@ -41,9 +41,9 @@ export declare const postCollabUpdate: import("h3").EventHandlerWithFetch<import
41
41
  * Body: { text: string, fieldName?: string, requestSource?: string }
42
42
  */
43
43
  export declare const postCollabText: import("h3").EventHandlerWithFetch<import("h3").EventHandlerRequest, Promise<{
44
- text?: undefined;
45
44
  ok?: undefined;
46
45
  error: string;
46
+ text?: undefined;
47
47
  } | {
48
48
  error?: undefined;
49
49
  ok: boolean;
@@ -0,0 +1,6 @@
1
+ declare const _default: import("../../action.js").ActionDefinition<{
2
+ templateId: string;
3
+ limit?: unknown;
4
+ }, import("../provider-metrics.js").ProviderMetricsResult<import("../provider-metrics.js").EmailActivityEntry[]>>;
5
+ export default _default;
6
+ //# sourceMappingURL=list-email-activity.d.ts.map
@@ -0,0 +1,15 @@
1
+ import { z } from "zod";
2
+ import { defineAction } from "../../action.js";
3
+ import { authorizeTransactionalEmailRead } from "../authorize.js";
4
+ import { fetchEmailActivity } from "../provider-metrics.js";
5
+ export default defineAction({
6
+ description: "List recent provider activity for one registered transactional email in this app. Organization admin only.",
7
+ schema: z.object({
8
+ templateId: z.string().min(1),
9
+ limit: z.coerce.number().int().min(1).max(1000).default(50),
10
+ }),
11
+ http: { method: "GET" },
12
+ authorize: ({ templateId }) => authorizeTransactionalEmailRead([templateId]),
13
+ run: async ({ templateId, limit }) => fetchEmailActivity({ templateId, limit }),
14
+ });
15
+ //# sourceMappingURL=list-email-activity.js.map
@@ -0,0 +1,6 @@
1
+ declare const _default: import("../../action.js").ActionDefinition<{
2
+ templateIds: string[];
3
+ windowDays?: unknown;
4
+ }, import("../provider-metrics.js").ProviderMetricsResult<import("../provider-metrics.js").EmailEngagement[]>>;
5
+ export default _default;
6
+ //# sourceMappingURL=list-email-engagement.d.ts.map
@@ -0,0 +1,15 @@
1
+ import { z } from "zod";
2
+ import { defineAction } from "../../action.js";
3
+ import { authorizeTransactionalEmailRead } from "../authorize.js";
4
+ import { fetchEmailEngagement } from "../provider-metrics.js";
5
+ export default defineAction({
6
+ description: "Read provider engagement metrics for registered transactional emails in this app. Organization admin only.",
7
+ schema: z.object({
8
+ templateIds: z.array(z.string().min(1)).max(100),
9
+ windowDays: z.coerce.number().int().min(1).max(365).default(30),
10
+ }),
11
+ http: { method: "POST" },
12
+ authorize: ({ templateIds }) => authorizeTransactionalEmailRead(templateIds),
13
+ run: async ({ templateIds, windowDays }) => fetchEmailEngagement(templateIds, windowDays),
14
+ });
15
+ //# sourceMappingURL=list-email-engagement.js.map
@@ -0,0 +1,8 @@
1
+ declare const _default: import("../../action.js").ActionDefinition<{
2
+ templateId?: string;
3
+ limit?: unknown;
4
+ }, {
5
+ entries: import("../log.js").EmailLogEntry[];
6
+ }>;
7
+ export default _default;
8
+ //# sourceMappingURL=list-email-log.d.ts.map
@@ -0,0 +1,22 @@
1
+ import { z } from "zod";
2
+ import { defineAction } from "../../action.js";
3
+ import { getAppSlug } from "../../server/app-name.js";
4
+ import { authorizeTransactionalEmailRead } from "../authorize.js";
5
+ import { listEmailLog } from "../log.js";
6
+ export default defineAction({
7
+ description: "List recent transactional email sends from this app, newest first, optionally filtered to one registered email id.",
8
+ schema: z.object({
9
+ templateId: z.string().optional(),
10
+ limit: z.coerce.number().int().min(1).max(500).default(100),
11
+ }),
12
+ http: { method: "GET" },
13
+ authorize: ({ templateId }) => authorizeTransactionalEmailRead(templateId ? [templateId] : []),
14
+ run: async ({ templateId, limit }) => ({
15
+ entries: await listEmailLog({
16
+ app: getAppSlug() ?? "unknown",
17
+ templateId,
18
+ limit,
19
+ }),
20
+ }),
21
+ });
22
+ //# sourceMappingURL=list-email-log.js.map
@@ -0,0 +1,23 @@
1
+ declare const _default: import("../../action.js").ActionDefinition<{
2
+ windowDays?: unknown;
3
+ }, {
4
+ app: string;
5
+ windowDays: number;
6
+ statsAvailable: boolean;
7
+ statsError: string;
8
+ emails: {
9
+ id: string;
10
+ app: string;
11
+ name: string;
12
+ trigger: string;
13
+ recipient: string;
14
+ recipientLabel: string;
15
+ sender: string;
16
+ senderLabel: string;
17
+ sent: number;
18
+ failed: number;
19
+ lastSentAt: number;
20
+ }[];
21
+ }>;
22
+ export default _default;
23
+ //# sourceMappingURL=list-transactional-emails.d.ts.map
@@ -0,0 +1,61 @@
1
+ import { z } from "zod";
2
+ import { defineAction } from "../../action.js";
3
+ import { getAppSlug } from "../../server/app-name.js";
4
+ import { getEmailSendStats } from "../log.js";
5
+ import { listTransactionalEmails } from "../registry.js";
6
+ import { registerCoreSystemEmails } from "../system-emails.js";
7
+ const DEFAULT_WINDOW_DAYS = 30;
8
+ export default defineAction({
9
+ description: "List the transactional emails this app can send, with the trigger, recipient and sender logic for each, plus local send counts and last-sent. Engagement metrics such as open rate are not included here — they live at the email provider.",
10
+ schema: z.object({
11
+ windowDays: z.coerce
12
+ .number()
13
+ .int()
14
+ .min(1)
15
+ .max(365)
16
+ .default(DEFAULT_WINDOW_DAYS)
17
+ .describe("How many days of send history to summarize."),
18
+ }),
19
+ http: { method: "GET" },
20
+ run: async ({ windowDays }) => {
21
+ registerCoreSystemEmails();
22
+ const since = Date.now() - windowDays * 24 * 60 * 60 * 1000;
23
+ const app = getAppSlug() ?? "unknown";
24
+ const definitions = listTransactionalEmails();
25
+ // A failed stats read must not masquerade as "no email ever sent" — the
26
+ // catalog is still worth returning, but the caller has to be able to tell
27
+ // that the numbers are missing rather than zero.
28
+ let statsById = null;
29
+ let statsError = null;
30
+ try {
31
+ const stats = await getEmailSendStats(since, app);
32
+ statsById = new Map(stats.map((row) => [row.templateId, row]));
33
+ }
34
+ catch (error) {
35
+ statsError = error instanceof Error ? error.message : String(error);
36
+ }
37
+ return {
38
+ app,
39
+ windowDays,
40
+ statsAvailable: statsError === null,
41
+ statsError,
42
+ emails: definitions.map((definition) => {
43
+ const stats = statsById?.get(definition.id);
44
+ return {
45
+ id: definition.id,
46
+ app: definition.app,
47
+ name: definition.name,
48
+ trigger: definition.trigger,
49
+ recipient: definition.recipient,
50
+ recipientLabel: definition.recipientLabel,
51
+ sender: definition.sender,
52
+ senderLabel: definition.senderLabel,
53
+ sent: stats?.sent ?? (statsById ? 0 : null),
54
+ failed: stats?.failed ?? (statsById ? 0 : null),
55
+ lastSentAt: stats?.lastSentAt ?? null,
56
+ };
57
+ }),
58
+ };
59
+ },
60
+ });
61
+ //# sourceMappingURL=list-transactional-emails.js.map
@@ -0,0 +1,10 @@
1
+ declare const _default: import("../../action.js").ActionDefinition<{
2
+ id: string;
3
+ }, {
4
+ id: string;
5
+ subject: string;
6
+ html: string;
7
+ text: string;
8
+ }>;
9
+ export default _default;
10
+ //# sourceMappingURL=render-transactional-email-preview.d.ts.map
@@ -0,0 +1,24 @@
1
+ import { z } from "zod";
2
+ import { defineAction } from "../../action.js";
3
+ import { renderTransactionalEmailPreview } from "../registry.js";
4
+ import { registerCoreSystemEmails } from "../system-emails.js";
5
+ export default defineAction({
6
+ description: "Render one of this app's transactional emails with representative dummy data, returning the subject, HTML and plain-text bodies for preview.",
7
+ schema: z.object({
8
+ id: z
9
+ .string()
10
+ .describe("Registered email id, e.g. calendar.booking-confirmed."),
11
+ }),
12
+ http: { method: "GET" },
13
+ run: async ({ id }) => {
14
+ registerCoreSystemEmails();
15
+ const rendered = renderTransactionalEmailPreview(id);
16
+ return {
17
+ id,
18
+ subject: rendered.subject,
19
+ html: rendered.html,
20
+ text: rendered.text,
21
+ };
22
+ },
23
+ });
24
+ //# sourceMappingURL=render-transactional-email-preview.js.map
@@ -0,0 +1,2 @@
1
+ export declare function authorizeTransactionalEmailRead(templateIds?: string[]): Promise<boolean>;
2
+ //# sourceMappingURL=authorize.d.ts.map
@@ -0,0 +1,10 @@
1
+ import { currentRequestUserIsOrgAdmin } from "../server/org-admin.js";
2
+ import { getTransactionalEmail } from "./registry.js";
3
+ import { registerCoreSystemEmails } from "./system-emails.js";
4
+ export async function authorizeTransactionalEmailRead(templateIds = []) {
5
+ if (!(await currentRequestUserIsOrgAdmin()))
6
+ return false;
7
+ registerCoreSystemEmails();
8
+ return templateIds.every((id) => Boolean(getTransactionalEmail(id)));
9
+ }
10
+ //# sourceMappingURL=authorize.js.map
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Durable send log for transactional emails.
3
+ *
4
+ * Written by `sendEmail` on every attempt, successful or not. Read by Dispatch
5
+ * to report per-email send counts and last-sent without depending on the
6
+ * provider's activity retention window.
7
+ */
8
+ export interface RecordEmailSendArgs {
9
+ templateId?: string;
10
+ app?: string;
11
+ recipient: string;
12
+ sender: string;
13
+ subject: string;
14
+ status: "sent" | "failed";
15
+ error?: string;
16
+ provider: string;
17
+ }
18
+ /**
19
+ * Append one send record.
20
+ *
21
+ * Callers treat logging as best-effort: a logging failure must not turn a
22
+ * delivered email into a thrown send. The failure is surfaced on the console
23
+ * rather than swallowed, so a persistently broken log is visible instead of
24
+ * quietly producing an empty activity view.
25
+ */
26
+ export declare function recordEmailSend(args: RecordEmailSendArgs): Promise<void>;
27
+ export interface EmailSendStats {
28
+ templateId: string;
29
+ sent: number;
30
+ failed: number;
31
+ lastSentAt: number | null;
32
+ }
33
+ /**
34
+ * Per-template send counts and last-sent, for sends at or after `since`.
35
+ * Templates with no rows are absent from the result — callers distinguish
36
+ * "never sent" from "sent zero times in window" by that absence.
37
+ */
38
+ export declare function getEmailSendStats(since: number, app: string): Promise<EmailSendStats[]>;
39
+ export interface EmailLogEntry {
40
+ id: string;
41
+ templateId: string | null;
42
+ app: string | null;
43
+ recipient: string;
44
+ sender: string;
45
+ subject: string;
46
+ status: string;
47
+ error: string | null;
48
+ provider: string;
49
+ createdAt: number;
50
+ }
51
+ /** Most recent sends for one app, newest first, optionally filtered to one template. */
52
+ export declare function listEmailLog(options: {
53
+ app: string;
54
+ templateId?: string;
55
+ limit?: number;
56
+ }): Promise<EmailLogEntry[]>;
57
+ //# sourceMappingURL=log.d.ts.map