@dalea/sdk 0.1.2

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 Dalea
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 ADDED
@@ -0,0 +1,119 @@
1
+ # @dalea/sdk
2
+
3
+ The official TypeScript & JavaScript SDK for the [Dalea](https://dalea.app) data platform.
4
+
5
+ Typed, promise-based access to the Dalea API, with dual **ESM + CJS** builds, bundled
6
+ type declarations, and **zero runtime dependencies**.
7
+
8
+ - Node **>= 20** (works in the browser and edge runtimes too)
9
+ - Fully typed against the platform's OpenAPI contract
10
+ - API-key, session-cookie, and OAuth 2.1 + PKCE auth
11
+
12
+ ## Install
13
+
14
+ ```sh
15
+ npm i @dalea/sdk
16
+ # or: pnpm add @dalea/sdk / yarn add @dalea/sdk
17
+ ```
18
+
19
+ ## Quickstart
20
+
21
+ Create a workspace API key in the Dalea app, then:
22
+
23
+ ```ts
24
+ import { DaleaClient } from '@dalea/sdk';
25
+
26
+ const client = new DaleaClient({
27
+ baseUrl: 'https://dalea.app',
28
+ apiKey: process.env.DALEA_API_KEY, // or set DALEA_API_KEY and omit this
29
+ });
30
+
31
+ // List the data environments in your workspace.
32
+ const environments = await client.data.environments.list();
33
+ console.log(environments);
34
+ ```
35
+
36
+ If `DALEA_API_KEY` is set in the environment, `new DaleaClient({ baseUrl: 'https://dalea.app' })`
37
+ picks it up automatically — no `apiKey` needed.
38
+
39
+ ## Authentication
40
+
41
+ Pass exactly one credential to the constructor:
42
+
43
+ ```ts
44
+ // 1. Workspace API key (server-side; the default) — sent as X-API-Key.
45
+ new DaleaClient({ baseUrl: 'https://dalea.app', apiKey: 'dalea_…' });
46
+
47
+ // 2. Session cookie (browser, same-origin) — omit baseUrl to use the current origin.
48
+ new DaleaClient({ sessionCookie: true });
49
+
50
+ // 3. Any Credential (OAuth 2.1 + PKCE, client-credentials, bearer, …).
51
+ import { OAuthPkceCredential } from '@dalea/sdk';
52
+ new DaleaClient({ baseUrl: 'https://dalea.app', credential: new OAuthPkceCredential(/* … */) });
53
+ ```
54
+
55
+ Scope calls to a workspace with `client.setWorkspace(id)` (or the `workspace` config
56
+ option), and pass a per-request bearer token with `client.as(token)`.
57
+
58
+ ## Error handling
59
+
60
+ Every failure throws a typed `DaleaError` subclass you can branch on:
61
+
62
+ ```ts
63
+ import { DaleaRateLimitError, DaleaValidationError } from '@dalea/sdk';
64
+
65
+ try {
66
+ await client.data.environments.list();
67
+ } catch (err) {
68
+ if (err instanceof DaleaRateLimitError) {
69
+ // Retries are automatic (see below); this only fires once they're exhausted.
70
+ // err.retryAfterSeconds carries the server's hint.
71
+ } else if (err instanceof DaleaValidationError) {
72
+ // err.code / err.message / err.data describe what the server rejected.
73
+ } else {
74
+ throw err;
75
+ }
76
+ }
77
+ ```
78
+
79
+ Other subclasses: `DaleaAuthError`, `DaleaPermissionError`, `DaleaNotFoundError`,
80
+ `DaleaConflictError`, `DaleaArchivedError`, `DaleaQuotaError`, `DaleaServerError`,
81
+ `DaleaNetworkError`.
82
+
83
+ ## Retries & backoff
84
+
85
+ Throttling responses (`429`) and transient `503`s are retried automatically with
86
+ exponential backoff and full jitter, honouring the server's `Retry-After`. **Writes
87
+ retry too** — a throttle is rejected before the handler runs, so replaying is safe —
88
+ so you never need to hand-roll a backoff loop. A `DaleaRateLimitError` surfaces only
89
+ once retries are exhausted (or when the server asks for a wait longer than
90
+ `maxRetryDelayMs`). Terminal errors like `DaleaQuotaError` (`507`) are never retried.
91
+
92
+ Tune or opt out via the constructor:
93
+
94
+ | Option | Default | Meaning |
95
+ | --- | --- | --- |
96
+ | `maxRetries` | `2` | Max retries per request. |
97
+ | `retryWrites` | `true` | Retry POST/PATCH/DELETE, not just GET. Set `false` for strict, no-replay callers. |
98
+ | `retryBaseDelayMs` | `500` | Base delay for exponential backoff when the server sends no `Retry-After`. |
99
+ | `maxRetryDelayMs` | `20000` | Ceiling on any single backoff wait; a longer `Retry-After` fails fast. |
100
+
101
+ ## Pagination
102
+
103
+ List endpoints expose `iterate*` async iterators built on the exported `paginate`
104
+ primitive, so you can walk every page without managing cursors yourself:
105
+
106
+ ```ts
107
+ for await (const obj of client.data.tables.iterateObjects(tableId)) {
108
+ // … `break` stops fetching the next page
109
+ }
110
+ ```
111
+
112
+ ## Documentation
113
+
114
+ - **API reference** — https://dalea.app/api-docs
115
+ - **Guides & concepts** — the Dalea wiki
116
+
117
+ ## License
118
+
119
+ [MIT](./LICENSE) © Dalea