@clocknext/sdk 0.14.0 → 0.15.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.
@@ -1,47 +0,0 @@
1
- import { activeQuery, filterByActive } from "../filters.js";
2
- import type { Transport } from "../http.js";
3
- import type { Composite, CreateCompositeInput } from "../types.js";
4
-
5
- /**
6
- * The `composites` resource — manage the org's composite *catalogue*: the
7
- * bundles of credits / outcomes / units that are grouped under one tag and
8
- * sold on a plan as a single thing. `/api/v1/composites`.
9
- *
10
- * Two things live elsewhere, deliberately:
11
- * • Tagging a signal into a composite occurrence is `composite: { ref, value }`
12
- * on the signal itself (see `signals.credit()` / `.outcome()` / `.unit()`).
13
- * • Closing an occurrence — the moment it is billed — is
14
- * `signals.completeComposite()`.
15
- *
16
- * This resource only defines what composites EXIST. Creating one prices it but
17
- * charges nobody: an invoice is built from plan components, never from a
18
- * catalogue entry, so a composite starts costing money only once a plan sells
19
- * it (`quantity × price`, frozen into the purchase at buy time).
20
- */
21
- export class Composites {
22
- constructor(private readonly transport: Transport) {}
23
-
24
- /** List composites. Pass `{ active: true }` for only the ones a signal can
25
- * still be tagged with — the default list INCLUDES archived ones, which
26
- * keep every row they already own.
27
- * `{ active: false }` returns only archived ones; omitting it returns
28
- * both. See `activeQuery` — the API itself only supports `true`. */
29
- async list(params: { active?: boolean } = {}): Promise<Composite[]> {
30
- const res = await this.transport.request<{ composites: Composite[] }>({
31
- method: "GET",
32
- path: "/api/v1/composites",
33
- query: { active: activeQuery(params.active) },
34
- });
35
- return filterByActive(res.composites, params.active);
36
- }
37
-
38
- /** Create a composite. `POST /api/v1/composites`. */
39
- async create(input: CreateCompositeInput): Promise<Composite> {
40
- const res = await this.transport.request<{ composite: Composite }>({
41
- method: "POST",
42
- path: "/api/v1/composites",
43
- body: input,
44
- });
45
- return res.composite;
46
- }
47
- }
@@ -1,76 +0,0 @@
1
- import { activeQuery, filterByActive } from "../filters.js";
2
- import type { Transport } from "../http.js";
3
- import type {
4
- CreateCreditInput,
5
- Credit,
6
- CreditDetail,
7
- UpdateCreditInput,
8
- } from "../types.js";
9
-
10
- /**
11
- * The `credits` resource — manage the org's credit *types* (the catalog). A
12
- * credit's stable `agentKey` is what you pass to `signals.credit()` when
13
- * recording usage against it. `/api/v1/credits`.
14
- */
15
- export class Credits {
16
- constructor(private readonly transport: Transport) {}
17
-
18
- /** List credit types. Pass `{ active: true }` to only return active ones.
19
- * `{ active: false }` returns only archived ones; omitting it returns
20
- * both. See `activeQuery` — the API itself only supports `true`. */
21
- async list(params: { active?: boolean } = {}): Promise<Credit[]> {
22
- const res = await this.transport.request<{ credits: Credit[] }>({
23
- method: "GET",
24
- path: "/api/v1/credits",
25
- query: { active: activeQuery(params.active) },
26
- });
27
- return filterByActive(res.credits, params.active);
28
- }
29
-
30
- /** Create a credit type; returns the created credit. `POST /api/v1/credits`. */
31
- async create(input: CreateCreditInput): Promise<Credit> {
32
- const res = await this.transport.request<{ credit: Credit }>({
33
- method: "POST",
34
- path: "/api/v1/credits",
35
- body: input,
36
- });
37
- return res.credit;
38
- }
39
-
40
- /** Fetch one credit type with usage stats. `GET /api/v1/credits/:id`. */
41
- async get(id: string): Promise<CreditDetail> {
42
- const res = await this.transport.request<{ credit: CreditDetail }>({
43
- method: "GET",
44
- path: `/api/v1/credits/${encodeURIComponent(id)}`,
45
- });
46
- return res.credit;
47
- }
48
-
49
- /** Update a credit type's definition; returns the updated credit. `PATCH /api/v1/credits/:id`. */
50
- async update(id: string, input: UpdateCreditInput): Promise<Credit> {
51
- const res = await this.transport.request<{ credit: Credit }>({
52
- method: "PATCH",
53
- path: `/api/v1/credits/${encodeURIComponent(id)}`,
54
- body: input,
55
- });
56
- return res.credit;
57
- }
58
-
59
- /** Activate or deactivate a credit type. */
60
- async setActive(id: string, isActive: boolean): Promise<Credit> {
61
- const res = await this.transport.request<{ credit: Credit }>({
62
- method: "PATCH",
63
- path: `/api/v1/credits/${encodeURIComponent(id)}`,
64
- body: { isActive },
65
- });
66
- return res.credit;
67
- }
68
-
69
- /** Delete a credit type. Refused while a customer is linked to it. */
70
- async delete(id: string): Promise<void> {
71
- await this.transport.request({
72
- method: "DELETE",
73
- path: `/api/v1/credits/${encodeURIComponent(id)}`,
74
- });
75
- }
76
- }
@@ -1,82 +0,0 @@
1
- import { activeQuery, filterByActive } from "../filters.js";
2
- import type { Transport } from "../http.js";
3
- import type {
4
- CreateOutcomeInput,
5
- Outcome,
6
- OutcomeDetail,
7
- UpdateOutcomeInput,
8
- } from "../types.js";
9
-
10
- /**
11
- * The `outcomes` resource — manage the org's outcome *types* (the catalog). An
12
- * outcome is a multi-step workflow. `/api/v1/outcomes`.
13
- *
14
- * Two distinct kinds of agent key, in separate namespaces, each unique per
15
- * organisation — do not conflate them:
16
- * - the OUTCOME's own `agentKey`, REQUIRED on `create()` and `update()`, which
17
- * names the outcome itself in the catalogue;
18
- * - each STEP's `agentKey`, which is what you pass to `signals.outcome()` to
19
- * report usage and to the outcome-adjust API.
20
- */
21
- export class Outcomes {
22
- constructor(private readonly transport: Transport) {}
23
-
24
- /** List outcome types. Pass `{ active: true }` to only return active ones.
25
- * `{ active: false }` returns only archived ones; omitting it returns
26
- * both. See `activeQuery` — the API itself only supports `true`. */
27
- async list(params: { active?: boolean } = {}): Promise<Outcome[]> {
28
- const res = await this.transport.request<{ outcomes: Outcome[] }>({
29
- method: "GET",
30
- path: "/api/v1/outcomes",
31
- query: { active: activeQuery(params.active) },
32
- });
33
- return filterByActive(res.outcomes, params.active);
34
- }
35
-
36
- /** Create an outcome type with its steps. `POST /api/v1/outcomes`. */
37
- async create(input: CreateOutcomeInput): Promise<Outcome> {
38
- const res = await this.transport.request<{ outcome: Outcome }>({
39
- method: "POST",
40
- path: "/api/v1/outcomes",
41
- body: input,
42
- });
43
- return res.outcome;
44
- }
45
-
46
- /** Fetch one outcome type with steps + stats. `GET /api/v1/outcomes/:id`. */
47
- async get(id: string): Promise<OutcomeDetail> {
48
- const res = await this.transport.request<{ outcome: OutcomeDetail }>({
49
- method: "GET",
50
- path: `/api/v1/outcomes/${encodeURIComponent(id)}`,
51
- });
52
- return res.outcome;
53
- }
54
-
55
- /** Update an outcome type's definition. `PATCH /api/v1/outcomes/:id`. */
56
- async update(id: string, input: UpdateOutcomeInput): Promise<Outcome> {
57
- const res = await this.transport.request<{ outcome: Outcome }>({
58
- method: "PATCH",
59
- path: `/api/v1/outcomes/${encodeURIComponent(id)}`,
60
- body: input,
61
- });
62
- return res.outcome;
63
- }
64
-
65
- /** Activate or deactivate an outcome type; returns the updated outcome. */
66
- async setActive(id: string, isActive: boolean): Promise<Outcome> {
67
- const res = await this.transport.request<{ outcome: Outcome }>({
68
- method: "PATCH",
69
- path: `/api/v1/outcomes/${encodeURIComponent(id)}`,
70
- body: { isActive },
71
- });
72
- return res.outcome;
73
- }
74
-
75
- /** Delete an outcome type. */
76
- async delete(id: string): Promise<void> {
77
- await this.transport.request({
78
- method: "DELETE",
79
- path: `/api/v1/outcomes/${encodeURIComponent(id)}`,
80
- });
81
- }
82
- }
@@ -1,76 +0,0 @@
1
- import { activeQuery, filterByActive } from "../filters.js";
2
- import type { Transport } from "../http.js";
3
- import type {
4
- CreateUnitInput,
5
- Unit,
6
- UnitDetail,
7
- UpdateUnitInput,
8
- } from "../types.js";
9
-
10
- /**
11
- * The `units` resource — manage the org's unit *types* (the catalog): named,
12
- * quantity-priced meters (FLAT / SLAB / VOLUME). Record consumption against a
13
- * unit with `signals.unit()`. `/api/v1/units-catalog`.
14
- */
15
- export class Units {
16
- constructor(private readonly transport: Transport) {}
17
-
18
- /** List unit types. Pass `{ active: true }` to only return active ones.
19
- * `{ active: false }` returns only archived ones; omitting it returns
20
- * both. See `activeQuery` — the API itself only supports `true`. */
21
- async list(params: { active?: boolean } = {}): Promise<Unit[]> {
22
- const res = await this.transport.request<{ units: Unit[] }>({
23
- method: "GET",
24
- path: "/api/v1/units-catalog",
25
- query: { active: activeQuery(params.active) },
26
- });
27
- return filterByActive(res.units, params.active);
28
- }
29
-
30
- /** Create a unit type. `POST /api/v1/units-catalog`. */
31
- async create(input: CreateUnitInput): Promise<Unit> {
32
- const res = await this.transport.request<{ unit: Unit }>({
33
- method: "POST",
34
- path: "/api/v1/units-catalog",
35
- body: input,
36
- });
37
- return res.unit;
38
- }
39
-
40
- /** Fetch one unit type with stats. `GET /api/v1/units-catalog/:id`. */
41
- async get(id: string): Promise<UnitDetail> {
42
- const res = await this.transport.request<{ unit: UnitDetail }>({
43
- method: "GET",
44
- path: `/api/v1/units-catalog/${encodeURIComponent(id)}`,
45
- });
46
- return res.unit;
47
- }
48
-
49
- /** Update a unit type's definition. `PATCH /api/v1/units-catalog/:id`. */
50
- async update(id: string, input: UpdateUnitInput): Promise<Unit> {
51
- const res = await this.transport.request<{ unit: Unit }>({
52
- method: "PATCH",
53
- path: `/api/v1/units-catalog/${encodeURIComponent(id)}`,
54
- body: input,
55
- });
56
- return res.unit;
57
- }
58
-
59
- /** Activate or deactivate a unit type. */
60
- async setActive(id: string, isActive: boolean): Promise<Unit> {
61
- const res = await this.transport.request<{ unit: Unit }>({
62
- method: "PATCH",
63
- path: `/api/v1/units-catalog/${encodeURIComponent(id)}`,
64
- body: { isActive },
65
- });
66
- return res.unit;
67
- }
68
-
69
- /** Delete a unit type. */
70
- async delete(id: string): Promise<void> {
71
- await this.transport.request({
72
- method: "DELETE",
73
- path: `/api/v1/units-catalog/${encodeURIComponent(id)}`,
74
- });
75
- }
76
- }
@@ -1,37 +0,0 @@
1
- import type { Transport } from "../http.js";
2
- import type { ThresholdKind, UpsertWebhookInput, Webhook } from "../types.js";
3
-
4
- /**
5
- * The `webhooks` resource — threshold alerts. At most one webhook per kind
6
- * (CREDIT / OUTCOME / WALLET); posting a kind again upserts it. `/api/v1/webhooks`.
7
- */
8
- export class Webhooks {
9
- constructor(private readonly transport: Transport) {}
10
-
11
- /** List configured webhooks. `GET /api/v1/webhooks`. */
12
- async list(): Promise<Webhook[]> {
13
- const res = await this.transport.request<{ webhooks: Webhook[] }>({
14
- method: "GET",
15
- path: "/api/v1/webhooks",
16
- });
17
- return res.webhooks;
18
- }
19
-
20
- /** Create or replace the webhook for a kind. `POST /api/v1/webhooks`. */
21
- async upsert(input: UpsertWebhookInput): Promise<Webhook> {
22
- const res = await this.transport.request<{ webhook: Webhook }>({
23
- method: "POST",
24
- path: "/api/v1/webhooks",
25
- body: input,
26
- });
27
- return res.webhook;
28
- }
29
-
30
- /** Delete the webhook for a kind (idempotent). `DELETE /api/v1/webhooks/:kind`. */
31
- async delete(kind: ThresholdKind): Promise<void> {
32
- await this.transport.request({
33
- method: "DELETE",
34
- path: `/api/v1/webhooks/${encodeURIComponent(kind)}`,
35
- });
36
- }
37
- }
@@ -1,33 +0,0 @@
1
- import { activeQuery, filterByActive } from "../filters.js";
2
- import type { Transport } from "../http.js";
3
- import type { Model, WorkspaceIdentity } from "../types.js";
4
-
5
- /**
6
- * The `workspace` resource — read-only introspection of the org behind the API
7
- * key. Grounds an integration (which workspace, and is it `sandbox` or `live`?)
8
- * and lists the models it may meter against. `/api/v1/me`, `/api/v1/models`.
9
- */
10
- export class Workspace {
11
- constructor(private readonly transport: Transport) {}
12
-
13
- /** Identify the org + key behind the request, incl. `sandbox` | `live`. */
14
- me(): Promise<WorkspaceIdentity> {
15
- return this.transport.request<WorkspaceIdentity>({
16
- method: "GET",
17
- path: "/api/v1/me",
18
- });
19
- }
20
-
21
- /** The org's enabled models with live prices. `{ active: true }` returns only
22
- * the models that can be metered right now.
23
- * `{ active: false }` returns only archived ones; omitting it returns
24
- * both. See `activeQuery` — the API itself only supports `true`. */
25
- async models(params: { active?: boolean } = {}): Promise<Model[]> {
26
- const res = await this.transport.request<{ models: Model[] }>({
27
- method: "GET",
28
- path: "/api/v1/models",
29
- query: { active: activeQuery(params.active) },
30
- });
31
- return filterByActive(res.models, params.active);
32
- }
33
- }