@linxin666/dsh-remote-bridge 0.4.13 → 0.4.14
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.i18n.yaml +2 -2
- package/README.md +13 -8
- package/README.zh.md +13 -8
- package/lib/client.js +112 -90
- package/lib/client.js.map +1 -1
- package/lib/index.js +873 -65
- package/lib/types/client/PairPanel.d.ts +7 -0
- package/lib/types/client/locales.d.ts +13 -10
- package/lib/types/core/connection.d.ts +41 -0
- package/lib/types/core/devices.d.ts +60 -7
- package/lib/types/core/protocol.d.ts +22 -0
- package/lib/types/core/push.d.ts +19 -1
- package/lib/types/host/relay-bridge-connector.d.ts +19 -0
- package/lib/types/host/relay-connector.d.ts +4 -0
- package/lib/types/host/relay-control.d.ts +77 -6
- package/lib/types/host/relay-registry.d.ts +12 -3
- package/lib/types/host/relay-secondary.d.ts +209 -0
- package/lib/types/host/relay.d.ts +1 -1
- package/lib/types/host/routes.d.ts +5 -0
- package/lib/types/index.d.ts +65 -3
- package/package.json +1 -1
- package/src/client/PairPanel.tsx +21 -0
- package/src/client/locales.ts +19 -15
- package/src/client/panel.module.css +32 -0
- package/src/core/connection.ts +110 -0
- package/src/core/devices.ts +141 -17
- package/src/core/protocol.ts +24 -0
- package/src/core/push.ts +20 -1
- package/src/host/relay-bridge-connector.ts +68 -2
- package/src/host/relay-connector.ts +9 -2
- package/src/host/relay-control.ts +98 -7
- package/src/host/relay-registry.ts +17 -5
- package/src/host/relay-secondary.ts +478 -0
- package/src/host/relay.ts +1 -1
- package/src/host/routes.ts +10 -0
- package/src/index.ts +270 -35
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
import type { PropsLocale } from '@deepseek-ai/dsh-client-ui-slots';
|
|
2
|
+
/**
|
|
3
|
+
* Where a reader of the beta build can reach the people running it. The URL is
|
|
4
|
+
* code, not copy: the dictionaries carry the sentence, this constant carries the
|
|
5
|
+
* destination, so a translation cannot retarget the link and a check can assert
|
|
6
|
+
* the real one.
|
|
7
|
+
*/
|
|
8
|
+
export declare const COMMUNITY_INVITE_URL = "https://discord.gg/nBy28kjun";
|
|
2
9
|
/** What the panel is currently showing. */
|
|
3
10
|
export type PairPanelState =
|
|
4
11
|
/** A read is in flight. */
|
|
@@ -3,10 +3,12 @@
|
|
|
3
3
|
* the header of an interactive card (§35.11).
|
|
4
4
|
*
|
|
5
5
|
* The panel has one job — put the live one-shot code in front of the operator as
|
|
6
|
-
* a QR symbol — so its copy carries
|
|
7
|
-
*
|
|
8
|
-
* the
|
|
9
|
-
*
|
|
6
|
+
* a QR symbol — so its copy carries what to do with the symbol, how long it
|
|
7
|
+
* lives, which address the phone will actually dial, why the code is single-use,
|
|
8
|
+
* and that the app is still in testing: the reader is told what they are joining
|
|
9
|
+
* and where to ask about it. No key states how the host finds its public
|
|
10
|
+
* address, and no key names the wire protocol: both are implementation facts the
|
|
11
|
+
* reader cannot act on.
|
|
10
12
|
*
|
|
11
13
|
* The card's keys say only what the transcript row can act on: whether the page
|
|
12
14
|
* is still waiting for the operator, that it is over, that this desktop renders
|
|
@@ -15,17 +17,18 @@
|
|
|
15
17
|
*/
|
|
16
18
|
/** Simplified Chinese dictionary (the key-set source of truth). */
|
|
17
19
|
export declare const zh: {
|
|
18
|
-
readonly 'entry.label': "
|
|
19
|
-
readonly title: "
|
|
20
|
-
readonly subtitle: "
|
|
20
|
+
readonly 'entry.label': "配对 iPhone";
|
|
21
|
+
readonly title: "iOS App 配对";
|
|
22
|
+
readonly subtitle: "用 iOS App(内测)扫描二维码,把 iPhone 连到这台电脑上。配对码只在本机显示。";
|
|
21
23
|
readonly 'state.reading': "正在取配对码…";
|
|
22
24
|
readonly 'pair.qrLabel': "配对二维码";
|
|
23
25
|
readonly 'pair.countdown': "剩余 {s} 秒";
|
|
24
26
|
readonly 'pair.expired': "配对码已过期";
|
|
25
27
|
readonly 'pair.refresh': "重新取码";
|
|
26
|
-
readonly 'pair.usedHint': "
|
|
27
|
-
readonly 'origin.located': "
|
|
28
|
-
readonly 'origin.missing': "
|
|
28
|
+
readonly 'pair.usedHint': "配对码一次性有效:iPhone 一开始配对就作废,重新取码也会作废上一张。";
|
|
29
|
+
readonly 'origin.located': "iPhone 将连到 {origin}";
|
|
30
|
+
readonly 'origin.missing': "没有找到公网地址:先在 App 里把连接地址填成你的公网中继,再扫码。本页的 {host} 只有本机能连。";
|
|
31
|
+
readonly 'community.invite': "iOS App 还在内测,欢迎来 Discord 交流";
|
|
29
32
|
readonly 'forbidden.title': "这个页面不是从本机打开的";
|
|
30
33
|
readonly 'forbidden.body': "配对码只能在本机 Web UI 上取。请在本机浏览器打开 http://127.0.0.1:<端口> 后重试。";
|
|
31
34
|
readonly 'failed.title': "取配对码失败";
|
|
@@ -84,6 +84,33 @@ export interface BridgeTransport {
|
|
|
84
84
|
*/
|
|
85
85
|
frameDeflate?(declared: boolean): void;
|
|
86
86
|
}
|
|
87
|
+
/**
|
|
88
|
+
* 第二会合点在协议面上的那一半:一条公告与一次收帧。
|
|
89
|
+
*
|
|
90
|
+
* 只有配了第二会合点的宿主才提供这个面,而它存在与否就是 `relay.tier.v1` 这个
|
|
91
|
+
* 能力名与 `relay.grant` 这个方法存在与否——没有它,握手与应答与今天逐字相同。
|
|
92
|
+
* 宿主侧的动作(写名册、去第二会合点申领)全在插件半区,core 里只留这两处接线,
|
|
93
|
+
* 所以一个不认识的宿主不会因为这里多了一层而改变任何一帧。
|
|
94
|
+
*/
|
|
95
|
+
export interface RelayTierFace {
|
|
96
|
+
/**
|
|
97
|
+
* 这次握手要在 `hello.r.relay` 里公告的会合点,或 undefined(此刻没有可公告的)。
|
|
98
|
+
*
|
|
99
|
+
* 公告的含义是「这台宿主此刻确实持有一份中继承认的、按 6 小时周期刷新的租约」,
|
|
100
|
+
* 而不是「它曾经申到过一次」:公告出去的是「拨这个地址」,而一个没有有效租约的
|
|
101
|
+
* 地址背后没有人服务。还没申到、降级被拒、grant 过期、主动释放,四种情况都回
|
|
102
|
+
* undefined,于是一条连接的下一个世代自己退回市场边缘,不需要服务端推送任何东西。
|
|
103
|
+
* @returns `wss://<id><suffix>`,或 undefined。
|
|
104
|
+
*/
|
|
105
|
+
origin(): string | undefined;
|
|
106
|
+
/**
|
|
107
|
+
* 一条新授权已经落进名册行:第二会合点要立刻重新申领一次。
|
|
108
|
+
*
|
|
109
|
+
* 调用发生在名册写完之后,所以插件半区读到的就是这条授权。它是**触发**而不是
|
|
110
|
+
* 等待:`relay.grant` 的应答不等那一次网络往返,申领失败由半区自己的退避收着。
|
|
111
|
+
*/
|
|
112
|
+
grantLanded(): void;
|
|
113
|
+
}
|
|
87
114
|
export interface BridgeConnectionOptions {
|
|
88
115
|
readonly gateway: BridgeGateway;
|
|
89
116
|
readonly pairing: PairingService;
|
|
@@ -171,6 +198,11 @@ export interface BridgeConnectionOptions {
|
|
|
171
198
|
* read the host's own answer.
|
|
172
199
|
*/
|
|
173
200
|
readonly turnEndQuiet?: TurnEndQuietGate;
|
|
201
|
+
/**
|
|
202
|
+
* 第二会合点(`relay.tier.v1`)。缺省就是没有第二会合点:`hello` 不带
|
|
203
|
+
* `relay` 键、能力表里没有那个名字、`relay.grant` 仍是 `unknown-method`。
|
|
204
|
+
*/
|
|
205
|
+
readonly relay?: RelayTierFace;
|
|
174
206
|
/**
|
|
175
207
|
* Called after a registration changed the device table.
|
|
176
208
|
*
|
|
@@ -181,6 +213,15 @@ export interface BridgeConnectionOptions {
|
|
|
181
213
|
* `push.register` into a failure.
|
|
182
214
|
*/
|
|
183
215
|
readonly onPushRegistered?: () => void;
|
|
216
|
+
/**
|
|
217
|
+
* Called after `pair.finish` admits a device into the roster.
|
|
218
|
+
*
|
|
219
|
+
* A machine that started with no paired devices defers claiming its relay
|
|
220
|
+
* lease until a remote device is actually paired (or a pairing code is
|
|
221
|
+
* requested); guarded at the call site so background relay work never fails
|
|
222
|
+
* the pairing response.
|
|
223
|
+
*/
|
|
224
|
+
readonly onDeviceEnrolled?: () => void;
|
|
184
225
|
}
|
|
185
226
|
/** A device the connection proved itself to be, resolved from the upgrade request. */
|
|
186
227
|
export interface ConnectionAuth {
|
|
@@ -19,14 +19,15 @@ export declare const DEVICE_ID_BYTES = 12;
|
|
|
19
19
|
*
|
|
20
20
|
* 1 carried the six identity fields only; 2 adds the optional `push` block per
|
|
21
21
|
* row (§28); 3 adds the optional `relayToken` inside that block, the credential the
|
|
22
|
-
* hosted relay signs a delivery for instead of a local Apple key
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
22
|
+
* hosted relay signs a delivery for instead of a local Apple key; 4 adds the
|
|
23
|
+
* optional `relay` block beside it, the tier grant the phone handed over and when
|
|
24
|
+
* this bridge received it. Every step is additive, so an older file reads as-is:
|
|
25
|
+
* no row loses a field, every paired phone stays paired, and the file is rewritten
|
|
26
|
+
* as the current version the next time anything is written. The reader therefore
|
|
27
|
+
* accepts any version whose row table validates rather than quarantining a file it
|
|
28
|
+
* merely does not recognise — a downgrade must never un-pair every phone.
|
|
28
29
|
*/
|
|
29
|
-
export declare const ROSTER_VERSION =
|
|
30
|
+
export declare const ROSTER_VERSION = 4;
|
|
30
31
|
/** The APNs environments a device may register for. */
|
|
31
32
|
export type PushEnvironment = 'sandbox' | 'production';
|
|
32
33
|
/** One Live Activity push token, with the session the card belongs to. */
|
|
@@ -72,6 +73,26 @@ export interface PushRegistration {
|
|
|
72
73
|
readonly relayToken?: string;
|
|
73
74
|
readonly registeredAt: number;
|
|
74
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* One device's relay tier grant (schema 4).
|
|
78
|
+
*
|
|
79
|
+
* The App obtains it from the account service and hands it over through
|
|
80
|
+
* `relay.grant`. This bridge never mints, parses or reissues it: it keeps the text
|
|
81
|
+
* and presents it in its next claim to the second meeting point, which decides the
|
|
82
|
+
* entitlement out of band and answers the host with a lease or a refusal. Nothing
|
|
83
|
+
* about the account crosses the wire back — the host learns "admitted" or "not",
|
|
84
|
+
* never who the phone is.
|
|
85
|
+
*
|
|
86
|
+
* It is a fact about the phone that gave it, so it lives in that phone's row and
|
|
87
|
+
* disappears with the row when the phone is revoked; it never becomes a second
|
|
88
|
+
* identity of the bridge's own.
|
|
89
|
+
*/
|
|
90
|
+
export interface RelayGrant {
|
|
91
|
+
/** The grant text, exactly as the account service issued it. */
|
|
92
|
+
readonly grant: string;
|
|
93
|
+
/** When this bridge received it, in epoch seconds. */
|
|
94
|
+
readonly receivedAt: number;
|
|
95
|
+
}
|
|
75
96
|
/** One device a notification can be addressed to. */
|
|
76
97
|
export interface PushTargetView {
|
|
77
98
|
readonly deviceId: string;
|
|
@@ -92,6 +113,14 @@ export interface DeviceRecord {
|
|
|
92
113
|
* every phone that predates the channel.
|
|
93
114
|
*/
|
|
94
115
|
readonly push?: PushRegistration;
|
|
116
|
+
/**
|
|
117
|
+
* The device's relay tier grant, absent until it calls `relay.grant`.
|
|
118
|
+
*
|
|
119
|
+
* A row without it is a phone whose host may still claim the second meeting
|
|
120
|
+
* point — a bridged lease needs no grant at the market edge — it just cannot be
|
|
121
|
+
* admitted to a tier that requires one.
|
|
122
|
+
*/
|
|
123
|
+
readonly relay?: RelayGrant;
|
|
95
124
|
}
|
|
96
125
|
/** What one successful enrollment hands back to the caller exactly once. */
|
|
97
126
|
export interface EnrollmentResult {
|
|
@@ -152,6 +181,30 @@ export declare class DeviceRoster {
|
|
|
152
181
|
* @returns false when no such device is paired.
|
|
153
182
|
*/
|
|
154
183
|
registerPush(deviceId: string, registration: PushRegistration): Promise<boolean>;
|
|
184
|
+
/**
|
|
185
|
+
* Record the relay grant one device just handed over (schema 4).
|
|
186
|
+
*
|
|
187
|
+
* A grant the phone resends replaces the one on the row: the account service
|
|
188
|
+
* reissues them periodically, and the newest text is the one the second meeting
|
|
189
|
+
* point will verify against the current plan. Nothing else on the row moves, so a
|
|
190
|
+
* grant that arrives between two reconnects cannot disturb a push registration.
|
|
191
|
+
* @param deviceId - the device that sent `relay.grant`.
|
|
192
|
+
* @param grant - the grant text as the account service issued it.
|
|
193
|
+
* @returns false when no such device is paired.
|
|
194
|
+
*/
|
|
195
|
+
setRelayGrant(deviceId: string, grant: string): Promise<boolean>;
|
|
196
|
+
/**
|
|
197
|
+
* @returns the relay grant this bridge claims with, or undefined when no row
|
|
198
|
+
* holds one.
|
|
199
|
+
*
|
|
200
|
+
* The newest one wins, because one host holds one lease at the second meeting
|
|
201
|
+
* point and the phone that most recently handed a grant over is the one whose
|
|
202
|
+
* subscription is being claimed. A pairing with several phones of mixed tiers is
|
|
203
|
+
* then the accepted asymmetry the design names: the host is admitted while at
|
|
204
|
+
* least one paired phone holds a tier that is, and the free-tier phone simply
|
|
205
|
+
* keeps using the market edge.
|
|
206
|
+
*/
|
|
207
|
+
relayGrant(): RelayGrant | undefined;
|
|
155
208
|
/**
|
|
156
209
|
* Forget one Live Activity token the phone no longer holds.
|
|
157
210
|
*
|
|
@@ -47,6 +47,14 @@ export declare const METHOD_USAGE_BALANCE = "usage.balance";
|
|
|
47
47
|
export declare const METHOD_USAGE_STATS = "usage.stats";
|
|
48
48
|
export declare const METHOD_UI_EVENT = "ui.event";
|
|
49
49
|
export declare const METHOD_UI_LIST = "ui.list";
|
|
50
|
+
/**
|
|
51
|
+
* 一条配对连接把手机从账号服务换到的中继授权交给宿主。
|
|
52
|
+
*
|
|
53
|
+
* 它是这条通道唯一的写动作:授权落进那台设备自己的名册行,随后宿主拿它去第二
|
|
54
|
+
* 会合点申领租约。宿主不认识账号——它只会看到「准了」或「不准」,绝不会从这一帧
|
|
55
|
+
* 里读出用户是谁。只在配了第二会合点的宿主上是这个方法(见 {@link CAP_RELAY_TIER})。
|
|
56
|
+
*/
|
|
57
|
+
export declare const METHOD_RELAY_GRANT = "relay.grant";
|
|
50
58
|
/** Server-pushed topics of protocol v1. */
|
|
51
59
|
export declare const TOPIC_SESSION_DELTA = "session.delta";
|
|
52
60
|
export declare const TOPIC_APPROVAL_REQUEST = "approval.request";
|
|
@@ -262,6 +270,20 @@ export declare const CAP_UI = "ui.v1";
|
|
|
262
270
|
* `ui.request` 说 `settled` 时结束),而不是按一次它信不过的应答清卡。
|
|
263
271
|
*/
|
|
264
272
|
export declare const CAP_UI_LIST = "ui.list.v1";
|
|
273
|
+
/**
|
|
274
|
+
* 宿主配了第二会合点时,在 `hello` 的 `capabilities` 里公告的能力名。
|
|
275
|
+
*
|
|
276
|
+
* 它是这条通道的全部门槛,而且门槛落在宿主这一侧:一个配了第二会合点的宿主才
|
|
277
|
+
* 公告这个名字、才收 {@link METHOD_RELAY_GRANT},客户端读到它之后才把授权发过来。
|
|
278
|
+
* 不配第二会合点的宿主——也就是缺省配置的每一台——公告表里没有这个名字,
|
|
279
|
+
* `relay.grant` 对它仍是 `unknown-method`,名册里也不会因此多出一个块:缺省
|
|
280
|
+
* 宿主的握手与名册与这条通道出现之前逐字相同。
|
|
281
|
+
*
|
|
282
|
+
* 正因为它是**条件**公告,{@link MINOR} 不随它抬格:minor 描述的是这个协议本身,
|
|
283
|
+
* 而缺省宿主在线路上读不到任何新东西(设计冻结在 21)。客户端因此按名字判断而不是
|
|
284
|
+
* 按 minor 判断:读不到这个名字就什么都不发。
|
|
285
|
+
*/
|
|
286
|
+
export declare const CAP_RELAY_TIER = "relay.tier.v1";
|
|
265
287
|
/**
|
|
266
288
|
* Capability a client declares in `hello`'s `cap` array to be answered with
|
|
267
289
|
* byte-level increments instead of the whole roster or the whole board.
|
package/lib/types/core/push.d.ts
CHANGED
|
@@ -46,6 +46,15 @@ export declare const PUSH_GLOBAL_PER_MINUTE = 30;
|
|
|
46
46
|
export declare const PUSH_WORKSPACE_LIMIT = 512;
|
|
47
47
|
/** The only deep-link form this channel emits. */
|
|
48
48
|
export declare const PUSH_DEEP_LINK_PREFIX = "whale://session/";
|
|
49
|
+
/**
|
|
50
|
+
* The one category a delivery may name (§28.4).
|
|
51
|
+
*
|
|
52
|
+
* A banner draws a button only where a category it knows is named, so this is the
|
|
53
|
+
* identifier the client registered statically for the two approval answers. It is
|
|
54
|
+
* the client's name rather than this bridge's: the bridge writes it verbatim and
|
|
55
|
+
* holds no second opinion about what a button says.
|
|
56
|
+
*/
|
|
57
|
+
export declare const PUSH_APPROVAL_CATEGORY = "dev.dsh.Whale.category.approval";
|
|
49
58
|
/** One device a notification can be addressed to. */
|
|
50
59
|
export interface PushAddress {
|
|
51
60
|
readonly deviceToken: string;
|
|
@@ -69,6 +78,13 @@ export interface PushNotification {
|
|
|
69
78
|
readonly body: string;
|
|
70
79
|
};
|
|
71
80
|
readonly sound: 'default';
|
|
81
|
+
/**
|
|
82
|
+
* The client's registered category, named only by an approval.
|
|
83
|
+
*
|
|
84
|
+
* Absent for every other event rather than empty: an absent key is a banner
|
|
85
|
+
* with no buttons, and an empty one would be a second way to say it.
|
|
86
|
+
*/
|
|
87
|
+
readonly category?: string;
|
|
72
88
|
};
|
|
73
89
|
/** Workspace short name; absent when this bridge cannot resolve one. */
|
|
74
90
|
readonly w?: string;
|
|
@@ -167,7 +183,9 @@ export interface PushNotifierOptions {
|
|
|
167
183
|
*
|
|
168
184
|
* Pure, and exported so the shape can be asserted without a sender: the keys
|
|
169
185
|
* are the contract, and the absence of any body text is the property that
|
|
170
|
-
* matters most.
|
|
186
|
+
* matters most. One key is conditional — an approval names the category the
|
|
187
|
+
* client registered, because naming it is the only thing that makes a banner
|
|
188
|
+
* draw a button, and every other event omits it so a banner stays buttonless.
|
|
171
189
|
* @param event - what happened.
|
|
172
190
|
* @param sessionId - the session it happened to.
|
|
173
191
|
* @param labels - the name and workspace short name, when the bridge holds them.
|
|
@@ -30,6 +30,16 @@
|
|
|
30
30
|
*
|
|
31
31
|
* Frames mirror `market/worker/src/relay-bridge.js`: control frames are JSON
|
|
32
32
|
* text, payload frames are `[kind:u8][streamId:u32be][payload]`.
|
|
33
|
+
*
|
|
34
|
+
* Flow control runs one way only, object to connector. A pause closes the
|
|
35
|
+
* object's window on one stream: this half stops sending that stream's payload
|
|
36
|
+
* frames and stops reading the upstream (a response body, a WebSocket socket),
|
|
37
|
+
* so the backlog waits in the kernel instead of in this process. A resume opens
|
|
38
|
+
* it again. A stream being abandoned arrives as close -- the frame this contract
|
|
39
|
+
* already used for a phone cancel -- and cancel is accepted as the same thing,
|
|
40
|
+
* because that is the name the frozen contract gives it. An object too old to
|
|
41
|
+
* send any of them leaves this half exactly as it was, and a frame this half has
|
|
42
|
+
* never heard of is ignored rather than answered.
|
|
33
43
|
*/
|
|
34
44
|
import type { RelayBridgeStart } from './relay-connector.ts';
|
|
35
45
|
/** The upgrade carries the lease secret here, never in the URL. */
|
|
@@ -151,7 +161,11 @@ export declare class RelayBridgeConnector {
|
|
|
151
161
|
private stateValue;
|
|
152
162
|
private attempts;
|
|
153
163
|
private disposed;
|
|
164
|
+
/** HTTP streams still uploading: the request the object's frames feed. */
|
|
154
165
|
private readonly requests;
|
|
166
|
+
/** HTTP streams whose head already arrived: the upstream response body a
|
|
167
|
+
* pause holds back and a stream being abandoned destroys. */
|
|
168
|
+
private readonly responses;
|
|
155
169
|
private readonly peers;
|
|
156
170
|
private readonly options;
|
|
157
171
|
constructor(options: RelayBridgeConnectorOptions);
|
|
@@ -173,6 +187,11 @@ export declare class RelayBridgeConnector {
|
|
|
173
187
|
private write;
|
|
174
188
|
private onBridgeFrame;
|
|
175
189
|
private onControl;
|
|
190
|
+
/** Close the object's window on one stream: a paused response body emits no
|
|
191
|
+
* more data events and a paused socket leaves its bytes in the kernel. */
|
|
192
|
+
private pauseStream;
|
|
193
|
+
/** Reopen that window. */
|
|
194
|
+
private resumeStream;
|
|
176
195
|
/**
|
|
177
196
|
* Answer one bridged stream with 404 without dialing anything: the refusal is
|
|
178
197
|
* complete here, so a non-whitelisted path costs the upstream nothing.
|
|
@@ -94,6 +94,10 @@ export interface RelayConnectorPairOptions {
|
|
|
94
94
|
stopBridge?: () => void;
|
|
95
95
|
/** Release the lease (the offline action, never a retire). */
|
|
96
96
|
release?: (identity: RelayIdentity) => Promise<void>;
|
|
97
|
+
/** The control-plane base the two lease endpoints hang off. The defaults
|
|
98
|
+
* below derive `claim` and `release` from it, so a host that configures
|
|
99
|
+
* nothing dials exactly the shipped market URLs. */
|
|
100
|
+
controlUrl?: string;
|
|
97
101
|
/** Observe the lease state (logs only — the card still renders the registry). */
|
|
98
102
|
onState?: (state: RelayPairState) => void;
|
|
99
103
|
baseDelayMs?: number;
|
|
@@ -11,9 +11,30 @@
|
|
|
11
11
|
* keeps the origin the registry gave it.
|
|
12
12
|
*/
|
|
13
13
|
import type { RelayIdentity } from './relay-registry.ts';
|
|
14
|
-
/**
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
/**
|
|
15
|
+
* The control-plane base every lease and registry endpoint hangs off: the
|
|
16
|
+
* market apex, never a relay hostname.
|
|
17
|
+
*
|
|
18
|
+
* This constant is the one home of the shipped default. A self-hosted meeting
|
|
19
|
+
* point sets the `relayControlUrl` config field, and its `claim`, `release`,
|
|
20
|
+
* `register` and `unregister` paths all move with that one base.
|
|
21
|
+
*/
|
|
22
|
+
export declare const RELAY_CONTROL_URL = "https://dsh-market.com/api/relay";
|
|
23
|
+
/** The paths one control-plane base serves. */
|
|
24
|
+
export type RelayControlEndpoint = 'claim' | 'release' | 'register' | 'unregister';
|
|
25
|
+
/**
|
|
26
|
+
* One endpoint of a control-plane base.
|
|
27
|
+
*
|
|
28
|
+
* The base arrives from a hand-written profile YAML, so its trailing slashes
|
|
29
|
+
* are trimmed instead of doubling the separator this adds.
|
|
30
|
+
* @param endpoint - the path below the base.
|
|
31
|
+
* @param controlUrl - the base; undefined means the shipped market apex.
|
|
32
|
+
* @returns the absolute endpoint URL.
|
|
33
|
+
*/
|
|
34
|
+
export declare function relayControlEndpointOf(endpoint: RelayControlEndpoint, controlUrl?: string): string;
|
|
35
|
+
/** The default lease endpoints (market apex, never a relay hostname). */
|
|
36
|
+
export declare const RELAY_CLAIM_URL: string;
|
|
37
|
+
export declare const RELAY_RELEASE_URL: string;
|
|
17
38
|
/** Which connector serves the relay hostname. `bridge` is the Durable Object
|
|
18
39
|
* meeting point (`relay-bridge-connector.ts`), `named` the instance's own cloud
|
|
19
40
|
* tunnel, `quick` today's Worker proxy path. */
|
|
@@ -63,10 +84,56 @@ export interface RelayClaimRequest {
|
|
|
63
84
|
port: number;
|
|
64
85
|
/** The plugin version, for the adoption readout of the migration. */
|
|
65
86
|
pluginVersion?: string;
|
|
87
|
+
/**
|
|
88
|
+
* The account service's relay grant, when this bridge holds one.
|
|
89
|
+
*
|
|
90
|
+
* Absent is the claim a host makes when no phone has handed a grant over yet,
|
|
91
|
+
* and the key is then left out of the body entirely: the second meeting point
|
|
92
|
+
* grades "no grant" as `tier-required`, which is a different answer from "this
|
|
93
|
+
* grant does not verify" (`grant-invalid`), and `null` would be read as the
|
|
94
|
+
* latter.
|
|
95
|
+
*/
|
|
96
|
+
grant?: string;
|
|
66
97
|
}
|
|
67
|
-
/**
|
|
98
|
+
/**
|
|
99
|
+
* The capped backoff a failed claim retries on. The cap is the whole Cloudflare
|
|
100
|
+
* rate-limit window: a spent account request budget answers `retryAfterMs:
|
|
101
|
+
* 300000` because that budget is counted over 300 seconds, so a shorter cap
|
|
102
|
+
* only brings the instance back inside the same spent window.
|
|
103
|
+
*/
|
|
68
104
|
export declare const CLAIM_RETRY_BASE_MS = 5000;
|
|
69
|
-
export declare const CLAIM_RETRY_MAX_MS =
|
|
105
|
+
export declare const CLAIM_RETRY_MAX_MS = 300000;
|
|
106
|
+
/**
|
|
107
|
+
* The control plane's refusal code for a claim whose grant does not reach the
|
|
108
|
+
* tier this meeting point admits. It is not an authentication answer — the id
|
|
109
|
+
* and secret verified — so it is graded apart from `auth-failed`.
|
|
110
|
+
*/
|
|
111
|
+
export declare const RELAY_TIER_REQUIRED = "tier-required";
|
|
112
|
+
/**
|
|
113
|
+
* The control plane's refusal code for a grant it will not vouch for: a bad
|
|
114
|
+
* signature, the wrong scope, or — the case that is not an error at all — a grant
|
|
115
|
+
* that has simply reached the end of its 30 days.
|
|
116
|
+
*
|
|
117
|
+
* It shares {@link RELAY_TIER_REQUIRED}'s branch because it is the same kind of
|
|
118
|
+
* fact: the id and the secret are fine, the admission this host was given is not,
|
|
119
|
+
* and the repair is a fresh grant (which the phone hands over) or another
|
|
120
|
+
* evaluation after the plan or the clock moved. `auth-failed` stays the one
|
|
121
|
+
* terminal 403.
|
|
122
|
+
*/
|
|
123
|
+
export declare const RELAY_GRANT_INVALID = "grant-invalid";
|
|
124
|
+
/**
|
|
125
|
+
* How long a claim refused for its admission (`tier-required` or
|
|
126
|
+
* `grant-invalid`) waits before the next attempt: six hours.
|
|
127
|
+
*
|
|
128
|
+
* Deliberately outside {@link CLAIM_RETRY_MAX_MS}. That cap exists because a
|
|
129
|
+
* spent rate-limit budget is counted over one 300-second window, so retrying
|
|
130
|
+
* faster lands inside the same spent window. An admission refusal is not a
|
|
131
|
+
* window: it is a fact about the plan or about the grant's own 30-day lifetime.
|
|
132
|
+
* Six hours is the interval the lease refresh itself runs on, so a downgrade is
|
|
133
|
+
* noticed at the next refresh, while an upgrade needs no wait at all: the phone
|
|
134
|
+
* hands the new grant over (`relay.tier.v1`) and that re-claims immediately.
|
|
135
|
+
*/
|
|
136
|
+
export declare const CLAIM_TIER_REQUIRED_DELAY_MS = 21600000;
|
|
70
137
|
/** Build the claim body (an absent value is omitted, never sent as null). */
|
|
71
138
|
export declare function relayClaimBody(request: RelayClaimRequest): string;
|
|
72
139
|
/** One lease read back from an accepted claim, or undefined for a bad shape. */
|
|
@@ -109,7 +176,11 @@ export interface RelayClaimRetry {
|
|
|
109
176
|
* Grade one failed claim into a retry decision.
|
|
110
177
|
*
|
|
111
178
|
* `403 auth-failed` is terminal: the id belongs to another secret and no
|
|
112
|
-
* number of retries can take it back.
|
|
179
|
+
* number of retries can take it back. The two admission 403s —
|
|
180
|
+
* `tier-required` and `grant-invalid` — are the ones that are not: the id and
|
|
181
|
+
* the secret verified and only the admission is missing, so both retry on the
|
|
182
|
+
* same fixed wait ({@link CLAIM_TIER_REQUIRED_DELAY_MS}) that the cap below
|
|
183
|
+
* deliberately does not clamp. Everything else retries on a capped
|
|
113
184
|
* exponential backoff, with the control plane's own `retryAfterMs` (a 502
|
|
114
185
|
* names it) raising the floor so a retry cannot land inside a known outage.
|
|
115
186
|
* @param outcome - the refused attempt.
|
|
@@ -15,12 +15,15 @@
|
|
|
15
15
|
* purpose, so an existing profile keeps the identity it already paired with.
|
|
16
16
|
*/
|
|
17
17
|
/** The market worker's registration endpoints (dsh-market.com edge API). */
|
|
18
|
-
export declare const RELAY_REGISTER_URL
|
|
19
|
-
export declare const RELAY_UNREGISTER_URL
|
|
18
|
+
export declare const RELAY_REGISTER_URL: string;
|
|
19
|
+
export declare const RELAY_UNREGISTER_URL: string;
|
|
20
20
|
/**
|
|
21
21
|
* The public origin template: one stable single-label subdomain per
|
|
22
22
|
* registration id. Single label on purpose — Universal SSL covers exactly
|
|
23
23
|
* one subdomain level, so a two-level hostname would get no certificate.
|
|
24
|
+
*
|
|
25
|
+
* This constant is the one home of the shipped default suffix; a self-hosted
|
|
26
|
+
* meeting point sets `relayPublicSuffix` and the hostname template follows.
|
|
24
27
|
*/
|
|
25
28
|
export declare const RELAY_BASE_SUFFIX = ".dsh-market.com";
|
|
26
29
|
export declare const RELAY_ID_RE: RegExp;
|
|
@@ -77,8 +80,11 @@ export declare function unregisterRelay(identity: RelayIdentity, endpoint?: stri
|
|
|
77
80
|
/**
|
|
78
81
|
* The stable relay base for one identity — the origin the QR and the phone
|
|
79
82
|
* bookmark use while (or after) the registration is accepted.
|
|
83
|
+
* @param identity - the registration identity.
|
|
84
|
+
* @param publicSuffix - the configured suffix; undefined means the shipped one.
|
|
85
|
+
* @returns the origin, with no path of its own.
|
|
80
86
|
*/
|
|
81
|
-
export declare function relayBaseOf(identity: RelayIdentity): string;
|
|
87
|
+
export declare function relayBaseOf(identity: RelayIdentity, publicSuffix?: string): string;
|
|
82
88
|
/**
|
|
83
89
|
* Registration loop with capped exponential backoff. Re-registration happens
|
|
84
90
|
* on every tunnel start (the quick URL can change after a crash-restart);
|
|
@@ -96,6 +102,9 @@ export declare class RelayRegistrar {
|
|
|
96
102
|
fetchFn?: typeof fetch;
|
|
97
103
|
registerUrl?: string;
|
|
98
104
|
unregisterUrl?: string;
|
|
105
|
+
/** The public suffix the hostname template uses (default
|
|
106
|
+
* {@link RELAY_BASE_SUFFIX}). */
|
|
107
|
+
publicSuffix?: string;
|
|
99
108
|
baseDelayMs?: number;
|
|
100
109
|
maxDelayMs?: number;
|
|
101
110
|
timerFn?: (fn: () => void, ms: number) => NodeJS.Timeout;
|