@celljs/ta-relay 4.14.0 → 4.15.1
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/esm/common/page-language.d.ts +14 -0
- package/esm/common/page-language.js +27 -0
- package/esm/common/relay-team.d.ts +33 -8
- package/esm/common/relay-team.js +55 -7
- package/esm/guest/guest-i18n.d.ts +6 -1
- package/esm/guest/guest-i18n.js +98 -5
- package/esm/guest/guest.js +1 -1
- package/esm/join/join-i18n.d.ts +13 -1
- package/esm/join/join-i18n.js +133 -3
- package/esm/join/join.js +79 -10
- package/esm/viewer/viewer-i18n.d.ts +6 -1
- package/esm/viewer/viewer-i18n.js +107 -3
- package/lib/common/page-language.d.ts +15 -0
- package/lib/common/page-language.js +31 -0
- package/lib/common/relay-team.d.ts +33 -8
- package/lib/common/relay-team.js +55 -7
- package/lib/guest/guest-i18n.d.ts +6 -1
- package/lib/guest/guest-i18n.js +99 -6
- package/lib/guest/guest.js +1 -1
- package/lib/join/join-i18n.d.ts +13 -1
- package/lib/join/join-i18n.js +134 -4
- package/lib/join/join.js +79 -10
- package/lib/viewer/viewer-i18n.d.ts +6 -1
- package/lib/viewer/viewer-i18n.js +108 -4
- package/package.json +2 -2
- package/viewer/join.html +4 -3
- package/viewer/page.html +9 -9
- package/viewer/room.html +10 -10
package/esm/join/join.js
CHANGED
|
@@ -81,10 +81,19 @@ class JoinPage {
|
|
|
81
81
|
void this.open();
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
|
-
/** Asks the Ta how one says who they are, then the form. */
|
|
84
|
+
/** Asks the Ta how one says who they are, then the form; a Ta that cannot be reached says so, to try again. */
|
|
85
85
|
async open(error) {
|
|
86
|
+
var _a;
|
|
86
87
|
this.frame(el('div', 'spin'));
|
|
87
|
-
|
|
88
|
+
try {
|
|
89
|
+
this.ways = await this.connection().ways('web');
|
|
90
|
+
}
|
|
91
|
+
catch (failure) {
|
|
92
|
+
(_a = this.joining) === null || _a === void 0 ? void 0 : _a.close();
|
|
93
|
+
this.joining = undefined;
|
|
94
|
+
this.frame(...this.heading(), el('p', 'error', this.reason(failure)), button('primary', t('retry'), () => void this.open(error)));
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
88
97
|
this.form(error);
|
|
89
98
|
}
|
|
90
99
|
connection() {
|
|
@@ -109,12 +118,17 @@ class JoinPage {
|
|
|
109
118
|
/** Signing in for the Ta app that opened this page: straight to the provider, the Ta giving where. */
|
|
110
119
|
async handOff({ provider, handoff }) {
|
|
111
120
|
var _a;
|
|
121
|
+
var _b;
|
|
112
122
|
this.frame(el('div', 'spin'), el('h1', 'room-name', t('signingIn')));
|
|
113
123
|
try {
|
|
114
|
-
const
|
|
115
|
-
|
|
124
|
+
const started = await this.connection().signIn(provider, handoff);
|
|
125
|
+
if (started.device) {
|
|
126
|
+
await this.typeCode(started, { id: provider, name: provider === 'github' ? 'GitHub' : provider }, '', handoff);
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
write(SIGN_IN_KEY, { state: started.state, href: RelayTeamLinkUtil.format(this.link), name: '', handoff });
|
|
116
130
|
(_a = this.joining) === null || _a === void 0 ? void 0 : _a.close();
|
|
117
|
-
location.replace(url);
|
|
131
|
+
location.replace((_b = started.url) !== null && _b !== void 0 ? _b : '');
|
|
118
132
|
}
|
|
119
133
|
catch (failure) {
|
|
120
134
|
this.frame(...this.heading(), el('p', 'error', this.reason(failure)));
|
|
@@ -137,13 +151,67 @@ class JoinPage {
|
|
|
137
151
|
this.frame(...this.heading(), el('p', 'error', this.reason(failure)));
|
|
138
152
|
}
|
|
139
153
|
}
|
|
140
|
-
/** To the provider, which sends the browser back to this page with a code. */
|
|
154
|
+
/** To the provider, which sends the browser back to this page with a code; or a code to type at it (GitHub's). */
|
|
141
155
|
async signIn(provider, name) {
|
|
142
156
|
var _a;
|
|
143
|
-
|
|
144
|
-
|
|
157
|
+
var _b;
|
|
158
|
+
const started = await this.connection().signIn(provider.id);
|
|
159
|
+
if (started.device) {
|
|
160
|
+
await this.typeCode(started, provider, name);
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
write(SIGN_IN_KEY, { state: started.state, href: location.href, name });
|
|
145
164
|
(_a = this.joining) === null || _a === void 0 ? void 0 : _a.close();
|
|
146
|
-
location.assign(url);
|
|
165
|
+
location.assign((_b = started.url) !== null && _b !== void 0 ? _b : '');
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Signing in by a code (docs/design/ta-team.md 17.4): the code, copied as the provider's page opens, typed there; the Ta
|
|
169
|
+
* asks the provider whether it was, and keeps the account under the state of the sign-in (or the app's handoff).
|
|
170
|
+
*/
|
|
171
|
+
async typeCode(started, provider, name, handoff) {
|
|
172
|
+
const device = started.device;
|
|
173
|
+
const joining = this.connection();
|
|
174
|
+
const named = JoinI18n.provider(provider);
|
|
175
|
+
const copied = el('p', 'small', '');
|
|
176
|
+
const open = button('primary', t('copyOpen', { provider: named }), () => {
|
|
177
|
+
var _a;
|
|
178
|
+
void ((_a = navigator.clipboard) === null || _a === void 0 ? void 0 : _a.writeText(device.code).then(() => (copied.textContent = t('copied'))).catch(() => undefined));
|
|
179
|
+
window.open(device.uri, '_blank', 'noopener');
|
|
180
|
+
});
|
|
181
|
+
const back = button('plain', t('back'), () => {
|
|
182
|
+
joining.close();
|
|
183
|
+
this.joining = undefined;
|
|
184
|
+
void this.open();
|
|
185
|
+
});
|
|
186
|
+
this.frame(...this.heading(), el('p', 'hint', t('typeCode', { provider: named })), el('div', 'device-code', device.code), open, copied, el('p', 'small', t('typeCodeHint', { provider: named })), ...(handoff ? [] : [back]));
|
|
187
|
+
try {
|
|
188
|
+
const account = await joining.typed(started.state, device.expiresAt);
|
|
189
|
+
if (this.joining !== joining) {
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
if (!account) {
|
|
193
|
+
await this.open(t('codeGone'));
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
if (handoff) {
|
|
197
|
+
joining.close();
|
|
198
|
+
this.frame(el('div', 'done-mark', '✓'), el('h1', 'room-name', t('handedOff', { who: account.name || account.id })), el('p', 'hint', t('backToApp', { owner: this.owner })));
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
this.frame(el('div', 'spin'), el('h1', 'room-name', t('checking')));
|
|
202
|
+
await this.ask(name, { handoff: started.state });
|
|
203
|
+
}
|
|
204
|
+
catch (failure) {
|
|
205
|
+
if (this.joining !== joining) {
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
if (handoff) {
|
|
209
|
+
this.frame(...this.heading(), el('p', 'error', this.reason(failure)));
|
|
210
|
+
}
|
|
211
|
+
else {
|
|
212
|
+
this.form(this.reason(failure));
|
|
213
|
+
}
|
|
214
|
+
}
|
|
147
215
|
}
|
|
148
216
|
/** This browser is let into that Ta already: Ta's page keeps it among its computers. */
|
|
149
217
|
joined() {
|
|
@@ -220,7 +288,7 @@ class JoinPage {
|
|
|
220
288
|
const one = button(required ? 'primary' : 'plain', t('signInWith', { provider: JoinI18n.provider(provider) }), () => {
|
|
221
289
|
busy(true);
|
|
222
290
|
one.textContent = t('signingIn');
|
|
223
|
-
this.signIn(provider
|
|
291
|
+
this.signIn(provider, field.value.trim()).catch(failure => this.form(this.reason(failure)));
|
|
224
292
|
});
|
|
225
293
|
return one;
|
|
226
294
|
});
|
|
@@ -316,6 +384,7 @@ style.textContent = `${GUEST_STYLE}
|
|
|
316
384
|
.accounts{display:flex;flex-direction:column;gap:8px;width:100%}
|
|
317
385
|
.accounts .plain{width:100%;padding:11px 14px;border:1px solid var(--line);border-radius:12px;color:var(--fg);font-weight:500}
|
|
318
386
|
.or{margin:2px 0;color:var(--muted);font-size:12.5px;text-align:center}
|
|
387
|
+
.device-code{align-self:center;margin:4px auto;padding:10px 18px;border:1px dashed var(--line);border-radius:12px;font:600 26px/1.2 ui-monospace,SFMono-Regular,Menlo,monospace;letter-spacing:.12em;user-select:all}
|
|
319
388
|
.done-mark{align-self:center;margin:0 auto;width:44px;height:44px;border-radius:50%;display:grid;place-items:center;background:var(--soft);color:var(--accent,#16a34a);font-size:22px;font-weight:600}
|
|
320
389
|
`;
|
|
321
390
|
document.head.append(style);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type PageLanguage } from '../common/page-language.js';
|
|
1
2
|
declare const zh: {
|
|
2
3
|
title: string;
|
|
3
4
|
loading: string;
|
|
@@ -48,8 +49,12 @@ declare const zh: {
|
|
|
48
49
|
use: string;
|
|
49
50
|
};
|
|
50
51
|
export type ViewerText = keyof typeof zh;
|
|
52
|
+
/** The words of each language of Ta, checked by scripts/check-i18n.ts. */
|
|
53
|
+
export declare const VIEWER_WORDS: Readonly<Record<PageLanguage, typeof zh>>;
|
|
51
54
|
export declare namespace ViewerI18n {
|
|
52
|
-
const
|
|
55
|
+
const language: PageLanguage;
|
|
56
|
+
/** Chinese or Japanese: Latin among the words has a space on each side. */
|
|
57
|
+
const cjk: boolean;
|
|
53
58
|
function t(id: ViewerText, values?: Record<string, string | number>): string;
|
|
54
59
|
function date(at: number): string;
|
|
55
60
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { pageLanguage } from '../common/page-language.js';
|
|
1
2
|
const zh = {
|
|
2
3
|
title: 'Ta 分享',
|
|
3
4
|
loading: '正在打开…',
|
|
@@ -47,6 +48,55 @@ const zh = {
|
|
|
47
48
|
script: '运行脚本',
|
|
48
49
|
use: '使用 {name}',
|
|
49
50
|
};
|
|
51
|
+
const zhTw = {
|
|
52
|
+
title: 'Ta 分享',
|
|
53
|
+
loading: '正在開啟…',
|
|
54
|
+
conversation: '對話',
|
|
55
|
+
file: '檔案',
|
|
56
|
+
sharedAt: '分享於 {date}',
|
|
57
|
+
messages: '{n} 條訊息',
|
|
58
|
+
passwordTitle: '這個分享需要口令',
|
|
59
|
+
passwordHint: '口令不在連結裡,請向分享的人要。',
|
|
60
|
+
password: '口令',
|
|
61
|
+
open: '開啟',
|
|
62
|
+
wrong: '口令不對,再試一次。',
|
|
63
|
+
busy: '口令錯得太多了,請過幾分鐘再試。',
|
|
64
|
+
gone: '這個連結已經失效:分享已停止或已過期。',
|
|
65
|
+
offline: '分享的人的電腦現在沒有執行 Ta,請稍後再試。',
|
|
66
|
+
self: '這是僅自己可見的分享,只有分享的人能在自己的 Ta 裡開啟。',
|
|
67
|
+
people: '這條連結只給指定的 Ta 好友:請在你自己的 Ta 應用裡掃碼或貼上開啟。',
|
|
68
|
+
invalid: '這不是一個完整的 Ta 分享連結,請檢查是否複製完整。',
|
|
69
|
+
timeout: '等了太久還沒收到,請稍後再試。',
|
|
70
|
+
large: '內容太大,打不開。',
|
|
71
|
+
failed: '打不開這個分享。',
|
|
72
|
+
you: '你',
|
|
73
|
+
ta: 'Ta',
|
|
74
|
+
outputsOmitted: '分享時沒有附上工具的輸出。',
|
|
75
|
+
imagesOmitted: '分享時去掉了 {n} 張圖片。',
|
|
76
|
+
redacted: '分享時隱去了 {n} 處疑似金鑰。',
|
|
77
|
+
image: '[圖片]',
|
|
78
|
+
download: '下載 {name}',
|
|
79
|
+
footer: '在 Ta 應用裡掃碼或貼上這個連結,可以把它匯入為你自己的對話接著聊。',
|
|
80
|
+
agentKind: '智慧體名片',
|
|
81
|
+
agentHint: '在 Ta 裡掃碼或貼上這個連結,就能把它加為你的智慧體;加進來時,它會先看看你的專案,把職責調整得貼合你那邊的情況。',
|
|
82
|
+
copy: '複製連結',
|
|
83
|
+
copied: '已複製',
|
|
84
|
+
failedCall: '失敗',
|
|
85
|
+
output: '輸出',
|
|
86
|
+
error: '出錯了',
|
|
87
|
+
secure: '端到端加密:中繼看不到內容',
|
|
88
|
+
run: '執行',
|
|
89
|
+
read: '讀取',
|
|
90
|
+
write: '寫入',
|
|
91
|
+
edit: '編輯',
|
|
92
|
+
search: '搜尋',
|
|
93
|
+
find: '查詢',
|
|
94
|
+
list: '列出',
|
|
95
|
+
fetch: '開啟網頁',
|
|
96
|
+
webSearch: '搜尋網頁',
|
|
97
|
+
script: '執行指令碼',
|
|
98
|
+
use: '使用 {name}',
|
|
99
|
+
};
|
|
50
100
|
const en = {
|
|
51
101
|
title: 'Shared from Ta',
|
|
52
102
|
loading: 'Opening…',
|
|
@@ -96,15 +146,69 @@ const en = {
|
|
|
96
146
|
script: 'Run a script',
|
|
97
147
|
use: 'Use {name}',
|
|
98
148
|
};
|
|
149
|
+
const ja = {
|
|
150
|
+
title: 'Ta から共有',
|
|
151
|
+
loading: '開いています…',
|
|
152
|
+
conversation: '会話',
|
|
153
|
+
file: 'ファイル',
|
|
154
|
+
sharedAt: '{date} に共有',
|
|
155
|
+
messages: '{n} 件のメッセージ',
|
|
156
|
+
passwordTitle: 'この共有にはパスワードが必要です',
|
|
157
|
+
passwordHint: 'パスワードはリンクに含まれていません。共有した人に尋ねてください。',
|
|
158
|
+
password: 'パスワード',
|
|
159
|
+
open: '開く',
|
|
160
|
+
wrong: 'パスワードが違います。もう一度試してください。',
|
|
161
|
+
busy: 'パスワード入力を間違えすぎました。数分後にもう一度試してください。',
|
|
162
|
+
gone: 'このリンクはもう有効ではありません。共有が停止されたか期限切れです。',
|
|
163
|
+
offline: '共有したコンピュータは現在 Ta を実行していません。後で再度試してください。',
|
|
164
|
+
self: 'この共有は共有者だけが自分の Ta で開くことができます。',
|
|
165
|
+
people: 'このリンクは指定された Ta 友だちのみが対象です。自分の Ta アプリでスキャンするかペーストして開いてください。',
|
|
166
|
+
invalid: 'これは Ta の完全なリンクではありません。全体がコピーされているか確認してください。',
|
|
167
|
+
timeout: '到着に時間がかかりすぎました。後で再度試してください。',
|
|
168
|
+
large: 'サイズが大きすぎて開くことができません。',
|
|
169
|
+
failed: 'この共有は開くことができません。',
|
|
170
|
+
you: 'あなた',
|
|
171
|
+
ta: 'Ta',
|
|
172
|
+
outputsOmitted: 'ツールの出力は共有されていません。',
|
|
173
|
+
imagesOmitted: '共有時に {n} 枚の画像が除外されました。',
|
|
174
|
+
redacted: 'シークレットのように見えた {n} 個の項目が削除されました。',
|
|
175
|
+
image: '[画像]',
|
|
176
|
+
download: '{name} をダウンロード',
|
|
177
|
+
footer: 'Ta アプリでこのリンクをスキャンするかペーストして、自分の会話としてインポートして続けることができます。',
|
|
178
|
+
agentKind: 'エージェントのカード',
|
|
179
|
+
agentHint: 'Ta でこのリンクをスキャンするかペーストしてあなたのエージェントとして追加できます。参加すると、まずあなたのプロジェクトを確認して、その状況に合わせて役割を調整します。',
|
|
180
|
+
copy: 'リンクをコピー',
|
|
181
|
+
copied: 'コピーされました',
|
|
182
|
+
failedCall: '失敗',
|
|
183
|
+
output: '出力',
|
|
184
|
+
error: 'エラー',
|
|
185
|
+
secure: 'エンドツーエンド暗号化。リレーは読むことができません',
|
|
186
|
+
run: '実行',
|
|
187
|
+
read: '読取',
|
|
188
|
+
write: '書込',
|
|
189
|
+
edit: '編集',
|
|
190
|
+
search: '検索',
|
|
191
|
+
find: '検索',
|
|
192
|
+
list: 'リスト',
|
|
193
|
+
fetch: '開く',
|
|
194
|
+
webSearch: 'ウェブを検索',
|
|
195
|
+
script: 'スクリプトを実行',
|
|
196
|
+
use: '{name} を使用',
|
|
197
|
+
};
|
|
198
|
+
/** The words of each language of Ta, checked by scripts/check-i18n.ts. */
|
|
199
|
+
export const VIEWER_WORDS = { 'zh-CN': zh, 'zh-TW': zhTw, 'en-US': en, 'ja-JP': ja };
|
|
99
200
|
export var ViewerI18n;
|
|
100
201
|
(function (ViewerI18n) {
|
|
101
|
-
ViewerI18n.
|
|
202
|
+
ViewerI18n.language = pageLanguage();
|
|
203
|
+
/** Chinese or Japanese: Latin among the words has a space on each side. */
|
|
204
|
+
ViewerI18n.cjk = ViewerI18n.language !== 'en-US';
|
|
205
|
+
const words = VIEWER_WORDS[ViewerI18n.language];
|
|
102
206
|
function t(id, values = {}) {
|
|
103
|
-
return
|
|
207
|
+
return words[id].replace(/\{(\w+)\}/g, (_, name) => { var _a; return String((_a = values[name]) !== null && _a !== void 0 ? _a : ''); });
|
|
104
208
|
}
|
|
105
209
|
ViewerI18n.t = t;
|
|
106
210
|
function date(at) {
|
|
107
|
-
return new Date(at).toLocaleString(ViewerI18n.
|
|
211
|
+
return new Date(at).toLocaleString(ViewerI18n.language, {
|
|
108
212
|
year: 'numeric',
|
|
109
213
|
month: 'short',
|
|
110
214
|
day: 'numeric',
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** A language of the pages of the relay, the languages of Ta. */
|
|
2
|
+
export type PageLanguage = 'zh-CN' | 'zh-TW' | 'en-US' | 'ja-JP';
|
|
3
|
+
/**
|
|
4
|
+
* The language of a page, from the browser's (`navigator.language`): Traditional Chinese for Taiwan, Hong Kong, Macau
|
|
5
|
+
* and `Hant`, Simplified for other Chinese, Japanese, else English; as TaLanguageUtil.of of ta-protocol, which the
|
|
6
|
+
* relay does without.
|
|
7
|
+
*/
|
|
8
|
+
export declare function pageLanguage(tag?: string | undefined): PageLanguage;
|
|
9
|
+
/**
|
|
10
|
+
* The language of a page a link opens: the first of the browser's languages that is Chinese or Japanese, else the
|
|
11
|
+
* language the link was made in (`linked`, the inviter's), else English. A browser in English alone, as many are
|
|
12
|
+
* whatever their users read, gets the page in the words of who sent the link.
|
|
13
|
+
*/
|
|
14
|
+
export declare function linkLanguage(languages: readonly string[], linked?: string): PageLanguage;
|
|
15
|
+
//# sourceMappingURL=page-language.d.ts.map
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.pageLanguage = pageLanguage;
|
|
4
|
+
exports.linkLanguage = linkLanguage;
|
|
5
|
+
/**
|
|
6
|
+
* The language of a page, from the browser's (`navigator.language`): Traditional Chinese for Taiwan, Hong Kong, Macau
|
|
7
|
+
* and `Hant`, Simplified for other Chinese, Japanese, else English; as TaLanguageUtil.of of ta-protocol, which the
|
|
8
|
+
* relay does without.
|
|
9
|
+
*/
|
|
10
|
+
function pageLanguage(tag = typeof navigator === 'undefined' ? undefined : navigator.language) {
|
|
11
|
+
const said = (tag !== null && tag !== void 0 ? tag : '').toLowerCase().replace(/_/g, '-');
|
|
12
|
+
if (/^zh(\b|-)/.test(said)) {
|
|
13
|
+
return /-hant\b/.test(said) || (!/-hans\b/.test(said) && /-(tw|hk|mo)\b/.test(said)) ? 'zh-TW' : 'zh-CN';
|
|
14
|
+
}
|
|
15
|
+
return /^ja(\b|-)/.test(said) ? 'ja-JP' : 'en-US';
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The language of a page a link opens: the first of the browser's languages that is Chinese or Japanese, else the
|
|
19
|
+
* language the link was made in (`linked`, the inviter's), else English. A browser in English alone, as many are
|
|
20
|
+
* whatever their users read, gets the page in the words of who sent the link.
|
|
21
|
+
*/
|
|
22
|
+
function linkLanguage(languages, linked) {
|
|
23
|
+
for (const tag of languages) {
|
|
24
|
+
const language = pageLanguage(tag);
|
|
25
|
+
if (language !== 'en-US') {
|
|
26
|
+
return language;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return linked && /^(zh|ja|en)\b/i.test(linked) ? pageLanguage(linked) : 'en-US';
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=page-language.js.map
|
|
@@ -16,6 +16,8 @@ export interface RelayTeamLink {
|
|
|
16
16
|
role: string;
|
|
17
17
|
/** It shares something on its own: the name shown (`设计师`). */
|
|
18
18
|
what?: string;
|
|
19
|
+
/** The language of who made it (`zh-CN`): the page of the link speaks it, unless the browser asks Chinese or Japanese. */
|
|
20
|
+
language?: string;
|
|
19
21
|
}
|
|
20
22
|
/** Where one asking from a browser comes from: the page of the relay (RELAY_JOIN_PATH), not the Ta app. */
|
|
21
23
|
export type RelayTeamVia = 'web';
|
|
@@ -35,19 +37,34 @@ export interface RelayTeamAnswer {
|
|
|
35
37
|
}
|
|
36
38
|
/** How one asking by a link may say who they are (docs/design/ta-team.md 17). */
|
|
37
39
|
export interface RelayTeamWays {
|
|
38
|
-
/** The providers the Ta signs in with: GitHub, Google, WeChat, the operator's. */
|
|
40
|
+
/** The providers the Ta signs in with: GitHub, Google, WeChat, the operator's; `device`, by a code typed at it. */
|
|
39
41
|
providers: {
|
|
40
42
|
id: string;
|
|
41
43
|
name: string;
|
|
44
|
+
device?: true;
|
|
42
45
|
}[];
|
|
43
46
|
/** They sign in first: the role manages members and they ask from a browser; otherwise signing in is theirs to choose. */
|
|
44
47
|
required: boolean;
|
|
45
48
|
/** The role manages members. */
|
|
46
49
|
manages?: boolean;
|
|
47
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* A sign-in started: `url`, where the browser goes, to come back to the page of the link; `device`, a code to type at
|
|
53
|
+
* the provider's `uri` (GitHub's device flow), the Ta asking it whether it was ({@link RelayTeamJoining.typed}).
|
|
54
|
+
*/
|
|
55
|
+
export interface RelayTeamSignInStart {
|
|
56
|
+
state: string;
|
|
57
|
+
url?: string;
|
|
58
|
+
device?: {
|
|
59
|
+
code: string;
|
|
60
|
+
uri: string;
|
|
61
|
+
expiresAt: number;
|
|
62
|
+
};
|
|
63
|
+
}
|
|
48
64
|
/**
|
|
49
65
|
* Signed in with a provider: as it came back to the page of the link (the code goes to the Ta, which alone can use it),
|
|
50
|
-
* or in a browser for the Ta app, by the handoff id the app gave it (RelayTeamLinkUtil.signInFor)
|
|
66
|
+
* or in a browser for the Ta app, by the handoff id the app gave it (RelayTeamLinkUtil.signInFor), or by a code typed,
|
|
67
|
+
* by the state of its sign-in as the handoff.
|
|
51
68
|
*/
|
|
52
69
|
export type RelayTeamSignIn = {
|
|
53
70
|
state: string;
|
|
@@ -108,15 +125,14 @@ export declare class RelayTeamJoining {
|
|
|
108
125
|
/** The keys of the request asked. */
|
|
109
126
|
get keys(): RelayIdentity | undefined;
|
|
110
127
|
/**
|
|
111
|
-
* How to say who one is. A Ta of before has no accounts for those asking (its link may not call `ways`): none needed
|
|
112
|
-
*
|
|
128
|
+
* How to say who one is. A Ta of before has no accounts for those asking (its link may not call `ways`): none needed.
|
|
129
|
+
* A Ta that cannot be reached throws, so that the page says so rather than hide the ways to sign in.
|
|
113
130
|
*/
|
|
114
131
|
ways(via?: RelayTeamVia): Promise<RelayTeamWays>;
|
|
132
|
+
/** A call the relay or the Ta did not answer: the Ta is off, or the connection was lost. */
|
|
133
|
+
static unreachable(failure: unknown): boolean;
|
|
115
134
|
/** Where the browser goes to sign in with a provider, and the state it comes back with to the page of the link; for the app, its handoff. */
|
|
116
|
-
signIn(provider: string, handoff?: string): Promise<
|
|
117
|
-
url: string;
|
|
118
|
-
state: string;
|
|
119
|
-
}>;
|
|
135
|
+
signIn(provider: string, handoff?: string): Promise<RelayTeamSignInStart>;
|
|
120
136
|
/** The browser came back signed in for the Ta app: the Ta verifies the account and keeps it for the app. */
|
|
121
137
|
signedIn(state: string, code: string): Promise<{
|
|
122
138
|
account: {
|
|
@@ -124,6 +140,15 @@ export declare class RelayTeamJoining {
|
|
|
124
140
|
name?: string;
|
|
125
141
|
};
|
|
126
142
|
}>;
|
|
143
|
+
/**
|
|
144
|
+
* Waits for the code of a sign-in (`device` of {@link signIn}) to be typed at the provider, asking again till it was
|
|
145
|
+
* (the account, kept by the Ta under the handoff of the sign-in, or its state), this stops or `until` passes. A call
|
|
146
|
+
* the relay or the Ta did not answer (a phone away while the code was typed) is asked again; one refused throws.
|
|
147
|
+
*/
|
|
148
|
+
typed(state: string, until?: number): Promise<{
|
|
149
|
+
id: string;
|
|
150
|
+
name?: string;
|
|
151
|
+
} | undefined>;
|
|
127
152
|
/**
|
|
128
153
|
* Waits for the browser to sign in for the app, asking again till it did (the account), this stops or `until`
|
|
129
154
|
* passes; a call that fails (the app was away while the browser was in front) is asked again.
|
package/lib/common/relay-team.js
CHANGED
|
@@ -50,18 +50,21 @@ var RelayTeamLinkUtil;
|
|
|
50
50
|
if (link.what) {
|
|
51
51
|
fragment.set('w', link.what);
|
|
52
52
|
}
|
|
53
|
+
if (link.language) {
|
|
54
|
+
fragment.set('l', link.language);
|
|
55
|
+
}
|
|
53
56
|
return `${link.relay.replace(/\/+$/, '')}${exports.RELAY_JOIN_PATH}#${fragment}`;
|
|
54
57
|
}
|
|
55
58
|
RelayTeamLinkUtil.format = format;
|
|
56
59
|
/** Undefined for text that is not such a link. */
|
|
57
60
|
function parse(text) {
|
|
58
61
|
var _a;
|
|
59
|
-
var _b, _c;
|
|
62
|
+
var _b, _c, _d;
|
|
60
63
|
let url;
|
|
61
64
|
try {
|
|
62
65
|
url = new URL(text.trim());
|
|
63
66
|
}
|
|
64
|
-
catch (
|
|
67
|
+
catch (_e) {
|
|
65
68
|
return undefined;
|
|
66
69
|
}
|
|
67
70
|
const fragment = new URLSearchParams(url.hash.slice(1));
|
|
@@ -75,7 +78,17 @@ var RelayTeamLinkUtil;
|
|
|
75
78
|
return undefined;
|
|
76
79
|
}
|
|
77
80
|
const what = (_a = fragment.get('w')) === null || _a === void 0 ? void 0 : _a.slice(0, 80);
|
|
78
|
-
|
|
81
|
+
const language = (_b = fragment.get('l')) !== null && _b !== void 0 ? _b : '';
|
|
82
|
+
return {
|
|
83
|
+
relay: url.origin,
|
|
84
|
+
host,
|
|
85
|
+
device,
|
|
86
|
+
key,
|
|
87
|
+
owner: (_c = fragment.get('o')) !== null && _c !== void 0 ? _c : '',
|
|
88
|
+
role: (_d = fragment.get('r')) !== null && _d !== void 0 ? _d : '',
|
|
89
|
+
...(what ? { what } : {}),
|
|
90
|
+
...(/^[a-z]{2}(-[A-Za-z]{2,4})?$/.test(language) ? { language } : {}),
|
|
91
|
+
};
|
|
79
92
|
}
|
|
80
93
|
RelayTeamLinkUtil.parse = parse;
|
|
81
94
|
/**
|
|
@@ -124,24 +137,59 @@ class RelayTeamJoining {
|
|
|
124
137
|
return this.own;
|
|
125
138
|
}
|
|
126
139
|
/**
|
|
127
|
-
* How to say who one is. A Ta of before has no accounts for those asking (its link may not call `ways`): none needed
|
|
128
|
-
*
|
|
140
|
+
* How to say who one is. A Ta of before has no accounts for those asking (its link may not call `ways`): none needed.
|
|
141
|
+
* A Ta that cannot be reached throws, so that the page says so rather than hide the ways to sign in.
|
|
129
142
|
*/
|
|
130
143
|
async ways(via) {
|
|
131
144
|
try {
|
|
132
145
|
return (await this.calls.callHost('ways', via ? { via } : {}));
|
|
133
146
|
}
|
|
134
|
-
catch (
|
|
147
|
+
catch (failure) {
|
|
148
|
+
if (RelayTeamJoining.unreachable(failure)) {
|
|
149
|
+
throw failure;
|
|
150
|
+
}
|
|
135
151
|
return { providers: [], required: false };
|
|
136
152
|
}
|
|
137
153
|
}
|
|
154
|
+
/** A call the relay or the Ta did not answer: the Ta is off, or the connection was lost. */
|
|
155
|
+
static unreachable(failure) {
|
|
156
|
+
return /did not answer|was lost/i.test(failure instanceof Error ? failure.message : String(failure));
|
|
157
|
+
}
|
|
138
158
|
/** Where the browser goes to sign in with a provider, and the state it comes back with to the page of the link; for the app, its handoff. */
|
|
139
159
|
async signIn(provider, handoff) {
|
|
140
160
|
return (await this.calls.callHost('signIn', { provider, ...(handoff ? { handoff } : {}) }));
|
|
141
161
|
}
|
|
142
162
|
/** The browser came back signed in for the Ta app: the Ta verifies the account and keeps it for the app. */
|
|
143
163
|
async signedIn(state, code) {
|
|
144
|
-
|
|
164
|
+
const answer = (await this.calls.callHost('signedIn', { state, code }));
|
|
165
|
+
return { account: answer.account };
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Waits for the code of a sign-in (`device` of {@link signIn}) to be typed at the provider, asking again till it was
|
|
169
|
+
* (the account, kept by the Ta under the handoff of the sign-in, or its state), this stops or `until` passes. A call
|
|
170
|
+
* the relay or the Ta did not answer (a phone away while the code was typed) is asked again; one refused throws.
|
|
171
|
+
*/
|
|
172
|
+
async typed(state, until = Date.now() + 15 * 60000) {
|
|
173
|
+
while (!this.closed && Date.now() < until) {
|
|
174
|
+
let answer;
|
|
175
|
+
try {
|
|
176
|
+
answer = (await this.calls.callHost('signedIn', { state }));
|
|
177
|
+
}
|
|
178
|
+
catch (failure) {
|
|
179
|
+
if (this.closed) {
|
|
180
|
+
return undefined;
|
|
181
|
+
}
|
|
182
|
+
if (!RelayTeamJoining.unreachable(failure)) {
|
|
183
|
+
throw failure;
|
|
184
|
+
}
|
|
185
|
+
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
188
|
+
if (answer.status === 'done' && answer.account) {
|
|
189
|
+
return answer.account;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
return undefined;
|
|
145
193
|
}
|
|
146
194
|
/**
|
|
147
195
|
* Waits for the browser to sign in for the app, asking again till it did (the account), this stops or `until`
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type PageLanguage } from '../common/page-language';
|
|
1
2
|
declare const zh: {
|
|
2
3
|
title: string;
|
|
3
4
|
invalid: string;
|
|
@@ -43,8 +44,12 @@ declare const zh: {
|
|
|
43
44
|
close: string;
|
|
44
45
|
};
|
|
45
46
|
export type GuestText = keyof typeof zh;
|
|
47
|
+
/** The words of each language of Ta, checked by scripts/check-i18n.ts. */
|
|
48
|
+
export declare const GUEST_WORDS: Readonly<Record<PageLanguage, typeof zh>>;
|
|
46
49
|
export declare namespace GuestI18n {
|
|
47
|
-
const
|
|
50
|
+
const language: PageLanguage;
|
|
51
|
+
/** Chinese or Japanese: Latin among the words has a space on each side. */
|
|
52
|
+
const cjk: boolean;
|
|
48
53
|
function t(id: GuestText, values?: Record<string, string | number>): string;
|
|
49
54
|
/** The time of a line: when today, else the day too. */
|
|
50
55
|
function time(at: number): string;
|