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