@aglyn/plugins-marketing 1.0.0-beta.218 → 1.0.0-beta.220

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 (99) hide show
  1. package/README.md +5 -1
  2. package/package.json +16 -16
  3. package/src/lib/analytics-provider.d.ts +177 -0
  4. package/src/lib/analytics-provider.js +370 -0
  5. package/src/lib/analytics-provider.js.map +1 -0
  6. package/src/lib/components/besigner-section-experiments.d.ts +20 -0
  7. package/src/lib/components/besigner-section-experiments.js +128 -0
  8. package/src/lib/components/besigner-section-experiments.js.map +1 -0
  9. package/src/lib/components/campaign-conversions-card.js +1 -1
  10. package/src/lib/components/campaign-conversions-card.js.map +1 -1
  11. package/src/lib/components/campaign-detail-card.js +16 -16
  12. package/src/lib/components/campaign-detail-card.js.map +1 -1
  13. package/src/lib/components/campaign-members-section.js +15 -14
  14. package/src/lib/components/campaign-members-section.js.map +1 -1
  15. package/src/lib/components/campaign-reach-sections.js +4 -1
  16. package/src/lib/components/campaign-reach-sections.js.map +1 -1
  17. package/src/lib/components/campaign-report-card.js +8 -6
  18. package/src/lib/components/campaign-report-card.js.map +1 -1
  19. package/src/lib/components/campaigns-card.js +1 -1
  20. package/src/lib/components/campaigns-card.js.map +1 -1
  21. package/src/lib/components/conversion-attribution.component.d.ts +1 -1
  22. package/src/lib/components/conversion-attribution.component.js +2 -2
  23. package/src/lib/components/conversion-attribution.component.js.map +1 -1
  24. package/src/lib/components/email-detail.js +12 -7
  25. package/src/lib/components/email-detail.js.map +1 -1
  26. package/src/lib/components/email-messages-widget.js +1 -1
  27. package/src/lib/components/email-messages-widget.js.map +1 -1
  28. package/src/lib/components/emails-list-card.js +11 -5
  29. package/src/lib/components/emails-list-card.js.map +1 -1
  30. package/src/lib/components/host-experiments-card.component.js +12 -7
  31. package/src/lib/components/host-experiments-card.component.js.map +1 -1
  32. package/src/lib/components/org-experiments-card.js +1 -1
  33. package/src/lib/components/org-experiments-card.js.map +1 -1
  34. package/src/lib/components/record-attribution-widget.js +1 -1
  35. package/src/lib/components/record-attribution-widget.js.map +1 -1
  36. package/src/lib/components/record-route-context.d.ts +41 -0
  37. package/src/lib/components/record-route-context.js +63 -0
  38. package/src/lib/components/record-route-context.js.map +1 -0
  39. package/src/lib/components/site-runtime.js +2 -2
  40. package/src/lib/components/site-runtime.js.map +1 -1
  41. package/src/lib/components/use-marketing-hub-path.d.ts +18 -5
  42. package/src/lib/components/use-marketing-hub-path.js +36 -6
  43. package/src/lib/components/use-marketing-hub-path.js.map +1 -1
  44. package/src/lib/constants/operator-alerts.js +4 -1
  45. package/src/lib/constants/operator-alerts.js.map +1 -1
  46. package/src/lib/declarations.server.d.ts +3 -1
  47. package/src/lib/declarations.server.js +17 -1
  48. package/src/lib/declarations.server.js.map +1 -1
  49. package/src/lib/model/campaign-conversions.d.ts +301 -0
  50. package/src/lib/model/campaign-conversions.js +252 -0
  51. package/src/lib/model/campaign-conversions.js.map +1 -0
  52. package/src/lib/model/campaign-kind.d.ts +50 -0
  53. package/src/lib/model/campaign-kind.js +52 -0
  54. package/src/lib/model/campaign-kind.js.map +1 -0
  55. package/src/lib/model/campaign-members-query.js +1 -1
  56. package/src/lib/model/campaign-members-query.js.map +1 -1
  57. package/src/lib/model/campaign-revenue.d.ts +327 -0
  58. package/src/lib/model/campaign-revenue.js +332 -0
  59. package/src/lib/model/campaign-revenue.js.map +1 -0
  60. package/src/lib/model/campaign-send-time.d.ts +74 -0
  61. package/src/lib/model/campaign-send-time.js +120 -0
  62. package/src/lib/model/campaign-send-time.js.map +1 -0
  63. package/src/lib/model/experiments.js +1 -1
  64. package/src/lib/model/experiments.js.map +1 -1
  65. package/src/lib/model/index.d.ts +3 -0
  66. package/src/lib/model/index.js +4 -1
  67. package/src/lib/model/index.js.map +1 -1
  68. package/src/lib/model/overlay-record-list.d.ts +33 -0
  69. package/src/lib/model/overlay-record-list.js +53 -0
  70. package/src/lib/model/overlay-record-list.js.map +1 -0
  71. package/src/lib/plugin.js +12 -0
  72. package/src/lib/plugin.js.map +1 -1
  73. package/src/lib/server/campaign-batch-plan.d.ts +73 -0
  74. package/src/lib/server/campaign-batch-plan.js +79 -0
  75. package/src/lib/server/campaign-batch-plan.js.map +1 -0
  76. package/src/lib/server/campaign-manage.js +19 -60
  77. package/src/lib/server/campaign-manage.js.map +1 -1
  78. package/src/lib/server/campaign-send.d.ts +1 -1
  79. package/src/lib/server/campaign-send.js +32 -11
  80. package/src/lib/server/campaign-send.js.map +1 -1
  81. package/src/lib/server/email-events.js +16 -16
  82. package/src/lib/server/email-events.js.map +1 -1
  83. package/src/lib/server/list-send-time-facts.d.ts +60 -0
  84. package/src/lib/server/list-send-time-facts.js +108 -0
  85. package/src/lib/server/list-send-time-facts.js.map +1 -0
  86. package/src/lib/server/overlay-beacon.d.ts +46 -0
  87. package/src/lib/server/overlay-beacon.js +76 -0
  88. package/src/lib/server/overlay-beacon.js.map +1 -0
  89. package/src/lib/server.js +4 -0
  90. package/src/lib/server.js.map +1 -1
  91. package/src/lib/tenant-emails.d.ts +29 -0
  92. package/src/lib/tenant-emails.js +41 -0
  93. package/src/lib/tenant-emails.js.map +1 -0
  94. package/src/lib/testing/stand-in-emails-page-routes.d.ts +27 -0
  95. package/src/lib/testing/stand-in-emails-page-routes.js +42 -0
  96. package/src/lib/testing/stand-in-emails-page-routes.js.map +1 -0
  97. package/src/lib/components/use-emails-hub-path.d.ts +0 -58
  98. package/src/lib/components/use-emails-hub-path.js +0 -109
  99. package/src/lib/components/use-emails-hub-path.js.map +0 -1
