@unboundcx/sdk 4.13.121 → 4.13.123

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,8 @@ 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';
27
+ import { JourneysService } from './services/journeys/JourneysService.js';
26
28
  import { EmergencyService } from './services/emergency.js';
27
29
  import { WebchatService } from './services/webchat.js';
28
30
  import { CobrowseService } from './services/cobrowse.js';
@@ -125,6 +127,8 @@ class UnboundSDK extends BaseSDK {
125
127
  this.sipEndpoints = new SipEndpointsService(this);
126
128
  this.ringGroups = new RingGroupsService(this);
127
129
  this.lineGroups = new LineGroupsService(this);
130
+ this.schedules = new SchedulesService(this);
131
+ this.journeys = new JourneysService(this);
128
132
  this.emergency = new EmergencyService(this);
129
133
  this.webchat = new WebchatService(this);
130
134
  this.cobrowse = new CobrowseService(this);
@@ -328,6 +332,10 @@ export { DealRegistrationsService } from './services/dealRegistrations.js';
328
332
  export { SipEndpointsService } from './services/sipEndpoints.js';
329
333
  export { RingGroupsService } from './services/ringGroups.js';
330
334
  export { LineGroupsService } from './services/lineGroups.js';
335
+ export { SchedulesService } from './services/schedules/SchedulesService.js';
336
+ export { TimeOffService } from './services/schedules/TimeOffService.js';
337
+ export { JourneysService } from './services/journeys/JourneysService.js';
338
+ export { JourneyMembersService } from './services/journeys/JourneyMembersService.js';
331
339
  export { EmergencyService } from './services/emergency.js';
332
340
  export { WebchatService, WebchatWidgetsService } from './services/webchat.js';
333
341
  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.123",
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,189 @@
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
+ * Journey member surface -- `sdk.journeys.members.*`. Custom non-CRUD
13
+ * endpoints (member grid, enrol, bulk actions, fix, events) mounted at
14
+ * `/journeys/:id/members*`; NOT generic-object CRUD (journeyMembers is
15
+ * registered isCreateable=0/isEditable=0 -- reads via `sdk.objects.query`
16
+ * for grids/filters are fine, writes only through these methods).
17
+ *
18
+ * @see app1-api src/services/journeys/routes.js
19
+ */
20
+ export class JourneyMembersService {
21
+ constructor(sdk) {
22
+ this.sdk = sdk;
23
+ }
24
+
25
+ /**
26
+ * Server-paged member grid for one journey.
27
+ * @param {string} journeyId
28
+ * @param {Object} [opts]
29
+ * @param {number} [opts.page]
30
+ * @param {number} [opts.pageSize]
31
+ * @param {string} [opts.sort]
32
+ * @param {string} [opts.sortDir]
33
+ * @param {string[]} [opts.status]
34
+ * @param {string} [opts.stepKey]
35
+ * @param {string} [opts.ownerUserId]
36
+ * @param {string} [opts.statusReason]
37
+ * @param {string} [opts.search]
38
+ * @returns {Promise<Object>} Paged member rows
39
+ */
40
+ async list(journeyId, opts = {}) {
41
+ this.sdk.validateParams(
42
+ { journeyId },
43
+ { journeyId: { type: 'string', required: true } },
44
+ );
45
+ const { status, ...rest } = opts;
46
+ const query = pickDefined({
47
+ ...rest,
48
+ status: Array.isArray(status) ? status.join(',') : status,
49
+ });
50
+ return await internalRequest(
51
+ this.sdk,
52
+ `/journeys/${journeyId}/members`,
53
+ 'GET',
54
+ { query },
55
+ );
56
+ }
57
+
58
+ /**
59
+ * @param {string} journeyId
60
+ * @param {string} memberId
61
+ * @returns {Promise<Object>} Single member row
62
+ */
63
+ async get(journeyId, memberId) {
64
+ this.sdk.validateParams(
65
+ { journeyId, memberId },
66
+ {
67
+ journeyId: { type: 'string', required: true },
68
+ memberId: { type: 'string', required: true },
69
+ },
70
+ );
71
+ return await internalRequest(
72
+ this.sdk,
73
+ `/journeys/${journeyId}/members/${memberId}`,
74
+ 'GET',
75
+ {},
76
+ );
77
+ }
78
+
79
+ /**
80
+ * Enrol people into a journey. Pass `dryRun: true` to get the pre-enrol
81
+ * summary without writing anything.
82
+ *
83
+ * @param {string} journeyId
84
+ * @param {Object} body
85
+ * @param {string[]} [body.peopleIds] - Either peopleIds or filter is required
86
+ * @param {Object} [body.filter]
87
+ * @param {Object} [body.overrides] - Per-member channel overrides
88
+ * @param {string} [body.ownerUserId]
89
+ * @param {string} [body.source]
90
+ * @param {boolean} [body.dryRun]
91
+ * @param {string} [body.primaryChannel]
92
+ * @param {string} [body.workflowVersionId]
93
+ * @returns {Promise<Object>} dryRun: {ready, noChannel, notOptedIn,
94
+ * suppressed, alreadyEnrolled, firstSendAt, outcomes}; real: enrol results
95
+ */
96
+ async enroll(journeyId, body = {}) {
97
+ this.sdk.validateParams(
98
+ { journeyId },
99
+ { journeyId: { type: 'string', required: true } },
100
+ );
101
+ return await internalRequest(
102
+ this.sdk,
103
+ `/journeys/${journeyId}/members/enroll`,
104
+ 'POST',
105
+ { body: pickDefined(body) },
106
+ );
107
+ }
108
+
109
+ /**
110
+ * Apply a bulk action to selected member ids, or to everything matching
111
+ * a filter under the caller's visibility.
112
+ *
113
+ * @param {string} journeyId
114
+ * @param {Object} body
115
+ * @param {'pause'|'resume'|'remove'|'reassign'|'changeChannel'} body.action
116
+ * @param {string[]} [body.ids] - Either ids or filter is required
117
+ * @param {Object} [body.filter]
118
+ * @param {string} [body.reason]
119
+ * @param {string} [body.ownerUserId]
120
+ * @param {Object} [body.channels]
121
+ * @returns {Promise<Object>} { results }
122
+ */
123
+ async actions(journeyId, body = {}) {
124
+ this.sdk.validateParams(
125
+ { journeyId, action: body?.action },
126
+ {
127
+ journeyId: { type: 'string', required: true },
128
+ action: { type: 'string', required: true },
129
+ },
130
+ );
131
+ return await internalRequest(
132
+ this.sdk,
133
+ `/journeys/${journeyId}/members/actions`,
134
+ 'POST',
135
+ { body: pickDefined(body) },
136
+ );
137
+ }
138
+
139
+ /**
140
+ * Fix a member's channel address and resume or remove it.
141
+ *
142
+ * @param {string} journeyId
143
+ * @param {string} memberId
144
+ * @param {Object} body
145
+ * @param {string} [body.emailAddress]
146
+ * @param {string} [body.phoneNumber]
147
+ * @param {string} [body.smsNumber]
148
+ * @param {'resume'|'remove'} body.then
149
+ * @param {string} [body.reason]
150
+ * @returns {Promise<Object>} Updated member
151
+ */
152
+ async fix(journeyId, memberId, body = {}) {
153
+ this.sdk.validateParams(
154
+ { journeyId, memberId, then: body?.then },
155
+ {
156
+ journeyId: { type: 'string', required: true },
157
+ memberId: { type: 'string', required: true },
158
+ then: { type: 'string', required: true },
159
+ },
160
+ );
161
+ return await internalRequest(
162
+ this.sdk,
163
+ `/journeys/${journeyId}/members/${memberId}/fix`,
164
+ 'POST',
165
+ { body: pickDefined(body) },
166
+ );
167
+ }
168
+
169
+ /**
170
+ * @param {string} journeyId
171
+ * @param {string} memberId
172
+ * @returns {Promise<Array>} journeyMemberEvents rows, in order
173
+ */
174
+ async events(journeyId, memberId) {
175
+ this.sdk.validateParams(
176
+ { journeyId, memberId },
177
+ {
178
+ journeyId: { type: 'string', required: true },
179
+ memberId: { type: 'string', required: true },
180
+ },
181
+ );
182
+ return await internalRequest(
183
+ this.sdk,
184
+ `/journeys/${journeyId}/members/${memberId}/events`,
185
+ 'GET',
186
+ {},
187
+ );
188
+ }
189
+ }
@@ -0,0 +1,216 @@
1
+ import { internalRequest } from '../../base.js';
2
+ import { JourneyMembersService } from './JourneyMembersService.js';
3
+
4
+ /**
5
+ * Journeys (journeys-plan.md §2/§4) -- `sdk.journeys.*`.
6
+ *
7
+ * `journeyTypes`/`journeys`/`journeyGoals` are generic objects (registered
8
+ * isCreateable=1/isEditable=1/isDeletable=1, with customHandlers on the api
9
+ * side -- e.g. creating a journey also creates its companion workflow), so
10
+ * their CRUD here is a thin wrapper over `sdk.objects.*` the way
11
+ * `sdk.users.setStatus` wraps `sdk.objects.updateById` -- not a duplicate
12
+ * HTTP surface. `journeyMembers` (registered isCreateable=0/isEditable=0)
13
+ * and the member-grid/enrol/action/fix/events/stats endpoints are custom
14
+ * routes under `/journeys/`, covered by `members` and `stats`.
15
+ *
16
+ * @see app1-api src/services/journeys/routes.js
17
+ */
18
+ export class JourneysService {
19
+ constructor(sdk) {
20
+ this.sdk = sdk;
21
+ this.members = new JourneyMembersService(sdk);
22
+ this.types = new JourneyTypesService(sdk);
23
+ this.goals = new JourneyGoalsService(sdk);
24
+ }
25
+
26
+ /**
27
+ * @param {Object} [opts] - sdk.objects.query opts (select, where, limit, nextId, …)
28
+ * @returns {Promise<Object>} Query result
29
+ */
30
+ async list(opts = {}) {
31
+ return await this.sdk.objects.query({ object: 'journeys', ...opts });
32
+ }
33
+
34
+ /**
35
+ * @param {string} id
36
+ * @returns {Promise<Object>} Journey record
37
+ */
38
+ async get(id) {
39
+ this.sdk.validateParams({ id }, { id: { type: 'string', required: true } });
40
+ return await this.sdk.objects.byId({ id });
41
+ }
42
+
43
+ /**
44
+ * Creating a journey also creates its companion workflow
45
+ * (type='journey', builderMode='advanced' until P4) + a draft version.
46
+ *
47
+ * @param {Object} body
48
+ * @param {string} body.name
49
+ * @param {string} body.journeyTypeId
50
+ * @returns {Promise<Object>} Created journey, with workflowId/workflowVersionId
51
+ */
52
+ async create(body) {
53
+ this.sdk.validateParams(
54
+ { name: body?.name, journeyTypeId: body?.journeyTypeId },
55
+ {
56
+ name: { type: 'string', required: true },
57
+ journeyTypeId: { type: 'string', required: true },
58
+ },
59
+ );
60
+ return await this.sdk.objects.create({ object: 'journeys', body });
61
+ }
62
+
63
+ /**
64
+ * @param {string} id
65
+ * @param {Object} update
66
+ * @returns {Promise<Object>} Update result
67
+ */
68
+ async update(id, update) {
69
+ this.sdk.validateParams(
70
+ { id, update },
71
+ {
72
+ id: { type: 'string', required: true },
73
+ update: { type: 'object', required: true },
74
+ },
75
+ );
76
+ return await this.sdk.objects.updateById({ object: 'journeys', id, update });
77
+ }
78
+
79
+ /**
80
+ * Delete ⇒ archive server-side (status: 'archived', never soft-deleted).
81
+ *
82
+ * @param {string} id
83
+ * @returns {Promise<Object>} { deleted: [id] }
84
+ */
85
+ async archive(id) {
86
+ this.sdk.validateParams({ id }, { id: { type: 'string', required: true } });
87
+ return await this.sdk.objects.deleteById({ object: 'journeys', id });
88
+ }
89
+
90
+ /**
91
+ * @param {string} journeyId
92
+ * @returns {Promise<Object>} { byStatus, needsAttentionByReason }
93
+ */
94
+ async stats(journeyId) {
95
+ this.sdk.validateParams(
96
+ { journeyId },
97
+ { journeyId: { type: 'string', required: true } },
98
+ );
99
+ return await internalRequest(
100
+ this.sdk,
101
+ `/journeys/${journeyId}/stats`,
102
+ 'GET',
103
+ {},
104
+ );
105
+ }
106
+ }
107
+
108
+ /**
109
+ * `sdk.journeys.types.*` -- journeyTypes generic-object CRUD. `queueId`
110
+ * stays empty until P5.
111
+ */
112
+ class JourneyTypesService {
113
+ constructor(sdk) {
114
+ this.sdk = sdk;
115
+ }
116
+
117
+ async list(opts = {}) {
118
+ return await this.sdk.objects.query({ object: 'journeyTypes', ...opts });
119
+ }
120
+
121
+ async get(id) {
122
+ this.sdk.validateParams({ id }, { id: { type: 'string', required: true } });
123
+ return await this.sdk.objects.byId({ id });
124
+ }
125
+
126
+ /**
127
+ * @param {Object} body
128
+ * @param {string} body.name
129
+ * @returns {Promise<Object>} Created journeyType
130
+ */
131
+ async create(body) {
132
+ this.sdk.validateParams(
133
+ { name: body?.name },
134
+ { name: { type: 'string', required: true } },
135
+ );
136
+ return await this.sdk.objects.create({ object: 'journeyTypes', body });
137
+ }
138
+
139
+ async update(id, update) {
140
+ this.sdk.validateParams(
141
+ { id, update },
142
+ {
143
+ id: { type: 'string', required: true },
144
+ update: { type: 'object', required: true },
145
+ },
146
+ );
147
+ return await this.sdk.objects.updateById({
148
+ object: 'journeyTypes',
149
+ id,
150
+ update,
151
+ });
152
+ }
153
+
154
+ async remove(id) {
155
+ this.sdk.validateParams({ id }, { id: { type: 'string', required: true } });
156
+ return await this.sdk.objects.deleteById({ object: 'journeyTypes', id });
157
+ }
158
+ }
159
+
160
+ /**
161
+ * `sdk.journeys.goals.*` -- journeyGoals generic-object CRUD (no `get`;
162
+ * goals are listed/edited inline on the journey, matching the plan's CRUD
163
+ * surface for this object).
164
+ */
165
+ class JourneyGoalsService {
166
+ constructor(sdk) {
167
+ this.sdk = sdk;
168
+ }
169
+
170
+ /**
171
+ * @param {Object} [opts] - sdk.objects.query opts; pass `where: { journeyId }` to scope
172
+ * @returns {Promise<Object>} Query result
173
+ */
174
+ async list(opts = {}) {
175
+ return await this.sdk.objects.query({ object: 'journeyGoals', ...opts });
176
+ }
177
+
178
+ /**
179
+ * @param {Object} body
180
+ * @param {string} body.journeyId
181
+ * @param {string} body.goalType
182
+ * @returns {Promise<Object>} Created journeyGoal
183
+ */
184
+ async create(body) {
185
+ this.sdk.validateParams(
186
+ { journeyId: body?.journeyId, goalType: body?.goalType },
187
+ {
188
+ journeyId: { type: 'string', required: true },
189
+ goalType: { type: 'string', required: true },
190
+ },
191
+ );
192
+ return await this.sdk.objects.create({ object: 'journeyGoals', body });
193
+ }
194
+
195
+ async update(id, update) {
196
+ this.sdk.validateParams(
197
+ { id, update },
198
+ {
199
+ id: { type: 'string', required: true },
200
+ update: { type: 'object', required: true },
201
+ },
202
+ );
203
+ return await this.sdk.objects.updateById({
204
+ object: 'journeyGoals',
205
+ id,
206
+ update,
207
+ });
208
+ }
209
+
210
+ async remove(id) {
211
+ this.sdk.validateParams({ id }, { id: { type: 'string', required: true } });
212
+ return await this.sdk.objects.deleteById({ object: 'journeyGoals', id });
213
+ }
214
+ }
215
+
216
+ export { JourneyTypesService, JourneyGoalsService };
@@ -1417,43 +1417,4 @@ export class ObjectsService {
1417
1417
  );
1418
1418
  }
