@allisall/sdk 0.0.0-stage → 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.
- package/LICENSE +202 -0
- package/NOTICE +2 -0
- package/README.md +227 -2
- package/dist/client.d.ts +121 -0
- package/dist/client.js +193 -0
- package/dist/decimal.d.ts +20 -0
- package/dist/decimal.js +23 -0
- package/dist/errors.d.ts +79 -0
- package/dist/errors.js +98 -0
- package/dist/generated/openapi.d.ts +7724 -0
- package/dist/generated/openapi.js +4 -0
- package/dist/generated/operations.d.ts +37 -0
- package/dist/generated/operations.js +976 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +5 -0
- package/dist/ingest.d.ts +28 -0
- package/dist/ingest.js +247 -0
- package/dist/money.d.ts +57 -0
- package/dist/money.js +284 -0
- package/dist/multipart.d.ts +27 -0
- package/dist/multipart.js +48 -0
- package/dist/options.d.ts +50 -0
- package/dist/options.js +73 -0
- package/dist/pagination.d.ts +55 -0
- package/dist/pagination.js +85 -0
- package/dist/request.d.ts +117 -0
- package/dist/request.js +363 -0
- package/dist/resources/agents.d.ts +51 -0
- package/dist/resources/agents.js +65 -0
- package/dist/resources/analytics.d.ts +42 -0
- package/dist/resources/analytics.js +68 -0
- package/dist/resources/api-keys.d.ts +54 -0
- package/dist/resources/api-keys.js +63 -0
- package/dist/resources/calculations.d.ts +78 -0
- package/dist/resources/calculations.js +111 -0
- package/dist/resources/clients.d.ts +65 -0
- package/dist/resources/clients.js +85 -0
- package/dist/resources/cost.d.ts +69 -0
- package/dist/resources/cost.js +89 -0
- package/dist/resources/dashboard.d.ts +24 -0
- package/dist/resources/dashboard.js +28 -0
- package/dist/resources/events.d.ts +47 -0
- package/dist/resources/events.js +69 -0
- package/dist/resources/health.d.ts +14 -0
- package/dist/resources/health.js +17 -0
- package/dist/resources/imports.d.ts +33 -0
- package/dist/resources/imports.js +37 -0
- package/dist/resources/outcome-types.d.ts +25 -0
- package/dist/resources/outcome-types.js +33 -0
- package/dist/resources/reports.d.ts +77 -0
- package/dist/resources/reports.js +103 -0
- package/dist/resources/value-models.d.ts +92 -0
- package/dist/resources/value-models.js +126 -0
- package/dist/retry.d.ts +18 -0
- package/dist/retry.js +105 -0
- package/dist/runtime.d.ts +19 -0
- package/dist/runtime.js +61 -0
- package/dist/share.d.ts +52 -0
- package/dist/share.js +60 -0
- package/dist/transport.d.ts +102 -0
- package/dist/transport.js +269 -0
- package/dist/types.d.ts +268 -0
- package/dist/types.js +89 -0
- package/dist/unicode.d.ts +2 -0
- package/dist/unicode.js +11 -0
- package/dist/uuid.d.ts +6 -0
- package/dist/uuid.js +20 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.js +2 -0
- package/package.json +40 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/NOTICE
ADDED
package/README.md
CHANGED
|
@@ -1,3 +1,228 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @allisall/sdk
|
|
2
2
|
|
|
3
|
-
|
|
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.
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
npm install @allisall/sdk
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Create a client
|
|
16
|
+
|
|
17
|
+
The client reads your API key from `AIA_API_KEY`:
|
|
18
|
+
|
|
19
|
+
```sh
|
|
20
|
+
export AIA_API_KEY=aia_...
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
import { Allisall } from "@allisall/sdk";
|
|
25
|
+
|
|
26
|
+
const client = new Allisall();
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
You can also pass the key yourself, as `new Allisall({ apiKey })`. Create
|
|
30
|
+
one client and reuse it.
|
|
31
|
+
|
|
32
|
+
## Ingest events
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
import { Allisall, decimal } from "@allisall/sdk";
|
|
36
|
+
|
|
37
|
+
const client = new Allisall();
|
|
38
|
+
|
|
39
|
+
const summary = await client.events.ingest([
|
|
40
|
+
{
|
|
41
|
+
timestamp: new Date(),
|
|
42
|
+
agent_key: "support-bot",
|
|
43
|
+
category: "model",
|
|
44
|
+
event_type: "completion",
|
|
45
|
+
model: "gpt-4o",
|
|
46
|
+
tokens_in: 1200,
|
|
47
|
+
tokens_out: 300,
|
|
48
|
+
cost: decimal("0.0042"),
|
|
49
|
+
},
|
|
50
|
+
]);
|
|
51
|
+
|
|
52
|
+
console.log(summary.accepted, summary.duplicates, summary.rejected);
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
`ingest` takes any number of events. It sends them in batches, retries a
|
|
56
|
+
failure worth retrying, and returns one summary for the whole list. A
|
|
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.
|
|
62
|
+
|
|
63
|
+
### Set your own `event_id` for at-least-once delivery
|
|
64
|
+
|
|
65
|
+
The SDK gives every event without an `event_id` a new one. That makes a
|
|
66
|
+
retry within one call safe, but it does not catch the same event sent
|
|
67
|
+
again in a later call. If your events can be delivered more than once,
|
|
68
|
+
for example from a queue that redelivers messages, set `event_id`
|
|
69
|
+
yourself, such as to the message's id. The API then stores the event
|
|
70
|
+
once, however often it arrives.
|
|
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
|
+
|
|
198
|
+
## Browsers
|
|
199
|
+
|
|
200
|
+
An API key in a browser can be read by anyone who loads the page. The
|
|
201
|
+
client therefore refuses an API key in a browser unless you pass
|
|
202
|
+
`dangerouslyAllowBrowser: true`:
|
|
203
|
+
|
|
204
|
+
```ts
|
|
205
|
+
import { Allisall } from "@allisall/sdk";
|
|
206
|
+
|
|
207
|
+
// Only if you accept that anyone who loads the page can read this key.
|
|
208
|
+
const client = new Allisall({
|
|
209
|
+
apiKey: "aia_...",
|
|
210
|
+
dangerouslyAllowBrowser: true,
|
|
211
|
+
});
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
Prefer calling the API from your server.
|
|
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
|
+
|
|
222
|
+
## Documentation
|
|
223
|
+
|
|
224
|
+
See [https://docs.allisai.ai](https://docs.allisai.ai).
|
|
225
|
+
|
|
226
|
+
## License
|
|
227
|
+
|
|
228
|
+
Apache-2.0. See `LICENSE` and `NOTICE`.
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
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";
|
|
14
|
+
import { type FetchLike, type TokenProvider, type TransportConfig } from "./transport.js";
|
|
15
|
+
/** The options of `new Allisall()`. Every one is optional. */
|
|
16
|
+
export interface ClientOptions {
|
|
17
|
+
/**
|
|
18
|
+
* The API key. Defaults to `AIA_API_KEY` from the environment. Pass
|
|
19
|
+
* either this or `tokenProvider`, not both.
|
|
20
|
+
*/
|
|
21
|
+
apiKey?: string | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* A callback returning the bearer token to send, called before every
|
|
24
|
+
* attempt, retries included. Use it to supply an API key fetched at run
|
|
25
|
+
* time, for example from a secret store.
|
|
26
|
+
*/
|
|
27
|
+
tokenProvider?: TokenProvider | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* The API's base URL, absolute, `http` or `https`. Defaults to
|
|
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.
|
|
35
|
+
*/
|
|
36
|
+
baseURL?: string | undefined;
|
|
37
|
+
/** The timeout of each attempt, in milliseconds. Defaults to 60,000. */
|
|
38
|
+
timeout?: number | undefined;
|
|
39
|
+
/** How many times a failure worth repeating is retried. Defaults to 2; 0 turns retries off. */
|
|
40
|
+
maxRetries?: number | undefined;
|
|
41
|
+
/** The `fetch` to send requests with. Defaults to the platform's own. */
|
|
42
|
+
fetch?: FetchLike | undefined;
|
|
43
|
+
/**
|
|
44
|
+
* Allows an API key in a browser, where anyone who loads the page can
|
|
45
|
+
* read it. Defaults to `false`.
|
|
46
|
+
*/
|
|
47
|
+
dangerouslyAllowBrowser?: boolean | undefined;
|
|
48
|
+
/**
|
|
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.
|
|
52
|
+
*/
|
|
53
|
+
defaultHeaders?: Readonly<Record<string, string>> | undefined;
|
|
54
|
+
}
|
|
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
|
+
*/
|
|
82
|
+
export declare class Allisall {
|
|
83
|
+
/** Events: ingest, and the events behind a client's totals. */
|
|
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;
|
|
109
|
+
/**
|
|
110
|
+
* @throws {AllisallError} when there is no credential, or both an API key
|
|
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.
|
|
119
|
+
*/
|
|
120
|
+
constructor(options?: ClientOptions);
|
|
121
|
+
}
|