order3000 1.1.0 → 1.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/dist/client.mjs CHANGED
@@ -115,13 +115,9 @@ class BaseResource {
115
115
  "Content-Type": "application/json"
116
116
  },
117
117
  body: data ? JSON.stringify(data) : void 0,
118
- signal: AbortSignal.timeout(36e4)
118
+ signal: AbortSignal.timeout(36e4),
119
+ cache: cacheOptions?.cache ?? "no-store"
119
120
  };
120
- if (cacheOptions?.next !== void 0) {
121
- init.next = cacheOptions.next;
122
- } else {
123
- init.cache = cacheOptions?.cache ?? "no-store";
124
- }
125
121
  const response = await fetch(url, init);
126
122
  if (!response.ok) {
127
123
  let body = "";
@@ -169,6 +165,71 @@ class BaseResource {
169
165
  }
170
166
  }
171
167
 
168
+ class AdsResource extends BaseResource {
169
+ constructor(tokenManager, baseUrl) {
170
+ super(tokenManager, baseUrl, "/ads");
171
+ }
172
+ /**
173
+ * List the venue's ads, ordered by `createdAt`. Optionally filter by
174
+ * `ownerEntityType` (e.g. `event`), `ownerEntityId`, or `channel` (e.g.
175
+ * `google`). Each ad carries its paste-ready Google Search Ad `content`
176
+ * document and lifecycle `status`.
177
+ */
178
+ async list(options) {
179
+ const params = new URLSearchParams();
180
+ if (options?.ownerEntityType) {
181
+ params.set("ownerEntityType", options.ownerEntityType);
182
+ }
183
+ if (options?.ownerEntityId) {
184
+ params.set("ownerEntityId", options.ownerEntityId);
185
+ }
186
+ if (options?.channel) {
187
+ params.set("channel", options.channel);
188
+ }
189
+ const qs = params.toString();
190
+ const path = qs ? `?${qs}` : "";
191
+ return this.request("GET", path);
192
+ }
193
+ /**
194
+ * Fetch a single ad by id within the active venue. Ads have no accessor
195
+ * — the lookup is always by uuid. Returns the full row including the
196
+ * `content` document and `status`.
197
+ */
198
+ async get(adId) {
199
+ return this.request("GET", `/${encodeURIComponent(adId)}`);
200
+ }
201
+ /**
202
+ * Create a new ad for a polymorphic owner entity (an event today). Copy
203
+ * + status take the DB defaults (empty content, `draft`) and are
204
+ * populated later via {@link patch}. Returns the created ad.
205
+ */
206
+ async create(body) {
207
+ return this.request("POST", "", body);
208
+ }
209
+ /**
210
+ * Partial-update an ad by id. Pass `content` to write paste-ready Google
211
+ * Responsive Search Ad copy (the char-limit + count validation is the
212
+ * self-heal contract) and/or `status` to move the ad through its
213
+ * lifecycle. Returns the resulting ad.
214
+ */
215
+ async patch(adId, body) {
216
+ return this.request(
217
+ "PATCH",
218
+ `/${encodeURIComponent(adId)}`,
219
+ body
220
+ );
221
+ }
222
+ /**
223
+ * Permanently delete an ad by id. Returns the deleted ad row.
224
+ */
225
+ async delete(adId) {
226
+ return this.request(
227
+ "DELETE",
228
+ `/${encodeURIComponent(adId)}`
229
+ );
230
+ }
231
+ }
232
+
172
233
  class AreasResource extends BaseResource {
173
234
  constructor(tokenManager, baseUrl) {
174
235
  super(tokenManager, baseUrl, "/areas");
@@ -181,11 +242,12 @@ class AreasResource extends BaseResource {
181
242
  return this.request("GET", queryString);
182
243
  }
183
244
  /**
184
- * Fetch a single area by id or accessor.
245
+ * Fetch a single area by id or accessor. The server resolves either
246
+ * form transparently.
185
247
  */
186
- async getByAccessor(accessor, options) {
248
+ async get(idOrAccessor, options) {
187
249
  const queryString = this.buildExpandQuery(options?.expand);
188
- return this.request("GET", `/${accessor}${queryString}`);
250
+ return this.request("GET", `/${idOrAccessor}${queryString}`);
189
251
  }
190
252
  /**
191
253
  * List occupied date/time windows for an area between `from` and `to`.
@@ -246,9 +308,10 @@ class ArticlesResource extends BaseResource {
246
308
  }
247
309
  /**
248
310
  * Fetch a single article by id or accessor within the active venue.
249
- * Returns the full row including the TipTap `content` document.
311
+ * The server resolves either form transparently. Returns the full row
312
+ * including the TipTap `content` document.
250
313
  */
251
- async getByAccessor(idOrAccessor) {
314
+ async get(idOrAccessor) {
252
315
  return this.request("GET", `/${encodeURIComponent(idOrAccessor)}`);
253
316
  }
254
317
  /**
@@ -319,6 +382,34 @@ class ArticlesResource extends BaseResource {
319
382
  }
320
383
  }
321
384
 
385
+ class AssetsResource extends BaseResource {
386
+ constructor(tokenManager, baseUrl) {
387
+ super(tokenManager, baseUrl, "/assets");
388
+ }
389
+ /**
390
+ * List a venue's ACTIVE assets carrying `tag`, ordered by `sortIndex`.
391
+ *
392
+ * A binding-agnostic query on the central `assets` table — an asset is
393
+ * returned regardless of whether it is bound to a ritual, dish, beverage,
394
+ * event, or is standalone. Each asset carries its resolved Supabase
395
+ * `publicUrl`.
396
+ *
397
+ * @param options - `tag` (required) + optional `type` filter
398
+ * @returns Array of assets with public URLs
399
+ */
400
+ async list(options) {
401
+ const queryParams = new URLSearchParams();
402
+ queryParams.set("tag", options.tag);
403
+ if (options.type) {
404
+ queryParams.set("type", options.type);
405
+ }
406
+ return this.request(
407
+ "GET",
408
+ `?${queryParams.toString()}`
409
+ );
410
+ }
411
+ }
412
+
322
413
  class BasketsResource extends BaseResource {
323
414
  constructor(tokenManager, baseUrl) {
324
415
  super(tokenManager, baseUrl, "/baskets");
@@ -449,27 +540,15 @@ class EventsResource extends BaseResource {
449
540
  return this.request("POST", "", event);
450
541
  }
451
542
  /**
452
- * Get a single event by ID
453
- * @param eventId - The event ID
454
- * @returns The event details
455
- */
456
- async get(eventId) {
457
- return this.request("GET", `/${eventId}`);
458
- }
459
- /**
460
- * Get an event by accessor (slug)
461
- * @param accessor - The event accessor (e.g., 'lunch-menu')
543
+ * Get a single event by id or accessor (slug), with optional `expand`
544
+ * parts. The server resolves either form transparently.
545
+ * @param idOrAccessor - The event UUID or accessor (e.g., 'lunch-menu')
462
546
  * @param options - Optional expand options
463
547
  * @returns The event with optional schedule, timeSlots, menus, and posters
464
548
  */
465
- async getByAccessor(accessor, options) {
549
+ async get(idOrAccessor, options) {
466
550
  const queryString = this.buildQueryString(options);
467
- return this.request(
468
- "GET",
469
- `/${accessor}${queryString}`,
470
- void 0,
471
- { next: { revalidate: 2700 } }
472
- );
551
+ return this.request("GET", `/${idOrAccessor}${queryString}`);
473
552
  }
474
553
  buildQueryString(options) {
475
554
  if (!options?.expand?.length) return "";
@@ -502,11 +581,11 @@ class EventsResource extends BaseResource {
502
581
  }
503
582
  /**
504
583
  * List the posters attached to an event. Convenience over
505
- * `getByAccessor(idOrAccessor, { expand: ['posters'] })` — returns the
584
+ * `get(idOrAccessor, { expand: ['posters'] })` — returns the
506
585
  * `posters[]` array (empty when the event has none).
507
586
  */
508
587
  async listPosters(idOrAccessor) {
509
- const event = await this.getByAccessor(idOrAccessor, {
588
+ const event = await this.get(idOrAccessor, {
510
589
  expand: ["posters"]
511
590
  });
512
591
  return event.posters ?? [];
@@ -547,24 +626,15 @@ class MenusResource extends BaseResource {
547
626
  super(tokenManager, baseUrl, "/menus");
548
627
  }
549
628
  /**
550
- * Get a menu by ID
551
- * @param id - The menu UUID
629
+ * Get a menu by id or accessor (slug), with optional `expand` parts.
630
+ * The server resolves either form transparently.
631
+ * @param idOrAccessor - The menu UUID or accessor (slug)
552
632
  * @param options - Optional expand options
553
633
  * @returns The menu with optional items and assets
554
634
  */
555
- async get(id, options) {
635
+ async get(idOrAccessor, options) {
556
636
  const queryString = this.buildQueryString(options);
557
- return this.request("GET", `/${id}${queryString}`);
558
- }
559
- /**
560
- * Get a menu by accessor
561
- * @param accessor - The menu accessor (slug)
562
- * @param options - Optional expand options
563
- * @returns The menu with optional items and assets
564
- */
565
- async getByAccessor(accessor, options) {
566
- const queryString = this.buildQueryString(options);
567
- return this.request("GET", `/${accessor}${queryString}`);
637
+ return this.request("GET", `/${idOrAccessor}${queryString}`);
568
638
  }
569
639
  /**
570
640
  * Get all bundles for a menu
@@ -693,20 +763,13 @@ class SubscriptionsResource extends BaseResource {
693
763
  super(tokenManager, baseUrl, "/subscriptions");
694
764
  }
695
765
  /**
696
- * Get a subscription by ID
697
- * @param id - The subscription UUID
698
- * @returns The subscription with posters
699
- */
700
- async get(id) {
701
- return this.request("GET", `/${id}`);
702
- }
703
- /**
704
- * Get a subscription by accessor
705
- * @param accessor - The subscription accessor (slug)
766
+ * Get a subscription by id or accessor (slug). The server resolves
767
+ * either form transparently.
768
+ * @param idOrAccessor - The subscription UUID or accessor (slug)
706
769
  * @returns The subscription with posters
707
770
  */
708
- async getByAccessor(accessor) {
709
- return this.request("GET", `/${accessor}`);
771
+ async get(idOrAccessor) {
772
+ return this.request("GET", `/${idOrAccessor}`);
710
773
  }
711
774
  /**
712
775
  * Subscribe a customer to a subscription plan via Stripe Checkout
@@ -959,7 +1022,7 @@ class VenuesResource {
959
1022
  * — the CLI hits this to prove the accessor exists and to cache the
960
1023
  * resolved UUID + display fields locally.
961
1024
  */
962
- async getByAccessor(idOrAccessor) {
1025
+ async get(idOrAccessor) {
963
1026
  const token = await this.tokenManager.getToken();
964
1027
  const url = `${this.baseUrl}/venues/${encodeURIComponent(idOrAccessor)}`;
965
1028
  const response = await fetch(url, {
@@ -1309,8 +1372,10 @@ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { en
1309
1372
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
1310
1373
  class O3KClient {
1311
1374
  constructor(config) {
1375
+ __publicField(this, "ads");
1312
1376
  __publicField(this, "areas");
1313
1377
  __publicField(this, "articles");
1378
+ __publicField(this, "assets");
1314
1379
  __publicField(this, "baskets");
1315
1380
  __publicField(this, "events");
1316
1381
  __publicField(this, "menus");
@@ -1331,8 +1396,10 @@ class O3KClient {
1331
1396
  tokenUrl,
1332
1397
  config.venueId
1333
1398
  );
1399
+ this.ads = new AdsResource(this.tokenManager, this.baseUrl);
1334
1400
  this.areas = new AreasResource(this.tokenManager, this.baseUrl);
1335
1401
  this.articles = new ArticlesResource(this.tokenManager, this.baseUrl);
1402
+ this.assets = new AssetsResource(this.tokenManager, this.baseUrl);
1336
1403
  this.baskets = new BasketsResource(this.tokenManager, this.baseUrl);
1337
1404
  this.events = new EventsResource(this.tokenManager, this.baseUrl);
1338
1405
  this.menus = new MenusResource(this.tokenManager, this.baseUrl);