@unboundcx/sdk 4.13.121 → 4.13.122

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/index.js CHANGED
@@ -23,6 +23,7 @@ import { DealRegistrationsService } from './services/dealRegistrations.js';
23
23
  import { SipEndpointsService } from './services/sipEndpoints.js';
24
24
  import { RingGroupsService } from './services/ringGroups.js';
25
25
  import { LineGroupsService } from './services/lineGroups.js';
26
+ import { SchedulesService } from './services/schedules/SchedulesService.js';
26
27
  import { EmergencyService } from './services/emergency.js';
27
28
  import { WebchatService } from './services/webchat.js';
28
29
  import { CobrowseService } from './services/cobrowse.js';
@@ -125,6 +126,7 @@ class UnboundSDK extends BaseSDK {
125
126
  this.sipEndpoints = new SipEndpointsService(this);
126
127
  this.ringGroups = new RingGroupsService(this);
127
128
  this.lineGroups = new LineGroupsService(this);
129
+ this.schedules = new SchedulesService(this);
128
130
  this.emergency = new EmergencyService(this);
129
131
  this.webchat = new WebchatService(this);
130
132
  this.cobrowse = new CobrowseService(this);
@@ -328,6 +330,8 @@ export { DealRegistrationsService } from './services/dealRegistrations.js';
328
330
  export { SipEndpointsService } from './services/sipEndpoints.js';
329
331
  export { RingGroupsService } from './services/ringGroups.js';
330
332
  export { LineGroupsService } from './services/lineGroups.js';
333
+ export { SchedulesService } from './services/schedules/SchedulesService.js';
334
+ export { TimeOffService } from './services/schedules/TimeOffService.js';
331
335
  export { EmergencyService } from './services/emergency.js';
332
336
  export { WebchatService, WebchatWidgetsService } from './services/webchat.js';
333
337
  export { CobrowseService, CobrowseVisitorService } from './services/cobrowse.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unboundcx/sdk",
3
- "version": "4.13.121",
3
+ "version": "4.13.122",
4
4
  "description": "Official JavaScript SDK for the Unbound API - A comprehensive toolkit for integrating with Unbound's communication, AI, and data management services",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -0,0 +1,232 @@
1
+ import { internalRequest } from '../../base.js';
2
+ import { TimeOffService } from './TimeOffService.js';
3
+
4
+ function pickDefined(fields) {
5
+ const body = {};
6
+ for (const [key, value] of Object.entries(fields)) {
7
+ if (value !== undefined) body[key] = value;
8
+ }
9
+ return body;
10
+ }
11
+
12
+ // Resolve/open query params a caller may pass to narrow which schedule is
13
+ // evaluated: a specific scheduleId (ignores assignment resolution), or a
14
+ // queueId/userId to resolve via assignments (journeys-plan.md §5).
15
+ function resolveQuery({ queueId, userId, scheduleId } = {}) {
16
+ return pickDefined({ queueId, userId, scheduleId });
17
+ }
18
+
19
+ /**
20
+ * Schedules (working hours, closures, assignments, time off) --
21
+ * journeys-plan.md §5. CRUD, assignments, holiday sets, time off, and the
22
+ * resolve/isOpen/nextOpen/simulate endpoints that evaluate a resolved
23
+ * schedule. `sdk.schedules.*`.
24
+ *
25
+ * @see app1-api src/services/schedules/routes.js
26
+ */
27
+ export class SchedulesService {
28
+ constructor(sdk) {
29
+ this.sdk = sdk;
30
+ this.timeOff = new TimeOffService(sdk);
31
+ }
32
+
33
+ /**
34
+ * @returns {Promise<Array>} Schedules (summary rows, no nested windows/closures)
35
+ */
36
+ async list() {
37
+ return await internalRequest(this.sdk, '/schedules', 'GET', {});
38
+ }
39
+
40
+ /**
41
+ * @param {string} id
42
+ * @returns {Promise<Object>} Schedule with nested windows, closures, usedBy
43
+ */
44
+ async get(id) {
45
+ this.sdk.validateParams({ id }, { id: { type: 'string', required: true } });
46
+ return await internalRequest(this.sdk, `/schedules/${id}`, 'GET', {});
47
+ }
48
+
49
+ /**
50
+ * @param {Object} body
51
+ * @param {string} body.name
52
+ * @param {string} [body.timezone]
53
+ * @param {boolean} [body.isAccountDefault]
54
+ * @param {Array<Object>} [body.windows] - {dayOfWeek, startTime, endTime}
55
+ * @param {Array<Object>} [body.closures] - {name, kind, config, partialDay?}
56
+ * @returns {Promise<Object>} Created schedule (with nested windows/closures)
57
+ */
58
+ async create(body) {
59
+ this.sdk.validateParams(
60
+ { name: body?.name },
61
+ { name: { type: 'string', required: true } },
62
+ );
63
+ return await internalRequest(this.sdk, '/schedules', 'POST', {
64
+ body: pickDefined(body),
65
+ });
66
+ }
67
+
68
+ /**
69
+ * Full replace-on-update: passing `windows`/`closures` replaces the
70
+ * schedule's entire set (not a merge/patch of individual rows).
71
+ *
72
+ * @param {string} id
73
+ * @param {Object} body - name?, timezone?, isAccountDefault?, windows?, closures?
74
+ * @returns {Promise<Object>} Updated schedule
75
+ */
76
+ async update(id, body) {
77
+ this.sdk.validateParams(
78
+ { id, body },
79
+ {
80
+ id: { type: 'string', required: true },
81
+ body: { type: 'object', required: true },
82
+ },
83
+ );
84
+ return await internalRequest(this.sdk, `/schedules/${id}`, 'PATCH', {
85
+ body: pickDefined(body),
86
+ });
87
+ }
88
+
89
+ /**
90
+ * @param {string} id
91
+ * @returns {Promise<Object>} { id, deleted: true } -- 409s while assigned
92
+ */
93
+ async remove(id) {
94
+ this.sdk.validateParams({ id }, { id: { type: 'string', required: true } });
95
+ return await internalRequest(this.sdk, `/schedules/${id}`, 'DELETE', {});
96
+ }
97
+
98
+ /**
99
+ * Set (replace) the one active assignment for a target. A target has at
100
+ * most one schedule at a time.
101
+ *
102
+ * @param {string} id - Schedule id
103
+ * @param {Object} params
104
+ * @param {'account'|'group'|'queue'|'user'} params.targetType
105
+ * @param {string} [params.targetId] - Required unless targetType is 'account'
106
+ * @returns {Promise<Object>} The assignment row
107
+ */
108
+ async setAssignment(id, { targetType, targetId } = {}) {
109
+ this.sdk.validateParams(
110
+ { id, targetType },
111
+ {
112
+ id: { type: 'string', required: true },
113
+ targetType: { type: 'string', required: true },
114
+ },
115
+ );
116
+ return await internalRequest(
117
+ this.sdk,
118
+ `/schedules/${id}/assignments`,
119
+ 'POST',
120
+ { body: pickDefined({ targetType, targetId }) },
121
+ );
122
+ }
123
+
124
+ /**
125
+ * @param {string} id - Schedule id
126
+ * @param {string} assignmentId
127
+ * @returns {Promise<Object>} { id, deleted: true }
128
+ */
129
+ async clearAssignment(id, assignmentId) {
130
+ this.sdk.validateParams(
131
+ { id, assignmentId },
132
+ {
133
+ id: { type: 'string', required: true },
134
+ assignmentId: { type: 'string', required: true },
135
+ },
136
+ );
137
+ return await internalRequest(
138
+ this.sdk,
139
+ `/schedules/${id}/assignments/${assignmentId}`,
140
+ 'DELETE',
141
+ {},
142
+ );
143
+ }
144
+
145
+ /**
146
+ * Every live assignment pointing at this schedule (account/group/queue/user).
147
+ *
148
+ * @param {string} id
149
+ * @returns {Promise<Array>} Assignment rows
150
+ */
151
+ async usedBy(id) {
152
+ this.sdk.validateParams({ id }, { id: { type: 'string', required: true } });
153
+ return await internalRequest(this.sdk, `/schedules/${id}/usedBy`, 'GET', {});
154
+ }
155
+
156
+ /**
157
+ * @returns {Promise<Array>} Holiday sets, one row per {country, key}
158
+ */
159
+ async listHolidaySets() {
160
+ return await internalRequest(this.sdk, '/schedules/holidaySets', 'GET', {});
161
+ }
162
+
163
+ /**
164
+ * Resolve the effective schedule for a target: user assignment -> queue
165
+ * assignment -> account default, with additive closures. Pass
166
+ * `scheduleId` to resolve a specific schedule directly (ignores
167
+ * assignment resolution; used by "simulate" against the schedule being
168
+ * edited).
169
+ *
170
+ * @param {Object} [params]
171
+ * @param {string} [params.queueId]
172
+ * @param {string} [params.userId]
173
+ * @param {string} [params.scheduleId]
174
+ * @returns {Promise<Object>} Resolved schedule { timezone, windows, closures, source, flagged }
175
+ */
176
+ async resolve(params = {}) {
177
+ return await internalRequest(this.sdk, '/schedules/resolve', 'GET', {
178
+ query: resolveQuery(params),
179
+ });
180
+ }
181
+
182
+ /**
183
+ * @param {Object} [params]
184
+ * @param {string} [params.queueId]
185
+ * @param {string} [params.userId]
186
+ * @param {string} [params.scheduleId]
187
+ * @param {string} [params.at] - ISO datetime; defaults to now
188
+ * @returns {Promise<Object>} { open, flagged }
189
+ */
190
+ async isOpen(params = {}) {
191
+ const { at, ...rest } = params;
192
+ return await internalRequest(this.sdk, '/schedules/isOpen', 'GET', {
193
+ query: pickDefined({ ...resolveQuery(rest), at }),
194
+ });
195
+ }
196
+
197
+ /**
198
+ * @param {Object} [params]
199
+ * @param {string} [params.queueId]
200
+ * @param {string} [params.userId]
201
+ * @param {string} [params.scheduleId]
202
+ * @param {string} [params.at] - ISO datetime; defaults to now
203
+ * @returns {Promise<Object>} { nextOpen, flagged }
204
+ */
205
+ async nextOpen(params = {}) {
206
+ const { at, ...rest } = params;
207
+ return await internalRequest(this.sdk, '/schedules/nextOpen', 'GET', {
208
+ query: pickDefined({ ...resolveQuery(rest), at }),
209
+ });
210
+ }
211
+
212
+ /**
213
+ * Simulate a resolved schedule: open/nextOpen at a point in time, plus
214
+ * optional addBusinessTime (pass `amount`+`unit`) and/or an `open` check
215
+ * across a `range` of ISO timestamps.
216
+ *
217
+ * @param {Object} [body]
218
+ * @param {string} [body.queueId]
219
+ * @param {string} [body.userId]
220
+ * @param {string} [body.scheduleId]
221
+ * @param {string} [body.at] - ISO datetime; defaults to now
222
+ * @param {number} [body.amount]
223
+ * @param {'minutes'|'hours'|'days'} [body.unit]
224
+ * @param {string[]} [body.range] - ISO datetimes to check open/closed for
225
+ * @returns {Promise<Object>} { resolved, open, nextOpen, addBusinessTime?, range? }
226
+ */
227
+ async simulate(body = {}) {
228
+ return await internalRequest(this.sdk, '/schedules/simulate', 'POST', {
229
+ body: pickDefined(body),
230
+ });
231
+ }
232
+ }
@@ -0,0 +1,131 @@
1
+ import { internalRequest } from '../../base.js';
2
+
3
+ function pickDefined(fields) {
4
+ const body = {};
5
+ for (const [key, value] of Object.entries(fields)) {
6
+ if (value !== undefined) body[key] = value;
7
+ }
8
+ return body;
9
+ }
10
+
11
+ /**
12
+ * userTimeOff CRUD -- self + manager-for-direct-reports.
13
+ * `sdk.schedules.timeOff.*` (journeys-plan.md §5).
14
+ *
15
+ * @see app1-api src/services/schedules/controllers/timeOff.js
16
+ */
17
+ export class TimeOffService {
18
+ constructor(sdk) {
19
+ this.sdk = sdk;
20
+ }
21
+
22
+ /**
23
+ * List time off rows. Omit `userId` for your own rows; pass it to look
24
+ * up a direct report's (manager-only, 403 otherwise).
25
+ *
26
+ * @param {Object} [params]
27
+ * @param {string} [params.userId]
28
+ * @returns {Promise<Array>} Time off rows
29
+ */
30
+ async list(params = {}) {
31
+ const { userId } = params;
32
+ const query = userId ? { userId } : {};
33
+ return await internalRequest(this.sdk, '/schedules/timeOff', 'GET', {
34
+ query,
35
+ });
36
+ }
37
+
38
+ /**
39
+ * Manager "Team time off" view -- every active direct report's rows.
40
+ *
41
+ * @returns {Promise<Array>} Time off rows for all direct reports
42
+ */
43
+ async listTeam() {
44
+ return await internalRequest(
45
+ this.sdk,
46
+ '/schedules/timeOff/team',
47
+ 'GET',
48
+ {},
49
+ );
50
+ }
51
+
52
+ /**
53
+ * Create a time off row. `userId` defaults to the caller; a manager may
54
+ * pass a direct report's userId.
55
+ *
56
+ * @param {Object} body
57
+ * @param {string} [body.userId]
58
+ * @param {string} body.startAt
59
+ * @param {string} body.endAt
60
+ * @param {string} [body.kind] - vacation|sick|other (default vacation)
61
+ * @param {string} [body.note]
62
+ * @param {string} [body.backupUserId]
63
+ * @returns {Promise<Object>} Created row
64
+ */
65
+ async create(body) {
66
+ this.sdk.validateParams(
67
+ { startAt: body?.startAt, endAt: body?.endAt },
68
+ {
69
+ startAt: { type: 'string', required: true },
70
+ endAt: { type: 'string', required: true },
71
+ },
72
+ );
73
+ return await internalRequest(this.sdk, '/schedules/timeOff', 'POST', {
74
+ body: pickDefined(body),
75
+ });
76
+ }
77
+
78
+ /**
79
+ * @param {string} id
80
+ * @param {Object} body - startAt?, endAt?, kind?, note?, backupUserId?
81
+ * @returns {Promise<Object>} Updated row
82
+ */
83
+ async update(id, body) {
84
+ this.sdk.validateParams(
85
+ { id, body },
86
+ {
87
+ id: { type: 'string', required: true },
88
+ body: { type: 'object', required: true },
89
+ },
90
+ );
91
+ return await internalRequest(
92
+ this.sdk,
93
+ `/schedules/timeOff/${id}`,
94
+ 'PATCH',
95
+ { body: pickDefined(body) },
96
+ );
97
+ }
98
+
99
+ /**
100
+ * @param {string} id
101
+ * @returns {Promise<Object>} { id, deleted: true }
102
+ */
103
+ async remove(id) {
104
+ this.sdk.validateParams({ id }, { id: { type: 'string', required: true } });
105
+ return await internalRequest(
106
+ this.sdk,
107
+ `/schedules/timeOff/${id}`,
108
+ 'DELETE',
109
+ {},
110
+ );
111
+ }
112
+
113
+ /**
114
+ * @param {string} userId
115
+ * @param {string} [at] - ISO datetime; defaults to now server-side
116
+ * @returns {Promise<Object>} { away: boolean }
117
+ */
118
+ async isUserAway(userId, at) {
119
+ this.sdk.validateParams(
120
+ { userId },
121
+ { userId: { type: 'string', required: true } },
122
+ );
123
+ const query = at ? { userId, at } : { userId };
124
+ return await internalRequest(
125
+ this.sdk,
126
+ '/schedules/timeOff/isUserAway',
127
+ 'GET',
128
+ { query },
129
+ );
130
+ }
131
+ }