@graphcore/react-kernel 0.3.0 → 0.4.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.
- package/dist/api/entityApi.d.ts +7 -1
- package/dist/auth/offlineAccess.d.ts +10 -0
- package/dist/components/Admin/AdminPanel.d.ts +4 -3
- package/dist/graphcore-react-kernel.cjs.js +3 -3
- package/dist/graphcore-react-kernel.es.js +1947 -1656
- package/dist/hooks/useCatalog.d.ts +28 -0
- package/dist/hooks/useServerRoutes.d.ts +5 -0
- package/dist/host/HostedSession.d.ts +28 -0
- package/dist/host/channel.d.ts +43 -0
- package/dist/host/connect.d.ts +26 -0
- package/dist/host/testing.d.ts +25 -0
- package/dist/lib/GraphCoreProvider.d.ts +4 -0
- package/dist/lib/index.d.ts +4 -0
- package/dist/lib/runtimeConfig.d.ts +3 -0
- package/dist/state/registryDirectoryStore.d.ts +1 -0
- package/dist/utils/StrategyRequestBuilder.d.ts +2 -2
- package/dist/views/EntityView.d.ts +3 -1
- package/package.json +1 -1
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export interface CatalogEntry {
|
|
2
|
+
/** `/c/<backend id><route>`: the place, naming its deployment. */
|
|
3
|
+
address: string;
|
|
4
|
+
/** The route on its own deployment. */
|
|
5
|
+
route: string;
|
|
6
|
+
backend_id: string;
|
|
7
|
+
handle: string | null;
|
|
8
|
+
app_id: string | null;
|
|
9
|
+
label: string;
|
|
10
|
+
/** An image's URL (absolute for a connection's), or null for the label's first letter. */
|
|
11
|
+
icon: string | null;
|
|
12
|
+
}
|
|
13
|
+
export interface CatalogDeployment {
|
|
14
|
+
backend_id: string;
|
|
15
|
+
handle: string | null;
|
|
16
|
+
web_url: string | null;
|
|
17
|
+
/** This deployment, as opposed to a connection. */
|
|
18
|
+
home: boolean;
|
|
19
|
+
available: boolean;
|
|
20
|
+
/** Why a connection is not available: `unreachable`, `undelegated`, `other-domain`, ... */
|
|
21
|
+
cause?: string;
|
|
22
|
+
}
|
|
23
|
+
export interface Catalog {
|
|
24
|
+
deployments: CatalogDeployment[];
|
|
25
|
+
entries: CatalogEntry[];
|
|
26
|
+
}
|
|
27
|
+
/** The deployment's catalog as the signed-in person reads it; null while loading or signed out. */
|
|
28
|
+
export declare function useCatalog(): Catalog | null;
|
|
@@ -2,6 +2,11 @@ export interface ServerRoute {
|
|
|
2
2
|
pattern: string;
|
|
3
3
|
view_name: string;
|
|
4
4
|
app_id: string;
|
|
5
|
+
/** Set when the route is listed in the deployment's catalog. */
|
|
6
|
+
catalog?: {
|
|
7
|
+
label: string;
|
|
8
|
+
icon: string | null;
|
|
9
|
+
} | null;
|
|
5
10
|
}
|
|
6
11
|
/** The server's route table, fetched once per page load; null while loading or if it failed. */
|
|
7
12
|
export declare function useServerRoutes(): ServerRoute[] | null;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
import { HostConnection } from './connect';
|
|
3
|
+
/** A token is asked for again this long before it expires. */
|
|
4
|
+
export declare const RENEW_BEFORE_SECONDS = 60;
|
|
5
|
+
export declare const HOST_ENDED_MESSAGE = "The workspace hosting this window stopped answering. Reload the workspace.";
|
|
6
|
+
export declare const HostContext: React.Context<HostConnection>;
|
|
7
|
+
/**
|
|
8
|
+
* The session of an app a host frames: the token comes from the host, and is
|
|
9
|
+
* asked for again shortly before it expires or when a request is refused. No
|
|
10
|
+
* sign-in or renewal of its own, so one session has one renewer.
|
|
11
|
+
*/
|
|
12
|
+
export declare function HostedSession({ connection }: {
|
|
13
|
+
connection: HostConnection;
|
|
14
|
+
}): any;
|
|
15
|
+
/**
|
|
16
|
+
* Reports every page the router shows to the host (`gc/notifications/navigated`)
|
|
17
|
+
* and goes where the host sends it (`gc/navigate`). Renders nothing, and nothing
|
|
18
|
+
* outside a host. Mount it once inside the router; `GraphCoreRouter` does.
|
|
19
|
+
*/
|
|
20
|
+
export declare function HostRouting(): React.JSX.Element;
|
|
21
|
+
export interface Host {
|
|
22
|
+
/** Whether a host frames this app. */
|
|
23
|
+
hosted: boolean;
|
|
24
|
+
/** Ask the host for a window at `address` (a route of this app, or an entity address); alone, go there. */
|
|
25
|
+
openWindow: (address: string) => Promise<void>;
|
|
26
|
+
}
|
|
27
|
+
/** The host this app runs in, if any. Outside a host `openWindow` navigates this page instead. */
|
|
28
|
+
export declare function useHost(): Host;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSON-RPC 2.0 over `postMessage` with one other window at one origin: the
|
|
3
|
+
* envelope MCP Apps uses, with gc's own methods under `gc/`.
|
|
4
|
+
*/
|
|
5
|
+
export declare const METHOD_NOT_FOUND = -32601;
|
|
6
|
+
export declare const INTERNAL_ERROR = -32603;
|
|
7
|
+
type Id = number | string;
|
|
8
|
+
export interface RpcMessage {
|
|
9
|
+
jsonrpc: '2.0';
|
|
10
|
+
id?: Id;
|
|
11
|
+
method?: string;
|
|
12
|
+
params?: unknown;
|
|
13
|
+
result?: unknown;
|
|
14
|
+
error?: {
|
|
15
|
+
code: number;
|
|
16
|
+
message: string;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
export declare class RpcError extends Error {
|
|
20
|
+
readonly code: number;
|
|
21
|
+
constructor(code: number, message: string);
|
|
22
|
+
}
|
|
23
|
+
export declare function isRpcMessage(data: unknown): data is RpcMessage;
|
|
24
|
+
type Handler = (params: unknown) => unknown | Promise<unknown>;
|
|
25
|
+
export declare class Channel {
|
|
26
|
+
private readonly self;
|
|
27
|
+
private readonly target;
|
|
28
|
+
readonly origin: string;
|
|
29
|
+
private nextId;
|
|
30
|
+
private readonly pending;
|
|
31
|
+
private readonly handlers;
|
|
32
|
+
private readonly listener;
|
|
33
|
+
/** Talks to `target`, and hears only messages from it sent at `origin`. */
|
|
34
|
+
constructor(self: Window, target: Window, origin: string);
|
|
35
|
+
request<T = unknown>(method: string, params?: unknown, timeoutMs?: number): Promise<T>;
|
|
36
|
+
notify(method: string, params?: unknown): void;
|
|
37
|
+
/** Answer `method` from the other side; a method with no handler is answered method-not-found. */
|
|
38
|
+
handle(method: string, handler: Handler): () => void;
|
|
39
|
+
dispose(): void;
|
|
40
|
+
private post;
|
|
41
|
+
private receive;
|
|
42
|
+
}
|
|
43
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Channel } from './channel';
|
|
2
|
+
export declare const PROTOCOL = 1;
|
|
3
|
+
export declare const HANDSHAKE_TIMEOUT_MS = 500;
|
|
4
|
+
/** What the framed app answers when the host sends it. */
|
|
5
|
+
export declare const FRAMED_COMMANDS: string[];
|
|
6
|
+
export interface HostConnection {
|
|
7
|
+
channel: Channel;
|
|
8
|
+
origin: string;
|
|
9
|
+
/** The methods the host answers. */
|
|
10
|
+
commands: string[];
|
|
11
|
+
token: string;
|
|
12
|
+
/** Seconds since the epoch. */
|
|
13
|
+
expiresAt: number;
|
|
14
|
+
}
|
|
15
|
+
export declare function isFramed(win?: Window): boolean;
|
|
16
|
+
/** The origins this deployment lets host it: its own, and `GRAPHCORE_FRAME_ORIGINS`. */
|
|
17
|
+
export declare function allowedHostOrigins(win?: Window): Promise<string[]>;
|
|
18
|
+
/**
|
|
19
|
+
* Sends `gc/initialize` to the parent at each allowed origin; `postMessage`
|
|
20
|
+
* delivers only where the parent's origin matches. The first valid answer
|
|
21
|
+
* wins. With none within `timeoutMs` the app is not hosted: null.
|
|
22
|
+
*/
|
|
23
|
+
export declare function connectToHost(allowedOrigins: string[], { win, timeoutMs }?: {
|
|
24
|
+
win?: Window;
|
|
25
|
+
timeoutMs?: number;
|
|
26
|
+
}): Promise<HostConnection | null>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** A fake parent window for tests: records what the framed app posts, and answers as a host would. */
|
|
2
|
+
export declare const HOST_ORIGIN = "https://gc.test";
|
|
3
|
+
export interface Posted {
|
|
4
|
+
message: any;
|
|
5
|
+
targetOrigin: string;
|
|
6
|
+
}
|
|
7
|
+
/** A `message` event as the browser delivers it; jsdom's `MessageEvent` refuses a fake `source`. */
|
|
8
|
+
export declare function deliver(win: Window, data: unknown, origin: string, source: unknown): void;
|
|
9
|
+
export declare class FakeHost {
|
|
10
|
+
readonly win: Window;
|
|
11
|
+
readonly posted: Posted[];
|
|
12
|
+
/** Answers by method; return undefined to stay silent. */
|
|
13
|
+
readonly answers: Record<string, (params: any) => unknown>;
|
|
14
|
+
origin: string;
|
|
15
|
+
readonly parent: {
|
|
16
|
+
postMessage: (message: any, targetOrigin: string) => void;
|
|
17
|
+
};
|
|
18
|
+
constructor(win?: Window);
|
|
19
|
+
/** Make `win.parent` this host, until `detach`. */
|
|
20
|
+
attach(): void;
|
|
21
|
+
detach(): void;
|
|
22
|
+
/** Send the framed app a request or notification from the host. */
|
|
23
|
+
send(message: object, origin?: string, source?: unknown): void;
|
|
24
|
+
sent(method: string): any[];
|
|
25
|
+
}
|
|
@@ -37,5 +37,9 @@ export interface GraphCoreProviderProps {
|
|
|
37
37
|
*
|
|
38
38
|
* Token injection (escape hatch): pass getToken + principalEntityId to bypass
|
|
39
39
|
* AuthPage when you already have a valid GraphCore token from an external system.
|
|
40
|
+
*
|
|
41
|
+
* In a frame, it first asks the parent whether it is a host (`gc/initialize`,
|
|
42
|
+
* to the origins the backend allows). A hosted app takes its token from the
|
|
43
|
+
* host instead of signing in.
|
|
40
44
|
*/
|
|
41
45
|
export declare function GraphCoreProvider({ apiUrl, wsUrl, registry, getToken, principalEntityId, agentMirror, basePath, children, }: GraphCoreProviderProps): React.JSX.Element;
|
package/dist/lib/index.d.ts
CHANGED
|
@@ -5,6 +5,10 @@ export { TopBar } from '../components/TopBar/TopBar';
|
|
|
5
5
|
export type { TopBarPlace, TopBarProps } from '../components/TopBar/TopBar';
|
|
6
6
|
export { ViewGallery } from '../components/ViewEntity/ViewGallery/ViewGallery';
|
|
7
7
|
export { useAuth } from '../hooks/useAuth';
|
|
8
|
+
export { useHost, HostRouting } from '../host/HostedSession';
|
|
9
|
+
export type { Host } from '../host/HostedSession';
|
|
10
|
+
export { useCatalog } from '../hooks/useCatalog';
|
|
11
|
+
export type { Catalog, CatalogDeployment, CatalogEntry } from '../hooks/useCatalog';
|
|
8
12
|
export { useOffersRegistration } from '../hooks/useOffersRegistration';
|
|
9
13
|
export { AccessPanel, GroupView, useAccess } from '../components/Access';
|
|
10
14
|
export { INVITE_ROUTE, InviteRoute, inviteUrl, usePendingInvite } from '../components/Invite';
|
|
@@ -15,6 +15,9 @@ export declare function getBasePath(): string;
|
|
|
15
15
|
export declare function webPath(path: string): string;
|
|
16
16
|
export declare function getApiUrl(): string;
|
|
17
17
|
export declare function getWsUrl(): string;
|
|
18
|
+
/** Who renews the session's token in place of the issuer: a host, for a framed app. */
|
|
19
|
+
export declare function setSessionRenewer(renew: (() => Promise<string | null>) | null): void;
|
|
20
|
+
export declare function getSessionRenewer(): (() => Promise<string | null>) | null;
|
|
18
21
|
/** Returns a token from an externally-supplied getToken fn (token injection path). */
|
|
19
22
|
export declare function getExternalToken(): string | null;
|
|
20
23
|
export declare function hasExternalToken(): boolean;
|
|
@@ -19,6 +19,7 @@ export declare const useAvailableEntitiesState: () => ResourceState<Record<strin
|
|
|
19
19
|
export declare const useStrategyDirectoryLoadable: () => ResourceState<Record<string, any>>;
|
|
20
20
|
export declare const useAvailableEntitiesLoadable: () => ResourceState<Record<string, any>>;
|
|
21
21
|
export declare const useDeclaredLoadable: () => ResourceState<Record<string, DeclaredInfo>>;
|
|
22
|
+
export declare const useNewUserGroupsLoadable: () => ResourceState<string[]>;
|
|
22
23
|
/** The declaration behind `key`, once the directory has loaded. */
|
|
23
24
|
export declare const useDeclared: (key: string | null | undefined) => DeclaredInfo | undefined;
|
|
24
25
|
export {};
|
|
@@ -59,10 +59,10 @@ export namespace StrategyRequests {
|
|
|
59
59
|
param_config: {};
|
|
60
60
|
};
|
|
61
61
|
/**
|
|
62
|
-
* Set the groups
|
|
62
|
+
* Set the groups every new user joins, beside those the project's settings name.
|
|
63
63
|
* @param {string} deploymentId - The deployment entity (`useDeploymentEntityId`)
|
|
64
64
|
*/
|
|
65
|
-
function setNewUserDefaults(deploymentId: string, groupIds: any
|
|
65
|
+
function setNewUserDefaults(deploymentId: string, groupIds: any): {
|
|
66
66
|
strategy_name: string;
|
|
67
67
|
target_entity_id: any;
|
|
68
68
|
param_config: {};
|
|
@@ -3,6 +3,8 @@ interface PlacementOptions {
|
|
|
3
3
|
/** Tells apart two placements of the same entity at the same position. */
|
|
4
4
|
slot?: string;
|
|
5
5
|
className?: string;
|
|
6
|
+
/** Places the view as a control inside another: no view switcher, and nothing shown while it loads. */
|
|
7
|
+
inline?: boolean;
|
|
6
8
|
}
|
|
7
9
|
export type EntityViewProps = PlacementOptions & {
|
|
8
10
|
/** Entity ids the placed view reads with `usePlacementContext`. Never stored. */
|
|
@@ -20,5 +22,5 @@ export type EntityViewProps = PlacementOptions & {
|
|
|
20
22
|
* view, else `BaseEntity`. A view renders as itself: its component over the
|
|
21
23
|
* entity it shows, with everything inside it stored in it.
|
|
22
24
|
*/
|
|
23
|
-
export declare function EntityView({ entityId, entityKey, context, slot, className }: EntityViewProps): React.JSX.Element;
|
|
25
|
+
export declare function EntityView({ entityId, entityKey, context, slot, className, inline }: EntityViewProps): React.JSX.Element;
|
|
24
26
|
export default EntityView;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphcore/react-kernel",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "GraphCore React frontend \u2014 EntityView, WebSocket plumbing, and view registry for building GraphCore-powered applications.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|