@openlup/platform 0.28.0 → 0.29.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 (124) hide show
  1. package/CHANGELOG.md +219 -18
  2. package/README.md +143 -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/marketing/acquisitionCaseSchemas.d.ts +103 -0
  8. package/dist/marketing/acquisitionCaseSchemas.js +53 -0
  9. package/dist/marketing/acquisitionEvidenceSchemas.d.ts +105 -0
  10. package/dist/marketing/acquisitionEvidenceSchemas.js +55 -0
  11. package/dist/marketing/analytics/dataLayer.d.ts +18 -0
  12. package/dist/marketing/analytics/dataLayer.js +111 -0
  13. package/dist/marketing/analytics/noop.d.ts +9 -0
  14. package/dist/marketing/analytics/noop.js +8 -0
  15. package/dist/marketing/analytics/purchaseFacts.d.ts +4 -0
  16. package/dist/marketing/analytics/purchaseFacts.js +69 -0
  17. package/dist/marketing/analytics/routePolicy.d.ts +10 -0
  18. package/dist/marketing/analytics/routePolicy.js +59 -0
  19. package/dist/marketing/consentEvidence.d.ts +8 -0
  20. package/dist/marketing/consentEvidence.js +32 -0
  21. package/dist/marketing/contactLegal.d.ts +14 -0
  22. package/dist/marketing/contactLegal.js +19 -0
  23. package/dist/marketing/contracts/acquisition.d.ts +88 -0
  24. package/dist/marketing/contracts/acquisition.js +1 -0
  25. package/dist/marketing/contracts/acquisitionPorts.d.ts +49 -0
  26. package/dist/marketing/contracts/acquisitionPorts.js +1 -0
  27. package/dist/marketing/contracts/analytics.d.ts +144 -0
  28. package/dist/marketing/contracts/analytics.js +1 -0
  29. package/dist/marketing/contracts/contactLegal.d.ts +53 -0
  30. package/dist/marketing/contracts/contactLegal.js +1 -0
  31. package/dist/marketing/contracts/index.d.ts +6 -0
  32. package/dist/marketing/contracts/index.js +1 -0
  33. package/dist/marketing/contracts/prelaunch.d.ts +39 -0
  34. package/dist/marketing/contracts/prelaunch.js +1 -0
  35. package/dist/marketing/index.d.ts +16 -0
  36. package/dist/marketing/index.js +14 -0
  37. package/dist/marketing/prelaunchAcquisitionSchemas.d.ts +116 -0
  38. package/dist/marketing/prelaunchAcquisitionSchemas.js +51 -0
  39. package/dist/marketing/seo/jsonLd.d.ts +157 -0
  40. package/dist/marketing/seo/jsonLd.js +127 -0
  41. package/dist/marketing/seo/metadata.d.ts +41 -0
  42. package/dist/marketing/seo/metadata.js +36 -0
  43. package/dist/marketing/seo/serializeJsonLd.d.ts +1 -0
  44. package/dist/marketing/seo/serializeJsonLd.js +6 -0
  45. package/dist/marketing/seo/urls.d.ts +14 -0
  46. package/dist/marketing/seo/urls.js +23 -0
  47. package/dist/marketing/server/acquisitionCaseDirect.d.ts +4 -0
  48. package/dist/marketing/server/acquisitionCaseDirect.js +88 -0
  49. package/dist/marketing/server/acquisitionCaseHandlers.d.ts +28 -0
  50. package/dist/marketing/server/acquisitionCaseHandlers.js +40 -0
  51. package/dist/marketing/server/acquisitionCasePorts.d.ts +42 -0
  52. package/dist/marketing/server/acquisitionCasePorts.js +1 -0
  53. package/dist/marketing/server/acquisitionEvidenceDirect.d.ts +5 -0
  54. package/dist/marketing/server/acquisitionEvidenceDirect.js +100 -0
  55. package/dist/marketing/server/analyticsContext.d.ts +3 -0
  56. package/dist/marketing/server/analyticsContext.js +65 -0
  57. package/dist/marketing/server/analyticsContextPorts.d.ts +31 -0
  58. package/dist/marketing/server/analyticsContextPorts.js +1 -0
  59. package/dist/marketing/server/bindings.d.ts +14 -0
  60. package/dist/marketing/server/bindings.js +18 -0
  61. package/dist/marketing/server/directPorts.d.ts +26 -0
  62. package/dist/marketing/server/directPorts.js +1 -0
  63. package/dist/marketing/server/index.d.ts +14 -0
  64. package/dist/marketing/server/index.js +11 -0
  65. package/dist/marketing/server/postgres/acquisitionCaseRoutines.d.ts +10 -0
  66. package/dist/marketing/server/postgres/acquisitionCaseRoutines.js +204 -0
  67. package/dist/marketing/server/postgres/acquisitionEvidenceRoutines.d.ts +10 -0
  68. package/dist/marketing/server/postgres/acquisitionEvidenceRoutines.js +107 -0
  69. package/dist/marketing/server/postgres/index.d.ts +3 -0
  70. package/dist/marketing/server/postgres/index.js +3 -0
  71. package/dist/marketing/server/prelaunchAcquisitionDirect.d.ts +4 -0
  72. package/dist/marketing/server/prelaunchAcquisitionDirect.js +122 -0
  73. package/dist/marketing/server/privacyContributor.d.ts +66 -0
  74. package/dist/marketing/server/privacyContributor.js +87 -0
  75. package/dist/marketing/server/research/adminSurveyResponsesHandler.d.ts +9 -0
  76. package/dist/marketing/server/research/adminSurveyResponsesHandler.js +53 -0
  77. package/dist/marketing/server/research/managedSurveyResponseSubmit.d.ts +39 -0
  78. package/dist/marketing/server/research/managedSurveyResponseSubmit.js +102 -0
  79. package/dist/marketing/server/research/surveyResponseSubmitHandler.d.ts +8 -0
  80. package/dist/marketing/server/research/surveyResponseSubmitHandler.js +41 -0
  81. package/dist/marketing/validation.d.ts +2 -0
  82. package/dist/marketing/validation.js +3 -0
  83. package/package.json +22 -2
  84. package/release-gates.json +72 -4
  85. package/src/composition/index.ts +1 -0
  86. package/src/composition/marketingContribution.ts +37 -0
  87. package/src/marketing/acquisitionCaseSchemas.ts +75 -0
  88. package/src/marketing/acquisitionEvidenceSchemas.ts +72 -0
  89. package/src/marketing/analytics/dataLayer.ts +100 -0
  90. package/src/marketing/analytics/noop.ts +14 -0
  91. package/src/marketing/analytics/purchaseFacts.ts +63 -0
  92. package/src/marketing/analytics/routePolicy.ts +55 -0
  93. package/src/marketing/consentEvidence.ts +36 -0
  94. package/src/marketing/contactLegal.ts +22 -0
  95. package/src/marketing/contracts/acquisition.ts +50 -0
  96. package/src/marketing/contracts/acquisitionPorts.ts +48 -0
  97. package/src/marketing/contracts/analytics.ts +88 -0
  98. package/src/marketing/contracts/contactLegal.ts +41 -0
  99. package/src/marketing/contracts/index.ts +17 -0
  100. package/src/marketing/contracts/prelaunch.ts +15 -0
  101. package/src/marketing/index.ts +16 -0
  102. package/src/marketing/prelaunchAcquisitionSchemas.ts +64 -0
  103. package/src/marketing/seo/jsonLd.ts +153 -0
  104. package/src/marketing/seo/metadata.ts +62 -0
  105. package/src/marketing/seo/serializeJsonLd.ts +6 -0
  106. package/src/marketing/seo/urls.ts +34 -0
  107. package/src/marketing/server/acquisitionCaseDirect.ts +67 -0
  108. package/src/marketing/server/acquisitionCaseHandlers.ts +57 -0
  109. package/src/marketing/server/acquisitionCasePorts.ts +42 -0
  110. package/src/marketing/server/acquisitionEvidenceDirect.ts +76 -0
  111. package/src/marketing/server/analyticsContext.ts +55 -0
  112. package/src/marketing/server/analyticsContextPorts.ts +28 -0
  113. package/src/marketing/server/bindings.ts +27 -0
  114. package/src/marketing/server/directPorts.ts +27 -0
  115. package/src/marketing/server/index.ts +14 -0
  116. package/src/marketing/server/postgres/acquisitionCaseRoutines.ts +218 -0
  117. package/src/marketing/server/postgres/acquisitionEvidenceRoutines.ts +103 -0
  118. package/src/marketing/server/postgres/index.ts +3 -0
  119. package/src/marketing/server/prelaunchAcquisitionDirect.ts +121 -0
  120. package/src/marketing/server/privacyContributor.ts +123 -0
  121. package/src/marketing/server/research/adminSurveyResponsesHandler.ts +78 -0
  122. package/src/marketing/server/research/managedSurveyResponseSubmit.ts +158 -0
  123. package/src/marketing/server/research/surveyResponseSubmitHandler.ts +57 -0
  124. package/src/marketing/validation.ts +3 -0
