@simplelayer/graniteer-core 0.2.2 → 0.3.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 (479) hide show
  1. package/dist/adminBookingCredit.d.ts +107 -0
  2. package/dist/adminBookingCredit.js +163 -0
  3. package/dist/agreementCheckout.d.ts +34 -0
  4. package/dist/agreementCheckout.js +211 -0
  5. package/dist/agreementPortalEmail.d.ts +15 -0
  6. package/dist/agreementPortalEmail.js +107 -0
  7. package/dist/availability.d.ts +51 -0
  8. package/dist/availability.js +152 -0
  9. package/dist/billingPortalLinkEmail.d.ts +14 -0
  10. package/dist/billingPortalLinkEmail.js +98 -0
  11. package/dist/bookingAgreementEmail.d.ts +23 -0
  12. package/dist/bookingAgreementEmail.js +116 -0
  13. package/dist/bookingEffects.d.ts +84 -0
  14. package/dist/bookingEffects.js +309 -0
  15. package/dist/bookingHoldReclaim.d.ts +16 -0
  16. package/dist/bookingHoldReclaim.js +74 -0
  17. package/dist/busClient.d.ts +44 -0
  18. package/dist/busClient.js +196 -0
  19. package/dist/busSignature.d.ts +19 -0
  20. package/{src/busSignature.ts → dist/busSignature.js} +64 -71
  21. package/dist/checkoutCoupon.d.ts +156 -0
  22. package/dist/checkoutCoupon.js +369 -0
  23. package/dist/checkoutSessionParams.d.ts +32 -0
  24. package/dist/checkoutSessionParams.js +72 -0
  25. package/dist/commonsContract.d.ts +70 -0
  26. package/dist/commonsContract.js +142 -0
  27. package/dist/commonsDeposit.d.ts +78 -0
  28. package/dist/commonsDeposit.js +199 -0
  29. package/dist/commonsDepositWebhook.d.ts +37 -0
  30. package/dist/commonsDepositWebhook.js +147 -0
  31. package/dist/conductorAdmin.d.ts +76 -0
  32. package/dist/conductorAdmin.js +88 -0
  33. package/dist/dayPassConfirmation.d.ts +17 -0
  34. package/dist/dayPassConfirmation.js +187 -0
  35. package/dist/dunningEmails.d.ts +40 -0
  36. package/dist/dunningEmails.js +174 -0
  37. package/dist/email-templates/brand.d.ts +82 -0
  38. package/dist/email-templates/brand.js +72 -0
  39. package/dist/email-templates/email-change.d.ts +10 -0
  40. package/dist/email-templates/email-change.js +50 -0
  41. package/dist/email-templates/invite.d.ts +8 -0
  42. package/dist/email-templates/invite.js +44 -0
  43. package/dist/email-templates/magic-link.d.ts +10 -0
  44. package/dist/email-templates/magic-link.js +26 -0
  45. package/dist/email-templates/reauthentication.d.ts +6 -0
  46. package/dist/email-templates/reauthentication.js +35 -0
  47. package/dist/email-templates/recovery.d.ts +10 -0
  48. package/dist/email-templates/recovery.js +26 -0
  49. package/dist/email-templates/signup.d.ts +12 -0
  50. package/dist/email-templates/signup.js +30 -0
  51. package/dist/entitlements.d.ts +17 -0
  52. package/dist/entitlements.js +33 -0
  53. package/dist/functions/admin-cancel-membership.d.ts +3 -0
  54. package/dist/functions/admin-cancel-membership.js +294 -0
  55. package/dist/functions/admin-change-membership-plan.d.ts +3 -0
  56. package/dist/functions/admin-change-membership-plan.js +289 -0
  57. package/dist/functions/admin-charge-guest-print.d.ts +1 -0
  58. package/dist/functions/admin-charge-guest-print.js +227 -0
  59. package/dist/functions/admin-correct-booking.d.ts +1 -0
  60. package/dist/functions/admin-correct-booking.js +326 -0
  61. package/dist/functions/admin-create-booking.d.ts +43 -0
  62. package/dist/functions/admin-create-booking.js +410 -0
  63. package/dist/functions/admin-create-commons-event.d.ts +1 -0
  64. package/dist/functions/admin-create-commons-event.js +237 -0
  65. package/dist/functions/admin-debug-boldsign-doc.d.ts +1 -0
  66. package/dist/functions/admin-debug-boldsign-doc.js +110 -0
  67. package/dist/functions/admin-door-write.d.ts +1 -0
  68. package/dist/functions/admin-door-write.js +267 -0
  69. package/dist/functions/admin-issue-day-pass.d.ts +14 -0
  70. package/dist/functions/admin-issue-day-pass.js +213 -0
  71. package/dist/functions/admin-mark-booking-paid.d.ts +1 -0
  72. package/dist/functions/admin-mark-booking-paid.js +202 -0
  73. package/dist/functions/admin-mint-billing-portal-link.d.ts +6 -0
  74. package/dist/functions/admin-mint-billing-portal-link.js +159 -0
  75. package/dist/functions/admin-mint-portal-link.d.ts +3 -0
  76. package/dist/functions/admin-mint-portal-link.js +54 -0
  77. package/dist/functions/admin-onboard-connect-account.d.ts +47 -0
  78. package/dist/functions/admin-onboard-connect-account.js +197 -0
  79. package/dist/functions/admin-photo-upload.d.ts +1 -0
  80. package/dist/functions/admin-photo-upload.js +104 -0
  81. package/dist/functions/admin-remove-team-member.d.ts +1 -0
  82. package/dist/functions/admin-remove-team-member.js +140 -0
  83. package/dist/functions/admin-request-trial.d.ts +5 -0
  84. package/dist/functions/admin-request-trial.js +349 -0
  85. package/dist/functions/admin-resend-commons-deposit-link.d.ts +7 -0
  86. package/dist/functions/admin-resend-commons-deposit-link.js +298 -0
  87. package/dist/functions/admin-reset-mfa.d.ts +1 -0
  88. package/dist/functions/admin-reset-mfa.js +129 -0
  89. package/dist/functions/admin-retry-invoice-payment.d.ts +76 -0
  90. package/dist/functions/admin-retry-invoice-payment.js +269 -0
  91. package/dist/functions/admin-reverse-coupon-redemption.d.ts +1 -0
  92. package/dist/functions/admin-reverse-coupon-redemption.js +91 -0
  93. package/dist/functions/admin-revoke-agreement.d.ts +4 -0
  94. package/dist/functions/admin-revoke-agreement.js +410 -0
  95. package/dist/functions/admin-send-commons-agreement.d.ts +1 -0
  96. package/dist/functions/admin-send-commons-agreement.js +212 -0
  97. package/dist/functions/admin-set-credit-amount.d.ts +1 -0
  98. package/dist/functions/admin-set-credit-amount.js +112 -0
  99. package/dist/functions/admin-skip-commons-contract.d.ts +1 -0
  100. package/dist/functions/admin-skip-commons-contract.js +170 -0
  101. package/dist/functions/admin-undo-membership-cancel.d.ts +3 -0
  102. package/dist/functions/admin-undo-membership-cancel.js +143 -0
  103. package/dist/functions/admin-wall-photo-write.d.ts +1 -0
  104. package/dist/functions/admin-wall-photo-write.js +137 -0
  105. package/dist/functions/auth-email-hook.d.ts +20 -0
  106. package/dist/functions/auth-email-hook.js +209 -0
  107. package/dist/functions/boldsign-sender-identity.d.ts +1 -0
  108. package/dist/functions/boldsign-sender-identity.js +109 -0
  109. package/dist/functions/booking-availability.d.ts +1 -0
  110. package/dist/functions/booking-availability.js +355 -0
  111. package/dist/functions/booking-member-preview.d.ts +1 -0
  112. package/dist/functions/booking-member-preview.js +123 -0
  113. package/dist/functions/booking-status.d.ts +3 -0
  114. package/dist/functions/booking-status.js +139 -0
  115. package/dist/functions/conductor.d.ts +3 -0
  116. package/dist/functions/conductor.js +451 -0
  117. package/dist/functions/create-agreement.d.ts +8 -0
  118. package/dist/functions/create-agreement.js +498 -0
  119. package/dist/functions/create-booking.d.ts +44 -0
  120. package/dist/functions/create-booking.js +538 -0
  121. package/dist/functions/create-day-pass-checkout.d.ts +6 -0
  122. package/dist/functions/create-day-pass-checkout.js +225 -0
  123. package/dist/functions/create-portal-session.d.ts +4 -0
  124. package/dist/functions/create-portal-session.js +127 -0
  125. package/dist/functions/create-subscription-checkout.d.ts +7 -0
  126. package/dist/functions/create-subscription-checkout.js +405 -0
  127. package/dist/functions/day-pass-status.d.ts +1 -0
  128. package/dist/functions/day-pass-status.js +70 -0
  129. package/dist/functions/dayStatus.d.ts +15 -0
  130. package/dist/functions/dayStatus.js +59 -0
  131. package/dist/functions/diag-webpush-test.d.ts +1 -0
  132. package/dist/functions/diag-webpush-test.js +42 -0
  133. package/dist/functions/event-access-admin.d.ts +17 -0
  134. package/dist/functions/event-access-admin.js +262 -0
  135. package/dist/functions/event-access-store.d.ts +1 -0
  136. package/dist/functions/event-access-store.js +343 -0
  137. package/dist/functions/ezeep-print-webhook.d.ts +1 -0
  138. package/dist/functions/ezeep-print-webhook.js +160 -0
  139. package/dist/functions/ezeep-usage-reconcile.d.ts +1 -0
  140. package/dist/functions/ezeep-usage-reconcile.js +305 -0
  141. package/dist/functions/fetch-avatar-original.d.ts +3 -0
  142. package/dist/functions/fetch-avatar-original.js +423 -0
  143. package/dist/functions/get-provider-sign-link.d.ts +3 -0
  144. package/dist/functions/get-provider-sign-link.js +146 -0
  145. package/dist/functions/get-signing-link.d.ts +1 -0
  146. package/dist/functions/get-signing-link.js +192 -0
  147. package/dist/functions/guest-print-setup-confirm.d.ts +1 -0
  148. package/dist/functions/guest-print-setup-confirm.js +126 -0
  149. package/dist/functions/guest-print-submit.d.ts +1 -0
  150. package/dist/functions/guest-print-submit.js +145 -0
  151. package/dist/functions/luma-webhook.d.ts +1 -0
  152. package/dist/functions/luma-webhook.js +123 -0
  153. package/dist/functions/manage-booking.d.ts +75 -0
  154. package/dist/functions/manage-booking.js +409 -0
  155. package/dist/functions/mcp.d.ts +16 -0
  156. package/dist/functions/mcp.js +51 -0
  157. package/dist/functions/member-door-action.d.ts +60 -0
  158. package/dist/functions/member-door-action.js +774 -0
  159. package/dist/functions/member-unifi-mapping.d.ts +15 -0
  160. package/dist/functions/member-unifi-mapping.js +198 -0
  161. package/dist/functions/membership-door-sync.d.ts +14 -0
  162. package/dist/functions/membership-door-sync.js +863 -0
  163. package/dist/functions/migration-collision-alert.copy.d.ts +7 -0
  164. package/dist/functions/migration-collision-alert.copy.js +207 -0
  165. package/dist/functions/migration-collision-alert.d.ts +7 -0
  166. package/dist/functions/migration-collision-alert.js +207 -0
  167. package/dist/functions/office-assignment-end.d.ts +12 -0
  168. package/dist/functions/office-assignment-end.js +140 -0
  169. package/dist/functions/portal-booking-access.d.ts +22 -0
  170. package/dist/functions/portal-booking-access.js +163 -0
  171. package/dist/functions/portal-list-invoices.d.ts +1 -0
  172. package/dist/functions/portal-list-invoices.js +90 -0
  173. package/dist/functions/portal-request-login.d.ts +7 -0
  174. package/dist/functions/portal-request-login.js +199 -0
  175. package/dist/functions/portal-resend-invite.d.ts +6 -0
  176. package/dist/functions/portal-resend-invite.js +225 -0
  177. package/dist/functions/portal-submit-event.d.ts +4 -0
  178. package/dist/functions/portal-submit-event.js +152 -0
  179. package/dist/functions/print-billing-recover.d.ts +1 -0
  180. package/dist/functions/print-billing-recover.js +83 -0
  181. package/dist/functions/print-billing-run.d.ts +1 -0
  182. package/dist/functions/print-billing-run.js +153 -0
  183. package/dist/functions/public-facts.d.ts +1 -0
  184. package/dist/functions/public-facts.js +141 -0
  185. package/dist/functions/push-send.d.ts +3 -0
  186. package/dist/functions/push-send.js +297 -0
  187. package/dist/functions/push-test.d.ts +3 -0
  188. package/dist/functions/push-test.js +215 -0
  189. package/dist/functions/request-portal-link.d.ts +7 -0
  190. package/dist/functions/request-portal-link.js +178 -0
  191. package/dist/functions/reschedule-booking.d.ts +50 -0
  192. package/dist/functions/reschedule-booking.js +571 -0
  193. package/dist/functions/review-ratings.d.ts +1 -0
  194. package/dist/functions/review-ratings.js +95 -0
  195. package/dist/functions/space-availability-range.d.ts +1 -0
  196. package/dist/functions/space-availability-range.js +109 -0
  197. package/dist/functions/stripe-db-reconcile.d.ts +7 -0
  198. package/dist/functions/stripe-db-reconcile.js +326 -0
  199. package/dist/functions/stripe-webhook.d.ts +46 -0
  200. package/dist/functions/stripe-webhook.js +2381 -0
  201. package/dist/functions/sync-gcal-blackouts.d.ts +1 -0
  202. package/dist/functions/sync-gcal-blackouts.js +251 -0
  203. package/dist/functions/timetable-event-register.d.ts +1 -0
  204. package/dist/functions/timetable-event-register.js +155 -0
  205. package/dist/functions/timetable-event-status.d.ts +1 -0
  206. package/dist/functions/timetable-event-status.js +86 -0
  207. package/dist/functions/timetable-spaces.d.ts +1 -0
  208. package/dist/functions/timetable-spaces.js +161 -0
  209. package/dist/functions/touch-pass-reconciler.d.ts +1 -0
  210. package/dist/functions/touch-pass-reconciler.js +688 -0
  211. package/dist/functions/touch-pass-signup.d.ts +1 -0
  212. package/dist/functions/touch-pass-signup.js +447 -0
  213. package/dist/functions/upload-booking-display-image.d.ts +4 -0
  214. package/dist/functions/upload-booking-display-image.js +159 -0
  215. package/dist/functions/virtual-onboarding-purge.d.ts +1 -0
  216. package/dist/functions/virtual-onboarding-purge.js +123 -0
  217. package/dist/functions/virtual-onboarding-submit.d.ts +1 -0
  218. package/dist/functions/virtual-onboarding-submit.js +303 -0
  219. package/dist/functions/voice-booking.d.ts +10 -0
  220. package/dist/functions/voice-booking.js +360 -0
  221. package/dist/functions/voice-day-pass.d.ts +15 -0
  222. package/dist/functions/voice-day-pass.js +269 -0
  223. package/dist/functions/voice-inquiry.d.ts +1 -0
  224. package/dist/functions/voice-inquiry.js +156 -0
  225. package/dist/functions/voice-membership-signup.d.ts +16 -0
  226. package/dist/functions/voice-membership-signup.js +277 -0
  227. package/dist/functions/voice-tour-availability.d.ts +1 -0
  228. package/dist/functions/voice-tour-availability.js +179 -0
  229. package/dist/functions/voice-tour-booking.d.ts +21 -0
  230. package/dist/functions/voice-tour-booking.js +308 -0
  231. package/dist/gcalSync.d.ts +29 -0
  232. package/dist/gcalSync.js +119 -0
  233. package/dist/ghlEventInquiry.d.ts +16 -0
  234. package/dist/ghlEventInquiry.js +116 -0
  235. package/dist/ghlNote.d.ts +5 -0
  236. package/dist/ghlNote.js +29 -0
  237. package/dist/ghlTask.d.ts +7 -0
  238. package/dist/ghlTask.js +39 -0
  239. package/dist/ghlVoiceInquiry.d.ts +26 -0
  240. package/dist/ghlVoiceInquiry.js +68 -0
  241. package/dist/guestPrintCapture.d.ts +217 -0
  242. package/dist/guestPrintCapture.js +362 -0
  243. package/dist/index.d.ts +3 -0
  244. package/{index.js → dist/index.js} +3 -2
  245. package/dist/lumaGhl.d.ts +19 -0
  246. package/dist/lumaGhl.js +147 -0
  247. package/dist/mailArrivalEmail.d.ts +15 -0
  248. package/dist/mailArrivalEmail.js +99 -0
  249. package/dist/manageToken.d.ts +64 -0
  250. package/dist/manageToken.js +261 -0
  251. package/dist/membership.d.ts +20 -0
  252. package/dist/membership.js +87 -0
  253. package/dist/membershipBusClient.d.ts +139 -0
  254. package/dist/membershipBusClient.js +443 -0
  255. package/dist/membershipWelcome.d.ts +117 -0
  256. package/dist/membershipWelcome.js +497 -0
  257. package/dist/migrationCheckout.d.ts +169 -0
  258. package/dist/migrationCheckout.js +250 -0
  259. package/dist/money.d.ts +20 -0
  260. package/dist/money.js +35 -0
  261. package/dist/ops.d.ts +27 -0
  262. package/dist/ops.js +87 -0
  263. package/dist/pacificDate.d.ts +8 -0
  264. package/{src/pacificDate.ts → dist/pacificDate.js} +76 -88
  265. package/dist/paymentLinkEmail.d.ts +15 -0
  266. package/dist/paymentLinkEmail.js +102 -0
  267. package/dist/policyAcknowledgment.d.ts +46 -0
  268. package/dist/policyAcknowledgment.js +58 -0
  269. package/dist/portalSession.d.ts +15 -0
  270. package/dist/portalSession.js +31 -0
  271. package/dist/pricing.d.ts +306 -0
  272. package/dist/pricing.js +788 -0
  273. package/dist/printBilling.d.ts +340 -0
  274. package/dist/printBilling.js +619 -0
  275. package/dist/printBillingAdapters.d.ts +29 -0
  276. package/dist/printBillingAdapters.js +130 -0
  277. package/dist/printCorrections.d.ts +175 -0
  278. package/dist/printCorrections.js +328 -0
  279. package/dist/rateLimit.d.ts +20 -0
  280. package/dist/rateLimit.js +70 -0
  281. package/dist/referralCredits.d.ts +5 -0
  282. package/{src/referralCredits.ts → dist/referralCredits.js} +27 -34
  283. package/dist/referralGrant.d.ts +49 -0
  284. package/dist/referralGrant.js +268 -0
  285. package/dist/rescheduleCredit.d.ts +98 -0
  286. package/dist/rescheduleCredit.js +263 -0
  287. package/dist/reservationWifiCode.d.ts +19 -0
  288. package/{src/reservationWifiCode.ts → dist/reservationWifiCode.js} +67 -81
  289. package/dist/retellCallAnalyzed.d.ts +18 -0
  290. package/dist/retellCallAnalyzed.js +91 -0
  291. package/dist/retellSignature.d.ts +14 -0
  292. package/dist/retellSignature.js +60 -0
  293. package/dist/signedUnpaidReminderEmail.d.ts +15 -0
  294. package/dist/signedUnpaidReminderEmail.js +111 -0
  295. package/dist/slackAlert.d.ts +13 -0
  296. package/dist/slackAlert.js +37 -0
  297. package/dist/stripeCoworkingPortal.d.ts +21 -0
  298. package/dist/stripeCoworkingPortal.js +80 -0
  299. package/dist/supabaseTestFakes.d.ts +67 -0
  300. package/dist/supabaseTestFakes.js +79 -0
  301. package/dist/supportTicketEmail.d.ts +16 -0
  302. package/dist/supportTicketEmail.js +98 -0
  303. package/dist/tier1Agreement.d.ts +51 -0
  304. package/dist/tier1Agreement.js +86 -0
  305. package/dist/unifiAccessPolicies.d.ts +36 -0
  306. package/dist/unifiAccessPolicies.js +185 -0
  307. package/dist/unifiGroups.d.ts +26 -0
  308. package/dist/unifiGroups.js +106 -0
  309. package/package.json +653 -169
  310. package/src/adminBookingCredit.test.ts +0 -451
  311. package/src/adminBookingCredit.ts +0 -239
  312. package/src/agreementCheckout.ts +0 -250
  313. package/src/agreementPortalEmail.ts +0 -128
  314. package/src/availability.test.ts +0 -25
  315. package/src/availability.ts +0 -201
  316. package/src/billingPortalLinkEmail.ts +0 -117
  317. package/src/bookingAgreementEmail.ts +0 -149
  318. package/src/bookingEffects.ts +0 -388
  319. package/src/bookingHoldReclaim.ts +0 -94
  320. package/src/busClient.ts +0 -268
  321. package/src/checkoutCoupon.test.ts +0 -675
  322. package/src/checkoutCoupon.ts +0 -455
  323. package/src/checkoutSessionParams.ts +0 -56
  324. package/src/commonsContract.ts +0 -175
  325. package/src/commonsDeposit.ts +0 -298
  326. package/src/commonsDepositWebhook.ts +0 -237
  327. package/src/conductorAdmin.ts +0 -141
  328. package/src/dayPassConfirmation.ts +0 -230
  329. package/src/dunningEmails.test.ts +0 -263
  330. package/src/dunningEmails.ts +0 -203
  331. package/src/email-templates/brand.ts +0 -93
  332. package/src/email-templates/email-change.tsx +0 -92
  333. package/src/email-templates/invite.tsx +0 -79
  334. package/src/email-templates/magic-link.tsx +0 -59
  335. package/src/email-templates/reauthentication.tsx +0 -60
  336. package/src/email-templates/recovery.tsx +0 -59
  337. package/src/email-templates/signup.tsx +0 -67
  338. package/src/functions/admin-cancel-membership.ts +0 -311
  339. package/src/functions/admin-change-membership-plan.ts +0 -312
  340. package/src/functions/admin-charge-guest-print.ts +0 -229
  341. package/src/functions/admin-correct-booking.ts +0 -333
  342. package/src/functions/admin-create-booking.ts +0 -460
  343. package/src/functions/admin-create-commons-event.ts +0 -244
  344. package/src/functions/admin-debug-boldsign-doc.ts +0 -93
  345. package/src/functions/admin-door-write.ts +0 -272
  346. package/src/functions/admin-issue-day-pass.ts +0 -231
  347. package/src/functions/admin-mark-booking-paid.ts +0 -203
  348. package/src/functions/admin-mint-billing-portal-link.ts +0 -168
  349. package/src/functions/admin-mint-portal-link.ts +0 -62
  350. package/src/functions/admin-photo-upload.ts +0 -128
  351. package/src/functions/admin-remove-team-member.ts +0 -150
  352. package/src/functions/admin-request-trial.ts +0 -366
  353. package/src/functions/admin-resend-commons-deposit-link.ts +0 -323
  354. package/src/functions/admin-reset-mfa.ts +0 -138
  355. package/src/functions/admin-retry-invoice-payment.test.ts +0 -567
  356. package/src/functions/admin-retry-invoice-payment.ts +0 -333
  357. package/src/functions/admin-reverse-coupon-redemption.ts +0 -98
  358. package/src/functions/admin-revoke-agreement.ts +0 -467
  359. package/src/functions/admin-send-commons-agreement.ts +0 -214
  360. package/src/functions/admin-set-credit-amount.ts +0 -123
  361. package/src/functions/admin-skip-commons-contract.ts +0 -165
  362. package/src/functions/admin-undo-membership-cancel.ts +0 -144
  363. package/src/functions/admin-wall-photo-write.ts +0 -141
  364. package/src/functions/auth-email-hook.ts +0 -259
  365. package/src/functions/boldsign-sender-identity.ts +0 -114
  366. package/src/functions/booking-availability.ts +0 -419
  367. package/src/functions/booking-member-preview.ts +0 -136
  368. package/src/functions/booking-status.ts +0 -149
  369. package/src/functions/conductor.ts +0 -505
  370. package/src/functions/create-agreement.ts +0 -537
  371. package/src/functions/create-booking.ts +0 -648
  372. package/src/functions/create-day-pass-checkout.ts +0 -218
  373. package/src/functions/create-portal-session.ts +0 -142
  374. package/src/functions/create-subscription-checkout.test.ts +0 -222
  375. package/src/functions/create-subscription-checkout.ts +0 -440
  376. package/src/functions/day-pass-status.ts +0 -89
  377. package/src/functions/dayStatus.ts +0 -71
  378. package/src/functions/diag-webpush-test.ts +0 -45
  379. package/src/functions/event-access-admin.ts +0 -277
  380. package/src/functions/event-access-store.ts +0 -334
  381. package/src/functions/ezeep-print-webhook.ts +0 -213
  382. package/src/functions/ezeep-usage-reconcile.ts +0 -299
  383. package/src/functions/fetch-avatar-original.ts +0 -457
  384. package/src/functions/get-provider-sign-link.ts +0 -155
  385. package/src/functions/get-signing-link.ts +0 -211
  386. package/src/functions/guest-print-setup-confirm.ts +0 -128
  387. package/src/functions/guest-print-submit.ts +0 -149
  388. package/src/functions/luma-webhook.ts +0 -165
  389. package/src/functions/manage-booking.ts +0 -472
  390. package/src/functions/mcp.ts +0 -67
  391. package/src/functions/member-door-action.test.ts +0 -1248
  392. package/src/functions/member-door-action.ts +0 -863
  393. package/src/functions/member-unifi-mapping.test.ts +0 -516
  394. package/src/functions/member-unifi-mapping.ts +0 -206
  395. package/src/functions/membership-door-sync.ts +0 -956
  396. package/src/functions/migration-collision-alert.copy.ts +0 -232
  397. package/src/functions/migration-collision-alert.test.ts +0 -349
  398. package/src/functions/migration-collision-alert.ts +0 -232
  399. package/src/functions/office-assignment-end.ts +0 -146
  400. package/src/functions/portal-booking-access.ts +0 -217
  401. package/src/functions/portal-list-invoices.ts +0 -99
  402. package/src/functions/portal-request-login.ts +0 -219
  403. package/src/functions/portal-resend-invite.ts +0 -248
  404. package/src/functions/portal-submit-event.ts +0 -168
  405. package/src/functions/print-billing-recover.ts +0 -97
  406. package/src/functions/print-billing-run.ts +0 -183
  407. package/src/functions/public-facts.ts +0 -168
  408. package/src/functions/push-send.ts +0 -348
  409. package/src/functions/push-test.ts +0 -234
  410. package/src/functions/request-portal-link.ts +0 -211
  411. package/src/functions/reschedule-booking.ts +0 -649
  412. package/src/functions/review-ratings.ts +0 -113
  413. package/src/functions/space-availability-range.acceptance.test.ts +0 -161
  414. package/src/functions/space-availability-range.ts +0 -142
  415. package/src/functions/stripe-db-reconcile.ts +0 -319
  416. package/src/functions/stripe-webhook.moved-regression.test.ts +0 -78
  417. package/src/functions/stripe-webhook.ts +0 -2595
  418. package/src/functions/sync-gcal-blackouts.ts +0 -298
  419. package/src/functions/timetable-event-register.ts +0 -162
  420. package/src/functions/timetable-event-status.ts +0 -90
  421. package/src/functions/timetable-spaces.ts +0 -219
  422. package/src/functions/touch-pass-reconciler.ts +0 -689
  423. package/src/functions/touch-pass-signup.ts +0 -478
  424. package/src/functions/upload-booking-display-image.ts +0 -179
  425. package/src/functions/virtual-onboarding-purge.ts +0 -134
  426. package/src/functions/virtual-onboarding-submit.ts +0 -315
  427. package/src/functions/voice-booking.ts +0 -453
  428. package/src/functions/voice-day-pass.ts +0 -346
  429. package/src/functions/voice-inquiry.test.ts +0 -301
  430. package/src/functions/voice-inquiry.ts +0 -198
  431. package/src/functions/voice-membership-signup.ts +0 -355
  432. package/src/functions/voice-tour-availability.ts +0 -204
  433. package/src/functions/voice-tour-booking.ts +0 -429
  434. package/src/gcalSync.ts +0 -142
  435. package/src/ghlEventInquiry.ts +0 -143
  436. package/src/ghlNote.ts +0 -34
  437. package/src/ghlTask.ts +0 -48
  438. package/src/ghlVoiceInquiry.ts +0 -90
  439. package/src/guestPrintCapture.test.ts +0 -722
  440. package/src/guestPrintCapture.ts +0 -538
  441. package/src/lumaGhl.ts +0 -195
  442. package/src/mailArrivalEmail.ts +0 -121
  443. package/src/manageToken.ts +0 -363
  444. package/src/membership.ts +0 -109
  445. package/src/membershipBusClient.ts +0 -537
  446. package/src/membershipWelcome.ts +0 -683
  447. package/src/migrationCheckout.ts +0 -366
  448. package/src/money.ts +0 -36
  449. package/src/ops.ts +0 -97
  450. package/src/paymentLinkEmail.ts +0 -123
  451. package/src/policyAcknowledgment.test.ts +0 -50
  452. package/src/policyAcknowledgment.ts +0 -96
  453. package/src/portalSession.ts +0 -46
  454. package/src/pricing.test.ts +0 -660
  455. package/src/pricing.ts +0 -1025
  456. package/src/printBilling.test.ts +0 -750
  457. package/src/printBilling.ts +0 -891
  458. package/src/printBillingAdapters.ts +0 -169
  459. package/src/printCorrections.test.ts +0 -348
  460. package/src/printCorrections.ts +0 -496
  461. package/src/rateLimit.ts +0 -82
  462. package/src/referralCredits.test.ts +0 -31
  463. package/src/referralGrant.ts +0 -321
  464. package/src/rescheduleCredit.test.ts +0 -521
  465. package/src/rescheduleCredit.ts +0 -337
  466. package/src/reservationWifiCode.test.ts +0 -69
  467. package/src/retellCallAnalyzed.test.ts +0 -167
  468. package/src/retellCallAnalyzed.ts +0 -113
  469. package/src/retellSignature.test.ts +0 -137
  470. package/src/retellSignature.ts +0 -82
  471. package/src/signedUnpaidReminderEmail.test.ts +0 -246
  472. package/src/signedUnpaidReminderEmail.ts +0 -132
  473. package/src/slackAlert.ts +0 -38
  474. package/src/stripeCoworkingPortal.ts +0 -91
  475. package/src/supabaseTestFakes.ts +0 -131
  476. package/src/supportTicketEmail.ts +0 -119
  477. package/src/tier1Agreement.ts +0 -125
  478. package/src/unifiAccessPolicies.ts +0 -228
  479. package/src/unifiGroups.ts +0 -129
