@microboxlabs/miot-calendar-client 0.2.0 → 0.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/README.md CHANGED
@@ -314,6 +314,113 @@ Manually change a slot's status.
314
314
 
315
315
  ---
316
316
 
317
+ ### Slot Managers
318
+
319
+ Slot managers automate slot generation for calendars. Each manager keeps slots generated a configurable number of days in advance and can be triggered manually or by an external scheduler (e.g. K8s CronJob).
320
+
321
+ #### `slotManagers.list(params?)`
322
+
323
+ List all slot managers, optionally filtered by active status.
324
+
325
+ | Param | Type | Required | Description |
326
+ |-------|------|----------|-------------|
327
+ | `active` | `boolean` | No | When `true`, return only active managers |
328
+
329
+ **Returns:** `SlotManagerResponse[]`
330
+
331
+ #### `slotManagers.create(body)`
332
+
333
+ Create an automatic slot generation manager for a calendar.
334
+
335
+ | Field | Type | Required | Default | Description |
336
+ |-------|------|----------|---------|-------------|
337
+ | `calendarId` | `string` | Yes | — | Calendar ID to manage |
338
+ | `active` | `boolean` | No | `true` | Enable or disable automatic generation |
339
+ | `daysInAdvance` | `number` | No | `30` | Days ahead to keep slots generated |
340
+ | `batchDays` | `number` | No | `7` | Max days to generate per scheduler run |
341
+ | `reprocessFrom` | `string` | No | — | Force regeneration from this date (`YYYY-MM-DD`) |
342
+ | `reprocessTo` | `string` | No | — | Force regeneration through this date (required with `reprocessFrom`) |
343
+
344
+ **Returns:** `SlotManagerResponse`
345
+
346
+ **Throws:** `MiotCalendarApiError` with status `400` if invalid or duplicate.
347
+
348
+ #### `slotManagers.get(id)`
349
+
350
+ Get a slot manager by ID.
351
+
352
+ | Param | Type | Required | Description |
353
+ |-------|------|----------|-------------|
354
+ | `id` | `string` | Yes | Slot manager ID |
355
+
356
+ **Returns:** `SlotManagerResponse`
357
+
358
+ **Throws:** `MiotCalendarApiError` with status `404` if not found.
359
+
360
+ #### `slotManagers.update(id, body)`
361
+
362
+ Update a slot manager's configuration. Takes the same body as `create`. Set `reprocessFrom` + `reprocessTo` to schedule one-shot slot regeneration.
363
+
364
+ | Param | Type | Required | Description |
365
+ |-------|------|----------|-------------|
366
+ | `id` | `string` | Yes | Slot manager ID |
367
+ | `body` | `SlotManagerRequest` | Yes | Updated configuration |
368
+
369
+ **Returns:** `SlotManagerResponse`
370
+
371
+ #### `slotManagers.deactivate(id)`
372
+
373
+ Deactivate a slot manager (soft delete — disables automatic generation without removing history).
374
+
375
+ | Param | Type | Required | Description |
376
+ |-------|------|----------|-------------|
377
+ | `id` | `string` | Yes | Slot manager ID |
378
+
379
+ **Returns:** `void` (HTTP 204 — no content)
380
+
381
+ #### `slotManagers.runAll()`
382
+
383
+ Synchronously run all active slot managers. Returns when all managers have completed.
384
+
385
+ **Returns:** `SlotManagerRunResponse[]`
386
+
387
+ #### `slotManagers.run(id)`
388
+
389
+ Synchronously run a single slot manager and return its run record.
390
+
391
+ | Param | Type | Required | Description |
392
+ |-------|------|----------|-------------|
393
+ | `id` | `string` | Yes | Slot manager ID |
394
+
395
+ **Returns:** `SlotManagerRunResponse`
396
+
397
+ **Throws:** `MiotCalendarApiError` with status `404` if not found.
398
+
399
+ #### `slotManagers.listAllRuns(params?)`
400
+
401
+ List recent runs across all managers.
402
+
403
+ | Param | Type | Required | Default | Description |
404
+ |-------|------|----------|---------|-------------|
405
+ | `limit` | `number` | No | `50` | Maximum number of records to return |
406
+
407
+ **Returns:** `SlotManagerRunResponse[]`
408
+
409
+ #### `slotManagers.listRuns(id, params?)`
410
+
411
+ List runs for a specific manager.
412
+
413
+ | Param | Type | Required | Default | Description |
414
+ |-------|------|----------|---------|-------------|
415
+ | `id` | `string` | Yes | — | Slot manager ID |
416
+ | `limit` | `number` | No | `20` | Maximum number of records to return |
417
+
418
+ **Returns:** `SlotManagerRunResponse[]`
419
+
420
+ **Throws:** `MiotCalendarApiError` with status `404` if manager not found.
421
+
422
+ ---
423
+
317
424
  ### Bookings
