@ismou-workspace/app-react 0.0.0-stage → 0.1.1

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.
@@ -0,0 +1,19 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { CORE_ADMIN_APPS_PAGE_PATH, ENROLL_PARAM, } from '@ismou-workspace/contracts';
3
+ import { useSharedMessages } from '@ismou-workspace/translations/react';
4
+ import { Button, CopyableCodeBlock, FullPageMessage } from '@ismou-workspace/ui';
5
+ /** Where the core reviews this app: its administration, told the app's URL (`ENROLL_PARAM`). */
6
+ export function enrollmentUrl(coreUrl, appUrl) {
7
+ const url = new URL(CORE_ADMIN_APPS_PAGE_PATH, coreUrl);
8
+ url.searchParams.set(ENROLL_PARAM, appUrl);
9
+ return url.href;
10
+ }
11
+ /**
12
+ * What an app shows until an administrator enrolls it: a link to its review in the core, which
13
+ * reads its manifest by itself, and the manifest, to paste when the core cannot reach the app.
14
+ * The session state is polled meanwhile: the page goes on by itself once enrolled.
15
+ */
16
+ export function UnenrolledPage({ session: { manifest, coreUrl } }) {
17
+ const t = useSharedMessages().platform;
18
+ return (_jsx(FullPageMessage, { loading: true, title: t.unenrolledTitle, description: t.unenrolledDescription, action: _jsx(Button, { asChild: true, children: _jsx("a", { href: enrollmentUrl(coreUrl, manifest.url), children: t.reviewEnrollment }) }), children: _jsx(CopyableCodeBlock, { value: JSON.stringify(manifest, null, 2) }) }));
19
+ }
@@ -0,0 +1,31 @@
1
+ import type { AppSessionState, DelegablePermission } from '@ismou-workspace/contracts';
2
+ /** The `AppSessionState` of a signed-in account: the only one the app renders with. */
3
+ export type AuthenticatedAppSessionState = Extract<AppSessionState, {
4
+ status: 'authenticated';
5
+ }>;
6
+ export declare const AppSessionContext: import("react").Context<{
7
+ status: "authenticated";
8
+ appId: string;
9
+ account: {
10
+ id: string;
11
+ email: string;
12
+ name: string;
13
+ avatar: {
14
+ kind: "generated";
15
+ seed: string;
16
+ } | {
17
+ kind: "file";
18
+ fileId: string;
19
+ url: string;
20
+ };
21
+ };
22
+ permissions: DelegablePermission[];
23
+ preferences: {
24
+ locale: "en" | "fr";
25
+ };
26
+ administrator: boolean;
27
+ coreUrl: string;
28
+ } | null>;
29
+ /** The signed-in account, its permissions in this app and the core URL. */
30
+ export declare function useAppSession(): AuthenticatedAppSessionState;
31
+ export declare function useHasPermission(permission: DelegablePermission): boolean;
@@ -0,0 +1,12 @@
1
+ import { createContext, useContext } from 'react';
2
+ export const AppSessionContext = createContext(null);
3
+ /** The signed-in account, its permissions in this app and the core URL. */
4
+ export function useAppSession() {
5
+ const session = useContext(AppSessionContext);
6
+ if (!session)
7
+ throw new Error('useAppSession must be used inside a PlatformProvider.');
8
+ return session;
9
+ }
10
+ export function useHasPermission(permission) {
11
+ return useAppSession().permissions.includes(permission);
12
+ }
@@ -0,0 +1,6 @@
1
+ import { type Account } from '@ismou-workspace/contracts';
2
+ /**
3
+ * The accounts of these ids, by id (who owns or added something). Ids of deleted accounts stay
4
+ * missing; nothing is fetched without `directory:read`.
5
+ */
6
+ export declare function useDirectoryAccounts(ids: readonly string[]): ReadonlyMap<string, Account>;
@@ -0,0 +1,20 @@
1
+ import { DIRECTORY_MAX_IDS } from '@ismou-workspace/contracts';
2
+ import { useQuery } from '@tanstack/react-query';
3
+ import { lookupDirectory } from './directory.api.js';
4
+ import { useHasPermission } from './use-app-session.js';
5
+ /**
6
+ * The accounts of these ids, by id (who owns or added something). Ids of deleted accounts stay
7
+ * missing; nothing is fetched without `directory:read`.
8
+ */
9
+ export function useDirectoryAccounts(ids) {
10
+ const canRead = useHasPermission('directory:read');
11
+ const sorted = [...new Set(ids)].sort().slice(0, DIRECTORY_MAX_IDS);
12
+ const query = useQuery({
13
+ queryKey: ['directory', { ids: sorted }],
14
+ queryFn: ({ signal }) => lookupDirectory(sorted, signal),
15
+ enabled: canRead && sorted.length > 0,
16
+ // Names change rarely: one lookup per screen is enough.
17
+ staleTime: 5 * 60 * 1000,
18
+ });
19
+ return new Map(query.data?.accounts.map((account) => [account.id, account]));
20
+ }
@@ -0,0 +1,17 @@
1
+ /** Accounts matching `search`, once typing settles; idle while the search is blank. */
2
+ export declare function useDirectorySearch(search: string): {
3
+ accounts: {
4
+ id: string;
5
+ email: string;
6
+ name: string;
7
+ avatar: {
8
+ kind: "generated";
9
+ seed: string;
10
+ } | {
11
+ kind: "file";
12
+ fileId: string;
13
+ url: string;
14
+ };
15
+ }[] | undefined;
16
+ error: Error | null;
17
+ };
@@ -0,0 +1,19 @@
1
+ import { useQuery } from '@tanstack/react-query';
2
+ import { useDebounce } from 'use-debounce';
3
+ import { searchDirectory } from './directory.api.js';
4
+ const DIRECTORY_SEARCH_DEBOUNCE_MS = 250;
5
+ /** Accounts matching `search`, once typing settles; idle while the search is blank. */
6
+ export function useDirectorySearch(search) {
7
+ const [settled] = useDebounce(search.trim(), DIRECTORY_SEARCH_DEBOUNCE_MS);
8
+ const query = useQuery({
9
+ queryKey: ['directory', { search: settled }],
10
+ queryFn: ({ signal }) => searchDirectory(settled, signal),
11
+ enabled: settled.length > 0,
12
+ });
13
+ // While typing, the results of the previous text would be misleading: none are shown.
14
+ const current = settled === search.trim();
15
+ return {
16
+ accounts: current ? query.data?.accounts : undefined,
17
+ error: current ? query.error : null,
18
+ };
19
+ }
@@ -0,0 +1,13 @@
1
+ import type { LauncherEntry } from '@ismou-workspace/contracts';
2
+ /** The entries of the app switcher: account, administration (for admins) and enrolled apps. */
3
+ export declare function useLauncher(): import("@tanstack/react-query").UseQueryResult<{
4
+ entries: {
5
+ id: string;
6
+ kind: "account" | "admin" | "app";
7
+ name: string;
8
+ url: string;
9
+ iconUrl: string;
10
+ }[];
11
+ }, Error>;
12
+ /** Whether the entry is the app this page belongs to: it lives at the app's URL. */
13
+ export declare function isCurrentAppEntry(entry: LauncherEntry, appUrl?: string): boolean;
@@ -0,0 +1,23 @@
1
+ import { appBasePath } from '@ismou-workspace/web-kit';
2
+ import { useQuery } from '@tanstack/react-query';
3
+ import { fetchLauncher } from './launcher.api.js';
4
+ const LAUNCHER_QUERY_KEY = ['launcher'];
5
+ /** Apps are enrolled or revoked rarely: the launcher is refetched at most every few minutes. */
6
+ const LAUNCHER_STALE_TIME_MS = 5 * 60 * 1000;
7
+ /** The entries of the app switcher: account, administration (for admins) and enrolled apps. */
8
+ export function useLauncher() {
9
+ return useQuery({
10
+ queryKey: LAUNCHER_QUERY_KEY,
11
+ queryFn: ({ signal }) => fetchLauncher(signal),
12
+ staleTime: LAUNCHER_STALE_TIME_MS,
13
+ });
14
+ }
15
+ /**
16
+ * The URL of the app this page belongs to: the page's origin and the app's base path (several
17
+ * apps may share an origin, each under its own path).
18
+ */
19
+ const currentAppUrl = () => `${window.location.origin}${appBasePath()}`;
20
+ /** Whether the entry is the app this page belongs to: it lives at the app's URL. */
21
+ export function isCurrentAppEntry(entry, appUrl = currentAppUrl()) {
22
+ return entry.kind === 'app' && entry.url.replace(/\/+$/, '') === appUrl;
23
+ }
@@ -0,0 +1,4 @@
1
+ /** Ends the app session, then follows the redirect the app server chose. */
2
+ export declare function useSignOut(): import("@tanstack/react-query").UseMutationResult<{
3
+ redirectTo: string;
4
+ }, Error, void, unknown>;
@@ -0,0 +1,10 @@
1
+ import { navigateToUrl } from '@ismou-workspace/web-kit';
2
+ import { useMutation } from '@tanstack/react-query';
3
+ import { signOut } from './app-session.api.js';
4
+ /** Ends the app session, then follows the redirect the app server chose. */
5
+ export function useSignOut() {
6
+ return useMutation({
7
+ mutationFn: signOut,
8
+ onSuccess: ({ redirectTo }) => navigateToUrl(redirectTo),
9
+ });
10
+ }
package/package.json CHANGED
@@ -1,6 +1,55 @@
1
1
  {
2
2
  "name": "@ismou-workspace/app-react",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.1",
4
+ "type": "module",
5
+ "sideEffects": false,
6
+ "exports": {
7
+ ".": {
8
+ "types": "./dist/index.d.ts",
9
+ "default": "./dist/index.js"
10
+ }
11
+ },
12
+ "dependencies": {
13
+ "@phosphor-icons/react": "2.1.10",
14
+ "use-debounce": "10.1.1",
15
+ "zod": "4.6.7",
16
+ "@ismou-workspace/contracts": "^0.1.1",
17
+ "@ismou-workspace/translations": "^0.1.1",
18
+ "@ismou-workspace/web-kit": "^0.1.1",
19
+ "@ismou-workspace/ui": "^0.1.1"
20
+ },
21
+ "peerDependencies": {
22
+ "@tanstack/react-query": "5.108.4",
23
+ "react": "19.3.1",
24
+ "react-dom": "19.3.1"
25
+ },
26
+ "devDependencies": {
27
+ "@tanstack/react-query": "5.108.4",
28
+ "@testing-library/react": "16.3.3",
29
+ "@types/react": "19.3.3",
30
+ "@types/react-dom": "19.3.0",
31
+ "jsdom": "31.0.1",
32
+ "react": "19.3.1",
33
+ "react-dom": "19.3.1",
34
+ "typescript": "7.0.2",
35
+ "vite": "8.4.1",
36
+ "vitest": "5.1.2",
37
+ "@ismou-workspace/tsconfig": "^0.1.1"
38
+ },
39
+ "repository": {
40
+ "type": "git",
41
+ "url": "git+https://github.com/ismou-workspace/sdk.git",
42
+ "directory": "packages/app-react"
43
+ },
44
+ "files": [
45
+ "dist"
46
+ ],
47
+ "publishConfig": {
48
+ "access": "public"
49
+ },
50
+ "scripts": {
51
+ "build": "tsc --project tsconfig.build.json",
52
+ "typecheck": "tsc --project tsconfig.json",
53
+ "test": "vitest run"
54
+ }
6
55
  }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.