@sevenfold/setto-client 0.46.0 → 0.47.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/chrome.d.ts +8 -0
- package/dist/chunks/SettoChat-C4QpE5Gm.js +14860 -0
- package/dist/chunks/SettoChat-C4QpE5Gm.js.map +1 -0
- package/dist/chunks/supabase-Dn3DJaKR.js +20737 -0
- package/dist/chunks/supabase-Dn3DJaKR.js.map +1 -0
- package/dist/lib/api.d.ts +7 -1
- package/dist/lib/supabase.d.ts +58 -7
- package/dist/lib/use-site-access.d.ts +3 -1
- package/dist/modules/chat/SettoChat.d.ts +10 -2
- package/dist/modules/chat/index.d.ts +31 -1
- package/dist/modules/chat/settings.d.ts +25 -0
- package/dist/provider.d.ts +20 -2
- package/dist/setto-client.js +1967 -37307
- package/dist/setto-client.js.map +1 -1
- package/package.json +1 -1
package/dist/lib/api.d.ts
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import type { SupabaseClient } from '@supabase/supabase-js';
|
|
2
2
|
import type { ContentFile, PublishFile, PublishResult } from '../types.js';
|
|
3
3
|
import type { AssetDraft } from './asset-store.js';
|
|
4
|
+
/**
|
|
5
|
+
* The client a call should read its token from: the one already loaded, the
|
|
6
|
+
* one being loaded, or null when nobody on this page has needed supabase-js
|
|
7
|
+
* yet — which means nobody is signed in (see `lib/supabase.ts`).
|
|
8
|
+
*/
|
|
9
|
+
export type SupabaseSource = SupabaseClient | (() => Promise<SupabaseClient | null>);
|
|
4
10
|
/**
|
|
5
11
|
* One authenticated JSON call against setto-server. Modules build their api
|
|
6
12
|
* segment on this (see `modules/forms/api.ts`) rather than on `fetch`, so
|
|
@@ -12,7 +18,7 @@ export type ApiRequest = <T>(path: string, init?: {
|
|
|
12
18
|
}, label?: string) => Promise<T>;
|
|
13
19
|
export declare function createApi(args: {
|
|
14
20
|
apiUrl: string;
|
|
15
|
-
supabase:
|
|
21
|
+
supabase: SupabaseSource;
|
|
16
22
|
}): {
|
|
17
23
|
request: ApiRequest;
|
|
18
24
|
forms: {
|
package/dist/lib/supabase.d.ts
CHANGED
|
@@ -1,9 +1,60 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
* Returns a Supabase client for a given (url, anonKey) pair.
|
|
4
|
-
* Memoised so we never create more than one client per provider mount.
|
|
5
|
-
*/
|
|
6
|
-
export declare function getSupabase(config: {
|
|
1
|
+
import type { SupabaseClient } from '@supabase/supabase-js';
|
|
2
|
+
export interface SupabaseConnection {
|
|
7
3
|
url: string;
|
|
8
4
|
anonKey: string;
|
|
9
|
-
}
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Where supabase-js keeps the session for this project, in `localStorage`.
|
|
8
|
+
* Per project URL so a host site with a Supabase of its own never collides,
|
|
9
|
+
* and so local `supabase start` sessions stay apart from production ones.
|
|
10
|
+
*/
|
|
11
|
+
export declare function supabaseStorageKey(url: string): string;
|
|
12
|
+
/**
|
|
13
|
+
* One client per Supabase project, fetched only when somebody needs it.
|
|
14
|
+
*
|
|
15
|
+
* supabase-js is about 200 kB of the bundle every visitor of every site
|
|
16
|
+
* downloaded, and a visitor is never signed in: the client was created, read
|
|
17
|
+
* an empty `localStorage` and did nothing else for the whole visit. So the
|
|
18
|
+
* library is a separate chunk now, loaded the first time something asks —
|
|
19
|
+
* a stored session, the `/setto` page, a sign-in arriving in the URL, an
|
|
20
|
+
* editor's chrome, or the visitor chat joining its Realtime channel.
|
|
21
|
+
*/
|
|
22
|
+
export interface SupabaseLoader {
|
|
23
|
+
/** The client once it has loaded, otherwise null. */
|
|
24
|
+
readonly client: SupabaseClient | null;
|
|
25
|
+
/** True while the library is being fetched. */
|
|
26
|
+
readonly loading: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* The client, loading it on first call. Memoised: every caller gets the
|
|
29
|
+
* same client. A failed fetch (a stale chunk after a deploy, a dropped
|
|
30
|
+
* connection) rejects, and the next call tries again.
|
|
31
|
+
*/
|
|
32
|
+
load(): Promise<SupabaseClient>;
|
|
33
|
+
}
|
|
34
|
+
export declare function supabaseLoader(config: SupabaseConnection): SupabaseLoader;
|
|
35
|
+
/** The client for this project, loading supabase-js on first call. */
|
|
36
|
+
export declare function loadSupabase(config: SupabaseConnection): Promise<SupabaseClient>;
|
|
37
|
+
/** True when `localStorage` holds anything supabase-js wrote for this project. */
|
|
38
|
+
export declare function hasStoredSession(url: string, storage: Pick<Storage, 'length' | 'key'> | null): boolean;
|
|
39
|
+
/**
|
|
40
|
+
* A sign-in arriving in the address: the implicit-flow fragment GoTrue and
|
|
41
|
+
* setto-server's handoffs append (`#access_token=…&refresh_token=…`, which is
|
|
42
|
+
* also how the support account's «Rediger» lands), an auth error, or an
|
|
43
|
+
* invite/recovery callback. supabase-js reads and clears these itself
|
|
44
|
+
* (`detectSessionInUrl`), so the client must exist on such a page.
|
|
45
|
+
*/
|
|
46
|
+
export declare function hasAuthInUrl(hash: string, search: string): boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Whether this page load can have a signed-in person on it, and so needs
|
|
49
|
+
* supabase-js from the start: a session stored for this project, the
|
|
50
|
+
* `/setto` page (the sign-in and the dashboard), or a sign-in in the URL.
|
|
51
|
+
* Anything else is a visitor, whose answer — no session — is known without it.
|
|
52
|
+
*/
|
|
53
|
+
export declare function needsSupabaseAtStart(config: SupabaseConnection, env: {
|
|
54
|
+
pathname: string;
|
|
55
|
+
hash: string;
|
|
56
|
+
search: string;
|
|
57
|
+
storage: Pick<Storage, 'length' | 'key'> | null;
|
|
58
|
+
}): boolean;
|
|
59
|
+
/** `localStorage`, or null where reading it throws. */
|
|
60
|
+
export declare function browserStorage(): Storage | null;
|
|
@@ -13,4 +13,6 @@ export interface SiteAccessState {
|
|
|
13
13
|
* the user has access to `siteId`. Returns a stable shape across loading,
|
|
14
14
|
* success, and failure so callers can read `currentSite` directly.
|
|
15
15
|
*/
|
|
16
|
-
export declare function useSiteAccess(
|
|
16
|
+
export declare function useSiteAccess(
|
|
17
|
+
/** Null until supabase-js has loaded, which it has whenever there is a session. */
|
|
18
|
+
supabase: SupabaseClient | null, session: Session | null, siteId: string): SiteAccessState;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type ReactNode } from 'react';
|
|
2
2
|
import { type MessageTranslation } from './translation-caption.js';
|
|
3
|
+
import { type PublicSettings } from './settings.js';
|
|
3
4
|
type Attachment = {
|
|
4
5
|
id: string;
|
|
5
6
|
url: string;
|
|
@@ -152,6 +153,13 @@ export type Mentionable = {
|
|
|
152
153
|
/** People only: green when online now. */
|
|
153
154
|
online?: boolean;
|
|
154
155
|
};
|
|
155
|
-
/**
|
|
156
|
-
|
|
156
|
+
/**
|
|
157
|
+
* Responsive visitor conversation. Its drawer only contains this browser's site chats.
|
|
158
|
+
*
|
|
159
|
+
* Loaded on its own, and only for a site whose chat is on: `SettoChat` in
|
|
160
|
+
* `index.ts` asks for the settings and hands them here (0.47).
|
|
161
|
+
*/
|
|
162
|
+
export declare function SettoChatWidget({ settings }: {
|
|
163
|
+
settings: PublicSettings;
|
|
164
|
+
}): import("react/jsx-runtime").JSX.Element | null;
|
|
157
165
|
export {};
|
|
@@ -1,3 +1,33 @@
|
|
|
1
|
+
import { Component, type ReactNode } from 'react';
|
|
1
2
|
import type { SettoModule } from '../module.js';
|
|
2
3
|
export declare const chatModule: SettoModule;
|
|
3
|
-
|
|
4
|
+
/**
|
|
5
|
+
* A widget that will not load (a chunk gone after a deploy, a dropped
|
|
6
|
+
* connection) or throws leaves the site as it was: no chat, no white page.
|
|
7
|
+
*/
|
|
8
|
+
declare class ChatBoundary extends Component<{
|
|
9
|
+
children: ReactNode;
|
|
10
|
+
}, {
|
|
11
|
+
failed: boolean;
|
|
12
|
+
}> {
|
|
13
|
+
state: {
|
|
14
|
+
failed: boolean;
|
|
15
|
+
};
|
|
16
|
+
static getDerivedStateFromError(): {
|
|
17
|
+
failed: boolean;
|
|
18
|
+
};
|
|
19
|
+
componentDidCatch(error: unknown): void;
|
|
20
|
+
render(): ReactNode;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The visitor chat, when the site has it switched on.
|
|
24
|
+
*
|
|
25
|
+
* Asks setto-server for the public settings and fetches the widget only when
|
|
26
|
+
* they say chat is on (0.47). Renders nothing until then, nothing on `/setto`,
|
|
27
|
+
* and nothing at all for a site without chat. The provider mounts it already;
|
|
28
|
+
* a site does not need to.
|
|
29
|
+
*/
|
|
30
|
+
export declare function SettoChat(): import("react").CElement<{
|
|
31
|
+
children: ReactNode;
|
|
32
|
+
}, ChatBoundary> | null;
|
|
33
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The chat's public settings: whether the site has chat at all, and how it
|
|
3
|
+
* introduces itself.
|
|
4
|
+
*
|
|
5
|
+
* Its own file, apart from the widget, because this is the one question every
|
|
6
|
+
* visitor's page asks; the widget and its Markdown renderer are fetched only
|
|
7
|
+
* when the answer is yes (see `index.ts`).
|
|
8
|
+
*/
|
|
9
|
+
export type PublicSettings = {
|
|
10
|
+
enabled: boolean;
|
|
11
|
+
displayName: string | null;
|
|
12
|
+
greeting: string;
|
|
13
|
+
/** The owner's opening line per language; an older server omits it. */
|
|
14
|
+
welcome?: {
|
|
15
|
+
no?: string | null;
|
|
16
|
+
en?: string | null;
|
|
17
|
+
} | null;
|
|
18
|
+
/** The assistant's persona on this site; an older server omits both. */
|
|
19
|
+
agentName?: string | null;
|
|
20
|
+
agentAvatarUrl?: string | null;
|
|
21
|
+
};
|
|
22
|
+
/** Never on Setto's own page, where the owner's chat is the dashboard's. */
|
|
23
|
+
export declare function chatShownHere(pathname: string): boolean;
|
|
24
|
+
/** The settings when chat is on, otherwise null — including when the call fails. */
|
|
25
|
+
export declare function fetchEnabledChatSettings(apiUrl: string, siteId: string, signal?: AbortSignal): Promise<PublicSettings | null>;
|
package/dist/provider.d.ts
CHANGED
|
@@ -8,10 +8,28 @@ import { PageStore } from './lib/page-store.js';
|
|
|
8
8
|
import type { SettoConfig, SiteRow } from './types.js';
|
|
9
9
|
export interface SettoContextValue {
|
|
10
10
|
config: SettoConfig;
|
|
11
|
-
|
|
11
|
+
/**
|
|
12
|
+
* The Supabase client, or null until supabase-js has loaded (0.47).
|
|
13
|
+
*
|
|
14
|
+
* The library is fetched only when someone can be signed in: a session is
|
|
15
|
+
* stored for this project, the page is `/setto`, a sign-in arrives in the
|
|
16
|
+
* URL, the chrome offers an editor component, or `loadSupabase` is called.
|
|
17
|
+
* For a visitor it stays null for the whole visit. It is never null while
|
|
18
|
+
* `session` is set, and never null inside a component the chrome offered
|
|
19
|
+
* through a slot. Elsewhere, check it or call `loadSupabase`.
|
|
20
|
+
*/
|
|
21
|
+
supabase: SupabaseClient | null;
|
|
22
|
+
/**
|
|
23
|
+
* The Supabase client, loading supabase-js first if nothing has yet (0.47).
|
|
24
|
+
* Memoised: always the same client as `supabase`. Absent on older clients.
|
|
25
|
+
*/
|
|
26
|
+
loadSupabase: () => Promise<SupabaseClient>;
|
|
12
27
|
api: SettoApi;
|
|
13
28
|
session: Session | null;
|
|
14
|
-
/**
|
|
29
|
+
/**
|
|
30
|
+
* True while the initial auth state is being read from local storage. False
|
|
31
|
+
* from the first render for a visitor with no stored session (0.47).
|
|
32
|
+
*/
|
|
15
33
|
authLoading: boolean;
|
|
16
34
|
/**
|
|
17
35
|
* True while the owner is editing: `canEdit`, and they chose to edit. What
|