@slotchain/sdk 1.3.0 → 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 +42 -10
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.mts +105 -8
- package/dist/index.d.ts +105 -8
- package/dist/index.esm.js +42 -10
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/clients/slot-client.ts +44 -10
- package/src/index.ts +3 -0
- package/src/types/api.ts +68 -0
|
@@ -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
|
-
*
|
|
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
|
-
*
|
|
63
|
-
*
|
|
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
|
|
106
|
-
*
|
|
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 ? '
|
|
143
|
+
return this.update(id, { status: available ? 'live' : 'archived' });
|
|
110
144
|
}
|
|
111
145
|
|
|
112
146
|
/**
|
package/src/index.ts
CHANGED
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
|
*/
|