@simplelayer/graniteer-core 0.3.18 → 0.3.19-referral.1
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/functions/admin-create-booking.d.ts +0 -3
- package/dist/functions/admin-create-booking.js +2 -15
- package/dist/functions/admin-mark-booking-paid.d.ts +1 -6
- package/dist/functions/admin-mark-booking-paid.js +3 -27
- package/dist/functions/admin-request-trial.js +1 -1
- package/dist/functions/booking-availability.d.ts +1 -2
- package/dist/functions/booking-availability.js +5 -14
- package/dist/functions/create-booking.d.ts +0 -5
- package/dist/functions/create-booking.js +4 -22
- package/dist/functions/create-subscription-checkout.js +4 -1
- package/dist/functions/manage-booking.d.ts +0 -6
- package/dist/functions/manage-booking.js +12 -29
- package/dist/functions/reschedule-booking.d.ts +0 -5
- package/dist/functions/reschedule-booking.js +2 -28
- package/dist/functions/space-availability-range.d.ts +1 -2
- package/dist/functions/space-availability-range.js +1 -8
- package/dist/functions/stripe-webhook.d.ts +0 -4
- package/dist/functions/stripe-webhook.js +9 -182
- package/dist/functions/sync-gcal-blackouts.js +1 -1
- package/dist/gcalSync.d.ts +0 -1
- package/dist/gcalSync.js +0 -5
- package/dist/pricing.d.ts +2 -10
- package/dist/pricing.js +9 -14
- package/dist/referralCodeLookup.d.ts +1 -0
- package/dist/referralCodeLookup.js +3 -0
- package/dist/referralCredits.d.ts +5 -0
- package/dist/referralCredits.js +5 -0
- package/dist/referralGrant.d.ts +4 -31
- package/dist/referralGrant.js +14 -234
- package/package.json +2 -26
- package/dist/bookingSource.d.ts +0 -2
- package/dist/bookingSource.js +0 -11
- package/dist/businessHours.d.ts +0 -11
- package/dist/businessHours.js +0 -55
- package/dist/connectBookingCharge.d.ts +0 -49
- package/dist/connectBookingCharge.js +0 -68
- package/dist/functions/booking-access-revoke-backstop.d.ts +0 -11
- package/dist/functions/booking-access-revoke-backstop.js +0 -121
- package/dist/functions/booking-access-revoke-door-state.d.ts +0 -22
- package/dist/functions/booking-access-revoke-door-state.js +0 -61
- package/dist/functions/booking-access-revoke.d.ts +0 -35
- package/dist/functions/booking-access-revoke.js +0 -279
- package/dist/gcalBookingEvents.d.ts +0 -59
- package/dist/gcalBookingEvents.js +0 -182
- package/dist/stripeConnectEvents.d.ts +0 -11
- package/dist/stripeConnectEvents.js +0 -37
- package/dist/tenant-config.d.ts +0 -8
- package/dist/tenant-config.js +0 -24
|
@@ -6,20 +6,12 @@ import { isDepositOnly, parseTstzRange } from '../bookingEffects.js';
|
|
|
6
6
|
import { extractDoorAccess } from '../busClient.js';
|
|
7
7
|
import { logWelcomeSkipped, WELCOME_OK_STATUSES, } from '../membershipWelcome.js';
|
|
8
8
|
import { sendDunningEmail } from '../dunningEmails.js';
|
|
9
|
-
import { recordReferralFailure
|
|
9
|
+
import { recordReferralFailure } from '../referralGrant.js';
|
|
10
|
+
import { escapeLikePattern } from '../referralCodeLookup.js';
|
|
10
11
|
import { findBaseItem } from '../membershipSubscriptionItems.js';
|
|
11
12
|
import { cancelUnpaidSignedBooking, isSignedUnpaidCancelDue, isCommonsSignedUnpaidPolicyEligible, readCommonsSignedPaymentLinkDryRun } from '../commonsSignedUnpaidCancellation.js';
|
|
12
13
|
import { sendBookingCancelledUnpaidEmailOnce } from '../bookingAgreementEmail.js';
|
|
13
|
-
import { errorNameFromUnknown, revokeBookingOrganizerAccessGrants, shouldRevokeOrganizerGrantsOnStripeChargeRefunded, } from './booking-access-revoke.js';
|
|
14
|
-
import { isValidConnectedAccountId } from '../connectBookingCharge.js';
|
|
15
|
-
import { connectAcceptedOpsKind, gateConnectBookingEvent } from '../stripeConnectEvents.js';
|
|
16
14
|
export function createStripeWebhookHandler(config) {
|
|
17
|
-
return buildStripeWebhookHandler(config, null);
|
|
18
|
-
}
|
|
19
|
-
export function createStripeConnectWebhookHandler(config) {
|
|
20
|
-
return buildStripeWebhookHandler(config, { accountId: config.stripeConnectedAccountId });
|
|
21
|
-
}
|
|
22
|
-
function buildStripeWebhookHandler(config, connect) {
|
|
23
15
|
const { systemActorEmail, dayPassPortalRedirectUrl, teamSeatSlug, virtualOfficeSlug, siteConfig, busProvision, busCancel, notifyGhl, createCalendarEvent, handleCommonsDepositSession, sendVirtualOfficeWelcome, sendMembershipWelcome, sendPrivateOfficeWelcome, loadPrivateOfficeBilling, sendTeamSeatWelcome, maybeActivateAgreement, pacificMidnightUtc, maybeConvertTrialGrant, provisionDayPass, cancelDayPass, } = config;
|
|
24
16
|
// No CORS — this is called by Stripe, not the browser.
|
|
25
17
|
return async (req) => {
|
|
@@ -27,16 +19,11 @@ function buildStripeWebhookHandler(config, connect) {
|
|
|
27
19
|
return new Response('Method not allowed', { status: 405 });
|
|
28
20
|
}
|
|
29
21
|
const stripeKey = Deno.env.get('STRIPE_SECRET_KEY');
|
|
30
|
-
const webhookSecret =
|
|
31
|
-
? Deno.env.get('STRIPE_CONNECT_WEBHOOK_SECRET')
|
|
32
|
-
: Deno.env.get('STRIPE_WEBHOOK_SECRET');
|
|
22
|
+
const webhookSecret = Deno.env.get('STRIPE_WEBHOOK_SECRET');
|
|
33
23
|
if (!stripeKey || !webhookSecret) {
|
|
34
24
|
return new Response('Webhook not configured', { status: 500 });
|
|
35
25
|
}
|
|
36
|
-
|
|
37
|
-
return new Response('Connect webhook not configured', { status: 500 });
|
|
38
|
-
}
|
|
39
|
-
let stripe = new Stripe(stripeKey, { apiVersion: '2024-11-20.acacia' });
|
|
26
|
+
const stripe = new Stripe(stripeKey, { apiVersion: '2024-11-20.acacia' });
|
|
40
27
|
const signature = req.headers.get('stripe-signature');
|
|
41
28
|
if (!signature)
|
|
42
29
|
return new Response('Missing signature', { status: 400 });
|
|
@@ -50,30 +37,6 @@ function buildStripeWebhookHandler(config, connect) {
|
|
|
50
37
|
return new Response('Invalid signature', { status: 400 });
|
|
51
38
|
}
|
|
52
39
|
const supabase = createClient(Deno.env.get('SUPABASE_URL'), Deno.env.get('SUPABASE_SERVICE_ROLE_KEY'));
|
|
53
|
-
if (connect) {
|
|
54
|
-
const connectAccountId = connect.accountId;
|
|
55
|
-
const gate = gateConnectBookingEvent(event, connectAccountId);
|
|
56
|
-
const ignoredReason = 'reason' in gate ? gate.reason : null;
|
|
57
|
-
await logOps(supabase, ignoredReason ? 'stripe_connect_event_ignored' : connectAcceptedOpsKind(event.type), {
|
|
58
|
-
event_id: event.id,
|
|
59
|
-
event_type: event.type,
|
|
60
|
-
connected_account_id: event.account ?? null,
|
|
61
|
-
...(ignoredReason ? { reason: ignoredReason } : {}),
|
|
62
|
-
}, {
|
|
63
|
-
severity: ignoredReason
|
|
64
|
-
? (ignoredReason === 'account_mismatch' ? 'warning' : 'info')
|
|
65
|
-
: (event.type.startsWith('charge.') ? 'warning' : 'info'),
|
|
66
|
-
}).catch(() => { });
|
|
67
|
-
if (ignoredReason) {
|
|
68
|
-
return new Response(JSON.stringify({ received: true, connect_event: true, ignored: ignoredReason }), {
|
|
69
|
-
headers: { 'Content-Type': 'application/json' }, status: 200,
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
stripe = new Stripe(stripeKey, { apiVersion: '2024-11-20.acacia', stripeAccount: connectAccountId });
|
|
73
|
-
// Account already verified above; clear it so the platform-only guard below lets this event reach the shared booking logic.
|
|
74
|
-
// Namespace the id so a platform-endpoint ledger row for the same evt_ can never swallow this delivery as a duplicate.
|
|
75
|
-
event = { ...event, id: `connect:${event.id}`, account: undefined };
|
|
76
|
-
}
|
|
77
40
|
// Idempotency ledger — dedupe Stripe redeliveries.
|
|
78
41
|
{
|
|
79
42
|
const { error: ledgerErr } = await supabase
|
|
@@ -100,101 +63,6 @@ function buildStripeWebhookHandler(config, connect) {
|
|
|
100
63
|
.from('bookings').select('id,status').eq('stripe_session_id', session.id).maybeSingle();
|
|
101
64
|
return data;
|
|
102
65
|
}
|
|
103
|
-
async function findBookingIdByPaymentIntent(paymentIntentId) {
|
|
104
|
-
const { data: rows, error } = await supabase
|
|
105
|
-
.from('bookings')
|
|
106
|
-
.select('id')
|
|
107
|
-
.eq('stripe_payment_intent', paymentIntentId)
|
|
108
|
-
.limit(2);
|
|
109
|
-
if (error) {
|
|
110
|
-
const code = error.code;
|
|
111
|
-
await logOps(supabase, 'booking_access_revoke_booking_lookup_failed', {
|
|
112
|
-
payment_intent_id: paymentIntentId,
|
|
113
|
-
...(typeof code === 'string' ? { error_code: code } : {}),
|
|
114
|
-
}, { severity: 'error', bookingId: null });
|
|
115
|
-
return null;
|
|
116
|
-
}
|
|
117
|
-
const list = (rows ?? []);
|
|
118
|
-
if (list.length > 1) {
|
|
119
|
-
await logOps(supabase, 'booking_access_revoke_booking_lookup_duplicate_pi', {
|
|
120
|
-
payment_intent_id: paymentIntentId,
|
|
121
|
-
match_count: list.length,
|
|
122
|
-
}, { severity: 'error', bookingId: null });
|
|
123
|
-
return null;
|
|
124
|
-
}
|
|
125
|
-
return list[0]?.id ?? null;
|
|
126
|
-
}
|
|
127
|
-
async function releaseStripeEventLedgerForRetry(eventId) {
|
|
128
|
-
const { error } = await supabase.from('stripe_events').delete().eq('event_id', eventId);
|
|
129
|
-
if (error) {
|
|
130
|
-
const code = error.code;
|
|
131
|
-
await logOps(supabase, 'stripe_events_ledger_release_failed', {
|
|
132
|
-
...(typeof code === 'string' ? { error_code: code } : {}),
|
|
133
|
-
}, { severity: 'error' });
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
function webhookResponseMarkerFailedForRetry() {
|
|
137
|
-
return new Response(JSON.stringify({ error: 'booking_access_revoke_marker_failed' }), {
|
|
138
|
-
status: 500,
|
|
139
|
-
headers: { 'Content-Type': 'application/json' },
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
async function maybeRevokeBookingAccessForCharge(charge, reason) {
|
|
143
|
-
const piId = typeof charge.payment_intent === 'string'
|
|
144
|
-
? charge.payment_intent
|
|
145
|
-
: charge.payment_intent?.id ?? null;
|
|
146
|
-
if (!piId)
|
|
147
|
-
return 'skipped';
|
|
148
|
-
let bookingId = null;
|
|
149
|
-
let markerFailed = false;
|
|
150
|
-
try {
|
|
151
|
-
bookingId = await findBookingIdByPaymentIntent(piId);
|
|
152
|
-
if (!bookingId)
|
|
153
|
-
return 'skipped';
|
|
154
|
-
if (connect) {
|
|
155
|
-
// Connect (direct-charge) bookings are refunded outside the app, so
|
|
156
|
-
// nothing cancels the booking: status stays 'paid', the slot stays
|
|
157
|
-
// blocked and door access stays live. Page staff to cancel in admin.
|
|
158
|
-
await logOps(supabase, 'connect_booking_refund_needs_cancel', {
|
|
159
|
-
charge_id: charge.id,
|
|
160
|
-
event_type: event.type,
|
|
161
|
-
reason,
|
|
162
|
-
}, { severity: 'error', bookingId }).catch(() => { });
|
|
163
|
-
}
|
|
164
|
-
const markerAt = new Date().toISOString();
|
|
165
|
-
const { error: markerErr } = await supabase
|
|
166
|
-
.from('bookings')
|
|
167
|
-
.update({ access_revoke_required_at: markerAt })
|
|
168
|
-
.eq('id', bookingId);
|
|
169
|
-
const runInlineRevoke = async () => {
|
|
170
|
-
await revokeBookingOrganizerAccessGrants(supabase, {
|
|
171
|
-
bookingId,
|
|
172
|
-
actingUserId: `system:${systemActorEmail}`,
|
|
173
|
-
reason,
|
|
174
|
-
});
|
|
175
|
-
};
|
|
176
|
-
if (markerErr) {
|
|
177
|
-
markerFailed = true;
|
|
178
|
-
const code = markerErr.code;
|
|
179
|
-
await logOps(supabase, 'booking_access_revoke_marker_failed', {
|
|
180
|
-
...(typeof code === 'string' ? { error_code: code } : {}),
|
|
181
|
-
}, { severity: 'error', bookingId });
|
|
182
|
-
await runInlineRevoke();
|
|
183
|
-
return 'marker_failed';
|
|
184
|
-
}
|
|
185
|
-
await runInlineRevoke();
|
|
186
|
-
return 'ok';
|
|
187
|
-
}
|
|
188
|
-
catch (e) {
|
|
189
|
-
await logOps(supabase, 'booking_access_revoke_step_failed', {
|
|
190
|
-
reason,
|
|
191
|
-
error_name: errorNameFromUnknown(e),
|
|
192
|
-
}, { severity: 'error', bookingId });
|
|
193
|
-
if (markerFailed)
|
|
194
|
-
return 'marker_failed';
|
|
195
|
-
return 'skipped';
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
66
|
// --- Internal coupon helpers (self-serve membership / day-pass checkout) ---
|
|
199
67
|
// create-subscription-checkout and create-day-pass-checkout reserve a
|
|
200
68
|
// coupon_redemptions row at session-creation time and stamp its id onto the
|
|
@@ -587,7 +455,9 @@ function buildStripeWebhookHandler(config, connect) {
|
|
|
587
455
|
const { data: referrer, error: referrerErr } = await supabase
|
|
588
456
|
.from('memberships')
|
|
589
457
|
.select('id')
|
|
590
|
-
.
|
|
458
|
+
.ilike('referral_code', escapeLikePattern(refCode))
|
|
459
|
+
.order('id', { ascending: true })
|
|
460
|
+
.limit(1)
|
|
591
461
|
.maybeSingle();
|
|
592
462
|
if (referrerErr || !referrer)
|
|
593
463
|
return; // unresolvable code -- silently skip, never block signup
|
|
@@ -2052,14 +1922,6 @@ function buildStripeWebhookHandler(config, connect) {
|
|
|
2052
1922
|
console.error('[stripe-webhook] charge.refunded referral clawback step failed', e instanceof Error ? e.message : String(e));
|
|
2053
1923
|
}
|
|
2054
1924
|
}
|
|
2055
|
-
// O3(b): organizer grant revoke on refund — gated by CS-GM partial-refund policy.
|
|
2056
|
-
if (shouldRevokeOrganizerGrantsOnStripeChargeRefunded(charge)) {
|
|
2057
|
-
const markerOutcome = await maybeRevokeBookingAccessForCharge(charge, 'charge_refunded');
|
|
2058
|
-
if (markerOutcome === 'marker_failed') {
|
|
2059
|
-
await releaseStripeEventLedgerForRetry(event.id);
|
|
2060
|
-
return webhookResponseMarkerFailedForRetry();
|
|
2061
|
-
}
|
|
2062
|
-
}
|
|
2063
1925
|
break;
|
|
2064
1926
|
}
|
|
2065
1927
|
case 'charge.dispute.created': {
|
|
@@ -2069,31 +1931,6 @@ function buildStripeWebhookHandler(config, connect) {
|
|
|
2069
1931
|
// charge.dispute.closed below, gated on status === 'lost'.
|
|
2070
1932
|
const dispute = event.data.object;
|
|
2071
1933
|
await logOps(supabase, 'referral_dispute_opened_no_action', { dispute_id: dispute.id, charge: typeof dispute.charge === 'string' ? dispute.charge : dispute.charge?.id ?? null }, { severity: 'warning' }).catch(() => { });
|
|
2072
|
-
// O3(b): chargeback opened — revoke organizer access immediately.
|
|
2073
|
-
let bookingIdForDisputeRevoke = null;
|
|
2074
|
-
try {
|
|
2075
|
-
const chargeId = typeof dispute.charge === 'string' ? dispute.charge : dispute.charge?.id ?? null;
|
|
2076
|
-
if (chargeId) {
|
|
2077
|
-
const charge = await stripe.charges.retrieve(chargeId);
|
|
2078
|
-
const piId = typeof charge.payment_intent === 'string'
|
|
2079
|
-
? charge.payment_intent
|
|
2080
|
-
: charge.payment_intent?.id ?? null;
|
|
2081
|
-
if (piId) {
|
|
2082
|
-
bookingIdForDisputeRevoke = await findBookingIdByPaymentIntent(piId);
|
|
2083
|
-
}
|
|
2084
|
-
const markerOutcome = await maybeRevokeBookingAccessForCharge(charge, 'charge_dispute_created');
|
|
2085
|
-
if (markerOutcome === 'marker_failed') {
|
|
2086
|
-
await releaseStripeEventLedgerForRetry(event.id);
|
|
2087
|
-
return webhookResponseMarkerFailedForRetry();
|
|
2088
|
-
}
|
|
2089
|
-
}
|
|
2090
|
-
}
|
|
2091
|
-
catch (e) {
|
|
2092
|
-
await logOps(supabase, 'booking_access_revoke_step_failed', {
|
|
2093
|
-
reason: 'charge_dispute_created',
|
|
2094
|
-
error_name: errorNameFromUnknown(e),
|
|
2095
|
-
}, { severity: 'error', bookingId: bookingIdForDisputeRevoke });
|
|
2096
|
-
}
|
|
2097
1934
|
break;
|
|
2098
1935
|
}
|
|
2099
1936
|
case 'charge.dispute.closed': {
|
|
@@ -2505,18 +2342,8 @@ function buildStripeWebhookHandler(config, connect) {
|
|
|
2505
2342
|
.select('id');
|
|
2506
2343
|
if (fipErr)
|
|
2507
2344
|
console.warn('[stripe-webhook] first_invoice_paid_at write failed', fipErr);
|
|
2508
|
-
//
|
|
2509
|
-
//
|
|
2510
|
-
// 'subscription_create' -- every other billing_reason
|
|
2511
|
-
// (subscription_cycle after a 100%-off code, a $0 invoice
|
|
2512
|
-
// covered entirely by account balance, etc.) bypasses the
|
|
2513
|
-
// amount check entirely. Gate the referral grant itself on a
|
|
2514
|
-
// genuinely nonzero amount_paid, separately from
|
|
2515
|
-
// first_invoice_paid_at (which has other consumers and should
|
|
2516
|
-
// keep its existing, broader semantics).
|
|
2517
|
-
if (!fipErr && fipRows && fipRows.length > 0 && (inv.amount_paid ?? 0) > 0) {
|
|
2518
|
-
await maybeGrantReferralCredit(supabase, stripe, fipRows[0].id);
|
|
2519
|
-
}
|
|
2345
|
+
// Referral crediting is NOT done here any more: gc-io's
|
|
2346
|
+
// referral-qualify-daily job pays it 30 days after signup.
|
|
2520
2347
|
}
|
|
2521
2348
|
}
|
|
2522
2349
|
break;
|
|
@@ -173,7 +173,7 @@ export async function handle(req) {
|
|
|
173
173
|
const keepIds = new Set();
|
|
174
174
|
for (const ev of events) {
|
|
175
175
|
if (shouldSkipEvent(ev, selfIds)) {
|
|
176
|
-
if (ev.id && (selfIds.has(ev.id) || ev.extendedProperties?.private?.gc_source === 'gc-connect'
|
|
176
|
+
if (ev.id && (selfIds.has(ev.id) || ev.extendedProperties?.private?.gc_source === 'gc-connect')) {
|
|
177
177
|
skippedSelf++;
|
|
178
178
|
}
|
|
179
179
|
continue;
|
package/dist/gcalSync.d.ts
CHANGED
|
@@ -5,7 +5,6 @@ export declare function allDayToUtcRange(startDate: string, endDate: string): {
|
|
|
5
5
|
endIso: string;
|
|
6
6
|
};
|
|
7
7
|
export declare function laMidnightUtc(dateStr: string): Date;
|
|
8
|
-
export declare const CS_BOOKING_ID_KEY = "cs_booking_id";
|
|
9
8
|
export interface GcalEventStartEnd {
|
|
10
9
|
dateTime?: string;
|
|
11
10
|
date?: string;
|
package/dist/gcalSync.js
CHANGED
|
@@ -62,7 +62,6 @@ export function laMidnightUtc(dateStr) {
|
|
|
62
62
|
// Fallback (should not happen for real LA dates).
|
|
63
63
|
return new Date(Date.UTC(y, mo - 1, d, 8, 0));
|
|
64
64
|
}
|
|
65
|
-
export const CS_BOOKING_ID_KEY = 'cs_booking_id';
|
|
66
65
|
// True when this event was created by our own booking system and must NOT be
|
|
67
66
|
// re-imported as a blackout (belt & braces: gc_source marker OR known booking
|
|
68
67
|
// google_event_id). Also drops cancelled and transparent (free) events.
|
|
@@ -76,10 +75,6 @@ export function shouldSkipEvent(ev, selfIds) {
|
|
|
76
75
|
const source = ev.extendedProperties?.private?.gc_source;
|
|
77
76
|
if (source === 'gc-connect')
|
|
78
77
|
return true;
|
|
79
|
-
// Events written back by gcalBookingEvents.ts carry cs_booking_id; importing
|
|
80
|
-
// them as blackouts would make every booking block its own slot.
|
|
81
|
-
if (ev.extendedProperties?.private?.[CS_BOOKING_ID_KEY])
|
|
82
|
-
return true;
|
|
83
78
|
if (selfIds.has(ev.id))
|
|
84
79
|
return true;
|
|
85
80
|
return false;
|
package/dist/pricing.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { SupabaseClient } from '@supabase/supabase-js';
|
|
2
|
-
import type { NoticeConfig } from './businessHours.js';
|
|
3
2
|
type SupabaseLike = SupabaseClient<any, any, any>;
|
|
4
3
|
export interface RoomForPricing {
|
|
5
4
|
id: string;
|
|
@@ -96,8 +95,8 @@ export declare function resolveHalfDayWindow(room: RoomForPricing, dayMode: 'hal
|
|
|
96
95
|
ok: false;
|
|
97
96
|
error: string;
|
|
98
97
|
};
|
|
99
|
-
export declare function validateAndPriceDayBlock(supabase: SupabaseLike, room: RoomForPricing, input: PricingInputDayBlock, nowMs: number
|
|
100
|
-
export declare function validateAndPriceHourly(supabase: SupabaseLike, room: RoomForPricing, input: PricingInputHourly, nowMs: number
|
|
98
|
+
export declare function validateAndPriceDayBlock(supabase: SupabaseLike, room: RoomForPricing, input: PricingInputDayBlock, nowMs: number): Promise<PricingResult>;
|
|
99
|
+
export declare function validateAndPriceHourly(supabase: SupabaseLike, room: RoomForPricing, input: PricingInputHourly, nowMs: number): Promise<PricingResult>;
|
|
101
100
|
/**
|
|
102
101
|
* Entry point: dispatches to hourly or day_block based on room.booking_mode.
|
|
103
102
|
* `quote` rooms cannot be booked via checkout.
|
|
@@ -303,12 +302,5 @@ export declare function validateAndPriceForRoom(supabase: SupabaseLike, room: Ro
|
|
|
303
302
|
discount_cents: number;
|
|
304
303
|
rule_type: string | null;
|
|
305
304
|
};
|
|
306
|
-
/**
|
|
307
|
-
* Optional per-operator minimum-notice config (minNoticeBusinessHours /
|
|
308
|
-
* holidays). Public customer paths (create-booking, reschedule-booking)
|
|
309
|
-
* pass it; staff paths (admin-create-booking) omit it and keep the plain
|
|
310
|
-
* 15-minute floor. Unset => exactly the historical 15-minute floor.
|
|
311
|
-
*/
|
|
312
|
-
notice?: NoticeConfig | null;
|
|
313
305
|
}): Promise<PricingResult>;
|
|
314
306
|
export {};
|
package/dist/pricing.js
CHANGED
|
@@ -6,16 +6,11 @@
|
|
|
6
6
|
// rangeLiteral } describing a fully-validated booking window.
|
|
7
7
|
import { getBusyRangesDetailed } from './availability.js';
|
|
8
8
|
import { logOps } from './ops.js';
|
|
9
|
-
import { DEFAULT_MIN_NOTICE_MS, earliestBookingStartMs, minNoticeErrorMessage } from './businessHours.js';
|
|
10
9
|
// Minimum lead time required between "now" and a booking's start time.
|
|
11
10
|
// Mirrors the same purpose as GHL's `allowBookingAfter` setting on the tour
|
|
12
11
|
// calendars, but for meeting rooms — previously there was no floor at all
|
|
13
12
|
// beyond "not literally in the past" (see 2026-08-25 same-day-tour review).
|
|
14
|
-
const MIN_BOOKING_NOTICE_MS =
|
|
15
|
-
// Earliest allowed start. Unset notice config => exactly now + 15 minutes.
|
|
16
|
-
function noticeFloorMs(nowMs, notice) {
|
|
17
|
-
return notice ? earliestBookingStartMs(nowMs, notice) : nowMs + MIN_BOOKING_NOTICE_MS;
|
|
18
|
-
}
|
|
13
|
+
const MIN_BOOKING_NOTICE_MS = 15 * 60 * 1000;
|
|
19
14
|
function laOffsetHours(atUtc) {
|
|
20
15
|
const parts = new Intl.DateTimeFormat('en-US', {
|
|
21
16
|
timeZone: 'America/Los_Angeles',
|
|
@@ -131,7 +126,7 @@ export function resolveHalfDayWindow(room, dayMode, wd, dateStr, openUtc, closeU
|
|
|
131
126
|
endUtc: laWallToUtc(y, mo, d, Math.floor(endMin / 60), endMin % 60),
|
|
132
127
|
};
|
|
133
128
|
}
|
|
134
|
-
export async function validateAndPriceDayBlock(supabase, room, input, nowMs
|
|
129
|
+
export async function validateAndPriceDayBlock(supabase, room, input, nowMs) {
|
|
135
130
|
const { date, day_mode } = input;
|
|
136
131
|
if (!date || !day_mode)
|
|
137
132
|
return { ok: false, status: 400, error: 'date and day_mode are required for this room' };
|
|
@@ -170,8 +165,8 @@ export async function validateAndPriceDayBlock(supabase, room, input, nowMs, not
|
|
|
170
165
|
endUtc = win.endUtc;
|
|
171
166
|
price_cents = room.half_day_cents;
|
|
172
167
|
}
|
|
173
|
-
if (startUtc.getTime() <
|
|
174
|
-
return { ok: false, status: 400, error:
|
|
168
|
+
if (startUtc.getTime() < nowMs + MIN_BOOKING_NOTICE_MS) {
|
|
169
|
+
return { ok: false, status: 400, error: 'Bookings need at least 15 minutes notice — please choose a later start time.' };
|
|
175
170
|
}
|
|
176
171
|
if (price_cents <= 0)
|
|
177
172
|
return { ok: false, status: 400, error: 'invalid price' };
|
|
@@ -184,7 +179,7 @@ export async function validateAndPriceDayBlock(supabase, room, input, nowMs, not
|
|
|
184
179
|
list_rule_type: null,
|
|
185
180
|
};
|
|
186
181
|
}
|
|
187
|
-
export async function validateAndPriceHourly(supabase, room, input, nowMs
|
|
182
|
+
export async function validateAndPriceHourly(supabase, room, input, nowMs) {
|
|
188
183
|
const { start, end } = input;
|
|
189
184
|
if (!start || !end)
|
|
190
185
|
return { ok: false, status: 400, error: 'start and end are required' };
|
|
@@ -195,8 +190,8 @@ export async function validateAndPriceHourly(supabase, room, input, nowMs, notic
|
|
|
195
190
|
}
|
|
196
191
|
if (!(startUtc < endUtc))
|
|
197
192
|
return { ok: false, status: 400, error: 'end must be after start' };
|
|
198
|
-
if (startUtc.getTime() <
|
|
199
|
-
return { ok: false, status: 400, error:
|
|
193
|
+
if (startUtc.getTime() < nowMs + MIN_BOOKING_NOTICE_MS) {
|
|
194
|
+
return { ok: false, status: 400, error: 'Bookings need at least 15 minutes notice — please choose a later start time.' };
|
|
200
195
|
}
|
|
201
196
|
if (startUtc.getUTCSeconds() !== 0 || startUtc.getUTCMilliseconds() !== 0 ||
|
|
202
197
|
endUtc.getUTCSeconds() !== 0 || endUtc.getUTCMilliseconds() !== 0 ||
|
|
@@ -704,8 +699,8 @@ export async function validateAndPriceForRoom(supabase, room, input, nowMs, opts
|
|
|
704
699
|
}
|
|
705
700
|
const isDayBlock = room.booking_mode === 'day_block';
|
|
706
701
|
const price = () => (isDayBlock
|
|
707
|
-
? validateAndPriceDayBlock(supabase, room, { date: input.date, day_mode: input.day_mode }, nowMs
|
|
708
|
-
: validateAndPriceHourly(supabase, room, { start: input.start, end: input.end }, nowMs
|
|
702
|
+
? validateAndPriceDayBlock(supabase, room, { date: input.date, day_mode: input.day_mode }, nowMs)
|
|
703
|
+
: validateAndPriceHourly(supabase, room, { start: input.start, end: input.end }, nowMs));
|
|
709
704
|
const baseRaw = await price();
|
|
710
705
|
if (!baseRaw.ok)
|
|
711
706
|
return baseRaw;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function escapeLikePattern(input: string): string;
|
|
@@ -2,4 +2,9 @@ export interface ReferralCredits {
|
|
|
2
2
|
referrerCents: number;
|
|
3
3
|
referredCents: number;
|
|
4
4
|
}
|
|
5
|
+
/**
|
|
6
|
+
* @deprecated gc-io's referralQualify owns the referral credit formula now
|
|
7
|
+
* (50% of the referred member's first-month price, floored). Retained
|
|
8
|
+
* unchanged for published-package compatibility.
|
|
9
|
+
*/
|
|
5
10
|
export declare function computeReferralCredits(planPriceCents: number, isPrivateOffice: boolean): ReferralCredits;
|
package/dist/referralCredits.js
CHANGED
|
@@ -13,6 +13,11 @@
|
|
|
13
13
|
// price + a private-office flag into two credit amounts.
|
|
14
14
|
const PRIVATE_OFFICE_REFERRER_CENTS = 30000; // flat $300
|
|
15
15
|
const MIN_CREDIT_CENTS = 2500; // $25 floor on both sides
|
|
16
|
+
/**
|
|
17
|
+
* @deprecated gc-io's referralQualify owns the referral credit formula now
|
|
18
|
+
* (50% of the referred member's first-month price, floored). Retained
|
|
19
|
+
* unchanged for published-package compatibility.
|
|
20
|
+
*/
|
|
16
21
|
export function computeReferralCredits(planPriceCents, isPrivateOffice) {
|
|
17
22
|
const referrerCents = isPrivateOffice
|
|
18
23
|
? PRIVATE_OFFICE_REFERRER_CENTS
|
package/dist/referralGrant.d.ts
CHANGED
|
@@ -14,36 +14,9 @@ type SupabaseLike = SupabaseClient<any, 'public', any>;
|
|
|
14
14
|
*/
|
|
15
15
|
export declare function recordReferralFailure(supabase: SupabaseLike, referralId: string, fromStatus: 'signed_up' | 'grant_failed' | 'credited', toStatus: 'grant_failed' | 'clawback_failed', error: unknown): Promise<void>;
|
|
16
16
|
/**
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* swap in the invoice.paid handler actually affected a row (genuinely the
|
|
21
|
-
* first real paid invoice for this membership) -- that call passes no
|
|
22
|
-
* `fromStatuses` override, so it only ever matches a 'signed_up' row.
|
|
23
|
-
*
|
|
24
|
-
* admin-referral-retry calls this SAME function with
|
|
25
|
-
* `fromStatuses: ['grant_failed']` to retry a previously-failed grant --
|
|
26
|
-
* see that function's own header comment for why it gates on the referred
|
|
27
|
-
* membership's live status first, and why it does NOT reset the row to
|
|
28
|
-
* 'signed_up' before calling this (that reset-then-call shape was tried and
|
|
29
|
-
* reverted after a second-model review found it opened a stranded-row
|
|
30
|
-
* window and a same-row race between two concurrent retries).
|
|
31
|
-
*
|
|
32
|
-
* Computes real credit amounts, grants a NEGATIVE Stripe Customer Balance
|
|
33
|
-
* Transaction (a credit) on each of the two Stripe customers, and marks the
|
|
34
|
-
* referral 'credited'.
|
|
35
|
-
*
|
|
36
|
-
* Entirely wrapped in try/catch and logs with the referral id on failure --
|
|
37
|
-
* a Stripe failure here must never break invoice.paid processing for an
|
|
38
|
-
* unrelated membership.
|
|
39
|
-
*
|
|
40
|
-
* IDEMPOTENT BY DESIGN -- this is also what makes it safe for
|
|
41
|
-
* admin-referral-retry to call again on a grant_failed row: before each
|
|
42
|
-
* Stripe call it checks whether this referral already has a txn id
|
|
43
|
-
* persisted, and each Stripe call carries a fixed idempotency key derived
|
|
44
|
-
* from the referral id, so a retry only attempts whichever side didn't
|
|
45
|
-
* already complete. Never write a second, separate recovery path -- retry
|
|
46
|
-
* by calling this function again.
|
|
17
|
+
* @deprecated SUPERSEDED -- no-op. Crediting is owned by gc-io's
|
|
18
|
+
* referral-qualify-daily job (30 days after signup). Never touches Stripe or
|
|
19
|
+
* the database; signature kept for published-package compatibility.
|
|
47
20
|
*/
|
|
48
|
-
export declare function maybeGrantReferralCredit(
|
|
21
|
+
export declare function maybeGrantReferralCredit(_supabase: SupabaseLike, _stripe: Stripe, referredMembershipId: string, _fromStatuses?: readonly ('signed_up' | 'grant_failed')[]): Promise<void>;
|
|
49
22
|
export {};
|