318
425
 
319
426
  #### `bookings.list(params?)`
@@ -533,6 +640,59 @@ interface UpdateSlotStatusRequest {
533
640
  }
534
641
  ```
535
642
 
643
+ ### `SlotManagerRequest`
644
+
645
+ ```ts
646
+ interface SlotManagerRequest {
647
+ calendarId: string; // Calendar ID to manage
648
+ active?: boolean; // Enable/disable (default: true)
649
+ daysInAdvance?: number; // Days ahead to keep generated (default: 30)
650
+ batchDays?: number; // Max days per scheduler run (default: 7)
651
+ reprocessFrom?: string; // YYYY-MM-DD — one-shot regeneration start
652
+ reprocessTo?: string; // YYYY-MM-DD — one-shot regeneration end
653
+ }
654
+ ```
655
+
656
+ ### `SlotManagerResponse`
657
+
658
+ ```ts
659
+ interface SlotManagerResponse {
660
+ id: string;
661
+ calendarId: string;
662
+ calendarCode: string;
663
+ calendarName: string;
664
+ active: boolean;
665
+ daysInAdvance: number;
666
+ batchDays: number;
667
+ reprocessFrom?: string; // Cleared after successful run
668
+ reprocessTo?: string; // Cleared after successful run
669
+ lastRunAt?: string; // ISO 8601
670
+ lastRunStatus?: string; // IDLE, RUNNING, SUCCESS, FAILED, SKIPPED
671
+ lastRunError?: string; // Error message from last failed run
672
+ generatedThrough?: string; // YYYY-MM-DD — latest date with generated slots
673
+ createdAt: string; // ISO 8601
674
+ updatedAt: string; // ISO 8601
675
+ }
676
+ ```
677
+
678
+ ### `SlotManagerRunResponse`
679
+
680
+ ```ts
681
+ interface SlotManagerRunResponse {
682
+ id: string;
683
+ managerId: string;
684
+ triggeredBy: string; // SCHEDULER, API, CLI
685
+ startedAt: string; // ISO 8601
686
+ finishedAt?: string; // ISO 8601
687
+ status: string; // RUNNING, SUCCESS, FAILED, SKIPPED
688
+ slotsCreated: number;
689
+ slotsSkipped: number;
690
+ generatedFrom?: string; // YYYY-MM-DD
691
+ generatedThrough?: string; // YYYY-MM-DD
692
+ errorMessage?: string;
693
+ }
694
+ ```
695
+
536
696
  ### `BookingRequest`
537
697
 
538
698
  ```ts
