shopstack 0.2.6 → 0.3.0

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/src/client.d.ts CHANGED
@@ -2,7 +2,98 @@ export interface ShopstackClientOptions {
2
2
  apiKey?: string;
3
3
  baseUrl?: string;
4
4
  fetch?: typeof fetch;
5
- webSocket?: typeof WebSocket;
5
+ /** Uses the runtime WebSocket when available; null selects bounded HTTP waits. */
6
+ webSocket?: typeof WebSocket | null;
7
+ }
8
+
9
+ export interface ShippingAddress {
10
+ city: string;
11
+ country: string;
12
+ line1: string;
13
+ line2?: string;
14
+ postal_code: string;
15
+ region?: string;
16
+ suburb?: string;
17
+ }
18
+
19
+ export interface CreateCheckoutRequest {
20
+ currency: string;
21
+ customer: {
22
+ /** When absent or blank, the service uses a checkout-scoped temporary inbox. */
23
+ email?: string;
24
+ name: string;
25
+ phone?: string;
26
+ shipping_address: ShippingAddress;
27
+ };
28
+ external_reference?: string;
29
+ instructions?: string;
30
+ item_url: string;
31
+ maximum_amount: string;
32
+ model_handle?: "qwen";
33
+ payment_provider?: "link";
34
+ proxy?: {
35
+ country?: string;
36
+ /** Explicit browser locale; the service does not infer it from country. */
37
+ locale?: string;
38
+ };
39
+ }
40
+
41
+ export interface ReservationDiner {
42
+ country: string;
43
+ first_name: string;
44
+ last_name: string;
45
+ phone_number: string;
46
+ }
47
+
48
+ export interface CreateReservationRequest {
49
+ diner: ReservationDiner;
50
+ external_reference?: string;
51
+ /** The service resolves this place name and its local time zone. */
52
+ location: { query: string };
53
+ /** Include all known search details. The service asks for missing information. */
54
+ request: string;
55
+ }
56
+
57
+ export interface ReservationProgress {
58
+ type: "progress";
59
+ request_id: string;
60
+ sequence: number;
61
+ call_id: number;
62
+ operation:
63
+ | "resolve_location"
64
+ | "get_search_filters"
65
+ | "search_restaurants"
66
+ | "prepare_booking"
67
+ | "confirm_booking"
68
+ | "decline_booking"
69
+ | "ask_user"
70
+ | "reply"
71
+ | "request"
72
+ | "model_decision"
73
+ | "model_request"
74
+ | "model_retry_wait"
75
+ | "restaurant_request"
76
+ | "provider_session"
77
+ | "location_lookup"
78
+ | "availability_recheck"
79
+ | "slot_lock"
80
+ | "slot_unlock"
81
+ | "guest_profile"
82
+ | "booking_submit"
83
+ | "booking_status"
84
+ | "booking_cancel"
85
+ | "guest_inbox";
86
+ phase: "started" | "completed" | "failed" | "selected";
87
+ elapsed_ms: number;
88
+ duration_ms?: number;
89
+ http_status?: number;
90
+ failure?: string;
91
+ }
92
+
93
+ export interface ReservationMutationOptions {
94
+ idempotencyKey?: string;
95
+ /** Display only. Callback failure does not retry or cancel the operation. */
96
+ onProgress?: (event: ReservationProgress) => unknown;
6
97
  }
7
98
 
