@aglyn/tenant-data-admin 1.0.0-beta.143

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 (374) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +7 -0
  3. package/jest.integration.config.d.ts +39 -0
  4. package/jest.integration.setup.d.ts +17 -0
  5. package/package.json +51 -0
  6. package/src/index.d.ts +17 -0
  7. package/src/index.js +18 -0
  8. package/src/index.js.map +1 -0
  9. package/src/lib/render-cache.d.ts +184 -0
  10. package/src/lib/render-cache.js +198 -0
  11. package/src/lib/render-cache.js.map +1 -0
  12. package/src/lib/server/account-addresses.d.ts +160 -0
  13. package/src/lib/server/account-addresses.js +311 -0
  14. package/src/lib/server/account-addresses.js.map +1 -0
  15. package/src/lib/server/account-emails.d.ts +219 -0
  16. package/src/lib/server/account-emails.js +640 -0
  17. package/src/lib/server/account-emails.js.map +1 -0
  18. package/src/lib/server/admin-audit.d.ts +180 -0
  19. package/src/lib/server/admin-audit.js +233 -0
  20. package/src/lib/server/admin-audit.js.map +1 -0
  21. package/src/lib/server/analytics-retention.d.ts +63 -0
  22. package/src/lib/server/analytics-retention.js +66 -0
  23. package/src/lib/server/analytics-retention.js.map +1 -0
  24. package/src/lib/server/api-http.d.ts +159 -0
  25. package/src/lib/server/api-http.js +230 -0
  26. package/src/lib/server/api-http.js.map +1 -0
  27. package/src/lib/server/api-keys.d.ts +117 -0
  28. package/src/lib/server/api-keys.js +298 -0
  29. package/src/lib/server/api-keys.js.map +1 -0
  30. package/src/lib/server/auth-handoff.d.ts +165 -0
  31. package/src/lib/server/auth-handoff.js +482 -0
  32. package/src/lib/server/auth-handoff.js.map +1 -0
  33. package/src/lib/server/auth-pools.d.ts +246 -0
  34. package/src/lib/server/auth-pools.js +551 -0
  35. package/src/lib/server/auth-pools.js.map +1 -0
  36. package/src/lib/server/billing-addons.d.ts +171 -0
  37. package/src/lib/server/billing-addons.js +277 -0
  38. package/src/lib/server/billing-addons.js.map +1 -0
  39. package/src/lib/server/campaign-attribution-store.d.ts +55 -0
  40. package/src/lib/server/campaign-attribution-store.js +95 -0
  41. package/src/lib/server/campaign-attribution-store.js.map +1 -0
  42. package/src/lib/server/campaign-conversion-attribution.d.ts +205 -0
  43. package/src/lib/server/campaign-conversion-attribution.js +279 -0
  44. package/src/lib/server/campaign-conversion-attribution.js.map +1 -0
  45. package/src/lib/server/client-error-report.d.ts +301 -0
  46. package/src/lib/server/client-error-report.js +755 -0
  47. package/src/lib/server/client-error-report.js.map +1 -0
  48. package/src/lib/server/connect-account-status.d.ts +74 -0
  49. package/src/lib/server/connect-account-status.js +94 -0
  50. package/src/lib/server/connect-account-status.js.map +1 -0
  51. package/src/lib/server/connect-payout-failure.d.ts +103 -0
  52. package/src/lib/server/connect-payout-failure.js +127 -0
  53. package/src/lib/server/connect-payout-failure.js.map +1 -0
  54. package/src/lib/server/console-api-rate-limit.d.ts +81 -0
  55. package/src/lib/server/console-api-rate-limit.js +111 -0
  56. package/src/lib/server/console-api-rate-limit.js.map +1 -0
  57. package/src/lib/server/console-domains.d.ts +326 -0
  58. package/src/lib/server/console-domains.js +779 -0
  59. package/src/lib/server/console-domains.js.map +1 -0
  60. package/src/lib/server/consume-once.d.ts +91 -0
  61. package/src/lib/server/consume-once.js +96 -0
  62. package/src/lib/server/consume-once.js.map +1 -0
  63. package/src/lib/server/contact-company-link.d.ts +85 -0
  64. package/src/lib/server/contact-company-link.js +105 -0
  65. package/src/lib/server/contact-company-link.js.map +1 -0
  66. package/src/lib/server/contact-email-engagement.d.ts +32 -0
  67. package/src/lib/server/contact-email-engagement.js +145 -0
  68. package/src/lib/server/contact-email-engagement.js.map +1 -0
  69. package/src/lib/server/contact-email-index.d.ts +56 -0
  70. package/src/lib/server/contact-email-index.js +158 -0
  71. package/src/lib/server/contact-email-index.js.map +1 -0
  72. package/src/lib/server/contact-lifecycle-floor.d.ts +89 -0
  73. package/src/lib/server/contact-lifecycle-floor.js +88 -0
  74. package/src/lib/server/contact-lifecycle-floor.js.map +1 -0
  75. package/src/lib/server/contact-merge.d.ts +55 -0
  76. package/src/lib/server/contact-merge.js +279 -0
  77. package/src/lib/server/contact-merge.js.map +1 -0
  78. package/src/lib/server/contact-suppression.d.ts +153 -0
  79. package/src/lib/server/contact-suppression.js +259 -0
  80. package/src/lib/server/contact-suppression.js.map +1 -0
  81. package/src/lib/server/crm-booking-activity.d.ts +86 -0
  82. package/src/lib/server/crm-booking-activity.js +251 -0
  83. package/src/lib/server/crm-booking-activity.js.map +1 -0
  84. package/src/lib/server/crm-email-activity.d.ts +112 -0
  85. package/src/lib/server/crm-email-activity.js +143 -0
  86. package/src/lib/server/crm-email-activity.js.map +1 -0
  87. package/src/lib/server/crm-inbound-email.d.ts +145 -0
  88. package/src/lib/server/crm-inbound-email.js +287 -0
  89. package/src/lib/server/crm-inbound-email.js.map +1 -0
  90. package/src/lib/server/crm-next-activity.d.ts +74 -0
  91. package/src/lib/server/crm-next-activity.js +194 -0
  92. package/src/lib/server/crm-next-activity.js.map +1 -0
  93. package/src/lib/server/crm-records.d.ts +144 -0
  94. package/src/lib/server/crm-records.js +218 -0
  95. package/src/lib/server/crm-records.js.map +1 -0
  96. package/src/lib/server/csp-aggregate.d.ts +62 -0
  97. package/src/lib/server/csp-aggregate.js +276 -0
  98. package/src/lib/server/csp-aggregate.js.map +1 -0
  99. package/src/lib/server/data-storage-gate.d.ts +66 -0
  100. package/src/lib/server/data-storage-gate.js +48 -0
  101. package/src/lib/server/data-storage-gate.js.map +1 -0
  102. package/src/lib/server/dataset-live-pages.d.ts +179 -0
  103. package/src/lib/server/dataset-live-pages.js +421 -0
  104. package/src/lib/server/dataset-live-pages.js.map +1 -0
  105. package/src/lib/server/dns-probe.d.ts +53 -0
  106. package/src/lib/server/dns-probe.js +184 -0
  107. package/src/lib/server/dns-probe.js.map +1 -0
  108. package/src/lib/server/document-id.d.ts +29 -0
  109. package/src/lib/server/document-id.js +100 -0
  110. package/src/lib/server/document-id.js.map +1 -0
  111. package/src/lib/server/domain-provider-vercel.d.ts +33 -0
  112. package/src/lib/server/domain-provider-vercel.js +298 -0
  113. package/src/lib/server/domain-provider-vercel.js.map +1 -0
  114. package/src/lib/server/domain-provider-webhook.d.ts +73 -0
  115. package/src/lib/server/domain-provider-webhook.js +223 -0
  116. package/src/lib/server/domain-provider-webhook.js.map +1 -0
  117. package/src/lib/server/domain-provider-wildcard.d.ts +54 -0
  118. package/src/lib/server/domain-provider-wildcard.js +163 -0
  119. package/src/lib/server/domain-provider-wildcard.js.map +1 -0
  120. package/src/lib/server/domain-provider.d.ts +197 -0
  121. package/src/lib/server/domain-provider.js +221 -0
  122. package/src/lib/server/domain-provider.js.map +1 -0
  123. package/src/lib/server/duplicate-activity.d.ts +54 -0
  124. package/src/lib/server/duplicate-activity.js +67 -0
  125. package/src/lib/server/duplicate-activity.js.map +1 -0
  126. package/src/lib/server/duplicate-resource.d.ts +55 -0
  127. package/src/lib/server/duplicate-resource.js +474 -0
  128. package/src/lib/server/duplicate-resource.js.map +1 -0
  129. package/src/lib/server/dynamic-list-materialize.d.ts +153 -0
  130. package/src/lib/server/dynamic-list-materialize.js +581 -0
  131. package/src/lib/server/dynamic-list-materialize.js.map +1 -0
  132. package/src/lib/server/edit-access-authz.d.ts +56 -0
  133. package/src/lib/server/edit-access-authz.js +107 -0
  134. package/src/lib/server/edit-access-authz.js.map +1 -0
  135. package/src/lib/server/edit-access-token.d.ts +72 -0
  136. package/src/lib/server/edit-access-token.js +116 -0
  137. package/src/lib/server/edit-access-token.js.map +1 -0
  138. package/src/lib/server/edit-hint-token.d.ts +83 -0
  139. package/src/lib/server/edit-hint-token.js +119 -0
  140. package/src/lib/server/edit-hint-token.js.map +1 -0
  141. package/src/lib/server/email-delivery-log.d.ts +509 -0
  142. package/src/lib/server/email-delivery-log.js +1043 -0
  143. package/src/lib/server/email-delivery-log.js.map +1 -0
  144. package/src/lib/server/email-flow-gate.d.ts +80 -0
  145. package/src/lib/server/email-flow-gate.js +153 -0
  146. package/src/lib/server/email-flow-gate.js.map +1 -0
  147. package/src/lib/server/email-marketing-gate.d.ts +333 -0
  148. package/src/lib/server/email-marketing-gate.js +639 -0
  149. package/src/lib/server/email-marketing-gate.js.map +1 -0
  150. package/src/lib/server/email-metering.d.ts +293 -0
  151. package/src/lib/server/email-metering.js +359 -0
  152. package/src/lib/server/email-metering.js.map +1 -0
  153. package/src/lib/server/email-revenue-attribution.d.ts +185 -0
  154. package/src/lib/server/email-revenue-attribution.js +300 -0
  155. package/src/lib/server/email-revenue-attribution.js.map +1 -0
  156. package/src/lib/server/email-send-rate.d.ts +232 -0
  157. package/src/lib/server/email-send-rate.js +417 -0
  158. package/src/lib/server/email-send-rate.js.map +1 -0
  159. package/src/lib/server/email-sender-reputation.d.ts +317 -0
  160. package/src/lib/server/email-sender-reputation.js +464 -0
  161. package/src/lib/server/email-sender-reputation.js.map +1 -0
  162. package/src/lib/server/email-suppression.d.ts +490 -0
  163. package/src/lib/server/email-suppression.js +648 -0
  164. package/src/lib/server/email-suppression.js.map +1 -0
  165. package/src/lib/server/email-topic-confirmation.d.ts +150 -0
  166. package/src/lib/server/email-topic-confirmation.js +272 -0
  167. package/src/lib/server/email-topic-confirmation.js.map +1 -0
  168. package/src/lib/server/email-unsubscribe-link.d.ts +174 -0
  169. package/src/lib/server/email-unsubscribe-link.js +236 -0
  170. package/src/lib/server/email-unsubscribe-link.js.map +1 -0
  171. package/src/lib/server/erase-person.d.ts +116 -0
  172. package/src/lib/server/erase-person.js +272 -0
  173. package/src/lib/server/erase-person.js.map +1 -0
  174. package/src/lib/server/erase.d.ts +458 -0
  175. package/src/lib/server/erase.js +1506 -0
  176. package/src/lib/server/erase.js.map +1 -0
  177. package/src/lib/server/firebase-admin.d.ts +71 -0
  178. package/src/lib/server/firebase-admin.js +343 -0
  179. package/src/lib/server/firebase-admin.js.map +1 -0
  180. package/src/lib/server/form-dataset-binding-token.d.ts +35 -0
  181. package/src/lib/server/form-dataset-binding-token.js +107 -0
  182. package/src/lib/server/form-dataset-binding-token.js.map +1 -0
  183. package/src/lib/server/free-workspace-cap.d.ts +201 -0
  184. package/src/lib/server/free-workspace-cap.js +404 -0
  185. package/src/lib/server/free-workspace-cap.js.map +1 -0
  186. package/src/lib/server/ga4-measurement-protocol.d.ts +256 -0
  187. package/src/lib/server/ga4-measurement-protocol.js +558 -0
  188. package/src/lib/server/ga4-measurement-protocol.js.map +1 -0
  189. package/src/lib/server/host-email-tokens.d.ts +47 -0
  190. package/src/lib/server/host-email-tokens.js +72 -0
  191. package/src/lib/server/host-email-tokens.js.map +1 -0
  192. package/src/lib/server/host-memberships.d.ts +54 -0
  193. package/src/lib/server/host-memberships.js +194 -0
  194. package/src/lib/server/host-memberships.js.map +1 -0
  195. package/src/lib/server/host-sending-domain.d.ts +292 -0
  196. package/src/lib/server/host-sending-domain.js +451 -0
  197. package/src/lib/server/host-sending-domain.js.map +1 -0
  198. package/src/lib/server/host-visitor-records.d.ts +150 -0
  199. package/src/lib/server/host-visitor-records.js +262 -0
  200. package/src/lib/server/host-visitor-records.js.map +1 -0
  201. package/src/lib/server/id-token-refusal.d.ts +28 -0
  202. package/src/lib/server/id-token-refusal.js +111 -0
  203. package/src/lib/server/id-token-refusal.js.map +1 -0
  204. package/src/lib/server/legal-acceptance.d.ts +214 -0
  205. package/src/lib/server/legal-acceptance.js +305 -0
  206. package/src/lib/server/legal-acceptance.js.map +1 -0
  207. package/src/lib/server/list-members.d.ts +211 -0
  208. package/src/lib/server/list-members.js +176 -0
  209. package/src/lib/server/list-members.js.map +1 -0
  210. package/src/lib/server/live-page-usage.d.ts +202 -0
  211. package/src/lib/server/live-page-usage.js +300 -0
  212. package/src/lib/server/live-page-usage.js.map +1 -0
  213. package/src/lib/server/lockdown.d.ts +313 -0
  214. package/src/lib/server/lockdown.js +643 -0
  215. package/src/lib/server/lockdown.js.map +1 -0
  216. package/src/lib/server/media-cdn-rate-limit.d.ts +188 -0
  217. package/src/lib/server/media-cdn-rate-limit.js +204 -0
  218. package/src/lib/server/media-cdn-rate-limit.js.map +1 -0
  219. package/src/lib/server/media-delivery.d.ts +267 -0
  220. package/src/lib/server/media-delivery.js +485 -0
  221. package/src/lib/server/media-delivery.js.map +1 -0
  222. package/src/lib/server/media-download-tokens.d.ts +161 -0
  223. package/src/lib/server/media-download-tokens.js +386 -0
  224. package/src/lib/server/media-download-tokens.js.map +1 -0
  225. package/src/lib/server/media-quarantine.d.ts +127 -0
  226. package/src/lib/server/media-quarantine.js +170 -0
  227. package/src/lib/server/media-quarantine.js.map +1 -0
  228. package/src/lib/server/media-signing.d.ts +126 -0
  229. package/src/lib/server/media-signing.js +159 -0
  230. package/src/lib/server/media-signing.js.map +1 -0
  231. package/src/lib/server/media-storage-path.d.ts +96 -0
  232. package/src/lib/server/media-storage-path.js +111 -0
  233. package/src/lib/server/media-storage-path.js.map +1 -0
  234. package/src/lib/server/media-strong-digest.d.ts +85 -0
  235. package/src/lib/server/media-strong-digest.js +190 -0
  236. package/src/lib/server/media-strong-digest.js.map +1 -0
  237. package/src/lib/server/media-tombstone.d.ts +276 -0
  238. package/src/lib/server/media-tombstone.js +421 -0
  239. package/src/lib/server/media-tombstone.js.map +1 -0
  240. package/src/lib/server/media-variants.d.ts +309 -0
  241. package/src/lib/server/media-variants.js +428 -0
  242. package/src/lib/server/media-variants.js.map +1 -0
  243. package/src/lib/server/member-email-aliases.d.ts +180 -0
  244. package/src/lib/server/member-email-aliases.js +420 -0
  245. package/src/lib/server/member-email-aliases.js.map +1 -0
  246. package/src/lib/server/member-photo.d.ts +88 -0
  247. package/src/lib/server/member-photo.js +185 -0
  248. package/src/lib/server/member-photo.js.map +1 -0
  249. package/src/lib/server/membership-recover-throttle.d.ts +211 -0
  250. package/src/lib/server/membership-recover-throttle.js +231 -0
  251. package/src/lib/server/membership-recover-throttle.js.map +1 -0
  252. package/src/lib/server/notifications.d.ts +55 -0
  253. package/src/lib/server/notifications.js +134 -0
  254. package/src/lib/server/notifications.js.map +1 -0
  255. package/src/lib/server/org-billing.d.ts +97 -0
  256. package/src/lib/server/org-billing.js +236 -0
  257. package/src/lib/server/org-billing.js.map +1 -0
  258. package/src/lib/server/organizations.d.ts +837 -0
  259. package/src/lib/server/organizations.js +1814 -0
  260. package/src/lib/server/organizations.js.map +1 -0
  261. package/src/lib/server/password-reset-throttle.d.ts +84 -0
  262. package/src/lib/server/password-reset-throttle.js +102 -0
  263. package/src/lib/server/password-reset-throttle.js.map +1 -0
  264. package/src/lib/server/personal-data-export.d.ts +241 -0
  265. package/src/lib/server/personal-data-export.js +858 -0
  266. package/src/lib/server/personal-data-export.js.map +1 -0
  267. package/src/lib/server/platform-domain-names.d.ts +62 -0
  268. package/src/lib/server/platform-domain-names.js +197 -0
  269. package/src/lib/server/platform-domain-names.js.map +1 -0
  270. package/src/lib/server/platform-marketing-consent.d.ts +133 -0
  271. package/src/lib/server/platform-marketing-consent.js +209 -0
  272. package/src/lib/server/platform-marketing-consent.js.map +1 -0
  273. package/src/lib/server/rate-limit-store.d.ts +702 -0
  274. package/src/lib/server/rate-limit-store.js +1220 -0
  275. package/src/lib/server/rate-limit-store.js.map +1 -0
  276. package/src/lib/server/realm-plugins.d.ts +67 -0
  277. package/src/lib/server/realm-plugins.js +250 -0
  278. package/src/lib/server/realm-plugins.js.map +1 -0
  279. package/src/lib/server/recaptcha-allowlist.d.ts +90 -0
  280. package/src/lib/server/recaptcha-allowlist.js +409 -0
  281. package/src/lib/server/recaptcha-allowlist.js.map +1 -0
  282. package/src/lib/server/release-flags.d.ts +105 -0
  283. package/src/lib/server/release-flags.js +183 -0
  284. package/src/lib/server/release-flags.js.map +1 -0
  285. package/src/lib/server/replay-erasures.d.ts +126 -0
  286. package/src/lib/server/replay-erasures.js +217 -0
  287. package/src/lib/server/replay-erasures.js.map +1 -0
  288. package/src/lib/server/resolve-people.d.ts +66 -0
  289. package/src/lib/server/resolve-people.js +112 -0
  290. package/src/lib/server/resolve-people.js.map +1 -0
  291. package/src/lib/server/safe-equal.d.ts +45 -0
  292. package/src/lib/server/safe-equal.js +58 -0
  293. package/src/lib/server/safe-equal.js.map +1 -0
  294. package/src/lib/server/sending-domain-debt.d.ts +127 -0
  295. package/src/lib/server/sending-domain-debt.js +268 -0
  296. package/src/lib/server/sending-domain-debt.js.map +1 -0
  297. package/src/lib/server/sending-domain-recheck.d.ts +151 -0
  298. package/src/lib/server/sending-domain-recheck.js +253 -0
  299. package/src/lib/server/sending-domain-recheck.js.map +1 -0
  300. package/src/lib/server/sending-domains.d.ts +364 -0
  301. package/src/lib/server/sending-domains.js +683 -0
  302. package/src/lib/server/sending-domains.js.map +1 -0
  303. package/src/lib/server/serve-media-cdn.d.ts +433 -0
  304. package/src/lib/server/serve-media-cdn.js +1370 -0
  305. package/src/lib/server/serve-media-cdn.js.map +1 -0
  306. package/src/lib/server/serve-plugin-fetch.d.ts +61 -0
  307. package/src/lib/server/serve-plugin-fetch.js +294 -0
  308. package/src/lib/server/serve-plugin-fetch.js.map +1 -0
  309. package/src/lib/server/sms-keywords.d.ts +63 -0
  310. package/src/lib/server/sms-keywords.js +146 -0
  311. package/src/lib/server/sms-keywords.js.map +1 -0
  312. package/src/lib/server/sso-break-glass-owners.d.ts +91 -0
  313. package/src/lib/server/sso-break-glass-owners.js +227 -0
  314. package/src/lib/server/sso-break-glass-owners.js.map +1 -0
  315. package/src/lib/server/sso-domain-policy.d.ts +140 -0
  316. package/src/lib/server/sso-domain-policy.js +239 -0
  317. package/src/lib/server/sso-domain-policy.js.map +1 -0
  318. package/src/lib/server/sso-drift-logic.d.ts +106 -0
  319. package/src/lib/server/sso-drift-logic.js +95 -0
  320. package/src/lib/server/sso-drift-logic.js.map +1 -0
  321. package/src/lib/server/sso-enforcement.d.ts +204 -0
  322. package/src/lib/server/sso-enforcement.js +309 -0
  323. package/src/lib/server/sso-enforcement.js.map +1 -0
  324. package/src/lib/server/sso-provisioning.d.ts +320 -0
  325. package/src/lib/server/sso-provisioning.js +715 -0
  326. package/src/lib/server/sso-provisioning.js.map +1 -0
  327. package/src/lib/server/staff-alert-email.d.ts +41 -0
  328. package/src/lib/server/staff-alert-email.js +63 -0
  329. package/src/lib/server/staff-alert-email.js.map +1 -0
  330. package/src/lib/server/stripe-account-mode.d.ts +156 -0
  331. package/src/lib/server/stripe-account-mode.js +162 -0
  332. package/src/lib/server/stripe-account-mode.js.map +1 -0
  333. package/src/lib/server/tenant-write-lockdown.d.ts +131 -0
  334. package/src/lib/server/tenant-write-lockdown.js +176 -0
  335. package/src/lib/server/tenant-write-lockdown.js.map +1 -0
  336. package/src/lib/server/test-firestore.d.ts +45 -0
  337. package/src/lib/server/test-firestore.js +124 -0
  338. package/src/lib/server/test-firestore.js.map +1 -0
  339. package/src/lib/server/token-revocation.d.ts +140 -0
  340. package/src/lib/server/token-revocation.js +255 -0
  341. package/src/lib/server/token-revocation.js.map +1 -0
  342. package/src/lib/server/update-existing.d.ts +32 -0
  343. package/src/lib/server/update-existing.js +73 -0
  344. package/src/lib/server/update-existing.js.map +1 -0
  345. package/src/lib/server/upload-cors-reconcile.d.ts +118 -0
  346. package/src/lib/server/upload-cors-reconcile.js +234 -0
  347. package/src/lib/server/upload-cors-reconcile.js.map +1 -0
  348. package/src/lib/server/upsert-contact.d.ts +262 -0
  349. package/src/lib/server/upsert-contact.js +546 -0
  350. package/src/lib/server/upsert-contact.js.map +1 -0
  351. package/src/lib/server/usage-invoice.d.ts +203 -0
  352. package/src/lib/server/usage-invoice.js +397 -0
  353. package/src/lib/server/usage-invoice.js.map +1 -0
  354. package/src/lib/server/user-profiles.d.ts +151 -0
  355. package/src/lib/server/user-profiles.js +364 -0
  356. package/src/lib/server/user-profiles.js.map +1 -0
  357. package/src/lib/server/vercel-drain-signature.d.ts +30 -0
  358. package/src/lib/server/vercel-drain-signature.js +61 -0
  359. package/src/lib/server/vercel-drain-signature.js.map +1 -0
  360. package/src/lib/server/vercel-log-drain.d.ts +259 -0
  361. package/src/lib/server/vercel-log-drain.js +479 -0
  362. package/src/lib/server/vercel-log-drain.js.map +1 -0
  363. package/src/lib/server/verify-email-cooldown.d.ts +102 -0
  364. package/src/lib/server/verify-email-cooldown.js +114 -0
  365. package/src/lib/server/verify-email-cooldown.js.map +1 -0
  366. package/src/lib/server/visitor-write-rate-limit.d.ts +87 -0
  367. package/src/lib/server/visitor-write-rate-limit.js +117 -0
  368. package/src/lib/server/visitor-write-rate-limit.js.map +1 -0
  369. package/src/lib/server/workspace-domains.d.ts +156 -0
  370. package/src/lib/server/workspace-domains.js +271 -0
  371. package/src/lib/server/workspace-domains.js.map +1 -0
  372. package/src/tenancy.d.ts +115 -0
  373. package/src/tenancy.js +142 -0
  374. package/src/tenancy.js.map +1 -0
