@celljs/ta-host 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.
Files changed (55) hide show
  1. package/README.en.md +2 -1
  2. package/README.md +2 -1
  3. package/esm/node/auth-server-impl.d.ts +12 -2
  4. package/esm/node/auth-server-impl.js +102 -3
  5. package/esm/node/custom-providers.d.ts +50 -0
  6. package/esm/node/custom-providers.js +335 -0
  7. package/esm/node/extension-data.js +7 -3
  8. package/esm/node/index.d.ts +1 -0
  9. package/esm/node/index.js +1 -0
  10. package/esm/node/jpeg-encoder.d.ts +7 -0
  11. package/esm/node/jpeg-encoder.js +268 -0
  12. package/esm/node/png-thumbnail.d.ts +40 -0
  13. package/esm/node/png-thumbnail.js +384 -0
  14. package/esm/node/serve-updates.d.ts +38 -0
  15. package/esm/node/serve-updates.js +89 -0
  16. package/esm/node/sign-in/sign-in-provider.d.ts +44 -0
  17. package/esm/node/sign-in/sign-in-provider.js +74 -7
  18. package/esm/node/sign-in/ta-sign-in.d.ts +4 -1
  19. package/esm/node/sign-in/ta-sign-in.js +6 -2
  20. package/esm/node/ta-server-impl.d.ts +3 -0
  21. package/esm/node/ta-server-impl.js +33 -9
  22. package/esm/node/team/host-team.js +1 -0
  23. package/esm/node/team/member-accounts.d.ts +25 -8
  24. package/esm/node/team/member-accounts.js +84 -4
  25. package/esm/node/team/team-calls.js +5 -0
  26. package/esm/node/web-extension-util.js +1 -0
  27. package/esm/node/workspace-files.d.ts +23 -0
  28. package/esm/node/workspace-files.js +86 -0
  29. package/lib/node/auth-server-impl.d.ts +12 -2
  30. package/lib/node/auth-server-impl.js +101 -2
  31. package/lib/node/custom-providers.d.ts +51 -0
  32. package/lib/node/custom-providers.js +338 -0
  33. package/lib/node/extension-data.js +6 -2
  34. package/lib/node/index.d.ts +1 -0
  35. package/lib/node/index.js +1 -0
  36. package/lib/node/jpeg-encoder.d.ts +8 -0
  37. package/lib/node/jpeg-encoder.js +271 -0
  38. package/lib/node/png-thumbnail.d.ts +41 -0
  39. package/lib/node/png-thumbnail.js +387 -0
  40. package/lib/node/serve-updates.d.ts +39 -0
  41. package/lib/node/serve-updates.js +92 -0
  42. package/lib/node/sign-in/sign-in-provider.d.ts +44 -0
  43. package/lib/node/sign-in/sign-in-provider.js +77 -9
  44. package/lib/node/sign-in/ta-sign-in.d.ts +4 -1
  45. package/lib/node/sign-in/ta-sign-in.js +6 -2
  46. package/lib/node/ta-server-impl.d.ts +3 -0
  47. package/lib/node/ta-server-impl.js +33 -9
  48. package/lib/node/team/host-team.js +1 -0
  49. package/lib/node/team/member-accounts.d.ts +25 -8
  50. package/lib/node/team/member-accounts.js +84 -4
  51. package/lib/node/team/team-calls.js +5 -0
  52. package/lib/node/web-extension-util.js +1 -0
  53. package/lib/node/workspace-files.d.ts +23 -0
  54. package/lib/node/workspace-files.js +86 -0
  55. package/package.json +10 -10
