@ziffr/sdk 0.15.0 → 0.17.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 +2 -2
- package/dist/index.d.ts +82 -10
- package/dist/index.js +13 -6
- 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! });
|
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`. */
|
|
@@ -32,6 +34,12 @@ export type Metric = {
|
|
|
32
34
|
};
|
|
33
35
|
/** A Metric on its own (`metrics.get`, `create` and `update` answer this): its description, its Workflow and when a value is due next. */
|
|
34
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[];
|
|
35
43
|
/** Where the Metric is in Ziffr, to give the person a link; needs a sign-in. */
|
|
36
44
|
url: string;
|
|
37
45
|
/** When its Workflow asks next (day, whole hour, time zone); null without a Workflow, and for a Derived or Archived Metric. */
|
|
@@ -72,7 +80,8 @@ export type Submitter = {
|
|
|
72
80
|
/** One labelled part of a value (GLOSSARY: Breakdown). */
|
|
73
81
|
export type BreakdownRow = {
|
|
74
82
|
label: string;
|
|
75
|
-
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;
|
|
76
85
|
};
|
|
77
86
|
/** A Metric's value for one period. */
|
|
78
87
|
export type Observation = {
|
|
@@ -88,6 +97,10 @@ export type Observation = {
|
|
|
88
97
|
submitted_at: string | null;
|
|
89
98
|
/** The Source it arrived through (web_form, mail, slack, telegram, api), or null for a Derived Metric. */
|
|
90
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;
|
|
91
104
|
/** A Thread on this period that the key's creator may read exists (see `thread`). */
|
|
92
105
|
has_thread: boolean;
|
|
93
106
|
breakdown: BreakdownRow[] | null;
|
|
@@ -163,6 +176,12 @@ export type NewMetric = {
|
|
|
163
176
|
submitters?: string[];
|
|
164
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. */
|
|
165
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;
|
|
166
185
|
};
|
|
167
186
|
/** What `metrics.update` may change of a Metric (scope metrics:edit): its description, Sources, Target Range and
|
|
168
187
|
* Workflow. Each part left out stays; null clears an end of the Target Range, the Metric's own Attainment method or its Workflow. */
|
|
@@ -182,6 +201,16 @@ export type MetricPatch = {
|
|
|
182
201
|
target_min?: number | null;
|
|
183
202
|
target_max?: number | null;
|
|
184
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;
|
|
185
214
|
};
|
|
186
215
|
/** A Metric's Unusual Value check: the check step of its Workflow, which several Metrics may share. */
|
|
187
216
|
export type UnusualValueCheck = {
|
|
@@ -220,6 +249,10 @@ export type Submission = {
|
|
|
220
249
|
value: number;
|
|
221
250
|
detail: string;
|
|
222
251
|
replayed: boolean;
|
|
252
|
+
unusual?: {
|
|
253
|
+
reasons: string[];
|
|
254
|
+
expected: string;
|
|
255
|
+
};
|
|
223
256
|
};
|
|
224
257
|
/** A Metric as its Feed sees it (spec 0012): what to fetch and which periods already have a value, never a value. */
|
|
225
258
|
export type FeedMetric = {
|
|
@@ -254,13 +287,14 @@ export type Workspace = {
|
|
|
254
287
|
/** The ways Ziffr can reach the key's creator to ask for a value now. */
|
|
255
288
|
reached_by: ("email" | "slack" | "telegram")[];
|
|
256
289
|
};
|
|
257
|
-
/** 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). */
|
|
258
291
|
export type Found = {
|
|
259
292
|
slug: string;
|
|
260
293
|
name: string;
|
|
261
294
|
archived: boolean;
|
|
262
295
|
period: string | null;
|
|
263
296
|
period_label: string | null;
|
|
297
|
+
matched_by?: "tag";
|
|
264
298
|
};
|
|
265
299
|
/** One duty in a Schedule: a value to submit, an Approval waiting, or a Task or Question assigned to the person. */
|
|
266
300
|
export type ScheduleEntry = {
|
|
@@ -270,10 +304,16 @@ export type ScheduleEntry = {
|
|
|
270
304
|
overdue: boolean;
|
|
271
305
|
/** Working days (Saturdays and Sundays skipped) it is late; 0 when it is not. */
|
|
272
306
|
overdue_working_days: number;
|
|
307
|
+
/** The Metric it is about; null for a checklist Task, which is about its Workflow (`workflow`) and period. */
|
|
273
308
|
metric: {
|
|
274
309
|
slug: string;
|
|
275
310
|
name: string;
|
|
276
|
-
};
|
|
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;
|
|
277
317
|
period: {
|
|
278
318
|
start: string;
|
|
279
319
|
name: string;
|
|
@@ -342,6 +382,20 @@ export type WorkflowStep = {
|
|
|
342
382
|
};
|
|
343
383
|
people: string[];
|
|
344
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;
|
|
345
399
|
};
|
|
346
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. */
|
|
347
401
|
export type AskingSchedule = {
|
|
@@ -394,7 +448,7 @@ export type TimelineEvent = {
|
|
|
394
448
|
/** The same moment's day in the workspace's time zone, and its time (HH:mm). */
|
|
395
449
|
day: string;
|
|
396
450
|
time: string;
|
|
397
|
-
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";
|
|
398
452
|
/** One sentence; names in it come from the workspace. */
|
|
399
453
|
text: string;
|
|
400
454
|
count: number;
|
|
@@ -417,6 +471,13 @@ export type PeriodStatus = {
|
|
|
417
471
|
of: number;
|
|
418
472
|
published: number;
|
|
419
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;
|
|
420
481
|
events: TimelineEvent[];
|
|
421
482
|
};
|
|
422
483
|
/** One value in a Feed's batch; `period` is the period's first day, the current period if left out. */
|
|
@@ -444,12 +505,17 @@ export type Action = {
|
|
|
444
505
|
kind: "question" | "task";
|
|
445
506
|
status: "open" | "answered" | "closed";
|
|
446
507
|
/** What a Workflow made it for (an Approval waiting, a Self-check, an Escalation); null for a plain one. */
|
|
447
|
-
purpose: "approval" | "self_check" | "escalation" | null;
|
|
448
|
-
/** 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. */
|
|
449
510
|
metric: {
|
|
450
511
|
slug: string;
|
|
451
512
|
name: string;
|
|
452
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;
|
|
453
519
|
period: string;
|
|
454
520
|
asked_by: string;
|
|
455
521
|
asked_by_name: string | null;
|
|
@@ -695,7 +761,7 @@ export type MadeViewLink = ViewLink & {
|
|
|
695
761
|
url: string;
|
|
696
762
|
};
|
|
697
763
|
/** The built-in views a key may place. */
|
|
698
|
-
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";
|
|
699
765
|
/** The few widget settings a key may set. */
|
|
700
766
|
export type WidgetSettings = {
|
|
701
767
|
window?: number;
|
|
@@ -736,8 +802,10 @@ export type PageOptions = {
|
|
|
736
802
|
cursor?: string;
|
|
737
803
|
};
|
|
738
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). */
|
|
739
806
|
export type MetricListOptions = PageOptions & {
|
|
740
807
|
archived?: boolean;
|
|
808
|
+
tag?: string[];
|
|
741
809
|
};
|
|
742
810
|
/** Options of a Metric's values: the periods from `from` to `to` (first days, YYYY-MM-DD, both included). */
|
|
743
811
|
export type ObservationOptions = PageOptions & {
|
|
@@ -779,9 +847,10 @@ export declare class Ziffr {
|
|
|
779
847
|
readonly metrics: {
|
|
780
848
|
/** One page of Metrics: those in use, or with `archived` only the Archived Metrics. */
|
|
781
849
|
list: ({ archived, ...options }?: MetricListOptions) => Promise<Page<Metric>>;
|
|
782
|
-
/** 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. */
|
|
783
851
|
all: (options?: {
|
|
784
852
|
archived?: boolean;
|
|
853
|
+
tag?: string[];
|
|
785
854
|
}) => AsyncGenerator<Metric, any, any>;
|
|
786
855
|
/** One Metric's description. */
|
|
787
856
|
get: (slug: string) => Promise<MetricDetail>;
|
|
@@ -986,6 +1055,9 @@ export declare class Ziffr {
|
|
|
986
1055
|
id: string;
|
|
987
1056
|
name: string;
|
|
988
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[]>;
|
|
989
1061
|
/** The workspace's Groups. */
|
|
990
1062
|
readonly groups: {
|
|
991
1063
|
/** One page of Groups. */
|
|
@@ -1042,8 +1114,8 @@ export declare class Ziffr {
|
|
|
1042
1114
|
close: (id: number) => Promise<Action>;
|
|
1043
1115
|
/** Reopens one the creator asked. */
|
|
1044
1116
|
reopen: (id: number) => Promise<Action>;
|
|
1045
|
-
/** Marks the creator's own open Task done. */
|
|
1046
|
-
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>;
|
|
1047
1119
|
/** Confirms the creator's own value in a Self-check. */
|
|
1048
1120
|
confirm: (id: number) => Promise<Action>;
|
|
1049
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
|
|
@@ -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";
|