@slotchain/sdk 1.3.0 → 1.5.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.
@@ -0,0 +1,52 @@
1
+ import type { AxiosInstance } from 'axios';
2
+ import type { ApiResponse, SlotNotice, ListNoticesOptions } from '../types/api';
3
+
4
+ /**
5
+ * NoticesClient — read active slot-scoped operational notices.
6
+ *
7
+ * Notices are a product concept (early closure, venue change, general alert)
8
+ * backed by `slot_moments` internally — the SDK surface reflects the product,
9
+ * not the storage model. Each notice's attached graphic (if any) is already
10
+ * resolved to a signed `imageUrl` server-side.
11
+ *
12
+ * @example List active notices for a tenant
13
+ * ```ts
14
+ * const { data } = await slotly.notices.list({ tenantId });
15
+ * ```
16
+ */
17
+ export class NoticesClient {
18
+ private readonly client: AxiosInstance;
19
+ private readonly base = '/api/v1/notices';
20
+
21
+ constructor(client: AxiosInstance) {
22
+ this.client = client;
23
+ }
24
+
25
+ /**
26
+ * List active notices for a tenant.
27
+ * Returns only notices where visible_until > activeAt (default: now).
28
+ */
29
+ async list(options: ListNoticesOptions): Promise<ApiResponse<SlotNotice[]>> {
30
+ const response = await this.client.get<ApiResponse<SlotNotice[]>>(this.base, {
31
+ params: {
32
+ tenant_id: options.tenantId,
33
+ active_at: options.activeAt,
34
+ slot_id: options.slotId,
35
+ types: options.types?.join(','),
36
+ },
37
+ });
38
+ return response.data;
39
+ }
40
+
41
+ /**
42
+ * Get a single notice by its slot_moment id.
43
+ */
44
+ async getById(id: string, tenantId: string): Promise<SlotNotice> {
45
+ const response = await this.client.get<ApiResponse<SlotNotice>>(`${this.base}/${id}`, {
46
+ params: { tenant_id: tenantId },
47
+ });
48
+ const { data } = response.data;
49
+ if (!data) throw new Error(`Notice ${id} not found`);
50
+ return data;
51
+ }
52
+ }
@@ -1,5 +1,7 @@
1
1
  import { AxiosInstance } from 'axios';
2
2
  import { ApiResponse, Slot, SlotServiceWithItems, Tenant } from '../types/api';
3
+ // CreateSlotInput and UpdateSlotInput are exported for consumer use but not yet
4
+ // enforced on method signatures — see SLOT_TYPE_UPGRADE_PLAN.md Phase 2.
3
5
 
