@ziffr/sdk 0.0.0-stage → 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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Stefan Sonntag
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,66 @@
1
- # Temporary Holding Version
1
+ # @ziffr/sdk
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Call the [Ziffr](https://github.com/ziffr/ziffr) API from TypeScript or JavaScript: read the Metrics an Access Key may see and their values, and submit values. MIT licensed, no dependencies, Node 20 or later (or any runtime with `fetch`).
4
+
5
+ ## A first call
6
+
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
+ 2. Install and call:
9
+
10
+ ```sh
11
+ npm install @ziffr/sdk
12
+ ```
13
+
14
+ ```ts
15
+ import { Ziffr } from "@ziffr/sdk";
16
+
17
+ const ziffr = new Ziffr({ url: "https://ziffr.example.com", accessKey: process.env.ZIFFR_ACCESS_KEY! });
18
+
19
+ for await (const metric of ziffr.metrics.all()) console.log(metric.slug, metric.name);
20
+
21
+ const { items } = await ziffr.observations.list("revenue", { from: "2026-01-01", to: "2026-03-01" });
22
+ console.log(items.map((o) => `${o.period}: ${o.value}`));
23
+
24
+ const result = await ziffr.observations.submit("orders", { value: 42 });
25
+ console.log(result.status); // "recorded", or "awaiting_approval" for an unusual value
26
+ ```
27
+
28
+ ## What it does for you
29
+
30
+ - **Pages for you.** Every list has `list({ limit, cursor })` for one page and `all()` to iterate over every item.
31
+ - **Waits out limits.** On a 429 it waits as long as the server's `Retry-After` says and tries again, up to `maxRetries` (default 3) and `maxRetryWait` seconds (default 60). A longer wait, such as the daily limit on values, throws at once.
32
+ - **Never makes a Metric twice.** `metrics.create` sends a fresh idempotency key too; it needs a key with "Create metrics", and the Metric belongs to the key's creator.
33
+ - **Never records a value twice.** Each `submit` sends a fresh idempotency key, so its own retries are safe. To make retries across runs of your program safe too, pass your own: `submit("orders", { value: 42 }, { idempotencyKey: "orders-2026-11" })`. A repeat with the same key and value gets the first answer back, with `replayed: true`.
34
+ - **One kind of error.** Every failure is a `ZiffrError` with the HTTP `status` and the API's stable `code` (`not_found`, `forbidden`, `locked`, `rate_limited`, and so on; `network` when Ziffr could not be reached).
35
+
36
+ A key sees exactly what the person who made it sees, no more. A Metric it may not see is `not_found`, the same as one that does not exist.
37
+
38
+ ## Calls
39
+
40
+ | Call | API |
41
+ | --- | --- |
42
+ | `metrics.list(options)`, `metrics.all()` | `GET /api/v1/metrics` |
43
+ | `metrics.get(slug)` | `GET /api/v1/metrics/{slug}` |
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) |
51
+ | `observations.list(slug, { from, to, limit, cursor })`, `observations.all(slug, { from, to })` | `GET /api/v1/metrics/{slug}/observations` |
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 |
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
+ | `people.list(options)`, `people.all()` | `GET /api/v1/people` |
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` |
65
+
66
+ Fields, limits and errors of each are in the [API reference](https://github.com/ziffr/ziffr/blob/next/docs/reference/api.md).