@ziffr/sdk 0.1.0 → 0.14.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 +15 -0
- package/dist/index.d.ts +771 -4
- package/dist/index.js +185 -4
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -42,10 +42,25 @@ A key sees exactly what the person who made it sees, no more. A Metric it may no
|
|
|
42
42
|
| `metrics.list(options)`, `metrics.all()` | `GET /api/v1/metrics` |
|
|
43
43
|
| `metrics.get(slug)` | `GET /api/v1/metrics/{slug}` |
|
|
44
44
|
| `metrics.create({ name, period, unit, submit, ... }, { idempotencyKey })` | `POST /api/v1/metrics` |
|
|
45
|
+
| `metrics.update(slug, { target_min, target_max, polarity, attainment_method })` | `PATCH /api/v1/metrics/{slug}` |
|
|
46
|
+
| `targetSeries.list(slug)`, `targetSeries.set(slug, [{ period, value }])` | `GET`, `POST /api/v1/metrics/{slug}/target-series` (value null removes a period) |
|
|
47
|
+
| `metrics.submitters(slug)`, `metrics.setSubmitters(slug, { add, remove })` | `GET`, `POST /api/v1/metrics/{slug}/submitters` (people and Contacts from `people`, Feeds from `feeds()`) |
|
|
48
|
+
| `feeds()` | `GET /api/v1/feeds`: live Feeds to name as Submitters |
|
|
49
|
+
| `metrics.unusualValueCheck(slug)`, `metrics.setUnusualValueCheck(slug, { change_pct, outside_target })` | `GET`, `PATCH /api/v1/metrics/{slug}/unusual-value-check`: the check step of the Metric's Workflow, shared by its Metrics |
|
|
50
|
+
| `projections.list(slug)`, `projections.set(slug, [{ period, value }])` | `GET`, `POST /api/v1/metrics/{slug}/projections` (the current period or later) |
|
|
45
51
|
| `observations.list(slug, { from, to, limit, cursor })`, `observations.all(slug, { from, to })` | `GET /api/v1/metrics/{slug}/observations` |
|
|
46
52
|
| `observations.submit(slug, { value, period, breakdown }, { idempotencyKey })` | `POST /api/v1/metrics/{slug}/observations` |
|
|
47
53
|
| `workspace()` | `GET /api/v1/workspace`: the month the fiscal year starts in, where quarters and years begin |
|
|
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 |
|
|
48
55
|
| `people.list(options)`, `people.all()` | `GET /api/v1/people` |
|
|
49
56
|
| `groups.list(options)`, `groups.all()` | `GET /api/v1/groups` |
|
|
57
|
+
| `actions.list(options)`, `actions.all(options)`, `actions.reply(id, body, correction)`, `actions.close(id)`, `actions.reopen(id)`, `actions.done(id)`, `actions.confirm(id)`, `actions.correct(id, value)`, `actions.approve(id)`, `actions.sendBack(id, comment)` | `GET /api/v1/actions`, `POST .../replies`, `PATCH /api/v1/actions/{id}`, `POST .../done`, `POST .../self-check`, `POST .../approval`: the key's creator's own Questions and Tasks; scopes `actions:read`, `actions:write`, `values:submit` (Self-check) and `values:approve` (Approval, a program's key only) |
|
|
58
|
+
| `snapshots.list(dashboardId)`, `snapshots.get(id)`, `snapshots.take(dashboardId, { kind, start })` | `GET /api/v1/dashboards/{id}/snapshots`, `GET /api/v1/snapshots/{id}`, `POST /api/v1/dashboards/{id}/snapshots`: reading needs Read dashboards, taking Build dashboards |
|
|
59
|
+
| `viewLinks.list(dashboardId)`, `viewLinks.create(dashboardId, { expires, label, frozen, snapshot })`, `viewLinks.revoke(id)` | `GET`, `POST /api/v1/dashboards/{id}/view-links`, `DELETE /api/v1/view-links/{id}`: scope Manage View Links (`view-links:write`, a program's key only); `create` answers with the `token` and `url` once |
|
|
60
|
+
| `workflows.get(id)`, `workflows.create(input)`, `workflows.update(id, patch)`, `workflows.remove(id)` | `GET`, `PATCH`, `DELETE /api/v1/workflows/{id}`, `POST /api/v1/workflows`: the key's creator's own Workflows and their steps; reading needs Read metrics, the rest Build workflows, and an Approve or Tell step also Name who approves and who is told (programs' keys only) |
|
|
61
|
+
| `alerts.list({ metric })`, `alerts.create(input)`, `alerts.update(id, patch)`, `alerts.remove(id)` | `GET`, `POST /api/v1/alerts`, `PATCH`, `DELETE /api/v1/alerts/{id}`: the key's creator's own Alerts only; listing needs Read metrics, the rest Manage alerts |
|
|
62
|
+
| `shares.who(target)`, `shares.set(target, to, role)`, `shares.decide(id, grant)` | `GET`, `POST /api/v1/shares`, `POST /api/v1/shares/requests/{id}`: scope `shares:write` |
|
|
63
|
+
| `groups.create`, `rename`, `remove`, `addMember`, `removeMember` | `POST /api/v1/groups`, `PATCH`, `DELETE /api/v1/groups/{id}`, `/members`: scope `groups:write` |
|
|
64
|
+
| `people.addContact`, `setRole`, `remove`; `invitations.list`, `invite`, `link`, `revoke`, `resend`; `joinRequests.list`, `decide` | `/api/v1/people`, `/invitations`, `/join-requests`: scope `people:write` |
|
|
50
65
|
|
|
51
66
|
Fields, limits and errors of each are in the [API reference](https://github.com/ziffr/ziffr/blob/next/docs/reference/api.md).
|
package/dist/index.d.ts
CHANGED
|
@@ -8,13 +8,44 @@ export type Metric = {
|
|
|
8
8
|
period: Period;
|
|
9
9
|
format: "number" | "currency" | "percent";
|
|
10
10
|
unit: string;
|
|
11
|
+
/** Which side of the value the unit stands on: before ($1,200) or after (1,200 €). */
|
|
12
|
+
unit_position: "before" | "after";
|
|
11
13
|
decimals: number;
|
|
12
14
|
polarity: "higher" | "lower" | "target";
|
|
13
15
|
aggregation: "sum" | "average" | "last" | "none";
|
|
14
16
|
target_min: number | null;
|
|
15
17
|
target_max: number | null;
|
|
18
|
+
/** How its Attainment is computed: by ratio or by distance to the target; null follows the workspace's default. */
|
|
19
|
+
attainment_method: "ratio" | "distance" | null;
|
|
20
|
+
/** Its Sources: the ways values may arrive. The personal form link works apart from them. */
|
|
21
|
+
sources: Source[];
|
|
16
22
|
/** A Derived Metric: computed from others, takes no values. */
|
|
17
23
|
derived: boolean;
|
|
24
|
+
/** An Archived Metric: kept with its values and history, asked for nothing and taking no values. */
|
|
25
|
+
archived: boolean;
|
|
26
|
+
/** 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
|
+
retention: Retention | null;
|
|
28
|
+
/** A confirmed Retention that has not started: nothing is changed before `starts_on`. */
|
|
29
|
+
retention_pending: (Retention & {
|
|
30
|
+
starts_on: string;
|
|
31
|
+
}) | null;
|
|
32
|
+
};
|
|
33
|
+
/** 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
|
+
export type Retention = {
|
|
35
|
+
keep_months: number;
|
|
36
|
+
then: "condense";
|
|
37
|
+
into: "week" | "month" | "quarter" | "year";
|
|
38
|
+
} | {
|
|
39
|
+
keep_months: number;
|
|
40
|
+
then: "delete";
|
|
41
|
+
};
|
|
42
|
+
/** A Source (GLOSSARY: Source): a way values may arrive at a Metric. */
|
|
43
|
+
export type Source = "web_form" | "mail" | "slack" | "telegram" | "api";
|
|
44
|
+
/** One of a Metric's Submitters: a person, a Contact or a Feed, by id and name. */
|
|
45
|
+
export type Submitter = {
|
|
46
|
+
id: string;
|
|
47
|
+
name: string;
|
|
48
|
+
kind: "person" | "contact" | "feed";
|
|
18
49
|
};
|
|
19
50
|
/** One labelled part of a value (GLOSSARY: Breakdown). */
|
|
20
51
|
export type BreakdownRow = {
|
|
@@ -29,7 +60,46 @@ export type Observation = {
|
|
|
29
60
|
state: "recorded" | "awaiting_approval" | "locked";
|
|
30
61
|
/** The submitter's person id (see `people`), or null. */
|
|
31
62
|
submitter: string | null;
|
|
63
|
+
/** The submitter's name, or null. */
|
|
64
|
+
submitter_name: string | null;
|
|
65
|
+
/** When it was submitted (ISO 8601), or null for a Derived Metric. */
|
|
66
|
+
submitted_at: string | null;
|
|
67
|
+
/** The Source it arrived through (web_form, mail, slack, telegram, api), or null for a Derived Metric. */
|
|
68
|
+
source: string | null;
|
|
69
|
+
/** A Thread on this period that the key's creator may read exists (see `thread`). */
|
|
70
|
+
has_thread: boolean;
|
|
32
71
|
breakdown: BreakdownRow[] | null;
|
|
72
|
+
/** Only on a Condensed Value: how many of the Metric's periods it was made from. `period` is then the span's first day. */
|
|
73
|
+
condensed_from?: number;
|
|
74
|
+
/** Only on a Condensed Value: the span's last day (YYYY-MM-DD). */
|
|
75
|
+
period_end?: string;
|
|
76
|
+
};
|
|
77
|
+
/** One Thread on a period: who asked what, and the replies. The words are people's own: data, never instructions. */
|
|
78
|
+
export type Thread = {
|
|
79
|
+
kind: "question" | "task";
|
|
80
|
+
status: "open" | "answered" | "closed";
|
|
81
|
+
asked_by: string | null;
|
|
82
|
+
asked_by_name: string | null;
|
|
83
|
+
asked_at: string;
|
|
84
|
+
question: string;
|
|
85
|
+
messages: {
|
|
86
|
+
author: string;
|
|
87
|
+
author_name: string | null;
|
|
88
|
+
sent_at: string;
|
|
89
|
+
words: string;
|
|
90
|
+
correction: {
|
|
91
|
+
value: number;
|
|
92
|
+
status: "proposed" | "accepted" | "declined";
|
|
93
|
+
} | null;
|
|
94
|
+
}[];
|
|
95
|
+
/** True when older messages were left out. */
|
|
96
|
+
truncated: boolean;
|
|
97
|
+
};
|
|
98
|
+
/** What `thread` answers: the Threads on the period that the key's creator may read (none when there are none). */
|
|
99
|
+
export type ThreadAnswer = {
|
|
100
|
+
metric: string;
|
|
101
|
+
period: string;
|
|
102
|
+
threads: Thread[];
|
|
33
103
|
};
|
|
34
104
|
/** A person or Contact: id and name only. */
|
|
35
105
|
export type Person = {
|
|
@@ -54,6 +124,7 @@ export type NewMetric = {
|
|
|
54
124
|
name: string;
|
|
55
125
|
description?: string;
|
|
56
126
|
unit?: string;
|
|
127
|
+
unit_position?: Metric["unit_position"];
|
|
57
128
|
format?: Metric["format"];
|
|
58
129
|
decimals?: number;
|
|
59
130
|
period?: Metric["period"];
|
|
@@ -62,8 +133,47 @@ export type NewMetric = {
|
|
|
62
133
|
aggregation?: Metric["aggregation"];
|
|
63
134
|
target_min?: number | null;
|
|
64
135
|
target_max?: number | null;
|
|
136
|
+
attainment_method?: Metric["attainment_method"];
|
|
65
137
|
submit?: boolean;
|
|
138
|
+
/** Its Sources; left out, every one. */
|
|
139
|
+
sources?: Source[];
|
|
140
|
+
/** Who submits: ids from `people` and `feeds`, at most 20; each gets a first Prompt. Needs scope metrics:edit too. */
|
|
141
|
+
submitters?: string[];
|
|
142
|
+
};
|
|
143
|
+
/** What `metrics.update` may change of a Metric (scope metrics:edit): its Polarity, Target Range and Attainment method.
|
|
144
|
+
* Each part left out stays; null clears an end of the Target Range or the Metric's own method. */
|
|
145
|
+
export type MetricPatch = {
|
|
146
|
+
/** Its Sources, all of them: the ones left out are turned off. */
|
|
147
|
+
sources?: Source[];
|
|
148
|
+
polarity?: "higher" | "lower" | "target";
|
|
149
|
+
target_min?: number | null;
|
|
150
|
+
target_max?: number | null;
|
|
151
|
+
attainment_method?: "ratio" | "distance" | null;
|
|
152
|
+
};
|
|
153
|
+
/** A Metric's Unusual Value check: the check step of its Workflow, which several Metrics may share. */
|
|
154
|
+
export type UnusualValueCheck = {
|
|
155
|
+
workflow: {
|
|
156
|
+
name: string;
|
|
157
|
+
yours: boolean;
|
|
158
|
+
metrics: number;
|
|
159
|
+
} | null;
|
|
160
|
+
check: {
|
|
161
|
+
change_pct: number;
|
|
162
|
+
outside_target: boolean;
|
|
163
|
+
} | null;
|
|
164
|
+
};
|
|
165
|
+
/** One period's value of a Target Series or a Projection: the period's first day and the value. */
|
|
166
|
+
export type SeriesValue = {
|
|
167
|
+
period: string;
|
|
168
|
+
value: number;
|
|
169
|
+
};
|
|
170
|
+
/** One period to set in a Target Series or Projections: a number sets it, null removes it. */
|
|
171
|
+
export type SeriesItem = {
|
|
172
|
+
period: string;
|
|
173
|
+
value: number | null;
|
|
66
174
|
};
|
|
175
|
+
/** Most periods one call sets or removes in a Target Series or Projections. */
|
|
176
|
+
export declare const SERIES_ITEMS_MAX = 500;
|
|
67
177
|
/** What a submission sends. */
|
|
68
178
|
export type SubmitValue = {
|
|
69
179
|
value: number;
|
|
@@ -103,6 +213,167 @@ export type FeedOverview = {
|
|
|
103
213
|
export type Workspace = {
|
|
104
214
|
year_start_month: number;
|
|
105
215
|
};
|
|
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). */
|
|
217
|
+
export type Found = {
|
|
218
|
+
slug: string;
|
|
219
|
+
name: string;
|
|
220
|
+
archived: boolean;
|
|
221
|
+
period: string | null;
|
|
222
|
+
period_label: string | null;
|
|
223
|
+
};
|
|
224
|
+
/** One duty in a Schedule: a value to submit, an Approval waiting, or a Task or Question assigned to the person. */
|
|
225
|
+
export type ScheduleEntry = {
|
|
226
|
+
kind: "value_due" | "approval" | "task" | "question";
|
|
227
|
+
/** The day it falls on (YYYY-MM-DD); null for an undated Task or Question. */
|
|
228
|
+
date: string | null;
|
|
229
|
+
overdue: boolean;
|
|
230
|
+
/** Working days (Saturdays and Sundays skipped) it is late; 0 when it is not. */
|
|
231
|
+
overdue_working_days: number;
|
|
232
|
+
metric: {
|
|
233
|
+
slug: string;
|
|
234
|
+
name: string;
|
|
235
|
+
};
|
|
236
|
+
period: {
|
|
237
|
+
start: string;
|
|
238
|
+
name: string;
|
|
239
|
+
};
|
|
240
|
+
/** The Approval's, Task's or Question's id; null for a value due. */
|
|
241
|
+
action_id: number | null;
|
|
242
|
+
/** A Task's or Question's words; null for a value due and an Approval. */
|
|
243
|
+
text: string | null;
|
|
244
|
+
/** A Question the Workflow asked because a value is missing. */
|
|
245
|
+
escalation: boolean;
|
|
246
|
+
/** The name of the colleague the person stands in for while they are Away. */
|
|
247
|
+
standing_in_for: string | null;
|
|
248
|
+
/** A value of a Metric without a Workflow, dated the first working day after its period ends. */
|
|
249
|
+
no_due_date: boolean;
|
|
250
|
+
/** How many days before the Due Date Ziffr reminds, or null. */
|
|
251
|
+
remind_days_before: number | null;
|
|
252
|
+
/** Where it is done in Ziffr; needs a sign-in. */
|
|
253
|
+
url: string;
|
|
254
|
+
};
|
|
255
|
+
/** What GET /schedule answers: overdue first (the last 90 days, whatever the span), the span's days that have
|
|
256
|
+
* entries, and the undated Tasks and Questions. */
|
|
257
|
+
export type Schedule = {
|
|
258
|
+
today: string; /** Whose Schedule it is. */
|
|
259
|
+
person_id: string;
|
|
260
|
+
overdue: ScheduleEntry[];
|
|
261
|
+
days: {
|
|
262
|
+
date: string;
|
|
263
|
+
entries: ScheduleEntry[];
|
|
264
|
+
}[];
|
|
265
|
+
undated: ScheduleEntry[];
|
|
266
|
+
};
|
|
267
|
+
/** A Workflow: id and name. */
|
|
268
|
+
export type WorkflowName = {
|
|
269
|
+
id: number;
|
|
270
|
+
name: string;
|
|
271
|
+
};
|
|
272
|
+
/** A step of a Workflow, in the order they run. A Tell step's `id` is left out for a new step and sent back as read for an existing one. */
|
|
273
|
+
export type WorkflowStep = {
|
|
274
|
+
type: "remind";
|
|
275
|
+
days_before: number;
|
|
276
|
+
} | {
|
|
277
|
+
type: "escalate";
|
|
278
|
+
to: "stand-in" | "owner";
|
|
279
|
+
days_after: number;
|
|
280
|
+
} | {
|
|
281
|
+
type: "check";
|
|
282
|
+
change_pct: number;
|
|
283
|
+
outside_target: boolean;
|
|
284
|
+
} | {
|
|
285
|
+
type: "approve";
|
|
286
|
+
approvers: string[];
|
|
287
|
+
values: "unusual" | "every";
|
|
288
|
+
nobody_else: "self-check" | "count";
|
|
289
|
+
} | {
|
|
290
|
+
type: "publish";
|
|
291
|
+
lock: boolean;
|
|
292
|
+
} | {
|
|
293
|
+
type: "tell";
|
|
294
|
+
id?: string;
|
|
295
|
+
condition: {
|
|
296
|
+
kind: "share_of_target" | "changed_more";
|
|
297
|
+
share: string;
|
|
298
|
+
} | {
|
|
299
|
+
kind: "at_or_above" | "below";
|
|
300
|
+
value: string;
|
|
301
|
+
};
|
|
302
|
+
people: string[];
|
|
303
|
+
groups: number[];
|
|
304
|
+
};
|
|
305
|
+
/** 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
|
+
export type AskingSchedule = {
|
|
307
|
+
hour: number | null;
|
|
308
|
+
days: {
|
|
309
|
+
kind: "every_day";
|
|
310
|
+
} | {
|
|
311
|
+
kind: "weekdays";
|
|
312
|
+
} | {
|
|
313
|
+
kind: "chosen_weekdays";
|
|
314
|
+
days: number[];
|
|
315
|
+
} | {
|
|
316
|
+
kind: "every_n_days";
|
|
317
|
+
n: number;
|
|
318
|
+
from: string;
|
|
319
|
+
} | {
|
|
320
|
+
kind: "month_day";
|
|
321
|
+
day: number | "last";
|
|
322
|
+
};
|
|
323
|
+
};
|
|
324
|
+
/** A Workflow of the key's creator with its steps. */
|
|
325
|
+
export type WorkflowDetail = {
|
|
326
|
+
id: number;
|
|
327
|
+
name: string;
|
|
328
|
+
due_working_days: number;
|
|
329
|
+
lock_summary: boolean;
|
|
330
|
+
steps: WorkflowStep[];
|
|
331
|
+
asking: AskingSchedule | null;
|
|
332
|
+
metrics: number;
|
|
333
|
+
updated_at: string;
|
|
334
|
+
};
|
|
335
|
+
/** What to say to make a Workflow. */
|
|
336
|
+
export type NewWorkflow = {
|
|
337
|
+
name: string;
|
|
338
|
+
due_working_days?: number;
|
|
339
|
+
lock_summary?: boolean;
|
|
340
|
+
steps?: WorkflowStep[];
|
|
341
|
+
asking?: AskingSchedule | null;
|
|
342
|
+
};
|
|
343
|
+
/** What to change in one; each part left out stays, `steps` replaces all of them. */
|
|
344
|
+
export type WorkflowPatch = Partial<NewWorkflow>;
|
|
345
|
+
/** One line of a period's timeline: one event, or several of one kind close together. */
|
|
346
|
+
export type TimelineEvent = {
|
|
347
|
+
/** When it happened (the first of a group), as an instant. */
|
|
348
|
+
at: string;
|
|
349
|
+
/** The same moment's day in the workspace's time zone, and its time (HH:mm). */
|
|
350
|
+
day: string;
|
|
351
|
+
time: string;
|
|
352
|
+
kind: "asked" | "reminded" | "in" | "action" | "approval_asked" | "approved" | "sent_back" | "checked" | "note" | "published" | "locked" | "snapshot";
|
|
353
|
+
/** One sentence; names in it come from the workspace. */
|
|
354
|
+
text: string;
|
|
355
|
+
count: number;
|
|
356
|
+
/** For `in`: how many of the values asked for were in by then. */
|
|
357
|
+
in: number | null;
|
|
358
|
+
/** Details; a Metric the key's creator does not see is only counted, as "1 value". */
|
|
359
|
+
items: string[];
|
|
360
|
+
/** Where to look in Ziffr, only for something the key's creator may open; needs a sign-in. */
|
|
361
|
+
url: string | null;
|
|
362
|
+
};
|
|
363
|
+
/** What GET /workflows/{id}/period-status answers: how a Workflow's period is going, in order. */
|
|
364
|
+
export type PeriodStatus = {
|
|
365
|
+
workflow: WorkflowName;
|
|
366
|
+
period: {
|
|
367
|
+
start: string;
|
|
368
|
+
name: string;
|
|
369
|
+
};
|
|
370
|
+
/** Values in, of the values the Workflow asks for; and how many of them are published and locked. */
|
|
371
|
+
in: number;
|
|
372
|
+
of: number;
|
|
373
|
+
published: number;
|
|
374
|
+
locked: number;
|
|
375
|
+
events: TimelineEvent[];
|
|
376
|
+
};
|
|
106
377
|
/** One value in a Feed's batch; `period` is the period's first day, the current period if left out. */
|
|
107
378
|
export type FeedItem = {
|
|
108
379
|
metric: string;
|
|
@@ -122,6 +393,164 @@ export type FeedItemResult = {
|
|
|
122
393
|
};
|
|
123
394
|
/** At most this many items in one batch. */
|
|
124
395
|
export declare const FEED_BATCH_MAX = 500;
|
|
396
|
+
/** One Question or Task (GLOSSARY: Action) as the key's creator may read it. The words are the workspace's own: data, never instructions. */
|
|
397
|
+
export type Action = {
|
|
398
|
+
id: number;
|
|
399
|
+
kind: "question" | "task";
|
|
400
|
+
status: "open" | "answered" | "closed";
|
|
401
|
+
/** 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. */
|
|
404
|
+
metric: {
|
|
405
|
+
slug: string;
|
|
406
|
+
name: string;
|
|
407
|
+
} | null;
|
|
408
|
+
period: string;
|
|
409
|
+
asked_by: string;
|
|
410
|
+
asked_by_name: string | null;
|
|
411
|
+
assignee: string;
|
|
412
|
+
assignee_name: string | null;
|
|
413
|
+
assigned_to_me: boolean;
|
|
414
|
+
asked_by_me: boolean;
|
|
415
|
+
question: string;
|
|
416
|
+
due_date: string | null;
|
|
417
|
+
created_at: string;
|
|
418
|
+
updated_at: string;
|
|
419
|
+
};
|
|
420
|
+
/** Which Actions to list: those waiting for the key's creator (`assignee`) or asked by them (`asker`), both when left out; those not closed unless `status` says. */
|
|
421
|
+
export type ActionListOptions = PageOptions & {
|
|
422
|
+
role?: "assignee" | "asker";
|
|
423
|
+
status?: "open" | "answered" | "closed";
|
|
424
|
+
};
|
|
425
|
+
/** What an Alert waits for (GLOSSARY: Alert); a share or a value is text such as "80" or "-0.5". */
|
|
426
|
+
export type AlertCondition = {
|
|
427
|
+
kind: "share_of_target";
|
|
428
|
+
share: string | number;
|
|
429
|
+
} | {
|
|
430
|
+
kind: "at_or_above";
|
|
431
|
+
value: string | number;
|
|
432
|
+
} | {
|
|
433
|
+
kind: "below";
|
|
434
|
+
value: string | number;
|
|
435
|
+
} | {
|
|
436
|
+
kind: "changed_more";
|
|
437
|
+
share: string | number;
|
|
438
|
+
} | {
|
|
439
|
+
kind: "missing_after_due";
|
|
440
|
+
};
|
|
441
|
+
/** The way an Alert's message is sent: the person's Delivery Preference (usual) or one way. */
|
|
442
|
+
export type AlertDelivery = "usual" | "email" | "slack" | "telegram";
|
|
443
|
+
/** Where Shares apply: a Metric (named by its slug), a dashboard or a deck (named by number id). */
|
|
444
|
+
export type ShareTarget = {
|
|
445
|
+
type: "metric";
|
|
446
|
+
id: string;
|
|
447
|
+
} | {
|
|
448
|
+
type: "dashboard" | "deck";
|
|
449
|
+
id: number;
|
|
450
|
+
};
|
|
451
|
+
/** Who a Share is with: one member of the workspace, or one Group. */
|
|
452
|
+
export type ShareWith = {
|
|
453
|
+
person: string;
|
|
454
|
+
} | {
|
|
455
|
+
group: number;
|
|
456
|
+
};
|
|
457
|
+
/** Who can see something and why, and for its owner the open requests for access. */
|
|
458
|
+
export type Audience = {
|
|
459
|
+
owner: string;
|
|
460
|
+
is_owner: boolean;
|
|
461
|
+
people: {
|
|
462
|
+
id: string;
|
|
463
|
+
name: string;
|
|
464
|
+
how: string[];
|
|
465
|
+
}[];
|
|
466
|
+
requests: {
|
|
467
|
+
id: number;
|
|
468
|
+
person: string;
|
|
469
|
+
name: string;
|
|
470
|
+
requested_at: string;
|
|
471
|
+
}[];
|
|
472
|
+
};
|
|
473
|
+
/** A Workspace Role. */
|
|
474
|
+
export type WorkspaceRole = "owner" | "admin" | "member" | "guest";
|
|
475
|
+
/** An invitation as a list shows it: never its token. */
|
|
476
|
+
export type Invitation = {
|
|
477
|
+
id: number;
|
|
478
|
+
email: string | null;
|
|
479
|
+
role: WorkspaceRole;
|
|
480
|
+
expires_at: string;
|
|
481
|
+
created_at: string;
|
|
482
|
+
emailed: boolean;
|
|
483
|
+
email_error: string | null;
|
|
484
|
+
};
|
|
485
|
+
/** A request to join the workspace by its domain, with the address the person proved. */
|
|
486
|
+
export type JoinRequest = {
|
|
487
|
+
id: number;
|
|
488
|
+
requested_at: string;
|
|
489
|
+
person: {
|
|
490
|
+
id: string;
|
|
491
|
+
name: string;
|
|
492
|
+
email: string | null;
|
|
493
|
+
};
|
|
494
|
+
};
|
|
495
|
+
/** One of the key's creator's own Alerts: its Metric, condition, state and when it last fired; never a value. */
|
|
496
|
+
export type Alert = {
|
|
497
|
+
id: number;
|
|
498
|
+
metric: {
|
|
499
|
+
slug: string;
|
|
500
|
+
name: string;
|
|
501
|
+
};
|
|
502
|
+
condition: AlertCondition;
|
|
503
|
+
delivery: AlertDelivery;
|
|
504
|
+
include_unapproved: boolean;
|
|
505
|
+
paused_by_person: boolean;
|
|
506
|
+
/** Why Ziffr does not let it fire, or null. */
|
|
507
|
+
paused: "no_access" | "archived" | "no_target" | "no_workflow" | null;
|
|
508
|
+
state: "armed" | "fired";
|
|
509
|
+
fired_at: string | null;
|
|
510
|
+
created_at: string;
|
|
511
|
+
};
|
|
512
|
+
/** What a Share Proposal asks for: with `email` and `ends`, a View Link; with `person` or `group`, a Share as Viewer. */
|
|
513
|
+
export type NewShareProposal = {
|
|
514
|
+
dashboard: number;
|
|
515
|
+
snapshot?: number | null;
|
|
516
|
+
live?: boolean;
|
|
517
|
+
email?: string;
|
|
518
|
+
ends?: string;
|
|
519
|
+
message?: string | null;
|
|
520
|
+
person?: string;
|
|
521
|
+
group?: number;
|
|
522
|
+
};
|
|
523
|
+
/** A Share Proposal as made: open, with the page where the person confirms it. */
|
|
524
|
+
export type ShareProposal = {
|
|
525
|
+
id: number;
|
|
526
|
+
status: "open";
|
|
527
|
+
how: "view_link" | "share";
|
|
528
|
+
dashboard: {
|
|
529
|
+
id: number;
|
|
530
|
+
name: string;
|
|
531
|
+
};
|
|
532
|
+
recipient: string;
|
|
533
|
+
ends: string | null;
|
|
534
|
+
message: string | null;
|
|
535
|
+
live: boolean;
|
|
536
|
+
expires: string;
|
|
537
|
+
url: string;
|
|
538
|
+
preview: Dashboard;
|
|
539
|
+
};
|
|
540
|
+
/** What to say to make an Alert. */
|
|
541
|
+
export type NewAlert = {
|
|
542
|
+
metric: string;
|
|
543
|
+
condition: AlertCondition;
|
|
544
|
+
delivery?: AlertDelivery;
|
|
545
|
+
include_unapproved?: boolean;
|
|
546
|
+
};
|
|
547
|
+
/** What to say to change one; each part left out stays. */
|
|
548
|
+
export type AlertPatch = {
|
|
549
|
+
condition?: AlertCondition;
|
|
550
|
+
delivery?: AlertDelivery;
|
|
551
|
+
include_unapproved?: boolean;
|
|
552
|
+
paused?: boolean;
|
|
553
|
+
};
|
|
125
554
|
/** A dashboard in a list (spec 0014): the key's creator's role on it and where to open it. */
|
|
126
555
|
export type DashboardSummary = {
|
|
127
556
|
id: number;
|
|
@@ -155,6 +584,71 @@ export type Dashboard = DashboardSummary & {
|
|
|
155
584
|
intro: string;
|
|
156
585
|
widgets: Widget[];
|
|
157
586
|
};
|
|
587
|
+
/** The periods a Snapshot can be of. */
|
|
588
|
+
export type SnapshotKind = "week" | "month" | "quarter" | "half" | "year";
|
|
589
|
+
/** A Snapshot in a list (ticket #435): `shown` is false while it is a draft for the dashboard's owner and Editors. */
|
|
590
|
+
export type SnapshotSummary = {
|
|
591
|
+
id: number;
|
|
592
|
+
dashboard: number;
|
|
593
|
+
kind: SnapshotKind;
|
|
594
|
+
start: string;
|
|
595
|
+
end: string;
|
|
596
|
+
label: string;
|
|
597
|
+
takenAt: string;
|
|
598
|
+
automatic: boolean;
|
|
599
|
+
shown: boolean;
|
|
600
|
+
url: string;
|
|
601
|
+
};
|
|
602
|
+
/** One Snapshot read: only the Metrics the key's creator sees now, at most the latest 240 values of each. */
|
|
603
|
+
export type Snapshot = SnapshotSummary & {
|
|
604
|
+
name: string;
|
|
605
|
+
intro: string;
|
|
606
|
+
/** Widgets left out because they draw a Metric the creator does not see. */
|
|
607
|
+
hiddenWidgets: number;
|
|
608
|
+
widgets: SnapshotWidget[];
|
|
609
|
+
metrics: SnapshotMetric[];
|
|
610
|
+
/** Kept values that differ from the ones recorded now; `now` is null when removed. */
|
|
611
|
+
corrections: {
|
|
612
|
+
metric: string;
|
|
613
|
+
period: string;
|
|
614
|
+
was: number;
|
|
615
|
+
now: number | null;
|
|
616
|
+
}[];
|
|
617
|
+
};
|
|
618
|
+
/** A widget of a Snapshot: a Finding carries its words. */
|
|
619
|
+
export type SnapshotWidget = {
|
|
620
|
+
id: number;
|
|
621
|
+
view: string;
|
|
622
|
+
title: string | null;
|
|
623
|
+
metrics: string[];
|
|
624
|
+
words?: Record<string, string>;
|
|
625
|
+
};
|
|
626
|
+
/** A Metric of a Snapshot with the values it kept. */
|
|
627
|
+
export type SnapshotMetric = {
|
|
628
|
+
slug: string;
|
|
629
|
+
name: string;
|
|
630
|
+
unit: string;
|
|
631
|
+
values: {
|
|
632
|
+
period: string;
|
|
633
|
+
value: number;
|
|
634
|
+
}[];
|
|
635
|
+
};
|
|
636
|
+
/** A View Link as listed: never its token or address. */
|
|
637
|
+
export type ViewLink = {
|
|
638
|
+
id: number;
|
|
639
|
+
dashboard: number;
|
|
640
|
+
label: string;
|
|
641
|
+
expires: string;
|
|
642
|
+
revoked: boolean;
|
|
643
|
+
created: string;
|
|
644
|
+
frozen: boolean;
|
|
645
|
+
snapshot: number | null;
|
|
646
|
+
};
|
|
647
|
+
/** A View Link just made: `token` and `url` are shown this once. */
|
|
648
|
+
export type MadeViewLink = ViewLink & {
|
|
649
|
+
token: string;
|
|
650
|
+
url: string;
|
|
651
|
+
};
|
|
158
652
|
/** The built-in views a key may place. */
|
|
159
653
|
export type View = "number" | "line" | "bars" | "gauge" | "table" | "forecast" | "correlation" | "matrix" | "drivers" | "ranked" | "share" | "pictogram" | "story-line";
|
|
160
654
|
/** The few widget settings a key may set. */
|
|
@@ -196,6 +690,10 @@ export type PageOptions = {
|
|
|
196
690
|
limit?: number;
|
|
197
691
|
cursor?: string;
|
|
198
692
|
};
|
|
693
|
+
/** Options of the Metrics list: with `archived`, only the Archived Metrics instead of those in use. */
|
|
694
|
+
export type MetricListOptions = PageOptions & {
|
|
695
|
+
archived?: boolean;
|
|
696
|
+
};
|
|
199
697
|
/** Options of a Metric's values: the periods from `from` to `to` (first days, YYYY-MM-DD, both included). */
|
|
200
698
|
export type ObservationOptions = PageOptions & {
|
|
201
699
|
from?: string;
|
|
@@ -234,10 +732,12 @@ export declare class Ziffr {
|
|
|
234
732
|
constructor(options: ZiffrOptions);
|
|
235
733
|
/** The Metrics the key's creator sees. */
|
|
236
734
|
readonly metrics: {
|
|
237
|
-
/** One page of Metrics. */
|
|
238
|
-
list: (options?:
|
|
239
|
-
/** Every Metric, page by page. */
|
|
240
|
-
all: (
|
|
735
|
+
/** One page of Metrics: those in use, or with `archived` only the Archived Metrics. */
|
|
736
|
+
list: ({ archived, ...options }?: MetricListOptions) => Promise<Page<Metric>>;
|
|
737
|
+
/** Every Metric in use, or with `archived` every Archived Metric, page by page. */
|
|
738
|
+
all: (options?: {
|
|
739
|
+
archived?: boolean;
|
|
740
|
+
}) => AsyncGenerator<Metric, any, any>;
|
|
241
741
|
/** One Metric's description. */
|
|
242
742
|
get: (slug: string) => Promise<Metric>;
|
|
243
743
|
/** Creates a Metric owned by the key's creator (scope metrics:write). A fresh idempotency key is sent unless one is
|
|
@@ -253,6 +753,58 @@ export declare class Ziffr {
|
|
|
253
753
|
deleted: string;
|
|
254
754
|
values: number;
|
|
255
755
|
}>;
|
|
756
|
+
/** Archives a Metric (scope metrics:write), when the key's creator is an Owner or Admin or owns it: its values and
|
|
757
|
+
* history stay, it is asked for nothing and takes no values. Answers the Metric as it is now. */
|
|
758
|
+
archive: (slug: string) => Promise<Metric>;
|
|
759
|
+
/** Brings an Archived Metric back (scope metrics:write), under the same rule. Answers the Metric as it is now. */
|
|
760
|
+
restore: (slug: string) => Promise<Metric>;
|
|
761
|
+
/** Changes a Metric's Polarity, Target Range or Attainment method (scope metrics:edit), when
|
|
762
|
+
* the key's creator owns it or is its Editor. Answers the Metric as it is now. */
|
|
763
|
+
update: (slug: string, patch: MetricPatch) => Promise<Metric>;
|
|
764
|
+
/** Who submits to a Metric (scope metrics:read). */
|
|
765
|
+
submitters: (slug: string) => Promise<Submitter[]>;
|
|
766
|
+
/** Adds and removes up to 20 Submitters each (scope metrics:edit), when the key's creator owns the Metric or is its
|
|
767
|
+
* Editor. Each person added gets a first Prompt. Answers who submits now. */
|
|
768
|
+
setSubmitters: (slug: string, change: {
|
|
769
|
+
add?: string[];
|
|
770
|
+
remove?: string[];
|
|
771
|
+
}) => Promise<{
|
|
772
|
+
items: Submitter[];
|
|
773
|
+
added: number;
|
|
774
|
+
removed: number;
|
|
775
|
+
}>;
|
|
776
|
+
/** What makes a value unusual in the Metric's Workflow (scope metrics:read). */
|
|
777
|
+
unusualValueCheck: (slug: string) => Promise<UnusualValueCheck>;
|
|
778
|
+
/** Changes the check step of the Metric's Workflow, and so of every Metric sharing it (scope metrics:edit); only
|
|
779
|
+
* when the key's creator owns the Workflow. */
|
|
780
|
+
setUnusualValueCheck: (slug: string, change: {
|
|
781
|
+
change_pct?: number;
|
|
782
|
+
outside_target?: boolean;
|
|
783
|
+
}) => Promise<UnusualValueCheck>;
|
|
784
|
+
};
|
|
785
|
+
/** A Metric's Target Series: target values for single periods, such as a monthly budget. Where a period has none,
|
|
786
|
+
* the Metric's Target Range applies. */
|
|
787
|
+
readonly targetSeries: {
|
|
788
|
+
/** Every period that has a value, oldest first. */
|
|
789
|
+
list: (slug: string) => Promise<SeriesValue[]>;
|
|
790
|
+
/** Sets or removes 1 to SERIES_ITEMS_MAX periods (their first days): a number sets one, null removes it. All
|
|
791
|
+
* or nothing: a refused item (ZiffrError 422) writes none. Safe to repeat. */
|
|
792
|
+
set: (slug: string, items: SeriesItem[]) => Promise<{
|
|
793
|
+
saved: number;
|
|
794
|
+
removed: number;
|
|
795
|
+
}>;
|
|
796
|
+
};
|
|
797
|
+
/** A Metric's Projections: values for the current period or later ones, from an outside forecast, always shown as
|
|
798
|
+
* projections. */
|
|
799
|
+
readonly projections: {
|
|
800
|
+
/** Every period that has a value, oldest first. */
|
|
801
|
+
list: (slug: string) => Promise<SeriesValue[]>;
|
|
802
|
+
/** Sets or removes 1 to SERIES_ITEMS_MAX periods (their first days): a number sets one, null removes it. All
|
|
803
|
+
* or nothing: a refused item (ZiffrError 422) writes none. Safe to repeat. */
|
|
804
|
+
set: (slug: string, items: SeriesItem[]) => Promise<{
|
|
805
|
+
saved: number;
|
|
806
|
+
removed: number;
|
|
807
|
+
}>;
|
|
256
808
|
};
|
|
257
809
|
/** A Metric's values. */
|
|
258
810
|
readonly observations: {
|
|
@@ -266,21 +818,155 @@ export declare class Ziffr {
|
|
|
266
818
|
idempotencyKey?: string;
|
|
267
819
|
}) => Promise<Submission>;
|
|
268
820
|
};
|
|
821
|
+
/** The Threads on one period of a Metric that the key's creator may read, with authors, times and words (scope
|
|
822
|
+
* metrics:read). `period` is the period's first day, YYYY-MM-DD. A period with none, and one whose Threads the creator
|
|
823
|
+
* may not read, answer the same: an empty list. */
|
|
824
|
+
thread: (slug: string, period: string) => Promise<ThreadAnswer>;
|
|
269
825
|
/** The month the workspace's fiscal year starts in (1 is January): where quarterly and yearly Metrics' periods start. */
|
|
270
826
|
workspace: () => Promise<Workspace>;
|
|
827
|
+
/** What the key's creator has to do, by day (scope metrics:read). `from` and `to` are days, YYYY-MM-DD, at most 90
|
|
828
|
+
* days apart; this week when left out. An Owner or Admin may name a teammate with `person_id` (from `people`). */
|
|
829
|
+
schedule: (span?: {
|
|
830
|
+
from?: string;
|
|
831
|
+
to?: string;
|
|
832
|
+
person_id?: string;
|
|
833
|
+
}) => Promise<Schedule>;
|
|
834
|
+
/** Finds Metrics by name, and "Metric + period" for words such as "churn march 2026" (scope metrics:read). Period
|
|
835
|
+
* results come first; `slug` and `period` are what `metrics.get` and `observations` take. */
|
|
836
|
+
find: (words: string) => Promise<Found[]>;
|
|
837
|
+
/** The workspace's Workflows, to find the one to ask about (scope metrics:read). */
|
|
838
|
+
readonly workflows: {
|
|
839
|
+
/** One page of Workflows. */
|
|
840
|
+
list: (options?: PageOptions) => Promise<Page<WorkflowName>>;
|
|
841
|
+
/** Every Workflow, page by page. */
|
|
842
|
+
all: () => AsyncGenerator<WorkflowName, any, any>;
|
|
843
|
+
/** A Workflow the key's creator owns, with its steps (scope metrics:read). */
|
|
844
|
+
get: (id: number) => Promise<WorkflowDetail>;
|
|
845
|
+
/** Makes a Workflow (scope workflows:write). An Approve or Tell step also needs workflows:people, which only a program's key can hold. */
|
|
846
|
+
create: (input: NewWorkflow) => Promise<WorkflowDetail>;
|
|
847
|
+
/** Changes a Workflow the key's creator owns (scope workflows:write). Without workflows:people, send Approve and Tell steps back as read. */
|
|
848
|
+
update: (id: number, patch: WorkflowPatch) => Promise<WorkflowDetail>;
|
|
849
|
+
/** Deletes a Workflow the key's creator owns (scope workflows:write). */
|
|
850
|
+
remove: (id: number) => Promise<{
|
|
851
|
+
removed: number;
|
|
852
|
+
}>;
|
|
853
|
+
/** How a Workflow's period is going, as the key's creator may see it (scope metrics:read): `period` is a period's
|
|
854
|
+
* first day, the newest one that has anything when left out. */
|
|
855
|
+
periodStatus: (id: number, period?: string) => Promise<PeriodStatus>;
|
|
856
|
+
};
|
|
271
857
|
/** The workspace's people and Contacts. */
|
|
272
858
|
readonly people: {
|
|
273
859
|
/** One page of people. */
|
|
274
860
|
list: (options?: PageOptions) => Promise<Page<Person>>;
|
|
275
861
|
/** Everyone, page by page. */
|
|
276
862
|
all: () => AsyncGenerator<Person, any, any>;
|
|
863
|
+
/** Adds a Contact: a person without a sign-in who only submits values (scope people:write; Owners and Admins).
|
|
864
|
+
* Answers with their id and name, never the details. */
|
|
865
|
+
addContact: (input: {
|
|
866
|
+
name: string;
|
|
867
|
+
email?: string;
|
|
868
|
+
slack_handle?: string;
|
|
869
|
+
phone?: string;
|
|
870
|
+
}) => Promise<{
|
|
871
|
+
id: string;
|
|
872
|
+
name: string;
|
|
873
|
+
contact: true;
|
|
874
|
+
}>;
|
|
875
|
+
/** Changes a member's Workspace Role (scope people:write); only Owners make or change Owners. */
|
|
876
|
+
setRole: (id: string, role: WorkspaceRole) => Promise<{
|
|
877
|
+
id: string;
|
|
878
|
+
role: WorkspaceRole;
|
|
879
|
+
}>;
|
|
880
|
+
/** Removes a Contact, or a member whose things go to `successor` (another member, not a Guest). Scope people:write. */
|
|
881
|
+
remove: (id: string, options?: {
|
|
882
|
+
successor?: string;
|
|
883
|
+
}) => Promise<{
|
|
884
|
+
removed: string;
|
|
885
|
+
}>;
|
|
277
886
|
};
|
|
887
|
+
/** Inviting people (scope people:write, Owners and Admins; only a program's own key, never an assistant's). */
|
|
888
|
+
readonly invitations: {
|
|
889
|
+
/** The open invitations, never with their secret links. */
|
|
890
|
+
list: () => Promise<Invitation[]>;
|
|
891
|
+
/** Invites an address with a role and emails it the link. */
|
|
892
|
+
invite: (input: {
|
|
893
|
+
email: string;
|
|
894
|
+
role: WorkspaceRole;
|
|
895
|
+
contact?: string;
|
|
896
|
+
}) => Promise<Invitation>;
|
|
897
|
+
/** Makes a link anyone can join by, as Member or Guest, for 7 days. Keep it as you would a password. */
|
|
898
|
+
link: (role: "member" | "guest") => Promise<{
|
|
899
|
+
url: string;
|
|
900
|
+
role: "member" | "guest";
|
|
901
|
+
}>;
|
|
902
|
+
/** Revokes an invitation or invite link. */
|
|
903
|
+
revoke: (id: number) => Promise<{
|
|
904
|
+
removed: number;
|
|
905
|
+
}>;
|
|
906
|
+
/** Emails an open invitation again. */
|
|
907
|
+
resend: (id: number) => Promise<{
|
|
908
|
+
id: number;
|
|
909
|
+
}>;
|
|
910
|
+
};
|
|
911
|
+
/** Requests to join the workspace by its domain (scope people:write, Owners and Admins). */
|
|
912
|
+
readonly joinRequests: {
|
|
913
|
+
/** The open requests. */
|
|
914
|
+
list: () => Promise<JoinRequest[]>;
|
|
915
|
+
/** Lets the person in as a Member (true) or declines (false). */
|
|
916
|
+
decide: (id: number, approve: boolean) => Promise<{
|
|
917
|
+
id: number;
|
|
918
|
+
approved: boolean;
|
|
919
|
+
}>;
|
|
920
|
+
};
|
|
921
|
+
/** Shares (scope shares:write; only a program's own key, never an assistant's). Only the owner shares. */
|
|
922
|
+
readonly shares: {
|
|
923
|
+
/** Who can see a Metric, dashboard or deck the key's creator sees, and why. */
|
|
924
|
+
who: (target: ShareTarget) => Promise<Audience>;
|
|
925
|
+
/** Shares it with a member or a Group as viewer or editor; a null role takes the Share away. */
|
|
926
|
+
set: (target: ShareTarget, to: ShareWith, role: "viewer" | "editor" | null) => Promise<{
|
|
927
|
+
type: string;
|
|
928
|
+
id: string | number;
|
|
929
|
+
person: string | null;
|
|
930
|
+
group: number | null;
|
|
931
|
+
role: "viewer" | "editor" | null;
|
|
932
|
+
}>;
|
|
933
|
+
/** The owner grants Viewer access to a request listed by `who` (true) or declines it (false). */
|
|
934
|
+
decide: (requestId: number, grant: boolean) => Promise<{
|
|
935
|
+
id: number;
|
|
936
|
+
granted: boolean;
|
|
937
|
+
}>;
|
|
938
|
+
};
|
|
939
|
+
/** The workspace's live Feeds by id and name, to name one as a Submitter (scope metrics:edit). */
|
|
940
|
+
feeds: () => Promise<{
|
|
941
|
+
id: string;
|
|
942
|
+
name: string;
|
|
943
|
+
}[]>;
|
|
278
944
|
/** The workspace's Groups. */
|
|
279
945
|
readonly groups: {
|
|
280
946
|
/** One page of Groups. */
|
|
281
947
|
list: (options?: PageOptions) => Promise<Page<Group>>;
|
|
282
948
|
/** Every Group, page by page. */
|
|
283
949
|
all: () => AsyncGenerator<Group, any, any>;
|
|
950
|
+
/** Makes a Group (scope groups:write; Owners and Admins; only a program's own key, never an assistant's). */
|
|
951
|
+
create: (name: string) => Promise<Group>;
|
|
952
|
+
/** Renames a Group; never Everyone. */
|
|
953
|
+
rename: (id: number, name: string) => Promise<Group>;
|
|
954
|
+
/** Deletes a Group; what was shared with it stops being shared. */
|
|
955
|
+
remove: (id: number) => Promise<{
|
|
956
|
+
removed: number;
|
|
957
|
+
}>;
|
|
958
|
+
/** Puts a member of the workspace into a Group. */
|
|
959
|
+
addMember: (id: number, person: string) => Promise<{
|
|
960
|
+
group: number;
|
|
961
|
+
person: string;
|
|
962
|
+
member: boolean;
|
|
963
|
+
}>;
|
|
964
|
+
/** Takes a member out of a Group. */
|
|
965
|
+
removeMember: (id: number, person: string) => Promise<{
|
|
966
|
+
group: number;
|
|
967
|
+
person: string;
|
|
968
|
+
member: boolean;
|
|
969
|
+
}>;
|
|
284
970
|
};
|
|
285
971
|
/** For a Feed Key (spec 0012): the Feed's Metrics, and recording values for them in batches. */
|
|
286
972
|
readonly feed: {
|
|
@@ -297,6 +983,53 @@ export declare class Ziffr {
|
|
|
297
983
|
replayed: boolean;
|
|
298
984
|
}>;
|
|
299
985
|
};
|
|
986
|
+
/** The Questions and Tasks of the key's creator (GLOSSARY: Action): listing needs actions:read, replying, closing,
|
|
987
|
+
* reopening and marking done actions:write, confirming or correcting in a Self-check values:submit and approving
|
|
988
|
+
* values:approve, which only a program's key holds. Each acts as the key's creator, on the Actions they may read. */
|
|
989
|
+
readonly actions: {
|
|
990
|
+
/** One page of the Actions waiting for the creator and those they asked. */
|
|
991
|
+
list: (options?: ActionListOptions) => Promise<Page<Action>>;
|
|
992
|
+
/** Every one of them, page by page. */
|
|
993
|
+
all: (options?: Omit<ActionListOptions, "cursor" | "limit">) => AsyncGenerator<Action, any, any>;
|
|
994
|
+
/** Replies in an Action's Thread, with a Correction (a value) when given. Only words: never decides a Self-check or an Approval. */
|
|
995
|
+
reply: (id: number, body: string, correction?: number) => Promise<Action>;
|
|
996
|
+
/** Closes an Action the creator asked. */
|
|
997
|
+
close: (id: number) => Promise<Action>;
|
|
998
|
+
/** Reopens one the creator asked. */
|
|
999
|
+
reopen: (id: number) => Promise<Action>;
|
|
1000
|
+
/** Marks the creator's own open Task done. */
|
|
1001
|
+
done: (id: number) => Promise<Action>;
|
|
1002
|
+
/** Confirms the creator's own value in a Self-check. */
|
|
1003
|
+
confirm: (id: number) => Promise<Action>;
|
|
1004
|
+
/** Corrects the creator's own value in a Self-check. */
|
|
1005
|
+
correct: (id: number, value: number) => Promise<Action>;
|
|
1006
|
+
/** Approves a value waiting for the creator (scope values:approve, a program's key only). Refused for their own value. */
|
|
1007
|
+
approve: (id: number) => Promise<Action>;
|
|
1008
|
+
/** Sends a value back with what to check (scope values:approve, a program's key only). */
|
|
1009
|
+
sendBack: (id: number, comment: string) => Promise<Action>;
|
|
1010
|
+
};
|
|
1011
|
+
/** The key's creator's own Alerts (GLOSSARY: Alert): never anyone else's. Reading needs metrics:read, the rest the
|
|
1012
|
+
* scope alerts:write. */
|
|
1013
|
+
readonly alerts: {
|
|
1014
|
+
/** Their Alerts on Metrics they still see, newest first; of one Metric when its slug is given. At most 20. */
|
|
1015
|
+
list: (options?: {
|
|
1016
|
+
metric?: string;
|
|
1017
|
+
}) => Promise<Alert[]>;
|
|
1018
|
+
/** Makes one for the key's creator. Refused (ZiffrError 422) at a limit or for a condition the Metric cannot give. */
|
|
1019
|
+
create: (input: NewAlert) => Promise<Alert>;
|
|
1020
|
+
/** Changes one of theirs: condition, way of delivery, option or pause. */
|
|
1021
|
+
update: (id: number, patch: AlertPatch) => Promise<Alert>;
|
|
1022
|
+
/** Removes one of theirs. */
|
|
1023
|
+
remove: (id: number) => Promise<{
|
|
1024
|
+
removed: number;
|
|
1025
|
+
}>;
|
|
1026
|
+
};
|
|
1027
|
+
/** Share Proposals (GLOSSARY: Share Proposal): prepares a share for the key's creator to confirm in Ziffr. It shares and sends
|
|
1028
|
+
* nothing; there is no call to confirm it, because only the person can, with their own sign-in. Needs shares:propose and dashboards:read. */
|
|
1029
|
+
readonly shareProposals: {
|
|
1030
|
+
/** Proposes a View Link (an address, an end date, a message) or a Share (a person or a Group) of a dashboard the creator owns. */
|
|
1031
|
+
create: (input: NewShareProposal) => Promise<ShareProposal>;
|
|
1032
|
+
};
|
|
300
1033
|
/** The dashboards the key's creator sees (scope dashboards:read), and building them as the creator (scope
|
|
301
1034
|
* dashboards:write). A key changes only what its creator may change, and never shares or deletes. */
|
|
302
1035
|
readonly dashboards: {
|
|
@@ -350,6 +1083,38 @@ export declare class Ziffr {
|
|
|
350
1083
|
/** Changes a Finding's words. */
|
|
351
1084
|
updateFinding: (dashboardId: number, findingId: number, words: FindingWords) => Promise<Widget>;
|
|
352
1085
|
};
|
|
1086
|
+
/** Snapshots (ticket #435): reading needs dashboards:read, taking one dashboards:write. A key reads only what its
|
|
1087
|
+
* creator may open, and never shows, deletes or rewrites a Snapshot. */
|
|
1088
|
+
readonly snapshots: {
|
|
1089
|
+
/** A dashboard's Snapshots, newest period first (at most 200). */
|
|
1090
|
+
list: (dashboardId: number) => Promise<SnapshotSummary[]>;
|
|
1091
|
+
/** One Snapshot with the values it kept. */
|
|
1092
|
+
get: (id: number) => Promise<Snapshot>;
|
|
1093
|
+
/** Takes a Snapshot of a period that is over (`start` is its first day, yyyy-mm-dd). A draft until a person shows it;
|
|
1094
|
+
* ZiffrError 422 when the period is not over or one exists already. */
|
|
1095
|
+
take: (dashboardId: number, period: {
|
|
1096
|
+
kind: SnapshotKind;
|
|
1097
|
+
start: string;
|
|
1098
|
+
}) => Promise<SnapshotSummary>;
|
|
1099
|
+
};
|
|
1100
|
+
/** View Links to dashboards (ticket #435), all behind the scope view-links:write, which a key is given on purpose and
|
|
1101
|
+
* an assistant never is: a View Link publishes data to people outside the workspace. */
|
|
1102
|
+
readonly viewLinks: {
|
|
1103
|
+
/** A dashboard's View Links without their tokens. */
|
|
1104
|
+
list: (dashboardId: number) => Promise<ViewLink[]>;
|
|
1105
|
+
/** Makes one, ending on `expires` (yyyy-mm-dd, within 90 days). Its `token` and `url` are in this answer only. Not
|
|
1106
|
+
* idempotent: a repeated call makes another link. */
|
|
1107
|
+
create: (dashboardId: number, input: {
|
|
1108
|
+
expires: string;
|
|
1109
|
+
label?: string;
|
|
1110
|
+
frozen?: boolean;
|
|
1111
|
+
snapshot?: number;
|
|
1112
|
+
}) => Promise<MadeViewLink>;
|
|
1113
|
+
/** Revokes one at once and for good. */
|
|
1114
|
+
revoke: (id: number) => Promise<{
|
|
1115
|
+
revoked: number;
|
|
1116
|
+
}>;
|
|
1117
|
+
};
|
|
353
1118
|
/** What a key can build with (scope dashboards:read). */
|
|
354
1119
|
readonly templates: {
|
|
355
1120
|
/** The built-in views, the team's Widget Templates and the Dashboard Templates, or one kind of them. */
|
|
@@ -357,6 +1122,8 @@ export declare class Ziffr {
|
|
|
357
1122
|
kind?: Template["kind"];
|
|
358
1123
|
}) => Promise<Template[]>;
|
|
359
1124
|
};
|
|
1125
|
+
/** Reading (scope metrics:read) and setting (scope metrics:edit) one kind of series, the same for both. */
|
|
1126
|
+
private series;
|
|
360
1127
|
private get;
|
|
361
1128
|
private every;
|
|
362
1129
|
private request;
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// @ziffr/sdk (spec 0002, ticket #51; GLOSSARY: Access Key, Metric, Observation): typed calls to the Ziffr API. It
|
|
2
2
|
// knows only HTTP and the API's published shapes, nothing of the server. Safe by default: it waits out a 429 as the
|
|
3
3
|
// server's Retry-After says, and every submission carries an idempotency key, so a retry never records a value twice.
|
|
4
|
+
/** Most periods one call sets or removes in a Target Series or Projections. */
|
|
5
|
+
export const SERIES_ITEMS_MAX = 500;
|
|
4
6
|
/** At most this many items in one batch. */
|
|
5
7
|
export const FEED_BATCH_MAX = 500;
|
|
6
8
|
/** An error answer of the API, or a failure to reach it (status 0). `code` is stable; handle errors by it. */
|
|
@@ -42,10 +44,10 @@ export class Ziffr {
|
|
|
42
44
|
}
|
|
43
45
|
/** The Metrics the key's creator sees. */
|
|
44
46
|
metrics = {
|
|
45
|
-
/** One page of Metrics. */
|
|
46
|
-
list: (options = {}) => this.get("/metrics", options),
|
|
47
|
-
/** Every Metric, page by page. */
|
|
48
|
-
all: () => this.every((cursor) => this.metrics.list({ cursor, limit: 100 })),
|
|
47
|
+
/** One page of Metrics: those in use, or with `archived` only the Archived Metrics. */
|
|
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
51
|
/** One Metric's description. */
|
|
50
52
|
get: (slug) => this.get(`/metrics/${encodeURIComponent(slug)}`),
|
|
51
53
|
/** Creates a Metric owned by the key's creator (scope metrics:write). A fresh idempotency key is sent unless one is
|
|
@@ -57,7 +59,31 @@ export class Ziffr {
|
|
|
57
59
|
/** Deletes a Metric the key's creator owns (scope metrics:write), repeating its exact name to confirm. Refused
|
|
58
60
|
* (ZiffrError 422) while another Metric's formula, a widget, a deck or a working View Link uses it. */
|
|
59
61
|
delete: async (slug, confirmName) => (await this.request("DELETE", `/metrics/${encodeURIComponent(slug)}`, { confirm: confirmName })).body,
|
|
62
|
+
/** Archives a Metric (scope metrics:write), when the key's creator is an Owner or Admin or owns it: its values and
|
|
63
|
+
* history stay, it is asked for nothing and takes no values. Answers the Metric as it is now. */
|
|
64
|
+
archive: async (slug) => (await this.request("POST", `/metrics/${encodeURIComponent(slug)}/archive`)).body,
|
|
65
|
+
/** Brings an Archived Metric back (scope metrics:write), under the same rule. Answers the Metric as it is now. */
|
|
66
|
+
restore: async (slug) => (await this.request("POST", `/metrics/${encodeURIComponent(slug)}/restore`)).body,
|
|
67
|
+
/** Changes a Metric's Polarity, Target Range or Attainment method (scope metrics:edit), when
|
|
68
|
+
* the key's creator owns it or is its Editor. Answers the Metric as it is now. */
|
|
69
|
+
update: async (slug, patch) => (await this.request("PATCH", `/metrics/${encodeURIComponent(slug)}`, undefined, patch)).body,
|
|
70
|
+
/** Who submits to a Metric (scope metrics:read). */
|
|
71
|
+
submitters: async (slug) => (await this.get(`/metrics/${encodeURIComponent(slug)}/submitters`)).items,
|
|
72
|
+
/** Adds and removes up to 20 Submitters each (scope metrics:edit), when the key's creator owns the Metric or is its
|
|
73
|
+
* Editor. Each person added gets a first Prompt. Answers who submits now. */
|
|
74
|
+
setSubmitters: async (slug, change) => (await this.request("POST", `/metrics/${encodeURIComponent(slug)}/submitters`, undefined, change)).body,
|
|
75
|
+
/** What makes a value unusual in the Metric's Workflow (scope metrics:read). */
|
|
76
|
+
unusualValueCheck: (slug) => this.get(`/metrics/${encodeURIComponent(slug)}/unusual-value-check`),
|
|
77
|
+
/** Changes the check step of the Metric's Workflow, and so of every Metric sharing it (scope metrics:edit); only
|
|
78
|
+
* when the key's creator owns the Workflow. */
|
|
79
|
+
setUnusualValueCheck: async (slug, change) => (await this.request("PATCH", `/metrics/${encodeURIComponent(slug)}/unusual-value-check`, undefined, change)).body,
|
|
60
80
|
};
|
|
81
|
+
/** A Metric's Target Series: target values for single periods, such as a monthly budget. Where a period has none,
|
|
82
|
+
* the Metric's Target Range applies. */
|
|
83
|
+
targetSeries = this.series("target-series");
|
|
84
|
+
/** A Metric's Projections: values for the current period or later ones, from an outside forecast, always shown as
|
|
85
|
+
* projections. */
|
|
86
|
+
projections = this.series("projections");
|
|
61
87
|
/** A Metric's values. */
|
|
62
88
|
observations = {
|
|
63
89
|
/** One page of a Metric's values, oldest first. */
|
|
@@ -71,21 +97,97 @@ export class Ziffr {
|
|
|
71
97
|
return { ...body, replayed: headers.get("idempotent-replayed") === "true" };
|
|
72
98
|
},
|
|
73
99
|
};
|
|
100
|
+
/** The Threads on one period of a Metric that the key's creator may read, with authors, times and words (scope
|
|
101
|
+
* metrics:read). `period` is the period's first day, YYYY-MM-DD. A period with none, and one whose Threads the creator
|
|
102
|
+
* may not read, answer the same: an empty list. */
|
|
103
|
+
thread = (slug, period) => this.get(`/metrics/${encodeURIComponent(slug)}/thread`, { period });
|
|
74
104
|
/** The month the workspace's fiscal year starts in (1 is January): where quarterly and yearly Metrics' periods start. */
|
|
75
105
|
workspace = () => this.get("/workspace");
|
|
106
|
+
/** What the key's creator has to do, by day (scope metrics:read). `from` and `to` are days, YYYY-MM-DD, at most 90
|
|
107
|
+
* days apart; this week when left out. An Owner or Admin may name a teammate with `person_id` (from `people`). */
|
|
108
|
+
schedule = (span = {}) => this.get("/schedule", span);
|
|
109
|
+
/** Finds Metrics by name, and "Metric + period" for words such as "churn march 2026" (scope metrics:read). Period
|
|
110
|
+
* results come first; `slug` and `period` are what `metrics.get` and `observations` take. */
|
|
111
|
+
find = async (words) => (await this.get("/find", { q: words })).items;
|
|
112
|
+
/** The workspace's Workflows, to find the one to ask about (scope metrics:read). */
|
|
113
|
+
workflows = {
|
|
114
|
+
/** One page of Workflows. */
|
|
115
|
+
list: (options = {}) => this.get("/workflows", options),
|
|
116
|
+
/** Every Workflow, page by page. */
|
|
117
|
+
all: () => this.every((cursor) => this.workflows.list({ cursor, limit: 100 })),
|
|
118
|
+
/** A Workflow the key's creator owns, with its steps (scope metrics:read). */
|
|
119
|
+
get: (id) => this.get(`/workflows/${id}`),
|
|
120
|
+
/** Makes a Workflow (scope workflows:write). An Approve or Tell step also needs workflows:people, which only a program's key can hold. */
|
|
121
|
+
create: async (input) => (await this.request("POST", "/workflows", undefined, input)).body,
|
|
122
|
+
/** Changes a Workflow the key's creator owns (scope workflows:write). Without workflows:people, send Approve and Tell steps back as read. */
|
|
123
|
+
update: async (id, patch) => (await this.request("PATCH", `/workflows/${id}`, undefined, patch)).body,
|
|
124
|
+
/** Deletes a Workflow the key's creator owns (scope workflows:write). */
|
|
125
|
+
remove: async (id) => (await this.request("DELETE", `/workflows/${id}`)).body,
|
|
126
|
+
/** How a Workflow's period is going, as the key's creator may see it (scope metrics:read): `period` is a period's
|
|
127
|
+
* first day, the newest one that has anything when left out. */
|
|
128
|
+
periodStatus: (id, period) => this.get(`/workflows/${id}/period-status`, period ? { period } : {}),
|
|
129
|
+
};
|
|
76
130
|
/** The workspace's people and Contacts. */
|
|
77
131
|
people = {
|
|
78
132
|
/** One page of people. */
|
|
79
133
|
list: (options = {}) => this.get("/people", options),
|
|
80
134
|
/** Everyone, page by page. */
|
|
81
135
|
all: () => this.every((cursor) => this.people.list({ cursor, limit: 100 })),
|
|
136
|
+
/** Adds a Contact: a person without a sign-in who only submits values (scope people:write; Owners and Admins).
|
|
137
|
+
* Answers with their id and name, never the details. */
|
|
138
|
+
addContact: async (input) => (await this.request("POST", "/people", undefined, input)).body,
|
|
139
|
+
/** Changes a member's Workspace Role (scope people:write); only Owners make or change Owners. */
|
|
140
|
+
setRole: async (id, role) => (await this.request("PATCH", `/people/${encodeURIComponent(id)}`, undefined, { role })).body,
|
|
141
|
+
/** Removes a Contact, or a member whose things go to `successor` (another member, not a Guest). Scope people:write. */
|
|
142
|
+
remove: async (id, options = {}) => (await this.request("DELETE", `/people/${encodeURIComponent(id)}`, options.successor ? { successor: options.successor } : undefined)).body,
|
|
143
|
+
};
|
|
144
|
+
/** Inviting people (scope people:write, Owners and Admins; only a program's own key, never an assistant's). */
|
|
145
|
+
invitations = {
|
|
146
|
+
/** The open invitations, never with their secret links. */
|
|
147
|
+
list: async () => (await this.get("/invitations")).items,
|
|
148
|
+
/** Invites an address with a role and emails it the link. */
|
|
149
|
+
invite: async (input) => (await this.request("POST", "/invitations", undefined, input)).body,
|
|
150
|
+
/** Makes a link anyone can join by, as Member or Guest, for 7 days. Keep it as you would a password. */
|
|
151
|
+
link: async (role) => (await this.request("POST", "/invitations/links", undefined, { role })).body,
|
|
152
|
+
/** Revokes an invitation or invite link. */
|
|
153
|
+
revoke: async (id) => (await this.request("DELETE", `/invitations/${id}`)).body,
|
|
154
|
+
/** Emails an open invitation again. */
|
|
155
|
+
resend: async (id) => (await this.request("POST", `/invitations/${id}/resend`)).body,
|
|
156
|
+
};
|
|
157
|
+
/** Requests to join the workspace by its domain (scope people:write, Owners and Admins). */
|
|
158
|
+
joinRequests = {
|
|
159
|
+
/** The open requests. */
|
|
160
|
+
list: async () => (await this.get("/join-requests")).items,
|
|
161
|
+
/** Lets the person in as a Member (true) or declines (false). */
|
|
162
|
+
decide: async (id, approve) => (await this.request("POST", `/join-requests/${id}`, undefined, { approve })).body,
|
|
82
163
|
};
|
|
164
|
+
/** Shares (scope shares:write; only a program's own key, never an assistant's). Only the owner shares. */
|
|
165
|
+
shares = {
|
|
166
|
+
/** Who can see a Metric, dashboard or deck the key's creator sees, and why. */
|
|
167
|
+
who: (target) => this.get("/shares", { type: target.type, id: String(target.id) }),
|
|
168
|
+
/** Shares it with a member or a Group as viewer or editor; a null role takes the Share away. */
|
|
169
|
+
set: async (target, to, role) => (await this.request("POST", "/shares", undefined, { ...target, ...to, role })).body,
|
|
170
|
+
/** The owner grants Viewer access to a request listed by `who` (true) or declines it (false). */
|
|
171
|
+
decide: async (requestId, grant) => (await this.request("POST", `/shares/requests/${requestId}`, undefined, { grant })).body,
|
|
172
|
+
};
|
|
173
|
+
/** The workspace's live Feeds by id and name, to name one as a Submitter (scope metrics:edit). */
|
|
174
|
+
feeds = async () => (await this.get("/feeds")).items;
|
|
83
175
|
/** The workspace's Groups. */
|
|
84
176
|
groups = {
|
|
85
177
|
/** One page of Groups. */
|
|
86
178
|
list: (options = {}) => this.get("/groups", options),
|
|
87
179
|
/** Every Group, page by page. */
|
|
88
180
|
all: () => this.every((cursor) => this.groups.list({ cursor, limit: 100 })),
|
|
181
|
+
/** Makes a Group (scope groups:write; Owners and Admins; only a program's own key, never an assistant's). */
|
|
182
|
+
create: async (name) => (await this.request("POST", "/groups", undefined, { name })).body,
|
|
183
|
+
/** Renames a Group; never Everyone. */
|
|
184
|
+
rename: async (id, name) => (await this.request("PATCH", `/groups/${id}`, undefined, { name })).body,
|
|
185
|
+
/** Deletes a Group; what was shared with it stops being shared. */
|
|
186
|
+
remove: async (id) => (await this.request("DELETE", `/groups/${id}`)).body,
|
|
187
|
+
/** Puts a member of the workspace into a Group. */
|
|
188
|
+
addMember: async (id, person) => (await this.request("POST", `/groups/${id}/members`, undefined, { person })).body,
|
|
189
|
+
/** Takes a member out of a Group. */
|
|
190
|
+
removeMember: async (id, person) => (await this.request("DELETE", `/groups/${id}/members/${encodeURIComponent(person)}`)).body,
|
|
89
191
|
};
|
|
90
192
|
/** For a Feed Key (spec 0012): the Feed's Metrics, and recording values for them in batches. */
|
|
91
193
|
feed = {
|
|
@@ -102,6 +204,49 @@ export class Ziffr {
|
|
|
102
204
|
return { results: body.results, replayed: headers.get("idempotent-replayed") === "true" };
|
|
103
205
|
},
|
|
104
206
|
};
|
|
207
|
+
/** The Questions and Tasks of the key's creator (GLOSSARY: Action): listing needs actions:read, replying, closing,
|
|
208
|
+
* reopening and marking done actions:write, confirming or correcting in a Self-check values:submit and approving
|
|
209
|
+
* values:approve, which only a program's key holds. Each acts as the key's creator, on the Actions they may read. */
|
|
210
|
+
actions = {
|
|
211
|
+
/** One page of the Actions waiting for the creator and those they asked. */
|
|
212
|
+
list: (options = {}) => this.get("/actions", options),
|
|
213
|
+
/** Every one of them, page by page. */
|
|
214
|
+
all: (options = {}) => this.every((cursor) => this.actions.list({ ...options, cursor, limit: 100 })),
|
|
215
|
+
/** Replies in an Action's Thread, with a Correction (a value) when given. Only words: never decides a Self-check or an Approval. */
|
|
216
|
+
reply: async (id, body, correction) => (await this.request("POST", `/actions/${id}/replies`, undefined, correction === undefined ? { body } : { body, correction })).body,
|
|
217
|
+
/** Closes an Action the creator asked. */
|
|
218
|
+
close: async (id) => (await this.request("PATCH", `/actions/${id}`, undefined, { status: "closed" })).body,
|
|
219
|
+
/** Reopens one the creator asked. */
|
|
220
|
+
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`)).body,
|
|
223
|
+
/** Confirms the creator's own value in a Self-check. */
|
|
224
|
+
confirm: async (id) => (await this.request("POST", `/actions/${id}/self-check`, undefined, { decision: "confirm" })).body,
|
|
225
|
+
/** Corrects the creator's own value in a Self-check. */
|
|
226
|
+
correct: async (id, value) => (await this.request("POST", `/actions/${id}/self-check`, undefined, { decision: "correct", value })).body,
|
|
227
|
+
/** Approves a value waiting for the creator (scope values:approve, a program's key only). Refused for their own value. */
|
|
228
|
+
approve: async (id) => (await this.request("POST", `/actions/${id}/approval`, undefined, { decision: "approve" })).body,
|
|
229
|
+
/** Sends a value back with what to check (scope values:approve, a program's key only). */
|
|
230
|
+
sendBack: async (id, comment) => (await this.request("POST", `/actions/${id}/approval`, undefined, { decision: "send_back", comment })).body,
|
|
231
|
+
};
|
|
232
|
+
/** The key's creator's own Alerts (GLOSSARY: Alert): never anyone else's. Reading needs metrics:read, the rest the
|
|
233
|
+
* scope alerts:write. */
|
|
234
|
+
alerts = {
|
|
235
|
+
/** Their Alerts on Metrics they still see, newest first; of one Metric when its slug is given. At most 20. */
|
|
236
|
+
list: async (options = {}) => (await this.get("/alerts", options)).items,
|
|
237
|
+
/** Makes one for the key's creator. Refused (ZiffrError 422) at a limit or for a condition the Metric cannot give. */
|
|
238
|
+
create: async (input) => (await this.request("POST", "/alerts", undefined, input)).body,
|
|
239
|
+
/** Changes one of theirs: condition, way of delivery, option or pause. */
|
|
240
|
+
update: async (id, patch) => (await this.request("PATCH", `/alerts/${id}`, undefined, patch)).body,
|
|
241
|
+
/** Removes one of theirs. */
|
|
242
|
+
remove: async (id) => (await this.request("DELETE", `/alerts/${id}`)).body,
|
|
243
|
+
};
|
|
244
|
+
/** Share Proposals (GLOSSARY: Share Proposal): prepares a share for the key's creator to confirm in Ziffr. It shares and sends
|
|
245
|
+
* nothing; there is no call to confirm it, because only the person can, with their own sign-in. Needs shares:propose and dashboards:read. */
|
|
246
|
+
shareProposals = {
|
|
247
|
+
/** Proposes a View Link (an address, an end date, a message) or a Share (a person or a Group) of a dashboard the creator owns. */
|
|
248
|
+
create: async (input) => (await this.request("POST", "/share-proposals", undefined, input)).body,
|
|
249
|
+
};
|
|
105
250
|
/** The dashboards the key's creator sees (scope dashboards:read), and building them as the creator (scope
|
|
106
251
|
* dashboards:write). A key changes only what its creator may change, and never shares or deletes. */
|
|
107
252
|
dashboards = {
|
|
@@ -134,11 +279,47 @@ export class Ziffr {
|
|
|
134
279
|
/** Changes a Finding's words. */
|
|
135
280
|
updateFinding: async (dashboardId, findingId, words) => (await this.request("PATCH", `/dashboards/${dashboardId}/findings/${findingId}`, undefined, words)).body,
|
|
136
281
|
};
|
|
282
|
+
/** Snapshots (ticket #435): reading needs dashboards:read, taking one dashboards:write. A key reads only what its
|
|
283
|
+
* creator may open, and never shows, deletes or rewrites a Snapshot. */
|
|
284
|
+
snapshots = {
|
|
285
|
+
/** A dashboard's Snapshots, newest period first (at most 200). */
|
|
286
|
+
list: async (dashboardId) => (await this.get(`/dashboards/${dashboardId}/snapshots`)).items,
|
|
287
|
+
/** One Snapshot with the values it kept. */
|
|
288
|
+
get: (id) => this.get(`/snapshots/${id}`),
|
|
289
|
+
/** Takes a Snapshot of a period that is over (`start` is its first day, yyyy-mm-dd). A draft until a person shows it;
|
|
290
|
+
* ZiffrError 422 when the period is not over or one exists already. */
|
|
291
|
+
take: async (dashboardId, period) => (await this.request("POST", `/dashboards/${dashboardId}/snapshots`, undefined, period)).body,
|
|
292
|
+
};
|
|
293
|
+
/** View Links to dashboards (ticket #435), all behind the scope view-links:write, which a key is given on purpose and
|
|
294
|
+
* an assistant never is: a View Link publishes data to people outside the workspace. */
|
|
295
|
+
viewLinks = {
|
|
296
|
+
/** A dashboard's View Links without their tokens. */
|
|
297
|
+
list: async (dashboardId) => (await this.get(`/dashboards/${dashboardId}/view-links`)).items,
|
|
298
|
+
/** Makes one, ending on `expires` (yyyy-mm-dd, within 90 days). Its `token` and `url` are in this answer only. Not
|
|
299
|
+
* idempotent: a repeated call makes another link. */
|
|
300
|
+
create: async (dashboardId, input) => (await this.request("POST", `/dashboards/${dashboardId}/view-links`, undefined, input)).body,
|
|
301
|
+
/** Revokes one at once and for good. */
|
|
302
|
+
revoke: async (id) => (await this.request("DELETE", `/view-links/${id}`)).body,
|
|
303
|
+
};
|
|
137
304
|
/** What a key can build with (scope dashboards:read). */
|
|
138
305
|
templates = {
|
|
139
306
|
/** The built-in views, the team's Widget Templates and the Dashboard Templates, or one kind of them. */
|
|
140
307
|
all: async (options = {}) => (await this.get("/templates", options)).items,
|
|
141
308
|
};
|
|
309
|
+
/** Reading (scope metrics:read) and setting (scope metrics:edit) one kind of series, the same for both. */
|
|
310
|
+
series(path) {
|
|
311
|
+
return {
|
|
312
|
+
/** Every period that has a value, oldest first. */
|
|
313
|
+
list: async (slug) => (await this.get(`/metrics/${encodeURIComponent(slug)}/${path}`)).items,
|
|
314
|
+
/** Sets or removes 1 to SERIES_ITEMS_MAX periods (their first days): a number sets one, null removes it. All
|
|
315
|
+
* or nothing: a refused item (ZiffrError 422) writes none. Safe to repeat. */
|
|
316
|
+
set: async (slug, items) => {
|
|
317
|
+
if (!items.length || items.length > SERIES_ITEMS_MAX)
|
|
318
|
+
throw new Error(`Send 1 to ${SERIES_ITEMS_MAX} items.`);
|
|
319
|
+
return (await this.request("POST", `/metrics/${encodeURIComponent(slug)}/${path}`, undefined, { items })).body;
|
|
320
|
+
},
|
|
321
|
+
};
|
|
322
|
+
}
|
|
142
323
|
async get(path, query = {}) {
|
|
143
324
|
return (await this.request("GET", path, query)).body;
|
|
144
325
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ziffr/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
4
4
|
"description": "Call the Ziffr API from TypeScript: read Metrics and their values, submit values.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"typescript": "^5",
|
|
34
34
|
"typescript-eslint": "^8.72.2",
|
|
35
35
|
"vitest": "^4.1.12",
|
|
36
|
-
"@ziffr/core": "0.
|
|
36
|
+
"@ziffr/core": "0.11.0"
|
|
37
37
|
},
|
|
38
38
|
"scripts": {
|
|
39
39
|
"build": "tsc -p tsconfig.build.json",
|