@lotics/app-sdk 0.27.0 → 0.28.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.
@@ -24,6 +24,7 @@ import { useCallback } from "react";
24
24
  import useSWR from "swr";
25
25
  import { rpc } from "./rpc.js";
26
26
  import { captureAppEvent } from "./analytics.js";
27
+ import { useAppContext } from "./viewer.js";
27
28
  /** The reduced storage shape the update endpoint accepts for `files`. */
28
29
  function toStorageFiles(files) {
29
30
  return (files ?? []).map((f) => ({
@@ -33,24 +34,6 @@ function toStorageFiles(files) {
33
34
  mime_type: f.mime_type,
34
35
  }));
35
36
  }
36
- /**
37
- * Read the app's context once, shared across every hook via a stable SWR key.
38
- * Comments need a signed-in member (members-only) AND the app's declared
39
- * `comments` capability — both come from here.
40
- */
41
- function useAppContext() {
42
- const { data } = useSWR("app-context", () => rpc("context", {}), {
43
- revalidateOnFocus: false,
44
- revalidateIfStale: false,
45
- revalidateOnReconnect: false,
46
- shouldRetryOnError: false,
47
- });
48
- return {
49
- memberId: data?.member_id ?? null,
50
- commentsEnabled: data?.comments_enabled ?? false,
51
- resolved: data !== undefined,
52
- };
53
- }
54
37
  let optimisticCounter = 0;
55
38
  /**
56
39
  * ```tsx
@@ -20,6 +20,7 @@ export { useWorkflow, useQuery, useInfiniteQuery, usePaginatedQuery, useFileUplo
20
20
  export type { UploadedFile, BaseQueryOptions, QueryOptions, InfiniteQueryOptions, PaginatedQueryOptions, QuerySortKey, QueryFilter, QueryFilterCondition, QueryFilterGroup, WorkflowResult, MembersOptions, } from "./hooks.js";
21
21
  export { useComments } from "./comments.js";
22
22
  export type { AppComment, AppCommentFile, CommentsState, UseCommentsArgs } from "./comments.js";
23
+ export { useViewer } from "./viewer.js";
23
24
  export { rpc } from "./rpc.js";
24
25
  export type { RpcOp } from "./rpc.js";
25
26
  export { openExternal } from "./open_external.js";
package/dist/src/index.js CHANGED
@@ -17,6 +17,7 @@
17
17
  export { mount } from "./mount.js";
18
18
  export { useWorkflow, useQuery, useInfiniteQuery, usePaginatedQuery, useFileUpload, useMembers, } from "./hooks.js";
19
19
  export { useComments } from "./comments.js";
20
+ export { useViewer } from "./viewer.js";
20
21
  export { rpc } from "./rpc.js";
21
22
  export { openExternal } from "./open_external.js";
22
23
  export { readMembers } from "./members.js";
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Read the app's context once, shared across every hook via a stable SWR key.
3
+ * The host (the product iframe, or `lotics app dev`) supplies the signed-in
4
+ * member and the app's declared capabilities.
5
+ */
6
+ export declare function useAppContext(): {
7
+ memberId: string | null;
8
+ commentsEnabled: boolean;
9
+ resolved: boolean;
10
+ };
11
+ /**
12
+ * The signed-in member currently viewing the app — the **view-as target** under
13
+ * an admin's "View as" (product UI or `lotics app dev --view-as`), the
14
+ * authenticated member otherwise, and `null` for a public/standalone visitor or
15
+ * until the context resolves (gate viewer-dependent UI on `loading`).
16
+ *
17
+ * Use it to personalize (greet the member, default an assignment to them) or to
18
+ * pass the viewer into a workflow that must attribute to them. **Per-row data
19
+ * scoping does NOT need this** — put an `is_current_member` filter in the query
20
+ * template and the server resolves it to the same member (honoring view-as).
21
+ */
22
+ export declare function useViewer(): {
23
+ memberId: string | null;
24
+ loading: boolean;
25
+ };
@@ -0,0 +1,35 @@
1
+ import useSWR from "swr";
2
+ import { rpc } from "./rpc.js";
3
+ /**
4
+ * Read the app's context once, shared across every hook via a stable SWR key.
5
+ * The host (the product iframe, or `lotics app dev`) supplies the signed-in
6
+ * member and the app's declared capabilities.
7
+ */
8
+ export function useAppContext() {
9
+ const { data } = useSWR("app-context", () => rpc("context", {}), {
10
+ revalidateOnFocus: false,
11
+ revalidateIfStale: false,
12
+ revalidateOnReconnect: false,
13
+ shouldRetryOnError: false,
14
+ });
15
+ return {
16
+ memberId: data?.member_id ?? null,
17
+ commentsEnabled: data?.comments_enabled ?? false,
18
+ resolved: data !== undefined,
19
+ };
20
+ }
21
+ /**
22
+ * The signed-in member currently viewing the app — the **view-as target** under
23
+ * an admin's "View as" (product UI or `lotics app dev --view-as`), the
24
+ * authenticated member otherwise, and `null` for a public/standalone visitor or
25
+ * until the context resolves (gate viewer-dependent UI on `loading`).
26
+ *
27
+ * Use it to personalize (greet the member, default an assignment to them) or to
28
+ * pass the viewer into a workflow that must attribute to them. **Per-row data
29
+ * scoping does NOT need this** — put an `is_current_member` filter in the query
30
+ * template and the server resolves it to the same member (honoring view-as).
31
+ */
32
+ export function useViewer() {
33
+ const ctx = useAppContext();
34
+ return { memberId: ctx.memberId, loading: !ctx.resolved };
35
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lotics/app-sdk",
3
- "version": "0.27.0",
3
+ "version": "0.28.0",
4
4
  "description": "Runtime SDK for Lotics custom-code apps — typed hooks, postMessage bridge, mount entry point",
5
5
  "type": "module",
6
6
  "exports": {