1419
1419
 
1420
- /**
1421
- * P7 (workflows-v2-plan.md W10/W11/W23) -- runs an immediate full
1422
- * enter+exit sweep for a journey program. Same diff-and-enqueue path a
1423
- * scheduled tick runs, so this can never 429.
1424
- * @param {string} programId
1425
- * @returns {Promise<{queued: true, enterEnqueued: number, exitEnqueued: number}>}
1426
- */
1427
- async runMarketingProgramNow(programId) {
1428
- this.sdk.validateParams(
1429
- { programId },
1430
- { programId: { type: 'string', required: true } },
1431
- );
1432
- return internalRequest(
1433
- this.sdk,
1434
- `/object/marketing-programs/${programId}/run`,
1435
- 'POST',
1436
- { body: {} },
1437
- );
1438
- }
1439
-
1440
- /**
1441
- * P7 -- paginated member list for a journey program (joined to people
1442
- * for display name; never raw peopleId).
1443
- * @param {string} programId
1444
- * @param {{nextId?: string, limit?: number}} [opts]
1445
- * @returns {Promise<{results: object[], pagination: object}>}
1446
- */
1447
- async listMarketingProgramMembers(programId, opts = {}) {
1448
- this.sdk.validateParams(
1449
- { programId },
1450
- { programId: { type: 'string', required: true } },
1451
- );
1452
- return internalRequest(
1453
- this.sdk,
1454
- `/object/marketing-programs/${programId}/members`,
1455
- 'GET',
1456
- { query: opts },
1457
- );
1458
- }
1459
1420
  }
@@ -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
+ }