@microboxlabs/miot-calendar-client 0.1.3 → 0.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/README.md CHANGED
@@ -89,11 +89,12 @@ const client = createMiotCalendarClient({
89
89
 
90
90
  #### `calendars.list(params?)`
91
91
 
92
- List all calendars, optionally filtered by active status.
92
+ List all calendars, optionally filtered by active status or group membership.
93
93
 
94
94
  | Param | Type | Required | Description |
95
95
  |-------|------|----------|-------------|
96
96
  | `active` | `boolean` | No | Filter by active status |
97
+ | `groupCode` | `string` | No | Filter calendars belonging to this group code |
97
98
 
98
99
  **Returns:** `CalendarResponse[]`
99
100
 
@@ -120,6 +121,7 @@ Create a new calendar.
120
121
  | `description` | `string` | No | — | Optional description |
121
122
  | `timezone` | `string` | No | `"UTC"` | IANA timezone |
122
123
  | `active` | `boolean` | No | `true` | Whether the calendar is active |
124
+ | `groups` | `string[]` | No | — | Group codes to assign. `null` = no change; `[]` = remove all; `["code"]` = replace all |
123
125
 
124
126
  **Returns:** `CalendarResponse`
125
127
 
@@ -130,7 +132,7 @@ Replace a calendar's fields. Takes the same body as `create`.
130
132
  | Param | Type | Required | Description |
131
133
  |-------|------|----------|-------------|
132
134
  | `id` | `string` | Yes | Calendar ID |
133
- | `body` | `CalendarRequest` | Yes | Updated calendar data |
135
+ | `body` | `CalendarRequest` | Yes | Updated calendar data (include `groups` to reassign group membership) |
134
136
 
135
137
  **Returns:** `CalendarResponse`
136
138
 
@@ -192,6 +194,70 @@ Update a time window. Takes the same body as `createTimeWindow`.
192
194
 
193
195
  ---
194
196
 
197
+ ### Groups
198
+
199
+ Calendar groups let you organize calendars into named collections. Calendars can belong to multiple groups; use `CalendarRequest.groups` on create or update to manage membership.
200
+
201
+ #### `groups.list(params?)`
202
+
203
+ List all calendar groups, optionally filtered by active status.
204
+
205
+ | Param | Type | Required | Description |
206
+ |-------|------|----------|-------------|
207
+ | `active` | `boolean` | No | Filter by active status |
208
+
209
+ **Returns:** `CalendarGroupResponse[]`
210
+
211
+ #### `groups.get(id)`
212
+
213
+ Get a single calendar group by ID.
214
+
215
+ | Param | Type | Required | Description |
216
+ |-------|------|----------|-------------|
217
+ | `id` | `string` | Yes | Group ID |
218
+
219
+ **Returns:** `CalendarGroupResponse`
220
+
221
+ **Throws:** `MiotCalendarApiError` with status `404` if not found.
222
+
223
+ #### `groups.create(body)`
224
+
225
+ Create a new calendar group.
226
+
227
+ | Field | Type | Required | Default | Description |
228
+ |-------|------|----------|---------|-------------|
229
+ | `code` | `string` | Yes | — | Unique code identifier (max 50 chars) |
230
+ | `name` | `string` | Yes | — | Display name (max 255 chars) |
231
+ | `description` | `string` | No | — | Optional description |
232
+ | `active` | `boolean` | No | `true` | Whether the group is active |
233
+
234
+ **Returns:** `CalendarGroupResponse`
235
+
236
+ **Throws:** `MiotCalendarApiError` with status `400` if the code is already taken.
237
+
238
+ #### `groups.update(id, body)`
239
+
240
+ Replace a calendar group's fields. Takes the same body as `create`.
241
+
242
+ | Param | Type | Required | Description |
243
+ |-------|------|----------|-------------|
244
+ | `id` | `string` | Yes | Group ID |
245
+ | `body` | `CalendarGroupRequest` | Yes | Updated group data |
246
+
247
+ **Returns:** `CalendarGroupResponse`
248
+
249
+ #### `groups.deactivate(id)`
250
+
251
+ Deactivate a calendar group (soft delete). Calendars in the group are not affected.
252
+
253
+ | Param | Type | Required | Description |
254
+ |-------|------|----------|-------------|
255
+ | `id` | `string` | Yes | Group ID |
256
+
257
+ **Returns:** `void` (HTTP 204 — no content)
258
+
259
+ ---
260
+
195
261
  ### Slots
196
262
 
197
263
  #### `slots.list(params)`
@@ -321,6 +387,31 @@ List all bookings for a specific resource.
321
387
 
322
388
  ## Types
323
389
 
390
+ ### `CalendarGroupRequest`
391
+
392
+ ```ts
393
+ interface CalendarGroupRequest {
394
+ code: string; // Unique code identifier (max 50 chars)
395
+ name: string; // Display name (max 255 chars)
396
+ description?: string; // Optional description
397
+ active?: boolean; // Active status (default: true)
398
+ }
399
+ ```
400
+
401
+ ### `CalendarGroupResponse`
402
+
403
+ ```ts
404
+ interface CalendarGroupResponse {
405
+ id: string;
406
+ code: string;
407
+ name: string;
408
+ description?: string;
409
+ active: boolean;
410
+ createdAt: string; // ISO 8601
411
+ updatedAt: string; // ISO 8601
412
+ }
413
+ ```
414
+
324
415
  ### `CalendarRequest`
325
416
 
326
417
  ```ts
@@ -330,6 +421,7 @@ interface CalendarRequest {
330
421
  description?: string; // Optional description
331
422
  timezone?: string; // IANA timezone (default: "UTC")
332
423
  active?: boolean; // Active status (default: true)
424
+ groups?: string[]; // Group codes to assign. null = no change; [] = remove all; ["code"] = replace all
333
425
  }
334
426
  ```
335
427
 
@@ -341,10 +433,11 @@ interface CalendarResponse {
341
433
  code: string;
342
434
  name: string;
343
435
  description?: string;
344
- timezone: string; // Always present (default: "UTC")
345
- active: boolean; // Always present (default: true)
346
- createdAt: string; // ISO 8601
347
- updatedAt: string; // ISO 8601
436
+ timezone: string; // Always present (default: "UTC")
437
+ active: boolean; // Always present (default: true)
438
+ createdAt: string; // ISO 8601
439
+ updatedAt: string; // ISO 8601
440
+ groups?: CalendarGroupResponse[]; // Groups this calendar belongs to
348
441
  }
349
442
  ```
350
443
 
package/dist/index.cjs ADDED
@@ -0,0 +1,225 @@
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
+ listTimeWindows(calendarId) {
83
+ return fetcher("GET", `${BASE2}/${calendarId}/time-windows`);
84
+ },
85
+ createTimeWindow(calendarId, body) {
86
+ return fetcher("POST", `${BASE2}/${calendarId}/time-windows`, { body });
87
+ },
88
+ updateTimeWindow(calendarId, timeWindowId, body) {
89
+ return fetcher("PUT", `${BASE2}/${calendarId}/time-windows/${timeWindowId}`, {
90
+ body
91
+ });
92
+ }
93
+ };
94
+ }
95
+
96
+ // src/resources/groups.ts
97
+ var BASE3 = "/api/v1/miot-calendar/groups";
98
+ function createGroupsApi(fetcher) {
99
+ return {
100
+ list(params) {
101
+ return fetcher("GET", BASE3, { query: params });
102
+ },
103
+ get(id) {
104
+ return fetcher("GET", `${BASE3}/${id}`);
105
+ },
106
+ create(body) {
107
+ return fetcher("POST", BASE3, { body });
108
+ },
109
+ update(id, body) {
110
+ return fetcher("PUT", `${BASE3}/${id}`, { body });
111
+ },
112
+ deactivate(id) {
113
+ return fetcher("DELETE", `${BASE3}/${id}`);
114
+ }
115
+ };
116
+ }
117
+
118
+ // src/resources/slot-managers.ts
119
+ var BASE4 = "/api/v1/miot-calendar/slot-managers";
120
+ function createSlotManagersApi(fetcher) {
121
+ return {
122
+ list(params) {
123
+ return fetcher("GET", BASE4, { query: params });
124
+ },
125
+ create(body) {
126
+ return fetcher("POST", BASE4, { body });
127
+ },
128
+ get(id) {
129
+ return fetcher("GET", `${BASE4}/${id}`);
130
+ },
131
+ update(id, body) {
132
+ return fetcher("PUT", `${BASE4}/${id}`, { body });
133
+ },
134
+ deactivate(id) {
135
+ return fetcher("DELETE", `${BASE4}/${id}`);
136
+ },
137
+ runAll() {
138
+ return fetcher("POST", `${BASE4}/run`);
139
+ },
140
+ run(id) {
141
+ return fetcher("POST", `${BASE4}/${id}/run`);
142
+ },
143
+ listAllRuns(params) {
144
+ return fetcher("GET", `${BASE4}/runs`, { query: params });
145
+ },
146
+ listRuns(id, params) {
147
+ return fetcher("GET", `${BASE4}/${id}/runs`, { query: params });
148
+ }
149
+ };
150
+ }
151
+
152
+ // src/resources/slots.ts
153
+ var BASE5 = "/api/v1/miot-calendar/slots";
154
+ function createSlotsApi(fetcher) {
155
+ return {
156
+ list(params) {
157
+ return fetcher("GET", BASE5, { query: params });
158
+ },
159
+ get(id) {
160
+ return fetcher("GET", `${BASE5}/${id}`);
161
+ },
162
+ generate(body) {
163
+ return fetcher("POST", `${BASE5}/generate`, { body });
164
+ },
165
+ updateStatus(id, body) {
166
+ return fetcher("PATCH", `${BASE5}/${id}/status`, { body });
167
+ }
168
+ };
169
+ }
170
+
171
+ // src/client.ts
172
+ function buildUrl(baseUrl, path, query) {
173
+ const url = new URL(path, baseUrl);
174
+ if (query) {
175
+ for (const [key, value] of Object.entries(query)) {
176
+ if (value !== void 0) {
177
+ url.searchParams.set(key, String(value));
178
+ }
179
+ }
180
+ }
181
+ return url.toString();
182
+ }
183
+ function createMiotCalendarClient(config) {
184
+ const fetchFn = config.fetch ?? globalThis.fetch;
185
+ const fetcher = async (method, path, options) => {
186
+ const url = buildUrl(config.baseUrl, path, options?.query);
187
+ const headers = {
188
+ ...config.headers,
189
+ ...options?.headers
190
+ };
191
+ if (options?.body !== void 0) {
192
+ headers["Content-Type"] = "application/json";
193
+ }
194
+ const response = await fetchFn(url, {
195
+ method,
196
+ headers,
197
+ body: options?.body === void 0 ? void 0 : JSON.stringify(options.body)
198
+ });
199
+ if (!response.ok) {
200
+ let body;
201
+ try {
202
+ body = await response.json();
203
+ } catch {
204
+ body = await response.text();
205
+ }
206
+ throw new MiotCalendarApiError(response.status, body);
207
+ }
208
+ if (response.status === 204) {
209
+ return void 0;
210
+ }
211
+ return response.json();
212
+ };
213
+ return {
214
+ bookings: createBookingsApi(fetcher),
215
+ calendars: createCalendarsApi(fetcher),
216
+ groups: createGroupsApi(fetcher),
217
+ slotManagers: createSlotManagersApi(fetcher),
218
+ slots: createSlotsApi(fetcher)
219
+ };
220
+ }
221
+ // Annotate the CommonJS export names for ESM import in node:
222
+ 0 && (module.exports = {
223
+ MiotCalendarApiError,
224
+ createMiotCalendarClient
225
+ });
@@ -0,0 +1,244 @@
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
+ }
53
+ interface CalendarResponse {
54
+ id: string;
55
+ code: string;
56
+ name: string;
57
+ description?: string;
58
+ timezone: string;
59
+ active: boolean;
60
+ createdAt: string;
61
+ updatedAt: string;
62
+ groups?: CalendarGroupResponse[];
63
+ }
64
+ interface TimeWindowRequest {
65
+ name: string;
66
+ startHour: number;
67
+ endHour: number;
68
+ validFrom: string;
69
+ slotDurationMinutes?: number;
70
+ capacityPerSlot?: number;
71
+ daysOfWeek?: string;
72
+ validTo?: string;
73
+ active?: boolean;
74
+ }
75
+ interface TimeWindowResponse {
76
+ id: string;
77
+ calendarId: string;
78
+ name: string;
79
+ startHour: number;
80
+ endHour: number;
81
+ slotDurationMinutes: number;
82
+ capacityPerSlot: number;
83
+ daysOfWeek: string;
84
+ validFrom: string;
85
+ validTo?: string;
86
+ active: boolean;
87
+ createdAt: string;
88
+ updatedAt: string;
89
+ }
90
+ interface GenerateSlotsRequest {
91
+ calendarId: string;
92
+ startDate: string;
93
+ endDate: string;
94
+ }
95
+ interface GenerateSlotsResponse {
96
+ slotsCreated: number;
97
+ slotsSkipped: number;
98
+ message: string;
99
+ }
100
+ interface SlotResponse {
101
+ id: string;
102
+ calendarId: string;
103
+ timeWindowId?: string;
104
+ slotDate: string;
105
+ slotHour: number;
106
+ slotMinutes: number;
107
+ capacity: number;
108
+ currentOccupancy: number;
109
+ availableCapacity: number;
110
+ status: SlotStatus;
111
+ createdAt: string;
112
+ updatedAt: string;
113
+ }
114
+ interface SlotListResponse {
115
+ data: SlotResponse[];
116
+ total: number;
117
+ }
118
+ interface UpdateSlotStatusRequest {
119
+ status: SlotStatus;
120
+ }
121
+ interface SlotManagerRequest {
122
+ calendarId: string;
123
+ active?: boolean;
124
+ daysInAdvance?: number;
125
+ batchDays?: number;
126
+ reprocessFrom?: string;
127
+ reprocessTo?: string;
128
+ }
129
+ interface SlotManagerResponse {
130
+ id: string;
131
+ calendarId: string;
132
+ calendarCode: string;
133
+ calendarName: string;
134
+ active: boolean;
135
+ daysInAdvance: number;
136
+ batchDays: number;
137
+ reprocessFrom?: string;
138
+ reprocessTo?: string;
139
+ lastRunAt?: string;
140
+ lastRunStatus?: string;
141
+ lastRunError?: string;
142
+ generatedThrough?: string;
143
+ createdAt: string;
144
+ updatedAt: string;
145
+ }
146
+ interface SlotManagerRunResponse {
147
+ id: string;
148
+ managerId: string;
149
+ triggeredBy: string;
150
+ startedAt: string;
151
+ finishedAt?: string;
152
+ status: string;
153
+ slotsCreated: number;
154
+ slotsSkipped: number;
155
+ generatedFrom?: string;
156
+ generatedThrough?: string;
157
+ errorMessage?: string;
158
+ }
159
+ interface ErrorResponse {
160
+ error: string;
161
+ message: string;
162
+ status: number;
163
+ timestamp: string;
164
+ }
165
+ interface ClientConfig {
166
+ baseUrl: string;
167
+ headers?: Record<string, string>;
168
+ fetch?: typeof fetch;
169
+ }
170
+
171
+ declare function createMiotCalendarClient(config: ClientConfig): {
172
+ bookings: {
173
+ list(params?: {
174
+ calendarId?: string;
175
+ startDate?: string;
176
+ endDate?: string;
177
+ }): Promise<BookingListResponse>;
178
+ get(id: string): Promise<BookingResponse>;
179
+ create(body: BookingRequest, options?: {
180
+ userId?: string;
181
+ }): Promise<BookingResponse>;
182
+ cancel(id: string): Promise<void>;
183
+ listByResource(resourceId: string): Promise<BookingListResponse>;
184
+ };
185
+ calendars: {
186
+ list(params?: {
187
+ active?: boolean;
188
+ groupCode?: string;
189
+ }): Promise<CalendarResponse[]>;
190
+ get(id: string): Promise<CalendarResponse>;
191
+ create(body: CalendarRequest): Promise<CalendarResponse>;
192
+ update(id: string, body: CalendarRequest): Promise<CalendarResponse>;
193
+ deactivate(id: string): Promise<void>;
194
+ listTimeWindows(calendarId: string): Promise<TimeWindowResponse[]>;
195
+ createTimeWindow(calendarId: string, body: TimeWindowRequest): Promise<TimeWindowResponse>;
196
+ updateTimeWindow(calendarId: string, timeWindowId: string, body: TimeWindowRequest): Promise<TimeWindowResponse>;
197
+ };
198
+ groups: {
199
+ list(params?: {
200
+ active?: boolean;
201
+ }): Promise<CalendarGroupResponse[]>;
202
+ get(id: string): Promise<CalendarGroupResponse>;
203
+ create(body: CalendarGroupRequest): Promise<CalendarGroupResponse>;
204
+ update(id: string, body: CalendarGroupRequest): Promise<CalendarGroupResponse>;
205
+ deactivate(id: string): Promise<void>;
206
+ };
207
+ slotManagers: {
208
+ list(params?: {
209
+ active?: boolean;
210
+ }): Promise<SlotManagerResponse[]>;
211
+ create(body: SlotManagerRequest): Promise<SlotManagerResponse>;
212
+ get(id: string): Promise<SlotManagerResponse>;
213
+ update(id: string, body: SlotManagerRequest): Promise<SlotManagerResponse>;
214
+ deactivate(id: string): Promise<void>;
215
+ runAll(): Promise<SlotManagerRunResponse[]>;
216
+ run(id: string): Promise<SlotManagerRunResponse>;
217
+ listAllRuns(params?: {
218
+ limit?: number;
219
+ }): Promise<SlotManagerRunResponse[]>;
220
+ listRuns(id: string, params?: {
221
+ limit?: number;
222
+ }): Promise<SlotManagerRunResponse[]>;
223
+ };
224
+ slots: {
225
+ list(params: {
226
+ calendarId: string;
227
+ available?: boolean;
228
+ startDate?: string;
229
+ endDate?: string;
230
+ }): Promise<SlotListResponse>;
231
+ get(id: string): Promise<SlotResponse>;
232
+ generate(body: GenerateSlotsRequest): Promise<GenerateSlotsResponse>;
233
+ updateStatus(id: string, body: UpdateSlotStatusRequest): Promise<SlotResponse>;
234
+ };
235
+ };
236
+
237
+ declare class MiotCalendarApiError extends Error {
238
+ readonly status: number;
239
+ readonly body: ErrorResponse | string;
240
+ name: "MiotCalendarApiError";
241
+ constructor(status: number, body: ErrorResponse | string);
242
+ }
243
+
244
+ 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
@@ -27,12 +27,28 @@ interface BookingListResponse {
27
27
  data: BookingResponse[];
28
28
  total: number;
29
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
+ }
30
45
  interface CalendarRequest {
31
46
  code: string;
32
47
  name: string;
33
48
  description?: string;
34
49
  timezone?: string;
35
50
  active?: boolean;
51
+ groups?: string[];
36
52
  }
37
53
  interface CalendarResponse {
38
54
  id: string;
@@ -43,6 +59,7 @@ interface CalendarResponse {
43
59
  active: boolean;
44
60
  createdAt: string;
45
61
  updatedAt: string;
62
+ groups?: CalendarGroupResponse[];
46
63
  }
47
64
  interface TimeWindowRequest {
48
65
  name: string;
@@ -101,6 +118,44 @@ interface SlotListResponse {
101
118
  interface UpdateSlotStatusRequest {
102
119
  status: SlotStatus;
103
120
  }
121
+ interface SlotManagerRequest {
122
+ calendarId: string;
123
+ active?: boolean;
124
+ daysInAdvance?: number;
125
+ batchDays?: number;
126
+ reprocessFrom?: string;
127
+ reprocessTo?: string;
128
+ }
129
+ interface SlotManagerResponse {
130
+ id: string;
131
+ calendarId: string;
132
+ calendarCode: string;
133
+ calendarName: string;
134
+ active: boolean;
135
+ daysInAdvance: number;
136
+ batchDays: number;
137
+ reprocessFrom?: string;
138
+ reprocessTo?: string;
139
+ lastRunAt?: string;
140
+ lastRunStatus?: string;
141
+ lastRunError?: string;
142
+ generatedThrough?: string;
143
+ createdAt: string;
144
+ updatedAt: string;
145
+ }
146
+ interface SlotManagerRunResponse {
147
+ id: string;
148
+ managerId: string;
149
+ triggeredBy: string;
150
+ startedAt: string;
151
+ finishedAt?: string;
152
+ status: string;
153
+ slotsCreated: number;
154
+ slotsSkipped: number;
155
+ generatedFrom?: string;
156
+ generatedThrough?: string;
157
+ errorMessage?: string;
158
+ }
104
159
  interface ErrorResponse {
105
160
  error: string;
106
161
  message: string;
@@ -130,6 +185,7 @@ declare function createMiotCalendarClient(config: ClientConfig): {
130
185
  calendars: {
131
186
  list(params?: {
132
187
  active?: boolean;
188
+ groupCode?: string;
133
189
  }): Promise<CalendarResponse[]>;
134
190
  get(id: string): Promise<CalendarResponse>;
135
191
  create(body: CalendarRequest): Promise<CalendarResponse>;
@@ -139,6 +195,32 @@ declare function createMiotCalendarClient(config: ClientConfig): {
139
195
  createTimeWindow(calendarId: string, body: TimeWindowRequest): Promise<TimeWindowResponse>;
140
196
  updateTimeWindow(calendarId: string, timeWindowId: string, body: TimeWindowRequest): Promise<TimeWindowResponse>;
141
197
  };
198
+ groups: {
199
+ list(params?: {
200
+ active?: boolean;
201
+ }): Promise<CalendarGroupResponse[]>;
202
+ get(id: string): Promise<CalendarGroupResponse>;
203
+ create(body: CalendarGroupRequest): Promise<CalendarGroupResponse>;
204
+ update(id: string, body: CalendarGroupRequest): Promise<CalendarGroupResponse>;
205
+ deactivate(id: string): Promise<void>;
206
+ };
207
+ slotManagers: {
208
+ list(params?: {
209
+ active?: boolean;
210
+ }): Promise<SlotManagerResponse[]>;
211
+ create(body: SlotManagerRequest): Promise<SlotManagerResponse>;
212
+ get(id: string): Promise<SlotManagerResponse>;
213
+ update(id: string, body: SlotManagerRequest): Promise<SlotManagerResponse>;
214
+ deactivate(id: string): Promise<void>;
215
+ runAll(): Promise<SlotManagerRunResponse[]>;
216
+ run(id: string): Promise<SlotManagerRunResponse>;
217
+ listAllRuns(params?: {
218
+ limit?: number;
219
+ }): Promise<SlotManagerRunResponse[]>;
220
+ listRuns(id: string, params?: {
221
+ limit?: number;
222
+ }): Promise<SlotManagerRunResponse[]>;
223
+ };
142
224
  slots: {
143
225
  list(params: {
144
226
  calendarId: string;
@@ -159,4 +241,4 @@ declare class MiotCalendarApiError extends Error {
159
241
  constructor(status: number, body: ErrorResponse | string);
160
242
  }
161
243
 
162
- export { type BookingListResponse, type BookingRequest, type BookingResponse, 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 };
244
+ 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 };
@@ -66,9 +66,9 @@ function createCalendarsApi(fetcher) {
66
66
  };
67
67
  }
68
68
 
69
- // src/resources/slots.ts
70
- var BASE3 = "/api/v1/miot-calendar/slots";
71
- function createSlotsApi(fetcher) {
69
+ // src/resources/groups.ts
70
+ var BASE3 = "/api/v1/miot-calendar/groups";
71
+ function createGroupsApi(fetcher) {
72
72
  return {
73
73
  list(params) {
74
74
  return fetcher("GET", BASE3, { query: params });
@@ -76,11 +76,67 @@ function createSlotsApi(fetcher) {
76
76
  get(id) {
77
77
  return fetcher("GET", `${BASE3}/${id}`);
78
78
  },
79
+ create(body) {
80
+ return fetcher("POST", BASE3, { body });
81
+ },
82
+ update(id, body) {
83
+ return fetcher("PUT", `${BASE3}/${id}`, { body });
84
+ },
85
+ deactivate(id) {
86
+ return fetcher("DELETE", `${BASE3}/${id}`);
87
+ }
88
+ };
89
+ }
90
+
91
+ // src/resources/slot-managers.ts
92
+ var BASE4 = "/api/v1/miot-calendar/slot-managers";
93
+ function createSlotManagersApi(fetcher) {
94
+ return {
95
+ list(params) {
96
+ return fetcher("GET", BASE4, { query: params });
97
+ },
98
+ create(body) {
99
+ return fetcher("POST", BASE4, { body });
100
+ },
101
+ get(id) {
102
+ return fetcher("GET", `${BASE4}/${id}`);
103
+ },
104
+ update(id, body) {
105
+ return fetcher("PUT", `${BASE4}/${id}`, { body });
106
+ },
107
+ deactivate(id) {
108
+ return fetcher("DELETE", `${BASE4}/${id}`);
109
+ },
110
+ runAll() {
111
+ return fetcher("POST", `${BASE4}/run`);
112
+ },
113
+ run(id) {
114
+ return fetcher("POST", `${BASE4}/${id}/run`);
115
+ },
116
+ listAllRuns(params) {
117
+ return fetcher("GET", `${BASE4}/runs`, { query: params });
118
+ },
119
+ listRuns(id, params) {
120
+ return fetcher("GET", `${BASE4}/${id}/runs`, { query: params });
121
+ }
122
+ };
123
+ }
124
+
125
+ // src/resources/slots.ts
126
+ var BASE5 = "/api/v1/miot-calendar/slots";
127
+ function createSlotsApi(fetcher) {
128
+ return {
129
+ list(params) {
130
+ return fetcher("GET", BASE5, { query: params });
131
+ },
132
+ get(id) {
133
+ return fetcher("GET", `${BASE5}/${id}`);
134
+ },
79
135
  generate(body) {
80
- return fetcher("POST", `${BASE3}/generate`, { body });
136
+ return fetcher("POST", `${BASE5}/generate`, { body });
81
137
  },
82
138
  updateStatus(id, body) {
83
- return fetcher("PATCH", `${BASE3}/${id}/status`, { body });
139
+ return fetcher("PATCH", `${BASE5}/${id}/status`, { body });
84
140
  }
85
141
  };
86
142
  }
@@ -130,6 +186,8 @@ function createMiotCalendarClient(config) {
130
186
  return {
131
187
  bookings: createBookingsApi(fetcher),
132
188
  calendars: createCalendarsApi(fetcher),
189
+ groups: createGroupsApi(fetcher),
190
+ slotManagers: createSlotManagersApi(fetcher),
133
191
  slots: createSlotsApi(fetcher)
134
192
  };
135
193
  }
package/package.json CHANGED
@@ -1,17 +1,22 @@
1
1
  {
2
2
  "name": "@microboxlabs/miot-calendar-client",
3
- "version": "0.1.3",
3
+ "version": "0.3.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"