@simplelayer/graniteer-core 0.3.15 → 0.3.18
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/bookingAgreementEmail.d.ts +34 -3
- package/dist/bookingAgreementEmail.js +100 -1
- package/dist/bookingEffects.d.ts +2 -0
- package/dist/bookingEffects.js +4 -3
- package/dist/bookingSource.d.ts +2 -0
- package/dist/bookingSource.js +11 -0
- package/dist/businessHours.d.ts +11 -0
- package/dist/businessHours.js +55 -0
- package/dist/checkoutSessionParams.d.ts +33 -0
- package/dist/checkoutSessionParams.js +71 -0
- package/dist/commonsSignedUnpaidCancellation.d.ts +154 -0
- package/dist/commonsSignedUnpaidCancellation.js +650 -0
- package/dist/connectBookingCharge.d.ts +49 -0
- package/dist/connectBookingCharge.js +68 -0
- package/dist/functions/admin-create-booking.d.ts +3 -0
- package/dist/functions/admin-create-booking.js +15 -2
- package/dist/functions/admin-mark-booking-paid.d.ts +6 -1
- package/dist/functions/admin-mark-booking-paid.js +27 -3
- package/dist/functions/booking-access-revoke-backstop.d.ts +11 -0
- package/dist/functions/booking-access-revoke-backstop.js +121 -0
- package/dist/functions/booking-access-revoke-door-state.d.ts +22 -0
- package/dist/functions/booking-access-revoke-door-state.js +61 -0
- package/dist/functions/booking-access-revoke.d.ts +35 -0
- package/dist/functions/booking-access-revoke.js +279 -0
- package/dist/functions/booking-availability.d.ts +2 -1
- package/dist/functions/booking-availability.js +14 -5
- package/dist/functions/create-booking.d.ts +5 -0
- package/dist/functions/create-booking.js +22 -4
- package/dist/functions/manage-booking.d.ts +6 -0
- package/dist/functions/manage-booking.js +29 -12
- package/dist/functions/reschedule-booking.d.ts +5 -0
- package/dist/functions/reschedule-booking.js +28 -2
- package/dist/functions/space-availability-range.d.ts +2 -1
- package/dist/functions/space-availability-range.js +8 -1
- package/dist/functions/stripe-webhook.d.ts +4 -0
- package/dist/functions/stripe-webhook.js +270 -2
- package/dist/functions/sync-gcal-blackouts.js +1 -1
- package/dist/gcalBookingEvents.d.ts +59 -0
- package/dist/gcalBookingEvents.js +182 -0
- package/dist/gcalSync.d.ts +1 -0
- package/dist/gcalSync.js +5 -0
- package/dist/pricing.d.ts +10 -2
- package/dist/pricing.js +14 -9
- package/dist/stripeConnectEvents.d.ts +11 -0
- package/dist/stripeConnectEvents.js +37 -0
- package/dist/supabaseTestFakes.js +7 -1
- package/dist/tenant-config.d.ts +8 -0
- package/dist/tenant-config.js +24 -0
- package/package.json +30 -2
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { JWT } from 'google-auth-library';
|
|
2
|
+
import { parsePgRange } from './availability.js';
|
|
3
|
+
import { CS_BOOKING_ID_KEY } from './gcalSync.js';
|
|
4
|
+
const EVENTS_SCOPE = 'https://www.googleapis.com/auth/calendar.events';
|
|
5
|
+
const CAL_BASE = 'https://www.googleapis.com/calendar/v3/calendars';
|
|
6
|
+
const TZ = 'America/Los_Angeles';
|
|
7
|
+
// Deterministic id (Google allows client ids of [a-v0-9], 5-1024 chars; a UUID's
|
|
8
|
+
// hex digits qualify) so create is idempotent and update/delete need no stored id.
|
|
9
|
+
export function eventIdForBooking(bookingId) {
|
|
10
|
+
return `csb${bookingId.replace(/-/g, '').toLowerCase()}`;
|
|
11
|
+
}
|
|
12
|
+
async function defaultGetAccessToken() {
|
|
13
|
+
const clientEmail = Deno.env.get('GOOGLE_SA_CLIENT_EMAIL');
|
|
14
|
+
const rawKey = Deno.env.get('GOOGLE_SA_PRIVATE_KEY');
|
|
15
|
+
if (!clientEmail || !rawKey)
|
|
16
|
+
return null;
|
|
17
|
+
const jwt = new JWT({ email: clientEmail, key: rawKey.replace(/\\n/g, '\n'), scopes: [EVENTS_SCOPE] });
|
|
18
|
+
const tok = await jwt.getAccessToken();
|
|
19
|
+
return tok?.token ?? null;
|
|
20
|
+
}
|
|
21
|
+
function eventBody(input, includeId) {
|
|
22
|
+
return {
|
|
23
|
+
...(includeId ? { id: eventIdForBooking(input.bookingId) } : {}),
|
|
24
|
+
summary: input.summary,
|
|
25
|
+
description: input.description,
|
|
26
|
+
location: input.location,
|
|
27
|
+
start: { dateTime: input.startIso, timeZone: TZ },
|
|
28
|
+
end: { dateTime: input.endIso, timeZone: TZ },
|
|
29
|
+
transparency: 'opaque',
|
|
30
|
+
extendedProperties: { private: { [CS_BOOKING_ID_KEY]: input.bookingId } },
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
async function call(method, calendarId, eventId, body, deps) {
|
|
34
|
+
const token = await (deps.getAccessToken ?? defaultGetAccessToken)();
|
|
35
|
+
if (!token)
|
|
36
|
+
return { noToken: true, status: 0 };
|
|
37
|
+
const url = `${CAL_BASE}/${encodeURIComponent(calendarId)}/events${eventId ? `/${encodeURIComponent(eventId)}` : ''}`;
|
|
38
|
+
const res = await (deps.fetch ?? fetch)(url, {
|
|
39
|
+
method,
|
|
40
|
+
headers: {
|
|
41
|
+
Authorization: `Bearer ${token}`,
|
|
42
|
+
...(body ? { 'Content-Type': 'application/json' } : {}),
|
|
43
|
+
},
|
|
44
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
45
|
+
signal: AbortSignal.timeout(15000),
|
|
46
|
+
});
|
|
47
|
+
return { noToken: false, status: res.status };
|
|
48
|
+
}
|
|
49
|
+
const isOk = (s) => s >= 200 && s < 300;
|
|
50
|
+
const noCreds = { ok: false, reason: 'no_credentials' };
|
|
51
|
+
const httpFail = (status) => ({ ok: false, reason: 'http_error', status });
|
|
52
|
+
export async function createBookingEvent(input, deps = {}) {
|
|
53
|
+
if (!input.calendarId)
|
|
54
|
+
return { ok: false, reason: 'no_calendar' };
|
|
55
|
+
try {
|
|
56
|
+
const eventId = eventIdForBooking(input.bookingId);
|
|
57
|
+
const r = await call('POST', input.calendarId, null, eventBody(input, true), deps);
|
|
58
|
+
if (r.noToken)
|
|
59
|
+
return noCreds;
|
|
60
|
+
if (isOk(r.status))
|
|
61
|
+
return { ok: true, eventId, action: 'created' };
|
|
62
|
+
// Deterministic id already exists (retry / duplicate delivery): converge via update.
|
|
63
|
+
if (r.status === 409)
|
|
64
|
+
return await updateBookingEvent(input, deps);
|
|
65
|
+
return httpFail(r.status);
|
|
66
|
+
}
|
|
67
|
+
catch (e) {
|
|
68
|
+
return { ok: false, reason: 'exception', detail: String(e) };
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
export async function updateBookingEvent(input, deps = {}) {
|
|
72
|
+
if (!input.calendarId)
|
|
73
|
+
return { ok: false, reason: 'no_calendar' };
|
|
74
|
+
try {
|
|
75
|
+
const eventId = eventIdForBooking(input.bookingId);
|
|
76
|
+
const r = await call('PATCH', input.calendarId, eventId, eventBody(input, false), deps);
|
|
77
|
+
if (r.noToken)
|
|
78
|
+
return noCreds;
|
|
79
|
+
if (isOk(r.status))
|
|
80
|
+
return { ok: true, eventId, action: 'updated' };
|
|
81
|
+
if (r.status === 404) {
|
|
82
|
+
const c = await call('POST', input.calendarId, null, eventBody(input, true), deps);
|
|
83
|
+
if (c.noToken)
|
|
84
|
+
return noCreds;
|
|
85
|
+
return isOk(c.status) ? { ok: true, eventId, action: 'created' } : httpFail(c.status);
|
|
86
|
+
}
|
|
87
|
+
return httpFail(r.status);
|
|
88
|
+
}
|
|
89
|
+
catch (e) {
|
|
90
|
+
return { ok: false, reason: 'exception', detail: String(e) };
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
export async function deleteBookingEvent(calendarId, bookingId, deps = {}) {
|
|
94
|
+
if (!calendarId)
|
|
95
|
+
return { ok: false, reason: 'no_calendar' };
|
|
96
|
+
try {
|
|
97
|
+
const eventId = eventIdForBooking(bookingId);
|
|
98
|
+
const r = await call('DELETE', calendarId, eventId, null, deps);
|
|
99
|
+
if (r.noToken)
|
|
100
|
+
return noCreds;
|
|
101
|
+
if (isOk(r.status))
|
|
102
|
+
return { ok: true, eventId, action: 'deleted' };
|
|
103
|
+
if (r.status === 404 || r.status === 410)
|
|
104
|
+
return { ok: true, eventId, action: 'already_absent' };
|
|
105
|
+
return httpFail(r.status);
|
|
106
|
+
}
|
|
107
|
+
catch (e) {
|
|
108
|
+
return { ok: false, reason: 'exception', detail: String(e) };
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
export function isGcalWritebackEnabled(operator) {
|
|
112
|
+
return operator?.googleCalendarWriteback === true;
|
|
113
|
+
}
|
|
114
|
+
export function bookingRowToEventInput(row) {
|
|
115
|
+
const calendarId = row.rooms?.google_calendar_id;
|
|
116
|
+
const range = parsePgRange(row.during);
|
|
117
|
+
if (!calendarId || !range)
|
|
118
|
+
return null;
|
|
119
|
+
const who = row.contact_name || row.contact_email || 'Guest';
|
|
120
|
+
const lines = [
|
|
121
|
+
row.contact_name ? `Name: ${row.contact_name}` : null,
|
|
122
|
+
row.contact_email ? `Email: ${row.contact_email}` : null,
|
|
123
|
+
row.contact_phone ? `Phone: ${row.contact_phone}` : null,
|
|
124
|
+
`Booking: ${row.id}`,
|
|
125
|
+
].filter(Boolean);
|
|
126
|
+
return {
|
|
127
|
+
calendarId,
|
|
128
|
+
bookingId: row.id,
|
|
129
|
+
startIso: new Date(range[0]).toISOString(),
|
|
130
|
+
endIso: new Date(range[1]).toISOString(),
|
|
131
|
+
summary: `${row.rooms?.name ?? 'Booking'} — ${who}`,
|
|
132
|
+
description: lines.join('\n'),
|
|
133
|
+
location: row.rooms?.address ?? undefined,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
const defaultLog = (m, d) => console.warn(m, d);
|
|
137
|
+
/**
|
|
138
|
+
* Fail-soft create for a paid booking row. Never throws; returns null when the
|
|
139
|
+
* operator flag is off (the default), so callers can invoke it unconditionally.
|
|
140
|
+
*/
|
|
141
|
+
export async function writebackBookingCreated(operator, row, deps = {}, log = defaultLog) {
|
|
142
|
+
if (!isGcalWritebackEnabled(operator))
|
|
143
|
+
return null;
|
|
144
|
+
try {
|
|
145
|
+
const input = bookingRowToEventInput(row);
|
|
146
|
+
if (!input)
|
|
147
|
+
return { ok: false, reason: 'no_calendar' };
|
|
148
|
+
const res = await createBookingEvent(input, deps);
|
|
149
|
+
if (!res.ok)
|
|
150
|
+
log('[gcalBookingEvents] create failed', { bookingId: row.id, ...res });
|
|
151
|
+
return res;
|
|
152
|
+
}
|
|
153
|
+
catch (e) {
|
|
154
|
+
log('[gcalBookingEvents] create threw', { bookingId: row.id, error: String(e) });
|
|
155
|
+
return { ok: false, reason: 'exception', detail: String(e) };
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
export async function writebackBookingCancelled(operator, calendarId, bookingId, deps = {}, log = defaultLog) {
|
|
159
|
+
if (!isGcalWritebackEnabled(operator))
|
|
160
|
+
return null;
|
|
161
|
+
try {
|
|
162
|
+
const res = await deleteBookingEvent(calendarId, bookingId, deps);
|
|
163
|
+
if (!res.ok)
|
|
164
|
+
log('[gcalBookingEvents] delete failed', { bookingId, ...res });
|
|
165
|
+
return res;
|
|
166
|
+
}
|
|
167
|
+
catch (e) {
|
|
168
|
+
log('[gcalBookingEvents] delete threw', { bookingId, error: String(e) });
|
|
169
|
+
return { ok: false, reason: 'exception', detail: String(e) };
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Adapter matching the `createCalendarEvent` dep shape used by create-booking,
|
|
174
|
+
* admin-create-booking, reschedule-booking and stripe-webhook. A tenant wrapper
|
|
175
|
+
* without door hardware can pass this as that dep; it is the only way to cover
|
|
176
|
+
* stripe-webhook's paid path without editing the webhook.
|
|
177
|
+
*/
|
|
178
|
+
export function makeWritebackCreateCalendarEvent(operator, deps = {}) {
|
|
179
|
+
return async (_admin, row) => {
|
|
180
|
+
await writebackBookingCreated(operator, row, deps);
|
|
181
|
+
};
|
|
182
|
+
}
|
package/dist/gcalSync.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ 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";
|
|
8
9
|
export interface GcalEventStartEnd {
|
|
9
10
|
dateTime?: string;
|
|
10
11
|
date?: string;
|
package/dist/gcalSync.js
CHANGED
|
@@ -62,6 +62,7 @@ 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';
|
|
65
66
|
// True when this event was created by our own booking system and must NOT be
|
|
66
67
|
// re-imported as a blackout (belt & braces: gc_source marker OR known booking
|
|
67
68
|
// google_event_id). Also drops cancelled and transparent (free) events.
|
|
@@ -75,6 +76,10 @@ export function shouldSkipEvent(ev, selfIds) {
|
|
|
75
76
|
const source = ev.extendedProperties?.private?.gc_source;
|
|
76
77
|
if (source === 'gc-connect')
|
|
77
78
|
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;
|
|
78
83
|
if (selfIds.has(ev.id))
|
|
79
84
|
return true;
|
|
80
85
|
return false;
|
package/dist/pricing.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { SupabaseClient } from '@supabase/supabase-js';
|
|
2
|
+
import type { NoticeConfig } from './businessHours.js';
|
|
2
3
|
type SupabaseLike = SupabaseClient<any, any, any>;
|
|
3
4
|
export interface RoomForPricing {
|
|
4
5
|
id: string;
|
|
@@ -95,8 +96,8 @@ export declare function resolveHalfDayWindow(room: RoomForPricing, dayMode: 'hal
|
|
|
95
96
|
ok: false;
|
|
96
97
|
error: string;
|
|
97
98
|
};
|
|
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>;
|
|
99
|
+
export declare function validateAndPriceDayBlock(supabase: SupabaseLike, room: RoomForPricing, input: PricingInputDayBlock, nowMs: number, notice?: NoticeConfig | null): Promise<PricingResult>;
|
|
100
|
+
export declare function validateAndPriceHourly(supabase: SupabaseLike, room: RoomForPricing, input: PricingInputHourly, nowMs: number, notice?: NoticeConfig | null): Promise<PricingResult>;
|
|
100
101
|
/**
|
|
101
102
|
* Entry point: dispatches to hourly or day_block based on room.booking_mode.
|
|
102
103
|
* `quote` rooms cannot be booked via checkout.
|
|
@@ -302,5 +303,12 @@ export declare function validateAndPriceForRoom(supabase: SupabaseLike, room: Ro
|
|
|
302
303
|
discount_cents: number;
|
|
303
304
|
rule_type: string | null;
|
|
304
305
|
};
|
|
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;
|
|
305
313
|
}): Promise<PricingResult>;
|
|
306
314
|
export {};
|
package/dist/pricing.js
CHANGED
|
@@ -6,11 +6,16 @@
|
|
|
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';
|
|
9
10
|
// Minimum lead time required between "now" and a booking's start time.
|
|
10
11
|
// Mirrors the same purpose as GHL's `allowBookingAfter` setting on the tour
|
|
11
12
|
// calendars, but for meeting rooms — previously there was no floor at all
|
|
12
13
|
// beyond "not literally in the past" (see 2026-08-25 same-day-tour review).
|
|
13
|
-
const MIN_BOOKING_NOTICE_MS =
|
|
14
|
+
const MIN_BOOKING_NOTICE_MS = DEFAULT_MIN_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
|
+
}
|
|
14
19
|
function laOffsetHours(atUtc) {
|
|
15
20
|
const parts = new Intl.DateTimeFormat('en-US', {
|
|
16
21
|
timeZone: 'America/Los_Angeles',
|
|
@@ -126,7 +131,7 @@ export function resolveHalfDayWindow(room, dayMode, wd, dateStr, openUtc, closeU
|
|
|
126
131
|
endUtc: laWallToUtc(y, mo, d, Math.floor(endMin / 60), endMin % 60),
|
|
127
132
|
};
|
|
128
133
|
}
|
|
129
|
-
export async function validateAndPriceDayBlock(supabase, room, input, nowMs) {
|
|
134
|
+
export async function validateAndPriceDayBlock(supabase, room, input, nowMs, notice) {
|
|
130
135
|
const { date, day_mode } = input;
|
|
131
136
|
if (!date || !day_mode)
|
|
132
137
|
return { ok: false, status: 400, error: 'date and day_mode are required for this room' };
|
|
@@ -165,8 +170,8 @@ export async function validateAndPriceDayBlock(supabase, room, input, nowMs) {
|
|
|
165
170
|
endUtc = win.endUtc;
|
|
166
171
|
price_cents = room.half_day_cents;
|
|
167
172
|
}
|
|
168
|
-
if (startUtc.getTime() < nowMs
|
|
169
|
-
return { ok: false, status: 400, error:
|
|
173
|
+
if (startUtc.getTime() < noticeFloorMs(nowMs, notice)) {
|
|
174
|
+
return { ok: false, status: 400, error: minNoticeErrorMessage(nowMs, notice) };
|
|
170
175
|
}
|
|
171
176
|
if (price_cents <= 0)
|
|
172
177
|
return { ok: false, status: 400, error: 'invalid price' };
|
|
@@ -179,7 +184,7 @@ export async function validateAndPriceDayBlock(supabase, room, input, nowMs) {
|
|
|
179
184
|
list_rule_type: null,
|
|
180
185
|
};
|
|
181
186
|
}
|
|
182
|
-
export async function validateAndPriceHourly(supabase, room, input, nowMs) {
|
|
187
|
+
export async function validateAndPriceHourly(supabase, room, input, nowMs, notice) {
|
|
183
188
|
const { start, end } = input;
|
|
184
189
|
if (!start || !end)
|
|
185
190
|
return { ok: false, status: 400, error: 'start and end are required' };
|
|
@@ -190,8 +195,8 @@ export async function validateAndPriceHourly(supabase, room, input, nowMs) {
|
|
|
190
195
|
}
|
|
191
196
|
if (!(startUtc < endUtc))
|
|
192
197
|
return { ok: false, status: 400, error: 'end must be after start' };
|
|
193
|
-
if (startUtc.getTime() < nowMs
|
|
194
|
-
return { ok: false, status: 400, error:
|
|
198
|
+
if (startUtc.getTime() < noticeFloorMs(nowMs, notice)) {
|
|
199
|
+
return { ok: false, status: 400, error: minNoticeErrorMessage(nowMs, notice) };
|
|
195
200
|
}
|
|
196
201
|
if (startUtc.getUTCSeconds() !== 0 || startUtc.getUTCMilliseconds() !== 0 ||
|
|
197
202
|
endUtc.getUTCSeconds() !== 0 || endUtc.getUTCMilliseconds() !== 0 ||
|
|
@@ -699,8 +704,8 @@ export async function validateAndPriceForRoom(supabase, room, input, nowMs, opts
|
|
|
699
704
|
}
|
|
700
705
|
const isDayBlock = room.booking_mode === 'day_block';
|
|
701
706
|
const price = () => (isDayBlock
|
|
702
|
-
? validateAndPriceDayBlock(supabase, room, { date: input.date, day_mode: input.day_mode }, nowMs)
|
|
703
|
-
: validateAndPriceHourly(supabase, room, { start: input.start, end: input.end }, nowMs));
|
|
707
|
+
? validateAndPriceDayBlock(supabase, room, { date: input.date, day_mode: input.day_mode }, nowMs, opts.notice)
|
|
708
|
+
: validateAndPriceHourly(supabase, room, { start: input.start, end: input.end }, nowMs, opts.notice));
|
|
704
709
|
const baseRaw = await price();
|
|
705
710
|
if (!baseRaw.ok)
|
|
706
711
|
return baseRaw;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type Stripe from 'stripe';
|
|
2
|
+
export declare const CONNECT_BOOKING_EVENT_TYPES: ReadonlySet<string>;
|
|
3
|
+
export type ConnectGateReason = 'not_connect_event' | 'account_mismatch' | 'event_type_not_handled' | 'not_a_booking_session';
|
|
4
|
+
export type ConnectGateResult = {
|
|
5
|
+
accept: true;
|
|
6
|
+
} | {
|
|
7
|
+
accept: false;
|
|
8
|
+
reason: ConnectGateReason;
|
|
9
|
+
};
|
|
10
|
+
export declare function gateConnectBookingEvent(event: Pick<Stripe.Event, 'type' | 'account' | 'data'>, operatorAccountId: string): ConnectGateResult;
|
|
11
|
+
export declare function connectAcceptedOpsKind(eventType: string): string;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// Gate for the Stripe Connect webhook endpoint (createStripeConnectWebhookHandler).
|
|
2
|
+
// Pure: decides whether a verified connected-account event may enter the shared
|
|
3
|
+
// booking logic in stripe-webhook.ts.
|
|
4
|
+
export const CONNECT_BOOKING_EVENT_TYPES = new Set([
|
|
5
|
+
'checkout.session.completed',
|
|
6
|
+
'checkout.session.expired',
|
|
7
|
+
'checkout.session.async_payment_failed',
|
|
8
|
+
'payment_intent.payment_failed',
|
|
9
|
+
'charge.refunded',
|
|
10
|
+
'charge.dispute.created',
|
|
11
|
+
'charge.dispute.closed',
|
|
12
|
+
]);
|
|
13
|
+
export function gateConnectBookingEvent(event, operatorAccountId) {
|
|
14
|
+
const acct = event.account;
|
|
15
|
+
if (typeof acct !== 'string' || acct.length === 0)
|
|
16
|
+
return { accept: false, reason: 'not_connect_event' };
|
|
17
|
+
if (acct !== operatorAccountId)
|
|
18
|
+
return { accept: false, reason: 'account_mismatch' };
|
|
19
|
+
if (!CONNECT_BOOKING_EVENT_TYPES.has(event.type))
|
|
20
|
+
return { accept: false, reason: 'event_type_not_handled' };
|
|
21
|
+
if (event.type.startsWith('checkout.session.')) {
|
|
22
|
+
const s = event.data?.object;
|
|
23
|
+
const md = (s?.metadata ?? {});
|
|
24
|
+
const bookingId = md.booking_id;
|
|
25
|
+
if (typeof bookingId !== 'string' || bookingId.length === 0 ||
|
|
26
|
+
md.checkout_type !== undefined || md.payment_type !== undefined ||
|
|
27
|
+
s?.mode === 'subscription') {
|
|
28
|
+
return { accept: false, reason: 'not_a_booking_session' };
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return { accept: true };
|
|
32
|
+
}
|
|
33
|
+
export function connectAcceptedOpsKind(eventType) {
|
|
34
|
+
return eventType.startsWith('charge.')
|
|
35
|
+
? 'stripe_connect_charge_refund_or_dispute'
|
|
36
|
+
: 'stripe_connect_event_accepted';
|
|
37
|
+
}
|
|
@@ -18,7 +18,13 @@ class FakeQuery {
|
|
|
18
18
|
this.responder = responder;
|
|
19
19
|
this.log = log;
|
|
20
20
|
}
|
|
21
|
-
select(
|
|
21
|
+
// `.update(...).select(...)` must stay op `update`; only a bare chain starts as select.
|
|
22
|
+
select(columns) {
|
|
23
|
+
if (this.rec.op === 'none')
|
|
24
|
+
this.rec.op = 'select';
|
|
25
|
+
this.rec.columns = columns;
|
|
26
|
+
return this;
|
|
27
|
+
}
|
|
22
28
|
insert(payload) { this.rec.op = 'insert'; this.rec.payload = payload; return this; }
|
|
23
29
|
update(payload) { this.rec.op = 'update'; this.rec.payload = payload; return this; }
|
|
24
30
|
delete() { this.rec.op = 'delete'; return this; }
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base origin of this tenant's membership/event-access middleware (the
|
|
3
|
+
* "ftw-middleware"-equivalent service that signs/serves door credentials,
|
|
4
|
+
* organizer links, and grant revokes). No trailing slash.
|
|
5
|
+
*
|
|
6
|
+
* Env var: EVENT_ACCESS_BUS_BASE
|
|
7
|
+
*/
|
|
8
|
+
export declare function getEventAccessBusBase(): string;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// Centralized tenant-scoped configuration for the handful of values that
|
|
2
|
+
// historically were hardcoded to Granite City Workspaces' own infrastructure
|
|
3
|
+
// instead of being dependency-injected like the rest of the operator identity
|
|
4
|
+
// (GHL_LOCATION_ID, OPERATOR/siteConfig objects, Stripe keys, etc. -- see
|
|
5
|
+
// docs/resale/TENANT-AUDIT.md). Every constant here is backed by an env var,
|
|
6
|
+
// documented in .env.tenant.example at the repo root. When an env var is
|
|
7
|
+
// unset, the fallback is Granite City's current production value, so existing
|
|
8
|
+
// deployments keep working unchanged until their env is configured.
|
|
9
|
+
//
|
|
10
|
+
// Most tenant identity in this codebase is injected by the caller (the
|
|
11
|
+
// gc-connect-style wrapper that imports this package) rather than read from
|
|
12
|
+
// env here. This module exists only for the small number of call sites
|
|
13
|
+
// (manage-booking.ts, booking-access-revoke.ts) that don't already receive a
|
|
14
|
+
// busBase-shaped config object from their caller.
|
|
15
|
+
/**
|
|
16
|
+
* Base origin of this tenant's membership/event-access middleware (the
|
|
17
|
+
* "ftw-middleware"-equivalent service that signs/serves door credentials,
|
|
18
|
+
* organizer links, and grant revokes). No trailing slash.
|
|
19
|
+
*
|
|
20
|
+
* Env var: EVENT_ACCESS_BUS_BASE
|
|
21
|
+
*/
|
|
22
|
+
export function getEventAccessBusBase() {
|
|
23
|
+
return Deno.env.get('EVENT_ACCESS_BUS_BASE') ?? 'https://ftw.granitecity.io';
|
|
24
|
+
}
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@simplelayer/graniteer-core",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.18",
|
|
4
4
|
"description": "Shared platform core for Graniteer",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
|
-
"test": "deno test --no-check --node-modules-dir=auto --allow-env --allow-net --allow-read src",
|
|
8
|
+
"test": "deno test --config deno.test.json --no-check --node-modules-dir=auto --allow-env --allow-net --allow-read src",
|
|
9
9
|
"build": "node scripts/build.mjs",
|
|
10
10
|
"verify:dist": "node scripts/verify-dist.mjs",
|
|
11
11
|
"prepack": "npm run build && npm run verify:dist",
|
|
@@ -117,6 +117,10 @@
|
|
|
117
117
|
"types": "./dist/commonsDepositWebhook.d.ts",
|
|
118
118
|
"default": "./dist/commonsDepositWebhook.js"
|
|
119
119
|
},
|
|
120
|
+
"./commonsSignedUnpaidCancellation": {
|
|
121
|
+
"types": "./dist/commonsSignedUnpaidCancellation.d.ts",
|
|
122
|
+
"default": "./dist/commonsSignedUnpaidCancellation.js"
|
|
123
|
+
},
|
|
120
124
|
"./conductorAdmin": {
|
|
121
125
|
"types": "./dist/conductorAdmin.d.ts",
|
|
122
126
|
"default": "./dist/conductorAdmin.js"
|
|
@@ -153,6 +157,26 @@
|
|
|
153
157
|
"types": "./dist/email-templates/signup.d.ts",
|
|
154
158
|
"default": "./dist/email-templates/signup.js"
|
|
155
159
|
},
|
|
160
|
+
"./bookingSource": {
|
|
161
|
+
"types": "./dist/bookingSource.d.ts",
|
|
162
|
+
"default": "./dist/bookingSource.js"
|
|
163
|
+
},
|
|
164
|
+
"./businessHours": {
|
|
165
|
+
"types": "./dist/businessHours.d.ts",
|
|
166
|
+
"default": "./dist/businessHours.js"
|
|
167
|
+
},
|
|
168
|
+
"./gcalBookingEvents": {
|
|
169
|
+
"types": "./dist/gcalBookingEvents.d.ts",
|
|
170
|
+
"default": "./dist/gcalBookingEvents.js"
|
|
171
|
+
},
|
|
172
|
+
"./connectBookingCharge": {
|
|
173
|
+
"types": "./dist/connectBookingCharge.d.ts",
|
|
174
|
+
"default": "./dist/connectBookingCharge.js"
|
|
175
|
+
},
|
|
176
|
+
"./stripeConnectEvents": {
|
|
177
|
+
"types": "./dist/stripeConnectEvents.d.ts",
|
|
178
|
+
"default": "./dist/stripeConnectEvents.js"
|
|
179
|
+
},
|
|
156
180
|
"./gcalSync": {
|
|
157
181
|
"types": "./dist/gcalSync.d.ts",
|
|
158
182
|
"default": "./dist/gcalSync.js"
|
|
@@ -393,6 +417,10 @@
|
|
|
393
417
|
"types": "./dist/functions/boldsign-sender-identity.d.ts",
|
|
394
418
|
"default": "./dist/functions/boldsign-sender-identity.js"
|
|
395
419
|
},
|
|
420
|
+
"./functions/booking-access-revoke-backstop": {
|
|
421
|
+
"types": "./dist/functions/booking-access-revoke-backstop.d.ts",
|
|
422
|
+
"default": "./dist/functions/booking-access-revoke-backstop.js"
|
|
423
|
+
},
|
|
396
424
|
"./functions/booking-availability": {
|
|
397
425
|
"types": "./dist/functions/booking-availability.d.ts",
|
|
398
426
|
"default": "./dist/functions/booking-availability.js"
|