@estoreclub/api 0.0.0-stage → 0.1.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.
Files changed (58) hide show
  1. package/dist/bridgeClient.d.ts +10 -0
  2. package/dist/bridgeClient.js +10 -0
  3. package/dist/bridgeClient.js.map +7 -0
  4. package/dist/chunks/chunk-2554RPSS.js +45 -0
  5. package/dist/chunks/chunk-2554RPSS.js.map +7 -0
  6. package/dist/chunks/chunk-2BH4QPV2.js +27 -0
  7. package/dist/chunks/chunk-2BH4QPV2.js.map +7 -0
  8. package/dist/chunks/chunk-3KEEGSMP.js +86 -0
  9. package/dist/chunks/chunk-3KEEGSMP.js.map +7 -0
  10. package/dist/chunks/chunk-5DN7L6LX.js +861 -0
  11. package/dist/chunks/chunk-5DN7L6LX.js.map +7 -0
  12. package/dist/chunks/chunk-DUVULZ6N.js +111 -0
  13. package/dist/chunks/chunk-DUVULZ6N.js.map +7 -0
  14. package/dist/chunks/chunk-GJZ7EZEF.js +25 -0
  15. package/dist/chunks/chunk-GJZ7EZEF.js.map +7 -0
  16. package/dist/chunks/chunk-HFEQWXG6.js +24 -0
  17. package/dist/chunks/chunk-HFEQWXG6.js.map +7 -0
  18. package/dist/chunks/chunk-OFFTL6RC.js +24 -0
  19. package/dist/chunks/chunk-OFFTL6RC.js.map +7 -0
  20. package/dist/chunks/chunk-TSERNR4R.js +15 -0
  21. package/dist/chunks/chunk-TSERNR4R.js.map +7 -0
  22. package/dist/chunks/chunk-ZITPZDI7.js +280 -0
  23. package/dist/chunks/chunk-ZITPZDI7.js.map +7 -0
  24. package/dist/client.d.ts +407 -0
  25. package/dist/client.js +14 -0
  26. package/dist/client.js.map +7 -0
  27. package/dist/companyApiKey.d.ts +9 -0
  28. package/dist/companyApiKey.js +9 -0
  29. package/dist/companyApiKey.js.map +7 -0
  30. package/dist/customerToken.d.ts +18 -0
  31. package/dist/customerToken.js +11 -0
  32. package/dist/customerToken.js.map +7 -0
  33. package/dist/errors.d.ts +41 -0
  34. package/dist/errors.js +9 -0
  35. package/dist/errors.js.map +7 -0
  36. package/dist/index.d.ts +82 -0
  37. package/dist/index.js +166 -0
  38. package/dist/index.js.map +7 -0
  39. package/dist/language.d.ts +27 -0
  40. package/dist/language.js +11 -0
  41. package/dist/language.js.map +7 -0
  42. package/dist/params.d.ts +58 -0
  43. package/dist/params.js +27 -0
  44. package/dist/params.js.map +7 -0
  45. package/dist/requestCache.d.ts +46 -0
  46. package/dist/requestCache.js +9 -0
  47. package/dist/requestCache.js.map +7 -0
  48. package/dist/siteData.d.ts +237 -0
  49. package/dist/siteData.js +132 -0
  50. package/dist/siteData.js.map +7 -0
  51. package/dist/types.d.ts +2123 -0
  52. package/dist/types.js +1 -0
  53. package/dist/types.js.map +7 -0
  54. package/dist/visitorCountry.d.ts +25 -0
  55. package/dist/visitorCountry.js +15 -0
  56. package/dist/visitorCountry.js.map +7 -0
  57. package/package.json +64 -4
  58. package/README.md +0 -3
