@raster-app/react 0.1.0-rc.1 → 0.2.0-canary-846559b

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.
@@ -1,6 +1,6 @@
1
1
  import { skipToken, useQuery, useQueryClient, } from '@tanstack/react-query';
2
2
  import { useCallback } from 'react';
3
- import { meLibraryAccess, } from '@raster-app/sdk';
3
+ import { listLibraries, meLibraryAccess, } from '@raster-app/sdk';
4
4
  import { useRasterClient } from './context.js';
5
5
  import { rasterKeys } from './query-keys.js';
6
6
  import { meQuery } from './use-organizations.js';
@@ -11,7 +11,7 @@ function librariesQuery(client, queryClient, identity, organizationId, organizat
11
11
  queryKey: [...rasterKeys.libraries(identity, organizationId), organizationName],
12
12
  queryFn: async ({ signal }) => {
13
13
  const [libraries, me] = await Promise.all([
14
- client.libraries.list({ organizationId, organizationName, signal }),
14
+ listLibraries(client, { organizationId, organizationName, signal }),
15
15
  queryClient.fetchQuery(meQuery(client, identity)),
16
16
  ]);
17
17
  return libraries.map((library) => ({
@@ -1 +1 @@
1
- {"version":3,"file":"use-libraries.js","sourceRoot":"","sources":["../src/use-libraries.ts"],"names":[],"mappings":"AAAA,OAAO,EAIN,SAAS,EACT,QAAQ,EACR,cAAc,GACd,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAA;AAEnC,OAAO,EAKN,eAAe,GACf,MAAM,iBAAiB,CAAA;AAExB,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAA;AAChD,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAA;AAOxD,oGAAoG;AACpG,SAAS,cAAc,CACtB,MAAoB,EACpB,WAAwB,EACxB,QAAuB,EACvB,cAAsB,EACtB,gBAA+B;IAE/B,OAAO;QACN,QA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AI,EAAE,GAAG,OAAO,CAAA;IAE3D,MAAM,MAAM,GAAG,eAAe,EAAE,CAAA;IAChC,MAAM,WAAW,GAAG,cAAc,EAAE,CAAA;IAEpC,MAAM,QAAQ,GAAG,qBAAqB,EAAE,CAAA;IAExC,OAAO,QAAQ,CACd,cAAc,KAAK,IAAI;QACtB,CAAC,CAAC;YACA,QAAQ,EAAE,CAAC,GAAG,UAAU,CAAC,SAAS,CAAC,QAAQ,EAAE,cAAc,CAAC,EAAE,gBAAgB,CAAC;YAC/E,OAAO,EAAE,SAAS;SAClB;QACF,CAAC,CAAC;YACA,GAAG,cAAc,CAAC,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,cAAc,EAAE,gBAAgB,CAAC;YAClF,OAAO,EAAE,QAAQ,KAAK,IAAI;SAC1B,CACH,CAAA;AACF,CAAC","sourcesContent":["import {\n\ttype QueryClient,\n\ttype QueryFunctionContext,\n\ttype UseQueryResult,\n\tskipToken,\n\tuseQuery,\n\tuseQueryClient,\n} from '@tanstack/react-query'\nimport { useCallback } from 'react'\n\nimport {\n\ttype Library,\n\ttype MeLibraryAccess,\n\ttype RasterApiError,\n\ttype RasterClient,\n\tmeLibraryAccess,\n} from '@raster-app/sdk'\n\nimport { useRasterClient } from './context.js'\nimport { rasterKeys } from './query-keys.js'\nimport { meQuery } from './use-organizations.js'\nimport { useCredentialIdentity } from './use-session.js'\n\nexport type LibraryWithAccess = Library & {\n\t/** What the credential may do here. Null is no access (see `meLibraryAccess`). */\n\taccess: MeLibraryAccess['access'] | null\n}\n\n/** An organization's libraries with their access, as the list reads them and a hover warms them. */\nfunction librariesQuery(\n\tclient: RasterClient,\n\tqueryClient: QueryClient,\n\tidentity: string | null,\n\torganizationId: string,\n\torganizationName: string | null\n) {\n\treturn {\n\t\tqueryKey: [...rasterKeys.libraries(identity, organizationId), organizationName],\n\t\tqueryFn: async ({ signal }: QueryFunctionContext): Promise<Array<LibraryWithAccess>> => {\n\t\t\tconst [libraries, me] = await Promise.all([\n\t\t\t\tclient.libraries.list({ organizationId, organizationName, signal }),\n\t\t\t\tqueryClient.fetchQuery(meQuery(client, identity)),\n\t\t\t])\n\t\t\treturn libraries.map((library) => ({\n\t\t\t\t...library,\n\t\t\t\taccess: meLibraryAccess(me, organizationId, library.id),\n\t\t\t}))\n\t\t},\n\t}\n}\n\n/** Warm an organization's libraries, as a hover in the organization switcher does. */\nexport function usePrefetchLibraries(): (\n\torganizationId: string,\n\torganizationName: string | null\n) => void {\n\tconst client = useRasterClient()\n\tconst queryClient = useQueryClient()\n\tconst identity = useCredentialIdentity()\n\n\treturn useCallback(\n\t\t(organizationId, organizationName) => {\n\t\t\tif (identity === null) return\n\t\t\tvoid queryClient.prefetchQuery(\n\t\t\t\tlibrariesQuery(client, queryClient, identity, organizationId, organizationName)\n\t\t\t)\n\t\t},\n\t\t[client, queryClient, identity]\n\t)\n}\n\n/**\n * Every library in one organization, each with the credential's access to it, so a host can\n * hide upload where it is read-only.\n *\n * Pass a null `organizationId` before one has been resolved; the hook then sits idle rather\n * than fetching against a placeholder.\n */\nexport function useLibraries(options: {\n\torganizationId: string | null\n\torganizationName?: string | null\n}): UseQueryResult<Array<LibraryWithAccess>, RasterApiError> {\n\tconst { organizationId, organizationName = null } = options\n\n\tconst client = useRasterClient()\n\tconst queryClient = useQueryClient()\n\n\tconst identity = useCredentialIdentity()\n\n\treturn useQuery<Array<LibraryWithAccess>, RasterApiError>(\n\t\torganizationId === null\n\t\t\t? {\n\t\t\t\t\tqueryKey: [...rasterKeys.libraries(identity, organizationId), organizationName],\n\t\t\t\t\tqueryFn: skipToken,\n\t\t\t\t}\n\t\t\t: {\n\t\t\t\t\t...librariesQuery(client, queryClient, identity, organizationId, organizationName),\n\t\t\t\t\tenabled: identity !== null,\n\t\t\t\t}\n\t)\n}\n"]}
1
+ {"version":3,"file":"use-libraries.js","sourceRoot":"","sources":["../src/use-libraries.ts"],"names":[],"mappings":"AAAA,OAAO,EAIN,SAAS,EACT,QAAQ,EAC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pC,MAAM,QAAQ,GAAG,qBAAqB,EAAE,CAAA;IAExC,OAAO,WAAW,CACjB,CAAC,cAAc,EAAE,gBAAgB,EAAE,EAAE;QACpC,IAAI,QAAQ,KAAK,IAAI;YAAE,OAAM;QAC7B,KAAK,WAAW,CAAC,aAAa,CAC7B,cAAc,CAAC,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,cAAc,EAAE,gBAAgB,CAAC,CAC/E,CAAA;IACF,CAAC,EACD,CAAC,MAAM,EAAE,WAAW,EAAE,QAAQ,CAAC,CAC/B,CAAA;AACF,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,CAAC,OAG5B;IACA,MAAM,EAAE,cAAc,EAAE,gBAAgB,GAAG,IAAI,EAAE,GAAG,OAAO,CAAA;IAE3D,MAAM,MAAM,GAAG,eAAe,EAAE,CAAA;IAChC,MAAM,WAAW,GAAG,cAAc,EAAE,CAAA;IAEpC,MAAM,QAAQ,GAAG,qBAAqB,EAAE,CAAA;IAExC,OAAO,QAAQ,CACd,cAAc,KAAK,IAAI;QACtB,CAAC,CAAC;YACA,QAAQ,EAAE,CAAC,GAAG,UAAU,CAAC,SAAS,CAAC,QAAQ,EAAE,cAAc,CAAC,EAAE,gBAAgB,CAAC;YAC/E,OAAO,EAAE,SAAS;SAClB;QACF,CAAC,CAAC;YACA,GAAG,cAAc,CAAC,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,cAAc,EAAE,gBAAgB,CAAC;YAClF,OAAO,EAAE,QAAQ,KAAK,IAAI;SAC1B,CACH,CAAA;AACF,CAAC","sourcesContent":["import {\n\ttype QueryClient,\n\ttype QueryFunctionContext,\n\ttype UseQueryResult,\n\tskipToken,\n\tuseQuery,\n\tuseQueryClient,\n} from '@tanstack/react-query'\nimport { useCallback } from 'react'\n\nimport {\n\ttype Library,\n\ttype MeLibraryAccess,\n\ttype RasterApiError,\n\ttype RasterClient,\n\tlistLibraries,\n\tmeLibraryAccess,\n} from '@raster-app/sdk'\n\nimport { useRasterClient } from './context.js'\nimport { rasterKeys } from './query-keys.js'\nimport { meQuery } from './use-organizations.js'\nimport { useCredentialIdentity } from './use-session.js'\n\nexport type LibraryWithAccess = Library & {\n\t/** What the credential may do here. Null is no access (see `meLibraryAccess`). */\n\taccess: MeLibraryAccess['access'] | null\n}\n\n/** An organization's libraries with their access, as the list reads them and a hover warms them. */\nfunction librariesQuery(\n\tclient: RasterClient,\n\tqueryClient: QueryClient,\n\tidentity: string | null,\n\torganizationId: string,\n\torganizationName: string | null\n) {\n\treturn {\n\t\tqueryKey: [...rasterKeys.libraries(identity, organizationId), organizationName],\n\t\tqueryFn: async ({ signal }: QueryFunctionContext): Promise<Array<LibraryWithAccess>> => {\n\t\t\tconst [libraries, me] = await Promise.all([\n\t\t\t\tlistLibraries(client, { organizationId, organizationName, signal }),\n\t\t\t\tqueryClient.fetchQuery(meQuery(client, identity)),\n\t\t\t])\n\t\t\treturn libraries.map((library) => ({\n\t\t\t\t...library,\n\t\t\t\taccess: meLibraryAccess(me, organizationId, library.id),\n\t\t\t}))\n\t\t},\n\t}\n}\n\n/** Warm an organization's libraries, as a hover in the organization switcher does. */\nexport function usePrefetchLibraries(): (\n\torganizationId: string,\n\torganizationName: string | null\n) => void {\n\tconst client = useRasterClient()\n\tconst queryClient = useQueryClient()\n\tconst identity = useCredentialIdentity()\n\n\treturn useCallback(\n\t\t(organizationId, organizationName) => {\n\t\t\tif (identity === null) return\n\t\t\tvoid queryClient.prefetchQuery(\n\t\t\t\tlibrariesQuery(client, queryClient, identity, organizationId, organizationName)\n\t\t\t)\n\t\t},\n\t\t[client, queryClient, identity]\n\t)\n}\n\n/**\n * Every library in one organization, each with the credential's access to it, so a host can\n * hide upload where it is read-only.\n *\n * Pass a null `organizationId` before one has been resolved; the hook then sits idle rather\n * than fetching against a placeholder.\n */\nexport function useLibraries(options: {\n\torganizationId: string | null\n\torganizationName?: string | null\n}): UseQueryResult<Array<LibraryWithAccess>, RasterApiError> {\n\tconst { organizationId, organizationName = null } = options\n\n\tconst client = useRasterClient()\n\tconst queryClient = useQueryClient()\n\n\tconst identity = useCredentialIdentity()\n\n\treturn useQuery<Array<LibraryWithAccess>, RasterApiError>(\n\t\torganizationId === null\n\t\t\t? {\n\t\t\t\t\tqueryKey: [...rasterKeys.libraries(identity, organizationId), organizationName],\n\t\t\t\t\tqueryFn: skipToken,\n\t\t\t\t}\n\t\t\t: {\n\t\t\t\t\t...librariesQuery(client, queryClient, identity, organizationId, organizationName),\n\t\t\t\t\tenabled: identity !== null,\n\t\t\t\t}\n\t)\n}\n"]}
@@ -1,11 +1,11 @@
1
1
  import { useQuery } from '@tanstack/react-query';
2
- import { meOrganizationList, } from '@raster-app/sdk';
2
+ import { getMe, meOrganizationList, } from '@raster-app/sdk';
3
3
  import { useRasterClient } from './context.js';
4
4
  import { rasterKeys } from './query-keys.js';
5
5
  import { useCredentialIdentity } from './use-session.js';
6
6
  /** `/me`, which both the organization list and each library's access are read from. */
7
7
  export function meQuery(client, identity) {
8
- return { queryKey: rasterKeys.me(identity), queryFn: () => client.me() };
8
+ return { queryKey: rasterKeys.me(identity), queryFn: () => getMe(client) };
9
9
  }
10
10
  /**
11
11
  * Every organization the current credential reaches, resolved from `/me`. An account in none
@@ -1 +1 @@
1
- {"version":3,"file":"use-organizations.js","sourceRoot":"","sources":["../src/use-organizations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAErE,OAAO,EAKN,kBAAkB,GAClB,MAAM,iBAAiB,CAAA;AAExB,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAA;AAExD,uFAAuF;AACvF,MAAM,UAAU,OAAO,CAAC,MAAoB,EAAE,QAAuB;IACpE,OAAO,EAAE,QAAQ,EAAE,UAAU,CAAC,EAAE,CAAC,QAAQ,CAAC,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,CAAA;AACzE,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,gBAAgB;IAC/B,MAAM,MAAM,GAAG,eAAe,EAAE,CAAA;IAEhC,MAAM,QAAQ,GAAG,qBAAqB,EAAE,CAAA;IAExC,OAAO,QAAQ,CAA0C;QACxD,GAAG,OAAO,CAAC,MAAM,EAAE,QAAQ,CAAC;QAC5B,MAAM,EAAE,kBAAkB;QAC1B,OAAO,EAAE,QAAQ,KAAK,IAAI;KAC1B,CAAC,CAAA;AACH,CAAC","sourcesContent":["import { type UseQueryResult, useQuery } from '@tanstack/react-query'\n\nimport {\n\ttype Me,\n\ttype Organization,\n\ttype RasterApiError,\n\ttype RasterClient,\n\tmeOrganizationList,\n} from '@raster-app/sdk'\n\nimport { useRasterClient } from './context.js'\nimport { rasterKeys } from './query-keys.js'\nimport { useCredentialIdentity } from './use-session.js'\n\n/** `/me`, which both the organization list and each library's access are read from. */\nexport function meQuery(client: RasterClient, identity: string | null) {\n\treturn { queryKey: rasterKeys.me(identity), queryFn: () => client.me() }\n}\n\n/**\n * Every organization the current credential reaches, resolved from `/me`. An account in none\n * gets an empty list.\n */\nexport function useOrganizations(): UseQueryResult<Array<Organization>, RasterApiError> {\n\tconst client = useRasterClient()\n\n\tconst identity = useCredentialIdentity()\n\n\treturn useQuery<Me, RasterApiError, Array<Organization>>({\n\t\t...meQuery(client, identity),\n\t\tselect: meOrganizationList,\n\t\tenabled: identity !== null,\n\t})\n}\n"]}
1
+ {"version":3,"file":"use-organizations.js","sourceRoot":"","sources":["../src/use-organizations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAErE,OAAO,EAKN,KAAK,EACL,kBAAkB,GAClB,MAAM,iBAAiB,CAAA;AAExB,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAA;AAExD,uFAAuF;AACvF,MAAM,UAAU,OAAO,CAAC,MAAoB,EAAE,QAAuB;IACpE,OAAO,EAAE,QAAQ,EAAE,UAAU,CAAC,EAAE,CAAC,QAAQ,CAAC,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,CAAA;AAC3E,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,gBAAgB;IAC/B,MAAM,MAAM,GAAG,eAAe,EAAE,CAAA;IAEhC,MAAM,QAAQ,GAAG,qBAAqB,EAAE,CAAA;IAExC,OAAO,QAAQ,CAA0C;QACxD,GAAG,OAAO,CAAC,MAAM,EAAE,QAAQ,CAAC;QAC5B,MAAM,EAAE,kBAAkB;QAC1B,OAAO,EAAE,QAAQ,KAAK,IAAI;KAC1B,CAAC,CAAA;AACH,CAAC","sourcesContent":["import { type UseQueryResult, useQuery } from '@tanstack/react-query'\n\nimport {\n\ttype Me,\n\ttype Organization,\n\ttype RasterApiError,\n\ttype RasterClient,\n\tgetMe,\n\tmeOrganizationList,\n} from '@raster-app/sdk'\n\nimport { useRasterClient } from './context.js'\nimport { rasterKeys } from './query-keys.js'\nimport { useCredentialIdentity } from './use-session.js'\n\n/** `/me`, which both the organization list and each library's access are read from. */\nexport function meQuery(client: RasterClient, identity: string | null) {\n\treturn { queryKey: rasterKeys.me(identity), queryFn: () => getMe(client) }\n}\n\n/**\n * Every organization the current credential reaches, resolved from `/me`. An account in none\n * gets an empty list.\n */\nexport function useOrganizations(): UseQueryResult<Array<Organization>, RasterApiError> {\n\tconst client = useRasterClient()\n\n\tconst identity = useCredentialIdentity()\n\n\treturn useQuery<Me, RasterApiError, Array<Organization>>({\n\t\t...meQuery(client, identity),\n\t\tselect: meOrganizationList,\n\t\tenabled: identity !== null,\n\t})\n}\n"]}
@@ -1,4 +1,4 @@
1
- import type { Asset, RasterApiError } from '@raster-app/sdk';
1
+ import { type Asset, type RasterApiError } from '@raster-app/sdk';
2
2
  type PromoteOptions = {
3
3
  organizationId: string;
4
4
  libraryId: string;
@@ -33,7 +33,7 @@ export type VariantPromote = {
33
33
  state: PromoteState;
34
34
  /**
35
35
  * Promote a variant to be its asset's default, then wait until Raster has swapped the files
36
- * (`assets.waitUntilPromoted`). Resolves with the asset as it then reads; null leaves the
36
+ * (`waitUntilPromoted`). Resolves with the asset as it then reads; null leaves the
37
37
  * rest to `state`.
38
38
  */
39
39
  promote: (options: PromoteOptions) => Promise<Asset | null>;
@@ -1,5 +1,6 @@
1
1
  import { useMutation, useQueryClient, } from '@tanstack/react-query';
2
2
  import { useCallback } from 'react';
3
+ import { promoteVariant, waitUntilPromoted } from '@raster-app/sdk';
3
4
  import { useRasterClient } from './context.js';
4
5
  import { rasterKeys } from './query-keys.js';
5
6
  import { useCredentialIdentity } from './use-session.js';
@@ -26,8 +27,8 @@ export function usePromoteVariant() {
26
27
  const identity = useCredentialIdentity();
27
28
  const mutation = useMutation({
28
29
  mutationFn: async (options) => {
29
- await client.assets.promote(options);
30
- return client.assets.waitUntilPromoted(options);
30
+ await promoteVariant(client, options);
31
+ return waitUntilPromoted(client, options);
31
32
  },
32
33
  onMutate: async ({ organizationId, libraryId, assetId, optimistic }) => {
33
34
  if (optimistic === undefined)
@@ -1 +1 @@
1
- {"version":3,"file":"use-promote-variant.js","sourceRoot":"","sources":["../src/use-promote-variant.ts"],"names":[],"mappings":"AAAA,OAAO,EAGN,WAAW,EACX,cAAc,GACd,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAA;AAInC,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAA;AAsCxD,SAAS,YAAY,CAC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AAW,EAAE,KAAK,EAAE,GAAG,QAAQ,CAAA;IACvC,MAAM,KAAK,GAAG,YAAY,CAAC,QAAQ,CAAC,CAAA;IAEpC,MAAM,OAAO,GAAG,WAAW,CAC1B,KAAK,EAAE,OAAO,EAAE,EAAE;QACjB,IAAI,CAAC;YACJ,OAAO,MAAM,WAAW,CAAC,OAAO,CAAC,CAAA;QAClC,CAAC;QAAC,MAAM,CAAC;YACR,OAAO,IAAI,CAAA;QACZ,CAAC;IACF,CAAC,EACD,CAAC,WAAW,CAAC,CACb,CAAA;IAED,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,CAAA;AACjC,CAAC","sourcesContent":["import {\n\ttype InfiniteData,\n\ttype UseMutationResult,\n\tuseMutation,\n\tuseQueryClient,\n} from '@tanstack/react-query'\nimport { useCallback } from 'react'\n\nimport type { Asset, RasterApiError } from '@raster-app/sdk'\n\nimport { useRasterClient } from './context.js'\nimport { rasterKeys } from './query-keys.js'\nimport { useCredentialIdentity } from './use-session.js'\n\ntype PromoteOptions = {\n\torganizationId: string\n\tlibraryId: string\n\t/** The asset whose default is being replaced. */\n\tassetId: string\n\t/** The variant to make the new default. */\n\tvariantId: string\n\t/**\n\t * Applied to the asset in the library's cached list straight away, and kept until the swap\n\t * lands or fails — say, to show the variant as the default already.\n\t */\n\toptimistic?: (asset: Asset) => Asset\n}\n\nexport type PromoteState =\n\t| { status: 'idle' }\n\t| { status: 'promoting' }\n\t/** The swap landed; `asset` is the asset as it now reads. */\n\t| { status: 'done'; asset: Asset }\n\t/** Raster took the promote, but had not swapped the files when the wait gave up. */\n\t| { status: 'timed-out' }\n\t| { status: 'error'; error: RasterApiError }\n\nexport type VariantPromote = {\n\tstate: PromoteState\n\t/**\n\t * Promote a variant to be its asset's default, then wait until Raster has swapped the files\n\t * (`assets.waitUntilPromoted`). Resolves with the asset as it then reads; null leaves the\n\t * rest to `state`.\n\t */\n\tpromote: (options: PromoteOptions) => Promise<Asset | null>\n\treset: () => void\n}\n\ntype AssetPages = InfiniteData<Array<Asset>>\n\nfunction replaceAsset(\n\tdata: AssetPages | undefined,\n\tassetId: string,\n\tupdate: (asset: Asset) => Asset\n): AssetPages | undefined {\n\tif (data === undefined) return undefined\n\treturn {\n\t\t...data,\n\t\tpages: data.pages.map((page) =>\n\t\t\tpage.map((asset) => (asset.id === assetId ? update(asset) : asset))\n\t\t),\n\t}\n}\n\nfunction promoteState(\n\tmutation: UseMutationResult<Asset | null, RasterApiError, PromoteOptions>\n): PromoteState {\n\tif (mutation.isPending) return { status: 'promoting' }\n\tif (mutation.isError) return { status: 'error', error: mutation.error }\n\tif (!mutation.isSuccess) return { status: 'idle' }\n\treturn mutation.data === null ? { status: 'timed-out' } : { status: 'done', asset: mutation.data }\n}\n\nexport function usePromoteVariant(): VariantPromote {\n\tconst client = useRasterClient()\n\tconst queryClient = useQueryClient()\n\n\tconst identity = useCredentialIdentity()\n\tconst mutation = useMutation<Asset | null, RasterApiError, PromoteOptions>({\n\t\tmutationFn: async (options) => {\n\t\t\tawait client.assets.promote(options)\n\t\t\treturn client.assets.waitUntilPromoted(options)\n\t\t},\n\t\tonMutate: async ({ organizationId, libraryId, assetId, optimistic }) => {\n\t\t\tif (optimistic === undefined) return\n\t\t\tconst key = rasterKeys.assets(identity, organizationId, libraryId)\n\t\t\t// A page landing after this would put the asset back as it was.\n\t\t\tawait queryClient.cancelQueries({ queryKey: key })\n\t\t\tqueryClient.setQueryData<AssetPages>(key, (data) => replaceAsset(data, assetId, optimistic))\n\t\t},\n\t\t// Landed, the asset as it now reads replaces the cached one. Otherwise the list is read\n\t\t// again, which also undoes an optimistic update that never landed.\n\t\tonSettled: (asset, _error, { organizationId, libraryId, assetId }) => {\n\t\t\tconst key = rasterKeys.assets(identity, organizationId, libraryId)\n\t\t\tif (asset) {\n\t\t\t\tqueryClient.setQueryData<AssetPages>(key, (data) =>\n\t\t\t\t\treplaceAsset(data, assetId, () => asset)\n\t\t\t\t)\n\t\t\t} else {\n\t\t\t\tvoid queryClient.invalidateQueries({ queryKey: key })\n\t\t\t}\n\t\t\tvoid queryClient.invalidateQueries({ queryKey: rasterKeys.search(identity, organizationId) })\n\t\t},\n\t})\n\n\tconst { mutateAsync, reset } = mutation\n\tconst state = promoteState(mutation)\n\n\tconst promote = useCallback<VariantPromote['promote']>(\n\t\tasync (options) => {\n\t\t\ttry {\n\t\t\t\treturn await mutateAsync(options)\n\t\t\t} catch {\n\t\t\t\treturn null\n\t\t\t}\n\t\t},\n\t\t[mutateAsync]\n\t)\n\n\treturn { state, promote, reset }\n}\n"]}
1
+ {"version":3,"file":"use-promote-variant.js","sourceRoot":"","sources":["../src/use-promote-variant.ts"],"names":[],"mappings":"AAAA,OAAO,EAGN,WAAW,EACX,cAAc,GACd,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAA;AAEnC,OAAO,EAAmC,cAAc,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAA;AAEpG,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAA;AAsCxD,SAAS,YAAY,CACpB,IAA4B,EAC5B,OAAe,EACf,MAA+B;IAE/B,IAAI,IAAI,KAAK,SAAS;QAAE,OAAO,SAAS,CAAA;IACxC,OAAO;QACN,GAAG,IAAI;QACP,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAC9B,IAAI,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,EAAE,KAAK,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CACnE;KACD,CAAA;AACF,CAAC;AAED,SAAS,YAAY,CACpB,QAAyE;IAEzE,IAA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Mutation,\n\tuseQueryClient,\n} from '@tanstack/react-query'\nimport { useCallback } from 'react'\n\nimport { type Asset, type RasterApiError, promoteVariant, waitUntilPromoted } from '@raster-app/sdk'\n\nimport { useRasterClient } from './context.js'\nimport { rasterKeys } from './query-keys.js'\nimport { useCredentialIdentity } from './use-session.js'\n\ntype PromoteOptions = {\n\torganizationId: string\n\tlibraryId: string\n\t/** The asset whose default is being replaced. */\n\tassetId: string\n\t/** The variant to make the new default. */\n\tvariantId: string\n\t/**\n\t * Applied to the asset in the library's cached list straight away, and kept until the swap\n\t * lands or fails — say, to show the variant as the default already.\n\t */\n\toptimistic?: (asset: Asset) => Asset\n}\n\nexport type PromoteState =\n\t| { status: 'idle' }\n\t| { status: 'promoting' }\n\t/** The swap landed; `asset` is the asset as it now reads. */\n\t| { status: 'done'; asset: Asset }\n\t/** Raster took the promote, but had not swapped the files when the wait gave up. */\n\t| { status: 'timed-out' }\n\t| { status: 'error'; error: RasterApiError }\n\nexport type VariantPromote = {\n\tstate: PromoteState\n\t/**\n\t * Promote a variant to be its asset's default, then wait until Raster has swapped the files\n\t * (`waitUntilPromoted`). Resolves with the asset as it then reads; null leaves the\n\t * rest to `state`.\n\t */\n\tpromote: (options: PromoteOptions) => Promise<Asset | null>\n\treset: () => void\n}\n\ntype AssetPages = InfiniteData<Array<Asset>>\n\nfunction replaceAsset(\n\tdata: AssetPages | undefined,\n\tassetId: string,\n\tupdate: (asset: Asset) => Asset\n): AssetPages | undefined {\n\tif (data === undefined) return undefined\n\treturn {\n\t\t...data,\n\t\tpages: data.pages.map((page) =>\n\t\t\tpage.map((asset) => (asset.id === assetId ? update(asset) : asset))\n\t\t),\n\t}\n}\n\nfunction promoteState(\n\tmutation: UseMutationResult<Asset | null, RasterApiError, PromoteOptions>\n): PromoteState {\n\tif (mutation.isPending) return { status: 'promoting' }\n\tif (mutation.isError) return { status: 'error', error: mutation.error }\n\tif (!mutation.isSuccess) return { status: 'idle' }\n\treturn mutation.data === null ? { status: 'timed-out' } : { status: 'done', asset: mutation.data }\n}\n\nexport function usePromoteVariant(): VariantPromote {\n\tconst client = useRasterClient()\n\tconst queryClient = useQueryClient()\n\n\tconst identity = useCredentialIdentity()\n\tconst mutation = useMutation<Asset | null, RasterApiError, PromoteOptions>({\n\t\tmutationFn: async (options) => {\n\t\t\tawait promoteVariant(client, options)\n\t\t\treturn waitUntilPromoted(client, options)\n\t\t},\n\t\tonMutate: async ({ organizationId, libraryId, assetId, optimistic }) => {\n\t\t\tif (optimistic === undefined) return\n\t\t\tconst key = rasterKeys.assets(identity, organizationId, libraryId)\n\t\t\t// A page landing after this would put the asset back as it was.\n\t\t\tawait queryClient.cancelQueries({ queryKey: key })\n\t\t\tqueryClient.setQueryData<AssetPages>(key, (data) => replaceAsset(data, assetId, optimistic))\n\t\t},\n\t\t// Landed, the asset as it now reads replaces the cached one. Otherwise the list is read\n\t\t// again, which also undoes an optimistic update that never landed.\n\t\tonSettled: (asset, _error, { organizationId, libraryId, assetId }) => {\n\t\t\tconst key = rasterKeys.assets(identity, organizationId, libraryId)\n\t\t\tif (asset) {\n\t\t\t\tqueryClient.setQueryData<AssetPages>(key, (data) =>\n\t\t\t\t\treplaceAsset(data, assetId, () => asset)\n\t\t\t\t)\n\t\t\t} else {\n\t\t\t\tvoid queryClient.invalidateQueries({ queryKey: key })\n\t\t\t}\n\t\t\tvoid queryClient.invalidateQueries({ queryKey: rasterKeys.search(identity, organizationId) })\n\t\t},\n\t})\n\n\tconst { mutateAsync, reset } = mutation\n\tconst state = promoteState(mutation)\n\n\tconst promote = useCallback<VariantPromote['promote']>(\n\t\tasync (options) => {\n\t\t\ttry {\n\t\t\t\treturn await mutateAsync(options)\n\t\t\t} catch {\n\t\t\t\treturn null\n\t\t\t}\n\t\t},\n\t\t[mutateAsync]\n\t)\n\n\treturn { state, promote, reset }\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  import { useCallback, useEffect, useSyncExternalStore } from 'react';
2
- import { isConfigured as isConfiguredCredentials } from '@raster-app/sdk';
2
+ import { getCredentialIdentity, getSession, isConfigured as isConfiguredCredentials, loadSession, onSessionChange, signOut as signOutClient, } from '@raster-app/sdk';
3
3
  import { useRasterClient } from './context.js';
4
4
  /**
5
5
  * The current credential, re-rendering on every change — a sign-in, a token refresh, a
@@ -7,12 +7,12 @@ import { useRasterClient } from './context.js';
7
7
  */
8
8
  export function useSession() {
9
9
  const client = useRasterClient();
10
- const credentials = useSyncExternalStore(useCallback((listener) => client.session.subscribe(listener), [client]), () => client.session.current(), () => undefined);
11
- const signOut = useCallback(() => client.auth.signOut(), [client]);
10
+ const credentials = useSyncExternalStore(useCallback((listener) => onSessionChange(client, listener), [client]), () => getSession(client), () => undefined);
11
+ const signOut = useCallback(() => signOutClient(client), [client]);
12
12
  // Hydration is single-flight in the SDK, so calling it from every mounted consumer costs
13
13
  // one store read in total.
14
14
  useEffect(() => {
15
- void client.session.hydrate().catch(() => {
15
+ void loadSession(client).catch(() => {
16
16
  // A store that cannot be read leaves the client signed out, so the host shows its
17
17
  // sign-in screen.
18
18
  });
@@ -32,6 +32,6 @@ export function useSession() {
32
32
  export function useCredentialIdentity() {
33
33
  const client = useRasterClient();
34
34
  const { isConfigured } = useSession();
35
- return isConfigured ? client.session.credentialIdentity() : null;
35
+ return isConfigured ? getCredentialIdentity(client) : null;
36
36
  }
37
37
  //# sourceMappingURL=use-session.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-session.js","sourceRoot":"","sources":["../src/use-session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAA;AAEpE,OAAO,EAA0B,YAAY,IAAI,uBAAuB,EAAE,MAAM,iBAAiB,CAAA;AAEjG,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAc9C;;;GAGG;AACH,MAAM,UAAU,UAAU;IACzB,MAAM,MAAM,GAAG,eAAe,EAAE,CAAA;IAEhC,MAAM,WAAW,GAAG,oBAAoB,CACvC,WAAW,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,EACvE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,EAC9B,GAAG,EAAE,CAAC,SAAS,CACf,CAAA;IAED,MAAM,OAAO,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,CAAA;IAElE,yFAAyF;IACzF,2BAA2B;IAC3B,SAAS,CAAC,GAAG,EAAE;QACd,KAAK,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE;YACxC,kFAAkF;YAClF,kBAAkB;QACnB,CAAC,CAAC,CAAA;IACH,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAA;IAEZ,OAAO;QACN,WAAW;QACX,YAAY,EAAE,uBAAuB,CAAC,WAAW,CAAC;QAClD,UAAU,EAAE,WAAW,EAAE,KAAK,IAAI,IAAI;QACtC,QAAQ,EAAE,WAAW,EAAE,QAAQ,IAAI,IAAI;QACvC,OAAO;KACP,CAAA;AACF,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,qBAAqB;IACpC,MAAM,MAAM,GAAG,eAAe,EAAE,CAAA;IAChC,MAAM,EAAE,YAAY,EAAE,GAAG,UAAU,EAAE,CAAA;IAErC,OAAO,YAAY,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,kBAAkB,EAAE,CAAC,CAAC,CAAC,IAAI,CAAA;AACjE,CAAC","sourcesContent":["import { useCallback, useEffect, useSyncExternalStore } from 'react'\n\nimport { type StoredCredentials, isConfigured as isConfiguredCredentials } from '@raster-app/sdk'\n\nimport { useRasterClient } from './context.js'\n\nexport type RasterSession = {\n\t/** `undefined` until the store has been read. Distinguishes \"loading\" from \"signed out\". */\n\tcredentials: StoredCredentials | undefined\n\t/** Whether there is any credential to call the API with — a session or an API key. */\n\tisConfigured: boolean\n\t/** Whether the credential is an OAuth session specifically (an API key is not). */\n\tisSignedIn: boolean\n\t/** The account name, for \"Signed in as …\". Null for an API key. */\n\tuserName: string | null\n\tsignOut: () => Promise<void>\n}\n\n/**\n * The current credential, re-rendering on every change — a sign-in, a token refresh, a\n * sign-out. `useSyncExternalStore` also catches a change between render and effect.\n */\nexport function useSession(): RasterSession {\n\tconst client = useRasterClient()\n\n\tconst credentials = useSyncExternalStore(\n\t\tuseCallback((listener) => client.session.subscribe(listener), [client]),\n\t\t() => client.session.current(),\n\t\t() => undefined\n\t)\n\n\tconst signOut = useCallback(() => client.auth.signOut(), [client])\n\n\t// Hydration is single-flight in the SDK, so calling it from every mounted consumer costs\n\t// one store read in total.\n\tuseEffect(() => {\n\t\tvoid client.session.hydrate().catch(() => {\n\t\t\t// A store that cannot be read leaves the client signed out, so the host shows its\n\t\t\t// sign-in screen.\n\t\t})\n\t}, [client])\n\n\treturn {\n\t\tcredentials,\n\t\tisConfigured: isConfiguredCredentials(credentials),\n\t\tisSignedIn: credentials?.oauth != null,\n\t\tuserName: credentials?.userName ?? null,\n\t\tsignOut,\n\t}\n}\n\n/**\n * The sign-in every query key is scoped by, or null while there is none to fetch with. A token\n * refresh keeps it; a different account, or the same one signing in again, changes it.\n */\nexport function useCredentialIdentity(): string | null {\n\tconst client = useRasterClient()\n\tconst { isConfigured } = useSession()\n\n\treturn isConfigured ? client.session.credentialIdentity() : null\n}\n"]}
1
+ {"version":3,"file":"use-session.js","sourceRoot":"","sources":["../src/use-session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAA;AAEpE,OAAO,EAEN,qBAAqB,EACrB,UAAU,EACV,YAAY,IAAI,uBAAuB,EACvC,WAAW,EACX,eAAe,EACf,OAAO,IAAI,aAAa,GACxB,MAAM,iBA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CredentialIdentity,\n\tgetSession,\n\tisConfigured as isConfiguredCredentials,\n\tloadSession,\n\tonSessionChange,\n\tsignOut as signOutClient,\n} from '@raster-app/sdk'\n\nimport { useRasterClient } from './context.js'\n\nexport type RasterSession = {\n\t/** `undefined` until the store has been read. Distinguishes \"loading\" from \"signed out\". */\n\tcredentials: StoredCredentials | undefined\n\t/** Whether there is any credential to call the API with — a session or an API key. */\n\tisConfigured: boolean\n\t/** Whether the credential is an OAuth session specifically (an API key is not). */\n\tisSignedIn: boolean\n\t/** The account name, for \"Signed in as …\". Null for an API key. */\n\tuserName: string | null\n\tsignOut: () => Promise<void>\n}\n\n/**\n * The current credential, re-rendering on every change — a sign-in, a token refresh, a\n * sign-out. `useSyncExternalStore` also catches a change between render and effect.\n */\nexport function useSession(): RasterSession {\n\tconst client = useRasterClient()\n\n\tconst credentials = useSyncExternalStore(\n\t\tuseCallback((listener) => onSessionChange(client, listener), [client]),\n\t\t() => getSession(client),\n\t\t() => undefined\n\t)\n\n\tconst signOut = useCallback(() => signOutClient(client), [client])\n\n\t// Hydration is single-flight in the SDK, so calling it from every mounted consumer costs\n\t// one store read in total.\n\tuseEffect(() => {\n\t\tvoid loadSession(client).catch(() => {\n\t\t\t// A store that cannot be read leaves the client signed out, so the host shows its\n\t\t\t// sign-in screen.\n\t\t})\n\t}, [client])\n\n\treturn {\n\t\tcredentials,\n\t\tisConfigured: isConfiguredCredentials(credentials),\n\t\tisSignedIn: credentials?.oauth != null,\n\t\tuserName: credentials?.userName ?? null,\n\t\tsignOut,\n\t}\n}\n\n/**\n * The sign-in every query key is scoped by, or null while there is none to fetch with. A token\n * refresh keeps it; a different account, or the same one signing in again, changes it.\n */\nexport function useCredentialIdentity(): string | null {\n\tconst client = useRasterClient()\n\tconst { isConfigured } = useSession()\n\n\treturn isConfigured ? getCredentialIdentity(client) : null\n}\n"]}
@@ -26,7 +26,7 @@ export type SignIn = {
26
26
  * Drives both ways in — the device grant and an API key — and holds their state: a device
27
27
  * grant waiting on the user, or the error that ended an attempt. Read the credential itself
28
28
  * with `useSession`. `scope` and `organizationId` go to the device grant, as
29
- * `auth.signInWithDevice` takes them.
29
+ * `signInWithDevice` takes them.
30
30
  */
31
31
  export declare function useSignIn(options?: {
32
32
  scope?: 'user' | 'org';
@@ -1,11 +1,11 @@
1
1
  import { useCallback, useEffect, useRef, useState } from 'react';
2
- import { isAbortError, toRasterApiError, } from '@raster-app/sdk';
2
+ import { connectApiKey as connectKey, isAbortError, signInWithDevice as startDeviceSignIn, toRasterApiError, } from '@raster-app/sdk';
3
3
  import { useRasterClient } from './context.js';
4
4
  /**
5
5
  * Drives both ways in — the device grant and an API key — and holds their state: a device
6
6
  * grant waiting on the user, or the error that ended an attempt. Read the credential itself
7
7
  * with `useSession`. `scope` and `organizationId` go to the device grant, as
8
- * `auth.signInWithDevice` takes them.
8
+ * `signInWithDevice` takes them.
9
9
  */
10
10
  export function useSignIn(options = {}) {
11
11
  const { scope, organizationId } = options;
@@ -32,7 +32,7 @@ export function useSignIn(options = {}) {
32
32
  controllerRef.current = controller;
33
33
  settle({ status: 'connecting' });
34
34
  try {
35
- await client.auth.signInWithDevice({
35
+ await startDeviceSignIn(client, {
36
36
  signal: controller.signal,
37
37
  onCode: (device) => settle({ status: 'awaitingApproval', device }),
38
38
  scope,
@@ -47,7 +47,7 @@ export function useSignIn(options = {}) {
47
47
  const connectApiKey = useCallback(async (apiKey) => {
48
48
  settle({ status: 'connecting' });
49
49
  try {
50
- await client.auth.connect({ apiKey });
50
+ await connectKey(client, { apiKey });
51
51
  settle({ status: 'idle' });
52
52
  }
53
53
  catch (caught) {
@@ -1 +1 @@
1
- {"version":3,"file":"use-sign-in.js","sourceRoot":"","sources":["../src/use-sign-in.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAEhE,OAAO,EAGN,YAAY,EACZ,gBAAgB,GAChB,MAAM,iBAAiB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AM,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAA;IAErE,SAAS,CAAC,GAAG,EAAE;QACd,UAAU,CAAC,OAAO,GAAG,IAAI,CAAA;QACzB,OAAO,GAAG,EAAE;YACX,UAAU,CAAC,OAAO,GAAG,KAAK,CAAA;YAC1B,mFAAmF;YACnF,gEAAgE;YAChE,aAAa,CAAC,OAAO,EAAE,KAAK,EAAE,CAAA;QAC/B,CAAC,CAAA;IACF,CAAC,EAAE,EAAE,CAAC,CAAA;IAEN,OAAO;QACN,KAAK;QACL,gBAAgB;QAChB,aAAa;QACb,MAAM;QACN,KAAK;KACL,CAAA;AACF,CAAC","sourcesContent":["import { useCallback, useEffect, useRef, useState } from 'react'\n\nimport {\n\ttype DeviceAuthorization,\n\ttype RasterApiError,\n\tisAbortError,\n\ttoRasterApiError,\n} from '@raster-app/sdk'\n\nimport { useRasterClient } from './context.js'\n\nexport type SignInState =\n\t| { status: 'idle' }\n\t| { status: 'connecting' }\n\t/** The device grant is waiting for the user to approve in their browser. */\n\t| { status: 'awaitingApproval'; device: DeviceAuthorization }\n\t| { status: 'error'; error: RasterApiError }\n\nexport type SignIn = {\n\tstate: SignInState\n\t/** Device grant (RFC 8628). Works in every host. */\n\tsignInWithDevice: () => Promise<void>\n\t/** Verify and adopt a pasted organization API key. */\n\tconnectApiKey: (apiKey: string) => Promise<void>\n\t/** Abandon a device sign-in that is still waiting. */\n\tcancel: () => void\n\treset: () => void\n}\n\n/**\n * Drives both ways in — the device grant and an API key — and holds their state: a device\n * grant waiting on the user, or the error that ended an attempt. Read the credential itself\n * with `useSession`. `scope` and `organizationId` go to the device grant, as\n * `auth.signInWithDevice` takes them.\n */\nexport function useSignIn(\n\toptions: { scope?: 'user' | 'org'; organizationId?: string } = {}\n): SignIn {\n\tconst { scope, organizationId } = options\n\tconst client = useRasterClient()\n\n\tconst [state, setState] = useState<SignInState>({ status: 'idle' })\n\n\tconst controllerRef = useRef<AbortController | null>(null)\n\tconst mountedRef = useRef(true)\n\n\t/** Ignore results that arrive after unmount; `setState` on a dead component is noise. */\n\tconst settle = useCallback((next: SignInState) => {\n\t\tif (mountedRef.current) setState(next)\n\t}, [])\n\n\tconst fail = useCallback(\n\t\t(caught: unknown) => {\n\t\t\t// A cancellation is not a failure to report — the user asked for it.\n\t\t\tif (isAbortError(caught)) {\n\t\t\t\tsettle({ status: 'idle' })\n\t\t\t\treturn\n\t\t\t}\n\t\t\tsettle({ status: 'error', error: toRasterApiError(caught) })\n\t\t},\n\t\t[settle]\n\t)\n\n\tconst signInWithDevice = useCallback(async () => {\n\t\tcontrollerRef.current?.abort()\n\t\tconst controller = new AbortController()\n\t\tcontrollerRef.current = controller\n\n\t\tsettle({ status: 'connecting' })\n\t\ttry {\n\t\t\tawait client.auth.signInWithDevice({\n\t\t\t\tsignal: controller.signal,\n\t\t\t\tonCode: (device) => settle({ status: 'awaitingApproval', device }),\n\t\t\t\tscope,\n\t\t\t\torganizationId,\n\t\t\t})\n\t\t\tsettle({ status: 'idle' })\n\t\t} catch (caught) {\n\t\t\tfail(caught)\n\t\t}\n\t}, [client, settle, fail, scope, organizationId])\n\n\tconst connectApiKey = useCallback(\n\t\tasync (apiKey: string) => {\n\t\t\tsettle({ status: 'connecting' })\n\t\t\ttry {\n\t\t\t\tawait client.auth.connect({ apiKey })\n\t\t\t\tsettle({ status: 'idle' })\n\t\t\t} catch (caught) {\n\t\t\t\tfail(caught)\n\t\t\t}\n\t\t},\n\t\t[client, settle, fail]\n\t)\n\n\tconst cancel = useCallback(() => {\n\t\tcontrollerRef.current?.abort()\n\t\tsettle({ status: 'idle' })\n\t}, [settle])\n\n\tconst reset = useCallback(() => settle({ status: 'idle' }), [settle])\n\n\tuseEffect(() => {\n\t\tmountedRef.current = true\n\t\treturn () => {\n\t\t\tmountedRef.current = false\n\t\t\t// A device sign-in polls indefinitely. Leaving it running after unmount would keep\n\t\t\t// hitting the token endpoint for a screen nobody is looking at.\n\t\t\tcontrollerRef.current?.abort()\n\t\t}\n\t}, [])\n\n\treturn {\n\t\tstate,\n\t\tsignInWithDevice,\n\t\tconnectApiKey,\n\t\tcancel,\n\t\treset,\n\t}\n}\n"]}
1
+ {"version":3,"file":"use-sign-in.js","sourceRoot":"","sources":["../src/use-sign-in.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAEhE,OAAO,EAGN,aAAa,IAAI,UAAU,EAC3B,YAAY,EACZ,gBAAgB,IAAI,iBAAiB,EACrC,gBAAgB,GAChB,MAAM,iBAAiB,CAAA;AAExB,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAoB9C;;;;;GAKG;AACH,MAAM,UAAU,SAAS,CACxB,UAA+D,EAAE;IAEjE,MAAM,EAAE,KAAK,EAAE,cAAc,EAAE,GAAG,OAAO,CAAA;IACzC,MAAM,MAAM,GAAG,eAAe,EAAE,CAAA;IAEhC,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAc,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAA;IAEnE,MAAM,aAAa,GAAG,MAAM,CAAyB,IAAI,CAAC,CAAA;IAC1D,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,CAAA;IAE/B,yFAAyF;IACzF,MAAM,MAAM,GAAG,WAAW,CAAC,CAAC,IAAiB,EAAE,EAAE;QAChD,IAAI,UAAU,CAAC,OAAO;YAAE,QAAQ,CAAC,IAAI,CAAC,CAAA;IACvC,CAAC,EAAE,EAAE,CAAC,CAAA;IAEN,MAAM,IAAI,GAAG,WAAW,CACvB,CAAC,MAAe,EAAE,EAAE;QACnB,qEAAqE;QACrE,IAAI,YAAY,CAAC,MAAM,CAAC,EAAE,CAAC;YAC1B,MAAM,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAA;YAC1B,OAAM;QACP,CAAC;QACD,MAAM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AC,CAAA;QACb,CAAC;IACF,CAAC,EACD,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,CACtB,CAAA;IAED,MAAM,MAAM,GAAG,WAAW,CAAC,GAAG,EAAE;QAC/B,aAAa,CAAC,OAAO,EAAE,KAAK,EAAE,CAAA;QAC9B,MAAM,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAA;IAC3B,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAA;IAEZ,MAAM,KAAK,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAA;IAErE,SAAS,CAAC,GAAG,EAAE;QACd,UAAU,CAAC,OAAO,GAAG,IAAI,CAAA;QACzB,OAAO,GAAG,EAAE;YACX,UAAU,CAAC,OAAO,GAAG,KAAK,CAAA;YAC1B,mFAAmF;YACnF,gEAAgE;YAChE,aAAa,CAAC,OAAO,EAAE,KAAK,EAAE,CAAA;QAC/B,CAAC,CAAA;IACF,CAAC,EAAE,EAAE,CAAC,CAAA;IAEN,OAAO;QACN,KAAK;QACL,gBAAgB;QAChB,aAAa;QACb,MAAM;QACN,KAAK;KACL,CAAA;AACF,CAAC","sourcesContent":["import { useCallback, useEffect, useRef, useState } from 'react'\n\nimport {\n\ttype DeviceAuthorization,\n\ttype RasterApiError,\n\tconnectApiKey as connectKey,\n\tisAbortError,\n\tsignInWithDevice as startDeviceSignIn,\n\ttoRasterApiError,\n} from '@raster-app/sdk'\n\nimport { useRasterClient } from './context.js'\n\nexport type SignInState =\n\t| { status: 'idle' }\n\t| { status: 'connecting' }\n\t/** The device grant is waiting for the user to approve in their browser. */\n\t| { status: 'awaitingApproval'; device: DeviceAuthorization }\n\t| { status: 'error'; error: RasterApiError }\n\nexport type SignIn = {\n\tstate: SignInState\n\t/** Device grant (RFC 8628). Works in every host. */\n\tsignInWithDevice: () => Promise<void>\n\t/** Verify and adopt a pasted organization API key. */\n\tconnectApiKey: (apiKey: string) => Promise<void>\n\t/** Abandon a device sign-in that is still waiting. */\n\tcancel: () => void\n\treset: () => void\n}\n\n/**\n * Drives both ways in — the device grant and an API key — and holds their state: a device\n * grant waiting on the user, or the error that ended an attempt. Read the credential itself\n * with `useSession`. `scope` and `organizationId` go to the device grant, as\n * `signInWithDevice` takes them.\n */\nexport function useSignIn(\n\toptions: { scope?: 'user' | 'org'; organizationId?: string } = {}\n): SignIn {\n\tconst { scope, organizationId } = options\n\tconst client = useRasterClient()\n\n\tconst [state, setState] = useState<SignInState>({ status: 'idle' })\n\n\tconst controllerRef = useRef<AbortController | null>(null)\n\tconst mountedRef = useRef(true)\n\n\t/** Ignore results that arrive after unmount; `setState` on a dead component is noise. */\n\tconst settle = useCallback((next: SignInState) => {\n\t\tif (mountedRef.current) setState(next)\n\t}, [])\n\n\tconst fail = useCallback(\n\t\t(caught: unknown) => {\n\t\t\t// A cancellation is not a failure to report — the user asked for it.\n\t\t\tif (isAbortError(caught)) {\n\t\t\t\tsettle({ status: 'idle' })\n\t\t\t\treturn\n\t\t\t}\n\t\t\tsettle({ status: 'error', error: toRasterApiError(caught) })\n\t\t},\n\t\t[settle]\n\t)\n\n\tconst signInWithDevice = useCallback(async () => {\n\t\tcontrollerRef.current?.abort()\n\t\tconst controller = new AbortController()\n\t\tcontrollerRef.current = controller\n\n\t\tsettle({ status: 'connecting' })\n\t\ttry {\n\t\t\tawait startDeviceSignIn(client, {\n\t\t\t\tsignal: controller.signal,\n\t\t\t\tonCode: (device) => settle({ status: 'awaitingApproval', device }),\n\t\t\t\tscope,\n\t\t\t\torganizationId,\n\t\t\t})\n\t\t\tsettle({ status: 'idle' })\n\t\t} catch (caught) {\n\t\t\tfail(caught)\n\t\t}\n\t}, [client, settle, fail, scope, organizationId])\n\n\tconst connectApiKey = useCallback(\n\t\tasync (apiKey: string) => {\n\t\t\tsettle({ status: 'connecting' })\n\t\t\ttry {\n\t\t\t\tawait connectKey(client, { apiKey })\n\t\t\t\tsettle({ status: 'idle' })\n\t\t\t} catch (caught) {\n\t\t\t\tfail(caught)\n\t\t\t}\n\t\t},\n\t\t[client, settle, fail]\n\t)\n\n\tconst cancel = useCallback(() => {\n\t\tcontrollerRef.current?.abort()\n\t\tsettle({ status: 'idle' })\n\t}, [settle])\n\n\tconst reset = useCallback(() => settle({ status: 'idle' }), [settle])\n\n\tuseEffect(() => {\n\t\tmountedRef.current = true\n\t\treturn () => {\n\t\t\tmountedRef.current = false\n\t\t\t// A device sign-in polls indefinitely. Leaving it running after unmount would keep\n\t\t\t// hitting the token endpoint for a screen nobody is looking at.\n\t\t\tcontrollerRef.current?.abort()\n\t\t}\n\t}, [])\n\n\treturn {\n\t\tstate,\n\t\tsignInWithDevice,\n\t\tconnectApiKey,\n\t\tcancel,\n\t\treset,\n\t}\n}\n"]}
package/package.json CHANGED
@@ -1,17 +1,15 @@
1
1
  {
2
2
  "name": "@raster-app/react",
3
- "version": "0.1.0-rc.1",
3
+ "version": "0.2.0-canary-846559b",
4
4
  "description": "React provider and hooks for the Raster SDK: session, organizations, libraries, assets, search and uploads.",
5
5
  "license": "MIT",
6
- "homepage": "https://raster.app/docs",
6
+ "homepage": "https://raster.app/docs/api/sdk",
7
7
  "keywords": [
8
8
  "raster",
9
9
  "dam",
10
10
  "assets",
11
11
  "react",
12
12
  "hooks",
13
- "figma",
14
- "sanity",
15
13
  "plugin"
16
14
  ],
17
15
  "type": "module",
@@ -31,7 +29,7 @@
31
29
  "./package.json": "./package.json"
32
30
  },
33
31
  "engines": {
34
- "node": ">=24"
32
+ "node": ">=22.12"
35
33
  },
36
34
  "scripts": {
37
35
  "build": "rm -rf dist && tsc -p tsconfig.build.json && cp src/styles.css dist/",
@@ -42,8 +40,9 @@
42
40
  "test": "bun test"
43
41
  },
44
42
  "dependencies": {
45
- "@raster-app/sdk": "^0.1.0-rc.1",
46
- "@tanstack/react-query": "^5.103.1"
43
+ "@raster-app/sdk": "0.2.0-canary-846559b",
44
+ "@tanstack/react-query": "^5.103.1",
45
+ "@tanstack/react-virtual": "^3.14.13"
47
46
  },
48
47
  "peerDependencies": {
49
48
  "react": "^18 || ^19"
@@ -55,4 +54,4 @@
55
54
  "publishConfig": {
56
55
  "access": "public"
57
56
  }
58
- }
57
+ }