@ziffr/sdk 0.14.0 → 0.16.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/README.md +3 -3
- package/dist/index.d.ts +136 -19
- package/dist/index.js +15 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -7,11 +7,11 @@ Call the [Ziffr](https://github.com/ziffr/ziffr) API from TypeScript or JavaScri
|
|
|
7
7
|
1. In Ziffr, open the Team page and create an Access Key. Give it "Read metrics", and "Submit values" if your program records values. Copy the key: it is shown once.
|
|
8
8
|
2. Install and call:
|
|
9
9
|
|
|
10
|
-
```sh
|
|
10
|
+
```sh skip="installs a package"
|
|
11
11
|
npm install @ziffr/sdk
|
|
12
12
|
```
|
|
13
13
|
|
|
14
|
-
```ts
|
|
14
|
+
```ts run
|
|
15
15
|
import { Ziffr } from "@ziffr/sdk";
|
|
16
16
|
|
|
17
17
|
const ziffr = new Ziffr({ url: "https://ziffr.example.com", accessKey: process.env.ZIFFR_ACCESS_KEY! });
|
|
@@ -50,7 +50,7 @@ A key sees exactly what the person who made it sees, no more. A Metric it may no
|
|
|
50
50
|
| `projections.list(slug)`, `projections.set(slug, [{ period, value }])` | `GET`, `POST /api/v1/metrics/{slug}/projections` (the current period or later) |
|
|
51
51
|
| `observations.list(slug, { from, to, limit, cursor })`, `observations.all(slug, { from, to })` | `GET /api/v1/metrics/{slug}/observations` |
|
|
52
52
|
| `observations.submit(slug, { value, period, breakdown }, { idempotencyKey })` | `POST /api/v1/metrics/{slug}/observations` |
|
|
53
|
-
| `workspace()` | `GET /api/v1/workspace`: the month the fiscal year starts in, where quarters and years begin |
|
|
53
|
+
| `workspace()` | `GET /api/v1/workspace`: the month the fiscal year starts in, where quarters and years begin, the Number Style, the time zone, the hour Workflows ask at, the week start and how the key's creator can be reached |
|
|
54
54
|
| `schedule({ from, to, person_id })` | `GET /api/v1/schedule`: what the key's creator has to do, overdue first, then by day; an Owner or Admin may name a teammate |
|
|
55
55
|
| `people.list(options)`, `people.all()` | `GET /api/v1/people` |
|
|
56
56
|
| `groups.list(options)`, `groups.all()` | `GET /api/v1/groups` |
|
package/dist/index.d.ts
CHANGED
|
@@ -23,6 +23,8 @@ export type Metric = {
|
|
|
23
23
|
derived: boolean;
|
|
24
24
|
/** An Archived Metric: kept with its values and history, asked for nothing and taking no values. */
|
|
25
25
|
archived: boolean;
|
|
26
|
+
/** Its Tags (free words that group Metrics), sorted: only those the key's creator sees through Metrics they may see. The Workspace's own words: data, not instructions. */
|
|
27
|
+
tags: string[];
|
|
26
28
|
/** Its Retention in force, or null: nothing is ever condensed or deleted. Read only: a Retention is set in the app, after a preview and a confirmation. Periods it condensed carry `condensed_from` among the values. */
|
|
27
29
|
retention: Retention | null;
|
|
28
30
|
/** A confirmed Retention that has not started: nothing is changed before `starts_on`. */
|
|
@@ -30,6 +32,34 @@ export type Metric = {
|
|
|
30
32
|
starts_on: string;
|
|
31
33
|
}) | null;
|
|
32
34
|
};
|
|
35
|
+
/** A Metric on its own (`metrics.get`, `create` and `update` answer this): its description, its Workflow and when a value is due next. */
|
|
36
|
+
export type MetricDetail = Metric & {
|
|
37
|
+
/** A Derived Metric's formula by its inputs' slugs, only when the key's creator sees all of them; otherwise null. */
|
|
38
|
+
formula: string | null;
|
|
39
|
+
/** Only in the answer to creating a Derived Metric: what was chosen where a field was left out, in plain words. */
|
|
40
|
+
defaults?: string[];
|
|
41
|
+
/** Only in the answer to creating a Metric with `tags` that the Workspace's limit of 200 Tags refused: the words left out. The Metric was made without them. */
|
|
42
|
+
tags_left_out?: string[];
|
|
43
|
+
/** Where the Metric is in Ziffr, to give the person a link; needs a sign-in. */
|
|
44
|
+
url: string;
|
|
45
|
+
/** When its Workflow asks next (day, whole hour, time zone); null without a Workflow, and for a Derived or Archived Metric. */
|
|
46
|
+
next_asked: {
|
|
47
|
+
day: string;
|
|
48
|
+
hour: number;
|
|
49
|
+
time_zone: string;
|
|
50
|
+
} | null;
|
|
51
|
+
/** The Workflow that asks for its values, or null; `yours` says whether the key's creator owns it. */
|
|
52
|
+
workflow: {
|
|
53
|
+
id: number;
|
|
54
|
+
name: string;
|
|
55
|
+
yours: boolean;
|
|
56
|
+
} | null;
|
|
57
|
+
/** The next Due Date (YYYY-MM-DD) and the first day of the period it is for; null without a Workflow, and for a Derived or Archived Metric. */
|
|
58
|
+
next_due: {
|
|
59
|
+
date: string;
|
|
60
|
+
period: string;
|
|
61
|
+
} | null;
|
|
62
|
+
};
|
|
33
63
|
/** A Retention (GLOSSARY: Retention): keep values for `keep_months` months (at least 13), then condense older ones into a longer period or delete them. */
|
|
34
64
|
export type Retention = {
|
|
35
65
|
keep_months: number;
|
|
@@ -50,7 +80,8 @@ export type Submitter = {
|
|
|
50
80
|
/** One labelled part of a value (GLOSSARY: Breakdown). */
|
|
51
81
|
export type BreakdownRow = {
|
|
52
82
|
label: string;
|
|
53
|
-
value: number;
|
|
83
|
+
value: number; /** The label of the row this one is a part of, in the same breakdown; left out for a row at the top. */
|
|
84
|
+
parent?: string | null;
|
|
54
85
|
};
|
|
55
86
|
/** A Metric's value for one period. */
|
|
56
87
|
export type Observation = {
|
|
@@ -66,6 +97,10 @@ export type Observation = {
|
|
|
66
97
|
submitted_at: string | null;
|
|
67
98
|
/** The Source it arrived through (web_form, mail, slack, telegram, api), or null for a Derived Metric. */
|
|
68
99
|
source: string | null;
|
|
100
|
+
/** Read only: who entered the value for its submitter (a Filled-in Value), or null; always null for a Guest's key. */
|
|
101
|
+
entered_by?: string | null;
|
|
102
|
+
/** Their name, or null. */
|
|
103
|
+
entered_by_name?: string | null;
|
|
69
104
|
/** A Thread on this period that the key's creator may read exists (see `thread`). */
|
|
70
105
|
has_thread: boolean;
|
|
71
106
|
breakdown: BreakdownRow[] | null;
|
|
@@ -139,16 +174,43 @@ export type NewMetric = {
|
|
|
139
174
|
sources?: Source[];
|
|
140
175
|
/** Who submits: ids from `people` and `feeds`, at most 20; each gets a first Prompt. Needs scope metrics:edit too. */
|
|
141
176
|
submitters?: string[];
|
|
177
|
+
/** One of your own Workflows, by id or exact name, so the Metric is asked for on its schedule at once. Needs scope metrics:edit too. */
|
|
178
|
+
workflow?: number | string | null;
|
|
179
|
+
/** Its Tags: free words, at most 10 (each at most 32 characters, no comma or markup). A word that exists is the same Tag Workspace-wide. */
|
|
180
|
+
tags?: string[];
|
|
181
|
+
/** Makes a Derived Metric: computed from Metrics you own or edit, by slug: "{revenue} / {orders}", "change({odometer}) / 7"
|
|
182
|
+
* (this period minus the previous one) or "prev({x})". It takes no values: submit, submitters, sources, aggregation,
|
|
183
|
+
* submission_rule and workflow are refused with it. Needs scope metrics:read too. */
|
|
184
|
+
formula?: string;
|
|
142
185
|
};
|
|
143
|
-
/** What `metrics.update` may change of a Metric (scope metrics:edit): its
|
|
144
|
-
* Each part left out stays; null clears an end of the Target Range
|
|
186
|
+
/** What `metrics.update` may change of a Metric (scope metrics:edit): its description, Sources, Target Range and
|
|
187
|
+
* Workflow. Each part left out stays; null clears an end of the Target Range, the Metric's own Attainment method or its Workflow. */
|
|
145
188
|
export type MetricPatch = {
|
|
189
|
+
name?: string;
|
|
190
|
+
description?: string;
|
|
191
|
+
unit?: string;
|
|
192
|
+
format?: Metric["format"];
|
|
193
|
+
/** Only while the Metric has no values and no targets or projections by period. */
|
|
194
|
+
period?: Metric["period"];
|
|
195
|
+
submission_rule?: "reject" | "overwrite" | "add" | "keep_both";
|
|
196
|
+
/** One of your own Workflows, by id or exact name, or null for none; only the Metric's owner. */
|
|
197
|
+
workflow?: number | string | null;
|
|
146
198
|
/** Its Sources, all of them: the ones left out are turned off. */
|
|
147
199
|
sources?: Source[];
|
|
148
200
|
polarity?: "higher" | "lower" | "target";
|
|
149
201
|
target_min?: number | null;
|
|
150
202
|
target_max?: number | null;
|
|
151
203
|
attainment_method?: "ratio" | "distance" | null;
|
|
204
|
+
/** A Derived Metric's new formula (scope metrics:read too); only its owner and Editors. */
|
|
205
|
+
formula?: string;
|
|
206
|
+
/** All its Tags (at most 10): it carries exactly these afterwards; [] takes them all off. Only its owner and Editors. */
|
|
207
|
+
tags?: string[];
|
|
208
|
+
};
|
|
209
|
+
/** A Tag the key's creator sees, and on how many Metrics they see it: in use and archived. */
|
|
210
|
+
export type Tag = {
|
|
211
|
+
name: string;
|
|
212
|
+
metrics: number;
|
|
213
|
+
archived: number;
|
|
152
214
|
};
|
|
153
215
|
/** A Metric's Unusual Value check: the check step of its Workflow, which several Metrics may share. */
|
|
154
216
|
export type UnusualValueCheck = {
|
|
@@ -187,6 +249,10 @@ export type Submission = {
|
|
|
187
249
|
value: number;
|
|
188
250
|
detail: string;
|
|
189
251
|
replayed: boolean;
|
|
252
|
+
unusual?: {
|
|
253
|
+
reasons: string[];
|
|
254
|
+
expected: string;
|
|
255
|
+
};
|
|
190
256
|
};
|
|
191
257
|
/** A Metric as its Feed sees it (spec 0012): what to fetch and which periods already have a value, never a value. */
|
|
192
258
|
export type FeedMetric = {
|
|
@@ -209,17 +275,26 @@ export type FeedOverview = {
|
|
|
209
275
|
year_start_month: number;
|
|
210
276
|
metrics: Page<FeedMetric>;
|
|
211
277
|
};
|
|
212
|
-
/** What GET /workspace answers: the month the workspace's fiscal year starts in, 1 (January) to 12. */
|
|
278
|
+
/** What GET /workspace answers: the month the workspace's fiscal year starts in, 1 (January) to 12, and how it writes numbers. */
|
|
213
279
|
export type Workspace = {
|
|
214
280
|
year_start_month: number;
|
|
281
|
+
number_style: "1,234.5" | "1.234,5" | "1 234,5" | "1'234.5";
|
|
282
|
+
/** The workspace's time zone (IANA name), which days, hours and Due Dates are in. */
|
|
283
|
+
time_zone: string;
|
|
284
|
+
/** The whole hour Workflows ask at unless they have an Asking Schedule of their own. */
|
|
285
|
+
run_hour: number;
|
|
286
|
+
week_start: "monday" | "sunday";
|
|
287
|
+
/** The ways Ziffr can reach the key's creator to ask for a value now. */
|
|
288
|
+
reached_by: ("email" | "slack" | "telegram")[];
|
|
215
289
|
};
|
|
216
|
-
/** One thing `find` found: a Metric, or its value for one period (`period` is the period's first day, null for the Metric alone). */
|
|
290
|
+
/** One thing `find` found: a Metric, or its value for one period (`period` is the period's first day, null for the Metric alone; `matched_by` is "tag" when a Tag of the Metric fit the words, not its name). */
|
|
217
291
|
export type Found = {
|
|
218
292
|
slug: string;
|
|
219
293
|
name: string;
|
|
220
294
|
archived: boolean;
|
|
221
295
|
period: string | null;
|
|
222
296
|
period_label: string | null;
|
|
297
|
+
matched_by?: "tag";
|
|
223
298
|
};
|
|
224
299
|
/** One duty in a Schedule: a value to submit, an Approval waiting, or a Task or Question assigned to the person. */
|
|
225
300
|
export type ScheduleEntry = {
|
|
@@ -229,10 +304,16 @@ export type ScheduleEntry = {
|
|
|
229
304
|
overdue: boolean;
|
|
230
305
|
/** Working days (Saturdays and Sundays skipped) it is late; 0 when it is not. */
|
|
231
306
|
overdue_working_days: number;
|
|
307
|
+
/** The Metric it is about; null for a checklist Task, which is about its Workflow (`workflow`) and period. */
|
|
232
308
|
metric: {
|
|
233
309
|
slug: string;
|
|
234
310
|
name: string;
|
|
235
|
-
};
|
|
311
|
+
} | null;
|
|
312
|
+
/** The Workflow a checklist Task is about; null for every other entry. */
|
|
313
|
+
workflow: {
|
|
314
|
+
id: number;
|
|
315
|
+
name: string;
|
|
316
|
+
} | null;
|
|
236
317
|
period: {
|
|
237
318
|
start: string;
|
|
238
319
|
name: string;
|
|
@@ -301,6 +382,20 @@ export type WorkflowStep = {
|
|
|
301
382
|
};
|
|
302
383
|
people: string[];
|
|
303
384
|
groups: number[];
|
|
385
|
+
}
|
|
386
|
+
/** A Checklist Item: `kind` "info" goes to `people` and `groups` on its `day` (working days after the period ends); "tick" is a Task for `assignee`. Names people, so without workflows:people send it back as read. */
|
|
387
|
+
| {
|
|
388
|
+
type: "checklist";
|
|
389
|
+
id?: string;
|
|
390
|
+
kind: "info" | "tick";
|
|
391
|
+
text: string;
|
|
392
|
+
day?: number;
|
|
393
|
+
people?: string[];
|
|
394
|
+
groups?: number[];
|
|
395
|
+
assignee?: string | null;
|
|
396
|
+
stand_in?: string | null;
|
|
397
|
+
due_working_days?: number;
|
|
398
|
+
read_group?: number | null;
|
|
304
399
|
};
|
|
305
400
|
/** When a Workflow runs on its own (the Asking Schedule): a whole hour in the Workspace's time zone (null: the Workspace's run hour) and the days. */
|
|
306
401
|
export type AskingSchedule = {
|
|
@@ -329,7 +424,11 @@ export type WorkflowDetail = {
|
|
|
329
424
|
lock_summary: boolean;
|
|
330
425
|
steps: WorkflowStep[];
|
|
331
426
|
asking: AskingSchedule | null;
|
|
332
|
-
metrics: number;
|
|
427
|
+
metrics: number; /** The Metrics that use it which the key's creator sees (at most 50). */
|
|
428
|
+
used_by: {
|
|
429
|
+
slug: string;
|
|
430
|
+
name: string;
|
|
431
|
+
}[];
|
|
333
432
|
updated_at: string;
|
|
334
433
|
};
|
|
335
434
|
/** What to say to make a Workflow. */
|
|
@@ -349,7 +448,7 @@ export type TimelineEvent = {
|
|
|
349
448
|
/** The same moment's day in the workspace's time zone, and its time (HH:mm). */
|
|
350
449
|
day: string;
|
|
351
450
|
time: string;
|
|
352
|
-
kind: "asked" | "reminded" | "in" | "action" | "approval_asked" | "approved" | "sent_back" | "checked" | "note" | "published" | "locked" | "snapshot";
|
|
451
|
+
kind: "asked" | "reminded" | "in" | "action" | "approval_asked" | "approved" | "sent_back" | "checked" | "note" | "published" | "locked" | "snapshot" | "checklist_sent" | "checklist_given" | "checklist_done" | "snapshot_sent" | "finished";
|
|
353
452
|
/** One sentence; names in it come from the workspace. */
|
|
354
453
|
text: string;
|
|
355
454
|
count: number;
|
|
@@ -372,6 +471,13 @@ export type PeriodStatus = {
|
|
|
372
471
|
of: number;
|
|
373
472
|
published: number;
|
|
374
473
|
locked: number;
|
|
474
|
+
/** The Workflow's checklist Tasks of the period: how many were given (`of`) and how many are done. `in` and `of` count values only. */
|
|
475
|
+
checklist: {
|
|
476
|
+
done: number;
|
|
477
|
+
of: number;
|
|
478
|
+
};
|
|
479
|
+
/** Whether the period is finished: every value locked and every checklist Task of it done. */
|
|
480
|
+
finished: boolean;
|
|
375
481
|
events: TimelineEvent[];
|
|
376
482
|
};
|
|
377
483
|
/** One value in a Feed's batch; `period` is the period's first day, the current period if left out. */
|
|
@@ -399,12 +505,17 @@ export type Action = {
|
|
|
399
505
|
kind: "question" | "task";
|
|
400
506
|
status: "open" | "answered" | "closed";
|
|
401
507
|
/** What a Workflow made it for (an Approval waiting, a Self-check, an Escalation); null for a plain one. */
|
|
402
|
-
purpose: "approval" | "self_check" | "escalation" | null;
|
|
403
|
-
/** The Metric it is about; null when the key's creator does not see it. */
|
|
508
|
+
purpose: "approval" | "self_check" | "escalation" | "checklist" | null;
|
|
509
|
+
/** The Metric it is about; null when the key's creator does not see it, and for a checklist Task, which has none. */
|
|
404
510
|
metric: {
|
|
405
511
|
slug: string;
|
|
406
512
|
name: string;
|
|
407
513
|
} | null;
|
|
514
|
+
/** The Workflow a checklist Task is about (its period is `period`); null for every other Action. */
|
|
515
|
+
workflow: {
|
|
516
|
+
id: number;
|
|
517
|
+
name: string;
|
|
518
|
+
} | null;
|
|
408
519
|
period: string;
|
|
409
520
|
asked_by: string;
|
|
410
521
|
asked_by_name: string | null;
|
|
@@ -650,7 +761,7 @@ export type MadeViewLink = ViewLink & {
|
|
|
650
761
|
url: string;
|
|
651
762
|
};
|
|
652
763
|
/** The built-in views a key may place. */
|
|
653
|
-
export type View = "number" | "line" | "bars" | "gauge" | "table" | "forecast" | "correlation" | "matrix" | "drivers" | "ranked" | "share" | "pictogram" | "story-line";
|
|
764
|
+
export type View = "number" | "line" | "bars" | "gauge" | "table" | "forecast" | "correlation" | "matrix" | "drivers" | "scoreboard" | "progress" | "stacked" | "pareto" | "slope" | "running-total" | "bump" | "heatmap" | "ranked" | "share" | "pictogram" | "story-line";
|
|
654
765
|
/** The few widget settings a key may set. */
|
|
655
766
|
export type WidgetSettings = {
|
|
656
767
|
window?: number;
|
|
@@ -691,8 +802,10 @@ export type PageOptions = {
|
|
|
691
802
|
cursor?: string;
|
|
692
803
|
};
|
|
693
804
|
/** Options of the Metrics list: with `archived`, only the Archived Metrics instead of those in use. */
|
|
805
|
+
/** `tag` keeps only Metrics that carry every one of these Tags (at most 10). */
|
|
694
806
|
export type MetricListOptions = PageOptions & {
|
|
695
807
|
archived?: boolean;
|
|
808
|
+
tag?: string[];
|
|
696
809
|
};
|
|
697
810
|
/** Options of a Metric's values: the periods from `from` to `to` (first days, YYYY-MM-DD, both included). */
|
|
698
811
|
export type ObservationOptions = PageOptions & {
|
|
@@ -734,17 +847,18 @@ export declare class Ziffr {
|
|
|
734
847
|
readonly metrics: {
|
|
735
848
|
/** One page of Metrics: those in use, or with `archived` only the Archived Metrics. */
|
|
736
849
|
list: ({ archived, ...options }?: MetricListOptions) => Promise<Page<Metric>>;
|
|
737
|
-
/** Every Metric in use, or with `archived` every Archived Metric, page by page. */
|
|
850
|
+
/** Every Metric in use, or with `archived` every Archived Metric, page by page; with `tag`, only those carrying all of them. */
|
|
738
851
|
all: (options?: {
|
|
739
852
|
archived?: boolean;
|
|
853
|
+
tag?: string[];
|
|
740
854
|
}) => AsyncGenerator<Metric, any, any>;
|
|
741
855
|
/** One Metric's description. */
|
|
742
|
-
get: (slug: string) => Promise<
|
|
856
|
+
get: (slug: string) => Promise<MetricDetail>;
|
|
743
857
|
/** Creates a Metric owned by the key's creator (scope metrics:write). A fresh idempotency key is sent unless one is
|
|
744
858
|
* given; pass your own to make retries across runs of your program safe too. */
|
|
745
859
|
create: (metric: NewMetric, options?: {
|
|
746
860
|
idempotencyKey?: string;
|
|
747
|
-
}) => Promise<
|
|
861
|
+
}) => Promise<MetricDetail & {
|
|
748
862
|
replayed: boolean;
|
|
749
863
|
}>;
|
|
750
864
|
/** Deletes a Metric the key's creator owns (scope metrics:write), repeating its exact name to confirm. Refused
|
|
@@ -758,9 +872,9 @@ export declare class Ziffr {
|
|
|
758
872
|
archive: (slug: string) => Promise<Metric>;
|
|
759
873
|
/** Brings an Archived Metric back (scope metrics:write), under the same rule. Answers the Metric as it is now. */
|
|
760
874
|
restore: (slug: string) => Promise<Metric>;
|
|
761
|
-
/** Changes a Metric's
|
|
762
|
-
*
|
|
763
|
-
update: (slug: string, patch: MetricPatch) => Promise<
|
|
875
|
+
/** Changes a Metric's description, Sources, Target Range or Workflow (scope metrics:edit), when the key's creator
|
|
876
|
+
* owns it or is its Editor (its Workflow: its owner). Answers the Metric as it is now. */
|
|
877
|
+
update: (slug: string, patch: MetricPatch) => Promise<MetricDetail>;
|
|
764
878
|
/** Who submits to a Metric (scope metrics:read). */
|
|
765
879
|
submitters: (slug: string) => Promise<Submitter[]>;
|
|
766
880
|
/** Adds and removes up to 20 Submitters each (scope metrics:edit), when the key's creator owns the Metric or is its
|
|
@@ -941,6 +1055,9 @@ export declare class Ziffr {
|
|
|
941
1055
|
id: string;
|
|
942
1056
|
name: string;
|
|
943
1057
|
}[]>;
|
|
1058
|
+
/** The Tags the key's creator sees, by name, each with how many Metrics they see it on (scope metrics:read). Renaming,
|
|
1059
|
+
* merging and deleting Tags is done in Ziffr by an Owner or Admin, not through the API. */
|
|
1060
|
+
tags: () => Promise<Tag[]>;
|
|
944
1061
|
/** The workspace's Groups. */
|
|
945
1062
|
readonly groups: {
|
|
946
1063
|
/** One page of Groups. */
|
|
@@ -997,8 +1114,8 @@ export declare class Ziffr {
|
|
|
997
1114
|
close: (id: number) => Promise<Action>;
|
|
998
1115
|
/** Reopens one the creator asked. */
|
|
999
1116
|
reopen: (id: number) => Promise<Action>;
|
|
1000
|
-
/** Marks the creator's own open Task done. */
|
|
1001
|
-
done: (id: number) => Promise<Action>;
|
|
1117
|
+
/** Marks the creator's own open Task done, with an optional note (at most 2,000 characters) kept as the Thread's last reply. */
|
|
1118
|
+
done: (id: number, note?: string) => Promise<Action>;
|
|
1002
1119
|
/** Confirms the creator's own value in a Self-check. */
|
|
1003
1120
|
confirm: (id: number) => Promise<Action>;
|
|
1004
1121
|
/** Corrects the creator's own value in a Self-check. */
|
package/dist/index.js
CHANGED
|
@@ -46,8 +46,8 @@ export class Ziffr {
|
|
|
46
46
|
metrics = {
|
|
47
47
|
/** One page of Metrics: those in use, or with `archived` only the Archived Metrics. */
|
|
48
48
|
list: ({ archived, ...options } = {}) => this.get("/metrics", { ...options, archived: archived ? "true" : undefined }),
|
|
49
|
-
/** Every Metric in use, or with `archived` every Archived Metric, page by page. */
|
|
50
|
-
all: (options = {}) => this.every((cursor) => this.metrics.list({ cursor, limit: 100, archived: options.archived })),
|
|
49
|
+
/** Every Metric in use, or with `archived` every Archived Metric, page by page; with `tag`, only those carrying all of them. */
|
|
50
|
+
all: (options = {}) => this.every((cursor) => this.metrics.list({ cursor, limit: 100, archived: options.archived, tag: options.tag })),
|
|
51
51
|
/** One Metric's description. */
|
|
52
52
|
get: (slug) => this.get(`/metrics/${encodeURIComponent(slug)}`),
|
|
53
53
|
/** Creates a Metric owned by the key's creator (scope metrics:write). A fresh idempotency key is sent unless one is
|
|
@@ -64,8 +64,8 @@ export class Ziffr {
|
|
|
64
64
|
archive: async (slug) => (await this.request("POST", `/metrics/${encodeURIComponent(slug)}/archive`)).body,
|
|
65
65
|
/** Brings an Archived Metric back (scope metrics:write), under the same rule. Answers the Metric as it is now. */
|
|
66
66
|
restore: async (slug) => (await this.request("POST", `/metrics/${encodeURIComponent(slug)}/restore`)).body,
|
|
67
|
-
/** Changes a Metric's
|
|
68
|
-
*
|
|
67
|
+
/** Changes a Metric's description, Sources, Target Range or Workflow (scope metrics:edit), when the key's creator
|
|
68
|
+
* owns it or is its Editor (its Workflow: its owner). Answers the Metric as it is now. */
|
|
69
69
|
update: async (slug, patch) => (await this.request("PATCH", `/metrics/${encodeURIComponent(slug)}`, undefined, patch)).body,
|
|
70
70
|
/** Who submits to a Metric (scope metrics:read). */
|
|
71
71
|
submitters: async (slug) => (await this.get(`/metrics/${encodeURIComponent(slug)}/submitters`)).items,
|
|
@@ -172,6 +172,9 @@ export class Ziffr {
|
|
|
172
172
|
};
|
|
173
173
|
/** The workspace's live Feeds by id and name, to name one as a Submitter (scope metrics:edit). */
|
|
174
174
|
feeds = async () => (await this.get("/feeds")).items;
|
|
175
|
+
/** The Tags the key's creator sees, by name, each with how many Metrics they see it on (scope metrics:read). Renaming,
|
|
176
|
+
* merging and deleting Tags is done in Ziffr by an Owner or Admin, not through the API. */
|
|
177
|
+
tags = async () => (await this.get("/tags")).items;
|
|
175
178
|
/** The workspace's Groups. */
|
|
176
179
|
groups = {
|
|
177
180
|
/** One page of Groups. */
|
|
@@ -218,8 +221,8 @@ export class Ziffr {
|
|
|
218
221
|
close: async (id) => (await this.request("PATCH", `/actions/${id}`, undefined, { status: "closed" })).body,
|
|
219
222
|
/** Reopens one the creator asked. */
|
|
220
223
|
reopen: async (id) => (await this.request("PATCH", `/actions/${id}`, undefined, { status: "open" })).body,
|
|
221
|
-
/** Marks the creator's own open Task done. */
|
|
222
|
-
done: async (id) => (await this.request("POST", `/actions/${id}/done
|
|
224
|
+
/** Marks the creator's own open Task done, with an optional note (at most 2,000 characters) kept as the Thread's last reply. */
|
|
225
|
+
done: async (id, note) => (await this.request("POST", `/actions/${id}/done`, undefined, note === undefined ? undefined : { note })).body,
|
|
223
226
|
/** Confirms the creator's own value in a Self-check. */
|
|
224
227
|
confirm: async (id) => (await this.request("POST", `/actions/${id}/self-check`, undefined, { decision: "confirm" })).body,
|
|
225
228
|
/** Corrects the creator's own value in a Self-check. */
|
|
@@ -333,9 +336,13 @@ export class Ziffr {
|
|
|
333
336
|
}
|
|
334
337
|
async request(method, path, query, body, idempotencyKey) {
|
|
335
338
|
const url = new URL(this.base + path);
|
|
336
|
-
for (const [k, v] of Object.entries(query ?? {}))
|
|
337
|
-
if (v
|
|
339
|
+
for (const [k, v] of Object.entries(query ?? {})) {
|
|
340
|
+
if (Array.isArray(v))
|
|
341
|
+
for (const item of v)
|
|
342
|
+
url.searchParams.append(k, item);
|
|
343
|
+
else if (v !== undefined)
|
|
338
344
|
url.searchParams.set(k, String(v));
|
|
345
|
+
}
|
|
339
346
|
const headers = { authorization: `Bearer ${this.key}`, accept: "application/json" };
|
|
340
347
|
if (body !== undefined)
|
|
341
348
|
headers["content-type"] = "application/json";
|