@@ -0,0 +1,157 @@
1
+ import type { OrganizationFacts } from "../contracts/contactLegal.js";
2
+ export type JsonLdNode = Record<string, unknown> & {
3
+ "@context"?: string;
4
+ "@id"?: string;
5
+ };
6
+ export declare function jsonLdGraph(...nodes: JsonLdNode[]): {
7
+ "@context": string;
8
+ "@graph": {
9
+ [x: string]: unknown;
10
+ "@id"?: string;
11
+ }[];
12
+ };
13
+ export declare function entityIds(origin: string): {
14
+ organization: string;
15
+ website: string;
16
+ brand: string;
17
+ };
18
+ export declare function organizationLd(origin: string, type: "Organization" | "OnlineStore", facts: OrganizationFacts): {
19
+ "@context": string;
20
+ "@id": string;
21
+ "@type": "Organization" | "OnlineStore";
22
+ name: string;
23
+ legalName: string;
24
+ url: string;
25
+ logo: {
26
+ "@type": string;
27
+ url: string;
28
+ contentUrl: string;
29
+ width: number;
30
+ height: number;
31
+ };
32
+ email: string;
33
+ vatID: string;
34
+ taxID: string;
35
+ areaServed: string;
36
+ sameAs: string[];
37
+ contactPoint: {
38
+ "@type": string;
39
+ email: string;
40
+ contactType: string;
41
+ availableLanguage: string[];
42
+ };
43
+ address: {
44
+ "@type": string;
45
+ streetAddress: string;
46
+ addressLocality: string;
47
+ postalCode: string;
48
+ addressRegion: string;
49
+ addressCountry: string;
50
+ };
51
+ };
52
+ export declare function brandLd(origin: string, name: string, url: string): {
53
+ "@context": string;
54
+ "@id": string;
55
+ "@type": string;
56
+ name: string;
57
+ url: string;
58
+ };
59
+ export declare function websiteLd(origin: string, name: string, url: string, inLanguage: string[]): {
60
+ "@context": string;
61
+ "@id": string;
62
+ "@type": string;
63
+ name: string;
64
+ url: string;
65
+ inLanguage: string[];
66
+ publisher: {
67
+ "@id": string;
68
+ };
69
+ };
70
+ export declare function contactPageLd(origin: string, pageUrl: string): {
71
+ "@context": string;
72
+ "@id": string;
73
+ "@type": string;
74
+ url: string;
75
+ publisher: {
76
+ "@id": string;
77
+ };
78
+ mainEntity: {
79
+ "@id": string;
80
+ };
81
+ };
82
+ export interface NetContent {
83
+ unscaled: number;
84
+ scale: number;
85
+ unit: string;
86
+ }
87
+ export declare function schemaWeight(netContent: NetContent): {
88
+ "@type": string;
89
+ value: number;
90
+ unitCode: string;
91
+ };
92
+ export interface ProductFacts {
93
+ url: string;
94
+ name: string;
95
+ inLanguage: string;
96
+ brandName: string;
97
+ category?: string;
98
+ images: string[];
99
+ sku?: string;
100
+ gtin13?: string;
101
+ netContent?: NetContent;
102
+ }
103
+ export declare function productLd(origin: string, product: ProductFacts): {
104
+ url: string;
105
+ weight?: {
106
+ "@type": string;
107
+ value: number;
108
+ unitCode: string;
109
+ } | undefined;
110
+ gtin13?: string | undefined;
111
+ sku?: string | undefined;
112
+ image: string[];
113
+ category?: string | undefined;
114
+ "@context": string;
115
+ "@id": string;
116
+ "@type": string;
117
+ name: string;
118
+ inLanguage: string;
119
+ brand: {
120
+ "@id": string;
121
+ "@type": string;
122
+ name: string;
123
+ };
124
+ manufacturer: {
125
+ "@id": string;
126
+ };
127
+ };
128
+ export declare function faqPageLd(faqs: {
129
+ question: string;
130
+ answer: string;
131
+ }[], pageUrl: string): {
132
+ "@context": string;
133
+ "@id": string;
134
+ "@type": string;
135
+ mainEntity: {
136
+ "@type": string;
137
+ name: string;
138
+ acceptedAnswer: {
139
+ "@type": string;
140
+ text: string;
141
+ };
142
+ }[];
143
+ };
144
+ export declare function breadcrumbLd(items: {
145
+ name: string;
146
+ url?: string;
147
+ }[], pageUrl: string): {
148
+ "@context": string;
149
+ "@id": string;
150
+ "@type": string;
151
+ itemListElement: {
152
+ item?: string | undefined;
153
+ "@type": string;
154
+ position: number;
155
+ name: string;
156
+ }[];
157
+ };
@@ -0,0 +1,127 @@
1
+ export function jsonLdGraph(...nodes) {
2
+ const seen = new Set();
3
+ const graph = nodes.flatMap(({ "@context": _context, ...node }) => {
4
+ if (node["@id"] && seen.has(node["@id"]))
5
+ return [];
6
+ if (node["@id"])
7
+ seen.add(node["@id"]);
8
+ return [node];
9
+ });
10
+ return { "@context": "https://schema.org", "@graph": graph };
11
+ }
12
+ export function entityIds(origin) {
13
+ const site = origin.replace(/\/$/, "");
14
+ return {
15
+ organization: `${site}/#organization`,
16
+ website: `${site}/#website`,
17
+ brand: `${site}/#brand`,
18
+ };
19
+ }
20
+ export function organizationLd(origin, type, facts) {
21
+ return {
22
+ "@context": "https://schema.org",
23
+ "@id": entityIds(origin).organization,
24
+ "@type": type,
25
+ name: facts.name,
26
+ legalName: facts.legalName,
27
+ url: facts.url,
28
+ logo: {
29
+ "@type": "ImageObject",
30
+ url: facts.logo.url,
31
+ contentUrl: facts.logo.contentUrl,
32
+ width: facts.logo.width,
33
+ height: facts.logo.height,
34
+ },
35
+ email: facts.email,
36
+ vatID: facts.vatID,
37
+ taxID: facts.taxID,
38
+ areaServed: facts.areaServed,
39
+ sameAs: facts.sameAs,
40
+ contactPoint: {
41
+ "@type": "ContactPoint",
42
+ email: facts.contactPoint.email,
43
+ contactType: facts.contactPoint.contactType,
44
+ availableLanguage: facts.contactPoint.availableLanguage,
45
+ },
46
+ address: {
47
+ "@type": "PostalAddress",
48
+ streetAddress: facts.address.streetAddress,
49
+ addressLocality: facts.address.addressLocality,
50
+ postalCode: facts.address.postalCode,
51
+ addressRegion: facts.address.addressRegion,
52
+ addressCountry: facts.address.addressCountry,
53
+ },
54
+ };
55
+ }
56
+ export function brandLd(origin, name, url) {
57
+ return { "@context": "https://schema.org", "@id": entityIds(origin).brand, "@type": "Brand", name, url };
58
+ }
59
+ export function websiteLd(origin, name, url, inLanguage) {
60
+ return {
61
+ "@context": "https://schema.org",
62
+ "@id": entityIds(origin).website,
63
+ "@type": "WebSite",
64
+ name,
65
+ url,
66
+ inLanguage,
67
+ publisher: { "@id": entityIds(origin).organization },
68
+ };
69
+ }
70
+ export function contactPageLd(origin, pageUrl) {
71
+ return {
72
+ "@context": "https://schema.org",
73
+ "@id": `${pageUrl.replace(/\/$/, "")}#webpage`,
74
+ "@type": "ContactPage",
75
+ url: pageUrl,
76
+ publisher: { "@id": entityIds(origin).organization },
77
+ mainEntity: { "@id": entityIds(origin).organization },
78
+ };
79
+ }
80
+ export function schemaWeight(netContent) {
81
+ const { unscaled, scale, unit } = netContent;
82
+ const unitCode = unit === "GRAM" || unit === "G" ? "GRM" : unit;
83
+ return { "@type": "QuantitativeValue", value: unscaled / 10 ** scale, unitCode };
84
+ }
85
+ export function productLd(origin, product) {
86
+ return {
87
+ "@context": "https://schema.org",
88
+ "@id": `${product.url.replace(/\/$/, "")}#product`,
89
+ "@type": "Product",
90
+ name: product.name,
91
+ inLanguage: product.inLanguage,
92
+ brand: { "@id": entityIds(origin).brand, "@type": "Brand", name: product.brandName },
93
+ manufacturer: { "@id": entityIds(origin).organization },
94
+ ...(product.category !== undefined ? { category: product.category } : {}),
95
+ image: product.images,
96
+ ...(product.sku !== undefined ? { sku: product.sku } : {}),
97
+ ...(product.gtin13 !== undefined ? { gtin13: product.gtin13 } : {}),
98
+ ...(product.netContent ? { weight: schemaWeight(product.netContent) } : {}),
99
+ url: product.url,
100
+ };
101
+ }
102
+ const pageEntityId = (pageUrl, fragment) => `${pageUrl.replace(/\/$/, "")}#${fragment}`;
103
+ export function faqPageLd(faqs, pageUrl) {
104
+ return {
105
+ "@context": "https://schema.org",
106
+ "@id": pageEntityId(pageUrl, "faq"),
107
+ "@type": "FAQPage",
108
+ mainEntity: faqs.map((faq) => ({
109
+ "@type": "Question",
110
+ name: faq.question,
111
+ acceptedAnswer: { "@type": "Answer", text: faq.answer },
112
+ })),
113
+ };
114
+ }
115
+ export function breadcrumbLd(items, pageUrl) {
116
+ return {
117
+ "@context": "https://schema.org",
118
+ "@id": pageEntityId(pageUrl, "breadcrumb"),
119
+ "@type": "BreadcrumbList",
120
+ itemListElement: items.map((item, index) => ({
121
+ "@type": "ListItem",
122
+ position: index + 1,
123
+ name: item.name,
124
+ ...(item.url ? { item: item.url } : {}),
125
+ })),
126
+ };
127
+ }
@@ -0,0 +1,41 @@
1
+ import { type JsonLdNode } from "./jsonLd.js";
2
+ import { type SiteRoute } from "./urls.js";
3
+ export type HeadTag = {
4
+ kind: "meta";
5
+ name: string;
6
+ content: string;
7
+ } | {
8
+ kind: "meta";
9
+ property: string;
10
+ content: string;
11
+ } | {
12
+ kind: "link";
13
+ rel: "canonical" | "alternate";
14
+ href: string;
15
+ hrefLang?: string;
16
+ };
17
+ export interface HeadFacts {
18
+ origin: string;
19
+ route: SiteRoute;
20
+ routes: readonly SiteRoute[];
21
+ xDefaultLocale: string;
22
+ htmlLang: string;
23
+ title: string;
24
+ description: string;
25
+ siteName: string;
26
+ ogImage: string;
27
+ ogImageWidth: number;
28
+ ogImageHeight: number;
29
+ ogLocale: string;
30
+ alternateOgLocale?: string;
31
+ twitterImage: string;
32
+ twitterHandle: string;
33
+ noindex?: boolean;
34
+ jsonLd?: JsonLdNode | JsonLdNode[];
35
+ }
36
+ export declare function buildHeadDescriptor(facts: HeadFacts): {
37
+ htmlLang: string;
38
+ title: string;
39
+ tags: HeadTag[];
40
+ jsonLd: string | null;
41
+ };
@@ -0,0 +1,36 @@
1
+ import { jsonLdGraph } from "./jsonLd.js";
2
+ import { serializeJsonLd } from "./serializeJsonLd.js";
3
+ import { canonicalUrlForRoute, hreflangLinksForRoute } from "./urls.js";
4
+ export function buildHeadDescriptor(facts) {
5
+ const canonicalUrl = canonicalUrlForRoute(facts.origin, facts.route);
6
+ const nodes = facts.jsonLd ? (Array.isArray(facts.jsonLd) ? facts.jsonLd : [facts.jsonLd]) : [];
7
+ const tags = [
8
+ { kind: "meta", name: "description", content: facts.description },
9
+ { kind: "link", rel: "canonical", href: canonicalUrl },
10
+ ...(facts.noindex ? [{ kind: "meta", name: "robots", content: "noindex, nofollow" }] : []),
11
+ { kind: "meta", property: "og:title", content: facts.title },
12
+ { kind: "meta", property: "og:description", content: facts.description },
13
+ { kind: "meta", property: "og:image", content: facts.ogImage },
14
+ { kind: "meta", property: "og:image:width", content: String(facts.ogImageWidth) },
15
+ { kind: "meta", property: "og:image:height", content: String(facts.ogImageHeight) },
16
+ { kind: "meta", property: "og:type", content: "website" },
17
+ { kind: "meta", property: "og:site_name", content: facts.siteName },
18
+ { kind: "meta", property: "og:url", content: canonicalUrl },
19
+ { kind: "meta", property: "og:locale", content: facts.ogLocale },
20
+ ...(facts.alternateOgLocale ? [{ kind: "meta", property: "og:locale:alternate", content: facts.alternateOgLocale }] : []),
21
+ { kind: "meta", name: "twitter:card", content: "summary_large_image" },
22
+ { kind: "meta", name: "twitter:site", content: facts.twitterHandle },
23
+ { kind: "meta", name: "twitter:title", content: facts.title },
24
+ { kind: "meta", name: "twitter:description", content: facts.description },
25
+ { kind: "meta", name: "twitter:image", content: facts.twitterImage },
26
+ ...hreflangLinksForRoute(facts.origin, facts.route, facts.routes, facts.xDefaultLocale).map((link) => ({
27
+ kind: "link", rel: "alternate", hrefLang: link.hrefLang, href: link.href,
28
+ })),
29
+ ];
30
+ return {
31
+ htmlLang: facts.htmlLang,
32
+ title: facts.title,
33
+ tags,
34
+ jsonLd: nodes.length > 0 ? serializeJsonLd(jsonLdGraph(...nodes)) : null,
35
+ };
36
+ }
@@ -0,0 +1 @@
1
+ export declare function serializeJsonLd(value: object): string;
@@ -0,0 +1,6 @@
1
+ export function serializeJsonLd(value) {
2
+ return JSON.stringify(value)
3
+ .replace(/</g, "\\u003c")
4
+ .replace(/\u2028/g, "\\u2028")
5
+ .replace(/\u2029/g, "\\u2029");
6
+ }
@@ -0,0 +1,14 @@
1
+ export interface SiteRoute {
2
+ id: string;
3
+ locale: string;
4
+ canonicalPath: string;
5
+ alternateRouteId?: string;
6
+ }
7
+ export interface HreflangLink {
8
+ hrefLang: string;
9
+ href: string;
10
+ }
11
+ export declare function normalizeSitePath(pathname: string): string;
12
+ export declare function absoluteSiteUrl(origin: string, pathname: string): string;
13
+ export declare function canonicalUrlForRoute(origin: string, route: SiteRoute): string;
14
+ export declare function hreflangLinksForRoute(origin: string, route: SiteRoute, routes: readonly SiteRoute[], xDefaultLocale: string): HreflangLink[];
@@ -0,0 +1,23 @@
1
+ export function normalizeSitePath(pathname) {
2
+ const path = pathname.startsWith("/") ? pathname : `/${pathname}`;
3
+ return path.length > 1 ? path.replace(/\/$/, "") : path;
4
+ }
5
+ export function absoluteSiteUrl(origin, pathname) {
6
+ const site = origin.replace(/\/$/, "");
7
+ const path = normalizeSitePath(pathname);
8
+ return path === "/" ? `${site}/` : `${site}${path}`;
9
+ }
10
+ export function canonicalUrlForRoute(origin, route) {
11
+ return absoluteSiteUrl(origin, route.canonicalPath);
12
+ }
13
+ export function hreflangLinksForRoute(origin, route, routes, xDefaultLocale) {
14
+ const alternate = route.alternateRouteId ? routes.find((candidate) => candidate.id === route.alternateRouteId) : undefined;
15
+ if (!alternate)
16
+ return [];
17
+ const pair = [route, alternate].sort((a, b) => a.locale.localeCompare(b.locale));
18
+ const preferred = pair.find((candidate) => candidate.locale === xDefaultLocale);
19
+ return [
20
+ ...pair.map((candidate) => ({ hrefLang: candidate.locale, href: canonicalUrlForRoute(origin, candidate) })),
21
+ { hrefLang: "x-default", href: canonicalUrlForRoute(origin, preferred ?? pair[0]) },
22
+ ];
23
+ }
@@ -0,0 +1,4 @@
1
+ import type { HttpRequest, HttpResponse } from "../../http/index.js";
2
+ import type { AcquisitionCaseDirectDeps } from "./directPorts.js";
3
+ export declare function createAcquisitionCaseListDirectHandler(options: AcquisitionCaseDirectDeps): (req: HttpRequest, res: HttpResponse) => Promise<void>;
4
+ export declare function createAcquisitionCaseActiveCountDirectHandler(options: AcquisitionCaseDirectDeps): (req: HttpRequest, res: HttpResponse) => Promise<void>;
@@ -0,0 +1,88 @@
1
+ import { ACQUISITION_CASE_VIEW, acquisitionCaseActiveCountResponseSchema, acquisitionCaseListRequestSchema, acquisitionCaseListResponseSchema } from "../acquisitionCaseSchemas.js";
2
+ export function createAcquisitionCaseListDirectHandler(options) {
3
+ const { respond, authorize, resolveBinding, isDirect } = options;
4
+ const { sendBffSuccess, sendMethodNotAllowed } = respond;
5
+ return async (req, res) => {
6
+ if (!isDirect() || first(req.query.view) !== ACQUISITION_CASE_VIEW)
7
+ return unavailable(res, respond);
8
+ if (req.method !== "GET")
9
+ return sendMethodNotAllowed(res, ["GET"]);
10
+ const actorRef = await authorize(req, res);
11
+ if (!actorRef)
12
+ return;
13
+ const request = acquisitionCaseListRequestSchema.safeParse({
14
+ view: first(req.query.view), cursor: first(req.query.cursor), limit: integer(first(req.query.limit), 25),
15
+ });
16
+ if (!request.success)
17
+ return badRequest(res, respond, request.error.flatten());
18
+ const binding = await bindingOrError(res, respond, resolveBinding);
19
+ if (!binding)
20
+ return;
21
+ const result = await operationOrError(res, respond, () => binding.handlers.list(actorRef, request.data));
22
+ if (!result)
23
+ return;
24
+ if (result.ok === false)
25
+ return failure(res, respond, result.error.kind);
26
+ const response = acquisitionCaseListResponseSchema.safeParse(result.value);
27
+ if (!response.success)
28
+ return invalidResponse(res, respond);
29
+ sendBffSuccess(res, response.data);
30
+ };
31
+ }
32
+ export function createAcquisitionCaseActiveCountDirectHandler(options) {
33
+ const { respond, resolveBinding, isDirect } = options;
34
+ const { sendBffSuccess, sendMethodNotAllowed } = respond;
35
+ return async (req, res) => {
36
+ if (!isDirect())
37
+ return unavailable(res, respond);
38
+ if (req.method !== "GET")
39
+ return sendMethodNotAllowed(res, ["GET"]);
40
+ const binding = await bindingOrError(res, respond, resolveBinding);
41
+ if (!binding)
42
+ return;
43
+ const result = await operationOrError(res, respond, () => binding.handlers.activeCount());
44
+ if (!result)
45
+ return;
46
+ if (result.ok === false)
47
+ return failure(res, respond, result.error.kind);
48
+ const response = acquisitionCaseActiveCountResponseSchema.safeParse(result.value);
49
+ if (!response.success)
50
+ return invalidResponse(res, respond);
51
+ sendBffSuccess(res, response.data);
52
+ };
53
+ }
54
+ async function bindingOrError(res, respond, resolve) {
55
+ try {
56
+ const binding = await resolve();
57
+ if (binding)
58
+ return binding;
59
+ }
60
+ catch { /* fail closed below */ }
61
+ respond.sendBffError(res, "UPSTREAM_UNAVAILABLE", "Acquisition case service unavailable");
62
+ return null;
63
+ }
64
+ async function operationOrError(res, respond, operation) {
65
+ try {
66
+ return await operation();
67
+ }
68
+ catch {
69
+ respond.sendBffError(res, "UPSTREAM_UNAVAILABLE", "Acquisition case service unavailable");
70
+ return null;
71
+ }
72
+ }
73
+ function first(value) { return Array.isArray(value) ? value[0] : value; }
74
+ function integer(value, fallback) { return value === undefined ? fallback : Number(value); }
75
+ function badRequest(res, respond, details) { respond.sendBffError(res, "BAD_REQUEST", "Invalid acquisition case request", { details }); }
76
+ function unavailable(res, respond) { respond.sendBffError(res, "NOT_FOUND", "Acquisition case unavailable"); }
77
+ function invalidResponse(res, respond) { respond.sendBffError(res, "INVALID_RESPONSE", "Acquisition case returned invalid response"); }
78
+ function failure(res, respond, kind) {
79
+ if (kind === "invalid")
80
+ return badRequest(res, respond);
81
+ if (kind === "conflict")
82
+ return respond.sendBffError(res, "CONFLICT", "Acquisition case request conflicts with prior state");
83
+ if (kind === "rate_limited")
84
+ return respond.sendBffError(res, "RATE_LIMITED", "Acquisition submission rate limited");
85
+ if (kind === "not_found")
86
+ return unavailable(res, respond);
87
+ respond.sendBffError(res, "UPSTREAM_UNAVAILABLE", "Acquisition case service unavailable");
88
+ }
@@ -0,0 +1,28 @@
1
+ import type { AcquisitionCaseListRequest } from "../contracts/index.js";
2
+ import { type AcquisitionCaseSubmitRequest, type AcquisitionCaseTransitionRequest } from "./acquisitionCasePorts.js";
3
+ import type { AcquisitionCasePort } from "./acquisitionCasePorts.js";
4
+ export interface AcquisitionCaseHandlerOptions {
5
+ now?: () => string;
6
+ }
7
+ export declare function createAcquisitionCaseHandlers(port: AcquisitionCasePort, options?: AcquisitionCaseHandlerOptions): {
8
+ submit(request: AcquisitionCaseSubmitRequest, context: {
9
+ idempotencyKey: string;
10
+ requesterKey: string;
11
+ }): Promise<import("./acquisitionCasePorts.js").AcquisitionCaseResult<import("../contracts/acquisition.js").AcquisitionCaseProjection>>;
12
+ list(actorRef: string, request: AcquisitionCaseListRequest): Promise<import("./acquisitionCasePorts.js").AcquisitionCaseResult<import("../contracts/acquisition.js").AcquisitionCaseListResponse>>;
13
+ get(actorRef: string, caseRef: string): Promise<import("./acquisitionCasePorts.js").AcquisitionCaseResult<import("../contracts/acquisition.js").AcquisitionCaseProjection>>;
14
+ transition(actorRef: string, idempotencyKey: string, request: AcquisitionCaseTransitionRequest): Promise<import("./acquisitionCasePorts.js").AcquisitionCaseResult<import("../contracts/acquisition.js").AcquisitionCaseProjection>>;
15
+ activeCount(): Promise<{
16
+ ok: false;
17
+ error: {
18
+ kind: import("./acquisitionCasePorts.js").AcquisitionCaseFailureKind;
19
+ };
20
+ } | {
21
+ ok: true;
22
+ value: {
23
+ activeTesterCount: number;
24
+ };
25
+ }>;
26
+ contractVersion: "tester_application_v1";
27
+ };
28
+ export type AcquisitionCaseHandlers = ReturnType<typeof createAcquisitionCaseHandlers>;
@@ -0,0 +1,40 @@
1
+ import { ACQUISITION_CASE_CONTRACT_VERSION, ACQUISITION_CASE_SOURCE } from "../acquisitionCaseSchemas.js";
2
+ const SCOPE = "public_tester_application";
3
+ export function createAcquisitionCaseHandlers(port, options = {}) {
4
+ const now = options.now ?? (() => new Date().toISOString());
5
+ return {
6
+ submit(request, context) {
7
+ return port.submit({
8
+ scope: SCOPE,
9
+ sourceKind: ACQUISITION_CASE_SOURCE,
10
+ idempotencyKey: context.idempotencyKey,
11
+ requesterKey: `${SCOPE}:${context.requesterKey}`,
12
+ acceptedAt: now(),
13
+ sourcePath: "/tester-application",
14
+ request,
15
+ });
16
+ },
17
+ list(actorRef, request) {
18
+ return port.list({
19
+ actorRef,
20
+ scope: SCOPE,
21
+ ...(request.cursor ? { cursor: request.cursor } : {}),
22
+ limit: request.limit,
23
+ });
24
+ },
25
+ get(actorRef, caseRef) {
26
+ return port.get({ actorRef, scope: SCOPE, caseRef });
27
+ },
28
+ transition(actorRef, idempotencyKey, request) {
29
+ return port.transition({ actorRef, scope: SCOPE, idempotencyKey, request });
30
+ },
31
+ async activeCount() {
32
+ const result = await port.activeCount(SCOPE);
33
+ return result.ok === false ? result : {
34
+ ok: true,
35
+ value: { activeTesterCount: result.value },
36
+ };
37
+ },
38
+ contractVersion: ACQUISITION_CASE_CONTRACT_VERSION,
39
+ };
40
+ }
@@ -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
+ /** Historical commands retained by the server adapter; public admission routes remain host-owned. */
4
+ export interface AcquisitionCaseSubmitRequest {
5
+ contact: {
6
+ email: string;
7
+ };
8
+ consent: {
9
+ accepted: true;
10
+ consentVersion: string;
11
+ policyVersion: string;
12
+ locale: Projection["consent"]["locale"];
13
+ };
14
+ addressReference: AcquisitionAddressReference;
15
+ }
16
+ export interface AcquisitionCaseTransitionRequest {
17
+ view: "acquisition_case_v1";
18
+ caseRef: string;
19
+ expectedVersion: number;
20
+ transition: "approve" | "activate" | "reject" | "withdraw";
21
+ reason?: string | undefined;
22
+ }
23
+ export interface AcquisitionCaseSubmitCommand {
24
+ scope: "public_tester_application";
25
+ sourceKind: "tester_application";
26
+ idempotencyKey: string;
27
+ requesterKey: string;
28
+ acceptedAt: string;
29
+ sourcePath: "/tester-application";
30
+ request: AcquisitionCaseSubmitRequest;
31
+ }
32
+ export interface AcquisitionCaseTransitionCommand {
33
+ actorRef: string;
34
+ scope: "public_tester_application";
35
+ idempotencyKey: string;
36
+ request: AcquisitionCaseTransitionRequest;
37
+ }
38
+ export interface AcquisitionCasePort extends PortableAcquisitionCasePort {
39
+ submit(command: AcquisitionCaseSubmitCommand): Promise<AcquisitionCaseResult<AcquisitionCaseProjection>>;
40
+ transition(command: AcquisitionCaseTransitionCommand): Promise<AcquisitionCaseResult<AcquisitionCaseProjection>>;
41
+ }
42
+ export type { AcquisitionCaseFailureKind, AcquisitionCaseResult, AcquisitionCaseListQuery, AcquisitionCaseGetQuery, } from "../contracts/index.js";
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,5 @@
1
+ import type { HttpRequest, HttpResponse } from "../../http/index.js";
2
+ import type { AcquisitionEvidenceDirectDeps } from "./directPorts.js";
3
+ export declare function createAcquisitionSurveySubmitDirectHandler(options: AcquisitionEvidenceDirectDeps): (req: HttpRequest, res: HttpResponse) => Promise<void>;
4
+ export declare function createAcquisitionSurveyListDirectHandler(options: AcquisitionEvidenceDirectDeps): (req: HttpRequest, res: HttpResponse) => Promise<void>;
5
+ export declare function createAcquisitionNewsletterConsentDirectHandler(options: AcquisitionEvidenceDirectDeps): (value: unknown, res: HttpResponse) => Promise<void>;