@raster-app/sdk 0.1.0-rc.1 → 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/README.md +31 -14
- package/dist/__generated__/openapi.d.ts +813 -578
- package/dist/__generated__/openapi.js.map +1 -1
- package/dist/adapters/index.d.ts +3 -3
- package/dist/adapters/index.js.map +1 -1
- package/dist/auth/session.d.ts +2 -2
- package/dist/auth/session.js.map +1 -1
- package/dist/images/blurhash-placeholder.js +2 -1
- package/dist/images/blurhash-placeholder.js.map +1 -1
- package/package.json +4 -6
package/README.md
CHANGED
|
@@ -1,39 +1,51 @@
|
|
|
1
1
|
# @raster-app/sdk
|
|
2
2
|
|
|
3
3
|
A client for the [Raster](https://raster.app) REST API: sign-in, sessions, assets, libraries,
|
|
4
|
-
search and image helpers.
|
|
5
|
-
|
|
4
|
+
search and image helpers.
|
|
5
|
+
|
|
6
|
+
## Documentation
|
|
7
|
+
|
|
8
|
+
[raster.app/docs/api/sdk](https://raster.app/docs/api/sdk)
|
|
9
|
+
|
|
10
|
+
## Requirements
|
|
11
|
+
|
|
12
|
+
- A browser, or Node.js 22.12 or later
|
|
13
|
+
- No dependencies
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
6
16
|
|
|
7
17
|
```sh
|
|
8
18
|
npm install @raster-app/sdk
|
|
9
19
|
```
|
|
10
20
|
|
|
11
|
-
|
|
12
|
-
|
|
21
|
+
For React, install [`@raster-app/react`](https://www.npmjs.com/package/@raster-app/react) instead.
|
|
22
|
+
It includes this package.
|
|
23
|
+
|
|
24
|
+
## Usage
|
|
13
25
|
|
|
14
26
|
```ts
|
|
15
27
|
import { createRasterClient, localStorageCredentialStore } from '@raster-app/sdk'
|
|
16
28
|
|
|
17
29
|
const raster = createRasterClient({
|
|
18
|
-
host: { name: '
|
|
30
|
+
host: { name: 'My App', openExternal: (url) => window.open(url, '_blank') },
|
|
19
31
|
credentials: localStorageCredentialStore(),
|
|
20
32
|
})
|
|
21
33
|
|
|
22
34
|
// Sign in with the device grant.
|
|
23
35
|
const controller = new AbortController()
|
|
24
36
|
await raster.auth.signInWithDevice({
|
|
25
|
-
onCode: (device) =>
|
|
37
|
+
onCode: (device) => console.log(`Approve ${device.userCode} in your browser`),
|
|
26
38
|
signal: controller.signal,
|
|
27
39
|
})
|
|
28
40
|
|
|
29
41
|
// Or connect an organization API key.
|
|
30
|
-
await raster.auth.connect({ apiKey })
|
|
42
|
+
await raster.auth.connect({ apiKey: 'your-api-key' })
|
|
31
43
|
|
|
32
44
|
const libraries = await raster.libraries.list({ organizationId: 'acme' })
|
|
33
45
|
const assets = await raster.assets.list({ organizationId: 'acme', libraryId: 'lib-1' })
|
|
34
46
|
```
|
|
35
47
|
|
|
36
|
-
|
|
48
|
+
### The host
|
|
37
49
|
|
|
38
50
|
`createRasterClient` takes what differs from one host to the next:
|
|
39
51
|
|
|
@@ -45,10 +57,10 @@ const assets = await raster.assets.list({ organizationId: 'acme', libraryId: 'li
|
|
|
45
57
|
|
|
46
58
|
Each client has its own session, so several can run on one page.
|
|
47
59
|
|
|
48
|
-
|
|
60
|
+
### Signing in
|
|
49
61
|
|
|
50
62
|
`auth.signInWithDevice` runs the OAuth device grant (RFC 8628), which works in every host,
|
|
51
|
-
including a
|
|
63
|
+
including a plugin's sandboxed iframe. `onCode` receives the code to show the user while the
|
|
52
64
|
consent page opens in their browser, and the promise settles once they approve.
|
|
53
65
|
`auth.connect({ apiKey })` connects an organization API key. Either way, `/me` checks the
|
|
54
66
|
credential before it is stored, so a bad key fails the call.
|
|
@@ -58,19 +70,20 @@ works in one organization passes `scope: 'org'`, which has the user pick exactly
|
|
|
58
70
|
organization's id as `organizationId`. Any other grant, of another organization or of the whole
|
|
59
71
|
account, then fails with `ORGANIZATION_MISMATCH` and leaves the saved credential as it was.
|
|
60
72
|
|
|
61
|
-
|
|
73
|
+
### Errors
|
|
62
74
|
|
|
63
75
|
A call to Raster that fails rejects with a `RasterApiError`. Branch on its `code`, and show the
|
|
64
76
|
user `toUserMessage(error)`.
|
|
65
77
|
|
|
66
|
-
|
|
78
|
+
### Images
|
|
67
79
|
|
|
68
80
|
`getThumbUrl(asset)` picks a thumbnail from the asset's `sizes`, `getPreviewUrl(asset)` a larger
|
|
69
81
|
size for an asset shown large, `getFullSizeUrl(asset)` returns the full-size image, and
|
|
70
82
|
`getBlurhashPlaceholder(asset)` a data URL to paint while any of them loads. Each URL carries the
|
|
71
|
-
asset's content version, so a cache never shows a replaced file.
|
|
83
|
+
asset's content version, so a cache never shows a replaced file. The placeholder draws on a
|
|
84
|
+
`document`, so outside a browser it returns null.
|
|
72
85
|
|
|
73
|
-
|
|
86
|
+
### File sizes and dates
|
|
74
87
|
|
|
75
88
|
These show file sizes and dates as the Raster app does: decimal units, so 1 MB is 1,000,000
|
|
76
89
|
bytes, and `en-US` dates.
|
|
@@ -81,3 +94,7 @@ bytes, and `en-US` dates.
|
|
|
81
94
|
- `formatDate(asset.created)` gives the date, `formatDateLong` adds the weekday and time, and
|
|
82
95
|
`formatRelativeTime` reads "just now", "5m ago", "3h ago" or "2d ago" within a week, then the
|
|
83
96
|
date. Each takes a `Date` or Unix milliseconds, and returns an empty string for null.
|
|
97
|
+
|
|
98
|
+
## License
|
|
99
|
+
|
|
100
|
+
MIT
|