@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 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. It runs in browsers and in Node 24 and later. The blurhash
5
- placeholder draws on a `document`, so outside a browser it returns null.
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
- A React host installs [`@raster-app/react`](https://www.npmjs.com/package/@raster-app/react)
12
- instead, which re-exports all of this package.
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: 'Sanity', openExternal: (url) => window.open(url, '_blank') },
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) => showTheUser(device.userCode),
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
- ## The host
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
- ## Signing in
60
+ ### Signing in
49
61
 
50
62
  `auth.signInWithDevice` runs the OAuth device grant (RFC 8628), which works in every host,
51
- including a Figma plugin's iframe. `onCode` receives the code to show the user while the
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
- ## Errors
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
- ## Images
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
- ## File sizes and dates
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