@allisall/sdk 0.1.0 → 0.2.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.
Files changed (60) hide show
  1. package/README.md +142 -4
  2. package/dist/client.d.ts +81 -37
  3. package/dist/client.js +136 -73
  4. package/dist/generated/openapi.d.ts +7724 -0
  5. package/dist/generated/openapi.js +4 -0
  6. package/dist/generated/operations.d.ts +37 -0
  7. package/dist/generated/operations.js +976 -0
  8. package/dist/index.d.ts +7 -2
  9. package/dist/index.js +1 -0
  10. package/dist/ingest.d.ts +1 -1
  11. package/dist/ingest.js +2 -2
  12. package/dist/money.d.ts +57 -0
  13. package/dist/money.js +284 -0
  14. package/dist/multipart.d.ts +27 -0
  15. package/dist/multipart.js +48 -0
  16. package/dist/options.d.ts +50 -0
  17. package/dist/options.js +73 -0
  18. package/dist/pagination.d.ts +55 -0
  19. package/dist/pagination.js +85 -0
  20. package/dist/request.d.ts +117 -0
  21. package/dist/request.js +363 -0
  22. package/dist/resources/agents.d.ts +51 -0
  23. package/dist/resources/agents.js +65 -0
  24. package/dist/resources/analytics.d.ts +42 -0
  25. package/dist/resources/analytics.js +68 -0
  26. package/dist/resources/api-keys.d.ts +54 -0
  27. package/dist/resources/api-keys.js +63 -0
  28. package/dist/resources/calculations.d.ts +78 -0
  29. package/dist/resources/calculations.js +111 -0
  30. package/dist/resources/clients.d.ts +65 -0
  31. package/dist/resources/clients.js +85 -0
  32. package/dist/resources/cost.d.ts +69 -0
  33. package/dist/resources/cost.js +89 -0
  34. package/dist/resources/dashboard.d.ts +24 -0
  35. package/dist/resources/dashboard.js +28 -0
  36. package/dist/resources/events.d.ts +47 -0
  37. package/dist/resources/events.js +69 -0
  38. package/dist/resources/health.d.ts +14 -0
  39. package/dist/resources/health.js +17 -0
  40. package/dist/resources/imports.d.ts +33 -0
  41. package/dist/resources/imports.js +37 -0
  42. package/dist/resources/outcome-types.d.ts +25 -0
  43. package/dist/resources/outcome-types.js +33 -0
  44. package/dist/resources/reports.d.ts +77 -0
  45. package/dist/resources/reports.js +103 -0
  46. package/dist/resources/value-models.d.ts +92 -0
  47. package/dist/resources/value-models.js +126 -0
  48. package/dist/runtime.d.ts +2 -0
  49. package/dist/runtime.js +2 -1
  50. package/dist/share.d.ts +52 -0
  51. package/dist/share.js +60 -0
  52. package/dist/transport.d.ts +54 -5
  53. package/dist/transport.js +81 -32
  54. package/dist/types.d.ts +135 -2
  55. package/dist/types.js +12 -3
  56. package/dist/unicode.d.ts +2 -0
  57. package/dist/unicode.js +11 -0
  58. package/dist/version.d.ts +1 -1
  59. package/dist/version.js +1 -1
  60. package/package.json +4 -3
package/README.md CHANGED
@@ -1,7 +1,10 @@
1
1
  # @allisall/sdk
2
2
 
3
- The allisall SDK for TypeScript and JavaScript. Version 0.1 sends events to
4
- the allisall API. It runs on Node 22 and later, and in current browsers.
3
+ The allisall SDK for TypeScript and JavaScript: a typed client for the
4
+ allisall API, covering events, imports, clients, agents, value models,
5
+ costs, analytics, calculations, reports, the dashboard, API keys and
6
+ shared reports. It runs on Node 22 and later, and in Chrome 114, Firefox
7
+ 135 and Safari 18.4 and later.
5
8
 
