@yadsh/dsh-qa-integrations 0.5.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 (212) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +617 -0
  3. package/compatibility.json +10 -0
  4. package/cordis.patch.yml +5 -0
  5. package/lib/broker.js +239 -0
  6. package/lib/broker.js.map +1 -0
  7. package/lib/client/bitrix24.js +33 -0
  8. package/lib/client/bitrix24.js.map +1 -0
  9. package/lib/client/card.js +33 -0
  10. package/lib/client/card.js.map +1 -0
  11. package/lib/client/confluence.js +148 -0
  12. package/lib/client/confluence.js.map +1 -0
  13. package/lib/client/copy.js +18 -0
  14. package/lib/client/copy.js.map +1 -0
  15. package/lib/client/gitlab.js +64 -0
  16. package/lib/client/gitlab.js.map +1 -0
  17. package/lib/client/index.js +71 -0
  18. package/lib/client/index.js.map +1 -0
  19. package/lib/client/integrations.js +34 -0
  20. package/lib/client/integrations.js.map +1 -0
  21. package/lib/client/jira.js +150 -0
  22. package/lib/client/jira.js.map +1 -0
  23. package/lib/client/provider-card.js +143 -0
  24. package/lib/client/provider-card.js.map +1 -0
  25. package/lib/client/styles.js +35 -0
  26. package/lib/client/styles.js.map +1 -0
  27. package/lib/client/teamcity.js +55 -0
  28. package/lib/client/teamcity.js.map +1 -0
  29. package/lib/client.js +8069 -0
  30. package/lib/client.js.map +1 -0
  31. package/lib/coerce.js +69 -0
  32. package/lib/coerce.js.map +1 -0
  33. package/lib/config.js +51 -0
  34. package/lib/config.js.map +1 -0
  35. package/lib/errors.js +14 -0
  36. package/lib/errors.js.map +1 -0
  37. package/lib/index.js +510 -0
  38. package/lib/index.js.map +1 -0
  39. package/lib/providers/bitrix24/catalog.js +245 -0
  40. package/lib/providers/bitrix24/catalog.js.map +1 -0
  41. package/lib/providers/bitrix24/config.js +40 -0
  42. package/lib/providers/bitrix24/config.js.map +1 -0
  43. package/lib/providers/bitrix24/index.js +128 -0
  44. package/lib/providers/bitrix24/index.js.map +1 -0
  45. package/lib/providers/bitrix24/operations.js +491 -0
  46. package/lib/providers/bitrix24/operations.js.map +1 -0
  47. package/lib/providers/bitrix24/tools.js +1035 -0
  48. package/lib/providers/bitrix24/tools.js.map +1 -0
  49. package/lib/providers/bitrix24/transport.js +142 -0
  50. package/lib/providers/bitrix24/transport.js.map +1 -0
  51. package/lib/providers/confluence/adf.js +348 -0
  52. package/lib/providers/confluence/adf.js.map +1 -0
  53. package/lib/providers/confluence/catalog.js +135 -0
  54. package/lib/providers/confluence/catalog.js.map +1 -0
  55. package/lib/providers/confluence/config.js +196 -0
  56. package/lib/providers/confluence/config.js.map +1 -0
  57. package/lib/providers/confluence/cql.js +78 -0
  58. package/lib/providers/confluence/cql.js.map +1 -0
  59. package/lib/providers/confluence/index.js +319 -0
  60. package/lib/providers/confluence/index.js.map +1 -0
  61. package/lib/providers/confluence/operations.js +653 -0
  62. package/lib/providers/confluence/operations.js.map +1 -0
  63. package/lib/providers/confluence/tools.js +282 -0
  64. package/lib/providers/confluence/tools.js.map +1 -0
  65. package/lib/providers/confluence/transport.js +247 -0
  66. package/lib/providers/confluence/transport.js.map +1 -0
  67. package/lib/providers/contract.js +2 -0
  68. package/lib/providers/contract.js.map +1 -0
  69. package/lib/providers/gitlab/catalog.js +171 -0
  70. package/lib/providers/gitlab/catalog.js.map +1 -0
  71. package/lib/providers/gitlab/config.js +141 -0
  72. package/lib/providers/gitlab/config.js.map +1 -0
  73. package/lib/providers/gitlab/index.js +227 -0
  74. package/lib/providers/gitlab/index.js.map +1 -0
  75. package/lib/providers/gitlab/operations.js +794 -0
  76. package/lib/providers/gitlab/operations.js.map +1 -0
  77. package/lib/providers/gitlab/tools.js +859 -0
  78. package/lib/providers/gitlab/tools.js.map +1 -0
  79. package/lib/providers/gitlab/transport.js +140 -0
  80. package/lib/providers/gitlab/transport.js.map +1 -0
  81. package/lib/providers/jira/adf.js +235 -0
  82. package/lib/providers/jira/adf.js.map +1 -0
  83. package/lib/providers/jira/catalog.js +145 -0
  84. package/lib/providers/jira/catalog.js.map +1 -0
  85. package/lib/providers/jira/config.js +198 -0
  86. package/lib/providers/jira/config.js.map +1 -0
  87. package/lib/providers/jira/index.js +301 -0
  88. package/lib/providers/jira/index.js.map +1 -0
  89. package/lib/providers/jira/jql.js +299 -0
  90. package/lib/providers/jira/jql.js.map +1 -0
  91. package/lib/providers/jira/operations.js +617 -0
  92. package/lib/providers/jira/operations.js.map +1 -0
  93. package/lib/providers/jira/tools.js +341 -0
  94. package/lib/providers/jira/tools.js.map +1 -0
  95. package/lib/providers/jira/transport.js +227 -0
  96. package/lib/providers/jira/transport.js.map +1 -0
  97. package/lib/providers/registry.js +21 -0
  98. package/lib/providers/registry.js.map +1 -0
  99. package/lib/providers/shared/account.js +20 -0
  100. package/lib/providers/shared/account.js.map +1 -0
  101. package/lib/providers/shared/host.js +15 -0
  102. package/lib/providers/shared/host.js.map +1 -0
  103. package/lib/providers/shared/http.js +148 -0
  104. package/lib/providers/shared/http.js.map +1 -0
  105. package/lib/providers/teamcity/artifacts.js +155 -0
  106. package/lib/providers/teamcity/artifacts.js.map +1 -0
  107. package/lib/providers/teamcity/catalog.js +155 -0
  108. package/lib/providers/teamcity/catalog.js.map +1 -0
  109. package/lib/providers/teamcity/config.js +262 -0
  110. package/lib/providers/teamcity/config.js.map +1 -0
  111. package/lib/providers/teamcity/index.js +228 -0
  112. package/lib/providers/teamcity/index.js.map +1 -0
  113. package/lib/providers/teamcity/locators.js +95 -0
  114. package/lib/providers/teamcity/locators.js.map +1 -0
  115. package/lib/providers/teamcity/logs.js +113 -0
  116. package/lib/providers/teamcity/logs.js.map +1 -0
  117. package/lib/providers/teamcity/network.js +160 -0
  118. package/lib/providers/teamcity/network.js.map +1 -0
  119. package/lib/providers/teamcity/operations.js +625 -0
  120. package/lib/providers/teamcity/operations.js.map +1 -0
  121. package/lib/providers/teamcity/tools.js +480 -0
  122. package/lib/providers/teamcity/tools.js.map +1 -0
  123. package/lib/providers/teamcity/transport.js +126 -0
  124. package/lib/providers/teamcity/transport.js.map +1 -0
  125. package/lib/redaction.js +38 -0
  126. package/lib/redaction.js.map +1 -0
  127. package/lib/repository.js +414 -0
  128. package/lib/repository.js.map +1 -0
  129. package/lib/secrets/key-provider.js +76 -0
  130. package/lib/secrets/key-provider.js.map +1 -0
  131. package/lib/secrets/secret-store.js +93 -0
  132. package/lib/secrets/secret-store.js.map +1 -0
  133. package/lib/shared/settings.js +19 -0
  134. package/lib/shared/settings.js.map +1 -0
  135. package/lib/tool-kit.js +55 -0
  136. package/lib/tool-kit.js.map +1 -0
  137. package/lib/tools.js +28 -0
  138. package/lib/tools.js.map +1 -0
  139. package/lib/typert.host.d.ts +3 -0
  140. package/lib/typert.host.js +1689 -0
  141. package/lib/typert.remote-client.d.ts +84 -0
  142. package/lib/typert.remote-client.js +1429 -0
  143. package/lib/types/broker.d.ts +30 -0
  144. package/lib/types/client/bitrix24.d.ts +18 -0
  145. package/lib/types/client/card.d.ts +13 -0
  146. package/lib/types/client/confluence.d.ts +17 -0
  147. package/lib/types/client/copy.d.ts +7 -0
  148. package/lib/types/client/gitlab.d.ts +15 -0
  149. package/lib/types/client/index.d.ts +13 -0
  150. package/lib/types/client/integrations.d.ts +28 -0
  151. package/lib/types/client/jira.d.ts +17 -0
  152. package/lib/types/client/provider-card.d.ts +63 -0
  153. package/lib/types/client/styles.d.ts +7 -0
  154. package/lib/types/client/teamcity.d.ts +19 -0
  155. package/lib/types/coerce.d.ts +18 -0
  156. package/lib/types/config.d.ts +48 -0
  157. package/lib/types/errors.d.ts +26 -0
  158. package/lib/types/index.d.ts +170 -0
  159. package/lib/types/providers/bitrix24/catalog.d.ts +48 -0
  160. package/lib/types/providers/bitrix24/config.d.ts +43 -0
  161. package/lib/types/providers/bitrix24/index.d.ts +31 -0
  162. package/lib/types/providers/bitrix24/operations.d.ts +13 -0
  163. package/lib/types/providers/bitrix24/tools.d.ts +9 -0
  164. package/lib/types/providers/bitrix24/transport.d.ts +26 -0
  165. package/lib/types/providers/confluence/adf.d.ts +22 -0
  166. package/lib/types/providers/confluence/catalog.d.ts +59 -0
  167. package/lib/types/providers/confluence/config.d.ts +68 -0
  168. package/lib/types/providers/confluence/cql.d.ts +43 -0
  169. package/lib/types/providers/confluence/index.d.ts +73 -0
  170. package/lib/types/providers/confluence/operations.d.ts +92 -0
  171. package/lib/types/providers/confluence/tools.d.ts +15 -0
  172. package/lib/types/providers/confluence/transport.d.ts +77 -0
  173. package/lib/types/providers/contract.d.ts +33 -0
  174. package/lib/types/providers/gitlab/catalog.d.ts +49 -0
  175. package/lib/types/providers/gitlab/config.d.ts +50 -0
  176. package/lib/types/providers/gitlab/index.d.ts +49 -0
  177. package/lib/types/providers/gitlab/operations.d.ts +40 -0
  178. package/lib/types/providers/gitlab/tools.d.ts +15 -0
  179. package/lib/types/providers/gitlab/transport.d.ts +52 -0
  180. package/lib/types/providers/jira/adf.d.ts +27 -0
  181. package/lib/types/providers/jira/catalog.d.ts +74 -0
  182. package/lib/types/providers/jira/config.d.ts +73 -0
  183. package/lib/types/providers/jira/index.d.ts +79 -0
  184. package/lib/types/providers/jira/jql.d.ts +51 -0
  185. package/lib/types/providers/jira/operations.d.ts +58 -0
  186. package/lib/types/providers/jira/tools.d.ts +17 -0
  187. package/lib/types/providers/jira/transport.d.ts +65 -0
  188. package/lib/types/providers/registry.d.ts +9 -0
  189. package/lib/types/providers/shared/account.d.ts +10 -0
  190. package/lib/types/providers/shared/host.d.ts +9 -0
  191. package/lib/types/providers/shared/http.d.ts +51 -0
  192. package/lib/types/providers/teamcity/artifacts.d.ts +45 -0
  193. package/lib/types/providers/teamcity/catalog.d.ts +55 -0
  194. package/lib/types/providers/teamcity/config.d.ts +66 -0
  195. package/lib/types/providers/teamcity/index.d.ts +62 -0
  196. package/lib/types/providers/teamcity/locators.d.ts +47 -0
  197. package/lib/types/providers/teamcity/logs.d.ts +31 -0
  198. package/lib/types/providers/teamcity/network.d.ts +32 -0
  199. package/lib/types/providers/teamcity/operations.d.ts +84 -0
  200. package/lib/types/providers/teamcity/tools.d.ts +15 -0
  201. package/lib/types/providers/teamcity/transport.d.ts +53 -0
  202. package/lib/types/redaction.d.ts +3 -0
  203. package/lib/types/repository.d.ts +48 -0
  204. package/lib/types/secrets/key-provider.d.ts +30 -0
  205. package/lib/types/secrets/secret-store.d.ts +12 -0
  206. package/lib/types/shared/settings.d.ts +19 -0
  207. package/lib/types/tool-kit.d.ts +26 -0
  208. package/lib/types/tools.d.ts +16 -0
  209. package/lib/types/types.d.ts +138 -0
  210. package/lib/types.js +2 -0
  211. package/lib/types.js.map +1 -0
  212. package/package.json +143 -0
