@dsh-teamwork/dsh-teamwork 0.3.0 → 0.5.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/README.md +2 -0
- package/lib/index.js +59 -20
- package/lib/index.js.map +1 -1
- package/lib/panel.js +3 -0
- package/lib/panel.js.map +1 -1
- package/lib/relay.js +211 -0
- package/lib/relay.js.map +1 -0
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/panel.d.ts +33 -0
- package/lib/types/panel.d.ts.map +1 -1
- package/lib/types/relay.d.ts +99 -0
- package/lib/types/relay.d.ts.map +1 -0
- package/lib/web/client.js +1760 -2
- package/package.json +2 -1
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { RelayStatus } from './panel.js';
|
|
3
|
+
export type { RelayStatus };
|
|
4
|
+
/** The relay's close codes this side acts on; any other close reconnects. */
|
|
5
|
+
export declare const RELAY_CLOSE: {
|
|
6
|
+
readonly badHello: 4400;
|
|
7
|
+
readonly unauthorized: 4401;
|
|
8
|
+
readonly replaced: 4409;
|
|
9
|
+
};
|
|
10
|
+
/** What the relay pushes unasked: a phone redeemed this computer's code, or a pairing ended. */
|
|
11
|
+
export type RelayEvent = {
|
|
12
|
+
t: 'paired';
|
|
13
|
+
} | {
|
|
14
|
+
t: 'revoked';
|
|
15
|
+
pairingId: string;
|
|
16
|
+
};
|
|
17
|
+
/** A request the relay answers once welcomed (its `src/protocol.ts`, `PluginRequestSchema`). */
|
|
18
|
+
export type RelayRequest = {
|
|
19
|
+
t: 'offer';
|
|
20
|
+
} | {
|
|
21
|
+
t: 'pairings';
|
|
22
|
+
} | {
|
|
23
|
+
t: 'decide';
|
|
24
|
+
pairingId: string;
|
|
25
|
+
accept: boolean;
|
|
26
|
+
} | {
|
|
27
|
+
t: 'revoke';
|
|
28
|
+
pairingId: string;
|
|
29
|
+
};
|
|
30
|
+
/** A pairing as the relay lists it (`src/pairing.ts`, `PairingView`). */
|
|
31
|
+
export declare const pairingSchema: z.ZodObject<{
|
|
32
|
+
id: z.ZodString;
|
|
33
|
+
deviceName: z.ZodString;
|
|
34
|
+
status: z.ZodEnum<{
|
|
35
|
+
pending: "pending";
|
|
36
|
+
confirmed: "confirmed";
|
|
37
|
+
}>;
|
|
38
|
+
createdAt: z.ZodString;
|
|
39
|
+
lastUsedAt: z.ZodNullable<z.ZodString>;
|
|
40
|
+
}, z.core.$strip>;
|
|
41
|
+
export declare const offerSchema: z.ZodObject<{
|
|
42
|
+
code: z.ZodString;
|
|
43
|
+
expiresAt: z.ZodString;
|
|
44
|
+
}, z.core.$strip>;
|
|
45
|
+
/** The relay answered a request with one of its error codes (`invalid_code`, `not_found`, `internal`). */
|
|
46
|
+
export declare class RelayError extends Error {
|
|
47
|
+
readonly code: string;
|
|
48
|
+
constructor(code: string);
|
|
49
|
+
}
|
|
50
|
+
export interface RelayLinkOptions {
|
|
51
|
+
/** The server the member signed in to, read on every attempt. */
|
|
52
|
+
endpoint: () => string;
|
|
53
|
+
/** The member's Bearer, or undefined while signed out. */
|
|
54
|
+
token: () => string | undefined;
|
|
55
|
+
/** Where this computer's stable relay id is kept. */
|
|
56
|
+
clientIdPath: string;
|
|
57
|
+
name?: string;
|
|
58
|
+
dshVersion?: string;
|
|
59
|
+
request?: typeof fetch;
|
|
60
|
+
/** The WebSocket class to dial with: Node's global by default. */
|
|
61
|
+
WebSocket?: typeof globalThis.WebSocket;
|
|
62
|
+
onStatus?: (status: RelayStatus) => void;
|
|
63
|
+
onEvent?: (event: RelayEvent) => void;
|
|
64
|
+
/** Longest wait between reconnection attempts. */
|
|
65
|
+
maxBackoffMs?: number;
|
|
66
|
+
/** How long to wait before asking a server without a relay again. */
|
|
67
|
+
rediscoverMs?: number;
|
|
68
|
+
}
|
|
69
|
+
export declare class RelayLink {
|
|
70
|
+
private readonly options;
|
|
71
|
+
private state;
|
|
72
|
+
private socket?;
|
|
73
|
+
private timer?;
|
|
74
|
+
private attempt;
|
|
75
|
+
/** Bumped by every refresh and stop, so a late callback of an older run changes nothing. */
|
|
76
|
+
private run;
|
|
77
|
+
private hostId?;
|
|
78
|
+
private requests;
|
|
79
|
+
constructor(options: RelayLinkOptions);
|
|
80
|
+
get status(): RelayStatus;
|
|
81
|
+
/** The relay's id for this computer, once welcomed. */
|
|
82
|
+
get host(): string | undefined;
|
|
83
|
+
/** Start over: after sign-in, sign-out or a change of server. */
|
|
84
|
+
refresh(): void;
|
|
85
|
+
stop(): void;
|
|
86
|
+
/** Ask the relay something, once connected; rejects when it is not, or does not answer in time. */
|
|
87
|
+
request(request: RelayRequest): Promise<unknown>;
|
|
88
|
+
private failRequests;
|
|
89
|
+
private halt;
|
|
90
|
+
private set;
|
|
91
|
+
private retry;
|
|
92
|
+
private backoff;
|
|
93
|
+
private connect;
|
|
94
|
+
/** A random id generated once per computer, so the relay keeps one host across restarts. */
|
|
95
|
+
private clientId;
|
|
96
|
+
}
|
|
97
|
+
/** `<cache>.host.json`, beside the cache, like the other per-computer files. */
|
|
98
|
+
export declare const relayClientIdPath: (cachePath: string) => string;
|
|
99
|
+
//# sourceMappingURL=relay.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"relay.d.ts","sourceRoot":"","sources":["../../src/relay.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C,YAAY,EAAE,WAAW,EAAE,CAAC;AAE5B,6EAA6E;AAC7E,eAAO,MAAM,WAAW;;;;CAAkE,CAAC;AAO3F,gGAAgG;AAChG,MAAM,MAAM,UAAU,GAAG;IAAE,CAAC,EAAE,QAAQ,CAAA;CAAE,GAAG;IAAE,CAAC,EAAE,SAAS,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAAC;AAG/E,gGAAgG;AAChG,MAAM,MAAM,YAAY,GACpB;IAAE,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