@phnx-labs/artifacts-cli 0.10.0 → 0.12.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.
@@ -0,0 +1,491 @@
1
+ // Sharing a page with specific people by email (PHNX-4394), injected into the
2
+ // generated share Worker beside the publish and media sources.
3
+ //
4
+ // __people/<user>/<slug> {"people":["a@x.com",...],"updated_at":"<iso>"}
5
+ // The authority: gateVisibility reads it on
6
+ // every me/org read by someone who is neither
7
+ // the owner nor in the stamped domain.
8
+ // __inbox/<email>/<user>/<slug> empty, customMetadata {owner_email,
9
+ // owner_name, title, added_at}. An index for
10
+ // "Shared with me", never an authority: every
11
+ // listing re-checks the page's list.
12
+ //
13
+ // Routes (JSON, cache-control: no-store):
14
+ // GET|PUT /__people/<user>/<slug> the page owner (PATCH's authority); anyone
15
+ // else gets 404. GET returns the list's
16
+ // version; PUT replaces the whole list and
17
+ // needs If-Match: "<version>", else 412.
18
+ // GET /__lookup?email=<exact> any signed-in identity
19
+ // GET /__mine pages under the handles the caller holds
20
+ // GET /__shared pages shared to the caller's email
21
+ //
22
+ // Names come from Rush (POST /internal/artifact-collab/people, exact email
23
+ // match) and invitation emails go out through POST .../invites.
24
+ export const SHARE_PEOPLE_WORKER_SOURCE = `
25
+ var PEOPLE_MAX = 50;
26
+ var PEOPLE_BODY_MAX_BYTES = 16 * 1024;
27
+ // Per identity, in the usage ledger's fixed 1h windows: newly added addresses
28
+ // per page owner (each may be emailed), and exact-address lookups per caller.
29
+ var PEOPLE_ADDED_PER_HOUR = 20;
30
+ var PEOPLE_LOOKUPS_PER_HOUR = 60;
31
+ var PEOPLE_TITLE_MAX = 200;
32
+ // /__mine and /__shared answer one bounded page at a time; follow next_cursor.
33
+ var PEOPLE_PAGE_SIZE = 25;
34
+ var PEOPLE_MINE_MAX_HANDLES = 20;
35
+ var PEOPLE_MINE_PER_HOUR = 240;
36
+ var PEOPLE_EMAIL = /^[^\\s@\\/,;<>"]+@[^\\s@\\/,;<>"]+\\.[^\\s@\\/,;<>"]+$/;
37
+
38
+ function peopleKey(path) {
39
+ return '__people/' + path;
40
+ }
41
+
42
+ function inboxKey(email, path) {
43
+ return '__inbox/' + email + '/' + path;
44
+ }
45
+
46
+ function peopleJson(body, status) {
47
+ return new Response(JSON.stringify(body), {
48
+ status: status,
49
+ headers: { 'content-type': 'application/json; charset=utf-8', 'cache-control': 'no-store', 'X-Robots-Tag': 'noindex' },
50
+ });
51
+ }
52
+
53
+ function accessCheckUnavailable() {
54
+ return new Response(JSON.stringify({ error: 'access_check_unavailable' }), {
55
+ status: 503,
56
+ headers: { 'content-type': 'application/json; charset=utf-8', 'cache-control': 'private, no-store', 'X-Robots-Tag': 'noindex', 'retry-after': '5' },
57
+ });
58
+ }
59
+
60
+ // One address, lowercased, or '' when it is not one.
61
+ function normalizePersonEmail(raw) {
62
+ if (typeof raw !== 'string') return '';
63
+ const email = raw.trim().toLowerCase();
64
+ return email.length <= 254 && PEOPLE_EMAIL.test(email) ? email : '';
65
+ }
66
+
67
+ function isExpiredObject(obj) {
68
+ const expiresAt = obj && obj.customMetadata && obj.customMetadata['expires-at'];
69
+ return !!expiresAt && Date.now() > Date.parse(expiresAt);
70
+ }
71
+
72
+ function pageTitle(meta, path) {
73
+ return String((meta && (meta.label || meta['og-title'])) || path.split('/').pop()).slice(0, PEOPLE_TITLE_MAX);
74
+ }
75
+
76
+ function pageKind(contentType) {
77
+ const ct = String(contentType || '').toLowerCase();
78
+ if (ct.indexOf('text/html') !== -1) return 'page';
79
+ return viewableAssetKind(ct) || 'file';
80
+ }
81
+
82
+ // The page's list and its version: the sidecar's R2 etag, '' when there is
83
+ // none. Throws when it cannot be read or parsed, so every caller fails closed
84
+ // rather than treating an unreadable list as an empty one.
85
+ async function readPeopleRecord(env, path) {
86
+ const object = await env.BUCKET.get(peopleKey(path));
87
+ if (!object) return { people: [], version: '' };
88
+ const parsed = JSON.parse(await object.text());
89
+ if (!parsed || !Array.isArray(parsed.people) || parsed.people.some(function (email) { return typeof email !== 'string'; })) {
90
+ throw new Error('malformed people list for ' + path);
91
+ }
92
+ return { people: parsed.people, version: object.etag || '' };
93
+ }
94
+
95
+ async function readPeople(env, path) {
96
+ return (await readPeopleRecord(env, path)).people;
97
+ }
98
+
99
+ // Replace the list only if it is still at version. Returns the new version
100
+ // ('' once emptied), or null when another write got there first. Callers hold
101
+ // the page's path lock, which also covers the delete R2 cannot make conditional.
102
+ async function writePeople(env, path, people, version) {
103
+ if (!people.length) {
104
+ await env.BUCKET.delete(peopleKey(path));
105
+ return '';
106
+ }
107
+ const written = await env.BUCKET.put(peopleKey(path), JSON.stringify({ people: people, updated_at: new Date().toISOString() }), {
108
+ httpMetadata: { contentType: 'application/json' },
109
+ onlyIf: version ? { etagMatches: version } : { etagDoesNotMatch: '*' },
110
+ });
111
+ return written === null ? null : (written.etag || '');
112
+ }
113
+
114
+ // The version a PUT was based on, from If-Match: "<version>" (or bare), with
115
+ // "" meaning "there is no list yet". null when the header is absent.
116
+ function ifMatchVersion(request) {
117
+ const raw = request.headers.get('if-match');
118
+ if (raw === null) return null;
119
+ return raw.trim().replace(/^W\\//, '').replace(/^"(.*)"$/, '$1');
120
+ }
121
+
122
+ function peopleChanged(record) {
123
+ return peopleJson({ error: 'people_changed', people: record.people, version: record.version }, 412);
124
+ }
125
+
126
+ // A page that goes away takes its list and inbox entries with it. A list that
127
+ // cannot be parsed still goes; its inbox entries are dropped by the next
128
+ // /__shared that finds no list behind them.
129
+ async function clearPeople(env, path) {
130
+ let people = [];
131
+ try {
132
+ people = await readPeople(env, path);
133
+ } catch (error) {
134
+ people = [];
135
+ }
136
+ for (const email of people) await env.BUCKET.delete(inboxKey(email, path));
137
+ await env.BUCKET.delete(peopleKey(path));
138
+ }
139
+
140
+ // Called under the path's mutation lock before a publish writes: current is
141
+ // what sits at the path now. Only a live page keeps its people.
142
+ async function clearStalePeople(env, path, current) {
143
+ if (current && !isExpiredObject(current)) return;
144
+ await clearPeople(env, path);
145
+ }
146
+
147
+ // Names and avatars for exact addresses, from Rush's users. An address with no
148
+ // account is absent from byEmail. error is set when Rush could not answer, so
149
+ // a missing name is never mistaken for "no Rush account".
150
+ async function lookupPeopleNames(env, emails) {
151
+ if (!emails.length) return { byEmail: {} };
152
+ const collab = collabConfig(env);
153
+ if (!collab) return { byEmail: {}, error: true };
154
+ const result = await collabRegistryCall(collab, 'POST', '/people', '', { emails: emails });
155
+ if (result.error || !result.body || !Array.isArray(result.body.people)) return { byEmail: {}, error: true };
156
+ const byEmail = {};
157
+ for (const person of result.body.people) {
158
+ if (!person || typeof person.email !== 'string') continue;
159
+ byEmail[person.email.toLowerCase()] = {
160
+ name: typeof person.name === 'string' && person.name ? person.name : null,
161
+ avatar_url: typeof person.avatar_url === 'string' && person.avatar_url ? person.avatar_url : null,
162
+ };
163
+ }
164
+ return { byEmail: byEmail };
165
+ }
166
+
167
+ function describePerson(email, names, callerEmail) {
168
+ const found = names.byEmail[email];
169
+ return {
170
+ email: email,
171
+ name: found ? found.name : null,
172
+ avatar_url: found ? found.avatar_url : null,
173
+ external: emailDomain(email) !== emailDomain(callerEmail),
174
+ };
175
+ }
176
+
177
+ // The caller for these routes: a Phoenix bearer and nothing else. Published
178
+ // pages run on this origin, so the browser's __share cookie (or a ticket it
179
+ // redeems) would let any page's script list a visitor's pages and add itself
180
+ // to them. The CLI and the console proxy both send the bearer.
181
+ async function peopleCaller(request, env) {
182
+ const identity = phoenixIdentity(await hooks.verifyPhoenixToken(request, env));
183
+ if (!identity) return { error: peopleJson({ error: 'unauthorized' }, 401) };
184
+ return { identity: identity };
185
+ }
186
+
187
+ async function handlePeopleRoute(request, env, url, path) {
188
+ const isRead = request.method === 'GET' || request.method === 'HEAD';
189
+ if (path === '__lookup' || path === '__mine' || path === '__shared') {
190
+ if (!isRead) return peopleJson({ error: 'method not allowed' }, 405);
191
+ const caller = await peopleCaller(request, env);
192
+ if (caller.error) return caller.error;
193
+ if (path === '__lookup') return lookupPerson(env, url, caller.identity);
194
+ if (path === '__mine') return listMine(env, url, caller.identity);
195
+ return listShared(env, url, caller.identity);
196
+ }
197
+ if (!isRead && request.method !== 'PUT') return peopleJson({ error: 'method not allowed' }, 405);
198
+ const key = path.slice('__people/'.length);
199
+ const segments = key.split('/');
200
+ const notFound = peopleJson({ error: 'not found' }, 404);
201
+ if (segments.length !== 2 || !segments[0] || !segments[1] || segments[0].startsWith('__') || key.endsWith('.png')) return notFound;
202
+ const caller = await peopleCaller(request, env);
203
+ if (caller.error) return caller.error;
204
+ const identity = caller.identity;
205
+ // The same authority PATCH visibility uses: the namespace's handle claim.
206
+ const auth = { kind: 'phoenix', owner: identity.userId, email: identity.email || '', name: identity.name || '' };
207
+ if (await assertNamespaceOwner(env, auth, segments)) return notFound;
208
+ const page = await env.BUCKET.head(key);
209
+ if (!page || isExpiredObject(page) || isMediaDerived(page)) return notFound;
210
+ if (request.method === 'PUT') return replacePeople(request, env, url, key, auth);
211
+
212
+ let record;
213
+ try {
214
+ record = await readPeopleRecord(env, key);
215
+ } catch (error) {
216
+ return accessCheckUnavailable();
217
+ }
218
+ const meta = page.customMetadata || {};
219
+ const names = await lookupPeopleNames(env, record.people);
220
+ const body = {
221
+ visibility: meta.visibility || 'public',
222
+ org_domain: meta.org_domain || null,
223
+ people: record.people.map(function (email) { return describePerson(email, names, auth.email); }),
224
+ version: record.version,
225
+ };
226
+ if (names.error) body.names_error = 'names_unavailable';
227
+ return peopleJson(body, 200);
228
+ }
229
+
230
+ async function replacePeople(request, env, url, key, auth) {
231
+ const read = await readBodyBounded(request, PEOPLE_BODY_MAX_BYTES);
232
+ if (read.oversize) return peopleJson({ error: 'too_many_people' }, 400);
233
+ let input;
234
+ try {
235
+ input = JSON.parse(new TextDecoder().decode(read.bytes) || '{}');
236
+ } catch {
237
+ return peopleJson({ error: 'invalid_request' }, 400);
238
+ }
239
+ if (!input || typeof input !== 'object' || !Array.isArray(input.people)) return peopleJson({ error: 'invalid_request' }, 400);
240
+ if (input.notify !== undefined && typeof input.notify !== 'boolean') return peopleJson({ error: 'invalid_request' }, 400);
241
+ const notify = input.notify !== false;
242
+ const next = [];
243
+ for (const raw of input.people) {
244
+ const email = normalizePersonEmail(raw);
245
+ if (!email) return peopleJson({ error: 'invalid_email', email: typeof raw === 'string' ? raw.slice(0, 254) : null }, 400);
246
+ if (next.indexOf(email) === -1) next.push(email);
247
+ }
248
+ if (next.length > PEOPLE_MAX) return peopleJson({ error: 'too_many_people', max: PEOPLE_MAX }, 400);
249
+ const ownerEmail = String(auth.email || '').toLowerCase();
250
+ if (ownerEmail && next.indexOf(ownerEmail) !== -1) return peopleJson({ error: 'owner_in_list' }, 400);
251
+ // The whole list is replaced, so a write must name the version it was based
252
+ // on: a client holding an old read cannot silently drop someone.
253
+ const basedOn = ifMatchVersion(request);
254
+ if (basedOn === null) return peopleJson({ error: 'people_version_required' }, 428);
255
+
256
+ // The page's lock: a delete or a fresh publish at this address cannot land
257
+ // between reading the page and writing its list.
258
+ const holder = 'people:' + crypto.randomUUID();
259
+ if (!(await acquirePathMutationLock(env.BUCKET, key, holder, 'mutation'))) {
260
+ return peopleJson({ error: 'conflict', detail: 'another write is active for this page' }, 409);
261
+ }
262
+ let added;
263
+ let removed;
264
+ let title;
265
+ let version;
266
+ try {
267
+ const page = await env.BUCKET.head(key);
268
+ if (!page || isExpiredObject(page) || isMediaDerived(page)) return peopleJson({ error: 'not found' }, 404);
269
+ const meta = page.customMetadata || {};
270
+ if ((meta.visibility || 'public') === 'private' && next.length) return peopleJson({ error: 'people_need_sign_in' }, 400);
271
+ let current;
272
+ try {
273
+ current = await readPeopleRecord(env, key);
274
+ } catch (error) {
275
+ return accessCheckUnavailable();
276
+ }
277
+ if (current.version !== basedOn) return peopleChanged(current);
278
+ const previous = current.people;
279
+ added = next.filter(function (email) { return previous.indexOf(email) === -1; });
280
+ removed = previous.filter(function (email) { return next.indexOf(email) === -1; });
281
+ title = pageTitle(meta, key);
282
+ if (added.length) {
283
+ const limited = await chargeHourly(env, auth.owner, 'people', PEOPLE_ADDED_PER_HOUR, added.length);
284
+ if (limited) return limited;
285
+ }
286
+ if (!(await pathMutationLockOwned(env.BUCKET, key, holder))) {
287
+ return peopleJson({ error: 'conflict', detail: 'the page lock changed; retry' }, 409);
288
+ }
289
+ // The list first: a removal is in force before any index catches up.
290
+ version = await writePeople(env, key, next, current.version);
291
+ if (version === null) {
292
+ try {
293
+ return peopleChanged(await readPeopleRecord(env, key));
294
+ } catch (error) {
295
+ return accessCheckUnavailable();
296
+ }
297
+ }
298
+ for (const email of removed) await env.BUCKET.delete(inboxKey(email, key));
299
+ // Every listed address gets an inbox entry, not only the added ones, so an
300
+ // entry a failed save never wrote is repaired by the next one. An existing
301
+ // entry keeps its added_at.
302
+ const addedAt = new Date().toISOString();
303
+ for (const email of next) {
304
+ if (added.indexOf(email) === -1 && (await env.BUCKET.head(inboxKey(email, key)))) continue;
305
+ await env.BUCKET.put(inboxKey(email, key), '', {
306
+ customMetadata: { owner_email: ownerEmail, owner_name: collabDisplayName({ name: auth.name, email: ownerEmail, userId: auth.owner }), title: title, added_at: addedAt },
307
+ });
308
+ }
309
+ // A generated cover was rendered for the old audience; drop it the way a
310
+ // visibility change does.
311
+ if (added.length || removed.length) {
312
+ const cover = await env.BUCKET.head(key + '.png');
313
+ if (cover && cover.customMetadata && cover.customMetadata['og-generated'] === 'true') await env.BUCKET.delete(key + '.png');
314
+ }
315
+ } finally {
316
+ await releasePathMutationLock(env.BUCKET, key, holder);
317
+ }
318
+
319
+ const body = { people: next, version: version, added: added, removed: removed, notified: [] };
320
+ if (notify && added.length) {
321
+ const outcome = await sendInvites(env, url, key, title, auth, added);
322
+ body.notified = outcome.sent;
323
+ if (outcome.unsent.length) {
324
+ body.notify_error = 'email_unavailable';
325
+ body.notify_failed = outcome.unsent;
326
+ }
327
+ }
328
+ return peopleJson(body, 200);
329
+ }
330
+
331
+ // Email the newly added addresses a link. The owner's name and address are the
332
+ // verified identity's, never anything the request carried. Rush answers
333
+ // {sent, failed (permanent), retryable}; anything not in sent is unsent. A
334
+ // transport failure or 5xx is retried once with the same Idempotency-Key, so
335
+ // Rush never sends a second copy of an invitation it already sent.
336
+ async function sendInvites(env, url, key, title, auth, recipients) {
337
+ const collab = collabConfig(env);
338
+ if (!collab) return { sent: [], unsent: recipients };
339
+ const ownerEmail = String(auth.email || '').toLowerCase();
340
+ const payload = {
341
+ url: url.origin + '/' + key,
342
+ title: title,
343
+ owner_name: collabDisplayName({ name: auth.name, email: ownerEmail, userId: auth.owner }),
344
+ owner_email: ownerEmail,
345
+ recipients: recipients,
346
+ };
347
+ const idempotencyKey = 'invite:' + crypto.randomUUID();
348
+ let result = await collabRegistryCall(collab, 'POST', '/invites', collabShareId(url, key), payload, idempotencyKey);
349
+ if (result.error && (!result.status || result.status >= 500)) {
350
+ result = await collabRegistryCall(collab, 'POST', '/invites', collabShareId(url, key), payload, idempotencyKey);
351
+ }
352
+ const answered = !result.error && result.body && Array.isArray(result.body.sent) ? result.body.sent : [];
353
+ const sent = recipients.filter(function (email) { return answered.indexOf(email) !== -1; });
354
+ return { sent: sent, unsent: recipients.filter(function (email) { return sent.indexOf(email) === -1; }) };
355
+ }
356
+
357
+ async function lookupPerson(env, url, identity) {
358
+ const email = normalizePersonEmail(url.searchParams.get('email') || '');
359
+ if (!email) return peopleJson({ error: 'invalid_email' }, 400);
360
+ const limited = await chargeHourly(env, identity.userId, 'lookup', PEOPLE_LOOKUPS_PER_HOUR, 1);
361
+ if (limited) return limited;
362
+ const names = await lookupPeopleNames(env, [email]);
363
+ const body = describePerson(email, names, identity.email);
364
+ if (names.error) body.names_error = 'names_unavailable';
365
+ return peopleJson(body, 200);
366
+ }
367
+
368
+ // Opaque paging position: the handle being listed and the last key returned.
369
+ function encodePeopleCursor(position) {
370
+ return toB64Url(JSON.stringify(position));
371
+ }
372
+
373
+ function decodePeopleCursor(raw) {
374
+ if (!raw) return { h: '', a: '' };
375
+ try {
376
+ const parsed = JSON.parse(fromB64Url(raw));
377
+ if (parsed && typeof parsed.h === 'string' && typeof parsed.a === 'string') return parsed;
378
+ } catch {
379
+ // not one of ours
380
+ }
381
+ return null;
382
+ }
383
+
384
+ // The handles whose claim the caller holds: the per-user index claimHandle
385
+ // keeps, plus the caller's derived handle for a claim written before the index.
386
+ async function ownedHandles(env, identity) {
387
+ const prefix = handleIndexPrefix(identity.userId);
388
+ const list = await env.BUCKET.list({ prefix: prefix, limit: PEOPLE_MINE_MAX_HANDLES });
389
+ const handles = (list.objects || []).map(function (o) { return o.key.slice(prefix.length); });
390
+ const derived = handleFromEmail(identity.email);
391
+ if (derived && handles.indexOf(derived) === -1 && (await holdsHandleClaim(env.BUCKET, derived, identity.userId))) handles.push(derived);
392
+ return handles.sort();
393
+ }
394
+
395
+ // One page of the live pages under the caller's handles, in key order.
396
+ async function listMine(env, url, identity) {
397
+ const position = decodePeopleCursor(url.searchParams.get('cursor'));
398
+ if (!position) return peopleJson({ error: 'invalid_cursor' }, 400);
399
+ const limited = await chargeHourly(env, identity.userId, 'mine', PEOPLE_MINE_PER_HOUR, 1);
400
+ if (limited) return limited;
401
+ const handles = await ownedHandles(env, identity);
402
+ let index = position.h ? handles.indexOf(position.h) : 0;
403
+ if (index === -1) return peopleJson({ pages: [], next_cursor: null }, 200);
404
+ const handle = handles[index];
405
+ if (!handle) return peopleJson({ pages: [], next_cursor: null }, 200);
406
+ // The delimiter leaves out retained revisions (<handle>/<slug>/rev-*).
407
+ const listing = await env.BUCKET.list({
408
+ prefix: handle + '/', delimiter: '/', limit: PEOPLE_PAGE_SIZE, include: ['httpMetadata', 'customMetadata'],
409
+ ...(position.a ? { startAfter: position.a } : {}),
410
+ });
411
+ const objects = listing.objects || [];
412
+ const last = objects.length ? objects[objects.length - 1].key : '';
413
+ const sidecars = {};
414
+ if (objects.length) {
415
+ const listed = await env.BUCKET.list({ prefix: peopleKey(handle + '/'), limit: 1000, ...(position.a ? { startAfter: peopleKey(position.a) } : {}) });
416
+ for (const sidecar of listed.objects || []) {
417
+ const path = sidecar.key.slice('__people/'.length);
418
+ if (path <= last) sidecars[path] = true;
419
+ }
420
+ }
421
+ const pages = [];
422
+ for (const o of objects) {
423
+ if (o.key.endsWith('.png') || isMediaDerived(o) || isExpiredObject(o)) continue;
424
+ const meta = o.customMetadata || {};
425
+ let people = [];
426
+ if (sidecars[o.key]) {
427
+ try {
428
+ people = await readPeople(env, o.key);
429
+ } catch (error) {
430
+ return accessCheckUnavailable();
431
+ }
432
+ }
433
+ pages.push({
434
+ url: url.origin + '/' + o.key,
435
+ path: o.key,
436
+ title: pageTitle(meta, o.key),
437
+ visibility: meta.visibility || 'public',
438
+ org_domain: meta.org_domain || null,
439
+ kind: pageKind(o.httpMetadata && o.httpMetadata.contentType),
440
+ size: typeof o.size === 'number' ? o.size : 0,
441
+ uploaded: new Date(publishedAtOf(o)).toISOString(),
442
+ people: people,
443
+ });
444
+ }
445
+ let next = null;
446
+ if (listing.truncated && last) next = { h: handle, a: last };
447
+ else if (index + 1 < handles.length) next = { h: handles[index + 1], a: '' };
448
+ return peopleJson({ pages: pages, next_cursor: next ? encodePeopleCursor(next) : null }, 200);
449
+ }
450
+
451
+ // One page of the caller's inbox, keeping only pages they can open because of
452
+ // the list right now: a live me or org page whose list still names them. The
453
+ // inbox is an index, never an authority, so a stale entry is skipped here and
454
+ // left for the owner's next save or the page's delete to clear.
455
+ async function listShared(env, url, identity) {
456
+ const position = decodePeopleCursor(url.searchParams.get('cursor'));
457
+ if (!position) return peopleJson({ error: 'invalid_cursor' }, 400);
458
+ const email = normalizePersonEmail(identity.email || '');
459
+ if (!email) return peopleJson({ pages: [], next_cursor: null }, 200);
460
+ const prefix = inboxKey(email, '');
461
+ const listing = await env.BUCKET.list({ prefix: prefix, limit: PEOPLE_PAGE_SIZE, include: ['customMetadata'], ...(position.a ? { startAfter: prefix + position.a } : {}) });
462
+ const entries = listing.objects || [];
463
+ const pages = [];
464
+ for (const entry of entries) {
465
+ const path = entry.key.slice(prefix.length);
466
+ const page = await env.BUCKET.head(path);
467
+ const pageMeta = (page && page.customMetadata) || {};
468
+ if (!page || isExpiredObject(page) || !isIdentityGated(pageMeta.visibility || 'public')) continue;
469
+ let people;
470
+ try {
471
+ people = await readPeople(env, path);
472
+ } catch (error) {
473
+ return accessCheckUnavailable();
474
+ }
475
+ if (people.indexOf(email) === -1) continue;
476
+ const meta = entry.customMetadata || {};
477
+ pages.push({
478
+ url: url.origin + '/' + path,
479
+ path: path,
480
+ title: pageTitle(pageMeta, path),
481
+ kind: pageKind(page.httpMetadata && page.httpMetadata.contentType),
482
+ owner_email: meta.owner_email || null,
483
+ owner_name: meta.owner_name || null,
484
+ added_at: meta.added_at || null,
485
+ });
486
+ }
487
+ const last = entries.length ? entries[entries.length - 1].key.slice(prefix.length) : '';
488
+ return peopleJson({ pages: pages, next_cursor: listing.truncated && last ? encodePeopleCursor({ h: '', a: last }) : null }, 200);
489
+ }
490
+ `;
491
+ //# sourceMappingURL=worker-people-template.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"worker-people-template.js","sourceRoot":"","sources":["../../../src/lib/share/worker-people-template.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,+DAA+D;AAC/D,EAAE;AACF,mFAAmF;AACnF,6EAA6E;AAC7E,+EAA+E;AAC/E,wEAAwE;AACxE,uEAAuE;AACvE,8EAA8E;AAC9E,+EAA+E;AAC/E,sEAAsE;AACtE,EAAE;AACF,0CAA0C;AAC1C,gFAAgF;AAChF,2EAA2E;AAC3E,8EAA8E;AAC9E,4EAA4E;AAC5E,4DAA4D;AAC5D,8EAA8E;AAC9E,wEAAwE;AACxE,EAAE;AACF,2EAA2E;AAC3E,gEAAgE;AAChE,MAAM,CAAC,MAAM,0BAA0B,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkdzC,CAAC"}