@yadsh/dsh-qa-integrations 0.6.0 → 0.7.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.
Files changed (83) hide show
  1. package/README.md +309 -288
  2. package/lib/broker.js +12 -0
  3. package/lib/broker.js.map +1 -1
  4. package/lib/client/bitrix24.js +66 -5
  5. package/lib/client/bitrix24.js.map +1 -1
  6. package/lib/client/confluence.js +97 -129
  7. package/lib/client/confluence.js.map +1 -1
  8. package/lib/client/gitlab.js +1 -1
  9. package/lib/client/gitlab.js.map +1 -1
  10. package/lib/client/index.js +25 -5
  11. package/lib/client/index.js.map +1 -1
  12. package/lib/client/integrations.js +1 -1
  13. package/lib/client/integrations.js.map +1 -1
  14. package/lib/client/jira.js +95 -127
  15. package/lib/client/jira.js.map +1 -1
  16. package/lib/client/operator-card.js +537 -0
  17. package/lib/client/operator-card.js.map +1 -0
  18. package/lib/client/operator-controls.js +232 -0
  19. package/lib/client/operator-controls.js.map +1 -0
  20. package/lib/client/styles.js +60 -0
  21. package/lib/client/styles.js.map +1 -1
  22. package/lib/client/testit.js +39 -3
  23. package/lib/client/testit.js.map +1 -1
  24. package/lib/client/weblate.js +38 -3
  25. package/lib/client/weblate.js.map +1 -1
  26. package/lib/client.js +2825 -785
  27. package/lib/client.js.map +1 -1
  28. package/lib/index.js +192 -51
  29. package/lib/index.js.map +1 -1
  30. package/lib/providers/bitrix24/catalog.js +138 -8
  31. package/lib/providers/bitrix24/catalog.js.map +1 -1
  32. package/lib/providers/bitrix24/config.js +85 -14
  33. package/lib/providers/bitrix24/config.js.map +1 -1
  34. package/lib/providers/bitrix24/index.js +113 -0
  35. package/lib/providers/bitrix24/index.js.map +1 -1
  36. package/lib/providers/confluence/catalog.js +51 -3
  37. package/lib/providers/confluence/catalog.js.map +1 -1
  38. package/lib/providers/confluence/index.js +293 -35
  39. package/lib/providers/confluence/index.js.map +1 -1
  40. package/lib/providers/confluence/operations.js +1 -1
  41. package/lib/providers/confluence/operations.js.map +1 -1
  42. package/lib/providers/jira/catalog.js +73 -3
  43. package/lib/providers/jira/catalog.js.map +1 -1
  44. package/lib/providers/jira/index.js +266 -12
  45. package/lib/providers/jira/index.js.map +1 -1
  46. package/lib/providers/testit/catalog.js +77 -0
  47. package/lib/providers/testit/catalog.js.map +1 -1
  48. package/lib/providers/testit/index.js +277 -3
  49. package/lib/providers/testit/index.js.map +1 -1
  50. package/lib/providers/weblate/catalog.js +103 -9
  51. package/lib/providers/weblate/catalog.js.map +1 -1
  52. package/lib/providers/weblate/index.js +243 -5
  53. package/lib/providers/weblate/index.js.map +1 -1
  54. package/lib/shared/settings.js +14 -0
  55. package/lib/shared/settings.js.map +1 -0
  56. package/lib/typert.host.js +148 -56
  57. package/lib/typert.remote-client.d.ts +13 -11
  58. package/lib/typert.remote-client.js +89 -50
  59. package/lib/types/broker.d.ts +11 -3
  60. package/lib/types/client/bitrix24.d.ts +24 -2
  61. package/lib/types/client/confluence.d.ts +19 -3
  62. package/lib/types/client/index.d.ts +7 -6
  63. package/lib/types/client/integrations.d.ts +2 -2
  64. package/lib/types/client/jira.d.ts +20 -3
  65. package/lib/types/client/operator-card.d.ts +22 -0
  66. package/lib/types/client/operator-controls.d.ts +135 -0
  67. package/lib/types/client/testit.d.ts +14 -1
  68. package/lib/types/client/weblate.d.ts +14 -1
  69. package/lib/types/index.d.ts +81 -13
  70. package/lib/types/providers/bitrix24/catalog.d.ts +8 -0
  71. package/lib/types/providers/bitrix24/config.d.ts +14 -23
  72. package/lib/types/providers/bitrix24/index.d.ts +36 -1
  73. package/lib/types/providers/confluence/catalog.d.ts +11 -3
  74. package/lib/types/providers/confluence/index.d.ts +61 -7
  75. package/lib/types/providers/confluence/operations.d.ts +2 -0
  76. package/lib/types/providers/jira/catalog.d.ts +13 -0
  77. package/lib/types/providers/jira/index.d.ts +48 -1
  78. package/lib/types/providers/testit/catalog.d.ts +12 -0
  79. package/lib/types/providers/testit/index.d.ts +61 -2
  80. package/lib/types/providers/weblate/catalog.d.ts +19 -2
  81. package/lib/types/providers/weblate/index.d.ts +43 -1
  82. package/lib/types/shared/settings.d.ts +14 -0
  83. package/package.json +4 -4
