@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
@@ -0,0 +1,405 @@
1
+ import { corsHeaders } from '@supabase/supabase-js/cors';
2
+ import { createClient } from '@supabase/supabase-js';
3
+ import Stripe from 'stripe';
4
+ import { z } from 'zod';
5
+ import { clientIp, checkRateLimit } from '../rateLimit.js';
6
+ import { logOps } from '../ops.js';
7
+ import { hasEntitlement } from '../entitlements.js';
8
+ import { applyCheckoutCoupon, couponFailureBody, reverseCheckoutCoupon, COUPON_START_DATE_CONFLICT_MESSAGE, } from '../checkoutCoupon.js';
9
+ import { buildSubscriptionSessionParams } from '../checkoutSessionParams.js';
10
+ // Extracted verbatim (bodies and comments) to _shared/pacificDate.ts so the
11
+ // migration-checkout functions can reuse the exact same clamp/validation
12
+ // arithmetic instead of duplicating it. Pure refactor: no behavior change.
13
+ import { MAX_START_DATE_DAYS, pacificDateStr, addDaysStr } from '../pacificDate.js';
14
+ const Body = z.object({
15
+ plan_slug: z.string().min(1).max(80).regex(/^[a-z0-9-]+$/),
16
+ email: z.string().email().max(255),
17
+ name: z.string().trim().min(1).max(200),
18
+ start_date: z.string().regex(/^\d{4}-\d{2}-\d{2}$/).optional(),
19
+ // Referral program Phase 1. Case-sensitive exact match against
20
+ // memberships.referral_code, resolved just below. An unresolvable code is
21
+ // silently ignored -- it must never block or error checkout.
22
+ referral_code: z.string().trim().min(1).max(32).optional(),
23
+ // Internal `coupons` code. Unlike referral_code, an unusable code here is a
24
+ // hard 400 -- the member typed it expecting a discount, so charging them
25
+ // full price silently is the wrong failure mode.
26
+ coupon_code: z.string().trim().min(1).max(40).regex(/^[A-Za-z0-9_-]+$/).optional(),
27
+ });
28
+ // MAX_START_DATE_DAYS, pacificDateStr and addDaysStr now live in
29
+ // _shared/pacificDate.ts (imported above) — moved there verbatim, comments
30
+ // included, so migration-checkout-redirect's dynamic start-date clamp and this
31
+ // function's start-date validation cannot drift apart.
32
+ // pacificMidnightUtc/laOffsetMinutes inlined verbatim from gc-connect's
33
+ // _shared/agreementActivation.ts (that file stays in gc-connect, out of scope
34
+ // this phase -- it also owns BoldSign-specific activation logic this function
35
+ // has nothing to do with). Single source of truth for the start instant
36
+ // (Pacific midnight -> UTC), reused wherever a plan/agreement needs the same
37
+ // clamp/validation arithmetic.
38
+ const LA_TZ = 'America/Los_Angeles';
39
+ /**
40
+ * Resolve the UTC instant of midnight (00:00) on a Pacific calendar date,
41
+ * handling PST/PDT correctly. Returns null for a missing/invalid date string.
42
+ */
43
+ function pacificMidnightUtc(dateStr) {
44
+ if (!dateStr)
45
+ return null;
46
+ const m = /^(\d{4})-(\d{2})-(\d{2})/.exec(String(dateStr));
47
+ if (!m)
48
+ return null;
49
+ const [, y, mo, d] = m;
50
+ // Start from the UTC-midnight guess, then correct by the zone offset that
51
+ // actually applies at that instant (two passes settles DST boundaries).
52
+ let ts = Date.UTC(Number(y), Number(mo) - 1, Number(d), 0, 0, 0);
53
+ for (let i = 0; i < 2; i++) {
54
+ const offsetMinutes = laOffsetMinutes(new Date(ts));
55
+ ts = Date.UTC(Number(y), Number(mo) - 1, Number(d), 0, 0, 0) - offsetMinutes * 60_000;
56
+ }
57
+ return new Date(ts);
58
+ }
59
+ /** Offset of America/Los_Angeles from UTC, in minutes, at the given instant. */
60
+ function laOffsetMinutes(at) {
61
+ const fmt = new Intl.DateTimeFormat('en-US', {
62
+ timeZone: LA_TZ,
63
+ hour12: false,
64
+ year: 'numeric',
65
+ month: '2-digit',
66
+ day: '2-digit',
67
+ hour: '2-digit',
68
+ minute: '2-digit',
69
+ second: '2-digit',
70
+ });
71
+ const parts = Object.fromEntries(fmt.formatToParts(at).filter((p) => p.type !== 'literal').map((p) => [p.type, p.value]));
72
+ const asUtc = Date.UTC(Number(parts.year), Number(parts.month) - 1, Number(parts.day), Number(parts.hour) % 24, Number(parts.minute), Number(parts.second));
73
+ return (asUtc - at.getTime()) / 60_000;
74
+ }
75
+ export async function handle(req, operator) {
76
+ if (req.method === 'OPTIONS')
77
+ return new Response('ok', { headers: corsHeaders });
78
+ if (!hasEntitlement(operator, 'membership')) {
79
+ return new Response(JSON.stringify({ ok: false, error: 'feature_not_enabled', feature: 'membership' }), {
80
+ status: 403, headers: { ...corsHeaders, 'Content-Type': 'application/json' },
81
+ });
82
+ }
83
+ // Set once a coupon reservation exists. Held at handler scope so the outer
84
+ // catch can release it if anything after the reservation throws -- otherwise
85
+ // a single-use code stays consumed by a checkout that never started.
86
+ let couponRedemptionId = null;
87
+ try {
88
+ const raw = await req.json().catch(() => ({}));
89
+ const parsed = Body.safeParse(raw);
90
+ if (!parsed.success) {
91
+ return new Response(JSON.stringify({ error: parsed.error.flatten() }), {
92
+ status: 400, headers: { ...corsHeaders, 'Content-Type': 'application/json' },
93
+ });
94
+ }
95
+ const { plan_slug, email, name, start_date, referral_code, coupon_code } = parsed.data;
96
+ const emailKey = email.toLowerCase();
97
+ if (start_date) {
98
+ // Round-trip check: rejects a calendar-invalid date (e.g. 2026-02-31) that
99
+ // the regex accepts, rather than letting pacificMidnightUtc silently roll
100
+ // it over to a different date than the one requested.
101
+ if (addDaysStr(start_date, 0) !== start_date) {
102
+ return new Response(JSON.stringify({ error: 'start_date_invalid' }), {
103
+ status: 400, headers: { ...corsHeaders, 'Content-Type': 'application/json' },
104
+ });
105
+ }
106
+ const today = pacificDateStr(new Date());
107
+ if (start_date < today) {
108
+ return new Response(JSON.stringify({ error: 'start_date_in_past' }), {
109
+ status: 400, headers: { ...corsHeaders, 'Content-Type': 'application/json' },
110
+ });
111
+ }
112
+ if (start_date > addDaysStr(today, MAX_START_DATE_DAYS)) {
113
+ return new Response(JSON.stringify({ error: 'start_date_too_far_out' }), {
114
+ status: 400, headers: { ...corsHeaders, 'Content-Type': 'application/json' },
115
+ });
116
+ }
117
+ }
118
+ // Single source of truth for the start instant (Pacific midnight -> UTC),
119
+ // shared with the private-office path and with stripe-webhook's door gate.
120
+ const startInstant = pacificMidnightUtc(start_date ?? null);
121
+ // null unless the date is strictly in the future -- a today date keeps
122
+ // the original behavior (bill immediately, no anchor, no proration change).
123
+ const futureStartUnix = startInstant && startInstant.getTime() > Date.now()
124
+ ? Math.floor(startInstant.getTime() / 1000)
125
+ : null;
126
+ // An internal coupon plus a FUTURE billing_cycle_anchor is an unverified
127
+ // combination on a live-only Stripe account: nobody has confirmed which
128
+ // invoice Stripe attaches the `discounts` coupon to, so a duration:'once'
129
+ // coupon could be consumed by a $0/placeholder invoice at session creation
130
+ // and leave the real first charge at the anchor date at full price -- with
131
+ // the internal redemption already flipped to 'applied'. Refuse the pair
132
+ // until a real Stripe test settles it. Earliest possible placement: no
133
+ // Stripe call, no coupon RPC, not even a Supabase client yet.
134
+ // A today-or-past start_date leaves futureStartUnix null (bill immediately,
135
+ // no anchor), which is the ordinary path and stays allowed with a coupon.
136
+ if (coupon_code && futureStartUnix !== null) {
137
+ return new Response(JSON.stringify(couponFailureBody({ message: COUPON_START_DATE_CONFLICT_MESSAGE })), {
138
+ status: 400, headers: { ...corsHeaders, 'Content-Type': 'application/json' },
139
+ });
140
+ }
141
+ const supabase = createClient(Deno.env.get('SUPABASE_URL'), Deno.env.get('SUPABASE_SERVICE_ROLE_KEY'));
142
+ // Fail-open rate limiting (mirror create-booking).
143
+ const ip = clientIp(req);
144
+ const [ipOk, emailOk] = await Promise.all([
145
+ checkRateLimit(supabase, 'create-subscription', ip, 10, 600),
146
+ checkRateLimit(supabase, 'create-subscription-email', emailKey, 5, 600),
147
+ ]);
148
+ if (!ipOk || !emailOk) {
149
+ return new Response(JSON.stringify({ error: 'Too many checkout attempts — please wait a few minutes and try again.' }), { status: 429, headers: { ...corsHeaders, 'Content-Type': 'application/json' } });
150
+ }
151
+ const { data: plan, error: pErr } = await supabase
152
+ .from('membership_plans')
153
+ .select('id,slug,name,category,active,billable,billing_interval,stripe_price_id,stripe_product_id,price_cents')
154
+ .eq('slug', plan_slug)
155
+ .maybeSingle();
156
+ if (pErr)
157
+ throw pErr;
158
+ // Self-serve subscription checkout is ALLOWLISTED to these categories.
159
+ // `office` is deliberately excluded: private offices are sign-before-pay — a signed
160
+ // BoldSign agreement precedes any charge, and boldsign-webhook creates that
161
+ // subscription itself. An office plan must never be billable from this public
162
+ // endpoint regardless of its flags or whether it has a stripe_price_id.
163
+ // Allowlist, not denylist: an unknown or NULL category fails closed.
164
+ const SELF_SERVE_CATEGORIES = ['coworking', 'dedicated'];
165
+ // Two supported pricing mechanisms, both still valid for allowlisted categories:
166
+ // 1. Stored Stripe Price ID — what all live self-serve plans use today.
167
+ // 2. Ad-hoc inline price_data from `price_cents`, so a price change is a DB edit
168
+ // with no Stripe Price object churn. This is DELIBERATE — do not "fix" it by
169
+ // requiring a stored price ID.
170
+ const usesAdHocPrice = !plan?.stripe_price_id &&
171
+ !!plan?.billing_interval &&
172
+ typeof plan?.price_cents === 'number' &&
173
+ plan.price_cents > 0;
174
+ const eligible = !!plan &&
175
+ plan.active === true &&
176
+ plan.billable === true &&
177
+ SELF_SERVE_CATEGORIES.includes(plan.category) &&
178
+ plan.billing_interval === 'month' &&
179
+ (!!plan.stripe_price_id || usesAdHocPrice);
180
+ if (!eligible) {
181
+ // Best-effort structured deny log. Never blocks or 500s the request.
182
+ try {
183
+ await logOps(supabase, 'subscription_checkout_denied', {
184
+ plan_slug,
185
+ ...(plan
186
+ ? {
187
+ category: plan.category,
188
+ active: plan.active,
189
+ billable: plan.billable,
190
+ billing_interval: plan.billing_interval,
191
+ has_price_id: !!plan.stripe_price_id,
192
+ }
193
+ : {}),
194
+ },
195
+ // _shared/ops.ts Severity is 'info' | 'warning' | 'error' — 'warn' is not a
196
+ // valid value, so the warn-level severity here is 'warning'.
197
+ { severity: 'warning' });
198
+ }
199
+ catch { /* ignore */ }
200
+ return new Response(JSON.stringify({ error: 'That plan is not available for online checkout.' }), {
201
+ status: 400, headers: { ...corsHeaders, 'Content-Type': 'application/json' },
202
+ });
203
+ }
204
+ // Referral program Phase 1: best-effort lookup only. A miss (typo, stale
205
+ // code, malicious input) is NOT an error -- it just means no referral
206
+ // metadata gets attached, same as if the field had been omitted.
207
+ let referralCode;
208
+ if (referral_code) {
209
+ try {
210
+ const { data: referrer, error: refErr } = await supabase
211
+ .from('memberships')
212
+ .select('id')
213
+ .eq('referral_code', referral_code)
214
+ .maybeSingle();
215
+ if (!refErr && referrer)
216
+ referralCode = referral_code;
217
+ }
218
+ catch (e) {
219
+ console.warn('[create-subscription-checkout] referral_code lookup failed (ignored)', e);
220
+ }
221
+ }
222
+ const stripeKey = Deno.env.get('STRIPE_SECRET_KEY');
223
+ if (!stripeKey) {
224
+ return new Response(JSON.stringify({ error: 'Payments not configured (missing STRIPE_SECRET_KEY).' }), {
225
+ status: 500, headers: { ...corsHeaders, 'Content-Type': 'application/json' },
226
+ });
227
+ }
228
+ const stripe = new Stripe(stripeKey, { apiVersion: '2024-11-20.acacia' });
229
+ // === Optional internal coupon ===
230
+ // Runs BEFORE any Stripe Customer or Session is created: a bad code should
231
+ // cost one read-only RPC, not a customer record and an abandoned session.
232
+ let stripeCouponId = null;
233
+ let couponId = null;
234
+ let couponAttemptId = null;
235
+ if (coupon_code) {
236
+ // The discount has to be computed against the SAME amount Stripe is
237
+ // about to charge. For the stored-price branch that means asking Stripe
238
+ // what the Price is actually worth -- price_cents may be stale or unset
239
+ // for those plans.
240
+ let baseAmountCents = null;
241
+ if (plan.stripe_price_id) {
242
+ try {
243
+ const price = await stripe.prices.retrieve(plan.stripe_price_id);
244
+ baseAmountCents = price.unit_amount ?? null;
245
+ }
246
+ catch (e) {
247
+ console.error('[create-subscription-checkout] prices.retrieve failed', String(e));
248
+ }
249
+ }
250
+ else {
251
+ baseAmountCents = plan.price_cents;
252
+ }
253
+ if (baseAmountCents === null) {
254
+ // Tiered/metered price, or Stripe unreachable -- we cannot size the
255
+ // discount, so refuse rather than guess.
256
+ return new Response(JSON.stringify(couponFailureBody({ message: "That code isn't valid." })), {
257
+ status: 400, headers: { ...corsHeaders, 'Content-Type': 'application/json' },
258
+ });
259
+ }
260
+ const outcome = await applyCheckoutCoupon(supabase, stripe, {
261
+ code: coupon_code,
262
+ fnName: 'create-subscription-checkout',
263
+ planId: plan.id,
264
+ planSlug: plan.slug,
265
+ planName: plan.name,
266
+ emailKey,
267
+ baseAmountCents,
268
+ appliedToType: 'membership',
269
+ oneTime: false,
270
+ actorEmail: operator.actorEmail,
271
+ });
272
+ if (!outcome.ok) {
273
+ return new Response(JSON.stringify(couponFailureBody(outcome)), {
274
+ status: 400, headers: { ...corsHeaders, 'Content-Type': 'application/json' },
275
+ });
276
+ }
277
+ stripeCouponId = outcome.stripeCouponId;
278
+ couponId = outcome.couponId;
279
+ couponAttemptId = outcome.attemptId;
280
+ couponRedemptionId = outcome.redemptionId;
281
+ }
282
+ // Reuse-or-create a Stripe Customer by email. Prefer search; fall back to list.
283
+ let customerId = null;
284
+ let matchCount = 0;
285
+ try {
286
+ const found = await stripe.customers.search({
287
+ query: `email:'${emailKey.replace(/'/g, "\\'")}'`,
288
+ limit: 2,
289
+ });
290
+ matchCount = found.data.length;
291
+ if (found.data.length > 0)
292
+ customerId = found.data[0].id;
293
+ }
294
+ catch (e) {
295
+ console.warn('[create-subscription-checkout] customers.search failed', e);
296
+ }
297
+ // Search is eventually consistent (~1 min). Always fall back to list for freshly-created customers.
298
+ if (!customerId) {
299
+ try {
300
+ const listed = await stripe.customers.list({ email: emailKey, limit: 2 });
301
+ matchCount = listed.data.length;
302
+ if (listed.data.length > 0)
303
+ customerId = listed.data[0].id;
304
+ }
305
+ catch (e2) {
306
+ console.warn('[create-subscription-checkout] customers.list failed', e2);
307
+ }
308
+ }
309
+ // Stripe does NOT enforce Customer email uniqueness. With >1 Customer per
310
+ // email the reused id is arbitrary, which makes any stripe_customer_id
311
+ // predicate downstream nondeterministic. Assert exactly one; flag otherwise.
312
+ // This is the second, INDEPENDENT copy of reuse-or-create-by-email; the
313
+ // other lives in _shared/agreementCheckout.ts. They are not byte-identical
314
+ // (this one also updates the reused customer's name), so both are fixed.
315
+ if (matchCount > 1) {
316
+ console.error('[create-subscription-checkout] multiple Stripe Customers for one email', { email: emailKey, match_count: matchCount, chosen: customerId });
317
+ }
318
+ if (customerId) {
319
+ // Best-effort: keep the reused customer's name current. Never block checkout.
320
+ try {
321
+ await stripe.customers.update(customerId, { name });
322
+ }
323
+ catch (e3) {
324
+ console.warn('[create-subscription-checkout] customers.update name failed', e3);
325
+ }
326
+ }
327
+ else {
328
+ const created = await stripe.customers.create({ email: emailKey, name });
329
+ customerId = created.id;
330
+ }
331
+ const origin = req.headers.get('origin');
332
+ const base = origin && /^https?:\/\//.test(origin) ? origin : `https://${operator.domain}`;
333
+ const metadata = {
334
+ checkout_type: 'membership',
335
+ plan_slug: plan.slug,
336
+ plan_id: plan.id,
337
+ ...(start_date ? { start_date } : {}),
338
+ ...(referralCode ? { referral_code: referralCode } : {}),
339
+ // stripe-webhook reads these back to flip the reservation to 'applied'
340
+ // once payment lands, or reverse it if the session expires.
341
+ ...(couponRedemptionId ? { coupon_redemption_id: couponRedemptionId } : {}),
342
+ ...(couponId ? { coupon_id: couponId } : {}),
343
+ // Opaque per-attempt uuid; it is the redemption row's applied_to_id, so
344
+ // this is what correlates that row back to this checkout attempt.
345
+ ...(couponAttemptId ? { coupon_attempt_id: couponAttemptId } : {}),
346
+ };
347
+ const lineItem = plan.stripe_price_id
348
+ ? { price: plan.stripe_price_id, quantity: 1 }
349
+ : {
350
+ price_data: {
351
+ currency: 'usd',
352
+ product_data: { name: plan.name },
353
+ unit_amount: plan.price_cents,
354
+ recurring: {
355
+ interval: plan.billing_interval,
356
+ },
357
+ },
358
+ quantity: 1,
359
+ };
360
+ // Future start date: anchor the first billing cycle to Pacific midnight on
361
+ // that date with proration_behavior 'none', so the member isn't charged
362
+ // until then (mirrors maybeActivateAgreement's office-subscription path).
363
+ const subscriptionData = futureStartUnix !== null
364
+ ? { metadata, billing_cycle_anchor: futureStartUnix, proration_behavior: 'none' }
365
+ : { metadata };
366
+ const session = await stripe.checkout.sessions.create(buildSubscriptionSessionParams({
367
+ customerId,
368
+ lineItem,
369
+ metadata,
370
+ subscriptionData,
371
+ // start_date is only appended when it's a validated YYYY-MM-DD in the future
372
+ // (futureStartUnix is non-null iff start_date was parsed and is strictly
373
+ // ahead of now), so start_date is guaranteed defined here.
374
+ successUrl: futureStartUnix !== null
375
+ ? `${base}/membership/success?session_id={CHECKOUT_SESSION_ID}&start_date=${start_date}`
376
+ : `${base}/membership/success?session_id={CHECKOUT_SESSION_ID}`,
377
+ cancelUrl: `${base}/pricing`,
378
+ stripeCouponId,
379
+ // Stripe's application_fee_percent is already a percentage of each
380
+ // invoice, so there is nothing to compute and no extra Stripe call. The
381
+ // builder emits neither field unless both are present.
382
+ applicationFeePercent: operator.stripeApplicationFeePercent,
383
+ connectedAccountId: operator.stripeConnectedAccountId,
384
+ }));
385
+ return new Response(JSON.stringify({ url: session.url }), {
386
+ headers: { ...corsHeaders, 'Content-Type': 'application/json' },
387
+ });
388
+ }
389
+ catch (e) {
390
+ console.error('create-subscription-checkout error', e);
391
+ try {
392
+ const opsClient = createClient(Deno.env.get('SUPABASE_URL') ?? '', Deno.env.get('SUPABASE_SERVICE_ROLE_KEY') ?? '');
393
+ // Checkout died after the coupon was reserved -- hand the redemption
394
+ // back. Runs BEFORE logOps so a failing ops write can't skip it.
395
+ if (couponRedemptionId) {
396
+ await reverseCheckoutCoupon(opsClient, couponRedemptionId, 'subscription_checkout_error', 'create-subscription-checkout', operator.actorEmail);
397
+ }
398
+ await logOps(opsClient, 'subscription_checkout_error', { message: e instanceof Error ? e.message : String(e) }, { severity: 'error' });
399
+ }
400
+ catch { /* ignore */ }
401
+ return new Response(JSON.stringify({ error: 'Something went wrong starting your checkout. Please try again.' }), {
402
+ status: 500, headers: { ...corsHeaders, 'Content-Type': 'application/json' },
403
+ });
404
+ }
405
+ }
@@ -0,0 +1 @@
1
+ export declare function handle(req: Request): Promise<Response>;
@@ -0,0 +1,70 @@
1
+ // Public, unauthenticated status lookup for the day-pass confirmation page
2
+ // (DayPassSuccess.tsx), mirroring booking-status/index.ts's IDOR-safe shape:
3
+ // the only lookup key is the Stripe Checkout Session id, which is
4
+ // unguessable and known only to the customer who completed checkout (it
5
+ // comes back via Stripe's {CHECKOUT_SESSION_ID} success_url placeholder).
6
+ // This endpoint is unauthenticated but MUST NOT accept a bare
7
+ // day_pass_purchases UUID as a lookup key -- same reasoning as
8
+ // booking-status's own comment on the same trap.
9
+ //
10
+ // Returns a deliberately narrow field set: no email (the one PII field the
11
+ // row actually has), and nothing from the admin-only issuance path
12
+ // (payment_source, created_by).
13
+ import { corsHeaders } from '@supabase/supabase-js/cors';
14
+ import { createClient } from '@supabase/supabase-js';
15
+ import { z } from 'zod';
16
+ const Body = z.object({
17
+ session_id: z.string().min(10).max(200),
18
+ });
19
+ export async function handle(req) {
20
+ if (req.method === 'OPTIONS')
21
+ return new Response('ok', { headers: corsHeaders });
22
+ try {
23
+ let payload = {};
24
+ if (req.method === 'POST') {
25
+ payload = (await req.json().catch(() => ({})));
26
+ }
27
+ else {
28
+ const url = new URL(req.url);
29
+ payload = { session_id: url.searchParams.get('session_id') ?? undefined };
30
+ }
31
+ const parsed = Body.safeParse(payload);
32
+ if (!parsed.success) {
33
+ return new Response(JSON.stringify({ error: 'missing session_id' }), {
34
+ status: 400, headers: { ...corsHeaders, 'Content-Type': 'application/json' },
35
+ });
36
+ }
37
+ const supabase = createClient(Deno.env.get('SUPABASE_URL'), Deno.env.get('SUPABASE_SERVICE_ROLE_KEY'));
38
+ const { data, error } = await supabase
39
+ .from('day_pass_purchases')
40
+ .select('visit_date,arrival_time,amount_cents,customer_name,refunded_at,' +
41
+ 'provisioning_status,wifi_code,wifi_valid_from,wifi_valid_to')
42
+ .eq('stripe_checkout_session_id', parsed.data.session_id)
43
+ .maybeSingle();
44
+ if (error)
45
+ throw error;
46
+ const row = data;
47
+ if (!row) {
48
+ return new Response(JSON.stringify({ error: 'not found' }), {
49
+ status: 404, headers: { ...corsHeaders, 'Content-Type': 'application/json' },
50
+ });
51
+ }
52
+ return new Response(JSON.stringify({
53
+ visit_date: row.visit_date,
54
+ arrival_time: row.arrival_time,
55
+ amount_cents: row.amount_cents,
56
+ customer_name: row.customer_name,
57
+ refunded: row.refunded_at !== null,
58
+ provisioning_status: row.provisioning_status,
59
+ wifi_code: row.wifi_code,
60
+ wifi_valid_from: row.wifi_valid_from,
61
+ wifi_valid_to: row.wifi_valid_to,
62
+ }), { headers: { ...corsHeaders, 'Content-Type': 'application/json' } });
63
+ }
64
+ catch (e) {
65
+ console.error('day-pass-status error', e);
66
+ return new Response(JSON.stringify({ error: e instanceof Error ? e.message : String(e) }), {
67
+ status: 500, headers: { ...corsHeaders, 'Content-Type': 'application/json' },
68
+ });
69
+ }
70
+ }
@@ -0,0 +1,15 @@
1
+ export type DayStatus = 'open' | 'partial' | 'full';
2
+ /** Next calendar date string (UTC-arithmetic on the YYYY-MM-DD parts only — no timezone involved). */
3
+ export declare function nextDateStr(dateStr: string): string;
4
+ /** All calendar date strings from start to end, inclusive. Caller enforces the max-range cap. */
5
+ export declare function dateRange(start: string, end: string): string[];
6
+ /** Merge overlapping/adjacent [start,end) pairs, sorted ascending. */
7
+ export declare function mergeRanges(ranges: [number, number][]): [number, number][];
8
+ /**
9
+ * Milliseconds of `[windowStart,windowEnd)` covered by `busy`, clipped to the
10
+ * window. `unparsed > 0` means some row's range could not be proven free, so
11
+ * (matching getBusyRangesDetailed's own doc comment for read-only "what's
12
+ * open" surfaces) the whole window is treated as covered rather than free.
13
+ */
14
+ export declare function coveredMs(busy: [number, number][], unparsed: number, windowStart: number, windowEnd: number): number;
15
+ export declare function statusForDay(bookingMode: string, busy: [number, number][], unparsed: number, windowStart: number, windowEnd: number): DayStatus;
@@ -0,0 +1,59 @@
1
+ // Pure, DB-free day-status math for space-availability-range. Split out from
2
+ // index.ts so it can be exercised directly by a standalone test without
3
+ // pulling in Deno.serve / the npm supabase-js client.
4
+ /** Next calendar date string (UTC-arithmetic on the YYYY-MM-DD parts only — no timezone involved). */
5
+ export function nextDateStr(dateStr) {
6
+ const [y, m, d] = dateStr.split('-').map(Number);
7
+ const dt = new Date(Date.UTC(y, m - 1, d + 1));
8
+ return `${dt.getUTCFullYear()}-${String(dt.getUTCMonth() + 1).padStart(2, '0')}-${String(dt.getUTCDate()).padStart(2, '0')}`;
9
+ }
10
+ /** All calendar date strings from start to end, inclusive. Caller enforces the max-range cap. */
11
+ export function dateRange(start, end) {
12
+ const dates = [];
13
+ let cur = start;
14
+ while (true) {
15
+ dates.push(cur);
16
+ if (cur === end)
17
+ break;
18
+ cur = nextDateStr(cur);
19
+ }
20
+ return dates;
21
+ }
22
+ /** Merge overlapping/adjacent [start,end) pairs, sorted ascending. */
23
+ export function mergeRanges(ranges) {
24
+ const sorted = [...ranges].sort((a, b) => a[0] - b[0]);
25
+ const out = [];
26
+ for (const [s, e] of sorted) {
27
+ const last = out[out.length - 1];
28
+ if (last && s <= last[1])
29
+ last[1] = Math.max(last[1], e);
30
+ else
31
+ out.push([s, e]);
32
+ }
33
+ return out;
34
+ }
35
+ /**
36
+ * Milliseconds of `[windowStart,windowEnd)` covered by `busy`, clipped to the
37
+ * window. `unparsed > 0` means some row's range could not be proven free, so
38
+ * (matching getBusyRangesDetailed's own doc comment for read-only "what's
39
+ * open" surfaces) the whole window is treated as covered rather than free.
40
+ */
41
+ export function coveredMs(busy, unparsed, windowStart, windowEnd) {
42
+ if (unparsed > 0)
43
+ return windowEnd - windowStart;
44
+ const clipped = busy
45
+ .map(([s, e]) => [Math.max(s, windowStart), Math.min(e, windowEnd)])
46
+ .filter(([s, e]) => e > s);
47
+ return mergeRanges(clipped).reduce((sum, [s, e]) => sum + (e - s), 0);
48
+ }
49
+ export function statusForDay(bookingMode, busy, unparsed, windowStart, windowEnd) {
50
+ const covered = coveredMs(busy, unparsed, windowStart, windowEnd);
51
+ if (covered <= 0)
52
+ return 'open';
53
+ if (covered >= windowEnd - windowStart)
54
+ return 'full';
55
+ // day_block and quote have no partial state — any busy time at all reads
56
+ // as full (a day_block room is whole/half-day blocks, not hourly slots;
57
+ // a quote room has no self-serve slots at all).
58
+ return bookingMode === 'hourly' ? 'partial' : 'full';
59
+ }
@@ -0,0 +1 @@
1
+ export declare function handle(req: Request): Promise<Response>;
@@ -0,0 +1,42 @@
1
+ import webpush from "web-push";
2
+ function errorSummary(err) {
3
+ const name = err instanceof Error ? err.name : undefined;
4
+ const message = err instanceof Error ? err.message : String(err ?? "");
5
+ const stack = err instanceof Error ? (err.stack ?? "").slice(0, 500) : "";
6
+ return { name, message, stack };
7
+ }
8
+ export async function handle(req) {
9
+ try {
10
+ const keys = webpush.generateVAPIDKeys();
11
+ webpush.setVapidDetails("mailto:test@example.com", keys.publicKey, keys.privateKey);
12
+ // Try building a real send call against a syntactically-valid but fake
13
+ // subscription, so we exercise the payload-encryption code path too.
14
+ // We EXPECT this specific send to fail (fake endpoint/keys) — we only
15
+ // care whether it fails with a normal push-service HTTP error (proves
16
+ // the crypto/encryption path ran) vs a Deno/npm compat crash (module
17
+ // resolution error, "createECDH is not a function", etc).
18
+ let sendResult;
19
+ try {
20
+ await webpush.sendNotification({
21
+ endpoint: "https://fcm.googleapis.com/fcm/send/fake-diagnostic-endpoint",
22
+ keys: {
23
+ p256dh: "BCvKwB2lbVjB3Ci77vzjxvzz1LvGe1I13a-b_bB2GVSlbVjB3Ci77vzjxvzz1LvGe1I13a-b_bB2GVSlbVjB3Cg",
24
+ auth: "8Q5g2vzz1LvGe1I13a-b",
25
+ },
26
+ }, JSON.stringify({ hello: "world" }));
27
+ sendResult = "unexpected_success";
28
+ }
29
+ catch (sendErr) {
30
+ sendResult = errorSummary(sendErr);
31
+ }
32
+ return new Response(JSON.stringify({ ok: true, keygen: "ok", sendResult }), {
33
+ headers: { "Content-Type": "application/json" },
34
+ });
35
+ }
36
+ catch (e) {
37
+ return new Response(JSON.stringify({ ok: false, error: errorSummary(e) }), {
38
+ status: 500,
39
+ headers: { "Content-Type": "application/json" },
40
+ });
41
+ }
42
+ }
@@ -0,0 +1,17 @@
1
+ export interface EventAccessAdminConfig {
2
+ /** Origin of the tenant's ftw-middleware-equivalent service, e.g.
3
+ * https://bus.example.com. No trailing slash. */
4
+ busBase: string;
5
+ /** Deploy-verification marker (lovable-ops §2c, 2026-09-04) returned by the
6
+ * unauthenticated GET branch: edge functions can silently keep serving
7
+ * pre-deploy bytecode even after a commit lands on main, `read_file` shows
8
+ * correct source, and a frontend `deploy_project` succeeds. Bump this string
9
+ * by hand whenever this tenant's wrapper changes OR its pinned
10
+ * graniteer-core version changes, and after asking Lovable to redeploy this
11
+ * function, GET this endpoint and confirm the returned build string matches
12
+ * what you just wrote — that's a live, cheap way to confirm the *deployed*
13
+ * bytecode (wrapper plus the core version it pulled in) is current, without
14
+ * needing a real door/grant to test against. */
15
+ buildMarker: string;
16
+ }
17
+ export declare function createEventAccessAdminHandler(config: EventAccessAdminConfig): (req: Request) => Promise<Response>;