4
6
  export class SlotClient {
5
7
  constructor(private client: AxiosInstance) {}
@@ -41,11 +43,27 @@ export class SlotClient {
41
43
  }
42
44
 
43
45
  /**
44
- * Create a new slot
46
+ * Create a new slot.
45
47
  * POST /api/v1/slots
46
- *
47
- * @param data - Slot creation data (tenant_id, name required)
48
+ *
49
+ * Accepts any subset of `Slot` fields. For new integrations, prefer the
50
+ * exported `CreateSlotInput` type which documents the recommended shape
51
+ * and will become the enforced signature in v2.0 (see SLOT_TYPE_UPGRADE_PLAN.md).
52
+ *
53
+ * New fields available as of v1.4:
54
+ * - `starts_at` — ISO 8601 datetime when the slot opens
55
+ * - `ends_at` — ISO 8601 datetime when the slot closes (omit for open-ended slots)
56
+ * - `metadata` — term enrichment bag (term_name, season, half_term_start,
57
+ * half_term_end, capacity); see `SlotMetadata` type
58
+ *
59
+ * @param data - Slot creation data
48
60
  * @returns Created slot
61
+ *
62
+ * @example
63
+ * // Recommended — opt into stricter typing now:
64
+ * import { CreateSlotInput } from '@slotly/sdk';
65
+ * const input: CreateSlotInput = { name: 'Autumn Term', tenant_id: '...', starts_at: '...' };
66
+ * sdk.slots.create(input);
49
67
  */
50
68
  async create(data: Partial<Slot>): Promise<ApiResponse<Slot>> {
51
69
  const response = await this.client.post<ApiResponse<Slot>>(
@@ -56,11 +74,17 @@ export class SlotClient {
56
74
  }
57
75
 
58
76
  /**
59
- * Update slot by ID
77
+ * Update slot by ID.
60
78
  * PUT /api/v1/slots/:id
61
- *
62
- * @param id - Slot ID
63
- * @param data - Slot update data
79
+ *
80
+ * Accepts any subset of `Slot` fields. For new integrations, prefer the
81
+ * exported `UpdateSlotInput` type it will become the enforced signature
82
+ * in v2.0 (see SLOT_TYPE_UPGRADE_PLAN.md).
83
+ *
84
+ * New fields available as of v1.4: `starts_at`, `ends_at`, `metadata`.
85
+ *
86
+ * @param id - Slot ID
87
+ * @param data - Fields to update
64
88
  * @returns Updated slot
65
89
  */
66
90
  async update(id: string, data: Partial<Slot>): Promise<ApiResponse<Slot>> {
@@ -92,6 +116,13 @@ export class SlotClient {
92
116
  * @param slots - Array of slots to create
93
117
  * @returns Created slots
94
118
  */
119
+ /**
120
+ * Bulk create slots.
121
+ * POST /api/v1/slots/bulk
122
+ *
123
+ * For new integrations, prefer passing `CreateSlotInput[]` — it will become
124
+ * the enforced signature in v2.0 (see SLOT_TYPE_UPGRADE_PLAN.md).
125
+ */
95
126
  async bulkCreate(slots: Partial<Slot>[]): Promise<ApiResponse<Slot[]>> {
96
127
  // Note: Verify if bulk endpoint exists in API
97
128
  const response = await this.client.post<ApiResponse<Slot[]>>(
@@ -102,11 +133,14 @@ export class SlotClient {
102
133
  }
103
134
 
104
135
  /**
105
- * Mark slot as available/unavailable
106
- * Note: Use update() method with status or other fields
136
+ * Mark slot as available (live) or unavailable (archived).
137
+ *
138
+ * Note: previous versions sent 'active'/'inactive' which were not valid DB
139
+ * enum values. Fixed in v1.4 to use 'live'/'archived' — the only valid
140
+ * non-draft statuses. If you need 'draft', use update() directly.
107
141
  */
108
142
  async setAvailability(id: string, available: boolean): Promise<ApiResponse<Slot>> {
109
- return this.update(id, { status: available ? 'active' : 'inactive' } as Partial<Slot>);
143
+ return this.update(id, { status: available ? 'live' : 'archived' });
110
144
  }
111
145
 
112
146
  /**
package/src/index.ts CHANGED
@@ -11,6 +11,7 @@ import { NotificationClient } from './clients/notification-client';
11
11
  import { DataQualityClient } from './clients/data-quality-client';
12
12
  import { OrganizationClient } from './clients/organization-client';
13
13
  import { DocumentClient } from './clients/document-client';
14
+ import { NoticesClient } from './clients/notices-client';
14
15
  import { setupRequestInterceptor, setupResponseInterceptor, setupErrorInterceptor } from './interceptors';
15
16
  import { setupRetryInterceptor } from './retry';
16
17
  import { SlotlyConfigurationError } from './errors';
@@ -31,6 +32,9 @@ export type {
31
32
  ServiceItemWithService,
32
33
  Category,
33
34
  Slot,
35
+ SlotMetadata,
36
+ CreateSlotInput,
37
+ UpdateSlotInput,
34
38
  Customer,
35
39
  CustomerIdentity,
36
40
  CustomerWithIdentities,
@@ -52,6 +56,9 @@ export type {
52
56
  ArtifactMimeCategory,
53
57
  ListArtifactsOptions,
54
58
  UploadArtifactOptions,
59
+ SlotNotice,
60
+ NoticeMomentType,
61
+ ListNoticesOptions,
55
62
  } from './types/api';
56
63
 
57
64
  // Re-export errors
@@ -120,6 +127,8 @@ export interface SlotlyApi {
120
127
  organization: OrganizationClient;
121
128
  /** Upload and retrieve file artifacts (CVs, invoices, images) linked to any Slotly entity */
122
129
  document: DocumentClient;
130
+ /** List slot-scoped operational notices (early closure, venue change, general alerts) */
131
+ notices: NoticesClient;
123
132
  }
124
133
 
125
134
  const defaultBaseURL = typeof process !== 'undefined' && process.env?.SLOTLY_API_URL
@@ -314,6 +323,7 @@ export const useSlotly = (options: SlotlyClientOptions): SlotlyApi => {
314
323
  dataQuality: new DataQualityClient(client),
315
324
  organization: new OrganizationClient(client),
316
325
  document: new DocumentClient(client),
326
+ notices: new NoticesClient(client),
317
327
  };
318
328
  };
319
329
 
package/src/types/api.ts CHANGED
@@ -172,17 +172,85 @@ export interface Service {
172
172
  updated_at: string;
173
173
  }
174
174
 
175
+ /**
176
+ * Metadata bag for a slot — open-ended key/value store, with well-known
177
+ * optional fields for childcare / nursery term-based scheduling.
178
+ */
179
+ export interface SlotMetadata {
180
+ /** Human-readable term name, e.g. "Autumn Term 2024" */
181
+ term_name?: string;
182
+ /** Season identifier, e.g. "autumn" | "spring" | "summer" */
183
+ season?: string;
184
+ /** ISO date string for when the half-term break starts */
185
+ half_term_start?: string;
186
+ /** ISO date string for when the half-term break ends */
187
+ half_term_end?: string;
188
+ /** Maximum number of children / participants in this slot */
189
+ capacity?: number;
190
+ /**
191
+ * Headcount at -2 weeks (used for register generation / staffing).
192
+ * Negative prefix avoids collision with positive operational fields.
193
+ */
194
+ neg_headcount_neg2?: number;
195
+ /**
196
+ * Headcount at -3 weeks (used for register generation / staffing).
197
+ */
198
+ neg_headcount_neg3?: number;
199
+ /** Arbitrary additional metadata */
200
+ [key: string]: unknown;
201
+ }
202
+
175
203
  export interface Slot {
176
204
  id: string;
177
205
  tenant_id: string;
206
+ /** Display name / title of the slot */
178
207
  name: string;
179
208
  description?: string;
180
209
  status?: string;
181
210
  is_active?: boolean;
211
+ /**
212
+ * ISO 8601 datetime when the slot opens (combines start_date + start_time from the DB).
213
+ * Present when the API serialises scheduled slots.
214
+ */
215
+ starts_at?: string;
216
+ /**
217
+ * ISO 8601 datetime when the slot closes (combines end_date + end_time from the DB).
218
+ * Absent for open-ended / on-demand slots.
219
+ */
220
+ ends_at?: string;
221
+ /** Arbitrary metadata bag — see SlotMetadata for well-known keys */
222
+ metadata?: SlotMetadata;
182
223
  created_at: string;
183
224
  updated_at: string;
184
225
  }
185
226
 
227
+ /**
228
+ * Input shape for creating or updating a slot.
229
+ * Omits server-generated fields; all scheduling fields optional.
230
+ */
231
+ export interface CreateSlotInput {
232
+ name: string;
233
+ description?: string;
234
+ tenant_id: string;
235
+ status?: 'draft' | 'live' | 'archived';
236
+ /**
237
+ * ISO 8601 datetime for when the slot opens.
238
+ * The API splits this into start_date + start_time before persisting.
239
+ */
240
+ starts_at?: string;
241
+ /**
242
+ * ISO 8601 datetime for when the slot closes.
243
+ * Omit for on-demand / open-ended slots.
244
+ */
245
+ ends_at?: string;
246
+ metadata?: SlotMetadata;
247
+ }
248
+
249
+ /**
250
+ * Partial update shape — all fields optional except id (supplied as path param).
251
+ */
252
+ export type UpdateSlotInput = Partial<Omit<CreateSlotInput, 'tenant_id'>>;
253
+
186
254
  /**
187
255
  * Customer record — matches the `customers` table.
188
256
  */
@@ -356,7 +424,7 @@ export interface GetOrganizationOptions {
356
424
  /**
357
425
  * Artifact / document attached to a customer or booking
358
426
  */
359
- export type ArtifactEntityType = 'customer' | 'booking' | 'slot' | 'service' | 'tenant';
427
+ export type ArtifactEntityType = 'customer' | 'booking' | 'slot' | 'service' | 'tenant' | 'slot_moment';
360
428
 
361
429
  export type ArtifactMimeCategory = 'pdf' | 'document' | 'image' | 'spreadsheet' | 'video' | 'audio' | 'other';
362
430
 
@@ -420,6 +488,53 @@ export interface UploadArtifactOptions {
420
488
  metadata?: Record<string, unknown>;
421
489
  }
422
490
 
491
+ /**
492
+ * Slot-scoped operational notice (early closure, venue change, general alert).
493
+ * Backed by a `slot_moment` — see NOTICES_PLAN.md in slotly-admin.
494
+ */
495
+ export type NoticeMomentType =
496
+ | 'general_notice'
497
+ | 'early_closure'
498
+ | 'closure_notice'
499
+ | 'venue_change';
500
+
501
+ export interface SlotNotice {
502
+ id: string;
503
+ slotId: string;
504
+ tenantId: string;
505
+ momentType: NoticeMomentType;
506
+ createdAt: string;
507
+ createdBy: string | null;
508
+ notice: {
509
+ type: string;
510
+ title: string;
511
+ message: string;
512
+ /** YYYY-MM-DD — the day the notice applies to */
513
+ affectedDate: string;
514
+ /** HH:MM — only present for early_closure notices */
515
+ closesAt?: string;
516
+ severity: 'info' | 'warning' | 'urgent';
517
+ visibleFrom: string;
518
+ visibleUntil: string;
519
+ dismissible: boolean;
520
+ /** Signed URL for the notice's attached graphic, if one was uploaded */
521
+ imageUrl?: string | null;
522
+ /** Staff-picked display treatment — 'banner' (compact, stacks) or 'modal' (full-screen, one at a time) */
523
+ presentation: 'banner' | 'modal';
524
+ };
525
+ affectedBookingIds: string[];
526
+ }
527
+
528
+ export interface ListNoticesOptions {
529
+ tenantId: string;
530
+ /** Filter to notices active at this ISO timestamp. Defaults to now. */
531
+ activeAt?: string;
532
+ /** Filter to a specific slot */
533
+ slotId?: string;
534
+ /** Specific notice types to include. Defaults to all notice types. */
535
+ types?: NoticeMomentType[];
536
+ }
537
+
423
538
  /**
424
539
  * Full tenant configuration including branding, services, and service items
425
540
  * Service items are nested within each service object (not as a separate top-level array)