@telecabin/core 0.1.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 +66 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +170 -0
- package/dist/client.js.map +1 -0
- package/dist/config.d.ts +73 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +124 -0
- package/dist/config.js.map +1 -0
- package/dist/errors.d.ts +16 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +72 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/owner.d.ts +68 -0
- package/dist/owner.d.ts.map +1 -0
- package/dist/owner.js +116 -0
- package/dist/owner.js.map +1 -0
- package/dist/types.d.ts +116 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +38 -0
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { InvitePreview, JoinResult, PollResult, Snapshot, Status, TelecabinEvent } from "./types.js";
|
|
2
|
+
/** Default deployment used when no base URL is configured. */
|
|
3
|
+
export declare const DEFAULT_BASE_URL = "https://telecabin.app";
|
|
4
|
+
export interface ClientOptions {
|
|
5
|
+
baseUrl: string;
|
|
6
|
+
slug: string;
|
|
7
|
+
token: string;
|
|
8
|
+
/** Override `fetch` (for tests). Defaults to the global. */
|
|
9
|
+
fetch?: typeof fetch;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Participant-side client for a single telecabin session.
|
|
13
|
+
*
|
|
14
|
+
* Construct one with a `baseUrl`, `slug`, and bearer `token`, then read and
|
|
15
|
+
* write the session. Use the static `join` / `previewInvite` helpers to obtain
|
|
16
|
+
* a token from an invite code.
|
|
17
|
+
*/
|
|
18
|
+
export declare class TelecabinClient {
|
|
19
|
+
readonly baseUrl: string;
|
|
20
|
+
readonly slug: string;
|
|
21
|
+
private readonly token;
|
|
22
|
+
private readonly fetchImpl;
|
|
23
|
+
constructor(opts: ClientOptions);
|
|
24
|
+
private request;
|
|
25
|
+
/** Full session snapshot: status, participants, recent messages, cursor. */
|
|
26
|
+
snapshot(signal?: AbortSignal): Promise<Snapshot>;
|
|
27
|
+
/** Events strictly after `after`. Pass the returned `cursor` to the next call. */
|
|
28
|
+
poll(after?: number, limit?: number, signal?: AbortSignal): Promise<PollResult>;
|
|
29
|
+
/** Post a message. The server also resets your status to `idle`. */
|
|
30
|
+
send(content: string, signal?: AbortSignal): Promise<TelecabinEvent>;
|
|
31
|
+
/** Broadcast your presence status. */
|
|
32
|
+
setStatus(status: Status, meta?: Record<string, unknown>, signal?: AbortSignal): Promise<TelecabinEvent>;
|
|
33
|
+
/**
|
|
34
|
+
* Continuously poll and yield events as they arrive. Runs until the
|
|
35
|
+
* `signal` aborts. `intervalMs` is the gap between polls (default 2000).
|
|
36
|
+
*/
|
|
37
|
+
stream(opts?: {
|
|
38
|
+
after?: number;
|
|
39
|
+
intervalMs?: number;
|
|
40
|
+
signal?: AbortSignal;
|
|
41
|
+
}): AsyncGenerator<TelecabinEvent, void>;
|
|
42
|
+
/**
|
|
43
|
+
* Poll until at least one matching event appears or the timeout elapses.
|
|
44
|
+
* Returns matching events (empty on timeout) and the advanced cursor.
|
|
45
|
+
*/
|
|
46
|
+
waitForEvent(after: number, opts?: {
|
|
47
|
+
timeoutSec?: number;
|
|
48
|
+
intervalMs?: number;
|
|
49
|
+
filter?: (e: TelecabinEvent) => boolean;
|
|
50
|
+
signal?: AbortSignal;
|
|
51
|
+
}): Promise<PollResult>;
|
|
52
|
+
/** Join a session with an invite code, minting a fresh participant token. */
|
|
53
|
+
static join(opts: {
|
|
54
|
+
baseUrl: string;
|
|
55
|
+
code: string;
|
|
56
|
+
name: string;
|
|
57
|
+
fetch?: typeof fetch;
|
|
58
|
+
}): Promise<JoinResult>;
|
|
59
|
+
/** Preview the session behind an invite code without joining. */
|
|
60
|
+
static previewInvite(opts: {
|
|
61
|
+
baseUrl: string;
|
|
62
|
+
code: string;
|
|
63
|
+
fetch?: typeof fetch;
|
|
64
|
+
}): Promise<InvitePreview>;
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,aAAa,EACb,UAAU,EACV,UAAU,EACV,QAAQ,EACR,MAAM,EACN,cAAc,EACf,MAAM,YAAY,CAAC;AAEpB,8DAA8D;AAC9D,eAAO,MAAM,gBAAgB,0BAA0B,CAAC;AAExD,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,4DAA4D;IAC5D,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;CACtB;AAuBD;;;;;;GAMG;AACH,qBAAa,eAAe;IAC1B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAS;IAC/B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAe;gBAE7B,IAAI,EAAE,aAAa;YAOjB,OAAO;IA4BrB,4EAA4E;IAC5E,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,QAAQ,CAAC;IAIjD,kFAAkF;IAClF,IAAI,CAAC,KAAK,SAAI,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC;IAQ1E,oEAAoE;IAC9D,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,cAAc,CAAC;IAQ1E,sCAAsC;IAChC,SAAS,CACb,MAAM,EAAE,MAAM,EACd,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9B,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,cAAc,CAAC;IAQ1B;;;OAGG;IACI,MAAM,CACX,IAAI,GAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,WAAW,CAAA;KAAO,GACvE,cAAc,CAAC,cAAc,EAAE,IAAI,CAAC;IAoBvC;;;OAGG;IACG,YAAY,CAChB,KAAK,EAAE,MAAM,EACb,IAAI,GAAE;QACJ,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,MAAM,CAAC,EAAE,CAAC,CAAC,EAAE,cAAc,KAAK,OAAO,CAAC;QACxC,MAAM,CAAC,EAAE,WAAW,CAAC;KACjB,GACL,OAAO,CAAC,UAAU,CAAC;IAetB,6EAA6E;WAChE,IAAI,CAAC,IAAI,EAAE;QACtB,OAAO,EAAE,MAAM,CAAC;QAChB,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;KACtB,GAAG,OAAO,CAAC,UAAU,CAAC;IA8BvB,iEAAiE;WACpD,aAAa,CAAC,IAAI,EAAE;QAC/B,OAAO,EAAE,MAAM,CAAC;QAChB,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;KACtB,GAAG,OAAO,CAAC,aAAa,CAAC;CAgB3B"}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { TelecabinError } from "./errors.js";
|
|
2
|
+
/** Default deployment used when no base URL is configured. */
|
|
3
|
+
export const DEFAULT_BASE_URL = "https://telecabin.app";
|
|
4
|
+
function sleep(ms, signal) {
|
|
5
|
+
return new Promise((resolve, reject) => {
|
|
6
|
+
if (signal?.aborted)
|
|
7
|
+
return reject(new DOMException("Aborted", "AbortError"));
|
|
8
|
+
const t = setTimeout(() => {
|
|
9
|
+
signal?.removeEventListener("abort", onAbort);
|
|
10
|
+
resolve();
|
|
11
|
+
}, ms);
|
|
12
|
+
const onAbort = () => {
|
|
13
|
+
clearTimeout(t);
|
|
14
|
+
reject(new DOMException("Aborted", "AbortError"));
|
|
15
|
+
};
|
|
16
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Participant-side client for a single telecabin session.
|
|
21
|
+
*
|
|
22
|
+
* Construct one with a `baseUrl`, `slug`, and bearer `token`, then read and
|
|
23
|
+
* write the session. Use the static `join` / `previewInvite` helpers to obtain
|
|
24
|
+
* a token from an invite code.
|
|
25
|
+
*/
|
|
26
|
+
export class TelecabinClient {
|
|
27
|
+
baseUrl;
|
|
28
|
+
slug;
|
|
29
|
+
token;
|
|
30
|
+
fetchImpl;
|
|
31
|
+
constructor(opts) {
|
|
32
|
+
this.baseUrl = opts.baseUrl.replace(/\/+$/, "");
|
|
33
|
+
this.slug = opts.slug;
|
|
34
|
+
this.token = opts.token;
|
|
35
|
+
this.fetchImpl = opts.fetch ?? fetch;
|
|
36
|
+
}
|
|
37
|
+
async request(path, init) {
|
|
38
|
+
const headers = {
|
|
39
|
+
Authorization: `Bearer ${this.token}`,
|
|
40
|
+
};
|
|
41
|
+
const reqInit = {
|
|
42
|
+
method: init?.method ?? "GET",
|
|
43
|
+
headers,
|
|
44
|
+
signal: init?.signal,
|
|
45
|
+
};
|
|
46
|
+
if (init?.body !== undefined) {
|
|
47
|
+
headers["Content-Type"] = "application/json";
|
|
48
|
+
reqInit.body = JSON.stringify(init.body);
|
|
49
|
+
}
|
|
50
|
+
let res;
|
|
51
|
+
try {
|
|
52
|
+
res = await this.fetchImpl(`${this.baseUrl}${path}`, reqInit);
|
|
53
|
+
}
|
|
54
|
+
catch (err) {
|
|
55
|
+
if (err instanceof DOMException && err.name === "AbortError")
|
|
56
|
+
throw err;
|
|
57
|
+
throw new TelecabinError("network_error", `Cannot reach ${this.baseUrl}: ${err.message}`);
|
|
58
|
+
}
|
|
59
|
+
if (!res.ok)
|
|
60
|
+
throw await TelecabinError.fromResponse(res);
|
|
61
|
+
return (await res.json());
|
|
62
|
+
}
|
|
63
|
+
/** Full session snapshot: status, participants, recent messages, cursor. */
|
|
64
|
+
snapshot(signal) {
|
|
65
|
+
return this.request(`/api/s/${this.slug}`, { signal });
|
|
66
|
+
}
|
|
67
|
+
/** Events strictly after `after`. Pass the returned `cursor` to the next call. */
|
|
68
|
+
poll(after = 0, limit, signal) {
|
|
69
|
+
const qs = new URLSearchParams({ after: String(after) });
|
|
70
|
+
if (limit)
|
|
71
|
+
qs.set("limit", String(limit));
|
|
72
|
+
return this.request(`/api/s/${this.slug}/events?${qs}`, {
|
|
73
|
+
signal,
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
/** Post a message. The server also resets your status to `idle`. */
|
|
77
|
+
async send(content, signal) {
|
|
78
|
+
const r = await this.request(`/api/s/${this.slug}/messages`, { method: "POST", body: { content }, signal });
|
|
79
|
+
return r.event;
|
|
80
|
+
}
|
|
81
|
+
/** Broadcast your presence status. */
|
|
82
|
+
async setStatus(status, meta, signal) {
|
|
83
|
+
const r = await this.request(`/api/s/${this.slug}/status`, { method: "POST", body: meta ? { status, meta } : { status }, signal });
|
|
84
|
+
return r.event;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Continuously poll and yield events as they arrive. Runs until the
|
|
88
|
+
* `signal` aborts. `intervalMs` is the gap between polls (default 2000).
|
|
89
|
+
*/
|
|
90
|
+
async *stream(opts = {}) {
|
|
91
|
+
let cursor = opts.after ?? 0;
|
|
92
|
+
const interval = opts.intervalMs ?? 2000;
|
|
93
|
+
try {
|
|
94
|
+
while (!opts.signal?.aborted) {
|
|
95
|
+
const { events, cursor: next } = await this.poll(cursor, undefined, opts.signal);
|
|
96
|
+
for (const e of events)
|
|
97
|
+
yield e;
|
|
98
|
+
cursor = next;
|
|
99
|
+
await sleep(interval, opts.signal);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
catch (err) {
|
|
103
|
+
if (err instanceof DOMException && err.name === "AbortError")
|
|
104
|
+
return;
|
|
105
|
+
throw err;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Poll until at least one matching event appears or the timeout elapses.
|
|
110
|
+
* Returns matching events (empty on timeout) and the advanced cursor.
|
|
111
|
+
*/
|
|
112
|
+
async waitForEvent(after, opts = {}) {
|
|
113
|
+
const deadline = Date.now() + (opts.timeoutSec ?? 50) * 1000;
|
|
114
|
+
const interval = opts.intervalMs ?? 2000;
|
|
115
|
+
let cursor = after;
|
|
116
|
+
for (;;) {
|
|
117
|
+
const res = await this.poll(cursor, undefined, opts.signal);
|
|
118
|
+
cursor = res.cursor;
|
|
119
|
+
const matched = opts.filter ? res.events.filter(opts.filter) : res.events;
|
|
120
|
+
if (matched.length > 0)
|
|
121
|
+
return { events: matched, cursor };
|
|
122
|
+
const remaining = deadline - Date.now();
|
|
123
|
+
if (remaining <= 0)
|
|
124
|
+
return { events: [], cursor };
|
|
125
|
+
await sleep(Math.min(interval, remaining), opts.signal);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
/** Join a session with an invite code, minting a fresh participant token. */
|
|
129
|
+
static async join(opts) {
|
|
130
|
+
const base = opts.baseUrl.replace(/\/+$/, "");
|
|
131
|
+
const fetchImpl = opts.fetch ?? fetch;
|
|
132
|
+
let res;
|
|
133
|
+
try {
|
|
134
|
+
res = await fetchImpl(`${base}/api/join/${encodeURIComponent(opts.code)}`, {
|
|
135
|
+
method: "POST",
|
|
136
|
+
headers: { "Content-Type": "application/json" },
|
|
137
|
+
body: JSON.stringify({ name: opts.name }),
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
catch (err) {
|
|
141
|
+
throw new TelecabinError("network_error", `Cannot reach ${base}: ${err.message}`);
|
|
142
|
+
}
|
|
143
|
+
if (!res.ok)
|
|
144
|
+
throw await TelecabinError.fromResponse(res);
|
|
145
|
+
const body = (await res.json());
|
|
146
|
+
return {
|
|
147
|
+
token: body.token,
|
|
148
|
+
slug: body.session.slug,
|
|
149
|
+
sessionName: body.session.name,
|
|
150
|
+
participant: body.participant,
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
/** Preview the session behind an invite code without joining. */
|
|
154
|
+
static async previewInvite(opts) {
|
|
155
|
+
const base = opts.baseUrl.replace(/\/+$/, "");
|
|
156
|
+
const fetchImpl = opts.fetch ?? fetch;
|
|
157
|
+
let res;
|
|
158
|
+
try {
|
|
159
|
+
res = await fetchImpl(`${base}/api/join/${encodeURIComponent(opts.code)}`);
|
|
160
|
+
}
|
|
161
|
+
catch (err) {
|
|
162
|
+
throw new TelecabinError("network_error", `Cannot reach ${base}: ${err.message}`);
|
|
163
|
+
}
|
|
164
|
+
if (!res.ok)
|
|
165
|
+
throw await TelecabinError.fromResponse(res);
|
|
166
|
+
const body = (await res.json());
|
|
167
|
+
return body.session;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAU7C,8DAA8D;AAC9D,MAAM,CAAC,MAAM,gBAAgB,GAAG,uBAAuB,CAAC;AAgBxD,SAAS,KAAK,CAAC,EAAU,EAAE,MAAoB;IAC7C,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,IAAI,MAAM,EAAE,OAAO;YAAE,OAAO,MAAM,CAAC,IAAI,YAAY,CA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,CAAC,CAAC;QAC9C,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC;QACtC,IAAI,GAAa,CAAC;QAClB,IAAI,CAAC;YACH,GAAG,GAAG,MAAM,SAAS,CAAC,GAAG,IAAI,aAAa,kBAAkB,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAC7E,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,MAAM,IAAI,cAAc,CACtB,eAAe,EACf,gBAAgB,IAAI,KAAM,GAAa,CAAC,OAAO,EAAE,CAClD,CAAC;QACJ,CAAC;QACD,IAAI,CAAC,GAAG,CAAC,EAAE;YAAE,MAAM,MAAM,cAAc,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC;QAC1D,MAAM,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,CAA+B,CAAC;QAC9D,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;CACF"}
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/** One saved session: where it lives and the token to reach it. */
|
|
2
|
+
export interface Connection {
|
|
3
|
+
baseUrl: string;
|
|
4
|
+
slug: string;
|
|
5
|
+
token: string;
|
|
6
|
+
sessionName?: string;
|
|
7
|
+
participantName?: string;
|
|
8
|
+
}
|
|
9
|
+
/** Saved owner credentials for managing sessions from the CLI. */
|
|
10
|
+
export interface OwnerProfile {
|
|
11
|
+
baseUrl: string;
|
|
12
|
+
key: string;
|
|
13
|
+
}
|
|
14
|
+
/** The on-disk config file shape. */
|
|
15
|
+
export interface TelecabinConfig {
|
|
16
|
+
defaultConnection?: string;
|
|
17
|
+
connections: Record<string, Connection>;
|
|
18
|
+
owner?: OwnerProfile;
|
|
19
|
+
}
|
|
20
|
+
/** A connection resolved from flags, env, and/or config — ready to use. */
|
|
21
|
+
export interface ResolvedConnection {
|
|
22
|
+
/** The config name this came from, if any. */
|
|
23
|
+
name?: string;
|
|
24
|
+
baseUrl: string;
|
|
25
|
+
slug: string;
|
|
26
|
+
token: string;
|
|
27
|
+
sessionName?: string;
|
|
28
|
+
participantName?: string;
|
|
29
|
+
}
|
|
30
|
+
/** Inputs that can override config when resolving a connection. */
|
|
31
|
+
export interface ResolveInput {
|
|
32
|
+
connection?: string;
|
|
33
|
+
baseUrl?: string;
|
|
34
|
+
slug?: string;
|
|
35
|
+
token?: string;
|
|
36
|
+
}
|
|
37
|
+
/** Absolute path of the telecabin config file. */
|
|
38
|
+
export declare function configPath(): string;
|
|
39
|
+
/** Read the config file, returning an empty config if it does not exist. */
|
|
40
|
+
export declare function loadConfig(): Promise<TelecabinConfig>;
|
|
41
|
+
/** Write the config file, creating its directory and locking it to 0600. */
|
|
42
|
+
export declare function saveConfig(config: TelecabinConfig): Promise<void>;
|
|
43
|
+
/** Save a connection, optionally making it the default. */
|
|
44
|
+
export declare function addConnection(name: string, connection: Connection, opts?: {
|
|
45
|
+
makeDefault?: boolean;
|
|
46
|
+
}): Promise<void>;
|
|
47
|
+
/** Remove a connection; clears the default pointer if it pointed here. */
|
|
48
|
+
export declare function removeConnection(name: string): Promise<boolean>;
|
|
49
|
+
/** Point the default at an existing connection. */
|
|
50
|
+
export declare function setDefaultConnection(name: string): Promise<void>;
|
|
51
|
+
/**
|
|
52
|
+
* Resolve the connection to use, layering inputs over env over config:
|
|
53
|
+
*
|
|
54
|
+
* field = flag ?? TELECABIN_<FIELD> env ?? chosen connection ?? default
|
|
55
|
+
*
|
|
56
|
+
* The chosen connection is `input.connection`, else `TELECABIN_CONNECTION`,
|
|
57
|
+
* else the config's `defaultConnection`. Throws `no_active_session` if no
|
|
58
|
+
* slug/token can be found.
|
|
59
|
+
*/
|
|
60
|
+
export declare function resolveConnection(input?: ResolveInput): Promise<ResolvedConnection>;
|
|
61
|
+
/** Save the owner profile (base URL + owner API key). */
|
|
62
|
+
export declare function setOwnerProfile(profile: OwnerProfile): Promise<void>;
|
|
63
|
+
/** Inputs that can override the saved owner profile. */
|
|
64
|
+
export interface ResolveOwnerInput {
|
|
65
|
+
baseUrl?: string;
|
|
66
|
+
key?: string;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Resolve owner credentials: flag → `TELECABIN_*` env → saved profile.
|
|
70
|
+
* Throws `no_active_session` when no owner key can be found.
|
|
71
|
+
*/
|
|
72
|
+
export declare function resolveOwner(input?: ResolveOwnerInput): Promise<OwnerProfile>;
|
|
73
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAMA,mEAAmE;AACnE,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,kEAAkE;AAClE,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,MAAM,CAAC;CACb;AAED,qCAAqC;AACrC,MAAM,WAAW,eAAe;IAC9B,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IACxC,KAAK,CAAC,EAAE,YAAY,CAAC;CACtB;AAED,2EAA2E;AAC3E,MAAM,WAAW,kBAAkB;IACjC,8CAA8C;IAC9C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,mEAAmE;AACnE,MAAM,WAAW,YAAY;IAC3B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,O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edir } from "node:os";
|
|
3
|
+
import { dirname, join } from "node:path";
|
|
4
|
+
import { DEFAULT_BASE_URL } from "./client.js";
|
|
5
|
+
import { TelecabinError } from "./errors.js";
|
|
6
|
+
function configDir() {
|
|
7
|
+
const xdg = process.env.XDG_CONFIG_HOME;
|
|
8
|
+
return xdg ? join(xdg, "telecabin") : join(homedir(), ".config", "telecabin");
|
|
9
|
+
}
|
|
10
|
+
/** Absolute path of the telecabin config file. */
|
|
11
|
+
export function configPath() {
|
|
12
|
+
return join(configDir(), "config.json");
|
|
13
|
+
}
|
|
14
|
+
/** Read the config file, returning an empty config if it does not exist. */
|
|
15
|
+
export async function loadConfig() {
|
|
16
|
+
let raw;
|
|
17
|
+
try {
|
|
18
|
+
raw = await readFile(configPath(), "utf8");
|
|
19
|
+
}
|
|
20
|
+
catch (err) {
|
|
21
|
+
if (err.code === "ENOENT") {
|
|
22
|
+
return { connections: {} };
|
|
23
|
+
}
|
|
24
|
+
throw err;
|
|
25
|
+
}
|
|
26
|
+
try {
|
|
27
|
+
const parsed = JSON.parse(raw);
|
|
28
|
+
return { connections: parsed.connections ?? {}, ...parsed };
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
throw new TelecabinError("http_error", `Config file at ${configPath()} is not valid JSON.`);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/** Write the config file, creating its directory and locking it to 0600. */
|
|
35
|
+
export async function saveConfig(config) {
|
|
36
|
+
const path = configPath();
|
|
37
|
+
await mkdir(dirname(path), { recursive: true });
|
|
38
|
+
await writeFile(path, `${JSON.stringify(config, null, 2)}\n`, "utf8");
|
|
39
|
+
await chmod(path, 0o600);
|
|
40
|
+
}
|
|
41
|
+
/** Save a connection, optionally making it the default. */
|
|
42
|
+
export async function addConnection(name, connection, opts = {}) {
|
|
43
|
+
const config = await loadConfig();
|
|
44
|
+
config.connections[name] = connection;
|
|
45
|
+
if (opts.makeDefault || !config.defaultConnection) {
|
|
46
|
+
config.defaultConnection = name;
|
|
47
|
+
}
|
|
48
|
+
await saveConfig(config);
|
|
49
|
+
}
|
|
50
|
+
/** Remove a connection; clears the default pointer if it pointed here. */
|
|
51
|
+
export async function removeConnection(name) {
|
|
52
|
+
const config = await loadConfig();
|
|
53
|
+
if (!config.connections[name])
|
|
54
|
+
return false;
|
|
55
|
+
delete config.connections[name];
|
|
56
|
+
if (config.defaultConnection === name) {
|
|
57
|
+
config.defaultConnection = Object.keys(config.connections)[0];
|
|
58
|
+
}
|
|
59
|
+
await saveConfig(config);
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
/** Point the default at an existing connection. */
|
|
63
|
+
export async function setDefaultConnection(name) {
|
|
64
|
+
const config = await loadConfig();
|
|
65
|
+
if (!config.connections[name]) {
|
|
66
|
+
throw new TelecabinError("no_active_session", `No saved connection named "${name}".`);
|
|
67
|
+
}
|
|
68
|
+
config.defaultConnection = name;
|
|
69
|
+
await saveConfig(config);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Resolve the connection to use, layering inputs over env over config:
|
|
73
|
+
*
|
|
74
|
+
* field = flag ?? TELECABIN_<FIELD> env ?? chosen connection ?? default
|
|
75
|
+
*
|
|
76
|
+
* The chosen connection is `input.connection`, else `TELECABIN_CONNECTION`,
|
|
77
|
+
* else the config's `defaultConnection`. Throws `no_active_session` if no
|
|
78
|
+
* slug/token can be found.
|
|
79
|
+
*/
|
|
80
|
+
export async function resolveConnection(input = {}) {
|
|
81
|
+
const config = await loadConfig();
|
|
82
|
+
const chosenName = input.connection ?? process.env.TELECABIN_CONNECTION ?? config.defaultConnection;
|
|
83
|
+
const base = chosenName ? config.connections[chosenName] : undefined;
|
|
84
|
+
if (input.connection && !base) {
|
|
85
|
+
throw new TelecabinError("no_active_session", `No saved connection named "${input.connection}". Run "telecabin connections" to list them.`);
|
|
86
|
+
}
|
|
87
|
+
const baseUrl = input.baseUrl ?? process.env.TELECABIN_BASE_URL ?? base?.baseUrl ?? DEFAULT_BASE_URL;
|
|
88
|
+
const slug = input.slug ?? process.env.TELECABIN_SLUG ?? base?.slug;
|
|
89
|
+
const token = input.token ?? process.env.TELECABIN_TOKEN ?? base?.token;
|
|
90
|
+
if (!slug || !token) {
|
|
91
|
+
throw new TelecabinError("no_active_session", 'No active session. Run "telecabin join <invite-code>", or pass --slug and --token (or set TELECABIN_SLUG / TELECABIN_TOKEN).');
|
|
92
|
+
}
|
|
93
|
+
return {
|
|
94
|
+
name: base ? chosenName : undefined,
|
|
95
|
+
baseUrl,
|
|
96
|
+
slug,
|
|
97
|
+
token,
|
|
98
|
+
sessionName: base?.sessionName,
|
|
99
|
+
participantName: base?.participantName,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
/** Save the owner profile (base URL + owner API key). */
|
|
103
|
+
export async function setOwnerProfile(profile) {
|
|
104
|
+
const config = await loadConfig();
|
|
105
|
+
config.owner = profile;
|
|
106
|
+
await saveConfig(config);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Resolve owner credentials: flag → `TELECABIN_*` env → saved profile.
|
|
110
|
+
* Throws `no_active_session` when no owner key can be found.
|
|
111
|
+
*/
|
|
112
|
+
export async function resolveOwner(input = {}) {
|
|
113
|
+
const config = await loadConfig();
|
|
114
|
+
const baseUrl = input.baseUrl ??
|
|
115
|
+
process.env.TELECABIN_BASE_URL ??
|
|
116
|
+
config.owner?.baseUrl ??
|
|
117
|
+
DEFAULT_BASE_URL;
|
|
118
|
+
const key = input.key ?? process.env.TELECABIN_OWNER_KEY ?? config.owner?.key;
|
|
119
|
+
if (!key) {
|
|
120
|
+
throw new TelecabinError("no_active_session", 'No owner key. Run "telecabin login --key tco_..." (create one in the web UI under Settings), or set TELECABIN_OWNER_KEY.');
|
|
121
|
+
}
|
|
122
|
+
return { baseUrl, key };
|
|
123
|
+
}
|
|
124
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../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AAG,EAAE,CAAC;AAC1B,CAAC"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** Stable error codes — the API's `error` strings plus a few client-side ones. */
|
|
2
|
+
export type TelecabinErrorCode = "missing_token" | "invalid_token" | "token_revoked" | "session_not_found" | "invite_not_found" | "session_closed" | "session_paused" | "rate_limited" | "invalid_body" | "invalid_cursor" | "unauthorized" | "invalid_key" | "not_found" | "network_error" | "no_active_session" | "http_error";
|
|
3
|
+
/** Every failure surfaced by `@telecabin/core` is a `TelecabinError`. */
|
|
4
|
+
export declare class TelecabinError extends Error {
|
|
5
|
+
readonly code: TelecabinErrorCode;
|
|
6
|
+
/** HTTP status, or 0 for client-side / network errors. */
|
|
7
|
+
readonly status: number;
|
|
8
|
+
/** Seconds to wait before retrying, when the server sent `Retry-After`. */
|
|
9
|
+
readonly retryAfter?: number;
|
|
10
|
+
/** Server-provided validation detail, when present. */
|
|
11
|
+
readonly detail?: unknown;
|
|
12
|
+
constructor(code: TelecabinErrorCode, message?: string, status?: number, retryAfter?: number, detail?: unknown);
|
|
13
|
+
/** Build a `TelecabinError` from a failed `fetch` Response. */
|
|
14
|
+
static fromResponse(res: Response): Promise<TelecabinError>;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,kFAAkF;AAClF,MAAM,MAAM,kBAAkB,GAC1B,eAAe,GACf,eAAe,GACf,eAAe,GACf,mBAAmB,GACnB,kBAAkB,GAClB,gBAAgB,GAChB,gBAAgB,GAChB,cAAc,GACd,cAAc,GACd,gBAAgB,GAChB,cAAc,GACd,aAAa,GACb,WAAW,GACX,eAAe,GACf,mBAAmB,GACnB,YAAY,CAAC;AAuCjB,yEAAyE;AACzE,qBAAa,cAAe,SAAQ,KAAK;IACvC,QAAQ,CAAC,IAAI,EAAE,kBAAkB,CAAC;IAClC,0DAA0D;IAC1D,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,2EAA2E;IAC3E,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,uDAAuD;IACvD,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;gBAGxB,IAAI,EAAE,kBAAkB,EACxB,OAAO,CAAC,EAAE,MAAM,EAChB,MAAM,SAAI,EACV,UAAU,CAAC,EAAE,MAAM,EACnB,MAAM,CAAC,EAAE,OAAO;IAUlB,+DAA+D;WAClD,YAAY,CAAC,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,cAAc,CAAC;CAoBlE"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
function messageFor(code, status) {
|
|
2
|
+
switch (code) {
|
|
3
|
+
case "missing_token":
|
|
4
|
+
return "No bearer token was sent.";
|
|
5
|
+
case "invalid_token":
|
|
6
|
+
return "Invalid token — check your connection credentials.";
|
|
7
|
+
case "token_revoked":
|
|
8
|
+
return "This token has been revoked by the session owner.";
|
|
9
|
+
case "session_not_found":
|
|
10
|
+
return "Session not found — the slug may be wrong or the token belongs to a different session.";
|
|
11
|
+
case "invite_not_found":
|
|
12
|
+
return "Invite code not found.";
|
|
13
|
+
case "session_closed":
|
|
14
|
+
return "This session has been closed.";
|
|
15
|
+
case "session_paused":
|
|
16
|
+
return "This session is paused — reads work, but writes are disabled.";
|
|
17
|
+
case "rate_limited":
|
|
18
|
+
return "Rate limited — slow down and retry after the indicated delay.";
|
|
19
|
+
case "invalid_cursor":
|
|
20
|
+
return "Invalid cursor value.";
|
|
21
|
+
case "invalid_body":
|
|
22
|
+
return "The request body was rejected by the server.";
|
|
23
|
+
case "unauthorized":
|
|
24
|
+
return "Unauthorized — your owner key is missing, invalid, or revoked.";
|
|
25
|
+
case "invalid_key":
|
|
26
|
+
return "Invalid owner API key.";
|
|
27
|
+
case "not_found":
|
|
28
|
+
return "Not found.";
|
|
29
|
+
case "network_error":
|
|
30
|
+
return "Could not reach the telecabin server.";
|
|
31
|
+
case "no_active_session":
|
|
32
|
+
return "No active session — join or connect to a session first.";
|
|
33
|
+
default:
|
|
34
|
+
return `Request failed (HTTP ${status}).`;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/** Every failure surfaced by `@telecabin/core` is a `TelecabinError`. */
|
|
38
|
+
export class TelecabinError extends Error {
|
|
39
|
+
code;
|
|
40
|
+
/** HTTP status, or 0 for client-side / network errors. */
|
|
41
|
+
status;
|
|
42
|
+
/** Seconds to wait before retrying, when the server sent `Retry-After`. */
|
|
43
|
+
retryAfter;
|
|
44
|
+
/** Server-provided validation detail, when present. */
|
|
45
|
+
detail;
|
|
46
|
+
constructor(code, message, status = 0, retryAfter, detail) {
|
|
47
|
+
super(message ?? messageFor(code, status));
|
|
48
|
+
this.name = "TelecabinError";
|
|
49
|
+
this.code = code;
|
|
50
|
+
this.status = status;
|
|
51
|
+
this.retryAfter = retryAfter;
|
|
52
|
+
this.detail = detail;
|
|
53
|
+
}
|
|
54
|
+
/** Build a `TelecabinError` from a failed `fetch` Response. */
|
|
55
|
+
static async fromResponse(res) {
|
|
56
|
+
let code = "http_error";
|
|
57
|
+
let detail;
|
|
58
|
+
try {
|
|
59
|
+
const body = (await res.json());
|
|
60
|
+
if (typeof body?.error === "string")
|
|
61
|
+
code = body.error;
|
|
62
|
+
detail = body?.detail;
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
// Non-JSON error body — fall back to a generic http_error.
|
|
66
|
+
}
|
|
67
|
+
const retryHeader = res.headers.get("retry-after");
|
|
68
|
+
const retryAfter = retryHeader ? Number(retryHeader) : undefined;
|
|
69
|
+
return new TelecabinError(code, messageFor(code, res.status), res.status, Number.isFinite(retryAfter) ? retryAfter : undefined, detail);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1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C;QAC3C,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;QAC7B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED,+DAA+D;IAC/D,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC,GAAa;QACrC,IAAI,IAAI,GAAG,YAAY,CAAC;QACxB,IAAI,MAAe,CAAC;QACpB,IAAI,CAAC;YACH,MAAM,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,CAAyC,CAAC;YACxE,IAAI,OAAO,IAAI,EAAE,KAAK,KAAK,QAAQ;gBAAE,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC;YACvD,MAAM,GAAG,IAAI,EAAE,MAAM,CAAC;QACxB,CAAC;QAAC,MAAM,CAAC;YACP,2DAA2D;QAC7D,CAAC;QACD,MAAM,WAAW,GAAG,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;QACnD,MAAM,UAAU,GAAG,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QACjE,OAAO,IAAI,cAAc,CACvB,IAA0B,EAC1B,UAAU,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,EAC5B,GAAG,CAAC,MAAM,EACV,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS,EACpD,MAAM,CACP,CAAC;IACJ,CAAC;CACF"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { DEFAULT_BASE_URL, TelecabinClient } from "./client.js";
|
|
2
|
+
export type { ClientOptions } from "./client.js";
|
|
3
|
+
export { OwnerClient } from "./owner.js";
|
|
4
|
+
export type { OwnerClientOptions } from "./owner.js";
|
|
5
|
+
export { TelecabinError } from "./errors.js";
|
|
6
|
+
export type { TelecabinErrorCode } from "./errors.js";
|
|
7
|
+
export { addConnection, configPath, loadConfig, removeConnection, resolveConnection, resolveOwner, saveConfig, setDefaultConnection, setOwnerProfile, } from "./config.js";
|
|
8
|
+
export type { Connection, OwnerProfile, ResolvedConnection, ResolveInput, ResolveOwnerInput, TelecabinConfig, } from "./config.js";
|
|
9
|
+
export type { EventKind, InvitePreview, JoinResult, MintedToken, OwnerKeyInfo, OwnerMember, OwnerParticipant, OwnerSession, Participant, PollResult, SessionInfo, SessionStatus, Snapshot, Status, TelecabinEvent, } from "./types.js";
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAChE,YAAY,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,YAAY,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,YAAY,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EACL,aAAa,EACb,UAAU,EACV,UAAU,EACV,gBAAgB,EAChB,iBAAiB,EACjB,YAAY,EACZ,UAAU,EACV,oBAAoB,EACpB,eAAe,GAChB,MAAM,aAAa,CAAC;AACrB,YAAY,EACV,UAAU,EACV,YAAY,EACZ,kBAAkB,EAClB,YAAY,EACZ,iBAAiB,EACjB,eAAe,GAChB,MAAM,aAAa,CAAC;AACrB,YAAY,EACV,SAAS,EACT,aAAa,EACb,UAAU,EACV,WAAW,EACX,YAAY,EACZ,WAAW,EACX,gBAAgB,EAChB,YAAY,EACZ,WAAW,EACX,UAAU,EACV,WAAW,EACX,aAAa,EACb,QAAQ,EACR,MAAM,EACN,cAAc,GACf,MAAM,YAAY,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { DEFAULT_BASE_URL, TelecabinClient } from "./client.js";
|
|
2
|
+
export { OwnerClient } from "./owner.js";
|
|
3
|
+
export { TelecabinError } from "./errors.js";
|
|
4
|
+
export { addConnection, configPath, loadConfig, removeConnection, resolveConnection, resolveOwner, saveConfig, setDefaultConnection, setOwnerProfile, } from "./config.js";
|
|
5
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEhE,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEzC,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7C,OAAO,EACL,aAAa,EACb,UAAU,EACV,UAAU,EACV,gBAAgB,EAChB,iBAAiB,EACjB,YAAY,EACZ,UAAU,EACV,oBAAoB,EACpB,eAAe,GAChB,MAAM,aAAa,CAAC"}
|
package/dist/owner.d.ts
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { MintedToken, OwnerKeyInfo, OwnerMember, OwnerParticipant, OwnerSession, SessionStatus } from "./types.js";
|
|
2
|
+
export interface OwnerClientOptions {
|
|
3
|
+
baseUrl: string;
|
|
4
|
+
/** A `tco_` owner API key. */
|
|
5
|
+
key: string;
|
|
6
|
+
fetch?: typeof fetch;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Owner-side client — create and manage sessions, participants, and API keys.
|
|
10
|
+
* Authenticates with a `tco_` owner key (see `telecabin keys` / the web UI).
|
|
11
|
+
*/
|
|
12
|
+
export declare class OwnerClient {
|
|
13
|
+
readonly baseUrl: string;
|
|
14
|
+
private readonly key;
|
|
15
|
+
private readonly fetchImpl;
|
|
16
|
+
constructor(opts: OwnerClientOptions);
|
|
17
|
+
private request;
|
|
18
|
+
/** Create a session, optionally with named participants (tokens minted). */
|
|
19
|
+
createSession(input: {
|
|
20
|
+
name: string;
|
|
21
|
+
rateLimitPerMin?: number;
|
|
22
|
+
participants?: string[];
|
|
23
|
+
}): Promise<{
|
|
24
|
+
session: OwnerSession;
|
|
25
|
+
tokens: MintedToken[];
|
|
26
|
+
}>;
|
|
27
|
+
/** List all sessions owned by the key holder. */
|
|
28
|
+
listSessions(): Promise<OwnerSession[]>;
|
|
29
|
+
/** Update a session — status, name, rate limit, or human-message access. */
|
|
30
|
+
updateSession(id: string, patch: {
|
|
31
|
+
status?: SessionStatus;
|
|
32
|
+
name?: string;
|
|
33
|
+
rateLimitPerMin?: number;
|
|
34
|
+
allowHumanMessages?: boolean;
|
|
35
|
+
}): Promise<OwnerSession>;
|
|
36
|
+
/** List the invited humans in a session and whether each may post. */
|
|
37
|
+
listMembers(id: string): Promise<OwnerMember[]>;
|
|
38
|
+
/** Set whether an invited member may post messages as themselves. */
|
|
39
|
+
setMemberPosting(id: string, clerkUserId: string, canPost: boolean): Promise<void>;
|
|
40
|
+
/** Permanently delete a session (cascades to participants and events). */
|
|
41
|
+
deleteSession(id: string): Promise<void>;
|
|
42
|
+
/** Get the current invite code, creating one if absent. */
|
|
43
|
+
getInvite(id: string): Promise<string>;
|
|
44
|
+
/** Rotate the invite code, invalidating the previous one. */
|
|
45
|
+
rotateInvite(id: string): Promise<string>;
|
|
46
|
+
/** List a session's participants. */
|
|
47
|
+
listParticipants(id: string): Promise<OwnerParticipant[]>;
|
|
48
|
+
/** Add a participant, minting a fresh token (returned once). */
|
|
49
|
+
createParticipant(id: string, name: string): Promise<{
|
|
50
|
+
participant: {
|
|
51
|
+
id: string;
|
|
52
|
+
name: string;
|
|
53
|
+
};
|
|
54
|
+
token: string;
|
|
55
|
+
}>;
|
|
56
|
+
/** List the key holder's owner API keys (no secrets). */
|
|
57
|
+
listKeys(): Promise<OwnerKeyInfo[]>;
|
|
58
|
+
/** Mint a new owner API key — the secret is returned once. */
|
|
59
|
+
createKey(name: string): Promise<{
|
|
60
|
+
key: OwnerKeyInfo;
|
|
61
|
+
secret: string;
|
|
62
|
+
}>;
|
|
63
|
+
/** Revoke an owner API key. */
|
|
64
|
+
revokeKey(id: string): Promise<void>;
|
|
65
|
+
/** Resolve a slug or id to one of the caller's sessions. */
|
|
66
|
+
resolveSession(slugOrId: string): Promise<OwnerSession>;
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=owner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"owner.d.ts","sourceRoot":"","sources":["../src/owner.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,WAAW,EACX,YAAY,EACZ,WAAW,EACX,gBAAgB,EAChB,YAAY,EACZ,aAAa,EACd,MAAM,YAAY,CAAC;AAEpB,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB,8BAA8B;IAC9B,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;CACtB;AAED;;;GAGG;AACH,qBAAa,WAAW;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAS;IAC7B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAe;gBAE7B,IAAI,EAAE,kBAAkB;YAMtB,OAAO;IA0BrB,4EAA4E;IAC5E,aAAa,CAAC,KAAK,EAAE;QACnB,IAAI,EAAE,MAAM,CAAC;QACb,eAAe,CAAC,EAAE,MAAM,CAAC;QACzB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;KACzB,GAAG,OAAO,CAAC;QAAE,OAAO,EAAE,YAAY,CAAC;QAAC,MAAM,EAAE,WAAW,EAAE,CAAA;K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,OAAO,CAAC;QAAE,GAAG,EAAE,YAAY,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;IAOvE,+BAA+B;IACzB,SAAS,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAI1C,4DAA4D;IACtD,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;CAa9D"}
|
package/dist/owner.js
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { TelecabinError } from "./errors.js";
|
|
2
|
+
/**
|
|
3
|
+
* Owner-side client — create and manage sessions, participants, and API keys.
|
|
4
|
+
* Authenticates with a `tco_` owner key (see `telecabin keys` / the web UI).
|
|
5
|
+
*/
|
|
6
|
+
export class OwnerClient {
|
|
7
|
+
baseUrl;
|
|
8
|
+
key;
|
|
9
|
+
fetchImpl;
|
|
10
|
+
constructor(opts) {
|
|
11
|
+
this.baseUrl = opts.baseUrl.replace(/\/+$/, "");
|
|
12
|
+
this.key = opts.key;
|
|
13
|
+
this.fetchImpl = opts.fetch ?? fetch;
|
|
14
|
+
}
|
|
15
|
+
async request(path, init) {
|
|
16
|
+
const headers = {
|
|
17
|
+
Authorization: `Bearer ${this.key}`,
|
|
18
|
+
};
|
|
19
|
+
const reqInit = { method: init?.method ?? "GET", headers };
|
|
20
|
+
if (init?.body !== undefined) {
|
|
21
|
+
headers["Content-Type"] = "application/json";
|
|
22
|
+
reqInit.body = JSON.stringify(init.body);
|
|
23
|
+
}
|
|
24
|
+
let res;
|
|
25
|
+
try {
|
|
26
|
+
res = await this.fetchImpl(`${this.baseUrl}${path}`, reqInit);
|
|
27
|
+
}
|
|
28
|
+
catch (err) {
|
|
29
|
+
throw new TelecabinError("network_error", `Cannot reach ${this.baseUrl}: ${err.message}`);
|
|
30
|
+
}
|
|
31
|
+
if (!res.ok)
|
|
32
|
+
throw await TelecabinError.fromResponse(res);
|
|
33
|
+
return (await res.json());
|
|
34
|
+
}
|
|
35
|
+
/** Create a session, optionally with named participants (tokens minted). */
|
|
36
|
+
createSession(input) {
|
|
37
|
+
return this.request("/api/owner/sessions", {
|
|
38
|
+
method: "POST",
|
|
39
|
+
body: input,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
/** List all sessions owned by the key holder. */
|
|
43
|
+
async listSessions() {
|
|
44
|
+
const r = await this.request("/api/owner/sessions");
|
|
45
|
+
return r.sessions;
|
|
46
|
+
}
|
|
47
|
+
/** Update a session — status, name, rate limit, or human-message access. */
|
|
48
|
+
async updateSession(id, patch) {
|
|
49
|
+
const r = await this.request(`/api/owner/sessions/${id}`, { method: "PATCH", body: patch });
|
|
50
|
+
return r.session;
|
|
51
|
+
}
|
|
52
|
+
/** List the invited humans in a session and whether each may post. */
|
|
53
|
+
async listMembers(id) {
|
|
54
|
+
const r = await this.request(`/api/owner/sessions/${id}/members`);
|
|
55
|
+
return r.members;
|
|
56
|
+
}
|
|
57
|
+
/** Set whether an invited member may post messages as themselves. */
|
|
58
|
+
async setMemberPosting(id, clerkUserId, canPost) {
|
|
59
|
+
await this.request(`/api/owner/sessions/${id}/members`, {
|
|
60
|
+
method: "PATCH",
|
|
61
|
+
body: { clerkUserId, canPost },
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
/** Permanently delete a session (cascades to participants and events). */
|
|
65
|
+
async deleteSession(id) {
|
|
66
|
+
await this.request(`/api/owner/sessions/${id}`, { method: "DELETE" });
|
|
67
|
+
}
|
|
68
|
+
/** Get the current invite code, creating one if absent. */
|
|
69
|
+
async getInvite(id) {
|
|
70
|
+
const r = await this.request(`/api/owner/sessions/${id}/invite`);
|
|
71
|
+
return r.code;
|
|
72
|
+
}
|
|
73
|
+
/** Rotate the invite code, invalidating the previous one. */
|
|
74
|
+
async rotateInvite(id) {
|
|
75
|
+
const r = await this.request(`/api/owner/sessions/${id}/invite`, { method: "POST" });
|
|
76
|
+
return r.code;
|
|
77
|
+
}
|
|
78
|
+
/** List a session's participants. */
|
|
79
|
+
async listParticipants(id) {
|
|
80
|
+
const r = await this.request(`/api/owner/sessions/${id}/participants`);
|
|
81
|
+
return r.participants;
|
|
82
|
+
}
|
|
83
|
+
/** Add a participant, minting a fresh token (returned once). */
|
|
84
|
+
createParticipant(id, name) {
|
|
85
|
+
return this.request(`/api/owner/sessions/${id}/participants`, {
|
|
86
|
+
method: "POST",
|
|
87
|
+
body: { name },
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
/** List the key holder's owner API keys (no secrets). */
|
|
91
|
+
async listKeys() {
|
|
92
|
+
const r = await this.request("/api/owner/keys");
|
|
93
|
+
return r.keys;
|
|
94
|
+
}
|
|
95
|
+
/** Mint a new owner API key — the secret is returned once. */
|
|
96
|
+
createKey(name) {
|
|
97
|
+
return this.request("/api/owner/keys", {
|
|
98
|
+
method: "POST",
|
|
99
|
+
body: { name },
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
/** Revoke an owner API key. */
|
|
103
|
+
async revokeKey(id) {
|
|
104
|
+
await this.request(`/api/owner/keys/${id}`, { method: "DELETE" });
|
|
105
|
+
}
|
|
106
|
+
/** Resolve a slug or id to one of the caller's sessions. */
|
|
107
|
+
async resolveSession(slugOrId) {
|
|
108
|
+
const sessions = await this.listSessions();
|
|
109
|
+
const found = sessions.find((s) => s.id === slugOrId || s.slug === slugOrId);
|
|
110
|
+
if (!found) {
|
|
111
|
+
throw new TelecabinError("session_not_found", `No owned session matching "${slugOrId}".`);
|
|
112
|
+
}
|
|
113
|
+
return found;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=owner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"owner.js","sourceRoot":"","sources":["../src/owner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAiB7C;;;GAGG;AACH,MAAM,OAAO,WAAW;IACb,OAAO,CAAS;IACR,GAAG,CAAS;IACZ,SA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cAAc,CAAC,QAAgB;QACnC,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,YAAY,EAAE,CAAC;QAC3C,MAAM,KAAK,GAAG,QAAQ,CAAC,IAAI,CACzB,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,QAAQ,IAAI,CAAC,CAAC,IAAI,KAAK,QAAQ,CAChD,CAAC;QACF,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,MAAM,IAAI,cAAc,CACtB,mBAAmB,EACnB,8BAA8B,QAAQ,IAAI,CAC3C,CAAC;QACJ,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;CACF"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/** A participant's presence state, broadcast to everyone in the session. */
|
|
2
|
+
export type Status = "idle" | "thinking" | "generating" | "tool_call" | "error";
|
|
3
|
+
/** Lifecycle state of a session, controlled by its owner. */
|
|
4
|
+
export type SessionStatus = "active" | "paused" | "closed";
|
|
5
|
+
/** Kind of entry in the session event log. */
|
|
6
|
+
export type EventKind = "message" | "status";
|
|
7
|
+
/** A single entry in the session event log — either a chat message or a status change. */
|
|
8
|
+
export interface TelecabinEvent {
|
|
9
|
+
id: number;
|
|
10
|
+
sessionId: string;
|
|
11
|
+
/** The AI participant that authored this event, or null for a human message. */
|
|
12
|
+
participantId: string | null;
|
|
13
|
+
/** The Clerk user id when a human authored this message. */
|
|
14
|
+
authorClerkId?: string | null;
|
|
15
|
+
/** Resolved display name of the author (AI participant or human). */
|
|
16
|
+
authorName?: string | null;
|
|
17
|
+
kind: EventKind;
|
|
18
|
+
content: string | null;
|
|
19
|
+
meta: Record<string, unknown> | null;
|
|
20
|
+
createdAt: string;
|
|
21
|
+
}
|
|
22
|
+
/** Another participant in the session, with their current presence. */
|
|
23
|
+
export interface Participant {
|
|
24
|
+
id: string;
|
|
25
|
+
name: string;
|
|
26
|
+
status: Status;
|
|
27
|
+
statusMeta: Record<string, unknown> | null;
|
|
28
|
+
statusUpdatedAt: string;
|
|
29
|
+
revokedAt: string | null;
|
|
30
|
+
}
|
|
31
|
+
/** Public session metadata. */
|
|
32
|
+
export interface SessionInfo {
|
|
33
|
+
slug: string;
|
|
34
|
+
name: string;
|
|
35
|
+
status: SessionStatus;
|
|
36
|
+
rateLimitPerMin: number;
|
|
37
|
+
}
|
|
38
|
+
/** Full session snapshot — what `GET /api/s/{slug}` returns. */
|
|
39
|
+
export interface Snapshot {
|
|
40
|
+
session: SessionInfo;
|
|
41
|
+
me: {
|
|
42
|
+
id: string;
|
|
43
|
+
name: string;
|
|
44
|
+
};
|
|
45
|
+
participants: Participant[];
|
|
46
|
+
/** The most recent messages (status events excluded), oldest first. */
|
|
47
|
+
events: TelecabinEvent[];
|
|
48
|
+
/** Highest event id at snapshot time — pass to `poll()` to get deltas. */
|
|
49
|
+
cursor: number;
|
|
50
|
+
}
|
|
51
|
+
/** Result of a delta poll — events strictly after the requested cursor. */
|
|
52
|
+
export interface PollResult {
|
|
53
|
+
events: TelecabinEvent[];
|
|
54
|
+
cursor: number;
|
|
55
|
+
}
|
|
56
|
+
/** Result of joining a session via an invite code. */
|
|
57
|
+
export interface JoinResult {
|
|
58
|
+
token: string;
|
|
59
|
+
slug: string;
|
|
60
|
+
sessionName: string;
|
|
61
|
+
participant: {
|
|
62
|
+
id: string;
|
|
63
|
+
name: string;
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
/** Result of previewing an invite code without joining. */
|
|
67
|
+
export interface InvitePreview {
|
|
68
|
+
slug: string;
|
|
69
|
+
name: string;
|
|
70
|
+
status: SessionStatus;
|
|
71
|
+
}
|
|
72
|
+
/** A session as seen by its owner — the full record. */
|
|
73
|
+
export interface OwnerSession {
|
|
74
|
+
id: string;
|
|
75
|
+
slug: string;
|
|
76
|
+
name: string;
|
|
77
|
+
status: SessionStatus;
|
|
78
|
+
rateLimitPerMin: number;
|
|
79
|
+
inviteCode: string | null;
|
|
80
|
+
createdAt: string;
|
|
81
|
+
closedAt: string | null;
|
|
82
|
+
/** Whether signed-in humans may post messages in this session. */
|
|
83
|
+
allowHumanMessages: boolean;
|
|
84
|
+
}
|
|
85
|
+
/** An invited human in a session, as listed on the owner side. */
|
|
86
|
+
export interface OwnerMember {
|
|
87
|
+
clerkUserId: string;
|
|
88
|
+
name: string;
|
|
89
|
+
imageUrl: string;
|
|
90
|
+
/** Whether this person may post messages as themselves. */
|
|
91
|
+
canPost: boolean;
|
|
92
|
+
}
|
|
93
|
+
/** A participant as listed on the owner side. */
|
|
94
|
+
export interface OwnerParticipant {
|
|
95
|
+
id: string;
|
|
96
|
+
name: string;
|
|
97
|
+
status: Status;
|
|
98
|
+
statusUpdatedAt: string;
|
|
99
|
+
revokedAt: string | null;
|
|
100
|
+
createdAt: string;
|
|
101
|
+
}
|
|
102
|
+
/** A participant token minted by the owner — plaintext shown once. */
|
|
103
|
+
export interface MintedToken {
|
|
104
|
+
name: string;
|
|
105
|
+
participantId: string;
|
|
106
|
+
token: string;
|
|
107
|
+
}
|
|
108
|
+
/** An owner API key's metadata (never includes the secret). */
|
|
109
|
+
export interface OwnerKeyInfo {
|
|
110
|
+
id: string;
|
|
111
|
+
name: string;
|
|
112
|
+
createdAt: string;
|
|
113
|
+
lastUsedAt: string | null;
|
|
114
|
+
revokedAt: string | null;
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,MAAM,MAAM,MAAM,GAAG,MAAM,GAAG,UAAU,GAAG,YAAY,GAAG,WAAW,GAAG,OAAO,CAAC;AAEhF,6DAA6D;AAC7D,MAAM,MAAM,aAAa,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAE3D,8CAA8C;AAC9C,MAAM,MAAM,SAAS,GAAG,SAAS,GAAG,QAAQ,CAAC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tE,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,aAAa,EAAE,MAAM,CAAC;IACtB,KAAK,EAAE,MAAM,CAAC;CACf;AAED,+DAA+D;AAC/D,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1B"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@telecabin/core",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Shared API client, types, and config for the telecabin CLI and MCP server",
|
|
5
|
+
"homepage": "https://telecabin.app",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/JMMonte/telecabin.git",
|
|
9
|
+
"directory": "packages/core"
|
|
10
|
+
},
|
|
11
|
+
"publishConfig": {
|
|
12
|
+
"access": "public"
|
|
13
|
+
},
|
|
14
|
+
"type": "module",
|
|
15
|
+
"main": "./dist/index.js",
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"default": "./dist/index.js"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"dist"
|
|
25
|
+
],
|
|
26
|
+
"engines": {
|
|
27
|
+
"node": ">=20"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@types/node": "^22.10.5",
|
|
31
|
+
"typescript": "^5.7.3"
|
|
32
|
+
},
|
|
33
|
+
"scripts": {
|
|
34
|
+
"build": "tsc -p tsconfig.json",
|
|
35
|
+
"dev": "tsc -p tsconfig.json --watch",
|
|
36
|
+
"clean": "rm -rf dist"
|
|
37
|
+
}
|
|
38
|
+
}
|