@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
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An asset's `sizes`, parsed: each size, the longest edge in pixels as a string such as `"400"`,
|
|
3
|
+
* maps to the CDN URL of the image at that size. Only sizes smaller than the source exist.
|
|
4
|
+
*/
|
|
5
|
+
export type SizeUrls = Record<string, string>;
|
|
6
|
+
/**
|
|
7
|
+
* Parse an asset's JSON-encoded `sizes`. Null when they are absent or malformed, so callers
|
|
8
|
+
* fall back to the full-size `url`.
|
|
9
|
+
*/
|
|
10
|
+
export declare function parseSizes(sizes: string | null | undefined): SizeUrls | null;
|
|
11
|
+
/**
|
|
12
|
+
* The URL of the smallest size at or above `targetEdge`, or of the largest when none reaches
|
|
13
|
+
* it. Null when there are no sizes.
|
|
14
|
+
*/
|
|
15
|
+
export declare function pickSizeUrl(sizes: SizeUrls | null | undefined, targetEdge: number): string | null;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parse an asset's JSON-encoded `sizes`. Null when they are absent or malformed, so callers
|
|
3
|
+
* fall back to the full-size `url`.
|
|
4
|
+
*/
|
|
5
|
+
export function parseSizes(sizes) {
|
|
6
|
+
if (!sizes)
|
|
7
|
+
return null;
|
|
8
|
+
try {
|
|
9
|
+
const parsed = JSON.parse(sizes);
|
|
10
|
+
if (typeof parsed !== 'object' || parsed === null)
|
|
11
|
+
return null;
|
|
12
|
+
const map = {};
|
|
13
|
+
for (const [size, url] of Object.entries(parsed)) {
|
|
14
|
+
if (typeof url === 'string')
|
|
15
|
+
map[size] = url;
|
|
16
|
+
}
|
|
17
|
+
return map;
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* The URL of the smallest size at or above `targetEdge`, or of the largest when none reaches
|
|
25
|
+
* it. Null when there are no sizes.
|
|
26
|
+
*/
|
|
27
|
+
export function pickSizeUrl(sizes, targetEdge) {
|
|
28
|
+
if (!sizes)
|
|
29
|
+
return null;
|
|
30
|
+
const available = Object.keys(sizes)
|
|
31
|
+
.map(Number)
|
|
32
|
+
.filter((n) => Number.isFinite(n))
|
|
33
|
+
.sort((a, b) => a - b);
|
|
34
|
+
if (available.length === 0)
|
|
35
|
+
return null;
|
|
36
|
+
const chosen = available.find((n) => n >= targetEdge) ?? available[available.length - 1];
|
|
37
|
+
if (chosen === undefined)
|
|
38
|
+
return null;
|
|
39
|
+
return sizes[String(chosen)] ?? null;
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=sizes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sizes.js","sourceRoot":"","sources":["../../src/images/sizes.ts"],"names":[],"mappings":"AAMA;;;GAGG;AACH,MAAM,UAAU,UAAU,CAAC,KAAgC;IAC1D,IAAI,CAAC,KAAK;QAAE,OAAO,IAAI,CAAA;IACvB,IAAI,CAAC;QACJ,MAAM,MAAM,GAAY,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;QACzC,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,KAAK,IAAI;YAAE,OAAO,IAAI,CAAA;QAC9D,MAAM,GAAG,GAAa,EAAE,CAAA;QACxB,KAAK,MAAM,CAAC,IAAI,EAAE,GAAG,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;YAClD,IAAI,OAAO,GAAG,KAAK,QAAQ;gBAAE,GAAG,CAAC,IAAI,CAAC,GAAG,GAAG,CAAA;QAC7C,CAAC;QACD,OAAO,GAAG,CAAA;IACX,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,IAAI,CAAA;IACZ,CAAC;AACF,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,KAAkC,EAAE,UAAkB;IACjF,IAAI,CAAC,KAAK;QAAE,OAAO,IAAI,CAAA;IACvB,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC;SAClC,GAAG,CAAC,MAAM,CAAC;SACX,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;SACjC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAA;IACvB,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAA;IACvC,MAAM,MAAM,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,UAAU,CAAC,IAAI,SAAS,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;IACxF,IAAI,MAAM,KAAK,SAAS;QAAE,OAAO,IAAI,CAAA;IACrC,OAAO,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,IAAI,CAAA;AACrC,CAAC","sourcesContent":["/**\n * An asset's `sizes`, parsed: each size, the longest edge in pixels as a string such as `\"400\"`,\n * maps to the CDN URL of the image at that size. Only sizes smaller than the source exist.\n */\nexport type SizeUrls = Record<string, string>\n\n/**\n * Parse an asset's JSON-encoded `sizes`. Null when they are absent or malformed, so callers\n * fall back to the full-size `url`.\n */\nexport function parseSizes(sizes: string | null | undefined): SizeUrls | null {\n\tif (!sizes) return null\n\ttry {\n\t\tconst parsed: unknown = JSON.parse(sizes)\n\t\tif (typeof parsed !== 'object' || parsed === null) return null\n\t\tconst map: SizeUrls = {}\n\t\tfor (const [size, url] of Object.entries(parsed)) {\n\t\t\tif (typeof url === 'string') map[size] = url\n\t\t}\n\t\treturn map\n\t} catch {\n\t\treturn null\n\t}\n}\n\n/**\n * The URL of the smallest size at or above `targetEdge`, or of the largest when none reaches\n * it. Null when there are no sizes.\n */\nexport function pickSizeUrl(sizes: SizeUrls | null | undefined, targetEdge: number): string | null {\n\tif (!sizes) return null\n\tconst available = Object.keys(sizes)\n\t\t.map(Number)\n\t\t.filter((n) => Number.isFinite(n))\n\t\t.sort((a, b) => a - b)\n\tif (available.length === 0) return null\n\tconst chosen = available.find((n) => n >= targetEdge) ?? available[available.length - 1]\n\tif (chosen === undefined) return null\n\treturn sizes[String(chosen)] ?? null\n}\n"]}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export { type RasterClient, type RasterClientConfig, createRasterClient } from './client.js';
|
|
2
|
+
export type { CredentialStore, RasterHost } from './adapters/index.js';
|
|
3
|
+
export { localStorageCredentialStore } from './adapters/local-storage.js';
|
|
4
|
+
export { memoryCredentialStore } from './adapters/memory.js';
|
|
5
|
+
export { RasterApiError, isAbortError, toFetchError, toRasterApiError, toUserMessage, } from './api/errors.js';
|
|
6
|
+
export { API_ORIGIN, API_VERSION, AUTH_ORIGIN, RASTER_HOSTS } from './constants.js';
|
|
7
|
+
export { type Asset, type AssetVariant, type DisplayAsset, type UploadedAsset, type Uploader, isReady, } from './types/asset.js';
|
|
8
|
+
export type { Library, Organization, Tag } from './types/library.js';
|
|
9
|
+
export { type CredentialOrganization, type OAuthSession, type StoredCredentials, SIGNED_OUT, emptyCredentials, isConfigured, } from './types/session.js';
|
|
10
|
+
export type { SessionStore } from './auth/session.js';
|
|
11
|
+
export type { DeviceAuthorization } from './auth/device.js';
|
|
12
|
+
export { ASSETS_PAGE_SIZE, hasMorePages } from './api/assets.js';
|
|
13
|
+
export { LIBRARIES_PAGE_SIZE } from './api/libraries.js';
|
|
14
|
+
export { SEARCH_PAGE_SIZE, type SearchHit, type SearchResult } from './api/search.js';
|
|
15
|
+
export type { PromoteResult } from './api/promote.js';
|
|
16
|
+
export type { UploadSource } from './api/upload.js';
|
|
17
|
+
export { type Me, type MeLibraryAccess, type MeOrganization, meCredentialOrganizations, meLibraryAccess, meOrganizationList, meOrganizations, } from './api/me.js';
|
|
18
|
+
export type { AuthorizedInit, RequestOptions, Transport } from './api/transport.js';
|
|
19
|
+
export { decodeBlurhash } from './images/blurhash.js';
|
|
20
|
+
export { blurhashToDataUrl } from './images/blurhash-placeholder.js';
|
|
21
|
+
export { getBlurhashPlaceholder, getFullSizeUrl, getPreviewUrl, getThumbUrl, versionedUrl, } from './images/image-src.js';
|
|
22
|
+
export { type SizeUrls, parseSizes, pickSizeUrl } from './images/sizes.js';
|
|
23
|
+
export { formatBytes, formatDate, formatDateLong, formatFileSize, formatRelativeTime, } from './format.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export { createRasterClient } from './client.js';
|
|
2
|
+
export { localStorageCredentialStore } from './adapters/local-storage.js';
|
|
3
|
+
export { memoryCredentialStore } from './adapters/memory.js';
|
|
4
|
+
export { RasterApiError, isAbortError, toFetchError, toRasterApiError, toUserMessage, } from './api/errors.js';
|
|
5
|
+
export { API_ORIGIN, API_VERSION, AUTH_ORIGIN, RASTER_HOSTS } from './constants.js';
|
|
6
|
+
export { isReady, } from './types/asset.js';
|
|
7
|
+
export { SIGNED_OUT, emptyCredentials, isConfigured, } from './types/session.js';
|
|
8
|
+
export { ASSETS_PAGE_SIZE, hasMorePages } from './api/assets.js';
|
|
9
|
+
export { LIBRARIES_PAGE_SIZE } from './api/libraries.js';
|
|
10
|
+
export { SEARCH_PAGE_SIZE } from './api/search.js';
|
|
11
|
+
export { meCredentialOrganizations, meLibraryAccess, meOrganizationList, meOrganizations, } from './api/me.js';
|
|
12
|
+
export { decodeBlurhash } from './images/blurhash.js';
|
|
13
|
+
export { blurhashToDataUrl } from './images/blurhash-placeholder.js';
|
|
14
|
+
export { getBlurhashPlaceholder, getFullSizeUrl, getPreviewUrl, getThumbUrl, versionedUrl, } from './images/image-src.js';
|
|
15
|
+
export { parseSizes, pickSizeUrl } from './images/sizes.js';
|
|
16
|
+
export { formatBytes, formatDate, formatDateLong, formatFileSize, formatRelativeTime, } from './format.js';
|
|
17
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAA8C,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAG5F,OAAO,EAAE,2BAA2B,EAAE,MAAM,6BAA6B,CAAA;AACzE,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAA;AAE5D,OAAO,EACN,cAAc,EACd,YAAY,EACZ,YAAY,EACZ,gBAAgB,EAChB,aAAa,GACb,MAAM,iBAAiB,CAAA;AAExB,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAEnF,OAAO,EAMN,OAAO,GACP,MAAM,kBAAkB,CAAA;AAEzB,OAAO,EAIN,UAAU,EACV,gBAAgB,EAChB,YAAY,GACZ,MAAM,oBAAoB,CAAA;AAK3B,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAChE,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAA;AACxD,OAAO,EAAE,gBAAgB,EAAqC,MAAM,iBAAiB,CAAA;AAGrF,OAAO,EAIN,yBAAyB,EACzB,eAAe,EACf,kBAAkB,EAClB,eAAe,GACf,MAAM,aAAa,CAAA;AAGpB,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AACrD,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAA;AACpE,OAAO,EACN,sBAAsB,EACtB,cAAc,EACd,aAAa,EACb,WAAW,EACX,YAAY,GACZ,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EAAiB,UAAU,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAE1E,OAAO,EACN,WAAW,EACX,UAAU,EACV,cAAc,EACd,cAAc,EACd,kBAAkB,GAClB,MAAM,aAAa,CAAA","sourcesContent":["export { type RasterClient, type RasterClientConfig, createRasterClient } from './client.js'\n\nexport type { CredentialStore, RasterHost } from './adapters/index.js'\nexport { localStorageCredentialStore } from './adapters/local-storage.js'\nexport { memoryCredentialStore } from './adapters/memory.js'\n\nexport {\n\tRasterApiError,\n\tisAbortError,\n\ttoFetchError,\n\ttoRasterApiError,\n\ttoUserMessage,\n} from './api/errors.js'\n\nexport { API_ORIGIN, API_VERSION, AUTH_ORIGIN, RASTER_HOSTS } from './constants.js'\n\nexport {\n\ttype Asset,\n\ttype AssetVariant,\n\ttype DisplayAsset,\n\ttype UploadedAsset,\n\ttype Uploader,\n\tisReady,\n} from './types/asset.js'\nexport type { Library, Organization, Tag } from './types/library.js'\nexport {\n\ttype CredentialOrganization,\n\ttype OAuthSession,\n\ttype StoredCredentials,\n\tSIGNED_OUT,\n\temptyCredentials,\n\tisConfigured,\n} from './types/session.js'\n\nexport type { SessionStore } from './auth/session.js'\nexport type { DeviceAuthorization } from './auth/device.js'\n\nexport { ASSETS_PAGE_SIZE, hasMorePages } from './api/assets.js'\nexport { LIBRARIES_PAGE_SIZE } from './api/libraries.js'\nexport { SEARCH_PAGE_SIZE, type SearchHit, type SearchResult } from './api/search.js'\nexport type { PromoteResult } from './api/promote.js'\nexport type { UploadSource } from './api/upload.js'\nexport {\n\ttype Me,\n\ttype MeLibraryAccess,\n\ttype MeOrganization,\n\tmeCredentialOrganizations,\n\tmeLibraryAccess,\n\tmeOrganizationList,\n\tmeOrganizations,\n} from './api/me.js'\nexport type { AuthorizedInit, RequestOptions, Transport } from './api/transport.js'\n\nexport { decodeBlurhash } from './images/blurhash.js'\nexport { blurhashToDataUrl } from './images/blurhash-placeholder.js'\nexport {\n\tgetBlurhashPlaceholder,\n\tgetFullSizeUrl,\n\tgetPreviewUrl,\n\tgetThumbUrl,\n\tversionedUrl,\n} from './images/image-src.js'\nexport { type SizeUrls, parseSizes, pickSizeUrl } from './images/sizes.js'\n\nexport {\n\tformatBytes,\n\tformatDate,\n\tformatDateLong,\n\tformatFileSize,\n\tformatRelativeTime,\n} from './format.js'\n"]}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { components } from '../__generated__/openapi.js';
|
|
2
|
+
/** A non-destructive variant of an asset — a crop, a colour adjustment. */
|
|
3
|
+
export type AssetVariant = components['schemas']['AssetVariant'];
|
|
4
|
+
export type Uploader = components['schemas']['Uploader'];
|
|
5
|
+
export type Asset = components['schemas']['Asset'];
|
|
6
|
+
/** The subset a grid renders, which `Asset` and `AssetVariant` both satisfy. */
|
|
7
|
+
export type DisplayAsset = {
|
|
8
|
+
id: string;
|
|
9
|
+
name: string | null;
|
|
10
|
+
url: string | null;
|
|
11
|
+
sizes: string | null;
|
|
12
|
+
width: number | null;
|
|
13
|
+
height: number | null;
|
|
14
|
+
blurhash?: string | null;
|
|
15
|
+
/** Absent on an `AssetVariant`, whose URL is content-addressed (see `versionedUrl`). */
|
|
16
|
+
contentVersion?: number | null;
|
|
17
|
+
/**
|
|
18
|
+
* Client-only: an optimistic promote sets these to the promoted variant's own image, and
|
|
19
|
+
* keeps `url` and `sizes`, which variant URLs are built from. The URL helpers prefer them.
|
|
20
|
+
*/
|
|
21
|
+
displayUrl?: string | null;
|
|
22
|
+
displaySizes?: string | null;
|
|
23
|
+
/**
|
|
24
|
+
* Client-only: set on the optimistic placeholder for a just-uploaded variant, which has the
|
|
25
|
+
* source's dimensions but is not selectable until Raster has produced the image.
|
|
26
|
+
*/
|
|
27
|
+
processing?: boolean;
|
|
28
|
+
contentType?: string | null;
|
|
29
|
+
size?: number | null;
|
|
30
|
+
variants?: Asset['variants'];
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Whether Raster has finished processing an asset or variant. Processing writes the
|
|
34
|
+
* dimensions when it finishes, for every image and video. It never writes `sizes` for an SVG
|
|
35
|
+
* or a small image, or `blurhash` for an SVG, and a listed variant has no `blurhash` at all.
|
|
36
|
+
* Zero means Raster could not read the file, which leaves nothing to place.
|
|
37
|
+
*/
|
|
38
|
+
export declare function isProcessed(asset: {
|
|
39
|
+
width?: number | null;
|
|
40
|
+
height?: number | null;
|
|
41
|
+
}): boolean;
|
|
42
|
+
/**
|
|
43
|
+
* An asset is usable once it has a full-size image (`getFullSizeUrl`) and is not processing.
|
|
44
|
+
* Its url exists from the upload on, so it is the dimensions or sizes, which processing
|
|
45
|
+
* writes when it finishes, that tell. A search hit has sizes but no url, and its index
|
|
46
|
+
* may never have stored dimensions: a host takes those from the loaded image.
|
|
47
|
+
*/
|
|
48
|
+
export declare function isReady(asset: DisplayAsset): boolean;
|
|
49
|
+
/** The asset an upload created. `appUrl` opens it in Raster. */
|
|
50
|
+
export type UploadedAsset = Pick<Asset, 'id' | 'parentId' | 'url' | 'appUrl' | 'name'>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { getFullSizeUrl } from '../images/image-src.js';
|
|
2
|
+
import { parseSizes } from '../images/sizes.js';
|
|
3
|
+
/**
|
|
4
|
+
* Whether Raster has finished processing an asset or variant. Processing writes the
|
|
5
|
+
* dimensions when it finishes, for every image and video. It never writes `sizes` for an SVG
|
|
6
|
+
* or a small image, or `blurhash` for an SVG, and a listed variant has no `blurhash` at all.
|
|
7
|
+
* Zero means Raster could not read the file, which leaves nothing to place.
|
|
8
|
+
*/
|
|
9
|
+
export function isProcessed(asset) {
|
|
10
|
+
return (asset.width ?? 0) > 0 && (asset.height ?? 0) > 0;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* An asset is usable once it has a full-size image (`getFullSizeUrl`) and is not processing.
|
|
14
|
+
* Its url exists from the upload on, so it is the dimensions or sizes, which processing
|
|
15
|
+
* writes when it finishes, that tell. A search hit has sizes but no url, and its index
|
|
16
|
+
* may never have stored dimensions: a host takes those from the loaded image.
|
|
17
|
+
*/
|
|
18
|
+
export function isReady(asset) {
|
|
19
|
+
return (!asset.processing &&
|
|
20
|
+
getFullSizeUrl(asset) !== null &&
|
|
21
|
+
(isProcessed(asset) || parseSizes(asset.sizes) !== null));
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=asset.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asset.js","sourceRoot":"","sources":["../../src/types/asset.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAA;AACvD,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAoC/C;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CAAC,KAAwD;IACnF,OAAO,CAAC,KAAK,CAAC,KAAK,IAAI,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,IAAI,CAAC,CAAC,GAAG,CAAC,CAAA;AACzD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,OAAO,CAAC,KAAmB;IAC1C,OAAO,CACN,CAAC,KAAK,CAAC,UAAU;QACjB,cAAc,CAAC,KAAK,CAAC,KAAK,IAAI;QAC9B,CAAC,WAAW,CAAC,KAAK,CAAC,IAAI,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,IAAI,CAAC,CACxD,CAAA;AACF,CAAC","sourcesContent":["import type { components } from '../__generated__/openapi.js'\nimport { getFullSizeUrl } from '../images/image-src.js'\nimport { parseSizes } from '../images/sizes.js'\n\n/** A non-destructive variant of an asset — a crop, a colour adjustment. */\nexport type AssetVariant = components['schemas']['AssetVariant']\n\nexport type Uploader = components['schemas']['Uploader']\n\nexport type Asset = components['schemas']['Asset']\n\n/** The subset a grid renders, which `Asset` and `AssetVariant` both satisfy. */\nexport type DisplayAsset = {\n\tid: string\n\tname: string | null\n\turl: string | null\n\tsizes: string | null\n\twidth: number | null\n\theight: number | null\n\tblurhash?: string | null\n\t/** Absent on an `AssetVariant`, whose URL is content-addressed (see `versionedUrl`). */\n\tcontentVersion?: number | null\n\t/**\n\t * Client-only: an optimistic promote sets these to the promoted variant's own image, and\n\t * keeps `url` and `sizes`, which variant URLs are built from. The URL helpers prefer them.\n\t */\n\tdisplayUrl?: string | null\n\tdisplaySizes?: string | null\n\t/**\n\t * Client-only: set on the optimistic placeholder for a just-uploaded variant, which has the\n\t * source's dimensions but is not selectable until Raster has produced the image.\n\t */\n\tprocessing?: boolean\n\tcontentType?: string | null\n\tsize?: number | null\n\tvariants?: Asset['variants']\n}\n\n/**\n * Whether Raster has finished processing an asset or variant. Processing writes the\n * dimensions when it finishes, for every image and video. It never writes `sizes` for an SVG\n * or a small image, or `blurhash` for an SVG, and a listed variant has no `blurhash` at all.\n * Zero means Raster could not read the file, which leaves nothing to place.\n */\nexport function isProcessed(asset: { width?: number | null; height?: number | null }): boolean {\n\treturn (asset.width ?? 0) > 0 && (asset.height ?? 0) > 0\n}\n\n/**\n * An asset is usable once it has a full-size image (`getFullSizeUrl`) and is not processing.\n * Its url exists from the upload on, so it is the dimensions or sizes, which processing\n * writes when it finishes, that tell. A search hit has sizes but no url, and its index\n * may never have stored dimensions: a host takes those from the loaded image.\n */\nexport function isReady(asset: DisplayAsset): boolean {\n\treturn (\n\t\t!asset.processing &&\n\t\tgetFullSizeUrl(asset) !== null &&\n\t\t(isProcessed(asset) || parseSizes(asset.sizes) !== null)\n\t)\n}\n\n/** The asset an upload created. `appUrl` opens it in Raster. */\nexport type UploadedAsset = Pick<Asset, 'id' | 'parentId' | 'url' | 'appUrl' | 'name'>\n"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { components } from '../__generated__/openapi.js';
|
|
2
|
+
/**
|
|
3
|
+
* An organization the credential can act on. `/me` reports these, so a host knows the set
|
|
4
|
+
* before fetching a single library — which is what lets it offer a choice first.
|
|
5
|
+
*/
|
|
6
|
+
export type Organization = {
|
|
7
|
+
id: string;
|
|
8
|
+
name: string | null;
|
|
9
|
+
/** Libraries reachable here. Carried by `/me`, so showing it costs no extra request. */
|
|
10
|
+
libraryCount: number;
|
|
11
|
+
};
|
|
12
|
+
export type Tag = components['schemas']['Tag'];
|
|
13
|
+
export type Library = components['schemas']['Library'] & {
|
|
14
|
+
/**
|
|
15
|
+
* The organization this library came from, which the SDK attaches: a credential can reach
|
|
16
|
+
* several, and every request for this library's assets needs it in the path.
|
|
17
|
+
*/
|
|
18
|
+
organizationId: string;
|
|
19
|
+
/** For display when a credential spans several organizations. */
|
|
20
|
+
organizationName: string | null;
|
|
21
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"library.js","sourceRoot":"","sources":["../../src/types/library.ts"],"names":[],"mappings":"","sourcesContent":["import type { components } from '../__generated__/openapi.js'\n\n/**\n * An organization the credential can act on. `/me` reports these, so a host knows the set\n * before fetching a single library — which is what lets it offer a choice first.\n */\nexport type Organization = {\n\tid: string\n\tname: string | null\n\t/** Libraries reachable here. Carried by `/me`, so showing it costs no extra request. */\n\tlibraryCount: number\n}\n\nexport type Tag = components['schemas']['Tag']\n\nexport type Library = components['schemas']['Library'] & {\n\t/**\n\t * The organization this library came from, which the SDK attaches: a credential can reach\n\t * several, and every request for this library's assets needs it in the path.\n\t */\n\torganizationId: string\n\t/** For display when a credential spans several organizations. */\n\torganizationName: string | null\n}\n"]}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/** A signed-in session — what the device grant hands back. */
|
|
2
|
+
export type OAuthSession = {
|
|
3
|
+
/** The install's client_id, which every sign-in through it reuses; refreshes present it. */
|
|
4
|
+
clientId: string;
|
|
5
|
+
/**
|
|
6
|
+
* Names this sign-in: minted when `connect` adopts it, kept through every refresh. The
|
|
7
|
+
* client id cannot do this, because the next sign-in reuses it. Absent from a session
|
|
8
|
+
* saved before this field existed.
|
|
9
|
+
*/
|
|
10
|
+
signInId?: string;
|
|
11
|
+
accessToken: string;
|
|
12
|
+
/**
|
|
13
|
+
* Rotates on every refresh, and presenting a spent one revokes the whole connection — so
|
|
14
|
+
* this is always the latest one issued, saved the moment it arrives.
|
|
15
|
+
*/
|
|
16
|
+
refreshToken: string;
|
|
17
|
+
/** When `accessToken` stops being accepted, in epoch ms. */
|
|
18
|
+
expiresAt: number;
|
|
19
|
+
};
|
|
20
|
+
/** One organization the credential reaches, as resolved from `/me`. */
|
|
21
|
+
export type CredentialOrganization = {
|
|
22
|
+
id: string;
|
|
23
|
+
name: string | null;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Everything the SDK persists through a `CredentialStore`, as one object written at once, so
|
|
27
|
+
* a crash cannot leave a session half-saved.
|
|
28
|
+
*/
|
|
29
|
+
export type StoredCredentials = {
|
|
30
|
+
/**
|
|
31
|
+
* The OAuth client this install registered, kept across sign-outs, so Connected apps lists
|
|
32
|
+
* one entry per install rather than one per sign-in.
|
|
33
|
+
*/
|
|
34
|
+
clientId: string | null;
|
|
35
|
+
/** A pasted organization API key — the alternative to signing in. Null when signed in. */
|
|
36
|
+
apiKey: string | null;
|
|
37
|
+
/** The signed-in session. Null when using an API key, or signed out. */
|
|
38
|
+
oauth: OAuthSession | null;
|
|
39
|
+
/**
|
|
40
|
+
* The person signed in, for "Signed in as …". Null for the API-key path — a key belongs
|
|
41
|
+
* to an organization, not a person — and null until `/me` reports the account's name.
|
|
42
|
+
*/
|
|
43
|
+
userName: string | null;
|
|
44
|
+
/**
|
|
45
|
+
* Every organization the credential reaches. One entry for an API key, or for a sign-in
|
|
46
|
+
* the user narrowed to a single organization at consent; several when they granted all
|
|
47
|
+
* of them. Empty only when the account belongs to none.
|
|
48
|
+
*/
|
|
49
|
+
organizations: Array<CredentialOrganization>;
|
|
50
|
+
};
|
|
51
|
+
/** Signed out, but still holding the registration — see `StoredCredentials.clientId`. */
|
|
52
|
+
export declare const SIGNED_OUT: Omit<StoredCredentials, 'clientId'>;
|
|
53
|
+
/** Empty credentials, as a store returns before anything has ever been saved. */
|
|
54
|
+
export declare function emptyCredentials(): StoredCredentials;
|
|
55
|
+
/**
|
|
56
|
+
* Whether these credentials can call the API at all. An account in no organization is signed
|
|
57
|
+
* in, and its host shows an empty list.
|
|
58
|
+
*/
|
|
59
|
+
export declare function isConfigured(credentials: StoredCredentials | null | undefined): credentials is StoredCredentials;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** Signed out, but still holding the registration — see `StoredCredentials.clientId`. */
|
|
2
|
+
export const SIGNED_OUT = {
|
|
3
|
+
apiKey: null,
|
|
4
|
+
oauth: null,
|
|
5
|
+
userName: null,
|
|
6
|
+
organizations: [],
|
|
7
|
+
};
|
|
8
|
+
/** Empty credentials, as a store returns before anything has ever been saved. */
|
|
9
|
+
export function emptyCredentials() {
|
|
10
|
+
return { ...SIGNED_OUT, clientId: null };
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Whether these credentials can call the API at all. An account in no organization is signed
|
|
14
|
+
* in, and its host shows an empty list.
|
|
15
|
+
*/
|
|
16
|
+
export function isConfigured(credentials) {
|
|
17
|
+
return (credentials != null &&
|
|
18
|
+
(credentials.oauth !== null ||
|
|
19
|
+
(typeof credentials.apiKey === 'string' && credentials.apiKey !== '')));
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=session.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.js","sourceRoot":"","sources":["../../src/types/session.ts"],"names":[],"mappings":"AAqDA,yFAAyF;AACzF,MAAM,CAAC,MAAM,UAAU,GAAwC;IAC9D,MAAM,EAAE,IAAI;IACZ,KAAK,EAAE,IAAI;IACX,QAAQ,EAAE,IAAI;IACd,aAAa,EAAE,EAAE;CACjB,CAAA;AAED,iFAAiF;AACjF,MAAM,UAAU,gBAAgB;IAC/B,OAAO,EAAE,GAAG,UAAU,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAA;AACzC,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,YAAY,CAC3B,WAAiD;IAEjD,OAAO,CACN,WAAW,IAAI,IAAI;QACnB,CAAC,WAAW,CAAC,KAAK,KAAK,IAAI;YAC1B,CAAC,OAAO,WAAW,CAAC,MAAM,KAAK,QAAQ,IAAI,WAAW,CAAC,MAAM,KAAK,EAAE,CAAC,CAAC,CACvE,CAAA;AACF,CAAC","sourcesContent":["/** A signed-in session — what the device grant hands back. */\nexport type OAuthSession = {\n\t/** The install's client_id, which every sign-in through it reuses; refreshes present it. */\n\tclientId: string\n\t/**\n\t * Names this sign-in: minted when `connect` adopts it, kept through every refresh. The\n\t * client id cannot do this, because the next sign-in reuses it. Absent from a session\n\t * saved before this field existed.\n\t */\n\tsignInId?: string\n\taccessToken: string\n\t/**\n\t * Rotates on every refresh, and presenting a spent one revokes the whole connection — so\n\t * this is always the latest one issued, saved the moment it arrives.\n\t */\n\trefreshToken: string\n\t/** When `accessToken` stops being accepted, in epoch ms. */\n\texpiresAt: number\n}\n\n/** One organization the credential reaches, as resolved from `/me`. */\nexport type CredentialOrganization = {\n\tid: string\n\tname: string | null\n}\n\n/**\n * Everything the SDK persists through a `CredentialStore`, as one object written at once, so\n * a crash cannot leave a session half-saved.\n */\nexport type StoredCredentials = {\n\t/**\n\t * The OAuth client this install registered, kept across sign-outs, so Connected apps lists\n\t * one entry per install rather than one per sign-in.\n\t */\n\tclientId: string | null\n\t/** A pasted organization API key — the alternative to signing in. Null when signed in. */\n\tapiKey: string | null\n\t/** The signed-in session. Null when using an API key, or signed out. */\n\toauth: OAuthSession | null\n\t/**\n\t * The person signed in, for \"Signed in as …\". Null for the API-key path — a key belongs\n\t * to an organization, not a person — and null until `/me` reports the account's name.\n\t */\n\tuserName: string | null\n\t/**\n\t * Every organization the credential reaches. One entry for an API key, or for a sign-in\n\t * the user narrowed to a single organization at consent; several when they granted all\n\t * of them. Empty only when the account belongs to none.\n\t */\n\torganizations: Array<CredentialOrganization>\n}\n\n/** Signed out, but still holding the registration — see `StoredCredentials.clientId`. */\nexport const SIGNED_OUT: Omit<StoredCredentials, 'clientId'> = {\n\tapiKey: null,\n\toauth: null,\n\tuserName: null,\n\torganizations: [],\n}\n\n/** Empty credentials, as a store returns before anything has ever been saved. */\nexport function emptyCredentials(): StoredCredentials {\n\treturn { ...SIGNED_OUT, clientId: null }\n}\n\n/**\n * Whether these credentials can call the API at all. An account in no organization is signed\n * in, and its host shows an empty list.\n */\nexport function isConfigured(\n\tcredentials: StoredCredentials | null | undefined\n): credentials is StoredCredentials {\n\treturn (\n\t\tcredentials != null &&\n\t\t(credentials.oauth !== null ||\n\t\t\t(typeof credentials.apiKey === 'string' && credentials.apiKey !== ''))\n\t)\n}\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@raster-app/sdk",
|
|
3
|
+
"version": "0.1.0-canary-2e1834e",
|
|
4
|
+
"description": "Framework-free client for the Raster REST API: OAuth, sessions, assets, libraries, search and image helpers.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"homepage": "https://raster.app/docs",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"raster",
|
|
9
|
+
"dam",
|
|
10
|
+
"assets",
|
|
11
|
+
"figma",
|
|
12
|
+
"sanity",
|
|
13
|
+
"plugin"
|
|
14
|
+
],
|
|
15
|
+
"type": "module",
|
|
16
|
+
"sideEffects": false,
|
|
17
|
+
"files": [
|
|
18
|
+
"dist"
|
|
19
|
+
],
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"exports": {
|
|
22
|
+
".": {
|
|
23
|
+
"types": "./dist/index.d.ts",
|
|
24
|
+
"default": "./dist/index.js"
|
|
25
|
+
},
|
|
26
|
+
"./package.json": "./package.json"
|
|
27
|
+
},
|
|
28
|
+
"engines": {
|
|
29
|
+
"node": ">=24"
|
|
30
|
+
},
|
|
31
|
+
"scripts": {
|
|
32
|
+
"build": "rm -rf dist && tsc -p tsconfig.build.json",
|
|
33
|
+
"prepack": "bun run build",
|
|
34
|
+
"dev": "tsc -p tsconfig.build.json --watch",
|
|
35
|
+
"check-types": "tsc --noEmit",
|
|
36
|
+
"lint": "biome lint --error-on-warnings .",
|
|
37
|
+
"test": "bun test"
|
|
38
|
+
},
|
|
39
|
+
"publishConfig": {
|
|
40
|
+
"access": "public"
|
|
41
|
+
}
|
|
42
|
+
}
|