@simplelayer/graniteer-core 0.5.0-rc.0 → 0.5.0-rc.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/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
1
  Copyright (c) 2026 SimpleLayer LLC. All rights reserved.
2
2
 
3
3
  This software is proprietary. No license is granted to use, copy, modify, or distribute it except under a separate written agreement with SimpleLayer LLC.
4
-
4
+
@@ -2,6 +2,7 @@
2
2
  // middleware's signed /admin/event-access/revoke path (same e1 HMAC contract
3
3
  // as event-access-admin.ts). Never throws; failures are ops-logged only.
4
4
  import { logOps } from '../ops.js';
5
+ import { getEnv } from '../runtime/env.js';
5
6
  import { sha256Hex, signBusMessage } from '../busSignature.js';
6
7
  import { getEventAccessBusBase } from '../tenant-config.js';
7
8
  import { doorReadForOpsLog, isDoorStateCompleteForGrantRevoke, } from './booking-access-revoke-door-state.js';
@@ -24,7 +25,7 @@ export function setForceRevokeThrowForTest(enabled) {
24
25
  }
25
26
  /** Fail-closed: only the exact string 'true' arms revoke work. */
26
27
  export function isBookingGrantRevokeEnabled() {
27
- return Deno.env.get(BOOKING_GRANT_REVOKE_ENABLED_ENV) === 'true';
28
+ return getEnv(BOOKING_GRANT_REVOKE_ENABLED_ENV) === 'true';
28
29
  }
29
30
  export function errorNameFromUnknown(e) {
30
31
  if (e instanceof Error && e.name)
@@ -40,6 +40,21 @@ export interface ManageBookingDeps {
40
40
  * var) when omitted -- same opts-override pattern as
41
41
  * booking-access-revoke.ts's revokeBookingOrganizerAccessGrants. */
42
42
  busBase?: string;
43
+ /** Optional override for the best-effort Google Calendar event delete on
44
+ * cancel. When provided it replaces the built-in service-account delete
45
+ * (which reads GOOGLE_SA_* env + rooms.google_calendar_id). Same
46
+ * best-effort contract: `ok: true` clears bookings.google_event_id; a
47
+ * non-ok result or a throw never rolls back the cancel/credit. */
48
+ deleteCalendarEvent?: (booking: {
49
+ id: string;
50
+ google_event_id: string | null;
51
+ rooms: {
52
+ google_calendar_id: string | null;
53
+ } | null;
54
+ }) => Promise<{
55
+ ok: boolean;
56
+ detail?: string;
57
+ }>;
43
58
  }
