@metaboliccode-dev/widget 0.2.86 → 0.2.88

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/README.md CHANGED
@@ -37,6 +37,35 @@ npm install @metaboliccode-dev/widget
37
37
 
38
38
  ## Component usage
39
39
 
40
+ New integrations obtain dashboard tokens on their server using OAuth credentials
41
+ registered for their tenant and environment:
42
+
43
+ ```ts
44
+ import { createMetabolicOAuthClient } from "@metaboliccode-dev/widget/server";
45
+
46
+ const oauth = createMetabolicOAuthClient({
47
+ baseUrl: process.env.METABOLIC_CODE_BACKEND_BASE_URL!,
48
+ clientId: process.env.METABOLIC_CODE_OAUTH_CLIENT_ID!,
49
+ clientSecret: process.env.METABOLIC_CODE_OAUTH_CLIENT_SECRET!,
50
+ });
51
+
52
+ // Validate the host user session and authorize these selectors before delegation.
53
+ const { accessToken, expiresIn } = await oauth.getDelegatedToken({
54
+ sub: authorizedUserId,
55
+ role: "patient",
56
+ patient_id: authorizedPatientId,
57
+ report_id: authorizedReportId,
58
+ scope: "reports:read patient:read",
59
+ });
60
+ ```
61
+
62
+ Pass only the delegated token to the dashboard. Client secrets and service tokens
63
+ must stay on the server. The helper caches service tokens and renews them before
64
+ expiry; delegated tokens expire after 300 seconds. Hosts request a fresh delegated
65
+ token when opening or renewing a dashboard session. OAuth failures never fall back
66
+ to legacy signing. Existing HS256 dashboard tokens and embed integrations remain
67
+ supported during migration.
68
+
40
69
  ```tsx
41
70
  import { MetabolicDashboard } from "@metaboliccode-dev/widget";
42
71
  import "@metaboliccode-dev/widget/styles.css";
@@ -11,8 +11,9 @@ export type DashboardTabContentCacheContextValue = {
11
11
  };
12
12
  export declare function useDashboardTabContentCache(): DashboardTabContentCacheContextValue | null;
13
13
  export declare function useInvalidateDashboardTabContentCache(): () => void;
14
- export declare function DashboardTabContentCacheProvider({ children, fetchers, ttlMs, }: {
14
+ export declare function DashboardTabContentCacheProvider({ children, fetchers, ttlMs, cacheKey, }: {
15
15
  children: ReactNode;
16
16
  fetchers: DashboardContentFetchers;
17
17
  ttlMs: number;
18
+ cacheKey?: string;
18
19
  }): import("react/jsx-runtime").JSX.Element;
@@ -4,6 +4,7 @@ export type MetabolicDashboardShellProps = {
4
4
  wrapTabContentCache: boolean;
5
5
  fetchers: DashboardContentFetchers;
6
6
  cacheTtlMs: number;
7
+ cacheKey: string;
7
8
  viewProps: MetabolicDashboardViewProps;
8
9
  };
9
- export declare function MetabolicDashboardShell({ wrapTabContentCache, fetchers, cacheTtlMs, viewProps, }: MetabolicDashboardShellProps): import("react/jsx-runtime").JSX.Element;
10
+ export declare function MetabolicDashboardShell({ wrapTabContentCache, fetchers, cacheTtlMs, cacheKey, viewProps, }: MetabolicDashboardShellProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,58 @@
1
+ export interface MetabolicOAuthClientOptions {
2
+ baseUrl: string;
3
+ clientId: string;
4
+ clientSecret: string;
5
+ fetch?: typeof globalThis.fetch;
6
+ }
7
+ export interface MetabolicAccessToken {
8
+ accessToken: string;
9
+ expiresIn: number;
10
+ expiresAt: number;
11
+ scope: string;
12
+ }
13
+ export interface MetabolicDelegatedIdentity {
14
+ sub: string;
15
+ role: string;
16
+ scope: string;
17
+ name?: string;
18
+ patient_id?: string;
19
+ report_id?: string;
20
+ questionnaire_response_id?: string;
21
+ white_label_domain?: string;
22
+ firebase_project_id?: string;
23
+ actor?: {
24
+ uid: string;
25
+ email?: string;
26
+ emailVerified?: boolean;
27
+ role?: string;
28
+ impersonatedBy?: {
29
+ uid: string;
30
+ email?: string;
31
+ role?: string;
32
+ };
33
+ };
34
+ }
35
+ export interface MetabolicEmbedLaunch {
36
+ subject: string;
37
+ role: string;
38
+ origin: string;
39
+ scope: string;
40
+ name?: string;
41
+ patient_id?: string;
42
+ report_id?: string;
43
+ questionnaire_response_id?: string;
44
+ }
45
+ export declare class MetabolicOAuthError extends Error {
46
+ readonly status: number;
47
+ readonly operation: string;
48
+ constructor(status: number, operation: string);
49
+ }
50
+ /** Server-only client. Never put its credentials or service tokens in browser props. */
51
+ export declare function createMetabolicOAuthClient(options: MetabolicOAuthClientOptions): {
52
+ getAccessToken: (scopes: readonly string[]) => Promise<MetabolicAccessToken>;
53
+ getDelegatedToken: (identity: MetabolicDelegatedIdentity) => Promise<MetabolicAccessToken>;
54
+ createEmbedLaunch: (identity: MetabolicEmbedLaunch) => Promise<{
55
+ embedToken: string;
56
+ expiresIn: number;
57
+ }>;
58
+ };
@@ -0,0 +1 @@
1
+ export {};