@@ -0,0 +1,76 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Aglyn LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */ import firebaseAdmin from "@aglyn/tenant-data-admin/server/firebase-admin";
17
+ import { FieldValue } from "firebase-admin/firestore";
18
+ /**
19
+ * OVERLAY ENGAGEMENT (AGL-200), as the site runtime reports it.
20
+ *
21
+ * The announcement bar and the popup post `{ overlay, overlayId? }` to the
22
+ * platform's site collector, which hands the beacon here after its host and
23
+ * lockdown gates. Two counters move, and neither is a pageview:
24
+ *
25
+ * - the site's day document (`hosts/{hostId}/analytics/{day}`) gains one
26
+ * under `overlays.{event}`, the host-wide totals the dashboard reads —
27
+ * stamped with the platform's expiry so a day created by overlay events
28
+ * alone is still swept (AGL-1844);
29
+ * - with an `overlayId` (AGL-271), that overlay's own document gains one
30
+ * under `stats.impressions`, `stats.clicks` or `stats.dismissals`, so the
31
+ * console shows engagement per bar and popup.
32
+ */ /** The events an overlay reports; anything else is counted nowhere. */ export const OVERLAY_BEACON_EVENTS = [
33
+ 'barImpression',
34
+ 'popupImpression',
35
+ 'popupDismiss',
36
+ 'popupClick',
37
+ 'barClick',
38
+ 'barDismiss'
39
+ ];
40
+ /** The body field that marks a beacon as an overlay's. */ export const OVERLAY_BEACON_FIELD = 'overlay';
41
+ /** The longest overlay id the per-overlay counter accepts. */ const OVERLAY_ID_MAX = 64;
42
+ /** Which of an overlay's lifetime counters an event moves. */ function statKeyOf(event) {
43
+ if (event.endsWith('Impression')) return 'impressions';
44
+ if (event.endsWith('Click')) return 'clicks';
45
+ return 'dismissals';
46
+ }
47
+ /** Counts one overlay beacon, on the Firestore it is handed. */ export async function countOverlayBeacon(request, firestore) {
48
+ var _request_body_OVERLAY_BEACON_FIELD, _request_body_overlayId;
49
+ const event = String((_request_body_OVERLAY_BEACON_FIELD = request.body[OVERLAY_BEACON_FIELD]) != null ? _request_body_OVERLAY_BEACON_FIELD : '');
50
+ if (!OVERLAY_BEACON_EVENTS.includes(event)) return;
51
+ const hostRef = firestore.collection('hosts').doc(request.hostId);
52
+ await hostRef.collection('analytics').doc(request.day).set({
53
+ overlays: {
54
+ [event]: FieldValue.increment(1)
55
+ },
56
+ expiresAt: request.dayExpiresAt
57
+ }, {
58
+ merge: true
59
+ });
60
+ const overlayId = String((_request_body_overlayId = request.body['overlayId']) != null ? _request_body_overlayId : '');
61
+ if (!overlayId || overlayId.length > OVERLAY_ID_MAX) return;
62
+ // update(), not set(): a beacon from a stale cached page must not
63
+ // resurrect a deleted overlay as a stats-only stray document.
64
+ await hostRef.collection('overlays').doc(overlayId).update({
65
+ [`stats.${statKeyOf(event)}`]: FieldValue.increment(1)
66
+ }).catch(()=>undefined);
67
+ }
68
+ /**
69
+ * Counts one overlay beacon on the platform's Firestore: what the server
70
+ * declarations hand the collector, with this module and the Admin SDK loaded
71
+ * on the first beacon.
72
+ */ export async function countOverlayBeaconOnPlatform(request) {
73
+ await countOverlayBeacon(request, firebaseAdmin.app().firestore());
74
+ }
75
+
76
+ //# sourceMappingURL=overlay-beacon.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../libs/plugins/marketing/src/lib/server/overlay-beacon.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { PluginSiteBeaconRequest } from '@aglyn/aglyn/plugin-manager/plugin-site-beacons'\nimport firebaseAdmin from '@aglyn/tenant-data-admin/server/firebase-admin'\nimport { FieldValue } from 'firebase-admin/firestore'\n\ntype Firestore = FirebaseFirestore.Firestore\n\n/**\n * OVERLAY ENGAGEMENT (AGL-200), as the site runtime reports it.\n *\n * The announcement bar and the popup post `{ overlay, overlayId? }` to the\n * platform's site collector, which hands the beacon here after its host and\n * lockdown gates. Two counters move, and neither is a pageview:\n *\n * - the site's day document (`hosts/{hostId}/analytics/{day}`) gains one\n * under `overlays.{event}`, the host-wide totals the dashboard reads —\n * stamped with the platform's expiry so a day created by overlay events\n * alone is still swept (AGL-1844);\n * - with an `overlayId` (AGL-271), that overlay's own document gains one\n * under `stats.impressions`, `stats.clicks` or `stats.dismissals`, so the\n * console shows engagement per bar and popup.\n */\n\n/** The events an overlay reports; anything else is counted nowhere. */\nexport const OVERLAY_BEACON_EVENTS: readonly string[] = [\n 'barImpression',\n 'popupImpression',\n 'popupDismiss',\n 'popupClick',\n 'barClick',\n 'barDismiss',\n]\n\n/** The body field that marks a beacon as an overlay's. */\nexport const OVERLAY_BEACON_FIELD = 'overlay'\n\n/** The longest overlay id the per-overlay counter accepts. */\nconst OVERLAY_ID_MAX = 64\n\n/** Which of an overlay's lifetime counters an event moves. */\nfunction statKeyOf(event: string): 'impressions' | 'clicks' | 'dismissals' {\n if (event.endsWith('Impression')) return 'impressions'\n if (event.endsWith('Click')) return 'clicks'\n return 'dismissals'\n}\n\n/** Counts one overlay beacon, on the Firestore it is handed. */\nexport async function countOverlayBeacon(\n request: PluginSiteBeaconRequest,\n firestore: Firestore,\n): Promise<void> {\n const event = String(request.body[OVERLAY_BEACON_FIELD] ?? '')\n if (!OVERLAY_BEACON_EVENTS.includes(event)) return\n const hostRef = firestore.collection('hosts').doc(request.hostId)\n await hostRef\n .collection('analytics')\n .doc(request.day)\n .set(\n {\n overlays: { [event]: FieldValue.increment(1) },\n expiresAt: request.dayExpiresAt,\n },\n { merge: true },\n )\n const overlayId = String(request.body['overlayId'] ?? '')\n if (!overlayId || overlayId.length > OVERLAY_ID_MAX) return\n // update(), not set(): a beacon from a stale cached page must not\n // resurrect a deleted overlay as a stats-only stray document.\n await hostRef\n .collection('overlays')\n .doc(overlayId)\n .update({ [`stats.${statKeyOf(event)}`]: FieldValue.increment(1) })\n .catch(() => undefined)\n}\n\n/**\n * Counts one overlay beacon on the platform's Firestore: what the server\n * declarations hand the collector, with this module and the Admin SDK loaded\n * on the first beacon.\n */\nexport async function countOverlayBeaconOnPlatform(\n request: PluginSiteBeaconRequest,\n): Promise<void> {\n await countOverlayBeacon(request, firebaseAdmin.app().firestore())\n}\n"],"names":["firebaseAdmin","FieldValue","OVERLAY_BEACON_EVENTS","OVERLAY_BEACON_FIELD","OVERLAY_ID_MAX","statKeyOf","event","endsWith","countOverlayBeacon","request","firestore","String","body","includes","hostRef","collection","doc","hostId","day","set","overlays","increment","expiresAt","dayExpiresAt","merge","overlayId","length","update","catch","undefined","countOverlayBeaconOnPlatform","app"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAGD,OAAOA,mBAAmB,iDAAgD;AAC1E,SAASC,UAAU,QAAQ,2BAA0B;AAIrD;;;;;;;;;;;;;;CAcC,GAED,qEAAqE,GACrE,OAAO,MAAMC,wBAA2C;IACtD;IACA;IACA;IACA;IACA;IACA;CACD,CAAA;AAED,wDAAwD,GACxD,OAAO,MAAMC,uBAAuB,UAAS;AAE7C,4DAA4D,GAC5D,MAAMC,iBAAiB;AAEvB,4DAA4D,GAC5D,SAASC,UAAUC,KAAa;IAC9B,IAAIA,MAAMC,QAAQ,CAAC,eAAe,OAAO;IACzC,IAAID,MAAMC,QAAQ,CAAC,UAAU,OAAO;IACpC,OAAO;AACT;AAEA,8DAA8D,GAC9D,OAAO,eAAeC,mBACpBC,OAAgC,EAChCC,SAAoB;QAECD,oCAaIA;IAbzB,MAAMH,QAAQK,QAAOF,qCAAAA,QAAQG,IAAI,CAACT,qBAAqB,YAAlCM,qCAAsC;IAC3D,IAAI,CAACP,sBAAsBW,QAAQ,CAACP,QAAQ;IAC5C,MAAMQ,UAAUJ,UAAUK,UAAU,CAAC,SAASC,GAAG,CAACP,QAAQQ,MAAM;IAChE,MAAMH,QACHC,UAAU,CAAC,aACXC,GAAG,CAACP,QAAQS,GAAG,EACfC,GAAG,CACF;QACEC,UAAU;YAAE,CAACd,MAAM,EAAEL,WAAWoB,SAAS,CAAC;QAAG;QAC7CC,WAAWb,QAAQc,YAAY;IACjC,GACA;QAAEC,OAAO;IAAK;IAElB,MAAMC,YAAYd,QAAOF,0BAAAA,QAAQG,IAAI,CAAC,YAAY,YAAzBH,0BAA6B;IACtD,IAAI,CAACgB,aAAaA,UAAUC,MAAM,GAAGtB,gBAAgB;IACrD,kEAAkE;IAClE,8DAA8D;IAC9D,MAAMU,QACHC,UAAU,CAAC,YACXC,GAAG,CAACS,WACJE,MAAM,CAAC;QAAE,CAAC,CAAC,MAAM,EAAEtB,UAAUC,QAAQ,CAAC,EAAEL,WAAWoB,SAAS,CAAC;IAAG,GAChEO,KAAK,CAAC,IAAMC;AACjB;AAEA;;;;CAIC,GACD,OAAO,eAAeC,6BACpBrB,OAAgC;IAEhC,MAAMD,mBAAmBC,SAAST,cAAc+B,GAAG,GAAGrB,SAAS;AACjE"}
package/src/lib/server.js CHANGED
@@ -18,6 +18,7 @@ import { evaluateAutoWinner } from "./model/index.js";
18
18
  import { registerPluginApiRoute, registerSitePageEnricher } from "@aglyn/aglyn/server";
