@estiva-app/interop 0.98.0 → 0.99.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@estiva-app/interop",
3
- "version": "0.98.0",
3
+ "version": "0.99.0",
4
4
  "description": "Render and act on another app's objects from its published NIP-89 manifest. The owner defines the projection; the consumer decides how it looks.",
5
5
  "license": "MIT",
6
6
  "type": "module",
package/src/folders.ts CHANGED
@@ -117,8 +117,8 @@ export function planCreateFolder(
117
117
  * Rename a Folder: `[kind:9002]`, and nothing else.
118
118
  *
119
119
  * The title is the channel's name (§3.2), so the channel is the only home to
120
- * write. The relay refuses it to anybody but the channel's owners and admins.
121
- * A name left on an older state by a command is never shown.
120
+ * write. The relay refuses it to anybody but the channel's owners and admins
121
+ * (and, on a team with no owner, the workspace's). A name left on an older state by a command is never shown.
122
122
  */
123
123
  export function planRenameFolder(
124
124
  pubkey: string,
@@ -221,8 +221,9 @@ export function planUnlistFile(
221
221
  * unlist a file from somewhere a person would have to remember.
222
222
  *
223
223
  * **Always in the Folder's own `h`**, and readers count it only from an owner
224
- * or admin on the Folder's `kind:39001` (§3.2) — the people who may rename it.
225
- * So offer Archive only to them (`FolderSummary.admins`): from anybody else the
224
+ * or admin on the Folder's `kind:39001` — or, on a team with no owner, from an
225
+ * owner or admin of the workspace (§3.2) — the people who may rename it. So
226
+ * offer Archive only to them (`FolderSummary.admins`): from anybody else the
226
227
  * relay accepts the event and every reader ignores it.
227
228
  *
228
229
  * `resolution` is what the person archiving said about it, carried as the
package/src/projection.ts CHANGED
@@ -2521,7 +2521,8 @@ export function isArchived(file: { archived?: Archive } | null | undefined): boo
2521
2521
  *
2522
2522
  * **A Folder is the exception** (SPEC §3.2): on a `kind:39000` address only a
2523
2523
  * change in the Folder's own `h` by one of `folderAdmins` — the owners and
2524
- * admins on its relay-signed `kind:39001` — counts. A caller that has not read
2524
+ * admins on its relay-signed `kind:39001`, and on a team with no owner the
2525
+ * workspace's owners and admins — counts. A caller that has not read
2525
2526
  * the admin list passes none, and then no change counts: a Folder shown live
2526
2527
  * when it is archived is recoverable, one any member could hide is not.
2527
2528
  */
@@ -6746,10 +6747,55 @@ function folderAdminsOf(admins: SignedEvent | undefined, channel: SignedEvent |
6746
6747
  ]
6747
6748
  }
6748
6749
 
6750
+ /** NIP-43's relay membership list: the workspace's roster, one `member` tag per key, with its role. */
6751
+ const KIND_RELAY_MEMBERS = 13534
6752
+
6753
+ /** The relay's roster, as a filter to add to a request that already reads a team's records. */
6754
+ const RELAY_MEMBERS_FILTER = { kinds: [KIND_RELAY_MEMBERS], limit: 1 }
6755
+
6756
+ /**
6757
+ * The workspace's owners and admins: the `member` tags whose role is `owner`
6758
+ * or `admin` on the newest `kind:13534` signed by `relay` (the key that signed
6759
+ * the team's `kind:39000`). A roster anybody else signed means nothing.
6760
+ */
6761
+ function workspaceAdminsOf(events: readonly SignedEvent[], relay: string): string[] {
6762
+ const roster = events
6763
+ .filter((event) => event.kind === KIND_RELAY_MEMBERS && event.pubkey === relay)
6764
+ .sort((a, b) => b.created_at - a.created_at || a.id.localeCompare(b.id))[0]
6765
+ if (!roster) return []
6766
+ return roster.tags
6767
+ .filter((tag) => tag[0] === 'member' && tag[1] && FOLDER_ADMIN_ROLES.has(tag[2] ?? ''))
6768
+ .map((tag) => tag[1])
6769
+ }
6770
+
6771
+ /**
6772
+ * Who may rename and archive a team: the owners and admins its relay-signed
6773
+ * `kind:39001` lists, and, when that list names no `owner`, the workspace's
6774
+ * owners and admins on the relay-signed roster as well. A team with no 39001 at
6775
+ * all is not taken as one with no owner: nothing says who is on it. Only a
6776
+ * team (`isTeam`: it holds a `kind:30890`) is looked after this way; a DM or
6777
+ * another conversation space, whose list names no owner either, never is.
6778
+ *
6779
+ * why: https://github.com/estiva-app/estiva-docs/blob/main/decisions/a-team-with-no-owner-is-looked-after-by-the-workspaces-admins.md
6780
+ */
6781
+ function teamStewardsOf(
6782
+ admins: SignedEvent | undefined,
6783
+ channel: SignedEvent | undefined,
6784
+ events: readonly SignedEvent[],
6785
+ isTeam: boolean,
6786
+ ): string[] {
6787
+ const own = folderAdminsOf(admins, channel)
6788
+ if (!isTeam || !admins || !channel || admins.pubkey !== channel.pubkey) return own
6789
+ if (channel.tags.some((tag) => tag[0] === 't' && tag[1] === 'dm')) return own
6790
+ const hasOwner = admins.tags.some((tag) => tag[0] === 'p' && tag[1] && tag.slice(2).includes('owner'))
6791
+ return hasOwner ? own : [...new Set([...own, ...workspaceAdminsOf(events, channel.pubkey)])]
6792
+ }
6793
+
6749
6794
  /**
6750
6795
  * A Folder's own archive (SPEC §3.2): the `archived` changes on its channel's
6751
- * address, counting only one carrying the Folder's own `h` whose author the
6752
- * relay lists as its owner or admin. From anybody else the relay accepts the
6796
+ * address, counting only one carrying the Folder's own `h` whose author is in
6797
+ * its {@link FolderSummary.admins} (its owners and admins, and on a team with
6798
+ * no owner the workspace's too). From anybody else the relay accepts the
6753
6799
  * change, and it means nothing.
6754
6800
  */
6755
6801
  function folderArchiveOf(changes: SignedEvent[], folder: Pick<FolderSummary, 'id' | 'channel' | 'admins'>): Archive | undefined {
@@ -6792,8 +6838,12 @@ export interface FolderSummary {
6792
6838
  company?: true
6793
6839
  /**
6794
6840
  * Who may rename and archive it: the owners and admins on its relay-signed
6795
- * `kind:39001`. Offer Archive only to them — a reader ignores an archive from
6796
- * anybody else (§3.2). Absent when the relay returned no admin list.
6841
+ * `kind:39001` and, on a team whose 39001 lists no owner, the workspace's
6842
+ * owners and admins on the relay-signed roster (`kind:13534`) too. Offer
6843
+ * Archive only to them — a reader ignores an archive from anybody else
6844
+ * (§3.2). Absent when the relay returned no admin list.
6845
+ *
6846
+ * why: https://github.com/estiva-app/estiva-docs/blob/main/decisions/a-team-with-no-owner-is-looked-after-by-the-workspaces-admins.md
6797
6847
  */
6798
6848
  admins?: string[]
6799
6849
  /**
@@ -6905,7 +6955,8 @@ export interface FolderContents extends FolderSummary {
6905
6955
  *
6906
6956
  * Both shapes in one pass: folders the relay maintains state for, and bare
6907
6957
  * channels that have none yet. A channel with state appears once, titled by its
6908
- * `kind:39000` (SPEC §3.2), with the owners and admins its `kind:39001` lists.
6958
+ * `kind:39000` (SPEC §3.2), with who may rename and archive it
6959
+ * ({@link FolderSummary.admins}).
6909
6960
  *
6910
6961
  * **A direct route, deliberately.** §4.2's post-mortem on REW-11 is that
6911
6962
  * discovering children only through their parent loses them when the parent
@@ -7014,6 +7065,8 @@ async function readFolderRecords(query: QueryFn): Promise<{ events: SignedEvent[
7014
7065
  { kinds: [KIND_FOLDER_STATE], limit: 500 },
7015
7066
  { kinds: [KIND_CHANNEL], limit: 500 },
7016
7067
  { kinds: [KIND_CHANNEL_ADMINS], limit: 500 },
7068
+ // Who looks after a team with no owner (FolderSummary.admins). Same request.
7069
+ RELAY_MEMBERS_FILTER,
7017
7070
  ])
7018
7071
  const byId = new Map<string, FolderSummary>()
7019
7072
  const channelOf = new Map<string, SignedEvent>()
@@ -7044,7 +7097,7 @@ async function readFolderRecords(query: QueryFn): Promise<{ events: SignedEvent[
7044
7097
  if (name !== undefined) folder.name = name
7045
7098
  if (channel.tags.some((tag) => tag[0] === 'private')) folder.private = true
7046
7099
  if (channel.tags.some((tag) => tag[0] === 'company')) folder.company = true
7047
- const admins = folderAdminsOf(adminsOf.get(id), channel)
7100
+ const admins = teamStewardsOf(adminsOf.get(id), channel, events, folder.hasState)
7048
7101
  if (admins.length) folder.admins = admins
7049
7102
  folder.channel = pointerToAddress({ kind: KIND_CHANNEL, pubkey: channel.pubkey, identifier: id, relays: [] })
7050
7103
  }
@@ -7480,12 +7533,17 @@ export async function resolveFolderContents(
7480
7533
  { kinds: [KIND_FOLDER_STATE], '#d': [folder], limit: 1 },
7481
7534
  { kinds: [KIND_CHANNEL], '#d': [folder], limit: 1 },
7482
7535
  { kinds: [KIND_CHANNEL_ADMINS], '#d': [folder], limit: 1 },
7536
+ // Who looks after it, and every team it lists, when one has no owner. Same request.
7537
+ RELAY_MEMBERS_FILTER,
7483
7538
  ])
7484
7539
  const state = identity.find((e) => e.kind === KIND_FOLDER_STATE && tagValue(e, 'd') === folder)
7485
7540
  const channel = identity.find((e) => e.kind === KIND_CHANNEL && tagValue(e, 'd') === folder)
7486
- const admins = folderAdminsOf(
7541
+ const roster = identity.filter((e) => e.kind === KIND_RELAY_MEMBERS)
7542
+ const admins = teamStewardsOf(
7487
7543
  identity.find((e) => e.kind === KIND_CHANNEL_ADMINS && tagValue(e, 'd') === folder),
7488
7544
  channel,
7545
+ roster,
7546
+ state !== undefined,
7489
7547
  )
7490
7548
  const channelAddress = channel
7491
7549
  ? pointerToAddress({ kind: KIND_CHANNEL, pubkey: channel.pubkey, identifier: folder, relays: [] })
@@ -7599,7 +7657,7 @@ export async function resolveFolderContents(
7599
7657
  // Every change, in groups small enough that a busy Folder's changes cannot
7600
7658
  // push one file's off the page — one Folder has already had 688. Same request.
7601
7659
  ...archiveFilters(channelAddress ? [...changesAsked, channelAddress] : changesAsked),
7602
- // A Folder listed here counts its archive only from its own admins (§3.2). Same request.
7660
+ // A Folder listed here counts its archive only from who looks after it (§3.2). Same request.
7603
7661
  ...(nestedFolderIds.length ? [{ kinds: [KIND_CHANNEL_ADMINS], '#d': nestedFolderIds, limit: nestedFolderIds.length }] : []),
7604
7662
  ], query),
7605
7663
  queryChunked(rootFilters.filter((filter) => 'fields' in filter), query),
@@ -7642,9 +7700,12 @@ export async function resolveFolderContents(
7642
7700
  const nestedAdmins =
7643
7701
  pointer.kind === KIND_CHANNEL
7644
7702
  ? new Set(
7645
- folderAdminsOf(
7703
+ teamStewardsOf(
7646
7704
  events.find((e) => e.kind === KIND_CHANNEL_ADMINS && tagValue(e, 'd') === pointer.identifier),
7647
7705
  root,
7706
+ roster,
7707
+ // A team listed in this one; a DM listed here is still never looked after.
7708
+ true,
7648
7709
  ),
7649
7710
  )
7650
7711
  : undefined