@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,62 @@
1
+ import { jsonLdGraph, type JsonLdNode } from "./jsonLd.js";
2
+ import { serializeJsonLd } from "./serializeJsonLd.js";
3
+ import { canonicalUrlForRoute, hreflangLinksForRoute, type SiteRoute } from "./urls.js";
4
+
5
+ export type HeadTag =
6
+ | { kind: "meta"; name: string; content: string }
7
+ | { kind: "meta"; property: string; content: string }
8
+ | { kind: "link"; rel: "canonical" | "alternate"; href: string; hrefLang?: string };
9
+
10
+ export interface HeadFacts {
11
+ origin: string;
12
+ route: SiteRoute;
13
+ routes: readonly SiteRoute[];
14
+ xDefaultLocale: string;
15
+ htmlLang: string;
16
+ title: string;
17
+ description: string;
18
+ siteName: string;
19
+ ogImage: string;
20
+ ogImageWidth: number;
21
+ ogImageHeight: number;
22
+ ogLocale: string;
23
+ alternateOgLocale?: string;
24
+ twitterImage: string;
25
+ twitterHandle: string;
26
+ noindex?: boolean;
27
+ jsonLd?: JsonLdNode | JsonLdNode[];
28
+ }
29
+
30
+ export function buildHeadDescriptor(facts: HeadFacts): { htmlLang: string; title: string; tags: HeadTag[]; jsonLd: string | null } {
31
+ const canonicalUrl = canonicalUrlForRoute(facts.origin, facts.route);
32
+ const nodes = facts.jsonLd ? (Array.isArray(facts.jsonLd) ? facts.jsonLd : [facts.jsonLd]) : [];
33
+ const tags: HeadTag[] = [
34
+ { kind: "meta", name: "description", content: facts.description },
35
+ { kind: "link", rel: "canonical", href: canonicalUrl },
36
+ ...(facts.noindex ? [{ kind: "meta" as const, name: "robots", content: "noindex, nofollow" }] : []),
37
+ { kind: "meta", property: "og:title", content: facts.title },
38
+ { kind: "meta", property: "og:description", content: facts.description },
39
+ { kind: "meta", property: "og:image", content: facts.ogImage },
40
+ { kind: "meta", property: "og:image:width", content: String(facts.ogImageWidth) },
41
+ { kind: "meta", property: "og:image:height", content: String(facts.ogImageHeight) },
42
+ { kind: "meta", property: "og:type", content: "website" },
43
+ { kind: "meta", property: "og:site_name", content: facts.siteName },
44
+ { kind: "meta", property: "og:url", content: canonicalUrl },
45
+ { kind: "meta", property: "og:locale", content: facts.ogLocale },
46
+ ...(facts.alternateOgLocale ? [{ kind: "meta" as const, property: "og:locale:alternate", content: facts.alternateOgLocale }] : []),
47
+ { kind: "meta", name: "twitter:card", content: "summary_large_image" },
48
+ { kind: "meta", name: "twitter:site", content: facts.twitterHandle },
49
+ { kind: "meta", name: "twitter:title", content: facts.title },
50
+ { kind: "meta", name: "twitter:description", content: facts.description },
51
+ { kind: "meta", name: "twitter:image", content: facts.twitterImage },
52
+ ...hreflangLinksForRoute(facts.origin, facts.route, facts.routes, facts.xDefaultLocale).map((link) => ({
53
+ kind: "link" as const, rel: "alternate" as const, hrefLang: link.hrefLang, href: link.href,
54
+ })),
55
+ ];
56
+ return {
57
+ htmlLang: facts.htmlLang,
58
+ title: facts.title,
59
+ tags,
60
+ jsonLd: nodes.length > 0 ? serializeJsonLd(jsonLdGraph(...nodes)) : null,
61
+ };
62
+ }
@@ -0,0 +1,6 @@
1
+ export function serializeJsonLd(value: object): string {
2
+ return JSON.stringify(value)
3
+ .replace(/</g, "\\u003c")
4
+ .replace(/\u2028/g, "\\u2028")
5
+ .replace(/\u2029/g, "\\u2029");
6
+ }
@@ -0,0 +1,34 @@
1
+ export interface SiteRoute {
2
+ id: string;
3
+ locale: string;
4
+ canonicalPath: string;
5
+ alternateRouteId?: string;
6
+ }
7
+
8
+ export interface HreflangLink { hrefLang: string; href: string }
9
+
10
+ export function normalizeSitePath(pathname: string): string {
11
+ const path = pathname.startsWith("/") ? pathname : `/${pathname}`;
12
+ return path.length > 1 ? path.replace(/\/$/, "") : path;
13
+ }
14
+
15
+ export function absoluteSiteUrl(origin: string, pathname: string): string {
16
+ const site = origin.replace(/\/$/, "");
17
+ const path = normalizeSitePath(pathname);
18
+ return path === "/" ? `${site}/` : `${site}${path}`;
19
+ }
20
+
21
+ export function canonicalUrlForRoute(origin: string, route: SiteRoute): string {
22
+ return absoluteSiteUrl(origin, route.canonicalPath);
23
+ }
24
+
25
+ export function hreflangLinksForRoute(origin: string, route: SiteRoute, routes: readonly SiteRoute[], xDefaultLocale: string): HreflangLink[] {
26
+ const alternate = route.alternateRouteId ? routes.find((candidate) => candidate.id === route.alternateRouteId) : undefined;
27
+ if (!alternate) return [];
28
+ const pair = [route, alternate].sort((a, b) => a.locale.localeCompare(b.locale));
29
+ const preferred = pair.find((candidate) => candidate.locale === xDefaultLocale);
30
+ return [
31
+ ...pair.map((candidate) => ({ hrefLang: candidate.locale, href: canonicalUrlForRoute(origin, candidate) })),
32
+ { hrefLang: "x-default", href: canonicalUrlForRoute(origin, preferred ?? pair[0]) },
33
+ ];
34
+ }
@@ -0,0 +1,67 @@
1
+ import type { HttpRequest, HttpResponse } from "../../http/index.js";
2
+ import type { BffResponder } from "../../bff/index.js";
3
+ import type { AcquisitionCaseDirectDeps, AcquisitionCaseBindingResolver } from "./directPorts.js";
4
+ import { ACQUISITION_CASE_VIEW, acquisitionCaseActiveCountResponseSchema, acquisitionCaseListRequestSchema, acquisitionCaseListResponseSchema } from "../acquisitionCaseSchemas.js";
5
+ import type { AcquisitionCaseFailureKind } from "../contracts/index.js";
6
+
7
+ export function createAcquisitionCaseListDirectHandler(options: AcquisitionCaseDirectDeps) {
8
+ const { respond, authorize, resolveBinding, isDirect } = options;
9
+ const { sendBffSuccess, sendMethodNotAllowed } = respond;
10
+ return async (req: HttpRequest, res: HttpResponse): Promise<void> => {
11
+ if (!isDirect() || first(req.query.view) !== ACQUISITION_CASE_VIEW) return unavailable(res, respond);
12
+ if (req.method !== "GET") return sendMethodNotAllowed(res, ["GET"]);
13
+ const actorRef = await authorize(req, res);
14
+ if (!actorRef) return;
15
+ const request = acquisitionCaseListRequestSchema.safeParse({
16
+ view: first(req.query.view), cursor: first(req.query.cursor), limit: integer(first(req.query.limit), 25),
17
+ });
18
+ if (!request.success) return badRequest(res, respond, request.error.flatten());
19
+ const binding = await bindingOrError(res, respond, resolveBinding);
20
+ if (!binding) return;
21
+ const result = await operationOrError(res, respond, () => binding.handlers.list(actorRef, request.data));
22
+ if (!result) return;
23
+ if (result.ok === false) return failure(res, respond, result.error.kind);
24
+ const response = acquisitionCaseListResponseSchema.safeParse(result.value);
25
+ if (!response.success) return invalidResponse(res, respond);
26
+ sendBffSuccess(res, response.data);
27
+ };
28
+ }
29
+
30
+ export function createAcquisitionCaseActiveCountDirectHandler(options: AcquisitionCaseDirectDeps) {
31
+ const { respond, resolveBinding, isDirect } = options;
32
+ const { sendBffSuccess, sendMethodNotAllowed } = respond;
33
+ return async (req: HttpRequest, res: HttpResponse): Promise<void> => {
34
+ if (!isDirect()) return unavailable(res, respond);
35
+ if (req.method !== "GET") return sendMethodNotAllowed(res, ["GET"]);
36
+ const binding = await bindingOrError(res, respond, resolveBinding);
37
+ if (!binding) return;
38
+ const result = await operationOrError(res, respond, () => binding.handlers.activeCount());
39
+ if (!result) return;
40
+ if (result.ok === false) return failure(res, respond, result.error.kind);
41
+ const response = acquisitionCaseActiveCountResponseSchema.safeParse(result.value);
42
+ if (!response.success) return invalidResponse(res, respond);
43
+ sendBffSuccess(res, response.data);
44
+ };
45
+ }
46
+
47
+ async function bindingOrError(res: HttpResponse, respond: BffResponder, resolve: AcquisitionCaseBindingResolver) {
48
+ try { const binding = await resolve(); if (binding) return binding; } catch { /* fail closed below */ }
49
+ respond.sendBffError(res, "UPSTREAM_UNAVAILABLE", "Acquisition case service unavailable");
50
+ return null;
51
+ }
52
+ async function operationOrError<T>(res: HttpResponse, respond: BffResponder, operation: () => Promise<T>): Promise<T | null> {
53
+ try { return await operation(); } catch { respond.sendBffError(res, "UPSTREAM_UNAVAILABLE", "Acquisition case service unavailable"); return null; }
54
+ }
55
+ function first(value: string | string[] | undefined): string | undefined { return Array.isArray(value) ? value[0] : value; }
56
+ function integer(value: string | undefined, fallback: number): number { return value === undefined ? fallback : Number(value); }
57
+ function badRequest(res: HttpResponse, respond: BffResponder, details?: unknown): void { respond.sendBffError(res, "BAD_REQUEST", "Invalid acquisition case request", { details }); }
58
+ function unavailable(res: HttpResponse, respond: BffResponder): void { respond.sendBffError(res, "NOT_FOUND", "Acquisition case unavailable"); }
59
+ function invalidResponse(res: HttpResponse, respond: BffResponder): void { respond.sendBffError(res, "INVALID_RESPONSE", "Acquisition case returned invalid response"); }
60
+ function failure(res: HttpResponse, respond: BffResponder, kind: AcquisitionCaseFailureKind): void {
61
+ if (kind === "invalid") return badRequest(res, respond);
62
+ if (kind === "conflict") return respond.sendBffError(res, "CONFLICT", "Acquisition case request conflicts with prior state");
63
+ if (kind === "rate_limited") return respond.sendBffError(res, "RATE_LIMITED", "Acquisition submission rate limited");
64
+ if (kind === "not_found") return unavailable(res, respond);
65
+ respond.sendBffError(res, "UPSTREAM_UNAVAILABLE", "Acquisition case service unavailable");
66
+ }
67
+
@@ -0,0 +1,57 @@
1
+ import { ACQUISITION_CASE_CONTRACT_VERSION, ACQUISITION_CASE_SOURCE } from "../acquisitionCaseSchemas.js";
2
+ import type { AcquisitionCaseListRequest } from "../contracts/index.js";
3
+ import { type AcquisitionCaseSubmitRequest, type AcquisitionCaseTransitionRequest } from "./acquisitionCasePorts.js";
4
+ import type { AcquisitionCasePort } from "./acquisitionCasePorts.js";
5
+
6
+ const SCOPE = "public_tester_application" as const;
7
+
8
+ export interface AcquisitionCaseHandlerOptions {
9
+ now?: () => string;
10
+ }
11
+
12
+ export function createAcquisitionCaseHandlers(
13
+ port: AcquisitionCasePort,
14
+ options: AcquisitionCaseHandlerOptions = {},
15
+ ) {
16
+ const now = options.now ?? (() => new Date().toISOString());
17
+ return {
18
+ submit(request: AcquisitionCaseSubmitRequest, context: {
19
+ idempotencyKey: string;
20
+ requesterKey: string;
21
+ }) {
22
+ return port.submit({
23
+ scope: SCOPE,
24
+ sourceKind: ACQUISITION_CASE_SOURCE,
25
+ idempotencyKey: context.idempotencyKey,
26
+ requesterKey: `${SCOPE}:${context.requesterKey}`,
27
+ acceptedAt: now(),
28
+ sourcePath: "/tester-application",
29
+ request,
30
+ });
31
+ },
32
+ list(actorRef: string, request: AcquisitionCaseListRequest) {
33
+ return port.list({
34
+ actorRef,
35
+ scope: SCOPE,
36
+ ...(request.cursor ? { cursor: request.cursor } : {}),
37
+ limit: request.limit,
38
+ });
39
+ },
40
+ get(actorRef: string, caseRef: string) {
41
+ return port.get({ actorRef, scope: SCOPE, caseRef });
42
+ },
43
+ transition(actorRef: string, idempotencyKey: string, request: AcquisitionCaseTransitionRequest) {
44
+ return port.transition({ actorRef, scope: SCOPE, idempotencyKey, request });
45
+ },
46
+ async activeCount() {
47
+ const result = await port.activeCount(SCOPE);
48
+ return result.ok === false ? result : {
49
+ ok: true as const,
50
+ value: { activeTesterCount: result.value },
51
+ };
52
+ },
53
+ contractVersion: ACQUISITION_CASE_CONTRACT_VERSION,
54
+ };
55
+ }
56
+
57
+ export type AcquisitionCaseHandlers = ReturnType<typeof createAcquisitionCaseHandlers>;
@@ -0,0 +1,42 @@
1
+ import type { AcquisitionCaseProjection, AcquisitionCaseResult, AcquisitionCasePort as PortableAcquisitionCasePort } from "../contracts/index.js";
2
+ import type { AcquisitionAddressReference, AcquisitionCaseProjection as Projection } from "../contracts/index.js";
3
+
4
+ /** Historical commands retained by the server adapter; public admission routes remain host-owned. */
5
+ export interface AcquisitionCaseSubmitRequest {
6
+ contact: { email: string };
7
+ consent: { accepted: true; consentVersion: string; policyVersion: string; locale: Projection["consent"]["locale"] };
8
+ addressReference: AcquisitionAddressReference;
9
+ }
10
+ export interface AcquisitionCaseTransitionRequest {
11
+ view: "acquisition_case_v1";
12
+ caseRef: string;
13
+ expectedVersion: number;
14
+ transition: "approve" | "activate" | "reject" | "withdraw";
15
+ reason?: string | undefined;
16
+ }
17
+
18
+ export interface AcquisitionCaseSubmitCommand {
19
+ scope: "public_tester_application";
20
+ sourceKind: "tester_application";
21
+ idempotencyKey: string;
22
+ requesterKey: string;
23
+ acceptedAt: string;
24
+ sourcePath: "/tester-application";
25
+ request: AcquisitionCaseSubmitRequest;
26
+ }
27
+
28
+ export interface AcquisitionCaseTransitionCommand {
29
+ actorRef: string;
30
+ scope: "public_tester_application";
31
+ idempotencyKey: string;
32
+ request: AcquisitionCaseTransitionRequest;
33
+ }
34
+
35
+ export interface AcquisitionCasePort extends PortableAcquisitionCasePort {
36
+ submit(command: AcquisitionCaseSubmitCommand): Promise<AcquisitionCaseResult<AcquisitionCaseProjection>>;
37
+ transition(command: AcquisitionCaseTransitionCommand): Promise<AcquisitionCaseResult<AcquisitionCaseProjection>>;
38
+ }
39
+
40
+ export type {
41
+ AcquisitionCaseFailureKind, AcquisitionCaseResult, AcquisitionCaseListQuery, AcquisitionCaseGetQuery,
42
+ } from "../contracts/index.js";
@@ -0,0 +1,76 @@
1
+ import { acquisitionNewsletterConsentEventSchema, acquisitionSurveyListQuerySchema, acquisitionSurveySubmitSchema } from "../acquisitionEvidenceSchemas.js";
2
+ import type { HttpRequest, HttpResponse } from "../../http/index.js";
3
+ import type { BffResponder } from "../../bff/index.js";
4
+ import type { AcquisitionEvidenceFailure } from "../contracts/index.js";
5
+ import type { AcquisitionEvidenceDirectDeps, AcquisitionEvidenceBindingResolver } from "./directPorts.js";
6
+
7
+ export function createAcquisitionSurveySubmitDirectHandler(options: AcquisitionEvidenceDirectDeps) {
8
+ const { respond, resolveBinding } = options;
9
+ const { sendBffSuccess, sendMethodNotAllowed } = respond;
10
+ return async (req: HttpRequest, res: HttpResponse): Promise<void> => {
11
+ if (req.method !== "POST") return sendMethodNotAllowed(res, ["POST"]);
12
+ const request = acquisitionSurveySubmitSchema.safeParse(req.body);
13
+ const idempotencyKey = firstHeader(req.headers["idempotency-key"]);
14
+ if (!request.success || !idempotencyKey) return badRequest(res, respond, request.success ? undefined : request.error.flatten());
15
+ const binding = await bindingOrError(res, respond, resolveBinding); if (!binding) return;
16
+ const result = await safeOperation(() => binding.submitSurvey({ ...request.data, idempotencyKey }));
17
+ if (!result) return unavailable(res, respond);
18
+ if (result.ok === false) return failure(res, respond, result.error.kind);
19
+ sendBffSuccess(res, result.value);
20
+ };
21
+ }
22
+
23
+ export function createAcquisitionSurveyListDirectHandler(options: AcquisitionEvidenceDirectDeps) {
24
+ const { respond, authorize, resolveBinding } = options;
25
+ const { sendBffSuccess, sendMethodNotAllowed } = respond;
26
+ return async (req: HttpRequest, res: HttpResponse): Promise<void> => {
27
+ if (req.method !== "GET") return sendMethodNotAllowed(res, ["GET"]);
28
+ const actorReference = await authorize(req, res); if (!actorReference) return;
29
+ const request = acquisitionSurveyListQuerySchema.safeParse({
30
+ view: first(req.query.view), surveyType: first(req.query.surveyType), limit: first(req.query.limit) ?? "50",
31
+ });
32
+ if (!request.success) return badRequest(res, respond, request.error.flatten());
33
+ const binding = await bindingOrError(res, respond, resolveBinding); if (!binding) return;
34
+ const result = await safeOperation(() => binding.listSurveys({ ...request.data, actorReference }));
35
+ if (!result) return unavailable(res, respond);
36
+ if (result.ok === false) return failure(res, respond, result.error.kind);
37
+ sendBffSuccess(res, result.value);
38
+ };
39
+ }
40
+
41
+ export function createAcquisitionNewsletterConsentDirectHandler(options: AcquisitionEvidenceDirectDeps) {
42
+ const { respond, resolveBinding } = options;
43
+ const { sendBffSuccess } = respond;
44
+ return async (value: unknown, res: HttpResponse): Promise<void> => {
45
+ const request = acquisitionNewsletterConsentEventSchema.safeParse(value);
46
+ if (!request.success) return badRequest(res, respond, request.error.flatten());
47
+ const binding = await bindingOrError(res, respond, resolveBinding); if (!binding) return;
48
+ const result = await safeOperation(() => binding.applyNewsletterConsent(request.data));
49
+ if (!result) return unavailable(res, respond);
50
+ if (result.ok === false) return failure(res, respond, result.error.kind);
51
+ sendBffSuccess(res, result.value);
52
+ };
53
+ }
54
+
55
+ async function bindingOrError(res: HttpResponse, respond: BffResponder, resolve: AcquisitionEvidenceBindingResolver) {
56
+ try { const binding = await resolve(); if (binding) return binding; }
57
+ catch { /* fail closed below */ }
58
+ unavailable(res, respond); return null;
59
+ }
60
+ async function safeOperation<T>(work: () => Promise<T>): Promise<T | null> {
61
+ try { return await work(); } catch { return null; }
62
+ }
63
+ function failure(res: HttpResponse, respond: BffResponder, kind: AcquisitionEvidenceFailure): void {
64
+ if (kind === "invalid") return badRequest(res, respond);
65
+ if (kind === "not_found") return respond.sendBffError(res, "NOT_FOUND", "Acquisition evidence subject not found");
66
+ if (kind === "conflict") return respond.sendBffError(res, "CONFLICT", "Acquisition evidence request conflicts with prior state");
67
+ unavailable(res, respond);
68
+ }
69
+ function badRequest(res: HttpResponse, respond: BffResponder, details?: unknown): void {
70
+ respond.sendBffError(res, "BAD_REQUEST", "Invalid acquisition evidence request", { details });
71
+ }
72
+ function unavailable(res: HttpResponse, respond: BffResponder): void {
73
+ respond.sendBffError(res, "UPSTREAM_UNAVAILABLE", "Acquisition evidence service unavailable");
74
+ }
75
+ function first(value: string | string[] | undefined): string | undefined { return Array.isArray(value) ? value[0] : value; }
76
+ function firstHeader(value: string | string[] | undefined): string | undefined { return first(value); }
@@ -0,0 +1,55 @@
1
+ import { z } from "../validation.js";
2
+ import type { HttpRequest, HttpResponse } from "../../http/index.js";
3
+ import type { AnalyticsContextHandlerDeps } from "./analyticsContextPorts.js";
4
+
5
+ export function createAnalyticsContextHandler(deps: AnalyticsContextHandlerDeps) {
6
+ const { respond, isEnabled, resolveStore, readAccessToken, resolveTrustedSubject, capabilityCrypto, cookieName, clientIdField } = deps;
7
+ const { sendBffError, sendBffSuccess, sendMethodNotAllowed } = respond;
8
+ const requestSchema = z.object({
9
+ granted: z.boolean(),
10
+ [clientIdField]: z.string().regex(/^\d+\.\d+$/).max(64).optional(),
11
+ explicitGrant: z.boolean().default(false),
12
+ }).strict();
13
+ return async (req: HttpRequest, res: HttpResponse): Promise<void> => {
14
+ if (req.method !== "POST") return sendMethodNotAllowed(res, ["POST"]);
15
+ if (!isEnabled()) return sendBffError(res, "NOT_FOUND", "Analytics context unavailable");
16
+ // No URL, IP, contact, session, form or account data is accepted or logged.
17
+ const origin = typeof req.headers.origin === "string" ? req.headers.origin : "";
18
+ if (!origin || origin !== `https://${req.headers.host}`) return sendBffError(res, "FORBIDDEN", "Same-origin request required");
19
+ const parsed = requestSchema.safeParse(req.body);
20
+ const clientId = parsed.success ? parsed.data[clientIdField] as string | undefined : undefined;
21
+ if (!parsed.success || (parsed.data.granted && !clientId)) return sendBffError(res, "BAD_REQUEST", "Invalid analytics context");
22
+ const store = resolveStore();
23
+ if (!store) return sendBffError(res, "UPSTREAM_UNAVAILABLE", "Analytics context unavailable");
24
+ // The computed shape key widens inference; the strict schema validates these fixed fields.
25
+ const data = parsed.data as { granted: boolean; explicitGrant: boolean };
26
+ let hash = contextHash(typeof req.headers.cookie === "string" ? req.headers.cookie : undefined, cookieName, (value) => capabilityCrypto.hashToken(value));
27
+ // Explicit user re-consent gets a new capability; withdrawn old bindings stay withdrawn.
28
+ let token: string | null = null;
29
+ if (data.granted && !hash) {
30
+ token = capabilityCrypto.mintToken();
31
+ hash = capabilityCrypto.hashToken(token);
32
+ }
33
+ if (!hash) { sendBffSuccess(res, { active: false }); return; }
34
+ try {
35
+ const accessToken = readAccessToken(req);
36
+ const subject = data.granted && accessToken ? await resolveTrustedSubject(accessToken) : null;
37
+ if (accessToken && data.granted && !subject) return sendBffError(res, "UNAUTHORIZED", "Customer session required");
38
+ let active = await store.syncContext({ tokenHash: hash, granted: data.granted, clientId: clientId ?? null });
39
+ if (active !== true && data.granted && data.explicitGrant && !token) {
40
+ token = capabilityCrypto.mintToken();
41
+ hash = capabilityCrypto.hashToken(token);
42
+ active = await store.syncContext({ tokenHash: hash, granted: true, clientId: clientId! });
43
+ }
44
+ if (active === true && subject) await store.enrollSubscriptions({ subject, contextHash: hash });
45
+ if (token && active === true) res.setHeader("Set-Cookie", `${cookieName}=${token}; Path=/; Max-Age=31536000; HttpOnly; Secure; SameSite=Lax`);
46
+ res.setHeader("Cache-Control", "no-store");
47
+ sendBffSuccess(res, { active: active === true });
48
+ } catch { sendBffError(res, "UPSTREAM_UNAVAILABLE", "Analytics context unavailable"); }
49
+ };
50
+ }
51
+
52
+ function contextHash(cookie: string | undefined, cookieName: string, hashToken: (token: string) => string): string | null {
53
+ const token = cookie?.split(";").map((part) => part.trim()).find((part) => part.startsWith(`${cookieName}=`))?.split("=")[1];
54
+ return token && /^[a-f0-9]{64}$/.test(token) ? hashToken(token) : null;
55
+ }
@@ -0,0 +1,28 @@
1
+ import type { HttpRequest } from "../../http/index.js";
2
+ import type { BffResponder } from "../../bff/index.js";
3
+
4
+ /** Host persistence rejects on failure; only literal true means an active context. */
5
+ export interface AnalyticsContextPersistencePort {
6
+ syncContext(input: { tokenHash: string; granted: boolean; clientId: string | null }): Promise<unknown>;
7
+ enrollSubscriptions(input: { subject: string; contextHash: string }): Promise<unknown>;
8
+ }
9
+
10
+ export type AnalyticsContextStoreResolver = () => AnalyticsContextPersistencePort | null;
11
+
12
+ /** The host supplies opaque 32-byte hexadecimal tokens and their cryptographic hash. */
13
+ export interface AnalyticsContextCapabilityCrypto {
14
+ mintToken(): string;
15
+ hashToken(token: string): string;
16
+ }
17
+
18
+ export interface AnalyticsContextHandlerDeps {
19
+ respond: BffResponder;
20
+ isEnabled: () => boolean;
21
+ resolveStore: AnalyticsContextStoreResolver;
22
+ readAccessToken: (req: HttpRequest) => string | null;
23
+ resolveTrustedSubject: (accessToken: string) => Promise<string | null>;
24
+ capabilityCrypto: AnalyticsContextCapabilityCrypto;
25
+ cookieName: string;
26
+ /** Historical request field name supplied by the host. */
27
+ clientIdField: string;
28
+ }
@@ -0,0 +1,27 @@
1
+ import type { ReadinessIssue } from "@openlup/core/readiness";
2
+ import { createMarketingPrivacyContributor, type MarketingPrivacyContributor, type MarketingPrivacyDependencies } from "./privacyContributor.js";
3
+
4
+ /** Select one fully bound privacy contributor; absent activation leaves the host registry unchanged. */
5
+ export function createMarketingPrivacyBindings<Context>(input: MarketingPrivacyDependencies<Context> & { enabled?: boolean }): {
6
+ contributor: MarketingPrivacyContributor<Context> | null;
7
+ issues: ReadinessIssue[];
8
+ callables: Readonly<{
9
+ exportPersonalData: MarketingPrivacyContributor<Context>["export"] | null;
10
+ assessErasure: MarketingPrivacyContributor<Context>["assessErasure"] | null;
11
+ eraseOrRetain: MarketingPrivacyContributor<Context>["eraseOrRetain"] | null;
12
+ }>;
13
+ } {
14
+ const acquisition = input.acquisition && [input.acquisition.export, input.acquisition.assessErasure, input.acquisition.eraseOrRetain].every(fn => typeof fn === "function") ? input.acquisition : null;
15
+ const remoteErasure = input.remoteErasure && [input.remoteErasure.read, input.remoteErasure.openAndFence].every(fn => typeof fn === "function") ? input.remoteErasure : null;
16
+ const issues: ReadinessIssue[] = [];
17
+ for (const [name, port] of [["acquisition", acquisition], ["remoteErasure", remoteErasure]] as const) {
18
+ if (!port) issues.push({ code: "OPENLUP_E_PORT_MISSING", package: "@openlup/platform", module: "marketing", subject: name, fix: `Bind the marketing ${name} owner port.` });
19
+ }
20
+ const selected = input.enabled === true && issues.length === 0
21
+ ? createMarketingPrivacyContributor({ ...input, acquisition, remoteErasure }) : null;
22
+ return { contributor: selected, issues, callables: Object.freeze({
23
+ exportPersonalData: selected ? selected.export : null,
24
+ assessErasure: selected ? selected.assessErasure : null,
25
+ eraseOrRetain: selected ? selected.eraseOrRetain : null,
26
+ }) };
27
+ }
@@ -0,0 +1,27 @@
1
+ import type { HttpRequest, HttpResponse } from "../../http/index.js";
2
+ import type { BffResponder } from "../../bff/index.js";
3
+ import type { AcquisitionCaseHandlers } from "./acquisitionCaseHandlers.js";
4
+ import type { AcquisitionEvidencePort } from "../contracts/index.js";
5
+
6
+ export interface AcquisitionCaseReadBinding {
7
+ handlers: Pick<AcquisitionCaseHandlers, "list" | "get" | "activeCount">;
8
+ }
9
+ export type AcquisitionCaseBindingResolver = () => Promise<AcquisitionCaseReadBinding | null>;
10
+ export type AcquisitionEvidenceBindingResolver = () => Promise<AcquisitionEvidencePort | null>;
11
+ export type AcquisitionAuthorize = (req: HttpRequest, res: HttpResponse) => Promise<string | null>;
12
+ export interface AcquisitionCaseDirectDeps {
13
+ respond: BffResponder;
14
+ authorize: AcquisitionAuthorize;
15
+ resolveBinding: AcquisitionCaseBindingResolver;
16
+ isDirect: () => boolean;
17
+ }
18
+ export interface PrelaunchAcquisitionDirectDeps {
19
+ respond: BffResponder;
20
+ authorize: AcquisitionAuthorize;
21
+ resolveBinding: AcquisitionCaseBindingResolver;
22
+ }
23
+ export interface AcquisitionEvidenceDirectDeps {
24
+ respond: BffResponder;
25
+ authorize: AcquisitionAuthorize;
26
+ resolveBinding: AcquisitionEvidenceBindingResolver;
27
+ }
@@ -0,0 +1,14 @@
1
+ /** Node-only acquisition and research algorithms. Hosts own routing, authorization and presentation. */
2
+ export * from "./acquisitionCaseHandlers.js";
3
+ export type * from "./acquisitionCasePorts.js";
4
+ export type * from "./directPorts.js";
5
+ export * from "./acquisitionCaseDirect.js";
6
+ export * from "./prelaunchAcquisitionDirect.js";
7
+ export * from "./acquisitionEvidenceDirect.js";
8
+ export * from "./research/surveyResponseSubmitHandler.js";
9
+ export * from "./research/adminSurveyResponsesHandler.js";
10
+ export * from "./research/managedSurveyResponseSubmit.js";
11
+ export { createAnalyticsContextHandler } from "./analyticsContext.js";
12
+ export type * from "./analyticsContextPorts.js";
13
+ export * from "./privacyContributor.js";
14
+ export * from "./bindings.js";