package/dist/index.cjs ADDED
@@ -0,0 +1,228 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ MiotCalendarApiError: () => MiotCalendarApiError,
24
+ createMiotCalendarClient: () => createMiotCalendarClient
25
+ });
26
+ module.exports = __toCommonJS(index_exports);
27
+
28
+ // src/errors.ts
29
+ var MiotCalendarApiError = class extends Error {
30
+ constructor(status, body) {
31
+ super(typeof body === "string" ? body : body.message);
32
+ this.status = status;
33
+ this.body = body;
34
+ }
35
+ name = "MiotCalendarApiError";
36
+ };
37
+
38
+ // src/resources/bookings.ts
39
+ var BASE = "/api/v1/miot-calendar/bookings";
40
+ function createBookingsApi(fetcher) {
41
+ return {
42
+ list(params) {
43
+ return fetcher("GET", BASE, { query: params });
44
+ },
45
+ get(id) {
46
+ return fetcher("GET", `${BASE}/${id}`);
47
+ },
48
+ create(body, options) {
49
+ return fetcher("POST", BASE, {
50
+ body,
51
+ headers: options?.userId ? { "X-User-Id": options.userId } : void 0
52
+ });
53
+ },
54
+ cancel(id) {
55
+ return fetcher("DELETE", `${BASE}/${id}`);
56
+ },
57
+ listByResource(resourceId) {
58
+ return fetcher("GET", `${BASE}/resource/${resourceId}`);
59
+ }
60
+ };
61
+ }
62
+
63
+ // src/resources/calendars.ts
64
+ var BASE2 = "/api/v1/miot-calendar/calendars";
65
+ function createCalendarsApi(fetcher) {
66
+ return {
67
+ list(params) {
68
+ return fetcher("GET", BASE2, { query: params });
69
+ },
70
+ get(id) {
71
+ return fetcher("GET", `${BASE2}/${id}`);
72
+ },
73
+ create(body) {
74
+ return fetcher("POST", BASE2, { body });
75
+ },
76
+ update(id, body) {
77
+ return fetcher("PUT", `${BASE2}/${id}`, { body });
78
+ },
79
+ deactivate(id) {
80
+ return fetcher("DELETE", `${BASE2}/${id}`);
81
+ },
82
+ purge(id) {
83
+ return fetcher("DELETE", `${BASE2}/${id}/purge`);
84
+ },
85
+ listTimeWindows(calendarId) {
86
+ return fetcher("GET", `${BASE2}/${calendarId}/time-windows`);
87
+ },
88
+ createTimeWindow(calendarId, body) {
89
+ return fetcher("POST", `${BASE2}/${calendarId}/time-windows`, { body });
90
+ },
91
+ updateTimeWindow(calendarId, timeWindowId, body) {
92
+ return fetcher("PUT", `${BASE2}/${calendarId}/time-windows/${timeWindowId}`, {
93
+ body
94
+ });
95
+ }
96
+ };
97
+ }
98
+
99
+ // src/resources/groups.ts
100
+ var BASE3 = "/api/v1/miot-calendar/groups";
101
+ function createGroupsApi(fetcher) {
102
+ return {
103
+ list(params) {
104
+ return fetcher("GET", BASE3, { query: params });
105
+ },
106
+ get(id) {
107
+ return fetcher("GET", `${BASE3}/${id}`);
108
+ },
109
+ create(body) {
110
+ return fetcher("POST", BASE3, { body });
111
+ },
112
+ update(id, body) {
113
+ return fetcher("PUT", `${BASE3}/${id}`, { body });
114
+ },
115
+ deactivate(id) {
116
+ return fetcher("DELETE", `${BASE3}/${id}`);
117
+ }
118
+ };
119
+ }
120
+
121
+ // src/resources/slot-managers.ts
122
+ var BASE4 = "/api/v1/miot-calendar/slot-managers";
123
+ function createSlotManagersApi(fetcher) {
124
+ return {
125
+ list(params) {
126
+ return fetcher("GET", BASE4, { query: params });
127
+ },
128
+ create(body) {
129
+ return fetcher("POST", BASE4, { body });
130
+ },
131
+ get(id) {
132
+ return fetcher("GET", `${BASE4}/${id}`);
133
+ },
134
+ update(id, body) {
135
+ return fetcher("PUT", `${BASE4}/${id}`, { body });
136
+ },
137
+ deactivate(id) {
138
+ return fetcher("DELETE", `${BASE4}/${id}`);
139
+ },
140
+ runAll() {
141
+ return fetcher("POST", `${BASE4}/run`);
142
+ },
143
+ run(id) {
144
+ return fetcher("POST", `${BASE4}/${id}/run`);
145
+ },
146
+ listAllRuns(params) {
147
+ return fetcher("GET", `${BASE4}/runs`, { query: params });
148
+ },
149
+ listRuns(id, params) {
150
+ return fetcher("GET", `${BASE4}/${id}/runs`, { query: params });
151
+ }
152
+ };
153
+ }
154
+
155
+ // src/resources/slots.ts
156
+ var BASE5 = "/api/v1/miot-calendar/slots";
157
+ function createSlotsApi(fetcher) {
158
+ return {
159
+ list(params) {
160
+ return fetcher("GET", BASE5, { query: params });
161
+ },
162
+ get(id) {
163
+ return fetcher("GET", `${BASE5}/${id}`);
164
+ },
165
+ generate(body) {
166
+ return fetcher("POST", `${BASE5}/generate`, { body });
167
+ },
168
+ updateStatus(id, body) {
169
+ return fetcher("PATCH", `${BASE5}/${id}/status`, { body });
170
+ }
171
+ };
172
+ }
173
+
174
+ // src/client.ts
175
+ function buildUrl(baseUrl, path, query) {
176
+ const url = new URL(path, baseUrl);
177
+ if (query) {
178
+ for (const [key, value] of Object.entries(query)) {
179
+ if (value !== void 0) {
180
+ url.searchParams.set(key, String(value));
181
+ }
182
+ }
183
+ }
184
+ return url.toString();
185
+ }
186
+ function createMiotCalendarClient(config) {
187
+ const fetchFn = config.fetch ?? globalThis.fetch;
188
+ const fetcher = async (method, path, options) => {
189
+ const url = buildUrl(config.baseUrl, path, options?.query);
190
+ const headers = {
191
+ ...config.headers,
192
+ ...options?.headers
193
+ };
194
+ if (options?.body !== void 0) {
195
+ headers["Content-Type"] = "application/json";
196
+ }
197
+ const response = await fetchFn(url, {
198
+ method,
199
+ headers,
200
+ body: options?.body === void 0 ? void 0 : JSON.stringify(options.body)
201
+ });
202
+ if (!response.ok) {
203
+ let body;
204
+ try {
205
+ body = await response.json();
206
+ } catch {
207
+ body = await response.text();
208
+ }
209
+ throw new MiotCalendarApiError(response.status, body);
210
+ }
211
+ if (response.status === 204) {
212
+ return void 0;
213
+ }
214
+ return response.json();
215
+ };
216
+ return {
217
+ bookings: createBookingsApi(fetcher),
218
+ calendars: createCalendarsApi(fetcher),
219
+ groups: createGroupsApi(fetcher),
220
+ slotManagers: createSlotManagersApi(fetcher),
221
+ slots: createSlotsApi(fetcher)
222
+ };
223
+ }
224
+ // Annotate the CommonJS export names for ESM import in node:
225
+ 0 && (module.exports = {
226
+ MiotCalendarApiError,
227
+ createMiotCalendarClient
228
+ });
@@ -0,0 +1,247 @@
1
+ type SlotStatus = "OPEN" | "FULL" | "CLOSED";
2
+ interface ResourceData {
3
+ id: string;
4
+ type?: string;
5
+ label?: string;
6
+ data?: Record<string, unknown>;
7
+ }
8
+ interface SlotData {
9
+ date: string;
10
+ hour: number;
11
+ minutes: number;
12
+ }
13
+ interface BookingRequest {
14
+ calendarId: string;
15
+ resource: ResourceData;
16
+ slot: SlotData;
17
+ }
18
+ interface BookingResponse {
19
+ id: string;
20
+ calendarId: string;
21
+ resource: ResourceData;
22
+ slot: SlotData;
23
+ createdAt: string;
24
+ createdBy?: string;
25
+ }
26
+ interface BookingListResponse {
27
+ data: BookingResponse[];
28
+ total: number;
29
+ }
30
+ interface CalendarGroupRequest {
31
+ code: string;
32
+ name: string;
33
+ description?: string;
34
+ active?: boolean;
35
+ }
36
+ interface CalendarGroupResponse {
37
+ id: string;
38
+ code: string;
39
+ name: string;
40
+ description?: string;
41
+ active: boolean;
42
+ createdAt: string;
43
+ updatedAt: string;
44
+ }
45
+ interface CalendarRequest {
46
+ code: string;
47
+ name: string;
48
+ description?: string;
49
+ timezone?: string;
50
+ active?: boolean;
51
+ groups?: string[];
52
+ autoSlotManager?: boolean;
53
+ }
54
+ interface CalendarResponse {
55
+ id: string;
56
+ code: string;
57
+ name: string;
58
+ description?: string;
59
+ timezone: string;
60
+ active: boolean;
61
+ createdAt: string;
62
+ updatedAt: string;
63
+ groups?: CalendarGroupResponse[];
64
+ hasSlotManager?: boolean;
65
+ }
66
+ interface TimeWindowRequest {
67
+ name: string;
68
+ startHour: number;
69
+ endHour: number;
70
+ validFrom: string;
71
+ slotDurationMinutes?: number;
72
+ capacityPerSlot?: number;
73
+ daysOfWeek?: string;
74
+ validTo?: string;
75
+ active?: boolean;
76
+ }
77
+ interface TimeWindowResponse {
78
+ id: string;
79
+ calendarId: string;
80
+ name: string;
81
+ startHour: number;
82
+ endHour: number;
83
+ slotDurationMinutes: number;
84
+ capacityPerSlot: number;
85
+ daysOfWeek: string;
86
+ validFrom: string;
87
+ validTo?: string;
88
+ active: boolean;
89
+ createdAt: string;
90
+ updatedAt: string;
91
+ }
92
+ interface GenerateSlotsRequest {
93
+ calendarId: string;
94
+ startDate: string;
95
+ endDate: string;
96
+ }
97
+ interface GenerateSlotsResponse {
98
+ slotsCreated: number;
99
+ slotsSkipped: number;
100
+ message: string;
101
+ }
102
+ interface SlotResponse {
103
+ id: string;
104
+ calendarId: string;
105
+ timeWindowId?: string;
106
+ slotDate: string;
107
+ slotHour: number;
108
+ slotMinutes: number;
109
+ capacity: number;
110
+ currentOccupancy: number;
111
+ availableCapacity: number;
112
+ status: SlotStatus;
113
+ createdAt: string;
114
+ updatedAt: string;
115
+ }
116
+ interface SlotListResponse {
117
+ data: SlotResponse[];
118
+ total: number;
119
+ }
120
+ interface UpdateSlotStatusRequest {
121
+ status: SlotStatus;
122
+ }
123
+ interface SlotManagerRequest {
124
+ calendarId: string;
125
+ active?: boolean;
126
+ daysInAdvance?: number;
127
+ batchDays?: number;
128
+ reprocessFrom?: string;
129
+ reprocessTo?: string;
130
+ }
131
+ interface SlotManagerResponse {
132
+ id: string;
133
+ calendarId: string;
134
+ calendarCode: string;
135
+ calendarName: string;
136
+ active: boolean;
137
+ daysInAdvance: number;
138
+ batchDays: number;
139
+ reprocessFrom?: string;
140
+ reprocessTo?: string;
141
+ lastRunAt?: string;
142
+ lastRunStatus?: string;
143
+ lastRunError?: string;
144
+ generatedThrough?: string;
145
+ createdAt: string;
146
+ updatedAt: string;
147
+ }
148
+ interface SlotManagerRunResponse {
149
+ id: string;
150
+ managerId: string;
151
+ triggeredBy: string;
152
+ startedAt: string;
153
+ finishedAt?: string;
154
+ status: string;
155
+ slotsCreated: number;
156
+ slotsSkipped: number;
157
+ generatedFrom?: string;
158
+ generatedThrough?: string;
159
+ errorMessage?: string;
160
+ }
161
+ interface ErrorResponse {
162
+ error: string;
163
+ message: string;
164
+ status: number;
165
+ timestamp: string;
166
+ }
167
+ interface ClientConfig {
168
+ baseUrl: string;
169
+ headers?: Record<string, string>;
170
+ fetch?: typeof fetch;
171
+ }
172
+
173
+ declare function createMiotCalendarClient(config: ClientConfig): {
174
+ bookings: {
175
+ list(params?: {
176
+ calendarId?: string;
177
+ startDate?: string;
178
+ endDate?: string;
179
+ }): Promise<BookingListResponse>;
180
+ get(id: string): Promise<BookingResponse>;
181
+ create(body: BookingRequest, options?: {
182
+ userId?: string;
183
+ }): Promise<BookingResponse>;
184
+ cancel(id: string): Promise<void>;
185
+ listByResource(resourceId: string): Promise<BookingListResponse>;
186
+ };
187
+ calendars: {
188
+ list(params?: {
189
+ active?: boolean;
190
+ groupCode?: string;
191
+ }): Promise<CalendarResponse[]>;
192
+ get(id: string): Promise<CalendarResponse>;
193
+ create(body: CalendarRequest): Promise<CalendarResponse>;
194
+ update(id: string, body: CalendarRequest): Promise<CalendarResponse>;
195
+ deactivate(id: string): Promise<void>;
196
+ purge(id: string): Promise<void>;
197
+ listTimeWindows(calendarId: string): Promise<TimeWindowResponse[]>;
198
+ createTimeWindow(calendarId: string, body: TimeWindowRequest): Promise<TimeWindowResponse>;
199
+ updateTimeWindow(calendarId: string, timeWindowId: string, body: TimeWindowRequest): Promise<TimeWindowResponse>;
200
+ };
201
+ groups: {
202
+ list(params?: {
203
+ active?: boolean;
204
+ }): Promise<CalendarGroupResponse[]>;
205
+ get(id: string): Promise<CalendarGroupResponse>;
206
+ create(body: CalendarGroupRequest): Promise<CalendarGroupResponse>;
207
+ update(id: string, body: CalendarGroupRequest): Promise<CalendarGroupResponse>;
208
+ deactivate(id: string): Promise<void>;
209
+ };
210
+ slotManagers: {
211
+ list(params?: {
212
+ active?: boolean;
213
+ }): Promise<SlotManagerResponse[]>;
214
+ create(body: SlotManagerRequest): Promise<SlotManagerResponse>;
215
+ get(id: string): Promise<SlotManagerResponse>;
216
+ update(id: string, body: SlotManagerRequest): Promise<SlotManagerResponse>;
217
+ deactivate(id: string): Promise<void>;
218
+ runAll(): Promise<SlotManagerRunResponse[]>;
219
+ run(id: string): Promise<SlotManagerRunResponse>;
220
+ listAllRuns(params?: {
221
+ limit?: number;
222
+ }): Promise<SlotManagerRunResponse[]>;
223
+ listRuns(id: string, params?: {
224
+ limit?: number;
225
+ }): Promise<SlotManagerRunResponse[]>;
226
+ };
227
+ slots: {
228
+ list(params: {
229
+ calendarId: string;
230
+ available?: boolean;
231
+ startDate?: string;
232
+ endDate?: string;
233
+ }): Promise<SlotListResponse>;
234
+ get(id: string): Promise<SlotResponse>;
235
+ generate(body: GenerateSlotsRequest): Promise<GenerateSlotsResponse>;
236
+ updateStatus(id: string, body: UpdateSlotStatusRequest): Promise<SlotResponse>;
237
+ };
238
+ };
239
+
240
+ declare class MiotCalendarApiError extends Error {
241
+ readonly status: number;
242
+ readonly body: ErrorResponse | string;
243
+ name: "MiotCalendarApiError";
244
+ constructor(status: number, body: ErrorResponse | string);
245
+ }
246
+
247
+ export { type BookingListResponse, type BookingRequest, type BookingResponse, type CalendarGroupRequest, type CalendarGroupResponse, type CalendarRequest, type CalendarResponse, type ClientConfig, type ErrorResponse, type GenerateSlotsRequest, type GenerateSlotsResponse, MiotCalendarApiError, type ResourceData, type SlotData, type SlotListResponse, type SlotManagerRequest, type SlotManagerResponse, type SlotManagerRunResponse, type SlotResponse, type SlotStatus, type TimeWindowRequest, type TimeWindowResponse, type UpdateSlotStatusRequest, createMiotCalendarClient };
package/dist/index.d.ts CHANGED
@@ -49,6 +49,7 @@ interface CalendarRequest {
49
49
  timezone?: string;
50
50
  active?: boolean;
51
51
  groups?: string[];
52
+ autoSlotManager?: boolean;
52
53
  }