8
99
  export interface PaymentCard {
@@ -34,6 +125,7 @@ export interface Checkout {
34
125
  | "failed"
35
126
  | "cancelled";
36
127
  revision: number;
128
+ /** Monotonic display version; it can advance without a lifecycle change. */
37
129
  presentation_revision: number;
38
130
  activity: string;
39
131
  intent?: {
@@ -42,6 +134,7 @@ export interface Checkout {
42
134
  updated_at: string;
43
135
  };
44
136
  item_url: string;
137
+ /** Present this exact owner-only URL verbatim. Never reconstruct its token. */
45
138
  live_view_url?: string;
46
139
  required_input?: { type: "payment_card" };
47
140
  approval?: PaymentApproval;
@@ -52,9 +145,124 @@ export interface Checkout {
52
145
  expires_at: string;
53
146
  }
54
147
 
148
+ export interface Reservation {
149
+ id: string;
150
+ status:
151
+ | "active"
152
+ | "confirmation_required"
153
+ | "confirmed"
154
+ | "cancelled"
155
+ | "booking_unknown"
156
+ | "cancellation_unknown";
157
+ revision: number;
158
+ turn: ReservationTurn;
159
+ created_at: string;
160
+ updated_at: string;
161
+ /** Search-session expiry; it does not end the life of a confirmed booking. */
162
+ expires_at: string;
163
+ /** Last retained time for reading and managing the confirmed booking. */
164
+ }
165
+
166
+ export type ReservationTurn =
167
+ | { type: "question" | "message"; message: string }
168
+ | {
169
+ type: "location_options";
170
+ message: string;
171
+ locations: { location_id: string; label: string }[];
172
+ }
173
+ | {
174
+ type: "options";
175
+ message: string;
176
+ options: ReservationCompactOption[];
177
+ more_available: number;
178
+ }
179
+ | {
180
+ type: "confirmation_required";
181
+ message: string;
182
+ confirmation_prompt: {
183
+ restaurant: string;
184
+ address: string;
185
+ date_time: string;
186
+ party_size: number;
187
+ option_id: string;
188
+ time_id: string;
189
+ diner: ReservationDiner;
190
+ };
191
+ }
192
+ | {
193
+ type: "confirmation";
194
+ message: string;
195
+ confirmation: {
196
+ confirmation_number: string;
197
+ restaurant: string;
198
+ date_time: string;
199
+ party_size: number;
200
+ status: string;
201
+ };
202
+ }
203
+ | {
204
+ type: "cancellation";
205
+ message: string;
206
+ cancellation: { confirmation_number: string; status: string };
207
+ };
208
+
209
+ export interface ReservationTime {
210
+ date_time: string;
211
+ time_id: string;
212
+ }
213
+
214
+ export interface ReservationCompactOption {
215
+ address: string;
216
+ available_times: ReservationTime[];
217
+ caveats: string[];
218
+ cuisines: string[];
219
+ cover_photo_url?: string;
220
+ description_excerpt?: string;
221
+ fit: string[];
222
+ name: string;
223
+ option_id: string;
224
+ price_label?: string;
225
+ rating?: number;
226
+ review_count?: number;
227
+ tags: ("more_availability" | "most_proven")[];
228
+ }
229
+
230
+ export interface ReservationOption extends Omit<
231
+ ReservationCompactOption,
232
+ | "available_times"
233
+ | "caveats"
234
+ | "cover_photo_url"
235
+ | "description_excerpt"
236
+ | "fit"
237
+ | "tags"
238
+ > {
239
+ description?: string;
240
+ match_reasons: string[];
241
+ photo_urls: string[];
242
+ times: ReservationTime[];
243
+ unverified: string[];
244
+ }
245
+
246
+ export interface ReservationOptionPage {
247
+ limit: number;
248
+ more_available: number;
249
+ next_offset?: number;
250
+ offset: number;
251
+ options: ReservationCompactOption[];
252
+ total_available: number;
253
+ }
254
+
255
+ export interface RunReservationOptions {
256
+ idempotencyKey?: string;
257
+ onTurn?(reservation: Reservation): void | Promise<void>;
258
+ respond?(
259
+ reservation: Reservation,
260
+ ): string | Promise<string | undefined> | undefined;
261
+ }
262
+
55
263
  export interface RunCheckoutOptions {
56
264
  idempotencyKey?: string;
57
- onCreated?(checkout: Checkout): void | Promise<void>;
265
+ /** @deprecated Checkout monitoring uses revision notifications and bounded waits. */
58
266
  pollIntervalMs?: number;
59
267
  timeoutMs?: number;
60
268
  onProgress?(checkout: Checkout): void | Promise<void>;
@@ -70,19 +278,7 @@ export interface RunCheckoutOptions {
70
278
  ): string | Promise<string | undefined> | undefined;
71
279
  }
72
280
 
73
- export interface CheckoutUpdateSubscription {
74
- socket_url: string;
75
- protocol: "shopstack.v1";
76
- token: string;
77
- expires_at: string;
78
- presentation_revision: number;
79
- }
80
-
81
- export interface LiveViewCapability {
82
- live_view_url: string;
83
- }
84
-
85
- export interface AccountLoginStarted {
281
+ export interface AccountSignupStarted {
86
282
  id: string;
87
283
  account_type: "personal" | "developer";
88
284
  email: string;
@@ -92,7 +288,7 @@ export interface AccountLoginStarted {
92
288
  poll_token: string;
93
289
  }
94
290
 
95
- export interface VerifiedAccountLogin {
291
+ export interface VerifiedAccountSignup {
96
292
  id: string;
97
293
  status: "verified";
98
294
  verified_at: string;
@@ -102,43 +298,45 @@ export interface VerifiedAccountLogin {
102
298
  user?: Record<string, unknown>;
103
299
  }
104
300
 
105
- export interface LoginOptions {
301
+ export interface SignupOptions {
106
302
  accountType: "personal" | "developer";
107
303
  email: string;
108
304
  pollIntervalMs?: number;
109
305
  timeoutMs?: number;
110
- persistence?: LoginPersistence;
111
- onProgress?(progress: LoginProgress): void | Promise<void>;
306
+ persistence?: SignupPersistence;
307
+ onProgress?(progress: SignupProgress): void | Promise<void>;
112
308
  onVerificationRequired?(
113
- login: Omit<AccountLoginStarted, "poll_token">,
309
+ signup: Omit<AccountSignupStarted, "poll_token">,
114
310
  ): void | Promise<void>;
115
311
  }
116
312
 
117
- export interface PendingLoginState {
313
+ export interface PendingSignupState {
118
314
  accountType: "personal" | "developer";
119
315
  attemptId: string;
316
+ /** Exact API base URL that issued this signup; never send its capabilities elsewhere. */
317
+ baseUrl?: string;
120
318
  email: string;
121
319
  expiresAt?: string;
122
320
  idempotencyKey: string;
123
321
  pollToken?: string;
124
322
  recoveryKey: string;
125
- loginId?: string;
323
+ signupId?: string;
126
324
  }
127
325
 
128
- export interface LoginPersistence {
326
+ export interface SignupPersistence {
129
327
  loadPending(input: {
130
328
  accountType: "personal" | "developer";
131
329
  email: string;
132
- }): Promise<PendingLoginState | undefined>;
133
- savePending(state: PendingLoginState): Promise<void>;
330
+ }): Promise<PendingSignupState | undefined>;
331
+ savePending(state: PendingSignupState): Promise<void>;
134
332
  completePending(
135
- state: PendingLoginState,
136
- result: VerifiedAccountLogin,
333
+ state: PendingSignupState,
334
+ result: VerifiedAccountSignup,
137
335
  ): Promise<void>;
138
- deletePending(state: PendingLoginState): Promise<void>;
336
+ deletePending(state: PendingSignupState): Promise<void>;
139
337
  }
140
338
 
141
- export interface LoginProgress {
339
+ export interface SignupProgress {
142
340
  state:
143
341
  | "pending"
144
342
  | "email_sent"
@@ -155,7 +353,7 @@ export interface LoginProgress {
155
353
  key_type?: "user" | "developer";
156
354
  }
157
355
 
158
- export type CompletedAccountLogin = Omit<VerifiedAccountLogin, "api_key">;
356
+ export type CompletedAccountSignup = Omit<VerifiedAccountSignup, "api_key">;
159
357
 
160
358
  export class ShopstackApiError extends Error {
161
359
  code: string;
@@ -165,20 +363,21 @@ export class ShopstackApiError extends Error {
165
363
 
166
364
  export class ShopstackClient {
167
365
  constructor(options?: ShopstackClientOptions);
168
- startAccountLogin(input: {
366
+ baseUrl: string;
367
+ startAccountSignup(input: {
169
368
  accountType: "personal" | "developer";
170
369
  email: string;
171
- }): Promise<AccountLoginStarted>;
172
- pollAccountLogin(
173
- loginId: string,
370
+ }): Promise<AccountSignupStarted>;
371
+ pollAccountSignup(
372
+ signupId: string,
174
373
  pollToken: string,
175
- ): Promise<Omit<AccountLoginStarted, "poll_token"> | VerifiedAccountLogin>;
176
- waitForAccountLogin(
177
- loginId: string,
374
+ ): Promise<Omit<AccountSignupStarted, "poll_token"> | VerifiedAccountSignup>;
375
+ waitForAccountSignup(
376
+ signupId: string,
178
377
  pollToken: string,
179
378
  options?: { pollIntervalMs?: number; timeoutMs?: number },
180
- ): Promise<VerifiedAccountLogin>;
181
- login(input: LoginOptions): Promise<CompletedAccountLogin>;
379
+ ): Promise<VerifiedAccountSignup>;
380
+ signup(input: SignupOptions): Promise<CompletedAccountSignup>;
182
381
  createUser(input: {
183
382
  externalId: string;
184
383
  idempotencyKey?: string;
@@ -199,23 +398,57 @@ export class ShopstackClient {
199
398
  paymentProvider?: "link",
200
399
  options?: { idempotencyKey?: string },
201
400
  ): Promise<Record<string, unknown>>;
401
+ createReservation(
402
+ reservation: CreateReservationRequest,
403
+ options?: ReservationMutationOptions,
404
+ ): Promise<Reservation>;
405
+ getReservation(reservationId: string): Promise<Reservation>;
406
+ listReservationOptions(
407
+ reservationId: string,
408
+ options?: { limit?: number; offset?: number },
409
+ ): Promise<ReservationOptionPage>;
410
+ getReservationOption(
411
+ reservationId: string,
412
+ optionId: string,
413
+ ): Promise<ReservationOption>;
414
+ sendReservationMessage(
415
+ reservationId: string,
416
+ content: string,
417
+ expectedRevision: number,
418
+ options?: ReservationMutationOptions,
419
+ ): Promise<Reservation>;
420
+ cancelReservation(
421
+ reservationId: string,
422
+ expectedRevision: number,
423
+ options?: ReservationMutationOptions,
424
+ ): Promise<Reservation>;
425
+ runReservation(
426
+ reservation: CreateReservationRequest,
427
+ options?: RunReservationOptions,
428
+ ): Promise<Reservation>;
202
429
  createCheckout(
203
- checkout: Record<string, unknown>,
430
+ checkout: CreateCheckoutRequest,
204
431
  options?: { idempotencyKey?: string },
205
432
  ): Promise<Checkout>;
206
433
  getCheckout(checkoutId: string): Promise<Checkout>;
207
- createLiveView(
208
- checkoutId: string,
209
- options?: { idempotencyKey?: string },
210
- ): Promise<LiveViewCapability>;
211
- createCheckoutUpdateSubscription(
212
- checkoutId: string,
213
- ): Promise<CheckoutUpdateSubscription>;
214
434
  waitForCheckoutUpdate(
215
435
  checkoutId: string,
216
- afterRevision: number,
217
- waitSeconds?: number,
436
+ options: { after: number; wait?: number; signal?: AbortSignal },
218
437
  ): Promise<Checkout | undefined>;
438
+ subscribeToCheckoutUpdates(
439
+ checkoutId: string,
440
+ options?: { signal?: AbortSignal },
441
+ ): Promise<{
442
+ socket_url: string;
443
+ protocol: "shopstack.v1";
444
+ token: string;
445
+ expires_at: string;
446
+ presentation_revision: number;
447
+ }>;
448
+ createLiveView(
449
+ checkoutId: string,
450
+ options?: { idempotencyKey?: string },
451
+ ): Promise<{ live_view_url: string }>;
219
452
  cancelCheckout(
220
453
  checkoutId: string,
221
454
  options?: { idempotencyKey?: string },
@@ -227,7 +460,6 @@ export class ShopstackClient {
227
460
  ): Promise<Record<string, unknown>>;
228
461
  listMessages(checkoutId: string): Promise<Record<string, unknown>>;
229
462
  listEvents(checkoutId: string): Promise<Record<string, unknown>>;
230
- listArtifacts(checkoutId: string): Promise<Record<string, unknown>>;
231
463
  providePaymentDetails(
232
464
  checkoutId: string,
233
465
  card: PaymentCard,
@@ -240,7 +472,7 @@ export class ShopstackClient {
240
472
  options?: { idempotencyKey?: string },
241
473
  ): Promise<Checkout>;
242
474
  runCheckout(
243
- checkout: Record<string, unknown>,
475
+ checkout: CreateCheckoutRequest,
244
476
  options?: RunCheckoutOptions,
245
477
  ): Promise<Checkout>;
246
478
  }