@@ -0,0 +1,387 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PngThumbnail = void 0;
4
+ const node_zlib_1 = require("node:zlib");
5
+ const jpeg_encoder_1 = require("./jpeg-encoder");
6
+ const SIGNATURE = [0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a];
7
+ /** Smaller than this much of its size, a picture is sent as it is: what it would save is not worth the time. */
8
+ const WORTH = 0.8;
9
+ /** Filled, a picture is never more than this many times its box on its long side (a very long one). */
10
+ const COVER_LONG = 4;
11
+ /** Rows read between two turns of the event loop, so that a large picture never holds up the other requests. */
12
+ const ROWS_A_TURN = 96;
13
+ /** A smaller PNG of more bytes a pixel than this is of a photo, a 3D scene or a gradient: a JPEG is tried too. */
14
+ const PHOTO_BYTES_A_PIXEL = 0.25;
15
+ const JPEG_QUALITY = 82;
16
+ /** Pictures of more pixels than this are sent as they are. */
17
+ const MAX_PIXELS = 64 * 1024 * 1024;
18
+ const CRC_TABLE = (() => {
19
+ const table = new Uint32Array(256);
20
+ for (let n = 0; n < 256; n++) {
21
+ let c = n;
22
+ for (let k = 0; k < 8; k++) {
23
+ c = c & 1 ? 0xedb88320 ^ (c >>> 1) : c >>> 1;
24
+ }
25
+ table[n] = c >>> 0;
26
+ }
27
+ return table;
28
+ })();
29
+ /**
30
+ * A smaller picture of a PNG, made without a library: the image read (any color type, 8 or 16 bits, a palette of 1 to 8,
31
+ * not interlaced), averaged down to the box (alpha weighted, so edges keep their colour) and written again, RGB when
32
+ * it is opaque. It yields to the event loop as it reads. Undefined for what it does not read, and for a picture already
33
+ * near the size of the box: then the picture itself is sent.
34
+ */
35
+ var PngThumbnail;
36
+ (function (PngThumbnail) {
37
+ function isPng(bytes) {
38
+ return bytes.length > 8 && SIGNATURE.every((byte, index) => bytes[index] === byte);
39
+ }
40
+ PngThumbnail.isPng = isPng;
41
+ /** The size a picture of `width` × `height` takes for `box`, never larger than it is. */
42
+ function size(width, height, box) {
43
+ let scale = box.fit === 'cover' ? Math.max(box.width / width, box.height / height) : Math.min(box.width / width, box.height / height);
44
+ if (box.fit === 'cover') {
45
+ scale = Math.min(scale, (box.width * COVER_LONG) / width, (box.height * COVER_LONG) / height);
46
+ }
47
+ scale = Math.min(1, scale);
48
+ return { width: Math.max(1, Math.round(width * scale)), height: Math.max(1, Math.round(height * scale)) };
49
+ }
50
+ PngThumbnail.size = size;
51
+ /**
52
+ * The smaller picture: a PNG, or a JPEG when the picture is opaque and of a photo (its PNG large for its pixels)
53
+ * and the JPEG is smaller.
54
+ */
55
+ async function make(bytes, box) {
56
+ const small = await smaller(bytes, box);
57
+ if (!small) {
58
+ return undefined;
59
+ }
60
+ const solid = opaque(small.rgba);
61
+ // Of its own size it is only written again as a JPEG: its PNG would be much what it is.
62
+ const png = small.resized ? encode(small.rgba, small.width, small.height) : undefined;
63
+ let made = png && { bytes: png, type: 'image/png' };
64
+ if (solid && (!png || png.length > small.width * small.height * PHOTO_BYTES_A_PIXEL)) {
65
+ await new Promise(resolve => setImmediate(resolve));
66
+ const jpeg = jpeg_encoder_1.JpegEncoder.encode(small.rgba, small.width, small.height, JPEG_QUALITY);
67
+ if (!made || jpeg.length < made.bytes.length) {
68
+ made = { bytes: jpeg, type: 'image/jpeg' };
69
+ }
70
+ }
71
+ // Not much smaller than the picture itself: the picture is sent.
72
+ return made && made.bytes.length < bytes.length * WORTH ? made : undefined;
73
+ }
74
+ PngThumbnail.make = make;
75
+ function opaque(rgba) {
76
+ for (let i = 3; i < rgba.length; i += 4) {
77
+ if (rgba[i] !== 255) {
78
+ return false;
79
+ }
80
+ }
81
+ return true;
82
+ }
83
+ async function smaller(bytes, box) {
84
+ if (!isPng(bytes)) {
85
+ return undefined;
86
+ }
87
+ const parsed = chunks(bytes);
88
+ if (!parsed) {
89
+ return undefined;
90
+ }
91
+ const { header, palette, transparency, data } = parsed;
92
+ const channels = CHANNELS[header.color];
93
+ if (!channels || header.interlace !== 0 || !depthFits(header) || header.width * header.height > MAX_PIXELS) {
94
+ return undefined;
95
+ }
96
+ // Near the size of the box, only a photo is written again: as a JPEG, smaller (make).
97
+ const pixels = header.width * header.height;
98
+ const near = size(header.width, header.height, box);
99
+ const out = near.width * near.height > pixels * WORTH * WORTH ? { width: header.width, height: header.height } : near;
100
+ if (out.width === header.width && bytes.length < pixels * PHOTO_BYTES_A_PIXEL * 2) {
101
+ return undefined;
102
+ }
103
+ let raw;
104
+ try {
105
+ raw = (0, node_zlib_1.inflateSync)(data);
106
+ }
107
+ catch (_a) {
108
+ return undefined;
109
+ }
110
+ const rgba = await average(raw, header, channels, palette, transparency, out.width, out.height);
111
+ return rgba && { width: out.width, height: out.height, rgba, resized: out.width !== header.width || out.height !== header.height };
112
+ }
113
+ /** The pixels of a PNG as RGBA, as `make` reads them; undefined for one it does not read. */
114
+ async function read(bytes) {
115
+ const parsed = isPng(bytes) ? chunks(bytes) : undefined;
116
+ const channels = parsed && CHANNELS[parsed.header.color];
117
+ if (!parsed || !channels || parsed.header.interlace !== 0 || !depthFits(parsed.header)) {
118
+ return undefined;
119
+ }
120
+ const { header, palette, transparency, data } = parsed;
121
+ const rgba = await average((0, node_zlib_1.inflateSync)(data), header, channels, palette, transparency, header.width, header.height);
122
+ return rgba && { width: header.width, height: header.height, rgba };
123
+ }
124
+ PngThumbnail.read = read;
125
+ const CHANNELS = { 0: 1, 2: 3, 3: 1, 4: 2, 6: 4 };
126
+ function depthFits({ color, depth }) {
127
+ return color === 3 ? [1, 2, 4, 8].includes(depth) : color === 0 ? [1, 2, 4, 8, 16].includes(depth) : depth === 8 || depth === 16;
128
+ }
129
+ function chunks(bytes) {
130
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
131
+ let header;
132
+ let palette;
133
+ let transparency;
134
+ const data = [];
135
+ for (let at = 8; at + 8 <= bytes.length;) {
136
+ const length = view.getUint32(at);
137
+ const type = String.fromCharCode(bytes[at + 4], bytes[at + 5], bytes[at + 6], bytes[at + 7]);
138
+ const body = bytes.subarray(at + 8, at + 8 + length);
139
+ if (body.length !== length) {
140
+ return undefined;
141
+ }
142
+ if (type === 'IHDR') {
143
+ header = {
144
+ width: view.getUint32(at + 8),
145
+ height: view.getUint32(at + 12),
146
+ depth: bytes[at + 16],
147
+ color: bytes[at + 17],
148
+ interlace: bytes[at + 20],
149
+ };
150
+ }
151
+ else if (type === 'PLTE') {
152
+ palette = body;
153
+ }
154
+ else if (type === 'tRNS') {
155
+ transparency = body;
156
+ }
157
+ else if (type === 'IDAT') {
158
+ data.push(body);
159
+ }
160
+ else if (type === 'IEND') {
161
+ break;
162
+ }
163
+ at += 12 + length;
164
+ }
165
+ return header && header.width > 0 && header.height > 0 && data.length > 0 ? { header, palette, transparency, data: Buffer.concat(data) } : undefined;
166
+ }
167
+ /** The image averaged down to `width` × `height`, as RGBA. */
168
+ async function average(raw, header, channels, palette, transparency, width, height) {
169
+ const { width: sourceWidth, height: sourceHeight, depth, color } = header;
170
+ const bits = channels * depth;
171
+ const stride = Math.ceil((sourceWidth * bits) / 8);
172
+ const step = Math.max(1, bits >> 3);
173
+ if (raw.length < (stride + 1) * sourceHeight || (color === 3 && !palette)) {
174
+ return undefined;
175
+ }
176
+ // Premultiplied sums of each pixel of the smaller picture, and its alpha.
177
+ const sums = new Float64Array(width * height * 4);
178
+ const counts = new Uint32Array(width * height);
179
+ const columns = new Uint32Array(sourceWidth);
180
+ for (let x = 0; x < sourceWidth; x++) {
181
+ columns[x] = Math.min(width - 1, Math.floor((x * width) / sourceWidth));
182
+ }
183
+ const max = (1 << Math.min(depth, 8)) - 1;
184
+ const key = transparency && (color === 0 || color === 2) ? transparency : undefined;
185
+ let previous = new Uint8Array(stride);
186
+ let line = new Uint8Array(stride);
187
+ const rgba = [0, 0, 0, 0];
188
+ for (let y = 0; y < sourceHeight; y++) {
189
+ if (y % ROWS_A_TURN === ROWS_A_TURN - 1) {
190
+ await new Promise(resolve => setImmediate(resolve));
191
+ }
192
+ const start = y * (stride + 1);
193
+ const filter = raw[start];
194
+ line.set(raw.subarray(start + 1, start + 1 + stride));
195
+ if (!unfilter(filter, line, previous, step)) {
196
+ return undefined;
197
+ }
198
+ const row = Math.min(height - 1, Math.floor((y * height) / sourceHeight)) * width;
199
+ for (let x = 0; x < sourceWidth; x++) {
200
+ pixel(line, x, depth, color, max, palette, transparency, key, rgba);
201
+ const at = row + columns[x];
202
+ const alpha = rgba[3];
203
+ sums[at * 4] += rgba[0] * alpha;
204
+ sums[at * 4 + 1] += rgba[1] * alpha;
205
+ sums[at * 4 + 2] += rgba[2] * alpha;
206
+ sums[at * 4 + 3] += alpha;
207
+ counts[at]++;
208
+ }
209
+ [previous, line] = [line, previous];
210
+ }
211
+ const out = new Uint8Array(width * height * 4);
212
+ for (let i = 0; i < width * height; i++) {
213
+ const alpha = sums[i * 4 + 3];
214
+ if (alpha > 0) {
215
+ out[i * 4] = Math.round(sums[i * 4] / alpha);
216
+ out[i * 4 + 1] = Math.round(sums[i * 4 + 1] / alpha);
217
+ out[i * 4 + 2] = Math.round(sums[i * 4 + 2] / alpha);
218
+ }
219
+ out[i * 4 + 3] = counts[i] ? Math.round(alpha / counts[i]) : 0;
220
+ }
221
+ return out;
222
+ }
223
+ function unfilter(filter, line, previous, step) {
224
+ const length = line.length;
225
+ switch (filter) {
226
+ case 0:
227
+ return true;
228
+ case 1:
229
+ for (let i = step; i < length; i++) {
230
+ line[i] = (line[i] + line[i - step]) & 255;
231
+ }
232
+ return true;
233
+ case 2:
234
+ for (let i = 0; i < length; i++) {
235
+ line[i] = (line[i] + previous[i]) & 255;
236
+ }
237
+ return true;
238
+ case 3:
239
+ for (let i = 0; i < length; i++) {
240
+ line[i] = (line[i] + (((i >= step ? line[i - step] : 0) + previous[i]) >> 1)) & 255;
241
+ }
242
+ return true;
243
+ case 4:
244
+ for (let i = 0; i < length; i++) {
245
+ line[i] = (line[i] + paeth(i >= step ? line[i - step] : 0, previous[i], i >= step ? previous[i - step] : 0)) & 255;
246
+ }
247
+ return true;
248
+ default:
249
+ return false;
250
+ }
251
+ }
252
+ function paeth(a, b, c) {
253
+ const p = a + b - c;
254
+ const pa = Math.abs(p - a);
255
+ const pb = Math.abs(p - b);
256
+ const pc = Math.abs(p - c);
257
+ return pa <= pb && pa <= pc ? a : pb <= pc ? b : c;
258
+ }
259
+ /** The RGBA (0–255) of pixel `x` of a row, into `out`. */
260
+ function pixel(line, x, depth, color, max, palette, transparency, key, out) {
261
+ if (depth < 8) {
262
+ const bit = x * depth;
263
+ const value = (line[bit >> 3] >> (8 - depth - (bit & 7))) & max;
264
+ if (color === 3 && palette) {
265
+ fromPalette(value, palette, transparency, out);
266
+ }
267
+ else {
268
+ const gray = Math.round((value * 255) / max);
269
+ out[0] = out[1] = out[2] = gray;
270
+ out[3] = key && ((key[0] << 8) | key[1]) === value ? 0 : 255;
271
+ }
272
+ return;
273
+ }
274
+ const wide = depth === 16;
275
+ const size = wide ? 2 : 1;
276
+ const sample = (channel, channels) => line[(x * channels + channel) * size];
277
+ switch (color) {
278
+ case 0: {
279
+ const gray = sample(0, 1);
280
+ out[0] = out[1] = out[2] = gray;
281
+ out[3] = key && !wide && key[1] === gray ? 0 : 255;
282
+ return;
283
+ }
284
+ case 2:
285
+ out[0] = sample(0, 3);
286
+ out[1] = sample(1, 3);
287
+ out[2] = sample(2, 3);
288
+ out[3] = key && !wide && key[1] === out[0] && key[3] === out[1] && key[5] === out[2] ? 0 : 255;
289
+ return;
290
+ case 3:
291
+ fromPalette(line[x], palette, transparency, out);
292
+ return;
293
+ case 4:
294
+ out[0] = out[1] = out[2] = sample(0, 2);
295
+ out[3] = sample(1, 2);
296
+ return;
297
+ default:
298
+ out[0] = sample(0, 4);
299
+ out[1] = sample(1, 4);
300
+ out[2] = sample(2, 4);
301
+ out[3] = sample(3, 4);
302
+ }
303
+ }
304
+ function fromPalette(index, palette, transparency, out) {
305
+ var _a, _b, _c;
306
+ out[0] = (_a = palette[index * 3]) !== null && _a !== void 0 ? _a : 0;
307
+ out[1] = (_b = palette[index * 3 + 1]) !== null && _b !== void 0 ? _b : 0;
308
+ out[2] = (_c = palette[index * 3 + 2]) !== null && _c !== void 0 ? _c : 0;
309
+ out[3] = transparency && index < transparency.length ? transparency[index] : 255;
310
+ }
311
+ /** RGBA written as a PNG: RGB when every pixel is opaque, each row with the filter that leaves the smallest sums. */
312
+ function encode(rgba, width, height) {
313
+ const solid = opaque(rgba);
314
+ const step = solid ? 3 : 4;
315
+ const stride = width * step;
316
+ const raw = new Uint8Array((stride + 1) * height);
317
+ let previous = new Uint8Array(stride);
318
+ let line = new Uint8Array(stride);
319
+ const trial = new Uint8Array(stride);
320
+ const best = new Uint8Array(stride);
321
+ for (let y = 0; y < height; y++) {
322
+ for (let x = 0; x < width; x++) {
323
+ for (let c = 0; c < step; c++) {
324
+ line[x * step + c] = rgba[(y * width + x) * 4 + c];
325
+ }
326
+ }
327
+ let bestFilter = 0;
328
+ let bestScore = Number.POSITIVE_INFINITY;
329
+ for (let filter = 0; filter < 5; filter++) {
330
+ let score = 0;
331
+ for (let i = 0; i < stride; i++) {
332
+ const left = i >= step ? line[i - step] : 0;
333
+ const up = previous[i];
334
+ const corner = i >= step ? previous[i - step] : 0;
335
+ const predicted = filter === 0 ? 0 : filter === 1 ? left : filter === 2 ? up : filter === 3 ? (left + up) >> 1 : paeth(left, up, corner);
336
+ const value = (line[i] - predicted) & 255;
337
+ trial[i] = value;
338
+ score += value < 128 ? value : 256 - value;
339
+ }
340
+ if (score < bestScore) {
341
+ bestScore = score;
342
+ bestFilter = filter;
343
+ best.set(trial);
344
+ }
345
+ }
346
+ raw[y * (stride + 1)] = bestFilter;
347
+ raw.set(best, y * (stride + 1) + 1);
348
+ [previous, line] = [line, previous];
349
+ }
350
+ const header = new Uint8Array(13);
351
+ const view = new DataView(header.buffer);
352
+ view.setUint32(0, width);
353
+ view.setUint32(4, height);
354
+ header[8] = 8;
355
+ header[9] = solid ? 2 : 6;
356
+ return chunked([
357
+ ['IHDR', header],
358
+ ['IDAT', (0, node_zlib_1.deflateSync)(raw, { level: 6 })],
359
+ ['IEND', new Uint8Array(0)],
360
+ ]);
361
+ }
362
+ PngThumbnail.encode = encode;
363
+ /** A PNG of these chunks, each with its length and CRC. */
364
+ function chunked(parts) {
365
+ return Buffer.concat([Uint8Array.from(SIGNATURE), ...parts.map(([type, body]) => chunk(type, body))]);
366
+ }
367
+ PngThumbnail.chunked = chunked;
368
+ function chunk(type, body) {
369
+ const out = new Uint8Array(12 + body.length);
370
+ const view = new DataView(out.buffer);
371
+ view.setUint32(0, body.length);
372
+ for (let i = 0; i < 4; i++) {
373
+ out[4 + i] = type.charCodeAt(i);
374
+ }
375
+ out.set(body, 8);
376
+ view.setUint32(8 + body.length, crc(out.subarray(4, 8 + body.length)));
377
+ return out;
378
+ }
379
+ function crc(bytes) {
380
+ let c = 0xffffffff;
381
+ for (let i = 0; i < bytes.length; i++) {
382
+ c = CRC_TABLE[(c ^ bytes[i]) & 255] ^ (c >>> 8);
383
+ }
384
+ return (c ^ 0xffffffff) >>> 0;
385
+ }
386
+ })(PngThumbnail || (exports.PngThumbnail = PngThumbnail = {}));
387
+ //# sourceMappingURL=png-thumbnail.js.map
@@ -0,0 +1,39 @@
1
+ import { type Application, ApplicationLifecycle } from '@celljs/core';
2
+ import type { TaServerUpdate } from '@celljs/ta-protocol';
3
+ export declare const TaServeUpdates: unique symbol;
4
+ /**
5
+ * The build of Ta that runs, and one installed over it since (an update of Ta Desktop, `npm i -g`, a build of the
6
+ * repository), which a restart of ta serve would run: TaServerInfo.version, build and update.
7
+ */
8
+ export interface TaServeUpdates {
9
+ /** The build read as the server started. */
10
+ running(): TaInstalledBuild;
11
+ /** Another build installed since, if any. */
12
+ update(): TaServerUpdate | undefined;
13
+ }
14
+ /** A build of Ta in its directory. */
15
+ export interface TaInstalledBuild extends TaServerUpdate {
16
+ /** What changes with each build: the file of its package.json, replaced or written again. */
17
+ stamp?: string;
18
+ }
19
+ export declare namespace TaServeUpdateUtil {
20
+ /** Where pi reads ta's package.json (TaBrand.activate): dist/pi of @celljs/ta, which each build writes again. */
21
+ function directory(): string | undefined;
22
+ function stamp(dir: string): string | undefined;
23
+ /**
24
+ * The build in `dir`: its version, and for a build of the development channel of Ta Desktop its commit, from
25
+ * ta-build.json in Contents/Resources of the app (`dir` is Resources/ta/dist/pi). Undefined while it cannot be read.
26
+ */
27
+ function read(dir: string): TaInstalledBuild | undefined;
28
+ }
29
+ export declare class TaServeUpdatesImpl implements TaServeUpdates, ApplicationLifecycle<Application> {
30
+ protected readonly dir: string | undefined;
31
+ /** As the server started: the files of the build that runs, read before anything replaced them. */
32
+ protected readonly started: TaInstalledBuild;
33
+ /** The build found installed over it, read once for each stamp. */
34
+ protected found?: TaInstalledBuild;
35
+ onStart(): void;
36
+ running(): TaInstalledBuild;
37
+ update(): TaServerUpdate | undefined;
38
+ }
39
+ //# sourceMappingURL=serve-updates.d.ts.map
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.TaServeUpdatesImpl = exports.TaServeUpdateUtil = exports.TaServeUpdates = void 0;
10
+ const node_fs_1 = require("node:fs");
11
+ const node_path_1 = require("node:path");
12
+ const core_1 = require("@celljs/core");
13
+ exports.TaServeUpdates = Symbol('TaServeUpdates');
14
+ var TaServeUpdateUtil;
15
+ (function (TaServeUpdateUtil) {
16
+ /** Where pi reads ta's package.json (TaBrand.activate): dist/pi of @celljs/ta, which each build writes again. */
17
+ function directory() {
18
+ return process.env.PI_PACKAGE_DIR || undefined;
19
+ }
20
+ TaServeUpdateUtil.directory = directory;
21
+ function stamp(dir) {
22
+ try {
23
+ const { ino, mtimeMs, size } = (0, node_fs_1.statSync)((0, node_path_1.join)(dir, 'package.json'));
24
+ return `${ino}:${mtimeMs}:${size}`;
25
+ }
26
+ catch (_a) {
27
+ return undefined;
28
+ }
29
+ }
30
+ TaServeUpdateUtil.stamp = stamp;
31
+ /**
32
+ * The build in `dir`: its version, and for a build of the development channel of Ta Desktop its commit, from
33
+ * ta-build.json in Contents/Resources of the app (`dir` is Resources/ta/dist/pi). Undefined while it cannot be read.
34
+ */
35
+ function read(dir) {
36
+ const stamp = TaServeUpdateUtil.stamp(dir);
37
+ let version;
38
+ try {
39
+ version = JSON.parse((0, node_fs_1.readFileSync)((0, node_path_1.join)(dir, 'package.json'), 'utf8')).version;
40
+ }
41
+ catch (_a) {
42
+ return undefined;
43
+ }
44
+ if (typeof version !== 'string') {
45
+ return undefined;
46
+ }
47
+ return { version, ...buildOf((0, node_path_1.join)(dir, '..', '..', '..', 'ta-build.json')), ...(stamp ? { stamp } : {}) };
48
+ }
49
+ TaServeUpdateUtil.read = read;
50
+ function buildOf(file) {
51
+ try {
52
+ const { channel, commit } = JSON.parse((0, node_fs_1.readFileSync)(file, 'utf8'));
53
+ return channel === 'dev' && typeof commit === 'string' && commit ? { build: commit.slice(0, 7) } : {};
54
+ }
55
+ catch (_a) {
56
+ return {};
57
+ }
58
+ }
59
+ })(TaServeUpdateUtil || (exports.TaServeUpdateUtil = TaServeUpdateUtil = {}));
60
+ let TaServeUpdatesImpl = class TaServeUpdatesImpl {
61
+ constructor() {
62
+ this.dir = TaServeUpdateUtil.directory();
63
+ /** As the server started: the files of the build that runs, read before anything replaced them. */
64
+ this.started = (this.dir && TaServeUpdateUtil.read(this.dir)) || { version: 'unknown' };
65
+ }
66
+ onStart() {
67
+ // Constructed as the server starts, so that `started` is the build that runs.
68
+ }
69
+ running() {
70
+ return this.started;
71
+ }
72
+ update() {
73
+ var _a;
74
+ const stamp = this.dir && TaServeUpdateUtil.stamp(this.dir);
75
+ if (!this.dir || !stamp || !this.started.stamp || stamp === this.started.stamp) {
76
+ return undefined;
77
+ }
78
+ if (((_a = this.found) === null || _a === void 0 ? void 0 : _a.stamp) !== stamp) {
79
+ this.found = TaServeUpdateUtil.read(this.dir);
80
+ }
81
+ if (!this.found) {
82
+ return undefined;
83
+ }
84
+ const { version, build } = this.found;
85
+ return { version, ...(build ? { build } : {}) };
86
+ }
87
+ };
88
+ exports.TaServeUpdatesImpl = TaServeUpdatesImpl;
89
+ exports.TaServeUpdatesImpl = TaServeUpdatesImpl = __decorate([
90
+ (0, core_1.Component)([exports.TaServeUpdates, core_1.ApplicationLifecycle])
91
+ ], TaServeUpdatesImpl);
92
+ //# sourceMappingURL=serve-updates.js.map
@@ -36,6 +36,8 @@ export interface GitHubEndpoints {
36
36
  authorize: string;
37
37
  token: string;
38
38
  user: string;
39
+ /** Where a code to type is asked for (the device flow). */
40
+ device: string;
39
41
  }