44
59
  declare function parseTstzRange(range: string): {
45
60
  startISO: string;
@@ -1,5 +1,5 @@
1
1
  import { createClient } from '@supabase/supabase-js';
2
- import { JWT } from 'google-auth-library';
2
+ import { getEnv } from '../runtime/env.js';
3
3
  import { writebackBookingCancelled } from '../gcalBookingEvents.js';
4
4
  import { clientIp, checkRateLimit } from '../rateLimit.js';
5
5
  import { verifyManageToken } from '../manageToken.js';
@@ -113,14 +113,15 @@ function googleCalendarUrl(startISO, endISO, title, details, location) {
113
113
  return `https://calendar.google.com/calendar/render?${params}`;
114
114
  }
115
115
  async function deleteCalendarEvent(booking) {
116
- const clientEmail = Deno.env.get('GOOGLE_SA_CLIENT_EMAIL');
117
- const rawKey = Deno.env.get('GOOGLE_SA_PRIVATE_KEY');
116
+ const clientEmail = getEnv('GOOGLE_SA_CLIENT_EMAIL');
117
+ const rawKey = getEnv('GOOGLE_SA_PRIVATE_KEY');
118
118
  if (!clientEmail || !rawKey)
119
119
  return { ok: false, detail: 'not_configured' };
120
120
  if (!booking.google_event_id || !booking.rooms?.google_calendar_id)
121
121
  return { ok: false, detail: 'no_event_or_calendar' };
122
122
  const privateKey = rawKey.replace(/\\n/g, '\n');
123
123
  try {
124
+ const { JWT } = await import('google-auth-library');
124
125
  const jwt = new JWT({ email: clientEmail, key: privateKey, scopes: ['https://www.googleapis.com/auth/calendar.events'] });
125
126
  const tok = await jwt.getAccessToken();
126
127
  if (!tok?.token)
@@ -138,7 +139,7 @@ async function deleteCalendarEvent(booking) {
138
139
  }
139
140
  }
140
141
  async function addGhlNote(ghlContactId, message) {
141
- const apiKey = Deno.env.get('GHL_API_KEY');
142
+ const apiKey = getEnv('GHL_API_KEY');
142
143
  if (!apiKey || !ghlContactId)
143
144
  return;
144
145
  try {
@@ -173,7 +174,7 @@ async function bookingViewForCustomer(b, operator) {
173
174
  // confirmed. A cancelled booking needs no extra handling: ftw-middleware
174
175
  // only ever validates against currently live/paid bookings.
175
176
  let reservationWifiCode = null;
176
- const wifiSecret = Deno.env.get('RESERVATION_WIFI_CODE_SECRET');
177
+ const wifiSecret = getEnv('RESERVATION_WIFI_CODE_SECRET');
177
178
  if (isPaid && wifiSecret && isReservationWifiRoom(b.rooms?.slug)) {
178
179
  reservationWifiCode = await deriveReservationWifiCode(wifiSecret, b.id);
179
180
  }
@@ -204,9 +205,9 @@ async function bookingViewForCustomer(b, operator) {
204
205
  export async function handle(req, operator, deps) {
205
206
  if (req.method === 'OPTIONS')
206
207
  return new Response('ok', { headers: corsHeaders });
207
- const SUPABASE_URL = Deno.env.get('SUPABASE_URL');
208
- const SERVICE_ROLE_KEY = Deno.env.get('SUPABASE_SERVICE_ROLE_KEY');
209
- const secret = Deno.env.get('MANAGE_TOKEN_SECRET');
208
+ const SUPABASE_URL = getEnv('SUPABASE_URL');
209
+ const SERVICE_ROLE_KEY = getEnv('SUPABASE_SERVICE_ROLE_KEY');
210
+ const secret = getEnv('MANAGE_TOKEN_SECRET');
210
211
  if (!secret)
211
212
  return json(500, { error: 'not_configured' });
212
213
  const admin = createClient(SUPABASE_URL, SERVICE_ROLE_KEY, {
@@ -290,7 +291,7 @@ export async function handle(req, operator, deps) {
290
291
  if (b.status !== 'paid' || endMs <= Date.now()) {
291
292
  return json(404, { error: 'no_credential' });
292
293
  }
293
- const busSecret = Deno.env.get('BUS_HMAC_SECRET');
294
+ const busSecret = getEnv('BUS_HMAC_SECRET');
294
295
  const slug = b.rooms?.slug ?? null;
295
296
  if (!busSecret || !slug || !parsedRange) {
296
297
  return json(404, { error: 'no_credential' });
@@ -481,7 +482,7 @@ export async function handle(req, operator, deps) {
481
482
  await writebackBookingCancelled(operator, b.rooms?.google_calendar_id, b.id);
482
483
  // Best-effort: delete Google Calendar event.
483
484
  try {
484
- const cal = await deleteCalendarEvent(b);
485
+ const cal = await (deps.deleteCalendarEvent ?? deleteCalendarEvent)(b);
485
486
  if (cal.ok) {
486
487
  await admin.from('bookings').update({ google_event_id: null }).eq('id', b.id);
487
488
  }
@@ -1,4 +1,4 @@
1
- import { JWT } from 'google-auth-library';
1
+ import { getEnv } from './runtime/env.js';
2
2
  import { parsePgRange } from './availability.js';
3
3
  import { CS_BOOKING_ID_KEY } from './gcalSync.js';
4
4
  const EVENTS_SCOPE = 'https://www.googleapis.com/auth/calendar.events';
@@ -10,10 +10,11 @@ export function eventIdForBooking(bookingId) {
10
10
  return `csb${bookingId.replace(/-/g, '').toLowerCase()}`;
11
11
  }
12
12
  async function defaultGetAccessToken() {
13
- const clientEmail = Deno.env.get('GOOGLE_SA_CLIENT_EMAIL');
14
- const rawKey = Deno.env.get('GOOGLE_SA_PRIVATE_KEY');
13
+ const clientEmail = getEnv('GOOGLE_SA_CLIENT_EMAIL');
14
+ const rawKey = getEnv('GOOGLE_SA_PRIVATE_KEY');
15
15
  if (!clientEmail || !rawKey)
16
16
  return null;
17
+ const { JWT } = await import('google-auth-library');
17
18
  const jwt = new JWT({ email: clientEmail, key: rawKey.replace(/\\n/g, '\n'), scopes: [EVENTS_SCOPE] });
18
19
  const tok = await jwt.getAccessToken();
19
20
  return tok?.token ?? null;
package/dist/ops.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { getEnv } from './runtime/env.js';
1
2
  /**
2
3
  * HARD CONTRACT: logOps NEVER THROWS. It returns
3
4
  * `{ ok: true } | { ok: false, error }`; no caller may be written assuming it
@@ -49,7 +50,7 @@ export async function logOps(supabase, kind, detail = {}, opts = {}) {
49
50
  }
50
51
  if (severity === 'error') {
51
52
  const text = `:rotating_light: GC Connect *${kind}* — ${JSON.stringify(detail).slice(0, 500)}`;
52
- const url = Deno.env.get('OPS_ALERT_WEBHOOK_URL');
53
+ const url = getEnv('OPS_ALERT_WEBHOOK_URL');
53
54
  if (url) {
54
55
  try {
55
56
  await fetch(url, {
@@ -63,8 +64,8 @@ export async function logOps(supabase, kind, detail = {}, opts = {}) {
63
64
  // Slack fallback so error-severity events land somewhere staff actually
64
65
  // look, not just an ops_events row. Same bot-token pattern the day-pass
65
66
  // notifier already uses. No-op until OPS_ALERT_SLACK_CHANNEL_ID is set.
66
- const slackToken = Deno.env.get('SLACK_BOT_TOKEN');
67
- const slackChannel = Deno.env.get('OPS_ALERT_SLACK_CHANNEL_ID');
67
+ const slackToken = getEnv('SLACK_BOT_TOKEN');
68
+ const slackChannel = getEnv('OPS_ALERT_SLACK_CHANNEL_ID');
68
69
  if (slackToken && slackChannel) {
69
70
  try {
70
71
  const res = await fetch('https://slack.com/api/chat.postMessage', {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@simplelayer/graniteer-core",
3
- "version": "0.5.0-rc.0",
3
+ "version": "0.5.0-rc.1",
4
4
  "description": "Shared platform core for Graniteer",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",