@simplelayer/graniteer-core 0.3.26 → 0.3.28

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.
@@ -0,0 +1,172 @@
1
+ import type { SupabaseClient } from '@supabase/supabase-js';
2
+ import type Stripe from 'stripe';
3
+ import { z } from 'zod';
4
+ import { loadTier1Terms } from './tier1Agreement.js';
5
+ import { sendPaymentLinkEmail } from './paymentLinkEmail.js';
6
+ import type { BookingLogOps, CreateBookingCoreArgs, CreateBookingResult } from './createBookingCore.js';
7
+ type SupabaseLike = SupabaseClient<any, any, any>;
8
+ export interface AgentIdentity {
9
+ /** Stable agent id from the authenticated credential. Never caller-supplied. */
10
+ id: string;
11
+ /** Short slug; becomes created_by = `service:<label>`. */
12
+ label: string;
13
+ tenantId: string;
14
+ }
15
+ export type ReserveOutcome = {
16
+ status: 'ok';
17
+ } | {
18
+ status: 'replay_succeeded';
19
+ bookingId: string;
20
+ } | {
21
+ status: 'in_progress';
22
+ } | {
23
+ status: 'idempotency_conflict';
24
+ } | {
25
+ status: 'ceiling_exceeded';
26
+ scope?: 'agent' | 'tenant';
27
+ };
28
+ export interface AgentClaims {
29
+ reserve(a: {
30
+ agentId: string;
31
+ tenantId: string;
32
+ key: string;
33
+ requestHash: string;
34
+ listCents: number;
35
+ agentMaxBookings: number;
36
+ agentMaxListCents: number;
37
+ tenantMaxBookings: number;
38
+ tenantMaxListCents: number;
39
+ windowSeconds: number;
40
+ createdBy?: string;
41
+ }): Promise<ReserveOutcome>;
42
+ /** Links the in_progress claim to its just-inserted booking. ok only when exactly one claim row was updated. */
43
+ link(a: {
44
+ agentId: string;
45
+ key: string;
46
+ bookingId: string;
47
+ }): Promise<{
48
+ ok: boolean;
49
+ }>;
50
+ /** `response` is what a replay may show: it must never contain a Checkout URL or session id. */
51
+ succeed(a: {
52
+ agentId: string;
53
+ key: string;
54
+ bookingId: string;
55
+ response: Record<string, unknown>;
56
+ }): Promise<void>;
57
+ fail(a: {
58
+ agentId: string;
59
+ key: string;
60
+ reason: string;
61
+ bookingId?: string;
62
+ }): Promise<void>;
63
+ failAmbiguous(a: {
64
+ agentId: string;
65
+ key: string;
66
+ reason: string;
67
+ bookingId: string;
68
+ }): Promise<void>;
69
+ release(a: {
70
+ agentId: string;
71
+ bookingId: string;
72
+ }): Promise<void>;
73
+ }
74
+ export interface AgentBrand {
75
+ name: string;
76
+ shortName: string;
77
+ domain: string;
78
+ supportEmail: string;
79
+ }
80
+ type TermsResult = Awaited<ReturnType<typeof loadTier1Terms>>;
81
+ export interface AgentRuntime {
82
+ agent: AgentIdentity;
83
+ claims: AgentClaims;
84
+ brand: AgentBrand;
85
+ nowMs?: () => number;
86
+ sendLinkEmail?: typeof sendPaymentLinkEmail;
87
+ loadTerms?: (admin: SupabaseLike) => Promise<TermsResult>;
88
+ /** Public, versioned URL of the Tier-1 terms artifact. */
89
+ termsUrl?: (version: string) => string;
90
+ }
91
+ export interface AgentStripe {
92
+ checkout: {
93
+ sessions: {
94
+ create: (params: Stripe.Checkout.SessionCreateParams, options?: {
95
+ stripeAccount?: string;
96
+ idempotencyKey?: string;
97
+ }) => Promise<Stripe.Checkout.Session>;
98
+ retrieve: (id: string) => Promise<Stripe.Checkout.Session>;
99
+ expire: (id: string) => Promise<Stripe.Checkout.Session>;
100
+ };
101
+ };
102
+ }
103
+ export declare const AgentBookingBody: z.ZodObject<{
104
+ room_id: z.ZodString;
105
+ start: z.ZodString;
106
+ end: z.ZodString;
107
+ contact: z.ZodObject<{
108
+ name: z.ZodString;
109
+ email: z.ZodString;
110
+ phone: z.ZodOptional<z.ZodString>;
111
+ }, "strict", z.ZodTypeAny, {
112
+ name?: string;
113
+ email?: string;
114
+ phone?: string;
115
+ }, {
116
+ name?: string;
117
+ email?: string;
118
+ phone?: string;
119
+ }>;
120
+ reason: z.ZodString;
121
+ idempotency_key: z.ZodString;
122
+ }, "strict", z.ZodTypeAny, {
123
+ room_id?: string;
124
+ start?: string;
125
+ end?: string;
126
+ reason?: string;
127
+ contact?: {
128
+ name?: string;
129
+ email?: string;
130
+ phone?: string;
131
+ };
132
+ idempotency_key?: string;
133
+ }, {
134
+ room_id?: string;
135
+ start?: string;
136
+ end?: string;
137
+ reason?: string;
138
+ contact?: {
139
+ name?: string;
140
+ email?: string;
141
+ phone?: string;
142
+ };
143
+ idempotency_key?: string;
144
+ }>;
145
+ export type AgentBookingInput = z.infer<typeof AgentBookingBody>;
146
+ export declare function parseAgentInput(raw: unknown): {
147
+ ok: true;
148
+ data: AgentBookingInput;
149
+ } | {
150
+ ok: false;
151
+ };
152
+ export declare function normalizeEmail(e: string): string;
153
+ export declare function normalizePhone(p: string | undefined): string | null;
154
+ /** sha256 over the canonical parsed input (sorted keys, normalized email/phone, UTC ISO times). */
155
+ export declare function computeRequestHash(i: AgentBookingInput): Promise<string>;
156
+ export declare function maskEmail(email: string): string;
157
+ /** Only InvalidRequest/Card errors prove no session was created. Everything else is ambiguous. */
158
+ export declare function isDefinitiveStripeError(e: unknown): boolean;
159
+ /** Voids ONLY the calling agent's own still-pending booking. Never touches paid rows. */
160
+ export declare function voidAgentBooking(a: {
161
+ admin: SupabaseLike;
162
+ stripe: AgentStripe;
163
+ agent: AgentIdentity;
164
+ bookingId: string;
165
+ logOps?: BookingLogOps;
166
+ /** Releases the idempotency claim. Defaults to the agent_booking_release RPC. */
167
+ releaseClaim?: (agentId: string, bookingId: string) => Promise<void>;
168
+ }): Promise<CreateBookingResult>;
169
+ /** Claims backed by SQL RPCs. Only agent_booking_reserve is specified; the rest are assumed names. */
170
+ export declare function makeSupabaseAgentClaims(admin: SupabaseLike): AgentClaims;
171
+ export declare function runAgentBooking(args: CreateBookingCoreArgs): Promise<CreateBookingResult>;
172
+ export {};