@cxxi-lab/hubbyware-sdk 3.2.1 → 3.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/frame/index.ts CHANGED
@@ -3,6 +3,6 @@
3
3
  // the base stylesheet, extracted into runtime.css at build (the frame page links it)
4
4
  import './runtime.css'
5
5
 
6
- export { call, collection, nav, notifications, settings, useInit, usePath, type Doc } from './sdk'
6
+ export { call, collection, nav, notifications, oauth, settings, useInit, usePath, type Doc, type OAuthConnection } from './sdk'
7
7
  export { defineHubby, start, type HubbyDefinition, type HubbyPageDefinition } from './hubby'
8
8
  export { useBackHandler, useMediaQuery } from '@cxxi-lab/hubbyware-ui'
package/frame/sdk.ts CHANGED
@@ -109,6 +109,21 @@ export const notifications = {
109
109
  }
110
110
 
111
111
  /** Announces the hubby's pages to its host (it builds the navigation). */
112
+ /** An account connected at a provider, as the hubby sees it (its grant covers what it declares: `ready`). */
113
+ export interface OAuthConnection { id: string, provider: string, email: string, name: string | null, ready: boolean, lastError: string | null }
114
+
115
+ /**
116
+ * The account's connections at a provider (Google, Microsoft), for what the hubby declares
117
+ * (hubby.json `oauth`; the account allowing it `app:oauth:<provider>`): through the host, as the hubby.
118
+ */
119
+ export const oauth = {
120
+ connections: () => call<OAuthConnection[]>('oauth.connections'),
121
+ /** the consent opens in the browser; resolves once the account consented */
122
+ connect: (provider: string, options: { connection?: string } = {}) => call<OAuthConnection | null>('oauth.connect', provider, options),
123
+ /** an access token, for the hubby's scopes only */
124
+ accessToken: (connection: string) => call<{ accessToken: string, expiresAt: number }>('oauth.accessToken', connection),
125
+ }
126
+
112
127
  export function register(pages: HubbyPage[], sections: Record<string, unknown>) {
113
128
  post({ type: 'register', pages, sections })
114
129
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cxxi-lab/hubbyware-sdk",
3
- "version": "3.2.1",
3
+ "version": "3.4.0",
4
4
  "description": "The contract of Hubbyware's hubbies: the SDK a hubby builds on (provided by the host app at run time), and the SDK of the hubbies running isolated in their frame. Formerly @cxxi-lab/hub-sdk.",
5
5
  "license": "MIT",
6
6
  "type": "module",
package/types/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- // @cxxi-lab/hubbyware-sdk 3.2.1: generated by app/scripts/emit-sdk-types.mjs from app/src/sdk — do not edit.
1
+ // @cxxi-lab/hubbyware-sdk 3.4.0: generated by app/scripts/emit-sdk-types.mjs from app/src/sdk — do not edit.
2
2
  import { IconDefinition } from '@fortawesome/fontawesome-svg-core';
3
3
  import { ComponentType, HTMLInputTypeAttribute, MouseEventHandler, ReactNode, TdHTMLAttributes, ThHTMLAttributes } from 'react';
4
4
 
@@ -46,6 +46,8 @@ export interface VpnInfo {
46
46
  port: number | null;
47
47
  error: string | null;
48
48
  endpoint: string | null;
49
+ /** the hubby the tunnel runs for (its config); older shells don't say */
50
+ hubby?: string | null;
49
51
  }
50
52
  export type UpdatePhase = "available" | "downloading" | "verifying" | "installing" | "error";
51
53
  export interface UpdateState {
@@ -432,23 +434,34 @@ export interface Platform {
432
434
  setMuted(value: boolean): void;
433
435
  onMutedChange(cb: (value: boolean) => void): Unsubscribe;
434
436
  getVpnStatus(): Promise<VpnInfo>;
435
- startVpn(): Promise<void>;
437
+ /** Starts the tunnel for a hubby, with its config (none named: the first hubby going out through the VPN). */
438
+ startVpn(hubby?: string): Promise<void>;
436
439
  stopVpn(): Promise<void>;
437
440
  onVpnStatusChange(cb: (info: VpnInfo) => void): Unsubscribe;
438
- replaceVpnConfig(): Promise<{
441
+ /** Picks a WireGuard config file for a hubby (none named: the first going out through the VPN). */
442
+ replaceVpnConfig(hubby?: string): Promise<{
439
443
  ok: boolean;
440
444
  path: string | null;
441
445
  error?: string;
442
446
  }>;
447
+ /**
448
+ * A hubby's VPN config, kept by the shell (server docs/plan-reseau-vpn.md): only whether there is
449
+ * one and its endpoint; the config itself never comes back to the web side.
450
+ */
451
+ getVpnConfig(hubby: string): Promise<{
452
+ configured: boolean;
453
+ endpoint: string | null;
454
+ }>;
455
+ /** Saves a hubby's WireGuard config (pasted); its tunnel, running, restarts with it. */
456
+ setVpnConfig(hubby: string, text: string): Promise<{
457
+ ok: boolean;
458
+ error?: string;
459
+ }>;
460
+ removeVpnConfig(hubby: string): Promise<void>;
443
461
  /** Opens the Settings window, on a screen when given (e.g. 'security'). */
444
462
  openSettings(target?: string): Promise<void>;
445
463
  /** In the Settings window: a screen another window asked for. */
446
464
  onSettingsGoto(cb: (target: string) => void): Unsubscribe;
447
- /**
448
- * Opens an OAuth consent page in an app window; resolves with the URL the provider redirected to
449
- * (`redirectUri` + the code), caught before it loads, or null when the window was closed.
450
- */
451
- authorizeOAuth(url: string, redirectUri: string): Promise<string | null>;
452
465
  /** Opens a hubby's window (HubbyManifest.windows), registered beforehand. */
453
466
  openHubbyWindow(hubbyId: string, windowId: string): Promise<void>;
454
467
  /** The windows of the active hubbies: what the app menu offers (replaces the previous list). */
@@ -687,13 +700,6 @@ export declare function Amount({ hubby, children, className }: {
687
700
  children: ReactNode;
688
701
  className?: string;
689
702
  }): import("react").JSX.Element;
690
- /**
691
- * The server's base URL. Given the path called, the routes of the hubbies reached through the VPN
692
- * (their data, their capabilities, their media: as they declare, core/hubby/declarations.ts) go to
693
- * the name only reachable through it (prod): the desktop routes that name through the tunnel, the
694
- * phone routes everything through it in private mode. Development: one local server.
695
- */
696
- export declare function getApiBaseUrl(path?: string): string;
697
703
  export declare function fetchSettings<T = Record<string, unknown>>(scope: string): Promise<T>;
698
704
  export declare function updateSettings<T = Record<string, unknown>>(scope: string, values: Partial<T>): Promise<T>;
699
705
  /** Standard JSON envelopes returned by the hub API. */
@@ -718,6 +724,44 @@ export interface PaginatedResponse<T> {
718
724
  * negative). Lets call-sites skip the async await on hot paths.
719
725
  */
720
726
  export declare function isIntegrationKnownSync(rawUrl: string): boolean;
727
+ /**
728
+ * The account's connections at a provider (Google, Microsoft), as a hubby uses them (server
729
+ * docs/plan-oauth.md): the hubby declares the provider scopes it needs (hubby.json `oauth`), the
730
+ * account allows it the provider (`app:oauth:<provider>`, its permissions), then it lists the
731
+ * connections, connects an account (the consent opens in the browser, the server takes the
732
+ * provider's answer) and gets access tokens narrowed to its scopes. Every call is the hubby's
733
+ * (its token): the SDK binds it (src/sdk/index.ts), the host too for an isolated one.
734
+ */
735
+ /** An account connected at a provider, as the hubby sees it. */
736
+ export interface OAuthConnection {
737
+ id: string;
738
+ provider: string;
739
+ email: string;
740
+ name: string | null;
741
+ /** its grant covers what the hubby declares (else: connect it again, `connect(provider, { connection })`) */
742
+ ready: boolean;
743
+ lastError: string | null;
744
+ }
745
+ export interface OAuthAccessToken {
746
+ accessToken: string;
747
+ /** unix seconds */
748
+ expiresAt: number;
749
+ }
750
+ export interface OAuthApi {
751
+ /** The account's connections at the providers the hubby declares (and was allowed). */
752
+ connections(): Promise<OAuthConnection[]>;
753
+ /**
754
+ * Connects an account at a provider for what the hubby declares, or gives one connected
755
+ * (`connection`) what it lacks: the consent opens in the browser; resolves once the account
756
+ * consented (null: given up, `signal`).
757
+ */
758
+ connect(provider: string, options?: {
759
+ connection?: string;
760
+ signal?: AbortSignal;
761
+ }): Promise<OAuthConnection | null>;
762
+ /** An access token of a connection, for the hubby's scopes (kept until shortly before it expires). */
763
+ accessToken(connection: string): Promise<OAuthAccessToken>;
764
+ }
721
765
  export type ButtonColor = "primary" | "secondary" | "danger";
722
766
  export interface ButtonProps {
723
767
  label?: ReactNode;
@@ -997,6 +1041,11 @@ export declare function api<T>(path: string, options?: RequestInit, retry?: bool
997
1041
  * body and carry the token — and resolves once the server closes it.
998
1042
  */
999
1043
  export declare function apiStream(path: string, options: RequestInit, onEvent: StreamEventHandler, retry?: boolean): Promise<void>;
1044
+ /**
1045
+ * The server's base URL, for the URLs a hubby hands an <img>, a <video>, a player (signed media).
1046
+ * The same for every path (`path`: kept for the hubbies passing it).
1047
+ */
1048
+ export declare function getApiBaseUrl(_path?: string): string;
1000
1049
  /** Applies the website integration (cookies, CDN referer) of a URL's site before a webview or the native player loads it. */
1001
1050
  export declare function ensureIntegrationForUrl(rawUrl: string): Promise<void>;
1002
1051
  /**
@@ -1007,6 +1056,11 @@ export declare function ensureIntegrationForUrl(rawUrl: string): Promise<void>;
1007
1056
  export declare function getPlayerConfig(domain: string): Promise<PlayerConfig | null>;
1008
1057
  /** Makes sure the shell holds the back's current player blocklist before a player loads a site (once per session). */
1009
1058
  export declare function syncPlayerBlocklist(): Promise<void>;
1059
+ /**
1060
+ * The account's connections at a provider (Google, Microsoft), for what the hubby declares
1061
+ * (hubby.json `oauth`): list them, connect an account, get access tokens narrowed to its scopes.
1062
+ */
1063
+ export declare const oauth: OAuthApi;
1010
1064
 
1011
1065
  export {
1012
1066
  FormData$1 as FormData,
package/version.json CHANGED
@@ -1,4 +1,4 @@
1
1
  {
2
- "version": "3.2.1",
2
+ "version": "3.4.0",
3
3
  "compatible": []
4
4
  }