@cxxi-lab/hubbyware-sdk 3.2.1 → 3.3.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.3.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.3.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
 
@@ -444,11 +444,6 @@ export interface Platform {
444
444
  openSettings(target?: string): Promise<void>;
445
445
  /** In the Settings window: a screen another window asked for. */
446
446
  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
447
  /** Opens a hubby's window (HubbyManifest.windows), registered beforehand. */
453
448
  openHubbyWindow(hubbyId: string, windowId: string): Promise<void>;
454
449
  /** The windows of the active hubbies: what the app menu offers (replaces the previous list). */
@@ -718,6 +713,44 @@ export interface PaginatedResponse<T> {
718
713
  * negative). Lets call-sites skip the async await on hot paths.
719
714
  */
720
715
  export declare function isIntegrationKnownSync(rawUrl: string): boolean;
716
+ /**
717
+ * The account's connections at a provider (Google, Microsoft), as a hubby uses them (server
718
+ * docs/plan-oauth.md): the hubby declares the provider scopes it needs (hubby.json `oauth`), the
719
+ * account allows it the provider (`app:oauth:<provider>`, its permissions), then it lists the
720
+ * connections, connects an account (the consent opens in the browser, the server takes the
721
+ * provider's answer) and gets access tokens narrowed to its scopes. Every call is the hubby's
722
+ * (its token): the SDK binds it (src/sdk/index.ts), the host too for an isolated one.
723
+ */
724
+ /** An account connected at a provider, as the hubby sees it. */
725
+ export interface OAuthConnection {
726
+ id: string;
727
+ provider: string;
728
+ email: string;
729
+ name: string | null;
730
+ /** its grant covers what the hubby declares (else: connect it again, `connect(provider, { connection })`) */
731
+ ready: boolean;
732
+ lastError: string | null;
733
+ }
734
+ export interface OAuthAccessToken {
735
+ accessToken: string;
736
+ /** unix seconds */
737
+ expiresAt: number;
738
+ }
739
+ export interface OAuthApi {
740
+ /** The account's connections at the providers the hubby declares (and was allowed). */
741
+ connections(): Promise<OAuthConnection[]>;
742
+ /**
743
+ * Connects an account at a provider for what the hubby declares, or gives one connected
744
+ * (`connection`) what it lacks: the consent opens in the browser; resolves once the account
745
+ * consented (null: given up, `signal`).
746
+ */
747
+ connect(provider: string, options?: {
748
+ connection?: string;
749
+ signal?: AbortSignal;
750
+ }): Promise<OAuthConnection | null>;
751
+ /** An access token of a connection, for the hubby's scopes (kept until shortly before it expires). */
752
+ accessToken(connection: string): Promise<OAuthAccessToken>;
753
+ }
721
754
  export type ButtonColor = "primary" | "secondary" | "danger";
722
755
  export interface ButtonProps {
723
756
  label?: ReactNode;
@@ -1007,6 +1040,11 @@ export declare function ensureIntegrationForUrl(rawUrl: string): Promise<void>;
1007
1040
  export declare function getPlayerConfig(domain: string): Promise<PlayerConfig | null>;
1008
1041
  /** Makes sure the shell holds the back's current player blocklist before a player loads a site (once per session). */
1009
1042
  export declare function syncPlayerBlocklist(): Promise<void>;
1043
+ /**
1044
+ * The account's connections at a provider (Google, Microsoft), for what the hubby declares
1045
+ * (hubby.json `oauth`): list them, connect an account, get access tokens narrowed to its scopes.
1046
+ */
1047
+ export declare const oauth: OAuthApi;
1010
1048
 
1011
1049
  export {
1012
1050
  FormData$1 as FormData,
package/version.json CHANGED
@@ -1,4 +1,4 @@
1
1
  {
2
- "version": "3.2.1",
2
+ "version": "3.3.0",
3
3
  "compatible": []
4
4
  }