@slotchain/sdk 1.2.4 → 1.4.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/index.cjs.js CHANGED
@@ -306,6 +306,10 @@ var BookingClient = class {
306
306
  /**
307
307
  * Create a new booking (publishes booking.created event)
308
308
  * POST /api/v1/bookings
309
+ *
310
+ * Provide either `slot_id` (explicit) or `tenant_id` (auto-resolve).
311
+ * When only `tenant_id` is given the API resolves the first active slot for that tenant,
312
+ * creating a default slot if none exists — so callers never need to manage slot IDs.
309
313
  */
310
314
  async create(data) {
311
315
  const response = await this.client.post(
@@ -314,6 +318,38 @@ var BookingClient = class {
314
318
  );
315
319
  return response.data;
316
320
  }
321
+ /**
322
+ * Create a booking for a specific service item (job posting, class, product, etc.)
323
+ * without requiring the caller to supply or know a slot ID.
324
+ *
325
+ * The API resolves the correct slot for the tenant automatically, creating a
326
+ * default slot if none exists. This is the preferred method for application flows
327
+ * where slots are an internal infrastructure concern, not a user-facing concept.
328
+ *
329
+ * POST /api/v1/bookings (with tenant_id instead of slot_id)
330
+ *
331
+ * @example
332
+ * ```typescript
333
+ * const booking = await slotly.booking.createFromServiceItem({
334
+ * tenantId: 'tenant-123',
335
+ * serviceId: 'service-abc',
336
+ * serviceItemId: 'item-xyz',
337
+ * customerInfo: { name: 'Jane Smith', email: 'jane@example.com' },
338
+ * extraData: { kind: 'job_application', booking_moment: 'submitted' },
339
+ * });
340
+ * ```
341
+ */
342
+ async createFromServiceItem(data) {
343
+ return this.create({
344
+ tenant_id: data.tenantId,
345
+ customer_info: data.customerInfo,
346
+ booking_data: {
347
+ service_id: data.serviceId,
348
+ service_item_id: data.serviceItemId,
349
+ ...data.extraData
350
+ }
351
+ });
352
+ }
317
353
  /**
318
354
  * Update booking by ID
319
355
  * PUT /api/v1/bookings/:id
@@ -704,11 +740,27 @@ var SlotClient = class {
704
740
  return response.data;
705
741
  }
706
742
  /**
707
- * Create a new slot
743
+ * Create a new slot.
708
744
  * POST /api/v1/slots
709
- *
710
- * @param data - Slot creation data (tenant_id, name required)
745
+ *
746
+ * Accepts any subset of `Slot` fields. For new integrations, prefer the
747
+ * exported `CreateSlotInput` type which documents the recommended shape
748
+ * and will become the enforced signature in v2.0 (see SLOT_TYPE_UPGRADE_PLAN.md).
749
+ *
750
+ * New fields available as of v1.4:
751
+ * - `starts_at` — ISO 8601 datetime when the slot opens
752
+ * - `ends_at` — ISO 8601 datetime when the slot closes (omit for open-ended slots)
753
+ * - `metadata` — term enrichment bag (term_name, season, half_term_start,
754
+ * half_term_end, capacity); see `SlotMetadata` type
755
+ *
756
+ * @param data - Slot creation data
711
757
  * @returns Created slot
758
+ *
759
+ * @example
760
+ * // Recommended — opt into stricter typing now:
761
+ * import { CreateSlotInput } from '@slotly/sdk';
762
+ * const input: CreateSlotInput = { name: 'Autumn Term', tenant_id: '...', starts_at: '...' };
763
+ * sdk.slots.create(input);
712
764
  */
713
765
  async create(data) {
714
766
  const response = await this.client.post(
@@ -718,11 +770,17 @@ var SlotClient = class {
718
770
  return response.data;
719
771
  }
720
772
  /**
721
- * Update slot by ID
773
+ * Update slot by ID.
722
774
  * PUT /api/v1/slots/:id
723
- *
724
- * @param id - Slot ID
725
- * @param data - Slot update data
775
+ *
776
+ * Accepts any subset of `Slot` fields. For new integrations, prefer the
777
+ * exported `UpdateSlotInput` type it will become the enforced signature
778
+ * in v2.0 (see SLOT_TYPE_UPGRADE_PLAN.md).
779
+ *
780
+ * New fields available as of v1.4: `starts_at`, `ends_at`, `metadata`.
781
+ *
782
+ * @param id - Slot ID
783
+ * @param data - Fields to update
726
784
  * @returns Updated slot
727
785
  */
728
786
  async update(id, data) {
@@ -752,6 +810,13 @@ var SlotClient = class {
752
810
  * @param slots - Array of slots to create
753
811
  * @returns Created slots
754
812
  */
813
+ /**
814
+ * Bulk create slots.
815
+ * POST /api/v1/slots/bulk
816
+ *
817
+ * For new integrations, prefer passing `CreateSlotInput[]` — it will become
818
+ * the enforced signature in v2.0 (see SLOT_TYPE_UPGRADE_PLAN.md).
819
+ */
755
820
  async bulkCreate(slots) {
756
821
  const response = await this.client.post(
757
822
  "/api/v1/slots/bulk",
@@ -760,11 +825,14 @@ var SlotClient = class {
760
825
  return response.data;
761
826
  }
762
827
  /**
763
- * Mark slot as available/unavailable
764
- * Note: Use update() method with status or other fields
828
+ * Mark slot as available (live) or unavailable (archived).
829
+ *
830
+ * Note: previous versions sent 'active'/'inactive' which were not valid DB
831
+ * enum values. Fixed in v1.4 to use 'live'/'archived' — the only valid
832
+ * non-draft statuses. If you need 'draft', use update() directly.
765
833
  */
766
834
  async setAvailability(id, available) {
767
- return this.update(id, { status: available ? "active" : "inactive" });
835
+ return this.update(id, { status: available ? "live" : "archived" });
768
836
  }
769
837
  /**
770
838
  * Get all active services for a slot with their items