@unboundcx/sdk 4.13.148 → 4.13.150
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/package.json +1 -1
- package/services/ai.js +8 -0
- package/services/reporting.js +24 -191
- package/services/reportingUsers.js +23 -0
- package/services/reportingViews.js +196 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unboundcx/sdk",
|
|
3
|
-
"version": "4.13.
|
|
3
|
+
"version": "4.13.150",
|
|
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",
|
package/services/ai.js
CHANGED
|
@@ -86,6 +86,7 @@ export class GenerativeService {
|
|
|
86
86
|
qualityCheck,
|
|
87
87
|
isPublic,
|
|
88
88
|
usageContext,
|
|
89
|
+
reportContext,
|
|
89
90
|
}) {
|
|
90
91
|
this.sdk.validateParams(
|
|
91
92
|
{
|
|
@@ -114,6 +115,7 @@ export class GenerativeService {
|
|
|
114
115
|
qualityCheck,
|
|
115
116
|
isPublic,
|
|
116
117
|
usageContext,
|
|
118
|
+
reportContext,
|
|
117
119
|
},
|
|
118
120
|
{
|
|
119
121
|
prompt: { type: 'string', required: false },
|
|
@@ -143,6 +145,11 @@ export class GenerativeService {
|
|
|
143
145
|
// Telemetry-only (contracts §9): { feature?, taskId?, sipCallId?,
|
|
144
146
|
// queueId?, cdrId? } -- never affects the prompt/session/cache/response.
|
|
145
147
|
usageContext: { type: 'object', required: false },
|
|
148
|
+
// Ask panel (ask-panel.md §B): { reportKey, title, state, allowed }
|
|
149
|
+
// for the server to ground the system prompt and build the
|
|
150
|
+
// proposeReportChange tool schema's enums. Optional -- omitted for
|
|
151
|
+
// every non-reporting chat surface.
|
|
152
|
+
reportContext: { type: 'object', required: false },
|
|
146
153
|
},
|
|
147
154
|
);
|
|
148
155
|
|
|
@@ -176,6 +183,7 @@ export class GenerativeService {
|
|
|
176
183
|
// Only included when the caller actually passed one -- keeps the
|
|
177
184
|
// wire payload identical to today for every existing caller.
|
|
178
185
|
...(usageContext !== undefined ? { usageContext } : {}),
|
|
186
|
+
...(reportContext !== undefined ? { reportContext } : {}),
|
|
179
187
|
},
|
|
180
188
|
// Return raw response for streaming to allow client-side stream handling
|
|
181
189
|
returnRawResponse: stream === true,
|
package/services/reporting.js
CHANGED
|
@@ -11,6 +11,8 @@ import { ReportingIvrMenusService } from './reportingIvrMenus.js';
|
|
|
11
11
|
import { ReportingConversationInsightsService } from './reportingConversationInsights.js';
|
|
12
12
|
import { ReportingSurveysService } from './reportingSurveys.js';
|
|
13
13
|
import { ReportingSalesService } from './reportingSales.js';
|
|
14
|
+
import { ReportingUsersService } from './reportingUsers.js';
|
|
15
|
+
import { ReportingViewsService } from './reportingViews.js';
|
|
14
16
|
|
|
15
17
|
// Q2: same queryString helper as reportingAgents.js (kept local -- no
|
|
16
18
|
// shared util module between the two files today).
|
|
@@ -28,20 +30,11 @@ function queryString(params = {}) {
|
|
|
28
30
|
export class ReportingService {
|
|
29
31
|
constructor(sdk) {
|
|
30
32
|
this.sdk = sdk;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
};
|
|
37
|
-
this.schedules = {
|
|
38
|
-
create: (...args) => this.createSchedule(...args),
|
|
39
|
-
list: (...args) => this.listSchedules(...args),
|
|
40
|
-
update: (...args) => this.updateSchedule(...args),
|
|
41
|
-
remove: (...args) => this.removeSchedule(...args),
|
|
42
|
-
runs: (...args) => this.listScheduleRuns(...args),
|
|
43
|
-
runNow: (...args) => this.runScheduleNow(...args),
|
|
44
|
-
};
|
|
33
|
+
// Saved views + their email schedules -- own file/class (ReportingViewsService)
|
|
34
|
+
// to keep this file under the repo's 400-line limit.
|
|
35
|
+
const viewsService = new ReportingViewsService(sdk);
|
|
36
|
+
this.views = viewsService.views;
|
|
37
|
+
this.schedules = viewsService.schedules;
|
|
45
38
|
// Each namespace below is its own file/class to keep this file under
|
|
46
39
|
// the repo's 400-line limit (house convention, see .agents below).
|
|
47
40
|
// P3 (agent-reporting-plan.md §7 + §8.1): thin presets over the registry above -- /reporting/agents/*.
|
|
@@ -74,6 +67,10 @@ export class ReportingService {
|
|
|
74
67
|
this.surveys = new ReportingSurveysService(sdk);
|
|
75
68
|
// Work Package C analytics-expansion (§4.5, §7 C row): Rep activity-to-revenue + Pipeline/deal-risk.
|
|
76
69
|
this.sales = new ReportingSalesService(sdk);
|
|
70
|
+
// analytics-expansion live-testing fix: report-scoped users list
|
|
71
|
+
// beyond team members (Call log's Users filter) -- own file to keep
|
|
72
|
+
// this file under the 400-line limit.
|
|
73
|
+
this.users = new ReportingUsersService(sdk);
|
|
77
74
|
}
|
|
78
75
|
|
|
79
76
|
/**
|
|
@@ -88,18 +85,27 @@ export class ReportingService {
|
|
|
88
85
|
|
|
89
86
|
/**
|
|
90
87
|
* Run a report over the reporting rollups (+ today stitch).
|
|
91
|
-
* @param {Object} body - { metrics, dimensions, filters, from, to, grain, tz, continuous }
|
|
92
|
-
*
|
|
88
|
+
* @param {Object} body - { metrics, dimensions, filters, from, to, grain, tz, continuous, range }
|
|
89
|
+
* `range: { preset }` (analytics-expansion live-testing fix, NL Ask v1)
|
|
90
|
+
* is an ALTERNATIVE to from/to -- the api resolves the concrete dates
|
|
91
|
+
* itself, in the account timezone, and that resolution WINS over any
|
|
92
|
+
* from/to also sent. Presets: today, yesterday, last7d, last30d,
|
|
93
|
+
* thisWeek, lastWeek, thisMonth, lastMonth.
|
|
94
|
+
* @returns {Promise<Object>} { columns, rows, definitions, meta } --
|
|
95
|
+
* meta now also carries the RESOLVED { from, to, preset } the query
|
|
96
|
+
* actually ran against (preset is null when no `range` was sent).
|
|
93
97
|
* @example
|
|
94
98
|
* await sdk.reporting.query({ metrics: ['handled','slPct'], dimensions: ['queue','time'], from, to, grain: 'day' });
|
|
99
|
+
* await sdk.reporting.query({ metrics: ['handled'], range: { preset: 'lastWeek' } });
|
|
95
100
|
*/
|
|
96
101
|
async query(body) {
|
|
102
|
+
const hasRange = body?.range && typeof body.range === 'object';
|
|
97
103
|
this.sdk.validateParams(
|
|
98
104
|
{ metrics: body?.metrics, from: body?.from, to: body?.to },
|
|
99
105
|
{
|
|
100
106
|
metrics: { type: 'array', required: true },
|
|
101
|
-
from: { type: 'string', required:
|
|
102
|
-
to: { type: 'string', required:
|
|
107
|
+
from: { type: 'string', required: !hasRange },
|
|
108
|
+
to: { type: 'string', required: !hasRange },
|
|
103
109
|
},
|
|
104
110
|
);
|
|
105
111
|
return internalRequest(this.sdk, '/reporting/query', 'POST', { body });
|
|
@@ -217,177 +223,4 @@ export class ReportingService {
|
|
|
217
223
|
async health() {
|
|
218
224
|
return internalRequest(this.sdk, '/reporting/health', 'GET');
|
|
219
225
|
}
|
|
220
|
-
|
|
221
|
-
/**
|
|
222
|
-
* @param {Object} [params] - { reportKey?: string } -- analytics-expansion
|
|
223
|
-
* A0b: omit for Explore views only (unchanged default); pass
|
|
224
|
-
* 'callLog' for that report's saved views instead.
|
|
225
|
-
* @returns {Promise<Object>} { results: [...] }
|
|
226
|
-
* @example
|
|
227
|
-
* const { results } = await sdk.reporting.views.list();
|
|
228
|
-
* const { results } = await sdk.reporting.views.list({ reportKey: 'callLog' });
|
|
229
|
-
*/
|
|
230
|
-
async listViews({ reportKey } = {}) {
|
|
231
|
-
return internalRequest(
|
|
232
|
-
this.sdk,
|
|
233
|
-
`/reporting/views${queryString({ reportKey })}`,
|
|
234
|
-
'GET',
|
|
235
|
-
);
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
/**
|
|
239
|
-
* @param {Object} view - { name, query, isShared }
|
|
240
|
-
* @returns {Promise<Object>} created view
|
|
241
|
-
* @example
|
|
242
|
-
* await sdk.reporting.views.create({ name: 'Daily SL', query: {...} });
|
|
243
|
-
*/
|
|
244
|
-
async createView({ name, query, isShared } = {}) {
|
|
245
|
-
this.sdk.validateParams(
|
|
246
|
-
{ name, query },
|
|
247
|
-
{ name: { type: 'string', required: true }, query: { type: 'object', required: true } },
|
|
248
|
-
);
|
|
249
|
-
const body = { name, query };
|
|
250
|
-
if (isShared !== undefined) body.isShared = isShared;
|
|
251
|
-
return internalRequest(this.sdk, '/reporting/views', 'POST', { body });
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
/**
|
|
255
|
-
* @param {string} id
|
|
256
|
-
* @param {Object} data - { name, query, isShared }
|
|
257
|
-
* @returns {Promise<Object>} updated view
|
|
258
|
-
* @example
|
|
259
|
-
* await sdk.reporting.views.update('263...', { isShared: true });
|
|
260
|
-
*/
|
|
261
|
-
async updateView(id, data) {
|
|
262
|
-
id = String(id);
|
|
263
|
-
this.sdk.validateParams({ id }, { id: { type: 'string', required: true } });
|
|
264
|
-
return internalRequest(this.sdk, `/reporting/views/${id}`, 'PUT', { body: data });
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
/**
|
|
268
|
-
* @param {string} id
|
|
269
|
-
* @returns {Promise<Object>} { id, deleted: true }
|
|
270
|
-
* @example
|
|
271
|
-
* await sdk.reporting.views.remove('263...');
|
|
272
|
-
*/
|
|
273
|
-
async removeView(id) {
|
|
274
|
-
id = String(id);
|
|
275
|
-
this.sdk.validateParams({ id }, { id: { type: 'string', required: true } });
|
|
276
|
-
return internalRequest(this.sdk, `/reporting/views/${id}`, 'DELETE');
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
/**
|
|
280
|
-
* @param {string} viewId
|
|
281
|
-
* @param {Object} schedule - { cron, timezone, recipients, format, runAs, isEnabled }
|
|
282
|
-
* @returns {Promise<Object>} created schedule
|
|
283
|
-
* @example
|
|
284
|
-
* await sdk.reporting.schedules.create('263...', { cron: '0 8 * * MON', timezone: 'America/Denver', recipients: ['a@b.com'] });
|
|
285
|
-
*/
|
|
286
|
-
async createSchedule(viewId, { cron, timezone, recipients, format, runAs, isEnabled } = {}) {
|
|
287
|
-
viewId = String(viewId);
|
|
288
|
-
this.sdk.validateParams(
|
|
289
|
-
{ viewId, cron, timezone, recipients },
|
|
290
|
-
{
|
|
291
|
-
viewId: { type: 'string', required: true },
|
|
292
|
-
cron: { type: 'string', required: true },
|
|
293
|
-
timezone: { type: 'string', required: true },
|
|
294
|
-
recipients: { type: 'array', required: true },
|
|
295
|
-
},
|
|
296
|
-
);
|
|
297
|
-
const body = { cron, timezone, recipients };
|
|
298
|
-
if (format !== undefined) body.format = format;
|
|
299
|
-
if (runAs !== undefined) body.runAs = runAs;
|
|
300
|
-
if (isEnabled !== undefined) body.isEnabled = isEnabled;
|
|
301
|
-
return internalRequest(this.sdk, `/reporting/views/${viewId}/schedule`, 'POST', { body });
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
/**
|
|
305
|
-
* @param {string} viewId
|
|
306
|
-
* @returns {Promise<Object>} { results: [...] }
|
|
307
|
-
* @example
|
|
308
|
-
* await sdk.reporting.schedules.list('263...');
|
|
309
|
-
*/
|
|
310
|
-
async listSchedules(viewId) {
|
|
311
|
-
viewId = String(viewId);
|
|
312
|
-
this.sdk.validateParams({ viewId }, { viewId: { type: 'string', required: true } });
|
|
313
|
-
return internalRequest(this.sdk, `/reporting/views/${viewId}/schedule`, 'GET');
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
/**
|
|
317
|
-
* @param {string} viewId
|
|
318
|
-
* @param {string} scheduleId
|
|
319
|
-
* @param {Object} data - partial { cron, timezone, recipients, format, isEnabled }
|
|
320
|
-
* @returns {Promise<Object>} updated schedule
|
|
321
|
-
* @example
|
|
322
|
-
* await sdk.reporting.schedules.update('263...', '264...', { isEnabled: false });
|
|
323
|
-
*/
|
|
324
|
-
async updateSchedule(viewId, scheduleId, data = {}) {
|
|
325
|
-
viewId = String(viewId);
|
|
326
|
-
scheduleId = String(scheduleId);
|
|
327
|
-
this.sdk.validateParams(
|
|
328
|
-
{ viewId, scheduleId },
|
|
329
|
-
{ viewId: { type: 'string', required: true }, scheduleId: { type: 'string', required: true } },
|
|
330
|
-
);
|
|
331
|
-
return internalRequest(
|
|
332
|
-
this.sdk,
|
|
333
|
-
`/reporting/views/${viewId}/schedule/${scheduleId}`,
|
|
334
|
-
'PUT',
|
|
335
|
-
{ body: data },
|
|
336
|
-
);
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
/**
|
|
340
|
-
* @param {string} viewId
|
|
341
|
-
* @param {string} scheduleId
|
|
342
|
-
* @returns {Promise<Object>} { id, deleted: true }
|
|
343
|
-
* @example
|
|
344
|
-
* await sdk.reporting.schedules.remove('263...', '264...');
|
|
345
|
-
*/
|
|
346
|
-
async removeSchedule(viewId, scheduleId) {
|
|
347
|
-
viewId = String(viewId);
|
|
348
|
-
scheduleId = String(scheduleId);
|
|
349
|
-
this.sdk.validateParams(
|
|
350
|
-
{ viewId, scheduleId },
|
|
351
|
-
{ viewId: { type: 'string', required: true }, scheduleId: { type: 'string', required: true } },
|
|
352
|
-
);
|
|
353
|
-
return internalRequest(this.sdk, `/reporting/views/${viewId}/schedule/${scheduleId}`, 'DELETE');
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
/**
|
|
357
|
-
* @returns {Promise<Array>} schedule runs (status, startedAt, finishedAt, error, attempt)
|
|
358
|
-
* @example
|
|
359
|
-
* await sdk.reporting.schedules.runs('263...', '264...');
|
|
360
|
-
*/
|
|
361
|
-
async listScheduleRuns(viewId, scheduleId) {
|
|
362
|
-
viewId = String(viewId);
|
|
363
|
-
scheduleId = String(scheduleId);
|
|
364
|
-
this.sdk.validateParams(
|
|
365
|
-
{ viewId, scheduleId },
|
|
366
|
-
{ viewId: { type: 'string', required: true }, scheduleId: { type: 'string', required: true } },
|
|
367
|
-
);
|
|
368
|
-
return internalRequest(this.sdk, `/reporting/views/${viewId}/schedule/${scheduleId}/runs`, 'GET');
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
/**
|
|
372
|
-
* Manual trigger -- runs the same delivery path as the cron tick, awaits
|
|
373
|
-
* sent/failed instead of just queuing.
|
|
374
|
-
* @param {string} viewId
|
|
375
|
-
* @param {string} scheduleId
|
|
376
|
-
* @returns {Promise<Object>} { id, status, attempt, error? }
|
|
377
|
-
* @example
|
|
378
|
-
* await sdk.reporting.schedules.runNow('263...', '264...');
|
|
379
|
-
*/
|
|
380
|
-
async runScheduleNow(viewId, scheduleId) {
|
|
381
|
-
viewId = String(viewId);
|
|
382
|
-
scheduleId = String(scheduleId);
|
|
383
|
-
this.sdk.validateParams(
|
|
384
|
-
{ viewId, scheduleId },
|
|
385
|
-
{ viewId: { type: 'string', required: true }, scheduleId: { type: 'string', required: true } },
|
|
386
|
-
);
|
|
387
|
-
return internalRequest(
|
|
388
|
-
this.sdk,
|
|
389
|
-
`/reporting/views/${viewId}/schedule/${scheduleId}/run-now`,
|
|
390
|
-
'POST',
|
|
391
|
-
);
|
|
392
|
-
}
|
|
393
226
|
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { internalRequest } from '../base.js';
|
|
2
|
+
|
|
3
|
+
// analytics-expansion live-testing fix: report-scoped users list beyond
|
|
4
|
+
// team members (Call log's Users filter). Own file (not reporting.js) same
|
|
5
|
+
// as ReportingMissedCallsService -- keeps reporting.js under the repo's
|
|
6
|
+
// 400-line limit.
|
|
7
|
+
export class ReportingUsersService {
|
|
8
|
+
constructor(sdk) {
|
|
9
|
+
this.sdk = sdk;
|
|
10
|
+
this.scope = (...args) => this.getUsersScope(...args);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Report-scoped users list beyond team members (analytics-expansion
|
|
15
|
+
* live-testing fix -- Call log's Users filter).
|
|
16
|
+
* @returns {Promise<Object>} { all: true } | { all: false, userIds: string[] }
|
|
17
|
+
* @example
|
|
18
|
+
* const { all, userIds } = await sdk.reporting.users.scope();
|
|
19
|
+
*/
|
|
20
|
+
async getUsersScope() {
|
|
21
|
+
return internalRequest(this.sdk, '/reporting/users/scope', 'GET');
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import { internalRequest } from '../base.js';
|
|
2
|
+
|
|
3
|
+
// F7 (cc-reporting-foundation-plan.md §8) -- saved views + their email
|
|
4
|
+
// schedules. Own file (not reporting.js) -- keeps reporting.js under the
|
|
5
|
+
// repo's 400-line limit.
|
|
6
|
+
export class ReportingViewsService {
|
|
7
|
+
constructor(sdk) {
|
|
8
|
+
this.sdk = sdk;
|
|
9
|
+
this.views = {
|
|
10
|
+
list: (...args) => this.listViews(...args),
|
|
11
|
+
create: (...args) => this.createView(...args),
|
|
12
|
+
update: (...args) => this.updateView(...args),
|
|
13
|
+
remove: (...args) => this.removeView(...args),
|
|
14
|
+
};
|
|
15
|
+
this.schedules = {
|
|
16
|
+
create: (...args) => this.createSchedule(...args),
|
|
17
|
+
list: (...args) => this.listSchedules(...args),
|
|
18
|
+
update: (...args) => this.updateSchedule(...args),
|
|
19
|
+
remove: (...args) => this.removeSchedule(...args),
|
|
20
|
+
runs: (...args) => this.listScheduleRuns(...args),
|
|
21
|
+
runNow: (...args) => this.runScheduleNow(...args),
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @param {Object} [params] - { reportKey?: string } -- analytics-expansion
|
|
27
|
+
* A0b: omit for Explore views only (unchanged default); pass
|
|
28
|
+
* 'callLog' for that report's saved views instead.
|
|
29
|
+
* @returns {Promise<Object>} { results: [...] }
|
|
30
|
+
* @example
|
|
31
|
+
* const { results } = await sdk.reporting.views.list();
|
|
32
|
+
* const { results } = await sdk.reporting.views.list({ reportKey: 'callLog' });
|
|
33
|
+
*/
|
|
34
|
+
async listViews({ reportKey } = {}) {
|
|
35
|
+
const parts = [];
|
|
36
|
+
if (reportKey) parts.push(`reportKey=${encodeURIComponent(reportKey)}`);
|
|
37
|
+
const qs = parts.length ? `?${parts.join('&')}` : '';
|
|
38
|
+
return internalRequest(this.sdk, `/reporting/views${qs}`, 'GET');
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @param {Object} view - { name, query, isShared }
|
|
43
|
+
* @returns {Promise<Object>} created view
|
|
44
|
+
* @example
|
|
45
|
+
* await sdk.reporting.views.create({ name: 'Daily SL', query: {...} });
|
|
46
|
+
*/
|
|
47
|
+
async createView({ name, query, isShared } = {}) {
|
|
48
|
+
this.sdk.validateParams(
|
|
49
|
+
{ name, query },
|
|
50
|
+
{ name: { type: 'string', required: true }, query: { type: 'object', required: true } },
|
|
51
|
+
);
|
|
52
|
+
const body = { name, query };
|
|
53
|
+
if (isShared !== undefined) body.isShared = isShared;
|
|
54
|
+
return internalRequest(this.sdk, '/reporting/views', 'POST', { body });
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* @param {string} id
|
|
59
|
+
* @param {Object} data - { name, query, isShared }
|
|
60
|
+
* @returns {Promise<Object>} updated view
|
|
61
|
+
* @example
|
|
62
|
+
* await sdk.reporting.views.update('263...', { isShared: true });
|
|
63
|
+
*/
|
|
64
|
+
async updateView(id, data) {
|
|
65
|
+
id = String(id);
|
|
66
|
+
this.sdk.validateParams({ id }, { id: { type: 'string', required: true } });
|
|
67
|
+
return internalRequest(this.sdk, `/reporting/views/${id}`, 'PUT', { body: data });
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* @param {string} id
|
|
72
|
+
* @returns {Promise<Object>} { id, deleted: true }
|
|
73
|
+
* @example
|
|
74
|
+
* await sdk.reporting.views.remove('263...');
|
|
75
|
+
*/
|
|
76
|
+
async removeView(id) {
|
|
77
|
+
id = String(id);
|
|
78
|
+
this.sdk.validateParams({ id }, { id: { type: 'string', required: true } });
|
|
79
|
+
return internalRequest(this.sdk, `/reporting/views/${id}`, 'DELETE');
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* @param {string} viewId
|
|
84
|
+
* @param {Object} schedule - { cron, timezone, recipients, format, runAs, isEnabled }
|
|
85
|
+
* @returns {Promise<Object>} created schedule
|
|
86
|
+
* @example
|
|
87
|
+
* await sdk.reporting.schedules.create('263...', { cron: '0 8 * * MON', timezone: 'America/Denver', recipients: ['a@b.com'] });
|
|
88
|
+
*/
|
|
89
|
+
async createSchedule(viewId, { cron, timezone, recipients, format, runAs, isEnabled } = {}) {
|
|
90
|
+
viewId = String(viewId);
|
|
91
|
+
this.sdk.validateParams(
|
|
92
|
+
{ viewId, cron, timezone, recipients },
|
|
93
|
+
{
|
|
94
|
+
viewId: { type: 'string', required: true },
|
|
95
|
+
cron: { type: 'string', required: true },
|
|
96
|
+
timezone: { type: 'string', required: true },
|
|
97
|
+
recipients: { type: 'array', required: true },
|
|
98
|
+
},
|
|
99
|
+
);
|
|
100
|
+
const body = { cron, timezone, recipients };
|
|
101
|
+
if (format !== undefined) body.format = format;
|
|
102
|
+
if (runAs !== undefined) body.runAs = runAs;
|
|
103
|
+
if (isEnabled !== undefined) body.isEnabled = isEnabled;
|
|
104
|
+
return internalRequest(this.sdk, `/reporting/views/${viewId}/schedule`, 'POST', { body });
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* @param {string} viewId
|
|
109
|
+
* @returns {Promise<Object>} { results: [...] }
|
|
110
|
+
* @example
|
|
111
|
+
* await sdk.reporting.schedules.list('263...');
|
|
112
|
+
*/
|
|
113
|
+
async listSchedules(viewId) {
|
|
114
|
+
viewId = String(viewId);
|
|
115
|
+
this.sdk.validateParams({ viewId }, { viewId: { type: 'string', required: true } });
|
|
116
|
+
return internalRequest(this.sdk, `/reporting/views/${viewId}/schedule`, 'GET');
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* @param {string} viewId
|
|
121
|
+
* @param {string} scheduleId
|
|
122
|
+
* @param {Object} data - partial { cron, timezone, recipients, format, isEnabled }
|
|
123
|
+
* @returns {Promise<Object>} updated schedule
|
|
124
|
+
* @example
|
|
125
|
+
* await sdk.reporting.schedules.update('263...', '264...', { isEnabled: false });
|
|
126
|
+
*/
|
|
127
|
+
async updateSchedule(viewId, scheduleId, data = {}) {
|
|
128
|
+
viewId = String(viewId);
|
|
129
|
+
scheduleId = String(scheduleId);
|
|
130
|
+
this.sdk.validateParams(
|
|
131
|
+
{ viewId, scheduleId },
|
|
132
|
+
{ viewId: { type: 'string', required: true }, scheduleId: { type: 'string', required: true } },
|
|
133
|
+
);
|
|
134
|
+
return internalRequest(
|
|
135
|
+
this.sdk,
|
|
136
|
+
`/reporting/views/${viewId}/schedule/${scheduleId}`,
|
|
137
|
+
'PUT',
|
|
138
|
+
{ body: data },
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* @param {string} viewId
|
|
144
|
+
* @param {string} scheduleId
|
|
145
|
+
* @returns {Promise<Object>} { id, deleted: true }
|
|
146
|
+
* @example
|
|
147
|
+
* await sdk.reporting.schedules.remove('263...', '264...');
|
|
148
|
+
*/
|
|
149
|
+
async removeSchedule(viewId, scheduleId) {
|
|
150
|
+
viewId = String(viewId);
|
|
151
|
+
scheduleId = String(scheduleId);
|
|
152
|
+
this.sdk.validateParams(
|
|
153
|
+
{ viewId, scheduleId },
|
|
154
|
+
{ viewId: { type: 'string', required: true }, scheduleId: { type: 'string', required: true } },
|
|
155
|
+
);
|
|
156
|
+
return internalRequest(this.sdk, `/reporting/views/${viewId}/schedule/${scheduleId}`, 'DELETE');
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* @returns {Promise<Array>} schedule runs (status, startedAt, finishedAt, error, attempt)
|
|
161
|
+
* @example
|
|
162
|
+
* await sdk.reporting.schedules.runs('263...', '264...');
|
|
163
|
+
*/
|
|
164
|
+
async listScheduleRuns(viewId, scheduleId) {
|
|
165
|
+
viewId = String(viewId);
|
|
166
|
+
scheduleId = String(scheduleId);
|
|
167
|
+
this.sdk.validateParams(
|
|
168
|
+
{ viewId, scheduleId },
|
|
169
|
+
{ viewId: { type: 'string', required: true }, scheduleId: { type: 'string', required: true } },
|
|
170
|
+
);
|
|
171
|
+
return internalRequest(this.sdk, `/reporting/views/${viewId}/schedule/${scheduleId}/runs`, 'GET');
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Manual trigger -- runs the same delivery path as the cron tick, awaits
|
|
176
|
+
* sent/failed instead of just queuing.
|
|
177
|
+
* @param {string} viewId
|
|
178
|
+
* @param {string} scheduleId
|
|
179
|
+
* @returns {Promise<Object>} { id, status, attempt, error? }
|
|
180
|
+
* @example
|
|
181
|
+
* await sdk.reporting.schedules.runNow('263...', '264...');
|
|
182
|
+
*/
|
|
183
|
+
async runScheduleNow(viewId, scheduleId) {
|
|
184
|
+
viewId = String(viewId);
|
|
185
|
+
scheduleId = String(scheduleId);
|
|
186
|
+
this.sdk.validateParams(
|
|
187
|
+
{ viewId, scheduleId },
|
|
188
|
+
{ viewId: { type: 'string', required: true }, scheduleId: { type: 'string', required: true } },
|
|
189
|
+
);
|
|
190
|
+
return internalRequest(
|
|
191
|
+
this.sdk,
|
|
192
|
+
`/reporting/views/${viewId}/schedule/${scheduleId}/run-now`,
|
|
193
|
+
'POST',
|
|
194
|
+
);
|
|
195
|
+
}
|
|
196
|
+
}
|