@@ -42,11 +42,42 @@ export const CONFLUENCE_CAPABILITIES = Object.freeze([
42
42
  hint: "История версий: номер, автор, дата и комментарий к версии",
43
43
  },
44
44
  ]);
45
+ /**
46
+ * A read of the connected identity alone: no resource, nothing personal.
47
+ */
48
+ const IDENTITY_READ = {
49
+ effect: "read",
50
+ sensitivity: "normal",
51
+ serviceCredential: "allow",
52
+ requiresResourceBoundary: false,
53
+ };
54
+ /**
55
+ * A read whose answer belongs to a space. `requiresResourceBoundary` makes the
56
+ * broker prove the profile bounds spaces at all, and the provider holds the
57
+ * call inside the boundary — which is what a service account needs, because it
58
+ * can see far more than the user it stands in for.
59
+ *
60
+ * This is also the ceiling of what this catalog contains. Every read answers
61
+ * authored Confluence content or its metadata; the one read that would return
62
+ * arbitrary uploaded bytes — an attachment body download — does not exist here.
63
+ * Should a write or a byte-returning read ever be added, it must be classified
64
+ * on purpose: an unclassified operation is unreachable through the managed
65
+ * credential, which is the fail-closed default.
66
+ */
67
+ const SPACE_READ = {
68
+ effect: "read",
69
+ sensitivity: "normal",
70
+ serviceCredential: "allow",
71
+ requiresResourceBoundary: true,
72
+ };
73
+ /** The resource kind every space-scoped operation of this provider is bounded by. */
74
+ export const CONFLUENCE_RESOURCE_KIND = "spaces";
45
75
  /**
46
76
  * Every model-reachable operation. The provider refuses any operation that is
47
- * not listed here, so this table — together with `capability` — is the
48
- * permission surface. Only GET: the catalog carries no operation that could
49
- * change Confluence state, and the confirmation framework does not exist yet.
77
+ * not listed here, so this table — together with `capability` and `security`
78
+ * — is the permission surface. Only GET: the catalog carries no operation that
79
+ * could change Confluence state, and the confirmation framework does not exist
80
+ * yet.
50
81
  *
51
82
  * The mix of REST versions is deliberate. Confluence Cloud v2 covers pages,
52
83
  * comments, attachments, versions and spaces, and that is where the reads go;
@@ -62,6 +93,7 @@ export const CONFLUENCE_OPERATIONS = Object.freeze({
62
93
  capability: "identity.read",
63
94
  method: "GET",
64
95
  path: "/wiki/rest/api/user/current",
96
+ security: IDENTITY_READ,
65
97
  },
66
98
  /** CQL search: the only read Confluence offers for free-text lookup. */
