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