19
19
  import { emailEventsHandler } from "./server/email-events.js";
20
20
  import { registerMarketingFigureReaders } from "./server/marketing-figures.js";
21
+ import { registerListSendTimeFacts } from "./server/list-send-time-facts.js";
21
22
  import { marketingSitePageEnricher } from "./server/site-page-enricher.js";
22
23
  import { firebaseAdmin, getOrgForHost } from "@aglyn/tenant-data-admin";
23
24
  import { FieldValue } from "firebase-admin/firestore";
@@ -129,6 +130,9 @@ import { campaignRecipientsHandler } from "./server/campaign-recipients.js";
129
130
  // Campaign and A/B testing results as figure tables (AGL-2915), for the AI
130
131
  // plugin's insights to read by id; the console runs insight jobs.
131
132
  registerMarketingFigureReaders(()=>firebaseAdmin.app().firestore());
133
+ // When a list reads its mail, from its sends on the site (AGL-3080): the
134
+ // AI plugin's campaign drafts suggest a send time through it.
135
+ registerListSendTimeFacts(()=>firebaseAdmin.app().firestore());
132
136
  registerPluginApiRoute('campaigns/send', campaignSendHandler);
133
137
  // Taking a campaign or an abandoned draft away, which is the one class of
134
138
  // change the send route may not carry: both write to the SEND collection,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../libs/plugins/marketing/src/lib/server.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { checkEntitlement } from '@aglyn/aglyn/server'\nimport { evaluateAutoWinner, type HostExperiment } from './model'\nimport {\n registerPluginApiRoute,\n registerSitePageEnricher,\n type PluginApiHandler,\n} from '@aglyn/aglyn/server'\nimport { emailEventsHandler } from './server/email-events'\nimport { registerMarketingFigureReaders } from './server/marketing-figures'\nimport { marketingSitePageEnricher } from './server/site-page-enricher'\nimport { firebaseAdmin, getOrgForHost } from '@aglyn/tenant-data-admin'\nimport { FieldValue } from 'firebase-admin/firestore'\nimport { campaignProcessScheduledHandler } from './server/campaign-process-scheduled'\nimport { listsMaterializeHandler } from './server/lists-materialize'\nimport {\n campaignManageHandler,\n campaignManageSubject,\n registerCampaignDraftWriter,\n} from './server/campaign-manage'\nimport { campaignSendHandler } from './server/campaign-send'\nimport { campaignRecipientsHandler } from './server/campaign-recipients'\n\n/**\n * Experiment beacon (AGL-252): counts an exposure or conversion on\n * `hosts/{hostId}/experiments/{id}/stats/{variantId}`. Sampled counters —\n * fire-and-forget from the page, abTesting-gated, no visitor identity\n * stored server-side (assignment is deterministic client-side).\n */\nconst trackHandler: PluginApiHandler = async (req, res) => {\n if (req.method !== 'POST') {\n return res.status(405).json({ error: 'Method not allowed' })\n }\n const hostId = String(req.body?.hostId ?? '')\n const experimentId = String(req.body?.experimentId ?? '')\n const variantId = String(req.body?.variantId ?? '')\n const kind = String(req.body?.kind ?? '')\n if (\n !hostId ||\n !experimentId ||\n !variantId ||\n !['exposure', 'conversion'].includes(kind)\n ) {\n return res.status(400).json({ error: 'Bad beacon' })\n }\n try {\n const org = (await getOrgForHost(hostId))?.org\n if (!checkEntitlement(org as any, 'abTesting')) {\n return res.status(200).json({ ok: true })\n }\n const experimentRef = firebaseAdmin\n .app()\n .firestore()\n .collection('hosts')\n .doc(hostId)\n .collection('experiments')\n .doc(experimentId)\n const experiment = await experimentRef.get()\n if (!experiment.exists || experiment.get('status') !== 'running') {\n return res.status(200).json({ ok: true })\n }\n // Ended experiments (AGL-273) stop counting: stale cached pages may\n // still beacon briefly, and post-end stats would skew the decision.\n const endAtMs = Number(experiment.get('endAtMs') ?? 0)\n if (endAtMs && Date.now() > endAtMs) {\n return res.status(200).json({ ok: true })\n }\n await experimentRef\n .collection('stats')\n .doc(variantId)\n .set(\n {\n [kind === 'exposure' ? 'exposures' : 'conversions']:\n FieldValue.increment(1),\n updatedAt: FieldValue.serverTimestamp(),\n },\n { merge: true },\n )\n // Auto-winner (AGL-273): conversions re-evaluate the opt-in decision\n // rule; a decided experiment finishes itself and serves the winner.\n const data = experiment.data() as HostExperiment\n if (kind === 'conversion' && data.autoWinner) {\n const statsSnapshot = await experimentRef.collection('stats').get()\n const statsByVariant: Record<\n string,\n { exposures?: number; conversions?: number }\n > = {}\n for (const doc of statsSnapshot.docs) {\n statsByVariant[doc.id] = {\n exposures: Number(doc.get('exposures') ?? 0),\n conversions: Number(doc.get('conversions') ?? 0),\n }\n }\n const decision = evaluateAutoWinner(data, statsByVariant)\n if (decision) {\n await experimentRef.update({\n status: 'done',\n winnerVariantId: decision.variantId,\n autoCompleted: true,\n completedAt: FieldValue.serverTimestamp(),\n })\n }\n }\n return res.status(200).json({ ok: true })\n } catch (error) {\n console.error(error)\n return res.status(200).json({ ok: true }) // beacons never error the page\n }\n}\n\n/** Registers the marketing plugin's public (site-facing) API routes (AGL-396). */\nexport function registerMarketingApi(): void {\n registerPluginApiRoute('experiments/track', trackHandler)\n // Site-page contributions (AGL-418): overlays, automations, experiments.\n registerSitePageEnricher(marketingSitePageEnricher)\n}\n\n/** Registers the marketing plugin's console-side API routes (AGL-396). */\nexport function registerMarketingConsoleApi(): void {\n // The campaign draft writer another plugin reaches through the core's\n // resource-drafts seam (AGL-2912). Registered here alone: the AI jobs that\n // write through it run only on the console, inline and on the beat\n // (AGL-3026).\n registerCampaignDraftWriter()\n // Campaign and A/B testing results as figure tables (AGL-2915), for the AI\n // plugin's insights to read by id; the console runs insight jobs.\n registerMarketingFigureReaders(() => firebaseAdmin.app().firestore())\n registerPluginApiRoute('campaigns/send', campaignSendHandler)\n // Taking a campaign or an abandoned draft away, which is the one class of\n // change the send route may not carry: both write to the SEND collection,\n // which no client may touch, and neither of them mails anything. The\n // organization hub reaches it naming its org and no site, so the route\n // names that org as its subject for the release gate.\n registerPluginApiRoute('campaigns/manage', campaignManageHandler, {\n subject: campaignManageSubject,\n })\n // The other direction through the per-recipient delivery log: not \"what did\n // we send this person\" but \"who did this design reach, and which of them\n // opened it\". Server-side because the log is a platform-level collection no\n // security rule can scope to one site's campaigns.\n registerPluginApiRoute('campaigns/recipients', campaignRecipientsHandler)\n // Relocated console route (AGL-418): the Resend/Svix webhook keeps its\n // /api/email/events URL via the dispatcher; ownership is recorded at\n // registration so the org gate attributes it to marketing, not email.\n registerPluginApiRoute('email/events', emailEventsHandler)\n registerPluginApiRoute(\n 'campaigns/process-scheduled',\n campaignProcessScheduledHandler,\n )\n // The dynamic-list sweep rides the same `*/15` fast-cron as the campaign\n // processor rather than provisioning a scheduler job of its own.\n registerPluginApiRoute('lists/materialize', listsMaterializeHandler)\n}\n"],"names":["checkEntitlement","evaluateAutoWinner","registerPluginApiRoute","registerSitePageEnricher","emailEventsHandler","registerMarketingFigureReaders","marketingSitePageEnricher","firebaseAdmin","getOrgForHost","FieldValue","campaignProcessScheduledHandler","listsMaterializeHandler","campaignManageHandler","campaignManageSubject","registerCampaignDraftWriter","campaignSendHandler","campaignRecipientsHandler","trackHandler","req","res","method","status","json","error","hostId","String","body","experimentId","variantId","kind","includes","experiment","org","ok","experimentRef","app","firestore","collection","doc","get","exists","endAtMs","Number","Date","now","set","increment","updatedAt","serverTimestamp","merge","data","autoWinner","statsSnapshot","statsByVariant","docs","id","exposures","conversions","decision","update","winnerVariantId","autoCompleted","completedAt","console","registerMarketingApi","registerMarketingConsoleApi","subject"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,gBAAgB,QAAQ,sBAAqB;AACtD,SAASC,kBAAkB,QAA6B,mBAAS;AACjE,SACEC,sBAAsB,EACtBC,wBAAwB,QAEnB,sBAAqB;AAC5B,SAASC,kBAAkB,QAAQ,2BAAuB;AAC1D,SAASC,8BAA8B,QAAQ,gCAA4B;AAC3E,SAASC,yBAAyB,QAAQ,iCAA6B;AACvE,SAASC,aAAa,EAAEC,aAAa,QAAQ,2BAA0B;AACvE,SAASC,UAAU,QAAQ,2BAA0B;AACrD,SAASC,+BAA+B,QAAQ,yCAAqC;AACrF,SAASC,uBAAuB,QAAQ,gCAA4B;AACpE,SACEC,qBAAqB,EACrBC,qBAAqB,EACrBC,2BAA2B,QACtB,8BAA0B;AACjC,SAASC,mBAAmB,QAAQ,4BAAwB;AAC5D,SAASC,yBAAyB,QAAQ,kCAA8B;AAExE;;;;;CAKC,GACD,MAAMC,eAAiC,OAAOC,KAAKC;;QAI3BD,WACMA,YACHA,YACLA;IANpB,IAAIA,IAAIE,MAAM,KAAK,QAAQ;QACzB,OAAOD,IAAIE,MAAM,CAAC,KAAKC,IAAI,CAAC;YAAEC,OAAO;QAAqB;IAC5D;IACA,MAAMC,SAASC,gBAAOP,YAAAA,IAAIQ,IAAI,qBAARR,U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D;IACA,2EAA2E;IAC3E,kEAAkE;IAClET,+BAA+B,IAAME,cAAc4B,GAAG,GAAGC,SAAS;IAClElC,uBAAuB,kBAAkBa;IACzC,0EAA0E;IAC1E,0EAA0E;IAC1E,qEAAqE;IACrE,uEAAuE;IACvE,sDAAsD;IACtDb,uBAAuB,oBAAoBU,uBAAuB;QAChEsD,SAASrD;IACX;IACA,4EAA4E;IAC5E,yEAAyE;IACzE,4EAA4E;IAC5E,mDAAmD;IACnDX,uBAAuB,wBAAwBc;IAC/C,uEAAuE;IACvE,qEAAqE;IACrE,sEAAsE;IACtEd,uBAAuB,gBAAgBE;IACvCF,uBACE,+BACAQ;IAEF,yEAAyE;IACzE,iEAAiE;IACjER,uBAAuB,qBAAqBS;AAC9C"}
