@getmodus/sdk 0.6.0 → 0.7.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/CHANGELOG.md +84 -4
- package/README.md +9 -1
- package/dist/{chunk-HEHHN4D6.js → chunk-JMFT5KO5.js} +330 -11
- package/dist/chunk-JMFT5KO5.js.map +1 -0
- package/dist/{conversations-BRg8gEKX.d.cts → conversations-B0_jmEuT.d.cts} +10469 -3196
- package/dist/{conversations-BRg8gEKX.d.ts → conversations-B0_jmEuT.d.ts} +10469 -3196
- package/dist/index.cjs +618 -58
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +372 -54
- package/dist/index.d.ts +372 -54
- package/dist/index.js +290 -49
- package/dist/index.js.map +1 -1
- package/dist/management/index.cjs +1134 -44
- package/dist/management/index.cjs.map +1 -1
- package/dist/management/index.d.cts +600 -9
- package/dist/management/index.d.ts +600 -9
- package/dist/management/index.js +807 -36
- package/dist/management/index.js.map +1 -1
- package/package.json +2 -3
- package/dist/chunk-HEHHN4D6.js.map +0 -1
package/dist/management/index.js
CHANGED
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
omitUndefined,
|
|
11
11
|
validateId,
|
|
12
12
|
validatePageSize
|
|
13
|
-
} from "../chunk-
|
|
13
|
+
} from "../chunk-JMFT5KO5.js";
|
|
14
14
|
|
|
15
15
|
// src/_query.ts
|
|
16
16
|
function updateMaskQuery(updateMask) {
|
|
@@ -161,6 +161,13 @@ var ManagementWorkflowsResource = class {
|
|
|
161
161
|
* @param options.view - Variation view: `"active"` (deployed) or `"draft"`.
|
|
162
162
|
* @param options.includeVariation - Include variation payload on each list row.
|
|
163
163
|
* @returns A page of workflows.
|
|
164
|
+
* @example
|
|
165
|
+
* ```ts
|
|
166
|
+
* const mgmt = new ModusManagement()
|
|
167
|
+
* for await (const wf of (await mgmt.workflows.list({ search: 'digest' })).autoPagingIter()) {
|
|
168
|
+
* console.log(wf.id, wf.name, wf.status)
|
|
169
|
+
* }
|
|
170
|
+
* ```
|
|
164
171
|
*/
|
|
165
172
|
list(options = {}) {
|
|
166
173
|
const pageSize = options.pageSize ?? 25;
|
|
@@ -193,6 +200,12 @@ var ManagementWorkflowsResource = class {
|
|
|
193
200
|
* @param workflowId - Workflow id.
|
|
194
201
|
* @param options.view - Variation view: `"active"` (deployed) or `"draft"`.
|
|
195
202
|
* @returns The workflow.
|
|
203
|
+
* @example
|
|
204
|
+
* ```ts
|
|
205
|
+
* const mgmt = new ModusManagement()
|
|
206
|
+
* const wf = await mgmt.workflows.get('weekly-digest')
|
|
207
|
+
* console.log(wf.name, wf.status)
|
|
208
|
+
* ```
|
|
196
209
|
*/
|
|
197
210
|
async get(workflowId, options = {}) {
|
|
198
211
|
validateId(workflowId, "workflow_id");
|
|
@@ -222,7 +235,8 @@ var ManagementWorkflowsResource = class {
|
|
|
222
235
|
* @returns The created workflow (draft).
|
|
223
236
|
* @example
|
|
224
237
|
* ```ts
|
|
225
|
-
* const
|
|
238
|
+
* const mgmt = new ModusManagement()
|
|
239
|
+
* const wf = await mgmt.workflows.create({ name: 'Daily report', type: 'task' })
|
|
226
240
|
* ```
|
|
227
241
|
*/
|
|
228
242
|
async create(options) {
|
|
@@ -250,6 +264,11 @@ var ManagementWorkflowsResource = class {
|
|
|
250
264
|
* @param options.guardrails - Guardrail labels to set. Fetches the current workflow first to merge. Pass `[]` to clear all.
|
|
251
265
|
* @param options.updateMask - Comma-separated field names to update or clear.
|
|
252
266
|
* @returns The updated workflow.
|
|
267
|
+
* @example
|
|
268
|
+
* ```ts
|
|
269
|
+
* const mgmt = new ModusManagement()
|
|
270
|
+
* const wf = await mgmt.workflows.update('PLACEHOLDER_WORKFLOW_ID', { description: 'Runs every morning' })
|
|
271
|
+
* ```
|
|
253
272
|
*/
|
|
254
273
|
async update(workflowId, options = {}) {
|
|
255
274
|
validateId(workflowId, "workflow_id");
|
|
@@ -285,8 +304,9 @@ var ManagementWorkflowsResource = class {
|
|
|
285
304
|
* @returns The published workflow.
|
|
286
305
|
* @example
|
|
287
306
|
* ```ts
|
|
288
|
-
*
|
|
289
|
-
*
|
|
307
|
+
* const mgmt = new ModusManagement()
|
|
308
|
+
* await mgmt.workflows.update('PLACEHOLDER_WORKFLOW_ID', { description: 'Runs every morning' })
|
|
309
|
+
* const published = await mgmt.workflows.deploy('PLACEHOLDER_WORKFLOW_ID')
|
|
290
310
|
* ```
|
|
291
311
|
*/
|
|
292
312
|
async deploy(workflowId) {
|
|
@@ -319,6 +339,11 @@ var ManagementWorkflowsResource = class {
|
|
|
319
339
|
*
|
|
320
340
|
* @param workflowId - Workflow id.
|
|
321
341
|
* @returns Resolves when the workflow is deleted.
|
|
342
|
+
* @example
|
|
343
|
+
* ```ts
|
|
344
|
+
* const mgmt = new ModusManagement()
|
|
345
|
+
* await mgmt.workflows.delete('PLACEHOLDER_WORKFLOW_ID')
|
|
346
|
+
* ```
|
|
322
347
|
*/
|
|
323
348
|
async delete(workflowId) {
|
|
324
349
|
validateId(workflowId, "workflow_id");
|
|
@@ -472,9 +497,526 @@ async function resolveAndUpdateLink(items, uid, options) {
|
|
|
472
497
|
});
|
|
473
498
|
}
|
|
474
499
|
|
|
500
|
+
// src/management/context/dashboards.ts
|
|
501
|
+
var ManagementDashboardElementsResource = class {
|
|
502
|
+
/** @internal */
|
|
503
|
+
constructor(http, config, dashboardId) {
|
|
504
|
+
this.http = http;
|
|
505
|
+
this.config = config;
|
|
506
|
+
this.dashboardId = dashboardId;
|
|
507
|
+
}
|
|
508
|
+
/**
|
|
509
|
+
* List every tile and filter on the dashboard draft.
|
|
510
|
+
*
|
|
511
|
+
* @returns Each element's id, kind, title and grid position, plus the current
|
|
512
|
+
* `draftRevision` to pass as `expectedRevision` on the next change.
|
|
513
|
+
* @throws NotFoundError - The dashboard does not exist or you cannot edit it.
|
|
514
|
+
* @example
|
|
515
|
+
* ```ts
|
|
516
|
+
* const listed = await mgmt.context.dashboards.elements('DASHBOARD_ID').list()
|
|
517
|
+
* listed.elements.map((element) => element.id)
|
|
518
|
+
* ```
|
|
519
|
+
*/
|
|
520
|
+
async list() {
|
|
521
|
+
return asRecord(
|
|
522
|
+
await invokeWithRetry(this.config, this.http, "DashboardsController_listElements", {
|
|
523
|
+
pathParams: { dashboardId: this.dashboardId }
|
|
524
|
+
})
|
|
525
|
+
);
|
|
526
|
+
}
|
|
527
|
+
/**
|
|
528
|
+
* Get the full draft settings of one tile or filter.
|
|
529
|
+
*
|
|
530
|
+
* @param elementId - Id of the tile or filter, as returned by `list()`.
|
|
531
|
+
* @returns The element's settings and the current `draftRevision`.
|
|
532
|
+
* @throws NotFoundError - The dashboard or the element does not exist, or you cannot
|
|
533
|
+
* edit the dashboard.
|
|
534
|
+
* @example
|
|
535
|
+
* ```ts
|
|
536
|
+
* const result = await mgmt.context.dashboards.elements('DASHBOARD_ID').get('ELEMENT_ID')
|
|
537
|
+
* result.element.title
|
|
538
|
+
* ```
|
|
539
|
+
*/
|
|
540
|
+
async get(elementId) {
|
|
541
|
+
validateId(elementId, "elementId");
|
|
542
|
+
return asRecord(
|
|
543
|
+
await invokeWithRetry(this.config, this.http, "DashboardsController_getElement", {
|
|
544
|
+
pathParams: { dashboardId: this.dashboardId, elementId }
|
|
545
|
+
})
|
|
546
|
+
);
|
|
547
|
+
}
|
|
548
|
+
/**
|
|
549
|
+
* Add a blank tile or filter to the dashboard draft.
|
|
550
|
+
*
|
|
551
|
+
* Modus assigns the new element's id; configure it afterwards with `update()`.
|
|
552
|
+
*
|
|
553
|
+
* @param input.expectedRevision - The `draftRevision` your change is based on.
|
|
554
|
+
* @param input.kind - `chart`, `kpi`, `table`, `markdown` or `filter`.
|
|
555
|
+
* @param input.title - Title shown on the element.
|
|
556
|
+
* @param input.layout - Grid position with `x` (0-11), `y`, `w` (1-12) and `h`.
|
|
557
|
+
* @returns The created element and the new `draftRevision`.
|
|
558
|
+
* @throws ConflictError - The draft changed since `expectedRevision`; list the
|
|
559
|
+
* elements again and retry with the new revision.
|
|
560
|
+
* @example
|
|
561
|
+
* ```ts
|
|
562
|
+
* const created = await mgmt.context.dashboards.elements('DASHBOARD_ID').create({
|
|
563
|
+
* expectedRevision: 3,
|
|
564
|
+
* kind: 'chart',
|
|
565
|
+
* title: 'Sales by region',
|
|
566
|
+
* layout: { x: 0, y: 4, w: 6, h: 4 },
|
|
567
|
+
* })
|
|
568
|
+
* ```
|
|
569
|
+
*/
|
|
570
|
+
async create(input) {
|
|
571
|
+
return asRecord(
|
|
572
|
+
await invokeWithRetry(this.config, this.http, "DashboardsController_createElement", {
|
|
573
|
+
pathParams: { dashboardId: this.dashboardId },
|
|
574
|
+
jsonBody: {
|
|
575
|
+
expectedRevision: input.expectedRevision,
|
|
576
|
+
kind: input.kind,
|
|
577
|
+
title: input.title,
|
|
578
|
+
layout: input.layout
|
|
579
|
+
}
|
|
580
|
+
})
|
|
581
|
+
);
|
|
582
|
+
}
|
|
583
|
+
/**
|
|
584
|
+
* Change settings of one tile or filter on the dashboard draft.
|
|
585
|
+
*
|
|
586
|
+
* @param elementId - Id of the tile or filter to change.
|
|
587
|
+
* @param input.expectedRevision - The `draftRevision` your change is based on.
|
|
588
|
+
* @param input.patch - The settings to change, for example `{ title: 'Sales' }`
|
|
589
|
+
* or `{ defaultValue: null }`. `null` clears a setting that supports clearing.
|
|
590
|
+
* @returns The whole dashboard after the change, including the new `draftRevision`.
|
|
591
|
+
* @throws ConflictError - The draft changed since `expectedRevision`.
|
|
592
|
+
* @throws NotFoundError - The dashboard or the element does not exist, or you cannot
|
|
593
|
+
* edit the dashboard.
|
|
594
|
+
* @example
|
|
595
|
+
* ```ts
|
|
596
|
+
* const dashboard = await mgmt.context.dashboards
|
|
597
|
+
* .elements('DASHBOARD_ID')
|
|
598
|
+
* .update('ELEMENT_ID', { expectedRevision: 3, patch: { title: 'Revenue' } })
|
|
599
|
+
* ```
|
|
600
|
+
*/
|
|
601
|
+
async update(elementId, input) {
|
|
602
|
+
validateId(elementId, "elementId");
|
|
603
|
+
return asRecord(
|
|
604
|
+
await invokeWithRetry(this.config, this.http, "DashboardsController_updateElement", {
|
|
605
|
+
pathParams: { dashboardId: this.dashboardId, elementId },
|
|
606
|
+
jsonBody: { expectedRevision: input.expectedRevision, patch: input.patch }
|
|
607
|
+
})
|
|
608
|
+
);
|
|
609
|
+
}
|
|
610
|
+
};
|
|
611
|
+
var ManagementDashboardsResource = class {
|
|
612
|
+
/** @internal */
|
|
613
|
+
constructor(http, config) {
|
|
614
|
+
this.http = http;
|
|
615
|
+
this.config = config;
|
|
616
|
+
}
|
|
617
|
+
/**
|
|
618
|
+
* List dashboards with their full definitions.
|
|
619
|
+
*
|
|
620
|
+
* @param options.view - `active` (default) lists published dashboards you can open;
|
|
621
|
+
* `draft` lists the drafts of dashboards you can edit.
|
|
622
|
+
* @returns Every matching dashboard. The list is not paginated.
|
|
623
|
+
* @example
|
|
624
|
+
* ```ts
|
|
625
|
+
* const drafts = await mgmt.context.dashboards.list({ view: 'draft' })
|
|
626
|
+
* drafts.map((dashboard) => [dashboard.id, dashboard.draftRevision])
|
|
627
|
+
* ```
|
|
628
|
+
*/
|
|
629
|
+
async list(options = {}) {
|
|
630
|
+
const data = asRecord(
|
|
631
|
+
await invokeWithRetry(this.config, this.http, "DashboardsController_list", {
|
|
632
|
+
query: { view: options.view }
|
|
633
|
+
})
|
|
634
|
+
);
|
|
635
|
+
return data.dashboards;
|
|
636
|
+
}
|
|
637
|
+
/**
|
|
638
|
+
* Get one dashboard with its full definition.
|
|
639
|
+
*
|
|
640
|
+
* @param dashboardId - Id of the dashboard.
|
|
641
|
+
* @param options.view - `active` (default) returns the published version; `draft`
|
|
642
|
+
* returns the working draft and requires edit access.
|
|
643
|
+
* @returns The dashboard, including `draftRevision` for the next change.
|
|
644
|
+
* @throws NotFoundError - The dashboard does not exist or you cannot open it.
|
|
645
|
+
* @example
|
|
646
|
+
* ```ts
|
|
647
|
+
* const draft = await mgmt.context.dashboards.get('DASHBOARD_ID', { view: 'draft' })
|
|
648
|
+
* draft.draftRevision
|
|
649
|
+
* ```
|
|
650
|
+
*/
|
|
651
|
+
async get(dashboardId, options = {}) {
|
|
652
|
+
validateId(dashboardId, "dashboardId");
|
|
653
|
+
return asRecord(
|
|
654
|
+
await invokeWithRetry(this.config, this.http, "DashboardsController_get", {
|
|
655
|
+
pathParams: { dashboardId },
|
|
656
|
+
query: { view: options.view }
|
|
657
|
+
})
|
|
658
|
+
);
|
|
659
|
+
}
|
|
660
|
+
/**
|
|
661
|
+
* Create a dashboard draft.
|
|
662
|
+
*
|
|
663
|
+
* The new dashboard is not visible to others until you `publish()` it.
|
|
664
|
+
*
|
|
665
|
+
* @param input.title - Dashboard title.
|
|
666
|
+
* @param input.definition - Tiles, filters and layout, for example
|
|
667
|
+
* `{ tiles: [], filters: [] }`. Element ids must be unique.
|
|
668
|
+
* @param input.description - Optional dashboard description.
|
|
669
|
+
* @param input.access - Optional `visibility`, `groupPermissions` and `sharedWith`.
|
|
670
|
+
* Defaults to private.
|
|
671
|
+
* @returns The created dashboard in its draft view.
|
|
672
|
+
* @throws ModusError - The definition or access settings are invalid.
|
|
673
|
+
* @example
|
|
674
|
+
* ```ts
|
|
675
|
+
* const dashboard = await mgmt.context.dashboards.create({
|
|
676
|
+
* title: 'Revenue',
|
|
677
|
+
* definition: { tiles: [], filters: [] },
|
|
678
|
+
* })
|
|
679
|
+
* dashboard.id
|
|
680
|
+
* ```
|
|
681
|
+
*/
|
|
682
|
+
async create(input) {
|
|
683
|
+
return asRecord(
|
|
684
|
+
await invokeWithRetry(this.config, this.http, "DashboardsController_create", {
|
|
685
|
+
jsonBody: {
|
|
686
|
+
title: input.title,
|
|
687
|
+
description: input.description,
|
|
688
|
+
definition: input.definition,
|
|
689
|
+
access: input.access
|
|
690
|
+
}
|
|
691
|
+
})
|
|
692
|
+
);
|
|
693
|
+
}
|
|
694
|
+
/**
|
|
695
|
+
* Replace the whole draft definition, and optionally the title and description.
|
|
696
|
+
*
|
|
697
|
+
* @param dashboardId - Id of the dashboard.
|
|
698
|
+
* @param input.expectedRevision - The `draftRevision` your change is based on.
|
|
699
|
+
* @param input.definition - The complete new definition. Tiles and filters left
|
|
700
|
+
* out are removed.
|
|
701
|
+
* @param input.title - New title; unchanged when omitted.
|
|
702
|
+
* @param input.description - New description; unchanged when omitted.
|
|
703
|
+
* @returns The dashboard draft after the change, including the new `draftRevision`.
|
|
704
|
+
* @throws ConflictError - The draft changed since `expectedRevision`; get the draft
|
|
705
|
+
* again and retry with the new revision.
|
|
706
|
+
* @throws NotFoundError - The dashboard does not exist or you cannot edit it.
|
|
707
|
+
* @example
|
|
708
|
+
* ```ts
|
|
709
|
+
* const draft = await mgmt.context.dashboards.get('DASHBOARD_ID', { view: 'draft' })
|
|
710
|
+
* await mgmt.context.dashboards.updateDraft('DASHBOARD_ID', {
|
|
711
|
+
* expectedRevision: draft.draftRevision,
|
|
712
|
+
* definition: draft.definition,
|
|
713
|
+
* title: 'Revenue',
|
|
714
|
+
* })
|
|
715
|
+
* ```
|
|
716
|
+
*/
|
|
717
|
+
async updateDraft(dashboardId, input) {
|
|
718
|
+
validateId(dashboardId, "dashboardId");
|
|
719
|
+
return asRecord(
|
|
720
|
+
await invokeWithRetry(this.config, this.http, "DashboardsController_updateDraft", {
|
|
721
|
+
pathParams: { dashboardId },
|
|
722
|
+
jsonBody: {
|
|
723
|
+
expectedRevision: input.expectedRevision,
|
|
724
|
+
title: input.title,
|
|
725
|
+
description: input.description,
|
|
726
|
+
definition: input.definition
|
|
727
|
+
}
|
|
728
|
+
})
|
|
729
|
+
);
|
|
730
|
+
}
|
|
731
|
+
/**
|
|
732
|
+
* Publish the draft as a new version that everyone with access sees.
|
|
733
|
+
*
|
|
734
|
+
* Alert workflows defined on the dashboard are updated to match.
|
|
735
|
+
*
|
|
736
|
+
* @param dashboardId - Id of the dashboard.
|
|
737
|
+
* @param input.expectedRevision - The `draftRevision` you reviewed and want to publish.
|
|
738
|
+
* @returns The published `dashboard` and the new `version`.
|
|
739
|
+
* @throws ConflictError - The draft changed since `expectedRevision`.
|
|
740
|
+
* @throws NotFoundError - The dashboard does not exist or you cannot edit it.
|
|
741
|
+
* @example
|
|
742
|
+
* ```ts
|
|
743
|
+
* const result = await mgmt.context.dashboards.publish('DASHBOARD_ID', { expectedRevision: 4 })
|
|
744
|
+
* result.version.versionNumber
|
|
745
|
+
* ```
|
|
746
|
+
*/
|
|
747
|
+
async publish(dashboardId, input) {
|
|
748
|
+
validateId(dashboardId, "dashboardId");
|
|
749
|
+
return asRecord(
|
|
750
|
+
await invokeWithRetry(this.config, this.http, "DashboardsController_publish", {
|
|
751
|
+
pathParams: { dashboardId },
|
|
752
|
+
jsonBody: { expectedRevision: input.expectedRevision }
|
|
753
|
+
})
|
|
754
|
+
);
|
|
755
|
+
}
|
|
756
|
+
/**
|
|
757
|
+
* Delete a dashboard and the alert workflows defined on it.
|
|
758
|
+
*
|
|
759
|
+
* A deleted dashboard cannot be restored.
|
|
760
|
+
*
|
|
761
|
+
* @param dashboardId - Id of the dashboard.
|
|
762
|
+
* @throws NotFoundError - The dashboard does not exist or you cannot edit it.
|
|
763
|
+
* @example
|
|
764
|
+
* ```ts
|
|
765
|
+
* await mgmt.context.dashboards.delete('DASHBOARD_ID')
|
|
766
|
+
* ```
|
|
767
|
+
*/
|
|
768
|
+
async delete(dashboardId) {
|
|
769
|
+
validateId(dashboardId, "dashboardId");
|
|
770
|
+
await invokeWithRetry(this.config, this.http, "DashboardsController_delete", {
|
|
771
|
+
pathParams: { dashboardId }
|
|
772
|
+
});
|
|
773
|
+
}
|
|
774
|
+
/**
|
|
775
|
+
* List the published versions of a dashboard, newest first.
|
|
776
|
+
*
|
|
777
|
+
* @param dashboardId - Id of the dashboard.
|
|
778
|
+
* @returns Every published version with its full definition. Definitions are
|
|
779
|
+
* returned as stored, so older versions may lack newer fields. The list is
|
|
780
|
+
* not paginated.
|
|
781
|
+
* @throws NotFoundError - The dashboard does not exist or you cannot open it.
|
|
782
|
+
* @example
|
|
783
|
+
* ```ts
|
|
784
|
+
* const versions = await mgmt.context.dashboards.listVersions('DASHBOARD_ID')
|
|
785
|
+
* versions.map((version) => [version.uid, version.versionNumber])
|
|
786
|
+
* ```
|
|
787
|
+
*/
|
|
788
|
+
async listVersions(dashboardId) {
|
|
789
|
+
validateId(dashboardId, "dashboardId");
|
|
790
|
+
const data = asRecord(
|
|
791
|
+
await invokeWithRetry(this.config, this.http, "DashboardsController_listVersions", {
|
|
792
|
+
pathParams: { dashboardId }
|
|
793
|
+
})
|
|
794
|
+
);
|
|
795
|
+
return data.versions;
|
|
796
|
+
}
|
|
797
|
+
/**
|
|
798
|
+
* Get a dashboard as it was in one version.
|
|
799
|
+
*
|
|
800
|
+
* @param dashboardId - Id of the dashboard.
|
|
801
|
+
* @param versionId - Id of the version, as returned by `listVersions()`.
|
|
802
|
+
* @returns The dashboard with that version's definition.
|
|
803
|
+
* @throws NotFoundError - The dashboard or the version does not exist, or you cannot
|
|
804
|
+
* open the dashboard.
|
|
805
|
+
* @example
|
|
806
|
+
* ```ts
|
|
807
|
+
* const old = await mgmt.context.dashboards.getVersion('DASHBOARD_ID', 'VERSION_ID')
|
|
808
|
+
* old.selectedVersion.versionNumber
|
|
809
|
+
* ```
|
|
810
|
+
*/
|
|
811
|
+
async getVersion(dashboardId, versionId) {
|
|
812
|
+
validateId(dashboardId, "dashboardId");
|
|
813
|
+
validateId(versionId, "versionId");
|
|
814
|
+
return asRecord(
|
|
815
|
+
await invokeWithRetry(this.config, this.http, "DashboardsController_getVersion", {
|
|
816
|
+
pathParams: { dashboardId, versionId }
|
|
817
|
+
})
|
|
818
|
+
);
|
|
819
|
+
}
|
|
820
|
+
/**
|
|
821
|
+
* Replace the draft with the content of an earlier version.
|
|
822
|
+
*
|
|
823
|
+
* The draft being replaced is kept as a draft snapshot. Call `publish()`
|
|
824
|
+
* afterwards to make the restored content visible.
|
|
825
|
+
*
|
|
826
|
+
* @param dashboardId - Id of the dashboard.
|
|
827
|
+
* @param versionId - Id of the version or draft snapshot to restore.
|
|
828
|
+
* @returns The dashboard draft after the restore.
|
|
829
|
+
* @throws NotFoundError - The dashboard or the version does not exist, or you cannot
|
|
830
|
+
* edit the dashboard.
|
|
831
|
+
* @example
|
|
832
|
+
* ```ts
|
|
833
|
+
* await mgmt.context.dashboards.restoreVersion('DASHBOARD_ID', 'VERSION_ID')
|
|
834
|
+
* ```
|
|
835
|
+
*/
|
|
836
|
+
async restoreVersion(dashboardId, versionId) {
|
|
837
|
+
validateId(dashboardId, "dashboardId");
|
|
838
|
+
validateId(versionId, "versionId");
|
|
839
|
+
return asRecord(
|
|
840
|
+
await invokeWithRetry(this.config, this.http, "DashboardsController_restore", {
|
|
841
|
+
pathParams: { dashboardId, versionId }
|
|
842
|
+
})
|
|
843
|
+
);
|
|
844
|
+
}
|
|
845
|
+
/**
|
|
846
|
+
* List recent snapshots of the dashboard draft, newest first.
|
|
847
|
+
*
|
|
848
|
+
* @param dashboardId - Id of the dashboard.
|
|
849
|
+
* @returns Up to 100 snapshots with their id, author and time. Pass an id to
|
|
850
|
+
* `restoreVersion()` to bring that draft back.
|
|
851
|
+
* @throws NotFoundError - The dashboard does not exist or you cannot edit it.
|
|
852
|
+
* @example
|
|
853
|
+
* ```ts
|
|
854
|
+
* const snapshots = await mgmt.context.dashboards.listDraftSnapshots('DASHBOARD_ID')
|
|
855
|
+
* snapshots.map((snapshot) => snapshot.uid)
|
|
856
|
+
* ```
|
|
857
|
+
*/
|
|
858
|
+
async listDraftSnapshots(dashboardId) {
|
|
859
|
+
validateId(dashboardId, "dashboardId");
|
|
860
|
+
const data = asRecord(
|
|
861
|
+
await invokeWithRetry(this.config, this.http, "DashboardsController_listDraftSnapshots", {
|
|
862
|
+
pathParams: { dashboardId }
|
|
863
|
+
})
|
|
864
|
+
);
|
|
865
|
+
return data.snapshots;
|
|
866
|
+
}
|
|
867
|
+
/**
|
|
868
|
+
* Replace who can open and edit a dashboard.
|
|
869
|
+
*
|
|
870
|
+
* All three settings are required and replace the current ones.
|
|
871
|
+
*
|
|
872
|
+
* @param dashboardId - Id of the dashboard.
|
|
873
|
+
* @param input.visibility - `shared` (the owner plus the groups in
|
|
874
|
+
* `groupPermissions`) or `private` (the owner plus the users in `sharedWith`).
|
|
875
|
+
* @param input.groupPermissions - Group id to `{ use, manage }`. Used only when shared.
|
|
876
|
+
* @param input.sharedWith - Users such as `{ email: 'ana@example.com', permission: 'use' }`.
|
|
877
|
+
* Used only when private.
|
|
878
|
+
* @returns The dashboard with its new access settings.
|
|
879
|
+
* @throws NotFoundError - The dashboard does not exist or you cannot edit it.
|
|
880
|
+
* @throws ModusError - A group, user or permission is invalid.
|
|
881
|
+
* @example
|
|
882
|
+
* ```ts
|
|
883
|
+
* await mgmt.context.dashboards.updateAccess('DASHBOARD_ID', {
|
|
884
|
+
* visibility: 'private',
|
|
885
|
+
* groupPermissions: {},
|
|
886
|
+
* sharedWith: [{ email: 'ana@example.com', permission: 'use' }],
|
|
887
|
+
* })
|
|
888
|
+
* ```
|
|
889
|
+
*/
|
|
890
|
+
async updateAccess(dashboardId, input) {
|
|
891
|
+
validateId(dashboardId, "dashboardId");
|
|
892
|
+
return asRecord(
|
|
893
|
+
await invokeWithRetry(this.config, this.http, "DashboardsController_updateAccess", {
|
|
894
|
+
pathParams: { dashboardId },
|
|
895
|
+
jsonBody: {
|
|
896
|
+
visibility: input.visibility,
|
|
897
|
+
groupPermissions: input.groupPermissions,
|
|
898
|
+
sharedWith: input.sharedWith
|
|
899
|
+
}
|
|
900
|
+
})
|
|
901
|
+
);
|
|
902
|
+
}
|
|
903
|
+
/**
|
|
904
|
+
* Ask another member of your organization to take ownership of a dashboard.
|
|
905
|
+
*
|
|
906
|
+
* Only the owner can request a transfer. Ownership moves when the recipient
|
|
907
|
+
* calls `acceptOwnershipTransfer()`.
|
|
908
|
+
*
|
|
909
|
+
* @param dashboardId - Id of the dashboard.
|
|
910
|
+
* @param input.newOwnerUserId - User id of the member who should become the owner.
|
|
911
|
+
* @returns The dashboard with `pendingOwnershipTransfer` set.
|
|
912
|
+
* @throws PermissionDeniedError - You are not the owner.
|
|
913
|
+
* @throws NotFoundError - The dashboard does not exist or you cannot open it.
|
|
914
|
+
* @example
|
|
915
|
+
* ```ts
|
|
916
|
+
* await mgmt.context.dashboards.requestOwnershipTransfer('DASHBOARD_ID', {
|
|
917
|
+
* newOwnerUserId: 'USER_ID',
|
|
918
|
+
* })
|
|
919
|
+
* ```
|
|
920
|
+
*/
|
|
921
|
+
async requestOwnershipTransfer(dashboardId, input) {
|
|
922
|
+
validateId(dashboardId, "dashboardId");
|
|
923
|
+
validateId(input.newOwnerUserId, "newOwnerUserId");
|
|
924
|
+
return asRecord(
|
|
925
|
+
await invokeWithRetry(this.config, this.http, "DashboardsController_transferOwnership", {
|
|
926
|
+
pathParams: { dashboardId },
|
|
927
|
+
jsonBody: { newOwnerUserId: input.newOwnerUserId }
|
|
928
|
+
})
|
|
929
|
+
);
|
|
930
|
+
}
|
|
931
|
+
/**
|
|
932
|
+
* Accept a pending ownership transfer and become the dashboard owner.
|
|
933
|
+
*
|
|
934
|
+
* Only the requested recipient can accept.
|
|
935
|
+
*
|
|
936
|
+
* @param dashboardId - Id of the dashboard.
|
|
937
|
+
* @returns The dashboard with you as its owner.
|
|
938
|
+
* @throws NotFoundError - The dashboard does not exist, or it has no pending transfer
|
|
939
|
+
* addressed to you.
|
|
940
|
+
* @example
|
|
941
|
+
* ```ts
|
|
942
|
+
* await mgmt.context.dashboards.acceptOwnershipTransfer('DASHBOARD_ID')
|
|
943
|
+
* ```
|
|
944
|
+
*/
|
|
945
|
+
async acceptOwnershipTransfer(dashboardId) {
|
|
946
|
+
validateId(dashboardId, "dashboardId");
|
|
947
|
+
return asRecord(
|
|
948
|
+
await invokeWithRetry(this.config, this.http, "DashboardsController_acceptOwnership", {
|
|
949
|
+
pathParams: { dashboardId }
|
|
950
|
+
})
|
|
951
|
+
);
|
|
952
|
+
}
|
|
953
|
+
/**
|
|
954
|
+
* Cancel a pending ownership transfer.
|
|
955
|
+
*
|
|
956
|
+
* Only the owner can cancel.
|
|
957
|
+
*
|
|
958
|
+
* @param dashboardId - Id of the dashboard.
|
|
959
|
+
* @returns The dashboard with no pending transfer.
|
|
960
|
+
* @throws NotFoundError - The dashboard does not exist, you cannot open it, or you are
|
|
961
|
+
* not the owner.
|
|
962
|
+
* @example
|
|
963
|
+
* ```ts
|
|
964
|
+
* await mgmt.context.dashboards.cancelOwnershipTransfer('DASHBOARD_ID')
|
|
965
|
+
* ```
|
|
966
|
+
*/
|
|
967
|
+
async cancelOwnershipTransfer(dashboardId) {
|
|
968
|
+
validateId(dashboardId, "dashboardId");
|
|
969
|
+
return asRecord(
|
|
970
|
+
await invokeWithRetry(this.config, this.http, "DashboardsController_cancelOwnership", {
|
|
971
|
+
pathParams: { dashboardId }
|
|
972
|
+
})
|
|
973
|
+
);
|
|
974
|
+
}
|
|
975
|
+
/**
|
|
976
|
+
* Work with the tiles and filters of one dashboard draft.
|
|
977
|
+
*
|
|
978
|
+
* @param dashboardId - Id of the dashboard.
|
|
979
|
+
* @returns A resource bound to that dashboard.
|
|
980
|
+
* @example
|
|
981
|
+
* ```ts
|
|
982
|
+
* await mgmt.context.dashboards.elements('DASHBOARD_ID').list()
|
|
983
|
+
* ```
|
|
984
|
+
*/
|
|
985
|
+
elements(dashboardId) {
|
|
986
|
+
validateId(dashboardId, "dashboardId");
|
|
987
|
+
return new ManagementDashboardElementsResource(this.http, this.config, dashboardId);
|
|
988
|
+
}
|
|
989
|
+
/**
|
|
990
|
+
* Move or resize several tiles and filters in one change.
|
|
991
|
+
*
|
|
992
|
+
* @param dashboardId - Id of the dashboard.
|
|
993
|
+
* @param input.expectedRevision - The `draftRevision` your change is based on.
|
|
994
|
+
* @param input.elements - Every element to place, each with `elementId` and its
|
|
995
|
+
* final `layout`.
|
|
996
|
+
* @returns The whole dashboard after the change, including the new `draftRevision`.
|
|
997
|
+
* @throws ConflictError - The draft changed since `expectedRevision`.
|
|
998
|
+
* @example
|
|
999
|
+
* ```ts
|
|
1000
|
+
* await mgmt.context.dashboards.updateLayout('DASHBOARD_ID', {
|
|
1001
|
+
* expectedRevision: 3,
|
|
1002
|
+
* elements: [{ elementId: 'ELEMENT_ID', layout: { x: 0, y: 0, w: 12, h: 2 } }],
|
|
1003
|
+
* })
|
|
1004
|
+
* ```
|
|
1005
|
+
*/
|
|
1006
|
+
async updateLayout(dashboardId, input) {
|
|
1007
|
+
validateId(dashboardId, "dashboardId");
|
|
1008
|
+
return asRecord(
|
|
1009
|
+
await invokeWithRetry(this.config, this.http, "DashboardsController_updateLayout", {
|
|
1010
|
+
pathParams: { dashboardId },
|
|
1011
|
+
jsonBody: { expectedRevision: input.expectedRevision, elements: input.elements }
|
|
1012
|
+
})
|
|
1013
|
+
);
|
|
1014
|
+
}
|
|
1015
|
+
};
|
|
1016
|
+
|
|
475
1017
|
// src/management/context/files.ts
|
|
476
1018
|
import { readdir, readFile, stat } from "fs/promises";
|
|
477
|
-
import { join } from "path";
|
|
1019
|
+
import { dirname, join, relative } from "path";
|
|
478
1020
|
var MAX_BULK_UPLOAD_FILES = 100;
|
|
479
1021
|
var DEFAULT_LIST_PAGE_SIZE = 50;
|
|
480
1022
|
var DEFAULT_PUT_TIMEOUT_MS = 6e4;
|
|
@@ -507,14 +1049,16 @@ function chunked(items, size) {
|
|
|
507
1049
|
for (let i = 0; i < items.length; i += size) out.push(items.slice(i, i + size));
|
|
508
1050
|
return out;
|
|
509
1051
|
}
|
|
510
|
-
async function mapWithConcurrency(items, concurrency, worker) {
|
|
1052
|
+
async function mapWithConcurrency(items, concurrency, worker, onItemDone) {
|
|
511
1053
|
const results = new Array(items.length);
|
|
512
1054
|
let cursor = 0;
|
|
513
1055
|
async function run() {
|
|
514
1056
|
for (; ; ) {
|
|
515
1057
|
const index = cursor++;
|
|
516
1058
|
if (index >= items.length) return;
|
|
517
|
-
|
|
1059
|
+
const result = await worker(items[index]);
|
|
1060
|
+
results[index] = result;
|
|
1061
|
+
onItemDone?.(result);
|
|
518
1062
|
}
|
|
519
1063
|
}
|
|
520
1064
|
await Promise.all(Array.from({ length: Math.min(concurrency, items.length) }, run));
|
|
@@ -560,25 +1104,29 @@ function createSlotsPayload(files) {
|
|
|
560
1104
|
}
|
|
561
1105
|
function uploadFromUrlsPayload(urls) {
|
|
562
1106
|
return {
|
|
563
|
-
urls: urls.map((u) =>
|
|
1107
|
+
urls: urls.map((u) => ({
|
|
1108
|
+
url: u.url,
|
|
1109
|
+
...u.fileName !== void 0 ? { fileName: u.fileName } : {},
|
|
1110
|
+
...u.folderPath !== void 0 ? { folderPath: u.folderPath } : {}
|
|
1111
|
+
}))
|
|
564
1112
|
};
|
|
565
1113
|
}
|
|
566
1114
|
function assignSlots(batch, result, failed) {
|
|
567
1115
|
const failedIndices = new Set(result.failed.map((f) => f.index));
|
|
568
1116
|
for (const f of result.failed) {
|
|
569
|
-
failed.push({ path: batch[f.index], error: f.error });
|
|
1117
|
+
failed.push({ path: batch[f.index]?.path ?? "", error: f.error });
|
|
570
1118
|
}
|
|
571
1119
|
const remaining = batch.filter((_, i) => !failedIndices.has(i));
|
|
572
1120
|
const uploaded = result.uploaded;
|
|
573
1121
|
if (uploaded.length < remaining.length) {
|
|
574
|
-
for (const
|
|
575
|
-
failed.push({ path, error: "Server returned fewer upload slots than requested files." });
|
|
1122
|
+
for (const file of remaining.slice(uploaded.length)) {
|
|
1123
|
+
failed.push({ path: file.path, error: "Server returned fewer upload slots than requested files." });
|
|
576
1124
|
}
|
|
577
1125
|
}
|
|
578
1126
|
const paired = Math.min(remaining.length, uploaded.length);
|
|
579
1127
|
const assignments = [];
|
|
580
1128
|
for (let i = 0; i < paired; i++) {
|
|
581
|
-
assignments.push({
|
|
1129
|
+
assignments.push({ ...remaining[i], slot: uploaded[i] });
|
|
582
1130
|
}
|
|
583
1131
|
return assignments;
|
|
584
1132
|
}
|
|
@@ -596,7 +1144,10 @@ var ManagementContextFilesResource = class {
|
|
|
596
1144
|
* Office/OpenDocument documents, audio, and video.
|
|
597
1145
|
* @param input.fileSize - File size in bytes. Rejected above 50MB.
|
|
598
1146
|
* @returns Presigned upload slot. PUT the raw bytes to `uploadUrl` within 15
|
|
599
|
-
* minutes, then
|
|
1147
|
+
* minutes, then call `finalize(slot.uploadId, slot.fileName)`. Pass the
|
|
1148
|
+
* slot's own `fileName` rather than your local basename — the server may
|
|
1149
|
+
* sanitize the requested name when it mints the key, and finalization
|
|
1150
|
+
* re-derives the key from `uploadId` and `fileName`.
|
|
600
1151
|
*/
|
|
601
1152
|
async createUploadUrl(input) {
|
|
602
1153
|
return asRecord(
|
|
@@ -631,7 +1182,11 @@ var ManagementContextFilesResource = class {
|
|
|
631
1182
|
async uploadFromUrl(url, options = {}) {
|
|
632
1183
|
return asRecord(
|
|
633
1184
|
await invokeWithRetry(this.config, this.http, "ContextFilesController_uploadFromUrl", {
|
|
634
|
-
jsonBody:
|
|
1185
|
+
jsonBody: {
|
|
1186
|
+
url,
|
|
1187
|
+
...options.fileName !== void 0 ? { fileName: options.fileName } : {},
|
|
1188
|
+
...options.folderPath !== void 0 ? { folderPath: options.folderPath } : {}
|
|
1189
|
+
}
|
|
635
1190
|
})
|
|
636
1191
|
);
|
|
637
1192
|
}
|
|
@@ -685,6 +1240,64 @@ var ManagementContextFilesResource = class {
|
|
|
685
1240
|
);
|
|
686
1241
|
return buildAipPage(data, "files", (raw) => raw, (token) => this.listPage(pageSize, token));
|
|
687
1242
|
}
|
|
1243
|
+
/**
|
|
1244
|
+
* Turn a file already PUT to a presigned URL into durable context.
|
|
1245
|
+
*
|
|
1246
|
+
* Call this once the PUT completes. The server locates the object from
|
|
1247
|
+
* `uploadId` + `fileName` and validates the bytes that actually arrived.
|
|
1248
|
+
* Safe to retry — a second call returns the same resource.
|
|
1249
|
+
*
|
|
1250
|
+
* @param uploadId - Upload id returned by `createUploadUrl`.
|
|
1251
|
+
* @param fileName - File name returned alongside it.
|
|
1252
|
+
* @returns The file upload resource, status `"processing"`.
|
|
1253
|
+
*/
|
|
1254
|
+
async finalize(uploadId, fileName, options = {}) {
|
|
1255
|
+
validateId(uploadId, "uploadId");
|
|
1256
|
+
return asRecord(
|
|
1257
|
+
await invokeWithRetry(this.config, this.http, "ContextFilesController_finalize", {
|
|
1258
|
+
pathParams: { uploadId },
|
|
1259
|
+
jsonBody: { fileName, ...options.folderPath !== void 0 ? { folderPath: options.folderPath } : {} }
|
|
1260
|
+
})
|
|
1261
|
+
);
|
|
1262
|
+
}
|
|
1263
|
+
/**
|
|
1264
|
+
* Finalize up to 100 uploads in one call.
|
|
1265
|
+
*
|
|
1266
|
+
* What makes directory upload cheap: 2000 files cost 20 requests here rather
|
|
1267
|
+
* than 2000.
|
|
1268
|
+
*
|
|
1269
|
+
* @param uploads - Uploads to finalize (max 100).
|
|
1270
|
+
* @returns Resources for every upload that finalized, plus per-index
|
|
1271
|
+
* failures for the rest — never a partial 4xx.
|
|
1272
|
+
*/
|
|
1273
|
+
async finalizeMany(uploads) {
|
|
1274
|
+
validateBulkSize(uploads.length, "uploads");
|
|
1275
|
+
return asRecord(
|
|
1276
|
+
await invokeWithRetry(this.config, this.http, "ContextFilesController_finalizeMany", {
|
|
1277
|
+
jsonBody: {
|
|
1278
|
+
uploads: uploads.map((u) => ({
|
|
1279
|
+
uploadId: u.uploadId,
|
|
1280
|
+
fileName: u.fileName,
|
|
1281
|
+
...u.folderPath !== void 0 ? { folderPath: u.folderPath } : {}
|
|
1282
|
+
}))
|
|
1283
|
+
}
|
|
1284
|
+
})
|
|
1285
|
+
);
|
|
1286
|
+
}
|
|
1287
|
+
/**
|
|
1288
|
+
* Upload an explicit list of local files.
|
|
1289
|
+
*
|
|
1290
|
+
* Same machinery as `uploadDir`, without the directory walk — use it when
|
|
1291
|
+
* the caller already knows which files to send.
|
|
1292
|
+
*
|
|
1293
|
+
* @param paths - Paths to local files.
|
|
1294
|
+
* @param options.concurrency - Max concurrent PUTs (default 10).
|
|
1295
|
+
* @param options.waitUntil - `"processing"` (default) or `"ready"`.
|
|
1296
|
+
* @param options.onProgress - Optional progress callback after each file.
|
|
1297
|
+
*/
|
|
1298
|
+
async uploadFiles(paths, options = {}) {
|
|
1299
|
+
return this.uploadPaths(paths.map((input) => typeof input === "string" ? { path: input } : input), options);
|
|
1300
|
+
}
|
|
688
1301
|
/**
|
|
689
1302
|
* Upload a local file and wait for it to reach `"processing"` or `"ready"`.
|
|
690
1303
|
*
|
|
@@ -712,6 +1325,8 @@ var ManagementContextFilesResource = class {
|
|
|
712
1325
|
});
|
|
713
1326
|
const data = await readFile(path);
|
|
714
1327
|
await putBytes(this.config.fetch, slot.uploadUrl, data, slot.contentType, DEFAULT_PUT_TIMEOUT_MS);
|
|
1328
|
+
const finalized = await this.finalize(slot.uploadId, slot.fileName);
|
|
1329
|
+
if (statusSatisfies(finalized.status, waitUntil)) return finalized;
|
|
715
1330
|
return this.pollUntil(
|
|
716
1331
|
slot.uploadId,
|
|
717
1332
|
waitUntil,
|
|
@@ -744,6 +1359,7 @@ var ManagementContextFilesResource = class {
|
|
|
744
1359
|
* @param options.recursive - Recurse into subdirectories (default `true`).
|
|
745
1360
|
* @param options.concurrency - Max concurrent PUT+poll operations (default 10).
|
|
746
1361
|
* @param options.waitUntil - `"processing"` (default) or `"ready"` — same as `upload()`.
|
|
1362
|
+
* @param options.onProgress - Optional progress callback after each file.
|
|
747
1363
|
* @returns `UploadDirResult` with every successful `FileUpload` and every
|
|
748
1364
|
* per-file failure (slot creation or PUT/poll), each tagged with its local path.
|
|
749
1365
|
*/
|
|
@@ -754,49 +1370,135 @@ var ManagementContextFilesResource = class {
|
|
|
754
1370
|
if (concurrency < 1) throw new Error(`concurrency must be >= 1, got ${concurrency}`);
|
|
755
1371
|
const dirStat = await stat(path);
|
|
756
1372
|
if (!dirStat.isDirectory()) throw new Error(`Not a directory: ${path}`);
|
|
1373
|
+
const files = await walkFiles(path, options.recursive ?? true);
|
|
1374
|
+
return this.uploadPaths(files.map((file) => {
|
|
1375
|
+
const folderPath = relative(path, dirname(file)).replace(/\\/g, "/");
|
|
1376
|
+
return { path: file, ...folderPath.length > 0 ? { folderPath } : {} };
|
|
1377
|
+
}), options);
|
|
1378
|
+
}
|
|
1379
|
+
/** Shared body of `uploadFiles` and `uploadDir`: presign in batches of 100,
|
|
1380
|
+
* PUT with bounded concurrency, then bulk-finalize the batch. */
|
|
1381
|
+
async uploadPaths(files, options) {
|
|
1382
|
+
const waitUntil = options.waitUntil ?? "processing";
|
|
1383
|
+
validateWaitUntil(waitUntil);
|
|
1384
|
+
const concurrency = options.concurrency ?? DEFAULT_CONCURRENCY;
|
|
1385
|
+
if (concurrency < 1) throw new Error(`concurrency must be >= 1, got ${concurrency}`);
|
|
757
1386
|
const uploaded = [];
|
|
758
1387
|
const failed = [];
|
|
759
|
-
const
|
|
1388
|
+
const total = files.length;
|
|
1389
|
+
let completed = 0;
|
|
1390
|
+
const emit = () => {
|
|
1391
|
+
completed += 1;
|
|
1392
|
+
options.onProgress?.({
|
|
1393
|
+
completed,
|
|
1394
|
+
total,
|
|
1395
|
+
succeeded: uploaded.length,
|
|
1396
|
+
failed: failed.length
|
|
1397
|
+
});
|
|
1398
|
+
};
|
|
760
1399
|
for (const batch of chunked(files, MAX_BULK_UPLOAD_FILES)) {
|
|
1400
|
+
const failedBefore = failed.length;
|
|
761
1401
|
const slots = await this.createSlots(batch, failed);
|
|
762
|
-
|
|
763
|
-
|
|
1402
|
+
for (let reported = failedBefore + 1; reported <= failed.length; reported += 1) {
|
|
1403
|
+
completed += 1;
|
|
1404
|
+
options.onProgress?.({ completed, total, succeeded: uploaded.length, failed: reported });
|
|
1405
|
+
}
|
|
1406
|
+
await this.uploadBatch(slots, waitUntil, concurrency, (result) => {
|
|
764
1407
|
if ("error" in result) failed.push(result);
|
|
765
1408
|
else uploaded.push(result);
|
|
766
|
-
|
|
1409
|
+
emit();
|
|
1410
|
+
});
|
|
767
1411
|
}
|
|
768
1412
|
return { uploaded, failed };
|
|
769
1413
|
}
|
|
770
1414
|
async createSlots(batch, failed) {
|
|
771
1415
|
const readable = [];
|
|
772
1416
|
const inputs = [];
|
|
773
|
-
for (const
|
|
1417
|
+
for (const file of batch) {
|
|
774
1418
|
try {
|
|
775
|
-
const fileStat = await stat(path);
|
|
776
|
-
const fileName = path.split(/[/\\]/).pop();
|
|
1419
|
+
const fileStat = await stat(file.path);
|
|
1420
|
+
const fileName = file.path.split(/[/\\]/).pop();
|
|
777
1421
|
inputs.push({ fileName, contentType: DEFER_CONTENT_TYPE_TO_SERVER, fileSize: fileStat.size });
|
|
778
|
-
readable.push(
|
|
1422
|
+
readable.push(file);
|
|
779
1423
|
} catch (error) {
|
|
780
1424
|
const message = error instanceof Error ? error.message : String(error);
|
|
781
|
-
failed.push({ path, error: message });
|
|
1425
|
+
failed.push({ path: file.path, error: message });
|
|
782
1426
|
}
|
|
783
1427
|
}
|
|
784
1428
|
if (inputs.length === 0) return [];
|
|
785
1429
|
const result = await this.createUploadUrls(inputs);
|
|
786
1430
|
return assignSlots(readable, result, failed);
|
|
787
1431
|
}
|
|
788
|
-
async uploadBatch(slots, waitUntil, concurrency) {
|
|
1432
|
+
async uploadBatch(slots, waitUntil, concurrency, onOutcome) {
|
|
789
1433
|
if (slots.length === 0) return [];
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
1434
|
+
const out = [];
|
|
1435
|
+
const put = await mapWithConcurrency(
|
|
1436
|
+
slots,
|
|
1437
|
+
concurrency,
|
|
1438
|
+
async ({ path, folderPath, slot }) => {
|
|
1439
|
+
try {
|
|
1440
|
+
const data = await readFile(path);
|
|
1441
|
+
await putBytes(this.config.fetch, slot.uploadUrl, data, slot.contentType, DEFAULT_PUT_TIMEOUT_MS);
|
|
1442
|
+
return { landed: { path, ...folderPath !== void 0 ? { folderPath } : {}, slot } };
|
|
1443
|
+
} catch (error) {
|
|
1444
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1445
|
+
return { failure: { path, error: message } };
|
|
1446
|
+
}
|
|
1447
|
+
},
|
|
1448
|
+
(outcome) => {
|
|
1449
|
+
if ("failure" in outcome) {
|
|
1450
|
+
out.push(outcome.failure);
|
|
1451
|
+
onOutcome?.(outcome.failure);
|
|
1452
|
+
}
|
|
798
1453
|
}
|
|
799
|
-
|
|
1454
|
+
);
|
|
1455
|
+
const landed = [];
|
|
1456
|
+
for (const entry of put) {
|
|
1457
|
+
if ("failure" in entry) {
|
|
1458
|
+
continue;
|
|
1459
|
+
}
|
|
1460
|
+
landed.push(entry.landed);
|
|
1461
|
+
}
|
|
1462
|
+
if (landed.length === 0) return out;
|
|
1463
|
+
const result = await this.finalizeMany(
|
|
1464
|
+
landed.map(({ slot, folderPath }) => ({
|
|
1465
|
+
uploadId: slot.uploadId,
|
|
1466
|
+
fileName: slot.fileName,
|
|
1467
|
+
...folderPath !== void 0 ? { folderPath } : {}
|
|
1468
|
+
}))
|
|
1469
|
+
);
|
|
1470
|
+
const failedIndices = new Set(result.failed.map((f) => f.index));
|
|
1471
|
+
for (const f of result.failed) {
|
|
1472
|
+
const failure = { path: landed[f.index]?.path ?? "", error: f.error };
|
|
1473
|
+
out.push(failure);
|
|
1474
|
+
onOutcome?.(failure);
|
|
1475
|
+
}
|
|
1476
|
+
const finalized = result.finalized;
|
|
1477
|
+
const remaining = landed.filter((_, i) => !failedIndices.has(i));
|
|
1478
|
+
if (waitUntil !== "ready") {
|
|
1479
|
+
for (const item of finalized) {
|
|
1480
|
+
out.push(item);
|
|
1481
|
+
onOutcome?.(item);
|
|
1482
|
+
}
|
|
1483
|
+
return out;
|
|
1484
|
+
}
|
|
1485
|
+
await mapWithConcurrency(
|
|
1486
|
+
remaining,
|
|
1487
|
+
concurrency,
|
|
1488
|
+
async ({ path, slot }) => {
|
|
1489
|
+
try {
|
|
1490
|
+
return await this.pollUntil(slot.uploadId, waitUntil, DEFAULT_POLL_INTERVAL_MS, DEFAULT_UPLOAD_TIMEOUT_MS);
|
|
1491
|
+
} catch (error) {
|
|
1492
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1493
|
+
return { path, error: message };
|
|
1494
|
+
}
|
|
1495
|
+
},
|
|
1496
|
+
(item) => {
|
|
1497
|
+
out.push(item);
|
|
1498
|
+
onOutcome?.(item);
|
|
1499
|
+
}
|
|
1500
|
+
);
|
|
1501
|
+
return out;
|
|
800
1502
|
}
|
|
801
1503
|
};
|
|
802
1504
|
|
|
@@ -911,6 +1613,7 @@ var ManagementContextResource = class {
|
|
|
911
1613
|
this.items = new ManagementContextItemsResource(http, config);
|
|
912
1614
|
this.customItems = new CustomContextItemsResource(http, config);
|
|
913
1615
|
this.files = new ManagementContextFilesResource(http, config);
|
|
1616
|
+
this.dashboards = new ManagementDashboardsResource(http, config);
|
|
914
1617
|
}
|
|
915
1618
|
/**
|
|
916
1619
|
* Add a free-form text note to the knowledge base.
|
|
@@ -920,6 +1623,7 @@ var ManagementContextResource = class {
|
|
|
920
1623
|
* @returns The created context item.
|
|
921
1624
|
* @example
|
|
922
1625
|
* ```ts
|
|
1626
|
+
* const mgmt = new ModusManagement()
|
|
923
1627
|
* const note = await mgmt.context.createNote('Runbook', '# Steps\n1. Check logs')
|
|
924
1628
|
* ```
|
|
925
1629
|
*/
|
|
@@ -937,6 +1641,14 @@ var ManagementContextResource = class {
|
|
|
937
1641
|
* @param options.body - New markdown body.
|
|
938
1642
|
* @param options.existing - Optional cached item to avoid a GET.
|
|
939
1643
|
* @returns The updated context item.
|
|
1644
|
+
* @example
|
|
1645
|
+
* ```ts
|
|
1646
|
+
* const mgmt = new ModusManagement()
|
|
1647
|
+
* const item = await mgmt.context.updateNote('PLACEHOLDER_UID', {
|
|
1648
|
+
* title: 'Runbook',
|
|
1649
|
+
* body: '# Steps\n1. Check logs\n2. Escalate',
|
|
1650
|
+
* })
|
|
1651
|
+
* ```
|
|
940
1652
|
*/
|
|
941
1653
|
updateNote(uid, options) {
|
|
942
1654
|
return resolveAndUpdateNote(this.items, uid, options);
|
|
@@ -949,6 +1661,14 @@ var ManagementContextResource = class {
|
|
|
949
1661
|
* @param options.query - SQL text.
|
|
950
1662
|
* @param options.path - Optional hierarchy path segments.
|
|
951
1663
|
* @returns The created context item.
|
|
1664
|
+
* @example
|
|
1665
|
+
* ```ts
|
|
1666
|
+
* const mgmt = new ModusManagement()
|
|
1667
|
+
* const query = await mgmt.context.createSavedQuery('Monthly ARR', {
|
|
1668
|
+
* connectionId: 'conn_warehouse',
|
|
1669
|
+
* query: 'select * from arr_monthly',
|
|
1670
|
+
* })
|
|
1671
|
+
* ```
|
|
952
1672
|
*/
|
|
953
1673
|
createSavedQuery(name, options) {
|
|
954
1674
|
return this.create(
|
|
@@ -970,6 +1690,14 @@ var ManagementContextResource = class {
|
|
|
970
1690
|
* @param options.query - New SQL text.
|
|
971
1691
|
* @param options.existing - Optional cached item to avoid a GET.
|
|
972
1692
|
* @returns The updated context item.
|
|
1693
|
+
* @example
|
|
1694
|
+
* ```ts
|
|
1695
|
+
* const mgmt = new ModusManagement()
|
|
1696
|
+
* const item = await mgmt.context.updateSavedQuery('PLACEHOLDER_UID', {
|
|
1697
|
+
* name: 'Monthly ARR',
|
|
1698
|
+
* query: 'select sum(amount) from arr_monthly',
|
|
1699
|
+
* })
|
|
1700
|
+
* ```
|
|
973
1701
|
*/
|
|
974
1702
|
updateSavedQuery(uid, options) {
|
|
975
1703
|
return resolveAndUpdateSavedQuery(this.items, uid, options);
|
|
@@ -982,6 +1710,13 @@ var ManagementContextResource = class {
|
|
|
982
1710
|
* @param options.isCrawl - When true, crawl linked pages into context.
|
|
983
1711
|
* @param options.pageLimit - Maximum pages to crawl when `isCrawl` is true.
|
|
984
1712
|
* @returns The created context item.
|
|
1713
|
+
* @example
|
|
1714
|
+
* ```ts
|
|
1715
|
+
* const mgmt = new ModusManagement()
|
|
1716
|
+
* const link = await mgmt.context.createLink('https://docs.example.com/runbook', {
|
|
1717
|
+
* title: 'Ops runbook',
|
|
1718
|
+
* })
|
|
1719
|
+
* ```
|
|
985
1720
|
*/
|
|
986
1721
|
createLink(url, options = {}) {
|
|
987
1722
|
return this.create(
|
|
@@ -1004,6 +1739,13 @@ var ManagementContextResource = class {
|
|
|
1004
1739
|
* @param options.url - New URL.
|
|
1005
1740
|
* @param options.existing - Optional cached item to avoid a GET.
|
|
1006
1741
|
* @returns The updated context item.
|
|
1742
|
+
* @example
|
|
1743
|
+
* ```ts
|
|
1744
|
+
* const mgmt = new ModusManagement()
|
|
1745
|
+
* const item = await mgmt.context.updateLink('PLACEHOLDER_UID', {
|
|
1746
|
+
* title: 'Ops runbook (2025)',
|
|
1747
|
+
* })
|
|
1748
|
+
* ```
|
|
1007
1749
|
*/
|
|
1008
1750
|
updateLink(uid, options) {
|
|
1009
1751
|
return resolveAndUpdateLink(this.items, uid, options);
|
|
@@ -1307,7 +2049,14 @@ var ManagementScopesResource = class {
|
|
|
1307
2049
|
* @param options.search - Case-insensitive substring filter on the scope name.
|
|
1308
2050
|
* @param options.view - Variation view: `"active"` (deployed) or `"draft"`.
|
|
1309
2051
|
* @param options.managerId - Return only scopes supervised by this manager scope id.
|
|
1310
|
-
* @returns A page of scopes.
|
|
2052
|
+
* @returns A page of scopes — use `.autoPagingIter()` for all pages.
|
|
2053
|
+
* @example
|
|
2054
|
+
* ```ts
|
|
2055
|
+
* const mgmt = new ModusManagement()
|
|
2056
|
+
* for await (const scope of (await mgmt.scopes.list()).autoPagingIter()) {
|
|
2057
|
+
* console.log(scope.id, scope.name, scope.status)
|
|
2058
|
+
* }
|
|
2059
|
+
* ```
|
|
1311
2060
|
*/
|
|
1312
2061
|
list(options = {}) {
|
|
1313
2062
|
const pageSize = options.pageSize ?? 25;
|
|
@@ -1339,6 +2088,12 @@ var ManagementScopesResource = class {
|
|
|
1339
2088
|
* @param scopeId - Scope id.
|
|
1340
2089
|
* @param options.view - Variation view: `"active"` (deployed) or `"draft"`.
|
|
1341
2090
|
* @returns The scope.
|
|
2091
|
+
* @example
|
|
2092
|
+
* ```ts
|
|
2093
|
+
* const mgmt = new ModusManagement()
|
|
2094
|
+
* const scope = await mgmt.scopes.get('PLACEHOLDER_SCOPE_ID')
|
|
2095
|
+
* console.log(scope.name, scope.status)
|
|
2096
|
+
* ```
|
|
1342
2097
|
*/
|
|
1343
2098
|
async get(scopeId, options = {}) {
|
|
1344
2099
|
validateId(scopeId, "scope_id");
|
|
@@ -1361,7 +2116,9 @@ var ManagementScopesResource = class {
|
|
|
1361
2116
|
* @returns The created scope (draft).
|
|
1362
2117
|
* @example
|
|
1363
2118
|
* ```ts
|
|
2119
|
+
* const mgmt = new ModusManagement()
|
|
1364
2120
|
* const scope = await mgmt.scopes.create({ name: 'Support assistant', model: 'claude-sonnet-5' })
|
|
2121
|
+
* console.log(scope.id, scope.name)
|
|
1365
2122
|
* ```
|
|
1366
2123
|
*/
|
|
1367
2124
|
async create(options) {
|
|
@@ -1392,6 +2149,13 @@ var ManagementScopesResource = class {
|
|
|
1392
2149
|
* @param options.guardrails - Guardrail labels to set. Fetches the current scope first to merge. Pass `[]` to clear all.
|
|
1393
2150
|
* @param options.updateMask - Comma-separated field names to update or clear.
|
|
1394
2151
|
* @returns The updated scope.
|
|
2152
|
+
* @example
|
|
2153
|
+
* ```ts
|
|
2154
|
+
* const mgmt = new ModusManagement()
|
|
2155
|
+
* const scope = await mgmt.scopes.update('PLACEHOLDER_SCOPE_ID', {
|
|
2156
|
+
* description: 'Answers billing questions for enterprise customers.',
|
|
2157
|
+
* })
|
|
2158
|
+
* ```
|
|
1395
2159
|
*/
|
|
1396
2160
|
async update(scopeId, options = {}) {
|
|
1397
2161
|
validateId(scopeId, "scope_id");
|
|
@@ -1433,8 +2197,10 @@ var ManagementScopesResource = class {
|
|
|
1433
2197
|
* @returns The published scope.
|
|
1434
2198
|
* @example
|
|
1435
2199
|
* ```ts
|
|
1436
|
-
*
|
|
1437
|
-
* const
|
|
2200
|
+
* const mgmt = new ModusManagement()
|
|
2201
|
+
* const scope = await mgmt.scopes.create({ name: 'Support assistant' })
|
|
2202
|
+
* const published = await mgmt.scopes.deploy(scope.id)
|
|
2203
|
+
* console.log(published.status)
|
|
1438
2204
|
* ```
|
|
1439
2205
|
*/
|
|
1440
2206
|
async deploy(scopeId) {
|
|
@@ -1452,6 +2218,11 @@ var ManagementScopesResource = class {
|
|
|
1452
2218
|
*
|
|
1453
2219
|
* @param scopeId - Scope id.
|
|
1454
2220
|
* @returns Resolves when the scope is deleted.
|
|
2221
|
+
* @example
|
|
2222
|
+
* ```ts
|
|
2223
|
+
* const mgmt = new ModusManagement()
|
|
2224
|
+
* await mgmt.scopes.delete('PLACEHOLDER_SCOPE_ID')
|
|
2225
|
+
* ```
|
|
1455
2226
|
*/
|
|
1456
2227
|
async delete(scopeId) {
|
|
1457
2228
|
validateId(scopeId, "scope_id");
|