@simplelayer/graniteer-core 0.3.20 → 0.3.21

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.
@@ -49,7 +49,7 @@ export function minNoticeErrorMessage(nowMs, cfg) {
49
49
  const earliest = new Intl.DateTimeFormat('en-US', {
50
50
  timeZone: 'America/Los_Angeles',
51
51
  weekday: 'short', month: 'short', day: 'numeric', hour: 'numeric', minute: '2-digit',
52
- }).format(new Date(earliestBookingStartMs(nowMs, cfg)));
52
+ }).format(new Date(earliestBookingStartMs(nowMs, cfg))).replace(/[  ]/g, ' ');
53
53
  return `Bookings need at least ${cfg.minNoticeBusinessHours} business hours notice ` +
54
54
  `(Monday–Friday, excluding holidays). The earliest available start is ${earliest} Pacific time.`;
55
55
  }
@@ -424,6 +424,8 @@ export async function handle(req, operator, deps) {
424
424
  outcome: fresh.status,
425
425
  });
426
426
  }
427
+ // Re-read failed: fail closed, never fall through to the credit grant.
428
+ return json(409, { error: 'already_changed' });
427
429
  }
428
430
  // Credit ledger row(s): split cash-funded (1yr) vs credit-funded (capped at
429
431
  // the ORIGINAL credit's own expiry) so a cancellation can never launder a
@@ -100,7 +100,9 @@ function buildStripeWebhookHandler(config, connect) {
100
100
  .from('bookings').select('id,status').eq('stripe_session_id', session.id).maybeSingle();
101
101
  return data;
102
102
  }
103
+ let bookingLookupErrored = false;
103
104
  async function findBookingIdByPaymentIntent(paymentIntentId) {
105
+ bookingLookupErrored = false;
104
106
  const { data: rows, error } = await supabase
105
107
  .from('bookings')
106
108
  .select('id')
@@ -112,6 +114,7 @@ function buildStripeWebhookHandler(config, connect) {
112
114
  payment_intent_id: paymentIntentId,
113
115
  ...(typeof code === 'string' ? { error_code: code } : {}),
114
116
  }, { severity: 'error', bookingId: null });
117
+ bookingLookupErrored = true;
115
118
  return null;
116
119
  }
117
120
  const list = (rows ?? []);
@@ -149,8 +152,11 @@ function buildStripeWebhookHandler(config, connect) {
149
152
  let markerFailed = false;
150
153
  try {
151
154
  bookingId = await findBookingIdByPaymentIntent(piId);
152
- if (!bookingId)
153
- return 'skipped';
155
+ if (!bookingId) {
156
+ // Connect: the marker is the only thing blocking self-service credit,
157
+ // so a lookup DB error must be retried by Stripe, not silently acked.
158
+ return connect && bookingLookupErrored ? 'marker_failed' : 'skipped';
159
+ }
154
160
  if (connect) {
155
161
  // Connect (direct-charge) bookings are refunded outside the app, so
156
162
  // nothing cancels the booking: status stays 'paid', the slot stays
@@ -2114,10 +2120,17 @@ function buildStripeWebhookHandler(config, connect) {
2114
2120
  }
2115
2121
  }
2116
2122
  catch (e) {
2123
+ const permanentStripeError = e?.type === 'StripeInvalidRequestError' && !isRetryableStripeError(e);
2117
2124
  await logOps(supabase, 'booking_access_revoke_step_failed', {
2118
2125
  reason: 'charge_dispute_created',
2119
2126
  error_name: errorNameFromUnknown(e),
2127
+ permanent_stripe_error: permanentStripeError,
2120
2128
  }, { severity: 'error', bookingId: bookingIdForDisputeRevoke });
2129
+ if (connect && !permanentStripeError) {
2130
+ // Marker is the only thing blocking self-service credit on Connect; let Stripe retry.
2131
+ await releaseStripeEventLedgerForRetry(event.id);
2132
+ return webhookResponseMarkerFailedForRetry();
2133
+ }
2121
2134
  }
2122
2135
  break;
2123
2136
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@simplelayer/graniteer-core",
3
- "version": "0.3.20",
3
+ "version": "0.3.21",
4
4
  "description": "Shared platform core for Graniteer",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",