@yadsh/dsh-qa-integrations 0.7.0 → 0.8.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/README.md +33 -16
- package/lib/client/confluence.js +37 -16
- package/lib/client/confluence.js.map +1 -1
- package/lib/client/jira.js +32 -11
- package/lib/client/jira.js.map +1 -1
- package/lib/client.js +128 -73
- package/lib/client.js.map +1 -1
- package/lib/coerce.js +17 -1
- package/lib/coerce.js.map +1 -1
- package/lib/config.js.map +1 -1
- package/lib/errors.js +22 -0
- package/lib/errors.js.map +1 -1
- package/lib/index.js +20 -2
- package/lib/index.js.map +1 -1
- package/lib/providers/bitrix24/config.js +2 -3
- package/lib/providers/bitrix24/config.js.map +1 -1
- package/lib/providers/bitrix24/index.js +1 -14
- package/lib/providers/bitrix24/index.js.map +1 -1
- package/lib/providers/bitrix24/operations.js +5 -9
- package/lib/providers/bitrix24/operations.js.map +1 -1
- package/lib/providers/bitrix24/transport.js +11 -31
- package/lib/providers/bitrix24/transport.js.map +1 -1
- package/lib/providers/confluence/adf.js +28 -23
- package/lib/providers/confluence/adf.js.map +1 -1
- package/lib/providers/confluence/catalog.js +40 -4
- package/lib/providers/confluence/catalog.js.map +1 -1
- package/lib/providers/confluence/config.js +27 -2
- package/lib/providers/confluence/config.js.map +1 -1
- package/lib/providers/confluence/credential-help.js +14 -8
- package/lib/providers/confluence/credential-help.js.map +1 -1
- package/lib/providers/confluence/dialect.js +215 -0
- package/lib/providers/confluence/dialect.js.map +1 -0
- package/lib/providers/confluence/index.js +137 -81
- package/lib/providers/confluence/index.js.map +1 -1
- package/lib/providers/confluence/operations.js +207 -152
- package/lib/providers/confluence/operations.js.map +1 -1
- package/lib/providers/confluence/storage.js +690 -0
- package/lib/providers/confluence/storage.js.map +1 -0
- package/lib/providers/confluence/transport.js +26 -89
- package/lib/providers/confluence/transport.js.map +1 -1
- package/lib/providers/gitlab/config.js +2 -3
- package/lib/providers/gitlab/config.js.map +1 -1
- package/lib/providers/gitlab/index.js +2 -20
- package/lib/providers/gitlab/index.js.map +1 -1
- package/lib/providers/gitlab/operations.js +7 -45
- package/lib/providers/gitlab/operations.js.map +1 -1
- package/lib/providers/gitlab/transport.js +2 -18
- package/lib/providers/gitlab/transport.js.map +1 -1
- package/lib/providers/jira/adf.js +19 -14
- package/lib/providers/jira/adf.js.map +1 -1
- package/lib/providers/jira/catalog.js +52 -1
- package/lib/providers/jira/catalog.js.map +1 -1
- package/lib/providers/jira/config.js +27 -2
- package/lib/providers/jira/config.js.map +1 -1
- package/lib/providers/jira/credential-help.js +16 -7
- package/lib/providers/jira/credential-help.js.map +1 -1
- package/lib/providers/jira/dialect.js +94 -0
- package/lib/providers/jira/dialect.js.map +1 -0
- package/lib/providers/jira/index.js +101 -95
- package/lib/providers/jira/index.js.map +1 -1
- package/lib/providers/jira/jql.js +54 -21
- package/lib/providers/jira/jql.js.map +1 -1
- package/lib/providers/jira/operations.js +77 -55
- package/lib/providers/jira/operations.js.map +1 -1
- package/lib/providers/jira/tools.js +1 -1
- package/lib/providers/jira/tools.js.map +1 -1
- package/lib/providers/jira/transport.js +12 -83
- package/lib/providers/jira/transport.js.map +1 -1
- package/lib/providers/shared/health.js +31 -0
- package/lib/providers/shared/health.js.map +1 -0
- package/lib/providers/shared/http.js +20 -0
- package/lib/providers/shared/http.js.map +1 -1
- package/lib/providers/shared/paths.js +14 -0
- package/lib/providers/shared/paths.js.map +1 -0
- package/lib/providers/shared/payload.js +46 -0
- package/lib/providers/shared/payload.js.map +1 -0
- package/lib/providers/teamcity/artifacts.js +0 -8
- package/lib/providers/teamcity/artifacts.js.map +1 -1
- package/lib/providers/teamcity/config.js +2 -3
- package/lib/providers/teamcity/config.js.map +1 -1
- package/lib/providers/teamcity/index.js +2 -20
- package/lib/providers/teamcity/index.js.map +1 -1
- package/lib/providers/teamcity/operations.js +5 -39
- package/lib/providers/teamcity/operations.js.map +1 -1
- package/lib/providers/teamcity/transport.js +2 -11
- package/lib/providers/teamcity/transport.js.map +1 -1
- package/lib/providers/testit/config.js +2 -3
- package/lib/providers/testit/config.js.map +1 -1
- package/lib/providers/testit/index.js +2 -20
- package/lib/providers/testit/index.js.map +1 -1
- package/lib/providers/testit/operations.js +34 -63
- package/lib/providers/testit/operations.js.map +1 -1
- package/lib/providers/testit/transport.js +2 -18
- package/lib/providers/testit/transport.js.map +1 -1
- package/lib/providers/weblate/config.js +2 -3
- package/lib/providers/weblate/config.js.map +1 -1
- package/lib/providers/weblate/index.js +2 -19
- package/lib/providers/weblate/index.js.map +1 -1
- package/lib/providers/weblate/operations.js +3 -33
- package/lib/providers/weblate/operations.js.map +1 -1
- package/lib/providers/weblate/query.js +3 -6
- package/lib/providers/weblate/query.js.map +1 -1
- package/lib/providers/weblate/transport.js +2 -12
- package/lib/providers/weblate/transport.js.map +1 -1
- package/lib/service-credentials/config.js +2 -3
- package/lib/service-credentials/config.js.map +1 -1
- package/lib/typert.host.js +62 -55
- package/lib/typert.remote-client.d.ts +4 -4
- package/lib/typert.remote-client.js +58 -51
- package/lib/types/client/confluence.d.ts +5 -1
- package/lib/types/client/jira.d.ts +5 -1
- package/lib/types/coerce.d.ts +14 -0
- package/lib/types/config.d.ts +4 -4
- package/lib/types/errors.d.ts +16 -0
- package/lib/types/index.d.ts +10 -2
- package/lib/types/providers/bitrix24/index.d.ts +1 -0
- package/lib/types/providers/confluence/catalog.d.ts +33 -5
- package/lib/types/providers/confluence/config.d.ts +39 -7
- package/lib/types/providers/confluence/credential-help.d.ts +9 -4
- package/lib/types/providers/confluence/dialect.d.ts +113 -0
- package/lib/types/providers/confluence/index.d.ts +24 -4
- package/lib/types/providers/confluence/operations.d.ts +12 -4
- package/lib/types/providers/confluence/storage.d.ts +28 -0
- package/lib/types/providers/confluence/transport.d.ts +10 -21
- package/lib/types/providers/jira/catalog.d.ts +36 -2
- package/lib/types/providers/jira/config.d.ts +37 -6
- package/lib/types/providers/jira/credential-help.d.ts +11 -3
- package/lib/types/providers/jira/dialect.d.ts +79 -0
- package/lib/types/providers/jira/index.d.ts +32 -22
- package/lib/types/providers/jira/jql.d.ts +14 -4
- package/lib/types/providers/jira/operations.d.ts +3 -0
- package/lib/types/providers/jira/transport.d.ts +6 -13
- package/lib/types/providers/shared/health.d.ts +18 -0
- package/lib/types/providers/shared/http.d.ts +9 -0
- package/lib/types/providers/shared/paths.d.ts +10 -0
- package/lib/types/providers/shared/payload.d.ts +26 -0
- package/lib/types/providers/teamcity/artifacts.d.ts +0 -2
- package/lib/types/providers/teamcity/index.d.ts +2 -0
- package/lib/types/providers/testit/index.d.ts +2 -0
- package/lib/types/types.d.ts +8 -0
- package/package.json +5 -5
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { IntegrationError } from "../../errors.js";
|
|
2
|
+
import { CONFLUENCE_COMPANION_PATHS, CONFLUENCE_INLINE_COMMENTS_PATH, CONFLUENCE_SERVER_COMPANION_PATHS, confluenceOperationPath, } from "./catalog.js";
|
|
3
|
+
/** The catalog's path of one operation on one product. */
|
|
4
|
+
function operationPath(operation, deployment) {
|
|
5
|
+
return confluenceOperationPath(operation, deployment) ?? "";
|
|
6
|
+
}
|
|
7
|
+
/** The same, with one `:placeholder` filled from a value we validated first. */
|
|
8
|
+
function fill(operation, deployment, placeholders, declared) {
|
|
9
|
+
let path = declared ?? operationPath(operation, deployment);
|
|
10
|
+
for (const [name, value] of Object.entries(placeholders)) {
|
|
11
|
+
path = path.replace(`:${name}`, value);
|
|
12
|
+
}
|
|
13
|
+
return path;
|
|
14
|
+
}
|
|
15
|
+
/** The comment collection of one Cloud page, by the kind the caller named. */
|
|
16
|
+
function commentCollection(pageId, kind) {
|
|
17
|
+
const declared = kind === "footer"
|
|
18
|
+
? confluenceOperationPath("pages.comments", "cloud")
|
|
19
|
+
: CONFLUENCE_INLINE_COMMENTS_PATH;
|
|
20
|
+
return fill("pages.comments", "cloud", { pageId }, declared);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The continuation parameter of one paged read. Cloud continues a v2 collection
|
|
24
|
+
* with the opaque cursor it handed out; a Server / Data Center installation
|
|
25
|
+
* continues a v1 collection at the row offset it reported. Keeping this here is
|
|
26
|
+
* what makes every caller of the dialect paging-agnostic.
|
|
27
|
+
*/
|
|
28
|
+
function paged(cursor, limit) {
|
|
29
|
+
return cursor === undefined ? { limit } : { limit, start: Number(cursor) };
|
|
30
|
+
}
|
|
31
|
+
/** The same, for the one collection Cloud pages by cursor. */
|
|
32
|
+
function cursorPaged(cursor, limit) {
|
|
33
|
+
return cursor === undefined ? { limit } : { limit, cursor };
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Atlassian Cloud: the v2 API under the site's `/wiki` root, an API token over
|
|
37
|
+
* HTTP Basic, and listings paged by an opaque upstream cursor.
|
|
38
|
+
*/
|
|
39
|
+
const CLOUD = Object.freeze({
|
|
40
|
+
deployment: "cloud",
|
|
41
|
+
credentialLabel: "Atlassian API token",
|
|
42
|
+
tokenShape: /^[A-Za-z0-9._=+/-]{16,512}$/u,
|
|
43
|
+
requiresEmail: true,
|
|
44
|
+
productName: "Confluence Cloud",
|
|
45
|
+
commentKinds: "path",
|
|
46
|
+
currentUserPath: operationPath("connection.get", "cloud"),
|
|
47
|
+
searchPath: ({ cql, start, limit, includeArchived }) => ({
|
|
48
|
+
path: operationPath("search.run", "cloud"),
|
|
49
|
+
query: {
|
|
50
|
+
cql,
|
|
51
|
+
limit,
|
|
52
|
+
start,
|
|
53
|
+
includeArchivedSpaces: includeArchived === true ? "true" : undefined,
|
|
54
|
+
},
|
|
55
|
+
}),
|
|
56
|
+
spacePath: (ref) => isNumericSpace(ref)
|
|
57
|
+
? {
|
|
58
|
+
path: fill("spaces.get", "cloud", { spaceId: ref }),
|
|
59
|
+
query: { "description-format": "plain" },
|
|
60
|
+
}
|
|
61
|
+
: {
|
|
62
|
+
path: operationPath("spaces.list", "cloud"),
|
|
63
|
+
query: { keys: ref, limit: 2, "description-format": "plain" },
|
|
64
|
+
},
|
|
65
|
+
spaceList: ({ keys, type, cursor, limit }) => ({
|
|
66
|
+
path: operationPath("spaces.list", "cloud"),
|
|
67
|
+
query: {
|
|
68
|
+
keys: keys.length === 0 ? undefined : keys.join(","),
|
|
69
|
+
type,
|
|
70
|
+
...cursorPaged(cursor, limit),
|
|
71
|
+
},
|
|
72
|
+
}),
|
|
73
|
+
pageSpacePath: (pageId) => ({
|
|
74
|
+
path: fill("pages.get", "cloud", { pageId }),
|
|
75
|
+
query: {},
|
|
76
|
+
}),
|
|
77
|
+
pagePath: (pageId) => ({
|
|
78
|
+
path: fill("pages.get", "cloud", { pageId }),
|
|
79
|
+
query: { "body-format": "atlas_doc_format", "include-labels": "true" },
|
|
80
|
+
}),
|
|
81
|
+
commentPath: ({ pageId, kind, cursor, limit }) => ({
|
|
82
|
+
path: commentCollection(pageId, kind),
|
|
83
|
+
query: {
|
|
84
|
+
"body-format": "atlas_doc_format",
|
|
85
|
+
sort: "created-date",
|
|
86
|
+
...cursorPaged(cursor, limit),
|
|
87
|
+
},
|
|
88
|
+
}),
|
|
89
|
+
commentChildrenPath: ({ commentId, kind, cursor, limit }) => ({
|
|
90
|
+
path: fill("commentChildren", "cloud", { commentId }, kind === "footer"
|
|
91
|
+
? CONFLUENCE_COMPANION_PATHS[0]
|
|
92
|
+
: CONFLUENCE_COMPANION_PATHS[1]),
|
|
93
|
+
query: {
|
|
94
|
+
"body-format": "atlas_doc_format",
|
|
95
|
+
sort: "created-date",
|
|
96
|
+
...cursorPaged(cursor, limit),
|
|
97
|
+
},
|
|
98
|
+
}),
|
|
99
|
+
attachmentPath: ({ pageId, cursor, limit }) => ({
|
|
100
|
+
path: fill("pages.attachments", "cloud", { pageId }),
|
|
101
|
+
query: { sort: "created-date", ...cursorPaged(cursor, limit) },
|
|
102
|
+
}),
|
|
103
|
+
versionPath: ({ pageId, cursor, limit }) => ({
|
|
104
|
+
path: fill("pages.versions", "cloud", { pageId }),
|
|
105
|
+
query: cursorPaged(cursor, limit),
|
|
106
|
+
}),
|
|
107
|
+
});
|
|
108
|
+
/**
|
|
109
|
+
* Server and Data Center: the v1 API under the installation's own base, a
|
|
110
|
+
* personal access token over Bearer, and listings paged by row offset. A
|
|
111
|
+
* self-hosted installation has no `/wiki` context of its own — an installation
|
|
112
|
+
* that lives behind a context path declares it in `baseUrl`, and every path
|
|
113
|
+
* below is relative to that.
|
|
114
|
+
*/
|
|
115
|
+
const SERVER = Object.freeze({
|
|
116
|
+
deployment: "server",
|
|
117
|
+
credentialLabel: "personal access token",
|
|
118
|
+
// A Data Center personal access token is base64, so it may carry `+`, `/` and
|
|
119
|
+
// padding; the shape is checked for "one opaque token" rather than an
|
|
120
|
+
// alphabet an API token happens to use.
|
|
121
|
+
tokenShape: /^[A-Za-z0-9._+/=-]{16,1024}$/u,
|
|
122
|
+
requiresEmail: false,
|
|
123
|
+
productName: "Confluence Server / Data Center",
|
|
124
|
+
// The v1 API keeps footer and inline comments in one collection and marks
|
|
125
|
+
// each comment with its location, so the kind is filtered after the read
|
|
126
|
+
// instead of selecting an endpoint.
|
|
127
|
+
commentKinds: "marker",
|
|
128
|
+
currentUserPath: operationPath("connection.get", "server"),
|
|
129
|
+
searchPath: ({ cql, start, limit }) => ({
|
|
130
|
+
path: operationPath("search.run", "server"),
|
|
131
|
+
query: {
|
|
132
|
+
cql,
|
|
133
|
+
limit,
|
|
134
|
+
start,
|
|
135
|
+
// The excerpt is what a search answer hands the model instead of the
|
|
136
|
+
// whole body, so the collection read asks for it explicitly.
|
|
137
|
+
expand: "space,version,excerpt",
|
|
138
|
+
},
|
|
139
|
+
}),
|
|
140
|
+
spacePath: (ref) => ({
|
|
141
|
+
path: operationPath("spaces.list", "server"),
|
|
142
|
+
query: { keys: ref, limit: 2, expand: "description.plain" },
|
|
143
|
+
}),
|
|
144
|
+
spaceList: ({ keys, type, cursor, limit }) => ({
|
|
145
|
+
path: operationPath("spaces.list", "server"),
|
|
146
|
+
query: {
|
|
147
|
+
keys: keys.length === 0 ? undefined : keys.join(","),
|
|
148
|
+
type,
|
|
149
|
+
...paged(cursor, limit),
|
|
150
|
+
},
|
|
151
|
+
}),
|
|
152
|
+
pageSpacePath: (pageId) => ({
|
|
153
|
+
path: fill("pages.get", "server", { pageId }),
|
|
154
|
+
query: { expand: "space" },
|
|
155
|
+
}),
|
|
156
|
+
pagePath: (pageId) => ({
|
|
157
|
+
path: fill("pages.get", "server", { pageId }),
|
|
158
|
+
query: {
|
|
159
|
+
expand: "body.storage,version,space,ancestors,metadata.labels",
|
|
160
|
+
},
|
|
161
|
+
}),
|
|
162
|
+
commentPath: ({ pageId, cursor, limit }) => ({
|
|
163
|
+
path: fill("pages.comments", "server", { pageId }),
|
|
164
|
+
query: {
|
|
165
|
+
expand: "body.storage,version,extensions",
|
|
166
|
+
...paged(cursor, limit),
|
|
167
|
+
},
|
|
168
|
+
}),
|
|
169
|
+
commentChildrenPath: ({ commentId, cursor, limit }) => ({
|
|
170
|
+
path: fill("commentChildren", "server", { commentId }, CONFLUENCE_SERVER_COMPANION_PATHS[0]),
|
|
171
|
+
query: {
|
|
172
|
+
expand: "body.storage,version,extensions",
|
|
173
|
+
...paged(cursor, limit),
|
|
174
|
+
},
|
|
175
|
+
}),
|
|
176
|
+
attachmentPath: ({ pageId, cursor, limit }) => ({
|
|
177
|
+
path: fill("pages.attachments", "server", { pageId }),
|
|
178
|
+
query: { expand: "version", ...paged(cursor, limit) },
|
|
179
|
+
}),
|
|
180
|
+
versionPath: ({ pageId, cursor, limit }) => ({
|
|
181
|
+
path: fill("pages.versions", "server", { pageId }),
|
|
182
|
+
query: paged(cursor, limit),
|
|
183
|
+
}),
|
|
184
|
+
});
|
|
185
|
+
export const CONFLUENCE_DIALECTS = Object.freeze({ cloud: CLOUD, server: SERVER });
|
|
186
|
+
/** The dialect of one configured instance. */
|
|
187
|
+
export function dialectOf(instance) {
|
|
188
|
+
return CONFLUENCE_DIALECTS[instance.deploymentType];
|
|
189
|
+
}
|
|
190
|
+
const NUMERIC = /^\d{1,20}$/u;
|
|
191
|
+
/** Whether a space reference is the numeric id the v2 API addresses it by. */
|
|
192
|
+
function isNumericSpace(value) {
|
|
193
|
+
return NUMERIC.test(value);
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* The `Authorization` header of one stored credential. Cloud spends an
|
|
197
|
+
* Atlassian API token as HTTP Basic over `email:token`; a Server / Data Center
|
|
198
|
+
* personal access token is a bearer token whose account is the token's own, so
|
|
199
|
+
* no e-mail travels with it.
|
|
200
|
+
*
|
|
201
|
+
* The credential carries what the operator's instance declared, so an instance
|
|
202
|
+
* whose deployment type no longer matches the stored credential is refused
|
|
203
|
+
* here, before the secret is spent: a token minted for one product must not be
|
|
204
|
+
* offered to the other.
|
|
205
|
+
*/
|
|
206
|
+
export function authorizationFor(dialect, credential) {
|
|
207
|
+
if (dialect.deployment === "server")
|
|
208
|
+
return `Bearer ${credential.token}`;
|
|
209
|
+
if (credential.email.trim() === "") {
|
|
210
|
+
throw new IntegrationError("CredentialRevoked", "This Confluence site is configured as Cloud and needs the account e-mail; reconnect it");
|
|
211
|
+
}
|
|
212
|
+
const pair = Buffer.from(`${credential.email}:${credential.token}`, "utf8").toString("base64");
|
|
213
|
+
return `Basic ${pair}`;
|
|
214
|
+
}
|
|
215
|
+
//# sourceMappingURL=dialect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dialect.js","sourceRoot":"","sources":["../../../src/providers/confluence/dialect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EACL,0BAA0B,EAC1B,+BAA+B,EAC/B,iCAAiC,EACjC,uBAAuB,GACxB,MAAM,cAAc,CAAC;AAGtB,0DAA0D;AAC1D,SAAS,aAAa,CACpB,SAAiB,EACjB,UAAgC;IAEhC,OAAO,uBAAuB,CAAC,SAAS,EAAE,UAAU,CAAC,IAAI,EAAE,CAAC;AAC9D,CAAC;AAED,gFAAgF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,KAAK,QAAQ;QAAE,OAAO,UAAU,UAAU,CAAC,KAAK,EAAE,CAAC;IACzE,IAAI,UAAU,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;QACnC,MAAM,IAAI,gBAAgB,CACxB,mBAAmB,EACnB,wFAAwF,CACzF,CAAC;IACJ,CAAC;IACD,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CACtB,GAAG,UAAU,CAAC,KAAK,IAAI,UAAU,CAAC,KAAK,EAAE,EACzC,MAAM,CACP,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IACrB,OAAO,SAAS,IAAI,EAAE,CAAC;AACzB,CAAC"}
|
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
import { resolveCredentialHelp, } from "@yadsh/dsh-plugin-kit";
|
|
2
|
-
import { IntegrationError } from "../../errors.js";
|
|
2
|
+
import { IntegrationError, recoverableResource } from "../../errors.js";
|
|
3
3
|
import { operationCapabilityServiceState } from "../../service-credentials/state.js";
|
|
4
|
+
import { healthFromFailure } from "../shared/health.js";
|
|
5
|
+
import { recordOf } from "../shared/payload.js";
|
|
4
6
|
import { assertServiceOperationAllowed, serviceBoundaryOf, serviceResourceDenied, } from "../shared/service-boundary.js";
|
|
5
7
|
import { CONFLUENCE_CAPABILITY_INFO, CONFLUENCE_OPERATIONS, CONFLUENCE_RESOURCE_KIND, confluenceOperationCapability, confluenceOperationMetadata, enabledCapabilities, } from "./catalog.js";
|
|
6
8
|
import { CONFLUENCE_CREDENTIAL_HELP } from "./credential-help.js";
|
|
7
9
|
import { credentialFromPlaintext, credentialInstance, ConfluenceTransport, } from "./transport.js";
|
|
8
|
-
import {
|
|
10
|
+
import { dialectOf } from "./dialect.js";
|
|
11
|
+
import { CONFLUENCE_HANDLERS, CONFLUENCE_PROJECTIONS, SPACE_TYPES, bodyLimit, commentCollections, commentChildrenPath, commentKind, commentPath, commentReplies, confluenceSource, isNumericSpace, listingCursor, numericId, offsetCursor, pageLimit, spaceKeys, spaceRef, } from "./operations.js";
|
|
9
12
|
import { confluenceInstance, spaceAllowed, } from "./config.js";
|
|
10
13
|
export { credentialFromPlaintext, credentialInstance, } from "./transport.js";
|
|
11
14
|
/**
|
|
12
|
-
* Atlassian API tokens are long opaque strings, sometimes prefixed
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
+
* Atlassian API tokens are long opaque strings, sometimes prefixed; a Server /
|
|
16
|
+
* Data Center personal access token is base64 and may carry `+`, `/` and
|
|
17
|
+
* padding. The shape a connection accepts is the dialect's own. A pasted URL, a
|
|
18
|
+
* YAML snippet or a credential with whitespace is refused before anything is
|
|
19
|
+
* sent upstream.
|
|
15
20
|
*/
|
|
16
|
-
const TOKEN_SHAPE = /^[A-Za-z0-9._=+/-]{16,512}$/u;
|
|
17
|
-
/** The Atlassian account the token belongs to; the pair is what authenticates. */
|
|
18
21
|
const EMAIL_SHAPE = /^[^\s@]{1,64}@[^\s@.]+(?:\.[^\s@.]+)+$/u;
|
|
19
22
|
/**
|
|
20
23
|
* The `email:token` pair of a deployment-managed secret. Atlassian
|
|
@@ -54,6 +57,26 @@ function accountName(data) {
|
|
|
54
57
|
function textOf(value) {
|
|
55
58
|
return typeof value === "string" && value !== "" ? value : undefined;
|
|
56
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* Which collection a comment of the marker dialect belongs to. Cloud hands out
|
|
62
|
+
* one endpoint per kind, so nothing has to be read off the comment there.
|
|
63
|
+
*/
|
|
64
|
+
function commentMarker(row) {
|
|
65
|
+
const value = typeof row === "object" && row !== null
|
|
66
|
+
? row["kind"]
|
|
67
|
+
: undefined;
|
|
68
|
+
return value === "footer" || value === "inline" ? value : undefined;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* The identifier of one user as either product reports it: Cloud names an
|
|
72
|
+
* account id, a Server / Data Center installation the user key and login its
|
|
73
|
+
* directory uses. The same value is what a later read has to name the user by.
|
|
74
|
+
*/
|
|
75
|
+
function identityOf(data) {
|
|
76
|
+
return (textOf(data["accountId"]) ??
|
|
77
|
+
textOf(data["userKey"]) ??
|
|
78
|
+
textOf(data["username"]));
|
|
79
|
+
}
|
|
57
80
|
/**
|
|
58
81
|
* Whether one space key stays inside the deployment's boundary. The profile's
|
|
59
82
|
* `resources.spaces` lists space keys — the same vocabulary the deployment's
|
|
@@ -69,7 +92,15 @@ export function spaceInBoundary(boundary, key) {
|
|
|
69
92
|
return false;
|
|
70
93
|
return (boundary[CONFLUENCE_RESOURCE_KIND] ?? []).some((entry) => entry.trim().toUpperCase() === normalized);
|
|
71
94
|
}
|
|
72
|
-
/**
|
|
95
|
+
/**
|
|
96
|
+
* Confluence provider: operator-configured sites over an Atlassian API token
|
|
97
|
+
* (Cloud) or a personal access token (Server / Data Center).
|
|
98
|
+
*
|
|
99
|
+
* Which product answers at a site — and so which endpoints, which
|
|
100
|
+
* authentication scheme and which shape of body this provider speaks — is the
|
|
101
|
+
* site's own declared deployment type, never a guess made at connect or at run
|
|
102
|
+
* time.
|
|
103
|
+
*/
|
|
73
104
|
export class ConfluenceProvider {
|
|
74
105
|
config;
|
|
75
106
|
id = "confluence";
|
|
@@ -102,26 +133,32 @@ export class ConfluenceProvider {
|
|
|
102
133
|
* broker from dialling any host the caller names or authenticating as any
|
|
103
134
|
* account the caller names.
|
|
104
135
|
*
|
|
105
|
-
* A deployment-managed secret cannot travel with a connect form, so
|
|
106
|
-
* arrives as the Basic pair Atlassian documents (`email:token`)
|
|
107
|
-
* forms can never be confused
|
|
136
|
+
* A deployment-managed secret cannot travel with a connect form, so on Cloud
|
|
137
|
+
* it arrives as the Basic pair Atlassian documents (`email:token`); the two
|
|
138
|
+
* forms can never be confused there, because an API token contains neither
|
|
139
|
+
* `@` nor `:`. A Server / Data Center personal access token is the secret
|
|
140
|
+
* alone, and its connection stores an empty e-mail: the instance's declared
|
|
141
|
+
* deployment type is what decides whether an account is required.
|
|
108
142
|
*/
|
|
109
143
|
parseCredential(raw, options) {
|
|
144
|
+
// The instance decides what this connection is allowed to look like, so it
|
|
145
|
+
// is resolved before the secret is judged.
|
|
146
|
+
const instance = this.resolveInstance(options?.["instanceId"]);
|
|
147
|
+
const dialect = dialectOf(instance);
|
|
110
148
|
const provided = raw.trim();
|
|
111
149
|
const pair = options?.["email"] === undefined ? splitBasicPair(provided) : undefined;
|
|
112
150
|
const token = pair === undefined ? provided : pair.token;
|
|
113
|
-
if (!
|
|
114
|
-
throw new IntegrationError("InvalidCredential",
|
|
151
|
+
if (!dialect.tokenShape.test(token)) {
|
|
152
|
+
throw new IntegrationError("InvalidCredential", `Use a Confluence ${dialect.credentialLabel}`);
|
|
115
153
|
}
|
|
116
154
|
const email = (pair === undefined ? options?.["email"] : pair.email)?.trim();
|
|
117
|
-
if (
|
|
155
|
+
if (dialect.requiresEmail && !EMAIL_SHAPE.test(email ?? "")) {
|
|
118
156
|
throw new IntegrationError("InvalidCredential", "Use the e-mail of the Atlassian account the token belongs to");
|
|
119
157
|
}
|
|
120
|
-
const instance = this.resolveInstance(options?.["instanceId"]);
|
|
121
158
|
return {
|
|
122
159
|
credential: JSON.stringify({
|
|
123
160
|
instanceId: instance.id,
|
|
124
|
-
email,
|
|
161
|
+
email: email ?? "",
|
|
125
162
|
token,
|
|
126
163
|
}),
|
|
127
164
|
portal: instance.baseUrl,
|
|
@@ -159,12 +196,10 @@ export class ConfluenceProvider {
|
|
|
159
196
|
async validate(context) {
|
|
160
197
|
const credential = credentialFromPlaintext(context.credential);
|
|
161
198
|
const instance = credentialInstance(this.config.confluence, credential);
|
|
162
|
-
// The connected user is the one read
|
|
163
|
-
//
|
|
164
|
-
const { data } = await this.transport.getJson(instance, credential,
|
|
165
|
-
const accountId =
|
|
166
|
-
textOf(data["userKey"]) ??
|
|
167
|
-
textOf(data["username"]);
|
|
199
|
+
// The connected user is the one read both products serve, and it is also
|
|
200
|
+
// the cheapest proof that this token may use Confluence at all.
|
|
201
|
+
const { data } = await this.transport.getJson(instance, credential, dialectOf(instance).currentUserPath);
|
|
202
|
+
const accountId = identityOf(data);
|
|
168
203
|
if (accountId === undefined) {
|
|
169
204
|
throw new IntegrationError("ProviderUnavailable", "Provider identity is unavailable");
|
|
170
205
|
}
|
|
@@ -186,15 +221,13 @@ export class ConfluenceProvider {
|
|
|
186
221
|
const instance = credentialInstance(this.config.confluence, credential);
|
|
187
222
|
let data;
|
|
188
223
|
try {
|
|
189
|
-
const response = await this.transport.getJson(instance, credential,
|
|
224
|
+
const response = await this.transport.getJson(instance, credential, dialectOf(instance).currentUserPath);
|
|
190
225
|
data = response.data;
|
|
191
226
|
}
|
|
192
227
|
catch (error) {
|
|
193
228
|
return healthFromFailure(error);
|
|
194
229
|
}
|
|
195
|
-
const id =
|
|
196
|
-
textOf(data["userKey"]) ??
|
|
197
|
-
textOf(data["username"]);
|
|
230
|
+
const id = identityOf(data);
|
|
198
231
|
return {
|
|
199
232
|
status: "healthy",
|
|
200
233
|
...(id === undefined
|
|
@@ -231,7 +264,7 @@ export class ConfluenceProvider {
|
|
|
231
264
|
// resolved first and verified before anything is fetched for the answer.
|
|
232
265
|
// Comments resolve their page inside their own read, a page read inside
|
|
233
266
|
// its own.
|
|
234
|
-
await this.assertPageReachable(instance, credential, numericId(input["pageId"], "pageId"), flags, boundary);
|
|
267
|
+
await this.assertPageReachable(instance, credential, numericId(input["pageId"], "pageId"), flags, boundary, dialectOf(instance));
|
|
235
268
|
}
|
|
236
269
|
if (boundary !== undefined && operation === "spaces.get") {
|
|
237
270
|
const ref = spaceRef(input["space"]);
|
|
@@ -246,15 +279,17 @@ export class ConfluenceProvider {
|
|
|
246
279
|
const prepared = boundary !== undefined && operation === "search.run"
|
|
247
280
|
? this.boundedSearchInput(input, boundary, flags)
|
|
248
281
|
: input;
|
|
282
|
+
const dialect = dialectOf(instance);
|
|
249
283
|
const request = handler(prepared, {
|
|
250
284
|
externalUserId: context.externalUserId,
|
|
251
285
|
flags,
|
|
286
|
+
dialect,
|
|
252
287
|
});
|
|
253
288
|
if (operation === "pages.get") {
|
|
254
|
-
return this.readPage(instance, credential, request, flags, prepared, boundary);
|
|
289
|
+
return this.readPage(instance, credential, request, flags, prepared, boundary, dialect);
|
|
255
290
|
}
|
|
256
291
|
if (operation === "pages.comments") {
|
|
257
|
-
return this.readComments(instance, credential,
|
|
292
|
+
return this.readComments(instance, credential, flags, prepared, boundary, dialect);
|
|
258
293
|
}
|
|
259
294
|
if (operation === "spaces.get") {
|
|
260
295
|
return this.readSpace(instance, credential, request, flags, boundary);
|
|
@@ -277,7 +312,13 @@ export class ConfluenceProvider {
|
|
|
277
312
|
const items = Array.isArray(answer["items"]) ? answer["items"] : [];
|
|
278
313
|
answer["items"] = items.filter((item) => this.itemSpaceReachable(item, flags, boundary));
|
|
279
314
|
}
|
|
280
|
-
|
|
315
|
+
// An offset-paged read counts its own rows, but the product's own `next`
|
|
316
|
+
// link is authoritative when it has one: it says where the next page really
|
|
317
|
+
// begins, which matters when a row of this page was dropped by a policy.
|
|
318
|
+
const upstream = response.page?.nextCursor;
|
|
319
|
+
const nextCursor = cursorMode === "upstream"
|
|
320
|
+
? upstream
|
|
321
|
+
: (answer["nextCursor"] ?? upstream);
|
|
281
322
|
return nextCursor === undefined ? answer : { ...answer, nextCursor };
|
|
282
323
|
}
|
|
283
324
|
/**
|
|
@@ -286,13 +327,10 @@ export class ConfluenceProvider {
|
|
|
286
327
|
* not allow is refused here, after the read and before the model sees it. In
|
|
287
328
|
* service mode the boundary is verified on the same resolved space.
|
|
288
329
|
*/
|
|
289
|
-
async readPage(instance, credential, request, flags, input, boundary) {
|
|
330
|
+
async readPage(instance, credential, request, flags, input, boundary, dialect) {
|
|
290
331
|
const projection = CONFLUENCE_PROJECTIONS["pages.get"];
|
|
291
332
|
const response = await this.transport.getJson(instance, credential, request.path, request.query);
|
|
292
|
-
const
|
|
293
|
-
const space = spaceId === undefined
|
|
294
|
-
? {}
|
|
295
|
-
: await this.readSpaceFields(instance, credential, spaceId);
|
|
333
|
+
const space = await this.spaceOfPage(instance, credential, response.data, dialect);
|
|
296
334
|
this.assertSpaceReachable(flags, textOf(space["key"]), boundary);
|
|
297
335
|
return (projection?.(response.data, {
|
|
298
336
|
...this.projectionContext(flags, instance, input),
|
|
@@ -305,35 +343,48 @@ export class ConfluenceProvider {
|
|
|
305
343
|
* cost one request per parent comment, so a discussion wider than the
|
|
306
344
|
* deployment cap is answered with the parents it did load and says so.
|
|
307
345
|
*/
|
|
308
|
-
async readComments(instance, credential,
|
|
346
|
+
async readComments(instance, credential, flags, input, boundary, dialect) {
|
|
309
347
|
const projection = CONFLUENCE_PROJECTIONS["pages.comments"];
|
|
310
348
|
const pageId = numericId(input["pageId"], "pageId");
|
|
311
349
|
const kind = commentKind(input["kind"]);
|
|
312
350
|
if (flags.allowedSpaces.length > 0 || boundary !== undefined) {
|
|
313
|
-
await this.assertPageReachable(instance, credential, pageId, flags, boundary);
|
|
351
|
+
await this.assertPageReachable(instance, credential, pageId, flags, boundary, dialect);
|
|
314
352
|
}
|
|
315
353
|
const includeReplies = typeof input["includeReplies"] === "boolean" && input["includeReplies"];
|
|
316
|
-
|
|
354
|
+
// Cloud keeps the two kinds in two collections, so a kind selects one; a
|
|
355
|
+
// Server / Data Center installation keeps both in one and marks each
|
|
356
|
+
// comment, so every kind is read from that one collection.
|
|
357
|
+
const collections = dialect.commentKinds === "path" ? commentCollections(kind) : ["footer"];
|
|
358
|
+
const cursor = listingCursor(input["cursor"], dialect);
|
|
359
|
+
const limit = pageLimit(input["limit"], flags);
|
|
317
360
|
const items = [];
|
|
318
361
|
const cursors = {};
|
|
319
362
|
let repliesTruncated = false;
|
|
320
363
|
for (const collection of collections) {
|
|
321
|
-
const
|
|
364
|
+
const call = commentPath(dialect, pageId, collection, cursor, limit);
|
|
365
|
+
const response = await this.transport.getJson(instance, credential, call.path, call.query);
|
|
322
366
|
const context = {
|
|
323
367
|
...this.projectionContext(flags, instance, input),
|
|
324
368
|
pageId,
|
|
325
369
|
kind: collection,
|
|
326
370
|
};
|
|
327
371
|
const projected = projection?.(response.data, context) ?? {};
|
|
328
|
-
const
|
|
372
|
+
const projectedRows = Array.isArray(projected["items"])
|
|
373
|
+
? projected["items"]
|
|
374
|
+
: [];
|
|
375
|
+
// The marker dialect answered one collection for every kind, so a kind
|
|
376
|
+
// the caller named is applied to the rows the product marked.
|
|
377
|
+
const rows = dialect.commentKinds === "marker" && kind !== "all"
|
|
378
|
+
? projectedRows.filter((row) => commentMarker(row) === kind)
|
|
379
|
+
: projectedRows;
|
|
329
380
|
const loaded = includeReplies
|
|
330
|
-
? await this.withReplies(instance, credential, rows, collection, flags, context)
|
|
381
|
+
? await this.withReplies(instance, credential, rows, collection, flags, context, dialect)
|
|
331
382
|
: { items: rows, truncated: false };
|
|
332
383
|
repliesTruncated = repliesTruncated || loaded.truncated;
|
|
333
384
|
items.push(...loaded.items);
|
|
334
|
-
const
|
|
335
|
-
if (
|
|
336
|
-
cursors[collection] =
|
|
385
|
+
const next = response.page?.nextCursor;
|
|
386
|
+
if (next !== undefined)
|
|
387
|
+
cursors[collection] = next;
|
|
337
388
|
}
|
|
338
389
|
const answer = {
|
|
339
390
|
source: confluenceSource(instance, { pageId }),
|
|
@@ -343,12 +394,12 @@ export class ConfluenceProvider {
|
|
|
343
394
|
return { ...answer, cursors, repliesTruncated };
|
|
344
395
|
return {
|
|
345
396
|
...answer,
|
|
346
|
-
nextCursor: cursors[
|
|
397
|
+
nextCursor: cursors[collections[0] ?? "footer"],
|
|
347
398
|
...(repliesTruncated ? { repliesTruncated: true } : {}),
|
|
348
399
|
};
|
|
349
400
|
}
|
|
350
401
|
/** One children read per parent comment, capped by the deployment. */
|
|
351
|
-
async withReplies(instance, credential, rows, collection, flags, context) {
|
|
402
|
+
async withReplies(instance, credential, rows, collection, flags, context, dialect) {
|
|
352
403
|
const cap = Math.max(flags.maxReplyParents, 0);
|
|
353
404
|
const items = [];
|
|
354
405
|
for (const [index, row] of rows.entries()) {
|
|
@@ -361,11 +412,11 @@ export class ConfluenceProvider {
|
|
|
361
412
|
items.push(row);
|
|
362
413
|
continue;
|
|
363
414
|
}
|
|
364
|
-
const
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
415
|
+
const call = commentChildrenPath(dialect,
|
|
416
|
+
// A row of the marker dialect names its own kind; a reply belongs to the
|
|
417
|
+
// collection its parent was read from.
|
|
418
|
+
commentMarker(row) ?? collection, numericId(id, "commentId"), undefined, pageLimit(undefined, flags));
|
|
419
|
+
const response = await this.transport.getJson(instance, credential, call.path, call.query);
|
|
369
420
|
items.push({
|
|
370
421
|
...row,
|
|
371
422
|
replies: commentReplies(response.data, collection, context),
|
|
@@ -451,7 +502,13 @@ export class ConfluenceProvider {
|
|
|
451
502
|
const unavailable = [];
|
|
452
503
|
for (const key of entries) {
|
|
453
504
|
try {
|
|
454
|
-
const
|
|
505
|
+
const call = dialectOf(instance).spaceList({
|
|
506
|
+
keys: [key],
|
|
507
|
+
type,
|
|
508
|
+
cursor: undefined,
|
|
509
|
+
limit: 2,
|
|
510
|
+
});
|
|
511
|
+
const { data } = await this.transport.getJson(instance, credential, call.path, call.query);
|
|
455
512
|
const projected = projection?.(data, { flags, instance }) ?? {};
|
|
456
513
|
const rows = Array.isArray(projected["items"])
|
|
457
514
|
? projected["items"]
|
|
@@ -474,26 +531,44 @@ export class ConfluenceProvider {
|
|
|
474
531
|
};
|
|
475
532
|
}
|
|
476
533
|
/** The fields a space contributes to a page answer, plus its policy key. */
|
|
477
|
-
async readSpaceFields(instance, credential, spaceId) {
|
|
478
|
-
const
|
|
479
|
-
|
|
480
|
-
`/wiki/api/v2/spaces/${numericId(spaceId, "spaceId")}`, {});
|
|
534
|
+
async readSpaceFields(instance, credential, spaceId, dialect) {
|
|
535
|
+
const call = dialect.spacePath(numericId(spaceId, "spaceId"));
|
|
536
|
+
const { data } = await this.transport.getJson(instance, credential, call.path, call.query);
|
|
481
537
|
return data;
|
|
482
538
|
}
|
|
539
|
+
/**
|
|
540
|
+
* The space a page belongs to, as the product reports it. Cloud names the
|
|
541
|
+
* space by an id on the page, so it is resolved with a second read; a
|
|
542
|
+
* Server / Data Center installation carries the space itself on the page, and
|
|
543
|
+
* that read would be spent for nothing.
|
|
544
|
+
*/
|
|
545
|
+
async spaceOfPage(instance, credential, page, dialect) {
|
|
546
|
+
const inline = recordOf(page["space"]);
|
|
547
|
+
if (Object.keys(inline).length > 0)
|
|
548
|
+
return inline;
|
|
549
|
+
const spaceId = textOf(page["spaceId"]);
|
|
550
|
+
return spaceId === undefined
|
|
551
|
+
? {}
|
|
552
|
+
: await this.readSpaceFields(instance, credential, spaceId, dialect);
|
|
553
|
+
}
|
|
483
554
|
/**
|
|
484
555
|
* The space of a page the call is about. Asked for whenever a policy needs
|
|
485
556
|
* it: the deployment allowlist, or — in service mode — the boundary, which is
|
|
486
557
|
* always there. Without either there is no policy to enforce, and the extra
|
|
487
558
|
* reads would be spent for nothing.
|
|
488
559
|
*/
|
|
489
|
-
async assertPageReachable(instance, credential, pageId, flags, boundary) {
|
|
490
|
-
const
|
|
491
|
-
const
|
|
492
|
-
|
|
560
|
+
async assertPageReachable(instance, credential, pageId, flags, boundary, dialect) {
|
|
561
|
+
const call = dialect.pageSpacePath(pageId);
|
|
562
|
+
const { data } = await this.transport.getJson(instance, credential, call.path, call.query);
|
|
563
|
+
const space = await this.spaceOfPage(instance, credential, data, dialect);
|
|
564
|
+
const key = textOf(space["key"]);
|
|
565
|
+
if (key === undefined) {
|
|
566
|
+
// A page answer that names no space at all is a page that is not there —
|
|
567
|
+
// or one the credentials may not see, which Confluence answers the same
|
|
568
|
+
// way on purpose.
|
|
493
569
|
throw new IntegrationError("ResourceNotFound", "Confluence page not found");
|
|
494
570
|
}
|
|
495
|
-
|
|
496
|
-
this.assertSpaceReachable(flags, textOf(space["key"]), boundary);
|
|
571
|
+
this.assertSpaceReachable(flags, key, boundary);
|
|
497
572
|
}
|
|
498
573
|
/**
|
|
499
574
|
* Both space policies of one read, in the order a refusal should name them:
|
|
@@ -562,25 +637,6 @@ export class ConfluenceProvider {
|
|
|
562
637
|
}
|
|
563
638
|
}
|
|
564
639
|
/** 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
640
|
/** 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
|
-
}
|
|
585
641
|
export default ConfluenceProvider;
|
|
586
642
|
//# sourceMappingURL=index.js.map
|