67
99
  "search.run": {
@@ -70,6 +102,7 @@ export const CONFLUENCE_OPERATIONS = Object.freeze({
70
102
  path: "/wiki/rest/api/search",
71
103
  list: true,
72
104
  cursor: "offset",
105
+ security: SPACE_READ,
73
106
  },
74
107
  "spaces.list": {
75
108
  capability: "spaces.read",
@@ -77,6 +110,7 @@ export const CONFLUENCE_OPERATIONS = Object.freeze({
77
110
  path: "/wiki/api/v2/spaces",
78
111
  list: true,
79
112
  cursor: "upstream",
113
+ security: SPACE_READ,
80
114
  },
81
115
  /**
82
116
  * v2 addresses a space by numeric id only; a key is resolved through
@@ -86,11 +120,13 @@ export const CONFLUENCE_OPERATIONS = Object.freeze({
86
120
  capability: "spaces.read",
87
121
  method: "GET",
88
122
  path: "/wiki/api/v2/spaces/:spaceId",
123
+ security: SPACE_READ,
89
124
  },
90
125
  "pages.get": {
91
126
  capability: "content.read",
92
127
  method: "GET",
93
128
  path: "/wiki/api/v2/pages/:pageId",
129
+ security: SPACE_READ,
94
130
  },
95
131
  /**
96
132
  * The catalog names the footer collection; inline comments live at the same
@@ -103,13 +139,20 @@ export const CONFLUENCE_OPERATIONS = Object.freeze({
103
139
  path: "/wiki/api/v2/pages/:pageId/footer-comments",
104
140
  list: true,
105
141
  cursor: "upstream",
142
+ security: SPACE_READ,
106
143
  },
144
+ /**
145
+ * Attachment metadata only: a name, a size, a download link. The bytes are
146
+ * never fetched — a read that returned arbitrary uploaded content would be a
147
+ * different classification entirely.
148
+ */
107
149
  "pages.attachments": {
108
150
  capability: "attachments.read",
109
151
  method: "GET",
110
152
  path: "/wiki/api/v2/pages/:pageId/attachments",
111
153
  list: true,
112
154
  cursor: "upstream",
155
+ security: SPACE_READ,
113
156
  },
114
157
  "pages.versions": {
115
158
  capability: "versions.read",
@@ -117,6 +160,7 @@ export const CONFLUENCE_OPERATIONS = Object.freeze({
117
160
  path: "/wiki/api/v2/pages/:pageId/versions",
118
161
  list: true,
119
162
  cursor: "upstream",
163
+ security: SPACE_READ,
120
164
  },
121
165
  });
122
166
  /** Capabilities this deployment allows, in catalog order. */
@@ -132,4 +176,8 @@ export const CONFLUENCE_CAPABILITY_INFO = Object.freeze(Object.fromEntries(CONFL
132
176
  export function confluenceOperationCapability(operation) {
133
177
  return CONFLUENCE_OPERATIONS[operation]?.capability;
134
178
  }
179
+ /** Security classification of an operation, or undefined when it is unknown. */
180
+ export function confluenceOperationMetadata(operation) {
181
+ return CONFLUENCE_OPERATIONS[operation]?.security;
182
+ }
135
183
  //# sourceMappingURL=catalog.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"catalog.js","sourceRoot":"","sources":["../../../src/providers/confluence/catalog.ts"],"names":[],"mappings":"AA4CA,MAAM,CAAC,MAAM,uBAAuB,GAClC,MAAM,CAAC,MAAM,CAAC;IACZ;QACE,UAAU,EAAE,eAAe;QAC3B,IAAI,EAAE,cAAc;QACpB,KAAK,EAAE,cAAc;QACrB,IAAI,EAAE,oEAAoE;KAC3E;IACD;QACE,UAAU,EAAE,aAAa;QACzB,IAAI,EAAE,YAAY;QAClB,KAAK,EAAE,qBAAqB;QAC5B,IAAI,EAAE,0DAA0D;KACjE;IACD;QACE,UAAU,EAAE,aAAa;QACzB,IAAI,EAAE,YAAY;QAClB,KAAK,EAAE,sBAAsB;QAC7B,IAAI,EAAE,yFAAyF;KAChG;IACD;QACE,UAAU,EAAE,cAAc;QAC1B,IAAI,EAAE,aAAa;QACnB,KAAK,EAAE,iBAAiB;QACxB,IAAI,EAAE,oFAAoF;KAC3F;IACD;QACE,UAAU,EAAE,eAAe;QAC3B,IAAI,EAAE,cAAc;QACpB,KAAK,EAAE,oBAAoB;QAC3B,IAAI,EAAE,sEAAsE;KAC7E;IACD;QACE,UAAU,EAAE,kBAAkB;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EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CACnE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,UAAU,CAC1B,CAAC;AACJ,CAAC;AAED,8EAA8E;AAC9E,MAAM,CAAC,MAAM,0BAA0B,GAEnC,MAAM,CAAC,MAAM,CACf,MAAM,CAAC,WAAW,CAChB,uBAAuB,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC;IACpC,IAAI,CAAC,UAAU;IACf,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE;CACvC,CAAC,CACwD,CAC7D,CAAC;AAEF,6EAA6E;AAC7E,MAAM,UAAU,6BAA6B,CAC3C,SAAiB;IAEjB,OAAO,qBAAqB,CAAC,SAAS,CAAC,EAAE,UAAU,CAAC;AACtD,CAAC;AAED,gFAAgF;AAChF,MAAM,UAAU,2BAA2B,CACzC,SAAiB;IAEjB,OAAO,qBAAqB,CAAC,SAAS,CAAC,EAAE,QAAQ,CAAC;AACpD,CAAC"}
@@ -1,10 +1,12 @@
1
1
  import { resolveCredentialHelp, } from "@yadsh/dsh-plugin-kit";
2
2
  import { IntegrationError } from "../../errors.js";
3
- import { CONFLUENCE_CAPABILITY_INFO, CONFLUENCE_OPERATIONS, enabledCapabilities, confluenceOperationCapability, } from "./catalog.js";
3
+ import { operationCapabilityServiceState } from "../../service-credentials/state.js";
4
+ import { assertServiceOperationAllowed, serviceBoundaryOf, serviceResourceDenied, } from "../shared/service-boundary.js";
5
+ import { CONFLUENCE_CAPABILITY_INFO, CONFLUENCE_OPERATIONS, CONFLUENCE_RESOURCE_KIND, confluenceOperationCapability, confluenceOperationMetadata, enabledCapabilities, } from "./catalog.js";
4
6
  import { CONFLUENCE_CREDENTIAL_HELP } from "./credential-help.js";
5
7
  import { credentialFromPlaintext, credentialInstance, ConfluenceTransport, } from "./transport.js";
6
- import { CONFLUENCE_HANDLERS, CONFLUENCE_PROJECTIONS, bodyLimit, commentChildrenPath, commentCollections, commentKind, commentPath, commentReplies, confluenceSource, numericId, offsetCursor, pageLimit, } from "./operations.js";
7
- import { spaceAllowed, } from "./config.js";
8
+ import { CONFLUENCE_HANDLERS, CONFLUENCE_PROJECTIONS, SPACE_TYPES, bodyLimit, commentChildrenPath, commentCollections, commentKind, commentPath, commentReplies, confluenceSource, isNumericSpace, numericId, offsetCursor, pageLimit, spaceKeys, spaceRef, } from "./operations.js";
9
+ import { confluenceInstance, spaceAllowed, } from "./config.js";
8
10
  export { credentialFromPlaintext, credentialInstance, } from "./transport.js";
9
11
  /**
10
12
  * Atlassian API tokens are long opaque strings, sometimes prefixed. A pasted
@@ -14,6 +16,33 @@ export { credentialFromPlaintext, credentialInstance, } from "./transport.js";
14
16
  const TOKEN_SHAPE = /^[A-Za-z0-9._=+/-]{16,512}$/u;
15
17
  /** The Atlassian account the token belongs to; the pair is what authenticates. */
16
18
  const EMAIL_SHAPE = /^[^\s@]{1,64}@[^\s@.]+(?:\.[^\s@.]+)+$/u;
19
+ /**
20
+ * The `email:token` pair of a deployment-managed secret. Atlassian
21
+ * authenticates HTTP Basic over exactly this string, so it is the form the
22
+ * operator keeps in the secret file or the environment — one record, because
23
+ * the pair must not be assembled from two. The connect form never produces it:
24
+ * it collects the e-mail next to the token, and a pasted pair stays refused.
25
+ */
26
+ function splitBasicPair(raw) {
27
+ const at = raw.indexOf(":");
28
+ if (at <= 0)
29
+ return undefined;
30
+ const email = raw.slice(0, at);
31
+ if (!EMAIL_SHAPE.test(email))
32
+ return undefined;
33
+ return { email, token: raw.slice(at + 1) };
34
+ }
35
+ /**
36
+ * How many space keys one CQL `space in (...)` clause can carry. A service
37
+ * boundary wider than this cannot be asked for in one search, and a silently
38
+ * truncated one would answer with a lie by omission.
39
+ */
40
+ const SEARCH_SPACE_CAP = 20;
41
+ /** Page-addressed reads whose answer carries no space of its own to check. */
42
+ const PAGE_ADDRESSED = Object.freeze([
43
+ "pages.attachments",
44
+ "pages.versions",
45
+ ]);
17
46
  function accountName(data) {
18
47
  for (const key of ["displayName", "publicName", "email"]) {
19
48
  const value = data[key];
@@ -25,6 +54,21 @@ function accountName(data) {
25
54
  function textOf(value) {
26
55
  return typeof value === "string" && value !== "" ? value : undefined;
27
56
  }
57
+ /**
58
+ * Whether one space key stays inside the deployment's boundary. The profile's
59
+ * `resources.spaces` lists space keys — the same vocabulary the deployment's
60
+ * own allowlist and the CQL speak — and keys are compared case-insensitively,
61
+ * because operator config, the v2 API and CQL spell the same key in different
62
+ * cases.
63
+ */
64
+ export function spaceInBoundary(boundary, key) {
65
+ if (key === undefined)
66
+ return false;
67
+ const normalized = key.trim().toUpperCase();
68
+ if (normalized === "")
69
+ return false;
70
+ return (boundary[CONFLUENCE_RESOURCE_KIND] ?? []).some((entry) => entry.trim().toUpperCase() === normalized);
71
+ }
28
72
  /** Confluence provider: operator-configured sites over an Atlassian API token. */
29
73
  export class ConfluenceProvider {
30
74
  config;
@@ -57,14 +101,20 @@ export class ConfluenceProvider {
57
101
  * from operator config, never from a tool argument, which is what keeps the
58
102
  * broker from dialling any host the caller names or authenticating as any
59
103
  * account the caller names.
104
+ *
105
+ * A deployment-managed secret cannot travel with a connect form, so it
106
+ * arrives as the Basic pair Atlassian documents (`email:token`). The two
107
+ * forms can never be confused: an API token contains neither `@` nor `:`.
60
108
  */
61
109
  parseCredential(raw, options) {
62
- const token = raw.trim();
110
+ const provided = raw.trim();
111
+ const pair = options?.["email"] === undefined ? splitBasicPair(provided) : undefined;
112
+ const token = pair === undefined ? provided : pair.token;
63
113
  if (!TOKEN_SHAPE.test(token)) {
64
114
  throw new IntegrationError("InvalidCredential", "Use an Atlassian API token");
65
115
  }
66
- const email = (options?.["email"] ?? "").trim();
67
- if (!EMAIL_SHAPE.test(email)) {
116
+ const email = (pair === undefined ? options?.["email"] : pair.email)?.trim();
117
+ if (email === undefined || !EMAIL_SHAPE.test(email)) {
68
118
  throw new IntegrationError("InvalidCredential", "Use the e-mail of the Atlassian account the token belongs to");
69
119
  }
70
120
  const instance = this.resolveInstance(options?.["instanceId"]);
@@ -80,6 +130,32 @@ export class ConfluenceProvider {
80
130
  operationCapability(operation) {
81
131
  return confluenceOperationCapability(operation);
82
132
  }
133
+ operationMetadata(operation) {
134
+ return confluenceOperationMetadata(operation);
135
+ }
136
+ /** Every space-scoped read is bounded by the profile's space keys. */
137
+ resourceBoundaryKind(operation) {
138
+ return CONFLUENCE_OPERATIONS[operation]?.security
139
+ .requiresResourceBoundary === true
140
+ ? CONFLUENCE_RESOURCE_KIND
141
+ : undefined;
142
+ }
143
+ /**
144
+ * Portal of a configured site. An empty id means "the only site", the same
145
+ * rule `parseCredential` applies, so deployment configuration and the
146
+ * connect form name sites alike.
147
+ */
148
+ instancePortal(instanceId) {
149
+ const instances = this.config.confluence.instances;
150
+ const id = instanceId.trim();
151
+ if (id === "") {
152
+ return instances.length === 1 ? instances[0]?.baseUrl : undefined;
153
+ }
154
+ return confluenceInstance(this.config.confluence, id)?.baseUrl;
155
+ }
156
+ capabilityServiceState(capability) {
157
+ return operationCapabilityServiceState(CONFLUENCE_OPERATIONS, capability);
158
+ }
83
159
  async validate(context) {
84
160
  const credential = credentialFromPlaintext(context.credential);
85
161
  const instance = credentialInstance(this.config.confluence, credential);
@@ -99,6 +175,36 @@ export class ConfluenceProvider {
99
175
  capabilities: this.capabilities,
100
176
  };
101
177
  }
178
+ /**
179
+ * Health of a deployment-managed token. The probe reads only the identity
180
+ * endpoint the personal validation reads, so it never changes upstream state;
181
+ * Confluence exposes no token-scope introspection, so the answer is healthy
182
+ * with a warning — the local service ceiling stays the whole local boundary.
183
+ */
184
+ async validateServiceCredential(context) {
185
+ const credential = credentialFromPlaintext(context.credential);
186
+ const instance = credentialInstance(this.config.confluence, credential);
187
+ let data;
188
+ try {
189
+ const response = await this.transport.getJson(instance, credential, "/wiki/rest/api/user/current");
190
+ data = response.data;
191
+ }
192
+ catch (error) {
193
+ return healthFromFailure(error);
194
+ }
195
+ const id = textOf(data["accountId"]) ??
196
+ textOf(data["userKey"]) ??
197
+ textOf(data["username"]);
198
+ return {
199
+ status: "healthy",
200
+ ...(id === undefined
201
+ ? {}
202
+ : { upstreamIdentity: { id, label: accountName(data) } }),
203
+ warnings: [
204
+ "Confluence did not report the token scopes; the local service ceiling still applies",
205
+ ],
206
+ };
207
+ }
102
208
  async execute(context, operation, input) {
103
209
  const credential = credentialFromPlaintext(context.credential);
104
210
  const instance = credentialInstance(this.config.confluence, credential);
@@ -111,35 +217,65 @@ export class ConfluenceProvider {
111
217
  throw new IntegrationError("InvalidRequest", "Unsupported Confluence operation");
112
218
  }
113
219
  const flags = this.config.confluence;
114
- const request = handler(input, {
220
+ // Ceiling first, then the boundary: what the operation is decides before
221
+ // where it may read.
222
+ if (context.credentialSource === "service") {
223
+ assertServiceOperationAllowed(definition.security, "This Confluence operation is not available through the service credential");
224
+ }
225
+ const boundary = serviceBoundaryOf(context);
226
+ if (boundary !== undefined && operation === "spaces.list") {
227
+ return this.listBoundedSpaces(instance, credential, boundary, input, flags);
228
+ }
229
+ if (boundary !== undefined && PAGE_ADDRESSED.includes(operation)) {
230
+ // These answers carry no space of their own, so the page's space is
231
+ // resolved first and verified before anything is fetched for the answer.
232
+ // Comments resolve their page inside their own read, a page read inside
233
+ // its own.
234
+ await this.assertPageReachable(instance, credential, numericId(input["pageId"], "pageId"), flags, boundary);
235
+ }
236
+ if (boundary !== undefined && operation === "spaces.get") {
237
+ const ref = spaceRef(input["space"]);
238
+ // A key is refused without a call; a numeric id is resolved to its key
239
+ // by the read itself, which verifies before anything is returned.
240
+ if (!isNumericSpace(ref) && !spaceInBoundary(boundary, ref)) {
241
+ throw serviceResourceDenied();
242
+ }
243
+ }
244
+ // In service mode a search is narrowed to the boundary before the handler
245
+ // builds the CQL, so the restriction travels upstream.
246
+ const prepared = boundary !== undefined && operation === "search.run"
247
+ ? this.boundedSearchInput(input, boundary, flags)
248
+ : input;
249
+ const request = handler(prepared, {
115
250
  externalUserId: context.externalUserId,
116
251
  flags,
117
252
  });
118
253
  if (operation === "pages.get") {
119
- return this.readPage(instance, credential, request, flags, input);
254
+ return this.readPage(instance, credential, request, flags, prepared, boundary);
120
255
  }
121
256
  if (operation === "pages.comments") {
122
- return this.readComments(instance, credential, request, flags, input);
257
+ return this.readComments(instance, credential, request, flags, prepared, boundary);
123
258
  }
124
259
  if (operation === "spaces.get") {
125
- return this.readSpace(instance, credential, request, flags);
260
+ return this.readSpace(instance, credential, request, flags, boundary);
126
261
  }
127
- return this.readList(instance, credential, request, operation, definition.cursor, flags, input);
262
+ return this.readList(instance, credential, request, operation, definition.cursor, flags, prepared, boundary);
128
263
  }
129
264
  /** One list read, with its cursor and with the space policy re-applied. */
130
- async readList(instance, credential, request, operation, cursorMode, flags, input) {
265
+ async readList(instance, credential, request, operation, cursorMode, flags, input, boundary) {
131
266
  const projection = CONFLUENCE_PROJECTIONS[operation];
132
267
  const response = await this.transport.getJson(instance, credential, request.path, request.query);
133
268
  const answer = projection?.(response.data, {
134
269
  ...this.projectionContext(flags, instance, input),
135
270
  start: cursorMode === "offset" ? offsetCursor(input["cursor"]) : undefined,
136
271
  }) ?? { source: {} };
137
- // The CQL already restricts the search to allowed spaces, and the space
138
- // listing asks for them by key. This filter is the second lock: a row whose
139
- // space cannot be read as an allowed key is dropped rather than shown.
140
- if (operation === "search.run" && flags.allowedSpaces.length > 0) {
272
+ // The CQL already restricts the search to allowed spaces — and, in service
273
+ // mode, to the boundary. This filter is the second lock: a row whose space
274
+ // cannot be read as an allowed key is dropped rather than shown.
275
+ if (operation === "search.run" &&
276
+ (flags.allowedSpaces.length > 0 || boundary !== undefined)) {
141
277
  const items = Array.isArray(answer["items"]) ? answer["items"] : [];
142
- answer["items"] = items.filter((item) => this.itemSpaceAllowed(item, flags));
278
+ answer["items"] = items.filter((item) => this.itemSpaceReachable(item, flags, boundary));
143
279
  }
144
280
  const nextCursor = cursorMode === "upstream" ? response.page?.nextCursor : undefined;
145
281
  return nextCursor === undefined ? answer : { ...answer, nextCursor };
@@ -147,16 +283,17 @@ export class ConfluenceProvider {
147
283
  /**
148
284
  * A page read is answered with the page's space, because that is what the
149
285
  * operator allowlist is written in — and a page whose space the policy does
150
- * not allow is refused here, after the read and before the model sees it.
286
+ * not allow is refused here, after the read and before the model sees it. In
287
+ * service mode the boundary is verified on the same resolved space.
151
288
  */
152
- async readPage(instance, credential, request, flags, input) {
289
+ async readPage(instance, credential, request, flags, input, boundary) {
153
290
  const projection = CONFLUENCE_PROJECTIONS["pages.get"];
154
291
  const response = await this.transport.getJson(instance, credential, request.path, request.query);
155
292
  const spaceId = textOf(response.data["spaceId"]);
156
293
  const space = spaceId === undefined
157
294
  ? {}
158
295
  : await this.readSpaceFields(instance, credential, spaceId);
159
- this.assertSpaceAllowed(flags, textOf(space["key"]));
296
+ this.assertSpaceReachable(flags, textOf(space["key"]), boundary);
160
297
  return (projection?.(response.data, {
161
298
  ...this.projectionContext(flags, instance, input),
162
299
  space,
@@ -168,12 +305,12 @@ export class ConfluenceProvider {
168
305
  * cost one request per parent comment, so a discussion wider than the
169
306
  * deployment cap is answered with the parents it did load and says so.
170
307
  */
171
- async readComments(instance, credential, request, flags, input) {
308
+ async readComments(instance, credential, request, flags, input, boundary) {
172
309
  const projection = CONFLUENCE_PROJECTIONS["pages.comments"];
173
310
  const pageId = numericId(input["pageId"], "pageId");
174
311
  const kind = commentKind(input["kind"]);
175
- if (flags.allowedSpaces.length > 0) {
176
- await this.assertPageAllowedBySpace(instance, credential, pageId, flags);
312
+ if (flags.allowedSpaces.length > 0 || boundary !== undefined) {
313
+ await this.assertPageReachable(instance, credential, pageId, flags, boundary);
177
314
  }
178
315
  const includeReplies = typeof input["includeReplies"] === "boolean" && input["includeReplies"];
179
316
  const collections = commentCollections(kind);
@@ -237,7 +374,7 @@ export class ConfluenceProvider {
237
374
  return { items, truncated: rows.length > cap };
238
375
  }
239
376
  /** One space, by id or by the key the listing endpoint resolves. */
240
- async readSpace(instance, credential, request, flags) {
377
+ async readSpace(instance, credential, request, flags, boundary) {
241
378
  const projection = CONFLUENCE_PROJECTIONS["spaces.get"];
242
379
  const response = await this.transport.getJson(instance, credential, request.path, request.query);
243
380
  const answer = projection?.(response.data, {
@@ -246,11 +383,96 @@ export class ConfluenceProvider {
246
383
  bodyLimit: bodyLimit(undefined, flags),
247
384
  }) ?? {};
248
385
  const space = answer["space"];
249
- this.assertSpaceAllowed(flags, typeof space === "object" && space !== null
386
+ this.assertSpaceReachable(flags, typeof space === "object" && space !== null
250
387
  ? textOf(space["key"])
251
- : undefined);
388
+ : undefined, boundary);
252
389
  return answer;
253
390
  }
391
+ /**
392
+ * A service search is narrowed to the boundary before the handler builds the
393
+ * CQL: an offset-paginated search whose out-of-boundary rows were dropped
394
+ * afterwards would answer pages that shrink and cursors that lose their
395
+ * place. A space the caller names outside the boundary is refused rather
396
+ * than dropped, and the filter in `readList` stays as the second lock.
397
+ */
398
+ boundedSearchInput(input, boundary, flags) {
399
+ const requested = spaceKeys(input["spaces"], "spaces");
400
+ for (const key of requested) {
401
+ if (!spaceInBoundary(boundary, key)) {
402
+ throw serviceResourceDenied();
403
+ }
404
+ }
405
+ if (requested.length > 0)
406
+ return input;
407
+ // Without spaces the caller named, the search asks for the boundary itself
408
+ // — still narrowed by the deployment allowlist, which binds the agent
409
+ // whatever credential it spends.
410
+ const allowlist = flags.allowedSpaces;
411
+ const spaces = (boundary[CONFLUENCE_RESOURCE_KIND] ?? [])
412
+ .map((key) => key.trim().toUpperCase())
413
+ .filter((key) => allowlist.length === 0 || allowlist.includes(key));
414
+ // An empty intersection means the two administrator lists disagree; a list
415
+ // wider than one CQL clause cannot be asked for at all. Both refuse rather
416
+ // than answer with an unbounded or silently truncated search.
417
+ if (spaces.length === 0 || spaces.length > SEARCH_SPACE_CAP) {
418
+ throw serviceResourceDenied();
419
+ }
420
+ return { ...input, spaces };
421
+ }
422
+ /**
423
+ * The bounded space listing. A service profile names the spaces it covers,
424
+ * so the listing is built from that list instead of from whatever the shared
425
+ * account can reach; a space the service token cannot see is reported as
426
+ * unavailable rather than silently dropped. The answer does not page: its
427
+ * size is the boundary the administrator defined, not upstream's.
428
+ */
429
+ async listBoundedSpaces(instance, credential, boundary, input, flags) {
430
+ const requested = spaceKeys(input["keys"], "keys");
431
+ for (const key of requested) {
432
+ if (!spaceInBoundary(boundary, key)) {
433
+ throw serviceResourceDenied();
434
+ }
435
+ }
436
+ const allowlist = flags.allowedSpaces;
437
+ const entries = (boundary[CONFLUENCE_RESOURCE_KIND] ?? []).filter((key) => {
438
+ const normalized = key.trim().toUpperCase();
439
+ return ((requested.length === 0 || requested.includes(normalized)) &&
440
+ (allowlist.length === 0 || allowlist.includes(normalized)));
441
+ });
442
+ if (entries.length === 0) {
443
+ throw serviceResourceDenied();
444
+ }
445
+ const type = textOf(input["type"]);
446
+ if (type !== undefined && !SPACE_TYPES.includes(type)) {
447
+ throw new IntegrationError("InvalidRequest", "type is invalid");
448
+ }
449
+ const projection = CONFLUENCE_PROJECTIONS["spaces.list"];
450
+ const items = [];
451
+ const unavailable = [];
452
+ for (const key of entries) {
453
+ try {
454
+ const { data } = await this.transport.getJson(instance, credential, "/wiki/api/v2/spaces", { keys: key, limit: 2, "description-format": "plain", type });
455
+ const projected = projection?.(data, { flags, instance }) ?? {};
456
+ const rows = Array.isArray(projected["items"])
457
+ ? projected["items"]
458
+ : [];
459
+ items.push(...rows);
460
+ }
461
+ catch (error) {
462
+ if (!recoverableResource(error))
463
+ throw error;
464
+ unavailable.push(key);
465
+ }
466
+ }
467
+ return {
468
+ source: confluenceSource(instance),
469
+ items,
470
+ serviceScoped: true,
471
+ ...(unavailable.length === 0
472
+ ? {}
473
+ : { unavailableResources: unavailable }),
474
+ };
475
+ }
254
476
  /** The fields a space contributes to a page answer, plus its policy key. */
255
477
  async readSpaceFields(instance, credential, spaceId) {
256
478
  const { data } = await this.transport.getJson(instance, credential,
@@ -259,18 +481,30 @@ export class ConfluenceProvider {
259
481
  return data;
260
482
  }
261
483
  /**
262
- * The space of a page the call is about. Only asked for when the deployment
263
- * narrowed spaces: without an allowlist there is no policy to enforce, and
264
- * the extra read would be spent for nothing.
484
+ * The space of a page the call is about. Asked for whenever a policy needs
485
+ * it: the deployment allowlist, or — in service mode — the boundary, which is
486
+ * always there. Without either there is no policy to enforce, and the extra
487
+ * reads would be spent for nothing.
265
488
  */
266
- async assertPageAllowedBySpace(instance, credential, pageId, flags) {
489
+ async assertPageReachable(instance, credential, pageId, flags, boundary) {
267
490
  const { data } = await this.transport.getJson(instance, credential, `/wiki/api/v2/pages/${pageId}`, {});
268
491
  const spaceId = textOf(data["spaceId"]);
269
492
  if (spaceId === undefined) {
270
493
  throw new IntegrationError("ResourceNotFound", "Confluence page not found");
271
494
  }
272
495
  const space = await this.readSpaceFields(instance, credential, spaceId);
273
- this.assertSpaceAllowed(flags, textOf(space["key"]));
496
+ this.assertSpaceReachable(flags, textOf(space["key"]), boundary);
497
+ }
498
+ /**
499
+ * Both space policies of one read, in the order a refusal should name them:
500
+ * the deployment allowlist first, the service boundary — when the call runs
501
+ * on the managed credential — second.
502
+ */
503
+ assertSpaceReachable(flags, key, boundary) {
504
+ this.assertSpaceAllowed(flags, key);
505
+ if (boundary !== undefined && !spaceInBoundary(boundary, key)) {
506
+ throw serviceResourceDenied();
507
+ }
274
508
  }
275
509
  /**
276
510
  * A space outside the operator allowlist is refused as a policy decision, not
@@ -283,16 +517,19 @@ export class ConfluenceProvider {
283
517
  throw new IntegrationError("OperationDeniedByPolicy", "Space is outside the allowlist of this deployment");
284
518
  }
285
519
  /** The space of one search row, as the projection resolved it. */
286
- itemSpaceAllowed(item, flags) {
520
+ itemSpaceReachable(item, flags, boundary) {
287
521
  const space = typeof item === "object" && item !== null
288
522
  ? item["space"]
289
523
  : undefined;
290
524
  const key = typeof space === "object" && space !== null
291
525
  ? textOf(space["key"])
292
526
  : undefined;
293
- // An empty allowlist never reaches here; a row whose space is unreadable
294
- // fails closed, so a listing can only show what this policy proves.
295
- return flags.allowedSpaces.length > 0 && spaceAllowed(flags, key);
527
+ // A row whose space is unreadable fails closed, so a listing can only show
528
+ // what a policy proves: the deployment allowlist, or — in service mode —
529
+ // the boundary as well.
530
+ if (!spaceAllowed(flags, key))
531
+ return false;
532
+ return boundary === undefined || spaceInBoundary(boundary, key);
296
533
  }
297
534
  projectionContext(flags, instance, input) {
298
535
  return {
@@ -324,5 +561,26 @@ export class ConfluenceProvider {
324
561
  return only;
325
562
  }
326
563
  }
564
+ /** A missing or forbidden space inside a boundary is reported, not fatal. */
565
+ function recoverableResource(error) {
566
+ return (error instanceof IntegrationError &&
567
+ (error.code === "ResourceNotFound" ||
568
+ error.code === "ProviderPermissionDenied"));
569
+ }
570
+ /** Map an upstream failure of the probe onto a health status. */
571
+ function healthFromFailure(error) {
572
+ if (!(error instanceof IntegrationError)) {
573
+ return { status: "unreachable" };
574
+ }
575
+ switch (error.code) {
576
+ case "CredentialExpired":
577
+ return { status: "expired" };
578
+ case "CredentialRevoked":
579
+ case "ProviderPermissionDenied":
580
+ return { status: "revoked" };
581
+ default:
582
+ return { status: "unreachable" };
583
+ }
584
+ }
327
585
  export default ConfluenceProvider;
328
586
  //# sourceMappingURL=index.js.map