@yadsh/dsh-qa-integrations 0.5.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.
- package/README.md +636 -202
- package/compatibility.json +1 -1
- package/lib/broker.js +468 -9
- package/lib/broker.js.map +1 -1
- package/lib/client/bitrix24.js +67 -5
- package/lib/client/bitrix24.js.map +1 -1
- package/lib/client/card.js +8 -1
- package/lib/client/card.js.map +1 -1
- package/lib/client/confluence.js +98 -129
- package/lib/client/confluence.js.map +1 -1
- package/lib/client/gitlab.js +41 -5
- package/lib/client/gitlab.js.map +1 -1
- package/lib/client/index.js +33 -11
- package/lib/client/index.js.map +1 -1
- package/lib/client/integrations.js +40 -3
- package/lib/client/integrations.js.map +1 -1
- package/lib/client/jira.js +96 -127
- package/lib/client/jira.js.map +1 -1
- package/lib/client/operator-card.js +537 -0
- package/lib/client/operator-card.js.map +1 -0
- package/lib/client/operator-controls.js +232 -0
- package/lib/client/operator-controls.js.map +1 -0
- package/lib/client/provider-card.js +138 -4
- package/lib/client/provider-card.js.map +1 -1
- package/lib/client/styles.js +68 -5
- package/lib/client/styles.js.map +1 -1
- package/lib/client/teamcity.js +31 -4
- package/lib/client/teamcity.js.map +1 -1
- package/lib/client/testit.js +101 -0
- package/lib/client/testit.js.map +1 -0
- package/lib/client/weblate.js +105 -0
- package/lib/client/weblate.js.map +1 -0
- package/lib/client.js +5214 -1054
- package/lib/client.js.map +1 -1
- package/lib/coerce.js +16 -7
- package/lib/coerce.js.map +1 -1
- package/lib/config.js +12 -0
- package/lib/config.js.map +1 -1
- package/lib/errors.js.map +1 -1
- package/lib/index.js +444 -57
- package/lib/index.js.map +1 -1
- package/lib/providers/bitrix24/catalog.js +151 -8
- package/lib/providers/bitrix24/catalog.js.map +1 -1
- package/lib/providers/bitrix24/config.js +87 -13
- package/lib/providers/bitrix24/config.js.map +1 -1
- package/lib/providers/bitrix24/credential-help.js +24 -0
- package/lib/providers/bitrix24/credential-help.js.map +1 -0
- package/lib/providers/bitrix24/index.js +122 -0
- package/lib/providers/bitrix24/index.js.map +1 -1
- package/lib/providers/bitrix24/operations.js +60 -1
- package/lib/providers/bitrix24/operations.js.map +1 -1
- package/lib/providers/bitrix24/tools.js +95 -3
- package/lib/providers/bitrix24/tools.js.map +1 -1
- package/lib/providers/confluence/catalog.js +51 -3
- package/lib/providers/confluence/catalog.js.map +1 -1
- package/lib/providers/confluence/credential-help.js +29 -0
- package/lib/providers/confluence/credential-help.js.map +1 -0
- package/lib/providers/confluence/index.js +302 -35
- package/lib/providers/confluence/index.js.map +1 -1
- package/lib/providers/confluence/operations.js +1 -1
- package/lib/providers/confluence/operations.js.map +1 -1
- package/lib/providers/gitlab/catalog.js +108 -15
- package/lib/providers/gitlab/catalog.js.map +1 -1
- package/lib/providers/gitlab/config.js +11 -3
- package/lib/providers/gitlab/config.js.map +1 -1
- package/lib/providers/gitlab/credential-help.js +33 -0
- package/lib/providers/gitlab/credential-help.js.map +1 -0
- package/lib/providers/gitlab/index.js +337 -6
- package/lib/providers/gitlab/index.js.map +1 -1
- package/lib/providers/jira/catalog.js +73 -3
- package/lib/providers/jira/catalog.js.map +1 -1
- package/lib/providers/jira/credential-help.js +31 -0
- package/lib/providers/jira/credential-help.js.map +1 -0
- package/lib/providers/jira/index.js +275 -12
- package/lib/providers/jira/index.js.map +1 -1
- package/lib/providers/registry.js +4 -0
- package/lib/providers/registry.js.map +1 -1
- package/lib/providers/shared/credential-help.js +29 -0
- package/lib/providers/shared/credential-help.js.map +1 -0
- package/lib/providers/shared/service-boundary.js +44 -0
- package/lib/providers/shared/service-boundary.js.map +1 -0
- package/lib/providers/teamcity/catalog.js +56 -2
- package/lib/providers/teamcity/catalog.js.map +1 -1
- package/lib/providers/teamcity/credential-help.js +25 -0
- package/lib/providers/teamcity/credential-help.js.map +1 -0
- package/lib/providers/teamcity/index.js +254 -2
- package/lib/providers/teamcity/index.js.map +1 -1
- package/lib/providers/testit/attachments.js +131 -0
- package/lib/providers/testit/attachments.js.map +1 -0
- package/lib/providers/testit/catalog.js +302 -0
- package/lib/providers/testit/catalog.js.map +1 -0
- package/lib/providers/testit/config.js +175 -0
- package/lib/providers/testit/config.js.map +1 -0
- package/lib/providers/testit/credential-help.js +29 -0
- package/lib/providers/testit/credential-help.js.map +1 -0
- package/lib/providers/testit/index.js +458 -0
- package/lib/providers/testit/index.js.map +1 -0
- package/lib/providers/testit/operations.js +1070 -0
- package/lib/providers/testit/operations.js.map +1 -0
- package/lib/providers/testit/tools.js +717 -0
- package/lib/providers/testit/tools.js.map +1 -0
- package/lib/providers/testit/transport.js +158 -0
- package/lib/providers/testit/transport.js.map +1 -0
- package/lib/providers/weblate/catalog.js +279 -0
- package/lib/providers/weblate/catalog.js.map +1 -0
- package/lib/providers/weblate/config.js +147 -0
- package/lib/providers/weblate/config.js.map +1 -0
- package/lib/providers/weblate/credential-help.js +26 -0
- package/lib/providers/weblate/credential-help.js.map +1 -0
- package/lib/providers/weblate/index.js +419 -0
- package/lib/providers/weblate/index.js.map +1 -0
- package/lib/providers/weblate/operations.js +703 -0
- package/lib/providers/weblate/operations.js.map +1 -0
- package/lib/providers/weblate/query.js +80 -0
- package/lib/providers/weblate/query.js.map +1 -0
- package/lib/providers/weblate/tools.js +408 -0
- package/lib/providers/weblate/tools.js.map +1 -0
- package/lib/providers/weblate/transport.js +179 -0
- package/lib/providers/weblate/transport.js.map +1 -0
- package/lib/repository.js +197 -13
- package/lib/repository.js.map +1 -1
- package/lib/service-credentials/config.js +179 -0
- package/lib/service-credentials/config.js.map +1 -0
- package/lib/service-credentials/policy.js +92 -0
- package/lib/service-credentials/policy.js.map +1 -0
- package/lib/service-credentials/registry.js +142 -0
- package/lib/service-credentials/registry.js.map +1 -0
- package/lib/service-credentials/state.js +30 -0
- package/lib/service-credentials/state.js.map +1 -0
- package/lib/service-credentials/types.js +20 -0
- package/lib/service-credentials/types.js.map +1 -0
- package/lib/shared/settings.js +8 -13
- package/lib/shared/settings.js.map +1 -1
- package/lib/tools.js +27 -2
- package/lib/tools.js.map +1 -1
- package/lib/typert.host.js +1340 -100
- package/lib/typert.remote-client.d.ts +45 -11
- package/lib/typert.remote-client.js +1101 -38
- package/lib/types/broker.d.ts +79 -5
- package/lib/types/client/bitrix24.d.ts +24 -2
- package/lib/types/client/card.d.ts +3 -1
- package/lib/types/client/confluence.d.ts +19 -3
- package/lib/types/client/gitlab.d.ts +15 -2
- package/lib/types/client/index.d.ts +7 -5
- package/lib/types/client/integrations.d.ts +12 -3
- package/lib/types/client/jira.d.ts +20 -3
- package/lib/types/client/operator-card.d.ts +22 -0
- package/lib/types/client/operator-controls.d.ts +135 -0
- package/lib/types/client/provider-card.d.ts +50 -8
- package/lib/types/client/styles.d.ts +4 -3
- package/lib/types/client/teamcity.d.ts +15 -2
- package/lib/types/client/testit.d.ts +28 -0
- package/lib/types/client/weblate.d.ts +28 -0
- package/lib/types/coerce.d.ts +2 -2
- package/lib/types/config.d.ts +21 -0
- package/lib/types/errors.d.ts +9 -1
- package/lib/types/index.d.ts +183 -18
- package/lib/types/providers/bitrix24/catalog.d.ts +9 -1
- package/lib/types/providers/bitrix24/config.d.ts +23 -22
- package/lib/types/providers/bitrix24/credential-help.d.ts +8 -0
- package/lib/types/providers/bitrix24/index.d.ts +41 -1
- package/lib/types/providers/bitrix24/tools.d.ts +4 -0
- package/lib/types/providers/confluence/catalog.d.ts +11 -3
- package/lib/types/providers/confluence/credential-help.d.ts +9 -0
- package/lib/types/providers/confluence/index.d.ts +66 -7
- package/lib/types/providers/confluence/operations.d.ts +2 -0
- package/lib/types/providers/contract.d.ts +62 -1
- package/lib/types/providers/gitlab/catalog.d.ts +20 -5
- package/lib/types/providers/gitlab/config.d.ts +14 -3
- package/lib/types/providers/gitlab/credential-help.d.ts +9 -0
- package/lib/types/providers/gitlab/index.d.ts +51 -1
- package/lib/types/providers/jira/catalog.d.ts +13 -0
- package/lib/types/providers/jira/credential-help.d.ts +8 -0
- package/lib/types/providers/jira/index.d.ts +53 -1
- package/lib/types/providers/registry.d.ts +2 -0
- package/lib/types/providers/shared/credential-help.d.ts +17 -0
- package/lib/types/providers/shared/service-boundary.d.ts +25 -0
- package/lib/types/providers/teamcity/catalog.d.ts +18 -2
- package/lib/types/providers/teamcity/credential-help.d.ts +8 -0
- package/lib/types/providers/teamcity/index.d.ts +53 -2
- package/lib/types/providers/testit/attachments.d.ts +20 -0
- package/lib/types/providers/testit/catalog.d.ts +87 -0
- package/lib/types/providers/testit/config.d.ts +61 -0
- package/lib/types/providers/testit/credential-help.d.ts +8 -0
- package/lib/types/providers/testit/index.d.ts +119 -0
- package/lib/types/providers/testit/operations.d.ts +95 -0
- package/lib/types/providers/testit/tools.d.ts +15 -0
- package/lib/types/providers/testit/transport.d.ts +67 -0
- package/lib/types/providers/weblate/catalog.d.ts +60 -0
- package/lib/types/providers/weblate/config.d.ts +57 -0
- package/lib/types/providers/weblate/credential-help.d.ts +9 -0
- package/lib/types/providers/weblate/index.d.ts +92 -0
- package/lib/types/providers/weblate/operations.d.ts +77 -0
- package/lib/types/providers/weblate/query.d.ts +37 -0
- package/lib/types/providers/weblate/tools.d.ts +15 -0
- package/lib/types/providers/weblate/transport.d.ts +60 -0
- package/lib/types/repository.d.ts +38 -3
- package/lib/types/service-credentials/config.d.ts +73 -0
- package/lib/types/service-credentials/policy.d.ts +44 -0
- package/lib/types/service-credentials/registry.d.ts +43 -0
- package/lib/types/service-credentials/state.d.ts +14 -0
- package/lib/types/service-credentials/types.d.ts +97 -0
- package/lib/types/shared/settings.d.ts +8 -13
- package/lib/types/tools.d.ts +10 -1
- package/lib/types/types.d.ts +114 -10
- package/package.json +7 -7
|
@@ -0,0 +1,703 @@
|
|
|
1
|
+
import { optionalInteger, requiredInteger, requiredText, } from "../../coerce.js";
|
|
2
|
+
import { IntegrationError } from "../../errors.js";
|
|
3
|
+
import { accountName } from "../shared/account.js";
|
|
4
|
+
import { COMMENT_CLAUSE, FAILING_CHECK_CLAUSE, SUGGESTION_CLAUSE, buildUnitQuery, exactClause, isUnitStateFilter, stateClause, textClause, } from "./query.js";
|
|
5
|
+
import { resultsOf } from "./transport.js";
|
|
6
|
+
/**
|
|
7
|
+
* Weblate project and component slugs are the same character set upstream
|
|
8
|
+
* (`[-a-zA-Z0-9_]+`); components nested in categories put the category path in
|
|
9
|
+
* front of the slug, one path segment per level.
|
|
10
|
+
*/
|
|
11
|
+
const SLUG = /^[-A-Za-z0-9_]+$/u;
|
|
12
|
+
/** Language codes, including the `pt_BR` and `sr@latin` style aliases. */
|
|
13
|
+
const LANGUAGE_CODE = /^[A-Za-z0-9][A-Za-z0-9@._+-]{0,49}$/u;
|
|
14
|
+
/** Rows per page when the agent does not ask for more. */
|
|
15
|
+
export const DEFAULT_PAGE_SIZE = 20;
|
|
16
|
+
/** Characters of one source/target string in a list answer. */
|
|
17
|
+
export const SUMMARY_TEXT_CHARS = 200;
|
|
18
|
+
/** Unit URLs attached to a screenshot; enough to identify, bounded anyway. */
|
|
19
|
+
const SCREENSHOT_UNIT_LIMIT = 50;
|
|
20
|
+
function invalid(field) {
|
|
21
|
+
throw new IntegrationError("InvalidRequest", `${field} is invalid`);
|
|
22
|
+
}
|
|
23
|
+
function hasTraversal(value) {
|
|
24
|
+
return value
|
|
25
|
+
.split("/")
|
|
26
|
+
.some((segment) => segment === ".." || segment === ".");
|
|
27
|
+
}
|
|
28
|
+
/** A slug, URL-encoded as one path segment. */
|
|
29
|
+
function slug(value, field) {
|
|
30
|
+
const normalized = requiredText(value, field, 1, 100);
|
|
31
|
+
if (!SLUG.test(normalized))
|
|
32
|
+
invalid(field);
|
|
33
|
+
return encodeURIComponent(normalized);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* A component reference: one slug, or a category path in front of it. Every
|
|
37
|
+
* segment is validated and encoded on its own, so the separator that joins them
|
|
38
|
+
* is the provider's and never a character the caller smuggled in.
|
|
39
|
+
*/
|
|
40
|
+
export function componentRef(value, field = "component") {
|
|
41
|
+
const normalized = requiredText(value, field, 1, 255).replace(/^\/+|\/+$/gu, "");
|
|
42
|
+
if (normalized === "" || hasTraversal(normalized))
|
|
43
|
+
invalid(field);
|
|
44
|
+
const segments = normalized.split("/");
|
|
45
|
+
if (segments.length > 8)
|
|
46
|
+
invalid(field);
|
|
47
|
+
const encoded = [];
|
|
48
|
+
for (const segment of segments) {
|
|
49
|
+
if (!SLUG.test(segment))
|
|
50
|
+
invalid(field);
|
|
51
|
+
encoded.push(encodeURIComponent(segment));
|
|
52
|
+
}
|
|
53
|
+
return encoded.join("/");
|
|
54
|
+
}
|
|
55
|
+
export function projectRef(value, field = "project") {
|
|
56
|
+
return slug(value, field);
|
|
57
|
+
}
|
|
58
|
+
export function languageRef(value, field = "language") {
|
|
59
|
+
const normalized = requiredText(value, field, 1, 50);
|
|
60
|
+
if (!LANGUAGE_CODE.test(normalized))
|
|
61
|
+
invalid(field);
|
|
62
|
+
return encodeURIComponent(normalized);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* One page of a collection, plus the cursor the model has to send back. An
|
|
66
|
+
* oversized page is clamped rather than refused: "give me more rows" is a
|
|
67
|
+
* request this deployment answers with its own ceiling, not an error the agent
|
|
68
|
+
* has to learn by trial.
|
|
69
|
+
*/
|
|
70
|
+
function pagination(input, flags) {
|
|
71
|
+
const asked = optionalInteger(input["perPage"], "perPage", 1, 10_000);
|
|
72
|
+
const perPage = Math.min(asked ?? DEFAULT_PAGE_SIZE, flags.maxPageSize);
|
|
73
|
+
const page = optionalInteger(input["page"], "page", 1) ?? 1;
|
|
74
|
+
return { page, perPage, query: { page, page_size: perPage } };
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* The `q` clauses the agent's filters translate into. Only documented lookups of
|
|
78
|
+
* Weblate's own search grammar are used; the query string itself is never
|
|
79
|
+
* accepted from the model.
|
|
80
|
+
*/
|
|
81
|
+
function unitQuery(input, extra = []) {
|
|
82
|
+
const state = input["state"];
|
|
83
|
+
if (state !== undefined && !isUnitStateFilter(state))
|
|
84
|
+
invalid("state");
|
|
85
|
+
const text = (field) => input[field] === undefined
|
|
86
|
+
? []
|
|
87
|
+
: [textClause(field, requiredText(input[field], field, 1, 200))];
|
|
88
|
+
return buildUnitQuery([
|
|
89
|
+
...text("source"),
|
|
90
|
+
...text("target"),
|
|
91
|
+
...text("context"),
|
|
92
|
+
...(state === undefined ? [] : [stateClause(state)]),
|
|
93
|
+
...(input["failingChecks"] === true ? [FAILING_CHECK_CLAUSE] : []),
|
|
94
|
+
...(input["suggestions"] === true ? [SUGGESTION_CLAUSE] : []),
|
|
95
|
+
...(input["comments"] === true ? [COMMENT_CLAUSE] : []),
|
|
96
|
+
...extra,
|
|
97
|
+
]);
|
|
98
|
+
}
|
|
99
|
+
/** Numeric id of a model-named resource; Weblate ids are positive integers. */
|
|
100
|
+
function identifier(value, field) {
|
|
101
|
+
return requiredInteger(value, field);
|
|
102
|
+
}
|
|
103
|
+
function fill(template, values) {
|
|
104
|
+
return Object.entries(values).reduce((path, [key, value]) => path.replace(`:${key}`, value), template);
|
|
105
|
+
}
|
|
106
|
+
export const WEBLATE_HANDLERS = Object.freeze({
|
|
107
|
+
"connection.get": () => ({
|
|
108
|
+
path: "/users/",
|
|
109
|
+
// Two rows are enough to tell "only me" from "the token may list users",
|
|
110
|
+
// which is the whole question this operation answers.
|
|
111
|
+
query: { page_size: 2 },
|
|
112
|
+
}),
|
|
113
|
+
"projects.list": (input, context) => {
|
|
114
|
+
const { page, perPage, query } = pagination(input, context.flags);
|
|
115
|
+
return { path: "/projects/", query, page: { page, perPage } };
|
|
116
|
+
},
|
|
117
|
+
"projects.get": (input) => ({
|
|
118
|
+
path: fill("/projects/:project/", {
|
|
119
|
+
project: projectRef(input["project"]),
|
|
120
|
+
}),
|
|
121
|
+
query: {},
|
|
122
|
+
}),
|
|
123
|
+
"projects.statistics": (input) => ({
|
|
124
|
+
path: fill("/projects/:project/statistics/", {
|
|
125
|
+
project: projectRef(input["project"]),
|
|
126
|
+
}),
|
|
127
|
+
query: {},
|
|
128
|
+
}),
|
|
129
|
+
"components.list": (input, context) => {
|
|
130
|
+
const { page, perPage, query } = pagination(input, context.flags);
|
|
131
|
+
return {
|
|
132
|
+
path: fill("/projects/:project/components/", {
|
|
133
|
+
project: projectRef(input["project"]),
|
|
134
|
+
}),
|
|
135
|
+
query,
|
|
136
|
+
page: { page, perPage },
|
|
137
|
+
};
|
|
138
|
+
},
|
|
139
|
+
"components.get": (input) => ({
|
|
140
|
+
path: fill("/components/:project/:component/", {
|
|
141
|
+
project: projectRef(input["project"]),
|
|
142
|
+
component: componentRef(input["component"]),
|
|
143
|
+
}),
|
|
144
|
+
query: {},
|
|
145
|
+
}),
|
|
146
|
+
"components.statistics": (input) => ({
|
|
147
|
+
path: fill("/components/:project/:component/statistics/", {
|
|
148
|
+
project: projectRef(input["project"]),
|
|
149
|
+
component: componentRef(input["component"]),
|
|
150
|
+
}),
|
|
151
|
+
query: {},
|
|
152
|
+
}),
|
|
153
|
+
"translations.list": (input, context) => {
|
|
154
|
+
const { page, perPage, query } = pagination(input, context.flags);
|
|
155
|
+
return {
|
|
156
|
+
path: fill("/components/:project/:component/translations/", {
|
|
157
|
+
project: projectRef(input["project"]),
|
|
158
|
+
component: componentRef(input["component"]),
|
|
159
|
+
}),
|
|
160
|
+
query,
|
|
161
|
+
page: { page, perPage },
|
|
162
|
+
};
|
|
163
|
+
},
|
|
164
|
+
"translations.get": (input) => ({
|
|
165
|
+
path: fill("/translations/:project/:component/:language/", {
|
|
166
|
+
project: projectRef(input["project"]),
|
|
167
|
+
component: componentRef(input["component"]),
|
|
168
|
+
language: languageRef(input["language"]),
|
|
169
|
+
}),
|
|
170
|
+
query: {},
|
|
171
|
+
}),
|
|
172
|
+
"translations.statistics": (input) => ({
|
|
173
|
+
path: fill("/translations/:project/:component/:language/statistics/", {
|
|
174
|
+
project: projectRef(input["project"]),
|
|
175
|
+
component: componentRef(input["component"]),
|
|
176
|
+
language: languageRef(input["language"]),
|
|
177
|
+
}),
|
|
178
|
+
query: {},
|
|
179
|
+
}),
|
|
180
|
+
"units.search": (input, context) => {
|
|
181
|
+
const { page, perPage, query } = pagination(input, context.flags);
|
|
182
|
+
const search = unitQuery(input);
|
|
183
|
+
return {
|
|
184
|
+
path: fill("/translations/:project/:component/:language/units/", {
|
|
185
|
+
project: projectRef(input["project"]),
|
|
186
|
+
component: componentRef(input["component"]),
|
|
187
|
+
language: languageRef(input["language"]),
|
|
188
|
+
}),
|
|
189
|
+
query: search === "" ? query : { ...query, q: search },
|
|
190
|
+
page: { page, perPage },
|
|
191
|
+
};
|
|
192
|
+
},
|
|
193
|
+
"units.find": (input, context) => {
|
|
194
|
+
const { page, perPage, query } = pagination(input, context.flags);
|
|
195
|
+
const search = unitQuery(input, [
|
|
196
|
+
...(input["project"] === undefined
|
|
197
|
+
? []
|
|
198
|
+
: [exactClause("project", projectRef(input["project"]))]),
|
|
199
|
+
...(input["component"] === undefined
|
|
200
|
+
? []
|
|
201
|
+
: [exactClause("component", componentRef(input["component"]))]),
|
|
202
|
+
...(input["language"] === undefined
|
|
203
|
+
? []
|
|
204
|
+
: [exactClause("language", languageRef(input["language"]))]),
|
|
205
|
+
]);
|
|
206
|
+
return {
|
|
207
|
+
path: "/units/",
|
|
208
|
+
query: search === "" ? query : { ...query, q: search },
|
|
209
|
+
page: { page, perPage },
|
|
210
|
+
};
|
|
211
|
+
},
|
|
212
|
+
"units.failing": (input, context) => {
|
|
213
|
+
const { page, perPage, query } = pagination(input, context.flags);
|
|
214
|
+
const search = unitQuery(input, [
|
|
215
|
+
FAILING_CHECK_CLAUSE,
|
|
216
|
+
...(input["project"] === undefined
|
|
217
|
+
? []
|
|
218
|
+
: [exactClause("project", projectRef(input["project"]))]),
|
|
219
|
+
...(input["component"] === undefined
|
|
220
|
+
? []
|
|
221
|
+
: [exactClause("component", componentRef(input["component"]))]),
|
|
222
|
+
...(input["language"] === undefined
|
|
223
|
+
? []
|
|
224
|
+
: [exactClause("language", languageRef(input["language"]))]),
|
|
225
|
+
]);
|
|
226
|
+
return {
|
|
227
|
+
path: "/units/",
|
|
228
|
+
// A set never repeats a clause, and the projection reports the check flag
|
|
229
|
+
// on every row so the agent can see which string failed.
|
|
230
|
+
query: { ...query, q: search },
|
|
231
|
+
page: { page, perPage },
|
|
232
|
+
};
|
|
233
|
+
},
|
|
234
|
+
"units.get": (input) => ({
|
|
235
|
+
path: fill("/units/:unitId/", {
|
|
236
|
+
unitId: String(identifier(input["unitId"], "unitId")),
|
|
237
|
+
}),
|
|
238
|
+
query: {},
|
|
239
|
+
}),
|
|
240
|
+
"units.comments": (input, context) => {
|
|
241
|
+
const { page, perPage, query } = pagination(input, context.flags);
|
|
242
|
+
return {
|
|
243
|
+
path: fill("/units/:unitId/comments/", {
|
|
244
|
+
unitId: String(identifier(input["unitId"], "unitId")),
|
|
245
|
+
}),
|
|
246
|
+
query,
|
|
247
|
+
page: { page, perPage },
|
|
248
|
+
};
|
|
249
|
+
},
|
|
250
|
+
"units.suggestions": (input, context) => {
|
|
251
|
+
const { page, perPage, query } = pagination(input, context.flags);
|
|
252
|
+
return {
|
|
253
|
+
path: fill("/units/:unitId/suggestions/", {
|
|
254
|
+
unitId: String(identifier(input["unitId"], "unitId")),
|
|
255
|
+
}),
|
|
256
|
+
query,
|
|
257
|
+
page: { page, perPage },
|
|
258
|
+
};
|
|
259
|
+
},
|
|
260
|
+
"changes.list": (input, context) => {
|
|
261
|
+
const { page, perPage, query } = pagination(input, context.flags);
|
|
262
|
+
return {
|
|
263
|
+
path: fill("/projects/:project/changes/", {
|
|
264
|
+
project: projectRef(input["project"]),
|
|
265
|
+
}),
|
|
266
|
+
query,
|
|
267
|
+
page: { page, perPage },
|
|
268
|
+
};
|
|
269
|
+
},
|
|
270
|
+
"screenshots.list": (input, context) => {
|
|
271
|
+
const { page, perPage, query } = pagination(input, context.flags);
|
|
272
|
+
return { path: "/screenshots/", query, page: { page, perPage } };
|
|
273
|
+
},
|
|
274
|
+
"screenshots.get": (input) => ({
|
|
275
|
+
path: fill("/screenshots/:screenshotId/", {
|
|
276
|
+
screenshotId: String(identifier(input["screenshotId"], "screenshotId")),
|
|
277
|
+
}),
|
|
278
|
+
query: {},
|
|
279
|
+
}),
|
|
280
|
+
});
|
|
281
|
+
function recordOf(value) {
|
|
282
|
+
return typeof value === "object" && value !== null && !Array.isArray(value)
|
|
283
|
+
? value
|
|
284
|
+
: {};
|
|
285
|
+
}
|
|
286
|
+
function stringOf(source, key) {
|
|
287
|
+
const value = source[key];
|
|
288
|
+
return typeof value === "string" && value !== "" ? value : undefined;
|
|
289
|
+
}
|
|
290
|
+
function numberOf(source, key) {
|
|
291
|
+
const value = source[key];
|
|
292
|
+
return typeof value === "number" && Number.isFinite(value)
|
|
293
|
+
? value
|
|
294
|
+
: undefined;
|
|
295
|
+
}
|
|
296
|
+
function booleanOf(source, key) {
|
|
297
|
+
const value = source[key];
|
|
298
|
+
return typeof value === "boolean" ? value : undefined;
|
|
299
|
+
}
|
|
300
|
+
/** Drop unset keys so a projection never answers with `undefined` holes. */
|
|
301
|
+
function compact(source) {
|
|
302
|
+
return Object.fromEntries(Object.entries(source).filter(([, value]) => value !== undefined));
|
|
303
|
+
}
|
|
304
|
+
/** Cut a string at a character budget without leaving half a surrogate pair. */
|
|
305
|
+
function clip(text, limit) {
|
|
306
|
+
if (text.length <= limit)
|
|
307
|
+
return text;
|
|
308
|
+
const cut = text.slice(0, limit);
|
|
309
|
+
const last = cut.charCodeAt(cut.length - 1);
|
|
310
|
+
return last >= 0xd800 && last <= 0xdbff ? cut.slice(0, -1) : cut;
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* A plural string as Weblate reports it: one string or one per plural form. The
|
|
314
|
+
* answer keeps the shape and says whether anything was cut, because a
|
|
315
|
+
* translation silently shorter than the real one would be read as the truth.
|
|
316
|
+
*/
|
|
317
|
+
function boundedStrings(value, limit) {
|
|
318
|
+
const items = typeof value === "string"
|
|
319
|
+
? [value]
|
|
320
|
+
: Array.isArray(value)
|
|
321
|
+
? value.filter((item) => typeof item === "string")
|
|
322
|
+
: [];
|
|
323
|
+
const truncated = items.some((item) => item.length > limit);
|
|
324
|
+
return { items: items.map((item) => clip(item, limit)), truncated };
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* Labels as Weblate reports them: unit labels carry their project and a colour
|
|
328
|
+
* next to the name, and only the name is a localization attribute.
|
|
329
|
+
*/
|
|
330
|
+
function labelNamesOf(source, key) {
|
|
331
|
+
const value = source[key];
|
|
332
|
+
if (!Array.isArray(value))
|
|
333
|
+
return [];
|
|
334
|
+
const names = [];
|
|
335
|
+
for (const item of value) {
|
|
336
|
+
if (typeof item === "string") {
|
|
337
|
+
names.push(item);
|
|
338
|
+
continue;
|
|
339
|
+
}
|
|
340
|
+
const name = recordOf(item)["name"];
|
|
341
|
+
if (typeof name === "string" && name !== "")
|
|
342
|
+
names.push(name);
|
|
343
|
+
}
|
|
344
|
+
return names;
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* Upstream URLs are echoed only when they point at the configured instance, and
|
|
348
|
+
* never followed: the provider answers with the address, it does not dial it.
|
|
349
|
+
*/
|
|
350
|
+
export function sameOriginUrl(value, origin) {
|
|
351
|
+
if (typeof value !== "string" || value.trim() === "")
|
|
352
|
+
return undefined;
|
|
353
|
+
try {
|
|
354
|
+
const url = new URL(value);
|
|
355
|
+
return url.origin === origin ? url.toString() : undefined;
|
|
356
|
+
}
|
|
357
|
+
catch {
|
|
358
|
+
return undefined;
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
/** Path segments of a same-origin API URL below `/api/<marker>/`. */
|
|
362
|
+
function apiSegments(value, origin, marker) {
|
|
363
|
+
const url = sameOriginUrl(value, origin);
|
|
364
|
+
if (url === undefined)
|
|
365
|
+
return undefined;
|
|
366
|
+
const segments = new URL(url).pathname
|
|
367
|
+
.split("/")
|
|
368
|
+
.filter((segment) => segment !== "")
|
|
369
|
+
.map((segment) => {
|
|
370
|
+
try {
|
|
371
|
+
return decodeURIComponent(segment);
|
|
372
|
+
}
|
|
373
|
+
catch {
|
|
374
|
+
return segment;
|
|
375
|
+
}
|
|
376
|
+
});
|
|
377
|
+
const markerAt = segments.indexOf(marker);
|
|
378
|
+
if (markerAt === -1)
|
|
379
|
+
return undefined;
|
|
380
|
+
const tail = segments.slice(markerAt + 1);
|
|
381
|
+
return tail.length === 0 ? undefined : tail;
|
|
382
|
+
}
|
|
383
|
+
/**
|
|
384
|
+
* Which project, component and language a unit belongs to, read out of the
|
|
385
|
+
* translation URL Weblate itself put in the answer. A category path keeps its
|
|
386
|
+
* place, so a component inside a category is reported and re-usable as the
|
|
387
|
+
* `component` argument of another call.
|
|
388
|
+
*/
|
|
389
|
+
export function translationRef(value, origin) {
|
|
390
|
+
const tail = apiSegments(value, origin, "translations");
|
|
391
|
+
if (tail === undefined || tail.length < 3)
|
|
392
|
+
return undefined;
|
|
393
|
+
return {
|
|
394
|
+
project: tail[0],
|
|
395
|
+
component: tail.slice(1, -1).join("/"),
|
|
396
|
+
language: tail[tail.length - 1],
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
/** The numeric id inside a same-origin `/api/units/<id>/` URL. */
|
|
400
|
+
function unitIdOf(value, origin) {
|
|
401
|
+
const tail = apiSegments(value, origin, "units");
|
|
402
|
+
if (tail === undefined || tail.length !== 1)
|
|
403
|
+
return undefined;
|
|
404
|
+
const id = Number(tail[0]);
|
|
405
|
+
return Number.isInteger(id) && id > 0 ? id : undefined;
|
|
406
|
+
}
|
|
407
|
+
/** The username inside a same-origin `/api/users/<username>/` URL. */
|
|
408
|
+
function usernameOf(value, origin) {
|
|
409
|
+
const tail = apiSegments(value, origin, "users");
|
|
410
|
+
if (tail === undefined || tail.length !== 1)
|
|
411
|
+
return undefined;
|
|
412
|
+
return tail[0];
|
|
413
|
+
}
|
|
414
|
+
/** Weblate's numeric unit states, as the API documents them. */
|
|
415
|
+
const UNIT_STATES = Object.freeze({
|
|
416
|
+
0: "untranslated",
|
|
417
|
+
10: "needs-editing",
|
|
418
|
+
20: "translated",
|
|
419
|
+
30: "approved",
|
|
420
|
+
100: "read-only",
|
|
421
|
+
});
|
|
422
|
+
export function unitState(value) {
|
|
423
|
+
return typeof value === "number"
|
|
424
|
+
? (UNIT_STATES[value] ?? "unknown")
|
|
425
|
+
: "unknown";
|
|
426
|
+
}
|
|
427
|
+
/**
|
|
428
|
+
* The Weblate account a `GET /api/users/` answer belongs to. An unprivileged
|
|
429
|
+
* token sees only itself, which is how the connected account is identified; a
|
|
430
|
+
* token that may list users answers with many rows, and then the account is
|
|
431
|
+
* reported as unknown rather than guessed from the first row.
|
|
432
|
+
*/
|
|
433
|
+
export function accountFromUsers(data) {
|
|
434
|
+
const users = resultsOf(data);
|
|
435
|
+
if (users.length !== 1)
|
|
436
|
+
return { account: null, resolved: false };
|
|
437
|
+
const source = recordOf(users[0]);
|
|
438
|
+
const id = numberOf(source, "id");
|
|
439
|
+
return {
|
|
440
|
+
account: compact({
|
|
441
|
+
id,
|
|
442
|
+
username: stringOf(source, "username"),
|
|
443
|
+
name: stringOf(source, "name"),
|
|
444
|
+
isBot: booleanOf(source, "is_bot"),
|
|
445
|
+
}),
|
|
446
|
+
resolved: true,
|
|
447
|
+
};
|
|
448
|
+
}
|
|
449
|
+
/**
|
|
450
|
+
* The name of the account as the Settings card shows it. An unresolved account
|
|
451
|
+
* falls back to whatever the caller names instead of a name picked at random.
|
|
452
|
+
*/
|
|
453
|
+
export function accountNameFrom(data, fallback) {
|
|
454
|
+
const { account } = accountFromUsers(data);
|
|
455
|
+
return account === null ? fallback : accountName(account, fallback);
|
|
456
|
+
}
|
|
457
|
+
/** External id the broker stores for this connection, when it is known. */
|
|
458
|
+
export function accountIdFrom(data) {
|
|
459
|
+
const { account } = accountFromUsers(data);
|
|
460
|
+
const id = account?.["id"];
|
|
461
|
+
return typeof id === "number" ? String(id) : "";
|
|
462
|
+
}
|
|
463
|
+
function projectSummary(value) {
|
|
464
|
+
const source = recordOf(value);
|
|
465
|
+
return compact({
|
|
466
|
+
id: numberOf(source, "id"),
|
|
467
|
+
name: stringOf(source, "name"),
|
|
468
|
+
slug: stringOf(source, "slug"),
|
|
469
|
+
webUrl: stringOf(source, "web_url"),
|
|
470
|
+
});
|
|
471
|
+
}
|
|
472
|
+
function languageSummary(value) {
|
|
473
|
+
const source = recordOf(value);
|
|
474
|
+
const code = stringOf(source, "code");
|
|
475
|
+
if (code === undefined)
|
|
476
|
+
return undefined;
|
|
477
|
+
return compact({
|
|
478
|
+
code,
|
|
479
|
+
name: stringOf(source, "name"),
|
|
480
|
+
pluralForms: numberOf(source, "plural_forms"),
|
|
481
|
+
});
|
|
482
|
+
}
|
|
483
|
+
function componentSummary(value) {
|
|
484
|
+
const source = recordOf(value);
|
|
485
|
+
return compact({
|
|
486
|
+
id: numberOf(source, "id"),
|
|
487
|
+
name: stringOf(source, "name"),
|
|
488
|
+
slug: stringOf(source, "slug"),
|
|
489
|
+
vcs: stringOf(source, "vcs"),
|
|
490
|
+
branch: stringOf(source, "branch"),
|
|
491
|
+
fileFormat: stringOf(source, "file_format"),
|
|
492
|
+
sourceLanguage: languageSummary(source["source_language"]),
|
|
493
|
+
webUrl: stringOf(source, "web_url"),
|
|
494
|
+
});
|
|
495
|
+
}
|
|
496
|
+
function translationSummary(value) {
|
|
497
|
+
const source = recordOf(value);
|
|
498
|
+
return compact({
|
|
499
|
+
// The nested listing removes the component, the single read keeps it.
|
|
500
|
+
component: componentSummary(source["component"]),
|
|
501
|
+
language: languageSummary(source["language"]),
|
|
502
|
+
languageCode: stringOf(source, "language_code"),
|
|
503
|
+
isTemplate: booleanOf(source, "is_template"),
|
|
504
|
+
filename: stringOf(source, "filename"),
|
|
505
|
+
total: numberOf(source, "total"),
|
|
506
|
+
translated: numberOf(source, "translated"),
|
|
507
|
+
translatedPercent: numberOf(source, "translated_percent"),
|
|
508
|
+
totalWords: numberOf(source, "total_words"),
|
|
509
|
+
translatedWords: numberOf(source, "translated_words"),
|
|
510
|
+
fuzzy: numberOf(source, "fuzzy"),
|
|
511
|
+
fuzzyPercent: numberOf(source, "fuzzy_percent"),
|
|
512
|
+
failingChecks: numberOf(source, "failing_checks"),
|
|
513
|
+
failingChecksPercent: numberOf(source, "failing_checks_percent"),
|
|
514
|
+
haveComment: numberOf(source, "have_comment"),
|
|
515
|
+
haveSuggestion: numberOf(source, "have_suggestion"),
|
|
516
|
+
lastAuthor: stringOf(source, "last_author"),
|
|
517
|
+
lastChange: stringOf(source, "last_change"),
|
|
518
|
+
translateUrl: stringOf(source, "translate_url"),
|
|
519
|
+
webUrl: stringOf(source, "web_url"),
|
|
520
|
+
});
|
|
521
|
+
}
|
|
522
|
+
function statisticsSummary(value) {
|
|
523
|
+
const source = recordOf(value);
|
|
524
|
+
return compact({
|
|
525
|
+
name: stringOf(source, "name"),
|
|
526
|
+
code: stringOf(source, "code"),
|
|
527
|
+
total: numberOf(source, "total"),
|
|
528
|
+
translated: numberOf(source, "translated"),
|
|
529
|
+
translatedPercent: numberOf(source, "translated_percent"),
|
|
530
|
+
totalWords: numberOf(source, "total_words"),
|
|
531
|
+
translatedWords: numberOf(source, "translated_words"),
|
|
532
|
+
fuzzy: numberOf(source, "fuzzy"),
|
|
533
|
+
fuzzyPercent: numberOf(source, "fuzzy_percent"),
|
|
534
|
+
failing: numberOf(source, "failing"),
|
|
535
|
+
failingPercent: numberOf(source, "failing_percent"),
|
|
536
|
+
lastAuthor: stringOf(source, "last_author"),
|
|
537
|
+
lastChange: stringOf(source, "last_change"),
|
|
538
|
+
translateUrl: stringOf(source, "translate_url"),
|
|
539
|
+
});
|
|
540
|
+
}
|
|
541
|
+
/**
|
|
542
|
+
* One localization string, normalized: the agent needs the source, the current
|
|
543
|
+
* translation, where the string lives and what Weblate thinks of it, and it
|
|
544
|
+
* needs to know when a value was cut.
|
|
545
|
+
*/
|
|
546
|
+
function unitSummary(value, context) {
|
|
547
|
+
const source = recordOf(value);
|
|
548
|
+
const ref = translationRef(source["translation"], context.origin);
|
|
549
|
+
const text = boundedStrings(source["source"], context.textLimit);
|
|
550
|
+
const target = boundedStrings(source["target"], context.textLimit);
|
|
551
|
+
const previous = boundedStrings(source["previous_source"], context.textLimit);
|
|
552
|
+
return compact({
|
|
553
|
+
id: numberOf(source, "id"),
|
|
554
|
+
project: ref?.["project"],
|
|
555
|
+
component: ref?.["component"],
|
|
556
|
+
language: stringOf(source, "language_code") ?? ref?.["language"],
|
|
557
|
+
state: unitState(source["state"]),
|
|
558
|
+
fuzzy: booleanOf(source, "fuzzy"),
|
|
559
|
+
translated: booleanOf(source, "translated"),
|
|
560
|
+
approved: booleanOf(source, "approved"),
|
|
561
|
+
pending: booleanOf(source, "pending"),
|
|
562
|
+
automaticallyTranslated: booleanOf(source, "automatically_translated"),
|
|
563
|
+
source: text.items,
|
|
564
|
+
target: target.items,
|
|
565
|
+
previousSource: previous.items.length === 0 ? undefined : previous.items,
|
|
566
|
+
textTruncated: text.truncated || target.truncated ? true : undefined,
|
|
567
|
+
context: stringOf(source, "context"),
|
|
568
|
+
note: stringOf(source, "note"),
|
|
569
|
+
explanation: stringOf(source, "explanation"),
|
|
570
|
+
location: stringOf(source, "location"),
|
|
571
|
+
flags: stringOf(source, "flags"),
|
|
572
|
+
priority: numberOf(source, "priority"),
|
|
573
|
+
numWords: numberOf(source, "num_words"),
|
|
574
|
+
position: numberOf(source, "position"),
|
|
575
|
+
hasSuggestion: booleanOf(source, "has_suggestion"),
|
|
576
|
+
hasComment: booleanOf(source, "has_comment"),
|
|
577
|
+
hasFailingCheck: booleanOf(source, "has_failing_check"),
|
|
578
|
+
labels: labelNamesOf(source, "labels"),
|
|
579
|
+
sourceUnitId: unitIdOf(source["source_unit"], context.origin),
|
|
580
|
+
webUrl: sameOriginUrl(source["web_url"], context.origin),
|
|
581
|
+
timestamp: stringOf(source, "timestamp"),
|
|
582
|
+
lastUpdated: stringOf(source, "last_updated"),
|
|
583
|
+
});
|
|
584
|
+
}
|
|
585
|
+
function commentSummary(value, context) {
|
|
586
|
+
const source = recordOf(value);
|
|
587
|
+
return compact({
|
|
588
|
+
id: numberOf(source, "id"),
|
|
589
|
+
comment: stringOf(source, "comment"),
|
|
590
|
+
// A comment is upstream-authored text like any other: bounded like one and
|
|
591
|
+
// never treated as an instruction.
|
|
592
|
+
author: usernameOf(source["user"], context.origin),
|
|
593
|
+
timestamp: stringOf(source, "timestamp"),
|
|
594
|
+
});
|
|
595
|
+
}
|
|
596
|
+
function suggestionSummary(value, context) {
|
|
597
|
+
const source = recordOf(value);
|
|
598
|
+
const target = boundedStrings(source["target"], context.textLimit);
|
|
599
|
+
return compact({
|
|
600
|
+
id: numberOf(source, "id"),
|
|
601
|
+
target: target.items,
|
|
602
|
+
textTruncated: target.truncated ? true : undefined,
|
|
603
|
+
votes: numberOf(source, "votes"),
|
|
604
|
+
author: usernameOf(source["user"], context.origin),
|
|
605
|
+
timestamp: stringOf(source, "timestamp"),
|
|
606
|
+
});
|
|
607
|
+
}
|
|
608
|
+
function changeSummary(value, context) {
|
|
609
|
+
const source = recordOf(value);
|
|
610
|
+
const translation = translationRef(source["translation"], context.origin);
|
|
611
|
+
return compact({
|
|
612
|
+
id: numberOf(source, "id"),
|
|
613
|
+
action: numberOf(source, "action"),
|
|
614
|
+
actionName: stringOf(source, "action_name"),
|
|
615
|
+
target: stringOf(source, "target"),
|
|
616
|
+
unitId: unitIdOf(source["unit"], context.origin),
|
|
617
|
+
project: translation?.["project"],
|
|
618
|
+
component: translation?.["component"],
|
|
619
|
+
language: translation?.["language"],
|
|
620
|
+
author: usernameOf(source["author"], context.origin),
|
|
621
|
+
user: usernameOf(source["user"], context.origin),
|
|
622
|
+
timestamp: stringOf(source, "timestamp"),
|
|
623
|
+
// The old and new values are translation text: bounded, and reported as the
|
|
624
|
+
// untrusted content they are.
|
|
625
|
+
old: clip(stringOf(source, "old") ?? "", context.textLimit) || undefined,
|
|
626
|
+
new: clip(stringOf(source, "new") ?? "", context.textLimit) || undefined,
|
|
627
|
+
});
|
|
628
|
+
}
|
|
629
|
+
function screenshotSummary(value, context) {
|
|
630
|
+
const source = recordOf(value);
|
|
631
|
+
const translation = translationRef(source["translation"], context.origin);
|
|
632
|
+
const unitIds = stringsOfRaw(source["units"])
|
|
633
|
+
.map((unit) => unitIdOf(unit, context.origin))
|
|
634
|
+
.filter((id) => id !== undefined)
|
|
635
|
+
.slice(0, SCREENSHOT_UNIT_LIMIT);
|
|
636
|
+
return compact({
|
|
637
|
+
id: numberOf(source, "id"),
|
|
638
|
+
name: stringOf(source, "name"),
|
|
639
|
+
repositoryFilename: stringOf(source, "repository_filename"),
|
|
640
|
+
project: translation?.["project"],
|
|
641
|
+
component: translation?.["component"],
|
|
642
|
+
language: translation?.["language"],
|
|
643
|
+
unitIds: unitIds.length === 0 ? undefined : unitIds,
|
|
644
|
+
// The address of the image on the configured instance. The provider hands it
|
|
645
|
+
// over as metadata only: it does not download screenshot bodies.
|
|
646
|
+
fileUrl: sameOriginUrl(source["file_url"], context.origin),
|
|
647
|
+
webUrl: sameOriginUrl(source["web_url"], context.origin),
|
|
648
|
+
});
|
|
649
|
+
}
|
|
650
|
+
function stringsOfRaw(value) {
|
|
651
|
+
return Array.isArray(value) ? value : [];
|
|
652
|
+
}
|
|
653
|
+
export const WEBLATE_PROJECTIONS = Object.freeze({
|
|
654
|
+
"connection.get": (data) => {
|
|
655
|
+
const { account, resolved } = accountFromUsers(data);
|
|
656
|
+
return {
|
|
657
|
+
account,
|
|
658
|
+
// False means the token may list users, so this provider cannot say
|
|
659
|
+
// which account it belongs to; nothing is guessed from the first row.
|
|
660
|
+
accountResolved: resolved,
|
|
661
|
+
};
|
|
662
|
+
},
|
|
663
|
+
"projects.list": (data) => (Array.isArray(data) ? data : []).map(projectSummary),
|
|
664
|
+
"projects.get": (data) => projectSummary(data),
|
|
665
|
+
"projects.statistics": (data) => statisticsSummary(data),
|
|
666
|
+
"components.list": (data) => (Array.isArray(data) ? data : []).map(componentSummary),
|
|
667
|
+
"components.get": (data) => componentSummary(data),
|
|
668
|
+
"components.statistics": (data) => statisticsSummary(data),
|
|
669
|
+
"translations.list": (data) => (Array.isArray(data) ? data : []).map(translationSummary),
|
|
670
|
+
"translations.get": (data) => translationSummary(data),
|
|
671
|
+
"translations.statistics": (data) => statisticsSummary(data),
|
|
672
|
+
"units.search": (data, context) => (Array.isArray(data) ? data : []).map((unit) => unitSummary(unit, context)),
|
|
673
|
+
"units.find": (data, context) => (Array.isArray(data) ? data : []).map((unit) => unitSummary(unit, context)),
|
|
674
|
+
"units.get": (data, context) => unitSummary(data, context),
|
|
675
|
+
"units.comments": (data, context) => (Array.isArray(data) ? data : []).map((comment) => commentSummary(comment, context)),
|
|
676
|
+
"units.suggestions": (data, context) => (Array.isArray(data) ? data : []).map((suggestion) => suggestionSummary(suggestion, context)),
|
|
677
|
+
"units.failing": (data, context) => (Array.isArray(data) ? data : []).map((unit) => unitSummary(unit, context)),
|
|
678
|
+
"changes.list": (data, context) => (Array.isArray(data) ? data : []).map((change) => changeSummary(change, context)),
|
|
679
|
+
"screenshots.list": (data, context) => (Array.isArray(data) ? data : []).map((screenshot) => screenshotSummary(screenshot, context)),
|
|
680
|
+
"screenshots.get": (data, context) => screenshotSummary(data, context),
|
|
681
|
+
});
|
|
682
|
+
/**
|
|
683
|
+
* Operations whose answer carries upstream-authored localization text. The
|
|
684
|
+
* marker is what tells a reader of the raw JSON that the strings inside were
|
|
685
|
+
* written by people on the far side and are data to them, never instructions.
|
|
686
|
+
*/
|
|
687
|
+
export const WEBLATE_UNTRUSTED_OPERATIONS = Object.freeze([
|
|
688
|
+
"units.search",
|
|
689
|
+
"units.find",
|
|
690
|
+
"units.get",
|
|
691
|
+
"units.failing",
|
|
692
|
+
"units.comments",
|
|
693
|
+
"units.suggestions",
|
|
694
|
+
"changes.list",
|
|
695
|
+
]);
|
|
696
|
+
/** Character budget of one string in the answer of this operation. */
|
|
697
|
+
export function textLimitFor(operation, requested, flags) {
|
|
698
|
+
if (operation !== "units.get")
|
|
699
|
+
return SUMMARY_TEXT_CHARS;
|
|
700
|
+
const asked = optionalInteger(requested, "maxChars", 128, 20_000);
|
|
701
|
+
return Math.min(asked ?? flags.maxTextChars, flags.maxTextChars);
|
|
702
|
+
}
|
|
703
|
+
//# sourceMappingURL=operations.js.map
|