@@ -0,0 +1,648 @@
1
+ import { _ as _extends } from "@swc/helpers/_/_extends";
2
+ /**
3
+ * @license
4
+ * Copyright 2026 Aglyn LLC
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */ /**
18
+ * The PLATFORM-WIDE email suppression list, `emailSuppressions/{emailKey}`
19
+ * (AGL-2407).
20
+ *
21
+ * ## What was missing
22
+ *
23
+ * AGL-1918 (`7a8f3cd68`) made `email.bounced` (permanent) and
24
+ * `email.complained` write a suppression — into `hosts/{hostId}/suppressions`,
25
+ * found from a Resend tag that only `campaign-send.ts` stamped. That closed
26
+ * the campaign half and could close no other, because there was nowhere to
27
+ * file the rest:
28
+ *
29
+ * Every other sender in the product goes through the shared `sendEmail` —
30
+ * invites,
31
+ * password resets, verification, receipts, booking confirmations, the monthly
32
+ * usage summary, the usage-alert fan-out, restock and abandoned-cart mail, the
33
+ * merchant-authored workflow `sendEmail` step. A bounce on any of those
34
+ * arrived at the webhook with no site to place it against and was answered
35
+ * `200 {ignored:true}`. A dead address was re-mailed on every subsequent send,
36
+ * forever, and a spam complaint had no effect on anything.
37
+ *
38
+ * That matters most exactly when it is hardest to fix: on Sept 1 the signup
39
+ * door opens, and verification and invite mail — addressed by strangers typing
40
+ * addresses — is the highest-bounce-rate mail we send, on the same Resend key
41
+ * and the same From address as everything else.
42
+ *
43
+ * ## Why a sibling of `contactSuppressions` and not a channel on it
44
+ *
45
+ * `contact-suppression.ts` is the same idea for phones and every argument it
46
+ * makes holds here: keyed on the identifier because that is what the sender
47
+ * holds at send time; one `get()` by document id, no query and no composite
48
+ * index that could go missing and fail the lookup open; a revocation is a
49
+ * FIELD and not a delete, because the record is the evidence that the
50
+ * suppression was honoured while it was in force.
51
+ *
52
+ * It is a separate collection for one concrete reason: the document id. That
53
+ * list's key is the E.164 digits, and its docblock argues at length that a
54
+ * phone number must NOT be hashed (NANP is ~10^10 values, so a hash buys the
55
+ * appearance of de-identification and none of the substance). An email address
56
+ * is not enumerable, `hosts/{hostId}/suppressions` already keys on
57
+ * `sha256(email)`, and one collection holding two incompatible key spaces is
58
+ * how a lookup comes to be performed against the wrong derivation. The
59
+ * address is stored in the document in the clear regardless, exactly as the
60
+ * per-host list stores it, so a staff reader still shows a human something
61
+ * they can act on.
62
+ *
63
+ * ## Who reads it, and who deliberately does NOT
64
+ *
65
+ * AGL-1438's rule is that a QUOTA may only ever refuse a campaign, because
66
+ * refusing a receipt or a password reset converts a billing event into an
67
+ * outage on a customer's business. A suppression is not a quota, but the same
68
+ * proportionality applies and lands in the same place:
69
+ *
70
+ * - **Bulk mail consults this list.** The monthly usage summary, the
71
+ * usage-alert fan-out and the marketplace review fan-out to a publisher's
72
+ * owners and admins go to a LIST of people who did not ask for that
73
+ * particular message, on a schedule or on every submission, forever. They
74
+ * are the sends that re-hit a dead mailbox every month and teach a mailbox
75
+ * provider that `aglyn.com` does not listen.
76
+ * - **Transactional mail does NOT.** A password reset, a verification, an
77
+ * invite, a receipt or a booking confirmation answers something the human
78
+ * just did. Refusing one because an address bounced or because somebody
79
+ * once pressed "report spam" on an unrelated message would lock a real
80
+ * customer out of their own account. The shared sender is therefore left
81
+ * unconditional on purpose, and this is the note that says so.
82
+ *
83
+ * (Written throughout without a literal call expression, on purpose:
84
+ * `email-send-metering-coverage.spec.ts` enumerates senders by grepping the
85
+ * tree for one, and a prose mention here would enrol a module that sends
86
+ * nothing into the AGL-1438 cost-meter sweep.)
87
+ */ import { FieldValue, Timestamp } from "firebase-admin/firestore";
88
+ // The leaf entry, not the `@aglyn/aglyn` barrel, for the reason
89
+ // `document-id.ts` gives at length: a barrel import resolves to whatever a
90
+ // spec's `jest.mock` happens to contain, and this module's neighbours are
91
+ // mocked in nearly every spec that touches them.
92
+ import { readTopicSubscriptionState, TOPIC_OPT_OUTS_SUBCOLLECTION } from "@aglyn/aglyn/app-utils/email-topics";
93
+ import { personKey } from "@aglyn/aglyn/app-utils/person-key";
94
+ import firebaseAdmin from "./firebase-admin.js";
95
+ const defaultFirestore = ()=>firebaseAdmin.app().firestore();
96
+ export const EMAIL_SUPPRESSIONS_COLLECTION = 'emailSuppressions';
97
+ /**
98
+ * The PER-SITE list, `hosts/{hostId}/suppressions/{emailKey}` — unsubscribes
99
+ * from one site's campaigns, plus the bounces and complaints that arrived
100
+ * carrying that site's tag.
101
+ *
102
+ * Named here rather than at each call site because the two lists are read
103
+ * together by {@link filterSendableForHost}, and a sender that knows one path
104
+ * as a string literal and the other through this module is one rename away
105
+ * from consulting a collection that does not exist and finding nobody
106
+ * suppressed.
107
+ */ export const HOST_SUPPRESSIONS_SUBCOLLECTION = 'suppressions';
108
+ /**
109
+ * The reasons that may be filed PLATFORM-WIDE, as a runtime set.
110
+ *
111
+ * ## The split this constant enforces
112
+ *
113
+ * A bounce and a complaint are facts about a MAILBOX and about the sending
114
+ * domain every tenant's mail leaves by: the address does not exist for
115
+ * anybody, and somebody who pressed "report spam" on `noreply@aglyn.com` has
116
+ * told every sender behind that domain at once. Those belong everywhere,
117
+ * immediately.
118
+ *
119
+ * An UNSUBSCRIBE is not that. It is a preference a person expressed to ONE
120
+ * brand — the sender line they read, the newsletter they joined — and an
121
+ * agency running twelve unrelated clients out of one account would, on a
122
+ * platform-wide entry, stop mailing that person on behalf of eleven brands
123
+ * they never heard from. So an unsubscribe lives only in
124
+ * `hosts/{hostId}/suppressions`, and {@link suppressEmail} refuses it.
125
+ *
126
+ * ## Why a runtime refusal and not just the type
127
+ *
128
+ * {@link EmailSuppressionReason} already excludes it, and a type is not a
129
+ * guard: every caller here builds its reason from a webhook payload or a
130
+ * ternary, `as` casts exist, and the plugin API surface is untyped at the
131
+ * boundary. The cost of the type being wrong once is an opt-out from one
132
+ * brand silently applied to every brand in the account, which is invisible
133
+ * from the console — the mail simply never arrives, and the merchant's own
134
+ * suppression list does not mention it.
135
+ */ export const PLATFORM_SUPPRESSION_REASONS = [
136
+ 'bounce',
137
+ 'complaint',
138
+ 'staff'
139
+ ];
140
+ /**
141
+ * The reason a self-service opt-out is filed under, on the PER-SITE list.
142
+ *
143
+ * Named because three call sites compare against it — the unsubscribe writes
144
+ * it, the resubscribe link refuses to reverse anything else, and the
145
+ * preference page reads it to decide whether an address may opt back in. A
146
+ * literal in three places is a literal that can be changed in two.
147
+ */ export const UNSUBSCRIBE_SUPPRESSION_REASON = 'unsubscribe';
148
+ /**
149
+ * Document id for an address: `sha256` of the lowercased, trimmed form.
150
+ *
151
+ * The SAME derivation `campaign-send.ts` uses for `hosts/{hostId}/suppressions`
152
+ * — deliberately, so the two lists can never disagree about which document
153
+ * describes which person.
154
+ *
155
+ * @returns the id, or `null` for anything that is not an address. Never a
156
+ * best-guess id: suppressing the wrong person and believing you
157
+ * suppressed the right one is worse than refusing.
158
+ */ export function emailSuppressionKey(email) {
159
+ /*
160
+ * Delegated, not reimplemented. A second hash of the same address is how
161
+ * this area got two derivations that agreed only by accident; `personKey`
162
+ * is the one that normalizes and the one the unsubscribe route already
163
+ * hashes through, so a suppression filed by either is found by both.
164
+ */ return personKey(email);
165
+ }
166
+ /**
167
+ * Record a platform-wide suppression. Idempotent by document id.
168
+ *
169
+ * `createdAt` is stamped only when the document is new, matching the per-host
170
+ * list: a second bounce must not overwrite the moment the address first went
171
+ * bad, because that is the date a human is told when they ask. `suppressedAt`
172
+ * moves every time, so "when did we last see this fail" stays answerable.
173
+ *
174
+ * A previously released record is un-released — a fresh failure is a fresh
175
+ * failure.
176
+ *
177
+ * @returns `created: false` when the address was already on the list.
178
+ */ export async function suppressEmail(input) {
179
+ var _input_firestore, _input_context, _input_hostId;
180
+ const key = emailSuppressionKey(input.email);
181
+ if (!key) {
182
+ throw new Error('[email-suppression] cannot key a suppression for that value');
183
+ }
184
+ if (!PLATFORM_SUPPRESSION_REASONS.includes(input.reason)) {
185
+ throw new Error(`[email-suppression] ${input.reason} is a per-site preference and ` + 'cannot be filed platform-wide');
186
+ }
187
+ const db = (_input_firestore = input.firestore) != null ? _input_firestore : defaultFirestore();
188
+ const ref = db.collection(EMAIL_SUPPRESSIONS_COLLECTION).doc(key);
189
+ const snapshot = await ref.get();
190
+ await ref.set(_extends({
191
+ email: String(input.email).trim().toLowerCase(),
192
+ reason: input.reason,
193
+ context: (_input_context = input.context) != null ? _input_context : null,
194
+ hostId: (_input_hostId = input.hostId) != null ? _input_hostId : null,
195
+ releasedAt: null,
196
+ suppressedAt: FieldValue.serverTimestamp()
197
+ }, snapshot.exists ? {} : {
198
+ createdAt: FieldValue.serverTimestamp()
199
+ }), {
200
+ merge: true
201
+ });
202
+ return {
203
+ key,
204
+ created: !snapshot.exists
205
+ };
206
+ }
207
+ /**
208
+ * Put an address back in circulation (a staff correction, or the person asking
209
+ * to be re-added). The record is kept and marked released, never deleted —
210
+ * same reasoning as `releasePhoneContact`: a deleted record cannot show that
211
+ * the suppression was honored while it stood.
212
+ *
213
+ * Unconditional on the reason, and that is what separates it from
214
+ * {@link releaseEmailForConfirmedOptIn}: a human with the staff role has read
215
+ * the record and is accountable for the row, so they may lift a complaint —
216
+ * a report filed against the wrong message, an address entered by mistake.
217
+ * Nothing automatic gets that latitude.
218
+ *
219
+ * @returns false when there was no live record to release.
220
+ */ export async function releaseEmail(input) {
221
+ var _input_firestore, _input_releasedByUid, _input_note;
222
+ const key = emailSuppressionKey(input.email);
223
+ if (!key) return false;
224
+ const db = (_input_firestore = input.firestore) != null ? _input_firestore : defaultFirestore();
225
+ const ref = db.collection(EMAIL_SUPPRESSIONS_COLLECTION).doc(key);
226
+ const snapshot = await ref.get();
227
+ if (!snapshot.exists || snapshot.get('releasedAt')) return false;
228
+ await ref.set({
229
+ releasedAt: FieldValue.serverTimestamp(),
230
+ releasedByUid: (_input_releasedByUid = input.releasedByUid) != null ? _input_releasedByUid : null,
231
+ releasedNote: (_input_note = input.note) != null ? _input_note : null,
232
+ releasedVia: 'staff'
233
+ }, {
234
+ merge: true
235
+ });
236
+ return true;
237
+ }
238
+ /**
239
+ * The ONLY reason a completed round trip may lift, as a runtime set.
240
+ *
241
+ * ## Why a bounce is releasable
242
+ *
243
+ * A `bounce` record is a claim about a MAILBOX at a moment: mail addressed
244
+ * here was permanently refused. Somebody clicking a confirmation link that
245
+ * was delivered to that mailbox has refuted the claim with the only evidence
246
+ * that could refute it — the message arrived, a human read it, and the round
247
+ * trip closed. Leaving the record standing after that makes one transient
248
+ * failure recorded as permanent — a mailbox that was full, a receiving server
249
+ * that answered 550 while it was misconfigured — a life sentence no route can
250
+ * undo.
251
+ *
252
+ * ## Why a complaint is NOT, and never will be
253
+ *
254
+ * `complaint` is not a deliverability fact. It is a person stating they do not
255
+ * want this mail, and a round trip proves nothing about that statement — it
256
+ * proves the mailbox works, which nobody doubted. Releasing one here would
257
+ * make a public signup form into a laundry for spam complaints: submit the
258
+ * complainant's address, they receive a confirmation (the shared sender is
259
+ * transactional and consults no list), and one click anywhere in the chain
260
+ * puts them back on the sending domain that the complaint was filed against.
261
+ * The same reasoning refuses `staff`, which is a written request, a
262
+ * correction, or a legal instruction, and is nobody's to reverse from a link.
263
+ *
264
+ * A runtime set and not just the type, for the reason
265
+ * {@link PLATFORM_SUPPRESSION_REASONS} gives: reasons arrive from webhook
266
+ * payloads through an untyped boundary, and the cost of the type being wrong
267
+ * once here is a complaint silently laundered.
268
+ */ export const OPT_IN_RELEASABLE_REASONS = [
269
+ 'bounce'
270
+ ];
271
+ /**
272
+ * Lift a platform suppression that a completed double opt-in has disproved.
273
+ *
274
+ * THE ONE PLACE THE AUTOMATIC RULE IS STATED, mirroring
275
+ * `releaseSiteSuppression` for the per-site list: every path that puts an
276
+ * address back in circulation without a human deciding goes through here, so
277
+ * there is one line to read and one line to change.
278
+ *
279
+ * ## Platform-wide, from one site's round trip
280
+ *
281
+ * The record being lifted asserts something host-independent — this mailbox
282
+ * does not exist, learned anywhere in the product, including on transactional
283
+ * mail that carried no site tag. A confirmation delivered to that mailbox
284
+ * disproves it just as host-independently, so scoping the release to the
285
+ * confirming site would leave a record standing that says the mailbox is dead
286
+ * while we hold proof that it is not. The site and the topic are written onto
287
+ * the record instead, which is what makes the release reviewable: an operator
288
+ * reading the row sees which site's round trip lifted it and when.
289
+ *
290
+ * ## The per-site list is NOT touched
291
+ *
292
+ * `hosts/{hostId}/suppressions` mixes a deliverability fact with a stated
293
+ * preference — an unsubscribe from that one site lives there too — and the
294
+ * email plugin's `releaseSiteSuppression` is the single guarded path that
295
+ * lifts one. Reaching around it from here would put a second, differently
296
+ * reasoned releaser on a list whose whole protection is that there is one.
297
+ *
298
+ * Never throws: it runs inside a recipient's confirmation click, and a
299
+ * Firestore failure must degrade to a suppression that stays in force, not to
300
+ * a person told their confirmation failed.
301
+ */ export async function releaseEmailForConfirmedOptIn(input) {
302
+ const key = emailSuppressionKey(input.email);
303
+ if (!key) return 'nothing-to-release';
304
+ try {
305
+ var _input_firestore;
306
+ const db = (_input_firestore = input.firestore) != null ? _input_firestore : defaultFirestore();
307
+ const ref = db.collection(EMAIL_SUPPRESSIONS_COLLECTION).doc(key);
308
+ const snapshot = await ref.get();
309
+ if (!snapshot.exists || snapshot.get('releasedAt')) {
310
+ return 'nothing-to-release';
311
+ }
312
+ if (!OPT_IN_RELEASABLE_REASONS.includes(snapshot.get('reason'))) {
313
+ return 'refused';
314
+ }
315
+ await ref.set({
316
+ releasedAt: FieldValue.serverTimestamp(),
317
+ // No human released this, so the field says so rather than naming
318
+ // whoever last touched the record.
319
+ releasedByUid: null,
320
+ releasedVia: 'double-opt-in',
321
+ releasedHostId: input.hostId || null,
322
+ releasedTopicId: input.topicId || null
323
+ }, {
324
+ merge: true
325
+ });
326
+ return 'released';
327
+ } catch (error) {
328
+ console.error('[email-suppression] opt-in release failed; suppression stands', error);
329
+ return 'failed';
330
+ }
331
+ }
332
+ /**
333
+ * The BULK-SEND gate. See the module note for which senders must call this and
334
+ * which must not.
335
+ *
336
+ * FAILS CLOSED, like `isPhoneContactSuppressed`: a read that throws answers
337
+ * `true`, meaning "treat as suppressed". The cost of failing closed here is
338
+ * one delayed informational email — every caller is a cron that runs again —
339
+ * and it is nearly free besides, because every one of them is already deep
340
+ * inside a Firestore-backed sweep that a Firestore outage has stopped anyway.
341
+ * The cost of failing open is another delivery attempt at a mailbox that has
342
+ * already told us permanently that it does not exist, which is precisely the
343
+ * behaviour a provider scores a sending domain on. Never "fix" a flaky read
344
+ * here by returning false.
345
+ */ export async function isEmailSuppressed(email, injectedFirestore) {
346
+ const key = emailSuppressionKey(email);
347
+ // An unusable value is one we cannot check against the list, so it is one we
348
+ // must not send to. Same fail-closed rule.
349
+ if (!key) return true;
350
+ try {
351
+ const db = injectedFirestore != null ? injectedFirestore : defaultFirestore();
352
+ const snapshot = await db.collection(EMAIL_SUPPRESSIONS_COLLECTION).doc(key).get();
353
+ if (!snapshot.exists) return false;
354
+ return !snapshot.get('releasedAt');
355
+ } catch (error) {
356
+ console.error('[email-suppression] lookup failed; failing closed', error);
357
+ return true;
358
+ }
359
+ }
360
+ /**
361
+ * The sendable subset of a recipient list, for the bulk senders.
362
+ *
363
+ * One `get()` per DISTINCT address rather than a query, so the check needs no
364
+ * index and cannot fail open on a missing one. The list is deduplicated first
365
+ * because the callers build it by fanning out over an org's owners and admins,
366
+ * which routinely names the same person twice.
367
+ */ export async function filterSuppressedEmails(emails, injectedFirestore) {
368
+ const seen = new Set();
369
+ const candidates = [];
370
+ for (const email of emails){
371
+ const normalized = String(email != null ? email : '').trim().toLowerCase();
372
+ if (!normalized || seen.has(normalized)) continue;
373
+ seen.add(normalized);
374
+ candidates.push(normalized);
375
+ }
376
+ const verdicts = await Promise.all(candidates.map((email)=>isEmailSuppressed(email, injectedFirestore)));
377
+ return candidates.filter((_email, index)=>!verdicts[index]);
378
+ }
379
+ /**
380
+ * The sendable subset for a send made in ONE SITE's name — BOTH lists.
381
+ *
382
+ * A per-site suppression says "not from this site". A platform suppression
383
+ * says the address hard-bounced or somebody pressed "report spam", learned
384
+ * anywhere in the product — including on transactional mail that carried no
385
+ * site tag at all and could therefore never have reached the per-site list.
386
+ * Consulting only the site's own list mails a known-dead or complaining
387
+ * address from the one shared sending domain every tenant's mail leaves by,
388
+ * which makes it every tenant's deliverability problem rather than one
389
+ * merchant's.
390
+ *
391
+ * Composed from {@link filterSuppressedEmails} rather than reimplementing the
392
+ * platform half: normalization, de-duplication and the fail-closed posture
393
+ * live there, and a second copy of them is a second set of rules for two
394
+ * senders to disagree about.
395
+ *
396
+ * ## Both halves fail CLOSED
397
+ *
398
+ * A read that throws answers "suppressed". The platform half already does; the
399
+ * per-site half matches it, because a list we could not read is not a list
400
+ * that said this address is safe to mail. The cost of the other choice is a
401
+ * message delivered to somebody who asked us to stop.
402
+ *
403
+ * ## One `getAll`, keyed, rather than a scan of the collection
404
+ *
405
+ * The per-site half looks up exactly the addresses being mailed, by document
406
+ * id, in one round trip. Reading the whole collection instead — which is what
407
+ * the campaign sender did — is bounded by however large the collection has
408
+ * grown, so a site with more suppressions than the read window fails OPEN on
409
+ * the remainder: the people most certain not to want the mail are the ones a
410
+ * truncated read drops.
411
+ */ export async function filterSendableForHost(hostId, emails, injectedFirestore) {
412
+ const platformSendable = await filterSuppressedEmails(emails, injectedFirestore);
413
+ // `getAll` rejects an empty reference list, and there is nothing to ask.
414
+ if (!platformSendable.length) return [];
415
+ const db = injectedFirestore != null ? injectedFirestore : defaultFirestore();
416
+ const hostList = db.collection('hosts').doc(hostId).collection(HOST_SUPPRESSIONS_SUBCOLLECTION);
417
+ // Every survivor of the platform half is keyable — `isEmailSuppressed`
418
+ // answers `true` for an address it cannot key — so this narrows the type
419
+ // rather than dropping anybody.
420
+ const keyed = [];
421
+ for (const email of platformSendable){
422
+ const key = emailSuppressionKey(email);
423
+ if (key) keyed.push({
424
+ email,
425
+ key
426
+ });
427
+ }
428
+ if (!keyed.length) return [];
429
+ try {
430
+ const snapshots = await db.getAll(...keyed.map((entry)=>hostList.doc(entry.key)));
431
+ return keyed.filter((_entry, index)=>{
432
+ var _snapshots_index;
433
+ return !((_snapshots_index = snapshots[index]) == null ? void 0 : _snapshots_index.exists);
434
+ }).map((entry)=>entry.email);
435
+ } catch (error) {
436
+ console.error('[email-suppression] per-site lookup failed; failing closed', error);
437
+ return [];
438
+ }
439
+ }
440
+ /**
441
+ * The subset of `emails` that may be mailed about `topicId` on this site.
442
+ *
443
+ * The third filter a campaign passes, after the platform list and the site's
444
+ * own: the two suppression lists answer "may we mail this person at all", and
445
+ * this answers "may we mail them about THIS". A recipient who unticked
446
+ * "Promotions and offers" on the preference page is not suppressed — they
447
+ * still get the newsletter — so the fact cannot live on either suppression
448
+ * list without meaning something it does not mean.
449
+ *
450
+ * ## Two ways to be excluded, and both are held here
451
+ *
452
+ * Somebody who LEFT the stream, and somebody who has been asked to confirm
453
+ * joining it and has not. The second is what makes a double opt-in worth
454
+ * recording: an unconfirmed subscriber has to be a real quarantine, not a
455
+ * field the send path never looks at. Both come back from
456
+ * `readTopicSubscriptionState`, which is the only place the three states are
457
+ * decided.
458
+ *
459
+ * Keyed by {@link emailSuppressionKey} and read with one `getAll`, which is
460
+ * both halves of the point: the same derivation as the two lists it runs
461
+ * beside, so one person is one document id everywhere; and one round trip
462
+ * bounded by the size of the send, so adding topics does not make a campaign
463
+ * cost more to resolve.
464
+ *
465
+ * ## This one fails OPEN, and that is the opposite of its neighbors
466
+ *
467
+ * Every other filter in this module answers "suppressed" when a read throws,
468
+ * because the cost of guessing wrong is mailing somebody who told us to stop.
469
+ * Here the cost of guessing wrong in that direction is refusing to send a
470
+ * newsletter somebody asked for, on a read that failed for an unrelated
471
+ * reason — and the campaign has already passed both suppression lists, so
472
+ * nobody who asked us to stop entirely can reach this line. A topic
473
+ * preference is a narrower fact than a suppression and it gets the treatment
474
+ * that matches. A caller that wants the strict posture already has it one
475
+ * layer up.
476
+ *
477
+ * An empty `topicId` is a campaign from before topics existed, or one whose
478
+ * topic was never resolved. It filters nobody: there is no stream to have
479
+ * left.
480
+ */ export async function filterTopicSendable(hostId, topicId, emails, injectedFirestore) {
481
+ const topic = String(topicId != null ? topicId : '').trim();
482
+ if (!topic || !emails.length) return [
483
+ ...emails
484
+ ];
485
+ // An unkeyable address cannot carry an opt-out record, so it cannot have
486
+ // left this topic. It is dropped from the LOOKUP and kept in the answer —
487
+ // the suppression filters above have already refused it on their own
488
+ // stricter rule, so this one has no business refusing it a second time.
489
+ const lookups = [];
490
+ for (const email of emails){
491
+ const key = emailSuppressionKey(email);
492
+ if (key) lookups.push({
493
+ email,
494
+ key
495
+ });
496
+ }
497
+ if (!lookups.length) return [
498
+ ...emails
499
+ ];
500
+ try {
501
+ const db = injectedFirestore != null ? injectedFirestore : defaultFirestore();
502
+ const optOuts = db.collection('hosts').doc(hostId).collection(TOPIC_OPT_OUTS_SUBCOLLECTION);
503
+ const snapshots = await db.getAll(...lookups.map((entry)=>optOuts.doc(entry.key)));
504
+ const gone = new Set();
505
+ lookups.forEach((entry, index)=>{
506
+ var _snapshot_get;
507
+ const snapshot = snapshots[index];
508
+ if (!(snapshot == null ? void 0 : snapshot.exists)) return;
509
+ /*
510
+ * The shared state reader, never a field test written out here.
511
+ *
512
+ * An entry means one of three things and only that function knows all
513
+ * three. The shorthand this replaced — "an entry with no
514
+ * `resubscribedAt` is a live opt-out" — reads a CONFIRMED double
515
+ * opt-in, which carries `pendingAt` and `confirmedAt` and no
516
+ * `resubscribedAt`, as somebody who left.
517
+ */ const record = ((_snapshot_get = snapshot.get('topics')) != null ? _snapshot_get : {})[topic];
518
+ if (readTopicSubscriptionState(record) !== 'subscribed') {
519
+ gone.add(entry.email);
520
+ }
521
+ });
522
+ return emails.filter((email)=>!gone.has(email));
523
+ } catch (error) {
524
+ console.error('[email-suppression] topic opt-out lookup failed; failing open', error);
525
+ return [
526
+ ...emails
527
+ ];
528
+ }
529
+ }
530
+ /*
531
+ * THE FOURTH FILTER IS NOT IN THIS FILE, and where it is is forced.
532
+ *
533
+ * `filterCadenceSendable` — the subset that has not asked this site for mail
534
+ * less often than right now — lives in `email-marketing-gate.ts`, because it
535
+ * reads the per-recipient counter document that module owns and names. That
536
+ * module already imports this one for the two suppression lists, so putting
537
+ * the cadence filter here would close a cycle. A campaign's subtraction chain
538
+ * therefore reads: this file's two lists, this file's topic opt-outs, then
539
+ * that file's cadence.
540
+ */ /**
541
+ * The staff queue, newest first, ordered by `suppressedAt` so a re-recorded or
542
+ * released entry surfaces again — the operator's question is "what changed",
543
+ * not "what was first written". Mirrors `listContactSuppressions`.
544
+ */ export async function listEmailSuppressions(options) {
545
+ var _ref, _ref1;
546
+ const db = (_ref = options == null ? void 0 : options.firestore) != null ? _ref : defaultFirestore();
547
+ let query = db.collection(EMAIL_SUPPRESSIONS_COLLECTION).orderBy('suppressedAt', 'desc');
548
+ const cursor = suppressionCursorTimestamp(options == null ? void 0 : options.startAfter);
549
+ if (cursor) query = query.startAfter(cursor);
550
+ const snapshot = await query.limit(Math.min(Math.max((_ref1 = options == null ? void 0 : options.limit) != null ? _ref1 : 100, 1), 500)).get();
551
+ return snapshot.docs.map((doc)=>_extends({
552
+ $id: doc.id
553
+ }, doc.data()));
554
+ }
555
+ /**
556
+ * The cursor a page hands back, from the last row on it.
557
+ *
558
+ * Null when the row carries no `suppressedAt` — every entry written since
559
+ * AGL-1918 does, and `orderBy` has already excluded any that does not, so
560
+ * this is the type narrowing rather than a case that occurs.
561
+ */ export function suppressionCursorFrom(record) {
562
+ var _ref, _ref1, _ref2;
563
+ const at = record == null ? void 0 : record['suppressedAt'];
564
+ const seconds = (_ref = at == null ? void 0 : at.seconds) != null ? _ref : at == null ? void 0 : at._seconds;
565
+ if (typeof seconds !== 'number') return null;
566
+ const nanoseconds = (_ref1 = (_ref2 = at == null ? void 0 : at.nanoseconds) != null ? _ref2 : at == null ? void 0 : at._nanoseconds) != null ? _ref1 : 0;
567
+ return `${seconds}.${nanoseconds}`;
568
+ }
569
+ /** The inverse, for the query. Invalid input yields no cursor, never a guess. */ export function suppressionCursorTimestamp(cursor) {
570
+ const [rawSeconds, rawNanos] = String(cursor != null ? cursor : '').split('.');
571
+ const seconds = Number(rawSeconds);
572
+ const nanoseconds = Number(rawNanos != null ? rawNanos : 0);
573
+ if (!Number.isFinite(seconds) || !seconds) return null;
574
+ return new Timestamp(seconds, Number.isFinite(nanoseconds) ? nanoseconds : 0);
575
+ }
576
+ /*==========================================
577
+ * THE ERASURE ROW ON THE PER-SITE LIST (AGL-2623).
578
+ *
579
+ * A person erased from a workspace must not be quietly rebuilt by the next
580
+ * form they fill in or the next order they place, and must not be mailed by
581
+ * a campaign either. Both gates already read `hosts/{hostId}/suppressions`
582
+ * — every campaign filter refuses an address with a row there — so the
583
+ * erasure writes one row per site of the workspace rather than inventing a
584
+ * third list, and the capture door reads the same row.
585
+ *
586
+ * The row carries NO address. Every other writer of this list stores the
587
+ * email in the clear beside the hash, because a hub admin releasing an
588
+ * unsubscribe needs to see who it was; an erasure row is the one whose
589
+ * whole purpose is that the address is no longer held, so the id — the
590
+ * hash — is the entire record, and a row that already held the address in
591
+ * the clear has it removed. The hub's list renders such a row as an entry
592
+ * with no address, which it already knows how to do.
593
+ *
594
+ * Per SITE, not platform-wide, on purpose: the erasure was asked of one
595
+ * workspace, and a second workspace that knows the same person has a
596
+ * relationship this request has no claim on. The platform list is for
597
+ * bounces and complaints, which are facts about the address everywhere.
598
+ *=========================================*/ /** The `reason` an erasure row carries. Read by the capture door, below. */ export const HOST_ERASURE_SUPPRESSION_REASON = 'erasure';
599
+ /**
600
+ * Suppress an address on one site because the person was erased. Idempotent:
601
+ * a second erasure of the same person merges onto the same row.
602
+ */ export async function suppressEmailForHostErasure(input) {
603
+ var _input_firestore;
604
+ const key = emailSuppressionKey(input.email);
605
+ if (!key) return null;
606
+ const db = (_input_firestore = input.firestore) != null ? _input_firestore : defaultFirestore();
607
+ const ref = db.collection('hosts').doc(input.hostId).collection(HOST_SUPPRESSIONS_SUBCOLLECTION).doc(key);
608
+ const snapshot = await ref.get();
609
+ await ref.set(_extends({
610
+ email: null,
611
+ reason: HOST_ERASURE_SUPPRESSION_REASON,
612
+ suppressedAt: FieldValue.serverTimestamp()
613
+ }, snapshot.exists ? {} : {
614
+ createdAt: FieldValue.serverTimestamp()
615
+ }), {
616
+ merge: true
617
+ });
618
+ return {
619
+ key,
620
+ created: !snapshot.exists
621
+ };
622
+ }
623
+ /**
624
+ * Whether a site has erased this address, so a capture must not create a
625
+ * contact for it. Only an ERASURE row refuses: an ordinary unsubscribe is a
626
+ * mailing preference, and a person who unsubscribed and then bought
627
+ * something is still a customer whose order the CRM should know about.
628
+ *
629
+ * Fails OPEN. A read that throws answers `false` and logs: the alternative
630
+ * refuses every capture on the site for as long as the list is unreadable,
631
+ * which turns a transient read failure into a silent drop of the site's
632
+ * leads and orders. The window this leaves — a recreate during an outage
633
+ * of the suppression read — is logged, and the next erasure run finds the
634
+ * recreated record by the same address.
635
+ */ export async function hostRefusesCaptureForErasure(hostId, email, injectedFirestore) {
636
+ const key = emailSuppressionKey(email);
637
+ if (!key) return false;
638
+ try {
639
+ const db = injectedFirestore != null ? injectedFirestore : defaultFirestore();
640
+ const snapshot = await db.collection('hosts').doc(hostId).collection(HOST_SUPPRESSIONS_SUBCOLLECTION).doc(key).get();
641
+ return Boolean(snapshot == null ? void 0 : snapshot.exists) && snapshot.get('reason') === HOST_ERASURE_SUPPRESSION_REASON;
642
+ } catch (error) {
643
+ console.error('[email-suppression] erasure lookup failed; the capture proceeds', error);
644
+ return false;
645
+ }
646
+ }
647
+
648
+ //# sourceMappingURL=email-suppression.js.map