@microboxlabs/miot-calendar-client 0.2.0 → 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/dist/index.cjs +225 -0
- package/dist/index.d.mts +244 -0
- package/dist/index.d.ts +56 -1
- package/dist/{index.js → index.mjs} +40 -5
- package/package.json +10 -4
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
|
+
});
|
package/dist/index.d.mts
ADDED
|
@@ -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
|
@@ -118,6 +118,44 @@ interface SlotListResponse {
|
|
|
118
118
|
interface UpdateSlotStatusRequest {
|
|
119
119
|
status: SlotStatus;
|
|
120
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
|
+
}
|
|
121
159
|
interface ErrorResponse {
|
|
122
160
|
error: string;
|
|
123
161
|
message: string;
|
|
@@ -166,6 +204,23 @@ declare function createMiotCalendarClient(config: ClientConfig): {
|
|
|
166
204
|
update(id: string, body: CalendarGroupRequest): Promise<CalendarGroupResponse>;
|
|
167
205
|
deactivate(id: string): Promise<void>;
|
|
168
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
|
+
};
|
|
169
224
|
slots: {
|
|
170
225
|
list(params: {
|
|
171
226
|
calendarId: string;
|
|
@@ -186,4 +241,4 @@ declare class MiotCalendarApiError extends Error {
|
|
|
186
241
|
constructor(status: number, body: ErrorResponse | string);
|
|
187
242
|
}
|
|
188
243
|
|
|
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 };
|
|
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 };
|
|
@@ -88,21 +88,55 @@ function createGroupsApi(fetcher) {
|
|
|
88
88
|
};
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
-
// src/resources/
|
|
92
|
-
var BASE4 = "/api/v1/miot-calendar/
|
|
93
|
-
function
|
|
91
|
+
// src/resources/slot-managers.ts
|
|
92
|
+
var BASE4 = "/api/v1/miot-calendar/slot-managers";
|
|
93
|
+
function createSlotManagersApi(fetcher) {
|
|
94
94
|
return {
|
|
95
95
|
list(params) {
|
|
96
96
|
return fetcher("GET", BASE4, { query: params });
|
|
97
97
|
},
|
|
98
|
+
create(body) {
|
|
99
|
+
return fetcher("POST", BASE4, { body });
|
|
100
|
+
},
|
|
98
101
|
get(id) {
|
|
99
102
|
return fetcher("GET", `${BASE4}/${id}`);
|
|
100
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
|
+
},
|
|
101
135
|
generate(body) {
|
|
102
|
-
return fetcher("POST", `${
|
|
136
|
+
return fetcher("POST", `${BASE5}/generate`, { body });
|
|
103
137
|
},
|
|
104
138
|
updateStatus(id, body) {
|
|
105
|
-
return fetcher("PATCH", `${
|
|
139
|
+
return fetcher("PATCH", `${BASE5}/${id}/status`, { body });
|
|
106
140
|
}
|
|
107
141
|
};
|
|
108
142
|
}
|
|
@@ -153,6 +187,7 @@ function createMiotCalendarClient(config) {
|
|
|
153
187
|
bookings: createBookingsApi(fetcher),
|
|
154
188
|
calendars: createCalendarsApi(fetcher),
|
|
155
189
|
groups: createGroupsApi(fetcher),
|
|
190
|
+
slotManagers: createSlotManagersApi(fetcher),
|
|
156
191
|
slots: createSlotsApi(fetcher)
|
|
157
192
|
};
|
|
158
193
|
}
|
package/package.json
CHANGED
|
@@ -1,17 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@microboxlabs/miot-calendar-client",
|
|
3
|
-
"version": "0.
|
|
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
|
-
"
|
|
14
|
-
|
|
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"
|