53
54
  interface CalendarResponse {
54
55
  id: string;
@@ -60,6 +61,7 @@ interface CalendarResponse {
60
61
  createdAt: string;
61
62
  updatedAt: string;
62
63
  groups?: CalendarGroupResponse[];
64
+ hasSlotManager?: boolean;
63
65
  }
64
66
  interface TimeWindowRequest {
65
67
  name: string;
@@ -118,6 +120,44 @@ interface SlotListResponse {
118
120
  interface UpdateSlotStatusRequest {
119
121
  status: SlotStatus;
120
122
  }
123
+ interface SlotManagerRequest {
124
+ calendarId: string;
125
+ active?: boolean;
126
+ daysInAdvance?: number;
127
+ batchDays?: number;
128
+ reprocessFrom?: string;
129
+ reprocessTo?: string;
130
+ }
131
+ interface SlotManagerResponse {
132
+ id: string;
133
+ calendarId: string;
134
+ calendarCode: string;
135
+ calendarName: string;
136
+ active: boolean;
137
+ daysInAdvance: number;
138
+ batchDays: number;
139
+ reprocessFrom?: string;
140
+ reprocessTo?: string;
141
+ lastRunAt?: string;
142
+ lastRunStatus?: string;
143
+ lastRunError?: string;
144
+ generatedThrough?: string;
145
+ createdAt: string;
146
+ updatedAt: string;
147
+ }
148
+ interface SlotManagerRunResponse {
149
+ id: string;
150
+ managerId: string;
151
+ triggeredBy: string;
152
+ startedAt: string;
153
+ finishedAt?: string;
154
+ status: string;
155
+ slotsCreated: number;
156
+ slotsSkipped: number;
157
+ generatedFrom?: string;
158
+ generatedThrough?: string;
159
+ errorMessage?: string;
160
+ }
121
161
  interface ErrorResponse {
122
162
  error: string;
123
163
  message: string;
@@ -153,6 +193,7 @@ declare function createMiotCalendarClient(config: ClientConfig): {
153
193
  create(body: CalendarRequest): Promise<CalendarResponse>;
154
194
  update(id: string, body: CalendarRequest): Promise<CalendarResponse>;
155
195
  deactivate(id: string): Promise<void>;
196
+ purge(id: string): Promise<void>;
156
197
  listTimeWindows(calendarId: string): Promise<TimeWindowResponse[]>;
157
198
  createTimeWindow(calendarId: string, body: TimeWindowRequest): Promise<TimeWindowResponse>;
158
199
  updateTimeWindow(calendarId: string, timeWindowId: string, body: TimeWindowRequest): Promise<TimeWindowResponse>;
@@ -166,6 +207,23 @@ declare function createMiotCalendarClient(config: ClientConfig): {
166
207
  update(id: string, body: CalendarGroupRequest): Promise<CalendarGroupResponse>;
167
208
  deactivate(id: string): Promise<void>;
168
209
  };
210
+ slotManagers: {
211
+ list(params?: {
212
+ active?: boolean;
213
+ }): Promise<SlotManagerResponse[]>;
214
+ create(body: SlotManagerRequest): Promise<SlotManagerResponse>;
215
+ get(id: string): Promise<SlotManagerResponse>;
216
+ update(id: string, body: SlotManagerRequest): Promise<SlotManagerResponse>;
217
+ deactivate(id: string): Promise<void>;
218
+ runAll(): Promise<SlotManagerRunResponse[]>;
219
+ run(id: string): Promise<SlotManagerRunResponse>;
220
+ listAllRuns(params?: {
221
+ limit?: number;
222
+ }): Promise<SlotManagerRunResponse[]>;
223
+ listRuns(id: string, params?: {
224
+ limit?: number;
225
+ }): Promise<SlotManagerRunResponse[]>;
226
+ };
169
227
  slots: {
170
228
  list(params: {
171
229
  calendarId: string;
@@ -186,4 +244,4 @@ declare class MiotCalendarApiError extends Error {
186
244
  constructor(status: number, body: ErrorResponse | string);
187
245
  }
188
246
 
189
- export { type BookingListResponse, type BookingRequest, type BookingResponse, type CalendarGroupRequest, type CalendarGroupResponse, type CalendarRequest, type CalendarResponse, type ClientConfig, type ErrorResponse, type GenerateSlotsRequest, type GenerateSlotsResponse, MiotCalendarApiError, type ResourceData, type SlotData, type SlotListResponse, type SlotResponse, type SlotStatus, type TimeWindowRequest, type TimeWindowResponse, type UpdateSlotStatusRequest, createMiotCalendarClient };
247
+ export { type BookingListResponse, type BookingRequest, type BookingResponse, type CalendarGroupRequest, type CalendarGroupResponse, type CalendarRequest, type CalendarResponse, type ClientConfig, type ErrorResponse, type GenerateSlotsRequest, type GenerateSlotsResponse, MiotCalendarApiError, type ResourceData, type SlotData, type SlotListResponse, type SlotManagerRequest, type SlotManagerResponse, type SlotManagerRunResponse, type SlotResponse, type SlotStatus, type TimeWindowRequest, type TimeWindowResponse, type UpdateSlotStatusRequest, createMiotCalendarClient };
@@ -52,6 +52,9 @@ function createCalendarsApi(fetcher) {
52
52
  deactivate(id) {
53
53
  return fetcher("DELETE", `${BASE2}/${id}`);
54
54
  },
55
+ purge(id) {
56
+ return fetcher("DELETE", `${BASE2}/${id}/purge`);
57
+ },
55
58
  listTimeWindows(calendarId) {
56
59
  return fetcher("GET", `${BASE2}/${calendarId}/time-windows`);
57
60
  },
@@ -88,21 +91,55 @@ function createGroupsApi(fetcher) {
88
91
  };
89
92
  }
90
93
 
91
- // src/resources/slots.ts
92
- var BASE4 = "/api/v1/miot-calendar/slots";
93
- function createSlotsApi(fetcher) {
94
+ // src/resources/slot-managers.ts
95
+ var BASE4 = "/api/v1/miot-calendar/slot-managers";
96
+ function createSlotManagersApi(fetcher) {
94
97
  return {
95
98
  list(params) {
96
99
  return fetcher("GET", BASE4, { query: params });
97
100
  },
101
+ create(body) {
102
+ return fetcher("POST", BASE4, { body });
103
+ },
98
104
  get(id) {
99
105
  return fetcher("GET", `${BASE4}/${id}`);
100
106
  },
107
+ update(id, body) {
108
+ return fetcher("PUT", `${BASE4}/${id}`, { body });
109
+ },
110
+ deactivate(id) {
111
+ return fetcher("DELETE", `${BASE4}/${id}`);
112
+ },
113
+ runAll() {
114
+ return fetcher("POST", `${BASE4}/run`);
115
+ },
116
+ run(id) {
117
+ return fetcher("POST", `${BASE4}/${id}/run`);
118
+ },
119
+ listAllRuns(params) {
120
+ return fetcher("GET", `${BASE4}/runs`, { query: params });
121
+ },
122
+ listRuns(id, params) {
123
+ return fetcher("GET", `${BASE4}/${id}/runs`, { query: params });
124
+ }
125
+ };
126
+ }
127
+
128
+ // src/resources/slots.ts
129
+ var BASE5 = "/api/v1/miot-calendar/slots";
130
+ function createSlotsApi(fetcher) {
131
+ return {
132
+ list(params) {
133
+ return fetcher("GET", BASE5, { query: params });
134
+ },
135
+ get(id) {
136
+ return fetcher("GET", `${BASE5}/${id}`);
137
+ },
101
138
  generate(body) {
102
- return fetcher("POST", `${BASE4}/generate`, { body });
139
+ return fetcher("POST", `${BASE5}/generate`, { body });
103
140
  },
104
141
  updateStatus(id, body) {
105
- return fetcher("PATCH", `${BASE4}/${id}/status`, { body });
142
+ return fetcher("PATCH", `${BASE5}/${id}/status`, { body });
106
143
  }
107
144
  };
108
145
  }
@@ -153,6 +190,7 @@ function createMiotCalendarClient(config) {
153
190
  bookings: createBookingsApi(fetcher),
154
191
  calendars: createCalendarsApi(fetcher),
155
192
  groups: createGroupsApi(fetcher),
193
+ slotManagers: createSlotManagersApi(fetcher),
156
194
  slots: createSlotsApi(fetcher)
157
195
  };
158
196
  }
package/package.json CHANGED
@@ -1,17 +1,22 @@
1
1
  {
2
2
  "name": "@microboxlabs/miot-calendar-client",
3
- "version": "0.2.0",
3
+ "version": "0.4.0",
4
4
  "license": "Apache-2.0",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/microboxlabs/modulariot",
8
8
  "directory": "packages/miot-calendar-client"
9
9
  },
10
- "type": "module",
11
10
  "exports": {
12
11
  ".": {
13
- "types": "./dist/index.d.ts",
14
- "import": "./dist/index.js"
12
+ "import": {
13
+ "types": "./dist/index.d.mts",
14
+ "default": "./dist/index.mjs"
15
+ },
16
+ "require": {
17
+ "types": "./dist/index.d.ts",
18
+ "default": "./dist/index.cjs"
19
+ }
15
20
  }
16
21
  },
17
22
  "files": [
@@ -19,6 +24,7 @@
19
24
  ],
20
25
  "scripts": {
21
26
  "build": "tsup",
27
+ "dev": "tsup --watch",
22
28
  "test": "vitest run",
23
29
  "lint": "eslint .",
24
30
  "check-types": "tsc --noEmit"