@openlup/platform 0.28.0 → 0.30.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 (241) hide show
  1. package/CHANGELOG.md +369 -156
  2. package/README.md +220 -4
  3. package/dist/composition/index.d.ts +1 -0
  4. package/dist/composition/index.js +1 -0
  5. package/dist/composition/marketingContribution.d.ts +21 -0
  6. package/dist/composition/marketingContribution.js +29 -0
  7. package/dist/composition/nodeHost.d.ts +1 -1
  8. package/dist/composition/nodeHost.js +3 -2
  9. package/dist/lifecycle/appUpgrade.d.ts +52 -0
  10. package/dist/lifecycle/appUpgrade.js +180 -0
  11. package/dist/lifecycle/index.d.ts +2 -0
  12. package/dist/lifecycle/index.js +2 -0
  13. package/dist/lifecycle/postgresInstallQualification.d.ts +51 -0
  14. package/dist/lifecycle/postgresInstallQualification.js +74 -0
  15. package/dist/marketing/acquisitionCaseSchemas.d.ts +103 -0
  16. package/dist/marketing/acquisitionCaseSchemas.js +53 -0
  17. package/dist/marketing/acquisitionEvidenceSchemas.d.ts +105 -0
  18. package/dist/marketing/acquisitionEvidenceSchemas.js +55 -0
  19. package/dist/marketing/analytics/dataLayer.d.ts +18 -0
  20. package/dist/marketing/analytics/dataLayer.js +111 -0
  21. package/dist/marketing/analytics/noop.d.ts +9 -0
  22. package/dist/marketing/analytics/noop.js +8 -0
  23. package/dist/marketing/analytics/purchaseFacts.d.ts +4 -0
  24. package/dist/marketing/analytics/purchaseFacts.js +69 -0
  25. package/dist/marketing/analytics/routePolicy.d.ts +10 -0
  26. package/dist/marketing/analytics/routePolicy.js +59 -0
  27. package/dist/marketing/consentEvidence.d.ts +8 -0
  28. package/dist/marketing/consentEvidence.js +32 -0
  29. package/dist/marketing/contactLegal.d.ts +14 -0
  30. package/dist/marketing/contactLegal.js +19 -0
  31. package/dist/marketing/contracts/acquisition.d.ts +88 -0
  32. package/dist/marketing/contracts/acquisition.js +1 -0
  33. package/dist/marketing/contracts/acquisitionPorts.d.ts +49 -0
  34. package/dist/marketing/contracts/acquisitionPorts.js +1 -0
  35. package/dist/marketing/contracts/analytics.d.ts +144 -0
  36. package/dist/marketing/contracts/analytics.js +1 -0
  37. package/dist/marketing/contracts/contactLegal.d.ts +53 -0
  38. package/dist/marketing/contracts/contactLegal.js +1 -0
  39. package/dist/marketing/contracts/index.d.ts +6 -0
  40. package/dist/marketing/contracts/index.js +1 -0
  41. package/dist/marketing/contracts/prelaunch.d.ts +39 -0
  42. package/dist/marketing/contracts/prelaunch.js +1 -0
  43. package/dist/marketing/index.d.ts +16 -0
  44. package/dist/marketing/index.js +14 -0
  45. package/dist/marketing/prelaunchAcquisitionSchemas.d.ts +116 -0
  46. package/dist/marketing/prelaunchAcquisitionSchemas.js +51 -0
  47. package/dist/marketing/seo/jsonLd.d.ts +157 -0
  48. package/dist/marketing/seo/jsonLd.js +127 -0
  49. package/dist/marketing/seo/metadata.d.ts +41 -0
  50. package/dist/marketing/seo/metadata.js +36 -0
  51. package/dist/marketing/seo/serializeJsonLd.d.ts +1 -0
  52. package/dist/marketing/seo/serializeJsonLd.js +6 -0
  53. package/dist/marketing/seo/urls.d.ts +14 -0
  54. package/dist/marketing/seo/urls.js +23 -0
  55. package/dist/marketing/server/acquisitionCaseDirect.d.ts +4 -0
  56. package/dist/marketing/server/acquisitionCaseDirect.js +88 -0
  57. package/dist/marketing/server/acquisitionCaseHandlers.d.ts +28 -0
  58. package/dist/marketing/server/acquisitionCaseHandlers.js +40 -0
  59. package/dist/marketing/server/acquisitionCasePorts.d.ts +42 -0
  60. package/dist/marketing/server/acquisitionCasePorts.js +1 -0
  61. package/dist/marketing/server/acquisitionEvidenceDirect.d.ts +5 -0
  62. package/dist/marketing/server/acquisitionEvidenceDirect.js +100 -0
  63. package/dist/marketing/server/analyticsContext.d.ts +3 -0
  64. package/dist/marketing/server/analyticsContext.js +65 -0
  65. package/dist/marketing/server/analyticsContextPorts.d.ts +31 -0
  66. package/dist/marketing/server/analyticsContextPorts.js +1 -0
  67. package/dist/marketing/server/bindings.d.ts +14 -0
  68. package/dist/marketing/server/bindings.js +18 -0
  69. package/dist/marketing/server/directPorts.d.ts +26 -0
  70. package/dist/marketing/server/directPorts.js +1 -0
  71. package/dist/marketing/server/index.d.ts +14 -0
  72. package/dist/marketing/server/index.js +11 -0
  73. package/dist/marketing/server/postgres/acquisitionCaseRoutines.d.ts +10 -0
  74. package/dist/marketing/server/postgres/acquisitionCaseRoutines.js +204 -0
  75. package/dist/marketing/server/postgres/acquisitionEvidenceRoutines.d.ts +10 -0
  76. package/dist/marketing/server/postgres/acquisitionEvidenceRoutines.js +107 -0
  77. package/dist/marketing/server/postgres/index.d.ts +3 -0
  78. package/dist/marketing/server/postgres/index.js +3 -0
  79. package/dist/marketing/server/prelaunchAcquisitionDirect.d.ts +4 -0
  80. package/dist/marketing/server/prelaunchAcquisitionDirect.js +122 -0
  81. package/dist/marketing/server/privacyContributor.d.ts +66 -0
  82. package/dist/marketing/server/privacyContributor.js +87 -0
  83. package/dist/marketing/server/research/adminSurveyResponsesHandler.d.ts +9 -0
  84. package/dist/marketing/server/research/adminSurveyResponsesHandler.js +53 -0
  85. package/dist/marketing/server/research/managedSurveyResponseSubmit.d.ts +39 -0
  86. package/dist/marketing/server/research/managedSurveyResponseSubmit.js +102 -0
  87. package/dist/marketing/server/research/surveyResponseSubmitHandler.d.ts +8 -0
  88. package/dist/marketing/server/research/surveyResponseSubmitHandler.js +41 -0
  89. package/dist/marketing/validation.d.ts +2 -0
  90. package/dist/marketing/validation.js +3 -0
  91. package/dist/migrations/postgresRunner.d.ts +9 -0
  92. package/dist/migrations/postgresRunner.js +17 -10
  93. package/dist/operations/adminAlertsSchemas.d.ts +153 -0
  94. package/dist/operations/adminAlertsSchemas.js +69 -0
  95. package/dist/operations/adminAlertsView.d.ts +73 -0
  96. package/dist/operations/adminAlertsView.js +184 -0
  97. package/dist/operations/alertPagingPolicy.d.ts +15 -0
  98. package/dist/operations/alertPagingPolicy.js +43 -0
  99. package/dist/operations/alertThrottlePolicy.d.ts +3 -0
  100. package/dist/operations/alertThrottlePolicy.js +18 -0
  101. package/dist/operations/clients.d.ts +17 -0
  102. package/dist/operations/clients.js +32 -0
  103. package/dist/operations/contracts/admin.d.ts +93 -0
  104. package/dist/operations/contracts/admin.js +1 -0
  105. package/dist/operations/contracts/adminAlertsContracts.d.ts +40 -0
  106. package/dist/operations/contracts/adminAlertsContracts.js +1 -0
  107. package/dist/operations/contracts/alertHumanContext.d.ts +7 -0
  108. package/dist/operations/contracts/alertHumanContext.js +1 -0
  109. package/dist/operations/contracts/index.d.ts +6 -0
  110. package/dist/operations/contracts/index.js +6 -0
  111. package/dist/operations/contracts/observabilityContracts.d.ts +41 -0
  112. package/dist/operations/contracts/observabilityContracts.js +1 -0
  113. package/dist/operations/contracts/observabilityPorts.d.ts +18 -0
  114. package/dist/operations/contracts/observabilityPorts.js +1 -0
  115. package/dist/operations/contracts/ports.d.ts +19 -0
  116. package/dist/operations/contracts/ports.js +1 -0
  117. package/dist/operations/errors.d.ts +6 -0
  118. package/dist/operations/errors.js +6 -0
  119. package/dist/operations/index.d.ts +9 -0
  120. package/dist/operations/index.js +9 -0
  121. package/dist/operations/schemas.d.ts +138 -0
  122. package/dist/operations/schemas.js +104 -0
  123. package/dist/operations/server/adminAlertsHandlers.d.ts +16 -0
  124. package/dist/operations/server/adminAlertsHandlers.js +35 -0
  125. package/dist/operations/server/adminPipelineHandlers.d.ts +12 -0
  126. package/dist/operations/server/adminPipelineHandlers.js +48 -0
  127. package/dist/operations/server/adminSettingsHandlers.d.ts +14 -0
  128. package/dist/operations/server/adminSettingsHandlers.js +82 -0
  129. package/dist/operations/server/controlPlaneHandler.d.ts +7 -0
  130. package/dist/operations/server/controlPlaneHandler.js +54 -0
  131. package/dist/operations/server/controlPlaneStore.d.ts +12 -0
  132. package/dist/operations/server/controlPlaneStore.js +138 -0
  133. package/dist/operations/server/controlPlaneWatchdog.d.ts +7 -0
  134. package/dist/operations/server/controlPlaneWatchdog.js +20 -0
  135. package/dist/operations/server/index.d.ts +12 -0
  136. package/dist/operations/server/index.js +12 -0
  137. package/dist/operations/server/migrations.d.ts +14 -0
  138. package/dist/operations/server/migrations.js +7 -0
  139. package/dist/operations/server/platformWatchdogDecision.d.ts +34 -0
  140. package/dist/operations/server/platformWatchdogDecision.js +71 -0
  141. package/dist/operations/server/platformWatchdogDeliveryPolicy.d.ts +10 -0
  142. package/dist/operations/server/platformWatchdogDeliveryPolicy.js +53 -0
  143. package/dist/operations/server/platformWatchdogQueue.d.ts +11 -0
  144. package/dist/operations/server/platformWatchdogQueue.js +94 -0
  145. package/dist/operations/server/platformWatchdogService.d.ts +47 -0
  146. package/dist/operations/server/platformWatchdogService.js +105 -0
  147. package/dist/operations/validation.d.ts +2 -0
  148. package/dist/operations/validation.js +3 -0
  149. package/dist/portability/filesystemObjects.d.ts +12 -0
  150. package/dist/portability/filesystemObjects.js +191 -0
  151. package/dist/portability/index.d.ts +5 -0
  152. package/dist/portability/index.js +4 -0
  153. package/dist/portability/objects.d.ts +63 -0
  154. package/dist/portability/objects.js +138 -0
  155. package/dist/portability/postgresRows.d.ts +64 -0
  156. package/dist/portability/postgresRows.js +182 -0
  157. package/dist/scheduler/advisoryLock.js +20 -2
  158. package/dist/scheduler/nodeScheduler.d.ts +2 -2
  159. package/dist/scheduler/nodeScheduler.js +35 -6
  160. package/package.json +47 -2
  161. package/release-gates.json +143 -9
  162. package/sql/20260814010000_platform_control_plane.sql +286 -0
  163. package/src/composition/index.ts +1 -0
  164. package/src/composition/marketingContribution.ts +37 -0
  165. package/src/composition/nodeHost.ts +4 -3
  166. package/src/lifecycle/appUpgrade.ts +186 -0
  167. package/src/lifecycle/index.ts +19 -0
  168. package/src/lifecycle/postgresInstallQualification.ts +125 -0
  169. package/src/marketing/acquisitionCaseSchemas.ts +75 -0
  170. package/src/marketing/acquisitionEvidenceSchemas.ts +72 -0
  171. package/src/marketing/analytics/dataLayer.ts +100 -0
  172. package/src/marketing/analytics/noop.ts +14 -0
  173. package/src/marketing/analytics/purchaseFacts.ts +63 -0
  174. package/src/marketing/analytics/routePolicy.ts +55 -0
  175. package/src/marketing/consentEvidence.ts +36 -0
  176. package/src/marketing/contactLegal.ts +22 -0
  177. package/src/marketing/contracts/acquisition.ts +50 -0
  178. package/src/marketing/contracts/acquisitionPorts.ts +48 -0
  179. package/src/marketing/contracts/analytics.ts +88 -0
  180. package/src/marketing/contracts/contactLegal.ts +41 -0
  181. package/src/marketing/contracts/index.ts +17 -0
  182. package/src/marketing/contracts/prelaunch.ts +15 -0
  183. package/src/marketing/index.ts +16 -0
  184. package/src/marketing/prelaunchAcquisitionSchemas.ts +64 -0
  185. package/src/marketing/seo/jsonLd.ts +153 -0
  186. package/src/marketing/seo/metadata.ts +62 -0
  187. package/src/marketing/seo/serializeJsonLd.ts +6 -0
  188. package/src/marketing/seo/urls.ts +34 -0
  189. package/src/marketing/server/acquisitionCaseDirect.ts +67 -0
  190. package/src/marketing/server/acquisitionCaseHandlers.ts +57 -0
  191. package/src/marketing/server/acquisitionCasePorts.ts +42 -0
  192. package/src/marketing/server/acquisitionEvidenceDirect.ts +76 -0
  193. package/src/marketing/server/analyticsContext.ts +55 -0
  194. package/src/marketing/server/analyticsContextPorts.ts +28 -0
  195. package/src/marketing/server/bindings.ts +27 -0
  196. package/src/marketing/server/directPorts.ts +27 -0
  197. package/src/marketing/server/index.ts +14 -0
  198. package/src/marketing/server/postgres/acquisitionCaseRoutines.ts +218 -0
  199. package/src/marketing/server/postgres/acquisitionEvidenceRoutines.ts +103 -0
  200. package/src/marketing/server/postgres/index.ts +3 -0
  201. package/src/marketing/server/prelaunchAcquisitionDirect.ts +121 -0
  202. package/src/marketing/server/privacyContributor.ts +123 -0
  203. package/src/marketing/server/research/adminSurveyResponsesHandler.ts +78 -0
  204. package/src/marketing/server/research/managedSurveyResponseSubmit.ts +158 -0
  205. package/src/marketing/server/research/surveyResponseSubmitHandler.ts +57 -0
  206. package/src/marketing/validation.ts +3 -0
  207. package/src/migrations/postgresRunner.ts +24 -9
  208. package/src/operations/adminAlertsSchemas.ts +78 -0
  209. package/src/operations/adminAlertsView.ts +238 -0
  210. package/src/operations/alertPagingPolicy.ts +50 -0
  211. package/src/operations/alertThrottlePolicy.ts +22 -0
  212. package/src/operations/clients.ts +44 -0
  213. package/src/operations/contracts/admin.ts +24 -0
  214. package/src/operations/contracts/adminAlertsContracts.ts +13 -0
  215. package/src/operations/contracts/alertHumanContext.ts +17 -0
  216. package/src/operations/contracts/index.ts +6 -0
  217. package/src/operations/contracts/observabilityContracts.ts +40 -0
  218. package/src/operations/contracts/observabilityPorts.ts +30 -0
  219. package/src/operations/contracts/ports.ts +22 -0
  220. package/src/operations/errors.ts +6 -0
  221. package/src/operations/index.ts +9 -0
  222. package/src/operations/schemas.ts +122 -0
  223. package/src/operations/server/adminAlertsHandlers.ts +61 -0
  224. package/src/operations/server/adminPipelineHandlers.ts +73 -0
  225. package/src/operations/server/adminSettingsHandlers.ts +114 -0
  226. package/src/operations/server/controlPlaneHandler.ts +56 -0
  227. package/src/operations/server/controlPlaneStore.ts +150 -0
  228. package/src/operations/server/controlPlaneWatchdog.ts +28 -0
  229. package/src/operations/server/index.ts +12 -0
  230. package/src/operations/server/migrations.ts +7 -0
  231. package/src/operations/server/platformWatchdogDecision.ts +93 -0
  232. package/src/operations/server/platformWatchdogDeliveryPolicy.ts +92 -0
  233. package/src/operations/server/platformWatchdogQueue.ts +96 -0
  234. package/src/operations/server/platformWatchdogService.ts +209 -0
  235. package/src/operations/validation.ts +3 -0
  236. package/src/portability/filesystemObjects.ts +138 -0
  237. package/src/portability/index.ts +12 -0
  238. package/src/portability/objects.ts +160 -0
  239. package/src/portability/postgresRows.ts +169 -0
  240. package/src/scheduler/advisoryLock.ts +20 -5
  241. package/src/scheduler/nodeScheduler.ts +28 -8