40
42
  /** GitHub's OAuth apps; the account is `github:<login>`. GitHub Enterprise Server has the same at its own address. */
41
43
  export declare class GitHubSignIn implements SignInProvider {
@@ -45,6 +47,8 @@ export declare class GitHubSignIn implements SignInProvider {
45
47
  readonly id = "github";
46
48
  readonly name = "GitHub";
47
49
  static endpoints(url?: string): GitHubEndpoints;
50
+ /** Who a token of GitHub is. */
51
+ static user(endpoints: GitHubEndpoints, token: string): Promise<SignInAccount>;
48
52
  constructor(clientId: string, clientSecret: string, endpoints?: GitHubEndpoints);
49
53
  authorizeUrl({ redirectUri, state, challenge }: {
50
54
  redirectUri: string;
@@ -57,6 +61,40 @@ export declare class GitHubSignIn implements SignInProvider {
57
61
  verifier: string;
58
62
  }): Promise<SignInAccount>;
59
63
  }
64
+ /** A code to type at the provider, and how often to ask whether it was (OAuth 2.0's device authorization, RFC 8628). */
65
+ export interface DeviceCode {
66
+ deviceCode: string;
67
+ userCode: string;
68
+ uri: string;
69
+ /** Seconds between asks. */
70
+ interval: number;
71
+ /** Seconds the code is good for. */
72
+ expiresIn: number;
73
+ }
74
+ /**
75
+ * A provider one signs in with by typing a code at it, the device flow: no secret and no address to come back to, so
76
+ * Ta ships one of its own and anyone's Ta knows who asks to come in without setting anything up (TaHostAccounts). It
77
+ * lets no one into ta serve: that is SignInFlow, with a provider of the operator's.
78
+ */
79
+ export interface DeviceSignInProvider extends TaSignInProvider {
80
+ readonly device: true;
81
+ code(): Promise<DeviceCode>;
82
+ /** The account once the code was typed and agreed to; `pending` while not yet, `slowDown` when asked too often. */
83
+ poll(deviceCode: string): Promise<SignInAccount | 'pending' | 'slowDown'>;
84
+ }
85
+ /** GitHub's device flow, with Ta's own OAuth app by default; the account is `github:<login>`, as GitHubSignIn's. */
86
+ export declare class GitHubDeviceSignIn implements DeviceSignInProvider {
87
+ protected readonly clientId: string;
88
+ protected readonly endpoints: GitHubEndpoints;
89
+ readonly id = "github";
90
+ readonly name = "GitHub";
91
+ readonly device: true;
92
+ /** Ta's own OAuth app on GitHub.com, its device flow on: a client id is public, and the device flow needs no secret. */
93
+ static readonly CLIENT_ID = "Ov23lip46sRQDlDM1xt7";
94
+ constructor(clientId?: string, endpoints?: GitHubEndpoints);
95
+ code(): Promise<DeviceCode>;
96
+ poll(deviceCode: string): Promise<SignInAccount | 'pending' | 'slowDown'>;
97
+ }
60
98
  interface OidcConfiguration {
61
99
  authorization_endpoint: string;
62
100
  token_endpoint: string;
@@ -165,6 +203,12 @@ export declare namespace SignInProviders {
165
203
  }
166
204
  /** The environment's variables that sign-in.json stands for: what the environment sets wins. */
167
205
  function withConfig(env: Record<string, string | undefined>, config: Config | undefined): Record<string, string | undefined>;
206
+ /**
207
+ * GitHub by a code, for those asking to come in, when GitHub is not set up with its secret (which goes there and back
208
+ * instead): `TA_GITHUB_DEVICE` is `off`, or `<client id>` or `<client id>@<address of GitHub>` of an OAuth app of
209
+ * one's own with its device flow on; by default Ta's own, on GitHub.com.
210
+ */
211
+ function device(env: Record<string, string | undefined>): DeviceSignInProvider | undefined;
168
212
  /**
169
213
  * The providers the operator configured in the environment of ta serve: a provider is offered when it
170
214
  * has its id and its secret.