@simplelayer/graniteer-core 0.3.5 → 0.3.7
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.
|
@@ -17,6 +17,24 @@ const corsHeaders = {
|
|
|
17
17
|
'Access-Control-Allow-Methods': 'POST, GET, OPTIONS',
|
|
18
18
|
};
|
|
19
19
|
const TIMEOUT_MS = 20_000;
|
|
20
|
+
// D32 item #3 (2026-09-23): a two-pin grant's UniFi collision-retry logic
|
|
21
|
+
// can, in the corrected worst case, take up to ~65-70s inside ftw-middleware
|
|
22
|
+
// alone (one wall-clock-budget-gated retry attempt can itself make up to 3
|
|
23
|
+
// UniFi calls before the budget check ever gets a chance to abort it -- see
|
|
24
|
+
// event_access.py's _TWO_PIN_PROVISION_BUDGET_SEC comment for the full
|
|
25
|
+
// derivation). The original 20s TIMEOUT_MS fired long before the middleware
|
|
26
|
+
// could ever return a real (success or definitive-failure) response for a
|
|
27
|
+
// grant, forcing staff to see a spurious 502 middleware_unreachable while
|
|
28
|
+
// the middleware kept working in the background -- wasting a minted PIN and
|
|
29
|
+
// requiring a manual Revoke+Grant. GRANT_TIMEOUT_MS gives grant-only
|
|
30
|
+
// headroom (95s) that sits comfortably above ftw-middleware's own
|
|
31
|
+
// _GRANT_HANDLER_TIMEOUT_SEC (85s, itself raised in the same pass to clear
|
|
32
|
+
// the corrected worst case) while staying under the Cloudflare Tunnel
|
|
33
|
+
// edge's own ~100s proxied-HTTP limit for ftw.granitecity.io -- past that,
|
|
34
|
+
// Cloudflare cuts the connection with a 524 regardless of what this signal
|
|
35
|
+
// says, so there is no point setting this any higher. door/revoke keep the
|
|
36
|
+
// original 20s: neither has a retry loop and both should fail fast.
|
|
37
|
+
const GRANT_TIMEOUT_MS = 95_000;
|
|
20
38
|
const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
21
39
|
const JWKS_URL_SUFFIX = '/auth/v1/.well-known/jwks.json';
|
|
22
40
|
let jwksCache = null;
|
|
@@ -226,7 +244,7 @@ export function createEventAccessAdminHandler(config) {
|
|
|
226
244
|
'X-Event-Access-Timestamp': ts,
|
|
227
245
|
},
|
|
228
246
|
body: rawBody,
|
|
229
|
-
signal: AbortSignal.timeout(TIMEOUT_MS),
|
|
247
|
+
signal: AbortSignal.timeout(action === 'grant' ? GRANT_TIMEOUT_MS : TIMEOUT_MS),
|
|
230
248
|
});
|
|
231
249
|
}
|
|
232
250
|
catch (e) {
|
|
@@ -174,6 +174,16 @@ export async function handle(req) {
|
|
|
174
174
|
extra.unlock_visitor_id = unlockVisitorId;
|
|
175
175
|
if (relockVisitorId)
|
|
176
176
|
extra.relock_visitor_id = relockVisitorId;
|
|
177
|
+
// D35 follow-up (PIN storage): unlock_pin/relock_pin are the plaintext
|
|
178
|
+
// PINs UniFi mints at visitor-creation time and never returns again --
|
|
179
|
+
// captured here, once, so a later read-back has somewhere to find them.
|
|
180
|
+
// Same optional/omitted-stays-untouched treatment as the visitor ids.
|
|
181
|
+
const unlockPin = str(args.unlock_pin);
|
|
182
|
+
const relockPin = str(args.relock_pin);
|
|
183
|
+
if (unlockPin)
|
|
184
|
+
extra.unlock_pin = unlockPin;
|
|
185
|
+
if (relockPin)
|
|
186
|
+
extra.relock_pin = relockPin;
|
|
177
187
|
const r = await cas(grantId, 'pending', 'active', extra);
|
|
178
188
|
if ('err' in r)
|
|
179
189
|
return await fail('db_error', { message: r.err });
|
|
@@ -226,6 +236,14 @@ export async function handle(req) {
|
|
|
226
236
|
patch.unlock_visitor_id = unlockVisitorId;
|
|
227
237
|
if (relockVisitorId)
|
|
228
238
|
patch.relock_visitor_id = relockVisitorId;
|
|
239
|
+
// PIN-storage follow-up: same COALESCE-on-presence semantics -- a
|
|
240
|
+
// revoke-failed row must not silently blank out a PIN already stored.
|
|
241
|
+
const unlockPin = str(args.unlock_pin);
|
|
242
|
+
const relockPin = str(args.relock_pin);
|
|
243
|
+
if (unlockPin)
|
|
244
|
+
patch.unlock_pin = unlockPin;
|
|
245
|
+
if (relockPin)
|
|
246
|
+
patch.relock_pin = relockPin;
|
|
229
247
|
const { data, error } = await supabase
|
|
230
248
|
.from('booking_access_grants').update(patch).eq('id', grantId).select('*').maybeSingle();
|
|
231
249
|
if (error)
|
|
@@ -261,6 +261,41 @@ export async function handle(req, operator, deps) {
|
|
|
261
261
|
return json(404, { error: 'no_credential' });
|
|
262
262
|
}
|
|
263
263
|
}
|
|
264
|
+
// Two-pin organizer credential (D35 follow-up): unlike 'credential' above,
|
|
265
|
+
// this table lives in this SAME Supabase project, so it's read directly
|
|
266
|
+
// via `admin` -- no HTTP call out to the ftw-middleware droplet at all. A
|
|
267
|
+
// booking may have EITHER a legacy single-pin credential (above) OR a
|
|
268
|
+
// two-pin grant (below), never assumed to be exclusive. Returns
|
|
269
|
+
// 404 { error: 'no_credential' } until the (separate, later) PIN-capture
|
|
270
|
+
// provisioning code actually writes unlock_pin/relock_pin.
|
|
271
|
+
if (action === 'two_pin_credential') {
|
|
272
|
+
const parsedRange = parseTstzRange(b.during);
|
|
273
|
+
const endMs = parsedRange ? new Date(parsedRange.endISO).getTime() : 0;
|
|
274
|
+
if (b.status !== 'paid' || endMs <= Date.now()) {
|
|
275
|
+
return json(404, { error: 'no_credential' });
|
|
276
|
+
}
|
|
277
|
+
try {
|
|
278
|
+
const { data, error } = await admin
|
|
279
|
+
.from('booking_access_grants')
|
|
280
|
+
.select('unlock_pin,relock_pin,access_start,access_end,status')
|
|
281
|
+
.eq('booking_id', b.id).eq('status', 'active')
|
|
282
|
+
.order('created_at', { ascending: false }).limit(1).maybeSingle();
|
|
283
|
+
if (error || !data)
|
|
284
|
+
return json(404, { error: 'no_credential' });
|
|
285
|
+
const grant = data;
|
|
286
|
+
if (!grant.unlock_pin && !grant.relock_pin)
|
|
287
|
+
return json(404, { error: 'no_credential' });
|
|
288
|
+
return json(200, {
|
|
289
|
+
unlock_pin: grant.unlock_pin ?? null,
|
|
290
|
+
relock_pin: grant.relock_pin ?? null,
|
|
291
|
+
valid_from_utc: grant.access_start ?? null,
|
|
292
|
+
valid_to_utc: grant.access_end ?? null,
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
catch {
|
|
296
|
+
return json(404, { error: 'no_credential' });
|
|
297
|
+
}
|
|
298
|
+
}
|
|
264
299
|
if (action !== 'cancel')
|
|
265
300
|
return json(400, { error: 'invalid_action' });
|
|
266
301
|
// Idempotent: if already cancelled, just return the current view.
|