6
9
  ## Install
7
10
 
@@ -51,8 +54,11 @@ console.log(summary.accepted, summary.duplicates, summary.rejected);
51
54
 
52
55
  `ingest` takes any number of events. It sends them in batches, retries a
53
56
  failure worth retrying, and returns one summary for the whole list. A
54
- rejected event is listed in `summary.errors`, and the others are still
55
- stored. Write `cost` with `decimal()` to keep it exact.
57
+ rejected event is counted in `summary.rejected`, its problems are listed in
58
+ `summary.errors`, and the others are still stored. When
59
+ `summary.errors_truncated` is `true`, the list omits some problems, and a
60
+ rejected event may have no entry. Write `cost` with `decimal()` to keep it
61
+ exact.
56
62
 
57
63
  ### Set your own `event_id` for at-least-once delivery
58
64
 
@@ -63,6 +69,132 @@ for example from a queue that redelivers messages, set `event_id`
63
69
  yourself, such as to the message's id. The API then stores the event
64
70
  once, however often it arrives.
65
71
 
72
+ ## Call the API
73
+
74
+ The client groups its methods by resource: `client.clients`,
75
+ `client.agents`, `client.valueModels`, `client.cost`, `client.analytics`,
76
+ `client.calculations`, `client.reports`, `client.dashboard` and more. Each
77
+ method's documentation names the API operation it calls and the scope your
78
+ key needs.
79
+
80
+ ```ts
81
+ import { Allisall } from "@allisall/sdk";
82
+
83
+ const client = new Allisall();
84
+
85
+ const created = await client.clients.create({
86
+ name: "Acme Logistics",
87
+ status: "active",
88
+ client_key: "acme",
89
+ });
90
+
91
+ // An update is a merge patch: a member you leave out keeps its value, and
92
+ // null clears it.
93
+ const updated = await client.clients.update(created.id, {
94
+ renewal_date: "2026-12-31",
95
+ });
96
+ console.log(updated.name, updated.renewal_date);
97
+ ```
98
+
99
+ A call that creates something other than an API key sends an
100
+ `Idempotency-Key`, and sends the same key again on a retry, so a retry
101
+ never creates a second one. Amounts
102
+ of money come back as a `Decimal`, a string holding the exact amount.
103
+
104
+ ## Lists
105
+
106
+ A list method returns every item of every page when you iterate it with
107
+ `for await`. The SDK fetches each page as the loop reaches it:
108
+
109
+ ```ts
110
+ import { Allisall } from "@allisall/sdk";
111
+
112
+ const client = new Allisall();
113
+
114
+ for await (const agent of client.agents.list()) {
115
+ console.log(agent.agent_key, agent.name);
116
+ }
117
+ ```
118
+
119
+ To work a page at a time, await the call instead. The page holds its items
120
+ in `data`, and `hasNextPage()` and `getNextPage()` move through the rest:
121
+
122
+ ```ts
123
+ import { Allisall } from "@allisall/sdk";
124
+
125
+ const client = new Allisall();
126
+
127
+ const page = await client.agents.list({ limit: 50 });
128
+ console.log(page.data.length, page.hasNextPage());
129
+ ```
130
+
131
+ ## Errors
132
+
133
+ Every error from the API or the network is an `AllisallError`. An error
134
+ response from the API is an `ApiError`, with the HTTP `status`, the API's
135
+ error `code` and the `requestId` to quote when you report a problem.
136
+ Branch on `code`:
137
+
138
+ ```ts
139
+ import { Allisall, ApiError } from "@allisall/sdk";
140
+
141
+ const client = new Allisall();
142
+
143
+ try {
144
+ await client.clients.delete("CLIENT_ID");
145
+ } catch (error) {
146
+ if (error instanceof ApiError && error.code === "client_has_events") {
147
+ // Events carry the client's key, so mark the client churned instead.
148
+ await client.clients.update("CLIENT_ID", { status: "churned" });
149
+ } else {
150
+ throw error;
151
+ }
152
+ }
153
+ ```
154
+
155
+ A `ConnectionError` means no response arrived, after any retries. A few
156
+ errors are not an `AllisallError`. An argument the SDK cannot send, such
157
+ as an invalid `Date`, throws a `TypeError` before anything is sent. An
158
+ error thrown by your `tokenProvider` reaches you unchanged. A call you
159
+ abort with `signal` rejects with the signal's reason.
160
+
161
+ The SDK retries a failure worth retrying, twice by default; set
162
+ `maxRetries` on the client or on one call to change that. It retries only
163
+ a request that cannot take effect twice: a `GET`, `PUT` or `DELETE`;
164
+ ingest, whose event ids deduplicate; and a call that carries an
165
+ `Idempotency-Key`. The SDK sends that key, the same on every attempt,
166
+ when it creates anything but an API key and when it commits an import. A
167
+ `PATCH`, the calculation and report actions (validate, publish, reopen,
168
+ share and revoke), revoking or creating an API key, an import preview,
169
+ and setting a value model's line items are never retried. Setting line
170
+ items is guarded by the model's `version`, which refuses a repeat of a
171
+ write that already landed.
172
+
173
+ ## Sessions
174
+
175
+ Some operations record a person's decision, such as publishing a
176
+ calculation, sharing a report, or managing API keys. They take a signed-in
177
+ user's session token, and refuse any API key with `403`
178
+ `session_required`. Pass a `tokenProvider` that returns the current token.
179
+ The client calls it before every attempt, so a refreshed token is picked
180
+ up:
181
+
182
+ ```ts
183
+ import { Allisall } from "@allisall/sdk";
184
+
185
+ // Your sign-in library's way to read the signed-in user's session token.
186
+ declare function currentSessionToken(): Promise<string>;
187
+
188
+ const client = new Allisall({ tokenProvider: currentSessionToken });
189
+
190
+ const calculation = await client.calculations.publish("CALCULATION_ID");
191
+ console.log(calculation.state);
192
+ ```
193
+
194
+ `getSharedReport(shareToken)` reads a shared report with its share token.
195
+ It is a function rather than a client method, because it needs no API key
196
+ and no session.
197
+
66
198
  ## Browsers
