@simplelayer/graniteer-core 0.0.2 → 0.1.2
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/index.js +2 -2
- package/package.json +98 -15
- package/src/adminBookingCredit.test.ts +451 -0
- package/src/adminBookingCredit.ts +239 -0
- package/src/availability.test.ts +25 -0
- package/src/availability.ts +201 -0
- package/src/bookingHoldReclaim.ts +94 -0
- package/src/checkoutSessionParams.ts +56 -0
- package/src/commonsContract.ts +175 -0
- package/src/conductorAdmin.ts +141 -0
- package/src/email-templates/email-change.tsx +92 -0
- package/src/email-templates/invite.tsx +79 -0
- package/src/email-templates/reauthentication.tsx +60 -0
- package/src/functions/admin-cancel-membership.ts +311 -0
- package/src/functions/admin-change-membership-plan.ts +308 -0
- package/src/functions/admin-charge-guest-print.ts +229 -0
- package/src/functions/admin-correct-booking.ts +333 -0
- package/src/functions/admin-create-commons-event.ts +244 -0
- package/src/functions/admin-debug-boldsign-doc.ts +93 -0
- package/src/functions/admin-door-write.ts +272 -0
- package/src/functions/admin-mark-booking-paid.ts +203 -0
- package/src/functions/admin-photo-upload.ts +128 -0
- package/src/functions/admin-remove-team-member.ts +150 -0
- package/src/functions/admin-reset-mfa.ts +138 -0
- package/src/functions/admin-reverse-coupon-redemption.ts +98 -0
- package/src/functions/admin-send-commons-agreement.ts +214 -0
- package/src/functions/admin-set-credit-amount.ts +123 -0
- package/src/functions/admin-skip-commons-contract.ts +165 -0
- package/src/functions/admin-undo-membership-cancel.ts +144 -0
- package/src/functions/admin-wall-photo-write.ts +141 -0
- package/src/functions/boldsign-sender-identity.ts +114 -0
- package/src/functions/booking-availability.ts +419 -0
- package/src/functions/booking-member-preview.ts +136 -0
- package/src/functions/day-pass-status.ts +89 -0
- package/src/functions/dayStatus.ts +71 -0
- package/src/functions/diag-webpush-test.ts +45 -0
- package/src/functions/event-access-store.ts +309 -0
- package/src/functions/ezeep-print-webhook.ts +213 -0
- package/src/functions/ezeep-usage-reconcile.ts +299 -0
- package/src/functions/get-signing-link.ts +211 -0
- package/src/functions/guest-print-setup-confirm.ts +128 -0
- package/src/functions/guest-print-submit.ts +149 -0
- package/src/functions/luma-webhook.ts +165 -0
- package/src/functions/migration-collision-alert.copy.ts +232 -0
- package/src/functions/migration-collision-alert.test.ts +349 -0
- package/src/functions/migration-collision-alert.ts +232 -0
- package/src/functions/office-assignment-end.ts +146 -0
- package/src/functions/portal-booking-access.ts +95 -0
- package/src/functions/portal-list-invoices.ts +99 -0
- package/src/functions/print-billing-recover.ts +97 -0
- package/src/functions/print-billing-run.ts +183 -0
- package/src/functions/public-facts.ts +168 -0
- package/src/functions/space-availability-range.acceptance.test.ts +161 -0
- package/src/functions/space-availability-range.ts +142 -0
- package/src/functions/sync-gcal-blackouts.ts +298 -0
- package/src/functions/timetable-event-register.ts +162 -0
- package/src/functions/timetable-event-status.ts +90 -0
- package/src/functions/timetable-spaces.ts +219 -0
- package/src/functions/touch-pass-reconciler.ts +689 -0
- package/src/functions/virtual-onboarding-purge.ts +134 -0
- package/src/functions/virtual-onboarding-submit.ts +315 -0
- package/src/functions/voice-inquiry.test.ts +301 -0
- package/src/functions/voice-inquiry.ts +198 -0
- package/src/functions/voice-tour-availability.ts +204 -0
- package/src/gcalSync.ts +142 -0
- package/src/ghlNote.ts +34 -0
- package/src/ghlTask.ts +48 -0
- package/src/ghlVoiceInquiry.ts +90 -0
- package/src/guestPrintCapture.test.ts +722 -0
- package/src/guestPrintCapture.ts +538 -0
- package/src/lumaGhl.ts +195 -0
- package/src/membership.ts +109 -0
- package/src/money.ts +36 -0
- package/src/ops.ts +97 -0
- package/src/pacificDate.ts +34 -0
- package/src/policyAcknowledgment.test.ts +50 -0
- package/src/policyAcknowledgment.ts +96 -0
- package/src/portalSession.ts +46 -0
- package/src/pricing.test.ts +660 -0
- package/src/pricing.ts +1025 -0
- package/src/printBilling.test.ts +750 -0
- package/src/printBilling.ts +891 -0
- package/src/printBillingAdapters.ts +169 -0
- package/src/printCorrections.test.ts +348 -0
- package/src/printCorrections.ts +496 -0
- package/src/rateLimit.ts +82 -0
- package/src/referralCredits.test.ts +31 -0
- package/src/referralCredits.ts +34 -0
- package/src/referralGrant.ts +321 -0
- package/src/rescheduleCredit.test.ts +521 -0
- package/src/rescheduleCredit.ts +337 -0
- package/src/reservationWifiCode.test.ts +69 -0
- package/src/reservationWifiCode.ts +81 -0
- package/src/retellCallAnalyzed.test.ts +167 -0
- package/src/retellCallAnalyzed.ts +113 -0
- package/src/retellSignature.test.ts +137 -0
- package/src/retellSignature.ts +82 -0
- package/src/slackAlert.ts +38 -0
- package/src/supabaseTestFakes.ts +131 -0
- package/src/tier1Agreement.ts +125 -0
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
// Commons (Tier 3) event contract rendering helpers.
|
|
2
|
+
//
|
|
3
|
+
// Pure functions only — no network, no Supabase. Everything here is venue-local
|
|
4
|
+
// (America/Los_Angeles) and derived from calendar components, never from a naive
|
|
5
|
+
// `new Date(...)` parse of a timestamp string (standing landmine on this project).
|
|
6
|
+
|
|
7
|
+
export const COMMONS_TEMPLATE_PATH = 'templates/commons/commons-event-contract-v1.docx';
|
|
8
|
+
export const COMMONS_DOCUMENT_VERSION = 'commons-event-contract-v1';
|
|
9
|
+
export const COMMONS_EXPECTED_FIELD_COUNT = 4;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The four BoldSign text tags carried by the Commons template, verbatim.
|
|
13
|
+
* Syntax is the pipe form BoldSign parses on this account (`{{type|signer|required|label|id}}`) —
|
|
14
|
+
* the colon form `{{sign:1|required}}` is rejected with "Invalid field type".
|
|
15
|
+
*
|
|
16
|
+
* NOTE: `client_signer_title` is marked required (`*`) here even though the design doc
|
|
17
|
+
* describes Title as optional. Verified live: BoldSign parses it as `isRequired: true`.
|
|
18
|
+
* This is intentional and accepted — do not "fix" it against the design doc without a
|
|
19
|
+
* task to work out (and test-send) BoldSign's optional-field syntax.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
export const COMMONS_BOLDSIGN_TAGS = [
|
|
23
|
+
'{{sign|1|*}}',
|
|
24
|
+
'{{date|1|*}}',
|
|
25
|
+
'{{text|1|*|Full name|client_signer_name}}',
|
|
26
|
+
'{{text|1|*|Title|client_signer_title}}',
|
|
27
|
+
] as const;
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
/** Phrases the corrected template must never contain (predecessor branding). */
|
|
31
|
+
export const FORBIDDEN_PHRASES = ['burst media', 'event center'] as const;
|
|
32
|
+
|
|
33
|
+
const LA_TZ = 'America/Los_Angeles';
|
|
34
|
+
|
|
35
|
+
const MONTHS = [
|
|
36
|
+
'January', 'February', 'March', 'April', 'May', 'June',
|
|
37
|
+
'July', 'August', 'September', 'October', 'November', 'December',
|
|
38
|
+
];
|
|
39
|
+
|
|
40
|
+
/** Venue-local calendar date (YYYY-MM-DD) for a UTC instant. */
|
|
41
|
+
export function laDateString(at: Date): string {
|
|
42
|
+
const parts = new Intl.DateTimeFormat('en-CA', {
|
|
43
|
+
timeZone: LA_TZ, year: 'numeric', month: '2-digit', day: '2-digit',
|
|
44
|
+
}).formatToParts(at);
|
|
45
|
+
const get = (t: string) => parts.find((p) => p.type === t)?.value ?? '';
|
|
46
|
+
return `${get('year')}-${get('month')}-${get('day')}`;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Venue-local clock time for a UTC instant, e.g. "5:00 PM". */
|
|
50
|
+
export function laTimeString(at: Date): string {
|
|
51
|
+
return new Intl.DateTimeFormat('en-US', {
|
|
52
|
+
timeZone: LA_TZ, hour: 'numeric', minute: '2-digit', hour12: true,
|
|
53
|
+
}).format(at).replace(/\u202f/g, ' ');
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** "2026-08-20" -> "August 20, 2026". Component arithmetic only. */
|
|
57
|
+
export function longDate(ymd: string): string {
|
|
58
|
+
const m = /^(\d{4})-(\d{2})-(\d{2})$/.exec(ymd);
|
|
59
|
+
if (!m) return ymd;
|
|
60
|
+
return `${MONTHS[Number(m[2]) - 1]} ${Number(m[3])}, ${m[1]}`;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Shift a YYYY-MM-DD calendar date by whole days, DST-free (UTC component math). */
|
|
64
|
+
export function shiftDays(ymd: string, days: number): string {
|
|
65
|
+
const m = /^(\d{4})-(\d{2})-(\d{2})$/.exec(ymd);
|
|
66
|
+
if (!m) return ymd;
|
|
67
|
+
const t = Date.UTC(Number(m[1]), Number(m[2]) - 1, Number(m[3])) + days * 86_400_000;
|
|
68
|
+
const d = new Date(t);
|
|
69
|
+
const pad = (n: number) => String(n).padStart(2, '0');
|
|
70
|
+
return `${d.getUTCFullYear()}-${pad(d.getUTCMonth() + 1)}-${pad(d.getUTCDate())}`;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Balance / COI due wording: 30 days before the event, venue-local. If that
|
|
75
|
+
* date is today or already past, the money is due at signature — print that
|
|
76
|
+
* instead of a date in the past.
|
|
77
|
+
*/
|
|
78
|
+
export function dueDateWording(eventYmd: string, todayYmd: string): { ymd: string; text: string } {
|
|
79
|
+
const ymd = shiftDays(eventYmd, -30);
|
|
80
|
+
return { ymd, text: ymd <= todayYmd ? 'immediately upon signature' : longDate(ymd) };
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** Whole-cent USD, e.g. "$4,800.00". */
|
|
84
|
+
export function usd(cents: number): string {
|
|
85
|
+
const v = Math.max(0, Math.round(cents)) / 100;
|
|
86
|
+
return `$${v.toLocaleString('en-US', { minimumFractionDigits: 2, maximumFractionDigits: 2 })}`;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function escapeXml(s: string): string {
|
|
90
|
+
return s.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function escapeRegex(s: string): string {
|
|
94
|
+
return s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Build a regex that matches `literal` even when Word has split it across runs
|
|
99
|
+
* (`...</w:t></w:r><w:r><w:rPr>..</w:rPr><w:t>...`), by allowing an optional
|
|
100
|
+
* run boundary between every character. A bare literal match silently no-ops
|
|
101
|
+
* on Word-authored XML.
|
|
102
|
+
*/
|
|
103
|
+
export function runSplitTolerantRegex(literal: string): RegExp {
|
|
104
|
+
const joint = '(?:</w:t>\\s*</w:r>\\s*<w:r>(?:<w:rPr>[\\s\\S]*?</w:rPr>)?<w:t[^>]*>)?';
|
|
105
|
+
const body = literal.split('').map(escapeRegex).join(joint);
|
|
106
|
+
return new RegExp(body, 'g');
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export interface CommonsTokenValues {
|
|
110
|
+
EFFECTIVE_DATE: string;
|
|
111
|
+
QUOTE_DATE: string;
|
|
112
|
+
CLIENT_LEGAL_NAME: string;
|
|
113
|
+
EVENT_DATE: string;
|
|
114
|
+
ARRIVAL_DATE: string;
|
|
115
|
+
ARRIVAL_TIME: string;
|
|
116
|
+
CHECKOUT_DATE: string;
|
|
117
|
+
CHECKOUT_TIME: string;
|
|
118
|
+
TOTAL_PRICE: string;
|
|
119
|
+
DEPOSIT_AMOUNT: string;
|
|
120
|
+
BALANCE_AMOUNT: string;
|
|
121
|
+
SECURITY_DEPOSIT_AMOUNT: string;
|
|
122
|
+
BALANCE_DUE_DATE: string;
|
|
123
|
+
COI_DUE_DATE: string;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** Substitute every [[TOKEN]] in document.xml. Reports any token left behind. */
|
|
127
|
+
export function substituteCommonsTokens(
|
|
128
|
+
xmlIn: string,
|
|
129
|
+
values: CommonsTokenValues,
|
|
130
|
+
): { xml: string; missing: string[] } {
|
|
131
|
+
let xml = xmlIn;
|
|
132
|
+
const missing: string[] = [];
|
|
133
|
+
for (const [key, value] of Object.entries(values)) {
|
|
134
|
+
const token = `[[${key}]]`;
|
|
135
|
+
const re = runSplitTolerantRegex(token);
|
|
136
|
+
if (!re.test(xml)) { missing.push(token); continue; }
|
|
137
|
+
xml = xml.replace(runSplitTolerantRegex(token), escapeXml(value));
|
|
138
|
+
}
|
|
139
|
+
return { xml, missing };
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** Plain text of a document.xml (tags stripped, paragraph breaks preserved). */
|
|
143
|
+
export function xmlToText(xml: string): string {
|
|
144
|
+
return xml
|
|
145
|
+
.replace(/<w:p[ >]/g, '\n<w:p ')
|
|
146
|
+
.replace(/<[^>]+>/g, '')
|
|
147
|
+
.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>')
|
|
148
|
+
.replace(/"/g, '"').replace(/'/g, "'")
|
|
149
|
+
.replace(/’/g, '\u2019');
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Hard build check. Returns a failure reason, or null when the rendered
|
|
154
|
+
* document is safe to send.
|
|
155
|
+
*/
|
|
156
|
+
export function validateRenderedCommonsXml(xml: string): string | null {
|
|
157
|
+
const text = xmlToText(xml).toLowerCase();
|
|
158
|
+
for (const phrase of FORBIDDEN_PHRASES) {
|
|
159
|
+
if (text.includes(phrase)) return `forbidden_phrase: "${phrase}" present in rendered document`;
|
|
160
|
+
}
|
|
161
|
+
const leftover = xml.match(/\[\[[A-Z_]+\]\]/g);
|
|
162
|
+
if (leftover && leftover.length > 0) {
|
|
163
|
+
return `unsubstituted_tokens: ${JSON.stringify(Array.from(new Set(leftover)))}`;
|
|
164
|
+
}
|
|
165
|
+
for (const tag of COMMONS_BOLDSIGN_TAGS) {
|
|
166
|
+
const count = (xml.match(runSplitTolerantRegex(tag)) ?? []).length;
|
|
167
|
+
if (count !== 1) return `tag_count_mismatch: ${tag} found ${count} times, expected 1`;
|
|
168
|
+
}
|
|
169
|
+
const total = (xml.match(/\{\{(sign|date|text|init)\|/g) ?? []).length;
|
|
170
|
+
|
|
171
|
+
if (total !== COMMONS_EXPECTED_FIELD_COUNT) {
|
|
172
|
+
return `tag_count_mismatch: found ${total} BoldSign tags, expected ${COMMONS_EXPECTED_FIELD_COUNT}`;
|
|
173
|
+
}
|
|
174
|
+
return null;
|
|
175
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
// The ONLY place Conductor is allowed to touch the service-role key.
|
|
2
|
+
//
|
|
3
|
+
// Exactly three privileged operations live here, and none of them reads member
|
|
4
|
+
// data: fetching Conductor's Anthropic key, consuming a rate-limit bucket, and
|
|
5
|
+
// appending one audit row. The client object is never exported and never shared
|
|
6
|
+
// with the request handler — every data read in `conductor/index.ts` goes
|
|
7
|
+
// through a separate anon-key client carrying the caller's own JWT, so RLS
|
|
8
|
+
// stays the only thing deciding what that caller can see.
|
|
9
|
+
//
|
|
10
|
+
// Same shape as the get_reconcile_secret()/get_door_sync_secret() pattern in
|
|
11
|
+
// stripe-db-reconcile and membership-door-sync: a service-role client, one RPC,
|
|
12
|
+
// nothing cached at module scope.
|
|
13
|
+
import { createClient } from 'npm:@supabase/supabase-js@2';
|
|
14
|
+
import { checkRateLimit } from './rateLimit.ts';
|
|
15
|
+
|
|
16
|
+
/** Fresh per call, deliberately — nothing privileged survives a request. */
|
|
17
|
+
function adminClient() {
|
|
18
|
+
return createClient(
|
|
19
|
+
Deno.env.get('SUPABASE_URL')!,
|
|
20
|
+
Deno.env.get('SUPABASE_SERVICE_ROLE_KEY')!,
|
|
21
|
+
{ auth: { persistSession: false, autoRefreshToken: false } },
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Two distinct not-configured outcomes, kept apart on purpose:
|
|
27
|
+
* 'not_configured' — the RPC answered, and what it returned is the migration's
|
|
28
|
+
* literal 'PLACEHOLDER_SET_ME' (or empty). Nobody has set
|
|
29
|
+
* the key yet.
|
|
30
|
+
* 'fetch_failed' — the RPC itself errored or threw. This is an outage, and
|
|
31
|
+
* it can happen long after the key was set correctly.
|
|
32
|
+
* Collapsing these into one code makes a real outage indistinguishable from
|
|
33
|
+
* "this was never turned on", which is exactly the state you cannot afford to
|
|
34
|
+
* misread when Conductor has been live for months.
|
|
35
|
+
*/
|
|
36
|
+
export type ConductorKeyResult =
|
|
37
|
+
| { key: string }
|
|
38
|
+
| { key: null; reason: 'not_configured' | 'fetch_failed' };
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Conductor's Anthropic key.
|
|
42
|
+
*
|
|
43
|
+
* Calls public.get_conductor_key() — the PostgREST-reachable wrapper added in
|
|
44
|
+
* 20260823120000, mirroring public.get_anthropic_key(). It is NOT called on the
|
|
45
|
+
* `private` schema: `private` is not one of this project's exposed schemas (and
|
|
46
|
+
* must not become one — anon/authenticated holding no USAGE on `private` is a
|
|
47
|
+
* migration-enforced invariant, not a setting), so a `.schema('private').rpc()`
|
|
48
|
+
* call would fail here. The wrapper is service_role-only; the secret still never
|
|
49
|
+
* becomes reachable from a browser session.
|
|
50
|
+
*/
|
|
51
|
+
export async function fetchConductorKey(): Promise<ConductorKeyResult> {
|
|
52
|
+
try {
|
|
53
|
+
const { data, error } = await adminClient().rpc('get_conductor_key');
|
|
54
|
+
if (error) {
|
|
55
|
+
console.error('[conductorAdmin] get_conductor_key failed', error.message);
|
|
56
|
+
return { key: null, reason: 'fetch_failed' };
|
|
57
|
+
}
|
|
58
|
+
const key = typeof data === 'string' ? data.trim() : '';
|
|
59
|
+
if (!key || key === 'PLACEHOLDER_SET_ME') return { key: null, reason: 'not_configured' };
|
|
60
|
+
return { key };
|
|
61
|
+
} catch (e) {
|
|
62
|
+
console.error('[conductorAdmin] get_conductor_key threw', e);
|
|
63
|
+
return { key: null, reason: 'fetch_failed' };
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* One rate-limit bucket, through the shared public.check_rate_limit() RPC every
|
|
69
|
+
* other function in this repo uses. Lives here rather than in the handler for
|
|
70
|
+
* the same reason the other two do: check_rate_limit() is granted to
|
|
71
|
+
* service_role only, so consuming a bucket needs the privileged client, and
|
|
72
|
+
* that client must not leak into request-handling code.
|
|
73
|
+
*
|
|
74
|
+
* Fails open (returns true) exactly as _shared/rateLimit.ts does — a rate-limit
|
|
75
|
+
* outage must not take Conductor down.
|
|
76
|
+
*/
|
|
77
|
+
export async function checkConductorRateLimit(
|
|
78
|
+
bucket: string,
|
|
79
|
+
identifier: string,
|
|
80
|
+
max: number,
|
|
81
|
+
windowSeconds: number,
|
|
82
|
+
): Promise<boolean> {
|
|
83
|
+
return await checkRateLimit(adminClient(), bucket, identifier, max, windowSeconds);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export interface ConductorEventInput {
|
|
87
|
+
actor_type: 'member' | 'staff';
|
|
88
|
+
actor_user_id: string;
|
|
89
|
+
question: string;
|
|
90
|
+
answer?: string | null;
|
|
91
|
+
model?: string | null;
|
|
92
|
+
ok: boolean;
|
|
93
|
+
error?: string | null;
|
|
94
|
+
/**
|
|
95
|
+
* Phase 7 escape hatch: distinguishes a plain Q&A row ('qa', the default —
|
|
96
|
+
* every row before this phase and every row with this field omitted) from a
|
|
97
|
+
* member sending a drafted request to staff ('draft_submitted').
|
|
98
|
+
*
|
|
99
|
+
* There is no dedicated `event_kind` column — conductor_events' schema is
|
|
100
|
+
* fixed at the four columns the 20260823120000 migration created, and this
|
|
101
|
+
* phase's schema work is scoped to dispatch_requests.source only (see
|
|
102
|
+
* 20260824070000). Adding a column would need a new migration this phase
|
|
103
|
+
* doesn't ship, so a 'draft_submitted' row is instead tagged with a
|
|
104
|
+
* `[draft_submitted -> dispatch_requests:<id>]` prefix on `question` — the
|
|
105
|
+
* one column already guaranteed to hold free text about what the actor did.
|
|
106
|
+
* `answer`/`model` stay null on these rows; nothing here changes ordinary
|
|
107
|
+
* 'qa' rows.
|
|
108
|
+
*/
|
|
109
|
+
event_kind?: 'qa' | 'draft_submitted';
|
|
110
|
+
/** Required with event_kind: 'draft_submitted' — the row it produced. */
|
|
111
|
+
dispatch_request_id?: string;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Appends one audit row. Never throws: a failed audit write must not turn a
|
|
116
|
+
* successful answer into an error for the caller, it just gets logged.
|
|
117
|
+
*
|
|
118
|
+
* Rows are deletable only through private.purge_conductor_events() /
|
|
119
|
+
* private.purge_conductor_events_for_user() — see the migration for why that is
|
|
120
|
+
* the deletion path and why `answer` is stored in full.
|
|
121
|
+
*/
|
|
122
|
+
export async function insertConductorEvent(event: ConductorEventInput): Promise<void> {
|
|
123
|
+
const question =
|
|
124
|
+
event.event_kind === 'draft_submitted'
|
|
125
|
+
? `[draft_submitted -> dispatch_requests:${event.dispatch_request_id ?? 'unknown'}] ${event.question}`
|
|
126
|
+
: event.question;
|
|
127
|
+
try {
|
|
128
|
+
const { error } = await adminClient().from('conductor_events').insert({
|
|
129
|
+
actor_type: event.actor_type,
|
|
130
|
+
actor_user_id: event.actor_user_id,
|
|
131
|
+
question,
|
|
132
|
+
answer: event.answer ?? null,
|
|
133
|
+
model: event.model ?? null,
|
|
134
|
+
ok: event.ok,
|
|
135
|
+
error: event.error ?? null,
|
|
136
|
+
});
|
|
137
|
+
if (error) console.error('[conductorAdmin] conductor_events insert failed', error.message);
|
|
138
|
+
} catch (e) {
|
|
139
|
+
console.error('[conductorAdmin] conductor_events insert threw', e);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/// <reference types="npm:@types/react@18.3.1" />
|
|
2
|
+
|
|
3
|
+
import * as React from 'npm:react@18.3.1'
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
Body,
|
|
7
|
+
Button,
|
|
8
|
+
Container,
|
|
9
|
+
Head,
|
|
10
|
+
Heading,
|
|
11
|
+
Html,
|
|
12
|
+
Link,
|
|
13
|
+
Preview,
|
|
14
|
+
Text,
|
|
15
|
+
} from 'npm:@react-email/components@0.0.22'
|
|
16
|
+
|
|
17
|
+
interface EmailChangeEmailProps {
|
|
18
|
+
siteName: string
|
|
19
|
+
// oldEmail is the user's current address (HookData.OldEmail). For the
|
|
20
|
+
// NEW-recipient half of a secure email_change fanout, `email` equals the
|
|
21
|
+
// recipient (NEW), so the "from" line must render oldEmail to read
|
|
22
|
+
// "from OLD to NEW" instead of "from NEW to NEW".
|
|
23
|
+
oldEmail: string
|
|
24
|
+
email: string
|
|
25
|
+
newEmail: string
|
|
26
|
+
confirmationUrl: string
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const EmailChangeEmail = ({
|
|
30
|
+
siteName,
|
|
31
|
+
oldEmail,
|
|
32
|
+
newEmail,
|
|
33
|
+
confirmationUrl,
|
|
34
|
+
}: EmailChangeEmailProps) => (
|
|
35
|
+
<Html lang="en" dir="ltr">
|
|
36
|
+
<Head />
|
|
37
|
+
<Preview>Confirm your email change for {siteName}</Preview>
|
|
38
|
+
<Body style={main}>
|
|
39
|
+
<Container style={container}>
|
|
40
|
+
<Heading style={h1}>Confirm your email change</Heading>
|
|
41
|
+
<Text style={text}>
|
|
42
|
+
You requested to change your email address for {siteName} from{' '}
|
|
43
|
+
<Link href={`mailto:${oldEmail}`} style={link}>
|
|
44
|
+
{oldEmail}
|
|
45
|
+
</Link>{' '}
|
|
46
|
+
to{' '}
|
|
47
|
+
<Link href={`mailto:${newEmail}`} style={link}>
|
|
48
|
+
{newEmail}
|
|
49
|
+
</Link>
|
|
50
|
+
.
|
|
51
|
+
</Text>
|
|
52
|
+
<Text style={text}>
|
|
53
|
+
Click the button below to confirm this change:
|
|
54
|
+
</Text>
|
|
55
|
+
<Button style={button} href={confirmationUrl}>
|
|
56
|
+
Confirm Email Change
|
|
57
|
+
</Button>
|
|
58
|
+
<Text style={footer}>
|
|
59
|
+
If you didn't request this change, please secure your account
|
|
60
|
+
immediately.
|
|
61
|
+
</Text>
|
|
62
|
+
</Container>
|
|
63
|
+
</Body>
|
|
64
|
+
</Html>
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
export default EmailChangeEmail
|
|
68
|
+
|
|
69
|
+
const main = { backgroundColor: '#ffffff', fontFamily: 'Arial, sans-serif' }
|
|
70
|
+
const container = { padding: '20px 25px' }
|
|
71
|
+
const h1 = {
|
|
72
|
+
fontSize: '22px',
|
|
73
|
+
fontWeight: 'bold' as const,
|
|
74
|
+
color: '#000000',
|
|
75
|
+
margin: '0 0 20px',
|
|
76
|
+
}
|
|
77
|
+
const text = {
|
|
78
|
+
fontSize: '14px',
|
|
79
|
+
color: '#55575d',
|
|
80
|
+
lineHeight: '1.5',
|
|
81
|
+
margin: '0 0 25px',
|
|
82
|
+
}
|
|
83
|
+
const link = { color: 'inherit', textDecoration: 'underline' }
|
|
84
|
+
const button = {
|
|
85
|
+
backgroundColor: '#000000',
|
|
86
|
+
color: '#ffffff',
|
|
87
|
+
fontSize: '14px',
|
|
88
|
+
borderRadius: '8px',
|
|
89
|
+
padding: '12px 20px',
|
|
90
|
+
textDecoration: 'none',
|
|
91
|
+
}
|
|
92
|
+
const footer = { fontSize: '12px', color: '#999999', margin: '30px 0 0' }
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/// <reference types="npm:@types/react@18.3.1" />
|
|
2
|
+
|
|
3
|
+
import * as React from 'npm:react@18.3.1'
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
Body,
|
|
7
|
+
Button,
|
|
8
|
+
Container,
|
|
9
|
+
Head,
|
|
10
|
+
Heading,
|
|
11
|
+
Html,
|
|
12
|
+
Link,
|
|
13
|
+
Preview,
|
|
14
|
+
Text,
|
|
15
|
+
} from 'npm:@react-email/components@0.0.22'
|
|
16
|
+
|
|
17
|
+
interface InviteEmailProps {
|
|
18
|
+
siteName: string
|
|
19
|
+
siteUrl: string
|
|
20
|
+
confirmationUrl: string
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export const InviteEmail = ({
|
|
24
|
+
siteName,
|
|
25
|
+
siteUrl,
|
|
26
|
+
confirmationUrl,
|
|
27
|
+
}: InviteEmailProps) => (
|
|
28
|
+
<Html lang="en" dir="ltr">
|
|
29
|
+
<Head />
|
|
30
|
+
<Preview>You've been invited to join {siteName}</Preview>
|
|
31
|
+
<Body style={main}>
|
|
32
|
+
<Container style={container}>
|
|
33
|
+
<Heading style={h1}>You've been invited</Heading>
|
|
34
|
+
<Text style={text}>
|
|
35
|
+
You've been invited to join{' '}
|
|
36
|
+
<Link href={siteUrl} style={link}>
|
|
37
|
+
<strong>{siteName}</strong>
|
|
38
|
+
</Link>
|
|
39
|
+
. Click the button below to accept the invitation and create your
|
|
40
|
+
account.
|
|
41
|
+
</Text>
|
|
42
|
+
<Button style={button} href={confirmationUrl}>
|
|
43
|
+
Accept Invitation
|
|
44
|
+
</Button>
|
|
45
|
+
<Text style={footer}>
|
|
46
|
+
If you weren't expecting this invitation, you can safely ignore this
|
|
47
|
+
email.
|
|
48
|
+
</Text>
|
|
49
|
+
</Container>
|
|
50
|
+
</Body>
|
|
51
|
+
</Html>
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
export default InviteEmail
|
|
55
|
+
|
|
56
|
+
const main = { backgroundColor: '#ffffff', fontFamily: 'Arial, sans-serif' }
|
|
57
|
+
const container = { padding: '20px 25px' }
|
|
58
|
+
const h1 = {
|
|
59
|
+
fontSize: '22px',
|
|
60
|
+
fontWeight: 'bold' as const,
|
|
61
|
+
color: '#000000',
|
|
62
|
+
margin: '0 0 20px',
|
|
63
|
+
}
|
|
64
|
+
const text = {
|
|
65
|
+
fontSize: '14px',
|
|
66
|
+
color: '#55575d',
|
|
67
|
+
lineHeight: '1.5',
|
|
68
|
+
margin: '0 0 25px',
|
|
69
|
+
}
|
|
70
|
+
const link = { color: 'inherit', textDecoration: 'underline' }
|
|
71
|
+
const button = {
|
|
72
|
+
backgroundColor: '#000000',
|
|
73
|
+
color: '#ffffff',
|
|
74
|
+
fontSize: '14px',
|
|
75
|
+
borderRadius: '8px',
|
|
76
|
+
padding: '12px 20px',
|
|
77
|
+
textDecoration: 'none',
|
|
78
|
+
}
|
|
79
|
+
const footer = { fontSize: '12px', color: '#999999', margin: '30px 0 0' }
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/// <reference types="npm:@types/react@18.3.1" />
|
|
2
|
+
|
|
3
|
+
import * as React from 'npm:react@18.3.1'
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
Body,
|
|
7
|
+
Container,
|
|
8
|
+
Head,
|
|
9
|
+
Heading,
|
|
10
|
+
Html,
|
|
11
|
+
Preview,
|
|
12
|
+
Text,
|
|
13
|
+
} from 'npm:@react-email/components@0.0.22'
|
|
14
|
+
|
|
15
|
+
interface ReauthenticationEmailProps {
|
|
16
|
+
token: string
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const ReauthenticationEmail = ({ token }: ReauthenticationEmailProps) => (
|
|
20
|
+
<Html lang="en" dir="ltr">
|
|
21
|
+
<Head />
|
|
22
|
+
<Preview>Your verification code</Preview>
|
|
23
|
+
<Body style={main}>
|
|
24
|
+
<Container style={container}>
|
|
25
|
+
<Heading style={h1}>Confirm reauthentication</Heading>
|
|
26
|
+
<Text style={text}>Use the code below to confirm your identity:</Text>
|
|
27
|
+
<Text style={codeStyle}>{token}</Text>
|
|
28
|
+
<Text style={footer}>
|
|
29
|
+
This code will expire shortly. If you didn't request this, you can
|
|
30
|
+
safely ignore this email.
|
|
31
|
+
</Text>
|
|
32
|
+
</Container>
|
|
33
|
+
</Body>
|
|
34
|
+
</Html>
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
export default ReauthenticationEmail
|
|
38
|
+
|
|
39
|
+
const main = { backgroundColor: '#ffffff', fontFamily: 'Arial, sans-serif' }
|
|
40
|
+
const container = { padding: '20px 25px' }
|
|
41
|
+
const h1 = {
|
|
42
|
+
fontSize: '22px',
|
|
43
|
+
fontWeight: 'bold' as const,
|
|
44
|
+
color: '#000000',
|
|
45
|
+
margin: '0 0 20px',
|
|
46
|
+
}
|
|
47
|
+
const text = {
|
|
48
|
+
fontSize: '14px',
|
|
49
|
+
color: '#55575d',
|
|
50
|
+
lineHeight: '1.5',
|
|
51
|
+
margin: '0 0 25px',
|
|
52
|
+
}
|
|
53
|
+
const codeStyle = {
|
|
54
|
+
fontFamily: 'Courier, monospace',
|
|
55
|
+
fontSize: '22px',
|
|
56
|
+
fontWeight: 'bold' as const,
|
|
57
|
+
color: '#000000',
|
|
58
|
+
margin: '0 0 30px',
|
|
59
|
+
}
|
|
60
|
+
const footer = { fontSize: '12px', color: '#999999', margin: '30px 0 0' }
|