@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,202 @@
1
+ // supabase/functions/admin-mark-booking-paid/index.ts
2
+ //
3
+ // Manual "mark fully paid" admin action, for payments collected outside the
4
+ // normal Stripe checkout flow -- cash, a Mercury wire/ACH, a sponsorship, or
5
+ // anything else staff need to record by hand. Works on any booking tier; the
6
+ // Commons (tier-3) contract flow is the main consumer since its remaining
7
+ // balance is explicitly collected by check/ACH per the contract, never
8
+ // through Stripe.
9
+ import { createClient } from '@supabase/supabase-js';
10
+ import { z } from 'zod';
11
+ import { jwtVerify, createRemoteJWKSet } from 'jose';
12
+ import Stripe from 'stripe';
13
+ import { clientIp, checkRateLimit } from '../rateLimit.js';
14
+ import { logOps } from '../ops.js';
15
+ const corsHeaders = {
16
+ 'Access-Control-Allow-Origin': '*',
17
+ 'Access-Control-Allow-Headers': 'authorization, x-client-info, apikey, content-type',
18
+ 'Access-Control-Allow-Methods': 'POST, OPTIONS',
19
+ };
20
+ const JWKS_URL_SUFFIX = '/auth/v1/.well-known/jwks.json';
21
+ let jwksCache = null;
22
+ function getJwks(supabaseUrl) {
23
+ if (!jwksCache)
24
+ jwksCache = createRemoteJWKSet(new URL(`${supabaseUrl}${JWKS_URL_SUFFIX}`));
25
+ return jwksCache;
26
+ }
27
+ async function verifyCaller(authHeader, supabaseUrl) {
28
+ if (!authHeader?.toLowerCase().startsWith('bearer '))
29
+ return null;
30
+ const token = authHeader.slice(7).trim();
31
+ try {
32
+ const { payload } = await jwtVerify(token, getJwks(supabaseUrl));
33
+ const claims = payload;
34
+ if (!claims.sub)
35
+ return null;
36
+ return claims;
37
+ }
38
+ catch {
39
+ return null;
40
+ }
41
+ }
42
+ function json(status, body) {
43
+ return new Response(JSON.stringify(body), { status, headers: { ...corsHeaders, 'Content-Type': 'application/json' } });
44
+ }
45
+ function fail(status, code, error, extra) {
46
+ return json(status, { ok: false, status, code, error, ...(extra ?? {}) });
47
+ }
48
+ const PAYMENT_METHODS = ['cash', 'stripe', 'mercury', 'sponsored', 'other'];
49
+ const Body = z.object({
50
+ booking_id: z.string().uuid(),
51
+ payment_method: z.enum(PAYMENT_METHODS),
52
+ notes: z.string().trim().max(500).optional(),
53
+ }).refine((b) => b.payment_method !== 'stripe' || !!b.notes?.trim(), { message: 'notes (e.g. the Stripe payment/charge ID) are required when payment_method is "stripe" -- this action does not itself touch Stripe.', path: ['notes'] });
54
+ // Only a live, still-collectible booking can be marked paid. Deliberately an
55
+ // allowlist, not a denylist of terminal statuses -- a new booking_status
56
+ // value added later (e.g. a dispute/chargeback state) should default to
57
+ // NOT payable until someone explicitly decides otherwise.
58
+ const PAYABLE_STATUSES = new Set(['pending', 'deposit_paid']);
59
+ export async function handle(req) {
60
+ if (req.method === 'OPTIONS')
61
+ return new Response('ok', { headers: corsHeaders });
62
+ if (req.method !== 'POST')
63
+ return fail(405, 'method_not_allowed', 'Method not allowed.');
64
+ const SUPABASE_URL = Deno.env.get('SUPABASE_URL');
65
+ const SERVICE_ROLE_KEY = Deno.env.get('SUPABASE_SERVICE_ROLE_KEY');
66
+ const authHeader = req.headers.get('Authorization') || req.headers.get('authorization');
67
+ const caller = await verifyCaller(authHeader, SUPABASE_URL);
68
+ if (!caller)
69
+ return fail(401, 'unauthenticated', 'Not signed in.');
70
+ if (caller.aal !== 'aal2')
71
+ return fail(403, 'mfa_required', 'Two-factor authentication is required.');
72
+ const callerEmail = (caller.email ?? '').toLowerCase();
73
+ if (!callerEmail)
74
+ return fail(403, 'no_email', 'Caller has no email claim.');
75
+ const admin = createClient(SUPABASE_URL, SERVICE_ROLE_KEY, { auth: { persistSession: false, autoRefreshToken: false } });
76
+ const [ipOk, emailOk] = await Promise.all([
77
+ checkRateLimit(admin, 'admin-mark-booking-paid-ip', clientIp(req), 20, 300),
78
+ checkRateLimit(admin, 'admin-mark-booking-paid-email', callerEmail, 20, 300),
79
+ ]);
80
+ if (!ipOk || !emailOk)
81
+ return fail(429, 'rate_limited', 'Too many attempts — try again shortly.');
82
+ const { data: allow, error: allowErr } = await admin.from('admin_users').select('email').eq('email', callerEmail).maybeSingle();
83
+ if (allowErr)
84
+ return fail(500, 'allowlist_lookup_failed', allowErr.message);
85
+ if (!allow)
86
+ return fail(403, 'not_authorized', 'Not authorized.');
87
+ let raw;
88
+ try {
89
+ raw = await req.json();
90
+ }
91
+ catch {
92
+ return fail(400, 'invalid_json', 'Body was not valid JSON.');
93
+ }
94
+ const parsed = Body.safeParse(raw);
95
+ if (!parsed.success)
96
+ return fail(400, 'invalid_body', JSON.stringify(parsed.error.flatten().fieldErrors));
97
+ const { booking_id, payment_method, notes } = parsed.data;
98
+ const { data: booking, error: bErr } = await admin
99
+ .from('bookings')
100
+ .select('id,status,list_amount_cents,dynamic_discount_cents,credit_applied_cents,discount_applied_cents,charged_amount_cents,paid_method,stripe_session_id,hold_expires_at,deposit_paid_at,payment_source,paid_notes,paid_marked_by_email,paid_marked_at')
101
+ .eq('id', booking_id)
102
+ .maybeSingle();
103
+ if (bErr)
104
+ return fail(500, 'booking_lookup_failed', bErr.message);
105
+ if (!booking)
106
+ return fail(404, 'booking_not_found', 'Booking not found.');
107
+ const priorStatus = String(booking.status);
108
+ if (!PAYABLE_STATUSES.has(priorStatus)) {
109
+ return fail(409, 'not_payable', `Booking status is "${priorStatus}"; nothing to mark paid.`);
110
+ }
111
+ // Never guess an amount -- a null list price means the booking isn't
112
+ // priced yet. (Number(null ?? 0) would silently treat that as $0 and a
113
+ // Postgres CHECK constraint passes on a NULL comparison, so nothing else
114
+ // would have caught this.)
115
+ if (booking.list_amount_cents == null) {
116
+ return fail(409, 'missing_list_amount', 'This booking has no list amount set; fix the booking before marking it paid.');
117
+ }
118
+ const grossCents = Number(booking.list_amount_cents)
119
+ - Number(booking.dynamic_discount_cents ?? 0)
120
+ - Number(booking.credit_applied_cents ?? 0)
121
+ - Number(booking.discount_applied_cents ?? 0);
122
+ // 'sponsored' means the venue comped it -- $0 actually changed hands, so
123
+ // charged_amount_cents must be $0. We fold the remainder into
124
+ // discount_applied_cents so bookings_amount_math_check is satisfied
125
+ // truthfully instead of recording full list revenue for a comped event.
126
+ const isSponsored = payment_method === 'sponsored';
127
+ const netCents = isSponsored ? 0 : grossCents;
128
+ if (!isSponsored && netCents <= 0) {
129
+ return fail(409, 'invalid_amount', `Computed amount is $${(netCents / 100).toFixed(2)}, which isn't a valid amount to mark paid. Check the booking's discounts/credits.`);
130
+ }
131
+ const extraDiscountForSponsored = isSponsored ? grossCents : 0;
132
+ // If there's still a live, unpaid Stripe checkout session on this booking
133
+ // (the deposit link emailed on contract signature), void it before
134
+ // recording an out-of-band payment. The real deposit-paid webhook is
135
+ // CAS-guarded on status='pending' so it can no longer corrupt this row
136
+ // once we flip to 'paid' below -- but Stripe would still capture real
137
+ // money if the customer clicks that live link later, which is the actual
138
+ // harm this guards against.
139
+ if (booking.stripe_session_id && priorStatus === 'pending') {
140
+ const stripeKey = Deno.env.get('STRIPE_SECRET_KEY');
141
+ if (!stripeKey) {
142
+ return fail(500, 'stripe_not_configured', 'STRIPE_SECRET_KEY is not set; cannot safely void the outstanding deposit link.');
143
+ }
144
+ try {
145
+ const stripe = new Stripe(stripeKey, { apiVersion: '2024-11-20.acacia' });
146
+ const session = await stripe.checkout.sessions.retrieve(String(booking.stripe_session_id));
147
+ if (session.status === 'open') {
148
+ await stripe.checkout.sessions.expire(String(booking.stripe_session_id));
149
+ }
150
+ }
151
+ catch (e) {
152
+ return fail(502, 'stripe_session_expire_failed', `Could not void the outstanding Stripe deposit link (${e instanceof Error ? e.message : String(e)}). Void it manually in the Stripe dashboard, then retry.`);
153
+ }
154
+ }
155
+ const markedAt = new Date().toISOString();
156
+ const { data: updated, error: updErr } = await admin
157
+ .from('bookings')
158
+ .update({
159
+ status: 'paid',
160
+ charged_amount_cents: netCents,
161
+ discount_applied_cents: Number(booking.discount_applied_cents ?? 0) + extraDiscountForSponsored,
162
+ paid_method: payment_method,
163
+ payment_source: payment_method === 'stripe' ? 'stripe' : 'offline',
164
+ paid_notes: notes ?? null,
165
+ paid_marked_by_email: callerEmail,
166
+ paid_marked_at: markedAt,
167
+ hold_expires_at: null,
168
+ })
169
+ .eq('id', booking_id)
170
+ .eq('status', priorStatus) // CAS -- refuse a stale double-click racing a real webhook
171
+ .select('id')
172
+ .maybeSingle();
173
+ if (updErr)
174
+ return fail(500, 'update_failed', updErr.message);
175
+ if (!updated)
176
+ return fail(409, 'status_changed', "This booking's status changed before the update landed — reload and try again.");
177
+ await logOps(admin, 'booking_marked_fully_paid', {
178
+ booking_id, actor: callerEmail, actor_user_id: caller.sub, payment_method, notes: notes ?? null,
179
+ prior_status: priorStatus, charged_amount_cents: netCents,
180
+ // mark_event_at ties this exact log row to the exact row mutation it
181
+ // describes -- admin-correct-booking matches on this instead of trusting
182
+ // "most recent row of this kind," which a swallowed insert error (or a
183
+ // second mark-paid/undo cycle) could otherwise make stale-but-present.
184
+ mark_event_at: markedAt,
185
+ // Full "before" snapshot of every column this action mutates AND every
186
+ // column bookings_amount_math_check depends on, so admin-correct-booking
187
+ // can both revert this exact row and detect drift instead of guessing.
188
+ prior_charged_amount_cents: booking.charged_amount_cents ?? null,
189
+ prior_discount_applied_cents: Number(booking.discount_applied_cents ?? 0),
190
+ prior_list_amount_cents: Number(booking.list_amount_cents),
191
+ prior_dynamic_discount_cents: Number(booking.dynamic_discount_cents ?? 0),
192
+ prior_credit_applied_cents: Number(booking.credit_applied_cents ?? 0),
193
+ prior_paid_method: booking.paid_method ?? null,
194
+ prior_payment_source: booking.payment_source ?? null,
195
+ prior_paid_notes: booking.paid_notes ?? null,
196
+ prior_paid_marked_by_email: booking.paid_marked_by_email ?? null,
197
+ prior_paid_marked_at: booking.paid_marked_at ?? null,
198
+ prior_hold_expires_at: booking.hold_expires_at ?? null,
199
+ prior_deposit_paid_at: booking.deposit_paid_at ?? null,
200
+ }, { severity: 'warning', bookingId: booking_id }).catch(() => { });
201
+ return json(200, { ok: true, booking_id, status: 'paid', charged_amount_cents: netCents });
202
+ }
@@ -0,0 +1,6 @@
1
+ export declare function handle(req: Request, operator: {
2
+ operatorName: string;
3
+ operatorShortName: string;
4
+ domain: string;
5
+ supportEmail: string;
6
+ }): Promise<Response>;
@@ -0,0 +1,159 @@
1
+ // Staff-triggered Stripe billing-portal link for a specific member.
2
+ //
3
+ // Mints the same kind of Billing Portal session create-portal-session gives
4
+ // a signed-in member -- staff never see or handle a card number, they only
5
+ // get (and optionally email) a Stripe-hosted link the member uses themselves.
6
+ //
7
+ // Auth/allowlist/rate-limit scaffold copied from admin-resend-payment-link-email.
8
+ import { createClient } from '@supabase/supabase-js';
9
+ import Stripe from 'stripe';
10
+ import { jwtVerify, createRemoteJWKSet } from 'jose';
11
+ import { clientIp, checkRateLimit } from '../rateLimit.js';
12
+ import { logOps } from '../ops.js';
13
+ import { getOrCreateCoworkingPortalConfig } from '../stripeCoworkingPortal.js';
14
+ import { sendBillingPortalLinkEmail } from '../billingPortalLinkEmail.js';
15
+ const corsHeaders = {
16
+ 'Access-Control-Allow-Origin': '*',
17
+ 'Access-Control-Allow-Headers': 'authorization, x-client-info, apikey, content-type',
18
+ 'Access-Control-Allow-Methods': 'POST, OPTIONS',
19
+ };
20
+ const JWKS_URL_SUFFIX = '/auth/v1/.well-known/jwks.json';
21
+ let jwksCache = null;
22
+ function getJwks(supabaseUrl) {
23
+ if (!jwksCache)
24
+ jwksCache = createRemoteJWKSet(new URL(`${supabaseUrl}${JWKS_URL_SUFFIX}`));
25
+ return jwksCache;
26
+ }
27
+ async function verifyCaller(authHeader, supabaseUrl) {
28
+ if (!authHeader?.toLowerCase().startsWith('bearer '))
29
+ return null;
30
+ const token = authHeader.slice(7).trim();
31
+ try {
32
+ const { payload } = await jwtVerify(token, getJwks(supabaseUrl));
33
+ const claims = payload;
34
+ if (!claims.sub)
35
+ return null;
36
+ return claims;
37
+ }
38
+ catch {
39
+ return null;
40
+ }
41
+ }
42
+ function json(status, body) {
43
+ return new Response(JSON.stringify(body), {
44
+ status,
45
+ headers: { ...corsHeaders, 'Content-Type': 'application/json' },
46
+ });
47
+ }
48
+ export async function handle(req, operator) {
49
+ if (req.method === 'OPTIONS')
50
+ return new Response('ok', { headers: corsHeaders });
51
+ if (req.method !== 'POST')
52
+ return json(405, { ok: false, error: 'method_not_allowed' });
53
+ const SUPABASE_URL = Deno.env.get('SUPABASE_URL');
54
+ const SERVICE_ROLE_KEY = Deno.env.get('SUPABASE_SERVICE_ROLE_KEY');
55
+ const stripeKey = Deno.env.get('STRIPE_SECRET_KEY');
56
+ if (!stripeKey)
57
+ return json(500, { ok: false, error: 'stripe_not_configured' });
58
+ const authHeader = req.headers.get('Authorization') || req.headers.get('authorization');
59
+ const caller = await verifyCaller(authHeader, SUPABASE_URL);
60
+ if (!caller)
61
+ return json(401, { ok: false, error: 'unauthenticated' });
62
+ if (caller.aal !== 'aal2')
63
+ return json(403, { ok: false, error: 'mfa_required' });
64
+ const callerEmail = (caller.email ?? '').toLowerCase();
65
+ if (!callerEmail)
66
+ return json(403, { ok: false, error: 'no_email' });
67
+ const admin = createClient(SUPABASE_URL, SERVICE_ROLE_KEY, {
68
+ auth: { persistSession: false, autoRefreshToken: false },
69
+ });
70
+ const [ipOk, emailOk] = await Promise.all([
71
+ checkRateLimit(admin, 'admin-mint-billing-portal-ip', clientIp(req), 60, 300),
72
+ checkRateLimit(admin, 'admin-mint-billing-portal-email', callerEmail, 40, 300),
73
+ ]);
74
+ if (!ipOk || !emailOk)
75
+ return json(429, { ok: false, error: 'rate_limited' });
76
+ const { data: allow, error: allowErr } = await admin
77
+ .from('admin_users').select('email').eq('email', callerEmail).maybeSingle();
78
+ if (allowErr)
79
+ return json(500, { ok: false, error: 'allowlist_lookup_failed' });
80
+ if (!allow)
81
+ return json(403, { ok: false, error: 'not_authorized' });
82
+ let body;
83
+ try {
84
+ body = await req.json();
85
+ }
86
+ catch {
87
+ return json(400, { ok: false, error: 'invalid_json' });
88
+ }
89
+ const membershipId = (body.membership_id ?? '').trim();
90
+ if (!/^[0-9a-f-]{36}$/i.test(membershipId)) {
91
+ return json(400, { ok: false, error: 'invalid_membership_id' });
92
+ }
93
+ const sendEmail = body.send_email === true;
94
+ const { data: row, error: rowErr } = await admin
95
+ .from('memberships')
96
+ .select('id,email,customer_name,status,stripe_customer_id')
97
+ .eq('id', membershipId)
98
+ .maybeSingle();
99
+ if (rowErr)
100
+ return json(500, { ok: false, error: 'lookup_failed' });
101
+ if (!row)
102
+ return json(404, { ok: false, error: 'not_found' });
103
+ if (!row.stripe_customer_id)
104
+ return json(400, { ok: false, error: 'no_stripe_customer' });
105
+ let portalUrl;
106
+ try {
107
+ const stripe = new Stripe(stripeKey, { apiVersion: '2024-11-20.acacia' });
108
+ const cfgId = await getOrCreateCoworkingPortalConfig(stripe, admin, {
109
+ headline: `Manage your ${operator.operatorName} membership`,
110
+ defaultReturnUrl: `https://${operator.domain}/membership`,
111
+ });
112
+ const session = await stripe.billingPortal.sessions.create({
113
+ customer: row.stripe_customer_id,
114
+ configuration: cfgId,
115
+ return_url: `https://${operator.domain}/membership`,
116
+ });
117
+ if (!session.url)
118
+ throw new Error('stripe_session_missing_url');
119
+ portalUrl = session.url;
120
+ }
121
+ catch (e) {
122
+ const detail = (e instanceof Error ? e.message : String(e)).slice(0, 500);
123
+ await logOps(admin, 'admin_billing_portal_link_failed', { membership_id: membershipId, actor_email: callerEmail, message: detail }, { severity: 'error' }).catch(() => { });
124
+ return json(502, { ok: false, error: 'portal_unavailable', detail });
125
+ }
126
+ let emailed = false;
127
+ if (sendEmail) {
128
+ if (!row.email) {
129
+ return json(400, { ok: false, error: 'no_member_email', url: portalUrl });
130
+ }
131
+ const result = await sendBillingPortalLinkEmail(admin, {
132
+ email: row.email,
133
+ name: row.customer_name,
134
+ portalUrl,
135
+ }, {
136
+ name: operator.operatorName,
137
+ shortName: operator.operatorShortName,
138
+ domain: operator.domain,
139
+ supportEmail: operator.supportEmail,
140
+ });
141
+ emailed = result === 'sent';
142
+ if (!emailed) {
143
+ // Link was minted successfully; only the email leg failed. Return it
144
+ // anyway so staff can still copy/send it by hand.
145
+ return json(200, { ok: true, url: portalUrl, emailed: false, email_error: result });
146
+ }
147
+ }
148
+ await admin.from('membership_admin_actions').insert({
149
+ membership_id: membershipId,
150
+ action: sendEmail ? 'billing_portal_link_emailed' : 'billing_portal_link_minted',
151
+ actor_email: callerEmail,
152
+ reason: sendEmail ? `Emailed to ${row.email ?? 'unknown'}` : 'Link copied by staff',
153
+ idempotency_key: crypto.randomUUID(),
154
+ }).then(({ error }) => {
155
+ if (error)
156
+ console.warn('[admin-mint-billing-portal-link] audit insert failed', error);
157
+ });
158
+ return json(200, { ok: true, url: portalUrl, emailed });
159
+ }
@@ -0,0 +1,3 @@
1
+ export declare function handle(req: Request, operator: {
2
+ domain: string;
3
+ }): Promise<Response>;
@@ -0,0 +1,54 @@
1
+ // Internal ops tool: re-mint the agreement portal URL for an existing
2
+ // signature_documents row. Read-only against the DB; reuses MANAGE_TOKEN_SECRET
3
+ // and the same buildAgreementPortalUrl helper as create-agreement.
4
+ import { createClient } from '@supabase/supabase-js';
5
+ import { buildAgreementPortalUrl } from '../manageToken.js';
6
+ const corsHeaders = {
7
+ 'Access-Control-Allow-Origin': '*',
8
+ 'Access-Control-Allow-Headers': 'authorization, x-client-info, apikey, content-type',
9
+ 'Access-Control-Allow-Methods': 'POST, OPTIONS',
10
+ };
11
+ function json(status, body) {
12
+ return new Response(JSON.stringify(body), {
13
+ status,
14
+ headers: { ...corsHeaders, 'Content-Type': 'application/json' },
15
+ });
16
+ }
17
+ export async function handle(req, operator) {
18
+ if (req.method === 'OPTIONS')
19
+ return new Response('ok', { headers: corsHeaders });
20
+ if (req.method !== 'POST')
21
+ return json(405, { ok: false, error: 'method_not_allowed' });
22
+ let body;
23
+ try {
24
+ body = await req.json();
25
+ }
26
+ catch {
27
+ return json(400, { ok: false, error: 'invalid_json' });
28
+ }
29
+ const id = typeof body.signature_document_id === 'string' ? body.signature_document_id.trim() : '';
30
+ const email = typeof body.signer_email === 'string' ? body.signer_email.trim() : '';
31
+ if (!/^[0-9a-f-]{36}$/i.test(id))
32
+ return json(400, { ok: false, error: 'invalid_signature_document_id' });
33
+ if (!email)
34
+ return json(400, { ok: false, error: 'invalid_signer_email' });
35
+ const admin = createClient(Deno.env.get('SUPABASE_URL'), Deno.env.get('SUPABASE_SERVICE_ROLE_KEY'), { auth: { persistSession: false, autoRefreshToken: false } });
36
+ const { data: row, error } = await admin
37
+ .from('signature_documents')
38
+ .select('id,signer_email')
39
+ .eq('id', id)
40
+ .maybeSingle();
41
+ if (error)
42
+ return json(500, { ok: false, error: 'lookup_failed' });
43
+ if (!row)
44
+ return json(404, { ok: false, error: 'not_found' });
45
+ const rowEmail = String(row.signer_email ?? '').toLowerCase();
46
+ if (!rowEmail || rowEmail !== email.toLowerCase()) {
47
+ return json(404, { ok: false, error: 'not_found' });
48
+ }
49
+ const secret = Deno.env.get('MANAGE_TOKEN_SECRET');
50
+ if (!secret)
51
+ return json(500, { ok: false, error: 'not_configured' });
52
+ const url = await buildAgreementPortalUrl(`https://${operator.domain}`, String(row.id), rowEmail, secret);
53
+ return json(200, { ok: true, url });
54
+ }
@@ -0,0 +1,47 @@
1
+ export interface OnboardStripeAccount {
2
+ id: string;
3
+ }
4
+ export interface OnboardStripeAccountLink {
5
+ url: string;
6
+ expires_at: number;
7
+ }
8
+ export interface OnboardStripeLike {
9
+ accounts: {
10
+ create(params: Record<string, unknown>): Promise<OnboardStripeAccount>;
11
+ };
12
+ accountLinks: {
13
+ create(params: Record<string, unknown>): Promise<OnboardStripeAccountLink>;
14
+ };
15
+ }
16
+ export interface OnboardDeps {
17
+ stripe: OnboardStripeLike;
18
+ log(kind: string, detail: Record<string, unknown>, severity: 'info' | 'warning' | 'error'): Promise<unknown>;
19
+ }
20
+ export interface OnboardInput {
21
+ tenantLabel: string;
22
+ email: string;
23
+ country: string;
24
+ businessType?: 'individual' | 'company';
25
+ }
26
+ export interface OnboardResult {
27
+ status: number;
28
+ body: Record<string, unknown>;
29
+ }
30
+ /** Basic shape/sanity checks only -- Stripe does its own real validation. */
31
+ export declare function validateOnboardInput(raw: unknown): {
32
+ ok: true;
33
+ value: OnboardInput;
34
+ } | {
35
+ ok: false;
36
+ error: string;
37
+ };
38
+ /** accounts.create params, built conditionally so `business_type` is never
39
+ * passed as `undefined` -- the Stripe SDK rejects that key outright. */
40
+ export declare function buildStripeAccountCreateParams(input: OnboardInput): Record<string, unknown>;
41
+ export declare function handleOnboardConnectAccount(rawBody: unknown, actorEmail: string, domain: string, deps: OnboardDeps): Promise<OnboardResult>;
42
+ export declare function handle(req: Request, operator: {
43
+ operatorName: string;
44
+ operatorShortName: string;
45
+ domain: string;
46
+ supportEmail: string;
47
+ }): Promise<Response>;
@@ -0,0 +1,197 @@
1
+ // Admin-triggered onboarding of a brand-new Stripe Connect account for a
2
+ // tenant: creates the Express account and immediately mints an Account Link
3
+ // for it in one request. There is no "link an existing account" flow here --
4
+ // see D33 Phase B.5.
5
+ //
6
+ // Auth/allowlist/rate-limit scaffold copied from admin-mint-billing-portal-link.
7
+ //
8
+ // IMPORTANT: this function intentionally does NOT persist the resulting
9
+ // account_id anywhere -- not in siteConfig, not in any table. It is returned
10
+ // in the JSON response only. Phase C adds a connectedAccountId field to
11
+ // siteConfig; until that lands, the caller is responsible for placing the id
12
+ // wherever it is needed. Do not "fix" this by adding a database write.
13
+ import { createClient } from '@supabase/supabase-js';
14
+ import Stripe from 'stripe';
15
+ import { jwtVerify, createRemoteJWKSet } from 'jose';
16
+ import { clientIp, checkRateLimit } from '../rateLimit.js';
17
+ import { logOps } from '../ops.js';
18
+ const corsHeaders = {
19
+ 'Access-Control-Allow-Origin': '*',
20
+ 'Access-Control-Allow-Headers': 'authorization, x-client-info, apikey, content-type',
21
+ 'Access-Control-Allow-Methods': 'POST, OPTIONS',
22
+ };
23
+ const JWKS_URL_SUFFIX = '/auth/v1/.well-known/jwks.json';
24
+ let jwksCache = null;
25
+ function getJwks(supabaseUrl) {
26
+ if (!jwksCache)
27
+ jwksCache = createRemoteJWKSet(new URL(`${supabaseUrl}${JWKS_URL_SUFFIX}`));
28
+ return jwksCache;
29
+ }
30
+ async function verifyCaller(authHeader, supabaseUrl) {
31
+ if (!authHeader?.toLowerCase().startsWith('bearer '))
32
+ return null;
33
+ const token = authHeader.slice(7).trim();
34
+ try {
35
+ const { payload } = await jwtVerify(token, getJwks(supabaseUrl));
36
+ const claims = payload;
37
+ if (!claims.sub)
38
+ return null;
39
+ return claims;
40
+ }
41
+ catch {
42
+ return null;
43
+ }
44
+ }
45
+ function json(status, body) {
46
+ return new Response(JSON.stringify(body), {
47
+ status,
48
+ headers: { ...corsHeaders, 'Content-Type': 'application/json' },
49
+ });
50
+ }
51
+ /** Basic shape/sanity checks only -- Stripe does its own real validation. */
52
+ export function validateOnboardInput(raw) {
53
+ const body = (raw ?? {});
54
+ const tenantLabel = typeof body.tenant_label === 'string' ? body.tenant_label.trim() : '';
55
+ if (!tenantLabel || tenantLabel.length > 200) {
56
+ return { ok: false, error: 'invalid_tenant_label' };
57
+ }
58
+ const email = typeof body.email === 'string' ? body.email.trim() : '';
59
+ if (!email || !email.includes('@') || email.length > 320) {
60
+ return { ok: false, error: 'invalid_email' };
61
+ }
62
+ let country = 'US';
63
+ if (body.country !== undefined && body.country !== null) {
64
+ const rawCountry = typeof body.country === 'string' ? body.country : '';
65
+ if (!/^[A-Za-z]{2}$/.test(rawCountry)) {
66
+ return { ok: false, error: 'invalid_country' };
67
+ }
68
+ country = rawCountry.toUpperCase();
69
+ }
70
+ let businessType;
71
+ if (body.business_type !== undefined && body.business_type !== null) {
72
+ if (body.business_type !== 'individual' && body.business_type !== 'company') {
73
+ return { ok: false, error: 'invalid_business_type' };
74
+ }
75
+ businessType = body.business_type;
76
+ }
77
+ return { ok: true, value: { tenantLabel, email, country, businessType } };
78
+ }
79
+ /** accounts.create params, built conditionally so `business_type` is never
80
+ * passed as `undefined` -- the Stripe SDK rejects that key outright. */
81
+ export function buildStripeAccountCreateParams(input) {
82
+ return {
83
+ type: 'express',
84
+ country: input.country,
85
+ email: input.email,
86
+ ...(input.businessType ? { business_type: input.businessType } : {}),
87
+ capabilities: {
88
+ card_payments: { requested: true },
89
+ transfers: { requested: true },
90
+ },
91
+ };
92
+ }
93
+ export async function handleOnboardConnectAccount(rawBody, actorEmail, domain, deps) {
94
+ const validated = validateOnboardInput(rawBody);
95
+ if (!validated.ok) {
96
+ return { status: 400, body: { ok: false, error: validated.error } };
97
+ }
98
+ const input = validated.value;
99
+ let account;
100
+ try {
101
+ account = await deps.stripe.accounts.create(buildStripeAccountCreateParams(input));
102
+ }
103
+ catch (e) {
104
+ const detail = (e instanceof Error ? e.message : String(e)).slice(0, 500);
105
+ await deps.log('admin_connect_account_create_failed', {
106
+ tenant_label: input.tenantLabel, actor_email: actorEmail, message: detail,
107
+ }, 'error');
108
+ return { status: 502, body: { ok: false, error: 'account_create_failed', detail } };
109
+ }
110
+ let accountLink;
111
+ try {
112
+ accountLink = await deps.stripe.accountLinks.create({
113
+ account: account.id,
114
+ refresh_url: `https://${domain}/admin/connect-onboarding-refresh?account=${account.id}`,
115
+ return_url: `https://${domain}/admin/connect-onboarding-complete?account=${account.id}`,
116
+ type: 'account_onboarding',
117
+ });
118
+ }
119
+ catch (e) {
120
+ const detail = (e instanceof Error ? e.message : String(e)).slice(0, 500);
121
+ // The account already exists in Stripe even though the link mint failed --
122
+ // surface its id so it is not lost, rather than dropping it on the floor.
123
+ await deps.log('admin_connect_account_link_failed', {
124
+ tenant_label: input.tenantLabel, actor_email: actorEmail, account_id: account.id, message: detail,
125
+ }, 'error');
126
+ return {
127
+ status: 502,
128
+ body: { ok: false, error: 'account_link_unavailable', account_id: account.id, detail },
129
+ };
130
+ }
131
+ await deps.log('admin_connect_account_onboarded', {
132
+ tenant_label: input.tenantLabel, actor_email: actorEmail, account_id: account.id,
133
+ }, 'info');
134
+ // NOT persisted anywhere on purpose -- no siteConfig write, no table insert
135
+ // of account.id above this line. It only ever leaves this function in the
136
+ // response body; see the file header for why.
137
+ return {
138
+ status: 200,
139
+ body: {
140
+ ok: true,
141
+ account_id: account.id,
142
+ onboarding_url: accountLink.url,
143
+ expires_at: accountLink.expires_at,
144
+ },
145
+ };
146
+ }
147
+ // ---8<--- END onboard-core (mirrored verbatim in admin-onboard-connect-account.test.ts) ---8<---
148
+ export async function handle(req, operator) {
149
+ if (req.method === 'OPTIONS')
150
+ return new Response('ok', { headers: corsHeaders });
151
+ if (req.method !== 'POST')
152
+ return json(405, { ok: false, error: 'method_not_allowed' });
153
+ const SUPABASE_URL = Deno.env.get('SUPABASE_URL');
154
+ const SERVICE_ROLE_KEY = Deno.env.get('SUPABASE_SERVICE_ROLE_KEY');
155
+ const stripeKey = Deno.env.get('STRIPE_SECRET_KEY');
156
+ if (!stripeKey)
157
+ return json(500, { ok: false, error: 'stripe_not_configured' });
158
+ const authHeader = req.headers.get('Authorization') || req.headers.get('authorization');
159
+ const caller = await verifyCaller(authHeader, SUPABASE_URL);
160
+ if (!caller)
161
+ return json(401, { ok: false, error: 'unauthenticated' });
162
+ if (caller.aal !== 'aal2')
163
+ return json(403, { ok: false, error: 'mfa_required' });
164
+ const callerEmail = (caller.email ?? '').toLowerCase();
165
+ if (!callerEmail)
166
+ return json(403, { ok: false, error: 'no_email' });
167
+ const admin = createClient(SUPABASE_URL, SERVICE_ROLE_KEY, {
168
+ auth: { persistSession: false, autoRefreshToken: false },
169
+ });
170
+ const [ipOk, emailOk] = await Promise.all([
171
+ checkRateLimit(admin, 'admin-onboard-connect-ip', clientIp(req), 60, 300),
172
+ checkRateLimit(admin, 'admin-onboard-connect-email', callerEmail, 40, 300),
173
+ ]);
174
+ if (!ipOk || !emailOk)
175
+ return json(429, { ok: false, error: 'rate_limited' });
176
+ const { data: allow, error: allowErr } = await admin
177
+ .from('admin_users').select('email').eq('email', callerEmail).maybeSingle();
178
+ if (allowErr)
179
+ return json(500, { ok: false, error: 'allowlist_lookup_failed' });
180
+ if (!allow)
181
+ return json(403, { ok: false, error: 'not_authorized' });
182
+ let body;
183
+ try {
184
+ body = await req.json();
185
+ }
186
+ catch {
187
+ return json(400, { ok: false, error: 'invalid_json' });
188
+ }
189
+ // Always the platform's own key: accounts.create is a platform-level call,
190
+ // never scoped to a connected account, so no `stripeAccount` request option.
191
+ const stripe = new Stripe(stripeKey, { apiVersion: '2024-11-20.acacia' });
192
+ const result = await handleOnboardConnectAccount(body, callerEmail, operator.domain, {
193
+ stripe: stripe,
194
+ log: (kind, detail, severity) => logOps(admin, kind, detail, { severity }).catch(() => { }),
195
+ });
196
+ return json(result.status, result.body);
197
+ }