@openlup/platform 0.27.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 (232) hide show
  1. package/CHANGELOG.md +386 -127
  2. package/README.md +251 -9
  3. package/dist/account-support/accountReadFacade.d.ts +8 -0
  4. package/dist/account-support/accountReadFacade.js +10 -0
  5. package/dist/account-support/accountReadModels.d.ts +69 -0
  6. package/dist/account-support/accountReadModels.js +272 -0
  7. package/dist/account-support/bindings.d.ts +23 -0
  8. package/dist/account-support/bindings.js +16 -0
  9. package/dist/account-support/contracts/account.d.ts +281 -0
  10. package/dist/account-support/contracts/account.js +1 -0
  11. package/dist/account-support/contracts/capabilities.d.ts +44 -0
  12. package/dist/account-support/contracts/capabilities.js +1 -0
  13. package/dist/account-support/contracts/commands.d.ts +307 -0
  14. package/dist/account-support/contracts/commands.js +1 -0
  15. package/dist/account-support/contracts/customer360.d.ts +154 -0
  16. package/dist/account-support/contracts/customer360.js +1 -0
  17. package/dist/account-support/contracts/index.d.ts +10 -0
  18. package/dist/account-support/contracts/index.js +1 -0
  19. package/dist/account-support/contracts/invoice.d.ts +79 -0
  20. package/dist/account-support/contracts/invoice.js +1 -0
  21. package/dist/account-support/contracts/operator.d.ts +289 -0
  22. package/dist/account-support/contracts/operator.js +1 -0
  23. package/dist/account-support/contribution.d.ts +24 -0
  24. package/dist/account-support/contribution.js +22 -0
  25. package/dist/account-support/customer360.d.ts +106 -0
  26. package/dist/account-support/customer360.js +163 -0
  27. package/dist/account-support/customerAccountReadDiagnostics.d.ts +11 -0
  28. package/dist/account-support/customerAccountReadDiagnostics.js +71 -0
  29. package/dist/account-support/index.d.ts +26 -0
  30. package/dist/account-support/index.js +15 -0
  31. package/dist/account-support/invoiceAccess.d.ts +57 -0
  32. package/dist/account-support/invoiceAccess.js +40 -0
  33. package/dist/account-support/migrations.d.ts +14 -0
  34. package/dist/account-support/migrations.js +7 -0
  35. package/dist/account-support/operatorAuthority.d.ts +67 -0
  36. package/dist/account-support/operatorAuthority.js +379 -0
  37. package/dist/account-support/operatorRecovery.d.ts +66 -0
  38. package/dist/account-support/operatorRecovery.js +129 -0
  39. package/dist/account-support/orderHistory.d.ts +50 -0
  40. package/dist/account-support/orderHistory.js +188 -0
  41. package/dist/account-support/paymentMethodComposition.d.ts +5 -0
  42. package/dist/account-support/paymentMethodComposition.js +4 -0
  43. package/dist/account-support/postgresOperatorAuthority.d.ts +16 -0
  44. package/dist/account-support/postgresOperatorAuthority.js +93 -0
  45. package/dist/account-support/selfService.d.ts +6 -0
  46. package/dist/account-support/selfService.js +81 -0
  47. package/dist/account-support/subscriptionCommandCodec.d.ts +10 -0
  48. package/dist/account-support/subscriptionCommandCodec.js +38 -0
  49. package/dist/catalog/draftSchemas.d.ts +1 -1
  50. package/dist/catalog/foundationSchemas.d.ts +3 -3
  51. package/dist/catalog/resolvedSkuProjection.d.ts +2 -2
  52. package/dist/catalog/sellableSchemas.d.ts +2 -2
  53. package/dist/commerce/checkoutCommandSchemas.d.ts +2 -2
  54. package/dist/commerce/checkoutResumeSchemas.d.ts +6 -6
  55. package/dist/commerce/checkoutSchemas.d.ts +12 -12
  56. package/dist/commerce/commerceReturnsPort.d.ts +2 -2
  57. package/dist/commerce/configuratorIntentSchemas.d.ts +2 -2
  58. package/dist/commerce/contractPrimitives.d.ts +8 -8
  59. package/dist/commerce/customerDefaultsSnapshotSchemas.d.ts +4 -4
  60. package/dist/commerce/model/omsReadModelHelpers.d.ts +4 -4
  61. package/dist/commerce/offerAvailabilitySchemas.d.ts +1 -1
  62. package/dist/commerce/oms/omsContractBase.d.ts +15 -15
  63. package/dist/commerce/oms/omsContractReadAuxSchemas.d.ts +11 -11
  64. package/dist/commerce/oms/omsContractReadSchemas.d.ts +121 -121
  65. package/dist/commerce/oms/omsContractRequests.d.ts +13 -13
  66. package/dist/commerce/oms/omsControlPlane.d.ts +22 -22
  67. package/dist/commerce/oms/omsFulfillmentContractSchemas.d.ts +12 -12
  68. package/dist/commerce/oms/omsFulfillmentDebugSchemas.d.ts +12 -12
  69. package/dist/commerce/orderReviewContracts.d.ts +33 -33
  70. package/dist/commerce/outboxEventSchemas.d.ts +4 -4
  71. package/dist/commerce/schemas.d.ts +21 -21
  72. package/dist/commerce/server/orderReviewHandlers.d.ts +10 -10
  73. package/dist/communications/consentPurposeRegistry.d.ts +1 -1
  74. package/dist/communications/newsletterIntegrationContracts.d.ts +8 -8
  75. package/dist/composition/accountSupportContribution.d.ts +18 -0
  76. package/dist/composition/accountSupportContribution.js +21 -0
  77. package/dist/composition/index.d.ts +2 -0
  78. package/dist/composition/index.js +2 -0
  79. package/dist/composition/marketingContribution.d.ts +21 -0
  80. package/dist/composition/marketingContribution.js +29 -0
  81. package/dist/fulfillment/handlerSchemas.d.ts +40 -40
  82. package/dist/identity/customerContracts.d.ts +2 -2
  83. package/dist/invoicing/snapshot.d.ts +1 -1
  84. package/dist/marketing/acquisitionCaseSchemas.d.ts +103 -0
  85. package/dist/marketing/acquisitionCaseSchemas.js +53 -0
  86. package/dist/marketing/acquisitionEvidenceSchemas.d.ts +105 -0
  87. package/dist/marketing/acquisitionEvidenceSchemas.js +55 -0
  88. package/dist/marketing/analytics/dataLayer.d.ts +18 -0
  89. package/dist/marketing/analytics/dataLayer.js +111 -0
  90. package/dist/marketing/analytics/noop.d.ts +9 -0
  91. package/dist/marketing/analytics/noop.js +8 -0
  92. package/dist/marketing/analytics/purchaseFacts.d.ts +4 -0
  93. package/dist/marketing/analytics/purchaseFacts.js +69 -0
  94. package/dist/marketing/analytics/routePolicy.d.ts +10 -0
  95. package/dist/marketing/analytics/routePolicy.js +59 -0
  96. package/dist/marketing/consentEvidence.d.ts +8 -0
  97. package/dist/marketing/consentEvidence.js +32 -0
  98. package/dist/marketing/contactLegal.d.ts +14 -0
  99. package/dist/marketing/contactLegal.js +19 -0
  100. package/dist/marketing/contracts/acquisition.d.ts +88 -0
  101. package/dist/marketing/contracts/acquisition.js +1 -0
  102. package/dist/marketing/contracts/acquisitionPorts.d.ts +49 -0
  103. package/dist/marketing/contracts/acquisitionPorts.js +1 -0
  104. package/dist/marketing/contracts/analytics.d.ts +144 -0
  105. package/dist/marketing/contracts/analytics.js +1 -0
  106. package/dist/marketing/contracts/contactLegal.d.ts +53 -0
  107. package/dist/marketing/contracts/contactLegal.js +1 -0
  108. package/dist/marketing/contracts/index.d.ts +6 -0
  109. package/dist/marketing/contracts/index.js +1 -0
  110. package/dist/marketing/contracts/prelaunch.d.ts +39 -0
  111. package/dist/marketing/contracts/prelaunch.js +1 -0
  112. package/dist/marketing/index.d.ts +16 -0
  113. package/dist/marketing/index.js +14 -0
  114. package/dist/marketing/prelaunchAcquisitionSchemas.d.ts +116 -0
  115. package/dist/marketing/prelaunchAcquisitionSchemas.js +51 -0
  116. package/dist/marketing/seo/jsonLd.d.ts +157 -0
  117. package/dist/marketing/seo/jsonLd.js +127 -0
  118. package/dist/marketing/seo/metadata.d.ts +41 -0
  119. package/dist/marketing/seo/metadata.js +36 -0
  120. package/dist/marketing/seo/serializeJsonLd.d.ts +1 -0
  121. package/dist/marketing/seo/serializeJsonLd.js +6 -0
  122. package/dist/marketing/seo/urls.d.ts +14 -0
  123. package/dist/marketing/seo/urls.js +23 -0
  124. package/dist/marketing/server/acquisitionCaseDirect.d.ts +4 -0
  125. package/dist/marketing/server/acquisitionCaseDirect.js +88 -0
  126. package/dist/marketing/server/acquisitionCaseHandlers.d.ts +28 -0
  127. package/dist/marketing/server/acquisitionCaseHandlers.js +40 -0
  128. package/dist/marketing/server/acquisitionCasePorts.d.ts +42 -0
  129. package/dist/marketing/server/acquisitionCasePorts.js +1 -0
  130. package/dist/marketing/server/acquisitionEvidenceDirect.d.ts +5 -0
  131. package/dist/marketing/server/acquisitionEvidenceDirect.js +100 -0
  132. package/dist/marketing/server/analyticsContext.d.ts +3 -0
  133. package/dist/marketing/server/analyticsContext.js +65 -0
  134. package/dist/marketing/server/analyticsContextPorts.d.ts +31 -0
  135. package/dist/marketing/server/analyticsContextPorts.js +1 -0
  136. package/dist/marketing/server/bindings.d.ts +14 -0
  137. package/dist/marketing/server/bindings.js +18 -0
  138. package/dist/marketing/server/directPorts.d.ts +26 -0
  139. package/dist/marketing/server/directPorts.js +1 -0
  140. package/dist/marketing/server/index.d.ts +14 -0
  141. package/dist/marketing/server/index.js +11 -0
  142. package/dist/marketing/server/postgres/acquisitionCaseRoutines.d.ts +10 -0
  143. package/dist/marketing/server/postgres/acquisitionCaseRoutines.js +204 -0
  144. package/dist/marketing/server/postgres/acquisitionEvidenceRoutines.d.ts +10 -0
  145. package/dist/marketing/server/postgres/acquisitionEvidenceRoutines.js +107 -0
  146. package/dist/marketing/server/postgres/index.d.ts +3 -0
  147. package/dist/marketing/server/postgres/index.js +3 -0
  148. package/dist/marketing/server/prelaunchAcquisitionDirect.d.ts +4 -0
  149. package/dist/marketing/server/prelaunchAcquisitionDirect.js +122 -0
  150. package/dist/marketing/server/privacyContributor.d.ts +66 -0
  151. package/dist/marketing/server/privacyContributor.js +87 -0
  152. package/dist/marketing/server/research/adminSurveyResponsesHandler.d.ts +9 -0
  153. package/dist/marketing/server/research/adminSurveyResponsesHandler.js +53 -0
  154. package/dist/marketing/server/research/managedSurveyResponseSubmit.d.ts +39 -0
  155. package/dist/marketing/server/research/managedSurveyResponseSubmit.js +102 -0
  156. package/dist/marketing/server/research/surveyResponseSubmitHandler.d.ts +8 -0
  157. package/dist/marketing/server/research/surveyResponseSubmitHandler.js +41 -0
  158. package/dist/marketing/validation.d.ts +2 -0
  159. package/dist/marketing/validation.js +3 -0
  160. package/dist/pricing/acquisitionQuoteBinding.d.ts +1 -1
  161. package/dist/pricing/catalogFactsSchemas.d.ts +1 -1
  162. package/dist/pricing/quotePromotionEvidence.d.ts +1 -1
  163. package/dist/pricing/quoteSchemas.d.ts +56 -56
  164. package/dist/promotions/adminPromotionCodesContracts.d.ts +30 -30
  165. package/dist/promotions/adminPromotionsContracts.d.ts +14 -14
  166. package/package.json +32 -2
  167. package/release-gates.json +99 -4
  168. package/sql/20261026120000_account_support_operator_authority.sql +693 -0
  169. package/src/account-support/accountReadFacade.ts +15 -0
  170. package/src/account-support/accountReadModels.ts +371 -0
  171. package/src/account-support/bindings.ts +28 -0
  172. package/src/account-support/contracts/account.ts +306 -0
  173. package/src/account-support/contracts/capabilities.ts +30 -0
  174. package/src/account-support/contracts/commands.ts +243 -0
  175. package/src/account-support/contracts/customer360.ts +150 -0
  176. package/src/account-support/contracts/index.ts +141 -0
  177. package/src/account-support/contracts/invoice.ts +44 -0
  178. package/src/account-support/contracts/operator.ts +123 -0
  179. package/src/account-support/contribution.ts +35 -0
  180. package/src/account-support/customer360.ts +268 -0
  181. package/src/account-support/customerAccountReadDiagnostics.ts +83 -0
  182. package/src/account-support/index.ts +72 -0
  183. package/src/account-support/invoiceAccess.ts +63 -0
  184. package/src/account-support/migrations.ts +7 -0
  185. package/src/account-support/operatorAuthority.ts +393 -0
  186. package/src/account-support/operatorRecovery.ts +136 -0
  187. package/src/account-support/orderHistory.ts +309 -0
  188. package/src/account-support/paymentMethodComposition.ts +8 -0
  189. package/src/account-support/postgresOperatorAuthority.ts +92 -0
  190. package/src/account-support/selfService.ts +83 -0
  191. package/src/account-support/subscriptionCommandCodec.ts +48 -0
  192. package/src/composition/accountSupportContribution.ts +28 -0
  193. package/src/composition/index.ts +2 -0
  194. package/src/composition/marketingContribution.ts +37 -0
  195. package/src/marketing/acquisitionCaseSchemas.ts +75 -0
  196. package/src/marketing/acquisitionEvidenceSchemas.ts +72 -0
  197. package/src/marketing/analytics/dataLayer.ts +100 -0
  198. package/src/marketing/analytics/noop.ts +14 -0
  199. package/src/marketing/analytics/purchaseFacts.ts +63 -0
  200. package/src/marketing/analytics/routePolicy.ts +55 -0
  201. package/src/marketing/consentEvidence.ts +36 -0
  202. package/src/marketing/contactLegal.ts +22 -0
  203. package/src/marketing/contracts/acquisition.ts +50 -0
  204. package/src/marketing/contracts/acquisitionPorts.ts +48 -0
  205. package/src/marketing/contracts/analytics.ts +88 -0
  206. package/src/marketing/contracts/contactLegal.ts +41 -0
  207. package/src/marketing/contracts/index.ts +17 -0
  208. package/src/marketing/contracts/prelaunch.ts +15 -0
  209. package/src/marketing/index.ts +16 -0
  210. package/src/marketing/prelaunchAcquisitionSchemas.ts +64 -0
  211. package/src/marketing/seo/jsonLd.ts +153 -0
  212. package/src/marketing/seo/metadata.ts +62 -0
  213. package/src/marketing/seo/serializeJsonLd.ts +6 -0
  214. package/src/marketing/seo/urls.ts +34 -0
  215. package/src/marketing/server/acquisitionCaseDirect.ts +67 -0
  216. package/src/marketing/server/acquisitionCaseHandlers.ts +57 -0
  217. package/src/marketing/server/acquisitionCasePorts.ts +42 -0
  218. package/src/marketing/server/acquisitionEvidenceDirect.ts +76 -0
  219. package/src/marketing/server/analyticsContext.ts +55 -0
  220. package/src/marketing/server/analyticsContextPorts.ts +28 -0
  221. package/src/marketing/server/bindings.ts +27 -0
  222. package/src/marketing/server/directPorts.ts +27 -0
  223. package/src/marketing/server/index.ts +14 -0
  224. package/src/marketing/server/postgres/acquisitionCaseRoutines.ts +218 -0
  225. package/src/marketing/server/postgres/acquisitionEvidenceRoutines.ts +103 -0
  226. package/src/marketing/server/postgres/index.ts +3 -0
  227. package/src/marketing/server/prelaunchAcquisitionDirect.ts +121 -0
  228. package/src/marketing/server/privacyContributor.ts +123 -0
  229. package/src/marketing/server/research/adminSurveyResponsesHandler.ts +78 -0
  230. package/src/marketing/server/research/managedSurveyResponseSubmit.ts +158 -0
  231. package/src/marketing/server/research/surveyResponseSubmitHandler.ts +57 -0
  232. package/src/marketing/validation.ts +3 -0
@@ -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
+ }
@@ -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); }