@raster-app/sdk 0.1.0-canary-2e1834e
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 +83 -0
- package/dist/__generated__/openapi.d.ts +1096 -0
- package/dist/__generated__/openapi.js +2 -0
- package/dist/__generated__/openapi.js.map +1 -0
- package/dist/adapters/index.d.ts +31 -0
- package/dist/adapters/index.js +2 -0
- package/dist/adapters/index.js.map +1 -0
- package/dist/adapters/local-storage.d.ts +3 -0
- package/dist/adapters/local-storage.js +49 -0
- package/dist/adapters/local-storage.js.map +1 -0
- package/dist/adapters/memory.d.ts +7 -0
- package/dist/adapters/memory.js +19 -0
- package/dist/adapters/memory.js.map +1 -0
- package/dist/api/assets.d.ts +41 -0
- package/dist/api/assets.js +70 -0
- package/dist/api/assets.js.map +1 -0
- package/dist/api/errors.d.ts +22 -0
- package/dist/api/errors.js +80 -0
- package/dist/api/errors.js.map +1 -0
- package/dist/api/libraries.d.ts +16 -0
- package/dist/api/libraries.js +22 -0
- package/dist/api/libraries.js.map +1 -0
- package/dist/api/me.d.ts +40 -0
- package/dist/api/me.js +39 -0
- package/dist/api/me.js.map +1 -0
- package/dist/api/promote.d.ts +36 -0
- package/dist/api/promote.js +29 -0
- package/dist/api/promote.js.map +1 -0
- package/dist/api/search.d.ts +25 -0
- package/dist/api/search.js +21 -0
- package/dist/api/search.js.map +1 -0
- package/dist/api/transport.d.ts +43 -0
- package/dist/api/transport.js +90 -0
- package/dist/api/transport.js.map +1 -0
- package/dist/api/upload.d.ts +40 -0
- package/dist/api/upload.js +60 -0
- package/dist/api/upload.js.map +1 -0
- package/dist/auth/device.d.ts +32 -0
- package/dist/auth/device.js +70 -0
- package/dist/auth/device.js.map +1 -0
- package/dist/auth/http.d.ts +25 -0
- package/dist/auth/http.js +70 -0
- package/dist/auth/http.js.map +1 -0
- package/dist/auth/register.d.ts +14 -0
- package/dist/auth/register.js +21 -0
- package/dist/auth/register.js.map +1 -0
- package/dist/auth/session.d.ts +30 -0
- package/dist/auth/session.js +231 -0
- package/dist/auth/session.js.map +1 -0
- package/dist/auth/tokens.d.ts +10 -0
- package/dist/auth/tokens.js +20 -0
- package/dist/auth/tokens.js.map +1 -0
- package/dist/client.d.ts +138 -0
- package/dist/client.js +122 -0
- package/dist/client.js.map +1 -0
- package/dist/constants.d.ts +18 -0
- package/dist/constants.js +24 -0
- package/dist/constants.js.map +1 -0
- package/dist/format.d.ts +13 -0
- package/dist/format.js +83 -0
- package/dist/format.js.map +1 -0
- package/dist/images/blurhash-placeholder.d.ts +5 -0
- package/dist/images/blurhash-placeholder.js +47 -0
- package/dist/images/blurhash-placeholder.js.map +1 -0
- package/dist/images/blurhash.d.ts +2 -0
- package/dist/images/blurhash.js +77 -0
- package/dist/images/blurhash.js.map +1 -0
- package/dist/images/image-src.d.ts +42 -0
- package/dist/images/image-src.js +83 -0
- package/dist/images/image-src.js.map +1 -0
- package/dist/images/sizes.d.ts +15 -0
- package/dist/images/sizes.js +41 -0
- package/dist/images/sizes.js.map +1 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.js +17 -0
- package/dist/index.js.map +1 -0
- package/dist/types/asset.d.ts +50 -0
- package/dist/types/asset.js +23 -0
- package/dist/types/asset.js.map +1 -0
- package/dist/types/library.d.ts +21 -0
- package/dist/types/library.js +2 -0
- package/dist/types/library.js.map +1 -0
- package/dist/types/session.d.ts +59 -0
- package/dist/types/session.js +21 -0
- package/dist/types/session.js.map +1 -0
- package/package.json +42 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Monogram
|
|
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,83 @@
|
|
|
1
|
+
# @raster-app/sdk
|
|
2
|
+
|
|
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.
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm install @raster-app/sdk
|
|
9
|
+
```
|
|
10
|
+
|
|
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.
|
|
13
|
+
|
|
14
|
+
```ts
|
|
15
|
+
import { createRasterClient, localStorageCredentialStore } from '@raster-app/sdk'
|
|
16
|
+
|
|
17
|
+
const raster = createRasterClient({
|
|
18
|
+
host: { name: 'Sanity', openExternal: (url) => window.open(url, '_blank') },
|
|
19
|
+
credentials: localStorageCredentialStore(),
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
// Sign in with the device grant.
|
|
23
|
+
const controller = new AbortController()
|
|
24
|
+
await raster.auth.signInWithDevice({
|
|
25
|
+
onCode: (device) => showTheUser(device.userCode),
|
|
26
|
+
signal: controller.signal,
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
// Or connect an organization API key.
|
|
30
|
+
await raster.auth.connect({ apiKey })
|
|
31
|
+
|
|
32
|
+
const libraries = await raster.libraries.list({ organizationId: 'acme' })
|
|
33
|
+
const assets = await raster.assets.list({ organizationId: 'acme', libraryId: 'lib-1' })
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## The host
|
|
37
|
+
|
|
38
|
+
`createRasterClient` takes what differs from one host to the next:
|
|
39
|
+
|
|
40
|
+
- `host`, a `RasterHost`: the app's name, which Raster's consent page shows, and
|
|
41
|
+
`openExternal`, which opens a URL in the user's browser.
|
|
42
|
+
- `credentials`, a `CredentialStore`: where the credential is kept. The SDK ships
|
|
43
|
+
`memoryCredentialStore` and `localStorageCredentialStore`. The credential is bearer tokens
|
|
44
|
+
in plain text, so it is as private as its store.
|
|
45
|
+
|
|
46
|
+
Each client has its own session, so several can run on one page.
|
|
47
|
+
|
|
48
|
+
## Signing in
|
|
49
|
+
|
|
50
|
+
`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
|
|
52
|
+
consent page opens in their browser, and the promise settles once they approve.
|
|
53
|
+
`auth.connect({ apiKey })` connects an organization API key. Either way, `/me` checks the
|
|
54
|
+
credential before it is stored, so a bad key fails the call.
|
|
55
|
+
|
|
56
|
+
The consent page lets the user grant every organization or narrow the grant to one. A host that
|
|
57
|
+
works in one organization passes `scope: 'org'`, which has the user pick exactly one, and that
|
|
58
|
+
organization's id as `organizationId`. Any other grant, of another organization or of the whole
|
|
59
|
+
account, then fails with `ORGANIZATION_MISMATCH` and leaves the saved credential as it was.
|
|
60
|
+
|
|
61
|
+
## Errors
|
|
62
|
+
|
|
63
|
+
A call to Raster that fails rejects with a `RasterApiError`. Branch on its `code`, and show the
|
|
64
|
+
user `toUserMessage(error)`.
|
|
65
|
+
|
|
66
|
+
## Images
|
|
67
|
+
|
|
68
|
+
`getThumbUrl(asset)` picks a thumbnail from the asset's `sizes`, `getPreviewUrl(asset)` a larger
|
|
69
|
+
size for an asset shown large, `getFullSizeUrl(asset)` returns the full-size image, and
|
|
70
|
+
`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.
|
|
72
|
+
|
|
73
|
+
## File sizes and dates
|
|
74
|
+
|
|
75
|
+
These show file sizes and dates as the Raster app does: decimal units, so 1 MB is 1,000,000
|
|
76
|
+
bytes, and `en-US` dates.
|
|
77
|
+
|
|
78
|
+
- `formatBytes(bytes)` formats a byte count.
|
|
79
|
+
- `formatFileSize(asset.size)` formats a size that may be missing, and returns an empty string
|
|
80
|
+
for a null, negative or non-finite size.
|
|
81
|
+
- `formatDate(asset.created)` gives the date, `formatDateLong` adds the weekday and time, and
|
|
82
|
+
`formatRelativeTime` reads "just now", "5m ago", "3h ago" or "2d ago" within a week, then the
|
|
83
|
+
date. Each takes a `Date` or Unix milliseconds, and returns an empty string for null.
|