@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.
- package/dist/adminBookingCredit.d.ts +107 -0
- package/dist/adminBookingCredit.js +163 -0
- package/dist/agreementCheckout.d.ts +34 -0
- package/dist/agreementCheckout.js +211 -0
- package/dist/agreementPortalEmail.d.ts +15 -0
- package/dist/agreementPortalEmail.js +107 -0
- package/dist/availability.d.ts +51 -0
- package/dist/availability.js +152 -0
- package/dist/billingPortalLinkEmail.d.ts +14 -0
- package/dist/billingPortalLinkEmail.js +98 -0
- package/dist/bookingAgreementEmail.d.ts +23 -0
- package/dist/bookingAgreementEmail.js +116 -0
- package/dist/bookingEffects.d.ts +84 -0
- package/dist/bookingEffects.js +309 -0
- package/dist/bookingHoldReclaim.d.ts +16 -0
- package/dist/bookingHoldReclaim.js +74 -0
- package/dist/busClient.d.ts +44 -0
- package/dist/busClient.js +196 -0
- package/dist/busSignature.d.ts +19 -0
- package/{src/busSignature.ts → dist/busSignature.js} +64 -71
- package/dist/checkoutCoupon.d.ts +156 -0
- package/dist/checkoutCoupon.js +369 -0
- package/dist/checkoutSessionParams.d.ts +32 -0
- package/dist/checkoutSessionParams.js +72 -0
- package/dist/commonsContract.d.ts +70 -0
- package/dist/commonsContract.js +142 -0
- package/dist/commonsDeposit.d.ts +78 -0
- package/dist/commonsDeposit.js +199 -0
- package/dist/commonsDepositWebhook.d.ts +37 -0
- package/dist/commonsDepositWebhook.js +147 -0
- package/dist/conductorAdmin.d.ts +76 -0
- package/dist/conductorAdmin.js +88 -0
- package/dist/dayPassConfirmation.d.ts +17 -0
- package/dist/dayPassConfirmation.js +187 -0
- package/dist/dunningEmails.d.ts +40 -0
- package/dist/dunningEmails.js +174 -0
- package/dist/email-templates/brand.d.ts +82 -0
- package/dist/email-templates/brand.js +72 -0
- package/dist/email-templates/email-change.d.ts +10 -0
- package/dist/email-templates/email-change.js +50 -0
- package/dist/email-templates/invite.d.ts +8 -0
- package/dist/email-templates/invite.js +44 -0
- package/dist/email-templates/magic-link.d.ts +10 -0
- package/dist/email-templates/magic-link.js +26 -0
- package/dist/email-templates/reauthentication.d.ts +6 -0
- package/dist/email-templates/reauthentication.js +35 -0
- package/dist/email-templates/recovery.d.ts +10 -0
- package/dist/email-templates/recovery.js +26 -0
- package/dist/email-templates/signup.d.ts +12 -0
- package/dist/email-templates/signup.js +30 -0
- package/dist/entitlements.d.ts +17 -0
- package/dist/entitlements.js +33 -0
- package/dist/functions/admin-cancel-membership.d.ts +3 -0
- package/dist/functions/admin-cancel-membership.js +294 -0
- package/dist/functions/admin-change-membership-plan.d.ts +3 -0
- package/dist/functions/admin-change-membership-plan.js +289 -0
- package/dist/functions/admin-charge-guest-print.d.ts +1 -0
- package/dist/functions/admin-charge-guest-print.js +227 -0
- package/dist/functions/admin-correct-booking.d.ts +1 -0
- package/dist/functions/admin-correct-booking.js +326 -0
- package/dist/functions/admin-create-booking.d.ts +43 -0
- package/dist/functions/admin-create-booking.js +410 -0
- package/dist/functions/admin-create-commons-event.d.ts +1 -0
- package/dist/functions/admin-create-commons-event.js +237 -0
- package/dist/functions/admin-debug-boldsign-doc.d.ts +1 -0
- package/dist/functions/admin-debug-boldsign-doc.js +110 -0
- package/dist/functions/admin-door-write.d.ts +1 -0
- package/dist/functions/admin-door-write.js +267 -0
- package/dist/functions/admin-issue-day-pass.d.ts +14 -0
- package/dist/functions/admin-issue-day-pass.js +213 -0
- package/dist/functions/admin-mark-booking-paid.d.ts +1 -0
- package/dist/functions/admin-mark-booking-paid.js +202 -0
- package/dist/functions/admin-mint-billing-portal-link.d.ts +6 -0
- package/dist/functions/admin-mint-billing-portal-link.js +159 -0
- package/dist/functions/admin-mint-portal-link.d.ts +3 -0
- package/dist/functions/admin-mint-portal-link.js +54 -0
- package/dist/functions/admin-onboard-connect-account.d.ts +47 -0
- package/dist/functions/admin-onboard-connect-account.js +197 -0
- package/dist/functions/admin-photo-upload.d.ts +1 -0
- package/dist/functions/admin-photo-upload.js +104 -0
- package/dist/functions/admin-remove-team-member.d.ts +1 -0
- package/dist/functions/admin-remove-team-member.js +140 -0
- package/dist/functions/admin-request-trial.d.ts +5 -0
- package/dist/functions/admin-request-trial.js +349 -0
- package/dist/functions/admin-resend-commons-deposit-link.d.ts +7 -0
- package/dist/functions/admin-resend-commons-deposit-link.js +298 -0
- package/dist/functions/admin-reset-mfa.d.ts +1 -0
- package/dist/functions/admin-reset-mfa.js +129 -0
- package/dist/functions/admin-retry-invoice-payment.d.ts +76 -0
- package/dist/functions/admin-retry-invoice-payment.js +269 -0
- package/dist/functions/admin-reverse-coupon-redemption.d.ts +1 -0
- package/dist/functions/admin-reverse-coupon-redemption.js +91 -0
- package/dist/functions/admin-revoke-agreement.d.ts +4 -0
- package/dist/functions/admin-revoke-agreement.js +410 -0
- package/dist/functions/admin-send-commons-agreement.d.ts +1 -0
- package/dist/functions/admin-send-commons-agreement.js +212 -0
- package/dist/functions/admin-set-credit-amount.d.ts +1 -0
- package/dist/functions/admin-set-credit-amount.js +112 -0
- package/dist/functions/admin-skip-commons-contract.d.ts +1 -0
- package/dist/functions/admin-skip-commons-contract.js +170 -0
- package/dist/functions/admin-undo-membership-cancel.d.ts +3 -0
- package/dist/functions/admin-undo-membership-cancel.js +143 -0
- package/dist/functions/admin-wall-photo-write.d.ts +1 -0
- package/dist/functions/admin-wall-photo-write.js +137 -0
- package/dist/functions/auth-email-hook.d.ts +20 -0
- package/dist/functions/auth-email-hook.js +209 -0
- package/dist/functions/boldsign-sender-identity.d.ts +1 -0
- package/dist/functions/boldsign-sender-identity.js +109 -0
- package/dist/functions/booking-availability.d.ts +1 -0
- package/dist/functions/booking-availability.js +355 -0
- package/dist/functions/booking-member-preview.d.ts +1 -0
- package/dist/functions/booking-member-preview.js +123 -0
- package/dist/functions/booking-status.d.ts +3 -0
- package/dist/functions/booking-status.js +139 -0
- package/dist/functions/conductor.d.ts +3 -0
- package/dist/functions/conductor.js +451 -0
- package/dist/functions/create-agreement.d.ts +8 -0
- package/dist/functions/create-agreement.js +498 -0
- package/dist/functions/create-booking.d.ts +44 -0
- package/dist/functions/create-booking.js +538 -0
- package/dist/functions/create-day-pass-checkout.d.ts +6 -0
- package/dist/functions/create-day-pass-checkout.js +225 -0
- package/dist/functions/create-portal-session.d.ts +4 -0
- package/dist/functions/create-portal-session.js +127 -0
- package/dist/functions/create-subscription-checkout.d.ts +7 -0
- package/dist/functions/create-subscription-checkout.js +405 -0
- package/dist/functions/day-pass-status.d.ts +1 -0
- package/dist/functions/day-pass-status.js +70 -0
- package/dist/functions/dayStatus.d.ts +15 -0
- package/dist/functions/dayStatus.js +59 -0
- package/dist/functions/diag-webpush-test.d.ts +1 -0
- package/dist/functions/diag-webpush-test.js +42 -0
- package/dist/functions/event-access-admin.d.ts +17 -0
- package/dist/functions/event-access-admin.js +262 -0
- package/dist/functions/event-access-store.d.ts +1 -0
- package/dist/functions/event-access-store.js +343 -0
- package/dist/functions/ezeep-print-webhook.d.ts +1 -0
- package/dist/functions/ezeep-print-webhook.js +160 -0
- package/dist/functions/ezeep-usage-reconcile.d.ts +1 -0
- package/dist/functions/ezeep-usage-reconcile.js +305 -0
- package/dist/functions/fetch-avatar-original.d.ts +3 -0
- package/dist/functions/fetch-avatar-original.js +423 -0
- package/dist/functions/get-provider-sign-link.d.ts +3 -0
- package/dist/functions/get-provider-sign-link.js +146 -0
- package/dist/functions/get-signing-link.d.ts +1 -0
- package/dist/functions/get-signing-link.js +192 -0
- package/dist/functions/guest-print-setup-confirm.d.ts +1 -0
- package/dist/functions/guest-print-setup-confirm.js +126 -0
- package/dist/functions/guest-print-submit.d.ts +1 -0
- package/dist/functions/guest-print-submit.js +145 -0
- package/dist/functions/luma-webhook.d.ts +1 -0
- package/dist/functions/luma-webhook.js +123 -0
- package/dist/functions/manage-booking.d.ts +75 -0
- package/dist/functions/manage-booking.js +409 -0
- package/dist/functions/mcp.d.ts +16 -0
- package/dist/functions/mcp.js +51 -0
- package/dist/functions/member-door-action.d.ts +60 -0
- package/dist/functions/member-door-action.js +774 -0
- package/dist/functions/member-unifi-mapping.d.ts +15 -0
- package/dist/functions/member-unifi-mapping.js +198 -0
- package/dist/functions/membership-door-sync.d.ts +14 -0
- package/dist/functions/membership-door-sync.js +863 -0
- package/dist/functions/migration-collision-alert.copy.d.ts +7 -0
- package/dist/functions/migration-collision-alert.copy.js +207 -0
- package/dist/functions/migration-collision-alert.d.ts +7 -0
- package/dist/functions/migration-collision-alert.js +207 -0
- package/dist/functions/office-assignment-end.d.ts +12 -0
- package/dist/functions/office-assignment-end.js +140 -0
- package/dist/functions/portal-booking-access.d.ts +22 -0
- package/dist/functions/portal-booking-access.js +163 -0
- package/dist/functions/portal-list-invoices.d.ts +1 -0
- package/dist/functions/portal-list-invoices.js +90 -0
- package/dist/functions/portal-request-login.d.ts +7 -0
- package/dist/functions/portal-request-login.js +199 -0
- package/dist/functions/portal-resend-invite.d.ts +6 -0
- package/dist/functions/portal-resend-invite.js +225 -0
- package/dist/functions/portal-submit-event.d.ts +4 -0
- package/dist/functions/portal-submit-event.js +152 -0
- package/dist/functions/print-billing-recover.d.ts +1 -0
- package/dist/functions/print-billing-recover.js +83 -0
- package/dist/functions/print-billing-run.d.ts +1 -0
- package/dist/functions/print-billing-run.js +153 -0
- package/dist/functions/public-facts.d.ts +1 -0
- package/dist/functions/public-facts.js +141 -0
- package/dist/functions/push-send.d.ts +3 -0
- package/dist/functions/push-send.js +297 -0
- package/dist/functions/push-test.d.ts +3 -0
- package/dist/functions/push-test.js +215 -0
- package/dist/functions/request-portal-link.d.ts +7 -0
- package/dist/functions/request-portal-link.js +178 -0
- package/dist/functions/reschedule-booking.d.ts +50 -0
- package/dist/functions/reschedule-booking.js +571 -0
- package/dist/functions/review-ratings.d.ts +1 -0
- package/dist/functions/review-ratings.js +95 -0
- package/dist/functions/space-availability-range.d.ts +1 -0
- package/dist/functions/space-availability-range.js +109 -0
- package/dist/functions/stripe-db-reconcile.d.ts +7 -0
- package/dist/functions/stripe-db-reconcile.js +326 -0
- package/dist/functions/stripe-webhook.d.ts +46 -0
- package/dist/functions/stripe-webhook.js +2381 -0
- package/dist/functions/sync-gcal-blackouts.d.ts +1 -0
- package/dist/functions/sync-gcal-blackouts.js +251 -0
- package/dist/functions/timetable-event-register.d.ts +1 -0
- package/dist/functions/timetable-event-register.js +155 -0
- package/dist/functions/timetable-event-status.d.ts +1 -0
- package/dist/functions/timetable-event-status.js +86 -0
- package/dist/functions/timetable-spaces.d.ts +1 -0
- package/dist/functions/timetable-spaces.js +161 -0
- package/dist/functions/touch-pass-reconciler.d.ts +1 -0
- package/dist/functions/touch-pass-reconciler.js +688 -0
- package/dist/functions/touch-pass-signup.d.ts +1 -0
- package/dist/functions/touch-pass-signup.js +447 -0
- package/dist/functions/upload-booking-display-image.d.ts +4 -0
- package/dist/functions/upload-booking-display-image.js +159 -0
- package/dist/functions/virtual-onboarding-purge.d.ts +1 -0
- package/dist/functions/virtual-onboarding-purge.js +123 -0
- package/dist/functions/virtual-onboarding-submit.d.ts +1 -0
- package/dist/functions/virtual-onboarding-submit.js +303 -0
- package/dist/functions/voice-booking.d.ts +10 -0
- package/dist/functions/voice-booking.js +360 -0
- package/dist/functions/voice-day-pass.d.ts +15 -0
- package/dist/functions/voice-day-pass.js +269 -0
- package/dist/functions/voice-inquiry.d.ts +1 -0
- package/dist/functions/voice-inquiry.js +156 -0
- package/dist/functions/voice-membership-signup.d.ts +16 -0
- package/dist/functions/voice-membership-signup.js +277 -0
- package/dist/functions/voice-tour-availability.d.ts +1 -0
- package/dist/functions/voice-tour-availability.js +179 -0
- package/dist/functions/voice-tour-booking.d.ts +21 -0
- package/dist/functions/voice-tour-booking.js +308 -0
- package/dist/gcalSync.d.ts +29 -0
- package/dist/gcalSync.js +119 -0
- package/dist/ghlEventInquiry.d.ts +16 -0
- package/dist/ghlEventInquiry.js +116 -0
- package/dist/ghlNote.d.ts +5 -0
- package/dist/ghlNote.js +29 -0
- package/dist/ghlTask.d.ts +7 -0
- package/dist/ghlTask.js +39 -0
- package/dist/ghlVoiceInquiry.d.ts +26 -0
- package/dist/ghlVoiceInquiry.js +68 -0
- package/dist/guestPrintCapture.d.ts +217 -0
- package/dist/guestPrintCapture.js +362 -0
- package/dist/index.d.ts +3 -0
- package/{index.js → dist/index.js} +3 -2
- package/dist/lumaGhl.d.ts +19 -0
- package/dist/lumaGhl.js +147 -0
- package/dist/mailArrivalEmail.d.ts +15 -0
- package/dist/mailArrivalEmail.js +99 -0
- package/dist/manageToken.d.ts +64 -0
- package/dist/manageToken.js +261 -0
- package/dist/membership.d.ts +20 -0
- package/dist/membership.js +87 -0
- package/dist/membershipBusClient.d.ts +139 -0
- package/dist/membershipBusClient.js +443 -0
- package/dist/membershipWelcome.d.ts +117 -0
- package/dist/membershipWelcome.js +497 -0
- package/dist/migrationCheckout.d.ts +169 -0
- package/dist/migrationCheckout.js +250 -0
- package/dist/money.d.ts +20 -0
- package/dist/money.js +35 -0
- package/dist/ops.d.ts +27 -0
- package/dist/ops.js +87 -0
- package/dist/pacificDate.d.ts +8 -0
- package/{src/pacificDate.ts → dist/pacificDate.js} +76 -88
- package/dist/paymentLinkEmail.d.ts +15 -0
- package/dist/paymentLinkEmail.js +102 -0
- package/dist/policyAcknowledgment.d.ts +46 -0
- package/dist/policyAcknowledgment.js +58 -0
- package/dist/portalSession.d.ts +15 -0
- package/dist/portalSession.js +31 -0
- package/dist/pricing.d.ts +306 -0
- package/dist/pricing.js +788 -0
- package/dist/printBilling.d.ts +340 -0
- package/dist/printBilling.js +619 -0
- package/dist/printBillingAdapters.d.ts +29 -0
- package/dist/printBillingAdapters.js +130 -0
- package/dist/printCorrections.d.ts +175 -0
- package/dist/printCorrections.js +328 -0
- package/dist/rateLimit.d.ts +20 -0
- package/dist/rateLimit.js +70 -0
- package/dist/referralCredits.d.ts +5 -0
- package/{src/referralCredits.ts → dist/referralCredits.js} +27 -34
- package/dist/referralGrant.d.ts +49 -0
- package/dist/referralGrant.js +268 -0
- package/dist/rescheduleCredit.d.ts +98 -0
- package/dist/rescheduleCredit.js +263 -0
- package/dist/reservationWifiCode.d.ts +19 -0
- package/{src/reservationWifiCode.ts → dist/reservationWifiCode.js} +67 -81
- package/dist/retellCallAnalyzed.d.ts +18 -0
- package/dist/retellCallAnalyzed.js +91 -0
- package/dist/retellSignature.d.ts +14 -0
- package/dist/retellSignature.js +60 -0
- package/dist/signedUnpaidReminderEmail.d.ts +15 -0
- package/dist/signedUnpaidReminderEmail.js +111 -0
- package/dist/slackAlert.d.ts +13 -0
- package/dist/slackAlert.js +37 -0
- package/dist/stripeCoworkingPortal.d.ts +21 -0
- package/dist/stripeCoworkingPortal.js +80 -0
- package/dist/supabaseTestFakes.d.ts +67 -0
- package/dist/supabaseTestFakes.js +79 -0
- package/dist/supportTicketEmail.d.ts +16 -0
- package/dist/supportTicketEmail.js +98 -0
- package/dist/tier1Agreement.d.ts +51 -0
- package/dist/tier1Agreement.js +86 -0
- package/dist/unifiAccessPolicies.d.ts +36 -0
- package/dist/unifiAccessPolicies.js +185 -0
- package/dist/unifiGroups.d.ts +26 -0
- package/dist/unifiGroups.js +106 -0
- package/package.json +653 -169
- package/src/adminBookingCredit.test.ts +0 -451
- package/src/adminBookingCredit.ts +0 -239
- package/src/agreementCheckout.ts +0 -250
- package/src/agreementPortalEmail.ts +0 -128
- package/src/availability.test.ts +0 -25
- package/src/availability.ts +0 -201
- package/src/billingPortalLinkEmail.ts +0 -117
- package/src/bookingAgreementEmail.ts +0 -149
- package/src/bookingEffects.ts +0 -388
- package/src/bookingHoldReclaim.ts +0 -94
- package/src/busClient.ts +0 -268
- package/src/checkoutCoupon.test.ts +0 -675
- package/src/checkoutCoupon.ts +0 -455
- package/src/checkoutSessionParams.ts +0 -56
- package/src/commonsContract.ts +0 -175
- package/src/commonsDeposit.ts +0 -298
- package/src/commonsDepositWebhook.ts +0 -237
- package/src/conductorAdmin.ts +0 -141
- package/src/dayPassConfirmation.ts +0 -230
- package/src/dunningEmails.test.ts +0 -263
- package/src/dunningEmails.ts +0 -203
- package/src/email-templates/brand.ts +0 -93
- package/src/email-templates/email-change.tsx +0 -92
- package/src/email-templates/invite.tsx +0 -79
- package/src/email-templates/magic-link.tsx +0 -59
- package/src/email-templates/reauthentication.tsx +0 -60
- package/src/email-templates/recovery.tsx +0 -59
- package/src/email-templates/signup.tsx +0 -67
- package/src/functions/admin-cancel-membership.ts +0 -311
- package/src/functions/admin-change-membership-plan.ts +0 -312
- package/src/functions/admin-charge-guest-print.ts +0 -229
- package/src/functions/admin-correct-booking.ts +0 -333
- package/src/functions/admin-create-booking.ts +0 -460
- package/src/functions/admin-create-commons-event.ts +0 -244
- package/src/functions/admin-debug-boldsign-doc.ts +0 -93
- package/src/functions/admin-door-write.ts +0 -272
- package/src/functions/admin-issue-day-pass.ts +0 -231
- package/src/functions/admin-mark-booking-paid.ts +0 -203
- package/src/functions/admin-mint-billing-portal-link.ts +0 -168
- package/src/functions/admin-mint-portal-link.ts +0 -62
- package/src/functions/admin-photo-upload.ts +0 -128
- package/src/functions/admin-remove-team-member.ts +0 -150
- package/src/functions/admin-request-trial.ts +0 -366
- package/src/functions/admin-resend-commons-deposit-link.ts +0 -323
- package/src/functions/admin-reset-mfa.ts +0 -138
- package/src/functions/admin-retry-invoice-payment.test.ts +0 -567
- package/src/functions/admin-retry-invoice-payment.ts +0 -333
- package/src/functions/admin-reverse-coupon-redemption.ts +0 -98
- package/src/functions/admin-revoke-agreement.ts +0 -467
- package/src/functions/admin-send-commons-agreement.ts +0 -214
- package/src/functions/admin-set-credit-amount.ts +0 -123
- package/src/functions/admin-skip-commons-contract.ts +0 -165
- package/src/functions/admin-undo-membership-cancel.ts +0 -144
- package/src/functions/admin-wall-photo-write.ts +0 -141
- package/src/functions/auth-email-hook.ts +0 -259
- package/src/functions/boldsign-sender-identity.ts +0 -114
- package/src/functions/booking-availability.ts +0 -419
- package/src/functions/booking-member-preview.ts +0 -136
- package/src/functions/booking-status.ts +0 -149
- package/src/functions/conductor.ts +0 -505
- package/src/functions/create-agreement.ts +0 -537
- package/src/functions/create-booking.ts +0 -648
- package/src/functions/create-day-pass-checkout.ts +0 -218
- package/src/functions/create-portal-session.ts +0 -142
- package/src/functions/create-subscription-checkout.test.ts +0 -222
- package/src/functions/create-subscription-checkout.ts +0 -440
- package/src/functions/day-pass-status.ts +0 -89
- package/src/functions/dayStatus.ts +0 -71
- package/src/functions/diag-webpush-test.ts +0 -45
- package/src/functions/event-access-admin.ts +0 -277
- package/src/functions/event-access-store.ts +0 -334
- package/src/functions/ezeep-print-webhook.ts +0 -213
- package/src/functions/ezeep-usage-reconcile.ts +0 -299
- package/src/functions/fetch-avatar-original.ts +0 -457
- package/src/functions/get-provider-sign-link.ts +0 -155
- package/src/functions/get-signing-link.ts +0 -211
- package/src/functions/guest-print-setup-confirm.ts +0 -128
- package/src/functions/guest-print-submit.ts +0 -149
- package/src/functions/luma-webhook.ts +0 -165
- package/src/functions/manage-booking.ts +0 -472
- package/src/functions/mcp.ts +0 -67
- package/src/functions/member-door-action.test.ts +0 -1248
- package/src/functions/member-door-action.ts +0 -863
- package/src/functions/member-unifi-mapping.test.ts +0 -516
- package/src/functions/member-unifi-mapping.ts +0 -206
- package/src/functions/membership-door-sync.ts +0 -956
- package/src/functions/migration-collision-alert.copy.ts +0 -232
- package/src/functions/migration-collision-alert.test.ts +0 -349
- package/src/functions/migration-collision-alert.ts +0 -232
- package/src/functions/office-assignment-end.ts +0 -146
- package/src/functions/portal-booking-access.ts +0 -217
- package/src/functions/portal-list-invoices.ts +0 -99
- package/src/functions/portal-request-login.ts +0 -219
- package/src/functions/portal-resend-invite.ts +0 -248
- package/src/functions/portal-submit-event.ts +0 -168
- package/src/functions/print-billing-recover.ts +0 -97
- package/src/functions/print-billing-run.ts +0 -183
- package/src/functions/public-facts.ts +0 -168
- package/src/functions/push-send.ts +0 -348
- package/src/functions/push-test.ts +0 -234
- package/src/functions/request-portal-link.ts +0 -211
- package/src/functions/reschedule-booking.ts +0 -649
- package/src/functions/review-ratings.ts +0 -113
- package/src/functions/space-availability-range.acceptance.test.ts +0 -161
- package/src/functions/space-availability-range.ts +0 -142
- package/src/functions/stripe-db-reconcile.ts +0 -319
- package/src/functions/stripe-webhook.moved-regression.test.ts +0 -78
- package/src/functions/stripe-webhook.ts +0 -2595
- package/src/functions/sync-gcal-blackouts.ts +0 -298
- package/src/functions/timetable-event-register.ts +0 -162
- package/src/functions/timetable-event-status.ts +0 -90
- package/src/functions/timetable-spaces.ts +0 -219
- package/src/functions/touch-pass-reconciler.ts +0 -689
- package/src/functions/touch-pass-signup.ts +0 -478
- package/src/functions/upload-booking-display-image.ts +0 -179
- package/src/functions/virtual-onboarding-purge.ts +0 -134
- package/src/functions/virtual-onboarding-submit.ts +0 -315
- package/src/functions/voice-booking.ts +0 -453
- package/src/functions/voice-day-pass.ts +0 -346
- package/src/functions/voice-inquiry.test.ts +0 -301
- package/src/functions/voice-inquiry.ts +0 -198
- package/src/functions/voice-membership-signup.ts +0 -355
- package/src/functions/voice-tour-availability.ts +0 -204
- package/src/functions/voice-tour-booking.ts +0 -429
- package/src/gcalSync.ts +0 -142
- package/src/ghlEventInquiry.ts +0 -143
- package/src/ghlNote.ts +0 -34
- package/src/ghlTask.ts +0 -48
- package/src/ghlVoiceInquiry.ts +0 -90
- package/src/guestPrintCapture.test.ts +0 -722
- package/src/guestPrintCapture.ts +0 -538
- package/src/lumaGhl.ts +0 -195
- package/src/mailArrivalEmail.ts +0 -121
- package/src/manageToken.ts +0 -363
- package/src/membership.ts +0 -109
- package/src/membershipBusClient.ts +0 -537
- package/src/membershipWelcome.ts +0 -683
- package/src/migrationCheckout.ts +0 -366
- package/src/money.ts +0 -36
- package/src/ops.ts +0 -97
- package/src/paymentLinkEmail.ts +0 -123
- package/src/policyAcknowledgment.test.ts +0 -50
- package/src/policyAcknowledgment.ts +0 -96
- package/src/portalSession.ts +0 -46
- package/src/pricing.test.ts +0 -660
- package/src/pricing.ts +0 -1025
- package/src/printBilling.test.ts +0 -750
- package/src/printBilling.ts +0 -891
- package/src/printBillingAdapters.ts +0 -169
- package/src/printCorrections.test.ts +0 -348
- package/src/printCorrections.ts +0 -496
- package/src/rateLimit.ts +0 -82
- package/src/referralCredits.test.ts +0 -31
- package/src/referralGrant.ts +0 -321
- package/src/rescheduleCredit.test.ts +0 -521
- package/src/rescheduleCredit.ts +0 -337
- package/src/reservationWifiCode.test.ts +0 -69
- package/src/retellCallAnalyzed.test.ts +0 -167
- package/src/retellCallAnalyzed.ts +0 -113
- package/src/retellSignature.test.ts +0 -137
- package/src/retellSignature.ts +0 -82
- package/src/signedUnpaidReminderEmail.test.ts +0 -246
- package/src/signedUnpaidReminderEmail.ts +0 -132
- package/src/slackAlert.ts +0 -38
- package/src/stripeCoworkingPortal.ts +0 -91
- package/src/supabaseTestFakes.ts +0 -131
- package/src/supportTicketEmail.ts +0 -119
- package/src/tier1Agreement.ts +0 -125
- package/src/unifiAccessPolicies.ts +0 -228
- package/src/unifiGroups.ts +0 -129
|
@@ -1,1248 +0,0 @@
|
|
|
1
|
-
// Unit tests for the member-door-action edge function.
|
|
2
|
-
//
|
|
3
|
-
// Run with:
|
|
4
|
-
// deno test --node-modules-dir=auto --allow-env --allow-net --allow-read \
|
|
5
|
-
// src/functions/member-door-action.test.ts
|
|
6
|
-
//
|
|
7
|
-
// `--node-modules-dir=auto` matters, and this line exists because it was
|
|
8
|
-
// documented wrong once: with `=none` the npm:@supabase/supabase-js graph fails
|
|
9
|
-
// to resolve `tslib` on a clean checkout, so the suite never runs. `=none` is
|
|
10
|
-
// still correct for `deno check`, which does not need the runtime graph.
|
|
11
|
-
//
|
|
12
|
-
// NO REAL NETWORK. Every outbound call — Supabase Auth, PostgREST, and
|
|
13
|
-
// ftw-middleware — is answered by an in-memory `globalThis.fetch` stub keyed off
|
|
14
|
-
// the request URL (same stub style as voice-inquiry/index.test.ts and
|
|
15
|
-
// voice-tour-booking/index.test.ts). The middleware base URL used throughout is
|
|
16
|
-
// `https://middleware.test.invalid`, on the reserved .invalid TLD, so a stub
|
|
17
|
-
// miss can never resolve to a real host.
|
|
18
|
-
//
|
|
19
|
-
// The Ed25519 keypair is generated fresh per test run, so the assertion
|
|
20
|
-
// signature is verified against a key this file owns — no key material and no
|
|
21
|
-
// live ftw-middleware are involved.
|
|
22
|
-
import {
|
|
23
|
-
assert, assertEquals, assertFalse, assertStringIncludes,
|
|
24
|
-
} from 'https://deno.land/std@0.224.0/assert/mod.ts';
|
|
25
|
-
import {
|
|
26
|
-
handleMemberDoorAction,
|
|
27
|
-
canonicalMemberActionMessage,
|
|
28
|
-
ASSERTION_HEADER,
|
|
29
|
-
SIGNATURE_HEADER,
|
|
30
|
-
TIMESTAMP_HEADER,
|
|
31
|
-
SCHEME_HEADER,
|
|
32
|
-
HMAC_SCHEME,
|
|
33
|
-
ASSERTION_MAX_TTL_SECONDS,
|
|
34
|
-
MEMBER_ACTIONS,
|
|
35
|
-
IGNORED_BODY_FIELDS,
|
|
36
|
-
parseEnabled,
|
|
37
|
-
parseAllowlist,
|
|
38
|
-
assertionTtlSeconds,
|
|
39
|
-
keyIsolationViolations,
|
|
40
|
-
type MemberAction,
|
|
41
|
-
} from './member-door-action.ts';
|
|
42
|
-
|
|
43
|
-
const MEMBER_UID = '11111111-1111-4111-8111-111111111111';
|
|
44
|
-
const MEMBERSHIP_ID = '22222222-2222-4222-8222-222222222222';
|
|
45
|
-
const GC_DOOR_ID = '33333333-3333-4333-8333-333333333333';
|
|
46
|
-
const UNIFI_DOOR_ID = '371d6bc0-82df-4609-a7b4-21aceef4f775';
|
|
47
|
-
const UNIFI_USER_ID = 'unifi-user-abc';
|
|
48
|
-
const MIDDLEWARE_BASE = 'https://middleware.test.invalid';
|
|
49
|
-
const GOOD_TOKEN = 'member-session-jwt';
|
|
50
|
-
|
|
51
|
-
// ---------------------------------------------------------------------------
|
|
52
|
-
// Ed25519 keypair for verifying the minted assertion
|
|
53
|
-
// ---------------------------------------------------------------------------
|
|
54
|
-
const keyPair = await crypto.subtle.generateKey(
|
|
55
|
-
{ name: 'Ed25519' }, true, ['sign', 'verify'],
|
|
56
|
-
) as CryptoKeyPair;
|
|
57
|
-
const PKCS8_B64 = btoa(
|
|
58
|
-
String.fromCharCode(...new Uint8Array(await crypto.subtle.exportKey('pkcs8', keyPair.privateKey))),
|
|
59
|
-
);
|
|
60
|
-
|
|
61
|
-
function b64urlDecode(s: string): Uint8Array<ArrayBuffer> {
|
|
62
|
-
const b64 = s.replace(/-/g, '+').replace(/_/g, '/') + '='.repeat((4 - (s.length % 4)) % 4);
|
|
63
|
-
const bin = atob(b64);
|
|
64
|
-
const out = new Uint8Array(new ArrayBuffer(bin.length));
|
|
65
|
-
for (let i = 0; i < bin.length; i++) out[i] = bin.charCodeAt(i);
|
|
66
|
-
return out;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
function b64urlDecodeJson(s: string): Record<string, unknown> {
|
|
70
|
-
return JSON.parse(new TextDecoder().decode(b64urlDecode(s)));
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
async function verifyAssertion(jwt: string): Promise<{
|
|
74
|
-
header: Record<string, unknown>;
|
|
75
|
-
claims: Record<string, unknown>;
|
|
76
|
-
signatureValid: boolean;
|
|
77
|
-
}> {
|
|
78
|
-
const [h, p, s] = jwt.split('.');
|
|
79
|
-
const signatureValid = await crypto.subtle.verify(
|
|
80
|
-
{ name: 'Ed25519' },
|
|
81
|
-
keyPair.publicKey,
|
|
82
|
-
b64urlDecode(s),
|
|
83
|
-
new TextEncoder().encode(`${h}.${p}`),
|
|
84
|
-
);
|
|
85
|
-
return { header: b64urlDecodeJson(h), claims: b64urlDecodeJson(p), signatureValid };
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
async function hmacD1(secret: string, msg: string): Promise<string> {
|
|
89
|
-
const key = await crypto.subtle.importKey(
|
|
90
|
-
'raw', new TextEncoder().encode(secret), { name: 'HMAC', hash: 'SHA-256' }, false, ['sign'],
|
|
91
|
-
);
|
|
92
|
-
const sig = new Uint8Array(await crypto.subtle.sign('HMAC', key, new TextEncoder().encode(msg)));
|
|
93
|
-
let str = '';
|
|
94
|
-
for (const b of sig) str += String.fromCharCode(b);
|
|
95
|
-
return btoa(str).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
async function sha256Hex(text: string): Promise<string> {
|
|
99
|
-
const d = new Uint8Array(await crypto.subtle.digest('SHA-256', new TextEncoder().encode(text)));
|
|
100
|
-
let out = '';
|
|
101
|
-
for (const b of d) out += b.toString(16).padStart(2, '0');
|
|
102
|
-
return out;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
// ---------------------------------------------------------------------------
|
|
106
|
-
// Env harness
|
|
107
|
-
// ---------------------------------------------------------------------------
|
|
108
|
-
const ENV_DEFAULTS: Record<string, string> = {
|
|
109
|
-
SUPABASE_URL: 'https://example.supabase.co',
|
|
110
|
-
SUPABASE_SERVICE_ROLE_KEY: 'test-service-role-key',
|
|
111
|
-
FTW_MIDDLEWARE_BASE_URL: MIDDLEWARE_BASE,
|
|
112
|
-
MEMBER_ACTIONS_HMAC_SECRET: 'test-d1-secret',
|
|
113
|
-
MEMBER_ASSERTION_SIGNING_KEY: PKCS8_B64,
|
|
114
|
-
MEMBER_ASSERTION_ISS: 'gc-io',
|
|
115
|
-
MEMBER_ASSERTION_AUD: 'ftw-middleware:granite-city',
|
|
116
|
-
MEMBER_ACTIONS_ENABLED: 'true',
|
|
117
|
-
MEMBER_ACTIONS_ALLOWLIST: MEMBER_UID,
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
// Cleared for every test so a value leaking in from the developer's real shell
|
|
121
|
-
// cannot make the key-isolation check pass or fail by accident.
|
|
122
|
-
const ENV_CLEARED: Record<string, string | undefined> = {
|
|
123
|
-
BUS_HMAC_SECRET: undefined,
|
|
124
|
-
BUS_HMAC_SECRET_MEMBERSHIP: undefined,
|
|
125
|
-
BUS_HMAC_SECRET_RESEND: undefined,
|
|
126
|
-
MEMBER_ACTIONS_MAPPING_SECRET: undefined,
|
|
127
|
-
MEMBER_ASSERTION_TTL_SECONDS: undefined,
|
|
128
|
-
OPS_ALERT_WEBHOOK_URL: undefined,
|
|
129
|
-
SLACK_BOT_TOKEN: undefined,
|
|
130
|
-
OPS_ALERT_SLACK_CHANNEL_ID: undefined,
|
|
131
|
-
};
|
|
132
|
-
|
|
133
|
-
function withEnvs(vars: Record<string, string | undefined>, fn: () => Promise<void>): Promise<void> {
|
|
134
|
-
const all = { ...ENV_DEFAULTS, ...ENV_CLEARED, ...vars };
|
|
135
|
-
const prev = new Map<string, string | undefined>();
|
|
136
|
-
for (const [k, v] of Object.entries(all)) {
|
|
137
|
-
prev.set(k, Deno.env.get(k));
|
|
138
|
-
if (v === undefined) Deno.env.delete(k);
|
|
139
|
-
else Deno.env.set(k, v);
|
|
140
|
-
}
|
|
141
|
-
return (async () => {
|
|
142
|
-
try {
|
|
143
|
-
await fn();
|
|
144
|
-
} finally {
|
|
145
|
-
for (const [k, v] of prev) {
|
|
146
|
-
if (v === undefined) Deno.env.delete(k);
|
|
147
|
-
else Deno.env.set(k, v);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
})();
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
// ---------------------------------------------------------------------------
|
|
154
|
-
// Fetch stub
|
|
155
|
-
// ---------------------------------------------------------------------------
|
|
156
|
-
interface MiddlewareCall {
|
|
157
|
-
url: string;
|
|
158
|
-
method: string;
|
|
159
|
-
headers: Record<string, string>;
|
|
160
|
-
body: string;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
interface StubOpts {
|
|
164
|
-
/** GoTrue /auth/v1/user answer. 'ok' | 'reject' */
|
|
165
|
-
auth?: 'ok' | 'reject';
|
|
166
|
-
membershipRows?: unknown[] | 'error';
|
|
167
|
-
door?: Record<string, unknown> | null;
|
|
168
|
-
rateLimitAllows?: boolean;
|
|
169
|
-
/** Middleware behaviour. */
|
|
170
|
-
middleware?:
|
|
171
|
-
| { kind: 'json'; status: number; body: unknown }
|
|
172
|
-
| { kind: 'raw'; status: number; text: string }
|
|
173
|
-
| { kind: 'timeout' };
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
interface Stub {
|
|
177
|
-
middlewareCalls: MiddlewareCall[];
|
|
178
|
-
opsEventInserts: unknown[];
|
|
179
|
-
otherUrls: string[];
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
function withFetchStub(opts: StubOpts, fn: (stub: Stub) => Promise<void>): Promise<void> {
|
|
183
|
-
const stub: Stub = { middlewareCalls: [], opsEventInserts: [], otherUrls: [] };
|
|
184
|
-
const original = globalThis.fetch;
|
|
185
|
-
globalThis.fetch = ((input: string | URL | Request, init?: RequestInit) => {
|
|
186
|
-
const url = typeof input === 'string'
|
|
187
|
-
? input
|
|
188
|
-
: input instanceof URL ? input.toString() : input.url;
|
|
189
|
-
|
|
190
|
-
if (url.startsWith(MIDDLEWARE_BASE)) {
|
|
191
|
-
const headers: Record<string, string> = {};
|
|
192
|
-
for (const [k, v] of Object.entries((init?.headers ?? {}) as Record<string, string>)) {
|
|
193
|
-
headers[k] = v;
|
|
194
|
-
}
|
|
195
|
-
stub.middlewareCalls.push({
|
|
196
|
-
url,
|
|
197
|
-
method: init?.method ?? 'GET',
|
|
198
|
-
headers,
|
|
199
|
-
body: typeof init?.body === 'string' ? init.body : '',
|
|
200
|
-
});
|
|
201
|
-
const mw = opts.middleware ?? { kind: 'json', status: 200, body: { ok: true } };
|
|
202
|
-
if (mw.kind === 'timeout') {
|
|
203
|
-
return Promise.reject(new DOMException('Signal timed out.', 'TimeoutError'));
|
|
204
|
-
}
|
|
205
|
-
if (mw.kind === 'raw') {
|
|
206
|
-
return Promise.resolve(new Response(mw.text, { status: mw.status }));
|
|
207
|
-
}
|
|
208
|
-
return Promise.resolve(new Response(JSON.stringify(mw.body), {
|
|
209
|
-
status: mw.status, headers: { 'Content-Type': 'application/json' },
|
|
210
|
-
}));
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
if (url.includes('/auth/v1/user')) {
|
|
214
|
-
const auth = (init?.headers ?? {}) as Record<string, string>;
|
|
215
|
-
const bearer = Object.entries(auth)
|
|
216
|
-
.find(([k]) => k.toLowerCase() === 'authorization')?.[1] ?? '';
|
|
217
|
-
if (opts.auth === 'reject' || !bearer.includes(GOOD_TOKEN)) {
|
|
218
|
-
return Promise.resolve(new Response(
|
|
219
|
-
JSON.stringify({ code: 401, msg: 'invalid claim: missing sub claim' }),
|
|
220
|
-
{ status: 401, headers: { 'Content-Type': 'application/json' } },
|
|
221
|
-
));
|
|
222
|
-
}
|
|
223
|
-
return Promise.resolve(new Response(
|
|
224
|
-
JSON.stringify({ id: MEMBER_UID, aud: 'authenticated', email: 'member@example.com' }),
|
|
225
|
-
{ status: 200, headers: { 'Content-Type': 'application/json' } },
|
|
226
|
-
));
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
if (url.includes('/rest/v1/rpc/check_rate_limit')) {
|
|
230
|
-
return Promise.resolve(new Response(
|
|
231
|
-
JSON.stringify(opts.rateLimitAllows ?? true),
|
|
232
|
-
{ status: 200, headers: { 'Content-Type': 'application/json' } },
|
|
233
|
-
));
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
if (url.includes('/rest/v1/memberships')) {
|
|
237
|
-
if (opts.membershipRows === 'error') {
|
|
238
|
-
return Promise.resolve(new Response(
|
|
239
|
-
JSON.stringify({ message: 'boom', code: '42501' }),
|
|
240
|
-
{ status: 400, headers: { 'Content-Type': 'application/json' } },
|
|
241
|
-
));
|
|
242
|
-
}
|
|
243
|
-
const rows = opts.membershipRows ?? [{
|
|
244
|
-
id: MEMBERSHIP_ID,
|
|
245
|
-
status: 'active',
|
|
246
|
-
pricing_grace_ends_at: null,
|
|
247
|
-
door_managed: true,
|
|
248
|
-
door_access_not_before: null,
|
|
249
|
-
unifi_access_user_id: UNIFI_USER_ID,
|
|
250
|
-
}];
|
|
251
|
-
return Promise.resolve(new Response(JSON.stringify(rows), {
|
|
252
|
-
status: 200, headers: { 'Content-Type': 'application/json' },
|
|
253
|
-
}));
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
if (url.includes('/rest/v1/doors')) {
|
|
257
|
-
const door = 'door' in opts
|
|
258
|
-
? opts.door
|
|
259
|
-
: { id: GC_DOOR_ID, name: 'Commons-Main', unifi_door_id: UNIFI_DOOR_ID, status: 'live' };
|
|
260
|
-
return Promise.resolve(new Response(JSON.stringify(door), {
|
|
261
|
-
status: 200, headers: { 'Content-Type': 'application/json' },
|
|
262
|
-
}));
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
if (url.includes('/rest/v1/ops_events')) {
|
|
266
|
-
if (typeof init?.body === 'string') stub.opsEventInserts.push(JSON.parse(init.body));
|
|
267
|
-
return Promise.resolve(new Response('[]', { status: 201 }));
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
stub.otherUrls.push(url);
|
|
271
|
-
return Promise.resolve(new Response('{}', { status: 200 }));
|
|
272
|
-
}) as typeof fetch;
|
|
273
|
-
|
|
274
|
-
return (async () => {
|
|
275
|
-
try {
|
|
276
|
-
await fn(stub);
|
|
277
|
-
} finally {
|
|
278
|
-
globalThis.fetch = original;
|
|
279
|
-
}
|
|
280
|
-
})();
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
function makeRequest(
|
|
284
|
-
body: unknown,
|
|
285
|
-
opts: { token?: string | null; method?: string } = {},
|
|
286
|
-
): Request {
|
|
287
|
-
const headers: Record<string, string> = {
|
|
288
|
-
'Content-Type': 'application/json',
|
|
289
|
-
'x-forwarded-for': '203.0.113.7',
|
|
290
|
-
};
|
|
291
|
-
const token = opts.token === undefined ? GOOD_TOKEN : opts.token;
|
|
292
|
-
if (token !== null) headers['Authorization'] = `Bearer ${token}`;
|
|
293
|
-
const method = opts.method ?? 'POST';
|
|
294
|
-
const bodyless = method === 'OPTIONS' || method === 'GET' || method === 'HEAD';
|
|
295
|
-
return new Request('https://example.com/member-door-action', {
|
|
296
|
-
method,
|
|
297
|
-
headers,
|
|
298
|
-
...(bodyless ? {} : { body: JSON.stringify(body) }),
|
|
299
|
-
});
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
const MIDDLEWARE_OK: Record<MemberAction, unknown> = {
|
|
303
|
-
unlock: { ok: true, outcome: 'unlocked', door_name: 'Commons-Main', confirmed_at: '2026-09-02T18:00:00Z' },
|
|
304
|
-
pin_regenerate: { ok: true, pin: '4821', pin_length: 4, issued_at: '2026-09-02T18:00:00Z' },
|
|
305
|
-
activity: {
|
|
306
|
-
ok: true,
|
|
307
|
-
hits: [
|
|
308
|
-
{ at: '2026-09-01T17:02:21-07:00', door_id: UNIFI_DOOR_ID, door_name: 'Commons-Main', result: 'ACCESS', method: 'remote', actor_id: UNIFI_USER_ID },
|
|
309
|
-
],
|
|
310
|
-
},
|
|
311
|
-
wifi_voucher: { ok: true, code: '9090950795', expires_at: '2026-09-03T02:00:00Z', time_limit_minutes: 480, authorized_guest_limit: 1 },
|
|
312
|
-
};
|
|
313
|
-
|
|
314
|
-
function requestFor(action: MemberAction, extra: Record<string, unknown> = {}) {
|
|
315
|
-
return makeRequest({
|
|
316
|
-
action,
|
|
317
|
-
...(action === 'unlock' ? { door_id: GC_DOOR_ID } : {}),
|
|
318
|
-
...extra,
|
|
319
|
-
});
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
// ===========================================================================
|
|
323
|
-
// 1. Happy path, all four actions, against a MOCKED ftw-middleware
|
|
324
|
-
// ===========================================================================
|
|
325
|
-
|
|
326
|
-
Deno.test('unlock: success calls POST /member/unlock and reports the confirmed outcome', async () => {
|
|
327
|
-
await withEnvs({}, async () => {
|
|
328
|
-
await withFetchStub(
|
|
329
|
-
{ middleware: { kind: 'json', status: 200, body: MIDDLEWARE_OK.unlock } },
|
|
330
|
-
async (stub) => {
|
|
331
|
-
const res = await handleMemberDoorAction(requestFor('unlock'));
|
|
332
|
-
assertEquals(res.status, 200);
|
|
333
|
-
assertEquals(await res.json(), {
|
|
334
|
-
ok: true, outcome: 'unlocked', door_name: 'Commons-Main', confirmed_at: '2026-09-02T18:00:00Z',
|
|
335
|
-
});
|
|
336
|
-
assertEquals(stub.middlewareCalls.length, 1);
|
|
337
|
-
assertEquals(stub.middlewareCalls[0].url, `${MIDDLEWARE_BASE}/member/unlock`);
|
|
338
|
-
assertEquals(stub.middlewareCalls[0].method, 'POST');
|
|
339
|
-
},
|
|
340
|
-
);
|
|
341
|
-
});
|
|
342
|
-
});
|
|
343
|
-
|
|
344
|
-
Deno.test('pin_regenerate: success calls POST /member/pin/regenerate and returns the PIN once', async () => {
|
|
345
|
-
await withEnvs({}, async () => {
|
|
346
|
-
await withFetchStub(
|
|
347
|
-
{ middleware: { kind: 'json', status: 200, body: MIDDLEWARE_OK.pin_regenerate } },
|
|
348
|
-
async (stub) => {
|
|
349
|
-
const res = await handleMemberDoorAction(requestFor('pin_regenerate'));
|
|
350
|
-
assertEquals(res.status, 200);
|
|
351
|
-
assertEquals(await res.json(), {
|
|
352
|
-
ok: true, pin: '4821', pin_length: 4, issued_at: '2026-09-02T18:00:00Z',
|
|
353
|
-
});
|
|
354
|
-
assertEquals(stub.middlewareCalls[0].url, `${MIDDLEWARE_BASE}/member/pin/regenerate`);
|
|
355
|
-
// The PIN must never appear in any audit / ops_events payload.
|
|
356
|
-
assertFalse(JSON.stringify(stub.opsEventInserts).includes('4821'));
|
|
357
|
-
},
|
|
358
|
-
);
|
|
359
|
-
});
|
|
360
|
-
});
|
|
361
|
-
|
|
362
|
-
Deno.test('pin_regenerate: a clean group_check keeps the ordinary success audit', async () => {
|
|
363
|
-
await withEnvs({}, async () => {
|
|
364
|
-
await withFetchStub({
|
|
365
|
-
middleware: {
|
|
366
|
-
kind: 'json',
|
|
367
|
-
status: 200,
|
|
368
|
-
body: { ...MIDDLEWARE_OK.pin_regenerate as Record<string, unknown>, group_check: 'ok' },
|
|
369
|
-
},
|
|
370
|
-
}, async (stub) => {
|
|
371
|
-
const res = await handleMemberDoorAction(requestFor('pin_regenerate'));
|
|
372
|
-
assertEquals(res.status, 200);
|
|
373
|
-
assertEquals((await res.json()).group_check, 'ok');
|
|
374
|
-
const audit = stub.opsEventInserts.find(
|
|
375
|
-
(e) => (e as { kind?: string }).kind === 'member_door_action',
|
|
376
|
-
) as { severity?: string; detail?: Record<string, unknown> } | undefined;
|
|
377
|
-
assert(audit, 'no audit row was written');
|
|
378
|
-
assertEquals(audit.severity, 'info');
|
|
379
|
-
assertEquals(audit.detail?.outcome, 'ok');
|
|
380
|
-
assertFalse(
|
|
381
|
-
JSON.stringify(stub.opsEventInserts).includes('group_check_mismatch'),
|
|
382
|
-
'a clean group_check must not raise the mismatch alert',
|
|
383
|
-
);
|
|
384
|
-
});
|
|
385
|
-
});
|
|
386
|
-
});
|
|
387
|
-
|
|
388
|
-
Deno.test('pin_regenerate: an ABSENT group_check keeps the ordinary success audit', async () => {
|
|
389
|
-
await withEnvs({}, async () => {
|
|
390
|
-
await withFetchStub(
|
|
391
|
-
{ middleware: { kind: 'json', status: 200, body: MIDDLEWARE_OK.pin_regenerate } },
|
|
392
|
-
async (stub) => {
|
|
393
|
-
const res = await handleMemberDoorAction(requestFor('pin_regenerate'));
|
|
394
|
-
assertEquals(res.status, 200);
|
|
395
|
-
const audit = stub.opsEventInserts.find(
|
|
396
|
-
(e) => (e as { kind?: string }).kind === 'member_door_action',
|
|
397
|
-
) as { severity?: string } | undefined;
|
|
398
|
-
assertEquals(audit?.severity, 'info');
|
|
399
|
-
assertFalse(JSON.stringify(stub.opsEventInserts).includes('group_check_mismatch'));
|
|
400
|
-
},
|
|
401
|
-
);
|
|
402
|
-
});
|
|
403
|
-
});
|
|
404
|
-
|
|
405
|
-
Deno.test('pin_regenerate: group_check "mismatch" survives projection and escalates the audit', async () => {
|
|
406
|
-
await withEnvs({}, async () => {
|
|
407
|
-
await withFetchStub({
|
|
408
|
-
middleware: {
|
|
409
|
-
kind: 'json',
|
|
410
|
-
status: 200,
|
|
411
|
-
body: { ...MIDDLEWARE_OK.pin_regenerate as Record<string, unknown>, group_check: 'mismatch' },
|
|
412
|
-
},
|
|
413
|
-
}, async (stub) => {
|
|
414
|
-
const res = await handleMemberDoorAction(requestFor('pin_regenerate'));
|
|
415
|
-
// The PIN was really written, so the member still gets it.
|
|
416
|
-
assertEquals(res.status, 200);
|
|
417
|
-
const body = await res.json();
|
|
418
|
-
assertEquals(body.pin, '4821');
|
|
419
|
-
assertEquals(body.group_check, 'mismatch');
|
|
420
|
-
|
|
421
|
-
const audit = stub.opsEventInserts.find(
|
|
422
|
-
(e) => (e as { kind?: string }).kind === 'member_door_action',
|
|
423
|
-
) as { severity?: string; detail?: Record<string, unknown> } | undefined;
|
|
424
|
-
assert(audit, 'no audit row was written');
|
|
425
|
-
assertEquals(audit.severity, 'error');
|
|
426
|
-
assertEquals(audit.detail?.group_check, 'mismatch');
|
|
427
|
-
|
|
428
|
-
// And it pages: a bare ops_events insert does not fan out to Slack, only
|
|
429
|
-
// logOps at error severity does.
|
|
430
|
-
assertStringIncludes(
|
|
431
|
-
JSON.stringify(stub.opsEventInserts),
|
|
432
|
-
'member_door_action_group_check_mismatch',
|
|
433
|
-
);
|
|
434
|
-
// The PIN still never reaches any audit payload.
|
|
435
|
-
assertFalse(JSON.stringify(stub.opsEventInserts).includes('4821'));
|
|
436
|
-
});
|
|
437
|
-
});
|
|
438
|
-
});
|
|
439
|
-
|
|
440
|
-
Deno.test('pin_regenerate: ANY non-ok group_check value escalates, not just "mismatch"', async () => {
|
|
441
|
-
await withEnvs({}, async () => {
|
|
442
|
-
for (const verdict of ['mismatch', 'unknown', 'error', 'skipped', 'OK']) {
|
|
443
|
-
await withFetchStub({
|
|
444
|
-
middleware: {
|
|
445
|
-
kind: 'json',
|
|
446
|
-
status: 200,
|
|
447
|
-
body: { ...MIDDLEWARE_OK.pin_regenerate as Record<string, unknown>, group_check: verdict },
|
|
448
|
-
},
|
|
449
|
-
}, async (stub) => {
|
|
450
|
-
const res = await handleMemberDoorAction(requestFor('pin_regenerate'));
|
|
451
|
-
assertEquals(res.status, 200, verdict);
|
|
452
|
-
const audit = stub.opsEventInserts.find(
|
|
453
|
-
(e) => (e as { kind?: string }).kind === 'member_door_action',
|
|
454
|
-
) as { severity?: string } | undefined;
|
|
455
|
-
// 'OK' is included deliberately: the contract value is lowercase 'ok',
|
|
456
|
-
// so anything else -- including a case variant -- is treated as unknown
|
|
457
|
-
// and escalated rather than optimistically accepted.
|
|
458
|
-
assertEquals(audit?.severity, 'error', verdict);
|
|
459
|
-
});
|
|
460
|
-
}
|
|
461
|
-
});
|
|
462
|
-
});
|
|
463
|
-
|
|
464
|
-
Deno.test('the group_check escalation is scoped to pin_regenerate only', async () => {
|
|
465
|
-
await withEnvs({}, async () => {
|
|
466
|
-
await withFetchStub({
|
|
467
|
-
middleware: {
|
|
468
|
-
kind: 'json',
|
|
469
|
-
status: 200,
|
|
470
|
-
body: { ...MIDDLEWARE_OK.wifi_voucher as Record<string, unknown>, group_check: 'mismatch' },
|
|
471
|
-
},
|
|
472
|
-
}, async (stub) => {
|
|
473
|
-
const res = await handleMemberDoorAction(requestFor('wifi_voucher'));
|
|
474
|
-
assertEquals(res.status, 200);
|
|
475
|
-
// Not in wifi_voucher's allowlist, so it is dropped rather than acted on.
|
|
476
|
-
assertFalse('group_check' in (await res.json()));
|
|
477
|
-
const audit = stub.opsEventInserts.find(
|
|
478
|
-
(e) => (e as { kind?: string }).kind === 'member_door_action',
|
|
479
|
-
) as { severity?: string } | undefined;
|
|
480
|
-
assertEquals(audit?.severity, 'info');
|
|
481
|
-
});
|
|
482
|
-
});
|
|
483
|
-
});
|
|
484
|
-
|
|
485
|
-
Deno.test('activity: success calls GET /member/activity and projects hits through the allowlist', async () => {
|
|
486
|
-
await withEnvs({}, async () => {
|
|
487
|
-
await withFetchStub(
|
|
488
|
-
{ middleware: { kind: 'json', status: 200, body: MIDDLEWARE_OK.activity } },
|
|
489
|
-
async (stub) => {
|
|
490
|
-
const res = await handleMemberDoorAction(requestFor('activity'));
|
|
491
|
-
assertEquals(res.status, 200);
|
|
492
|
-
const body = await res.json();
|
|
493
|
-
assertEquals(body.ok, true);
|
|
494
|
-
assertEquals(body.hits.length, 1);
|
|
495
|
-
// actor_id is asserted server-side then dropped: no UniFi internal id
|
|
496
|
-
// reaches the browser.
|
|
497
|
-
assertEquals(body.hits[0], {
|
|
498
|
-
at: '2026-09-01T17:02:21-07:00',
|
|
499
|
-
door_id: UNIFI_DOOR_ID,
|
|
500
|
-
door_name: 'Commons-Main',
|
|
501
|
-
result: 'ACCESS',
|
|
502
|
-
method: 'remote',
|
|
503
|
-
});
|
|
504
|
-
assertEquals(stub.middlewareCalls[0].method, 'GET');
|
|
505
|
-
assertEquals(stub.middlewareCalls[0].url, `${MIDDLEWARE_BASE}/member/activity?limit=25`);
|
|
506
|
-
assertEquals(stub.middlewareCalls[0].body, '');
|
|
507
|
-
},
|
|
508
|
-
);
|
|
509
|
-
});
|
|
510
|
-
});
|
|
511
|
-
|
|
512
|
-
Deno.test('activity: unknown middleware fields are dropped, not passed through raw', async () => {
|
|
513
|
-
await withEnvs({}, async () => {
|
|
514
|
-
await withFetchStub({
|
|
515
|
-
middleware: {
|
|
516
|
-
kind: 'json',
|
|
517
|
-
status: 200,
|
|
518
|
-
body: {
|
|
519
|
-
ok: true,
|
|
520
|
-
hits: [{
|
|
521
|
-
at: 'x', door_name: 'Commons-Main', actor_id: UNIFI_USER_ID,
|
|
522
|
-
_source: { actor: { display_name: 'Someone Else' } },
|
|
523
|
-
authentication: { credential_provider: 'REX' },
|
|
524
|
-
}],
|
|
525
|
-
},
|
|
526
|
-
},
|
|
527
|
-
}, async () => {
|
|
528
|
-
const res = await handleMemberDoorAction(requestFor('activity'));
|
|
529
|
-
const body = await res.json();
|
|
530
|
-
assertEquals(body.hits[0], { at: 'x', door_name: 'Commons-Main' });
|
|
531
|
-
});
|
|
532
|
-
});
|
|
533
|
-
});
|
|
534
|
-
|
|
535
|
-
Deno.test('activity: limit is clamped to the server maximum', async () => {
|
|
536
|
-
await withEnvs({}, async () => {
|
|
537
|
-
await withFetchStub(
|
|
538
|
-
{ middleware: { kind: 'json', status: 200, body: { ok: true, hits: [] } } },
|
|
539
|
-
async (stub) => {
|
|
540
|
-
await handleMemberDoorAction(requestFor('activity', { limit: 9999 }));
|
|
541
|
-
assertEquals(stub.middlewareCalls[0].url, `${MIDDLEWARE_BASE}/member/activity?limit=50`);
|
|
542
|
-
},
|
|
543
|
-
);
|
|
544
|
-
});
|
|
545
|
-
});
|
|
546
|
-
|
|
547
|
-
Deno.test('wifi_voucher: success calls POST /member/wifi-voucher and returns the code once', async () => {
|
|
548
|
-
await withEnvs({}, async () => {
|
|
549
|
-
await withFetchStub(
|
|
550
|
-
{ middleware: { kind: 'json', status: 200, body: MIDDLEWARE_OK.wifi_voucher } },
|
|
551
|
-
async (stub) => {
|
|
552
|
-
const res = await handleMemberDoorAction(requestFor('wifi_voucher'));
|
|
553
|
-
assertEquals(res.status, 200);
|
|
554
|
-
assertEquals(await res.json(), {
|
|
555
|
-
ok: true,
|
|
556
|
-
code: '9090950795',
|
|
557
|
-
expires_at: '2026-09-03T02:00:00Z',
|
|
558
|
-
time_limit_minutes: 480,
|
|
559
|
-
authorized_guest_limit: 1,
|
|
560
|
-
});
|
|
561
|
-
assertEquals(stub.middlewareCalls[0].url, `${MIDDLEWARE_BASE}/member/wifi-voucher`);
|
|
562
|
-
// Body carries no member-configurable limits (plan §6.2).
|
|
563
|
-
assertEquals(stub.middlewareCalls[0].body, '{}');
|
|
564
|
-
assertFalse(JSON.stringify(stub.opsEventInserts).includes('9090950795'));
|
|
565
|
-
},
|
|
566
|
-
);
|
|
567
|
-
});
|
|
568
|
-
});
|
|
569
|
-
|
|
570
|
-
// ===========================================================================
|
|
571
|
-
// 2. Identity assertion
|
|
572
|
-
// ===========================================================================
|
|
573
|
-
|
|
574
|
-
Deno.test('assertion: signed Ed25519, subject is the verified session sub, exp <= 120s', async () => {
|
|
575
|
-
await withEnvs({}, async () => {
|
|
576
|
-
await withFetchStub(
|
|
577
|
-
{ middleware: { kind: 'json', status: 200, body: MIDDLEWARE_OK.unlock } },
|
|
578
|
-
async (stub) => {
|
|
579
|
-
await handleMemberDoorAction(requestFor('unlock'));
|
|
580
|
-
const jwt = stub.middlewareCalls[0].headers[ASSERTION_HEADER];
|
|
581
|
-
assert(jwt, 'assertion header was not sent');
|
|
582
|
-
const { header, claims, signatureValid } = await verifyAssertion(jwt);
|
|
583
|
-
assert(signatureValid, 'assertion signature did not verify under the test key');
|
|
584
|
-
assertEquals(header.alg, 'EdDSA');
|
|
585
|
-
assertEquals(header.crv, 'Ed25519');
|
|
586
|
-
assertEquals(claims.sub, MEMBER_UID);
|
|
587
|
-
assertEquals(claims.iss, 'gc-io');
|
|
588
|
-
assertEquals(claims.aud, 'ftw-middleware:granite-city');
|
|
589
|
-
assertEquals(claims.act, 'unlock');
|
|
590
|
-
assertEquals(claims.door_id, UNIFI_DOOR_ID);
|
|
591
|
-
assertEquals(claims.nbf, claims.iat);
|
|
592
|
-
assert(typeof claims.jti === 'string' && (claims.jti as string).length >= 32);
|
|
593
|
-
const ttl = (claims.exp as number) - (claims.iat as number);
|
|
594
|
-
assert(ttl > 0 && ttl <= ASSERTION_MAX_TTL_SECONDS, `ttl was ${ttl}`);
|
|
595
|
-
},
|
|
596
|
-
);
|
|
597
|
-
});
|
|
598
|
-
});
|
|
599
|
-
|
|
600
|
-
Deno.test('assertion: the client can never choose the subject, the UniFi user, or the door', async () => {
|
|
601
|
-
await withEnvs({}, async () => {
|
|
602
|
-
await withFetchStub(
|
|
603
|
-
{ middleware: { kind: 'json', status: 200, body: MIDDLEWARE_OK.unlock } },
|
|
604
|
-
async (stub) => {
|
|
605
|
-
const req = makeRequest({
|
|
606
|
-
action: 'unlock',
|
|
607
|
-
door_id: GC_DOOR_ID,
|
|
608
|
-
// Every one of these is a forgery attempt and every one is ignored.
|
|
609
|
-
sub: 'attacker-uid',
|
|
610
|
-
user_id: 'attacker-uid',
|
|
611
|
-
unifi_user_id: 'someone-elses-unifi-id',
|
|
612
|
-
unifi_access_user_id: 'someone-elses-unifi-id',
|
|
613
|
-
actor_id: 'someone-elses-unifi-id',
|
|
614
|
-
actor_name: 'Someone Else',
|
|
615
|
-
email: 'victim@example.com',
|
|
616
|
-
});
|
|
617
|
-
const res = await handleMemberDoorAction(req);
|
|
618
|
-
assertEquals(res.status, 200);
|
|
619
|
-
const call = stub.middlewareCalls[0];
|
|
620
|
-
// The outbound body is empty: there is no field for the middleware to
|
|
621
|
-
// prefer over the assertion.
|
|
622
|
-
assertEquals(call.body, '{}');
|
|
623
|
-
const { claims } = await verifyAssertion(call.headers[ASSERTION_HEADER]);
|
|
624
|
-
assertEquals(claims.sub, MEMBER_UID);
|
|
625
|
-
assertEquals(claims.door_id, UNIFI_DOOR_ID);
|
|
626
|
-
assertFalse(JSON.stringify(claims).includes('attacker-uid'));
|
|
627
|
-
assertFalse(JSON.stringify(claims).includes('someone-elses-unifi-id'));
|
|
628
|
-
},
|
|
629
|
-
);
|
|
630
|
-
});
|
|
631
|
-
});
|
|
632
|
-
|
|
633
|
-
Deno.test('assertion: not one IGNORED_BODY_FIELDS value survives into the outbound call', async () => {
|
|
634
|
-
await withEnvs({}, async () => {
|
|
635
|
-
await withFetchStub(
|
|
636
|
-
{ middleware: { kind: 'json', status: 200, body: MIDDLEWARE_OK.wifi_voucher } },
|
|
637
|
-
async (stub) => {
|
|
638
|
-
const poisoned: Record<string, unknown> = { action: 'wifi_voucher' };
|
|
639
|
-
for (const f of IGNORED_BODY_FIELDS) poisoned[f] = `POISON-${f}`;
|
|
640
|
-
const res = await handleMemberDoorAction(makeRequest(poisoned));
|
|
641
|
-
assertEquals(res.status, 200);
|
|
642
|
-
const call = stub.middlewareCalls[0];
|
|
643
|
-
const seen = `${call.url}\n${call.body}\n${JSON.stringify(call.headers)}`;
|
|
644
|
-
assertFalse(seen.includes('POISON'), 'a client-supplied identity field was forwarded');
|
|
645
|
-
},
|
|
646
|
-
);
|
|
647
|
-
});
|
|
648
|
-
});
|
|
649
|
-
|
|
650
|
-
Deno.test('assertion: a distinct jti is minted per request', async () => {
|
|
651
|
-
await withEnvs({}, async () => {
|
|
652
|
-
await withFetchStub(
|
|
653
|
-
{ middleware: { kind: 'json', status: 200, body: MIDDLEWARE_OK.wifi_voucher } },
|
|
654
|
-
async (stub) => {
|
|
655
|
-
await handleMemberDoorAction(requestFor('wifi_voucher'));
|
|
656
|
-
await handleMemberDoorAction(requestFor('wifi_voucher'));
|
|
657
|
-
const a = await verifyAssertion(stub.middlewareCalls[0].headers[ASSERTION_HEADER]);
|
|
658
|
-
const b = await verifyAssertion(stub.middlewareCalls[1].headers[ASSERTION_HEADER]);
|
|
659
|
-
assert(a.claims.jti !== b.claims.jti);
|
|
660
|
-
},
|
|
661
|
-
);
|
|
662
|
-
});
|
|
663
|
-
});
|
|
664
|
-
|
|
665
|
-
Deno.test('d1 HMAC: signature verifies over the documented canonical message', async () => {
|
|
666
|
-
await withEnvs({}, async () => {
|
|
667
|
-
await withFetchStub(
|
|
668
|
-
{ middleware: { kind: 'json', status: 200, body: MIDDLEWARE_OK.unlock } },
|
|
669
|
-
async (stub) => {
|
|
670
|
-
await handleMemberDoorAction(requestFor('unlock'));
|
|
671
|
-
const call = stub.middlewareCalls[0];
|
|
672
|
-
assertEquals(call.headers[SCHEME_HEADER], HMAC_SCHEME);
|
|
673
|
-
const expected = await hmacD1(
|
|
674
|
-
ENV_DEFAULTS.MEMBER_ACTIONS_HMAC_SECRET,
|
|
675
|
-
canonicalMemberActionMessage(
|
|
676
|
-
'unlock',
|
|
677
|
-
call.headers[TIMESTAMP_HEADER],
|
|
678
|
-
await sha256Hex(call.headers[ASSERTION_HEADER]),
|
|
679
|
-
await sha256Hex('{}'),
|
|
680
|
-
),
|
|
681
|
-
);
|
|
682
|
-
assertEquals(call.headers[SIGNATURE_HEADER], expected);
|
|
683
|
-
},
|
|
684
|
-
);
|
|
685
|
-
});
|
|
686
|
-
});
|
|
687
|
-
|
|
688
|
-
Deno.test('d1 HMAC: the GET signs its canonical query string', async () => {
|
|
689
|
-
await withEnvs({}, async () => {
|
|
690
|
-
await withFetchStub(
|
|
691
|
-
{ middleware: { kind: 'json', status: 200, body: { ok: true, hits: [] } } },
|
|
692
|
-
async (stub) => {
|
|
693
|
-
await handleMemberDoorAction(requestFor('activity', { limit: 10 }));
|
|
694
|
-
const call = stub.middlewareCalls[0];
|
|
695
|
-
const expected = await hmacD1(
|
|
696
|
-
ENV_DEFAULTS.MEMBER_ACTIONS_HMAC_SECRET,
|
|
697
|
-
canonicalMemberActionMessage(
|
|
698
|
-
'activity',
|
|
699
|
-
call.headers[TIMESTAMP_HEADER],
|
|
700
|
-
await sha256Hex(call.headers[ASSERTION_HEADER]),
|
|
701
|
-
await sha256Hex('limit=10'),
|
|
702
|
-
),
|
|
703
|
-
);
|
|
704
|
-
assertEquals(call.headers[SIGNATURE_HEADER], expected);
|
|
705
|
-
},
|
|
706
|
-
);
|
|
707
|
-
});
|
|
708
|
-
});
|
|
709
|
-
|
|
710
|
-
// ===========================================================================
|
|
711
|
-
// 3. Auth-context rejection — no unauthenticated caller can invoke ANY action
|
|
712
|
-
// ===========================================================================
|
|
713
|
-
|
|
714
|
-
Deno.test('no Authorization header: every action is rejected 401 and nothing is forwarded', async () => {
|
|
715
|
-
await withEnvs({}, async () => {
|
|
716
|
-
for (const action of MEMBER_ACTIONS) {
|
|
717
|
-
await withFetchStub({}, async (stub) => {
|
|
718
|
-
const req = makeRequest(
|
|
719
|
-
{ action, ...(action === 'unlock' ? { door_id: GC_DOOR_ID } : {}) },
|
|
720
|
-
{ token: null },
|
|
721
|
-
);
|
|
722
|
-
const res = await handleMemberDoorAction(req);
|
|
723
|
-
assertEquals(res.status, 401, `action ${action}`);
|
|
724
|
-
assertEquals(await res.json(), { ok: false, error: 'unauthorized' });
|
|
725
|
-
assertEquals(stub.middlewareCalls.length, 0, `action ${action} reached the middleware`);
|
|
726
|
-
});
|
|
727
|
-
}
|
|
728
|
-
});
|
|
729
|
-
});
|
|
730
|
-
|
|
731
|
-
Deno.test('invalid session (auth endpoint rejects the JWT): every action is 401, nothing forwarded', async () => {
|
|
732
|
-
await withEnvs({}, async () => {
|
|
733
|
-
for (const action of MEMBER_ACTIONS) {
|
|
734
|
-
await withFetchStub({ auth: 'reject' }, async (stub) => {
|
|
735
|
-
const res = await handleMemberDoorAction(requestFor(action));
|
|
736
|
-
assertEquals(res.status, 401, `action ${action}`);
|
|
737
|
-
assertEquals(stub.middlewareCalls.length, 0);
|
|
738
|
-
});
|
|
739
|
-
}
|
|
740
|
-
});
|
|
741
|
-
});
|
|
742
|
-
|
|
743
|
-
Deno.test('anon/publishable key presented as the bearer is not a session: 401', async () => {
|
|
744
|
-
await withEnvs({}, async () => {
|
|
745
|
-
await withFetchStub({}, async (stub) => {
|
|
746
|
-
const res = await handleMemberDoorAction(makeRequest(
|
|
747
|
-
{ action: 'unlock', door_id: GC_DOOR_ID },
|
|
748
|
-
{ token: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.anon-publishable-key.sig' },
|
|
749
|
-
));
|
|
750
|
-
assertEquals(res.status, 401);
|
|
751
|
-
assertEquals(stub.middlewareCalls.length, 0);
|
|
752
|
-
});
|
|
753
|
-
});
|
|
754
|
-
});
|
|
755
|
-
|
|
756
|
-
Deno.test('non-POST and OPTIONS are handled without touching identity or the middleware', async () => {
|
|
757
|
-
await withEnvs({}, async () => {
|
|
758
|
-
await withFetchStub({}, async (stub) => {
|
|
759
|
-
const opts = await handleMemberDoorAction(makeRequest(null, { method: 'OPTIONS' }));
|
|
760
|
-
assertEquals(opts.status, 200);
|
|
761
|
-
assertEquals(await opts.text(), 'ok');
|
|
762
|
-
const get = await handleMemberDoorAction(makeRequest(null, { method: 'GET' }));
|
|
763
|
-
assertEquals(get.status, 405);
|
|
764
|
-
assertEquals(stub.middlewareCalls.length, 0);
|
|
765
|
-
});
|
|
766
|
-
});
|
|
767
|
-
});
|
|
768
|
-
|
|
769
|
-
// ===========================================================================
|
|
770
|
-
// 4. tenant-app-side authorization: uniform opaque refusal, fail closed
|
|
771
|
-
// ===========================================================================
|
|
772
|
-
|
|
773
|
-
Deno.test('feature flag off (default) denies every action with 503 and forwards nothing', async () => {
|
|
774
|
-
await withEnvs({ MEMBER_ACTIONS_ENABLED: undefined }, async () => {
|
|
775
|
-
for (const action of MEMBER_ACTIONS) {
|
|
776
|
-
await withFetchStub({}, async (stub) => {
|
|
777
|
-
const res = await handleMemberDoorAction(requestFor(action));
|
|
778
|
-
assertEquals(res.status, 503);
|
|
779
|
-
assertEquals(await res.json(), { ok: false, error: 'not_configured' });
|
|
780
|
-
assertEquals(stub.middlewareCalls.length, 0);
|
|
781
|
-
});
|
|
782
|
-
}
|
|
783
|
-
});
|
|
784
|
-
});
|
|
785
|
-
|
|
786
|
-
Deno.test('a malformed MEMBER_ACTIONS_ENABLED value is treated as false, never as a crash', async () => {
|
|
787
|
-
await withEnvs({ MEMBER_ACTIONS_ENABLED: 'maybe' }, async () => {
|
|
788
|
-
await withFetchStub({}, async (stub) => {
|
|
789
|
-
const res = await handleMemberDoorAction(requestFor('unlock'));
|
|
790
|
-
assertEquals(res.status, 503);
|
|
791
|
-
assertEquals(stub.middlewareCalls.length, 0);
|
|
792
|
-
});
|
|
793
|
-
});
|
|
794
|
-
});
|
|
795
|
-
|
|
796
|
-
Deno.test('an EMPTY allowlist denies everyone (not "no filter applied")', async () => {
|
|
797
|
-
await withEnvs({ MEMBER_ACTIONS_ALLOWLIST: '' }, async () => {
|
|
798
|
-
await withFetchStub({}, async (stub) => {
|
|
799
|
-
const res = await handleMemberDoorAction(requestFor('unlock'));
|
|
800
|
-
assertEquals(res.status, 403);
|
|
801
|
-
assertEquals(await res.json(), { ok: false, error: 'not_permitted' });
|
|
802
|
-
assertEquals(stub.middlewareCalls.length, 0);
|
|
803
|
-
});
|
|
804
|
-
});
|
|
805
|
-
});
|
|
806
|
-
|
|
807
|
-
Deno.test('the allowlist is keyed on the Supabase sub, not the email', async () => {
|
|
808
|
-
await withEnvs({ MEMBER_ACTIONS_ALLOWLIST: 'member@example.com' }, async () => {
|
|
809
|
-
await withFetchStub({}, async (stub) => {
|
|
810
|
-
const res = await handleMemberDoorAction(requestFor('unlock'));
|
|
811
|
-
assertEquals(res.status, 403);
|
|
812
|
-
assertEquals(stub.middlewareCalls.length, 0);
|
|
813
|
-
});
|
|
814
|
-
});
|
|
815
|
-
});
|
|
816
|
-
|
|
817
|
-
Deno.test('no UniFi mapping is a hard denial with the uniform opaque body', async () => {
|
|
818
|
-
await withEnvs({}, async () => {
|
|
819
|
-
await withFetchStub({
|
|
820
|
-
membershipRows: [{
|
|
821
|
-
id: MEMBERSHIP_ID, status: 'active', pricing_grace_ends_at: null,
|
|
822
|
-
door_managed: true, door_access_not_before: null, unifi_access_user_id: null,
|
|
823
|
-
}],
|
|
824
|
-
}, async (stub) => {
|
|
825
|
-
const res = await handleMemberDoorAction(requestFor('unlock'));
|
|
826
|
-
assertEquals(res.status, 403);
|
|
827
|
-
assertEquals(await res.json(), { ok: false, error: 'not_permitted' });
|
|
828
|
-
assertEquals(stub.middlewareCalls.length, 0);
|
|
829
|
-
});
|
|
830
|
-
});
|
|
831
|
-
});
|
|
832
|
-
|
|
833
|
-
Deno.test('an AMBIGUOUS (non-unique) UniFi mapping is a hard denial', async () => {
|
|
834
|
-
await withEnvs({}, async () => {
|
|
835
|
-
await withFetchStub({
|
|
836
|
-
membershipRows: [
|
|
837
|
-
{ id: MEMBERSHIP_ID, status: 'active', pricing_grace_ends_at: null, door_managed: true, door_access_not_before: null, unifi_access_user_id: 'unifi-a' },
|
|
838
|
-
{ id: 'other', status: 'active', pricing_grace_ends_at: null, door_managed: true, door_access_not_before: null, unifi_access_user_id: 'unifi-b' },
|
|
839
|
-
],
|
|
840
|
-
}, async (stub) => {
|
|
841
|
-
const res = await handleMemberDoorAction(requestFor('unlock'));
|
|
842
|
-
assertEquals(res.status, 403);
|
|
843
|
-
assertEquals(stub.middlewareCalls.length, 0);
|
|
844
|
-
assertStringIncludes(JSON.stringify(stub.opsEventInserts), 'member_door_action_ambiguous_mapping');
|
|
845
|
-
});
|
|
846
|
-
});
|
|
847
|
-
});
|
|
848
|
-
|
|
849
|
-
Deno.test('a member with no membership row at all is denied', async () => {
|
|
850
|
-
await withEnvs({}, async () => {
|
|
851
|
-
await withFetchStub({ membershipRows: [] }, async (stub) => {
|
|
852
|
-
const res = await handleMemberDoorAction(requestFor('activity'));
|
|
853
|
-
assertEquals(res.status, 403);
|
|
854
|
-
assertEquals(stub.middlewareCalls.length, 0);
|
|
855
|
-
});
|
|
856
|
-
});
|
|
857
|
-
});
|
|
858
|
-
|
|
859
|
-
Deno.test('an unentitled (canceled, no grace) membership is denied', async () => {
|
|
860
|
-
await withEnvs({}, async () => {
|
|
861
|
-
await withFetchStub({
|
|
862
|
-
membershipRows: [{
|
|
863
|
-
id: MEMBERSHIP_ID, status: 'canceled', pricing_grace_ends_at: null,
|
|
864
|
-
door_managed: true, door_access_not_before: null, unifi_access_user_id: UNIFI_USER_ID,
|
|
865
|
-
}],
|
|
866
|
-
}, async (stub) => {
|
|
867
|
-
const res = await handleMemberDoorAction(requestFor('unlock'));
|
|
868
|
-
assertEquals(res.status, 403);
|
|
869
|
-
assertEquals(stub.middlewareCalls.length, 0);
|
|
870
|
-
});
|
|
871
|
-
});
|
|
872
|
-
});
|
|
873
|
-
|
|
874
|
-
Deno.test('door_access_not_before in the future is denied', async () => {
|
|
875
|
-
await withEnvs({}, async () => {
|
|
876
|
-
await withFetchStub({
|
|
877
|
-
membershipRows: [{
|
|
878
|
-
id: MEMBERSHIP_ID, status: 'active', pricing_grace_ends_at: null,
|
|
879
|
-
door_managed: true,
|
|
880
|
-
door_access_not_before: new Date(Date.now() + 86_400_000).toISOString(),
|
|
881
|
-
unifi_access_user_id: UNIFI_USER_ID,
|
|
882
|
-
}],
|
|
883
|
-
}, async (stub) => {
|
|
884
|
-
const res = await handleMemberDoorAction(requestFor('unlock'));
|
|
885
|
-
assertEquals(res.status, 403);
|
|
886
|
-
assertEquals(stub.middlewareCalls.length, 0);
|
|
887
|
-
});
|
|
888
|
-
});
|
|
889
|
-
});
|
|
890
|
-
|
|
891
|
-
Deno.test('a door_managed=false membership is denied', async () => {
|
|
892
|
-
await withEnvs({}, async () => {
|
|
893
|
-
await withFetchStub({
|
|
894
|
-
membershipRows: [{
|
|
895
|
-
id: MEMBERSHIP_ID, status: 'active', pricing_grace_ends_at: null,
|
|
896
|
-
door_managed: false, door_access_not_before: null, unifi_access_user_id: UNIFI_USER_ID,
|
|
897
|
-
}],
|
|
898
|
-
}, async (stub) => {
|
|
899
|
-
const res = await handleMemberDoorAction(requestFor('unlock'));
|
|
900
|
-
assertEquals(res.status, 403);
|
|
901
|
-
assertEquals(stub.middlewareCalls.length, 0);
|
|
902
|
-
});
|
|
903
|
-
});
|
|
904
|
-
});
|
|
905
|
-
|
|
906
|
-
Deno.test('an unprovisioned door yields the SAME opaque refusal as an unentitled member', async () => {
|
|
907
|
-
await withEnvs({}, async () => {
|
|
908
|
-
await withFetchStub({
|
|
909
|
-
door: { id: GC_DOOR_ID, name: 'Granite City Hub', unifi_door_id: 'PENDING', status: 'pending_placeholder' },
|
|
910
|
-
}, async (stub) => {
|
|
911
|
-
const res = await handleMemberDoorAction(requestFor('unlock'));
|
|
912
|
-
assertEquals(res.status, 403);
|
|
913
|
-
assertEquals(await res.json(), { ok: false, error: 'not_permitted' });
|
|
914
|
-
assertEquals(stub.middlewareCalls.length, 0);
|
|
915
|
-
});
|
|
916
|
-
});
|
|
917
|
-
});
|
|
918
|
-
|
|
919
|
-
Deno.test('a malformed door id is a shape error, not an entitlement oracle', async () => {
|
|
920
|
-
await withEnvs({}, async () => {
|
|
921
|
-
await withFetchStub({}, async (stub) => {
|
|
922
|
-
const res = await handleMemberDoorAction(makeRequest({ action: 'unlock', door_id: 'not-a-uuid' }));
|
|
923
|
-
assertEquals(res.status, 400);
|
|
924
|
-
assertEquals(await res.json(), { ok: false, error: 'invalid_payload' });
|
|
925
|
-
assertEquals(stub.middlewareCalls.length, 0);
|
|
926
|
-
});
|
|
927
|
-
});
|
|
928
|
-
});
|
|
929
|
-
|
|
930
|
-
Deno.test('an unknown action is refused before any signing or forwarding', async () => {
|
|
931
|
-
await withEnvs({}, async () => {
|
|
932
|
-
await withFetchStub({}, async (stub) => {
|
|
933
|
-
const res = await handleMemberDoorAction(makeRequest({ action: 'lockdown' }));
|
|
934
|
-
assertEquals(res.status, 400);
|
|
935
|
-
assertEquals(await res.json(), { ok: false, error: 'unknown_action' });
|
|
936
|
-
assertEquals(stub.middlewareCalls.length, 0);
|
|
937
|
-
});
|
|
938
|
-
});
|
|
939
|
-
});
|
|
940
|
-
|
|
941
|
-
Deno.test('rate limiting refuses before any signing or forwarding', async () => {
|
|
942
|
-
await withEnvs({}, async () => {
|
|
943
|
-
await withFetchStub({ rateLimitAllows: false }, async (stub) => {
|
|
944
|
-
const res = await handleMemberDoorAction(requestFor('unlock'));
|
|
945
|
-
assertEquals(res.status, 429);
|
|
946
|
-
assertEquals(await res.json(), { ok: false, error: 'rate_limited' });
|
|
947
|
-
assertEquals(stub.middlewareCalls.length, 0);
|
|
948
|
-
});
|
|
949
|
-
});
|
|
950
|
-
});
|
|
951
|
-
|
|
952
|
-
Deno.test('a membership lookup failure fails closed (500), never "no restriction found"', async () => {
|
|
953
|
-
await withEnvs({}, async () => {
|
|
954
|
-
await withFetchStub({ membershipRows: 'error' }, async (stub) => {
|
|
955
|
-
const res = await handleMemberDoorAction(requestFor('unlock'));
|
|
956
|
-
assertEquals(res.status, 500);
|
|
957
|
-
assertEquals(await res.json(), { ok: false, error: 'lookup_failed' });
|
|
958
|
-
assertEquals(stub.middlewareCalls.length, 0);
|
|
959
|
-
});
|
|
960
|
-
});
|
|
961
|
-
});
|
|
962
|
-
|
|
963
|
-
// ===========================================================================
|
|
964
|
-
// 5. Configuration / key isolation
|
|
965
|
-
// ===========================================================================
|
|
966
|
-
|
|
967
|
-
Deno.test('an unset middleware base URL makes the function inert (503), never a default host', async () => {
|
|
968
|
-
await withEnvs({ FTW_MIDDLEWARE_BASE_URL: undefined }, async () => {
|
|
969
|
-
await withFetchStub({}, async (stub) => {
|
|
970
|
-
const res = await handleMemberDoorAction(requestFor('unlock'));
|
|
971
|
-
assertEquals(res.status, 503);
|
|
972
|
-
assertEquals(await res.json(), { ok: false, error: 'not_configured' });
|
|
973
|
-
assertEquals(stub.middlewareCalls.length, 0);
|
|
974
|
-
assertEquals(stub.otherUrls.length, 0);
|
|
975
|
-
});
|
|
976
|
-
});
|
|
977
|
-
});
|
|
978
|
-
|
|
979
|
-
Deno.test('a non-https middleware base URL is refused', async () => {
|
|
980
|
-
await withEnvs({ FTW_MIDDLEWARE_BASE_URL: 'http://middleware.test.invalid' }, async () => {
|
|
981
|
-
await withFetchStub({}, async (stub) => {
|
|
982
|
-
const res = await handleMemberDoorAction(requestFor('unlock'));
|
|
983
|
-
assertEquals(res.status, 503);
|
|
984
|
-
assertEquals(stub.middlewareCalls.length, 0);
|
|
985
|
-
assertEquals(stub.otherUrls.length, 0);
|
|
986
|
-
});
|
|
987
|
-
});
|
|
988
|
-
});
|
|
989
|
-
|
|
990
|
-
Deno.test('reusing a membership-sync secret as the assertion key refuses every request', async () => {
|
|
991
|
-
await withEnvs({ BUS_HMAC_SECRET_MEMBERSHIP: PKCS8_B64 }, async () => {
|
|
992
|
-
await withFetchStub({}, async (stub) => {
|
|
993
|
-
const res = await handleMemberDoorAction(requestFor('unlock'));
|
|
994
|
-
assertEquals(res.status, 500);
|
|
995
|
-
assertEquals(await res.json(), { ok: false, error: 'signing_unavailable' });
|
|
996
|
-
assertEquals(stub.middlewareCalls.length, 0);
|
|
997
|
-
});
|
|
998
|
-
});
|
|
999
|
-
});
|
|
1000
|
-
|
|
1001
|
-
Deno.test('an unusable signing key refuses rather than falling back to an unsigned call', async () => {
|
|
1002
|
-
await withEnvs({ MEMBER_ASSERTION_SIGNING_KEY: 'not-a-key' }, async () => {
|
|
1003
|
-
await withFetchStub({}, async (stub) => {
|
|
1004
|
-
const res = await handleMemberDoorAction(requestFor('unlock'));
|
|
1005
|
-
assertEquals(res.status, 500);
|
|
1006
|
-
assertEquals(await res.json(), { ok: false, error: 'signing_unavailable' });
|
|
1007
|
-
assertEquals(stub.middlewareCalls.length, 0);
|
|
1008
|
-
});
|
|
1009
|
-
});
|
|
1010
|
-
});
|
|
1011
|
-
|
|
1012
|
-
// ===========================================================================
|
|
1013
|
-
// 6. Mocked ftw-middleware failure modes
|
|
1014
|
-
// ===========================================================================
|
|
1015
|
-
|
|
1016
|
-
Deno.test('unlock TIMEOUT reports "couldn\'t confirm", never unlocked, and never retries', async () => {
|
|
1017
|
-
await withEnvs({}, async () => {
|
|
1018
|
-
await withFetchStub({ middleware: { kind: 'timeout' } }, async (stub) => {
|
|
1019
|
-
const res = await handleMemberDoorAction(requestFor('unlock'));
|
|
1020
|
-
assertEquals(res.status, 502);
|
|
1021
|
-
const body = await res.json();
|
|
1022
|
-
assertEquals(body.ok, false);
|
|
1023
|
-
assertEquals(body.error, 'unlock_unconfirmed');
|
|
1024
|
-
assertStringIncludes(body.message, 'use your card');
|
|
1025
|
-
// Exactly one attempt: an unlock is never auto-retried.
|
|
1026
|
-
assertEquals(stub.middlewareCalls.length, 1);
|
|
1027
|
-
assertStringIncludes(JSON.stringify(stub.opsEventInserts), '"outcome":"unknown"');
|
|
1028
|
-
});
|
|
1029
|
-
});
|
|
1030
|
-
});
|
|
1031
|
-
|
|
1032
|
-
Deno.test('unlock 500 from the middleware is unconfirmed, not a denial and not a success', async () => {
|
|
1033
|
-
await withEnvs({}, async () => {
|
|
1034
|
-
await withFetchStub({ middleware: { kind: 'raw', status: 500, text: 'upstream boom' } }, async (stub) => {
|
|
1035
|
-
const res = await handleMemberDoorAction(requestFor('unlock'));
|
|
1036
|
-
assertEquals(res.status, 502);
|
|
1037
|
-
assertEquals((await res.json()).error, 'unlock_unconfirmed');
|
|
1038
|
-
assertEquals(stub.middlewareCalls.length, 1);
|
|
1039
|
-
});
|
|
1040
|
-
});
|
|
1041
|
-
});
|
|
1042
|
-
|
|
1043
|
-
Deno.test('unlock with a missing outcome is unconfirmed: success is asserted, never inferred', async () => {
|
|
1044
|
-
await withEnvs({}, async () => {
|
|
1045
|
-
await withFetchStub({ middleware: { kind: 'json', status: 200, body: { ok: true } } }, async () => {
|
|
1046
|
-
const res = await handleMemberDoorAction(requestFor('unlock'));
|
|
1047
|
-
assertEquals(res.status, 502);
|
|
1048
|
-
assertEquals((await res.json()).error, 'unlock_unconfirmed');
|
|
1049
|
-
});
|
|
1050
|
-
});
|
|
1051
|
-
});
|
|
1052
|
-
|
|
1053
|
-
Deno.test('unlock with outcome "unconfirmed" is reported as unconfirmed', async () => {
|
|
1054
|
-
await withEnvs({}, async () => {
|
|
1055
|
-
await withFetchStub({
|
|
1056
|
-
middleware: { kind: 'json', status: 200, body: { ok: true, outcome: 'unconfirmed' } },
|
|
1057
|
-
}, async () => {
|
|
1058
|
-
const res = await handleMemberDoorAction(requestFor('unlock'));
|
|
1059
|
-
assertEquals(res.status, 502);
|
|
1060
|
-
assertEquals((await res.json()).error, 'unlock_unconfirmed');
|
|
1061
|
-
});
|
|
1062
|
-
});
|
|
1063
|
-
});
|
|
1064
|
-
|
|
1065
|
-
Deno.test('a middleware 403 becomes the uniform opaque refusal, and is logged loudly', async () => {
|
|
1066
|
-
await withEnvs({}, async () => {
|
|
1067
|
-
await withFetchStub({
|
|
1068
|
-
middleware: { kind: 'json', status: 403, body: { ok: false, error: 'not_permitted' } },
|
|
1069
|
-
}, async (stub) => {
|
|
1070
|
-
const res = await handleMemberDoorAction(requestFor('unlock'));
|
|
1071
|
-
assertEquals(res.status, 403);
|
|
1072
|
-
assertEquals(await res.json(), { ok: false, error: 'not_permitted' });
|
|
1073
|
-
assertStringIncludes(JSON.stringify(stub.opsEventInserts), 'member_door_action_call_failed');
|
|
1074
|
-
});
|
|
1075
|
-
});
|
|
1076
|
-
});
|
|
1077
|
-
|
|
1078
|
-
Deno.test('a middleware 200 carrying ok:false is still a refusal', async () => {
|
|
1079
|
-
await withEnvs({}, async () => {
|
|
1080
|
-
await withFetchStub({
|
|
1081
|
-
middleware: { kind: 'json', status: 200, body: { ok: false, error: 'no_covering_schedule' } },
|
|
1082
|
-
}, async () => {
|
|
1083
|
-
const res = await handleMemberDoorAction(requestFor('unlock'));
|
|
1084
|
-
assertEquals(res.status, 403);
|
|
1085
|
-
assertEquals(await res.json(), { ok: false, error: 'not_permitted' });
|
|
1086
|
-
});
|
|
1087
|
-
});
|
|
1088
|
-
});
|
|
1089
|
-
|
|
1090
|
-
Deno.test('a 404 (route not deployed yet) degrades gracefully per action', async () => {
|
|
1091
|
-
await withEnvs({}, async () => {
|
|
1092
|
-
await withFetchStub({ middleware: { kind: 'raw', status: 404, text: 'not found' } }, async () => {
|
|
1093
|
-
const unlock = await handleMemberDoorAction(requestFor('unlock'));
|
|
1094
|
-
assertEquals(unlock.status, 502);
|
|
1095
|
-
assertEquals((await unlock.json()).error, 'unlock_unconfirmed');
|
|
1096
|
-
});
|
|
1097
|
-
await withFetchStub({ middleware: { kind: 'raw', status: 404, text: 'not found' } }, async () => {
|
|
1098
|
-
const activity = await handleMemberDoorAction(requestFor('activity'));
|
|
1099
|
-
assertEquals(activity.status, 502);
|
|
1100
|
-
assertEquals((await activity.json()).error, 'middleware_error');
|
|
1101
|
-
});
|
|
1102
|
-
});
|
|
1103
|
-
});
|
|
1104
|
-
|
|
1105
|
-
Deno.test('a middleware 429 is surfaced as rate limiting, not as a denial', async () => {
|
|
1106
|
-
await withEnvs({}, async () => {
|
|
1107
|
-
await withFetchStub({ middleware: { kind: 'raw', status: 429, text: 'slow down' } }, async () => {
|
|
1108
|
-
const res = await handleMemberDoorAction(requestFor('wifi_voucher'));
|
|
1109
|
-
assertEquals(res.status, 429);
|
|
1110
|
-
assertEquals(await res.json(), { ok: false, error: 'rate_limited' });
|
|
1111
|
-
});
|
|
1112
|
-
});
|
|
1113
|
-
});
|
|
1114
|
-
|
|
1115
|
-
Deno.test('an unparseable middleware body is an error, never a partial success', async () => {
|
|
1116
|
-
await withEnvs({}, async () => {
|
|
1117
|
-
await withFetchStub({ middleware: { kind: 'raw', status: 200, text: '<html>502</html>' } }, async () => {
|
|
1118
|
-
const res = await handleMemberDoorAction(requestFor('wifi_voucher'));
|
|
1119
|
-
assertEquals(res.status, 502);
|
|
1120
|
-
assertEquals((await res.json()).error, 'middleware_error');
|
|
1121
|
-
});
|
|
1122
|
-
});
|
|
1123
|
-
});
|
|
1124
|
-
|
|
1125
|
-
Deno.test('a middleware transport failure on a non-unlock action is 502 middleware_unreachable', async () => {
|
|
1126
|
-
await withEnvs({}, async () => {
|
|
1127
|
-
await withFetchStub({ middleware: { kind: 'timeout' } }, async () => {
|
|
1128
|
-
const res = await handleMemberDoorAction(requestFor('activity'));
|
|
1129
|
-
assertEquals(res.status, 502);
|
|
1130
|
-
assertEquals((await res.json()).error, 'middleware_unreachable');
|
|
1131
|
-
});
|
|
1132
|
-
});
|
|
1133
|
-
});
|
|
1134
|
-
|
|
1135
|
-
Deno.test('activity: one foreign actor_id discards the WHOLE feed and alerts', async () => {
|
|
1136
|
-
await withEnvs({}, async () => {
|
|
1137
|
-
await withFetchStub({
|
|
1138
|
-
middleware: {
|
|
1139
|
-
kind: 'json',
|
|
1140
|
-
status: 200,
|
|
1141
|
-
body: {
|
|
1142
|
-
ok: true,
|
|
1143
|
-
hits: [
|
|
1144
|
-
{ at: 'a', door_name: 'Commons-Main', actor_id: UNIFI_USER_ID },
|
|
1145
|
-
{ at: 'b', door_name: 'Beer Fridge', actor_id: 'someone-elses-unifi-id' },
|
|
1146
|
-
],
|
|
1147
|
-
},
|
|
1148
|
-
},
|
|
1149
|
-
}, async (stub) => {
|
|
1150
|
-
const res = await handleMemberDoorAction(requestFor('activity'));
|
|
1151
|
-
assertEquals(res.status, 502);
|
|
1152
|
-
const text = JSON.stringify(await res.json());
|
|
1153
|
-
assertFalse(text.includes('Beer Fridge'));
|
|
1154
|
-
assertFalse(text.includes('Commons-Main'));
|
|
1155
|
-
assertStringIncludes(JSON.stringify(stub.opsEventInserts), 'member_door_action_scope_violation');
|
|
1156
|
-
});
|
|
1157
|
-
});
|
|
1158
|
-
});
|
|
1159
|
-
|
|
1160
|
-
Deno.test('activity: a response with no hits array is an error, not an empty feed', async () => {
|
|
1161
|
-
await withEnvs({}, async () => {
|
|
1162
|
-
await withFetchStub({ middleware: { kind: 'json', status: 200, body: { ok: true } } }, async () => {
|
|
1163
|
-
const res = await handleMemberDoorAction(requestFor('activity'));
|
|
1164
|
-
assertEquals(res.status, 502);
|
|
1165
|
-
assertEquals((await res.json()).error, 'middleware_error');
|
|
1166
|
-
});
|
|
1167
|
-
});
|
|
1168
|
-
});
|
|
1169
|
-
|
|
1170
|
-
// ===========================================================================
|
|
1171
|
-
// 7. Pure helpers
|
|
1172
|
-
// ===========================================================================
|
|
1173
|
-
|
|
1174
|
-
Deno.test('parseEnabled: explicit truthy strings only, anything else false + malformed', () => {
|
|
1175
|
-
for (const v of ['1', 'true', 'TRUE', ' yes ', 'on', 'y', 't']) {
|
|
1176
|
-
assertEquals(parseEnabled(v), { enabled: true, malformed: false }, v);
|
|
1177
|
-
}
|
|
1178
|
-
for (const v of [undefined, '', '0', 'false', 'no', 'off', 'n', 'f']) {
|
|
1179
|
-
assertEquals(parseEnabled(v), { enabled: false, malformed: false }, String(v));
|
|
1180
|
-
}
|
|
1181
|
-
for (const v of ['maybe', 'True-ish', '2', 'null']) {
|
|
1182
|
-
assertEquals(parseEnabled(v), { enabled: false, malformed: true }, v);
|
|
1183
|
-
}
|
|
1184
|
-
});
|
|
1185
|
-
|
|
1186
|
-
Deno.test('parseAllowlist: empty means empty (deny everyone), separators are flexible', () => {
|
|
1187
|
-
assertEquals(parseAllowlist(undefined).size, 0);
|
|
1188
|
-
assertEquals(parseAllowlist(' ').size, 0);
|
|
1189
|
-
assertEquals(parseAllowlist('a, b;c d').size, 4);
|
|
1190
|
-
assert(parseAllowlist('a, b').has('b'));
|
|
1191
|
-
});
|
|
1192
|
-
|
|
1193
|
-
Deno.test('assertionTtlSeconds: clamped into [10, 120] with a safe default', () => {
|
|
1194
|
-
assertEquals(assertionTtlSeconds(undefined), 60);
|
|
1195
|
-
assertEquals(assertionTtlSeconds('nonsense'), 60);
|
|
1196
|
-
assertEquals(assertionTtlSeconds('5'), 10);
|
|
1197
|
-
assertEquals(assertionTtlSeconds('90'), 90);
|
|
1198
|
-
assertEquals(assertionTtlSeconds('9999'), ASSERTION_MAX_TTL_SECONDS);
|
|
1199
|
-
});
|
|
1200
|
-
|
|
1201
|
-
Deno.test('keyIsolationViolations: flags every reuse, clean when all secrets differ', () => {
|
|
1202
|
-
assertEquals(
|
|
1203
|
-
keyIsolationViolations({
|
|
1204
|
-
MEMBER_ASSERTION_SIGNING_KEY: 'k1',
|
|
1205
|
-
MEMBER_ACTIONS_HMAC_SECRET: 'k2',
|
|
1206
|
-
BUS_HMAC_SECRET: 'k3',
|
|
1207
|
-
BUS_HMAC_SECRET_MEMBERSHIP: 'k4',
|
|
1208
|
-
BUS_HMAC_SECRET_RESEND: 'k5',
|
|
1209
|
-
SUPABASE_SERVICE_ROLE_KEY: 'k6',
|
|
1210
|
-
MEMBER_ACTIONS_MAPPING_SECRET: 'k7',
|
|
1211
|
-
}),
|
|
1212
|
-
[],
|
|
1213
|
-
);
|
|
1214
|
-
// The mapping endpoint's bearer is checked from this side too: if it were the
|
|
1215
|
-
// same value the tenant app signs with, ftw-middleware's independent resolution would
|
|
1216
|
-
// stop being independent.
|
|
1217
|
-
assertEquals(
|
|
1218
|
-
keyIsolationViolations({
|
|
1219
|
-
MEMBER_ASSERTION_SIGNING_KEY: 'same',
|
|
1220
|
-
MEMBER_ACTIONS_MAPPING_SECRET: 'same',
|
|
1221
|
-
}),
|
|
1222
|
-
['MEMBER_ASSERTION_SIGNING_KEY==MEMBER_ACTIONS_MAPPING_SECRET'],
|
|
1223
|
-
);
|
|
1224
|
-
assertEquals(
|
|
1225
|
-
keyIsolationViolations({
|
|
1226
|
-
MEMBER_ACTIONS_HMAC_SECRET: 'same',
|
|
1227
|
-
MEMBER_ACTIONS_MAPPING_SECRET: 'same',
|
|
1228
|
-
}),
|
|
1229
|
-
['MEMBER_ACTIONS_HMAC_SECRET==MEMBER_ACTIONS_MAPPING_SECRET'],
|
|
1230
|
-
);
|
|
1231
|
-
assertEquals(
|
|
1232
|
-
keyIsolationViolations({ MEMBER_ASSERTION_SIGNING_KEY: 'same', BUS_HMAC_SECRET_MEMBERSHIP: 'same' }),
|
|
1233
|
-
['MEMBER_ASSERTION_SIGNING_KEY==BUS_HMAC_SECRET_MEMBERSHIP'],
|
|
1234
|
-
);
|
|
1235
|
-
assertEquals(
|
|
1236
|
-
keyIsolationViolations({ MEMBER_ASSERTION_SIGNING_KEY: 'same', MEMBER_ACTIONS_HMAC_SECRET: 'same' }),
|
|
1237
|
-
['MEMBER_ASSERTION_SIGNING_KEY==MEMBER_ACTIONS_HMAC_SECRET'],
|
|
1238
|
-
);
|
|
1239
|
-
// All-unset must not report a spurious "everything equals everything".
|
|
1240
|
-
assertEquals(keyIsolationViolations({}), []);
|
|
1241
|
-
});
|
|
1242
|
-
|
|
1243
|
-
Deno.test('canonicalMemberActionMessage: exact 5-line shape, no trailing newline', () => {
|
|
1244
|
-
assertEquals(
|
|
1245
|
-
canonicalMemberActionMessage('unlock', '1788307341', 'aa', 'bb'),
|
|
1246
|
-
'd1\nunlock\n1788307341\naa\nbb',
|
|
1247
|
-
);
|
|
1248
|
-
});
|