@@ -0,0 +1,55 @@
1
+ import type { AnalyticsRoutePolicyInput } from "../contracts/analytics.js";
2
+ export type { AnalyticsRoutePolicyInput } from "../contracts/analytics.js";
3
+ const CAMPAIGN_KEYS = ["utm_source", "utm_medium", "utm_campaign", "utm_content", "utm_term"] as const;
4
+ const CAMPAIGN_VALUE = /^[A-Za-z0-9_-]{1,100}$/;
5
+ const NO_ADDITIONAL_PATHS: ReadonlySet<string> = new Set();
6
+
7
+ export function normalizeAnalyticsPathname(pathname: string): string {
8
+ const withLeadingSlash = pathname.startsWith("/") ? pathname : `/${pathname}`;
9
+ const withoutTrailingSlash = withLeadingSlash.length > 1
10
+ ? withLeadingSlash.replace(/\/+$/, "") : withLeadingSlash;
11
+ return withoutTrailingSlash.toLowerCase();
12
+ }
13
+
14
+ /** Route manifests and sensitive paths are explicit host policy. */
15
+ export function createAnalyticsRoutePolicy(input: AnalyticsRoutePolicyInput) {
16
+ const manifestPaths = new Set(input.publicPaths.map(normalizeAnalyticsPathname));
17
+ const redirectPaths = new Set(input.redirectSources.filter(source => !source.includes(":"))
18
+ .map(normalizeAnalyticsPathname));
19
+ function isSensitiveAnalyticsPath(pathname: string): boolean {
20
+ const capabilityPath = pathname.toLowerCase();
21
+ return input.privatePathPrefixes.some(prefix => pathname === prefix || pathname.startsWith(`${prefix}/`))
22
+ || input.privateAuthPaths.includes(pathname)
23
+ || input.capabilityPathPrefixes.some(prefix => capabilityPath === prefix || capabilityPath.startsWith(`${prefix}/`));
24
+ }
25
+ function isOptionalAnalyticsRouteEligible(pathname: string): boolean {
26
+ return !isSensitiveAnalyticsPath(pathname);
27
+ }
28
+ function isDeploymentAnalyticsRouteEligible(pathname: string,
29
+ additionalPublicPaths: ReadonlySet<string> = NO_ADDITIONAL_PATHS): boolean {
30
+ const path = normalizeAnalyticsPathname(pathname);
31
+ if (isSensitiveAnalyticsPath(path)) return false;
32
+ return manifestPaths.has(path) || redirectPaths.has(path) || additionalPublicPaths.has(path);
33
+ }
34
+ function sanitizeDeploymentAnalyticsUrl(rawUrl: string, currentOrigin: string,
35
+ additionalPublicPaths?: ReadonlySet<string>): string | null {
36
+ let base: URL;
37
+ let url: URL;
38
+ try { base = new URL(currentOrigin); url = new URL(rawUrl, base); } catch { return null; }
39
+ if ((url.protocol !== "http:" && url.protocol !== "https:") || url.username || url.password
40
+ || url.origin !== base.origin) return null;
41
+ const pathname = normalizeAnalyticsPathname(url.pathname);
42
+ if (!isDeploymentAnalyticsRouteEligible(pathname, additionalPublicPaths)) return null;
43
+ const campaign = new URLSearchParams();
44
+ for (const key of CAMPAIGN_KEYS) {
45
+ const values = url.searchParams.getAll(key);
46
+ if (values.length === 1 && CAMPAIGN_VALUE.test(values[0]!)) campaign.set(key, values[0]!);
47
+ }
48
+ url.pathname = pathname;
49
+ url.search = campaign.toString();
50
+ url.hash = "";
51
+ return url.href;
52
+ }
53
+ return { isSensitiveAnalyticsPath, isOptionalAnalyticsRouteEligible,
54
+ isDeploymentAnalyticsRouteEligible, sanitizeDeploymentAnalyticsUrl };
55
+ }
@@ -0,0 +1,36 @@
1
+ import type { MarketingHistoricalConsentCommand, MarketingHistoricalConsentState, MarketingHistoricalConsentResult } from "./contracts/analytics.js";
2
+ export type { MarketingHistoricalConsentCommand, MarketingHistoricalConsentState, MarketingHistoricalConsentResult } from "./contracts/analytics.js";
3
+ import { z } from "./validation.js";
4
+
5
+ const historicalTimestamp = z.string().max(80).datetime({ offset: true });
6
+ const HISTORICAL_MIN_AGE_MS = 5 * 60 * 1000;
7
+
8
+ /** Transport chronology after authorization; never changes the local consent grant. */
9
+ export function selectMarketingHistoricalConsentTime(input: {
10
+ command: MarketingHistoricalConsentCommand; state: MarketingHistoricalConsentState; now: Date;
11
+ }): MarketingHistoricalConsentResult {
12
+ const { command, state, now } = input;
13
+ if (!Number.isFinite(now.getTime())) return { kind: "hold", reason: "consent_time_invalid" };
14
+ let selected = command.consentedAt;
15
+ if (state.consent === "SUBSCRIBED") {
16
+ const native = historicalTimestamp.safeParse(state.nativeConsentAt);
17
+ if (!native.success || !Number.isFinite(Date.parse(native.data)) || Date.parse(native.data) >= now.getTime()) {
18
+ return { kind: "hold", reason: "provider_state_unknown" };
19
+ }
20
+ const overriding = state.suppressions.some(item => item.reason === "UNSUBSCRIBE"
21
+ && (item.listId === null || item.listId === command.listId));
22
+ if (!overriding) selected = native.data;
23
+ else if (Date.parse(command.consentedAt ?? "") > Date.parse(native.data)) {
24
+ return { kind: "hold", reason: "provider_state_unknown" };
25
+ }
26
+ }
27
+ const parsed = historicalTimestamp.safeParse(selected);
28
+ if (!parsed.success || !Number.isFinite(Date.parse(parsed.data)) || Date.parse(parsed.data) >= now.getTime()) {
29
+ return { kind: "hold", reason: "consent_time_invalid" };
30
+ }
31
+ // Parsing truncates fractional milliseconds; round only the age boundary up.
32
+ const discarded = /\.\d{3}(\d+)(?:Z|[+-]\d{2}:\d{2})$/.exec(parsed.data)?.[1];
33
+ const matureAt = Date.parse(parsed.data) + (discarded && /[1-9]/.test(discarded) ? 1 : 0) + HISTORICAL_MIN_AGE_MS;
34
+ return now.getTime() < matureAt ? { kind: "defer", retryAt: new Date(matureAt).toISOString() }
35
+ : { kind: "ready", providerConsentedAt: parsed.data };
36
+ }
@@ -0,0 +1,22 @@
1
+ import type { ContactContent, LegalDocumentContent } from "./contracts/contactLegal.js";
2
+
3
+ export function contactContent(facts: ContactContent) {
4
+ return {
5
+ supportEmail: facts.supportEmail,
6
+ companyLines: [
7
+ facts.organization.legalName,
8
+ facts.addressLine,
9
+ facts.registrationIdentifiers.map(({ label, value }) => `${label} ${value}`).join(" · "),
10
+ ...(facts.registrationAuthority !== undefined ? [facts.registrationAuthority] : []),
11
+ ],
12
+ };
13
+ }
14
+
15
+ export function legalDocumentContent(content: LegalDocumentContent) {
16
+ return {
17
+ title: content.title,
18
+ intro: content.intro,
19
+ sections: content.sections.map(({ title, body }) => ({ title, body })),
20
+ ...(content.lastUpdated !== undefined ? { lastUpdated: content.lastUpdated } : {}),
21
+ };
22
+ }
@@ -0,0 +1,50 @@
1
+ export type AcquisitionOpaqueReference = string;
2
+ export type AcquisitionAddressReference = { source: string; reference: string; revision: string; provenance: string };
3
+ export type AcquisitionCaseState = "submitted" | "approved" | "active" | "rejected" | "withdrawn";
4
+ export type AcquisitionCaseProjection = {
5
+ contractVersion: "tester_application_v1";
6
+ caseRef: string;
7
+ contactRef: string;
8
+ sourceKind: "tester_application";
9
+ consent: { consentVersion: string; policyVersion: string; recordedAt: string; locale: "en" | "pl"; sourcePath: "/tester-application" };
10
+ addressReference: AcquisitionAddressReference | null;
11
+ state: AcquisitionCaseState;
12
+ version: number;
13
+ createdAt: string;
14
+ updatedAt: string;
15
+ };
16
+ export type AcquisitionCaseListRequest = { view: "acquisition_case_v1"; cursor?: string | undefined; limit: number };
17
+ export type AcquisitionCaseListResponse = { contractVersion: "tester_application_v1"; cases: AcquisitionCaseProjection[]; nextCursor: string | null };
18
+ export type AcquisitionCaseActiveCountResponse = { activeTesterCount: number };
19
+ export type AcquisitionIdempotencyKey = string;
20
+ export type AcquisitionSurveySubmit = { view: "acquisition_survey_v1"; caseReference: string; surveyType: "producer" | "consumer"; responseData: Record<string, unknown> };
21
+ export type AcquisitionSurveyEvidence = {
22
+ evidenceReference: string;
23
+ caseReference: string;
24
+ contactReference: string;
25
+ surveyType: "producer" | "consumer";
26
+ responseDigest: string;
27
+ answerCount: number;
28
+ recordedAt: string;
29
+ };
30
+ export type AcquisitionSurveySubmitResponse = { contractVersion: "acquisition_survey_v1"; evidence: AcquisitionSurveyEvidence; replayed: boolean };
31
+ export type AcquisitionSurveyListQuery = { view: "acquisition_survey_v1"; surveyType?: "producer" | "consumer" | undefined; limit: number };
32
+ export type AcquisitionSurveyListResponse = { contractVersion: "acquisition_survey_v1"; rows: AcquisitionSurveyEvidence[]; totalCount: number };
33
+ export type AcquisitionNewsletterConsentEvent = {
34
+ contractVersion: "acquisition_newsletter_consent_v1";
35
+ caseReference: string;
36
+ contactReference: string;
37
+ eventReference: string;
38
+ eventType: "subscribe" | "unsubscribe" | "suppress" | "complaint" | "update";
39
+ purpose: "marketing_launch_offer" | "marketing_newsletter";
40
+ explicitOptInEvidence: boolean;
41
+ occurredAt: string;
42
+ };
43
+ export type AcquisitionNewsletterConsentResponse = {
44
+ contractVersion: "acquisition_newsletter_consent_v1";
45
+ eventReference: string;
46
+ outcome: "applied" | "ignored" | "stale";
47
+ consentState: "granted" | "suppressed" | null;
48
+ auditReference: string;
49
+ replayed: boolean;
50
+ };
@@ -0,0 +1,48 @@
1
+ import type {
2
+ AcquisitionCaseListResponse, AcquisitionCaseProjection, AcquisitionNewsletterConsentEvent,
3
+ AcquisitionNewsletterConsentResponse, AcquisitionSurveyListQuery, AcquisitionSurveyListResponse,
4
+ AcquisitionSurveySubmit, AcquisitionSurveySubmitResponse,
5
+ } from "./acquisition.js";
6
+
7
+ export type AcquisitionCaseFailureKind =
8
+ | "conflict"
9
+ | "invalid"
10
+ | "not_found"
11
+ | "rate_limited"
12
+ | "unavailable";
13
+
14
+ export type AcquisitionCaseResult<T> =
15
+ | { ok: true; value: T; replayed?: boolean }
16
+ | { ok: false; error: { kind: AcquisitionCaseFailureKind } };
17
+
18
+ export interface AcquisitionCaseListQuery {
19
+ actorRef: string;
20
+ scope: "public_tester_application";
21
+ cursor?: string;
22
+ limit: number;
23
+ }
24
+
25
+ export interface AcquisitionCaseGetQuery {
26
+ actorRef: string;
27
+ scope: "public_tester_application";
28
+ caseRef: string;
29
+ }
30
+
31
+ export interface AcquisitionCasePort {
32
+ list(query: AcquisitionCaseListQuery): Promise<AcquisitionCaseResult<AcquisitionCaseListResponse>>;
33
+ get(query: AcquisitionCaseGetQuery): Promise<AcquisitionCaseResult<AcquisitionCaseProjection>>;
34
+ activeCount(scope: "public_tester_application"): Promise<AcquisitionCaseResult<number>>;
35
+ close(): Promise<void>;
36
+ }
37
+
38
+ export type AcquisitionEvidenceFailure = "invalid" | "not_found" | "conflict" | "unavailable";
39
+ export type AcquisitionEvidenceResult<T> =
40
+ | { ok: true; value: T }
41
+ | { ok: false; error: { kind: AcquisitionEvidenceFailure } };
42
+
43
+ export interface AcquisitionEvidencePort {
44
+ submitSurvey(input: AcquisitionSurveySubmit & { idempotencyKey: string }): Promise<AcquisitionEvidenceResult<AcquisitionSurveySubmitResponse>>;
45
+ listSurveys(input: AcquisitionSurveyListQuery & { actorReference: string }): Promise<AcquisitionEvidenceResult<AcquisitionSurveyListResponse>>;
46
+ applyNewsletterConsent(input: AcquisitionNewsletterConsentEvent): Promise<AcquisitionEvidenceResult<AcquisitionNewsletterConsentResponse>>;
47
+ close(): Promise<void>;
48
+ }
@@ -0,0 +1,88 @@
1
+ /** The host supplies its own literal step vocabulary. */
2
+ export type AnalyticsStepName<StepName extends string = string> = StepName;
3
+ export interface AnalyticsCheckoutItem { item_id: string; quantity: number }
4
+ export interface AnalyticsPurchaseItem extends AnalyticsCheckoutItem {
5
+ item_variant?: string;
6
+ price: number;
7
+ discount: number;
8
+ }
9
+ export type AnalyticsCheckoutMode = "one_time" | "subscription";
10
+ /** No answer describes an ended wait, without asserting payment failure. */
11
+ export type AnalyticsPaymentWaitOutcome = "confirmed" | "refused" | "no_answer";
12
+ export interface AnalyticsEventMap<StepName extends string = string> {
13
+ page_view: { page_path: string };
14
+ configurator_start: { entry_view: "hero" | "configurator" };
15
+ configurator_step_view: { step_number: number; step_name: AnalyticsStepName<StepName> };
16
+ begin_checkout: { checkout_mode: AnalyticsCheckoutMode; items: AnalyticsCheckoutItem[] };
17
+ purchase: {
18
+ transaction_id: string;
19
+ currency: string;
20
+ value: number;
21
+ shipping: number;
22
+ tax: number;
23
+ checkout_mode: AnalyticsCheckoutMode;
24
+ items: AnalyticsPurchaseItem[];
25
+ };
26
+ // Wait observations carry no identity, amount, currency or payment method.
27
+ payment_wait_start: { checkoutMode: AnalyticsCheckoutMode };
28
+ payment_wait_end: { outcome: AnalyticsPaymentWaitOutcome; checkoutMode: AnalyticsCheckoutMode };
29
+ configurator_draft_restored: { draft_context: "public" };
30
+ configurator_draft_save_failed: { draft_context: "public"; reason: "unavailable" | "quota" | "conflict" };
31
+ configurator_draft_reset: { draft_context: "public" };
32
+ }
33
+ export type AnalyticsEventName = keyof AnalyticsEventMap;
34
+
35
+ export interface AnalyticsSinkAttemptMask { deployment: boolean; optional: boolean }
36
+ /** Synchronous local acceptance only; never transport delivery or business acknowledgement. */
37
+ export interface AnalyticsSinkAdmission { deployment: boolean; optional: boolean }
38
+ export interface AnalyticsCookieConsent {
39
+ necessary: boolean; functional: boolean; analytics: boolean; marketing: boolean;
40
+ }
41
+ export type AnalyticsBrowserWindow = Pick<Window, "localStorage" | "addEventListener" | "removeEventListener"> & {
42
+ dataLayer?: unknown[];
43
+ };
44
+ export interface AnalyticsDataLayerOptions<StepName extends string = string> {
45
+ consentStorageKey?: string;
46
+ consentChangeEvent?: string;
47
+ /** Host wire names, analytics first then advertising in supplied order. Omission disables consent commands and optional event admission. */
48
+ consentSignalNames?: { analytics: string; advertising: readonly string[] };
49
+ eventPrefix?: string;
50
+ readContainerId?: () => string | null;
51
+ trackDeploymentEvent?: <K extends AnalyticsEventName>(event: K, properties: AnalyticsEventMap<StepName>[K]) => boolean;
52
+ getWindow?: () => AnalyticsBrowserWindow | undefined;
53
+ }
54
+
55
+ export interface AnalyticsRoutePolicyInput {
56
+ publicPaths: readonly string[];
57
+ redirectSources: readonly string[];
58
+ privatePathPrefixes: readonly string[];
59
+ privateAuthPaths: readonly string[];
60
+ capabilityPathPrefixes: readonly string[];
61
+ }
62
+
63
+ /** Only paid recap facts read by the projection; money remains the host's truth. */
64
+ export interface PurchaseOrder {
65
+ orderId: string;
66
+ status: string;
67
+ paymentStatus: string | null;
68
+ checkoutKind: "one_time" | "subscription_initial" | "subscription_renewal" | null;
69
+ moneyReconciled: boolean;
70
+ items: Array<{ sku: string | null; variantCode: string | null; quantity: number;
71
+ catalogTotalGross: number; effectiveNet: number; vatRateBps: number }>;
72
+ totals: { tax: { amountMinor: number }; total: { amountMinor: number; currency: string } };
73
+ }
74
+ export type PurchaseSuppressionReason = "order_not_paid" | "payment_not_succeeded"
75
+ | "checkout_kind_unsupported" | "money_unreconciled" | "items_empty" | "sku_missing"
76
+ | "quantity_invalid" | "line_money_invalid" | "net_discount_invalid"
77
+ | "item_limit_exceeded" | "shipping_net_invalid";
78
+
79
+ export interface MarketingHistoricalConsentCommand { consentedAt: string | null; listId: string | null }
80
+ /** Native state literals are compatibility inputs supplied by the host adapter. */
81
+ export interface MarketingHistoricalConsentState {
82
+ consent: "SUBSCRIBED" | "UNSUBSCRIBED" | "NEVER_SUBSCRIBED" | "unknown";
83
+ nativeConsentAt?: string | null;
84
+ suppressions: Array<{ reason: "UNSUBSCRIBE" | "SPAM_REPORT" | "USER_SUPPRESSED" | "HARD_BOUNCE" | "INVALID_EMAIL" | "unknown";
85
+ listId: string | null }>;
86
+ }
87
+ export type MarketingHistoricalConsentResult = { kind: "ready"; providerConsentedAt: string }
88
+ | { kind: "defer"; retryAt: string } | { kind: "hold"; reason: string };
@@ -0,0 +1,41 @@
1
+ export interface OrganizationFacts {
2
+ name: string;
3
+ legalName: string;
4
+ url: string;
5
+ logo: { url: string; contentUrl: string; width: number; height: number };
6
+ email: string;
7
+ vatID: string;
8
+ taxID: string;
9
+ areaServed: string;
10
+ sameAs: string[];
11
+ contactPoint: { email: string; contactType: string; availableLanguage: string[] };
12
+ address: {
13
+ streetAddress: string;
14
+ addressLocality: string;
15
+ postalCode: string;
16
+ addressRegion: string;
17
+ addressCountry: string;
18
+ };
19
+ }
20
+
21
+ export interface ContactContent {
22
+ organization: OrganizationFacts;
23
+ supportEmail: string;
24
+ addressLine: string;
25
+ registrationIdentifiers: { label: string; value: string }[];
26
+ registrationAuthority?: string;
27
+ }
28
+
29
+ export interface LegalDocumentContent {
30
+ title: string;
31
+ intro: string;
32
+ sections: { title: string; body: string }[];
33
+ lastUpdated?: string;
34
+ }
35
+
36
+ export interface PrivacyProcessorDisclosure {
37
+ processorName: string;
38
+ purpose: string;
39
+ dataCategories: string[];
40
+ details?: string;
41
+ }
@@ -0,0 +1,17 @@
1
+ export type * from "./acquisition.js";
2
+ export type {
3
+ MarketingResearchJson,
4
+ ResearchSurveyType,
5
+ AdminSurveyResponsesRequest,
6
+ AdminSurveyResponseRow,
7
+ AdminSurveyResponsesResponse,
8
+ ResearchSurveySubmitRequest,
9
+ ResearchSurveySubmitResponse,
10
+ MarketingResearchSurveyResponsesReadPort,
11
+ MarketingResearchSurveyRequestHeaders,
12
+ MarketingResearchSurveySubmitPort,
13
+ } from "@openlup/core/marketing/research";
14
+ export type * from "./acquisitionPorts.js";
15
+ export type * from "./prelaunch.js";
16
+ export type * from "./analytics.js";
17
+ export type * from "./contactLegal.js";
@@ -0,0 +1,15 @@
1
+ export type PrelaunchAcquisitionListRequest = { view: "prelaunch_acquisition_v1"; cursor?: string | undefined; limit: number };
2
+ export type PrelaunchAcquisitionDetailRequest = { sourceRef: string };
3
+ export type PrelaunchAcquisitionLead = {
4
+ sourceRef: string;
5
+ contactRef: string;
6
+ sourceKind: "tester_application";
7
+ consent: { consentVersion: string; policyVersion: string; recordedAt: string; locale: "en" | "pl"; sourcePath: "/tester-application" };
8
+ addressReference: { source: string; reference: string; revision: string; provenance: string } | null;
9
+ state: "submitted" | "approved" | "active" | "rejected" | "withdrawn";
10
+ version: number;
11
+ createdAt: string;
12
+ updatedAt: string;
13
+ };
14
+ export type PrelaunchAcquisitionListResponse = { contractVersion: "prelaunch_acquisition_v1"; leads: PrelaunchAcquisitionLead[]; nextCursor: string | null };
15
+ export type PrelaunchAcquisitionDetailResponse = { contractVersion: "prelaunch_acquisition_v1"; lead: PrelaunchAcquisitionLead };
@@ -0,0 +1,16 @@
1
+ export * from "./acquisitionCaseSchemas.js";
2
+ export * from "./acquisitionEvidenceSchemas.js";
3
+ export * from "@openlup/core/marketing/research";
4
+ export * from "./prelaunchAcquisitionSchemas.js";
5
+ export type * from "./contracts/acquisitionPorts.js";
6
+ export * from "./analytics/noop.js";
7
+ export * from "./analytics/dataLayer.js";
8
+ export * from "./analytics/routePolicy.js";
9
+ export * from "./analytics/purchaseFacts.js";
10
+ export * from "./consentEvidence.js";
11
+ export * from "./seo/serializeJsonLd.js";
12
+ export * from "./seo/urls.js";
13
+ export * from "./seo/metadata.js";
14
+ export * from "./seo/jsonLd.js";
15
+ export type * from "./contracts/contactLegal.js";
16
+ export * from "./contactLegal.js";
@@ -0,0 +1,64 @@
1
+ import { z } from "./validation.js";
2
+
3
+ export const PRELAUNCH_ACQUISITION_VIEW = "prelaunch_acquisition_v1" as const;
4
+ export const PRELAUNCH_ACQUISITION_CONTRACT_VERSION = "prelaunch_acquisition_v1" as const;
5
+
6
+ const acquisitionCaseRefSchema = z.string().regex(/^acquisition-case:[0-9a-f-]{36}$/);
7
+ const acquisitionContactRefSchema = z.string().regex(/^acquisition-contact:[0-9a-f-]{36}$/);
8
+ const acquisitionOpaqueRefSchema = z.string().trim().min(8).max(160)
9
+ .regex(/^[A-Za-z0-9][A-Za-z0-9._:-]*$/);
10
+ const acquisitionDateTimeSchema = z.string().datetime({ offset: true });
11
+
12
+ export const prelaunchAcquisitionListRequestSchema = z.object({
13
+ view: z.literal(PRELAUNCH_ACQUISITION_VIEW),
14
+ cursor: acquisitionOpaqueRefSchema.optional(),
15
+ limit: z.coerce.number().int().min(1).max(100).default(25),
16
+ }).strict();
17
+
18
+ export const prelaunchAcquisitionDetailRequestSchema = z.object({
19
+ sourceRef: acquisitionCaseRefSchema,
20
+ }).strict();
21
+
22
+ export const prelaunchAcquisitionLeadSchema = z.object({
23
+ sourceRef: acquisitionCaseRefSchema,
24
+ contactRef: acquisitionContactRefSchema,
25
+ sourceKind: z.literal("tester_application"),
26
+ consent: z.object({
27
+ consentVersion: z.string().min(1).max(64),
28
+ policyVersion: z.string().min(1).max(64),
29
+ recordedAt: acquisitionDateTimeSchema,
30
+ locale: z.enum(["en", "pl"]),
31
+ sourcePath: z.literal("/tester-application"),
32
+ }).strict(),
33
+ addressReference: z.object({
34
+ source: z.string().trim().min(1).max(48).regex(/^[a-z][a-z0-9_-]*$/),
35
+ reference: acquisitionOpaqueRefSchema,
36
+ revision: z.string().trim().min(1).max(64).regex(/^[A-Za-z0-9][A-Za-z0-9._:-]*$/),
37
+ provenance: z.string().trim().min(1).max(64).regex(/^[a-z][a-z0-9_-]*$/),
38
+ }).strict().nullable(),
39
+ state: z.enum(["submitted", "approved", "active", "rejected", "withdrawn"]),
40
+ version: z.number().int().positive(),
41
+ createdAt: acquisitionDateTimeSchema,
42
+ updatedAt: acquisitionDateTimeSchema,
43
+ }).strict().superRefine((value, context) => {
44
+ if (value.state !== "withdrawn" && value.addressReference === null) {
45
+ context.addIssue({ code: z.ZodIssueCode.custom, path: ["addressReference"], message: "active case requires address reference" });
46
+ }
47
+ });
48
+
49
+ export const prelaunchAcquisitionListResponseSchema = z.object({
50
+ contractVersion: z.literal(PRELAUNCH_ACQUISITION_CONTRACT_VERSION),
51
+ leads: z.array(prelaunchAcquisitionLeadSchema).max(100),
52
+ nextCursor: acquisitionOpaqueRefSchema.nullable(),
53
+ }).strict();
54
+
55
+ export const prelaunchAcquisitionDetailResponseSchema = z.object({
56
+ contractVersion: z.literal(PRELAUNCH_ACQUISITION_CONTRACT_VERSION),
57
+ lead: prelaunchAcquisitionLeadSchema,
58
+ }).strict();
59
+
60
+ export type PrelaunchAcquisitionListRequest = z.infer<typeof prelaunchAcquisitionListRequestSchema>;
61
+ export type PrelaunchAcquisitionDetailRequest = z.infer<typeof prelaunchAcquisitionDetailRequestSchema>;
62
+ export type PrelaunchAcquisitionLead = z.infer<typeof prelaunchAcquisitionLeadSchema>;
63
+ export type PrelaunchAcquisitionListResponse = z.infer<typeof prelaunchAcquisitionListResponseSchema>;
64
+ export type PrelaunchAcquisitionDetailResponse = z.infer<typeof prelaunchAcquisitionDetailResponseSchema>;
@@ -0,0 +1,153 @@
1
+ import type { OrganizationFacts } from "../contracts/contactLegal.js";
2
+
3
+ export type JsonLdNode = Record<string, unknown> & { "@context"?: string; "@id"?: string };
4
+
5
+ export function jsonLdGraph(...nodes: JsonLdNode[]) {
6
+ const seen = new Set<string>();
7
+ const graph = nodes.flatMap(({ "@context": _context, ...node }) => {
8
+ if (node["@id"] && seen.has(node["@id"] as string)) return [];
9
+ if (node["@id"]) seen.add(node["@id"] as string);
10
+ return [node];
11
+ });
12
+ return { "@context": "https://schema.org", "@graph": graph };
13
+ }
14
+
15
+ export function entityIds(origin: string) {
16
+ const site = origin.replace(/\/$/, "");
17
+ return {
18
+ organization: `${site}/#organization`,
19
+ website: `${site}/#website`,
20
+ brand: `${site}/#brand`,
21
+ };
22
+ }
23
+
24
+ export function organizationLd(origin: string, type: "Organization" | "OnlineStore", facts: OrganizationFacts) {
25
+ return {
26
+ "@context": "https://schema.org",
27
+ "@id": entityIds(origin).organization,
28
+ "@type": type,
29
+ name: facts.name,
30
+ legalName: facts.legalName,
31
+ url: facts.url,
32
+ logo: {
33
+ "@type": "ImageObject",
34
+ url: facts.logo.url,
35
+ contentUrl: facts.logo.contentUrl,
36
+ width: facts.logo.width,
37
+ height: facts.logo.height,
38
+ },
39
+ email: facts.email,
40
+ vatID: facts.vatID,
41
+ taxID: facts.taxID,
42
+ areaServed: facts.areaServed,
43
+ sameAs: facts.sameAs,
44
+ contactPoint: {
45
+ "@type": "ContactPoint",
46
+ email: facts.contactPoint.email,
47
+ contactType: facts.contactPoint.contactType,
48
+ availableLanguage: facts.contactPoint.availableLanguage,
49
+ },
50
+ address: {
51
+ "@type": "PostalAddress",
52
+ streetAddress: facts.address.streetAddress,
53
+ addressLocality: facts.address.addressLocality,
54
+ postalCode: facts.address.postalCode,
55
+ addressRegion: facts.address.addressRegion,
56
+ addressCountry: facts.address.addressCountry,
57
+ },
58
+ };
59
+ }
60
+
61
+ export function brandLd(origin: string, name: string, url: string) {
62
+ return { "@context": "https://schema.org", "@id": entityIds(origin).brand, "@type": "Brand", name, url };
63
+ }
64
+
65
+ export function websiteLd(origin: string, name: string, url: string, inLanguage: string[]) {
66
+ return {
67
+ "@context": "https://schema.org",
68
+ "@id": entityIds(origin).website,
69
+ "@type": "WebSite",
70
+ name,
71
+ url,
72
+ inLanguage,
73
+ publisher: { "@id": entityIds(origin).organization },
74
+ };
75
+ }
76
+
77
+ export function contactPageLd(origin: string, pageUrl: string) {
78
+ return {
79
+ "@context": "https://schema.org",
80
+ "@id": `${pageUrl.replace(/\/$/, "")}#webpage`,
81
+ "@type": "ContactPage",
82
+ url: pageUrl,
83
+ publisher: { "@id": entityIds(origin).organization },
84
+ mainEntity: { "@id": entityIds(origin).organization },
85
+ };
86
+ }
87
+
88
+ export interface NetContent { unscaled: number; scale: number; unit: string }
89
+
90
+ export function schemaWeight(netContent: NetContent) {
91
+ const { unscaled, scale, unit } = netContent;
92
+ const unitCode = unit === "GRAM" || unit === "G" ? "GRM" : unit;
93
+ return { "@type": "QuantitativeValue", value: unscaled / 10 ** scale, unitCode };
94
+ }
95
+
96
+ export interface ProductFacts {
97
+ url: string;
98
+ name: string;
99
+ inLanguage: string;
100
+ brandName: string;
101
+ category?: string;
102
+ images: string[];
103
+ sku?: string;
104
+ gtin13?: string;
105
+ netContent?: NetContent;
106
+ }
107
+
108
+ export function productLd(origin: string, product: ProductFacts) {
109
+ return {
110
+ "@context": "https://schema.org",
111
+ "@id": `${product.url.replace(/\/$/, "")}#product`,
112
+ "@type": "Product",
113
+ name: product.name,
114
+ inLanguage: product.inLanguage,
115
+ brand: { "@id": entityIds(origin).brand, "@type": "Brand", name: product.brandName },
116
+ manufacturer: { "@id": entityIds(origin).organization },
117
+ ...(product.category !== undefined ? { category: product.category } : {}),
118
+ image: product.images,
119
+ ...(product.sku !== undefined ? { sku: product.sku } : {}),
120
+ ...(product.gtin13 !== undefined ? { gtin13: product.gtin13 } : {}),
121
+ ...(product.netContent ? { weight: schemaWeight(product.netContent) } : {}),
122
+ url: product.url,
123
+ };
124
+ }
125
+
126
+ const pageEntityId = (pageUrl: string, fragment: string) => `${pageUrl.replace(/\/$/, "")}#${fragment}`;
127
+
128
+ export function faqPageLd(faqs: { question: string; answer: string }[], pageUrl: string) {
129
+ return {
130
+ "@context": "https://schema.org",
131
+ "@id": pageEntityId(pageUrl, "faq"),
132
+ "@type": "FAQPage",
133
+ mainEntity: faqs.map((faq) => ({
134
+ "@type": "Question",
135
+ name: faq.question,
136
+ acceptedAnswer: { "@type": "Answer", text: faq.answer },
137
+ })),
138
+ };
139
+ }
140
+
141
+ export function breadcrumbLd(items: { name: string; url?: string }[], pageUrl: string) {
142
+ return {
143
+ "@context": "https://schema.org",
144
+ "@id": pageEntityId(pageUrl, "breadcrumb"),
145
+ "@type": "BreadcrumbList",
146
+ itemListElement: items.map((item, index) => ({
147
+ "@type": "ListItem",
148
+ position: index + 1,
149
+ name: item.name,
150
+ ...(item.url ? { item: item.url } : {}),
151
+ })),
152
+ };
153
+ }