@@ -0,0 +1,407 @@
1
+ import type { AddCartItemParams, CreateCheckoutParams, GetCartParams, GetCheckoutParams, TrackOrderParams, GetCategoryParams, ListCategoriesParams, ListProductsParams, Paginated, PublicCart, PublicCheckout, PublicCheckoutSession, PublicCategory, PublicCompany, GetDictionaryParams, GetProductParams, ListCombosParams, PublicCombo, PublicDiscountRule, PublicDictionary, PublicImage, PublicDictionarySummary, PublicStoreLocation, PublicTerms, PublicProduct, PublicProductSettingDefinition, PublicSiteInfo, RemoveCartItemParams, SetCartBookingParams, SetCartItemQuantityParams, SetCheckoutEmailParams, CreateBookingParams, GetBookingPlanParams, GetBookingSlotsParams, GetOrderTimesParams, PublicBooking, CustomerTokenParams, PublicCustomer, PublicCustomerAccount, PublicCustomerBooking, PublicBookingPreorder, SetBookingPreorderParams, PublicCustomerOrder, PublicCustomerOrderDetail, PublicCustomerSession, CustomerPage, CustomerHistoryParams, CustomerBookingsParams, AddCustomerAddressParams, PublicCustomerAddress, PublicCustomerPaymentMethod, CreateProductCommentParams, DeleteProductCommentParams, GetProductCommentsParams, GetProductFeedbackParams, PublicProductComment, PublicProductCommentsPage, PublicProductFeedback, PublicCommentVoteResult, PublicProductRating, RateProductParams, UnrateProductParams, VoteProductCommentParams, RequestSignInCodeParams, SignInWithAppleParams, SignInWithGoogleParams, RefreshCustomerTokenParams, UpdateCustomerProfileParams, VerifySignInCodeParams, PublicBookingPlan, PublicBookingSlots, PublicOrderTimes, PublicDiningTable } from "./types";
2
+ export interface PublicApiConfig {
3
+ /** e.g. `http://localhost:4000` — the value of `NEXT_PUBLIC_SERVER_URL`. */
4
+ baseUrl: string;
5
+ /**
6
+ * The COMPANY's own key, and the only credential this client knows.
7
+ *
8
+ * It goes on the wire as `x-company-api-key`, which every public route authenticates with —
9
+ * and the server resolves the company FROM it. That is why there is no domain in this
10
+ * config: the key already says whose data this is, so there is nothing left for a caller to
11
+ * choose, and no way to point one company's key at another's catalogue.
12
+ *
13
+ * `setCompanyApiKey()` sets the same thing process-wide, for a caller that learns the key
14
+ * after this client was built; a key given here wins over that one.
15
+ *
16
+ * Where it comes from is deliberately somebody else's problem. The TRUSTED layer in front of
17
+ * a rendered page — the preview's route handler, the public site's server — turns a host or
18
+ * a deployment id into a company key and hands the page only that. The platform key and the
19
+ * lookup that uses it never enter this package.
20
+ */
21
+ companyApiKey?: string;
22
+ /**
23
+ * Read a product SAMPLE instead of the company's own catalogue — its slug, e.g. `sample-pizza`,
24
+ * the same id a template names as its `productSampleId`. Sent as `x-product-sample`.
25
+ *
26
+ * The key still decides whose SITE this is: `getSiteInfo()` answers with the company's own
27
+ * name, languages and currency. Only the menu changes — products, categories, lists, product
28
+ * settings, and the cart built from them. A checkout is refused, since nobody sells a sample.
29
+ */
30
+ productSample?: string;
31
+ /**
32
+ * The visitor a call is made for, sent as `x-visitor-ip` with `platformKey` as `x-api-key`:
33
+ * the API counts the emails a visitor sets off (sign-in codes, confirmations) by their address,
34
+ * and a call relayed by a server would otherwise all come from that server. Believed only with
35
+ * the platform key, so set by the platform's own site server only - never page code.
36
+ */
37
+ visitor?: {
38
+ ip: string;
39
+ platformKey: string;
40
+ };
41
+ /**
42
+ * How `fetch` may cache. `no-store` unless told otherwise: a page is rendered per request
43
+ * and a menu, a price or a basket must never be served stale.
44
+ *
45
+ * A STATIC EXPORT is the exception — it is rendered once, at build time, and Next refuses a
46
+ * `no-store` fetch there (the route "couldn't be rendered statically"), which a page catches
47
+ * as an unavailable API and draws its empty state. The template preview is one.
48
+ */
49
+ cache?: RequestCache;
50
+ /**
51
+ * The language names and descriptions come back in, sent as `x-language`. Omitted, the one
52
+ * `setLanguageResolver()` answers with for this request — see `language.ts`. Null: the shop's
53
+ * default, never the resolver - a client made for one request, whose resolver may be set by
54
+ * another request's render at the same moment.
55
+ */
56
+ language?: string | null;
57
+ /**
58
+ * The signed-in customer every call is made as, sent as `x-customer-token` - what a shop
59
+ * open to signed-in customers only (`customerAccess: signed_in`) needs on its catalogue,
60
+ * cart and checkout reads too. A call's own `customerToken` wins. Omitted, the one
61
+ * `setCustomerTokenResolver()` answers with for this render - see `customerToken.ts`. Set by
62
+ * the trusted layer only, from its cookie: the token never reaches page code. Null: a guest,
63
+ * never the resolver - a client made for one request (the RPC endpoint), which must not pick
64
+ * up the token of another visitor's render running at the same moment.
65
+ */
66
+ customerToken?: string | null;
67
+ /**
68
+ * The country the visitor is in ("NZ"), answered as `getSiteInfo().visitorCountry`. Omitted,
69
+ * the one `setVisitorCountryResolver()` answers with for this render - see
70
+ * `visitorCountry.ts`. Null: unknown, never the resolver - a client made for one request.
71
+ */
72
+ visitorCountry?: string | null;
73
+ /** Injected for tests, and for callers with their own fetch wrapper (caching, retries). */
74
+ fetchImpl?: typeof fetch;
75
+ timeoutMs?: number;
76
+ }
77
+ /**
78
+ * The public API, bound to one company by its key.
79
+ *
80
+ * Every method here maps to a route that exists. A page list is not among them, so it is
81
+ * absent rather than stubbed.
82
+ *
83
+ * The listings and single-category read take `include`, the optional parts of each row. The
84
+ * API sends none of them unless asked; this client asks for ALL of them unless the caller
85
+ * narrows the list — pages written before `include` existed keep rendering images and
86
+ * settings, and a page that wants a lighter response says which parts it needs.
87
+ */
88
+ export interface PublicApiClient {
89
+ /** The company the key belongs to, minus the key itself. */
90
+ getCompany(): Promise<PublicCompany>;
91
+ /** The same record as a *site*: what a page renders in its header and its `<head>`. */
92
+ getSiteInfo(): Promise<PublicSiteInfo>;
93
+ /**
94
+ * Active categories, in the order the author arranged them. A plain array — this route is
95
+ * not paginated, so `limit` is applied to the answer rather than to the request.
96
+ */
97
+ getCategories(params?: ListCategoriesParams): Promise<PublicCategory[]>;
98
+ /** One category by `id`, or by what it is CALLED. See `GetCategoryParams`. */
99
+ getCategory(params: GetCategoryParams): Promise<PublicCategory>;
100
+ /** Active products. PAGINATED — the list is under `.data`, unlike categories. */
101
+ getProducts(params?: ListProductsParams): Promise<Paginated<PublicProduct>>;
102
+ /**
103
+ * One product by `id`, or by what it is called — the counterpart of `getCategory`.
104
+ *
105
+ * A page written by hand can say "Pizza Margherita"; a page holding a row from a listing
106
+ * passes its `id`. Always carries every part — the same settings, media and prices as a
107
+ * full listing row.
108
+ */
109
+ getProduct(params: GetProductParams): Promise<PublicProduct>;
110
+ /**
111
+ * The shop's own settings CATALOGUE: which fields it keeps on a product, what kind of value
112
+ * each holds, and which of them it shows. A plain array — the response wraps it in
113
+ * `{ settings }` and this unwraps it, the way `getCategories` flattens its own answer.
114
+ *
115
+ * For one product's values, read `product.settings`: the same keys, described, with what
116
+ * that product holds.
117
+ *
118
+ * Only the fields the shop has switched on and lets websites read: a field it keeps private
119
+ * (a SKU, a cost, a supplier) is in neither answer.
120
+ */
121
+ getProductSettings(params?: {
122
+ /** Only the yes/no fields — the same set `getProducts({ tags })` filters against. */
123
+ tagsOnly?: boolean;
124
+ }): Promise<PublicProductSettingDefinition[]>;
125
+ /**
126
+ * Every list the shop can read — its own, then the platform's (currencies, languages) —
127
+ * with the columns their entries carry, but not the entries. Find a list here, read its
128
+ * entries with `getDictionary({ identifier })`.
129
+ *
130
+ * Only the lists the shop marked "Visible on site" in the admin; a list it keeps private is
131
+ * not here, and a column it keeps private is left out of every list.
132
+ */
133
+ listDictionaries(): Promise<PublicDictionarySummary[]>;
134
+ /**
135
+ * The shop's locations, in its own order — for a "find us" list or a map. Not split by
136
+ * workspace: a location is a place. Empty for a shop that has entered none.
137
+ */
138
+ getLocations(): Promise<PublicStoreLocation[]>;
139
+ /** A table a guest is ordering from, by the id on its QR code: its name, and whether it is open. */
140
+ getDiningTable(params: {
141
+ tableId: string;
142
+ }): Promise<PublicDiningTable>;
143
+ /** Checks the code staff gave a guest at this table; rejects a wrong one. Books nothing. */
144
+ verifyDiningTableCode(params: {
145
+ tableId: string;
146
+ code: string;
147
+ }): Promise<void>;
148
+ /**
149
+ * The shop's terms and privacy policy - whether customers must accept them, and the text it
150
+ * wrote (Markdown) in the visitor's language. Shown at sign-up and to a signed-in customer
151
+ * with `terms` among their `missingFields`; accepted with `acceptTerms: true` on their account.
152
+ */
153
+ getTerms(params?: {
154
+ language?: string;
155
+ }): Promise<PublicTerms>;
156
+ /**
157
+ * The times a party can book on a day at one location — every half hour it is open, each
158
+ * saying whether a table that seats them is free. Refused while the shop takes no bookings
159
+ * (`getSiteInfo().reservationMode` not `off`).
160
+ */
161
+ getBookingSlots(params: GetBookingSlotsParams): Promise<PublicBookingSlots>;
162
+ /**
163
+ * When an order can be for — now, and the later times on the location's clock. Empty `days`
164
+ * when the shop does not let customers choose a time.
165
+ */
166
+ getOrderTimes(params?: GetOrderTimesParams): Promise<PublicOrderTimes>;
167
+ /** The location's floor plan at a time: what to draw, which tables are free, the best fit. */
168
+ getBookingPlan(params: GetBookingPlanParams): Promise<PublicBookingPlan>;
169
+ /**
170
+ * Book a table — confirmed at once. Refused (409) when no table is free any more; pick
171
+ * another time.
172
+ */
173
+ createBooking(params: CreateBookingParams): Promise<PublicBooking>;
174
+ /**
175
+ * Emails the visitor a six-digit sign-in code — only while `customerSignInMethods.email`.
176
+ * There is no separate sign-up: an email the shop does not know becomes a
177
+ * customer. Refused (429) when a code went to that email under two minutes ago.
178
+ */
179
+ requestSignInCode(params: RequestSignInCodeParams): Promise<{
180
+ expiresIn: number;
181
+ }>;
182
+ /**
183
+ * Signs in with the emailed code. Keep the `token` it answers with where only the site's
184
+ * server can read it (an httpOnly cookie), and pass it as `customerToken`.
185
+ */
186
+ verifySignInCode(params: VerifySignInCodeParams): Promise<PublicCustomerSession>;
187
+ /** Signs in with the ID token Google Identity Services gave the page. */
188
+ signInWithGoogle(params: SignInWithGoogleParams): Promise<PublicCustomerSession>;
189
+ /**
190
+ * Signs in with the ID token the platform's Apple popup posted back, and the name Apple sent
191
+ * beside it (the first sign-in only).
192
+ */
193
+ signInWithApple(params: SignInWithAppleParams): Promise<PublicCustomerSession>;
194
+ /**
195
+ * Trades a refresh token for a new session — a new `token` AND a new `refreshToken`; the one
196
+ * sent is spent. 401 when it is unknown, run out, spent, or for another shop: sign out.
197
+ * Server side only, like the sign-ins: neither token may reach the browser.
198
+ */
199
+ refreshCustomerToken(params: RefreshCustomerTokenParams): Promise<PublicCustomerSession>;
200
+ /** Ends the session the refresh token belongs to. Quiet for one already gone. */
201
+ signOutCustomer(params: RefreshCustomerTokenParams): Promise<void>;
202
+ /** The signed-in customer, with their recent orders and bookings. 401 when the token lapsed. */
203
+ getCustomerAccount(params: CustomerTokenParams): Promise<PublicCustomerAccount>;
204
+ /** The signed-in customer's orders on this site, newest first. */
205
+ getCustomerOrders(params: CustomerTokenParams & CustomerHistoryParams): Promise<CustomerPage<PublicCustomerOrder>>;
206
+ /** One of their orders, with its lines. Rejects (404) for an order that is not theirs. */
207
+ getCustomerOrder(params: CustomerTokenParams & {
208
+ orderId: string;
209
+ }): Promise<PublicCustomerOrderDetail>;
210
+ /** Their bookings — upcoming by default. */
211
+ getCustomerBookings(params: CustomerTokenParams & CustomerBookingsParams): Promise<CustomerPage<PublicCustomerBooking>>;
212
+ /**
213
+ * Calls off one of their bookings — only while it is still ahead and not yet seated. Answers
214
+ * with the booking, now `cancelled`.
215
+ */
216
+ cancelCustomerBooking(params: CustomerTokenParams & {
217
+ /** The booking - its `bookingNumber` (`12`) or its `bookingId`. */
218
+ bookingId: string | number;
219
+ }): Promise<PublicCustomerBooking>;
220
+ /**
221
+ * Sets the dishes they order ahead for one of their bookings - every dish and how many,
222
+ * replacing what was there; empty takes the preorder away. Kept as the booking's unpaid order,
223
+ * paid at the table. Refused once the booking is no longer theirs to change
224
+ * (`cancellableUntil`). Answers with the preorder as kept, or null.
225
+ */
226
+ setCustomerBookingPreorder(params: SetBookingPreorderParams): Promise<{
227
+ preorder: PublicBookingPreorder | null;
228
+ }>;
229
+ /** The places they have had orders delivered to, or saved - the one used last first. */
230
+ getCustomerAddresses(params: CustomerTokenParams): Promise<{
231
+ data: PublicCustomerAddress[];
232
+ }>;
233
+ /** Saves an address for them; the same one again only moves its `lastUsedAt`. */
234
+ addCustomerAddress(params: AddCustomerAddressParams): Promise<PublicCustomerAddress>;
235
+ /** Forgets one of their addresses. */
236
+ deleteCustomerAddress(params: CustomerTokenParams & {
237
+ customerAddressId: string;
238
+ }): Promise<void>;
239
+ /** The cards they saved paying here - brand, last four, expiry; nothing that can pay. */
240
+ getCustomerPaymentMethods(params: CustomerTokenParams): Promise<{
241
+ data: PublicCustomerPaymentMethod[];
242
+ }>;
243
+ /** Removes one of their saved cards. Refused (409) for one an upcoming booking keeps. */
244
+ deleteCustomerPaymentMethod(params: CustomerTokenParams & {
245
+ paymentMethodId: string;
246
+ }): Promise<void>;
247
+ /**
248
+ * Their favourite products, as `getProducts` lists them - the same paging, `include` and
249
+ * filters, limited to the ones they added.
250
+ */
251
+ getCustomerFavourites(params: CustomerTokenParams & ListProductsParams): Promise<Paginated<PublicProduct>>;
252
+ /** Just their favourites' ids, newest first - to fill in the hearts on a listing. */
253
+ getCustomerFavouriteIds(params: CustomerTokenParams): Promise<{
254
+ productIds: string[];
255
+ }>;
256
+ /** Adds a product to their favourites; one already there stays once. */
257
+ addCustomerFavourite(params: CustomerTokenParams & {
258
+ productId: string;
259
+ }): Promise<void>;
260
+ /** Takes a product out of their favourites; one not there is no error. */
261
+ removeCustomerFavourite(params: CustomerTokenParams & {
262
+ productId: string;
263
+ }): Promise<void>;
264
+ /** Changes the signed-in customer's name or phone; their email stays. */
265
+ updateCustomerProfile(params: UpdateCustomerProfileParams): Promise<PublicCustomer>;
266
+ /**
267
+ * What a product takes — comments, stars, likes — and its totals. Any visitor may read it;
268
+ * pass `customerToken` for the signed-in customer's own stars.
269
+ */
270
+ getProductFeedback(params: GetProductFeedbackParams): Promise<PublicProductFeedback>;
271
+ /**
272
+ * A product's comments, newest first — roots only, each with its `replyCount`. With
273
+ * `parentId`, that root's replies, oldest first. Empty when the product takes no comments.
274
+ */
275
+ getProductComments(params: GetProductCommentsParams): Promise<PublicProductCommentsPage>;
276
+ /**
277
+ * Comments on a product as the signed-in customer, or replies with `parentId`. 403 when the
278
+ * product takes no comments (`getProductFeedback().allowComments`).
279
+ */
280
+ createProductComment(params: CreateProductCommentParams): Promise<PublicProductComment>;
281
+ /** Removes one of the signed-in customer's own comments; a root goes with its replies. */
282
+ deleteProductComment(params: DeleteProductCommentParams): Promise<void>;
283
+ /**
284
+ * The signed-in customer's vote on a product, the shop's way (`productVoting`): stars or a
285
+ * like / dislike. A new one replaces theirs. Answers with the product's votes. 403 when the
286
+ * product takes none, 400 for a vote the other way.
287
+ */
288
+ rateProduct(params: RateProductParams): Promise<PublicProductRating>;
289
+ /** Takes the signed-in customer's vote on a product back. */
290
+ unrateProduct(params: UnrateProductParams): Promise<PublicProductRating>;
291
+ /**
292
+ * The signed-in customer's vote on a comment, the shop's way (`commentVoting`); 0 takes it
293
+ * back. Answers with the comment's votes.
294
+ */
295
+ voteProductComment(params: VoteProductCommentParams): Promise<PublicCommentVoteResult>;
296
+ /**
297
+ * The combos on sale NOW — active, inside their dates and inside one of their weekly windows
298
+ * at the moment of the request — in the shop's order, each with its slots and the products
299
+ * that may fill them. Pass `categoryId` for the ones the shop displays in that category.
300
+ */
301
+ getCombos(params?: ListCombosParams): Promise<PublicCombo[]>;
302
+ /**
303
+ * The discount rules on now, for badging the products they target. Display only: the cart
304
+ * decides which rule a unit actually takes.
305
+ */
306
+ getDiscountRules(): Promise<PublicDiscountRule[]>;
307
+ /**
308
+ * One of the shop's own lists, by `identifier`, by `id` or by name — its sizes, its add-ons,
309
+ * its ingredients.
310
+ *
311
+ * `identifier` is the handle the shop gave the list (`"add_ons"`): set once, never changed,
312
+ * and shown on the list's own page in the admin. Write pages against it — the label is
313
+ * translated and reworded, so a page reading by name breaks when the shop renames the list.
314
+ *
315
+ * What a product carries is the NAMES it uses out of a list; this is the list itself, with
316
+ * the columns each entry holds. A page that prices an add-on reads it here, because the
317
+ * surcharge is a fact about the entry rather than about any product offering it.
318
+ *
319
+ * A list the shop keeps private (not "Visible on site") answers 404 exactly like a missing
320
+ * one, and a private column is left out of `columns` and of every entry's `values`.
321
+ */
322
+ getDictionary(params: GetDictionaryParams): Promise<PublicDictionary>;
323
+ /**
324
+ * Several lists in ONE request, by identifier — the batch form of `getDictionary`.
325
+ *
326
+ * A page that needs many lists (a menu's sizes, add-ons, bases, …) reads them all in a single
327
+ * round trip instead of one each. The answer is the lists that exist, each carrying its own
328
+ * `identifier` to match back against what was asked; an identifier with no list is simply
329
+ * absent (not an error), so map by `identifier` rather than by position. A private list is
330
+ * absent the same way.
331
+ */
332
+ getDictionaries(params: {
333
+ identifiers: string[];
334
+ }): Promise<PublicDictionary[]>;
335
+ /**
336
+ * Size and resized copies of pictures the site holds only as URLs — a "Site images" entry, a
337
+ * size's drawing, a location photo — so `Image` can serve them like a product's photos.
338
+ *
339
+ * Answers only for the shop's own media and the platform's shared images that have copies;
340
+ * any other URL is left out, and is drawn from the URL as it is. At most 200 per call.
341
+ */
342
+ lookupImages(params: {
343
+ urls: string[];
344
+ }): Promise<PublicImage[]>;
345
+ /**
346
+ * The basket, held by the server so it survives a reload.
347
+ *
348
+ * `createCart` first; everything after it needs the `cartId` that returns. The server also
349
+ * sets that id as a cookie, so a browser on the same site can omit it — but this client
350
+ * passes it explicitly whenever it has one, because a server component has no cookie jar and
351
+ * because an explicit id cannot be silently swapped by whatever the jar happens to hold.
352
+ *
353
+ * Every call answers with the WHOLE cart, so a caller never has to reconstruct it from a
354
+ * response describing only what changed.
355
+ */
356
+ createCart(): Promise<PublicCart>;
357
+ getCart(params: GetCartParams): Promise<PublicCart>;
358
+ /** Adds, or increases a line already there — lines are (product, variantId, variant). */
359
+ addCartItem(params: AddCartItemParams): Promise<PublicCart>;
360
+ /** Zero removes the line, so a stepper needs no second call. */
361
+ setCartItemQuantity(params: SetCartItemQuantityParams): Promise<PublicCart>;
362
+ removeCartItem(params: RemoveCartItemParams): Promise<PublicCart>;
363
+ /** Say which table booking the basket is ordered for - or none. */
364
+ setCartBooking(params: SetCartBookingParams): Promise<PublicCart>;
365
+ destroyCart(params: GetCartParams): Promise<void>;
366
+ /**
367
+ * Turn the basket into a checkout, and get the page that takes the payment.
368
+ *
369
+ * The answer's `checkoutUrl` is where the SHOPPER goes — redirect their browser to it. The
370
+ * page asks for their email unless `customerEmail` was given, shows the order, takes the card
371
+ * (saving it only if they choose), and sends them back to `successUrl` once paid. The cart moves to `checkout` now, and to `paid` when Stripe
372
+ * confirms.
373
+ */
374
+ createCheckout(params: CreateCheckoutParams): Promise<PublicCheckout>;
375
+ /**
376
+ * Read a checkout — including what is needed to take the card in the page itself.
377
+ *
378
+ * The id is the credential, exactly as a cart id is: the route takes no key, because the
379
+ * page that charges may be a browser. While the checkout can still be paid the answer
380
+ * carries `payment`, which Stripe's Elements mount against; once it is paid or cancelled
381
+ * that is gone and `status` is the answer.
382
+ */
383
+ getCheckout(params: GetCheckoutParams): Promise<PublicCheckoutSession>;
384
+ /**
385
+ * Record who is paying, from the site's own payment page — the receipt goes there, and it is
386
+ * how a card they saved at this shop is offered again. Answers with the checkout as
387
+ * `getCheckout` would, its `payment` now carrying `customerSessionClientSecret`. Like
388
+ * `getCheckout`, the id is the credential; refused once the checkout can no longer be paid.
389
+ */
390
+ setCheckoutEmail(params: SetCheckoutEmailParams): Promise<PublicCheckoutSession>;
391
+ /**
392
+ * Find a placed order for the shop's tracking page - signed in or not: its `number` (`1042`,
393
+ * `#1042`, or the delivery's `D-17`) with the `email` it was placed with, or `checkoutId`
394
+ * alone. Answers as `getCustomerOrder` does, with `shipment` once a carrier has it. Every
395
+ * mismatch is the same 404 (`order_track_not_found`); limited per visitor (429). Never cached.
396
+ */
397
+ trackOrder(params: TrackOrderParams): Promise<PublicCustomerOrderDetail>;
398
+ }
399
+ /**
400
+ * Build a client.
401
+ *
402
+ * Whose data it reads is decided entirely by the key, and that is the whole design. A client
403
+ * that took a domain per call would let whoever held one read any company; a client that took
404
+ * one at construction still made every caller carry a value the server does not read. Neither
405
+ * is here any more.
406
+ */
407
+ export declare function createPublicApiClient(config: PublicApiConfig): PublicApiClient;
package/dist/client.js ADDED
@@ -0,0 +1,14 @@
1
+ import {
2
+ createPublicApiClient
3
+ } from "./chunks/chunk-5DN7L6LX.js";
4
+ import "./chunks/chunk-2BH4QPV2.js";
5
+ import "./chunks/chunk-2554RPSS.js";
6
+ import "./chunks/chunk-TSERNR4R.js";
7
+ import "./chunks/chunk-OFFTL6RC.js";
8
+ import "./chunks/chunk-GJZ7EZEF.js";
9
+ import "./chunks/chunk-HFEQWXG6.js";
10
+ import "./chunks/chunk-3KEEGSMP.js";
11
+ export {
12
+ createPublicApiClient
13
+ };
14
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": [],
4
+ "sourcesContent": [],
5
+ "mappings": "",
6
+ "names": []
7
+ }
@@ -0,0 +1,9 @@
1
+ /** Set it, or pass null/empty to fall back to the config and the environment. */
2
+ export declare function setCompanyApiKey(key: string | null | undefined): void;
3
+ /**
4
+ * What is currently set, or null.
5
+ *
6
+ * Returns the key itself, so treat it as the secret it is: it belongs in a request header,
7
+ * never in a log line, an error message or anything a page renders.
8
+ */
9
+ export declare function getCompanyApiKey(): string | null;
@@ -0,0 +1,9 @@
1
+ import {
2
+ getCompanyApiKey,
3
+ setCompanyApiKey
4
+ } from "./chunks/chunk-TSERNR4R.js";
5
+ export {
6
+ getCompanyApiKey,
7
+ setCompanyApiKey
8
+ };
9
+ //# sourceMappingURL=companyApiKey.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": [],
4
+ "sourcesContent": [],
5
+ "mappings": "",
6
+ "names": []
7
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * The signed-in customer a render is made for, for every call it makes.
3
+ *
4
+ * A shop may show itself to signed-in customers only (`customerAccess: signed_in`): the API then
5
+ * refuses a guest its catalogue, cart, checkout and bookings. A page's reads are made on the
6
+ * server, which knows the visitor only by the request's cookie - so the render tier reads the
7
+ * token from that cookie and sets a resolver here for the length of one render, the same way it
8
+ * sets the language (`language.ts`). Every call then carries `x-customer-token` without page
9
+ * code passing anything - page code never sees the token.
10
+ *
11
+ * A call that names its own `customerToken` keeps it; nothing set here means a guest's calls.
12
+ */
13
+ export type CustomerTokenResolver = () => string | null | undefined;
14
+ export declare function setCustomerTokenResolver(next: CustomerTokenResolver | null): void;
15
+ /** The resolver in force, so the render tier can put back exactly what was there. */
16
+ export declare function getCustomerTokenResolver(): CustomerTokenResolver | null;
17
+ /** The token to send, or undefined for a guest. Never throws. */
18
+ export declare function resolveCustomerToken(): string | undefined;
@@ -0,0 +1,11 @@
1
+ import {
2
+ getCustomerTokenResolver,
3
+ resolveCustomerToken,
4
+ setCustomerTokenResolver
5
+ } from "./chunks/chunk-OFFTL6RC.js";
6
+ export {
7
+ getCustomerTokenResolver,
8
+ resolveCustomerToken,
9
+ setCustomerTokenResolver
10
+ };
11
+ //# sourceMappingURL=customerToken.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": [],
4
+ "sourcesContent": [],
5
+ "mappings": "",
6
+ "names": []
7
+ }
@@ -0,0 +1,41 @@
1
+ /**
2
+ * One error type, and deliberately uninformative.
3
+ *
4
+ * The message can end up rendered by a page — the runtime hands it straight to page code as
5
+ * the reason a capability failed — so it names a status and nothing else. The internal URL,
6
+ * the base host and the key are exactly what must not travel with it.
7
+ */
8
+ /** What a refusal says beyond its status and sentence - see `PublicApiError`. */
9
+ export interface RefusalFacts {
10
+ code?: string;
11
+ missingFields?: string[];
12
+ }
13
+ /** The refusal facts in an API answer's body (or a relayed error), keeping only well-formed ones. */
14
+ export declare function refusalFactsOf(body: unknown): RefusalFacts;
15
+ export declare class PublicApiError extends Error {
16
+ readonly status?: number;
17
+ /**
18
+ * What the SERVER said, when it said anything.
19
+ *
20
+ * Kept apart from `message`, which stays terse and safe to render anywhere. This is the
21
+ * server's own sentence — "Amount must convert to at least 50 cents", "One or more products
22
+ * not found" — and it is the only part that tells a caller what to do differently. Without
23
+ * it a page could say nothing better than "that did not work", while the reason sat in a
24
+ * log nobody was reading.
25
+ *
26
+ * Shown at the CALLER's discretion, because only the caller knows who is reading. A shop's
27
+ * own admin screen can print it; a page facing a shopper should decide case by case.
28
+ */
29
+ readonly detail?: string;
30
+ /**
31
+ * The refusal's machine-readable `code` (`customer_sign_in_required`, `customer_details_required`),
32
+ * when the API gave one - what a page branches on, unlike the sentence in `detail`.
33
+ */
34
+ readonly code?: string;
35
+ /**
36
+ * The details a signed-in customer still owes, with `customer_details_required` - so a page asks
37
+ * for exactly those without reading the account first.
38
+ */
39
+ readonly missingFields?: string[];
40
+ constructor(reason: string, status?: number, detail?: string, refusal?: RefusalFacts);
41
+ }
package/dist/errors.js ADDED
@@ -0,0 +1,9 @@
1
+ import {
2
+ PublicApiError,
3
+ refusalFactsOf
4
+ } from "./chunks/chunk-GJZ7EZEF.js";
5
+ export {
6
+ PublicApiError,
7
+ refusalFactsOf
8
+ };
9
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": [],
4
+ "sourcesContent": [],
5
+ "mappings": "",
6
+ "names": []
7
+ }
@@ -0,0 +1,82 @@
1
+ /**
2
+ * `@estoreclub/api` — the client for the server's PUBLIC company API.
3
+ *
4
+ * One place knows how a site's data becomes an HTTP request: the URLs, the key header, the
5
+ * timeout, the paging clamp. Everything else asks this.
6
+ *
7
+ * Two ways in, on purpose:
8
+ *
9
+ * - **`getSiteInfo` / `getCategories` / `getCategory` / `getProducts` / `getProduct` /
10
+ * `listDictionaries` / `getDictionary`** — the site's own data,
11
+ * read through a client configured once from the environment. This is what PAGE CODE
12
+ * imports, and it is server-only: `COMPANY_API_KEY` is a secret.
13
+ * - **`createPublicApiClient`** — the client itself, for a caller that gets the key from
14
+ * something other than the environment (a request, a test, a tool reading several sites).
15
+ *
16
+ * It is deliberately small and dependency-free — one `fetch`, no framework, no React, no node
17
+ * builtins — so it runs in a Next server component, a script and a test alike.
18
+ *
19
+ * **It knows nothing about domains.** Every public route authenticates with
20
+ * `x-company-api-key` and the server resolves the company from that key, so the key IS the
21
+ * answer to whose data is read. Turning a host or a deployment id into one is the job of the
22
+ * trusted layer in front of the page, which holds the platform key; page code supplies
23
+ * parameters and nothing else — never a domain, never a URL, never a key.
24
+ */
25
+ export { createPublicApiClient, type PublicApiClient, type PublicApiConfig, } from "./client";
26
+ export { getSiteInfo, getCategories, getCategory, getProducts, getProduct, listDictionaries, getDictionary, getDictionaries, lookupImages, getLocations, getDiningTable, verifyDiningTableCode, getTerms, getBookingSlots, getBookingPlan, getOrderTimes, createBooking, getProductSettings, getCombos, getDiscountRules, resetSiteData, } from "./siteData";
27
+ /**
28
+ * The basket, held by the server so it survives a reload.
29
+ *
30
+ * `createCart()` answers with an id that every other call needs, and that id is the credential
31
+ * for the cart: keep it out of URLs and out of anything a page renders.
32
+ */
33
+ export { createCart, getCart, addCartItem, setCartItemQuantity, removeCartItem, setCartBooking, destroyCart, } from "./siteData";
34
+ /**
35
+ * Paying for the basket, either way round.
36
+ *
37
+ * `createCheckout` answers with `checkoutUrl` — the hosted payment page the shopper's browser
38
+ * is sent to; the platform takes the card and returns them to the site. A site that would
39
+ * rather keep the shopper on its own page passes that same checkout's id to `getCheckout` and
40
+ * mounts Stripe's Elements on what comes back; `setCheckoutEmail` records the shopper there.
41
+ */
42
+ export { createCheckout, getCheckout, setCheckoutEmail } from "./siteData";
43
+ /**
44
+ * The shop's order-tracking page, signed in or not: an order number (or delivery's `D-17`) with
45
+ * the email it was placed with, or a checkout id alone, answers with the order and its shipment.
46
+ */
47
+ export { trackOrder } from "./siteData";
48
+ /**
49
+ * Customers signing in on the site, the ways the shop allows (`getSiteInfo().customerSignInMethods`).
50
+ * A sign-in answers with a token; pass it as `customerToken` and what is made with it — a
51
+ * checkout, a booking — belongs to the customer. Keep it in an httpOnly cookie, server side.
52
+ */
53
+ export { requestSignInCode, verifySignInCode, signInWithGoogle, signInWithApple, getCustomerAccount, getCustomerOrders, getCustomerOrder, getCustomerBookings, cancelCustomerBooking, setCustomerBookingPreorder, getCustomerAddresses, addCustomerAddress, deleteCustomerAddress, getCustomerPaymentMethods, deleteCustomerPaymentMethod, getCustomerFavourites, getCustomerFavouriteIds, addCustomerFavourite, removeCustomerFavourite, updateCustomerProfile, } from "./siteData";
54
+ /**
55
+ * What customers say about a product: the switches and totals, its comments and their replies.
56
+ * Reads take an optional `customerToken` (for `mine`); a comment needs one.
57
+ */
58
+ export { getProductFeedback, getProductComments, createProductComment, deleteProductComment, rateProduct, unrateProduct, voteProductComment, } from "./siteData";
59
+ /**
60
+ * The key every scoped call authenticates with, for the whole process. Set by the trusted
61
+ * layer once it has done the exchange — see `companyApiKey.ts`.
62
+ */
63
+ export { setCompanyApiKey, getCompanyApiKey } from "./companyApiKey";
64
+ /**
65
+ * Which language the reads answer in, asked per request — see `language.ts`. Set by the site
66
+ * once, like the key.
67
+ */
68
+ export { setLanguageResolver, getLanguageResolver, type LanguageResolver, } from "./language";
69
+ /**
70
+ * Who the render is made for - the signed-in customer, from the request's cookie - asked per
71
+ * call. Set by the render tier for one render; see `customerToken.ts`.
72
+ */
73
+ export { setCustomerTokenResolver, getCustomerTokenResolver, type CustomerTokenResolver, } from "./customerToken";
74
+ /**
75
+ * The visitor's country, per render - see `visitorCountry.ts`. Set by the render tier from the
76
+ * request; a page reads it as `getSiteInfo().visitorCountry`.
77
+ */
78
+ export { setVisitorCountryResolver, getVisitorCountryResolver, countryFromHeaders, type VisitorCountryResolver, } from "./visitorCountry";
79
+ export { PublicApiError } from "./errors";
80
+ export { MAX_LIMIT } from "./params";
81
+ export { runWithRequestCache } from "./requestCache";
82
+ export type { AddCartItemParams, CheckoutStatus, CreateBookingParams, GetBookingPlanParams, GetBookingSlotsParams, ReservationKind, GetOrderTimesParams, PublicBooking, PublicBookingEntry, PublicBookingPlan, PublicBookingSlot, PublicBookingSlots, PublicReservationPayment, ReservationPaymentTiming, PublicOrderTime, PublicOrderTimes, PublicPlanItem, PublicPlanTable, ComboPick, ComboPriceKind, CreateCheckoutParams, CustomerTokenParams, CustomerField, CustomerConsent, CustomerRequiredFields, CurrencySymbolPosition, ByIdOrName, GetCartParams, GetCategoryParams, GetCheckoutParams, TrackOrderParams, GetDictionaryParams, GetProductParams, ListCategoriesParams, ListCombosParams, ListProductsParams, Paginated, PaginationMetadata, DiscountRuleKind, PublicCart, PublicCartCombo, PublicCartComboPick, PublicCartDiscount, PublicCartItem, PublicCombo, PublicComboSlot, PublicComboSlotOption, PublicComboVariant, PublicDealSchedule, PublicDiscountRule, PublicCheckout, PublicCheckoutPayment, PublicCheckoutSession, PublicCategory, PublicCategoryInclude, PublicCustomer, PublicCustomerAccount, PublicCustomerBooking, PublicBookingPreorder, PublicBookingPreorderLine, SetBookingPreorderParams, PublicCustomerAddress, PublicCustomerPaymentMethod, AddCustomerAddressParams, PublicCustomerOrder, PublicCustomerOrderDetail, PublicCustomerOrderLine, PublicCustomerOrderProgress, PublicCustomerOrderShipment, PublicCustomerSession, CustomerPage, CustomerHistoryParams, CustomerBookingsParams, CreateProductCommentParams, DeleteProductCommentParams, GetProductCommentsParams, GetProductFeedbackParams, PublicProductComment, PublicProductCommentsPage, PublicProductFeedback, PublicProductRating, PublicCommentVoteResult, ProductVoting, RateProductParams, UnrateProductParams, VoteProductCommentParams, PublicCompany, PublicDictionary, PublicDictionaryColumn, PublicDictionaryColumnType, PublicDictionaryEntry, PublicDictionarySummary, PublicLanguage, PublicImage, PublicMedia, PublicProduct, PublicProductVariant, PublicProductCategoryRef, PublicProductInclude, ProductSort, PublicProductSetting, PublicProductSettingDefinition, PublicProductSettingRange, PublicProductSettingType, OrderLocationMode, CustomerAccess, OrderType, PublicPaymentDiscount, PublicPaymentDiscounts, PublicSiteInfo, PublicStoreLocation, PublicDiningTable, PublicTerms, RemoveCartItemParams, SetCartBookingParams, RequestSignInCodeParams, SetCartItemQuantityParams, SetCheckoutEmailParams, SignInWithGoogleParams, SignInWithAppleParams, RefreshCustomerTokenParams, UpdateCustomerProfileParams, VerifySignInCodeParams, Workspace, } from "./types";