@modesto_ma/dsh-channels 0.4.0 → 0.5.0-beta.2

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 (66) hide show
  1. package/README.md +83 -57
  2. package/docs/access-control-design.md +8 -5
  3. package/docs/attachment-pipeline-v2.md +33 -41
  4. package/docs/feishu-onboarding.md +36 -33
  5. package/docs/persistence.md +6 -4
  6. package/docs/refactor-plan.md +1 -1
  7. package/docs/workspace-isolation-design.md +7 -8
  8. package/lib/client.js +444 -288
  9. package/lib/client.js.map +1 -1
  10. package/lib/index.js +9017 -6794
  11. package/lib/index.js.map +1 -1
  12. package/package.json +1 -1
  13. package/src/access/cards.ts +9 -9
  14. package/src/access/controller.ts +10 -10
  15. package/src/access/index.ts +1 -0
  16. package/src/access/policy.ts +10 -10
  17. package/src/access/requests.ts +32 -31
  18. package/src/access/store.ts +43 -13
  19. package/src/access/targets.ts +56 -0
  20. package/src/cards/approval.ts +96 -26
  21. package/src/cards/index.ts +1 -0
  22. package/src/cards/onboarding.ts +1 -0
  23. package/src/cards/picker.ts +108 -0
  24. package/src/cards/streaming.ts +56 -7
  25. package/src/cards/wiki.ts +124 -0
  26. package/src/client/api.ts +5 -25
  27. package/src/client/panel/access-card.tsx +24 -15
  28. package/src/client/panel/access-tab.tsx +3 -3
  29. package/src/client/panel/connection-tab.tsx +70 -1
  30. package/src/client/panel/index.tsx +11 -62
  31. package/src/client/panel/shared.tsx +96 -24
  32. package/src/client/panel/workspace-tab.tsx +2 -18
  33. package/src/client/string-list.ts +139 -0
  34. package/src/client/styles.ts +5 -0
  35. package/src/commands/registry.ts +8 -5
  36. package/src/config.ts +55 -54
  37. package/src/domain.ts +36 -123
  38. package/src/feishu/delivery.ts +34 -1
  39. package/src/feishu/inbound-attachments.ts +1 -1
  40. package/src/feishu/manifest.ts +8 -31
  41. package/src/feishu/message-read.ts +97 -24
  42. package/src/feishu/scopes.ts +194 -0
  43. package/src/feishu/send-file.ts +543 -0
  44. package/src/feishu/slash-commands.ts +134 -0
  45. package/src/feishu/tools.ts +72 -112
  46. package/src/feishu/wiki/api.ts +346 -0
  47. package/src/feishu/wiki/consent.ts +183 -0
  48. package/src/feishu/wiki/links.ts +122 -0
  49. package/src/feishu/wiki/scope.ts +66 -0
  50. package/src/feishu/wiki/tools.ts +984 -0
  51. package/src/feishu-channel.ts +280 -9
  52. package/src/index.ts +5 -4
  53. package/src/interactions/approvals.ts +187 -7
  54. package/src/interactions/pending.ts +3 -3
  55. package/src/routing/inbound.ts +73 -106
  56. package/src/service.ts +545 -440
  57. package/src/session/manager.ts +1 -1
  58. package/src/session/routes.ts +2 -3
  59. package/src/settings/contract.ts +110 -89
  60. package/src/settings/routes.ts +3 -17
  61. package/src/settings/surface.ts +144 -94
  62. package/src/streamer.ts +94 -5
  63. package/src/workspaces.ts +21 -29
  64. package/src/cleanup.ts +0 -546
  65. package/src/client/panel/cleanup-card.tsx +0 -106
  66. package/src/feishu/pending-attachments.ts +0 -562
@@ -0,0 +1,66 @@
1
+ /**
2
+ * `wikiRoots` containment: decides whether a wiki node lies inside one of the
3
+ * configured roots before any wiki tool touches it.
4
+ *
5
+ * A space root contains every node of that space. A node root contains
6
+ * itself and its descendants; descent is checked by walking the node's
7
+ * parent chain with `spaces/get_node`, bounded by {@link MAX_PARENT_DEPTH}.
8
+ * A node whose chain cannot be read is treated as outside (fail closed).
9
+ *
10
+ * @module dsh-channels/feishu/wiki/scope
11
+ */
12
+
13
+ import type { WikiApi, WikiNode } from './api.ts'
14
+ import type { WikiRoot } from './links.ts'
15
+
16
+ /**
17
+ * Longest parent chain walked for a node root. Feishu limits wiki depth well
18
+ * below this; a longer chain is treated as outside.
19
+ */
20
+ const MAX_PARENT_DEPTH = 64
21
+
22
+ /** The root a node was found under. */
23
+ export interface WikiContainment {
24
+ readonly root: WikiRoot
25
+ }
26
+
27
+ /**
28
+ * Find the configured root containing `node`.
29
+ *
30
+ * @param api Wiki endpoints (for parent lookups).
31
+ * @param roots Configured roots.
32
+ * @param node The node to check.
33
+ * @returns The containing root, or `undefined` when none contains it.
34
+ */
35
+ export async function containingRoot(
36
+ api: WikiApi,
37
+ roots: readonly WikiRoot[],
38
+ node: WikiNode,
39
+ ): Promise<WikiContainment | undefined> {
40
+ for (const root of roots) {
41
+ if (root.kind === 'space' && root.spaceId === node.spaceId) return { root }
42
+ }
43
+ const nodeRoots = roots.filter((root): root is Extract<WikiRoot, { kind: 'node' }> => root.kind === 'node')
44
+ if (nodeRoots.length === 0) return undefined
45
+ const byToken = new Map(nodeRoots.map(root => [root.nodeToken, root]))
46
+ let current: WikiNode = node
47
+ for (let depth = 0; depth <= MAX_PARENT_DEPTH; depth += 1) {
48
+ const match = byToken.get(current.nodeToken)
49
+ if (match !== undefined) return { root: match }
50
+ if (current.parentNodeToken === undefined) return undefined
51
+ current = await api.getNode(current.parentNodeToken, 'wiki')
52
+ }
53
+ return undefined
54
+ }
55
+
56
+ /**
57
+ * Whether a whole space (its top level) is inside the roots: only a space
58
+ * root covers a space's top level.
59
+ *
60
+ * @param roots Configured roots.
61
+ * @param spaceId The space.
62
+ * @returns True when a space root names it.
63
+ */
64
+ export function spaceIsRoot(roots: readonly WikiRoot[], spaceId: string): boolean {
65
+ return roots.some(root => root.kind === 'space' && root.spaceId === spaceId)
66
+ }