@@ -0,0 +1,653 @@
1
+ import { optionalBoolean, optionalInteger, optionalText, requiredDate, requiredStringList, } from "../../coerce.js";
2
+ import { IntegrationError } from "../../errors.js";
3
+ import { adfToText, textBudget } from "./adf.js";
4
+ import { CONTENT_TYPES, ORDER_BY, buildCql, } from "./cql.js";
5
+ /** Confluence page and comment ids are decimal, and only that. */
6
+ const NUMERIC_ID = /^\d{1,20}$/u;
7
+ /** A space key or id, as it travels inside a path segment. */
8
+ const SPACE_REF = /^[A-Za-z0-9][A-Za-z0-9_-]{0,254}$/u;
9
+ /** An opaque cursor Confluence itself handed out; never a URL or a path. */
10
+ const UPSTREAM_CURSOR = /^[A-Za-z0-9+/=_.:-]{1,400}$/u;
11
+ /** Rows one answer asks for when the model names no `limit`. */
12
+ export const DEFAULT_LIMIT = 20;
13
+ /** Deepest offset a search may walk to; search pagination is not a crawl API. */
14
+ const MAX_START = 10_000;
15
+ /** Floor for a requested body budget, so a tiny number is not a silent zero. */
16
+ const MIN_BODY_CHARS = 100;
17
+ function invalid(field) {
18
+ throw new IntegrationError("InvalidRequest", `${field} is invalid`);
19
+ }
20
+ /** A page or comment id, accepted as a number or as its decimal digits. */
21
+ export function numericId(value, field) {
22
+ const text = typeof value === "number" && Number.isInteger(value)
23
+ ? String(value)
24
+ : typeof value === "string"
25
+ ? value.trim()
26
+ : "";
27
+ if (!NUMERIC_ID.test(text))
28
+ invalid(field);
29
+ return text;
30
+ }
31
+ /** A space key or numeric id, as `confluence_get_space` accepts either. */
32
+ export function spaceRef(value, field = "space") {
33
+ const text = typeof value === "string" ? value.trim() : "";
34
+ if (!SPACE_REF.test(text))
35
+ invalid(field);
36
+ return text;
37
+ }
38
+ /** Whether a space reference is the numeric id v2 wants in a path. */
39
+ export function isNumericSpace(value) {
40
+ return NUMERIC_ID.test(value);
41
+ }
42
+ /** Space keys the model named, upper-cased the way CQL and the policy spell them. */
43
+ function spaceKeys(value, field) {
44
+ if (value === undefined)
45
+ return [];
46
+ return requiredStringList(value, field, 20, 255).map((key) => key.toUpperCase());
47
+ }
48
+ /** Content types, validated against what CQL accepts. */
49
+ function contentTypes(value) {
50
+ return requiredStringList(value, "contentTypes", 2, 16).filter((type) => CONTENT_TYPES.includes(type));
51
+ }
52
+ function ordering(value) {
53
+ const text = optionalText(value, "orderBy", 3, 16);
54
+ if (text === undefined)
55
+ return undefined;
56
+ if (text === "relevance")
57
+ return undefined;
58
+ if (text in ORDER_BY)
59
+ return text;
60
+ return invalid("orderBy");
61
+ }
62
+ /**
63
+ * Rows per answer. A `limit` above the deployment cap is clamped rather than
64
+ * refused: the answer says how many rows it carries, so the model can page on
65
+ * without having to guess what this stand allows.
66
+ */
67
+ export function pageLimit(value, flags) {
68
+ const requested = optionalInteger(value, "limit", 1, 100_000);
69
+ return Math.min(requested ?? DEFAULT_LIMIT, flags.maxResults);
70
+ }
71
+ /** Character budget of one body, bounded by the deployment ceiling. */
72
+ export function bodyLimit(value, flags) {
73
+ const requested = optionalInteger(value, "maxChars", MIN_BODY_CHARS, flags.maxBodyChars);
74
+ return requested ?? Math.min(flags.defaultBodyChars, flags.maxBodyChars);
75
+ }
76
+ /**
77
+ * Search pagination is offset-based, so its cursor is the row offset the
78
+ * previous answer ended at. It carries no identity: every call re-resolves the
79
+ * account and the space policy from the session, so an offset cannot reach
80
+ * another user's data.
81
+ */
82
+ export function offsetCursor(value) {
83
+ if (value === undefined)
84
+ return 0;
85
+ const text = typeof value === "number" && Number.isInteger(value)
86
+ ? String(value)
87
+ : typeof value === "string"
88
+ ? value.trim()
89
+ : "";
90
+ if (!NUMERIC_ID.test(text))
91
+ invalid("cursor");
92
+ const offset = Number(text);
93
+ if (!Number.isFinite(offset) || offset > MAX_START)
94
+ invalid("cursor");
95
+ return offset;
96
+ }
97
+ /** v2 pagination is cursor-based; the token is shape-checked before it is spent. */
98
+ export function upstreamCursor(value) {
99
+ const text = optionalText(value, "cursor", 1, 400);
100
+ if (text === undefined)
101
+ return undefined;
102
+ if (!UPSTREAM_CURSOR.test(text))
103
+ invalid("cursor");
104
+ return text;
105
+ }
106
+ /**
107
+ * A relative window, as the search shorthand spells it: `-7d`, `-2w`, `-1m`,
108
+ * `-1y`. The question "what changed this week" is the common one, and an agent
109
+ * whose system prompt carries no clock cannot turn it into a date — so the
110
+ * provider accepts the window and resolves it against its own clock.
111
+ */
112
+ const RELATIVE_WINDOW = /^-(\d{1,4})([dwmy])$/u;
113
+ /** Longest window a shorthand may name, so a typo cannot scan the whole site. */
114
+ const MAX_WINDOW_DAYS = 3_650;
115
+ const MS_PER_DAY = 86_400_000;
116
+ /**
117
+ * The inclusive lower bound on `lastmodified`, either as an absolute date or as
118
+ * a window counted back from today. Resolution happens here, once, so the CQL
119
+ * the provider builds is always an absolute date.
120
+ */
121
+ export function modifiedAfterDate(value, today = new Date()) {
122
+ if (value === undefined)
123
+ return undefined;
124
+ const text = optionalText(value, "modifiedAfter", 3, 10);
125
+ if (text === undefined)
126
+ return undefined;
127
+ const match = RELATIVE_WINDOW.exec(text);
128
+ if (match === null)
129
+ return requiredDate(value, "modifiedAfter");
130
+ const amount = Number(match[1]);
131
+ const unit = match[2];
132
+ if (!Number.isInteger(amount) || amount < 1)
133
+ invalid("modifiedAfter");
134
+ const days = unit === "d"
135
+ ? amount
136
+ : unit === "w"
137
+ ? amount * 7
138
+ : unit === "m"
139
+ ? amount * 30
140
+ : amount * 365;
141
+ if (days > MAX_WINDOW_DAYS)
142
+ invalid("modifiedAfter");
143
+ return new Date(today.getTime() - days * MS_PER_DAY)
144
+ .toISOString()
145
+ .slice(0, 10);
146
+ }
147
+ export const COMMENT_KINDS = Object.freeze([
148
+ "footer",
149
+ "inline",
150
+ "all",
151
+ ]);
152
+ /** Comment kind, defaulting to the page's footer discussion. */
153
+ export function commentKind(value) {
154
+ const text = optionalText(value, "kind", 3, 6) ?? "footer";
155
+ if (!COMMENT_KINDS.includes(text))
156
+ invalid("kind");
157
+ return text;
158
+ }
159
+ /** Collections a kind reads; `all` is the two of them, in this order. */
160
+ export function commentCollections(kind) {
161
+ return kind === "all" ? ["footer", "inline"] : [kind];
162
+ }
163
+ /** The page-relative collection path of one comment kind. */
164
+ export function commentPath(pageId, kind) {
165
+ return `/wiki/api/v2/pages/${pageId}/${kind}-comments`;
166
+ }
167
+ /** The replies of one comment; the collection decides which endpoint owns them. */
168
+ export function commentChildrenPath(kind, commentId) {
169
+ return `/wiki/api/v2/${kind}-comments/${commentId}/children`;
170
+ }
171
+ export const SPACE_TYPES = Object.freeze([
172
+ "global",
173
+ "personal",
174
+ "collaboration",
175
+ "knowledge_base",
176
+ ]);
177
+ /**
178
+ * Every handler builds a request out of validated arguments: the path is a
179
+ * fixed string with our own placeholders filled, and every query value is
180
+ * either a constant, a number, or a value this module checked first.
181
+ */
182
+ export const CONFLUENCE_HANDLERS = Object.freeze({
183
+ "connection.get": () => ({
184
+ path: "/wiki/rest/api/user/current",
185
+ query: {},
186
+ }),
187
+ "search.run": (input, context) => {
188
+ const allowed = context.flags.allowedSpaces;
189
+ const requested = spaceKeys(input["spaces"], "spaces");
190
+ // A space outside the operator allowlist is refused here rather than
191
+ // silently dropped: the model asked for something it may not have, and the
192
+ // honest answer is a refusal it can learn from.
193
+ for (const key of requested) {
194
+ if (allowed.length > 0 && !allowed.includes(key)) {
195
+ throw new IntegrationError("OperationDeniedByPolicy", "Space is outside the allowlist of this deployment");
196
+ }
197
+ }
198
+ const cql = buildCql({
199
+ query: optionalText(input["query"], "query", 1, 400),
200
+ spaces: requested.length > 0 ? requested : allowed,
201
+ contentTypes: input["contentTypes"] === undefined
202
+ ? undefined
203
+ : contentTypes(input["contentTypes"]),
204
+ labels: input["labels"] === undefined
205
+ ? undefined
206
+ : requiredStringList(input["labels"], "labels", 20, 255),
207
+ creator: optionalText(input["creator"], "creator", 1, 255),
208
+ contributor: optionalText(input["contributor"], "contributor", 1, 255),
209
+ modifiedAfter: modifiedAfterDate(input["modifiedAfter"]),
210
+ orderBy: ordering(input["orderBy"]),
211
+ });
212
+ const includeArchived = optionalBoolean(input["includeArchived"], "includeArchived");
213
+ return {
214
+ path: "/wiki/rest/api/search",
215
+ query: {
216
+ cql,
217
+ limit: pageLimit(input["limit"], context.flags),
218
+ start: offsetCursor(input["cursor"]),
219
+ includeArchivedSpaces: includeArchived === true ? "true" : undefined,
220
+ },
221
+ };
222
+ },
223
+ "spaces.list": (input, context) => {
224
+ const allowed = context.flags.allowedSpaces;
225
+ const requested = spaceKeys(input["keys"], "keys");
226
+ for (const key of requested) {
227
+ if (allowed.length > 0 && !allowed.includes(key)) {
228
+ throw new IntegrationError("OperationDeniedByPolicy", "Space is outside the allowlist of this deployment");
229
+ }
230
+ }
231
+ const keys = requested.length > 0 ? requested : allowed;
232
+ const type = optionalText(input["type"], "type", 3, 32);
233
+ if (type !== undefined && !SPACE_TYPES.includes(type))
234
+ invalid("type");
235
+ return {
236
+ path: "/wiki/api/v2/spaces",
237
+ query: {
238
+ keys: keys.length === 0 ? undefined : keys.join(","),
239
+ type,
240
+ limit: pageLimit(input["limit"], context.flags),
241
+ cursor: upstreamCursor(input["cursor"]),
242
+ },
243
+ };
244
+ },
245
+ "spaces.get": (input) => {
246
+ const ref = spaceRef(input["space"]);
247
+ // v2 addresses a space by numeric id only. A key is looked up through the
248
+ // listing endpoint here, so the model still gets to speak in keys without
249
+ // the request ever holding a caller-shaped path.
250
+ if (!isNumericSpace(ref)) {
251
+ return {
252
+ path: "/wiki/api/v2/spaces",
253
+ query: { keys: ref, limit: 2, "description-format": "plain" },
254
+ };
255
+ }
256
+ return {
257
+ path: `/wiki/api/v2/spaces/${ref}`,
258
+ query: { "description-format": "plain" },
259
+ };
260
+ },
261
+ "pages.get": (input) => ({
262
+ path: `/wiki/api/v2/pages/${numericId(input["pageId"], "pageId")}`,
263
+ query: {
264
+ "body-format": "atlas_doc_format",
265
+ "include-labels": "true",
266
+ },
267
+ }),
268
+ "pages.comments": (input, context) => {
269
+ // The catalog declares the footer collection; `kind` picks between the two
270
+ // fixed paths, and `all` is answered by the provider as two reads.
271
+ const kind = commentKind(input["kind"]);
272
+ const pageId = numericId(input["pageId"], "pageId");
273
+ return {
274
+ path: commentPath(pageId, commentCollections(kind)[0] ?? "footer"),
275
+ query: {
276
+ "body-format": "atlas_doc_format",
277
+ limit: pageLimit(input["limit"], context.flags),
278
+ cursor: upstreamCursor(input["cursor"]),
279
+ sort: "created-date",
280
+ },
281
+ };
282
+ },
283
+ "pages.attachments": (input, context) => ({
284
+ path: `/wiki/api/v2/pages/${numericId(input["pageId"], "pageId")}/attachments`,
285
+ query: {
286
+ limit: pageLimit(input["limit"], context.flags),
287
+ cursor: upstreamCursor(input["cursor"]),
288
+ sort: "created-date",
289
+ },
290
+ }),
291
+ "pages.versions": (input, context) => ({
292
+ path: `/wiki/api/v2/pages/${numericId(input["pageId"], "pageId")}/versions`,
293
+ query: {
294
+ limit: pageLimit(input["limit"], context.flags),
295
+ cursor: upstreamCursor(input["cursor"]),
296
+ },
297
+ }),
298
+ });
299
+ function recordOf(value) {
300
+ return typeof value === "object" && value !== null && !Array.isArray(value)
301
+ ? value
302
+ : {};
303
+ }
304
+ function arrayOf(source, key) {
305
+ const value = source[key];
306
+ return Array.isArray(value) ? value : [];
307
+ }
308
+ function stringOf(source, key) {
309
+ const value = source[key];
310
+ return typeof value === "string" && value !== "" ? value : undefined;
311
+ }
312
+ function numberOf(source, key) {
313
+ const value = source[key];
314
+ return typeof value === "number" && Number.isFinite(value)
315
+ ? value
316
+ : undefined;
317
+ }
318
+ function booleanOf(source, key) {
319
+ const value = source[key];
320
+ return typeof value === "boolean" ? value : undefined;
321
+ }
322
+ /** Drop unset keys so a projection never answers with `undefined` holes. */
323
+ function compact(source) {
324
+ return Object.fromEntries(Object.entries(source).filter(([, value]) => value !== undefined));
325
+ }
326
+ /**
327
+ * A page URL a person can open. Confluence answers `_links.webui` as an
328
+ * absolute *path* under the site's `/wiki` root, so the two are concatenated —
329
+ * resolving it against the origin would drop `/wiki` and hand the model a link
330
+ * that 404s. A deployment configured with the Atlassian gateway base has no
331
+ * site origin to name, and answering with a gateway URL would be worse than
332
+ * answering with none.
333
+ */
334
+ function humanUrl(relative, declaredBase, instance) {
335
+ if (relative === undefined)
336
+ return undefined;
337
+ if (/^https?:\/\//u.test(relative))
338
+ return relative;
339
+ const declared = declaredBase?.trim();
340
+ const declaredIsSite = declared !== undefined &&
341
+ /^https?:\/\//u.test(declared) &&
342
+ new URL(declared).host !== "api.atlassian.com";
343
+ // A gateway instance, such as the one scoped API tokens need, has no site
344
+ // origin of its own to name.
345
+ const site = new URL(instance.baseUrl).host === "api.atlassian.com"
346
+ ? undefined
347
+ : instance.baseUrl;
348
+ const base = declaredIsSite
349
+ ? declared
350
+ : declared !== undefined && !/^https?:\/\//u.test(declared)
351
+ ? site === undefined
352
+ ? undefined
353
+ : `${site}${declared}`
354
+ : site === undefined
355
+ ? undefined
356
+ : `${site}/wiki`;
357
+ if (base === undefined)
358
+ return undefined;
359
+ return relative.startsWith("/")
360
+ ? `${base.replace(/\/+$/u, "")}${relative}`
361
+ : `${base.replace(/\/+$/u, "")}/${relative}`;
362
+ }
363
+ /**
364
+ * Any text taken from Confluence, with the budget that applies to it. One
365
+ * shape everywhere, so a reader can tell content from metadata without
366
+ * knowing which tool produced the answer.
367
+ */
368
+ function contentBlock(text, limit, format) {
369
+ return { format, ...textBudget(text, limit) };
370
+ }
371
+ /** Labels arrive as a `results` collection in v2 and as a bare list nowhere. */
372
+ function labelNames(value) {
373
+ const results = arrayOf(recordOf(value), "results");
374
+ const names = results
375
+ .map((item) => stringOf(recordOf(item), "name"))
376
+ .filter((name) => name !== undefined);
377
+ return names.length === 0 ? undefined : names;
378
+ }
379
+ /**
380
+ * Search excerpts arrive highlighted: the default representation wraps the
381
+ * matched terms in `<span>`. The provider hands the words over, never the
382
+ * markup, and undoes only the five entities a highlight can produce.
383
+ */
384
+ export function plainExcerpt(value) {
385
+ return value
386
+ .replace(/<[^>]*>/gu, "")
387
+ .replaceAll("&quot;", '"')
388
+ .replaceAll("&#39;", "'")
389
+ .replaceAll("&lt;", "<")
390
+ .replaceAll("&gt;", ">")
391
+ .replaceAll("&amp;", "&")
392
+ .replace(/\s+/gu, " ")
393
+ .trim();
394
+ }
395
+ /** The space of one search result: content, the flat field, or its breadcrumb. */
396
+ function resultSpace(source) {
397
+ const content = recordOf(source["content"]);
398
+ const direct = recordOf(content["space"] ?? source["space"]);
399
+ const key = stringOf(direct, "key") ?? keyFromDisplayUrl(source);
400
+ const name = stringOf(direct, "name") ??
401
+ stringOf(recordOf(source["resultGlobalContainer"]), "title");
402
+ return { key, name };
403
+ }
404
+ /** `resultGlobalContainer.displayUrl` is `/spaces/KEY`, so it names the space. */
405
+ function keyFromDisplayUrl(source) {
406
+ const container = recordOf(source["resultGlobalContainer"]);
407
+ const display = stringOf(container, "displayUrl");
408
+ if (display === undefined)
409
+ return undefined;
410
+ const match = /\/spaces\/([^/?#]+)/u.exec(display);
411
+ return match?.[1];
412
+ }
413
+ function unwrapResults(value) {
414
+ if (Array.isArray(value))
415
+ return value;
416
+ return arrayOf(recordOf(value), "results");
417
+ }
418
+ /**
419
+ * The spaces of a `spaces.get` answer. A numeric-id read answers the space
420
+ * itself, while the keyed lookup answers a collection with zero or one row.
421
+ */
422
+ function spaceMatches(value) {
423
+ const record = recordOf(value);
424
+ if (Array.isArray(record["results"]))
425
+ return record["results"];
426
+ const looksLikeSpace = stringOf(record, "key") !== undefined ||
427
+ stringOf(record, "id") !== undefined;
428
+ return looksLikeSpace ? [record] : [];
429
+ }
430
+ function searchItem(item, context) {
431
+ const source = recordOf(item);
432
+ const content = recordOf(source["content"]);
433
+ const space = resultSpace(source);
434
+ const id = stringOf(content, "id");
435
+ const excerpt = stringOf(source, "excerpt");
436
+ return compact({
437
+ id,
438
+ type: stringOf(content, "type") ?? stringOf(source, "entityType"),
439
+ title: stringOf(content, "title") ?? stringOf(source, "title"),
440
+ space: compact({ key: space.key, name: space.name }),
441
+ modifiedAt: stringOf(source, "lastModified") ??
442
+ stringOf(recordOf(content["version"]), "when"),
443
+ url: humanUrl(stringOf(source, "url"), undefined, context.instance),
444
+ untrustedContent: excerpt === undefined
445
+ ? undefined
446
+ : { format: "text", excerpt: plainExcerpt(excerpt) },
447
+ });
448
+ }
449
+ /**
450
+ * One comment as the model reads it. The list endpoints carry no author name
451
+ * and no date of their own: Confluence keeps both on the comment's version, so
452
+ * that is where they are read from.
453
+ */
454
+ function commentItem(item, kind, context) {
455
+ const source = recordOf(item);
456
+ const version = recordOf(source["version"]);
457
+ const body = recordOf(recordOf(source["body"])["atlas_doc_format"]);
458
+ const text = adfToText(body["value"]);
459
+ return compact({
460
+ id: stringOf(source, "id"),
461
+ kind,
462
+ parentCommentId: stringOf(source, "parentCommentId"),
463
+ resolutionStatus: stringOf(source, "resolutionStatus"),
464
+ version: compact({
465
+ number: numberOf(version, "number"),
466
+ createdAt: stringOf(version, "createdAt"),
467
+ authorId: stringOf(version, "authorId"),
468
+ minorEdit: booleanOf(version, "minorEdit"),
469
+ }),
470
+ url: humanUrl(stringOf(recordOf(source["_links"]), "webui"), undefined, context.instance),
471
+ untrustedContent: contentBlock(text, context.bodyLimit ?? text.length, "markdown-like"),
472
+ });
473
+ }
474
+ /** The replies of one comment, from a children read of its own. */
475
+ export function commentReplies(data, kind, context) {
476
+ return unwrapResults(data).map((item) => commentItem(item, kind, context));
477
+ }
478
+ function spaceSummary(value) {
479
+ const source = recordOf(value);
480
+ return compact({
481
+ id: stringOf(source, "id"),
482
+ key: stringOf(source, "key"),
483
+ name: stringOf(source, "name"),
484
+ type: stringOf(source, "type"),
485
+ status: stringOf(source, "status"),
486
+ homepageId: stringOf(source, "homepageId"),
487
+ });
488
+ }
489
+ /** One source block for every answer: identity of the read, never its content. */
490
+ export function confluenceSource(instance, extra = {}) {
491
+ return compact({
492
+ provider: "confluence",
493
+ site: instance.baseUrl,
494
+ ...extra,
495
+ });
496
+ }
497
+ export const CONFLUENCE_PROJECTIONS = Object.freeze({
498
+ "connection.get": (data, context) => {
499
+ const source = recordOf(data);
500
+ return {
501
+ source: confluenceSource(context.instance),
502
+ account: compact({
503
+ accountId: stringOf(source, "accountId"),
504
+ displayName: stringOf(source, "displayName"),
505
+ publicName: stringOf(source, "publicName"),
506
+ email: stringOf(source, "email"),
507
+ accountType: stringOf(source, "accountType"),
508
+ type: stringOf(source, "type"),
509
+ }),
510
+ };
511
+ },
512
+ "search.run": (data, context) => {
513
+ const source = recordOf(data);
514
+ const items = arrayOf(source, "results").map((item) => searchItem(item, context));
515
+ const start = context.start ?? numberOf(source, "start") ?? 0;
516
+ const totalSize = numberOf(source, "totalSize");
517
+ // An empty page never carries a cursor: handing back the offset it started
518
+ // at would let a caller that follows it loop forever.
519
+ const nextCursor = items.length > 0 &&
520
+ totalSize !== undefined &&
521
+ start + items.length < totalSize
522
+ ? String(start + items.length)
523
+ : undefined;
524
+ return {
525
+ source: confluenceSource(context.instance),
526
+ items,
527
+ nextCursor,
528
+ totalSize,
529
+ };
530
+ },
531
+ "spaces.list": (data, context) => ({
532
+ source: confluenceSource(context.instance),
533
+ items: unwrapResults(data)
534
+ .map(spaceSummary)
535
+ .filter((space) => spaceWithinPolicy(space, context)),
536
+ }),
537
+ "spaces.get": (data, context) => {
538
+ const matches = spaceMatches(data);
539
+ const space = matches.length === 1 ? matches[0] : undefined;
540
+ if (space === undefined) {
541
+ throw new IntegrationError("ResourceNotFound", "Confluence space not found");
542
+ }
543
+ const summary = spaceSummary(space);
544
+ const description = recordOf(recordOf(recordOf(space)["description"])["plain"]);
545
+ const text = stringOf(description, "value");
546
+ return {
547
+ source: confluenceSource(context.instance),
548
+ space: summary,
549
+ untrustedContent: text === undefined
550
+ ? undefined
551
+ : contentBlock(text, context.bodyLimit ?? text.length, "plain"),
552
+ };
553
+ },
554
+ "pages.get": (data, context) => {
555
+ const source = recordOf(data);
556
+ const links = recordOf(source["_links"]);
557
+ const version = recordOf(source["version"]);
558
+ const body = recordOf(recordOf(source["body"])["atlas_doc_format"]);
559
+ const text = adfToText(body["value"]);
560
+ const budgetLimit = context.bodyLimit ?? text.length;
561
+ const space = context.space ?? {};
562
+ return {
563
+ source: confluenceSource(context.instance, {
564
+ pageId: stringOf(source, "id") ?? context.pageId,
565
+ url: humanUrl(stringOf(links, "webui"), stringOf(links, "base"), context.instance),
566
+ }),
567
+ page: compact({
568
+ title: stringOf(source, "title"),
569
+ status: stringOf(source, "status"),
570
+ space: compact({
571
+ id: stringOf(space, "id") ?? stringOf(source, "spaceId"),
572
+ key: stringOf(space, "key"),
573
+ name: stringOf(space, "name"),
574
+ }),
575
+ parentId: stringOf(source, "parentId"),
576
+ author: compact({ accountId: stringOf(source, "authorId") }),
577
+ owner: compact({ accountId: stringOf(source, "ownerId") }),
578
+ createdAt: stringOf(source, "createdAt"),
579
+ version: compact({
580
+ number: numberOf(version, "number"),
581
+ createdAt: stringOf(version, "createdAt"),
582
+ message: stringOf(version, "message"),
583
+ authorId: stringOf(version, "authorId"),
584
+ minorEdit: booleanOf(version, "minorEdit"),
585
+ }),
586
+ labels: labelNames(source["labels"]),
587
+ }),
588
+ untrustedContent: contentBlock(text, budgetLimit, "markdown-like"),
589
+ };
590
+ },
591
+ "pages.comments": (data, context) => {
592
+ const kind = context.kind ?? "footer";
593
+ return {
594
+ source: confluenceSource(context.instance, {
595
+ pageId: context.pageId,
596
+ }),
597
+ items: unwrapResults(data).map((item) => commentItem(item, kind, context)),
598
+ };
599
+ },
600
+ "pages.attachments": (data, context) => ({
601
+ source: confluenceSource(context.instance, { pageId: context.pageId }),
602
+ items: unwrapResults(data).map((item) => {
603
+ const attachment = recordOf(item);
604
+ const version = recordOf(attachment["version"]);
605
+ const links = recordOf(attachment["_links"]);
606
+ return compact({
607
+ id: stringOf(attachment, "id"),
608
+ title: stringOf(attachment, "title"),
609
+ mediaType: stringOf(attachment, "mediaType"),
610
+ fileSize: numberOf(attachment, "fileSize"),
611
+ status: stringOf(attachment, "status"),
612
+ versionNumber: numberOf(version, "number"),
613
+ createdAt: stringOf(attachment, "createdAt"),
614
+ authorId: stringOf(version, "authorId"),
615
+ pageId: stringOf(attachment, "pageId"),
616
+ // Metadata only: a download link is handed over, the bytes are not
617
+ // fetched — whether an attachment body may ever leave Confluence is a
618
+ // deployment decision this read-only provider does not take.
619
+ webuiLink: stringOf(attachment, "webuiLink") ?? stringOf(links, "webui"),
620
+ downloadLink: stringOf(attachment, "downloadLink") ?? stringOf(links, "download"),
621
+ });
622
+ }),
623
+ }),
624
+ "pages.versions": (data, context) => ({
625
+ source: confluenceSource(context.instance, { pageId: context.pageId }),
626
+ items: unwrapResults(data).map((item) => {
627
+ const version = recordOf(item);
628
+ const page = recordOf(version["page"]);
629
+ return compact({
630
+ number: numberOf(version, "number"),
631
+ message: stringOf(version, "message"),
632
+ createdAt: stringOf(version, "createdAt"),
633
+ authorId: stringOf(version, "authorId"),
634
+ minorEdit: booleanOf(version, "minorEdit"),
635
+ pageId: stringOf(page, "id") ?? context.pageId,
636
+ title: stringOf(page, "title"),
637
+ });
638
+ }),
639
+ }),
640
+ });
641
+ /**
642
+ * Whether a projected space passes the operator allowlist. The upstream `keys`
643
+ * filter already narrows the request when the policy is set; this second check
644
+ * makes the answer independent of that filter holding.
645
+ */
646
+ function spaceWithinPolicy(space, context) {
647
+ const allowed = context.flags.allowedSpaces;
648
+ if (allowed.length === 0)
649
+ return true;
650
+ const key = typeof space["key"] === "string" ? space["key"] : undefined;
651
+ return key !== undefined && allowed.includes(key.toUpperCase());
652
+ }
653
+ //# sourceMappingURL=operations.js.map