@tabs-and-spaces/sdk 0.2.0 → 0.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/dist/client.d.ts +10 -2
- package/dist/client.js +9 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/protocol.d.ts +41 -2
- package/dist/protocol.js +15 -0
- package/dist/server.d.ts +4 -2
- package/dist/server.js +1 -0
- package/package.json +1 -1
package/dist/client.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type DataRecord, type DataRequest, type DataScope, type EventKey, type
|
|
1
|
+
import { type DataRecord, type DataRequest, type DataScope, type EventKey, type PageContext, type Theme } from "./protocol.js";
|
|
2
2
|
/** A refusal from the workspace, with its reason's code (like `INVALID` or `FORBIDDEN`). */
|
|
3
3
|
export declare class WorkspaceError extends Error {
|
|
4
4
|
readonly code: string | null;
|
|
@@ -35,7 +35,7 @@ export interface Collection<T extends Record<string, unknown> = Record<string, u
|
|
|
35
35
|
}
|
|
36
36
|
export interface Connection {
|
|
37
37
|
/** Who's looking, and where. */
|
|
38
|
-
readonly context:
|
|
38
|
+
readonly context: PageContext;
|
|
39
39
|
/** The workspace's theme now. */
|
|
40
40
|
readonly theme: Theme;
|
|
41
41
|
/**
|
|
@@ -67,6 +67,14 @@ export interface Connection {
|
|
|
67
67
|
* with `NO_TASKS_TAB` when the space has no Tasks tab to keep triggers in.
|
|
68
68
|
*/
|
|
69
69
|
openTrigger(event?: string): Promise<void>;
|
|
70
|
+
/**
|
|
71
|
+
* Takes the person to a space, or one of its tabs (decision 177): a home page's
|
|
72
|
+
* links into the workspace. The workspace goes there; your page is left.
|
|
73
|
+
*/
|
|
74
|
+
open(target: {
|
|
75
|
+
space: string;
|
|
76
|
+
tab?: string;
|
|
77
|
+
}): Promise<void>;
|
|
70
78
|
/** Called when the reader switches between light and dark. Returns an unsubscribe. */
|
|
71
79
|
onTheme(listener: (theme: Theme) => void): () => void;
|
|
72
80
|
/** Stops listening. */
|
package/dist/client.js
CHANGED
|
@@ -125,6 +125,15 @@ export function connect({ timeoutMs = 10_000, window: win = window } = {}) {
|
|
|
125
125
|
await ask((id) => ({ tands: 1, type: "event", id, name, data: fields }));
|
|
126
126
|
},
|
|
127
127
|
requestEventKey: () => ask((id) => ({ tands: 1, type: "eventKey", id })),
|
|
128
|
+
async open(target) {
|
|
129
|
+
await ask((id) => ({
|
|
130
|
+
tands: 1,
|
|
131
|
+
type: "open",
|
|
132
|
+
id,
|
|
133
|
+
space: target.space,
|
|
134
|
+
tab: target.tab ?? null,
|
|
135
|
+
}));
|
|
136
|
+
},
|
|
128
137
|
async openTrigger(event) {
|
|
129
138
|
await ask((id) => ({ tands: 1, type: "openTrigger", id, event: event ?? null }));
|
|
130
139
|
},
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Tabs & Spaces apps (M9). In a Custom tab's page: `connect()`. On your
|
|
2
|
+
* Tabs & Spaces apps (M9). In a Custom tab's or home page's page: `connect()`. On your
|
|
3
3
|
* server: `verifyToken()` from "@tabs-and-spaces/sdk/server".
|
|
4
4
|
*/
|
|
5
5
|
export { connect, WorkspaceError, type Collection, type Connection, type ConnectOptions, type Values, } from "./client.js";
|
|
6
|
-
export { PROTOCOL_VERSION, readAppMessage, readHostMessage, type AppMessage, type DataRecord, type DataRequest, type DataScope, type EventKey, type HostMessage, type TabContext, type Theme, } from "./protocol.js";
|
|
6
|
+
export { PROTOCOL_VERSION, readAppMessage, readHostMessage, type AppMessage, type DataRecord, type DataRequest, type DataScope, type EventKey, type HomeContext, type HostMessage, isHome, type PageContext, type TabContext, type Theme, } from "./protocol.js";
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Tabs & Spaces apps (M9). In a Custom tab's page: `connect()`. On your
|
|
2
|
+
* Tabs & Spaces apps (M9). In a Custom tab's or home page's page: `connect()`. On your
|
|
3
3
|
* server: `verifyToken()` from "@tabs-and-spaces/sdk/server".
|
|
4
4
|
*/
|
|
5
5
|
export { connect, WorkspaceError, } from "./client.js";
|
|
6
|
-
export { PROTOCOL_VERSION, readAppMessage, readHostMessage, } from "./protocol.js";
|
|
6
|
+
export { PROTOCOL_VERSION, readAppMessage, readHostMessage, isHome, } from "./protocol.js";
|
package/dist/protocol.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* tokens and theme changes. Every message carries `tands: 1`.
|
|
6
6
|
*/
|
|
7
7
|
export declare const PROTOCOL_VERSION = 1;
|
|
8
|
-
/** Who's looking, and where (also inside the token, signed). */
|
|
8
|
+
/** Who's looking, and where, in a Custom tab (also inside the token, signed). */
|
|
9
9
|
export interface TabContext {
|
|
10
10
|
user: {
|
|
11
11
|
id: string;
|
|
@@ -35,7 +35,38 @@ export interface TabContext {
|
|
|
35
35
|
};
|
|
36
36
|
/** The reader's language, like "en" or "fr". */
|
|
37
37
|
locale: string;
|
|
38
|
+
home?: undefined;
|
|
38
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Who's looking at one of your home pages (decision 177): the workspace's Home,
|
|
42
|
+
* so no space or tab around it. Guests see it too: `user.guest` says so.
|
|
43
|
+
*/
|
|
44
|
+
export interface HomeContext {
|
|
45
|
+
user: {
|
|
46
|
+
id: string;
|
|
47
|
+
name: string;
|
|
48
|
+
guest: boolean;
|
|
49
|
+
};
|
|
50
|
+
workspace: {
|
|
51
|
+
id: string;
|
|
52
|
+
slug: string;
|
|
53
|
+
name: string;
|
|
54
|
+
};
|
|
55
|
+
space: null;
|
|
56
|
+
tab: null;
|
|
57
|
+
/** Which of your manifest's `home` pages this is. */
|
|
58
|
+
home: {
|
|
59
|
+
id: string;
|
|
60
|
+
};
|
|
61
|
+
app: {
|
|
62
|
+
id: string;
|
|
63
|
+
};
|
|
64
|
+
locale: string;
|
|
65
|
+
}
|
|
66
|
+
/** Where your page is: a Custom tab in a space, or the workspace's Home. */
|
|
67
|
+
export type PageContext = TabContext | HomeContext;
|
|
68
|
+
/** Whether your page is the workspace's Home (no space or tab around it). */
|
|
69
|
+
export declare const isHome: (context: PageContext) => context is HomeContext;
|
|
39
70
|
export type Theme = "light" | "dark";
|
|
40
71
|
/** Where app data lives, and so who sees it. */
|
|
41
72
|
export type DataScope = "workspace" | "space" | "tab" | "user";
|
|
@@ -139,6 +170,14 @@ export type AppMessage = {
|
|
|
139
170
|
type: "openTrigger";
|
|
140
171
|
id: string;
|
|
141
172
|
event: string | null;
|
|
173
|
+
}
|
|
174
|
+
/** Takes the person to a space, or one of its tabs (decision 177). Answered like data. */
|
|
175
|
+
| {
|
|
176
|
+
tands: 1;
|
|
177
|
+
type: "open";
|
|
178
|
+
id: string;
|
|
179
|
+
space: string;
|
|
180
|
+
tab: string | null;
|
|
142
181
|
};
|
|
143
182
|
/** What the app's server reports events with, at `eventsUrl` (decision 170). */
|
|
144
183
|
export interface EventKey {
|
|
@@ -149,7 +188,7 @@ export interface EventKey {
|
|
|
149
188
|
export type HostMessage = {
|
|
150
189
|
tands: 1;
|
|
151
190
|
type: "context";
|
|
152
|
-
context:
|
|
191
|
+
context: PageContext;
|
|
153
192
|
token: string;
|
|
154
193
|
expiresAt: string;
|
|
155
194
|
theme: Theme;
|
package/dist/protocol.js
CHANGED
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
* tokens and theme changes. Every message carries `tands: 1`.
|
|
6
6
|
*/
|
|
7
7
|
export const PROTOCOL_VERSION = 1;
|
|
8
|
+
/** Whether your page is the workspace's Home (no space or tab around it). */
|
|
9
|
+
export const isHome = (context) => Boolean(context.home);
|
|
8
10
|
const isRecord = (value) => typeof value === "object" && value !== null;
|
|
9
11
|
/** A message from an app's page, or null. */
|
|
10
12
|
export function readAppMessage(data) {
|
|
@@ -39,6 +41,19 @@ export function readAppMessage(data) {
|
|
|
39
41
|
event: typeof data.event === "string" ? data.event : null,
|
|
40
42
|
};
|
|
41
43
|
}
|
|
44
|
+
const id = (value) => typeof value === "string" && value.length > 0 && value.length <= 64;
|
|
45
|
+
if (data.type === "open" &&
|
|
46
|
+
id(data.id) &&
|
|
47
|
+
id(data.space) &&
|
|
48
|
+
(data.tab === undefined || data.tab === null || id(data.tab))) {
|
|
49
|
+
return {
|
|
50
|
+
tands: 1,
|
|
51
|
+
type: "open",
|
|
52
|
+
id: data.id,
|
|
53
|
+
space: data.space,
|
|
54
|
+
tab: typeof data.tab === "string" ? data.tab : null,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
42
57
|
if (data.type === "event" &&
|
|
43
58
|
typeof data.id === "string" &&
|
|
44
59
|
data.id.length <= 64 &&
|
package/dist/server.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { DataRecord, DataRequest, DataScope, EventKey, TabContext } from "./protocol.js";
|
|
1
|
+
import type { DataRecord, DataRequest, DataScope, EventKey, PageContext, TabContext } from "./protocol.js";
|
|
2
|
+
export { isHome, type HomeContext, type PageContext, type TabContext } from "./protocol.js";
|
|
2
3
|
/**
|
|
3
4
|
* Checking a Custom tab's token on your server (Node 22+, Deno, Bun, Workers:
|
|
4
5
|
* anywhere with Web Crypto's Ed25519). The workspace signs it (EdDSA); its
|
|
@@ -17,7 +18,8 @@ export interface PublicKey {
|
|
|
17
18
|
alg?: string;
|
|
18
19
|
}
|
|
19
20
|
export interface VerifiedToken {
|
|
20
|
-
|
|
21
|
+
/** A Custom tab's, or a home page's (`isHome()`); an action's is always a tab's. */
|
|
22
|
+
context: PageContext;
|
|
21
23
|
/** The deployment that signed it (its public address). */
|
|
22
24
|
issuer: string;
|
|
23
25
|
expiresAt: Date;
|
package/dist/server.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tabs-and-spaces/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Building apps for Tabs & Spaces: a Custom tab's page talks to the workspace, its server checks who's looking. No dependencies.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Tabs & Spaces",
|