@simplelayer/graniteer-core 0.3.5 → 0.3.6

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.
@@ -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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@simplelayer/graniteer-core",
3
- "version": "0.3.5",
3
+ "version": "0.3.6",
4
4
  "description": "Shared platform core for Graniteer",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",