@superartifacts/sdk 0.0.0-stage → 0.1.1
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 +21 -0
- package/README.md +158 -2
- package/dist/index.cjs +788 -0
- package/dist/index.d.cts +2399 -0
- package/dist/index.d.ts +2399 -0
- package/dist/index.js +745 -0
- package/package.json +58 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Super Artifacts
|
|
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,159 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @superartifacts/sdk
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The TypeScript SDK for the [Super Artifacts](https://superartifacts.app) REST API. No runtime
|
|
4
|
+
dependencies.
|
|
5
|
+
|
|
6
|
+
Node 20.3+. It uses only the standard `fetch`, so other runtimes that provide it may work; only
|
|
7
|
+
Node is tested.
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @superartifacts/sdk
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
**Server-side only.** The API refuses any request carrying an `Origin` header, which means every
|
|
14
|
+
browser, and a key on a page is a leaked key. The client throws if you construct it in a browser.
|
|
15
|
+
`dangerouslyAllowBrowser: true` turns that check off for use behind your own proxy, and ships the
|
|
16
|
+
key to every visitor.
|
|
17
|
+
|
|
18
|
+
## Quickstart
|
|
19
|
+
|
|
20
|
+
Create a key in [Settings → API keys](https://superartifacts.app/settings/api-keys) and put it in
|
|
21
|
+
`SUPERARTIFACTS_API_KEY`.
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
import { SuperArtifacts } from '@superartifacts/sdk'
|
|
25
|
+
|
|
26
|
+
const sa = new SuperArtifacts()
|
|
27
|
+
|
|
28
|
+
const me = await sa.account.whoami()
|
|
29
|
+
console.log(me)
|
|
30
|
+
|
|
31
|
+
const published = await sa.artifacts.publish({
|
|
32
|
+
slug: 'hello',
|
|
33
|
+
title: 'Hello',
|
|
34
|
+
prompt: 'A page that says hello.',
|
|
35
|
+
html: '<h1>Hello</h1>',
|
|
36
|
+
})
|
|
37
|
+
console.log(published)
|
|
38
|
+
|
|
39
|
+
const { artifacts } = await sa.artifacts.list()
|
|
40
|
+
console.log(artifacts)
|
|
41
|
+
|
|
42
|
+
for await (const row of sa.data.iterArtifactRows({ artifact: 'hello' })) {
|
|
43
|
+
console.log(row)
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Every method takes one object holding the operation's path, query and body fields together, and an
|
|
48
|
+
optional second argument for this request alone:
|
|
49
|
+
|
|
50
|
+
```ts
|
|
51
|
+
await sa.artifacts.update({ artifact: 'hello', visibility: 'private' }, { timeout: 30_000 })
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Responses are untyped JSON until the API describes them: every result is an open object, so
|
|
55
|
+
destructure and index it without a cast.
|
|
56
|
+
|
|
57
|
+
Resources: `account`, `artifacts`, `live`, `uploads`, `data`, `schema`, `entries`, `secrets`,
|
|
58
|
+
`templates`, `projects`, `shares`, `comments`, `mentions`, `signatures`.
|
|
59
|
+
|
|
60
|
+
## Configuration
|
|
61
|
+
|
|
62
|
+
```ts
|
|
63
|
+
new SuperArtifacts({
|
|
64
|
+
apiKey: process.env.SUPERARTIFACTS_API_KEY, // the default
|
|
65
|
+
baseUrl: 'https://superartifacts.app', // the default
|
|
66
|
+
timeout: 60_000, // milliseconds per attempt
|
|
67
|
+
maxRetries: 2,
|
|
68
|
+
fetch: globalThis.fetch,
|
|
69
|
+
})
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Per request: `{ idempotencyKey, timeout, signal, headers }`.
|
|
73
|
+
|
|
74
|
+
## Errors
|
|
75
|
+
|
|
76
|
+
Every failure is a `SuperArtifactsError` with `status`, `code`, `message` and, when the API asked
|
|
77
|
+
you to wait, `retryAfter` in seconds. Anything else the API said is in `details`. A missing key
|
|
78
|
+
throws before any request, so that `AuthenticationError` has no `status` or `code`.
|
|
79
|
+
|
|
80
|
+
| Class | When |
|
|
81
|
+
| --- | --- |
|
|
82
|
+
| `InvalidArgumentsError` | 400 |
|
|
83
|
+
| `AuthenticationError` | 401, or no key to send |
|
|
84
|
+
| `PlanLimitError` | 402 |
|
|
85
|
+
| `PermissionError` | 403 `forbidden` |
|
|
86
|
+
| `ScopeRequiredError` | 403 `scope_required`: a read key called a write |
|
|
87
|
+
| `NotFoundError` | 404 |
|
|
88
|
+
| `ConflictError` | 409 |
|
|
89
|
+
| `PayloadTooLargeError` | 413: over 1 MiB, see [Uploads](#uploads) |
|
|
90
|
+
| `RateLimitError` | 429 |
|
|
91
|
+
| `InternalError` | 5xx |
|
|
92
|
+
| `ConnectionError` | no answer arrived (`status` 0) |
|
|
93
|
+
| `TimeoutError` | the attempt ran out of time (`status` 0) |
|
|
94
|
+
|
|
95
|
+
```ts
|
|
96
|
+
import { NotFoundError } from '@superartifacts/sdk'
|
|
97
|
+
|
|
98
|
+
try {
|
|
99
|
+
await sa.artifacts.get({ artifact: 'nope' })
|
|
100
|
+
} catch (error) {
|
|
101
|
+
if (error instanceof NotFoundError) console.log(error.code)
|
|
102
|
+
else throw error
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## Retries
|
|
107
|
+
|
|
108
|
+
- A `429` is retried after its `Retry-After`. Past 60 seconds it is not waited out: the
|
|
109
|
+
`RateLimitError` comes straight back with `retryAfter` set.
|
|
110
|
+
- `502`, `503`, `504`, timeouts and network errors are retried with backoff on `GET`, `DELETE` and
|
|
111
|
+
any `POST` carrying an `Idempotency-Key`.
|
|
112
|
+
- Every `POST` carries one: a fresh UUID per call, reused across that call's retries, so a retried
|
|
113
|
+
publish happens once. Pass your own with `{ idempotencyKey }` to make a call safe to repeat across
|
|
114
|
+
restarts, or `{ idempotencyKey: false }` to send none, which turns these retries off.
|
|
115
|
+
- No other `4xx` is retried, and neither is a `PATCH` or `PUT`.
|
|
116
|
+
|
|
117
|
+
## Pagination
|
|
118
|
+
|
|
119
|
+
Operations that page have an iterator that fetches pages as you read:
|
|
120
|
+
|
|
121
|
+
```ts
|
|
122
|
+
for await (const row of sa.data.iterRows({ dataset: 'signups' })) console.log(row)
|
|
123
|
+
for await (const row of sa.data.iterArtifactRows({ artifact: 'hello' })) console.log(row)
|
|
124
|
+
for await (const entry of sa.entries.iter({ collection: 'posts' })) console.log(entry)
|
|
125
|
+
for await (const mention of sa.mentions.iter()) console.log(mention)
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
`sa.comments.list` returns one page.
|
|
129
|
+
|
|
130
|
+
## Uploads
|
|
131
|
+
|
|
132
|
+
A request body is capped at 1 MiB. Files bigger than that are staged, then published by id:
|
|
133
|
+
|
|
134
|
+
```ts
|
|
135
|
+
import { readFile } from 'node:fs/promises'
|
|
136
|
+
|
|
137
|
+
const { uploadId } = await sa.uploads.upload([
|
|
138
|
+
{ path: 'images/hero.png', data: await readFile('hero.png') },
|
|
139
|
+
])
|
|
140
|
+
|
|
141
|
+
await sa.artifacts.publish({
|
|
142
|
+
slug: 'hello',
|
|
143
|
+
prompt: 'A page with a hero image.',
|
|
144
|
+
html: '<img src="images/hero.png">',
|
|
145
|
+
uploads: uploadId,
|
|
146
|
+
})
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
One file may be 5 MiB and one upload 10 MiB. A staged set expires after 30 minutes.
|
|
150
|
+
|
|
151
|
+
## Links
|
|
152
|
+
|
|
153
|
+
- [SDK documentation](https://superartifacts.app/docs/sdks/typescript)
|
|
154
|
+
- [REST API reference](https://superartifacts.app/docs/reference/api)
|
|
155
|
+
- [OpenAPI document](https://superartifacts.app/v1/openapi.json)
|
|
156
|
+
|
|
157
|
+
## License
|
|
158
|
+
|
|
159
|
+
MIT
|