1
+ {"version":3,"sources":["../../../../../../libs/plugins/marketing/src/lib/server.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { checkEntitlement } from '@aglyn/aglyn/server'\nimport { evaluateAutoWinner, type HostExperiment } from './model'\nimport {\n registerPluginApiRoute,\n registerSitePageEnricher,\n type PluginApiHandler,\n} from '@aglyn/aglyn/server'\nimport { emailEventsHandler } from './server/email-events'\nimport { registerMarketingFigureReaders } from './server/marketing-figures'\nimport { registerListSendTimeFacts } from './server/list-send-time-facts'\nimport { marketingSitePageEnricher } from './server/site-page-enricher'\nimport { firebaseAdmin, getOrgForHost } from '@aglyn/tenant-data-admin'\nimport { FieldValue } from 'firebase-admin/firestore'\nimport { campaignProcessScheduledHandler } from './server/campaign-process-scheduled'\nimport { listsMaterializeHandler } from './server/lists-materialize'\nimport {\n campaignManageHandler,\n campaignManageSubject,\n registerCampaignDraftWriter,\n} from './server/campaign-manage'\nimport { campaignSendHandler } from './server/campaign-send'\nimport { campaignRecipientsHandler } from './server/campaign-recipients'\n\n/**\n * Experiment beacon (AGL-252): counts an exposure or conversion on\n * `hosts/{hostId}/experiments/{id}/stats/{variantId}`. Sampled counters —\n * fire-and-forget from the page, abTesting-gated, no visitor identity\n * stored server-side (assignment is deterministic client-side).\n */\nconst trackHandler: PluginApiHandler = async (req, res) => {\n if (req.method !== 'POST') {\n return res.status(405).json({ error: 'Method not allowed' })\n }\n const hostId = String(req.body?.hostId ?? '')\n const experimentId = String(req.body?.experimentId ?? '')\n const variantId = String(req.body?.variantId ?? '')\n const kind = String(req.body?.kind ?? '')\n if (\n !hostId ||\n !experimentId ||\n !variantId ||\n !['exposure', 'conversion'].includes(kind)\n ) {\n return res.status(400).json({ error: 'Bad beacon' })\n }\n try {\n const org = (await getOrgForHost(hostId))?.org\n if (!checkEntitlement(org as any, 'abTesting')) {\n return res.status(200).json({ ok: true })\n }\n const experimentRef = firebaseAdmin\n .app()\n .firestore()\n .collection('hosts')\n .doc(hostId)\n .collection('experiments')\n .doc(experimentId)\n const experiment = await experimentRef.get()\n if (!experiment.exists || experiment.get('status') !== 'running') {\n return res.status(200).json({ ok: true })\n }\n // Ended experiments (AGL-273) stop counting: stale cached pages may\n // still beacon briefly, and post-end stats would skew the decision.\n const endAtMs = Number(experiment.get('endAtMs') ?? 0)\n if (endAtMs && Date.now() > endAtMs) {\n return res.status(200).json({ ok: true })\n }\n await experimentRef\n .collection('stats')\n .doc(variantId)\n .set(\n {\n [kind === 'exposure' ? 'exposures' : 'conversions']:\n FieldValue.increment(1),\n updatedAt: FieldValue.serverTimestamp(),\n },\n { merge: true },\n )\n // Auto-winner (AGL-273): conversions re-evaluate the opt-in decision\n // rule; a decided experiment finishes itself and serves the winner.\n const data = experiment.data() as HostExperiment\n if (kind === 'conversion' && data.autoWinner) {\n const statsSnapshot = await experimentRef.collection('stats').get()\n const statsByVariant: Record<\n string,\n { exposures?: number; conversions?: number }\n > = {}\n for (const doc of statsSnapshot.docs) {\n statsByVariant[doc.id] = {\n exposures: Number(doc.get('exposures') ?? 0),\n conversions: Number(doc.get('conversions') ?? 0),\n }\n }\n const decision = evaluateAutoWinner(data, statsByVariant)\n if (decision) {\n await experimentRef.update({\n status: 'done',\n winnerVariantId: decision.variantId,\n autoCompleted: true,\n completedAt: FieldValue.serverTimestamp(),\n })\n }\n }\n return res.status(200).json({ ok: true })\n } catch (error) {\n console.error(error)\n return res.status(200).json({ ok: true }) // beacons never error the page\n }\n}\n\n/** Registers the marketing plugin's public (site-facing) API routes (AGL-396). */\nexport function registerMarketingApi(): void {\n registerPluginApiRoute('experiments/track', trackHandler)\n // Site-page contributions (AGL-418): overlays, automations, experiments.\n registerSitePageEnricher(marketingSitePageEnricher)\n}\n\n/** Registers the marketing plugin's console-side API routes (AGL-396). */\nexport function registerMarketingConsoleApi(): void {\n // The campaign draft writer another plugin reaches through the core's\n // resource-drafts seam (AGL-2912). Registered here alone: the AI jobs that\n // write through it run only on the console, inline and on the beat\n // (AGL-3026).\n registerCampaignDraftWriter()\n // Campaign and A/B testing results as figure tables (AGL-2915), for the AI\n // plugin's insights to read by id; the console runs insight jobs.\n registerMarketingFigureReaders(() => firebaseAdmin.app().firestore())\n // When a list reads its mail, from its sends on the site (AGL-3080): the\n // AI plugin's campaign drafts suggest a send time through it.\n registerListSendTimeFacts(() => firebaseAdmin.app().firestore())\n registerPluginApiRoute('campaigns/send', campaignSendHandler)\n // Taking a campaign or an abandoned draft away, which is the one class of\n // change the send route may not carry: both write to the SEND collection,\n // which no client may touch, and neither of them mails anything. The\n // organization hub reaches it naming its org and no site, so the route\n // names that org as its subject for the release gate.\n registerPluginApiRoute('campaigns/manage', campaignManageHandler, {\n subject: campaignManageSubject,\n })\n // The other direction through the per-recipient delivery log: not \"what did\n // we send this person\" but \"who did this design reach, and which of them\n // opened it\". Server-side because the log is a platform-level collection no\n // security rule can scope to one site's campaigns.\n registerPluginApiRoute('campaigns/recipients', campaignRecipientsHandler)\n // Relocated console route (AGL-418): the Resend/Svix webhook keeps its\n // /api/email/events URL via the dispatcher; ownership is recorded at\n // registration so the org gate attributes it to marketing, not email.\n registerPluginApiRoute('email/events', emailEventsHandler)\n registerPluginApiRoute(\n 'campaigns/process-scheduled',\n campaignProcessScheduledHandler,\n )\n // The dynamic-list sweep rides the same `*/15` fast-cron as the campaign\n // processor rather than provisioning a scheduler job of its own.\n registerPluginApiRoute('lists/materialize', listsMaterializeHandler)\n}\n"],"names":["checkEntitlement","evaluateAutoWinner","registerPluginApiRoute","registerSitePageEnricher","emailEventsHandler","registerMarketingFigureReaders","registerListSendTimeFacts","marketingSitePageEnricher","firebaseAdmin","getOrgForHost","FieldValue","campaignProcessScheduledHandler","listsMaterializeHandler","campaignManageHandler","campaignManageSubject","registerCampaignDraftWriter","campaignSendHandler","campaignRecipientsHandler","trackHandler","req","res","method","status","json","error","hostId","String","body","experimentId","variantId","kind","includes","experiment","org","ok","experimentRef","app","firestore","collection","doc","get","exists","endAtMs","Number","Date","now","set","increment","updatedAt","serverTimestamp","merge","data","autoWinner","statsSnapshot","statsByVariant","docs","id","exposures","conversions","decision","update","winnerVariantId","autoCompleted","completedAt","console","registerMarketingApi","registerMarketingConsoleApi","subject"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,gBAAgB,QAAQ,sBAAqB;AACtD,SAASC,kBAAkB,QAA6B,mBAAS;AACjE,SACEC,sBAAsB,EACtBC,wBAAwB,QAEnB,sBAAqB;AAC5B,SAASC,kBAAkB,QAAQ,2BAAuB;AAC1D,SAASC,8BAA8B,QAAQ,gCAA4B;AAC3E,SAASC,yBAAyB,QAAQ,mCAA+B;AACzE,SAASC,yBAAyB,QAAQ,iCAA6B;AACvE,SAASC,aAAa,EAAEC,aAAa,QAAQ,2BAA0B;AACvE,SAASC,UAAU,QAAQ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nCiC,eAAe;oBACfC,aAAarD,WAAWuC,eAAe;gBACzC;YACF;QACF;QACA,OAAO7B,IAAIE,MAAM,CAAC,KAAKC,IAAI,CAAC;YAAEW,IAAI;QAAK;IACzC,EAAE,OAAOV,OAAO;QACdwC,QAAQxC,KAAK,CAACA;QACd,OAAOJ,IAAIE,MAAM,CAAC,KAAKC,IAAI,CAAC;YAAEW,IAAI;QAAK,GAAG,+BAA+B;;IAC3E;AACF;AAEA,gFAAgF,GAChF,OAAO,SAAS+B;IACd/D,uBAAuB,qBAAqBgB;IAC5C,yEAAyE;IACzEf,yBAAyBI;AAC3B;AAEA,wEAAwE,GACxE,OAAO,SAAS2D;IACd,sEAAsE;IACtE,2EAA2E;IAC3E,mEAAmE;IACnE,cAAc;IACdnD;IACA,2EAA2E;IAC3E,kEAAkE;IAClEV,+BAA+B,IAAMG,cAAc4B,GAAG,GAAGC,SAAS;IAClE,yEAAyE;IACzE,8DAA8D;IAC9D/B,0BAA0B,IAAME,cAAc4B,GAAG,GAAGC,SAAS;IAC7DnC,uBAAuB,kBAAkBc;IACzC,0EAA0E;IAC1E,0EAA0E;IAC1E,qEAAqE;IACrE,uEAAuE;IACvE,sDAAsD;IACtDd,uBAAuB,oBAAoBW,uBAAuB;QAChEsD,SAASrD;IACX;IACA,4EAA4E;IAC5E,yEAAyE;IACzE,4EAA4E;IAC5E,mDAAmD;IACnDZ,uBAAuB,wBAAwBe;IAC/C,uEAAuE;IACvE,qEAAqE;IACrE,sEAAsE;IACtEf,uBAAuB,gBAAgBE;IACvCF,uBACE,+BACAS;IAEF,yEAAyE;IACzE,iEAAiE;IACjET,uBAAuB,qBAAqBU;AAC9C"}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Aglyn LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import type { TenantEmailEntry } from '@aglyn/shared-util-email';
18
+ /**
19
+ * The emails a site sends its own customers through Marketing (AGL-769/770).
20
+ *
21
+ * Declared here, by the plugin that sends them, and compiled into the
22
+ * platform's tenant email catalog (`TENANT_EMAILS` in
23
+ * `@aglyn/shared-util-email`) by `tools/scripts/generate-plugin-manifests.mjs`
24
+ * (AGL-3080): the catalog's readers include the send path, which loads no
25
+ * plugin code, so a runtime registry it had not filled would quietly send
26
+ * the text card in place of the site's designed email. Regenerate after
27
+ * changing an entry; `--check` refuses a stale catalog.
28
+ */
29
+ export declare function marketingTenantEmails(): readonly TenantEmailEntry[];
@@ -0,0 +1,41 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Aglyn LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */ /**
17
+ * The emails a site sends its own customers through Marketing (AGL-769/770).
18
+ *
19
+ * Declared here, by the plugin that sends them, and compiled into the
20
+ * platform's tenant email catalog (`TENANT_EMAILS` in
21
+ * `@aglyn/shared-util-email`) by `tools/scripts/generate-plugin-manifests.mjs`
22
+ * (AGL-3080): the catalog's readers include the send path, which loads no
23
+ * plugin code, so a runtime registry it had not filled would quietly send
24
+ * the text card in place of the site's designed email. Regenerate after
25
+ * changing an entry; `--check` refuses a stale catalog.
26
+ */ export function marketingTenantEmails() {
27
+ return [
28
+ {
29
+ key: 'campaign',
30
+ name: 'Campaign broadcast',
31
+ description: "A campaign sent to the site's subscriber list.",
32
+ pluginId: 'marketing',
33
+ plugin: 'Marketing',
34
+ control: 'external',
35
+ authoredIn: 'Marketing → Campaigns',
36
+ footerReason: 'You’re receiving this email from {{host.businessName}}.'
37
+ }
38
+ ];
39
+ }
40
+
41
+ //# sourceMappingURL=tenant-emails.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../libs/plugins/marketing/src/lib/tenant-emails.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { TenantEmailEntry } from '@aglyn/shared-util-email'\n\n/**\n * The emails a site sends its own customers through Marketing (AGL-769/770).\n *\n * Declared here, by the plugin that sends them, and compiled into the\n * platform's tenant email catalog (`TENANT_EMAILS` in\n * `@aglyn/shared-util-email`) by `tools/scripts/generate-plugin-manifests.mjs`\n * (AGL-3080): the catalog's readers include the send path, which loads no\n * plugin code, so a runtime registry it had not filled would quietly send\n * the text card in place of the site's designed email. Regenerate after\n * changing an entry; `--check` refuses a stale catalog.\n */\nexport function marketingTenantEmails(): readonly TenantEmailEntry[] {\n return [\n {\n key: 'campaign',\n name: 'Campaign broadcast',\n description: \"A campaign sent to the site's subscriber list.\",\n pluginId: 'marketing',\n plugin: 'Marketing',\n control: 'external',\n authoredIn: 'Marketing → Campaigns',\n footerReason:\n 'You’re receiving this email from {{host.businessName}}.',\n },\n ]\n}\n"],"names":["marketingTenantEmails","key","name","description","pluginId","plugin","control","authoredIn","footerReason"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAID;;;;;;;;;;CAUC,GACD,OAAO,SAASA;IACd,OAAO;QACL;YACEC,KAAK;YACLC,MAAM;YACNC,aAAa;YACbC,UAAU;YACVC,QAAQ;YACRC,SAAS;YACTC,YAAY;YACZC,cACE;QACJ;KACD;AACH"}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Aglyn LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ /**
18
+ * The Emails page's record routes, as the email plugin publishes them
19
+ * (AGL-3080), stood in for this plugin's specs — a campaign links each
20
+ * message's report and the template it was built from, and this plugin may
21
+ * not load the email plugin that registers the real routes. What that plugin
22
+ * publishes is held in its own `email-record-routes.spec.ts`.
23
+ *
24
+ * Registered under the owner's id, `email`, so a spec asking what happens
25
+ * where it is not loaded unregisters that plugin's services.
26
+ */
27
+ export declare function standInEmailsPageRoutes(): void;
@@ -0,0 +1,42 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Aglyn LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */ import { registerPluginRecordRoute } from "@aglyn/aglyn/plugin-manager/plugin-record-routes";
17
+ /**
18
+ * The Emails page's record routes, as the email plugin publishes them
19
+ * (AGL-3080), stood in for this plugin's specs — a campaign links each
20
+ * message's report and the template it was built from, and this plugin may
21
+ * not load the email plugin that registers the real routes. What that plugin
22
+ * publishes is held in its own `email-record-routes.spec.ts`.
23
+ *
24
+ * Registered under the owner's id, `email`, so a spec asking what happens
25
+ * where it is not loaded unregisters that plugin's services.
26
+ */ export function standInEmailsPageRoutes() {
27
+ const hub = (orgSlug, host)=>host ? `/${orgSlug}/hosts/${host}/emails` : `/${orgSlug}/emails`;
28
+ registerPluginRecordRoute('emailMessage', {
29
+ list: ({ orgSlug, host })=>`${hub(orgSlug, host)}/messages`,
30
+ record: ({ orgSlug, host }, id)=>`${hub(orgSlug, host)}/messages/${encodeURIComponent(id)}`
31
+ }, {
32
+ pluginId: 'email'
33
+ });
34
+ registerPluginRecordRoute('emailTemplate', {
35
+ list: ({ orgSlug, host })=>host ? `${hub(orgSlug, host)}/templates` : null,
36
+ record: ({ orgSlug, host }, id)=>host ? `${hub(orgSlug, host)}/templates/${encodeURIComponent(id)}` : null
37
+ }, {
38
+ pluginId: 'email'
39
+ });
40
+ }
41
+
42
+ //# sourceMappingURL=stand-in-emails-page-routes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../libs/plugins/marketing/src/lib/testing/stand-in-emails-page-routes.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { registerPluginRecordRoute } from '@aglyn/aglyn/plugin-manager/plugin-record-routes'\n\n/**\n * The Emails page's record routes, as the email plugin publishes them\n * (AGL-3080), stood in for this plugin's specs — a campaign links each\n * message's report and the template it was built from, and this plugin may\n * not load the email plugin that registers the real routes. What that plugin\n * publishes is held in its own `email-record-routes.spec.ts`.\n *\n * Registered under the owner's id, `email`, so a spec asking what happens\n * where it is not loaded unregisters that plugin's services.\n */\nexport function standInEmailsPageRoutes(): void {\n const hub = (orgSlug: string, host: string | null) =>\n host ? `/${orgSlug}/hosts/${host}/emails` : `/${orgSlug}/emails`\n registerPluginRecordRoute(\n 'emailMessage',\n {\n list: ({ orgSlug, host }) => `${hub(orgSlug, host)}/messages`,\n record: ({ orgSlug, host }, id) => `${hub(orgSlug, host)}/messages/${encodeURIComponent(id)}`,\n },\n { pluginId: 'email' },\n )\n registerPluginRecordRoute(\n 'emailTemplate',\n {\n list: ({ orgSlug, host }) => (host ? `${hub(orgSlug, host)}/templates` : null),\n record: ({ orgSlug, host }, id) =>\n host ? `${hub(orgSlug, host)}/templates/${encodeURIComponent(id)}` : null,\n },\n { pluginId: 'email' },\n )\n}\n"],"names":["registerPluginRecordRoute","standInEmailsPageRoutes","hub","orgSlug","host","list","record","id","encodeURIComponent","pluginId"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,yBAAyB,QAAQ,mDAAkD;AAE5F;;;;;;;;;CASC,GACD,OAAO,SAASC;IACd,MAAMC,MAAM,CAACC,SAAiBC,OAC5BA,OAAO,CAAC,CAAC,EAAED,QAAQ,OAAO,EAAEC,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC,EAAED,QAAQ,OAAO,CAAC;IAClEH,0BACE,gBACA;QACEK,MAAM,CAAC,EAAEF,OAAO,EAAEC,IAAI,EAAE,GAAK,GAAGF,IAAIC,SAASC,MAAM,SAAS,CAAC;QAC7DE,QAAQ,CAAC,EAAEH,OAAO,EAAEC,IAAI,EAAE,EAAEG,KAAO,GAAGL,IAAIC,SAASC,MAAM,UAAU,EAAEI,mBAAmBD,KAAK;IAC/F,GACA;QAAEE,UAAU;IAAQ;IAEtBT,0BACE,iBACA;QACEK,MAAM,CAAC,EAAEF,OAAO,EAAEC,IAAI,EAAE,GAAMA,OAAO,GAAGF,IAAIC,SAASC,MAAM,UAAU,CAAC,GAAG;QACzEE,QAAQ,CAAC,EAAEH,OAAO,EAAEC,IAAI,EAAE,EAAEG,KAC1BH,OAAO,GAAGF,IAAIC,SAASC,MAAM,WAAW,EAAEI,mBAAmBD,KAAK,GAAG;IACzE,GACA;QAAEE,UAAU;IAAQ;AAExB"}
@@ -1,58 +0,0 @@
1
- /**
2
- * The Emails console's URL: under the site being read, or the organization's
3
- * own Emails page on a surface mounted over the org.
4
- *
5
- * A campaign's page links to two records it does not own — the message that
6
- * was sent inside it, and the template that message was built from — and both
7
- * keep their pages on the Emails console. The shell hands a plugin page only
8
- * its OWN `basePath`, so the sibling hub is named here by its SLUG rather
9
- * than by editing the last segment off the current path: a slug is a string
10
- * this file can be searched for when a surface moves, and string surgery on
11
- * somebody else's path is a link that keeps resolving to the wrong place.
12
- *
13
- * Free, deliberately. The org slug and the subdomain are already in the URL
14
- * the console is on, so this reads the route rather than resolving the host
15
- * document — the two `getDoc`s that resolution costs would be paid on every
16
- * open of a campaign, to render a link. At the organization level the org
17
- * mount already carries the slug.
18
- *
19
- * The org answer comes from the MOUNT rather than from the route having no
20
- * site in it: a card is on the organization's page because it was handed the
21
- * org mount, and that is the fact a link to the org's messages has to follow.
22
- * A message is the org's document, so its page there is
23
- * `/[orgSlug]/emails/messages/{id}` — the Emails page over every site.
24
- *
25
- * `null` before the params resolve, so callers render plain text rather than
26
- * a link to nowhere.
27
- */
28
- export declare function useEmailsHubPath(): string | null;
29
- /**
30
- * The MARKETING console's URL: under the site being read, or the
31
- * organization's own Marketing hub on a page that names no site.
32
- *
33
- * Named for the same reason the Emails one is, from the opposite direction: a
34
- * converted record — a form submission in the Inbox, a contact in Contacts —
35
- * links to the campaign it came from, and those surfaces are handed their own
36
- * hub's `basePath`, not this one's.
37
- *
38
- * Campaigns belong to the organization, so the org-level CRM and the org
39
- * Marketing hub itself link a campaign to `/[orgSlug]/marketing/campaigns/{id}`.
40
- */
41
- export declare function useMarketingHubPath(): string | null;
42
- /** The organization's own Marketing hub, `/[orgSlug]/marketing`. */
43
- export declare function orgMarketingHubPath(orgSlug: string): string;
44
- /** The organization's own Emails page, `/[orgSlug]/emails`. */
45
- export declare function orgEmailsHubPath(orgSlug: string): string;
46
- /**
47
- * Any sibling hub's URL under the site being read, by plugin slug.
48
- *
49
- * One implementation, because "read the org slug and the subdomain off the
50
- * route rather than resolving the host document" is the property that keeps
51
- * these links free, and a second copy of it is where somebody pays for the
52
- * two `getDoc`s instead.
53
- *
54
- * `null` on a page that names no site: a site's hub is the only thing this
55
- * builds.
56
- */
57
- export declare function useConsoleHubPath(pluginSlug: string): string | null;
58
- export default useEmailsHubPath;
@@ -1,109 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright 2026 Aglyn LLC
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- * http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- */ 'use client';
17
- import { buildRoute, Route } from "@aglyn/aglyn";
18
- import { useParams } from "next/navigation";
19
- import { useMarketingOrgMount } from "./marketing-org-mount.js";
20
- /**
21
- * The Emails console's URL: under the site being read, or the organization's
22
- * own Emails page on a surface mounted over the org.
23
- *
24
- * A campaign's page links to two records it does not own — the message that
25
- * was sent inside it, and the template that message was built from — and both
26
- * keep their pages on the Emails console. The shell hands a plugin page only
27
- * its OWN `basePath`, so the sibling hub is named here by its SLUG rather
28
- * than by editing the last segment off the current path: a slug is a string
29
- * this file can be searched for when a surface moves, and string surgery on
30
- * somebody else's path is a link that keeps resolving to the wrong place.
31
- *
32
- * Free, deliberately. The org slug and the subdomain are already in the URL
33
- * the console is on, so this reads the route rather than resolving the host
34
- * document — the two `getDoc`s that resolution costs would be paid on every
35
- * open of a campaign, to render a link. At the organization level the org
36
- * mount already carries the slug.
37
- *
38
- * The org answer comes from the MOUNT rather than from the route having no
39
- * site in it: a card is on the organization's page because it was handed the
40
- * org mount, and that is the fact a link to the org's messages has to follow.
41
- * A message is the org's document, so its page there is
42
- * `/[orgSlug]/emails/messages/{id}` — the Emails page over every site.
43
- *
44
- * `null` before the params resolve, so callers render plain text rather than
45
- * a link to nowhere.
46
- */ export function useEmailsHubPath() {
47
- const orgMount = useMarketingOrgMount();
48
- const siteHub = useConsoleHubPath(EMAILS_SLUG);
49
- return orgMount ? orgEmailsHubPath(orgMount.orgSlug) : siteHub;
50
- }
51
- /**
52
- * The MARKETING console's URL: under the site being read, or the
53
- * organization's own Marketing hub on a page that names no site.
54
- *
55
- * Named for the same reason the Emails one is, from the opposite direction: a
56
- * converted record — a form submission in the Inbox, a contact in Contacts —
57
- * links to the campaign it came from, and those surfaces are handed their own
58
- * hub's `basePath`, not this one's.
59
- *
60
- * Campaigns belong to the organization, so the org-level CRM and the org
61
- * Marketing hub itself link a campaign to `/[orgSlug]/marketing/campaigns/{id}`.
62
- */ export function useMarketingHubPath() {
63
- const params = useParams();
64
- const orgSlug = params == null ? void 0 : params.orgSlug;
65
- if (!orgSlug) return null;
66
- return (params == null ? void 0 : params.host) ? buildRoute(Route.HOST_PLUGIN, {
67
- orgSlug,
68
- host: params.host,
69
- pluginSlug: MARKETING_SLUG
70
- }) : orgMarketingHubPath(orgSlug);
71
- }
72
- /** The Marketing hub's URL slug, under a site and under the org alike. */ const MARKETING_SLUG = 'marketing';
73
- /** The Emails console's URL slug, under a site and under the org alike. */ const EMAILS_SLUG = 'emails';
74
- /** The organization's own Marketing hub, `/[orgSlug]/marketing`. */ export function orgMarketingHubPath(orgSlug) {
75
- return buildRoute(Route.ORG_PLUGIN, {
76
- orgSlug,
77
- pluginSlug: MARKETING_SLUG
78
- });
79
- }
80
- /** The organization's own Emails page, `/[orgSlug]/emails`. */ export function orgEmailsHubPath(orgSlug) {
81
- return buildRoute(Route.ORG_PLUGIN, {
82
- orgSlug,
83
- pluginSlug: EMAILS_SLUG
84
- });
85
- }
86
- /**
87
- * Any sibling hub's URL under the site being read, by plugin slug.
88
- *
89
- * One implementation, because "read the org slug and the subdomain off the
90
- * route rather than resolving the host document" is the property that keeps
91
- * these links free, and a second copy of it is where somebody pays for the
92
- * two `getDoc`s instead.
93
- *
94
- * `null` on a page that names no site: a site's hub is the only thing this
95
- * builds.
96
- */ export function useConsoleHubPath(pluginSlug) {
97
- const params = useParams();
98
- const orgSlug = params == null ? void 0 : params.orgSlug;
99
- const host = params == null ? void 0 : params.host;
100
- if (!orgSlug || !host) return null;
101
- return buildRoute(Route.HOST_PLUGIN, {
102
- orgSlug,
103
- host,
104
- pluginSlug
105
- });
106
- }
107
- export default useEmailsHubPath;
108
-
109
- //# sourceMappingURL=use-emails-hub-path.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../../../../libs/plugins/marketing/src/lib/components/use-emails-hub-path.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n'use client'\n\nimport { buildRoute, Route } from '@aglyn/aglyn'\nimport { useParams } from 'next/navigation'\nimport { useMarketingOrgMount } from './marketing-org-mount'\n\n/**\n * The Emails console's URL: under the site being read, or the organization's\n * own Emails page on a surface mounted over the org.\n *\n * A campaign's page links to two records it does not own — the message that\n * was sent inside it, and the template that message was built from — and both\n * keep their pages on the Emails console. The shell hands a plugin page only\n * its OWN `basePath`, so the sibling hub is named here by its SLUG rather\n * than by editing the last segment off the current path: a slug is a string\n * this file can be searched for when a surface moves, and string surgery on\n * somebody else's path is a link that keeps resolving to the wrong place.\n *\n * Free, deliberately. The org slug and the subdomain are already in the URL\n * the console is on, so this reads the route rather than resolving the host\n * document — the two `getDoc`s that resolution costs would be paid on every\n * open of a campaign, to render a link. At the organization level the org\n * mount already carries the slug.\n *\n * The org answer comes from the MOUNT rather than from the route having no\n * site in it: a card is on the organization's page because it was handed the\n * org mount, and that is the fact a link to the org's messages has to follow.\n * A message is the org's document, so its page there is\n * `/[orgSlug]/emails/messages/{id}` — the Emails page over every site.\n *\n * `null` before the params resolve, so callers render plain text rather than\n * a link to nowhere.\n */\nexport function useEmailsHubPath(): string | null {\n const orgMount = useMarketingOrgMount()\n const siteHub = useConsoleHubPath(EMAILS_SLUG)\n return orgMount ? orgEmailsHubPath(orgMount.orgSlug) : siteHub\n}\n\n/**\n * The MARKETING console's URL: under the site being read, or the\n * organization's own Marketing hub on a page that names no site.\n *\n * Named for the same reason the Emails one is, from the opposite direction: a\n * converted record — a form submission in the Inbox, a contact in Contacts —\n * links to the campaign it came from, and those surfaces are handed their own\n * hub's `basePath`, not this one's.\n *\n * Campaigns belong to the organization, so the org-level CRM and the org\n * Marketing hub itself link a campaign to `/[orgSlug]/marketing/campaigns/{id}`.\n */\nexport function useMarketingHubPath(): string | null {\n const params = useParams<{ orgSlug: string; host: string }>()\n const orgSlug = params?.orgSlug\n if (!orgSlug) return null\n return params?.host\n ? buildRoute(Route.HOST_PLUGIN, {\n orgSlug,\n host: params.host,\n pluginSlug: MARKETING_SLUG,\n })\n : orgMarketingHubPath(orgSlug)\n}\n\n/** The Marketing hub's URL slug, under a site and under the org alike. */\nconst MARKETING_SLUG = 'marketing'\n\n/** The Emails console's URL slug, under a site and under the org alike. */\nconst EMAILS_SLUG = 'emails'\n\n/** The organization's own Marketing hub, `/[orgSlug]/marketing`. */\nexport function orgMarketingHubPath(orgSlug: string): string {\n return buildRoute(Route.ORG_PLUGIN, { orgSlug, pluginSlug: MARKETING_SLUG })\n}\n\n/** The organization's own Emails page, `/[orgSlug]/emails`. */\nexport function orgEmailsHubPath(orgSlug: string): string {\n return buildRoute(Route.ORG_PLUGIN, { orgSlug, pluginSlug: EMAILS_SLUG })\n}\n\n/**\n * Any sibling hub's URL under the site being read, by plugin slug.\n *\n * One implementation, because \"read the org slug and the subdomain off the\n * route rather than resolving the host document\" is the property that keeps\n * these links free, and a second copy of it is where somebody pays for the\n * two `getDoc`s instead.\n *\n * `null` on a page that names no site: a site's hub is the only thing this\n * builds.\n */\nexport function useConsoleHubPath(pluginSlug: string): string | null {\n const params = useParams<{ orgSlug: string; host: string }>()\n const orgSlug = params?.orgSlug\n const host = params?.host\n if (!orgSlug || !host) return null\n return buildRoute(Route.HOST_PLUGIN, { orgSlug, host, pluginSlug })\n}\n\nexport default useEmailsHubPath\n"],"names":["buildRoute","Route","useParams","useMarketingOrgMount","useEmailsHubPath","orgMount","siteHub","useConsoleHubPath","EMAILS_SLUG","orgEmailsHubPath","orgSlug","useMarketingHubPath","params","host","HOST_PLUGIN","pluginSlug","MARKETING_SLUG","orgMarketingHubPath","ORG_PLUGIN"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD;AAEA,SAASA,UAAU,EAAEC,KAAK,QAAQ,eAAc;AAChD,SAASC,SAAS,QAAQ,kBAAiB;AAC3C,SAASC,oBAAoB,QAAQ,2BAAuB;AAE5D;;;;;;;;;;;;;;;;;;;;;;;;;;CA0BC,GACD,OAAO,SAASC;IACd,MAAMC,WAAWF;IACjB,MAAMG,UAAUC,kBAAkBC;IAClC,OAAOH,WAAWI,iBAAiBJ,SAASK,OAAO,IAAIJ;AACzD;AAEA;;;;;;;;;;;CAWC,GACD,OAAO,SAASK;IAC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