67
199
 
68
200
  An API key in a browser can be read by anyone who loads the page. The
@@ -81,6 +213,12 @@ const client = new Allisall({
81
213
 
82
214
  Prefer calling the API from your server.
83
215
 
216
+ The SDK supports Chrome 114, Firefox 135 and Safari 18.4 and later. They are
217
+ the first releases that read and write JSON numbers exactly, which the SDK
218
+ needs for amounts of money. In an older browser, a call that sends a
219
+ `Decimal` or receives an amount fails with an `AllisallError` that names
220
+ the missing feature.
221
+
84
222
  ## Documentation
85
223
 
86
224
  See [https://docs.allisai.ai](https://docs.allisai.ai).
package/dist/client.d.ts CHANGED
@@ -1,5 +1,17 @@
1
+ import { Agents } from "./resources/agents.js";
2
+ import { Analytics } from "./resources/analytics.js";
3
+ import { ApiKeys } from "./resources/api-keys.js";
4
+ import { Calculations } from "./resources/calculations.js";
5
+ import { Clients } from "./resources/clients.js";
6
+ import { Cost } from "./resources/cost.js";
7
+ import { DashboardOperations } from "./resources/dashboard.js";
8
+ import { Events } from "./resources/events.js";
9
+ import { HealthOperations } from "./resources/health.js";
10
+ import { Imports } from "./resources/imports.js";
11
+ import { OutcomeTypes } from "./resources/outcome-types.js";
12
+ import { Reports } from "./resources/reports.js";
13
+ import { ValueModels } from "./resources/value-models.js";
1
14
  import { type FetchLike, type TokenProvider, type TransportConfig } from "./transport.js";
2
- import type { EventInput, IngestSummary } from "./types.js";
3
15
  /** The options of `new Allisall()`. Every one is optional. */
4
16
  export interface ClientOptions {
5
17
  /**
@@ -16,6 +28,10 @@ export interface ClientOptions {
16
28
  /**
17
29
  * The API's base URL, absolute, `http` or `https`. Defaults to
18
30
  * `AIA_BASE_URL` from the environment, then `https://api.allisai.ai`.
31
+ *
32
+ * In a browser it may also be a path on the page's own origin, starting
33
+ * with a single `/`, such as `/api` for a proxy. It is resolved against
34
+ * the page's address once, when the client is constructed.
19
35
  */
20
36
  baseURL?: string | undefined;
21
37
  /** The timeout of each attempt, in milliseconds. Defaults to 60,000. */
@@ -29,49 +45,77 @@ export interface ClientOptions {
29
45
  * read it. Defaults to `false`.
30
46
  */
31
47
  dangerouslyAllowBrowser?: boolean | undefined;
32
- }
33
- /** The options of one call. */
34
- export interface RequestOptions {
35
- /** Cancels the call, including any wait between retries. */
36
- signal?: AbortSignal | undefined;
37
- }
38
- /** The `events` operations. */
39
- declare class Events {
40
- #private;
41
- constructor(config: TransportConfig);
42
48
  /**
43
- * Ingests any number of events. They are sent in batches of at most 500
44
- * events and 5,000,000 bytes, one batch after another, each retried as
45
- * the client allows. Every event without an `event_id` gets a generated
46
- * one, so a retry never stores an event twice. Your objects are not
47
- * modified.
48
- *
49
- * An event too large to send even alone is not sent, and is reported as a
50
- * rejected row with the code `too_large`.
51
- *
52
- * @returns the combined outcome over the whole list.
53
- * @throws {IngestError} when a batch fails; the call stops there, and the
54
- * error carries the summary so far and every event from the failed batch
55
- * onward, to send again. A batch fails on an error response, on no
56
- * response, on the caller's cancellation, or when its token cannot be
57
- * had: an error from `tokenProvider`, or, in a browser without
58
- * `dangerouslyAllowBrowser`, a provider's token that is an API key. The
59
- * error is the `IngestError`'s `cause`.
60
- * @throws {TypeError} when an event cannot be encoded, before anything is sent.
49
+ * Headers sent on every request. They may not name `Authorization`,
50
+ * `Content-Type`, `Idempotency-Key` or `X-Request-Id`, which the SDK sets.
51
+ * A call's own `headers` are sent over them.
61
52
  */
62
- ingest(events: readonly EventInput[], options?: RequestOptions): Promise<IngestSummary>;
53
+ defaultHeaders?: Readonly<Record<string, string>> | undefined;
63
54
  }
64
- /** The allisall API client. Construct one and reuse it. */
55
+ /** The options a client and a shared-report call resolve alike. */
56
+ export type TransportOptions = Pick<ClientOptions, "baseURL" | "timeout" | "maxRetries" | "fetch">;
57
+ /**
58
+ * Resolves what every request needs apart from its credential and default
59
+ * headers: the base URL, timeout, retries, `fetch` and `User-Agent`, which
60
+ * a browser does not send.
61
+ *
62
+ * @throws {AllisallError} for a base URL, timeout or `maxRetries` the
63
+ * client refuses.
64
+ */
65
+ export declare function transportSettings(options: TransportOptions, browser: boolean): Pick<TransportConfig, "baseURL" | "timeout" | "maxRetries" | "fetch" | "userAgent">;
66
+ /**
67
+ * Checks the client's options and fixes everything a request needs.
68
+ *
69
+ * @throws {AllisallError} for an option the client refuses.
70
+ * @throws {TypeError} when `defaultHeaders` is not a plain object of
71
+ * header names and string values, names a header the SDK sets, or holds a
72
+ * name or value the platform cannot send.
73
+ */
74
+ export declare function transportConfig(options: ClientOptions): TransportConfig;
75
+ /**
76
+ * The allisall API client. Construct one and reuse it.
77
+ *
78
+ * Its operations are grouped by what they act on, one property per group,
79
+ * such as `client.clients.list()`. A failed call rejects with an `ApiError`
80
+ * for an error response, or a `ConnectionError` when no response arrived.
81
+ */
65
82
  export declare class Allisall {
66
- /** The `events` operations. */
83
+ /** Events: ingest, and the events behind a client's totals. */
67
84
  readonly events: Events;
85
+ /** CSV imports of events. */
86
+ readonly imports: Imports;
87
+ /** Clients, and the agents assigned to each. */
88
+ readonly clients: Clients;
89
+ /** Agents. */
90
+ readonly agents: Agents;
91
+ /** Value models, by their own id or by their client's, and value templates. */
92
+ readonly valueModels: ValueModels;
93
+ /** Outcome types, for the workspace or for one client. */
94
+ readonly outcomeTypes: OutcomeTypes;
95
+ /** Cost line items and the price table. */
96
+ readonly cost: Cost;
97
+ /** A client's value, cost, ROI and anomalies over a period. */
98
+ readonly analytics: Analytics;
99
+ /** Calculations, and the human steps that validate, publish and reopen them. */
100
+ readonly calculations: Calculations;
101
+ /** Reports on calculations, and the human steps that share and revoke them. */
102
+ readonly reports: Reports;
103
+ /** The workspace's month, and renewal readiness. */
104
+ readonly dashboard: DashboardOperations;
105
+ /** API keys, managed with a session token. */
106
+ readonly apiKeys: ApiKeys;
107
+ /** The API's liveness. */
108
+ readonly health: HealthOperations;
68
109
  /**
69
110
  * @throws {AllisallError} when there is no credential, or both an API key
70
- * and a token provider; when the base URL is not an absolute `http` or
71
- * `https` URL; when `maxRetries` is negative or `timeout` is not
72
- * positive; or when an API key is used in a browser without
73
- * `dangerouslyAllowBrowser`.
111
+ * and a token provider; when the base URL is neither an absolute `http`
112
+ * or `https` URL nor, in a browser, a path starting with a single `/`
113
+ * that resolves to the page's own origin; when `maxRetries` is negative
114
+ * or `timeout` is not positive; or when an API key is used in a browser
115
+ * without `dangerouslyAllowBrowser`.
116
+ * @throws {TypeError} when `defaultHeaders` is not a plain object of
117
+ * header names and string values, names a header the SDK sets, or holds a
118
+ * name or value the platform cannot send.
74
119
  */
75
120
  constructor(options?: ClientOptions);
76
121
  }
77
- export {};
package/dist/client.js CHANGED
@@ -1,12 +1,23 @@
1
1
  // The client: its options, and how the credential and the base URL are
2
2
  // resolved at construction.
3
3
  import { AllisallError } from "./errors.js";
4
- import { ingest, readIngestResult } from "./ingest.js";
5
- import { isBrowser, readEnv, userAgent } from "./runtime.js";
6
- import { BROWSER_KEY_MESSAGE, isPrintableCredential, post, } from "./transport.js";
4
+ import { DEFAULT_MAX_RETRIES, DEFAULT_TIMEOUT_MS, resolveHeaders, resolveMaxRetries, resolveTimeout, } from "./options.js";
5
+ import { Agents } from "./resources/agents.js";
6
+ import { Analytics } from "./resources/analytics.js";
7
+ import { ApiKeys } from "./resources/api-keys.js";
8
+ import { Calculations } from "./resources/calculations.js";
9
+ import { Clients } from "./resources/clients.js";
10
+ import { Cost } from "./resources/cost.js";
11
+ import { DashboardOperations } from "./resources/dashboard.js";
12
+ import { Events } from "./resources/events.js";
13
+ import { HealthOperations } from "./resources/health.js";
14
+ import { Imports } from "./resources/imports.js";
15
+ import { OutcomeTypes } from "./resources/outcome-types.js";
16
+ import { Reports } from "./resources/reports.js";
17
+ import { ValueModels } from "./resources/value-models.js";
18
+ import { globalValue, isBrowser, readEnv, userAgent } from "./runtime.js";
19
+ import { BROWSER_KEY_MESSAGE, isPrintableCredential, } from "./transport.js";
7
20
  const DEFAULT_BASE_URL = "https://api.allisai.ai";
8
- const DEFAULT_TIMEOUT_MS = 60_000;
9
- const DEFAULT_MAX_RETRIES = 2;
10
21
  function resolveCredential(options) {
11
22
  const { apiKey, tokenProvider } = options;
12
23
  if (apiKey !== undefined && tokenProvider !== undefined) {
@@ -38,93 +49,145 @@ function resolveCredential(options) {
38
49
  }
39
50
  throw new AllisallError("allisall: no credential; pass apiKey or tokenProvider, or set AIA_API_KEY");
40
51
  }
41
- function resolveBaseURL(option) {
52
+ /** Reads `globalThis.location.href`, where it exists. */
53
+ function pageAddress() {
54
+ const location = globalValue("location");
55
+ if (typeof location !== "object" || location === null)
56
+ return undefined;
57
+ const href = Reflect.get(location, "href");
58
+ return typeof href === "string" ? href : undefined;
59
+ }
60
+ /**
61
+ * Resolves the base URL: the option, else `AIA_BASE_URL`, else the API's
62
+ * own host. In a browser, a path starting with a single `/` is resolved
63
+ * against the page's address and must keep its origin.
64
+ *
65
+ * @throws {AllisallError} for a base URL the client refuses.
66
+ */
67
+ function resolveBaseURL(option, browser) {
42
68
  const raw = option ?? readEnv("AIA_BASE_URL") ?? DEFAULT_BASE_URL;
69
+ // A path on the page's own origin, such as "/api". A leading "//" names
70
+ // another host, so it is not a path.
71
+ const pathOnly = typeof raw === "string" && raw.startsWith("/") && !raw.startsWith("//");
72
+ const page = browser && pathOnly ? pageAddress() : undefined;
43
73
  let url;
44
74
  try {
45
- url = new URL(raw);
75
+ url = page === undefined ? new URL(raw) : new URL(raw, page);
46
76
  }
47
77
  catch {
48
- throw new AllisallError(`allisall: the base URL ${JSON.stringify(raw)} is not an absolute URL`);
78
+ throw new AllisallError(pathOnly && browser
79
+ ? `allisall: the base URL ${JSON.stringify(raw)} is a path, and the page's address could not be read to resolve it`
80
+ : `allisall: the base URL ${JSON.stringify(raw)} is not an absolute URL`);
49
81
  }
50
82
  if (url.protocol !== "http:" && url.protocol !== "https:") {
51
83
  throw new AllisallError(`allisall: the base URL ${JSON.stringify(raw)} is not http or https`);
52
84
  }
85
+ // URL parsing reads a backslash as "/" and drops tabs and newlines, so a
86
+ // value such as "/\other.example/api" passes the "//" check above and
87
+ // still names another host. Only the resolved origin settles it.
88
+ if (page !== undefined && url.origin !== new URL(page).origin) {
89
+ throw new AllisallError(`allisall: the base URL ${JSON.stringify(raw)} is a path, but resolves to another origin, ${url.origin}`);
90
+ }
53
91
  return url;
54
92
  }
55
- function resolveTimeout(option) {
56
- const timeout = option ?? DEFAULT_TIMEOUT_MS;
57
- if (typeof timeout !== "number" ||
58
- !Number.isFinite(timeout) ||
59
- timeout <= 0) {
60
- throw new AllisallError(`allisall: timeout must be a positive number of milliseconds, not ${String(timeout)}`);
61
- }
62
- return timeout;
93
+ /**
94
+ * Resolves what every request needs apart from its credential and default
95
+ * headers: the base URL, timeout, retries, `fetch` and `User-Agent`, which
96
+ * a browser does not send.
97
+ *
98
+ * @throws {AllisallError} for a base URL, timeout or `maxRetries` the
99
+ * client refuses.
100
+ */
101
+ export function transportSettings(options, browser) {
102
+ return {
103
+ baseURL: resolveBaseURL(options.baseURL, browser),
104
+ timeout: resolveTimeout(options.timeout, DEFAULT_TIMEOUT_MS),
105
+ maxRetries: resolveMaxRetries(options.maxRetries, DEFAULT_MAX_RETRIES),
106
+ fetch: options.fetch,
107
+ userAgent: userAgent(),
108
+ };
63
109
  }
64
- function resolveMaxRetries(option) {
65
- const maxRetries = option ?? DEFAULT_MAX_RETRIES;
66
- if (!Number.isInteger(maxRetries) || maxRetries < 0) {
67
- throw new AllisallError(`allisall: maxRetries must be a whole number, 0 or more, not ${String(maxRetries)}`);
110
+ /**
111
+ * Checks the client's options and fixes everything a request needs.
112
+ *
113
+ * @throws {AllisallError} for an option the client refuses.
114
+ * @throws {TypeError} when `defaultHeaders` is not a plain object of
115
+ * header names and string values, names a header the SDK sets, or holds a
116
+ * name or value the platform cannot send.
117
+ */
118
+ export function transportConfig(options) {
119
+ const credential = resolveCredential(options);
120
+ const browser = isBrowser();
121
+ const refuseApiKeys = browser && options.dangerouslyAllowBrowser !== true;
122
+ if (refuseApiKeys && credential.kind === "apiKey") {
123
+ throw new AllisallError(BROWSER_KEY_MESSAGE);
68
124
  }
69
- return maxRetries;
125
+ return {
126
+ ...transportSettings(options, browser),
127
+ credential,
128
+ refuseApiKeys,
129
+ defaultHeaders: resolveHeaders(options.defaultHeaders, "defaultHeaders"),
130
+ };
70
131
  }
71
- /** The `events` operations. */
72
- class Events {
73
- #config;
74
- constructor(config) {
75
- this.#config = config;
76
- }
77
- /**
78
- * Ingests any number of events. They are sent in batches of at most 500
79
- * events and 5,000,000 bytes, one batch after another, each retried as
80
- * the client allows. Every event without an `event_id` gets a generated
81
- * one, so a retry never stores an event twice. Your objects are not
82
- * modified.
83
- *
84
- * An event too large to send even alone is not sent, and is reported as a
85
- * rejected row with the code `too_large`.
86
- *
87
- * @returns the combined outcome over the whole list.
88
- * @throws {IngestError} when a batch fails; the call stops there, and the
89
- * error carries the summary so far and every event from the failed batch
90
- * onward, to send again. A batch fails on an error response, on no
91
- * response, on the caller's cancellation, or when its token cannot be
92
- * had: an error from `tokenProvider`, or, in a browser without
93
- * `dangerouslyAllowBrowser`, a provider's token that is an API key. The
94
- * error is the `IngestError`'s `cause`.
95
- * @throws {TypeError} when an event cannot be encoded, before anything is sent.
96
- */
97
- ingest(events, options = {}) {
98
- const config = this.#config;
99
- return ingest(events, (body, count, signal) => post(config, "/v1/events", body, (value) => readIngestResult(value, count), signal), options.signal);
100
- }
101
- }
102
- /** The allisall API client. Construct one and reuse it. */
132
+ /**
133
+ * The allisall API client. Construct one and reuse it.
134
+ *
135
+ * Its operations are grouped by what they act on, one property per group,
136
+ * such as `client.clients.list()`. A failed call rejects with an `ApiError`
137
+ * for an error response, or a `ConnectionError` when no response arrived.
138
+ */
103
139
  export class Allisall {
104
- /** The `events` operations. */
140
+ /** Events: ingest, and the events behind a client's totals. */
105
141
  events;
142
+ /** CSV imports of events. */
143
+ imports;
144
+ /** Clients, and the agents assigned to each. */
145
+ clients;
146
+ /** Agents. */
147
+ agents;
148
+ /** Value models, by their own id or by their client's, and value templates. */
149
+ valueModels;
150
+ /** Outcome types, for the workspace or for one client. */
151
+ outcomeTypes;
152
+ /** Cost line items and the price table. */
153
+ cost;
154
+ /** A client's value, cost, ROI and anomalies over a period. */
155
+ analytics;
156
+ /** Calculations, and the human steps that validate, publish and reopen them. */
157
+ calculations;
158
+ /** Reports on calculations, and the human steps that share and revoke them. */
159
+ reports;
160
+ /** The workspace's month, and renewal readiness. */
161
+ dashboard;
162
+ /** API keys, managed with a session token. */
163
+ apiKeys;
164
+ /** The API's liveness. */
165
+ health;
106
166
  /**
107
167
  * @throws {AllisallError} when there is no credential, or both an API key
108
- * and a token provider; when the base URL is not an absolute `http` or
109
- * `https` URL; when `maxRetries` is negative or `timeout` is not
110
- * positive; or when an API key is used in a browser without
111
- * `dangerouslyAllowBrowser`.
168
+ * and a token provider; when the base URL is neither an absolute `http`
169
+ * or `https` URL nor, in a browser, a path starting with a single `/`
170
+ * that resolves to the page's own origin; when `maxRetries` is negative
171
+ * or `timeout` is not positive; or when an API key is used in a browser
172
+ * without `dangerouslyAllowBrowser`.
173
+ * @throws {TypeError} when `defaultHeaders` is not a plain object of
174
+ * header names and string values, names a header the SDK sets, or holds a
175
+ * name or value the platform cannot send.
112
176
  */
113
177
  constructor(options = {}) {
114
- const credential = resolveCredential(options);
115
- const browser = isBrowser();
116
- const refuseApiKeys = browser && options.dangerouslyAllowBrowser !== true;
117
- if (refuseApiKeys && credential.kind === "apiKey") {
118
- throw new AllisallError(BROWSER_KEY_MESSAGE);
119
- }
120
- this.events = new Events({
121
- baseURL: resolveBaseURL(options.baseURL),
122
- credential,
123
- timeout: resolveTimeout(options.timeout),
124
- maxRetries: resolveMaxRetries(options.maxRetries),
125
- fetch: options.fetch,
126
- refuseApiKeys,
127
- userAgent: userAgent(),
128
- });
178
+ const config = transportConfig(options);
179
+ this.events = new Events(config);
180
+ this.imports = new Imports(config);
181
+ this.clients = new Clients(config);
182
+ this.agents = new Agents(config);
183
+ this.valueModels = new ValueModels(config);
184
+ this.outcomeTypes = new OutcomeTypes(config);
185
+ this.cost = new Cost(config);
186
+ this.analytics = new Analytics(config);
187
+ this.calculations = new Calculations(config);
188
+ this.reports = new Reports(config);
189
+ this.dashboard = new DashboardOperations(config);
190
+ this.apiKeys = new ApiKeys(config);
191
+ this.health = new HealthOperations(config);
129
192
  }
130
193
  }