@@ -1,521 +0,0 @@
1
- // Fully mocked. NO network: the Supabase admin client is a hand-rolled stub
2
- // (mirrors the fake-client style used in adminBookingCredit.test.ts), so this
3
- // can run against live-only credentials with zero risk of touching them.
4
- //
5
- // This pins down the E10 fix: a reschedule refund must split into up to TWO
6
- // credit grants — a cash-funded portion at the plain 1-year default, and a
7
- // credit-funded portion capped at the ORIGINAL credit's own expiry — rather
8
- // than capping (or failing to cap) the whole sum. It exercises all four
9
- // acceptance scenarios named in the fix's own spec:
10
- // (a) cash-only booking -> unchanged 1yr grant, no lookup at all.
11
- // (b) partly paid via monthly membership credit (System A) -> that
12
- // portion capped at the real period-end, cash portion still 1yr.
13
- // (c) partly paid via an existing System-B grant credit with a short
14
- // expiry -> same capping.
15
- // (d) the lookup query itself errors (or comes up empty despite
16
- // credit_applied_cents > 0) -> falls back to 1-year default AND signals
17
- // the caller to log at ERROR severity (not warning).
18
-
19
- import { assert, assertEquals } from 'https://deno.land/std@0.224.0/assert/mod.ts';
20
- import {
21
- buildRescheduleCreditGrants,
22
- MIN_CREDIT_GRANT_LIFETIME_DAYS,
23
- nextPeriodMonthStr,
24
- resolveOriginalCreditExpiry,
25
- type RescheduleCreditLookupClient,
26
- } from './rescheduleCredit.ts';
27
-
28
- const BOOKING_ID = '33333333-3333-3333-3333-333333333333';
29
-
30
- // ---------------------------------------------------------------------------
31
- // Fake admin client
32
- // ---------------------------------------------------------------------------
33
-
34
- interface FakeAdminConfig {
35
- ledgerRows?: { period_id: string | null }[] | null;
36
- ledgerError?: { message: string } | null;
37
- periodRow?: { period_month: string } | null;
38
- periodError?: { message: string } | null;
39
- anchorIso?: string | null;
40
- anchorError?: { message: string } | null;
41
- grantRows?: { expires_at: string }[] | null;
42
- grantError?: { message: string } | null;
43
- }
44
-
45
- /** A recorded {method, args} call against one specific query chain. */
46
- type FilterCall = { method: string; args: unknown[] };
47
-
48
- /**
49
- * Fake admin client. Beyond routing to the right canned response, this
50
- * records every filter-chain call (.eq/.in/.not/.order) per query bucket so
51
- * tests can assert the ACTUAL filter shape sent — not just which table/branch
52
- * was hit. This is what would have caught the real regression an adversarial
53
- * review found in this module's first draft: a `.not('redeemed_at', 'is',
54
- * null)` filter on the System-B query that silently reopened the exact bug
55
- * this module exists to close (see the "must NOT filter on redeemed_at" test
56
- * below). A fake that only tracked which branch ran, without recording the
57
- * filter arguments, would have kept passing right through that regression.
58
- */
59
- function makeFakeAdmin(
60
- cfg: FakeAdminConfig,
61
- ): RescheduleCreditLookupClient & { calls: string[]; filterCalls: { ledger: FilterCall[]; grant: FilterCall[] } } {
62
- const calls: string[] = [];
63
- const filterCalls = { ledger: [] as FilterCall[], grant: [] as FilterCall[] };
64
- return {
65
- calls,
66
- filterCalls,
67
- from(table: string) {
68
- let usedIn = false;
69
- let usedGrantEntryType = false;
70
- // The two credits-table queries this module runs are distinguished by
71
- // their FIRST .eq() call's column, matching the real code exactly:
72
- // ledger keys on booking_id, the System-B fallback keys on
73
- // redeemed_booking_id.
74
- let bucket: 'ledger' | 'grant' | null = null;
75
- const record = (method: string, args: unknown[]) => {
76
- if (table === 'credits' && bucket) filterCalls[bucket].push({ method, args });
77
- };
78
- // deno-lint-ignore no-explicit-any
79
- const chain: any = {
80
- select: () => chain,
81
- eq: (col: string, val: unknown) => {
82
- if (table === 'credits' && bucket === null) {
83
- if (col === 'booking_id') bucket = 'ledger';
84
- else if (col === 'redeemed_booking_id') bucket = 'grant';
85
- }
86
- if (table === 'credits' && col === 'entry_type' && val === 'grant') usedGrantEntryType = true;
87
- record('eq', [col, val]);
88
- return chain;
89
- },
90
- in: (col: string, val: unknown) => {
91
- usedIn = true;
92
- record('in', [col, val]);
93
- return chain;
94
- },
95
- not: (col: string, op: string, val: unknown) => {
96
- record('not', [col, op, val]);
97
- return chain;
98
- },
99
- order: (col: string, opts: unknown) => {
100
- record('order', [col, opts]);
101
- return chain;
102
- },
103
- limit: () => {
104
- if (table === 'credits' && usedIn) {
105
- calls.push('credits:ledger');
106
- return Promise.resolve({ data: cfg.ledgerRows ?? [], error: cfg.ledgerError ?? null });
107
- }
108
- if (table === 'credits' && usedGrantEntryType) {
109
- calls.push('credits:grant');
110
- return Promise.resolve({ data: cfg.grantRows ?? [], error: cfg.grantError ?? null });
111
- }
112
- throw new Error(`unexpected .limit() on table ${table}`);
113
- },
114
- maybeSingle: () => {
115
- if (table === 'credit_periods') {
116
- calls.push('credit_periods');
117
- return Promise.resolve({ data: cfg.periodRow ?? null, error: cfg.periodError ?? null });
118
- }
119
- throw new Error(`unexpected .maybeSingle() on table ${table}`);
120
- },
121
- };
122
- return chain;
123
- },
124
- rpc(fn: string) {
125
- if (fn === 'period_anchor') {
126
- calls.push('rpc:period_anchor');
127
- return Promise.resolve({ data: cfg.anchorIso ?? null, error: cfg.anchorError ?? null });
128
- }
129
- throw new Error(`unexpected rpc ${fn}`);
130
- },
131
- };
132
- }
133
-
134
- /** True if any recorded call on this bucket filters on the given column. */
135
- function filtersOnColumn(calls: FilterCall[], column: string): boolean {
136
- return calls.some((c) => c.args[0] === column && (c.method === 'eq' || c.method === 'not'));
137
- }
138
-
139
- // Relative to the real clock (not a fixed calendar date) so this suite can
140
- // never drift into false failures/successes as real time passes a hardcoded
141
- // date — see the floor tests below for the incident that taught us this.
142
- const DEFAULT_EXP = new Date(Date.now() + 365 * 24 * 60 * 60 * 1000); // stand-in "1 year from now"
143
-
144
- // ---------------------------------------------------------------------------
145
- // nextPeriodMonthStr
146
- // ---------------------------------------------------------------------------
147
-
148
- Deno.test('nextPeriodMonthStr: ordinary month rolls forward within the year', () => {
149
- assertEquals(nextPeriodMonthStr('2026-08-01'), '2026-09-01');
150
- });
151
-
152
- Deno.test('nextPeriodMonthStr: December rolls into January of the following year', () => {
153
- assertEquals(nextPeriodMonthStr('2026-12-01'), '2027-01-01');
154
- });
155
-
156
- Deno.test('nextPeriodMonthStr: single-digit month stays zero-padded', () => {
157
- assertEquals(nextPeriodMonthStr('2026-01-01'), '2026-02-01');
158
- assertEquals(nextPeriodMonthStr('2026-09-01'), '2026-10-01');
159
- });
160
-
161
- // ---------------------------------------------------------------------------
162
- // resolveOriginalCreditExpiry
163
- // ---------------------------------------------------------------------------
164
-
165
- Deno.test('resolveOriginalCreditExpiry: System A hold/consume row -> period_anchor of NEXT month', async () => {
166
- const admin = makeFakeAdmin({
167
- ledgerRows: [{ period_id: 'p1' }],
168
- periodRow: { period_month: '2026-08-01' },
169
- anchorIso: '2026-09-01T07:00:00.000Z',
170
- });
171
- const r = await resolveOriginalCreditExpiry(admin, BOOKING_ID, DEFAULT_EXP);
172
- assertEquals(r.errored, false);
173
- assert(!r.errored);
174
- assertEquals(r.source, 'system_a');
175
- assertEquals(r.exp.toISOString(), '2026-09-01T07:00:00.000Z');
176
- // Never falls through to the System-B query once System A resolves.
177
- assertEquals(admin.calls, ['credits:ledger', 'credit_periods', 'rpc:period_anchor']);
178
- });
179
-
180
- Deno.test('resolveOriginalCreditExpiry: no System A row -> falls back to System B grant expires_at', async () => {
181
- const admin = makeFakeAdmin({
182
- ledgerRows: [],
183
- grantRows: [{ expires_at: '2026-09-15T00:00:00.000Z' }],
184
- });
185
- const r = await resolveOriginalCreditExpiry(admin, BOOKING_ID, DEFAULT_EXP);
186
- assert(!r.errored);
187
- assertEquals(r.source, 'system_b');
188
- assertEquals(r.exp.toISOString(), '2026-09-15T00:00:00.000Z');
189
- assertEquals(admin.calls, ['credits:ledger', 'credits:grant']);
190
- });
191
-
192
- // Regression guard for a real bug an adversarial review caught in this
193
- // module's first draft: the System-B query used to require
194
- // `redeemed_at IS NOT NULL`. But redeemed_at is only set once
195
- // credit_reservation_finalize succeeds, and both its call sites treat a
196
- // finalize failure as log-only, non-fatal — leaving a PAID booking with
197
- // redeemed_booking_id set and redeemed_at forever NULL. That filter silently
198
- // pushed exactly that booking to 'not_found' and the full 1-year default,
199
- // reopening the exact laundering bug this module exists to close.
200
- Deno.test('resolveOriginalCreditExpiry: System B row is found even when redeemed_at is still NULL (finalize pending) — the query must never filter on redeemed_at', async () => {
201
- const admin = makeFakeAdmin({
202
- ledgerRows: [],
203
- // No `redeemed_at` field at all in the canned row — mirrors a real row
204
- // where credit_reservation_finalize never ran.
205
- grantRows: [{ expires_at: '2026-09-18T00:00:00.000Z' }],
206
- });
207
- const r = await resolveOriginalCreditExpiry(admin, BOOKING_ID, DEFAULT_EXP);
208
- assert(!r.errored, 'must be found and used, not silently treated as not_found');
209
- assertEquals(r.source, 'system_b');
210
- assertEquals(r.exp.toISOString(), '2026-09-18T00:00:00.000Z');
211
- assert(
212
- !filtersOnColumn(admin.filterCalls.grant, 'redeemed_at'),
213
- 'the System-B query must NOT filter on redeemed_at — see the comment above resolveOriginalCreditExpiry\'s System-B query',
214
- );
215
- });
216
-
217
- Deno.test('resolveOriginalCreditExpiry: System B row found with a NULL expires_at -> not an error, just nothing to cap (defaults, but errored=false)', async () => {
218
- const admin = makeFakeAdmin({
219
- ledgerRows: [],
220
- grantRows: [{ expires_at: null as unknown as string }],
221
- });
222
- const r = await resolveOriginalCreditExpiry(admin, BOOKING_ID, DEFAULT_EXP);
223
- assert(!r.errored, 'finding the funding row with no expiry is not a lookup failure');
224
- assertEquals(r.source, 'system_b');
225
- assertEquals(r.exp, DEFAULT_EXP);
226
- });
227
-
228
- Deno.test('resolveOriginalCreditExpiry: neither system explains a credit-funded booking -> errored, defaults, source=not_found', async () => {
229
- const admin = makeFakeAdmin({ ledgerRows: [], grantRows: [] });
230
- const r = await resolveOriginalCreditExpiry(admin, BOOKING_ID, DEFAULT_EXP);
231
- assert(r.errored);
232
- assertEquals(r.source, 'not_found');
233
- assertEquals(r.exp, DEFAULT_EXP);
234
- });
235
-
236
- Deno.test('resolveOriginalCreditExpiry: ledger query itself errors -> errored, defaults, source=error, detail carries the message', async () => {
237
- const admin = makeFakeAdmin({ ledgerError: { message: 'connection reset' } });
238
- const r = await resolveOriginalCreditExpiry(admin, BOOKING_ID, DEFAULT_EXP);
239
- assert(r.errored);
240
- assertEquals(r.source, 'error');
241
- assertEquals(r.detail, 'connection reset');
242
- assertEquals(r.exp, DEFAULT_EXP);
243
- });
244
-
245
- Deno.test('resolveOriginalCreditExpiry: period_anchor RPC itself errors -> errored, defaults (never crashes)', async () => {
246
- const admin = makeFakeAdmin({
247
- ledgerRows: [{ period_id: 'p1' }],
248
- periodRow: { period_month: '2026-08-01' },
249
- anchorError: { message: 'function period_anchor does not exist' },
250
- });
251
- const r = await resolveOriginalCreditExpiry(admin, BOOKING_ID, DEFAULT_EXP);
252
- assert(r.errored);
253
- assertEquals(r.source, 'error');
254
- assertEquals(r.exp, DEFAULT_EXP);
255
- });
256
-
257
- // ---------------------------------------------------------------------------
258
- // buildRescheduleCreditGrants — the four acceptance scenarios
259
- // ---------------------------------------------------------------------------
260
-
261
- Deno.test('(a) cash-only booking: single 1yr grant, no credit lookup performed at all', async () => {
262
- const admin = makeFakeAdmin({});
263
- const res = await buildRescheduleCreditGrants(admin, {
264
- bookingId: BOOKING_ID,
265
- contactEmail: 'Member@Example.com',
266
- ghlContactId: 'ghl-1',
267
- cashPortionCents: 12000,
268
- creditPortionCents: 0,
269
- defaultExp: DEFAULT_EXP,
270
- });
271
- assertEquals(res.expiryLookupErrored, false);
272
- assertEquals(res.grants.length, 1);
273
- assertEquals(res.grants[0], {
274
- entry_type: 'grant',
275
- contact_email: 'member@example.com',
276
- ghl_contact_id: 'ghl-1',
277
- delta_cents: 12000,
278
- reason: 'Booking rescheduled by customer (cash-funded portion)',
279
- booking_id: BOOKING_ID,
280
- expires_at: DEFAULT_EXP.toISOString(),
281
- });
282
- assertEquals(admin.calls, [], 'no lookup should ever run when there is no credit portion');
283
- });
284
-
285
- Deno.test('(b) partly paid via monthly membership credit: that portion capped at real period-end, cash portion still 1yr', async () => {
286
- // Anchored to "now + 90 days", well beyond MIN_CREDIT_GRANT_LIFETIME_DAYS,
287
- // so the expired-credit floor never engages here — this test is purely
288
- // about the cap ITSELF, not the floor (see the dedicated floor tests
289
- // below). A fixed calendar date would eventually fall into the past as
290
- // real time passes it, silently starting to exercise the floor instead of
291
- // the cap and breaking this test's exact-match assertions.
292
- const futureAnchor = new Date(Date.now() + 90 * 24 * 60 * 60 * 1000);
293
- const admin = makeFakeAdmin({
294
- ledgerRows: [{ period_id: 'p1' }],
295
- periodRow: { period_month: '2026-08-01' },
296
- anchorIso: futureAnchor.toISOString(),
297
- });
298
- const res = await buildRescheduleCreditGrants(admin, {
299
- bookingId: BOOKING_ID,
300
- contactEmail: 'member@example.com',
301
- ghlContactId: null,
302
- cashPortionCents: 5000,
303
- creditPortionCents: 7000,
304
- defaultExp: DEFAULT_EXP,
305
- });
306
- assertEquals(res.expiryLookupErrored, false);
307
- assertEquals(res.grants.length, 2);
308
- const cashGrant = res.grants.find((g) => g.reason.includes('cash-funded'));
309
- const creditGrant = res.grants.find((g) => g.reason.includes('credit-funded'));
310
- assert(cashGrant && creditGrant);
311
- assertEquals(cashGrant!.delta_cents, 5000);
312
- assertEquals(cashGrant!.expires_at, DEFAULT_EXP.toISOString(), 'cash portion keeps the plain 1yr default');
313
- assertEquals(creditGrant!.delta_cents, 7000);
314
- assertEquals(creditGrant!.expires_at, futureAnchor.toISOString(), 'credit portion capped at the real period-end, NOT 1yr');
315
- assert(
316
- new Date(creditGrant!.expires_at).getTime() < DEFAULT_EXP.getTime(),
317
- 'the whole point of the fix: credit portion must expire sooner than the 1yr default',
318
- );
319
- assertEquals(creditGrant!.reason, 'Booking rescheduled by customer (credit-funded portion, source=system_a)');
320
- });
321
-
322
- Deno.test('(c) partly paid via an existing System-B grant credit with a short expiry: same capping', async () => {
323
- // See test (b)'s comment: anchored relative to now so this test can never
324
- // drift into exercising the floor instead of the cap.
325
- const futureGrantExpiry = new Date(Date.now() + 60 * 24 * 60 * 60 * 1000);
326
- const admin = makeFakeAdmin({
327
- ledgerRows: [], // not System-A funded
328
- grantRows: [{ expires_at: futureGrantExpiry.toISOString() }],
329
- });
330
- const res = await buildRescheduleCreditGrants(admin, {
331
- bookingId: BOOKING_ID,
332
- contactEmail: 'member@example.com',
333
- ghlContactId: null,
334
- cashPortionCents: 3000,
335
- creditPortionCents: 4000,
336
- defaultExp: DEFAULT_EXP,
337
- });
338
- assertEquals(res.expiryLookupErrored, false);
339
- const creditGrant = res.grants.find((g) => g.reason.includes('credit-funded'));
340
- assert(creditGrant);
341
- assertEquals(creditGrant!.expires_at, futureGrantExpiry.toISOString());
342
- assertEquals(creditGrant!.reason, 'Booking rescheduled by customer (credit-funded portion, source=system_b)');
343
- assert(new Date(creditGrant!.expires_at).getTime() < DEFAULT_EXP.getTime());
344
- });
345
-
346
- Deno.test('(d) lookup query errors: falls back to 1yr default AND signals the caller to log at ERROR severity', async () => {
347
- const admin = makeFakeAdmin({ ledgerError: { message: 'db unavailable' } });
348
- const res = await buildRescheduleCreditGrants(admin, {
349
- bookingId: BOOKING_ID,
350
- contactEmail: 'member@example.com',
351
- ghlContactId: null,
352
- cashPortionCents: 0,
353
- creditPortionCents: 9000,
354
- defaultExp: DEFAULT_EXP,
355
- });
356
- assertEquals(res.expiryLookupErrored, true, 'caller must be told to log at ERROR, never silently succeed');
357
- assertEquals(res.expiryLookupDetail, 'db unavailable');
358
- assertEquals(res.expirySource, 'error');
359
- assertEquals(res.grants.length, 1);
360
- assertEquals(res.grants[0].delta_cents, 9000);
361
- assertEquals(res.grants[0].expires_at, DEFAULT_EXP.toISOString(), 'still made whole via the safe 1yr fallback, never crashes or drops the credit');
362
- });
363
-
364
- Deno.test('(d2) credit_applied_cents > 0 but neither system explains it: same ERROR-signaling fallback as a hard query error', async () => {
365
- const admin = makeFakeAdmin({ ledgerRows: [], grantRows: [] });
366
- const res = await buildRescheduleCreditGrants(admin, {
367
- bookingId: BOOKING_ID,
368
- contactEmail: 'member@example.com',
369
- ghlContactId: null,
370
- cashPortionCents: 0,
371
- creditPortionCents: 2500,
372
- defaultExp: DEFAULT_EXP,
373
- });
374
- assertEquals(res.expiryLookupErrored, true);
375
- assertEquals(res.expirySource, 'not_found');
376
- assertEquals(res.grants[0].expires_at, DEFAULT_EXP.toISOString());
377
- });
378
-
379
- // ---------------------------------------------------------------------------
380
- // Edge cases
381
- // ---------------------------------------------------------------------------
382
-
383
- Deno.test('fully credit-funded (no cash portion): exactly one grant, no cash row emitted', async () => {
384
- const admin = makeFakeAdmin({
385
- ledgerRows: [{ period_id: 'p1' }],
386
- periodRow: { period_month: '2026-08-01' },
387
- anchorIso: new Date(Date.now() + 90 * 24 * 60 * 60 * 1000).toISOString(),
388
- });
389
- const res = await buildRescheduleCreditGrants(admin, {
390
- bookingId: BOOKING_ID,
391
- contactEmail: 'member@example.com',
392
- ghlContactId: null,
393
- cashPortionCents: 0,
394
- creditPortionCents: 8000,
395
- defaultExp: DEFAULT_EXP,
396
- });
397
- assertEquals(res.grants.length, 1);
398
- assertEquals(res.grants[0].reason.includes('credit-funded'), true);
399
- });
400
-
401
- // ---------------------------------------------------------------------------
402
- // Expired-credit floor (Kyle's call, E10/GATE-0188 follow-up, 2026-09-10):
403
- // a capped grant must never be issued already-dead just because the
404
- // ORIGINAL credit it's capped against had already expired.
405
- // ---------------------------------------------------------------------------
406
-
407
- Deno.test('floor: original credit already expired in the past -> new grant floored to EXACTLY now+MIN_CREDIT_GRANT_LIFETIME_DAYS, not the past date', async () => {
408
- const admin = makeFakeAdmin({
409
- ledgerRows: [],
410
- grantRows: [{ expires_at: '2020-01-01T00:00:00.000Z' }], // long expired
411
- });
412
- const before = Date.now();
413
- const res = await buildRescheduleCreditGrants(admin, {
414
- bookingId: BOOKING_ID,
415
- contactEmail: 'member@example.com',
416
- ghlContactId: null,
417
- cashPortionCents: 0,
418
- creditPortionCents: 5000,
419
- defaultExp: DEFAULT_EXP,
420
- });
421
- const after = Date.now();
422
- const gotMs = new Date(res.grants[0].expires_at).getTime();
423
- const floorLow = before + MIN_CREDIT_GRANT_LIFETIME_DAYS * 24 * 60 * 60 * 1000;
424
- const floorHigh = after + MIN_CREDIT_GRANT_LIFETIME_DAYS * 24 * 60 * 60 * 1000;
425
- assert(
426
- gotMs >= floorLow && gotMs <= floorHigh,
427
- `expected exactly now+${MIN_CREDIT_GRANT_LIFETIME_DAYS}d (within test execution slack), got ${res.grants[0].expires_at}`,
428
- );
429
- });
430
-
431
- // CRITICAL regression guard: the floor's trigger must be "already expired"
432
- // (resolved.exp in the past), NOT "expiring within the floor window". An
433
- // earlier draft of this floor used the broader trigger and — because a
434
- // System-A (monthly membership credit) cap is USUALLY well under 30 days out
435
- // by design (it's the real end of the current calendar month) — that draft
436
- // silently overrode the System-A cap on essentially every real cancellation,
437
- // re-widening the exact laundering gap E10/GATE-0188 exists to close. Caught
438
- // on adversarial review before merge. This test pins the fix: a FUTURE
439
- // expiry under 30 days out must be left exactly as resolved, not floored up.
440
- Deno.test('floor does NOT engage on a future-but-under-30-days expiry (a normal, correct System-A/B cap) — only on a TRULY expired original', async () => {
441
- const soonButFuture = new Date(Date.now() + 5 * 24 * 60 * 60 * 1000); // 5 days out, still in the future
442
- const admin = makeFakeAdmin({
443
- ledgerRows: [],
444
- grantRows: [{ expires_at: soonButFuture.toISOString() }],
445
- });
446
- const res = await buildRescheduleCreditGrants(admin, {
447
- bookingId: BOOKING_ID,
448
- contactEmail: 'member@example.com',
449
- ghlContactId: null,
450
- cashPortionCents: 0,
451
- creditPortionCents: 5000,
452
- defaultExp: DEFAULT_EXP,
453
- });
454
- assertEquals(
455
- res.grants[0].expires_at,
456
- soonButFuture.toISOString(),
457
- 'a genuinely future cap (even one under the floor window) must be left EXACTLY as resolved — flooring it would let a member ratchet a near-expired credit\'s lifetime back up on every reschedule/cancel cycle',
458
- );
459
- });
460
-
461
- // Realistic System-A shape: period_anchor() returns the 1st of NEXT month,
462
- // so a real monthly-membership-credit cap is typically well under 30 days
463
- // out. This is the exact case the broader (wrong) floor trigger would have
464
- // silently overridden — see the regression guard above for the incident.
465
- Deno.test('realistic System-A cap (period end ~10 days out): capped exactly at period end, NOT floored to 30 days', async () => {
466
- const realisticPeriodEnd = new Date(Date.now() + 10 * 24 * 60 * 60 * 1000);
467
- const admin = makeFakeAdmin({
468
- ledgerRows: [{ period_id: 'p1' }],
469
- periodRow: { period_month: '2026-08-01' },
470
- anchorIso: realisticPeriodEnd.toISOString(),
471
- });
472
- const res = await buildRescheduleCreditGrants(admin, {
473
- bookingId: BOOKING_ID,
474
- contactEmail: 'member@example.com',
475
- ghlContactId: null,
476
- cashPortionCents: 0,
477
- creditPortionCents: 5000,
478
- defaultExp: DEFAULT_EXP,
479
- });
480
- assertEquals(
481
- res.grants[0].expires_at,
482
- realisticPeriodEnd.toISOString(),
483
- 'the whole point of E10: a monthly credit\'s real, intended use-it-or-lose-it deadline must survive untouched, not get quietly extended to 30 days',
484
- );
485
- });
486
-
487
- Deno.test('floor: original credit expiring well beyond the floor window is left EXACTLY as resolved (floor only ever applies to a TRULY expired original)', async () => {
488
- const wellBeyondFloor = new Date(Date.now() + 60 * 24 * 60 * 60 * 1000); // 60 days out
489
- const admin = makeFakeAdmin({
490
- ledgerRows: [],
491
- grantRows: [{ expires_at: wellBeyondFloor.toISOString() }],
492
- });
493
- const res = await buildRescheduleCreditGrants(admin, {
494
- bookingId: BOOKING_ID,
495
- contactEmail: 'member@example.com',
496
- ghlContactId: null,
497
- cashPortionCents: 0,
498
- creditPortionCents: 5000,
499
- defaultExp: DEFAULT_EXP,
500
- });
501
- assertEquals(
502
- res.grants[0].expires_at,
503
- wellBeyondFloor.toISOString(),
504
- 'the whole point of the floor: it must never shorten a capping that is already correct',
505
- );
506
- });
507
-
508
- Deno.test('zero cash AND zero credit: no grants at all (a delta_cents=0 grant would violate credits_delta_sign_check)', async () => {
509
- const admin = makeFakeAdmin({});
510
- const res = await buildRescheduleCreditGrants(admin, {
511
- bookingId: BOOKING_ID,
512
- contactEmail: 'member@example.com',
513
- ghlContactId: null,
514
- cashPortionCents: 0,
515
- creditPortionCents: 0,
516
- defaultExp: DEFAULT_EXP,
517
- });
518
- assertEquals(res.grants.length, 0);
519
- assertEquals(res.expiryLookupErrored, false);
520
- assertEquals(admin.calls, []);
521
- });